"use client"; import { motion } from "motion/react"; import { ChartFrame } from "./chart-frame"; import { linearScale, niceTicks, catColor } from "@/lib/chart-utils"; export type Bubble = { x: number; y: number; size: number; label?: string }; type BubbleChartProps = { data: Bubble[]; /** Max bubble radius in drawing units. Default 34. */ maxRadius?: number; width?: number; height?: number; className?: string; }; const M = { top: 24, right: 28, bottom: 34, left: 44 }; /** BubbleChart — scatter with radius mapped to `size`; bubbles inflate (scale 0→1), staggered. */ export function BubbleChart({ data, maxRadius = 34, width = 600, height = 400, className }: BubbleChartProps) { const xs = data.map((d) => d.x); const ys = data.map((d) => d.y); const sizes = data.map((d) => d.size); const maxSize = Math.max(...sizes, 1); 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 r = (s: number) => 6 + Math.sqrt(s / maxSize) * (maxRadius - 6); const yticks = niceTicks(Math.min(0, ...ys), Math.max(...ys), 4); return ( {({ inView, reduce }) => ( <> {yticks.map((t) => ( ))} {data.map((d, i) => { const cx = sx(d.x); const cy = sy(d.y); return ( {d.label && ( {d.label} )} ); })} )} ); }