basalt-ui 2.23.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/MIGRATING.md +225 -12
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +22 -19
- package/agent/skills/basalt-design/references/states.md +39 -0
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +17 -2
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +7 -3
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +32 -6
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +5 -1
- package/dist/charts/chart-legend.module.css +16 -0
- package/dist/charts/compile.d.ts +2 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +47 -3
- package/dist/charts/legend.d.ts +0 -6
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +87 -35
- package/dist/charts/sparkline.module.css +59 -6
- package/dist/charts/sparkline.module.css.d.ts +1 -0
- package/dist/charts/state.js +1 -1
- package/dist/charts/types.d.ts +11 -0
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +19 -23
- package/dist/dashboard/bar-list.module.css +3 -15
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/meter-model.d.ts +30 -1
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +74 -5
- package/dist/dashboard/meter-parts.d.ts +8 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +64 -21
- package/dist/dashboard/meter.d.ts +8 -1
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +14 -3
- package/dist/dashboard/meter.module.css +42 -2
- package/dist/dashboard/meter.module.css.d.ts +4 -0
- package/dist/dashboard/query-state.d.ts +7 -3
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +14 -6
- package/dist/dashboard/section.d.ts +2 -1
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.module.css +12 -0
- package/dist/dashboard/settings-section.d.ts +1 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +3 -3
- package/dist/dashboard/stat-card.module.css +24 -10
- package/dist/dashboard/stat-group.module.css +8 -0
- package/dist/dashboard/stat-strip.d.ts +3 -2
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +83 -73
- package/dist/dashboard/stat-strip.module.css +22 -38
- package/dist/dashboard/stat-strip.module.css.d.ts +1 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +19 -1
- package/dist/dashboard/widget-header.module.css +6 -0
- package/dist/guard/index.d.ts +2 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +1 -12
- package/dist/table/data-table.js +1 -1
- package/dist/theme/controls.module.css +7 -2
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +7 -5
- package/dist/tokens/palette.d.ts +2 -2
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +2 -2
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/src/charts/Bars.tsx +29 -2
- package/src/charts/CartesianChart.tsx +7 -3
- package/src/charts/Sparkline.tsx +66 -21
- package/src/charts/StackedArea.tsx +12 -1
- package/src/charts/chart-legend.module.css +16 -0
- package/src/charts/compile.ts +84 -2
- package/src/charts/legend.tsx +70 -3
- package/src/charts/sparkline.module.css +59 -6
- package/src/charts/sparkline.module.css.d.ts +1 -0
- package/src/charts/state.tsx +1 -1
- package/src/charts/types.ts +9 -0
- package/src/cli/shot/measure.ts +27 -27
- package/src/dashboard/bar-list.module.css +3 -15
- package/src/dashboard/empty-state.tsx +4 -2
- package/src/dashboard/meter-model.ts +124 -7
- package/src/dashboard/meter-parts.tsx +127 -31
- package/src/dashboard/meter.module.css +42 -2
- package/src/dashboard/meter.module.css.d.ts +4 -0
- package/src/dashboard/meter.tsx +22 -3
- package/src/dashboard/query-state.tsx +19 -8
- package/src/dashboard/section.module.css +12 -0
- package/src/dashboard/section.tsx +2 -1
- package/src/dashboard/settings-section.tsx +4 -4
- package/src/dashboard/stat-card.module.css +24 -10
- package/src/dashboard/stat-group.module.css +8 -0
- package/src/dashboard/stat-strip.module.css +22 -38
- package/src/dashboard/stat-strip.module.css.d.ts +1 -0
- package/src/dashboard/stat-strip.tsx +63 -43
- package/src/dashboard/widget-header.module.css +6 -0
- package/src/dashboard/widget-header.tsx +28 -1
- package/src/guard/index.ts +3 -14
- package/src/table/data-table.tsx +1 -1
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +6 -6
- package/src/theme/controls.module.css +7 -2
- package/src/theme/index.ts +7 -5
- package/src/tokens/palette.ts +2 -2
package/src/cli/shot/measure.ts
CHANGED
|
@@ -94,12 +94,12 @@ export function finishMeasurement({ texts, radius, nested, ...rest }: Reading):
|
|
|
94
94
|
/* oxlint-disable unicorn/consistent-function-scoping -- the helpers below are serialised into the page with it: no outer scope */
|
|
95
95
|
export function measureAnchor(root: Element): Reading {
|
|
96
96
|
const px = (v: string | number): number => Math.round(parseFloat(String(v)) * 100) / 100
|
|
97
|
-
const
|
|
98
|
-
top
|
|
99
|
-
|
|
100
|
-
bottom
|
|
101
|
-
left
|
|
102
|
-
}
|
|
97
|
+
const edges = (s: CSSStyleDeclaration, p: string, x = ''): number[] =>
|
|
98
|
+
['top', 'right', 'bottom', 'left'].map((e) => px(s.getPropertyValue(`${p}-${e}${x}`)))
|
|
99
|
+
const sides = (s: CSSStyleDeclaration): Measurement['padding'] => {
|
|
100
|
+
const [top = 0, right = 0, bottom = 0, left = 0] = edges(s, 'padding')
|
|
101
|
+
return { top, right, bottom, left }
|
|
102
|
+
}
|
|
103
103
|
const ctx = document.createElement('canvas').getContext('2d', { willReadFrequently: true })
|
|
104
104
|
if (!ctx) throw new Error('no 2d canvas context: cannot read colours')
|
|
105
105
|
const parsed = new Map<string, number[]>()
|
|
@@ -126,12 +126,13 @@ export function measureAnchor(root: Element): Reading {
|
|
|
126
126
|
const a = top[3] ?? 1
|
|
127
127
|
return [0, 1, 2, 3].map((i) => (i === 3 ? 1 : (top[i] ?? 0) * a + (under[i] ?? 0) * (1 - a)))
|
|
128
128
|
}
|
|
129
|
+
const shown = (s: CSSStyleDeclaration): boolean =>
|
|
130
|
+
s.visibility !== 'hidden' && s.display !== 'none' && s.opacity !== '0'
|
|
131
|
+
const fills = (s: CSSStyleDeclaration): boolean =>
|
|
132
|
+
shown(s) && s.content !== 'none' && (rgba(s.backgroundColor)[3] ?? 0) > 0
|
|
129
133
|
const visible = (el: Element): CSSStyleDeclaration | null => {
|
|
130
134
|
const s = getComputedStyle(el)
|
|
131
|
-
|
|
132
|
-
return s.visibility === 'hidden' || s.display === 'none' || s.opacity === '0' || r.width === 0
|
|
133
|
-
? null
|
|
134
|
-
: s
|
|
135
|
+
return shown(s) && el.getBoundingClientRect().width !== 0 ? s : null
|
|
135
136
|
}
|
|
136
137
|
/** The effective background: layers up to the first opaque ancestor (html/body included), composited. */
|
|
137
138
|
const backdrop = (el: Element): { color: number[]; assumedWhite: boolean } => {
|
|
@@ -148,18 +149,13 @@ export function measureAnchor(root: Element): Reading {
|
|
|
148
149
|
|
|
149
150
|
const cs = getComputedStyle(root)
|
|
150
151
|
const rect = root.getBoundingClientRect()
|
|
151
|
-
const widest = Math.max(
|
|
152
|
-
...['Top', 'Right', 'Bottom', 'Left'].map((e) =>
|
|
153
|
-
px(cs.getPropertyValue(`border-${e.toLowerCase()}-width`)),
|
|
154
|
-
),
|
|
155
|
-
)
|
|
152
|
+
const widest = Math.max(...edges(cs, 'border', '-width'))
|
|
156
153
|
|
|
157
154
|
// gap: the first flex/grid box (breadth-first) that actually spaces its children.
|
|
158
155
|
let gap = { row: 0, column: 0 }
|
|
159
156
|
const queue: Element[] = [root]
|
|
160
157
|
for (let i = 0; i < queue.length && i < 80; i++) {
|
|
161
|
-
const item = queue[i]
|
|
162
|
-
if (!item) break
|
|
158
|
+
const item = queue[i] as Element
|
|
163
159
|
const s = getComputedStyle(item)
|
|
164
160
|
const row = px(s.rowGap) || 0
|
|
165
161
|
const column = px(s.columnGap) || 0
|
|
@@ -187,22 +183,27 @@ export function measureAnchor(root: Element): Reading {
|
|
|
187
183
|
const s = visible(el)
|
|
188
184
|
if (!s) continue
|
|
189
185
|
const r = el.getBoundingClientRect()
|
|
190
|
-
const hasBg = (
|
|
191
|
-
const hasBorder =
|
|
192
|
-
(e) => px(s.getPropertyValue(`border-${e.toLowerCase()}-width`)) > 0,
|
|
193
|
-
)
|
|
186
|
+
const hasBg = fills(s)
|
|
187
|
+
const hasBorder = edges(s, 'border', '-width').some((w) => w > 0)
|
|
194
188
|
if (el !== root && (hasBg || hasBorder) && nested.length < 60) {
|
|
195
189
|
nested.push({
|
|
196
190
|
path: pathOf(el),
|
|
197
191
|
radius: { value: s.borderTopLeftRadius, width: px(r.width), height: px(r.height) },
|
|
198
|
-
padding: sides(s
|
|
192
|
+
padding: sides(s),
|
|
199
193
|
})
|
|
200
194
|
}
|
|
201
|
-
//
|
|
195
|
+
// Only boxes smaller than the anchor count (wrappers are layout); a pseudo fill is paint (Skeleton) only if it covers its host.
|
|
196
|
+
const pseudo = ['::before', '::after'].some((p) => {
|
|
197
|
+
const ps = getComputedStyle(el, p)
|
|
198
|
+
return (
|
|
199
|
+
fills(ps) &&
|
|
200
|
+
[px(ps.width) - r.width, px(ps.height) - r.height].every((d) => Math.abs(d) <= 2)
|
|
201
|
+
)
|
|
202
|
+
})
|
|
202
203
|
if (
|
|
203
204
|
el !== root &&
|
|
204
205
|
(/^(svg|img|canvas|video|input|textarea)$/i.test(el.tagName) ||
|
|
205
|
-
((hasBg || hasBorder) && r.height < rect.height * 0.9))
|
|
206
|
+
((hasBg || hasBorder || pseudo) && r.height < rect.height * 0.9))
|
|
206
207
|
) {
|
|
207
208
|
painted.push([r.top, r.bottom])
|
|
208
209
|
}
|
|
@@ -230,8 +231,7 @@ export function measureAnchor(root: Element): Reading {
|
|
|
230
231
|
}
|
|
231
232
|
|
|
232
233
|
// emptyRatio: the largest vertical run (edges included) with nothing painted in it.
|
|
233
|
-
const top = rect
|
|
234
|
-
const bottom = rect.bottom
|
|
234
|
+
const { top, bottom } = rect
|
|
235
235
|
let cursor = top
|
|
236
236
|
let longest = 0
|
|
237
237
|
for (const [a, b] of painted.toSorted((x, y) => x[0] - y[0])) {
|
|
@@ -244,7 +244,7 @@ export function measureAnchor(root: Element): Reading {
|
|
|
244
244
|
|
|
245
245
|
return {
|
|
246
246
|
box: { width: px(rect.width), height: px(rect.height) },
|
|
247
|
-
padding: sides(cs
|
|
247
|
+
padding: sides(cs),
|
|
248
248
|
gap,
|
|
249
249
|
radius: { value: cs.borderTopLeftRadius, width: px(rect.width), height: px(rect.height) },
|
|
250
250
|
borderWidth: widest,
|
|
@@ -228,22 +228,10 @@
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
/*
|
|
231
|
-
* A column of DeltaBadges:
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* a hero metric has no column to line up with (D33: tabular figures only in a table-like column).
|
|
231
|
+
* A column of DeltaBadges: glyph and figure are ONE unit, end-aligned as a whole, so the glyph never drifts
|
|
232
|
+
* from its figure however wide the column ("▲ 9%" and "▲13%" share their right edge and keep the badge's own
|
|
233
|
+
* gap). Tabular figures keep the right edges even (D33: only in a table-like column, not a hero metric).
|
|
235
234
|
*/
|
|
236
235
|
.secondary [data-delta] {
|
|
237
|
-
display: inline-grid;
|
|
238
|
-
grid-template-columns: 1em minmax(4ch, auto);
|
|
239
|
-
justify-items: end;
|
|
240
236
|
font-variant-numeric: tabular-nums;
|
|
241
237
|
}
|
|
242
|
-
|
|
243
|
-
.secondary [data-delta]:not(:has([data-delta-glyph]))::before {
|
|
244
|
-
content: '';
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
.secondary [data-delta-glyph] {
|
|
248
|
-
justify-self: center;
|
|
249
|
-
}
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* generous vertical padding for a full-page empty state; `tier="section"` is compact, for an
|
|
5
5
|
* empty card/panel region.
|
|
6
6
|
*
|
|
7
|
+
* Its copy says the cause and the next step, never a bare "No data".
|
|
8
|
+
*
|
|
7
9
|
* @example
|
|
8
10
|
* import { EmptyState } from 'basalt-ui'
|
|
9
11
|
*
|
|
10
12
|
* <EmptyState
|
|
11
13
|
* icon={<IconInboxEmpty />}
|
|
12
|
-
* title="No
|
|
13
|
-
* description="
|
|
14
|
+
* title="No decisions match"
|
|
15
|
+
* description="The queue is filtered to Blocked; clear it to see all 12."
|
|
14
16
|
* action={<Button onClick={onReset}>Clear filters</Button>}
|
|
15
17
|
* tier="section"
|
|
16
18
|
* />
|
|
@@ -320,6 +320,14 @@ export function placeRowLabels(
|
|
|
320
320
|
short[i] = useShort
|
|
321
321
|
kept.push({ box, tick })
|
|
322
322
|
}
|
|
323
|
+
// One register: once any name falls back to its `short`, every other shown name that has one
|
|
324
|
+
// follows (the holding name, which never shortens, is the one exception). A shorter box only
|
|
325
|
+
// clears more, so the placement above stays valid.
|
|
326
|
+
if (short.some(Boolean)) {
|
|
327
|
+
for (const [i, label] of labels.entries()) {
|
|
328
|
+
if (shown[i] && !label.holding && label.short !== undefined) short[i] = true
|
|
329
|
+
}
|
|
330
|
+
}
|
|
323
331
|
return { shown, short, shift }
|
|
324
332
|
}
|
|
325
333
|
|
|
@@ -363,6 +371,8 @@ export type BarModel = {
|
|
|
363
371
|
zoneLabels: readonly ZoneLabel[]
|
|
364
372
|
ticks: readonly TickMark[]
|
|
365
373
|
markerPct: number | undefined
|
|
374
|
+
/** Percent where the committed fill ends: the reading caption's anchor. Absent on a marked track. */
|
|
375
|
+
fillEndPct: number | undefined
|
|
366
376
|
targetPct: number | undefined
|
|
367
377
|
/** The default start caption (the zone is named on the band, so it is the bare reading); `startCaption` decides whether it shows. */
|
|
368
378
|
startText: string
|
|
@@ -475,6 +485,12 @@ export function modelBar(input: BarInput): BarModel {
|
|
|
475
485
|
}),
|
|
476
486
|
ticks,
|
|
477
487
|
markerPct: zoned || striped ? toPct((reading - min) / span) : undefined,
|
|
488
|
+
fillEndPct:
|
|
489
|
+
zoned || striped
|
|
490
|
+
? undefined
|
|
491
|
+
: toPct(
|
|
492
|
+
parts.filter((p) => !p.forecast).reduce((end, p) => Math.max(end, p.start + p.size), 0),
|
|
493
|
+
),
|
|
478
494
|
targetPct: target === undefined ? undefined : toPct((target - min) / span),
|
|
479
495
|
startText: format(reading),
|
|
480
496
|
endText: endCaptionText(reading, target, format),
|
|
@@ -486,8 +502,26 @@ export function modelBar(input: BarInput): BarModel {
|
|
|
486
502
|
export const ringFraction = (reading: number, min: number, max: number): number =>
|
|
487
503
|
clamp01((reading - min) / spanOf(min, max).span)
|
|
488
504
|
|
|
489
|
-
/**
|
|
490
|
-
|
|
505
|
+
/**
|
|
506
|
+
* One caption on the marks row: its natural width and where it is anchored (`pct`), else its edge.
|
|
507
|
+
* `align` is which edge of the caption sits on the mark (default: its centre). `drop` ranks it for
|
|
508
|
+
* dropping when the row is too narrow: the lowest rank goes first, none never drops.
|
|
509
|
+
*/
|
|
510
|
+
export type MarkItem = {
|
|
511
|
+
width: number
|
|
512
|
+
pct?: number
|
|
513
|
+
edge?: 'end'
|
|
514
|
+
align?: 'start' | 'center' | 'end'
|
|
515
|
+
drop?: number
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** Where a caption starts before any caption is pushed off it: on its mark, else at its edge. */
|
|
519
|
+
function idealLeft(i: MarkItem, rowWidth: number): number {
|
|
520
|
+
if (i.pct === undefined) return i.edge === 'end' ? rowWidth - i.width : 0
|
|
521
|
+
const at = (rowWidth * i.pct) / 100
|
|
522
|
+
const left = i.align === 'end' ? at - i.width : i.align === 'start' ? at : at - i.width / 2
|
|
523
|
+
return Math.max(0, Math.min(left, rowWidth - i.width))
|
|
524
|
+
}
|
|
491
525
|
|
|
492
526
|
/**
|
|
493
527
|
* Where each caption of the marks row starts (px, logical start edge), index-aligned with `items`: an
|
|
@@ -504,11 +538,13 @@ export function placeMarkCaptions(
|
|
|
504
538
|
): number[] | null {
|
|
505
539
|
if (rowWidth <= 0 || !items.some((i) => i.pct !== undefined)) return null
|
|
506
540
|
if (items.some((i) => i.width > rowWidth)) return null
|
|
507
|
-
const lefts = items.map((i) =>
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
const order = lefts
|
|
541
|
+
const lefts = items.map((i) => idealLeft(i, rowWidth))
|
|
542
|
+
// Captions keep their order along the track: by their mark (an edge caption by its edge), not by
|
|
543
|
+
// where clamping left them, so a reading near the end never ends up right of the target.
|
|
544
|
+
const markAt = (i: MarkItem) => i.pct ?? (i.edge === 'end' ? 100 : 0)
|
|
545
|
+
const order = lefts
|
|
546
|
+
.map((_, i) => i)
|
|
547
|
+
.toSorted((a, b) => markAt(items[a] as MarkItem) - markAt(items[b] as MarkItem) || a - b)
|
|
512
548
|
const widthOf = (i: number) => items[i]?.width ?? 0
|
|
513
549
|
for (const [n, i] of order.entries()) {
|
|
514
550
|
const prev = order[n - 1]
|
|
@@ -524,6 +560,87 @@ export function placeMarkCaptions(
|
|
|
524
560
|
return first !== undefined && (lefts[first] ?? 0) < -LABEL_SUBPIXEL ? null : lefts
|
|
525
561
|
}
|
|
526
562
|
|
|
563
|
+
/** The furthest a droppable caption may sit from its own mark (Wave 37 r2's "not far"); past it, it drops. */
|
|
564
|
+
export const MAX_CAPTION_SHIFT = 24
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* `placeMarkCaptions` with dropping: when the captions cannot all clear each other on one line, the
|
|
568
|
+
* droppable ones go one at a time in `drop` rank order (a caption without a rank never goes) until
|
|
569
|
+
* the rest fit. A droppable caption stays while it sits within `MAX_CAPTION_SHIFT` of its mark and
|
|
570
|
+
* moves no undroppable caption (the reading, the target) further than those move with every droppable
|
|
571
|
+
* one dropped: two undroppables that collide on their own are not a reason to drop anything.
|
|
572
|
+
* `starts[i]` is the start of caption `i`, `undefined` when it dropped; `dropped[i]` marks the drop.
|
|
573
|
+
* `null` when even the undroppable ones do not fit, so the row flows instead.
|
|
574
|
+
*/
|
|
575
|
+
export function placeCaptionRow(
|
|
576
|
+
items: readonly MarkItem[],
|
|
577
|
+
rowWidth: number,
|
|
578
|
+
gap: number,
|
|
579
|
+
): { starts: (number | undefined)[]; dropped: boolean[] } | null {
|
|
580
|
+
const fixed = items.map((_, i) => i).filter((i) => items[i]?.drop === undefined)
|
|
581
|
+
const baseline = placeMarkCaptions(
|
|
582
|
+
fixed.map((i) => items[i] as MarkItem),
|
|
583
|
+
rowWidth,
|
|
584
|
+
gap,
|
|
585
|
+
)
|
|
586
|
+
if (baseline === null) return null
|
|
587
|
+
const allowed = new Map(
|
|
588
|
+
fixed.map((i, n) => [
|
|
589
|
+
i,
|
|
590
|
+
Math.abs((baseline[n] ?? 0) - idealLeft(items[i] as MarkItem, rowWidth)) + LABEL_SUBPIXEL,
|
|
591
|
+
]),
|
|
592
|
+
)
|
|
593
|
+
const dropped = items.map(() => false)
|
|
594
|
+
const order = items
|
|
595
|
+
.map((item, i) => ({ rank: item.drop, i }))
|
|
596
|
+
.filter((d): d is { rank: number; i: number } => d.rank !== undefined)
|
|
597
|
+
.toSorted((a, b) => a.rank - b.rank)
|
|
598
|
+
for (let step = 0; step <= order.length; step++) {
|
|
599
|
+
const kept = items.map((_, i) => i).filter((i) => !dropped[i])
|
|
600
|
+
const lefts = placeMarkCaptions(
|
|
601
|
+
kept.map((i) => items[i] as MarkItem),
|
|
602
|
+
rowWidth,
|
|
603
|
+
gap,
|
|
604
|
+
)
|
|
605
|
+
const settled =
|
|
606
|
+
lefts !== null &&
|
|
607
|
+
(step === order.length ||
|
|
608
|
+
kept.every((i, n) => {
|
|
609
|
+
const item = items[i] as MarkItem
|
|
610
|
+
const moved = Math.abs((lefts[n] ?? 0) - idealLeft(item, rowWidth))
|
|
611
|
+
if (item.drop === undefined) return moved <= (allowed.get(i) ?? 0)
|
|
612
|
+
return item.pct === undefined || moved <= MAX_CAPTION_SHIFT
|
|
613
|
+
}))
|
|
614
|
+
if (lefts !== null && settled) {
|
|
615
|
+
const starts = items.map((): number | undefined => undefined)
|
|
616
|
+
for (const [n, i] of kept.entries()) starts[i] = lefts[n]
|
|
617
|
+
return { starts, dropped }
|
|
618
|
+
}
|
|
619
|
+
const next = order[step]
|
|
620
|
+
if (next === undefined) return null
|
|
621
|
+
dropped[next.i] = true
|
|
622
|
+
}
|
|
623
|
+
return null
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* How many columns the categorical part captions take when they do not fit under their segments:
|
|
628
|
+
* the most columns whose widest-per-column entries fit the row, with no lone entry on the last row
|
|
629
|
+
* (`n % cols === 1`). All in one row when they fit; one column is always valid.
|
|
630
|
+
*/
|
|
631
|
+
export function partColumns(widths: readonly number[], rowWidth: number, gap: number): number {
|
|
632
|
+
const n = widths.length
|
|
633
|
+
for (let cols = n; cols > 1; cols--) {
|
|
634
|
+
if (n > cols && n % cols === 1) continue
|
|
635
|
+
const widest = Array.from({ length: cols }, (_, c) =>
|
|
636
|
+
Math.max(0, ...widths.filter((_w, i) => i % cols === c)),
|
|
637
|
+
)
|
|
638
|
+
const total = widest.reduce((a, b) => a + b, 0) + gap * (cols - 1)
|
|
639
|
+
if (total <= rowWidth + LABEL_SUBPIXEL) return cols
|
|
640
|
+
}
|
|
641
|
+
return 1
|
|
642
|
+
}
|
|
643
|
+
|
|
527
644
|
/**
|
|
528
645
|
* Whether every categorical part's caption fits under its own segment: left-aligned at the part's
|
|
529
646
|
* start and ending before the next part's start (less `gap`) or the row's end. A zero-width part never fits.
|
|
@@ -7,8 +7,9 @@ import { cx } from '../common/props'
|
|
|
7
7
|
import {
|
|
8
8
|
ariaValues,
|
|
9
9
|
modelBar,
|
|
10
|
+
partColumns,
|
|
10
11
|
partsFitUnder,
|
|
11
|
-
|
|
12
|
+
placeCaptionRow,
|
|
12
13
|
placeRowLabels,
|
|
13
14
|
ringFraction,
|
|
14
15
|
ringMarks,
|
|
@@ -126,13 +127,31 @@ const glueUnits = (text: ReactNode): ReactNode =>
|
|
|
126
127
|
const glue = (text: ReactNode): ReactNode =>
|
|
127
128
|
typeof text === 'string' ? String(glueUnits(text)).replace(SHORT_LAST_WORD, '$1\u00a0$2') : text
|
|
128
129
|
|
|
130
|
+
/**
|
|
131
|
+
* One caption-height line, so a placeholder row stands where the loaded Meter's caption, figure or
|
|
132
|
+
* zone-name row will (a zoned track's rows are `1.25em`, as its label rows). Not announced; the root carries the state.
|
|
133
|
+
*/
|
|
134
|
+
function Line({ zoned, children }: { zoned: boolean; children?: ReactNode }) {
|
|
135
|
+
return (
|
|
136
|
+
<div className={cx(classes.line, zoned && classes.lineZoned)} data-meter-line aria-hidden>
|
|
137
|
+
{children}
|
|
138
|
+
</div>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The loaded Meter's footprint at its loaded height: a zoned track keeps the figure row above and the
|
|
144
|
+
* zone-name row below, a plain bar the caption row below, so the card does not jump when data lands.
|
|
145
|
+
*/
|
|
129
146
|
export function MeterLoading({
|
|
130
147
|
label,
|
|
131
148
|
ring,
|
|
149
|
+
zoned,
|
|
132
150
|
shell,
|
|
133
151
|
}: {
|
|
134
152
|
label: string
|
|
135
153
|
ring: boolean
|
|
154
|
+
zoned: boolean
|
|
136
155
|
shell: Shell
|
|
137
156
|
}) {
|
|
138
157
|
return (
|
|
@@ -142,8 +161,15 @@ export function MeterLoading({
|
|
|
142
161
|
<Skeleton className={classes.skeletonRing} circle />
|
|
143
162
|
) : (
|
|
144
163
|
<>
|
|
164
|
+
{zoned && (
|
|
165
|
+
<Line zoned={zoned}>
|
|
166
|
+
<Skeleton className={classes.skeletonCaption} radius="sm" />
|
|
167
|
+
</Line>
|
|
168
|
+
)}
|
|
145
169
|
<Skeleton className={classes.skeletonTrack} />
|
|
146
|
-
<
|
|
170
|
+
<Line zoned={zoned}>
|
|
171
|
+
<Skeleton className={classes.skeletonCaption} radius="sm" />
|
|
172
|
+
</Line>
|
|
147
173
|
</>
|
|
148
174
|
)}
|
|
149
175
|
</div>
|
|
@@ -156,11 +182,13 @@ export function MeterEmpty(props: {
|
|
|
156
182
|
label: string
|
|
157
183
|
text: string | undefined
|
|
158
184
|
ring: boolean
|
|
185
|
+
zoned: boolean
|
|
159
186
|
shell: Shell
|
|
160
187
|
}) {
|
|
161
|
-
const { label, text, ring, shell } = props
|
|
162
|
-
// The ring has a reading slot (its centre), so the dash sits there as the reading
|
|
163
|
-
//
|
|
188
|
+
const { label, text, ring, zoned, shell } = props
|
|
189
|
+
// The ring has a reading slot (its centre), so the dash sits there as the reading. A bar states its
|
|
190
|
+
// gap once, and only if the host says so (`text`): otherwise the caption rows a loaded Meter would
|
|
191
|
+
// have stay blank, so the muted track keeps the loaded height without a dash under it.
|
|
164
192
|
return (
|
|
165
193
|
<output {...rootProps(shell)} aria-label={label}>
|
|
166
194
|
{ring ? (
|
|
@@ -169,12 +197,22 @@ export function MeterEmpty(props: {
|
|
|
169
197
|
<span className={classes.ringValue}>{EMPTY_READING}</span>
|
|
170
198
|
</span>
|
|
171
199
|
) : (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
200
|
+
<>
|
|
201
|
+
{zoned && !shell.row && <Line zoned />}
|
|
202
|
+
<div className={classes.trackBox}>
|
|
203
|
+
<div className={classes.track} data-meter-track />
|
|
204
|
+
</div>
|
|
205
|
+
</>
|
|
175
206
|
)}
|
|
176
|
-
{
|
|
177
|
-
<span className={classes.empty}>{text
|
|
207
|
+
{text !== undefined ? (
|
|
208
|
+
<span className={classes.empty}>{text}</span>
|
|
209
|
+
) : (
|
|
210
|
+
!ring && (
|
|
211
|
+
<>
|
|
212
|
+
<VisuallyHidden className={classes.summary}>No reading</VisuallyHidden>
|
|
213
|
+
{!shell.row && <Line zoned={zoned} />}
|
|
214
|
+
</>
|
|
215
|
+
)
|
|
178
216
|
)}
|
|
179
217
|
</output>
|
|
180
218
|
)
|
|
@@ -450,19 +488,33 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
450
488
|
}
|
|
451
489
|
|
|
452
490
|
/** One caption of the marks row, in flow order: its anchor (`pct`, or the row's `edge`) when it has one. */
|
|
453
|
-
type CaptionItem = {
|
|
491
|
+
type CaptionItem = {
|
|
492
|
+
key: string
|
|
493
|
+
node: ReactNode
|
|
494
|
+
pct?: number
|
|
495
|
+
edge?: 'end'
|
|
496
|
+
end?: boolean
|
|
497
|
+
/** The default target figure: one line, never wrapped. */
|
|
498
|
+
target?: boolean
|
|
499
|
+
align?: 'start' | 'center' | 'end'
|
|
500
|
+
/** Drop rank when the row is too narrow (lowest first); none never drops. */
|
|
501
|
+
drop?: number
|
|
502
|
+
}
|
|
454
503
|
|
|
455
504
|
/** The measurement shared by the marks row and the part list: natural widths, row width, gap step. */
|
|
456
505
|
function measureItems(row: HTMLElement) {
|
|
457
506
|
const kids = [...row.children] as HTMLElement[]
|
|
458
507
|
const widths = kids.map((kid) => {
|
|
459
508
|
// In the flow a caption may shrink and wrap inside itself; its anchored width is its one-line one.
|
|
460
|
-
const { whiteSpace, flex } = kid.style
|
|
509
|
+
const { whiteSpace, flex, width: inline } = kid.style
|
|
461
510
|
kid.style.whiteSpace = 'nowrap'
|
|
462
511
|
kid.style.flex = 'none'
|
|
512
|
+
// A grid cell would clamp the box to its column; the natural width is what is measured.
|
|
513
|
+
kid.style.width = 'max-content'
|
|
463
514
|
const width = kid.offsetWidth
|
|
464
515
|
kid.style.whiteSpace = whiteSpace
|
|
465
516
|
kid.style.flex = flex
|
|
517
|
+
kid.style.width = inline
|
|
466
518
|
return width
|
|
467
519
|
})
|
|
468
520
|
return { widths, rowWidth: row.clientWidth, gap: columnGapOf(row) }
|
|
@@ -502,17 +554,24 @@ function useMeasured(
|
|
|
502
554
|
}, [rowRef, key])
|
|
503
555
|
}
|
|
504
556
|
|
|
505
|
-
|
|
506
|
-
|
|
557
|
+
type CaptionPlacement = { starts: (number | undefined)[]; dropped: boolean[] }
|
|
558
|
+
const samePlacement = (a: CaptionPlacement | null, b: CaptionPlacement | null) =>
|
|
559
|
+
a === b ||
|
|
560
|
+
(a !== null &&
|
|
561
|
+
b !== null &&
|
|
562
|
+
a.starts.length === b.starts.length &&
|
|
563
|
+
a.starts.every((v, i) => v === b.starts[i] && a.dropped[i] === b.dropped[i]))
|
|
507
564
|
|
|
508
565
|
/**
|
|
509
566
|
* The captions under the track. A caption that names a mark (the forecast boundary, the target) sits
|
|
510
|
-
* AT that mark, centred and clamped inside the track
|
|
511
|
-
*
|
|
567
|
+
* AT that mark, centred and clamped inside the track (the reading ends at its fill end), when every
|
|
568
|
+
* caption fits with a gap step between them. A row that is too narrow drops its droppable captions
|
|
569
|
+
* (`drop` rank, lowest first) before anything wraps; they stay in the described-by text. Only when
|
|
570
|
+
* even the rest do not fit (and in server markup) the row flows and wraps: start, forecast, end.
|
|
512
571
|
*/
|
|
513
572
|
function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
514
573
|
const rowRef = useRef<HTMLDivElement>(null)
|
|
515
|
-
const [
|
|
574
|
+
const [placed, setPlaced] = useState<CaptionPlacement | null>(null)
|
|
516
575
|
useMeasured(
|
|
517
576
|
rowRef,
|
|
518
577
|
(row) => {
|
|
@@ -521,26 +580,36 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
|
521
580
|
width: widths[i] ?? 0,
|
|
522
581
|
...(item.pct !== undefined && { pct: item.pct }),
|
|
523
582
|
...(item.edge !== undefined && { edge: item.edge }),
|
|
583
|
+
...(item.align !== undefined && { align: item.align }),
|
|
584
|
+
...(item.drop !== undefined && { drop: item.drop }),
|
|
524
585
|
}))
|
|
525
|
-
const next =
|
|
526
|
-
|
|
586
|
+
const next = placeCaptionRow(marks, rowWidth, gap)
|
|
587
|
+
setPlaced((prev) => (samePlacement(prev, next) ? prev : next))
|
|
527
588
|
},
|
|
528
589
|
items
|
|
529
|
-
.map(
|
|
590
|
+
.map(
|
|
591
|
+
(i) =>
|
|
592
|
+
`${i.key}@${i.pct ?? i.edge ?? ''}${i.align ?? ''}${i.drop ?? ''}:${typeof i.node === 'string' ? i.node : ''}`,
|
|
593
|
+
)
|
|
530
594
|
.join('\u0000'),
|
|
531
595
|
)
|
|
532
596
|
return (
|
|
533
597
|
<div
|
|
534
598
|
ref={rowRef}
|
|
535
|
-
className={cx(classes.captions,
|
|
599
|
+
className={cx(classes.captions, placed !== null && classes.captionsAnchored)}
|
|
536
600
|
data-meter-captions
|
|
537
|
-
data-anchored={
|
|
601
|
+
data-anchored={placed === null ? undefined : ''}
|
|
538
602
|
>
|
|
539
603
|
{items.map((item, i) => (
|
|
540
604
|
<span
|
|
541
605
|
key={item.key}
|
|
542
|
-
className={
|
|
543
|
-
|
|
606
|
+
className={
|
|
607
|
+
item.target ? classes.captionTarget : item.end ? classes.captionEnd : classes.caption
|
|
608
|
+
}
|
|
609
|
+
data-hidden={placed?.dropped[i] ? '' : undefined}
|
|
610
|
+
{...(placed?.starts[i] !== undefined && {
|
|
611
|
+
style: { insetInlineStart: `${placed.starts[i]}px` },
|
|
612
|
+
})}
|
|
544
613
|
>
|
|
545
614
|
{item.node}
|
|
546
615
|
</span>
|
|
@@ -551,13 +620,15 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
|
551
620
|
|
|
552
621
|
/**
|
|
553
622
|
* Categorical part captions (swatch, name, value): each under its own segment when every one fits
|
|
554
|
-
* there on one line, else a
|
|
555
|
-
*
|
|
623
|
+
* there on one line, else a grid from the track's start: one row when every entry fits it, else
|
|
624
|
+
* the most columns that fit with no lone entry on the last row. An entry stays on one line unless
|
|
625
|
+
* it is wider than the row itself.
|
|
556
626
|
*/
|
|
557
627
|
function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
|
|
558
628
|
const rowRef = useRef<HTMLUListElement>(null)
|
|
559
629
|
const [under, setUnder] = useState(false)
|
|
560
630
|
const [overwide, setOverwide] = useState(false)
|
|
631
|
+
const [cols, setCols] = useState(0)
|
|
561
632
|
useMeasured(
|
|
562
633
|
rowRef,
|
|
563
634
|
(row) => {
|
|
@@ -569,6 +640,7 @@ function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
|
|
|
569
640
|
gap,
|
|
570
641
|
)
|
|
571
642
|
setUnder(fits)
|
|
643
|
+
setCols(fits ? 0 : partColumns(widths, rowWidth, gap))
|
|
572
644
|
},
|
|
573
645
|
captions.map((c) => `${c.label} ${c.text}@${c.startPct}`).join('\u0000'),
|
|
574
646
|
)
|
|
@@ -579,7 +651,11 @@ function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
|
|
|
579
651
|
classes.partCaptions,
|
|
580
652
|
under && classes.partCaptionsUnder,
|
|
581
653
|
overwide && classes.partCaptionsWrap,
|
|
654
|
+
cols > 0 && classes.partCaptionsGrid,
|
|
582
655
|
)}
|
|
656
|
+
style={
|
|
657
|
+
cols > 0 ? { gridTemplateColumns: `repeat(${cols}, minmax(0, max-content))` } : undefined
|
|
658
|
+
}
|
|
583
659
|
// The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
584
660
|
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
585
661
|
role="list"
|
|
@@ -623,6 +699,7 @@ export function MeterBar(props: {
|
|
|
623
699
|
forecastCaption: string | undefined
|
|
624
700
|
startCaption: ReactNode
|
|
625
701
|
endCaption: ReactNode
|
|
702
|
+
readingAt: 'fill' | 'start' | undefined
|
|
626
703
|
shell: Shell
|
|
627
704
|
}) {
|
|
628
705
|
const { label, min, max, format, zones, shell } = props
|
|
@@ -675,6 +752,11 @@ export function MeterBar(props: {
|
|
|
675
752
|
...labelled,
|
|
676
753
|
]
|
|
677
754
|
const zoneLabels = compact ? [] : model.zoneLabels
|
|
755
|
+
// On a zoned track the zone names own the row below; the figures at its two ends sit above the
|
|
756
|
+
// track, where nothing else competes for them. Every other tick label stays with the names.
|
|
757
|
+
const isEnd = (t: TickMark) => t.pct <= 0 || t.pct >= 100
|
|
758
|
+
const aboveTicks = zoneLabels.length > 0 ? tickLabels.filter(isEnd) : tickLabels
|
|
759
|
+
const belowTicks = zoneLabels.length > 0 ? tickLabels.filter((t) => !isEnd(t)) : []
|
|
678
760
|
const describedBy =
|
|
679
761
|
model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
|
|
680
762
|
|
|
@@ -687,13 +769,27 @@ export function MeterBar(props: {
|
|
|
687
769
|
? []
|
|
688
770
|
: [
|
|
689
771
|
...(start !== null && !anchored
|
|
690
|
-
? [
|
|
772
|
+
? [
|
|
773
|
+
{
|
|
774
|
+
key: 'start',
|
|
775
|
+
node: glue(start),
|
|
776
|
+
// The reading sits at its fill's end (clamped inside the track); `readingAt="start"` keeps the old start edge.
|
|
777
|
+
...(props.readingAt !== 'start' &&
|
|
778
|
+
model.fillEndPct !== undefined && {
|
|
779
|
+
pct: model.fillEndPct,
|
|
780
|
+
align: 'end' as const,
|
|
781
|
+
}),
|
|
782
|
+
} satisfies CaptionItem,
|
|
783
|
+
]
|
|
691
784
|
: []),
|
|
692
785
|
...(model.forecastText !== null
|
|
693
786
|
? [
|
|
694
787
|
{
|
|
695
788
|
key: 'forecast',
|
|
696
789
|
node: glue(model.forecastText),
|
|
790
|
+
drop: 2,
|
|
791
|
+
// The reading ends at the boundary, the forecast begins there.
|
|
792
|
+
...(props.readingAt !== 'start' && start !== null && { align: 'start' as const }),
|
|
697
793
|
...(model.boundaryPct !== undefined && { pct: model.boundaryPct }),
|
|
698
794
|
} satisfies CaptionItem,
|
|
699
795
|
]
|
|
@@ -708,6 +804,7 @@ export function MeterBar(props: {
|
|
|
708
804
|
key: `tick${t.key}`,
|
|
709
805
|
node: glue(t.caption),
|
|
710
806
|
pct: t.pct,
|
|
807
|
+
drop: 1,
|
|
711
808
|
} satisfies CaptionItem,
|
|
712
809
|
],
|
|
713
810
|
)),
|
|
@@ -717,6 +814,7 @@ export function MeterBar(props: {
|
|
|
717
814
|
key: 'end',
|
|
718
815
|
node: glue(end),
|
|
719
816
|
end: true,
|
|
817
|
+
...(targetHere && { target: true }),
|
|
720
818
|
...(targetHere && model.targetPct !== undefined
|
|
721
819
|
? { pct: model.targetPct }
|
|
722
820
|
: { edge: 'end' as const }),
|
|
@@ -728,9 +826,7 @@ export function MeterBar(props: {
|
|
|
728
826
|
const root = rootProps(shell)
|
|
729
827
|
return (
|
|
730
828
|
<div {...root} className={root.className}>
|
|
731
|
-
{
|
|
732
|
-
<LabelRow zones={zoneLabels} ticks={tickLabels} />
|
|
733
|
-
)}
|
|
829
|
+
{aboveTicks.length > 0 && <LabelRow zones={[]} ticks={aboveTicks} />}
|
|
734
830
|
<div
|
|
735
831
|
className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
|
|
736
832
|
data-meter-track-hidden={trackHidden ? '' : undefined}
|
|
@@ -781,7 +877,7 @@ export function MeterBar(props: {
|
|
|
781
877
|
))}
|
|
782
878
|
<Tick kind="target" className={classes.tick} pct={model.targetPct} />
|
|
783
879
|
</div>
|
|
784
|
-
{zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={
|
|
880
|
+
{zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={belowTicks} />}
|
|
785
881
|
{anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
|
|
786
882
|
{model.describedByText !== null && (
|
|
787
883
|
<VisuallyHidden id={describedId} className={classes.summary}>
|