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/dist/charts/compile.d.ts
CHANGED
|
@@ -26,10 +26,27 @@ export type CartesianInput<T, X extends ChartX> = Pick<CartesianChartProps<T, X>
|
|
|
26
26
|
stack?: 'stacked' | 'normalized';
|
|
27
27
|
/** The plot area the engine last laid out; `null` before the first layout (the frame stands in). */
|
|
28
28
|
plot?: PlotSizes | null;
|
|
29
|
+
/** The tooltip opens below the chart (a strip of cells), above only when there is no room. */
|
|
30
|
+
tooltipBelow?: boolean;
|
|
31
|
+
/** The vertical rule under the cursor. Default `true`; a bar kind has none (its hover is the bar). */
|
|
32
|
+
crosshair?: boolean;
|
|
33
|
+
/** The engine's point marker on the focused datum. Default `true`; a bar kind has none (its hover is the bar). */
|
|
34
|
+
focusRing?: boolean;
|
|
29
35
|
};
|
|
30
36
|
export declare function defaultNumberFormat(v: number): string;
|
|
31
|
-
/**
|
|
32
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The UTC midnight of the day a day-keyed instant stands for. A key at LOCAL midnight is that local
|
|
39
|
+
* calendar date (east of UTC it is `22:00` UTC of the day before); any other key is its UTC date, so
|
|
40
|
+
* a key at 12:00 UTC or later never rolls to the next day.
|
|
41
|
+
*/
|
|
42
|
+
export declare function bucketDay(d: Date): Date;
|
|
43
|
+
/**
|
|
44
|
+
* The tooltip's date: weekday, day, month and year in the page's locale (`defineFormat` /
|
|
45
|
+
* `BasaltProvider`), read in UTC like the time scale; a non-midnight instant adds `HH:MM`. With
|
|
46
|
+
* `dayOnly` (a day-granular series) the instant is its bucket's DAY, never a clock time: see
|
|
47
|
+
* {@link bucketDay}.
|
|
48
|
+
*/
|
|
49
|
+
export declare function utcHeaderDate(d: Date, dayOnly?: boolean): string;
|
|
33
50
|
/**
|
|
34
51
|
* Default Date tick values: the time scale's own ticks, kept to whole UTC days once the data is
|
|
35
52
|
* daily or coarser — d3 picks 12-hour steps for a short daily series, which label one day twice.
|
|
@@ -61,8 +78,6 @@ export declare function yGuide<T>(opts: {
|
|
|
61
78
|
cls: ContainerClass;
|
|
62
79
|
side: 'left' | 'right';
|
|
63
80
|
grid: boolean;
|
|
64
|
-
/** The whole chart's height: decides inside or gutter labels. */
|
|
65
|
-
height: number;
|
|
66
81
|
}): Omit<ChartPositionScaleOptions<number>, 'scale'>;
|
|
67
82
|
/**
|
|
68
83
|
* Every n-th value, n the smallest stride that leaves at most the class's x tick count (the same
|
|
@@ -82,8 +97,6 @@ export declare function xGuide<X extends ChartX>(opts: {
|
|
|
82
97
|
/** A consumer's formatter; absent, Date ticks get the span-aware {@link xTickFormat}. */
|
|
83
98
|
format?: ((v: ChartValue) => string) | undefined;
|
|
84
99
|
cls: ContainerClass;
|
|
85
|
-
/** The whole chart's height: decides whether the left margin is locked to zero. */
|
|
86
|
-
height: number;
|
|
87
100
|
}): Omit<ChartPositionScaleOptions<ChartValue>, 'scale'>;
|
|
88
101
|
/** Gradient resource id for a series' area fill; the host's `idPrefix` scopes it per chart. */
|
|
89
102
|
export declare const areaGradientId: (index: number) => string;
|
|
@@ -98,6 +111,12 @@ export declare function areaGradient(index: number, color: string): ChartGradien
|
|
|
98
111
|
* reaches the area (the caller keeps the plain series-colour fade). Linear axes only.
|
|
99
112
|
*/
|
|
100
113
|
export declare function zoneAreaGradient(index: number, zones: readonly ZoneSpec[], values: readonly (number | null)[]): ChartGradient | null;
|
|
114
|
+
/**
|
|
115
|
+
* A day-granular x: every step between its distinct instants is a whole day or more (23 h: a DST
|
|
116
|
+
* day), or its one instant is a UTC midnight. The tooltip header of such a series is its date, never
|
|
117
|
+
* a clock time (a bucket keyed by local midnight is `22:00` UTC in a UTC+2 zone).
|
|
118
|
+
*/
|
|
119
|
+
export declare function dayGranular(values: readonly ChartX[]): boolean;
|
|
101
120
|
export declare function compileCartesian<T, X extends ChartX>(input: CartesianInput<T, X>): CartesianDefinition;
|
|
102
121
|
export {};
|
|
103
122
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings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ACzF,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IAChD,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,CA6BvD;AAED,+FAA+F;AAC/F,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAAgC,CAAA;AAE/E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAYxE;AAKD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GACjC,aAAa,GAAG,IAAI,CAuBtB;AAyZD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAO9D;AAuID,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAClD,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1B,mBAAmB,CA0HrB"}
|
package/dist/charts/compile.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { headerDay, readoutClock } from "./chart-dates.js";
|
|
2
|
+
import { dateTickFormat, utcAxisDate } from "./date-tick-format.js";
|
|
2
3
|
import { crosshair } from "@tanstack/charts/crosshair";
|
|
3
4
|
import { decorative } from "@tanstack/charts/mark/decorative";
|
|
4
5
|
import { rect } from "@tanstack/charts/rect";
|
|
@@ -7,13 +8,14 @@ import { ruleX, ruleY } from "@tanstack/charts/rule";
|
|
|
7
8
|
import { scaleLinear } from "@tanstack/charts/scales/linear";
|
|
8
9
|
import { scaleUtc } from "d3-scale";
|
|
9
10
|
import { portal } from "@tanstack/charts/tooltip/portal";
|
|
10
|
-
import { SHORT_CHART_HEIGHT } from "./box.js";
|
|
11
11
|
import { compact } from "../format/number.js";
|
|
12
|
+
import { NON_FINITE, numberFormat } from "../format/shared.js";
|
|
12
13
|
import { VX } from "../tokens/index.js";
|
|
13
14
|
import { cursorBinding, followerOptions, quietWhileFollowing } from "./cursor.js";
|
|
14
15
|
import { cursorDots } from "./marks.js";
|
|
15
16
|
import { bucketTicks, strideEvery } from "./ticks.js";
|
|
16
17
|
import { MAIN_PANE, plotAccess, plotContext } from "./plot-context.js";
|
|
18
|
+
import { refLabelPosition } from "./ref-label.js";
|
|
17
19
|
import { resolveContainerClass } from "../tokens/size-classes.js";
|
|
18
20
|
import { resolveYDomain, xScaleFor, xZoneFractions, yScaleFor } from "./scales.js";
|
|
19
21
|
import { AXIS_LINE, CHART_THEME, CROSSHAIR, DASH, GRID_LINE } from "./theme.js";
|
|
@@ -24,18 +26,21 @@ const LADDER = {
|
|
|
24
26
|
regular: { xTicks: 5, yTicks: 5 },
|
|
25
27
|
wide: { xTicks: 6, yTicks: 5 }
|
|
26
28
|
};
|
|
27
|
-
const INSIDE_LABEL_DX = 4;
|
|
28
29
|
const LEFT_EDGE_SHARE = 0.05;
|
|
29
|
-
const INSIDE_LABEL_DY = -6;
|
|
30
|
-
const labelsInside = (cls, height) => cls === "compact" && height > 0 && height < SHORT_CHART_HEIGHT;
|
|
31
30
|
function defaultNumberFormat(v) {
|
|
32
31
|
return compact(v, { digits: Math.abs(v) >= 1e3 ? 1 : 2 });
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
function bucketDay(d) {
|
|
34
|
+
const local = d.getHours() === 0 && d.getMinutes() === 0 && d.getSeconds() === 0;
|
|
35
|
+
return new Date(
|
|
36
|
+
local ? Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) : Math.floor(d.getTime() / DAY_MS) * DAY_MS
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function utcHeaderDate(d, dayOnly = false) {
|
|
40
|
+
if (!Number.isFinite(d.getTime())) return NON_FINITE;
|
|
41
|
+
const date = headerDay(dayOnly ? bucketDay(d) : d);
|
|
42
|
+
if (dayOnly || d.getTime() % DAY_MS === 0) return date;
|
|
43
|
+
return `${date} ${readoutClock(d)}`;
|
|
39
44
|
}
|
|
40
45
|
const DAY_MS = 864e5;
|
|
41
46
|
function dateTicks(domain, count, stepMs) {
|
|
@@ -102,28 +107,29 @@ function visibleSeries(series, hidden) {
|
|
|
102
107
|
(s) => !hidden.has(s.key) && !(s.parent !== void 0 && hidden.has(s.parent))
|
|
103
108
|
);
|
|
104
109
|
}
|
|
110
|
+
const decimalSeparator = () => numberFormat(void 0, {}).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
111
|
+
const zeroFraction = (separator) => new RegExp(`(\\d)${separator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}0+(?!\\d)`, "g");
|
|
112
|
+
function wholeStepFormat(axis, cfg, ticks) {
|
|
113
|
+
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)];
|
|
114
|
+
const values = "values" in ticks ? ticks.values : cfg?.scale === "log" ? [] : scaleLinear().domain([lo, hi]).ticks(ticks.count);
|
|
115
|
+
if (values.length === 0 || !values.every(Number.isInteger)) return axis.format;
|
|
116
|
+
const padded = zeroFraction(decimalSeparator());
|
|
117
|
+
return (v) => axis.format(v).replace(padded, "$1");
|
|
118
|
+
}
|
|
105
119
|
function yGuide(opts) {
|
|
106
|
-
const { cfg, axis, cls, side, grid
|
|
120
|
+
const { cfg, axis, cls, side, grid } = opts;
|
|
107
121
|
const ladder = LADDER[cls];
|
|
108
122
|
const ticks = typeof cfg?.ticks === "object" ? { values: cfg.ticks } : { count: typeof cfg?.ticks === "number" ? cfg.ticks : ladder.yTicks };
|
|
109
123
|
const gridLine = grid ? { grid: GRID_LINE } : {};
|
|
110
124
|
if (cls === "micro") return { ...gridLine, axis: false };
|
|
111
|
-
const
|
|
125
|
+
const tickFormat = wholeStepFormat(axis, cfg, ticks);
|
|
112
126
|
return {
|
|
113
127
|
...gridLine,
|
|
114
128
|
...side === "right" && { side: "right" },
|
|
115
129
|
axis: {
|
|
116
130
|
line: false,
|
|
117
|
-
ticks: { ...ticks, format:
|
|
118
|
-
tickLabels: {
|
|
119
|
-
fontSize: TICK_FONT,
|
|
120
|
-
opacity: 1,
|
|
121
|
-
...inside && {
|
|
122
|
-
anchor: side === "left" ? "start" : "end",
|
|
123
|
-
dx: side === "left" ? INSIDE_LABEL_DX : -INSIDE_LABEL_DX,
|
|
124
|
-
dy: INSIDE_LABEL_DY
|
|
125
|
-
}
|
|
126
|
-
}
|
|
131
|
+
ticks: { ...ticks, format: tickFormat, line: false },
|
|
132
|
+
tickLabels: { fontSize: TICK_FONT, opacity: 1 }
|
|
127
133
|
}
|
|
128
134
|
};
|
|
129
135
|
}
|
|
@@ -155,9 +161,8 @@ function xTickFormat(consumer, tickValues) {
|
|
|
155
161
|
return (v) => v instanceof Date ? dateFormat(v) : defaultFormatX(v);
|
|
156
162
|
}
|
|
157
163
|
function xGuide(opts) {
|
|
158
|
-
const { model, xTicks, cls
|
|
164
|
+
const { model, xTicks, cls } = opts;
|
|
159
165
|
const ladder = LADDER[cls];
|
|
160
|
-
const inside = labelsInside(cls, height);
|
|
161
166
|
const ticks = xTickPolicy(model, xTicks ?? ladder.xTicks);
|
|
162
167
|
const format = xTickFormat(opts.format, "values" in ticks ? ticks.values : []);
|
|
163
168
|
const [leftEdgeX, spanX] = !model.band && model.extent ? [model.extent[0], model.extent[1] - model.extent[0]] : [Number.NaN, Number.NaN];
|
|
@@ -170,13 +175,10 @@ function xGuide(opts) {
|
|
|
170
175
|
opacity: 1,
|
|
171
176
|
thin: true,
|
|
172
177
|
// A label centred on a tick near the plot's left edge hangs left of it, under the gutter's
|
|
173
|
-
// lowest y label
|
|
174
|
-
|
|
175
|
-
anchor: ({ index, value }) => {
|
|
176
|
-
const pinnedFirst = inside && index === 0;
|
|
178
|
+
// lowest y label: start-anchor it. `+value` is a Date's timestamp, or the number itself.
|
|
179
|
+
anchor: ({ value }) => {
|
|
177
180
|
const share = (+value - leftEdgeX) / spanX;
|
|
178
|
-
|
|
179
|
-
return pinnedFirst || onLeftEdge ? "start" : void 0;
|
|
181
|
+
return share >= 0 && share <= LEFT_EDGE_SHARE ? "start" : void 0;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
}
|
|
@@ -279,30 +281,39 @@ function overlayBounds(input) {
|
|
|
279
281
|
for (const l of input.refLines ?? []) bounds[sideOf(l.axis)].push(l.value);
|
|
280
282
|
return bounds;
|
|
281
283
|
}
|
|
282
|
-
function leftDomain(input, series, bounds) {
|
|
284
|
+
function leftDomain(input, series, bounds, tickCount) {
|
|
283
285
|
const auto = input.y?.domain === void 0 || input.y.domain === "auto";
|
|
284
286
|
if (auto && input.stack === "normalized") return normalizedDomain(input.data, series);
|
|
285
287
|
return resolveYDomain(
|
|
286
288
|
input.y,
|
|
287
289
|
input.data,
|
|
288
290
|
auto && input.stack ? stackedSeries(series) : series,
|
|
289
|
-
bounds
|
|
291
|
+
bounds,
|
|
292
|
+
tickCount
|
|
290
293
|
);
|
|
291
294
|
}
|
|
292
|
-
function resolveAxes(input, visible) {
|
|
295
|
+
function resolveAxes(input, visible, cls) {
|
|
293
296
|
const hasY2 = input.y2 !== void 0;
|
|
297
|
+
const tickCount = (cfg) => typeof cfg?.ticks === "object" ? 0 : cfg?.ticks ?? LADDER[cls].yTicks;
|
|
294
298
|
const bounds = overlayBounds(input);
|
|
295
299
|
const onRight = (s) => hasY2 && s.axis === "right";
|
|
296
300
|
const left = {
|
|
297
301
|
domain: leftDomain(
|
|
298
302
|
input,
|
|
299
303
|
visible.filter((s) => !onRight(s)),
|
|
300
|
-
bounds.left
|
|
304
|
+
bounds.left,
|
|
305
|
+
tickCount(input.y)
|
|
301
306
|
),
|
|
302
307
|
format: input.y?.format ?? defaultNumberFormat
|
|
303
308
|
};
|
|
304
309
|
const right = hasY2 ? {
|
|
305
|
-
domain: resolveYDomain(
|
|
310
|
+
domain: resolveYDomain(
|
|
311
|
+
input.y2,
|
|
312
|
+
input.data,
|
|
313
|
+
visible.filter(onRight),
|
|
314
|
+
bounds.right,
|
|
315
|
+
tickCount(input.y2)
|
|
316
|
+
),
|
|
306
317
|
format: input.y2?.format ?? defaultNumberFormat
|
|
307
318
|
} : null;
|
|
308
319
|
return {
|
|
@@ -400,14 +411,25 @@ function underlayMarks(input, model, axes) {
|
|
|
400
411
|
});
|
|
401
412
|
return [...zones, ...xZones];
|
|
402
413
|
}
|
|
403
|
-
const
|
|
414
|
+
const BAR_BODY = 0.8;
|
|
404
415
|
const REF_LABEL_DX = 6;
|
|
405
416
|
const REF_LABEL_DY_ABOVE = -5;
|
|
406
417
|
const REF_LABEL_DY_BELOW = 11;
|
|
407
|
-
const refLabelMark = (r, i,
|
|
408
|
-
const
|
|
409
|
-
const
|
|
410
|
-
const
|
|
418
|
+
const refLabelMark = (r, i, ctx) => {
|
|
419
|
+
const { axes } = ctx;
|
|
420
|
+
const startFirst = r.axis === "right" && axes.scaleId(r.axis) === "y2";
|
|
421
|
+
const position = refLabelPosition({
|
|
422
|
+
pinned: r.labelPosition,
|
|
423
|
+
startFirst,
|
|
424
|
+
value: r.value,
|
|
425
|
+
domain: axes.axisOf(r.axis).domain,
|
|
426
|
+
plotWidth: ctx.plotWidth,
|
|
427
|
+
plotHeight: ctx.plotHeight,
|
|
428
|
+
label: r.label ?? "",
|
|
429
|
+
fontSize: VX.text.micro,
|
|
430
|
+
series: ctx.lines(r.axis)
|
|
431
|
+
});
|
|
432
|
+
const atStart = position.startsWith("start");
|
|
411
433
|
return decorative(
|
|
412
434
|
text([{ f: atStart ? 0 : 1 }], {
|
|
413
435
|
id: `ref-${i}-label`,
|
|
@@ -420,11 +442,11 @@ const refLabelMark = (r, i, axes) => {
|
|
|
420
442
|
fontSize: VX.text.micro,
|
|
421
443
|
anchor: atStart ? "start" : "end",
|
|
422
444
|
dx: atStart ? REF_LABEL_DX : -REF_LABEL_DX,
|
|
423
|
-
dy:
|
|
445
|
+
dy: position.endsWith("above") ? REF_LABEL_DY_ABOVE : REF_LABEL_DY_BELOW
|
|
424
446
|
})
|
|
425
447
|
);
|
|
426
448
|
};
|
|
427
|
-
const refLineMarks = (input, axes) => (input.refLines ?? []).flatMap(
|
|
449
|
+
const refLineMarks = (input, axes, label) => (input.refLines ?? []).flatMap(
|
|
428
450
|
(r, i) => (
|
|
429
451
|
// A line that names itself in the legend can be toggled off there.
|
|
430
452
|
input.hidden?.has(refLegendKey(i)) ? [] : [
|
|
@@ -436,12 +458,12 @@ const refLineMarks = (input, axes) => (input.refLines ?? []).flatMap(
|
|
|
436
458
|
yScale: axes.scaleId(r.axis),
|
|
437
459
|
...r.dashed && { strokeDasharray: DASH }
|
|
438
460
|
}),
|
|
439
|
-
...r.label ? [refLabelMark(r, i,
|
|
461
|
+
...r.label ? [refLabelMark(r, i, label())] : []
|
|
440
462
|
]
|
|
441
463
|
)
|
|
442
464
|
);
|
|
443
465
|
function buildScales(opts) {
|
|
444
|
-
const { input, model, axes, formatX, cls,
|
|
466
|
+
const { input, model, axes, formatX, cls, zoneScale } = opts;
|
|
445
467
|
const { left, right } = axes;
|
|
446
468
|
return {
|
|
447
469
|
x: {
|
|
@@ -450,8 +472,7 @@ function buildScales(opts) {
|
|
|
450
472
|
model,
|
|
451
473
|
xTicks: input.xTicks,
|
|
452
474
|
format: input.formatX ? formatX : void 0,
|
|
453
|
-
cls
|
|
454
|
-
height
|
|
475
|
+
cls
|
|
455
476
|
})
|
|
456
477
|
},
|
|
457
478
|
y: {
|
|
@@ -460,7 +481,6 @@ function buildScales(opts) {
|
|
|
460
481
|
cfg: input.y,
|
|
461
482
|
axis: left,
|
|
462
483
|
cls,
|
|
463
|
-
height,
|
|
464
484
|
side: "left",
|
|
465
485
|
grid: input.y?.grid ?? true
|
|
466
486
|
})
|
|
@@ -473,7 +493,6 @@ function buildScales(opts) {
|
|
|
473
493
|
cfg: input.y2,
|
|
474
494
|
axis: right,
|
|
475
495
|
cls,
|
|
476
|
-
height,
|
|
477
496
|
side: "right",
|
|
478
497
|
grid: input.y2?.grid ?? false
|
|
479
498
|
})
|
|
@@ -484,11 +503,26 @@ function buildScales(opts) {
|
|
|
484
503
|
}
|
|
485
504
|
};
|
|
486
505
|
}
|
|
487
|
-
function tooltipHeader(input, formatX, v, d) {
|
|
506
|
+
function tooltipHeader(input, formatX, dayOnly, v, d) {
|
|
488
507
|
if (input.tooltip && input.tooltip.formatHeader) return input.tooltip.formatHeader(v, d);
|
|
489
|
-
if (v instanceof Date && !input.formatX) return utcHeaderDate(v);
|
|
508
|
+
if (v instanceof Date && (!input.formatX || dayOnly)) return utcHeaderDate(v, dayOnly);
|
|
490
509
|
return formatX(v);
|
|
491
510
|
}
|
|
511
|
+
function dayGranular(values) {
|
|
512
|
+
const times = values.flatMap((v) => v instanceof Date ? [v.getTime()] : []);
|
|
513
|
+
if (times.length === 0 || times.length !== values.length) return false;
|
|
514
|
+
const sorted = times.toSorted((a, b) => a - b);
|
|
515
|
+
if (sorted.length === 1) return sorted[0] % DAY_MS === 0;
|
|
516
|
+
return sorted.every((t, i) => i === 0 || t - sorted[i - 1] >= DAY_MS - HOUR_MS);
|
|
517
|
+
}
|
|
518
|
+
const HOUR_MS = 36e5;
|
|
519
|
+
const stem = (w) => w.toLowerCase().replace(/s$/, "");
|
|
520
|
+
function unitIsName(label, value) {
|
|
521
|
+
const words = value.trim().split(/\s+/);
|
|
522
|
+
const unit = words.at(-1);
|
|
523
|
+
if (words.length < 2 || unit === void 0 || stem(unit) !== stem(label.trim())) return null;
|
|
524
|
+
return words.slice(0, -1).join(" ");
|
|
525
|
+
}
|
|
492
526
|
function rowsOf(input, visibleKeys) {
|
|
493
527
|
const seriesBy = new Map(input.series.map((s) => [s.key, s]));
|
|
494
528
|
return (key) => {
|
|
@@ -518,8 +552,14 @@ function cursorDotMarks(input, visible, axes) {
|
|
|
518
552
|
return cursorDots(s, rows, axes.onRight(s) ? "y2" : void 0);
|
|
519
553
|
});
|
|
520
554
|
}
|
|
555
|
+
const stripAnchor = (points, { plot }) => {
|
|
556
|
+
const xs = points.map((p) => p.x);
|
|
557
|
+
return { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: plot.y + plot.height };
|
|
558
|
+
};
|
|
559
|
+
const STRIP_TOOLTIP_PLACEMENT = ["bottom", "top"];
|
|
560
|
+
const STRIP_TOOLTIP_OFFSET = 8;
|
|
521
561
|
function tooltipSpec(opts) {
|
|
522
|
-
const { input, axes, visible, keys, visibleKeys, formatX } = opts;
|
|
562
|
+
const { input, axes, visible, keys, visibleKeys, formatX, dayOnly } = opts;
|
|
523
563
|
const hidden = input.series.filter((s) => !visibleKeys.has(s.key));
|
|
524
564
|
const rowSeries = (input.reverseRows ? visible.toReversed() : visible).filter(
|
|
525
565
|
(s) => s.tooltip !== false
|
|
@@ -528,7 +568,8 @@ function tooltipSpec(opts) {
|
|
|
528
568
|
use: quietWhileFollowing,
|
|
529
569
|
...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
|
|
530
570
|
portal,
|
|
531
|
-
anchor: "group-center",
|
|
571
|
+
anchor: input.tooltipBelow ? stripAnchor : "group-center",
|
|
572
|
+
...input.tooltipBelow && { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET },
|
|
532
573
|
content: (points) => {
|
|
533
574
|
const primary = points[0];
|
|
534
575
|
if (!primary) return { rows: [] };
|
|
@@ -539,17 +580,13 @@ function tooltipSpec(opts) {
|
|
|
539
580
|
for (const s of rowSeries) {
|
|
540
581
|
const v = s.getValue(d);
|
|
541
582
|
if (v === null || !Number.isFinite(v)) continue;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
s.formatValue ? s.formatValue(v, d) : axes.axisOf(axes.onRight(s) ? "right" : "left").format(v),
|
|
546
|
-
input.highlighted === s.key
|
|
547
|
-
)
|
|
548
|
-
);
|
|
583
|
+
const text2 = s.formatValue ? s.formatValue(v, d) : axes.axisOf(axes.onRight(s) ? "right" : "left").format(v);
|
|
584
|
+
const bare = input.series.length === 1 ? unitIsName(s.label, text2) : null;
|
|
585
|
+
rows.push(seriesRow(s, bare ?? text2, input.highlighted === s.key));
|
|
549
586
|
}
|
|
550
587
|
const extra = (input.tooltip || void 0)?.rows?.(d, { visible, hidden }) ?? [];
|
|
551
588
|
return {
|
|
552
|
-
title: tooltipHeader(input, formatX, x, d),
|
|
589
|
+
title: tooltipHeader(input, formatX, dayOnly, x, d),
|
|
553
590
|
rows: [...rows, ...extra.map(engineRow)]
|
|
554
591
|
};
|
|
555
592
|
}
|
|
@@ -569,18 +606,42 @@ function compileCartesian(input) {
|
|
|
569
606
|
const visibleKeys = new Set(visible.map((s) => s.key));
|
|
570
607
|
const keys = new Set(input.series.map((s) => s.key));
|
|
571
608
|
const model = xScaleFor(input.data.map(input.x), input.band === true, input.xDomain);
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
609
|
+
const byClass = /* @__PURE__ */ new Map();
|
|
610
|
+
const axesAt = (cls) => {
|
|
611
|
+
const found = byClass.get(cls);
|
|
612
|
+
if (found) return found;
|
|
613
|
+
const made = resolveAxes(input, visible, cls);
|
|
614
|
+
byClass.set(cls, made);
|
|
615
|
+
return made;
|
|
616
|
+
};
|
|
617
|
+
const shared = axesAt("regular");
|
|
618
|
+
const dots = cursorDotMarks(input, visible, shared);
|
|
576
619
|
const rows = rowsOf(input, visibleKeys);
|
|
577
620
|
const formatX = (v) => input.formatX ? input.formatX(v) : defaultFormatX(v);
|
|
578
621
|
const gradients = input.series.flatMap(
|
|
579
|
-
(s, i) => s.area ? [seriesAreaGradient(s, i, input,
|
|
622
|
+
(s, i) => s.area ? [seriesAreaGradient(s, i, input, shared)] : []
|
|
623
|
+
);
|
|
624
|
+
const dayOnly = dayGranular(model.values);
|
|
625
|
+
const names = (input.refLines ?? []).some((r) => r.label !== void 0 && r.label !== "");
|
|
626
|
+
const barHalf = model.halfStep * BAR_BODY;
|
|
627
|
+
const linesOn = (side) => visible.filter((s) => shared.onRight(s) === (side === "right" && shared.right !== null)).map(
|
|
628
|
+
(s) => rows(s.key).flatMap((r) => {
|
|
629
|
+
const fx = model.fraction(r.x);
|
|
630
|
+
if (fx === null || r.y === null) return [];
|
|
631
|
+
if (!(model.band && s.mark === "bar")) return [{ fx, y: r.y }];
|
|
632
|
+
return [
|
|
633
|
+
{ fx: fx - barHalf, y: 0 },
|
|
634
|
+
{ fx: fx - barHalf, y: r.y },
|
|
635
|
+
{ fx: fx + barHalf, y: r.y },
|
|
636
|
+
{ fx: fx + barHalf, y: 0 }
|
|
637
|
+
];
|
|
638
|
+
})
|
|
580
639
|
);
|
|
581
640
|
const definition = {
|
|
582
641
|
chart: ({ width, height }) => {
|
|
583
642
|
const cls = resolveContainerClass(width);
|
|
643
|
+
const axes = axesAt(cls);
|
|
644
|
+
const access = plotAccess(definition, input.plot, MAIN_PANE);
|
|
584
645
|
const kindMarks = input.marks(
|
|
585
646
|
plotContext(
|
|
586
647
|
{
|
|
@@ -596,29 +657,46 @@ function compileCartesian(input) {
|
|
|
596
657
|
yDomain: axes.left.domain,
|
|
597
658
|
y2Domain: axes.right?.domain
|
|
598
659
|
},
|
|
599
|
-
|
|
660
|
+
access
|
|
600
661
|
)
|
|
601
662
|
);
|
|
663
|
+
const under = underlayMarks(input, model, axes);
|
|
664
|
+
const over = refLineMarks(input, axes, () => {
|
|
665
|
+
access.read();
|
|
666
|
+
const size = access.size();
|
|
667
|
+
return {
|
|
668
|
+
plotWidth: size?.width ?? width,
|
|
669
|
+
plotHeight: size?.height ?? height,
|
|
670
|
+
lines: linesOn,
|
|
671
|
+
axes,
|
|
672
|
+
model
|
|
673
|
+
};
|
|
674
|
+
});
|
|
602
675
|
return {
|
|
603
|
-
marks: [
|
|
676
|
+
marks: [
|
|
677
|
+
...under,
|
|
678
|
+
...kindMarks,
|
|
679
|
+
...dots,
|
|
680
|
+
...over,
|
|
681
|
+
...input.crosshair === false ? [] : [crosshair({ x: CROSSHAIR, y: false })]
|
|
682
|
+
],
|
|
604
683
|
scales: buildScales({
|
|
605
684
|
input,
|
|
606
685
|
model,
|
|
607
686
|
axes,
|
|
608
687
|
formatX,
|
|
609
688
|
cls,
|
|
610
|
-
|
|
611
|
-
zoneScale: under.length > 0 || (input.refLines ?? []).some((r) => r.label)
|
|
689
|
+
zoneScale: under.length > 0 || names
|
|
612
690
|
}),
|
|
613
691
|
theme: CHART_THEME,
|
|
614
692
|
...gradients.length > 0 && { gradients },
|
|
615
|
-
clip: true
|
|
616
|
-
...labelsInside(cls, height) && { margin: { left: 0, ...axes.right && { right: 0 } } }
|
|
693
|
+
clip: true
|
|
617
694
|
};
|
|
618
695
|
},
|
|
619
696
|
// Followers resolve the leader's group, so they draw its dots; `quietWhileFollowing` mutes the
|
|
620
697
|
// tooltip unless the chart opts into following tooltips.
|
|
621
698
|
focus: "group-x",
|
|
699
|
+
...input.focusRing === false && { focusRing: false },
|
|
622
700
|
maxFocusDistance: Number.POSITIVE_INFINITY,
|
|
623
701
|
cursor: cursorBinding({
|
|
624
702
|
group: input.cursorGroup,
|
|
@@ -628,16 +706,18 @@ function compileCartesian(input) {
|
|
|
628
706
|
mode: input.cursorResolution ?? "nearest",
|
|
629
707
|
pin: input.coarse === true
|
|
630
708
|
}),
|
|
631
|
-
tooltip: input.tooltip === false ? false : tooltipSpec({ input, axes, visible, keys, visibleKeys, formatX })
|
|
709
|
+
tooltip: input.tooltip === false ? false : tooltipSpec({ input, axes: shared, visible, keys, visibleKeys, formatX, dayOnly })
|
|
632
710
|
};
|
|
633
711
|
return definition;
|
|
634
712
|
}
|
|
635
713
|
export {
|
|
636
714
|
areaGradient,
|
|
637
715
|
areaGradientId,
|
|
716
|
+
bucketDay,
|
|
638
717
|
compileCartesian,
|
|
639
718
|
dashedSwatch,
|
|
640
719
|
dateTicks,
|
|
720
|
+
dayGranular,
|
|
641
721
|
defaultFormatX,
|
|
642
722
|
defaultNumberFormat,
|
|
643
723
|
engineRow,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The default Date x tick labels: chosen from the TICK step (not the data step), read in UTC like
|
|
3
3
|
* the scale that placed them. A label may recur on one axis only behind a MARKER label (a day or a
|
|
4
|
-
* year) — `12:00, 18:00, 18
|
|
4
|
+
* year) — `12:00, 18:00, 18 Oct, 06:00, 12:00` is fine, `17 Oct, 17 Oct, 18 Oct` is not. Each span has
|
|
5
5
|
* a ladder of levels, plainest first; the first level that holds the invariant wins. The last rung
|
|
6
6
|
* of every ladder names the whole date (or instant) of its tick, so the invariant always holds.
|
|
7
7
|
*/
|
|
8
8
|
export declare const pad2: (n: number) => string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare
|
|
9
|
+
/** The day (`4 Oct`, in the page locale), read in UTC like the time scale (a local read shifts a
|
|
10
|
+
* day west of UTC). */
|
|
11
|
+
export declare const utcAxisDate: (d: Date) => string;
|
|
12
12
|
/**
|
|
13
13
|
* A formatter for one tick set. A Date that is not among the ticks (a hover, a consumer reading
|
|
14
|
-
* the axis format) reads as plain
|
|
14
|
+
* the axis format) reads as the plain day: its position in the set is undefined.
|
|
15
15
|
*/
|
|
16
16
|
export declare function dateTickFormat(ticks: readonly Date[]): (d: Date) => string;
|
|
17
17
|
//# sourceMappingURL=date-tick-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-tick-format.d.ts","sourceRoot":"","sources":["../../src/charts/date-tick-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"date-tick-format.d.ts","sourceRoot":"","sources":["../../src/charts/date-tick-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,eAAO,MAAM,IAAI,GAAI,GAAG,MAAM,KAAG,MAAoC,CAAA;AAUrE;uBACuB;AACvB,eAAO,MAAM,WAAW,qBAAU,CAAA;AAgGlC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,KAAK,MAAM,CAM1E"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { axisDay, axisDayYear, monthName } from "./chart-dates.js";
|
|
2
2
|
const pad2 = (n) => String(n).padStart(2, "0");
|
|
3
|
-
const monthName = (d) => MONTHS[d.getUTCMonth()];
|
|
4
3
|
const DAY_MS = 864e5;
|
|
5
4
|
const HOUR_MS = 36e5;
|
|
6
5
|
const MONTH_STEP_MS = 27 * DAY_MS;
|
|
7
|
-
|
|
8
|
-
return `${pad2(d.getUTCDate())}.${pad2(d.getUTCMonth() + 1)}`;
|
|
9
|
-
}
|
|
6
|
+
const utcAxisDate = axisDay;
|
|
10
7
|
const utcClock = (d) => `${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`;
|
|
11
8
|
const utcClockSeconds = (d) => `${utcClock(d)}:${pad2(d.getUTCSeconds())}`;
|
|
12
9
|
const utcClockMillis = (d) => `${utcClockSeconds(d)}.${String(d.getUTCMilliseconds()).padStart(3, "0")}`;
|
|
13
|
-
const utcAxisDateYear =
|
|
10
|
+
const utcAxisDateYear = axisDayYear;
|
|
14
11
|
const isMidnight = (t) => t % DAY_MS === 0;
|
|
15
12
|
const isJanuary = (d) => d.getUTCMonth() === 0;
|
|
16
13
|
const dayOf = (t) => Math.floor(t / DAY_MS);
|
|
@@ -75,7 +72,6 @@ function dateTickFormat(ticks) {
|
|
|
75
72
|
}
|
|
76
73
|
export {
|
|
77
74
|
dateTickFormat,
|
|
78
|
-
monthName,
|
|
79
75
|
pad2,
|
|
80
76
|
utcAxisDate
|
|
81
77
|
};
|
package/dist/charts/labels.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types.js';
|
|
2
2
|
export type EndLabelAnchor = 'start' | 'end';
|
|
3
|
+
/** Which side of its line a flipped label sits: away from the line's last segment. */
|
|
4
|
+
export type EndLabelSide = 'above' | 'below';
|
|
3
5
|
/**
|
|
4
6
|
* The side of its point an end label takes: `start` (right of the point) unless the point leaves
|
|
5
7
|
* less room than the label needs. `fraction` is the point's x as a share of the plot width,
|
|
@@ -13,20 +15,33 @@ export declare function endLabelAnchor(opts: {
|
|
|
13
15
|
label: string;
|
|
14
16
|
fontSize: number;
|
|
15
17
|
}): EndLabelAnchor;
|
|
18
|
+
/** `Lines`' one naming switch: who names the series. */
|
|
19
|
+
export type LinesNaming = 'auto' | 'legend' | 'endLabels';
|
|
16
20
|
export type EndLabel<T, X extends ChartX> = {
|
|
17
21
|
series: ChartSeries<T>;
|
|
18
22
|
row: PlotRow<T, X>;
|
|
19
23
|
anchor: EndLabelAnchor;
|
|
24
|
+
/** Only a flipped label (left of its point) can meet its own line; it takes the clear side. */
|
|
25
|
+
side: EndLabelSide;
|
|
26
|
+
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
|
|
27
|
+
nudge: number;
|
|
20
28
|
};
|
|
21
29
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
30
|
+
* Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
|
|
31
|
+
* shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
|
|
32
|
+
* lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot. Order is kept.
|
|
33
|
+
*/
|
|
34
|
+
export declare function spreadLabels(ys: readonly number[], plotHeight: number): number[];
|
|
35
|
+
/**
|
|
36
|
+
* The end labels to draw. `auto`: on the wide class only, with ≤ {@link MAX_END_LABELS} lines and
|
|
37
|
+
* no right axis; `endLabels`: at every width and any line count (still no right axis, whose
|
|
38
|
+
* series read another scale); `legend`: none. Labels that would collide are spread apart, never
|
|
39
|
+
* dropped. A series whose last point the plot's own x scale cannot place, or places outside the plot
|
|
25
40
|
* (`plot.xFraction` outside [0, 1]: clipped by a narrower `xDomain`), has no label.
|
|
26
41
|
*/
|
|
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
|
|
29
|
-
export declare function endLabelOffset(anchor: EndLabelAnchor): {
|
|
42
|
+
export declare function endLabelPlan<T, X extends ChartX>(plot: PlotContext<T, X>, lines: readonly ChartSeries<T>[], naming?: LinesNaming): EndLabel<T, X>[];
|
|
43
|
+
/** The offset of a label from its point: right of it, level; or left of it, above or below. */
|
|
44
|
+
export declare function endLabelOffset(anchor: EndLabelAnchor, side?: EndLabelSide): {
|
|
30
45
|
dx: number;
|
|
31
46
|
dy: number;
|
|
32
47
|
};
|
|
@@ -1 +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;
|
|
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;AAmBpF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,CAAA;AAC5C,sFAAsF;AACtF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,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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