Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/components/PackageDownloadAnalytics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ const chartData = computed<{ dataset: VueUiXyDatasetItem[] | null; dates: string

const formatter = ({ value }: { value: number }) => formatCompactNumber(value, { decimals: 1 })

const loadFile = (link: string, filename: string) => {
const a = document.createElement('a')
a.href = link
a.download = filename
a.click()
a.remove()
}

const config = computed(() => ({
theme: isDarkMode.value ? 'dark' : 'default',
chart: {
Expand All @@ -438,6 +446,22 @@ const config = computed(() => ({
table: false,
tooltip: false,
},
callbacks: {
img: ({ imageUri }: { imageUri: string }) => {
loadFile(imageUri, `${packageName}-${selectedGranularity.value}.png`)
},
csv: (csvStr: string) => {
const blob = new Blob([csvStr.replace('data:text/csv;charset=utf-8,', '')])
Comment thread
btea marked this conversation as resolved.
const url = URL.createObjectURL(blob)
loadFile(url, `${packageName}-${selectedGranularity.value}.csv`)
URL.revokeObjectURL(url)
},
svg: ({ blob }: { blob: Blob }) => {
const url = URL.createObjectURL(blob)
loadFile(url, `${packageName}-${selectedGranularity.value}.svg`)
URL.revokeObjectURL(url)
},
},
},
backgroundColor: isDarkMode.value ? '#0A0A0A' : '#FFFFFF',
grid: {
Expand Down