{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radar-chart",
  "type": "registry:component",
  "title": "Radar Chart",
  "description": "Several measures on spokes around a centre, one closed shape per series, so profiles can be compared at a glance: which is stronger where, with arrow keys reading each spoke.",
  "categories": [
    "viz"
  ],
  "dependencies": [],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/chart",
    "@rivier-ui/cn"
  ],
  "files": [
    {
      "path": "registry/viz/radar-chart.tsx",
      "type": "registry:component",
      "target": "components/viz/radar-chart.tsx",
      "content": "\"use client\";\n/**\n * @name radar-chart\n * @category viz\n * @description Several measures on spokes around a centre, one closed shape per series, so profiles can be compared at a glance: which is stronger where, with arrow keys reading each spoke.\n * @when Comparing two or three profiles across five to ten measures on the same scale: skills, product ratings, nutrition against a target. For exact comparison, or measures on different scales, use bar-chart or small-multiples; with more than three series the shapes tangle.\n * @example\n * <RadarChart\n *   label=\"Two plans compared\"\n *   data={[\n *     { measure: \"Speed\", basic: 3, plus: 4 },\n *     { measure: \"Storage\", basic: 2, plus: 5 },\n *     { measure: \"Support\", basic: 3, plus: 4 },\n *     { measure: \"Price\", basic: 5, plus: 3 },\n *     { measure: \"Security\", basic: 4, plus: 4 },\n *   ]}\n *   axis=\"measure\"\n *   series={[{ key: \"basic\", label: \"Basic\" }, { key: \"plus\", label: \"Plus\" }]}\n *   max={5}\n * />\n */\nimport { useMemo } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport {\n  ChartContainer,\n  ChartEmpty,\n  ChartLegend,\n  ChartMark,\n  chartSeries,\n  ChartSvg,\n  ChartTooltip,\n  fitText,\n  formatNumber,\n  readNumber,\n  useChartCursor,\n  type ChartBaseProps,\n  type ChartSeries,\n} from \"@/components/viz/chart\";\n\nexport type RadarChartProps<T extends object> = ChartBaseProps & {\n  /** One object per spoke (measure). */\n  data: readonly T[];\n  /** The field naming each spoke. */\n  axis: keyof T & string;\n  /** The shapes, in a fixed order. */\n  series: readonly ChartSeries<T>[];\n  /** The value at the rim. Default: the largest value, made round. */\n  max?: number;\n  /** How many rings of the grid. Default 4. */\n  rings?: number;\n  /** Fill each shape lightly. Default true. */\n  fill?: boolean;\n  showLegend?: boolean;\n};\n\nexport function RadarChart<T extends object>({\n  data,\n  axis,\n  series,\n  max,\n  rings = 4,\n  fill = true,\n  showLegend,\n  label,\n  aspect = 1,\n  height,\n  emptyLabel,\n  locale,\n  formatValue,\n  className,\n  ...props\n}: RadarChartProps<T>) {\n  const spokes = useMemo(() => data.map((row) => String((row as Record<string, unknown>)[axis] ?? \"\")), [data, axis]);\n  const cursor = useChartCursor(spokes.length);\n  const number = formatValue ?? ((value: number) => formatNumber(value, locale));\n  const highest = max ?? Math.max(1, ...data.flatMap((row) => series.map((item) => readNumber(row, item.key) ?? 0)));\n  const table = {\n    caption: label,\n    columns: [axis, ...series.map((item) => item.label)],\n    rows: data.map((row, index) => [\n      spokes[index] ?? \"\",\n      ...series.map((item) => {\n        const v = readNumber(row, item.key);\n        return v === null ? \"\" : number(v);\n      }),\n    ]),\n  };\n  const rowsAt = (index: number): { label: string; value: string; index: number }[] =>\n    series.flatMap((item, s) => {\n      const v = data[index] ? readNumber(data[index], item.key) : null;\n      return v === null ? [] : [{ label: item.label, value: number(v), index: s }];\n    });\n  const legend = showLegend ?? series.length > 1;\n\n  return (\n    <div data-slot=\"radar-chart\" className={cn(\"flex w-full min-w-0 flex-col gap-3\", className)} {...props}>\n      {legend ? <ChartLegend items={series.map((item, index) => ({ label: item.label, index }))} /> : null}\n      <ChartContainer\n        aspect={aspect}\n        height={height}\n        table={table}\n        announcement={\n          cursor.keyboard && cursor.active !== null\n            ? `${spokes[cursor.active] ?? \"\"}: ${rowsAt(cursor.active)\n                .map((row) => `${row.label} ${row.value}`)\n                .join(\", \")}`\n            : \"\"\n        }\n      >\n        {({ width, height: plotHeight }) => {\n          if (spokes.length < 3) return <ChartEmpty>{emptyLabel}</ChartEmpty>;\n          const cx = width / 2;\n          const cy = plotHeight / 2;\n          const room = Math.min(90, width * 0.22);\n          const radius = Math.max(10, Math.min(cx - room, cy - 20));\n          const angle = (index: number): number => (index / spokes.length) * Math.PI * 2 - Math.PI / 2;\n          const at = (index: number, value: number): [number, number] => {\n            const r = (Math.max(0, value) / highest) * radius;\n            return [cx + Math.cos(angle(index)) * r, cy + Math.sin(angle(index)) * r];\n          };\n          const ring = (share: number): string => spokes.map((_, i) => at(i, share * highest).join(\",\")).join(\" \");\n          const tip = cursor.active === null ? undefined : at(cursor.active, highest);\n          return (\n            <>\n              <ChartSvg label={label} width={width} height={plotHeight} interactive {...cursor.svgProps}>\n                <g aria-hidden=\"true\">\n                  {Array.from({ length: rings }, (_, i) => (\n                    <polygon key={i} points={ring((i + 1) / rings)} fill=\"none\" className=\"stroke-border\" />\n                  ))}\n                  {spokes.map((name, index) => {\n                    const [x, y] = at(index, highest);\n                    const cos = Math.cos(angle(index));\n                    const anchor = Math.abs(cos) < 0.2 ? \"middle\" : cos > 0 ? \"start\" : \"end\";\n                    const [lx, ly] = at(index, highest * 1.08);\n                    return (\n                      <g key={index} onPointerEnter={() => cursor.point(index)}>\n                        <line x1={cx} y1={cy} x2={x} y2={y} className={cursor.active === index ? \"stroke-foreground\" : \"stroke-border\"} />\n                        <circle cx={x} cy={y} r={16} fill=\"transparent\" />\n                        <text x={lx} y={ly} dy=\"0.32em\" textAnchor={anchor} className={cn(\"text-xs\", cursor.active === index ? \"fill-foreground font-medium\" : \"fill-muted-foreground\")}>\n                          {fitText(name, room - 8)}\n                        </text>\n                      </g>\n                    );\n                  })}\n                  <text x={cx + 4} y={cy - radius} dy=\"-0.2em\" className=\"fill-muted-foreground text-xs tabular-nums\">\n                    {number(highest)}\n                  </text>\n                  {series.map((item, s) => {\n                    const points = data.map((row, i) => at(i, readNumber(row, item.key) ?? 0));\n                    const style = chartSeries(s);\n                    return (\n                      <g key={item.key} className=\"pointer-events-none\">\n                        <polygon\n                          points={points.map((p) => p.join(\",\")).join(\" \")}\n                          className={cn(style.stroke, style.fill)}\n                          fillOpacity={fill ? 0.14 : 0}\n                          strokeWidth={2}\n                          strokeDasharray={style.dash}\n                          strokeLinejoin=\"round\"\n                        />\n                        {points.map(([x, y], i) => (cursor.active === i ? <ChartMark key={i} index={s} x={x} y={y} radius={4} /> : null))}\n                      </g>\n                    );\n                  })}\n                </g>\n              </ChartSvg>\n              {tip && cursor.active !== null ? <ChartTooltip x={tip[0]} y={tip[1]} side={tip[0] > cx ? \"left\" : \"right\"} title={spokes[cursor.active]} rows={rowsAt(cursor.active)} /> : null}\n            </>\n          );\n        }}\n      </ChartContainer>\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "viz",
    "when": "Comparing two or three profiles across five to ten measures on the same scale: skills, product ratings, nutrition against a target. For exact comparison, or measures on different scales, use bar-chart or small-multiples; with more than three series the shapes tangle.",
    "example": "<RadarChart\n  label=\"Two plans compared\"\n  data={[\n    { measure: \"Speed\", basic: 3, plus: 4 },\n    { measure: \"Storage\", basic: 2, plus: 5 },\n    { measure: \"Support\", basic: 3, plus: 4 },\n    { measure: \"Price\", basic: 5, plus: 3 },\n    { measure: \"Security\", basic: 4, plus: 4 },\n  ]}\n  axis=\"measure\"\n  series={[{ key: \"basic\", label: \"Basic\" }, { key: \"plus\", label: \"Plus\" }]}\n  max={5}\n/>",
    "client": true
  }
}
