Treemap

Compares parts of a total as sized tiles.

Cloud spend · September
Hover a tile for its value and share
Cloud spend by service data
ItemValueShare of total

Installation

pnpm dlx shadcn@latest add @paneui/treemap

Usage

Examples

Flat

Use when the data has no natural groups.

Custom Colors

Gap, Padding and Radius

Controlled Active Tile

Use when a list outside the chart should highlight the same tile.

Compact

Keyboard

Each tile is focusable. Tab in, then ArrowRight / ArrowDown and ArrowLeft / ArrowUp move between tiles and Home / End jump to the ends. Focus shows the tooltip.

Accessibility

Every tile has an aria-label with its group, value and share, and a visually hidden data table lists all tiles for screen readers. Labels hide on tiles too small to hold them.

API Reference

Treemap

Squarified treemap with one level of grouping, tooltip and legend. Also accepts every prop of section.

data*
readonly TreemapNode[]
Top-level nodes; nodes with children become groups.
label= "Treemap"
string
Accessible name for the chart, legend and data table.
height= 320
number
Chart height in px; width fills the container.
formatValue= formatNumber
(value: number) => string
Formats values in the tooltip, labels and table.
gap= 3
number
Space between tiles in px.
groupPadding= 3
number
Inset of child tiles inside a group, in px.
radius= 10
number
Tile corner radius in px.
showLegend= true
boolean
Show the legend of top-level nodes.
activeId
string | null
Controlled highlighted tile.
defaultActiveId
string | null
Initially highlighted tile.
onActiveChange
(id: string | null) => void
Called on hover, focus and leave.
PropTypeDefaultDescription
data*readonly TreemapNode[]—Top-level nodes; nodes with children become groups.
labelstring"Treemap"Accessible name for the chart, legend and data table.
heightnumber320Chart height in px; width fills the container.
formatValue(value: number) => stringformatNumberFormats values in the tooltip, labels and table.
gapnumber3Space between tiles in px.
groupPaddingnumber3Inset of child tiles inside a group, in px.
radiusnumber10Tile corner radius in px.
showLegendbooleantrueShow the legend of top-level nodes.
activeIdstring | null—Controlled highlighted tile.
defaultActiveIdstring | null—Initially highlighted tile.
onActiveChange(id: string | null) => void—Called on hover, focus and leave.

TreemapNode

One node of data.

id*
string
Stable id.
label*
string
Tile and legend label.
value
number
Leaf value. Ignored when children is given (the group sums them).
children
TreemapNode[]
Child leaves (one level is drawn).
color
string
Overrides the palette colour; groups pass theirs down and shade each child a step darker.
description
string
Extra line in the tooltip.
PropTypeDefaultDescription
id*string—Stable id.
label*string—Tile and legend label.
valuenumber—Leaf value. Ignored when children is given (the group sums them).
childrenTreemapNode[]—Child leaves (one level is drawn).
colorstring—Overrides the palette colour; groups pass theirs down and shade each child a step darker.
descriptionstring—Extra line in the tooltip.

squarify

(values: readonly number[], rect: { x, y, w, h }) => Rect[]. The squarified layout algorithm, exported for custom treemaps.