"use client"; import { motion } from "motion/react"; import { ChartFrame } from "@/components/charts/chart-frame"; import { treeLayout, type TreeNode } from "@/lib/layout"; type DecisionTreeProps = { root: TreeNode; width?: number; height?: number; className?: string; }; const BOX_W = 124; const BOX_H = 44; /** DecisionTree — tree where internal nodes are decisions (accent outline) and leaves are outcomes; edges carry yes/no labels and draw in. */ export function DecisionTree({ root, width = 720, height = 400, className }: DecisionTreeProps) { const { nodes, edges } = treeLayout(root, width, height); const isLeaf = (id: string) => !nodes.some((n) => n.parentId === id); return ( {({ inView, reduce }) => ( <> {edges.map((e, i) => { const target = nodes.find((n) => n.x === e.to.x && n.y === e.to.y); const midY = (e.from.y + BOX_H / 2 + (e.to.y - BOX_H / 2)) / 2; const d = `M${e.from.x},${e.from.y + BOX_H / 2} V${midY} H${e.to.x} V${e.to.y - BOX_H / 2}`; return ( {e.label && ( {e.label} )} ); })} {nodes.map((n) => { const leaf = isLeaf(n.id); return ( {n.label} ); })} )} ); }