forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadAnalytics.vue
More file actions
843 lines (763 loc) · 25.3 KB
/
DownloadAnalytics.vue
File metadata and controls
843 lines (763 loc) · 25.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
<script setup lang="ts">
import type { VueUiXyDatasetItem } from 'vue-data-ui'
import { VueUiXy } from 'vue-data-ui/vue-ui-xy'
import { useDebounceFn, useElementSize } from '@vueuse/core'
import { useCssVariables } from '~/composables/useColors'
import { OKLCH_NEUTRAL_FALLBACK, transparentizeOklch } from '~/utils/colors'
const props = defineProps<{
weeklyDownloads: WeeklyDownloadPoint[]
inModal?: boolean
packageName: string
createdIso: string | null
}>()
const { locale } = useI18n()
const { accentColors, selectedAccentColor } = useAccentColor()
const colorMode = useColorMode()
const resolvedMode = shallowRef<'light' | 'dark'>('light')
const rootEl = shallowRef<HTMLElement | null>(null)
const { width } = useElementSize(rootEl)
const chartKey = ref(0)
let chartRemountTimeoutId: ReturnType<typeof setTimeout> | null = null
onMounted(() => {
rootEl.value = document.documentElement
resolvedMode.value = colorMode.value === 'dark' ? 'dark' : 'light'
// If the chart is painted too early, built-in auto-sizing does not adapt to the final container size
chartRemountTimeoutId = setTimeout(() => {
chartKey.value += 1
chartRemountTimeoutId = null
}, 1)
})
onBeforeUnmount(() => {
if (chartRemountTimeoutId !== null) {
clearTimeout(chartRemountTimeoutId)
chartRemountTimeoutId = null
}
})
const { colors } = useCssVariables(
['--bg', '--fg', '--bg-subtle', '--bg-elevated', '--fg-subtle', '--border', '--border-subtle'],
{
element: rootEl,
watchHtmlAttributes: true,
watchResize: false, // set to true only if a var changes color on resize
},
)
watch(
() => colorMode.value,
value => {
resolvedMode.value = value === 'dark' ? 'dark' : 'light'
},
{ flush: 'sync' },
)
const isDarkMode = computed(() => resolvedMode.value === 'dark')
const accentColorValueById = computed<Record<string, string>>(() => {
const map: Record<string, string> = {}
for (const item of accentColors) {
map[item.id] = item.value
}
return map
})
const accent = computed(() => {
const id = selectedAccentColor.value
return id
? (accentColorValueById.value[id] ?? colors.value.fgSubtle ?? OKLCH_NEUTRAL_FALLBACK)
: (colors.value.fgSubtle ?? OKLCH_NEUTRAL_FALLBACK)
})
const mobileBreakpointWidth = 640
const isMobile = computed(() => {
return width.value > 0 && width.value < mobileBreakpointWidth
})
type ChartTimeGranularity = 'daily' | 'weekly' | 'monthly' | 'yearly'
type EvolutionData =
| DailyDownloadPoint[]
| WeeklyDownloadPoint[]
| MonthlyDownloadPoint[]
| YearlyDownloadPoint[]
type DateRangeFields = {
startDate?: string
endDate?: string
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
}
function isWeeklyDataset(data: unknown): data is WeeklyDownloadPoint[] {
return (
Array.isArray(data) &&
data.length > 0 &&
isRecord(data[0]) &&
'weekStart' in data[0] &&
'weekEnd' in data[0] &&
'downloads' in data[0]
)
}
function isDailyDataset(data: unknown): data is DailyDownloadPoint[] {
return (
Array.isArray(data) &&
data.length > 0 &&
isRecord(data[0]) &&
'day' in data[0] &&
'downloads' in data[0]
)
}
function isMonthlyDataset(data: unknown): data is MonthlyDownloadPoint[] {
return (
Array.isArray(data) &&
data.length > 0 &&
isRecord(data[0]) &&
'month' in data[0] &&
'downloads' in data[0]
)
}
function isYearlyDataset(data: unknown): data is YearlyDownloadPoint[] {
return (
Array.isArray(data) &&
data.length > 0 &&
isRecord(data[0]) &&
'year' in data[0] &&
'downloads' in data[0]
)
}
function formatXyDataset(
selectedGranularity: ChartTimeGranularity,
dataset: EvolutionData,
): { dataset: VueUiXyDatasetItem[] | null; dates: number[] } {
if (selectedGranularity === 'weekly' && isWeeklyDataset(dataset)) {
return {
dataset: [
{
name: props.packageName,
type: 'line',
series: dataset.map(d => d.downloads),
color: accent.value,
},
],
dates: dataset.map(d => d.timestampEnd),
}
}
if (selectedGranularity === 'daily' && isDailyDataset(dataset)) {
return {
dataset: [
{
name: props.packageName,
type: 'line',
series: dataset.map(d => d.downloads),
color: accent.value,
},
],
dates: dataset.map(d => d.timestamp),
}
}
if (selectedGranularity === 'monthly' && isMonthlyDataset(dataset)) {
return {
dataset: [
{
name: props.packageName,
type: 'line',
series: dataset.map(d => d.downloads),
color: accent.value,
},
],
dates: dataset.map(d => d.timestamp),
}
}
if (selectedGranularity === 'yearly' && isYearlyDataset(dataset)) {
return {
dataset: [
{
name: props.packageName,
type: 'line',
series: dataset.map(d => d.downloads),
color: accent.value,
},
],
dates: dataset.map(d => d.timestamp),
}
}
return { dataset: null, dates: [] }
}
function toIsoDateOnly(value: string): string {
return value.slice(0, 10)
}
function isValidIsoDateOnly(value: string): boolean {
return /^\d{4}-\d{2}-\d{2}$/.test(value)
}
function safeMin(a: string, b: string): string {
return a.localeCompare(b) <= 0 ? a : b
}
function safeMax(a: string, b: string): string {
return a.localeCompare(b) >= 0 ? a : b
}
/**
* Two-phase state:
* - selectedGranularity: immediate UI
* - displayedGranularity: only updated once data is ready
*/
const selectedGranularity = shallowRef<ChartTimeGranularity>('weekly')
const displayedGranularity = shallowRef<ChartTimeGranularity>('weekly')
/**
* Date range inputs.
* They are initialized from the current effective range:
* - weekly: from weeklyDownloads first -> weekStart/weekEnd
* - fallback: last 30 days ending yesterday (client-side)
*/
const startDate = shallowRef<string>('') // YYYY-MM-DD
const endDate = shallowRef<string>('') // YYYY-MM-DD
const hasUserEditedDates = shallowRef(false)
function initDateRangeFromWeekly() {
if (hasUserEditedDates.value) return
if (!props.weeklyDownloads?.length) return
const first = props.weeklyDownloads[0]
const last = props.weeklyDownloads[props.weeklyDownloads.length - 1]
const start = first?.weekStart ? toIsoDateOnly(first.weekStart) : ''
const end = last?.weekEnd ? toIsoDateOnly(last.weekEnd) : ''
if (isValidIsoDateOnly(start)) startDate.value = start
if (isValidIsoDateOnly(end)) endDate.value = end
}
function initDateRangeFallbackClient() {
if (hasUserEditedDates.value) return
if (!import.meta.client) return
if (startDate.value && endDate.value) return
const today = new Date()
const yesterday = new Date(
Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 1),
)
const end = yesterday.toISOString().slice(0, 10)
const startObj = new Date(yesterday)
startObj.setUTCDate(startObj.getUTCDate() - 29)
const start = startObj.toISOString().slice(0, 10)
if (!startDate.value) startDate.value = start
if (!endDate.value) endDate.value = end
}
watch(
() => props.weeklyDownloads?.length,
() => {
initDateRangeFromWeekly()
initDateRangeFallbackClient()
},
{ immediate: true },
)
const initialStartDate = shallowRef<string>('') // YYYY-MM-DD
const initialEndDate = shallowRef<string>('') // YYYY-MM-DD
function setInitialRangeIfEmpty() {
if (initialStartDate.value || initialEndDate.value) return
if (startDate.value) initialStartDate.value = startDate.value
if (endDate.value) initialEndDate.value = endDate.value
}
watch(
[startDate, endDate],
() => {
// mark edited only when both have some value (prevents init watchers from flagging too early)
if (startDate.value || endDate.value) hasUserEditedDates.value = true
setInitialRangeIfEmpty()
},
{ immediate: true, flush: 'post' },
)
const showResetButton = computed(() => {
if (!initialStartDate.value && !initialEndDate.value) return false
return startDate.value !== initialStartDate.value || endDate.value !== initialEndDate.value
})
const options = shallowRef<
| { granularity: 'day'; startDate?: string; endDate?: string }
| { granularity: 'week'; weeks: number; startDate?: string; endDate?: string }
| { granularity: 'month'; months: number; startDate?: string; endDate?: string }
| { granularity: 'year'; startDate?: string; endDate?: string }
>({ granularity: 'week', weeks: 52 })
function applyDateRange<T extends Record<string, unknown>>(base: T): T & DateRangeFields {
const next: T & DateRangeFields = { ...base }
const start = startDate.value ? toIsoDateOnly(startDate.value) : ''
const end = endDate.value ? toIsoDateOnly(endDate.value) : ''
const validStart = start && isValidIsoDateOnly(start) ? start : ''
const validEnd = end && isValidIsoDateOnly(end) ? end : ''
if (validStart && validEnd) {
next.startDate = safeMin(validStart, validEnd)
next.endDate = safeMax(validStart, validEnd)
} else {
if (validStart) next.startDate = validStart
else delete next.startDate
if (validEnd) next.endDate = validEnd
else delete next.endDate
}
return next
}
watch(
[selectedGranularity, startDate, endDate],
([granularityValue]) => {
if (granularityValue === 'daily') options.value = applyDateRange({ granularity: 'day' })
else if (granularityValue === 'weekly')
options.value = applyDateRange({ granularity: 'week', weeks: 52 })
else if (granularityValue === 'monthly')
options.value = applyDateRange({ granularity: 'month', months: 24 })
else options.value = applyDateRange({ granularity: 'year' })
},
{ immediate: true },
)
const { fetchPackageDownloadEvolution } = useCharts()
const evolution = shallowRef<EvolutionData>(props.weeklyDownloads)
const pending = shallowRef(false)
let lastRequestKey = ''
let requestToken = 0
const debouncedLoad = useDebounceFn(() => {
load()
}, 1000)
async function load() {
if (!import.meta.client) return
if (!props.inModal) return
const o = options.value
const extraBase =
o.granularity === 'week'
? `w:${String(o.weeks ?? '')}`
: o.granularity === 'month'
? `m:${String(o.months ?? '')}`
: ''
const startKey = (o as any).startDate ?? ''
const endKey = (o as any).endDate ?? ''
const requestKey = `${props.packageName}|${props.createdIso ?? ''}|${o.granularity}|${extraBase}|${startKey}|${endKey}`
if (requestKey === lastRequestKey) return
lastRequestKey = requestKey
const hasExplicitRange = Boolean((o as any).startDate || (o as any).endDate)
if (o.granularity === 'week' && props.weeklyDownloads?.length && !hasExplicitRange) {
evolution.value = props.weeklyDownloads
pending.value = false
displayedGranularity.value = 'weekly'
return
}
pending.value = true
const currentToken = ++requestToken
try {
const result = await fetchPackageDownloadEvolution(
() => props.packageName,
() => props.createdIso,
() => o as any, // FIXME: any
)
if (currentToken !== requestToken) return
evolution.value = (result as EvolutionData) ?? []
displayedGranularity.value = selectedGranularity.value
} catch {
if (currentToken !== requestToken) return
evolution.value = []
} finally {
if (currentToken === requestToken) {
pending.value = false
}
}
}
watch(
() => props.inModal,
() => {
// modal open/close should be immediate
load()
},
{ immediate: true },
)
watch(
() => [
props.packageName,
props.createdIso,
options.value.granularity,
(options.value as any).weeks,
(options.value as any).months,
],
() => {
// changing package or granularity should be immediate
load()
},
{ immediate: true },
)
watch(
() => [(options.value as any).startDate, (options.value as any).endDate],
() => {
// date typing / picking should be debounced
debouncedLoad()
},
{ immediate: true },
)
const effectiveData = computed<EvolutionData>(() => {
if (displayedGranularity.value === 'weekly' && props.weeklyDownloads?.length) {
if (isWeeklyDataset(evolution.value) && evolution.value.length) return evolution.value
return props.weeklyDownloads
}
return evolution.value
})
const chartData = computed<{ dataset: VueUiXyDatasetItem[] | null; dates: number[] }>(() => {
return formatXyDataset(displayedGranularity.value, effectiveData.value)
})
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 datetimeFormatterOptions = computed(() => {
return {
daily: {
year: 'yyyy-MM-dd',
month: 'yyyy-MM-dd',
day: 'yyyy-MM-dd',
},
weekly: {
year: 'yyyy-MM-dd',
month: 'yyyy-MM-dd',
day: 'yyyy-MM-dd',
},
monthly: {
year: 'MMM yyyy',
month: 'MMM yyyy',
day: 'MMM yyyy',
},
yearly: {
year: 'yyyy',
month: 'yyyy',
day: 'yyyy',
},
}[selectedGranularity.value]
})
const config = computed(() => {
return {
theme: isDarkMode.value ? 'dark' : 'default',
chart: {
height: isMobile.value ? 950 : 600,
padding: {
bottom: 36,
},
userOptions: {
buttons: {
pdf: false,
labels: false,
fullscreen: false,
table: false,
tooltip: false,
},
buttonTitles: {
csv: $t('package.downloads.download_file', { fileType: 'CSV' }),
img: $t('package.downloads.download_file', { fileType: 'PNG' }),
svg: $t('package.downloads.download_file', { fileType: 'SVG' }),
annotator: $t('package.downloads.toggle_annotator'),
},
callbacks: {
img: ({ imageUri }: { imageUri: string }) => {
loadFile(
imageUri,
`${props.packageName}-${selectedGranularity.value}_${startDate.value}_${endDate.value}.png`,
)
},
csv: (csvStr: string) => {
// Extract multiline date format template and replace newlines with spaces in CSV
// This ensures CSV compatibility by converting multiline date ranges to single-line format
const PLACEHOLDER_CHAR = '\0'
const multilineDateTemplate = $t('package.downloads.date_range_multiline', {
start: PLACEHOLDER_CHAR,
end: PLACEHOLDER_CHAR,
})
.replaceAll(PLACEHOLDER_CHAR, '')
.trim()
const blob = new Blob([
csvStr
.replace('data:text/csv;charset=utf-8,', '')
.replaceAll(`\n${multilineDateTemplate}`, ` ${multilineDateTemplate}`),
])
const url = URL.createObjectURL(blob)
loadFile(
url,
`${props.packageName}-${selectedGranularity.value}_${startDate.value}_${endDate.value}.csv`,
)
URL.revokeObjectURL(url)
},
svg: ({ blob }: { blob: Blob }) => {
const url = URL.createObjectURL(blob)
loadFile(
url,
`${props.packageName}-${selectedGranularity.value}_${startDate.value}_${endDate.value}.svg`,
)
URL.revokeObjectURL(url)
},
},
},
backgroundColor: colors.value.bg,
grid: {
stroke: colors.value.border,
labels: {
fontSize: isMobile.value ? 24 : 16,
axis: {
yLabel: $t('package.downloads.y_axis_label', {
granularity: $t(`package.downloads.granularity_${selectedGranularity.value}`),
}),
xLabel: props.packageName,
yLabelOffsetX: 12,
fontSize: isMobile.value ? 32 : 24,
},
xAxisLabels: {
show: false,
values: chartData.value?.dates,
datetimeFormatter: {
enable: true,
locale: locale.value,
useUTC: true,
options: datetimeFormatterOptions.value,
},
},
yAxis: {
formatter,
useNiceScale: true,
},
},
},
timeTag: {
show: true,
backgroundColor: colors.value.bgElevated,
color: colors.value.fg,
fontSize: 16,
circleMarker: {
radius: 3,
color: colors.value.border,
},
useDefaultFormat: true,
timeFormat: 'yyyy-MM-dd HH:mm:ss',
},
highlighter: {
useLine: true,
},
legend: {
show: false, // As long as a single package is displayed
},
tooltip: {
teleportTo: '#chart-modal',
borderColor: 'transparent',
backdropFilter: false,
backgroundColor: 'transparent',
customFormat: ({ datapoint }: { datapoint: Record<string, any> }) => {
if (!datapoint) return ''
const displayValue = formatter({ value: datapoint[0]?.value ?? 0 })
return `<div class="flex flex-col font-mono text-xs p-3 border border-border rounded-md bg-[var(--bg)]/10 backdrop-blur-md">
<span class="text-xl text-[var(--fg)]">${displayValue}</span>
</div>
`
},
},
zoom: {
maxWidth: isMobile.value ? 350 : 500,
highlightColor: colors.value.bgElevated,
minimap: {
show: true,
lineColor: '#FAFAFA',
selectedColor: accent.value,
selectedColorOpacity: 0.06,
frameColor: colors.value.border,
},
preview: {
fill: transparentizeOklch(accent.value, isDarkMode.value ? 0.95 : 0.92),
stroke: transparentizeOklch(accent.value, 0.5),
strokeWidth: 1,
strokeDasharray: 3,
},
},
},
}
})
</script>
<template>
<div class="w-full relative" id="download-analytics">
<div class="w-full mb-4 flex flex-col gap-3">
<!-- Mobile: stack vertically, Desktop: horizontal -->
<div class="flex flex-col sm:flex-row gap-3 sm:gap-2 sm:items-end">
<!-- Granularity -->
<div class="flex flex-col gap-1 sm:shrink-0">
<label
for="granularity"
class="text-[10px] font-mono text-fg-subtle tracking-wide uppercase"
>
{{ $t('package.downloads.granularity') }}
</label>
<div
class="flex items-center px-2.5 py-1.75 bg-bg-subtle border border-border rounded-md focus-within:(border-border-hover ring-2 ring-accent/30)"
>
<select
id="granularity"
v-model="selectedGranularity"
class="w-full bg-bg-subtle font-mono text-sm text-fg outline-none appearance-none"
>
<option value="daily">{{ $t('package.downloads.granularity_daily') }}</option>
<option value="weekly">{{ $t('package.downloads.granularity_weekly') }}</option>
<option value="monthly">{{ $t('package.downloads.granularity_monthly') }}</option>
<option value="yearly">{{ $t('package.downloads.granularity_yearly') }}</option>
</select>
</div>
</div>
<!-- Date range inputs -->
<div class="grid grid-cols-2 gap-2 flex-1">
<div class="flex flex-col gap-1">
<label
for="startDate"
class="text-[10px] font-mono text-fg-subtle tracking-wide uppercase"
>
{{ $t('package.downloads.start_date') }}
</label>
<div
class="flex items-center gap-2 px-2.5 py-1.75 bg-bg-subtle border border-border rounded-md focus-within:(border-border-hover ring-2 ring-accent/30)"
>
<span class="i-carbon:calendar w-4 h-4 text-fg-subtle shrink-0" aria-hidden="true" />
<input
id="startDate"
v-model="startDate"
type="date"
class="w-full min-w-0 bg-transparent font-mono text-sm text-fg outline-none [color-scheme:light] dark:[color-scheme:dark]"
/>
</div>
</div>
<div class="flex flex-col gap-1">
<label
for="endDate"
class="text-[10px] font-mono text-fg-subtle tracking-wide uppercase"
>
{{ $t('package.downloads.end_date') }}
</label>
<div
class="flex items-center gap-2 px-2.5 py-1.75 bg-bg-subtle border border-border rounded-md focus-within:(border-border-hover ring-2 ring-accent/30)"
>
<span class="i-carbon:calendar w-4 h-4 text-fg-subtle shrink-0" aria-hidden="true" />
<input
id="endDate"
v-model="endDate"
type="date"
class="w-full min-w-0 bg-transparent font-mono text-sm text-fg outline-none [color-scheme:light] dark:[color-scheme:dark]"
/>
</div>
</div>
</div>
<!-- Reset button -->
<button
v-if="showResetButton"
type="button"
aria-label="Reset date range"
class="self-end flex items-center justify-center px-2.5 py-1.75 border border-transparent rounded-md text-fg-subtle hover:text-fg transition-colors hover:border-border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 sm:mb-0"
@click="
() => {
hasUserEditedDates = false
startDate = ''
endDate = ''
initDateRangeFromWeekly()
initDateRangeFallbackClient()
}
"
>
<span class="i-carbon:reset w-5 h-5" aria-hidden="true" />
</button>
</div>
</div>
<ClientOnly v-if="inModal && chartData.dataset">
<VueUiXy
:dataset="chartData.dataset"
:config="config"
class="[direction:ltr]"
:key="chartKey"
>
<template #menuIcon="{ isOpen }">
<span v-if="isOpen" class="i-carbon:close w-6 h-6" aria-hidden="true" />
<span v-else class="i-carbon:overflow-menu-vertical w-6 h-6" aria-hidden="true" />
</template>
<template #optionCsv>
<span
class="i-carbon:csv w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #optionImg>
<span
class="i-carbon:png w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #optionSvg>
<span
class="i-carbon:svg w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #annotator-action-close>
<span
class="i-carbon:close w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #annotator-action-color="{ color }">
<span class="i-carbon:color-palette w-6 h-6" :style="{ color }" aria-hidden="true" />
</template>
<template #annotator-action-undo>
<span
class="i-carbon:undo w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #annotator-action-redo>
<span
class="i-carbon:redo w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #annotator-action-delete>
<span
class="i-carbon:trash-can w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
<template #optionAnnotator="{ isAnnotator }">
<span
v-if="isAnnotator"
class="i-carbon:edit-off w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
<span
v-else
class="i-carbon:edit w-6 h-6 text-fg-subtle"
style="pointer-events: none"
aria-hidden="true"
/>
</template>
</VueUiXy>
<template #fallback>
<div class="min-h-[260px]" />
</template>
</ClientOnly>
<!-- Empty state when no chart data -->
<div
v-if="inModal && !chartData.dataset && !pending"
class="min-h-[260px] flex items-center justify-center text-fg-subtle font-mono text-sm"
>
{{ $t('package.downloads.no_data') }}
</div>
<div
v-if="pending"
role="status"
aria-live="polite"
class="absolute top-1/2 inset-is-1/2 -translate-x-1/2 -translate-y-1/2 text-xs text-fg-subtle font-mono bg-bg/70 backdrop-blur px-3 py-2 rounded-md border border-border"
>
{{ $t('package.downloads.loading') }}
</div>
</div>
</template>
<style>
.vue-ui-pen-and-paper-actions {
background: var(--bg-elevated) !important;
}
.vue-ui-pen-and-paper-action {
background: var(--bg-elevated) !important;
border: none !important;
}
.vue-ui-pen-and-paper-action:hover {
background: var(--bg-elevated) !important;
box-shadow: none !important;
}
/* Override default placement of the refresh button to have it to the minimap's side */
#download-analytics .vue-data-ui-refresh-button {
top: -0.6rem !important;
left: calc(100% + 2rem) !important;
}
</style>