All components (283)
Waffle chart
Data · WaffleChart · .amset-waffle
What it is and when to use it
A grid of squares in which each one is worth the same: a hundred squares, and 46 % are of this tone. It reads better than a ring when what matters is "how many out of a hundred", because there are no angles to compare by eye.
When to use it
- A few parts of a total, said as a percentage ("out of every hundred orders, 46 come through the web").
itemsare the parts:{ key, label, value, tone? }.rowsandcolumnschange the grid (10 × 10 by default) andtotalsays what it is worth when full: if it is larger than the sum, what is missing stays empty.- The cells are split by the largest-remainder method: they add up to exactly the ones there are.
- Pointing at a row of the legend highlights its cells and dims the rest.
When not to
- Many parts:
TreemapChart. - Evolution over time:
LineChart. - A single measure against a ceiling:
RingProgressorGauge.
Keyboard: Tab goes to the drawing and the arrows move from part to part; the marked part dims the rest, with a spoken notice.
Accessibility: it is an image (role="img") with a written summary ("4 parts out of 100. The largest, Web: 46, 46 %") and underneath goes a real table. The numbers are written in the legend: colour is not the only thing that informs.
Fine-tuning: --amset-waffle-cell is the side of each square, --amset-waffle-gap the gap and --amset-waffle-empty the colour of the empty ones.
What it looks like
| Part | Value | Share of total |
|---|---|---|
| Web | 46 | 46% |
| Store | 31 | 31% |
| Phone | 15 | 15% |
| Others | 8 | 8% |
<WaffleChart
label="Orders by channel"
items={[
{ key: "web", label: "Web", value: 46 },
{ key: "store", label: "Store", value: 31 },
{ key: "phone", label: "Phone", value: 15 },
]}
/>Props
Import it with import { WaffleChart } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
itemsrequired | readonly WaffleItem[] | The parts: `{ key, label, value, tone? }`. |
labelrequired | string | What is being measured. Required: a chart without a title tells nothing. |
className | string | Merged with the library classes; it does not replace them. |
columns | number | — |
error | ReactNode | The data has not arrived: it says so where the drawing goes, with what is passed here. |
format | (value: number) => string | — |
loading | boolean | The data is on its way. |
rows | number | — |
tableVisible | boolean | Also shows the table. For the screen reader it is always there. |
total | number | What the full grid is worth. Without it, the sum of the parts; if it is larger, what is missing stays empty. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
CSS variables
These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.
| Variable | Default |
|---|---|
--amset-waffle-cell | 1.5rem |
--amset-waffle-gap | 3px |
--amset-waffle-empty | var(--amset-border) |
How to change it
.amset-waffle {
--amset-waffle-cell: ...;
--amset-waffle-gap: ...;
}In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
