"use client"; import { motion } from "motion/react"; import { ChartFrame } from "@/components/charts/chart-frame"; import { radialLayout, type TreeNode } from "@/lib/layout"; import { catColor } from "@/lib/chart-utils"; type MindMapProps = { root: TreeNode; width?: number; height?: number; className?: string; }; /** MindMap — central node with radial branches (curved edges); reveals outward by depth. */ export function MindMap({ root, width = 640, height = 460, className }: MindMapProps) { const cx = width / 2; const cy = height / 2; const { nodes, edges } = radialLayout(root, cx, cy, Math.min(width, height) / 2 - 70); const branchColor = new Map(); (root.children ?? []).forEach((b, i) => branchColor.set(b.id, catColor(i))); const colorFor = (n: { id: string; parentId?: string }): string => branchColor.get(n.id) ?? (n.parentId ? branchColor.get(n.parentId) ?? "var(--accent-500)" : "var(--accent-500)"); return ( {({ inView, reduce }) => ( <> {edges.map((e, i) => { const mx = (e.from.x + e.to.x) / 2; const d = `M${e.from.x},${e.from.y} Q${mx},${e.from.y} ${e.to.x},${e.to.y}`; return ( ); })} {nodes.map((n) => { const w = n.depth === 0 ? 120 : Math.max(56, (n.label?.length ?? 4) * 8 + 24); const h = n.depth === 0 ? 48 : 32; const color = colorFor(n); return ( {n.label} ); })} )} ); }