Skip to content

Commit 1baaba3

Browse files
bteadanielroeautofix-ci[bot]
authored
feat: package analytics download file custom name (#212)
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent b2589b1 commit 1baaba3

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
@@ -426,6 +426,14 @@ const chartData = computed<{ dataset: VueUiXyDatasetItem[] | null; dates: string
426426
427427
const formatter = ({ value }: { value: number }) => formatCompactNumber(value, { decimals: 1 })
428428
429+
const loadFile = (link: string, filename: string) => {
430+
const a = document.createElement('a')
431+
a.href = link
432+
a.download = filename
433+
a.click()
434+
a.remove()
435+
}
436+
429437
const config = computed(() => ({
430438
theme: isDarkMode.value ? 'dark' : 'default',
431439
chart: {
@@ -438,6 +446,22 @@ const config = computed(() => ({
438446
table: false,
439447
tooltip: false,
440448
},
449+
callbacks: {
450+
img: ({ imageUri }: { imageUri: string }) => {
451+
loadFile(imageUri, `${packageName}-${selectedGranularity.value}.png`)
452+
},
453+
csv: (csvStr: string) => {
454+
const blob = new Blob([csvStr.replace('data:text/csv;charset=utf-8,', '')])
455+
const url = URL.createObjectURL(blob)
456+
loadFile(url, `${packageName}-${selectedGranularity.value}.csv`)
457+
URL.revokeObjectURL(url)
458+
},
459+
svg: ({ blob }: { blob: Blob }) => {
460+
const url = URL.createObjectURL(blob)
461+
loadFile(url, `${packageName}-${selectedGranularity.value}.svg`)
462+
URL.revokeObjectURL(url)
463+
},
464+
},
441465
},
442466
backgroundColor: isDarkMode.value ? '#0A0A0A' : '#FFFFFF',
443467
grid: {

0 commit comments

Comments
 (0)