Components / data

Heatmap

How an amount varies across a grid, shown as depth of one color.

Rendered from the package · open on its own

Summary

How an amount varies across a grid, shown as depth of one color.

APG patternnone
Built onnative elements
Statusself-tested
Since0.16.0
<Heatmap
  label="Daily spending, August to October; weekends run highest"
  columnLabels={['Aug', '', '', '', 'Sep', '', '', '', '', 'Oct']}
  cells={days.map((day) => (day ? { level: day.level, text: `${day.date}, ${day.amount}` } : null))}
/>

Anatomy

A <div data-se="heatmap"> carrying the image role and its name. Inside it, one cell for each square, written down the first column and then down the next, with a columnheader before each column when the columns are labelled. A cell's level is data-level, 0 to 4; a cell with no value is data-absent.

PartElementRequired
cell<span>yes
columnheader<span>no

Properties

PropertyValuesDefaultWhat it does
cells(HeatmapCell | null)[]requiredOne entry for each square, in order: down the first column, then down the next. null is a cell with no value; it keeps its square and draws nothing, so every column lines up.
rowsnumber7How many cells make a column. Seven puts one week in each.
columnLabelsstring[]noneThe label above each column, by position. Give one only where a new group begins — a month — and an empty string everywhere else.
labelstringrequiredIts name, and the pattern in a sentence — Daily spending; weekends run highest. Not drawn. A reader who cannot see the grid gets the finding.

States

_None. Rest is the only condition it has._

Behavior

There are five levels, 0 to 4. More cannot be told apart at this size, and fewer hides the pattern. A level outside the range is brought to the nearest end.

The caller sets the level. What counts as a lot depends on what is measured, and only the caller knows. Quartiles suit one set of values and mislead for another.

The levels are evenly spaced. Each carries one quarter more of the color than the one below, so the step between any two neighbors looks the same.

A cell with no value keeps its place. It draws nothing and still takes its square, so every column lines up. A short last column is filled out the same way.

Accessibility

The pattern is said in words. label is the accessible name, and it states what the grid shows. The squares alone cannot be read by a screen reader.

One color, by depth. The levels differ in how much of one color they carry, never in which color, so the pattern survives for a reader who cannot tell two colors apart.

Keyboard

None of its own. It is not focusable and takes no keys.

Roles, states and properties

AttributeSet by
aria-labelset at render
rolealways img

Focus

Never takes focus. It reports a pattern and offers no action.

Screen reader

Not recorded as verified. Stage 4 of the readiness ladder — driving each component with VoiceOver and NVDA — is unstarted across the package, and no component should claim otherwise until docs/journal/ records the session that did it.

Contrast and target size

npm run check:contrast audits every color pair this component uses across all four skins, light and dark, and fails the build on a shortfall. Two waivers are on the record in docs/audit/DEFERRED.md.

It sets no target size of its own; anything interactive inside it brings its own.

Level 1 is faint against a card: its contrast on --se-surface runs from 1.2 to 1.8 across the skins. It is one full step from level 0 and little more than that from the card. The pattern is carried by the label, not by any one square.

Tested

  • test/apg/heatmap.test.jsx
  • test/browser/heatmap.spec.mjs

Known gaps

_No upstream requirement is recorded as not applicable._

A cell's words reach a pointer only. They are the square's title, shown when a pointer rests on it. A keyboard and a screen reader get the label and nothing finer. Making each cell reachable would make this a grid with a key table; the other way is a DataTable of the same values beside it. The parent spec holds the question open.

Appearance

A grid that flows by column. Each cell is --se-space-3 square with --se-space-1 between cells. A cell's corner is half of --se-radius-sm: the step itself is larger than a square this size can take. Level 0 is --se-surface-sunk, level 4 is --se-accent, and the three between are the accent mixed into the sunk surface by a quarter, a half and three quarters, in oklch. An empty cell takes --se-border-sunk as its edge.

TokenUsed for
--se-accentbackground
--se-border-sunkbox-shadow
--se-border-widthbox-shadow
--se-radius-smborder-radius
--se-space-1gap
--se-space-3grid-auto-columns, grid-template-rows
--se-surface-sunkbackground
--se-text-2xsfont-size
--se-text-mutedcolor

Motion

Nothing moves. Cells never fade or fill in.

Content

The label names what is measured and states the pattern. Daily spending, August to October; weekends run highest. A reader who cannot see the grid gets the finding.

A cell's words give the place and the value. Oct 4, $143.

Label a column only where a group begins. A month name over its first week, and nothing over the rest.

Usage

For a pattern, not a value. Use a DataTable where the reader needs to look a number up.

Not for a handful of values. A bar chart compares them better.

It is as wide as its columns. Where the grid outgrows its place, put it in a region that scrolls; the cells never shrink.

Notes

No ramp token. Stage 2 of the plan measured the ramp and found quarters even in every skin, to within 0.004 of lightness, where the prototype's 22, 45 and 70 percent made the top step a third larger than the bottom (docs/proposals/2026-11-14-sequential-ramp.md). The level is a local on the cell, as a tree node's depth is.

Level 0 is not mixed. It is --se-surface-sunk as the skin gives it. A mix at nothing is not nothing: a surface with almost no color of its own has no hue to keep, so mixing gives it the accent's, and a warm sunk surface came out faintly blue. The browser test caught it.

The corner is derived, not a new step. The prototype it was built for drew 3px, and the smallest radius step is 5 to 7px depending on the skin. Half the step is 2.5 to 3.5px. A new lowest step of the radius scale for one component would be a scale growing on demand.

An empty cell has an edge, from --se-border-sunk. In high-contrast the sunk surface is the card's own white, and without an edge an empty square is white on white and the grid loses its shape. --se-border-sunk is the role for exactly this: the hairline around something that sits on a sunk fill. A skin whose sunk fill already stands apart points it at the fill and the edge disappears, which davor-anic does.

The component does not work out the levels. It would have to choose between quartiles, equal bands and a fixed scale, and each is wrong for some data.

No second color for the high end. The values run one way from nothing. A second color states a midpoint the data does not have.