@motionscript/charts 0.1.1-alpha.0 → 0.1.1-alpha.2
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 +34 -0
- package/README.md +109 -28
- package/dist/bar-chart/bar-chart.d.ts +265 -39
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +219 -171
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +12 -7
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +56 -42
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +76 -52
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +105 -89
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +4 -4
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +2 -2
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +41 -65
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +73 -117
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-7XCRX6GE.js +2 -0
- package/dist/browser/chunks/chunk-7XCRX6GE.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +5 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +5 -2
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kit/cartesian.d.ts +51 -15
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +81 -29
- package/dist/kit/cartesian.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -24
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +52 -46
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +8 -4
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +30 -20
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/{line-chart → kit}/horizontal-axis.d.ts +31 -6
- package/dist/kit/horizontal-axis.d.ts.map +1 -0
- package/dist/{line-chart → kit}/horizontal-axis.js +23 -24
- package/dist/kit/horizontal-axis.js.map +1 -0
- package/dist/kit/motion.d.ts +5 -0
- package/dist/kit/motion.d.ts.map +1 -1
- package/dist/kit/motion.js +8 -0
- package/dist/kit/motion.js.map +1 -1
- package/dist/{pie-chart → kit}/pie-legend.d.ts +3 -3
- package/dist/kit/pie-legend.d.ts.map +1 -0
- package/dist/{pie-chart → kit}/pie-legend.js +11 -10
- package/dist/kit/pie-legend.js.map +1 -0
- package/dist/kit/polar.d.ts +31 -0
- package/dist/kit/polar.d.ts.map +1 -0
- package/dist/kit/polar.js +33 -0
- package/dist/kit/polar.js.map +1 -0
- package/dist/kit/shared.d.ts +11 -50
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +58 -141
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/style.d.ts +517 -0
- package/dist/kit/style.d.ts.map +1 -0
- package/dist/kit/style.js +292 -0
- package/dist/kit/style.js.map +1 -0
- package/dist/kit/vertical-axis.d.ts +22 -2
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +56 -43
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +95 -3
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +165 -53
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +1 -1
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +7 -8
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/index.d.ts +5 -6
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +3 -4
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +281 -18
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +284 -134
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +51 -34
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +175 -83
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +2 -0
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +15 -0
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +3 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +9 -1
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -3
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -2
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +114 -18
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +38 -24
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +16 -5
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +89 -55
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +61 -62
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +44 -123
- package/dist/pie-chart/shared.js.map +1 -1
- package/dist/radar-chart/index.d.ts +5 -0
- package/dist/radar-chart/index.d.ts.map +1 -0
- package/dist/radar-chart/index.js +5 -0
- package/dist/radar-chart/index.js.map +1 -0
- package/dist/radar-chart/radar-chart.d.ts +212 -0
- package/dist/radar-chart/radar-chart.d.ts.map +1 -0
- package/dist/radar-chart/radar-chart.js +224 -0
- package/dist/radar-chart/radar-chart.js.map +1 -0
- package/dist/radar-chart/radar-grid.d.ts +49 -0
- package/dist/radar-chart/radar-grid.d.ts.map +1 -0
- package/dist/radar-chart/radar-grid.js +63 -0
- package/dist/radar-chart/radar-grid.js.map +1 -0
- package/dist/radar-chart/radar-series.d.ts +59 -0
- package/dist/radar-chart/radar-series.d.ts.map +1 -0
- package/dist/radar-chart/radar-series.js +71 -0
- package/dist/radar-chart/radar-series.js.map +1 -0
- package/dist/radar-chart/shared.d.ts +78 -0
- package/dist/radar-chart/shared.d.ts.map +1 -0
- package/dist/radar-chart/shared.js +129 -0
- package/dist/radar-chart/shared.js.map +1 -0
- package/dist/radial-chart/index.d.ts +6 -0
- package/dist/radial-chart/index.d.ts.map +1 -0
- package/dist/radial-chart/index.js +4 -0
- package/dist/radial-chart/index.js.map +1 -0
- package/dist/radial-chart/radial-chart.d.ts +210 -0
- package/dist/radial-chart/radial-chart.d.ts.map +1 -0
- package/dist/radial-chart/radial-chart.js +175 -0
- package/dist/radial-chart/radial-chart.js.map +1 -0
- package/dist/radial-chart/radial-rings.d.ts +121 -0
- package/dist/radial-chart/radial-rings.d.ts.map +1 -0
- package/dist/radial-chart/radial-rings.js +273 -0
- package/dist/radial-chart/radial-rings.js.map +1 -0
- package/dist/radial-chart/shared.d.ts +77 -0
- package/dist/radial-chart/shared.d.ts.map +1 -0
- package/dist/radial-chart/shared.js +78 -0
- package/dist/radial-chart/shared.js.map +1 -0
- package/package.json +4 -4
- package/registry.json +21 -6
- package/src/bar-chart/bar-chart.ts +263 -179
- package/src/bar-chart/category-axis.ts +46 -40
- package/src/bar-chart/chart-bars.ts +136 -117
- package/src/bar-chart/index.ts +7 -10
- package/src/bar-chart/shared.ts +88 -233
- package/src/engine.ts +5 -2
- package/src/index.ts +2 -0
- package/src/kit/cartesian.ts +121 -40
- package/src/kit/chart-canvas.ts +49 -54
- package/src/kit/chart-legend.ts +28 -20
- package/src/kit/horizontal-axis.ts +114 -0
- package/src/kit/motion.ts +7 -0
- package/src/{pie-chart → kit}/pie-legend.ts +12 -11
- package/src/kit/polar.ts +54 -0
- package/src/kit/shared.ts +55 -277
- package/src/kit/style.ts +353 -0
- package/src/kit/vertical-axis.ts +67 -48
- package/src/line-chart/chart-line.ts +176 -54
- package/src/line-chart/chart-region.ts +6 -10
- package/src/line-chart/index.ts +14 -10
- package/src/line-chart/line-chart.ts +353 -151
- package/src/line-chart/shared.ts +193 -174
- package/src/line-chart/x-scale.ts +13 -0
- package/src/nodes.ts +9 -1
- package/src/pie-chart/index.ts +2 -23
- package/src/pie-chart/pie-chart.ts +54 -35
- package/src/pie-chart/pie-ring.ts +92 -71
- package/src/pie-chart/shared.ts +80 -270
- package/src/radar-chart/index.ts +4 -0
- package/src/radar-chart/radar-chart.ts +290 -0
- package/src/radar-chart/radar-grid.ts +83 -0
- package/src/radar-chart/radar-series.ts +88 -0
- package/src/radar-chart/shared.ts +153 -0
- package/src/radial-chart/index.ts +5 -0
- package/src/radial-chart/radial-chart.ts +212 -0
- package/src/radial-chart/radial-rings.ts +328 -0
- package/src/radial-chart/shared.ts +126 -0
- package/dist/browser/chunks/chunk-4SMRCU24.js +0 -2
- package/dist/browser/chunks/chunk-4SMRCU24.js.map +0 -7
- package/dist/kit/chart-border.d.ts +0 -18
- package/dist/kit/chart-border.d.ts.map +0 -1
- package/dist/kit/chart-border.js +0 -23
- package/dist/kit/chart-border.js.map +0 -1
- package/dist/line-chart/horizontal-axis.d.ts.map +0 -1
- package/dist/line-chart/horizontal-axis.js.map +0 -1
- package/dist/pie-chart/pie-legend.d.ts.map +0 -1
- package/dist/pie-chart/pie-legend.js.map +0 -1
- package/src/kit/chart-border.ts +0 -36
- package/src/line-chart/horizontal-axis.ts +0 -122
|
@@ -1,83 +1,59 @@
|
|
|
1
|
-
import { type DataRecord, type Fill, type
|
|
2
|
-
import { type
|
|
1
|
+
import { type DataRecord, type Fill, type CornerRadiusResolved as _CornerRadiusResolved, type CornerStyleResolved as _CornerStyleResolved, type RectCornerRadius as _RectCornerRadius, type RectCornerStyle as _RectCornerStyle } from "@motionscript/sdk";
|
|
2
|
+
import { type ChartSeries, type Range } from "../kit/shared.js";
|
|
3
3
|
/** One bar per row, beside its siblings in the category slot or stacked on them: {@link ChartSeries} under the name for what it draws here. */
|
|
4
4
|
export type BarSeries = ChartSeries;
|
|
5
|
+
/** How the series share a category: side by side, stacked, or stacked as shares of 100. */
|
|
6
|
+
export type BarStack = "none" | "stacked" | "percent";
|
|
7
|
+
/** Which way the bars grow: up from a category row, or right from a category column. */
|
|
8
|
+
export type BarOrientation = "vertical" | "horizontal";
|
|
5
9
|
/**
|
|
6
|
-
* One bar's span in data units. A span rather than a height because
|
|
7
|
-
*
|
|
10
|
+
* One bar's span in data units. A span rather than a height because every mode
|
|
11
|
+
* fits it, and a negative value just runs the other way with no special case.
|
|
8
12
|
*/
|
|
9
13
|
export interface BarSpan {
|
|
10
|
-
/** Where the base sits: 0
|
|
14
|
+
/** Where the base sits: 0 apart, the running total below (or above, for a negative) when stacked. */
|
|
11
15
|
from: number;
|
|
12
16
|
to: number;
|
|
13
|
-
/** `to - from
|
|
17
|
+
/** `to - from`. */
|
|
14
18
|
value: number;
|
|
19
|
+
/** Whether it ends its stack on its side of zero, so its far end is rounded. */
|
|
20
|
+
outer: boolean;
|
|
15
21
|
}
|
|
16
22
|
/**
|
|
17
|
-
* One row's spans, in series order. Stacking
|
|
18
|
-
*
|
|
19
|
-
*
|
|
23
|
+
* One row's spans, in series order. Stacking keeps a running sum on each side
|
|
24
|
+
* of zero, so a negative value stacks downward from the baseline rather than
|
|
25
|
+
* eating into the positives. In `percent` each value is its share of the row's
|
|
26
|
+
* total magnitude. A zero value still yields a degenerate span, keeping the list
|
|
27
|
+
* index-aligned with the series. `weights` scale each series' contribution.
|
|
20
28
|
*/
|
|
21
|
-
export declare function barSpans(row: DataRecord, series: BarSeries[],
|
|
22
|
-
/**
|
|
23
|
-
* The series ending a row's stack, which gets the rounded cap; `-1` when the row
|
|
24
|
-
* is all zero. It is the last non-zero series, so a zero one does not take the
|
|
25
|
-
* cap and leave the segment below square.
|
|
26
|
-
*/
|
|
27
|
-
export declare function stackCapIndex(row: DataRecord, series: BarSeries[]): number;
|
|
29
|
+
export declare function barSpans(row: DataRecord, series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): BarSpan[];
|
|
28
30
|
export declare function barCategories(data: DataRecord[], field: string): string[];
|
|
29
31
|
/**
|
|
30
32
|
* The `[min, max]` of everything drawn, zero always included: a scale starting
|
|
31
|
-
* at 40 draws a
|
|
33
|
+
* at 40 draws a bar three times its neighbour for a 10% difference. A cropped
|
|
32
34
|
* axis takes an explicit range.
|
|
33
35
|
*/
|
|
34
|
-
export declare function barValueExtent(data: DataRecord[], series: BarSeries[],
|
|
35
|
-
/** The explicit `range`, else the data's extent nudged to tidy bounds; `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
|
|
36
|
-
export declare function resolveBarScale(data: DataRecord[], series: BarSeries[],
|
|
37
|
-
/**
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
yAxis: AxisConfig;
|
|
57
|
-
plotArea: PlotAreaConfig;
|
|
58
|
-
legend: LegendConfig;
|
|
59
|
-
/** The figure printed on each column. */
|
|
60
|
-
valueStyle: TextStyle;
|
|
61
|
-
/** How far everything outside a spotlit series or category fades. */
|
|
62
|
-
spotlight: {
|
|
63
|
-
dimOpacity: number;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/** The author's partial theme, deep-merged onto {@link DEFAULT_BAR_CHART_THEME}. */
|
|
67
|
-
export type BarChartTheme = {
|
|
68
|
-
seriesFills?: Fill[];
|
|
69
|
-
bar?: Partial<BarStyleConfig>;
|
|
70
|
-
xAxis?: Partial<AxisConfig>;
|
|
71
|
-
yAxis?: Partial<AxisConfig>;
|
|
72
|
-
plotArea?: Partial<PlotAreaConfig>;
|
|
73
|
-
legend?: LegendTheme;
|
|
74
|
-
valueStyle?: TextStyle;
|
|
75
|
-
spotlight?: Partial<BarChartConfig["spotlight"]>;
|
|
36
|
+
export declare function barValueExtent(data: DataRecord[], series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): Range;
|
|
37
|
+
/** The explicit `range`, else the data's extent nudged to tidy bounds (a percent stack reads to 100); `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
|
|
38
|
+
export declare function resolveBarScale(data: DataRecord[], series: readonly BarSeries[], stack: BarStack, range: Range | undefined, divisions: number, weights?: readonly number[]): Range;
|
|
39
|
+
/** Black or white, whichever reads on `fill`: a figure printed inside a bar. */
|
|
40
|
+
export declare function inkOn(fill: Fill): string;
|
|
41
|
+
/** A bar chart's own look: its corners, and how wide the bars are. */
|
|
42
|
+
export declare const BAR_MARKS: {
|
|
43
|
+
/**
|
|
44
|
+
* Each corner as for a bar standing up from the baseline: the top pair round
|
|
45
|
+
* its far end, the bottom pair its base. Inside a stack, a segment's far end
|
|
46
|
+
* stays square unless it ends the stack, and its base unless it starts it.
|
|
47
|
+
*/
|
|
48
|
+
barCornerRadius: import("@motionscript/sdk").Type<_RectCornerRadius, _CornerRadiusResolved, false>;
|
|
49
|
+
barCornerStyle: import("@motionscript/sdk").Type<_RectCornerStyle, _CornerStyleResolved, false>;
|
|
50
|
+
/** How much of its category slot a bar group fills, the rest spacing the groups. */
|
|
51
|
+
barWidth: import("@motionscript/sdk").Type<number, number, false>;
|
|
52
|
+
/** Space between the bars of one group, side by side. */
|
|
53
|
+
barGap: import("@motionscript/sdk").Type<number, number, false>;
|
|
54
|
+
};
|
|
55
|
+
export declare const BAR_LABELS: {
|
|
56
|
+
/** Read as the chart is built: each bar's value past its end, inside it, or none. */
|
|
57
|
+
values: import("@motionscript/sdk").Type<"end" | "inside" | "none", "end" | "inside" | "none", false>;
|
|
76
58
|
};
|
|
77
|
-
export declare const DEFAULT_BAR_CHART_THEME: BarChartConfig;
|
|
78
|
-
/** The `theme` entry's resolve: merges a partial {@link BarChartTheme} onto `previous` (first resolution: the default). */
|
|
79
|
-
export declare function resolveBarChartTheme(theme: BarChartTheme | undefined, previous?: BarChartConfig): BarChartConfig;
|
|
80
|
-
export declare function lerpBarChartTheme(from: BarChartConfig, to: BarChartConfig, t: number): BarChartConfig;
|
|
81
|
-
/** Series `index`'s own `fill`, else the palette's entry. */
|
|
82
|
-
export declare function resolveBarFill(palette: Fill[], series: BarSeries, index: number): Fill;
|
|
83
59
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/bar-chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/bar-chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,IAAI,EAET,KAAK,oBAAoB,IAAI,qBAAqB,EAClD,KAAK,mBAAmB,IAAI,oBAAoB,EAChD,KAAK,gBAAgB,IAAI,iBAAiB,EAC1C,KAAK,eAAe,IAAI,gBAAgB,EACzC,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAwB,KAAK,WAAW,EAAE,KAAK,KAAK,EAAE,MAAM,eAAe,CAAA;AAElF,+IAA+I;AAC/I,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AAEnC,2FAA2F;AAC3F,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAA;AAErD,wFAAwF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
CHANGED
|
@@ -1,143 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { CHART_PALETTE, DEFAULT_LEGEND, DEFAULT_PLOT_AREA, DEFAULT_SERIES_FILLS, DEFAULT_X_AXIS, DEFAULT_Y_AXIS, SPOTLIGHT_DIM, lerpAxisConfig, lerpLegendConfig, lerpPlotArea, lerpSeriesFills, num, resolveAxisConfig, resolveLegendConfig, resolvePlotArea, resolveSeriesFills, text, } from "../kit/shared.js";
|
|
1
|
+
import { Types, fillOps, } from "@motionscript/sdk";
|
|
2
|
+
import { niceRange, num, text } from "../kit/shared.js";
|
|
4
3
|
/**
|
|
5
|
-
* One row's spans, in series order. Stacking
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* One row's spans, in series order. Stacking keeps a running sum on each side
|
|
5
|
+
* of zero, so a negative value stacks downward from the baseline rather than
|
|
6
|
+
* eating into the positives. In `percent` each value is its share of the row's
|
|
7
|
+
* total magnitude. A zero value still yields a degenerate span, keeping the list
|
|
8
|
+
* index-aligned with the series. `weights` scale each series' contribution.
|
|
8
9
|
*/
|
|
9
|
-
export function barSpans(row, series,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return { from: 0, to: value, value };
|
|
15
|
-
|
|
16
|
-
running += value;
|
|
17
|
-
return { from, to: running, value };
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The series ending a row's stack, which gets the rounded cap; `-1` when the row
|
|
22
|
-
* is all zero. It is the last non-zero series, so a zero one does not take the
|
|
23
|
-
* cap and leave the segment below square.
|
|
24
|
-
*/
|
|
25
|
-
export function stackCapIndex(row, series) {
|
|
26
|
-
let last = -1;
|
|
27
|
-
for (let i = 0; i < series.length; i++) {
|
|
28
|
-
if (num(row, series[i].field) !== 0)
|
|
29
|
-
last = i;
|
|
10
|
+
export function barSpans(row, series, stack, weights = []) {
|
|
11
|
+
const weight = (i) => Math.max(0, weights[i] ?? 1);
|
|
12
|
+
if (stack !== "stacked" && stack !== "percent") {
|
|
13
|
+
return series.map((s) => {
|
|
14
|
+
const value = num(row, s.field);
|
|
15
|
+
return { from: 0, to: value, value, outer: true };
|
|
16
|
+
});
|
|
30
17
|
}
|
|
31
|
-
|
|
18
|
+
const values = series.map((s, i) => num(row, s.field) * weight(i));
|
|
19
|
+
const total = values.reduce((sum, v) => sum + Math.abs(v), 0);
|
|
20
|
+
const scaled = stack === "percent" ? values.map((v) => (total > 0 ? (v / total) * 100 : 0)) : values;
|
|
21
|
+
let lastUp = -1;
|
|
22
|
+
let lastDown = -1;
|
|
23
|
+
scaled.forEach((v, i) => {
|
|
24
|
+
if (v > 0)
|
|
25
|
+
lastUp = i;
|
|
26
|
+
else if (v < 0)
|
|
27
|
+
lastDown = i;
|
|
28
|
+
});
|
|
29
|
+
let up = 0;
|
|
30
|
+
let down = 0;
|
|
31
|
+
return scaled.map((value, i) => {
|
|
32
|
+
if (value < 0) {
|
|
33
|
+
const from = down;
|
|
34
|
+
down += value;
|
|
35
|
+
return { from, to: down, value, outer: i === lastDown };
|
|
36
|
+
}
|
|
37
|
+
const from = up;
|
|
38
|
+
up += value;
|
|
39
|
+
return { from, to: up, value, outer: i === lastUp };
|
|
40
|
+
});
|
|
32
41
|
}
|
|
33
42
|
export function barCategories(data, field) {
|
|
34
43
|
return data.map((row) => text(row, field));
|
|
35
44
|
}
|
|
36
45
|
/**
|
|
37
46
|
* The `[min, max]` of everything drawn, zero always included: a scale starting
|
|
38
|
-
* at 40 draws a
|
|
47
|
+
* at 40 draws a bar three times its neighbour for a 10% difference. A cropped
|
|
39
48
|
* axis takes an explicit range.
|
|
40
49
|
*/
|
|
41
|
-
export function barValueExtent(data, series,
|
|
50
|
+
export function barValueExtent(data, series, stack, weights) {
|
|
42
51
|
let lo = 0;
|
|
43
52
|
let hi = 0;
|
|
44
53
|
for (const row of data) {
|
|
45
|
-
for (const span of barSpans(row, series,
|
|
54
|
+
for (const span of barSpans(row, series, stack, weights)) {
|
|
46
55
|
lo = Math.min(lo, span.from, span.to);
|
|
47
56
|
hi = Math.max(hi, span.from, span.to);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
return lo < hi ? [lo, hi] : [0, 1];
|
|
51
60
|
}
|
|
52
|
-
/** The explicit `range`, else the data's extent nudged to tidy bounds; `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
|
|
53
|
-
export function resolveBarScale(data, series,
|
|
61
|
+
/** The explicit `range`, else the data's extent nudged to tidy bounds (a percent stack reads to 100); `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
|
|
62
|
+
export function resolveBarScale(data, series, stack, range, divisions, weights) {
|
|
54
63
|
if (range)
|
|
55
64
|
return range;
|
|
56
|
-
const [lo, hi] = barValueExtent(data, series,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return [
|
|
65
|
+
const [lo, hi] = barValueExtent(data, series, stack, weights);
|
|
66
|
+
if (stack === "percent")
|
|
67
|
+
return [lo < 0 ? -100 : 0, hi > 0 ? 100 : 0];
|
|
68
|
+
return niceRange([lo, hi], divisions);
|
|
60
69
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
groupGap: 6,
|
|
67
|
-
stroke: [],
|
|
68
|
-
shadow: [],
|
|
69
|
-
},
|
|
70
|
-
// Captions rather than numeric markers: less weight than the line chart's ticks.
|
|
71
|
-
xAxis: {
|
|
72
|
-
...DEFAULT_X_AXIS,
|
|
73
|
-
labelStyle: { ...DEFAULT_X_AXIS.labelStyle, fontWeight: 600 },
|
|
74
|
-
tickPadding: 16,
|
|
75
|
-
},
|
|
76
|
-
yAxis: DEFAULT_Y_AXIS,
|
|
77
|
-
plotArea: DEFAULT_PLOT_AREA,
|
|
78
|
-
legend: DEFAULT_LEGEND,
|
|
79
|
-
valueStyle: {
|
|
80
|
-
fontSize: 24,
|
|
81
|
-
fontWeight: 700,
|
|
82
|
-
textAlign: "center",
|
|
83
|
-
fill: CHART_PALETTE.markerColor,
|
|
84
|
-
},
|
|
85
|
-
spotlight: { dimOpacity: SPOTLIGHT_DIM },
|
|
86
|
-
};
|
|
87
|
-
function resolveBarStyle(bar, previous) {
|
|
88
|
-
return {
|
|
89
|
-
cornerRadius: bar?.cornerRadius ?? previous.cornerRadius,
|
|
90
|
-
slotFill: bar?.slotFill ?? previous.slotFill,
|
|
91
|
-
groupGap: bar?.groupGap ?? previous.groupGap,
|
|
92
|
-
stroke: strokeOps.resolve(bar?.stroke ?? previous.stroke),
|
|
93
|
-
shadow: shadowOps.resolve(bar?.shadow ?? previous.shadow),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function lerpBarStyle(from, to, t) {
|
|
97
|
-
return {
|
|
98
|
-
cornerRadius: lerpNumber(from.cornerRadius, to.cornerRadius, t),
|
|
99
|
-
slotFill: lerpNumber(from.slotFill, to.slotFill, t),
|
|
100
|
-
groupGap: lerpNumber(from.groupGap, to.groupGap, t),
|
|
101
|
-
stroke: strokeOps.lerp(from.stroke, to.stroke, t),
|
|
102
|
-
shadow: shadowOps.lerp(from.shadow, to.shadow, t),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/** The `theme` entry's resolve: merges a partial {@link BarChartTheme} onto `previous` (first resolution: the default). */
|
|
106
|
-
export function resolveBarChartTheme(theme, previous) {
|
|
107
|
-
const base = previous ?? DEFAULT_BAR_CHART_THEME;
|
|
108
|
-
return {
|
|
109
|
-
seriesFills: resolveSeriesFills(theme?.seriesFills, base.seriesFills),
|
|
110
|
-
bar: resolveBarStyle(theme?.bar, base.bar),
|
|
111
|
-
xAxis: resolveAxisConfig(theme?.xAxis, base.xAxis),
|
|
112
|
-
yAxis: resolveAxisConfig(theme?.yAxis, base.yAxis),
|
|
113
|
-
plotArea: resolvePlotArea(theme?.plotArea, base.plotArea),
|
|
114
|
-
legend: resolveLegendConfig(theme?.legend, base.legend),
|
|
115
|
-
valueStyle: textOps.resolveStyle(theme?.valueStyle, base.valueStyle),
|
|
116
|
-
spotlight: {
|
|
117
|
-
dimOpacity: theme?.spotlight?.dimOpacity ?? base.spotlight.dimOpacity,
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
export function lerpBarChartTheme(from, to, t) {
|
|
122
|
-
return {
|
|
123
|
-
seriesFills: lerpSeriesFills(from.seriesFills, to.seriesFills, t),
|
|
124
|
-
bar: lerpBarStyle(from.bar, to.bar, t),
|
|
125
|
-
xAxis: lerpAxisConfig(from.xAxis, to.xAxis, t),
|
|
126
|
-
yAxis: lerpAxisConfig(from.yAxis, to.yAxis, t),
|
|
127
|
-
plotArea: lerpPlotArea(from.plotArea, to.plotArea, t),
|
|
128
|
-
legend: lerpLegendConfig(from.legend, to.legend, t),
|
|
129
|
-
valueStyle: textOps.lerpStyle(from.valueStyle, to.valueStyle, t),
|
|
130
|
-
spotlight: {
|
|
131
|
-
dimOpacity: lerpNumber(from.spotlight.dimOpacity, to.spotlight.dimOpacity, t),
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
/** Series `index`'s own `fill`, else the palette's entry. */
|
|
136
|
-
export function resolveBarFill(palette, series, index) {
|
|
137
|
-
if (series.fill != null)
|
|
138
|
-
return fillOps.resolve(series.fill);
|
|
139
|
-
if (palette.length === 0)
|
|
70
|
+
/** Black or white, whichever reads on `fill`: a figure printed inside a bar. */
|
|
71
|
+
export function inkOn(fill) {
|
|
72
|
+
const layers = fillOps.resolve(fill);
|
|
73
|
+
const top = layers[layers.length - 1];
|
|
74
|
+
if (top?.type !== "solid")
|
|
140
75
|
return "white";
|
|
141
|
-
|
|
76
|
+
const [r, g, b] = top.color;
|
|
77
|
+
const lift = (c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
78
|
+
const luminance = 0.2126 * lift(r) + 0.7152 * lift(g) + 0.0722 * lift(b);
|
|
79
|
+
return luminance > 0.4 ? "#0a0a0a" : "white";
|
|
142
80
|
}
|
|
81
|
+
/** A bar chart's own look: its corners, and how wide the bars are. */
|
|
82
|
+
export const BAR_MARKS = {
|
|
83
|
+
/**
|
|
84
|
+
* Each corner as for a bar standing up from the baseline: the top pair round
|
|
85
|
+
* its far end, the bottom pair its base. Inside a stack, a segment's far end
|
|
86
|
+
* stays square unless it ends the stack, and its base unless it starts it.
|
|
87
|
+
*/
|
|
88
|
+
barCornerRadius: Types.cornerRadius({ topLeft: 10, topRight: 10, bottomRight: 0, bottomLeft: 0 }),
|
|
89
|
+
barCornerStyle: Types.cornerStyle("rounded"),
|
|
90
|
+
/** How much of its category slot a bar group fills, the rest spacing the groups. */
|
|
91
|
+
barWidth: Types.number(0.7, { min: 0.05, max: 1, step: 0.05, unit: "%", scale: 100 }),
|
|
92
|
+
/** Space between the bars of one group, side by side. */
|
|
93
|
+
barGap: Types.number(6, { min: 0, max: 40, step: 1, unit: "px" }),
|
|
94
|
+
};
|
|
95
|
+
export const BAR_LABELS = {
|
|
96
|
+
/** Read as the chart is built: each bar's value past its end, inside it, or none. */
|
|
97
|
+
values: Types.oneOf(["none", "end", "inside"], { animatable: false }),
|
|
98
|
+
};
|
|
143
99
|
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/bar-chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAEtD,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,GAAG,EACH,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,kBAAkB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\n lerpNumber,\n shadowOps,\n strokeOps,\n textOps,\n type DataRecord,\n type Fill,\n type Shadow,\n type ShadowResolved,\n type Stroke,\n type StrokeResolved,\n type TextStyle,\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_FILLS,\n DEFAULT_X_AXIS,\n DEFAULT_Y_AXIS,\n SPOTLIGHT_DIM,\n lerpAxisConfig,\n lerpLegendConfig,\n lerpPlotArea,\n lerpSeriesFills,\n num,\n resolveAxisConfig,\n resolveLegendConfig,\n resolvePlotArea,\n resolveSeriesFills,\n text,\n type AxisConfig,\n type ChartSeries,\n type LegendConfig,\n type LegendTheme,\n type PlotAreaConfig,\n type Range,\n} from \"../kit/shared\"\n\n/** One bar per row, beside its siblings in the category slot or stacked on them: {@link ChartSeries} under the name for what it draws here. */\nexport type BarSeries = ChartSeries\n\n/**\n * One bar's span in data units. A span rather than a height because both modes\n * fit it, and a negative value just runs the other way with no special case.\n */\nexport interface BarSpan {\n /** Where the base sits: 0 when grouped, the running total below when stacked. */\n from: number\n to: number\n /** `to - from`, kept for the figure printed on the bar. */\n value: number\n}\n\n/**\n * One row's spans, in series order. Stacking is a running sum in listed order,\n * so series 0 sits on the baseline. A zero value still yields a degenerate span,\n * keeping the list index-aligned with the series.\n */\nexport function barSpans(\n row: DataRecord,\n series: BarSeries[],\n stacked: boolean\n): BarSpan[] {\n let running = 0\n return series.map((s) => {\n const value = num(row, s.field)\n if (!stacked) return { from: 0, to: value, value }\n const from = running\n running += value\n return { from, to: running, value }\n })\n}\n\n/**\n * The series ending a row's stack, which gets the rounded cap; `-1` when the row\n * is all zero. It is the last non-zero series, so a zero one does not take the\n * cap and leave the segment below square.\n */\nexport function stackCapIndex(row: DataRecord, series: BarSeries[]): number {\n let last = -1\n for (let i = 0; i < series.length; i++) {\n if (num(row, series[i].field) !== 0) last = i\n }\n return last\n}\n\nexport function barCategories(data: DataRecord[], field: string): string[] {\n return data.map((row) => text(row, field))\n}\n\n/**\n * The `[min, max]` of everything drawn, zero always included: a scale starting\n * at 40 draws a column three times its neighbour for a 10% difference. A cropped\n * axis takes an explicit range.\n */\nexport function barValueExtent(\n data: DataRecord[],\n series: BarSeries[],\n stacked: boolean\n): Range {\n let lo = 0\n let hi = 0\n for (const row of data) {\n for (const span of barSpans(row, series, stacked)) {\n lo = Math.min(lo, span.from, span.to)\n hi = Math.max(hi, span.from, span.to)\n }\n }\n return lo < hi ? [lo, hi] : [0, 1]\n}\n\n/** The explicit `range`, else the data's extent nudged to tidy bounds; `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */\nexport function resolveBarScale(\n data: DataRecord[],\n series: BarSeries[],\n stacked: boolean,\n range: Range | undefined,\n divisions: number\n): Range {\n if (range) return range\n const [lo, hi] = barValueExtent(data, series, stacked)\n const segments = Math.max(1, Math.round(divisions))\n const step = niceStep((hi - lo) / segments || 1)\n return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step]\n}\n\n/** How the columns are drawn and the slot divided. */\nexport interface BarStyleConfig {\n /** Radius in px of a column's far-end corners; an interior stacked segment stays square. */\n cornerRadius: number\n /** Fraction of the category slot the bars fill, `[0, 1]`; the rest separates groups. */\n slotFill: number\n /** Gap in px between grouped bars within a slot; ignored when stacked. */\n groupGap: number\n stroke: Stroke\n shadow: Shadow\n}\n\n/** A {@link BarChart}'s full, resolved visual theme. */\nexport interface BarChartConfig {\n /** Cycled by series index; a series' own `fill` replaces its entry outright. */\n seriesFills: Fill[]\n bar: BarStyleConfig\n /** The category axis. */\n xAxis: AxisConfig\n /** The value axis. */\n yAxis: AxisConfig\n plotArea: PlotAreaConfig\n legend: LegendConfig\n /** The figure printed on each column. */\n valueStyle: TextStyle\n /** How far everything outside a spotlit series or category fades. */\n spotlight: { dimOpacity: number }\n}\n\n/** The author's partial theme, deep-merged onto {@link DEFAULT_BAR_CHART_THEME}. */\nexport type BarChartTheme = {\n seriesFills?: Fill[]\n bar?: Partial<BarStyleConfig>\n xAxis?: Partial<AxisConfig>\n yAxis?: Partial<AxisConfig>\n plotArea?: Partial<PlotAreaConfig>\n legend?: LegendTheme\n valueStyle?: TextStyle\n spotlight?: Partial<BarChartConfig[\"spotlight\"]>\n}\n\nexport const DEFAULT_BAR_CHART_THEME: BarChartConfig = {\n seriesFills: DEFAULT_SERIES_FILLS,\n bar: {\n cornerRadius: 6,\n slotFill: 0.72,\n groupGap: 6,\n stroke: [],\n shadow: [],\n },\n // Captions rather than numeric markers: less weight than the line chart's ticks.\n xAxis: {\n ...DEFAULT_X_AXIS,\n labelStyle: { ...DEFAULT_X_AXIS.labelStyle, fontWeight: 600 },\n tickPadding: 16,\n },\n yAxis: DEFAULT_Y_AXIS,\n plotArea: DEFAULT_PLOT_AREA,\n legend: DEFAULT_LEGEND,\n valueStyle: {\n fontSize: 24,\n fontWeight: 700,\n textAlign: \"center\",\n fill: CHART_PALETTE.markerColor,\n },\n spotlight: { dimOpacity: SPOTLIGHT_DIM },\n}\n\nfunction resolveBarStyle(\n bar: Partial<BarStyleConfig> | undefined,\n previous: BarStyleConfig\n): BarStyleConfig {\n return {\n cornerRadius: bar?.cornerRadius ?? previous.cornerRadius,\n slotFill: bar?.slotFill ?? previous.slotFill,\n groupGap: bar?.groupGap ?? previous.groupGap,\n stroke: strokeOps.resolve(bar?.stroke ?? previous.stroke),\n shadow: shadowOps.resolve(bar?.shadow ?? previous.shadow),\n }\n}\n\nfunction lerpBarStyle(\n from: BarStyleConfig,\n to: BarStyleConfig,\n t: number\n): BarStyleConfig {\n return {\n cornerRadius: lerpNumber(from.cornerRadius, to.cornerRadius, t),\n slotFill: lerpNumber(from.slotFill, to.slotFill, t),\n groupGap: lerpNumber(from.groupGap, to.groupGap, t),\n stroke: strokeOps.lerp(\n from.stroke as StrokeResolved[],\n to.stroke as StrokeResolved[],\n t\n ),\n shadow: shadowOps.lerp(\n from.shadow as ShadowResolved[],\n to.shadow as ShadowResolved[],\n t\n ),\n }\n}\n\n/** The `theme` entry's resolve: merges a partial {@link BarChartTheme} onto `previous` (first resolution: the default). */\nexport function resolveBarChartTheme(\n theme: BarChartTheme | undefined,\n previous?: BarChartConfig\n): BarChartConfig {\n const base = previous ?? DEFAULT_BAR_CHART_THEME\n return {\n seriesFills: resolveSeriesFills(theme?.seriesFills, base.seriesFills),\n bar: resolveBarStyle(theme?.bar, base.bar),\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 valueStyle: textOps.resolveStyle(theme?.valueStyle, base.valueStyle),\n spotlight: {\n dimOpacity: theme?.spotlight?.dimOpacity ?? base.spotlight.dimOpacity,\n },\n }\n}\n\nexport function lerpBarChartTheme(\n from: BarChartConfig,\n to: BarChartConfig,\n t: number\n): BarChartConfig {\n return {\n seriesFills: lerpSeriesFills(from.seriesFills, to.seriesFills, t),\n bar: lerpBarStyle(from.bar, to.bar, 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 valueStyle: textOps.lerpStyle(from.valueStyle, to.valueStyle, t),\n spotlight: {\n dimOpacity: lerpNumber(\n from.spotlight.dimOpacity,\n to.spotlight.dimOpacity,\n t\n ),\n },\n }\n}\n\n/** Series `index`'s own `fill`, else the palette's entry. */\nexport function resolveBarFill(\n palette: Fill[],\n series: BarSeries,\n index: number\n): Fill {\n if (series.fill != null) return fillOps.resolve(series.fill)\n if (palette.length === 0) return \"white\"\n return palette[index % palette.length]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/bar-chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,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ACzD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;CAClE,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,qFAAqF;IACrF,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAU,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;CAC/E,CAAA","sourcesContent":["import {\n Types,\n fillOps,\n type DataRecord,\n type Fill,\n // Named so the emitted marks types reach these through the sdk, not core.\n type CornerRadiusResolved as _CornerRadiusResolved,\n type CornerStyleResolved as _CornerStyleResolved,\n type RectCornerRadius as _RectCornerRadius,\n type RectCornerStyle as _RectCornerStyle,\n} from \"@motionscript/sdk\"\n\nimport { niceRange, num, text, type ChartSeries, type Range } from \"../kit/shared\"\n\n/** One bar per row, beside its siblings in the category slot or stacked on them: {@link ChartSeries} under the name for what it draws here. */\nexport type BarSeries = ChartSeries\n\n/** How the series share a category: side by side, stacked, or stacked as shares of 100. */\nexport type BarStack = \"none\" | \"stacked\" | \"percent\"\n\n/** Which way the bars grow: up from a category row, or right from a category column. */\nexport type BarOrientation = \"vertical\" | \"horizontal\"\n\n/**\n * One bar's span in data units. A span rather than a height because every mode\n * fits it, and a negative value just runs the other way with no special case.\n */\nexport interface BarSpan {\n /** Where the base sits: 0 apart, the running total below (or above, for a negative) when stacked. */\n from: number\n to: number\n /** `to - from`. */\n value: number\n /** Whether it ends its stack on its side of zero, so its far end is rounded. */\n outer: boolean\n}\n\n/**\n * One row's spans, in series order. Stacking keeps a running sum on each side\n * of zero, so a negative value stacks downward from the baseline rather than\n * eating into the positives. In `percent` each value is its share of the row's\n * total magnitude. A zero value still yields a degenerate span, keeping the list\n * index-aligned with the series. `weights` scale each series' contribution.\n */\nexport function barSpans(row: DataRecord, series: readonly BarSeries[], stack: BarStack, weights: readonly number[] = []): BarSpan[] {\n const weight = (i: number) => Math.max(0, weights[i] ?? 1)\n if (stack !== \"stacked\" && stack !== \"percent\") {\n return series.map((s) => {\n const value = num(row, s.field)\n return { from: 0, to: value, value, outer: true }\n })\n }\n const values = series.map((s, i) => num(row, s.field) * weight(i))\n const total = values.reduce((sum, v) => sum + Math.abs(v), 0)\n const scaled = stack === \"percent\" ? values.map((v) => (total > 0 ? (v / total) * 100 : 0)) : values\n let lastUp = -1\n let lastDown = -1\n scaled.forEach((v, i) => {\n if (v > 0) lastUp = i\n else if (v < 0) lastDown = i\n })\n let up = 0\n let down = 0\n return scaled.map((value, i) => {\n if (value < 0) {\n const from = down\n down += value\n return { from, to: down, value, outer: i === lastDown }\n }\n const from = up\n up += value\n return { from, to: up, value, outer: i === lastUp }\n })\n}\n\nexport function barCategories(data: DataRecord[], field: string): string[] {\n return data.map((row) => text(row, field))\n}\n\n/**\n * The `[min, max]` of everything drawn, zero always included: a scale starting\n * at 40 draws a bar three times its neighbour for a 10% difference. A cropped\n * axis takes an explicit range.\n */\nexport function barValueExtent(data: DataRecord[], series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): Range {\n let lo = 0\n let hi = 0\n for (const row of data) {\n for (const span of barSpans(row, series, stack, weights)) {\n lo = Math.min(lo, span.from, span.to)\n hi = Math.max(hi, span.from, span.to)\n }\n }\n return lo < hi ? [lo, hi] : [0, 1]\n}\n\n/** The explicit `range`, else the data's extent nudged to tidy bounds (a percent stack reads to 100); `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */\nexport function resolveBarScale(\n data: DataRecord[],\n series: readonly BarSeries[],\n stack: BarStack,\n range: Range | undefined,\n divisions: number,\n weights?: readonly number[]\n): Range {\n if (range) return range\n const [lo, hi] = barValueExtent(data, series, stack, weights)\n if (stack === \"percent\") return [lo < 0 ? -100 : 0, hi > 0 ? 100 : 0]\n return niceRange([lo, hi], divisions)\n}\n\n/** Black or white, whichever reads on `fill`: a figure printed inside a bar. */\nexport function inkOn(fill: Fill): string {\n const layers = fillOps.resolve(fill)\n const top = layers[layers.length - 1]\n if (top?.type !== \"solid\") return \"white\"\n const [r, g, b] = top.color\n const lift = (c: number) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)\n const luminance = 0.2126 * lift(r) + 0.7152 * lift(g) + 0.0722 * lift(b)\n return luminance > 0.4 ? \"#0a0a0a\" : \"white\"\n}\n\n/** A bar chart's own look: its corners, and how wide the bars are. */\nexport const BAR_MARKS = {\n /**\n * Each corner as for a bar standing up from the baseline: the top pair round\n * its far end, the bottom pair its base. Inside a stack, a segment's far end\n * stays square unless it ends the stack, and its base unless it starts it.\n */\n barCornerRadius: Types.cornerRadius({ topLeft: 10, topRight: 10, bottomRight: 0, bottomLeft: 0 }),\n barCornerStyle: Types.cornerStyle(\"rounded\"),\n /** How much of its category slot a bar group fills, the rest spacing the groups. */\n barWidth: Types.number(0.7, { min: 0.05, max: 1, step: 0.05, unit: \"%\", scale: 100 }),\n /** Space between the bars of one group, side by side. */\n barGap: Types.number(6, { min: 0, max: 40, step: 1, unit: \"px\" }),\n}\n\nexport const BAR_LABELS = {\n /** Read as the chart is built: each bar's value past its end, inside it, or none. */\n values: Types.oneOf([\"none\", \"end\", \"inside\"] as const, { animatable: false }),\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{lerpNumber as X}from"@motionscript/sdk";import{niceStep as $}from"@motionscript/sdk/component";function St(e,t){return{label:e?.label??t?.label??"",range:e?.range??t?.range,ticks:e?.ticks??t?.ticks,format:e?.format??t?.format}}function Y(e,t,r){return{label:r<.5?e.label:t.label,range:Ce(e.range,t.range,r),ticks:Ie(e.ticks,t.ticks,r),format:r<.5?e.format:t.format}}function Ce(e,t,r){return!e||!t?r<.5?e:t:[X(e[0],t[0],r),X(e[1],t[1],r)]}function Ie(e,t,r){if(!e||!t)return r<.5?e:t;let n=Math.max(e.length,t.length),o=[];for(let i=0;i<n;i++)o.push(X(e[i]??t[i],t[i]??e[i],r));return o}function ie(e){return e.blend}function At(e,t,r){let n=t.range!==e.range,o=n&&t.range&&t.ticks&&t.ticks===e.ticks?{...t,ticks:j(t.range,Math.max(2,t.ticks.length)-1)}:t,i=ie(e)!==void 0,a=i||n||o.ticks!==e.ticks,l=i||e.range===void 0||e.ticks===void 0||o.range===void 0||o.ticks===void 0;return!a||!l?Y(e,o,r):r===0?e:r===1?o:{...Y(e,o,r),blend:{from:e,to:o,t:r}}}function oe(e,t){let r=ie(e);return r?Y(oe(r.from,t),oe(r.to,t),r.t):t(e)}var B={plotFill:"#15130e",borderColor:"#4a4036",gridColor:"#2c2820",markerColor:"#8a7f70",regionColor:"#d99a3a"},ae=.2;function Et(e,t){if(t===void 0)return 0;let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}function vt(e,t){if(t===void 0||t==="")return"";let r=e[t];return r==null?"":String(r)}function Mt(e,t=[]){if(e.length===0)return[];let r=new Set(t),n=new Set,o=[];for(let i of e)for(let a of Object.keys(i))!r.has(a)&&!n.has(a)&&(n.add(a),o.push(a));return o.filter(i=>{let a=!1;for(let l of e){let c=l[i];if(!(c===void 0||c==="")){if(typeof c!="number")return!1;a=!0}}return a})}var le={fontSize:24,fontWeight:700,textAlign:"center",fill:B.markerColor},se={fontSize:30,fontWeight:600,textAlign:"center",fill:B.markerColor},ce={weight:2,fill:B.gridColor},fe={labelStyle:le,titleStyle:se,lineStyle:ce,tickPadding:20,titlePadding:4},de={labelStyle:{...le,fontWeight:500,textAlign:"right"},titleStyle:se,lineStyle:ce,tickPadding:40,titlePadding:24},N={padding:0,textStyle:{fontSize:30,fontWeight:600,textAlign:"left",fill:B.markerColor},itemGap:44,markerStyle:{width:60,height:24,borderRadius:6,stroke:[],shadow:[]}};function ue(e,t){if(Number.isInteger(e))return String(e);let r=Math.max(1,t===void 0?1:Be(t));return e.toFixed(r).replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,"")}function Be(e){if(!(e>0)||!Number.isFinite(e))return 1;for(let t=0;t<=6;t++){let r=e*10**t;if(Math.abs(r-Math.round(r))<1e-6*Math.max(1,r))return t}return Math.min(6,Math.max(1,Math.ceil(-Math.log10(e))+1))}function Lt(e){let t=[...e].filter(Number.isFinite).sort((n,o)=>n-o),r;for(let n=1;n<t.length;n++){let o=t[n]-t[n-1];o>1e-12&&(r===void 0||o<r)&&(r=o)}return r}function _t(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${t.toFixed(1).replace(/\.0$/,"")}%`}function j([e,t],r){let n=Math.max(2,Math.round(r));return Array.from({length:n+1},(o,i)=>e+(t-e)/n*i)}function Rt([e,t],r){let n=Math.max(1,Math.round(r));if(t===e)return Ne(e,n);let o=$((t-e)/n);return[Math.floor(e/o)*o,Math.ceil(t/o)*o]}function Ne(e,t){if(e===0)return[0,1];let r=$(Math.abs(e)/t);return[e-r,e+r]}function zt([e,t],r){let n=t-e,o=Math.max(1,Math.round(r));if(!(n>0))return j([e,t],o);let i=f=>Math.abs(f-Math.round(f))<1e-6,a=$(n/o),l;for(let f of We(a)){let s=n/f;!i(s)||!i(e/f)||s<2||s>8||(l===void 0||Math.abs(s-o)<Math.abs(n/l-o))&&(l=f)}if(l===void 0)return j([e,t],o);let c=Math.round(e/l);return Array.from({length:Math.round(n/l)+1},(f,s)=>Number(((c+s)*l).toPrecision(12)))}function We(e){let t=10**Math.floor(Math.log10(e)),r=[];for(let o of[t/10,t,t*10])for(let i of[1,2,5])r.push(i*o);let n=r.findIndex(o=>Math.abs(o-e)<e*1e-9);return r.slice(Math.max(0,n-2),n+3)}import{Types as d,textOps as he}from"@motionscript/sdk";var Ot="chart",ge=["#4f8cff","#2fbf8f","#f5a524","#e5547a","#9b6cf0"],V="#f4f4f5",O="#a1a1aa",He={seriesFills:d.palette(ge)},Ue={background:d.fill([])},Xe={...Ue,gridBackground:d.fill([])},Ye={legendText:d.typography({fontSize:28,fontWeight:500,fill:V})},je={xLabelText:d.typography({fontSize:28,fontWeight:500,fill:O}),xTitleText:d.typography({fontSize:31,fontWeight:600,fill:O}),yLabelText:d.typography({fontSize:28,fontWeight:500,fill:O}),yTitleText:d.typography({fontSize:31,fontWeight:600,fill:O}),valueText:d.typography({fontSize:24,fontWeight:600,fill:V}),...Ye},$e={horizontalGrid:d.stroke({weight:2,fill:"white/15"}),verticalGrid:d.stroke([]),axisStroke:d.stroke([]),showXAxis:d.boolean(!0,{animatable:!1}),showYAxis:d.boolean(!0,{animatable:!1})},Dt={legend:d.oneOf(["bottom","top","right","none"],{animatable:!1}),swatch:d.oneOf(["square","circle","line"])},Pt={...He,...Xe,...je,labelText:d.typography(),centerText:d.typography(),spokeText:d.typography(),horizontalGrid:$e.horizontalGrid,gridStroke:d.stroke([]),spokeStroke:d.stroke([]),track:d.fill([])};function T(e,t){let r=n=>({fill:n});return{xLabelText:r(t),xTitleText:r(t),yLabelText:r(t),yTitleText:r(t),valueText:r(e),legendText:r(e),labelText:r(t),centerText:r(e),spokeText:r(t)}}function S(e){return{horizontalGrid:{weight:2,fill:e},gridStroke:{weight:2,fill:e},spokeStroke:{weight:2,fill:e},track:e}}var Ct={midnight:{seriesFills:[...ge],...T(V,O),...S("white/15"),track:"white/10",background:[],gridBackground:[]},paper:{seriesFills:["#2563eb","#059669","#d97706","#db2777","#7c3aed"],...T("#1c1917","#57534e"),...S("#1c1917/12"),background:"#fafaf9",gridBackground:[]},ember:{seriesFills:["#d9603b","#8194ad","#e0a93b","#5e9d6b","#9ec85a"],...T("#e9e1d4","#8a7f70"),...S("#2c2820"),background:"#15130e",gridBackground:[]},neon:{seriesFills:["#22d3ee","#a3e635","#f472b6","#facc15","#818cf8"],...T("#ffffff","#94a3b8"),...S("white/10"),background:[],gridBackground:[]},ocean:{seriesFills:["#0ea5e9","#14b8a6","#6366f1","#38bdf8","#2dd4bf"],...T("#e0f2fe","#7dd3fc"),...S("#7dd3fc/20"),background:"#082f49",gridBackground:[]},sunset:{seriesFills:["#f97316","#ef4444","#ec4899","#f59e0b","#a855f7"],...T("#fff7ed","#fdba74"),...S("#fdba74/20"),background:[],gridBackground:[]},pastel:{seriesFills:["#a5b4fc","#f9a8d4","#86efac","#fde68a","#7dd3fc"],...T("#f8fafc","#cbd5e1"),...S("white/12"),background:[],gridBackground:[]},mono:{seriesFills:["#fafafa","#a3a3a3","#737373","#d4d4d4","#525252"],...T("#fafafa","#a3a3a3"),...S("white/12"),background:[],gridBackground:[]}};function Ve(e,t,r){if(r!=null)return r;let n=e.seriesFills;return n.length>0?n[t%n.length]:"white"}function It(e,t,r){return Ve(e,r,t.fill)}function R(e,t=28){let r=e?.fontSize;return typeof r=="number"&&Number.isFinite(r)?r:t}function W(e,t="center",r){return he.styleProps({...he.mergeStyle(e,r),textAlign:t})}function Ke(e,t){return W(t==="x"?e.xLabelText:e.yLabelText,t==="x"?"center":"right")}function Bt(e,t="center"){return W(e.valueText,t)}function Nt(e,t){let r=Math.round(R(t==="x"?e.xLabelText:e.yLabelText)*.6);return{labelStyle:Ke(e,t),titleStyle:W(t==="x"?e.xTitleText:e.yTitleText),lineStyle:t==="x"?e.verticalGrid:e.horizontalGrid,tickPadding:t==="x"?{top:r}:{right:r},titlePadding:t==="x"?{top:Math.round(r/2)}:{right:r}}}function Wt(e){let t=R(e.legendText),r=Math.max(8,Math.round(t*.6)),n=e.swatch==="line"?{width:Math.round(r*2),height:Math.max(3,Math.round(r/4)),borderRadius:r}:e.swatch==="circle"?{width:r,height:r,borderRadius:r/2}:{width:r,height:r,borderRadius:Math.round(r/4)};return{padding:0,textStyle:W(e.legendText,"left"),itemGap:Math.round(t*1.4),markerStyle:{...n,stroke:[],shadow:[]}}}function Ht(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return t;let r=t,n=["palette","foreground","muted","fontFamily","fontSize","fontWeight","barRadius"],o=e==="cartesian"||e==="radar";if(!n.some(v=>v in r)&&!(o&&"background"in r&&!("gridBackground"in r)))return t;let{palette:i,foreground:a,muted:l,fontFamily:c,fontSize:f,fontWeight:s,barRadius:p,...g}=r,x={...g};typeof p=="number"&&x.barCornerRadius===void 0&&(x.barCornerRadius={topLeft:p,topRight:p,bottomRight:0,bottomLeft:0}),i!==void 0&&x.seriesFills===void 0&&(x.seriesFills=i),o&&"background"in r&&!("gridBackground"in r)&&(x.gridBackground=r.background,delete x.background);let L=typeof f=="number"?f:void 0,C=typeof s=="number"?s:void 0,h=(v,I=1,Pe=0)=>{let _={};return typeof c=="string"&&c!==""&&(_.fontFamily=c),L!==void 0&&(_.fontSize=Math.round(L*I)),C!==void 0&&(_.fontWeight=Math.min(900,C+Pe)),v!==void 0&&(_.fill=v),Object.keys(_).length>0?_:void 0},y={legendText:h(a)};e==="cartesian"?(y.xLabelText=h(l),y.yLabelText=h(l),y.xTitleText=h(l,1.1,100),y.yTitleText=h(l,1.1,100),y.valueText=h(a,.85,100)):e==="pie"?(y.labelText=h(l),y.valueText=h(a,1,200),y.centerText=h(a,1.8,300)):e==="radar"?y.spokeText=h(l):(y.labelText=h(l),y.centerText=h(a,1.8,300));for(let[v,I]of Object.entries(y))I&&x[v]===void 0&&(x[v]=I);return x}}import{Rect as A,RotatedBox as qe,Text as pe,textOps as Je}from"@motionscript/sdk";function jt(e){return Math.round(R(e.legendText)*.9)}function $t(e){return Math.ceil(R(e.yLabelText)*.7)}function Vt(e){return Math.ceil(R(e.xLabelText)*1.1)}function Kt(e){let r=[new A({flow:"horizontal",width:"fill",height:"fill",children:[...e.left?[e.left]:[],e.plot]})];e.bottom&&r.push(new A({flow:"horizontal",width:"fill",height:"hug",children:[...e.ghost?[e.ghost]:[],e.bottom]}));let n=new A({flow:"vertical",width:"fill",height:"fill",children:r}),o=e.legend&&e.legendAt!=="none"?e.legend:void 0,i=new A({flow:"horizontal",width:"fill",height:"fill",align:"center",gap:e.gap,children:[n,...o&&e.legendAt==="right"?[o]:[]]}),a=l=>new A({flow:"horizontal",width:"fill",height:"hug",align:"center",children:[l]});return new A({flow:"vertical",width:"fill",height:"fill",gap:e.gap,padding:e.padding,...e.background?{fill:e.background}:{},children:[...o&&e.legendAt==="top"?[a(o)]:[],i,...o&&e.legendAt==="bottom"?[a(o)]:[]]})}function qt(e){let t=[],r=n=>{for(let o of n)t.push(o),r(o.children)};return r(e),t}function Jt(e){let t=e?.layoutBounds;return{width:t?.width??0,height:t?.height??0}}function b(e){let t=Object.keys(Je.styleProps(e())),r={};for(let n of t)r[n]=()=>e()[n];return r}function Qt(e){let t=Array.from({length:e.count},(n,o)=>new pe({...b(e.text),text:()=>e.captions()[o]??""})),r=[];return e.title!==""&&r.push(new qe({angle:-90,width:"hug",height:"hug",children:new pe({...b(e.titleText),text:e.title})})),r.push(new A({flow:"vertical",width:"hug",height:"hug",padding:()=>({right:e.tickPad()}),children:t})),new A({opacity:0,flow:"horizontal",gap:e.titlePad,width:"hug",height:0,children:r})}function Zt(e,t){return(Array.isArray(e)?e:[e]).map(n=>typeof n=="object"&&n!==null?{...n,opacity:(n.opacity??1)*t}:n)}import{Graphics2D as Se,Types as H,component2d as Qe,fillOps as be,strokeOps as ke}from"@motionscript/sdk";import{Types as xe}from"@motionscript/sdk";function u(e,t){return xe.custom(e,t)}function me(e){return e}var rr=xe.custom(0,{kind:"series",min:0,step:1});function ye(e,t){for(let r of t.fills??[])e.fill(r);for(let r of t.strokes??[])for(let n of r)e.fill(n.fill);for(let r of t.shadows??[])for(let n of r)e.fill(n.fill)}var K=()=>H.custom([],{resolve:ke.resolve,lerp:ke.lerp});function we(e,[t,r],n){return(r<=t?0:(e-t)/(r-t)-.5)*n}function Te(e,t,r,n,o=1){e.draw(new Se().line({points:[t,r]}).stroke(n).opacity(o))}var sr=Qe({key:"chartCanvas",state:{fill:H.custom([],{resolve:be.resolve,lerp:be.lerp}),xGridStroke:K(),yGridStroke:K(),xMarkers:u(()=>[]),yMarkers:u(()=>[]),xExtent:u(()=>[0,1]),yExtent:u(()=>[0,1]),axisStroke:K(),xAxisAt:H.custom(null),yAxisAt:H.custom(null)},load:(e,t)=>ye(e,{fills:[t.fill],strokes:[t.xGridStroke,t.yGridStroke,t.axisStroke]}),render:(e,t)=>{let{width:r,height:n}=e.size;if(r<=0||n<=0)return;t.fill.length>0&&e.draw(new Se().rect({x:0,y:0,width:r,height:n}).fill(t.fill));let o=(c,f,s)=>Math.max(-f/2+s/2,Math.min(f/2-s/2,c)),i=(c,f)=>{let s=f[0]?.weight??0;if(!(s<=0))for(let p of c){let g=o(we(p,t.xExtent,r),r,s);Te(e,{x:g,y:-n/2},{x:g,y:n/2},f)}},a=(c,f)=>{let s=f[0]?.weight??0;if(!(s<=0))for(let p of c){let g=o(we(p,t.yExtent,n),n,s);Te(e,{x:-r/2,y:g},{x:r/2,y:g},f)}},l=([c,f])=>s=>s>=Math.min(c,f)-1e-9&&s<=Math.max(c,f)+1e-9;i(t.xMarkers.filter(l(t.xExtent)),t.xGridStroke),a(t.yMarkers.filter(l(t.yExtent)),t.yGridStroke),t.xAxisAt!==null&&a([t.xAxisAt],t.axisStroke),t.yAxisAt!==null&&i([t.yAxisAt],t.axisStroke)}});import{Rect as Me,Text as Le,Types as U,component2d as lt}from"@motionscript/sdk";import{enterBudget as st}from"@motionscript/sdk/component";import{Types as Ze,easeOut as et}from"@motionscript/sdk";var tt=e=>e,q=20;function dr(e){return e==="top"?{y:q}:e==="right"?{x:q}:{y:-q}}var ur=5,hr={axes:.35,marks:.5,legend:.15};function k(e){return e.easing?tt:et()}function z(e,t){let r=e.duration,n=t.reduce((i,a)=>Math.max(i,a.at+a.duration),0),o=n>r&&n>0?r/n:1;return e.together(t.map(({at:i,duration:a,piece:l})=>{let c=i*o,f=a*o;return e.sequence([e.wait(c),l,e.wait(Math.max(0,r-c-f))])}))}var J={opacity:1,shift:0};function F(){return Ze.custom({},{private:!0,resolve:(e,t)=>({...t,...e})})}function m(e,t){return e[t]??J}function M(e,t){let r={};for(let n of e)r[n]=t;return r}function E(e,t,r,n){return e.animate(o=>{let i=n(o);return{arrivals:{[t]:{opacity:r.opacity+(J.opacity-r.opacity)*i,shift:r.shift+(J.shift-r.shift)*i}}}})}import{Rect as Ae,RotatedBox as rt,Text as Ee,Types as Q,component2d as nt,insetsOps as ve}from"@motionscript/sdk";import{enterBudget as ot}from"@motionscript/sdk/component";var it=24;function Z(e,t){let r=e.markers.indexOf(t);return(r>=0?e.captions[r]:void 0)??ue(t)}function ee(e,t){return{tick:ve.resolve(e.tickPadding)[t],title:ve.resolve(e.titlePadding)[t]}}function at(e){let t=()=>ee(e.axis(),"right"),r=Array.from({length:e.count},(o,i)=>{let a=()=>l.parent?.layoutBounds??{width:0,height:0},l=new Ee({...b(()=>e.axis().labelStyle),text:()=>e.text(i),x:()=>(a().width-t().tick)/2-l.layoutBounds.width/2+m(e.arrivals(),i).shift,y:()=>e.place(i,a().height),opacity:()=>m(e.arrivals(),i).opacity*(e.opacity?.(i)??1)});return l}),n=[];return e.label!==""&&n.push(new rt({angle:-90,width:"hug",height:"hug",children:new Ee({...b(()=>e.axis().titleStyle),text:e.label,opacity:()=>m(e.arrivals(),"label").opacity,x:()=>m(e.arrivals(),"label").shift})})),n.push(new Ae({height:"fill",width:"hug",padding:()=>({right:t().tick}),children:r})),new Ae({flow:"horizontal",gap:()=>t().title,height:"fill",children:n})}var wr=nt({key:"verticalAxis",state:{range:u(()=>[0,1]),markers:u(()=>[]),captions:u(()=>[]),axis:Q.custom(de),label:"",arrivals:F()},defaults:{width:"fill",height:"fill"},children:e=>{let t=()=>[...e.markers].sort((n,o)=>o-n),r=n=>{if(n===void 0)return 0;let[o,i]=e.range;return i<=o?0:(n-o)/(i-o)};return[at({count:e.markers.length,axis:()=>e.axis,text:n=>{let o=t()[n];return o===void 0?"":Z(e,o)},place:(n,o)=>(r(t()[n])-.5)*o,arrivals:()=>e.arrivals,label:e.label})]},commands:{enter:{args:{stagger:Q.custom(void 0),slide:Q.number(it)},run:(e,t)=>{let{stagger:r,slide:n}=e.args,o=t.markers.length,i=t.label!=="",a={opacity:0,shift:n},l=[...t.markers.keys(),...i?["label"]:[]],c=e.animate(()=>({arrivals:M(l,a)}));if(o===0)return c;let{step:f,per:s,caption:p}=ot(e.duration,o,i,r),g=k(e),x=t.markers.map((C,h)=>({at:(o-1-h)*f,duration:s,piece:E(e,h,a,g)})),L=i?[{at:(o-1)*f+s,duration:p,piece:E(e,"label",a,g)}]:[];return e.together([c,z(e,[...x,...L])])}}}});var ct=24,Rr=lt({key:"horizontalAxis",state:{range:u(()=>[0,1]),markers:u(()=>[]),captions:u(()=>[]),axis:U.custom(fe),label:"",overhang:U.custom({left:0,right:0}),arrivals:F()},defaults:{width:"fill",height:"fill"},children:e=>{let t=()=>ee(e.axis,"top"),r=()=>[...e.markers].sort((a,l)=>a-l),n=a=>{if(a===void 0)return 0;let[l,c]=e.range;return c<=l?0:(a-l)/(c-l)},o=e.markers.map((a,l)=>{let c=()=>f.parent?.layoutBounds.width??0,f=new Le({...b(()=>e.axis.labelStyle),text:()=>{let s=r()[l];return s===void 0?"":Z(e,s)},x:()=>{let s=c(),p=f.layoutBounds.width/2,g=(n(r()[l])-.5)*s;return Math.max(-s/2-e.overhang.left+p,Math.min(s/2+e.overhang.right-p,g))},opacity:()=>m(e.arrivals,l).opacity,y:()=>m(e.arrivals,l).shift});return f}),i=[new Me({width:"fill",height:"hug",padding:()=>({top:t().tick}),children:o})];return e.label!==""&&i.push(new Le({...b(()=>e.axis.titleStyle),text:e.label,opacity:()=>m(e.arrivals,"label").opacity,y:()=>m(e.arrivals,"label").shift})),[new Me({flow:"vertical",gap:()=>t().title,height:"hug",width:"fill",children:i})]},commands:{enter:{args:{stagger:U.custom(void 0),slide:U.number(ct)},run:(e,t)=>{let{stagger:r,slide:n}=e.args,o=t.markers.length,i=t.label!=="",a={opacity:0,shift:n},l=[...t.markers.keys(),...i?["label"]:[]],c=e.animate(()=>({arrivals:M(l,a)}));if(o===0)return c;let{step:f,per:s,caption:p}=st(e.duration,o,i,r),g=k(e),x=t.markers.map((C,h)=>({at:h*f,duration:s,piece:E(e,h,a,g)})),L=i?[{at:(o-1)*f+s,duration:p,piece:E(e,"label",a,g)}]:[];return e.together([c,z(e,[...x,...L])])}}}});import{Flow as D,Paint as w,Rect as ft,Shapes as te,Text as dt,Types as G,component2d as Re}from"@motionscript/sdk";var ze={...w.state,...D.state,...te.corners},ut=Re({key:"legendEntry",state:{...ze,shown:G.number(1),along:G.oneOf(["horizontal","vertical"])},commands:{...w.commands},measure:(e,t,r)=>{let n=D.measure(e,t,r,w.inset(t));return t.shown>=1?n:t.along==="vertical"?{...n,height:t.shown*n.height}:{...n,width:t.shown*n.width}},layout:(e,t,r)=>D.layout(e,t,r,w.inset(t)),render:(e,t)=>w.draw(e,t,te.rect(e.size,t))});function ht(e,t){if(Array.isArray(e))return e;let r=[...t??[]];for(let[n,o]of Object.entries(e))r[Number(n)]=o;return r}var Cr=Re({key:"chartLegend",state:{...ze,series:u(()=>[]),swatches:u(()=>[]),legend:G.custom(N),reveal:u(()=>[],{resolve:ht})},defaults:{flow:"horizontal",width:"hug",height:"hug",gap:e=>e.flow==="vertical"?Math.round(e.legend.itemGap*.4):e.legend.itemGap,padding:e=>e.legend.padding,align:e=>e.flow==="vertical"?"centerLeft":"center",reveal:e=>e.series.map(t=>t.enabled??!0?1:0)},children:e=>{let t=()=>e.legend.markerStyle,r=e.flow==="vertical"?"vertical":"horizontal";return e.series.map((n,o)=>ut({flow:"horizontal",gap:()=>Math.round((e.legend.textStyle.fontSize??24)*.45),align:"center",width:"hug",height:"hug",along:r,opacity:()=>e.reveal[o]??0,gapScale:()=>e.reveal[o]??0,shown:()=>e.reveal[o]??0,children:[ft({width:()=>t().width,height:()=>t().height,cornerRadius:()=>t().borderRadius,fill:()=>e.swatches[o]??"white",stroke:()=>t().stroke,shadow:()=>t().shadow}),dt({...b(()=>e.legend.textStyle),text:n.label||n.field})]}))},commands:{...w.commands,showSeries:{args:{index:G.number(0,{min:0,step:1})},run:(e,t)=>e.args.index in t.series?e.animate(_e(t,e.args.index,1,k(e))):e.wait(e.duration)},hideSeries:{args:{index:G.number(0,{min:0,step:1})},run:(e,t)=>e.args.index in t.series?e.animate(_e(t,e.args.index,0,k(e))):e.wait(e.duration)},spotlightSeries:{args:{index:G.number(0,{min:0,step:1})},run:(e,t,r)=>e.together(r.flatMap((n,o)=>(t.reveal[o]??0)>0?[n.to({opacity:o===e.args.index?1:ae})]:[]))}},measure:(e,t,r)=>D.measure(e,t,r,w.inset(t)),layout:(e,t,r)=>D.layout(e,t,r,w.inset(t)),render:(e,t)=>w.draw(e,t,te.rect(e.size,t))});function _e(e,t,r,n){let o=e.reveal[t]??0;return i=>({reveal:{[t]:o+(r-o)*n(i)}})}import{Flow as re,Paint as P,Rect as ne,Shapes as Fe,Text as gt,Types as pt,clamp as xt,component2d as mt,textOps as yt}from"@motionscript/sdk";var Ge=16,Ur=mt({key:"pieLegend",state:{...P.state,...re.state,...Fe.corners,slices:u(()=>[]),legend:pt.custom(N),dims:u(()=>[]),arrivals:F()},defaults:{flow:"vertical",align:"centerLeft",width:"hug",height:"hug",gap:e=>e.legend.itemGap/3,padding:e=>e.legend.padding},children:e=>{let t=()=>e.legend.markerStyle;return e.slices.map((r,n)=>ne({width:"hug",height:"hug",flow:"freeform",opacity:()=>xt(e.dims[n]??1,0,1),children:[ne({flow:"horizontal",gap:()=>Math.round(e.legend.textStyle.fontSize===void 0?12:Number(e.legend.textStyle.fontSize)*.4),align:"center",width:"hug",height:"hug",opacity:()=>m(e.arrivals,n).opacity,x:()=>m(e.arrivals,n).shift,children:[ne({width:()=>t().width,height:()=>t().height,cornerRadius:()=>t().borderRadius,fill:()=>e.slices[n]?.fill??"white"}),gt({...yt.styleProps(e.legend.textStyle),fill:()=>e.legend.textStyle.fill??"white",fontSize:()=>e.legend.textStyle.fontSize??28,fontWeight:()=>e.legend.textStyle.fontWeight??500,text:()=>e.slices[n]?.category??""})]})]}))},commands:{...P.commands,arm:(e,t)=>e.animate(()=>({arrivals:M([...t.slices.keys()],{opacity:0,shift:Ge})})),enter:(e,t)=>{let r=t.slices.length;if(r===0)return e.wait(e.duration);let n={opacity:0,shift:Ge},o=e.animate(()=>({arrivals:M([...t.slices.keys()],n)})),i=e.duration/(1+Math.max(0,r-1)/5),a=i/5,l=k(e),c=t.slices.map((f,s)=>({at:s*a,duration:i,piece:E(e,s,n,l)}));return e.together([o,z(e,c)])}},measure:(e,t,r)=>re.measure(e,t,r,P.inset(t)),layout:(e,t,r)=>re.layout(e,t,r,P.inset(t)),render:(e,t)=>P.draw(e,t,Fe.rect(e.size,t))});import{clamp as bt,fillOps as Oe}from"@motionscript/sdk";var jr=Math.PI/180;function $r(e,t,r){return e<=0?1:1-(1-bt(t,0,1))*e*(1-r)}function Vr(e,t){return{x:e*Math.sin(t),y:e*Math.cos(t)}}var Kr=.15,De=new WeakMap;function kt(e){if(typeof e!="object"||e===null)return Oe.resolve(e);let t=De.get(e);return t===void 0&&De.set(e,t=Oe.resolve(e)),t}function qr(e){return e.map(t=>kt(t.fill))}export*from"@motionscript/sdk/component";export{Ot as a,ge as b,V as c,O as d,He as e,Ue as f,Xe as g,Ye as h,je as i,$e as j,Dt as k,Ct as l,Ve as m,It as n,R as o,W as p,Ke as q,Bt as r,Nt as s,Wt as t,Ht as u,jt as v,$t as w,Vt as x,Kt as y,qt as z,Jt as A,b as B,Qt as C,Zt as D,u as E,me as F,rr as G,ye as H,Te as I,sr as J,q as K,dr as L,ur as M,hr as N,k as O,z as P,F as Q,m as R,M as S,E as T,St as U,Y as V,At as W,oe as X,ae as Y,Et as Z,vt as _,Mt as $,fe as aa,de as ba,N as ca,ue as da,Lt as ea,_t as fa,j as ga,Rt as ha,zt as ia,Cr as ja,Z as ka,ee as la,at as ma,wr as na,Rr as oa,Ur as pa,jr as qa,$r as ra,Vr as sa,Kr as ta,kt as ua,qr as va};
|
|
2
|
+
//# sourceMappingURL=chunk-7XCRX6GE.js.map
|