{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line-graph",
  "type": "registry:component",
  "title": "Chart Line Graph",
  "description": "A responsive line graph that draws its path when it scrolls into view, with gradient area fill, gridlines, a pulsing end point and a crosshair tooltip you can drive with the pointer or the arrow keys.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "charts",
    "chart",
    "line",
    "graph",
    "tooltip",
    "keyboard",
    "svg"
  ],
  "docs": "https://hyperblur.dev/effects/chart-line-graph",
  "files": [
    {
      "path": "registry/hyperblur/chart-line-graph.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/chart-line-graph.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ChartLinePoint {\n  label: string;\n  value: number;\n}\n\nexport interface ChartLineGraphProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  data?: ChartLinePoint[];\n  format?: (value: number) => string;\n  axisFormat?: (value: number) => string;\n  height?: number;\n  accent?: string;\n  curve?: boolean;\n  sweep?: boolean;\n}\n\nconst defaultData: ChartLinePoint[] = [\n  { label: \"Week 1\", value: 1240 },\n  { label: \"Week 2\", value: 1310 },\n  { label: \"Week 3\", value: 1295 },\n  { label: \"Week 4\", value: 1480 },\n  { label: \"Week 5\", value: 1620 },\n  { label: \"Week 6\", value: 1575 },\n  { label: \"Week 7\", value: 1790 },\n  { label: \"Week 8\", value: 1960 },\n  { label: \"Week 9\", value: 1885 },\n  { label: \"Week 10\", value: 2140 },\n  { label: \"Week 11\", value: 2310 },\n  { label: \"Week 12\", value: 2495 },\n];\n\nconst css = `\n.hb-zb5 {\n  --hb-zb5-a: #2f7bff;\n  position: relative;\n  width: 100%;\n  box-sizing: border-box;\n  padding: 0 14px 26px 44px;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 12px;\n}\n.hb-zb5 *, .hb-zb5 *::before, .hb-zb5 *::after { box-sizing: border-box; }\n.hb-zb5-plot {\n  position: relative;\n  width: 100%;\n  height: var(--hb-zb5-h, 240px);\n  outline: none;\n  cursor: crosshair;\n  touch-action: pan-y;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-zb5-plot:focus-visible { border-radius: 8px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--hb-zb5-a) 70%, transparent); }\n.hb-zb5-svg { position: absolute; left: 0; top: 0; display: block; overflow: visible; }\n.hb-zb5-grid { stroke: rgba(255, 255, 255, 0.07); stroke-width: 1; stroke-dasharray: 2 5; }\n.hb-zb5-base { stroke: rgba(255, 255, 255, 0.16); stroke-dasharray: none; }\n.hb-zb5-vg { stroke: rgba(255, 255, 255, 0.04); stroke-width: 1; }\n.hb-zb5-line {\n  fill: none;\n  stroke: var(--hb-zb5-a);\n  stroke-width: 2.25;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  stroke-dasharray: 1 1;\n  stroke-dashoffset: 1;\n  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--hb-zb5-a) 55%, transparent));\n}\n.hb-zb5[data-in=\"true\"] .hb-zb5-line {\n  stroke-dashoffset: 0;\n  transition: stroke-dashoffset 1.8s cubic-bezier(0.65, 0, 0.25, 1);\n}\n.hb-zb5-area { clip-path: inset(0 100% 0 0); }\n.hb-zb5[data-in=\"true\"] .hb-zb5-area {\n  clip-path: inset(0 0 0 0);\n  transition: clip-path 1.8s cubic-bezier(0.65, 0, 0.25, 1);\n}\n.hb-zb5-pt {\n  fill: #0a0a0a;\n  stroke: var(--hb-zb5-a);\n  stroke-width: 1.75;\n  opacity: 0;\n}\n.hb-zb5[data-in=\"true\"] .hb-zb5-pt {\n  opacity: 0.85;\n  transition: opacity 0.35s ease var(--hb-zb5-d, 0ms);\n}\n.hb-zb5-yl, .hb-zb5-xl {\n  position: absolute;\n  font-size: 11px;\n  line-height: 1;\n  color: #8f8f8f;\n  white-space: nowrap;\n  font-variant-numeric: tabular-nums;\n  pointer-events: none;\n}\n.hb-zb5-yl { right: calc(100% + 10px); transform: translateY(-50%); }\n.hb-zb5-xl { top: calc(100% + 10px); transform: translateX(-50%); }\n.hb-zb5-xl[data-on=\"true\"] { color: #ededed; }\n.hb-zb5-cx {\n  position: absolute;\n  top: 0;\n  width: 1px;\n  background: linear-gradient(to bottom, color-mix(in srgb, var(--hb-zb5-a) 80%, transparent), rgba(255, 255, 255, 0.04));\n  pointer-events: none;\n  transition: left 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-zb5-dot {\n  position: absolute;\n  width: 12px;\n  height: 12px;\n  margin: -6px 0 0 -6px;\n  border-radius: 50%;\n  background: #0a0a0a;\n  border: 2.5px solid var(--hb-zb5-a);\n  box-shadow: 0 0 0 5px color-mix(in srgb, var(--hb-zb5-a) 22%, transparent);\n  pointer-events: none;\n  transition: left 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-zb5-end {\n  position: absolute;\n  width: 10px;\n  height: 10px;\n  margin: -5px 0 0 -5px;\n  border-radius: 50%;\n  background: var(--hb-zb5-a);\n  box-shadow: 0 0 12px var(--hb-zb5-a);\n  pointer-events: none;\n  opacity: 0;\n  transition: opacity 0.4s ease;\n}\n.hb-zb5[data-in=\"true\"] .hb-zb5-end { opacity: 1; transition-delay: 1.7s; }\n.hb-zb5[data-hold=\"true\"] .hb-zb5-end { opacity: 0; transition-delay: 0s; }\n.hb-zb5-end::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  border: 1.5px solid var(--hb-zb5-a);\n  animation: hb-zb5-pulse 2.2s ease-out infinite;\n}\n.hb-zb5-tip {\n  position: absolute;\n  z-index: 2;\n  display: flex;\n  flex-direction: column;\n  gap: 3px;\n  min-width: 96px;\n  padding: 8px 11px;\n  border-radius: 10px;\n  border: 1px solid rgba(255, 255, 255, 0.12);\n  background: rgba(23, 23, 23, 0.94);\n  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);\n  pointer-events: none;\n  white-space: nowrap;\n  transform: translate(-50%, calc(-100% - 14px));\n  animation: hb-zb5-pop 0.18s ease-out;\n  transition: left 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-zb5-tip[data-below=\"true\"] { transform: translate(-50%, 18px); }\n.hb-zb5-tl { font-size: 11px; color: #8f8f8f; }\n.hb-zb5-tv { display: flex; align-items: baseline; gap: 8px; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }\n.hb-zb5-td { font-size: 11px; font-weight: 600; color: #3ecf8e; }\n.hb-zb5-td[data-neg=\"true\"] { color: #ff6b6b; }\n@keyframes hb-zb5-pulse {\n  0% { transform: scale(1); opacity: 0.9; }\n  100% { transform: scale(3.4); opacity: 0; }\n}\n@keyframes hb-zb5-pop {\n  from { opacity: 0; }\n  to { opacity: 1; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-zb5-line, .hb-zb5-area, .hb-zb5-pt, .hb-zb5-end, .hb-zb5-cx, .hb-zb5-dot, .hb-zb5-tip { transition: none !important; animation: none !important; }\n  .hb-zb5-line { stroke-dashoffset: 0; }\n  .hb-zb5-area { clip-path: none; }\n  .hb-zb5-pt { opacity: 0.85; }\n  .hb-zb5-end { opacity: 1; }\n}\n`;\n\nconst PAD_X = 12;\nconst PAD_T = 18;\nconst PAD_B = 6;\n\nfunction niceStep(raw: number) {\n  const mag = Math.pow(10, Math.floor(Math.log10(raw)));\n  const norm = raw / mag;\n  const f = norm <= 1 ? 1 : norm <= 2 ? 2 : norm <= 2.5 ? 2.5 : norm <= 5 ? 5 : 10;\n  return f * mag;\n}\n\nfunction linePath(xs: number[], ys: number[], curve: boolean) {\n  const n = xs.length;\n  if (n === 0) return \"\";\n  if (n === 1) return `M${xs[0].toFixed(2)} ${ys[0].toFixed(2)}`;\n  if (!curve) return xs.map((x, i) => `${i ? \"L\" : \"M\"}${x.toFixed(2)} ${ys[i].toFixed(2)}`).join(\"\");\n  const dx: number[] = [];\n  const m: number[] = [];\n  for (let i = 0; i < n - 1; i++) {\n    dx.push(xs[i + 1] - xs[i]);\n    m.push((ys[i + 1] - ys[i]) / dx[i]);\n  }\n  const t: number[] = new Array(n).fill(0);\n  t[0] = m[0];\n  t[n - 1] = m[n - 2];\n  for (let i = 1; i < n - 1; i++) t[i] = m[i - 1] * m[i] <= 0 ? 0 : (m[i - 1] + m[i]) / 2;\n  for (let i = 0; i < n - 1; i++) {\n    if (m[i] === 0) {\n      t[i] = 0;\n      t[i + 1] = 0;\n    } else {\n      const a = t[i] / m[i];\n      const b = t[i + 1] / m[i];\n      const s = a * a + b * b;\n      if (s > 9) {\n        const k = 3 / Math.sqrt(s);\n        t[i] = k * a * m[i];\n        t[i + 1] = k * b * m[i];\n      }\n    }\n  }\n  let d = `M${xs[0].toFixed(2)} ${ys[0].toFixed(2)}`;\n  for (let i = 0; i < n - 1; i++) {\n    const h = dx[i] / 3;\n    d += `C${(xs[i] + h).toFixed(2)} ${(ys[i] + t[i] * h).toFixed(2)} ${(xs[i + 1] - h).toFixed(2)} ${(ys[i + 1] - t[i + 1] * h).toFixed(2)} ${xs[i + 1].toFixed(2)} ${ys[i + 1].toFixed(2)}`;\n  }\n  return d;\n}\n\nconst plainFormat = (v: number) => v.toLocaleString(\"en-US\");\nconst compactFormat = (v: number) => (Math.abs(v) >= 1000 ? `${+(v / 1000).toFixed(1)}k` : String(+v.toFixed(2)));\n\nexport function ChartLineGraph({\n  data = defaultData,\n  format = plainFormat,\n  axisFormat = compactFormat,\n  height = 240,\n  accent = \"#2f7bff\",\n  curve = true,\n  sweep = false,\n  \"aria-label\": ariaLabel = \"Line graph\",\n  className = \"\",\n  style,\n  ...rest\n}: ChartLineGraphProps) {\n  const uid = React.useId().replace(/:/g, \"\");\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const plotRef = React.useRef<HTMLDivElement>(null);\n  const [width, setWidth] = React.useState(640);\n  const [shown, setShown] = React.useState(false);\n  const [visible, setVisible] = React.useState(false);\n  const [active, setActive] = React.useState<number | null>(null);\n  const [auto, setAuto] = React.useState<number | null>(null);\n\n  const n = data.length;\n\n  React.useEffect(() => {\n    const el = plotRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => {\n      const w = el.clientWidth;\n      if (w > 0) setWidth(w);\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      (entries) => {\n        const hit = entries[entries.length - 1].isIntersecting;\n        setVisible(hit);\n        if (hit) setShown(true);\n      },\n      { threshold: 0.2 }\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    if (!sweep || !visible || !shown || n < 2) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let i = 1;\n    let interval = 0;\n    const first = window.setTimeout(() => {\n      setAuto(i);\n      interval = window.setInterval(() => {\n        i = (i + 1) % n;\n        setAuto(i);\n      }, 1300);\n    }, 2100);\n    return () => {\n      window.clearTimeout(first);\n      window.clearInterval(interval);\n      setAuto(null);\n    };\n  }, [sweep, visible, shown, n]);\n\n  const values = data.map((d) => d.value);\n  const lo = n ? Math.min(...values) : 0;\n  const hi = n ? Math.max(...values) : 1;\n  const span = hi - lo || Math.abs(hi) || 1;\n  const step = niceStep(span / 4);\n  const yMin = Math.floor(lo / step) * step;\n  let yMax = Math.ceil(hi / step) * step;\n  if (yMax - yMin < step * 4) yMax = yMin + step * 4;\n  const ticks: number[] = [];\n  for (let v = yMin; v <= yMax + step * 0.001; v += step) ticks.push(v);\n\n  const plotH = height;\n  const inner = plotH - PAD_T - PAD_B;\n  const gap = n > 1 ? (width - PAD_X * 2) / (n - 1) : 0;\n  const xs = data.map((_, i) => (n > 1 ? PAD_X + i * gap : width / 2));\n  const ys = data.map((d) => PAD_T + (1 - (d.value - yMin) / (yMax - yMin)) * inner);\n  const tickY = (v: number) => PAD_T + (1 - (v - yMin) / (yMax - yMin)) * inner;\n  const line = linePath(xs, ys, curve);\n  const area = n > 1 ? `${line}L${xs[n - 1].toFixed(2)} ${plotH}L${xs[0].toFixed(2)} ${plotH}Z` : \"\";\n  const every = Math.max(1, Math.ceil(n / Math.max(2, Math.floor(width / 70))));\n\n  const idx = active ?? auto;\n  const hold = active !== null;\n\n  function locate(clientX: number) {\n    const el = plotRef.current;\n    if (!el || n === 0) return 0;\n    const r = el.getBoundingClientRect();\n    const raw = gap ? (clientX - r.left - PAD_X) / gap : 0;\n    return Math.min(n - 1, Math.max(0, Math.round(raw)));\n  }\n\n  function onKey(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (n === 0) return;\n    const cur = active;\n    let next: number | null | undefined;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") next = cur === null ? 0 : Math.min(n - 1, cur + 1);\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") next = cur === null ? n - 1 : Math.max(0, cur - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = n - 1;\n    else if (e.key === \"Escape\") next = null;\n    if (next === undefined) return;\n    e.preventDefault();\n    setActive(next);\n  }\n\n  const cur = idx !== null && idx < n ? data[idx] : null;\n  const prevPoint = idx !== null && idx > 0 ? data[idx - 1] : null;\n  const delta = cur && prevPoint && prevPoint.value !== 0 ? ((cur.value - prevPoint.value) / Math.abs(prevPoint.value)) * 100 : null;\n  const tipX = idx !== null ? Math.min(width - 62, Math.max(62, xs[idx])) : 0;\n  const tipBelow = idx !== null && ys[idx] < 74;\n\n  return (\n    <div\n      ref={rootRef}\n      data-in={shown ? \"true\" : \"false\"}\n      data-hold={idx !== null ? \"true\" : \"false\"}\n      className={`hb-zb5 ${className}`.trim()}\n      style={{ \"--hb-zb5-a\": accent, \"--hb-zb5-h\": `${height}px`, ...style } as React.CSSProperties}\n      {...rest}\n    >\n      <style href=\"hb-chart-line-graph\" precedence=\"default\">{css}</style>\n      <div\n        ref={plotRef}\n        className=\"hb-zb5-plot\"\n        role=\"slider\"\n        tabIndex={0}\n        aria-label={ariaLabel}\n        aria-orientation=\"horizontal\"\n        aria-valuemin={0}\n        aria-valuemax={Math.max(0, n - 1)}\n        aria-valuenow={hold && cur ? (active ?? undefined) : undefined}\n        aria-valuetext={hold && cur ? `${cur.label}: ${format(cur.value)}` : undefined}\n        onPointerMove={(e) => {\n          if (e.pointerType === \"touch\") return;\n          setActive(locate(e.clientX));\n        }}\n        onPointerDown={(e) => setActive(locate(e.clientX))}\n        onPointerLeave={(e) => {\n          if (e.pointerType !== \"touch\") setActive(null);\n        }}\n        onKeyDown={onKey}\n        onFocus={(e) => {\n          if (active === null && e.currentTarget.matches(\":focus-visible\")) setActive(n - 1);\n        }}\n        onBlur={() => setActive(null)}\n      >\n        <svg className=\"hb-zb5-svg\" width={width} height={plotH} viewBox={`0 0 ${width} ${plotH}`} aria-hidden=\"true\">\n          <defs>\n            <linearGradient id={`${uid}-a`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n              <stop offset=\"0\" style={{ stopColor: \"var(--hb-zb5-a)\", stopOpacity: 0.34 }} />\n              <stop offset=\"1\" style={{ stopColor: \"var(--hb-zb5-a)\", stopOpacity: 0 }} />\n            </linearGradient>\n          </defs>\n          {ticks.map((v, i) => (\n            <line\n              key={`g${i}`}\n              className={i === 0 ? \"hb-zb5-grid hb-zb5-base\" : \"hb-zb5-grid\"}\n              x1={0}\n              x2={width}\n              y1={tickY(v).toFixed(2)}\n              y2={tickY(v).toFixed(2)}\n            />\n          ))}\n          {data.map((_, i) =>\n            i % every === 0 ? (\n              <line key={`v${i}`} className=\"hb-zb5-vg\" x1={xs[i].toFixed(2)} x2={xs[i].toFixed(2)} y1={PAD_T} y2={plotH - PAD_B} />\n            ) : null\n          )}\n          {area ? <path className=\"hb-zb5-area\" d={area} fill={`url(#${uid}-a)`} /> : null}\n          {line ? <path className=\"hb-zb5-line\" d={line} pathLength={1} /> : null}\n          {data.map((_, i) => (\n            <circle\n              key={`p${i}`}\n              className=\"hb-zb5-pt\"\n              cx={xs[i].toFixed(2)}\n              cy={ys[i].toFixed(2)}\n              r={3}\n              style={{ \"--hb-zb5-d\": `${Math.round(n > 1 ? (i / (n - 1)) * 1500 : 0)}ms` } as React.CSSProperties}\n            />\n          ))}\n        </svg>\n        {ticks.map((v, i) => (\n          <span key={`y${i}`} className=\"hb-zb5-yl\" style={{ top: tickY(v) }}>\n            {axisFormat(v)}\n          </span>\n        ))}\n        {data.map((d, i) =>\n          i % every === 0 ? (\n            <span key={`x${i}`} className=\"hb-zb5-xl\" data-on={idx === i ? \"true\" : \"false\"} style={{ left: xs[i] }}>\n              {d.label}\n            </span>\n          ) : null\n        )}\n        {n > 0 ? <span className=\"hb-zb5-end\" style={{ left: xs[n - 1], top: ys[n - 1] }} /> : null}\n        {cur && idx !== null ? (\n          <>\n            <span className=\"hb-zb5-cx\" style={{ left: xs[idx], height: plotH - PAD_B }} />\n            <span className=\"hb-zb5-dot\" style={{ left: xs[idx], top: ys[idx] }} />\n            <div className=\"hb-zb5-tip\" data-below={tipBelow ? \"true\" : \"false\"} style={{ left: tipX, top: ys[idx] }}>\n              <span className=\"hb-zb5-tl\">{cur.label}</span>\n              <span className=\"hb-zb5-tv\">\n                {format(cur.value)}\n                {delta !== null ? (\n                  <span className=\"hb-zb5-td\" data-neg={delta < 0 ? \"true\" : \"false\"}>\n                    {delta >= 0 ? \"+\" : \"\"}\n                    {delta.toFixed(1)}%\n                  </span>\n                ) : null}\n              </span>\n            </div>\n          </>\n        ) : null}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}