basalt-ui 2.11.0 → 2.12.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/AGENTS.md +1 -1
- package/CHANGELOG.md +26 -0
- package/MIGRATING.md +33 -12
- package/README.md +2 -0
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +1 -1
- package/agent/skills/basalt-charts/SKILL.md +1 -1
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +1 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +7 -45
- package/dist/charts/MirroredBars.js +2 -2
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +21 -5
- package/dist/charts/labels.d.ts +34 -0
- package/dist/charts/labels.d.ts.map +1 -0
- package/dist/charts/labels.js +63 -0
- package/dist/charts/marks.d.ts +7 -0
- package/dist/charts/marks.d.ts.map +1 -1
- package/dist/charts/marks.js +22 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +5 -3
- package/dist/charts/ticks.d.ts +12 -0
- package/dist/charts/ticks.d.ts.map +1 -0
- package/dist/charts/ticks.js +42 -0
- package/dist/charts/types.d.ts +11 -3
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.d.ts +2 -3
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +71 -26
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -1
- package/dist/commands/command-stash.d.ts +15 -0
- package/dist/commands/command-stash.d.ts.map +1 -0
- package/dist/commands/command-stash.js +31 -0
- package/dist/commands/define-commands.d.ts +2 -3
- package/dist/commands/define-commands.d.ts.map +1 -1
- package/dist/commands/define-commands.js +9 -7
- package/dist/commands/define-overlays.d.ts +6 -12
- package/dist/commands/define-overlays.d.ts.map +1 -1
- package/dist/commands/define-overlays.js +28 -34
- package/dist/commands/projectors.js +1 -1
- package/dist/provider/hotkeys.d.ts +2 -6
- package/dist/provider/hotkeys.d.ts.map +1 -1
- package/dist/provider/hotkeys.js +10 -15
- package/dist/provider/index.d.ts +5 -3
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +12 -35
- package/dist/provider/modals-mount.d.ts +16 -0
- package/dist/provider/modals-mount.d.ts.map +1 -0
- package/dist/provider/modals-mount.js +42 -0
- package/dist/provider/notifier.d.ts +22 -0
- package/dist/provider/notifier.d.ts.map +1 -0
- package/dist/provider/notifier.js +36 -0
- package/dist/provider/route-transition.d.ts +1 -1
- package/dist/provider/route-transition.d.ts.map +1 -1
- package/dist/provider/route-transition.js +1 -1
- package/dist/provider/slots.d.ts +25 -0
- package/dist/provider/slots.d.ts.map +1 -0
- package/dist/provider/slots.js +29 -0
- package/dist/provider/spotlight-actions.d.ts +1 -1
- package/dist/provider/spotlight-actions.d.ts.map +1 -1
- package/dist/provider/spotlight-actions.js +2 -3
- package/dist/provider/spotlight-mount.d.ts +3 -0
- package/dist/provider/spotlight-mount.d.ts.map +1 -0
- package/dist/provider/spotlight-mount.js +26 -0
- package/dist/router-tanstack/nav-stash.d.ts +24 -0
- package/dist/router-tanstack/nav-stash.d.ts.map +1 -0
- package/dist/router-tanstack/nav-stash.js +23 -0
- package/dist/router-tanstack/nav.d.ts +5 -15
- package/dist/router-tanstack/nav.d.ts.map +1 -1
- package/dist/router-tanstack/nav.js +6 -16
- package/dist/router-tanstack/use-nav.js +1 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.js +1 -1
- package/llms.txt +4 -4
- package/package.json +2 -2
- package/src/charts/DualPanel.tsx +1 -0
- package/src/charts/Lines.tsx +11 -57
- package/src/charts/MirroredBars.tsx +2 -2
- package/src/charts/compile.ts +34 -6
- package/src/charts/labels.ts +118 -0
- package/src/charts/marks.ts +41 -0
- package/src/charts/scales.ts +9 -7
- package/src/charts/ticks.ts +61 -0
- package/src/charts/types.ts +11 -3
- package/src/cli/doctor-upgrade.ts +101 -35
- package/src/cli/index.ts +5 -3
- package/src/cli/sync.ts +2 -2
- package/src/commands/command-stash.ts +44 -0
- package/src/commands/define-commands.ts +10 -17
- package/src/commands/define-overlays.ts +40 -68
- package/src/commands/projectors.ts +1 -1
- package/src/provider/hotkeys.ts +14 -22
- package/src/provider/index.tsx +28 -52
- package/src/provider/modals-mount.tsx +66 -0
- package/src/provider/notifier.ts +52 -0
- package/src/provider/route-transition.ts +1 -1
- package/src/provider/slots.ts +59 -0
- package/src/provider/spotlight-actions.tsx +3 -4
- package/src/provider/spotlight-mount.tsx +33 -0
- package/src/router-tanstack/nav-stash.ts +41 -0
- package/src/router-tanstack/nav.ts +11 -31
- package/src/router-tanstack/use-nav.ts +1 -1
- package/src/surfaces.ts +1 -1
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* silently. Compile-verified. A config whose selling point is "typos are compile errors" cannot
|
|
10
10
|
* have a hole exactly where metadata typos live.
|
|
11
11
|
*
|
|
12
|
-
* No JSX and no Mantine in this module — `./router-tanstack` is a headless barrel by contract.
|
|
12
|
+
* No JSX and no Mantine in this module — `./router-tanstack` is a headless barrel by contract. The one
|
|
13
|
+
* exception is `defineNav`'s registration of the Spotlight mount (`../provider/slots`): nav entries
|
|
14
|
+
* feed the palette, and the mount is only reachable through this call.
|
|
13
15
|
*/
|
|
14
16
|
import type { RegisteredRouter } from '@tanstack/react-router';
|
|
15
17
|
import type { ReactNode } from 'react';
|
|
@@ -146,10 +148,6 @@ export declare function defineNav<const G extends ReadonlyArray<AnyNavGroup>, co
|
|
|
146
148
|
* literal whose text is the fix (V2-SPEC § 3).
|
|
147
149
|
*/
|
|
148
150
|
type RegisteredOr<T> = 0 extends 1 & RegisteredRouter['routeTree'] ? 'basalt: declare Register { router }' : T;
|
|
149
|
-
/** @internal */
|
|
150
|
-
export declare function getActiveNav(): {
|
|
151
|
-
groups: ReadonlyArray<AnyNavGroup>;
|
|
152
|
-
} | undefined;
|
|
153
151
|
/**
|
|
154
152
|
* The link options for one destination, by id. Spreadable into `<Link>`, `router.navigate()`
|
|
155
153
|
* and `redirect()`. This is what collapses a consumer's Spotlight commands and index redirect.
|
|
@@ -161,14 +159,6 @@ export declare function getActiveNav(): {
|
|
|
161
159
|
export declare function navTarget<const C extends {
|
|
162
160
|
groups: ReadonlyArray<AnyNavGroup>;
|
|
163
161
|
}, K extends NavItemId<C['groups']>>(config: C, id: K): NavIndex<C['groups']>[K];
|
|
164
|
-
|
|
165
|
-
export type FlatNavItem
|
|
166
|
-
groupId: string;
|
|
167
|
-
groupLabel: string;
|
|
168
|
-
};
|
|
169
|
-
/** Depth-first flatten, parent then children — the leaf every other surface reads. */
|
|
170
|
-
export declare function flattenNav(config: {
|
|
171
|
-
groups: ReadonlyArray<AnyNavGroup>;
|
|
172
|
-
}): FlatNavItem[];
|
|
173
|
-
export {};
|
|
162
|
+
export { flattenNav, getActiveNav } from './nav-stash.js';
|
|
163
|
+
export type { FlatNavItem } from './nav-stash.js';
|
|
174
164
|
//# sourceMappingURL=nav.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nav.d.ts","sourceRoot":"","sources":["../../src/router-tanstack/nav.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nav.d.ts","sourceRoot":"","sources":["../../src/router-tanstack/nav.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI9E,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CA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AG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAMxD;AAED;;;;GAIG;AACH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,gBAAgB,CAAC,WAAW,CAAC,GAC9D,qCAAqC,GACrC,CAAC,CAAA;AAaL;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,KAAK,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,CAAA;CAAE,EACtD,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAChC,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAM5C;AAED,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { registerSlot } from "../provider/slots.js";
|
|
2
|
+
import { setActiveNav } from "./nav-stash.js";
|
|
3
|
+
import { SpotlightMount } from "../provider/spotlight-mount.js";
|
|
1
4
|
function navGroup(meta, items) {
|
|
2
5
|
return { ...meta, items };
|
|
3
6
|
}
|
|
4
7
|
function defineNav(config) {
|
|
5
8
|
const nav = config;
|
|
6
|
-
|
|
9
|
+
setActiveNav(nav);
|
|
10
|
+
registerSlot("spotlight", SpotlightMount);
|
|
7
11
|
return nav;
|
|
8
12
|
}
|
|
9
|
-
let activeNav;
|
|
10
|
-
function getActiveNav() {
|
|
11
|
-
return activeNav;
|
|
12
|
-
}
|
|
13
13
|
function findById(items, id) {
|
|
14
14
|
for (const item of items) {
|
|
15
15
|
if (item.id === id) return item;
|
|
@@ -25,17 +25,7 @@ function navTarget(config, id) {
|
|
|
25
25
|
}
|
|
26
26
|
throw new Error(`navTarget: no nav item with id "${id}"`);
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
const out = [];
|
|
30
|
-
const walk = (items, groupId, groupLabel) => {
|
|
31
|
-
for (const item of items) {
|
|
32
|
-
out.push({ ...item, groupId, groupLabel });
|
|
33
|
-
if (item.children) walk(item.children, groupId, groupLabel);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
for (const g of config.groups) walk(g.items, g.id, g.label);
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
28
|
+
import { flattenNav, getActiveNav } from "./nav-stash.js";
|
|
39
29
|
export {
|
|
40
30
|
defineNav,
|
|
41
31
|
flattenNav,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement, forwardRef, useMemo } from "react";
|
|
2
2
|
import { Link, useMatchRoute, useRouterState } from "@tanstack/react-router";
|
|
3
|
-
import { flattenNav } from "./nav.js";
|
|
3
|
+
import { flattenNav } from "./nav-stash.js";
|
|
4
4
|
const OverriddenAnchor = forwardRef((props, ref) => {
|
|
5
5
|
const {
|
|
6
6
|
"aria-current": _routerCurrent,
|
package/dist/surfaces.d.ts
CHANGED
|
@@ -248,7 +248,7 @@ export declare const SURFACES: {
|
|
|
248
248
|
readonly skill: readonly ["basalt-app"];
|
|
249
249
|
readonly guardKinds: readonly [];
|
|
250
250
|
readonly pluginRules: readonly [];
|
|
251
|
-
readonly description: "defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Spotlight, Modals
|
|
251
|
+
readonly description: "defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Notifications; Spotlight mounts once defineNav/defineCommands ran, Modals once defineOverlays/overlays.confirm ran";
|
|
252
252
|
readonly optionalPeers: readonly ["@tanstack/react-hotkeys"];
|
|
253
253
|
readonly forbiddenImports: readonly [];
|
|
254
254
|
};
|
package/dist/surfaces.js
CHANGED
|
@@ -207,7 +207,7 @@ const SURFACES = {
|
|
|
207
207
|
skill: ["basalt-app"],
|
|
208
208
|
guardKinds: [],
|
|
209
209
|
pluginRules: [],
|
|
210
|
-
description: "defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Spotlight, Modals
|
|
210
|
+
description: "defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Notifications; Spotlight mounts once defineNav/defineCommands ran, Modals once defineOverlays/overlays.confirm ran",
|
|
211
211
|
optionalPeers: ["@tanstack/react-hotkeys"],
|
|
212
212
|
forbiddenImports: []
|
|
213
213
|
},
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.
|
|
1
|
+
# basalt-ui v2.12.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.12.0
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
|
@@ -535,7 +535,7 @@ Install: bun add @mantine/form@^9.7.0
|
|
|
535
535
|
|
|
536
536
|
## basalt-ui/commands
|
|
537
537
|
Import: import { ... } from 'basalt-ui/commands'
|
|
538
|
-
Description: defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Spotlight, Modals
|
|
538
|
+
Description: defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Notifications; Spotlight mounts once defineNav/defineCommands ran, Modals once defineOverlays/overlays.confirm ran
|
|
539
539
|
Layer: mantine-coupled
|
|
540
540
|
Rule: basalt-batteries
|
|
541
541
|
Signature: NotificationBell(props: NotificationBellProps): JSX.Element
|
|
@@ -688,7 +688,7 @@ Signature: useAgentThreadRuns(props: UseAgentThreadRunsArgs<TPart>): UseAgentThr
|
|
|
688
688
|
onError?: ((info: { readonly threadId: string; readonly error: unknow…
|
|
689
689
|
throttle?: number
|
|
690
690
|
telemetry?: Telemetry
|
|
691
|
-
Install: bun add ai@^7.0.137 @ai-sdk/provider@^4.0.26 motion
|
|
691
|
+
Install: bun add ai@^7.0.137 @ai-sdk/provider@^4.0.26 motion@^14.1.0
|
|
692
692
|
OptionalPeers: use-stick-to-bottom@^1.1.6, @tanstack/react-virtual@>=3.14.0 <4
|
|
693
693
|
|
|
694
694
|
## basalt-ui/content
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basalt-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"charts",
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"beautiful-mermaid": "^1.1.0",
|
|
190
190
|
"d3-scale": "4.0.2",
|
|
191
191
|
"dayjs": "^1.11.0",
|
|
192
|
-
"motion": "14.1.0",
|
|
192
|
+
"motion": "^14.1.0",
|
|
193
193
|
"react": "^19.3.0",
|
|
194
194
|
"react-dom": "^19.3.0",
|
|
195
195
|
"react-markdown": "^10.1.0",
|
package/src/charts/DualPanel.tsx
CHANGED
package/src/charts/Lines.tsx
CHANGED
|
@@ -5,35 +5,31 @@
|
|
|
5
5
|
* reference lines, `y2`, legend, cursor and tooltip are the rung's.
|
|
6
6
|
*
|
|
7
7
|
* At the wide class with ≤ 3 plotted lines and no `y2`, each line also carries an end label; the
|
|
8
|
-
* legend still names every series (and still toggles them).
|
|
8
|
+
* legend still names every series (and still toggles them). A label that would not fit between its
|
|
9
|
+
* last point and the plot's right edge ends at the point instead, above it. Before the engine has
|
|
10
|
+
* measured the plot (the server HTML, the first client frame) the room is read off the frame, which
|
|
11
|
+
* is wider by the axis gutters; the measured render corrects it.
|
|
9
12
|
*/
|
|
10
13
|
import { areaY } from '@tanstack/charts/area'
|
|
11
14
|
import { differenceY } from '@tanstack/charts/difference'
|
|
12
15
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
13
|
-
import { text } from '@tanstack/charts/text'
|
|
14
16
|
import { useCallback } from 'react'
|
|
15
17
|
import type { ReactElement } from 'react'
|
|
16
|
-
import { VX } from '../tokens'
|
|
17
18
|
import { CartesianRung } from './CartesianChart'
|
|
18
19
|
import { areaGradientId } from './compile'
|
|
19
20
|
import { chartCurve } from './curves'
|
|
20
|
-
import {
|
|
21
|
+
import { endLabelMarks, endLabelPlan } from './labels'
|
|
22
|
+
import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from './marks'
|
|
21
23
|
import { rowX } from './types'
|
|
22
24
|
import type {
|
|
23
25
|
CartesianChartProps,
|
|
24
26
|
ChartMarks,
|
|
25
|
-
ChartSeries,
|
|
26
27
|
ChartX,
|
|
27
28
|
PlotContext,
|
|
28
29
|
PlotRow,
|
|
29
30
|
Threshold,
|
|
30
31
|
} from './types'
|
|
31
32
|
|
|
32
|
-
const MAX_END_LABELS = 3
|
|
33
|
-
/** Below this vertical gap two end labels would collide; then none is drawn. */
|
|
34
|
-
const END_LABEL_MIN_GAP = 13
|
|
35
|
-
const END_LABEL_DX = 6
|
|
36
|
-
|
|
37
33
|
export type LinesProps<T, X extends ChartX = ChartX> = Omit<CartesianChartProps<T, X>, 'marks'> & {
|
|
38
34
|
/**
|
|
39
35
|
* Fills between the first visible series and a value, on one side of it. Unavailable on a string
|
|
@@ -44,46 +40,6 @@ export type LinesProps<T, X extends ChartX = ChartX> = Omit<CartesianChartProps<
|
|
|
44
40
|
|
|
45
41
|
const hasValue = <T, X extends ChartX>(r: PlotRow<T, X>): boolean => r.y !== null
|
|
46
42
|
|
|
47
|
-
function endLabels<T, X extends ChartX>(
|
|
48
|
-
plot: PlotContext<T, X>,
|
|
49
|
-
lines: readonly ChartSeries<T>[],
|
|
50
|
-
): ChartMarks {
|
|
51
|
-
if (plot.containerClass !== 'wide' || plot.y2 !== undefined) return []
|
|
52
|
-
if (lines.length === 0 || lines.length > MAX_END_LABELS) return []
|
|
53
|
-
const last = lines.flatMap((s) => {
|
|
54
|
-
const row = plot.rows(s.key).findLast(hasValue)
|
|
55
|
-
return row ? [{ s, row }] : []
|
|
56
|
-
})
|
|
57
|
-
// Collision check in pixels from the plot height: labels that would overlap are not drawn at all.
|
|
58
|
-
// No `y2` here (returned above), so every label reads the left domain.
|
|
59
|
-
const domain = plot.yDomain
|
|
60
|
-
const ys = last.map(({ row }) => {
|
|
61
|
-
if (row.y === null) return Number.NaN
|
|
62
|
-
return ((row.y - domain[0]) / (domain[1] - domain[0] || 1)) * plot.height
|
|
63
|
-
})
|
|
64
|
-
const sorted = ys.toSorted((a, b) => a - b)
|
|
65
|
-
if (
|
|
66
|
-
sorted.some(
|
|
67
|
-
(y, i) => Number.isNaN(y) || (i > 0 && y - (sorted[i - 1] as number) < END_LABEL_MIN_GAP),
|
|
68
|
-
)
|
|
69
|
-
)
|
|
70
|
-
return []
|
|
71
|
-
return last.map(({ s, row }) =>
|
|
72
|
-
decorative(
|
|
73
|
-
text([row], {
|
|
74
|
-
id: `${s.key}-end-label`,
|
|
75
|
-
x: rowX,
|
|
76
|
-
y: 'y',
|
|
77
|
-
text: () => s.label,
|
|
78
|
-
fill: s.color,
|
|
79
|
-
fontSize: VX.text.micro,
|
|
80
|
-
anchor: 'start',
|
|
81
|
-
dx: END_LABEL_DX,
|
|
82
|
-
}),
|
|
83
|
-
),
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
43
|
export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): ReactElement {
|
|
88
44
|
const { thresholds, ...rest } = props
|
|
89
45
|
const { series } = props
|
|
@@ -134,15 +90,13 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
|
|
|
134
90
|
)
|
|
135
91
|
}
|
|
136
92
|
for (const s of plot.visible) {
|
|
93
|
+
const yScale = yScaleOf(plot, s)
|
|
137
94
|
out.push(lineMark(plot, s))
|
|
138
|
-
out.push(...
|
|
95
|
+
out.push(...loneDots(s, drawnRows(plot, s), yScale, plot.highlighted))
|
|
96
|
+
out.push(...markersOf(s, plot.rows(s.key), yScale))
|
|
139
97
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
plot,
|
|
143
|
-
plotted.filter((s) => s.role !== 'reference'),
|
|
144
|
-
),
|
|
145
|
-
)
|
|
98
|
+
const labelled = plotted.filter((s) => s.role !== 'reference')
|
|
99
|
+
out.push(...endLabelMarks(endLabelPlan(plot, labelled)))
|
|
146
100
|
return out
|
|
147
101
|
},
|
|
148
102
|
[series, thresholds],
|
|
@@ -181,7 +181,7 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
181
181
|
foldConfig.merge,
|
|
182
182
|
)
|
|
183
183
|
: data
|
|
184
|
-
const model = xScaleFor<X>(drawn.map(x),
|
|
184
|
+
const model = xScaleFor<X>(drawn.map(x), 'flush')
|
|
185
185
|
const visible = visibleSeries(bars, hidden)
|
|
186
186
|
// A legend-hidden absent entry gives its share back to the measured bar, as `BandStrip`
|
|
187
187
|
// does; with no entry the share is always drawn, flat neutral.
|
|
@@ -196,7 +196,7 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
196
196
|
const downMax = paneMax(down, downSeries, drawn, downOn)
|
|
197
197
|
const bandWidth = 2 * model.halfStep * BAND_FILL
|
|
198
198
|
// One instance per pane: the engine sets a scale's range, and the panes' plots differ in width.
|
|
199
|
-
const bandScale = () => xScaleFor<X>(drawn.map(x),
|
|
199
|
+
const bandScale = () => xScaleFor<X>(drawn.map(x), 'flush').scale
|
|
200
200
|
|
|
201
201
|
const pane =
|
|
202
202
|
(
|
package/src/charts/compile.ts
CHANGED
|
@@ -29,6 +29,7 @@ import { VX } from '../tokens'
|
|
|
29
29
|
import type { ContainerClass } from '../tokens/size-classes'
|
|
30
30
|
import { cursorBinding, sourceOnlyFocus } from './cursor'
|
|
31
31
|
import { cursorDots } from './marks'
|
|
32
|
+
import { bucketTicks, strideEvery } from './ticks'
|
|
32
33
|
import { MAIN_PANE, plotAccess, plotContext } from './plot-context'
|
|
33
34
|
import type { PlotSizes } from './plot-context'
|
|
34
35
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
@@ -101,6 +102,13 @@ const LADDER = {
|
|
|
101
102
|
|
|
102
103
|
/** Space between the plot's left edge and a compact y label drawn inside it. */
|
|
103
104
|
const INSIDE_LABEL_DX = 4
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A tick within this share of the x domain from its start counts as on the left edge: half a
|
|
108
|
+
* `DD.MM` label is ~15 px, 4–5% of a compact plot. Round ticks rarely land on the domain start
|
|
109
|
+
* exactly, so an equality test would miss the common case.
|
|
110
|
+
*/
|
|
111
|
+
const LEFT_EDGE_SHARE = 0.05
|
|
104
112
|
const INSIDE_LABEL_DY = -6
|
|
105
113
|
|
|
106
114
|
/**
|
|
@@ -280,11 +288,21 @@ export function yGuide<T>(opts: {
|
|
|
280
288
|
}
|
|
281
289
|
}
|
|
282
290
|
|
|
291
|
+
/** The buckets of a band Date axis, or `null` for any other axis. */
|
|
292
|
+
function bucketDates<X extends ChartX>(model: XScaleModel<X>): readonly Date[] | null {
|
|
293
|
+
if (!model.band || model.kind !== 'date') return null
|
|
294
|
+
const dates = model.values.filter((v): v is X & Date => v instanceof Date)
|
|
295
|
+
return dates.length === model.values.length ? dates : null
|
|
296
|
+
}
|
|
297
|
+
|
|
283
298
|
function xTickPolicy<X extends ChartX>(
|
|
284
299
|
model: XScaleModel<X>,
|
|
285
300
|
xTicks: number | readonly X[],
|
|
286
301
|
): { values: readonly ChartValue[] } | { count: number } {
|
|
287
302
|
if (typeof xTicks === 'object') return { values: xTicks }
|
|
303
|
+
const buckets = typeof xTicks === 'number' && Number.isFinite(xTicks) ? bucketDates(model) : null
|
|
304
|
+
if (buckets !== null && typeof xTicks === 'number')
|
|
305
|
+
return { values: bucketTicks(buckets, xTicks) }
|
|
288
306
|
if (model.band || model.kind === 'string') return { values: model.values }
|
|
289
307
|
if (model.kind === 'date' && model.extent)
|
|
290
308
|
return {
|
|
@@ -299,8 +317,7 @@ function xTickPolicy<X extends ChartX>(
|
|
|
299
317
|
* the ones that collide, so a short-label grid (18 hour columns) would otherwise draw all of them.
|
|
300
318
|
*/
|
|
301
319
|
export function strideTicks<V>(values: readonly V[], cls: ContainerClass): V[] {
|
|
302
|
-
|
|
303
|
-
return values.filter((_, i) => i % stride === 0)
|
|
320
|
+
return strideEvery(values, LADDER[cls].xTicks)
|
|
304
321
|
}
|
|
305
322
|
|
|
306
323
|
export function xGuide<X extends ChartX>(opts: {
|
|
@@ -315,6 +332,11 @@ export function xGuide<X extends ChartX>(opts: {
|
|
|
315
332
|
const ladder = LADDER[cls]
|
|
316
333
|
const inside = labelsInside(cls, height)
|
|
317
334
|
const ticks = xTickPolicy(model, xTicks ?? ladder.xTicks)
|
|
335
|
+
// A continuous scale's domain start and span; a band scale pads its first slot, so none applies.
|
|
336
|
+
const [leftEdgeX, spanX] =
|
|
337
|
+
!model.band && model.extent
|
|
338
|
+
? [model.extent[0], model.extent[1] - model.extent[0]]
|
|
339
|
+
: [Number.NaN, Number.NaN]
|
|
318
340
|
return {
|
|
319
341
|
axis: {
|
|
320
342
|
line: AXIS_LINE,
|
|
@@ -323,10 +345,15 @@ export function xGuide<X extends ChartX>(opts: {
|
|
|
323
345
|
fontSize: ladder.font,
|
|
324
346
|
opacity: 1,
|
|
325
347
|
thin: true,
|
|
326
|
-
// A
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
})
|
|
348
|
+
// A label centred on a tick near the plot's left edge hangs left of it, under the gutter's
|
|
349
|
+
// lowest y label (outside labels) or off the plot (inside labels, left margin locked to
|
|
350
|
+
// zero): start-anchor it. `+value` is a Date's timestamp, or the number itself.
|
|
351
|
+
anchor: ({ index, value }: { index: number; value: ChartValue }) => {
|
|
352
|
+
const pinnedFirst = inside && index === 0
|
|
353
|
+
const share = (+value - leftEdgeX) / spanX
|
|
354
|
+
const onLeftEdge = share >= 0 && share <= LEFT_EDGE_SHARE
|
|
355
|
+
return pinnedFirst || onLeftEdge ? ('start' as const) : undefined
|
|
356
|
+
},
|
|
330
357
|
},
|
|
331
358
|
},
|
|
332
359
|
}
|
|
@@ -857,6 +884,7 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
857
884
|
width,
|
|
858
885
|
height,
|
|
859
886
|
data: input.data,
|
|
887
|
+
xFraction: model.fraction,
|
|
860
888
|
y2: axes.right ? 'y2' : undefined,
|
|
861
889
|
yDomain: axes.left.domain,
|
|
862
890
|
y2Domain: axes.right?.domain,
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Lines`' end labels: which series carry one, and on which side of its last point it sits. Pure,
|
|
3
|
+
* so the rules are tested without an engine; `endLabelMarks` is the only part that draws.
|
|
4
|
+
*/
|
|
5
|
+
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
6
|
+
import { text } from '@tanstack/charts/text'
|
|
7
|
+
import { VX } from '../tokens'
|
|
8
|
+
import { rowX } from './types'
|
|
9
|
+
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types'
|
|
10
|
+
|
|
11
|
+
const MAX_END_LABELS = 3
|
|
12
|
+
/** Below this vertical gap two end labels would collide; then none is drawn. */
|
|
13
|
+
const END_LABEL_MIN_GAP = 13
|
|
14
|
+
const END_LABEL_DX = 6
|
|
15
|
+
/**
|
|
16
|
+
* A glyph's advance as a share of the font size, for the room check. 0.85 covers proportional
|
|
17
|
+
* Latin text, capitals included, in the shipped faces; a run of the widest capitals (`W`, `M` are
|
|
18
|
+
* ~1 em) or a much wider face can still exceed it, so the estimate errs towards flipping: a label
|
|
19
|
+
* that did not need to flip sits above its point, one that needed to and did not is cut.
|
|
20
|
+
*/
|
|
21
|
+
const END_LABEL_GLYPH_EM = 0.85
|
|
22
|
+
/** A label flipped inside the plot sits this far above its point. */
|
|
23
|
+
const END_LABEL_FLIP_DY = -9
|
|
24
|
+
|
|
25
|
+
export type EndLabelAnchor = 'start' | 'end'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The side of its point an end label takes: `start` (right of the point) unless the point leaves
|
|
29
|
+
* less room than the label needs. `fraction` is the point's x as a share of the plot width,
|
|
30
|
+
* `plotWidth` the plot in px. Before the engine has measured the plot, `plotWidth` is the frame's,
|
|
31
|
+
* which is wider than the plot by the axis gutters: the first frame can keep `start` for a label
|
|
32
|
+
* the measured frame then flips.
|
|
33
|
+
*/
|
|
34
|
+
export function endLabelAnchor(opts: {
|
|
35
|
+
fraction: number
|
|
36
|
+
plotWidth: number
|
|
37
|
+
label: string
|
|
38
|
+
fontSize: number
|
|
39
|
+
}): EndLabelAnchor {
|
|
40
|
+
const { fraction, plotWidth, label, fontSize } = opts
|
|
41
|
+
const room = (1 - fraction) * plotWidth
|
|
42
|
+
return room >= label.length * fontSize * END_LABEL_GLYPH_EM + END_LABEL_DX ? 'start' : 'end'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type EndLabel<T, X extends ChartX> = {
|
|
46
|
+
series: ChartSeries<T>
|
|
47
|
+
row: PlotRow<T, X>
|
|
48
|
+
anchor: EndLabelAnchor
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type LastPoint<T, X extends ChartX> = {
|
|
52
|
+
series: ChartSeries<T>
|
|
53
|
+
row: PlotRow<T, X>
|
|
54
|
+
y: number
|
|
55
|
+
fraction: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The end labels to draw: none off the wide class, with a right axis, with more than
|
|
60
|
+
* {@link MAX_END_LABELS} lines, or when two would collide in pixels (against the plot's height).
|
|
61
|
+
* A series whose last point the plot's own x scale cannot place, or places outside the plot
|
|
62
|
+
* (`plot.xFraction` outside [0, 1]: clipped by a narrower `xDomain`), has no label.
|
|
63
|
+
*/
|
|
64
|
+
export function endLabelPlan<T, X extends ChartX>(
|
|
65
|
+
plot: PlotContext<T, X>,
|
|
66
|
+
lines: readonly ChartSeries<T>[],
|
|
67
|
+
): EndLabel<T, X>[] {
|
|
68
|
+
if (plot.containerClass !== 'wide' || plot.y2 !== undefined) return []
|
|
69
|
+
if (lines.length === 0 || lines.length > MAX_END_LABELS) return []
|
|
70
|
+
const last = lines.flatMap((series): LastPoint<T, X>[] => {
|
|
71
|
+
const row = plot.rows(series.key).findLast((r) => r.y !== null)
|
|
72
|
+
if (row === undefined || row.y === null) return []
|
|
73
|
+
const fraction = plot.xFraction(row.x)
|
|
74
|
+
if (fraction === null || fraction < 0 || fraction > 1) return []
|
|
75
|
+
return [{ series, row, y: row.y, fraction }]
|
|
76
|
+
})
|
|
77
|
+
// Collision check in pixels from the plot height: labels that would overlap are not drawn at all.
|
|
78
|
+
// No `y2` here (returned above), so every label reads the left domain.
|
|
79
|
+
const [lo, hi] = plot.yDomain
|
|
80
|
+
const ys = last
|
|
81
|
+
.map(({ y }) => ((y - lo) / (hi - lo || 1)) * plot.plotHeight)
|
|
82
|
+
.toSorted((a, b) => a - b)
|
|
83
|
+
if (ys.some((y, i) => i > 0 && y - (ys[i - 1] as number) < END_LABEL_MIN_GAP)) return []
|
|
84
|
+
return last.map(({ series, row, fraction }) => ({
|
|
85
|
+
series,
|
|
86
|
+
row,
|
|
87
|
+
anchor: endLabelAnchor({
|
|
88
|
+
fraction,
|
|
89
|
+
plotWidth: plot.plotWidth,
|
|
90
|
+
label: series.label,
|
|
91
|
+
fontSize: VX.text.micro,
|
|
92
|
+
}),
|
|
93
|
+
}))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The offset of a label from its point: right of it, level; or left of it and above. */
|
|
97
|
+
export function endLabelOffset(anchor: EndLabelAnchor): { dx: number; dy: number } {
|
|
98
|
+
return anchor === 'end'
|
|
99
|
+
? { dx: -END_LABEL_DX, dy: END_LABEL_FLIP_DY }
|
|
100
|
+
: { dx: END_LABEL_DX, dy: 0 }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>[]): ChartMarks {
|
|
104
|
+
return plan.map(({ series, row, anchor }) =>
|
|
105
|
+
decorative(
|
|
106
|
+
text([row], {
|
|
107
|
+
id: `${series.key}-end-label`,
|
|
108
|
+
x: rowX,
|
|
109
|
+
y: 'y',
|
|
110
|
+
text: () => series.label,
|
|
111
|
+
fill: series.color,
|
|
112
|
+
fontSize: VX.text.micro,
|
|
113
|
+
anchor,
|
|
114
|
+
...endLabelOffset(anchor),
|
|
115
|
+
}),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
}
|
package/src/charts/marks.ts
CHANGED
|
@@ -58,6 +58,47 @@ export function lineMark<T, X extends ChartX>(
|
|
|
58
58
|
})
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
const isFinitePoint = <T, X extends ChartX>(r: PlotRow<T, X> | undefined): boolean =>
|
|
62
|
+
r !== undefined && r.y !== null && Number.isFinite(r.y)
|
|
63
|
+
|
|
64
|
+
/** A lone dot's radius as a multiple of the series' stroke width, so it reads as the line's end cap. */
|
|
65
|
+
const LONE_DOT_STROKE_FACTOR = 1.25
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The dot for a point a line cannot draw: a finite value with no finite neighbour in `drawn` (the
|
|
69
|
+
* rows the line is drawn through: a one-point window, or a value between nulls). A path of one
|
|
70
|
+
* point has no length, so without this the series is invisible. One mark per series. A point the
|
|
71
|
+
* series' own `getMarker` already marks is left to it.
|
|
72
|
+
*/
|
|
73
|
+
export function loneDots<T, X extends ChartX>(
|
|
74
|
+
s: ChartSeries<T>,
|
|
75
|
+
drawn: readonly PlotRow<T, X>[],
|
|
76
|
+
yScale: 'y2' | undefined,
|
|
77
|
+
highlighted: string | null,
|
|
78
|
+
): ChartMarks {
|
|
79
|
+
const lone = drawn.filter(
|
|
80
|
+
(r, i) =>
|
|
81
|
+
isFinitePoint(r) &&
|
|
82
|
+
!isFinitePoint(drawn[i - 1]) &&
|
|
83
|
+
!isFinitePoint(drawn[i + 1]) &&
|
|
84
|
+
!s.getMarker?.(r.datum),
|
|
85
|
+
)
|
|
86
|
+
if (lone.length === 0) return []
|
|
87
|
+
return [
|
|
88
|
+
decorative(
|
|
89
|
+
dot(lone, {
|
|
90
|
+
id: `${s.key}-lone`,
|
|
91
|
+
x: rowX,
|
|
92
|
+
y: 'y',
|
|
93
|
+
r: Math.max(VX.dotR - 1, (s.strokeWidth ?? LINE_STROKE_WIDTH) * LONE_DOT_STROKE_FACTOR),
|
|
94
|
+
fill: s.color,
|
|
95
|
+
fillOpacity: (s.strokeOpacity ?? 1) * emphasis(highlighted, s),
|
|
96
|
+
...(yScale !== undefined && { yScale }),
|
|
97
|
+
}),
|
|
98
|
+
),
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
|
|
61
102
|
type MarkerGroup<T, X extends ChartX> = {
|
|
62
103
|
color: string
|
|
63
104
|
opacity: number
|
package/src/charts/scales.ts
CHANGED
|
@@ -158,7 +158,9 @@ function explicitDomain(xDomain: readonly [ChartX, ChartX] | undefined): [number
|
|
|
158
158
|
|
|
159
159
|
export function xScaleFor<X extends ChartX>(
|
|
160
160
|
raw: readonly X[],
|
|
161
|
-
band
|
|
161
|
+
/** `'flush'`: a band scale with no outer padding, so the first and last band meet the plot's
|
|
162
|
+
* edges (`MirroredBars`); `true` pads half a gap-and-a-bit at each end, as `Bars` does. */
|
|
163
|
+
band: boolean | 'flush',
|
|
162
164
|
/** Continuous scales only: the explicit `[min, max]` that replaces the data's own extent. */
|
|
163
165
|
xDomain?: readonly [X, X],
|
|
164
166
|
): XScaleModel<X> {
|
|
@@ -171,11 +173,11 @@ export function xScaleFor<X extends ChartX>(
|
|
|
171
173
|
const keys = values as X[]
|
|
172
174
|
const index = new Map(keys.map((k, i) => [keyOf(k), i] as const))
|
|
173
175
|
if (band) {
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
const outer = band === 'flush' ? 0 : BAND_PADDING_OUTER
|
|
177
|
+
// Total width in steps; no data has none, so a step of 1 (a lone flush band spans 0.8 of one).
|
|
178
|
+
const steps = n - BAND_PADDING_INNER + 2 * outer
|
|
179
|
+
const step = 1 / (steps > 0 ? steps : 1)
|
|
180
|
+
const scale = scaleBand<X>().domain(keys).paddingInner(BAND_PADDING_INNER).paddingOuter(outer)
|
|
179
181
|
return {
|
|
180
182
|
kind,
|
|
181
183
|
band: true,
|
|
@@ -186,7 +188,7 @@ export function xScaleFor<X extends ChartX>(
|
|
|
186
188
|
fraction: (x) => {
|
|
187
189
|
const i = index.get(keyOf(x))
|
|
188
190
|
if (i === undefined) return null
|
|
189
|
-
return step * (
|
|
191
|
+
return step * (outer + i + (1 - BAND_PADDING_INNER) / 2)
|
|
190
192
|
},
|
|
191
193
|
}
|
|
192
194
|
}
|