basalt-ui 2.10.0 → 2.11.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 (65) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/MIGRATING.md +27 -13
  3. package/agent/rules/basalt-charts.md +2 -2
  4. package/agent/skills/basalt-charts/SKILL.md +16 -17
  5. package/dist/charts/BandStrip.d.ts +3 -2
  6. package/dist/charts/BandStrip.d.ts.map +1 -1
  7. package/dist/charts/CartesianChart.d.ts +3 -0
  8. package/dist/charts/CartesianChart.d.ts.map +1 -1
  9. package/dist/charts/CartesianChart.js +9 -3
  10. package/dist/charts/DualPanel.d.ts.map +1 -1
  11. package/dist/charts/DualPanel.js +20 -15
  12. package/dist/charts/Heatmap.d.ts +33 -3
  13. package/dist/charts/Heatmap.d.ts.map +1 -1
  14. package/dist/charts/Heatmap.js +111 -68
  15. package/dist/charts/Sparkline.d.ts +12 -0
  16. package/dist/charts/Sparkline.d.ts.map +1 -1
  17. package/dist/charts/Sparkline.js +68 -5
  18. package/dist/charts/band-fold.d.ts +7 -0
  19. package/dist/charts/band-fold.d.ts.map +1 -1
  20. package/dist/charts/compile.d.ts +4 -1
  21. package/dist/charts/compile.d.ts.map +1 -1
  22. package/dist/charts/compile.js +22 -14
  23. package/dist/charts/heatmap-fill.d.ts +15 -0
  24. package/dist/charts/heatmap-fill.d.ts.map +1 -0
  25. package/dist/charts/heatmap-fill.js +13 -0
  26. package/dist/charts/host.d.ts +5 -1
  27. package/dist/charts/host.d.ts.map +1 -1
  28. package/dist/charts/host.js +37 -1
  29. package/dist/charts/index.d.ts +1 -1
  30. package/dist/charts/index.d.ts.map +1 -1
  31. package/dist/charts/marks.d.ts +1 -1
  32. package/dist/charts/marks.d.ts.map +1 -1
  33. package/dist/charts/marks.js +28 -13
  34. package/dist/charts/panel.d.ts +7 -1
  35. package/dist/charts/panel.d.ts.map +1 -1
  36. package/dist/charts/panel.js +9 -4
  37. package/dist/charts/plot-context.d.ts +42 -0
  38. package/dist/charts/plot-context.d.ts.map +1 -0
  39. package/dist/charts/plot-context.js +64 -0
  40. package/dist/charts/scales.d.ts +3 -1
  41. package/dist/charts/scales.d.ts.map +1 -1
  42. package/dist/charts/scales.js +23 -5
  43. package/dist/charts/types.d.ts +31 -5
  44. package/dist/charts/types.d.ts.map +1 -1
  45. package/dist/tokens/core.d.ts +6 -0
  46. package/dist/tokens/core.d.ts.map +1 -1
  47. package/dist/tokens/core.js +5 -3
  48. package/llms.txt +12 -4
  49. package/package.json +1 -1
  50. package/src/charts/BandStrip.tsx +2 -5
  51. package/src/charts/CartesianChart.tsx +13 -2
  52. package/src/charts/DualPanel.tsx +21 -16
  53. package/src/charts/Heatmap.tsx +181 -76
  54. package/src/charts/Sparkline.tsx +106 -5
  55. package/src/charts/band-fold.ts +11 -0
  56. package/src/charts/compile.ts +26 -14
  57. package/src/charts/heatmap-fill.ts +19 -0
  58. package/src/charts/host.tsx +59 -0
  59. package/src/charts/index.ts +1 -1
  60. package/src/charts/marks.ts +31 -14
  61. package/src/charts/panel.tsx +18 -5
  62. package/src/charts/plot-context.ts +109 -0
  63. package/src/charts/scales.ts +33 -5
  64. package/src/charts/types.ts +31 -5
  65. package/src/tokens/core.ts +10 -3
@@ -1,6 +1,5 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { colorGradientLegend } from "@tanstack/charts/legend";
3
- import { decorative } from "@tanstack/charts/mark/decorative";
4
3
  import { cell } from "@tanstack/charts/rect";
5
4
  import { scaleBand } from "@tanstack/charts/scales/band";
6
5
  import { tooltip as tooltipHost } from "@tanstack/charts/tooltip";
@@ -10,22 +9,29 @@ import { useId, useMemo } from "react";
10
9
  import { alpha, VX } from "../tokens/index.js";
11
10
  import { resolveContainerClass } from "../tokens/size-classes.js";
