basalt-ui 2.16.0 → 2.18.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 +165 -124
- package/MIGRATING.md +133 -15
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +3 -3
- package/configs/oxlint-plugin.js +2 -2
- package/dist/charts/Donut.d.ts.map +1 -1
- package/dist/charts/Donut.js +2 -2
- package/dist/charts/DualPanel.js +2 -2
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +2 -2
- package/dist/charts/MirroredBars.js +2 -2
- package/dist/charts/Sparkline.d.ts +4 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +3 -3
- package/dist/charts/compile.d.ts +8 -3
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +19 -9
- package/dist/charts/cursor.d.ts +14 -1
- package/dist/charts/cursor.d.ts.map +1 -1
- package/dist/charts/cursor.js +29 -3
- package/dist/charts/date-tick-format.d.ts +17 -0
- package/dist/charts/date-tick-format.d.ts.map +1 -0
- package/dist/charts/date-tick-format.js +81 -0
- package/dist/charts/panel.d.ts +2 -1
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +3 -2
- package/dist/charts/types.d.ts +5 -1
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -2
- package/dist/cli/shot/capture.d.ts +28 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +96 -13
- package/dist/cli/shot/index.d.ts +10 -1
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +40 -5
- package/dist/cli/shot/playwright.d.ts +4 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/real-data.d.ts +35 -0
- package/dist/cli/shot/real-data.d.ts.map +1 -0
- package/dist/cli/shot/real-data.js +120 -0
- package/dist/cli/shot/serve.d.ts +2 -2
- package/dist/cli/shot/serve.d.ts.map +1 -1
- package/dist/cli/shot/serve.js +16 -2
- package/dist/dashboard/bar-list.d.ts +29 -0
- package/dist/dashboard/bar-list.d.ts.map +1 -0
- package/dist/dashboard/bar-list.js +52 -0
- package/dist/dashboard/bar-list.module.css +73 -0
- package/dist/dashboard/bar-list.module.css.d.ts +16 -0
- package/dist/dashboard/delta-badge.d.ts +2 -2
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +12 -14
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-model.d.ts +78 -0
- package/dist/dashboard/meter-model.d.ts.map +1 -0
- package/dist/dashboard/meter-model.js +91 -0
- package/dist/dashboard/meter-parts.d.ts +42 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -0
- package/dist/dashboard/meter-parts.js +163 -0
- package/dist/dashboard/meter.d.ts +112 -0
- package/dist/dashboard/meter.d.ts.map +1 -0
- package/dist/dashboard/meter.js +43 -0
- package/dist/dashboard/meter.module.css +150 -0
- package/dist/dashboard/meter.module.css.d.ts +28 -0
- package/dist/dashboard/query-state.d.ts +35 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +12 -1
- package/dist/dashboard/scale.d.ts +9 -0
- package/dist/dashboard/scale.d.ts.map +1 -0
- package/dist/dashboard/scale.js +10 -0
- package/dist/dashboard/stat-card-parts.d.ts +40 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -0
- package/dist/dashboard/stat-card-parts.js +55 -0
- package/dist/dashboard/stat-card.d.ts +46 -34
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +148 -79
- package/dist/dashboard/stat-card.module.css +220 -7
- package/dist/dashboard/stat-card.module.css.d.ts +20 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +73 -9
- package/dist/dashboard/widget-header.module.css +25 -17
- package/dist/guard/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/theme/chrome-vars.d.ts +82 -0
- package/dist/theme/chrome-vars.d.ts.map +1 -0
- package/dist/theme/chrome-vars.js +36 -0
- package/dist/theme/controls.module.css +20 -1
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +30 -33
- package/dist/tokens/derive.d.ts +11 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +9 -24
- package/dist/tokens/status-text.d.ts +26 -0
- package/dist/tokens/status-text.d.ts.map +1 -0
- package/dist/tokens/status-text.js +68 -0
- package/llms.txt +36 -4
- package/package.json +1 -1
- package/src/charts/Donut.tsx +2 -2
- package/src/charts/DualPanel.tsx +2 -2
- package/src/charts/Heatmap.tsx +2 -2
- package/src/charts/MirroredBars.tsx +2 -2
- package/src/charts/Sparkline.tsx +7 -5
- package/src/charts/compile.ts +31 -11
- package/src/charts/cursor.ts +48 -3
- package/src/charts/date-tick-format.ts +132 -0
- package/src/charts/panel.tsx +5 -3
- package/src/charts/types.ts +5 -1
- package/src/cli/help.ts +22 -2
- package/src/cli/shot/capture.ts +133 -12
- package/src/cli/shot/index.ts +50 -4
- package/src/cli/shot/playwright.ts +1 -1
- package/src/cli/shot/real-data.ts +165 -0
- package/src/cli/shot/serve.ts +28 -3
- package/src/dashboard/bar-list.module.css +73 -0
- package/src/dashboard/bar-list.module.css.d.ts +16 -0
- package/src/dashboard/bar-list.tsx +112 -0
- package/src/dashboard/delta-badge.tsx +24 -18
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-model.ts +161 -0
- package/src/dashboard/meter-parts.tsx +223 -0
- package/src/dashboard/meter.module.css +150 -0
- package/src/dashboard/meter.module.css.d.ts +28 -0
- package/src/dashboard/meter.tsx +162 -0
- package/src/dashboard/query-state.tsx +38 -0
- package/src/dashboard/scale.ts +13 -0
- package/src/dashboard/stat-card-parts.tsx +108 -0
- package/src/dashboard/stat-card.module.css +220 -7
- package/src/dashboard/stat-card.module.css.d.ts +20 -0
- package/src/dashboard/stat-card.tsx +282 -174
- package/src/dashboard/widget-header.module.css +25 -17
- package/src/dashboard/widget-header.tsx +103 -7
- package/src/guard/index.ts +2 -2
- package/src/index.ts +4 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +128 -40
- package/src/theme/chrome-vars.ts +111 -0
- package/src/theme/controls.module.css +20 -1
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +39 -101
- package/src/tokens/derive.ts +19 -26
- package/src/tokens/status-text.ts +85 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type MeterSegment = {
|
|
2
|
+
value: number;
|
|
3
|
+
label: string;
|
|
4
|
+
color?: string;
|
|
5
|
+
forecast?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type MeterZone = {
|
|
8
|
+
from: number;
|
|
9
|
+
to: number;
|
|
10
|
+
label: string;
|
|
11
|
+
color?: string;
|
|
12
|
+
};
|
|
13
|
+
/** A fill on the track, as fractions (0–1) of the span. */
|
|
14
|
+
export type Part = {
|
|
15
|
+
readonly start: number;
|
|
16
|
+
readonly size: number;
|
|
17
|
+
readonly color: string | undefined;
|
|
18
|
+
readonly forecast: boolean;
|
|
19
|
+
};
|
|
20
|
+
type Format = (value: number) => string;
|
|
21
|
+
export declare const isReading: (n: number | null | undefined) => n is number;
|
|
22
|
+
/** The track's span. A track that ends at or before its start falls back to 1 and is `valid: false`. */
|
|
23
|
+
export declare function spanOf(min: number, max: number): {
|
|
24
|
+
span: number;
|
|
25
|
+
valid: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare function ariaValues(reading: number, min: number, max: number, format: Format): {
|
|
28
|
+
readonly role: "meter";
|
|
29
|
+
readonly 'aria-valuenow': number;
|
|
30
|
+
readonly 'aria-valuemin': number;
|
|
31
|
+
readonly 'aria-valuemax': number;
|
|
32
|
+
readonly 'aria-valuetext': string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The ONE place segment amounts are sanitised: a negative or non-finite amount is 0. The painted
|
|
36
|
+
* track, the captions and `aria-valuenow` all derive from what this returns.
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeSegments(segments: readonly MeterSegment[]): MeterSegment[];
|
|
39
|
+
/** Segment amounts (already normalised) accumulate from `min`; a part never passes the track end. */
|
|
40
|
+
export declare function layoutSegments(segments: readonly MeterSegment[], span: number): Part[];
|
|
41
|
+
/** `from` is inclusive; a value on the last band's `to` belongs to that band. */
|
|
42
|
+
export declare function findHoldingZone(zones: readonly MeterZone[], value: number): MeterZone | undefined;
|
|
43
|
+
/** A zone band as left edge + width in percent, clipped to the track. */
|
|
44
|
+
export declare function zoneBand(zone: MeterZone, min: number, span: number): {
|
|
45
|
+
start: number;
|
|
46
|
+
width: number;
|
|
47
|
+
};
|
|
48
|
+
export type BarInput = {
|
|
49
|
+
reading: number;
|
|
50
|
+
min: number;
|
|
51
|
+
max: number;
|
|
52
|
+
format: Format;
|
|
53
|
+
segments?: readonly MeterSegment[] | undefined;
|
|
54
|
+
zones?: readonly MeterZone[] | undefined;
|
|
55
|
+
target?: number | undefined;
|
|
56
|
+
color?: string | undefined;
|
|
57
|
+
forecastCaption?: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
export type BarModel = {
|
|
60
|
+
span: number;
|
|
61
|
+
/** Fills, or none when the track is drawn as zones. */
|
|
62
|
+
parts: readonly Part[];
|
|
63
|
+
/** Percent where the first forecast part starts; absent when the forecast opens the track. */
|
|
64
|
+
boundaryPct: number | undefined;
|
|
65
|
+
forecastText: string | null;
|
|
66
|
+
markerPct: number | undefined;
|
|
67
|
+
targetPct: number | undefined;
|
|
68
|
+
startText: string;
|
|
69
|
+
endText: string | null;
|
|
70
|
+
describedByText: string | null;
|
|
71
|
+
};
|
|
72
|
+
/** Segments are amounts accumulated from `min`, so the reading is `min` plus their sum. */
|
|
73
|
+
export declare const segmentReading: (segments: readonly MeterSegment[], min: number) => number;
|
|
74
|
+
export declare function modelBar(input: BarInput): BarModel;
|
|
75
|
+
/** The ring's one arc, as a fraction of the circumference. */
|
|
76
|
+
export declare const ringFraction: (reading: number, min: number, max: number) => number;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=meter-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter-model.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-model.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAC/F,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnF,2DAA2D;AAC3D,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AAEvC,eAAO,MAAM,SAAS,GAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,CAAC,IAAI,MACjB,CAAA;AAE7C,wGAAwG;AACxG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D;IACvD,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IACtB,8FAA8F;IAC9F,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B,CAAA;AAeD,2FAA2F;AAC3F,eAAO,MAAM,cAAc,GAAI,UAAU,SAAS,YAAY,EAAE,EAAE,KAAK,MAAM,KAAG,MAC/B,CAAA;AAEjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAuClD;AAED,8DAA8D;AAC9D,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MACvB,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { clamp01, toPct } from "./scale.js";
|
|
2
|
+
const isReading = (n) => typeof n === "number" && Number.isFinite(n);
|
|
3
|
+
function spanOf(min, max) {
|
|
4
|
+
return max > min ? { span: max - min, valid: true } : { span: 1, valid: false };
|
|
5
|
+
}
|
|
6
|
+
function ariaValues(reading, min, max, format) {
|
|
7
|
+
return {
|
|
8
|
+
role: "meter",
|
|
9
|
+
"aria-valuenow": Math.min(max, Math.max(min, reading)),
|
|
10
|
+
"aria-valuemin": min,
|
|
11
|
+
"aria-valuemax": max,
|
|
12
|
+
"aria-valuetext": format(reading)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function normalizeSegments(segments) {
|
|
16
|
+
return segments.map((s) => ({ ...s, value: Number.isFinite(s.value) ? Math.max(0, s.value) : 0 }));
|
|
17
|
+
}
|
|
18
|
+
function layoutSegments(segments, span) {
|
|
19
|
+
let cursor = 0;
|
|
20
|
+
return segments.map((s) => {
|
|
21
|
+
const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor));
|
|
22
|
+
const forecast = s.forecast === true;
|
|
23
|
+
const part = { start: cursor, size, color: forecast ? void 0 : s.color, forecast };
|
|
24
|
+
cursor += size;
|
|
25
|
+
return part;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function findHoldingZone(zones, value) {
|
|
29
|
+
const end = Math.max(...zones.map((z) => z.to));
|
|
30
|
+
return zones.find((z) => value >= z.from && (value < z.to || value === z.to && z.to === end));
|
|
31
|
+
}
|
|
32
|
+
function zoneBand(zone, min, span) {
|
|
33
|
+
const lo = clamp01((zone.from - min) / span);
|
|
34
|
+
const hi = clamp01((zone.to - min) / span);
|
|
35
|
+
return { start: toPct(lo), width: toPct(hi - lo) };
|
|
36
|
+
}
|
|
37
|
+
const segmentText = (s, format) => `${s.label} ${format(s.value)}${s.forecast === true ? " (forecast)" : ""}`;
|
|
38
|
+
function endCaptionText(reading, target, format) {
|
|
39
|
+
if (target === void 0) return null;
|
|
40
|
+
if (reading > target) return `Target ${format(target)} \xB7 ${format(reading - target)} over`;
|
|
41
|
+
return `Target ${format(target)}`;
|
|
42
|
+
}
|
|
43
|
+
function fillParts(input, span, zoned) {
|
|
44
|
+
if (zoned) return [];
|
|
45
|
+
if (input.segments !== void 0) return layoutSegments(input.segments, span);
|
|
46
|
+
const fill = { value: input.reading - input.min, label: "" };
|
|
47
|
+
return layoutSegments([input.color === void 0 ? fill : { ...fill, color: input.color }], span);
|
|
48
|
+
}
|
|
49
|
+
const segmentReading = (segments, min) => segments.reduce((sum, s) => sum + s.value, min);
|
|
50
|
+
function modelBar(input) {
|
|
51
|
+
const { reading, min, max, format, segments, zones, target } = input;
|
|
52
|
+
const { span } = spanOf(min, max);
|
|
53
|
+
const zoned = zones !== void 0 && zones.length > 0;
|
|
54
|
+
const holding = zoned ? findHoldingZone(zones, reading) : void 0;
|
|
55
|
+
const parts = fillParts(input, span, zoned);
|
|
56
|
+
const firstForecast = parts.findIndex((p) => p.forecast);
|
|
57
|
+
const forecastLabels = segments?.filter((s) => s.forecast === true).map((s) => `${s.label} ${format(s.value)}`) ?? [];
|
|
58
|
+
const zoneText = !zoned ? [] : [
|
|
59
|
+
...zones.map((z) => `${z.label} ${format(z.from)} to ${format(z.to)}`),
|
|
60
|
+
holding === void 0 ? `${format(reading)} is outside every zone` : `${format(reading)} is in ${holding.label}`
|
|
61
|
+
];
|
|
62
|
+
const describedBy = [
|
|
63
|
+
...segments?.map((s) => segmentText(s, format)) ?? [],
|
|
64
|
+
...zoneText,
|
|
65
|
+
...target === void 0 ? [] : [`Target ${format(target)}`]
|
|
66
|
+
];
|
|
67
|
+
return {
|
|
68
|
+
span,
|
|
69
|
+
parts,
|
|
70
|
+
boundaryPct: firstForecast > 0 ? toPct(parts[firstForecast]?.start ?? 0) : void 0,
|
|
71
|
+
forecastText: forecastLabels.length === 0 ? null : input.forecastCaption ?? `Forecast: ${forecastLabels.join(", ")}`,
|
|
72
|
+
markerPct: zoned ? toPct((reading - min) / span) : void 0,
|
|
73
|
+
targetPct: target === void 0 ? void 0 : toPct((target - min) / span),
|
|
74
|
+
startText: holding === void 0 ? format(reading) : `${holding.label} \xB7 ${format(reading)}`,
|
|
75
|
+
endText: endCaptionText(reading, target, format),
|
|
76
|
+
describedByText: describedBy.length > 0 ? describedBy.join("; ") : null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const ringFraction = (reading, min, max) => clamp01((reading - min) / spanOf(min, max).span);
|
|
80
|
+
export {
|
|
81
|
+
ariaValues,
|
|
82
|
+
findHoldingZone,
|
|
83
|
+
isReading,
|
|
84
|
+
layoutSegments,
|
|
85
|
+
modelBar,
|
|
86
|
+
normalizeSegments,
|
|
87
|
+
ringFraction,
|
|
88
|
+
segmentReading,
|
|
89
|
+
spanOf,
|
|
90
|
+
zoneBand
|
|
91
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import type { MeterSegment, MeterZone } from './meter-model.js';
|
|
3
|
+
export type Shell = {
|
|
4
|
+
className: string | undefined;
|
|
5
|
+
style: CSSProperties | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function MeterLoading({ label, ring, shell, }: {
|
|
8
|
+
label: string;
|
|
9
|
+
ring: boolean;
|
|
10
|
+
shell: Shell;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export declare function MeterEmpty(props: {
|
|
13
|
+
label: string;
|
|
14
|
+
text: string;
|
|
15
|
+
ring: boolean;
|
|
16
|
+
shell: Shell;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
export declare function MeterRing(props: {
|
|
19
|
+
label: string;
|
|
20
|
+
reading: number;
|
|
21
|
+
min: number;
|
|
22
|
+
max: number;
|
|
23
|
+
color: string | undefined;
|
|
24
|
+
format: (value: number) => string;
|
|
25
|
+
shell: Shell;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
27
|
+
export declare function MeterBar(props: {
|
|
28
|
+
label: string;
|
|
29
|
+
reading: number;
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
format: (value: number) => string;
|
|
33
|
+
color: string | undefined;
|
|
34
|
+
segments: readonly MeterSegment[] | undefined;
|
|
35
|
+
zones: readonly MeterZone[] | undefined;
|
|
36
|
+
target: number | undefined;
|
|
37
|
+
forecastCaption: string | undefined;
|
|
38
|
+
startCaption: ReactNode;
|
|
39
|
+
endCaption: ReactNode;
|
|
40
|
+
shell: Shell;
|
|
41
|
+
}): import("react").JSX.Element;
|
|
42
|
+
//# sourceMappingURL=meter-parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter-parts.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-parts.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO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EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,eAAe,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,YAAY,EAAE,SAAS,CAAA;IACvB,UAAU,EAAE,SAAS,CAAA;IACrB,KAAK,EAAE,KAAK,CAAA;CACb,+BAuDA"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Skeleton, VisuallyHidden } from "@mantine/core";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { cx } from "../common/props.js";
|
|
5
|
+
import { ariaValues, modelBar, ringFraction, zoneBand } from "./meter-model.js";
|
|
6
|
+
import classes from "./meter.module.css";
|
|
7
|
+
import { toPct } from "./scale.js";
|
|
8
|
+
const RING_VIEWBOX = 36;
|
|
9
|
+
const RING_STROKE = 4;
|
|
10
|
+
const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2;
|
|
11
|
+
const RING_LENGTH = 2 * Math.PI * RING_RADIUS;
|
|
12
|
+
const RING_CENTER = RING_VIEWBOX / 2;
|
|
13
|
+
function RingSvg({ fraction, color }) {
|
|
14
|
+
return /* @__PURE__ */ jsxs("svg", { className: classes.ring, viewBox: `0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`, "aria-hidden": true, children: [
|
|
15
|
+
/* @__PURE__ */ jsx(
|
|
16
|
+
"circle",
|
|
17
|
+
{
|
|
18
|
+
className: classes.ringTrack,
|
|
19
|
+
cx: RING_CENTER,
|
|
20
|
+
cy: RING_CENTER,
|
|
21
|
+
r: RING_RADIUS,
|
|
22
|
+
strokeWidth: RING_STROKE
|
|
23
|
+
}
|
|
24
|
+
),
|
|
25
|
+
fraction !== void 0 && /* @__PURE__ */ jsx(
|
|
26
|
+
"circle",
|
|
27
|
+
{
|
|
28
|
+
className: classes.ringArc,
|
|
29
|
+
cx: RING_CENTER,
|
|
30
|
+
cy: RING_CENTER,
|
|
31
|
+
r: RING_RADIUS,
|
|
32
|
+
strokeWidth: RING_STROKE,
|
|
33
|
+
strokeDasharray: `${fraction * RING_LENGTH} ${RING_LENGTH}`,
|
|
34
|
+
...color !== void 0 && { style: { stroke: color } }
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
] });
|
|
38
|
+
}
|
|
39
|
+
function MeterLoading({
|
|
40
|
+
label,
|
|
41
|
+
ring,
|
|
42
|
+
shell
|
|
43
|
+
}) {
|
|
44
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(classes.root, shell.className), style: shell.style, "aria-busy": "true", children: [
|
|
45
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: `Loading ${label}` }),
|
|
46
|
+
ring ? /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonRing, circle: true }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
|
+
/* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonTrack }),
|
|
48
|
+
/* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonCaption, radius: "sm" })
|
|
49
|
+
] })
|
|
50
|
+
] });
|
|
51
|
+
}
|
|
52
|
+
function MeterEmpty(props) {
|
|
53
|
+
const { label, text, ring, shell } = props;
|
|
54
|
+
return /* @__PURE__ */ jsxs("output", { className: cx(classes.root, shell.className), style: shell.style, "aria-label": label, children: [
|
|
55
|
+
ring ? /* @__PURE__ */ jsx("span", { className: classes.ringBox, children: /* @__PURE__ */ jsx(RingSvg, {}) }) : /* @__PURE__ */ jsx("div", { className: classes.trackBox, children: /* @__PURE__ */ jsx("div", { className: classes.track, "data-meter-track": true }) }),
|
|
56
|
+
/* @__PURE__ */ jsx("span", { className: classes.empty, children: text })
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
59
|
+
function MeterRing(props) {
|
|
60
|
+
const { label, reading, min, max, color, format, shell } = props;
|
|
61
|
+
return /* @__PURE__ */ jsx("div", { className: cx(classes.root, shell.className), style: shell.style, children: /* @__PURE__ */ jsxs(
|
|
62
|
+
"span",
|
|
63
|
+
{
|
|
64
|
+
className: classes.ringBox,
|
|
65
|
+
"aria-label": label,
|
|
66
|
+
...ariaValues(reading, min, max, format),
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ jsx(RingSvg, { fraction: ringFraction(reading, min, max), color }),
|
|
69
|
+
/* @__PURE__ */ jsx("span", { className: classes.ringValue, children: format(reading) })
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
) });
|
|
73
|
+
}
|
|
74
|
+
function fillStyle(p) {
|
|
75
|
+
return { width: `${toPct(p.size)}%`, ...p.color !== void 0 && { background: p.color } };
|
|
76
|
+
}
|
|
77
|
+
const ZONE_STRENGTH_MIN = 15;
|
|
78
|
+
const ZONE_STRENGTH_STEP = 45;
|
|
79
|
+
const ZONE_STRENGTH_SOLO = 40;
|
|
80
|
+
const ZONE_GAP = "1px";
|
|
81
|
+
function zoneStyle(zone, index, count, min, span) {
|
|
82
|
+
const band = zoneBand(zone, min, span);
|
|
83
|
+
const gap = index > 0;
|
|
84
|
+
const strength = count > 1 ? ZONE_STRENGTH_MIN + index / (count - 1) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO;
|
|
85
|
+
return {
|
|
86
|
+
insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
|
|
87
|
+
width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
|
|
88
|
+
background: zone.color ?? `color-mix(in srgb, var(--vx-line) ${strength}%, transparent)`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function MeterBar(props) {
|
|
92
|
+
const { label, reading, min, max, format, zones, shell } = props;
|
|
93
|
+
const describedId = useId();
|
|
94
|
+
const model = modelBar(props);
|
|
95
|
+
const start = props.startCaption === void 0 ? model.startText : props.startCaption;
|
|
96
|
+
const end = props.endCaption === void 0 ? model.endText : props.endCaption;
|
|
97
|
+
const hasCaptions = start !== null || end !== null || model.forecastText !== null;
|
|
98
|
+
const describedBy = model.describedByText === null ? {} : { "aria-describedby": describedId };
|
|
99
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(classes.root, shell.className), style: shell.style, children: [
|
|
100
|
+
/* @__PURE__ */ jsxs(
|
|
101
|
+
"div",
|
|
102
|
+
{
|
|
103
|
+
className: classes.trackBox,
|
|
104
|
+
"aria-label": label,
|
|
105
|
+
...ariaValues(reading, min, max, format),
|
|
106
|
+
...describedBy,
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsxs("div", { className: classes.track, "data-meter-track": true, children: [
|
|
109
|
+
model.markerPct !== void 0 && zones?.map((z, i) => /* @__PURE__ */ jsx(
|
|
110
|
+
"div",
|
|
111
|
+
{
|
|
112
|
+
className: classes.zone,
|
|
113
|
+
"data-meter-zone": z.label,
|
|
114
|
+
style: zoneStyle(z, i, zones.length, min, model.span)
|
|
115
|
+
},
|
|
116
|
+
i
|
|
117
|
+
)),
|
|
118
|
+
model.parts.map((p, i) => /* @__PURE__ */ jsx(
|
|
119
|
+
"div",
|
|
120
|
+
{
|
|
121
|
+
className: cx(classes.fill, p.forecast && classes.forecastFill),
|
|
122
|
+
"data-meter-fill": p.forecast ? "forecast" : "committed",
|
|
123
|
+
style: fillStyle(p)
|
|
124
|
+
},
|
|
125
|
+
i
|
|
126
|
+
))
|
|
127
|
+
] }),
|
|
128
|
+
/* @__PURE__ */ jsx(Tick, { kind: "marker", className: classes.marker, pct: model.markerPct }),
|
|
129
|
+
/* @__PURE__ */ jsx(Tick, { kind: "boundary", className: classes.boundaryTick, pct: model.boundaryPct }),
|
|
130
|
+
/* @__PURE__ */ jsx(Tick, { kind: "target", className: classes.tick, pct: model.targetPct })
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
model.describedByText !== null && /* @__PURE__ */ jsx(VisuallyHidden, { id: describedId, children: model.describedByText }),
|
|
135
|
+
hasCaptions && /* @__PURE__ */ jsxs("div", { className: classes.captions, "data-meter-captions": true, children: [
|
|
136
|
+
start !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: start }),
|
|
137
|
+
model.forecastText !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: model.forecastText }),
|
|
138
|
+
end !== null && /* @__PURE__ */ jsx("span", { className: classes.captionEnd, children: end })
|
|
139
|
+
] })
|
|
140
|
+
] });
|
|
141
|
+
}
|
|
142
|
+
function Tick({
|
|
143
|
+
kind,
|
|
144
|
+
className,
|
|
145
|
+
pct
|
|
146
|
+
}) {
|
|
147
|
+
if (pct === void 0) return null;
|
|
148
|
+
return /* @__PURE__ */ jsx(
|
|
149
|
+
"div",
|
|
150
|
+
{
|
|
151
|
+
className,
|
|
152
|
+
"data-meter-tick": kind,
|
|
153
|
+
style: { insetInlineStart: `${pct}%` },
|
|
154
|
+
"aria-hidden": true
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
MeterBar,
|
|
160
|
+
MeterEmpty,
|
|
161
|
+
MeterLoading,
|
|
162
|
+
MeterRing
|
|
163
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
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: the fill is neutral (`VX.line`). `color` is for a VERDICT only (over budget, below
|
|
8
|
+
* target) and is a status colour the consumer passes; categorical `segments` take the consumer's
|
|
9
|
+
* series colours. Committed vs forecast is the same neutral at two strengths — never colour alone: a
|
|
10
|
+
* tick marks the boundary and a caption names the forecast. A value past `max` clamps the fill at the
|
|
11
|
+
* track end; the caption still states the real value.
|
|
12
|
+
*
|
|
13
|
+
* `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
|
|
14
|
+
* passes a status colour) and the reading becomes a MARKER on the track, not a fill; the caption names
|
|
15
|
+
* the zone that holds the value (`from` inclusive). Use it for a reading judged against ranges.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { Meter } from 'basalt-ui'
|
|
19
|
+
*
|
|
20
|
+
* // Spend against a budget: past the target the end caption states the overage.
|
|
21
|
+
* <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
|
|
22
|
+
* // Training load as a zone band with a marker: caption reads "Optimal · 612".
|
|
23
|
+
* <Meter
|
|
24
|
+
* label="Training load"
|
|
25
|
+
* max={1000}
|
|
26
|
+
* value={612}
|
|
27
|
+
* zones={[
|
|
28
|
+
* { from: 0, to: 300, label: 'Low' },
|
|
29
|
+
* { from: 300, to: 750, label: 'Optimal' },
|
|
30
|
+
* { from: 750, to: 1000, label: 'High' },
|
|
31
|
+
* ]}
|
|
32
|
+
* />
|
|
33
|
+
* // A readiness score on its 0–100 scale (its contributors: <BarList max={100} … secondary="Good" />).
|
|
34
|
+
* <Meter label="Recovery" value={72} max={100} />
|
|
35
|
+
* <Meter
|
|
36
|
+
* label="Course progress"
|
|
37
|
+
* max={120}
|
|
38
|
+
* segments={[{ value: 70, label: 'Done' }, { value: 25, label: 'Planned', forecast: true }]}
|
|
39
|
+
* />
|
|
40
|
+
* <Meter shape="ring" label="Cache hit rate" value={87} max={100} format={(v) => `${v}%`} />
|
|
41
|
+
*/
|
|
42
|
+
import type { ReactNode } from 'react';
|
|
43
|
+
import type { BasaltProps } from '../common/props.js';
|
|
44
|
+
import type { MeterSegment, MeterZone } from './meter-model.js';
|
|
45
|
+
type Common = BasaltProps & {
|
|
46
|
+
/** Accessible name (`aria-label`). Required: a meter without one is announced as a bare number. */
|
|
47
|
+
label: string;
|
|
48
|
+
/** Track start. Default 0. */
|
|
49
|
+
min?: number;
|
|
50
|
+
/** Track end. Default 100. */
|
|
51
|
+
max?: number;
|
|
52
|
+
/** Formats values in captions and the accessible text. Default: the number as written. */
|
|
53
|
+
format?: (value: number) => string;
|
|
54
|
+
/** Renders a skeleton with the meter's footprint. */
|
|
55
|
+
loading?: boolean;
|
|
56
|
+
/** Muted line shown when there is no reading. The track stays so the footprint holds. */
|
|
57
|
+
emptyText?: string;
|
|
58
|
+
};
|
|
59
|
+
type BarCommon = Common & {
|
|
60
|
+
shape?: 'bar';
|
|
61
|
+
/** Target position; draws a tick and states it in the end caption (with the overage past it). */
|
|
62
|
+
target?: number;
|
|
63
|
+
/** Start caption (default: the formatted reading, or `Zone · reading`). `null` drops it. */
|
|
64
|
+
startCaption?: ReactNode;
|
|
65
|
+
/** End caption (default: `Target <target>`). `null` drops it. */
|
|
66
|
+
endCaption?: ReactNode;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* One of four forms; mixing them is a compile error.
|
|
70
|
+
* - Bar `value` (+ `target`, `color`): one reading on a neutral track.
|
|
71
|
+
* - Bar `segments`: ordered parts that sum to the reading (committed/forecast, part of a whole).
|
|
72
|
+
* - Bar `value` + `zones`: the reading is a marker against contiguous bands.
|
|
73
|
+
* - Ring (`shape: 'ring'`) `value` (+ `color`): one headline ratio; no target, captions, segments or zones.
|
|
74
|
+
*/
|
|
75
|
+
export type MeterProps = (BarCommon & {
|
|
76
|
+
/** The reading. `null`/`undefined` (or non-finite) renders the empty state. */
|
|
77
|
+
value?: number | null | undefined;
|
|
78
|
+
/** A status colour, for a verdict only. Omit for the neutral fill. */
|
|
79
|
+
color?: string;
|
|
80
|
+
segments?: never;
|
|
81
|
+
zones?: never;
|
|
82
|
+
}) | (BarCommon & {
|
|
83
|
+
/** Ordered parts, accumulated from `min`; their sum is the reading. `forecast` parts render lighter. */
|
|
84
|
+
segments: readonly MeterSegment[];
|
|
85
|
+
/** Names the forecast beside the boundary tick (default: `Forecast: <labels>`). */
|
|
86
|
+
forecastCaption?: string;
|
|
87
|
+
value?: never;
|
|
88
|
+
color?: never;
|
|
89
|
+
zones?: never;
|
|
90
|
+
}) | (BarCommon & {
|
|
91
|
+
value?: number | null | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Contiguous bands drawn as the track, positioned from each `from`. The reading becomes a marker
|
|
94
|
+
* and the caption names the band that holds it.
|
|
95
|
+
*/
|
|
96
|
+
zones: readonly MeterZone[];
|
|
97
|
+
segments?: never;
|
|
98
|
+
color?: never;
|
|
99
|
+
}) | (Common & {
|
|
100
|
+
shape: 'ring';
|
|
101
|
+
value?: number | null | undefined;
|
|
102
|
+
/** A status colour, for a verdict only. */
|
|
103
|
+
color?: string;
|
|
104
|
+
segments?: never;
|
|
105
|
+
zones?: never;
|
|
106
|
+
target?: never;
|
|
107
|
+
startCaption?: never;
|
|
108
|
+
endCaption?: never;
|
|
109
|
+
});
|
|
110
|
+
export declare function Meter(props: MeterProps): import("react").JSX.Element;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=meter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAI5D,KAAK,MAAM,GAAG,WAAW,GAAG;IAC1B,mGAAmG;IACnG,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,0FAA0F;IAC1F,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAClC,qDAAqD;IACrD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yFA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KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB,CAAC,CAAA;AAYN,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,+BA+BtC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isReading, normalizeSegments, segmentReading, spanOf } from "./meter-model.js";
|
|
3
|
+
import { MeterBar, MeterEmpty, MeterLoading, MeterRing } from "./meter-parts.js";
|
|
4
|
+
import { asText } from "./scale.js";
|
|
5
|
+
let warnedTrack = false;
|
|
6
|
+
function warnInvalidTrack(min, max) {
|
|
7
|
+
if (warnedTrack || spanOf(min, max).valid || process.env.NODE_ENV === "production") return;
|
|
8
|
+
warnedTrack = true;
|
|
9
|
+
console.warn(
|
|
10
|
+
`[basalt] Meter: max (${max}) must be greater than min (${min}); drawing an empty track`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
function Meter(props) {
|
|
14
|
+
const { label, min = 0, max = 100, format = asText, className, style } = props;
|
|
15
|
+
const shell = { className, style };
|
|
16
|
+
const ring = props.shape === "ring";
|
|
17
|
+
warnInvalidTrack(min, max);
|
|
18
|
+
if (props.loading === true) return /* @__PURE__ */ jsx(MeterLoading, { label, ring, shell });
|
|
19
|
+
const segments = props.segments === void 0 ? void 0 : normalizeSegments(props.segments);
|
|
20
|
+
const reading = segments === void 0 ? props.value : segmentReading(segments, min);
|
|
21
|
+
if (!isReading(reading) || segments?.length === 0) {
|
|
22
|
+
return /* @__PURE__ */ jsx(MeterEmpty, { label, text: props.emptyText ?? "No data", ring, shell });
|
|
23
|
+
}
|
|
24
|
+
if (props.shape === "ring") {
|
|
25
|
+
return /* @__PURE__ */ jsx(MeterRing, { ...{ label, reading, min, max, format, shell }, color: props.color });
|
|
26
|
+
}
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
MeterBar,
|
|
29
|
+
{
|
|
30
|
+
...{ label, reading, min, max, format, shell },
|
|
31
|
+
color: props.color,
|
|
32
|
+
segments,
|
|
33
|
+
zones: props.zones,
|
|
34
|
+
target: isReading(props.target) ? props.target : void 0,
|
|
35
|
+
forecastCaption: props.segments === void 0 ? void 0 : props.forecastCaption,
|
|
36
|
+
startCaption: props.startCaption,
|
|
37
|
+
endCaption: props.endCaption
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
Meter
|
|
43
|
+
};
|