basalt-ui 2.25.0 → 2.27.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/MIGRATING.md +227 -19
  3. package/configs/oxlint-basalt.json +1 -1
  4. package/configs/oxlint-plugin.js +3 -9
  5. package/configs/oxlint-plugin.test.ts +6 -0
  6. package/dist/charts/Bars.d.ts.map +1 -1
  7. package/dist/charts/Bars.js +37 -1
  8. package/dist/charts/ChartCard.d.ts +13 -5
  9. package/dist/charts/ChartCard.d.ts.map +1 -1
  10. package/dist/charts/ChartCard.js +12 -2
  11. package/dist/charts/Sparkline.d.ts.map +1 -1
  12. package/dist/charts/Sparkline.js +106 -10
  13. package/dist/charts/chart-box.module.css +123 -5
  14. package/dist/charts/chart-box.module.css.d.ts +3 -0
  15. package/dist/charts/chart-card.module.css +34 -0
  16. package/dist/charts/chart-card.module.css.d.ts +2 -0
  17. package/dist/charts/chart-legend.module.css +1 -16
  18. package/dist/charts/compile.d.ts +20 -0
  19. package/dist/charts/compile.d.ts.map +1 -1
  20. package/dist/charts/compile.js +99 -3
  21. package/dist/charts/legend.d.ts.map +1 -1
  22. package/dist/charts/legend.js +54 -71
  23. package/dist/charts/sparkline.module.css +13 -9
  24. package/dist/charts/state.d.ts +7 -0
  25. package/dist/charts/state.d.ts.map +1 -1
  26. package/dist/charts/state.js +17 -1
  27. package/dist/cli/shot/capture.d.ts +32 -3
  28. package/dist/cli/shot/capture.d.ts.map +1 -1
  29. package/dist/cli/shot/capture.js +17 -7
  30. package/dist/dashboard/meter-model.d.ts +19 -3
  31. package/dist/dashboard/meter-model.d.ts.map +1 -1
  32. package/dist/dashboard/meter-model.js +155 -13
  33. package/dist/dashboard/meter-parts.d.ts +4 -7
  34. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  35. package/dist/dashboard/meter-parts.js +130 -90
  36. package/dist/dashboard/meter.d.ts +1 -1
  37. package/dist/dashboard/meter.d.ts.map +1 -1
  38. package/dist/dashboard/meter.js +10 -7
  39. package/dist/dashboard/meter.module.css +55 -13
  40. package/dist/dashboard/meter.module.css.d.ts +1 -2
  41. package/dist/dashboard/section.d.ts +1 -2
  42. package/dist/dashboard/section.d.ts.map +1 -1
  43. package/dist/dashboard/section.module.css +8 -7
  44. package/dist/dashboard/stat-card.module.css +17 -0
  45. package/dist/dashboard/stat-strip.d.ts +9 -1
  46. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  47. package/dist/dashboard/stat-strip.js +121 -27
  48. package/dist/dashboard/stat-strip.module.css +51 -3
  49. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  50. package/dist/dashboard/visual-slot.d.ts +4 -0
  51. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  52. package/dist/dashboard/visual-slot.js +2 -0
  53. package/dist/dashboard/widget-header.module.css +9 -0
  54. package/llms.txt +3 -2
  55. package/package.json +1 -1
  56. package/src/charts/Bars.tsx +50 -2
  57. package/src/charts/ChartCard.tsx +32 -5
  58. package/src/charts/Sparkline.tsx +166 -13
  59. package/src/charts/chart-box.module.css +123 -5
  60. package/src/charts/chart-box.module.css.d.ts +3 -0
  61. package/src/charts/chart-card.module.css +34 -0
  62. package/src/charts/chart-card.module.css.d.ts +2 -0
  63. package/src/charts/chart-legend.module.css +1 -16
  64. package/src/charts/compile.ts +153 -3
  65. package/src/charts/legend.tsx +33 -49
  66. package/src/charts/sparkline.module.css +13 -9
  67. package/src/charts/state.tsx +43 -1
  68. package/src/cli/shot/capture.ts +25 -9
  69. package/src/dashboard/meter-model.ts +248 -22
  70. package/src/dashboard/meter-parts.tsx +124 -69
  71. package/src/dashboard/meter.module.css +55 -13
  72. package/src/dashboard/meter.module.css.d.ts +1 -2
  73. package/src/dashboard/meter.tsx +22 -9
  74. package/src/dashboard/section.module.css +8 -7
  75. package/src/dashboard/section.tsx +1 -2
  76. package/src/dashboard/stat-card.module.css +17 -0
  77. package/src/dashboard/stat-strip.module.css +51 -3
  78. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  79. package/src/dashboard/stat-strip.tsx +162 -33
  80. package/src/dashboard/visual-slot.ts +5 -0
  81. package/src/dashboard/widget-header.module.css +9 -0
