UI

Waffle chart

A grid of discrete cells filled in proportion to each part's share of a whole.

import { WaffleChart } from '@uthereal/ui/waffle-chart'

Waffle chart playground

Electricity generation, 2023
100 cells. Use arrow keys to move between cells, Page Up and Page Down to jump between categories.
Electricity generation, 2023
CategoryValueShareCells
Wind and solar218 TWh43%43
Hydro20 TWh4%4
Gas76 TWh15%15
Coal132 TWh26%26
Other61 TWh12%12
Loading interactive preview…

Overview

A waffle chart represents parts of a whole as a grid of discrete cells (10 × 10 by default, so each cell equals 1%). Cells fill column by column from the bottom-left corner using largest-remainder rounding so cell counts always sum to the full grid. The grid scales with its container up to 300 px (maxWidth), with a legend beside it at 420 px or wider and below it on narrower layouts. Exploring a cell highlights its part, dims remaining parts, and shows a tooltip with the share and value. A native data table lists every part's value, share, and cell count.

Use a waffle chart when shares should read as countable units. For a quick glance at a few shares, use a donut chart. To compare absolute values, use a bar chart.

Usage

import { WaffleChart } from '@uthereal/ui/waffle-chart'

export function PowerMix() {
  return (
    <WaffleChart
      title="Electricity generation, 2023"
      unit="TWh"
      parts={[
        { id: 'wind-solar', label: 'Wind and solar', value: 218 },
        { id: 'coal', label: 'Coal', value: 132 },
      ]}
    />
  )
}

The first part (or accentPart) takes the primary series color; the next three take supporting palette colors, and later parts take neutral steps. After the accent part, cells also cycle through square, round, and framed shapes as a color-free channel. Set color on a part to override its palette slot.

Examples

Folding small parts into Other

Parts below groupBelow (4% by default), plus the smallest parts beyond maxParts, fold into one gray "Other" part whenever two or more parts qualify. The data table continues to list every supplied part individually.

Browsers
100 cells. Use arrow keys to move between cells, Page Up and Page Down to jump between categories.
Browsers
CategoryValueShareCells
Chrome6161%61
Safari2121%21
Edge77%7
Firefox55%–
Samsung Internet33%–
Opera33%–

Custom grid dimensions

Set rows and columns (5–20 each) to build non-square grids such as a 5 × 20 horizontal strip. Cells have a 3 px gap and grow to fill the container up to maxWidth; size sets the initial unmeasured cell size (12, 16, or 20 px) for server rendering.

Traffic by source
100 cells. Use arrow keys to move between cells, Page Up and Page Down to jump between categories.
Traffic by source
CategoryValueShareCells
Direct4242%42
Search3131%31
Social1717%17
Email1010%10

Behavior

Hovering or focusing a legend button previews its part. Clicking it pins the part (aria-pressed) so other parts stay dimmed, and clicking again releases it (legendToggle: false disables pinning and leaves preview only). Control the pinned part with activePart and onActivePartChange, or initialize it with defaultActivePart.

