@motionscript/charts 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +85 -0
  5. package/dist/bar-chart/bar-chart.d.ts +28 -13
  6. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  7. package/dist/bar-chart/bar-chart.js +60 -56
  8. package/dist/bar-chart/bar-chart.js.map +1 -1
  9. package/dist/bar-chart/category-axis.js.map +1 -1
  10. package/dist/bar-chart/chart-bars.js.map +1 -1
  11. package/dist/bar-chart/index.js.map +1 -1
  12. package/dist/bar-chart/shared.d.ts +3 -3
  13. package/dist/bar-chart/shared.js +3 -3
  14. package/dist/bar-chart/shared.js.map +1 -1
  15. package/dist/browser/chunks/chunk-5ZPBV6BU.js +2 -0
  16. package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +7 -0
  17. package/dist/browser/index.js +1 -1
  18. package/dist/browser/index.js.map +3 -3
  19. package/dist/browser/kit.js +1 -1
  20. package/dist/browser/manifest.json +3 -2
  21. package/dist/engine.js.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/kit/chart-border.js.map +1 -1
  24. package/dist/kit/chart-canvas.js.map +1 -1
  25. package/dist/kit/chart-legend.d.ts +4 -25
  26. package/dist/kit/chart-legend.d.ts.map +1 -1
  27. package/dist/kit/chart-legend.js +31 -55
  28. package/dist/kit/chart-legend.js.map +1 -1
  29. package/dist/kit/shared.d.ts +29 -6
  30. package/dist/kit/shared.d.ts.map +1 -1
  31. package/dist/kit/shared.js +64 -8
  32. package/dist/kit/shared.js.map +1 -1
  33. package/dist/kit/vertical-axis.js.map +1 -1
  34. package/dist/line-chart/chart-line.d.ts +2 -2
  35. package/dist/line-chart/chart-line.js.map +1 -1
  36. package/dist/line-chart/chart-region.js.map +1 -1
  37. package/dist/line-chart/horizontal-axis.js.map +1 -1
  38. package/dist/line-chart/index.js.map +1 -1
  39. package/dist/line-chart/line-chart.d.ts +9 -1
  40. package/dist/line-chart/line-chart.d.ts.map +1 -1
  41. package/dist/line-chart/line-chart.js +32 -8
  42. package/dist/line-chart/line-chart.js.map +1 -1
  43. package/dist/line-chart/shared.d.ts +3 -3
  44. package/dist/line-chart/shared.d.ts.map +1 -1
  45. package/dist/line-chart/shared.js +19 -4
  46. package/dist/line-chart/shared.js.map +1 -1
  47. package/dist/line-chart/x-scale.d.ts +1 -1
  48. package/dist/line-chart/x-scale.js +1 -1
  49. package/dist/line-chart/x-scale.js.map +1 -1
  50. package/dist/nodes.js.map +1 -1
  51. package/dist/pie-chart/index.js.map +1 -1
  52. package/dist/pie-chart/pie-chart.d.ts +2 -2
  53. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  54. package/dist/pie-chart/pie-chart.js +9 -7
  55. package/dist/pie-chart/pie-chart.js.map +1 -1
  56. package/dist/pie-chart/pie-legend.js +4 -4
  57. package/dist/pie-chart/pie-legend.js.map +1 -1
  58. package/dist/pie-chart/pie-ring.d.ts +13 -4
  59. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  60. package/dist/pie-chart/pie-ring.js +44 -14
  61. package/dist/pie-chart/pie-ring.js.map +1 -1
  62. package/dist/pie-chart/shared.d.ts +3 -3
  63. package/dist/pie-chart/shared.js +3 -3
  64. package/dist/pie-chart/shared.js.map +1 -1
  65. package/package.json +6 -5
  66. package/registry.json +23 -23
  67. package/src/bar-chart/bar-chart.ts +820 -814
  68. package/src/bar-chart/category-axis.ts +177 -177
  69. package/src/bar-chart/chart-bars.ts +310 -310
  70. package/src/bar-chart/index.ts +31 -31
  71. package/src/bar-chart/shared.ts +354 -354
  72. package/src/engine.ts +26 -26
  73. package/src/index.ts +5 -5
  74. package/src/kit/chart-border.ts +61 -61
  75. package/src/kit/chart-canvas.ts +157 -157
  76. package/src/kit/chart-legend.ts +245 -250
  77. package/src/kit/shared.ts +733 -675
  78. package/src/kit/vertical-axis.ts +224 -224
  79. package/src/line-chart/chart-line.ts +208 -208
  80. package/src/line-chart/chart-region.ts +135 -135
  81. package/src/line-chart/horizontal-axis.ts +202 -202
  82. package/src/line-chart/index.ts +39 -39
  83. package/src/line-chart/line-chart.ts +961 -929
  84. package/src/line-chart/shared.ts +473 -459
  85. package/src/line-chart/x-scale.ts +367 -367
  86. package/src/nodes.ts +20 -20
  87. package/src/pie-chart/index.ts +37 -37
  88. package/src/pie-chart/pie-chart.ts +383 -381
  89. package/src/pie-chart/pie-legend.ts +159 -159
  90. package/src/pie-chart/pie-ring.ts +935 -903
  91. package/src/pie-chart/shared.ts +490 -490
  92. package/dist/browser/chunks/chunk-RMHQ6GYU.js +0 -2
  93. package/dist/browser/chunks/chunk-RMHQ6GYU.js.map +0 -7
