basalt-ui 2.21.0 → 2.23.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 +60 -0
- package/MIGRATING.md +452 -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 +73 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +6 -0
- package/dist/charts/CartesianChart.d.ts +10 -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 +39 -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 +14 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +101 -22
- 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 +38 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +18 -1
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- 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 +7 -0
- package/dist/charts/compile.d.ts +25 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +152 -72
- 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 +21 -6
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +52 -17
- 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 +43 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +75 -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 +13 -17
- 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 +5 -2
- package/dist/charts/types.d.ts +18 -8
- 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 +202 -36
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +17 -1
- package/dist/cli/shot/playwright.d.ts +13 -2
- 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 +4 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- 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/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 +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +15 -8
- package/dist/dashboard/bar-list.module.css +83 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- 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 +84 -5
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +100 -15
- package/dist/dashboard/meter-parts.d.ts +9 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +276 -74
- package/dist/dashboard/meter.d.ts +54 -65
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +21 -4
- package/dist/dashboard/meter.module.css +76 -0
- package/dist/dashboard/meter.module.css.d.ts +6 -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/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +1 -1
- 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 +36 -0
- package/dist/dashboard/stat-group.module.css +7 -0
- package/dist/dashboard/stat-strip.d.ts +22 -6
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +104 -60
- package/dist/dashboard/stat-strip.module.css +122 -53
- 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/index.d.ts.map +1 -1
- package/dist/guard/index.js +0 -5
- 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 +43 -4
- 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 +37 -0
- package/dist/theme/controls.module.css.d.ts +2 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +18 -27
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- 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 +11 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +11 -10
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +42 -22
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +83 -3
- package/src/charts/Bars.tsx +7 -0
- package/src/charts/CartesianChart.tsx +18 -3
- package/src/charts/ChartCard.tsx +54 -13
- 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 +135 -25
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +50 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +253 -87
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +81 -26
- 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 +131 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +13 -17
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +9 -4
- package/src/charts/types.ts +18 -8
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/init.ts +100 -3
- package/src/cli/shot/capture.ts +266 -35
- package/src/cli/shot/detect.ts +18 -1
- package/src/cli/shot/playwright.ts +20 -4
- package/src/cli/shot/types.ts +5 -0
- package/src/cli/tokens-css.ts +18 -20
- 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 +83 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +107 -69
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +207 -24
- package/src/dashboard/meter-parts.tsx +349 -67
- package/src/dashboard/meter.module.css +76 -0
- package/src/dashboard/meter.module.css.d.ts +6 -0
- package/src/dashboard/meter.tsx +72 -18
- 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/query-state.tsx +1 -1
- 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 +36 -0
- package/src/dashboard/stat-card.tsx +12 -6
- package/src/dashboard/stat-group.module.css +7 -0
- package/src/dashboard/stat-strip.module.css +122 -53
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +176 -91
- package/src/dashboard/visual-slot.ts +12 -3
- package/src/guard/index.ts +0 -5
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +43 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +200 -68
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +37 -0
- package/src/theme/controls.module.css.d.ts +2 -0
- package/src/theme/index.ts +22 -32
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/palette.ts +11 -10
- package/src/tokens/status-text.ts +2 -0
|
@@ -5,11 +5,26 @@
|
|
|
5
5
|
import type { ReactNode } from 'react'
|
|
6
6
|
import { clamp01, toPct } from './scale'
|
|
7
7
|
|
|
8
|
-
export type MeterSegment = {
|
|
8
|
+
export type MeterSegment = {
|
|
9
|
+
value: number
|
|
10
|
+
label: string
|
|
11
|
+
color?: string
|
|
12
|
+
/**
|
|
13
|
+
* `'muted'`: the part takes the one flat muted fill every muted part shares, a hairline seam
|
|
14
|
+
* between neighbours (never a lightness step). A `color` wins.
|
|
15
|
+
*/
|
|
16
|
+
tone?: 'muted'
|
|
17
|
+
forecast?: boolean
|
|
18
|
+
}
|
|
9
19
|
export type MeterZone = {
|
|
10
20
|
from: number
|
|
11
21
|
to: number
|
|
12
22
|
label: string
|
|
23
|
+
/**
|
|
24
|
+
* `'muted'`: the band takes the one flat muted fill every muted zone shares, a hairline gap
|
|
25
|
+
* between neighbours (never a lightness step): a non-verdict band is not a value bar. A `color` wins.
|
|
26
|
+
*/
|
|
27
|
+
tone?: 'muted'
|
|
13
28
|
/**
|
|
14
29
|
* A shorter name for a narrow track. The row tries `label`, then `short`, and only then hides the
|
|
15
30
|
* name; the holding zone always shows its full `label`. The described-by text keeps `label`.
|
|
@@ -17,11 +32,54 @@ export type MeterZone = {
|
|
|
17
32
|
short?: string
|
|
18
33
|
color?: string
|
|
19
34
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
35
|
+
/**
|
|
36
|
+
* A mark on the track at `at` (in the reading's units). A `label` is captioned beside it, above the
|
|
37
|
+
* track; a `caption` sits under the track, centred on the mark and clamped inside the track.
|
|
38
|
+
*/
|
|
39
|
+
export type MeterTick = { at: number; label?: string; caption?: string }
|
|
40
|
+
|
|
41
|
+
/** A colour of a `stops` gradient at `at` (in the reading's units); the colour is the consumer's. */
|
|
42
|
+
type MeterStop = { at: number; color: string }
|
|
43
|
+
|
|
44
|
+
/** A ramp step's strength in percent of its neutral: from `lo`, spread over `step` across the steps. */
|
|
45
|
+
export const RAMP_ZONE = { lo: 15, step: 45, solo: 40 }
|
|
46
|
+
/** The flat muted fill, in percent of `--vx-muted`: a zone band (argo's alpha) and a segment (clears 3:1 on the track). */
|
|
47
|
+
const MUTED_ZONE = 35
|
|
48
|
+
const MUTED_PART = 65
|
|
49
|
+
/** Neighbouring steps stay at least this far apart (the contrast the zone ramp always had), up to `RAMP_MAX`. */
|
|
50
|
+
export const RAMP_MIN_STEP = 15
|
|
51
|
+
export const RAMP_MAX = 95
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Step `index` of `count`. The spread is floored at `RAMP_MIN_STEP` per step, so a ramp stays
|
|
55
|
+
* distinguishable by lightness up to six zones; past that the last steps clamp at
|
|
56
|
+
* `RAMP_MAX` and merge, which is the cue to group parts.
|
|
57
|
+
*/
|
|
58
|
+
export function rampStrength(index: number, count: number, ramp: typeof RAMP_ZONE): number {
|
|
59
|
+
if (count <= 1) return ramp.solo
|
|
60
|
+
return Math.min(RAMP_MAX, ramp.lo + index * Math.max(RAMP_MIN_STEP, ramp.step / (count - 1)))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function rampFill(base: 'line', index: number, count: number, ramp: typeof RAMP_ZONE): string {
|
|
64
|
+
return `color-mix(in srgb, var(--vx-${base}) ${rampStrength(index, count, ramp)}%, transparent)`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const mutedFill = (pct: number) => `color-mix(in srgb, var(--vx-muted) ${pct}%, transparent)`
|
|
68
|
+
|
|
69
|
+
/** A zone's fill: its own colour, else the one flat muted fill (`tone="muted"`), else its step of the line ramp. */
|
|
70
|
+
export function zoneFill(zone: MeterZone, index: number, count: number): string {
|
|
71
|
+
if (zone.color !== undefined) return zone.color
|
|
72
|
+
return zone.tone === 'muted' ? mutedFill(MUTED_ZONE) : rampFill('line', index, count, RAMP_ZONE)
|
|
73
|
+
}
|
|
22
74
|
|
|
23
75
|
/** One tick on the track: its percent position and what it says (caption `label`, aria `text`). */
|
|
24
|
-
export type TickMark = {
|
|
76
|
+
export type TickMark = {
|
|
77
|
+
key: string
|
|
78
|
+
pct: number
|
|
79
|
+
label: string | undefined
|
|
80
|
+
caption: string | undefined
|
|
81
|
+
text: string
|
|
82
|
+
}
|
|
25
83
|
|
|
26
84
|
/** A fill on the track, as fractions (0–1) of the span, with the segment it was laid out from. */
|
|
27
85
|
export type Part = {
|
|
@@ -29,13 +87,22 @@ export type Part = {
|
|
|
29
87
|
readonly size: number
|
|
30
88
|
readonly color: string | undefined
|
|
31
89
|
readonly forecast: boolean
|
|
90
|
+
/** A muted part right after another muted part: a hairline seam keeps the shared fill apart. */
|
|
91
|
+
readonly seam: boolean
|
|
32
92
|
readonly label: string
|
|
33
93
|
/** The segment's own (normalised) amount, in the reading's units — what its caption states. */
|
|
34
94
|
readonly amount: number
|
|
35
95
|
}
|
|
36
96
|
|
|
37
97
|
/** One categorical part's caption: its position key, name, formatted amount and fill colour (`undefined` = neutral). */
|
|
38
|
-
export type PartCaption = {
|
|
98
|
+
export type PartCaption = {
|
|
99
|
+
key: string
|
|
100
|
+
label: string
|
|
101
|
+
text: string
|
|
102
|
+
color: string | undefined
|
|
103
|
+
/** Where the part starts on the track, in percent: the caption sits under it when they all fit. */
|
|
104
|
+
startPct: number
|
|
105
|
+
}
|
|
39
106
|
|
|
40
107
|
/** One zone's name on the label row: its span's centre and width (percent) and whether it holds the reading. */
|
|
41
108
|
export type ZoneLabel = {
|
|
@@ -74,6 +141,7 @@ export function tickMarks(
|
|
|
74
141
|
key: String(i),
|
|
75
142
|
pct: toPct((t.at - min) / span),
|
|
76
143
|
label: t.label,
|
|
144
|
+
caption: t.caption,
|
|
77
145
|
text: `${t.label ?? 'Tick'} ${format(t.at)}`,
|
|
78
146
|
},
|
|
79
147
|
]
|
|
@@ -81,6 +149,36 @@ export function tickMarks(
|
|
|
81
149
|
)
|
|
82
150
|
}
|
|
83
151
|
|
|
152
|
+
/** A `stops` gradient's colour list, in order along the track; `at` outside `[min, max]` clamps. */
|
|
153
|
+
export function stopsGradient(stops: readonly MeterStop[], min: number, span: number): string {
|
|
154
|
+
return stops
|
|
155
|
+
.toSorted((a, b) => a.at - b.at)
|
|
156
|
+
.map((s) => `${s.color} ${toPct(clamp01((s.at - min) / span))}%`)
|
|
157
|
+
.join(', ')
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const ringAngle = (pct: number) => Math.round(pct * 3.6 * 100) / 100
|
|
161
|
+
|
|
162
|
+
/** A ring's marks (target, ticks): the angle clockwise from the top, and the accessible text. */
|
|
163
|
+
export function ringMarks(
|
|
164
|
+
target: number | undefined,
|
|
165
|
+
ticks: readonly MeterTick[] | undefined,
|
|
166
|
+
min: number,
|
|
167
|
+
max: number,
|
|
168
|
+
format: Format,
|
|
169
|
+
): { angle: number; text: string }[] {
|
|
170
|
+
const { span } = spanOf(min, max)
|
|
171
|
+
const marks = tickMarks(ticks, min, max, format).map((t) => ({
|
|
172
|
+
angle: ringAngle(t.pct),
|
|
173
|
+
text: t.text,
|
|
174
|
+
}))
|
|
175
|
+
if (target === undefined || !Number.isFinite(target) || target < min || target > max) return marks
|
|
176
|
+
return [
|
|
177
|
+
{ angle: ringAngle(toPct((target - min) / span)), text: `Target ${format(target)}` },
|
|
178
|
+
...marks,
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
|
|
84
182
|
export const isReading = (n: number | null | undefined): n is number =>
|
|
85
183
|
typeof n === 'number' && Number.isFinite(n)
|
|
86
184
|
|
|
@@ -110,6 +208,8 @@ export function normalizeSegments(segments: readonly MeterSegment[]): MeterSegme
|
|
|
110
208
|
/** Segment amounts (already normalised) accumulate from `min`; a part never passes the track end. */
|
|
111
209
|
export function layoutSegments(segments: readonly MeterSegment[], span: number): Part[] {
|
|
112
210
|
let cursor = 0
|
|
211
|
+
const isMuted = (s: MeterSegment) => s.tone === 'muted' && s.color === undefined && !s.forecast
|
|
212
|
+
let prevMuted = false
|
|
113
213
|
return segments.map((s) => {
|
|
114
214
|
const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor))
|
|
115
215
|
const forecast = s.forecast === true
|
|
@@ -117,12 +217,14 @@ export function layoutSegments(segments: readonly MeterSegment[], span: number):
|
|
|
117
217
|
const part = {
|
|
118
218
|
start: cursor,
|
|
119
219
|
size,
|
|
120
|
-
color: forecast ? undefined : s.color,
|
|
220
|
+
color: forecast ? undefined : isMuted(s) ? mutedFill(MUTED_PART) : s.color,
|
|
121
221
|
forecast,
|
|
222
|
+
seam: isMuted(s) && prevMuted,
|
|
122
223
|
label: s.label,
|
|
123
224
|
amount: s.value,
|
|
124
225
|
}
|
|
125
226
|
cursor += size
|
|
227
|
+
prevMuted = isMuted(s)
|
|
126
228
|
return part
|
|
127
229
|
})
|
|
128
230
|
}
|
|
@@ -143,7 +245,14 @@ export type LabelBox = { left: number; right: number }
|
|
|
143
245
|
* A label on the shared row: its measured box and, for a zone name, the span it must stay inside.
|
|
144
246
|
* The holding zone's name never hides for width: it ignores its span and is shifted into the row.
|
|
145
247
|
*/
|
|
146
|
-
export type RowLabel = {
|
|
248
|
+
export type RowLabel = {
|
|
249
|
+
box: LabelBox
|
|
250
|
+
span?: LabelBox
|
|
251
|
+
holding?: boolean
|
|
252
|
+
/** A tick at the track's start or end: it keeps its place over every zone name it would touch. */
|
|
253
|
+
end?: boolean
|
|
254
|
+
short?: LabelBox
|
|
255
|
+
}
|
|
147
256
|
|
|
148
257
|
/** The placement of the row's labels, index-aligned with the input. */
|
|
149
258
|
export type RowPlacement = {
|
|
@@ -157,33 +266,45 @@ export type RowPlacement = {
|
|
|
157
266
|
/**
|
|
158
267
|
* Which labels of the row show, in input order. The holding zone's name claims its place first (it
|
|
159
268
|
* is the reading's verdict, so it never hides for width: it may spill past its span, shifted inside
|
|
160
|
-
* the row); the
|
|
161
|
-
* when it lies inside the row and its own span and
|
|
162
|
-
*
|
|
269
|
+
* the row); the other ticks go next, then the end ticks (at the track's start or end: a scale's
|
|
270
|
+
* figures); every other zone name then shows only when it lies inside the row and its own span and
|
|
271
|
+
* clears every label already kept, trying its full name, then its `short` box, then hiding. An end
|
|
272
|
+
* figure hides only when it cannot clear the holding name, an interior tick or the other end. A tick
|
|
273
|
+
* keeps at least `gap` px (one gap step of the host's spacing) from every other label; zone names
|
|
274
|
+
* among themselves only must not touch. A hidden name is still named in the described-by text.
|
|
163
275
|
*/
|
|
164
|
-
export function placeRowLabels(
|
|
276
|
+
export function placeRowLabels(
|
|
277
|
+
labels: readonly RowLabel[],
|
|
278
|
+
rowWidth: number,
|
|
279
|
+
gap = 0,
|
|
280
|
+
): RowPlacement {
|
|
165
281
|
const shown = labels.map(() => false)
|
|
166
282
|
const short = labels.map(() => false)
|
|
167
283
|
const shift = labels.map(() => 0)
|
|
168
|
-
const kept: LabelBox[] = []
|
|
169
|
-
const rank = (l: RowLabel) => (l.holding ? 0 : l.span ? 2 : 1)
|
|
284
|
+
const kept: { box: LabelBox; tick: boolean }[] = []
|
|
285
|
+
const rank = (l: RowLabel) => (l.holding ? 0 : l.span ? 3 : l.end ? 2 : 1)
|
|
170
286
|
const order = labels
|
|
171
287
|
.map((_, i) => i)
|
|
172
288
|
.toSorted((a, b) => rank(labels[a] as RowLabel) - rank(labels[b] as RowLabel))
|
|
173
|
-
|
|
174
|
-
|
|
289
|
+
// The gap step applies when either label of a pair is a tick; zone names keep to "not touching".
|
|
290
|
+
const clears = (b: LabelBox, tick: boolean) =>
|
|
291
|
+
!kept.some(({ box: k, tick: kTick }) => {
|
|
292
|
+
const pad = tick || kTick ? gap : 0
|
|
293
|
+
return b.left < k.right + pad - LABEL_SUBPIXEL && k.left < b.right + pad - LABEL_SUBPIXEL
|
|
294
|
+
})
|
|
175
295
|
for (const i of order) {
|
|
176
296
|
const label = labels[i] as RowLabel
|
|
177
297
|
const { span } = label
|
|
298
|
+
const tick = span === undefined && !label.holding
|
|
178
299
|
let box = label.box
|
|
179
300
|
if (label.holding) {
|
|
180
301
|
const width = box.right - box.left
|
|
181
302
|
const left = Math.max(0, Math.min(box.left, rowWidth - width))
|
|
182
303
|
shift[i] = left - box.left
|
|
183
304
|
box = { left, right: left + width }
|
|
184
|
-
if (!clears(box)) continue
|
|
305
|
+
if (!clears(box, false)) continue
|
|
185
306
|
shown[i] = true
|
|
186
|
-
kept.push(box)
|
|
307
|
+
kept.push({ box, tick: false })
|
|
187
308
|
continue
|
|
188
309
|
}
|
|
189
310
|
const fits = (b: LabelBox) =>
|
|
@@ -191,13 +312,13 @@ export function placeRowLabels(labels: readonly RowLabel[], rowWidth: number): R
|
|
|
191
312
|
b.right <= rowWidth + LABEL_SUBPIXEL &&
|
|
192
313
|
(span === undefined ||
|
|
193
314
|
(b.left >= span.left - LABEL_SUBPIXEL && b.right <= span.right + LABEL_SUBPIXEL)) &&
|
|
194
|
-
clears(b)
|
|
315
|
+
clears(b, tick)
|
|
195
316
|
const useShort = !fits(box) && label.short !== undefined && fits(label.short)
|
|
196
317
|
if (useShort) box = label.short as LabelBox
|
|
197
318
|
else if (!fits(box)) continue
|
|
198
319
|
shown[i] = true
|
|
199
320
|
short[i] = useShort
|
|
200
|
-
kept.push(box)
|
|
321
|
+
kept.push({ box, tick })
|
|
201
322
|
}
|
|
202
323
|
return { shown, short, shift }
|
|
203
324
|
}
|
|
@@ -219,6 +340,7 @@ export type BarInput = {
|
|
|
219
340
|
format: Format
|
|
220
341
|
segments?: readonly MeterSegment[] | undefined
|
|
221
342
|
zones?: readonly MeterZone[] | undefined
|
|
343
|
+
stops?: readonly MeterStop[] | undefined
|
|
222
344
|
target?: number | undefined
|
|
223
345
|
ticks?: readonly MeterTick[] | undefined
|
|
224
346
|
color?: string | undefined
|
|
@@ -235,6 +357,8 @@ export type BarModel = {
|
|
|
235
357
|
captionMode: CaptionMode
|
|
236
358
|
/** Only in `parts` mode: one caption per part, in order. Empty otherwise. */
|
|
237
359
|
partCaptions: readonly PartCaption[]
|
|
360
|
+
/** The `stops` gradient's colour list; absent without `stops`. */
|
|
361
|
+
stopsCss: string | undefined
|
|
238
362
|
/** Only on a zoned track: every zone's name, in zone order. Empty otherwise. */
|
|
239
363
|
zoneLabels: readonly ZoneLabel[]
|
|
240
364
|
ticks: readonly TickMark[]
|
|
@@ -252,8 +376,8 @@ function endCaptionText(reading: number, target: number | undefined, format: For
|
|
|
252
376
|
return `Target ${format(target)}`
|
|
253
377
|
}
|
|
254
378
|
|
|
255
|
-
function fillParts(input: BarInput, span: number,
|
|
256
|
-
if (
|
|
379
|
+
function fillParts(input: BarInput, span: number, marked: boolean): Part[] {
|
|
380
|
+
if (marked) return []
|
|
257
381
|
if (input.segments !== undefined) return layoutSegments(input.segments, span)
|
|
258
382
|
const fill = { value: input.reading - input.min, label: '' }
|
|
259
383
|
return layoutSegments([input.color === undefined ? fill : { ...fill, color: input.color }], span)
|
|
@@ -270,6 +394,7 @@ function partCaptionsOf(parts: readonly Part[], format: Format): PartCaption[] {
|
|
|
270
394
|
label: p.label,
|
|
271
395
|
text: format(p.amount),
|
|
272
396
|
color: p.color,
|
|
397
|
+
startPct: toPct(p.start),
|
|
273
398
|
}))
|
|
274
399
|
}
|
|
275
400
|
|
|
@@ -294,13 +419,14 @@ export function startCaptionText(model: BarModel, override: ReactNode | undefine
|
|
|
294
419
|
}
|
|
295
420
|
|
|
296
421
|
export function modelBar(input: BarInput): BarModel {
|
|
297
|
-
const { reading, min, max, format, segments, zones, target } = input
|
|
422
|
+
const { reading, min, max, format, segments, zones, target, stops } = input
|
|
298
423
|
const ticks = tickMarks(input.ticks, min, max, format)
|
|
299
424
|
const { span } = spanOf(min, max)
|
|
300
425
|
const zoned = zones !== undefined && zones.length > 0
|
|
301
426
|
const holding = zoned ? findHoldingZone(zones, reading) : undefined
|
|
302
427
|
|
|
303
|
-
const
|
|
428
|
+
const striped = !zoned && stops !== undefined && stops.length > 0
|
|
429
|
+
const parts = fillParts(input, span, zoned || striped)
|
|
304
430
|
const firstForecast = parts.findIndex((p) => p.forecast)
|
|
305
431
|
const forecastLabels =
|
|
306
432
|
segments?.filter((s) => s.forecast === true).map((s) => `${s.label} ${format(s.value)}`) ?? []
|
|
@@ -333,6 +459,7 @@ export function modelBar(input: BarInput): BarModel {
|
|
|
333
459
|
: (input.forecastCaption ?? `Forecast: ${forecastLabels.join(', ')}`),
|
|
334
460
|
captionMode,
|
|
335
461
|
partCaptions,
|
|
462
|
+
stopsCss: striped ? stopsGradient(stops, min, span) : undefined,
|
|
336
463
|
zoneLabels: !zoned
|
|
337
464
|
? []
|
|
338
465
|
: zones.map((z, i) => {
|
|
@@ -347,7 +474,7 @@ export function modelBar(input: BarInput): BarModel {
|
|
|
347
474
|
}
|
|
348
475
|
}),
|
|
349
476
|
ticks,
|
|
350
|
-
markerPct: zoned ? toPct((reading - min) / span) : undefined,
|
|
477
|
+
markerPct: zoned || striped ? toPct((reading - min) / span) : undefined,
|
|
351
478
|
targetPct: target === undefined ? undefined : toPct((target - min) / span),
|
|
352
479
|
startText: format(reading),
|
|
353
480
|
endText: endCaptionText(reading, target, format),
|
|
@@ -358,3 +485,59 @@ export function modelBar(input: BarInput): BarModel {
|
|
|
358
485
|
/** The ring's one arc, as a fraction of the circumference. */
|
|
359
486
|
export const ringFraction = (reading: number, min: number, max: number): number =>
|
|
360
487
|
clamp01((reading - min) / spanOf(min, max).span)
|
|
488
|
+
|
|
489
|
+
/** One caption on the marks row: its natural width and where it is anchored (`pct`), else its edge. */
|
|
490
|
+
export type MarkItem = { width: number; pct?: number; edge?: 'end' }
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Where each caption of the marks row starts (px, logical start edge), index-aligned with `items`: an
|
|
494
|
+
* anchored caption is centred on its mark and clamped inside the row, the others sit at the start (or,
|
|
495
|
+
* `edge: 'end'`, the end). Two captions closer than `gap` are pushed apart, in order, the least that
|
|
496
|
+
* clears them, so a caption stays as near its mark as the row allows. `null` when nothing is anchored,
|
|
497
|
+
* the row is unmeasured, a caption is wider than the row, or the captions cannot all clear each other
|
|
498
|
+
* inside the row: the row then flows and wraps instead.
|
|
499
|
+
*/
|
|
500
|
+
export function placeMarkCaptions(
|
|
501
|
+
items: readonly MarkItem[],
|
|
502
|
+
rowWidth: number,
|
|
503
|
+
gap: number,
|
|
504
|
+
): number[] | null {
|
|
505
|
+
if (rowWidth <= 0 || !items.some((i) => i.pct !== undefined)) return null
|
|
506
|
+
if (items.some((i) => i.width > rowWidth)) return null
|
|
507
|
+
const lefts = items.map((i) => {
|
|
508
|
+
if (i.pct === undefined) return i.edge === 'end' ? rowWidth - i.width : 0
|
|
509
|
+
return Math.max(0, Math.min((rowWidth * i.pct) / 100 - i.width / 2, rowWidth - i.width))
|
|
510
|
+
})
|
|
511
|
+
const order = lefts.map((_, i) => i).toSorted((a, b) => (lefts[a] ?? 0) - (lefts[b] ?? 0))
|
|
512
|
+
const widthOf = (i: number) => items[i]?.width ?? 0
|
|
513
|
+
for (const [n, i] of order.entries()) {
|
|
514
|
+
const prev = order[n - 1]
|
|
515
|
+
if (prev !== undefined)
|
|
516
|
+
lefts[i] = Math.max(lefts[i] ?? 0, (lefts[prev] ?? 0) + widthOf(prev) + gap)
|
|
517
|
+
}
|
|
518
|
+
for (const [n, i] of order.toReversed().entries()) {
|
|
519
|
+
const next = order.toReversed()[n - 1]
|
|
520
|
+
const limit = next === undefined ? rowWidth : (lefts[next] ?? 0) - gap
|
|
521
|
+
lefts[i] = Math.min(lefts[i] ?? 0, limit - widthOf(i))
|
|
522
|
+
}
|
|
523
|
+
const first = order[0]
|
|
524
|
+
return first !== undefined && (lefts[first] ?? 0) < -LABEL_SUBPIXEL ? null : lefts
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Whether every categorical part's caption fits under its own segment: left-aligned at the part's
|
|
529
|
+
* start and ending before the next part's start (less `gap`) or the row's end. A zero-width part never fits.
|
|
530
|
+
*/
|
|
531
|
+
export function partsFitUnder(
|
|
532
|
+
parts: readonly { startPct: number; width: number }[],
|
|
533
|
+
rowWidth: number,
|
|
534
|
+
gap: number,
|
|
535
|
+
): boolean {
|
|
536
|
+
if (rowWidth <= 0) return false
|
|
537
|
+
return parts.every((p, i) => {
|
|
538
|
+
const left = (rowWidth * p.startPct) / 100
|
|
539
|
+
const next = parts[i + 1]
|
|
540
|
+
const limit = next === undefined ? rowWidth : (rowWidth * next.startPct) / 100 - gap
|
|
541
|
+
return left + p.width <= limit + LABEL_SUBPIXEL
|
|
542
|
+
})
|
|
543
|
+
}
|