仕組み
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.
向いている場面
- Where the money, space or time goes in a hierarchy: spend by service, disk use by folder, hours by project and task.
向かない場面
- Exact comparison between similar values: use a bar list.
- Negative values or values over time.
使い方
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')}`}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
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. |
アクセシビリティ
- 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.
モーション
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.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
Treemap.jsxtreemap.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



