Treemap

View as Markdown

How a whole splits into many parts, as tiles sized by value, in groups, that you can press to drill in.

  • Compute
  • Data
  • Network
  • Other
11 partsTotal $61,800.00

Press a service to open its costs.

When to use

How a whole splits into many parts, as tiles sized by value, in groups, that you can press to drill in. Use Bar Chart instead when the parts aren't nested and are few.

Usage

import { Treemap } from "./ui/uicontext/components/charts/Treemap.ts"
export const Revenue = <M>(h: Html.H<M>) =>	Treemap(h, { label: "Revenue by product", items: [{ id: "core", label: "Core", value: 820 }, { id: "ai", label: "AI add-on", value: 210 }, { id: "api", label: "API", value: 95 }] })

Examples

Without groups

Each part takes the next chart color. Tiles too small for a name still say it on hover and to a screen reader.

  • Photos: 142 GB, 35.1%
  • Developer: 88 GB, 21.7%
  • Movies: 64 GB, 15.8%
  • Music: 36 GB, 8.9%
  • System: 28 GB, 6.9%
  • Mail: 21 GB, 5.2%
  • Downloads: 17 GB, 4.2%
  • Documents: 9 GB, 2.2%
8 partsTotal 405 GB

API reference

Options

Treemap options
NameTypeDefaultDescription
labelrequiredstring—What the whole is: "Cloud spend, November"
itemsrequiredTreemapItem[]——
groupsTreemapGroup[]—The groups items belong to, in legend order; without them each item takes the next color
formatChartFormat——
heightnumber320Pixels; 320 by default
rationumber1.6How wide the box is for its height, for the layout; 1.6 by default. The tiles stretch to the real box.
onSelect(id: string) => Message—Makes each tile a button
localestring——
styleStyle——

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/treemap

Source