Examples

Two levels

Preview
Storage by team (GB)Treemap of 7 items, total 1,440. Largest: Design › Assets (29.2%); Engineering › Builds (26.4%); Engineering › Logs (14.6%).
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
import { Treemap } from '@reactloom/charts';

const storage = [
  { label: 'Design', children: [{ label: 'Assets', value: 420 }, { label: 'Prototypes', value: 160 }, { label: 'Archive', value: 90 }] },
  { label: 'Engineering', children: [{ label: 'Builds', value: 380 }, { label: 'Logs', value: 210 }] },
  { label: 'Finance', children: [{ label: 'Reports', value: 120 }, { label: 'Invoices', value: 60 }] },
];

export default function Example() {
  return <Treemap title="Storage by team (GB)" data={storage} />;
}

Download as PNG or SVG

downloadChart and chartToSvg work with every ReactLoom chart.

Preview
Sales by category (k€)Treemap of 5 items, total 1,340. Largest: Laptops (40.3%); Phones (30.6%); Tablets (14.2%).
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
import { chartToSvg, downloadChart, Treemap } from '@reactloom/charts';
import { Button, HStack, Stack } from '@reactloom/ui';
import { useRef } from 'react';

const sales = [
  { label: 'Laptops', value: 540 },
  { label: 'Phones', value: 410 },
  { label: 'Tablets', value: 190 },
  { label: 'Accessories', value: 120 },
  { label: 'Services', value: 80 },
];

// Every chart can be saved as SVG or PNG, with theme colours resolved.
export default function Example() {
  const ref = useRef<HTMLDivElement>(null);
  const figure = () => ref.current?.querySelector('figure');
  return (
    <Stack gap="3" style={{ width: '100%' }}>
      <HStack gap="2">
        <Button size="sm" variant="secondary" onClick={() => figure() && void downloadChart(figure() as Element, { format: 'png', filename: 'sales' })}>
          Download PNG
        </Button>
        <Button size="sm" variant="secondary" onClick={() => figure() && void navigator.clipboard?.writeText(chartToSvg(figure() as Element))}>
          Copy SVG
        </Button>
      </HStack>
      <div ref={ref}>
        <Treemap title="Sales by category (k€)" data={sales} />
      </div>
    </Stack>
  );
}

API reference

Treemap props
PropTypeDefault
datarequired
Parents sum their children.
{ label, value?, children? }[]—
titlerequired
Names the figure.
string—
description
The takeaway; a factual summary is generated when omitted.
ReactNode—
table
The data table alternative.
'toggle' | 'visible' | 'none''toggle'
height · valueFormat · formatValue · messages
As on the other charts.
—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-active]present when on

Theme tokens it reads

--pl-color-bg-surface --pl-color-fg-default --pl-color-fg-muted

Accessibility

  • The chart is a figure named by its title and described by a summary; the drawing is hidden from assistive technology.
  • The plot is one tab stop: arrow keys move between items and each is announced; the data table gives every value.
  • Items are read with their parent, value and share.
Keyboard interactions
KeyAction
TabFocus the plot
← → ↑ ↓Move between items
Home / EndFirst / last item
EscapeClear the highlight

Usage guidelines

Do

  • Label the unit in the title.

Don’t

  • Don't use a treemap to compare similar sizes precisely — use a BarChart.