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.
Files changed (254) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/MIGRATING.md +452 -12
  3. package/agent/agents/basalt-design-reviewer.md +1 -1
  4. package/agent/rules/basalt-tokens.md +1 -1
  5. package/agent/skills/basalt-design/SKILL.md +1 -1
  6. package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
  7. package/agent/skills/basalt-design/references/catalogue.md +1 -0
  8. package/dist/charts/BandStrip.d.ts.map +1 -1
  9. package/dist/charts/BandStrip.js +73 -3
  10. package/dist/charts/Bars.d.ts.map +1 -1
  11. package/dist/charts/Bars.js +6 -0
  12. package/dist/charts/CartesianChart.d.ts +10 -0
  13. package/dist/charts/CartesianChart.d.ts.map +1 -1
  14. package/dist/charts/CartesianChart.js +8 -5
  15. package/dist/charts/ChartCard.d.ts +12 -3
  16. package/dist/charts/ChartCard.d.ts.map +1 -1
  17. package/dist/charts/ChartCard.js +39 -8
  18. package/dist/charts/DualPanel.d.ts.map +1 -1
  19. package/dist/charts/DualPanel.js +5 -8
  20. package/dist/charts/Heatmap.d.ts +12 -1
  21. package/dist/charts/Heatmap.d.ts.map +1 -1
  22. package/dist/charts/Heatmap.js +34 -5
  23. package/dist/charts/Lines.d.ts +3 -0
  24. package/dist/charts/Lines.d.ts.map +1 -1
  25. package/dist/charts/Lines.js +29 -6
  26. package/dist/charts/MirroredBars.d.ts.map +1 -1
  27. package/dist/charts/MirroredBars.js +4 -6
  28. package/dist/charts/Sparkline.d.ts +14 -2
  29. package/dist/charts/Sparkline.d.ts.map +1 -1
  30. package/dist/charts/Sparkline.js +101 -22
  31. package/dist/charts/StackedArea.d.ts +4 -1
  32. package/dist/charts/StackedArea.d.ts.map +1 -1
  33. package/dist/charts/StackedArea.js +9 -3
  34. package/dist/charts/band-fold.d.ts +38 -1
  35. package/dist/charts/band-fold.d.ts.map +1 -1
  36. package/dist/charts/band-fold.js +18 -1
  37. package/dist/charts/chart-box.module.css +19 -0
  38. package/dist/charts/chart-card.module.css +25 -0
  39. package/dist/charts/chart-dates.d.ts +12 -0
  40. package/dist/charts/chart-dates.d.ts.map +1 -0
  41. package/dist/charts/chart-dates.js +16 -0
  42. package/dist/charts/chart-legend.module.css +7 -0
  43. package/dist/charts/compile.d.ts +25 -6
  44. package/dist/charts/compile.d.ts.map +1 -1
  45. package/dist/charts/compile.js +152 -72
  46. package/dist/charts/date-tick-format.d.ts +5 -5
  47. package/dist/charts/date-tick-format.d.ts.map +1 -1
  48. package/dist/charts/date-tick-format.js +3 -7
  49. package/dist/charts/labels.d.ts +21 -6
  50. package/dist/charts/labels.d.ts.map +1 -1
  51. package/dist/charts/labels.js +52 -17
  52. package/dist/charts/legend.d.ts +2 -0
  53. package/dist/charts/legend.d.ts.map +1 -1
  54. package/dist/charts/legend.js +7 -21
  55. package/dist/charts/marks.js +1 -1
  56. package/dist/charts/panel.d.ts +0 -6
  57. package/dist/charts/panel.d.ts.map +1 -1
  58. package/dist/charts/panel.js +1 -10
  59. package/dist/charts/ref-label.d.ts +43 -0
  60. package/dist/charts/ref-label.d.ts.map +1 -0
  61. package/dist/charts/ref-label.js +75 -0
  62. package/dist/charts/scales.d.ts +4 -1
  63. package/dist/charts/scales.d.ts.map +1 -1
  64. package/dist/charts/scales.js +14 -3
  65. package/dist/charts/sparkline.module.css +13 -17
  66. package/dist/charts/sparkline.module.css.d.ts +1 -2
  67. package/dist/charts/state.d.ts +2 -0
  68. package/dist/charts/state.d.ts.map +1 -1
  69. package/dist/charts/state.js +5 -2
  70. package/dist/charts/types.d.ts +18 -8
  71. package/dist/charts/types.d.ts.map +1 -1
  72. package/dist/cli/doctor-upgrade.d.ts +1 -0
  73. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  74. package/dist/cli/doctor-upgrade.js +1 -0
  75. package/dist/cli/init.d.ts +2 -0
  76. package/dist/cli/init.d.ts.map +1 -1
  77. package/dist/cli/init.js +68 -4
  78. package/dist/cli/shot/capture.d.ts +21 -2
  79. package/dist/cli/shot/capture.d.ts.map +1 -1
  80. package/dist/cli/shot/capture.js +202 -36
  81. package/dist/cli/shot/detect.d.ts.map +1 -1
  82. package/dist/cli/shot/detect.js +17 -1
  83. package/dist/cli/shot/playwright.d.ts +13 -2
  84. package/dist/cli/shot/playwright.d.ts.map +1 -1
  85. package/dist/cli/shot/playwright.js +5 -1
  86. package/dist/cli/shot/types.d.ts +4 -0
  87. package/dist/cli/shot/types.d.ts.map +1 -1
  88. package/dist/cli/shot/types.js +2 -0
  89. package/dist/cli/tokens-css.d.ts +5 -7
  90. package/dist/cli/tokens-css.d.ts.map +1 -1
  91. package/dist/cli/tokens-css.js +11 -12
  92. package/dist/controls/controls.module.css +11 -1
  93. package/dist/controls/filter-pill.d.ts.map +1 -1
  94. package/dist/controls/filter-pill.js +1 -0
  95. package/dist/controls/sync-button.d.ts.map +1 -1
  96. package/dist/controls/sync-button.js +22 -3
  97. package/dist/controls/sync-button.module.css +34 -2
  98. package/dist/controls/sync-button.module.css.d.ts +1 -0
  99. package/dist/dashboard/bar-list.d.ts +6 -1
  100. package/dist/dashboard/bar-list.d.ts.map +1 -1
  101. package/dist/dashboard/bar-list.js +15 -8
  102. package/dist/dashboard/bar-list.module.css +83 -0
  103. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  104. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  105. package/dist/dashboard/delta-badge.js +2 -2
  106. package/dist/dashboard/index.d.ts +1 -0
  107. package/dist/dashboard/index.d.ts.map +1 -1
  108. package/dist/dashboard/index.js +2 -0
  109. package/dist/dashboard/meter-model.d.ts +84 -5
  110. package/dist/dashboard/meter-model.d.ts.map +1 -1
  111. package/dist/dashboard/meter-model.js +100 -15
  112. package/dist/dashboard/meter-parts.d.ts +9 -1
  113. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  114. package/dist/dashboard/meter-parts.js +276 -74
  115. package/dist/dashboard/meter.d.ts +54 -65
  116. package/dist/dashboard/meter.d.ts.map +1 -1
  117. package/dist/dashboard/meter.js +21 -4
  118. package/dist/dashboard/meter.module.css +76 -0
  119. package/dist/dashboard/meter.module.css.d.ts +6 -0
  120. package/dist/dashboard/page-summary.d.ts +20 -0
  121. package/dist/dashboard/page-summary.d.ts.map +1 -0
  122. package/dist/dashboard/page-summary.js +28 -0
  123. package/dist/dashboard/page-summary.module.css +89 -0
  124. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  125. package/dist/dashboard/query-state.d.ts.map +1 -1
  126. package/dist/dashboard/query-state.js +1 -1
  127. package/dist/dashboard/section.d.ts +25 -2
  128. package/dist/dashboard/section.d.ts.map +1 -1
  129. package/dist/dashboard/section.js +10 -5
  130. package/dist/dashboard/section.module.css +23 -0
  131. package/dist/dashboard/section.module.css.d.ts +1 -0
  132. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  133. package/dist/dashboard/stat-card-parts.js +1 -1
  134. package/dist/dashboard/stat-card.d.ts +4 -2
  135. package/dist/dashboard/stat-card.d.ts.map +1 -1
  136. package/dist/dashboard/stat-card.js +7 -5
  137. package/dist/dashboard/stat-card.module.css +36 -0
  138. package/dist/dashboard/stat-group.module.css +7 -0
  139. package/dist/dashboard/stat-strip.d.ts +22 -6
  140. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  141. package/dist/dashboard/stat-strip.js +104 -60
  142. package/dist/dashboard/stat-strip.module.css +122 -53
  143. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  144. package/dist/dashboard/visual-slot.d.ts +7 -1
  145. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  146. package/dist/dashboard/visual-slot.js +3 -1
  147. package/dist/guard/index.d.ts.map +1 -1
  148. package/dist/guard/index.js +0 -5
  149. package/dist/guard/vx-names.d.ts.map +1 -1
  150. package/dist/guard/vx-names.js +2 -0
  151. package/dist/index.d.ts +1 -1
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +3 -1
  154. package/dist/styles.css +43 -4
  155. package/dist/theme/chrome-vars.d.ts +20 -5
  156. package/dist/theme/chrome-vars.d.ts.map +1 -1
  157. package/dist/theme/chrome-vars.js +46 -3
  158. package/dist/theme/controls.module.css +37 -0
  159. package/dist/theme/controls.module.css.d.ts +2 -0
  160. package/dist/theme/index.d.ts.map +1 -1
  161. package/dist/theme/index.js +18 -27
  162. package/dist/theme/status-verdict.d.ts.map +1 -1
  163. package/dist/theme/status-verdict.js +9 -1
  164. package/dist/tokens/core.d.ts +2 -1
  165. package/dist/tokens/core.d.ts.map +1 -1
  166. package/dist/tokens/core.js +6 -1
  167. package/dist/tokens/derive.d.ts +3 -1
  168. package/dist/tokens/derive.d.ts.map +1 -1
  169. package/dist/tokens/derive.js +16 -1
  170. package/dist/tokens/palette.d.ts +11 -10
  171. package/dist/tokens/palette.d.ts.map +1 -1
  172. package/dist/tokens/palette.js +11 -10
  173. package/dist/tokens/status-text.d.ts.map +1 -1
  174. package/dist/tokens/status-text.js +3 -1
  175. package/llms.txt +42 -22
  176. package/package.json +1 -1
  177. package/src/charts/BandStrip.tsx +83 -3
  178. package/src/charts/Bars.tsx +7 -0
  179. package/src/charts/CartesianChart.tsx +18 -3
  180. package/src/charts/ChartCard.tsx +54 -13
  181. package/src/charts/DualPanel.tsx +3 -6
  182. package/src/charts/Heatmap.tsx +54 -5
  183. package/src/charts/Lines.tsx +56 -10
  184. package/src/charts/MirroredBars.tsx +3 -5
  185. package/src/charts/Sparkline.tsx +135 -25
  186. package/src/charts/StackedArea.tsx +14 -4
  187. package/src/charts/band-fold.ts +50 -1
  188. package/src/charts/chart-box.module.css +19 -0
  189. package/src/charts/chart-card.module.css +25 -0
  190. package/src/charts/chart-dates.ts +30 -0
  191. package/src/charts/chart-legend.module.css +7 -0
  192. package/src/charts/compile.ts +253 -87
  193. package/src/charts/date-tick-format.ts +10 -13
  194. package/src/charts/labels.ts +81 -26
  195. package/src/charts/legend.tsx +10 -20
  196. package/src/charts/marks.ts +1 -1
  197. package/src/charts/panel.tsx +1 -16
  198. package/src/charts/ref-label.ts +131 -0
  199. package/src/charts/scales.ts +22 -2
  200. package/src/charts/sparkline.module.css +13 -17
  201. package/src/charts/sparkline.module.css.d.ts +1 -2
  202. package/src/charts/state.tsx +9 -4
  203. package/src/charts/types.ts +18 -8
  204. package/src/cli/doctor-upgrade.ts +1 -1
  205. package/src/cli/init.ts +100 -3
  206. package/src/cli/shot/capture.ts +266 -35
  207. package/src/cli/shot/detect.ts +18 -1
  208. package/src/cli/shot/playwright.ts +20 -4
  209. package/src/cli/shot/types.ts +5 -0
  210. package/src/cli/tokens-css.ts +18 -20
  211. package/src/controls/controls.module.css +11 -1
  212. package/src/controls/filter-pill.tsx +2 -0
  213. package/src/controls/sync-button.module.css +34 -2
  214. package/src/controls/sync-button.module.css.d.ts +1 -0
  215. package/src/controls/sync-button.tsx +40 -4
  216. package/src/dashboard/bar-list.module.css +83 -0
  217. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  218. package/src/dashboard/bar-list.tsx +107 -69
  219. package/src/dashboard/delta-badge.tsx +6 -2
  220. package/src/dashboard/index.ts +1 -0
  221. package/src/dashboard/meter-model.ts +207 -24
  222. package/src/dashboard/meter-parts.tsx +349 -67
  223. package/src/dashboard/meter.module.css +76 -0
  224. package/src/dashboard/meter.module.css.d.ts +6 -0
  225. package/src/dashboard/meter.tsx +72 -18
  226. package/src/dashboard/page-summary.module.css +89 -0
  227. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  228. package/src/dashboard/page-summary.tsx +95 -0
  229. package/src/dashboard/query-state.tsx +1 -1
  230. package/src/dashboard/section.module.css +23 -0
  231. package/src/dashboard/section.module.css.d.ts +1 -0
  232. package/src/dashboard/section.tsx +59 -11
  233. package/src/dashboard/stat-card-parts.tsx +5 -1
  234. package/src/dashboard/stat-card.module.css +36 -0
  235. package/src/dashboard/stat-card.tsx +12 -6
  236. package/src/dashboard/stat-group.module.css +7 -0
  237. package/src/dashboard/stat-strip.module.css +122 -53
  238. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  239. package/src/dashboard/stat-strip.tsx +176 -91
  240. package/src/dashboard/visual-slot.ts +12 -3
  241. package/src/guard/index.ts +0 -5
  242. package/src/guard/vx-names.ts +2 -0
  243. package/src/index.ts +2 -0
  244. package/src/styles.css +43 -4
  245. package/src/theme/__snapshots__/plain-theme.test.ts.snap +200 -68
  246. package/src/theme/chrome-vars.ts +77 -8
  247. package/src/theme/controls.module.css +37 -0
  248. package/src/theme/controls.module.css.d.ts +2 -0
  249. package/src/theme/index.ts +22 -32
  250. package/src/theme/status-verdict.tsx +5 -1
  251. package/src/tokens/core.ts +4 -1
  252. package/src/tokens/derive.ts +32 -3
  253. package/src/tokens/palette.ts +11 -10
  254. package/src/tokens/status-text.ts +2 -0
