"use client"; import { motion } from "motion/react"; import { ChartFrame } from "./chart-frame"; import { linearScale, niceTicks, catColor, type Point } from "@/lib/chart-utils"; export type ScatterSeries = { label: string; data: Point[] }; type ScatterPlotProps = { series: ScatterSeries[]; width?: number; height?: number; className?: string; }; const M = { top: 16, right: 18, bottom: 34, left: 44 }; /** ScatterPlot — points scale + fade in, staggered, over drawn axes. */ export function ScatterPlot({ series, width = 560, height = 380, className }: ScatterPlotProps) { const all = series.flatMap((s) => s.data); const xs = all.map((p) => p.x); const ys = all.map((p) => p.y); const sx = linearScale([Math.min(...xs), Math.max(...xs)], [M.left, width - M.right]); const sy = linearScale([Math.min(0, ...ys), Math.max(...ys)], [height - M.bottom, M.top]); const yticks = niceTicks(Math.min(0, ...ys), Math.max(...ys), 4); return ( {({ inView, reduce }) => ( <> {yticks.map((t) => ( {t} ))} {series.map((s, si) => s.data.map((p, i) => { const cx = sx(p.x); const cy = sy(p.y); return ( ); }), )} )} ); }