basalt-ui 2.22.0 → 2.24.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 +68 -0
- package/MIGRATING.md +400 -12
- package/agent/agents/basalt-design-reviewer.md +3 -3
- package/agent/skills/basalt-design/SKILL.md +2 -2
- package/agent/skills/basalt-design/references/catalogue.md +22 -19
- package/agent/skills/basalt-design/references/states.md +39 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +51 -5
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +19 -3
- package/dist/charts/CartesianChart.d.ts +2 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +7 -3
- package/dist/charts/ChartCard.d.ts +1 -1
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +25 -15
- package/dist/charts/Sparkline.d.ts +8 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +95 -15
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +5 -1
- package/dist/charts/band-fold.d.ts +22 -4
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +10 -2
- package/dist/charts/chart-dates.d.ts +12 -0
- package/dist/charts/chart-dates.d.ts.map +1 -0
- package/dist/charts/chart-dates.js +16 -0
- package/dist/charts/chart-legend.module.css +16 -0
- package/dist/charts/compile.d.ts +10 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +77 -24
- package/dist/charts/date-tick-format.d.ts +5 -5
- package/dist/charts/date-tick-format.d.ts.map +1 -1
- package/dist/charts/date-tick-format.js +3 -7
- package/dist/charts/labels.d.ts +7 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +28 -17
- package/dist/charts/legend.d.ts +0 -6
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +87 -35
- package/dist/charts/ref-label.d.ts +17 -0
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +13 -1
- package/dist/charts/sparkline.module.css +62 -12
- package/dist/charts/sparkline.module.css.d.ts +1 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +4 -2
- package/dist/charts/types.d.ts +15 -3
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +9 -5
- package/dist/cli/shot/detect.js +8 -5
- package/dist/cli/shot/measure.js +19 -23
- package/dist/cli/shot/playwright.d.ts +8 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/playwright.js +5 -1
- package/dist/cli/shot/types.d.ts +2 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/tokens-css.d.ts +5 -7
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +11 -12
- package/dist/dashboard/bar-list.d.ts +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +8 -0
- package/dist/dashboard/bar-list.module.css +18 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/meter-model.d.ts +55 -21
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +98 -17
- package/dist/dashboard/meter-parts.d.ts +9 -2
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +99 -21
- package/dist/dashboard/meter.d.ts +21 -8
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +14 -3
- package/dist/dashboard/meter.module.css +57 -2
- package/dist/dashboard/meter.module.css.d.ts +5 -0
- package/dist/dashboard/query-state.d.ts +7 -3
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +15 -7
- package/dist/dashboard/section.d.ts +2 -1
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.module.css +12 -0
- package/dist/dashboard/settings-section.d.ts +1 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +3 -3
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.module.css +43 -10
- package/dist/dashboard/stat-group.module.css +15 -0
- package/dist/dashboard/stat-strip.d.ts +16 -5
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +100 -74
- package/dist/dashboard/stat-strip.module.css +68 -62
- package/dist/dashboard/stat-strip.module.css.d.ts +1 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +19 -1
- package/dist/dashboard/widget-header.module.css +6 -0
- package/dist/guard/index.d.ts +2 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +1 -17
- package/dist/styles.css +18 -11
- package/dist/table/data-table.js +1 -1
- package/dist/theme/controls.module.css +19 -0
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +12 -7
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- package/dist/tokens/palette.d.ts +7 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +7 -10
- package/llms.txt +7 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +55 -5
- package/src/charts/Bars.tsx +31 -3
- package/src/charts/CartesianChart.tsx +9 -3
- package/src/charts/ChartCard.tsx +32 -19
- package/src/charts/Sparkline.tsx +139 -21
- package/src/charts/StackedArea.tsx +12 -1
- package/src/charts/band-fold.ts +25 -6
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/chart-legend.module.css +16 -0
- package/src/charts/compile.ts +148 -25
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +43 -22
- package/src/charts/legend.tsx +70 -3
- package/src/charts/ref-label.ts +27 -0
- package/src/charts/sparkline.module.css +62 -12
- package/src/charts/sparkline.module.css.d.ts +1 -0
- package/src/charts/state.tsx +7 -4
- package/src/charts/types.ts +13 -3
- package/src/cli/shot/capture.ts +15 -3
- package/src/cli/shot/detect.ts +9 -9
- package/src/cli/shot/measure.ts +27 -27
- package/src/cli/shot/playwright.ts +18 -2
- package/src/cli/shot/types.ts +2 -0
- package/src/cli/tokens-css.ts +18 -20
- package/src/dashboard/bar-list.module.css +18 -0
- package/src/dashboard/bar-list.tsx +29 -0
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/empty-state.tsx +4 -2
- package/src/dashboard/meter-model.ts +181 -47
- package/src/dashboard/meter-parts.tsx +187 -30
- package/src/dashboard/meter.module.css +57 -2
- package/src/dashboard/meter.module.css.d.ts +5 -0
- package/src/dashboard/meter.tsx +33 -10
- package/src/dashboard/query-state.tsx +20 -9
- package/src/dashboard/section.module.css +12 -0
- package/src/dashboard/section.tsx +2 -1
- package/src/dashboard/settings-section.tsx +4 -4
- package/src/dashboard/stat-card-parts.tsx +1 -1
- package/src/dashboard/stat-card.module.css +43 -10
- package/src/dashboard/stat-group.module.css +15 -0
- package/src/dashboard/stat-strip.module.css +68 -62
- package/src/dashboard/stat-strip.module.css.d.ts +1 -0
- package/src/dashboard/stat-strip.tsx +118 -59
- package/src/dashboard/widget-header.module.css +6 -0
- package/src/dashboard/widget-header.tsx +28 -1
- package/src/guard/index.ts +3 -19
- package/src/styles.css +18 -11
- package/src/table/data-table.tsx +1 -1
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +14 -8
- package/src/theme/controls.module.css +19 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +12 -7
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/palette.ts +7 -10
package/dist/charts/Sparkline.js
CHANGED
|
@@ -6,12 +6,16 @@ import { ruleY } from "@tanstack/charts/rule";
|
|
|
6
6
|
import { scaleBand } from "@tanstack/charts/scales/band";
|
|
7
7
|
import { scaleLinear } from "@tanstack/charts/scales/linear";
|
|
8
8
|
import { text } from "@tanstack/charts/text";
|
|
9
|
-
import { useId, useMemo, useState } from "react";
|
|
9
|
+
import { useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
10
10
|
import { cx } from "../common/props.js";
|
|
11
11
|
import { VX, alpha } from "../tokens/index.js";
|
|
12
12
|
import { chartCurve } from "./curves.js";
|
|
13
13
|
import { barMark } from "./marks.js";
|
|
14
|
-
import {
|
|
14
|
+
import { VisualSlotContext } from "../dashboard/visual-slot.js";
|
|
15
|
+
import { bucketDay, dayGranular, defaultNumberFormat } from "./compile.js";
|
|
16
|
+
import { referenceLabelPlacement } from "./ref-label.js";
|
|
17
|
+
import { readoutClock, readoutDay } from "./chart-dates.js";
|
|
18
|
+
import { toDate } from "../format/shared.js";
|
|
15
19
|
import { ChartEngine, idPrefixOf } from "./host.js";
|
|
16
20
|
import classes from "./sparkline.module.css";
|
|
17
21
|
import { ChartPlaceholder, resolveChartState } from "./state.js";
|
|
@@ -19,13 +23,38 @@ import { CHART_THEME, DASH } from "./theme.js";
|
|
|
19
23
|
const LINE_WIDTH = 1.5;
|
|
20
24
|
const DOT_R = 2.5;
|
|
21
25
|
const BAR_GAP = 0.15;
|
|
26
|
+
const READOUT_GAP = 8;
|
|
22
27
|
const LINE_INSET = 3;
|
|
23
28
|
const MUTED_LINE = alpha(VX.muted, 0.35);
|
|
24
|
-
const
|
|
29
|
+
const REFERENCE_LABEL_DX = 3;
|
|
25
30
|
const LINE_PX_PER_POINT = 1;
|
|
26
31
|
const BAR_PX_PER_BAR = 2;
|
|
27
32
|
const LINE_POOL_MIN = 4;
|
|
33
|
+
const DAY_MS = 864e5;
|
|
28
34
|
const finite = (v) => Number.isFinite(v) ? v : null;
|
|
35
|
+
function momentsOf(data) {
|
|
36
|
+
const dates = [];
|
|
37
|
+
for (const d of data) {
|
|
38
|
+
if (typeof d !== "object" || d === null) return void 0;
|
|
39
|
+
dates.push(toDate(d.at));
|
|
40
|
+
}
|
|
41
|
+
const known = dates.filter((d) => d !== null);
|
|
42
|
+
if (known.length === 0) return void 0;
|
|
43
|
+
let lo = Number.POSITIVE_INFINITY;
|
|
44
|
+
let hi = Number.NEGATIVE_INFINITY;
|
|
45
|
+
for (const d of known) {
|
|
46
|
+
const day = Math.floor(d.getTime() / DAY_MS);
|
|
47
|
+
if (day < lo) lo = day;
|
|
48
|
+
if (day > hi) hi = day;
|
|
49
|
+
}
|
|
50
|
+
const clockOnly = lo === hi;
|
|
51
|
+
const byDay = dayGranular(known);
|
|
52
|
+
return dates.map((d) => {
|
|
53
|
+
if (d === null) return void 0;
|
|
54
|
+
if (byDay) return readoutDay(bucketDay(d));
|
|
55
|
+
return clockOnly ? readoutClock(d) : `${readoutDay(d)} ${readoutClock(d)}`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
29
58
|
function extent(rows) {
|
|
30
59
|
let lo = Number.POSITIVE_INFINITY;
|
|
31
60
|
let hi = Number.NEGATIVE_INFINITY;
|
|
@@ -102,7 +131,7 @@ function frameOf([lo, hi], mark, count, hasEnd) {
|
|
|
102
131
|
}
|
|
103
132
|
function compileSparkline(source, extentOf, mark, color, emphasisColor, reference, referenceLabel) {
|
|
104
133
|
const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null);
|
|
105
|
-
const referenceMark = () => reference === null ? [] : [
|
|
134
|
+
const referenceMark = (height) => reference === null ? [] : [
|
|
106
135
|
ruleY([reference], {
|
|
107
136
|
id: "reference",
|
|
108
137
|
stroke: VX.line,
|
|
@@ -120,19 +149,29 @@ function compileSparkline(source, extentOf, mark, color, emphasisColor, referenc
|
|
|
120
149
|
fill: VX.ink2,
|
|
121
150
|
fontSize: VX.text.micro,
|
|
122
151
|
anchor: "start",
|
|
123
|
-
|
|
152
|
+
dx: REFERENCE_LABEL_DX,
|
|
153
|
+
dy: referenceLabelPlacement({
|
|
154
|
+
value: reference,
|
|
155
|
+
domain: frame.y,
|
|
156
|
+
height,
|
|
157
|
+
inset: mark === "bar" ? 0 : LINE_INSET,
|
|
158
|
+
fontSize: VX.text.micro
|
|
159
|
+
}).dy
|
|
124
160
|
})
|
|
125
161
|
)
|
|
126
162
|
]
|
|
127
163
|
];
|
|
128
164
|
return {
|
|
129
|
-
|
|
165
|
+
// A bar's hover is the bar and the readout chip: no engine point marker (bar chrome only, as
|
|
166
|
+
// `Bars`).
|
|
167
|
+
...mark === "bar" && { focusRing: false },
|
|
168
|
+
chart: ({ width, height }) => {
|
|
130
169
|
const rows = poolSparkline(source, width, mark);
|
|
131
170
|
const last = rows.at(-1);
|
|
132
171
|
if (mark === "bar") {
|
|
133
172
|
return {
|
|
134
173
|
marks: [
|
|
135
|
-
...referenceMark(),
|
|
174
|
+
...referenceMark(height),
|
|
136
175
|
barMark(rows, {
|
|
137
176
|
id: "bars",
|
|
138
177
|
x: "i",
|
|
@@ -157,7 +196,7 @@ function compileSparkline(source, extentOf, mark, color, emphasisColor, referenc
|
|
|
157
196
|
}
|
|
158
197
|
return {
|
|
159
198
|
marks: [
|
|
160
|
-
...referenceMark(),
|
|
199
|
+
...referenceMark(height),
|
|
161
200
|
lineY(rows, {
|
|
162
201
|
id: "line",
|
|
163
202
|
x: "i",
|
|
@@ -205,6 +244,14 @@ function meanOf(rows) {
|
|
|
205
244
|
}
|
|
206
245
|
return sum / n;
|
|
207
246
|
}
|
|
247
|
+
function fitReadout(node) {
|
|
248
|
+
const overflows = () => node.scrollWidth > node.clientWidth;
|
|
249
|
+
node.removeAttribute("data-tight");
|
|
250
|
+
node.removeAttribute("data-stacked");
|
|
251
|
+
if (!overflows()) return;
|
|
252
|
+
node.setAttribute("data-tight", "");
|
|
253
|
+
if (overflows()) node.setAttribute("data-stacked", "");
|
|
254
|
+
}
|
|
208
255
|
function Sparkline(props) {
|
|
209
256
|
const {
|
|
210
257
|
ariaLabel,
|
|
@@ -225,11 +272,16 @@ function Sparkline(props) {
|
|
|
225
272
|
style
|
|
226
273
|
} = props;
|
|
227
274
|
const id = useId();
|
|
275
|
+
const hosted = useContext(VisualSlotContext) !== null;
|
|
228
276
|
const [hover, setHover] = useState(null);
|
|
229
277
|
const [keyed, setKeyed] = useState(null);
|
|
230
278
|
const active = hover ?? keyed;
|
|
279
|
+
const readoutRef = useRef(null);
|
|
231
280
|
const model = useMemo(() => {
|
|
232
|
-
const rows2 = data.map((
|
|
281
|
+
const rows2 = data.map((d, i) => ({
|
|
282
|
+
i,
|
|
283
|
+
v: finite(typeof d === "object" && d !== null ? d.value : d)
|
|
284
|
+
}));
|
|
233
285
|
const range = extent(rows2);
|
|
234
286
|
if (range === null) return null;
|
|
235
287
|
const at2 = reference === "mean" ? meanOf(rows2) : reference ?? null;
|
|
@@ -238,6 +290,7 @@ function Sparkline(props) {
|
|
|
238
290
|
const end = emphasizeLast ? emphasisColor : null;
|
|
239
291
|
return {
|
|
240
292
|
rows: rows2,
|
|
293
|
+
moments: momentsOf(data),
|
|
241
294
|
frame: frameOf(full, mark, rows2.length, end !== null),
|
|
242
295
|
definition: compileSparkline(rows2, full, mark, color, end, ref, referenceLabel)
|
|
243
296
|
};
|
|
@@ -269,18 +322,43 @@ function Sparkline(props) {
|
|
|
269
322
|
setKeyed(lastFinite(rows));
|
|
270
323
|
};
|
|
271
324
|
const inset = mark === "line" ? LINE_INSET : 0;
|
|
272
|
-
const layerStyle = { inset, "--basalt-spark-
|
|
325
|
+
const layerStyle = { inset, ["--basalt-spark-inset"]: `${inset}px` };
|
|
273
326
|
const value = active === null ? null : rows?.[active]?.v ?? null;
|
|
274
327
|
const at = interactive && active !== null && value !== null ? {
|
|
275
328
|
value,
|
|
276
329
|
fx: mark === "bar" ? (active + 0.5) / model.rows.length : (active - model.frame.x[0]) / (model.frame.x[1] - model.frame.x[0]),
|
|
277
330
|
fy: (model.frame.y[1] - value) / (model.frame.y[1] - model.frame.y[0]),
|
|
278
|
-
label: labels?.[active]
|
|
331
|
+
label: labels?.[active] ?? model.moments?.[active]
|
|
279
332
|
} : null;
|
|
333
|
+
const beside = at === null ? null : at.fx > 0.5 ? "left" : "right";
|
|
334
|
+
const shown = at !== null;
|
|
335
|
+
useLayoutEffect(() => {
|
|
336
|
+
if (readoutRef.current !== null) fitReadout(readoutRef.current);
|
|
337
|
+
}, [active, at?.label, at?.value, beside]);
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
const layer = readoutRef.current?.parentElement;
|
|
340
|
+
if (!shown || !layer || typeof ResizeObserver === "undefined") return;
|
|
341
|
+
const observer = new ResizeObserver(() => {
|
|
342
|
+
if (readoutRef.current !== null) fitReadout(readoutRef.current);
|
|
343
|
+
});
|
|
344
|
+
observer.observe(layer);
|
|
345
|
+
return () => observer.disconnect();
|
|
346
|
+
}, [shown]);
|
|
347
|
+
const readoutStyle = at === null ? void 0 : hosted ? { left: `${at.fx * 100}%`, translate: `${-at.fx * 100}% 0`, maxWidth: "100%" } : {
|
|
348
|
+
...beside === "right" ? {
|
|
349
|
+
left: `calc(${at.fx * 100}% + ${READOUT_GAP}px)`,
|
|
350
|
+
maxWidth: `calc(${(1 - at.fx) * 100}% - ${READOUT_GAP}px)`
|
|
351
|
+
} : {
|
|
352
|
+
right: `calc(${(1 - at.fx) * 100}% + ${READOUT_GAP}px)`,
|
|
353
|
+
maxWidth: `calc(${at.fx * 100}% - ${READOUT_GAP}px)`
|
|
354
|
+
},
|
|
355
|
+
...at.fy > 0.5 ? { top: 0 } : { bottom: 0 }
|
|
356
|
+
};
|
|
280
357
|
return /* @__PURE__ */ jsxs(
|
|
281
358
|
"div",
|
|
282
359
|
{
|
|
283
360
|
"data-basalt-sparkline": "",
|
|
361
|
+
...hosted && { "data-basalt-hosted": "" },
|
|
284
362
|
role: "presentation",
|
|
285
363
|
className: cx(classes.root, className),
|
|
286
364
|
style: { width: width ?? "100%", height, minWidth: 0, ...style },
|
|
@@ -305,9 +383,10 @@ function Sparkline(props) {
|
|
|
305
383
|
}
|
|
306
384
|
),
|
|
307
385
|
at !== null && // One layer on the plot rect (inside a line's margin): the dot and the readout take their
|
|
308
|
-
// fractions of the same box, so both land where the mark did.
|
|
386
|
+
// fractions of the same box, so both land where the mark did. A bar has no dot: the bar
|
|
387
|
+
// is the marker.
|
|
309
388
|
/* @__PURE__ */ jsxs("span", { "aria-hidden": "true", className: classes.layer, style: layerStyle, children: [
|
|
310
|
-
/* @__PURE__ */ jsx(
|
|
389
|
+
mark === "line" && /* @__PURE__ */ jsx(
|
|
311
390
|
"span",
|
|
312
391
|
{
|
|
313
392
|
"data-basalt-sparkline-dot": "",
|
|
@@ -318,14 +397,15 @@ function Sparkline(props) {
|
|
|
318
397
|
/* @__PURE__ */ jsxs(
|
|
319
398
|
"output",
|
|
320
399
|
{
|
|
400
|
+
ref: readoutRef,
|
|
321
401
|
"data-basalt-sparkline-readout": "",
|
|
322
402
|
"aria-live": hover === null ? "polite" : "off",
|
|
323
403
|
className: classes.readout,
|
|
324
|
-
style:
|
|
404
|
+
style: readoutStyle,
|
|
325
405
|
children: [
|
|
326
406
|
format(at.value),
|
|
327
407
|
at.label !== void 0 && /* @__PURE__ */ jsxs("span", { className: classes.label, children: [
|
|
328
|
-
" \xB7 ",
|
|
408
|
+
/* @__PURE__ */ jsx("span", { className: classes.sep, children: " \xB7 " }),
|
|
329
409
|
at.label
|
|
330
410
|
] })
|
|
331
411
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StackedArea.d.ts","sourceRoot":"","sources":["../../src/charts/StackedArea.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StackedArea.d.ts","sourceRoot":"","sources":["../../src/charts/StackedArea.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,OAAO,KAAK,EAAE,mBAAmB,EAAc,WAAW,EAAE,MAAM,EAAe,MAAM,SAAS,CAAA;AAIhG,gGAAgG;AAChG,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,IAAI,CACnC,WAAW,CAAC,CAAC,CAAC,EACd,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAChG,GAAG;IACF,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,IAAI,CAC/D,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EACzB,OAAO,GAAG,GAAG,GAAG,IAAI,GAAG,QAAQ,CAChC,GAAG;IACF,gCAAgC;IAChC,MAAM,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAA;IACrC;qEACiE;IACjE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,iEAAiE;IACjE,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CAC3E,CAAA;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EACtD,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC5B,YAAY,CAoDd"}
|
|
@@ -8,7 +8,11 @@ import { emphasis } from "./marks.js";
|
|
|
8
8
|
import { rowX } from "./types.js";
|
|
9
9
|
const DEFAULT_BAND_OPACITY = 0.85;
|
|
10
10
|
function StackedArea(props) {
|
|
11
|
-
const { series:
|
|
11
|
+
const { series: given, fillOpacity, ...rest } = props;
|
|
12
|
+
const bands = useMemo(
|
|
13
|
+
() => rest.data.length === 0 ? given : given.filter((b) => !rest.data.every((d) => b.getValue(d) === 0)),
|
|
14
|
+
[given, rest.data]
|
|
15
|
+
);
|
|
12
16
|
const series = useMemo(
|
|
13
17
|
() => bands.map((s) => ({
|
|
14
18
|
...s,
|
|
@@ -18,12 +18,29 @@ export type NamedChartState = Pick<ChartSeries<never>, 'key' | 'label' | 'color'
|
|
|
18
18
|
};
|
|
19
19
|
/** The status inks a state can name: `VX.status.*`. */
|
|
20
20
|
export type StatusTone = 'good' | 'warn' | 'bad' | 'neutral';
|
|
21
|
-
|
|
22
|
-
export declare function glyphOf(s: Pick<NamedChartState, 'glyph' | 'tone'> & {
|
|
21
|
+
type ToneSource = Pick<NamedChartState, 'glyph' | 'tone'> & {
|
|
23
22
|
color?: string | undefined;
|
|
24
|
-
}
|
|
25
|
-
/** A
|
|
23
|
+
};
|
|
24
|
+
/** A state's status tone: its own, else the one its status colour names. */
|
|
25
|
+
export declare function toneOf(s: ToneSource): StatusTone | undefined;
|
|
26
|
+
/** The glyph a state draws: its own, else its status tone's default, else none. */
|
|
27
|
+
export declare function glyphOf(s: ToneSource): string | undefined;
|
|
28
|
+
/** A heat cell narrower than this (px) draws no glyph: it would not fit inside the fill. */
|
|
26
29
|
export declare const GLYPH_MIN_PX = 12;
|
|
30
|
+
/**
|
|
31
|
+
* A `BandStrip` cell narrower than this (px) draws no glyph: its fill is full-height, so the glyph
|
|
32
|
+
* is set at the xs size (a 16 px line), and a `!` or `×` is unreadable in less. Such a cell draws a
|
|
33
|
+
* notch instead, see {@link NOTCH_PX}. A `Heatmap` keeps {@link GLYPH_MIN_PX}.
|
|
34
|
+
*/
|
|
35
|
+
export declare const BAND_GLYPH_MIN_PX = 16;
|
|
36
|
+
/**
|
|
37
|
+
* The height (px) of the bottom notch a glyph state draws where the glyph does not fit: a warn
|
|
38
|
+
* notch is shorter than a bad one, so the state is never told by hue alone.
|
|
39
|
+
*/
|
|
40
|
+
export declare const NOTCH_PX: {
|
|
41
|
+
readonly warn: 3;
|
|
42
|
+
readonly bad: 6;
|
|
43
|
+
};
|
|
27
44
|
/** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
|
|
28
45
|
export type Group<T> = {
|
|
29
46
|
start: number;
|
|
@@ -44,4 +61,5 @@ export declare function foldBands<T>(data: readonly T[], cap: number, merge: (gr
|
|
|
44
61
|
* in production the chart degrades to the unset behaviour.
|
|
45
62
|
*/
|
|
46
63
|
export declare function resolveNamedState<K extends string>(component: string, prop: string, requested: K | undefined, known: readonly string[]): K | undefined;
|
|
64
|
+
export {};
|
|
47
65
|
//# 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":"AAEA,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,GAAG;IACF;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B;gDAC4C;IAC5C,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;CAC9B,CAAA;AAED,uDAAuD;AACvD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAA;AAK5D,
|
|
1
|
+
{"version":3,"file":"band-fold.d.ts","sourceRoot":"","sources":["../../src/charts/band-fold.ts"],"names":[],"mappings":"AAEA,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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BAAiB,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,11 +1,16 @@
|
|
|
1
1
|
import { oneOf } from "../common/errors.js";
|
|
2
2
|
import { VX } from "../tokens/index.js";
|
|
3
3
|
const TONE_GLYPH = { warn: "!", bad: "\xD7" };
|
|
4
|
+
function toneOf(s) {
|
|
5
|
+
return s.tone ?? (s.color === VX.status.warn ? "warn" : s.color === VX.status.bad ? "bad" : void 0);
|
|
6
|
+
}
|
|
4
7
|
function glyphOf(s) {
|
|
5
|
-
const tone =
|
|
8
|
+
const tone = toneOf(s);
|
|
6
9
|
return s.glyph ?? (tone === void 0 ? void 0 : TONE_GLYPH[tone]);
|
|
7
10
|
}
|
|
8
11
|
const GLYPH_MIN_PX = 12;
|
|
12
|
+
const BAND_GLYPH_MIN_PX = 16;
|
|
13
|
+
const NOTCH_PX = { warn: 3, bad: 6 };
|
|
9
14
|
function groupsOf(data, cap) {
|
|
10
15
|
const size = Math.max(1, Math.ceil(data.length / Math.max(cap, 1)));
|
|
11
16
|
const out = [];
|
|
@@ -30,9 +35,12 @@ function resolveNamedState(component, prop, requested, known) {
|
|
|
30
35
|
return void 0;
|
|
31
36
|
}
|
|
32
37
|
export {
|
|
38
|
+
BAND_GLYPH_MIN_PX,
|
|
33
39
|
GLYPH_MIN_PX,
|
|
40
|
+
NOTCH_PX,
|
|
34
41
|
foldBands,
|
|
35
42
|
glyphOf,
|
|
36
43
|
groupsOf,
|
|
37
|
-
resolveNamedState
|
|
44
|
+
resolveNamedState,
|
|
45
|
+
toneOf
|
|
38
46
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** An axis tick's day: `4 Oct` (the page locale's own order). */
|
|
2
|
+
export declare const axisDay: (d: Date) => string;
|
|
3
|
+
/** {@link axisDay} with a two-digit year. */
|
|
4
|
+
export declare const axisDayYear: (d: Date) => string;
|
|
5
|
+
export declare const monthName: (d: Date) => string;
|
|
6
|
+
/** The tooltip header's date: weekday, day, month and year. */
|
|
7
|
+
export declare const headerDay: (d: Date) => string;
|
|
8
|
+
/** A day written out for a readout (`12 Oct`): the same format as an axis tick. */
|
|
9
|
+
export declare const readoutDay: (d: Date) => string;
|
|
10
|
+
/** A clock time for a readout, `HH:MM` in the page locale's digits. */
|
|
11
|
+
export declare const readoutClock: (d: Date) => string;
|
|
12
|
+
//# sourceMappingURL=chart-dates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-dates.d.ts","sourceRoot":"","sources":["../../src/charts/chart-dates.ts"],"names":[],"mappings":"AAWA,iEAAiE;AACjE,eAAO,MAAM,OAAO,GAAI,GAAG,IAAI,KAAG,MAA0D,CAAA;AAE5F,6CAA6C;AAC7C,eAAO,MAAM,WAAW,GAAI,GAAG,IAAI,KAAG,MAC6B,CAAA;AAEnE,eAAO,MAAM,SAAS,GAAI,GAAG,IAAI,KAAG,MAA0C,CAAA;AAE9E,+DAA+D;AAC/D,eAAO,MAAM,SAAS,GAAI,GAAG,IAAI,KAAG,MACiD,CAAA;AAErF,mFAAmF;AACnF,eAAO,MAAM,UAAU,MAbI,IAAI,KAAG,MAaD,CAAA;AAEjC,uEAAuE;AACvE,eAAO,MAAM,YAAY,GAAI,GAAG,IAAI,KAAG,MACiC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { dateFormat } from "../format/shared.js";
|
|
2
|
+
const utcFormat = (options, d) => dateFormat(void 0, { ...options, timeZone: "UTC" }).format(d);
|
|
3
|
+
const axisDay = (d) => utcFormat({ day: "numeric", month: "short" }, d);
|
|
4
|
+
const axisDayYear = (d) => utcFormat({ day: "numeric", month: "short", year: "2-digit" }, d);
|
|
5
|
+
const monthName = (d) => utcFormat({ month: "short" }, d);
|
|
6
|
+
const headerDay = (d) => utcFormat({ weekday: "short", day: "numeric", month: "short", year: "numeric" }, d);
|
|
7
|
+
const readoutDay = axisDay;
|
|
8
|
+
const readoutClock = (d) => utcFormat({ hour: "2-digit", minute: "2-digit", hourCycle: "h23" }, d);
|
|
9
|
+
export {
|
|
10
|
+
axisDay,
|
|
11
|
+
axisDayYear,
|
|
12
|
+
headerDay,
|
|
13
|
+
monthName,
|
|
14
|
+
readoutClock,
|
|
15
|
+
readoutDay
|
|
16
|
+
};
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@container (min-width: 240px) {
|
|
18
|
+
/* One row: `foldLegend` (legend.tsx) folds what does not fit into `+N`; zones lead the series. */
|
|
18
19
|
.auto {
|
|
20
|
+
flex-wrap: nowrap;
|
|
21
|
+
overflow: hidden;
|
|
19
22
|
display: flex;
|
|
20
23
|
column-gap: var(--bc-dots-gap);
|
|
21
24
|
--vx-hit-gap: var(--bc-dots-gap);
|
|
@@ -24,6 +27,8 @@
|
|
|
24
27
|
|
|
25
28
|
@container (min-width: 480px) {
|
|
26
29
|
.auto {
|
|
30
|
+
flex-wrap: wrap;
|
|
31
|
+
overflow: visible;
|
|
27
32
|
column-gap: var(--bc-legend-gap);
|
|
28
33
|
--vx-hit-gap: var(--bc-legend-gap);
|
|
29
34
|
}
|
|
@@ -43,3 +48,14 @@
|
|
|
43
48
|
display: none;
|
|
44
49
|
}
|
|
45
50
|
}
|
|
51
|
+
|
|
52
|
+
/* The compact fold (`foldLegend`, which only folds while the row is `nowrap`); wide keeps every entry.
|
|
53
|
+
* `!important`: an entry's inline `all: unset` (legend.tsx) would otherwise reset `display`. */
|
|
54
|
+
.auto [data-legend-folded] {
|
|
55
|
+
display: none !important;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.auto [data-legend-more] {
|
|
59
|
+
order: 1;
|
|
60
|
+
flex: none;
|
|
61
|
+
}
|
package/dist/charts/compile.d.ts
CHANGED
|
@@ -30,8 +30,16 @@ export type CartesianInput<T, X extends ChartX> = Pick<CartesianChartProps<T, X>
|
|
|
30
30
|
tooltipBelow?: boolean;
|
|
31
31
|
/** The vertical rule under the cursor. Default `true`; a bar kind has none (its hover is the bar). */
|
|
32
32
|
crosshair?: boolean;
|
|
33
|
+
/** The engine's point marker on the focused datum. Default `true`; a bar kind has none (its hover is the bar). */
|
|
34
|
+
focusRing?: boolean;
|
|
33
35
|
};
|
|
34
36
|
export declare function defaultNumberFormat(v: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* The UTC midnight of the day a day-keyed instant stands for. A key at LOCAL midnight is that local
|
|
39
|
+
* calendar date (east of UTC it is `22:00` UTC of the day before); any other key is its UTC date, so
|
|
40
|
+
* a key at 12:00 UTC or later never rolls to the next day.
|
|
41
|
+
*/
|
|
42
|
+
export declare function bucketDay(d: Date): Date;
|
|
35
43
|
/**
|
|
36
44
|
* The tooltip's date: weekday, day, month and year in the page's locale (`defineFormat` /
|
|
37
45
|
* `BasaltProvider`), read in UTC like the time scale; a non-midnight instant adds `HH:MM`. With
|
|
@@ -58,6 +66,8 @@ export declare function engineRow(row: ChartTooltipRow & {
|
|
|
58
66
|
export declare function seriesRow(s: Pick<ChartSeries<never>, 'label' | 'note' | 'color' | 'dash'>, value: string, active: boolean): EngineTooltipRow;
|
|
59
67
|
/** Legend-only entries for the reference lines that name themselves, in line order. */
|
|
60
68
|
export declare function refLegendSeries<T>(refLines: readonly RefLine[] | undefined): ChartSeries<T>[];
|
|
69
|
+
/** Legend-only entries for the zones that name themselves (`ZoneSpec.legend`), in zone order. */
|
|
70
|
+
export declare function zoneLegendSeries<T>(zones: readonly ZoneSpec[] | undefined): ChartSeries<T>[];
|
|
61
71
|
/** The visible series: not toggled off, and not a companion whose parent is. */
|
|
62
72
|
export declare function visibleSeries<T>(series: readonly ChartSeries<T>[], hidden: ReadonlySet<string>): ChartSeries<T>[];
|
|
63
73
|
type YAxis = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAGV,aAAa,EAEb,yBAAyB,EACzB,eAAe,IAAI,gBAAgB,EACnC,UAAU,EACV,yBAAyB,EAE1B,MAAM,6BAA6B,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAO5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEnB,WAAW,EACX,eAAe,EACf,MAAM,EAEN,OAAO,EAEP,QAAQ,EACT,MAAM,SAAS,CAAA;AAEhB;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AAE/F,gGAAgG;AAChG,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,IAAI,CACpD,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,MAAM,GACN,GAAG,GACH,QAAQ,GACR,OAAO,GACP,GAAG,GACH,IAAI,GACJ,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,QAAQ,GACR,UAAU,GACV,aAAa,GACb,kBAAkB,GAClB,SAAS,CACZ,GAAG;IACF,8FAA8F;IAC9F,OAAO,EAAE,MAAM,CAAA;IACf,8CAA8C;IAC9C,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC5B,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,wDAAwD;IACxD,I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from "./date-tick-format.js";
|
|
2
3
|
import { crosshair } from "@tanstack/charts/crosshair";
|
|
3
4
|
import { decorative } from "@tanstack/charts/mark/decorative";
|
|
@@ -8,7 +9,7 @@ import { scaleLinear } from "@tanstack/charts/scales/linear";
|
|
|
8
9
|
import { scaleUtc } from "d3-scale";
|
|
9
10
|
import { portal } from "@tanstack/charts/tooltip/portal";
|
|
10
11
|
import { compact } from "../format/number.js";
|
|
11
|
-
import { NON_FINITE,
|
|
12
|
+
import { NON_FINITE, numberFormat } from "../format/shared.js";
|
|
12
13
|
import { VX } from "../tokens/index.js";
|
|
13
14
|
import { cursorBinding, followerOptions, quietWhileFollowing } from "./cursor.js";
|
|
14
15
|
import { cursorDots } from "./marks.js";
|
|
@@ -37,22 +38,9 @@ function bucketDay(d) {
|
|
|
37
38
|
}
|
|
38
39
|
function utcHeaderDate(d, dayOnly = false) {
|
|
39
40
|
if (!Number.isFinite(d.getTime())) return NON_FINITE;
|
|
40
|
-
const
|
|
41
|
-
const date = dateFormat(void 0, {
|
|
42
|
-
weekday: "short",
|
|
43
|
-
day: "numeric",
|
|
44
|
-
month: "short",
|
|
45
|
-
year: "numeric",
|
|
46
|
-
timeZone: "UTC"
|
|
47
|
-
}).format(at);
|
|
41
|
+
const date = headerDay(dayOnly ? bucketDay(d) : d);
|
|
48
42
|
if (dayOnly || d.getTime() % DAY_MS === 0) return date;
|
|
49
|
-
|
|
50
|
-
hour: "2-digit",
|
|
51
|
-
minute: "2-digit",
|
|
52
|
-
hourCycle: "h23",
|
|
53
|
-
timeZone: "UTC"
|
|
54
|
-
}).format(d);
|
|
55
|
-
return `${date} ${clock}`;
|
|
43
|
+
return `${date} ${readoutClock(d)}`;
|
|
56
44
|
}
|
|
57
45
|
const DAY_MS = 864e5;
|
|
58
46
|
function dateTicks(domain, count, stepMs) {
|
|
@@ -87,6 +75,7 @@ function seriesRow(s, value, active) {
|
|
|
87
75
|
});
|
|
88
76
|
}
|
|
89
77
|
const REF_KEY_PREFIX = "__ref-";
|
|
78
|
+
const ZONE_KEY_PREFIX = "__zone-";
|
|
90
79
|
const refLegendKey = (index) => `${REF_KEY_PREFIX}${index}`;
|
|
91
80
|
const SWATCH_SOLID = /* @__PURE__ */ new Map([
|
|
92
81
|
[VX.goodRef, VX.goodSolid],
|
|
@@ -114,23 +103,59 @@ function refLegendSeries(refLines) {
|
|
|
114
103
|
]
|
|
115
104
|
);
|
|
116
105
|
}
|
|
106
|
+
function zoneLegendSeries(zones) {
|
|
107
|
+
return (zones ?? []).flatMap(
|
|
108
|
+
(z, i) => z.legend === void 0 ? [] : [
|
|
109
|
+
{
|
|
110
|
+
key: `${ZONE_KEY_PREFIX}${i}`,
|
|
111
|
+
label: z.legend.label,
|
|
112
|
+
color: z.legend.color ?? SWATCH_SOLID.get(z.fill) ?? z.fill,
|
|
113
|
+
mark: z.legend.mark ?? "bar",
|
|
114
|
+
role: "reference",
|
|
115
|
+
tooltip: false,
|
|
116
|
+
getValue: () => null
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
);
|
|
120
|
+
}
|
|
117
121
|
function visibleSeries(series, hidden) {
|
|
118
122
|
return series.filter(
|
|
119
123
|
(s) => !hidden.has(s.key) && !(s.parent !== void 0 && hidden.has(s.parent))
|
|
120
124
|
);
|
|
121
125
|
}
|
|
126
|
+
const decimalSeparator = () => numberFormat(void 0, {}).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
127
|
+
const zeroFraction = (separator) => new RegExp(`(\\d)${separator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}0+(?!\\d)`, "g");
|
|
128
|
+
function wholeStepFormat(axis, cfg, ticks) {
|
|
129
|
+
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)];
|
|
130
|
+
const values = "values" in ticks ? ticks.values : cfg?.scale === "log" ? [] : scaleLinear().domain([lo, hi]).ticks(ticks.count);
|
|
131
|
+
if (values.length === 0 || !values.every(Number.isInteger)) return axis.format;
|
|
132
|
+
const padded = zeroFraction(decimalSeparator());
|
|
133
|
+
return (v) => axis.format(v).replace(padded, "$1");
|
|
134
|
+
}
|
|
135
|
+
const END_TICK_MIN_GAP = 0.4;
|
|
136
|
+
function withEndTick(cfg, axis, count) {
|
|
137
|
+
if (!Array.isArray(cfg?.domain) || cfg.scale === "log" || cfg.nice === true) return null;
|
|
138
|
+
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)];
|
|
139
|
+
const round = scaleLinear().domain([lo, hi]).ticks(count);
|
|
140
|
+
const last = round.at(-1);
|
|
141
|
+
const next = round.at(1);
|
|
142
|
+
const first = round.at(0);
|
|
143
|
+
if (last === void 0 || next === void 0 || first === void 0 || last >= hi) return null;
|
|
144
|
+
return hi - last >= (next - first) * END_TICK_MIN_GAP ? { values: [...round, hi] } : null;
|
|
145
|
+
}
|
|
122
146
|
function yGuide(opts) {
|
|
123
147
|
const { cfg, axis, cls, side, grid } = opts;
|
|
124
148
|
const ladder = LADDER[cls];
|
|
125
|
-
const ticks = typeof cfg?.ticks === "object" ? { values: cfg.ticks } : { count: typeof cfg?.ticks === "number" ? cfg.ticks : ladder.yTicks };
|
|
149
|
+
const ticks = typeof cfg?.ticks === "object" ? { values: cfg.ticks } : (cls === "compact" && cfg?.ticks === void 0 ? withEndTick(cfg, axis, ladder.yTicks) : null) ?? { count: typeof cfg?.ticks === "number" ? cfg.ticks : ladder.yTicks };
|
|
126
150
|
const gridLine = grid ? { grid: GRID_LINE } : {};
|
|
127
151
|
if (cls === "micro") return { ...gridLine, axis: false };
|
|
152
|
+
const tickFormat = wholeStepFormat(axis, cfg, ticks);
|
|
128
153
|
return {
|
|
129
154
|
...gridLine,
|
|
130
155
|
...side === "right" && { side: "right" },
|
|
131
156
|
axis: {
|
|
132
157
|
line: false,
|
|
133
|
-
ticks: { ...ticks, format:
|
|
158
|
+
ticks: { ...ticks, format: tickFormat, line: false },
|
|
134
159
|
tickLabels: { fontSize: TICK_FONT, opacity: 1 }
|
|
135
160
|
}
|
|
136
161
|
};
|
|
@@ -159,8 +184,8 @@ function xTickFormat(consumer, tickValues) {
|
|
|
159
184
|
if (consumer) return consumer;
|
|
160
185
|
if (tickValues.length === 0 || !tickValues.every((v) => v instanceof Date))
|
|
161
186
|
return defaultFormatX;
|
|
162
|
-
const
|
|
163
|
-
return (v) => v instanceof Date ?
|
|
187
|
+
const dateFormat = dateTickFormat(tickValues);
|
|
188
|
+
return (v) => v instanceof Date ? dateFormat(v) : defaultFormatX(v);
|
|
164
189
|
}
|
|
165
190
|
function xGuide(opts) {
|
|
166
191
|
const { model, xTicks, cls } = opts;
|
|
@@ -413,6 +438,7 @@ function underlayMarks(input, model, axes) {
|
|
|
413
438
|
});
|
|
414
439
|
return [...zones, ...xZones];
|
|
415
440
|
}
|
|
441
|
+
const BAR_BODY = 0.8;
|
|
416
442
|
const REF_LABEL_DX = 6;
|
|
417
443
|
const REF_LABEL_DY_ABOVE = -5;
|
|
418
444
|
const REF_LABEL_DY_BELOW = 11;
|
|
@@ -506,7 +532,7 @@ function buildScales(opts) {
|
|
|
506
532
|
}
|
|
507
533
|
function tooltipHeader(input, formatX, dayOnly, v, d) {
|
|
508
534
|
if (input.tooltip && input.tooltip.formatHeader) return input.tooltip.formatHeader(v, d);
|
|
509
|
-
if (v instanceof Date && !input.formatX) return utcHeaderDate(v, dayOnly);
|
|
535
|
+
if (v instanceof Date && (!input.formatX || dayOnly)) return utcHeaderDate(v, dayOnly);
|
|
510
536
|
return formatX(v);
|
|
511
537
|
}
|
|
512
538
|
function dayGranular(values) {
|
|
@@ -559,6 +585,22 @@ const stripAnchor = (points, { plot }) => {
|
|
|
559
585
|
};
|
|
560
586
|
const STRIP_TOOLTIP_PLACEMENT = ["bottom", "top"];
|
|
561
587
|
const STRIP_TOOLTIP_OFFSET = 8;
|
|
588
|
+
const TIP_CHROME = 30;
|
|
589
|
+
const TIP_ROW = 18;
|
|
590
|
+
const TIP_TOP_AIR = 4;
|
|
591
|
+
const TIP_SIDE_STEP = 96;
|
|
592
|
+
const barAnchor = (rows) => (points, { plot }) => {
|
|
593
|
+
const xs = points.map((p) => p.x);
|
|
594
|
+
const ys = points.map((p) => p.y);
|
|
595
|
+
const centre = (Math.min(...xs) + Math.max(...xs)) / 2;
|
|
596
|
+
const x = Math.min(Math.max(centre, plot.x), plot.x + plot.width);
|
|
597
|
+
const y = (Math.min(...ys) + Math.max(...ys)) / 2;
|
|
598
|
+
const floor = plot.y + TIP_TOP_AIR + TIP_CHROME + rows * TIP_ROW;
|
|
599
|
+
if (y >= floor) return { x, y };
|
|
600
|
+
const toRight = x - plot.x < plot.width / 2;
|
|
601
|
+
const stepped = x + (toRight ? TIP_SIDE_STEP : -TIP_SIDE_STEP);
|
|
602
|
+
return { x: Math.min(Math.max(stepped, plot.x), plot.x + plot.width), y: floor };
|
|
603
|
+
};
|
|
562
604
|
function tooltipSpec(opts) {
|
|
563
605
|
const { input, axes, visible, keys, visibleKeys, formatX, dayOnly } = opts;
|
|
564
606
|
const hidden = input.series.filter((s) => !visibleKeys.has(s.key));
|
|
@@ -569,7 +611,7 @@ function tooltipSpec(opts) {
|
|
|
569
611
|
use: quietWhileFollowing,
|
|
570
612
|
...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
|
|
571
613
|
portal,
|
|
572
|
-
anchor: input.tooltipBelow ? stripAnchor : "group-center",
|
|
614
|
+
anchor: input.tooltipBelow ? stripAnchor : visible.some((s) => s.mark === "bar") ? barAnchor(rowSeries.length) : "group-center",
|
|
573
615
|
...input.tooltipBelow && { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET },
|
|
574
616
|
content: (points) => {
|
|
575
617
|
const primary = points[0];
|
|
@@ -624,10 +666,18 @@ function compileCartesian(input) {
|
|
|
624
666
|
);
|
|
625
667
|
const dayOnly = dayGranular(model.values);
|
|
626
668
|
const names = (input.refLines ?? []).some((r) => r.label !== void 0 && r.label !== "");
|
|
669
|
+
const barHalf = model.halfStep * BAR_BODY;
|
|
627
670
|
const linesOn = (side) => visible.filter((s) => shared.onRight(s) === (side === "right" && shared.right !== null)).map(
|
|
628
671
|
(s) => rows(s.key).flatMap((r) => {
|
|
629
672
|
const fx = model.fraction(r.x);
|
|
630
|
-
|
|
673
|
+
if (fx === null || r.y === null) return [];
|
|
674
|
+
if (!(model.band && s.mark === "bar")) return [{ fx, y: r.y }];
|
|
675
|
+
return [
|
|
676
|
+
{ fx: fx - barHalf, y: 0 },
|
|
677
|
+
{ fx: fx - barHalf, y: r.y },
|
|
678
|
+
{ fx: fx + barHalf, y: r.y },
|
|
679
|
+
{ fx: fx + barHalf, y: 0 }
|
|
680
|
+
];
|
|
631
681
|
})
|
|
632
682
|
);
|
|
633
683
|
const definition = {
|
|
@@ -689,6 +739,7 @@ function compileCartesian(input) {
|
|
|
689
739
|
// Followers resolve the leader's group, so they draw its dots; `quietWhileFollowing` mutes the
|
|
690
740
|
// tooltip unless the chart opts into following tooltips.
|
|
691
741
|
focus: "group-x",
|
|
742
|
+
...input.focusRing === false && { focusRing: false },
|
|
692
743
|
maxFocusDistance: Number.POSITIVE_INFINITY,
|
|
693
744
|
cursor: cursorBinding({
|
|
694
745
|
group: input.cursorGroup,
|
|
@@ -705,6 +756,7 @@ function compileCartesian(input) {
|
|
|
705
756
|
export {
|
|
706
757
|
areaGradient,
|
|
707
758
|
areaGradientId,
|
|
759
|
+
bucketDay,
|
|
708
760
|
compileCartesian,
|
|
709
761
|
dashedSwatch,
|
|
710
762
|
dateTicks,
|
|
@@ -720,5 +772,6 @@ export {
|
|
|
720
772
|
xGuide,
|
|
721
773
|
xTickFormat,
|
|
722
774
|
yGuide,
|
|
723
|
-
zoneAreaGradient
|
|
775
|
+
zoneAreaGradient,
|
|
776
|
+
zoneLegendSeries
|
|
724
777
|
};
|