perf: The map is not packaged into the code to reduce the server size
This commit is contained in:
parent
d2c83e43d4
commit
c894fde09f
2
.gitignore
vendored
2
.gitignore
vendored
@ -25,4 +25,4 @@ logs
|
|||||||
.wrangler
|
.wrangler
|
||||||
site
|
site
|
||||||
cache
|
cache
|
||||||
assets/location/world-topo.json
|
public/world.json
|
||||||
|
|||||||
@ -1,14 +1,23 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { VisSingleContainer, VisTopoJSONMap, VisTopoJSONMapSelectors } from '@unovis/vue'
|
import { VisSingleContainer, VisTopoJSONMap, VisTopoJSONMapSelectors } from '@unovis/vue'
|
||||||
import WorldMapTopoJSON from '@/assets/location/world-topo.json' // https://github.com/apache/echarts/blob/master/test/data/map/json/world.json
|
|
||||||
import { ChartTooltip } from '@/components/ui/chart'
|
import { ChartTooltip } from '@/components/ui/chart'
|
||||||
|
|
||||||
const id = inject('id')
|
const id = inject('id')
|
||||||
const startAt = inject('startAt')
|
const startAt = inject('startAt')
|
||||||
const endAt = inject('endAt')
|
const endAt = inject('endAt')
|
||||||
|
|
||||||
|
const worldMapTopoJSON = ref({})
|
||||||
const areaData = ref([])
|
const areaData = ref([])
|
||||||
|
|
||||||
|
async function getWorldMapJSON() {
|
||||||
|
const data = await $fetch('/world.json', {
|
||||||
|
query: {
|
||||||
|
type: 'world',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
worldMapTopoJSON.value = data
|
||||||
|
}
|
||||||
|
|
||||||
async function getMapData() {
|
async function getMapData() {
|
||||||
areaData.value = []
|
areaData.value = []
|
||||||
const { data } = await useAPI('/api/stats/metrics', {
|
const { data } = await useAPI('/api/stats/metrics', {
|
||||||
@ -30,6 +39,7 @@ async function getMapData() {
|
|||||||
const stopWatchTime = watch([startAt, endAt], getMapData)
|
const stopWatchTime = watch([startAt, endAt], getMapData)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
getWorldMapJSON()
|
||||||
getMapData()
|
getMapData()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -60,11 +70,12 @@ const Tooltip = {
|
|||||||
<CardContent class="flex-1 flex [&_[data-radix-aspect-ratio-wrapper]]:flex-1">
|
<CardContent class="flex-1 flex [&_[data-radix-aspect-ratio-wrapper]]:flex-1">
|
||||||
<AspectRatio :ratio="65 / 30">
|
<AspectRatio :ratio="65 / 30">
|
||||||
<VisSingleContainer
|
<VisSingleContainer
|
||||||
|
v-if="worldMapTopoJSON.type"
|
||||||
:data="{ areas: areaData }"
|
:data="{ areas: areaData }"
|
||||||
class="h-full"
|
class="h-full"
|
||||||
>
|
>
|
||||||
<VisTopoJSONMap
|
<VisTopoJSONMap
|
||||||
:topojson="WorldMapTopoJSON"
|
:topojson="worldMapTopoJSON"
|
||||||
map-feature-name="states"
|
map-feature-name="states"
|
||||||
/>
|
/>
|
||||||
<ChartSingleTooltip
|
<ChartSingleTooltip
|
||||||
|
|||||||
@ -5,6 +5,6 @@ provide('id', ref())
|
|||||||
<template>
|
<template>
|
||||||
<main class="space-y-6">
|
<main class="space-y-6">
|
||||||
<DashboardBreadcrumb title="Analysis" />
|
<DashboardBreadcrumb title="Analysis" />
|
||||||
<LazyDashboard />
|
<Dashboard />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<main class="flex items-center justify-center h-full">
|
<main class="flex items-center justify-center h-full">
|
||||||
<LazyLogin />
|
<Login />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@ -16,4 +16,4 @@ WorldMapTopoJSON.objects.states.geometries.map((state) => {
|
|||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
writeFileSync(join(import.meta.dirname, '../assets/location/world-topo.json'), JSON.stringify(WorldMapTopoJSON), 'utf8')
|
writeFileSync(join(import.meta.dirname, '../public/world.json'), JSON.stringify(WorldMapTopoJSON), 'utf8')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user