Waffle chart
A grid where each cell is a share of a whole: 10 × 10 by default, so a cell is 1%. One number ("37% answered") or up to eight parts. A CSS grid of plain elements; the whole grid is one image with a text summary, not a hundred announced cells.
Anatomy
← x-ds-chart only when `interactive`
← the rest of the part's cells
…
← empty cells
legend: swatch, name, "62 · 62%"
Part, Value, Share, and the total
| Part | Token | Why |
|---|---|---|
| Cells | series-1 … series-8 by position; a row's tone or series; tone for one number | specs/chart-series.md |
| Empty cells | the progress track, fg/10 | |
| Cell | sm 10, md 14, lg 18px; square (2px corners) or circle | |
| Gap | 2px |
Cells
Chart::cells() shares rows × columns out by largest remainder, the empty
remainder taking part, so the counts always total the grid. A part above zero
that would round to no cell gets one, taken from the part with the most: a
part the legend lists and the grid does not show reads as a mistake, and the
cost is at most a cell. The printed percentages come from
Chart::percentages() against the whole, <1% for a part too small to round
to one, and on a 10 × 10 grid they equal the cell counts.
Cells are emitted in reading order, each part's run and then the empty ones, and the grid places them: in a right-to-left page it fills from the right with nothing in the view knowing. The view does not force a direction.
Data
| Case | Result |
|---|---|
| a number | one part, named by label, against total (default 100) |
parts (['Free' => 62, …] or rows with label, value, tone / series) | against total, default their sum |
total smaller than the sum | ignored: the whole is the sum |
rows / columns | 1 to 20 each, clamped |
| a negative or a non-number | throws, naming the part |
| more than eight parts | throws |
| no parts, or a whole of zero | ds::empty-state, bare |
The summary
One number: "Answered: 37 of 100 (37%)." Parts, generated by
Chart::whole() as the split bar's: the gist with a legend, every part
without one. summary replaces it; table adds part, value and share, and
the total.
Accessibility
| Without the script | With it | |
|---|---|---|
| Role | img on the grid | group, keeping the name; each part's first cell img, "Pro: 30 (30%)" |
| Keyboard | none | one Tab stop; any arrow moves part to part (never cell to cell), Home / End, Escape |
| Pointer | — | over any cell of a part: its readout, beside that cell (data-ds-chart-piece names the part) |
| Focus ring | — | on the part's first cell |
The cells carry no names and no roles of their own, so a screen reader meets one image, or one stop per part.
Do not
- Do not use it for precise comparison. Counting cells is slow; it shows a share at a glance. Bars compare.
- Do not use more than a handful of parts, or parts under a cell each.
- Do not change the grid to make a number fit: 10 × 10 is what makes a cell read as 1%. Use another shape only when the whole has a natural count (5 × 20 for 200 invitations, 2 to a cell).
From the package repo: edit this page on GitHub.