basalt-ui 2.20.0 → 2.22.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 +72 -0
- package/MIGRATING.md +394 -12
- package/agent/agents/basalt-design-reviewer.md +22 -5
- package/agent/rules/basalt-tokens.md +3 -3
- 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 +49 -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/configs/oxlint-plugin.js +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +27 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +5 -0
- package/dist/charts/CartesianChart.d.ts +8 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +17 -4
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +33 -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 +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +39 -14
- 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 +20 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +9 -0
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +17 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +145 -74
- package/dist/charts/labels.d.ts +15 -4
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +34 -10
- 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 +26 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +63 -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 +10 -11
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +4 -1
- package/dist/charts/types.d.ts +14 -5
- 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/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/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 +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +71 -6
- 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 +200 -33
- 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 +409 -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/playwright.d.ts +5 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/types.d.ts +6 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +4 -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/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 +5 -2
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +9 -10
- package/dist/dashboard/bar-list.module.css +53 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- 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 +108 -6
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +123 -19
- package/dist/dashboard/meter-parts.d.ts +8 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +345 -146
- package/dist/dashboard/meter.d.ts +50 -63
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +24 -3
- package/dist/dashboard/meter.module.css +79 -65
- package/dist/dashboard/meter.module.css.d.ts +7 -7
- 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 +1 -1
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +3 -2
- 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 -4
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +24 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +97 -39
- package/dist/dashboard/stat-strip.module.css +147 -17
- package/dist/dashboard/stat-strip.module.css.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -0
- package/dist/dashboard/visual-slot.js +7 -0
- package/dist/guard/index.d.ts +15 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +14 -0
- 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/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 +34 -2
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- 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 +33 -0
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +11 -5
- 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/oklab.d.ts +28 -0
- package/dist/tokens/oklab.d.ts.map +1 -0
- package/dist/tokens/oklab.js +73 -0
- package/dist/tokens/palette.d.ts +4 -0
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +4 -0
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +43 -23
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +33 -3
- package/src/charts/Bars.tsx +6 -0
- package/src/charts/CartesianChart.tsx +16 -3
- package/src/charts/ChartCard.tsx +43 -7
- 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 +50 -13
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +31 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +210 -85
- package/src/charts/labels.ts +48 -14
- 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 +104 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +10 -11
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +12 -1
- package/src/charts/types.ts +14 -5
- package/src/cli/check-theme.ts +3 -0
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/help.ts +18 -1
- package/src/cli/index.ts +48 -17
- package/src/cli/init.ts +102 -4
- package/src/cli/shot/capture.ts +266 -34
- package/src/cli/shot/detect.ts +550 -0
- package/src/cli/shot/index.ts +8 -4
- package/src/cli/shot/measure.ts +4 -0
- package/src/cli/shot/playwright.ts +2 -2
- package/src/cli/shot/types.ts +8 -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/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 +53 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +88 -76
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +265 -28
- package/src/dashboard/meter-parts.tsx +424 -163
- package/src/dashboard/meter.module.css +79 -65
- package/src/dashboard/meter.module.css.d.ts +7 -7
- package/src/dashboard/meter.tsx +77 -17
- 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 +4 -7
- 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 +17 -0
- package/src/dashboard/stat-card.tsx +14 -5
- package/src/dashboard/stat-strip.module.css +147 -17
- package/src/dashboard/stat-strip.module.css.d.ts +8 -0
- package/src/dashboard/stat-strip.tsx +182 -56
- package/src/dashboard/visual-slot.ts +17 -0
- package/src/guard/index.ts +16 -4
- package/src/guard/palette.ts +261 -0
- package/src/guard/series-file.ts +51 -0
- package/src/guard/types.ts +3 -2
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +34 -2
- package/src/surfaces.ts +2 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +220 -60
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +33 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +18 -5
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/oklab.ts +97 -0
- package/src/tokens/palette.ts +4 -0
- package/src/tokens/status-text.ts +2 -0
package/src/charts/DualPanel.tsx
CHANGED
|
@@ -16,7 +16,7 @@ import { VX, alpha } from '../tokens'
|
|
|
16
16
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
17
17
|
import { defaultNumberFormat, engineRow, seriesRow, visibleSeries } from './compile'
|
|
18
18
|
import { barMark, emphasis, lineMark, markersOf, thinFill } from './marks'
|
|
19
|
-
import { PanelRung,
|
|
19
|
+
import { PanelRung, paneX, paneY, rowsOf } from './panel'
|
|
20
20
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
21
21
|
import { plotContext } from './plot-context'
|
|
22
22
|
import type { SignedSeries } from './legend'
|
|
@@ -283,15 +283,13 @@ export function DualPanel<T, X extends Date | number = Date | number>(
|
|
|
283
283
|
format: topFormat,
|
|
284
284
|
ticks: TOP_TICKS,
|
|
285
285
|
cls,
|
|
286
|
-
height: chartHeightOf(h, topFraction, PANE_GAP),
|
|
287
286
|
}),
|
|
288
287
|
},
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
290
|
|
|
292
|
-
const barPane: PaneBuilder = ({ width
|
|
291
|
+
const barPane: PaneBuilder = ({ width }) => {
|
|
293
292
|
const cls = resolveContainerClass(width)
|
|
294
|
-
const whole = chartHeightOf(h, 1 - topFraction, PANE_GAP)
|
|
295
293
|
const barRows = barOn ? rowsOf(data, x, barSeries) : []
|
|
296
294
|
const dim = emphasis(highlighted, { key: BAR_KEY })
|
|
297
295
|
return {
|
|
@@ -306,14 +304,13 @@ export function DualPanel<T, X extends Date | number = Date | number>(
|
|
|
306
304
|
}),
|
|
307
305
|
],
|
|
308
306
|
scales: {
|
|
309
|
-
x: paneX({ scale: xScale(), model, format, cls
|
|
307
|
+
x: paneX({ scale: xScale(), model, format, cls }),
|
|
310
308
|
y: paneY({
|
|
311
309
|
scale: barScale,
|
|
312
310
|
domain: barDomain,
|
|
313
311
|
format: bar.format,
|
|
314
312
|
ticks: BAR_TICKS,
|
|
315
313
|
cls,
|
|
316
|
-
height: whole,
|
|
317
314
|
}),
|
|
318
315
|
},
|
|
319
316
|
}
|
package/src/charts/Heatmap.tsx
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* There is no cursor and no crosshair — the tooltip is per cell, its rows are `tooltip.rows(d)` data.
|
|
9
9
|
*/
|
|
10
10
|
import { colorGradientLegend } from '@tanstack/charts/legend'
|
|
11
|
+
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
11
12
|
import { cell } from '@tanstack/charts/rect'
|
|
13
|
+
import { text } from '@tanstack/charts/text'
|
|
12
14
|
import { scaleBand } from '@tanstack/charts/scales/band'
|
|
13
15
|
import { portal } from '@tanstack/charts/tooltip/portal'
|
|
14
16
|
import type { ChartBuildContext, ChartPoint, StoredChartSpec } from '@tanstack/charts/types/core'
|
|
@@ -20,7 +22,7 @@ import { alpha, VX } from '../tokens'
|
|
|
20
22
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
21
23
|
import { engineRow, strideTicks } from './compile'
|
|
22
24
|
import type { CartesianDefinition } from './compile'
|
|
23
|
-
import { resolveNamedState } from './band-fold'
|
|
25
|
+
import { GLYPH_MIN_PX, glyphOf, resolveNamedState } from './band-fold'
|
|
24
26
|
import type { NamedChartState } from './band-fold'
|
|
25
27
|
import { ABSENT_OPACITY, RAMP_LEVELS, RAMP_OPACITIES } from './heatmap-fill'
|
|
26
28
|
import { engineTooltip } from './cursor'
|
|
@@ -37,11 +39,29 @@ import type { ChartSeries, ChartState, ChartTooltipRow, ResponsiveChartHeight }
|
|
|
37
39
|
* `fillOpacity` (default 1) are its flat fill, `label` its legend entry and tooltip reading, `note`
|
|
38
40
|
* a muted qualifier after the label in the legend, `legend: false` keeps it out of the legend.
|
|
39
41
|
* `tooltip` is omitted: a cell's tooltip always names its state, so there is no row to hide.
|
|
42
|
+
*
|
|
43
|
+
* A categorical STATUS grid (up / degraded / down) names a `tone` instead of a `color`:
|
|
44
|
+
*
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <Heatmap getState={(d) => d.status} getValue={() => null} …
|
|
47
|
+
* states={[{ key: 'up', label: 'Up', tone: 'good' }, { key: 'down', label: 'Down', tone: 'bad' }]} />
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* `warn` and `bad` draw `!` and `×` in the cell; `glyph` overrides them, `glyph: ''` opts out.
|
|
40
51
|
*/
|
|
41
|
-
export type HeatmapState<K extends string = string> = Omit<
|
|
52
|
+
export type HeatmapState<K extends string = string> = Omit<
|
|
53
|
+
NamedChartState,
|
|
54
|
+
'key' | 'tooltip' | 'color'
|
|
55
|
+
> & {
|
|
42
56
|
key: K
|
|
57
|
+
/** The flat fill, a `VX.*` ref. Needed unless `tone` is set; `color` wins over `tone`. */
|
|
58
|
+
color?: string | undefined
|
|
43
59
|
}
|
|
44
60
|
|
|
61
|
+
/** The fill a state resolves to: its `color`, else its tone's status colour, else neutral. */
|
|
62
|
+
const fillOf = (s: HeatmapState | undefined): string =>
|
|
63
|
+
s?.color ?? (s?.tone === undefined ? VX.neutral : VX.status[s.tone])
|
|
64
|
+
|
|
45
65
|
export type HeatmapProps<T, K extends string = string> = BasaltProps & {
|
|
46
66
|
/** The accessible name. Required. */
|
|
47
67
|
ariaLabel: string
|
|
@@ -137,7 +157,7 @@ function valueRows<K extends string>(
|
|
|
137
157
|
formatValue: (v: number) => string,
|
|
138
158
|
pointColor: string | undefined,
|
|
139
159
|
): ChartTooltipRow[] {
|
|
140
|
-
if (named) return [{ label, value: named.label, color: named
|
|
160
|
+
if (named) return [{ label, value: named.label, color: fillOf(named) }]
|
|
141
161
|
if (c.value === null) return [{ label, value: 'No data' }]
|
|
142
162
|
return [{ label, value: formatValue(c.value), ...(pointColor && { color: pointColor }) }]
|
|
143
163
|
}
|
|
@@ -241,6 +261,9 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
241
261
|
? {
|
|
242
262
|
use: engineTooltip,
|
|
243
263
|
portal,
|
|
264
|
+
// Below the hovered cell (flipping above only when there is no room): the default sits
|
|
265
|
+
// above it and covers the caption row over the grid.
|
|
266
|
+
placement: ['bottom', 'top'] as const,
|
|
244
267
|
content: (points: readonly ChartPoint[]) => {
|
|
245
268
|
const point = points[0]
|
|
246
269
|
const c = point?.datum as Cell<T, K> | undefined
|
|
@@ -265,6 +288,31 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
265
288
|
opacity: 1,
|
|
266
289
|
thin: true,
|
|
267
290
|
}
|
|
291
|
+
// A stated cell's glyph, centred in the cell; skipped when the cell is too narrow to hold it.
|
|
292
|
+
const glyphMarks = (plotWidth: number) => {
|
|
293
|
+
const drawn = [...stated].flatMap(([key, group]) => {
|
|
294
|
+
const named = stateByKey.get(key)
|
|
295
|
+
const glyph = named && glyphOf({ ...named, color: fillOf(named) })
|
|
296
|
+
return glyph ? group.map((c) => ({ ...c, glyph })) : []
|
|
297
|
+
})
|
|
298
|
+
return drawn.length > 0 && plotWidth / Math.max(cols.length, 1) >= GLYPH_MIN_PX
|
|
299
|
+
? [
|
|
300
|
+
decorative(
|
|
301
|
+
text(drawn, {
|
|
302
|
+
id: 'state-glyphs',
|
|
303
|
+
x: 'col',
|
|
304
|
+
y: 'row',
|
|
305
|
+
key: 'id',
|
|
306
|
+
text: 'glyph',
|
|
307
|
+
fill: VX.surface.panel,
|
|
308
|
+
fontSize: VX.text.xs,
|
|
309
|
+
fontWeight: 600,
|
|
310
|
+
anchor: 'middle',
|
|
311
|
+
}),
|
|
312
|
+
),
|
|
313
|
+
]
|
|
314
|
+
: []
|
|
315
|
+
}
|
|
268
316
|
const marks = [
|
|
269
317
|
// Inert, not decorative: it must still win the hit test, so a pointer over an empty
|
|
270
318
|
// position lands on THIS cell (whose tooltip is empty) instead of snapping to a neighbour.
|
|
@@ -273,11 +321,12 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
273
321
|
...[...stated].map(([key, group]) => {
|
|
274
322
|
const named = stateByKey.get(key)
|
|
275
323
|
return cellMark(`state:${key}`, group, {
|
|
276
|
-
fill: named
|
|
324
|
+
fill: fillOf(named),
|
|
277
325
|
...(named?.fillOpacity !== undefined && { fillOpacity: named.fillOpacity }),
|
|
278
326
|
})
|
|
279
327
|
}),
|
|
280
328
|
cellMark('cells', present, { color: 'value' }),
|
|
329
|
+
...glyphMarks(width),
|
|
281
330
|
]
|
|
282
331
|
return {
|
|
283
332
|
marks,
|
|
@@ -351,7 +400,7 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
351
400
|
: states.map((s) => ({
|
|
352
401
|
key: s.key,
|
|
353
402
|
label: s.label,
|
|
354
|
-
color: s
|
|
403
|
+
color: fillOf(s),
|
|
355
404
|
mark: 'bar' as const,
|
|
356
405
|
...(s.fillOpacity !== undefined && { fillOpacity: s.fillOpacity }),
|
|
357
406
|
...(s.legend !== undefined && { legend: s.legend }),
|
package/src/charts/Lines.tsx
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* `thresholds` (fills between the first series and a value, Date/number x only). Zones, x-zones,
|
|
5
5
|
* reference lines, `y2`, legend, cursor and tooltip are the rung's.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* `naming` is the one switch for who names the series. `auto` (default): from the wide class up, a
|
|
8
|
+
* chart of ≤ 3 lines and no `y2` names them with end labels and its legend goes; below it the
|
|
9
|
+
* legend names them. `legend`: the legend at every width, no end labels. `endLabels`: end labels at
|
|
10
|
+
* every width, no legend (a chart with a `y2` keeps its legend). A label that would not fit between
|
|
11
|
+
* its last point and the plot's right edge ends at the point instead, above it; labels that would
|
|
12
|
+
* collide are spread apart. Before the engine has measured the plot (the server HTML, the first
|
|
13
|
+
* client frame) the room is read off the frame, which is wider by the axis gutters; the measured
|
|
14
|
+
* render corrects it.
|
|
12
15
|
*/
|
|
13
16
|
import { areaY } from '@tanstack/charts/area'
|
|
14
17
|
import { differenceY } from '@tanstack/charts/difference'
|
|
@@ -19,11 +22,13 @@ import { CartesianRung } from './CartesianChart'
|
|
|
19
22
|
import { areaGradientId } from './compile'
|
|
20
23
|
import { chartCurve } from './curves'
|
|
21
24
|
import { endLabelMarks, endLabelPlan } from './labels'
|
|
25
|
+
import type { LinesNaming } from './labels'
|
|
22
26
|
import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from './marks'
|
|
23
27
|
import { rowX } from './types'
|
|
24
28
|
import type {
|
|
25
29
|
CartesianChartProps,
|
|
26
30
|
ChartMarks,
|
|
31
|
+
ChartSeries,
|
|
27
32
|
ChartX,
|
|
28
33
|
PlotContext,
|
|
29
34
|
PlotRow,
|
|
@@ -36,13 +41,47 @@ export type LinesProps<T, X extends ChartX = ChartX> = Omit<CartesianChartProps<
|
|
|
36
41
|
* x: the engine's `differenceY` takes a Date or number x only.
|
|
37
42
|
*/
|
|
38
43
|
thresholds?: [X] extends [string] ? never : readonly Threshold[]
|
|
44
|
+
/** Who names the series: `'auto'` (default; end labels from the wide class, the legend below it),
|
|
45
|
+
* `'legend'` or `'endLabels'`. */
|
|
46
|
+
naming?: 'auto' | 'legend' | 'endLabels' | undefined
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
const hasValue = <T, X extends ChartX>(r: PlotRow<T, X>): boolean => r.y !== null
|
|
42
50
|
|
|
51
|
+
/** Whether a series' last non-null point exists and sits inside the chart's x domain. */
|
|
52
|
+
function lastIsPlaceable<T, X extends ChartX>(
|
|
53
|
+
props: Pick<LinesProps<T, X>, 'data' | 'x' | 'xDomain'>,
|
|
54
|
+
s: ChartSeries<T>,
|
|
55
|
+
): boolean {
|
|
56
|
+
const last = props.data.findLast((d) => s.getValue(d) !== null)
|
|
57
|
+
if (last === undefined) return false
|
|
58
|
+
const { xDomain } = props
|
|
59
|
+
if (xDomain === undefined) return true
|
|
60
|
+
const at = +props.x(last) // a Date's timestamp, or the number itself
|
|
61
|
+
return Number.isNaN(at) || (at >= +xDomain[0] && at <= +xDomain[1])
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The most lines `auto` names with end labels (and so the most a legend gives way for). */
|
|
65
|
+
const AUTO_END_LABELS = 3
|
|
66
|
+
|
|
43
67
|
export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): ReactElement {
|
|
44
|
-
const { thresholds, ...rest } = props
|
|
68
|
+
const { thresholds, naming = 'auto', ...rest } = props
|
|
45
69
|
const { series } = props
|
|
70
|
+
// Whether end labels can name every legend entry: only then may the legend give way to them.
|
|
71
|
+
const labelled = series.filter((s) => s.role !== 'reference')
|
|
72
|
+
const namedByLabels =
|
|
73
|
+
props.y2 === undefined &&
|
|
74
|
+
series.every((s) => s.legend === false || s.role !== 'reference') &&
|
|
75
|
+
!(props.refLines ?? []).some((r) => r.legend !== undefined)
|
|
76
|
+
// When the legend must name something the labels cannot (a right axis, a named reference line),
|
|
77
|
+
// it stays and the labels are not drawn: one naming, never two.
|
|
78
|
+
const effective: LinesNaming = namedByLabels ? naming : 'legend'
|
|
79
|
+
// The legend gives way only to labels that WILL draw for every line: each labelled series needs a
|
|
80
|
+
// last value the plot can place (a narrower `xDomain` can clip it away).
|
|
81
|
+
const placeable = labelled.every((s) => lastIsPlaceable(props, s))
|
|
82
|
+
const labelsOnly = effective === 'endLabels'
|
|
83
|
+
const hideAtWide =
|
|
84
|
+
effective === 'auto' && placeable && labelled.length > 0 && labelled.length <= AUTO_END_LABELS
|
|
46
85
|
const marks = useCallback(
|
|
47
86
|
(plot: PlotContext<T, X>): ChartMarks => {
|
|
48
87
|
const indexOf = new Map(series.map((s, i) => [s.key, i]))
|
|
@@ -83,7 +122,7 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
|
|
|
83
122
|
y1: () => 0,
|
|
84
123
|
fill: `url(#${areaGradientId(indexOf.get(s.key) ?? 0)})`,
|
|
85
124
|
fillOpacity: 1,
|
|
86
|
-
curve: chartCurve(s.curve ?? '
|
|
125
|
+
curve: chartCurve(s.curve ?? 'linear'),
|
|
87
126
|
...(yScaleOf(plot, s) !== undefined && { yScale: 'y2' }),
|
|
88
127
|
}),
|
|
89
128
|
),
|
|
@@ -96,10 +135,17 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
|
|
|
96
135
|
out.push(...markersOf(s, plot.rows(s.key), yScale))
|
|
97
136
|
}
|
|
98
137
|
const labelled = plotted.filter((s) => s.role !== 'reference')
|
|
99
|
-
out.push(...endLabelMarks(endLabelPlan(plot, labelled)))
|
|
138
|
+
out.push(...endLabelMarks(endLabelPlan(plot, labelled, effective)))
|
|
100
139
|
return out
|
|
101
140
|
},
|
|
102
|
-
[series, thresholds],
|
|
141
|
+
[series, thresholds, effective],
|
|
142
|
+
)
|
|
143
|
+
return (
|
|
144
|
+
<CartesianRung
|
|
145
|
+
{...rest}
|
|
146
|
+
marks={marks}
|
|
147
|
+
{...(labelsOnly && { legend: false as const })}
|
|
148
|
+
{...(hideAtWide && { hideLegendAtWide: true })}
|
|
149
|
+
/>
|
|
103
150
|
)
|
|
104
|
-
return <CartesianRung {...rest} marks={marks} />
|
|
105
151
|
}
|
|
@@ -23,7 +23,7 @@ import { VX, alpha } from '../tokens'
|
|
|
23
23
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
24
24
|
import { defaultNumberFormat, seriesRow, visibleSeries } from './compile'
|
|
25
25
|
import { barMark, emphasis } from './marks'
|
|
26
|
-
import { PanelRung,
|
|
26
|
+
import { PanelRung, paneX, paneY, rowsOf } from './panel'
|
|
27
27
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
28
28
|
import { xScaleFor } from './scales'
|
|
29
29
|
import { foldBands, resolveNamedState } from './band-fold'
|
|
@@ -206,9 +206,8 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
206
206
|
on: boolean,
|
|
207
207
|
max: number,
|
|
208
208
|
): PaneBuilder =>
|
|
209
|
-
({ width: w
|
|
209
|
+
({ width: w }) => {
|
|
210
210
|
const cls = resolveContainerClass(w)
|
|
211
|
-
const whole = chartHeightOf(h, side === 'up' ? upFraction : 1 - upFraction, 0)
|
|
212
211
|
// The down pane's zero is at its top.
|
|
213
212
|
const domain: [number, number] = side === 'up' ? [0, max] : [max, 0]
|
|
214
213
|
const rows: PlotRow<T, X>[] = on ? rowsOf(drawn, x, s) : []
|
|
@@ -282,7 +281,7 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
282
281
|
scales: {
|
|
283
282
|
x:
|
|
284
283
|
side === 'down'
|
|
285
|
-
? paneX({ scale: bandScale(), model, format, cls
|
|
284
|
+
? paneX({ scale: bandScale(), model, format, cls })
|
|
286
285
|
: { scale: bandScale(), axis: false },
|
|
287
286
|
y: paneY({
|
|
288
287
|
scale: scaleLinear().domain(domain),
|
|
@@ -290,7 +289,6 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
290
289
|
format: cfg.format,
|
|
291
290
|
ticks: cfg.ticks ?? DEFAULT_PANE_TICKS,
|
|
292
291
|
cls,
|
|
293
|
-
height: whole,
|
|
294
292
|
}),
|
|
295
293
|
zx: { channel: 'x', scale: scaleLinear().domain([0, 1]), axis: false },
|
|
296
294
|
},
|
package/src/charts/Sparkline.tsx
CHANGED
|
@@ -11,11 +11,12 @@ 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'
|
|
@@ -24,7 +25,7 @@ import { ChartEngine, idPrefixOf } from './host'
|
|
|
24
25
|
import classes from './sparkline.module.css'
|
|
25
26
|
import { ChartPlaceholder, resolveChartState } from './state'
|
|
26
27
|
import { CHART_THEME, DASH } from './theme'
|
|
27
|
-
import type { ChartState } from './types'
|
|
28
|
+
import type { ChartMarks, ChartState } from './types'
|
|
28
29
|
|
|
29
30
|
export type SparklineProps = BasaltProps & {
|
|
30
31
|
/** The accessible name. Required: a chart without one is an unlabeled image. */
|
|
@@ -38,6 +39,8 @@ export type SparklineProps = BasaltProps & {
|
|
|
38
39
|
mark?: 'line' | 'bar' | undefined
|
|
39
40
|
/** A `VX.*` ref or a series token. Default `VX.faint`. */
|
|
40
41
|
color?: string | undefined
|
|
42
|
+
/** `'muted'`: the quiet trend line (a muted ink at low alpha). An explicit `color` wins. */
|
|
43
|
+
tone?: 'muted' | undefined
|
|
41
44
|
/** Paints the last point in `emphasisColor` — the one reading a trend beside a KPI is for.
|
|
42
45
|
* Default `true`; pass `false` for a bare line. */
|
|
43
46
|
emphasizeLast?: boolean | undefined
|
|
@@ -50,9 +53,13 @@ export type SparklineProps = BasaltProps & {
|
|
|
50
53
|
/** A quiet dashed hairline at a value, or at the mean of the plotted values (`'mean'`). The y
|
|
51
54
|
* domain widens to include it. Not a legend item, never a status colour. */
|
|
52
55
|
reference?: number | 'mean' | undefined
|
|
56
|
+
/** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot start just
|
|
57
|
+
* above the line. */
|
|
58
|
+
referenceLabel?: string | undefined
|
|
53
59
|
/** Formats the readout's value. Default: the compact number format. */
|
|
54
60
|
format?: ((value: number) => string) | undefined
|
|
55
|
-
/** The readout's x label per point, index-aligned with `data
|
|
61
|
+
/** The readout's x label per point, index-aligned with `data`: pass the point's day ("12 Oct"),
|
|
62
|
+
* and the readout reads `3 items · 12 Oct` beside the point. Omitted: the value alone. */
|
|
56
63
|
labels?: readonly string[] | undefined
|
|
57
64
|
}
|
|
58
65
|
|
|
@@ -61,6 +68,12 @@ type Point = { i: number; v: number | null }
|
|
|
61
68
|
const LINE_WIDTH = 1.5
|
|
62
69
|
const DOT_R = 2.5
|
|
63
70
|
const BAR_GAP = 0.15
|
|
71
|
+
/** Air round a line's plot, px (the engine's plot margin): the end marker stays inside the svg box,
|
|
72
|
+
* so it clears the 2px focus outline round it. A bar plot is flush. */
|
|
73
|
+
const LINE_INSET = 3
|
|
74
|
+
/** The muted tone's line: the same alpha the consumers hand-built (`alpha(VX.muted, .35)`). */
|
|
75
|
+
const MUTED_LINE = alpha(VX.muted, 0.35)
|
|
76
|
+
const REFERENCE_LABEL_DY = -4
|
|
64
77
|
// Pixel policy of the self-pooling (`poolSparkline`): the densest a series may draw.
|
|
65
78
|
const LINE_PX_PER_POINT = 1
|
|
66
79
|
const BAR_PX_PER_BAR = 2
|
|
@@ -201,9 +214,10 @@ function compileSparkline(
|
|
|
201
214
|
color: string,
|
|
202
215
|
emphasisColor: string | null,
|
|
203
216
|
reference: number | null,
|
|
217
|
+
referenceLabel: string | undefined,
|
|
204
218
|
): CartesianDefinition {
|
|
205
219
|
const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null)
|
|
206
|
-
const referenceMark = ():
|
|
220
|
+
const referenceMark = (): ChartMarks =>
|
|
207
221
|
reference === null
|
|
208
222
|
? []
|
|
209
223
|
: [
|
|
@@ -214,6 +228,22 @@ function compileSparkline(
|
|
|
214
228
|
strokeWidth: 1,
|
|
215
229
|
strokeDasharray: DASH,
|
|
216
230
|
}),
|
|
231
|
+
...(referenceLabel === undefined
|
|
232
|
+
? []
|
|
233
|
+
: [
|
|
234
|
+
decorative(
|
|
235
|
+
text([reference], {
|
|
236
|
+
id: 'reference-label',
|
|
237
|
+
x: () => (mark === 'bar' ? 0 : frame.x[0]),
|
|
238
|
+
y: (v: number) => v,
|
|
239
|
+
text: () => referenceLabel,
|
|
240
|
+
fill: VX.ink2,
|
|
241
|
+
fontSize: VX.text.micro,
|
|
242
|
+
anchor: 'start',
|
|
243
|
+
dy: REFERENCE_LABEL_DY,
|
|
244
|
+
}),
|
|
245
|
+
),
|
|
246
|
+
]),
|
|
217
247
|
]
|
|
218
248
|
return {
|
|
219
249
|
chart: ({ width }) => {
|
|
@@ -276,7 +306,7 @@ function compileSparkline(
|
|
|
276
306
|
},
|
|
277
307
|
theme: CHART_THEME,
|
|
278
308
|
guides: false,
|
|
279
|
-
margin:
|
|
309
|
+
margin: LINE_INSET,
|
|
280
310
|
}
|
|
281
311
|
},
|
|
282
312
|
}
|
|
@@ -315,11 +345,13 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
315
345
|
height,
|
|
316
346
|
width,
|
|
317
347
|
mark = 'line',
|
|
318
|
-
|
|
348
|
+
tone,
|
|
349
|
+
color = tone === 'muted' ? MUTED_LINE : VX.faint,
|
|
319
350
|
emphasizeLast = true,
|
|
320
351
|
emphasisColor = VX.line,
|
|
321
352
|
state,
|
|
322
353
|
reference,
|
|
354
|
+
referenceLabel,
|
|
323
355
|
format = defaultNumberFormat,
|
|
324
356
|
labels,
|
|
325
357
|
className,
|
|
@@ -344,9 +376,9 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
344
376
|
return {
|
|
345
377
|
rows,
|
|
346
378
|
frame: frameOf(full, mark, rows.length, end !== null),
|
|
347
|
-
definition: compileSparkline(rows, full, mark, color, end, ref),
|
|
379
|
+
definition: compileSparkline(rows, full, mark, color, end, ref, referenceLabel),
|
|
348
380
|
}
|
|
349
|
-
}, [data, mark, color, emphasizeLast, emphasisColor, reference])
|
|
381
|
+
}, [data, mark, color, emphasizeLast, emphasisColor, reference, referenceLabel])
|
|
350
382
|
const resolved = resolveChartState(state)
|
|
351
383
|
const rows = model?.rows
|
|
352
384
|
const interactive = resolved === null && model !== null
|
|
@@ -389,6 +421,8 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
389
421
|
setKeyed(lastFinite(rows))
|
|
390
422
|
}
|
|
391
423
|
|
|
424
|
+
const inset = mark === 'line' ? LINE_INSET : 0
|
|
425
|
+
const layerStyle = { inset, '--basalt-spark-lift': `${inset}px` } as CSSProperties
|
|
392
426
|
const value = active === null ? null : (rows?.[active]?.v ?? null)
|
|
393
427
|
const at =
|
|
394
428
|
interactive && active !== null && value !== null
|
|
@@ -428,7 +462,9 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
428
462
|
/>
|
|
429
463
|
)}
|
|
430
464
|
{at !== null && (
|
|
431
|
-
|
|
465
|
+
// One layer on the plot rect (inside a line's margin): the dot and the readout take their
|
|
466
|
+
// fractions of the same box, so both land where the mark did.
|
|
467
|
+
<span aria-hidden="true" className={classes.layer} style={layerStyle}>
|
|
432
468
|
<span
|
|
433
469
|
data-basalt-sparkline-dot=""
|
|
434
470
|
className={classes.dot}
|
|
@@ -437,12 +473,13 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
437
473
|
<output
|
|
438
474
|
data-basalt-sparkline-readout=""
|
|
439
475
|
aria-live={hover === null ? 'polite' : 'off'}
|
|
440
|
-
className={
|
|
476
|
+
className={classes.readout}
|
|
477
|
+
style={{ left: `${at.fx * 100}%`, transform: `translateX(-${at.fx * 100}%)` }}
|
|
441
478
|
>
|
|
442
|
-
{at.label !== undefined && <span className={classes.label}>{at.label} </span>}
|
|
443
479
|
{format(at.value)}
|
|
480
|
+
{at.label !== undefined && <span className={classes.label}> · {at.label}</span>}
|
|
444
481
|
</output>
|
|
445
|
-
|
|
482
|
+
</span>
|
|
446
483
|
)}
|
|
447
484
|
</div>
|
|
448
485
|
)
|
|
@@ -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
|
-
() =>
|
|
48
|
-
|
|
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 => {
|
package/src/charts/band-fold.ts
CHANGED
|
@@ -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,36 @@ 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
|
+
/** The glyph a state draws: its own, else its status tone's default, else none. */
|
|
33
|
+
export function glyphOf(
|
|
34
|
+
s: Pick<NamedChartState, 'glyph' | 'tone'> & { color?: string | undefined },
|
|
35
|
+
): string | undefined {
|
|
36
|
+
const tone =
|
|
37
|
+
s.tone ?? (s.color === VX.status.warn ? 'warn' : s.color === VX.status.bad ? 'bad' : undefined)
|
|
38
|
+
return s.glyph ?? (tone === undefined ? undefined : TONE_GLYPH[tone])
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A cell narrower than this (px) draws no glyph: it would not fit inside the fill. */
|
|
42
|
+
export const GLYPH_MIN_PX = 12
|
|
13
43
|
|
|
14
44
|
/** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
|
|
15
45
|
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
|
+
}
|