@@ -15,6 +15,10 @@ import { ruleX, ruleY } from '@tanstack/charts/rule'
15
15
  import { scaleLinear } from '@tanstack/charts/scales/linear'
16
16
  import { scaleUtc } from 'd3-scale'
17
17
  import { portal } from '@tanstack/charts/tooltip/portal'
18
+ import type {
19
+ ChartTooltipPortalExtension,
20
+ ChartTooltipPortalPositionContext,
21
+ } from '@tanstack/charts/tooltip/portal'
18
22
  import type {
19
23
  ChartBuildContext,
20
24
  ChartTooltipAnchorContext,
@@ -1023,6 +1027,20 @@ const stripAnchor = (
1023
1027
  }
1024
1028
  const STRIP_TOOLTIP_PLACEMENT = ['bottom', 'top'] as const
1025
1029
  const STRIP_TOOLTIP_OFFSET = 8
1030
+ /**
1031
+ * A slotted `Bars` (`tooltipBelow` and `bare`): a micro-visual whose tooltip is the one-line chip
1032
+ * (`chart-box.module.css`, `data-basalt-slot`) in the line the cell reserves above the plot. It
1033
+ * anchors to the plot's top edge, flush, and opens upward, never below the plot and never over the
1034
+ * bars; the card clamp's vertical flip does not apply to it.
1035
+ */
1036
+ const slotAnchor = (
1037
+ points: readonly ChartPoint[],
1038
+ { plot }: ChartTooltipAnchorContext,
1039
+ ): { x: number; y: number } => {
1040
+ const xs = points.map((p) => p.x)
1041
+ return { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: plot.y }
1042
+ }
1043
+ const SLOT_TOOLTIP_PLACEMENT = ['top'] as const
1026
1044
 
1027
1045
  /** A tooltip's chrome (title row, padding) and each series row, px: the guess the bar anchor reserves. */
1028
1046
  const TIP_CHROME = 30
@@ -1057,6 +1075,132 @@ const barAnchor =
1057
1075
  return { x: Math.min(Math.max(stepped, plot.x), plot.x + plot.width), y: floor }
1058
1076
  }
1059
1077
 
