Skip to content

Commit 091780e

Browse files
committed
feat: package analytics download file custom name
1 parent 64d0bc6 commit 091780e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

app/components/PackageDownloadAnalytics.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ const chartData = computed<{ dataset: VueUiXyDatasetItem[] | null; dates: string
414414
415415
const formatter = ({ value }: { value: number }) => formatCompactNumber(value, { decimals: 1 })
416416
417+
const loadFile = (link: string, filename: string) => {
418+
const a = document.createElement('a')
419+
a.href = link
420+
a.download = filename
421+
a.click()
422+
a.remove()
423+
}
424+
417425
const config = computed(() => ({
418426
theme: isDarkMode.value ? 'dark' : 'default',
419427
chart: {
@@ -425,6 +433,22 @@ const config = computed(() => ({
425433
table: false,
426434
tooltip: false,
427435
},
436+
callbacks: {
437+
img: ({ imageUri }: { imageUri: string }) => {
438+
loadFile(imageUri, `${packageName}-${selectedGranularity.value}.png`)
439+
},
440+
csv: (csvStr: string) => {
441+
const blob = new Blob([csvStr.replace('data:text/csv;charset=utf-8,', '')])
442+
const url = URL.createObjectURL(blob)
443+
loadFile(url, `${packageName}-${selectedGranularity.value}.csv`)
444+
URL.revokeObjectURL(url)
445+
},
446+
svg: ({ blob }: { blob: Blob}) => {
447+
const url = URL.createObjectURL(blob)
448+
loadFile(url, `${packageName}-${selectedGranularity.value}.svg`)
449+
URL.revokeObjectURL(url)
450+
},
451+
},
428452
},
429453
backgroundColor: isDarkMode.value ? '#0A0A0A' : '#FFFFFF',
430454
grid: {

0 commit comments

Comments
 (0)