@xeonr/platform-ui 1.10.2 → 1.12.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 (200) hide show
  1. package/dist/auth/AuthCode.d.ts +48 -0
  2. package/dist/auth/AuthCode.d.ts.map +1 -0
  3. package/dist/auth/AuthCode.js +197 -0
  4. package/dist/auth/AuthCode.js.map +1 -0
  5. package/dist/auth/AuthConsent.d.ts +69 -0
  6. package/dist/auth/AuthConsent.d.ts.map +1 -0
  7. package/dist/auth/AuthConsent.js +155 -0
  8. package/dist/auth/AuthConsent.js.map +1 -0
  9. package/dist/auth/AuthControls.d.ts +133 -0
  10. package/dist/auth/AuthControls.d.ts.map +1 -0
  11. package/dist/auth/AuthControls.js +379 -0
  12. package/dist/auth/AuthControls.js.map +1 -0
  13. package/dist/auth/AuthPanel.d.ts +106 -0
  14. package/dist/auth/AuthPanel.d.ts.map +1 -0
  15. package/dist/auth/AuthPanel.js +317 -0
  16. package/dist/auth/AuthPanel.js.map +1 -0
  17. package/dist/auth.d.ts +5 -0
  18. package/dist/auth.d.ts.map +1 -0
  19. package/dist/auth.js +15 -0
  20. package/dist/auth.js.map +1 -0
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +2 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/kit/Anchored.js +109 -109
  26. package/dist/kit/Anchored.js.map +1 -1
  27. package/dist/kit/ApiKeyForm.js +73 -73
  28. package/dist/kit/ApiKeyForm.js.map +1 -1
  29. package/dist/kit/ApiKeys.js +144 -144
  30. package/dist/kit/ApiKeys.js.map +1 -1
  31. package/dist/kit/Badge.js +45 -45
  32. package/dist/kit/Badge.js.map +1 -1
  33. package/dist/kit/Blocks.d.ts.map +1 -1
  34. package/dist/kit/Blocks.js +103 -102
  35. package/dist/kit/Blocks.js.map +1 -1
  36. package/dist/kit/Board.js +54 -54
  37. package/dist/kit/Board.js.map +1 -1
  38. package/dist/kit/Button.d.ts +3 -3
  39. package/dist/kit/Button.d.ts.map +1 -1
  40. package/dist/kit/Button.js +55 -50
  41. package/dist/kit/Button.js.map +1 -1
  42. package/dist/kit/Card.d.ts.map +1 -1
  43. package/dist/kit/Card.js +36 -29
  44. package/dist/kit/Card.js.map +1 -1
  45. package/dist/kit/ChartFrame.js +54 -54
  46. package/dist/kit/ChartFrame.js.map +1 -1
  47. package/dist/kit/ChartTypes.js +215 -215
  48. package/dist/kit/ChartTypes.js.map +1 -1
  49. package/dist/kit/Charts.js +605 -605
  50. package/dist/kit/Charts.js.map +1 -1
  51. package/dist/kit/Checkbox.js +16 -16
  52. package/dist/kit/Checkbox.js.map +1 -1
  53. package/dist/kit/Chip.js +21 -21
  54. package/dist/kit/Chip.js.map +1 -1
  55. package/dist/kit/Choice.js +24 -24
  56. package/dist/kit/Choice.js.map +1 -1
  57. package/dist/kit/CodeEditor.d.ts.map +1 -1
  58. package/dist/kit/CodeEditor.js +26 -48
  59. package/dist/kit/CodeEditor.js.map +1 -1
  60. package/dist/kit/Color.js +74 -74
  61. package/dist/kit/Color.js.map +1 -1
  62. package/dist/kit/Combobox.js +67 -67
  63. package/dist/kit/Combobox.js.map +1 -1
  64. package/dist/kit/CommandPalette.d.ts.map +1 -1
  65. package/dist/kit/CommandPalette.js +96 -86
  66. package/dist/kit/CommandPalette.js.map +1 -1
  67. package/dist/kit/Comment.js +7 -7
  68. package/dist/kit/Comment.js.map +1 -1
  69. package/dist/kit/Controls.js +122 -122
  70. package/dist/kit/Controls.js.map +1 -1
  71. package/dist/kit/DataGrid.js +97 -97
  72. package/dist/kit/DataGrid.js.map +1 -1
  73. package/dist/kit/DataTable.d.ts.map +1 -1
  74. package/dist/kit/DataTable.js +196 -195
  75. package/dist/kit/DataTable.js.map +1 -1
  76. package/dist/kit/DatePicker.js +242 -242
  77. package/dist/kit/DatePicker.js.map +1 -1
  78. package/dist/kit/Drawer.d.ts.map +1 -1
  79. package/dist/kit/Drawer.js +15 -14
  80. package/dist/kit/Drawer.js.map +1 -1
  81. package/dist/kit/Dropzone.js +80 -80
  82. package/dist/kit/Dropzone.js.map +1 -1
  83. package/dist/kit/Editable.d.ts.map +1 -1
  84. package/dist/kit/Editable.js +130 -129
  85. package/dist/kit/Editable.js.map +1 -1
  86. package/dist/kit/EmptyState.d.ts.map +1 -1
  87. package/dist/kit/EmptyState.js +14 -13
  88. package/dist/kit/EmptyState.js.map +1 -1
  89. package/dist/kit/EntityHeader.d.ts.map +1 -1
  90. package/dist/kit/EntityHeader.js +17 -16
  91. package/dist/kit/EntityHeader.js.map +1 -1
  92. package/dist/kit/Facet.js +52 -52
  93. package/dist/kit/Facet.js.map +1 -1
  94. package/dist/kit/FacetRail.js +91 -91
  95. package/dist/kit/FacetRail.js.map +1 -1
  96. package/dist/kit/Forbidden.js +7 -7
  97. package/dist/kit/Forbidden.js.map +1 -1
  98. package/dist/kit/Form.d.ts.map +1 -1
  99. package/dist/kit/Form.js +144 -143
  100. package/dist/kit/Form.js.map +1 -1
  101. package/dist/kit/Graph.d.ts +14 -3
  102. package/dist/kit/Graph.d.ts.map +1 -1
  103. package/dist/kit/Graph.js +473 -314
  104. package/dist/kit/Graph.js.map +1 -1
  105. package/dist/kit/GroupedMultiSelect.js +115 -115
  106. package/dist/kit/GroupedMultiSelect.js.map +1 -1
  107. package/dist/kit/Icon.d.ts +2 -0
  108. package/dist/kit/Icon.d.ts.map +1 -1
  109. package/dist/kit/Icon.js +3 -1
  110. package/dist/kit/Icon.js.map +1 -1
  111. package/dist/kit/JumpList.js +11 -11
  112. package/dist/kit/JumpList.js.map +1 -1
  113. package/dist/kit/KV.js +6 -6
  114. package/dist/kit/KV.js.map +1 -1
  115. package/dist/kit/Layout.js +5 -5
  116. package/dist/kit/Layout.js.map +1 -1
  117. package/dist/kit/List.js +74 -74
  118. package/dist/kit/List.js.map +1 -1
  119. package/dist/kit/LogView.js +68 -68
  120. package/dist/kit/LogView.js.map +1 -1
  121. package/dist/kit/Markdown.js +37 -37
  122. package/dist/kit/Markdown.js.map +1 -1
  123. package/dist/kit/Marker.js +42 -42
  124. package/dist/kit/Marker.js.map +1 -1
  125. package/dist/kit/Menu.js +128 -128
  126. package/dist/kit/Menu.js.map +1 -1
  127. package/dist/kit/Modal.d.ts.map +1 -1
  128. package/dist/kit/Modal.js +86 -75
  129. package/dist/kit/Modal.js.map +1 -1
  130. package/dist/kit/MultiCombobox.js +157 -157
  131. package/dist/kit/MultiCombobox.js.map +1 -1
  132. package/dist/kit/PageHeader.d.ts.map +1 -1
  133. package/dist/kit/PageHeader.js +8 -7
  134. package/dist/kit/PageHeader.js.map +1 -1
  135. package/dist/kit/Panel.d.ts.map +1 -1
  136. package/dist/kit/Panel.js +33 -14
  137. package/dist/kit/Panel.js.map +1 -1
  138. package/dist/kit/Picker.js +159 -159
  139. package/dist/kit/Picker.js.map +1 -1
  140. package/dist/kit/PipelineFlow.js +86 -86
  141. package/dist/kit/PipelineFlow.js.map +1 -1
  142. package/dist/kit/Popover.js +67 -67
  143. package/dist/kit/Popover.js.map +1 -1
  144. package/dist/kit/Range.js +76 -76
  145. package/dist/kit/Range.js.map +1 -1
  146. package/dist/kit/Reorder.js +95 -95
  147. package/dist/kit/Reorder.js.map +1 -1
  148. package/dist/kit/Search.js +27 -27
  149. package/dist/kit/Search.js.map +1 -1
  150. package/dist/kit/Secret.js +26 -26
  151. package/dist/kit/Secret.js.map +1 -1
  152. package/dist/kit/Skeleton.js +14 -14
  153. package/dist/kit/Skeleton.js.map +1 -1
  154. package/dist/kit/Sparkline.js +51 -51
  155. package/dist/kit/Sparkline.js.map +1 -1
  156. package/dist/kit/Spectrum.js +163 -163
  157. package/dist/kit/Spectrum.js.map +1 -1
  158. package/dist/kit/Splash.js +3 -3
  159. package/dist/kit/Splash.js.map +1 -1
  160. package/dist/kit/Split.js +13 -13
  161. package/dist/kit/Split.js.map +1 -1
  162. package/dist/kit/SplitButton.d.ts.map +1 -1
  163. package/dist/kit/SplitButton.js +8 -6
  164. package/dist/kit/SplitButton.js.map +1 -1
  165. package/dist/kit/Stat.d.ts.map +1 -1
  166. package/dist/kit/Stat.js +61 -60
  167. package/dist/kit/Stat.js.map +1 -1
  168. package/dist/kit/Stepper.js +22 -22
  169. package/dist/kit/Stepper.js.map +1 -1
  170. package/dist/kit/TabStrip.js +68 -68
  171. package/dist/kit/TabStrip.js.map +1 -1
  172. package/dist/kit/Text.js +63 -63
  173. package/dist/kit/Text.js.map +1 -1
  174. package/dist/kit/Toast.js +29 -29
  175. package/dist/kit/Toast.js.map +1 -1
  176. package/dist/kit/Tooltip.js +83 -83
  177. package/dist/kit/Tooltip.js.map +1 -1
  178. package/dist/kit/Trace.js +33 -33
  179. package/dist/kit/Trace.js.map +1 -1
  180. package/dist/kit/Upload.js +88 -88
  181. package/dist/kit/Upload.js.map +1 -1
  182. package/dist/kit/graphLayout.d.ts +32 -0
  183. package/dist/kit/graphLayout.d.ts.map +1 -0
  184. package/dist/kit/graphLayout.js +179 -0
  185. package/dist/kit/graphLayout.js.map +1 -0
  186. package/dist/theme/ThemeProvider.d.ts +17 -1
  187. package/dist/theme/ThemeProvider.d.ts.map +1 -1
  188. package/dist/theme/ThemeProvider.js +40 -4
  189. package/dist/theme/ThemeProvider.js.map +1 -1
  190. package/dist/theme/ThemeScope.d.ts +9 -1
  191. package/dist/theme/ThemeScope.d.ts.map +1 -1
  192. package/dist/theme/ThemeScope.js +11 -4
  193. package/dist/theme/ThemeScope.js.map +1 -1
  194. package/dist/theme/tokens.d.ts +74 -0
  195. package/dist/theme/tokens.d.ts.map +1 -1
  196. package/dist/theme/tokens.js +197 -3
  197. package/dist/theme/tokens.js.map +1 -1
  198. package/package.json +12 -6
  199. package/scripts/check-colour-literals.mjs +5 -1
  200. package/scripts/stable-styled-ids.mjs +75 -0
@@ -4,7 +4,7 @@ import styled from "styled-components";
4
4
  import { v } from "../theme/tokens.js";
5
5
  import { fmtCount } from "./Facet.js";
6
6
  import { LegendChips, LegendNote } from "./ChartFrame.js";
