import { useMemo } from 'react' import { allocateBoxes, type BoxesSpec } from '../../utils/screenBoxes' import './storyCharts.css' const fmt = (n: number) => n.toLocaleString('en-US') interface Props { spec: BoxesSpec | null | undefined } /** * A compact strip of boxes on a story screen (#1415): a takeaway title, one `[data-box]` mark per record (or per stated number * of records), and a colour legend with the counts. It is the landing place of the particle flights between screens (#1404), * so every screen has one. A screen with nothing on record shows one hollow box and says so; nothing is invented. */ export default function ScreenBoxes({ spec }: Props) { const alloc = useMemo(() => (spec ? allocateBoxes(spec.groups) : null), [spec]) if (!spec || !alloc) return null const { cells, per, total } = alloc const legend = spec.groups.filter((g) => g.count > 0) return (
{spec.title}
1 ? `, one box for ${fmt(per)}` : ''}`}> {cells.length === 0 ? ( ) : ( cells.map((c, i) => ) )}
{spec.note &&

{spec.note}

}
) }