@motionscript/charts 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +40 -0
- package/README.md +30 -16
- package/dist/bar-chart/bar-chart.d.ts +133 -242
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +378 -569
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +35 -41
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +93 -115
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +50 -70
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +156 -210
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -2
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +3 -3
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +3 -3
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-XROBIRQK.js +2 -0
- package/dist/browser/chunks/chunk-XROBIRQK.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 +8 -6
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +8 -6
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +44 -0
- package/dist/kit/cartesian.d.ts.map +1 -0
- package/dist/kit/cartesian.js +59 -0
- package/dist/kit/cartesian.js.map +1 -0
- package/dist/kit/chart-border.d.ts +10 -11
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +15 -32
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -21
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +33 -90
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +123 -64
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +129 -154
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +17 -0
- package/dist/kit/entries.d.ts.map +1 -0
- package/dist/kit/entries.js +19 -0
- package/dist/kit/entries.js.map +1 -0
- package/dist/kit/motion.d.ts +48 -0
- package/dist/kit/motion.d.ts.map +1 -0
- package/dist/kit/motion.js +63 -0
- package/dist/kit/motion.js.map +1 -0
- package/dist/kit/paints.d.ts +10 -0
- package/dist/kit/paints.d.ts.map +1 -0
- package/dist/kit/paints.js +12 -0
- package/dist/kit/paints.js.map +1 -0
- package/dist/kit/shared.d.ts +31 -3
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +42 -3
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +48 -61
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +97 -132
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +60 -77
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +100 -121
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +32 -33
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +31 -65
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +58 -64
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +94 -123
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -2
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +1 -1
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +156 -319
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +403 -663
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +3 -3
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +3 -3
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -2
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +108 -132
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +200 -271
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +84 -31
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +93 -107
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +160 -131
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +333 -391
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +2 -2
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +2 -2
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +415 -701
- package/src/bar-chart/category-axis.ts +95 -110
- package/src/bar-chart/chart-bars.ts +178 -200
- package/src/bar-chart/index.ts +2 -2
- package/src/bar-chart/shared.ts +3 -3
- package/src/engine.ts +8 -6
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +22 -33
- package/src/kit/chart-canvas.ts +44 -79
- package/src/kit/chart-legend.ts +173 -189
- package/src/kit/entries.ts +20 -0
- package/src/kit/motion.ts +90 -0
- package/src/kit/paints.ts +15 -0
- package/src/kit/shared.ts +52 -3
- package/src/kit/vertical-axis.ts +110 -140
- package/src/line-chart/chart-line.ts +102 -154
- package/src/line-chart/chart-region.ts +35 -80
- package/src/line-chart/horizontal-axis.ts +101 -152
- package/src/line-chart/index.ts +2 -2
- package/src/line-chart/line-chart.ts +449 -825
- package/src/line-chart/shared.ts +3 -3
- package/src/nodes.ts +8 -10
- package/src/pie-chart/index.ts +2 -2
- package/src/pie-chart/pie-chart.ts +221 -311
- package/src/pie-chart/pie-legend.ts +124 -114
- package/src/pie-chart/pie-ring.ts +386 -473
- package/src/pie-chart/shared.ts +2 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js +0 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type NodeOf, type RectProps, type Alignment as _Alignment, type CornerRadiusResolved as _CornerRadiusResolved, type CornerStyleResolved as _CornerStyleResolved, type Fill as _Fill, type FillResolved as _FillResolved, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type RectCornerRadius as _RectCornerRadius, type RectCornerStyle as _RectCornerStyle, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved, type Vector2 as _Vector2 } from "@motionscript/sdk";
|
|
2
|
+
import { type Arrival } from "../kit/motion.js";
|
|
2
3
|
import { type LegendConfig } from "../kit/shared.js";
|
|
3
|
-
import { type Seekable } from "@motionscript/sdk/component";
|
|
4
4
|
import type { PieSlice } from "./shared.js";
|
|
5
5
|
export interface PieLegendProps extends RectProps {
|
|
6
6
|
/** One entry per slice, in ring order. */
|
|
@@ -27,34 +27,87 @@ export interface PieLegendProps extends RectProps {
|
|
|
27
27
|
* shouldn't be in the chart shouldn't be in the table — removing one would
|
|
28
28
|
* silently re-cut every other wedge's share, which is a different chart rather
|
|
29
29
|
* than the same chart with something hidden. Selection is what a pie has
|
|
30
|
-
* instead, and it arrives through {@link dims}.
|
|
30
|
+
* instead, and it arrives through {@link PieLegendProps.dims}.
|
|
31
31
|
*/
|
|
32
|
-
export declare
|
|
33
|
-
slices: PieSlice[]
|
|
34
|
-
legend: LegendConfig
|
|
35
|
-
dims: number[]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
export declare const PieLegend: import("@motionscript/sdk").Component<"pieLegend", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
33
|
+
readonly slices: import("@motionscript/sdk").Type<PieSlice[], PieSlice[], false>;
|
|
34
|
+
readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
|
|
35
|
+
readonly dims: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
36
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
37
|
+
readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
|
|
38
|
+
readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
|
|
39
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
40
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
41
|
+
readonly wrap: boolean;
|
|
42
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
43
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
44
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
45
|
+
readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
46
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
47
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
48
|
+
readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
49
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
51
|
+
}>, {
|
|
52
|
+
readonly arm: unknown;
|
|
53
|
+
readonly enter: unknown;
|
|
54
|
+
readonly fillTo: readonly ["fill"];
|
|
55
|
+
readonly strokeTo: readonly ["stroke"];
|
|
56
|
+
readonly shadowTo: readonly ["shadow"];
|
|
57
|
+
readonly overlayTo: readonly ["overlay"];
|
|
58
|
+
readonly progressTo: readonly ["start", "end"];
|
|
59
|
+
readonly flash: {
|
|
60
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
61
|
+
};
|
|
62
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
63
|
+
readonly slices: import("@motionscript/sdk").Type<PieSlice[], PieSlice[], false>;
|
|
64
|
+
readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
|
|
65
|
+
readonly dims: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
66
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
67
|
+
readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
|
|
68
|
+
readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
|
|
69
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
70
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
71
|
+
readonly wrap: boolean;
|
|
72
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
73
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
74
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
75
|
+
readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
76
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
77
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
78
|
+
readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
79
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
80
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
81
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
82
|
+
readonly slices: import("@motionscript/sdk").Type<PieSlice[], PieSlice[], false>;
|
|
83
|
+
readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
|
|
84
|
+
readonly dims: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
85
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
86
|
+
readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
|
|
87
|
+
readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
|
|
88
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
89
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
90
|
+
readonly wrap: boolean;
|
|
91
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
92
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
93
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
94
|
+
readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
95
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
96
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
97
|
+
readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
98
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
99
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
100
|
+
}>, {
|
|
101
|
+
readonly arm: unknown;
|
|
102
|
+
readonly enter: unknown;
|
|
103
|
+
readonly fillTo: readonly ["fill"];
|
|
104
|
+
readonly strokeTo: readonly ["stroke"];
|
|
105
|
+
readonly shadowTo: readonly ["shadow"];
|
|
106
|
+
readonly overlayTo: readonly ["overlay"];
|
|
107
|
+
readonly progressTo: readonly ["start", "end"];
|
|
108
|
+
readonly flash: {
|
|
109
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
110
|
+
};
|
|
111
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
112
|
+
export type PieLegend = NodeOf<typeof PieLegend>;
|
|
60
113
|
//# sourceMappingURL=pie-legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie-legend.d.ts","sourceRoot":"","sources":["../../src/pie-chart/pie-legend.ts"],"names":[],"mappings":"AA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MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { command, Rect, Text, easeOut, property, textOps, } from "@motionscript/sdk";
|
|
1
|
+
import { Flow, Paint, Rect, Shapes, Text, Types, component2d, textOps, } from "@motionscript/sdk";
|
|
2
|
+
import { fresh } from "../kit/entries.js";
|
|
3
|
+
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "../kit/motion.js";
|
|
8
4
|
import { DEFAULT_LEGEND, clampUnit, } from "../kit/shared.js";
|
|
9
|
-
import { at, compose, hold } from "@motionscript/sdk/component";
|
|
10
5
|
/** How far an entry starts to the right of its slot when it enters, in px. */
|
|
11
6
|
const SLIDE = 16;
|
|
12
7
|
/**
|
|
@@ -23,109 +18,100 @@ const SLIDE = 16;
|
|
|
23
18
|
* shouldn't be in the chart shouldn't be in the table — removing one would
|
|
24
19
|
* silently re-cut every other wedge's share, which is a different chart rather
|
|
25
20
|
* than the same chart with something hidden. Selection is what a pie has
|
|
26
|
-
* instead, and it arrives through {@link dims}.
|
|
21
|
+
* instead, and it arrives through {@link PieLegendProps.dims}.
|
|
27
22
|
*/
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
opacity: () => clampUnit(this.dims[i] ?? 1),
|
|
57
|
-
children: [item],
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/** One entry: the slice's colour swatch beside its caption. */
|
|
62
|
-
buildItem(index) {
|
|
63
|
-
const marker = this.legend.markerStyle;
|
|
64
|
-
return new Rect({ flow: "horizontal",
|
|
65
|
-
gap: 12,
|
|
66
|
-
align: "center",
|
|
23
|
+
export const PieLegend = component2d({
|
|
24
|
+
key: "pieLegend",
|
|
25
|
+
state: {
|
|
26
|
+
...Paint.state,
|
|
27
|
+
...Flow.state,
|
|
28
|
+
...Shapes.corners,
|
|
29
|
+
slices: fresh(() => []),
|
|
30
|
+
legend: Types.custom(DEFAULT_LEGEND),
|
|
31
|
+
dims: fresh(() => []),
|
|
32
|
+
arrivals: arrivalsEntry(),
|
|
33
|
+
},
|
|
34
|
+
// A column, for the reason `ChartLegend` gives for its row: a `Rect` given no
|
|
35
|
+
// flow lays its children out `freeform`, every caption on top of the last.
|
|
36
|
+
defaults: {
|
|
37
|
+
flow: "vertical",
|
|
38
|
+
align: "centerLeft",
|
|
39
|
+
width: "hug",
|
|
40
|
+
height: "hug",
|
|
41
|
+
gap: (state) => state.legend.itemGap / 3,
|
|
42
|
+
padding: (state) => state.legend.padding,
|
|
43
|
+
},
|
|
44
|
+
// One entry per slice, ordered top → bottom. The selection dim rides a wrapper
|
|
45
|
+
// rather than the entry itself, so the entrance can animate the entry's own
|
|
46
|
+
// opacity without the two fighting over one value — opacity multiplies down
|
|
47
|
+
// the tree, which is exactly the composition wanted here.
|
|
48
|
+
children: (state) => {
|
|
49
|
+
const marker = state.legend.markerStyle;
|
|
50
|
+
return state.slices.map((_, index) => Rect({
|
|
67
51
|
width: "hug",
|
|
68
52
|
height: "hug",
|
|
53
|
+
flow: "freeform",
|
|
54
|
+
opacity: () => clampUnit(state.dims[index] ?? 1),
|
|
69
55
|
children: [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
56
|
+
Rect({
|
|
57
|
+
flow: "horizontal",
|
|
58
|
+
gap: 12,
|
|
59
|
+
align: "center",
|
|
60
|
+
width: "hug",
|
|
61
|
+
height: "hug",
|
|
62
|
+
opacity: () => arrivalOf(state.arrivals, index).opacity,
|
|
63
|
+
x: () => arrivalOf(state.arrivals, index).shift,
|
|
64
|
+
children: [
|
|
65
|
+
Rect({
|
|
66
|
+
width: marker.height,
|
|
67
|
+
height: marker.height,
|
|
68
|
+
cornerRadius: marker.borderRadius,
|
|
69
|
+
fill: () => state.slices[index]?.fill ?? "white",
|
|
70
|
+
stroke: marker.stroke,
|
|
71
|
+
shadow: marker.shadow,
|
|
72
|
+
}),
|
|
73
|
+
Text({
|
|
74
|
+
...textOps.styleProps(state.legend.textStyle),
|
|
75
|
+
text: () => state.slices[index]?.category ?? "",
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
81
78
|
}),
|
|
82
79
|
],
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
property({ default: () => [] })
|
|
121
|
-
], PieLegend.prototype, "slices", void 0);
|
|
122
|
-
__decorate([
|
|
123
|
-
property({ default: DEFAULT_LEGEND })
|
|
124
|
-
], PieLegend.prototype, "legend", void 0);
|
|
125
|
-
__decorate([
|
|
126
|
-
property({ default: () => [] })
|
|
127
|
-
], PieLegend.prototype, "dims", void 0);
|
|
128
|
-
__decorate([
|
|
129
|
-
command()
|
|
130
|
-
], PieLegend.prototype, "enter", null);
|
|
80
|
+
}));
|
|
81
|
+
},
|
|
82
|
+
commands: {
|
|
83
|
+
...Paint.commands,
|
|
84
|
+
/**
|
|
85
|
+
* Every entry at its pre-entrance state, shifted right and transparent: what
|
|
86
|
+
* a chart shows ahead of this legend's own beat in its entrance, since
|
|
87
|
+
* `enter` arms the entries only on its first frame.
|
|
88
|
+
*/
|
|
89
|
+
arm: (timeline, state) => timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], { opacity: 0, shift: SLIDE }) })),
|
|
90
|
+
/**
|
|
91
|
+
* Slide + fade every entry in from the right, staggered top-to-bottom. Its
|
|
92
|
+
* first frame arms them all: shifted right and transparent.
|
|
93
|
+
*
|
|
94
|
+
* The timeline's duration is the **whole** entrance: the stagger is carved
|
|
95
|
+
* out of it rather than added on top, so the command takes exactly the time
|
|
96
|
+
* the timeline laid out for it.
|
|
97
|
+
*/
|
|
98
|
+
enter: (timeline, state) => {
|
|
99
|
+
const count = state.slices.length;
|
|
100
|
+
if (count === 0)
|
|
101
|
+
return timeline.wait(timeline.duration);
|
|
102
|
+
const from = { opacity: 0, shift: SLIDE };
|
|
103
|
+
const arm = timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], from) }));
|
|
104
|
+
// Each gap is a fifth of an entry's own move, the rhythm the axes use;
|
|
105
|
+
// solved for from the budget rather than added to it.
|
|
106
|
+
const per = timeline.duration / (1 + Math.max(0, count - 1) / 5);
|
|
107
|
+
const step = per / 5;
|
|
108
|
+
const ease = frameEase(timeline);
|
|
109
|
+
const entries = state.slices.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));
|
|
110
|
+
return timeline.together([arm, beats(timeline, entries)]);
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
|
|
114
|
+
layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
|
|
115
|
+
render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),
|
|
116
|
+
});
|
|
131
117
|
//# sourceMappingURL=pie-legend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie-legend.js","sourceRoot":"","sources":["../../src/pie-chart/pie-legend.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,OAAO,GAIR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,cAAc,EACd,SAAS,GAEV,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAiB,MAAM,6BAA6B,CAAA;AAe9E,8EAA8E;AAC9E,MAAM,KAAK,GAAG,EAAE,CAAA;AAEhB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,SAAU,SAAQ,IAAI;IAKjC,6EAA6E;IACrE,KAAK,GAAW,EAAE,CAAA;IAE1B,YAAY,KAA6C;QACvD,iEAAiE;QACjE,4EAA4E;QAC5E,yEAAyE;QACzE,YAAY;QACZ,KAAK,CAAC;YACJ,GAAI,KAAmB;YACvB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,YAAY;YACnB,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,KAAK;SACd,CAAC,CAAA;QAEF,oEAAoE;QACpE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA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,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CACrG,CAAA;IACH,CAAC;CACF;AA1GwD;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAgB,EAAE,CAAC;yCAA2B;AAC1B;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yCAA6B;AACd;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;uCAAuB;AAoFnE;IADC,OAAO,EAAE;sCAoBT","sourcesContent":["import {\r\n command,\r\n Rect,\r\n Text,\r\n easeOut,\r\n property,\r\n textOps,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type RectProps,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport {\r\n DEFAULT_LEGEND,\r\n clampUnit,\r\n type LegendConfig,\r\n} from \"../kit/shared\"\r\nimport { at, compose, hold, type Seekable } from \"@motionscript/sdk/component\"\r\nimport type { PieSlice } from \"./shared\"\r\n\r\nexport interface PieLegendProps extends RectProps {\r\n /** One entry per slice, in ring order. */\r\n slices: PieSlice[]\r\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\r\n legend: LegendConfig\r\n /**\r\n * Per-slice opacity multiplier, by index — the same signal that dims the ring,\r\n * so an entry fades in step with the wedge it names. Missing entries read as 1.\r\n */\r\n dims: number[]\r\n}\r\n\r\n/** How far an entry starts to the right of its slot when it enters, in px. */\r\nconst SLIDE = 16\r\n\r\n/**\r\n * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per\r\n * slice, each pairing the slice's caption with its colour swatch.\r\n *\r\n * A column rather than the cartesian charts' row, because it sits *beside* the\r\n * ring rather than beneath the plot — a pie is as tall as it is wide, so the\r\n * space it leaves over is a vertical strip. It is otherwise the same entry: the\r\n * swatch carries the colour, the caption reads in the legend's neutral ink, and\r\n * both take the shared {@link LegendConfig}.\r\n *\r\n * There is no show/hide here. A pie's marks are its *rows*, and a row that\r\n * shouldn't be in the chart shouldn't be in the table — removing one would\r\n * silently re-cut every other wedge's share, which is a different chart rather\r\n * than the same chart with something hidden. Selection is what a pie has\r\n * instead, and it arrives through {@link dims}.\r\n */\r\nexport class PieLegend extends Rect {\r\n @property({ default: () => [] as PieSlice[] }) declare slices: PieSlice[]\r\n @property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig\r\n @property({ default: () => [] as number[] }) declare dims: number[]\r\n\r\n /** One entry per slice, ordered top → bottom, for the staggered entrance. */\r\n private items: Rect[] = []\r\n\r\n constructor(props?: NodeConfig<PieLegend, PieLegendProps>) {\r\n // `flow` with the rest of the fixed geometry, and for the reason\r\n // {@link ChartLegend} spells out: a `Rect` given none lays its children out\r\n // `freeform`, so an unstated column is every caption drawn on top of the\r\n // last one.\r\n super({\r\n ...(props as RectProps),\r\n flow: \"vertical\",\r\n align: \"centerLeft\",\r\n width: \"hug\",\r\n height: \"hug\",\r\n })\r\n\r\n // Fixed column geometry last, so it wins over what super() applied.\r\n this.set({ gap: this.legend.itemGap / 3, padding: this.legend.padding })\r\n\r\n for (let i = 0; i < this.slices.length; i++) {\r\n const item = this.buildItem(i)\r\n this.items.push(item)\r\n // The selection dim rides a wrapper rather than the entry itself, so the\r\n // entrance can animate the entry's own opacity without the two fighting\r\n // over one value — opacity multiplies down the tree, which is exactly the\r\n // composition wanted here.\r\n this.add(\r\n new Rect({\r\n width: \"hug\",\r\n height: \"hug\",\r\n flow: \"freeform\",\r\n opacity: () => clampUnit(this.dims[i] ?? 1),\r\n children: [item],\r\n })\r\n )\r\n }\r\n }\r\n\r\n /** One entry: the slice's colour swatch beside its caption. */\r\n private buildItem(index: number): Rect {\r\n const marker = this.legend.markerStyle\r\n return new Rect({ flow: \"horizontal\",\r\n gap: 12,\r\n align: \"center\",\r\n width: \"hug\",\r\n height: \"hug\",\r\n children: [\r\n new Rect({\r\n width: marker.height,\r\n height: marker.height,\r\n cornerRadius: marker.borderRadius,\r\n fill: () => this.slices[index]?.fill ?? \"white\",\r\n stroke: marker.stroke,\r\n shadow: marker.shadow,\r\n }),\r\n new Text({\r\n ...textOps.styleProps(this.legend.textStyle),\r\n text: () => this.slices[index]?.category ?? \"\",\r\n }),\r\n ],\r\n })\r\n }\r\n\r\n /**\r\n * Prime every entry at its pre-entrance state: shifted right and transparent.\r\n *\r\n * Idempotent, and separate from {@link enter} so the chart can arm its whole\r\n * composition before the first frame is drawn — the resting state is the\r\n * finished legend, so there is nothing hidden to reveal unless a scene asks.\r\n */\r\n arm(slide = SLIDE): void {\r\n for (const item of this.items) item.set({ opacity: 0, x: slide })\r\n }\r\n\r\n /**\r\n * Slide + fade every entry in from the right, staggered top-to-bottom.\r\n *\r\n * `duration` is the **whole** entrance: the stagger is carved out of it rather\r\n * than added on top, so the command takes exactly the time the timeline laid\r\n * out for it.\r\n */\r\n @command()\r\n enter(\r\n args: CommandArgs<Record<string, never>> & { duration: number }\r\n ): Seekable {\r\n const duration = args.duration\r\n const easing = args.easing ?? easeOut()\r\n const items = this.items\r\n if (items.length === 0) return hold(duration)\r\n this.arm()\r\n\r\n // Each gap is a fifth of an entry's own move, the rhythm the axes use;\r\n // solved for from the budget rather than added to it. The offsets were\r\n // always `i * step` — written as `wait` inside a generator they merely only\r\n // existed while it ran.\r\n const per = duration / (1 + Math.max(0, items.length - 1) / 5)\r\n const step = per / 5\r\n\r\n return compose(\r\n items.map((item, i) => at(i * step, item.to({ data: { opacity: 1, x: 0 }, duration: per, easing })))\r\n )\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"pie-legend.js","sourceRoot":"","sources":["../../src/pie-chart/pie-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,OAAO,GAqBR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA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QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YACtH,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;QAC3D,CAAC;KACF;IACD,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnG,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvF,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;CAC7E,CAAC,CAAA","sourcesContent":["import {\r\n Flow,\r\n Paint,\r\n Rect,\r\n Shapes,\r\n Text,\r\n Types,\r\n component2d,\r\n textOps,\r\n type NodeOf,\r\n type RectProps,\r\n // Named so the column's emitted type reaches the Rect surface it spreads through the sdk, not core.\r\n type Alignment as _Alignment,\r\n type CornerRadiusResolved as _CornerRadiusResolved,\r\n type CornerStyleResolved as _CornerStyleResolved,\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type FlowMode as _FlowMode,\r\n type FlowResolved as _FlowResolved,\r\n type GapSize as _GapSize,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type RectCornerRadius as _RectCornerRadius,\r\n type RectCornerStyle as _RectCornerStyle,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n type Vector2 as _Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"../kit/motion\"\r\nimport {\r\n DEFAULT_LEGEND,\r\n clampUnit,\r\n type LegendConfig,\r\n} from \"../kit/shared\"\r\nimport type { PieSlice } from \"./shared\"\r\n\r\nexport interface PieLegendProps extends RectProps {\r\n /** One entry per slice, in ring order. */\r\n slices: PieSlice[]\r\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\r\n legend: LegendConfig\r\n /**\r\n * Per-slice opacity multiplier, by index — the same signal that dims the ring,\r\n * so an entry fades in step with the wedge it names. Missing entries read as 1.\r\n */\r\n dims: number[]\r\n}\r\n\r\n/** How far an entry starts to the right of its slot when it enters, in px. */\r\nconst SLIDE = 16\r\n\r\n/**\r\n * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per\r\n * slice, each pairing the slice's caption with its colour swatch.\r\n *\r\n * A column rather than the cartesian charts' row, because it sits *beside* the\r\n * ring rather than beneath the plot — a pie is as tall as it is wide, so the\r\n * space it leaves over is a vertical strip. It is otherwise the same entry: the\r\n * swatch carries the colour, the caption reads in the legend's neutral ink, and\r\n * both take the shared {@link LegendConfig}.\r\n *\r\n * There is no show/hide here. A pie's marks are its *rows*, and a row that\r\n * shouldn't be in the chart shouldn't be in the table — removing one would\r\n * silently re-cut every other wedge's share, which is a different chart rather\r\n * than the same chart with something hidden. Selection is what a pie has\r\n * instead, and it arrives through {@link PieLegendProps.dims}.\r\n */\r\nexport const PieLegend = component2d({\r\n key: \"pieLegend\",\r\n state: {\r\n ...Paint.state,\r\n ...Flow.state,\r\n ...Shapes.corners,\r\n slices: fresh<PieSlice[]>(() => []),\r\n legend: Types.custom<LegendConfig>(DEFAULT_LEGEND),\r\n dims: fresh<number[]>(() => []),\r\n arrivals: arrivalsEntry(),\r\n },\r\n // A column, for the reason `ChartLegend` gives for its row: a `Rect` given no\r\n // flow lays its children out `freeform`, every caption on top of the last.\r\n defaults: {\r\n flow: \"vertical\",\r\n align: \"centerLeft\",\r\n width: \"hug\",\r\n height: \"hug\",\r\n gap: (state) => state.legend.itemGap / 3,\r\n padding: (state) => state.legend.padding,\r\n },\r\n // One entry per slice, ordered top → bottom. The selection dim rides a wrapper\r\n // rather than the entry itself, so the entrance can animate the entry's own\r\n // opacity without the two fighting over one value — opacity multiplies down\r\n // the tree, which is exactly the composition wanted here.\r\n children: (state) => {\r\n const marker = state.legend.markerStyle\r\n return state.slices.map((_, index) =>\r\n Rect({\r\n width: \"hug\",\r\n height: \"hug\",\r\n flow: \"freeform\",\r\n opacity: () => clampUnit(state.dims[index] ?? 1),\r\n children: [\r\n Rect({\r\n flow: \"horizontal\",\r\n gap: 12,\r\n align: \"center\",\r\n width: \"hug\",\r\n height: \"hug\",\r\n opacity: () => arrivalOf(state.arrivals, index).opacity,\r\n x: () => arrivalOf(state.arrivals, index).shift,\r\n children: [\r\n Rect({\r\n width: marker.height,\r\n height: marker.height,\r\n cornerRadius: marker.borderRadius,\r\n fill: () => state.slices[index]?.fill ?? \"white\",\r\n stroke: marker.stroke,\r\n shadow: marker.shadow,\r\n }),\r\n Text({\r\n ...textOps.styleProps(state.legend.textStyle),\r\n text: () => state.slices[index]?.category ?? \"\",\r\n }),\r\n ],\r\n }),\r\n ],\r\n })\r\n )\r\n },\r\n commands: {\r\n ...Paint.commands,\r\n /**\r\n * Every entry at its pre-entrance state, shifted right and transparent: what\r\n * a chart shows ahead of this legend's own beat in its entrance, since\r\n * `enter` arms the entries only on its first frame.\r\n */\r\n arm: (timeline, state) =>\r\n timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], { opacity: 0, shift: SLIDE }) })),\r\n /**\r\n * Slide + fade every entry in from the right, staggered top-to-bottom. Its\r\n * first frame arms them all: shifted right and transparent.\r\n *\r\n * The timeline's duration is the **whole** entrance: the stagger is carved\r\n * out of it rather than added on top, so the command takes exactly the time\r\n * the timeline laid out for it.\r\n */\r\n enter: (timeline, state) => {\r\n const count = state.slices.length\r\n if (count === 0) return timeline.wait(timeline.duration)\r\n const from: Arrival = { opacity: 0, shift: SLIDE }\r\n const arm = timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], from) }))\r\n // Each gap is a fifth of an entry's own move, the rhythm the axes use;\r\n // solved for from the budget rather than added to it.\r\n const per = timeline.duration / (1 + Math.max(0, count - 1) / 5)\r\n const step = per / 5\r\n const ease = frameEase(timeline)\r\n const entries = state.slices.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }))\r\n return timeline.together([arm, beats(timeline, entries)])\r\n },\r\n },\r\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\r\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\r\n render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),\r\n})\r\n\r\nexport type PieLegend = NodeOf<typeof PieLegend>\r\n"]}
|