basalt-ui 2.23.0 → 2.25.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 +63 -0
- package/MIGRATING.md +264 -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 +21 -3
- package/dist/charts/CartesianChart.d.ts +2 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +7 -3
- package/dist/charts/ChartCard.d.ts +6 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +1 -1
- 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 +4 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +65 -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.d.ts +3 -1
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +10 -2
- package/dist/charts/types.d.ts +11 -0
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +25 -36
- package/dist/cli/shot/measure.js +19 -23
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +16 -2
- package/dist/dashboard/bar-list.module.css +10 -17
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- 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 +24 -39
- 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 +4 -3
- package/package.json +1 -1
- package/src/charts/Bars.tsx +36 -4
- package/src/charts/CartesianChart.tsx +9 -3
- package/src/charts/ChartCard.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 +104 -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 +16 -7
- package/src/charts/types.ts +9 -0
- package/src/cli/shot/detect.ts +26 -40
- package/src/cli/shot/measure.ts +27 -27
- package/src/dashboard/bar-list.module.css +10 -17
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +14 -2
- 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 +24 -39
- 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
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@container (min-width: 240px) {
|
|
18
|
+
/* One row: `foldLegend` (legend.tsx) folds what does not fit into `+N`; zones lead the series. */
|
|
18
19
|
.auto {
|
|
20
|
+
flex-wrap: nowrap;
|
|
21
|
+
overflow: hidden;
|
|
19
22
|
display: flex;
|
|
20
23
|
column-gap: var(--bc-dots-gap);
|
|
21
24
|
--vx-hit-gap: var(--bc-dots-gap);
|
|
@@ -24,6 +27,8 @@
|
|
|
24
27
|
|
|
25
28
|
@container (min-width: 480px) {
|
|
26
29
|
.auto {
|
|
30
|
+
flex-wrap: wrap;
|
|
31
|
+
overflow: visible;
|
|
27
32
|
column-gap: var(--bc-legend-gap);
|
|
28
33
|
--vx-hit-gap: var(--bc-legend-gap);
|
|
29
34
|
}
|
|
@@ -43,3 +48,14 @@
|
|
|
43
48
|
display: none;
|
|
44
49
|
}
|
|
45
50
|
}
|
|
51
|
+
|
|
52
|
+
/* The compact fold (`foldLegend`, which only folds while the row is `nowrap`); wide keeps every entry.
|
|
53
|
+
* `!important`: an entry's inline `all: unset` (legend.tsx) would otherwise reset `display`. */
|
|
54
|
+
.auto [data-legend-folded] {
|
|
55
|
+
display: none !important;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.auto [data-legend-more] {
|
|
59
|
+
order: 1;
|
|
60
|
+
flex: none;
|
|
61
|
+
}
|
package/src/charts/compile.ts
CHANGED
|
@@ -101,6 +101,8 @@ export type CartesianInput<T, X extends ChartX> = Pick<
|
|
|
101
101
|
crosshair?: boolean
|
|
102
102
|
/** The engine's point marker on the focused datum. Default `true`; a bar kind has none (its hover is the bar). */
|
|
103
103
|
focusRing?: boolean
|
|
104
|
+
/** No axes, grid or margin: the plot is the whole box (a visual slot's bars, as `Sparkline`). */
|
|
105
|
+
bare?: boolean
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/** The one tick-label size, at every container width: the caption size, so a card never mixes sizes. */
|
|
@@ -211,6 +213,7 @@ export function seriesRow(
|
|
|
211
213
|
|
|
212
214
|
/** Keys the compiler reserves for the legend entries it derives from `refLines`. */
|
|
213
215
|
const REF_KEY_PREFIX = '__ref-'
|
|
216
|
+
const ZONE_KEY_PREFIX = '__zone-'
|
|
214
217
|
|
|
215
218
|
/** The legend key of a reference line that names itself (`RefLine.legend`). */
|
|
216
219
|
const refLegendKey = (index: number): string => `${REF_KEY_PREFIX}${index}`
|
|
@@ -251,6 +254,25 @@ export function refLegendSeries<T>(refLines: readonly RefLine[] | undefined): Ch
|
|
|
251
254
|
)
|
|
252
255
|
}
|
|
253
256
|
|
|
257
|
+
/** Legend-only entries for the zones that name themselves (`ZoneSpec.legend`), in zone order. */
|
|
258
|
+
export function zoneLegendSeries<T>(zones: readonly ZoneSpec[] | undefined): ChartSeries<T>[] {
|
|
259
|
+
return (zones ?? []).flatMap((z, i) =>
|
|
260
|
+
z.legend === undefined
|
|
261
|
+
? []
|
|
262
|
+
: [
|
|
263
|
+
{
|
|
264
|
+
key: `${ZONE_KEY_PREFIX}${i}`,
|
|
265
|
+
label: z.legend.label,
|
|
266
|
+
color: z.legend.color ?? SWATCH_SOLID.get(z.fill) ?? z.fill,
|
|
267
|
+
mark: z.legend.mark ?? 'bar',
|
|
268
|
+
role: 'reference' as const,
|
|
269
|
+
tooltip: false,
|
|
270
|
+
getValue: () => null,
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
|
|
254
276
|
/** The visible series: not toggled off, and not a companion whose parent is. */
|
|
255
277
|
export function visibleSeries<T>(
|
|
256
278
|
series: readonly ChartSeries<T>[],
|
|
@@ -297,6 +319,29 @@ function wholeStepFormat<T>(
|
|
|
297
319
|
return (v) => axis.format(v).replace(padded, '$1')
|
|
298
320
|
}
|
|
299
321
|
|
|
322
|
+
/** A fixed domain's end this near the last round tick (as a share of the tick step) stays unlabelled. */
|
|
323
|
+
const END_TICK_MIN_GAP = 0.4
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The compact ladder's three ticks can stop short of a fixed domain's end (`[0, 25]` ticks `0 10 20`),
|
|
327
|
+
* and a unit the formatter states on the top tick (`25 days`) goes with it. A fixed domain whose end
|
|
328
|
+
* leaves at least {@link END_TICK_MIN_GAP} of a step above the last tick gets the end as a tick too.
|
|
329
|
+
*/
|
|
330
|
+
function withEndTick<T>(
|
|
331
|
+
cfg: AxisConfig<T> | undefined,
|
|
332
|
+
axis: YAxis,
|
|
333
|
+
count: number,
|
|
334
|
+
): { values: readonly number[] } | null {
|
|
335
|
+
if (!Array.isArray(cfg?.domain) || cfg.scale === 'log' || cfg.nice === true) return null
|
|
336
|
+
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)]
|
|
337
|
+
const round = scaleLinear().domain([lo, hi]).ticks(count)
|
|
338
|
+
const last = round.at(-1)
|
|
339
|
+
const next = round.at(1)
|
|
340
|
+
const first = round.at(0)
|
|
341
|
+
if (last === undefined || next === undefined || first === undefined || last >= hi) return null
|
|
342
|
+
return hi - last >= (next - first) * END_TICK_MIN_GAP ? { values: [...round, hi] } : null
|
|
343
|
+
}
|
|
344
|
+
|
|
300
345
|
export function yGuide<T>(opts: {
|
|
301
346
|
cfg: AxisConfig<T> | undefined
|
|
302
347
|
axis: YAxis
|
|
@@ -309,7 +354,9 @@ export function yGuide<T>(opts: {
|
|
|
309
354
|
const ticks =
|
|
310
355
|
typeof cfg?.ticks === 'object'
|
|
311
356
|
? { values: cfg.ticks }
|
|
312
|
-
:
|
|
357
|
+
: ((cls === 'compact' && cfg?.ticks === undefined
|
|
358
|
+
? withEndTick(cfg, axis, ladder.yTicks)
|
|
359
|
+
: null) ?? { count: typeof cfg?.ticks === 'number' ? cfg.ticks : ladder.yTicks })
|
|
313
360
|
const gridLine = grid ? { grid: GRID_LINE } : {}
|
|
314
361
|
if (cls === 'micro') return { ...gridLine, axis: false }
|
|
315
362
|
const tickFormat = wholeStepFormat(axis, cfg, ticks)
|
|
@@ -819,6 +866,23 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
819
866
|
}): StoredChartSpec['scales'] {
|
|
820
867
|
const { input, model, axes, formatX, cls, zoneScale } = opts
|
|
821
868
|
const { left, right } = axes
|
|
869
|
+
if (input.bare === true) {
|
|
870
|
+
return {
|
|
871
|
+
x: { scale: model.scale, axis: false as const },
|
|
872
|
+
y: { scale: yScaleFor(input.y, left.domain), axis: false as const },
|
|
873
|
+
// A right-axis series still needs its scale, drawn or not.
|
|
874
|
+
...(right && {
|
|
875
|
+
y2: {
|
|
876
|
+
channel: 'y' as const,
|
|
877
|
+
scale: yScaleFor(input.y2, right.domain),
|
|
878
|
+
axis: false as const,
|
|
879
|
+
},
|
|
880
|
+
}),
|
|
881
|
+
...(zoneScale && {
|
|
882
|
+
zx: { channel: 'x' as const, scale: scaleLinear().domain([0, 1]), axis: false as const },
|
|
883
|
+
}),
|
|
884
|
+
}
|
|
885
|
+
}
|
|
822
886
|
return {
|
|
823
887
|
x: {
|
|
824
888
|
scale: model.scale,
|
|
@@ -960,6 +1024,39 @@ const stripAnchor = (
|
|
|
960
1024
|
const STRIP_TOOLTIP_PLACEMENT = ['bottom', 'top'] as const
|
|
961
1025
|
const STRIP_TOOLTIP_OFFSET = 8
|
|
962
1026
|
|
|
1027
|
+
/** A tooltip's chrome (title row, padding) and each series row, px: the guess the bar anchor reserves. */
|
|
1028
|
+
const TIP_CHROME = 30
|
|
1029
|
+
const TIP_ROW = 18
|
|
1030
|
+
/** Air between a clamped tooltip's top and the plot's top edge, px. */
|
|
1031
|
+
const TIP_TOP_AIR = 4
|
|
1032
|
+
|
|
1033
|
+
/** A tall bar's tooltip steps aside by this much (a tooltip's half width plus a bar's), px. */
|
|
1034
|
+
const TIP_SIDE_STEP = 96
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* A bar's tooltip opens above the bar, and above a tall bar that is above the plot, over the card's
|
|
1038
|
+
* headline. For a bar too tall to fit it, the anchor drops to where the open-above tooltip's top meets
|
|
1039
|
+
* the plot's top edge (`rows` series rows tall) and steps to the side with more room, so the tooltip
|
|
1040
|
+
* sits beside the bar, in the plot, and not on the bar's top. A short bar is unaffected.
|
|
1041
|
+
*/
|
|
1042
|
+
const barAnchor =
|
|
1043
|
+
(rows: number) =>
|
|
1044
|
+
(
|
|
1045
|
+
points: readonly ChartPoint[],
|
|
1046
|
+
{ plot }: ChartTooltipAnchorContext,
|
|
1047
|
+
): { x: number; y: number } => {
|
|
1048
|
+
const xs = points.map((p) => p.x)
|
|
1049
|
+
const ys = points.map((p) => p.y)
|
|
1050
|
+
const centre = (Math.min(...xs) + Math.max(...xs)) / 2
|
|
1051
|
+
const x = Math.min(Math.max(centre, plot.x), plot.x + plot.width)
|
|
1052
|
+
const y = (Math.min(...ys) + Math.max(...ys)) / 2
|
|
1053
|
+
const floor = plot.y + TIP_TOP_AIR + TIP_CHROME + rows * TIP_ROW
|
|
1054
|
+
if (y >= floor) return { x, y }
|
|
1055
|
+
const toRight = x - plot.x < plot.width / 2
|
|
1056
|
+
const stepped = x + (toRight ? TIP_SIDE_STEP : -TIP_SIDE_STEP)
|
|
1057
|
+
return { x: Math.min(Math.max(stepped, plot.x), plot.x + plot.width), y: floor }
|
|
1058
|
+
}
|
|
1059
|
+
|
|
963
1060
|
function tooltipSpec<T, X extends ChartX>(opts: {
|
|
964
1061
|
input: CartesianInput<T, X>
|
|
965
1062
|
axes: Axes<T>
|
|
@@ -979,7 +1076,11 @@ function tooltipSpec<T, X extends ChartX>(opts: {
|
|
|
979
1076
|
use: quietWhileFollowing,
|
|
980
1077
|
...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
|
|
981
1078
|
portal,
|
|
982
|
-
anchor: input.tooltipBelow
|
|
1079
|
+
anchor: input.tooltipBelow
|
|
1080
|
+
? stripAnchor
|
|
1081
|
+
: visible.some((s) => s.mark === 'bar')
|
|
1082
|
+
? barAnchor(rowSeries.length)
|
|
1083
|
+
: 'group-center',
|
|
983
1084
|
...(input.tooltipBelow && { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET }),
|
|
984
1085
|
content: (points: readonly ChartPoint[]) => {
|
|
985
1086
|
const primary = points[0]
|
|
@@ -1123,6 +1224,7 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
1123
1224
|
zoneScale: under.length > 0 || names,
|
|
1124
1225
|
}),
|
|
1125
1226
|
theme: CHART_THEME,
|
|
1227
|
+
...(input.bare === true && { guides: false as const, margin: 0 }),
|
|
1126
1228
|
...(gradients.length > 0 && { gradients }),
|
|
1127
1229
|
clip: true,
|
|
1128
1230
|
}
|
package/src/charts/legend.tsx
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* its parent's entry. Toggling an entry hides the series from the plot, the tooltip and the auto
|
|
5
5
|
* domain together; hovering one emphasizes it (the definition is rebuilt with `highlighted`).
|
|
6
6
|
*/
|
|
7
|
+
import { useEffect, useLayoutEffect, useRef } from 'react'
|
|
7
8
|
import type { CSSProperties, ReactElement } from 'react'
|
|
8
9
|
import { VX } from '../tokens'
|
|
9
10
|
import classes from './chart-legend.module.css'
|
|
@@ -28,13 +29,17 @@ const ROLE_ORDER = ['series', 'overlay', 'reference'] as const
|
|
|
28
29
|
*/
|
|
29
30
|
const DOTS_GAP = 30
|
|
30
31
|
|
|
32
|
+
const byReferenceFirst = <T,>(a: ChartSeries<T>, b: ChartSeries<T>): number =>
|
|
33
|
+
Number(b.role === 'reference') - Number(a.role === 'reference')
|
|
34
|
+
|
|
31
35
|
/** The entries a series list derives, in display order (by role when `groups`). */
|
|
32
36
|
export function legendEntries<T>(
|
|
33
37
|
series: readonly ChartSeries<T>[],
|
|
34
38
|
groups: boolean,
|
|
35
39
|
): ChartSeries<T>[][] {
|
|
36
40
|
const entries = series.filter((s) => s.legend !== false)
|
|
37
|
-
|
|
41
|
+
// Zones and reference lines, which hue alone cannot name, lead: the compact row folds from its end.
|
|
42
|
+
if (!groups) return entries.length ? [entries.toSorted(byReferenceFirst)] : []
|
|
38
43
|
return ROLE_ORDER.map((role) => entries.filter((s) => (s.role ?? 'series') === role)).filter(
|
|
39
44
|
(g) => g.length > 0,
|
|
40
45
|
)
|
|
@@ -57,8 +62,10 @@ const rowBaseStyle: CSSProperties = {
|
|
|
57
62
|
const rowStyle: CSSProperties = { ...rowBaseStyle, display: 'flex' }
|
|
58
63
|
/** The gaps `chart-legend.module.css` reads, as custom properties. */
|
|
59
64
|
type LegendVars = CSSProperties & Record<'--bc-legend-gap' | '--bc-dots-gap', string>
|
|
65
|
+
// `flex-wrap` is the stylesheet's too: one folded row below 480px, wrapping rows from it.
|
|
66
|
+
const { flexWrap: _wrap, ...autoBaseStyle } = rowBaseStyle
|
|
60
67
|
const autoRowStyle: LegendVars = {
|
|
61
|
-
...
|
|
68
|
+
...autoBaseStyle,
|
|
62
69
|
'--bc-legend-gap': `${VX.legendGap}px`,
|
|
63
70
|
'--bc-dots-gap': `${DOTS_GAP}px`,
|
|
64
71
|
}
|
|
@@ -187,12 +194,69 @@ export type ChartLegendProps<T> = {
|
|
|
187
194
|
hideAtWide?: boolean
|
|
188
195
|
}
|
|
189
196
|
|
|
197
|
+
const VISUALLY_HIDDEN = {
|
|
198
|
+
position: 'absolute',
|
|
199
|
+
width: '1px',
|
|
200
|
+
height: '1px',
|
|
201
|
+
overflow: 'hidden',
|
|
202
|
+
clipPath: 'inset(50%)',
|
|
203
|
+
whiteSpace: 'nowrap',
|
|
204
|
+
} as const
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The compact legend is ONE row (the stylesheet sets `nowrap` below 480px). Entries that do not fit
|
|
208
|
+
* fold into a `+N` chip (named for assistive tech by the folded labels), the last entry first. The
|
|
209
|
+
* entries are in display order: the reference/zone entries, which hue alone cannot name, lead the
|
|
210
|
+
* series (the title and tooltip name those).
|
|
211
|
+
* Measured on the node, never in React state, so a hover or a resize does not re-render.
|
|
212
|
+
*/
|
|
213
|
+
function foldLegend(row: HTMLElement): void {
|
|
214
|
+
const items = [...row.querySelectorAll<HTMLElement>('[data-legend-key]')]
|
|
215
|
+
const more = row.querySelector<HTMLElement>('[data-legend-more]')
|
|
216
|
+
for (const it of items) it.removeAttribute('data-legend-folded')
|
|
217
|
+
more?.setAttribute('hidden', '')
|
|
218
|
+
if (more === null || getComputedStyle(row).flexWrap !== 'nowrap') return
|
|
219
|
+
const display = items
|
|
220
|
+
const folded: HTMLElement[] = []
|
|
221
|
+
while (row.scrollWidth > row.clientWidth + 0.5 && folded.length < display.length - 1) {
|
|
222
|
+
const last = display[display.length - 1 - folded.length]
|
|
223
|
+
if (last === undefined) break
|
|
224
|
+
last.setAttribute('data-legend-folded', '')
|
|
225
|
+
folded.push(last)
|
|
226
|
+
more.removeAttribute('hidden')
|
|
227
|
+
const names = folded.map((f) => f.textContent).join(', ')
|
|
228
|
+
more.textContent = `+${folded.length}`
|
|
229
|
+
more.title = names
|
|
230
|
+
// The folded labels, visually hidden: assistive tech reads `+2: Caution, Danger`.
|
|
231
|
+
const hiddenNames = document.createElement('span')
|
|
232
|
+
hiddenNames.textContent = `: ${names}`
|
|
233
|
+
Object.assign(hiddenNames.style, VISUALLY_HIDDEN)
|
|
234
|
+
more.append(hiddenNames)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
190
238
|
export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null {
|
|
239
|
+
const rowRef = useRef<HTMLFieldSetElement>(null)
|
|
240
|
+
const auto = props.mode === 'auto'
|
|
241
|
+
// Re-fold when the entries change; a resize re-folds through the observer.
|
|
242
|
+
const signature = props.series.map((s) => s.key).join('|')
|
|
243
|
+
// `signature` is intentionally an extra dep: the fold must re-run when the entries change.
|
|
244
|
+
useLayoutEffect(() => {
|
|
245
|
+
if (auto && rowRef.current !== null) foldLegend(rowRef.current)
|
|
246
|
+
}, [auto, signature])
|
|
247
|
+
// Same: `signature` re-subscribes the observer to the re-rendered row.
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
const row = rowRef.current
|
|
250
|
+
if (!auto || row === null || typeof ResizeObserver === 'undefined') return
|
|
251
|
+
const observer = new ResizeObserver(() => foldLegend(row))
|
|
252
|
+
observer.observe(row)
|
|
253
|
+
return () => observer.disconnect()
|
|
254
|
+
}, [auto, signature])
|
|
191
255
|
const groups = legendEntries(props.series, props.groups)
|
|
192
256
|
if (groups.length === 0) return null
|
|
193
|
-
const auto = props.mode === 'auto'
|
|
194
257
|
return (
|
|
195
258
|
<fieldset
|
|
259
|
+
ref={rowRef}
|
|
196
260
|
aria-label="Legend"
|
|
197
261
|
data-basalt-chart-legend={props.mode}
|
|
198
262
|
// `visibility: hidden` is the real guard (nothing is announced, focused or clickable);
|
|
@@ -219,6 +283,7 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
219
283
|
<span
|
|
220
284
|
key={s.key}
|
|
221
285
|
data-legend-key={s.key}
|
|
286
|
+
data-legend-role={s.role ?? 'series'}
|
|
222
287
|
style={itemStyle}
|
|
223
288
|
onMouseEnter={() => props.onHighlight(s.key)}
|
|
224
289
|
onMouseLeave={() => props.onHighlight(null)}
|
|
@@ -231,6 +296,7 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
231
296
|
key={s.key}
|
|
232
297
|
type="button"
|
|
233
298
|
data-legend-key={s.key}
|
|
299
|
+
data-legend-role={s.role ?? 'series'}
|
|
234
300
|
data-basalt-hit=""
|
|
235
301
|
aria-pressed={!off}
|
|
236
302
|
style={itemStyle}
|
|
@@ -245,6 +311,7 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
245
311
|
)
|
|
246
312
|
}),
|
|
247
313
|
])}
|
|
314
|
+
{auto && <span data-legend-more="" hidden style={noteStyle} />}
|
|
248
315
|
</fieldset>
|
|
249
316
|
)
|
|
250
317
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip. Inside a host that
|
|
3
|
+
* reserves a line for it (`StatCard`'s sparkline slot, a strip cell's visual: `data-basalt-hosted`,
|
|
4
|
+
* `--basalt-spark-readout-h`) it sits ABOVE the plot, so it never covers the plotted line, the dashed
|
|
5
|
+
* reference or the dot. A bare `Sparkline` has no such line, so its chip stays inside its own box
|
|
6
|
+
* (placed inline in `Sparkline.tsx`, away from the point). `Sparkline.tsx` slides it with the point
|
|
7
|
+
* (`left` + `translate` by one fraction), which keeps it inside the box at either edge at any width.
|
|
8
|
+
* `--basalt-spark-readout-lift: 0` on a host puts the chip back in the box.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
.root {
|
|
@@ -35,10 +36,62 @@
|
|
|
35
36
|
border-radius: var(--vx-radius-ctrl);
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
/* The host's reserved line: above the plot. The chip's bottom meets the sparkline's own top edge (the
|
|
40
|
+
* layer sits `--basalt-spark-inset` below it). */
|
|
41
|
+
[data-basalt-hosted] .readout {
|
|
42
|
+
top: calc(
|
|
43
|
+
var(--basalt-spark-readout-lift, 1) * -1 *
|
|
44
|
+
(var(--basalt-spark-readout-h, 1.125rem) + var(--basalt-spark-inset, 0px))
|
|
45
|
+
);
|
|
46
|
+
max-height: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
38
49
|
.label {
|
|
39
50
|
opacity: 0.7;
|
|
40
51
|
}
|
|
41
52
|
|
|
53
|
+
.sep {
|
|
54
|
+
white-space: pre;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* A readout that overflows its box first drops the air round its separator and its padding. */
|
|
58
|
+
.readout[data-tight] {
|
|
59
|
+
padding-inline: 2px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.readout[data-tight] .sep {
|
|
63
|
+
letter-spacing: -0.15em;
|
|
64
|
+
word-spacing: -0.25em;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* A readout that still overflows stacks (set in `Sparkline.tsx`): the date on its own line, wrapped
|
|
68
|
+
* not clipped. It sits INSIDE the plot's top band (the lift-0 placement), hosted or bare: a hosted
|
|
69
|
+
* chip grown past the host's one reserved line would cover the figure's delta or qualifier above. */
|
|
70
|
+
.readout[data-stacked] {
|
|
71
|
+
block-size: auto;
|
|
72
|
+
max-height: none;
|
|
73
|
+
padding-block: 1px;
|
|
74
|
+
line-height: 1.25;
|
|
75
|
+
text-overflow: clip;
|
|
76
|
+
white-space: normal;
|
|
77
|
+
overflow-wrap: break-word;
|
|
78
|
+
/* Not the shrink-to-fit width an absolutely positioned box gets: at a point near the right edge
|
|
79
|
+
* that is the sliver right of `left`, and the date would wrap letter by letter. */
|
|
80
|
+
width: max-content;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[data-basalt-hosted] .readout[data-stacked] {
|
|
84
|
+
top: 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.readout[data-stacked] .label {
|
|
88
|
+
display: block;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.readout[data-stacked] .sep {
|
|
92
|
+
display: none;
|
|
93
|
+
}
|
|
94
|
+
|
|
42
95
|
.layer {
|
|
43
96
|
position: absolute;
|
|
44
97
|
pointer-events: none;
|
package/src/charts/state.tsx
CHANGED
|
@@ -76,7 +76,9 @@ const emptyLabel = (state: ChartState | undefined): string =>
|
|
|
76
76
|
* `<Suspense>` fallback built from one) occupies the final chart's height. */
|
|
77
77
|
export function ChartPlaceholder(props: {
|
|
78
78
|
state: ChartState | undefined
|
|
79
|
-
|
|
79
|
+
/** `'content'`: error and empty end at their content (a list or Meter body, no chart to keep the
|
|
80
|
+
* frame for); the chart height law and a stated height keep D37's box. Pending always keeps a box. */
|
|
81
|
+
height?: ChartBoxHeight | 'content'
|
|
80
82
|
/** Error only: the shared Retry button, the same one `ErrorState` renders. */
|
|
81
83
|
onRetry?: () => void
|
|
82
84
|
/** A refetch is in flight: Retry is inert and marked busy. */
|
|
@@ -95,18 +97,25 @@ export function ChartPlaceholder(props: {
|
|
|
95
97
|
// An error keeps the chart's height as a floor (the frame does not jump, `ssr-contract`) and may
|
|
96
98
|
// grow past it rather than clip its action; its anatomy is top-aligned, so the room is plain
|
|
97
99
|
// card below the content, not a block of text floating mid-card.
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const { height } = props
|
|
101
|
+
const fit = (node: ReactElement): ReactElement =>
|
|
102
|
+
height === 'content' && kind !== 'pending' ? (
|
|
103
|
+
node
|
|
104
|
+
) : (
|
|
105
|
+
<ChartBox
|
|
106
|
+
height={height === 'content' ? undefined : height}
|
|
107
|
+
{...(kind === 'error' && { className: growClass })}
|
|
108
|
+
>
|
|
109
|
+
{node}
|
|
110
|
+
</ChartBox>
|
|
111
|
+
)
|
|
103
112
|
if (kind === 'pending')
|
|
104
113
|
return fit(
|
|
105
114
|
<output aria-label="Loading chart" aria-busy="true" className={stateClass} style={style} />,
|
|
106
115
|
)
|
|
107
116
|
const label =
|
|
108
117
|
kind === 'error'
|
|
109
|
-
? toErrorMessage(props.state?.error, 'The
|
|
118
|
+
? toErrorMessage(props.state?.error, 'The request failed.')
|
|
110
119
|
: emptyLabel(props.state)
|
|
111
120
|
const body = props.compact ? (
|
|
112
121
|
<span aria-hidden="true">—</span>
|
package/src/charts/types.ts
CHANGED
|
@@ -132,6 +132,15 @@ export type ZoneSpec = {
|
|
|
132
132
|
to: number
|
|
133
133
|
fill: string
|
|
134
134
|
axisSide?: 'left' | 'right' | undefined
|
|
135
|
+
/**
|
|
136
|
+
* Names the band in the legend (its fill as the swatch, a bar by default), so a zone chart keeps
|
|
137
|
+
* a key at 390 and needs no always-`null` series. `mark` is the swatch shape. `color` is the
|
|
138
|
+
* swatch when the fill is a whisper-alpha wash a 10px swatch would lose (default: the fill, a
|
|
139
|
+
* status tint mapped to its solid).
|
|
140
|
+
*/
|
|
141
|
+
legend?:
|
|
142
|
+
| { label: string; mark?: 'line' | 'bar' | undefined; color?: string | undefined }
|
|
143
|
+
| undefined
|
|
135
144
|
/** A rule on the band's visual `top` (the larger bound) and/or `bottom` (the smaller), whichever
|
|
136
145
|
* of `from`/`to` that is. */
|
|
137
146
|
edge?: ZoneEdge<'top' | 'bottom'> | undefined
|
package/src/cli/shot/detect.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* | craft-1/scale-error, -missing| layout | P1 |
|
|
16
16
|
* | craft-1/off-scale-inset, -gap| layout | P1; P3 when every off value is within 1 px of a step |
|
|
17
17
|
* | craft-3/empty-region | layout | P1 |
|
|
18
|
-
* | craft-1/off-scale-radius | style | P1; P3
|
|
18
|
+
* | craft-1/off-scale-radius | style | P1; P3 within 1 px of a step (never a nested one) |
|
|
19
19
|
* | craft-1/nested-radius-step | style | P1 |
|
|
20
20
|
* | craft-2/font-sizes | style | P1 |
|
|
21
21
|
* | lint/basalt/<rule> | style | P1 for an error, P2 for a warning |
|
|
@@ -121,48 +121,34 @@ function craftOne(a: AnchorMetrics, scale: Scale | undefined): Draft[] {
|
|
|
121
121
|
if (!scale) return []
|
|
122
122
|
const base = { anchor: a.name, route: a.route, where: where(a) }
|
|
123
123
|
const out: Draft[] = []
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
124
|
+
const sides = SIDE_NAMES.map((side) => ({ at: side, v: a.padding[side], nested: false }))
|
|
125
|
+
const gaps = (['row', 'column'] as const).map((axis) => ({
|
|
126
|
+
at: axis,
|
|
127
|
+
v: a.gap[axis],
|
|
128
|
+
nested: false,
|
|
129
|
+
}))
|
|
130
|
+
const radii = [
|
|
131
|
+
{ at: '', v: a.radius, nested: false },
|
|
132
|
+
...a.nested.map((n) => ({ at: `nested ${n.path}`, v: n.radius, nested: true })),
|
|
133
|
+
]
|
|
134
|
+
const groups = [
|
|
135
|
+
['inset', 'layout', 'Padding', 'padding', scale.spacing, sides],
|
|
136
|
+
['gap', 'layout', 'Gap', 'gap', scale.spacing, gaps],
|
|
137
|
+
['radius', 'style', 'Radius', 'radius', scale.radius, radii],
|
|
138
|
+
] as const
|
|
139
|
+
for (const [rule, layer, label, field, steps, items] of groups) {
|
|
140
|
+
const off = items.flatMap(({ at, v, nested }) => {
|
|
141
|
+
const d = offScale(v, Object.values(steps))
|
|
142
|
+
return d === null ? [] : [{ at, v, d, nested }]
|
|
139
143
|
})
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const gap = (['row', 'column'] as const).flatMap((axis) => {
|
|
143
|
-
const d = offScale(a.gap[axis], spacing)
|
|
144
|
-
return d === null ? [] : [{ axis, v: a.gap[axis], d }]
|
|
145
|
-
})
|
|
146
|
-
if (gap.length > 0) {
|
|
144
|
+
if (off.length === 0) continue
|
|
147
145
|
out.push({
|
|
148
146
|
...base,
|
|
149
|
-
rule:
|
|
150
|
-
severity: sizing(
|
|
151
|
-
layer
|
|
152
|
-
cite: `metrics.json anchors[${a.name} ${where(a)}]
|
|
153
|
-
defect:
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const radius = offScale(a.radius, radii)
|
|
158
|
-
if (radius !== null) {
|
|
159
|
-
out.push({
|
|
160
|
-
...base,
|
|
161
|
-
rule: 'craft-1/off-scale-radius',
|
|
162
|
-
severity: sizing([radius]),
|
|
163
|
-
layer: 'style',
|
|
164
|
-
cite: `metrics.json anchors[${a.name} ${where(a)}].radius`,
|
|
165
|
-
defect: `Radius ${String(a.radius)}px is not a radius step (${stepsText(scale.radius)}).`,
|
|
147
|
+
rule: `craft-1/off-scale-${rule}`,
|
|
148
|
+
severity: off.some((o) => o.nested) ? 'P1' : sizing(off.map((o) => o.d)),
|
|
149
|
+
layer,
|
|
150
|
+
cite: `metrics.json anchors[${a.name} ${where(a)}].${field}`,
|
|
151
|
+
defect: `${label} ${off.map((o) => `${o.at} ${o.v}px`.trim()).join(', ')} is not a ${steps === scale.radius ? 'radius' : 'spacing'} step (${stepsText(steps)}).`,
|
|
166
152
|
})
|
|
167
153
|
}
|
|
168
154
|
return out
|