{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radar-chart",
  "type": "registry:component",
  "title": "Radar Chart",
  "description": "A multi-axis radar chart with up to three translucent series, grid rings, point tooltips and a legend that hides or shows each series.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "charts",
    "radar",
    "spider",
    "chart",
    "skills",
    "comparison",
    "svg"
  ],
  "docs": "https://hyperblur.dev/effects/radar-chart",
  "files": [
    {
      "path": "registry/hyperblur/radar-chart.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/radar-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface RadarSeries {\n  name: string;\n  values: number[];\n  color?: string;\n}\n\nexport interface RadarChartProps extends React.HTMLAttributes<HTMLDivElement> {\n  axes?: string[];\n  series?: RadarSeries[];\n  max?: number;\n  rings?: number;\n  colors?: string[];\n  height?: number;\n  legend?: \"bottom\" | \"right\" | \"none\";\n  valueFormatter?: (n: number) => string;\n  animate?: boolean;\n}\n\nconst PALETTE = [\"#2f7bff\", \"#8b5cf6\", \"#34d399\", \"#fbbf24\", \"#fb7185\", \"#7fb3ff\"];\n\nconst DEFAULT_AXES = [\"Speed\", \"Power\", \"Range\", \"Defense\", \"Agility\", \"Focus\"];\n\nconst DEFAULT_SERIES: RadarSeries[] = [\n  { name: \"Current\", values: [82, 64, 71, 58, 90, 76] },\n  { name: \"Previous\", values: [68, 72, 54, 63, 70, 61] },\n];\n\nconst css = `\n.hb-rdr { display: flex; flex-direction: column; gap: 8px; width: 100%; min-width: 0; box-sizing: border-box; color: #ededed; font-family: inherit; }\n.hb-rdr *, .hb-rdr *::before, .hb-rdr *::after { box-sizing: border-box; }\n.hb-rdr[data-legend=\"right\"] { flex-direction: row; align-items: center; gap: 10px; }\n.hb-rdr-plot { position: relative; flex: 1 1 auto; min-width: 0; width: 100%; max-width: 420px; margin: 0 auto; touch-action: pan-y; }\n.hb-rdr-svg { display: block; width: 100%; height: auto; overflow: visible; }\n.hb-rdr-ring { fill: none; stroke: #262626; stroke-width: 1; }\n.hb-rdr-ring[data-last=\"true\"] { stroke: #333333; }\n.hb-rdr-axis { stroke: #262626; stroke-width: 1; }\n.hb-rdr-label { fill: #a1a1a1; font-size: 10.5px; font-family: inherit; transition: fill .2s ease; }\n.hb-rdr-label[data-on=\"true\"] { fill: #ededed; }\n.hb-rdr-poly {\n  animation: hb-rdr-grow .85s cubic-bezier(.22, .8, .24, 1) backwards;\n  animation-delay: var(--hb-rdr-d, 0ms);\n  transition: opacity .25s ease;\n}\n.hb-rdr-poly[data-dim=\"true\"] { opacity: .28; }\n.hb-rdr-poly[data-off=\"true\"] { opacity: 0; pointer-events: none; }\n.hb-rdr-shape { stroke-width: 1.75; stroke-linejoin: round; transition: fill-opacity .25s ease, stroke-width .2s ease; }\n.hb-rdr-dots {\n  animation: hb-rdr-fade .4s ease backwards;\n  animation-delay: calc(var(--hb-rdr-d, 0ms) + 600ms);\n  transition: opacity .25s ease;\n}\n.hb-rdr-dots[data-dim=\"true\"] { opacity: .28; }\n.hb-rdr-dots[data-off=\"true\"] { opacity: 0; pointer-events: none; }\n.hb-rdr-hit { fill: transparent; outline: none; cursor: pointer; }\n.hb-rdr-hit:focus-visible { stroke: #7fb3ff; stroke-width: 1.5; }\n.hb-rdr-tip {\n  position: absolute;\n  z-index: 2;\n  min-width: 92px;\n  padding: 6px 9px;\n  border-radius: 8px;\n  border: 1px solid #262626;\n  background: #171717;\n  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .8);\n  font-size: 11px;\n  line-height: 1.4;\n  white-space: nowrap;\n  pointer-events: none;\n}\n.hb-rdr-tip-r { display: flex; align-items: center; gap: 6px; color: #ededed; }\n.hb-rdr-tip-d { width: 6px; height: 6px; border-radius: 2px; flex: none; }\n.hb-rdr-tip-l { color: #8f8f8f; }\n.hb-rdr-tip-v {\n  margin-left: auto;\n  padding-left: 10px;\n  color: #ededed;\n  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-variant-numeric: tabular-nums;\n}\n.hb-rdr-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 0; padding: 0; list-style: none; }\n.hb-rdr[data-legend=\"right\"] .hb-rdr-legend { flex: none; flex-direction: column; flex-wrap: nowrap; align-items: stretch; justify-content: center; }\n.hb-rdr-btn {\n  display: inline-flex;\n  align-items: center;\n  gap: 7px;\n  padding: 4px 9px;\n  border: 1px solid transparent;\n  border-radius: 999px;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 11.5px;\n  line-height: 1.3;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease, border-color .15s ease;\n}\n.hb-rdr-btn:hover { background: #1a1a1a; }\n.hb-rdr-btn:focus-visible { outline: 2px solid #7fb3ff; outline-offset: 1px; }\n.hb-rdr-btn[aria-pressed=\"false\"] { color: #6b6b6b; }\n.hb-rdr-btn[aria-pressed=\"false\"] .hb-rdr-name { text-decoration: line-through; }\n.hb-rdr-swatch { width: 8px; height: 8px; border-radius: 3px; flex: none; transition: opacity .2s ease; }\n.hb-rdr-btn[aria-pressed=\"false\"] .hb-rdr-swatch { opacity: .35; }\n.hb-rdr-name { white-space: nowrap; }\n.hb-rdr[data-animate=\"false\"] .hb-rdr-poly, .hb-rdr[data-animate=\"false\"] .hb-rdr-dots { animation: none; }\n@keyframes hb-rdr-grow {\n  from { transform: scale(.05); opacity: 0; }\n}\n@keyframes hb-rdr-fade {\n  from { opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-rdr-poly, .hb-rdr-dots { animation: none !important; }\n  .hb-rdr-poly, .hb-rdr-dots, .hb-rdr-shape, .hb-rdr-label, .hb-rdr-btn { transition: none !important; }\n}\n`;\n\nfunction f(n: number) {\n  return n.toFixed(2);\n}\n\nfunction niceMax(raw: number) {\n  if (!(raw > 0)) return 1;\n  const mag = Math.pow(10, Math.floor(Math.log10(raw)));\n  const half = mag / 2;\n  return Math.ceil(raw / half) * half;\n}\n\nexport function RadarChart({\n  axes = DEFAULT_AXES,\n  series = DEFAULT_SERIES,\n  max,\n  rings = 4,\n  colors = PALETTE,\n  height = 200,\n  legend = \"bottom\",\n  valueFormatter,\n  animate = true,\n  className = \"\",\n  ...rest\n}: RadarChartProps) {\n  const [hidden, setHidden] = React.useState<number[]>([]);\n  const [active, setActive] = React.useState<{ s: number; i: number } | null>(null);\n  const [hoverSeries, setHoverSeries] = React.useState<number | null>(null);\n\n  const n = axes.length;\n  const W = 260;\n  const H = Math.max(120, height);\n  const cx = W / 2;\n  const cy = H / 2;\n  const R = Math.max(24, Math.min(W / 2 - 58, H / 2 - 20));\n  const items = series.map((s, si) => ({ ...s, si, color: s.color ?? colors[si % colors.length] }));\n  const peak = Math.max(0, ...items.flatMap((s) => s.values.filter((v) => Number.isFinite(v))));\n  const top = max ?? niceMax(peak);\n  const ringCount = Math.max(1, Math.round(rings));\n  const fmt = valueFormatter ?? ((v: number) => String(Math.round(v * 10) / 10));\n\n  const angle = (i: number) => -Math.PI / 2 + (i / Math.max(1, n)) * Math.PI * 2;\n  const point = (i: number, frac: number): [number, number] => [\n    cx + R * frac * Math.cos(angle(i)),\n    cy + R * frac * Math.sin(angle(i)),\n  ];\n  const frac = (v: number | undefined) => (Number.isFinite(v) ? Math.min(1, Math.max(0, (v as number) / top)) : 0);\n  const polyPoints = (s: RadarSeries) =>\n    axes\n      .map((_, i) => {\n        const [x, y] = point(i, frac(s.values[i]));\n        return `${f(x)},${f(y)}`;\n      })\n      .join(\" \");\n\n  const toggle = (si: number) =>\n    setHidden((h) => (h.includes(si) ? h.filter((x) => x !== si) : [...h, si]));\n\n  const focusSeries = active ? active.s : hoverSeries;\n  const summary = items.length\n    ? `Radar chart across ${n} axes. ${items\n        .map((s) => {\n          let best = 0;\n          axes.forEach((_, i) => {\n            if ((s.values[i] ?? 0) > (s.values[best] ?? 0)) best = i;\n          });\n          return `${s.name} peaks at ${axes[best]}, ${fmt(s.values[best] ?? 0)}`;\n        })\n        .join(\". \")}.`\n    : \"Radar chart with no data\";\n\n  const tipItem = active ? items.find((s) => s.si === active.s) : undefined;\n  let tip: React.ReactNode = null;\n  if (active && tipItem) {\n    const [px, py] = point(active.i, frac(tipItem.values[active.i]));\n    const below = py < H * 0.28;\n    tip = (\n      <div\n        className=\"hb-rdr-tip\"\n        aria-hidden=\"true\"\n        style={{\n          left: `${Math.min(84, Math.max(16, (px / W) * 100)).toFixed(2)}%`,\n          top: `${((py / H) * 100).toFixed(2)}%`,\n          transform: below ? \"translate(-50%, 14px)\" : \"translate(-50%, calc(-100% - 12px))\",\n        }}\n      >\n        <div className=\"hb-rdr-tip-r\">\n          <span className=\"hb-rdr-tip-d\" style={{ background: tipItem.color }} />\n          {tipItem.name}\n        </div>\n        <div className=\"hb-rdr-tip-r\">\n          <span className=\"hb-rdr-tip-l\">{axes[active.i]}</span>\n          <span className=\"hb-rdr-tip-v\">{fmt(tipItem.values[active.i] ?? 0)}</span>\n        </div>\n      </div>\n    );\n  }\n\n  const legendEl =\n    legend === \"none\" ? null : (\n      <ul className=\"hb-rdr-legend\">\n        {items.map((s) => {\n          const on = !hidden.includes(s.si);\n          return (\n            <li key={s.si}>\n              <button\n                type=\"button\"\n                className=\"hb-rdr-btn\"\n                aria-pressed={on}\n                onClick={() => toggle(s.si)}\n                onMouseEnter={() => setHoverSeries(s.si)}\n                onMouseLeave={() => setHoverSeries(null)}\n                onFocus={() => setHoverSeries(s.si)}\n                onBlur={() => setHoverSeries(null)}\n              >\n                <span className=\"hb-rdr-swatch\" style={{ background: s.color }} />\n                <span className=\"hb-rdr-name\">{s.name}</span>\n              </button>\n            </li>\n          );\n        })}\n      </ul>\n    );\n\n  return (\n    <div\n      className={`hb-rdr ${className}`}\n      data-legend={legend}\n      data-animate={animate ? \"true\" : \"false\"}\n      {...rest}\n    >\n      <style href=\"hb-radar-chart\" precedence=\"default\">{css}</style>\n      <div className=\"hb-rdr-plot\" onMouseLeave={() => setActive(null)}>\n        <svg className=\"hb-rdr-svg\" viewBox={`0 0 ${W} ${H}`} role=\"img\" aria-label={summary}>\n          {Array.from({ length: ringCount }, (_, k) => {\n            const pts = axes\n              .map((_, i) => {\n                const [x, y] = point(i, (k + 1) / ringCount);\n                return `${f(x)},${f(y)}`;\n              })\n              .join(\" \");\n            return <polygon key={k} className=\"hb-rdr-ring\" data-last={k === ringCount - 1 ? \"true\" : \"false\"} points={pts} />;\n          })}\n          {axes.map((_, i) => {\n            const [x, y] = point(i, 1);\n            return <line key={i} className=\"hb-rdr-axis\" x1={f(cx)} y1={f(cy)} x2={f(x)} y2={f(y)} />;\n          })}\n          {axes.map((label, i) => {\n            const c = Math.cos(angle(i));\n            const s = Math.sin(angle(i));\n            const lx = cx + (R + 11) * c;\n            const ly = cy + (R + 11) * s;\n            return (\n              <text\n                key={i}\n                className=\"hb-rdr-label\"\n                data-on={active && active.i === i ? \"true\" : \"false\"}\n                x={f(lx)}\n                y={f(ly)}\n                textAnchor={c > 0.3 ? \"start\" : c < -0.3 ? \"end\" : \"middle\"}\n                dominantBaseline={s < -0.5 ? \"auto\" : s > 0.5 ? \"hanging\" : \"middle\"}\n              >\n                {label}\n              </text>\n            );\n          })}\n          {items.map((s) => {\n            const off = hidden.includes(s.si);\n            const dim = focusSeries !== null && focusSeries !== s.si;\n            return (\n              <g\n                key={s.si}\n                className=\"hb-rdr-poly\"\n                data-off={off ? \"true\" : \"false\"}\n                data-dim={dim ? \"true\" : \"false\"}\n                style={{\n                  transformOrigin: `${f(cx)}px ${f(cy)}px`,\n                  [\"--hb-rdr-d\" as string]: `${s.si * 140}ms`,\n                }}\n              >\n                <polygon\n                  className=\"hb-rdr-shape\"\n                  points={polyPoints(s)}\n                  fill={s.color}\n                  fillOpacity={focusSeries === s.si ? 0.28 : 0.15}\n                  stroke={s.color}\n                />\n              </g>\n            );\n          })}\n          {items.map((s) => {\n            const off = hidden.includes(s.si);\n            const dim = focusSeries !== null && focusSeries !== s.si;\n            return (\n              <g\n                key={s.si}\n                className=\"hb-rdr-dots\"\n                data-off={off ? \"true\" : \"false\"}\n                data-dim={dim ? \"true\" : \"false\"}\n                style={{ [\"--hb-rdr-d\" as string]: `${s.si * 140}ms` }}\n              >\n                {axes.map((label, i) => {\n                  const [x, y] = point(i, frac(s.values[i]));\n                  const on = active && active.s === s.si && active.i === i;\n                  return (\n                    <g key={i}>\n                      <circle cx={f(x)} cy={f(y)} r={on ? 4.5 : 3} fill=\"#0a0a0a\" stroke={s.color} strokeWidth={1.75} />\n                      <circle\n                        className=\"hb-rdr-hit\"\n                        cx={f(x)}\n                        cy={f(y)}\n                        r={9}\n                        tabIndex={off ? -1 : 0}\n                        aria-label={`${s.name}, ${label}: ${fmt(s.values[i] ?? 0)}`}\n                        onMouseEnter={() => setActive({ s: s.si, i })}\n                        onFocus={() => setActive({ s: s.si, i })}\n                        onBlur={() => setActive(null)}\n                      />\n                    </g>\n                  );\n                })}\n              </g>\n            );\n          })}\n        </svg>\n        {tip}\n      </div>\n      {legendEl}\n    </div>\n  );\n}\n"
    }
  ]
}