"use client"; import { motion } from "motion/react"; import { ChartFrame } from "./chart-frame"; import { seqRamp } from "@/lib/chart-utils"; type HeatmapProps = { rows: string[]; cols: string[]; /** values[row][col]. */ values: number[][]; width?: number; height?: number; className?: string; }; const M = { top: 24, right: 12, bottom: 12, left: 88 }; /** Heatmap — cells fade in along a diagonal cascade; color from the sequential ramp. */ export function Heatmap({ rows, cols, values, width = 600, height, className }: HeatmapProps) { const all = values.flat(); const min = Math.min(...all); const max = Math.max(...all); const norm = (v: number) => (max === min ? 0.5 : (v - min) / (max - min)); const cellW = (width - M.left - M.right) / cols.length; const cellH = 38; const h = height ?? M.top + M.bottom + rows.length * cellH; return ( {({ inView, reduce }) => ( <> {cols.map((c, ci) => ( {c} ))} {rows.map((r, ri) => ( {r} {cols.map((_, ci) => { const v = values[ri]?.[ci] ?? 0; const t = norm(v); return ( ); })} ))} )} ); }