fix: match client-side sparkline behavior to SSR region-aware rendering
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user