7
- import { CHART_SIZES, TONE_COLOUR, niceTicks, rampToken, spaced, stepLabel, timeDetail, timeTick, timeTicks, useChartSize, } from "./chartScale.js";
7
+ import { CHART_SIZES, TONE_COLOUR, niceTicks, rampToken, spaced, stepLabel, timeDetail, timeTick, timeTicks, useChartSize } from "./chartScale.js";
8
8
  // The time charts in raw SVG, themed with the tokens so they sit in the same
9
9
  // visual system as everything else. No charting library: the need is "n series
10
10
  // over a shared time axis", lined, stacked or barred, with markers, thresholds,
@@ -16,69 +16,69 @@ import { CHART_SIZES, TONE_COLOUR, niceTicks, rampToken, spaced, stepLabel, time
16
16
  // the legend and drag-to-zoom.
17
17
  export { timeTick };
18
18
  function scaleBytes(n) {
19
- const units = ["B", "KB", "MB", "GB", "TB", "PB"];
20
- let val = n;
21
- let i = 0;
22
- while (Math.abs(val) >= 1024 && i < units.length - 1) {
23
- val /= 1024;
24
- i++;
25
- }
26
- return `${i === 0 || Math.abs(val) >= 100 ? Math.round(val) : Math.abs(val) >= 10 ? val.toFixed(1) : val.toFixed(2)} ${units[i]}`;
19
+ const units = ["B", "KB", "MB", "GB", "TB", "PB"];
20
+ let val = n;
21
+ let i = 0;
22
+ while (Math.abs(val) >= 1024 && i < units.length - 1) {
23
+ val /= 1024;
24
+ i++;
25
+ }
26
+ return `${i === 0 || Math.abs(val) >= 100 ? Math.round(val) : Math.abs(val) >= 10 ? val.toFixed(1) : val.toFixed(2)} ${units[i]}`;
27
27
  }
28
28
  function tickValue(x) {
29
- if (Math.abs(x) >= 1000)
30
- return fmtCount(Math.round(x));
31
- return Number.isInteger(x) ? String(x) : String(Number(x.toPrecision(3)));
29
+ if (Math.abs(x) >= 1000)
30
+ return fmtCount(Math.round(x));
31
+ return Number.isInteger(x) ? String(x) : String(Number(x.toPrecision(3)));
32
32
  }
33
33
  /** Reads a number as its unit. `compact` is the axis form (shorter, whole numbers for percent); the default is the tooltip's. */
34
34
  export function formatUnit(value, unit, compact = false) {
35
- switch (unit) {
36
- case "percent": return compact ? `${Math.round(value)}%` : `${value.toFixed(value >= 10 || Number.isInteger(value) ? 0 : 1)}%`;
37
- case "bytes": return scaleBytes(value);
38
- case "bps": return `${scaleBytes(value)}/s`;
39
- default: return compact ? tickValue(value) : Math.abs(value) >= 100 || Number.isInteger(value) ? fmtCount(Math.round(value)) : value.toFixed(1);
40
- }
35
+ switch (unit) {
36
+ case "percent":return compact ? `${Math.round(value)}%` : `${value.toFixed(value >= 10 || Number.isInteger(value) ? 0 : 1)}%`;
37
+ case "bytes":return scaleBytes(value);
38
+ case "bps":return `${scaleBytes(value)}/s`;
39
+ default:return compact ? tickValue(value) : Math.abs(value) >= 100 || Number.isInteger(value) ? fmtCount(Math.round(value)) : value.toFixed(1);
40
+ }
41
41
  }
42
42
  /** The change from `was` to `now` as the tooltip writes it: "+72 %", "−9 %", "→" when flat. */
43
43
  export function formatDelta(now, was) {
44
- if (!Number.isFinite(now) || !Number.isFinite(was))
45
- return "";
46
- if (was === 0)
47
- return now === 0 ? "→" : "new";
48
- const pct = ((now - was) / Math.abs(was)) * 100;
49
- if (Math.abs(pct) < 1)
50
- return "→";
51
- return `${pct > 0 ? "+" : "−"}${Math.abs(pct) >= 10 ? Math.round(Math.abs(pct)) : Math.abs(pct).toFixed(1)} %`;
44
+ if (!Number.isFinite(now) || !Number.isFinite(was))
45
+ return "";
46
+ if (was === 0)
47
+ return now === 0 ? "→" : "new";
48
+ const pct = (now - was) / Math.abs(was) * 100;
49
+ if (Math.abs(pct) < 1)
50
+ return "→";
51
+ return `${pct > 0 ? "+" : "−"}${Math.abs(pct) >= 10 ? Math.round(Math.abs(pct)) : Math.abs(pct).toFixed(1)} %`;
52
52
  }
53
53
  const syncBus = new Map();
54
54
  function publish(key, t, from) {
55
- if (!key)
56
- return;
57
- for (const fn of syncBus.get(key) ?? [])
58
- fn(t, from);
55
+ if (!key)
56
+ return;
57
+ for (const fn of syncBus.get(key) ?? [])
58
+ fn(t, from);
59
59
  }
60
60
  // ---------------------------------------------------------------------------
61
61
  // Styles
62
62
  // ---------------------------------------------------------------------------
63
- const Wrap = styled.div `min-width: 0;`;
64
- const Plot = styled.div `position: relative; min-width: 0;`;
65
- const PlotSvg = styled.svg `
63
+ const Wrap = styled.div.withConfig({ componentId: "sc-pigh48-0" })`min-width: 0;`;
64
+ const Plot = styled.div.withConfig({ componentId: "sc-pigh48-1" })`position: relative; min-width: 0;`;
65
+ const PlotSvg = styled.svg.withConfig({ componentId: "sc-pigh48-2" })`
66
66
  display: block;
67
67
  width: 100%;
68
68
  overflow: visible;
69
- cursor: ${(p) => (p.$interactive ? "crosshair" : "default")};
69
+ cursor: ${(p) => p.$interactive ? "crosshair" : "default"};
70
70
  user-select: none;
71
71
  touch-action: pan-y;
72
72
  &:focus { outline: none; }
73
- &:focus-visible { outline: 2px solid ${v.brand55}; outline-offset: 2px; border-radius: 4px; }
73
+ &:focus-visible { outline: 2px solid ${v.brand55}; outline-offset: 2px; border-radius: min(4px, ${v.rCtl}); }
74
74
  text { font-family: ${v.mono}; font-variant-numeric: tabular-nums; }
75
75
  `;
76
- const Note = styled.div `
76
+ const Note = styled.div.withConfig({ componentId: "sc-pigh48-3" })`
77
77
  height: ${(p) => p.$h}px; display: grid; place-items: center;
78
78
  color: ${v.faint}; font-size: 12px; text-align: center;
79
79
  `;
80
- const ChartHint = styled.div `margin-top: 4px; font-size: 11px; color: ${v.faint};`;
81
- const Tip = styled.div `
80
+ const ChartHint = styled.div.withConfig({ componentId: "sc-pigh48-4" })`margin-top: 4px; font-size: 11px; color: ${v.faint};`;
81
+ const Tip = styled.div.withConfig({ componentId: "sc-pigh48-5" })`
82
82
  position: absolute;
83
83
  top: 6px;
84
84
  pointer-events: none;
@@ -86,7 +86,7 @@ const Tip = styled.div `
86
86
  max-width: 340px;
87
87
  background: ${v.surface2};
88
88
  border: 1px solid ${v.line2};
89
- border-radius: 8px;
89
+ border-radius: min(8px, ${v.rCtl});
90
90
  box-shadow: ${v.elev};
91
91
  padding: 7px 9px;
92
92
  font-size: 11px;
@@ -95,568 +95,568 @@ const Tip = styled.div `
95
95
  .t { color: ${v.faint}; margin-bottom: 4px; font-family: ${v.mono}; white-space: nowrap; }
96
96
  .more { color: ${v.faint}; margin-top: 2px; }
97
97
  `;
98
- const TipRow = styled.div `
98
+ const TipRow = styled.div.withConfig({ componentId: "sc-pigh48-6" })`
99
99
  display: grid;
100
100
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
101
101
  align-items: center;
102
102
  column-gap: 7px;
103
103
  line-height: 1.7;
104
104
  font-family: ${v.mono};
105
- color: ${(p) => (p.$focus ? v.text : v.muted)};
106
- .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: ${(p) => (p.$focus || p.$strong ? 600 : 400)}; }
107
- .val { color: ${v.text}; font-variant-numeric: tabular-nums; text-align: right; font-weight: ${(p) => (p.$strong ? 600 : 400)}; padding-left: 10px; }
105
+ color: ${(p) => p.$focus ? v.text : v.muted};
106
+ .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: ${(p) => p.$focus || p.$strong ? 600 : 400}; }
107
+ .val { color: ${v.text}; font-variant-numeric: tabular-nums; text-align: right; font-weight: ${(p) => p.$strong ? 600 : 400}; padding-left: 10px; }
108
108
  .delta { color: ${v.faint}; font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }
109
109
  .delta.up { color: ${v.chartCrit}; }
110
110
  .delta.down { color: ${v.chartOk}; }
111
111
  `;
112
- const TipSwatch = styled.i `
113
- width: 10px; height: ${(p) => (p.$dashed ? 0 : 3)}px; border-radius: 2px;
114
- background: ${(p) => (p.$dashed ? "none" : p.$c)};
115
- border-top: ${(p) => (p.$dashed ? `2px dashed ${p.$c}` : "0")};
112
+ const TipSwatch = styled.i.withConfig({ componentId: "sc-pigh48-7" })`
113
+ width: 10px; height: ${(p) => p.$dashed ? 0 : 3}px; border-radius: 2px;
114
+ background: ${(p) => p.$dashed ? "none" : p.$c};
115
+ border-top: ${(p) => p.$dashed ? `2px dashed ${p.$c}` : "0"};
116
116
  `;
117
117
  const MAX_TIP_ROWS = 12;
118
118
  /** Splits aligned values into the unbroken runs of reported samples; a missing one ends the run. */
119
119
  function runsOf(xs, ys) {
120
- const runs = [];
121
- let run = [];
122
- for (let i = 0; i < xs.length; i++) {
123
- const val = ys[i];
124
- if (val == null || !Number.isFinite(val)) {
125
- if (run.length)
126
- runs.push(run);
127
- run = [];
128
- }
129
- else
130
- run.push({ t: xs[i], v: val });
131
- }
132
- if (run.length)
133
- runs.push(run);
134
- return runs;
120
+ const runs = [];
121
+ let run = [];
122
+ for (let i = 0; i < xs.length; i++) {
123
+ const val = ys[i];
124
+ if (val == null || !Number.isFinite(val)) {
125
+ if (run.length)
126
+ runs.push(run);
127
+ run = [];
128
+ } else
129
+
130
+ run.push({ t: xs[i], v: val });
131
+ }
132
+ if (run.length)
133
+ runs.push(run);
134
+ return runs;
135
135
  }
136
136
  const markerColour = (m) => m.colour ?? (m.tone ? TONE_COLOUR[m.tone] : m.kind === "alert" ? v.chartCrit : m.kind === "note" ? v.faint : v.chartDeploy);
137
137
  const thresholdWord = (t) => t.label ?? (t.tone === "warn" ? "warn" : t.tone === "ok" ? "ok" : t.tone === "info" ? "target" : "alert");
138
138
  function TimePlot(props) {
139
- const { series, kind, label, empty, formatValue, formatTime, unit, area, stacked, max, min, log, domain, onZoom, onPoint, onReset, onThresholdDrag, syncKey, legend, legendExtra, total, bandOpacity, neutral, hint, testId, } = props;
140
- const size = useChartSize(props.size);
141
- const spec = CHART_SIZES[size];
142
- const H = props.height ?? spec.height;
143
- const axes = spec.yTicks > 0;
144
- // A sparkline has no room for annotations: it is the shape, nothing else.
145
- const markers = axes ? props.markers : undefined;
146
- const thresholds = axes ? props.thresholds : undefined;
147
- const bands = axes ? props.bands : undefined;
148
- const uid = useId().replace(/:/g, "");
149
- const me = useRef(Symbol("chart"));
150
- const wrapRef = useRef(null);
151
- const svgRef = useRef(null);
152
- const [width, setWidth] = useState(600);
153
- const [hidden, setHidden] = useState(new Set());
154
- const [hover, setHover] = useState(null);
155
- const [drag, setDrag] = useState(null);
156
- const down = useRef(null);
157
- const dragRule = useRef(null);
158
- // The plot is drawn at its real width so its text stays crisp; where there is
159
- // no ResizeObserver (a server render, a test DOM) it keeps the default.
160
- const hasData = series.some((s) => s.points.length > 0);
161
- useLayoutEffect(() => {
162
- const el = wrapRef.current;
163
- if (!el || typeof ResizeObserver === "undefined")
164
- return;
165
- const measure = () => { const w = el.getBoundingClientRect().width; if (w > 0)
166
- setWidth(Math.max(120, Math.round(w))); };
167
- measure();
168
- const ro = new ResizeObserver(measure);
169
- ro.observe(el);
170
- return () => ro.disconnect();
171
- }, [hasData]);
172
- // Measured series take the ramp in order; a reference, a compare and a
173
- // neutral series sit outside it. A compare takes its twin's colour.
174
- const colours = useMemo(() => {
175
- const byName = new Map();
176
- let n = 0;
177
- const out = series.map((s) => {
178
- if (s.tone)
179
- return TONE_COLOUR[s.tone];
180
- if (s.colour)
181
- return s.colour;
182
- if (s.reference || neutral?.(s.name))
183
- return v.faint;
184
- if (s.compareOf)
185
- return "";
186
- return rampToken(n++);
187
- });
188
- series.forEach((s, i) => byName.set(s.name, out[i]));
189
- return series.map((s, i) => out[i] || byName.get(s.compareOf ?? "") || v.faint);
190
- }, [series, neutral]);
191
- const names = series.map((s) => s.name).join("\u0000");
192
- // Only names still on the chart count: a new group-by starts with all shown.
193
- const muted = useMemo(() => {
194
- const present = new Set(names.split("\u0000"));
195
- return new Set([...hidden].filter((n) => present.has(n)));
196
- }, [hidden, names]);
197
- const isShown = (s) => !muted.has(s.name) && !(s.compareOf && muted.has(s.compareOf));
198
- // Every series on the union of their timestamps.
199
- const aligned = useMemo(() => {
200
- const xs = [...new Set(series.flatMap((s) => s.points.map((p) => p.t)))].sort((a, b) => a - b);
201
- const index = new Map(xs.map((x, i) => [x, i]));
202
- const cols = series.map((s) => {
203
- const col = new Array(xs.length).fill(null);
204
- for (const p of s.points) {
205
- const i = index.get(p.t);
206
- if (i !== undefined && p.v != null && Number.isFinite(p.v))
207
- col[i] = p.v;
208
- }
209
- return col;
210
- });
211
- let step = Infinity;
212
- for (let i = 1; i < xs.length; i++)
213
- step = Math.min(step, xs[i] - xs[i - 1]);
214
- return { xs, cols, step: Number.isFinite(step) ? step : 60_000 };
215
- }, [series]);
216
- const { xs, cols, step } = aligned;
217
- // Sync: another chart's crosshair, at the nearest bucket here.
218
- useEffect(() => {
219
- if (!syncKey)
220
- return;
221
- const set = syncBus.get(syncKey) ?? new Set();
222
- syncBus.set(syncKey, set);
223
- const fn = (t, from) => {
224
- if (from === me.current)
225
- return;
226
- if (t === null) {
227
- setHover((h) => (h && !h.own ? null : h));
228
- return;
229
- }
230
- let best = -1;
231
- for (let i = 0; i < xs.length; i++)
232
- if (best < 0 || Math.abs(xs[i] - t) < Math.abs(xs[best] - t))
233
- best = i;
234
- if (best >= 0 && Math.abs(xs[best] - t) <= step)
235
- setHover({ idx: best, py: null, own: false });
236
- else
237
- setHover((h) => (h && !h.own ? null : h));
238
- };
239
- set.add(fn);
240
- return () => { set.delete(fn); };
241
- }, [syncKey, xs, step]);
242
- if (xs.length === 0)
243
- return _jsx(Wrap, { ref: wrapRef, "data-testid": testId, children: _jsx(Note, { "$h": H, children: empty }) });
244
- const stack = kind === "bars" || !!stacked;
245
- const stackable = (s) => stack && !s.reference && !s.overlay && !s.compareOf;
246
- // Stacked parts: each part's lower and upper edge at every bucket.
247
- const lower = series.map(() => []);
248
- const upper = series.map(() => []);
249
- const totals = xs.map(() => 0);
250
- for (let i = 0; i < xs.length; i++) {
251
- let base = 0;
252
- series.forEach((s, k) => {
253
- if (!stackable(s) || !isShown(s))
254
- return;
255
- const val = cols[k][i];
256
- lower[k][i] = base;
257
- if (val == null) {
258
- upper[k][i] = kind === "bars" ? null : base;
259
- return;
260
- }
261
- base += val;
262
- upper[k][i] = base;
263
- });
264
- totals[i] = base;
265
- }
266
- // The value axis fits what is shown, the thresholds and zero.
267
- const shownVals = [];
139
+ const { series, kind, label, empty, formatValue, formatTime, unit, area, stacked, max, min, log, domain, onZoom, onPoint, onReset, onThresholdDrag, syncKey, legend, legendExtra, total, bandOpacity, neutral, hint, testId } = props;
140
+ const size = useChartSize(props.size);
141
+ const spec = CHART_SIZES[size];
142
+ const H = props.height ?? spec.height;
143
+ const axes = spec.yTicks > 0;
144
+ // A sparkline has no room for annotations: it is the shape, nothing else.
145
+ const markers = axes ? props.markers : undefined;
146
+ const thresholds = axes ? props.thresholds : undefined;
147
+ const bands = axes ? props.bands : undefined;
148
+ const uid = useId().replace(/:/g, "");
149
+ const me = useRef(Symbol("chart"));
150
+ const wrapRef = useRef(null);
151
+ const svgRef = useRef(null);
152
+ const [width, setWidth] = useState(600);
153
+ const [hidden, setHidden] = useState(new Set());
154
+ const [hover, setHover] = useState(null);
155
+ const [drag, setDrag] = useState(null);
156
+ const down = useRef(null);
157
+ const dragRule = useRef(null);
158
+ // The plot is drawn at its real width so its text stays crisp; where there is
159
+ // no ResizeObserver (a server render, a test DOM) it keeps the default.
160
+ const hasData = series.some((s) => s.points.length > 0);
161
+ useLayoutEffect(() => {
162
+ const el = wrapRef.current;
163
+ if (!el || typeof ResizeObserver === "undefined")
164
+ return;
165
+ const measure = () => {const w = el.getBoundingClientRect().width;if (w > 0)
166
+ setWidth(Math.max(120, Math.round(w)));};
167
+ measure();
168
+ const ro = new ResizeObserver(measure);
169
+ ro.observe(el);
170
+ return () => ro.disconnect();
171
+ }, [hasData]);
172
+ // Measured series take the ramp in order; a reference, a compare and a
173
+ // neutral series sit outside it. A compare takes its twin's colour.
174
+ const colours = useMemo(() => {
175
+ const byName = new Map();
176
+ let n = 0;
177
+ const out = series.map((s) => {
178
+ if (s.tone)
179
+ return TONE_COLOUR[s.tone];
180
+ if (s.colour)
181
+ return s.colour;
182
+ if (s.reference || neutral?.(s.name))
183
+ return v.faint;
184
+ if (s.compareOf)
185
+ return "";
186
+ return rampToken(n++);
187
+ });
188
+ series.forEach((s, i) => byName.set(s.name, out[i]));
189
+ return series.map((s, i) => out[i] || byName.get(s.compareOf ?? "") || v.faint);
190
+ }, [series, neutral]);
191
+ const names = series.map((s) => s.name).join("\u0000");
192
+ // Only names still on the chart count: a new group-by starts with all shown.
193
+ const muted = useMemo(() => {
194
+ const present = new Set(names.split("\u0000"));
195
+ return new Set([...hidden].filter((n) => present.has(n)));
196
+ }, [hidden, names]);
197
+ const isShown = (s) => !muted.has(s.name) && !(s.compareOf && muted.has(s.compareOf));
198
+ // Every series on the union of their timestamps.
199
+ const aligned = useMemo(() => {
200
+ const xs = [...new Set(series.flatMap((s) => s.points.map((p) => p.t)))].sort((a, b) => a - b);
201
+ const index = new Map(xs.map((x, i) => [x, i]));
202
+ const cols = series.map((s) => {
203
+ const col = new Array(xs.length).fill(null);
204
+ for (const p of s.points) {
205
+ const i = index.get(p.t);
206
+ if (i !== undefined && p.v != null && Number.isFinite(p.v))
207
+ col[i] = p.v;
208
+ }
209
+ return col;
210
+ });
211
+ let step = Infinity;
212
+ for (let i = 1; i < xs.length; i++)
213
+ step = Math.min(step, xs[i] - xs[i - 1]);
214
+ return { xs, cols, step: Number.isFinite(step) ? step : 60_000 };
215
+ }, [series]);
216
+ const { xs, cols, step } = aligned;
217
+ // Sync: another chart's crosshair, at the nearest bucket here.
218
+ useEffect(() => {
219
+ if (!syncKey)
220
+ return;
221
+ const set = syncBus.get(syncKey) ?? new Set();
222
+ syncBus.set(syncKey, set);
223
+ const fn = (t, from) => {
224
+ if (from === me.current)
225
+ return;
226
+ if (t === null) {
227
+ setHover((h) => h && !h.own ? null : h);
228
+ return;
229
+ }
230
+ let best = -1;
231
+ for (let i = 0; i < xs.length; i++)
232
+ if (best < 0 || Math.abs(xs[i] - t) < Math.abs(xs[best] - t))
233
+ best = i;
234
+ if (best >= 0 && Math.abs(xs[best] - t) <= step)
235
+ setHover({ idx: best, py: null, own: false });else
236
+
237
+ setHover((h) => h && !h.own ? null : h);
238
+ };
239
+ set.add(fn);
240
+ return () => {set.delete(fn);};
241
+ }, [syncKey, xs, step]);
242
+ if (xs.length === 0)
243
+ return _jsx(Wrap, { ref: wrapRef, "data-testid": testId, children: _jsx(Note, { "$h": H, children: empty }) });
244
+ const stack = kind === "bars" || !!stacked;
245
+ const stackable = (s) => stack && !s.reference && !s.overlay && !s.compareOf;
246
+ // Stacked parts: each part's lower and upper edge at every bucket.
247
+ const lower = series.map(() => []);
248
+ const upper = series.map(() => []);
249
+ const totals = xs.map(() => 0);
250
+ for (let i = 0; i < xs.length; i++) {
251
+ let base = 0;
268
252
  series.forEach((s, k) => {
269
- if (!isShown(s))
270
- return;
271
- if (stackable(s))
272
- for (const u of upper[k]) {
273
- if (u != null)
274
- shownVals.push(u);
275
- }
276
- else
277
- for (const c of cols[k]) {
278
- if (c != null)
279
- shownVals.push(c);
280
- }
253
+ if (!stackable(s) || !isShown(s))
254
+ return;
255
+ const val = cols[k][i];
256
+ lower[k][i] = base;
257
+ if (val == null) {
258
+ upper[k][i] = kind === "bars" ? null : base;
259
+ return;
260
+ }
261
+ base += val;
262
+ upper[k][i] = base;
281
263
  });
282
- for (const t of thresholds ?? [])
283
- if (Number.isFinite(t.value))
284
- shownVals.push(t.value * 1.05);
285
- let dataMax = shownVals.length ? Math.max(...shownVals) : 1;
286
- let dataMin = shownVals.length ? Math.min(...shownVals, 0) : 0;
287
- if (min !== undefined)
288
- dataMin = min;
289
- if (max !== undefined)
290
- dataMax = max;
291
- let yTicks;
292
- let yLo;
293
- let yHi;
294
- const tickCount = props.height !== undefined && props.height < 120 ? 2 : Math.max(2, spec.yTicks);
295
- if (log) {
296
- const pos = shownVals.filter((n) => n > 0);
297
- const lo = min !== undefined && min > 0 ? min : pos.length ? Math.min(...pos) : 1;
298
- const hi = Math.max(dataMax, lo * 10);
299
- const a = Math.floor(Math.log10(lo));
300
- const b = Math.ceil(Math.log10(hi));
301
- yLo = 10 ** a;
302
- yHi = 10 ** b;
303
- yTicks = [];
304
- const every = Math.max(1, Math.ceil((b - a) / Math.max(1, tickCount - 1)));
305
- for (let e = a; e <= b; e += every)
306
- yTicks.push(10 ** e);
264
+ totals[i] = base;
265
+ }
266
+ // The value axis fits what is shown, the thresholds and zero.
267
+ const shownVals = [];
268
+ series.forEach((s, k) => {
269
+ if (!isShown(s))
270
+ return;
271
+ if (stackable(s))
272
+ for (const u of upper[k]) {
273
+ if (u != null)
274
+ shownVals.push(u);
275
+ } else
276
+
277
+ for (const c of cols[k]) {
278
+ if (c != null)
279
+ shownVals.push(c);
307
280
  }
308
- else {
309
- const nice = niceTicks(dataMin, dataMax, tickCount);
310
- yLo = min ?? nice.min;
311
- yHi = max ?? nice.max;
312
- if (yHi <= yLo)
313
- yHi = yLo + 1;
314
- yTicks = nice.ticks.filter((t) => t >= yLo - 1e-9 && t <= yHi + 1e-9);
281
+ });
282
+ for (const t of thresholds ?? [])
283
+ if (Number.isFinite(t.value))
284
+ shownVals.push(t.value * 1.05);
285
+ let dataMax = shownVals.length ? Math.max(...shownVals) : 1;
286
+ let dataMin = shownVals.length ? Math.min(...shownVals, 0) : 0;
287
+ if (min !== undefined)
288
+ dataMin = min;
289
+ if (max !== undefined)
290
+ dataMax = max;
291
+ let yTicks;
292
+ let yLo;
293
+ let yHi;
294
+ const tickCount = props.height !== undefined && props.height < 120 ? 2 : Math.max(2, spec.yTicks);
295
+ if (log) {
296
+ const pos = shownVals.filter((n) => n > 0);
297
+ const lo = min !== undefined && min > 0 ? min : pos.length ? Math.min(...pos) : 1;
298
+ const hi = Math.max(dataMax, lo * 10);
299
+ const a = Math.floor(Math.log10(lo));
300
+ const b = Math.ceil(Math.log10(hi));
301
+ yLo = 10 ** a;
302
+ yHi = 10 ** b;
303
+ yTicks = [];
304
+ const every = Math.max(1, Math.ceil((b - a) / Math.max(1, tickCount - 1)));
305
+ for (let e = a; e <= b; e += every)
306
+ yTicks.push(10 ** e);
307
+ } else
308
+ {
309
+ const nice = niceTicks(dataMin, dataMax, tickCount);
310
+ yLo = min ?? nice.min;
311
+ yHi = max ?? nice.max;
312
+ if (yHi <= yLo)
313
+ yHi = yLo + 1;
314
+ yTicks = nice.ticks.filter((t) => t >= yLo - 1e-9 && t <= yHi + 1e-9);
315
+ }
316
+ const fmtTip = formatValue ?? (unit ? (n) => formatUnit(n, unit) : tickValue);
317
+ const fmtAxis = formatValue ?? (unit ? (n) => formatUnit(n, unit, true) : tickValue);
318
+ const from = domain?.from ?? xs[0];
319
+ const to = domain?.to ?? (kind === "bars" ? xs[xs.length - 1] + step : xs[xs.length - 1]);
320
+ const tSpan = Math.max(1, to - from);
321
+ const yLabels = axes ? yTicks.map((t) => fmtAxis(t)) : [];
322
+ const padL = axes ? Math.max(28, Math.ceil(Math.max(...yLabels.map((s) => s.length)) * 6.2) + 10) : 0;
323
+ const padR = axes ? 10 : size === "s" ? 3 : 0;
324
+ const markerLabels = spec.markerLabels && (markers?.length ?? 0) > 0;
325
+ const padT = axes ? markerLabels ? 18 : 8 : 3;
326
+ const padB = axes ? 20 : 3;
327
+ const plotW = Math.max(10, width - padL - padR);
328
+ const plotH = Math.max(10, H - padT - padB);
329
+ const bottom = padT + plotH;
330
+ const x = (t) => padL + (t - from) / tSpan * plotW;
331
+ const y = log ?
332
+ (val) => bottom - (Math.log10(Math.max(val, yLo)) - Math.log10(yLo)) / (Math.log10(yHi) - Math.log10(yLo)) * plotH :
333
+ (val) => bottom - (Math.min(Math.max(val, yLo), yHi) - yLo) / (yHi - yLo) * plotH;
334
+ const baseY = y(log ? yLo : Math.max(yLo, Math.min(0, yHi)));
335
+ const f = (n) => n.toFixed(1);
336
+ const measured = series.filter((s) => !s.reference && !s.compareOf);
337
+ const fillSingle = !stack && area && (size === "s" || size === "m" || props.height !== undefined) && measured.length === 1;
338
+ // Pointer → the nearest bucket.
339
+ const idxAt = (clientX) => {
340
+ const rect = svgRef.current?.getBoundingClientRect();
341
+ if (!rect || rect.width === 0)
342
+ return null;
343
+ const px = (clientX - rect.left) / rect.width * width;
344
+ const t = from + (px - padL) / plotW * tSpan;
345
+ let best = 0;
346
+ for (let i = 1; i < xs.length; i++) {
347
+ const centre = kind === "bars" ? xs[i] + step / 2 : xs[i];
348
+ const bestCentre = kind === "bars" ? xs[best] + step / 2 : xs[best];
349
+ if (Math.abs(centre - t) < Math.abs(bestCentre - t))
350
+ best = i;
315
351
  }
316
- const fmtTip = formatValue ?? (unit ? (n) => formatUnit(n, unit) : tickValue);
317
- const fmtAxis = formatValue ?? (unit ? (n) => formatUnit(n, unit, true) : tickValue);
318
- const from = domain?.from ?? xs[0];
319
- const to = domain?.to ?? (kind === "bars" ? xs[xs.length - 1] + step : xs[xs.length - 1]);
320
- const tSpan = Math.max(1, to - from);
321
- const yLabels = axes ? yTicks.map((t) => fmtAxis(t)) : [];
322
- const padL = axes ? Math.max(28, Math.ceil(Math.max(...yLabels.map((s) => s.length)) * 6.2) + 10) : 0;
323
- const padR = axes ? 10 : size === "s" ? 3 : 0;
324
- const markerLabels = spec.markerLabels && (markers?.length ?? 0) > 0;
325
- const padT = axes ? (markerLabels ? 18 : 8) : 3;
326
- const padB = axes ? 20 : 3;
327
- const plotW = Math.max(10, width - padL - padR);
328
- const plotH = Math.max(10, H - padT - padB);
329
- const bottom = padT + plotH;
330
- const x = (t) => padL + ((t - from) / tSpan) * plotW;
331
- const y = log
332
- ? (val) => bottom - ((Math.log10(Math.max(val, yLo)) - Math.log10(yLo)) / (Math.log10(yHi) - Math.log10(yLo))) * plotH
333
- : (val) => bottom - ((Math.min(Math.max(val, yLo), yHi) - yLo) / (yHi - yLo)) * plotH;
334
- const baseY = y(log ? yLo : Math.max(yLo, Math.min(0, yHi)));
335
- const f = (n) => n.toFixed(1);
336
- const measured = series.filter((s) => !s.reference && !s.compareOf);
337
- const fillSingle = !stack && area && (size === "s" || size === "m" || props.height !== undefined) && measured.length === 1;
338
- // Pointer → the nearest bucket.
339
- const idxAt = (clientX) => {
340
- const rect = svgRef.current?.getBoundingClientRect();
341
- if (!rect || rect.width === 0)
342
- return null;
343
- const px = ((clientX - rect.left) / rect.width) * width;
344
- const t = from + ((px - padL) / plotW) * tSpan;
345
- let best = 0;
346
- for (let i = 1; i < xs.length; i++) {
347
- const centre = kind === "bars" ? xs[i] + step / 2 : xs[i];
348
- const bestCentre = kind === "bars" ? xs[best] + step / 2 : xs[best];
349
- if (Math.abs(centre - t) < Math.abs(bestCentre - t))
350
- best = i;
351
- }
352
- return best;
353
- };
354
- const fracAt = (clientX) => {
355
- const rect = svgRef.current?.getBoundingClientRect();
356
- if (!rect || rect.width === 0)
357
- return null;
358
- const px = ((clientX - rect.left) / rect.width) * width;
359
- return Math.min(1, Math.max(0, (px - padL) / plotW));
360
- };
361
- const pyAt = (clientY) => {
362
- const rect = svgRef.current?.getBoundingClientRect();
363
- if (!rect || rect.height === 0)
364
- return null;
365
- return ((clientY - rect.top) / rect.height) * H;
366
- };
367
- /** The series nearest the pointer at a bucket. */
368
- const nearest = (idx, py) => {
369
- let best = null;
370
- let dist = Infinity;
371
- series.forEach((s, k) => {
372
- if (!isShown(s))
373
- return;
374
- if (stackable(s)) {
375
- const lo = lower[k][idx];
376
- const hi = upper[k][idx];
377
- if (lo == null || hi == null)
378
- return;
379
- if (py !== null && py <= y(lo) && py >= y(hi)) {
380
- best = k;
381
- dist = -1;
382
- return;
383
- }
384
- const d = py === null ? Infinity : Math.min(Math.abs(py - y(lo)), Math.abs(py - y(hi)));
385
- if (d < dist) {
386
- dist = d;
387
- best = k;
388
- }
389
- return;
390
- }
391
- const val = cols[k][idx];
392
- if (val == null || s.reference)
393
- return;
394
- const d = py === null ? Infinity : Math.abs(py - y(val));
395
- if (dist >= 0 && d < dist) {
396
- dist = d;
397
- best = k;
398
- }
399
- });
400
- return py === null ? null : best;
401
- };
402
- const setHoverIdx = (h) => {
403
- setHover(h);
404
- publish(syncKey, h ? xs[h.idx] : null, me.current);
405
- };
406
- const pointAt = (idx, py) => {
407
- const k = nearest(idx, py);
408
- const val = k !== null ? cols[k][idx] : null;
409
- return { t: xs[idx], step, series: k !== null ? series[k].name : undefined, value: val ?? undefined };
410
- };
411
- const onPointerMove = (e) => {
412
- if (dragRule.current !== null && onThresholdDrag) {
413
- const py = pyAt(e.clientY);
414
- if (py === null)
415
- return;
416
- const clamped = Math.min(bottom, Math.max(padT, py));
417
- const val = log
418
- ? 10 ** (Math.log10(yLo) + ((bottom - clamped) / plotH) * (Math.log10(yHi) - Math.log10(yLo)))
419
- : yLo + ((bottom - clamped) / plotH) * (yHi - yLo);
420
- onThresholdDrag(dragRule.current, val);
421
- return;
352
+ return best;
353
+ };
354
+ const fracAt = (clientX) => {
355
+ const rect = svgRef.current?.getBoundingClientRect();
356
+ if (!rect || rect.width === 0)
357
+ return null;
358
+ const px = (clientX - rect.left) / rect.width * width;
359
+ return Math.min(1, Math.max(0, (px - padL) / plotW));
360
+ };
361
+ const pyAt = (clientY) => {
362
+ const rect = svgRef.current?.getBoundingClientRect();
363
+ if (!rect || rect.height === 0)
364
+ return null;
365
+ return (clientY - rect.top) / rect.height * H;
366
+ };
367
+ /** The series nearest the pointer at a bucket. */
368
+ const nearest = (idx, py) => {
369
+ let best = null;
370
+ let dist = Infinity;
371
+ series.forEach((s, k) => {
372
+ if (!isShown(s))
373
+ return;
374
+ if (stackable(s)) {
375
+ const lo = lower[k][idx];
376
+ const hi = upper[k][idx];
377
+ if (lo == null || hi == null)
378
+ return;
379
+ if (py !== null && py <= y(lo) && py >= y(hi)) {
380
+ best = k;
381
+ dist = -1;
382
+ return;
422
383
  }
423
- const idx = idxAt(e.clientX);
424
- if (idx === null)
425
- return;
426
- setHoverIdx({ idx, py: pyAt(e.clientY), own: true });
427
- if (drag) {
428
- const fr = fracAt(e.clientX);
429
- if (fr !== null)
430
- setDrag({ from: drag.from, to: fr });
431
- }
432
- };
433
- const onPointerDown = (e) => {
434
- if (e.button !== 0)
435
- return;
436
- down.current = { x: e.clientX, y: e.clientY };
437
- if (onZoom) {
438
- const fr = fracAt(e.clientX);
439
- if (fr !== null)
440
- setDrag({ from: fr, to: fr });
384
+ const d = py === null ? Infinity : Math.min(Math.abs(py - y(lo)), Math.abs(py - y(hi)));
385
+ if (d < dist) {
386
+ dist = d;
387
+ best = k;
441
388
  }
389
+ return;
390
+ }
391
+ const val = cols[k][idx];
392
+ if (val == null || s.reference)
393
+ return;
394
+ const d = py === null ? Infinity : Math.abs(py - y(val));
395
+ if (dist >= 0 && d < dist) {
396
+ dist = d;
397
+ best = k;
398
+ }
399
+ });
400
+ return py === null ? null : best;
401
+ };
402
+ const setHoverIdx = (h) => {
403
+ setHover(h);
404
+ publish(syncKey, h ? xs[h.idx] : null, me.current);
405
+ };
406
+ const pointAt = (idx, py) => {
407
+ const k = nearest(idx, py);
408
+ const val = k !== null ? cols[k][idx] : null;
409
+ return { t: xs[idx], step, series: k !== null ? series[k].name : undefined, value: val ?? undefined };
410
+ };
411
+ const onPointerMove = (e) => {
412
+ if (dragRule.current !== null && onThresholdDrag) {
413
+ const py = pyAt(e.clientY);
414
+ if (py === null)
415
+ return;
416
+ const clamped = Math.min(bottom, Math.max(padT, py));
417
+ const val = log ?
418
+ 10 ** (Math.log10(yLo) + (bottom - clamped) / plotH * (Math.log10(yHi) - Math.log10(yLo))) :
419
+ yLo + (bottom - clamped) / plotH * (yHi - yLo);
420
+ onThresholdDrag(dragRule.current, val);
421
+ return;
422
+ }
423
+ const idx = idxAt(e.clientX);
424
+ if (idx === null)
425
+ return;
426
+ setHoverIdx({ idx, py: pyAt(e.clientY), own: true });
427
+ if (drag) {
428
+ const fr = fracAt(e.clientX);
429
+ if (fr !== null)
430
+ setDrag({ from: drag.from, to: fr });
431
+ }
432
+ };
433
+ const onPointerDown = (e) => {
434
+ if (e.button !== 0)
435
+ return;
436
+ down.current = { x: e.clientX, y: e.clientY };
437
+ if (onZoom) {
438
+ const fr = fracAt(e.clientX);
439
+ if (fr !== null)
440
+ setDrag({ from: fr, to: fr });
441
+ }
442
+ };
443
+ const onPointerUp = (e) => {
444
+ if (dragRule.current !== null) {
445
+ dragRule.current = null;
446
+ return;
447
+ }
448
+ const start = down.current;
449
+ down.current = null;
450
+ if (drag && onZoom && Math.abs(drag.to - drag.from) * plotW > 4) {
451
+ const a = from + Math.min(drag.from, drag.to) * tSpan;
452
+ const b = from + Math.max(drag.from, drag.to) * tSpan;
453
+ setDrag(null);
454
+ onZoom(new Date(a), new Date(b));
455
+ return;
456
+ }
457
+ setDrag(null);
458
+ if (onPoint && start && Math.abs(e.clientX - start.x) <= 3) {
459
+ const idx = idxAt(e.clientX);
460
+ if (idx !== null)
461
+ onPoint(pointAt(idx, pyAt(e.clientY)), { clientX: e.clientX, clientY: e.clientY });
462
+ }
463
+ };
464
+ const onContextMenu = (e) => {
465
+ if (!onPoint)
466
+ return;
467
+ e.preventDefault();
468
+ const idx = idxAt(e.clientX);
469
+ if (idx !== null)
470
+ onPoint(pointAt(idx, pyAt(e.clientY)), { clientX: e.clientX, clientY: e.clientY });
471
+ };
472
+ const onKey = (e) => {
473
+ const last = xs.length - 1;
474
+ const cur = hover?.idx ?? last;
475
+ let next = cur;
476
+ if (e.key === "ArrowLeft")
477
+ next = Math.max(0, cur - 1);else
478
+ if (e.key === "ArrowRight")
479
+ next = Math.min(last, cur + 1);else
480
+ if (e.key === "Home")
481
+ next = 0;else
482
+ if (e.key === "End")
483
+ next = last;else
484
+ if (e.key === "Escape")
485
+ next = null;else
486
+ if (e.key === "Enter" && onPoint && hover) {
487
+ const rect = svgRef.current?.getBoundingClientRect();
488
+ onPoint(pointAt(hover.idx, null), { clientX: (rect?.left ?? 0) + x(xs[hover.idx]) / width * (rect?.width ?? width), clientY: rect?.top ?? 0 });
489
+ return;
490
+ } else
491
+
492
+ return;
493
+ e.preventDefault();
494
+ setHoverIdx(next === null ? null : { idx: next, py: null, own: true });
495
+ };
496
+ const toggle = (name, solo) => setHidden(() => {
497
+ const prev = muted;
498
+ const measuredNames = measured.map((s) => s.name);
499
+ if (solo) {
500
+ const soloed = measuredNames.every((n) => n === name ? !prev.has(n) : prev.has(n));
501
+ return soloed ? new Set() : new Set(measuredNames.filter((n) => n !== name));
502
+ }
503
+ const next = new Set(prev);
504
+ if (next.has(name))
505
+ next.delete(name);else
506
+
507
+ next.add(name);
508
+ // Hiding every measured series leaves a chart with no axis to read; treat
509
+ // the last one as "show all again". References and compares do not count.
510
+ const off = measuredNames.filter((n) => next.has(n)).length;
511
+ return measuredNames.length > 0 && off === measuredNames.length ? new Set() : next;
512
+ });
513
+ // Time ticks, thinned so two labels never touch.
514
+ const xTickMarks = axes ?
515
+ timeTicks(from, to, Math.min(spec.xTicks, Math.max(2, Math.floor(plotW / 70))), formatTime) :
516
+ [];
517
+ const tipTime = formatTime ?? timeDetail(step);
518
+ // The hovered bucket's rows: every shown series worst-first (the stacked
519
+ // charts top-first under a total), a compare read as its twin's delta.
520
+ const tip = (() => {
521
+ if (!hover || drag || !hover.own)
522
+ return null;
523
+ const idx = hover.idx;
524
+ const focus = nearest(idx, hover.py);
525
+ const twins = new Map();
526
+ series.forEach((s, k) => {if (s.compareOf && isShown(s))
527
+ twins.set(s.compareOf, k);});
528
+ const present = new Set(series.map((s) => s.name));
529
+ const rows = series.
530
+ map((s, k) => ({ s, k, val: cols[k][idx] ?? null })).
531
+ filter((r) => isShown(r.s) && !(r.s.compareOf && present.has(r.s.compareOf)));
532
+ if (stack)
533
+ rows.reverse();else
534
+
535
+ rows.sort((a, b) => (a.s.reference ? 1 : 0) - (b.s.reference ? 1 : 0) || (b.val ?? -Infinity) - (a.val ?? -Infinity));
536
+ if (!rows.length)
537
+ return null;
538
+ const shownRows = rows.slice(0, MAX_TIP_ROWS);
539
+ const left = x(xs[idx] + (kind === "bars" ? step / 2 : 0));
540
+ const flip = left > width * 0.6;
541
+ const cmpName = [...twins.values()].map((k) => series[k].name)[0];
542
+ const vs = cmpName && cmpName.includes(" · ") ? ` · vs ${cmpName.split(" · ").pop()}` : "";
543
+ return _jsxs(Tip, { style: flip ? { right: width - left + 12 } : { left: left + 12 }, "data-testid": testId ? `${testId}-tooltip` : undefined, children: [_jsxs("div", { className: "t", children: [tipTime(xs[idx]), step > 0 && xs.length > 1 ? ` · ${stepLabel(step)} bucket` : "", vs] }), total && stack ? _jsxs(TipRow, { "$strong": true, children: [_jsx("span", {}), _jsx("span", { className: "n", children: "Total" }), _jsx("span", { className: "val", children: fmtTip(totals[idx] ?? 0) }), _jsx("span", {})] }) : null, shownRows.map((r) => {
544
+ const twin = twins.get(r.s.name);
545
+ const was = twin !== undefined ? cols[twin][idx] : null;
546
+ const delta = r.val != null && was != null ? formatDelta(r.val, was) : "";
547
+ const dir = delta.startsWith("+") ? "up" : delta.startsWith("−") ? "down" : "";
548
+ return _jsxs(TipRow, { "$focus": focus === r.k && series.length > 1, children: [_jsx(TipSwatch, { "$c": colours[r.k], "$dashed": r.s.reference || r.s.dashed || !!r.s.compareOf }), _jsx("span", { className: "n", children: r.s.name }), _jsx("span", { className: "val", children: r.val == null ? "—" : fmtTip(r.val) }), _jsx("span", { className: `delta ${dir}`, children: delta })] }, r.s.name);
549
+ }), rows.length > shownRows.length ? _jsxs("div", { className: "more", children: ["+", rows.length - shownRows.length, " more"] }) : null] });
550
+ })();
551
+ // Marker labels at rest (L/XL) skip one that would touch the last kept.
552
+ const markerX = (markers ?? []).map((m) => x(m.at));
553
+ const markerKeep = spaced(markerX, 46);
554
+ const hoverX = hover && !drag ? x(xs[hover.idx] + (kind === "bars" ? step / 2 : 0)) : null;
555
+ const barW = Math.max(1, step / tSpan * plotW);
556
+ const barInset = barW > 4 ? Math.min(2, barW * 0.12) : 0;
557
+ const lastValue = (k) => {
558
+ const c = cols[k];
559
+ for (let i = c.length - 1; i >= 0; i--)
560
+ if (c[i] != null)
561
+ return c[i];
562
+ return null;
563
+ };
564
+ const showLegend = (legend ?? spec.legend) && size !== "s";
565
+ const legendItems = series.map((s, k) => {
566
+ const last = lastValue(k);
567
+ return {
568
+ key: s.name, name: s.name, colour: colours[k], value: last == null ? undefined : fmtTip(last),
569
+ dashed: s.reference || s.dashed || !!s.compareOf, faded: !!s.compareOf, off: !isShown(s)
442
570
  };
443
- const onPointerUp = (e) => {
444
- if (dragRule.current !== null) {
445
- dragRule.current = null;
446
- return;
447
- }
448
- const start = down.current;
449
- down.current = null;
450
- if (drag && onZoom && Math.abs(drag.to - drag.from) * plotW > 4) {
451
- const a = from + Math.min(drag.from, drag.to) * tSpan;
452
- const b = from + Math.max(drag.from, drag.to) * tSpan;
571
+ });
572
+ const thresholdNotes = (thresholds ?? []).filter((t) => Number.isFinite(t.value));
573
+ return _jsxs(Wrap, { "data-testid": testId, children: [_jsxs(Plot, { ref: wrapRef, children: [_jsxs(PlotSvg, { ref: svgRef, width: "100%", height: H, viewBox: `0 0 ${width} ${H}`, preserveAspectRatio: "none", role: "img", "aria-label": `${label}. Arrow keys step through the buckets.`, tabIndex: size === "s" ? -1 : 0, "$interactive": size !== "s", onPointerMove: onPointerMove, onPointerDown: onPointerDown, onPointerUp: onPointerUp, onPointerLeave: () => {if (dragRule.current === null) {
574
+ setHoverIdx(null);
453
575
  setDrag(null);
454
- onZoom(new Date(a), new Date(b));
455
- return;
456
- }
457
- setDrag(null);
458
- if (onPoint && start && Math.abs(e.clientX - start.x) <= 3) {
459
- const idx = idxAt(e.clientX);
460
- if (idx !== null)
461
- onPoint(pointAt(idx, pyAt(e.clientY)), { clientX: e.clientX, clientY: e.clientY });
462
- }
463
- };
464
- const onContextMenu = (e) => {
465
- if (!onPoint)
466
- return;
467
- e.preventDefault();
468
- const idx = idxAt(e.clientX);
469
- if (idx !== null)
470
- onPoint(pointAt(idx, pyAt(e.clientY)), { clientX: e.clientX, clientY: e.clientY });
471
- };
472
- const onKey = (e) => {
473
- const last = xs.length - 1;
474
- const cur = hover?.idx ?? last;
475
- let next = cur;
476
- if (e.key === "ArrowLeft")
477
- next = Math.max(0, cur - 1);
478
- else if (e.key === "ArrowRight")
479
- next = Math.min(last, cur + 1);
480
- else if (e.key === "Home")
481
- next = 0;
482
- else if (e.key === "End")
483
- next = last;
484
- else if (e.key === "Escape")
485
- next = null;
486
- else if (e.key === "Enter" && onPoint && hover) {
487
- const rect = svgRef.current?.getBoundingClientRect();
488
- onPoint(pointAt(hover.idx, null), { clientX: (rect?.left ?? 0) + (x(xs[hover.idx]) / width) * (rect?.width ?? width), clientY: rect?.top ?? 0 });
489
- return;
490
- }
491
- else
492
- return;
493
- e.preventDefault();
494
- setHoverIdx(next === null ? null : { idx: next, py: null, own: true });
495
- };
496
- const toggle = (name, solo) => setHidden(() => {
497
- const prev = muted;
498
- const measuredNames = measured.map((s) => s.name);
499
- if (solo) {
500
- const soloed = measuredNames.every((n) => n === name ? !prev.has(n) : prev.has(n));
501
- return soloed ? new Set() : new Set(measuredNames.filter((n) => n !== name));
502
- }
503
- const next = new Set(prev);
504
- if (next.has(name))
505
- next.delete(name);
506
- else
507
- next.add(name);
508
- // Hiding every measured series leaves a chart with no axis to read; treat
509
- // the last one as "show all again". References and compares do not count.
510
- const off = measuredNames.filter((n) => next.has(n)).length;
511
- return measuredNames.length > 0 && off === measuredNames.length ? new Set() : next;
512
- });
513
- // Time ticks, thinned so two labels never touch.
514
- const xTickMarks = axes
515
- ? timeTicks(from, to, Math.min(spec.xTicks, Math.max(2, Math.floor(plotW / 70))), formatTime)
516
- : [];
517
- const tipTime = formatTime ?? timeDetail(step);
518
- // The hovered bucket's rows: every shown series worst-first (the stacked
519
- // charts top-first under a total), a compare read as its twin's delta.
520
- const tip = (() => {
521
- if (!hover || drag || !hover.own)
522
- return null;
523
- const idx = hover.idx;
524
- const focus = nearest(idx, hover.py);
525
- const twins = new Map();
526
- series.forEach((s, k) => { if (s.compareOf && isShown(s))
527
- twins.set(s.compareOf, k); });
528
- const present = new Set(series.map((s) => s.name));
529
- const rows = series
530
- .map((s, k) => ({ s, k, val: cols[k][idx] ?? null }))
531
- .filter((r) => isShown(r.s) && !(r.s.compareOf && present.has(r.s.compareOf)));
532
- if (stack)
533
- rows.reverse();
534
- else
535
- rows.sort((a, b) => (a.s.reference ? 1 : 0) - (b.s.reference ? 1 : 0) || (b.val ?? -Infinity) - (a.val ?? -Infinity));
536
- if (!rows.length)
576
+ }}, onContextMenu: onContextMenu, onDoubleClick: onReset ? (e) => {e.preventDefault();onReset();} : undefined, onKeyDown: onKey, onFocus: () => {if (!hover && size !== "s")
577
+ setHoverIdx({ idx: xs.length - 1, py: null, own: true });}, onBlur: () => setHoverIdx(null), children: [bands?.some((b) => b.hatch) ? _jsx("defs", { children: _jsx("pattern", { id: `hatch-${uid}`, width: "6", height: "6", patternUnits: "userSpaceOnUse", patternTransform: "rotate(45)", children: _jsx("line", { x1: "0", y1: "0", x2: "0", y2: "6", stroke: v.line2, strokeWidth: 2 }) }) }) : null, (bands ?? []).map((b, i) => {
578
+ const a = Math.max(padL, x(b.from));
579
+ const z = Math.min(padL + plotW, x(b.to));
580
+ if (z <= a)
581
+ return null;
582
+ return _jsx("rect", { x: a, y: padT, width: Math.max(1, z - a), height: plotH, fill: b.hatch ? `url(#hatch-${uid})` : b.colour ?? TONE_COLOUR[b.tone ?? "brand"], ...(b.hatch || b.colour ? {} : { opacity: 0.07 }), children: b.label ? _jsx("title", { children: b.label }) : null }, `b${i}`);
583
+ }), axes ? yTicks.map((t, i) => _jsxs("g", { children: [Math.abs(y(t) - bottom) > 0.5 ? _jsx("line", { x1: padL, x2: padL + plotW, y1: f(y(t)), y2: f(y(t)), stroke: v.line, strokeWidth: 1 }) : null, _jsx("text", { x: padL - 6, y: y(t) + 3.5, textAnchor: "end", fontSize: 10, fill: v.faint, children: yLabels[i] })] }, `y${t}`)) : null, axes ? _jsx("line", { x1: padL, x2: padL + plotW, y1: bottom, y2: bottom, stroke: v.line2, strokeWidth: 1 }) : null, xTickMarks.map((tk, i) => {
584
+ const px = x(tk.t);
585
+ if (px < padL - 1 || px > padL + plotW + 1)
586
+ return null;
587
+ const anchor = px - padL < 20 ? "start" : padL + plotW - px < 20 ? "end" : "middle";
588
+ return _jsx("text", { x: px, y: H - 5, fontSize: 10, fill: v.faint, opacity: tk.dim ? 0.6 : 1, textAnchor: anchor, children: tk.label }, `x${i}`);
589
+ }), kind === "bars" ? _jsx("g", { children: series.map((s, k) => {
590
+ if (!stackable(s) || !isShown(s))
537
591
  return null;
538
- const shownRows = rows.slice(0, MAX_TIP_ROWS);
539
- const left = x(xs[idx] + (kind === "bars" ? step / 2 : 0));
540
- const flip = left > width * 0.6;
541
- const cmpName = [...twins.values()].map((k) => series[k].name)[0];
542
- const vs = cmpName && cmpName.includes(" · ") ? ` · vs ${cmpName.split(" · ").pop()}` : "";
543
- return (_jsxs(Tip, { style: flip ? { right: width - left + 12 } : { left: left + 12 }, "data-testid": testId ? `${testId}-tooltip` : undefined, children: [_jsxs("div", { className: "t", children: [tipTime(xs[idx]), step > 0 && xs.length > 1 ? ` · ${stepLabel(step)} bucket` : "", vs] }), total && stack ? (_jsxs(TipRow, { "$strong": true, children: [_jsx("span", {}), _jsx("span", { className: "n", children: "Total" }), _jsx("span", { className: "val", children: fmtTip(totals[idx] ?? 0) }), _jsx("span", {})] })) : null, shownRows.map((r) => {
544
- const twin = twins.get(r.s.name);
545
- const was = twin !== undefined ? cols[twin][idx] : null;
546
- const delta = r.val != null && was != null ? formatDelta(r.val, was) : "";
547
- const dir = delta.startsWith("+") ? "up" : delta.startsWith("−") ? "down" : "";
548
- return (_jsxs(TipRow, { "$focus": focus === r.k && series.length > 1, children: [_jsx(TipSwatch, { "$c": colours[r.k], "$dashed": r.s.reference || r.s.dashed || !!r.s.compareOf }), _jsx("span", { className: "n", children: r.s.name }), _jsx("span", { className: "val", children: r.val == null ? "—" : fmtTip(r.val) }), _jsx("span", { className: `delta ${dir}`, children: delta })] }, r.s.name));
549
- }), rows.length > shownRows.length ? _jsxs("div", { className: "more", children: ["+", rows.length - shownRows.length, " more"] }) : null] }));
550
- })();
551
- // Marker labels at rest (L/XL) skip one that would touch the last kept.
552
- const markerX = (markers ?? []).map((m) => x(m.at));
553
- const markerKeep = spaced(markerX, 46);
554
- const hoverX = hover && !drag ? x(xs[hover.idx] + (kind === "bars" ? step / 2 : 0)) : null;
555
- const barW = Math.max(1, (step / tSpan) * plotW);
556
- const barInset = barW > 4 ? Math.min(2, barW * 0.12) : 0;
557
- const lastValue = (k) => {
558
- const c = cols[k];
559
- for (let i = c.length - 1; i >= 0; i--)
560
- if (c[i] != null)
561
- return c[i];
562
- return null;
563
- };
564
- const showLegend = (legend ?? spec.legend) && size !== "s";
565
- const legendItems = series.map((s, k) => {
566
- const last = lastValue(k);
567
- return {
568
- key: s.name, name: s.name, colour: colours[k], value: last == null ? undefined : fmtTip(last),
569
- dashed: s.reference || s.dashed || !!s.compareOf, faded: !!s.compareOf, off: !isShown(s),
570
- };
571
- });
572
- const thresholdNotes = (thresholds ?? []).filter((t) => Number.isFinite(t.value));
573
- return (_jsxs(Wrap, { "data-testid": testId, children: [_jsxs(Plot, { ref: wrapRef, children: [_jsxs(PlotSvg, { ref: svgRef, width: "100%", height: H, viewBox: `0 0 ${width} ${H}`, preserveAspectRatio: "none", role: "img", "aria-label": `${label}. Arrow keys step through the buckets.`, tabIndex: size === "s" ? -1 : 0, "$interactive": size !== "s", onPointerMove: onPointerMove, onPointerDown: onPointerDown, onPointerUp: onPointerUp, onPointerLeave: () => { if (dragRule.current === null) {
574
- setHoverIdx(null);
575
- setDrag(null);
576
- } }, onContextMenu: onContextMenu, onDoubleClick: onReset ? (e) => { e.preventDefault(); onReset(); } : undefined, onKeyDown: onKey, onFocus: () => { if (!hover && size !== "s")
577
- setHoverIdx({ idx: xs.length - 1, py: null, own: true }); }, onBlur: () => setHoverIdx(null), children: [bands?.some((b) => b.hatch) ? (_jsx("defs", { children: _jsx("pattern", { id: `hatch-${uid}`, width: "6", height: "6", patternUnits: "userSpaceOnUse", patternTransform: "rotate(45)", children: _jsx("line", { x1: "0", y1: "0", x2: "0", y2: "6", stroke: v.line2, strokeWidth: 2 }) }) })) : null, (bands ?? []).map((b, i) => {
578
- const a = Math.max(padL, x(b.from));
579
- const z = Math.min(padL + plotW, x(b.to));
580
- if (z <= a)
581
- return null;
582
- return (_jsx("rect", { x: a, y: padT, width: Math.max(1, z - a), height: plotH, fill: b.hatch ? `url(#hatch-${uid})` : b.colour ?? TONE_COLOUR[b.tone ?? "brand"], ...(b.hatch || b.colour ? {} : { opacity: 0.07 }), children: b.label ? _jsx("title", { children: b.label }) : null }, `b${i}`));
583
- }), axes ? yTicks.map((t, i) => (_jsxs("g", { children: [Math.abs(y(t) - bottom) > 0.5 ? _jsx("line", { x1: padL, x2: padL + plotW, y1: f(y(t)), y2: f(y(t)), stroke: v.line, strokeWidth: 1 }) : null, _jsx("text", { x: padL - 6, y: y(t) + 3.5, textAnchor: "end", fontSize: 10, fill: v.faint, children: yLabels[i] })] }, `y${t}`))) : null, axes ? _jsx("line", { x1: padL, x2: padL + plotW, y1: bottom, y2: bottom, stroke: v.line2, strokeWidth: 1 }) : null, xTickMarks.map((tk, i) => {
584
- const px = x(tk.t);
585
- if (px < padL - 1 || px > padL + plotW + 1)
586
- return null;
587
- const anchor = px - padL < 20 ? "start" : padL + plotW - px < 20 ? "end" : "middle";
588
- return (_jsx("text", { x: px, y: H - 5, fontSize: 10, fill: v.faint, opacity: tk.dim ? 0.6 : 1, textAnchor: anchor, children: tk.label }, `x${i}`));
589
- }), kind === "bars" ? (_jsx("g", { children: series.map((s, k) => {
590
- if (!stackable(s) || !isShown(s))
591
- return null;
592
- return (_jsx("g", { fill: colours[k], children: xs.map((t, i) => {
593
- const lo = lower[k][i];
594
- const hi = upper[k][i];
595
- if (lo == null || hi == null || hi === lo)
596
- return null;
597
- const top = y(hi);
598
- const h = Math.max(0.5, y(lo) - top);
599
- return _jsx("rect", { x: f(x(t) + barInset), y: f(top), width: f(Math.max(0.5, barW - barInset * 2)), height: f(h), opacity: hover && hover.idx !== i && hover.own ? 0.7 : 1 }, t);
600
- }) }, s.name));
601
- }) })) : null, stack && kind === "line" ? series.map((s, k) => {
602
- if (!stackable(s) || !isShown(s))
603
- return null;
604
- const up = upper[k];
605
- const lo = lower[k];
606
- const top = xs.map((t, i) => `${f(x(t))} ${f(y(up[i] ?? 0))}`);
607
- const bot = xs.map((t, i) => `${f(x(t))} ${f(y(lo[i] ?? 0))}`).reverse();
608
- return (_jsxs("g", { children: [_jsx("path", { d: `M ${top.join(" L ")} L ${bot.join(" L ")} Z`, fill: colours[k], fillOpacity: bandOpacity ?? 0.35, stroke: "none" }), _jsx("path", { d: `M ${top.join(" L ")}`, fill: "none", stroke: bandOpacity && bandOpacity > 0.6 ? v.surface : colours[k], strokeWidth: bandOpacity && bandOpacity > 0.6 ? 1.2 : 1.8, strokeLinejoin: "round", strokeLinecap: "round" })] }, s.name));
609
- }) : null, series.map((s, k) => {
610
- if (!isShown(s) || stackable(s))
611
- return null;
612
- const runs = runsOf(xs, cols[k]);
613
- const colour = colours[k];
614
- const dashed = s.reference || s.dashed || !!s.compareOf;
615
- const xOff = kind === "bars" ? step / 2 : 0;
616
- return (_jsxs("g", { opacity: s.compareOf ? 0.45 : 1, children: [fillSingle && !s.reference && !s.compareOf ? runs.filter((r) => r.length > 1).map((r, j) => (_jsx("path", { d: `M ${f(x(r[0].t + xOff))} ${f(baseY)} ${r.map((p) => `L ${f(x(p.t + xOff))} ${f(y(p.v))}`).join(" ")} L ${f(x(r[r.length - 1].t + xOff))} ${f(baseY)} Z`, fill: colour, fillOpacity: 0.12, stroke: "none" }, `a${j}`))) : null, runs.map((r, j) => r.length > 1
617
- ? _jsx("path", { d: r.map((p, q) => `${q === 0 ? "M" : "L"} ${f(x(p.t + xOff))} ${f(y(p.v))}`).join(" "), fill: "none", stroke: colour, strokeWidth: size === "s" ? 1.5 : 1.8, strokeLinejoin: "round", strokeLinecap: "round", ...(dashed ? { strokeDasharray: "5 4" } : {}) }, j)
618
- // a lone sample between two gaps has no line to draw; it is a dot
619
- : _jsx("circle", { cx: f(x(r[0].t + xOff)), cy: f(y(r[0].v)), r: 1.8, fill: colour }, j)), size === "s" && !s.compareOf && !s.reference && runs.length ? (() => {
620
- const lastRun = runs[runs.length - 1];
621
- const p = lastRun[lastRun.length - 1];
622
- return _jsx("circle", { cx: f(x(p.t + xOff)), cy: f(y(p.v)), r: 2.2, fill: colour });
623
- })() : null] }, s.name));
624
- }), (thresholds ?? []).map((t, i) => {
625
- if (!Number.isFinite(t.value))
626
- return null;
627
- const ty = y(t.value);
628
- const colour = TONE_COLOUR[t.tone ?? "crit"];
629
- // Two rules close together: the lower one's label goes under its line.
630
- const crowded = (thresholds ?? []).some((o, j) => j !== i && Number.isFinite(o.value) && y(o.value) < ty && ty - y(o.value) < 13);
631
- const labelY = crowded ? ty + 11 : ty - 4;
632
- return (_jsxs("g", { children: [_jsx("line", { x1: padL, x2: padL + plotW, y1: f(ty), y2: f(ty), stroke: colour, strokeWidth: 1, strokeDasharray: "4 3" }), axes ? (_jsx("text", { x: padL + plotW - 2, y: labelY, textAnchor: "end", fontSize: 10, fill: colour, children: `${thresholdWord(t)} · ${fmtAxis(t.value)}` })) : null, onThresholdDrag ? (_jsx("rect", { x: padL, y: ty - 5, width: plotW, height: 10, fill: "transparent", style: { cursor: "ns-resize" }, role: "slider", tabIndex: 0, "aria-label": `${thresholdWord(t)} threshold`, "aria-valuenow": t.value, "aria-valuetext": fmtTip(t.value), "data-testid": testId ? `${testId}-drag-${thresholdWord(t)}` : undefined, onPointerDown: (e) => { e.stopPropagation(); dragRule.current = i; (e.currentTarget.ownerSVGElement ?? e.currentTarget).setPointerCapture?.(e.pointerId); }, onKeyDown: (e) => {
633
- if (e.key !== "ArrowUp" && e.key !== "ArrowDown")
634
- return;
635
- e.preventDefault();
636
- e.stopPropagation();
637
- const d = Math.abs(t.value) > 0 ? Math.abs(t.value) * 0.05 : 0.01;
638
- onThresholdDrag(i, t.value + (e.key === "ArrowUp" ? d : -d));
639
- } })) : null] }, `t${i}`));
640
- }), (markers ?? []).map((m, i) => {
641
- const mx = markerX[i];
642
- if (mx < padL - 0.5 || mx > padL + plotW + 0.5)
643
- return null;
644
- const colour = markerColour(m);
645
- const near = hoverX !== null && Math.abs(hoverX - mx) < 8;
646
- const labelled = (markerLabels && markerKeep[i]) || near;
647
- return (_jsxs("g", { "data-marker": m.kind ?? "deploy", children: [_jsx("title", { children: m.label }), _jsx("line", { x1: f(mx), x2: f(mx), y1: padT, y2: bottom, stroke: colour, strokeWidth: 1, strokeDasharray: "2 3", opacity: 0.8 }), m.kind === "alert"
648
- ? _jsx("rect", { x: mx - 1, y: bottom - 6, width: 2, height: 7, fill: colour })
649
- : m.kind === "note"
650
- ? _jsx("circle", { cx: mx, cy: bottom, r: 2.6, fill: colour })
651
- : _jsx("polygon", { points: `${f(mx)},${f(bottom - 6)} ${f(mx - 4.5)},${f(bottom + 1.5)} ${f(mx + 4.5)},${f(bottom + 1.5)}`, fill: colour }), labelled && axes ? (_jsx("text", { x: mx, y: padT - 5, textAnchor: mx > padL + plotW - 30 ? "end" : mx < padL + 30 ? "start" : "middle", fontSize: 10, fill: colour, children: m.label })) : null] }, `m${i}`));
652
- }), drag && Math.abs(drag.to - drag.from) * plotW > 1 ? (_jsx("rect", { x: padL + Math.min(drag.from, drag.to) * plotW, width: Math.abs(drag.to - drag.from) * plotW, y: padT, height: plotH, fill: v.brand12, stroke: v.brand55, strokeWidth: 1 })) : null, hoverX !== null && size !== "s" ? (_jsx("line", { x1: f(hoverX), x2: f(hoverX), y1: padT, y2: bottom, stroke: v.line2, strokeWidth: 1, strokeDasharray: hover?.own ? undefined : "3 3" })) : null, hover && !drag && kind === "line" && size !== "s" ? series.map((s, k) => {
653
- if (!isShown(s))
654
- return null;
655
- const val = stackable(s) ? upper[k][hover.idx] : cols[k][hover.idx];
656
- if (val == null)
657
- return null;
658
- return _jsx("circle", { cx: f(x(xs[hover.idx])), cy: f(y(val)), r: 3, fill: colours[k], stroke: v.surface, strokeWidth: 1.5, opacity: s.compareOf ? 0.6 : 1 }, `h${k}`);
659
- }) : null] }), tip] }), showLegend && (series.length > 1 || thresholdNotes.length > 0 || legendExtra || legend) ? (_jsx(LegendChips, { items: legendItems, onToggle: toggle, notes: _jsxs(_Fragment, { children: [thresholdNotes.length ? (_jsx(LegendNote, { colour: TONE_COLOUR[thresholdNotes[0].tone ?? "crit"], dashed: true, children: thresholdNotes.map((t) => `${thresholdWord(t)} ${fmtTip(t.value)}`).join(" · ") })) : null, legendExtra] }) })) : null, hint !== undefined ? hint : onZoom && size !== "s" && size !== "m" ? _jsx(ChartHint, { children: "Drag across the chart to zoom into a window." }) : null] }));
592
+ return _jsx("g", { fill: colours[k], children: xs.map((t, i) => {
593
+ const lo = lower[k][i];
594
+ const hi = upper[k][i];
595
+ if (lo == null || hi == null || hi === lo)
596
+ return null;
597
+ const top = y(hi);
598
+ const h = Math.max(0.5, y(lo) - top);
599
+ return _jsx("rect", { x: f(x(t) + barInset), y: f(top), width: f(Math.max(0.5, barW - barInset * 2)), height: f(h), opacity: hover && hover.idx !== i && hover.own ? 0.7 : 1 }, t);
600
+ }) }, s.name);
601
+ }) }) : null, stack && kind === "line" ? series.map((s, k) => {
602
+ if (!stackable(s) || !isShown(s))
603
+ return null;
604
+ const up = upper[k];
605
+ const lo = lower[k];
606
+ const top = xs.map((t, i) => `${f(x(t))} ${f(y(up[i] ?? 0))}`);
607
+ const bot = xs.map((t, i) => `${f(x(t))} ${f(y(lo[i] ?? 0))}`).reverse();
608
+ return _jsxs("g", { children: [_jsx("path", { d: `M ${top.join(" L ")} L ${bot.join(" L ")} Z`, fill: colours[k], fillOpacity: bandOpacity ?? 0.35, stroke: "none" }), _jsx("path", { d: `M ${top.join(" L ")}`, fill: "none", stroke: bandOpacity && bandOpacity > 0.6 ? v.surface : colours[k], strokeWidth: bandOpacity && bandOpacity > 0.6 ? 1.2 : 1.8, strokeLinejoin: "round", strokeLinecap: "round" })] }, s.name);
609
+ }) : null, series.map((s, k) => {
610
+ if (!isShown(s) || stackable(s))
611
+ return null;
612
+ const runs = runsOf(xs, cols[k]);
613
+ const colour = colours[k];
614
+ const dashed = s.reference || s.dashed || !!s.compareOf;
615
+ const xOff = kind === "bars" ? step / 2 : 0;
616
+ return _jsxs("g", { opacity: s.compareOf ? 0.45 : 1, children: [fillSingle && !s.reference && !s.compareOf ? runs.filter((r) => r.length > 1).map((r, j) => _jsx("path", { d: `M ${f(x(r[0].t + xOff))} ${f(baseY)} ${r.map((p) => `L ${f(x(p.t + xOff))} ${f(y(p.v))}`).join(" ")} L ${f(x(r[r.length - 1].t + xOff))} ${f(baseY)} Z`, fill: colour, fillOpacity: 0.12, stroke: "none" }, `a${j}`)) : null, runs.map((r, j) => r.length > 1 ?
617
+ _jsx("path", { d: r.map((p, q) => `${q === 0 ? "M" : "L"} ${f(x(p.t + xOff))} ${f(y(p.v))}`).join(" "), fill: "none", stroke: colour, strokeWidth: size === "s" ? 1.5 : 1.8, strokeLinejoin: "round", strokeLinecap: "round", ...(dashed ? { strokeDasharray: "5 4" } : {}) }, j)
618
+ // a lone sample between two gaps has no line to draw; it is a dot
619
+ : _jsx("circle", { cx: f(x(r[0].t + xOff)), cy: f(y(r[0].v)), r: 1.8, fill: colour }, j)), size === "s" && !s.compareOf && !s.reference && runs.length ? (() => {
620
+ const lastRun = runs[runs.length - 1];
621
+ const p = lastRun[lastRun.length - 1];
622
+ return _jsx("circle", { cx: f(x(p.t + xOff)), cy: f(y(p.v)), r: 2.2, fill: colour });
623
+ })() : null] }, s.name);
624
+ }), (thresholds ?? []).map((t, i) => {
625
+ if (!Number.isFinite(t.value))
626
+ return null;
627
+ const ty = y(t.value);
628
+ const colour = TONE_COLOUR[t.tone ?? "crit"];
629
+ // Two rules close together: the lower one's label goes under its line.
630
+ const crowded = (thresholds ?? []).some((o, j) => j !== i && Number.isFinite(o.value) && y(o.value) < ty && ty - y(o.value) < 13);
631
+ const labelY = crowded ? ty + 11 : ty - 4;
632
+ return _jsxs("g", { children: [_jsx("line", { x1: padL, x2: padL + plotW, y1: f(ty), y2: f(ty), stroke: colour, strokeWidth: 1, strokeDasharray: "4 3" }), axes ? _jsx("text", { x: padL + plotW - 2, y: labelY, textAnchor: "end", fontSize: 10, fill: colour, children: `${thresholdWord(t)} · ${fmtAxis(t.value)}` }) : null, onThresholdDrag ? _jsx("rect", { x: padL, y: ty - 5, width: plotW, height: 10, fill: "transparent", style: { cursor: "ns-resize" }, role: "slider", tabIndex: 0, "aria-label": `${thresholdWord(t)} threshold`, "aria-valuenow": t.value, "aria-valuetext": fmtTip(t.value), "data-testid": testId ? `${testId}-drag-${thresholdWord(t)}` : undefined, onPointerDown: (e) => {e.stopPropagation();dragRule.current = i;(e.currentTarget.ownerSVGElement ?? e.currentTarget).setPointerCapture?.(e.pointerId);}, onKeyDown: (e) => {
633
+ if (e.key !== "ArrowUp" && e.key !== "ArrowDown")
634
+ return;
635
+ e.preventDefault();
636
+ e.stopPropagation();
637
+ const d = Math.abs(t.value) > 0 ? Math.abs(t.value) * 0.05 : 0.01;
638
+ onThresholdDrag(i, t.value + (e.key === "ArrowUp" ? d : -d));
639
+ } }) : null] }, `t${i}`);
640
+ }), (markers ?? []).map((m, i) => {
641
+ const mx = markerX[i];
642
+ if (mx < padL - 0.5 || mx > padL + plotW + 0.5)
643
+ return null;
644
+ const colour = markerColour(m);
645
+ const near = hoverX !== null && Math.abs(hoverX - mx) < 8;
646
+ const labelled = markerLabels && markerKeep[i] || near;
647
+ return _jsxs("g", { "data-marker": m.kind ?? "deploy", children: [_jsx("title", { children: m.label }), _jsx("line", { x1: f(mx), x2: f(mx), y1: padT, y2: bottom, stroke: colour, strokeWidth: 1, strokeDasharray: "2 3", opacity: 0.8 }), m.kind === "alert" ?
648
+ _jsx("rect", { x: mx - 1, y: bottom - 6, width: 2, height: 7, fill: colour }) :
649
+ m.kind === "note" ?
650
+ _jsx("circle", { cx: mx, cy: bottom, r: 2.6, fill: colour }) :
651
+ _jsx("polygon", { points: `${f(mx)},${f(bottom - 6)} ${f(mx - 4.5)},${f(bottom + 1.5)} ${f(mx + 4.5)},${f(bottom + 1.5)}`, fill: colour }), labelled && axes ? _jsx("text", { x: mx, y: padT - 5, textAnchor: mx > padL + plotW - 30 ? "end" : mx < padL + 30 ? "start" : "middle", fontSize: 10, fill: colour, children: m.label }) : null] }, `m${i}`);
652
+ }), drag && Math.abs(drag.to - drag.from) * plotW > 1 ? _jsx("rect", { x: padL + Math.min(drag.from, drag.to) * plotW, width: Math.abs(drag.to - drag.from) * plotW, y: padT, height: plotH, fill: v.brand12, stroke: v.brand55, strokeWidth: 1 }) : null, hoverX !== null && size !== "s" ? _jsx("line", { x1: f(hoverX), x2: f(hoverX), y1: padT, y2: bottom, stroke: v.line2, strokeWidth: 1, strokeDasharray: hover?.own ? undefined : "3 3" }) : null, hover && !drag && kind === "line" && size !== "s" ? series.map((s, k) => {
653
+ if (!isShown(s))
654
+ return null;
655
+ const val = stackable(s) ? upper[k][hover.idx] : cols[k][hover.idx];
656
+ if (val == null)
657
+ return null;
658
+ return _jsx("circle", { cx: f(x(xs[hover.idx])), cy: f(y(val)), r: 3, fill: colours[k], stroke: v.surface, strokeWidth: 1.5, opacity: s.compareOf ? 0.6 : 1 }, `h${k}`);
659
+ }) : null] }), tip] }), showLegend && (series.length > 1 || thresholdNotes.length > 0 || legendExtra || legend) ? _jsx(LegendChips, { items: legendItems, onToggle: toggle, notes: _jsxs(_Fragment, { children: [thresholdNotes.length ? _jsx(LegendNote, { colour: TONE_COLOUR[thresholdNotes[0].tone ?? "crit"], dashed: true, children: thresholdNotes.map((t) => `${thresholdWord(t)} ${fmtTip(t.value)}`).join(" · ") }) : null, legendExtra] }) }) : null, hint !== undefined ? hint : onZoom && size !== "s" && size !== "m" ? _jsx(ChartHint, { children: "Drag across the chart to zoom into a window." }) : null] });
660
660
  }
