@nanahoshi/mona-ui 0.26.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chart/README.md +2 -2
- package/docs/chart-bar.md +714 -0
- package/docs/chart-financial.md +567 -0
- package/docs/chart-funnel.md +546 -0
- package/docs/chart-heatmap.md +535 -0
- package/docs/chart-line-area.md +462 -0
- package/docs/chart-pie.md +645 -0
- package/docs/chart-radar.md +518 -0
- package/docs/chart-radial.md +658 -0
- package/docs/chart-scatter.md +479 -0
- package/docs/chart-treemap.md +651 -0
- package/docs/chart.md +263 -1856
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +126 -66
- package/llms.txt +11 -1
- package/package.json +1 -1
- package/types/nanahoshi-mona-ui-chart.d.ts +50 -20
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
# Treemap
|
|
2
|
+
|
|
3
|
+
> A treemap series that tiles hierarchical data by value.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/chart`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-treemap-series`
|
|
8
|
+
|
|
9
|
+
A treemap series tiles hierarchical data into nested rectangles, each sized by its value, so the reader sees at a glance how a total splits into parts and those parts into smaller ones. It goes alone inside a `mona-chart`, without axes, and reads a tree of nodes in which each parent holds its children.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Use a treemap when the data is a tree and the question is how much each part takes of the whole: a budget by department and team, disk usage by folder, revenue by region and country. Every rectangle's area is its value, and a parent's rectangle holds its children's.
|
|
14
|
+
|
|
15
|
+
**Use something else when:**
|
|
16
|
+
|
|
17
|
+
- The data is flat, with a handful of parts. A pie or donut reads more easily, see [Pie & Donut](chart-pie.md).
|
|
18
|
+
- The reader must compare values precisely. Areas are hard to compare, and bars are easier, see [Bar & Waterfall](chart-bar.md).
|
|
19
|
+
- The parts are steps that lose volume in order, such as a sign-up flow. Use a funnel, see [Funnel](chart-funnel.md).
|
|
20
|
+
- Values can be negative. A treemap only draws sizes, so a negative value takes no space.
|
|
21
|
+
|
|
22
|
+
The chart, legend, tooltip and the rest of the shared parts are described on [Chart Overview](chart.md).
|
|
23
|
+
|
|
24
|
+
## Import & Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import {
|
|
28
|
+
ChartComponent,
|
|
29
|
+
ChartLegendComponent,
|
|
30
|
+
ChartTooltipComponent,
|
|
31
|
+
TreemapSeriesComponent
|
|
32
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<mona-chart aria-label="Annual budget" class="h-80 w-full" [data]="budget">
|
|
37
|
+
<mona-treemap-series name="Budget" />
|
|
38
|
+
<mona-chart-legend />
|
|
39
|
+
<mona-chart-tooltip />
|
|
40
|
+
</mona-chart>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
protected readonly budget = [
|
|
45
|
+
{
|
|
46
|
+
name: "Engineering",
|
|
47
|
+
children: [
|
|
48
|
+
{ name: "Platform", value: 1840 },
|
|
49
|
+
{ name: "Mobile", value: 1260 }
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{ name: "Sales", children: [{ name: "Enterprise", value: 1380 }] }
|
|
53
|
+
];
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Give the chart a height. It fills its host, and a host without a height has none.
|
|
57
|
+
|
|
58
|
+
## Anatomy
|
|
59
|
+
|
|
60
|
+
The series reads the chart's `data`, unless it has its own `data`, which wins and can also be a single root object. Each item of the array is a top-level node.
|
|
61
|
+
|
|
62
|
+
| Input | Default | Reads |
|
|
63
|
+
| :--- | :--- | :--- |
|
|
64
|
+
| `labelField` | `"name"` | The node's label. A node without one is named "Node" followed by a number. |
|
|
65
|
+
| `field` | `"value"` | The value of a node without children. |
|
|
66
|
+
| `childrenField` | `"children"` | The array of child nodes. |
|
|
67
|
+
| `keyField` | none | A stable identity, so a node keeps its id, its hidden state and its animation when the data changes. |
|
|
68
|
+
| `colorField` | none | A color for the node and everything below it. |
|
|
69
|
+
|
|
70
|
+
A field is a property name or an accessor, `(node, index) => value`. Only nodes without children read `field`: a parent's size is always the sum of its children, and a value on a parent is ignored.
|
|
71
|
+
|
|
72
|
+
Each parent draws a light background with a header strip across the top, which holds its label. The nodes at the bottom of what's drawn, the leaves and any node `maxDepth` collapses, are filled with the branch's color.
|
|
73
|
+
|
|
74
|
+
### Templates
|
|
75
|
+
|
|
76
|
+
`ng-template[monaChartTreemapLabelTemplate]`, inside the series, replaces the content of every label, parent headers included. The context is a `ChartTreemapLabelTemplateContext`. `let-node` gives the node's `ChartHierarchyNodeContext`; the context also has the label's `bounds`, its `color` and `textColor`, and the same node fields at the top level.
|
|
77
|
+
|
|
78
|
+
| Field | Holds |
|
|
79
|
+
| :--- | :--- |
|
|
80
|
+
| `formattedLabel`, `formattedValue` | The label after `categoryFormatter` and the value after `valueFormatter`. |
|
|
81
|
+
| `formattedPath`, `path` | The labels from the top-level node down to this one. |
|
|
82
|
+
| `depth` | `1` for a top-level node. |
|
|
83
|
+
| `isLeaf`, `isCollapsed` | Whether the node has no children, or has children that `maxDepth` hides. A parent header is neither. |
|
|
84
|
+
| `percentageOfParent`, `percentageOfRoot` | The node's share of its parent and of the visible total, from `0` to `1`. |
|
|
85
|
+
| `childCount`, `descendantCount`, `aggregateValue` | The size of the subtree and its total. |
|
|
86
|
+
|
|
87
|
+
The chart, legend and tooltip templates are described on [Chart Overview](chart.md).
|
|
88
|
+
|
|
89
|
+
## Examples
|
|
90
|
+
|
|
91
|
+
### Budget by department
|
|
92
|
+
|
|
93
|
+
The smallest treemap: an array of departments, each with its teams. `showValues` writes each team's value under its name, and `valueFormatter` formats it there, in the tooltip and in announcements. The legend lists the departments.
|
|
94
|
+
|
|
95
|
+
`budget-example.component.ts`
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { Component } from "@angular/core";
|
|
99
|
+
import {
|
|
100
|
+
ChartComponent,
|
|
101
|
+
ChartLegendComponent,
|
|
102
|
+
ChartTooltipComponent,
|
|
103
|
+
TreemapSeriesComponent
|
|
104
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
105
|
+
import type { ChartValueFormatter } from "@nanahoshi/mona-ui/chart";
|
|
106
|
+
|
|
107
|
+
const dollars = new Intl.NumberFormat("en", {
|
|
108
|
+
currency: "USD",
|
|
109
|
+
maximumFractionDigits: 1,
|
|
110
|
+
notation: "compact",
|
|
111
|
+
style: "currency"
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
@Component({
|
|
115
|
+
selector: "app-chart-treemap-budget-example",
|
|
116
|
+
imports: [ChartComponent, ChartLegendComponent, ChartTooltipComponent, TreemapSeriesComponent],
|
|
117
|
+
templateUrl: "./budget-example.component.html"
|
|
118
|
+
})
|
|
119
|
+
export class ChartTreemapBudgetExampleComponent {
|
|
120
|
+
protected readonly budget = [
|
|
121
|
+
{
|
|
122
|
+
name: "Engineering",
|
|
123
|
+
children: [
|
|
124
|
+
{ name: "Platform", value: 1840000 },
|
|
125
|
+
{ name: "Mobile", value: 1260000 },
|
|
126
|
+
{ name: "Web", value: 1120000 },
|
|
127
|
+
{ name: "Data", value: 960000 }
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "Sales",
|
|
132
|
+
children: [
|
|
133
|
+
{ name: "Enterprise", value: 1380000 },
|
|
134
|
+
{ name: "Mid-market", value: 860000 },
|
|
135
|
+
{ name: "Partnerships", value: 420000 }
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "Marketing",
|
|
140
|
+
children: [
|
|
141
|
+
{ name: "Growth", value: 720000 },
|
|
142
|
+
{ name: "Brand", value: 640000 },
|
|
143
|
+
{ name: "Events", value: 380000 }
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "Operations",
|
|
148
|
+
children: [
|
|
149
|
+
{ name: "Facilities", value: 520000 },
|
|
150
|
+
{ name: "People", value: 460000 },
|
|
151
|
+
{ name: "Finance", value: 410000 }
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
];
|
|
155
|
+
protected readonly dollars: ChartValueFormatter = value => dollars.format(Number(value));
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`budget-example.component.html`
|
|
160
|
+
|
|
161
|
+
```html
|
|
162
|
+
<mona-chart aria-label="Annual budget by department" class="h-80 w-full" [data]="budget">
|
|
163
|
+
<mona-treemap-series name="Budget" [showValues]="true" [valueFormatter]="dollars" />
|
|
164
|
+
<mona-chart-legend />
|
|
165
|
+
<mona-chart-tooltip />
|
|
166
|
+
</mona-chart>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Drill down
|
|
170
|
+
|
|
171
|
+
`maxDepth` set to `1` collapses each region into one rectangle the size of its total. The chart's `pointClick` event carries the node's `hierarchy`, and its `sourceIndexPath` says which region was chosen, so the page can show that region's countries instead. `Enter` on a focused node emits `pointClick` too, so the drill down works from the keyboard.
|
|
172
|
+
|
|
173
|
+
`drill-down-example.component.ts`
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { Component, computed, signal } from "@angular/core";
|
|
177
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
178
|
+
import { ChartComponent, ChartTooltipComponent, TreemapSeriesComponent } from "@nanahoshi/mona-ui/chart";
|
|
179
|
+
import type { ChartPointEvent } from "@nanahoshi/mona-ui/chart";
|
|
180
|
+
|
|
181
|
+
interface Region {
|
|
182
|
+
readonly children: readonly { readonly name: string; readonly value: number }[];
|
|
183
|
+
readonly name: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const REGIONS: readonly Region[] = [
|
|
187
|
+
{
|
|
188
|
+
name: "Europe",
|
|
189
|
+
children: [
|
|
190
|
+
{ name: "Germany", value: 420 },
|
|
191
|
+
{ name: "France", value: 310 },
|
|
192
|
+
{ name: "Spain", value: 190 },
|
|
193
|
+
{ name: "Italy", value: 170 }
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "Americas",
|
|
198
|
+
children: [
|
|
199
|
+
{ name: "United States", value: 880 },
|
|
200
|
+
{ name: "Canada", value: 210 },
|
|
201
|
+
{ name: "Brazil", value: 160 }
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "Asia Pacific",
|
|
206
|
+
children: [
|
|
207
|
+
{ name: "Japan", value: 380 },
|
|
208
|
+
{ name: "Australia", value: 240 },
|
|
209
|
+
{ name: "Singapore", value: 120 }
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
@Component({
|
|
215
|
+
selector: "app-chart-treemap-drill-down-example",
|
|
216
|
+
imports: [ButtonDirective, ChartComponent, ChartTooltipComponent, TreemapSeriesComponent],
|
|
217
|
+
templateUrl: "./drill-down-example.component.html"
|
|
218
|
+
})
|
|
219
|
+
export class ChartTreemapDrillDownExampleComponent {
|
|
220
|
+
protected readonly data = computed(() => this.region()?.children ?? REGIONS);
|
|
221
|
+
protected readonly region = signal<Region | null>(null);
|
|
222
|
+
|
|
223
|
+
protected onPointClick(event: ChartPointEvent): void {
|
|
224
|
+
if (this.region()) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
// With maxDepth 1 each region is one rectangle, and the first index of its path is the region's.
|
|
228
|
+
const index = event.hierarchy?.sourceIndexPath[0];
|
|
229
|
+
const region = index === undefined ? undefined : REGIONS[index];
|
|
230
|
+
if (region) {
|
|
231
|
+
this.region.set(region);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`drill-down-example.component.html`
|
|
238
|
+
|
|
239
|
+
```html
|
|
240
|
+
<div class="flex flex-col gap-2">
|
|
241
|
+
<div class="flex h-8 items-center">
|
|
242
|
+
@if (region()) {
|
|
243
|
+
<button monaButton size="small" type="button" (click)="region.set(null)">All regions</button>
|
|
244
|
+
}
|
|
245
|
+
</div>
|
|
246
|
+
<mona-chart
|
|
247
|
+
class="h-72 w-full"
|
|
248
|
+
subtitle="Revenue in millions. Click or press Enter on a region to open it."
|
|
249
|
+
[data]="data()"
|
|
250
|
+
[title]="region()?.name ?? 'Revenue by region'"
|
|
251
|
+
(pointClick)="onPointClick($event)">
|
|
252
|
+
<mona-treemap-series name="Revenue" [maxDepth]="1" [showValues]="true" />
|
|
253
|
+
<mona-chart-tooltip />
|
|
254
|
+
</mona-chart>
|
|
255
|
+
</div>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Custom labels and colors
|
|
259
|
+
|
|
260
|
+
`colors` gives each top-level folder its color, and `colorField` paints one node differently from its branch. The label template adds the node's share of its folder, and `minLabelHeight` makes room for the second line.
|
|
261
|
+
|
|
262
|
+
`custom-labels-example.component.ts`
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { PercentPipe } from "@angular/common";
|
|
266
|
+
import { Component } from "@angular/core";
|
|
267
|
+
import {
|
|
268
|
+
ChartComponent,
|
|
269
|
+
ChartTooltipComponent,
|
|
270
|
+
ChartTreemapLabelTemplateDirective,
|
|
271
|
+
TreemapSeriesComponent
|
|
272
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
273
|
+
import type { ChartValueFormatter } from "@nanahoshi/mona-ui/chart";
|
|
274
|
+
|
|
275
|
+
@Component({
|
|
276
|
+
selector: "app-chart-treemap-custom-labels-example",
|
|
277
|
+
imports: [
|
|
278
|
+
ChartComponent,
|
|
279
|
+
ChartTooltipComponent,
|
|
280
|
+
ChartTreemapLabelTemplateDirective,
|
|
281
|
+
PercentPipe,
|
|
282
|
+
TreemapSeriesComponent
|
|
283
|
+
],
|
|
284
|
+
templateUrl: "./custom-labels-example.component.html"
|
|
285
|
+
})
|
|
286
|
+
export class ChartTreemapCustomLabelsExampleComponent {
|
|
287
|
+
protected readonly colors = ["#1d4ed8", "#0f766e", "#6d28d9"];
|
|
288
|
+
protected readonly disk = [
|
|
289
|
+
{
|
|
290
|
+
name: "Media",
|
|
291
|
+
children: [
|
|
292
|
+
{ name: "Videos", size: 48 },
|
|
293
|
+
{ name: "Photos", size: 31 },
|
|
294
|
+
{ name: "Music", size: 12 }
|
|
295
|
+
]
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: "Projects",
|
|
299
|
+
children: [
|
|
300
|
+
{ name: "node_modules", size: 22, color: "#b91c1c" },
|
|
301
|
+
{ name: "Builds", size: 9 },
|
|
302
|
+
{ name: "Sources", size: 4 }
|
|
303
|
+
]
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "System",
|
|
307
|
+
children: [
|
|
308
|
+
{ name: "Applications", size: 26 },
|
|
309
|
+
{ name: "Caches", size: 7 },
|
|
310
|
+
{ name: "Logs", size: 2 }
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
];
|
|
314
|
+
protected readonly gigabytes: ChartValueFormatter = value => `${value} GB`;
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
`custom-labels-example.component.html`
|
|
319
|
+
|
|
320
|
+
```html
|
|
321
|
+
<mona-chart aria-label="Disk usage" class="h-80 w-full" [data]="disk">
|
|
322
|
+
<mona-treemap-series
|
|
323
|
+
colorField="color"
|
|
324
|
+
field="size"
|
|
325
|
+
name="Disk usage"
|
|
326
|
+
[borderRadius]="4"
|
|
327
|
+
[colors]="colors"
|
|
328
|
+
[minLabelHeight]="32"
|
|
329
|
+
[parentHeaderHeight]="24"
|
|
330
|
+
[valueFormatter]="gigabytes">
|
|
331
|
+
<ng-template monaChartTreemapLabelTemplate let-node>
|
|
332
|
+
<span class="truncate font-semibold">{{ node.formattedLabel }}</span>
|
|
333
|
+
@if (node.isLeaf) {
|
|
334
|
+
<span class="truncate text-xs opacity-80">
|
|
335
|
+
{{ node.formattedValue }} · {{ (node.percentageOfParent ?? 0) | percent }}
|
|
336
|
+
</span>
|
|
337
|
+
}
|
|
338
|
+
</ng-template>
|
|
339
|
+
</mona-treemap-series>
|
|
340
|
+
<mona-chart-tooltip />
|
|
341
|
+
</mona-chart>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Appearance & Styling
|
|
345
|
+
|
|
346
|
+
| Input | Values | Effect |
|
|
347
|
+
| :--- | :--- | :--- |
|
|
348
|
+
| `tile` | `"squarify"`, `"binary"`, `"dice"`, `"slice"`, `"slice-dice"` | How a rectangle is split among its children. `squarify` keeps the rectangles close to square, so they're easiest to compare. `binary` splits in balanced halves. `dice` lays children side by side in columns, `slice` stacks them in rows, and `slice-dice` alternates between the two by level. |
|
|
349
|
+
| `sort` | `"descending"`, `"ascending"`, `"none"` | The order of siblings. `descending` puts subtrees with more levels first and then the larger values, `ascending` the reverse, and `none` keeps the data's order. |
|
|
350
|
+
| `paddingInner` | Pixels, `2` | The gap between siblings. |
|
|
351
|
+
| `paddingOuter` | Pixels, `4` | The space inside a parent around its children. |
|
|
352
|
+
| `parentHeaderHeight` | Pixels, `20` when unset | The height of a parent's header strip. |
|
|
353
|
+
| `colors` | An array of CSS colors | One color per top-level node, used again from the start when there are more nodes than colors. A node's whole branch takes its color. |
|
|
354
|
+
| `color` | A CSS color | One color for every branch, when `colors` isn't set. |
|
|
355
|
+
| `fillOpacity` | `0` to `1`, `1` when unset | The opacity of the filled rectangles: leaves and collapsed nodes. |
|
|
356
|
+
| `parentFillOpacity` | `0` to `1`, `0.15` when unset | The opacity of a parent's background. |
|
|
357
|
+
| `strokeColor`, `strokeWidth` | A CSS color, pixels | The outline of each rectangle. By default it's 1 pixel in the surface color, which reads as a gap. |
|
|
358
|
+
| `borderRadius` | Pixels, `0` when unset | The corner radius of each rectangle. |
|
|
359
|
+
|
|
360
|
+
Colors can be any CSS color, or a custom property such as `--color-chart-2`. Without `colors` or `color`, a color set on the series element, with `style` or a `text-` class, colors every branch, and without that the branches take the chart palette in order.
|
|
361
|
+
|
|
362
|
+
### Labels
|
|
363
|
+
|
|
364
|
+
| Input | Default | Effect |
|
|
365
|
+
| :--- | :--- | :--- |
|
|
366
|
+
| `showLabels` | `true` | Labels the leaves and collapsed nodes. |
|
|
367
|
+
| `showParentLabels` | `true` | Labels the parents in their header strip. Turned off, parents have no header and are only padded by `paddingOuter`. |
|
|
368
|
+
| `showValues` | `false` | Adds the value under each leaf's label. |
|
|
369
|
+
| `minLabelWidth` | `30` | The narrowest rectangle that gets a label, in pixels. |
|
|
370
|
+
| `minLabelHeight` | `16`, or `24` with `showValues` | The lowest leaf or collapsed node that gets a label. A header needs at least 12 pixels. |
|
|
371
|
+
| `maxLabels` | `100` | The most labels shown. Parent headers come first, from the top level down, then the largest leaves. |
|
|
372
|
+
| `categoryFormatter` | none | Formats the labels, in the rectangles, the legend, the tooltip and announcements. |
|
|
373
|
+
| `valueFormatter` | none | Formats the values. Without it they're shortened, as `1.8K`, for the library locale. |
|
|
374
|
+
|
|
375
|
+
The text color is chosen to stay readable on each rectangle's fill. Parent headers use the foreground color.
|
|
376
|
+
|
|
377
|
+
`labelFormatter` is deprecated. Use `categoryFormatter`, which wins when both are set.
|
|
378
|
+
|
|
379
|
+
## Theming
|
|
380
|
+
|
|
381
|
+
These custom properties, set on the series element or on the chart, change the defaults. The inputs above take precedence over them.
|
|
382
|
+
|
|
383
|
+
| Property | Sets |
|
|
384
|
+
| :--- | :--- |
|
|
385
|
+
| `--mona-chart-treemap-stroke-color` | The outline color. |
|
|
386
|
+
| `--mona-chart-treemap-stroke-width` | The outline width, as a number of pixels. |
|
|
387
|
+
| `--mona-chart-treemap-fill-opacity` | The opacity of leaves and collapsed nodes. |
|
|
388
|
+
| `--mona-chart-treemap-parent-fill-opacity` | The opacity of parent backgrounds. |
|
|
389
|
+
| `--mona-chart-treemap-border-radius` | The corner radius, as a number of pixels. |
|
|
390
|
+
| `--mona-chart-treemap-label-color` | One text color for every label, instead of the automatic contrast color. |
|
|
391
|
+
|
|
392
|
+
## Behavior
|
|
393
|
+
|
|
394
|
+
### One series, no axes
|
|
395
|
+
|
|
396
|
+
A treemap takes the whole chart on its own. A chart with two treemap series, or a treemap and any other series, draws nothing and logs a development warning. X, Y, angular and radial axes are ignored, with a warning. The chart's `navigation`, `downsampling` and `xField` don't apply.
|
|
397
|
+
|
|
398
|
+
### Values
|
|
399
|
+
|
|
400
|
+
- A parent's value is the sum of its descendants, and a parent with an empty `children` array counts as a leaf.
|
|
401
|
+
- A negative value counts as `0`, with a development warning. A value that isn't a finite number also counts as `0`. A node worth `0` takes no space.
|
|
402
|
+
- When no visible leaf has a positive value, the chart shows its no-data state. So does hiding every top-level node, or the series.
|
|
403
|
+
- `children` that isn't an array is ignored with a warning, and a node that contains itself further down is left out, with a warning, so cyclic data doesn't hang the chart. The tree is cut at 128 levels.
|
|
404
|
+
|
|
405
|
+
### Depth and collapsing
|
|
406
|
+
|
|
407
|
+
`maxDepth` limits how many levels are laid out. A node at that level that has children is collapsed: it's drawn as one filled rectangle the size of its total, labelled like a leaf, with `isCollapsed` set in the label context and in the event and tooltip `hierarchy`. A value of `0` or less counts as `1`, a fraction is rounded down, and leaving it unset, or setting `Infinity`, shows every level.
|
|
408
|
+
|
|
409
|
+
### Hiding top-level nodes
|
|
410
|
+
|
|
411
|
+
The legend has an entry for each top-level node. Toggling one hides that node and everything in it, and the others grow to fill the space. The series then emits `nodeVisibilityChange`, with the node's id, label and new state, and updates `[(hiddenNodeIds)]`. The chart's `seriesVisibilityChange` isn't emitted, since the series stays visible.
|
|
412
|
+
|
|
413
|
+
- Only top-level ids have an effect. Hiding a deeper node isn't supported.
|
|
414
|
+
- Ids are generated: with `keyField` from the key, and `chartItemKeyId(key)` builds that id (see the [Chart Overview API](chart.md)). Without `keyField` they come from the path of labels; read those from `nodeVisibilityChange`, or from `hierarchy.nodeId` in the chart's point events, rather than building them by hand.
|
|
415
|
+
- Hidden ids the data no longer has are dropped when the data changes, and an empty data set keeps them, as described on [Chart Overview](chart.md).
|
|
416
|
+
- Give nodes a `keyField` when the data reloads or two siblings can share a label. Without one, siblings with the same label are told apart by their order. A key used twice falls back to the path, with a warning.
|
|
417
|
+
|
|
418
|
+
`[(visible)]` shows or hides the whole series.
|
|
419
|
+
|
|
420
|
+
### Pointer and tooltip
|
|
421
|
+
|
|
422
|
+
The pointer picks the deepest node under it. A parent is picked from its header strip, since its children cover the rest, so with `showParentLabels` off a parent can only be reached with the keyboard. The tooltip shows the node's label, its path when it's below the top level, its value and its share of the visible total. `pointClick` and `pointFocusChange` carry the node in `hierarchy`, with the same fields as the label context.
|
|
423
|
+
|
|
424
|
+
## Accessibility
|
|
425
|
+
|
|
426
|
+
The chart is the focusable element, and the series adds no roles of its own. Moving to a node announces its path, its value, its share of the total and whether it's a leaf or a group with its number of children.
|
|
427
|
+
|
|
428
|
+
- **Name the chart and the series.** Give the chart a `title` or `aria-label`, and the series a `name`, which the description reads.
|
|
429
|
+
- **Format values.** Use `valueFormatter` to add a unit, since announcements and the data table read the formatted value.
|
|
430
|
+
- **Labels are hidden from screen readers.** The labels, including a `monaChartTreemapLabelTemplate`, are `aria-hidden`, so don't put information only there.
|
|
431
|
+
- **Don't rely on color alone.** A branch is one color, so keep the parent labels or the legend that name it, and check that custom `colors` keep text readable.
|
|
432
|
+
- With `dataTable`, the table has a row for each node, labelled by its path, and a value column.
|
|
433
|
+
|
|
434
|
+
### Keyboard Navigation
|
|
435
|
+
|
|
436
|
+
Keys move through the drawn nodes as a tree, in depth-first order.
|
|
437
|
+
|
|
438
|
+
| Key | Action |
|
|
439
|
+
| :--- | :--- |
|
|
440
|
+
| `ArrowRight` | Move to the first child, or to the next node when there are no children. |
|
|
441
|
+
| `ArrowLeft` | Move to the parent. |
|
|
442
|
+
| `ArrowDown` | Move to the next sibling, or to the next node when this is the last sibling. |
|
|
443
|
+
| `ArrowUp` | Move to the previous sibling, or else the previous node or the parent. |
|
|
444
|
+
| `Home` / `End` | Move to the first or last node. |
|
|
445
|
+
|
|
446
|
+
`Enter`, `Space`, `Escape` and the rest are listed on [Chart Overview](chart.md).
|
|
447
|
+
|
|
448
|
+
## API
|
|
449
|
+
|
|
450
|
+
Everything below is imported from `@nanahoshi/mona-ui/chart`.
|
|
451
|
+
|
|
452
|
+
### `TreemapSeriesComponent`
|
|
453
|
+
|
|
454
|
+
Renders hierarchical treemap visualizations using nested squarified, binary, dice, or slice-dice rectangles.
|
|
455
|
+
|
|
456
|
+
**Selector:** `mona-treemap-series`
|
|
457
|
+
|
|
458
|
+
#### Inputs
|
|
459
|
+
|
|
460
|
+
| Name | Type | Default | Description |
|
|
461
|
+
| --- | --- | --- | --- |
|
|
462
|
+
| `borderRadius` | `number \| undefined` | `undefined` | Corner radius in pixels applied to leaf node rectangles. |
|
|
463
|
+
| `categoryFormatter` | `ChartValueFormatter \| undefined` | `undefined` | Formatter callback for node labels. |
|
|
464
|
+
| `childrenField` | `ChartField` | `"children"` | Property key or accessor function extracting child nodes from a hierarchical data object. |
|
|
465
|
+
| `class` | `string` | `""` | Additional CSS classes applied to the series. |
|
|
466
|
+
| `color` | `string` | `""` | Fallback base fill color applied to series or root branches. |
|
|
467
|
+
| `colorField` | `ChartField \| undefined` | `undefined` | Accessor function or property key extracting an explicit fill color for a node. |
|
|
468
|
+
| `colors` | `readonly string[] \| undefined` | `undefined` | Explicit array of colors assigned to top-level branches and inherited down subtrees. |
|
|
469
|
+
| `data` | `readonly unknown[] \| unknown \| undefined` | `undefined` | Hierarchical root object or array of root nodes overriding chart-level data. |
|
|
470
|
+
| `field` | `ChartField` | `"value"` | Property key or accessor function extracting the numeric value for a leaf node. |
|
|
471
|
+
| `fillOpacity` | `number \| undefined` | `undefined` | Opacity of leaf node fills (0 to 1). |
|
|
472
|
+
| `hiddenNodeIds` (two-way) | `readonly string[]` | `[]` | The hidden top-level node IDs. Bind `[(hiddenNodeIds)]` for two-way binding; legend toggles write to it. With `keyField`, build an ID with `chartItemKeyId(key)`; otherwise read IDs from `nodeVisibilityChange`. |
|
|
473
|
+
| `keyField` | `ChartField \| undefined` | `undefined` | Property key or accessor extracting a stable datum identity across data updates. |
|
|
474
|
+
| `labelField` | `ChartField` | `"name"` | Property key or accessor extracting the display label for a node. |
|
|
475
|
+
| `labelFormatter` | `ChartValueFormatter \| undefined` | `undefined` | **Deprecated.** Use `categoryFormatter`, as on the other series. Formatter callback for node display labels. |
|
|
476
|
+
| `maxDepth` | `number \| undefined` | `undefined` | Maximum tree depth to layout and render. Normalized: finite <= 0 becomes 1, finite > 0 is floored, undefined/NaN/Infinity is unlimited. |
|
|
477
|
+
| `maxLabels` | `number` | `100` | Maximum number of DOM label candidates to render (prioritizing parent headers and largest leaf areas). |
|
|
478
|
+
| `minLabelHeight` | `number \| undefined` | `undefined` | Minimum pixel height required for a node to display a DOM label (defaults to 16 when showValues is false, 24 when true). |
|
|
479
|
+
| `minLabelWidth` | `number \| undefined` | `undefined` | Minimum pixel width required for a node to display a DOM label (defaults to 30). |
|
|
480
|
+
| `name` | `string` | `"Treemap"` | Series name used in tooltips and accessibility announcements. |
|
|
481
|
+
| `paddingInner` | `number` | `2` | Inner padding in pixels between sibling treemap rectangles. |
|
|
482
|
+
| `paddingOuter` | `number` | `4` | Outer padding in pixels around parent boundaries. |
|
|
483
|
+
| `parentFillOpacity` | `number \| undefined` | `undefined` | Fill opacity applied to non-leaf parent group background rectangles. |
|
|
484
|
+
| `parentHeaderHeight` | `number \| undefined` | `undefined` | Header height in pixels reserved for parent node header labels. |
|
|
485
|
+
| `showLabels` | `boolean` | `true` | Whether to display DOM labels for leaf and terminal nodes. |
|
|
486
|
+
| `showParentLabels` | `boolean` | `true` | Whether to reserve header space and display labels for parent grouping nodes. |
|
|
487
|
+
| `showValues` | `boolean` | `false` | Whether to display numeric values in default leaf labels. |
|
|
488
|
+
| `sort` | `ChartTreemapSort` | `"descending"` | Sort order for sibling nodes: "descending", "ascending", or "none". |
|
|
489
|
+
| `strokeColor` | `string` | `""` | Color of node boundary stroke borders. |
|
|
490
|
+
| `strokeWidth` | `number \| undefined` | `undefined` | Stroke width in pixels for node boundary borders. |
|
|
491
|
+
| `tile` | `ChartTreemapTile` | `"squarify"` | D3 treemap tiling algorithm: "squarify", "binary", "dice", "slice", or "slice-dice". |
|
|
492
|
+
| `valueFormatter` | `ChartValueFormatter \| undefined` | `undefined` | Formatter callback for numeric values in labels and tooltips. |
|
|
493
|
+
| `visible` (two-way) | `boolean` | `true` | Two-way bindable visibility of the series. |
|
|
494
|
+
|
|
495
|
+
#### Outputs
|
|
496
|
+
|
|
497
|
+
| Name | Type | Description |
|
|
498
|
+
| --- | --- | --- |
|
|
499
|
+
| `hiddenNodeIdsChange` | `readonly string[]` | Emitted when `hiddenNodeIds` changes. |
|
|
500
|
+
| `nodeVisibilityChange` | `ChartTreemapNodeVisibilityEvent<unknown>` | Emits when an individual node or branch's visibility is toggled via the legend. |
|
|
501
|
+
| `visibleChange` | `boolean` | Emitted when `visible` changes. |
|
|
502
|
+
|
|
503
|
+
#### Methods
|
|
504
|
+
|
|
505
|
+
| Signature | Description |
|
|
506
|
+
| --- | --- |
|
|
507
|
+
| `toggleNode(nodeId: string): boolean` | Shows or hides the node with this id, and returns whether it's now visible. |
|
|
508
|
+
|
|
509
|
+
### `ChartTreemapLabelTemplateDirective`
|
|
510
|
+
|
|
511
|
+
**Selector:** `ng-template[monaChartTreemapLabelTemplate]`
|
|
512
|
+
|
|
513
|
+
#### Template context
|
|
514
|
+
|
|
515
|
+
| Name | Type |
|
|
516
|
+
| --- | --- |
|
|
517
|
+
| `$implicit` | `ChartHierarchyNodeContext<unknown>` |
|
|
518
|
+
| `bounds` | `ChartRect` |
|
|
519
|
+
| `color` | `string` |
|
|
520
|
+
| `datum` | `unknown` |
|
|
521
|
+
| `depth` | `number` |
|
|
522
|
+
| `formattedLabel` | `string` |
|
|
523
|
+
| `formattedPath` | `readonly string[]` |
|
|
524
|
+
| `formattedValue` | `string` |
|
|
525
|
+
| `isCollapsed` | `boolean` |
|
|
526
|
+
| `isLeaf` | `boolean` |
|
|
527
|
+
| `label` | `unknown` |
|
|
528
|
+
| `node` | `ChartHierarchyNodeContext<unknown>` |
|
|
529
|
+
| `nodeId` | `string` |
|
|
530
|
+
| `path` | `readonly unknown[]` |
|
|
531
|
+
| `percentageOfParent?` | `number \| undefined` |
|
|
532
|
+
| `percentageOfRoot?` | `number \| undefined` |
|
|
533
|
+
| `textColor` | `string` |
|
|
534
|
+
| `value` | `number` |
|
|
535
|
+
|
|
536
|
+
### Types
|
|
537
|
+
|
|
538
|
+
#### `ChartHierarchyNodeContext`
|
|
539
|
+
|
|
540
|
+
**Type parameters:** `T = unknown`
|
|
541
|
+
|
|
542
|
+
| Name | Type |
|
|
543
|
+
| --- | --- |
|
|
544
|
+
| `aggregateValue` (read-only) | `number` |
|
|
545
|
+
| `childCount` (read-only) | `number` |
|
|
546
|
+
| `dataIndex` (read-only) | `number` |
|
|
547
|
+
| `datum` (read-only) | `T` |
|
|
548
|
+
| `depth` (read-only) | `number` |
|
|
549
|
+
| `descendantCount` (read-only) | `number` |
|
|
550
|
+
| `formattedLabel` (read-only) | `string` |
|
|
551
|
+
| `formattedPath` (read-only) | `readonly string[]` |
|
|
552
|
+
| `formattedValue` (read-only) | `string` |
|
|
553
|
+
| `isCollapsed` (read-only) | `boolean` |
|
|
554
|
+
| `isLeaf` (read-only) | `boolean` |
|
|
555
|
+
| `label` (read-only) | `unknown` |
|
|
556
|
+
| `nodeId` (read-only) | `string` |
|
|
557
|
+
| `parentId?` (read-only) | `string` |
|
|
558
|
+
| `path` (read-only) | `readonly unknown[]` |
|
|
559
|
+
| `percentageOfParent?` (read-only) | `number` |
|
|
560
|
+
| `percentageOfRoot?` (read-only) | `number` |
|
|
561
|
+
| `rawValue?` (read-only) | `number` |
|
|
562
|
+
| `siblingIndex` (read-only) | `number` |
|
|
563
|
+
| `sourceIndexPath` (read-only) | `readonly number[]` |
|
|
564
|
+
| `treeHeight` (read-only) | `number` |
|
|
565
|
+
|
|
566
|
+
#### `ChartHierarchyPointMetadata`
|
|
567
|
+
|
|
568
|
+
| Name | Type |
|
|
569
|
+
| --- | --- |
|
|
570
|
+
| `aggregateValue` (read-only) | `number` |
|
|
571
|
+
| `childCount` (read-only) | `number` |
|
|
572
|
+
| `dataIndex` (read-only) | `number` |
|
|
573
|
+
| `depth` (read-only) | `number` |
|
|
574
|
+
| `descendantCount` (read-only) | `number` |
|
|
575
|
+
| `formattedLabel` (read-only) | `string` |
|
|
576
|
+
| `formattedPath` (read-only) | `readonly string[]` |
|
|
577
|
+
| `formattedValue` (read-only) | `string` |
|
|
578
|
+
| `isCollapsed` (read-only) | `boolean` |
|
|
579
|
+
| `isLeaf` (read-only) | `boolean` |
|
|
580
|
+
| `label` (read-only) | `unknown` |
|
|
581
|
+
| `nodeId` (read-only) | `string` |
|
|
582
|
+
| `parentId?` (read-only) | `string` |
|
|
583
|
+
| `path` (read-only) | `readonly unknown[]` |
|
|
584
|
+
| `percentageOfParent?` (read-only) | `number` |
|
|
585
|
+
| `percentageOfRoot?` (read-only) | `number` |
|
|
586
|
+
| `rawValue?` (read-only) | `number` |
|
|
587
|
+
| `siblingIndex` (read-only) | `number` |
|
|
588
|
+
| `sourceIndexPath` (read-only) | `readonly number[]` |
|
|
589
|
+
| `treeHeight` (read-only) | `number` |
|
|
590
|
+
|
|
591
|
+
#### `ChartTreemapLabelTemplateContext`
|
|
592
|
+
|
|
593
|
+
**Type parameters:** `T = unknown`
|
|
594
|
+
|
|
595
|
+
| Name | Type |
|
|
596
|
+
| --- | --- |
|
|
597
|
+
| `$implicit` (read-only) | `ChartHierarchyNodeContext<T>` |
|
|
598
|
+
| `bounds` (read-only) | `ChartRect` |
|
|
599
|
+
| `color` (read-only) | `string` |
|
|
600
|
+
| `datum` (read-only) | `T` |
|
|
601
|
+
| `depth` (read-only) | `number` |
|
|
602
|
+
| `formattedLabel` (read-only) | `string` |
|
|
603
|
+
| `formattedPath` (read-only) | `readonly string[]` |
|
|
604
|
+
| `formattedValue` (read-only) | `string` |
|
|
605
|
+
| `isCollapsed` (read-only) | `boolean` |
|
|
606
|
+
| `isLeaf` (read-only) | `boolean` |
|
|
607
|
+
| `label` (read-only) | `unknown` |
|
|
608
|
+
| `node` (read-only) | `ChartHierarchyNodeContext<T>` |
|
|
609
|
+
| `nodeId` (read-only) | `string` |
|
|
610
|
+
| `path` (read-only) | `readonly unknown[]` |
|
|
611
|
+
| `percentageOfParent?` (read-only) | `number` |
|
|
612
|
+
| `percentageOfRoot?` (read-only) | `number` |
|
|
613
|
+
| `textColor` (read-only) | `string` |
|
|
614
|
+
| `value` (read-only) | `number` |
|
|
615
|
+
|
|
616
|
+
#### `ChartTreemapNodeVisibilityEvent`
|
|
617
|
+
|
|
618
|
+
**Type parameters:** `T = unknown`
|
|
619
|
+
|
|
620
|
+
| Name | Type |
|
|
621
|
+
| --- | --- |
|
|
622
|
+
| `dataIndex?` (read-only) | `number` |
|
|
623
|
+
| `datum?` (read-only) | `T` |
|
|
624
|
+
| `depth?` (read-only) | `number` |
|
|
625
|
+
| `formattedLabel?` (read-only) | `string` |
|
|
626
|
+
| `label?` (read-only) | `unknown` |
|
|
627
|
+
| `nodeId` (read-only) | `string` |
|
|
628
|
+
| `seriesId` (read-only) | `string` |
|
|
629
|
+
| `seriesName` (read-only) | `string` |
|
|
630
|
+
| `seriesType` (read-only) | `"treemap"` |
|
|
631
|
+
| `visible` (read-only) | `boolean` |
|
|
632
|
+
|
|
633
|
+
#### `ChartHierarchicalKind`
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
type ChartHierarchicalKind = "treemap";
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
#### `ChartTreemapSort`
|
|
640
|
+
|
|
641
|
+
```typescript
|
|
642
|
+
type ChartTreemapSort = "ascending" | "descending" | "none";
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
#### `ChartTreemapTile`
|
|
646
|
+
|
|
647
|
+
```typescript
|
|
648
|
+
type ChartTreemapTile = "binary" | "dice" | "slice" | "slice-dice" | "squarify";
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
**Documented elsewhere:** [`ChartField`](chart.md), [`ChartRect`](chart.md), [`ChartValueFormatter`](chart.md)
|