Skip to documentation content

Treemap

A composable treemap for showing how a total divides into categories and their parts.

Basic Treemap

Overview

Use a treemap to show which parts of a large total matter most: spend by service, bundle size by package, or tickets by topic. Each tile's area is proportional to its value, and nested tiles show how a category breaks down. A treemap holds far more items than a pie chart, but area is harder to compare precisely than length, so reach for a bar chart when exact ranking is the question.

Anatomy

Treemap owns the hierarchical data, colors, and loading state. Each top-level node is a category with its own config entry; its children take lighter steps of the same color, ordered by size, so a family of tiles reads as one group. Add Tiles to control radius, gaps, value labels, and drill-down, Legend to name the categories, and Tooltip for each tile's value and its share of its parent.

Accessibility

When ariaLabel is omitted, the generated name gives the total and the largest categories with their values. Labels pick near-black or near-white text from each tile's fill, so they stay readable on light and dark tints. Small tiles hide their labels instead of overflowing; pair the chart with a table when every value must be readable. Drill-down and the tooltip are pointer-operated.

Installation

npm install honestui

Usage

The data is an array of nodes. A leaf carries a value; a parent's value is the sum of its children.

import { Treemap, type ChartConfig, type TreemapNode } from "honestui/charts";
<Treemap data={data} config={chartConfig}>
  <Treemap.Legend />
  <Treemap.Tooltip />
  <Treemap.Tiles />
</Treemap>

Parent tiles get a tinted frame with a header strip naming the group. Turn it off with showParentLabels={false} to draw only the leaves.

Drill Down

isDrillable

With isDrillable, the treemap shows one level at a time. Selecting a tile zooms into it, and a breadcrumb under the chart leads back out. Use it for deep trees, where showing every level at once leaves tiles too small to label.

Flat Data

Flat categories

Nodes without children make a flat treemap: one tile per category. This example uses a single-hue ramp in the config, a larger radius, and wider gaps.

Loading State

isLoading='true'

Pass isLoading to reserve the layout with neutral tiles and the same loading treatment as the other Honest UI charts.

API Reference

Treemap
PropTypeDefaultDescription
data*TreemapNode[]–

Top-level nodes. Each has a name and either a value or children.

config*ChartConfig–

Labels and theme colors keyed by top-level node name.

classNamestring–

Additional CSS classes for the chart container. Give the chart an explicit height.

animationbooleantrue

Enables the intro and zoom animation. Reduced-motion preferences disable it automatically.

isLoadingbooleanfalse

Replaces the data with neutral placeholder tiles and a progress label.

ariaLabelstring–

Accessible name for the canvas chart. A summary of the largest categories is generated when omitted.

onTileClick(tile: TreemapTile) => void–

Fires when a tile is selected and Tiles has isClickable. The tile carries its value, path, and category.

chartOptionsRecord<string, unknown>–

Escape hatch merged over the generated ECharts option object.

Tiles
PropTypeDefaultDescription
radiusnumber2

Tile corner radius in pixels.

gapnumber2

Space between tiles in pixels.

showValuesbooleantrue

Shows each tile's value under its name.

valueFormatter(value: number) => string–

Formats values in tile labels.

isDrillablebooleanfalse

Shows one level at a time and zooms into a tile when it is selected, with a breadcrumb back out.

showParentLabelsbooleantrue

Frames parent tiles with a header strip naming the group.

rootLabelstring"All"

The breadcrumb's first item, which returns to the top level.

isClickablebooleanfalse

Enables the pointer cursor and onTileClick.

Legend
PropTypeDefaultDescription
variantLegendVariant"rounded-square"

Indicator shape, shared with the other Honest UI charts.

alignleft|center|right"center"

Horizontal alignment of the legend.

verticalAligntop|bottom"bottom"

Places the legend above or below the tiles.

Tooltip
PropTypeDefaultDescription
variantdefault|frosted-glass"default"

Tooltip surface treatment.

roundnesssm|md|lg|xl"lg"

Tooltip corner radius.

positionfixed|variable"variable"

Pins the tooltip to the top or lets it follow the pointer.

valueFormatter(value: number) => string–

Formats the value shown in the tooltip.