"use client"; import type { HistoryPoint } from "@dci/core"; import { useMemo } from "react"; import { LineChart, type Series } from "@/components/ui/charts"; import { SourceBadge } from "@/components/ui/source-badge"; import { fieldLabel } from "@/lib/field-labels"; import { fmtDate, fmtMw } from "@/lib/format"; import { Evidence } from "./evidence-context"; const COLORS: Record = { itCapacityMw: "var(--ink)", totalPowerMw: "var(--st-planned)", plannedPowerMw: "var(--accent)", plannedMw: "var(--accent)", utilityCapacityMw: "var(--st-permitting)", gridConnectionMw: "var(--st-permitting)", ultimateCampusMw: "var(--st-construction)", }; /** * Capacity history: step chart of every observed / changed MW value per field (values hold until the next * observation). With fewer than two dated points it degrades to a dated list so nothing is drawn that the data * cannot support. */ export function CapacityHistoryChart({ points, height = 180 }: { points: HistoryPoint[]; height?: number }) { const mw = useMemo(() => points.filter((p) => /Mw$|_mw$/.test(p.field) && typeof p.value === "number").sort((a, b) => (a.date < b.date ? -1 : 1)), [points]); const series = useMemo(() => { const by = new Map(); for (const p of mw) { const f = p.field.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase()); if (!by.has(f)) by.set(f, []); by.get(f)!.push(p); } return Array.from(by.entries()).map(([field, pts]) => ({ name: fieldLabel(field), color: COLORS[field] ?? "var(--ink-3)", step: true, dashed: /planned/i.test(field), data: pts.map((p) => ({ x: p.date.slice(0, 10), y: p.value as number })) })); }, [mw]); const dates = new Set(mw.map((p) => p.date.slice(0, 10))); if (!mw.length) return

No MW figure has been observed for this record — no history to chart.

; return (
{dates.size >= 2 ? ( fmtMw(v)} ariaLabel="Capacity history — observed MW values by date" /> ) : (

One observation date so far — the step chart appears once a second dated value exists.

)}
    {[...mw].reverse().slice(0, 12).map((p, i) => (
  • {fieldLabel(p.field)} {p.sourceKind && } {p.kind}
    {typeof p.oldValue === "number" && {fmtMw(p.oldValue)}} {fmtMw(p.value as number)}
  • ))}
); }