Treemap
Parts of a whole as rectangles whose areas follow their values, grouped one level deep: spend by team and service, storage by folder and file type. It shows many parts at once where a donut chart can show five. When the exact sizes must be compared, use the bar chart.
Install
npx shadcn@latest add @thrum-pro/treemapThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type TreemapNode = {
name: string;
value?: number | null; // ignored when it has children
children?: TreemapNode[]; // one level deep
};[
{ name: "Platform", children: [{ name: "Compute", value: 48200 }, { name: "Storage", value: 21900 }] },
{ name: "Support", value: 12800 },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly TreemapNode[] | Required | The top-level items. An item with children is a group whose size is the sum of its children; an item without children is a group of one. Zero, negative and missing values are left out. Past five groups, the smaller ones are folded into one neutral group named Other, with one tile each. |
label | string | Required | What the sizes measure. Read by screen readers and used as the table caption. |
format | Intl.NumberFormatOptions | Default compact | How values are written in the tiles, the readout and the data table. Shares of the whole have one decimal. |
locale | string | Default "en-US" | Locale for numbers. Fixed by default so the server and the browser print the same text. |
legend | boolean | Default true | Show each group's colour and name above the tiles, largest first. It appears when there are two or more groups. |
onActiveChange | (index: number | null) => void | – | Called with the index of the tile under the cursor, counted in reading order (top to bottom, then left to right), or null when the cursor leaves. |
sound | boolean | Default true | Play a tick as the cursor moves between tiles, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when nothing has a size above zero. |
className | string | – | Sets the size. The default is full width and 288 pixels tall, legend included. |
Motion and sound
Motion
- First draw: tiles fade in in reading order in 250 ms each, the last starting within 300 ms of the first.
- New data with the same tiles: every tile moves and resizes to its new place in 400 ms with no overshoot. A different number of tiles is drawn again at once.
- The ring around the active tile follows the pointer on a stiff spring.
- Reduced motion: the tiles appear complete, and changes and the cursor move instantly.
Sound
- A soft tick each time the cursor lands on a different tile, at most one every 40 ms.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The chart is one tab stop. It is exposed as a slider whose value text is the tile under the cursor, with its group, for example “Platform › Compute: $48.2K, 31.4%”.
- A visually hidden table lists every tile with its group, value and share of the whole, group by group.
- Tiles are a light tint of their group's colour with a full-strength outline, so names and values in the text colour keep 4.5:1 on every tile in both themes. Groups are also named in the legend and the readout, never by colour alone.
- A tile too small for its name is still drawn and still reached by the cursor; the readout names it.
- Every tile is a pointer target over its whole area.
| Keys | Action |
|---|---|
| Tab | Focus the chart. The cursor goes to the last tile in reading order. |
| → ↑ | Move to the next tile in reading order. |
| ← ↓ | Move to the tile before. |
| Home / End | Jump to the first or last tile. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/treemap.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.0 · 2026-12-03First release.