"use client"; import { motion } from "motion/react"; import { ChartFrame } from "./chart-frame"; import { linearScale, niceTicks } from "@/lib/chart-utils"; export type HistBin = { label: string; value: number }; type HistogramProps = { bins: HistBin[]; width?: number; height?: number; className?: string; }; const M = { top: 16, right: 18, bottom: 36, left: 44 }; /** Histogram — contiguous bars (no gap) growing scaleY from the baseline, staggered. */ export function Histogram({ bins, width = 600, height = 360, className }: HistogramProps) { const max = Math.max(...bins.map((b) => b.value), 1); const sy = linearScale([0, max], [height - M.bottom, M.top]); const baseY = height - M.bottom; const plotW = width - M.left - M.right; const bw = plotW / bins.length; const ticks = niceTicks(0, max, 4); return ( {({ inView, reduce }) => ( <> {ticks.map((t) => ( {t} ))} {bins.map((b, i) => { const x = M.left + i * bw; const y = sy(b.value); const h = baseY - y; return ( {b.label} ); })} )} ); }