12
11
  import { engineRow, strideTicks } from "./compile.js";
12
+ import { resolveNamedState } from "./band-fold.js";
13
+ import { ABSENT_OPACITY, RAMP_LEVELS, RAMP_OPACITIES } from "./heatmap-fill.js";
13
14
  import { ChartEngine, idPrefixOf } from "./host.js";
15
+ import { ChartLegend } from "./legend.js";
14
16
  import { useCoarsePointer } from "../common/use-media-query.js";
15
17
  import { HEIGHT_MAX, HEIGHT_MIN } from "./box.js";
16
18
  import { ChartPlaceholder, resolveChartState } from "./state.js";
17
19
  import { AXIS_LINE, CHART_THEME } from "./theme.js";
18
- const LEVELS = 8;
19
- const MIN_LEVEL = 0.14;
20
20
  const ROW_PITCH = 26;
21
21
  const CHROME = 64;
22
22
  const CELL_INSET = 1;
23
23
  const identityLabel = (band) => band;
24
24
  const firstSeen = (keys) => [...new Set(keys)];
25
- const ramp = (color) => Array.from(
26
- { length: LEVELS },
27
- (_, i) => alpha(color, MIN_LEVEL + (1 - MIN_LEVEL) * i / (LEVELS - 1))
28
- );
25
+ const ramp = (color) => RAMP_OPACITIES.map((a) => alpha(color, a));
26
+ const noneHidden = /* @__PURE__ */ new Set();
27
+ const noop = () => {
28
+ };
29
+ const noStates = [];
30
+ function valueRows(c, named, label, formatValue, pointColor) {
31
+ if (named) return [{ label, value: named.label, color: named.color }];
32
+ if (c.value === null) return [{ label, value: "No data" }];
33
+ return [{ label, value: formatValue(c.value), ...pointColor && { color: pointColor } }];
34
+ }
29
35
  const fillStyle = { position: "relative", height: "100%", minHeight: HEIGHT_MIN };
