Treemap

Shares of a total as rectangles sized by value, with names and values inside the tiles that fit and nested groups. Drawn as SVG, rendered on the server and themed by the design tokens.

Part of @tectra-ng/charts (npm install @tectra-ng/charts, also included in tectra-ng).

Features8APIThemingAccessibility

Basic

Pass items with a label and a value. Bigger values get bigger tiles; names and values are drawn inside the tiles that have room. Hover a tile or use the arrow keys for the tooltip with its share.

Arrow keys move between values
Spend by category. Treemap, 1 series, 8 values, total 55,300
CategoryValueShare
Hosting18,40033.3%
Advertising12,60022.8%
Salaries9,80017.7%
Software6,20011.2%
Office3,9007.1%
Travel2,4004.3%
Training1,3002.4%
Other7001.3%

Nested

An item with children becomes a labelled group whose tiles share its colour; its value is the sum of the children. tileClick tells which tile and group were clicked.

Arrow keys move between values
Visitors by region and country. Treemap, 1 series, 9 values, total 22,500
CategoryValueShare
Europe / Germany4,20018.7%
Europe / France3,10013.8%
Europe / Poland1,9008.4%
Europe / Spain1,5006.7%
Americas / United States5,20023.1%
Americas / Canada1,4006.2%
Americas / Brazil1,1004.9%
Asia / Japan2,30010.2%
Asia / India1,8008%
Click a country.

Labels

showDataLabels and showValues switch the text inside the tiles; small tiles never get text that would not fit, the tooltip still names them.

Arrow keys move between values
Disk usage by folder. Treemap, 1 series, 9 values, total 98.2K
CategoryValueShare
videos48.2K49.1%
photos21.5K21.9%
backups15.8K16.1%
documents6.4K6.5%
music3.9K4%
downloads1.8K1.8%
fonts4200.4%
notes1600.2%
keys400%

Tile template

<ng-template txTreemapTile let-tile> draws your own content in every tile: the context has label, value (formatted), share, color, width and height, so you can choose what fits. The content is clipped to the tile.

Arrow keys move between values
Sales by store. Treemap, 1 series, 6 values, total 5,250
CategoryValueShare
Berlin Mitte1,84035%
Munich Central1,32025.1%
Hamburg Port96018.3%
Cologne Old Town61011.6%
Leipzig3807.2%
Bremen1402.7%

Value format

valueFormat formats the values in the tiles and the tooltip; tooltipFormatter changes only the tooltip.

Arrow keys move between values
Revenue by plan. Treemap, 1 series, 4 values, total $1234K
CategoryValueShare
Team$482K39.1%
Pro$370K30%
Enterprise$288K23.3%
Starter$94K7.6%

Loading and empty

loading shows a skeleton of the same size; items with no positive value show "No data".

No data

Design tokens

dt sets the tokens of one treemap — the treemap group of the chart tokens (radius, gap, label type) and the series colours.

Arrow keys move between values
Code by language. Treemap, 1 series, 4 values, total 100
CategoryValueShare
TypeScript6262%
SCSS1818%
HTML1414%
JSON66%

Pass through

pt adds classes and styles to the parts: root, plot, svg, tile, tileContent, tileLabel, tileValue, group, groupLabel, tooltip, empty, skeleton.

Arrow keys move between values
Visits by device. Treemap, 1 series, 3 values, total 10,560
CategoryValueShare
Desktop5,82055.1%
Mobile4,13039.1%
Tablet6105.8%