1078
+ /** The card a tooltip stays inside: a `ChartCard`, a strip cell, a `StatCard` (a Mantine Card). Never a Paper: the nearest small inner one would clamp. */
1079
+ const TIP_CARD = '[data-basalt-chart-card], [data-strip-cell], .mantine-Card-root'
1080
+ /** Air between a card-clamped tooltip and the card's edge, px. */
1081
+ const TIP_CARD_AIR = 4
1082
+ /** A card narrower than this keeps the engine's width and horizontal placement (a ~120px strip
1083
+ * cell would squeeze a tooltip to its 6rem label floor); the vertical rule applies to every card. */
1084
+ const TIP_CARD_ROOMY = 192
1085
+
1086
+ /**
1087
+ * The engine places a portalled tooltip against the viewport, so it opens past the card's edge, over
1088
+ * the neighbouring card or the section heading above. Its placements (a hover, and its own resize /
1089
+ * scroll repositions, which never pass through `position`) all write the element's inline `left` and
1090
+ * `top`, so each write is followed by a settle inside the card (`settleInCard`).
1091
+ */
1092
+ /** What a card clamp does: `card` a chart tooltip (both axes, the card's width), `slot` a slotted
1093
+ * `Bars` chip (flush above its plot), `strip` a `BandStrip`'s (sideways only, as before Wave 39). */
1094
+ type TipMode = 'card' | 'slot' | 'strip'
1095
+
1096
+ const cardPortal = (mode: TipMode): ChartTooltipPortalExtension => ({
1097
+ id: portal.id,
1098
+ create(context, options) {
1099
+ const inner = portal.create(context, options)
1100
+ const { element, container } = context
1101
+ if (mode === 'slot') element.dataset['basaltSlot'] = ''
1102
+ let last: ChartTooltipPortalPositionContext | undefined
1103
+ const watch = new MutationObserver(() => {
1104
+ if (last) settleInCard(element, container, last, mode)
1105
+ })
1106
+ watch.observe(element, { attributes: true, attributeFilter: ['style'] })
1107
+ return {
1108
+ ...inner,
1109
+ position(next) {
1110
+ last = next
1111
+ return inner.position(next)
1112
+ },
1113
+ destroy() {
1114
+ watch.disconnect()
1115
+ inner.destroy()
1116
+ },
1117
+ }
1118
+ },
1119
+ })
1120
+
1121
+ /**
1122
+ * Keeps a tooltip inside its card on both axes. A card with room lets the tooltip grow up to its
1123
+ * width before a label wraps, and re-centres it on the anchor at that width. A tooltip that would
1124
+ * cross the card's top or bottom flips to the other side of its anchor when that side fits; neither
1125
+ * fitting, it slides in; taller than the card, it aligns to the card's top (the only overflow).
1126
+ * A `slot` tooltip (a slotted `Bars`, one line) keeps its place above the plot, centred on the
1127
+ * anchor, capped at the card's width and held inside the card sideways and at its top. A hidden or unmeasured tooltip is left alone, and an unchanged position
1128
+ * is not written back (a write re-runs this).
1129
+ */
1130
+ export function settleInCard(
1131
+ tip: HTMLElement,
1132
+ within: Element,
1133
+ ctx: ChartTooltipPortalPositionContext,
1134
+ mode: TipMode = 'card',
1135
+ ): void {
1136
+ const slot = mode === 'slot'
1137
+ if (tip.hidden || tip.offsetHeight === 0) return
1138
+ const card = within.closest(TIP_CARD)?.getBoundingClientRect()
1139
+ const surface = ctx.surface.element.getBoundingClientRect()
1140
+ const { width: sceneW, height: sceneH } = ctx.scene
1141
+ let left = Number.parseFloat(tip.style.left)
1142
+ let top = Number.parseFloat(tip.style.top)
1143
+ if (!card || Number.isNaN(left) || Number.isNaN(top) || !surface.width || !sceneW || !sceneH)
1144
+ return
1145
+ const w0 = tip.offsetWidth
1146
+ const toClient = (p: { x: number; y: number }): { x: number; y: number } => ({
1147
+ x: surface.left + (p.x / sceneW) * surface.width,
1148
+ y: surface.top + (p.y / sceneH) * surface.height,
1149
+ })
1150
+ if (mode === 'strip') {
1151
+ // A `BandStrip`: sideways only, as before; the engine's width and vertical placement stand.
1152
+ if (w0 + 2 * TIP_CARD_AIR <= card.width)
1153
+ left = Math.min(Math.max(left, card.left + TIP_CARD_AIR), card.right - w0 - TIP_CARD_AIR)
1154
+ if (Math.abs(left - Number.parseFloat(tip.style.left)) > 0.5) tip.style.left = `${left}px`
1155
+ return
1156
+ }
1157
+ const roomy = card.width >= TIP_CARD_ROOMY
1158
+ // A wider tooltip is centred again on its anchor at that width, and held inside the card.
1159
+ const grown = roomy || slot
1160
+ if (!grown) {
1161
+ // A card that shrank under a wider tooltip: the engine's own width and cap again.
1162
+ if (tip.dataset['basaltMax'] !== undefined) {
1163
+ tip.style.maxWidth = tip.dataset['basaltMax']
1164
+ tip.style.removeProperty('width')
1165
+ delete tip.dataset['basaltMax']
1166
+ }
1167
+ } else {
1168
+ tip.dataset['basaltMax'] ??= tip.style.maxWidth
1169
+ // Grows to its content, capped at the card's width; the engine's shrink-to-fit would narrow it
1170
+ // to the room right of its `left`.
1171
+ const cap = `${card.width - 2 * TIP_CARD_AIR}px`
1172
+ if (tip.style.maxWidth !== cap) tip.style.maxWidth = cap
1173
+ if (tip.style.width !== 'max-content') tip.style.width = 'max-content'
1174
+ }
1175
+ const [w, h] = [tip.offsetWidth, tip.offsetHeight]
1176
+ const anchor = toClient(ctx.anchor)
1177
+ const gap = Math.max(0, Number.isFinite(ctx.offset) ? (ctx.offset ?? 10) : 10)
1178
+ const minTop = card.top + TIP_CARD_AIR
1179
+ const maxTop = card.bottom - TIP_CARD_AIR - h
1180
+ const side = tip.dataset['placement']
1181
+ if (slot) {
1182
+ // Flush above the plot, in the reserved line: no flip, never pushed down over the bars.
1183
+ top = Math.max(anchor.y - gap - h, card.top)
1184
+ left = anchor.x - w / 2
1185
+ } else if (side === 'top' || side === 'bottom') {
1186
+ const above = anchor.y - gap - h
1187
+ const below = anchor.y + gap
1188
+ const order = side === 'top' ? [above, below] : [below, above]
1189
+ const fits = order.findIndex((t) => t >= minTop && t <= maxTop)
1190
+ top = order[Math.max(fits, 0)] ?? top
1191
+ if (fits > 0) tip.dataset['placement'] = side === 'top' ? 'bottom' : 'top'
1192
+ if (roomy) left = anchor.x - w / 2
1193
+ }
1194
+ if (!slot) top = maxTop < minTop ? minTop : Math.min(Math.max(top, minTop), maxTop)
1195
+ if (grown || w + 2 * TIP_CARD_AIR <= card.width)
1196
+ left = Math.min(
1197
+ Math.max(left, card.left + TIP_CARD_AIR),
1198
+ Math.max(card.right - w - TIP_CARD_AIR, card.left + TIP_CARD_AIR),
1199
+ )
1200
+ if (Math.abs(left - Number.parseFloat(tip.style.left)) > 0.5) tip.style.left = `${left}px`
1201
+ if (Math.abs(top - Number.parseFloat(tip.style.top)) > 0.5) tip.style.top = `${top}px`
1202
+ }
1203
+
1060
1204
  function tooltipSpec<T, X extends ChartX>(opts: {
1061
1205
  input: CartesianInput<T, X>
1062
1206
  axes: Axes<T>
@@ -1069,19 +1213,25 @@ function tooltipSpec<T, X extends ChartX>(opts: {
1069
1213
  }): NonNullable<CartesianDefinition['tooltip']> {
1070
1214
  const { input, axes, visible, keys, visibleKeys, formatX, dayOnly } = opts
1071
1215
  const hidden = input.series.filter((s) => !visibleKeys.has(s.key))
1216
+ const slot = input.tooltipBelow === true && input.bare === true
1072
1217
  const rowSeries = (input.reverseRows ? visible.toReversed() : visible).filter(
1073
1218
  (s) => s.tooltip !== false,
1074
1219
  )
1075
1220
  return {
1076
1221
  use: quietWhileFollowing,
1077
1222
  ...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
1078
- portal,
1223
+ portal: cardPortal(slot ? 'slot' : input.tooltipBelow === true ? 'strip' : 'card'),
1079
1224
  anchor: input.tooltipBelow
1080
- ? stripAnchor
1225
+ ? slot
1226
+ ? slotAnchor
1227
+ : stripAnchor
1081
1228
  : visible.some((s) => s.mark === 'bar')
1082
1229
  ? barAnchor(rowSeries.length)
1083
1230
  : 'group-center',
1084
- ...(input.tooltipBelow && { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET }),
1231
+ ...(input.tooltipBelow &&
1232
+ (slot
1233
+ ? { placement: SLOT_TOOLTIP_PLACEMENT, offset: 0 }
1234
+ : { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET })),
1085
1235
  content: (points: readonly ChartPoint[]) => {
1086
1236
  const primary = points[0]
1087
1237
  if (!primary) return { rows: [] }
@@ -29,8 +29,8 @@ const ROLE_ORDER = ['series', 'overlay', 'reference'] as const
29
29
  */
30
30
  const DOTS_GAP = 30
31
31
 
32
- const byReferenceFirst = <T,>(a: ChartSeries<T>, b: ChartSeries<T>): number =>
33
- Number(b.role === 'reference') - Number(a.role === 'reference')
32
+ const byReferenceLast = <T,>(a: ChartSeries<T>, b: ChartSeries<T>): number =>
33
+ Number(a.role === 'reference') - Number(b.role === 'reference')
34
34
 
35
35
  /** The entries a series list derives, in display order (by role when `groups`). */
36
36
  export function legendEntries<T>(
@@ -38,8 +38,8 @@ export function legendEntries<T>(
38
38
  groups: boolean,
39
39
  ): ChartSeries<T>[][] {
40
40
  const entries = series.filter((s) => s.legend !== false)
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)] : []
41
+ // Series lead, zones and reference lines follow: the compact row wraps between entries and names them all.
42
+ if (!groups) return entries.length ? [entries.toSorted(byReferenceLast)] : []
43
43
  return ROLE_ORDER.map((role) => entries.filter((s) => (s.role ?? 'series') === role)).filter(
44
44
  (g) => g.length > 0,
45
45
  )
@@ -62,7 +62,7 @@ const rowBaseStyle: CSSProperties = {
62
62
  const rowStyle: CSSProperties = { ...rowBaseStyle, display: 'flex' }
63
63
  /** The gaps `chart-legend.module.css` reads, as custom properties. */
64
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.
65
+ // `flex-wrap` is the stylesheet's too, so the same rule wraps at every width.
66
66
  const { flexWrap: _wrap, ...autoBaseStyle } = rowBaseStyle
67
67
  const autoRowStyle: LegendVars = {
68
68
  ...autoBaseStyle,
@@ -94,11 +94,17 @@ const buttonStyle: CSSProperties = {
94
94
  border: '1px solid transparent',
95
95
  display: 'inline-flex',
96
96
  alignItems: 'center',
97
+ // An entry never wraps inside itself (a threshold stays with its name) and never outgrows the row:
98
+ // the label ellipsizes at the row's width (`labelStyle`), its full name in `title`.
99
+ whiteSpace: 'nowrap',
100
+ maxWidth: '100%',
101
+ minWidth: 0,
97
102
  gap: 6,
98
103
  cursor: 'pointer',
99
104
  borderRadius: VX.radiusCtrl,
100
105
  }
101
- const noteStyle: CSSProperties = { color: VX.axis }
106
+ const noteStyle: CSSProperties = { color: VX.axis, flex: 'none' }
107
+ const labelStyle: CSSProperties = { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' }
102
108
 
103
109
  /**
104
110
  * A legend entry that may be a sign-coloured bar: `colorNegative` is the below-zero colour and the
@@ -194,63 +200,40 @@ export type ChartLegendProps<T> = {
194
200
  hideAtWide?: boolean
195
201
  }
196
202
 
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
203
  /**
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.
204
+ * The compact legend names every entry at every width: nothing folds, the row wraps between entries
205
+ * (series, then overlays, then references). A label that ellipsizes carries its full name in
206
+ * `title`; one that fits carries none. Measured on the node, never in React state.
212
207
  */
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)
208
+ function titleClipped(row: HTMLElement): void {
209
+ for (const label of row.querySelectorAll<HTMLElement>('[data-legend-label]')) {
210
+ if (label.scrollWidth > label.clientWidth + 0.5) label.title = label.textContent ?? ''
211
+ else label.removeAttribute('title')
235
212
  }
236
213
  }
237
214
 
238
215
  export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null {
239
216
  const rowRef = useRef<HTMLFieldSetElement>(null)
240
217
  const auto = props.mode === 'auto'
241
- // Re-fold when the entries change; a resize re-folds through the observer.
218
+ // Re-title when the entries change; a resize re-titles through the observer.
242
219
  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.
220
+ // `signature` is intentionally an extra dep: the titles must re-run when the entries change.
244
221
  useLayoutEffect(() => {
245
- if (auto && rowRef.current !== null) foldLegend(rowRef.current)
222
+ if (auto && rowRef.current !== null) titleClipped(rowRef.current)
246
223
  }, [auto, signature])
247
224
  // Same: `signature` re-subscribes the observer to the re-rendered row.
248
225
  useEffect(() => {
249
226
  const row = rowRef.current
250
227
  if (!auto || row === null || typeof ResizeObserver === 'undefined') return
251
- const observer = new ResizeObserver(() => foldLegend(row))
228
+ const observer = new ResizeObserver(() => titleClipped(row))
252
229
  observer.observe(row)
253
- return () => observer.disconnect()
230
+ // A web font landing changes the entry widths without resizing the row.
231
+ let live = true
232
+ void document.fonts?.ready?.then(() => live && titleClipped(row))
233
+ return () => {
234
+ live = false
235
+ observer.disconnect()
236
+ }
254
237
  }, [auto, signature])
255
238
  const groups = legendEntries(props.series, props.groups)
256
239
  if (groups.length === 0) return null
@@ -273,7 +256,9 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
273
256
  const content = (
274
257
  <>
275
258
  <Swatch s={s} mode={props.mode} />
276
- <span>{s.label}</span>
259
+ <span style={labelStyle} data-legend-label="">
260
+ {s.label}
261
+ </span>
277
262
  {s.note !== undefined && <span style={noteStyle}>{s.note}</span>}
278
263
  </>
279
264
  )
@@ -311,7 +296,6 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
311
296
  )
312
297
  }),
313
298
  ])}
314
- {auto && <span data-legend-more="" hidden style={noteStyle} />}
315
299
  </fieldset>
316
300
  )
317
301
  }