661
661
  /**
662
662
  * LineChart: n series over a shared time axis — the default timeseries, up to
@@ -680,7 +680,7 @@ function TimePlot(props) {
680
680
  * follows the frame's.
681
681
  */
682
682
  export function LineChart({ label = "Series", empty = "No samples in range", ...rest }) {
683
- return _jsx(TimePlot, { kind: "line", label: label, empty: empty, ...rest });
683
+ return _jsx(TimePlot, { kind: "line", label: label, empty: empty, ...rest });
684
684
  }
685
685
  /**
686
686
  * BarChart: counts per bucket, stacked by part (status class, error type) over
@@ -690,7 +690,7 @@ export function LineChart({ label = "Series", empty = "No samples in range", ...
690
690
  * thresholds, the tooltip, the legend — is LineChart's.
691
691
  */
692
692
  export function BarChart({ label = "Counts over time", empty = "No activity in range", ...rest }) {
693
- return _jsx(TimePlot, { kind: "bars", label: label, empty: empty, total: true, ...rest });
693
+ return _jsx(TimePlot, { kind: "bars", label: label, empty: empty, total: true, ...rest });
694
694
  }
695
695
  /**
696
696
  * Histogram: a stacked bar per bucket over time — BarChart's time-bucketed
@@ -704,19 +704,19 @@ export function BarChart({ label = "Counts over time", empty = "No activity in r
704
704
  * span in local time.
705
705
  */
