| | 0 | 1 | | export function Sparkline({ seed }: { seed: number }) { |
| | 0 | 2 | | const w = 56, h = 20, n = 7; |
| | 0 | 3 | | const pts = Array.from({ length: n }, (_, i) => i).reduce<number[]>((acc, i) => { |
| | 0 | 4 | | const prev = acc.length > 0 ? acc[acc.length - 1]! : Math.max(1, seed * 0.5); |
| | 0 | 5 | | const noise = ((seed * (i * 13 + 7)) % 7) - 3; |
| | 0 | 6 | | const next = Math.max(1, prev + (seed - prev) * 0.35 + noise); |
| | 0 | 7 | | acc.push(i === n - 1 ? seed : Math.round(next)); |
| | 0 | 8 | | return acc; |
| | | 9 | | }, []); |
| | 0 | 10 | | const max = Math.max(...pts, 1); |
| | 0 | 11 | | const coords = pts |
| | 0 | 12 | | .map((p, i) => `${((i / (n - 1)) * w).toFixed(1)},${(h - (p / max) * h).toFixed(1)}`) |
| | | 13 | | .join(" "); |
| | 0 | 14 | | return ( |
| | | 15 | | <svg width={w} height={h} style={{ flexShrink: 0, overflow: "visible" }}> |
| | | 16 | | <polyline fill="none" stroke="var(--c-accent)" strokeWidth="1.4" |
| | | 17 | | strokeLinecap="round" strokeLinejoin="round" points={coords} opacity="0.8" /> |
| | | 18 | | </svg> |
| | | 19 | | ); |
| | | 20 | | } |