basalt-ui 2.24.0 → 2.26.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 +55 -0
- package/MIGRATING.md +191 -19
- package/configs/oxlint-basalt.json +1 -1
- package/configs/oxlint-plugin.js +3 -9
- package/configs/oxlint-plugin.test.ts +6 -0
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +4 -1
- package/dist/charts/CartesianChart.d.ts +2 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/ChartCard.d.ts +11 -5
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +11 -3
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +65 -7
- package/dist/charts/chart-box.module.css +50 -7
- package/dist/charts/chart-box.module.css.d.ts +2 -0
- package/dist/charts/chart-card.module.css +34 -0
- package/dist/charts/chart-card.module.css.d.ts +2 -0
- package/dist/charts/chart-legend.module.css +5 -6
- package/dist/charts/compile.d.ts +2 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +45 -1
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +42 -9
- package/dist/charts/sparkline.module.css +13 -9
- package/dist/charts/state.d.ts +3 -1
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +15 -2
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +25 -36
- 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 +7 -2
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/meter-model.d.ts +2 -0
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +99 -7
- package/dist/dashboard/meter-parts.d.ts +4 -7
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +102 -78
- package/dist/dashboard/meter.d.ts +1 -1
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +10 -7
- package/dist/dashboard/meter.module.css +43 -12
- package/dist/dashboard/meter.module.css.d.ts +1 -2
- package/dist/dashboard/section.d.ts +1 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.module.css +8 -7
- package/dist/dashboard/stat-card.module.css +19 -2
- package/dist/dashboard/stat-strip.d.ts +9 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +32 -6
- package/dist/dashboard/stat-strip.module.css +40 -1
- package/dist/dashboard/stat-strip.module.css.d.ts +3 -0
- package/dist/dashboard/visual-slot.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +2 -0
- package/dist/dashboard/widget-header.module.css +9 -0
- package/llms.txt +3 -3
- package/package.json +1 -1
- package/src/charts/Bars.tsx +7 -2
- package/src/charts/CartesianChart.tsx +2 -0
- package/src/charts/ChartCard.tsx +30 -7
- package/src/charts/Sparkline.tsx +105 -10
- package/src/charts/chart-box.module.css +50 -7
- package/src/charts/chart-box.module.css.d.ts +2 -0
- package/src/charts/chart-card.module.css +34 -0
- package/src/charts/chart-card.module.css.d.ts +2 -0
- package/src/charts/chart-legend.module.css +5 -6
- package/src/charts/compile.ts +60 -1
- package/src/charts/legend.tsx +64 -16
- package/src/charts/sparkline.module.css +13 -9
- package/src/charts/state.tsx +33 -7
- package/src/cli/shot/detect.ts +26 -40
- package/src/dashboard/bar-list.module.css +7 -2
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +14 -2
- package/src/dashboard/meter-model.ts +147 -12
- package/src/dashboard/meter-parts.tsx +71 -50
- package/src/dashboard/meter.module.css +43 -12
- package/src/dashboard/meter.module.css.d.ts +1 -2
- package/src/dashboard/meter.tsx +22 -9
- package/src/dashboard/section.module.css +8 -7
- package/src/dashboard/section.tsx +1 -2
- package/src/dashboard/stat-card.module.css +19 -2
- package/src/dashboard/stat-strip.module.css +40 -1
- package/src/dashboard/stat-strip.module.css.d.ts +3 -0
- package/src/dashboard/stat-strip.tsx +49 -8
- package/src/dashboard/visual-slot.ts +5 -0
- package/src/dashboard/widget-header.module.css +9 -0
package/src/charts/Sparkline.tsx
CHANGED
|
@@ -389,18 +389,90 @@ function meanOf(rows: readonly Point[]): number {
|
|
|
389
389
|
return sum / n
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
/** A plotted point as fractions of the plot rect: `[fx, fy]`, fy down. */
|
|
393
|
+
type LinePoint = readonly [number, number]
|
|
394
|
+
|
|
395
|
+
/** Air between a stacked chip and the plotted line (stroke and dot radius included), px. */
|
|
396
|
+
const CLEAR = 4
|
|
397
|
+
|
|
398
|
+
/** Whether the polyline passes through the box `[left, left + w] x [top, top + h]`, grown by CLEAR. */
|
|
399
|
+
function lineHits(
|
|
400
|
+
pts: readonly (readonly [number, number])[],
|
|
401
|
+
box: { left: number; top: number; w: number; h: number },
|
|
402
|
+
): boolean {
|
|
403
|
+
const x0 = box.left - CLEAR
|
|
404
|
+
const x1 = box.left + box.w + CLEAR
|
|
405
|
+
const y0 = box.top - CLEAR
|
|
406
|
+
const y1 = box.top + box.h + CLEAR
|
|
407
|
+
for (let i = 0; i < pts.length; i += 1) {
|
|
408
|
+
const [ax, ay] = pts[i] as readonly [number, number]
|
|
409
|
+
const next = pts[i + 1]
|
|
410
|
+
if (next === undefined) return ax >= x0 && ax <= x1 && ay >= y0 && ay <= y1
|
|
411
|
+
const [bx, by] = next
|
|
412
|
+
if (Math.max(ax, bx) < x0 || Math.min(ax, bx) > x1) continue
|
|
413
|
+
// y at the segment's ends clipped to the box's x-range: y is linear, so its range is the ends'.
|
|
414
|
+
const yAt = (x: number): number => (bx === ax ? ay : ay + ((by - ay) * (x - ax)) / (bx - ax))
|
|
415
|
+
const ya = yAt(Math.max(Math.min(ax, bx), x0))
|
|
416
|
+
const yb = yAt(Math.min(Math.max(ax, bx), x1))
|
|
417
|
+
if (Math.max(ya, yb) >= y0 && Math.min(ya, yb) <= y1) return true
|
|
418
|
+
}
|
|
419
|
+
return false
|
|
420
|
+
}
|
|
421
|
+
|
|
392
422
|
/**
|
|
393
|
-
* A
|
|
394
|
-
*
|
|
395
|
-
*
|
|
423
|
+
* A hosted line's stacked chip is two lines tall, more than the host's one reserved line, so it sits
|
|
424
|
+
* in the plot, and never on the plotted line: first at the cursor (slid with it) at the plot's top,
|
|
425
|
+
* then its bottom, then to the right and to the left of the cursor at either edge, the first of
|
|
426
|
+
* those the line misses. A plot too short for the chip (a 22px strip cell) has no such spot: the
|
|
427
|
+
* chip then hangs from the plot's bottom edge, over the host's footer or card padding: a hover
|
|
428
|
+
* covers the figure's secondary text before it covers the data or the figure's delta above.
|
|
429
|
+
* Offsets go on `margin-left` and `top`, which React's `left` / `translate` do not own.
|
|
396
430
|
*/
|
|
397
|
-
function
|
|
431
|
+
function placeStacked(node: HTMLElement, line: () => readonly LinePoint[], fx: number): void {
|
|
432
|
+
const layer = node.parentElement
|
|
433
|
+
if (!layer) return
|
|
434
|
+
const [W, H, w, h] = [layer.clientWidth, layer.clientHeight, node.offsetWidth, node.offsetHeight]
|
|
435
|
+
if (W <= 0 || H <= 0) return
|
|
436
|
+
const pts = line().map(([x, y]): [number, number] => [x * W, y * H])
|
|
437
|
+
const slid = fx * (W - w)
|
|
438
|
+
const room = (left: number): number => Math.min(Math.max(left, 0), Math.max(W - w, 0))
|
|
439
|
+
const lefts = [slid, room(fx * W + CLEAR * 2), room(fx * W - CLEAR * 2 - w)]
|
|
440
|
+
const tops = [0, Math.max(H - h, 0)]
|
|
441
|
+
const fit = lefts
|
|
442
|
+
.flatMap((left) => tops.map((top) => ({ left, top, w, h })))
|
|
443
|
+
.find((box) => !lineHits(pts, box))
|
|
444
|
+
if (!fit) {
|
|
445
|
+
node.style.top = `${H + CLEAR}px`
|
|
446
|
+
return
|
|
447
|
+
}
|
|
448
|
+
node.style.top = `${fit.top}px`
|
|
449
|
+
node.style.marginLeft = `${fit.left - slid}px`
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* A readout never loses its separator or its date to an ellipsis: when the one-line chip overflows
|
|
454
|
+
* its box it first tightens (`data-tight`: less padding, the separator's air stays), then stacks
|
|
455
|
+
* (`data-stacked`: the date on its own line, placed off the plotted line when `line` is given). Set
|
|
456
|
+
* on the node, so a measure never re-renders.
|
|
457
|
+
*/
|
|
458
|
+
function fitReadout(
|
|
459
|
+
node: HTMLElement,
|
|
460
|
+
line: (() => readonly LinePoint[]) | null,
|
|
461
|
+
fx: number,
|
|
462
|
+
): void {
|
|
398
463
|
const overflows = (): boolean => node.scrollWidth > node.clientWidth
|
|
399
464
|
node.removeAttribute('data-tight')
|
|
400
465
|
node.removeAttribute('data-stacked')
|
|
466
|
+
// `top` is React's on a bare chip; a hosted line's chip is the only one `placeStacked` writes to.
|
|
467
|
+
if (line !== null) {
|
|
468
|
+
node.style.removeProperty('top')
|
|
469
|
+
node.style.removeProperty('margin-left')
|
|
470
|
+
}
|
|
401
471
|
if (!overflows()) return
|
|
402
472
|
node.setAttribute('data-tight', '')
|
|
403
|
-
if (overflows())
|
|
473
|
+
if (!overflows()) return
|
|
474
|
+
node.setAttribute('data-stacked', '')
|
|
475
|
+
if (line !== null) placeStacked(node, line, fx)
|
|
404
476
|
}
|
|
405
477
|
|
|
406
478
|
export function Sparkline(props: SparklineProps): ReactElement {
|
|
@@ -514,16 +586,39 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
514
586
|
const beside = at === null ? null : at.fx > 0.5 ? 'left' : 'right'
|
|
515
587
|
// The chip's fit depends on its text and (bare) its side, not on the pointer's every tick.
|
|
516
588
|
const shown = at !== null
|
|
589
|
+
// The cursor's fraction is read at fit time: it moves with `active`, which already refits.
|
|
590
|
+
const fxRef = useRef(0)
|
|
517
591
|
useLayoutEffect(() => {
|
|
518
|
-
|
|
519
|
-
}
|
|
592
|
+
fxRef.current = at?.fx ?? 0
|
|
593
|
+
})
|
|
594
|
+
const fitRef = useRef<() => void>(() => {})
|
|
595
|
+
useLayoutEffect(() => {
|
|
596
|
+
// A hosted line's stacked chip clears the plotted line, built only when the chip stacks; a bar
|
|
597
|
+
// or a bare chip keeps its place.
|
|
598
|
+
const line =
|
|
599
|
+
hosted && mark === 'line' && model !== null
|
|
600
|
+
? (): LinePoint[] =>
|
|
601
|
+
model.rows.flatMap((r, i): LinePoint[] =>
|
|
602
|
+
r.v === null
|
|
603
|
+
? []
|
|
604
|
+
: [
|
|
605
|
+
[
|
|
606
|
+
(i - model.frame.x[0]) / (model.frame.x[1] - model.frame.x[0]),
|
|
607
|
+
(model.frame.y[1] - r.v) / (model.frame.y[1] - model.frame.y[0]),
|
|
608
|
+
],
|
|
609
|
+
],
|
|
610
|
+
)
|
|
611
|
+
: null
|
|
612
|
+
fitRef.current = () => {
|
|
613
|
+
if (readoutRef.current !== null) fitReadout(readoutRef.current, line, fxRef.current)
|
|
614
|
+
}
|
|
615
|
+
fitRef.current()
|
|
616
|
+
}, [active, at?.label, at?.value, beside, hosted, mark, model])
|
|
520
617
|
// ...and on the box, which a container resize changes without a hover.
|
|
521
618
|
useEffect(() => {
|
|
522
619
|
const layer = readoutRef.current?.parentElement
|
|
523
620
|
if (!shown || !layer || typeof ResizeObserver === 'undefined') return
|
|
524
|
-
const observer = new ResizeObserver(() =>
|
|
525
|
-
if (readoutRef.current !== null) fitReadout(readoutRef.current)
|
|
526
|
-
})
|
|
621
|
+
const observer = new ResizeObserver(() => fitRef.current())
|
|
527
622
|
observer.observe(layer)
|
|
528
623
|
return () => observer.disconnect()
|
|
529
624
|
}, [shown])
|
|
@@ -93,21 +93,64 @@
|
|
|
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
|
+
.ghostBar {
|
|
119
|
+
flex: 1 1 0;
|
|
120
|
+
min-width: 0;
|
|
121
|
+
border-radius: 3px 3px 0 0;
|
|
122
|
+
background: color-mix(in srgb, var(--vx-ink) 18%, var(--vx-surface-panel));
|
|
123
|
+
}
|
|
124
|
+
|
|
96
125
|
/*
|
|
97
126
|
* The engine paints its tooltip rows as a grid of `.55rem | minmax(0, 1fr) | auto` with inline
|
|
98
127
|
* styles and `overflow-wrap: anywhere` on the card, so a narrow tooltip (a 390 viewport, a pointer
|
|
99
128
|
* near an edge) squeezes the name column to one character per line. The name keeps a floor and
|
|
100
|
-
* never wraps
|
|
101
|
-
* portalled out of the chart's tree, hence the global class names.
|
|
102
|
-
* engine's own values are inline.
|
|
129
|
+
* wraps at word breaks when it must; the figure never wraps and never ends in an ellipsis, it stays
|
|
130
|
+
* right-aligned. The tooltip is portalled out of the chart's tree, hence the global class names.
|
|
131
|
+
* `!important` because the engine's own values are inline.
|
|
103
132
|
*/
|
|
104
133
|
:global(.ts-chart-tooltip__row) {
|
|
105
|
-
grid-template-columns: 0.55rem minmax(6rem,
|
|
134
|
+
grid-template-columns: 0.55rem minmax(6rem, 1fr) auto !important;
|
|
106
135
|
}
|
|
107
136
|
|
|
108
137
|
:global(.ts-chart-tooltip__row > span:nth-child(2)) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
overflow-wrap: break-word;
|
|
139
|
+
white-space: normal;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
:global(.ts-chart-tooltip__row > span:nth-child(3)) {
|
|
112
143
|
white-space: nowrap;
|
|
113
144
|
}
|
|
145
|
+
|
|
146
|
+
/* Opaque in both schemes: `--vx-tooltip-bg` is translucent in dark and the card's footer ghosts
|
|
147
|
+
* through a tooltip that opens over it (a slotted `Bars`). The tint is layered over the elevated
|
|
148
|
+
* surface, so a consumer's `tooltipBg` and `--basalt-tooltip-surface` still colour it. The engine's
|
|
149
|
+
* own value is inline. */
|
|
150
|
+
:global(.ts-chart-tooltip) {
|
|
151
|
+
background: linear-gradient(
|
|
152
|
+
var(--basalt-tooltip-surface, var(--vx-tooltip-bg)),
|
|
153
|
+
var(--basalt-tooltip-surface, var(--vx-tooltip-bg))
|
|
154
|
+
)
|
|
155
|
+
var(--vx-surface-elevated) !important;
|
|
156
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@container (min-width: 240px) {
|
|
18
|
-
/*
|
|
18
|
+
/* `foldLegend` (legend.tsx) folds the zones / references that wrap the row into `+N`; series never fold. */
|
|
19
19
|
.auto {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
--bc-fold: 1;
|
|
21
|
+
flex-wrap: wrap;
|
|
22
22
|
display: flex;
|
|
23
23
|
column-gap: var(--bc-dots-gap);
|
|
24
24
|
--vx-hit-gap: var(--bc-dots-gap);
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
@container (min-width: 480px) {
|
|
29
29
|
.auto {
|
|
30
|
-
|
|
31
|
-
overflow: visible;
|
|
30
|
+
--bc-fold: 0;
|
|
32
31
|
column-gap: var(--bc-legend-gap);
|
|
33
32
|
--vx-hit-gap: var(--bc-legend-gap);
|
|
34
33
|
}
|
|
@@ -49,7 +48,7 @@
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
/* The compact fold (`foldLegend`, which only folds while
|
|
51
|
+
/* The compact fold (`foldLegend`, which only folds while `--bc-fold` is 1); wide keeps every entry.
|
|
53
52
|
* `!important`: an entry's inline `all: unset` (legend.tsx) would otherwise reset `display`. */
|
|
54
53
|
.auto [data-legend-folded] {
|
|
55
54
|
display: none !important;
|
package/src/charts/compile.ts
CHANGED
|
@@ -15,6 +15,7 @@ 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 { ChartTooltipPortalExtension } from '@tanstack/charts/tooltip/portal'
|
|
18
19
|
import type {
|
|
19
20
|
ChartBuildContext,
|
|
20
21
|
ChartTooltipAnchorContext,
|
|
@@ -101,6 +102,8 @@ export type CartesianInput<T, X extends ChartX> = Pick<
|
|
|
101
102
|
crosshair?: boolean
|
|
102
103
|
/** The engine's point marker on the focused datum. Default `true`; a bar kind has none (its hover is the bar). */
|
|
103
104
|
focusRing?: boolean
|
|
105
|
+
/** No axes, grid or margin: the plot is the whole box (a visual slot's bars, as `Sparkline`). */
|
|
106
|
+
bare?: boolean
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
/** The one tick-label size, at every container width: the caption size, so a card never mixes sizes. */
|
|
@@ -864,6 +867,23 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
864
867
|
}): StoredChartSpec['scales'] {
|
|
865
868
|
const { input, model, axes, formatX, cls, zoneScale } = opts
|
|
866
869
|
const { left, right } = axes
|
|
870
|
+
if (input.bare === true) {
|
|
871
|
+
return {
|
|
872
|
+
x: { scale: model.scale, axis: false as const },
|
|
873
|
+
y: { scale: yScaleFor(input.y, left.domain), axis: false as const },
|
|
874
|
+
// A right-axis series still needs its scale, drawn or not.
|
|
875
|
+
...(right && {
|
|
876
|
+
y2: {
|
|
877
|
+
channel: 'y' as const,
|
|
878
|
+
scale: yScaleFor(input.y2, right.domain),
|
|
879
|
+
axis: false as const,
|
|
880
|
+
},
|
|
881
|
+
}),
|
|
882
|
+
...(zoneScale && {
|
|
883
|
+
zx: { channel: 'x' as const, scale: scaleLinear().domain([0, 1]), axis: false as const },
|
|
884
|
+
}),
|
|
885
|
+
}
|
|
886
|
+
}
|
|
867
887
|
return {
|
|
868
888
|
x: {
|
|
869
889
|
scale: model.scale,
|
|
@@ -1038,6 +1058,44 @@ const barAnchor =
|
|
|
1038
1058
|
return { x: Math.min(Math.max(stepped, plot.x), plot.x + plot.width), y: floor }
|
|
1039
1059
|
}
|
|
1040
1060
|
|
|
1061
|
+
/** 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. */
|
|
1062
|
+
const TIP_CARD = '[data-basalt-chart-card], [data-strip-cell], .mantine-Card-root'
|
|
1063
|
+
/** Air between a card-clamped tooltip and the card's edge, px. */
|
|
1064
|
+
const TIP_CARD_AIR = 4
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* The engine places a portalled tooltip against the viewport, so at the first or last point of a
|
|
1068
|
+
* chart it opens past the card's edge, over the neighbouring card. Its placements (a hover, and its
|
|
1069
|
+
* own resize / scroll repositions, which never pass through `position`) all write the element's
|
|
1070
|
+
* inline `left`, so each write is followed by a slide back inside the card (the viewport placement
|
|
1071
|
+
* stands when the card is narrower than the tooltip).
|
|
1072
|
+
*/
|
|
1073
|
+
const cardPortal: ChartTooltipPortalExtension = {
|
|
1074
|
+
id: portal.id,
|
|
1075
|
+
create(context, options) {
|
|
1076
|
+
const inner = portal.create(context, options)
|
|
1077
|
+
const { element, container } = context
|
|
1078
|
+
const watch = new MutationObserver(() => clampToCard(element, container))
|
|
1079
|
+
watch.observe(element, { attributes: true, attributeFilter: ['style'] })
|
|
1080
|
+
return {
|
|
1081
|
+
...inner,
|
|
1082
|
+
destroy() {
|
|
1083
|
+
watch.disconnect()
|
|
1084
|
+
inner.destroy()
|
|
1085
|
+
},
|
|
1086
|
+
}
|
|
1087
|
+
},
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
function clampToCard(tip: HTMLElement, within: Element): void {
|
|
1091
|
+
const card = within.closest(TIP_CARD)?.getBoundingClientRect()
|
|
1092
|
+
const left = Number.parseFloat(tip.style.left)
|
|
1093
|
+
const width = tip.offsetWidth
|
|
1094
|
+
if (!card || Number.isNaN(left) || width + 2 * TIP_CARD_AIR > card.width) return
|
|
1095
|
+
const next = Math.min(Math.max(left, card.left + TIP_CARD_AIR), card.right - width - TIP_CARD_AIR)
|
|
1096
|
+
if (Math.abs(next - left) > 0.5) tip.style.left = `${next}px`
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1041
1099
|
function tooltipSpec<T, X extends ChartX>(opts: {
|
|
1042
1100
|
input: CartesianInput<T, X>
|
|
1043
1101
|
axes: Axes<T>
|
|
@@ -1056,7 +1114,7 @@ function tooltipSpec<T, X extends ChartX>(opts: {
|
|
|
1056
1114
|
return {
|
|
1057
1115
|
use: quietWhileFollowing,
|
|
1058
1116
|
...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
|
|
1059
|
-
portal,
|
|
1117
|
+
portal: cardPortal,
|
|
1060
1118
|
anchor: input.tooltipBelow
|
|
1061
1119
|
? stripAnchor
|
|
1062
1120
|
: visible.some((s) => s.mark === 'bar')
|
|
@@ -1205,6 +1263,7 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
1205
1263
|
zoneScale: under.length > 0 || names,
|
|
1206
1264
|
}),
|
|
1207
1265
|
theme: CHART_THEME,
|
|
1266
|
+
...(input.bare === true && { guides: false as const, margin: 0 }),
|
|
1208
1267
|
...(gradients.length > 0 && { gradients }),
|
|
1209
1268
|
clip: true,
|
|
1210
1269
|
}
|
package/src/charts/legend.tsx
CHANGED
|
@@ -29,8 +29,8 @@ const ROLE_ORDER = ['series', 'overlay', 'reference'] as const
|
|
|
29
29
|
*/
|
|
30
30
|
const DOTS_GAP = 30
|
|
31
31
|
|
|
32
|
-
const
|
|
33
|
-
Number(
|
|
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
|
-
//
|
|
42
|
-
if (!groups) return entries.length ? [entries.toSorted(
|
|
41
|
+
// Series lead, zones and reference lines follow: the compact fold takes the references from the end.
|
|
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
|
|
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
|
|
@@ -204,10 +210,29 @@ const VISUALLY_HIDDEN = {
|
|
|
204
210
|
} as const
|
|
205
211
|
|
|
206
212
|
/**
|
|
207
|
-
* The
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
* The number of lines the visible entries (and the chip) sit on. Bucketed by vertical centre, so the
|
|
214
|
+
* chip's own height (shorter than an entry's) does not read as another line.
|
|
215
|
+
*/
|
|
216
|
+
function lineCount(row: HTMLElement, more: HTMLElement): number {
|
|
217
|
+
const shown = [...row.querySelectorAll<HTMLElement>('[data-legend-key]')].filter(
|
|
218
|
+
(it) => !it.hasAttribute('data-legend-folded'),
|
|
219
|
+
)
|
|
220
|
+
if (!more.hidden) shown.push(more)
|
|
221
|
+
const centres = shown
|
|
222
|
+
.map((it) => {
|
|
223
|
+
const r = it.getBoundingClientRect()
|
|
224
|
+
return r.top + r.height / 2
|
|
225
|
+
})
|
|
226
|
+
.toSorted((x, y) => x - y)
|
|
227
|
+
// A new line starts where the centre jumps by more than half an entry's height.
|
|
228
|
+
return centres.filter((c, i) => i === 0 || c - (centres[i - 1] ?? c) > 6).length
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The compact legend names every series at every width. When the row wraps below 480px, the
|
|
233
|
+
* zone / reference entries fold into a `+N` chip (named for assistive tech by the folded labels), the
|
|
234
|
+
* last first, only while the row has more lines than the series alone would; a series never folds.
|
|
235
|
+
* The entries are in display order: series, then zones / references.
|
|
211
236
|
* Measured on the node, never in React state, so a hover or a resize does not re-render.
|
|
212
237
|
*/
|
|
213
238
|
function foldLegend(row: HTMLElement): void {
|
|
@@ -215,11 +240,21 @@ function foldLegend(row: HTMLElement): void {
|
|
|
215
240
|
const more = row.querySelector<HTMLElement>('[data-legend-more]')
|
|
216
241
|
for (const it of items) it.removeAttribute('data-legend-folded')
|
|
217
242
|
more?.setAttribute('hidden', '')
|
|
218
|
-
|
|
219
|
-
const
|
|
243
|
+
// A label that ellipsizes carries its full name in `title`; one that fits carries none.
|
|
244
|
+
for (const label of row.querySelectorAll<HTMLElement>('[data-legend-label]')) {
|
|
245
|
+
if (label.scrollWidth > label.clientWidth + 0.5) label.title = label.textContent ?? ''
|
|
246
|
+
else label.removeAttribute('title')
|
|
247
|
+
}
|
|
248
|
+
// `--bc-fold` is the stylesheet's compact flag (chart-legend.module.css); wide keeps every entry.
|
|
249
|
+
if (more === null || getComputedStyle(row).getPropertyValue('--bc-fold').trim() !== '1') return
|
|
250
|
+
const references = items.filter((it) => it.dataset['legendRole'] === 'reference')
|
|
251
|
+
// The series-only line count is the floor: folding a reference that frees no line only hides a name.
|
|
252
|
+
for (const r of references) r.setAttribute('data-legend-folded', '')
|
|
253
|
+
const floor = lineCount(row, more)
|
|
254
|
+
for (const r of references) r.removeAttribute('data-legend-folded')
|
|
220
255
|
const folded: HTMLElement[] = []
|
|
221
|
-
while (
|
|
222
|
-
const last =
|
|
256
|
+
while (folded.length < references.length && lineCount(row, more) > floor) {
|
|
257
|
+
const last = references[references.length - 1 - folded.length]
|
|
223
258
|
if (last === undefined) break
|
|
224
259
|
last.setAttribute('data-legend-folded', '')
|
|
225
260
|
folded.push(last)
|
|
@@ -233,6 +268,11 @@ function foldLegend(row: HTMLElement): void {
|
|
|
233
268
|
Object.assign(hiddenNames.style, VISUALLY_HIDDEN)
|
|
234
269
|
more.append(hiddenNames)
|
|
235
270
|
}
|
|
271
|
+
// Folding freed no line (the chip's own width cost it): show every name instead.
|
|
272
|
+
if (folded.length > 0 && lineCount(row, more) > floor) {
|
|
273
|
+
for (const f of folded) f.removeAttribute('data-legend-folded')
|
|
274
|
+
more.setAttribute('hidden', '')
|
|
275
|
+
}
|
|
236
276
|
}
|
|
237
277
|
|
|
238
278
|
export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null {
|
|
@@ -250,7 +290,13 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
250
290
|
if (!auto || row === null || typeof ResizeObserver === 'undefined') return
|
|
251
291
|
const observer = new ResizeObserver(() => foldLegend(row))
|
|
252
292
|
observer.observe(row)
|
|
253
|
-
|
|
293
|
+
// A web font landing changes the entry widths without resizing the row.
|
|
294
|
+
let live = true
|
|
295
|
+
void document.fonts?.ready?.then(() => live && foldLegend(row))
|
|
296
|
+
return () => {
|
|
297
|
+
live = false
|
|
298
|
+
observer.disconnect()
|
|
299
|
+
}
|
|
254
300
|
}, [auto, signature])
|
|
255
301
|
const groups = legendEntries(props.series, props.groups)
|
|
256
302
|
if (groups.length === 0) return null
|
|
@@ -273,7 +319,9 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
273
319
|
const content = (
|
|
274
320
|
<>
|
|
275
321
|
<Swatch s={s} mode={props.mode} />
|
|
276
|
-
<span
|
|
322
|
+
<span style={labelStyle} data-legend-label="">
|
|
323
|
+
{s.label}
|
|
324
|
+
</span>
|
|
277
325
|
{s.note !== undefined && <span style={noteStyle}>{s.note}</span>}
|
|
278
326
|
</>
|
|
279
327
|
)
|
|
@@ -31,7 +31,13 @@
|
|
|
31
31
|
text-overflow: ellipsis;
|
|
32
32
|
white-space: nowrap;
|
|
33
33
|
pointer-events: none;
|
|
34
|
-
|
|
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
|
|
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
|
|
69
|
-
*
|
|
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;
|
package/src/charts/state.tsx
CHANGED
|
@@ -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,20 @@ 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
|
+
/** The loaded shape of a plot, drawn in neutral tone (`chart-box.module.css` `.ghost`). */
|
|
45
|
+
function PlotGhost(): ReactElement {
|
|
46
|
+
return (
|
|
47
|
+
<div aria-hidden="true" data-basalt-plot-ghost="" className={boxClasses.ghost}>
|
|
48
|
+
{GHOST_BARS.map((h, i) => (
|
|
49
|
+
<span key={i} className={boxClasses.ghostBar} style={{ height: `${h}%` }} />
|
|
50
|
+
))}
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
// The error idiom (D28, SPEC § 6.12): a status dot + a word + the message + the action, on the
|
|
41
56
|
// neutral surface. The dot is drawn from `--vx-*` tokens here — `src/charts/**` stays Mantine-free and `theme/status-dot` sits in the
|
|
42
57
|
// Mantine-coupled theme layer.
|
|
@@ -76,7 +91,9 @@ const emptyLabel = (state: ChartState | undefined): string =>
|
|
|
76
91
|
* `<Suspense>` fallback built from one) occupies the final chart's height. */
|
|
77
92
|
export function ChartPlaceholder(props: {
|
|
78
93
|
state: ChartState | undefined
|
|
79
|
-
|
|
94
|
+
/** `'content'`: error and empty end at their content (a list or Meter body, no chart to keep the
|
|
95
|
+
* frame for); the chart height law and a stated height keep D37's box. Pending always keeps a box. */
|
|
96
|
+
height?: ChartBoxHeight | 'content'
|
|
80
97
|
/** Error only: the shared Retry button, the same one `ErrorState` renders. */
|
|
81
98
|
onRetry?: () => void
|
|
82
99
|
/** A refetch is in flight: Retry is inert and marked busy. */
|
|
@@ -95,14 +112,23 @@ export function ChartPlaceholder(props: {
|
|
|
95
112
|
// An error keeps the chart's height as a floor (the frame does not jump, `ssr-contract`) and may
|
|
96
113
|
// grow past it rather than clip its action; its anatomy is top-aligned, so the room is plain
|
|
97
114
|
// card below the content, not a block of text floating mid-card.
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
const { height } = props
|
|
116
|
+
const fit = (node: ReactElement): ReactElement =>
|
|
117
|
+
height === 'content' && kind !== 'pending' ? (
|
|
118
|
+
node
|
|
119
|
+
) : (
|
|
120
|
+
<ChartBox
|
|
121
|
+
height={height === 'content' ? undefined : height}
|
|
122
|
+
{...(kind === 'error' && { className: growClass })}
|
|
123
|
+
>
|
|
124
|
+
{node}
|
|
125
|
+
</ChartBox>
|
|
126
|
+
)
|
|
103
127
|
if (kind === 'pending')
|
|
104
128
|
return fit(
|
|
105
|
-
<output aria-label="Loading chart" aria-busy="true" className={stateClass} style={style}
|
|
129
|
+
<output aria-label="Loading chart" aria-busy="true" className={stateClass} style={style}>
|
|
130
|
+
{!props.compact && <PlotGhost />}
|
|
131
|
+
</output>,
|
|
106
132
|
)
|
|
107
133
|
const label =
|
|
108
134
|
kind === 'error'
|