706
706
  export function Histogram({ buckets, tones = {}, height, size, label = "Activity over time", empty = "No activity in range", formatValue, formatTime, onZoom, markers }) {
707
- const series = useMemo(() => {
708
- const order = [];
709
- for (const b of buckets)
710
- for (const p of b.parts)
711
- if (!order.includes(p.name))
712
- order.push(p.name);
713
- return order.map((name) => ({
714
- name,
715
- tone: tones[name],
716
- points: buckets.map((b) => ({ t: b.t, v: b.parts.find((p) => p.name === name)?.value ?? 0 })),
717
- }));
718
- }, [buckets, tones]);
719
- return (_jsx(TimePlot, { kind: "bars", series: series, label: label, empty: empty, total: true, formatValue: formatValue ?? fmtCount, formatTime: formatTime, height: height, size: size, onZoom: onZoom, markers: markers, legend: series.length > 1 && (height === undefined || height >= 120) }));
707
+ const series = useMemo(() => {
708
+ const order = [];
709
+ for (const b of buckets)
710
+ for (const p of b.parts)
711
+ if (!order.includes(p.name))
712
+ order.push(p.name);
713
+ return order.map((name) => ({
714
+ name,
715
+ tone: tones[name],
716
+ points: buckets.map((b) => ({ t: b.t, v: b.parts.find((p) => p.name === name)?.value ?? 0 }))
717
+ }));
718
+ }, [buckets, tones]);
719
+ return _jsx(TimePlot, { kind: "bars", series: series, label: label, empty: empty, total: true, formatValue: formatValue ?? fmtCount, formatTime: formatTime, height: height, size: size, onZoom: onZoom, markers: markers, legend: series.length > 1 && (height === undefined || height >= 120) });
720
720
  }