@@ -31,7 +31,13 @@
31
31
  text-overflow: ellipsis;
32
32
  white-space: nowrap;
33
33
  pointer-events: none;
34
- background: var(--vx-tooltip-bg);
34
+ /* Opaque in both schemes: `--vx-tooltip-bg` is translucent in dark, and a footer under the chip
35
+ * would ghost through it, so the tint is layered over the elevated surface. */
36
+ background: linear-gradient(
37
+ var(--basalt-tooltip-surface, var(--vx-tooltip-bg)),
38
+ var(--basalt-tooltip-surface, var(--vx-tooltip-bg))
39
+ )
40
+ var(--vx-surface-elevated);
35
41
  border: 1px solid var(--vx-tooltip-border);
36
42
  border-radius: var(--vx-radius-ctrl);
37
43
  }
@@ -54,19 +60,17 @@
54
60
  white-space: pre;
55
61
  }
56
62
 
57
- /* A readout that overflows its box first drops the air round its separator and its padding. */
63
+ /* A readout that overflows its box first shrinks its padding. The separator and the air round it
64
+ * never drop. */
58
65
  .readout[data-tight] {
59
66
  padding-inline: 2px;
60
67
  }
61
68
 
62
- .readout[data-tight] .sep {
63
- letter-spacing: -0.15em;
64
- word-spacing: -0.25em;
65
- }
66
-
67
69
  /* 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
+ * not clipped. It sits INSIDE the plot (the lift-0 placement), hosted or bare: a hosted chip grown
71
+ * past the host's one reserved line would cover the figure's delta or qualifier above. A hosted
72
+ * line's chip is then placed by `Sparkline.tsx` where the plotted line is not (`top`/`margin-left`
73
+ * inline); `top: 0` is the fallback. */
70
74
  .readout[data-stacked] {
71
75
  block-size: auto;
72
76
  max-height: none;
@@ -7,6 +7,7 @@ import { toErrorMessage } from '../common/errors'
7
7
  import { RetryButton } from '../common/retry-button'
8
8
  import { VX } from '../tokens'
9
9
  import { ChartBox, growClass, stateClass } from './box'
10
+ import boxClasses from './chart-box.module.css'
10
11
  import type { ChartBoxHeight } from './box'
11
12
  import type { ChartState } from './types'
12
13
 
@@ -37,6 +38,43 @@ const pendingStyle: CSSProperties = {
37
38
  background: `linear-gradient(90deg, transparent, ${VX.surface.subtle}, transparent)`,
38
39
  }
39
40
 
41
+ /** Bar ghost heights (% of the plot) of a pending plot: a mild rise, not data. */
42
+ const GHOST_BARS = [38, 52, 44, 66, 58, 74, 62, 48] as const
43
+
44
+ /**
45
+ * The shape a pending plot draws: `'bars'` (default), `'line'` for a line or area chart, or a bar
46
+ * count when the loaded chart's data length is known (a 6-month chart loads 6 bars).
47
+ */
48
+ export type PlotGhostShape = 'bars' | 'line' | number
49
+
50
+ /** A mild rise across the width, in a 100 x 40 box stretched to the plot. */
51
+ const GHOST_LINE = '0,30 12,26 25,28 38,18 50,22 62,12 75,16 88,8 100,12'
52
+
53
+ /** The loaded shape of a plot, drawn in neutral tone (`chart-box.module.css` `.ghost`). */
54
+ function PlotGhost({ shape = 'bars' }: { shape?: PlotGhostShape }): ReactElement {
55
+ if (shape === 'line')
56
+ return (
57
+ <div aria-hidden="true" data-basalt-plot-ghost="line" className={boxClasses.ghost}>
58
+ <svg viewBox="0 0 100 40" preserveAspectRatio="none" className={boxClasses.ghostLine}>
59
+ <polyline points={GHOST_LINE} vectorEffect="non-scaling-stroke" />
60
+ </svg>
61
+ </div>
62
+ )
63
+ const count =
64
+ typeof shape === 'number' ? Math.max(1, Math.min(Math.floor(shape), 60)) : GHOST_BARS.length
65
+ return (
66
+ <div aria-hidden="true" data-basalt-plot-ghost="bars" className={boxClasses.ghost}>
67
+ {Array.from({ length: count }, (_, i) => (
68
+ <span
69
+ key={i}
70
+ className={boxClasses.ghostBar}
71
+ style={{ height: `${GHOST_BARS[i % GHOST_BARS.length]}%` }}
72
+ />
73
+ ))}
74
+ </div>
75
+ )
76
+ }
77
+
40
78
  // The error idiom (D28, SPEC § 6.12): a status dot + a word + the message + the action, on the
41
79
  // neutral surface. The dot is drawn from `--vx-*` tokens here — `src/charts/**` stays Mantine-free and `theme/status-dot` sits in the
42
80
  // Mantine-coupled theme layer.
@@ -90,6 +128,8 @@ export function ChartPlaceholder(props: {
90
128
  compact?: boolean
91
129
  /** Error only: what failed to load, "Could not load {noun}". Default: no noun. */
92
130
  noun?: string
131
+ /** Pending only: the ghost's shape. Default `'bars'`. */
132
+ ghost?: PlotGhostShape
93
133
  }): ReactElement | null {
94
134
  const kind = resolveChartState(props.state)
95
135
  if (kind === null) return null
@@ -111,7 +151,9 @@ export function ChartPlaceholder(props: {
111
151
  )
112
152
  if (kind === 'pending')
113
153
  return fit(
114
- <output aria-label="Loading chart" aria-busy="true" className={stateClass} style={style} />,
154
+ <output aria-label="Loading chart" aria-busy="true" className={stateClass} style={style}>
155
+ {!props.compact && <PlotGhost {...(props.ghost !== undefined && { shape: props.ghost })} />}
156
+ </output>,
115
157
  )
116
158
  const label =
117
159
  kind === 'error'
@@ -140,20 +140,22 @@ export function withParam(route: string, state: ShotState): string {
140
140
  return `${path}${path.includes('?') ? '&' : '?'}shot-state=${state}${fragment}`
141
141
  }
142
142
 
143
- /** The rect union of `boxes`, grown by `margin` and clamped to the viewport (`tall`: its current height). */
143
+ /** The rect union of `boxes`, grown by `margin` and clamped to the viewport (`tall`: its current height); null when nothing of it is inside. */
144
144
  export function unionClip(
145
145
  boxes: readonly Box[],
146
146
  margin: number,
147
147
  viewport: Viewport,
148
148
  tall?: number,
149
- ): Box {
149
+ ): Box | null {
150
150
  const { width, height: base } = VIEWPORT_SPECS[viewport]
151
151
  const height = tall ?? base
152
152
  const left = Math.max(0, Math.min(...boxes.map((b) => b.x)) - margin)
153
153
  const top = Math.max(0, Math.min(...boxes.map((b) => b.y)) - margin)
154
154
  const right = Math.min(width, Math.max(...boxes.map((b) => b.x + b.width)) + margin)
155
155
  const bottom = Math.min(height, Math.max(...boxes.map((b) => b.y + b.height)) + margin)
156
- return { x: left, y: top, width: Math.max(1, right - left), height: Math.max(1, bottom - top) }
156
+ return right <= left || bottom <= top
157
+ ? null
158
+ : { x: left, y: top, width: right - left, height: bottom - top }
157
159
  }
158
160
 
159
161
  /** One screenshot with the options every shot shares. */
@@ -170,6 +172,19 @@ const snap = (
170
172
  ...extra,
171
173
  })
172
174
 
175
+ /** A clip of `targets` re-measured against the live page height (`c.height` goes stale after a reflow); an empty clip is retried once after a frame, then fails. */
176
+ export async function snapClip(c: Ctx, path: string, targets: readonly PwLocator[]): Promise<void> {
177
+ for (let retry = true; ; retry = false) {
178
+ const live = await c.page.evaluate<number>('window.innerHeight')
179
+ const boxes = (await Promise.all(targets.map((t) => t.boundingBox()))).filter((b) => b !== null)
180
+ const clip =
181
+ boxes.length === targets.length && unionClip(boxes, FOCUS_MARGIN_PX, c.viewport, live)
182
+ if (clip) return void (await snap(c.page, path, { clip }))
183
+ if (!retry) throw new Error('Clipped area is either empty or outside the resulting image')
184
+ await c.page.evaluate(FRAMES)
185
+ }
186
+ }
187
+
173
188
  function record(c: Ctx, { name, state, status, file, note, stateful }: Outcome): void {
174
189
  const { route, scheme, viewport } = c
175
190
  c.shots.push({
@@ -545,6 +560,9 @@ export async function hoverTrigger(target: PwLocator): Promise<void> {
545
560
  await target.hover({ timeout: HOVER_TIMEOUT_MS, ...(position && { position }) })
546
561
  }
547
562
 
563
+ const tipOf = (c: Ctx, describedBy: string): PwLocator =>
564
+ c.page.locator(visibleTooltip(describedBy)).first()
565
+
548
566
  /**
549
567
  * The box of the tooltip an action opened, or null when none shows up. Call `markVisibleTooltips`
550
568
  * before the action; `describedBy` is the trigger's own tooltip id, when it has one.
@@ -554,7 +572,7 @@ async function openTooltipBox(
554
572
  describedBy: string,
555
573
  timeout = TIP_PROBE_MS,
556
574
  ): Promise<Box | null> {
557
- const tip = c.page.locator(visibleTooltip(describedBy)).first()
575
+ const tip = tipOf(c, describedBy)
558
576
  try {
559
577
  await tip.waitFor({ state: 'visible', timeout })
560
578
  } catch {
@@ -586,7 +604,7 @@ async function captureHover(c: Ctx, name: string): Promise<void> {
586
604
  const describedBy = idOf(await target.evaluate(describedByOf))
587
605
  const [box, tip] = [await settledBox(anchor), await openTooltipBox(c, describedBy)]
588
606
  if (!box || !tip) return void (await snap(anchor, path))
589
- await snap(c.page, path, { clip: unionClip([box, tip], FOCUS_MARGIN_PX, c.viewport, c.height) })
607
+ await snapClip(c, path, [anchor, tipOf(c, describedBy)])
590
608
  })
591
609
  await c.page.mouse.move(0, 0)
592
610
  }
@@ -645,9 +663,7 @@ async function captureFocus(c: Ctx, name: string): Promise<void> {
645
663
  ),
646
664
  )
647
665
  const tip = await openTooltipBox(c, focused)
648
- await snap(c.page, path, {
649
- clip: unionClip(tip ? [box, tip] : [box], FOCUS_MARGIN_PX, c.viewport, c.height),
650
- })
666
+ await snapClip(c, path, tip ? [anchor, tipOf(c, focused)] : [anchor])
651
667
  })
652
668
  await c.page.evaluate('document.activeElement?.blur()')
653
669
  }
@@ -666,7 +682,7 @@ async function captureTooltip(c: Ctx, name: string): Promise<void> {
666
682
  if (!t) throw new Error('no visible [role="tooltip"] after hover')
667
683
  const a = await settledBox(anchor)
668
684
  if (!a) throw new Error('tooltip or anchor has no box')
669
- await snap(c.page, path, { clip: unionClip([a, t], FOCUS_MARGIN_PX, c.viewport, c.height) })
685
+ await snapClip(c, path, [anchor, tipOf(c, describedBy)])
670
686
  })
671
687
  await c.page.mouse.move(0, 0)
672
688
  }