Skip to content

Commit 192efd5

Browse files
authored
fix: chart improvements (#230)
1 parent 872c5b6 commit 192efd5

3 files changed

Lines changed: 35 additions & 9 deletions

File tree

app/components/PackageDownloadAnalytics.vue

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ function safeMax(a: string, b: string): string {
191191
return a.localeCompare(b) >= 0 ? a : b
192192
}
193193
194+
function extractDates(dateLabel: string) {
195+
if (typeof dateLabel !== 'string') return []
196+
197+
const parts = dateLabel.trim().split(/\s+/).filter(Boolean)
198+
199+
if (parts.length < 2) return []
200+
201+
return [parts[0], parts[parts.length - 1]]
202+
}
203+
194204
/**
195205
* Two-phase state:
196206
* - selectedGranularity: immediate UI
@@ -448,17 +458,26 @@ const config = computed(() => ({
448458
},
449459
callbacks: {
450460
img: ({ imageUri }: { imageUri: string }) => {
451-
loadFile(imageUri, `${packageName}-${selectedGranularity.value}.png`)
461+
loadFile(
462+
imageUri,
463+
`${packageName}-${selectedGranularity.value}_${startDate.value}_${endDate.value}.png`,
464+
)
452465
},
453466
csv: (csvStr: string) => {
454467
const blob = new Blob([csvStr.replace('data:text/csv;charset=utf-8,', '')])
455468
const url = URL.createObjectURL(blob)
456-
loadFile(url, `${packageName}-${selectedGranularity.value}.csv`)
469+
loadFile(
470+
url,
471+
`${packageName}-${selectedGranularity.value}_${startDate.value}_${endDate.value}.csv`,
472+
)
457473
URL.revokeObjectURL(url)
458474
},
459475
svg: ({ blob }: { blob: Blob }) => {
460476
const url = URL.createObjectURL(blob)
461-
loadFile(url, `${packageName}-${selectedGranularity.value}.svg`)
477+
loadFile(
478+
url,
479+
`${packageName}-${selectedGranularity.value}_${startDate.value}_${endDate.value}.svg`,
480+
)
462481
URL.revokeObjectURL(url)
463482
},
464483
},
@@ -512,6 +531,13 @@ const config = computed(() => ({
512531
},
513532
zoom: {
514533
maxWidth: 500,
534+
customFormat:
535+
displayedGranularity.value !== 'weekly'
536+
? undefined
537+
: ({ absoluteIndex, side }: { absoluteIndex: number; side: 'left' | 'right' }) => {
538+
const parts = extractDates(chartData.value.dates[absoluteIndex] ?? '')
539+
return side === 'left' ? parts[0] : parts.at(-1)
540+
},
515541
highlightColor: isDarkMode.value ? '#2A2A2A' : '#E1E5E8',
516542
minimap: {
517543
show: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"validate-npm-package-name": "^7.0.2",
5454
"virtua": "^0.48.3",
5555
"vue": "3.5.27",
56-
"vue-data-ui": "^3.13.4"
56+
"vue-data-ui": "^3.13.5"
5757
},
5858
"devDependencies": {
5959
"@iconify-json/carbon": "1.2.18",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)