@@ -1,159 +1,159 @@
1
- import {
2
- command,
3
- Rect,
4
- Text,
5
- easeOut,
6
- property,
7
- textOps,
8
- type CommandArgs,
9
- type NodeConfig,
10
- type RectProps,
11
- } from "@motionscript/sdk"
12
-
13
- import {
14
- DEFAULT_LEGEND,
15
- clampUnit,
16
- type LegendConfig,
17
- } from "../kit/shared"
18
- import { at, compose, hold, type Seekable } from "@motionscript/sdk/component"
19
- import type { PieSlice } from "./shared"
20
-
21
- export interface PieLegendProps extends RectProps {
22
- /** One entry per slice, in ring order. */
23
- slices: PieSlice[]
24
- /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */
25
- legend: LegendConfig
26
- /**
27
- * Per-slice opacity multiplier, by index — the same signal that dims the ring,
28
- * so an entry fades in step with the wedge it names. Missing entries read as 1.
29
- */
30
- dims: number[]
31
- }
32
-
33
- /** How far an entry starts to the right of its slot when it enters, in px. */
34
- const SLIDE = 16
35
-
36
- /**
37
- * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per
38
- * slice, each pairing the slice's caption with its colour swatch.
39
- *
40
- * A column rather than the cartesian charts' row, because it sits *beside* the
41
- * ring rather than beneath the plot — a pie is as tall as it is wide, so the
42
- * space it leaves over is a vertical strip. It is otherwise the same entry: the
43
- * swatch carries the colour, the caption reads in the legend's neutral ink, and
44
- * both take the shared {@link LegendConfig}.
45
- *
46
- * There is no show/hide here. A pie's marks are its *rows*, and a row that
47
- * shouldn't be in the chart shouldn't be in the table — removing one would
48
- * silently re-cut every other wedge's share, which is a different chart rather
49
- * than the same chart with something hidden. Selection is what a pie has
50
- * instead, and it arrives through {@link dims}.
51
- */
52
- export class PieLegend extends Rect {
53
- @property({ default: () => [] as PieSlice[] }) declare slices: PieSlice[]
54
- @property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig
55
- @property({ default: () => [] as number[] }) declare dims: number[]
56
-
57
- /** One entry per slice, ordered top → bottom, for the staggered entrance. */
58
- private items: Rect[] = []
59
-
60
- constructor(props?: NodeConfig<PieLegend, PieLegendProps>) {
61
- // `flow` with the rest of the fixed geometry, and for the reason
62
- // {@link ChartLegend} spells out: a `Rect` given none lays its children out
63
- // `freeform`, so an unstated column is every caption drawn on top of the
64
- // last one.
65
- super({
66
- ...(props as RectProps),
67
- flow: "vertical",
68
- align: "centerLeft",
69
- width: "hug",
70
- height: "hug",
71
- })
72
-
73
- // Fixed column geometry last, so it wins over what super() applied.
74
- this.set({ gap: this.legend.itemGap / 3, padding: this.legend.padding })
75
-
76
- for (let i = 0; i < this.slices.length; i++) {
77
- const item = this.buildItem(this.slices[i])
78
- this.items.push(item)
79
- // The selection dim rides a wrapper rather than the entry itself, so the
80
- // entrance can animate the entry's own opacity without the two fighting
81
- // over one value — opacity multiplies down the tree, which is exactly the
82
- // composition wanted here.
83
- this.add(
84
- new Rect({
85
- width: "hug",
86
- height: "hug",
87
- flow: "freeform",
88
- opacity: () => clampUnit(this.dims[i] ?? 1),
89
- children: [item],
90
- })
91
- )
92
- }
93
- }
94
-
95
- /** One entry: the slice's colour swatch beside its caption. */
96
- private buildItem(slice: PieSlice): Rect {
97
- const marker = this.legend.markerStyle
98
- return new Rect({ flow: "horizontal",
99
- gap: 12,
100
- align: "center",
101
- width: "hug",
102
- height: "hug",
103
- children: [
104
- new Rect({
105
- width: marker.height,
106
- height: marker.height,
107
- cornerRadius: marker.borderRadius,
108
- fill: slice.fill,
109
- stroke: marker.stroke,
110
- shadow: marker.shadow,
111
- }),
112
- new Text({
113
- ...textOps.styleProps(this.legend.textStyle),
114
- text: slice.category,
115
- }),
116
- ],
117
- })
118
- }
119
-
120
- /**
121
- * Prime every entry at its pre-entrance state: shifted right and transparent.
122
- *
123
- * Idempotent, and separate from {@link enter} so the chart can arm its whole
124
- * composition before the first frame is drawn — the resting state is the
125
- * finished legend, so there is nothing hidden to reveal unless a scene asks.
126
- */
127
- arm(slide = SLIDE): void {
128
- for (const item of this.items) item.set({ opacity: 0, x: slide })
129
- }
130
-
131
- /**
132
- * Slide + fade every entry in from the right, staggered top-to-bottom.
133
- *
134
- * `duration` is the **whole** entrance: the stagger is carved out of it rather
135
- * than added on top, so the command takes exactly the time the timeline laid
136
- * out for it.
137
- */
138
- @command()
139
- enter(
140
- args: CommandArgs<Record<string, never>> & { duration: number }
141
- ): Seekable {
142
- const duration = args.duration
143
- const easing = args.easing ?? easeOut()
144
- const items = this.items
145
- if (items.length === 0) return hold(duration)
146
- this.arm()
147
-
148
- // Each gap is a fifth of an entry's own move, the rhythm the axes use;
149
- // solved for from the budget rather than added to it. The offsets were
150
- // always `i * step` — written as `wait` inside a generator they merely only
151
- // existed while it ran.
152
- const per = duration / (1 + Math.max(0, items.length - 1) / 5)
153
- const step = per / 5
154
-
155
- return compose(
156
- items.map((item, i) => at(i * step, item.to({ data: { opacity: 1, x: 0 }, duration: per, easing })))
157
- )
158
- }
159
- }
1
+ import {
2
+ command,
3
+ Rect,
4
+ Text,
5
+ easeOut,
6
+ property,
7
+ textOps,
8
+ type CommandArgs,
9
+ type NodeConfig,
10
+ type RectProps,
11
+ } from "@motionscript/sdk"
12
+
13
+ import {
14
+ DEFAULT_LEGEND,
15
+ clampUnit,
16
+ type LegendConfig,
17
+ } from "../kit/shared"
18
+ import { at, compose, hold, type Seekable } from "@motionscript/sdk/component"
19
+ import type { PieSlice } from "./shared"
20
+
21
+ export interface PieLegendProps extends RectProps {
22
+ /** One entry per slice, in ring order. */
23
+ slices: PieSlice[]
24
+ /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */
25
+ legend: LegendConfig
26
+ /**
27
+ * Per-slice opacity multiplier, by index — the same signal that dims the ring,
28
+ * so an entry fades in step with the wedge it names. Missing entries read as 1.
29
+ */
30
+ dims: number[]
31
+ }
32
+
33
+ /** How far an entry starts to the right of its slot when it enters, in px. */
34
+ const SLIDE = 16
35
+
36
+ /**
37
+ * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per
38
+ * slice, each pairing the slice's caption with its colour swatch.
39
+ *
40
+ * A column rather than the cartesian charts' row, because it sits *beside* the
41
+ * ring rather than beneath the plot — a pie is as tall as it is wide, so the
42
+ * space it leaves over is a vertical strip. It is otherwise the same entry: the
43
+ * swatch carries the colour, the caption reads in the legend's neutral ink, and
44
+ * both take the shared {@link LegendConfig}.
45
+ *
46
+ * There is no show/hide here. A pie's marks are its *rows*, and a row that
47
+ * shouldn't be in the chart shouldn't be in the table — removing one would
48
+ * silently re-cut every other wedge's share, which is a different chart rather
49
+ * than the same chart with something hidden. Selection is what a pie has
50
+ * instead, and it arrives through {@link dims}.
51
+ */
52
+ export class PieLegend extends Rect {
53
+ @property({ default: () => [] as PieSlice[] }) declare slices: PieSlice[]
54
+ @property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig
55
+ @property({ default: () => [] as number[] }) declare dims: number[]
56
+
57
+ /** One entry per slice, ordered top → bottom, for the staggered entrance. */
58
+ private items: Rect[] = []
59
+
60
+ constructor(props?: NodeConfig<PieLegend, PieLegendProps>) {
61
+ // `flow` with the rest of the fixed geometry, and for the reason
62
+ // {@link ChartLegend} spells out: a `Rect` given none lays its children out
63
+ // `freeform`, so an unstated column is every caption drawn on top of the
64
+ // last one.
65
+ super({
66
+ ...(props as RectProps),
67
+ flow: "vertical",
68
+ align: "centerLeft",
69
+ width: "hug",
70
+ height: "hug",
71
+ })
72
+
73
+ // Fixed column geometry last, so it wins over what super() applied.
74
+ this.set({ gap: this.legend.itemGap / 3, padding: this.legend.padding })
75
+
76
+ for (let i = 0; i < this.slices.length; i++) {
77
+ const item = this.buildItem(i)
78
+ this.items.push(item)
79
+ // The selection dim rides a wrapper rather than the entry itself, so the
80
+ // entrance can animate the entry's own opacity without the two fighting
81
+ // over one value — opacity multiplies down the tree, which is exactly the
82
+ // composition wanted here.
83
+ this.add(
84
+ new Rect({
85
+ width: "hug",
86
+ height: "hug",
87
+ flow: "freeform",
88
+ opacity: () => clampUnit(this.dims[i] ?? 1),
89
+ children: [item],
90
+ })
91
+ )
92
+ }
93
+ }
94
+
95
+ /** One entry: the slice's colour swatch beside its caption. */
96
+ private buildItem(index: number): Rect {
97
+ const marker = this.legend.markerStyle
98
+ return new Rect({ flow: "horizontal",
99
+ gap: 12,
100
+ align: "center",
101
+ width: "hug",
102
+ height: "hug",
103
+ children: [
104
+ new Rect({
105
+ width: marker.height,
106
+ height: marker.height,
107
+ cornerRadius: marker.borderRadius,
108
+ fill: () => this.slices[index]?.fill ?? "white",
109
+ stroke: marker.stroke,
110
+ shadow: marker.shadow,
111
+ }),
112
+ new Text({
113
+ ...textOps.styleProps(this.legend.textStyle),
114
+ text: () => this.slices[index]?.category ?? "",
115
+ }),
116
+ ],
117
+ })
118
+ }
119
+
120
+ /**
121
+ * Prime every entry at its pre-entrance state: shifted right and transparent.
122
+ *
123
+ * Idempotent, and separate from {@link enter} so the chart can arm its whole
124
+ * composition before the first frame is drawn — the resting state is the
125
+ * finished legend, so there is nothing hidden to reveal unless a scene asks.
126
+ */
127
+ arm(slide = SLIDE): void {
128
+ for (const item of this.items) item.set({ opacity: 0, x: slide })
129
+ }
130
+
131
+ /**
132
+ * Slide + fade every entry in from the right, staggered top-to-bottom.
133
+ *
134
+ * `duration` is the **whole** entrance: the stagger is carved out of it rather
135
+ * than added on top, so the command takes exactly the time the timeline laid
136
+ * out for it.
137
+ */
138
+ @command()
139
+ enter(
140
+ args: CommandArgs<Record<string, never>> & { duration: number }
141
+ ): Seekable {
142
+ const duration = args.duration
143
+ const easing = args.easing ?? easeOut()
144
+ const items = this.items
145
+ if (items.length === 0) return hold(duration)
146
+ this.arm()
147
+
148
+ // Each gap is a fifth of an entry's own move, the rhythm the axes use;
149
+ // solved for from the budget rather than added to it. The offsets were
150
+ // always `i * step` — written as `wait` inside a generator they merely only
151
+ // existed while it ran.
152
+ const per = duration / (1 + Math.max(0, items.length - 1) / 5)
153
+ const step = per / 5
154
+
155
+ return compose(
156
+ items.map((item, i) => at(i * step, item.to({ data: { opacity: 1, x: 0 }, duration: per, easing })))
157
+ )
158
+ }
159
+ }