import React, { useMemo } from 'react'; interface Props { series: number[]; label?: string; height?: number; } function sparkPath(values: number[], w: number, h: number): string { if (values.length < 2) return ''; const lo = Math.min(...values); const hi = Math.max(...values); const range = hi - lo || 1; return values.map((v, i) => { const x = (i / (values.length - 1)) * w; const y = h - 8 - ((v - lo) / range) * (h - 16); return `${i === 0 ? 'M' : 'L'}${x.toFixed(1)},${y.toFixed(1)}`; }).join(' '); } export default function DashboardSparkChart({ series, label, height = 140 }: Props) { const w = 480; const path = useMemo(() => sparkPath(series, w, height), [series, height]); const area = path ? `${path} L ${w},${height} L 0,${height} Z` : ''; const last = series.length ? series[series.length - 1] : 0; return (
{label && (
{label} {last.toFixed(1)}/s
)} {area && } {path && ( )}
); }