basalt-ui 2.9.1 → 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.
- package/CHANGELOG.md +61 -38
- package/MIGRATING.md +34 -12
- package/agent/rules/basalt-charts.md +2 -2
- package/agent/skills/basalt-charts/SKILL.md +16 -17
- package/dist/charts/BandStrip.d.ts +9 -6
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +8 -8
- package/dist/charts/CartesianChart.d.ts +3 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +13 -6
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +20 -15
- package/dist/charts/Heatmap.d.ts +33 -3
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +111 -68
- package/dist/charts/MirroredBars.d.ts +16 -5
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +46 -9
- package/dist/charts/Sparkline.d.ts +12 -0
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +68 -5
- package/dist/charts/band-fold.d.ts +13 -0
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +11 -1
- package/dist/charts/compile.d.ts +4 -1
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +22 -14
- package/dist/charts/heatmap-fill.d.ts +15 -0
- package/dist/charts/heatmap-fill.d.ts.map +1 -0
- package/dist/charts/heatmap-fill.js +13 -0
- package/dist/charts/host.d.ts +5 -1
- package/dist/charts/host.d.ts.map +1 -1
- package/dist/charts/host.js +37 -1
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +14 -10
- package/dist/charts/marks.d.ts +1 -1
- package/dist/charts/marks.d.ts.map +1 -1
- package/dist/charts/marks.js +28 -13
- package/dist/charts/panel.d.ts +7 -1
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +9 -4
- package/dist/charts/plot-context.d.ts +42 -0
- package/dist/charts/plot-context.d.ts.map +1 -0
- package/dist/charts/plot-context.js +64 -0
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +23 -5
- package/dist/charts/types.d.ts +36 -4
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/controls/enum-filter.d.ts +4 -1
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +2 -1
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +2 -0
- package/dist/tokens/core.d.ts +6 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +5 -3
- package/llms.txt +17 -8
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +19 -20
- package/src/charts/CartesianChart.tsx +16 -4
- package/src/charts/DualPanel.tsx +21 -16
- package/src/charts/Heatmap.tsx +181 -76
- package/src/charts/MirroredBars.tsx +71 -18
- package/src/charts/Sparkline.tsx +106 -5
- package/src/charts/band-fold.ts +32 -0
- package/src/charts/compile.ts +26 -14
- package/src/charts/heatmap-fill.ts +19 -0
- package/src/charts/host.tsx +59 -0
- package/src/charts/index.ts +1 -1
- package/src/charts/legend.tsx +21 -12
- package/src/charts/marks.ts +31 -14
- package/src/charts/panel.tsx +18 -5
- package/src/charts/plot-context.ts +109 -0
- package/src/charts/scales.ts +33 -5
- package/src/charts/types.ts +36 -4
- package/src/controls/enum-filter.tsx +5 -1
- package/src/controls/number-filter.tsx +6 -1
- package/src/tokens/core.ts +10 -3
package/dist/charts/Heatmap.js
CHANGED
|
@@ -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) =>
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
|
78
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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:
|
|
155
|
-
format:
|
|
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:
|
|
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__ */
|
|
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:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
}
|
|
@@ -15,18 +15,29 @@ export type MirroredBarPane = {
|
|
|
15
15
|
format: (v: number) => string;
|
|
16
16
|
};
|
|
17
17
|
/** A bar series. Any entry that is neither pane is legend-only (give it `getValue: () => null`). */
|
|
18
|
-
export type MirroredBarsSeries<T> = Pick<ChartSeries<T>, '
|
|
19
|
-
|
|
18
|
+
export type MirroredBarsSeries<T, K extends string = string> = Pick<ChartSeries<T>, 'label' | 'color' | 'getValue' | 'formatValue' | 'tooltip' | 'legend' | 'role' | 'note'> & {
|
|
19
|
+
key: K;
|
|
20
|
+
/** Read for the `absentState` entry only (its fill and swatch); the panes draw at full colour. */
|
|
21
|
+
fillOpacity?: number | undefined;
|
|
22
|
+
};
|
|
23
|
+
export type MirroredBarsProps<T, X extends ChartX = ChartX, K extends string = string> = Pick<CartesianChartProps<T, X>, 'ariaLabel' | 'data' | 'x' | 'formatX' | 'legend' | 'height' | 'state' | 'cursorGroup' | 'tooltip' | 'className' | 'style'> & {
|
|
20
24
|
/** The single source of colours, legend entries and tooltip rows. */
|
|
21
|
-
series: readonly MirroredBarsSeries<T>[];
|
|
25
|
+
series: readonly MirroredBarsSeries<T, K>[];
|
|
22
26
|
/** Drawn above the baseline. */
|
|
23
27
|
up: MirroredBarPane;
|
|
24
28
|
/** Drawn below the baseline. */
|
|
25
29
|
down: MirroredBarPane;
|
|
26
30
|
/** The up pane's share of the height. Default 0.35: the pair is usually asymmetric. */
|
|
27
31
|
upFraction?: number | undefined;
|
|
28
|
-
/** 0..1 of a bar's width that no source sample covers, drawn
|
|
32
|
+
/** 0..1 of a bar's width that no source sample covers, drawn across both panes. */
|
|
29
33
|
getAbsentFraction?: ((d: T) => number) | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The `series` key that names the absent share: its colour fills it and its legend entry labels
|
|
36
|
+
* it (give it `getValue: () => null`, it is legend-only). `BandStrip.absentState`'s shape. Its
|
|
37
|
+
* colour must differ from every measured series', not only by alpha. Default: a flat
|
|
38
|
+
* `--vx-neutral` with no legend entry. A key naming no entry throws.
|
|
39
|
+
*/
|
|
40
|
+
absentState?: K | undefined;
|
|
30
41
|
/** Per-datum bar opacity: a real but qualified measurement (a short bucket) drawn dimmer. */
|
|
31
42
|
getBarOpacity?: ((d: T) => number) | undefined;
|
|
32
43
|
/**
|
|
@@ -40,5 +51,5 @@ export type MirroredBarsProps<T, X extends ChartX = ChartX> = Pick<CartesianChar
|
|
|
40
51
|
/** Default `'leading'`: x is a slot's start. */
|
|
41
52
|
cursorResolution?: CartesianChartProps<T, X>['cursorResolution'] | undefined;
|
|
42
53
|
};
|
|
43
|
-
export declare function MirroredBars<T, X extends ChartX = ChartX>(props: MirroredBarsProps<T, X>): ReactElement;
|
|
54
|
+
export declare function MirroredBars<T, X extends ChartX = ChartX, K extends string = string>(props: MirroredBarsProps<T, X, K>): ReactElement;
|
|
44
55
|
//# sourceMappingURL=MirroredBars.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MirroredBars.d.ts","sourceRoot":"","sources":["../../src/charts/MirroredBars.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAUzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,EAAW,MAAM,SAAS,CAAA;AAEhF,4BAA4B;AAC5B,MAAM,MAAM,eAAe,GAAG;IAC5B;8EAC0E;IAC1E,GAAG,EAAE,MAAM,CAAA;IACX,+FAA+F;IAC/F,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACjC,sGAAsG;IACtG,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,2DAA2D;IAC3D,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAC9B,CAAA;AAED,oGAAoG;AACpG,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"MirroredBars.d.ts","sourceRoot":"","sources":["../../src/charts/MirroredBars.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAUzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,EAAW,MAAM,SAAS,CAAA;AAEhF,4BAA4B;AAC5B,MAAM,MAAM,eAAe,GAAG;IAC5B;8EAC0E;IAC1E,GAAG,EAAE,MAAM,CAAA;IACX,+FAA+F;IAC/F,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACjC,sGAAsG;IACtG,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,2DAA2D;IAC3D,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAC9B,CAAA;AAED,oGAAoG;AACpG,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,IAAI,CACjE,WAAW,CAAC,CAAC,CAAC,EACd,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CACxF,GAAG;IACF,GAAG,EAAE,CAAC,CAAA;IACN,kGAAkG;IAClG,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,IAAI,CAC3F,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,WAAW,GACX,MAAM,GACN,GAAG,GACH,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,aAAa,GACb,SAAS,GACT,WAAW,GACX,OAAO,CACV,GAAG;IACF,qEAAqE;IACrE,MAAM,EAAE,SAAS,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAA;IAC3C,gCAAgC;IAChC,EAAE,EAAE,eAAe,CAAA;IACnB,gCAAgC;IAChC,IAAI,EAAE,eAAe,CAAA;IACrB,uFAAuF;IACvF,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IAClD;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAC3B,6FAA6F;IAC7F,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IAC9C;;;OAGG;IACH,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;KAAE,GAAG,SAAS,CAAA;IAC/E,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,SAAS,CAAA;CAC7E,CAAA;AAsCD,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAClF,KAAK,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAChC,YAAY,CAoNd"}
|
|
@@ -10,7 +10,7 @@ import { defaultFormatX, defaultNumberFormat, seriesRow, visibleSeries } from ".
|
|
|
10
10
|
import { barMark, emphasis } from "./marks.js";
|
|
11
11
|
import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from "./panel.js";
|
|
12
12
|
import { xScaleFor } from "./scales.js";
|
|
13
|
-
import { foldBands } from "./band-fold.js";
|
|
13
|
+
import { foldBands, resolveNamedState } from "./band-fold.js";
|
|
14
14
|
import { rowX } from "./types.js";
|
|
15
15
|
const DEFAULT_UP_FRACTION = 0.35;
|
|
16
16
|
const DEFAULT_PANE_TICKS = 3;
|
|
@@ -36,14 +36,37 @@ function assertPaneKey(side, key, series) {
|
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
function MirroredBars(props) {
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const {
|
|
40
|
+
data,
|
|
41
|
+
x,
|
|
42
|
+
series,
|
|
43
|
+
up,
|
|
44
|
+
down,
|
|
45
|
+
upFraction = DEFAULT_UP_FRACTION,
|
|
46
|
+
getAbsentFraction,
|
|
47
|
+
getBarOpacity,
|
|
48
|
+
fold: foldConfig,
|
|
49
|
+
cursorResolution = "leading",
|
|
50
|
+
absentState,
|
|
51
|
+
...rung
|
|
52
|
+
} = props;
|
|
42
53
|
const { formatX } = rung;
|
|
54
|
+
const absentKey = resolveNamedState(
|
|
55
|
+
"MirroredBars",
|
|
56
|
+
"absentState",
|
|
57
|
+
absentState,
|
|
58
|
+
series.map((s) => s.key)
|
|
59
|
+
);
|
|
43
60
|
const bars = useMemo(
|
|
44
|
-
() => series.map((s) => ({
|
|
45
|
-
|
|
61
|
+
() => series.map((s) => ({
|
|
62
|
+
...s,
|
|
63
|
+
mark: "bar",
|
|
64
|
+
// A pane draws at full colour, so its swatch must not claim an opacity the plot lacks.
|
|
65
|
+
...s.key !== absentKey && { fillOpacity: void 0 }
|
|
66
|
+
})),
|
|
67
|
+
[series, absentKey]
|
|
46
68
|
);
|
|
69
|
+
const absentEntry = bars.find((s) => s.key === absentKey);
|
|
47
70
|
const plan = useCallback(
|
|
48
71
|
({ hidden, highlighted, width }) => {
|
|
49
72
|
const upSeries = assertPaneKey("up", up.key, bars);
|
|
@@ -55,6 +78,8 @@ function MirroredBars(props) {
|
|
|
55
78
|
) : data;
|
|
56
79
|
const model = xScaleFor(drawn.map(x), true);
|
|
57
80
|
const visible = visibleSeries(bars, hidden);
|
|
81
|
+
const absentOn = !absentEntry || visible.includes(absentEntry);
|
|
82
|
+
const absentFill = absentEntry ? alpha(absentEntry.color, absentEntry.fillOpacity ?? 1) : VX.neutral;
|
|
58
83
|
const upOn = visible.includes(upSeries);
|
|
59
84
|
const downOn = visible.includes(downSeries);
|
|
60
85
|
const format = (v) => formatX ? formatX(v) : defaultFormatX(v);
|
|
@@ -69,7 +94,7 @@ function MirroredBars(props) {
|
|
|
69
94
|
const rows = on ? rowsOf(drawn, x, s) : [];
|
|
70
95
|
const opacity = (d) => (getBarOpacity?.(d) ?? BAR_OPACITY) * emphasis(highlighted, s);
|
|
71
96
|
const left = (row) => (model.fraction(row.x) ?? 0) - bandWidth / 2;
|
|
72
|
-
const absent = (d) => clamp01(getAbsentFraction?.(d));
|
|
97
|
+
const absent = (d) => absentOn ? clamp01(getAbsentFraction?.(d)) : 0;
|
|
73
98
|
const measured = rows.filter(
|
|
74
99
|
(r) => r.y !== null && absent(r.datum) > 0 && absent(r.datum) < 1
|
|
75
100
|
);
|
|
@@ -125,7 +150,7 @@ function MirroredBars(props) {
|
|
|
125
150
|
y1: () => 0,
|
|
126
151
|
y2: () => max,
|
|
127
152
|
xScale: "zx",
|
|
128
|
-
fill:
|
|
153
|
+
fill: absentFill,
|
|
129
154
|
inset: 0
|
|
130
155
|
})
|
|
131
156
|
)
|
|
@@ -168,7 +193,19 @@ function MirroredBars(props) {
|
|
|
168
193
|
}
|
|
169
194
|
};
|
|
170
195
|
},
|
|
171
|
-
[
|
|
196
|
+
[
|
|
197
|
+
data,
|
|
198
|
+
x,
|
|
199
|
+
bars,
|
|
200
|
+
up,
|
|
201
|
+
down,
|
|
202
|
+
upFraction,
|
|
203
|
+
getAbsentFraction,
|
|
204
|
+
getBarOpacity,
|
|
205
|
+
foldConfig,
|
|
206
|
+
formatX,
|
|
207
|
+
absentEntry
|
|
208
|
+
]
|
|
172
209
|
);
|
|
173
210
|
return /* @__PURE__ */ jsx(
|
|
174
211
|
PanelRung,
|
|
@@ -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;
|
|
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;AAED,KAAK,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAwG5C;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,KAAK,EAAE,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GAAG,KAAK,GACnB,SAAS,KAAK,EAAE,CAIlB;AA8ED,qEAAqE;AAErE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,CAyC7D"}
|
package/dist/charts/Sparkline.js
CHANGED
|
@@ -14,6 +14,9 @@ import { CHART_THEME } from "./theme.js";
|
|
|
14
14
|
const LINE_WIDTH = 1.6;
|
|
15
15
|
const DOT_R = 2.5;
|
|
16
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
|
-
|
|
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 : (
|
|
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(
|
|
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;
|
|
@@ -12,4 +19,10 @@ export declare function groupsOf<T>(data: readonly T[], cap: number): Group<T>[]
|
|
|
12
19
|
* `floor(width / minBandPx)`.
|
|
13
20
|
*/
|
|
14
21
|
export declare function foldBands<T>(data: readonly T[], cap: number, merge: (group: T[]) => T): T[];
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a prop that names a `series` / `states` key (`absentState`): the key when it names an
|
|
24
|
+
* entry, `undefined` when it is unset. A key naming nothing throws in dev, naming the valid set;
|
|
25
|
+
* in production the chart degrades to the unset behaviour.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveNamedState<K extends string>(component: string, prop: string, requested: K | undefined, known: readonly string[]): K | undefined;
|
|
15
28
|
//# sourceMappingURL=band-fold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"band-fold.d.ts","sourceRoot":"","sources":["../../src/charts/band-fold.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/charts/band-fold.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { oneOf } from "../common/errors.js";
|
|
1
2
|
function groupsOf(data, cap) {
|
|
2
3
|
const size = Math.max(1, Math.ceil(data.length / Math.max(cap, 1)));
|
|
3
4
|
const out = [];
|
|
@@ -13,7 +14,16 @@ function foldBands(data, cap, merge) {
|
|
|
13
14
|
if (data.length <= cap) return [...data];
|
|
14
15
|
return groupsOf(data, cap).map((g) => merge(g.items));
|
|
15
16
|
}
|
|
17
|
+
function resolveNamedState(component, prop, requested, known) {
|
|
18
|
+
if (requested === void 0) return void 0;
|
|
19
|
+
if (known.includes(requested)) return requested;
|
|
20
|
+
if (process.env.NODE_ENV !== "production") {
|
|
21
|
+
throw new Error(oneOf(component, prop, [...known], requested));
|
|
22
|
+
}
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
16
25
|
export {
|
|
17
26
|
foldBands,
|
|
18
|
-
groupsOf
|
|
27
|
+
groupsOf,
|
|
28
|
+
resolveNamedState
|
|
19
29
|
};
|
package/dist/charts/compile.d.ts
CHANGED
|
@@ -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). */
|