Skip to content
Thrum

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/treemap

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Data shape

Type
type TreemapNode = {
  name: string;
  value?: number | null;      // ignored when it has children
  children?: TreemapNode[];   // one level deep
};
Sample
[
  { name: "Platform", children: [{ name: "Compute", value: 48200 }, { name: "Storage", value: 21900 }] },
  { name: "Support", value: 12800 },
]

Props

PropTypeDefaultDescription
datareadonly TreemapNode[]RequiredThe 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.
labelstringRequiredWhat the sizes measure. Read by screen readers and used as the table caption.
formatIntl.NumberFormatOptionsDefault compactHow values are written in the tiles, the readout and the data table. Shares of the whole have one decimal.
localestringDefault "en-US"Locale for numbers. Fixed by default so the server and the browser print the same text.
legendbooleanDefault trueShow 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.
soundbooleanDefault truePlay a tick as the cursor moves between tiles, if the visitor has sound on.
emptyLabelstringDefault "No data"Text shown when nothing has a size above zero.
classNamestring–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.
KeysAction
TabFocus 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 / EndJump to the first or last tile.
EscHide the cursor.

Source

SourcePro

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. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor