"use client" interface LatencyChartProps { series: Record } // Maps to CSS variables defined in globals.css const COLORS: Record = { msk: "var(--chart-line-1)", spb: "var(--chart-line-2)", fra: "var(--chart-line-3)", ams: "var(--chart-line-4)", } const LABELS: Record = { msk: "MSK", spb: "SPB", fra: "FRA", ams: "AMS", } export function LatencyChart({ series }: LatencyChartProps) { const W = 800, H = 220 const pad = { l: 44, r: 12, t: 12, b: 28 } const iw = W - pad.l - pad.r const ih = H - pad.t - pad.b const allVals = Object.values(series).flat() const maxVal = Math.ceil(Math.max(...allVals) / 20) * 20 + 10 const xAt = (i: number, n: number) => pad.l + (i / (n - 1)) * iw const yAt = (v: number) => pad.t + (1 - v / maxVal) * ih const gridLines = [0, 0.25, 0.5, 0.75, 1] return (
{gridLines.map((p, i) => ( {Math.round(maxVal * (1 - p))}мс ))} {[0, 15, 30, 45, 59].map((i) => ( -{60 - i}м ))} {Object.entries(series).map(([key, arr]) => { const pts = arr.map((v, i) => `${xAt(i, arr.length).toFixed(1)},${yAt(v).toFixed(1)}`).join(" ") const color = COLORS[key] ?? "var(--chart-line-1)" return ( ) })}
{Object.keys(series).map((k) => { const color = COLORS[k] ?? "var(--chart-line-1)" return (
{LABELS[k]}
) })}
) }