Set decimals (0–3) to control share precision. When data updates, cells preserve identity and reassign from shrinking parts to growing parts without crossing paths. Touch drags scrub across cells. In RTL (dir="rtl"), columns fill from the right.

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
titlestringDefault: "Waffle chart"Figure title. It names the chart for assistive technology and captions the data table.
descriptionstring—One or two sentences on what the chart shows, below the title; omit it when the title says enough.
tableTogglebooleanDefault: falseShow a button that reveals the data table. The table is always available to assistive technology.
tableLabelstringDefault: "Data table"Name of the data table button.
pointLabelstringDefault: "{label}, {share}, {value}"Announced as the cursor reads a cell, from the keyboard or the pointer (Arc): "{label}, {share}, {value}".
valueFormatNumberFormat—How values appear in the tooltip, table and axis: decimal, percent or currency, with fraction digits. Axis ticks are compacted (12.9K).
localestring—BCP 47 locale for numbers and dates. Omit it to inherit the application locale (en-US by default).
partsChartPart[]Default: [{"id":"direct","label":"Direct","value":42},{"id":"search","label":"Search","value":31},{"id":"social","label":"Social","value":17},{"id":"email","label":"Email","value":10}]The parts of the whole in display order, each with an id, a label and a value of zero or more; at least one is greater than zero. Colors follow this order and never move when a part is hidden.
maxPartsintegerDefault: 6Parts shown before the rest fold into one "Other" part in gray (2–8). The data table always lists every part.
groupBelownumberDefault: 0.04Parts below this share of the whole (0–0.5; 0.04 is 4%) fold into "Other", but only when two or more would fold.
otherLabelstringDefault: "Other"Name of the folded part.
categoryLabelstringDefault: "Category"Header of the category column in the data table.
valueLabelstringDefault: "Value"Header of the value column in the data table.
shareLabelstringDefault: "Share"Header of the share column in the data table (each part’s share of the whole).
legendTogglebooleanDefault: trueClicking a legend entry pins its part (aria-pressed) so the others stay dimmed, and clicking it again releases it, as in Arc. Off, entries only preview their part on hover or keyboard focus.
legendLabelstringDefault: "{title} categories"Accessible name of the legend; {title} is the chart title (Arc: "Electricity generation, 2023 categories").
accentPartstring | null—ID of the part painted in the accent (series 1); the next three parts take the supporting series and later ones neutral steps. null keeps every part off the accent; omitted, the first part.
unitstring—Unit after each value in the tooltip, the announcement and the data table, such as "TWh".
decimalsintegerDefault: 0Decimal places of every share (0–3), as in Arc.
cellsLabelstringDefault: "Cells"Header of the cell-count column in the data table.
keysLabelstringDefault: "{count} cells. Use arrow keys to move between cells, Page Up and Page Down to jump between categories."Keyboard hint that describes the grid; {count} is the number of cells.
roleLabelstringDefault: "waffle chart"How assistive technology names the grid ("waffle chart").
rowsintegerDefault: 10Rows of cells (5–20).
columnsintegerDefault: 10Columns of cells (5–20). rows × columns cells make the whole; parts fill whole cells by the largest remainder, so they always add up.
sizesm | md | lgDefault: "md"Cells of 12, 16 or 20 pixels before the grid is measured; then cells grow to fill the width, up to a 300 pixel grid, with a 3 pixel gap.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeWaffleChartTheme—Color mode, accent, and tokens, including cellSize, maxWidth and the chart palette. See Theming.
motionnone | subtle | expressiveDefault: "subtle"Draw-in and data change animation preset. System reduced-motion preferences take precedence.
motionOptionsWaffleChartMotionOptions—draw replaces Arc's snappy spring that pops the cells in from .4 when the chart scrolls into view: a tween with a duration (ms) or a spring. Cells travel to the parts that grew on Arc's morph spring, dipping mid-flight.
dirltr | rtl—Reading direction; rtl fills the columns from the right. Omit it to inherit the page direction.

React integration

PropPurpose
activePartControlled pinned part ID, or null for none
defaultActivePartInitial pinned part ID when uncontrolled
onActivePartChangeFires with the pinned part ID (or null) on pin or release, in both modes
presetApplication defaults, overridden by explicit instance props
tokensCSS variables applied after the typed theme
refRef forwarded to the root <figure>
className, styleApplied to the root <figure>
Native attributesid, data-*, and remaining <figure> attributes forwarded to the root

Keyboard & accessibility

KeyInteraction
TabFocus the waffle grid, then legend pin buttons
Arrow keysMove the active cursor cell by cell across the grid
PageDown, PageUpJump to the next or previous part
Home, EndJump to the first or last filled cell
Enter, SpacePin or release the focused part (on legend buttons)
EscapeClear the active cell cursor and tooltip

The chart renders a <figure> named by title and linked via aria-details to a data table with value, share, and cell count (cellsLabel) columns. Individual cells are hidden from assistive technology; the grid is a single tab stop with role description roleLabel ("waffle chart") and hint keysLabel. Each cursor move rings the cell, shows the tooltip, and announces politely via pointLabel. Under forced-colors, system colors apply.

Motion and theming

When 35% of the chart enters the viewport, cells scale in from 0.4 on a snappy spring along the fill order; server-rendered markup is final. On data updates, reassigned cells travel on the chart morph spring (dipping to 0.62 mid-flight) and transition color and shape over 480 ms across a 320 ms stagger while legend shares count to their new values. The tooltip glides between cells on its own spring. motionOptions.draw and motionOptions.morph accept a tween with duration (ms) or a spring. motion="none" and prefers-reduced-motion: reduce disable motion.

theme accepts a mode, an accent, and semantic tokens including cellSize, maxWidth, and the chart palette. An application-wide UtherealProvider supplies defaults.

Composition

In an agent composition, WaffleChart is a leaf with no actions. The host updates parts through composition updates. See Building with agents.

{
  "type": "WaffleChart",
  "props": {
    "title": "Budget by team",
    "parts": [
      { "id": "engineering", "label": "Engineering", "value": 60 },
      { "id": "sales", "label": "Sales", "value": 40 }
    ]
  },
  "children": []
}

On this page