Ballmac UI home

Treemap

New

A dependency-free treemap: each item is a rectangle sized by its share of the whole in a squarified layout, with real text on the cells, group colours and a legend with totals, and arrow keys that move to the nearest cell.

v1.0.0Updated Oct 24, 2026Ships with a test
What changed

Model inference · $3,150 USD · 20% of the totalUp 18% on last month with the new assistant.

  • Production$8,050 · 51%
  • AI$4,320 · 27%
  • Developer$1,200 · 8%
  • Observability$2,190 · 14%

Installation

$ pnpm dlx shadcn@latest add @ballmac/treemap

Usage

import { Treemap, squarify } from "@/components/ballmac/treemap"

The full example is in the Code tab above.

Examples

What fills a context window

Select a block to see its share.

  • Instructions8,800 · 7%
  • History64,100 · 50%
  • Files41,500 · 33%
  • Retrieved13,000 · 10%

API reference

PropTypeDefault
items*TreemapItem[]—
format

Turns a value into text.

(value: number) => string(v) => v.toLocaleString("en-US")
aspect

Width divided by height of the chart.

number16 / 9
selected

The selected item id. Controlled.

string | null—
defaultSelected

The selected item id for uncontrolled use.

string | nullnull
onSelectedChange

Called when an item is chosen, or null when it is cleared.

(id: string | null) => void—
unit

What the sizes mean, for assistive technology, for example "tokens".

string—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
TabEnters the chart once, on the largest cell (or the selected one)
Arrow keysMove to the nearest cell in that direction (left and right swap in right-to-left); Home and End go to the largest and smallest
Enter / SpaceSelects the cell; again to clear it
Screen readersEach cell reads 'Compute: 4,210 USD, 38.2% of the total, Production'; the selected item is a polite live region

Use with AI

items is [{ id, label, value, group?, detail? }]; zero or negative values are dropped. format(value), unit, aspect (width over height, default 16/9), selected / defaultSelected / onSelectedChange. Exports squarify(items, w, h) for your own layouts. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Treemap (@ballmac/treemap) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Showing how a whole divides into many parts of very different size
  • Disk, cost, token or traffic breakdowns

Not for

  • A handful of parts; use chart-pie or a bar list
  • A change over time; use chart-area
  • Flows between steps; use flow-sankey

Registry JSON: https://ui.ballmac.com/r/treemap.json

Credits

Free to use in personal and commercial projects.

npm
None

Ballmac UI Pro

Need the whole screen, not one piece?

150 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.

Not ready? Try three Pro blocks free

Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.