fix: match client-side sparkline behavior to SSR region-aware rendering

This commit is contained in:
2026-03-18 19:31:41 +04:00
parent 6beb7f8039
commit 688245b0c2
2 changed files with 55 additions and 26 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
export function sparkline(values: number[], width = 120, height = 32, color = '#60a5fa'): string {
export function sparkline(values: number[], width = 120, height = 32, color = '#60a5fa', region = '__none__'): string {
if (!values.length) return '';
const max = Math.max(...values, 1);
const min = Math.min(...values, 0);
@@ -9,7 +9,7 @@ export function sparkline(values: number[], width = 120, height = 32, color = '#
const y = height - ((v - min) / range) * (height - 4) - 2;
return `${x},${y}`;
}).join(' ');
return `<svg width="${width}" height="${height}" class="inline-block" data-vals="${values.join(',')}"><polyline points="${points}" fill="none" stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
return `<svg width="${width}" height="${height}" class="inline-block" data-vals="${values.join(',')}" data-region="${region}"><polyline points="${points}" fill="none" stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
}
// Given pings with region+latency, pick the region with the lowest avg latency
@@ -42,5 +42,5 @@ export function sparklineFromPings(pings: Array<{latency_ms?: number|null, regio
}
const color = COLORS[bestRegion] || '#60a5fa';
return sparkline(byRegion[bestRegion], width, height, color);
return sparkline(byRegion[bestRegion], width, height, color, bestRegion);
}