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
26 changes: 25 additions & 1 deletion app/components/Package/TrendsChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,17 @@ const datetimeFormatterOptions = computed(() => {
}[selectedGranularity.value]
})

// Cached date formatter for tooltip
const tooltipDateFormatter = computed(() => {
const granularity = displayedGranularity.value
return new Intl.DateTimeFormat(locale.value, {
year: 'numeric',
month: granularity === 'yearly' ? undefined : 'short',
day: granularity === 'daily' || granularity === 'weekly' ? 'numeric' : undefined,
timeZone: 'UTC',
})
})

const sanitise = (value: string) =>
value
.replace(/^@/, '')
Expand Down Expand Up @@ -1598,11 +1609,23 @@ const chartConfig = computed<VueUiXyConfig>(() => {
borderColor: 'transparent',
backdropFilter: false,
backgroundColor: 'transparent',
customFormat: ({ datapoint: items }) => {
customFormat: ({ datapoint: items, absoluteIndex }) => {
if (!items || pending.value) return ''

const hasMultipleItems = items.length > 1

// Format date for multiple series datasets
let formattedDate = ''
if (hasMultipleItems && absoluteIndex !== undefined) {
const index = Number(absoluteIndex)
if (Number.isInteger(index) && index >= 0 && index < chartData.value.dates.length) {
const timestamp = chartData.value.dates[index]
if (typeof timestamp === 'number') {
formattedDate = tooltipDateFormatter.value.format(new Date(timestamp))
}
}
}

const rows = items
.map((d: Record<string, any>) => {
const label = String(d?.name ?? '').trim()
Expand Down Expand Up @@ -1635,6 +1658,7 @@ const chartConfig = computed<VueUiXyConfig>(() => {
.join('')

return `<div class="font-mono text-xs p-3 border border-border rounded-md bg-[var(--bg)]/10 backdrop-blur-md">
${formattedDate ? `<div class="text-2xs text-[var(--fg-subtle)] mb-2">${formattedDate}</div>` : ''}
<div class="${hasMultipleItems ? 'flex flex-col gap-2' : ''}">
${rows}
</div>
Expand Down
Loading