721
721
  /**
722
722
  * Lines the series up on the union of their timestamps. A series with no point
@@ -724,17 +724,17 @@ export function Histogram({ buckets, tones = {}, height, size, label = "Activity
724
724
  * first point it is zero.
725
725
  */
726
726
  export function stackSeries(series) {
727
- const times = [...new Set(series.flatMap((s) => s.points.map((p) => p.t)))].sort((a, b) => a - b);
728
- const sorted = series.map((s) => [...s.points].sort((a, b) => a.t - b.t));
729
- const at = sorted.map(() => 0);
730
- return times.map((t) => {
731
- const values = sorted.map((pts, i) => {
732
- while (at[i] < pts.length && pts[at[i]].t <= t)
733
- at[i]++;
734
- return at[i] > 0 ? pts[at[i] - 1].v : 0;
735
- });
736
- return { t, values, total: values.reduce((a, b) => a + b, 0) };
727
+ const times = [...new Set(series.flatMap((s) => s.points.map((p) => p.t)))].sort((a, b) => a - b);
728
+ const sorted = series.map((s) => [...s.points].sort((a, b) => a.t - b.t));
729
+ const at = sorted.map(() => 0);
730
+ return times.map((t) => {
731
+ const values = sorted.map((pts, i) => {
732
+ while (at[i] < pts.length && pts[at[i]].t <= t)
733
+ at[i]++;
734
+ return at[i] > 0 ? pts[at[i] - 1].v : 0;
737
735
  });
736
+ return { t, values, total: values.reduce((a, b) => a + b, 0) };
737
+ });
738
738
  }
739
739
  const isOther = (name) => name === "Other";
740
740
  /**
@@ -750,10 +750,10 @@ const isOther = (name) => name === "Other";
750
750
  * values in a table too: the chart is not the only way in.
751
751
  */
752
752
  export function StackedAreaChart({ series, max, height, size, label = "Stacked series", empty = "No samples in range", formatValue, formatTime, markers, onZoom }) {
753
- const lines = useMemo(() => {
754
- const moments = stackSeries(series);
755
- return series.map((s, i) => ({ name: s.name, points: moments.map((m) => ({ t: m.t, v: m.values[i] })) }));
756
- }, [series]);
757
- return (_jsx(TimePlot, { kind: "line", stacked: true, total: true, series: lines, max: max, height: height, size: size ?? (height === undefined ? "l" : undefined), label: label, empty: empty, formatValue: formatValue, formatTime: formatTime, bandOpacity: 0.85, neutral: isOther, markers: markers, onZoom: onZoom, legend: series.length > 1 }));
753
+ const lines = useMemo(() => {
754
+ const moments = stackSeries(series);
755
+ return series.map((s, i) => ({ name: s.name, points: moments.map((m) => ({ t: m.t, v: m.values[i] })) }));
756
+ }, [series]);
757
+ return _jsx(TimePlot, { kind: "line", stacked: true, total: true, series: lines, max: max, height: height, size: size ?? (height === undefined ? "l" : undefined), label: label, empty: empty, formatValue: formatValue, formatTime: formatTime, bandOpacity: 0.85, neutral: isOther, markers: markers, onZoom: onZoom, legend: series.length > 1 });
758
758
  }
759
- //# sourceMappingURL=Charts.js.map
759
+ //# sourceMappingURL=Charts.js.map