Treemap

Proportional area tiles via squarified layout.

Import

import { Treemap } from '@matix/charts/treemap';

Usage

Treemap cells default to light so labels remain dominant. solid and gradient are available for denser visual emphasis, and every treatment has a subtle CSS-only hover response.

Data for Video, Photos, Other, Documents
CategoryValue
Video:260.
Photos:120.
Other:80.
Documents:40.

Without cell labels

Turn showLabels off and let the tooltip (or an opt-in legend) carry identity — useful when cells are numerous and small.

Data for Chrome, Safari, Edge, Firefox, Other
CategoryValue
Chrome:64.
Safari:19.
Edge:5.
Firefox:3.
Other:9.

Secondary values

Keep area and color as separate quantitative channels: value always controls cell area, while secondaryValue can drive a diverging negative-to-positive scale. This is the conventional model for market maps, portfolio changes, and variance views because a negative change never creates a negative area.

<Treemap
  colorBy="secondaryValue"
  secondaryValueLabel="Change"
  formatters={{
    secondaryValue: (value) => `${value > 0 ? '+' : ''}${value}%`,
  }}
  data={[
    { id: 'alpha', label: 'Alpha', value: 55, secondaryValue: 6.2 },
    { id: 'beta', label: 'Beta', value: 45, secondaryValue: -4 },
  ]}
/>

colorBy="single" is the quiet default. id hashes stable IDs into the categorical palette and still honors an explicit colorIndex.

API Reference

PropTypeDefaultDescription
datareadonly TreemapDatum[]—Cells; non-positive primary values are skipped
fillChartFilllightCell treatment: solid, light, or gradient
colorBy'single' | 'id' | 'secondaryValue'singleShared color, stable categorical identity, or a diverging quantitative scale
secondaryValueLabelstringSecondary valueLabel used by the tooltip and accessible data table
widthnumber—Controlled layout width; enables deterministic SSR
initialWidthnumber—SSR width hint replaced by client measurement
heightnumber280SVG height in px — width is measured from the container
showLabelsbooleantrueLabel, value, and optional secondary value inside cells that have enough room
showTooltipbooleantrueShow value, share, and optional secondary value on hover
showLegendbooleanfalseCategorical legend or negative/zero/positive scale key
animatebooleantrueCells fade in, staggered biggest-first
formattersChartFormatters—Format labels, values, and secondary values across every surface
labelstring—Accessible name; defaults to the joined cell labels
labelsChartLabels—Screen-reader text of the data table and the legend, for translation
showLabelbooleanfalseRender label as a visible title above the plot
sxStyleXStyles—StyleX style override

TreemapDatum

FieldTypeDescription
idstringStable data identity
labelstringCell / tooltip label, falls back to id
colorIndexnumberPalette slot 0–7; overrides the hash in colorBy="id" mode
valuenumberCell area weight; must be finite and positive to render
secondaryValuenumberOptional second measure for labels, tooltips, tables, and coloring

Layout

Cells are placed with the squarified algorithm (Bruls, Huizing & van Wijk), which keeps aspect ratios close to 1 so areas stay comparable by eye. Input order doesn't affect placement — bigger values always claim the better positions. Color allocation is explicit through colorBy; the secondary scale normalizes magnitude against the largest absolute secondary value in the data. Solid and light fills remain continuous. Gradient fills reuse eleven perceptual steps (five per direction plus neutral), bounding SVG definition count even for large datasets.

Accessibility

  • label provides the concise image name. description adds a richer summary through aria-describedby; consumer-owned text or a visible table can be linked with the aria-describedby prop.
  • Up to 20 rendered cells receive a visually hidden native data table, including the secondary-value column when present. accessibleData replaces that table with custom React content; pass null to suppress it. labels translates the table text and the legend name.
  • Cell marks and inline labels remain aria-hidden; the chart is one image target and the table carries cell values.
  • The pointer tooltip is supplemental; the table carries values for assistive technology.
  • The light treatment uses a lower tint than bar marks because treemap cells carry text. A series-colored border keeps identity, and all fill modes retain the hover cue.
  • Solid and gradient cells use white in-cell text with a soft dark shadow; the default light treatment keeps semantic red/green secondary text.

Server rendering

Pass width for deterministic server-rendered SVG. Use initialWidth for responsive hydration from a server estimate. Without either prop, the wrapper reserves height before client measurement.