Skip to content

Commit fea11d6

Browse files
committed
chore: use common shared chart utils
1 parent 77aa146 commit fea11d6

2 files changed

Lines changed: 2 additions & 30 deletions

File tree

app/components/Package/TrendsChart.vue

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
import { DATE_INPUT_MAX } from '~/utils/input'
2121
import { applyDataCorrection } from '~/utils/chart-data-correction'
2222
import { applyBlocklistCorrection, getAnomaliesForPackages } from '~/utils/download-anomalies'
23-
import { copyAltTextForTrendLineChart } from '~/utils/charts'
23+
import { copyAltTextForTrendLineChart, sanitise, loadFile } from '~/utils/charts'
2424
2525
import('vue-data-ui/style.css')
2626
@@ -1085,14 +1085,6 @@ const maxDatapoints = computed(() =>
10851085
Math.max(0, ...(chartData.value.dataset ?? []).map(d => d.series.length)),
10861086
)
10871087
1088-
const loadFile = (link: string, filename: string) => {
1089-
const a = document.createElement('a')
1090-
a.href = link
1091-
a.download = filename
1092-
a.click()
1093-
a.remove()
1094-
}
1095-
10961088
const datetimeFormatterOptions = computed(() => {
10971089
return {
10981090
daily: { year: 'yyyy-MM-dd', month: 'yyyy-MM-dd', day: 'yyyy-MM-dd' },
@@ -1113,12 +1105,6 @@ const tooltipDateFormatter = computed(() => {
11131105
})
11141106
})
11151107
1116-
const sanitise = (value: string) =>
1117-
value
1118-
.replace(/^@/, '')
1119-
.replace(/[\\/:"*?<>|]/g, '-')
1120-
.replace(/\//g, '-')
1121-
11221108
function buildExportFilename(extension: string): string {
11231109
const g = selectedGranularity.value
11241110
const range = `${startDate.value}_${endDate.value}`

app/components/Package/VersionDistribution.vue

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
drawNpmxLogoAndTaglineWatermark,
1010
} from '~/composables/useChartWatermark'
1111
import TooltipApp from '~/components/Tooltip/App.vue'
12-
import { copyAltTextForVersionsBarChart } from '~/utils/charts'
12+
import { copyAltTextForVersionsBarChart, sanitise, loadFile } from '~/utils/charts'
1313
1414
import('vue-data-ui/style.css')
1515
@@ -89,20 +89,6 @@ const compactNumberFormatter = useCompactNumberFormatter()
8989
// Show loading indicator immediately to maintain stable layout
9090
const showLoadingIndicator = computed(() => pending.value)
9191
92-
const loadFile = (link: string, filename: string) => {
93-
const a = document.createElement('a')
94-
a.href = link
95-
a.download = filename
96-
a.click()
97-
a.remove()
98-
}
99-
100-
const sanitise = (value: string) =>
101-
value
102-
.replace(/^@/, '')
103-
.replace(/[\\/:"*?<>|]/g, '-')
104-
.replace(/\//g, '-')
105-
10692
const { locale } = useI18n()
10793
function formatDate(date: Date) {
10894
return date.toLocaleString(locale.value, {

0 commit comments

Comments
 (0)