@@ -11,25 +11,31 @@ import { lineY } from '@tanstack/charts/line'
11
11
  import { ruleY } from '@tanstack/charts/rule'
12
12
  import { scaleBand } from '@tanstack/charts/scales/band'
13
13
  import { scaleLinear } from '@tanstack/charts/scales/linear'
14
+ import { text } from '@tanstack/charts/text'
14
15
  import { useId, useMemo, useState } from 'react'
15
- import type { FocusEvent, KeyboardEvent, PointerEvent, ReactElement } from 'react'
16
+ import type { CSSProperties, FocusEvent, KeyboardEvent, PointerEvent, ReactElement } from 'react'
16
17
  import { cx } from '../common/props'
17
18
  import type { BasaltProps } from '../common/props'
18
- import { VX } from '../tokens'
19
+ import { VX, alpha } from '../tokens'
19
20
  import type { CartesianDefinition } from './compile'
20
21
  import { chartCurve } from './curves'
21
22
  import { barMark } from './marks'
22
- import { defaultNumberFormat } from './compile'
23
+ import { bucketDay, dayGranular, defaultNumberFormat } from './compile'
24
+ import { referenceLabelPlacement } from './ref-label'
25
+ import { readoutClock, readoutDay } from './chart-dates'
26
+ import { toDate } from '../format/shared'
23
27
  import { ChartEngine, idPrefixOf } from './host'
