{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "neon-pulse-line-chart",
  "title": "Neon Pulse Line Chart",
  "description": "A calm line with a bright pulse travelling along it, lighting up a row of heat cells as it passes. Three stats, a one-line readout and keyboard day inspection.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/neon-pulse-line-chart/neon-pulse-line-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PulsePoint {\n  /** ISO date, YYYY-MM-DD. */\n  date: string;\n  value: number;\n}\n\nexport interface NeonPulseLineChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  /** Line under the title. Worked out from the data when left out. */\n  subtitle?: string;\n  data?: PulsePoint[];\n  /** Colour of the line, pulse and cells. */\n  color?: string;\n  /** Seconds between pulses. */\n  pulseSeconds?: number;\n  /** Height of the plot, in px. */\n  height?: number;\n  /** Word after the value in the readout. */\n  unit?: string;\n  formatValue?: (value: number) => string;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    text: \"#F7F8F8\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    empty: \"#16171A\",\n    tip: \"#161718\",\n    tipShadow: \"0 4px 24px rgba(0,0,0,0.4)\",\n    chip: \"rgba(255,255,255,0.05)\",\n    chipOn: \"rgba(255,255,255,0.1)\",\n    ring: \"#F7F8F8\",\n    accent: \"#2EE6A8\",\n    glow: 0.8,\n    /** How much the pulse brightens a cell. Pale cells on white are darkened instead, or they would vanish. */\n    lift: 1.2,\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    text: \"#08090A\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    empty: \"#EEEFF1\",\n    tip: \"#FFFFFF\",\n    tipShadow: \"0 3px 12px rgba(8,9,10,0.09)\",\n    chip: \"rgba(8,9,10,0.04)\",\n    chipOn: \"#FFFFFF\",\n    ring: \"#08090A\",\n    accent: \"#0E9F6E\",\n    glow: 0.35,\n    lift: -0.4,\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst DAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\nconst MONTHS = [\n  \"Jan\",\n  \"Feb\",\n  \"Mar\",\n  \"Apr\",\n  \"May\",\n  \"Jun\",\n  \"Jul\",\n  \"Aug\",\n  \"Sep\",\n  \"Oct\",\n  \"Nov\",\n  \"Dec\",\n];\n\nconst LEFT = 40;\nconst RIGHT = 8;\nconst TOP = 10;\n\nfunction parse(date: string) {\n  const [y, m, d] = date.split(\"-\").map(Number);\n  return new Date(Date.UTC(y, m - 1, d));\n}\n\n/** \"Dec 3\" */\nfunction shortDate(date: string) {\n  const d = parse(date);\n  return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;\n}\n\n/** \"Wed, Dec 3\" */\nfunction longDate(date: string) {\n  return `${DAYS[parse(date).getUTCDay()]}, ${shortDate(date)}`;\n}\n\n/** A fixed, believable daily series: a trend, a weekly rhythm and integer noise, so server and client agree. */\nfunction makeSeries(seed: number, length: number, base: number, rise: number) {\n  const week = [0, 12, 18, 16, 10, -24, -30];\n  const end = Date.UTC(2025, 11, 31);\n  let state = seed;\n  return Array.from({ length }, (_, i) => {\n    state = (state * 9301 + 49297) % 233280;\n    const noise = Math.round((state / 233280 - 0.5) * 34);\n    const when = new Date(end - (length - 1 - i) * 86400000);\n    return {\n      date: when.toISOString().slice(0, 10),\n      value: Math.round(\n        (base + (rise * i) / length) *\n          (1 + (week[when.getUTCDay()] + noise) / 100),\n      ),\n    };\n  });\n}\n\nfunction mix(a: string, b: string, t: number) {\n  const channels = (hex: string) =>\n    [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));\n  const [x, y] = [channels(a), channels(b)];\n  return `rgb(${x.map((v, i) => Math.round(v + (y[i] - v) * t)).join(\",\")})`;\n}\n\n/** Five levels from the quartiles, so one huge day does not wash out the rest. */\nfunction levels(values: number[]) {\n  const sorted = [...values].sort((a, b) => a - b);\n  const at = (p: number) => sorted[Math.floor(p * (sorted.length - 1))] ?? 0;\n  const cuts = [at(0.2), at(0.45), at(0.7), at(0.9)];\n  return values.map((v) => cuts.filter((c) => v > c).length);\n}\n\nconst LEVEL_MIX = [0.12, 0.3, 0.52, 0.76, 1];\n\n// Monotone cubic interpolation preserves local extrema and never overshoots the data.\nfunction curve(points: [number, number][]) {\n  if (points.length < 2) return \"\";\n  const slopes = points\n    .slice(1)\n    .map((p, i) => (p[1] - points[i][1]) / (p[0] - points[i][0]));\n  const tangents = points.map((_, i) =>\n    i === 0\n      ? slopes[0]\n      : i === points.length - 1\n        ? slopes[i - 1]\n        : slopes[i - 1] * slopes[i] <= 0\n          ? 0\n          : (slopes[i - 1] + slopes[i]) / 2,\n  );\n  return (\n    `M${points[0][0].toFixed(1)},${points[0][1].toFixed(1)}` +\n    points\n      .slice(1)\n      .map((p, i) => {\n        const prev = points[i];\n        const dx = (p[0] - prev[0]) / 3;\n        return `C${(prev[0] + dx).toFixed(1)},${(prev[1] + dx * tangents[i]).toFixed(1)} ${(p[0] - dx).toFixed(1)},${(p[1] - dx * tangents[i + 1]).toFixed(1)} ${p[0].toFixed(1)},${p[1].toFixed(1)}`;\n      })\n      .join(\"\")\n  );\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** The chart is drawn at its real width, so its text stays the same size on a phone. */\nfunction useWidth(ref: React.RefObject<HTMLElement | null>) {\n  const [width, setWidth] = React.useState(700);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) =>\n      setWidth(Math.max(240, Math.round(entry.contentRect.width))),\n    );\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [ref]);\n  return width;\n}\n\nfunction Stat({\n  value,\n  label,\n  pal,\n}: {\n  value: string;\n  label: string;\n  pal: Palette;\n}) {\n  return (\n    <div className=\"text-left sm:text-right\">\n      <p className=\"m-0 text-[18px] leading-[1.2] font-[510] tracking-[-0.018em] tabular-nums\">\n        {value}\n      </p>\n      <p\n        className=\"m-0 mt-0.5 text-[12px] tracking-[-0.011em]\"\n        style={{ color: pal.sub }}\n      >\n        {label}\n      </p>\n    </div>\n  );\n}\n\nfunction Legend({ pal, accent }: { pal: Palette; accent: string }) {\n  return (\n    <div\n      className=\"flex items-center gap-1 text-[12px]\"\n      style={{ color: pal.sub }}\n    >\n      <span className=\"mr-1\">Less</span>\n      {LEVEL_MIX.map((t) => (\n        <span\n          key={t}\n          className=\"size-2.5 rounded-[3px]\"\n          style={{ background: mix(pal.empty, accent, t) }}\n        />\n      ))}\n      <span className=\"ml-1\">More</span>\n    </div>\n  );\n}\n\nfunction Tip({\n  x,\n  y,\n  width,\n  pal,\n  children,\n}: {\n  x: number;\n  y: number;\n  width: number;\n  pal: Palette;\n  children: React.ReactNode;\n}) {\n  return (\n    <div\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute z-10 -translate-x-1/2 rounded-lg px-2.5 py-1.5 text-[12px] tracking-[-0.011em] whitespace-nowrap\"\n      style={{\n        left: Math.max(92, Math.min(width - 92, x)),\n        top: Math.max(0, y - 42),\n        background: pal.tip,\n        color: pal.sub,\n        boxShadow: `inset 0 0 0 1px ${pal.border}, ${pal.tipShadow}`,\n      }}\n    >\n      {children}\n    </div>\n  );\n}\n\nconst CARD_FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\n\nconst DEFAULT_DATA: PulsePoint[] = makeSeries(11, 60, 620, 460);\nconst FORMAT = (n: number) => Math.round(n).toLocaleString(\"en-US\");\n\nexport function NeonPulseLineChart({\n  theme = \"dark\",\n  title = \"Request pulse\",\n  subtitle,\n  data = DEFAULT_DATA,\n  color,\n  pulseSeconds = 3.2,\n  height = 200,\n  unit = \"req/s\",\n  formatValue = FORMAT,\n  className,\n  style,\n  ...props\n}: NeonPulseLineChartProps) {\n  const pal = PALETTES[theme];\n  const accent = color ?? pal.accent;\n  const reduce = useReducedMotion();\n  const id = React.useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const width = useWidth(boxRef);\n  const pathRef = React.useRef<SVGPathElement>(null);\n  const glowRef = React.useRef<SVGPathElement>(null);\n  const coreRef = React.useRef<SVGPathElement>(null);\n  const headRef = React.useRef<SVGGElement>(null);\n  const cellRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const [active, setActive] = React.useState<number | null>(null);\n\n  const count = data.length;\n  const values = data.map((d) => d.value);\n  const max = Math.max(1, ...values) * 1.08;\n  const span = width - LEFT - RIGHT;\n  const x = (i: number) => LEFT + ((i + 0.5) / Math.max(1, count)) * span;\n  const y = (v: number) => height - 2 - (v / max) * (height - TOP - 2);\n  const line = curve(data.map((d, i) => [x(i), y(d.value)]));\n  const level = levels(values);\n  const every = Math.max(1, Math.ceil(count / Math.floor(width / 96)));\n  const peak = Math.max(0, ...values);\n  const average = values.reduce((n, v) => n + v, 0) / Math.max(1, count);\n  const point = active === null ? null : data[active];\n\n  // The pulse runs on the clock from one loop and writes straight to the elements, and only while it is on screen.\n  React.useEffect(() => {\n    const path = pathRef.current;\n    const glow = glowRef.current;\n    const core = coreRef.current;\n    const head = headRef.current;\n    const box = boxRef.current;\n    if (!path || !glow || !core || !head || !box || reduce) return;\n    const cycle = Math.max(0.6, pulseSeconds) * 1000;\n    let raf = 0;\n    const frame = (now: number) => {\n      const length = path.getTotalLength();\n      const trail = Math.max(70, length * 0.16);\n      const p = (now % cycle) / (cycle * 0.84);\n      const on = p <= 1;\n      const at = Math.min(1, p) * length;\n      const fade = on ? Math.min(1, p / 0.06, (1 - p) / 0.06 + 0.02) : 0;\n      for (const el of [glow, core]) {\n        el.style.strokeDasharray = `${trail} ${length + trail}`;\n        el.style.strokeDashoffset = `${trail - at}`;\n      }\n      glow.style.opacity = `${fade * 0.9}`;\n      core.style.opacity = `${fade}`;\n      const dot = path.getPointAtLength(at);\n      head.style.transform = `translate(${dot.x}px, ${dot.y}px)`;\n      head.style.opacity = `${fade}`;\n      const reach = (box.clientWidth - LEFT - RIGHT) * 0.05;\n      cellRefs.current.forEach((cell, i) => {\n        if (!cell) return;\n        const cx =\n          LEFT +\n          ((i + 0.5) / cellRefs.current.length) *\n            (box.clientWidth - LEFT - RIGHT);\n        const lit = on ? Math.exp(-(((cx - dot.x) / reach) ** 2)) : 0;\n        cell.style.filter =\n          lit > 0.02 ? `brightness(${1 + lit * pal.lift})` : \"\";\n      });\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(box);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [reduce, pulseSeconds, line, pal.lift]);\n\n  const inspect = (clientX: number, el: Element) => {\n    const r = el.getBoundingClientRect();\n    const i = Math.floor(((clientX - r.left - LEFT) / span) * count);\n    setActive(Math.max(0, Math.min(count - 1, i)));\n  };\n\n  return (\n    <section\n      className={`w-full rounded-2xl p-5 sm:p-6 ${className ?? \"\"}`}\n      style={{\n        background: pal.card,\n        boxShadow: `inset 0 0 0 1px ${pal.border}`,\n        color: pal.text,\n        fontFamily: CARD_FONT,\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-start justify-between gap-x-8 gap-y-3\">\n        <div>\n          <h3 className=\"m-0 text-[17px] leading-[1.33] font-[590] tracking-[-0.012em]\">\n            {title}\n          </h3>\n          <p\n            className=\"m-0 mt-0.5 text-[13px] tracking-[-0.011em]\"\n            style={{ color: pal.sub }}\n          >\n            {subtitle ?? `Daily average, last ${count} days`}\n          </p>\n        </div>\n        <div className=\"flex gap-7\">\n          <Stat\n            value={formatValue(values[count - 1] ?? 0)}\n            label=\"Latest\"\n            pal={pal}\n          />\n          <Stat value={formatValue(average)} label=\"Average\" pal={pal} />\n          <Stat value={formatValue(peak)} label=\"Peak\" pal={pal} />\n        </div>\n      </div>\n\n      {count < 2 ? (\n        <p className=\"py-16 text-center text-sm\" style={{ color: pal.sub }}>\n          No data available.\n        </p>\n      ) : (\n        <div\n          ref={boxRef}\n          className=\"relative mt-5 rounded-lg outline-none focus-visible:ring-2\"\n          tabIndex={0}\n          role=\"group\"\n          aria-label={`${title}. Use left and right arrow keys to read each day.`}\n          onPointerMove={(e) => inspect(e.clientX, e.currentTarget)}\n          onPointerLeave={() => setActive(null)}\n          onBlur={() => setActive(null)}\n          onKeyDown={(e) => {\n            if (e.key !== \"ArrowLeft\" && e.key !== \"ArrowRight\") return;\n            e.preventDefault();\n            const dir = e.key === \"ArrowRight\" ? 1 : -1;\n            setActive((a) =>\n              Math.max(0, Math.min(count - 1, (a ?? count) + dir)),\n            );\n          }}\n        >\n          <svg\n            viewBox={`0 0 ${width} ${height}`}\n            className=\"block w-full\"\n            style={{ height }}\n            role=\"img\"\n            aria-label={\n              point\n                ? `${longDate(point.date)}: ${formatValue(point.value)} ${unit}`\n                : `Latest ${formatValue(values[count - 1])} ${unit}`\n            }\n          >\n            <defs>\n              <linearGradient id={`${id}-fill`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                <stop stopColor={accent} stopOpacity=\"0.14\" />\n                <stop offset=\"1\" stopColor={accent} stopOpacity=\"0\" />\n              </linearGradient>\n              <filter\n                id={`${id}-glow`}\n                x=\"-5%\"\n                y=\"-40%\"\n                width=\"110%\"\n                height=\"180%\"\n              >\n                <feGaussianBlur stdDeviation=\"5\" />\n              </filter>\n            </defs>\n            {[0, 0.5, 1].map((t) => (\n              <g key={t}>\n                <line\n                  x1={LEFT}\n                  x2={width - RIGHT}\n                  y1={y(max * t)}\n                  y2={y(max * t)}\n                  stroke={pal.grid}\n                />\n                <text\n                  x={LEFT - 8}\n                  y={y(max * t) + 4}\n                  textAnchor=\"end\"\n                  fontSize=\"11\"\n                  fill={pal.faint}\n                >\n                  {formatValue(max * t)}\n                </text>\n              </g>\n            ))}\n            <path\n              d={`${line}L${x(count - 1)},${height}L${x(0)},${height}Z`}\n              fill={`url(#${id}-fill)`}\n            />\n            <path\n              ref={pathRef}\n              d={line}\n              fill=\"none\"\n              stroke={accent}\n              strokeOpacity=\"0.5\"\n              strokeWidth=\"1.5\"\n              strokeLinecap=\"round\"\n            />\n            <path\n              ref={glowRef}\n              d={line}\n              fill=\"none\"\n              stroke={accent}\n              strokeWidth=\"7\"\n              strokeLinecap=\"round\"\n              filter={`url(#${id}-glow)`}\n              opacity=\"0\"\n              strokeOpacity={pal.glow}\n            />\n            <path\n              ref={coreRef}\n              d={line}\n              fill=\"none\"\n              stroke={accent}\n              strokeWidth=\"2.25\"\n              strokeLinecap=\"round\"\n              opacity=\"0\"\n            />\n            <g ref={headRef} opacity=\"0\">\n              <circle r=\"9\" fill={accent} opacity={pal.glow * 0.3} />\n              <circle r=\"3\" fill={pal.text} />\n            </g>\n            {point && active !== null && (\n              <g>\n                <line\n                  x1={x(active)}\n                  x2={x(active)}\n                  y1={TOP}\n                  y2={height}\n                  stroke={pal.border}\n                />\n                <circle\n                  cx={x(active)}\n                  cy={y(point.value)}\n                  r=\"3.5\"\n                  fill={accent}\n                  stroke={pal.card}\n                  strokeWidth=\"2\"\n                />\n              </g>\n            )}\n          </svg>\n\n          <div\n            aria-hidden=\"true\"\n            className=\"mt-2 flex gap-[3px]\"\n            style={{ marginLeft: LEFT, marginRight: RIGHT }}\n          >\n            {data.map((d, i) => (\n              <span\n                key={d.date}\n                ref={(el) => {\n                  cellRefs.current[i] = el;\n                }}\n                className=\"h-3.5 min-w-0 flex-1 rounded-[3px]\"\n                style={{\n                  background: mix(pal.empty, accent, LEVEL_MIX[level[i]]),\n                  boxShadow: active === i ? `0 0 0 1px ${pal.ring}` : undefined,\n                }}\n              />\n            ))}\n          </div>\n          <div\n            aria-hidden=\"true\"\n            className=\"relative mt-1.5 h-4 text-[11px]\"\n            style={{ color: pal.faint, marginLeft: LEFT, marginRight: RIGHT }}\n          >\n            {data\n              .map((d) => d.date)\n              .map(\n                (date, i) =>\n                  i % every === 0 && (\n                    <span\n                      key={date}\n                      className=\"absolute top-0 whitespace-nowrap\"\n                      style={{ left: `${(i / count) * 100}%` }}\n                    >\n                      {shortDate(date)}\n                    </span>\n                  ),\n              )}\n          </div>\n\n          {point && active !== null && (\n            <Tip x={x(active)} y={y(point.value)} width={width} pal={pal}>\n              <span className=\"font-[510]\" style={{ color: pal.text }}>\n                {formatValue(point.value)} {unit}\n              </span>{\" \"}\n              on {longDate(point.date)}\n            </Tip>\n          )}\n        </div>\n      )}\n\n      <div\n        className=\"mt-3 flex flex-wrap items-center justify-between gap-2 text-[12px]\"\n        style={{ color: pal.sub }}\n      >\n        <span>\n          {count > 0 &&\n            `${shortDate(data[0].date)} – ${shortDate(data[count - 1].date)}`}\n        </span>\n        <Legend pal={pal} accent={accent} />\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}