Skip to content

Commit 2bf037c

Browse files
committed
chore: use vue-data-ui generic type annotations
1 parent 8b34cd8 commit 2bf037c

File tree

3 files changed

+35
-46
lines changed

3 files changed

+35
-46
lines changed

app/components/Package/TrendsChart.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { VueUiXyDatasetItem } from 'vue-data-ui'
2+
import type { VueUiXyConfig, VueUiXyDatapointItem, VueUiXyDatasetItem } from 'vue-data-ui'
33
import { VueUiXy } from 'vue-data-ui/vue-ui-xy'
44
import { useDebounceFn, useElementSize } from '@vueuse/core'
55
import { useCssVariables } from '~/composables/useColors'
@@ -1404,9 +1404,9 @@ function drawSvgPrintLegend(svg: Record<string, any>) {
14041404
}
14051405
14061406
// VueUiXy chart component configuration
1407-
const chartConfig = computed(() => {
1407+
const chartConfig = computed<VueUiXyConfig>(() => {
14081408
return {
1409-
theme: isDarkMode.value ? 'dark' : 'default',
1409+
theme: isDarkMode.value ? 'dark' : '',
14101410
chart: {
14111411
height: isMobile.value ? 950 : 600,
14121412
backgroundColor: colors.value.bg,
@@ -1428,10 +1428,13 @@ const chartConfig = computed(() => {
14281428
altCopy: undefined, // TODO: set to proper translation key
14291429
},
14301430
callbacks: {
1431-
img: ({ imageUri }: { imageUri: string }) => {
1431+
img: args => {
1432+
const imageUri = args?.imageUri
1433+
if (!imageUri) return
14321434
loadFile(imageUri, buildExportFilename('png'))
14331435
},
1434-
csv: (csvStr: string) => {
1436+
csv: csvStr => {
1437+
if (!csvStr) return
14351438
const PLACEHOLDER_CHAR = '\0'
14361439
const multilineDateTemplate = $t('package.trends.date_range_multiline', {
14371440
start: PLACEHOLDER_CHAR,
@@ -1448,7 +1451,7 @@ const chartConfig = computed(() => {
14481451
loadFile(url, buildExportFilename('csv'))
14491452
URL.revokeObjectURL(url)
14501453
},
1451-
svg: ({ blob }: { blob: Blob }) => {
1454+
svg: ({ blob }) => {
14521455
const url = URL.createObjectURL(blob)
14531456
loadFile(url, buildExportFilename('svg'))
14541457
URL.revokeObjectURL(url)
@@ -1510,7 +1513,7 @@ const chartConfig = computed(() => {
15101513
borderColor: 'transparent',
15111514
backdropFilter: false,
15121515
backgroundColor: 'transparent',
1513-
customFormat: ({ datapoint }: { datapoint: Record<string, any> | any[] }) => {
1516+
customFormat: ({ datapoint }) => {
15141517
if (!datapoint || pending.value) return ''
15151518
15161519
const items = Array.isArray(datapoint) ? datapoint : [datapoint[0]]

app/components/Package/VersionDistribution.vue

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<script setup lang="ts">
22
import { VueUiXy } from 'vue-data-ui/vue-ui-xy'
3-
import {
4-
type VueUiXyDatasetItem,
5-
type VueUiXyDatasetBarItem,
6-
type VueUiXyDatapointItem,
7-
type MinimalCustomFormatParams,
8-
} from 'vue-data-ui'
3+
import { type VueUiXyDatasetItem, type VueUiXyConfig } from 'vue-data-ui'
94
import { useElementSize } from '@vueuse/core'
105
import { useCssVariables } from '~/composables/useColors'
116
import { OKLCH_NEUTRAL_FALLBACK, transparentizeOklch, lightenHex } from '~/utils/colors'
@@ -15,10 +10,6 @@ import {
1510
} from '~/composables/useChartWatermark'
1611
import TooltipApp from '~/components/Tooltip/App.vue'
1712
18-
type TooltipParams = MinimalCustomFormatParams<VueUiXyDatapointItem[]> & {
19-
bars: VueUiXyDatasetBarItem[]
20-
}
21-
2213
const props = defineProps<{
2314
packageName: string
2415
inModal?: boolean
@@ -176,7 +167,7 @@ const hasMinimap = computed<boolean>(() => {
176167
return series.length > 6
177168
})
178169
179-
const chartConfig = computed(() => {
170+
const chartConfig = computed<VueUiXyConfig>(() => {
180171
return {
181172
theme: isDarkMode.value ? 'dark' : '',
182173
chart: {
@@ -209,10 +200,13 @@ const chartConfig = computed(() => {
209200
altCopy: undefined, // TODO: set to proper translation key
210201
},
211202
callbacks: {
212-
img: ({ imageUri }: { imageUri: string }) => {
203+
img: args => {
204+
const imageUri = args?.imageUri
205+
if (!imageUri) return
213206
loadFile(imageUri, buildExportFilename('png'))
214207
},
215-
csv: (csvStr: string) => {
208+
csv: csvStr => {
209+
if (!csvStr) return
216210
const PLACEHOLDER_CHAR = '\0'
217211
const multilineDateTemplate = $t('package.trends.date_range_multiline', {
218212
start: PLACEHOLDER_CHAR,
@@ -229,7 +223,7 @@ const chartConfig = computed(() => {
229223
loadFile(url, buildExportFilename('csv'))
230224
URL.revokeObjectURL(url)
231225
},
232-
svg: ({ blob }: { blob: Blob }) => {
226+
svg: ({ blob }) => {
233227
const url = URL.createObjectURL(blob)
234228
loadFile(url, buildExportFilename('svg'))
235229
URL.revokeObjectURL(url)
@@ -277,8 +271,7 @@ const chartConfig = computed(() => {
277271
borderColor: 'transparent',
278272
backdropFilter: false,
279273
backgroundColor: 'transparent',
280-
customFormat: (params: TooltipParams) => {
281-
const { datapoint, absoluteIndex, bars } = params
274+
customFormat: ({ datapoint, absoluteIndex, bars }) => {
282275
if (!datapoint || pending.value) return ''
283276
284277
// Use absoluteIndex to get the correct version from chartDataset
@@ -329,9 +322,6 @@ const chartConfig = computed(() => {
329322
},
330323
},
331324
},
332-
table: {
333-
show: false,
334-
},
335325
}
336326
})
337327
</script>
@@ -447,7 +437,7 @@ const chartConfig = computed(() => {
447437
role="region"
448438
aria-labelledby="version-distribution-title"
449439
class="relative"
450-
:class="isMobile ? 'min-h-[260px]' : 'min-h-[400px]'"
440+
:class="isMobile ? 'min-h-[260px]' : 'min-h-[520px]'"
451441
>
452442
<!-- Chart content -->
453443
<ClientOnly v-if="xyDataset.length > 0 && !error">
@@ -463,6 +453,16 @@ const chartConfig = computed(() => {
463453
v-if="svg.isPrintingSvg || svg.isPrintingImg"
464454
v-html="drawNpmxLogoAndTaglineWatermark(svg, watermarkColors, $t, 'bottom')"
465455
/>
456+
457+
<!-- Overlay covering the chart area to hide line resizing when switching granularities recalculates VueUiXy scaleMax when estimation lines are necessary -->
458+
<rect
459+
v-if="pending"
460+
:x="svg.drawingArea.left"
461+
:y="svg.drawingArea.top - 12"
462+
:width="svg.drawingArea.width + 12"
463+
:height="svg.drawingArea.height + 48"
464+
:fill="colors.bg"
465+
/>
466466
</template>
467467

468468
<!-- Custom bar gradient based on the series color -->
@@ -620,21 +620,6 @@ const chartConfig = computed(() => {
620620
:deep(.vue-ui-xy) svg rect {
621621
transition: none !important;
622622
}
623-
624-
@keyframes fadeInUp {
625-
from {
626-
opacity: 0;
627-
transform: translateY(8px);
628-
}
629-
to {
630-
opacity: 1;
631-
transform: translateY(0);
632-
}
633-
}
634-
635-
.chart-container {
636-
animation: fadeInUp 350ms cubic-bezier(0.4, 0, 0.2, 1);
637-
}
638623
</style>
639624

640625
<style>

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useCssVariables } from '~/composables/useColors'
44
import type { WeeklyDataPoint } from '~/types/chart'
55
import { OKLCH_NEUTRAL_FALLBACK, lightenOklch } from '~/utils/colors'
66
import type { RepoRef } from '#shared/utils/git-providers'
7+
import type { VueUiSparklineConfig, VueUiSparklineDatasetItem } from 'vue-data-ui'
78
89
const props = defineProps<{
910
packageName: string
@@ -176,7 +177,7 @@ watch(
176177
() => loadWeeklyDownloads(),
177178
)
178179
179-
const dataset = computed(() =>
180+
const dataset = computed<VueUiSparklineDatasetItem[]>(() =>
180181
weeklyDownloads.value.map(d => ({
181182
value: d?.value ?? 0,
182183
period: $t('package.trends.date_range', {
@@ -188,7 +189,7 @@ const dataset = computed(() =>
188189
189190
const lastDatapoint = computed(() => dataset.value.at(-1)?.period ?? '')
190191
191-
const config = computed(() => {
192+
const config = computed<VueUiSparklineConfig>(() => {
192193
return {
193194
theme: 'dark',
194195
/**
@@ -234,7 +235,7 @@ const config = computed(() => {
234235
show: hasSparklineAnimation.value, // the pulse will not show if prefers-reduced-motion (enforced by vue-data-ui)
235236
loop: true, // runs only once if false
236237
radius: 1.5,
237-
color: pulseColor.value,
238+
color: pulseColor.value!,
238239
easing: 'ease-in-out',
239240
trail: {
240241
show: true,
@@ -248,7 +249,7 @@ const config = computed(() => {
248249
stroke: isDarkMode.value ? 'oklch(0.985 0 0)' : 'oklch(0.145 0 0)',
249250
},
250251
title: {
251-
text: lastDatapoint.value,
252+
text: String(lastDatapoint.value),
252253
fontSize: 12,
253254
color: colors.value.fgSubtle,
254255
bold: false,

0 commit comments

Comments
 (0)