{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-radar",
  "title": "Radar chart",
  "description": "A radar chart: rings and spokes, then each series' shape hatched in and outlined, the first in the accent.",
  "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-radar.tsx",
      "content": "'use client';\n\n/**\n * chart-radar — a radar chart a pen plots as you scroll: the rings and spokes\n * first, then each series' shape hatched in, then its outline, the first in\n * the accent colour, with a dot on every reading.\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 names, 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, hatchMarks, marker, niceTicks, num, seriesOf, toPath, useSize,\n  type ChartTrigger, type ChartConfig, type Datum, type Mark, type Pen, type Pt,\n} from '@/lib/chart';\n\nexport interface ChartRadarProps {\n  /** One object per spoke. */\n  data?: Datum[];\n  /** The key in each object that names its spoke. */\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  /** The value at the outer ring. Defaults to a round number above the largest value. */\n  max?: number;\n  /** Rings, as polygons (like a web) or circles. */\n  grid?: 'polygon' | 'circle';\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  { skill: 'Speed', score: 86 }, { skill: 'Range', score: 64 }, { skill: 'Control', score: 92 },\n  { skill: 'Stamina', score: 71 }, { skill: 'Accuracy', score: 58 }, { skill: 'Recovery', score: 77 },\n];\n\n// The web's radius and where the spoke names sit, as fractions of its square box\n// (the names fall in the padding round it).\nconst R = 0.46, RL = 0.53;\n\nexport function ChartRadar({\n  data = SAMPLE,\n  index = 'skill',\n  config,\n  max,\n  grid = 'polygon',\n  legend,\n  accent = ACCENT,\n  label = 'Radar chart',\n  trigger = 'scroll',\n  duration = 1800,\n  className = '',\n}: ChartRadarProps) {\n  const series = seriesOf(data, index, config, accent);\n  const ticks = niceTicks(0, max ?? Math.max(...data.flatMap((d) => series.map((s) => num(d[s.key])))), 4);\n  const top = max ?? ticks[ticks.length - 1];\n  const n = data.length;\n  const angle = (i: number) => (i / n) * Math.PI * 2;\n  const [ref, size] = useSize<HTMLDivElement>();\n\n  const pens = useMemo((): Pen[] | null => {\n    if (!size) return null;\n    const s = Math.min(size.w, size.h);\n    const cx = size.w / 2, cy = size.h / 2, r = s * R;\n    const at = (i: number, v: number): Pt => [cx + Math.sin(angle(i)) * r * v, cy - Math.cos(angle(i)) * r * v];\n    const rings: Mark[] = ticks.filter((t) => t > 0 && t <= top).map((t) => {\n      const k = t / top;\n      const pts: Pt[] = grid === 'circle'\n        ? Array.from({ length: 97 }, (_, j): Pt => [cx + Math.sin((j / 96) * Math.PI * 2) * r * k, cy - Math.cos((j / 96) * Math.PI * 2) * r * k])\n        : [...Array.from({ length: n }, (_, i) => at(i, k)), at(0, k)];\n      return { d: toPath(pts), width: k === 1 ? 0.9 : 0.6, opacity: k === 1 ? 0.6 : 0.28 };\n    });\n    const spokes: Mark[] = data.map((_, i) => ({ d: toPath([[cx, cy], at(i, 1)]), width: 0.6, opacity: 0.35 }));\n    const fill: Mark[] = [];\n    const outline: Mark[] = [];\n    const dots: Mark[] = [];\n    series.forEach((ser, k) => {\n      const pts = data.map((d, i) => at(i, Math.max(0, num(d[ser.key])) / top));\n      fill.push(...hatchMarks(pts, ser.hatch, { opacity: k === 0 ? 0.75 : 0.6, width: 0.9, inset: 3 }));\n      outline.push({ d: toPath([...pts, pts[0]]), color: ser.color, width: k === 0 ? 2 : 1.5 });\n      pts.forEach(([x, y]) => dots.push({ d: marker(ser.marker, x, y, 2.6), color: ser.color, width: 1.2 }));\n    });\n    return [\n      { marks: [...rings, ...spokes], ...PHASE.axes, spread: 0.8 },\n      { marks: fill, ...PHASE.fill, spread: 2.5 },\n      { marks: outline, from: PHASE.ink.from, to: 0.6, spread: 0.5 * (outline.length - 1) },\n      { marks: dots, from: 0.7, to: PHASE.ink.to, spread: 2 },\n    ];\n  }, [size, data, index, config, top, grid, accent]);\n\n  return (\n    <figure className={`mx-auto w-full max-w-md ${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=\"px-16 py-7\">\n          <div ref={ref} data-slot=\"plot\" className=\"relative aspect-square w-full\">\n            {size && pens ? <PenLayers size={size} pens={pens} trigger={trigger} duration={duration} /> : null}\n            {data.map((d, i) => {\n              const sx = Math.sin(angle(i)), sy = -Math.cos(angle(i));\n              const tx = sx > 0.3 ? '0%' : sx < -0.3 ? '-100%' : '-50%';\n              const ty = sy < -0.6 ? '-100%' : sy > 0.6 ? '0%' : '-50%';\n              return (\n                <span\n                  key={i}\n                  className=\"absolute whitespace-nowrap font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground\"\n                  style={{ left: `${(50 + sx * RL * 100).toFixed(2)}%`, top: `${(50 + sy * RL * 100).toFixed(2)}%`, translate: `${tx} ${ty}` }}\n                >\n                  {String(d[index])}\n                </span>\n              );\n            })}\n          </div>\n        </div>\n        {(legend ?? series.length > 1) && <Legend series={series} kind=\"hatch\" className=\"mt-2 justify-center\" />}\n      </div>\n    </figure>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/scrollfx/chart-radar.tsx"
    }
  ],
  "type": "registry:ui"
}