@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,546 @@
|
|
|
1
|
+
# Funnel
|
|
2
|
+
|
|
3
|
+
> A funnel series for stages that narrow, with conversion and drop-off between them.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/chart`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-funnel-series`
|
|
8
|
+
|
|
9
|
+
A funnel series draws the stages of a process, such as a sign-up flow or a sales pipeline, as connected bands whose width follows how many reached each stage. Each stage carries its conversion from the stage before, its conversion from the first stage, and how many dropped off, for labels, tooltips and screen readers. It goes inside a `mona-chart` on its own, with no axes.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
A funnel shows how many items, such as visitors, deals or sessions, reach each stage of a process that runs in a fixed order, and how many are lost on the way. The widest stage takes the most room, and every other stage is as wide as its share of it.
|
|
14
|
+
|
|
15
|
+
Use it for:
|
|
16
|
+
|
|
17
|
+
- Sign-up, onboarding and checkout flows, where the reader asks where people leave.
|
|
18
|
+
- Sales pipelines, from leads to won deals.
|
|
19
|
+
- Any sequence of steps where each stage is a subset of the one before it, or at least follows it.
|
|
20
|
+
|
|
21
|
+
**Use something else when:**
|
|
22
|
+
|
|
23
|
+
- The stages have no order, or they're parts of one total. Use a pie or donut, see [Pie & Donut](chart-pie.md).
|
|
24
|
+
- You need to compare the stages of several funnels, or one funnel over time. A chart takes one funnel, so use grouped bars, see [Bar & Waterfall](chart-bar.md).
|
|
25
|
+
- The values add up and subtract to a total. Use a waterfall, see [Bar & Waterfall](chart-bar.md).
|
|
26
|
+
|
|
27
|
+
The chart, legend, tooltip and interaction parts the series sits in are described on [Chart Overview](chart.md).
|
|
28
|
+
|
|
29
|
+
## Import & Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import {
|
|
33
|
+
ChartComponent,
|
|
34
|
+
ChartLegendComponent,
|
|
35
|
+
ChartTooltipComponent,
|
|
36
|
+
FunnelSeriesComponent
|
|
37
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<mona-chart aria-label="Sign-up funnel" class="h-80 w-full" [data]="stages">
|
|
42
|
+
<mona-funnel-series categoryField="stage" field="users" name="Users" />
|
|
43
|
+
<mona-chart-legend />
|
|
44
|
+
<mona-chart-tooltip />
|
|
45
|
+
</mona-chart>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
protected readonly stages = [
|
|
50
|
+
{ stage: "Visited", users: 12400 },
|
|
51
|
+
{ stage: "Signed up", users: 4820 },
|
|
52
|
+
{ stage: "Subscribed", users: 1120 }
|
|
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 its rows from the chart's `data`, unless it has its own `data`. Each row is one stage, in the order of the rows.
|
|
61
|
+
|
|
62
|
+
| Input | Reads | Default |
|
|
63
|
+
| :--- | :--- | :--- |
|
|
64
|
+
| `field` | The stage's value. | `"value"` |
|
|
65
|
+
| `categoryField` | The stage's name, for its label, legend entry, tooltip and announcement. | `"category"` |
|
|
66
|
+
| `keyField` | A key that identifies the stage, used for its stage ID. Optional. | |
|
|
67
|
+
| `colorField` | A CSS color for the stage. Optional. | |
|
|
68
|
+
|
|
69
|
+
A field is a property name or an accessor, `(row, index) => value`. A row without a name is called "Stage" and its position, as in "Stage 3".
|
|
70
|
+
|
|
71
|
+
### What each stage carries
|
|
72
|
+
|
|
73
|
+
The stage label template, the tooltip context (`point.funnel`) and the `pointClick` and `pointFocusChange` events (`funnel`) describe a stage with these values. They're worked out from the visible stages only.
|
|
74
|
+
|
|
75
|
+
| Value | Holds |
|
|
76
|
+
| :--- | :--- |
|
|
77
|
+
| `value`, `formattedValue` | The stage's value, and its text from `valueFormatter` or the library locale. |
|
|
78
|
+
| `previousValue` | The value of the visible stage before it. The first stage has none. |
|
|
79
|
+
| `conversionRate`, `formattedConversionRate` | The value divided by the previous value, as a ratio and as a percentage with at most one decimal. The first stage has none, and neither does a stage after one whose value is `0`. |
|
|
80
|
+
| `overallConversionRate`, `formattedOverallConversionRate` | The value divided by the first visible stage's value. |
|
|
81
|
+
| `dropOff` | The previous value minus this value. It's negative when the stage is larger than the one before it. |
|
|
82
|
+
| `stageId`, `stageIndex` | The stage's ID, and its position among the visible stages. |
|
|
83
|
+
|
|
84
|
+
### Templates
|
|
85
|
+
|
|
86
|
+
- `ng-template[monaChartFunnelLabelTemplate]`, inside the series, replaces the text of the stage labels. The context is the stage, as `$implicit` and `stage`, with the values above plus `bounds`, `color`, `textColor`, `datum`, `category`, `formattedCategory` and `dataIndex`. The template replaces only the text, so `labelContent` no longer applies, while `showLabels`, `maxLabels` and the minimum sizes still decide which stages get a label.
|
|
87
|
+
- The chart, legend, tooltip and no-data templates are described on [Chart Overview](chart.md).
|
|
88
|
+
|
|
89
|
+
## Examples
|
|
90
|
+
|
|
91
|
+
### Sales pipeline
|
|
92
|
+
|
|
93
|
+
`labelContent="category-value-conversion"` adds each stage's conversion from the stage before to its label, and `valueFormatter` adds the unit to the labels, tooltips and announcements. The legend lists the stages, one entry each.
|
|
94
|
+
|
|
95
|
+
`sales-pipeline-example.component.ts`
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { Component } from "@angular/core";
|
|
99
|
+
import {
|
|
100
|
+
ChartComponent,
|
|
101
|
+
ChartLegendComponent,
|
|
102
|
+
ChartTooltipComponent,
|
|
103
|
+
FunnelSeriesComponent
|
|
104
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
105
|
+
import type { ChartValueFormatter } from "@nanahoshi/mona-ui/chart";
|
|
106
|
+
|
|
107
|
+
@Component({
|
|
108
|
+
selector: "app-chart-funnel-sales-pipeline-example",
|
|
109
|
+
imports: [ChartComponent, ChartLegendComponent, ChartTooltipComponent, FunnelSeriesComponent],
|
|
110
|
+
templateUrl: "./sales-pipeline-example.component.html"
|
|
111
|
+
})
|
|
112
|
+
export class ChartFunnelSalesPipelineExampleComponent {
|
|
113
|
+
protected readonly pipeline = [
|
|
114
|
+
{ deals: 2400, stage: "Leads" },
|
|
115
|
+
{ deals: 1250, stage: "Qualified" },
|
|
116
|
+
{ deals: 640, stage: "Proposal" },
|
|
117
|
+
{ deals: 410, stage: "Negotiation" },
|
|
118
|
+
{ deals: 260, stage: "Won" }
|
|
119
|
+
];
|
|
120
|
+
protected readonly deals: ChartValueFormatter = value => `${Number(value).toLocaleString("en")} deals`;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`sales-pipeline-example.component.html`
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<mona-chart aria-label="Sales pipeline by stage" class="h-80 w-full" [data]="pipeline">
|
|
128
|
+
<mona-funnel-series
|
|
129
|
+
categoryField="stage"
|
|
130
|
+
field="deals"
|
|
131
|
+
labelContent="category-value-conversion"
|
|
132
|
+
name="Deals"
|
|
133
|
+
[valueFormatter]="deals" />
|
|
134
|
+
<mona-chart-legend position="end" />
|
|
135
|
+
<mona-chart-tooltip />
|
|
136
|
+
</mona-chart>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Conversion labels
|
|
140
|
+
|
|
141
|
+
A label template writes each stage's label with your own markup. Here a horizontal funnel shows the conversion and the drop-off under each step's name, and `minLabelWidth` leaves out labels on stages too narrow for them.
|
|
142
|
+
|
|
143
|
+
`conversion-labels-example.component.ts`
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { DecimalPipe } from "@angular/common";
|
|
147
|
+
import { Component } from "@angular/core";
|
|
148
|
+
import {
|
|
149
|
+
ChartComponent,
|
|
150
|
+
ChartFunnelLabelTemplateDirective,
|
|
151
|
+
ChartTooltipComponent,
|
|
152
|
+
FunnelSeriesComponent
|
|
153
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
154
|
+
|
|
155
|
+
@Component({
|
|
156
|
+
selector: "app-chart-funnel-conversion-labels-example",
|
|
157
|
+
imports: [
|
|
158
|
+
ChartComponent,
|
|
159
|
+
ChartFunnelLabelTemplateDirective,
|
|
160
|
+
ChartTooltipComponent,
|
|
161
|
+
DecimalPipe,
|
|
162
|
+
FunnelSeriesComponent
|
|
163
|
+
],
|
|
164
|
+
templateUrl: "./conversion-labels-example.component.html"
|
|
165
|
+
})
|
|
166
|
+
export class ChartFunnelConversionLabelsExampleComponent {
|
|
167
|
+
protected readonly checkout = [
|
|
168
|
+
{ sessions: 8600, step: "Cart" },
|
|
169
|
+
{ sessions: 5900, step: "Shipping" },
|
|
170
|
+
{ sessions: 4700, step: "Payment" },
|
|
171
|
+
{ sessions: 4100, step: "Review" },
|
|
172
|
+
{ sessions: 3800, step: "Paid" }
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`conversion-labels-example.component.html`
|
|
178
|
+
|
|
179
|
+
```html
|
|
180
|
+
<mona-chart aria-label="Checkout sessions by step" class="h-64 w-full" [data]="checkout">
|
|
181
|
+
<mona-funnel-series
|
|
182
|
+
categoryField="step"
|
|
183
|
+
field="sessions"
|
|
184
|
+
name="Sessions"
|
|
185
|
+
orientation="horizontal"
|
|
186
|
+
[minLabelWidth]="72">
|
|
187
|
+
<ng-template monaChartFunnelLabelTemplate let-stage>
|
|
188
|
+
<span class="font-semibold">{{ stage.formattedCategory }}</span>
|
|
189
|
+
<span>{{ stage.formattedValue }}</span>
|
|
190
|
+
@if (stage.dropOff) {
|
|
191
|
+
<span>{{ stage.formattedConversionRate }}, lost {{ stage.dropOff | number }}</span>
|
|
192
|
+
}
|
|
193
|
+
</ng-template>
|
|
194
|
+
</mona-funnel-series>
|
|
195
|
+
<mona-chart-tooltip />
|
|
196
|
+
</mona-chart>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Stage visibility
|
|
200
|
+
|
|
201
|
+
`[(hiddenStageIds)]` holds the hidden stages, and the legend writes to it when the user toggles a stage. With `keyField`, a stage keeps its ID when the rows change order. Hiding a stage works out the conversion of the stages after it again, from the visible stages.
|
|
202
|
+
|
|
203
|
+
`stage-visibility-example.component.ts`
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { Component, signal } from "@angular/core";
|
|
207
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
208
|
+
import {
|
|
209
|
+
ChartComponent,
|
|
210
|
+
ChartLegendComponent,
|
|
211
|
+
ChartTooltipComponent,
|
|
212
|
+
FunnelSeriesComponent
|
|
213
|
+
} from "@nanahoshi/mona-ui/chart";
|
|
214
|
+
import type { ChartFunnelStageVisibilityEvent } from "@nanahoshi/mona-ui/chart";
|
|
215
|
+
|
|
216
|
+
@Component({
|
|
217
|
+
selector: "app-chart-funnel-stage-visibility-example",
|
|
218
|
+
imports: [ButtonDirective, ChartComponent, ChartLegendComponent, ChartTooltipComponent, FunnelSeriesComponent],
|
|
219
|
+
templateUrl: "./stage-visibility-example.component.html"
|
|
220
|
+
})
|
|
221
|
+
export class ChartFunnelStageVisibilityExampleComponent {
|
|
222
|
+
protected readonly hidden = signal<readonly string[]>([]);
|
|
223
|
+
protected readonly journey = [
|
|
224
|
+
{ id: "visited", stage: "Visited", users: 12400 },
|
|
225
|
+
{ id: "signed-up", stage: "Signed up", users: 4820 },
|
|
226
|
+
{ id: "trial", stage: "Started trial", users: 3150 },
|
|
227
|
+
{ id: "subscribed", stage: "Subscribed", users: 1120 },
|
|
228
|
+
{ id: "renewed", stage: "Renewed", users: 860 }
|
|
229
|
+
];
|
|
230
|
+
protected readonly lastChange = signal("");
|
|
231
|
+
|
|
232
|
+
protected onStageVisibilityChange(event: ChartFunnelStageVisibilityEvent): void {
|
|
233
|
+
this.lastChange.set(`${event.formattedCategory} was ${event.visible ? "shown" : "hidden"} from the legend.`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`stage-visibility-example.component.html`
|
|
239
|
+
|
|
240
|
+
```html
|
|
241
|
+
<div class="flex w-full flex-col gap-3">
|
|
242
|
+
<div class="flex flex-wrap gap-2">
|
|
243
|
+
<button monaButton type="button" (click)="hidden.set(['k:s:trial'])">Skip the trial stage</button>
|
|
244
|
+
<button monaButton type="button" [disabled]="hidden().length === 0" (click)="hidden.set([])">
|
|
245
|
+
Show every stage
|
|
246
|
+
</button>
|
|
247
|
+
</div>
|
|
248
|
+
<mona-chart aria-label="Users at each stage of the customer journey" class="h-80 w-full" [data]="journey">
|
|
249
|
+
<mona-funnel-series
|
|
250
|
+
categoryField="stage"
|
|
251
|
+
field="users"
|
|
252
|
+
keyField="id"
|
|
253
|
+
labelContent="category-value-conversion"
|
|
254
|
+
name="Users"
|
|
255
|
+
[(hiddenStageIds)]="hidden"
|
|
256
|
+
(stageVisibilityChange)="onStageVisibilityChange($event)" />
|
|
257
|
+
<mona-chart-legend />
|
|
258
|
+
<mona-chart-tooltip />
|
|
259
|
+
</mona-chart>
|
|
260
|
+
<p class="text-sm text-muted-foreground">Hidden stage IDs: {{ hidden().length ? hidden().join(", ") : "none" }}</p>
|
|
261
|
+
<p aria-live="polite" class="text-sm text-muted-foreground">{{ lastChange() }}</p>
|
|
262
|
+
</div>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Appearance & Styling
|
|
266
|
+
|
|
267
|
+
| Input | Values | Effect |
|
|
268
|
+
| :--- | :--- | :--- |
|
|
269
|
+
| `orientation` | `"vertical"`, `"horizontal"` | Vertical runs the stages from top to bottom, horizontal from left to right. |
|
|
270
|
+
| `widthRatio` | A number from `0.1` to `1` | The widest stage's share of the plot's width, or of its height when horizontal. Values outside the range are clamped. |
|
|
271
|
+
| `gap` | Pixels | The space between stages. Together the gaps never take more than half the funnel's length. |
|
|
272
|
+
| `showLabels` | `boolean` | Whether stages get a label. |
|
|
273
|
+
| `labelContent` | `"category"`, `"value"`, `"category-value"`, `"category-value-conversion"` | What a built-in label shows. The conversion is left out on the first stage. |
|
|
274
|
+
| `maxLabels` | A number | The most labels shown, in stage order. |
|
|
275
|
+
| `minLabelWidth`, `minLabelHeight` | Pixels | The smallest space a label needs inside its stage, `48` wide and `20` tall by default. Both apply in either orientation, and a stage without room has no label. |
|
|
276
|
+
| `color` | Any CSS color | One color for every stage. |
|
|
277
|
+
| `colors` | An array of CSS colors | Colors for the stages in row order, starting over when they run out. |
|
|
278
|
+
| `colorField` | A field | A color for each stage from its row. |
|
|
279
|
+
| `fillOpacity` | A number from `0` to `1` | The opacity of the stages. `1` by default. |
|
|
280
|
+
| `strokeColor`, `strokeWidth` | A CSS color, pixels | The outline between stages. By default it's the surface color, 1 pixel wide. |
|
|
281
|
+
|
|
282
|
+
A stage takes the first color it finds in this order: its `colorField` value, `colors`, `color`, a text color class on the series element, then the chart palette, `--color-chart-1` to `--color-chart-5` by row.
|
|
283
|
+
|
|
284
|
+
Each stage starts as wide as its value and ends as wide as the next stage's value, and the last stage keeps one width. A stage larger than the one before it widens instead of narrowing, as when invitations bring in more people than sent them.
|
|
285
|
+
|
|
286
|
+
Built-in labels pick white or a dark text color, whichever contrasts more with the stage color.
|
|
287
|
+
|
|
288
|
+
## Theming
|
|
289
|
+
|
|
290
|
+
These CSS custom properties style a funnel when the matching input isn't set. Put them on the chart, or on the series with its `class`.
|
|
291
|
+
|
|
292
|
+
| Property | Default | Styles |
|
|
293
|
+
| :--- | :--- | :--- |
|
|
294
|
+
| `--mona-chart-funnel-stroke-color` | The surface color | The outline between stages. |
|
|
295
|
+
| `--mona-chart-funnel-stroke-width` | `1` | The outline width, in pixels. |
|
|
296
|
+
| `--mona-chart-funnel-fill-opacity` | `1` | The opacity of the stages. |
|
|
297
|
+
| `--mona-chart-funnel-label-color` | White or dark, by contrast | The text color of every label. |
|
|
298
|
+
|
|
299
|
+
## Behavior
|
|
300
|
+
|
|
301
|
+
### One funnel per chart
|
|
302
|
+
|
|
303
|
+
A funnel has its chart to itself. A chart with two funnels, or with a funnel and another series, draws no stages, shows its no-data message and logs a development warning. Axes inside a funnel chart are ignored, with a development warning.
|
|
304
|
+
|
|
305
|
+
### Values
|
|
306
|
+
|
|
307
|
+
- A stage needs a finite number of `0` or more. A row whose value is negative, missing, `NaN`, infinite or text that isn't a number is left out, and negative or invalid values log a development warning.
|
|
308
|
+
- A stage whose value is `0` is kept, with no width, and the stage after it has no conversion rate.
|
|
309
|
+
- When no stage is above zero, or every stage is hidden, the chart shows its no-data message. The legend stays, so the user can show hidden stages again. A hidden series shows the message too.
|
|
310
|
+
|
|
311
|
+
### Stage IDs
|
|
312
|
+
|
|
313
|
+
Each stage has an ID, which `hiddenStageIds`, `stageVisibilityChange` and the label context use.
|
|
314
|
+
|
|
315
|
+
- With `keyField`, the ID comes from the row's key, and `chartItemKeyId(key)` builds it. It stays with the row when rows are reordered. A key used twice logs a development warning, and the later row falls back to its index.
|
|
316
|
+
- Without `keyField`, the ID comes from the row's index, and `chartItemIndexId(index)` builds it. It follows the position, not the row, when rows are reordered.
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
import { chartItemKeyId } from "@nanahoshi/mona-ui/chart";
|
|
320
|
+
|
|
321
|
+
protected readonly hiddenStageIds = signal([chartItemKeyId("trial")]);
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Both functions are described in the [Chart Overview API](chart.md). Treat the IDs as opaque: compare them, but don't parse them.
|
|
325
|
+
|
|
326
|
+
The ID also matches stages from one data set to the next, so stages with the same ID animate from where they were.
|
|
327
|
+
|
|
328
|
+
### Stage visibility
|
|
329
|
+
|
|
330
|
+
- `[(hiddenStageIds)]` holds the IDs of the hidden stages. The legend writes to it when the user toggles a stage, and the parent can write to it too. IDs the data no longer has are dropped when the data changes, see [Two-Way Binding](chart.md).
|
|
331
|
+
- `stageVisibilityChange` emits when the legend or a method shows or hides a stage, with the stage's ID, name, row and new visibility. It doesn't emit when the parent writes `hiddenStageIds`.
|
|
332
|
+
- The series has methods for code that holds it through `viewChild`: `setDatumVisibility(stageId, visible)`, `toggleDatumVisibility(stageId)`, `isDatumVisible(stageId)` and `resetVisibility()`, which shows every stage. `resetVisibility()` doesn't emit `stageVisibilityChange`.
|
|
333
|
+
- A hidden stage keeps its legend entry. The other stages close up, and their widths, conversions and drop-offs are worked out again from the visible stages.
|
|
334
|
+
- `[(visible)]` hides the whole series.
|
|
335
|
+
|
|
336
|
+
### Value formatting
|
|
337
|
+
|
|
338
|
+
- `valueFormatter` formats a stage's value in its label, tooltip and announcement. `categoryFormatter` formats its name everywhere it appears, including the legend. Both get the value and the row's index.
|
|
339
|
+
- Conversion rates are percentages for the library locale. The drop-off in the tooltip and announcements is a number for the library locale, and `valueFormatter` doesn't apply to it.
|
|
340
|
+
|
|
341
|
+
### Tooltip
|
|
342
|
+
|
|
343
|
+
The tooltip shows one stage: its name, value, conversion and overall conversion, leaving out what the stage doesn't have, and its drop-off when that's above zero. `shared` has no effect on a funnel.
|
|
344
|
+
|
|
345
|
+
## Accessibility
|
|
346
|
+
|
|
347
|
+
The chart is the focusable element, and the series adds no roles of its own. Moving to a stage announces the series name, the stage's name, its position ("stage 2 of 5") and value, then its conversion from the previous stage, its overall conversion, and its drop-off when that's above zero. Give the series a `name`, and use `valueFormatter` to add a unit.
|
|
348
|
+
|
|
349
|
+
- **Stage labels are hidden from screen readers.** The announcements carry each stage's name, value, conversions and drop-off, and the chart's `dataTable` lists the visible stages and their values. Don't put information only in a label template.
|
|
350
|
+
- **Don't rely on color alone.** Each stage's position and label tell it apart. Keep the labels or the legend so stages can be named without their color.
|
|
351
|
+
- **Check label contrast with custom colors.** Built-in labels pick their text color for the stage's color at full opacity, so a low `fillOpacity` or `--mona-chart-funnel-label-color` needs its own check.
|
|
352
|
+
|
|
353
|
+
### Keyboard Navigation
|
|
354
|
+
|
|
355
|
+
| Key | Action |
|
|
356
|
+
| :--- | :--- |
|
|
357
|
+
| `ArrowDown` / `ArrowUp` | In a vertical funnel, move to the next or previous stage. |
|
|
358
|
+
| `ArrowRight` / `ArrowLeft` | In a horizontal funnel, move to the next or previous stage. |
|
|
359
|
+
| `Home` / `End` | Move to the first or last stage. |
|
|
360
|
+
|
|
361
|
+
The legend toggles stages with `Enter` and `Space`. The rest of the keys, including `Enter` for `pointClick` and `Escape`, are listed on [Chart Overview](chart.md).
|
|
362
|
+
|
|
363
|
+
## API
|
|
364
|
+
|
|
365
|
+
Everything below is imported from `@nanahoshi/mona-ui/chart`.
|
|
366
|
+
|
|
367
|
+
### `FunnelSeriesComponent`
|
|
368
|
+
|
|
369
|
+
Renders conversion pipeline and sales funnel visualizations using connected trapezoidal stages. Supports vertical and
|
|
370
|
+
horizontal layouts, custom stage colors, inscribed DOM labels, widening stages (>100% conversion), and dynamic stage
|
|
371
|
+
visibility toggling.
|
|
372
|
+
|
|
373
|
+
**Selector:** `mona-funnel-series`
|
|
374
|
+
|
|
375
|
+
#### Inputs
|
|
376
|
+
|
|
377
|
+
| Name | Type | Default | Description |
|
|
378
|
+
| --- | --- | --- | --- |
|
|
379
|
+
| `categoryField` | `ChartField` | `"category"` | Property key or accessor extracting stage names. |
|
|
380
|
+
| `categoryFormatter` | `ChartValueFormatter \| undefined` | `undefined` | Optional custom formatter for category names. |
|
|
381
|
+
| `class` | `string` | `""` | CSS class name applied to the hidden series host element. |
|
|
382
|
+
| `color` | `string` | `""` | Uniform fill color for all funnel stages. |
|
|
383
|
+
| `colorField` | `ChartField \| undefined` | `undefined` | Property key extracting discrete colors per datum. |
|
|
384
|
+
| `colors` | `readonly string[] \| undefined` | `undefined` | Palette array of colors cycled across stages. |
|
|
385
|
+
| `data` | `readonly unknown[] \| undefined` | `undefined` | Array of stage data items overriding chart-level root data. |
|
|
386
|
+
| `field` | `ChartField` | `"value"` | Property key or accessor function extracting numeric values. |
|
|
387
|
+
| `fillOpacity` | `number \| undefined` | `undefined` | Fill opacity applied to stage trapezoids (0 to 1). |
|
|
388
|
+
| `gap` | `number` | `2` | Spacing in pixels between consecutive funnel stages. |
|
|
389
|
+
| `hiddenStageIds` (two-way) | `readonly string[]` | `[]` | The hidden stage IDs. Bind `[(hiddenStageIds)]` for two-way binding; legend toggles write to it. Build an ID with `chartItemKeyId(key)` when `keyField` is set, or with `chartItemIndexId(index)`. |
|
|
390
|
+
| `keyField` | `ChartField \| undefined` | `undefined` | Unique identifier key field for datums. |
|
|
391
|
+
| `labelContent` | `ChartFunnelLabelContent` | `"category-value"` | Content format for automatic stage labels. |
|
|
392
|
+
| `maxLabels` | `number` | `100` | Maximum number of visible stage labels rendered simultaneously. |
|
|
393
|
+
| `minLabelHeight` | `number \| undefined` | `undefined` | Minimum stage height required in vertical orientation to render label. |
|
|
394
|
+
| `minLabelWidth` | `number \| undefined` | `undefined` | Minimum stage width required in horizontal orientation to render label. |
|
|
395
|
+
| `name` | `string` | `"Funnel"` | Descriptive series name displayed in chart legend and tooltips. |
|
|
396
|
+
| `orientation` | `ChartFunnelOrientation` | `"vertical"` | Layout orientation of the funnel ('vertical' or 'horizontal'). |
|
|
397
|
+
| `showLabels` | `boolean` | `true` | Controls whether built-in stage text labels are rendered. |
|
|
398
|
+
| `strokeColor` | `string` | `""` | Stroke outline color for stage trapezoids. |
|
|
399
|
+
| `strokeWidth` | `number \| undefined` | `undefined` | Stroke width in pixels for stage trapezoids. |
|
|
400
|
+
| `valueFormatter` | `ChartValueFormatter \| undefined` | `undefined` | Custom formatter function for numeric values. |
|
|
401
|
+
| `visible` (two-way) | `boolean` | `true` | Controls overall visibility of the funnel series. |
|
|
402
|
+
| `widthRatio` | `number` | `0.9` | Maximum width ratio (0 to 1) for the funnel's widest stage relative to plot area. |
|
|
403
|
+
|
|
404
|
+
#### Outputs
|
|
405
|
+
|
|
406
|
+
| Name | Type | Description |
|
|
407
|
+
| --- | --- | --- |
|
|
408
|
+
| `hiddenStageIdsChange` | `readonly string[]` | Emitted when `hiddenStageIds` changes. |
|
|
409
|
+
| `stageVisibilityChange` | `ChartFunnelStageVisibilityEvent<unknown>` | Emits when a stage's visibility is toggled via legend or API. |
|
|
410
|
+
| `visibleChange` | `boolean` | Emitted when `visible` changes. |
|
|
411
|
+
|
|
412
|
+
#### Methods
|
|
413
|
+
|
|
414
|
+
| Signature | Description |
|
|
415
|
+
| --- | --- |
|
|
416
|
+
| `isDatumVisible(stageId: string): boolean` | Whether the stage with this id is visible. |
|
|
417
|
+
| `resetVisibility(): void` | Shows every stage again. |
|
|
418
|
+
| `setDatumVisibility(stageId: string, visible: boolean): void` | Shows or hides the stage with this id. |
|
|
419
|
+
| `toggleDatumVisibility(stageId: string): boolean` | Shows or hides the stage with this id, and returns whether it's now visible. |
|
|
420
|
+
|
|
421
|
+
### `ChartFunnelLabelTemplateDirective`
|
|
422
|
+
|
|
423
|
+
**Selector:** `ng-template[monaChartFunnelLabelTemplate]`
|
|
424
|
+
|
|
425
|
+
#### Template context
|
|
426
|
+
|
|
427
|
+
| Name | Type |
|
|
428
|
+
| --- | --- |
|
|
429
|
+
| `$implicit` | `ChartFunnelStageContext<unknown>` |
|
|
430
|
+
| `bounds` | `ChartRect` |
|
|
431
|
+
| `category` | `unknown` |
|
|
432
|
+
| `color` | `string` |
|
|
433
|
+
| `conversionRate?` | `number \| undefined` |
|
|
434
|
+
| `dataIndex` | `number` |
|
|
435
|
+
| `datum` | `unknown` |
|
|
436
|
+
| `dropOff?` | `number \| undefined` |
|
|
437
|
+
| `formattedCategory` | `string` |
|
|
438
|
+
| `formattedConversionRate?` | `string \| undefined` |
|
|
439
|
+
| `formattedOverallConversionRate?` | `string \| undefined` |
|
|
440
|
+
| `formattedValue` | `string` |
|
|
441
|
+
| `overallConversionRate?` | `number \| undefined` |
|
|
442
|
+
| `previousValue?` | `number \| undefined` |
|
|
443
|
+
| `stage` | `ChartFunnelStageContext<unknown>` |
|
|
444
|
+
| `stageId` | `string` |
|
|
445
|
+
| `stageIndex` | `number` |
|
|
446
|
+
| `textColor?` | `string \| undefined` |
|
|
447
|
+
| `value` | `number` |
|
|
448
|
+
|
|
449
|
+
### Types
|
|
450
|
+
|
|
451
|
+
#### `ChartFunnelLabelTemplateContext`
|
|
452
|
+
|
|
453
|
+
**Type parameters:** `T = unknown`
|
|
454
|
+
|
|
455
|
+
| Name | Type |
|
|
456
|
+
| --- | --- |
|
|
457
|
+
| `$implicit` (read-only) | `ChartFunnelStageContext<T>` |
|
|
458
|
+
| `bounds` (read-only) | `ChartRect` |
|
|
459
|
+
| `category` (read-only) | `unknown` |
|
|
460
|
+
| `color` (read-only) | `string` |
|
|
461
|
+
| `conversionRate?` (read-only) | `number` |
|
|
462
|
+
| `dataIndex` (read-only) | `number` |
|
|
463
|
+
| `datum` (read-only) | `T` |
|
|
464
|
+
| `dropOff?` (read-only) | `number` |
|
|
465
|
+
| `formattedCategory` (read-only) | `string` |
|
|
466
|
+
| `formattedConversionRate?` (read-only) | `string` |
|
|
467
|
+
| `formattedOverallConversionRate?` (read-only) | `string` |
|
|
468
|
+
| `formattedValue` (read-only) | `string` |
|
|
469
|
+
| `overallConversionRate?` (read-only) | `number` |
|
|
470
|
+
| `previousValue?` (read-only) | `number` |
|
|
471
|
+
| `stage` (read-only) | `ChartFunnelStageContext<T>` |
|
|
472
|
+
| `stageId` (read-only) | `string` |
|
|
473
|
+
| `stageIndex` (read-only) | `number` |
|
|
474
|
+
| `textColor?` (read-only) | `string` |
|
|
475
|
+
| `value` (read-only) | `number` |
|
|
476
|
+
|
|
477
|
+
#### `ChartFunnelPointMetadata`
|
|
478
|
+
|
|
479
|
+
| Name | Type |
|
|
480
|
+
| --- | --- |
|
|
481
|
+
| `category` (read-only) | `unknown` |
|
|
482
|
+
| `conversionRate?` (read-only) | `number` |
|
|
483
|
+
| `dropOff?` (read-only) | `number` |
|
|
484
|
+
| `formattedCategory` (read-only) | `string` |
|
|
485
|
+
| `formattedConversionRate?` (read-only) | `string` |
|
|
486
|
+
| `formattedOverallConversionRate?` (read-only) | `string` |
|
|
487
|
+
| `formattedValue` (read-only) | `string` |
|
|
488
|
+
| `overallConversionRate?` (read-only) | `number` |
|
|
489
|
+
| `previousValue?` (read-only) | `number` |
|
|
490
|
+
| `stageId` (read-only) | `string` |
|
|
491
|
+
| `stageIndex` (read-only) | `number` |
|
|
492
|
+
| `value` (read-only) | `number` |
|
|
493
|
+
|
|
494
|
+
#### `ChartFunnelStageContext`
|
|
495
|
+
|
|
496
|
+
**Type parameters:** `T = unknown`
|
|
497
|
+
|
|
498
|
+
| Name | Type |
|
|
499
|
+
| --- | --- |
|
|
500
|
+
| `bounds` (read-only) | `ChartRect` |
|
|
501
|
+
| `category` (read-only) | `unknown` |
|
|
502
|
+
| `color` (read-only) | `string` |
|
|
503
|
+
| `conversionRate?` (read-only) | `number` |
|
|
504
|
+
| `dataIndex` (read-only) | `number` |
|
|
505
|
+
| `datum` (read-only) | `T` |
|
|
506
|
+
| `dropOff?` (read-only) | `number` |
|
|
507
|
+
| `formattedCategory` (read-only) | `string` |
|
|
508
|
+
| `formattedConversionRate?` (read-only) | `string` |
|
|
509
|
+
| `formattedOverallConversionRate?` (read-only) | `string` |
|
|
510
|
+
| `formattedValue` (read-only) | `string` |
|
|
511
|
+
| `overallConversionRate?` (read-only) | `number` |
|
|
512
|
+
| `previousValue?` (read-only) | `number` |
|
|
513
|
+
| `stageId` (read-only) | `string` |
|
|
514
|
+
| `stageIndex` (read-only) | `number` |
|
|
515
|
+
| `textColor?` (read-only) | `string` |
|
|
516
|
+
| `value` (read-only) | `number` |
|
|
517
|
+
|
|
518
|
+
#### `ChartFunnelStageVisibilityEvent`
|
|
519
|
+
|
|
520
|
+
**Type parameters:** `T = unknown`
|
|
521
|
+
|
|
522
|
+
| Name | Type |
|
|
523
|
+
| --- | --- |
|
|
524
|
+
| `category` (read-only) | `unknown` |
|
|
525
|
+
| `dataIndex` (read-only) | `number` |
|
|
526
|
+
| `datum` (read-only) | `T` |
|
|
527
|
+
| `formattedCategory` (read-only) | `string` |
|
|
528
|
+
| `seriesId` (read-only) | `string` |
|
|
529
|
+
| `seriesName` (read-only) | `string` |
|
|
530
|
+
| `seriesType` (read-only) | `"funnel"` |
|
|
531
|
+
| `stageId` (read-only) | `string` |
|
|
532
|
+
| `visible` (read-only) | `boolean` |
|
|
533
|
+
|
|
534
|
+
#### `ChartFunnelLabelContent`
|
|
535
|
+
|
|
536
|
+
```typescript
|
|
537
|
+
type ChartFunnelLabelContent = "category" | "category-value" | "category-value-conversion" | "value";
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### `ChartFunnelOrientation`
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
type ChartFunnelOrientation = "horizontal" | "vertical";
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
**Documented elsewhere:** [`ChartField`](chart.md), [`ChartRect`](chart.md), [`ChartValueFormatter`](chart.md)
|