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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basalt-ui",
3
- "version": "2.25.0",
3
+ "version": "2.27.0",
4
4
  "description": "Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets",
5
5
  "keywords": [
6
6
  "charts",
@@ -4,9 +4,11 @@
4
4
  * stack diverges around the baseline (the 1.x `negativeBars`, now just a signed value). Zones,
5
5
  * reference lines, legend, cursor and tooltip are the rung's. In a visual slot (a `StatCard`
6
6
  * `sparkline`, a strip cell's `visual`) it drops both axes, the grid, the margin and the legend and
7
- * fills the slot like a `Sparkline`: a small histogram, its bins named in the tooltip below it.
7
+ * fills the slot like a `Sparkline`: a small histogram whose tooltip is the one-line chip
8
+ * (`<value> · <x label>`) in the line the host reserves above the plot.
8
9
  */
9
10
  import { barY } from '@tanstack/charts/bar'
11
+ import { dot } from '@tanstack/charts/dot'
10
12
  import { group } from '@tanstack/charts/group'
11
13
  import { stack } from '@tanstack/charts/stack'
12
14
  import { useCallback, useContext, useMemo } from 'react'
@@ -66,6 +68,8 @@ export type BarsProps<T, X extends ChartX = ChartX> = Omit<
66
68
  }
67
69
 
68
70
  const DEFAULT_BAR_OPACITY = 0.85
71
+ /** The empty-bin marker's radius, px: the plot's floor clips it to a 2px-high tick. */
72
+ const EMPTY_BIN_R = 2
69
73
  /** The faintest shade told-apart-by-shade series step down to. */
70
74
  const SHADE_FLOOR = 0.4
71
75
 
@@ -104,12 +108,55 @@ function guardLogStack(layout: string, onLog: boolean): void {
104
108
  warnedLogStack = true
105
109
  }
106
110
 
111
+ /**
112
+ * A slotted chart has no axes to name the hovered bin, and an empty bin has no bar to light: the
113
+ * readout says `0 runs · 16 Oct 02:00` and nothing in the plot would mark where. Each bin whose
114
+ * stack sums to zero gets a baseline mark (a half-dot on the plot's floor), hidden until that x is hovered (the same `focus: 'x'`
115
+ * state that takes a drawn bar to full strength).
116
+ */
117
+ function emptyBinTicks<T, X extends ChartX>(rows: readonly PlotRow<T, X>[]): ChartMarks {
118
+ // A gap (`y: null` on every series) is an absence, not a zero: only a bin with a value counts.
119
+ const sums = new Map<string, { row: PlotRow<T, X>; sum: number; values: number }>()
120
+ for (const row of rows) {
121
+ const key = String(row.x instanceof Date ? row.x.getTime() : row.x)
122
+ const entry = sums.get(key) ?? { row, sum: 0, values: 0 }
123
+ if (row.y !== null && Number.isFinite(row.y)) {
124
+ entry.sum += Math.abs(row.y)
125
+ entry.values += 1
126
+ }
127
+ sums.set(key, entry)
128
+ }
129
+ const empty = [...sums.values()].filter((e) => e.values > 0 && e.sum === 0).map((e) => e.row)
130
+ if (empty.length === 0) return []
131
+ return [
132
+ dot(empty, {
133
+ id: 'empty-bins',
134
+ x: rowX,
135
+ y: () => 0,
136
+ r: EMPTY_BIN_R,
137
+ fill: VX.muted,
138
+ fillOpacity: 0,
139
+ states: [{ when: { focus: 'x' }, style: { fillOpacity: 1 } }],
140
+ }),
141
+ ]
142
+ }
143
+
144
+ /** Whether the baseline (y = 0) is on the plot: not on a log axis, not in a domain that starts above it. */
145
+ function floorIsZero<T>(y: BarsProps<T>['y']): boolean {
146
+ if (y?.scale === 'log') return false
147
+ const domain = y?.domain
148
+ if (Array.isArray(domain)) return domain[0] <= 0 && domain[1] >= 0
149
+ if (typeof domain === 'function') return false
150
+ return (y?.autoMinCeil ?? 0) <= 0
151
+ }
152
+
107
153
  export function Bars<T, X extends ChartX = ChartX>(props: BarsProps<T, X>): ReactElement {
108
154
  const { bars: given, lines, layout = 'stacked', barOpacity, ...rest } = props
109
155
  const bars = useMemo(() => shadeSharedColors(given, barOpacity), [given, barOpacity])
110
156
  const sharedColor = bars.some((b, i) => bars.findIndex((o) => o.color === b.color) !== i)
111
157
  guardLogStack(layout, bars.length > 0 && rest.y?.scale === 'log')
112
158
  const sample = rest.data[0]
159
+ const zeroFloor = floorIsZero(rest.y)
113
160
  const bare = useContext(VisualSlotContext) !== null
114
161
  const series = useMemo<ChartSeries<T>[]>(
115
162
  () => [
@@ -165,13 +212,14 @@ export function Bars<T, X extends ChartX = ChartX>(props: BarsProps<T, X>): Reac
165
212
  : stack({ order, ...(layout === 'normalized' && { offset: 'normalize' }) }),
166
213
  }),
167
214
  )
