basalt-ui 2.11.0 → 2.11.1
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 +10 -0
- package/MIGRATING.md +21 -12
- 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/llms.txt +2 -2
- package/package.json +1 -1
- 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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [2.11.1](https://github.com/jkrumm/basalt-ui/compare/v2.11.0...v2.11.1) (2026-10-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* end labels read the plot's own x model and plot height ([81780be](https://github.com/jkrumm/basalt-ui/commit/81780be14d37875c445f6f432439b8bb93302f03))
|
|
7
|
+
* end-label room, bucket ticks and lone dots per review ([6011eb6](https://github.com/jkrumm/basalt-ui/commit/6011eb65f304e0de6e6893c5a68a30af69e513ca))
|
|
8
|
+
* lone points, end labels and axis ticks render cleanly ([95f898f](https://github.com/jkrumm/basalt-ui/commit/95f898f16927e209daa11ee2e587267103031b27))
|
|
9
|
+
* mirrored bars reach both plot edges ([d8d6d4a](https://github.com/jkrumm/basalt-ui/commit/d8d6d4a8ddd3a3689b50b8f2213fee9683cf56a4))
|
|
10
|
+
|
|
1
11
|
# [2.11.0](https://github.com/jkrumm/basalt-ui/compare/v2.10.0...v2.11.0) (2026-10-15)
|
|
2
12
|
|
|
3
13
|
|
package/MIGRATING.md
CHANGED
|
@@ -66,18 +66,18 @@ There is one row per SURFACE, not per export, and a surface earns a row once any
|
|
|
66
66
|
shipped lefthook preset both changed in 1.30.0 with no row that owned them — which is how a
|
|
67
67
|
consumer read this index, found nothing, and diffed a KPI row that had silently gone 4-up → 2-up.
|
|
68
68
|
|
|
69
|
-
| Surface | 1.27.0 | 1.28.0 | 1.29.0 | 1.30.0 | 1.30.1 | 1.30.2 | 1.31.0 | 1.32.0 | 1.32.1 | 1.33.0 | 1.34.0 | 1.34.1 | 1.35.0 | 1.36.0 | 1.36.1 | 1.37.0 | 1.37.1 | 1.38.0 | 1.38.1 | 1.39.0 | 1.40.0 | 1.40.1 | 1.40.2 | 1.40.3 | 1.41.0 | 2.0.0 | 2.0.1 | 2.0.2 | 2.0.3 | 2.0.4 | 2.0.5 | 2.1.0 | 2.2.0 | 2.3.0 | 2.4.0 | 2.5.0 | 2.6.0 | 2.6.1 | 2.7.0 | 2.7.1 | 2.7.2 | 2.7.3 | 2.8.0 | 2.8.1 | 2.9.0 | 2.9.1 | 2.10.0 | 2.11.0 | Unreleased |
|
|
70
|
-
| ----------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------- | ------ | ------ | -------------------------------------------------------------------------------------------- | ------ | ------ | ------ | ------ | ------ | ----------------------------------------------- | ------ | ------ | ------ | ------ | ------------------------------------------------------------ | ---------- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
71
|
-
| **tokens** (`./tokens`) | — | `--vx-divider` → `rgba()` on both schemes (§ Shell) | `--vx-space-touch-target` added (§ Additions) | eight spacing numbers (§ Chrome) | — | — | `--vx-hit` replaces the touch vars; `SIZE_CLASSES` (§ 1.31.0) | — | `SIZE_CLASSES`/`CONTAINER_CLASSES` actually exported (§ Fixes) | `CONTAINER_GRID_BREAKPOINTS`; `raw-breakpoint` trusts it (§ 1.33.0) | `CONTAINER_KEYS` (§ 1.34.0) | — | — | — | — | — | — | — | | `appShellInset` 20 → 16 (§ 1.38.1) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — |
|
|
72
|
-
| **charts** (`./charts`) | — | phone tier, `curve`, formatters, `state`, log axis (§ preamble) | `ChartState.empty: string`, `AxisBottomNumeric` (§ Additions) | responsive `height`, `legend.maxRows` (§ Charts) | `height` reaches the kinds; `maxRows` beats the `fill` fit (§ Charts) | — | container-class tier + `height` keys (§ 1.31.0) | — | `ResponsiveChartHeight` `sm` → key (§ Container recipes) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | `BandSpan.absentFraction` + `absentState` (§ 2.8.0) | — | — | — | — | — | — |
|
|
73
|
-
| **shell** (`.`) | — | scrollport, region seams, **the brand left the sidebar** (§§ scrollport, brand, Shell) | `PageTitle`, `BasaltDevDock`, `useBreakpoint` (§ Additions) | More popover, aside pill, the responsive gutter, `useBasaltSpacing` (§ Chrome) | — | — | `theme.breakpoints` derived, `useSizeClass`, `data-basalt-host`, `useBreakpoint` on notice (§ 1.31.0) | `useBreakpoint` removal → 1.33.0; `useSizeClass` is shell-only (§ 1.32.0) | shell-less `shell/` gutter, `AppShell` breakpoints, `useSizeClass` for overlays (§§ Shell-less, `useSizeClass`) | — | `useBreakpoint` removed (§ 1.34.0) | — | — | `useCoarsePointer()` (§ `useCoarsePointer()`) | — | — | — | — | | content gutter 16, block 8 from `sm` (§ 1.38.1) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | `BasaltProvider` embedded mode, `spotlight` (§ 2.8.0) | — | — | — | — | — | — |
|
|
74
|
-
| **controls** (`./controls`) | `NumberFilter`, `field.number` (§ Controls) | sheet renders panel rows; `PanelRow`, `SliderControl` (§ `basalt-ui/controls`) | — | — | — | — | — | — | — | `NumberFilter clearable`; `createSearchStore` `resets` (§ State and controls) | — | — | — | `FormSection`/`FormRow`/`FormGroup`/`FormActions` move here (§ The form layout moves) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
|
|
75
|
-
| **forms** (`./forms`) | — | `field` → `inputProps`, **`inputProps` drops `key`**, the layout tier (§ `inputProps`) | `field` DELETED — and the `--fix` recipe no longer works (§ Consolidation) | — | — | — | — | — | `FormGroup` row no longer stretches (§ Fixes) | — | — | — | — | the layout + `useForm`/`schemaResolver` deprecated, removed 1.37.0 (§ The form layout moves) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — |
|
|
76
|
-
| **data** (`./data/table`) | — | root is a `<div>`, row selection, `getItemKey` required (§ `basalt-ui/data`) | `./data` + `./query` + `./connectivity` dropped (§ Consolidation) | — | — | — | — | — | `renderCard` documented (§ `renderCard`) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
|
|
77
|
-
| **dashboard** (`.`) | `StatCard`: `unit`, `breakdown`, delta format (§ `StatCard`) | `StatGroup`, `WidgetGrid`, query-aware `StatCard` — additive | — | **the column law keys on the CONTAINER; `cols={4}` is 2-up at `sm`** (§ Dashboard) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — |
|
|
78
|
-
| **toolchain** (`./configs/*`) | — | — | the shipped lefthook preset's `check-theme` BROKE — the CLI resolver stopped ascending (§ CLI) | the preset's default bin, and the `root:` recipe (§ Toolchain) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
|
|
79
|
-
| **CLI** (`basalt-ui`) | — | — | **resolver stops relocating; `doctor` loses 6 of 10 checks** (§ CLI) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | the managed block moves `CLAUDE.md` → `AGENTS.md` (§ 1.41.0) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | `doctor`: CSS + forced dropped subpaths, `oxlint-floor`, Start wiring (§ 2.8.0) | — | § 1.x compatibility layer removed | — | — | — | — |
|
|
80
|
-
| **guards** | five rules → `error` (§ Guards) | six new ids at `warn` (§ preamble) | `query-dual-import` retired in 1.29.1 (§ Guards) | four rules → `error` (§ Guards) | — | — | — | `raw-breakpoint`: the container-grid answer, `error` at 1.33.0 (§ 1.32.0) | `FormRow`/`FormGroup` homes in both lanes; `basalt-main` dropped (§ Fixes) | C1 + breakpoint pairs → `error`; `unknown-vx-token` `warn` (§ Guards) | — | — | — | `unknown-vx-token` → `error`; the token factories throw (§ Guards) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — |
|
|
69
|
+
| Surface | 1.27.0 | 1.28.0 | 1.29.0 | 1.30.0 | 1.30.1 | 1.30.2 | 1.31.0 | 1.32.0 | 1.32.1 | 1.33.0 | 1.34.0 | 1.34.1 | 1.35.0 | 1.36.0 | 1.36.1 | 1.37.0 | 1.37.1 | 1.38.0 | 1.38.1 | 1.39.0 | 1.40.0 | 1.40.1 | 1.40.2 | 1.40.3 | 1.41.0 | 2.0.0 | 2.0.1 | 2.0.2 | 2.0.3 | 2.0.4 | 2.0.5 | 2.1.0 | 2.2.0 | 2.3.0 | 2.4.0 | 2.5.0 | 2.6.0 | 2.6.1 | 2.7.0 | 2.7.1 | 2.7.2 | 2.7.3 | 2.8.0 | 2.8.1 | 2.9.0 | 2.9.1 | 2.10.0 | 2.11.0 | 2.11.1 | Unreleased |
|
|
70
|
+
| ----------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------- | ------ | ------ | -------------------------------------------------------------------------------------------- | ------ | ------ | ------ | ------ | ------ | ----------------------------------------------- | ------ | ------ | ------ | ------ | ------------------------------------------------------------ | ---------- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
71
|
+
| **tokens** (`./tokens`) | — | `--vx-divider` → `rgba()` on both schemes (§ Shell) | `--vx-space-touch-target` added (§ Additions) | eight spacing numbers (§ Chrome) | — | — | `--vx-hit` replaces the touch vars; `SIZE_CLASSES` (§ 1.31.0) | — | `SIZE_CLASSES`/`CONTAINER_CLASSES` actually exported (§ Fixes) | `CONTAINER_GRID_BREAKPOINTS`; `raw-breakpoint` trusts it (§ 1.33.0) | `CONTAINER_KEYS` (§ 1.34.0) | — | — | — | — | — | — | — | | `appShellInset` 20 → 16 (§ 1.38.1) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — | — |
|
|
72
|
+
| **charts** (`./charts`) | — | phone tier, `curve`, formatters, `state`, log axis (§ preamble) | `ChartState.empty: string`, `AxisBottomNumeric` (§ Additions) | responsive `height`, `legend.maxRows` (§ Charts) | `height` reaches the kinds; `maxRows` beats the `fill` fit (§ Charts) | — | container-class tier + `height` keys (§ 1.31.0) | — | `ResponsiveChartHeight` `sm` → key (§ Container recipes) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | `BandSpan.absentFraction` + `absentState` (§ 2.8.0) | — | — | — | — | — | — | — |
|
|
73
|
+
| **shell** (`.`) | — | scrollport, region seams, **the brand left the sidebar** (§§ scrollport, brand, Shell) | `PageTitle`, `BasaltDevDock`, `useBreakpoint` (§ Additions) | More popover, aside pill, the responsive gutter, `useBasaltSpacing` (§ Chrome) | — | — | `theme.breakpoints` derived, `useSizeClass`, `data-basalt-host`, `useBreakpoint` on notice (§ 1.31.0) | `useBreakpoint` removal → 1.33.0; `useSizeClass` is shell-only (§ 1.32.0) | shell-less `shell/` gutter, `AppShell` breakpoints, `useSizeClass` for overlays (§§ Shell-less, `useSizeClass`) | — | `useBreakpoint` removed (§ 1.34.0) | — | — | `useCoarsePointer()` (§ `useCoarsePointer()`) | — | — | — | — | | content gutter 16, block 8 from `sm` (§ 1.38.1) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | `BasaltProvider` embedded mode, `spotlight` (§ 2.8.0) | — | — | — | — | — | — | — |
|
|
74
|
+
| **controls** (`./controls`) | `NumberFilter`, `field.number` (§ Controls) | sheet renders panel rows; `PanelRow`, `SliderControl` (§ `basalt-ui/controls`) | — | — | — | — | — | — | — | `NumberFilter clearable`; `createSearchStore` `resets` (§ State and controls) | — | — | — | `FormSection`/`FormRow`/`FormGroup`/`FormActions` move here (§ The form layout moves) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
|
|
75
|
+
| **forms** (`./forms`) | — | `field` → `inputProps`, **`inputProps` drops `key`**, the layout tier (§ `inputProps`) | `field` DELETED — and the `--fix` recipe no longer works (§ Consolidation) | — | — | — | — | — | `FormGroup` row no longer stretches (§ Fixes) | — | — | — | — | the layout + `useForm`/`schemaResolver` deprecated, removed 1.37.0 (§ The form layout moves) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — | — |
|
|
76
|
+
| **data** (`./data/table`) | — | root is a `<div>`, row selection, `getItemKey` required (§ `basalt-ui/data`) | `./data` + `./query` + `./connectivity` dropped (§ Consolidation) | — | — | — | — | — | `renderCard` documented (§ `renderCard`) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
|
|
77
|
+
| **dashboard** (`.`) | `StatCard`: `unit`, `breakdown`, delta format (§ `StatCard`) | `StatGroup`, `WidgetGrid`, query-aware `StatCard` — additive | — | **the column law keys on the CONTAINER; `cols={4}` is 2-up at `sm`** (§ Dashboard) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — | — |
|
|
78
|
+
| **toolchain** (`./configs/*`) | — | — | the shipped lefthook preset's `check-theme` BROKE — the CLI resolver stopped ascending (§ CLI) | the preset's default bin, and the `root:` recipe (§ Toolchain) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
|
|
79
|
+
| **CLI** (`basalt-ui`) | — | — | **resolver stops relocating; `doctor` loses 6 of 10 checks** (§ CLI) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | the managed block moves `CLAUDE.md` → `AGENTS.md` (§ 1.41.0) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | `doctor`: CSS + forced dropped subpaths, `oxlint-floor`, Start wiring (§ 2.8.0) | — | § 1.x compatibility layer removed | — | — | — | — | — |
|
|
80
|
+
| **guards** | five rules → `error` (§ Guards) | six new ids at `warn` (§ preamble) | `query-dual-import` retired in 1.29.1 (§ Guards) | four rules → `error` (§ Guards) | — | — | — | `raw-breakpoint`: the container-grid answer, `error` at 1.33.0 (§ 1.32.0) | `FormRow`/`FormGroup` homes in both lanes; `basalt-main` dropped (§ Fixes) | C1 + breakpoint pairs → `error`; `unknown-vx-token` `warn` (§ Guards) | — | — | — | `unknown-vx-token` → `error`; the token factories throw (§ Guards) | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | § 1.x compatibility layer removed | — | — | — | — | — |
|
|
81
81
|
|
|
82
82
|
---
|
|
83
83
|
|
|
@@ -1046,6 +1046,15 @@ The `basalt-ui/router-tanstack` subpath is **removed** in 2.x, not moved: an imp
|
|
|
1046
1046
|
_Nothing yet. Author the next section under this heading as `## Unreleased — <title>`; the
|
|
1047
1047
|
release renames it and opens a new one here._
|
|
1048
1048
|
|
|
1049
|
+
## 2.11.1 — lone points, end labels and axis ticks render cleanly
|
|
1050
|
+
|
|
1051
|
+
- **`Lines` draws a lone point.** A series with one finite value (a one-point window, or a value between nulls) drew nothing: a path of one point has no length. It now draws a dot in the series colour, at every isolated finite row (`gaps: 'connect'` bridges the nulls, so only a series with a single finite row is lone there). A point the series' own `getMarker` marks is not doubled. Delete any `getMarker` you added to make a single run visible. **Opt-out: none.**
|
|
1052
|
+
- **`Lines` end labels never clip.** At the `wide` class a label whose room between its last point and the plot's right edge is too small (a last point on the edge cut "Download" to "Downloa") now ends at the point and sits above it. The room is read through the plot's own x mapping (`xDomain`, else the extent of every datum) against an estimated label width (0.85 em per glyph: it errs towards flipping, so a label of the widest capitals can still run long); a string x has no continuous position and keeps the default. Before the engine has measured the plot (the server HTML, the first client frame) the room is taken from the frame, which is wider by the axis gutters, so a label can start on its first frame and flip on the measured one. A label with room is unchanged. **Opt-out: none.**
|
|
1053
|
+
- **Every band Date axis now gets bucket-snapped ticks by default.** `BandStrip`, `MirroredBars`, `Bars` and any other band x of Dates labelled every bucket and let the engine thin the collisions, which left an uneven subset that nearly touched ("18:13 18:17 18:21"). Ticks are now the time scale's own round instants, each snapped to the bucket it falls in (so a label may read 18:13, the bucket nearest 18:15); `xTicks` as a number sets the count. A string band x is unchanged. **Opt-out: pass `xTicks` as an array of the bucket dates to label.**
|
|
1054
|
+
- **The first x tick label no longer sits on the y label.** A tick within 5% of the x domain's start (the first tick of a series whose domain starts on a round instant, or a round tick just inside one that does not) is start-anchored, so at the compact class (gutter y labels) its label stops under the lowest y label instead of centring on the plot's left edge. Later ticks stay centred. **Opt-out: none.**
|
|
1055
|
+
- **`MirroredBars` bars reach both plot edges.** The panes used the padded band scale `Bars` uses (0.1 of a step of outer padding), so the last bar ended a tenth of a step short of the right edge and the first started that far in — 1.2 px at 30 daily buckets on a 390 px phone (0.8 px at 168 hourly buckets on 1440). Bars now sit flush: the first bar's left and the last bar's right edge are the plot's. The gap between bars is unchanged. `BandStrip` already filled the plot (probed at both widths). **Opt-out: none.**
|
|
1056
|
+
- **Docs: only the CURSOR dot reads `getMarker` on consumer `marks`.** The 2.11.0 line "a `CartesianChart` with consumer `marks` can colour the dot" means the cursor dot of a `cursorValue` series, and only its `color`. Always-on per-point markers are `Lines`-only: on consumer `marks`, `getMarker` without `cursorValue` is ignored, so draw a persistent dot in `marks` yourself. The `getMarker` JSDoc and the `basalt-charts` skill say so now.
|
|
1057
|
+
|
|
1049
1058
|
## 2.11.0 — Heatmap cells carry a state, a shared x domain, a self-pooling sparkline, visible reference lines
|
|
1050
1059
|
|
|
1051
1060
|
- **`Heatmap`: a position with no datum is inert.** Hovering before the window or after `now` used to snap to the neighbouring row's cell (a tooltip titled with another day's hour); it now opens no tooltip. Positions that hold a datum are unchanged. **Opt-out: none.**
|
|
@@ -34,6 +34,6 @@ const railTop = (plotHeight: number) => Y_MAX - (RAIL_PX * (Y_MAX - Y_MIN)) / pl
|
|
|
34
34
|
/>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
4. Wrap it in `ChartCard`; pass `state={{ pending, error, empty }}` from the query. A `cursorValue` series colours its
|
|
37
|
+
4. Wrap it in `ChartCard`; pass `state={{ pending, error, empty }}` from the query. A `cursorValue` series colours its CURSOR dot per datum with `getMarker: (d) => ({ color })`; always-on markers are `Lines`-only, so a consumer-`marks` chart draws its persistent dots itself.
|
|
38
38
|
5. Run the repo's own gate (e.g. `make check`), which runs lint, the theme guard and typecheck; fix every finding at its source.
|
|
39
39
|
6. Check both color schemes and a pending query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DualPanel.d.ts","sourceRoot":"","sources":["../../src/charts/DualPanel.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAWzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAW,MAAM,SAAS,CAAA;AAcxE,uBAAuB;AACvB,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,IAAI,CACjC,WAAW,CAAC,CAAC,CAAC,EACZ,KAAK,GACL,OAAO,GACP,OAAO,GACP,UAAU,GACV,aAAa,GACb,SAAS,GACT,QAAQ,GACR,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,aAAa,GACb,eAAe,GACf,WAAW,CACd,CA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CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;QAC5C,uDAAuD;QACvD,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;KACpD,GACD,SAAS,CAAA;IACb;;;OAGG;IACH,WAAW,CAAC,EACR;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAC1E,SAAS,CAAA;IACb,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;IACpB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC,CAAA;AAiBD,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,EAClE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1B,YAAY,CA6Od"}
|
package/dist/charts/DualPanel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lines.d.ts","sourceRoot":"","sources":["../../src/charts/Lines.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Lines.d.ts","sourceRoot":"","sources":["../../src/charts/Lines.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAOzC,OAAO,KAAK,EACV,mBAAmB,EAEnB,MAAM,EAGN,SAAS,EACV,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG;IAChG;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,SAAS,SAAS,EAAE,CAAA;CACjE,CAAA;AAID,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CA8DzF"}
|
package/dist/charts/Lines.js
CHANGED
|
@@ -2,50 +2,14 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { areaY } from "@tanstack/charts/area";
|
|
3
3
|
import { differenceY } from "@tanstack/charts/difference";
|
|
4
4
|
import { decorative } from "@tanstack/charts/mark/decorative";
|
|
5
|
-
import { text } from "@tanstack/charts/text";
|
|
6
5
|
import { useCallback } from "react";
|
|
7
|
-
import { VX } from "../tokens/index.js";
|
|
8
6
|
import { CartesianRung } from "./CartesianChart.js";
|
|
9
7
|
import { areaGradientId } from "./compile.js";
|
|
10
8
|
import { chartCurve } from "./curves.js";
|
|
11
|
-
import {
|
|
9
|
+
import { endLabelMarks, endLabelPlan } from "./labels.js";
|
|
10
|
+
import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from "./marks.js";
|
|
12
11
|
import { rowX } from "./types.js";
|
|
13
|
-
const MAX_END_LABELS = 3;
|
|
14
|
-
const END_LABEL_MIN_GAP = 13;
|
|
15
|
-
const END_LABEL_DX = 6;
|
|
16
12
|
const hasValue = (r) => r.y !== null;
|
|
17
|
-
function endLabels(plot, lines) {
|
|
18
|
-
if (plot.containerClass !== "wide" || plot.y2 !== void 0) return [];
|
|
19
|
-
if (lines.length === 0 || lines.length > MAX_END_LABELS) return [];
|
|
20
|
-
const last = lines.flatMap((s) => {
|
|
21
|
-
const row = plot.rows(s.key).findLast(hasValue);
|
|
22
|
-
return row ? [{ s, row }] : [];
|
|
23
|
-
});
|
|
24
|
-
const domain = plot.yDomain;
|
|
25
|
-
const ys = last.map(({ row }) => {
|
|
26
|
-
if (row.y === null) return Number.NaN;
|
|
27
|
-
return (row.y - domain[0]) / (domain[1] - domain[0] || 1) * plot.height;
|
|
28
|
-
});
|
|
29
|
-
const sorted = ys.toSorted((a, b) => a - b);
|
|
30
|
-
if (sorted.some(
|
|
31
|
-
(y, i) => Number.isNaN(y) || i > 0 && y - sorted[i - 1] < END_LABEL_MIN_GAP
|
|
32
|
-
))
|
|
33
|
-
return [];
|
|
34
|
-
return last.map(
|
|
35
|
-
({ s, row }) => decorative(
|
|
36
|
-
text([row], {
|
|
37
|
-
id: `${s.key}-end-label`,
|
|
38
|
-
x: rowX,
|
|
39
|
-
y: "y",
|
|
40
|
-
text: () => s.label,
|
|
41
|
-
fill: s.color,
|
|
42
|
-
fontSize: VX.text.micro,
|
|
43
|
-
anchor: "start",
|
|
44
|
-
dx: END_LABEL_DX
|
|
45
|
-
})
|
|
46
|
-
)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
13
|
function Lines(props) {
|
|
50
14
|
const { thresholds, ...rest } = props;
|
|
51
15
|
const { series } = props;
|
|
@@ -94,15 +58,13 @@ function Lines(props) {
|
|
|
94
58
|
);
|
|
95
59
|
}
|
|
96
60
|
for (const s of plot.visible) {
|
|
61
|
+
const yScale = yScaleOf(plot, s);
|
|
97
62
|
out.push(lineMark(plot, s));
|
|
98
|
-
out.push(...
|
|
63
|
+
out.push(...loneDots(s, drawnRows(plot, s), yScale, plot.highlighted));
|
|
64
|
+
out.push(...markersOf(s, plot.rows(s.key), yScale));
|
|
99
65
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
plot,
|
|
103
|
-
plotted.filter((s) => s.role !== "reference")
|
|
104
|
-
)
|
|
105
|
-
);
|
|
66
|
+
const labelled = plotted.filter((s) => s.role !== "reference");
|
|
67
|
+
out.push(...endLabelMarks(endLabelPlan(plot, labelled)));
|
|
106
68
|
return out;
|
|
107
69
|
},
|
|
108
70
|
[series, thresholds]
|
|
@@ -76,7 +76,7 @@ function MirroredBars(props) {
|
|
|
76
76
|
Math.floor(width / (foldConfig.minBandPx ?? DEFAULT_MIN_BAND_PX)),
|
|
77
77
|
foldConfig.merge
|
|
78
78
|
) : data;
|
|
79
|
-
const model = xScaleFor(drawn.map(x),
|
|
79
|
+
const model = xScaleFor(drawn.map(x), "flush");
|
|
80
80
|
const visible = visibleSeries(bars, hidden);
|
|
81
81
|
const absentOn = !absentEntry || visible.includes(absentEntry);
|
|
82
82
|
const absentFill = absentEntry ? alpha(absentEntry.color, absentEntry.fillOpacity ?? 1) : VX.neutral;
|
|
@@ -86,7 +86,7 @@ function MirroredBars(props) {
|
|
|
86
86
|
const upMax = paneMax(up, upSeries, drawn, upOn);
|
|
87
87
|
const downMax = paneMax(down, downSeries, drawn, downOn);
|
|
88
88
|
const bandWidth = 2 * model.halfStep * BAND_FILL;
|
|
89
|
-
const bandScale = () => xScaleFor(drawn.map(x),
|
|
89
|
+
const bandScale = () => xScaleFor(drawn.map(x), "flush").scale;
|
|
90
90
|
const pane = (side, cfg, s, on, max) => ({ width: w, height: h }) => {
|
|
91
91
|
const cls = resolveContainerClass(w);
|
|
92
92
|
const whole = chartHeightOf(h, side === "up" ? upFraction : 1 - upFraction, 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,aAAa,EAEb,yBAAyB,EACzB,eAAe,IAAI,gBAAgB,EACnC,UAAU,EACV,yBAAyB,EAE1B,MAAM,6BAA6B,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,aAAa,EAEb,yBAAyB,EACzB,eAAe,IAAI,gBAAgB,EACnC,UAAU,EACV,yBAAyB,EAE1B,MAAM,6BAA6B,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,E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CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GACjC,aAAa,GAAG,IAAI,CAuBtB;AAqbD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAClD,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1B,mBAAmB,CA0ErB"}
|
package/dist/charts/compile.js
CHANGED
|
@@ -11,6 +11,7 @@ import { fmtCompact } from "../format/number.js";
|
|
|
11
11
|
import { VX } from "../tokens/index.js";
|
|
12
12
|
import { cursorBinding, sourceOnlyFocus } from "./cursor.js";
|
|
13
13
|
import { cursorDots } from "./marks.js";
|
|
14
|
+
import { bucketTicks, strideEvery } from "./ticks.js";
|
|
14
15
|
import { MAIN_PANE, plotAccess, plotContext } from "./plot-context.js";
|
|
15
16
|
import { resolveContainerClass } from "../tokens/size-classes.js";
|
|
16
17
|
import { resolveYDomain, xScaleFor, xZoneFractions, yScaleFor } from "./scales.js";
|
|
@@ -22,6 +23,7 @@ const LADDER = {
|
|
|
22
23
|
wide: { font: VX.text.micro, xTicks: 6, yTicks: 5 }
|
|
23
24
|
};
|
|
24
25
|
const INSIDE_LABEL_DX = 4;
|
|
26
|
+
const LEFT_EDGE_SHARE = 0.05;
|
|
25
27
|
const INSIDE_LABEL_DY = -6;
|
|
26
28
|
const labelsInside = (cls, height) => cls === "compact" && height > 0 && height < SHORT_CHART_HEIGHT;
|
|
27
29
|
function defaultNumberFormat(v) {
|
|
@@ -128,8 +130,16 @@ function yGuide(opts) {
|
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
}
|
|
133
|
+
function bucketDates(model) {
|
|
134
|
+
if (!model.band || model.kind !== "date") return null;
|
|
135
|
+
const dates = model.values.filter((v) => v instanceof Date);
|
|
136
|
+
return dates.length === model.values.length ? dates : null;
|
|
137
|
+
}
|
|
131
138
|
function xTickPolicy(model, xTicks) {
|
|
132
139
|
if (typeof xTicks === "object") return { values: xTicks };
|
|
140
|
+
const buckets = typeof xTicks === "number" && Number.isFinite(xTicks) ? bucketDates(model) : null;
|
|
141
|
+
if (buckets !== null && typeof xTicks === "number")
|
|
142
|
+
return { values: bucketTicks(buckets, xTicks) };
|
|
133
143
|
if (model.band || model.kind === "string") return { values: model.values };
|
|
134
144
|
if (model.kind === "date" && model.extent)
|
|
135
145
|
return {
|
|
@@ -138,14 +148,14 @@ function xTickPolicy(model, xTicks) {
|
|
|
138
148
|
return { count: xTicks };
|
|
139
149
|
}
|
|
140
150
|
function strideTicks(values, cls) {
|
|
141
|
-
|
|
142
|
-
return values.filter((_, i) => i % stride === 0);
|
|
151
|
+
return strideEvery(values, LADDER[cls].xTicks);
|
|
143
152
|
}
|
|
144
153
|
function xGuide(opts) {
|
|
145
154
|
const { model, xTicks, format, cls, height } = opts;
|
|
146
155
|
const ladder = LADDER[cls];
|
|
147
156
|
const inside = labelsInside(cls, height);
|
|
148
157
|
const ticks = xTickPolicy(model, xTicks ?? ladder.xTicks);
|
|
158
|
+
const [leftEdgeX, spanX] = !model.band && model.extent ? [model.extent[0], model.extent[1] - model.extent[0]] : [Number.NaN, Number.NaN];
|
|
149
159
|
return {
|
|
150
160
|
axis: {
|
|
151
161
|
line: AXIS_LINE,
|
|
@@ -154,9 +164,14 @@ function xGuide(opts) {
|
|
|
154
164
|
fontSize: ladder.font,
|
|
155
165
|
opacity: 1,
|
|
156
166
|
thin: true,
|
|
157
|
-
// A
|
|
158
|
-
|
|
159
|
-
|
|
167
|
+
// A label centred on a tick near the plot's left edge hangs left of it, under the gutter's
|
|
168
|
+
// lowest y label (outside labels) or off the plot (inside labels, left margin locked to
|
|
169
|
+
// zero): start-anchor it. `+value` is a Date's timestamp, or the number itself.
|
|
170
|
+
anchor: ({ index, value }) => {
|
|
171
|
+
const pinnedFirst = inside && index === 0;
|
|
172
|
+
const share = (+value - leftEdgeX) / spanX;
|
|
173
|
+
const onLeftEdge = share >= 0 && share <= LEFT_EDGE_SHARE;
|
|
174
|
+
return pinnedFirst || onLeftEdge ? "start" : void 0;
|
|
160
175
|
}
|
|
161
176
|
}
|
|
162
177
|
}
|
|
@@ -539,6 +554,7 @@ function compileCartesian(input) {
|
|
|
539
554
|
width,
|
|
540
555
|
height,
|
|
541
556
|
data: input.data,
|
|
557
|
+
xFraction: model.fraction,
|
|
542
558
|
y2: axes.right ? "y2" : void 0,
|
|
543
559
|
yDomain: axes.left.domain,
|
|
544
560
|
y2Domain: axes.right?.domain
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types.js';
|
|
2
|
+
export type EndLabelAnchor = 'start' | 'end';
|
|
3
|
+
/**
|
|
4
|
+
* The side of its point an end label takes: `start` (right of the point) unless the point leaves
|
|
5
|
+
* less room than the label needs. `fraction` is the point's x as a share of the plot width,
|
|
6
|
+
* `plotWidth` the plot in px. Before the engine has measured the plot, `plotWidth` is the frame's,
|
|
7
|
+
* which is wider than the plot by the axis gutters: the first frame can keep `start` for a label
|
|
8
|
+
* the measured frame then flips.
|
|
9
|
+
*/
|
|
10
|
+
export declare function endLabelAnchor(opts: {
|
|
11
|
+
fraction: number;
|
|
12
|
+
plotWidth: number;
|
|
13
|
+
label: string;
|
|
14
|
+
fontSize: number;
|
|
15
|
+
}): EndLabelAnchor;
|
|
16
|
+
export type EndLabel<T, X extends ChartX> = {
|
|
17
|
+
series: ChartSeries<T>;
|
|
18
|
+
row: PlotRow<T, X>;
|
|
19
|
+
anchor: EndLabelAnchor;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The end labels to draw: none off the wide class, with a right axis, with more than
|
|
23
|
+
* {@link MAX_END_LABELS} lines, or when two would collide in pixels (against the plot's height).
|
|
24
|
+
* A series whose last point the plot's own x scale cannot place, or places outside the plot
|
|
25
|
+
* (`plot.xFraction` outside [0, 1]: clipped by a narrower `xDomain`), has no label.
|
|
26
|
+
*/
|
|
27
|
+
export declare function endLabelPlan<T, X extends ChartX>(plot: PlotContext<T, X>, lines: readonly ChartSeries<T>[]): EndLabel<T, X>[];
|
|
28
|
+
/** The offset of a label from its point: right of it, level; or left of it and above. */
|
|
29
|
+
export declare function endLabelOffset(anchor: EndLabelAnchor): {
|
|
30
|
+
dx: number;
|
|
31
|
+
dy: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>[]): ChartMarks;
|
|
34
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/charts/labels.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAgBpF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,CAAA;AAE5C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,cAAc,CAIjB;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI;IAC1C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IACtB,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAClB,MAAM,EAAE,cAAc,CAAA;CACvB,CAAA;AASD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAC9C,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,KAAK,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,GAC/B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CA2BlB;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAIjF;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,SAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,UAAU,CAe9F"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { decorative } from "@tanstack/charts/mark/decorative";
|
|
2
|
+
import { text } from "@tanstack/charts/text";
|
|
3
|
+
import { VX } from "../tokens/index.js";
|
|
4
|
+
import { rowX } from "./types.js";
|
|
5
|
+
const MAX_END_LABELS = 3;
|
|
6
|
+
const END_LABEL_MIN_GAP = 13;
|
|
7
|
+
const END_LABEL_DX = 6;
|
|
8
|
+
const END_LABEL_GLYPH_EM = 0.85;
|
|
9
|
+
const END_LABEL_FLIP_DY = -9;
|
|
10
|
+
function endLabelAnchor(opts) {
|
|
11
|
+
const { fraction, plotWidth, label, fontSize } = opts;
|
|
12
|
+
const room = (1 - fraction) * plotWidth;
|
|
13
|
+
return room >= label.length * fontSize * END_LABEL_GLYPH_EM + END_LABEL_DX ? "start" : "end";
|
|
14
|
+
}
|
|
15
|
+
function endLabelPlan(plot, lines) {
|
|
16
|
+
if (plot.containerClass !== "wide" || plot.y2 !== void 0) return [];
|
|
17
|
+
if (lines.length === 0 || lines.length > MAX_END_LABELS) return [];
|
|
18
|
+
const last = lines.flatMap((series) => {
|
|
19
|
+
const row = plot.rows(series.key).findLast((r) => r.y !== null);
|
|
20
|
+
if (row === void 0 || row.y === null) return [];
|
|
21
|
+
const fraction = plot.xFraction(row.x);
|
|
22
|
+
if (fraction === null || fraction < 0 || fraction > 1) return [];
|
|
23
|
+
return [{ series, row, y: row.y, fraction }];
|
|
24
|
+
});
|
|
25
|
+
const [lo, hi] = plot.yDomain;
|
|
26
|
+
const ys = last.map(({ y }) => (y - lo) / (hi - lo || 1) * plot.plotHeight).toSorted((a, b) => a - b);
|
|
27
|
+
if (ys.some((y, i) => i > 0 && y - ys[i - 1] < END_LABEL_MIN_GAP)) return [];
|
|
28
|
+
return last.map(({ series, row, fraction }) => ({
|
|
29
|
+
series,
|
|
30
|
+
row,
|
|
31
|
+
anchor: endLabelAnchor({
|
|
32
|
+
fraction,
|
|
33
|
+
plotWidth: plot.plotWidth,
|
|
34
|
+
label: series.label,
|
|
35
|
+
fontSize: VX.text.micro
|
|
36
|
+
})
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
function endLabelOffset(anchor) {
|
|
40
|
+
return anchor === "end" ? { dx: -END_LABEL_DX, dy: END_LABEL_FLIP_DY } : { dx: END_LABEL_DX, dy: 0 };
|
|
41
|
+
}
|
|
42
|
+
function endLabelMarks(plan) {
|
|
43
|
+
return plan.map(
|
|
44
|
+
({ series, row, anchor }) => decorative(
|
|
45
|
+
text([row], {
|
|
46
|
+
id: `${series.key}-end-label`,
|
|
47
|
+
x: rowX,
|
|
48
|
+
y: "y",
|
|
49
|
+
text: () => series.label,
|
|
50
|
+
fill: series.color,
|
|
51
|
+
fontSize: VX.text.micro,
|
|
52
|
+
anchor,
|
|
53
|
+
...endLabelOffset(anchor)
|
|
54
|
+
})
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
endLabelAnchor,
|
|
60
|
+
endLabelMarks,
|
|
61
|
+
endLabelOffset,
|
|
62
|
+
endLabelPlan
|
|
63
|
+
};
|
package/dist/charts/marks.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ export declare function emphasis<T>(highlighted: string | null, s: Pick<ChartSer
|
|
|
7
7
|
/** The rows a series' line and area are drawn through: all of them, or only the non-null ones. */
|
|
8
8
|
export declare function drawnRows<T, X extends ChartX>(plot: PlotContext<T, X>, s: Pick<ChartSeries<T>, 'key' | 'gaps'>): PlotRow<T, X>[];
|
|
9
9
|
export declare function lineMark<T, X extends ChartX>(plot: PlotContext<T, X>, s: ChartSeries<T>): ChartMarks[number];
|
|
10
|
+
/**
|
|
11
|
+
* The dot for a point a line cannot draw: a finite value with no finite neighbour in `drawn` (the
|
|
12
|
+
* rows the line is drawn through: a one-point window, or a value between nulls). A path of one
|
|
13
|
+
* point has no length, so without this the series is invisible. One mark per series. A point the
|
|
14
|
+
* series' own `getMarker` already marks is left to it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function loneDots<T, X extends ChartX>(s: ChartSeries<T>, drawn: readonly PlotRow<T, X>[], yScale: 'y2' | undefined, highlighted: string | null): ChartMarks;
|
|
10
17
|
/** A series' `getMarker` points as dots: one decorative mark per distinct paint. */
|
|
11
18
|
export declare function markersOf<T, X extends ChartX>(s: ChartSeries<T>, rows: readonly PlotRow<T, X>[], yScale: 'y2' | undefined): ChartMarks;
|
|
12
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marks.d.ts","sourceRoot":"","sources":["../../src/charts/marks.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAQvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEpF,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAC1C,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC9B,IAAI,GAAG,SAAS,CAElB;AAED,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,CAAC,EACxB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,GACxC,MAAM,CAER;AAED,kGAAkG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|
|
|
31
31
|
...yScale !== void 0 && { yScale }
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
+
const isFinitePoint = (r) => r !== void 0 && r.y !== null && Number.isFinite(r.y);
|
|
35
|
+
const LONE_DOT_STROKE_FACTOR = 1.25;
|
|
36
|
+
function loneDots(s, drawn, yScale, highlighted) {
|
|
37
|
+
const lone = drawn.filter(
|
|
38
|
+
(r, i) => isFinitePoint(r) && !isFinitePoint(drawn[i - 1]) && !isFinitePoint(drawn[i + 1]) && !s.getMarker?.(r.datum)
|
|
39
|
+
);
|
|
40
|
+
if (lone.length === 0) return [];
|
|
41
|
+
return [
|
|
42
|
+
decorative(
|
|
43
|
+
dot(lone, {
|
|
44
|
+
id: `${s.key}-lone`,
|
|
45
|
+
x: rowX,
|
|
46
|
+
y: "y",
|
|
47
|
+
r: Math.max(VX.dotR - 1, (s.strokeWidth ?? LINE_STROKE_WIDTH) * LONE_DOT_STROKE_FACTOR),
|
|
48
|
+
fill: s.color,
|
|
49
|
+
fillOpacity: (s.strokeOpacity ?? 1) * emphasis(highlighted, s),
|
|
50
|
+
...yScale !== void 0 && { yScale }
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
];
|
|
54
|
+
}
|
|
34
55
|
function markersOf(s, rows, yScale) {
|
|
35
56
|
const getMarker = s.getMarker;
|
|
36
57
|
if (!getMarker) return [];
|
|
@@ -158,6 +179,7 @@ export {
|
|
|
158
179
|
drawnRows,
|
|
159
180
|
emphasis,
|
|
160
181
|
lineMark,
|
|
182
|
+
loneDots,
|
|
161
183
|
markersOf,
|
|
162
184
|
thinFill,
|
|
163
185
|
yScaleOf
|
package/dist/charts/scales.d.ts
CHANGED
|
@@ -38,7 +38,10 @@ export type XScaleModel<X extends ChartX> = {
|
|
|
38
38
|
extent?: readonly [number, number];
|
|
39
39
|
step: number;
|
|
40
40
|
};
|
|
41
|
-
export declare function xScaleFor<X extends ChartX>(raw: readonly X[],
|
|
41
|
+
export declare function xScaleFor<X extends ChartX>(raw: readonly X[],
|
|
42
|
+
/** `'flush'`: a band scale with no outer padding, so the first and last band meet the plot's
|
|
43
|
+
* edges (`MirroredBars`); `true` pads half a gap-and-a-bit at each end, as `Bars` does. */
|
|
44
|
+
band: boolean | 'flush',
|
|
42
45
|
/** Continuous scales only: the explicit `[min, max]` that replaces the data's own extent. */
|
|
43
46
|
xDomain?: readonly [X, X]): XScaleModel<X>;
|
|
44
47
|
/** An x-zone's [left, right] as plot fractions, clamped to the plot; `null` when it is empty. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scales.d.ts","sourceRoot":"","sources":["../../src/charts/scales.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAE5D,OAAO,EAAE,QAAQ,EAAY,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIzE,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAC9B,IAAI,EAAE,SAAS,CAAC,EAAE,EAClB,MAAM,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,EACjC,WAAW,GAAE,SAAS,MAAM,EAAO,GAClC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAiC3B;AAED,2DAA2D;AAC3D,wBAAgB,SAAS,CAAC,CAAC,EACzB,GAAG,EAAE,UAAU,CAAC,CAA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S,MAAM,IAAI;IAC1C,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,OAAO,CAAA;IACb,2CAA2C;IAC3C,KAAK,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAA;IACpB,uFAAuF;IACvF,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAA;IACjC,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAA;IAChB,2FAA2F;IAC3F,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAoBD,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EACxC,GAAG,EAAE,SAAS,CAAC,EAAE;AACjB;2FAC2F;AAC3F,IAAI,EAAE,OAAO,GAAG,OAAO;AACvB,6FAA6F;AAC7F,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GACxB,WAAW,CAAC,CAAC,CAAC,CAwFhB;AAED,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAClB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAOlC"}
|
package/dist/charts/scales.js
CHANGED
|
@@ -91,8 +91,10 @@ function xScaleFor(raw, band, xDomain) {
|
|
|
91
91
|
const keys = values;
|
|
92
92
|
const index = new Map(keys.map((k, i) => [keyOf(k), i]));
|
|
93
93
|
if (band) {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
94
|
+
const outer = band === "flush" ? 0 : BAND_PADDING_OUTER;
|
|
95
|
+
const steps = n - BAND_PADDING_INNER + 2 * outer;
|
|
96
|
+
const step2 = 1 / (steps > 0 ? steps : 1);
|
|
97
|
+
const scale2 = scaleBand().domain(keys).paddingInner(BAND_PADDING_INNER).paddingOuter(outer);
|
|
96
98
|
return {
|
|
97
99
|
kind,
|
|
98
100
|
band: true,
|
|
@@ -103,7 +105,7 @@ function xScaleFor(raw, band, xDomain) {
|
|
|
103
105
|
fraction: (x) => {
|
|
104
106
|
const i = index.get(keyOf(x));
|
|
105
107
|
if (i === void 0) return null;
|
|
106
|
-
return step2 * (
|
|
108
|
+
return step2 * (outer + i + (1 - BAND_PADDING_INNER) / 2);
|
|
107
109
|
}
|
|
108
110
|
};
|
|
109
111
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Every n-th value, n the smallest stride that leaves at most `count` of them. */
|
|
2
|
+
export declare function strideEvery<V>(values: readonly V[], count: number): V[];
|
|
3
|
+
/**
|
|
4
|
+
* Ticks of a bucketed Date axis: the time scale's own round instants, each snapped to the bucket
|
|
5
|
+
* it falls in. Labelling every bucket and letting the engine thin the collisions leaves an uneven,
|
|
6
|
+
* near-touching subset ("18:13 18:17 18:21"); round instants are evenly spaced whenever the
|
|
7
|
+
* buckets are. A bucket is used once, and a round instant with no bucket within a step of it is
|
|
8
|
+
* dropped. Fewer than two picks falls back to a plain stride over the distinct,
|
|
9
|
+
* sorted buckets. `count` must be finite (`xTickPolicy` guards it). O(ticks · log buckets) after the sort.
|
|
10
|
+
*/
|
|
11
|
+
export declare function bucketTicks(values: readonly Date[], count: number): Date[];
|
|
12
|
+
//# sourceMappingURL=ticks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticks.d.ts","sourceRoot":"","sources":["../../src/charts/ticks.ts"],"names":[],"mappings":"AAMA,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAGvE;AAuBD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,CAmB1E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { scaleUtc } from "d3-scale";
|
|
2
|
+
function strideEvery(values, count) {
|
|
3
|
+
const stride = Math.max(1, Math.ceil(values.length / Math.max(1, count)));
|
|
4
|
+
return values.filter((_, i) => i % stride === 0);
|
|
5
|
+
}
|
|
6
|
+
function medianGap(sorted) {
|
|
7
|
+
const gaps = sorted.slice(1).map((t, i) => t - sorted[i]);
|
|
8
|
+
return gaps.toSorted((a, b) => a - b)[gaps.length >> 1];
|
|
9
|
+
}
|
|
10
|
+
function nearestIndex(sorted, target) {
|
|
11
|
+
let lo = 0;
|
|
12
|
+
let hi = sorted.length - 1;
|
|
13
|
+
while (lo < hi) {
|
|
14
|
+
const mid = lo + hi >> 1;
|
|
15
|
+
if (sorted[mid] < target) lo = mid + 1;
|
|
16
|
+
else hi = mid;
|
|
17
|
+
}
|
|
18
|
+
const before = lo - 1;
|
|
19
|
+
return before >= 0 && target - sorted[before] <= sorted[lo] - target ? before : lo;
|
|
20
|
+
}
|
|
21
|
+
function bucketTicks(values, count) {
|
|
22
|
+
const times = [...new Set(values.map((v) => v.getTime()).filter(Number.isFinite))].toSorted(
|
|
23
|
+
(a, b) => a - b
|
|
24
|
+
);
|
|
25
|
+
const asDates = (ts) => ts.map((t) => new Date(t));
|
|
26
|
+
const first = times[0];
|
|
27
|
+
const last = times.at(-1);
|
|
28
|
+
if (first === void 0 || last === void 0 || first === last) return asDates(times);
|
|
29
|
+
const step = medianGap(times);
|
|
30
|
+
const want = Math.max(1, Math.floor(count));
|
|
31
|
+
const picked = /* @__PURE__ */ new Set();
|
|
32
|
+
for (const tick of scaleUtc().domain([new Date(first), new Date(last)]).ticks(want)) {
|
|
33
|
+
const t = tick.getTime();
|
|
34
|
+
const near = times[nearestIndex(times, t)];
|
|
35
|
+
if (near !== void 0 && Math.abs(near - t) < step) picked.add(near);
|
|
36
|
+
}
|
|
37
|
+
return asDates(picked.size >= 2 ? [...picked] : strideEvery(times, want));
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
bucketTicks,
|
|
41
|
+
strideEvery
|
|
42
|
+
};
|
package/dist/charts/types.d.ts
CHANGED
|
@@ -65,9 +65,11 @@ export type ChartSeries<T> = {
|
|
|
65
65
|
* dot follows the datum. A series drawn from `plot.rows` already has one.
|
|
66
66
|
*/
|
|
67
67
|
cursorValue?: ((d: T) => number | null) | undefined;
|
|
68
|
-
/** A marker at a point (a PR star, a status dot); `null` for none.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
/** A marker at a point (a PR star, a status dot); `null` for none. Always-on markers are `Lines`'
|
|
69
|
+
* alone. On a `CartesianChart` with consumer `marks` only the CURSOR dot of a `cursorValue`
|
|
70
|
+
* series reads `getMarker` (its `color`): without `cursorValue` it is ignored there, so draw a
|
|
71
|
+
* persistent dot in `marks` yourself. Each distinct color is one extra mark: keep colors a small
|
|
72
|
+
* categorical set (statuses, buckets), never a continuous scale. */
|
|
71
73
|
getMarker?: ((d: T) => {
|
|
72
74
|
color?: string | undefined;
|
|
73
75
|
r?: number | undefined;
|
|
@@ -244,6 +246,12 @@ export type PlotContext<T, X extends ChartX = ChartX> = {
|
|
|
244
246
|
data: readonly T[];
|
|
245
247
|
/** Bind a mark to the right axis with `yScale: plot.y2` (present only with a `y2` config). */
|
|
246
248
|
y2: 'y2' | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Where an x value sits in the plot, 0 (left edge) to 1 (right edge), on the SAME x scale the
|
|
251
|
+
* axis draws: an explicit `xDomain` or the extent of every datum. Outside [0, 1] a value is
|
|
252
|
+
* clipped; `null` for a value the scale cannot place.
|
|
253
|
+
*/
|
|
254
|
+
xFraction: (x: X) => number | null;
|
|
247
255
|
/** The resolved y domain (and the right axis', with `y2`): basalt's, never the engine's. */
|
|
248
256
|
yDomain: readonly [number, number];
|
|
249
257
|
y2Domain: readonly [number, number] | undefined;
|
|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6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,SAAS,CAAA;IAC1C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAA;IACrC,gGAAgG;IAChG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IACxC,KAAK,CAAC,EAAE,SAAS,QAAQ,EAAE,GAAG,SAAS,CAAA;IACvC,MAAM,CAAC,EAAE,SAAS,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAA;IAC5C,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAA;IACzC,gCAAgC;IAChC,MAAM,CAAC,EAAE,iBAAiB,GAAG,KAAK,GAAG,SAAS,CAAA;IAC9C;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAA;IACnD,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;IAC9B,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC;qCACiC;IACjC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;IAC/C,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,SAAS,CAAA;CACvD,CAAA;AAED;mBACmB;AACnB,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAAU,CAAA"}
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.11.
|
|
1
|
+
# basalt-ui v2.11.1
|
|
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.11.
|
|
16
|
+
Version: 2.11.1
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
package/package.json
CHANGED
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
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tick selection that needs no engine: the stride every band axis shares, and the round,
|
|
3
|
+
* bucket-snapped ticks of a bucketed Date axis.
|
|
4
|
+
*/
|
|
5
|
+
import { scaleUtc } from 'd3-scale'
|
|
6
|
+
|
|
7
|
+
/** Every n-th value, n the smallest stride that leaves at most `count` of them. */
|
|
8
|
+
export function strideEvery<V>(values: readonly V[], count: number): V[] {
|
|
9
|
+
const stride = Math.max(1, Math.ceil(values.length / Math.max(1, count)))
|
|
10
|
+
return values.filter((_, i) => i % stride === 0)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The median gap between sorted, DISTINCT numbers: two or more of them leave a positive one. */
|
|
14
|
+
function medianGap(sorted: readonly number[]): number {
|
|
15
|
+
const gaps = sorted.slice(1).map((t, i) => t - (sorted[i] as number))
|
|
16
|
+
return gaps.toSorted((a, b) => a - b)[gaps.length >> 1] as number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The index of the value nearest `target` in an ascending, non-empty array (binary search). */
|
|
20
|
+
function nearestIndex(sorted: readonly number[], target: number): number {
|
|
21
|
+
let lo = 0
|
|
22
|
+
let hi = sorted.length - 1
|
|
23
|
+
while (lo < hi) {
|
|
24
|
+
const mid = (lo + hi) >> 1
|
|
25
|
+
if ((sorted[mid] as number) < target) lo = mid + 1
|
|
26
|
+
else hi = mid
|
|
27
|
+
}
|
|
28
|
+
const before = lo - 1
|
|
29
|
+
return before >= 0 && target - (sorted[before] as number) <= (sorted[lo] as number) - target
|
|
30
|
+
? before
|
|
31
|
+
: lo
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Ticks of a bucketed Date axis: the time scale's own round instants, each snapped to the bucket
|
|
36
|
+
* it falls in. Labelling every bucket and letting the engine thin the collisions leaves an uneven,
|
|
37
|
+
* near-touching subset ("18:13 18:17 18:21"); round instants are evenly spaced whenever the
|
|
38
|
+
* buckets are. A bucket is used once, and a round instant with no bucket within a step of it is
|
|
39
|
+
* dropped. Fewer than two picks falls back to a plain stride over the distinct,
|
|
40
|
+
* sorted buckets. `count` must be finite (`xTickPolicy` guards it). O(ticks · log buckets) after the sort.
|
|
41
|
+
*/
|
|
42
|
+
export function bucketTicks(values: readonly Date[], count: number): Date[] {
|
|
43
|
+
const times = [...new Set(values.map((v) => v.getTime()).filter(Number.isFinite))].toSorted(
|
|
44
|
+
(a, b) => a - b,
|
|
45
|
+
)
|
|
46
|
+
const asDates = (ts: readonly number[]): Date[] => ts.map((t) => new Date(t))
|
|
47
|
+
const first = times[0]
|
|
48
|
+
const last = times.at(-1)
|
|
49
|
+
if (first === undefined || last === undefined || first === last) return asDates(times)
|
|
50
|
+
const step = medianGap(times)
|
|
51
|
+
const want = Math.max(1, Math.floor(count))
|
|
52
|
+
const picked = new Set<number>()
|
|
53
|
+
for (const tick of scaleUtc()
|
|
54
|
+
.domain([new Date(first), new Date(last)])
|
|
55
|
+
.ticks(want)) {
|
|
56
|
+
const t = tick.getTime()
|
|
57
|
+
const near = times[nearestIndex(times, t)]
|
|
58
|
+
if (near !== undefined && Math.abs(near - t) < step) picked.add(near)
|
|
59
|
+
}
|
|
60
|
+
return asDates(picked.size >= 2 ? [...picked] : strideEvery(times, want))
|
|
61
|
+
}
|
package/src/charts/types.ts
CHANGED
|
@@ -67,9 +67,11 @@ export type ChartSeries<T> = {
|
|
|
67
67
|
* dot follows the datum. A series drawn from `plot.rows` already has one.
|
|
68
68
|
*/
|
|
69
69
|
cursorValue?: ((d: T) => number | null) | undefined
|
|
70
|
-
/** A marker at a point (a PR star, a status dot); `null` for none.
|
|
71
|
-
*
|
|
72
|
-
*
|
|
70
|
+
/** A marker at a point (a PR star, a status dot); `null` for none. Always-on markers are `Lines`'
|
|
71
|
+
* alone. On a `CartesianChart` with consumer `marks` only the CURSOR dot of a `cursorValue`
|
|
72
|
+
* series reads `getMarker` (its `color`): without `cursorValue` it is ignored there, so draw a
|
|
73
|
+
* persistent dot in `marks` yourself. Each distinct color is one extra mark: keep colors a small
|
|
74
|
+
* categorical set (statuses, buckets), never a continuous scale. */
|
|
73
75
|
getMarker?:
|
|
74
76
|
| ((d: T) => {
|
|
75
77
|
color?: string | undefined
|
|
@@ -265,6 +267,12 @@ export type PlotContext<T, X extends ChartX = ChartX> = {
|
|
|
265
267
|
data: readonly T[]
|
|
266
268
|
/** Bind a mark to the right axis with `yScale: plot.y2` (present only with a `y2` config). */
|
|
267
269
|
y2: 'y2' | undefined
|
|
270
|
+
/**
|
|
271
|
+
* Where an x value sits in the plot, 0 (left edge) to 1 (right edge), on the SAME x scale the
|
|
272
|
+
* axis draws: an explicit `xDomain` or the extent of every datum. Outside [0, 1] a value is
|
|
273
|
+
* clipped; `null` for a value the scale cannot place.
|
|
274
|
+
*/
|
|
275
|
+
xFraction: (x: X) => number | null
|
|
268
276
|
/** The resolved y domain (and the right axis', with `y2`): basalt's, never the engine's. */
|
|
269
277
|
yDomain: readonly [number, number]
|
|
270
278
|
y2Domain: readonly [number, number] | undefined
|