basalt-ui 2.21.0 → 2.23.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 +60 -0
- package/MIGRATING.md +452 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/rules/basalt-tokens.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +73 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +6 -0
- package/dist/charts/CartesianChart.d.ts +10 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +12 -3
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +39 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +14 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +101 -22
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +38 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +18 -1
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-dates.d.ts +12 -0
- package/dist/charts/chart-dates.d.ts.map +1 -0
- package/dist/charts/chart-dates.js +16 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +25 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +152 -72
- package/dist/charts/date-tick-format.d.ts +5 -5
- package/dist/charts/date-tick-format.d.ts.map +1 -1
- package/dist/charts/date-tick-format.js +3 -7
- package/dist/charts/labels.d.ts +21 -6
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +52 -17
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +43 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +75 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +13 -17
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +2 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +5 -2
- package/dist/charts/types.d.ts +18 -8
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +68 -4
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +202 -36
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +17 -1
- package/dist/cli/shot/playwright.d.ts +13 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/playwright.js +5 -1
- package/dist/cli/shot/types.d.ts +4 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- package/dist/cli/tokens-css.d.ts +5 -7
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +11 -12
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +15 -8
- package/dist/dashboard/bar-list.module.css +83 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +84 -5
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +100 -15
- package/dist/dashboard/meter-parts.d.ts +9 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +276 -74
- package/dist/dashboard/meter.d.ts +54 -65
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +21 -4
- package/dist/dashboard/meter.module.css +76 -0
- package/dist/dashboard/meter.module.css.d.ts +6 -0
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -5
- package/dist/dashboard/stat-card.module.css +36 -0
- package/dist/dashboard/stat-group.module.css +7 -0
- package/dist/dashboard/stat-strip.d.ts +22 -6
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +104 -60
- package/dist/dashboard/stat-strip.module.css +122 -53
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts +7 -1
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +3 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +0 -5
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +43 -4
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +37 -0
- package/dist/theme/controls.module.css.d.ts +2 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +18 -27
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/palette.d.ts +11 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +11 -10
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +42 -22
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +83 -3
- package/src/charts/Bars.tsx +7 -0
- package/src/charts/CartesianChart.tsx +18 -3
- package/src/charts/ChartCard.tsx +54 -13
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +135 -25
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +50 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +253 -87
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +81 -26
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +131 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +13 -17
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +9 -4
- package/src/charts/types.ts +18 -8
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/init.ts +100 -3
- package/src/cli/shot/capture.ts +266 -35
- package/src/cli/shot/detect.ts +18 -1
- package/src/cli/shot/playwright.ts +20 -4
- package/src/cli/shot/types.ts +5 -0
- package/src/cli/tokens-css.ts +18 -20
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +83 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +107 -69
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +207 -24
- package/src/dashboard/meter-parts.tsx +349 -67
- package/src/dashboard/meter.module.css +76 -0
- package/src/dashboard/meter.module.css.d.ts +6 -0
- package/src/dashboard/meter.tsx +72 -18
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +36 -0
- package/src/dashboard/stat-card.tsx +12 -6
- package/src/dashboard/stat-group.module.css +7 -0
- package/src/dashboard/stat-strip.module.css +122 -53
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +176 -91
- package/src/dashboard/visual-slot.ts +12 -3
- package/src/guard/index.ts +0 -5
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +43 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +200 -68
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +37 -0
- package/src/theme/controls.module.css.d.ts +2 -0
- package/src/theme/index.ts +22 -32
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/palette.ts +11 -10
- package/src/tokens/status-text.ts +2 -0
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The default Date x tick labels: chosen from the TICK step (not the data step), read in UTC like
|
|
3
3
|
* the scale that placed them. A label may recur on one axis only behind a MARKER label (a day or a
|
|
4
|
-
* year) — `12:00, 18:00, 18
|
|
4
|
+
* year) — `12:00, 18:00, 18 Oct, 06:00, 12:00` is fine, `17 Oct, 17 Oct, 18 Oct` is not. Each span has
|
|
5
5
|
* a ladder of levels, plainest first; the first level that holds the invariant wins. The last rung
|
|
6
6
|
* of every ladder names the whole date (or instant) of its tick, so the invariant always holds.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
export const pad2 = (n: number): string => String(n).padStart(2, '0')
|
|
9
|
+
import { axisDay, axisDayYear, monthName } from './chart-dates'
|
|
11
10
|
|
|
12
|
-
export const
|
|
11
|
+
export const pad2 = (n: number): string => String(n).padStart(2, '0')
|
|
13
12
|
|
|
14
13
|
const DAY_MS = 86_400_000
|
|
15
14
|
const HOUR_MS = 3_600_000
|
|
@@ -19,18 +18,16 @@ const HOUR_MS = 3_600_000
|
|
|
19
18
|
*/
|
|
20
19
|
const MONTH_STEP_MS = 27 * DAY_MS
|
|
21
20
|
|
|
22
|
-
/** `
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
21
|
+
/** The day (`4 Oct`, in the page locale), read in UTC like the time scale (a local read shifts a
|
|
22
|
+
* day west of UTC). */
|
|
23
|
+
export const utcAxisDate = axisDay
|
|
26
24
|
|
|
27
25
|
const utcClock = (d: Date): string => `${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`
|
|
28
26
|
const utcClockSeconds = (d: Date): string => `${utcClock(d)}:${pad2(d.getUTCSeconds())}`
|
|
29
27
|
const utcClockMillis = (d: Date): string =>
|
|
30
28
|
`${utcClockSeconds(d)}.${String(d.getUTCMilliseconds()).padStart(3, '0')}`
|
|
31
|
-
/** Two digits: a widened day label stays
|
|
32
|
-
const utcAxisDateYear =
|
|
33
|
-
`${utcAxisDate(d)}.${String(d.getUTCFullYear()).slice(2)}`
|
|
29
|
+
/** Two digits: a widened day label stays the same family (`4 Oct 26`). */
|
|
30
|
+
const utcAxisDateYear = axisDayYear
|
|
34
31
|
|
|
35
32
|
const isMidnight = (t: number): boolean => t % DAY_MS === 0
|
|
36
33
|
const isJanuary = (d: Date): boolean => d.getUTCMonth() === 0
|
|
@@ -69,7 +66,7 @@ const subDayLevels: Level[] = [
|
|
|
69
66
|
]
|
|
70
67
|
|
|
71
68
|
/**
|
|
72
|
-
* A day or more: `
|
|
69
|
+
* A day or more: the day (`18 Oct`). Ticks are at least a day apart here, so they fall on different UTC days
|
|
73
70
|
* and the last rung, which names the full date, cannot repeat.
|
|
74
71
|
*/
|
|
75
72
|
const dayLevels: Level[] = [
|
|
@@ -121,7 +118,7 @@ function stepOf(times: readonly number[]): number {
|
|
|
121
118
|
|
|
122
119
|
/**
|
|
123
120
|
* A formatter for one tick set. A Date that is not among the ticks (a hover, a consumer reading
|
|
124
|
-
* the axis format) reads as plain
|
|
121
|
+
* the axis format) reads as the plain day: its position in the set is undefined.
|
|
125
122
|
*/
|
|
126
123
|
export function dateTickFormat(ticks: readonly Date[]): (d: Date) => string {
|
|
127
124
|
const times = [...new Set(ticks.map((t) => t.getTime()))].toSorted((a, b) => a - b)
|
package/src/charts/labels.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { rowX } from './types'
|
|
|
9
9
|
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types'
|
|
10
10
|
|
|
11
11
|
const MAX_END_LABELS = 3
|
|
12
|
-
/**
|
|
12
|
+
/** Two end labels closer than this (px, vertically) are pushed apart to it. */
|
|
13
13
|
const END_LABEL_MIN_GAP = 13
|
|
14
14
|
const END_LABEL_DX = 6
|
|
15
15
|
/**
|
|
@@ -19,10 +19,15 @@ const END_LABEL_DX = 6
|
|
|
19
19
|
* that did not need to flip sits above its point, one that needed to and did not is cut.
|
|
20
20
|
*/
|
|
21
21
|
const END_LABEL_GLYPH_EM = 0.85
|
|
22
|
-
/** A label flipped inside the plot sits this far above its point. */
|
|
22
|
+
/** A label flipped inside the plot sits this far above (or, below its point, `BELOW`) its point. */
|
|
23
23
|
const END_LABEL_FLIP_DY = -9
|
|
24
|
+
const END_LABEL_FLIP_DY_BELOW = 13
|
|
25
|
+
/** The room a label's centre keeps from the plot's top and bottom edge, px: half its line. */
|
|
26
|
+
const END_LABEL_EDGE = 7
|
|
24
27
|
|
|
25
28
|
export type EndLabelAnchor = 'start' | 'end'
|
|
29
|
+
/** Which side of its line a flipped label sits: away from the line's last segment. */
|
|
30
|
+
export type EndLabelSide = 'above' | 'below'
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* The side of its point an end label takes: `start` (right of the point) unless the point leaves
|
|
@@ -42,10 +47,17 @@ export function endLabelAnchor(opts: {
|
|
|
42
47
|
return room >= label.length * fontSize * END_LABEL_GLYPH_EM + END_LABEL_DX ? 'start' : 'end'
|
|
43
48
|
}
|
|
44
49
|
|
|
50
|
+
/** `Lines`' one naming switch: who names the series. */
|
|
51
|
+
export type LinesNaming = 'auto' | 'legend' | 'endLabels'
|
|
52
|
+
|
|
45
53
|
export type EndLabel<T, X extends ChartX> = {
|
|
46
54
|
series: ChartSeries<T>
|
|
47
55
|
row: PlotRow<T, X>
|
|
48
56
|
anchor: EndLabelAnchor
|
|
57
|
+
/** Only a flipped label (left of its point) can meet its own line; it takes the clear side. */
|
|
58
|
+
side: EndLabelSide
|
|
59
|
+
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
|
|
60
|
+
nudge: number
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
type LastPoint<T, X extends ChartX> = {
|
|
@@ -53,55 +65,97 @@ type LastPoint<T, X extends ChartX> = {
|
|
|
53
65
|
row: PlotRow<T, X>
|
|
54
66
|
y: number
|
|
55
67
|
fraction: number
|
|
68
|
+
/** The value one finite point earlier: where the line's last segment comes from. */
|
|
69
|
+
prev: number | null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
|
|
74
|
+
* shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
|
|
75
|
+
* lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot. Order is kept.
|
|
76
|
+
*/
|
|
77
|
+
export function spreadLabels(ys: readonly number[], plotHeight: number): number[] {
|
|
78
|
+
const order = ys.map((y, i) => i).toSorted((a, b) => (ys[a] as number) - (ys[b] as number))
|
|
79
|
+
const placed = new Map<number, number>()
|
|
80
|
+
let floor = END_LABEL_EDGE
|
|
81
|
+
for (const i of order) {
|
|
82
|
+
const at = Math.max(ys[i] as number, floor)
|
|
83
|
+
placed.set(i, at)
|
|
84
|
+
floor = at + END_LABEL_MIN_GAP
|
|
85
|
+
}
|
|
86
|
+
// Pushed past the top: slide the whole stack back down, then re-sweep from the top.
|
|
87
|
+
const top = plotHeight - END_LABEL_EDGE
|
|
88
|
+
let ceiling = Infinity
|
|
89
|
+
for (const i of order.toReversed()) {
|
|
90
|
+
const at = Math.min(placed.get(i) as number, ceiling, top)
|
|
91
|
+
placed.set(i, at)
|
|
92
|
+
ceiling = at - END_LABEL_MIN_GAP
|
|
93
|
+
}
|
|
94
|
+
return ys.map((y, i) => (placed.get(i) as number) - y)
|
|
56
95
|
}
|
|
57
96
|
|
|
58
97
|
/**
|
|
59
|
-
* The end labels to draw
|
|
60
|
-
*
|
|
61
|
-
*
|
|
98
|
+
* The end labels to draw. `auto`: on the wide class only, with ≤ {@link MAX_END_LABELS} lines and
|
|
99
|
+
* no right axis; `endLabels`: at every width and any line count (still no right axis, whose
|
|
100
|
+
* series read another scale); `legend`: none. Labels that would collide are spread apart, never
|
|
101
|
+
* dropped. A series whose last point the plot's own x scale cannot place, or places outside the plot
|
|
62
102
|
* (`plot.xFraction` outside [0, 1]: clipped by a narrower `xDomain`), has no label.
|
|
63
103
|
*/
|
|
64
104
|
export function endLabelPlan<T, X extends ChartX>(
|
|
65
105
|
plot: PlotContext<T, X>,
|
|
66
106
|
lines: readonly ChartSeries<T>[],
|
|
107
|
+
naming: LinesNaming = 'auto',
|
|
67
108
|
): EndLabel<T, X>[] {
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
109
|
+
if (naming === 'legend' || plot.y2 !== undefined || lines.length === 0) return []
|
|
110
|
+
if (naming === 'auto' && (plot.containerClass !== 'wide' || lines.length > MAX_END_LABELS))
|
|
111
|
+
return []
|
|
70
112
|
const last = lines.flatMap((series): LastPoint<T, X>[] => {
|
|
71
|
-
const
|
|
113
|
+
const finite = plot.rows(series.key).filter((r) => r.y !== null)
|
|
114
|
+
const row = finite.at(-1)
|
|
72
115
|
if (row === undefined || row.y === null) return []
|
|
73
116
|
const fraction = plot.xFraction(row.x)
|
|
74
117
|
if (fraction === null || fraction < 0 || fraction > 1) return []
|
|
75
|
-
return [{ series, row, y: row.y, fraction }]
|
|
118
|
+
return [{ series, row, y: row.y, fraction, prev: finite.at(-2)?.y ?? null }]
|
|
76
119
|
})
|
|
77
|
-
// Collision check in pixels from the plot height: labels that would overlap are not drawn at all.
|
|
78
120
|
// No `y2` here (returned above), so every label reads the left domain.
|
|
79
121
|
const [lo, hi] = plot.yDomain
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
.toSorted((a, b) => a - b)
|
|
83
|
-
if (ys.some((y, i) => i > 0 && y - (ys[i - 1] as number) < END_LABEL_MIN_GAP)) return []
|
|
84
|
-
return last.map(({ series, row, fraction }) => ({
|
|
85
|
-
series,
|
|
86
|
-
row,
|
|
87
|
-
anchor: endLabelAnchor({
|
|
122
|
+
const placed = last.map(({ series, fraction, y, prev }) => {
|
|
123
|
+
const anchor = endLabelAnchor({
|
|
88
124
|
fraction,
|
|
89
125
|
plotWidth: plot.plotWidth,
|
|
90
126
|
label: series.label,
|
|
91
127
|
fontSize: VX.text.micro,
|
|
92
|
-
})
|
|
128
|
+
})
|
|
129
|
+
// A line falling into its end point comes from above: the label drops below it.
|
|
130
|
+
const side = prev !== null && prev > y ? ('below' as const) : ('above' as const)
|
|
131
|
+
// The label's centre, px from the plot's bottom, with its flip: what the spread keeps apart.
|
|
132
|
+
const centre = ((y - lo) / (hi - lo || 1)) * plot.plotHeight - endLabelOffset(anchor, side).dy
|
|
133
|
+
return { anchor, side, centre }
|
|
134
|
+
})
|
|
135
|
+
const shifts = spreadLabels(
|
|
136
|
+
placed.map((p) => p.centre),
|
|
137
|
+
plot.plotHeight,
|
|
138
|
+
)
|
|
139
|
+
return last.map(({ series, row }, i) => ({
|
|
140
|
+
series,
|
|
141
|
+
row,
|
|
142
|
+
anchor: (placed[i] as (typeof placed)[number]).anchor,
|
|
143
|
+
side: (placed[i] as (typeof placed)[number]).side,
|
|
144
|
+
nudge: 0 - (shifts[i] as number),
|
|
93
145
|
}))
|
|
94
146
|
}
|
|
95
147
|
|
|
96
|
-
/** The offset of a label from its point: right of it, level; or left of it
|
|
97
|
-
export function endLabelOffset(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
148
|
+
/** The offset of a label from its point: right of it, level; or left of it, above or below. */
|
|
149
|
+
export function endLabelOffset(
|
|
150
|
+
anchor: EndLabelAnchor,
|
|
151
|
+
side: EndLabelSide = 'above',
|
|
152
|
+
): { dx: number; dy: number } {
|
|
153
|
+
if (anchor === 'start') return { dx: END_LABEL_DX, dy: 0 }
|
|
154
|
+
return { dx: -END_LABEL_DX, dy: side === 'above' ? END_LABEL_FLIP_DY : END_LABEL_FLIP_DY_BELOW }
|
|
101
155
|
}
|
|
102
156
|
|
|
103
157
|
export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>[]): ChartMarks {
|
|
104
|
-
return plan.map(({ series, row, anchor }) =>
|
|
158
|
+
return plan.map(({ series, row, anchor, side, nudge }) =>
|
|
105
159
|
decorative(
|
|
106
160
|
text([row], {
|
|
107
161
|
id: `${series.key}-end-label`,
|
|
@@ -111,7 +165,8 @@ export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>
|
|
|
111
165
|
fill: series.color,
|
|
112
166
|
fontSize: VX.text.micro,
|
|
113
167
|
anchor,
|
|
114
|
-
|
|
168
|
+
dx: endLabelOffset(anchor, side).dx,
|
|
169
|
+
dy: endLabelOffset(anchor, side).dy + nudge,
|
|
115
170
|
}),
|
|
116
171
|
),
|
|
117
172
|
)
|
package/src/charts/legend.tsx
CHANGED
|
@@ -49,7 +49,8 @@ const rowBaseStyle: CSSProperties = {
|
|
|
49
49
|
flexWrap: 'wrap',
|
|
50
50
|
alignItems: 'center',
|
|
51
51
|
rowGap: 4,
|
|
52
|
-
|
|
52
|
+
// The tick step: ticks, legend and tooltip are one size, so a chart card has at most three.
|
|
53
|
+
fontSize: VX.text.micro,
|
|
53
54
|
color: VX.ink2,
|
|
54
55
|
lineHeight: 1.35,
|
|
55
56
|
}
|
|
@@ -153,29 +154,15 @@ function Swatch({ s, mode }: { s: SwatchStyle; mode: LegendMode }): ReactElement
|
|
|
153
154
|
</>
|
|
154
155
|
)
|
|
155
156
|
if ((s.mark ?? 'line') === 'line') return <LineSwatch s={s} compact={mode === 'dots'} />
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<span
|
|
159
|
-
aria-hidden
|
|
160
|
-
className={classes.dot}
|
|
161
|
-
style={{
|
|
162
|
-
width: 8,
|
|
163
|
-
height: 8,
|
|
164
|
-
// theme-allow raw-surface — a legend dot is a circle, not a surface corner
|
|
165
|
-
borderRadius: '50%',
|
|
166
|
-
background: swatchFill(s),
|
|
167
|
-
opacity: s.fillOpacity ?? 1,
|
|
168
|
-
flex: 'none',
|
|
169
|
-
}}
|
|
170
|
-
/>
|
|
171
|
-
)
|
|
157
|
+
// One shape per mark kind at every width: a bar is a rounded square, compact (8) or wide (10).
|
|
158
|
+
const size = mode === 'dots' ? 8 : 10
|
|
172
159
|
return (
|
|
173
160
|
<span
|
|
174
161
|
aria-hidden
|
|
175
|
-
className={classes.chip}
|
|
162
|
+
className={mode === 'dots' ? classes.dot : classes.chip}
|
|
176
163
|
style={{
|
|
177
|
-
width:
|
|
178
|
-
height:
|
|
164
|
+
width: size,
|
|
165
|
+
height: size,
|
|
179
166
|
// theme-allow raw-surface — swatch geometry, not a surface corner
|
|
180
167
|
borderRadius: 2,
|
|
181
168
|
background: swatchFill(s),
|
|
@@ -196,6 +183,8 @@ export type ChartLegendProps<T> = {
|
|
|
196
183
|
onHighlight: (key: string | null) => void
|
|
197
184
|
/** Keeps the legend's box but shows and offers nothing: a chart with no marks names no series. */
|
|
198
185
|
concealed?: boolean
|
|
186
|
+
/** `auto` mode only: gone from the wide class up, where end labels name the lines (CSS). */
|
|
187
|
+
hideAtWide?: boolean
|
|
199
188
|
}
|
|
200
189
|
|
|
201
190
|
export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null {
|
|
@@ -210,6 +199,7 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
210
199
|
// `aria-hidden` is belt-and-braces for a tree that ignores computed visibility.
|
|
211
200
|
{...(props.concealed && { 'aria-hidden': true })}
|
|
212
201
|
{...(auto && { className: classes.auto })}
|
|
202
|
+
{...(auto && props.hideAtWide && { 'data-hide-wide': '' })}
|
|
213
203
|
style={rowLayout(props.mode, props.concealed === true)}
|
|
214
204
|
>
|
|
215
205
|
{groups.map((group, gi) => [
|
package/src/charts/marks.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function lineMark<T, X extends ChartX>(
|
|
|
52
52
|
stroke: s.color,
|
|
53
53
|
strokeWidth: s.strokeWidth ?? LINE_STROKE_WIDTH,
|
|
54
54
|
strokeOpacity: (s.strokeOpacity ?? 1) * emphasis(plot.highlighted, s),
|
|
55
|
-
curve: chartCurve(s.curve ?? '
|
|
55
|
+
curve: chartCurve(s.curve ?? 'linear'),
|
|
56
56
|
...(s.dash === 'dashed' && { strokeDasharray: DASH }),
|
|
57
57
|
...(yScale !== undefined && { yScale }),
|
|
58
58
|
})
|
package/src/charts/panel.tsx
CHANGED
|
@@ -90,15 +90,12 @@ export const paneY = (opts: {
|
|
|
90
90
|
format: (v: number) => string
|
|
91
91
|
ticks: number
|
|
92
92
|
cls: ContainerClass
|
|
93
|
-
/** The whole chart's height ({@link chartHeightOf}). */
|
|
94
|
-
height: number
|
|
95
93
|
}): StoredChartSpec['scales'][string] => ({
|
|
96
94
|
scale: opts.scale,
|
|
97
95
|
...yGuide({
|
|
98
96
|
cfg: { ticks: opts.ticks },
|
|
99
97
|
axis: { domain: opts.domain, format: opts.format },
|
|
100
98
|
cls: opts.cls,
|
|
101
|
-
height: opts.height,
|
|
102
99
|
side: 'left',
|
|
103
100
|
grid: true,
|
|
104
101
|
}),
|
|
@@ -113,23 +110,11 @@ export const paneX = <X extends ChartX>(opts: {
|
|
|
113
110
|
/** A consumer's x format; absent, the span-aware default ({@link xTickFormat}). */
|
|
114
111
|
format?: ((v: ChartValue) => string) | undefined
|
|
115
112
|
cls: ContainerClass
|
|
116
|
-
/** The whole chart's height ({@link chartHeightOf}). */
|
|
117
|
-
height: number
|
|
118
113
|
}): StoredChartSpec['scales'][string] => ({
|
|
119
114
|
scale: opts.scale,
|
|
120
|
-
...xGuide({
|
|
121
|
-
model: opts.model,
|
|
122
|
-
xTicks: undefined,
|
|
123
|
-
format: opts.format,
|
|
124
|
-
cls: opts.cls,
|
|
125
|
-
height: opts.height,
|
|
126
|
-
}),
|
|
115
|
+
...xGuide({ model: opts.model, xTicks: undefined, format: opts.format, cls: opts.cls }),
|
|
127
116
|
})
|
|
128
117
|
|
|
129
|
-
/** The whole chart's height from one pane's: a pane gets `share` of the height less the gap. */
|
|
130
|
-
export const chartHeightOf = (paneHeight: number, share: number, gap: number): number =>
|
|
131
|
-
paneHeight > 0 && share > 0 ? paneHeight / share + gap : 0
|
|
132
|
-
|
|
133
118
|
/** One row per datum for a series: a `null` or non-finite value is kept as a gap. */
|
|
134
119
|
export function rowsOf<T, X extends ChartX>(
|
|
135
120
|
data: readonly T[],
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a reference line's caption sits. Pure, so the rule is tested without an engine: a
|
|
3
|
+
* caption takes the first of four spots (end/start of the plot, above/below its line) that stays
|
|
4
|
+
* inside the plot and that no data line runs through; `RefLine.labelPosition` pins one.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type RefLabelPosition = 'end-above' | 'end-below' | 'start-above' | 'start-below'
|
|
8
|
+
|
|
9
|
+
/** A data point as a share of the plot width and a y value on the line's own axis. */
|
|
10
|
+
export type RefLabelPoint = { fx: number; y: number }
|
|
11
|
+
|
|
12
|
+
/** A glyph's advance as a share of the font size (proportional Latin text, capitals included). */
|
|
13
|
+
const GLYPH_EM = 0.62
|
|
14
|
+
/** The inset from the plot edge (the text's `dx`) and the gap between caption and line, in px. */
|
|
15
|
+
const EDGE_INSET = 6
|
|
16
|
+
const LINE_GAP = 3
|
|
17
|
+
|
|
18
|
+
const ORDER_END: readonly RefLabelPosition[] = [
|
|
19
|
+
'end-above',
|
|
20
|
+
'end-below',
|
|
21
|
+
'start-above',
|
|
22
|
+
'start-below',
|
|
23
|
+
]
|
|
24
|
+
const ORDER_START: readonly RefLabelPosition[] = [
|
|
25
|
+
'start-above',
|
|
26
|
+
'start-below',
|
|
27
|
+
'end-above',
|
|
28
|
+
'end-below',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
/** The y range of the polyline `points` (sorted by `fx`) between `fx0` and `fx1`, or `null`. */
|
|
32
|
+
function yRangeWithin(
|
|
33
|
+
points: readonly RefLabelPoint[],
|
|
34
|
+
fx0: number,
|
|
35
|
+
fx1: number,
|
|
36
|
+
): [number, number] | null {
|
|
37
|
+
let lo = Infinity
|
|
38
|
+
let hi = -Infinity
|
|
39
|
+
const take = (y: number): void => {
|
|
40
|
+
if (y < lo) lo = y
|
|
41
|
+
if (y > hi) hi = y
|
|
42
|
+
}
|
|
43
|
+
const at = (a: RefLabelPoint, b: RefLabelPoint, fx: number): number =>
|
|
44
|
+
b.fx === a.fx ? a.y : a.y + ((b.y - a.y) * (fx - a.fx)) / (b.fx - a.fx)
|
|
45
|
+
for (let i = 0; i < points.length; i++) {
|
|
46
|
+
const p = points[i] as RefLabelPoint
|
|
47
|
+
if (p.fx >= fx0 && p.fx <= fx1) take(p.y)
|
|
48
|
+
const next = points[i + 1]
|
|
49
|
+
if (next === undefined || (p.fx < fx0 && next.fx < fx0) || (p.fx > fx1 && next.fx > fx1))
|
|
50
|
+
continue
|
|
51
|
+
// A segment entering or leaving the window contributes where it crosses its edge.
|
|
52
|
+
for (const edge of [fx0, fx1]) {
|
|
53
|
+
if ((p.fx < edge && next.fx > edge) || (p.fx > edge && next.fx < edge))
|
|
54
|
+
take(at(p.fx < next.fx ? p : next, p.fx < next.fx ? next : p, edge))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return lo <= hi ? [lo, hi] : null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function refLabelPosition(opts: {
|
|
61
|
+
/** `RefLine.labelPosition`: wins over everything. */
|
|
62
|
+
pinned: RefLabelPosition | undefined
|
|
63
|
+
/** The default end when nothing constrains it: `true` for a right-axis line. */
|
|
64
|
+
startFirst: boolean
|
|
65
|
+
value: number
|
|
66
|
+
domain: readonly [number, number]
|
|
67
|
+
plotWidth: number
|
|
68
|
+
plotHeight: number
|
|
69
|
+
label: string
|
|
70
|
+
fontSize: number
|
|
71
|
+
/** One polyline per visible series on the line's axis. */
|
|
72
|
+
series: readonly (readonly RefLabelPoint[])[]
|
|
73
|
+
}): RefLabelPosition {
|
|
74
|
+
const { pinned, startFirst, value, plotWidth, plotHeight, label, fontSize, series } = opts
|
|
75
|
+
const order = startFirst ? ORDER_START : ORDER_END
|
|
76
|
+
if (pinned !== undefined) return pinned
|
|
77
|
+
const [lo, hi] = [Math.min(...opts.domain), Math.max(...opts.domain)]
|
|
78
|
+
if (hi === lo || plotWidth <= 0 || plotHeight <= 0) return order[0] as RefLabelPosition
|
|
79
|
+
const perPx = (hi - lo) / plotHeight
|
|
80
|
+
const widthFx = (label.length * fontSize * GLYPH_EM + EDGE_INSET) / plotWidth
|
|
81
|
+
const heightPx = fontSize + 2
|
|
82
|
+
const bandOf = (position: RefLabelPosition): [number, number] =>
|
|
83
|
+
position.endsWith('above')
|
|
84
|
+
? [value + LINE_GAP * perPx, value + (LINE_GAP + heightPx) * perPx]
|
|
85
|
+
: [value - (LINE_GAP + heightPx) * perPx, value - LINE_GAP * perPx]
|
|
86
|
+
const inPlot = (position: RefLabelPosition): boolean => {
|
|
87
|
+
const [from, to] = bandOf(position)
|
|
88
|
+
return from >= lo && to <= hi
|
|
89
|
+
}
|
|
90
|
+
const clear = (position: RefLabelPosition): boolean => {
|
|
91
|
+
const [from, to] = bandOf(position)
|
|
92
|
+
const [fx0, fx1] = position.startsWith('end')
|
|
93
|
+
? [1 - widthFx, 1 - EDGE_INSET / plotWidth]
|
|
94
|
+
: [EDGE_INSET / plotWidth, widthFx]
|
|
95
|
+
return series.every((points) => {
|
|
96
|
+
const range = yRangeWithin(points, fx0, fx1)
|
|
97
|
+
return range === null || range[1] < from || range[0] > to
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
// A caption that cannot avoid the data still stays inside the plot.
|
|
101
|
+
return (
|
|
102
|
+
order.find((p) => inPlot(p) && clear(p)) ?? order.find(inPlot) ?? (order[0] as RefLabelPosition)
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The gap between a sparkline reference label's box and its line, px. */
|
|
107
|
+
const SPARK_LABEL_GAP = 2
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Which side of its line a sparkline's reference label sits on, and its `dy` (the engine centres
|
|
111
|
+
* the text on its y): above by default, below when the line is too near the plot top for the label
|
|
112
|
+
* box to fit above it. The box clears the line by {@link SPARK_LABEL_GAP}, so the dashed rule never
|
|
113
|
+
* strikes the text, and stays inside the plot (`height` less the line inset each side).
|
|
114
|
+
*/
|
|
115
|
+
export function referenceLabelPlacement(opts: {
|
|
116
|
+
value: number
|
|
117
|
+
domain: readonly [number, number]
|
|
118
|
+
height: number
|
|
119
|
+
/** The plot's margin inside the svg box, px. */
|
|
120
|
+
inset: number
|
|
121
|
+
fontSize: number
|
|
122
|
+
}): { side: 'above' | 'below'; dy: number } {
|
|
123
|
+
const { value, domain, height, inset, fontSize } = opts
|
|
124
|
+
const [lo, hi] = [Math.min(...domain), Math.max(...domain)]
|
|
125
|
+
const share = hi === lo ? 0 : (value - lo) / (hi - lo)
|
|
126
|
+
const line = inset + (height - 2 * inset) * (1 - share)
|
|
127
|
+
const reach = SPARK_LABEL_GAP + fontSize + 1
|
|
128
|
+
const side = line - reach >= 0 || line + reach > height ? 'above' : 'below'
|
|
129
|
+
const dy = (SPARK_LABEL_GAP + (fontSize + 1) / 2) * (side === 'above' ? -1 : 1)
|
|
130
|
+
return { side, dy }
|
|
131
|
+
}
|
package/src/charts/scales.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { scaleBand } from '@tanstack/charts/scales/band'
|
|
8
8
|
import { scaleLinear } from '@tanstack/charts/scales/linear'
|
|
9
9
|
import { scalePoint } from '@tanstack/charts/scales/point'
|
|
10
|
-
import { scaleLog, scaleUtc } from 'd3-scale'
|
|
10
|
+
import { scaleLinear as d3Linear, scaleLog, scaleUtc } from 'd3-scale'
|
|
11
11
|
import type { ChartPositionScaleOptions } from '@tanstack/charts/types/core'
|
|
12
12
|
import type { AxisConfig, ChartSeries, ChartX, XZoneSpec } from './types'
|
|
13
13
|
|
|
@@ -25,6 +25,23 @@ export function padAutoUpper(candidate: number, pad: number): number {
|
|
|
25
25
|
return candidate > 0 ? candidate * pad : candidate / pad
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Raises `upper` until the axis' top tick (for `count` ticks over `[lower, upper]`) reaches `max`:
|
|
30
|
+
* a padded domain can end between ticks, so the line peaks above the last label. Each step adds
|
|
31
|
+
* one tick interval, so the loop ends within a few turns.
|
|
32
|
+
*/
|
|
33
|
+
function coverTop(lower: number, upper: number, max: number, count: number): number {
|
|
34
|
+
let top = upper
|
|
35
|
+
for (let i = 0; i < 4; i++) {
|
|
36
|
+
const ticks = d3Linear().domain([lower, top]).ticks(count)
|
|
37
|
+
const last = ticks.at(-1)
|
|
38
|
+
const step = ticks.length > 1 ? (ticks[1] as number) - (ticks[0] as number) : 0
|
|
39
|
+
if (last === undefined || step <= 0 || last >= max) return top
|
|
40
|
+
top = last + step
|
|
41
|
+
}
|
|
42
|
+
return top
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
/**
|
|
29
46
|
* One y axis' domain. `extraBounds` are the finite zone and reference-line values pinned to this
|
|
30
47
|
* axis — a target past the data must stay inside the plot. Infinite bounds clamp to the domain by
|
|
@@ -35,6 +52,9 @@ export function resolveYDomain<T>(
|
|
|
35
52
|
data: readonly T[],
|
|
36
53
|
series: readonly ChartSeries<T>[],
|
|
37
54
|
extraBounds: readonly number[] = [],
|
|
55
|
+
/** The number of ticks the axis will draw (0: none, or its own tick values): when set, an AUTO
|
|
56
|
+
* domain ends on a tick at or above the data's maximum. */
|
|
57
|
+
tickCount = 0,
|
|
38
58
|
): readonly [number, number] {
|
|
39
59
|
const domain = cfg?.domain ?? 'auto'
|
|
40
60
|
if (Array.isArray(domain)) return domain as readonly [number, number]
|
|
@@ -67,7 +87,7 @@ export function resolveYDomain<T>(
|
|
|
67
87
|
const lower = padAutoLower(Math.min(min, cfg?.autoMinCeil ?? 0), pad)
|
|
68
88
|
// A flat series would be a scale with no extent: every point on one pixel.
|
|
69
89
|
if (lower === upper) return [Math.min(lower, 0), upper === 0 ? 1 : upper * pad]
|
|
70
|
-
return [lower, upper]
|
|
90
|
+
return [lower, tickCount > 0 && !cfg?.nice ? coverTop(lower, upper, max, tickCount) : upper]
|
|
71
91
|
}
|
|
72
92
|
|
|
73
93
|
/** A configured y scale instance for a resolved domain. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip, so a narrow cell
|
|
3
|
-
* cannot be escaped. It sits
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* cannot be escaped. It sits INSIDE the plot box, beside the hovered point (the roomier side, so it
|
|
4
|
+
* flips at the edges) and on the half of the box away from the point, so it covers neither the dot
|
|
5
|
+
* nor anything the host draws round the sparkline (a card's delta period, a strip's caption): a chip
|
|
6
|
+
* above the box landed on that text, and a host slot that clips took it off the page. Where it
|
|
7
|
+
* crosses the line it is opaque, so it reads over it. Placement is inline (`Sparkline.tsx`).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
.root {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
.readout {
|
|
15
15
|
position: absolute;
|
|
16
|
-
bottom: 100%;
|
|
17
16
|
z-index: 1;
|
|
17
|
+
max-height: 100%;
|
|
18
18
|
max-width: 100%;
|
|
19
19
|
box-sizing: border-box;
|
|
20
20
|
padding: 0 4px;
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
23
23
|
font-variant-numeric: lining-nums;
|
|
24
24
|
font-size: var(--vx-text-xs);
|
|
25
|
-
/* The
|
|
26
|
-
* value (`stat-card.module.css`, `stat-strip.module.css`)
|
|
25
|
+
/* The chip's height: hosts that reserve a line for it set `--basalt-spark-readout-h` to the same
|
|
26
|
+
* value (`stat-card.module.css`, `stat-strip.module.css`). */
|
|
27
27
|
block-size: var(--basalt-spark-readout-h, 1.125rem);
|
|
28
28
|
line-height: calc(var(--basalt-spark-readout-h, 1.125rem) - 2px);
|
|
29
29
|
color: var(--vx-tooltip-text);
|
|
@@ -35,19 +35,15 @@
|
|
|
35
35
|
border-radius: var(--vx-radius-ctrl);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
.start {
|
|
39
|
-
left: 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.end {
|
|
43
|
-
right: 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
38
|
.label {
|
|
47
|
-
font-family: var(--basalt-font-mono);
|
|
48
39
|
opacity: 0.7;
|
|
49
40
|
}
|
|
50
41
|
|
|
42
|
+
.layer {
|
|
43
|
+
position: absolute;
|
|
44
|
+
pointer-events: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
51
47
|
.dot {
|
|
52
48
|
position: absolute;
|
|
53
49
|
width: 6px;
|
package/src/charts/state.tsx
CHANGED
|
@@ -53,6 +53,8 @@ const dotStyle: CSSProperties = {
|
|
|
53
53
|
const errorStyle: CSSProperties = {
|
|
54
54
|
...boxStyle,
|
|
55
55
|
alignItems: 'flex-start',
|
|
56
|
+
justifyContent: 'flex-start',
|
|
57
|
+
paddingBottom: VX.space.controlGap,
|
|
56
58
|
textAlign: 'start',
|
|
57
59
|
fontSize: VX.text.sm,
|
|
58
60
|
gap: VX.space.controlGap,
|
|
@@ -68,7 +70,7 @@ const errorHeadStyle: CSSProperties = {
|
|
|
68
70
|
const errorMessageStyle: CSSProperties = { color: VX.muted }
|
|
69
71
|
|
|
70
72
|
const emptyLabel = (state: ChartState | undefined): string =>
|
|
71
|
-
typeof state?.empty === 'string' ? state.empty : '
|
|
73
|
+
typeof state?.empty === 'string' ? state.empty : 'Nothing recorded in this range.'
|
|
72
74
|
|
|
73
75
|
/** Fills the same {@link ChartBox} the chart will, so a pending, failed or empty chart (and a
|
|
74
76
|
* `<Suspense>` fallback built from one) occupies the final chart's height. */
|
|
@@ -84,12 +86,15 @@ export function ChartPlaceholder(props: {
|
|
|
84
86
|
/** For a box too small to hold a sentence (a sparkline): error and empty show a `—` and carry the
|
|
85
87
|
* label as the accessible name and the hover title. */
|
|
86
88
|
compact?: boolean
|
|
89
|
+
/** Error only: what failed to load, "Could not load {noun}". Default: no noun. */
|
|
90
|
+
noun?: string
|
|
87
91
|
}): ReactElement | null {
|
|
88
92
|
const kind = resolveChartState(props.state)
|
|
89
93
|
if (kind === null) return null
|
|
90
94
|
const style = kind === 'pending' ? pendingStyle : kind === 'error' ? errorStyle : boxStyle
|
|
91
|
-
// An error
|
|
92
|
-
//
|
|
95
|
+
// An error keeps the chart's height as a floor (the frame does not jump, `ssr-contract`) and may
|
|
96
|
+
// grow past it rather than clip its action; its anatomy is top-aligned, so the room is plain
|
|
97
|
+
// card below the content, not a block of text floating mid-card.
|
|
93
98
|
const fit = (node: ReactElement): ReactElement => (
|
|
94
99
|
<ChartBox height={props.height} {...(kind === 'error' && { className: growClass })}>
|
|
95
100
|
{node}
|
|
@@ -110,7 +115,7 @@ export function ChartPlaceholder(props: {
|
|
|
110
115
|
{kind === 'error' && (
|
|
111
116
|
<span style={errorHeadStyle}>
|
|
112
117
|
<span aria-hidden="true" data-basalt-status-dot="" style={dotStyle} />
|
|
113
|
-
Could not load
|
|
118
|
+
Could not load{props.noun === undefined ? '' : ` ${props.noun}`}
|
|
114
119
|
</span>
|
|
115
120
|
)}
|
|
116
121
|
<span style={errorMessageStyle}>{label}</span>
|