"use client"; import { motion } from "motion/react"; import { ChartFrame } from "./chart-frame"; import { linearScale, niceTicks } from "@/lib/chart-utils"; export type BoxGroup = { label: string; min: number; q1: number; median: number; q3: number; max: number; }; type BoxPlotProps = { data: BoxGroup[]; width?: number; height?: number; className?: string; }; const M = { top: 16, right: 18, bottom: 34, left: 44 }; /** BoxPlot — whiskers fade/draw, box grows scaleY from the median, median line lands last. */ export function BoxPlot({ data, width = 600, height = 360, className }: BoxPlotProps) { const lo = Math.min(...data.map((d) => d.min)); const hi = Math.max(...data.map((d) => d.max)); const sy = linearScale([lo, hi], [height - M.bottom, M.top]); const ticks = niceTicks(lo, hi, 4); const plotW = width - M.left - M.right; const step = plotW / data.length; const bw = Math.min(step * 0.5, 60); return ( {({ inView, reduce }) => ( <> {ticks.map((t) => ( {t} ))} {data.map((d, i) => { const cx = M.left + step * (i + 0.5); const yTop = sy(d.q3); const yBot = sy(d.q1); const yMed = sy(d.median); const delay = 0.1 + i * 0.12; return ( {/* whisker */} {/* box */} {d.label} ); })} )} ); }