@zsherman/charts 0.0.0-stage → 0.1.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.
Files changed (180) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +373 -0
  3. package/README.md +13 -2
  4. package/THIRD_PARTY_NOTICES.md +33 -0
  5. package/dist/dom/bar-list/bar-list.js +386 -0
  6. package/dist/dom/bar-list/bar-list.styles.js +171 -0
  7. package/dist/dom/bar-list/index.js +1 -0
  8. package/dist/dom/chart/chart.js +716 -0
  9. package/dist/dom/chart/chart.styles.js +165 -0
  10. package/dist/dom/chart/index.js +1 -0
  11. package/dist/dom/chart-grid/chart-grid.js +67 -0
  12. package/dist/dom/chart-grid/index.js +1 -0
  13. package/dist/dom/donut/donut.js +565 -0
  14. package/dist/dom/donut/donut.styles.js +111 -0
  15. package/dist/dom/donut/index.js +1 -0
  16. package/dist/dom/heat-graph/calendar.js +118 -0
  17. package/dist/dom/heat-graph/heat-graph.js +423 -0
  18. package/dist/dom/heat-graph/heat-graph.styles.js +168 -0
  19. package/dist/dom/heat-graph/index.js +1 -0
  20. package/dist/dom/heat-matrix/heat-matrix.js +346 -0
  21. package/dist/dom/heat-matrix/heat-matrix.styles.js +155 -0
  22. package/dist/dom/heat-matrix/index.js +1 -0
  23. package/dist/dom/heat-matrix/model.js +41 -0
  24. package/dist/dom/index.js +13 -0
  25. package/dist/dom/internal/colors.js +44 -0
  26. package/dist/dom/internal/floating-tip.js +83 -0
  27. package/dist/dom/internal/format.js +43 -0
  28. package/dist/dom/internal/grid-context.js +5 -0
  29. package/dist/dom/internal/hidden.styles.js +16 -0
  30. package/dist/dom/internal/legend.js +112 -0
  31. package/dist/dom/internal/legend.styles.js +108 -0
  32. package/dist/dom/internal/markers.js +101 -0
  33. package/dist/dom/internal/options.js +300 -0
  34. package/dist/dom/internal/place.js +27 -0
  35. package/dist/dom/internal/scheme-watch.js +73 -0
  36. package/dist/dom/internal/share.js +28 -0
  37. package/dist/dom/internal/types.js +0 -0
  38. package/dist/dom/row-chart/index.js +1 -0
  39. package/dist/dom/row-chart/model.js +59 -0
  40. package/dist/dom/row-chart/row-chart.js +691 -0
  41. package/dist/dom/row-chart/row-chart.styles.js +242 -0
  42. package/dist/dom/segmented-bar/index.js +1 -0
  43. package/dist/dom/segmented-bar/segmented-bar.js +280 -0
  44. package/dist/dom/segmented-bar/segmented-bar.styles.js +88 -0
  45. package/dist/dom/sparkline/index.js +1 -0
  46. package/dist/dom/sparkline/sparkline.js +145 -0
  47. package/dist/dom/stacked-histogram/histogram.js +137 -0
  48. package/dist/dom/stacked-histogram/index.js +1 -0
  49. package/dist/dom/stacked-histogram/stacked-histogram.js +761 -0
  50. package/dist/dom/stacked-histogram/stacked-histogram.styles.js +211 -0
  51. package/dist/dom/state-timeline/index.js +1 -0
  52. package/dist/dom/state-timeline/model.js +166 -0
  53. package/dist/dom/state-timeline/state-timeline.js +729 -0
  54. package/dist/dom/state-timeline/state-timeline.styles.js +171 -0
  55. package/dist/dom/status-history/index.js +1 -0
  56. package/dist/dom/status-history/status-history.js +542 -0
  57. package/dist/dom/status-history/status-history.styles.js +171 -0
  58. package/dist/solid/bar-list/bar-list.jsx +139 -0
  59. package/dist/solid/bar-list/bar-list.styles.jsx +171 -0
  60. package/dist/solid/bar-list/index.jsx +1 -0
  61. package/dist/solid/chart/chart.jsx +454 -0
  62. package/dist/solid/chart/chart.styles.jsx +165 -0
  63. package/dist/solid/chart/index.jsx +1 -0
  64. package/dist/solid/chart-grid/chart-grid.jsx +46 -0
  65. package/dist/solid/chart-grid/index.jsx +1 -0
  66. package/dist/solid/donut/donut.jsx +291 -0
  67. package/dist/solid/donut/donut.styles.jsx +111 -0
  68. package/dist/solid/donut/index.jsx +1 -0
  69. package/dist/solid/heat-graph/calendar.jsx +118 -0
  70. package/dist/solid/heat-graph/heat-graph.jsx +228 -0
  71. package/dist/solid/heat-graph/heat-graph.styles.jsx +168 -0
  72. package/dist/solid/heat-graph/index.jsx +1 -0
  73. package/dist/solid/heat-matrix/heat-matrix.jsx +165 -0
  74. package/dist/solid/heat-matrix/heat-matrix.styles.jsx +155 -0
  75. package/dist/solid/heat-matrix/index.jsx +1 -0
  76. package/dist/solid/heat-matrix/model.jsx +41 -0
  77. package/dist/solid/index.jsx +13 -0
  78. package/dist/solid/internal/colors.jsx +44 -0
  79. package/dist/solid/internal/floating-tip.jsx +68 -0
  80. package/dist/solid/internal/format.jsx +43 -0
  81. package/dist/solid/internal/grid-context.jsx +5 -0
  82. package/dist/solid/internal/hidden.styles.jsx +16 -0
  83. package/dist/solid/internal/legend.jsx +35 -0
  84. package/dist/solid/internal/legend.styles.jsx +108 -0
  85. package/dist/solid/internal/markers.jsx +101 -0
  86. package/dist/solid/internal/options.jsx +300 -0
  87. package/dist/solid/internal/place.jsx +27 -0
  88. package/dist/solid/internal/scheme-watch.jsx +73 -0
  89. package/dist/solid/internal/share.jsx +28 -0
  90. package/dist/solid/internal/types.jsx +0 -0
  91. package/dist/solid/row-chart/index.jsx +1 -0
  92. package/dist/solid/row-chart/model.jsx +59 -0
  93. package/dist/solid/row-chart/row-chart.jsx +312 -0
  94. package/dist/solid/row-chart/row-chart.styles.jsx +242 -0
  95. package/dist/solid/segmented-bar/index.jsx +1 -0
  96. package/dist/solid/segmented-bar/segmented-bar.jsx +125 -0
  97. package/dist/solid/segmented-bar/segmented-bar.styles.jsx +88 -0
  98. package/dist/solid/sparkline/index.jsx +1 -0
  99. package/dist/solid/sparkline/sparkline.jsx +88 -0
  100. package/dist/solid/stacked-histogram/histogram.jsx +137 -0
  101. package/dist/solid/stacked-histogram/index.jsx +1 -0
  102. package/dist/solid/stacked-histogram/stacked-histogram.jsx +381 -0
  103. package/dist/solid/stacked-histogram/stacked-histogram.styles.jsx +211 -0
  104. package/dist/solid/state-timeline/index.jsx +1 -0
  105. package/dist/solid/state-timeline/model.jsx +166 -0
  106. package/dist/solid/state-timeline/state-timeline.jsx +387 -0
  107. package/dist/solid/state-timeline/state-timeline.styles.jsx +171 -0
  108. package/dist/solid/status-history/index.jsx +1 -0
  109. package/dist/solid/status-history/status-history.jsx +279 -0
  110. package/dist/solid/status-history/status-history.styles.jsx +171 -0
  111. package/dist/styles.css +1 -0
  112. package/dist/types/bar-list/bar-list.d.ts +91 -0
  113. package/dist/types/bar-list/bar-list.styles.d.ts +148 -0
  114. package/dist/types/bar-list/index.d.ts +3 -0
  115. package/dist/types/chart/chart.d.ts +98 -0
  116. package/dist/types/chart/chart.styles.d.ts +145 -0
  117. package/dist/types/chart/index.d.ts +3 -0
  118. package/dist/types/chart-grid/chart-grid.d.ts +35 -0
  119. package/dist/types/chart-grid/index.d.ts +2 -0
  120. package/dist/types/donut/donut.d.ts +124 -0
  121. package/dist/types/donut/donut.styles.d.ts +96 -0
  122. package/dist/types/donut/index.d.ts +3 -0
  123. package/dist/types/heat-graph/calendar.d.ts +61 -0
  124. package/dist/types/heat-graph/heat-graph.d.ts +82 -0
  125. package/dist/types/heat-graph/heat-graph.styles.d.ts +141 -0
  126. package/dist/types/heat-graph/index.d.ts +4 -0
  127. package/dist/types/heat-matrix/heat-matrix.d.ts +65 -0
  128. package/dist/types/heat-matrix/heat-matrix.styles.d.ts +135 -0
  129. package/dist/types/heat-matrix/index.d.ts +3 -0
  130. package/dist/types/heat-matrix/model.d.ts +15 -0
  131. package/dist/types/index.d.ts +12 -0
  132. package/dist/types/internal/colors.d.ts +22 -0
  133. package/dist/types/internal/floating-tip.d.ts +15 -0
  134. package/dist/types/internal/format.d.ts +7 -0
  135. package/dist/types/internal/grid-context.d.ts +9 -0
  136. package/dist/types/internal/hidden.styles.d.ts +15 -0
  137. package/dist/types/internal/legend.d.ts +18 -0
  138. package/dist/types/internal/legend.styles.d.ts +96 -0
  139. package/dist/types/internal/markers.d.ts +16 -0
  140. package/dist/types/internal/options.d.ts +59 -0
  141. package/dist/types/internal/place.d.ts +20 -0
  142. package/dist/types/internal/scheme-watch.d.ts +12 -0
  143. package/dist/types/internal/share.d.ts +19 -0
  144. package/dist/types/internal/types.d.ts +163 -0
  145. package/dist/types/row-chart/index.d.ts +4 -0
  146. package/dist/types/row-chart/model.d.ts +50 -0
  147. package/dist/types/row-chart/row-chart.d.ts +148 -0
  148. package/dist/types/row-chart/row-chart.styles.d.ts +216 -0
  149. package/dist/types/segmented-bar/index.d.ts +3 -0
  150. package/dist/types/segmented-bar/segmented-bar.d.ts +65 -0
  151. package/dist/types/segmented-bar/segmented-bar.styles.d.ts +75 -0
  152. package/dist/types/sparkline/index.d.ts +3 -0
  153. package/dist/types/sparkline/sparkline.d.ts +38 -0
  154. package/dist/types/stacked-histogram/histogram.d.ts +48 -0
  155. package/dist/types/stacked-histogram/index.d.ts +4 -0
  156. package/dist/types/stacked-histogram/stacked-histogram.d.ts +73 -0
  157. package/dist/types/stacked-histogram/stacked-histogram.styles.d.ts +187 -0
  158. package/dist/types/state-timeline/index.d.ts +3 -0
  159. package/dist/types/state-timeline/model.d.ts +63 -0
  160. package/dist/types/state-timeline/state-timeline.d.ts +108 -0
  161. package/dist/types/state-timeline/state-timeline.styles.d.ts +151 -0
  162. package/dist/types/status-history/index.d.ts +3 -0
  163. package/dist/types/status-history/status-history.d.ts +72 -0
  164. package/dist/types/status-history/status-history.styles.d.ts +150 -0
  165. package/docs/api.json +1346 -0
  166. package/docs/bar-list.md +190 -0
  167. package/docs/chart-grid.md +77 -0
  168. package/docs/chart.md +355 -0
  169. package/docs/donut.md +182 -0
  170. package/docs/heat-graph.md +121 -0
  171. package/docs/heat-matrix.md +108 -0
  172. package/docs/llms.txt +68 -0
  173. package/docs/row-chart.md +193 -0
  174. package/docs/search-index.json +291 -0
  175. package/docs/segmented-bar.md +128 -0
  176. package/docs/sparkline.md +82 -0
  177. package/docs/stacked-histogram.md +123 -0
  178. package/docs/state-timeline.md +141 -0
  179. package/docs/status-history.md +121 -0
  180. package/package.json +109 -4
