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.
| Category | Value |
|---|---|
| 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.
| Category | Value |
|---|---|
| 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
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly TreemapDatum[] | — | Cells; non-positive primary values are skipped |
fill | ChartFill | light | Cell treatment: solid, light, or gradient |
colorBy | 'single' | 'id' | 'secondaryValue' | single | Shared color, stable categorical identity, or a diverging quantitative scale |
secondaryValueLabel | string | Secondary value | Label used by the tooltip and accessible data table |
width | number | — | Controlled layout width; enables deterministic SSR |
initialWidth | number | — | SSR width hint replaced by client measurement |
height | number | 280 | SVG height in px — width is measured from the container |
showLabels | boolean | true | Label, value, and optional secondary value inside cells that have enough room |
showTooltip | boolean | true | Show value, share, and optional secondary value on hover |
showLegend | boolean | false | Categorical legend or negative/zero/positive scale key |
animate | boolean | true | Cells fade in, staggered biggest-first |
formatters | ChartFormatters | — | Format labels, values, and secondary values across every surface |
label | string | — | Accessible name; defaults to the joined cell labels |
labels | ChartLabels | — | Screen-reader text of the data table and the legend, for translation |
showLabel | boolean | false | Render label as a visible title above the plot |
sx | StyleXStyles | — | StyleX style override |
TreemapDatum
| Field | Type | Description |
|---|---|---|
id | string | Stable data identity |
label | string | Cell / tooltip label, falls back to id |
colorIndex | number | Palette slot 0–7; overrides the hash in colorBy="id" mode |
value | number | Cell area weight; must be finite and positive to render |
secondaryValue | number | Optional 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
labelprovides the concise image name.descriptionadds a richer summary througharia-describedby; consumer-owned text or a visible table can be linked with thearia-describedbyprop.- Up to 20 rendered cells receive a visually hidden native data table, including the secondary-value column when present.
accessibleDatareplaces that table with custom React content; passnullto suppress it.labelstranslates 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
lighttreatment 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.