@zsherman/charts 0.0.0-stage → 0.1.0
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/CHANGELOG.md +7 -0
- package/LICENSE +373 -0
- package/README.md +13 -2
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/dist/dom/bar-list/bar-list.js +386 -0
- package/dist/dom/bar-list/bar-list.styles.js +171 -0
- package/dist/dom/bar-list/index.js +1 -0
- package/dist/dom/chart/chart.js +716 -0
- package/dist/dom/chart/chart.styles.js +165 -0
- package/dist/dom/chart/index.js +1 -0
- package/dist/dom/chart-grid/chart-grid.js +67 -0
- package/dist/dom/chart-grid/index.js +1 -0
- package/dist/dom/donut/donut.js +565 -0
- package/dist/dom/donut/donut.styles.js +111 -0
- package/dist/dom/donut/index.js +1 -0
- package/dist/dom/heat-graph/calendar.js +118 -0
- package/dist/dom/heat-graph/heat-graph.js +423 -0
- package/dist/dom/heat-graph/heat-graph.styles.js +168 -0
- package/dist/dom/heat-graph/index.js +1 -0
- package/dist/dom/heat-matrix/heat-matrix.js +346 -0
- package/dist/dom/heat-matrix/heat-matrix.styles.js +155 -0
- package/dist/dom/heat-matrix/index.js +1 -0
- package/dist/dom/heat-matrix/model.js +41 -0
- package/dist/dom/index.js +13 -0
- package/dist/dom/internal/colors.js +44 -0
- package/dist/dom/internal/floating-tip.js +83 -0
- package/dist/dom/internal/format.js +43 -0
- package/dist/dom/internal/grid-context.js +5 -0
- package/dist/dom/internal/hidden.styles.js +16 -0
- package/dist/dom/internal/legend.js +112 -0
- package/dist/dom/internal/legend.styles.js +108 -0
- package/dist/dom/internal/markers.js +101 -0
- package/dist/dom/internal/options.js +300 -0
- package/dist/dom/internal/place.js +27 -0
- package/dist/dom/internal/scheme-watch.js +73 -0
- package/dist/dom/internal/share.js +28 -0
- package/dist/dom/internal/types.js +0 -0
- package/dist/dom/row-chart/index.js +1 -0
- package/dist/dom/row-chart/model.js +59 -0
- package/dist/dom/row-chart/row-chart.js +691 -0
- package/dist/dom/row-chart/row-chart.styles.js +242 -0
- package/dist/dom/segmented-bar/index.js +1 -0
- package/dist/dom/segmented-bar/segmented-bar.js +280 -0
- package/dist/dom/segmented-bar/segmented-bar.styles.js +88 -0
- package/dist/dom/sparkline/index.js +1 -0
- package/dist/dom/sparkline/sparkline.js +145 -0
- package/dist/dom/stacked-histogram/histogram.js +137 -0
- package/dist/dom/stacked-histogram/index.js +1 -0
- package/dist/dom/stacked-histogram/stacked-histogram.js +761 -0
- package/dist/dom/stacked-histogram/stacked-histogram.styles.js +211 -0
- package/dist/dom/state-timeline/index.js +1 -0
- package/dist/dom/state-timeline/model.js +166 -0
- package/dist/dom/state-timeline/state-timeline.js +729 -0
- package/dist/dom/state-timeline/state-timeline.styles.js +171 -0
- package/dist/dom/status-history/index.js +1 -0
- package/dist/dom/status-history/status-history.js +542 -0
- package/dist/dom/status-history/status-history.styles.js +171 -0
- package/dist/solid/bar-list/bar-list.jsx +139 -0
- package/dist/solid/bar-list/bar-list.styles.jsx +171 -0
- package/dist/solid/bar-list/index.jsx +1 -0
- package/dist/solid/chart/chart.jsx +454 -0
- package/dist/solid/chart/chart.styles.jsx +165 -0
- package/dist/solid/chart/index.jsx +1 -0
- package/dist/solid/chart-grid/chart-grid.jsx +46 -0
- package/dist/solid/chart-grid/index.jsx +1 -0
- package/dist/solid/donut/donut.jsx +291 -0
- package/dist/solid/donut/donut.styles.jsx +111 -0
- package/dist/solid/donut/index.jsx +1 -0
- package/dist/solid/heat-graph/calendar.jsx +118 -0
- package/dist/solid/heat-graph/heat-graph.jsx +228 -0
- package/dist/solid/heat-graph/heat-graph.styles.jsx +168 -0
- package/dist/solid/heat-graph/index.jsx +1 -0
- package/dist/solid/heat-matrix/heat-matrix.jsx +165 -0
- package/dist/solid/heat-matrix/heat-matrix.styles.jsx +155 -0
- package/dist/solid/heat-matrix/index.jsx +1 -0
- package/dist/solid/heat-matrix/model.jsx +41 -0
- package/dist/solid/index.jsx +13 -0
- package/dist/solid/internal/colors.jsx +44 -0
- package/dist/solid/internal/floating-tip.jsx +68 -0
- package/dist/solid/internal/format.jsx +43 -0
- package/dist/solid/internal/grid-context.jsx +5 -0
- package/dist/solid/internal/hidden.styles.jsx +16 -0
- package/dist/solid/internal/legend.jsx +35 -0
- package/dist/solid/internal/legend.styles.jsx +108 -0
- package/dist/solid/internal/markers.jsx +101 -0
- package/dist/solid/internal/options.jsx +300 -0
- package/dist/solid/internal/place.jsx +27 -0
- package/dist/solid/internal/scheme-watch.jsx +73 -0
- package/dist/solid/internal/share.jsx +28 -0
- package/dist/solid/internal/types.jsx +0 -0
- package/dist/solid/row-chart/index.jsx +1 -0
- package/dist/solid/row-chart/model.jsx +59 -0
- package/dist/solid/row-chart/row-chart.jsx +312 -0
- package/dist/solid/row-chart/row-chart.styles.jsx +242 -0
- package/dist/solid/segmented-bar/index.jsx +1 -0
- package/dist/solid/segmented-bar/segmented-bar.jsx +125 -0
- package/dist/solid/segmented-bar/segmented-bar.styles.jsx +88 -0
- package/dist/solid/sparkline/index.jsx +1 -0
- package/dist/solid/sparkline/sparkline.jsx +88 -0
- package/dist/solid/stacked-histogram/histogram.jsx +137 -0
- package/dist/solid/stacked-histogram/index.jsx +1 -0
- package/dist/solid/stacked-histogram/stacked-histogram.jsx +381 -0
- package/dist/solid/stacked-histogram/stacked-histogram.styles.jsx +211 -0
- package/dist/solid/state-timeline/index.jsx +1 -0
- package/dist/solid/state-timeline/model.jsx +166 -0
- package/dist/solid/state-timeline/state-timeline.jsx +387 -0
- package/dist/solid/state-timeline/state-timeline.styles.jsx +171 -0
- package/dist/solid/status-history/index.jsx +1 -0
- package/dist/solid/status-history/status-history.jsx +279 -0
- package/dist/solid/status-history/status-history.styles.jsx +171 -0
- package/dist/styles.css +1 -0
- package/dist/types/bar-list/bar-list.d.ts +91 -0
- package/dist/types/bar-list/bar-list.styles.d.ts +148 -0
- package/dist/types/bar-list/index.d.ts +3 -0
- package/dist/types/chart/chart.d.ts +98 -0
- package/dist/types/chart/chart.styles.d.ts +145 -0
- package/dist/types/chart/index.d.ts +3 -0
- package/dist/types/chart-grid/chart-grid.d.ts +35 -0
- package/dist/types/chart-grid/index.d.ts +2 -0
- package/dist/types/donut/donut.d.ts +124 -0
- package/dist/types/donut/donut.styles.d.ts +96 -0
- package/dist/types/donut/index.d.ts +3 -0
- package/dist/types/heat-graph/calendar.d.ts +61 -0
- package/dist/types/heat-graph/heat-graph.d.ts +82 -0
- package/dist/types/heat-graph/heat-graph.styles.d.ts +141 -0
- package/dist/types/heat-graph/index.d.ts +4 -0
- package/dist/types/heat-matrix/heat-matrix.d.ts +65 -0
- package/dist/types/heat-matrix/heat-matrix.styles.d.ts +135 -0
- package/dist/types/heat-matrix/index.d.ts +3 -0
- package/dist/types/heat-matrix/model.d.ts +15 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/internal/colors.d.ts +22 -0
- package/dist/types/internal/floating-tip.d.ts +15 -0
- package/dist/types/internal/format.d.ts +7 -0
- package/dist/types/internal/grid-context.d.ts +9 -0
- package/dist/types/internal/hidden.styles.d.ts +15 -0
- package/dist/types/internal/legend.d.ts +18 -0
- package/dist/types/internal/legend.styles.d.ts +96 -0
- package/dist/types/internal/markers.d.ts +16 -0
- package/dist/types/internal/options.d.ts +59 -0
- package/dist/types/internal/place.d.ts +20 -0
- package/dist/types/internal/scheme-watch.d.ts +12 -0
- package/dist/types/internal/share.d.ts +19 -0
- package/dist/types/internal/types.d.ts +163 -0
- package/dist/types/row-chart/index.d.ts +4 -0
- package/dist/types/row-chart/model.d.ts +50 -0
- package/dist/types/row-chart/row-chart.d.ts +148 -0
- package/dist/types/row-chart/row-chart.styles.d.ts +216 -0
- package/dist/types/segmented-bar/index.d.ts +3 -0
- package/dist/types/segmented-bar/segmented-bar.d.ts +65 -0
- package/dist/types/segmented-bar/segmented-bar.styles.d.ts +75 -0
- package/dist/types/sparkline/index.d.ts +3 -0
- package/dist/types/sparkline/sparkline.d.ts +38 -0
- package/dist/types/stacked-histogram/histogram.d.ts +48 -0
- package/dist/types/stacked-histogram/index.d.ts +4 -0
- package/dist/types/stacked-histogram/stacked-histogram.d.ts +73 -0
- package/dist/types/stacked-histogram/stacked-histogram.styles.d.ts +187 -0
- package/dist/types/state-timeline/index.d.ts +3 -0
- package/dist/types/state-timeline/model.d.ts +63 -0
- package/dist/types/state-timeline/state-timeline.d.ts +108 -0
- package/dist/types/state-timeline/state-timeline.styles.d.ts +151 -0
- package/dist/types/status-history/index.d.ts +3 -0
- package/dist/types/status-history/status-history.d.ts +72 -0
- package/dist/types/status-history/status-history.styles.d.ts +150 -0
- package/docs/api.json +1346 -0
- package/docs/bar-list.md +190 -0
- package/docs/chart-grid.md +77 -0
- package/docs/chart.md +355 -0
- package/docs/donut.md +182 -0
- package/docs/heat-graph.md +121 -0
- package/docs/heat-matrix.md +108 -0
- package/docs/llms.txt +68 -0
- package/docs/row-chart.md +193 -0
- package/docs/search-index.json +291 -0
- package/docs/segmented-bar.md +128 -0
- package/docs/sparkline.md +82 -0
- package/docs/stacked-histogram.md +123 -0
- package/docs/state-timeline.md +141 -0
- package/docs/status-history.md +121 -0
- package/package.json +104 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Segmented bar
|
|
2
|
+
|
|
3
|
+
<!-- search: segmented bar, category bar, stacked bar, 100% bar, status breakdown, usage bar, storage, quota, part to whole, progress by status, target marker -->
|
|
4
|
+
|
|
5
|
+
One bar split into parts: a breakdown by category or by status that fills the bar (100%), or parts "used of" a total, like storage of a quota. A marker can show a target or a limit, and a legend under the bar gives each part's value and share. It's plain DOM, so it renders on the server.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { SegmentedBar } from "@zsherman/charts/segmented-bar";
|
|
9
|
+
|
|
10
|
+
<SegmentedBar
|
|
11
|
+
label="Test results, run 4821"
|
|
12
|
+
segments={[
|
|
13
|
+
{ label: "Passed", value: 188, tone: "success" },
|
|
14
|
+
{ label: "Flaky", value: 9, tone: "warning" },
|
|
15
|
+
{ label: "Failed", value: 5, tone: "danger" },
|
|
16
|
+
{ label: "Skipped", value: 12, tone: "neutral" },
|
|
17
|
+
]}
|
|
18
|
+
legend
|
|
19
|
+
/>;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage guidelines
|
|
23
|
+
|
|
24
|
+
- Use it for one whole split into a few parts, read left to right: test results by state, deals by stage, storage by file type. Up to about six parts; past that, fold the small ones into "Other" yourself, or use a [Bar list](./bar-list.md) to rank them.
|
|
25
|
+
- Name it with `label`: what the bar shows. The bar's accessible name is the label, then every part's share, written from the data ("Test results, run 4821: Passed 88%, Flaky 4.2%, Failed 2.3%, Skipped 5.6%").
|
|
26
|
+
- Turn the `legend` on wherever people need the numbers: it's where the values are written. Without it, put the key figures in text near the bar.
|
|
27
|
+
- For several wholes to compare side by side, use a stacked [Row chart](./row-chart.md) (one bar per row, with labels and notes) or a stacked [Chart](./chart.md) (bars over time); for one whole as a ring, a [Donut](./donut.md); for a single value of a maximum, the kit's Meter or Progress.
|
|
28
|
+
|
|
29
|
+
## Anatomy
|
|
30
|
+
|
|
31
|
+
Each part is a `SegmentedBarSegment`, and `marker` a `SegmentedBarMarker`:
|
|
32
|
+
|
|
33
|
+
| Field | Type | |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `label` | `string` | The part ("Passed"). |
|
|
36
|
+
| `value` | `number \| null` | Its amount. Missing or negative counts as 0: no bar, a legend row at 0. |
|
|
37
|
+
| `tone` | `"neutral" \| "accent" \| "info" \| "success" \| "warning" \| "danger"` | A status color, for a breakdown by state. |
|
|
38
|
+
| `color` | `ChartColor` | A chart token or any CSS color; wins over `tone`. |
|
|
39
|
+
| `marker.value` | `number` | Where the tick sits, in the segments' units (of `max`, or of the total). Not drawn unless it's a finite number. |
|
|
40
|
+
| `marker.label` | `string` | Its text above the bar, also read at the end of the bar's name. |
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<SegmentedBar
|
|
44
|
+
label="…" // required: what the bar shows
|
|
45
|
+
segments={[{ label, value, tone, color }]} // in order from the start
|
|
46
|
+
max={100} // "used of" a total: the rest stays empty track
|
|
47
|
+
marker={{ value: 90, label: "Warning at 90 GB" }}
|
|
48
|
+
legend // each part's swatch, label, value and share
|
|
49
|
+
format={(v) => …} // how values are written in the legend
|
|
50
|
+
height={8} // the bar's height in pixels
|
|
51
|
+
labels={{ remaining, empty }}
|
|
52
|
+
/>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
What renders: a root `div` (`data-slot="segmented-bar"`) with the marker's label (`segmented-bar-marker-label`, hidden from assistive technology), the bar (`segmented-bar-bar`, `role="img"` named from the data) of segments (`segmented-bar-segment`), the marker's tick (`segmented-bar-marker`), and the legend (`segmented-bar-legend`, a `ul`), or `segmented-bar-empty` when there are no segments.
|
|
56
|
+
|
|
57
|
+
## Colors and tones
|
|
58
|
+
|
|
59
|
+
Without `color` or `tone`, parts take the chart colors in order (`--sui-chart-1`, `--sui-chart-2`, …), the same as Chart's series. For a breakdown by state, set `tone`: the kit's status colors as Badge uses them (`success`, `warning`, `danger`, `info`, `accent`, and a gray `neutral` for "skipped" or "not started"). `color` takes a chart token (`"chart-3"`) or any CSS color, and wins over `tone`. Colors never carry meaning alone: the legend names every part, and the bar's name lists them.
|
|
60
|
+
|
|
61
|
+
## Used of a total
|
|
62
|
+
|
|
63
|
+
`max` turns the bar into "used of" a total: the parts fill their share of `max`, the rest stays empty track, and the legend and the name add a row for the rest (`labels.remaining`, "Remaining" by default). A total above `max` fills the bar.
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
const gb = new Intl.NumberFormat("en-US", { style: "unit", unit: "gigabyte", maximumFractionDigits: 1 });
|
|
67
|
+
|
|
68
|
+
<SegmentedBar
|
|
69
|
+
label="Storage, 84.2 GB of 100 GB used"
|
|
70
|
+
segments={[
|
|
71
|
+
{ label: "Video", value: 41.6 },
|
|
72
|
+
{ label: "Photos", value: 27.3 },
|
|
73
|
+
{ label: "Documents", value: 9.8 },
|
|
74
|
+
{ label: "Backups", value: 5.5 },
|
|
75
|
+
]}
|
|
76
|
+
max={100}
|
|
77
|
+
marker={{ value: 90, label: "Warning at 90 GB" }}
|
|
78
|
+
labels={{ remaining: "Free" }}
|
|
79
|
+
format={(v) => gb.format(v)}
|
|
80
|
+
legend
|
|
81
|
+
/>;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Marker
|
|
85
|
+
|
|
86
|
+
`marker` draws a tick across the bar at `value` (in the segments' units, of `max` or of the total) with its `label` above it: a target, a limit, "you are here". The label is centred on the tick and lines up with it near either end. It's read at the end of the bar's name, so write it as a phrase ("Warning at 90 GB", "Goal: 80%"). A `value` that isn't a finite number draws no marker. In right-to-left text the parts and the marker run from the right.
|
|
87
|
+
|
|
88
|
+
## States
|
|
89
|
+
|
|
90
|
+
- No segments: the bar is empty track, its name ends in "No data" (`labels.empty`), and the legend's place says so.
|
|
91
|
+
- All zero: the parts draw nothing; the legend keeps a row for each at 0. With `max`, the rest is 100%.
|
|
92
|
+
- One part far larger than the others: every part above 0 keeps at least 2px of bar, and the legend says how small ("<0.1%").
|
|
93
|
+
|
|
94
|
+
## Formats
|
|
95
|
+
|
|
96
|
+
Values follow the kit's locale (`LocaleProvider`), full below 10,000 and compact above; pass `format` for units. Shares have one decimal under 10%, none above, and "<0.1%" for a sliver. The legend wraps into columns as the width allows; long labels wrap within their row.
|
|
97
|
+
|
|
98
|
+
## Words
|
|
99
|
+
|
|
100
|
+
`remaining` and `empty` take `labels`, or app-wide the kit's `LocaleProvider messages={{ segmentedBar: { … } }}`.
|
|
101
|
+
|
|
102
|
+
## Gotchas
|
|
103
|
+
|
|
104
|
+
- Shares are rounded on their own, so they can add up to 99% or 101%.
|
|
105
|
+
- After eight parts without `color` or `tone`, the chart colors repeat: fold the small parts first.
|
|
106
|
+
- Don't use status tones for categories that aren't states (regions, file types): use the chart colors.
|
|
107
|
+
|
|
108
|
+
## API reference
|
|
109
|
+
|
|
110
|
+
<!-- generated:props:segmented-bar (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
111
|
+
|
|
112
|
+
Generated from the types of `@zsherman/charts/segmented-bar`. Each part also takes its element's native and ARIA attributes.
|
|
113
|
+
|
|
114
|
+
#### `SegmentedBar`
|
|
115
|
+
|
|
116
|
+
| Prop | Type | Default | Description |
|
|
117
|
+
| --- | --- | --- | --- |
|
|
118
|
+
| `class` | `ClassValue` | | Extra classes on the root. |
|
|
119
|
+
| `format` | `((value: number) => string)` | | How values are written in the legend. Defaults to the locale's numbers, compact from 10,000. |
|
|
120
|
+
| `height` | `number` | `8` | The bar's height in pixels. |
|
|
121
|
+
| `label` (required) | `string` | | What the bar shows ("Storage", "Test results"). Its name is this, then each part's share, written from the data. |
|
|
122
|
+
| `labels` | `Partial<SegmentedBarLabels>` | | The words, in your wording or language (app-wide: `LocaleProvider messages.segmentedBar`). |
|
|
123
|
+
| `legend` | `boolean` | | A legend under the bar: each part's swatch, label, value and share (and the rest of `max`). |
|
|
124
|
+
| `marker` | `SegmentedBarMarker` | | A tick with its own label: a target or a limit. |
|
|
125
|
+
| `max` | `number` | | The whole, for "used of total" (84 GB of 100 GB): the rest stays empty track. Without it, the segments fill the bar (100%). A total above `max` fills the bar. |
|
|
126
|
+
| `segments` (required) | `readonly SegmentedBarSegment[]` | | The parts, in order from the start. |
|
|
127
|
+
|
|
128
|
+
<!-- /generated:props:segmented-bar -->
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Sparkline
|
|
2
|
+
|
|
3
|
+
<!-- search: sparkline, trend line, mini chart, kpi, stat tile, micro chart -->
|
|
4
|
+
|
|
5
|
+
A word-sized trend line with no axes, legend or tooltip: the shape of the last days or hours next to the figure it supports, in a stat tile or a table cell. It shows a direction, not values. It's a small SVG, not a canvas chart: it renders on the server, follows the color scheme through CSS, and adds about 1 KiB rather than uPlot.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Sparkline } from "@zsherman/charts/sparkline";
|
|
9
|
+
|
|
10
|
+
<Sparkline label="Revenue, last 30 days: up 12%" data={[38, 39.2, 38.7, 40.1, 41.5]} />;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage guidelines
|
|
14
|
+
|
|
15
|
+
- Put the number first and the sparkline under or beside it; the sparkline never replaces the figure.
|
|
16
|
+
- Say the trend in `label` ("up 12%"): the line is an image with no values to read.
|
|
17
|
+
- Give it the same period everywhere on a page (30 days in every tile), so tiles compare.
|
|
18
|
+
- Pick one color for the metric (`color="chart-1"`), or the series color it has in the full chart elsewhere on the page. A falling metric that's bad news is still a line in its series color; say "down" in the badge or text, not with red.
|
|
19
|
+
- `area` adds a wash under the line, for metrics whose volume matters (revenue, traffic).
|
|
20
|
+
- For values people read or compare, use a [Chart](./chart.md).
|
|
21
|
+
|
|
22
|
+
## Anatomy
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
<Sparkline
|
|
26
|
+
label="…" // required: the trend in words
|
|
27
|
+
data={[1, 2, 3]} // values, oldest first; or [x, y] aligned data for uneven spacing
|
|
28
|
+
height={32}
|
|
29
|
+
color="chart-1"
|
|
30
|
+
area // a wash under the line
|
|
31
|
+
dot // a dot at the latest value
|
|
32
|
+
/>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
A `div` (`data-slot="sparkline"`, `role="img"` named by `label`, not focusable) holding an `svg` stretched to its box: the line (`sparkline-line`, a non-scaling stroke, so it keeps its width however wide the tile), the optional wash (`sparkline-area`) and dot (`sparkline-dot`, with a surface ring). The y range fits the values; there's no zero baseline, so it shows change, not size.
|
|
36
|
+
|
|
37
|
+
## Stat tiles
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Badge } from "@zsherman/kit/badge";
|
|
41
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@zsherman/kit/card";
|
|
42
|
+
import { Sparkline } from "@zsherman/charts/sparkline";
|
|
43
|
+
|
|
44
|
+
<Card size="sm">
|
|
45
|
+
<CardHeader>
|
|
46
|
+
<CardTitle>Revenue</CardTitle>
|
|
47
|
+
</CardHeader>
|
|
48
|
+
<CardContent style={{ display: "grid", gap: "10px" }}>
|
|
49
|
+
<div style={{ display: "flex", "align-items": "baseline", gap: "8px" }}>
|
|
50
|
+
<span style={{ "font-size": "var(--sui-text-xl)", "font-weight": "var(--sui-weight-semibold)" }}>$48.2K</span>
|
|
51
|
+
<Badge tone="success" size="sm">+12.4%</Badge>
|
|
52
|
+
</div>
|
|
53
|
+
<Sparkline label="Revenue, last 30 days: up 12.4%" data={revenue} color="chart-1" area dot height={36} />
|
|
54
|
+
</CardContent>
|
|
55
|
+
</Card>;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Gotchas
|
|
59
|
+
|
|
60
|
+
- It fills its container's width: inside a flex row, give it room (`flex: 1` or a width).
|
|
61
|
+
- `null` in the values breaks the line there, as in a Chart. With no values it draws nothing: say so in the tile.
|
|
62
|
+
|
|
63
|
+
## API reference
|
|
64
|
+
|
|
65
|
+
<!-- generated:props:sparkline (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
66
|
+
|
|
67
|
+
Generated from the types of `@zsherman/charts/sparkline`. Each part also takes its element's native and ARIA attributes.
|
|
68
|
+
|
|
69
|
+
#### `Sparkline`
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Default | Description |
|
|
72
|
+
| --- | --- | --- | --- |
|
|
73
|
+
| `area` | `boolean` | | Fill a wash under the line. |
|
|
74
|
+
| `class` | `ClassValue` | | Extra classes on the root. |
|
|
75
|
+
| `color` | `ChartColor` | `"chart-1"` | The line's color: a chart token (`chart-1` … `chart-8`) or any CSS color. |
|
|
76
|
+
| `data` (required) | `readonly (number \| null)[] \| AlignedData` | | The values, oldest first; or `[x, y]` aligned data when the points aren't evenly spaced. |
|
|
77
|
+
| `dot` | `boolean` | | Mark the latest value with a dot: where "now" is. |
|
|
78
|
+
| `height` | `number` | `32` | Height in pixels. The width follows the container. |
|
|
79
|
+
| `label` (required) | `string` | | The trend in words: the metric, the period and its direction ("Revenue, last 30 days: up 12%"). |
|
|
80
|
+
| `width` | `number` | `1.5` | Line width in pixels. |
|
|
81
|
+
|
|
82
|
+
<!-- /generated:props:sparkline -->
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Stacked histogram
|
|
2
|
+
|
|
3
|
+
<!-- search: histogram, log volume, events over time, time buckets, stacked bars, range selection, brush, zoom to range, time window -->
|
|
4
|
+
|
|
5
|
+
Counts per time bucket, stacked by series: the shape of events over time above a log or record list. Drag across the bars, or hold Shift with the arrow keys, to select a range; the selection card's Zoom hands it to `onZoom`, and you set the window. It's SVG and DOM (no canvas, no uPlot), so it renders on the server. The arrow keys read each bucket out.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { StackedHistogram, type HistogramRange } from "@zsherman/charts/stacked-histogram";
|
|
9
|
+
import { createSignal } from "solid-js";
|
|
10
|
+
|
|
11
|
+
const [domain, setDomain] = createSignal<HistogramRange>({ from: start, to: end });
|
|
12
|
+
|
|
13
|
+
<StackedHistogram
|
|
14
|
+
label="4,357 log events by level, per minute; errors spike after 2:52 PM"
|
|
15
|
+
buckets={[
|
|
16
|
+
{ time: Date.UTC(2026, 10, 18, 14, 0), values: { error: 0, warn: 3, info: 27 } },
|
|
17
|
+
{ time: Date.UTC(2026, 10, 18, 14, 1), values: { error: 1, warn: 2, info: 31 } },
|
|
18
|
+
]}
|
|
19
|
+
series={[
|
|
20
|
+
{ key: "error", label: "Errors", color: "var(--sui-danger)" },
|
|
21
|
+
{ key: "warn", label: "Warnings", color: "var(--sui-warning)" },
|
|
22
|
+
{ key: "info", label: "Info", color: "chart-1" },
|
|
23
|
+
]}
|
|
24
|
+
bucketMs={60_000}
|
|
25
|
+
domain={domain()}
|
|
26
|
+
onZoom={setDomain}
|
|
27
|
+
/>;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage guidelines
|
|
31
|
+
|
|
32
|
+
- Use it for event counts over time split by kind, above the list they come from: log lines by level, requests by status, jobs by outcome. It shows the shape and picks a window; the list shows the records.
|
|
33
|
+
- Name it with `label`: the total, what is counted and the takeaway ("4,357 log events by level; errors spike after 2:52 PM").
|
|
34
|
+
- Pass `onZoom` when choosing a window should filter the list: set `domain` to the range it receives, and filter the list the same way. Offer a Reset beside it (zooming back out is yours: set `domain` back).
|
|
35
|
+
- Order `series` bottom to top: the one that matters most (errors) on the baseline, where it's easiest to compare.
|
|
36
|
+
- For a continuous measure (latency, CPU) use a [Chart](./chart.md); for daily counts over months, a [Heat graph](./heat-graph.md); for one service's pass/fail per interval, a [Status history](./status-history.md); for exact counts, a table.
|
|
37
|
+
|
|
38
|
+
## Anatomy
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
<StackedHistogram
|
|
42
|
+
label="…" // required: the plot's accessible name
|
|
43
|
+
buckets={[{ time, values }]} // time: the bucket's start in ms; values: counts by series key
|
|
44
|
+
series={[{ key, label, color }]} // bottom to top; colors default to the chart tokens in order
|
|
45
|
+
bucketMs={60_000} // required: a bucket's width in ms
|
|
46
|
+
domain={{ from, to }} // the window drawn (to exclusive); the buckets' span by default
|
|
47
|
+
height={64} // the bars' height in px
|
|
48
|
+
onZoom={(range) => …} // turns on selection; called with the chosen range
|
|
49
|
+
legend // on by default for two or more series
|
|
50
|
+
timeZone="UTC" // how times are written and where ticks fall
|
|
51
|
+
formatValue={(n) => …} // counts in the tooltip, the card and the readout
|
|
52
|
+
labels={{ zoom, clear, total, selection, keyboardHint, selectHint }}
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
What renders: a root `div` (`data-slot="stacked-histogram"`) with the plot (`stacked-histogram-plot`: `role="application"` with `onZoom`, else `role="img"`, named by `label`) holding an SVG with one `path` per series (`stacked-histogram-series`), the cursor band (`stacked-histogram-band`), the selection (`stacked-histogram-selection`) and the tooltip (`stacked-histogram-tooltip`); then the time axis (`stacked-histogram-axis`), the legend (`stacked-histogram-legend`), the selection card (`stacked-histogram-selection-card`, a `group` named "Selection" with Clear and Zoom buttons) and a polite live region (`stacked-histogram-readout`).
|
|
57
|
+
|
|
58
|
+
## Data
|
|
59
|
+
|
|
60
|
+
- `time` is a bucket's **start in milliseconds** (`Date.UTC(…)`, `date.getTime()`), and `bucketMs` its width in milliseconds: `60_000` for minutes, not `60`.
|
|
61
|
+
- Buckets are sorted oldest first. A missing key, a negative or a non-finite count is drawn as 0.
|
|
62
|
+
- Buckets outside `domain` aren't drawn: pass every bucket and let `domain` choose, or pass only the window's. A gap in the buckets is a gap in the bars.
|
|
63
|
+
- The bars scale to the busiest bucket in the window, so zooming in rescales them.
|
|
64
|
+
|
|
65
|
+
## Zoom and selection
|
|
66
|
+
|
|
67
|
+
With `onZoom`, a press and drag over the bars selects whole buckets; a click selects one. The selection parks: the bars outside it fade, and the selection card under the axis shows its range and each series' sum, with Clear and Zoom. Drag either edge of a parked selection to resize it. Zoom calls `onZoom({ from, to })` (`to` is the end of the last bucket) and drops the selection; set `domain` to it. A selection outlives live updates: it's kept in time, not bucket positions, and clipped to the window.
|
|
68
|
+
|
|
69
|
+
## Keyboard
|
|
70
|
+
|
|
71
|
+
| Key | Action |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| Tab | Into the plot (then to the selection card's buttons). |
|
|
74
|
+
| ← / → | The previous or next bucket: its range and counts are read out, and the tooltip follows. |
|
|
75
|
+
| Home / End | The first or last bucket. |
|
|
76
|
+
| Shift + ← / → / Home / End | Extend a selection from where it started (with `onZoom`). |
|
|
77
|
+
| Enter | Zoom to the selection. |
|
|
78
|
+
| Escape | Clear the selection; again, the cursor. |
|
|
79
|
+
|
|
80
|
+
Time runs left to right in right-to-left text too, as on a chart's axis.
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
- The plot is named by `label` and described by a keyboard hint; with `onZoom` it's an `application`, so screen readers pass the keys through.
|
|
85
|
+
- Each bucket the cursor reaches is read out in a polite live region ("2:00 – 2:01 PM: Errors 0, Warnings 3, Info 27; Total 30"); a selection reads its range and total.
|
|
86
|
+
- Series never rely on color alone: the tooltip, the card and the readout name them, and the legend lists them.
|
|
87
|
+
- Bars keep their colors in forced-colors mode (they're data); the selection and focus ring use system colors.
|
|
88
|
+
- Give the records themselves (the log list) or a table for exact values: the bars show shape.
|
|
89
|
+
|
|
90
|
+
## Words
|
|
91
|
+
|
|
92
|
+
The card's buttons and name, the total row and the keyboard hints take `labels`, or app-wide the kit's `LocaleProvider messages={{ stackedHistogram: { … } }}`. Numbers and times follow `LocaleProvider`'s locale.
|
|
93
|
+
|
|
94
|
+
## Gotchas
|
|
95
|
+
|
|
96
|
+
- Set `timeZone` when the server renders: the server and the browser may sit in different zones and would write different times. Ticks fall on round times in that zone.
|
|
97
|
+
- Keep `buckets`, `series` and `domain` stable between updates (a signal or a memo): a selection is kept across updates, but a new `domain` clips it.
|
|
98
|
+
- Log levels are states: their colors can be the kit's status colors (`var(--sui-danger)`, `var(--sui-warning)`); other series take chart tokens.
|
|
99
|
+
|
|
100
|
+
## API reference
|
|
101
|
+
|
|
102
|
+
<!-- generated:props:stacked-histogram (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
103
|
+
|
|
104
|
+
Generated from the types of `@zsherman/charts/stacked-histogram`. Each part also takes its element's native and ARIA attributes.
|
|
105
|
+
|
|
106
|
+
#### `StackedHistogram`
|
|
107
|
+
|
|
108
|
+
| Prop | Type | Default | Description |
|
|
109
|
+
| --- | --- | --- | --- |
|
|
110
|
+
| `bucketMs` (required) | `number` | | The width of a bucket in milliseconds (`60_000` for minutes). |
|
|
111
|
+
| `buckets` (required) | `readonly HistogramBucket[]` | | One entry per time bucket, oldest first. Buckets outside `domain` aren't drawn. |
|
|
112
|
+
| `class` | `ClassValue` | | Extra classes on the root. |
|
|
113
|
+
| `domain` | `HistogramRange` | | The time window drawn (`to` exclusive). Defaults to the buckets' own span; set it to what `onZoom` chose. |
|
|
114
|
+
| `formatValue` | `((value: number) => string)` | | How a count is written. Defaults to the locale's number format. |
|
|
115
|
+
| `height` | `number` | `64` | The bars' height in pixels. |
|
|
116
|
+
| `label` (required) | `string` | | What is counted, for assistive technology: the total and the measure ("412 log events by level"). |
|
|
117
|
+
| `labels` | `Partial<StackedHistogramLabels>` | | The histogram's words, in your wording or language (app-wide: `LocaleProvider messages.stackedHistogram`). |
|
|
118
|
+
| `legend` | `boolean` | | The series names under the axis. On by default for two or more series. |
|
|
119
|
+
| `onZoom` | `((range: HistogramRange) => void)` | | Called with the range a person selected (by dragging, or Shift with the arrow keys) and chose to zoom to. Without it, the histogram only reads out its buckets. |
|
|
120
|
+
| `series` (required) | `readonly HistogramSeries[]` | | The stacked series, bottom to top: the first sits on the baseline. |
|
|
121
|
+
| `timeZone` | `string` | | The time zone times are written in and ticks fall on (`"UTC"`, `"Europe/Berlin"`). Defaults to the runtime's: set it when the server renders, so server and browser write the same times. |
|
|
122
|
+
|
|
123
|
+
<!-- /generated:props:stacked-histogram -->
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# State timeline
|
|
2
|
+
|
|
3
|
+
<!-- search: state timeline, status timeline, timeline, swimlanes, lanes, gantt, uptime over time, route health, packet loss over time, service states, discrete states, grafana state timeline -->
|
|
4
|
+
|
|
5
|
+
Many rows on one time axis, each a lane of colored states: the loss level of every route over 12 hours, the status of each service over a day, a host's power states. Runs of one state are merged into one segment, so hundreds of readings per row stay light, and a short failure is never drawn thinner than a pixel. A cursor runs through every lane at the pointer, with a tooltip for the row under it; the arrow keys walk rows and segments. It's plain SVG and DOM, so it renders on the server; each row is named with its share of time per state.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { StateTimeline } from "@zsherman/charts/state-timeline";
|
|
9
|
+
|
|
10
|
+
<StateTimeline
|
|
11
|
+
label="Route loss over time, last 12 hours, by route"
|
|
12
|
+
states={[
|
|
13
|
+
{ key: "ok", label: "No loss", tone: "success" },
|
|
14
|
+
{ key: "low", label: "Under 1%", tone: "warning" },
|
|
15
|
+
{ key: "mid", label: "1–5%", color: "chart-2" },
|
|
16
|
+
{ key: "high", label: "Over 5%", tone: "danger" },
|
|
17
|
+
]}
|
|
18
|
+
rows={[
|
|
19
|
+
{
|
|
20
|
+
label: "eu-central → us-east",
|
|
21
|
+
data: [
|
|
22
|
+
{ time: "2026-11-26T02:30:00Z", state: "ok", value: 0 },
|
|
23
|
+
{ time: "2026-11-26T02:31:00Z", state: "high", value: 7.5 },
|
|
24
|
+
{ time: "2026-11-26T02:32:00Z", state: "ok", value: 0 },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
]}
|
|
28
|
+
step={60_000}
|
|
29
|
+
timeZone="UTC"
|
|
30
|
+
formatValue={(v) => `${v}% loss`}
|
|
31
|
+
/>;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage guidelines
|
|
35
|
+
|
|
36
|
+
- Use it for a few to a few dozen things whose state changes over time, when the question is "which ones, and when": route health, service status, deploy stages per environment, machines' states.
|
|
37
|
+
- Name it with `label`: what the rows are, what the states mean, the period.
|
|
38
|
+
- Keep it to a handful of states, listed from calm to severe. Later states draw over earlier ones where a segment is widened to a pixel, so a short failure is never hidden under its neighbours. Map measurements to states yourself (loss over 5% is "high") and keep the measurement in `value` for the tooltip.
|
|
39
|
+
- `step` is how long one reading lasts. With readings at a fixed interval (a probe a minute), set it to the interval: a missing reading leaves a gap. With readings only when the state changes, set it to the longest a reading may stand for (and `range` to the period), and each lasts until the next.
|
|
40
|
+
- For one service's recent health as a strip of equal intervals, use a [Status history](./status-history.md); for values over time, a [Chart](./chart.md); for values between pairs, a [Heat matrix](./heat-matrix.md); for one request's spans as a waterfall, `SpanTimeline` from `@zsherman/kit/span-timeline`.
|
|
41
|
+
|
|
42
|
+
## Anatomy
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<StateTimeline
|
|
46
|
+
label="…" // required: the chart's accessible name
|
|
47
|
+
states={[{ key, label, tone, color }]} // calm to severe
|
|
48
|
+
rows={[{ label, key, data: [{ time, state, value, note, data }] }]}
|
|
49
|
+
step={60_000} // how long a reading lasts (ms); the shortest interval by default
|
|
50
|
+
range={[start, end]} // the period; the readings' by default
|
|
51
|
+
rowHeight={14} rowGap={4}
|
|
52
|
+
ticks={8} // about how many times under the lanes
|
|
53
|
+
timeZone="UTC" // how times are written; the reader's by default
|
|
54
|
+
formatTime={(date) => …} // in the tooltip and readout
|
|
55
|
+
formatValue={(v) => …} // a reading's value in the tooltip
|
|
56
|
+
legend tooltip
|
|
57
|
+
labels={{ keyboardHint, noData, legend, empty }}
|
|
58
|
+
/>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`time` is a `Date`, milliseconds since the epoch, or an ISO string. `state` is a state's `key`, or `null` for a reading with no data (a gap). Without `color` or `tone`, states take the chart colors in order.
|
|
62
|
+
|
|
63
|
+
What renders: a root `div` (`data-slot="state-timeline"`) with the legend (`state-timeline-legend`), the plot (`state-timeline-plot`, a `group` named by `label`, focusable with the tooltip) holding a list of rows (`state-timeline-rows`) whose items (`state-timeline-row`) carry the label (`state-timeline-label`, `data-active` on the active row) and the lane (`state-timeline-lane`, an SVG with one path per state), then the axis (`state-timeline-axis`), the cursor line (`state-timeline-cursor`) and the tooltip (`state-timeline-tooltip`, a manual popover in the top layer). `state-timeline-readout` is the polite live region; `state-timeline-empty` replaces the plot when there are no rows.
|
|
64
|
+
|
|
65
|
+
## Readings, segments and gaps
|
|
66
|
+
|
|
67
|
+
Each reading lasts until the next one, or until `step` has passed, whichever comes first, so a reading that comes late by more than a step leaves a gap. Back-to-back readings in the same state merge into one segment: a row of 720 one-minute readings that's mostly "ok" draws a handful of rectangles, one path per state. Gaps show the lane's muted surface. Segments are clipped to `range`.
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
// Readings only when the state changed: each lasts until the next, up to 10 hours.
|
|
71
|
+
<StateTimeline
|
|
72
|
+
label="Service status, 26 November, 08:00 to 18:00 UTC"
|
|
73
|
+
states={[
|
|
74
|
+
{ key: "up", label: "Operational", tone: "success" },
|
|
75
|
+
{ key: "down", label: "Outage", tone: "danger" },
|
|
76
|
+
]}
|
|
77
|
+
rows={[
|
|
78
|
+
{
|
|
79
|
+
label: "Checkout",
|
|
80
|
+
data: [
|
|
81
|
+
{ time: Date.UTC(2026, 10, 26, 8), state: "up" },
|
|
82
|
+
{ time: Date.UTC(2026, 10, 26, 14, 2), state: "down", note: "Payment provider returned 503" },
|
|
83
|
+
{ time: Date.UTC(2026, 10, 26, 14, 19), state: "up" },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
]}
|
|
87
|
+
step={10 * 60 * 60_000}
|
|
88
|
+
range={[Date.UTC(2026, 10, 26, 8), Date.UTC(2026, 10, 26, 18)]}
|
|
89
|
+
timeZone="UTC"
|
|
90
|
+
/>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Tooltip and cursor
|
|
94
|
+
|
|
95
|
+
Over a lane, a line runs through every lane at the pointer's time and the tooltip shows the row, the time, its state with the reading's `value` (written with `formatValue`) and `note`, and the segment's start, end and length. The tooltip renders in the top layer, so no card or dialog clips it, and stays on screen. `tooltip={false}` turns it off (and the plot stops taking focus).
|
|
96
|
+
|
|
97
|
+
## Accessibility
|
|
98
|
+
|
|
99
|
+
- The rows are a group named by `label`, holding a list. Each row is named with its share of time per state: "Checkout: Operational 97%, Outage 2.8%" (and "No data" for gaps). The lanes, labels and axis are hidden from assistive technology so nothing is read twice.
|
|
100
|
+
- With the tooltip, the plot is focusable: Up and Down choose a row at the same time, Left and Right move to the row's previous or next segment, Home and End to its first and last, Escape clears. The tooltip follows, and a polite live region reads "Checkout: Outage, 2:02 PM – 2:19 PM".
|
|
101
|
+
- Colors aren't the only cue: the legend names each state, the tooltip and the readout say it in words, and each row's name gives the shares.
|
|
102
|
+
- Long row names are cut short with an ellipsis; the full text is in the row's name and a `title`.
|
|
103
|
+
- Time runs left to right in right-to-left text too, as it does on a chart's axis; the labels move to the right.
|
|
104
|
+
|
|
105
|
+
## Words
|
|
106
|
+
|
|
107
|
+
`keyboardHint`, `noData`, `legend` and `empty` take `labels`, or app-wide the kit's `LocaleProvider messages={{ stateTimeline: { … } }}`. Times follow `LocaleProvider`'s locale and `timeZone`.
|
|
108
|
+
|
|
109
|
+
## Gotchas
|
|
110
|
+
|
|
111
|
+
- `time` in milliseconds, not seconds (unlike Chart's x values).
|
|
112
|
+
- `step` defaults to the shortest interval between readings across rows. With readings only on change, that's the shortest change, and every longer stretch would become a gap: set `step` yourself.
|
|
113
|
+
- States are drawn in the order of `states`: list them calm to severe, so the severe ones are on top.
|
|
114
|
+
|
|
115
|
+
## API reference
|
|
116
|
+
|
|
117
|
+
<!-- generated:props:state-timeline (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
118
|
+
|
|
119
|
+
Generated from the types of `@zsherman/charts/state-timeline`. Each part also takes its element's native and ARIA attributes.
|
|
120
|
+
|
|
121
|
+
#### `StateTimeline`
|
|
122
|
+
|
|
123
|
+
| Prop | Type | Default | Description |
|
|
124
|
+
| --- | --- | --- | --- |
|
|
125
|
+
| `class` | `ClassValue` | | Extra classes on the root. |
|
|
126
|
+
| `formatTime` | `((date: Date) => string)` | | How a time is written in the tooltip and the keyboard readout. |
|
|
127
|
+
| `formatValue` | `((value: number) => string)` | | How a sample's `value` is written in the tooltip ("2.4% loss"). |
|
|
128
|
+
| `label` (required) | `string` | | The chart's name for assistive technology: what the rows are, what the states mean, the period. |
|
|
129
|
+
| `labels` | `Partial<StateTimelineLabels>` | | The words, in your wording or language (app-wide: `LocaleProvider messages.stateTimeline`). |
|
|
130
|
+
| `legend` | `boolean` | `true` | The states legend above the lanes. |
|
|
131
|
+
| `range` | `readonly [string \| number \| Date, string \| number \| Date]` | | The period shown, `[start, end]`. Defaults to the first reading to the end of the last. |
|
|
132
|
+
| `rowGap` | `number` | `4` | Space between lanes in pixels. |
|
|
133
|
+
| `rowHeight` | `number` | `14` | Each lane's height in pixels. |
|
|
134
|
+
| `rows` (required) | `readonly StateTimelineRow<T>[]` | | The rows, top to bottom. |
|
|
135
|
+
| `states` (required) | `readonly StateTimelineState[]` | | The states, from calm to severe. Each sample's `state` is one of their keys. |
|
|
136
|
+
| `step` | `number` | | How long one reading lasts, in milliseconds: a reading later than this after the last leaves a gap. Defaults to the shortest interval between readings. |
|
|
137
|
+
| `ticks` | `number` | `8` | About how many times to write under the lanes (round times: every 30 minutes, every hour). |
|
|
138
|
+
| `timeZone` | `string` | | The time zone times are written in ("UTC"). Defaults to the reader's. |
|
|
139
|
+
| `tooltip` | `boolean` | `true` | The tooltip at the pointer, also driven by the keyboard (arrow keys on the focused chart). |
|
|
140
|
+
|
|
141
|
+
<!-- /generated:props:state-timeline -->
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Status history
|
|
2
|
+
|
|
3
|
+
<!-- search: uptime, status page, health check, monitor, availability, incidents, uptime bars, service status -->
|
|
4
|
+
|
|
5
|
+
One bar per check interval, colored by what the check found: healthy, degraded, failed or no data. For the recent health of one service on a monitor card or status page. It's plain DOM, so it renders on the server. It's a grid with one tab stop: the arrow keys move by interval, each bar is named with its time and state, and the tooltip follows both the pointer and the focus.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { StatusHistory } from "@zsherman/charts/status-history";
|
|
9
|
+
|
|
10
|
+
<StatusHistory
|
|
11
|
+
label="Checkout, last 90 hours: 98.9% uptime, 1 failed hour"
|
|
12
|
+
data={[
|
|
13
|
+
{ time: Date.UTC(2026, 10, 18, 16), status: "success" },
|
|
14
|
+
{ time: Date.UTC(2026, 10, 18, 17), status: "error", note: "checkout returned 503 for 14 minutes" },
|
|
15
|
+
{ time: Date.UTC(2026, 10, 18, 18), status: "success" },
|
|
16
|
+
]}
|
|
17
|
+
title="Checkout"
|
|
18
|
+
summary="98.9% uptime"
|
|
19
|
+
startLabel="90 hours ago"
|
|
20
|
+
endLabel="Now"
|
|
21
|
+
/>;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage guidelines
|
|
25
|
+
|
|
26
|
+
- Use it for one service or check over recent intervals, when the question is "was it up, and when wasn't it": a monitor card, a status page row, a list of services.
|
|
27
|
+
- Name it with `label`: what is checked, the period and the result ("Checkout, last 90 hours: 98.9% uptime, 1 failed hour"). Put the uptime in text too (`summary`).
|
|
28
|
+
- Compute the uptime yourself and say how: whether degraded intervals count as up, and whether `unknown` ones count at all.
|
|
29
|
+
- Give failures a `note` ("checkout returned 503 for 14 minutes"): it's read after the time and state, and shown in the tooltip.
|
|
30
|
+
- For many services or routes on one time axis, use a [State timeline](./state-timeline.md); for counts or measurements, a [Chart](./chart.md) or a [Stacked histogram](./stacked-histogram.md); for daily activity over months, a [Heat graph](./heat-graph.md); for one current state, a badge.
|
|
31
|
+
|
|
32
|
+
## Anatomy
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
<StatusHistory
|
|
36
|
+
label="…" // required: the grid's accessible name
|
|
37
|
+
data={[{ time, status, note, data }]} // oldest first; one bar each
|
|
38
|
+
height={32} gap={2} // bar height; space between bars (narrows when tight)
|
|
39
|
+
title summary startLabel endLabel // the four corners: above start/end, below start/end
|
|
40
|
+
axis // dates under the bars
|
|
41
|
+
legend // the states present, with counts
|
|
42
|
+
colors={{ error: "chart-8" }} // per state; the kit's status colors by default
|
|
43
|
+
timeZone="UTC" // how times are written
|
|
44
|
+
formatTime={(date) => …} // an interval's time in its name and tooltip
|
|
45
|
+
onSelectEntry={(entry, index) => …} // click, Enter or Space on a bar
|
|
46
|
+
labels={{ success, degraded, error, unknown }}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
What renders: a root `div` (`data-slot="status-history"`) with the header corners (`status-history-header`), the grid (`status-history-grid`, `role="grid"` named by `label`) with one `row` (`status-history-bars`) of `gridcell` bars (`data-index`, `data-status`), the axis (`status-history-axis`, hidden from assistive technology), the footer corners (`status-history-footer`), the legend (`status-history-legend`) and the tooltip (`status-history-tooltip`). Empty corners take no space.
|
|
51
|
+
|
|
52
|
+
## States
|
|
53
|
+
|
|
54
|
+
| `status` | Means | Default color | Word |
|
|
55
|
+
| --- | --- | --- | --- |
|
|
56
|
+
| `success` | The check ran and met its target. | `--sui-success` | Healthy |
|
|
57
|
+
| `degraded` | It worked but missed a target (slow responses). | `--sui-warning` | Degraded |
|
|
58
|
+
| `error` | It failed, or the service was down. | `--sui-danger` | Failed |
|
|
59
|
+
| `unknown` | No check ran, or no result arrived: says nothing about health. | a faint neutral | No data |
|
|
60
|
+
|
|
61
|
+
`colors` overrides a state's color with a chart token or any CSS color. Bars keep their colors in forced-colors mode (they're data); the focus ring follows the system.
|
|
62
|
+
|
|
63
|
+
## Layout
|
|
64
|
+
|
|
65
|
+
The bars share the root's width; the gap narrows when they run out of room, so 90 bars fit a phone. `time` is a `Date`, milliseconds or an ISO string. Times are written with the clock when intervals are shorter than a day, else as dates; `axis` writes a date under the first interval of each day (up to five), or times within a single day.
|
|
66
|
+
|
|
67
|
+
## Keyboard
|
|
68
|
+
|
|
69
|
+
| Key | Action |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| Tab | Into the grid, on the latest interval (or the last one focused). |
|
|
72
|
+
| ← / → | The previous or next interval (mirrored in right-to-left text). |
|
|
73
|
+
| Home / End | The first or last interval. |
|
|
74
|
+
| Enter, Space | `onSelectEntry` with the focused interval. |
|
|
75
|
+
| Escape | Hide the tooltip. |
|
|
76
|
+
|
|
77
|
+
## Accessibility
|
|
78
|
+
|
|
79
|
+
- The grid is named by `label`; each bar is a `gridcell` named with its time, state and note ("Nov 17, 2026, 9:00 PM: Failed. checkout returned 503 for 14 minutes"), so color is never the only way to read a bar.
|
|
80
|
+
- The tooltip repeats the bar's time, state and note for pointer and keyboard users; it isn't announced.
|
|
81
|
+
- `legend` names the states with their counts: turn it on where people compare services.
|
|
82
|
+
- `onSelectEntry` works from the keyboard too (Enter or Space on the focused bar).
|
|
83
|
+
|
|
84
|
+
## Words
|
|
85
|
+
|
|
86
|
+
The state words take `labels`, or app-wide the kit's `LocaleProvider messages={{ statusHistory: { … } }}`. Dates and numbers follow `LocaleProvider`'s locale.
|
|
87
|
+
|
|
88
|
+
## Gotchas
|
|
89
|
+
|
|
90
|
+
- Set `timeZone` when the server renders, so the server and the browser write the same times.
|
|
91
|
+
- Use `unknown`, not `success`, for intervals with no result: a gap in monitoring isn't uptime.
|
|
92
|
+
- Status colors are for states only: don't reuse them for a chart series that isn't a state.
|
|
93
|
+
|
|
94
|
+
## API reference
|
|
95
|
+
|
|
96
|
+
<!-- generated:props:status-history (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
97
|
+
|
|
98
|
+
Generated from the types of `@zsherman/charts/status-history`. Each part also takes its element's native and ARIA attributes.
|
|
99
|
+
|
|
100
|
+
#### `StatusHistory`
|
|
101
|
+
|
|
102
|
+
| Prop | Type | Default | Description |
|
|
103
|
+
| --- | --- | --- | --- |
|
|
104
|
+
| `axis` | `boolean` | | Dates under the bars, for a long range without `startLabel` and `endLabel`. |
|
|
105
|
+
| `class` | `ClassValue` | | Extra classes on the root. |
|
|
106
|
+
| `colors` | `Partial<Record<StatusState, ChartColor>>` | | Each state's color: a chart token (`chart-1` … `chart-8`) or any CSS color. Defaults to the kit's status colors. |
|
|
107
|
+
| `data` (required) | `readonly StatusEntry<T>[]` | | One entry per interval, oldest first. Each draws one bar; bars are never merged. |
|
|
108
|
+
| `endLabel` | `Element` | | Below the end: where it ends ("Now"). |
|
|
109
|
+
| `formatTime` | `((date: Date) => string)` | | How an interval's time is written in its name and tooltip. Defaults to the locale's date, and time when intervals are shorter than a day. |
|
|
110
|
+
| `gap` | `number` | `2` | Space between bars in pixels (it narrows when the bars run out of room). |
|
|
111
|
+
| `height` | `number` | `32` | The bars' height in pixels. |
|
|
112
|
+
| `label` (required) | `string` | | The history in words, for assistive technology: what is checked, the period and the result. |
|
|
113
|
+
| `labels` | `Partial<StatusHistoryLabels>` | | The status words, in your wording or language (app-wide: `LocaleProvider messages.statusHistory`). |
|
|
114
|
+
| `legend` | `boolean` | | The states shown, each named with its count. |
|
|
115
|
+
| `onSelectEntry` | `((entry: StatusEntry<T>, index: number) => void)` | | Called when a bar is clicked or chosen with Enter or Space: open that interval's details. |
|
|
116
|
+
| `startLabel` | `Element` | | Below the start: where the range begins ("90 hours ago"). |
|
|
117
|
+
| `summary` | `Element` | | Above the end: the result ("99.2% uptime"). |
|
|
118
|
+
| `timeZone` | `string` | | The time zone times are written in (`"UTC"`, `"Europe/Berlin"`). Defaults to the runtime's: set it when the server renders, so server and browser write the same times. |
|
|
119
|
+
| `title` | `Element` | | Above the start: what is checked ("Checkout"). |
|
|
120
|
+
|
|
121
|
+
<!-- /generated:props:status-history -->
|