{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line",
  "title": "Line chart",
  "description": "A line chart a pen plots as you scroll: gridlines, then each series left to right, the first in the accent, then a marker on every point. One series or several; smooth, straight or stepped.",
  "dependencies": [
    "svg-scroll-draw@^2.29.0"
  ],
  "registryDependencies": [
    "https://scrollfx-ui.vercel.app/r/plotter.json",
    "https://scrollfx-ui.vercel.app/r/chart.json"
  ],
  "files": [
    {
      "path": "registry/ui/chart-line.tsx",
      "content": "'use client';\n\n/**\n * chart-line — a line chart a pen plots as you scroll: the gridlines first,\n * then each series left to right (the first in the accent colour), then a\n * marker on every point. One series or several; smooth, straight or stepped.\n *\n * Built on svg-scroll-draw (MIT): https://github.com/DhruvilChauahan0210/scrollfx\n * Needs: react, svg-scroll-draw, lib/chart and lib/plotter (installed with it).\n * Styling: Tailwind CSS with shadcn/ui tokens.\n *\n * The axis labels, the legend and a data table for screen readers are in the\n * server HTML; the strokes are made in the browser at the chart's size and\n * finish as the chart reaches the middle of the screen. Reduced motion shows\n * the chart drawn.\n */\n\nimport { useMemo } from 'react';\nimport 'svg-scroll-draw/no-flash.css';\nimport {\n  ACCENT, DataTable, Legend, PHASE, PenLayers, XLabels, YLabels, curvePath, formatter, gutter, linear, marker, niceTicks, num, seriesOf, toPath, useSize,\n  type ChartTrigger, type ChartConfig, type Curve, type Datum, type Mark, type Pen,\n} from '@/lib/chart';\n\nexport interface ChartLineProps {\n  /** One object per point along the x axis. */\n  data?: Datum[];\n  /** The key in each object that labels its point on the x axis. */\n  index?: string;\n  /** The series to draw, by key: a label and, if you like, a colour. Defaults to every number in the first object. */\n  config?: ChartConfig;\n  /** How the pen joins the points. */\n  curve?: Curve;\n  /** A marker on every point: circles for the first series, then squares, triangles, diamonds, crosses. */\n  markers?: boolean;\n  /** The plot's height in pixels; it takes the full width. */\n  height?: number;\n  /** How numbers on the axis are written (Intl.NumberFormat options). */\n  format?: Intl.NumberFormatOptions;\n  /** Start the y axis at zero, or fit it to the data. */\n  zero?: boolean;\n  /** Show the key. By default, when there is more than one series. */\n  legend?: boolean;\n  /** The first series' colour. */\n  accent?: string;\n  /** What the chart shows, for screen readers (it captions the data table). */\n  label?: string;\n  /** `scroll`: inked as it rises, done at mid-screen. `view`: played once as it comes into view. */\n  trigger?: ChartTrigger;\n  /** With `view`, how long the chart takes, in ms. */\n  duration?: number;\n  className?: string;\n}\n\nconst SAMPLE: Datum[] = [\n  { month: 'Jan', visitors: 1240 }, { month: 'Feb', visitors: 1510 }, { month: 'Mar', visitors: 1460 }, { month: 'Apr', visitors: 1980 },\n  { month: 'May', visitors: 2350 }, { month: 'Jun', visitors: 2210 }, { month: 'Jul', visitors: 2740 }, { month: 'Aug', visitors: 3120 },\n  { month: 'Sep', visitors: 2980 }, { month: 'Oct', visitors: 3540 }, { month: 'Nov', visitors: 3890 }, { month: 'Dec', visitors: 4320 },\n];\n\nexport function ChartLine({\n  data = SAMPLE,\n  index = 'month',\n  config,\n  curve = 'smooth',\n  markers,\n  height = 240,\n  format,\n  zero = true,\n  legend,\n  accent = ACCENT,\n  label = 'Line chart',\n  trigger = 'scroll',\n  duration = 1800,\n  className = '',\n}: ChartLineProps) {\n  const series = seriesOf(data, index, config, accent);\n  const values = data.flatMap((d) => series.map((s) => num(d[s.key])));\n  const ticks = niceTicks(zero ? Math.min(0, ...values) : Math.min(...values), Math.max(...values), 4);\n  const [lo, hi] = [ticks[0], ticks[ticks.length - 1]];\n  const fmt = formatter(format);\n  const n = data.length;\n  const xAt = (i: number) => (n > 1 ? i / (n - 1) : 0.5);\n  const showMarkers = markers ?? (series.length > 1 && curve !== 'step');\n  const [ref, size] = useSize<HTMLDivElement>();\n\n  const pens = useMemo((): Pen[] | null => {\n    if (!size) return null;\n    const { w, h } = size;\n    const y = linear(lo, hi, h, 0);\n    // Gridlines bottom to top; the zero line (the baseline) in full ink.\n    const axes: Mark[] = ticks.map((t) => ({ d: toPath([[0, y(t)], [w, y(t)]]), width: t === 0 || t === lo ? 1 : 0.6, opacity: t === 0 || t === lo ? 0.9 : 0.22 }));\n    // A short tick under each point on the baseline.\n    for (let i = 0; i < n; i++) axes.push({ d: toPath([[xAt(i) * w, h], [xAt(i) * w, h + 5]]), width: 0.8, opacity: 0.6 });\n    const lines: Mark[] = series.map((s, k) => ({\n      d: curvePath(data.map((d, i) => [xAt(i) * w, y(num(d[s.key]))]), curve),\n      color: s.color,\n      width: k === 0 ? 2.2 : 1.5,\n    }));\n    const dots: Mark[] = showMarkers\n      ? data.flatMap((d, i) => series.map((s) => ({ d: marker(s.marker, xAt(i) * w, y(num(d[s.key]))), color: s.color, width: 1.3 })))\n      : [];\n    return [\n      { marks: axes, ...PHASE.axes, spread: 0.6 },\n      { marks: lines, from: PHASE.ink.from, to: showMarkers ? 0.6 : PHASE.ink.to, spread: 0.5 * (lines.length - 1) },\n      { marks: dots, from: 0.74, to: PHASE.ink.to, spread: 2 },\n    ];\n  }, [size, data, index, config, curve, showMarkers, accent, lo, hi]);\n\n  return (\n    <figure className={`w-full ${className}`}>\n      <DataTable caption={label} head={[index, ...series.map((s) => s.label)]} rows={data.map((d) => [String(d[index]), ...series.map((s) => num(d[s.key]))])} />\n      <div aria-hidden>\n        <div className=\"flex\">\n          <YLabels ticks={ticks.map((t) => ({ label: fmt(t), at: (t - lo) / (hi - lo) }))} />\n          <div ref={ref} data-slot=\"plot\" className=\"relative min-w-0 flex-1\" style={{ height }}>\n            {size && pens ? <PenLayers size={size} pens={pens} trigger={trigger} duration={duration} /> : null}\n          </div>\n        </div>\n        <XLabels ticks={data.map((d, i) => ({ label: String(d[index]), at: xAt(i) }))} offset={gutter(ticks.map(fmt))} />\n        {(legend ?? series.length > 1) && <Legend series={series} kind=\"line\" className=\"mt-5\" />}\n      </div>\n    </figure>\n  );\n}\n\n",
      "type": "registry:ui",
      "target": "components/scrollfx/chart-line.tsx"
    }
  ],
  "type": "registry:ui"
}