basalt-ui 2.21.0 → 2.22.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 +33 -0
- package/MIGRATING.md +277 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/rules/basalt-tokens.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +27 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +5 -0
- package/dist/charts/CartesianChart.d.ts +8 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +12 -3
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +29 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +39 -14
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +20 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +9 -0
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +17 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +145 -74
- package/dist/charts/labels.d.ts +15 -4
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +34 -10
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +26 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +63 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +10 -11
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +2 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +2 -1
- package/dist/charts/types.d.ts +14 -5
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +68 -4
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +194 -32
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +14 -1
- package/dist/cli/shot/playwright.d.ts +5 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/types.d.ts +2 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +7 -8
- package/dist/dashboard/bar-list.module.css +53 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +77 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +88 -15
- package/dist/dashboard/meter-parts.d.ts +8 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +238 -71
- package/dist/dashboard/meter.d.ts +43 -60
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +20 -3
- package/dist/dashboard/meter.module.css +61 -0
- package/dist/dashboard/meter.module.css.d.ts +5 -0
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -5
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +7 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +74 -46
- package/dist/dashboard/stat-strip.module.css +67 -20
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts +7 -1
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +3 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +34 -2
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +23 -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 +8 -20
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/palette.d.ts +4 -0
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +4 -0
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +38 -20
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +33 -3
- package/src/charts/Bars.tsx +6 -0
- package/src/charts/CartesianChart.tsx +16 -3
- package/src/charts/ChartCard.tsx +34 -6
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +50 -13
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +31 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +210 -85
- package/src/charts/labels.ts +48 -14
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +104 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +10 -11
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +3 -1
- package/src/charts/types.ts +14 -5
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/init.ts +100 -3
- package/src/cli/shot/capture.ts +251 -32
- package/src/cli/shot/detect.ts +18 -1
- package/src/cli/shot/playwright.ts +2 -2
- package/src/cli/shot/types.ts +3 -0
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +53 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +78 -69
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +186 -20
- package/src/dashboard/meter-parts.tsx +285 -64
- package/src/dashboard/meter.module.css +61 -0
- package/src/dashboard/meter.module.css.d.ts +5 -0
- package/src/dashboard/meter.tsx +60 -10
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +17 -0
- package/src/dashboard/stat-card.tsx +12 -6
- package/src/dashboard/stat-strip.module.css +67 -20
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +118 -72
- package/src/dashboard/visual-slot.ts +12 -3
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +34 -2
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +186 -60
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +23 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +12 -25
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/palette.ts +4 -0
- package/src/tokens/status-text.ts +2 -0
|
@@ -6,10 +6,14 @@ import { cx } from "../common/props.js";
|
|
|
6
6
|
import {
|
|
7
7
|
ariaValues,
|
|
8
8
|
modelBar,
|
|
9
|
+
partsFitUnder,
|
|
10
|
+
placeMarkCaptions,
|
|
11
|
+
placeRowLabels,
|
|
9
12
|
ringFraction,
|
|
13
|
+
ringMarks,
|
|
10
14
|
startCaptionText,
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
zoneBand,
|
|
16
|
+
zoneFill
|
|
13
17
|
} from "./meter-model.js";
|
|
14
18
|
import classes from "./meter.module.css";
|
|
15
19
|
import { VisualSlotContext } from "./visual-slot.js";
|
|
@@ -26,7 +30,13 @@ const RING_STROKE = 4;
|
|
|
26
30
|
const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2;
|
|
27
31
|
const RING_LENGTH = 2 * Math.PI * RING_RADIUS;
|
|
28
32
|
const RING_CENTER = RING_VIEWBOX / 2;
|
|
29
|
-
|
|
33
|
+
const RING_TICK_INNER = RING_RADIUS - RING_STROKE / 2 - 0.75;
|
|
34
|
+
const RING_TICK_OUTER = RING_VIEWBOX / 2 - 0.5;
|
|
35
|
+
function RingSvg({
|
|
36
|
+
fraction,
|
|
37
|
+
color,
|
|
38
|
+
marks = []
|
|
39
|
+
}) {
|
|
30
40
|
return /* @__PURE__ */ jsxs("svg", { className: classes.ring, viewBox: `0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`, "aria-hidden": true, children: [
|
|
31
41
|
/* @__PURE__ */ jsx(
|
|
32
42
|
"circle",
|
|
@@ -49,7 +59,22 @@ function RingSvg({ fraction, color }) {
|
|
|
49
59
|
strokeDasharray: `${fraction * RING_LENGTH} ${RING_LENGTH}`,
|
|
50
60
|
...color !== void 0 && { style: { stroke: color } }
|
|
51
61
|
}
|
|
52
|
-
)
|
|
62
|
+
),
|
|
63
|
+
marks.map((m, i) => (
|
|
64
|
+
// The svg is rotated so 0° is the top: a horizontal line at the rim, turned `angle` clockwise.
|
|
65
|
+
/* @__PURE__ */ jsx("g", { "data-meter-ring-tick": "", children: [classes.ringTickHalo, classes.ringTick].map((cls, n) => /* @__PURE__ */ jsx(
|
|
66
|
+
"line",
|
|
67
|
+
{
|
|
68
|
+
className: cls,
|
|
69
|
+
x1: RING_CENTER + RING_TICK_INNER,
|
|
70
|
+
x2: RING_CENTER + RING_TICK_OUTER,
|
|
71
|
+
y1: RING_CENTER,
|
|
72
|
+
y2: RING_CENTER,
|
|
73
|
+
transform: `rotate(${m.angle} ${RING_CENTER} ${RING_CENTER})`
|
|
74
|
+
},
|
|
75
|
+
n
|
|
76
|
+
)) }, i)
|
|
77
|
+
))
|
|
53
78
|
] });
|
|
54
79
|
}
|
|
55
80
|
const UNITS = "h|d|w|mo|y|s|ms|min|m|km|mi|g|kg|%|\u20AC|pts|bpm|AU|kcal|KB|MB|GB|TB";
|
|
@@ -79,36 +104,39 @@ function MeterEmpty(props) {
|
|
|
79
104
|
}
|
|
80
105
|
function MeterRing(props) {
|
|
81
106
|
const { label, reading, min, max, color, format, shell } = props;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
107
|
+
const describedId = useId();
|
|
108
|
+
const marks = ringMarks(props.target, props.ticks, min, max, format);
|
|
109
|
+
return /* @__PURE__ */ jsxs("div", { ...rootProps(shell), children: [
|
|
110
|
+
/* @__PURE__ */ jsxs(
|
|
111
|
+
"span",
|
|
112
|
+
{
|
|
113
|
+
className: classes.ringBox,
|
|
114
|
+
"aria-label": label,
|
|
115
|
+
...ariaValues(reading, min, max, format),
|
|
116
|
+
...marks.length > 0 && { "aria-describedby": describedId },
|
|
117
|
+
children: [
|
|
118
|
+
/* @__PURE__ */ jsx(RingSvg, { fraction: ringFraction(reading, min, max), color, marks }),
|
|
119
|
+
/* @__PURE__ */ jsx("span", { className: classes.ringValue, children: format(reading) })
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
marks.length > 0 && /* @__PURE__ */ jsx(VisuallyHidden, { id: describedId, className: classes.summary, children: marks.map((m) => m.text).join("; ") })
|
|
124
|
+
] });
|
|
94
125
|
}
|
|
95
126
|
function fillStyle(p) {
|
|
96
127
|
return { width: `${toPct(p.size)}%`, ...p.color !== void 0 && { background: p.color } };
|
|
97
128
|
}
|
|
98
|
-
const ZONE_STRENGTH_MIN = 15;
|
|
99
|
-
const ZONE_STRENGTH_STEP = 45;
|
|
100
|
-
const ZONE_STRENGTH_SOLO = 40;
|
|
101
129
|
const ZONE_GAP = "1px";
|
|
102
130
|
function zoneStyle(zone, index, count, min, span) {
|
|
103
131
|
const band = zoneBand(zone, min, span);
|
|
104
132
|
const gap = index > 0;
|
|
105
|
-
const strength = count > 1 ? ZONE_STRENGTH_MIN + index / (count - 1) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO;
|
|
106
133
|
return {
|
|
107
134
|
insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
|
|
108
135
|
width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
|
|
109
|
-
background: zone
|
|
136
|
+
background: zoneFill(zone, index, count)
|
|
110
137
|
};
|
|
111
138
|
}
|
|
139
|
+
const columnGapOf = (el) => Number.parseFloat(getComputedStyle(el).columnGap) || 0;
|
|
112
140
|
const sameLayout = (a, b) => a.shown.length === b.shown.length && a.shown.every(
|
|
113
141
|
(v, i) => v === b.shown[i] && a.short[i] === b.short[i] && a.shift[i] === b.shift[i]
|
|
114
142
|
);
|
|
@@ -136,7 +164,8 @@ function useRowLabelLayout(rowRef, slots, shortOf, key) {
|
|
|
136
164
|
return {
|
|
137
165
|
box: { left: r.left - origin.left, right: r.right - origin.left },
|
|
138
166
|
...a !== void 0 && b !== void 0 && { span: { left: Math.min(a, b), right: Math.max(a, b) } },
|
|
139
|
-
...slot?.holding && { holding: true }
|
|
167
|
+
...slot?.holding && { holding: true },
|
|
168
|
+
...slot?.end && { end: true }
|
|
140
169
|
};
|
|
141
170
|
});
|
|
142
171
|
shortOfRef.current.forEach((labelIndex, n) => {
|
|
@@ -144,7 +173,7 @@ function useRowLabelLayout(rowRef, slots, shortOf, key) {
|
|
|
144
173
|
const label = labels[labelIndex];
|
|
145
174
|
if (r && label) label.short = { left: r.left - origin.left, right: r.right - origin.left };
|
|
146
175
|
});
|
|
147
|
-
const placed = placeRowLabels(labels, origin.width);
|
|
176
|
+
const placed = placeRowLabels(labels, origin.width, columnGapOf(row));
|
|
148
177
|
const next = {
|
|
149
178
|
shown: placed.shown,
|
|
150
179
|
short: placed.short,
|
|
@@ -203,7 +232,7 @@ const TICK_LABEL_FLIP_PCT = 50;
|
|
|
203
232
|
function LabelRow({ zones, ticks }) {
|
|
204
233
|
const rowRef = useRef(null);
|
|
205
234
|
const slots = [
|
|
206
|
-
...ticks.map(() =>
|
|
235
|
+
...ticks.map((t) => t.pct <= 0 || t.pct >= 100 ? { end: true } : {}),
|
|
207
236
|
...zones.map((z) => ({
|
|
208
237
|
spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
|
|
209
238
|
holding: z.holding
|
|
@@ -272,52 +301,206 @@ function LabelRow({ zones, ticks }) {
|
|
|
272
301
|
}
|
|
273
302
|
);
|
|
274
303
|
}
|
|
304
|
+
function measureItems(row) {
|
|
305
|
+
const kids = [...row.children];
|
|
306
|
+
const widths = kids.map((kid) => {
|
|
307
|
+
const { whiteSpace, flex } = kid.style;
|
|
308
|
+
kid.style.whiteSpace = "nowrap";
|
|
309
|
+
kid.style.flex = "none";
|
|
310
|
+
const width = kid.offsetWidth;
|
|
311
|
+
kid.style.whiteSpace = whiteSpace;
|
|
312
|
+
kid.style.flex = flex;
|
|
313
|
+
return width;
|
|
314
|
+
});
|
|
315
|
+
return { widths, rowWidth: row.clientWidth, gap: columnGapOf(row) };
|
|
316
|
+
}
|
|
317
|
+
function useMeasured(rowRef, measure, key) {
|
|
318
|
+
const measureRef = useRef(measure);
|
|
319
|
+
useIsomorphicLayoutEffect(() => {
|
|
320
|
+
measureRef.current = measure;
|
|
321
|
+
});
|
|
322
|
+
useIsomorphicLayoutEffect(() => {
|
|
323
|
+
const row = rowRef.current;
|
|
324
|
+
if (!row) return;
|
|
325
|
+
const run = () => measureRef.current(row);
|
|
326
|
+
run();
|
|
327
|
+
const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(run);
|
|
328
|
+
observer?.observe(row);
|
|
329
|
+
for (const kid of row.children) observer?.observe(kid);
|
|
330
|
+
const fonts = typeof document === "undefined" ? void 0 : document.fonts;
|
|
331
|
+
fonts?.addEventListener?.("loadingdone", run);
|
|
332
|
+
return () => {
|
|
333
|
+
observer?.disconnect();
|
|
334
|
+
fonts?.removeEventListener?.("loadingdone", run);
|
|
335
|
+
};
|
|
336
|
+
}, [rowRef, key]);
|
|
337
|
+
}
|
|
338
|
+
const sameStarts = (a, b) => a === b || a !== null && b !== null && a.length === b.length && a.every((v, i) => v === b[i]);
|
|
339
|
+
function CaptionRow({ items }) {
|
|
340
|
+
const rowRef = useRef(null);
|
|
341
|
+
const [starts, setStarts] = useState(null);
|
|
342
|
+
useMeasured(
|
|
343
|
+
rowRef,
|
|
344
|
+
(row) => {
|
|
345
|
+
const { widths, rowWidth, gap } = measureItems(row);
|
|
346
|
+
const marks = items.map((item, i) => ({
|
|
347
|
+
width: widths[i] ?? 0,
|
|
348
|
+
...item.pct !== void 0 && { pct: item.pct },
|
|
349
|
+
...item.edge !== void 0 && { edge: item.edge }
|
|
350
|
+
}));
|
|
351
|
+
const next = placeMarkCaptions(marks, rowWidth, gap);
|
|
352
|
+
setStarts((prev) => sameStarts(prev, next) ? prev : next);
|
|
353
|
+
},
|
|
354
|
+
items.map((i) => `${i.key}@${i.pct ?? i.edge ?? ""}:${typeof i.node === "string" ? i.node : ""}`).join("\0")
|
|
355
|
+
);
|
|
356
|
+
return /* @__PURE__ */ jsx(
|
|
357
|
+
"div",
|
|
358
|
+
{
|
|
359
|
+
ref: rowRef,
|
|
360
|
+
className: cx(classes.captions, starts !== null && classes.captionsAnchored),
|
|
361
|
+
"data-meter-captions": true,
|
|
362
|
+
"data-anchored": starts === null ? void 0 : "",
|
|
363
|
+
children: items.map((item, i) => /* @__PURE__ */ jsx(
|
|
364
|
+
"span",
|
|
365
|
+
{
|
|
366
|
+
className: item.end ? classes.captionEnd : classes.caption,
|
|
367
|
+
...starts?.[i] !== void 0 && { style: { insetInlineStart: `${starts[i]}px` } },
|
|
368
|
+
children: item.node
|
|
369
|
+
},
|
|
370
|
+
item.key
|
|
371
|
+
))
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
function PartCaptions({ captions }) {
|
|
376
|
+
const rowRef = useRef(null);
|
|
377
|
+
const [under, setUnder] = useState(false);
|
|
378
|
+
useMeasured(
|
|
379
|
+
rowRef,
|
|
380
|
+
(row) => {
|
|
381
|
+
const { widths, rowWidth, gap } = measureItems(row);
|
|
382
|
+
const fits = partsFitUnder(
|
|
383
|
+
captions.map((c, i) => ({ startPct: c.startPct, width: widths[i] ?? 0 })),
|
|
384
|
+
rowWidth,
|
|
385
|
+
gap
|
|
386
|
+
);
|
|
387
|
+
setUnder(fits);
|
|
388
|
+
},
|
|
389
|
+
captions.map((c) => `${c.label} ${c.text}@${c.startPct}`).join("\0")
|
|
390
|
+
);
|
|
391
|
+
return /* @__PURE__ */ jsx(
|
|
392
|
+
"ul",
|
|
393
|
+
{
|
|
394
|
+
ref: rowRef,
|
|
395
|
+
className: cx(classes.partCaptions, under && classes.partCaptionsUnder),
|
|
396
|
+
role: "list",
|
|
397
|
+
"data-meter-parts": true,
|
|
398
|
+
"data-anchored": under ? "" : void 0,
|
|
399
|
+
children: captions.map((c) => /* @__PURE__ */ jsxs(
|
|
400
|
+
"li",
|
|
401
|
+
{
|
|
402
|
+
className: classes.partCaption,
|
|
403
|
+
...under && { style: { insetInlineStart: `${c.startPct}%` } },
|
|
404
|
+
children: [
|
|
405
|
+
/* @__PURE__ */ jsx(
|
|
406
|
+
"span",
|
|
407
|
+
{
|
|
408
|
+
className: classes.swatch,
|
|
409
|
+
style: { background: c.color ?? "var(--vx-line)" },
|
|
410
|
+
"aria-hidden": true
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
glueUnits(`${c.label} ${c.text}`)
|
|
414
|
+
]
|
|
415
|
+
},
|
|
416
|
+
c.key
|
|
417
|
+
))
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
|
+
}
|
|
275
421
|
function MeterBar(props) {
|
|
276
|
-
const { label,
|
|
422
|
+
const { label, min, max, format, zones, shell } = props;
|
|
277
423
|
const describedId = useId();
|
|
278
424
|
const model = modelBar(props);
|
|
279
425
|
const compact = shell.row;
|
|
280
|
-
const hosted = useContext(VisualSlotContext)
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
const
|
|
426
|
+
const hosted = useContext(VisualSlotContext) !== null;
|
|
427
|
+
const marked = model.markerPct !== void 0;
|
|
428
|
+
const readingOn = props.markerReading ?? (model.zoneLabels.length > 0 && !hosted);
|
|
429
|
+
const start = compact || marked && !readingOn && props.startCaption === void 0 ? null : startCaptionText(model, props.startCaption);
|
|
430
|
+
const anchored = marked && start !== null;
|
|
431
|
+
const trackHidden = props.track === false && model.parts.length === 1 && props.segments === void 0 && props.target === void 0 && model.ticks.length === 0;
|
|
432
|
+
const hasParts = model.partCaptions.length > 0;
|
|
286
433
|
const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== void 0);
|
|
287
434
|
const zoneLabels = compact ? [] : model.zoneLabels;
|
|
288
435
|
const describedBy = model.describedByText === null ? {} : { "aria-describedby": describedId };
|
|
436
|
+
const endOverride = props.endCaption !== void 0;
|
|
437
|
+
const targetHere = !endOverride && model.targetPct !== void 0 && model.endText !== null;
|
|
438
|
+
const end = compact ? null : endOverride ? props.endCaption : model.endText;
|
|
439
|
+
const items = compact ? [] : [
|
|
440
|
+
...start !== null && !anchored ? [{ key: "start", node: glue(start) }] : [],
|
|
441
|
+
...model.forecastText !== null ? [
|
|
442
|
+
{
|
|
443
|
+
key: "forecast",
|
|
444
|
+
node: glue(model.forecastText),
|
|
445
|
+
...model.boundaryPct !== void 0 && { pct: model.boundaryPct }
|
|
446
|
+
}
|
|
447
|
+
] : [],
|
|
448
|
+
...end !== null ? [
|
|
449
|
+
{
|
|
450
|
+
key: "end",
|
|
451
|
+
node: glue(end),
|
|
452
|
+
end: true,
|
|
453
|
+
...targetHere && model.targetPct !== void 0 ? { pct: model.targetPct } : { edge: "end" }
|
|
454
|
+
}
|
|
455
|
+
] : []
|
|
456
|
+
];
|
|
289
457
|
const root = rootProps(shell);
|
|
290
458
|
return /* @__PURE__ */ jsxs("div", { ...root, className: root.className, children: [
|
|
291
459
|
tickLabels.length > 0 && zoneLabels.length === 0 && /* @__PURE__ */ jsx(LabelRow, { zones: zoneLabels, ticks: tickLabels }),
|
|
292
460
|
/* @__PURE__ */ jsxs(
|
|
293
461
|
"div",
|
|
294
462
|
{
|
|
295
|
-
className: classes.trackBox,
|
|
463
|
+
className: cx(classes.trackBox, trackHidden && classes.trackHidden),
|
|
464
|
+
"data-meter-track-hidden": trackHidden ? "" : void 0,
|
|
296
465
|
"aria-label": label,
|
|
297
|
-
...ariaValues(reading, min, max, format),
|
|
466
|
+
...ariaValues(props.reading, min, max, format),
|
|
298
467
|
...describedBy,
|
|
299
468
|
children: [
|
|
300
|
-
/* @__PURE__ */ jsxs(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
)),
|
|
310
|
-
model.parts.map((p, i) => /* @__PURE__ */ jsx(
|
|
311
|
-
"div",
|
|
312
|
-
{
|
|
313
|
-
className: cx(classes.fill, p.forecast && classes.forecastFill),
|
|
314
|
-
"data-meter-fill": p.forecast ? "forecast" : "committed",
|
|
315
|
-
"data-tone": props.tone === "muted" && p.color === void 0 && !p.forecast ? "muted" : void 0,
|
|
316
|
-
style: fillStyle(p)
|
|
469
|
+
/* @__PURE__ */ jsxs(
|
|
470
|
+
"div",
|
|
471
|
+
{
|
|
472
|
+
className: classes.track,
|
|
473
|
+
"data-meter-track": true,
|
|
474
|
+
...model.stopsCss !== void 0 && {
|
|
475
|
+
"data-meter-stops": "",
|
|
476
|
+
// theme-allow hidden-inline-style — the gradient is the consumer's colour data
|
|
477
|
+
style: { "--basalt-stops": model.stopsCss }
|
|
317
478
|
},
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
479
|
+
children: [
|
|
480
|
+
zones?.map(
|
|
481
|
+
(z, i) => model.markerPct !== void 0 && /* @__PURE__ */ jsx(
|
|
482
|
+
"div",
|
|
483
|
+
{
|
|
484
|
+
className: classes.zone,
|
|
485
|
+
"data-meter-zone": z.label,
|
|
486
|
+
style: zoneStyle(z, i, zones.length, min, model.span)
|
|
487
|
+
},
|
|
488
|
+
i
|
|
489
|
+
)
|
|
490
|
+
),
|
|
491
|
+
model.parts.map((p, i) => /* @__PURE__ */ jsx(
|
|
492
|
+
"div",
|
|
493
|
+
{
|
|
494
|
+
className: cx(classes.fill, p.forecast && classes.forecastFill),
|
|
495
|
+
"data-meter-fill": p.forecast ? "forecast" : "committed",
|
|
496
|
+
"data-tone": props.tone === "muted" && p.color === void 0 && !p.forecast ? "muted" : void 0,
|
|
497
|
+
style: fillStyle(p)
|
|
498
|
+
},
|
|
499
|
+
i
|
|
500
|
+
))
|
|
501
|
+
]
|
|
502
|
+
}
|
|
503
|
+
),
|
|
321
504
|
/* @__PURE__ */ jsx(Tick, { kind: "marker", className: classes.marker, pct: model.markerPct }),
|
|
322
505
|
/* @__PURE__ */ jsx(Tick, { kind: "boundary", className: classes.boundaryTick, pct: model.boundaryPct }),
|
|
323
506
|
model.ticks.map((t) => /* @__PURE__ */ jsx(Tick, { kind: "tick", className: classes.tick, pct: t.pct }, t.key)),
|
|
@@ -328,24 +511,8 @@ function MeterBar(props) {
|
|
|
328
511
|
zoneLabels.length > 0 && /* @__PURE__ */ jsx(LabelRow, { zones: zoneLabels, ticks: tickLabels }),
|
|
329
512
|
anchored && /* @__PURE__ */ jsx(ZoneReading, { pct: model.markerPct ?? 0, children: start }),
|
|
330
513
|
model.describedByText !== null && /* @__PURE__ */ jsx(VisuallyHidden, { id: describedId, className: classes.summary, children: model.describedByText }),
|
|
331
|
-
hasParts &&
|
|
332
|
-
|
|
333
|
-
/* @__PURE__ */ jsx("ul", { className: classes.partCaptions, role: "list", "data-meter-parts": true, children: model.partCaptions.map((c) => /* @__PURE__ */ jsxs("li", { className: classes.partCaption, children: [
|
|
334
|
-
/* @__PURE__ */ jsx(
|
|
335
|
-
"span",
|
|
336
|
-
{
|
|
337
|
-
className: classes.swatch,
|
|
338
|
-
style: { background: c.color ?? "var(--vx-line)" },
|
|
339
|
-
"aria-hidden": true
|
|
340
|
-
}
|
|
341
|
-
),
|
|
342
|
-
glueUnits(`${c.label} ${c.text}`)
|
|
343
|
-
] }, c.key)) }),
|
|
344
|
-
hasCaptions && /* @__PURE__ */ jsxs("div", { className: classes.captions, "data-meter-captions": true, children: [
|
|
345
|
-
start !== null && !anchored && /* @__PURE__ */ jsx("span", { className: classes.caption, children: glue(start) }),
|
|
346
|
-
!compact && model.forecastText !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: glue(model.forecastText) }),
|
|
347
|
-
end !== null && /* @__PURE__ */ jsx("span", { className: classes.captionEnd, children: glue(end) })
|
|
348
|
-
] })
|
|
514
|
+
hasParts && /* @__PURE__ */ jsx(PartCaptions, { captions: model.partCaptions }),
|
|
515
|
+
items.length > 0 && /* @__PURE__ */ jsx(CaptionRow, { items })
|
|
349
516
|
] });
|
|
350
517
|
}
|
|
351
518
|
const TICK_WIDTH = "2px";
|
|
@@ -1,56 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meter — one bounded quantity on a track: progress to a target, a committed/forecast split, a
|
|
3
|
-
* part-of-a-whole strip (`segments`), or a single headline ratio as a `ring`. Choose it for "how far
|
|
4
|
-
* along is this against a limit"; choose `BarList` for a ranking and a chart for a trend. An HTML/CSS
|
|
5
|
-
* primitive, not a chart kind (no scale, axis or tooltip).
|
|
6
|
-
*
|
|
7
|
-
* Colour law: a plain `value` bar's fill is neutral (`--vx-muted` at a strength that holds 3:1 on
|
|
8
|
-
* the track; `tone="ink"` for full ink); `segments` and `zones` keep their own fills. `color` is
|
|
9
|
-
* for a VERDICT only (over budget, below target) and is a status colour the consumer passes;
|
|
10
|
-
* categorical `segments` take the consumer's series colours. Committed vs forecast is the same neutral at two strengths — never colour alone: a
|
|
11
|
-
* tick marks the boundary and a caption names the forecast. A value past `max` clamps the fill at the
|
|
12
|
-
* track end; the caption still states the real value.
|
|
13
|
-
*
|
|
14
|
-
* `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
|
|
15
|
-
* passes a status colour) and the reading becomes a MARKER on the track, not a fill. Each zone is
|
|
16
|
-
* named under the band at its start, the one holding the value (`from` inclusive) in ink and a
|
|
17
|
-
* heavier weight; names that would collide wrap as a list instead. The fit is measured in the
|
|
18
|
-
* browser, so server markup shows the band and the list may appear after mount. Use it for a
|
|
19
|
-
* reading judged against ranges.
|
|
20
|
-
*
|
|
21
|
-
* Every state (bar, ring, empty, loading) carries `data-basalt-meter` on its root. That attribute is
|
|
22
|
-
* the contract with `StatCard`: a Meter passed as its `sparkline` visual makes the slot size to content
|
|
23
|
-
* and keep the card's inline inset (both placements) instead of the sparkline's fixed height and bleed.
|
|
24
|
-
*
|
|
25
|
-
* Categorical `segments` (no `forecast` part) are captioned one per part — swatch, name, value — under
|
|
26
|
-
* the track and the default start caption is dropped (an explicit `startCaption` still shows);
|
|
27
|
-
* committed/forecast keeps the reading plus the forecast caption.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* import { Meter } from 'basalt-ui'
|
|
31
|
-
*
|
|
32
|
-
* // Spend against a budget: past the target the end caption states the overage.
|
|
33
|
-
* <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
|
|
34
|
-
* // Training load as a zone band with a marker: the zones are named under the band, "Optimal" in ink.
|
|
35
|
-
* <Meter
|
|
36
|
-
* label="Training load"
|
|
37
|
-
* max={1000}
|
|
38
|
-
* value={612}
|
|
39
|
-
* zones={[
|
|
40
|
-
* { from: 0, to: 300, label: 'Low' },
|
|
41
|
-
* { from: 300, to: 750, label: 'Optimal' },
|
|
42
|
-
* { from: 750, to: 1000, label: 'High' },
|
|
43
|
-
* ]}
|
|
44
|
-
* />
|
|
45
|
-
* // A readiness score on its 0–100 scale (its contributors: <BarList max={100} … secondary="Good" />).
|
|
46
|
-
* <Meter label="Recovery" value={72} max={100} />
|
|
47
|
-
* <Meter
|
|
48
|
-
* label="Course progress"
|
|
49
|
-
* max={120}
|
|
50
|
-
* segments={[{ value: 70, label: 'Done' }, { value: 25, label: 'Planned', forecast: true }]}
|
|
51
|
-
* />
|
|
52
|
-
* <Meter shape="ring" label="Cache hit rate" value={87} max={100} format={(v) => `${v}%`} />
|
|
53
|
-
*/
|
|
54
1
|
import type { ReactNode } from 'react';
|
|
55
2
|
import type { BasaltProps } from '../common/props.js';
|
|
56
3
|
import type { MeterSegment, MeterTick, MeterZone } from './meter-model.js';
|
|
@@ -89,27 +36,54 @@ type BarCommon = Common & {
|
|
|
89
36
|
tone?: 'muted' | 'ink';
|
|
90
37
|
/**
|
|
91
38
|
* `'row'`: in-line use — a track one text line tall and no caption rows (reading, target, forecast,
|
|
92
|
-
*
|
|
93
|
-
*
|
|
39
|
+
* zone and tick captions). Categorical `segments` keep their per-part captions (swatch, name, value)
|
|
40
|
+
* so the parts stay named. The label stays as `aria-label`; the described-by text keeps the rest.
|
|
41
|
+
* Put the value beside it in your own layout.
|
|
94
42
|
*/
|
|
95
43
|
size?: 'row';
|
|
96
|
-
/** Start caption (default: the formatted reading). `null` drops it. */
|
|
44
|
+
/** Start caption (default: the formatted reading). `null` drops it; zone labels stay. */
|
|
97
45
|
startCaption?: ReactNode;
|
|
98
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* End caption (default: `Target <target>`, drawn at the target's tick rather than the track end
|
|
48
|
+
* when it fits). `null` drops it; zone labels stay.
|
|
49
|
+
*/
|
|
99
50
|
endCaption?: ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* The reading printed at the marker of a zoned bar. Default `true`, and `false` inside a basalt host
|
|
53
|
+
* (`StatCard`, a strip cell's `visual`) that already states the value. Pass `false` when YOUR
|
|
54
|
+
* headline states it: the marker stays and keeps its `aria-valuenow` / `aria-valuetext`. Pass `true`
|
|
55
|
+
* to print it inside a host. A `stops` track prints it only when `true`.
|
|
56
|
+
*/
|
|
57
|
+
reading?: boolean;
|
|
100
58
|
};
|
|
101
59
|
/**
|
|
102
60
|
* One of four forms; mixing them is a compile error.
|
|
103
61
|
* - Bar `value` (+ `target`, `color`): one reading on a neutral track.
|
|
104
62
|
* - Bar `segments`: ordered parts that sum to the reading (committed/forecast, part of a whole).
|
|
105
63
|
* - Bar `value` + `zones`: the reading is a marker against contiguous bands.
|
|
106
|
-
* -
|
|
64
|
+
* - Bar `value` + `stops`: the reading is a marker on one gradient track.
|
|
65
|
+
* - Ring (`shape: 'ring'`) `value` (+ `color`, `target`, `ticks`): one headline ratio; no captions,
|
|
66
|
+
* segments or zones.
|
|
107
67
|
*/
|
|
108
68
|
export type MeterProps = (BarCommon & {
|
|
109
69
|
/** The reading. `null`/`undefined` (or non-finite) renders the empty state. */
|
|
110
70
|
value?: number | null | undefined;
|
|
111
71
|
/** A status colour, for a verdict only. Omit for the neutral fill. */
|
|
112
72
|
color?: string;
|
|
73
|
+
/**
|
|
74
|
+
* `false` draws no track for a value with nothing to compare against (no `target`, no `ticks`):
|
|
75
|
+
* the track stays in the accessibility tree and the captions remain. A `target` or `ticks` keep it.
|
|
76
|
+
*/
|
|
77
|
+
track?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Draws the track as ONE gradient through these colours (the consumer's: tokens or its own
|
|
80
|
+
* values, `at` in the reading's units) and the reading as a marker on it. Not a zone: no names,
|
|
81
|
+
* and no labels unless `ticks` are given. Use it for a scale whose hue IS the quantity.
|
|
82
|
+
*/
|
|
83
|
+
stops?: readonly {
|
|
84
|
+
at: number;
|
|
85
|
+
color: string;
|
|
86
|
+
}[];
|
|
113
87
|
segments?: never;
|
|
114
88
|
zones?: never;
|
|
115
89
|
}) | (BarCommon & {
|
|
@@ -120,6 +94,8 @@ export type MeterProps = (BarCommon & {
|
|
|
120
94
|
value?: never;
|
|
121
95
|
color?: never;
|
|
122
96
|
zones?: never;
|
|
97
|
+
stops?: never;
|
|
98
|
+
track?: never;
|
|
123
99
|
}) | (BarCommon & {
|
|
124
100
|
value?: number | null | undefined;
|
|
125
101
|
/**
|
|
@@ -129,19 +105,26 @@ export type MeterProps = (BarCommon & {
|
|
|
129
105
|
zones: readonly MeterZone[];
|
|
130
106
|
segments?: never;
|
|
131
107
|
color?: never;
|
|
108
|
+
stops?: never;
|
|
109
|
+
track?: never;
|
|
132
110
|
}) | (Common & {
|
|
133
111
|
shape: 'ring';
|
|
134
112
|
value?: number | null | undefined;
|
|
135
113
|
/** A status colour, for a verdict only. */
|
|
136
114
|
color?: string;
|
|
115
|
+
/** A short radial mark at this value (a limit to compare the arc against); the value stays centred. */
|
|
116
|
+
target?: number;
|
|
117
|
+
/** More radial marks, each at its `at`; a `label` is for the accessible text only. */
|
|
118
|
+
ticks?: readonly MeterTick[];
|
|
137
119
|
segments?: never;
|
|
138
120
|
zones?: never;
|
|
139
|
-
target?: never;
|
|
140
|
-
ticks?: never;
|
|
141
121
|
tone?: never;
|
|
142
122
|
size?: never;
|
|
143
123
|
startCaption?: never;
|
|
144
124
|
endCaption?: never;
|
|
125
|
+
reading?: never;
|
|
126
|
+
stops?: never;
|
|
127
|
+
track?: never;
|
|
145
128
|
});
|
|
146
129
|
export declare function Meter(props: MeterProps): import("react").JSX.Element;
|
|
147
130
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter.tsx"],"names":[],"mappings":"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"}
|
package/dist/dashboard/meter.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { VX } from "../tokens/index.js";
|
|
2
4
|
import { isReading, normalizeSegments, segmentReading, spanOf } from "./meter-model.js";
|
|
3
5
|
import { MeterBar, MeterEmpty, MeterLoading, MeterRing } from "./meter-parts.js";
|
|
4
6
|
import { asText } from "./scale.js";
|
|
7
|
+
import { VisualSlotContext } from "./visual-slot.js";
|
|
5
8
|
let warnedTrack = false;
|
|
6
9
|
function warnInvalidTrack(min, max) {
|
|
7
10
|
if (warnedTrack || spanOf(min, max).valid || process.env.NODE_ENV === "production") return;
|
|
@@ -20,6 +23,8 @@ function Meter(props) {
|
|
|
20
23
|
const shell = { className, style, row };
|
|
21
24
|
const ring = props.shape === "ring";
|
|
22
25
|
warnInvalidTrack(min, max);
|
|
26
|
+
const hostTone = useContext(VisualSlotContext)?.tone;
|
|
27
|
+
const hostColor = hostTone === void 0 ? void 0 : VX.status[hostTone];
|
|
23
28
|
if (props.loading === true) return /* @__PURE__ */ jsx(MeterLoading, { label, ring, shell });
|
|
24
29
|
const segments = props.segments === void 0 ? void 0 : normalizeSegments(props.segments);
|
|
25
30
|
const reading = segments === void 0 ? props.value : segmentReading(segments, min);
|
|
@@ -27,18 +32,30 @@ function Meter(props) {
|
|
|
27
32
|
return /* @__PURE__ */ jsx(MeterEmpty, { label, text: props.emptyText ?? "No data", ring, shell });
|
|
28
33
|
}
|
|
29
34
|
if (props.shape === "ring") {
|
|
30
|
-
return /* @__PURE__ */ jsx(
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
MeterRing,
|
|
37
|
+
{
|
|
38
|
+
...{ label, reading, min, max, format, shell },
|
|
39
|
+
color: props.color ?? hostColor,
|
|
40
|
+
target: isReading(props.target) ? props.target : void 0,
|
|
41
|
+
ticks: props.ticks
|
|
42
|
+
}
|
|
43
|
+
);
|
|
31
44
|
}
|
|
45
|
+
const plain = props.segments === void 0 && props.zones === void 0 && props.stops === void 0;
|
|
32
46
|
return /* @__PURE__ */ jsx(
|
|
33
47
|
MeterBar,
|
|
34
48
|
{
|
|
35
49
|
...{ label, reading, min, max, format, shell },
|
|
36
|
-
color: props.color,
|
|
50
|
+
color: props.color ?? (props.tone === void 0 && plain ? hostColor : void 0),
|
|
37
51
|
segments,
|
|
38
52
|
zones: props.zones,
|
|
53
|
+
stops: props.stops,
|
|
54
|
+
track: props.track,
|
|
55
|
+
markerReading: props.reading,
|
|
39
56
|
target: isReading(props.target) ? props.target : void 0,
|
|
40
57
|
ticks: props.ticks,
|
|
41
|
-
tone: barTone(props.tone,
|
|
58
|
+
tone: barTone(props.tone, plain),
|
|
42
59
|
forecastCaption: props.segments === void 0 ? void 0 : props.forecastCaption,
|
|
43
60
|
startCaption: props.startCaption,
|
|
44
61
|
endCaption: props.endCaption
|