Cómo funciona
A squarified layout keeps tiles close to square, so labels have room, and it is recomputed at the measured width. Each tile is a light tint of its branch colour with ink text and a hairline in the same hue, and a branch keeps its colour when you zoom into it. Large first-level tiles show faint inner lines of their children, so it is clear which tiles open. Hovering or focusing a tile fades the others, reveals a small zoom badge and shows a dark tip with the value and share. Opening a tile replays the next level growing out of that tile's exact box with Web Animations on transform only; the breadcrumb goes back up with a short settle.
Úsalo para
- Where the money, space or time goes in a hierarchy: spend by service, disk use by folder, hours by project and task.
Busca otra opción cuando
- Exact comparison between similar values: use a bar list.
- Negative values or values over time.
Uso
import { Treemap } from './Treemap.jsx'
export function SpendByService({ services }) {
return (
<Treemap
label="Cloud spend by service"
data={{
name: 'All services',
children: services.map((s, i) => ({
name: s.name,
tone: i + 1,
children: s.lines.map((l) => ({ name: l.name, value: l.cost })),
})),
}}
formatValue={(v) => `$${v.toLocaleString('en-US')}`}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
data | { name: string, value?: number, tone?: 1-8, children?: Node[] } | — | The root and its tree. Leaves carry value; a branch's size is the sum of its leaves. Top-level tone colours the whole branch. |
height / gap | number | 300 / 3 | Plot height and the space between tiles, in px. The width follows the container. |
depth | 1 | 2 | 2 | 2 draws faint lines inside large tiles showing how their children divide them. |
showValues | boolean | true | Value under the name on tiles large enough for two lines. |
formatValue / formatShare | (v) => string / (pct) => string | — | Formats for the value and the share of the current level. |
label / labels | string / { open(name), back } | 'Treemap' | Accessible name of each level and the wording for tiles that open and the breadcrumb. |
Accesibilidad
- Each level is a list with an accessible name; tiles that open are buttons named “Open name, value, share”, and leaf tiles are focusable images with the same information.
- Tab moves through tiles; Enter or Space opens one; the breadcrumb is a navigation landmark whose earlier levels are buttons and whose current level has aria-current.
- The hover tip is decorative; everything it shows is in the accessible names.
- Reduced motion skips the zoom and the tile entrance.
Movimiento
Zoom in: 520ms from the tile's box on the reveal curve. Zoom out: 360ms settle from 106%. Tiles: 420ms entrance with a 35ms stagger. Hover: 200ms.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
Treemap.jsxtreemap.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.



