basalt-ui 2.19.0 → 2.21.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 +89 -0
- package/MIGRATING.md +291 -12
- package/agent/agents/basalt-design-reviewer.md +22 -5
- package/agent/rules/basalt-charts.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-tokens.md +2 -2
- package/agent/skills/basalt-app/SKILL.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +10 -23
- package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
- package/agent/skills/basalt-design/references/catalogue.md +48 -0
- package/agent/skills/basalt-design/references/concept.md +36 -0
- package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
- package/agent/skills/basalt-design/references/stat-tile.md +24 -0
- package/agent/templates/AGENTS-block.md.tpl +3 -3
- package/agent/templates/DESIGN.md.tpl +1 -1
- package/configs/oxlint-plugin.js +34 -19
- package/configs/oxlint-plugin.test.ts +32 -2
- package/dist/charts/ChartCard.d.ts +33 -4
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +37 -11
- package/dist/charts/Donut.d.ts.map +1 -1
- package/dist/charts/Donut.js +13 -1
- package/dist/charts/Heatmap.js +1 -1
- package/dist/charts/Sparkline.d.ts +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +137 -18
- package/dist/charts/box.d.ts +2 -0
- package/dist/charts/box.d.ts.map +1 -1
- package/dist/charts/box.js +2 -0
- package/dist/charts/chart-box.module.css +30 -0
- package/dist/charts/chart-box.module.css.d.ts +1 -0
- package/dist/charts/chart-card.module.css +47 -0
- package/dist/charts/chart-card.module.css.d.ts +7 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +35 -8
- package/dist/charts/host.d.ts.map +1 -1
- package/dist/charts/host.js +2 -1
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/sparkline.module.css +59 -0
- package/dist/charts/sparkline.module.css.d.ts +13 -0
- package/dist/charts/state.d.ts +5 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +34 -4
- package/dist/charts/types.d.ts +6 -0
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +3 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +3 -2
- package/dist/cli/index.d.ts +4 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +27 -15
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +3 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +6 -1
- package/dist/cli/shot/detect.d.ts +51 -0
- package/dist/cli/shot/detect.d.ts.map +1 -0
- package/dist/cli/shot/detect.js +396 -0
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +7 -4
- package/dist/cli/shot/measure.d.ts +2 -0
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +2 -0
- package/dist/cli/shot/types.d.ts +4 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- package/dist/cli/sync.d.ts +2 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -2
- package/dist/common/retry-button.d.ts +12 -0
- package/dist/common/retry-button.d.ts.map +1 -0
- package/dist/common/retry-button.js +22 -0
- package/dist/common/retry-button.module.css +58 -0
- package/dist/common/retry-button.module.css.d.ts +8 -0
- package/dist/controls/sync-button.d.ts +3 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/dashboard/bar-list.d.ts +18 -4
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +39 -15
- package/dist/dashboard/bar-list.module.css +77 -2
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/delta-badge.d.ts +8 -3
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +9 -2
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/meter-model.d.ts +53 -6
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +62 -14
- package/dist/dashboard/meter-parts.d.ts +5 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +140 -68
- package/dist/dashboard/meter.d.ts +29 -4
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +8 -1
- package/dist/dashboard/meter.module.css +74 -43
- package/dist/dashboard/meter.module.css.d.ts +4 -4
- package/dist/dashboard/query-state.d.ts +1 -1
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +16 -10
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +14 -25
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +1 -1
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +5 -7
- package/dist/dashboard/stat-card.module.css +15 -7
- package/dist/dashboard/stat-group.d.ts +11 -2
- package/dist/dashboard/stat-group.d.ts.map +1 -1
- package/dist/dashboard/stat-group.js +9 -7
- package/dist/dashboard/stat-strip.d.ts +67 -0
- package/dist/dashboard/stat-strip.d.ts.map +1 -0
- package/dist/dashboard/stat-strip.js +115 -0
- package/dist/dashboard/stat-strip.module.css +291 -0
- package/dist/dashboard/stat-strip.module.css.d.ts +32 -0
- package/dist/dashboard/visual-slot.d.ts +2 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -0
- package/dist/dashboard/visual-slot.js +5 -0
- package/dist/dashboard/widget-header.d.ts +3 -3
- package/dist/dashboard/widget-header.module.css +10 -6
- package/dist/format/date.d.ts.map +1 -1
- package/dist/format/date.js +4 -3
- package/dist/format/shared.d.ts +6 -0
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +6 -2
- package/dist/guard/index.d.ts +16 -3
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +15 -1
- package/dist/guard/palette.d.ts +51 -0
- package/dist/guard/palette.d.ts.map +1 -0
- package/dist/guard/palette.js +190 -0
- package/dist/guard/series-file.d.ts +15 -0
- package/dist/guard/series-file.d.ts.map +1 -0
- package/dist/guard/series-file.js +29 -0
- package/dist/guard/types.d.ts +3 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/styles.css +6 -0
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/dist/theme/card-inset.module.css +76 -0
- package/dist/theme/card-inset.module.css.d.ts +9 -0
- package/dist/theme/controls.module.css +13 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +41 -0
- package/dist/theme/nav-link.module.css +8 -10
- package/dist/theme/status-dot.d.ts +3 -2
- package/dist/theme/status-dot.d.ts.map +1 -1
- package/dist/theme/status-dot.js +12 -3
- package/dist/theme/status-verdict.d.ts +3 -2
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +3 -2
- package/dist/theme/status-verdict.module.css +4 -2
- package/dist/tokens/oklab.d.ts +28 -0
- package/dist/tokens/oklab.d.ts.map +1 -0
- package/dist/tokens/oklab.js +73 -0
- package/llms.txt +33 -7
- package/package.json +1 -1
- package/src/charts/ChartCard.tsx +79 -5
- package/src/charts/Donut.tsx +9 -1
- package/src/charts/Heatmap.tsx +1 -1
- package/src/charts/Sparkline.tsx +180 -18
- package/src/charts/box.tsx +2 -0
- package/src/charts/chart-box.module.css +30 -0
- package/src/charts/chart-box.module.css.d.ts +1 -0
- package/src/charts/chart-card.module.css +47 -0
- package/src/charts/chart-card.module.css.d.ts +7 -0
- package/src/charts/compile.ts +42 -9
- package/src/charts/host.tsx +6 -3
- package/src/charts/index.ts +1 -1
- package/src/charts/sparkline.module.css +59 -0
- package/src/charts/sparkline.module.css.d.ts +13 -0
- package/src/charts/state.tsx +53 -4
- package/src/charts/types.ts +6 -0
- package/src/cli/check-theme.ts +3 -0
- package/src/cli/help.ts +18 -1
- package/src/cli/index.ts +48 -17
- package/src/cli/init.ts +2 -1
- package/src/cli/shot/capture.ts +15 -2
- package/src/cli/shot/detect.ts +533 -0
- package/src/cli/shot/index.ts +8 -4
- package/src/cli/shot/measure.ts +4 -0
- package/src/cli/shot/types.ts +5 -1
- package/src/cli/sync.ts +4 -2
- package/src/common/retry-button.module.css +58 -0
- package/src/common/retry-button.module.css.d.ts +8 -0
- package/src/common/retry-button.tsx +29 -0
- package/src/controls/sync-button.tsx +3 -0
- package/src/dashboard/bar-list.module.css +77 -2
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +89 -18
- package/src/dashboard/delta-badge.tsx +21 -5
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-model.ts +126 -20
- package/src/dashboard/meter-parts.tsx +224 -88
- package/src/dashboard/meter.module.css +74 -43
- package/src/dashboard/meter.module.css.d.ts +4 -4
- package/src/dashboard/meter.tsx +39 -5
- package/src/dashboard/query-state.tsx +26 -20
- package/src/dashboard/settings-section.tsx +1 -8
- package/src/dashboard/stat-card-parts.tsx +1 -1
- package/src/dashboard/stat-card.module.css +15 -7
- package/src/dashboard/stat-card.tsx +9 -9
- package/src/dashboard/stat-group.tsx +19 -8
- package/src/dashboard/stat-strip.module.css +291 -0
- package/src/dashboard/stat-strip.module.css.d.ts +32 -0
- package/src/dashboard/stat-strip.tsx +263 -0
- package/src/dashboard/visual-slot.ts +8 -0
- package/src/dashboard/widget-header.module.css +10 -6
- package/src/dashboard/widget-header.tsx +3 -3
- package/src/format/date.ts +6 -3
- package/src/format/shared.ts +11 -2
- package/src/guard/index.ts +17 -5
- package/src/guard/palette.ts +261 -0
- package/src/guard/series-file.ts +51 -0
- package/src/guard/types.ts +3 -2
- package/src/index.ts +7 -0
- package/src/styles.css +6 -0
- package/src/surfaces.ts +2 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +202 -24
- package/src/theme/card-inset.module.css +76 -0
- package/src/theme/card-inset.module.css.d.ts +9 -0
- package/src/theme/controls.module.css +13 -0
- package/src/theme/index.ts +56 -0
- package/src/theme/nav-link.module.css +8 -10
- package/src/theme/status-dot.tsx +17 -5
- package/src/theme/status-verdict.module.css +4 -2
- package/src/theme/status-verdict.tsx +9 -4
- package/src/tokens/oklab.ts +97 -0
package/src/charts/Sparkline.tsx
CHANGED
|
@@ -8,18 +8,22 @@
|
|
|
8
8
|
import { dot } from '@tanstack/charts/dot'
|
|
9
9
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
10
10
|
import { lineY } from '@tanstack/charts/line'
|
|
11
|
+
import { ruleY } from '@tanstack/charts/rule'
|
|
11
12
|
import { scaleBand } from '@tanstack/charts/scales/band'
|
|
12
13
|
import { scaleLinear } from '@tanstack/charts/scales/linear'
|
|
13
|
-
import { useId, useMemo } from 'react'
|
|
14
|
-
import type { ReactElement } from 'react'
|
|
14
|
+
import { useId, useMemo, useState } from 'react'
|
|
15
|
+
import type { FocusEvent, KeyboardEvent, PointerEvent, ReactElement } from 'react'
|
|
16
|
+
import { cx } from '../common/props'
|
|
15
17
|
import type { BasaltProps } from '../common/props'
|
|
16
18
|
import { VX } from '../tokens'
|
|
17
19
|
import type { CartesianDefinition } from './compile'
|
|
18
20
|
import { chartCurve } from './curves'
|
|
19
21
|
import { barMark } from './marks'
|
|
22
|
+
import { defaultNumberFormat } from './compile'
|
|
20
23
|
import { ChartEngine, idPrefixOf } from './host'
|
|
24
|
+
import classes from './sparkline.module.css'
|
|
21
25
|
import { ChartPlaceholder, resolveChartState } from './state'
|
|
22
|
-
import { CHART_THEME } from './theme'
|
|
26
|
+
import { CHART_THEME, DASH } from './theme'
|
|
23
27
|
import type { ChartState } from './types'
|
|
24
28
|
|
|
25
29
|
export type SparklineProps = BasaltProps & {
|
|
@@ -43,6 +47,13 @@ export type SparklineProps = BasaltProps & {
|
|
|
43
47
|
/** Pending / error / empty, the same contract as every other kind. The placeholder fills the
|
|
44
48
|
* sparkline's own `width` × `height`, so a loading tile does not shift when the trend lands. */
|
|
45
49
|
state?: ChartState | undefined
|
|
50
|
+
/** A quiet dashed hairline at a value, or at the mean of the plotted values (`'mean'`). The y
|
|
51
|
+
* domain widens to include it. Not a legend item, never a status colour. */
|
|
52
|
+
reference?: number | 'mean' | undefined
|
|
53
|
+
/** Formats the readout's value. Default: the compact number format. */
|
|
54
|
+
format?: ((value: number) => string) | undefined
|
|
55
|
+
/** The readout's x label per point, index-aligned with `data`. Omitted: the value alone. */
|
|
56
|
+
labels?: readonly string[] | undefined
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
type Point = { i: number; v: number | null }
|
|
@@ -165,13 +176,45 @@ export function poolSparkline(
|
|
|
165
176
|
return mark === 'bar' ? poolBar(rows, cap) : poolLine(rows, cap)
|
|
166
177
|
}
|
|
167
178
|
|
|
179
|
+
type Frame = { x: readonly [number, number]; y: readonly [number, number] }
|
|
180
|
+
|
|
181
|
+
/** The domains a series is drawn in — shared by the compile and the readout's dot, which
|
|
182
|
+
* must land where the mark did. A bar's x is a band, so only its y is a continuous domain. */
|
|
183
|
+
function frameOf(
|
|
184
|
+
[lo, hi]: readonly [number, number],
|
|
185
|
+
mark: 'line' | 'bar',
|
|
186
|
+
count: number,
|
|
187
|
+
hasEnd: boolean,
|
|
188
|
+
): Frame {
|
|
189
|
+
if (mark === 'bar') return { x: [0, count], y: [Math.min(lo, 0), Math.max(hi, 0) || 1] }
|
|
190
|
+
// A flat or single-point series needs an extent; 10% air keeps the stroke inside the box.
|
|
191
|
+
const pad = (hi - lo) * 0.1 || 1
|
|
192
|
+
// Half a dot of air at each end, in index units, so the last-point dot is not clipped.
|
|
193
|
+
const xPad = hasEnd ? (count - 1) * 0.04 || 0.5 : 0
|
|
194
|
+
return { x: [-xPad, Math.max(count - 1, 1) + xPad], y: [lo - pad, hi + pad] }
|
|
195
|
+
}
|
|
196
|
+
|
|
168
197
|
function compileSparkline(
|
|
169
198
|
source: readonly Point[],
|
|
170
|
-
|
|
199
|
+
extentOf: readonly [number, number],
|
|
171
200
|
mark: 'line' | 'bar',
|
|
172
201
|
color: string,
|
|
173
202
|
emphasisColor: string | null,
|
|
203
|
+
reference: number | null,
|
|
174
204
|
): CartesianDefinition {
|
|
205
|
+
const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null)
|
|
206
|
+
const referenceMark = (): readonly ReturnType<typeof ruleY>[] =>
|
|
207
|
+
reference === null
|
|
208
|
+
? []
|
|
209
|
+
: [
|
|
210
|
+
ruleY([reference], {
|
|
211
|
+
id: 'reference',
|
|
212
|
+
stroke: VX.line,
|
|
213
|
+
strokeOpacity: 1,
|
|
214
|
+
strokeWidth: 1,
|
|
215
|
+
strokeDasharray: DASH,
|
|
216
|
+
}),
|
|
217
|
+
]
|
|
175
218
|
return {
|
|
176
219
|
chart: ({ width }) => {
|
|
177
220
|
const rows = poolSparkline(source, width, mark)
|
|
@@ -179,6 +222,7 @@ function compileSparkline(
|
|
|
179
222
|
if (mark === 'bar') {
|
|
180
223
|
return {
|
|
181
224
|
marks: [
|
|
225
|
+
...referenceMark(),
|
|
182
226
|
barMark(rows, {
|
|
183
227
|
id: 'bars',
|
|
184
228
|
x: 'i',
|
|
@@ -195,7 +239,7 @@ function compileSparkline(
|
|
|
195
239
|
axis: false as const,
|
|
196
240
|
},
|
|
197
241
|
y: {
|
|
198
|
-
scale: scaleLinear().domain(
|
|
242
|
+
scale: scaleLinear().domain(frame.y),
|
|
199
243
|
axis: false as const,
|
|
200
244
|
},
|
|
201
245
|
},
|
|
@@ -204,12 +248,9 @@ function compileSparkline(
|
|
|
204
248
|
margin: 0,
|
|
205
249
|
}
|
|
206
250
|
}
|
|
207
|
-
// A flat or single-point series needs an extent; 10% air keeps the stroke inside the box.
|
|
208
|
-
const pad = (hi - lo) * 0.1 || 1
|
|
209
|
-
// Half a dot of air at each end, in index units, so the last-point dot is not clipped.
|
|
210
|
-
const xPad = emphasisColor === null ? 0 : (source.length - 1) * 0.04 || 0.5
|
|
211
251
|
return {
|
|
212
252
|
marks: [
|
|
253
|
+
...referenceMark(),
|
|
213
254
|
lineY(rows, {
|
|
214
255
|
id: 'line',
|
|
215
256
|
x: 'i',
|
|
@@ -228,10 +269,10 @@ function compileSparkline(
|
|
|
228
269
|
],
|
|
229
270
|
scales: {
|
|
230
271
|
x: {
|
|
231
|
-
scale: scaleLinear().domain(
|
|
272
|
+
scale: scaleLinear().domain(frame.x),
|
|
232
273
|
axis: false as const,
|
|
233
274
|
},
|
|
234
|
-
y: { scale: scaleLinear().domain(
|
|
275
|
+
y: { scale: scaleLinear().domain(frame.y), axis: false as const },
|
|
235
276
|
},
|
|
236
277
|
theme: CHART_THEME,
|
|
237
278
|
guides: false,
|
|
@@ -241,7 +282,31 @@ function compileSparkline(
|
|
|
241
282
|
}
|
|
242
283
|
}
|
|
243
284
|
|
|
244
|
-
/** `
|
|
285
|
+
/** An `aria-hidden` ancestor makes the sparkline decorative, whatever its own props say. */
|
|
286
|
+
const hidden = (el: HTMLElement): boolean => el.closest('[aria-hidden="true"]') !== null
|
|
287
|
+
|
|
288
|
+
/** The point `from` steps to along `dir`, skipping gaps; `from` itself when there is none. */
|
|
289
|
+
function stepFrom(rows: readonly Point[], from: number, dir: 1 | -1): number {
|
|
290
|
+
for (let i = from + dir; i >= 0 && i < rows.length; i += dir) if (rows[i]?.v !== null) return i
|
|
291
|
+
return from
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const lastFinite = (rows: readonly Point[]): number | null => {
|
|
295
|
+
const i = rows.findLastIndex((r) => r.v !== null)
|
|
296
|
+
return i < 0 ? null : i
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** The mean of the plotted (finite) values. */
|
|
300
|
+
function meanOf(rows: readonly Point[]): number {
|
|
301
|
+
let sum = 0
|
|
302
|
+
let n = 0
|
|
303
|
+
for (const r of rows) {
|
|
304
|
+
if (r.v === null) continue
|
|
305
|
+
sum += r.v
|
|
306
|
+
n += 1
|
|
307
|
+
}
|
|
308
|
+
return sum / n
|
|
309
|
+
}
|
|
245
310
|
|
|
246
311
|
export function Sparkline(props: SparklineProps): ReactElement {
|
|
247
312
|
const {
|
|
@@ -254,34 +319,131 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
254
319
|
emphasizeLast = true,
|
|
255
320
|
emphasisColor = VX.line,
|
|
256
321
|
state,
|
|
322
|
+
reference,
|
|
323
|
+
format = defaultNumberFormat,
|
|
324
|
+
labels,
|
|
257
325
|
className,
|
|
258
326
|
style,
|
|
259
327
|
} = props
|
|
260
328
|
const id = useId()
|
|
261
|
-
|
|
329
|
+
// Two sources, so a pointer leaving a focused chart hands the readout back to the focused point.
|
|
330
|
+
const [hover, setHover] = useState<number | null>(null)
|
|
331
|
+
const [keyed, setKeyed] = useState<number | null>(null)
|
|
332
|
+
const active = hover ?? keyed
|
|
333
|
+
const model = useMemo(() => {
|
|
262
334
|
const rows: Point[] = data.map((v, i) => ({ i, v: finite(v) }))
|
|
263
335
|
const range = extent(rows)
|
|
264
336
|
// No finite value means nothing to scale: the empty render, never an Infinity domain.
|
|
265
337
|
if (range === null) return null
|
|
266
|
-
|
|
267
|
-
|
|
338
|
+
const at = reference === 'mean' ? meanOf(rows) : (reference ?? null)
|
|
339
|
+
const ref = at !== null && Number.isFinite(at) ? at : null
|
|
340
|
+
// The reference is part of the extent, so it is never clipped.
|
|
341
|
+
const full: readonly [number, number] =
|
|
342
|
+
ref === null ? range : [Math.min(range[0], ref), Math.max(range[1], ref)]
|
|
343
|
+
const end = emphasizeLast ? emphasisColor : null
|
|
344
|
+
return {
|
|
345
|
+
rows,
|
|
346
|
+
frame: frameOf(full, mark, rows.length, end !== null),
|
|
347
|
+
definition: compileSparkline(rows, full, mark, color, end, ref),
|
|
348
|
+
}
|
|
349
|
+
}, [data, mark, color, emphasizeLast, emphasisColor, reference])
|
|
268
350
|
const resolved = resolveChartState(state)
|
|
351
|
+
const rows = model?.rows
|
|
352
|
+
const interactive = resolved === null && model !== null
|
|
353
|
+
|
|
354
|
+
const onPointerMove = (e: PointerEvent<HTMLDivElement>): void => {
|
|
355
|
+
if (!interactive || rows === undefined || hidden(e.currentTarget)) return
|
|
356
|
+
const box = e.currentTarget.getBoundingClientRect()
|
|
357
|
+
if (box.width <= 0) return
|
|
358
|
+
const frac = Math.min(Math.max((e.clientX - box.left) / box.width, 0), 1)
|
|
359
|
+
const [x0, x1] = model.frame.x
|
|
360
|
+
const i =
|
|
361
|
+
mark === 'bar'
|
|
362
|
+
? Math.min(Math.floor(frac * rows.length), rows.length - 1)
|
|
363
|
+
: Math.min(Math.max(Math.round(x0 + frac * (x1 - x0)), 0), rows.length - 1)
|
|
364
|
+
setHover(rows[i]?.v === null ? null : i)
|
|
365
|
+
}
|
|
366
|
+
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>): void => {
|
|
367
|
+
if (!interactive || rows === undefined || hidden(e.currentTarget)) return
|
|
368
|
+
const from = keyed ?? lastFinite(rows)
|
|
369
|
+
if (from === null) return
|
|
370
|
+
const next =
|
|
371
|
+
e.key === 'ArrowLeft'
|
|
372
|
+
? stepFrom(rows, from, -1)
|
|
373
|
+
: e.key === 'ArrowRight'
|
|
374
|
+
? stepFrom(rows, from, 1)
|
|
375
|
+
: e.key === 'Home'
|
|
376
|
+
? stepFrom(rows, -1, 1)
|
|
377
|
+
: e.key === 'End'
|
|
378
|
+
? stepFrom(rows, rows.length, -1)
|
|
379
|
+
: e.key === 'Escape'
|
|
380
|
+
? null
|
|
381
|
+
: undefined
|
|
382
|
+
if (next === undefined) return
|
|
383
|
+
e.preventDefault()
|
|
384
|
+
setHover(null)
|
|
385
|
+
setKeyed(next)
|
|
386
|
+
}
|
|
387
|
+
const onFocus = (e: FocusEvent<HTMLDivElement>): void => {
|
|
388
|
+
if (!interactive || rows === undefined || keyed !== null || hidden(e.currentTarget)) return
|
|
389
|
+
setKeyed(lastFinite(rows))
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const value = active === null ? null : (rows?.[active]?.v ?? null)
|
|
393
|
+
const at =
|
|
394
|
+
interactive && active !== null && value !== null
|
|
395
|
+
? {
|
|
396
|
+
value,
|
|
397
|
+
fx:
|
|
398
|
+
mark === 'bar'
|
|
399
|
+
? (active + 0.5) / model.rows.length
|
|
400
|
+
: (active - model.frame.x[0]) / (model.frame.x[1] - model.frame.x[0]),
|
|
401
|
+
fy: (model.frame.y[1] - value) / (model.frame.y[1] - model.frame.y[0]),
|
|
402
|
+
label: labels?.[active],
|
|
403
|
+
}
|
|
404
|
+
: null
|
|
269
405
|
return (
|
|
270
406
|
<div
|
|
271
407
|
data-basalt-sparkline=""
|
|
272
|
-
|
|
408
|
+
role="presentation"
|
|
409
|
+
className={cx(classes.root, className)}
|
|
273
410
|
style={{ width: width ?? '100%', height, minWidth: 0, ...style }}
|
|
411
|
+
onPointerMove={onPointerMove}
|
|
412
|
+
onPointerLeave={() => setHover(null)}
|
|
413
|
+
onKeyDown={onKeyDown}
|
|
414
|
+
onFocus={onFocus}
|
|
415
|
+
onBlur={() => {
|
|
416
|
+
setHover(null)
|
|
417
|
+
setKeyed(null)
|
|
418
|
+
}}
|
|
274
419
|
>
|
|
275
420
|
{resolved !== null && <ChartPlaceholder state={state} height={height} compact />}
|
|
276
|
-
{resolved === null &&
|
|
421
|
+
{resolved === null && model !== null && (
|
|
277
422
|
<ChartEngine
|
|
278
|
-
definition={definition}
|
|
423
|
+
definition={model.definition}
|
|
279
424
|
ariaLabel={ariaLabel}
|
|
280
425
|
height={height}
|
|
281
426
|
idPrefix={idPrefixOf(id, 'spark')}
|
|
282
427
|
coarse={false}
|
|
283
428
|
/>
|
|
284
429
|
)}
|
|
430
|
+
{at !== null && (
|
|
431
|
+
<>
|
|
432
|
+
<span
|
|
433
|
+
data-basalt-sparkline-dot=""
|
|
434
|
+
className={classes.dot}
|
|
435
|
+
style={{ left: `${at.fx * 100}%`, top: `${at.fy * 100}%` }}
|
|
436
|
+
/>
|
|
437
|
+
<output
|
|
438
|
+
data-basalt-sparkline-readout=""
|
|
439
|
+
aria-live={hover === null ? 'polite' : 'off'}
|
|
440
|
+
className={cx(classes.readout, at.fx > 0.5 ? classes.start : classes.end)}
|
|
441
|
+
>
|
|
442
|
+
{at.label !== undefined && <span className={classes.label}>{at.label} </span>}
|
|
443
|
+
{format(at.value)}
|
|
444
|
+
</output>
|
|
445
|
+
</>
|
|
446
|
+
)}
|
|
285
447
|
</div>
|
|
286
448
|
)
|
|
287
449
|
}
|
package/src/charts/box.tsx
CHANGED
|
@@ -62,3 +62,33 @@
|
|
|
62
62
|
width: 100%;
|
|
63
63
|
height: 100%;
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/* An error body: the box's height is the floor, so its content (and the action) always fit. */
|
|
67
|
+
.grow {
|
|
68
|
+
height: auto;
|
|
69
|
+
max-height: none;
|
|
70
|
+
min-height: var(--bc-micro);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@container (min-width: 240px) {
|
|
74
|
+
.grow {
|
|
75
|
+
min-height: var(--bc-compact);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@container (min-width: 480px) {
|
|
80
|
+
.grow {
|
|
81
|
+
min-height: var(--bc-regular);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@container (min-width: 800px) {
|
|
86
|
+
.grow {
|
|
87
|
+
min-height: var(--bc-wide);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.grow > .state {
|
|
92
|
+
height: auto;
|
|
93
|
+
min-height: inherit;
|
|
94
|
+
}
|
|
@@ -23,3 +23,50 @@
|
|
|
23
23
|
:is([data-basalt-card-short], [data-basalt-chart-card]:has([data-basalt-chart-short])) .header {
|
|
24
24
|
padding-top: 4px;
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* The facts line (`facts` prop): the headline figure under the title, in place of a subtitle. It wraps
|
|
29
|
+
* (rows and the pieces inside a row), so a half-width card never clips the value. The value is the
|
|
30
|
+
* proportional sans with lining figures (Wave 35); the unit and period are muted. Weight and tracking
|
|
31
|
+
* are StatCard's hero values (`stat-card.module.css` `.value`: 500 / -0.02em, which no token names).
|
|
32
|
+
*/
|
|
33
|
+
.facts {
|
|
34
|
+
margin-top: var(--vx-space-stack-xs);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.factsRow {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-wrap: wrap;
|
|
40
|
+
align-items: baseline;
|
|
41
|
+
gap: var(--vx-space-stack-xs) var(--vx-space-stack-md);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.fact {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
align-items: baseline;
|
|
48
|
+
gap: var(--vx-space-stack-xs);
|
|
49
|
+
min-width: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.factValue {
|
|
53
|
+
min-width: 0;
|
|
54
|
+
overflow-wrap: anywhere;
|
|
55
|
+
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
56
|
+
font-size: var(--vx-text-kpi);
|
|
57
|
+
font-weight: 500;
|
|
58
|
+
font-variant-numeric: lining-nums;
|
|
59
|
+
letter-spacing: -0.02em;
|
|
60
|
+
color: var(--vx-ink);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.factUnit,
|
|
64
|
+
.factPeriod,
|
|
65
|
+
.factsBasis {
|
|
66
|
+
font-size: var(--vx-text-sm);
|
|
67
|
+
color: var(--vx-muted);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.factsBasis {
|
|
71
|
+
margin: var(--vx-space-stack-xs) 0 0;
|
|
72
|
+
}
|
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
declare const classes: {
|
|
6
6
|
readonly header: string
|
|
7
|
+
readonly facts: string
|
|
8
|
+
readonly factsRow: string
|
|
9
|
+
readonly factsBasis: string
|
|
10
|
+
readonly fact: string
|
|
11
|
+
readonly factValue: string
|
|
12
|
+
readonly factUnit: string
|
|
13
|
+
readonly factPeriod: string
|
|
7
14
|
}
|
|
8
15
|
export default classes
|
package/src/charts/compile.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { dateTickFormat, monthName, pad2, utcAxisDate } from './date-tick-format
|
|
|
9
9
|
import { crosshair } from '@tanstack/charts/crosshair'
|
|
10
10
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
11
11
|
import { rect } from '@tanstack/charts/rect'
|
|
12
|
+
import { text } from '@tanstack/charts/text'
|
|
12
13
|
import { ruleX, ruleY } from '@tanstack/charts/rule'
|
|
13
14
|
import { scaleLinear } from '@tanstack/charts/scales/linear'
|
|
14
15
|
import { scaleUtc } from 'd3-scale'
|
|
@@ -92,13 +93,16 @@ export type CartesianInput<T, X extends ChartX> = Pick<
|
|
|
92
93
|
plot?: PlotSizes | null
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
/**
|
|
96
|
+
/** The one tick-label size, at every container width: the caption size, so a card never mixes sizes. */
|
|
97
|
+
const TICK_FONT = VX.text.micro
|
|
98
|
+
|
|
99
|
+
/** Tick counts per container class (§ 9.6). */
|
|
96
100
|
const LADDER = {
|
|
97
|
-
micro: {
|
|
98
|
-
compact: {
|
|
99
|
-
regular: {
|
|
100
|
-
wide: {
|
|
101
|
-
} as const satisfies Record<ContainerClass, {
|
|
101
|
+
micro: { xTicks: 2, yTicks: 0 },
|
|
102
|
+
compact: { xTicks: 3, yTicks: 3 },
|
|
103
|
+
regular: { xTicks: 5, yTicks: 5 },
|
|
104
|
+
wide: { xTicks: 6, yTicks: 5 },
|
|
105
|
+
} as const satisfies Record<ContainerClass, { xTicks: number; yTicks: number }>
|
|
102
106
|
|
|
103
107
|
/** Space between the plot's left edge and a compact y label drawn inside it. */
|
|
104
108
|
const INSIDE_LABEL_DX = 4
|
|
@@ -269,7 +273,7 @@ export function yGuide<T>(opts: {
|
|
|
269
273
|
line: false,
|
|
270
274
|
ticks: { ...ticks, format: axis.format, line: false, ...(inside && { size: 0, padding: 0 }) },
|
|
271
275
|
tickLabels: {
|
|
272
|
-
fontSize:
|
|
276
|
+
fontSize: TICK_FONT,
|
|
273
277
|
opacity: 1,
|
|
274
278
|
...(inside && {
|
|
275
279
|
anchor: side === 'left' ? ('start' as const) : ('end' as const),
|
|
@@ -355,7 +359,7 @@ export function xGuide<X extends ChartX>(opts: {
|
|
|
355
359
|
line: AXIS_LINE,
|
|
356
360
|
ticks: { ...ticks, format, line: false, size: 0 },
|
|
357
361
|
tickLabels: {
|
|
358
|
-
fontSize:
|
|
362
|
+
fontSize: TICK_FONT,
|
|
359
363
|
opacity: 1,
|
|
360
364
|
thin: true,
|
|
361
365
|
// A label centred on a tick near the plot's left edge hangs left of it, under the gutter's
|
|
@@ -682,6 +686,34 @@ function underlayMarks<T, X extends ChartX>(
|
|
|
682
686
|
return [...zones, ...xZones]
|
|
683
687
|
}
|
|
684
688
|
|
|
689
|
+
/** A ref label within this share of the plot height of the top flips below its line. */
|
|
690
|
+
const REF_LABEL_TOP_SHARE = 0.12
|
|
691
|
+
const REF_LABEL_DX = 6
|
|
692
|
+
const REF_LABEL_DY_ABOVE = -5
|
|
693
|
+
const REF_LABEL_DY_BELOW = 11
|
|
694
|
+
|
|
695
|
+
/** The caption naming a reference line, at the plot end clear of its own axis' tick labels. */
|
|
696
|
+
const refLabelMark = <T>(r: RefLine, i: number, axes: Axes<T>): ChartMarks[number] => {
|
|
697
|
+
const [lo, hi] = axes.axisOf(r.axis).domain
|
|
698
|
+
const nearTop = hi !== lo && (r.value - lo) / (hi - lo) > 1 - REF_LABEL_TOP_SHARE
|
|
699
|
+
const atStart = r.axis === 'right' && axes.scaleId(r.axis) === 'y2'
|
|
700
|
+
return decorative(
|
|
701
|
+
text([{ f: atStart ? 0 : 1 }], {
|
|
702
|
+
id: `ref-${i}-label`,
|
|
703
|
+
x: (d: { f: number }) => d.f,
|
|
704
|
+
y: () => r.value,
|
|
705
|
+
xScale: 'zx',
|
|
706
|
+
yScale: axes.scaleId(r.axis),
|
|
707
|
+
text: () => r.label ?? '',
|
|
708
|
+
fill: VX.ink2,
|
|
709
|
+
fontSize: VX.text.micro,
|
|
710
|
+
anchor: atStart ? 'start' : 'end',
|
|
711
|
+
dx: atStart ? REF_LABEL_DX : -REF_LABEL_DX,
|
|
712
|
+
dy: nearTop ? REF_LABEL_DY_BELOW : REF_LABEL_DY_ABOVE,
|
|
713
|
+
}),
|
|
714
|
+
)
|
|
715
|
+
}
|
|
716
|
+
|
|
685
717
|
/** Reference lines, over the marks. */
|
|
686
718
|
const refLineMarks = <T, X extends ChartX>(
|
|
687
719
|
input: CartesianInput<T, X>,
|
|
@@ -700,6 +732,7 @@ const refLineMarks = <T, X extends ChartX>(
|
|
|
700
732
|
yScale: axes.scaleId(r.axis),
|
|
701
733
|
...(r.dashed && { strokeDasharray: DASH }),
|
|
702
734
|
}),
|
|
735
|
+
...(r.label ? [refLabelMark(r, i, axes)] : []),
|
|
703
736
|
],
|
|
704
737
|
)
|
|
705
738
|
|
|
@@ -921,7 +954,7 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
921
954
|
formatX,
|
|
922
955
|
cls,
|
|
923
956
|
height,
|
|
924
|
-
zoneScale: under.length > 0,
|
|
957
|
+
zoneScale: under.length > 0 || (input.refLines ?? []).some((r) => r.label),
|
|
925
958
|
}),
|
|
926
959
|
theme: CHART_THEME,
|
|
927
960
|
...(gradients.length > 0 && { gradients }),
|
package/src/charts/host.tsx
CHANGED
|
@@ -35,13 +35,16 @@ export type ChartEngineProps = {
|
|
|
35
35
|
/** The engine props of a basalt definition (`CartesianDefinition`'s datum and value types). */
|
|
36
36
|
type EngineProps = ChartProps<unknown, ChartValue, number>
|
|
37
37
|
|
|
38
|
-
/** `currentColor` is the axis ink. The font is
|
|
39
|
-
*
|
|
38
|
+
/** `currentColor` is the axis ink. The font is the proportional sans with tabular figures (Wave 35
|
|
39
|
+
* law: tabular in axis ticks, mono only for captions, times and code); `--basalt-chart-font` retunes
|
|
40
|
+
* the face from outside. It is inherited by the svg —
|
|
41
|
+
* TanStack measures guides with the host's computed font. */
|
|
40
42
|
const HOST_STYLE: CSSProperties = {
|
|
41
43
|
// Overrides the host's own fallback height: the box decides, the engine measures it.
|
|
42
44
|
height: '100%',
|
|
43
45
|
color: 'var(--vx-axis)',
|
|
44
|
-
fontFamily: 'var(--basalt-font-
|
|
46
|
+
fontFamily: 'var(--basalt-chart-font, var(--basalt-font-sans))',
|
|
47
|
+
fontVariantNumeric: 'tabular-nums',
|
|
45
48
|
}
|
|
46
49
|
const COARSE_STYLE: CSSProperties = { ...HOST_STYLE, touchAction: 'pan-y' }
|
|
47
50
|
|
package/src/charts/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ export {
|
|
|
27
27
|
type MirroredBarsSeries,
|
|
28
28
|
type MirroredBarPane,
|
|
29
29
|
} from './MirroredBars'
|
|
30
|
-
export { ChartCard, type ChartCardProps, type ChartCardSlot } from './ChartCard'
|
|
30
|
+
export { ChartCard, type ChartCardProps, type ChartCardSlot, type ChartFact } from './ChartCard'
|
|
31
31
|
export { chartCursor } from './cursor'
|
|
32
32
|
export { chartCurve, type CurveName } from './curves'
|
|
33
33
|
export type {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip, so a narrow cell
|
|
3
|
+
* cannot be escaped. It sits OUTSIDE the plot box, on the line just above it, so it can never cover
|
|
4
|
+
* a mark: the plot is the whole box, and a chip inside it would have to hide some series (a line's
|
|
5
|
+
* last segment, a bar, the end dot) wherever it landed. Above is always free inside a card or strip
|
|
6
|
+
* cell (the hero value or caption is what sits there), and the chip is opaque so it reads over it.
|
|
7
|
+
* It takes the side away from the hovered point.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
.root {
|
|
11
|
+
position: relative;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.readout {
|
|
15
|
+
position: absolute;
|
|
16
|
+
bottom: 100%;
|
|
17
|
+
z-index: 1;
|
|
18
|
+
max-width: 100%;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
padding: 0 4px;
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
23
|
+
font-variant-numeric: lining-nums;
|
|
24
|
+
font-size: var(--vx-text-xs);
|
|
25
|
+
/* The line a host slot reserves above the plot: it sets `--basalt-spark-readout-h` to the same
|
|
26
|
+
* value (`stat-card.module.css`, `stat-strip.module.css`), so the chip lands in reserved space. */
|
|
27
|
+
block-size: var(--basalt-spark-readout-h, 1.125rem);
|
|
28
|
+
line-height: calc(var(--basalt-spark-readout-h, 1.125rem) - 2px);
|
|
29
|
+
color: var(--vx-tooltip-text);
|
|
30
|
+
text-overflow: ellipsis;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
background: var(--vx-tooltip-bg);
|
|
34
|
+
border: 1px solid var(--vx-tooltip-border);
|
|
35
|
+
border-radius: var(--vx-radius-ctrl);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.start {
|
|
39
|
+
left: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.end {
|
|
43
|
+
right: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.label {
|
|
47
|
+
font-family: var(--basalt-font-mono);
|
|
48
|
+
opacity: 0.7;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.dot {
|
|
52
|
+
position: absolute;
|
|
53
|
+
width: 6px;
|
|
54
|
+
height: 6px;
|
|
55
|
+
pointer-events: none;
|
|
56
|
+
background: var(--vx-ink);
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
transform: translate(-50%, -50%);
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
|
|
3
|
+
* signature — so dot access stays verbatim under the package's strict flags.
|
|
4
|
+
*/
|
|
5
|
+
declare const classes: {
|
|
6
|
+
readonly root: string
|
|
7
|
+
readonly readout: string
|
|
8
|
+
readonly start: string
|
|
9
|
+
readonly end: string
|
|
10
|
+
readonly label: string
|
|
11
|
+
readonly dot: string
|
|
12
|
+
}
|
|
13
|
+
export default classes
|