-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ac471b
commit bd12895
Showing
8 changed files
with
253 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/analytics/analytics-chart/sandbox/pages/GeoChartDemo.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<SandboxLayout | ||
:links="appLinks" | ||
title="Analytics Charts" | ||
> | ||
<template #controls /> | ||
|
||
<GeoChart | ||
:chart-data="chartData" | ||
/> | ||
</SandboxLayout> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { inject, onMounted, ref } from 'vue' | ||
import type { SandboxNavigationItem } from '@kong-ui-public/sandbox-layout' | ||
import { GeoChart, type KChartData } from '../../src' | ||
import { topojson, type Feature } from 'chartjs-chart-geo' | ||
const appLinks: SandboxNavigationItem[] = inject('app-links', []) | ||
const chartData = ref<KChartData>() | ||
onMounted(async () => { | ||
const data = await fetch('https://unpkg.com/world-atlas/countries-50m.json').then((r) => r.json()) | ||
let countries = topojson.feature(data, data.objects.countries).features | ||
countries = countries.filter(c => c.properties.name !== 'Antarctica') | ||
chartData.value = { | ||
labels: countries.map((c: Feature) => c.properties.name), | ||
datasets: [{ | ||
label: 'Countries', | ||
data: countries.map((c: Feature) => ({ | ||
feature: c, | ||
value: Math.random() * 100, | ||
})), | ||
}], | ||
} | ||
}) | ||
</script> |
95 changes: 95 additions & 0 deletions
95
packages/analytics/analytics-chart/src/components/GeoChart.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<template> | ||
<div class="chart-container"> | ||
<canvas | ||
ref="chartCanvas" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, computed, toRef } from 'vue' | ||
import type { PropType, Ref } from 'vue' | ||
import composables from '../composables' | ||
import type { KChartData, LegendValues } from '../types' | ||
import type { ChartOptions } from 'chart.js' | ||
import { Chart } from 'chart.js' | ||
import { ChoroplethController, GeoFeature, ColorScale, ProjectionScale } from 'chartjs-chart-geo' | ||
// register controller in chart.js and ensure the defaults are set | ||
Chart.register(ChoroplethController, GeoFeature, ColorScale, ProjectionScale) | ||
const props = defineProps({ | ||
chartData: { | ||
type: Object as PropType<KChartData>, | ||
required: false, | ||
default: () => ({ labels: [], datasets: [] }), | ||
}, | ||
tooltipTitle: { | ||
type: String, | ||
required: false, | ||
default: '', | ||
}, | ||
legendValues: { | ||
type: Object as PropType<LegendValues>, | ||
required: false, | ||
default: null, | ||
}, | ||
metricUnit: { | ||
type: String, | ||
required: false, | ||
default: '', | ||
}, | ||
syntheticsDataKey: { | ||
type: String, | ||
required: false, | ||
default: '', | ||
}, | ||
}) | ||
const chartCanvas = ref<HTMLCanvasElement>() | ||
const options = computed<ChartOptions>(() => { | ||
return { | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
}, | ||
scales: { | ||
projection: { | ||
axis: 'x', | ||
projection: 'mercator', | ||
}, | ||
}, | ||
x: { | ||
grid: { | ||
display: false, | ||
drawBorder: false, | ||
}, | ||
}, | ||
y: { | ||
grid: { | ||
display: false, | ||
drawBorder: false, | ||
}, | ||
}, | ||
} | ||
}) | ||
composables.useChartJSCommon( | ||
'choropleth', | ||
chartCanvas, | ||
toRef(props, 'chartData'), | ||
[], | ||
options, | ||
) as Ref<Chart | null> | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.chart-container { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.