{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radar-chart",
  "title": "Radar Chart",
  "description": "A multi-series radar/spider chart with ring gridlines, per-series solid or dashed strokes, optional point markers, and a hover tooltip comparing every series at the highlighted axis.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/radar-chart/radar-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type RadarChartTheme = \"light\" | \"dark\";\n\nexport interface RadarChartSeries {\n  visible?: boolean;\n  label: string;\n  color: string;\n  style?: \"solid\" | \"dashed\";\n  showMarkers?: boolean;\n}\n\nexport interface RadarChartAxisPoint {\n  label: string;\n  v1: number;\n  v2: number;\n  v3: number;\n}\n\nexport interface RadarChartProps {\n  theme?: RadarChartTheme;\n  title?: string;\n  subtitle?: string;\n  chartHeight?: number;\n  showLegend?: boolean;\n  max?: number;\n  rings?: number;\n  outerRadius?: number;\n  series1?: RadarChartSeries;\n  series2?: RadarChartSeries;\n  series3?: RadarChartSeries;\n  axes?: RadarChartAxisPoint[];\n  enableHover?: boolean;\n  className?: string;\n}\n\nconst VB_W = 1200;\nconst VB_H = 560;\nconst PAD_TOP = 26;\nconst PAD_BOTTOM = 44;\n\nfunction clamp(n: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, n));\n}\n\nfunction round(n: number): number {\n  return Math.round(n * 1000) / 1000;\n}\n\nfunction pointOnCircle(cx: number, cy: number, r: number, angle: number) {\n  return { x: round(cx + r * Math.cos(angle)), y: round(cy + r * Math.sin(angle)) };\n}\n\nconst DARK_SERIES1: Required<RadarChartSeries> = { visible: true, label: \"Launch build\", color: \"#F5F4F1\", style: \"solid\", showMarkers: true };\nconst DARK_SERIES2: Required<RadarChartSeries> = { visible: true, label: \"Target bar\", color: \"#87FFE3\", style: \"dashed\", showMarkers: false };\nconst DARK_SERIES3: Required<RadarChartSeries> = { visible: true, label: \"Buyer benchmark\", color: \"#F2A841\", style: \"solid\", showMarkers: true };\nconst LIGHT_SERIES1: Required<RadarChartSeries> = { ...DARK_SERIES1, color: \"#0A0A0A\" };\nconst LIGHT_SERIES2: Required<RadarChartSeries> = { ...DARK_SERIES2, color: \"#0E9F80\" };\nconst LIGHT_SERIES3: Required<RadarChartSeries> = { ...DARK_SERIES3, color: \"#D9822B\" };\n\nconst DEFAULT_AXES: RadarChartAxisPoint[] = [\n  { label: \"SSO\", v1: 78, v2: 80, v3: 60 },\n  { label: \"Data residency\", v1: 55, v2: 82, v3: 58 },\n  { label: \"Audit exports\", v1: 60, v2: 85, v3: 92 },\n  { label: \"Key rotation\", v1: 58, v2: 88, v3: 90 },\n  { label: \"RPO drills\", v1: 42, v2: 85, v3: 88 },\n  { label: \"Admin guardrails\", v1: 50, v2: 82, v3: 70 },\n  { label: \"Procurement\", v1: 48, v2: 80, v3: 65 },\n  { label: \"Support SLA\", v1: 72, v2: 85, v3: 78 },\n];\n\nexport function RadarChart({\n  theme = \"dark\",\n  title = \"Security posture comparison\",\n  subtitle = \"\",\n  chartHeight = 420,\n  showLegend = true,\n  max = 100,\n  rings = 4,\n  outerRadius = 150,\n  series1 = theme === \"light\" ? LIGHT_SERIES1 : DARK_SERIES1,\n  series2 = theme === \"light\" ? LIGHT_SERIES2 : DARK_SERIES2,\n  series3 = theme === \"light\" ? LIGHT_SERIES3 : DARK_SERIES3,\n  axes = DEFAULT_AXES,\n  enableHover = true,\n  className,\n}: RadarChartProps) {\n  const isDark = theme === \"dark\";\n  const [hoverIndex, setHoverIndex] = React.useState<number | null>(null);\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const [containerWidth, setContainerWidth] = React.useState(0);\n\n  React.useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => setContainerWidth(entry.contentRect.width));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  // preserveAspectRatio=\"none\" stretches the SVG to fill its box; on a narrow\n  // container that non-uniform scaling thins axis-label text to illegibility, so\n  // below the viewBox's natural aspect ratio we shrink the box to match it.\n  const effectiveHeight = containerWidth > 0 ? Math.min(chartHeight, containerWidth * (VB_H / VB_W)) : chartHeight;\n\n  // Keep axis labels a readable ~13px on screen regardless of how far the viewBox is scaled down.\n  const viewScale = containerWidth > 0 ? Math.min(containerWidth / VB_W, effectiveHeight / VB_H) : 0.5;\n  const axisFontSize = Math.min(36, Math.max(12, 13 / viewScale));\n\n  const palette = {\n    cardBg: isDark ? \"#0E0E0E\" : \"#ffffff\",\n    cardBorder: isDark ? \"rgba(255,255,255,0.08)\" : \"rgba(0,0,0,0.06)\",\n    textPrimary: isDark ? \"#f4f5f7\" : \"#111317\",\n    textSub: isDark ? \"rgba(255,255,255,0.55)\" : \"rgba(17,19,23,0.55)\",\n    gridLine: isDark ? \"rgba(255,255,255,0.07)\" : \"rgba(17,19,23,0.08)\",\n    axisText: isDark ? \"rgba(255,255,255,0.7)\" : \"rgba(17,19,23,0.7)\",\n    badgeBorder: isDark ? \"rgba(255,255,255,0.12)\" : \"rgba(0,0,0,0.08)\",\n  };\n\n  const headerHeight = (title ? 30 : 0) + (subtitle ? 22 : 0);\n  const series = [series1, series2, series3];\n  const valueKeys: Array<keyof RadarChartAxisPoint> = [\"v1\", \"v2\", \"v3\"];\n  const n = axes.length;\n  const cx = VB_W / 2;\n  const cy = PAD_TOP + (showLegend ? 34 : 0) + headerHeight + (VB_H - PAD_TOP - (showLegend ? 34 : 0) - headerHeight - PAD_BOTTOM) / 2;\n  const step = n > 0 ? (Math.PI * 2) / n : 0;\n  const angleAt = (i: number) => -Math.PI / 2 + i * step;\n  const pointFor = (i: number, value: number) => {\n    const r = clamp(value / max, 0, 1) * outerRadius;\n    return pointOnCircle(cx, cy, r, angleAt(i));\n  };\n\n  const ringPolygons = React.useMemo(() => {\n    const result: string[] = [];\n    for (let ring = 1; ring <= rings; ring++) {\n      const r = (ring / rings) * outerRadius;\n      const pts = Array.from({ length: n }, (_, i) => pointOnCircle(cx, cy, r, angleAt(i)));\n      result.push(pts.map((p) => `${p.x},${p.y}`).join(\" \"));\n    }\n    return result;\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [n, rings, outerRadius, cx, cy]);\n\n  const seriesPolygons = React.useMemo(() => {\n    return valueKeys.map((key) => axes.map((d, i) => pointFor(i, (d[key] as number) ?? 0)));\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [axes, n, max, outerRadius, cx, cy]);\n\n  const hoverAxis = hoverIndex !== null ? clamp(hoverIndex, 0, n - 1) : null;\n\n  const hover = React.useMemo(() => {\n    if (hoverAxis === null) return null;\n    const d = axes[hoverAxis];\n    if (!d) return null;\n    const items = series\n      .map((s, i) => ({ s, value: (d[valueKeys[i]] as number) ?? 0 }))\n      .filter((it) => it.s.visible !== false);\n    return { label: d.label, items };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [hoverAxis, axes, series1, series2, series3]);\n\n  return (\n    <div\n      className={cn(\"box-border flex w-full flex-col gap-1 overflow-hidden rounded-[20px]\", className)}\n      style={{ backgroundColor: palette.cardBg, border: `1px solid ${palette.cardBorder}`, padding: \"28px 32px\", fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\" }}\n    >\n      {title && <div className=\"text-center text-[17px] font-bold\" style={{ color: palette.textPrimary }}>{title}</div>}\n      {subtitle && (\n        <div className=\"mx-auto mt-0.5 max-w-[760px] text-center text-[12.5px] leading-[1.5]\" style={{ color: palette.textSub }}>\n          {subtitle}\n        </div>\n      )}\n\n      {showLegend && (\n        <div className=\"mt-3.5 flex flex-wrap justify-center gap-[22px]\">\n          {series.map(\n            (s, i) =>\n              s.visible !== false && (\n                <div key={i} className=\"flex items-center gap-[7px]\">\n                  <span className=\"inline-block h-[9px] w-[9px] rounded-[3px]\" style={{ backgroundColor: s.color }} />\n                  <span className=\"text-[12.5px] font-semibold\" style={{ color: palette.textPrimary }}>\n                    {s.label}\n                  </span>\n                </div>\n              ),\n          )}\n        </div>\n      )}\n\n      <div ref={containerRef} className=\"relative mt-3 w-full\" style={{ height: effectiveHeight }}>\n        <svg width=\"100%\" height=\"100%\" viewBox={`0 0 ${VB_W} ${VB_H}`} preserveAspectRatio=\"none\" className=\"block overflow-visible\">\n          {ringPolygons.map((pts, ri) => (\n            <polygon\n              key={`ring-${ri}`}\n              points={pts}\n              fill=\"none\"\n              stroke={palette.gridLine}\n              strokeWidth={1}\n              strokeDasharray={ri === rings - 1 ? \"4 4\" : undefined}\n            />\n          ))}\n\n          {axes.map((d, i) => {\n            const outer = pointOnCircle(cx, cy, outerRadius, angleAt(i));\n            return <line key={`spoke-${i}`} x1={cx} y1={cy} x2={outer.x} y2={outer.y} stroke={palette.gridLine} strokeWidth={1} />;\n          })}\n\n          {axes.map((d, i) => {\n            const pos = pointOnCircle(cx, cy, outerRadius + 10 + axisFontSize * 0.8, angleAt(i));\n            const cosA = Math.cos(angleAt(i));\n            const anchor = cosA > 0.3 ? \"start\" : cosA < -0.3 ? \"end\" : \"middle\";\n            return (\n              <text key={`axislabel-${i}`} x={pos.x} y={pos.y} textAnchor={anchor} dominantBaseline=\"middle\" fontSize={axisFontSize} fill={palette.axisText}>\n                {d.label}\n              </text>\n            );\n          })}\n\n          {series.map(\n            (s, si) =>\n              s.visible !== false && (\n                <polygon\n                  key={`radarpoly-${si}`}\n                  points={seriesPolygons[si].map((p) => `${p.x},${p.y}`).join(\" \")}\n                  fill={s.color}\n                  fillOpacity={isDark ? 0.14 : 0.1}\n                  stroke={s.color}\n                  strokeWidth={2}\n                  strokeDasharray={s.style === \"dashed\" ? \"7 5\" : undefined}\n                  strokeLinejoin=\"round\"\n                />\n              ),\n          )}\n\n          {series.map(\n            (s, si) =>\n              s.visible !== false &&\n              s.showMarkers &&\n              seriesPolygons[si].map((p, i) => <circle key={`radarmk-${si}-${i}`} cx={p.x} cy={p.y} r={3.4} fill={s.color} />),\n          )}\n\n          {enableHover &&\n            axes.map((d, i) => {\n              const halfStep = step / 2;\n              const p1 = pointOnCircle(cx, cy, outerRadius + 30, angleAt(i) - halfStep);\n              const p2 = pointOnCircle(cx, cy, outerRadius + 30, angleAt(i) + halfStep);\n              const largeArc = halfStep * 2 > Math.PI ? 1 : 0;\n              const wedge = `M ${cx} ${cy} L ${p1.x} ${p1.y} A ${outerRadius + 30} ${outerRadius + 30} 0 ${largeArc} 1 ${p2.x} ${p2.y} Z`;\n              return (\n                <path\n                  key={`radarhit-${i}`}\n                  d={wedge}\n                  fill=\"transparent\"\n                  stroke=\"none\"\n                  style={{ cursor: \"pointer\" }}\n                  onMouseEnter={() => setHoverIndex(i)}\n                  onMouseLeave={() => setHoverIndex(null)}\n                />\n              );\n            })}\n        </svg>\n\n        {enableHover && hoverAxis !== null && hover && (\n          <div\n            className=\"absolute min-w-[150px] rounded-[10px] px-3 py-2 pointer-events-none whitespace-nowrap\"\n            style={{\n              left: `${(pointOnCircle(cx, cy, outerRadius + 30, angleAt(hoverAxis)).x / VB_W) * 100}%`,\n              top: `${(pointOnCircle(cx, cy, outerRadius + 30, angleAt(hoverAxis)).y / VB_H) * 100}%`,\n              transform: `translate(${Math.cos(angleAt(hoverAxis)) >= 0 ? \"0%\" : \"-100%\"}, -50%)`,\n              backgroundColor: isDark ? \"rgba(10,10,14,0.94)\" : \"rgba(255,255,255,0.97)\",\n              border: `1px solid ${palette.badgeBorder}`,\n              boxShadow: isDark ? \"0 10px 28px rgba(0,0,0,0.5)\" : \"0 6px 20px rgba(0,0,0,0.12)\",\n            }}\n          >\n            <div className=\"mb-1.5 text-[11.5px] font-bold\" style={{ color: palette.textPrimary }}>\n              {hover.label}\n            </div>\n            {hover.items.map((it, ri) => (\n              <div key={ri} className=\"mt-1 flex items-center justify-between gap-3\">\n                <div className=\"flex items-center gap-1.5\">\n                  <span className=\"inline-block h-2 w-2 shrink-0 rounded-full\" style={{ backgroundColor: it.s.color }} />\n                  <span className=\"text-[11.5px]\" style={{ color: palette.textSub }}>\n                    {it.s.label}\n                  </span>\n                </div>\n                <span className=\"text-[11.5px] font-bold\" style={{ color: palette.textPrimary }}>\n                  {Math.round(it.value)}\n                </span>\n              </div>\n            ))}\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}