@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.
Files changed (180) hide show
  1. package/CHANGELOG.md +7 -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 +104 -4
@@ -0,0 +1,454 @@
1
+ import { backdrop, createResolver, cssColor, wash } from "../internal/colors.jsx";
2
+ import { numberFormat, valueFormat, xFormat } from "../internal/format.jsx";
3
+ import { useChartGrid } from "../internal/grid-context.jsx";
4
+ import { watchScheme } from "../internal/scheme-watch.jsx";
5
+ import { markersPlugin } from "../internal/markers.jsx";
6
+ import { FloatingTip } from "../internal/floating-tip.jsx";
7
+ import { buildOptions, stackData } from "../internal/options.jsx";
8
+ import { styles } from "./chart.styles.jsx";
9
+ import * as stylex from "@stylexjs/stylex";
10
+ import { useLocale, useMessages } from "@zsherman/kit/locale-provider";
11
+ import { DEV, For, Show, createEffect, createMemo, createSignal, createUniqueId, omit, onSettled } from "solid-js";
12
+ import uPlot from "uplot";
13
+ // src/chart/chart.tsx
14
+ const DEFAULT_HEIGHT = 240;
15
+ /**
16
+ * Move the cursor and publish it, so charts sharing it (a ChartGrid) follow the keyboard too. uPlot's
17
+ * `setCursor` takes a third `pub` argument its type declarations leave out.
18
+ */
19
+ const moveCursor = (u, left, top) => u.setCursor({
20
+ left,
21
+ top
22
+ }, true, true);
23
+ const swatchStyle = (css) => ({ "--swatch": css });
24
+ /**
25
+ * A canvas chart for values over time or across categories: lines, areas and bars, grouped or stacked,
26
+ * with a tooltip, a legend that toggles series, drag to zoom and live data. Built on uPlot and themed with
27
+ * the kit's tokens (`--sui-chart-1` … `-8`); the plot is a named image whose values the keyboard reads out.
28
+ *
29
+ * @example
30
+ * <Chart
31
+ * label="Requests per minute, last hour"
32
+ * data={[times, inbound, outbound]}
33
+ * series={[{ label: "Inbound" }, { label: "Outbound" }]}
34
+ * />
35
+ */
36
+ function Chart(props) {
37
+ const rest = omit(props, "label", "description", "title", "data", "series", "height", "stacked", "markers", "x", "y", "legend", "tooltip", "zoom", "onZoom", "onSelect", "onCursor", "focus", "syncKey", "cursor", "padding", "controller", "plugins", "hooks", "labels", "class");
38
+ const id = createUniqueId();
39
+ const grid = useChartGrid();
40
+ const locale = useLocale();
41
+ const messages = useMessages("chart");
42
+ const text = {
43
+ keyboardHint: () => props.labels?.keyboardHint ?? messages()?.keyboardHint ?? "Use the left and right arrow keys to read values.",
44
+ legend: (label) => (props.labels?.legend ?? messages()?.legend ?? ((l) => `${l}: series`))(label)
45
+ };
46
+ let plot;
47
+ let probe;
48
+ let u = null;
49
+ let zoomed = false;
50
+ let zoomPending = false;
51
+ const height = () => props.height ?? grid?.height() ?? DEFAULT_HEIGHT;
52
+ const tooltipOn = () => props.tooltip !== false && props.cursor !== false;
53
+ const legendMode = () => props.legend ?? props.series.length > 1;
54
+ const empty = () => (props.data[0]?.length ?? 0) === 0;
55
+ const [hidden, setHidden] = createSignal(/* @__PURE__ */ new Set(), { ownedWrite: true });
56
+ const [tip, setTip] = createSignal(null, { ownedWrite: true });
57
+ /** The focused series (index into `series`): near the pointer, or its legend entry hovered. */
58
+ const [focused, setFocused] = createSignal(null, { ownedWrite: true });
59
+ const [readout, setReadout] = createSignal("", { ownedWrite: true });
60
+ const [mounted, setMounted] = createSignal(false);
61
+ const [scheme, setScheme] = createSignal(0);
62
+ let config;
63
+ let builtSeries;
64
+ let data = [[]];
65
+ let shown = /* @__PURE__ */ new Set();
66
+ let plotHeight = DEFAULT_HEIGHT;
67
+ const fmtX = createMemo(() => {
68
+ const xs = props.data[0];
69
+ const span = xs && xs.length > 1 ? (xs[xs.length - 1] ?? 0) - (xs[0] ?? 0) : 0;
70
+ return (typeof props.tooltip === "object" ? props.tooltip.formatX : void 0) ?? xFormat(props.x, locale(), span);
71
+ });
72
+ const fmtValue = createMemo(() => {
73
+ const fallback = numberFormat(locale());
74
+ return props.series.map((s) => valueFormat(s, props.y, fallback));
75
+ });
76
+ const valueAt = (series, idx) => {
77
+ const v = props.data[series + 1]?.[idx];
78
+ return v == null ? "–" : fmtValue()[series]?.(v) ?? String(v);
79
+ };
80
+ /** The cursor's index: a memo, so the point below changes when the index does, not on every pixel. */
81
+ const cursorIdx = createMemo(() => tip()?.idx ?? null);
82
+ /** What's under the cursor: the tooltip's content and `onCursor`'s argument. */
83
+ const point = createMemo(() => {
84
+ const idx = cursorIdx();
85
+ const x = idx == null ? void 0 : props.data[0]?.[idx];
86
+ if (idx == null || x == null) return null;
87
+ return {
88
+ index: idx,
89
+ x,
90
+ xText: fmtX()(x),
91
+ series: props.series.map((s, i) => ({
92
+ label: s.label,
93
+ value: props.data[i + 1]?.[idx] ?? null,
94
+ text: valueAt(i, idx),
95
+ color: cssColor(s.color, i),
96
+ shown: !hidden().has(i)
97
+ })),
98
+ focused: focused()
99
+ };
100
+ });
101
+ let reported = false;
102
+ createEffect(point, (next) => {
103
+ if (!next && !reported) return;
104
+ reported = true;
105
+ props.onCursor?.(next);
106
+ });
107
+ /** The labeled markers in words, for the plot's description: "Target: 4.0%; Incident: 3:05 PM – 3:20 PM". */
108
+ const markerText = createMemo(() => {
109
+ const yFmt = props.y?.format ?? numberFormat(locale());
110
+ return (props.markers ?? []).filter((m) => m.label).map((m) => {
111
+ const fmt = m.axis === "y" ? yFmt : fmtX();
112
+ const value = typeof m.value === "number" ? fmt(m.value) : `${fmt(m.value[0])} – ${fmt(m.value[1])}`;
113
+ return `${m.label}: ${value}`;
114
+ }).join("; ");
115
+ });
116
+ /** The data uPlot draws: cumulative for a stack. */
117
+ const drawn = (d) => config?.stacked ? stackData(d, shown) : d;
118
+ function readoutAt(idx) {
119
+ const parts = props.series.flatMap((s, i) => hidden().has(i) ? [] : [`${s.label} ${valueAt(i, idx)}`]);
120
+ const x = props.data[0]?.[idx];
121
+ return `${x == null ? "" : fmtX()(x)}: ${parts.join(", ")}`;
122
+ }
123
+ function theme(resolve) {
124
+ const style = getComputedStyle(plot);
125
+ const face = `${style.fontSize} ${style.fontFamily || "sans-serif"}`;
126
+ return {
127
+ text: resolve("var(--sui-text-muted)"),
128
+ grid: resolve("var(--sui-border)"),
129
+ baseline: resolve("var(--sui-border-strong)"),
130
+ surface: backdrop(plot) ?? resolve("var(--sui-bg)"),
131
+ font: face,
132
+ labelFont: `500 ${face}`
133
+ };
134
+ }
135
+ function build() {
136
+ u?.destroy();
137
+ u = null;
138
+ setTip(null);
139
+ setFocused(null);
140
+ const c = config;
141
+ const width = plot.clientWidth;
142
+ if (!c || width <= 0) return;
143
+ if (c.series !== builtSeries) {
144
+ builtSeries = c.series;
145
+ shown = new Set(c.series.flatMap((s, i) => s.show === false ? [i] : []));
146
+ setHidden(shown);
147
+ }
148
+ const resolve = createResolver(probe);
149
+ const css = c.series.map((s, i) => cssColor(s.color, i));
150
+ const brush = c.zoom === false ? c.onSelect ? "select" : false : "zoom";
151
+ const full = numberFormat(c.locale);
152
+ const yTicks = (value, ticks) => {
153
+ const max = Math.max(...ticks.map(Math.abs));
154
+ return (max >= 1e4 ? numberFormat(c.locale, max) : full)(value);
155
+ };
156
+ const options = buildOptions({
157
+ series: c.series,
158
+ x: c.x,
159
+ y: c.y,
160
+ stacked: c.stacked,
161
+ width,
162
+ height: plotHeight,
163
+ strokes: css.map(resolve),
164
+ fills: c.series.map((s, i) => s.type === "bar" ? resolve(css[i]) : s.type === "area" || c.stacked ? resolve(wash(css[i], c.stacked ? 35 : 12)) : void 0),
165
+ theme: theme(resolve),
166
+ cursor: c.cursor,
167
+ focus: c.focus,
168
+ brush,
169
+ syncKey: c.syncKey,
170
+ padding: c.padding ?? [
171
+ 12,
172
+ 12,
173
+ 0,
174
+ 0
175
+ ],
176
+ hidden: shown,
177
+ markers: c.markers,
178
+ yTicks,
179
+ plugins: [...c.markers?.length ? [markersPlugin(c.markers, {
180
+ resolve,
181
+ text: resolve("var(--sui-text-muted)"),
182
+ font: theme(resolve).font
183
+ })] : [], ...c.plugins ?? []],
184
+ hooks: {
185
+ ...c.hooks,
186
+ setCursor: [(self) => {
187
+ const idx = self.cursor.idx;
188
+ const left = self.cursor.left ?? -1;
189
+ if (idx == null || left < 0) {
190
+ setTip(null);
191
+ return;
192
+ }
193
+ const over = self.over;
194
+ setTip({
195
+ idx,
196
+ left: left + over.offsetLeft,
197
+ top: Math.min(Math.max((self.cursor.top ?? 0) + over.offsetTop, 24), over.offsetHeight - 24),
198
+ flip: left > over.clientWidth / 2
199
+ });
200
+ }, ...c.hooks?.setCursor ?? []],
201
+ setSeries: [(_self, i, opts) => {
202
+ if (opts.focus != null) setFocused(i == null ? null : i - 1);
203
+ }, ...c.hooks?.setSeries ?? []],
204
+ setSelect: [(self) => {
205
+ const { left, width } = self.select;
206
+ if (width <= 0) return;
207
+ const range = {
208
+ min: self.posToVal(left, "x"),
209
+ max: self.posToVal(left + width, "x")
210
+ };
211
+ if (brush === "select") {
212
+ c.onSelect?.(range);
213
+ self.setSelect({
214
+ left: 0,
215
+ top: 0,
216
+ width: 0,
217
+ height: 0
218
+ }, false);
219
+ } else zoomPending = true;
220
+ }, ...c.hooks?.setSelect ?? []],
221
+ setScale: [(self, key) => {
222
+ if (key !== "x") return;
223
+ const { min, max } = self.scales.x ?? {};
224
+ if (zoomPending && min != null && max != null) {
225
+ zoomPending = false;
226
+ zoomed = true;
227
+ c.onZoom?.({
228
+ min,
229
+ max
230
+ });
231
+ } else if (zoomed && !zoomPending) {
232
+ zoomed = false;
233
+ c.onZoom?.(null);
234
+ }
235
+ }, ...c.hooks?.setScale ?? []]
236
+ }
237
+ });
238
+ zoomed = false;
239
+ zoomPending = false;
240
+ u = new uPlot(options, drawn(data), plot);
241
+ }
242
+ createEffect(() => ({
243
+ data: props.data,
244
+ series: props.series.length
245
+ }), (next) => {
246
+ data = next.data;
247
+ if (DEV && next.data.length !== next.series + 1) console.warn(`[solid-ui] Chart: ${next.data.length} data arrays for ${next.series} series; pass x and one array per series. The chart keeps what it drew.`);
248
+ const arrays = drawn(next.data);
249
+ if (u && arrays.length === u.series.length) u.setData(arrays, !zoomed);
250
+ });
251
+ createEffect(height, (h) => {
252
+ plotHeight = h;
253
+ if (u) u.setSize({
254
+ width: plot.clientWidth,
255
+ height: h
256
+ });
257
+ });
258
+ createEffect(() => {
259
+ if (!mounted()) return void 0;
260
+ scheme();
261
+ return {
262
+ series: props.series,
263
+ x: props.x,
264
+ y: props.y,
265
+ stacked: props.stacked === true,
266
+ zoom: props.zoom,
267
+ onSelect: props.onSelect,
268
+ onZoom: props.onZoom,
269
+ cursor: props.cursor !== false,
270
+ focus: props.focus !== false && props.stacked !== true && props.series.filter((s) => (s.type ?? "line") !== "bar").length > 1,
271
+ padding: props.padding,
272
+ syncKey: props.syncKey ?? grid?.syncKey(),
273
+ plugins: props.plugins,
274
+ hooks: props.hooks,
275
+ markers: props.markers,
276
+ locale: locale()
277
+ };
278
+ }, (next) => {
279
+ if (!next) return;
280
+ config = next;
281
+ build();
282
+ });
283
+ onSettled(() => {
284
+ setMounted(true);
285
+ const resize = new ResizeObserver(() => {
286
+ const width = plot.clientWidth;
287
+ if (!u) {
288
+ if (width > 0) build();
289
+ } else if (width > 0 && Math.abs(width - u.width) > .5) u.setSize({
290
+ width,
291
+ height: plotHeight
292
+ });
293
+ });
294
+ resize.observe(plot);
295
+ const unwatch = watchScheme(probe, () => setScheme((n) => n + 1));
296
+ document.fonts?.ready.then(() => u?.setSize({
297
+ width: plot.clientWidth,
298
+ height: plotHeight
299
+ }));
300
+ props.controller?.({
301
+ setData: (next) => {
302
+ data = next;
303
+ u?.setData(drawn(next), !zoomed);
304
+ },
305
+ setXRange: (range) => {
306
+ zoomPending = true;
307
+ u?.setScale("x", range);
308
+ },
309
+ setYRange: (range) => u?.setScale("y", range),
310
+ resetZoom: () => {
311
+ if (u) u.setData(u.data, true);
312
+ },
313
+ uplot: () => u
314
+ });
315
+ return () => {
316
+ resize.disconnect();
317
+ unwatch();
318
+ u?.destroy();
319
+ u = null;
320
+ };
321
+ });
322
+ function toggle(i) {
323
+ const next = new Set(shown);
324
+ const show = next.has(i);
325
+ if (show) next.delete(i);
326
+ else next.add(i);
327
+ shown = next;
328
+ setHidden(next);
329
+ if (!u) return;
330
+ if (config?.stacked) build();
331
+ else {
332
+ if (!show && focused() === i) u.setSeries(null, { focus: true });
333
+ u.setSeries(i + 1, { show });
334
+ }
335
+ }
336
+ /**
337
+ * Focus a series from its legend entry (the others fade), or clear it. A hidden series has nothing to
338
+ * set apart. Not published to a shared cursor: each chart in a grid has its own series.
339
+ */
340
+ function focusSeries(i) {
341
+ if (!u || props.focus === false || i != null && shown.has(i)) return;
342
+ u.setSeries(i == null ? null : i + 1, { focus: true });
343
+ }
344
+ /** Arrow keys walk the cursor through the visible points; the tooltip and the live region follow. */
345
+ function onKeyDown(event) {
346
+ if (!u || !tooltipOn() || empty()) return;
347
+ const xs = u.data[0];
348
+ const [first, last] = u.series[0]?.idxs ?? [0, xs.length - 1];
349
+ const current = u.cursor.idx;
350
+ let idx;
351
+ switch (event.key) {
352
+ case "ArrowRight":
353
+ idx = current == null ? first : Math.min(last, current + 1);
354
+ break;
355
+ case "ArrowLeft":
356
+ idx = current == null ? last : Math.max(first, current - 1);
357
+ break;
358
+ case "Home":
359
+ idx = first;
360
+ break;
361
+ case "End":
362
+ idx = last;
363
+ break;
364
+ case "Escape":
365
+ if (current == null) return;
366
+ moveCursor(u, -10, -10);
367
+ setReadout("");
368
+ event.preventDefault();
369
+ return;
370
+ default: return;
371
+ }
372
+ event.preventDefault();
373
+ const x = xs[idx];
374
+ if (x == null) return;
375
+ const firstShown = props.series.findIndex((_s, i) => !hidden().has(i));
376
+ const y = firstShown >= 0 ? u.data[firstShown + 1]?.[idx] : null;
377
+ moveCursor(u, u.valToPos(x, "x"), y == null ? u.over.clientHeight / 2 : u.valToPos(y, "y"));
378
+ setReadout(readoutAt(idx));
379
+ }
380
+ function onBlur() {
381
+ if (u && u.cursor.idx != null) moveCursor(u, -10, -10);
382
+ setReadout("");
383
+ }
384
+ const legendIdx = () => tip()?.idx ?? (props.data[0]?.length ?? 0) - 1;
385
+ const Swatch = (p) => <span aria-hidden="true" data-slot="chart-swatch" {...stylex.attrs(styles.swatch, (p.series.type ?? "line") === "line" && !props.stacked && styles.swatchLine, p.series.dash && styles.swatchDashed, p.off && styles.swatchOff)} style={swatchStyle(cssColor(p.series.color, p.index))} />;
386
+ return <div {...rest} data-slot="chart" class={[stylex.props(styles.root).className, props.class]}>
387
+ <Show when={props.title}>
388
+ <div id={`${id}-title`} data-slot="chart-title" {...stylex.attrs(styles.title)}>
389
+ {props.title}
390
+ </div>
391
+ </Show>
392
+ <div ref={(el) => plot = el} data-slot="chart-plot" role="img" aria-label={props.label} aria-describedby={[
393
+ props.description ? `${id}-desc` : "",
394
+ markerText() ? `${id}-markers` : "",
395
+ tooltipOn() && !empty() ? `${id}-keys` : ""
396
+ ].filter(Boolean).join(" ") || void 0} tabindex={tooltipOn() && !empty() ? 0 : void 0} data-empty={empty() ? "" : void 0} onKeyDown={onKeyDown} onBlur={onBlur} {...stylex.attrs(styles.plot)} style={{ height: `${height()}px` }}>
397
+ <span ref={(el) => probe = el} {...stylex.attrs(styles.probe)} />
398
+ <Show when={tooltipOn() ? point() : null}>
399
+ {(p) => <FloatingTip data-slot="chart-tooltip" aria-hidden="true" origin={() => plot} left={tip()?.left ?? 0} top={tip()?.top ?? 0} before={tip()?.flip} xstyle={styles.tooltip}>
400
+ <Show keyed when={typeof props.tooltip === "object" ? props.tooltip.render : void 0} fallback={<>
401
+ <div data-slot="chart-tooltip-heading" {...stylex.attrs(styles.tooltipHeading)}>
402
+ {p().xText}
403
+ </div>
404
+ <For each={props.series}>
405
+ {(s, i) => <Show when={!hidden().has(i())}>
406
+ <div data-slot="chart-tooltip-row" data-focused={p().focused === i() ? "" : void 0} {...stylex.attrs(styles.row, p().focused != null && p().focused !== i() && styles.rowFaded)}>
407
+ <Swatch series={s} index={i()} />
408
+ <span {...stylex.attrs(styles.rowLabel)}>{s.label}</span>
409
+ <span {...stylex.attrs(styles.value)}>{p().series[i()]?.text}</span>
410
+ </div>
411
+ </Show>}
412
+ </For>
413
+ </>}>
414
+ {(render) => render(p)}
415
+ </Show>
416
+ </FloatingTip>}
417
+ </Show>
418
+ </div>
419
+ <Show when={props.description}>
420
+ <span id={`${id}-desc`} {...stylex.attrs(styles.visuallyHidden)}>
421
+ {props.description}
422
+ </span>
423
+ </Show>
424
+ <Show when={markerText()}>
425
+ <span id={`${id}-markers`} {...stylex.attrs(styles.visuallyHidden)}>
426
+ {markerText()}
427
+ </span>
428
+ </Show>
429
+ <span id={`${id}-keys`} {...stylex.attrs(styles.visuallyHidden)}>
430
+ {text.keyboardHint()}
431
+ </span>
432
+ <span data-slot="chart-readout" aria-live="polite" {...stylex.attrs(styles.visuallyHidden)}>
433
+ {readout()}
434
+ </span>
435
+ <Show when={legendMode()}>
436
+ <ul data-slot="chart-legend" aria-label={text.legend(props.label)} {...stylex.attrs(styles.legend)}>
437
+ <For each={props.series}>
438
+ {(s, i) => <li>
439
+ <button type="button" data-slot="chart-legend-item" aria-pressed={hidden().has(i()) ? "false" : "true"} onClick={() => toggle(i())} onPointerEnter={() => focusSeries(i())} onPointerLeave={() => focusSeries(null)} onFocus={() => focusSeries(i())} onBlur={() => focusSeries(null)} {...stylex.attrs(styles.legendButton)}>
440
+ <Swatch series={s} index={i()} off={hidden().has(i())} />
441
+ {s.label}
442
+ <Show when={legendMode() === "live" && !empty()}>
443
+ <span data-slot="chart-legend-value" {...stylex.attrs(styles.legendValue)}>
444
+ {valueAt(i(), legendIdx())}
445
+ </span>
446
+ </Show>
447
+ </button>
448
+ </li>}
449
+ </For>
450
+ </ul>
451
+ </Show>
452
+ </div>;
453
+ }
454
+ export { Chart };
@@ -0,0 +1,165 @@
1
+ import "@stylexjs/stylex";
2
+ // src/chart/chart.styles.ts
3
+ const styles = {
4
+ root: {
5
+ kB7OPa: "x9f619",
6
+ k1xSpc: "x78zum5",
7
+ kXwgrk: "xdt5ytf",
8
+ kOIVth: "x8rwxmg",
9
+ k7Eaqz: "xeuugli",
10
+ kMv6JI: "x13rcfk",
11
+ kMwMTN: "x1yjpjgc",
12
+ $$css: true
13
+ },
14
+ title: {
15
+ kogj98: "x1ghz6dp",
16
+ kGuDYH: "x409pna",
17
+ k63SB2: "x1vmg6u2",
18
+ kLWn49: "xau0z5x",
19
+ kMwMTN: "x1yjpjgc",
20
+ $$css: true
21
+ },
22
+ plot: {
23
+ kVAEAm: "x1n2onr6",
24
+ kB7OPa: "x9f619",
25
+ k7Eaqz: "xeuugli",
26
+ kaIpWk: "x1b6xorz",
27
+ k3XXqK: "x1t137rt x9v5kkp",
28
+ kMeerF: "x1de99jn",
29
+ kInvED: "x1hl8ikr",
30
+ kjBf7l: "xi1ptex x1x84bn5",
31
+ kGuDYH: "xb5fjo1",
32
+ $$css: true
33
+ },
34
+ probe: {
35
+ k1xSpc: "x1s85apg",
36
+ $$css: true
37
+ },
38
+ tooltip: {
39
+ kB7OPa: "x9f619",
40
+ k1xSpc: "xrvj5dj",
41
+ kOIVth: "xz09phk",
42
+ k7Eaqz: "xzhy1st",
43
+ ks0D6T: "x2y036v",
44
+ k8WAf4: "xqy2vlu",
45
+ kg3NbH: "xxobuei",
46
+ kWkggS: "xm9f0jk",
47
+ kMwMTN: "x1yjpjgc",
48
+ kMzoRj: "xmkeg23",
49
+ ksu8eU: "x1y0btm7",
50
+ kVAM5u: "x1wpxzwl x1w1tqly",
51
+ kaIpWk: "x1ttroej",
52
+ kGVxlE: "xfw8du2",
53
+ kGuDYH: "xb5fjo1",
54
+ kLWn49: "xau0z5x",
55
+ kfzvcC: "x47corl",
56
+ khDVqt: "xuxw1ft",
57
+ $$css: true
58
+ },
59
+ tooltipHeading: {
60
+ kMwMTN: "xe2mk2a",
61
+ k63SB2: "x1vmg6u2",
62
+ $$css: true
63
+ },
64
+ row: {
65
+ k1xSpc: "x78zum5",
66
+ kGNEyG: "x6s0dn4",
67
+ kOIVth: "x8rwxmg",
68
+ $$css: true
69
+ },
70
+ rowFaded: {
71
+ kSiTet: "xwq05k6",
72
+ $$css: true
73
+ },
74
+ rowLabel: {
75
+ kzQI83: "x1iyjqo2",
76
+ kMwMTN: "xe2mk2a",
77
+ $$css: true
78
+ },
79
+ value: {
80
+ kcqcaj: "xss6m8b",
81
+ k63SB2: "x1vmg6u2",
82
+ kMwMTN: "x1yjpjgc",
83
+ kQ0QjF: "xa7awgv",
84
+ $$css: true
85
+ },
86
+ legend: {
87
+ k1xSpc: "x78zum5",
88
+ kwnvtZ: "x1a02dak",
89
+ kOIVth: "xz09phk",
90
+ kogj98: "x1ghz6dp",
91
+ keTefX: "x1pxmky9",
92
+ kmVPX3: "x1717udv",
93
+ kB88ic: "xe8uvvx",
94
+ $$css: true
95
+ },
96
+ legendButton: {
97
+ kB7OPa: "x9f619",
98
+ k1xSpc: "x3nfvp2",
99
+ kGNEyG: "x6s0dn4",
100
+ kOIVth: "x1xuqxfr",
101
+ kAzted: "x1pw4g4d",
102
+ kg3NbH: "x1d6xsf",
103
+ kogj98: "x1ghz6dp",
104
+ kMzoRj: "xc342km",
105
+ kaIpWk: "x1b6xorz",
106
+ kWkggS: "xjbqb8w x12f1u69",
107
+ kMwMTN: "x1yjpjgc x1b9byvc",
108
+ kMv6JI: "xjb2p0i",
109
+ kGuDYH: "xb5fjo1",
110
+ k63SB2: "x1vmg6u2",
111
+ kLWn49: "xau0z5x",
112
+ kkrTdU: "x1ypdohk",
113
+ k3XXqK: "x1t137rt x9v5kkp",
114
+ kMeerF: "x1de99jn",
115
+ kInvED: "x2ssjo2",
116
+ kjBf7l: "xi1ptex x1x84bn5",
117
+ kMnn75: "xkrqix3 x1f7ip12",
118
+ $$css: true
119
+ },
120
+ legendValue: {
121
+ kcqcaj: "xss6m8b",
122
+ kMwMTN: "xe2mk2a",
123
+ kQ0QjF: "xa7awgv",
124
+ $$css: true
125
+ },
126
+ swatch: {
127
+ kmuXW: "x2lah0s",
128
+ kB7OPa: "x9f619",
129
+ k1xSpc: "x1rg5ohu",
130
+ kzqmXN: "x1jw3ynk",
131
+ kZKoxP: "xvle69y",
132
+ kaIpWk: "x1cum3z5",
133
+ kWkggS: "xrmkqiu",
134
+ kAXs8y: "x1kzknox",
135
+ $$css: true
136
+ },
137
+ swatchLine: {
138
+ kzqmXN: "xcdlrvm",
139
+ kZKoxP: "x36qwtl",
140
+ kaIpWk: "x1nj7uno",
141
+ $$css: true
142
+ },
143
+ swatchDashed: {
144
+ kWkggS: "xjbqb8w",
145
+ kKwaWg: "x1fb1h6r",
146
+ $$css: true
147
+ },
148
+ swatchOff: {
149
+ kSiTet: "x3onkmb",
150
+ $$css: true
151
+ },
152
+ visuallyHidden: {
153
+ kVAEAm: "x10l6tqk",
154
+ kzqmXN: "x1i1rx1s",
155
+ kZKoxP: "xjm9jq1",
156
+ kogj98: "xkdpibf",
157
+ kmVPX3: "x1717udv",
158
+ kVQacm: "xb3r6kr",
159
+ kMcinP: "xeh89do",
160
+ khDVqt: "xuxw1ft",
161
+ kMzoRj: "xc342km",
162
+ $$css: true
163
+ }
164
+ };
165
+ export { styles };
@@ -0,0 +1 @@
1
+ export { Chart } from "./chart.jsx";
@@ -0,0 +1,46 @@
1
+ import { ChartGridContext } from "../internal/grid-context.jsx";
2
+ import * as stylex from "@stylexjs/stylex";
3
+ import { createUniqueId, omit } from "solid-js";
4
+ // src/chart-grid/chart-grid.tsx
5
+ const _temp = {
6
+ kumcoG: "xqketvx",
7
+ "$$css": true
8
+ };
9
+ const _temp2 = {
10
+ kumcoG: "xqketvx",
11
+ "$$css": true
12
+ };
13
+ const styles = {
14
+ grid: {
15
+ k1xSpc: "xrvj5dj",
16
+ kOIVth: "xcjfhwz",
17
+ k7Eaqz: "xeuugli",
18
+ $$css: true
19
+ },
20
+ auto: (min) => [_temp, { "--x-gridTemplateColumns": `repeat(auto-fill, minmax(min(100%, ${min}), 1fr))` != null ? `repeat(auto-fill, minmax(min(100%, ${min}), 1fr))` : void 0 }],
21
+ fixed: (columns) => [_temp2, { "--x-gridTemplateColumns": `repeat(${columns}, minmax(0, 1fr))` != null ? `repeat(${columns}, minmax(0, 1fr))` : void 0 }]
22
+ };
23
+ /**
24
+ * Several charts on one time axis, laid out in columns that follow the width, with one shared cursor.
25
+ * For a diagnostics or metrics panel read together. Each chart keeps its own label and title.
26
+ *
27
+ * @example
28
+ * <ChartGrid label="Network, last hour">
29
+ * <Chart title="Throughput (Mbps)" label="Throughput, last hour" data={throughput} series={[{ label: "In" }]} />
30
+ * <Chart title="Latency (ms)" label="Latency, last hour" data={latency} series={[{ label: "p95" }]} />
31
+ * </ChartGrid>
32
+ */
33
+ function ChartGrid(props) {
34
+ const rest = omit(props, "label", "children", "minColumnWidth", "columns", "sync", "chartHeight", "class");
35
+ const key = `chart-grid-${createUniqueId()}`;
36
+ const layout = () => stylex.props(styles.grid, props.columns ? styles.fixed(String(props.columns)) : styles.auto(`${props.minColumnWidth ?? 320}px`));
37
+ return <ChartGridContext value={{
38
+ syncKey: () => props.sync === false ? void 0 : key,
39
+ height: () => props.chartHeight
40
+ }}>
41
+ <div {...rest} role="group" aria-label={props.label} data-slot="chart-grid" class={[layout().className, props.class]} style={layout().style}>
42
+ {props.children}
43
+ </div>
44
+ </ChartGridContext>;
45
+ }
46
+ export { ChartGrid };
@@ -0,0 +1 @@
1
+ export { ChartGrid } from "./chart-grid.jsx";