Treemap Chart
A series as boxes, each as large as its value, squarified — gathered in groups if you like. Names and colors come from the chart's config; the keyboard moves through the boxes, and the tooltip says their values.
Installation
It has its own entry point, @semantic-components/ui/charts/treemap, built on d3-scale d3-shape d3-hierarchy — an optional peer of ui: install it where you use the component.
ts
import { ScChartTreemap } from '@semantic-components/ui/charts/treemap';Usage
import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScChart, type ScChartConfig, ScChartLabels, ScChartPlot, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue,} from '@semantic-components/ui/charts';import { ScChartTreemap } from '@semantic-components/ui/charts/treemap';
@Component({ selector: 'app-treemap-chart-usage-demo', imports: [ ScChart, ScChartPlot, ScChartTreemap, ScChartLabels, ScChartTooltip, ScChartTooltipPortal, ScChartTooltipProvider, DecimalPipe, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipValue, ], template: ` <div scChart class="aspect-video max-h-72" [config]="config" [data]="data"> <svg scChartPlot categoryKey="browser" aria-label="Visitors by browser"> <g scChartTreemap key="visitors"> <g scChartLabels position="start" class="fill-background" [formatter]="name" /> </g> </svg> <div scChartTooltipProvider> <ng-template scChartTooltipPortal> <div scChartTooltip #tooltip="scChartTooltip"> @for (item of tooltip.payload(); track item.dataKey) { <div scChartTooltipItem [item]="item"> <span scChartTooltipIndicator></span> <span scChartTooltipName>{{ item.name }}</span> <span scChartTooltipValue>{{ item.value | number }}</span> </div> } </div> </ng-template> </div> </div> `, host: { class: 'block w-full max-w-xl' }, encapsulation: ViewEncapsulation.None,})export class TreemapChartUsageDemo { private readonly data = [ { browser: 'chrome', visitors: 275 }, { browser: 'safari', visitors: 200 }, { browser: 'firefox', visitors: 187 }, { browser: 'edge', visitors: 173 }, ]; private readonly config: ScChartConfig = { visitors: { label: 'Visitors' }, chrome: { label: 'Chrome', color: 'var(--chart-2)' }, safari: { label: 'Safari', color: 'var(--chart-3)' }, firefox: { label: 'Firefox', color: 'var(--chart-4)' }, edge: { label: 'Edge', color: 'var(--chart-5)' }, }; private readonly name = (_: number, browser: string) => this.config[browser]?.label ?? browser;}Anatomy
A chart (its rows and config), its plot with the series, and the tooltip and legend you write from their state.
import { ScChart, ScChartPlot, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue } from '@semantic-components/ui/charts';import { ScChartTreemap } from '@semantic-components/ui/charts/treemap';<div scChart [config]="…" [data]="…"> <svg scChartPlot categoryKey="…" aria-label="…"> <g scChartTreemap key="…" /> </svg> <div scChartTooltipProvider> <ng-template scChartTooltipPortal> <div scChartTooltip #tooltip="scChartTooltip"> <div scChartTooltipItem [item]="…"> <span scChartTooltipIndicator></span> <span scChartTooltipName>…</span> <span scChartTooltipValue>…</span> </div> </div> </ng-template> </div></div>Accessibility
- The plot is one tab stop, a group named by its aria-label: the arrow keys, Home and End move through its boxes; Escape closes the tooltip.
- As the keyboard moves, screen readers hear what the tooltip says, through the CDK's LiveAnnouncer (politely).
- Right to left, with the app following the direction (charts.followDirection), it is mirrored — laid out from the right — and ← goes to the next.
- With reduced motion (prefers-reduced-motion), it appears and changes at once.
Examples
Groups
import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScChart, type ScChartConfig, ScChartLabels, ScChartLegend, ScChartLegendIndicator, ScChartLegendItem, ScChartPlot,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScChart, type ScChartConfig, ScChartLabels, ScChartPlot, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem,API reference
The series' inputs. The chart, its plot, axes, tooltip and legend are on the Chart page.
| Input | Type | Default | Description |
|---|---|---|---|
key | string (required) | — | each box's value |
groupKey | string | '' | each row's group |
gap | number | 2 | the space between boxes, in px |
isAnimationActive | boolean | true | its boxes slide in from the left when it appears (Recharts' entrance) |
animationBegin | number | 0 | the wait before it starts, in ms |
animationDuration | number | 1500 | how long it lasts, in ms |
animationEasing | ease, ease-in, ease-out, ease-in-out, linear | linear | |
class | string | '' | Merged over its own classes. |