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`
    legend: swatch, name, "62 · 62%"
Part, Value, Share, and the total
PartTokenWhy
Cellsseries-1 … series-8 by position; a row's tone or series; tone for one numberspecs/chart-series.md
Empty cellsthe progress track, fg/10
Cellsm 10, md 14, lg 18px; square (2px corners) or circle
Gap2px

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

CaseResult
a numberone 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 sumignored: the whole is the sum
rows / columns1 to 20 each, clamped
a negative or a non-numberthrows, naming the part
more than eight partsthrows
no parts, or a whole of zerods::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 scriptWith it
Roleimg on the gridgroup, keeping the name; each part's first cell img, "Pro: 30 (30%)"
Keyboardnoneone 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.

Was this page helpful?