{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hud-line-chart",
  "type": "registry:ui",
  "title": "HUD Line Chart",
  "description": "Dependency-free SVG time-series plot: multi-series with dash-pattern separation, axis grid, caution band, direct end-labels and a hover crosshair readout.",
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/hud/hud-line-chart.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/lib/utils\"\n\n// Time-series plot drawn as inline SVG — no charting dependency, matching radar\n// and dot-globe. Series are separated by LIGHTNESS plus a dash pattern, not by\n// hue: this kit is monochrome + one accent by design, so colour alone would not\n// distinguish them. The four steps below are the validated order (CVD and\n// normal-vision separation both ΔE 16.4); --chart-5 (red) is deliberately absent\n// because it is reserved as a status colour. Past 4 series, facet instead of\n// inventing a fifth hue.\nconst SERIES_COLORS = [\n  \"var(--chart-1)\", // #FF7A29 accent\n  \"var(--chart-3)\", // #C8CCCE\n  \"var(--chart-2)\", // #8A9094\n  \"var(--chart-4)\", // #5A6065 — below 3:1 on card; direct labels are mandatory relief\n]\n\nconst SERIES_DASH = [\"\", \"5 3\", \"2 3\", \"8 3 2 3\"]\n\ntype LineSeries = {\n  name: string\n  values: number[]\n}\n\n/** Measures the host element so text renders at true pixel size (the kit's\n *  10px minimum would break under a scaled viewBox). */\nfunction useWidth(ref: React.RefObject<HTMLDivElement | null>) {\n  const [width, setWidth] = React.useState(0)\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el) return\n    const ro = new ResizeObserver(([e]) => setWidth(e.contentRect.width))\n    ro.observe(el)\n    return () => ro.disconnect()\n  }, [ref])\n  return width\n}\n\nfunction niceTicks(min: number, max: number, count: number) {\n  const raw = (max - min) / count\n  const mag = Math.pow(10, Math.floor(Math.log10(raw || 1)))\n  const step = [1, 2, 2.5, 5, 10].find((s) => s * mag >= raw)! * mag\n  const ticks: number[] = []\n  for (let v = Math.ceil(min / step) * step; v <= max + 1e-9; v += step) ticks.push(v)\n  return ticks\n}\n\nfunction HudLineChart({\n  className,\n  series,\n  labels,\n  min: minProp,\n  max: maxProp,\n  band,\n  unit = \"\",\n  height = 200,\n  area = false,\n  legend = true,\n  ...props\n}: Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  series: LineSeries[]\n  /** X tick labels, one per data point. Thinned automatically to avoid collision. */\n  labels?: string[]\n  min?: number\n  max?: number\n  /** Shaded caution range, in data units. */\n  band?: { from: number; to: number }\n  unit?: string\n  height?: number\n  area?: boolean\n  legend?: boolean\n}) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const width = useWidth(ref)\n  const [hover, setHover] = React.useState<number | null>(null)\n\n  const count = Math.max(...series.map((s) => s.values.length), 0)\n  const all = series.flatMap((s) => s.values)\n  const lo = minProp ?? Math.min(...all, band?.from ?? Infinity)\n  const hi = maxProp ?? Math.max(...all, band?.to ?? -Infinity)\n  const span = hi - lo || 1\n\n  // Right padding leaves room for the direct end-labels that carry series identity.\n  const pad = { l: 40, r: 46, t: 10, b: labels ? 22 : 8 }\n  const plotW = Math.max(0, width - pad.l - pad.r)\n  const plotH = height - pad.t - pad.b\n\n  const x = (i: number) => pad.l + (count > 1 ? (i / (count - 1)) * plotW : plotW / 2)\n  const y = (v: number) => pad.t + plotH - ((v - lo) / span) * plotH\n\n  const yTicks = niceTicks(lo, hi, 4)\n\n  // End-labels are the primary identity cue, so they must never overlap: lay them\n  // out top-down and push each one clear of the previous by a full line.\n  const endLabels = series\n    .map((s, si) => ({ si, value: s.values[s.values.length - 1] }))\n    .filter((e) => e.value !== undefined)\n    .map((e) => ({ ...e, y: y(e.value) }))\n    .sort((a, b) => a.y - b.y)\n  for (let i = 1; i < endLabels.length; i++) {\n    endLabels[i].y = Math.max(endLabels[i].y, endLabels[i - 1].y + 12)\n  }\n  const overflow = endLabels.length\n    ? Math.max(0, endLabels[endLabels.length - 1].y - (height - 4))\n    : 0\n  endLabels.forEach((e) => (e.y -= overflow))\n  // Thin X labels to whatever fits at 10px rather than shrinking the type.\n  const xStride = Math.max(1, Math.ceil(count / Math.max(1, Math.floor(plotW / 56))))\n\n  function onMove(e: React.MouseEvent<HTMLDivElement>) {\n    if (count < 2 || plotW <= 0) return\n    const rel = e.clientX - e.currentTarget.getBoundingClientRect().left - pad.l\n    setHover(Math.max(0, Math.min(count - 1, Math.round((rel / plotW) * (count - 1)))))\n  }\n\n  return (\n    <div className={cn(\"w-full\", className)} {...props}>\n      {legend && series.length > 1 && (\n        <div className=\"mb-2 flex flex-wrap items-center gap-x-4 gap-y-1\">\n          {series.map((s, i) => (\n            <span key={s.name} className=\"flex items-center gap-1.5\">\n              <svg width=\"14\" height=\"2\" aria-hidden>\n                <line\n                  x1=\"0\"\n                  y1=\"1\"\n                  x2=\"14\"\n                  y2=\"1\"\n                  stroke={SERIES_COLORS[i % SERIES_COLORS.length]}\n                  strokeWidth=\"2\"\n                  strokeDasharray={SERIES_DASH[i % SERIES_DASH.length]}\n                />\n              </svg>\n              <span className=\"font-mono text-[10px] uppercase tracking-[0.14em] text-[#7A8085]\">\n                {s.name}\n              </span>\n            </span>\n          ))}\n        </div>\n      )}\n\n      <div\n        ref={ref}\n        className=\"relative\"\n        style={{ height }}\n        onMouseMove={onMove}\n        onMouseLeave={() => setHover(null)}\n      >\n        {width > 0 && (\n          <svg width={width} height={height} className=\"block\">\n            {band && (\n              <g>\n                <rect\n                  x={pad.l}\n                  y={Math.min(y(band.from), y(band.to))}\n                  width={plotW}\n                  height={Math.abs(y(band.from) - y(band.to))}\n                  fill=\"var(--warning)\"\n                  opacity={0.08}\n                />\n                {/* Dashed edges keep the band reading as a threshold rather than\n                    as another filled series. */}\n                {[band.from, band.to].map((v) =>\n                  v <= lo || v >= hi ? null : (\n                    <line\n                      key={v}\n                      x1={pad.l}\n                      y1={y(v)}\n                      x2={pad.l + plotW}\n                      y2={y(v)}\n                      stroke=\"var(--warning)\"\n                      strokeWidth=\"1\"\n                      strokeDasharray=\"3 3\"\n                      opacity={0.4}\n                    />\n                  )\n                )}\n              </g>\n            )}\n\n            {yTicks.map((t) => (\n              <g key={t}>\n                <line\n                  x1={pad.l}\n                  y1={y(t)}\n                  x2={pad.l + plotW}\n                  y2={y(t)}\n                  stroke=\"#1D2023\"\n                  strokeWidth=\"1\"\n                />\n                <text\n                  x={pad.l - 8}\n                  y={y(t)}\n                  textAnchor=\"end\"\n                  dominantBaseline=\"middle\"\n                  className=\"font-mono\"\n                  fontSize=\"10\"\n                  fill=\"#5A6065\"\n                >\n                  {t}\n                </text>\n              </g>\n            ))}\n\n            {labels &&\n              labels.map((l, i) =>\n                i % xStride === 0 ? (\n                  <text\n                    key={i}\n                    x={x(i)}\n                    y={height - 6}\n                    textAnchor=\"middle\"\n                    className=\"font-mono\"\n                    fontSize=\"10\"\n                    fill=\"#5A6065\"\n                  >\n                    {l}\n                  </text>\n                ) : null\n              )}\n\n            {series.map((s, si) => {\n              const color = SERIES_COLORS[si % SERIES_COLORS.length]\n              const d = s.values.map((v, i) => `${i ? \"L\" : \"M\"}${x(i)},${y(v)}`).join(\" \")\n              return (\n                <g key={s.name}>\n                  {area && (\n                    <path\n                      d={`${d} L${x(s.values.length - 1)},${pad.t + plotH} L${x(0)},${pad.t + plotH} Z`}\n                      fill={color}\n                      opacity={0.1}\n                    />\n                  )}\n                  <path\n                    d={d}\n                    fill=\"none\"\n                    stroke={color}\n                    strokeWidth=\"2\"\n                    strokeDasharray={SERIES_DASH[si % SERIES_DASH.length]}\n                  />\n                </g>\n              )\n            })}\n\n            {/* Direct end-labels: required relief for the darkest step and the\n                reason identity never rests on colour alone. */}\n            {endLabels.map((e) => (\n              <text\n                key={e.si}\n                x={pad.l + plotW + 6}\n                y={e.y}\n                dominantBaseline=\"middle\"\n                className=\"font-mono\"\n                fontSize=\"10\"\n                fill={SERIES_COLORS[e.si % SERIES_COLORS.length]}\n              >\n                {e.value}\n                {unit}\n              </text>\n            ))}\n\n            {hover !== null && (\n              <g>\n                <line\n                  x1={x(hover)}\n                  y1={pad.t}\n                  x2={x(hover)}\n                  y2={pad.t + plotH}\n                  stroke=\"var(--primary)\"\n                  strokeWidth=\"1\"\n                  opacity={0.5}\n                />\n                {series.map((s, si) =>\n                  s.values[hover] === undefined ? null : (\n                    <circle\n                      key={s.name}\n                      cx={x(hover)}\n                      cy={y(s.values[hover])}\n                      r=\"4\"\n                      fill={SERIES_COLORS[si % SERIES_COLORS.length]}\n                      stroke=\"var(--card)\"\n                      strokeWidth=\"2\"\n                    />\n                  )\n                )}\n              </g>\n            )}\n          </svg>\n        )}\n\n        {hover !== null && (\n          <div\n            className=\"pointer-events-none absolute top-0 z-10 border border-border bg-popover px-2.5 py-1.5\"\n            style={{\n              left: Math.min(Math.max(x(hover) + 10, 0), Math.max(width - 132, 0)),\n              minWidth: 122,\n            }}\n          >\n            {labels?.[hover] && (\n              <div className=\"mb-1 font-mono text-[10px] uppercase tracking-[0.14em] text-[#5A6065]\">\n                {labels[hover]}\n              </div>\n            )}\n            {series.map((s, si) => (\n              <div key={s.name} className=\"flex items-center justify-between gap-3\">\n                <span className=\"flex items-center gap-1.5\">\n                  <span\n                    className=\"size-1.5\"\n                    style={{ background: SERIES_COLORS[si % SERIES_COLORS.length] }}\n                  />\n                  <span className=\"font-mono text-[10px] uppercase tracking-[0.12em] text-[#7A8085]\">\n                    {s.name}\n                  </span>\n                </span>\n                <span className=\"font-mono text-[10px] text-[#D4D8DA]\">\n                  {s.values[hover]}\n                  {unit}\n                </span>\n              </div>\n            ))}\n          </div>\n        )}\n      </div>\n    </div>\n  )\n}\n\nexport { HudLineChart, type LineSeries }\n",
      "type": "registry:ui"
    }
  ]
}