215
+ if (bare && zeroFloor) out.push(...emptyBinTicks(rows))
168
216
  for (const s of plot.visible) {
169
217
  if (barKeys.has(s.key)) continue
170
218
  out.push(lineMark(plot, s))
171
219
  }
172
220
  return out
173
221
  },
174
- [bars, layout, barOpacity, sharedColor],
222
+ [bars, layout, barOpacity, sharedColor, bare, zeroFloor],
175
223
  )
176
224
 
177
225
  return (
@@ -136,9 +136,13 @@ type ChartCardBaseProps = BasaltProps &
136
136
  deltaPolarity?: DeltaPolarity | undefined
137
137
  /** A mono count tag after the title. */
138
138
  count?: number | undefined
139
- /** Right-aligned controls. */
139
+ /** Right-aligned controls. A `<Text size="xs">` caption here renders at 11 (the chart-text step,
140
+ * beside the plot's ticks); wrap it in a `span` or give it your own class to opt out. */
140
141
  actions?: ReactNode
141
- /** A resolved state replaces `children` with its placeholder; the header stays. */
142
+ /** A resolved state replaces `children` with its placeholder; the header stays. The card learns
143
+ * a state only from here: a body that draws its own loading or empty line (`Meter loading`,
144
+ * `BarList emptyText`) must ALSO be reported here (`{ pending: true }`, `{ empty }`), or the
145
+ * `facts` above it render over a state they contradict. */
142
146
  state?: ChartState | undefined
143
147
  /** Body height while a placeholder shows. Default: the chart height law, i.e. exactly the box an
144
148
  * unsized chart takes — pass the chart's own `height` when it states one, so a `<Suspense
@@ -148,6 +152,9 @@ type ChartCardBaseProps = BasaltProps &
148
152
  * its own loading (`BarList loading`, a loading `Meter`); a children-less `<Suspense
149
153
  * fallback>` should pass a numeric height instead. */
150
154
  placeholderHeight?: number | ResponsiveChartHeight | 'content' | undefined
155
+ /** The pending plot's ghost: `'bars'` (default), `'line'` for a line or area chart, or the bar
156
+ * count when the loaded chart's data length is known. */
157
+ ghost?: 'bars' | 'line' | number | undefined
151
158
  /** Placeholder data is showing: the facts row dims with the plot (a strip cell's `stale`). */
152
159
  stale?: boolean | undefined
153
160
  /** What an errored `state` names: "Could not load {stateNoun}". Default: no noun. */
@@ -163,8 +170,9 @@ type ChartCardBaseProps = BasaltProps &
163
170
 
164
171
  /**
165
172
  * `facts` replaces the legacy `value`/`delta` hero: the two are mutually exclusive in the type. The
166
- * facts show only at rest: while `state` is pending, errored or empty the figure would sit above a
167
- * skeleton or a placeholder that contradicts it, so the header keeps its title row alone.
173
+ * figures show only at rest: while `state` is errored or empty one would sit above a placeholder that
174
+ * contradicts it, so the header keeps its title row alone. While pending the row keeps its footprint
175
+ * as a skeleton (a figure bar and, with a `subtitle`, a basis line), never the stale figure.
168
176
  */
169
177
  export type ChartCardProps = ChartCardBaseProps &
170
178
  (
@@ -232,6 +240,18 @@ function Facts({
232
240
  )
233
241
  }
234
242
 
243
+ /** The facts row of a pending card: bars at the loaded row's height, no figure. */
244
+ function FactsSkeleton({ basis }: { basis: boolean }): ReactElement {
245
+ return (
246
+ <div data-basalt-facts-skeleton="" aria-hidden="true" className={classes.facts}>
247
+ <div className={classes.factsRow}>
248
+ <span className={classes.skeletonFigure} />
249
+ </div>
250
+ {basis && <p className={cx(classes.factsBasis, classes.skeletonBasis)} />}
251
+ </div>
252
+ )
253
+ }
254
+
235
255
  export function ChartCard({
236
256
  actions,
237
257
  state,
@@ -239,6 +259,7 @@ export function ChartCard({
239
259
  stateAction,
240
260
  stale,
241
261
  stateNoun,
262
+ ghost,
242
263
  onRetry,
243
264
  retrying,
244
265
  className,
@@ -251,8 +272,12 @@ export function ChartCard({
251
272
  const { ref, short } = useShortCard()
252
273
  const resolved = resolveChartState(state)
253
274
  const showFacts = facts !== undefined && resolved === null
275
+ const skeletonFacts = facts !== undefined && resolved === 'pending'
254
276
  const hasHeader =
255
- actions !== undefined || showFacts || HEADER_TRIGGERS.some((k) => header[k] !== undefined)
277
+ actions !== undefined ||
278
+ showFacts ||
279
+ skeletonFacts ||
280
+ HEADER_TRIGGERS.some((k) => header[k] !== undefined)
256
281
  // With facts the subtitle is the basis line after them, not WidgetHeader's foldable row.
257
282
  const { subtitle, ...rest } = header
258
283
  const headerProps = facts === undefined ? header : rest
@@ -278,6 +303,7 @@ export function ChartCard({
278
303
  })}
279
304
  />
280
305
  {showFacts && <Facts facts={facts} basis={subtitle} stale={stale} />}
306
+ {skeletonFacts && <FactsSkeleton basis={subtitle !== undefined} />}
281
307
  </div>
282
308
  )}
283
309
  <div
@@ -291,6 +317,7 @@ export function ChartCard({
291
317
  state={state}
292
318
  {...(placeholderHeight !== undefined && { height: placeholderHeight })}
293
319
  {...(stateNoun !== undefined && { noun: stateNoun })}
320
+ {...(ghost !== undefined && { ghost })}
294
321
  {...(onRetry !== undefined && { onRetry })}
295
322
  {...(retrying !== undefined && { retrying })}
296
323
  action={stateAction}
@@ -80,6 +80,9 @@ const READOUT_GAP = 8
80
80
  /** Air round a line's plot, px (the engine's plot margin): the end marker stays inside the svg box,
81
81
  * so it clears the 2px focus outline round it. A bar plot is flush. */
82
82
  const LINE_INSET = 3
83
+ /** A bare line sparkline shorter than this has no room for a two-line readout (about 34px with its
84
+ * padding and border): it keeps the one-line form, in the in-box band farthest from the line. */
85
+ const SHORT_BOX = 36
83
86
  /** The muted tone's line: the same alpha the consumers hand-built (`alpha(VX.muted, .35)`). */
84
87
  const MUTED_LINE = alpha(VX.muted, 0.35)
85
88
  /** Air between the plot's start and the reference label, so the focus outline never covers it. */
@@ -389,18 +392,144 @@ function meanOf(rows: readonly Point[]): number {
389
392
  return sum / n
390
393
  }
391
394
 
395
+ /** A plotted point as fractions of the plot rect: `[fx, fy]`, fy down. */
396
+ type LinePoint = readonly [number, number]
397
+
398
+ /** Air between a stacked chip and the plotted line (stroke and dot radius included), px. */
399
+ const CLEAR = 4
400
+
401
+ /** Whether the polyline passes through the box `[left, left + w] x [top, top + h]`, grown by CLEAR. */
402
+ function lineHits(
403
+ pts: readonly (readonly [number, number])[],
404
+ box: { left: number; top: number; w: number; h: number },
405
+ ): boolean {
406
+ const x0 = box.left - CLEAR
407
+ const x1 = box.left + box.w + CLEAR
408
+ const y0 = box.top - CLEAR
409
+ const y1 = box.top + box.h + CLEAR
410
+ for (let i = 0; i < pts.length; i += 1) {
411
+ const [ax, ay] = pts[i] as readonly [number, number]
412
+ const next = pts[i + 1]
413
+ if (next === undefined) return ax >= x0 && ax <= x1 && ay >= y0 && ay <= y1
414
+ const [bx, by] = next
415
+ if (Math.max(ax, bx) < x0 || Math.min(ax, bx) > x1) continue
416
+ // y at the segment's ends clipped to the box's x-range: y is linear, so its range is the ends'.
417
+ const yAt = (x: number): number => (bx === ax ? ay : ay + ((by - ay) * (x - ax)) / (bx - ax))
418
+ const ya = yAt(Math.max(Math.min(ax, bx), x0))
419
+ const yb = yAt(Math.min(Math.max(ax, bx), x1))
420
+ if (Math.max(ya, yb) >= y0 && Math.min(ya, yb) <= y1) return true
421
+ }
422
+ return false
423
+ }
424
+
425
+ /**
426
+ * A hosted line's stacked chip is two lines tall, more than the host's one reserved line, so it sits
427
+ * in the plot, and never on the plotted line: first at the cursor (slid with it) at the plot's top,
428
+ * then its bottom, then to the right and to the left of the cursor at either edge, the first of
429
+ * those the line misses. A plot too short for the chip (a 22px strip cell) has no such spot: the
430
+ * chip then hangs from the plot's bottom edge, over the host's footer or card padding: a hover
431
+ * covers the figure's secondary text before it covers the data or the figure's delta above.
432
+ * Offsets go on `margin-left` and `top`, which React's `left` / `translate` do not own.
433
+ */
434
+ function placeStacked(node: HTMLElement, line: () => readonly LinePoint[], fx: number): void {
435
+ const layer = node.parentElement
436
+ if (!layer) return
437
+ const [W, H, w, h] = [layer.clientWidth, layer.clientHeight, node.offsetWidth, node.offsetHeight]
438
+ if (W <= 0 || H <= 0) return
439
+ const pts = line().map(([x, y]): [number, number] => [x * W, y * H])
440
+ const slid = fx * (W - w)
441
+ const room = (left: number): number => Math.min(Math.max(left, 0), Math.max(W - w, 0))
442
+ const lefts = [slid, room(fx * W + CLEAR * 2), room(fx * W - CLEAR * 2 - w)]
443
+ const tops = [0, Math.max(H - h, 0)]
444
+ const fit = lefts
445
+ .flatMap((left) => tops.map((top) => ({ left, top, w, h })))
446
+ .find((box) => !lineHits(pts, box))
447
+ if (!fit) {
448
+ node.style.top = `${H + CLEAR}px`
449
+ return
450
+ }
451
+ node.style.top = `${fit.top}px`
452
+ node.style.marginLeft = `${fit.left - slid}px`
453
+ }
454
+
455
+ /** The plotted line's y (fraction of the box) at x, interpolated along the polyline; null outside it. */
456
+ function lineYAt(pts: readonly (readonly [number, number])[], x: number): number | null {
457
+ for (let i = 0; i + 1 < pts.length; i += 1) {
458
+ const [ax, ay] = pts[i] as readonly [number, number]
459
+ const [bx, by] = pts[i + 1] as readonly [number, number]
460
+ if (x >= Math.min(ax, bx) && x <= Math.max(ax, bx))
461
+ return bx === ax ? ay : ay + ((by - ay) * (x - ax)) / (bx - ax)
462
+ }
463
+ return null
464
+ }
465
+
466
+ /**
467
+ * A short bare line's one-line chip stays inside its box (it can never reach a sibling above or
468
+ * below). It slides with the point and takes the band, top or bottom, farthest from the plotted line
469
+ * under it; a box so short that the chip fills it moves beside the point instead, so the chip never
470
+ * covers the dot. Offsets go on `margin-left` and `top`, which React's `left` / `translate` do not own.
471
+ */
472
+ function placeInBand(node: HTMLElement, line: () => readonly LinePoint[], fx: number): void {
473
+ const layer = node.parentElement
474
+ if (!layer) return
475
+ const [W, H, w, h] = [layer.clientWidth, layer.clientHeight, node.offsetWidth, node.offsetHeight]
476
+ if (W <= 0 || H <= 0) return
477
+ const pts = line().map(([x, y]): [number, number] => [x * W, y * H])
478
+ const slid = fx * (W - w)
479
+ const room = (left: number): number => Math.min(Math.max(left, 0), Math.max(W - w, 0))
480
+ const lefts = [slid, room(fx * W + CLEAR * 2), room(fx * W - CLEAR * 2 - w)]
481
+ const bands = [0, Math.max(H - h, 0)]
482
+ const dotY = lineYAt(pts, fx * W)
483
+ const score = (left: number, top: number): number => {
484
+ const covers =
485
+ dotY !== null &&
486
+ fx * W + CLEAR > left &&
487
+ fx * W - CLEAR < left + w &&
488
+ dotY + CLEAR > top &&
489
+ dotY - CLEAR < top + h
490
+ let nearest = Number.POSITIVE_INFINITY
491
+ for (let x = left; x <= left + w; x += 2) {
492
+ const y = lineYAt(pts, x)
493
+ if (y === null) continue
494
+ nearest = Math.min(nearest, y < top ? top - y : y > top + h ? y - (top + h) : 0)
495
+ }
496
+ return (covers ? -1000 : 0) + Math.min(nearest, 999)
497
+ }
498
+ const fit = lefts
499
+ .flatMap((left) => bands.map((top) => ({ left, top, s: score(left, top) })))
500
+ .reduce((a, b) => (b.s > a.s ? b : a))
501
+ node.style.top = `${fit.top}px`
502
+ node.style.marginLeft = `${fit.left - slid}px`
503
+ }
504
+
392
505
  /**
393
- * A readout never loses its date to an ellipsis: when the one-line chip overflows its box it first
394
- * tightens (`data-tight`: no air round the dot), then stacks (`data-stacked`: the date on its own
395
- * line). Set on the node, so a measure never re-renders.
506
+ * A readout never loses its separator or its date to an ellipsis: when the one-line chip overflows
507
+ * its box it first tightens (`data-tight`: less padding, the separator's air stays), then stacks
508
+ * (`data-stacked`: the date on its own line, placed off the plotted line when `line` is given). Set
509
+ * on the node, so a measure never re-renders.
396
510
  */
397
- function fitReadout(node: HTMLElement): void {
511
+ function fitReadout(
512
+ node: HTMLElement,
513
+ line: (() => readonly LinePoint[]) | null,
514
+ fx: number,
515
+ band: boolean,
516
+ ): void {
398
517
  const overflows = (): boolean => node.scrollWidth > node.clientWidth
399
518
  node.removeAttribute('data-tight')
400
519
  node.removeAttribute('data-stacked')
401
- if (!overflows()) return
402
- node.setAttribute('data-tight', '')
403
- if (overflows()) node.setAttribute('data-stacked', '')
520
+ // `top` is React's on a bare chip; a hosted line's chip is the only one `placeStacked` writes to.
521
+ if (line !== null) {
522
+ node.style.removeProperty('top')
523
+ node.style.removeProperty('margin-left')
524
+ }
525
+ if (overflows()) {
526
+ node.setAttribute('data-tight', '')
527
+ // A short bare box has no room for two lines: it stays one line, tight.
528
+ if (overflows() && !band) node.setAttribute('data-stacked', '')
529
+ }
530
+ if (line === null) return
531
+ if (band) placeInBand(node, line, fx)
532
+ else if (node.hasAttribute('data-stacked')) placeStacked(node, line, fx)
404
533
  }
405
534
 
406
535
  export function Sparkline(props: SparklineProps): ReactElement {
@@ -511,26 +640,50 @@ export function Sparkline(props: SparklineProps): ReactElement {
511
640
  // `translate` take one fraction), inside the box at either edge whatever its width, and the
512
641
  // stylesheet lifts it above the plot. Bare: beside the point, on the roomier side and on the half of
513
642
  // the box away from it, so the chip covers neither the dot nor anything the host draws round it.
643
+ const short = !hosted && mark === 'line' && height < SHORT_BOX
514
644
  const beside = at === null ? null : at.fx > 0.5 ? 'left' : 'right'
515
645
  // The chip's fit depends on its text and (bare) its side, not on the pointer's every tick.
516
646
  const shown = at !== null
647
+ // The cursor's fraction is read at fit time: it moves with `active`, which already refits.
648
+ const fxRef = useRef(0)
517
649
  useLayoutEffect(() => {
518
- if (readoutRef.current !== null) fitReadout(readoutRef.current)
519
- }, [active, at?.label, at?.value, beside])
650
+ fxRef.current = at?.fx ?? 0
651
+ })
652
+ const fitRef = useRef<() => void>(() => {})
653
+ useLayoutEffect(() => {
654
+ // A hosted line's stacked chip clears the plotted line, built only when the chip stacks; a bar
655
+ // or a bare chip keeps its place.
656
+ const line =
657
+ (hosted || short) && mark === 'line' && model !== null
658
+ ? (): LinePoint[] =>
659
+ model.rows.flatMap((r, i): LinePoint[] =>
660
+ r.v === null
661
+ ? []
662
+ : [
663
+ [
664
+ (i - model.frame.x[0]) / (model.frame.x[1] - model.frame.x[0]),
665
+ (model.frame.y[1] - r.v) / (model.frame.y[1] - model.frame.y[0]),
666
+ ],
667
+ ],
668
+ )
669
+ : null
670
+ fitRef.current = () => {
671
+ if (readoutRef.current !== null) fitReadout(readoutRef.current, line, fxRef.current, short)
672
+ }
673
+ fitRef.current()
674
+ }, [active, at?.label, at?.value, beside, hosted, short, mark, model])
520
675
  // ...and on the box, which a container resize changes without a hover.
521
676
  useEffect(() => {
522
677
  const layer = readoutRef.current?.parentElement
523
678
  if (!shown || !layer || typeof ResizeObserver === 'undefined') return
524
- const observer = new ResizeObserver(() => {
525
- if (readoutRef.current !== null) fitReadout(readoutRef.current)
526
- })
679
+ const observer = new ResizeObserver(() => fitRef.current())
527
680
  observer.observe(layer)
528
681
  return () => observer.disconnect()
529
682
  }, [shown])
530
683
  const readoutStyle: CSSProperties | undefined =
531
684
  at === null
532
685
  ? undefined
533
- : hosted
686
+ : hosted || short
534
687
  ? { left: `${at.fx * 100}%`, translate: `${-at.fx * 100}% 0`, maxWidth: '100%' }
535
688
  : {
536
689
  ...(beside === 'right'
@@ -93,21 +93,139 @@
93
93
  min-height: inherit;
94
94
  }
95
95
 
96
+ /*
97
+ * A pending plot in the loaded shape (`state.tsx`): an axis baseline and a few bar ghosts in a
98
+ * neutral tone, so a loading card reads as the chart it will be rather than a blank plate. Heights
99
+ * are constants, so the server HTML is the client's. 18% ink over the panel is the tone of the
100
+ * facts skeleton (`chart-card.module.css`).
101
+ */
102
+ .ghost {
103
+ box-sizing: border-box;
104
+ display: flex;
105
+ align-items: flex-end;
106
+ gap: 5%;
107
+ width: 100%;
108
+ height: 100%;
109
+ padding: 12px 4px 0;
110
+ /* The axis baseline: a 1px line painted under the ghosts, not a border (the divider law inventories those). */
111
+ background: linear-gradient(
112
+ color-mix(in srgb, var(--vx-ink) 24%, var(--vx-surface-panel)),
113
+ color-mix(in srgb, var(--vx-ink) 24%, var(--vx-surface-panel))
114
+ )
115
+ bottom / 100% 1px no-repeat;
116
+ }
117
+
118
+ .ghostLine {
119
+ width: 100%;
120
+ height: 100%;
121
+ fill: none;
122
+ stroke: color-mix(in srgb, var(--vx-ink) 24%, var(--vx-surface-panel));
123
+ stroke-width: 2px;
124
+ stroke-linecap: round;
125
+ stroke-linejoin: round;
126
+ }
127
+
128
+ .ghostBar {
129
+ flex: 1 1 0;
130
+ min-width: 0;
131
+ border-radius: 3px 3px 0 0;
132
+ background: color-mix(in srgb, var(--vx-ink) 18%, var(--vx-surface-panel));
133
+ }
134
+
96
135
  /*
97
136
  * The engine paints its tooltip rows as a grid of `.55rem | minmax(0, 1fr) | auto` with inline
98
137
  * styles and `overflow-wrap: anywhere` on the card, so a narrow tooltip (a 390 viewport, a pointer
99
138
  * near an edge) squeezes the name column to one character per line. The name keeps a floor and
100
- * never wraps; a long name ends in an ellipsis, the value stays right-aligned. The tooltip is
101
- * portalled out of the chart's tree, hence the global class names. `!important` because the
102
- * engine's own values are inline.
139
+ * wraps at word breaks when it must; the figure never wraps and never ends in an ellipsis, it stays
140
+ * right-aligned. The tooltip is portalled out of the chart's tree, hence the global class names.
141
+ * `!important` because the engine's own values are inline.
103
142
  */
104
143
  :global(.ts-chart-tooltip__row) {
105
- grid-template-columns: 0.55rem minmax(6rem, max-content) auto !important;
144
+ grid-template-columns: 0.55rem minmax(6rem, 1fr) auto !important;
106
145
  }
107
146
 
108
147
  :global(.ts-chart-tooltip__row > span:nth-child(2)) {
109
- max-width: 14rem;
148
+ /* Words wrap, tokens do not: the engine's `anywhere` on the card would split `Load (7)` as
149
+ * `Load` / `7)` and `TE 2.1/0.4` mid-figure. A single token wider than the card overflows it. */
150
+ overflow-wrap: normal;
151
+ white-space: normal;
152
+ }
153
+
154
+ :global(.ts-chart-tooltip__row > span:nth-child(3)) {
155
+ white-space: nowrap;
156
+ }
157
+
158
+ /* Opaque in both schemes: `--vx-tooltip-bg` is translucent in dark and the card's footer ghosts
159
+ * through a tooltip that opens over it (a slotted `Bars`). The tint is layered over the elevated
160
+ * surface, so a consumer's `tooltipBg` and `--basalt-tooltip-surface` still colour it. The engine's
161
+ * own value is inline. */
162
+ :global(.ts-chart-tooltip) {
163
+ background: linear-gradient(
164
+ var(--basalt-tooltip-surface, var(--vx-tooltip-bg)),
165
+ var(--basalt-tooltip-surface, var(--vx-tooltip-bg))
166
+ )
167
+ var(--vx-surface-elevated) !important;
168
+ }
169
+
170
+ /*
171
+ * A slotted `Bars` (`data-basalt-slot`, set by `compile.ts`) is a micro-visual: its tooltip is the
172
+ * Sparkline's one-line chip, `<value> · <x label>` in the line the host reserves above the plot. The
173
+ * first row's figure leads, the header follows it, further rows are hidden (a chart that needs rows
174
+ * lives in a `ChartCard`); an overlong header ends in an ellipsis. Height, type and edge are the
175
+ * chip's (`sparkline.module.css`); the tooltip is portalled out of the host, so its fallbacks stand.
176
+ */
177
+ :global(.ts-chart-tooltip[data-basalt-slot]) {
178
+ display: flex !important;
179
+ align-items: center;
180
+ box-sizing: border-box;
181
+ width: max-content;
182
+ block-size: 1.125rem;
183
+ padding: 0 4px !important;
184
+ overflow: hidden;
185
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
186
+ font-variant-numeric: lining-nums;
187
+ font-size: var(--vx-text-xs);
188
+ line-height: calc(1.125rem - 2px);
189
+ white-space: nowrap !important;
190
+ border-radius: var(--vx-radius-ctrl) !important;
191
+ /* theme-allow css-raw-surface — the chip is flat, like the Sparkline's, not a floating panel */
192
+ box-shadow: none !important;
193
+ }
194
+
195
+ :global(.ts-chart-tooltip[data-basalt-slot]:is([hidden], [popover]:not(:popover-open))) {
196
+ /* The flex above must not beat the engine's own hide. */
197
+ display: none !important;
198
+ }
199
+
200
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__rows) {
201
+ flex: none;
202
+ order: 0;
203
+ }
204
+
205
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__row) {
206
+ display: block !important;
207
+ }
208
+
209
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__row:not(:first-child)),
210
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__row > span:not(:last-child)) {
211
+ display: none;
212
+ }
213
+
214
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__title) {
215
+ display: block !important;
216
+ flex: 0 1 auto;
217
+ min-width: 0;
218
+ order: 1;
219
+ margin: 0 !important;
110
220
  overflow: hidden;
221
+ font-weight: inherit !important;
111
222
  text-overflow: ellipsis;
112
223
  white-space: nowrap;
224
+ overflow-wrap: normal;
225
+ opacity: 0.7;
226
+ }
227
+
228
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__title::before) {
229
+ content: ' · ';
230
+ white-space: pre;
113
231
  }
@@ -9,5 +9,8 @@ declare const classes: {
9
9
  readonly fill: string
10
10
  readonly state: string
11
11
  readonly grow: string
12
+ readonly ghost: string
13
+ readonly ghostLine: string
14
+ readonly ghostBar: string
12
15
  }
13
16
  export default classes
@@ -95,3 +95,37 @@
95
95
  .factsRow[data-stale] {
96
96
  opacity: 0.55;
97
97
  }
98
+
99
+ /*
100
+ * A pending card keeps its facts footprint: bars as tall as the loaded figure and basis lines (`1lh`
101
+ * at the same font size), painted a little inside the line box so they read as text, not slabs. The
102
+ * tone is the chart ghost's (`chart-box.module.css` `.ghost`).
103
+ */
104
+ .skeletonFigure,
105
+ .skeletonBasis {
106
+ position: relative;
107
+ display: block;
108
+ }
109
+
110
+ .skeletonFigure {
111
+ font-size: var(--vx-text-kpi);
112
+ height: 1lh;
113
+ width: 4.5rem;
114
+ }
115
+
116
+ .skeletonBasis {
117
+ font-size: var(--vx-text-sm);
118
+ height: 1lh;
119
+ width: 9rem;
120
+ max-width: 100%;
121
+ }
122
+
123
+ .skeletonFigure::before,
124
+ .skeletonBasis::before {
125
+ content: '';
126
+ position: absolute;
127
+ inset-inline: 0;
128
+ inset-block: 0.2lh;
129
+ border-radius: 3px;
130
+ background: color-mix(in srgb, var(--vx-ink) 18%, var(--vx-surface-panel));
131
+ }
@@ -11,5 +11,7 @@ declare const classes: {
11
11
  readonly factValue: string
12
12
  readonly factUnit: string
13
13
  readonly factPeriod: string
14
+ readonly skeletonFigure: string
15
+ readonly skeletonBasis: string
14
16
  }
15
17
  export default classes
@@ -15,10 +15,8 @@
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. */
19
18
  .auto {
20
- flex-wrap: nowrap;
21
- overflow: hidden;
19
+ flex-wrap: wrap;
22
20
  display: flex;
23
21
  column-gap: var(--bc-dots-gap);
24
22
  --vx-hit-gap: var(--bc-dots-gap);
@@ -27,8 +25,6 @@
27
25
 
28
26
  @container (min-width: 480px) {
29
27
  .auto {
30
- flex-wrap: wrap;
31
- overflow: visible;
32
28
  column-gap: var(--bc-legend-gap);
33
29
  --vx-hit-gap: var(--bc-legend-gap);
34
30
  }
@@ -48,14 +44,3 @@
48
44
  display: none;
49
45
  }
50
46
  }
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
- }