"use client"; import { motion } from "motion/react"; import { ChartFrame } from "./chart-frame"; import { polygonPath, catColor, type Point } from "@/lib/chart-utils"; export type RadarSeries = { label: string; values: number[] }; type RadarChartProps = { axes: string[]; series: RadarSeries[]; max?: number; size?: number; className?: string; }; /** RadarChart — grid rings + spokes draw, then each series polygon draws (pathLength) and fills. Multi-series via --cat-*. */ export function RadarChart({ axes, series, max, size = 380, className }: RadarChartProps) { const cx = size / 2; const cy = size / 2; const r = size / 2 - 44; const n = axes.length; const maxVal = max ?? Math.max(...series.flatMap((s) => s.values), 1); const angleAt = (i: number) => (i / n) * Math.PI * 2 - Math.PI / 2; const pointAt = (i: number, value: number): Point => { const rr = (value / maxVal) * r; return { x: cx + Math.cos(angleAt(i)) * rr, y: cy + Math.sin(angleAt(i)) * rr }; }; const rings = [0.25, 0.5, 0.75, 1]; return ( {({ inView, reduce }) => ( <> {rings.map((f, ri) => ( { const p = pointAt(i, maxVal * f); return `${p.x},${p.y}`; }).join(" ")} fill="none" stroke="var(--ink-100)" strokeWidth={1} /> ))} {axes.map((ax, i) => { const outer = pointAt(i, maxVal); const lp = pointAt(i, maxVal * 1.16); return ( {ax} ); })} {series.map((s, si) => { const pts = s.values.map((v, i) => pointAt(i, v)); const color = catColor(si); return ( {pts.map((p, i) => ( ))} ); })} )} ); }