Xzero UI
Pro library

Treemap

A squarified treemap: click to drill and the tiles grow to fill the view, with a breadcrumb back and metrics that morph every tile.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/treemap
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/treemap

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { Treemap } from "@/components/xzero/treemap/treemap";

const data = {
  id: "all", label: "All regions",
  children: [
    { id: "na", label: "North America", children: [{ id: "us", label: "United States", value: 18400, color: 24 }, { id: "ca", label: "Canada", value: 2350, color: 19 }] },
    { id: "eu", label: "Europe", children: [{ id: "de", label: "Germany", value: 4120, color: 28 }] },
  ],
};

export function Revenue() {
  return <Treemap data={data} label="ARR" colorLabel="Growth" formatColor={value => `+${value}%`} />;
}

API reference

Treemap

A squarified treemap of a hierarchy. Click a branch and its tile grows to fill the view while its children open inside; the breadcrumb zooms back out. Switching the size or shading measure morphs every tile.

PropTypeDefaultDescription
data (required)TreemapNode–The root: { id, label, value?, color?, children? }. A branch's value is the sum of its children.
label (required)string–What the whole is. Names the chart for assistive technology.
formatValue(value: number) => string–Formats sizes on tiles, the total, and the tooltip.
colorLabelstring–Names the shading measure, such as "Growth". Tiles take the hue of their top level branch and deepen with the measure. Leave it out for one depth.
formatColor(value: number) => string–Formats the shading measure.
colorDomain[number, number]–Range of the shading measure. Defaults to the range of the leaves.
focusstring–Controlled id of the node that fills the view.
defaultFocusstring–Initial focus when uncontrolled. Defaults to the root.
onFocusChange(id: string) => void–Called when people drill in or out.
heightnumber420Height of the tiles in pixels.
emptyLabelstring"No data yet"Shown when every value is zero.
classNamestring–Extra class on the root figure.

Keyboard interactions

KeysAction
Arrow keysMove to the nearest top level tile in that direction.
Home / EndMove to the first or last tile.
Enter / SpaceZooms into the tile in focus.
Escape / BackspaceZooms out one level.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in charts

Guidance for AI tools

Treemap: A squarified treemap: click to drill and the tiles grow to fill the view, with a breadcrumb back and metrics that morph every tile. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components