import { useEffect, useState } from 'react' import { Line } from 'react-chartjs-2' import { Chart as ChartJS, LinearScale, PointElement, LineElement, Tooltip, Filler, } from 'chart.js' import { MonitorState, MonitorTarget } from '@/types/config' import { codeToCountry } from '@/util/iata' import { formatTime } from '@/util/status' ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Filler) // Chart.js draws on a canvas, so read the brand tokens from CSS (and again if the theme changes). function useTokens() { const read = () => { const s = getComputedStyle(document.documentElement) const v = (n: string) => s.getPropertyValue(n).trim() return { moss: v('--moss'), mossSoft: v('--moss-soft'), line: v('--line'), muted: v('--ink-muted'), ink: v('--ink'), raised: v('--paper-raised'), strong: v('--line-strong') } } const [t, setT] = useState(read) useEffect(() => { const obs = new MutationObserver(() => setT(read())) obs.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }) return () => obs.disconnect() }, []) return t } export default function LatencyChart({ monitor, state }: { monitor: MonitorTarget; state: MonitorState }) { const t = useTokens() const points = (state.latency[monitor.id] || []).map((p) => ({ x: p.time, y: p.ping, loc: p.loc })) const font = { family: getComputedStyle(document.body).fontFamily, size: 12 } return (