30
36
  function Heatmap(props) {
31
37
  const {
@@ -37,6 +43,9 @@ function Heatmap(props) {
37
43
  color = VX.line,
38
44
  domain,
39
45
  formatValue = String,
46
+ formatLegend = formatValue,
47
+ getState,
48
+ states = noStates,
40
49
  formatRow = identityLabel,
41
50
  formatCol = identityLabel,
42
51
  legend,
@@ -51,12 +60,16 @@ function Heatmap(props) {
51
60
  const showLegend = legend !== false;
52
61
  const legendLabel = legend === false ? void 0 : legend?.label;
53
62
  const showTooltip = tooltip !== false;
54
- const tooltipRows = tooltip === false ? void 0 : tooltip?.rows;
63
+ const tooltipConfig = tooltip === false ? void 0 : tooltip;
64
+ const tooltipRows = tooltipConfig?.rows;
65
+ const valueLabel = tooltipConfig?.valueLabel ?? "Value";
55
66
  const rows = useMemo(() => props.rows ?? firstSeen(data.map(getRow)), [props.rows, data, getRow]);
56
67
  const cols = useMemo(() => props.cols ?? firstSeen(data.map(getCol)), [props.cols, data, getCol]);
57
68
  const statedHeight = height ?? Math.min(Math.max(rows.length * ROW_PITCH + CHROME, HEIGHT_MIN), HEIGHT_MAX);
58
69
  const coarse = useCoarsePointer();
59
70
  const boxHeight = matchHeight ? "fill" : statedHeight;
71
+ const stateKeys = useMemo(() => states.map((s) => s.key), [states]);
72
+ const stateByKey = useMemo(() => new Map(states.map((s) => [s.key, s])), [states]);
60
73
  const definition = useMemo(() => {
61
74
  const byBand = /* @__PURE__ */ new Map();
62
75
  for (const d of data) {
@@ -66,6 +79,7 @@ function Heatmap(props) {
66
79
  byBand.set(row, inRow);
67
80
  }
68
81
  const present = [];
82
+ const stated = /* @__PURE__ */ new Map();
69
83
  const absentWithDatum = [];
70
84
  const absentEmpty = [];
71
85
  let max = 0;
@@ -74,8 +88,20 @@ function Heatmap(props) {
74
88
  const datum = byBand.get(row)?.get(col);
75
89
  const raw = datum === void 0 ? null : getValue(datum);
76
90
  const value = raw !== null && Number.isFinite(raw) ? raw : null;
77
- const cellAt = { id: r * cols.length + c, row, col, datum, value };
78
- if (value !== null) {
91
+ const stateKey = datum === void 0 || getState === void 0 ? void 0 : resolveNamedState("Heatmap", "Heatmap.getState", getState(datum), stateKeys);
92
+ const cellAt = {
93
+ id: r * cols.length + c,
94
+ row,
95
+ col,
96
+ datum,
97
+ value,
98
+ state: stateKey
99
+ };
100
+ if (stateKey !== void 0) {
101
+ const bucket = stated.get(stateKey) ?? [];
102
+ bucket.push(cellAt);
103
+ stated.set(stateKey, bucket);
104
+ } else if (value !== null) {
79
105
  present.push(cellAt);
80
106
  max = Math.max(max, value);
81
107
  } else if (datum === void 0) absentEmpty.push(cellAt);
@@ -85,6 +111,22 @@ function Heatmap(props) {
85
111
  const [lo, hi] = domain ?? [0, max];
86
112
  const scale = scaleQuantize().domain([lo, hi > lo ? hi : lo + 1]).range(ramp(color));
87
113
  const header = (c) => `${formatRow(c.row)} \xB7 ${formatCol(c.col)}`;
114
+ const cellMark = (id, group, paint) => cell(group, { id, x: "col", y: "row", inset: CELL_INSET, key: "id", ...paint });
115
+ const tooltipOptions = showTooltip ? {
116
+ use: tooltipHost,
117
+ portal,
118
+ content: (points) => {
119
+ const point = points[0];
120
+ const c = point?.datum;
121
+ if (!point || !c || c.datum === void 0) return { rows: [] };
122
+ const named = c.state === void 0 ? void 0 : stateByKey.get(c.state);
123
+ const rows2 = [
124
+ ...valueRows(c, named, valueLabel, formatValue, point.color),
125
+ ...tooltipRows?.(c.datum) ?? []
126
+ ];
127
+ return { title: header(c), rows: rows2.map(engineRow) };
128
+ }
129
+ } : false;
88
130
  return {
89
131
  chart: ({ width }) => {
90
132
  const ticks = { line: false, size: 0 };
@@ -95,33 +137,18 @@ function Heatmap(props) {
95
137
  thin: true
96
138
  };
97
139
  const marks = [
98
- decorative(
99
- cell(absentEmpty, {
100
- id: "absent-empty",
101
- x: "col",
102
- y: "row",
103
- fill: VX.neutral,
104
- fillOpacity: 0.12,
105
- inset: CELL_INSET
106
- })
107
- ),
108
- cell(absentWithDatum, {
109
- id: "absent",
110
- x: "col",
111
- y: "row",
112
- fill: VX.neutral,
113
- fillOpacity: 0.12,
114
- inset: CELL_INSET,
115
- key: "id"
140
+ // Inert, not decorative: it must still win the hit test, so a pointer over an empty
141
+ // position lands on THIS cell (whose tooltip is empty) instead of snapping to a neighbour.
142
+ cellMark("absent-empty", absentEmpty, { fill: VX.neutral, fillOpacity: ABSENT_OPACITY }),
143
+ cellMark("absent", absentWithDatum, { fill: VX.neutral, fillOpacity: ABSENT_OPACITY }),
144
+ ...[...stated].map(([key, group]) => {
145
+ const named = stateByKey.get(key);
146
+ return cellMark(`state:${key}`, group, {
147
+ fill: named?.color ?? VX.neutral,
148
+ ...named?.fillOpacity !== void 0 && { fillOpacity: named.fillOpacity }
149
+ });
116
150
  }),
117
- cell(present, {
118
- id: "cells",
119
- x: "col",
120
- y: "row",
121
- color: "value",
122
- inset: CELL_INSET,
123
- key: "id"
124
- })
151
+ cellMark("cells", present, { color: "value" })
125
152
  ];
126
153
  return {
127
154
  marks,
@@ -151,8 +178,8 @@ function Heatmap(props) {
151
178
  scale,
152
179
  ...showLegend && {
153
180
  legend: colorGradientLegend({
154
- steps: LEVELS,
155
- format: formatValue,
181
+ steps: RAMP_LEVELS,
182
+ format: formatLegend,
156
183
  placement: "bottom",
157
184
  ...legendLabel !== void 0 && { label: legendLabel }
158
185
  })
@@ -161,24 +188,7 @@ function Heatmap(props) {
161
188
  theme: CHART_THEME
162
189
  };
163
190
  },
164
- tooltip: showTooltip ? {
165
- use: tooltipHost,
166
- portal,
167
- content: (points) => {
168
- const point = points[0];
169
- const c = point?.datum;
170
- if (!point || !c) return { rows: [] };
171
- const extra = c.datum === void 0 ? [] : tooltipRows?.(c.datum) ?? [];
172
- const value = c.value === null ? [{ label: "Value", value: "No data" }] : [
173
- {
174
- label: "Value",
175
- value: formatValue(c.value),
176
- ...point.color && { color: point.color }
177
- }
178
- ];
179
- return { title: header(c), rows: [...value, ...extra].map(engineRow) };
180
- }
181
- } : false
191
+ tooltip: tooltipOptions
182
192
  };
183
193
  }, [
184
194
  data,
@@ -190,6 +200,11 @@ function Heatmap(props) {
190
200
  color,
191
201
  domain,
192
202
  formatValue,
203
+ formatLegend,
204
+ getState,
205
+ stateKeys,
206
+ stateByKey,
207
+ valueLabel,
193
208
  formatRow,
194
209
  formatCol,
195
210
  legendLabel,
@@ -197,23 +212,51 @@ function Heatmap(props) {
197
212
  showTooltip,
198
213
  tooltipRows
199
214
  ]);
215
+ const legendSeries = useMemo(
216
+ () => getState === void 0 ? [] : states.map((s) => ({
217
+ key: s.key,
218
+ label: s.label,
219
+ color: s.color,
220
+ mark: "bar",
221
+ ...s.fillOpacity !== void 0 && { fillOpacity: s.fillOpacity },
222
+ ...s.legend !== void 0 && { legend: s.legend },
223
+ ...s.note !== void 0 && { note: s.note },
224
+ getValue: () => null
225
+ })),
226
+ [states, getState]
227
+ );
200
228
  const resolved = resolveChartState(state);
201
- return /* @__PURE__ */ jsx(
229
+ return /* @__PURE__ */ jsxs(
202
230
  "div",
203
231
  {
204
232
  "data-basalt-chart": "",
205
233
  ...className !== void 0 && { className },
206
234
  style: matchHeight ? { ...fillStyle, ...style } : style,
207
- children: resolved === null ? /* @__PURE__ */ jsx(
208
- ChartEngine,
209
- {
210
- definition,
211
- ariaLabel,
212
- height: boxHeight,
213
- idPrefix: idPrefixOf(chartId),
214
- coarse
215
- }
216
- ) : /* @__PURE__ */ jsx(ChartPlaceholder, { state, height: boxHeight })
235
+ children: [
236
+ resolved === null ? /* @__PURE__ */ jsx(
237
+ ChartEngine,
238
+ {
239
+ definition,
240
+ ariaLabel,
241
+ height: boxHeight,
242
+ idPrefix: idPrefixOf(chartId),
243
+ coarse
244
+ }
245
+ ) : /* @__PURE__ */ jsx(ChartPlaceholder, { state, height: boxHeight }),
246
+ showLegend && legendSeries.length > 0 && /* @__PURE__ */ jsx(
247
+ ChartLegend,
248
+ {
249
+ series: legendSeries,
250
+ hidden: noneHidden,
251
+ mode: "chips",
252
+ groups: false,
253
+ toggle: false,
254
+ onToggle: noop,
255
+ onHighlight: noop,
256
+ concealed: resolved !== null
257
+ }
258
+ )
259
+ ]
217
260
  }
218
261
  );
219
262
  }
@@ -21,6 +21,18 @@ export type SparklineProps = BasaltProps & {
21
21
  * sparkline's own `width` × `height`, so a loading tile does not shift when the trend lands. */
22
22
  state?: ChartState | undefined;
23
23
  };
24
+ type Point = {
25
+ i: number;
26
+ v: number | null;
27
+ };
28
+ /**
29
+ * Pools a series to what `width` px can show, so the caller never sizes it: at most one point
30
+ * per `LINE_PX_PER_POINT` (min/max-preserving) or one bar per `BAR_PX_PER_BAR`. A series at or
31
+ * under its cap is returned as is, so a short series draws exactly as before; `width <= 0`
32
+ * (unmeasured) pools nothing. A line is never pooled below its two endpoints.
33
+ */
34
+ export declare function poolSparkline(rows: readonly Point[], width: number, mark: 'line' | 'bar'): readonly Point[];
24
35
  /** `useId` output (`«r1»`, `:r1:`) is not a safe SVG id fragment. */
25
36
  export declare function Sparkline(props: SparklineProps): ReactElement;
37
+ export {};
26
38
  //# sourceMappingURL=Sparkline.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sparkline.d.ts","sourceRoot":"","sources":["../../src/charts/Sparkline.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAQlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IACzC,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IACvB,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAA;IACjC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,8FAA8F;IAC9F,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACnC,2BAA2B;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC;oGACgG;IAChG,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;CAC/B,CAAA;AAiGD,qEAAqE;AAErE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,CAyC7D"}
1
+ {"version":3,"file":"Sparkline.d.ts","sourceRoot":"","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
16
  const BAR_GAP = 0.15;
17
+ const LINE_PX_PER_POINT = 1;
18
+ const BAR_PX_PER_BAR = 2;
19
+ const LINE_POOL_MIN = 4;
17
20
  const finite = (v) => Number.isFinite(v) ? v : null;
18
21
  function extent(rows) {
19
22
  let lo = Number.POSITIVE_INFINITY;
@@ -25,10 +28,69 @@ function extent(rows) {
25
28
  }
26
29
  return lo <= hi ? [lo, hi] : null;
27
30
  }
28
- function compileSparkline(rows, [lo, hi], mark, color, emphasisColor) {
31
+ const sampleOf = (row) => row.v === null ? null : { row, v: row.v };
32
+ function buckets(rows, count) {
33
+ const size = rows.length / count;
34
+ return Array.from(
35
+ { length: count },
36
+ (_, b) => rows.slice(Math.round(b * size), Math.round((b + 1) * size))
37
+ ).filter((bucket) => bucket.length > 0);
38
+ }
39
+ function runRows(run, beforeGap) {
40
+ const keep = [
41
+ run.lo,
42
+ run.hi,
43
+ ...run.afterGap ? [run.first] : [],
44
+ ...beforeGap ? [run.last] : []
45
+ ];
46
+ const byIndex = new Map(keep.map((k) => [k.row.i, k.row]));
47
+ return [...byIndex.values()].toSorted((a, b) => a.i - b.i);
48
+ }
49
+ function poolLine(rows, cap) {
50
+ const first = rows[0];
29
51
  const last = rows.at(-1);
52
+ if (first === void 0 || last === void 0) return rows;
53
+ if (cap < LINE_POOL_MIN) return [first, last];
54
+ const out = [first];
55
+ const endsInGap = () => out.at(-1)?.v === null;
56
+ for (const bucket of buckets(rows.slice(1, -1), Math.floor(cap / 2) - 1)) {
57
+ let run;
58
+ for (const row of bucket) {
59
+ const s = sampleOf(row);
60
+ if (s === null) {
61
+ if (run !== void 0) out.push(...runRows(run, true));
62
+ run = void 0;
63
+ if (!endsInGap()) out.push(row);
64
+ continue;
65
+ }
66
+ run = run === void 0 ? { first: s, lo: s, hi: s, last: s, afterGap: endsInGap() } : { ...run, lo: s.v < run.lo.v ? s : run.lo, hi: s.v > run.hi.v ? s : run.hi, last: s };
67
+ }
68
+ if (run !== void 0) out.push(...runRows(run, false));
69
+ }
70
+ return last.v === null && endsInGap() ? out : [...out, last];
71
+ }
72
+ function poolBar(rows, cap) {
73
+ const first = rows[0];
74
+ const last = rows.at(-1);
75
+ if (first === void 0 || last === void 0) return rows;
76
+ const furthest = (group) => group.reduce((best, r) => {
77
+ if (r.v === null) return best;
78
+ return best === null || Math.abs(r.v) > Math.abs(best) ? r.v : best;
79
+ }, null);
80
+ if (cap < 2) return [{ i: 0, v: furthest(rows) }];
81
+ const values = cap === 2 ? [first.v, last.v] : [first.v, ...buckets(rows.slice(1, -1), cap - 2).map(furthest), last.v];
82
+ return values.map((v, i) => ({ i, v }));
83
+ }
84
+ function poolSparkline(rows, width, mark) {
85
+ const cap = Math.floor(width / (mark === "bar" ? BAR_PX_PER_BAR : LINE_PX_PER_POINT));
86
+ if (width <= 0 || rows.length <= Math.max(cap, mark === "bar" ? 1 : 2)) return rows;
87
+ return mark === "bar" ? poolBar(rows, cap) : poolLine(rows, cap);
88
+ }
89
+ function compileSparkline(source, [lo, hi], mark, color, emphasisColor) {
30
90
  return {
31
- chart: () => {
91
+ chart: ({ width }) => {
92
+ const rows = poolSparkline(source, width, mark);
93
+ const last = rows.at(-1);
32
94
  if (mark === "bar") {
33
95
  return {
34
96
  marks: [
@@ -55,7 +117,7 @@ function compileSparkline(rows, [lo, hi], mark, color, emphasisColor) {
55
117
  };
56
118
  }
57
119
  const pad = (hi - lo) * 0.1 || 1;
58
- const xPad = emphasisColor === null ? 0 : (rows.length - 1) * 0.04 || 0.5;
120
+ const xPad = emphasisColor === null ? 0 : (source.length - 1) * 0.04 || 0.5;
59
121
  return {
60
122
  marks: [
61
123
  lineY(rows, {
@@ -74,7 +136,7 @@ function compileSparkline(rows, [lo, hi], mark, color, emphasisColor) {
74
136
  ],
75
137
  scales: {
76
138
  x: {
77
- scale: scaleLinear().domain([-xPad, Math.max(rows.length - 1, 1) + xPad]),
139
+ scale: scaleLinear().domain([-xPad, Math.max(source.length - 1, 1) + xPad]),
78
140
  axis: false
79
141
  },
80
142
  y: { scale: scaleLinear().domain([lo - pad, hi + pad]), axis: false }
@@ -131,5 +193,6 @@ function Sparkline(props) {
131
193
  );
132
194
  }
133
195
  export {
134
- Sparkline
196
+ Sparkline,
197
+ poolSparkline
135
198
  };
@@ -1,3 +1,10 @@
1
+ import type { ChartSeries } from './types.js';
2
+ /**
3
+ * The fields a named state carries wherever one is declared (`BandStrip`'s `states`, `Heatmap`'s):
4
+ * the key, its legend label and color, its fill opacity, and the legend / tooltip / note switches.
5
+ * One base so a field means the same thing on every kind.
6
+ */
7
+ export type NamedChartState = Pick<ChartSeries<never>, 'key' | 'label' | 'color' | 'tooltip' | 'legend' | 'note' | 'fillOpacity'>;
1
8
  /** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
2
9
  export type Group<T> = {
3
10
  start: number;
@@ -1 +1 @@
1
- {"version":3,"file":"band-fold.d.ts","sourceRoot":"","sources":["../../src/charts/band-fold.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,EAAE,CAAA;CAAE,CAAA;AAEpD,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CASvE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAI3F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,CAAC,GAAG,SAAS,EACxB,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,CAAC,GAAG,SAAS,CAOf"}
1
+ {"version":3,"file":"band-fold.d.ts","sourceRoot":"","sources":["../../src/charts/band-fold.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,WAAW,CAAC,KAAK,CAAC,EAClB,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,aAAa,CAC1E,CAAA;AAED,4FAA4F;AAC5F,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,EAAE,CAAA;CAAE,CAAA;AAEpD,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CASvE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAI3F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,CAAC,GAAG,SAAS,EACxB,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,CAAC,GAAG,SAAS,CAOf"}
@@ -1,5 +1,6 @@
1
1
  import type { ChartGradient, ChartPositionScaleOptions, ChartTooltipRow as EngineTooltipRow, ChartValue, ResponsiveChartDefinition } from '@tanstack/charts/types/core';
2
2
  import type { ContainerClass } from '../tokens/size-classes.js';
3
+ import type { PlotSizes } from './plot-context.js';
3
4
  import type { XScaleModel } from './scales.js';
4
5
  import type { AxisConfig, CartesianChartProps, ChartSeries, ChartTooltipRow, ChartX, RefLine, ZoneSpec } from './types.js';
5
6
  /**
@@ -8,7 +9,7 @@ import type { AxisConfig, CartesianChartProps, ChartSeries, ChartTooltipRow, Cha
8
9
  */
9
10
  export type CartesianDefinition = ResponsiveChartDefinition<unknown, ChartValue, number, 'dom'>;
10
11
  /** Everything the rung compiles: the public props minus React chrome, plus the host's state. */
11
- export type CartesianInput<T, X extends ChartX> = Pick<CartesianChartProps<T, X>, 'data' | 'x' | 'series' | 'marks' | 'y' | 'y2' | 'xTicks' | 'formatX' | 'zones' | 'xZones' | 'refLines' | 'cursorGroup' | 'cursorResolution' | 'tooltip'> & {
12
+ export type CartesianInput<T, X extends ChartX> = Pick<CartesianChartProps<T, X>, 'data' | 'x' | 'series' | 'marks' | 'y' | 'y2' | 'xTicks' | 'xDomain' | 'formatX' | 'zones' | 'xZones' | 'refLines' | 'cursorGroup' | 'cursorResolution' | 'tooltip'> & {
12
13
  /** Unique per mounted chart (React `useId`): owns what this chart publishes to the cursor. */
13
14
  chartId: string;
14
15
  /** Series keys the legend has toggled off. */
@@ -23,6 +24,8 @@ export type CartesianInput<T, X extends ChartX> = Pick<CartesianChartProps<T, X>
23
24
  reverseRows?: boolean;
24
25
  /** Bar kinds: how the left-axis `mark: 'bar'` series combine for the auto domain. */
25
26
  stack?: 'stacked' | 'normalized';
27
+ /** The plot area the engine last laid out; `null` before the first layout (the frame stands in). */
28
+ plot?: PlotSizes | null;
26
29
  };
27
30
  export declare function defaultNumberFormat(v: number): string;
28
31
  /** `DD.MM`, read in UTC like the time scale that placed it (a local read shifts a day west of UTC). */
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,aAAa,EAEb,yBAAyB,EACzB,eAAe,IAAI,gBAAgB,EACnC,UAAU,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,CAAA;CACf,GAAG,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,CAoBvD;AAED,+FAA+F;AAC/F,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAAgC,CAAA;AAE/E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAYxE;AAKD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GACjC,aAAa,GAAG,IAAI,CAuBtB;AAqbD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAClD,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1B,mBAAmB,CAyErB"}
@@ -11,6 +11,7 @@ import { fmtCompact } from "../format/number.js";
11
11
  import { VX } from "../tokens/index.js";
12
12
  import { cursorBinding, sourceOnlyFocus } from "./cursor.js";
13
13
  import { cursorDots } from "./marks.js";
14
+ import { MAIN_PANE, plotAccess, plotContext } from "./plot-context.js";
14
15
  import { resolveContainerClass } from "../tokens/size-classes.js";
15
16
  import { resolveYDomain, xScaleFor, xZoneFractions, yScaleFor } from "./scales.js";
16
17
  import { AXIS_LINE, CHART_THEME, CROSSHAIR, DASH, GRID_LINE } from "./theme.js";
@@ -463,7 +464,7 @@ function cursorDotMarks(input, visible, axes) {
463
464
  const y = cursorValue(d);
464
465
  return y === null || !Number.isFinite(y) ? [] : [{ x: input.x(d), y, series: s.key, datum: d }];
465
466
  });
466
- return [cursorDots(s, rows, axes.onRight(s) ? "y2" : void 0)];
467
+ return cursorDots(s, rows, axes.onRight(s) ? "y2" : void 0);
467
468
  });
468
469
  }
469
470
  function tooltipSpec(opts) {
@@ -515,7 +516,7 @@ function compileCartesian(input) {
515
516
  const visible = visibleSeries(input.series, input.hidden ?? /* @__PURE__ */ new Set());
516
517
  const visibleKeys = new Set(visible.map((s) => s.key));
517
518
  const keys = new Set(input.series.map((s) => s.key));
518
- const model = xScaleFor(input.data.map(input.x), input.band === true);
519
+ const model = xScaleFor(input.data.map(input.x), input.band === true, input.xDomain);
519
520
  const axes = resolveAxes(input, visible);
520
521
  const under = underlayMarks(input, model, axes);
521
522
  const over = refLineMarks(input, axes);
@@ -525,20 +526,26 @@ function compileCartesian(input) {
525
526
  const gradients = input.series.flatMap(
526
527
  (s, i) => s.area ? [seriesAreaGradient(s, i, input, axes)] : []
527
528
  );
528
- return {
529
+ const definition = {
529
530
  chart: ({ width, height }) => {
530
531
  const cls = resolveContainerClass(width);
531
- const kindMarks = input.marks({
532
- rows,
533
- visible,
534
- highlighted: input.highlighted ?? null,
535
- containerClass: cls,
536
- width,
537
- height,
538
- y2: axes.right ? "y2" : void 0,
539
- yDomain: axes.left.domain,
540
- y2Domain: axes.right?.domain
541
- });
532
+ const kindMarks = input.marks(
533
+ plotContext(
534
+ {
535
+ rows,
536
+ visible,
537
+ highlighted: input.highlighted ?? null,
538
+ containerClass: cls,
539
+ width,
540
+ height,
541
+ data: input.data,
542
+ y2: axes.right ? "y2" : void 0,
543
+ yDomain: axes.left.domain,
544
+ y2Domain: axes.right?.domain
545
+ },
546
+ plotAccess(definition, input.plot, MAIN_PANE)
547
+ )
548
+ );
542
549
  return {
543
550
  marks: [...under, ...kindMarks, ...dots, ...over, crosshair({ x: CROSSHAIR, y: false })],
544
551
  scales: buildScales({
@@ -568,6 +575,7 @@ function compileCartesian(input) {
568
575
  }),
569
576
  tooltip: input.tooltip === false ? false : tooltipSpec({ input, axes, visible, keys, visibleKeys, formatX })
570
577
  };
578
+ return definition;
571
579
  }
572
580
  export {
573
581
  areaGradient,
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `Heatmap` fills as numbers: the ramp's floor and the flat absent fill are tuned TOGETHER,
3
+ * because a near-baseline measured hour must never read as an unmeasured one. `heatmap-fill.test.ts`
4
+ * holds the pair to a ΔE*ab floor against every ramp step in both schemes — retune here, not at a
5
+ * call site.
6
+ */
7
+ /** Intensity steps: quantized, so the gradient legend and the cells are the same ramp. */
8
+ export declare const RAMP_LEVELS = 8;
9
+ /** Opacity of the lowest ramp step. */
10
+ export declare const RAMP_FLOOR = 0.28;
11
+ /** Opacity of the flat neutral fill of an absent cell. */
12
+ export declare const ABSENT_OPACITY = 0.08;
13
+ /** The ramp's opacities, lowest to full ink. */
14
+ export declare const RAMP_OPACITIES: readonly number[];
15
+ //# sourceMappingURL=heatmap-fill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heatmap-fill.d.ts","sourceRoot":"","sources":["../../src/charts/heatmap-fill.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0FAA0F;AAC1F,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,uCAAuC;AACvC,eAAO,MAAM,UAAU,OAAO,CAAA;AAC9B,0DAA0D;AAC1D,eAAO,MAAM,cAAc,OAAO,CAAA;AAElC,gDAAgD;AAChD,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAG3C,CAAA"}
@@ -0,0 +1,13 @@
1
+ const RAMP_LEVELS = 8;
2
+ const RAMP_FLOOR = 0.28;
3
+ const ABSENT_OPACITY = 0.08;
4
+ const RAMP_OPACITIES = Array.from(
5
+ { length: RAMP_LEVELS },
6
+ (_, i) => RAMP_FLOOR + (1 - RAMP_FLOOR) * i / (RAMP_LEVELS - 1)
7
+ );
8
+ export {
9
+ ABSENT_OPACITY,
10
+ RAMP_FLOOR,
11
+ RAMP_LEVELS,
12
+ RAMP_OPACITIES
13
+ };
@@ -1,5 +1,6 @@
1
1
  import type { ReactElement } from 'react';
2
2
  import type { CartesianDefinition } from './compile.js';
3
+ import type { PlotSizes } from './plot-context.js';
3
4
  import type { ChartBoxHeight } from './box.js';
4
5
  export type ChartEngineProps = {
5
6
  definition: CartesianDefinition;
@@ -10,8 +11,11 @@ export type ChartEngineProps = {
10
11
  idPrefix: string;
11
12
  /** `touch-action: pan-y`: a vertical swipe across the chart still scrolls the page. */
12
13
  coarse: boolean;
14
+ /** The laid-out plot area of every pane after each layout, in px; fires only for a definition
15
+ * whose `marks` read it (and once more for a read that comes after the measurement). */
16
+ onPlot?: (sizes: PlotSizes) => void;
13
17
  };
14
- export declare function ChartEngine({ definition, ariaLabel, height, idPrefix, coarse, }: ChartEngineProps): ReactElement;
18
+ export declare function ChartEngine({ definition, ariaLabel, height, idPrefix, coarse, onPlot, }: ChartEngineProps): ReactElement;
15
19
  /** Scopes the engine's SVG resource ids per chart instance (`useId` output carries colons). */
16
20
  export declare const idPrefixOf: (id: string, prefix?: string) => string;
17
21
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/charts/host.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAG3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,mBAAmB,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,8FAA8F;IAC9F,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,yFAAyF;IACzF,QAAQ,EAAE,MAAM,CAAA;IAChB,uFAAuF;IACvF,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAYD,wBAAgB,WAAW,CAAC,EAC1B,UAAU,EACV,SAAS,EACT,MAAM,EACN,QAAQ,EACR,MAAM,GACP,EAAE,gBAAgB,GAAG,YAAY,CAajC;AAED,+FAA+F;AAC/F,eAAO,MAAM,UAAU,GAAI,IAAI,MAAM,EAAE,eAAgB,KAAG,MACN,CAAA"}
1
+ {"version":3,"file":"host.d.ts","sourceRoot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