24
28
  import classes from './sparkline.module.css'
25
29
  import { ChartPlaceholder, resolveChartState } from './state'
26
30
  import { CHART_THEME, DASH } from './theme'
27
- import type { ChartState } from './types'
31
+ import type { ChartMarks, ChartState } from './types'
28
32
 
29
33
  export type SparklineProps = BasaltProps & {
30
34
  /** The accessible name. Required: a chart without one is an unlabeled image. */
31
35
  ariaLabel: string
32
- data: readonly number[]
36
+ /** The values, or `{ at, value }` points: `at` (a Date, epoch ms or ISO string) names the point in
37
+ * the readout, as a day or, within one day, an hour, in the page's format locale. */
38
+ data: readonly number[] | readonly { at: Date | number | string; value: number }[]
33
39
  /** Height in px. */
34
40
  height: number
35
41
  /** Width in px. Default: the container's, measured by the host. */
@@ -38,6 +44,8 @@ export type SparklineProps = BasaltProps & {
38
44
  mark?: 'line' | 'bar' | undefined
39
45
  /** A `VX.*` ref or a series token. Default `VX.faint`. */
40
46
  color?: string | undefined
47
+ /** `'muted'`: the quiet trend line (a muted ink at low alpha). An explicit `color` wins. */
48
+ tone?: 'muted' | undefined
41
49
  /** Paints the last point in `emphasisColor` — the one reading a trend beside a KPI is for.
42
50
  * Default `true`; pass `false` for a bare line. */
43
51
  emphasizeLast?: boolean | undefined
@@ -50,9 +58,14 @@ export type SparklineProps = BasaltProps & {
50
58
  /** A quiet dashed hairline at a value, or at the mean of the plotted values (`'mean'`). The y
51
59
  * domain widens to include it. Not a legend item, never a status colour. */
52
60
  reference?: number | 'mean' | undefined
61
+ /** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot start just
62
+ * above the line. */
63
+ referenceLabel?: string | undefined
53
64
  /** Formats the readout's value. Default: the compact number format. */
54
65
  format?: ((value: number) => string) | undefined
55
- /** The readout's x label per point, index-aligned with `data`. Omitted: the value alone. */
66
+ /** The readout's x label per point, index-aligned with `data`: pass the point's day ("12 Oct"),
67
+ * and the readout reads `3 items · 12 Oct` beside the point. Omitted: the moment of an `{ at }`
68
+ * point, else the value alone. */
56
69
  labels?: readonly string[] | undefined
57
70
  }
58
71
 
@@ -61,14 +74,52 @@ type Point = { i: number; v: number | null }
61
74
  const LINE_WIDTH = 1.5
62
75
  const DOT_R = 2.5
63
76
  const BAR_GAP = 0.15
77
+ /** Air between the hovered point and the readout chip beside it, px. */
78
+ const READOUT_GAP = 8
79
+ /** Air round a line's plot, px (the engine's plot margin): the end marker stays inside the svg box,
80
+ * so it clears the 2px focus outline round it. A bar plot is flush. */
81
+ const LINE_INSET = 3
82
+ /** The muted tone's line: the same alpha the consumers hand-built (`alpha(VX.muted, .35)`). */
83
+ const MUTED_LINE = alpha(VX.muted, 0.35)
84
+ /** Air between the plot's start and the reference label, so the focus outline never covers it. */
85
+ const REFERENCE_LABEL_DX = 3
64
86
  // Pixel policy of the self-pooling (`poolSparkline`): the densest a series may draw.
65
87
  const LINE_PX_PER_POINT = 1
66
88
  const BAR_PX_PER_BAR = 2
67
89
  /** First, last and one min/max pair: the fewest points a pooled line can hold. */
68
90
  const LINE_POOL_MIN = 4
69
91
 
92
+ const DAY_MS = 86_400_000
93
+
70
94
  const finite = (v: number): number | null => (Number.isFinite(v) ? v : null)
71
95
 
96
+ /** The readout's moment per point of `{ at }` data: the day when the points are a day or more apart,
97
+ * else the hour (with the day once they span several). `undefined` for plain values. */
98
+ function momentsOf(data: SparklineProps['data']): readonly (string | undefined)[] | undefined {
99
+ const dates: (Date | null)[] = []
100
+ for (const d of data) {
101
+ if (typeof d !== 'object' || d === null) return undefined
102
+ dates.push(toDate(d.at))
103
+ }
104
+ const known = dates.filter((d): d is Date => d !== null)
105
+ if (known.length === 0) return undefined
106
+ // By loop: a spread overflows the stack on a long series.
107
+ let lo = Number.POSITIVE_INFINITY
108
+ let hi = Number.NEGATIVE_INFINITY
109
+ for (const d of known) {
110
+ const day = Math.floor(d.getTime() / DAY_MS)
111
+ if (day < lo) lo = day
112
+ if (day > hi) hi = day
113
+ }
114
+ const oneDay = lo === hi
115
+ const byDay = dayGranular(known)
116
+ return dates.map((d) => {
117
+ if (d === null) return undefined
118
+ if (byDay) return readoutDay(bucketDay(d))
119
+ return oneDay ? readoutClock(d) : `${readoutDay(d)} ${readoutClock(d)}`
120
+ })
121
+ }
122
+
72
123
  /** Min and max of the finite values, by loop (a spread overflows the stack on long series). */
73
124
  function extent(rows: readonly Point[]): readonly [number, number] | null {
74
125
  let lo = Number.POSITIVE_INFINITY
@@ -201,9 +252,10 @@ function compileSparkline(
201
252
  color: string,
202
253
  emphasisColor: string | null,
203
254
  reference: number | null,
255
+ referenceLabel: string | undefined,
204
256
  ): CartesianDefinition {
205
257
  const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null)
206
- const referenceMark = (): readonly ReturnType<typeof ruleY>[] =>
258
+ const referenceMark = (height: number): ChartMarks =>
207
259
  reference === null
208
260
  ? []
209
261
  : [
@@ -214,15 +266,41 @@ function compileSparkline(
214
266
  strokeWidth: 1,
215
267
  strokeDasharray: DASH,
216
268
  }),
269
+ ...(referenceLabel === undefined
270
+ ? []
271
+ : [
272
+ decorative(
273
+ text([reference], {
274
+ id: 'reference-label',
275
+ x: () => (mark === 'bar' ? 0 : frame.x[0]),
276
+ y: (v: number) => v,
277
+ text: () => referenceLabel,
278
+ fill: VX.ink2,
279
+ fontSize: VX.text.micro,
280
+ anchor: 'start',
281
+ dx: REFERENCE_LABEL_DX,
282
+ dy: referenceLabelPlacement({
283
+ value: reference,
284
+ domain: frame.y,
285
+ height,
286
+ inset: mark === 'bar' ? 0 : LINE_INSET,
287
+ fontSize: VX.text.micro,
288
+ }).dy,
289
+ }),
290
+ ),
291
+ ]),
217
292
  ]
218
293
  return {
219
- chart: ({ width }) => {
294
+ // A bar's hover is the bar and the readout chip: no engine point marker (bar chrome only, as
295
+ // `Bars`).
296
+ ...(mark === 'bar' && { focusRing: false as const }),
297
+ chart: ({ width, height }) => {
220
298
  const rows = poolSparkline(source, width, mark)
221
299
  const last = rows.at(-1)
222
300
  if (mark === 'bar') {
223
301
  return {
224
302
  marks: [
225
- ...referenceMark(),
303
+ ...referenceMark(height),
226
304
  barMark(rows, {
227
305
  id: 'bars',
228
306
  x: 'i',
@@ -250,7 +328,7 @@ function compileSparkline(
250
328
  }
251
329
  return {
252
330
  marks: [
253
- ...referenceMark(),
331
+ ...referenceMark(height),
254
332
  lineY(rows, {
255
333
  id: 'line',
256
334
  x: 'i',
@@ -276,7 +354,7 @@ function compileSparkline(
276
354
  },
277
355
  theme: CHART_THEME,
278
356
  guides: false,
279
- margin: 0,
357
+ margin: LINE_INSET,
280
358
  }
281
359
  },
282
360
  }
@@ -315,11 +393,13 @@ export function Sparkline(props: SparklineProps): ReactElement {
315
393
  height,
316
394
  width,
317
395
  mark = 'line',
318
- color = VX.faint,
396
+ tone,
397
+ color = tone === 'muted' ? MUTED_LINE : VX.faint,
319
398
  emphasizeLast = true,
320
399
  emphasisColor = VX.line,
321
400
  state,
322
401
  reference,
402
+ referenceLabel,
323
403
  format = defaultNumberFormat,
324
404
  labels,
325
405
  className,
@@ -331,7 +411,10 @@ export function Sparkline(props: SparklineProps): ReactElement {
331
411
  const [keyed, setKeyed] = useState<number | null>(null)
332
412
  const active = hover ?? keyed
333
413
  const model = useMemo(() => {
334
- const rows: Point[] = data.map((v, i) => ({ i, v: finite(v) }))
414
+ const rows: Point[] = data.map((d, i) => ({
415
+ i,
416
+ v: finite(typeof d === 'object' && d !== null ? d.value : d),
417
+ }))
335
418
  const range = extent(rows)
336
419
  // No finite value means nothing to scale: the empty render, never an Infinity domain.
337
420
  if (range === null) return null
@@ -343,10 +426,11 @@ export function Sparkline(props: SparklineProps): ReactElement {
343
426
  const end = emphasizeLast ? emphasisColor : null
344
427
  return {
345
428
  rows,
429
+ moments: momentsOf(data),
346
430
  frame: frameOf(full, mark, rows.length, end !== null),
347
- definition: compileSparkline(rows, full, mark, color, end, ref),
431
+ definition: compileSparkline(rows, full, mark, color, end, ref, referenceLabel),
348
432
  }
349
- }, [data, mark, color, emphasizeLast, emphasisColor, reference])
433
+ }, [data, mark, color, emphasizeLast, emphasisColor, reference, referenceLabel])
350
434
  const resolved = resolveChartState(state)
351
435
  const rows = model?.rows
352
436
  const interactive = resolved === null && model !== null
@@ -389,6 +473,8 @@ export function Sparkline(props: SparklineProps): ReactElement {
389
473
  setKeyed(lastFinite(rows))
390
474
  }
391
475
 
476
+ const inset = mark === 'line' ? LINE_INSET : 0
477
+ const layerStyle: CSSProperties = { inset }
392
478
  const value = active === null ? null : (rows?.[active]?.v ?? null)
393
479
  const at =
394
480
  interactive && active !== null && value !== null
@@ -399,9 +485,27 @@ export function Sparkline(props: SparklineProps): ReactElement {
399
485
  ? (active + 0.5) / model.rows.length
400
486
  : (active - model.frame.x[0]) / (model.frame.x[1] - model.frame.x[0]),
401
487
  fy: (model.frame.y[1] - value) / (model.frame.y[1] - model.frame.y[0]),
402
- label: labels?.[active],
488
+ label: labels?.[active] ?? model.moments?.[active],
403
489
  }
404
490
  : null
491
+ // Beside the point, on the roomier side, and on the half of the box away from it: the chip never
492
+ // covers the dot or the host's text, and stays inside the box whatever clips above it.
493
+ const beside = at === null ? null : at.fx > 0.5 ? 'left' : 'right'
494
+ const readoutStyle: CSSProperties | undefined =
495
+ at === null
496
+ ? undefined
497
+ : {
498
+ ...(beside === 'right'
499
+ ? {
500
+ left: `calc(${at.fx * 100}% + ${READOUT_GAP}px)`,
501
+ maxWidth: `calc(${(1 - at.fx) * 100}% - ${READOUT_GAP}px)`,
502
+ }
503
+ : {
504
+ right: `calc(${(1 - at.fx) * 100}% + ${READOUT_GAP}px)`,
505
+ maxWidth: `calc(${at.fx * 100}% - ${READOUT_GAP}px)`,
506
+ }),
507
+ ...(at.fy > 0.5 ? { top: 0 } : { bottom: 0 }),
508
+ }
405
509
  return (
406
510
  <div
407
511
  data-basalt-sparkline=""
@@ -428,21 +532,27 @@ export function Sparkline(props: SparklineProps): ReactElement {
428
532
  />
429
533
  )}
430
534
  {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
- />
535
+ // One layer on the plot rect (inside a line's margin): the dot and the readout take their
536
+ // fractions of the same box, so both land where the mark did. A bar has no dot: the bar
537
+ // is the marker.
538
+ <span aria-hidden="true" className={classes.layer} style={layerStyle}>
539
+ {mark === 'line' && (
540
+ <span
541
+ data-basalt-sparkline-dot=""
542
+ className={classes.dot}
543
+ style={{ left: `${at.fx * 100}%`, top: `${at.fy * 100}%` }}
544
+ />
545
+ )}
437
546
  <output
438
547
  data-basalt-sparkline-readout=""
439
548
  aria-live={hover === null ? 'polite' : 'off'}
440
- className={cx(classes.readout, at.fx > 0.5 ? classes.start : classes.end)}
549
+ className={classes.readout}
550
+ style={readoutStyle}
441
551
  >
442
- {at.label !== undefined && <span className={classes.label}>{at.label} </span>}
443
552
  {format(at.value)}
553
+ {at.label !== undefined && <span className={classes.label}> · {at.label}</span>}
444
554
  </output>
445
- </>
555
+ </span>
446
556
  )}
447
557
  </div>
448
558
  )
@@ -24,7 +24,7 @@ export type StackedAreaBand<T> = Pick<
24
24
  ChartSeries<T>,
25
25
  'key' | 'label' | 'color' | 'getValue' | 'formatValue' | 'tooltip' | 'legend' | 'role' | 'note'
26
26
  > & {
27
- /** Default 0.85. */
27
+ /** Default: the chart's `fillOpacity` (0.85). */
28
28
  fillOpacity?: number | undefined
29
29
  }
30
30
 
@@ -34,6 +34,9 @@ export type StackedAreaProps<T, X extends ChartX = ChartX> = Omit<
34
34
  > & {
35
35
  /** The bands, bottom to top. */
36
36
  series: readonly StackedAreaBand<T>[]
37
+ /** Every band's fill opacity, 0–1 (default 0.85: full-opacity bands read saturated). A band's own
38
+ * `fillOpacity` wins. The legend swatch wears the same shade. */
39
+ fillOpacity?: number | undefined
37
40
  /** No `scale`: a log axis has no additive zero to stack from. */
38
41
  y?: Omit<NonNullable<CartesianChartProps<T, X>['y']>, 'scale'> | undefined
39
42
  }
@@ -41,11 +44,18 @@ export type StackedAreaProps<T, X extends ChartX = ChartX> = Omit<
41
44
  export function StackedArea<T, X extends ChartX = ChartX>(
42
45
  props: StackedAreaProps<T, X>,
43
46
  ): ReactElement {
44
- const { series: bands, ...rest } = props
47
+ const { series: bands, fillOpacity, ...rest } = props
45
48
  // `mark: 'bar'` is what the rung sums for the auto domain, and the legend/tooltip swatch.
46
49
  const series = useMemo<ChartSeries<T>[]>(
47
- () => bands.map((s) => ({ ...s, mark: 'bar' as const })),
48
- [bands],
50
+ () =>
51
+ bands.map((s) => ({
52
+ ...s,
53
+ mark: 'bar' as const,
54
+ ...((s.fillOpacity ?? fillOpacity) !== undefined && {
55
+ fillOpacity: s.fillOpacity ?? fillOpacity,
56
+ }),
57
+ })),
58
+ [bands, fillOpacity],
49
59
  )
50
60
 
51
61
  const marks = useCallback((plot: PlotContext<T, X>): ChartMarks => {
@@ -1,4 +1,5 @@
1
1
  import { oneOf } from '../common/errors'
2
+ import { VX } from '../tokens'
2
3
  import type { ChartSeries } from './types'
3
4
 
4
5
  /**
@@ -9,7 +10,55 @@ import type { ChartSeries } from './types'
9
10
  export type NamedChartState = Pick<
10
11
  ChartSeries<never>,
11
12
  'key' | 'label' | 'color' | 'tooltip' | 'legend' | 'note' | 'fillOpacity'
12
- >
13
+ > & {
14
+ /**
15
+ * A short mark (`!`, `×`) drawn in the middle of each cell in this state, so a state is not told
16
+ * apart by hue alone; `''` opts out of the default. Default: `!` for a `warn` state and `×` for a
17
+ * `bad` one (by `tone`, or by a `color` that is `VX.status.warn` / `VX.status.bad`); none
18
+ * otherwise. Skipped on a cell too narrow to hold it.
19
+ */
20
+ glyph?: string | undefined
21
+ /** The status this state means. `Heatmap` also fills from it; on `BandStrip` it only picks the
22
+ * default `glyph` (the fill is `color`). */
23
+ tone?: StatusTone | undefined
24
+ }
25
+
26
+ /** The status inks a state can name: `VX.status.*`. */
27
+ export type StatusTone = 'good' | 'warn' | 'bad' | 'neutral'
28
+
29
+ /** `warn` and `bad` carry a glyph by default: a status state is not told apart by hue alone. */
30
+ const TONE_GLYPH: Partial<Record<StatusTone, string>> = { warn: '!', bad: '×' }
31
+
32
+ type ToneSource = Pick<NamedChartState, 'glyph' | 'tone'> & { color?: string | undefined }
33
+
34
+ /** A state's status tone: its own, else the one its status colour names. */
35
+ export function toneOf(s: ToneSource): StatusTone | undefined {
36
+ return (
37
+ s.tone ?? (s.color === VX.status.warn ? 'warn' : s.color === VX.status.bad ? 'bad' : undefined)
38
+ )
39
+ }
40
+
41
+ /** The glyph a state draws: its own, else its status tone's default, else none. */
42
+ export function glyphOf(s: ToneSource): string | undefined {
43
+ const tone = toneOf(s)
44
+ return s.glyph ?? (tone === undefined ? undefined : TONE_GLYPH[tone])
45
+ }
46
+
47
+ /** A heat cell narrower than this (px) draws no glyph: it would not fit inside the fill. */
48
+ export const GLYPH_MIN_PX = 12
49
+
50
+ /**
51
+ * A `BandStrip` cell narrower than this (px) draws no glyph: its fill is full-height, so the glyph
52
+ * is set at the xs size (a 16 px line), and a `!` or `×` is unreadable in less. Such a cell draws a
53
+ * notch instead, see {@link NOTCH_PX}. A `Heatmap` keeps {@link GLYPH_MIN_PX}.
54
+ */
55
+ export const BAND_GLYPH_MIN_PX = 16
56
+
57
+ /**
58
+ * The height (px) of the bottom notch a glyph state draws where the glyph does not fit: a warn
59
+ * notch is shorter than a bad one, so the state is never told by hue alone.
60
+ */
61
+ export const NOTCH_PX = { warn: 3, bad: 6 } as const
13
62
 
14
63
  /** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
15
64
  export type Group<T> = { start: number; items: T[] }
@@ -92,3 +92,22 @@
92
92
  height: auto;
93
93
  min-height: inherit;
94
94
  }
95
+
96
+ /*
97
+ * The engine paints its tooltip rows as a grid of `.55rem | minmax(0, 1fr) | auto` with inline
98
+ * styles and `overflow-wrap: anywhere` on the card, so a narrow tooltip (a 390 viewport, a pointer
99
+ * near an edge) squeezes the name column to one character per line. The name keeps a floor and
100
+ * never wraps; a long name ends in an ellipsis, the value stays right-aligned. The tooltip is
101
+ * portalled out of the chart's tree, hence the global class names. `!important` because the
102
+ * engine's own values are inline.
103
+ */
104
+ :global(.ts-chart-tooltip__row) {
105
+ grid-template-columns: 0.55rem minmax(6rem, max-content) auto !important;
106
+ }
107
+
108
+ :global(.ts-chart-tooltip__row > span:nth-child(2)) {
109
+ max-width: 14rem;
110
+ overflow: hidden;
111
+ text-overflow: ellipsis;
112
+ white-space: nowrap;
113
+ }
@@ -70,3 +70,28 @@
70
70
  .factsBasis {
71
71
  margin: var(--vx-space-stack-xs) 0 0;
72
72
  }
73
+
74
+ /*
75
+ * A fact's tone is INK only (the value and its trailing text), never a fill. The status solids are
76
+ * the text-safe ones (`status-text.ts`). `stale` is the strip cell's dimmed value, verbatim
77
+ * (`stat-strip.module.css` `.cell[data-stale]`).
78
+ */
79
+ .fact[data-tone='good'] :is(.factValue, .factUnit, .factPeriod) {
80
+ color: var(--vx-status-good);
81
+ }
82
+
83
+ .fact[data-tone='warn'] :is(.factValue, .factUnit, .factPeriod) {
84
+ color: var(--vx-status-warn);
85
+ }
86
+
87
+ .fact[data-tone='bad'] :is(.factValue, .factUnit, .factPeriod) {
88
+ color: var(--vx-status-bad);
89
+ }
90
+
91
+ .fact[data-tone='muted'] :is(.factValue, .factUnit, .factPeriod) {
92
+ color: var(--vx-muted);
93
+ }
94
+
95
+ .factsRow[data-stale] {
96
+ opacity: 0.55;
97
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The chart layer's one date locale: the axis's day labels, the tooltip header and a sparkline's
3
+ * readout all read the page's `defineFormat` / `BasaltProvider` locale through here (the runtime's
4
+ * when none is set), so no card mixes two orders: `04.10` ticks under a `Sat, Oct 10, 2026` header
5
+ * under a `3 Oct` fact. Every read is UTC, like the time scale that placed the ticks.
6
+ */
7
+ import { dateFormat } from '../format/shared'
8
+
9
+ const utcFormat = (options: Intl.DateTimeFormatOptions, d: Date): string =>
10
+ dateFormat(undefined, { ...options, timeZone: 'UTC' }).format(d)
11
+
12
+ /** An axis tick's day: `4 Oct` (the page locale's own order). */
13
+ export const axisDay = (d: Date): string => utcFormat({ day: 'numeric', month: 'short' }, d)
14
+
15
+ /** {@link axisDay} with a two-digit year. */
16
+ export const axisDayYear = (d: Date): string =>
17
+ utcFormat({ day: 'numeric', month: 'short', year: '2-digit' }, d)
18
+
19
+ export const monthName = (d: Date): string => utcFormat({ month: 'short' }, d)
20
+
21
+ /** The tooltip header's date: weekday, day, month and year. */
22
+ export const headerDay = (d: Date): string =>
23
+ utcFormat({ weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' }, d)
24
+
25
+ /** A day written out for a readout (`12 Oct`): the same format as an axis tick. */
26
+ export const readoutDay = axisDay
27
+
28
+ /** A clock time for a readout, `HH:MM` in the page locale's digits. */
29
+ export const readoutClock = (d: Date): string =>
30
+ utcFormat({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }, d)
@@ -36,3 +36,10 @@
36
36
  display: inline-flex;
37
37
  }
38
38
  }
39
+
40
+ /* Lines' `naming="auto"`: from the wide class the end labels name the lines, so the legend goes. */
41
+ @container (min-width: 800px) {
42
+ .auto[data-hide-wide] {
43
+ display: none;
44
+ }
45
+ }