@motionscript/charts 0.1.0 → 0.1.1-alpha.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 +19 -0
- package/dist/bar-chart/bar-chart.d.ts +22 -93
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +48 -121
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +11 -38
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +15 -38
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +43 -74
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +31 -59
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -10
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +0 -7
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +27 -90
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +15 -54
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-4SMRCU24.js +2 -0
- package/dist/browser/chunks/chunk-4SMRCU24.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +4 -16
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +4 -16
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +8 -28
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +7 -19
- package/dist/kit/cartesian.js.map +1 -1
- package/dist/kit/chart-border.d.ts +9 -18
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +4 -9
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +25 -36
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +13 -13
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +14 -61
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +17 -65
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +2 -0
- package/dist/kit/entries.d.ts.map +1 -1
- package/dist/kit/entries.js +2 -0
- package/dist/kit/entries.js.map +1 -1
- package/dist/kit/motion.d.ts +11 -3
- package/dist/kit/motion.d.ts.map +1 -1
- package/dist/kit/motion.js +7 -1
- package/dist/kit/motion.js.map +1 -1
- package/dist/kit/shared.d.ts +60 -175
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +40 -157
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +16 -45
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +17 -42
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +16 -41
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +14 -43
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +14 -27
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +8 -22
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +16 -43
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +13 -42
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +1 -13
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +0 -12
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +23 -109
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +45 -141
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +33 -107
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +28 -81
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +14 -55
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +29 -111
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +0 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -12
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +1 -12
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +0 -9
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +37 -71
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +31 -65
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +11 -26
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +14 -39
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +50 -192
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +75 -247
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +45 -131
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +29 -72
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +51 -165
- package/src/bar-chart/category-axis.ts +16 -57
- package/src/bar-chart/chart-bars.ts +43 -120
- package/src/bar-chart/index.ts +2 -10
- package/src/bar-chart/shared.ts +29 -97
- package/src/engine.ts +4 -16
- package/src/kit/cartesian.ts +11 -26
- package/src/kit/chart-border.ts +6 -20
- package/src/kit/chart-canvas.ts +15 -40
- package/src/kit/chart-legend.ts +17 -86
- package/src/kit/entries.ts +4 -1
- package/src/kit/motion.ts +11 -2
- package/src/kit/shared.ts +58 -219
- package/src/kit/vertical-axis.ts +18 -71
- package/src/line-chart/chart-line.ts +16 -44
- package/src/line-chart/chart-region.ts +10 -23
- package/src/line-chart/horizontal-axis.ts +13 -42
- package/src/line-chart/index.ts +1 -13
- package/src/line-chart/line-chart.ts +50 -184
- package/src/line-chart/shared.ts +51 -145
- package/src/line-chart/x-scale.ts +31 -121
- package/src/nodes.ts +0 -12
- package/src/pie-chart/index.ts +1 -12
- package/src/pie-chart/pie-chart.ts +34 -102
- package/src/pie-chart/pie-legend.ts +14 -55
- package/src/pie-chart/pie-ring.ts +80 -307
- package/src/pie-chart/shared.ts +50 -139
- package/dist/browser/chunks/chunk-TJNHLQGV.js +0 -2
- package/dist/browser/chunks/chunk-TJNHLQGV.js.map +0 -7
|
@@ -1,78 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
* Types and pure helpers specific to the {@link LineChart} family: the traced
|
|
3
|
-
* polylines, the spotlit region they dim outside of, and the theme those two
|
|
4
|
-
* add to the shared chart vocabulary.
|
|
5
|
-
*
|
|
6
|
-
* Everything a bar or a pie chart would want too — what a series is, how an axis
|
|
7
|
-
* is scaled and formatted, the theme leaf resolvers, the legend and plot-panel
|
|
8
|
-
* branches — lives in `../kit/shared.ts` and is imported here. What's
|
|
9
|
-
* left below is what only a line chart has: points sorted along an x column,
|
|
10
|
-
* a region clipped out of a polyline, and the `region` branch of the theme.
|
|
11
|
-
*
|
|
12
|
-
* Kept renderer-agnostic (no `Node` imports) so every part shares one
|
|
13
|
-
* scale/format/palette/theme vocabulary, and so a host's own inspector
|
|
14
|
-
* mapping can build a partial {@link ChartTheme} without
|
|
15
|
-
* pulling the components in.
|
|
16
|
-
*/
|
|
17
|
-
import { type DataRecord, type Fill, type Stroke } from "@motionscript/sdk";
|
|
1
|
+
import { type DataRecord, type Fill, type Stroke, type Vector2 } from "@motionscript/sdk";
|
|
18
2
|
import { type AxisConfig, type ChartSeries, type LegendConfig, type LegendTheme, type PlotAreaConfig, type Range } from "../kit/shared.js";
|
|
19
3
|
import type { XScale } from "./x-scale.js";
|
|
20
|
-
/**
|
|
21
|
-
* One series in a {@link LineChart}: a polyline traced through the values in one
|
|
22
|
-
* column of the chart's `data`, drawn in `fill` (or the theme's `seriesStyles`
|
|
23
|
-
* palette when omitted) and captioned by `label` in the legend.
|
|
24
|
-
*
|
|
25
|
-
* The family-wide {@link ChartSeries} under a name that says what it draws here;
|
|
26
|
-
* the chart's own `xField` prop names the column carrying the shared x values,
|
|
27
|
-
* so every series is read off the same rows — one row per sample, one column per
|
|
28
|
-
* series.
|
|
29
|
-
*/
|
|
4
|
+
/** One polyline of a {@link LineChart}: {@link ChartSeries} under the name for what it draws here. */
|
|
30
5
|
export type LineSeries = ChartSeries;
|
|
31
6
|
/**
|
|
32
|
-
* A rectangular slice of the plot
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* Either axis may be omitted, and that's the point: `{ x: [60, 100] }` is a
|
|
36
|
-
* vertical band spanning the full height, `{ y: [8, 10] }` a horizontal band
|
|
37
|
-
* spanning the full width, and both together a box. A reversed range is read
|
|
38
|
-
* the same as the forward one — a region is a span, not a direction.
|
|
7
|
+
* A rectangular slice of the plot in data units, the input to `spotlightRegion`
|
|
8
|
+
* and `zoomTo`. Either axis may be omitted: `{ x: [60, 100] }` is a full-height
|
|
9
|
+
* band. A reversed range reads the same as a forward one.
|
|
39
10
|
*/
|
|
40
11
|
export interface PlotRegion {
|
|
41
|
-
/**
|
|
12
|
+
/** Omit to span the full plot width. */
|
|
42
13
|
x?: Range;
|
|
43
|
-
/**
|
|
14
|
+
/** Omit to span the full plot height. */
|
|
44
15
|
y?: Range;
|
|
45
16
|
}
|
|
46
17
|
/**
|
|
47
|
-
* A {@link PlotRegion}
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `xBounded`/`yBounded` carry which axes the author actually constrained: an
|
|
52
|
-
* unbounded axis has its edges pinned to the plot's own and draws no rule.
|
|
18
|
+
* A {@link PlotRegion} in the plot's centred pixel space (origin at the centre,
|
|
19
|
+
* y-up), the frame the series points live in. An axis the author left unbounded
|
|
20
|
+
* has its edges pinned to the plot's own and draws no rule.
|
|
53
21
|
*/
|
|
54
22
|
export interface RegionBox {
|
|
55
23
|
left: number;
|
|
56
24
|
right: number;
|
|
57
25
|
bottom: number;
|
|
58
26
|
top: number;
|
|
59
|
-
/** The author gave an x range — the left/right edges are real data bounds. */
|
|
60
27
|
xBounded: boolean;
|
|
61
|
-
/** The author gave a y range — the bottom/top edges are real data bounds. */
|
|
62
28
|
yBounded: boolean;
|
|
63
29
|
}
|
|
64
|
-
/** The
|
|
30
|
+
/** The "no region" resting value. */
|
|
65
31
|
export declare const EMPTY_REGION_BOX: RegionBox;
|
|
66
|
-
/**
|
|
32
|
+
/** Whether `box` is non-degenerate, so there is something to spotlight. */
|
|
67
33
|
export declare function hasRegion(box: RegionBox): boolean;
|
|
68
34
|
/**
|
|
69
|
-
* Resolve a {@link PlotRegion} against the plot
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* An omitted axis takes the plot's own edges, so the region spans it. A given
|
|
74
|
-
* axis is clamped to the plot, so a range running off the scale still produces
|
|
75
|
-
* a box inside the panel.
|
|
35
|
+
* Resolve a {@link PlotRegion} against the plot rectangle (centred pixel space)
|
|
36
|
+
* and the data ranges its edges span. An omitted axis takes the plot's own
|
|
37
|
+
* edges; a given one is clamped to the plot.
|
|
76
38
|
*/
|
|
77
39
|
export declare function resolveRegionBox(region: PlotRegion | null | undefined, plot: {
|
|
78
40
|
left: number;
|
|
@@ -80,51 +42,33 @@ export declare function resolveRegionBox(region: PlotRegion | null | undefined,
|
|
|
80
42
|
bottom: number;
|
|
81
43
|
top: number;
|
|
82
44
|
}, xScale: Range, yScale: Range): RegionBox;
|
|
83
|
-
/** A bare `{x, y}` — declared locally so this module stays free of node imports. */
|
|
84
|
-
interface Vector2Like {
|
|
85
|
-
x: number;
|
|
86
|
-
y: number;
|
|
87
|
-
}
|
|
88
45
|
/**
|
|
89
|
-
* The parts of `points`
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* Segments are clipped against the box rather than filtered by endpoint, so a
|
|
94
|
-
* line entering the region mid-segment is cut exactly on the boundary.
|
|
95
|
-
*/
|
|
96
|
-
export declare function clipPolylineToBox(points: Vector2Like[], box: RegionBox): Vector2Like[][];
|
|
97
|
-
/**
|
|
98
|
-
* How a spotlit {@link PlotRegion} is drawn — the dashed rules on its bounded
|
|
99
|
-
* edges, the wash filling it, and how far the series fade outside it.
|
|
46
|
+
* The parts of `points` inside `box`, as contiguous sub-polylines: a series is
|
|
47
|
+
* drawn dimmed in full, then these runs are re-drawn at full strength. Segments
|
|
48
|
+
* are clipped, not filtered by endpoint, so a line entering mid-segment is cut
|
|
49
|
+
* exactly on the boundary.
|
|
100
50
|
*/
|
|
51
|
+
export declare function clipPolylineToBox(points: Vector2[], box: RegionBox): Vector2[][];
|
|
52
|
+
/** How a spotlit {@link PlotRegion} is drawn: rules on its bounded edges, a wash, and how far series fade outside it. */
|
|
101
53
|
export interface RegionConfig {
|
|
102
|
-
/**
|
|
54
|
+
/** Marks each bounded edge. */
|
|
103
55
|
stroke: Stroke;
|
|
104
|
-
/**
|
|
56
|
+
/** Drawn under the series lines. */
|
|
105
57
|
fill: Fill;
|
|
106
|
-
/** Opacity the stretch of every series
|
|
58
|
+
/** Opacity the stretch of every series outside the region fades to. */
|
|
107
59
|
dimOpacity: number;
|
|
108
60
|
}
|
|
109
61
|
/** A {@link LineChart}'s full, resolved visual theme. */
|
|
110
62
|
export interface ChartConfig {
|
|
111
|
-
/**
|
|
112
|
-
* Default per-series line stroke, cycled by series index (`i % length`). A
|
|
113
|
-
* series' own `fill`, when set, overrides just the colour.
|
|
114
|
-
*/
|
|
63
|
+
/** Cycled by series index; a series' own `fill` overrides just the colour. */
|
|
115
64
|
seriesStyles: Stroke[];
|
|
116
65
|
xAxis: AxisConfig;
|
|
117
66
|
yAxis: AxisConfig;
|
|
118
|
-
/** The plot panel: border, fill, and drop shadow. */
|
|
119
67
|
plotArea: PlotAreaConfig;
|
|
120
68
|
legend: LegendConfig;
|
|
121
|
-
/** The spotlit-region annotation — see {@link RegionConfig}. */
|
|
122
69
|
region: RegionConfig;
|
|
123
70
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Author-facing partial theme, passed as {@link LineChart}'s `theme` prop —
|
|
126
|
-
* every branch optional and deep-merged onto {@link DEFAULT_CHART_THEME}.
|
|
127
|
-
*/
|
|
71
|
+
/** The author's partial theme, deep-merged onto {@link DEFAULT_CHART_THEME}. */
|
|
128
72
|
export type ChartTheme = {
|
|
129
73
|
seriesStyles?: Stroke[];
|
|
130
74
|
xAxis?: Partial<AxisConfig>;
|
|
@@ -133,39 +77,21 @@ export type ChartTheme = {
|
|
|
133
77
|
legend?: LegendTheme;
|
|
134
78
|
region?: Partial<RegionConfig>;
|
|
135
79
|
};
|
|
136
|
-
/** The chart's out-of-the-box look. */
|
|
137
80
|
export declare const DEFAULT_CHART_THEME: ChartConfig;
|
|
138
|
-
/**
|
|
139
|
-
* {@link LineChart}'s `theme` entry's resolve: merges the author's partial
|
|
140
|
-
* {@link ChartTheme} onto `previous` (falling back to
|
|
141
|
-
* {@link DEFAULT_CHART_THEME} on first resolution), fully resolving every leaf.
|
|
142
|
-
*/
|
|
81
|
+
/** The `theme` entry's resolve: merges a partial {@link ChartTheme} onto `previous` (first resolution: the default). */
|
|
143
82
|
export declare function resolveChartTheme(theme: ChartTheme | undefined, previous?: ChartConfig): ChartConfig;
|
|
144
|
-
/** {@link LineChart}'s `theme` entry's lerp — leaf by leaf. */
|
|
145
83
|
export declare function lerpChartTheme(from: ChartConfig, to: ChartConfig, t: number): ChartConfig;
|
|
146
84
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* in.
|
|
151
|
-
*
|
|
152
|
-
* A row missing its y column contributes a 0 rather than a gap — these charts
|
|
153
|
-
* draw continuous lines, so dropping the point would silently bridge the hole.
|
|
154
|
-
*
|
|
155
|
-
* Takes the resolved scale rather than the column *name*, because what a row's x
|
|
156
|
-
* is depends on what kind of column it came out of: a number, an instant, or a
|
|
157
|
-
* place in the file. See `x-scale.ts`.
|
|
85
|
+
* One series' `[x, y]` points, sorted along x so the polyline traces left to
|
|
86
|
+
* right. A row missing its y contributes 0 rather than a gap, since dropping it
|
|
87
|
+
* would silently bridge the hole.
|
|
158
88
|
*/
|
|
159
89
|
export declare function seriesPoints(data: DataRecord[], x: XScale, series: LineSeries): [x: number, y: number][];
|
|
160
|
-
/** Min/max across every series' column, the fallback when unset. */
|
|
161
90
|
export declare function yExtent(data: DataRecord[], series: LineSeries[]): Range;
|
|
162
91
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* `divisions` is how many segments the auto-range is stepped into (one fewer
|
|
167
|
-
* than a marker count) — it only shapes the tidy step when `range` is omitted.
|
|
92
|
+
* The explicit `range`, else the data's y extent nudged out to tidy step bounds.
|
|
93
|
+
* `divisions` (one fewer than the marker count) only shapes the step when
|
|
94
|
+
* `range` is omitted.
|
|
168
95
|
*/
|
|
169
96
|
export declare function resolveYScale(data: DataRecord[], series: LineSeries[], range: Range | undefined, divisions: number): Range;
|
|
170
|
-
export {};
|
|
171
97
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/line-chart/shared.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/line-chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,UAAU,EACf,KA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,EAAE,MAAM,CAAC,EAAE,CAI1B;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAUvE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAAE,EAClB,MAAM,EAAE,UAAU,EAAE,EACpB,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,SAAS,EAAE,MAAM,GAChB,KAAK,CAOP"}
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types and pure helpers specific to the {@link LineChart} family: the traced
|
|
3
|
-
* polylines, the spotlit region they dim outside of, and the theme those two
|
|
4
|
-
* add to the shared chart vocabulary.
|
|
5
|
-
*
|
|
6
|
-
* Everything a bar or a pie chart would want too — what a series is, how an axis
|
|
7
|
-
* is scaled and formatted, the theme leaf resolvers, the legend and plot-panel
|
|
8
|
-
* branches — lives in `../kit/shared.ts` and is imported here. What's
|
|
9
|
-
* left below is what only a line chart has: points sorted along an x column,
|
|
10
|
-
* a region clipped out of a polyline, and the `region` branch of the theme.
|
|
11
|
-
*
|
|
12
|
-
* Kept renderer-agnostic (no `Node` imports) so every part shares one
|
|
13
|
-
* scale/format/palette/theme vocabulary, and so a host's own inspector
|
|
14
|
-
* mapping can build a partial {@link ChartTheme} without
|
|
15
|
-
* pulling the components in.
|
|
16
|
-
*/
|
|
17
1
|
import { Fills, fillOps, lerpNumber, strokeOps, } from "@motionscript/sdk";
|
|
18
|
-
import {
|
|
19
|
-
|
|
2
|
+
import { niceStep } from "@motionscript/sdk/component";
|
|
3
|
+
import { CHART_PALETTE, DEFAULT_LEGEND, DEFAULT_PLOT_AREA, DEFAULT_SERIES_STROKES, DEFAULT_X_AXIS, DEFAULT_Y_AXIS, SPOTLIGHT_DIM, lerpAxisConfig, lerpLegendConfig, lerpPlotArea, lerpSeriesStrokes, num, resolveAxisConfig, resolveLegendConfig, resolvePlotArea, resolveSeriesStrokes, } from "../kit/shared.js";
|
|
4
|
+
/** The "no region" resting value. */
|
|
20
5
|
export const EMPTY_REGION_BOX = {
|
|
21
6
|
left: 0,
|
|
22
7
|
right: 0,
|
|
@@ -25,18 +10,14 @@ export const EMPTY_REGION_BOX = {
|
|
|
25
10
|
xBounded: false,
|
|
26
11
|
yBounded: false,
|
|
27
12
|
};
|
|
28
|
-
/**
|
|
13
|
+
/** Whether `box` is non-degenerate, so there is something to spotlight. */
|
|
29
14
|
export function hasRegion(box) {
|
|
30
15
|
return box.right > box.left && box.top > box.bottom;
|
|
31
16
|
}
|
|
32
17
|
/**
|
|
33
|
-
* Resolve a {@link PlotRegion} against the plot
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* An omitted axis takes the plot's own edges, so the region spans it. A given
|
|
38
|
-
* axis is clamped to the plot, so a range running off the scale still produces
|
|
39
|
-
* a box inside the panel.
|
|
18
|
+
* Resolve a {@link PlotRegion} against the plot rectangle (centred pixel space)
|
|
19
|
+
* and the data ranges its edges span. An omitted axis takes the plot's own
|
|
20
|
+
* edges; a given one is clamped to the plot.
|
|
40
21
|
*/
|
|
41
22
|
export function resolveRegionBox(region, plot, xScale, yScale) {
|
|
42
23
|
if (!region || (region.x === undefined && region.y === undefined)) {
|
|
@@ -59,12 +40,10 @@ export function resolveRegionBox(region, plot, xScale, yScale) {
|
|
|
59
40
|
return { left, right, bottom, top, xBounded, yBounded };
|
|
60
41
|
}
|
|
61
42
|
/**
|
|
62
|
-
* The parts of `points`
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* Segments are clipped against the box rather than filtered by endpoint, so a
|
|
67
|
-
* line entering the region mid-segment is cut exactly on the boundary.
|
|
43
|
+
* The parts of `points` inside `box`, as contiguous sub-polylines: a series is
|
|
44
|
+
* drawn dimmed in full, then these runs are re-drawn at full strength. Segments
|
|
45
|
+
* are clipped, not filtered by endpoint, so a line entering mid-segment is cut
|
|
46
|
+
* exactly on the boundary.
|
|
68
47
|
*/
|
|
69
48
|
export function clipPolylineToBox(points, box) {
|
|
70
49
|
if (points.length < 2 || !hasRegion(box))
|
|
@@ -74,15 +53,14 @@ export function clipPolylineToBox(points, box) {
|
|
|
74
53
|
for (let i = 1; i < points.length; i++) {
|
|
75
54
|
const seg = clipSegment(points[i - 1], points[i], box);
|
|
76
55
|
if (!seg) {
|
|
77
|
-
//
|
|
56
|
+
// Misses the box: close the open run.
|
|
78
57
|
if (run.length >= 2)
|
|
79
58
|
runs.push(run);
|
|
80
59
|
run = [];
|
|
81
60
|
continue;
|
|
82
61
|
}
|
|
83
62
|
const [a, b] = seg;
|
|
84
|
-
//
|
|
85
|
-
// ended; otherwise the line left the box and came back, which is a new run.
|
|
63
|
+
// Continues the open run if it starts where the last ended; otherwise the line left and came back.
|
|
86
64
|
if (run.length > 0 && samePoint(run[run.length - 1], a))
|
|
87
65
|
run.push(b);
|
|
88
66
|
else {
|
|
@@ -99,16 +77,13 @@ export function clipPolylineToBox(points, box) {
|
|
|
99
77
|
function samePoint(a, b) {
|
|
100
78
|
return Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5;
|
|
101
79
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Liang–Barsky clip of one segment against the axis-aligned `box`. Returns the
|
|
104
|
-
* surviving `[start, end]`, or `null` when the segment lies wholly outside.
|
|
105
|
-
*/
|
|
80
|
+
/** Liang-Barsky clip of one segment against `box`: the surviving `[start, end]`, or `null` when wholly outside. */
|
|
106
81
|
function clipSegment(a, b, box) {
|
|
107
82
|
const dx = b.x - a.x;
|
|
108
83
|
const dy = b.y - a.y;
|
|
109
84
|
let t0 = 0;
|
|
110
85
|
let t1 = 1;
|
|
111
|
-
// Each edge as (p, q): the segment survives where p
|
|
86
|
+
// Each edge as (p, q): the segment survives where p*t <= q.
|
|
112
87
|
const edges = [
|
|
113
88
|
[-dx, a.x - box.left],
|
|
114
89
|
[dx, box.right - a.x],
|
|
@@ -117,7 +92,7 @@ function clipSegment(a, b, box) {
|
|
|
117
92
|
];
|
|
118
93
|
for (const [p, q] of edges) {
|
|
119
94
|
if (p === 0) {
|
|
120
|
-
// Parallel to this edge: outside it
|
|
95
|
+
// Parallel to this edge: outside it, the whole segment is out.
|
|
121
96
|
if (q < 0)
|
|
122
97
|
return null;
|
|
123
98
|
continue;
|
|
@@ -141,12 +116,7 @@ function clipSegment(a, b, box) {
|
|
|
141
116
|
{ x: a.x + t1 * dx, y: a.y + t1 * dy },
|
|
142
117
|
];
|
|
143
118
|
}
|
|
144
|
-
/**
|
|
145
|
-
* The legend of a line chart: the shared one, with a small rounded-square
|
|
146
|
-
* swatch in place of the wide chip. A bar's or a wedge's swatch stands in for
|
|
147
|
-
* an area of paint and is drawn like one; a line's stands in for a colour, and
|
|
148
|
-
* a square reads as the sample it is.
|
|
149
|
-
*/
|
|
119
|
+
/** The shared legend with a small square swatch: a line's swatch stands for a colour, where a bar's or wedge's stands for an area of paint. */
|
|
150
120
|
const LINE_CHART_LEGEND = {
|
|
151
121
|
...DEFAULT_LEGEND,
|
|
152
122
|
markerStyle: {
|
|
@@ -156,7 +126,6 @@ const LINE_CHART_LEGEND = {
|
|
|
156
126
|
borderRadius: 6,
|
|
157
127
|
},
|
|
158
128
|
};
|
|
159
|
-
/** The chart's out-of-the-box look. */
|
|
160
129
|
export const DEFAULT_CHART_THEME = {
|
|
161
130
|
seriesStyles: DEFAULT_SERIES_STROKES,
|
|
162
131
|
xAxis: DEFAULT_X_AXIS,
|
|
@@ -164,16 +133,13 @@ export const DEFAULT_CHART_THEME = {
|
|
|
164
133
|
plotArea: DEFAULT_PLOT_AREA,
|
|
165
134
|
legend: LINE_CHART_LEGEND,
|
|
166
135
|
region: {
|
|
167
|
-
// Brighter
|
|
168
|
-
// rather than another axis line; `butt` caps keep the dash lengths exact.
|
|
136
|
+
// Brighter and dashed so it reads as a call-out, not an axis line; `butt` caps keep dash lengths exact.
|
|
169
137
|
stroke: {
|
|
170
138
|
weight: 3,
|
|
171
139
|
fill: CHART_PALETTE.regionColor,
|
|
172
140
|
dash: [14, 12],
|
|
173
141
|
cap: "butt",
|
|
174
142
|
},
|
|
175
|
-
// A wash barely above the panel — enough to tint the band, not enough to
|
|
176
|
-
// mute the series drawn over it.
|
|
177
143
|
fill: Fills.color(CHART_PALETTE.regionColor, { opacity: 0.08 }),
|
|
178
144
|
dimOpacity: SPOTLIGHT_DIM,
|
|
179
145
|
},
|
|
@@ -192,11 +158,7 @@ function lerpRegionConfig(from, to, t) {
|
|
|
192
158
|
dimOpacity: lerpNumber(from.dimOpacity, to.dimOpacity, t),
|
|
193
159
|
};
|
|
194
160
|
}
|
|
195
|
-
/**
|
|
196
|
-
* {@link LineChart}'s `theme` entry's resolve: merges the author's partial
|
|
197
|
-
* {@link ChartTheme} onto `previous` (falling back to
|
|
198
|
-
* {@link DEFAULT_CHART_THEME} on first resolution), fully resolving every leaf.
|
|
199
|
-
*/
|
|
161
|
+
/** The `theme` entry's resolve: merges a partial {@link ChartTheme} onto `previous` (first resolution: the default). */
|
|
200
162
|
export function resolveChartTheme(theme, previous) {
|
|
201
163
|
const base = previous ?? DEFAULT_CHART_THEME;
|
|
202
164
|
return {
|
|
@@ -208,7 +170,6 @@ export function resolveChartTheme(theme, previous) {
|
|
|
208
170
|
region: resolveRegionConfig(theme?.region, base.region),
|
|
209
171
|
};
|
|
210
172
|
}
|
|
211
|
-
/** {@link LineChart}'s `theme` entry's lerp — leaf by leaf. */
|
|
212
173
|
export function lerpChartTheme(from, to, t) {
|
|
213
174
|
return {
|
|
214
175
|
seriesStyles: lerpSeriesStrokes(from.seriesStyles, to.seriesStyles, t),
|
|
@@ -219,26 +180,16 @@ export function lerpChartTheme(from, to, t) {
|
|
|
219
180
|
region: lerpRegionConfig(from.region, to.region, t),
|
|
220
181
|
};
|
|
221
182
|
}
|
|
222
|
-
// ---- Scales --------------------------------------------------------------
|
|
223
183
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* in.
|
|
228
|
-
*
|
|
229
|
-
* A row missing its y column contributes a 0 rather than a gap — these charts
|
|
230
|
-
* draw continuous lines, so dropping the point would silently bridge the hole.
|
|
231
|
-
*
|
|
232
|
-
* Takes the resolved scale rather than the column *name*, because what a row's x
|
|
233
|
-
* is depends on what kind of column it came out of: a number, an instant, or a
|
|
234
|
-
* place in the file. See `x-scale.ts`.
|
|
184
|
+
* One series' `[x, y]` points, sorted along x so the polyline traces left to
|
|
185
|
+
* right. A row missing its y contributes 0 rather than a gap, since dropping it
|
|
186
|
+
* would silently bridge the hole.
|
|
235
187
|
*/
|
|
236
188
|
export function seriesPoints(data, x, series) {
|
|
237
189
|
return data
|
|
238
190
|
.map((row, i) => [x.at(i), num(row, series.field)])
|
|
239
191
|
.sort((a, b) => a[0] - b[0]);
|
|
240
192
|
}
|
|
241
|
-
/** Min/max across every series' column, the fallback when unset. */
|
|
242
193
|
export function yExtent(data, series) {
|
|
243
194
|
let lo = Infinity;
|
|
244
195
|
let hi = -Infinity;
|
|
@@ -253,11 +204,9 @@ export function yExtent(data, series) {
|
|
|
253
204
|
return lo <= hi ? [lo, hi] : [0, 1];
|
|
254
205
|
}
|
|
255
206
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* `divisions` is how many segments the auto-range is stepped into (one fewer
|
|
260
|
-
* than a marker count) — it only shapes the tidy step when `range` is omitted.
|
|
207
|
+
* The explicit `range`, else the data's y extent nudged out to tidy step bounds.
|
|
208
|
+
* `divisions` (one fewer than the marker count) only shapes the step when
|
|
209
|
+
* `range` is omitted.
|
|
261
210
|
*/
|
|
262
211
|
export function resolveYScale(data, series, range, divisions) {
|
|
263
212
|
if (range)
|
|
@@ -270,11 +219,9 @@ export function resolveYScale(data, series, range, divisions) {
|
|
|
270
219
|
return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step];
|
|
271
220
|
}
|
|
272
221
|
/**
|
|
273
|
-
* The scale for data
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* `[3, 7]` and `5000` gets `[3000, 7000]`), or to `[0, 1]` for all zeros, as for
|
|
277
|
-
* no data at all.
|
|
222
|
+
* The scale for constant data. A zero-width scale would put every tick on one
|
|
223
|
+
* value and the line on the floor, so it widens by a step sized to the
|
|
224
|
+
* magnitude (`5` gets `[3, 7]`), or `[0, 1]` for zero.
|
|
278
225
|
*/
|
|
279
226
|
function constantScale(value, segments) {
|
|
280
227
|
if (value === 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/line-chart/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,SAAS,GAMV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,GAAG,EACH,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GAOrB,MAAM,eAAe,CAAA;AAoDtB,4DAA4D;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAc;IACzC,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;CAChB,CAAA;AAED,oFAAoF;AACpF,MAAM,UAAU,SAAS,CAAC,GAAc;IACtC,OAAO,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;AACrD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAqC,EACrC,IAAkE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AAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAA;IACnD,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,aAAa,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAA;IAC3C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;AACpE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,KAAa,EAAE,QAAgB;IACpD,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAA;IACjD,OAAO,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAA;AACrC,CAAC","sourcesContent":["/**\n * Types and pure helpers specific to the {@link LineChart} family: the traced\n * polylines, the spotlit region they dim outside of, and the theme those two\n * add to the shared chart vocabulary.\n *\n * Everything a bar or a pie chart would want too — what a series is, how an axis\n * is scaled and formatted, the theme leaf resolvers, the legend and plot-panel\n * branches — lives in `../kit/shared.ts` and is imported here. What's\n * left below is what only a line chart has: points sorted along an x column,\n * a region clipped out of a polyline, and the `region` branch of the theme.\n *\n * Kept renderer-agnostic (no `Node` imports) so every part shares one\n * scale/format/palette/theme vocabulary, and so a host's own inspector\n * mapping can build a partial {@link ChartTheme} without\n * pulling the components in.\n */\n\nimport {\n Fills,\n fillOps,\n lerpNumber,\n strokeOps,\n type DataRecord,\n type Fill,\n type FillResolved,\n type Stroke,\n type StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport {\n CHART_PALETTE,\n DEFAULT_LEGEND,\n DEFAULT_PLOT_AREA,\n DEFAULT_SERIES_STROKES,\n DEFAULT_X_AXIS,\n DEFAULT_Y_AXIS,\n SPOTLIGHT_DIM,\n lerpAxisConfig,\n lerpLegendConfig,\n lerpPlotArea,\n lerpSeriesStrokes,\n niceStep,\n num,\n resolveAxisConfig,\n resolveLegendConfig,\n resolvePlotArea,\n resolveSeriesStrokes,\n type AxisConfig,\n type ChartSeries,\n type LegendConfig,\n type LegendTheme,\n type PlotAreaConfig,\n type Range,\n} from \"../kit/shared\"\nimport type { XScale } from \"./x-scale\"\n\n/**\n * One series in a {@link LineChart}: a polyline traced through the values in one\n * column of the chart's `data`, drawn in `fill` (or the theme's `seriesStyles`\n * palette when omitted) and captioned by `label` in the legend.\n *\n * The family-wide {@link ChartSeries} under a name that says what it draws here;\n * the chart's own `xField` prop names the column carrying the shared x values,\n * so every series is read off the same rows — one row per sample, one column per\n * series.\n */\nexport type LineSeries = ChartSeries\n\n// ---- Plot regions -------------------------------------------------------\n\n/**\n * A rectangular slice of the plot, in **data units** — the author-facing input\n * to {@link LineChart.spotlightRegion} / {@link LineChart.zoomTo}.\n *\n * Either axis may be omitted, and that's the point: `{ x: [60, 100] }` is a\n * vertical band spanning the full height, `{ y: [8, 10] }` a horizontal band\n * spanning the full width, and both together a box. A reversed range is read\n * the same as the forward one — a region is a span, not a direction.\n */\nexport interface PlotRegion {\n /** Horizontal span in x-axis data units. Omit to span the full plot width. */\n x?: Range\n /** Vertical span in y-axis data units. Omit to span the full plot height. */\n y?: Range\n}\n\n/**\n * A {@link PlotRegion} resolved into the plot's **centred pixel space** (origin\n * at the plot centre, y-up) — the same local frame the series points live in,\n * so a line can be clipped against it directly.\n *\n * `xBounded`/`yBounded` carry which axes the author actually constrained: an\n * unbounded axis has its edges pinned to the plot's own and draws no rule.\n */\nexport interface RegionBox {\n left: number\n right: number\n bottom: number\n top: number\n /** The author gave an x range — the left/right edges are real data bounds. */\n xBounded: boolean\n /** The author gave a y range — the bottom/top edges are real data bounds. */\n yBounded: boolean\n}\n\n/** The empty box, used as the \"no region\" resting value. */\nexport const EMPTY_REGION_BOX: RegionBox = {\n left: 0,\n right: 0,\n bottom: 0,\n top: 0,\n xBounded: false,\n yBounded: false,\n}\n\n/** Is `box` a real, non-degenerate region — i.e. is there anything to spotlight? */\nexport function hasRegion(box: RegionBox): boolean {\n return box.right > box.left && box.top > box.bottom\n}\n\n/**\n * Resolve a {@link PlotRegion} against the plot's pixel box and the chart's\n * scales. `plot` is the plot rectangle in centred pixel space, and\n * `xScale`/`yScale` the data ranges those edges span.\n *\n * An omitted axis takes the plot's own edges, so the region spans it. A given\n * axis is clamped to the plot, so a range running off the scale still produces\n * a box inside the panel.\n */\nexport function resolveRegionBox(\n region: PlotRegion | null | undefined,\n plot: { left: number; right: number; bottom: number; top: number },\n xScale: Range,\n yScale: Range\n): RegionBox {\n if (!region || (region.x === undefined && region.y === undefined)) {\n return EMPTY_REGION_BOX\n }\n\n const span = (\n range: Range | undefined,\n [min, max]: Range,\n lo: number,\n hi: number\n ): [number, number, boolean] => {\n if (range === undefined || max <= min) return [lo, hi, false]\n const a = Math.min(range[0], range[1])\n const b = Math.max(range[0], range[1])\n const toPx = (v: number) => lo + ((v - min) / (max - min)) * (hi - lo)\n return [\n Math.max(lo, Math.min(hi, toPx(a))),\n Math.max(lo, Math.min(hi, toPx(b))),\n true,\n ]\n }\n\n const [left, right, xBounded] = span(region.x, xScale, plot.left, plot.right)\n const [bottom, top, yBounded] = span(region.y, yScale, plot.bottom, plot.top)\n return { left, right, bottom, top, xBounded, yBounded }\n}\n\n/** A bare `{x, y}` — declared locally so this module stays free of node imports. */\ninterface Vector2Like {\n x: number\n y: number\n}\n\n/**\n * The parts of `points` that fall **inside** `box`, as a list of contiguous\n * sub-polylines — the geometry behind the region spotlight: a series is drawn\n * dimmed in full, then these runs are re-drawn over it at full strength.\n *\n * Segments are clipped against the box rather than filtered by endpoint, so a\n * line entering the region mid-segment is cut exactly on the boundary.\n */\nexport function clipPolylineToBox(\n points: Vector2Like[],\n box: RegionBox\n): Vector2Like[][] {\n if (points.length < 2 || !hasRegion(box)) return []\n\n const runs: Vector2Like[][] = []\n let run: Vector2Like[] = []\n\n for (let i = 1; i < points.length; i++) {\n const seg = clipSegment(points[i - 1], points[i], box)\n if (!seg) {\n // Segment misses the box entirely — close whatever run was open.\n if (run.length >= 2) runs.push(run)\n run = []\n continue\n }\n const [a, b] = seg\n // Continue the open run when this clipped segment starts where the last one\n // ended; otherwise the line left the box and came back, which is a new run.\n if (run.length > 0 && samePoint(run[run.length - 1], a)) run.push(b)\n else {\n if (run.length >= 2) runs.push(run)\n run = [a, b]\n }\n }\n if (run.length >= 2) runs.push(run)\n return runs\n}\n\n/** Points within half a pixel are the same point, for run-joining purposes. */\nfunction samePoint(a: Vector2Like, b: Vector2Like): boolean {\n return Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5\n}\n\n/**\n * Liang–Barsky clip of one segment against the axis-aligned `box`. Returns the\n * surviving `[start, end]`, or `null` when the segment lies wholly outside.\n */\nfunction clipSegment(\n a: Vector2Like,\n b: Vector2Like,\n box: RegionBox\n): [Vector2Like, Vector2Like] | null {\n const dx = b.x - a.x\n const dy = b.y - a.y\n let t0 = 0\n let t1 = 1\n\n // Each edge as (p, q): the segment survives where p·t <= q.\n const edges: [number, number][] = [\n [-dx, a.x - box.left],\n [dx, box.right - a.x],\n [-dy, a.y - box.bottom],\n [dy, box.top - a.y],\n ]\n for (const [p, q] of edges) {\n if (p === 0) {\n // Parallel to this edge: outside it means the whole segment is out.\n if (q < 0) return null\n continue\n }\n const r = q / p\n if (p < 0) {\n if (r > t1) return null\n if (r > t0) t0 = r\n } else {\n if (r < t0) return null\n if (r < t1) t1 = r\n }\n }\n return [\n { x: a.x + t0 * dx, y: a.y + t0 * dy },\n { x: a.x + t1 * dx, y: a.y + t1 * dy },\n ]\n}\n\n// ---- Theme ---------------------------------------------------------------\n\n/**\n * How a spotlit {@link PlotRegion} is drawn — the dashed rules on its bounded\n * edges, the wash filling it, and how far the series fade outside it.\n */\nexport interface RegionConfig {\n /** The dashed rule marking each bounded edge. */\n stroke: Stroke\n /** Wash filling the region, drawn under the series lines. */\n fill: Fill\n /** Opacity the stretch of every series *outside* the region fades to. */\n dimOpacity: number\n}\n\n/** A {@link LineChart}'s full, resolved visual theme. */\nexport interface ChartConfig {\n /**\n * Default per-series line stroke, cycled by series index (`i % length`). A\n * series' own `fill`, when set, overrides just the colour.\n */\n seriesStyles: Stroke[]\n xAxis: AxisConfig\n yAxis: AxisConfig\n /** The plot panel: border, fill, and drop shadow. */\n plotArea: PlotAreaConfig\n legend: LegendConfig\n /** The spotlit-region annotation — see {@link RegionConfig}. */\n region: RegionConfig\n}\n\n/**\n * Author-facing partial theme, passed as {@link LineChart}'s `theme` prop —\n * every branch optional and deep-merged onto {@link DEFAULT_CHART_THEME}.\n */\nexport type ChartTheme = {\n seriesStyles?: Stroke[]\n xAxis?: Partial<AxisConfig>\n yAxis?: Partial<AxisConfig>\n plotArea?: Partial<PlotAreaConfig>\n legend?: LegendTheme\n region?: Partial<RegionConfig>\n}\n\n/**\n * The legend of a line chart: the shared one, with a small rounded-square\n * swatch in place of the wide chip. A bar's or a wedge's swatch stands in for\n * an area of paint and is drawn like one; a line's stands in for a colour, and\n * a square reads as the sample it is.\n */\nconst LINE_CHART_LEGEND: LegendConfig = {\n ...DEFAULT_LEGEND,\n markerStyle: {\n ...DEFAULT_LEGEND.markerStyle,\n width: 20,\n height: 20,\n borderRadius: 6,\n },\n}\n\n/** The chart's out-of-the-box look. */\nexport const DEFAULT_CHART_THEME: ChartConfig = {\n seriesStyles: DEFAULT_SERIES_STROKES,\n xAxis: DEFAULT_X_AXIS,\n yAxis: DEFAULT_Y_AXIS,\n plotArea: DEFAULT_PLOT_AREA,\n legend: LINE_CHART_LEGEND,\n region: {\n // Brighter than the grid and dashed, so the boundary reads as a call-out\n // rather than another axis line; `butt` caps keep the dash lengths exact.\n stroke: {\n weight: 3,\n fill: CHART_PALETTE.regionColor,\n dash: [14, 12],\n cap: \"butt\",\n },\n // A wash barely above the panel — enough to tint the band, not enough to\n // mute the series drawn over it.\n fill: Fills.color(CHART_PALETTE.regionColor, { opacity: 0.08 }),\n dimOpacity: SPOTLIGHT_DIM,\n },\n}\n\nfunction resolveRegionConfig(\n region: Partial<RegionConfig> | undefined,\n previous: RegionConfig\n): RegionConfig {\n return {\n stroke: strokeOps.resolve(region?.stroke ?? previous.stroke),\n fill: fillOps.resolve(region?.fill ?? previous.fill),\n dimOpacity: region?.dimOpacity ?? previous.dimOpacity,\n }\n}\n\nfunction lerpRegionConfig(\n from: RegionConfig,\n to: RegionConfig,\n t: number\n): RegionConfig {\n return {\n stroke: strokeOps.lerp(\n from.stroke as StrokeResolved[],\n to.stroke as StrokeResolved[],\n t\n ),\n fill: fillOps.lerp(\n from.fill as FillResolved[],\n to.fill as FillResolved[],\n t\n ),\n dimOpacity: lerpNumber(from.dimOpacity, to.dimOpacity, t),\n }\n}\n\n/**\n * {@link LineChart}'s `theme` entry's resolve: merges the author's partial\n * {@link ChartTheme} onto `previous` (falling back to\n * {@link DEFAULT_CHART_THEME} on first resolution), fully resolving every leaf.\n */\nexport function resolveChartTheme(\n theme: ChartTheme | undefined,\n previous?: ChartConfig\n): ChartConfig {\n const base = previous ?? DEFAULT_CHART_THEME\n return {\n seriesStyles: resolveSeriesStrokes(theme?.seriesStyles, base.seriesStyles),\n xAxis: resolveAxisConfig(theme?.xAxis, base.xAxis),\n yAxis: resolveAxisConfig(theme?.yAxis, base.yAxis),\n plotArea: resolvePlotArea(theme?.plotArea, base.plotArea),\n legend: resolveLegendConfig(theme?.legend, base.legend),\n region: resolveRegionConfig(theme?.region, base.region),\n }\n}\n\n/** {@link LineChart}'s `theme` entry's lerp — leaf by leaf. */\nexport function lerpChartTheme(\n from: ChartConfig,\n to: ChartConfig,\n t: number\n): ChartConfig {\n return {\n seriesStyles: lerpSeriesStrokes(from.seriesStyles, to.seriesStyles, t),\n xAxis: lerpAxisConfig(from.xAxis, to.xAxis, t),\n yAxis: lerpAxisConfig(from.yAxis, to.yAxis, t),\n plotArea: lerpPlotArea(from.plotArea, to.plotArea, t),\n legend: lerpLegendConfig(from.legend, to.legend, t),\n region: lerpRegionConfig(from.region, to.region, t),\n }\n}\n\n// ---- Scales --------------------------------------------------------------\n\n/**\n * Resolve one series' `[x, y]` points out of the chart's rows: each row's\n * position on the {@link XScale} paired with its own `field` column, sorted\n * along x so the polyline traces left-to-right whatever order the rows arrived\n * in.\n *\n * A row missing its y column contributes a 0 rather than a gap — these charts\n * draw continuous lines, so dropping the point would silently bridge the hole.\n *\n * Takes the resolved scale rather than the column *name*, because what a row's x\n * is depends on what kind of column it came out of: a number, an instant, or a\n * place in the file. See `x-scale.ts`.\n */\nexport function seriesPoints(\n data: DataRecord[],\n x: XScale,\n series: LineSeries\n): [x: number, y: number][] {\n return data\n .map((row, i): [number, number] => [x.at(i), num(row, series.field)])\n .sort((a, b) => a[0] - b[0])\n}\n\n/** Min/max across every series' column, the fallback when unset. */\nexport function yExtent(data: DataRecord[], series: LineSeries[]): Range {\n let lo = Infinity\n let hi = -Infinity\n for (const row of data)\n for (const s of series) {\n const v = num(row, s.field)\n if (v < lo) lo = v\n if (v > hi) hi = v\n }\n return lo <= hi ? [lo, hi] : [0, 1]\n}\n\n/**\n * Effective vertical scale: the explicit `range`, else the data's y extent\n * nudged out to tidy step bounds so markers read as round numbers.\n *\n * `divisions` is how many segments the auto-range is stepped into (one fewer\n * than a marker count) — it only shapes the tidy step when `range` is omitted.\n */\nexport function resolveYScale(\n data: DataRecord[],\n series: LineSeries[],\n range: Range | undefined,\n divisions: number\n): Range {\n if (range) return range\n const [lo, hi] = yExtent(data, series)\n const segments = Math.max(1, Math.round(divisions))\n if (hi === lo) return constantScale(lo, segments)\n const step = niceStep((hi - lo) / segments)\n return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step]\n}\n\n/**\n * The scale for data that never moves. A zero-width scale puts every tick on the\n * same value and the line on the plot's floor, so it is widened to a few steps\n * either side of the value (the step sized to its magnitude, so `5` gets\n * `[3, 7]` and `5000` gets `[3000, 7000]`), or to `[0, 1]` for all zeros, as for\n * no data at all.\n */\nfunction constantScale(value: number, segments: number): Range {\n if (value === 0) return [0, 1]\n const step = niceStep(Math.abs(value) / segments)\n return [value - step, value + step]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/line-chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,SAAS,GAOV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAEtD,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,GAAG,EACH,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GAOrB,MAAM,eAAe,CAAA;AAgCtB,qCAAqC;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAc;IACzC,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;CAChB,CAAA;AAED,2EAA2E;AAC3E,MAAM,UAAU,SAAS,CAAC,GAAc;IACtC,OAAO,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;AACrD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAqC,EACrC,IAAkE,EAClE,MAAa,EACb,MAAa;IAEb,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,C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G,QAAQ,CAAC,CAAA;IAC3C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;AACpE,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAa,EAAE,QAAgB;IACpD,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAA;IACjD,OAAO,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import {\n Fills,\n fillOps,\n lerpNumber,\n strokeOps,\n type DataRecord,\n type Fill,\n type FillResolved,\n type Stroke,\n type StrokeResolved,\n type Vector2,\n} from \"@motionscript/sdk\"\nimport { niceStep } from \"@motionscript/sdk/component\"\n\nimport {\n CHART_PALETTE,\n DEFAULT_LEGEND,\n DEFAULT_PLOT_AREA,\n DEFAULT_SERIES_STROKES,\n DEFAULT_X_AXIS,\n DEFAULT_Y_AXIS,\n SPOTLIGHT_DIM,\n lerpAxisConfig,\n lerpLegendConfig,\n lerpPlotArea,\n lerpSeriesStrokes,\n num,\n resolveAxisConfig,\n resolveLegendConfig,\n resolvePlotArea,\n resolveSeriesStrokes,\n type AxisConfig,\n type ChartSeries,\n type LegendConfig,\n type LegendTheme,\n type PlotAreaConfig,\n type Range,\n} from \"../kit/shared\"\nimport type { XScale } from \"./x-scale\"\n\n/** One polyline of a {@link LineChart}: {@link ChartSeries} under the name for what it draws here. */\nexport type LineSeries = ChartSeries\n\n/**\n * A rectangular slice of the plot in data units, the input to `spotlightRegion`\n * and `zoomTo`. Either axis may be omitted: `{ x: [60, 100] }` is a full-height\n * band. A reversed range reads the same as a forward one.\n */\nexport interface PlotRegion {\n /** Omit to span the full plot width. */\n x?: Range\n /** Omit to span the full plot height. */\n y?: Range\n}\n\n/**\n * A {@link PlotRegion} in the plot's centred pixel space (origin at the centre,\n * y-up), the frame the series points live in. An axis the author left unbounded\n * has its edges pinned to the plot's own and draws no rule.\n */\nexport interface RegionBox {\n left: number\n right: number\n bottom: number\n top: number\n xBounded: boolean\n yBounded: boolean\n}\n\n/** The \"no region\" resting value. */\nexport const EMPTY_REGION_BOX: RegionBox = {\n left: 0,\n right: 0,\n bottom: 0,\n top: 0,\n xBounded: false,\n yBounded: false,\n}\n\n/** Whether `box` is non-degenerate, so there is something to spotlight. */\nexport function hasRegion(box: RegionBox): boolean {\n return box.right > box.left && box.top > box.bottom\n}\n\n/**\n * Resolve a {@link PlotRegion} against the plot rectangle (centred pixel space)\n * and the data ranges its edges span. An omitted axis takes the plot's own\n * edges; a given one is clamped to the plot.\n */\nexport function resolveRegionBox(\n region: PlotRegion | null | undefined,\n plot: { left: number; right: number; bottom: number; top: number },\n xScale: Range,\n yScale: Range\n): RegionBox {\n if (!region || (region.x === undefined && region.y === undefined)) {\n return EMPTY_REGION_BOX\n }\n\n const span = (\n range: Range | undefined,\n [min, max]: Range,\n lo: number,\n hi: number\n ): [number, number, boolean] => {\n if (range === undefined || max <= min) return [lo, hi, false]\n const a = Math.min(range[0], range[1])\n const b = Math.max(range[0], range[1])\n const toPx = (v: number) => lo + ((v - min) / (max - min)) * (hi - lo)\n return [\n Math.max(lo, Math.min(hi, toPx(a))),\n Math.max(lo, Math.min(hi, toPx(b))),\n true,\n ]\n }\n\n const [left, right, xBounded] = span(region.x, xScale, plot.left, plot.right)\n const [bottom, top, yBounded] = span(region.y, yScale, plot.bottom, plot.top)\n return { left, right, bottom, top, xBounded, yBounded }\n}\n\n/**\n * The parts of `points` inside `box`, as contiguous sub-polylines: a series is\n * drawn dimmed in full, then these runs are re-drawn at full strength. Segments\n * are clipped, not filtered by endpoint, so a line entering mid-segment is cut\n * exactly on the boundary.\n */\nexport function clipPolylineToBox(\n points: Vector2[],\n box: RegionBox\n): Vector2[][] {\n if (points.length < 2 || !hasRegion(box)) return []\n\n const runs: Vector2[][] = []\n let run: Vector2[] = []\n\n for (let i = 1; i < points.length; i++) {\n const seg = clipSegment(points[i - 1], points[i], box)\n if (!seg) {\n // Misses the box: close the open run.\n if (run.length >= 2) runs.push(run)\n run = []\n continue\n }\n const [a, b] = seg\n // Continues the open run if it starts where the last ended; otherwise the line left and came back.\n if (run.length > 0 && samePoint(run[run.length - 1], a)) run.push(b)\n else {\n if (run.length >= 2) runs.push(run)\n run = [a, b]\n }\n }\n if (run.length >= 2) runs.push(run)\n return runs\n}\n\n/** Points within half a pixel are the same point, for run-joining purposes. */\nfunction samePoint(a: Vector2, b: Vector2): boolean {\n return Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5\n}\n\n/** Liang-Barsky clip of one segment against `box`: the surviving `[start, end]`, or `null` when wholly outside. */\nfunction clipSegment(\n a: Vector2,\n b: Vector2,\n box: RegionBox\n): [Vector2, Vector2] | null {\n const dx = b.x - a.x\n const dy = b.y - a.y\n let t0 = 0\n let t1 = 1\n\n // Each edge as (p, q): the segment survives where p*t <= q.\n const edges: [number, number][] = [\n [-dx, a.x - box.left],\n [dx, box.right - a.x],\n [-dy, a.y - box.bottom],\n [dy, box.top - a.y],\n ]\n for (const [p, q] of edges) {\n if (p === 0) {\n // Parallel to this edge: outside it, the whole segment is out.\n if (q < 0) return null\n continue\n }\n const r = q / p\n if (p < 0) {\n if (r > t1) return null\n if (r > t0) t0 = r\n } else {\n if (r < t0) return null\n if (r < t1) t1 = r\n }\n }\n return [\n { x: a.x + t0 * dx, y: a.y + t0 * dy },\n { x: a.x + t1 * dx, y: a.y + t1 * dy },\n ]\n}\n\n/** How a spotlit {@link PlotRegion} is drawn: rules on its bounded edges, a wash, and how far series fade outside it. */\nexport interface RegionConfig {\n /** Marks each bounded edge. */\n stroke: Stroke\n /** Drawn under the series lines. */\n fill: Fill\n /** Opacity the stretch of every series outside the region fades to. */\n dimOpacity: number\n}\n\n/** A {@link LineChart}'s full, resolved visual theme. */\nexport interface ChartConfig {\n /** Cycled by series index; a series' own `fill` overrides just the colour. */\n seriesStyles: Stroke[]\n xAxis: AxisConfig\n yAxis: AxisConfig\n plotArea: PlotAreaConfig\n legend: LegendConfig\n region: RegionConfig\n}\n\n/** The author's partial theme, deep-merged onto {@link DEFAULT_CHART_THEME}. */\nexport type ChartTheme = {\n seriesStyles?: Stroke[]\n xAxis?: Partial<AxisConfig>\n yAxis?: Partial<AxisConfig>\n plotArea?: Partial<PlotAreaConfig>\n legend?: LegendTheme\n region?: Partial<RegionConfig>\n}\n\n/** The shared legend with a small square swatch: a line's swatch stands for a colour, where a bar's or wedge's stands for an area of paint. */\nconst LINE_CHART_LEGEND: LegendConfig = {\n ...DEFAULT_LEGEND,\n markerStyle: {\n ...DEFAULT_LEGEND.markerStyle,\n width: 20,\n height: 20,\n borderRadius: 6,\n },\n}\n\nexport const DEFAULT_CHART_THEME: ChartConfig = {\n seriesStyles: DEFAULT_SERIES_STROKES,\n xAxis: DEFAULT_X_AXIS,\n yAxis: DEFAULT_Y_AXIS,\n plotArea: DEFAULT_PLOT_AREA,\n legend: LINE_CHART_LEGEND,\n region: {\n // Brighter and dashed so it reads as a call-out, not an axis line; `butt` caps keep dash lengths exact.\n stroke: {\n weight: 3,\n fill: CHART_PALETTE.regionColor,\n dash: [14, 12],\n cap: \"butt\",\n },\n fill: Fills.color(CHART_PALETTE.regionColor, { opacity: 0.08 }),\n dimOpacity: SPOTLIGHT_DIM,\n },\n}\n\nfunction resolveRegionConfig(\n region: Partial<RegionConfig> | undefined,\n previous: RegionConfig\n): RegionConfig {\n return {\n stroke: strokeOps.resolve(region?.stroke ?? previous.stroke),\n fill: fillOps.resolve(region?.fill ?? previous.fill),\n dimOpacity: region?.dimOpacity ?? previous.dimOpacity,\n }\n}\n\nfunction lerpRegionConfig(\n from: RegionConfig,\n to: RegionConfig,\n t: number\n): RegionConfig {\n return {\n stroke: strokeOps.lerp(\n from.stroke as StrokeResolved[],\n to.stroke as StrokeResolved[],\n t\n ),\n fill: fillOps.lerp(\n from.fill as FillResolved[],\n to.fill as FillResolved[],\n t\n ),\n dimOpacity: lerpNumber(from.dimOpacity, to.dimOpacity, t),\n }\n}\n\n/** The `theme` entry's resolve: merges a partial {@link ChartTheme} onto `previous` (first resolution: the default). */\nexport function resolveChartTheme(\n theme: ChartTheme | undefined,\n previous?: ChartConfig\n): ChartConfig {\n const base = previous ?? DEFAULT_CHART_THEME\n return {\n seriesStyles: resolveSeriesStrokes(theme?.seriesStyles, base.seriesStyles),\n xAxis: resolveAxisConfig(theme?.xAxis, base.xAxis),\n yAxis: resolveAxisConfig(theme?.yAxis, base.yAxis),\n plotArea: resolvePlotArea(theme?.plotArea, base.plotArea),\n legend: resolveLegendConfig(theme?.legend, base.legend),\n region: resolveRegionConfig(theme?.region, base.region),\n }\n}\n\nexport function lerpChartTheme(\n from: ChartConfig,\n to: ChartConfig,\n t: number\n): ChartConfig {\n return {\n seriesStyles: lerpSeriesStrokes(from.seriesStyles, to.seriesStyles, t),\n xAxis: lerpAxisConfig(from.xAxis, to.xAxis, t),\n yAxis: lerpAxisConfig(from.yAxis, to.yAxis, t),\n plotArea: lerpPlotArea(from.plotArea, to.plotArea, t),\n legend: lerpLegendConfig(from.legend, to.legend, t),\n region: lerpRegionConfig(from.region, to.region, t),\n }\n}\n\n/**\n * One series' `[x, y]` points, sorted along x so the polyline traces left to\n * right. A row missing its y contributes 0 rather than a gap, since dropping it\n * would silently bridge the hole.\n */\nexport function seriesPoints(\n data: DataRecord[],\n x: XScale,\n series: LineSeries\n): [x: number, y: number][] {\n return data\n .map((row, i): [number, number] => [x.at(i), num(row, series.field)])\n .sort((a, b) => a[0] - b[0])\n}\n\nexport function yExtent(data: DataRecord[], series: LineSeries[]): Range {\n let lo = Infinity\n let hi = -Infinity\n for (const row of data)\n for (const s of series) {\n const v = num(row, s.field)\n if (v < lo) lo = v\n if (v > hi) hi = v\n }\n return lo <= hi ? [lo, hi] : [0, 1]\n}\n\n/**\n * The explicit `range`, else the data's y extent nudged out to tidy step bounds.\n * `divisions` (one fewer than the marker count) only shapes the step when\n * `range` is omitted.\n */\nexport function resolveYScale(\n data: DataRecord[],\n series: LineSeries[],\n range: Range | undefined,\n divisions: number\n): Range {\n if (range) return range\n const [lo, hi] = yExtent(data, series)\n const segments = Math.max(1, Math.round(divisions))\n if (hi === lo) return constantScale(lo, segments)\n const step = niceStep((hi - lo) / segments)\n return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step]\n}\n\n/**\n * The scale for constant data. A zero-width scale would put every tick on one\n * value and the line on the floor, so it widens by a step sized to the\n * magnitude (`5` gets `[3, 7]`), or `[0, 1]` for zero.\n */\nfunction constantScale(value: number, segments: number): Range {\n if (value === 0) return [0, 1]\n const step = niceStep(Math.abs(value) / segments)\n return [value - step, value + step]\n}\n"]}
|