{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "plotted-chart",
  "title": "Plotted chart",
  "description": "Figures that count up beside an area chart a pen plots as you scroll: hatched in from left to right, the curve drawn over it.",
  "dependencies": [
    "svg-scroll-draw@^2.29.0"
  ],
  "registryDependencies": [
    "https://scrollfx-ui.vercel.app/r/plotter.json"
  ],
  "files": [
    {
      "path": "registry/blocks/plotted-chart.tsx",
      "content": "'use client';\n\n/**\n * plotted-chart — figures beside a chart a pen plots as you scroll: the area\n * under the curve is hatched in, stroke by stroke from left to right, the\n * curve is drawn over it in the accent colour, and the figures count up.\n *\n * Built on svg-scroll-draw (MIT): https://github.com/DhruvilChauahan0210/scrollfx\n * Needs: react, svg-scroll-draw, and lib/plotter (installed with it).\n * Styling: Tailwind CSS with shadcn/ui tokens. The heading takes one emphasised\n * word between asterisks, set in `font-serif`.\n *\n * The figures and the axis labels are in the server HTML. The drawing is made\n * in the browser from `data`. Reduced motion shows everything drawn.\n */\n\nimport { useEffect, useState } from 'react';\nimport { ScrollCounter, ScrollDraw } from 'svg-scroll-draw/react';\nimport 'svg-scroll-draw/no-flash.css';\nimport { curveY, scrollWindow, smooth, staggerFor } from '@/lib/plotter';\n\nexport interface Stat {\n  value: number;\n  decimals?: number;\n  prefix?: string;\n  suffix?: string;\n  label: string;\n}\n\nexport interface PlottedChartProps {\n  eyebrow?: string;\n  heading?: string;\n  description?: string;\n  /** The series, left to right. */\n  data?: { label: string; value: number }[];\n  stats?: Stat[];\n  caption?: string;\n  accent?: string;\n  className?: string;\n}\n\nconst DEFAULT_DATA = [\n  { label: 'Jan', value: 1.2 }, { label: 'Feb', value: 1.5 }, { label: 'Mar', value: 1.9 }, { label: 'Apr', value: 1.7 },\n  { label: 'May', value: 1.6 }, { label: 'Jun', value: 2.2 }, { label: 'Jul', value: 2.8 }, { label: 'Aug', value: 2.7 },\n  { label: 'Sep', value: 3.4 }, { label: 'Oct', value: 3.6 }, { label: 'Nov', value: 4.2 }, { label: 'Dec', value: 4.6 },\n];\n\nconst DEFAULT_STATS: Stat[] = [\n  { value: 4.6, decimals: 1, suffix: 'M', label: 'Events a day, in December' },\n  { value: 283, suffix: '%', label: 'Growth over the year' },\n  { value: 38, suffix: ' ms', label: 'Median time to the dashboard' },\n];\n\nfunction Heading({ text }: { text: string }) {\n  return <>{text.split(/(\\*[^*]+\\*)/).map((p, i) => (p.startsWith('*') ? <em key={i} className=\"italic\">{p.slice(1, -1)}</em> : <span key={i}>{p}</span>))}</>;\n}\n\nconst W = 1000, H = 420, TOP = 40, BASE = 400, X0 = 10, X1 = 990;\n\nexport function PlottedChart({\n  eyebrow = 'A year in numbers',\n  heading = 'Growth, *plotted*.',\n  description = 'Sample figures. Swap in your own series and the chart is drawn from them.',\n  data = DEFAULT_DATA,\n  stats = DEFAULT_STATS,\n  caption = 'Fig. 1 — Events per day, millions',\n  accent = '#e0482a',\n  className = '',\n}: PlottedChartProps) {\n  const [drawing, setDrawing] = useState<{ curve: string; hatch: string[] } | null>(null);\n\n  useEffect(() => {\n    const max = Math.max(...data.map((d) => d.value)) * 1.08;\n    const pts = data.map((d, i): [number, number] => [X0 + (i / (data.length - 1)) * (X1 - X0), BASE - (d.value / max) * (BASE - TOP)]);\n    const hatch: string[] = [];\n    for (let x = X0 + 3; x < X1; x += 7) hatch.push(`M${x.toFixed(1)} ${BASE}L${x.toFixed(1)} ${(curveY(pts, x) + 6).toFixed(1)}`);\n    setDrawing({ curve: smooth(pts), hatch });\n  }, [data]);\n\n  // The hatching sweeps left to right and the curve keeps pace with it; both\n  // finish as the chart reaches the middle of the screen.\n  const SPREAD = 1.2;\n\n  return (\n    <section className={`mx-auto max-w-7xl px-6 py-28 sm:px-10 ${className}`}>\n      <div className=\"grid gap-16 lg:grid-cols-[minmax(0,4fr)_minmax(0,8fr)] lg:gap-20\">\n        <div>\n          <p className=\"font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground\">{eyebrow}</p>\n          <h2 className=\"mt-6 font-serif text-[clamp(2.6rem,5vw,4.2rem)] leading-[0.98] tracking-[-0.03em]\">\n            <Heading text={heading} />\n          </h2>\n          <p className=\"mt-6 max-w-sm text-pretty leading-relaxed text-muted-foreground\">{description}</p>\n          <dl className=\"mt-12 divide-y border-y\">\n            {stats.map((s) => (\n              <div key={s.label} className=\"flex items-baseline justify-between gap-6 py-5\">\n                <dt className=\"max-w-[12rem] text-sm text-muted-foreground\">{s.label}</dt>\n                <dd className=\"font-serif text-4xl tracking-[-0.02em] tabular-nums\">\n                  {s.prefix}\n                  <ScrollCounter to={s.value} decimals={s.decimals ?? 0} trigger={scrollWindow()} />\n                  {s.suffix}\n                </dd>\n              </div>\n            ))}\n          </dl>\n        </div>\n\n        <figure className=\"self-end\">\n          <div className=\"relative aspect-[1000/420] w-full\">\n            {drawing ? (\n              <>\n                <ScrollDraw stagger={staggerFor(drawing.hatch.length, SPREAD)} easing=\"linear\" trigger={scrollWindow(SPREAD)} className=\"absolute inset-0\" aria-hidden>\n                  <svg viewBox={`0 0 ${W} ${H}`} className=\"size-full\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.1\" strokeLinecap=\"round\" opacity={0.75}>\n                    {drawing.hatch.map((d, i) => <path key={i} d={d} />)}\n                  </svg>\n                </ScrollDraw>\n                <ScrollDraw easing=\"linear\" trigger={scrollWindow()} className=\"absolute inset-0\" aria-hidden>\n                  <svg viewBox={`0 0 ${W} ${H}`} className=\"size-full overflow-visible\" fill=\"none\" stroke={accent} strokeWidth=\"3\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                    <path d={drawing.curve} />\n                  </svg>\n                </ScrollDraw>\n              </>\n            ) : null}\n            <div className=\"absolute inset-x-0 bottom-[4.5%] border-t border-foreground/60\" />\n          </div>\n          <div className=\"mt-3 flex justify-between font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground\">\n            {data.map((d, i) => <span key={d.label} className={i % 2 ? 'hidden sm:inline' : ''}>{d.label}</span>)}\n          </div>\n          <figcaption className=\"mt-6 font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground\">{caption}</figcaption>\n        </figure>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "meta": {
    "motion": "Scroll through it: the hatching and the curve plot left to right.",
    "tall": true
  },
  "type": "registry:block"
}