interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / docs / archive / drakestapleton.com-old / src / components / VolumeChart.tsx

47 lines · 1615 bytes Raw Blame History
1import { VOLUME } from "../data/portfolio";
2
3function fmt(n: number): string {
4 if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
5 if (n >= 1000) return `${Math.round(n / 1000)}k`;
6 return String(n);
7}
8
9export function VolumeChart() {
10 const { months, added } = VOLUME;
11 const w = 960;
12 const h = 220;
13 const pad = { t: 16, r: 48, b: 28, l: 8 };
14 const max = Math.max(...added);
15 let run = 0;
16 const cum = added.map((n) => (run += n));
17 const maxC = cum[cum.length - 1];
18 const bw = (w - pad.l - pad.r) / added.length;
19 const bars = added.map((n, i) => {
20 const bh = (n / max) * (h - pad.t - pad.b);
21 return { x: pad.l + i * bw + 4, y: h - pad.b - bh, h: bh, n };
22 });
23 const line = cum
24 .map((n, i) => {
25 const x = pad.l + i * bw + bw / 2;
26 const y = h - pad.b - (n / maxC) * (h - pad.t - pad.b);
27 return `${i === 0 ? "M" : "L"}${x.toFixed(1)},${y.toFixed(1)}`;
28 })
29 .join(" ");
30
31 return (
32 <svg className="chart" viewBox={`0 0 ${w} ${h}`} role="img" aria-label="Monthly source added and cumulative">
33 {bars.map((b, i) => (
34 <rect key={months[i]} x={b.x} y={b.y} width={bw - 8} height={Math.max(b.h, 0)} fill="#7fb8a6cc" rx="3" />
35 ))}
36 <path d={line} fill="none" stroke="#a9462b" strokeWidth="2" />
37 {months.map((m, i) => (
38 <text key={m} x={pad.l + i * bw + bw / 2} y={h - 8} textAnchor="middle" fill="#6d626a" fontSize="9">
39 {m}
40 </text>
41 ))}
42 <text x={w - 4} y={18} textAnchor="end" fill="#6d626a" fontSize="10">
43 peak {fmt(max)} ยท total {fmt(maxC)}
44 </text>
45 </svg>
46 );
47}