basalt-ui 2.16.0 → 2.17.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 +149 -126
- package/MIGRATING.md +101 -15
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +2 -2
- package/configs/oxlint-plugin.js +2 -2
- package/dist/charts/Donut.d.ts.map +1 -1
- package/dist/charts/Donut.js +2 -2
- package/dist/charts/DualPanel.js +2 -2
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +2 -2
- package/dist/charts/MirroredBars.js +2 -2
- package/dist/charts/Sparkline.d.ts +4 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +3 -3
- package/dist/charts/compile.d.ts +8 -3
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +19 -9
- package/dist/charts/cursor.d.ts +14 -1
- package/dist/charts/cursor.d.ts.map +1 -1
- package/dist/charts/cursor.js +29 -3
- package/dist/charts/date-tick-format.d.ts +17 -0
- package/dist/charts/date-tick-format.d.ts.map +1 -0
- package/dist/charts/date-tick-format.js +81 -0
- package/dist/charts/panel.d.ts +2 -1
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +3 -2
- package/dist/charts/types.d.ts +5 -1
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/capture.d.ts +16 -0
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +24 -3
- package/dist/cli/shot/playwright.d.ts +4 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.d.ts +2 -2
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +12 -14
- package/dist/dashboard/query-state.d.ts +35 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +12 -1
- package/dist/dashboard/stat-card-parts.d.ts +40 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -0
- package/dist/dashboard/stat-card-parts.js +55 -0
- package/dist/dashboard/stat-card.d.ts +46 -34
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +148 -79
- package/dist/dashboard/stat-card.module.css +220 -7
- package/dist/dashboard/stat-card.module.css.d.ts +20 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +73 -9
- package/dist/dashboard/widget-header.module.css +25 -17
- package/dist/guard/index.js +2 -2
- package/dist/theme/chrome-vars.d.ts +82 -0
- package/dist/theme/chrome-vars.d.ts.map +1 -0
- package/dist/theme/chrome-vars.js +36 -0
- package/dist/theme/controls.module.css +20 -1
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +30 -33
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +2 -2
- package/llms.txt +6 -3
- package/package.json +1 -1
- package/src/charts/Donut.tsx +2 -2
- package/src/charts/DualPanel.tsx +2 -2
- package/src/charts/Heatmap.tsx +2 -2
- package/src/charts/MirroredBars.tsx +2 -2
- package/src/charts/Sparkline.tsx +7 -5
- package/src/charts/compile.ts +31 -11
- package/src/charts/cursor.ts +48 -3
- package/src/charts/date-tick-format.ts +132 -0
- package/src/charts/panel.tsx +5 -3
- package/src/charts/types.ts +5 -1
- package/src/cli/shot/capture.ts +35 -3
- package/src/cli/shot/playwright.ts +1 -1
- package/src/dashboard/delta-badge.tsx +24 -18
- package/src/dashboard/query-state.tsx +38 -0
- package/src/dashboard/stat-card-parts.tsx +108 -0
- package/src/dashboard/stat-card.module.css +220 -7
- package/src/dashboard/stat-card.module.css.d.ts +20 -0
- package/src/dashboard/stat-card.tsx +282 -174
- package/src/dashboard/widget-header.module.css +25 -17
- package/src/dashboard/widget-header.tsx +103 -7
- package/src/guard/index.ts +2 -2
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +128 -40
- package/src/theme/chrome-vars.ts +111 -0
- package/src/theme/controls.module.css +20 -1
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +39 -101
- package/src/tokens/derive.ts +7 -2
|
@@ -276,7 +276,7 @@ html .accordionItem {
|
|
|
276
276
|
/*
|
|
277
277
|
* Tabs: the tab-list rule (and the inactive-tab hover underline) is a layout separator — the
|
|
278
278
|
* divider token, not the heavy gray-3/dark-4 line. Mantine's scheme rules sit at (0,2,0); the
|
|
279
|
-
* `html[...]` prefix lands (0,2,1). The active underline
|
|
279
|
+
* `html[...]` prefix lands (0,2,1). The active underline's colour is set in the theme's Tabs `vars`.
|
|
280
280
|
*/
|
|
281
281
|
html[data-mantine-color-scheme] .tabsRoot {
|
|
282
282
|
--tab-border-color: var(--vx-divider);
|
|
@@ -304,3 +304,22 @@ html .tableRoot {
|
|
|
304
304
|
html .tableRoot tbody tr:last-of-type {
|
|
305
305
|
border-bottom: none;
|
|
306
306
|
}
|
|
307
|
+
|
|
308
|
+
/*
|
|
309
|
+
* Badge leading glyph (`leftSection`): the state encoded by shape. 12px on a 20px chip, 4px gap
|
|
310
|
+
* (Mantine's own section margin is spacing.xs / 2 = 4), centred on the label.
|
|
311
|
+
*/
|
|
312
|
+
.badgeSection {
|
|
313
|
+
--badge-section-margin: calc(0.25rem * var(--mantine-scale));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.badgeSection svg,
|
|
317
|
+
.badgeSection img {
|
|
318
|
+
width: calc(0.75rem * var(--mantine-scale));
|
|
319
|
+
height: calc(0.75rem * var(--mantine-scale));
|
|
320
|
+
flex-shrink: 0;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.badgeSection img {
|
|
324
|
+
object-fit: contain;
|
|
325
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAwBA,OA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AAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE9E,8FAA8F;AAC9F,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAsF7D;;8FAE8F;AAC9F,eAAO,MAAM,oBAAoB,EAAE,oBACc,CAAA;AAEjD,kEAAkE;AAClE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IAE9B;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAA;IAEzB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAE1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAC7B,CAAA;AAYD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,aAAa,CAAC,EACrD,OAAO,CAAC,EAAE,wBAAwB,GACjC,oBAAoB,CAiCtB"}
|
package/dist/theme/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { DEFAULT_DERIVE_CONFIG, isDefaultDeriveConfig, resolveDeriveConfig } fro
|
|
|
17
17
|
import { pxRem, TEXT_LINE, VX } from "../tokens/core.js";
|
|
18
18
|
import { CTL_HEIGHT_VARS } from "../tokens/ctl-vars.js";
|
|
19
19
|
import { SIZE_CLASS_BREAKPOINTS } from "../tokens/size-classes.js";
|
|
20
|
+
import { onColor, onColorFor, subtleInkVars, tabsVars } from "./chrome-vars.js";
|
|
20
21
|
import controlsClasses from "./controls.module.css";
|
|
21
22
|
import floatingClasses from "./floating.module.css";
|
|
22
23
|
import navLinkClasses from "./nav-link.module.css";
|
|
@@ -70,15 +71,6 @@ function buildDarkTuple(data) {
|
|
|
70
71
|
"#09090b"
|
|
71
72
|
];
|
|
72
73
|
}
|
|
73
|
-
function onColor(theme, color) {
|
|
74
|
-
const name = color ?? theme.primaryColor;
|
|
75
|
-
if (!Object.prototype.hasOwnProperty.call(theme.colors, name)) return void 0;
|
|
76
|
-
return `var(--vx-on-${name})`;
|
|
77
|
-
}
|
|
78
|
-
function onColorFor(theme, props) {
|
|
79
|
-
const autoContrast = props.autoContrast ?? theme.autoContrast;
|
|
80
|
-
return autoContrast ? onColor(theme, props.color) : void 0;
|
|
81
|
-
}
|
|
82
74
|
function relativeLuminance(hex) {
|
|
83
75
|
const channels = hexToRgb(hex).map((c) => {
|
|
84
76
|
const s = c / 255;
|
|
@@ -113,10 +105,6 @@ const basaltVariantColorResolver = (input) => {
|
|
|
113
105
|
const autoContrast = input.autoContrast ?? input.theme.autoContrast;
|
|
114
106
|
return autoContrast ? { ...resolved, color: on } : resolved;
|
|
115
107
|
}
|
|
116
|
-
if (input.variant === "subtle") {
|
|
117
|
-
const isDefaultColor = input.color === void 0 || input.color === input.theme.primaryColor;
|
|
118
|
-
return isDefaultColor ? { ...resolved, hover: `color-mix(in srgb, var(--vx-ink) 6%, transparent)` } : resolved;
|
|
119
|
-
}
|
|
120
108
|
if (input.variant === "outline") {
|
|
121
109
|
return { ...resolved, color: `color-mix(in srgb, ${resolved.color} 70%, var(--vx-ink))` };
|
|
122
110
|
}
|
|
@@ -259,10 +247,12 @@ function buildTheme(data, options = {}) {
|
|
|
259
247
|
}
|
|
260
248
|
}
|
|
261
249
|
}),
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
250
|
+
// Status chip (SPEC § 6.10): `light` + `tight`, neutral until `color=` opts in (the accent is
|
|
251
|
+
// never a status chip's default); a `leftSection` glyph is sized in `badgeSection`.
|
|
252
|
+
Badge: ext({
|
|
253
|
+
defaultProps: { variant: "light", color: "gray", radius: radius.tight },
|
|
254
|
+
classNames: { section: controlsClasses.badgeSection }
|
|
255
|
+
}),
|
|
266
256
|
// Alert renders its title in the body font by default; bring it onto the head-font idiom
|
|
267
257
|
// (docs/DESIGN-SPEC.md §5) like every other titled surface. Radius/padding/color tint are
|
|
268
258
|
// already on-system (defaultRadius 'md' control tier + the variant color resolver), so only
|
|
@@ -425,19 +415,29 @@ function buildTheme(data, options = {}) {
|
|
|
425
415
|
// `size="xs"`) on Mantine's own static height.
|
|
426
416
|
Button: ext({
|
|
427
417
|
classNames: { root: controlsClasses.buttonRoot },
|
|
428
|
-
vars: (_theme, props) =>
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
418
|
+
vars: (_theme, props) => {
|
|
419
|
+
const ink = subtleInkVars(props);
|
|
420
|
+
return {
|
|
421
|
+
root: {
|
|
422
|
+
"--button-height": props.size === "md" ? "calc(var(--vx-space-control-height) * var(--mantine-scale))" : void 0,
|
|
423
|
+
"--button-color": ink.color,
|
|
424
|
+
"--button-hover": ink.hover
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
433
428
|
}),
|
|
434
429
|
ActionIcon: ext({
|
|
435
430
|
classNames: { root: controlsClasses.actionIconRoot },
|
|
436
|
-
vars: (_theme, props) =>
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
431
|
+
vars: (_theme, props) => {
|
|
432
|
+
const ink = subtleInkVars(props);
|
|
433
|
+
return {
|
|
434
|
+
root: {
|
|
435
|
+
"--ai-size": props.size === "md" ? "calc(var(--vx-space-control-height) * var(--mantine-scale))" : void 0,
|
|
436
|
+
"--ai-color": ink.color,
|
|
437
|
+
"--ai-hover": ink.hover
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
441
|
}),
|
|
442
442
|
// CheckboxCard / RadioCard (`withBorder`, true by default): same live regression as Button/
|
|
443
443
|
// ActionIcon before this pass — Mantine ships `border: 1px solid transparent` as the BASE
|
|
@@ -799,14 +799,11 @@ function buildTheme(data, options = {}) {
|
|
|
799
799
|
// The tab-list bottom rule (and the inactive-tab hover underline) is a layout separator, not
|
|
800
800
|
// control chrome — it reads the divider token instead of the heavy gray-3/dark-4 line
|
|
801
801
|
// (controls.module.css; custom properties are stripped from `styles` objects). The active tab
|
|
802
|
-
// underline
|
|
802
|
+
// underline takes ink, not the accent (SPEC § 6.12; DESIGN-CORE § Accent discipline);
|
|
803
|
+
// `color=` opts back in. Only the underline `default` variant — `pills` fills with the colour.
|
|
803
804
|
Tabs: ext({
|
|
804
805
|
classNames: { root: controlsClasses.tabsRoot },
|
|
805
|
-
|
|
806
|
-
// `--tabs-color` / `--tabs-radius`, yet Tabs' OWN varsResolver writes `--tabs-text-color` —
|
|
807
|
-
// an upstream type gap, so the var it actually paints the active tab with is otherwise
|
|
808
|
-
// unreachable from the theme.
|
|
809
|
-
vars: (theme, props) => ({ root: { "--tabs-text-color": onColorFor(theme, props) } })
|
|
806
|
+
vars: tabsVars
|
|
810
807
|
}),
|
|
811
808
|
// ── ON-COLOR re-points (see the ON-COLOR doctrine above) ────────────────────────────────
|
|
812
809
|
// These components never reach `variantColorResolver` — each calls Mantine's `getContrastColor`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../../src/tokens/derive.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAEvC,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;;;;OAQG;IACH,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAA;IAC/C;kGAC8F;IAC9F,UAAU,EAAE,MAAM,CAAA;IAClB;mDAC+C;IAC/C,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;;;OAMG;IACH,gB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;IACtC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;CACrC,CAAA;AAED;;8DAE8D;AAC9D,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,CAQjE;AAED,gGAAgG;AAChG,wBAAgB,eAAe,CAC7B,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,CAAC,EAChD,MAAM,EAAE,YAAY,GACnB,cAAc,CA+GhB"}
|
package/dist/tokens/derive.js
CHANGED
|
@@ -135,8 +135,8 @@ const INK_TONE = {
|
|
|
135
135
|
const STATUS_HUE = { good: 151.975, warn: 76.64, bad: 29.905 };
|
|
136
136
|
const STATUS_STOP = {
|
|
137
137
|
good: { light: { tone: 45.75, chroma: 37.75 }, dark: { tone: 70.23, chroma: 53.23 } },
|
|
138
|
-
warn: { light: { tone:
|
|
139
|
-
bad: { light: { tone: 43.86, chroma: 54.46 }, dark: { tone:
|
|
138
|
+
warn: { light: { tone: 46, chroma: 61.12 }, dark: { tone: 72.34, chroma: 62.55 } },
|
|
139
|
+
bad: { light: { tone: 43.86, chroma: 54.46 }, dark: { tone: 66.5, chroma: 53.79 } }
|
|
140
140
|
};
|
|
141
141
|
function deriveTokens(config) {
|
|
142
142
|
assertValidAccentHex(config.accent);
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.
|
|
1
|
+
# basalt-ui v2.17.0
|
|
2
2
|
# Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
|
|
3
3
|
#
|
|
4
4
|
# Entry points: use the exact import specifier below; do not guess.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
|
|
14
14
|
|
|
15
15
|
Package: basalt-ui
|
|
16
|
-
Version: 2.
|
|
16
|
+
Version: 2.17.0
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
|
@@ -159,7 +159,6 @@ Signature: StatCard(props: StatCardProps): JSX.Element
|
|
|
159
159
|
classNames?: Partial<Record<StatCardSlot, string>>
|
|
160
160
|
icon?: ReactNode
|
|
161
161
|
title: string
|
|
162
|
-
subtitle?: string
|
|
163
162
|
info?: string
|
|
164
163
|
unit?: string
|
|
165
164
|
delta?: number
|
|
@@ -168,6 +167,10 @@ Signature: StatCard(props: StatCardProps): JSX.Element
|
|
|
168
167
|
deltaFormat?: (delta: number) => string
|
|
169
168
|
deltaGlyph?: boolean
|
|
170
169
|
value: string
|
|
170
|
+
qualifier?: string
|
|
171
|
+
subtitle?: string
|
|
172
|
+
loading?: boolean
|
|
173
|
+
emptyText?: string
|
|
171
174
|
breakdown?: readonly StatCardBreakdownRow[]
|
|
172
175
|
query?: QueryStateLike<unknown>
|
|
173
176
|
sparkline?: ReactNode | ((size: StatCardSparklineSize) => ReactNode)
|
package/package.json
CHANGED
package/src/charts/Donut.tsx
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* container or wider, below it otherwise (`donut.module.css`, decided in CSS so the server HTML is
|
|
7
7
|
* the hydrated layout). No cursor: a ring has no shared axis.
|
|
8
8
|
*/
|
|
9
|
-
import { tooltip as tooltipHost } from '@tanstack/charts/tooltip'
|
|
10
9
|
import { portal } from '@tanstack/charts/tooltip/portal'
|
|
11
10
|
import { pie, polar, radialArc } from '@tanstack/charts/polar'
|
|
12
11
|
import type { ChartPoint, StoredChartSpec } from '@tanstack/charts/types/core'
|
|
@@ -15,6 +14,7 @@ import type { CSSProperties, ReactElement } from 'react'
|
|
|
15
14
|
import type { BasaltProps } from '../common/props'
|
|
16
15
|
import { alpha, VX } from '../tokens'
|
|
17
16
|
import type { CartesianDefinition } from './compile'
|
|
17
|
+
import { engineTooltip } from './cursor'
|
|
18
18
|
import { ChartEngine, idPrefixOf } from './host'
|
|
19
19
|
import { ChartLegend } from './legend'
|
|
20
20
|
import { useCoarsePointer } from '../common/use-media-query'
|
|
@@ -184,7 +184,7 @@ export function Donut<K extends string = string>(props: DonutProps<K>): ReactEle
|
|
|
184
184
|
theme: CHART_THEME,
|
|
185
185
|
}),
|
|
186
186
|
tooltip: {
|
|
187
|
-
use:
|
|
187
|
+
use: engineTooltip,
|
|
188
188
|
portal,
|
|
189
189
|
content: (points: readonly ChartPoint[]) => {
|
|
190
190
|
const slice = points[0]?.datum as Slice | undefined
|
package/src/charts/DualPanel.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import { useCallback, useMemo } from 'react'
|
|
|
14
14
|
import type { ReactElement } from 'react'
|
|
15
15
|
import { VX, alpha } from '../tokens'
|
|
16
16
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
17
|
-
import {
|
|
17
|
+
import { defaultNumberFormat, engineRow, seriesRow, visibleSeries } from './compile'
|
|
18
18
|
import { barMark, emphasis, lineMark, markersOf, thinFill } from './marks'
|
|
19
19
|
import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from './panel'
|
|
20
20
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
@@ -182,7 +182,7 @@ export function DualPanel<T, X extends Date | number = Date | number>(
|
|
|
182
182
|
// A row's x as a fraction of the plot (the domain is padded half a step each side).
|
|
183
183
|
const fillAt = (v: Date | number): number =>
|
|
184
184
|
((v instanceof Date ? v.getTime() : v) - (lo - pad)) / (hi - lo + 2 * pad)
|
|
185
|
-
const format = (v: ChartValue): string =>
|
|
185
|
+
const format = formatX ? (v: ChartValue): string => formatX(v as X) : undefined
|
|
186
186
|
|
|
187
187
|
const visible = visibleSeries(lines, hidden)
|
|
188
188
|
const barOn = !hidden.has(BAR_KEY)
|
package/src/charts/Heatmap.tsx
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { colorGradientLegend } from '@tanstack/charts/legend'
|
|
11
11
|
import { cell } from '@tanstack/charts/rect'
|
|
12
12
|
import { scaleBand } from '@tanstack/charts/scales/band'
|
|
13
|
-
import { tooltip as tooltipHost } from '@tanstack/charts/tooltip'
|
|
14
13
|
import { portal } from '@tanstack/charts/tooltip/portal'
|
|
15
14
|
import type { ChartBuildContext, ChartPoint, StoredChartSpec } from '@tanstack/charts/types/core'
|
|
16
15
|
import { scaleQuantize } from 'd3-scale'
|
|
@@ -24,6 +23,7 @@ import type { CartesianDefinition } from './compile'
|
|
|
24
23
|
import { resolveNamedState } from './band-fold'
|
|
25
24
|
import type { NamedChartState } from './band-fold'
|
|
26
25
|
import { ABSENT_OPACITY, RAMP_LEVELS, RAMP_OPACITIES } from './heatmap-fill'
|
|
26
|
+
import { engineTooltip } from './cursor'
|
|
27
27
|
import { ChartEngine, idPrefixOf } from './host'
|
|
28
28
|
import { ChartLegend } from './legend'
|
|
29
29
|
import { useCoarsePointer } from '../common/use-media-query'
|
|
@@ -239,7 +239,7 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
239
239
|
cell(group, { id, x: 'col', y: 'row', inset: CELL_INSET, key: 'id', ...paint })
|
|
240
240
|
const tooltipOptions = showTooltip
|
|
241
241
|
? {
|
|
242
|
-
use:
|
|
242
|
+
use: engineTooltip,
|
|
243
243
|
portal,
|
|
244
244
|
content: (points: readonly ChartPoint[]) => {
|
|
245
245
|
const point = points[0]
|
|
@@ -21,7 +21,7 @@ import { useCallback, useMemo } from 'react'
|
|
|
21
21
|
import type { ReactElement } from 'react'
|
|
22
22
|
import { VX, alpha } from '../tokens'
|
|
23
23
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
24
|
-
import {
|
|
24
|
+
import { defaultNumberFormat, seriesRow, visibleSeries } from './compile'
|
|
25
25
|
import { barMark, emphasis } from './marks'
|
|
26
26
|
import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from './panel'
|
|
27
27
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
@@ -191,7 +191,7 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
191
191
|
: VX.neutral
|
|
192
192
|
const upOn = visible.includes(upSeries)
|
|
193
193
|
const downOn = visible.includes(downSeries)
|
|
194
|
-
const format = (v: ChartValue): string =>
|
|
194
|
+
const format = formatX ? (v: ChartValue): string => formatX(v as X) : undefined
|
|
195
195
|
const upMax = paneMax(up, upSeries, drawn, upOn)
|
|
196
196
|
const downMax = paneMax(down, downSeries, drawn, downOn)
|
|
197
197
|
const bandWidth = 2 * model.halfStep * BAND_FILL
|
package/src/charts/Sparkline.tsx
CHANGED
|
@@ -34,9 +34,11 @@ export type SparklineProps = BasaltProps & {
|
|
|
34
34
|
mark?: 'line' | 'bar' | undefined
|
|
35
35
|
/** A `VX.*` ref or a series token. Default `VX.faint`. */
|
|
36
36
|
color?: string | undefined
|
|
37
|
-
/** Paints the last point in `emphasisColor` — the one reading a trend beside a KPI is for.
|
|
37
|
+
/** Paints the last point in `emphasisColor` — the one reading a trend beside a KPI is for.
|
|
38
|
+
* Default `true`; pass `false` for a bare line. */
|
|
38
39
|
emphasizeLast?: boolean | undefined
|
|
39
|
-
/** Default `VX.
|
|
40
|
+
/** Default `VX.line`, the line's own neutral, so a single metric stays neutral. Pass a status or
|
|
41
|
+
* trend colour to make the end dot carry a verdict. */
|
|
40
42
|
emphasisColor?: string | undefined
|
|
41
43
|
/** Pending / error / empty, the same contract as every other kind. The placeholder fills the
|
|
42
44
|
* sparkline's own `width` × `height`, so a loading tile does not shift when the trend lands. */
|
|
@@ -45,7 +47,7 @@ export type SparklineProps = BasaltProps & {
|
|
|
45
47
|
|
|
46
48
|
type Point = { i: number; v: number | null }
|
|
47
49
|
|
|
48
|
-
const LINE_WIDTH = 1.
|
|
50
|
+
const LINE_WIDTH = 1.5
|
|
49
51
|
const DOT_R = 2.5
|
|
50
52
|
const BAR_GAP = 0.15
|
|
51
53
|
// Pixel policy of the self-pooling (`poolSparkline`): the densest a series may draw.
|
|
@@ -249,8 +251,8 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
249
251
|
width,
|
|
250
252
|
mark = 'line',
|
|
251
253
|
color = VX.faint,
|
|
252
|
-
emphasizeLast =
|
|
253
|
-
emphasisColor = VX.
|
|
254
|
+
emphasizeLast = true,
|
|
255
|
+
emphasisColor = VX.line,
|
|
254
256
|
state,
|
|
255
257
|
className,
|
|
256
258
|
style,
|
package/src/charts/compile.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* binding, the tooltip content, and the container-class guide ladder.
|
|
6
6
|
* TanStack owns margins (measured), layout, focus and keyboard, the tooltip surface and SSR.
|
|
7
7
|
*/
|
|
8
|
+
import { dateTickFormat, monthName, pad2, utcAxisDate } from './date-tick-format'
|
|
8
9
|
import { crosshair } from '@tanstack/charts/crosshair'
|
|
9
10
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
10
11
|
import { rect } from '@tanstack/charts/rect'
|
|
@@ -122,18 +123,11 @@ export function defaultNumberFormat(v: number): string {
|
|
|
122
123
|
return compact(v, { digits: Math.abs(v) >= 1000 ? 1 : 2 })
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
126
126
|
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
127
|
-
const pad2 = (n: number): string => String(n).padStart(2, '0')
|
|
128
|
-
|
|
129
|
-
/** `DD.MM`, read in UTC like the time scale that placed it (a local read shifts a day west of UTC). */
|
|
130
|
-
export function utcAxisDate(d: Date): string {
|
|
131
|
-
return `${pad2(d.getUTCDate())}.${pad2(d.getUTCMonth() + 1)}`
|
|
132
|
-
}
|
|
133
127
|
|
|
134
128
|
/** `Mon Sep 1 2026`, in UTC; a non-midnight instant adds `HH:MM`. */
|
|
135
129
|
export function utcHeaderDate(d: Date): string {
|
|
136
|
-
const date = `${DAYS[d.getUTCDay()]} ${
|
|
130
|
+
const date = `${DAYS[d.getUTCDay()]} ${monthName(d)} ${d.getUTCDate()} ${d.getUTCFullYear()}`
|
|
137
131
|
const ms = d.getTime() % DAY_MS
|
|
138
132
|
return ms === 0 ? date : `${date} ${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`
|
|
139
133
|
}
|
|
@@ -319,18 +313,38 @@ export function strideTicks<V>(values: readonly V[], cls: ContainerClass): V[] {
|
|
|
319
313
|
return strideEvery(values, LADDER[cls].xTicks)
|
|
320
314
|
}
|
|
321
315
|
|
|
316
|
+
/**
|
|
317
|
+
* The one decision between a consumer's x format and the default: the consumer's wins; else dates
|
|
318
|
+
* read span-aware from the given tick values; else the plain default (numbers, strings, and a lone
|
|
319
|
+
* Date with no ticks to read a span from).
|
|
320
|
+
*/
|
|
321
|
+
export function xTickFormat(
|
|
322
|
+
consumer: ((v: ChartValue) => string) | undefined,
|
|
323
|
+
tickValues: readonly ChartValue[],
|
|
324
|
+
): (v: ChartValue) => string {
|
|
325
|
+
if (consumer) return consumer
|
|
326
|
+
if (tickValues.length === 0 || !tickValues.every((v): v is Date => v instanceof Date))
|
|
327
|
+
return defaultFormatX
|
|
328
|
+
const dateFormat = dateTickFormat(tickValues)
|
|
329
|
+
return (v) => (v instanceof Date ? dateFormat(v) : defaultFormatX(v))
|
|
330
|
+
}
|
|
331
|
+
|
|
322
332
|
export function xGuide<X extends ChartX>(opts: {
|
|
323
333
|
model: XScaleModel<X>
|
|
324
334
|
xTicks: number | readonly X[] | undefined
|
|
325
|
-
|
|
335
|
+
/** A consumer's formatter; absent, Date ticks get the span-aware {@link xTickFormat}. */
|
|
336
|
+
format?: ((v: ChartValue) => string) | undefined
|
|
326
337
|
cls: ContainerClass
|
|
327
338
|
/** The whole chart's height: decides whether the left margin is locked to zero. */
|
|
328
339
|
height: number
|
|
329
340
|
}): Omit<ChartPositionScaleOptions<ChartValue>, 'scale'> {
|
|
330
|
-
const { model, xTicks,
|
|
341
|
+
const { model, xTicks, cls, height } = opts
|
|
331
342
|
const ladder = LADDER[cls]
|
|
332
343
|
const inside = labelsInside(cls, height)
|
|
333
344
|
const ticks = xTickPolicy(model, xTicks ?? ladder.xTicks)
|
|
345
|
+
// A Date axis always resolves to `values` (the time scale has an extent; a band axis lists its
|
|
346
|
+
// buckets), so `{ count }` is only ever a number axis and never needs the date formatter.
|
|
347
|
+
const format = xTickFormat(opts.format, 'values' in ticks ? ticks.values : [])
|
|
334
348
|
// A continuous scale's domain start and span; a band scale pads its first slot, so none applies.
|
|
335
349
|
const [leftEdgeX, spanX] =
|
|
336
350
|
!model.band && model.extent
|
|
@@ -703,7 +717,13 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
703
717
|
return {
|
|
704
718
|
x: {
|
|
705
719
|
scale: model.scale,
|
|
706
|
-
...xGuide({
|
|
720
|
+
...xGuide({
|
|
721
|
+
model,
|
|
722
|
+
xTicks: input.xTicks,
|
|
723
|
+
format: input.formatX ? formatX : undefined,
|
|
724
|
+
cls,
|
|
725
|
+
height,
|
|
726
|
+
}),
|
|
707
727
|
},
|
|
708
728
|
y: {
|
|
709
729
|
scale: yScaleFor(input.y, left.domain),
|
package/src/charts/cursor.ts
CHANGED
|
@@ -294,10 +294,55 @@ export function followerOptions(
|
|
|
294
294
|
return onFollow ? {} : ({ follower: { group, chartId } } satisfies TooltipFollowerOptions)
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
/** The engine host's hover readout element. */
|
|
298
|
+
export const TOOLTIP_READOUT = '.ts-chart-tooltip'
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The engine host stamps `role="status"` on its readout on every paint; a hover readout is a
|
|
302
|
+
* tooltip. `aria-live="polite"` stays, so a keyboard user still hears the reading. The host hands
|
|
303
|
+
* out no element: the readout is in the chart's container, except in the portal's fallback, which
|
|
304
|
+
* parks it on `<body>` — only then is the owner document searched (and every chart's readout
|
|
305
|
+
* stamped, which is right for each). Idempotent; a pinned custom body's `role="dialog"` is left
|
|
306
|
+
* alone.
|
|
307
|
+
*/
|
|
308
|
+
function stampTooltipRole(container: Element): void {
|
|
309
|
+
const own = container.querySelectorAll(TOOLTIP_READOUT)
|
|
310
|
+
const readouts = own.length > 0 ? own : container.ownerDocument.querySelectorAll(TOOLTIP_READOUT)
|
|
311
|
+
for (const el of readouts)
|
|
312
|
+
if (el.getAttribute('role') === 'status') el.setAttribute('role', 'tooltip')
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Decorates a tooltip host so every `paint` is followed by {@link stampTooltipRole}. The one
|
|
317
|
+
* stamping seam: `quietWhileFollowing` is built on it, and so is any chart that wires the engine host
|
|
318
|
+
* directly (Donut, Heatmap).
|
|
319
|
+
*/
|
|
320
|
+
export function withTooltipRole(extension: ChartTooltipExtension): ChartTooltipExtension {
|
|
321
|
+
return {
|
|
322
|
+
...extension,
|
|
323
|
+
create: (context) => {
|
|
324
|
+
const host = extension.create(context)
|
|
325
|
+
return {
|
|
326
|
+
...host,
|
|
327
|
+
paint: (paint) => {
|
|
328
|
+
host.paint(paint)
|
|
329
|
+
stampTooltipRole(context.container)
|
|
330
|
+
},
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The engine's tooltip host with its readout stamped, built once: a chart passes this as
|
|
338
|
+
* `tooltip.use`, so the extension keeps one identity across memo rebuilds.
|
|
339
|
+
*/
|
|
340
|
+
export const engineTooltip = withTooltipRole(tooltip)
|
|
341
|
+
|
|
297
342
|
/**
|
|
298
343
|
* The engine's DOM tooltip host, silent while this chart FOLLOWS another's cursor. A follower
|
|
299
344
|
* resolves the leader's focus group (so the engine draws the same dots at the shared x); the host
|
|
300
|
-
* would then paint a tooltip and fill its
|
|
345
|
+
* would then paint a tooltip and fill its live region. Whenever `isForeign` holds,
|
|
301
346
|
* this wrapper calls the host's `hide()` instead of `paint()`: a follower that has never led never
|
|
302
347
|
* creates the element, and one that has led keeps it in the DOM, hidden. Otherwise (leader, no
|
|
303
348
|
* `follower` option, or after the leader clears) it defers to the host.
|
|
@@ -309,9 +354,9 @@ export function followerOptions(
|
|
|
309
354
|
* re-check this wrapper, the live region included, on every `@tanstack/charts` upgrade.
|
|
310
355
|
*/
|
|
311
356
|
export const quietWhileFollowing: ChartTooltipExtension = {
|
|
312
|
-
...
|
|
357
|
+
...engineTooltip,
|
|
313
358
|
create: (context) => {
|
|
314
|
-
const host =
|
|
359
|
+
const host = engineTooltip.create(context)
|
|
315
360
|
let configured = false
|
|
316
361
|
let follower: TooltipFollowerOptions['follower']
|
|
317
362
|
return {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default Date x tick labels: chosen from the TICK step (not the data step), read in UTC like
|
|
3
|
+
* the scale that placed them. A label may recur on one axis only behind a MARKER label (a day or a
|
|
4
|
+
* year) — `12:00, 18:00, 18.10, 06:00, 12:00` is fine, `17.10, 17.10, 18.10` is not. Each span has
|
|
5
|
+
* a ladder of levels, plainest first; the first level that holds the invariant wins. The last rung
|
|
6
|
+
* of every ladder names the whole date (or instant) of its tick, so the invariant always holds.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
10
|
+
export const pad2 = (n: number): string => String(n).padStart(2, '0')
|
|
11
|
+
|
|
12
|
+
export const monthName = (d: Date): string => MONTHS[d.getUTCMonth()]!
|
|
13
|
+
|
|
14
|
+
const DAY_MS = 86_400_000
|
|
15
|
+
const HOUR_MS = 3_600_000
|
|
16
|
+
/**
|
|
17
|
+
* Month ticks are 28–31 days apart; 27 days leaves slack for a consumer's uneven ticks while
|
|
18
|
+
* keeping a 2-week step on the day ladder.
|
|
19
|
+
*/
|
|
20
|
+
const MONTH_STEP_MS = 27 * DAY_MS
|
|
21
|
+
|
|
22
|
+
/** `DD.MM`, read in UTC like the time scale (a local read shifts a day west of UTC). */
|
|
23
|
+
export function utcAxisDate(d: Date): string {
|
|
24
|
+
return `${pad2(d.getUTCDate())}.${pad2(d.getUTCMonth() + 1)}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const utcClock = (d: Date): string => `${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`
|
|
28
|
+
const utcClockSeconds = (d: Date): string => `${utcClock(d)}:${pad2(d.getUTCSeconds())}`
|
|
29
|
+
const utcClockMillis = (d: Date): string =>
|
|
30
|
+
`${utcClockSeconds(d)}.${String(d.getUTCMilliseconds()).padStart(3, '0')}`
|
|
31
|
+
/** Two digits: a widened day label stays 8 characters and still reads as the `DD.MM` family. */
|
|
32
|
+
const utcAxisDateYear = (d: Date): string =>
|
|
33
|
+
`${utcAxisDate(d)}.${String(d.getUTCFullYear()).slice(2)}`
|
|
34
|
+
|
|
35
|
+
const isMidnight = (t: number): boolean => t % DAY_MS === 0
|
|
36
|
+
const isJanuary = (d: Date): boolean => d.getUTCMonth() === 0
|
|
37
|
+
const dayOf = (t: number): number => Math.floor(t / DAY_MS)
|
|
38
|
+
const startsNewDay = (t: number, prev: number | undefined): boolean =>
|
|
39
|
+
prev === undefined || dayOf(t) !== dayOf(prev)
|
|
40
|
+
|
|
41
|
+
type Label = { text: string; marker: boolean }
|
|
42
|
+
/** One label per tick time (ascending), as a whole: a label may depend on its predecessor. */
|
|
43
|
+
type Level = (times: readonly number[]) => Label[]
|
|
44
|
+
|
|
45
|
+
const marker = (text: string): Label => ({ text, marker: true })
|
|
46
|
+
const plain = (text: string): Label => ({ text, marker: false })
|
|
47
|
+
const each =
|
|
48
|
+
(label: (t: number, d: Date, prev: number | undefined) => Label): Level =>
|
|
49
|
+
(times) =>
|
|
50
|
+
times.map((t, i) => label(t, new Date(t), times[i - 1]))
|
|
51
|
+
|
|
52
|
+
/** Under a day: `HH:MM`, a midnight tick carries the day. */
|
|
53
|
+
const subDayLevels: Level[] = [
|
|
54
|
+
each((t, d) => (isMidnight(t) ? marker(utcAxisDate(d)) : plain(utcClock(d)))),
|
|
55
|
+
// No midnight in reach: the first tick of each day carries its date instead.
|
|
56
|
+
each((t, d, prev) =>
|
|
57
|
+
isMidnight(t)
|
|
58
|
+
? marker(utcAxisDate(d))
|
|
59
|
+
: startsNewDay(t, prev)
|
|
60
|
+
? marker(`${utcAxisDate(d)} ${utcClock(d)}`)
|
|
61
|
+
: plain(utcClock(d)),
|
|
62
|
+
),
|
|
63
|
+
each((_, d) => marker(`${utcAxisDate(d)} ${utcClock(d)}`)),
|
|
64
|
+
// Sub-minute steps: the seconds, then (sub-second steps) the milliseconds. Every label names its
|
|
65
|
+
// whole instant to the millisecond, and `dateTickFormat` dedupes ticks to the millisecond, so
|
|
66
|
+
// the last rung cannot repeat.
|
|
67
|
+
each((_, d) => marker(`${utcAxisDate(d)} ${utcClockSeconds(d)}`)),
|
|
68
|
+
each((_, d) => marker(`${utcAxisDate(d)} ${utcClockMillis(d)}`)),
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A day or more: `DD.MM`. Ticks are at least a day apart here, so they fall on different UTC days
|
|
73
|
+
* and the last rung, which names the full date, cannot repeat.
|
|
74
|
+
*/
|
|
75
|
+
const dayLevels: Level[] = [
|
|
76
|
+
each((_, d) => marker(utcAxisDate(d))),
|
|
77
|
+
each((_, d) => marker(utcAxisDateYear(d))),
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
/** A month or more: the month, a January tick carries the year. */
|
|
81
|
+
const monthLevels: Level[] = [
|
|
82
|
+
each((_, d) => (isJanuary(d) ? marker(String(d.getUTCFullYear())) : plain(monthName(d)))),
|
|
83
|
+
each((_, d) => marker(`${monthName(d)} ${d.getUTCFullYear()}`)),
|
|
84
|
+
// Ticks a month apart in name only (Jan 1 and Jan 31): fall to the day ladder (ticks here are
|
|
85
|
+
// >= 27 days apart, so its full-date last rung is unique).
|
|
86
|
+
...dayLevels,
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
/** A marker label is unique on the axis; any other label repeats only after a marker. */
|
|
90
|
+
function holdsInvariant(labels: readonly Label[]): boolean {
|
|
91
|
+
const markers = new Set<string>()
|
|
92
|
+
const since = new Set<string>()
|
|
93
|
+
for (const { text, marker: isMarker } of labels) {
|
|
94
|
+
if (isMarker ? markers.has(text) : since.has(text)) return false
|
|
95
|
+
if (isMarker) {
|
|
96
|
+
markers.add(text)
|
|
97
|
+
since.clear()
|
|
98
|
+
} else since.add(text)
|
|
99
|
+
}
|
|
100
|
+
return true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The first level whose labels hold the invariant, else the last (see each ladder's last rung). */
|
|
104
|
+
function pickLabels(levels: readonly Level[], times: readonly number[]): Label[] {
|
|
105
|
+
let labels: Label[] = []
|
|
106
|
+
for (const level of levels) {
|
|
107
|
+
labels = level(times)
|
|
108
|
+
if (holdsInvariant(labels)) return labels
|
|
109
|
+
}
|
|
110
|
+
return labels
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The tick step: the smallest gap between ticks. One tick has no gap, so it takes the span its own
|
|
115
|
+
* instant implies: a midnight is a day, anything else is read as a clock time.
|
|
116
|
+
*/
|
|
117
|
+
function stepOf(times: readonly number[]): number {
|
|
118
|
+
if (times.length === 1) return isMidnight(times[0]!) ? DAY_MS : HOUR_MS
|
|
119
|
+
return times.reduce((min, t, i) => (i === 0 ? min : Math.min(min, t - times[i - 1]!)), Infinity)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A formatter for one tick set. A Date that is not among the ticks (a hover, a consumer reading
|
|
124
|
+
* the axis format) reads as plain `DD.MM`: its position in the set is undefined.
|
|
125
|
+
*/
|
|
126
|
+
export function dateTickFormat(ticks: readonly Date[]): (d: Date) => string {
|
|
127
|
+
const times = [...new Set(ticks.map((t) => t.getTime()))].toSorted((a, b) => a - b)
|
|
128
|
+
const step = stepOf(times)
|
|
129
|
+
const levels = step < DAY_MS ? subDayLevels : step < MONTH_STEP_MS ? dayLevels : monthLevels
|
|
130
|
+
const text = new Map(pickLabels(levels, times).map((l, i) => [times[i]!, l.text]))
|
|
131
|
+
return (d) => text.get(d.getTime()) ?? utcAxisDate(d)
|
|
132
|
+
}
|