{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-area",
  "title": "Area chart",
  "description": "An area chart hatched in stroke by stroke under its curve, then the curve drawn over it in the accent. One series, or several stacked, each with its own hatch.",
  "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-area.tsx",
      "content": "'use client';\n\n/**\n * chart-area — an area chart a pen hatches in as you scroll: the gridlines\n * first, then the area under each series stroke by stroke from left to right,\n * then the curve over it, the first in the accent colour. One series, or\n * several stacked one on another, each band hatched at its own angle.\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, curvePoints, formatter, gutter, hatchMarks, linear, niceTicks, num, seriesOf, toPath, useSize,\n  type ChartTrigger, type ChartConfig, type Curve, type Datum, type Hatch, type Mark, type Pen, type Pt,\n} from '@/lib/chart';\n\nexport interface ChartAreaProps {\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  /** Stack the series one on another, rather than each from zero. */\n  stacked?: boolean;\n  /** How the pen joins the points. */\n  curve?: Curve;\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  /** 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\n/** Upright hatching for the first band, as the plotted-chart plate has it, then diagonals each way and across. */\nconst AREA_HATCHES: Hatch[] = [\n  { angle: 90, gap: 6 },\n  { angle: 45, gap: 6 },\n  { angle: 135, gap: 6 },\n  { angle: 0, gap: 5 },\n];\n\nconst SAMPLE: Datum[] = [\n  { month: 'Jan', events: 1.2 }, { month: 'Feb', events: 1.5 }, { month: 'Mar', events: 1.9 }, { month: 'Apr', events: 1.7 },\n  { month: 'May', events: 1.6 }, { month: 'Jun', events: 2.2 }, { month: 'Jul', events: 2.8 }, { month: 'Aug', events: 2.7 },\n  { month: 'Sep', events: 3.4 }, { month: 'Oct', events: 3.6 }, { month: 'Nov', events: 4.2 }, { month: 'Dec', events: 4.6 },\n];\n\nexport function ChartArea({\n  data = SAMPLE,\n  index = 'month',\n  config,\n  stacked = false,\n  curve = 'smooth',\n  height = 240,\n  format,\n  legend,\n  accent = ACCENT,\n  label = 'Area chart',\n  trigger = 'scroll',\n  duration = 1800,\n  className = '',\n}: ChartAreaProps) {\n  const series = seriesOf(data, index, config, accent).map((s, i) => ({ ...s, hatch: AREA_HATCHES[i % AREA_HATCHES.length] }));\n  // Each band's top, and (stacked) its bottom: the running total of the series below.\n  const tops = data.map((d) => {\n    let sum = 0;\n    return series.map((s) => (stacked ? (sum += num(d[s.key])) : num(d[s.key])));\n  });\n  const ticks = niceTicks(0, Math.max(...tops.flat()), 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 [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    const axes: Mark[] = ticks.map((t) => ({ d: toPath([[0, y(t)], [w, y(t)]]), width: t === lo ? 1 : 0.6, opacity: t === lo ? 0.9 : 0.22 }));\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 line = (k: number): Pt[] => data.map((_, i) => [xAt(i) * w, y(tops[i][k])]);\n    const fill: Mark[] = [];\n    const lines: Mark[] = [];\n    // Unstacked bands overlap, so the hatching goes back to front: the largest first.\n    const order = series.map((_, k) => k);\n    if (!stacked) order.sort((a, b) => tops.reduce((m, t) => m + t[b], 0) - tops.reduce((m, t) => m + t[a], 0));\n    for (const k of order) {\n      const top = curvePoints(line(k), curve);\n      const bottom: Pt[] = stacked && k > 0 ? curvePoints(line(k - 1), curve).reverse() : [[top[top.length - 1][0], h], [top[0][0], h]];\n      fill.push(...hatchMarks([...top, ...bottom], series[k].hatch, { opacity: 0.7, width: 0.9, inset: 3.5 }));\n    }\n    series.forEach((s, k) => lines.push({ d: curvePath(line(k), curve), color: s.color, width: k === 0 ? 2.4 : 1.6 }));\n    return [\n      { marks: axes, ...PHASE.axes, spread: 0.6 },\n      { marks: fill, ...PHASE.fill, spread: 2.5 },\n      { marks: lines, ...PHASE.ink, spread: 0.5 * (lines.length - 1) },\n    ];\n  }, [size, data, index, config, stacked, curve, 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=\"hatch\" className=\"mt-5\" />}\n      </div>\n    </figure>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/scrollfx/chart-area.tsx"
    }
  ],
  "type": "registry:ui"
}