@@ -0,0 +1,381 @@
1
+ import { cssColor } from "../internal/colors.jsx";
2
+ import { barPaths, extent, indexAt, sums, timeTicks, visibleBuckets } from "./histogram.jsx";
3
+ import { styles } from "./stacked-histogram.styles.jsx";
4
+ import * as stylex from "@stylexjs/stylex";
5
+ import { Button } from "@zsherman/kit/button";
6
+ import { useLocale, useMessages } from "@zsherman/kit/locale-provider";
7
+ import { For, Show, createMemo, createSignal, createUniqueId, omit, onSettled } from "solid-js";
8
+ // src/stacked-histogram/stacked-histogram.tsx
9
+ const DEFAULT_LABELS = {
10
+ zoom: "Zoom",
11
+ clear: "Clear",
12
+ total: "Total",
13
+ selection: "Selection",
14
+ keyboardHint: "Use the left and right arrow keys to read each bucket.",
15
+ selectHint: "Hold Shift with the arrow keys to select a range, Enter to zoom to it, Escape to clear it."
16
+ };
17
+ /** A grab handle: how near a selection's edge, in pixels, a press drags that edge. */
18
+ const EDGE = 8;
19
+ /**
20
+ * Counts per time bucket, stacked by series, for the shape of events over time above a log or record list.
21
+ * Drag across the bars, or hold Shift with the arrow keys, to select a range and zoom the window to it. SVG
22
+ * drawn on the server; the arrow keys read each bucket out.
23
+ *
24
+ * @example
25
+ * <StackedHistogram label="412 log events by level" buckets={buckets} series={levels} bucketMs={60_000} />
26
+ */
27
+ function StackedHistogram(props) {
28
+ const rest = omit(props, "label", "buckets", "series", "bucketMs", "domain", "height", "onZoom", "legend", "timeZone", "formatValue", "labels", "class");
29
+ const id = createUniqueId();
30
+ const locale = useLocale();
31
+ const messages = useMessages("stackedHistogram");
32
+ const text = (k) => props.labels?.[k] ?? messages()?.[k] ?? DEFAULT_LABELS[k];
33
+ const height = () => props.height ?? 64;
34
+ const step = () => Math.max(1, props.bucketMs);
35
+ const domain = createMemo(() => props.domain ?? extent(props.buckets, step()) ?? {
36
+ from: 0,
37
+ to: step()
38
+ });
39
+ const shown = createMemo(() => visibleBuckets(props.buckets, domain()));
40
+ const keys = createMemo(() => props.series.map((s) => s.key));
41
+ const shape = createMemo(() => barPaths(shown(), keys(), domain(), step(), height()));
42
+ const colorOf = (i) => cssColor(props.series[i]?.color, i);
43
+ const number = createMemo(() => new Intl.NumberFormat(locale()));
44
+ const value = (n) => props.formatValue ? props.formatValue(n) : number().format(n);
45
+ const span = () => domain().to - domain().from;
46
+ /** A time as a percentage across the plot. */
47
+ const at = (t) => (t - domain().from) / span() * 100;
48
+ const [width, setWidth] = createSignal(640);
49
+ const ticks = createMemo(() => {
50
+ const { step: tickStep, ticks: list } = timeTicks(domain(), Math.max(2, Math.floor(width() / 88)), props.timeZone);
51
+ const long = span() > 864e5;
52
+ const time = new Intl.DateTimeFormat(locale(), {
53
+ timeZone: props.timeZone,
54
+ hour: "numeric",
55
+ minute: "2-digit",
56
+ ...tickStep < 6e4 ? { second: "2-digit" } : {}
57
+ });
58
+ const date = new Intl.DateTimeFormat(locale(), {
59
+ month: "short",
60
+ day: "numeric",
61
+ timeZone: props.timeZone
62
+ });
63
+ return list.map((t) => ({
64
+ left: at(t.time),
65
+ text: t.day && long || tickStep >= 864e5 ? date.format(t.time) : time.format(t.time)
66
+ })).filter((t) => t.left >= 4 && t.left <= 96);
67
+ });
68
+ const formatRange = createMemo(() => {
69
+ const opts = step() >= 864e5 ? { dateStyle: "medium" } : span() > 864e5 ? {
70
+ month: "short",
71
+ day: "numeric",
72
+ hour: "numeric",
73
+ minute: "2-digit"
74
+ } : {
75
+ hour: "numeric",
76
+ minute: "2-digit",
77
+ ...step() < 6e4 ? { second: "2-digit" } : {}
78
+ };
79
+ const f = new Intl.DateTimeFormat(locale(), {
80
+ ...opts,
81
+ timeZone: props.timeZone
82
+ });
83
+ return (a, b) => f.formatRange(a, b);
84
+ });
85
+ const [cursor, setCursor] = createSignal(null);
86
+ const [anchor, setAnchor] = createSignal(null);
87
+ const [selected, setSelected] = createSignal(null);
88
+ const [drag, setDrag] = createSignal(null);
89
+ const [readout, setReadout] = createSignal("");
90
+ const indexOfTime = (t) => t === null ? -1 : indexAt(shown(), t);
91
+ const cursorIndex = createMemo(() => {
92
+ const t = cursor();
93
+ const i = indexOfTime(t);
94
+ return i >= 0 && t !== null && shown()[i].time === t ? i : -1;
95
+ });
96
+ const rangeOf = (a, b) => {
97
+ const list = shown();
98
+ const lo = list[Math.min(a, b)];
99
+ const hi = list[Math.max(a, b)];
100
+ return lo && hi ? {
101
+ from: lo.time,
102
+ to: hi.time + step()
103
+ } : null;
104
+ };
105
+ /** The selection on screen: a drag in progress, or the parked range clipped to the window. */
106
+ const selection = createMemo(() => {
107
+ const d = drag();
108
+ if (d) return rangeOf(indexOfTime(d.anchor), indexOfTime(d.head));
109
+ const s = selected();
110
+ if (!s) return null;
111
+ const from = Math.max(s.from, domain().from);
112
+ const to = Math.min(s.to, domain().to);
113
+ return from < to && shown().some((b) => b.time >= from && b.time < to) ? {
114
+ from,
115
+ to
116
+ } : null;
117
+ });
118
+ const selectionIndexes = () => {
119
+ const s = selection();
120
+ if (!s) return null;
121
+ return [indexAt(shown(), s.from), indexAt(shown(), s.to - 1)];
122
+ };
123
+ let plot;
124
+ onSettled(() => {
125
+ const observer = new ResizeObserver(([entry]) => {
126
+ if (entry && entry.contentRect.width > 0) setWidth(entry.contentRect.width);
127
+ });
128
+ observer.observe(plot);
129
+ return () => observer.disconnect();
130
+ });
131
+ const bucketText = (i) => {
132
+ const b = shown()[i];
133
+ if (!b) return "";
134
+ const parts = props.series.map((s, k) => `${s.label} ${value(sums(shown(), keys(), i, i)[k])}`);
135
+ const total = sums(shown(), keys(), i, i).reduce((a, v) => a + v, 0);
136
+ return `${formatRange()(b.time, b.time + step())}: ${parts.join(", ")}; ${text("total")} ${value(total)}`;
137
+ };
138
+ const selectionText = (r) => {
139
+ const [a, b] = [indexAt(shown(), r.from), indexAt(shown(), r.to - 1)];
140
+ const total = sums(shown(), keys(), a, b).reduce((x, v) => x + v, 0);
141
+ return `${text("selection")} ${formatRange()(r.from, r.to)}: ${text("total")} ${value(total)}`;
142
+ };
143
+ const indexFromPointer = (event) => {
144
+ const box = plot.getBoundingClientRect();
145
+ const t = domain().from + Math.min(1, Math.max(0, (event.clientX - box.left) / Math.max(1, box.width))) * span();
146
+ return indexAt(shown(), t);
147
+ };
148
+ function onPointerDown(event) {
149
+ if (!props.onZoom || event.button !== 0 || drag() || !shown().length) return;
150
+ const i = indexFromPointer(event);
151
+ if (i < 0) return;
152
+ let from = i;
153
+ const s = selection();
154
+ if (s) {
155
+ const box = plot.getBoundingClientRect();
156
+ const x = event.clientX - box.left;
157
+ const left = at(s.from) / 100 * box.width;
158
+ const right = at(s.to) / 100 * box.width;
159
+ const [a, b] = selectionIndexes();
160
+ if (Math.abs(x - left) <= EDGE) from = b;
161
+ else if (Math.abs(x - right) <= EDGE) from = a;
162
+ }
163
+ plot.setPointerCapture(event.pointerId);
164
+ setDrag({
165
+ pointerId: event.pointerId,
166
+ anchor: shown()[from].time,
167
+ head: shown()[i].time
168
+ });
169
+ event.preventDefault();
170
+ }
171
+ function onPointerMove(event) {
172
+ const i = indexFromPointer(event);
173
+ if (i < 0) return;
174
+ const t = shown()[i].time;
175
+ const d = drag();
176
+ if (d && d.pointerId === event.pointerId) {
177
+ if (d.head !== t) setDrag({
178
+ ...d,
179
+ head: t
180
+ });
181
+ }
182
+ if (cursor() !== t) setCursor(t);
183
+ }
184
+ function endDrag(event) {
185
+ const d = drag();
186
+ if (!d || d.pointerId !== event.pointerId) return;
187
+ const r = rangeOf(indexOfTime(d.anchor), indexOfTime(d.head));
188
+ setDrag(null);
189
+ setSelected(r);
190
+ setAnchor(d.anchor);
191
+ if (r) setReadout(selectionText(r));
192
+ }
193
+ function zoom() {
194
+ const s = selection();
195
+ if (!s || !props.onZoom) return;
196
+ setSelected(null);
197
+ setAnchor(null);
198
+ setCursor(null);
199
+ props.onZoom(s);
200
+ }
201
+ function clear() {
202
+ setSelected(null);
203
+ setAnchor(null);
204
+ setReadout("");
205
+ plot.focus();
206
+ }
207
+ function onKeyDown(event) {
208
+ const list = shown();
209
+ if (!list.length) return;
210
+ const last = list.length - 1;
211
+ const i = cursorIndex();
212
+ let next;
213
+ switch (event.key) {
214
+ case "ArrowRight":
215
+ next = i < 0 ? 0 : Math.min(last, i + 1);
216
+ break;
217
+ case "ArrowLeft":
218
+ next = i < 0 ? last : Math.max(0, i - 1);
219
+ break;
220
+ case "Home":
221
+ next = 0;
222
+ break;
223
+ case "End":
224
+ next = last;
225
+ break;
226
+ case "Enter":
227
+ if (!selection()) return;
228
+ event.preventDefault();
229
+ zoom();
230
+ return;
231
+ case "Escape":
232
+ if (selection()) {
233
+ event.preventDefault();
234
+ clear();
235
+ } else if (i >= 0) {
236
+ event.preventDefault();
237
+ setCursor(null);
238
+ setReadout("");
239
+ }
240
+ return;
241
+ default: return;
242
+ }
243
+ event.preventDefault();
244
+ setCursor(list[next].time);
245
+ if (event.shiftKey && props.onZoom) {
246
+ const from = anchor() ?? list[i < 0 ? next : i].time;
247
+ setAnchor(from);
248
+ const r = rangeOf(indexOfTime(from), next);
249
+ setSelected(r);
250
+ if (r) setReadout(selectionText(r));
251
+ } else setReadout(bucketText(next));
252
+ }
253
+ const tip = createMemo(() => {
254
+ const i = cursorIndex();
255
+ const b = shown()[i];
256
+ if (!b || drag()) return null;
257
+ const center = at(b.time + step() / 2);
258
+ return {
259
+ index: i,
260
+ center,
261
+ flip: center > 60
262
+ };
263
+ });
264
+ const totals = (a, b) => sums(shown(), keys(), a, b);
265
+ const Rows = (p) => {
266
+ const t = () => totals(p.a, p.b);
267
+ return <>
268
+ <For each={props.series}>
269
+ {(s, k) => <div {...stylex.attrs(styles.row)}>
270
+ <span aria-hidden="true" {...stylex.attrs(styles.swatch)} style={{ "--swatch": colorOf(k()) }} />
271
+ <span {...stylex.attrs(styles.rowLabel)}>{s.label}</span>
272
+ <span {...stylex.attrs(styles.value)}>{value(t()[k()] ?? 0)}</span>
273
+ </div>}
274
+ </For>
275
+ <Show when={props.series.length > 1}>
276
+ <div {...stylex.attrs(styles.row, styles.total)}>
277
+ <span {...stylex.attrs(styles.rowLabel)}>{text("total")}</span>
278
+ <span {...stylex.attrs(styles.value)}>{value(t().reduce((x, v) => x + v, 0))}</span>
279
+ </div>
280
+ </Show>
281
+ </>;
282
+ };
283
+ const empty = () => shown().length === 0;
284
+ const legendOn = () => props.legend ?? props.series.length > 1;
285
+ return <div {...rest} data-slot="stacked-histogram" class={[stylex.props(styles.root).className, props.class]}>
286
+ <div ref={(el) => plot = el} data-slot="stacked-histogram-plot" role={props.onZoom ? "application" : "img"} aria-label={props.label} aria-describedby={empty() ? void 0 : `${id}-keys`} tabindex={empty() ? void 0 : 0} data-empty={empty() ? "" : void 0} {...stylex.attrs(styles.plot, props.onZoom && styles.selectable)} style={{ height: `${height()}px` }} onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={endDrag} onLostPointerCapture={endDrag} onPointerCancel={(e) => {
287
+ if (drag()?.pointerId === e.pointerId) setDrag(null);
288
+ }} onPointerLeave={() => {
289
+ if (!drag()) setCursor(null);
290
+ }} onKeyDown={onKeyDown} onBlur={() => setReadout("")}>
291
+ <Show when={tip()}>
292
+ {(t) => <span aria-hidden="true" data-slot="stacked-histogram-band" {...stylex.attrs(styles.band)} style={{
293
+ left: `${at(shown()[t().index].time)}%`,
294
+ width: `${step() / span() * 100}%`
295
+ }} />}
296
+ </Show>
297
+ <svg aria-hidden="true" viewBox={`0 0 ${shape().width} ${height()}`} preserveAspectRatio="none" {...stylex.attrs(styles.svg)}>
298
+ {}
299
+ <For each={props.series}>
300
+ {(_s, i) => <path data-slot="stacked-histogram-series" d={shape().paths[i()]} style={{ fill: colorOf(i()) }} />}
301
+ </For>
302
+ </svg>
303
+ <Show when={selection()}>
304
+ {(s) => <>
305
+ <span aria-hidden="true" {...stylex.attrs(styles.scrim)} style={{
306
+ left: 0,
307
+ width: `${at(s().from)}%`
308
+ }} />
309
+ <span aria-hidden="true" {...stylex.attrs(styles.scrim)} style={{
310
+ left: `${at(s().to)}%`,
311
+ right: 0
312
+ }} />
313
+ <span aria-hidden="true" data-slot="stacked-histogram-selection" {...stylex.attrs(styles.selection)} style={{
314
+ left: `${at(s().from)}%`,
315
+ width: `${at(s().to) - at(s().from)}%`
316
+ }} />
317
+ <span aria-hidden="true" {...stylex.attrs(styles.handle)} style={{ left: `${at(s().from)}%` }} />
318
+ <span aria-hidden="true" {...stylex.attrs(styles.handle)} style={{ left: `${at(s().to)}%` }} />
319
+ </>}
320
+ </Show>
321
+ <Show when={!selection() && tip()}>
322
+ {(t) => <div aria-hidden="true" data-slot="stacked-histogram-tooltip" {...stylex.attrs(styles.panel, styles.tooltip)} style={{
323
+ left: `${t().center}%`,
324
+ transform: `translateX(${t().flip ? "calc(-100% - 12px)" : "12px"})`
325
+ }}>
326
+ <div {...stylex.attrs(styles.heading)}>
327
+ {formatRange()(shown()[t().index].time, shown()[t().index].time + step())}
328
+ </div>
329
+ <Rows a={t().index} b={t().index} />
330
+ </div>}
331
+ </Show>
332
+ </div>
333
+ <div aria-hidden="true" data-slot="stacked-histogram-axis" {...stylex.attrs(styles.axis)}>
334
+ {}
335
+ <For each={ticks()} keyed={false}>
336
+ {(t) => <span {...stylex.attrs(styles.tick)} style={{ left: `${t().left}%` }}>
337
+ {t().text}
338
+ </span>}
339
+ </For>
340
+ </div>
341
+ <Show when={legendOn()}>
342
+ <ul data-slot="stacked-histogram-legend" {...stylex.attrs(styles.legend)}>
343
+ <For each={props.series}>
344
+ {(s, i) => <li {...stylex.attrs(styles.legendItem)}>
345
+ <span aria-hidden="true" {...stylex.attrs(styles.swatch)} style={{ "--swatch": colorOf(i()) }} />
346
+ {s.label}
347
+ </li>}
348
+ </For>
349
+ </ul>
350
+ </Show>
351
+ <Show when={!drag() && selection()}>
352
+ {(s) => {
353
+ const center = () => (at(s().from) + at(s().to)) / 2;
354
+ const align = () => center() < 25 ? "start" : center() > 75 ? "end" : "center";
355
+ return <div role="group" aria-label={text("selection")} data-slot="stacked-histogram-selection-card" {...stylex.attrs(styles.panel)} style={{
356
+ top: `${height() + 22}px`,
357
+ left: align() === "start" ? `${at(s().from)}%` : align() === "end" ? `${at(s().to)}%` : `${center()}%`,
358
+ transform: `translateX(${align() === "start" ? "0" : align() === "end" ? "-100%" : "-50%"})`
359
+ }}>
360
+ <div {...stylex.attrs(styles.heading)}>{formatRange()(s().from, s().to)}</div>
361
+ <Rows a={selectionIndexes()[0]} b={selectionIndexes()[1]} />
362
+ <div {...stylex.attrs(styles.actions)}>
363
+ <Button size="sm" variant="ghost" onClick={clear}>
364
+ {text("clear")}
365
+ </Button>
366
+ <Button size="sm" variant="primary" onClick={zoom}>
367
+ {text("zoom")}
368
+ </Button>
369
+ </div>
370
+ </div>;
371
+ }}
372
+ </Show>
373
+ <span id={`${id}-keys`} {...stylex.attrs(styles.visuallyHidden)}>
374
+ {props.onZoom ? `${text("keyboardHint")} ${text("selectHint")}` : text("keyboardHint")}
375
+ </span>
376
+ <span data-slot="stacked-histogram-readout" aria-live="polite" {...stylex.attrs(styles.visuallyHidden)}>
377
+ {readout()}
378
+ </span>
379
+ </div>;
380
+ }
381
+ export { StackedHistogram };
@@ -0,0 +1,211 @@
1
+ import "@stylexjs/stylex";
2
+ // src/stacked-histogram/stacked-histogram.styles.ts
3
+ const styles = {
4
+ root: {
5
+ kVAEAm: "x1n2onr6",
6
+ kB7OPa: "x9f619",
7
+ k1xSpc: "x78zum5",
8
+ kXwgrk: "xdt5ytf",
9
+ kOIVth: "xz09phk",
10
+ k7Eaqz: "xeuugli",
11
+ kMv6JI: "x13rcfk",
12
+ kMwMTN: "x1yjpjgc",
13
+ $$css: true
14
+ },
15
+ plot: {
16
+ kVAEAm: "x1n2onr6",
17
+ kB7OPa: "x9f619",
18
+ k7Eaqz: "xeuugli",
19
+ ksoyAI: "xzt5al7",
20
+ kt9PQ7: "xso031l",
21
+ kfdmCh: "x1q0q8m5",
22
+ kL6WhQ: "x9b9q96",
23
+ kFalU9: "xx69xxh",
24
+ kfSwDN: "x87ps6o",
25
+ k3XXqK: "x1t137rt x9v5kkp",
26
+ kMeerF: "x1de99jn",
27
+ kInvED: "x1hl8ikr",
28
+ kjBf7l: "xi1ptex x1x84bn5",
29
+ kaIpWk: "x1nj7uno",
30
+ $$css: true
31
+ },
32
+ selectable: {
33
+ kkrTdU: "xsid9ct",
34
+ $$css: true
35
+ },
36
+ svg: {
37
+ kVAEAm: "x10l6tqk",
38
+ kpwlN0: "x10a8y8t",
39
+ k1xSpc: "x1lliihq",
40
+ kzqmXN: "xh8yej3",
41
+ kZKoxP: "x5yr21d",
42
+ kVQacm: "x1rea2x4",
43
+ kAXs8y: "x1kzknox",
44
+ $$css: true
45
+ },
46
+ band: {
47
+ kVAEAm: "x10l6tqk",
48
+ k87sOh: "x13vifvy",
49
+ krVfgx: "x1ey2m1c",
50
+ kWkggS: "x1t2kxjd",
51
+ kfzvcC: "x47corl",
52
+ $$css: true
53
+ },
54
+ scrim: {
55
+ kVAEAm: "x10l6tqk",
56
+ k87sOh: "x13vifvy",
57
+ krVfgx: "x1ey2m1c",
58
+ kWkggS: "xhb7yn7",
59
+ kfzvcC: "x47corl",
60
+ $$css: true
61
+ },
62
+ selection: {
63
+ kVAEAm: "x10l6tqk",
64
+ k87sOh: "x13vifvy",
65
+ krVfgx: "x1ey2m1c",
66
+ kB7OPa: "x9f619",
67
+ kMzoRj: "xmkeg23",
68
+ ksu8eU: "x1y0btm7",
69
+ kVAM5u: "xqa1mra x1n2ykn",
70
+ kaIpWk: "x1cum3z5",
71
+ kWkggS: "xxrc88",
72
+ kfzvcC: "x47corl",
73
+ $$css: true
74
+ },
75
+ handle: {
76
+ kVAEAm: "x10l6tqk",
77
+ k87sOh: "xwa60dl",
78
+ kzqmXN: "x51ohtg",
79
+ kZKoxP: "x1v9usgg",
80
+ kaIpWk: "x1cum3z5",
81
+ kWkggS: "xllakjs x1jzqe4",
82
+ k3aq6I: "x11lhmoz",
83
+ kkrTdU: "x7eptgl",
84
+ $$css: true
85
+ },
86
+ axis: {
87
+ kVAEAm: "x1n2onr6",
88
+ kZKoxP: "x1l36t39",
89
+ ksoyAI: "xzt5al7",
90
+ kGuDYH: "xb5fjo1",
91
+ kLWn49: "xl2ypbo",
92
+ kMwMTN: "xe2mk2a",
93
+ kcqcaj: "xss6m8b",
94
+ kVQacm: "xb3r6kr",
95
+ $$css: true
96
+ },
97
+ tick: {
98
+ kVAEAm: "x10l6tqk",
99
+ k87sOh: "x13vifvy",
100
+ khDVqt: "xuxw1ft",
101
+ k3aq6I: "xuuh30",
102
+ $$css: true
103
+ },
104
+ legend: {
105
+ k1xSpc: "x78zum5",
106
+ kwnvtZ: "x1a02dak",
107
+ kOIVth: "xgtrjx6",
108
+ kogj98: "x1ghz6dp",
109
+ keoZOQ: "x108si3",
110
+ kmVPX3: "x1717udv",
111
+ kB88ic: "xe8uvvx",
112
+ kGuDYH: "xb5fjo1",
113
+ kLWn49: "xau0z5x",
114
+ k63SB2: "x1vmg6u2",
115
+ kMwMTN: "x1yjpjgc",
116
+ $$css: true
117
+ },
118
+ legendItem: {
119
+ k1xSpc: "x3nfvp2",
120
+ kGNEyG: "x6s0dn4",
121
+ kOIVth: "x1xuqxfr",
122
+ $$css: true
123
+ },
124
+ swatch: {
125
+ kmuXW: "x2lah0s",
126
+ k1xSpc: "x1rg5ohu",
127
+ kzqmXN: "x1e7hgle",
128
+ kZKoxP: "x1qa65zt",
129
+ kaIpWk: "x1cum3z5",
130
+ kWkggS: "xrmkqiu",
131
+ kAXs8y: "x1kzknox",
132
+ $$css: true
133
+ },
134
+ panel: {
135
+ kVAEAm: "x10l6tqk",
136
+ kY2c9j: "x1vjfegm",
137
+ k87sOh: "x13vifvy",
138
+ kbCHJM: "xu96u03",
139
+ kB7OPa: "x9f619",
140
+ k1xSpc: "xrvj5dj",
141
+ kOIVth: "xz09phk",
142
+ k7Eaqz: "x1ag9ea8",
143
+ ks0D6T: "xuj78ke",
144
+ k8WAf4: "xqy2vlu",
145
+ kg3NbH: "xxobuei",
146
+ kWkggS: "xm9f0jk",
147
+ kMwMTN: "x1yjpjgc",
148
+ kMzoRj: "xmkeg23",
149
+ ksu8eU: "x1y0btm7",
150
+ kVAM5u: "x1wpxzwl x1w1tqly",
151
+ kaIpWk: "x1ttroej",
152
+ kGVxlE: "xfw8du2",
153
+ kGuDYH: "xb5fjo1",
154
+ kLWn49: "xau0z5x",
155
+ khDVqt: "xuxw1ft",
156
+ $$css: true
157
+ },
158
+ tooltip: {
159
+ kfzvcC: "x47corl",
160
+ $$css: true
161
+ },
162
+ heading: {
163
+ kMwMTN: "xe2mk2a",
164
+ k63SB2: "x1vmg6u2",
165
+ $$css: true
166
+ },
167
+ row: {
168
+ k1xSpc: "x78zum5",
169
+ kGNEyG: "x6s0dn4",
170
+ kOIVth: "x8rwxmg",
171
+ $$css: true
172
+ },
173
+ rowLabel: {
174
+ kzQI83: "x1iyjqo2",
175
+ kMwMTN: "xe2mk2a",
176
+ $$css: true
177
+ },
178
+ total: {
179
+ kLKAdn: "xmudmli",
180
+ kEafiO: "x178xt8z",
181
+ kPef9Z: "x13fuv20",
182
+ kLZC3w: "x8diiv1",
183
+ $$css: true
184
+ },
185
+ value: {
186
+ kcqcaj: "xss6m8b",
187
+ k63SB2: "x1vmg6u2",
188
+ kMwMTN: "x1yjpjgc",
189
+ $$css: true
190
+ },
191
+ actions: {
192
+ k1xSpc: "x78zum5",
193
+ kjj79g: "x13a6bvl",
194
+ kOIVth: "xz09phk",
195
+ kLKAdn: "xmudmli",
196
+ $$css: true
197
+ },
198
+ visuallyHidden: {
199
+ kVAEAm: "x10l6tqk",
200
+ kzqmXN: "x1i1rx1s",
201
+ kZKoxP: "xjm9jq1",
202
+ kogj98: "xkdpibf",
203
+ kmVPX3: "x1717udv",
204
+ kVQacm: "xb3r6kr",
205
+ kMcinP: "xeh89do",
206
+ khDVqt: "xuxw1ft",
207
+ kMzoRj: "xc342km",
208
+ $$css: true
209
+ }
210
+ };
211
+ export { styles };
@@ -0,0 +1 @@
1
+ export { StateTimeline } from "./state-timeline.jsx";