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
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The default Date x tick labels: chosen from the TICK step (not the data step), read in UTC like
|
|
3
3
|
* the scale that placed them. A label may recur on one axis only behind a MARKER label (a day or a
|
|
4
|
-
* year) — `12:00, 18:00, 18
|
|
4
|
+
* year) — `12:00, 18:00, 18 Oct, 06:00, 12:00` is fine, `17 Oct, 17 Oct, 18 Oct` is not. Each span has
|
|
5
5
|
* a ladder of levels, plainest first; the first level that holds the invariant wins. The last rung
|
|
6
6
|
* of every ladder names the whole date (or instant) of its tick, so the invariant always holds.
|
|
7
7
|
*/
|
|
8
8
|
export declare const pad2: (n: number) => string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare
|
|
9
|
+
/** The day (`4 Oct`, in the page locale), read in UTC like the time scale (a local read shifts a
|
|
10
|
+
* day west of UTC). */
|
|
11
|
+
export declare const utcAxisDate: (d: Date) => string;
|
|
12
12
|
/**
|
|
13
13
|
* A formatter for one tick set. A Date that is not among the ticks (a hover, a consumer reading
|
|
14
|
-
* the axis format) reads as plain
|
|
14
|
+
* the axis format) reads as the plain day: its position in the set is undefined.
|
|
15
15
|
*/
|
|
16
16
|
export declare function dateTickFormat(ticks: readonly Date[]): (d: Date) => string;
|
|
17
17
|
//# sourceMappingURL=date-tick-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-tick-format.d.ts","sourceRoot":"","sources":["../../src/charts/date-tick-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"date-tick-format.d.ts","sourceRoot":"","sources":["../../src/charts/date-tick-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,eAAO,MAAM,IAAI,GAAI,GAAG,MAAM,KAAG,MAAoC,CAAA;AAUrE;uBACuB;AACvB,eAAO,MAAM,WAAW,qBAAU,CAAA;AAgGlC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,KAAK,MAAM,CAM1E"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { axisDay, axisDayYear, monthName } from "./chart-dates.js";
|
|
2
2
|
const pad2 = (n) => String(n).padStart(2, "0");
|
|
3
|
-
const monthName = (d) => MONTHS[d.getUTCMonth()];
|
|
4
3
|
const DAY_MS = 864e5;
|
|
5
4
|
const HOUR_MS = 36e5;
|
|
6
5
|
const MONTH_STEP_MS = 27 * DAY_MS;
|
|
7
|
-
|
|
8
|
-
return `${pad2(d.getUTCDate())}.${pad2(d.getUTCMonth() + 1)}`;
|
|
9
|
-
}
|
|
6
|
+
const utcAxisDate = axisDay;
|
|
10
7
|
const utcClock = (d) => `${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`;
|
|
11
8
|
const utcClockSeconds = (d) => `${utcClock(d)}:${pad2(d.getUTCSeconds())}`;
|
|
12
9
|
const utcClockMillis = (d) => `${utcClockSeconds(d)}.${String(d.getUTCMilliseconds()).padStart(3, "0")}`;
|
|
13
|
-
const utcAxisDateYear =
|
|
10
|
+
const utcAxisDateYear = axisDayYear;
|
|
14
11
|
const isMidnight = (t) => t % DAY_MS === 0;
|
|
15
12
|
const isJanuary = (d) => d.getUTCMonth() === 0;
|
|
16
13
|
const dayOf = (t) => Math.floor(t / DAY_MS);
|
|
@@ -75,7 +72,6 @@ function dateTickFormat(ticks) {
|
|
|
75
72
|
}
|
|
76
73
|
export {
|
|
77
74
|
dateTickFormat,
|
|
78
|
-
monthName,
|
|
79
75
|
pad2,
|
|
80
76
|
utcAxisDate
|
|
81
77
|
};
|
package/dist/charts/labels.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types.js';
|
|
2
2
|
export type EndLabelAnchor = 'start' | 'end';
|
|
3
|
+
/** Which side of its line a flipped label sits: away from the line's last segment. */
|
|
4
|
+
export type EndLabelSide = 'above' | 'below';
|
|
3
5
|
/**
|
|
4
6
|
* The side of its point an end label takes: `start` (right of the point) unless the point leaves
|
|
5
7
|
* less room than the label needs. `fraction` is the point's x as a share of the plot width,
|
|
@@ -19,13 +21,15 @@ export type EndLabel<T, X extends ChartX> = {
|
|
|
19
21
|
series: ChartSeries<T>;
|
|
20
22
|
row: PlotRow<T, X>;
|
|
21
23
|
anchor: EndLabelAnchor;
|
|
24
|
+
/** Only a flipped label (left of its point) can meet its own line; it takes the clear side. */
|
|
25
|
+
side: EndLabelSide;
|
|
22
26
|
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
|
|
23
27
|
nudge: number;
|
|
24
28
|
};
|
|
25
29
|
/**
|
|
26
30
|
* Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
|
|
27
31
|
* shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
|
|
28
|
-
* topmost
|
|
32
|
+
* lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot. Order is kept.
|
|
29
33
|
*/
|
|
30
34
|
export declare function spreadLabels(ys: readonly number[], plotHeight: number): number[];
|
|
31
35
|
/**
|
|
@@ -36,8 +40,8 @@ export declare function spreadLabels(ys: readonly number[], plotHeight: number):
|
|
|
36
40
|
* (`plot.xFraction` outside [0, 1]: clipped by a narrower `xDomain`), has no label.
|
|
37
41
|
*/
|
|
38
42
|
export declare function endLabelPlan<T, X extends ChartX>(plot: PlotContext<T, X>, lines: readonly ChartSeries<T>[], naming?: LinesNaming): EndLabel<T, X>[];
|
|
39
|
-
/** The offset of a label from its point: right of it, level; or left of it
|
|
40
|
-
export declare function endLabelOffset(anchor: EndLabelAnchor): {
|
|
43
|
+
/** The offset of a label from its point: right of it, level; or left of it, above or below. */
|
|
44
|
+
export declare function endLabelOffset(anchor: EndLabelAnchor, side?: EndLabelSide): {
|
|
41
45
|
dx: number;
|
|
42
46
|
dy: number;
|
|
43
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/charts/labels.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/charts/labels.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAmBpF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,CAAA;AAC5C,sFAAsF;AACtF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,CAAA;AAE5C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,cAAc,CAIjB;AAED,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEzD,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI;IAC1C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IACtB,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAClB,MAAM,EAAE,cAAc,CAAA;IACtB,+FAA+F;IAC/F,IAAI,EAAE,YAAY,CAAA;IAClB,6FAA6F;IAC7F,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAWD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBhF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAC9C,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,KAAK,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,EAChC,MAAM,GAAE,WAAoB,GAC3B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAsClB;AAED,+FAA+F;AAC/F,wBAAgB,cAAc,CAC5B,MAAM,EAAE,cAAc,EACtB,IAAI,GAAE,YAAsB,GAC3B;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAG5B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,SAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,UAAU,CAgB9F"}
|
package/dist/charts/labels.js
CHANGED
|
@@ -7,6 +7,8 @@ const END_LABEL_MIN_GAP = 13;
|
|
|
7
7
|
const END_LABEL_DX = 6;
|
|
8
8
|
const END_LABEL_GLYPH_EM = 0.85;
|
|
9
9
|
const END_LABEL_FLIP_DY = -9;
|
|
10
|
+
const END_LABEL_FLIP_DY_BELOW = 13;
|
|
11
|
+
const END_LABEL_EDGE = 7;
|
|
10
12
|
function endLabelAnchor(opts) {
|
|
11
13
|
const { fraction, plotWidth, label, fontSize } = opts;
|
|
12
14
|
const room = (1 - fraction) * plotWidth;
|
|
@@ -15,13 +17,13 @@ function endLabelAnchor(opts) {
|
|
|
15
17
|
function spreadLabels(ys, plotHeight) {
|
|
16
18
|
const order = ys.map((y, i) => i).toSorted((a, b) => ys[a] - ys[b]);
|
|
17
19
|
const placed = /* @__PURE__ */ new Map();
|
|
18
|
-
let floor =
|
|
20
|
+
let floor = END_LABEL_EDGE;
|
|
19
21
|
for (const i of order) {
|
|
20
22
|
const at = Math.max(ys[i], floor);
|
|
21
23
|
placed.set(i, at);
|
|
22
24
|
floor = at + END_LABEL_MIN_GAP;
|
|
23
25
|
}
|
|
24
|
-
const top = plotHeight -
|
|
26
|
+
const top = plotHeight - END_LABEL_EDGE;
|
|
25
27
|
let ceiling = Infinity;
|
|
26
28
|
for (const i of order.toReversed()) {
|
|
27
29
|
const at = Math.min(placed.get(i), ceiling, top);
|
|
@@ -35,35 +37,44 @@ function endLabelPlan(plot, lines, naming = "auto") {
|
|
|
35
37
|
if (naming === "auto" && (plot.containerClass !== "wide" || lines.length > MAX_END_LABELS))
|
|
36
38
|
return [];
|
|
37
39
|
const last = lines.flatMap((series) => {
|
|
38
|
-
const
|
|
40
|
+
const finite = plot.rows(series.key).filter((r) => r.y !== null);
|
|
41
|
+
const row = finite.at(-1);
|
|
39
42
|
if (row === void 0 || row.y === null) return [];
|
|
40
43
|
const fraction = plot.xFraction(row.x);
|
|
41
44
|
if (fraction === null || fraction < 0 || fraction > 1) return [];
|
|
42
|
-
return [{ series, row, y: row.y, fraction }];
|
|
45
|
+
return [{ series, row, y: row.y, fraction, prev: finite.at(-2)?.y ?? null }];
|
|
43
46
|
});
|
|
44
47
|
const [lo, hi] = plot.yDomain;
|
|
48
|
+
const placed = last.map(({ series, fraction, y, prev }) => {
|
|
49
|
+
const anchor = endLabelAnchor({
|
|
50
|
+
fraction,
|
|
51
|
+
plotWidth: plot.plotWidth,
|
|
52
|
+
label: series.label,
|
|
53
|
+
fontSize: VX.text.micro
|
|
54
|
+
});
|
|
55
|
+
const side = prev !== null && prev > y ? "below" : "above";
|
|
56
|
+
const centre = (y - lo) / (hi - lo || 1) * plot.plotHeight - endLabelOffset(anchor, side).dy;
|
|
57
|
+
return { anchor, side, centre };
|
|
58
|
+
});
|
|
45
59
|
const shifts = spreadLabels(
|
|
46
|
-
|
|
60
|
+
placed.map((p) => p.centre),
|
|
47
61
|
plot.plotHeight
|
|
48
62
|
);
|
|
49
|
-
return last.map(({ series, row
|
|
63
|
+
return last.map(({ series, row }, i) => ({
|
|
50
64
|
series,
|
|
51
65
|
row,
|
|
52
|
-
anchor:
|
|
53
|
-
|
|
54
|
-
plotWidth: plot.plotWidth,
|
|
55
|
-
label: series.label,
|
|
56
|
-
fontSize: VX.text.micro
|
|
57
|
-
}),
|
|
66
|
+
anchor: placed[i].anchor,
|
|
67
|
+
side: placed[i].side,
|
|
58
68
|
nudge: 0 - shifts[i]
|
|
59
69
|
}));
|
|
60
70
|
}
|
|
61
|
-
function endLabelOffset(anchor) {
|
|
62
|
-
|
|
71
|
+
function endLabelOffset(anchor, side = "above") {
|
|
72
|
+
if (anchor === "start") return { dx: END_LABEL_DX, dy: 0 };
|
|
73
|
+
return { dx: -END_LABEL_DX, dy: side === "above" ? END_LABEL_FLIP_DY : END_LABEL_FLIP_DY_BELOW };
|
|
63
74
|
}
|
|
64
75
|
function endLabelMarks(plan) {
|
|
65
76
|
return plan.map(
|
|
66
|
-
({ series, row, anchor, nudge }) => decorative(
|
|
77
|
+
({ series, row, anchor, side, nudge }) => decorative(
|
|
67
78
|
text([row], {
|
|
68
79
|
id: `${series.key}-end-label`,
|
|
69
80
|
x: rowX,
|
|
@@ -72,8 +83,8 @@ function endLabelMarks(plan) {
|
|
|
72
83
|
fill: series.color,
|
|
73
84
|
fontSize: VX.text.micro,
|
|
74
85
|
anchor,
|
|
75
|
-
dx: endLabelOffset(anchor).dx,
|
|
76
|
-
dy: endLabelOffset(anchor).dy + nudge
|
|
86
|
+
dx: endLabelOffset(anchor, side).dx,
|
|
87
|
+
dy: endLabelOffset(anchor, side).dy + nudge
|
|
77
88
|
})
|
|
78
89
|
)
|
|
79
90
|
);
|
package/dist/charts/legend.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The derived legend — HTML, Mantine-free, outside the engine. Entries come from `series` only (a
|
|
3
|
-
* legend cannot name what the plot does not draw); a companion (`legend: false` + `parent`) rides
|
|
4
|
-
* its parent's entry. Toggling an entry hides the series from the plot, the tooltip and the auto
|
|
5
|
-
* domain together; hovering one emphasizes it (the definition is rebuilt with `highlighted`).
|
|
6
|
-
*/
|
|
7
1
|
import type { ReactElement } from 'react';
|
|
8
2
|
import type { ChartSeries } from './types.js';
|
|
9
3
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/charts/legend.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/charts/legend.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAA;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAelD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,CAAC,EAC7B,MAAM,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,EACjC,MAAM,EAAE,OAAO,GACd,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAOpB;AAyDD;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAWrF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;;;;;CAGd,CAAA;AAuDV,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,MAAM,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;IAClC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACzC,kGAAkG;IAClG,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AA2CD,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CA+E9E"}
|
package/dist/charts/legend.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
2
3
|
import { VX } from "../tokens/index.js";
|
|
3
4
|
import classes from "./chart-legend.module.css";
|
|
4
5
|
const ROLE_ORDER = ["series", "overlay", "reference"];
|
|
5
6
|
const DOTS_GAP = 30;
|
|
7
|
+
const byReferenceFirst = (a, b) => Number(b.role === "reference") - Number(a.role === "reference");
|
|
6
8
|
function legendEntries(series, groups) {
|
|
7
9
|
const entries = series.filter((s) => s.legend !== false);
|
|
8
|
-
if (!groups) return entries.length ? [entries] : [];
|
|
10
|
+
if (!groups) return entries.length ? [entries.toSorted(byReferenceFirst)] : [];
|
|
9
11
|
return ROLE_ORDER.map((role) => entries.filter((s) => (s.role ?? "series") === role)).filter(
|
|
10
12
|
(g) => g.length > 0
|
|
11
13
|
);
|
|
@@ -24,8 +26,9 @@ const rowBaseStyle = {
|
|
|
24
26
|
lineHeight: 1.35
|
|
25
27
|
};
|
|
26
28
|
const rowStyle = { ...rowBaseStyle, display: "flex" };
|
|
29
|
+
const { flexWrap: _wrap, ...autoBaseStyle } = rowBaseStyle;
|
|
27
30
|
const autoRowStyle = {
|
|
28
|
-
...
|
|
31
|
+
...autoBaseStyle,
|
|
29
32
|
"--bc-legend-gap": `${VX.legendGap}px`,
|
|
30
33
|
"--bc-dots-gap": `${DOTS_GAP}px`
|
|
31
34
|
};
|
|
@@ -113,60 +116,109 @@ function Swatch({ s, mode }) {
|
|
|
113
116
|
}
|
|
114
117
|
);
|
|
115
118
|
}
|
|
119
|
+
const VISUALLY_HIDDEN = {
|
|
120
|
+
position: "absolute",
|
|
121
|
+
width: "1px",
|
|
122
|
+
height: "1px",
|
|
123
|
+
overflow: "hidden",
|
|
124
|
+
clipPath: "inset(50%)",
|
|
125
|
+
whiteSpace: "nowrap"
|
|
126
|
+
};
|
|
127
|
+
function foldLegend(row) {
|
|
128
|
+
const items = [...row.querySelectorAll("[data-legend-key]")];
|
|
129
|
+
const more = row.querySelector("[data-legend-more]");
|
|
130
|
+
for (const it of items) it.removeAttribute("data-legend-folded");
|
|
131
|
+
more?.setAttribute("hidden", "");
|
|
132
|
+
if (more === null || getComputedStyle(row).flexWrap !== "nowrap") return;
|
|
133
|
+
const display = items;
|
|
134
|
+
const folded = [];
|
|
135
|
+
while (row.scrollWidth > row.clientWidth + 0.5 && folded.length < display.length - 1) {
|
|
136
|
+
const last = display[display.length - 1 - folded.length];
|
|
137
|
+
if (last === void 0) break;
|
|
138
|
+
last.setAttribute("data-legend-folded", "");
|
|
139
|
+
folded.push(last);
|
|
140
|
+
more.removeAttribute("hidden");
|
|
141
|
+
const names = folded.map((f) => f.textContent).join(", ");
|
|
142
|
+
more.textContent = `+${folded.length}`;
|
|
143
|
+
more.title = names;
|
|
144
|
+
const hiddenNames = document.createElement("span");
|
|
145
|
+
hiddenNames.textContent = `: ${names}`;
|
|
146
|
+
Object.assign(hiddenNames.style, VISUALLY_HIDDEN);
|
|
147
|
+
more.append(hiddenNames);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
116
150
|
function ChartLegend(props) {
|
|
151
|
+
const rowRef = useRef(null);
|
|
152
|
+
const auto = props.mode === "auto";
|
|
153
|
+
const signature = props.series.map((s) => s.key).join("|");
|
|
154
|
+
useLayoutEffect(() => {
|
|
155
|
+
if (auto && rowRef.current !== null) foldLegend(rowRef.current);
|
|
156
|
+
}, [auto, signature]);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
const row = rowRef.current;
|
|
159
|
+
if (!auto || row === null || typeof ResizeObserver === "undefined") return;
|
|
160
|
+
const observer = new ResizeObserver(() => foldLegend(row));
|
|
161
|
+
observer.observe(row);
|
|
162
|
+
return () => observer.disconnect();
|
|
163
|
+
}, [auto, signature]);
|
|
117
164
|
const groups = legendEntries(props.series, props.groups);
|
|
118
165
|
if (groups.length === 0) return null;
|
|
119
|
-
|
|
120
|
-
return /* @__PURE__ */ jsx(
|
|
166
|
+
return /* @__PURE__ */ jsxs(
|
|
121
167
|
"fieldset",
|
|
122
168
|
{
|
|
169
|
+
ref: rowRef,
|
|
123
170
|
"aria-label": "Legend",
|
|
124
171
|
"data-basalt-chart-legend": props.mode,
|
|
125
172
|
...props.concealed && { "aria-hidden": true },
|
|
126
173
|
...auto && { className: classes.auto },
|
|
127
174
|
...auto && props.hideAtWide && { "data-hide-wide": "" },
|
|
128
175
|
style: rowLayout(props.mode, props.concealed === true),
|
|
129
|
-
children:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/* @__PURE__ */
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
176
|
+
children: [
|
|
177
|
+
groups.map((group, gi) => [
|
|
178
|
+
gi > 0 && /* @__PURE__ */ jsx("span", { "aria-hidden": true, style: dividerStyle }, `divider-${gi}`),
|
|
179
|
+
...group.map((s) => {
|
|
180
|
+
const off = props.hidden.has(s.key);
|
|
181
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
182
|
+
/* @__PURE__ */ jsx(Swatch, { s, mode: props.mode }),
|
|
183
|
+
/* @__PURE__ */ jsx("span", { children: s.label }),
|
|
184
|
+
s.note !== void 0 && /* @__PURE__ */ jsx("span", { style: noteStyle, children: s.note })
|
|
185
|
+
] });
|
|
186
|
+
const itemStyle = { ...buttonStyle, opacity: off ? 0.4 : 1 };
|
|
187
|
+
if (!props.toggle)
|
|
188
|
+
return /* @__PURE__ */ jsx(
|
|
189
|
+
"span",
|
|
190
|
+
{
|
|
191
|
+
"data-legend-key": s.key,
|
|
192
|
+
"data-legend-role": s.role ?? "series",
|
|
193
|
+
style: itemStyle,
|
|
194
|
+
onMouseEnter: () => props.onHighlight(s.key),
|
|
195
|
+
onMouseLeave: () => props.onHighlight(null),
|
|
196
|
+
children: content
|
|
197
|
+
},
|
|
198
|
+
s.key
|
|
199
|
+
);
|
|
140
200
|
return /* @__PURE__ */ jsx(
|
|
141
|
-
"
|
|
201
|
+
"button",
|
|
142
202
|
{
|
|
203
|
+
type: "button",
|
|
143
204
|
"data-legend-key": s.key,
|
|
205
|
+
"data-legend-role": s.role ?? "series",
|
|
206
|
+
"data-basalt-hit": "",
|
|
207
|
+
"aria-pressed": !off,
|
|
144
208
|
style: itemStyle,
|
|
209
|
+
onClick: () => props.onToggle(s.key),
|
|
145
210
|
onMouseEnter: () => props.onHighlight(s.key),
|
|
146
211
|
onMouseLeave: () => props.onHighlight(null),
|
|
212
|
+
onFocus: () => props.onHighlight(s.key),
|
|
213
|
+
onBlur: () => props.onHighlight(null),
|
|
147
214
|
children: content
|
|
148
215
|
},
|
|
149
216
|
s.key
|
|
150
217
|
);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
"data-legend-key": s.key,
|
|
156
|
-
"data-basalt-hit": "",
|
|
157
|
-
"aria-pressed": !off,
|
|
158
|
-
style: itemStyle,
|
|
159
|
-
onClick: () => props.onToggle(s.key),
|
|
160
|
-
onMouseEnter: () => props.onHighlight(s.key),
|
|
161
|
-
onMouseLeave: () => props.onHighlight(null),
|
|
162
|
-
onFocus: () => props.onHighlight(s.key),
|
|
163
|
-
onBlur: () => props.onHighlight(null),
|
|
164
|
-
children: content
|
|
165
|
-
},
|
|
166
|
-
s.key
|
|
167
|
-
);
|
|
168
|
-
})
|
|
169
|
-
])
|
|
218
|
+
})
|
|
219
|
+
]),
|
|
220
|
+
auto && /* @__PURE__ */ jsx("span", { "data-legend-more": "", hidden: true, style: noteStyle })
|
|
221
|
+
]
|
|
170
222
|
}
|
|
171
223
|
);
|
|
172
224
|
}
|
|
@@ -23,4 +23,21 @@ export declare function refLabelPosition(opts: {
|
|
|
23
23
|
/** One polyline per visible series on the line's axis. */
|
|
24
24
|
series: readonly (readonly RefLabelPoint[])[];
|
|
25
25
|
}): RefLabelPosition;
|
|
26
|
+
/**
|
|
27
|
+
* Which side of its line a sparkline's reference label sits on, and its `dy` (the engine centres
|
|
28
|
+
* the text on its y): above by default, below when the line is too near the plot top for the label
|
|
29
|
+
* box to fit above it. The box clears the line by {@link SPARK_LABEL_GAP}, so the dashed rule never
|
|
30
|
+
* strikes the text, and stays inside the plot (`height` less the line inset each side).
|
|
31
|
+
*/
|
|
32
|
+
export declare function referenceLabelPlacement(opts: {
|
|
33
|
+
value: number;
|
|
34
|
+
domain: readonly [number, number];
|
|
35
|
+
height: number;
|
|
36
|
+
/** The plot's margin inside the svg box, px. */
|
|
37
|
+
inset: number;
|
|
38
|
+
fontSize: number;
|
|
39
|
+
}): {
|
|
40
|
+
side: 'above' | 'below';
|
|
41
|
+
dy: number;
|
|
42
|
+
};
|
|
26
43
|
//# sourceMappingURL=ref-label.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-label.d.ts","sourceRoot":"","sources":["../../src/charts/ref-label.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,GAAG,aAAa,GAAG,aAAa,CAAA;AAExF,sFAAsF;AACtF,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAkDrD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,qDAAqD;IACrD,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACpC,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC,SAAS,aAAa,EAAE,CAAC,EAAE,CAAA;CAC9C,GAAG,gBAAgB,CA+BnB"}
|
|
1
|
+
{"version":3,"file":"ref-label.d.ts","sourceRoot":"","sources":["../../src/charts/ref-label.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,GAAG,aAAa,GAAG,aAAa,CAAA;AAExF,sFAAsF;AACtF,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAkDrD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,qDAAqD;IACrD,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACpC,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC,SAAS,aAAa,EAAE,CAAC,EAAE,CAAA;CAC9C,GAAG,gBAAgB,CA+BnB;AAKD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG;IAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAS1C"}
|
package/dist/charts/ref-label.js
CHANGED
|
@@ -58,6 +58,18 @@ function refLabelPosition(opts) {
|
|
|
58
58
|
};
|
|
59
59
|
return order.find((p) => inPlot(p) && clear(p)) ?? order.find(inPlot) ?? order[0];
|
|
60
60
|
}
|
|
61
|
+
const SPARK_LABEL_GAP = 2;
|
|
62
|
+
function referenceLabelPlacement(opts) {
|
|
63
|
+
const { value, domain, height, inset, fontSize } = opts;
|
|
64
|
+
const [lo, hi] = [Math.min(...domain), Math.max(...domain)];
|
|
65
|
+
const share = hi === lo ? 0 : (value - lo) / (hi - lo);
|
|
66
|
+
const line = inset + (height - 2 * inset) * (1 - share);
|
|
67
|
+
const reach = SPARK_LABEL_GAP + fontSize + 1;
|
|
68
|
+
const side = line - reach >= 0 || line + reach > height ? "above" : "below";
|
|
69
|
+
const dy = (SPARK_LABEL_GAP + (fontSize + 1) / 2) * (side === "above" ? -1 : 1);
|
|
70
|
+
return { side, dy };
|
|
71
|
+
}
|
|
61
72
|
export {
|
|
62
|
-
refLabelPosition
|
|
73
|
+
refLabelPosition,
|
|
74
|
+
referenceLabelPlacement
|
|
63
75
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip. Inside a host that
|
|
3
|
+
* reserves a line for it (`StatCard`'s sparkline slot, a strip cell's visual: `data-basalt-hosted`,
|
|
4
|
+
* `--basalt-spark-readout-h`) it sits ABOVE the plot, so it never covers the plotted line, the dashed
|
|
5
|
+
* reference or the dot. A bare `Sparkline` has no such line, so its chip stays inside its own box
|
|
6
|
+
* (placed inline in `Sparkline.tsx`, away from the point). `Sparkline.tsx` slides it with the point
|
|
7
|
+
* (`left` + `translate` by one fraction), which keeps it inside the box at either edge at any width.
|
|
8
|
+
* `--basalt-spark-readout-lift: 0` on a host puts the chip back in the box.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
.root {
|
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
.readout {
|
|
16
16
|
position: absolute;
|
|
17
|
-
/* The layer is inset from the root by the line's plot margin; lifting by it puts the chip back
|
|
18
|
-
* on the root's top edge, the line a host slot reserves. */
|
|
19
|
-
bottom: calc(100% + var(--basalt-spark-lift, 0px));
|
|
20
17
|
z-index: 1;
|
|
18
|
+
max-height: 100%;
|
|
21
19
|
max-width: 100%;
|
|
22
20
|
box-sizing: border-box;
|
|
23
21
|
padding: 0 4px;
|
|
@@ -25,8 +23,8 @@
|
|
|
25
23
|
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
26
24
|
font-variant-numeric: lining-nums;
|
|
27
25
|
font-size: var(--vx-text-xs);
|
|
28
|
-
/* The
|
|
29
|
-
* value (`stat-card.module.css`, `stat-strip.module.css`)
|
|
26
|
+
/* The chip's height: hosts that reserve a line for it set `--basalt-spark-readout-h` to the same
|
|
27
|
+
* value (`stat-card.module.css`, `stat-strip.module.css`). */
|
|
30
28
|
block-size: var(--basalt-spark-readout-h, 1.125rem);
|
|
31
29
|
line-height: calc(var(--basalt-spark-readout-h, 1.125rem) - 2px);
|
|
32
30
|
color: var(--vx-tooltip-text);
|
|
@@ -38,10 +36,62 @@
|
|
|
38
36
|
border-radius: var(--vx-radius-ctrl);
|
|
39
37
|
}
|
|
40
38
|
|
|
39
|
+
/* The host's reserved line: above the plot. The chip's bottom meets the sparkline's own top edge (the
|
|
40
|
+
* layer sits `--basalt-spark-inset` below it). */
|
|
41
|
+
[data-basalt-hosted] .readout {
|
|
42
|
+
top: calc(
|
|
43
|
+
var(--basalt-spark-readout-lift, 1) * -1 *
|
|
44
|
+
(var(--basalt-spark-readout-h, 1.125rem) + var(--basalt-spark-inset, 0px))
|
|
45
|
+
);
|
|
46
|
+
max-height: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
.label {
|
|
42
50
|
opacity: 0.7;
|
|
43
51
|
}
|
|
44
52
|
|
|
53
|
+
.sep {
|
|
54
|
+
white-space: pre;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* A readout that overflows its box first drops the air round its separator and its padding. */
|
|
58
|
+
.readout[data-tight] {
|
|
59
|
+
padding-inline: 2px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.readout[data-tight] .sep {
|
|
63
|
+
letter-spacing: -0.15em;
|
|
64
|
+
word-spacing: -0.25em;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* A readout that still overflows stacks (set in `Sparkline.tsx`): the date on its own line, wrapped
|
|
68
|
+
* not clipped. It sits INSIDE the plot's top band (the lift-0 placement), hosted or bare: a hosted
|
|
69
|
+
* chip grown past the host's one reserved line would cover the figure's delta or qualifier above. */
|
|
70
|
+
.readout[data-stacked] {
|
|
71
|
+
block-size: auto;
|
|
72
|
+
max-height: none;
|
|
73
|
+
padding-block: 1px;
|
|
74
|
+
line-height: 1.25;
|
|
75
|
+
text-overflow: clip;
|
|
76
|
+
white-space: normal;
|
|
77
|
+
overflow-wrap: break-word;
|
|
78
|
+
/* Not the shrink-to-fit width an absolutely positioned box gets: at a point near the right edge
|
|
79
|
+
* that is the sliver right of `left`, and the date would wrap letter by letter. */
|
|
80
|
+
width: max-content;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[data-basalt-hosted] .readout[data-stacked] {
|
|
84
|
+
top: 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.readout[data-stacked] .label {
|
|
88
|
+
display: block;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.readout[data-stacked] .sep {
|
|
92
|
+
display: none;
|
|
93
|
+
}
|
|
94
|
+
|
|
45
95
|
.layer {
|
|
46
96
|
position: absolute;
|
|
47
97
|
pointer-events: none;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/charts/state.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,CAAA;AAErE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,kBAAkB,CAMnF;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/charts/state.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,CAAA;AAErE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,kBAAkB,CAMnF;AAsDD;8EAC8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAA;IAC7B,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;2DACuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,YAAY,GAAG,IAAI,CAuDtB"}
|
package/dist/charts/state.js
CHANGED
|
@@ -37,6 +37,8 @@ const dotStyle = {
|
|
|
37
37
|
const errorStyle = {
|
|
38
38
|
...boxStyle,
|
|
39
39
|
alignItems: "flex-start",
|
|
40
|
+
justifyContent: "flex-start",
|
|
41
|
+
paddingBottom: VX.space.controlGap,
|
|
40
42
|
textAlign: "start",
|
|
41
43
|
fontSize: VX.text.sm,
|
|
42
44
|
gap: VX.space.controlGap
|
|
@@ -49,7 +51,7 @@ const errorHeadStyle = {
|
|
|
49
51
|
fontWeight: 500
|
|
50
52
|
};
|
|
51
53
|
const errorMessageStyle = { color: VX.muted };
|
|
52
|
-
const emptyLabel = (state) => typeof state?.empty === "string" ? state.empty : "
|
|
54
|
+
const emptyLabel = (state) => typeof state?.empty === "string" ? state.empty : "Nothing recorded in this range.";
|
|
53
55
|
function ChartPlaceholder(props) {
|
|
54
56
|
const kind = resolveChartState(props.state);
|
|
55
57
|
if (kind === null) return null;
|
|
@@ -59,7 +61,7 @@ function ChartPlaceholder(props) {
|
|
|
59
61
|
return fit(
|
|
60
62
|
/* @__PURE__ */ jsx("output", { "aria-label": "Loading chart", "aria-busy": "true", className: stateClass, style })
|
|
61
63
|
);
|
|
62
|
-
const label = kind === "error" ? toErrorMessage(props.state?.error, "The
|
|
64
|
+
const label = kind === "error" ? toErrorMessage(props.state?.error, "The request failed.") : emptyLabel(props.state);
|
|
63
65
|
const body = props.compact ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2014" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
64
66
|
kind === "error" && /* @__PURE__ */ jsxs("span", { style: errorHeadStyle, children: [
|
|
65
67
|
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", "data-basalt-status-dot": "", style: dotStyle }),
|
package/dist/charts/types.d.ts
CHANGED
|
@@ -121,6 +121,17 @@ export type ZoneSpec = {
|
|
|
121
121
|
to: number;
|
|
122
122
|
fill: string;
|
|
123
123
|
axisSide?: 'left' | 'right' | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Names the band in the legend (its fill as the swatch, a bar by default), so a zone chart keeps
|
|
126
|
+
* a key at 390 and needs no always-`null` series. `mark` is the swatch shape. `color` is the
|
|
127
|
+
* swatch when the fill is a whisper-alpha wash a 10px swatch would lose (default: the fill, a
|
|
128
|
+
* status tint mapped to its solid).
|
|
129
|
+
*/
|
|
130
|
+
legend?: {
|
|
131
|
+
label: string;
|
|
132
|
+
mark?: 'line' | 'bar' | undefined;
|
|
133
|
+
color?: string | undefined;
|
|
134
|
+
} | undefined;
|
|
124
135
|
/** A rule on the band's visual `top` (the larger bound) and/or `bottom` (the smaller), whichever
|
|
125
136
|
* of `from`/`to` that is. */
|
|
126
137
|
edge?: ZoneEdge<'top' | 'bottom'> | undefined;
|
|
@@ -185,8 +196,9 @@ export type ChartTooltipRow = {
|
|
|
185
196
|
swatch?: 'solid' | 'dashed' | undefined;
|
|
186
197
|
};
|
|
187
198
|
export type ChartTooltipConfig<T, X extends ChartX = ChartX> = {
|
|
188
|
-
/** The tooltip title. Default:
|
|
189
|
-
* `
|
|
199
|
+
/** The tooltip title. Default: a Date x reads weekday, day, month and year in the page locale
|
|
200
|
+
* (`Tue 1 Sep 2026`; a non-day instant adds its time) whatever `formatX` shortens the ticks to;
|
|
201
|
+
* any other x goes through `formatX`. */
|
|
190
202
|
formatHeader?: ((x: X, d: T) => string) | undefined;
|
|
191
203
|
/** Rows after the per-series rows (a total, a zone badge, a context line). `visible`/`hidden` are
|
|
192
204
|
* the legend's split, so a row never names a series the plot no longer draws. */
|
|
@@ -297,7 +309,7 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
297
309
|
xDomain?: readonly [X, X] | undefined;
|
|
298
310
|
/**
|
|
299
311
|
* Tick label for an x value. Default: compact numbers, strings verbatim, and dates by tick step
|
|
300
|
-
* (`HH:MM` with the day on midnight, `
|
|
312
|
+
* (`HH:MM` with the day on midnight, the day (`4 Oct`, in the page locale), a month with the year on January; a label recurs
|
|
301
313
|
* only behind a day or year label).
|
|
302
314
|
*/
|
|
303
315
|
formatX?: ((x: X) => string) | undefined;
|