basalt-ui 2.27.2 → 2.28.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 +99 -0
- package/MIGRATING.md +168 -12
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-tokens.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +40 -36
- package/agent/skills/basalt-design/references/recipes.md +47 -0
- package/configs/oxlint-basalt.json +2 -1
- package/configs/oxlint-plugin.js +110 -2
- package/configs/oxlint-plugin.test.ts +99 -4
- package/dist/agent/chat/thread-message.d.ts +1 -160
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +7 -162
- package/dist/agent/chat/virtualize.d.ts +5 -5
- package/dist/charts/ChartCard.d.ts +5 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +46 -13
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +11 -4
- package/dist/charts/Sparkline.d.ts +9 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +104 -41
- package/dist/charts/chart-box.module.css +50 -0
- package/dist/charts/chart-box.module.css.d.ts +5 -0
- package/dist/charts/chart-card.module.css +12 -4
- package/dist/charts/chart-card.module.css.d.ts +1 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +20 -18
- package/dist/charts/labels.d.ts +13 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +131 -20
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +1 -1
- package/dist/charts/ref-label.d.ts +31 -8
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +40 -9
- package/dist/charts/sparkline.module.css +6 -0
- package/dist/charts/state.d.ts +3 -3
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +20 -2
- package/dist/cli/shot/capture.d.ts +6 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +18 -5
- package/dist/common/empty-copy.d.ts +16 -0
- package/dist/common/empty-copy.d.ts.map +1 -0
- package/dist/common/empty-copy.js +9 -0
- package/dist/common/virtual-rows.d.ts +196 -0
- package/dist/common/virtual-rows.d.ts.map +1 -0
- package/dist/common/virtual-rows.js +290 -0
- package/dist/controls/controls.module.css +33 -1
- package/dist/controls/controls.module.css.d.ts +2 -0
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -2
- package/dist/controls/filter-pill.d.ts +27 -3
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +15 -4
- package/dist/controls/form-layout.d.ts +9 -3
- package/dist/controls/form-layout.d.ts.map +1 -1
- package/dist/controls/form-layout.js +74 -12
- package/dist/controls/form-layout.module.css +112 -7
- package/dist/controls/form-layout.module.css.d.ts +1 -0
- package/dist/controls/multi-select-filter.d.ts +2 -2
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +12 -6
- package/dist/controls/range-filter.d.ts +1 -1
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +8 -2
- package/dist/dashboard/bar-list.d.ts +1 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +6 -2
- package/dist/dashboard/bar-list.module.css +0 -2
- package/dist/dashboard/board-nav.d.ts +22 -0
- package/dist/dashboard/board-nav.d.ts.map +1 -0
- package/dist/dashboard/board-nav.js +49 -0
- package/dist/dashboard/board.d.ts +52 -0
- package/dist/dashboard/board.d.ts.map +1 -0
- package/dist/dashboard/board.js +228 -0
- package/dist/dashboard/board.module.css +160 -0
- package/dist/dashboard/board.module.css.d.ts +26 -0
- package/dist/dashboard/empty-state.d.ts +3 -3
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +13 -6
- package/dist/dashboard/event-list-model.d.ts +51 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -0
- package/dist/dashboard/event-list-model.js +72 -0
- package/dist/dashboard/event-list-rows.d.ts +23 -0
- package/dist/dashboard/event-list-rows.d.ts.map +1 -0
- package/dist/dashboard/event-list-rows.js +93 -0
- package/dist/dashboard/event-list-scroll.d.ts +27 -0
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
- package/dist/dashboard/event-list-scroll.js +103 -0
- package/dist/dashboard/event-list-skeleton.d.ts +10 -0
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
- package/dist/dashboard/event-list-skeleton.js +36 -0
- package/dist/dashboard/event-list.d.ts +65 -0
- package/dist/dashboard/event-list.d.ts.map +1 -0
- package/dist/dashboard/event-list.js +178 -0
- package/dist/dashboard/event-list.module.css +283 -0
- package/dist/dashboard/event-list.module.css.d.ts +33 -0
- 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-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +5 -3
- package/dist/dashboard/meter.module.css +2 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/settings-section.d.ts +4 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +1 -1
- package/dist/dashboard/settings-section.module.css +19 -4
- package/dist/dashboard/stat-card-parts.d.ts +5 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +8 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +25 -6
- package/dist/dashboard/stat-card.module.css +31 -7
- package/dist/dashboard/stat-card.module.css.d.ts +3 -0
- package/dist/dashboard/stat-strip.module.css +4 -1
- package/dist/dashboard/widget-header.module.css +17 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/shell/app-main.module.css +18 -0
- package/dist/styles.css +46 -0
- package/dist/surfaces.d.ts +2 -2
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +8 -2
- package/dist/table/cell-kinds.d.ts +44 -0
- package/dist/table/cell-kinds.d.ts.map +1 -0
- package/dist/table/cell-kinds.js +169 -0
- package/dist/table/cell-kinds.module.css +55 -0
- package/dist/table/cell-kinds.module.css.d.ts +15 -0
- package/dist/table/data-table-fold.d.ts +147 -0
- package/dist/table/data-table-fold.d.ts.map +1 -0
- package/dist/table/data-table-fold.js +288 -0
- package/dist/table/data-table-state.d.ts +10 -3
- package/dist/table/data-table-state.d.ts.map +1 -1
- package/dist/table/data-table-state.js +11 -6
- package/dist/table/data-table.d.ts +11 -26
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +354 -254
- package/dist/table/data-table.module.css +210 -3
- package/dist/table/data-table.module.css.d.ts +12 -0
- package/dist/table/table-features.d.ts +34 -4
- package/dist/table/table-features.d.ts.map +1 -1
- package/dist/table/table-features.js +10 -0
- package/dist/theme/card-inset.module.css +35 -0
- package/dist/theme/controls.module.css +32 -0
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +5 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +14 -10
- package/dist/tokens/core.d.ts +1 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +1 -0
- package/dist/tokens/derive.js +1 -1
- package/dist/tokens/palette.d.ts +2 -1
- package/dist/tokens/palette.d.ts.map +1 -1
- package/llms.txt +34 -5
- package/package.json +1 -1
- package/src/agent/chat/thread-message.tsx +10 -403
- package/src/agent/chat/virtualize.ts +5 -5
- package/src/charts/ChartCard.tsx +79 -17
- package/src/charts/Lines.tsx +13 -4
- package/src/charts/Sparkline.tsx +131 -45
- package/src/charts/chart-box.module.css +50 -0
- package/src/charts/chart-box.module.css.d.ts +5 -0
- package/src/charts/chart-card.module.css +12 -4
- package/src/charts/chart-card.module.css.d.ts +1 -0
- package/src/charts/compile.ts +22 -18
- package/src/charts/labels.ts +175 -24
- package/src/charts/legend.tsx +3 -2
- package/src/charts/ref-label.ts +86 -17
- package/src/charts/sparkline.module.css +6 -0
- package/src/charts/state.tsx +36 -7
- package/src/cli/shot/capture.ts +29 -6
- package/src/common/empty-copy.ts +17 -0
- package/src/common/virtual-rows.tsx +682 -0
- package/src/controls/controls.module.css +33 -1
- package/src/controls/controls.module.css.d.ts +2 -0
- package/src/controls/enum-filter.tsx +8 -2
- package/src/controls/filter-pill.tsx +80 -27
- package/src/controls/form-layout.module.css +112 -7
- package/src/controls/form-layout.module.css.d.ts +1 -0
- package/src/controls/form-layout.tsx +115 -22
- package/src/controls/multi-select-filter.tsx +22 -11
- package/src/controls/range-filter.tsx +9 -3
- package/src/dashboard/bar-list.module.css +0 -2
- package/src/dashboard/bar-list.tsx +8 -5
- package/src/dashboard/board-nav.ts +67 -0
- package/src/dashboard/board.module.css +160 -0
- package/src/dashboard/board.module.css.d.ts +26 -0
- package/src/dashboard/board.tsx +394 -0
- package/src/dashboard/empty-state.tsx +16 -9
- package/src/dashboard/event-list-model.ts +113 -0
- package/src/dashboard/event-list-rows.tsx +120 -0
- package/src/dashboard/event-list-scroll.ts +145 -0
- package/src/dashboard/event-list-skeleton.tsx +58 -0
- package/src/dashboard/event-list.module.css +283 -0
- package/src/dashboard/event-list.module.css.d.ts +33 -0
- package/src/dashboard/event-list.tsx +309 -0
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-parts.tsx +9 -2
- package/src/dashboard/meter.module.css +2 -1
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/settings-section.module.css +19 -4
- package/src/dashboard/settings-section.tsx +7 -2
- package/src/dashboard/stat-card-parts.tsx +20 -3
- package/src/dashboard/stat-card.module.css +31 -7
- package/src/dashboard/stat-card.module.css.d.ts +3 -0
- package/src/dashboard/stat-card.tsx +24 -5
- package/src/dashboard/stat-strip.module.css +4 -1
- package/src/dashboard/widget-header.module.css +17 -1
- package/src/guard/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/shell/app-main.module.css +18 -0
- package/src/styles.css +46 -0
- package/src/surfaces.ts +7 -1
- package/src/table/cell-kinds.module.css +55 -0
- package/src/table/cell-kinds.module.css.d.ts +15 -0
- package/src/table/cell-kinds.tsx +234 -0
- package/src/table/data-table-fold.tsx +514 -0
- package/src/table/data-table-state.ts +24 -13
- package/src/table/data-table.module.css +210 -3
- package/src/table/data-table.module.css.d.ts +12 -0
- package/src/table/data-table.tsx +406 -359
- package/src/table/table-features.ts +44 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
- package/src/theme/card-inset.module.css +35 -0
- package/src/theme/controls.module.css +32 -0
- package/src/theme/ctl-theme.tsx +8 -0
- package/src/theme/index.ts +12 -8
- package/src/tokens/core.ts +1 -0
- package/src/tokens/derive.ts +1 -1
- package/src/tokens/palette.ts +4 -1
package/src/charts/labels.ts
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
6
6
|
import { text } from '@tanstack/charts/text'
|
|
7
7
|
import { VX } from '../tokens'
|
|
8
|
+
import { yRangeWithin } from './ref-label'
|
|
9
|
+
import type { LabelBox, RefLabelPoint } from './ref-label'
|
|
8
10
|
import { rowX } from './types'
|
|
9
11
|
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types'
|
|
10
12
|
|
|
11
13
|
const MAX_END_LABELS = 3
|
|
12
|
-
/** Two end labels closer than this (px, vertically) are pushed apart to it. */
|
|
13
|
-
const END_LABEL_MIN_GAP =
|
|
14
|
+
/** Two end labels closer than this (px, vertically) are pushed apart to it: one label line (11px at 1.35) plus two pixels of air. */
|
|
15
|
+
const END_LABEL_MIN_GAP = 17
|
|
14
16
|
const END_LABEL_DX = 6
|
|
15
17
|
/**
|
|
16
18
|
* A glyph's advance as a share of the font size, for the room check. 0.85 covers proportional
|
|
@@ -24,6 +26,16 @@ const END_LABEL_FLIP_DY = -9
|
|
|
24
26
|
const END_LABEL_FLIP_DY_BELOW = 13
|
|
25
27
|
/** The room a label's centre keeps from the plot's top and bottom edge, px: half its line. */
|
|
26
28
|
const END_LABEL_EDGE = 7
|
|
29
|
+
/** A glyph's advance as a share of the font size, for a label's drawn box (the room check's {@link END_LABEL_GLYPH_EM} errs wide). */
|
|
30
|
+
const BOX_GLYPH_EM = 0.68
|
|
31
|
+
/** A label's ink is this share of its font size tall, centred on its text's y. */
|
|
32
|
+
const BOX_INK = 0.75
|
|
33
|
+
/** Air a label keeps from any line, px, and the margin a claimed box carries for a caption. */
|
|
34
|
+
const LINE_AIR = 4.5
|
|
35
|
+
/** What a label across a reference rule from its own line costs in {@link place}'s air score, px. */
|
|
36
|
+
const CROSSED_PENALTY = 100
|
|
37
|
+
/** The most flipped labels whose two sides are all tried (2 ** n assignments). */
|
|
38
|
+
const MAX_SIDE_SEARCH = 5
|
|
27
39
|
|
|
28
40
|
export type EndLabelAnchor = 'start' | 'end'
|
|
29
41
|
/** Which side of its line a flipped label sits: away from the line's last segment. */
|
|
@@ -56,8 +68,20 @@ export type EndLabel<T, X extends ChartX> = {
|
|
|
56
68
|
anchor: EndLabelAnchor
|
|
57
69
|
/** Only a flipped label (left of its point) can meet its own line; it takes the clear side. */
|
|
58
70
|
side: EndLabelSide
|
|
59
|
-
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
|
|
71
|
+
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours and the lines. */
|
|
60
72
|
nudge: number
|
|
73
|
+
/** The room the drawn label takes, for a reference caption to keep clear of. */
|
|
74
|
+
box: LabelBox
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const claimedBoxes = new WeakMap<object, readonly LabelBox[]>()
|
|
78
|
+
/** Records the boxes the end labels of `plot` take (once per plot, by `Lines`). */
|
|
79
|
+
export function claimLabelBoxes(plot: object, boxes: readonly LabelBox[]): void {
|
|
80
|
+
claimedBoxes.set(plot, boxes)
|
|
81
|
+
}
|
|
82
|
+
/** The boxes {@link claimLabelBoxes} recorded for `plot`: what a reference caption avoids. */
|
|
83
|
+
export function claimedLabelBoxes(plot: object): readonly LabelBox[] {
|
|
84
|
+
return claimedBoxes.get(plot) ?? []
|
|
61
85
|
}
|
|
62
86
|
|
|
63
87
|
type LastPoint<T, X extends ChartX> = {
|
|
@@ -72,16 +96,21 @@ type LastPoint<T, X extends ChartX> = {
|
|
|
72
96
|
/**
|
|
73
97
|
* Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
|
|
74
98
|
* shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
|
|
75
|
-
* lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot
|
|
99
|
+
* lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot; a stack too tall for the plot
|
|
100
|
+
* shrinks its gap to fit. Order is kept.
|
|
76
101
|
*/
|
|
77
102
|
export function spreadLabels(ys: readonly number[], plotHeight: number): number[] {
|
|
78
103
|
const order = ys.map((y, i) => i).toSorted((a, b) => (ys[a] as number) - (ys[b] as number))
|
|
79
104
|
const placed = new Map<number, number>()
|
|
105
|
+
// A stack taller than the plot closes its gaps evenly rather than leave the plot.
|
|
106
|
+
const room = Math.max(plotHeight - 2 * END_LABEL_EDGE, 0)
|
|
107
|
+
const gap =
|
|
108
|
+
ys.length > 1 ? Math.min(END_LABEL_MIN_GAP, room / (ys.length - 1)) : END_LABEL_MIN_GAP
|
|
80
109
|
let floor = END_LABEL_EDGE
|
|
81
110
|
for (const i of order) {
|
|
82
111
|
const at = Math.max(ys[i] as number, floor)
|
|
83
112
|
placed.set(i, at)
|
|
84
|
-
floor = at +
|
|
113
|
+
floor = at + gap
|
|
85
114
|
}
|
|
86
115
|
// Pushed past the top: slide the whole stack back down, then re-sweep from the top.
|
|
87
116
|
const top = plotHeight - END_LABEL_EDGE
|
|
@@ -89,7 +118,7 @@ export function spreadLabels(ys: readonly number[], plotHeight: number): number[
|
|
|
89
118
|
for (const i of order.toReversed()) {
|
|
90
119
|
const at = Math.min(placed.get(i) as number, ceiling, top)
|
|
91
120
|
placed.set(i, at)
|
|
92
|
-
ceiling = at -
|
|
121
|
+
ceiling = at - gap
|
|
93
122
|
}
|
|
94
123
|
return ys.map((y, i) => (placed.get(i) as number) - y)
|
|
95
124
|
}
|
|
@@ -105,6 +134,8 @@ export function endLabelPlan<T, X extends ChartX>(
|
|
|
105
134
|
plot: PlotContext<T, X>,
|
|
106
135
|
lines: readonly ChartSeries<T>[],
|
|
107
136
|
naming: LinesNaming = 'auto',
|
|
137
|
+
/** The values of the reference lines on the left axis: rules a label must not sit on. */
|
|
138
|
+
rules: readonly number[] = [],
|
|
108
139
|
): EndLabel<T, X>[] {
|
|
109
140
|
if (naming === 'legend' || plot.y2 !== undefined || lines.length === 0) return []
|
|
110
141
|
if (naming === 'auto' && (plot.containerClass !== 'wide' || lines.length > MAX_END_LABELS))
|
|
@@ -119,30 +150,150 @@ export function endLabelPlan<T, X extends ChartX>(
|
|
|
119
150
|
})
|
|
120
151
|
// No `y2` here (returned above), so every label reads the left domain.
|
|
121
152
|
const [lo, hi] = plot.yDomain
|
|
122
|
-
const
|
|
123
|
-
|
|
153
|
+
const anchors = last.map(({ series, fraction }) =>
|
|
154
|
+
endLabelAnchor({
|
|
124
155
|
fraction,
|
|
125
156
|
plotWidth: plot.plotWidth,
|
|
126
157
|
label: series.label,
|
|
127
158
|
fontSize: VX.text.micro,
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
159
|
+
}),
|
|
160
|
+
)
|
|
161
|
+
// Flipped labels (left of their point) sit over their own line. A line falling into its end
|
|
162
|
+
// comes from above, so its label drops below; a rising line's rises above. Several flipped lines
|
|
163
|
+
// that move the same way would all take the same side and stack in the gap between them, so they
|
|
164
|
+
// wrap the lines instead: falling, the lowest below and the rest above; rising, the mirror.
|
|
165
|
+
const falls = last.map(({ y, prev }) => prev !== null && prev > y)
|
|
166
|
+
const flipped = last.flatMap((_, i) => (anchors[i] === 'end' ? [i] : []))
|
|
167
|
+
const lineY = (i: number): number => (last[i] as (typeof last)[number]).y
|
|
168
|
+
const sameWay =
|
|
169
|
+
flipped.length > 1 && flipped.every((i) => falls[i] === falls[flipped[0] as number])
|
|
170
|
+
const wrapped = sameWay ? flipped.toSorted((a, b) => lineY(a) - lineY(b)) : []
|
|
171
|
+
// The one that keeps the far side: the lowest when falling, the highest when rising.
|
|
172
|
+
const outlier = falls[flipped[0] as number] ? wrapped[0] : wrapped.at(-1)
|
|
173
|
+
const preferred = last.map((_, i): EndLabelSide => {
|
|
174
|
+
const fall = falls[i] as boolean
|
|
175
|
+
return sameWay && anchors[i] === 'end'
|
|
176
|
+
? (i === outlier) === fall
|
|
177
|
+
? 'below'
|
|
178
|
+
: 'above'
|
|
179
|
+
: fall
|
|
180
|
+
? 'below'
|
|
181
|
+
: 'above'
|
|
182
|
+
})
|
|
183
|
+
const toPx = (y: number): number => ((y - lo) / (hi - lo || 1)) * plot.plotHeight
|
|
184
|
+
const nominal = (i: number, side: EndLabelSide): number =>
|
|
185
|
+
toPx(lineY(i)) - endLabelOffset(anchors[i] as EndLabelAnchor, side).dy
|
|
186
|
+
const half = (VX.text.micro * BOX_INK) / 2
|
|
187
|
+
const plotW = Math.max(plot.plotWidth, 1)
|
|
188
|
+
const spans = last.map(({ series, fraction }, i) => {
|
|
189
|
+
const room = (END_LABEL_DX + series.label.length * VX.text.micro * BOX_GLYPH_EM) / plotW
|
|
190
|
+
const edge = END_LABEL_DX / plotW
|
|
191
|
+
return anchors[i] === 'end'
|
|
192
|
+
? ([fraction - room, fraction - edge] as const)
|
|
193
|
+
: ([fraction + edge, fraction + room] as const)
|
|
134
194
|
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
195
|
+
// Every line a label could sit on, as polylines in px from the plot's bottom: each visible
|
|
196
|
+
// series and each reference rule. Only the stretch under the labels matters.
|
|
197
|
+
const from = Math.min(...spans.map(([x0]) => x0))
|
|
198
|
+
const obstacles: RefLabelPoint[][] = [
|
|
199
|
+
...plot.visible.map((s) => {
|
|
200
|
+
const pts: RefLabelPoint[] = []
|
|
201
|
+
let before: RefLabelPoint | undefined
|
|
202
|
+
for (const r of plot.rows(s.key)) {
|
|
203
|
+
const fx = r.y === null ? null : plot.xFraction(r.x)
|
|
204
|
+
if (fx === null || r.y === null) continue
|
|
205
|
+
const pt = { fx, y: toPx(r.y) }
|
|
206
|
+
if (fx < from) before = pt
|
|
207
|
+
else {
|
|
208
|
+
if (before !== undefined) pts.push(before)
|
|
209
|
+
before = undefined
|
|
210
|
+
pts.push(pt)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (before !== undefined) pts.push(before)
|
|
214
|
+
return pts
|
|
215
|
+
}),
|
|
216
|
+
...rules.map((v) => [
|
|
217
|
+
{ fx: 0, y: toPx(v) },
|
|
218
|
+
{ fx: 1, y: toPx(v) },
|
|
219
|
+
]),
|
|
220
|
+
]
|
|
221
|
+
/** Per label, the line ranges (px) its x-window runs into: fixed, so computed once. */
|
|
222
|
+
const windowRanges = spans.map(([x0, x1]) =>
|
|
223
|
+
obstacles.flatMap((pts) => {
|
|
224
|
+
const range = yRangeWithin(pts, x0, x1)
|
|
225
|
+
return range === null ? [] : [range]
|
|
226
|
+
}),
|
|
138
227
|
)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
228
|
+
const ranges = (i: number): readonly [number, number][] => windowRanges[i] as [number, number][]
|
|
229
|
+
/** Where the centre goes to clear the lines on `side` of `start`, stepping past each one it meets. */
|
|
230
|
+
const cleared = (i: number, side: EndLabelSide, start: number): number => {
|
|
231
|
+
const blockers = ranges(i)
|
|
232
|
+
let c = start
|
|
233
|
+
for (let n = 0; n <= blockers.length; n++) {
|
|
234
|
+
const hit = blockers.find(([a, b]) => b + LINE_AIR > c - half && a - LINE_AIR < c + half)
|
|
235
|
+
if (hit === undefined) break
|
|
236
|
+
c = side === 'above' ? hit[1] + LINE_AIR + half : hit[0] - LINE_AIR - half
|
|
237
|
+
}
|
|
238
|
+
return c
|
|
239
|
+
}
|
|
240
|
+
const airOf = (i: number, c: number): number =>
|
|
241
|
+
Math.min(
|
|
242
|
+
Number.POSITIVE_INFINITY,
|
|
243
|
+
...ranges(i).map(([a, b]) => Math.max(a - (c + half), c - half - b)),
|
|
244
|
+
)
|
|
245
|
+
const place = (sides: readonly EndLabelSide[]) => {
|
|
246
|
+
const start = last.map((_, i) =>
|
|
247
|
+
cleared(i, sides[i] as EndLabelSide, nominal(i, sides[i] as EndLabelSide)),
|
|
248
|
+
)
|
|
249
|
+
const shifts = spreadLabels(start, plot.plotHeight)
|
|
250
|
+
const centres = start.map((c, i) => c + (shifts[i] as number))
|
|
251
|
+
// A label across a reference rule from its own line's end reads as the rule's label: worse
|
|
252
|
+
// than any amount of lost air.
|
|
253
|
+
const crossed = centres.filter((c, i) => {
|
|
254
|
+
const end = toPx(lineY(i))
|
|
255
|
+
return rules.some(
|
|
256
|
+
(v) => (toPx(v) - c) * (toPx(v) - end) < 0 && (c - end) * (toPx(v) - end) > 0,
|
|
257
|
+
)
|
|
258
|
+
}).length
|
|
259
|
+
const score =
|
|
260
|
+
centres.reduce((sum, c, i) => sum + Math.min(airOf(i, c), LINE_AIR), 0) -
|
|
261
|
+
CROSSED_PENALTY * crossed
|
|
262
|
+
return { sides, centres, score }
|
|
263
|
+
}
|
|
264
|
+
// Each flipped label may take either side: the assignment that keeps most air from the lines
|
|
265
|
+
// wins, the preferred one on a tie. Level labels (right of
|
|
266
|
+
// their point) keep theirs.
|
|
267
|
+
const options = flipped.length <= MAX_SIDE_SEARCH ? flipped.length : 0
|
|
268
|
+
let best = place(preferred)
|
|
269
|
+
for (let mask = 1; mask < 1 << options; mask++) {
|
|
270
|
+
const sides = preferred.map((side, i): EndLabelSide => {
|
|
271
|
+
const at = flipped.indexOf(i)
|
|
272
|
+
return at >= 0 && (mask >> at) & 1 ? (side === 'above' ? 'below' : 'above') : side
|
|
273
|
+
})
|
|
274
|
+
const trial = place(sides)
|
|
275
|
+
if (trial.score > best.score + 0.01) best = trial
|
|
276
|
+
}
|
|
277
|
+
return last.map(({ series, row }, i) => {
|
|
278
|
+
const side = best.sides[i] as EndLabelSide
|
|
279
|
+
const centre = best.centres[i] as number
|
|
280
|
+
const [x0, x1] = spans[i] as readonly [number, number]
|
|
281
|
+
const perPx = (hi - lo) / (plot.plotHeight || 1)
|
|
282
|
+
// Two pixels of margin each way: the caption keeps its own gap from the claimed box.
|
|
283
|
+
return {
|
|
284
|
+
series,
|
|
285
|
+
row,
|
|
286
|
+
anchor: anchors[i] as EndLabelAnchor,
|
|
287
|
+
side,
|
|
288
|
+
nudge: nominal(i, side) - centre,
|
|
289
|
+
box: {
|
|
290
|
+
fx0: x0 - 2 / plotW,
|
|
291
|
+
fx1: x1 + 2 / plotW,
|
|
292
|
+
y0: lo + (centre - half - 2) * perPx,
|
|
293
|
+
y1: lo + (centre + half + 2) * perPx,
|
|
294
|
+
},
|
|
295
|
+
}
|
|
296
|
+
})
|
|
146
297
|
}
|
|
147
298
|
|
|
148
299
|
/** The offset of a label from its point: right of it, level; or left of it, above or below. */
|
package/src/charts/legend.tsx
CHANGED
|
@@ -115,7 +115,7 @@ export type SignedSeries<T> = ChartSeries<T> & { colorNegative?: string | undefi
|
|
|
115
115
|
|
|
116
116
|
type SwatchStyle = Pick<
|
|
117
117
|
SignedSeries<never>,
|
|
118
|
-
'color' | 'colorNegative' | 'mark' | 'dash' | 'strokeOpacity' | 'fillOpacity'
|
|
118
|
+
'color' | 'colorNegative' | 'mark' | 'dash' | 'strokeOpacity' | 'fillOpacity' | 'role'
|
|
119
119
|
>
|
|
120
120
|
|
|
121
121
|
/** A swatch fill: the series colour, or a hard-stop split for a sign-coloured bar. */
|
|
@@ -149,7 +149,8 @@ function LineSwatch({ s, compact }: { s: SwatchStyle; compact: boolean }): React
|
|
|
149
149
|
y1={4}
|
|
150
150
|
y2={4}
|
|
151
151
|
stroke={s.color}
|
|
152
|
-
|
|
152
|
+
// A reference line is drawn as a 1px rule (`refLineMarks`), a series from 2px: the key keeps that difference.
|
|
153
|
+
strokeWidth={s.role === 'reference' ? 1 : 2}
|
|
153
154
|
strokeLinecap={s.dash === 'dashed' ? 'butt' : 'round'}
|
|
154
155
|
strokeOpacity={s.strokeOpacity ?? 1}
|
|
155
156
|
{...(s.dash === 'dashed' && { strokeDasharray: dash })}
|
package/src/charts/ref-label.ts
CHANGED
|
@@ -15,6 +15,12 @@ const GLYPH_EM = 0.62
|
|
|
15
15
|
const EDGE_INSET = 6
|
|
16
16
|
const LINE_GAP = 3
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* A box another label has claimed in the same plot: a share of the plot width and a span of values
|
|
20
|
+
* on the left axis. A caption never takes a spot that overlaps one.
|
|
21
|
+
*/
|
|
22
|
+
export type LabelBox = { fx0: number; fx1: number; y0: number; y1: number }
|
|
23
|
+
|
|
18
24
|
const ORDER_END: readonly RefLabelPosition[] = [
|
|
19
25
|
'end-above',
|
|
20
26
|
'end-below',
|
|
@@ -29,7 +35,7 @@ const ORDER_START: readonly RefLabelPosition[] = [
|
|
|
29
35
|
]
|
|
30
36
|
|
|
31
37
|
/** The y range of the polyline `points` (sorted by `fx`) between `fx0` and `fx1`, or `null`. */
|
|
32
|
-
function yRangeWithin(
|
|
38
|
+
export function yRangeWithin(
|
|
33
39
|
points: readonly RefLabelPoint[],
|
|
34
40
|
fx0: number,
|
|
35
41
|
fx1: number,
|
|
@@ -70,8 +76,11 @@ export function refLabelPosition(opts: {
|
|
|
70
76
|
fontSize: number
|
|
71
77
|
/** One polyline per visible series on the line's axis. */
|
|
72
78
|
series: readonly (readonly RefLabelPoint[])[]
|
|
79
|
+
/** Labels already placed on this axis (end labels): a caption keeps clear of them too. */
|
|
80
|
+
claimed?: readonly LabelBox[] | undefined
|
|
73
81
|
}): RefLabelPosition {
|
|
74
82
|
const { pinned, startFirst, value, plotWidth, plotHeight, label, fontSize, series } = opts
|
|
83
|
+
const { claimed = [] } = opts
|
|
75
84
|
const order = startFirst ? ORDER_START : ORDER_END
|
|
76
85
|
if (pinned !== undefined) return pinned
|
|
77
86
|
const [lo, hi] = [Math.min(...opts.domain), Math.max(...opts.domain)]
|
|
@@ -92,10 +101,12 @@ export function refLabelPosition(opts: {
|
|
|
92
101
|
const [fx0, fx1] = position.startsWith('end')
|
|
93
102
|
? [1 - widthFx, 1 - EDGE_INSET / plotWidth]
|
|
94
103
|
: [EDGE_INSET / plotWidth, widthFx]
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
return (
|
|
105
|
+
series.every((points) => {
|
|
106
|
+
const range = yRangeWithin(points, fx0, fx1)
|
|
107
|
+
return range === null || range[1] < from || range[0] > to
|
|
108
|
+
}) && claimed.every((b) => b.fx1 < fx0 || b.fx0 > fx1 || b.y1 < from || b.y0 > to)
|
|
109
|
+
)
|
|
99
110
|
}
|
|
100
111
|
// A caption that cannot avoid the data still stays inside the plot.
|
|
101
112
|
return (
|
|
@@ -105,27 +116,85 @@ export function refLabelPosition(opts: {
|
|
|
105
116
|
|
|
106
117
|
/** The gap between a sparkline reference label's box and its line, px. */
|
|
107
118
|
const SPARK_LABEL_GAP = 2
|
|
119
|
+
/** Air between a sparkline label's box and the data line (stroke and end dot included), px. */
|
|
120
|
+
const SPARK_LINE_AIR = 5
|
|
121
|
+
|
|
122
|
+
export type SparkLabelPlacement = {
|
|
123
|
+
side: 'above' | 'below'
|
|
124
|
+
end: 'start' | 'end'
|
|
125
|
+
/** The engine centres the text on its y: the offset that puts the box on `side` of the line. */
|
|
126
|
+
dy: number
|
|
127
|
+
}
|
|
108
128
|
|
|
109
129
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
130
|
+
* Where a sparkline's reference label sits: of start-above, start-below, end-above, end-below, the
|
|
131
|
+
* one whose box stays inside the plot (`height` in full) and moves least off the reference to clear
|
|
132
|
+
* the data line by {@link SPARK_LINE_AIR} (the first of the four on a tie). The box clears the
|
|
133
|
+
* reference by at least {@link SPARK_LABEL_GAP}, so the dashed rule never strikes the text.
|
|
134
|
+
* `line` is the plotted polyline as `{ fx, y }` (a share of the plot width, a value on `domain`);
|
|
135
|
+
* without it (a bar sparkline, or no `width`/`label`) only the plot bounds decide.
|
|
114
136
|
*/
|
|
115
137
|
export function referenceLabelPlacement(opts: {
|
|
116
138
|
value: number
|
|
117
139
|
domain: readonly [number, number]
|
|
118
140
|
height: number
|
|
141
|
+
/** Plot width, px. */
|
|
142
|
+
width?: number | undefined
|
|
119
143
|
/** The plot's margin inside the svg box, px. */
|
|
120
144
|
inset: number
|
|
121
145
|
fontSize: number
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
label?: string | undefined
|
|
147
|
+
line?: readonly RefLabelPoint[] | undefined
|
|
148
|
+
}): SparkLabelPlacement {
|
|
149
|
+
const { value, domain, height, inset, fontSize, line } = opts
|
|
150
|
+
const { width = 0, label = '' } = opts
|
|
124
151
|
const [lo, hi] = [Math.min(...domain), Math.max(...domain)]
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
152
|
+
const plotH = height - 2 * inset
|
|
153
|
+
const plotW = width - 2 * inset
|
|
154
|
+
const px = (y: number): number => inset + plotH * (1 - (hi === lo ? 0 : (y - lo) / (hi - lo)))
|
|
155
|
+
const at = px(value)
|
|
156
|
+
const boxH = fontSize
|
|
157
|
+
const boxW = label.length * fontSize * GLYPH_EM + EDGE_INSET
|
|
158
|
+
const pxLine = line?.map((p) => ({ fx: p.fx, y: px(p.y) }))
|
|
159
|
+
const candidates = (['start', 'end'] as const).flatMap((end) =>
|
|
160
|
+
(['above', 'below'] as const).map((side) => {
|
|
161
|
+
const nominal = side === 'above' ? at - SPARK_LABEL_GAP - boxH : at + SPARK_LABEL_GAP
|
|
162
|
+
const [fx0, fx1] = end === 'start' ? [0, boxW / plotW] : [1 - boxW / plotW, 1]
|
|
163
|
+
// The curve between two points stays between their values but not on the chord, so the
|
|
164
|
+
// window reaches out to the vertices that bound it.
|
|
165
|
+
const lead = pxLine?.find((p) => p.fx >= fx1)?.fx ?? fx1
|
|
166
|
+
const trail = pxLine?.findLast((p) => p.fx <= fx0)?.fx ?? fx0
|
|
167
|
+
const range =
|
|
168
|
+
pxLine === undefined || plotW <= 0
|
|
169
|
+
? null
|
|
170
|
+
: yRangeWithin(pxLine, Math.min(trail, fx0), Math.max(lead, fx1))
|
|
171
|
+
// A box the line comes within the air of slides away from the reference, along its side, until it has air.
|
|
172
|
+
const near =
|
|
173
|
+
range !== null &&
|
|
174
|
+
range[1] + SPARK_LINE_AIR > nominal &&
|
|
175
|
+
range[0] - SPARK_LINE_AIR < nominal + boxH
|
|
176
|
+
const top = !near
|
|
177
|
+
? nominal
|
|
178
|
+
: side === 'above'
|
|
179
|
+
? range[0] - SPARK_LINE_AIR - boxH
|
|
180
|
+
: range[1] + SPARK_LINE_AIR
|
|
181
|
+
return {
|
|
182
|
+
side,
|
|
183
|
+
end,
|
|
184
|
+
top,
|
|
185
|
+
shift: Math.abs(top - nominal),
|
|
186
|
+
fits: top >= 0 && top + boxH <= height,
|
|
187
|
+
}
|
|
188
|
+
}),
|
|
189
|
+
)
|
|
190
|
+
const fitting = candidates.filter((c) => c.fits)
|
|
191
|
+
// The fitting spot that stays nearest the reference (the first of the four on a tie), else the
|
|
192
|
+
// first: the plot bounds alone decide when nothing fits.
|
|
193
|
+
const found = fitting.reduce<(typeof candidates)[number] | undefined>(
|
|
194
|
+
(best, c) => (best === undefined || c.shift < best.shift ? c : best),
|
|
195
|
+
undefined,
|
|
196
|
+
)
|
|
197
|
+
const { side, end, top } = found ?? (candidates[0] as (typeof candidates)[number])
|
|
198
|
+
const dy = top + boxH / 2 - at
|
|
199
|
+
return { side, end, dy }
|
|
131
200
|
}
|
|
@@ -114,3 +114,9 @@
|
|
|
114
114
|
border-radius: 50%;
|
|
115
115
|
transform: translate(-50%, -50%);
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
/* The reference caption steps aside while a readout shows: the chip can land on it (a long caption
|
|
119
|
+
* reaches the chip's line), and the readout is what the pointer asked for. */
|
|
120
|
+
.root[data-basalt-readout] [data-ts-key='reference-label'] {
|
|
121
|
+
visibility: hidden;
|
|
122
|
+
}
|
package/src/charts/state.tsx
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* the chart chrome and `ChartCard`, so a pending card and a pending chart read the same.
|
|
4
4
|
*/
|
|
5
5
|
import type { CSSProperties, ReactElement, ReactNode } from 'react'
|
|
6
|
+
import { splitEmptyCopy } from '../common/empty-copy'
|
|
6
7
|
import { toErrorMessage } from '../common/errors'
|
|
7
8
|
import { RetryButton } from '../common/retry-button'
|
|
8
9
|
import { VX } from '../tokens'
|
|
@@ -42,10 +43,10 @@ const pendingStyle: CSSProperties = {
|
|
|
42
43
|
const GHOST_BARS = [38, 52, 44, 66, 58, 74, 62, 48] as const
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
* The shape a pending plot draws: `'bars'` (default), `'line'` for a line or area chart,
|
|
46
|
-
* count when the loaded chart's data length is known (a 6-month chart loads 6 bars).
|
|
46
|
+
* The shape a pending plot draws: `'bars'` (default), `'line'` for a line or area chart, `'band'`
|
|
47
|
+
* for a `BandStrip` (one row), or a bar count when the loaded chart's data length is known (a 6-month chart loads 6 bars).
|
|
47
48
|
*/
|
|
48
|
-
export type PlotGhostShape = 'bars' | 'line' | number
|
|
49
|
+
export type PlotGhostShape = 'bars' | 'line' | 'band' | number
|
|
49
50
|
|
|
50
51
|
/** A mild rise across the width, in a 100 x 40 box stretched to the plot. */
|
|
51
52
|
const GHOST_LINE = '0,30 12,26 25,28 38,18 50,22 62,12 75,16 88,8 100,12'
|
|
@@ -60,6 +61,12 @@ function PlotGhost({ shape = 'bars' }: { shape?: PlotGhostShape }): ReactElement
|
|
|
60
61
|
</svg>
|
|
61
62
|
</div>
|
|
62
63
|
)
|
|
64
|
+
if (shape === 'band')
|
|
65
|
+
return (
|
|
66
|
+
<div aria-hidden="true" data-basalt-plot-ghost="band" className={boxClasses.ghost}>
|
|
67
|
+
<span className={boxClasses.ghostBand} />
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
63
70
|
const count =
|
|
64
71
|
typeof shape === 'number' ? Math.max(1, Math.min(Math.floor(shape), 60)) : GHOST_BARS.length
|
|
65
72
|
return (
|
|
@@ -97,6 +104,11 @@ const errorStyle: CSSProperties = {
|
|
|
97
104
|
fontSize: VX.text.sm,
|
|
98
105
|
gap: VX.space.controlGap,
|
|
99
106
|
}
|
|
107
|
+
// The empty tile's one ring: an inset shadow, never a border, as `EmptyState`'s section tier draws it.
|
|
108
|
+
const tileStyle: CSSProperties = {
|
|
109
|
+
// theme-allow surface-shadow-override — an inset ring on a tile inside a surface, not a card's depth
|
|
110
|
+
boxShadow: `var(--basalt-state-ring, inset 0 0 0 1px ${VX.surface.hairline})`,
|
|
111
|
+
}
|
|
100
112
|
const errorHeadStyle: CSSProperties = {
|
|
101
113
|
display: 'inline-flex',
|
|
102
114
|
alignItems: 'center',
|
|
@@ -152,7 +164,8 @@ export function ChartPlaceholder(props: {
|
|
|
152
164
|
if (kind === 'pending')
|
|
153
165
|
return fit(
|
|
154
166
|
<output aria-label="Loading chart" aria-busy="true" className={stateClass} style={style}>
|
|
155
|
-
{
|
|
167
|
+
{/* A sparkline's box is too small for bars: it ghosts a line, in the same tone as every ghost. */}
|
|
168
|
+
<PlotGhost shape={props.ghost ?? (props.compact ? 'line' : 'bars')} />
|
|
156
169
|
</output>,
|
|
157
170
|
)
|
|
158
171
|
const label =
|
|
@@ -189,9 +202,25 @@ export function ChartPlaceholder(props: {
|
|
|
189
202
|
{body}
|
|
190
203
|
</div>,
|
|
191
204
|
)
|
|
205
|
+
if (props.compact)
|
|
206
|
+
return fit(
|
|
207
|
+
<output data-basalt-chart-state={kind} className={stateClass} style={style} {...name}>
|
|
208
|
+
{body}
|
|
209
|
+
</output>,
|
|
210
|
+
)
|
|
211
|
+
// The § 6.11 empty tile inside the chart's own box: one ring, card radius, the title at `sm` 500
|
|
212
|
+
// and a muted line, centred. `EmptyState` is Mantine-coupled, so the anatomy is plain HTML here.
|
|
213
|
+
// The live region holds the copy only; the action is its sibling, so a button is not announced.
|
|
214
|
+
const { title, description } = splitEmptyCopy(label)
|
|
192
215
|
return fit(
|
|
193
|
-
<
|
|
194
|
-
{
|
|
195
|
-
|
|
216
|
+
<div data-basalt-chart-state={kind} className={stateClass} style={boxStyle}>
|
|
217
|
+
<div data-basalt-empty-tile="" className={boxClasses.emptyTile} style={tileStyle}>
|
|
218
|
+
<output className={boxClasses.emptyCopy}>
|
|
219
|
+
<span className={boxClasses.emptyTitle}>{title}</span>
|
|
220
|
+
{description !== undefined && <span className={boxClasses.emptyText}>{description}</span>}
|
|
221
|
+
</output>
|
|
222
|
+
{props.action !== undefined && <div>{props.action}</div>}
|
|
223
|
+
</div>
|
|
224
|
+
</div>,
|
|
196
225
|
)
|
|
197
226
|
}
|
package/src/cli/shot/capture.ts
CHANGED
|
@@ -416,14 +416,31 @@ async function frame(c: Ctx, name: string): Promise<() => Promise<void>> {
|
|
|
416
416
|
return undo
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
-
/**
|
|
419
|
+
/**
|
|
420
|
+
* Runs in the page: px the PAGE scrollport hides, which `fullPage` cannot see. That is the element
|
|
421
|
+
* carrying `data-basalt-scrollport` (BasaltShell's `AppShell.Main`); a shell-less app has none, so
|
|
422
|
+
* the outermost auto/scroll box counts instead. A bounded scroll box nested inside it (an event
|
|
423
|
+
* list, a table) never does: its hidden rows are not page height.
|
|
424
|
+
*/
|
|
420
425
|
export function hiddenScrollPx(): number {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
426
|
+
const hidden = (el: Element): number => Math.max(0, el.scrollHeight - el.clientHeight)
|
|
427
|
+
const declared = document.querySelector('[data-basalt-scrollport]')
|
|
428
|
+
if (declared !== null) return hidden(declared)
|
|
429
|
+
const scrolls = (el: Element): boolean => {
|
|
424
430
|
const { overflowY } = getComputedStyle(el)
|
|
425
|
-
|
|
426
|
-
|
|
431
|
+
return overflowY === 'auto' || overflowY === 'scroll'
|
|
432
|
+
}
|
|
433
|
+
let extra = 0
|
|
434
|
+
for (const el of Array.from(document.body.querySelectorAll('*'))) {
|
|
435
|
+
if (el.clientHeight < window.innerHeight / 2 || !scrolls(el)) continue
|
|
436
|
+
let nested = false
|
|
437
|
+
for (
|
|
438
|
+
let p = el.parentElement;
|
|
439
|
+
p !== null && p !== document.documentElement;
|
|
440
|
+
p = p.parentElement
|
|
441
|
+
)
|
|
442
|
+
if (scrolls(p)) nested = true
|
|
443
|
+
if (!nested) extra = Math.max(extra, hidden(el))
|
|
427
444
|
}
|
|
428
445
|
return extra
|
|
429
446
|
}
|
|
@@ -888,6 +905,12 @@ async function capturePage(
|
|
|
888
905
|
await captureUrlState(c, state)
|
|
889
906
|
collect(c)
|
|
890
907
|
}
|
|
908
|
+
// After every state, so the order never matters: a name no rest read held is absent at rest.
|
|
909
|
+
const atRest = new Set(c.shots.filter((s) => s.state === 'rest').map((s) => s.name))
|
|
910
|
+
for (const name of new Set(c.shots.map((s) => s.name))) {
|
|
911
|
+
if (input.states.includes('rest') && !atRest.has(name) && !c.facts.anchors.includes(name))
|
|
912
|
+
record(c, { name, state: 'rest', status: 'absent', note: 'not rendered at rest' })
|
|
913
|
+
}
|
|
891
914
|
flagProblems(c)
|
|
892
915
|
return c
|
|
893
916
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The empty tile's copy from the one string a host carries (`ChartState.empty`, `StatCard`'s
|
|
3
|
+
* `emptyText`), as `EmptyState` reads it (SPEC § 6.11): the title (why it is empty) and the muted
|
|
4
|
+
* line (what to do).
|
|
5
|
+
*
|
|
6
|
+
* One rule: the title is everything up to the first `.`, `!` or `?` that is followed by whitespace
|
|
7
|
+
* or ends the string; the description is the rest. Both parts are trimmed, and a trailing `.` is
|
|
8
|
+
* dropped from the title only (a `?` or `!` stays, the description keeps its own punctuation). An
|
|
9
|
+
* abbreviation such as `e.g. ` or `approx. ` ends the title early: write the copy without one, or
|
|
10
|
+
* as a single sentence.
|
|
11
|
+
*/
|
|
12
|
+
export function splitEmptyCopy(label: string): { title: string; description: string | undefined } {
|
|
13
|
+
const at = label.search(/[.!?](\s|$)/)
|
|
14
|
+
const head = (at < 0 ? label : label.slice(0, at + 1)).trim()
|
|
15
|
+
const rest = at < 0 ? '' : label.slice(at + 1).trim()
|
|
16
|
+
return { title: head.replace(/\.$/, ''), description: rest === '' ? undefined : rest }
|
|
17
|
+
}
|