basalt-ui 2.21.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/MIGRATING.md +452 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/rules/basalt-tokens.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +73 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +6 -0
- package/dist/charts/CartesianChart.d.ts +10 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +12 -3
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +39 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +14 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +101 -22
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +38 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +18 -1
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-dates.d.ts +12 -0
- package/dist/charts/chart-dates.d.ts.map +1 -0
- package/dist/charts/chart-dates.js +16 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +25 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +152 -72
- package/dist/charts/date-tick-format.d.ts +5 -5
- package/dist/charts/date-tick-format.d.ts.map +1 -1
- package/dist/charts/date-tick-format.js +3 -7
- package/dist/charts/labels.d.ts +21 -6
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +52 -17
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +43 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +75 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +13 -17
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +2 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +5 -2
- package/dist/charts/types.d.ts +18 -8
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +68 -4
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +202 -36
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +17 -1
- package/dist/cli/shot/playwright.d.ts +13 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/playwright.js +5 -1
- package/dist/cli/shot/types.d.ts +4 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- package/dist/cli/tokens-css.d.ts +5 -7
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +11 -12
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +15 -8
- package/dist/dashboard/bar-list.module.css +83 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +84 -5
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +100 -15
- package/dist/dashboard/meter-parts.d.ts +9 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +276 -74
- package/dist/dashboard/meter.d.ts +54 -65
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +21 -4
- package/dist/dashboard/meter.module.css +76 -0
- package/dist/dashboard/meter.module.css.d.ts +6 -0
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -5
- package/dist/dashboard/stat-card.module.css +36 -0
- package/dist/dashboard/stat-group.module.css +7 -0
- package/dist/dashboard/stat-strip.d.ts +22 -6
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +104 -60
- package/dist/dashboard/stat-strip.module.css +122 -53
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts +7 -1
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +3 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +0 -5
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +43 -4
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +37 -0
- package/dist/theme/controls.module.css.d.ts +2 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +18 -27
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/palette.d.ts +11 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +11 -10
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +42 -22
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +83 -3
- package/src/charts/Bars.tsx +7 -0
- package/src/charts/CartesianChart.tsx +18 -3
- package/src/charts/ChartCard.tsx +54 -13
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +135 -25
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +50 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +253 -87
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +81 -26
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +131 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +13 -17
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +9 -4
- package/src/charts/types.ts +18 -8
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/init.ts +100 -3
- package/src/cli/shot/capture.ts +266 -35
- package/src/cli/shot/detect.ts +18 -1
- package/src/cli/shot/playwright.ts +20 -4
- package/src/cli/shot/types.ts +5 -0
- package/src/cli/tokens-css.ts +18 -20
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +83 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +107 -69
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +207 -24
- package/src/dashboard/meter-parts.tsx +349 -67
- package/src/dashboard/meter.module.css +76 -0
- package/src/dashboard/meter.module.css.d.ts +6 -0
- package/src/dashboard/meter.tsx +72 -18
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +36 -0
- package/src/dashboard/stat-card.tsx +12 -6
- package/src/dashboard/stat-group.module.css +7 -0
- package/src/dashboard/stat-strip.module.css +122 -53
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +176 -91
- package/src/dashboard/visual-slot.ts +12 -3
- package/src/guard/index.ts +0 -5
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +43 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +200 -68
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +37 -0
- package/src/theme/controls.module.css.d.ts +2 -0
- package/src/theme/index.ts +22 -32
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/palette.ts +11 -10
- package/src/tokens/status-text.ts +2 -0
package/src/charts/compile.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* binding, the tooltip content, and the container-class guide ladder.
|
|
6
6
|
* TanStack owns margins (measured), layout, focus and keyboard, the tooltip surface and SSR.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { headerDay, readoutClock } from './chart-dates'
|
|
9
|
+
import { dateTickFormat, utcAxisDate } from './date-tick-format'
|
|
9
10
|
import { crosshair } from '@tanstack/charts/crosshair'
|
|
10
11
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
11
12
|
import { rect } from '@tanstack/charts/rect'
|
|
@@ -16,6 +17,7 @@ import { scaleUtc } from 'd3-scale'
|
|
|
16
17
|
import { portal } from '@tanstack/charts/tooltip/portal'
|
|
17
18
|
import type {
|
|
18
19
|
ChartBuildContext,
|
|
20
|
+
ChartTooltipAnchorContext,
|
|
19
21
|
ChartGradient,
|
|
20
22
|
ChartPoint,
|
|
21
23
|
ChartPositionScaleOptions,
|
|
@@ -24,14 +26,16 @@ import type {
|
|
|
24
26
|
ResponsiveChartDefinition,
|
|
25
27
|
StoredChartSpec,
|
|
26
28
|
} from '@tanstack/charts/types/core'
|
|
27
|
-
import { SHORT_CHART_HEIGHT } from './box'
|
|
28
29
|
import { compact } from '../format/number'
|
|
30
|
+
import { NON_FINITE, numberFormat } from '../format/shared'
|
|
29
31
|
import { VX } from '../tokens'
|
|
30
32
|
import type { ContainerClass } from '../tokens/size-classes'
|
|
31
33
|
import { cursorBinding, followerOptions, quietWhileFollowing } from './cursor'
|
|
32
34
|
import { cursorDots } from './marks'
|
|
33
35
|
import { bucketTicks, strideEvery } from './ticks'
|
|
34
36
|
import { MAIN_PANE, plotAccess, plotContext } from './plot-context'
|
|
37
|
+
import { refLabelPosition } from './ref-label'
|
|
38
|
+
import type { RefLabelPoint } from './ref-label'
|
|
35
39
|
import type { PlotSizes } from './plot-context'
|
|
36
40
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
37
41
|
import { resolveYDomain, xScaleFor, xZoneFractions, yScaleFor } from './scales'
|
|
@@ -91,6 +95,12 @@ export type CartesianInput<T, X extends ChartX> = Pick<
|
|
|
91
95
|
stack?: 'stacked' | 'normalized'
|
|
92
96
|
/** The plot area the engine last laid out; `null` before the first layout (the frame stands in). */
|
|
93
97
|
plot?: PlotSizes | null
|
|
98
|
+
/** The tooltip opens below the chart (a strip of cells), above only when there is no room. */
|
|
99
|
+
tooltipBelow?: boolean
|
|
100
|
+
/** The vertical rule under the cursor. Default `true`; a bar kind has none (its hover is the bar). */
|
|
101
|
+
crosshair?: boolean
|
|
102
|
+
/** The engine's point marker on the focused datum. Default `true`; a bar kind has none (its hover is the bar). */
|
|
103
|
+
focusRing?: boolean
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
/** The one tick-label size, at every container width: the caption size, so a card never mixes sizes. */
|
|
@@ -104,36 +114,42 @@ const LADDER = {
|
|
|
104
114
|
wide: { xTicks: 6, yTicks: 5 },
|
|
105
115
|
} as const satisfies Record<ContainerClass, { xTicks: number; yTicks: number }>
|
|
106
116
|
|
|
107
|
-
/** Space between the plot's left edge and a compact y label drawn inside it. */
|
|
108
|
-
const INSIDE_LABEL_DX = 4
|
|
109
|
-
|
|
110
117
|
/**
|
|
111
118
|
* A tick within this share of the x domain from its start counts as on the left edge: half a
|
|
112
|
-
*
|
|
119
|
+
* day label is ~15 px, 4–5% of a compact plot. Round ticks rarely land on the domain start
|
|
113
120
|
* exactly, so an equality test would miss the common case.
|
|
114
121
|
*/
|
|
115
122
|
const LEFT_EDGE_SHARE = 0.05
|
|
116
|
-
const INSIDE_LABEL_DY = -6
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Y labels go inside the plot only for the compact class under `SHORT_CHART_HEIGHT` (the box's own
|
|
120
|
-
* short signal); otherwise they sit in a left gutter. `height` is the whole chart's, `0` before it
|
|
121
|
-
* is measured, which keeps the gutter rather than flipping a first paint inside.
|
|
122
|
-
*/
|
|
123
|
-
const labelsInside = (cls: ContainerClass, height: number): boolean =>
|
|
124
|
-
cls === 'compact' && height > 0 && height < SHORT_CHART_HEIGHT
|
|
125
123
|
|
|
126
124
|
export function defaultNumberFormat(v: number): string {
|
|
127
125
|
return compact(v, { digits: Math.abs(v) >= 1000 ? 1 : 2 })
|
|
128
126
|
}
|
|
129
127
|
|
|
130
|
-
|
|
128
|
+
/**
|
|
129
|
+
* The UTC midnight of the day a day-keyed instant stands for. A key at LOCAL midnight is that local
|
|
130
|
+
* calendar date (east of UTC it is `22:00` UTC of the day before); any other key is its UTC date, so
|
|
131
|
+
* a key at 12:00 UTC or later never rolls to the next day.
|
|
132
|
+
*/
|
|
133
|
+
export function bucketDay(d: Date): Date {
|
|
134
|
+
const local = d.getHours() === 0 && d.getMinutes() === 0 && d.getSeconds() === 0
|
|
135
|
+
return new Date(
|
|
136
|
+
local
|
|
137
|
+
? Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())
|
|
138
|
+
: Math.floor(d.getTime() / DAY_MS) * DAY_MS,
|
|
139
|
+
)
|
|
140
|
+
}
|
|
131
141
|
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
/**
|
|
143
|
+
* The tooltip's date: weekday, day, month and year in the page's locale (`defineFormat` /
|
|
144
|
+
* `BasaltProvider`), read in UTC like the time scale; a non-midnight instant adds `HH:MM`. With
|
|
145
|
+
* `dayOnly` (a day-granular series) the instant is its bucket's DAY, never a clock time: see
|
|
146
|
+
* {@link bucketDay}.
|
|
147
|
+
*/
|
|
148
|
+
export function utcHeaderDate(d: Date, dayOnly = false): string {
|
|
149
|
+
if (!Number.isFinite(d.getTime())) return NON_FINITE
|
|
150
|
+
const date = headerDay(dayOnly ? bucketDay(d) : d)
|
|
151
|
+
if (dayOnly || d.getTime() % DAY_MS === 0) return date
|
|
152
|
+
return `${date} ${readoutClock(d)}`
|
|
137
153
|
}
|
|
138
154
|
|
|
139
155
|
const DAY_MS = 86_400_000
|
|
@@ -247,16 +263,48 @@ export function visibleSeries<T>(
|
|
|
247
263
|
|
|
248
264
|
type YAxis = { domain: readonly [number, number]; format: (v: number) => string }
|
|
249
265
|
|
|
266
|
+
/** The page locale's decimal separator (`.` or `,`). */
|
|
267
|
+
const decimalSeparator = (): string =>
|
|
268
|
+
numberFormat(undefined, {})
|
|
269
|
+
.formatToParts(1.1)
|
|
270
|
+
.find((p) => p.type === 'decimal')?.value ?? '.'
|
|
271
|
+
|
|
272
|
+
/** A trailing zero fraction behind a digit (`2.0`, `2,00`), the separator being a decimal one. */
|
|
273
|
+
const zeroFraction = (separator: string): RegExp =>
|
|
274
|
+
new RegExp(`(\\d)${separator.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}0+(?!\\d)`, 'g')
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The tick formatter. When every tick is a whole number (a whole step), a formatter that pads
|
|
278
|
+
* decimals (`toFixed(1)`) prints integers: `2 s`, not `2.0 s`. Only the page locale's decimal
|
|
279
|
+
* separator is read as one, so a thousands group (`1,000`, `1.000` in de) is never cut; a formatter
|
|
280
|
+
* that writes `.` under a `,` locale keeps its padding. The tooltip keeps the full format. The
|
|
281
|
+
* ticks are the engine's own (`count` goes through the same linear scale the engine builds).
|
|
282
|
+
*/
|
|
283
|
+
function wholeStepFormat<T>(
|
|
284
|
+
axis: YAxis,
|
|
285
|
+
cfg: AxisConfig<T> | undefined,
|
|
286
|
+
ticks: { values: readonly number[] } | { count: number },
|
|
287
|
+
): (v: number) => string {
|
|
288
|
+
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)]
|
|
289
|
+
const values =
|
|
290
|
+
'values' in ticks
|
|
291
|
+
? ticks.values
|
|
292
|
+
: cfg?.scale === 'log'
|
|
293
|
+
? []
|
|
294
|
+
: scaleLinear().domain([lo, hi]).ticks(ticks.count)
|
|
295
|
+
if (values.length === 0 || !values.every(Number.isInteger)) return axis.format
|
|
296
|
+
const padded = zeroFraction(decimalSeparator())
|
|
297
|
+
return (v) => axis.format(v).replace(padded, '$1')
|
|
298
|
+
}
|
|
299
|
+
|
|
250
300
|
export function yGuide<T>(opts: {
|
|
251
301
|
cfg: AxisConfig<T> | undefined
|
|
252
302
|
axis: YAxis
|
|
253
303
|
cls: ContainerClass
|
|
254
304
|
side: 'left' | 'right'
|
|
255
305
|
grid: boolean
|
|
256
|
-
/** The whole chart's height: decides inside or gutter labels. */
|
|
257
|
-
height: number
|
|
258
306
|
}): Omit<ChartPositionScaleOptions<number>, 'scale'> {
|
|
259
|
-
const { cfg, axis, cls, side, grid
|
|
307
|
+
const { cfg, axis, cls, side, grid } = opts
|
|
260
308
|
const ladder = LADDER[cls]
|
|
261
309
|
const ticks =
|
|
262
310
|
typeof cfg?.ticks === 'object'
|
|
@@ -264,23 +312,15 @@ export function yGuide<T>(opts: {
|
|
|
264
312
|
: { count: typeof cfg?.ticks === 'number' ? cfg.ticks : ladder.yTicks }
|
|
265
313
|
const gridLine = grid ? { grid: GRID_LINE } : {}
|
|
266
314
|
if (cls === 'micro') return { ...gridLine, axis: false }
|
|
267
|
-
|
|
268
|
-
|
|
315
|
+
const tickFormat = wholeStepFormat(axis, cfg, ticks)
|
|
316
|
+
// Labels sit in a gutter OUTSIDE the plot, against its edge: a line never runs through one.
|
|
269
317
|
return {
|
|
270
318
|
...gridLine,
|
|
271
319
|
...(side === 'right' && { side: 'right' as const }),
|
|
272
320
|
axis: {
|
|
273
321
|
line: false,
|
|
274
|
-
ticks: { ...ticks, format:
|
|
275
|
-
tickLabels: {
|
|
276
|
-
fontSize: TICK_FONT,
|
|
277
|
-
opacity: 1,
|
|
278
|
-
...(inside && {
|
|
279
|
-
anchor: side === 'left' ? ('start' as const) : ('end' as const),
|
|
280
|
-
dx: side === 'left' ? INSIDE_LABEL_DX : -INSIDE_LABEL_DX,
|
|
281
|
-
dy: INSIDE_LABEL_DY,
|
|
282
|
-
}),
|
|
283
|
-
},
|
|
322
|
+
ticks: { ...ticks, format: tickFormat, line: false },
|
|
323
|
+
tickLabels: { fontSize: TICK_FONT, opacity: 1 },
|
|
284
324
|
},
|
|
285
325
|
}
|
|
286
326
|
}
|
|
@@ -339,12 +379,9 @@ export function xGuide<X extends ChartX>(opts: {
|
|
|
339
379
|
/** A consumer's formatter; absent, Date ticks get the span-aware {@link xTickFormat}. */
|
|
340
380
|
format?: ((v: ChartValue) => string) | undefined
|
|
341
381
|
cls: ContainerClass
|
|
342
|
-
/** The whole chart's height: decides whether the left margin is locked to zero. */
|
|
343
|
-
height: number
|
|
344
382
|
}): Omit<ChartPositionScaleOptions<ChartValue>, 'scale'> {
|
|
345
|
-
const { model, xTicks, cls
|
|
383
|
+
const { model, xTicks, cls } = opts
|
|
346
384
|
const ladder = LADDER[cls]
|
|
347
|
-
const inside = labelsInside(cls, height)
|
|
348
385
|
const ticks = xTickPolicy(model, xTicks ?? ladder.xTicks)
|
|
349
386
|
// A Date axis always resolves to `values` (the time scale has an extent; a band axis lists its
|
|
350
387
|
// buckets), so `{ count }` is only ever a number axis and never needs the date formatter.
|
|
@@ -363,13 +400,10 @@ export function xGuide<X extends ChartX>(opts: {
|
|
|
363
400
|
opacity: 1,
|
|
364
401
|
thin: true,
|
|
365
402
|
// A label centred on a tick near the plot's left edge hangs left of it, under the gutter's
|
|
366
|
-
// lowest y label
|
|
367
|
-
|
|
368
|
-
anchor: ({ index, value }: { index: number; value: ChartValue }) => {
|
|
369
|
-
const pinnedFirst = inside && index === 0
|
|
403
|
+
// lowest y label: start-anchor it. `+value` is a Date's timestamp, or the number itself.
|
|
404
|
+
anchor: ({ value }: { value: ChartValue }) => {
|
|
370
405
|
const share = (+value - leftEdgeX) / spanX
|
|
371
|
-
|
|
372
|
-
return pinnedFirst || onLeftEdge ? ('start' as const) : undefined
|
|
406
|
+
return share >= 0 && share <= LEFT_EDGE_SHARE ? ('start' as const) : undefined
|
|
373
407
|
},
|
|
374
408
|
},
|
|
375
409
|
},
|
|
@@ -536,6 +570,7 @@ function leftDomain<T, X extends ChartX>(
|
|
|
536
570
|
input: CartesianInput<T, X>,
|
|
537
571
|
series: readonly ChartSeries<T>[],
|
|
538
572
|
bounds: readonly number[],
|
|
573
|
+
tickCount: number,
|
|
539
574
|
): readonly [number, number] {
|
|
540
575
|
const auto = input.y?.domain === undefined || input.y.domain === 'auto'
|
|
541
576
|
if (auto && input.stack === 'normalized') return normalizedDomain(input.data, series)
|
|
@@ -544,6 +579,7 @@ function leftDomain<T, X extends ChartX>(
|
|
|
544
579
|
input.data,
|
|
545
580
|
auto && input.stack ? stackedSeries(series) : series,
|
|
546
581
|
bounds,
|
|
582
|
+
tickCount,
|
|
547
583
|
)
|
|
548
584
|
}
|
|
549
585
|
|
|
@@ -551,8 +587,12 @@ function leftDomain<T, X extends ChartX>(
|
|
|
551
587
|
function resolveAxes<T, X extends ChartX>(
|
|
552
588
|
input: CartesianInput<T, X>,
|
|
553
589
|
visible: readonly ChartSeries<T>[],
|
|
590
|
+
cls: ContainerClass,
|
|
554
591
|
): Axes<T> {
|
|
555
592
|
const hasY2 = input.y2 !== undefined
|
|
593
|
+
// Ticks the axis draws at this class: a domain that ends on one never leaves the data above the top label.
|
|
594
|
+
const tickCount = (cfg: AxisConfig<T> | undefined): number =>
|
|
595
|
+
typeof cfg?.ticks === 'object' ? 0 : (cfg?.ticks ?? LADDER[cls].yTicks)
|
|
556
596
|
const bounds = overlayBounds(input)
|
|
557
597
|
const onRight = (s: ChartSeries<T>): boolean => hasY2 && s.axis === 'right'
|
|
558
598
|
const left: YAxis = {
|
|
@@ -560,12 +600,19 @@ function resolveAxes<T, X extends ChartX>(
|
|
|
560
600
|
input,
|
|
561
601
|
visible.filter((s) => !onRight(s)),
|
|
562
602
|
bounds.left,
|
|
603
|
+
tickCount(input.y),
|
|
563
604
|
),
|
|
564
605
|
format: input.y?.format ?? defaultNumberFormat,
|
|
565
606
|
}
|
|
566
607
|
const right: YAxis | null = hasY2
|
|
567
608
|
? {
|
|
568
|
-
domain: resolveYDomain(
|
|
609
|
+
domain: resolveYDomain(
|
|
610
|
+
input.y2,
|
|
611
|
+
input.data,
|
|
612
|
+
visible.filter(onRight),
|
|
613
|
+
bounds.right,
|
|
614
|
+
tickCount(input.y2),
|
|
615
|
+
),
|
|
569
616
|
format: input.y2?.format ?? defaultNumberFormat,
|
|
570
617
|
}
|
|
571
618
|
: null
|
|
@@ -686,17 +733,42 @@ function underlayMarks<T, X extends ChartX>(
|
|
|
686
733
|
return [...zones, ...xZones]
|
|
687
734
|
}
|
|
688
735
|
|
|
689
|
-
/** A
|
|
690
|
-
const
|
|
736
|
+
/** A band's bar spans this share of its half step (`paddingInner` 0.2 leaves 0.8 of the step). */
|
|
737
|
+
const BAR_BODY = 0.8
|
|
691
738
|
const REF_LABEL_DX = 6
|
|
692
739
|
const REF_LABEL_DY_ABOVE = -5
|
|
693
740
|
const REF_LABEL_DY_BELOW = 11
|
|
694
741
|
|
|
695
|
-
/**
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
742
|
+
/** What a reference line's caption needs to choose its spot: the plot in px and the data on its axis. */
|
|
743
|
+
type RefLabelContext<T, X extends ChartX> = {
|
|
744
|
+
plotWidth: number
|
|
745
|
+
plotHeight: number
|
|
746
|
+
/** One polyline per visible series on the line's axis. */
|
|
747
|
+
lines: (side: 'left' | 'right' | undefined) => readonly (readonly RefLabelPoint[])[]
|
|
748
|
+
axes: Axes<T>
|
|
749
|
+
model: XScaleModel<X>
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/** The caption naming a reference line, at the spot {@link refLabelPosition} picks. */
|
|
753
|
+
const refLabelMark = <T, X extends ChartX>(
|
|
754
|
+
r: RefLine,
|
|
755
|
+
i: number,
|
|
756
|
+
ctx: RefLabelContext<T, X>,
|
|
757
|
+
): ChartMarks[number] => {
|
|
758
|
+
const { axes } = ctx
|
|
759
|
+
const startFirst = r.axis === 'right' && axes.scaleId(r.axis) === 'y2'
|
|
760
|
+
const position = refLabelPosition({
|
|
761
|
+
pinned: r.labelPosition,
|
|
762
|
+
startFirst,
|
|
763
|
+
value: r.value,
|
|
764
|
+
domain: axes.axisOf(r.axis).domain,
|
|
765
|
+
plotWidth: ctx.plotWidth,
|
|
766
|
+
plotHeight: ctx.plotHeight,
|
|
767
|
+
label: r.label ?? '',
|
|
768
|
+
fontSize: VX.text.micro,
|
|
769
|
+
series: ctx.lines(r.axis),
|
|
770
|
+
})
|
|
771
|
+
const atStart = position.startsWith('start')
|
|
700
772
|
return decorative(
|
|
701
773
|
text([{ f: atStart ? 0 : 1 }], {
|
|
702
774
|
id: `ref-${i}-label`,
|
|
@@ -709,15 +781,16 @@ const refLabelMark = <T>(r: RefLine, i: number, axes: Axes<T>): ChartMarks[numbe
|
|
|
709
781
|
fontSize: VX.text.micro,
|
|
710
782
|
anchor: atStart ? 'start' : 'end',
|
|
711
783
|
dx: atStart ? REF_LABEL_DX : -REF_LABEL_DX,
|
|
712
|
-
dy:
|
|
784
|
+
dy: position.endsWith('above') ? REF_LABEL_DY_ABOVE : REF_LABEL_DY_BELOW,
|
|
713
785
|
}),
|
|
714
786
|
)
|
|
715
787
|
}
|
|
716
788
|
|
|
717
|
-
/** Reference lines, over the marks. */
|
|
789
|
+
/** Reference lines, over the marks. `label` reads the plot size, so only a chart with an unpinned caption pays for it. */
|
|
718
790
|
const refLineMarks = <T, X extends ChartX>(
|
|
719
791
|
input: CartesianInput<T, X>,
|
|
720
792
|
axes: Axes<T>,
|
|
793
|
+
label: () => RefLabelContext<T, X>,
|
|
721
794
|
): ChartMarks =>
|
|
722
795
|
(input.refLines ?? []).flatMap((r, i) =>
|
|
723
796
|
// A line that names itself in the legend can be toggled off there.
|
|
@@ -732,7 +805,7 @@ const refLineMarks = <T, X extends ChartX>(
|
|
|
732
805
|
yScale: axes.scaleId(r.axis),
|
|
733
806
|
...(r.dashed && { strokeDasharray: DASH }),
|
|
734
807
|
}),
|
|
735
|
-
...(r.label ? [refLabelMark(r, i,
|
|
808
|
+
...(r.label ? [refLabelMark(r, i, label())] : []),
|
|
736
809
|
],
|
|
737
810
|
)
|
|
738
811
|
|
|
@@ -742,10 +815,9 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
742
815
|
axes: Axes<T>
|
|
743
816
|
formatX: (v: ChartValue) => string
|
|
744
817
|
cls: ContainerClass
|
|
745
|
-
height: number
|
|
746
818
|
zoneScale: boolean
|
|
747
819
|
}): StoredChartSpec['scales'] {
|
|
748
|
-
const { input, model, axes, formatX, cls,
|
|
820
|
+
const { input, model, axes, formatX, cls, zoneScale } = opts
|
|
749
821
|
const { left, right } = axes
|
|
750
822
|
return {
|
|
751
823
|
x: {
|
|
@@ -755,7 +827,6 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
755
827
|
xTicks: input.xTicks,
|
|
756
828
|
format: input.formatX ? formatX : undefined,
|
|
757
829
|
cls,
|
|
758
|
-
height,
|
|
759
830
|
}),
|
|
760
831
|
},
|
|
761
832
|
y: {
|
|
@@ -764,7 +835,6 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
764
835
|
cfg: input.y,
|
|
765
836
|
axis: left,
|
|
766
837
|
cls,
|
|
767
|
-
height,
|
|
768
838
|
side: 'left',
|
|
769
839
|
grid: input.y?.grid ?? true,
|
|
770
840
|
}),
|
|
@@ -777,7 +847,6 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
777
847
|
cfg: input.y2,
|
|
778
848
|
axis: right,
|
|
779
849
|
cls,
|
|
780
|
-
height,
|
|
781
850
|
side: 'right',
|
|
782
851
|
grid: input.y2?.grid ?? false,
|
|
783
852
|
}),
|
|
@@ -789,18 +858,50 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
789
858
|
}
|
|
790
859
|
}
|
|
791
860
|
|
|
792
|
-
/**
|
|
861
|
+
/**
|
|
862
|
+
* The tooltip title: the consumer's header, a long UTC date for a Date x, else the axis format. A
|
|
863
|
+
* day-granular series keeps its long date under a consumer `formatX` too: that formatter shortens
|
|
864
|
+
* the ticks (`2 Sep`), it does not rename the day.
|
|
865
|
+
*/
|
|
793
866
|
function tooltipHeader<T, X extends ChartX>(
|
|
794
867
|
input: CartesianInput<T, X>,
|
|
795
868
|
formatX: (v: ChartValue) => string,
|
|
869
|
+
dayOnly: boolean,
|
|
796
870
|
v: ChartValue,
|
|
797
871
|
d: T,
|
|
798
872
|
): string {
|
|
799
873
|
if (input.tooltip && input.tooltip.formatHeader) return input.tooltip.formatHeader(v as X, d)
|
|
800
|
-
if (v instanceof Date && !input.formatX) return utcHeaderDate(v)
|
|
874
|
+
if (v instanceof Date && (!input.formatX || dayOnly)) return utcHeaderDate(v, dayOnly)
|
|
801
875
|
return formatX(v)
|
|
802
876
|
}
|
|
803
877
|
|
|
878
|
+
/**
|
|
879
|
+
* A day-granular x: every step between its distinct instants is a whole day or more (23 h: a DST
|
|
880
|
+
* day), or its one instant is a UTC midnight. The tooltip header of such a series is its date, never
|
|
881
|
+
* a clock time (a bucket keyed by local midnight is `22:00` UTC in a UTC+2 zone).
|
|
882
|
+
*/
|
|
883
|
+
export function dayGranular(values: readonly ChartX[]): boolean {
|
|
884
|
+
const times = values.flatMap((v) => (v instanceof Date ? [v.getTime()] : []))
|
|
885
|
+
if (times.length === 0 || times.length !== values.length) return false
|
|
886
|
+
const sorted = times.toSorted((a, b) => a - b)
|
|
887
|
+
if (sorted.length === 1) return (sorted[0] as number) % DAY_MS === 0
|
|
888
|
+
// 23 h, not 24: a local-midnight key is only 23 h after the previous one across a spring-forward DST.
|
|
889
|
+
return sorted.every((t, i) => i === 0 || t - (sorted[i - 1] as number) >= DAY_MS - HOUR_MS)
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const HOUR_MS = 3_600_000
|
|
893
|
+
|
|
894
|
+
/** The word without its case or a plural `s`: `Sessions` and `session` are one unit. */
|
|
895
|
+
const stem = (w: string): string => w.toLowerCase().replace(/s$/, '')
|
|
896
|
+
|
|
897
|
+
/** A row's label repeats the unit its value already carries (`Sessions` / `27 sessions`). */
|
|
898
|
+
function unitIsName(label: string, value: string): string | null {
|
|
899
|
+
const words = value.trim().split(/\s+/)
|
|
900
|
+
const unit = words.at(-1)
|
|
901
|
+
if (words.length < 2 || unit === undefined || stem(unit) !== stem(label.trim())) return null
|
|
902
|
+
return words.slice(0, -1).join(' ')
|
|
903
|
+
}
|
|
904
|
+
|
|
804
905
|
/** `plot.rows`: one row per datum for a visible series, `[]` for a hidden one, a throw for a typo. */
|
|
805
906
|
function rowsOf<T, X extends ChartX>(
|
|
806
907
|
input: CartesianInput<T, X>,
|
|
@@ -843,6 +944,22 @@ function cursorDotMarks<T, X extends ChartX>(
|
|
|
843
944
|
})
|
|
844
945
|
}
|
|
845
946
|
|
|
947
|
+
/**
|
|
948
|
+
* `tooltipBelow` (a `BandStrip`, a short bar of cells under a hero value and beside its neighbours):
|
|
949
|
+
* the tooltip opens below the strip, above only when there is no room, so it never covers the
|
|
950
|
+
* cell's own value, with a gap clear of the cell edge.
|
|
951
|
+
*/
|
|
952
|
+
/** The hovered cell's centre x, on the strip's bottom edge: `bottom` opens just under the strip. */
|
|
953
|
+
const stripAnchor = (
|
|
954
|
+
points: readonly ChartPoint[],
|
|
955
|
+
{ plot }: ChartTooltipAnchorContext,
|
|
956
|
+
): { x: number; y: number } => {
|
|
957
|
+
const xs = points.map((p) => p.x)
|
|
958
|
+
return { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: plot.y + plot.height }
|
|
959
|
+
}
|
|
960
|
+
const STRIP_TOOLTIP_PLACEMENT = ['bottom', 'top'] as const
|
|
961
|
+
const STRIP_TOOLTIP_OFFSET = 8
|
|
962
|
+
|
|
846
963
|
function tooltipSpec<T, X extends ChartX>(opts: {
|
|
847
964
|
input: CartesianInput<T, X>
|
|
848
965
|
axes: Axes<T>
|
|
@@ -850,8 +967,10 @@ function tooltipSpec<T, X extends ChartX>(opts: {
|
|
|
850
967
|
keys: ReadonlySet<string>
|
|
851
968
|
visibleKeys: ReadonlySet<string>
|
|
852
969
|
formatX: (v: ChartValue) => string
|
|
970
|
+
/** The x is day-granular: the header is a date, not a clock time. */
|
|
971
|
+
dayOnly: boolean
|
|
853
972
|
}): NonNullable<CartesianDefinition['tooltip']> {
|
|
854
|
-
const { input, axes, visible, keys, visibleKeys, formatX } = opts
|
|
973
|
+
const { input, axes, visible, keys, visibleKeys, formatX, dayOnly } = opts
|
|
855
974
|
const hidden = input.series.filter((s) => !visibleKeys.has(s.key))
|
|
856
975
|
const rowSeries = (input.reverseRows ? visible.toReversed() : visible).filter(
|
|
857
976
|
(s) => s.tooltip !== false,
|
|
@@ -860,7 +979,8 @@ function tooltipSpec<T, X extends ChartX>(opts: {
|
|
|
860
979
|
use: quietWhileFollowing,
|
|
861
980
|
...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
|
|
862
981
|
portal,
|
|
863
|
-
anchor: 'group-center',
|
|
982
|
+
anchor: input.tooltipBelow ? stripAnchor : 'group-center',
|
|
983
|
+
...(input.tooltipBelow && { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET }),
|
|
864
984
|
content: (points: readonly ChartPoint[]) => {
|
|
865
985
|
const primary = points[0]
|
|
866
986
|
if (!primary) return { rows: [] }
|
|
@@ -875,20 +995,17 @@ function tooltipSpec<T, X extends ChartX>(opts: {
|
|
|
875
995
|
for (const s of rowSeries) {
|
|
876
996
|
const v = s.getValue(d)
|
|
877
997
|
if (v === null || !Number.isFinite(v)) continue
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
input.highlighted === s.key,
|
|
885
|
-
),
|
|
886
|
-
)
|
|
998
|
+
const text = s.formatValue
|
|
999
|
+
? s.formatValue(v, d)
|
|
1000
|
+
: axes.axisOf(axes.onRight(s) ? 'right' : 'left').format(v)
|
|
1001
|
+
// A lone series whose value already ends in its own name (`27 sessions`) prints the name once.
|
|
1002
|
+
const bare = input.series.length === 1 ? unitIsName(s.label, text) : null
|
|
1003
|
+
rows.push(seriesRow(s, bare ?? text, input.highlighted === s.key))
|
|
887
1004
|
}
|
|
888
1005
|
const extra: readonly ChartTooltipRow[] =
|
|
889
1006
|
(input.tooltip || undefined)?.rows?.(d, { visible, hidden }) ?? []
|
|
890
1007
|
return {
|
|
891
|
-
title: tooltipHeader(input, formatX, x, d),
|
|
1008
|
+
title: tooltipHeader(input, formatX, dayOnly, x, d),
|
|
892
1009
|
rows: [...rows, ...extra.map(engineRow)],
|
|
893
1010
|
}
|
|
894
1011
|
},
|
|
@@ -913,20 +1030,51 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
913
1030
|
const visibleKeys = new Set(visible.map((s) => s.key))
|
|
914
1031
|
const keys = new Set(input.series.map((s) => s.key))
|
|
915
1032
|
const model = xScaleFor(input.data.map(input.x), input.band === true, input.xDomain)
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
const
|
|
1033
|
+
// The y domain depends on the tick count, so on the class; everything else about the axes
|
|
1034
|
+
// (formats, sides) does not, and `shared` stands for it.
|
|
1035
|
+
const byClass = new Map<ContainerClass, Axes<T>>()
|
|
1036
|
+
const axesAt = (cls: ContainerClass): Axes<T> => {
|
|
1037
|
+
const found = byClass.get(cls)
|
|
1038
|
+
if (found) return found
|
|
1039
|
+
const made = resolveAxes(input, visible, cls)
|
|
1040
|
+
byClass.set(cls, made)
|
|
1041
|
+
return made
|
|
1042
|
+
}
|
|
1043
|
+
const shared = axesAt('regular')
|
|
1044
|
+
const dots = cursorDotMarks(input, visible, shared)
|
|
920
1045
|
const rows = rowsOf(input, visibleKeys)
|
|
921
1046
|
const formatX = (v: ChartValue): string =>
|
|
922
1047
|
input.formatX ? input.formatX(v as X) : defaultFormatX(v)
|
|
923
1048
|
const gradients = input.series.flatMap((s, i) =>
|
|
924
|
-
s.area ? [seriesAreaGradient(s, i, input,
|
|
1049
|
+
s.area ? [seriesAreaGradient(s, i, input, shared)] : [],
|
|
925
1050
|
)
|
|
1051
|
+
const dayOnly = dayGranular(model.values)
|
|
1052
|
+
const names = (input.refLines ?? []).some((r) => r.label !== undefined && r.label !== '')
|
|
1053
|
+
// What an unpinned reference caption avoids: each visible series as (x share, y) points. A bar is
|
|
1054
|
+
// a filled column from zero, so it walks round its body instead of through its top centre.
|
|
1055
|
+
const barHalf = model.halfStep * BAR_BODY
|
|
1056
|
+
const linesOn = (side: 'left' | 'right' | undefined): RefLabelPoint[][] =>
|
|
1057
|
+
visible
|
|
1058
|
+
.filter((s) => shared.onRight(s) === (side === 'right' && shared.right !== null))
|
|
1059
|
+
.map((s) =>
|
|
1060
|
+
rows(s.key).flatMap((r) => {
|
|
1061
|
+
const fx = model.fraction(r.x)
|
|
1062
|
+
if (fx === null || r.y === null) return []
|
|
1063
|
+
if (!(model.band && s.mark === 'bar')) return [{ fx, y: r.y }]
|
|
1064
|
+
return [
|
|
1065
|
+
{ fx: fx - barHalf, y: 0 },
|
|
1066
|
+
{ fx: fx - barHalf, y: r.y },
|
|
1067
|
+
{ fx: fx + barHalf, y: r.y },
|
|
1068
|
+
{ fx: fx + barHalf, y: 0 },
|
|
1069
|
+
]
|
|
1070
|
+
}),
|
|
1071
|
+
)
|
|
926
1072
|
|
|
927
1073
|
const definition: CartesianDefinition = {
|
|
928
1074
|
chart: ({ width, height }: ChartBuildContext): StoredChartSpec => {
|
|
929
1075
|
const cls = resolveContainerClass(width)
|
|
1076
|
+
const axes = axesAt(cls)
|
|
1077
|
+
const access = plotAccess(definition, input.plot, MAIN_PANE)
|
|
930
1078
|
const kindMarks = input.marks(
|
|
931
1079
|
plotContext(
|
|
932
1080
|
{
|
|
@@ -942,29 +1090,47 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
942
1090
|
yDomain: axes.left.domain,
|
|
943
1091
|
y2Domain: axes.right?.domain,
|
|
944
1092
|
},
|
|
945
|
-
|
|
1093
|
+
access,
|
|
946
1094
|
),
|
|
947
1095
|
)
|
|
1096
|
+
const under = underlayMarks(input, model, axes)
|
|
1097
|
+
const over = refLineMarks(input, axes, () => {
|
|
1098
|
+
// Reading the plot size recompiles once on the measured area; the frame stands in before it.
|
|
1099
|
+
access.read()
|
|
1100
|
+
const size = access.size()
|
|
1101
|
+
return {
|
|
1102
|
+
plotWidth: size?.width ?? width,
|
|
1103
|
+
plotHeight: size?.height ?? height,
|
|
1104
|
+
lines: linesOn,
|
|
1105
|
+
axes,
|
|
1106
|
+
model,
|
|
1107
|
+
}
|
|
1108
|
+
})
|
|
948
1109
|
return {
|
|
949
|
-
marks: [
|
|
1110
|
+
marks: [
|
|
1111
|
+
...under,
|
|
1112
|
+
...kindMarks,
|
|
1113
|
+
...dots,
|
|
1114
|
+
...over,
|
|
1115
|
+
...(input.crosshair === false ? [] : [crosshair({ x: CROSSHAIR, y: false })]),
|
|
1116
|
+
],
|
|
950
1117
|
scales: buildScales({
|
|
951
1118
|
input,
|
|
952
1119
|
model,
|
|
953
1120
|
axes,
|
|
954
1121
|
formatX,
|
|
955
1122
|
cls,
|
|
956
|
-
|
|
957
|
-
zoneScale: under.length > 0 || (input.refLines ?? []).some((r) => r.label),
|
|
1123
|
+
zoneScale: under.length > 0 || names,
|
|
958
1124
|
}),
|
|
959
1125
|
theme: CHART_THEME,
|
|
960
1126
|
...(gradients.length > 0 && { gradients }),
|
|
961
1127
|
clip: true,
|
|
962
|
-
...(labelsInside(cls, height) && { margin: { left: 0, ...(axes.right && { right: 0 }) } }),
|
|
963
1128
|
}
|
|
964
1129
|
},
|
|
965
1130
|
// Followers resolve the leader's group, so they draw its dots; `quietWhileFollowing` mutes the
|
|
966
1131
|
// tooltip unless the chart opts into following tooltips.
|
|
967
1132
|
focus: 'group-x',
|
|
1133
|
+
...(input.focusRing === false && { focusRing: false as const }),
|
|
968
1134
|
maxFocusDistance: Number.POSITIVE_INFINITY,
|
|
969
1135
|
cursor: cursorBinding({
|
|
970
1136
|
group: input.cursorGroup,
|
|
@@ -977,7 +1143,7 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
977
1143
|
tooltip:
|
|
978
1144
|
input.tooltip === false
|
|
979
1145
|
? false
|
|
980
|
-
: tooltipSpec({ input, axes, visible, keys, visibleKeys, formatX }),
|
|
1146
|
+
: tooltipSpec({ input, axes: shared, visible, keys, visibleKeys, formatX, dayOnly }),
|
|
981
1147
|
}
|
|
982
1148
|
return definition
|
|
983
1149
|
}
|