@motionscript/charts 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/dist/bar-chart/bar-chart.d.ts +286 -0
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -0
  5. package/dist/bar-chart/bar-chart.js +610 -0
  6. package/dist/bar-chart/bar-chart.js.map +1 -0
  7. package/dist/bar-chart/category-axis.d.ts +77 -0
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -0
  9. package/dist/bar-chart/category-axis.js +141 -0
  10. package/dist/bar-chart/category-axis.js.map +1 -0
  11. package/dist/bar-chart/chart-bars.d.ts +149 -0
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -0
  13. package/dist/bar-chart/chart-bars.js +236 -0
  14. package/dist/bar-chart/chart-bars.js.map +1 -0
  15. package/dist/bar-chart/index.d.ts +16 -0
  16. package/dist/bar-chart/index.d.ts.map +1 -0
  17. package/dist/bar-chart/index.js +12 -0
  18. package/dist/bar-chart/index.js.map +1 -0
  19. package/dist/bar-chart/shared.d.ts +146 -0
  20. package/dist/bar-chart/shared.d.ts.map +1 -0
  21. package/dist/bar-chart/shared.js +182 -0
  22. package/dist/bar-chart/shared.js.map +1 -0
  23. package/dist/browser/chunks/chunk-ZMBOBHYL.js +2 -0
  24. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +7 -0
  25. package/dist/browser/index.js +2 -0
  26. package/dist/browser/index.js.map +7 -0
  27. package/dist/browser/kit.js +2 -0
  28. package/dist/browser/kit.js.map +7 -0
  29. package/dist/browser/manifest.json +12 -0
  30. package/dist/engine.d.ts +27 -0
  31. package/dist/engine.d.ts.map +1 -0
  32. package/dist/engine.js +27 -0
  33. package/dist/engine.js.map +1 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +6 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +28 -0
  39. package/dist/kit/chart-border.d.ts.map +1 -0
  40. package/dist/kit/chart-border.js +45 -0
  41. package/dist/kit/chart-border.js.map +1 -0
  42. package/dist/kit/chart-canvas.d.ts +56 -0
  43. package/dist/kit/chart-canvas.d.ts.map +1 -0
  44. package/dist/kit/chart-canvas.js +125 -0
  45. package/dist/kit/chart-canvas.js.map +1 -0
  46. package/dist/kit/chart-legend.d.ts +126 -0
  47. package/dist/kit/chart-legend.d.ts.map +1 -0
  48. package/dist/kit/chart-legend.js +212 -0
  49. package/dist/kit/chart-legend.js.map +1 -0
  50. package/dist/kit/shared.d.ts +251 -0
  51. package/dist/kit/shared.d.ts.map +1 -0
  52. package/dist/kit/shared.js +401 -0
  53. package/dist/kit/shared.js.map +1 -0
  54. package/dist/kit/vertical-axis.d.ts +99 -0
  55. package/dist/kit/vertical-axis.d.ts.map +1 -0
  56. package/dist/kit/vertical-axis.js +176 -0
  57. package/dist/kit/vertical-axis.js.map +1 -0
  58. package/dist/line-chart/chart-line.d.ts +91 -0
  59. package/dist/line-chart/chart-line.d.ts.map +1 -0
  60. package/dist/line-chart/chart-line.js +156 -0
  61. package/dist/line-chart/chart-line.js.map +1 -0
  62. package/dist/line-chart/chart-region.d.ts +47 -0
  63. package/dist/line-chart/chart-region.d.ts.map +1 -0
  64. package/dist/line-chart/chart-region.js +101 -0
  65. package/dist/line-chart/chart-region.js.map +1 -0
  66. package/dist/line-chart/horizontal-axis.d.ts +85 -0
  67. package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
  68. package/dist/line-chart/horizontal-axis.js +158 -0
  69. package/dist/line-chart/horizontal-axis.js.map +1 -0
  70. package/dist/line-chart/index.d.ts +22 -0
  71. package/dist/line-chart/index.d.ts.map +1 -0
  72. package/dist/line-chart/index.js +19 -0
  73. package/dist/line-chart/index.js.map +1 -0
  74. package/dist/line-chart/line-chart.d.ts +347 -0
  75. package/dist/line-chart/line-chart.d.ts.map +1 -0
  76. package/dist/line-chart/line-chart.js +701 -0
  77. package/dist/line-chart/line-chart.js.map +1 -0
  78. package/dist/line-chart/shared.d.ts +171 -0
  79. package/dist/line-chart/shared.d.ts.map +1 -0
  80. package/dist/line-chart/shared.js +270 -0
  81. package/dist/line-chart/shared.js.map +1 -0
  82. package/dist/line-chart/x-scale.d.ts +84 -0
  83. package/dist/line-chart/x-scale.d.ts.map +1 -0
  84. package/dist/line-chart/x-scale.js +302 -0
  85. package/dist/line-chart/x-scale.js.map +1 -0
  86. package/dist/nodes.d.ts +20 -0
  87. package/dist/nodes.d.ts.map +1 -0
  88. package/dist/nodes.js +20 -0
  89. package/dist/nodes.js.map +1 -0
  90. package/dist/pie-chart/index.d.ts +18 -0
  91. package/dist/pie-chart/index.d.ts.map +1 -0
  92. package/dist/pie-chart/index.js +14 -0
  93. package/dist/pie-chart/index.js.map +1 -0
  94. package/dist/pie-chart/pie-chart.d.ts +170 -0
  95. package/dist/pie-chart/pie-chart.d.ts.map +1 -0
  96. package/dist/pie-chart/pie-chart.js +291 -0
  97. package/dist/pie-chart/pie-chart.js.map +1 -0
  98. package/dist/pie-chart/pie-legend.d.ts +60 -0
  99. package/dist/pie-chart/pie-legend.d.ts.map +1 -0
  100. package/dist/pie-chart/pie-legend.js +131 -0
  101. package/dist/pie-chart/pie-legend.js.map +1 -0
  102. package/dist/pie-chart/pie-ring.d.ts +266 -0
  103. package/dist/pie-chart/pie-ring.d.ts.map +1 -0
  104. package/dist/pie-chart/pie-ring.js +708 -0
  105. package/dist/pie-chart/pie-ring.js.map +1 -0
  106. package/dist/pie-chart/shared.d.ts +210 -0
  107. package/dist/pie-chart/shared.d.ts.map +1 -0
  108. package/dist/pie-chart/shared.js +240 -0
  109. package/dist/pie-chart/shared.js.map +1 -0
  110. package/package.json +69 -3
  111. package/registry.json +23 -0
  112. package/src/bar-chart/bar-chart.ts +804 -0
  113. package/src/bar-chart/category-axis.ts +177 -0
  114. package/src/bar-chart/chart-bars.ts +310 -0
  115. package/src/bar-chart/index.ts +31 -0
  116. package/src/bar-chart/shared.ts +354 -0
  117. package/src/engine.ts +26 -0
  118. package/src/index.ts +5 -0
  119. package/src/kit/chart-border.ts +61 -0
  120. package/src/kit/chart-canvas.ts +157 -0
  121. package/src/kit/chart-legend.ts +250 -0
  122. package/src/kit/shared.ts +675 -0
  123. package/src/kit/vertical-axis.ts +224 -0
  124. package/src/line-chart/chart-line.ts +208 -0
  125. package/src/line-chart/chart-region.ts +135 -0
  126. package/src/line-chart/horizontal-axis.ts +202 -0
  127. package/src/line-chart/index.ts +39 -0
  128. package/src/line-chart/line-chart.ts +894 -0
  129. package/src/line-chart/shared.ts +459 -0
  130. package/src/line-chart/x-scale.ts +367 -0
  131. package/src/nodes.ts +20 -0
  132. package/src/pie-chart/index.ts +37 -0
  133. package/src/pie-chart/pie-chart.ts +374 -0
  134. package/src/pie-chart/pie-legend.ts +159 -0
  135. package/src/pie-chart/pie-ring.ts +903 -0
  136. package/src/pie-chart/shared.ts +490 -0
  137. package/README.md +0 -4
@@ -0,0 +1,490 @@
1
+ /**
2
+ * Types and pure helpers specific to the {@link PieChart} family: how rows
3
+ * become slices, how slices become arcs on a ring, where the labels around it
4
+ * end up, and the theme all of that is drawn from.
5
+ *
6
+ * The one chart in the family that draws **one mark per row** rather than one
7
+ * per column, which is why almost nothing about its geometry is shared: there is
8
+ * no scale, no axis and no baseline, only a circle divided by share. What it
9
+ * *does* share — the legend, the theme leaf resolvers, the palette, the
10
+ * percentage format — comes from `nodes/chart-kit/shared.ts`.
11
+ *
12
+ * Kept renderer-agnostic (no `Node` imports) so the studio's inspector mapping
13
+ * (`pie-chart-props.ts`) can build a partial {@link PieChartTheme} without
14
+ * pulling the node classes in.
15
+ */
16
+
17
+ import {
18
+ lerpNumber,
19
+ shadowOps,
20
+ strokeOps,
21
+ textOps,
22
+ type DataRecord,
23
+ type Fill,
24
+ type Shadow,
25
+ type ShadowResolved,
26
+ type Stroke,
27
+ type StrokeResolved,
28
+ type TextStyle,
29
+ type Vector2,
30
+ } from "@motionscript/core"
31
+
32
+ import {
33
+ CHART_PALETTE,
34
+ DEFAULT_LEGEND,
35
+ DEFAULT_SERIES_FILLS,
36
+ SPOTLIGHT_DIM,
37
+ lerpLegendConfig,
38
+ lerpSeriesFills,
39
+ num,
40
+ resolveLegendConfig,
41
+ resolveSeriesFills,
42
+ text,
43
+ type LegendConfig,
44
+ type LegendTheme,
45
+ } from "../kit/shared"
46
+
47
+ /**
48
+ * One **resolved** slice of a {@link PieChart}: its caption, its magnitude, and
49
+ * the paint its wedge and legend swatch take.
50
+ *
51
+ * This is what the ring and the legend consume, not what a scene authors: the
52
+ * chart takes tabular `data` plus two field names and resolves it into these, so
53
+ * the parts stay unaware of where a slice's caption, magnitude and paint came
54
+ * from.
55
+ */
56
+ export interface PieSlice {
57
+ /** Legend caption and label text for this slice. */
58
+ category: string
59
+ /** This slice's magnitude. Its wedge covers `value / (sum of all values)`. */
60
+ value: number
61
+ /** Wedge and swatch paint. */
62
+ fill: Fill
63
+ }
64
+
65
+ /**
66
+ * Resolve tabular rows into slices: one per row, captioned by the `category`
67
+ * column, sized by the `value` column, painted from `palette` by row order
68
+ * (cycling when the palette is shorter than the data).
69
+ *
70
+ * Paint comes from the palette rather than from the rows because a pie draws one
71
+ * mark per *row* — unlike the line and bar charts, where a colour belongs to a
72
+ * series (a whole column) and rides on the series entry instead. Keeping it out
73
+ * of the rows is what lets a pie be fed straight from a CSV of plain numbers.
74
+ */
75
+ export function resolvePieSlices(
76
+ data: DataRecord[],
77
+ category: string,
78
+ value: string,
79
+ palette: Fill[]
80
+ ): PieSlice[] {
81
+ return data.map((row, i) => ({
82
+ category: text(row, category),
83
+ value: num(row, value),
84
+ fill:
85
+ palette.length > 0 ? palette[i % palette.length] : ("white" as Fill),
86
+ }))
87
+ }
88
+
89
+ /** What a {@link PieChart}'s labels say. */
90
+ export type PieLabelMode =
91
+ /**
92
+ * The category and its percentage, two lines. Their order flips with the
93
+ * placement: a **leader** label reads category over percentage, an **inside**
94
+ * label reads the percentage big over a small category caption — inside a
95
+ * wedge the reader already knows which slice they're on, so the magnitude is
96
+ * the thing being read.
97
+ */
98
+ | "both"
99
+ /** The category only. */
100
+ | "category"
101
+ /** The percentage only — the pick when a legend already names the categories. */
102
+ | "percent"
103
+ /** No labels and no leader lines at all. */
104
+ | "none"
105
+
106
+ /**
107
+ * Where a slice's label sits.
108
+ *
109
+ * `"inside"` drops the leader line entirely and centres the label in the wedge's
110
+ * own band, which costs no gutter — so the ring draws bigger — and costs the eye
111
+ * no round trip. `"leader"` is the classic treatment, and what a sliver too
112
+ * narrow to hold text needs.
113
+ */
114
+ export type PieLabelPlacement = "inside" | "leader" | "none"
115
+
116
+ /** Degrees → radians. */
117
+ export const DEG = Math.PI / 180
118
+
119
+ /** A slice's plotted value: negatives and non-finite values count as 0. */
120
+ export function sliceValue(slice: PieSlice): number {
121
+ return slice.value > 0 && Number.isFinite(slice.value) ? slice.value : 0
122
+ }
123
+
124
+ /** Sum of every slice's plotted value — the denominator every share is taken against. */
125
+ export function sliceTotal(slices: PieSlice[]): number {
126
+ let sum = 0
127
+ for (const slice of slices) sum += sliceValue(slice)
128
+ return sum
129
+ }
130
+
131
+ /**
132
+ * The point at radius `r` and angle `a` on a ring centred on the origin, in the
133
+ * node's centred, **y-up** space. Angles run **clockwise from 12 o'clock**:
134
+ * `a = 0` points straight up (+y), and increasing `a` sweeps toward +x then −y.
135
+ */
136
+ export function ringPoint(r: number, a: number): Vector2 {
137
+ return { x: r * Math.sin(a), y: r * Math.cos(a) }
138
+ }
139
+
140
+ /** One slice's resolved angular span on the ring. */
141
+ export interface PieArc {
142
+ /** Index of the slice in the source list. */
143
+ index: number
144
+ /** Start angle, radians clockwise from 12 o'clock. */
145
+ a0: number
146
+ /** End angle, radians clockwise from 12 o'clock. */
147
+ a1: number
148
+ /** Bisector angle — where this slice's label and pop-out point. */
149
+ mid: number
150
+ /** This slice's share of the total, in `[0, 1]`. */
151
+ fraction: number
152
+ }
153
+
154
+ /**
155
+ * Resolve slices into per-slice arcs: each covers exactly its share of the
156
+ * circle, walking clockwise from `startDegrees` (0 = 12 o'clock), with the arcs
157
+ * abutting. Zero/negative slices are skipped entirely; an all-zero list yields
158
+ * no arcs.
159
+ *
160
+ * Arcs are the *undivided* shares — the gap between neighbours is not carved out
161
+ * here, because a fixed angular gap reads as a wedge: wide at the rim, pinched
162
+ * shut at the hole. It's applied when the wedge is drawn instead, as a
163
+ * constant-width inset off both ends of every arc, so a slice still covers its
164
+ * true percentage of the circle.
165
+ */
166
+ export function pieArcs(slices: PieSlice[], startDegrees: number): PieArc[] {
167
+ const total = sliceTotal(slices)
168
+ if (total <= 0) return []
169
+
170
+ const arcs: PieArc[] = []
171
+ let cursor = startDegrees * DEG
172
+ slices.forEach((slice, index) => {
173
+ const value = sliceValue(slice)
174
+ if (value <= 0) return
175
+ const fraction = value / total
176
+ const a0 = cursor
177
+ const a1 = a0 + fraction * Math.PI * 2
178
+ cursor = a1
179
+ arcs.push({ index, a0, a1, mid: (a0 + a1) / 2, fraction })
180
+ })
181
+ return arcs
182
+ }
183
+
184
+ /** A label competing for vertical space in one of the two label columns. */
185
+ export interface LabelSlot {
186
+ /** Where the label would sit if nothing else were in the way. */
187
+ ideal: number
188
+ /** Where it ends up once the column has been de-conflicted. Written by {@link relaxLabels}. */
189
+ y: number
190
+ }
191
+
192
+ /**
193
+ * Spread one column of labels so no two overlap, keeping each as close to its
194
+ * `ideal` y as possible and the whole column inside `[bottom, top]`.
195
+ *
196
+ * Two passes, the standard treatment. Walking top-to-bottom, each label takes
197
+ * the highest slot at or below its ideal that still clears the label above it by
198
+ * `minGap`; if that pushes the tail past `bottom`, a reverse pass lifts it back
199
+ * up. When there are more labels than the column can hold, the reverse pass wins
200
+ * and the crowding is shared evenly rather than dumped off the bottom edge.
201
+ *
202
+ * Mutates each slot's `y` and returns `slots` re-ordered top-to-bottom.
203
+ */
204
+ export function relaxLabels<T extends LabelSlot>(
205
+ slots: T[],
206
+ minGap: number,
207
+ top: number,
208
+ bottom: number
209
+ ): T[] {
210
+ slots.sort((a, b) => b.ideal - a.ideal)
211
+
212
+ let ceiling = top
213
+ for (const slot of slots) {
214
+ slot.y = Math.min(slot.ideal, ceiling)
215
+ ceiling = slot.y - minGap
216
+ }
217
+
218
+ let floor = bottom
219
+ for (let i = slots.length - 1; i >= 0; i--) {
220
+ slots[i].y = Math.max(slots[i].y, floor)
221
+ floor = slots[i].y + minGap
222
+ }
223
+
224
+ return slots
225
+ }
226
+
227
+ // ---- Theme ---------------------------------------------------------------
228
+
229
+ /** The ring's geometry and paint — everything about the wedges but their colour. */
230
+ export interface RingConfig {
231
+ /**
232
+ * Width of the channel between adjacent slices, in px, held constant all the
233
+ * way across the band — the same clearance at the hole as at the rim. (An
234
+ * angular gap would splay open toward the rim instead.)
235
+ */
236
+ gap: number
237
+ /**
238
+ * Radius of the hole punched through the middle. Below 1 it reads as a
239
+ * fraction of the ring's outer radius (`0.6` leaves a band 40% of the radius
240
+ * thick); 1 and up as an explicit pixel radius; `0` fills the middle in,
241
+ * drawing solid pie wedges.
242
+ */
243
+ holeRadius: number
244
+ /** Angle in degrees where the first slice begins, clockwise from 12 o'clock. */
245
+ startAngle: number
246
+ /**
247
+ * How far out a selected slice's rim reaches, as a **multiple of the ring's
248
+ * outer radius**. Being relative, the emphasis scales with the chart instead
249
+ * of shrinking on a big one and swamping a small one. Clamped to `[1, 1.6]`.
250
+ */
251
+ selectedGrow: number
252
+ /** Optional outline on every wedge. */
253
+ stroke: Stroke
254
+ /** Optional drop shadow on every wedge. */
255
+ shadow: Shadow
256
+ }
257
+
258
+ /** How the ring's labels are set, and the leader lines that point at them. */
259
+ export interface LabelConfig {
260
+ /** The category caption on a label. */
261
+ textStyle: TextStyle
262
+ /** The percentage on a label. */
263
+ percentStyle: TextStyle
264
+ /**
265
+ * Ink for a label set **inside** its wedge, both lines. Separate because an
266
+ * inside label sits on the wedge's own paint rather than on the background, so
267
+ * it usually wants the opposite end of the value range from everything else.
268
+ */
269
+ insideStyle: TextStyle
270
+ /** The leader line running from a wedge out to its label. */
271
+ leaderStroke: Stroke
272
+ }
273
+
274
+ /** The summary set in the ring's hole. */
275
+ export interface CenterConfig {
276
+ labelStyle: TextStyle
277
+ captionStyle: TextStyle
278
+ }
279
+
280
+ /** A {@link PieChart}'s full, resolved visual theme. */
281
+ export interface PieChartConfig {
282
+ /** Wedge and swatch paint, cycled by **row** index (`i % length`). */
283
+ sliceFills: Fill[]
284
+ ring: RingConfig
285
+ label: LabelConfig
286
+ center: CenterConfig
287
+ legend: LegendConfig
288
+ /** How far everything outside the selection fades while any slice is selected. */
289
+ spotlight: { dimOpacity: number }
290
+ }
291
+
292
+ /** Author-facing partial theme — every branch optional and deep-merged. */
293
+ export type PieChartTheme = {
294
+ sliceFills?: Fill[]
295
+ ring?: Partial<RingConfig>
296
+ label?: Partial<LabelConfig>
297
+ center?: Partial<CenterConfig>
298
+ legend?: LegendTheme
299
+ spotlight?: Partial<PieChartConfig["spotlight"]>
300
+ }
301
+
302
+ const LABEL_TEXT_STYLE: TextStyle = {
303
+ fontSize: 26,
304
+ fontWeight: 600,
305
+ textAlign: "center",
306
+ fill: CHART_PALETTE.markerColor,
307
+ }
308
+
309
+ /** The pie chart's out-of-the-box look. */
310
+ export const DEFAULT_PIE_CHART_THEME: PieChartConfig = {
311
+ sliceFills: DEFAULT_SERIES_FILLS,
312
+ ring: {
313
+ gap: 6,
314
+ // A donut rather than a solid pie by default: the hole is the largest
315
+ // uninterrupted area the chart owns and the one place a conclusion can be
316
+ // set. `0` here would give that away before anyone had asked for it.
317
+ holeRadius: 0.6,
318
+ startAngle: 0,
319
+ selectedGrow: 1.08,
320
+ stroke: [],
321
+ shadow: [],
322
+ },
323
+ label: {
324
+ textStyle: LABEL_TEXT_STYLE,
325
+ percentStyle: { ...LABEL_TEXT_STYLE, fontWeight: 700 },
326
+ // Inside labels sit on the wedge's paint, which is a mid-tone from the
327
+ // palette — so they lead with the panel colour rather than the axis ink.
328
+ insideStyle: { ...LABEL_TEXT_STYLE, fontWeight: 800, fill: "#15130e" },
329
+ leaderStroke: { weight: 2, fill: CHART_PALETTE.markerColor },
330
+ },
331
+ center: {
332
+ labelStyle: {
333
+ fontSize: 46,
334
+ fontWeight: 800,
335
+ textAlign: "center",
336
+ fill: CHART_PALETTE.markerColor,
337
+ },
338
+ captionStyle: {
339
+ fontSize: 22,
340
+ fontWeight: 500,
341
+ textAlign: "center",
342
+ fill: CHART_PALETTE.markerColor,
343
+ },
344
+ },
345
+ legend: DEFAULT_LEGEND,
346
+ spotlight: { dimOpacity: SPOTLIGHT_DIM },
347
+ }
348
+
349
+ function resolveRingConfig(
350
+ ring: Partial<RingConfig> | undefined,
351
+ previous: RingConfig
352
+ ): RingConfig {
353
+ return {
354
+ gap: ring?.gap ?? previous.gap,
355
+ holeRadius: ring?.holeRadius ?? previous.holeRadius,
356
+ startAngle: ring?.startAngle ?? previous.startAngle,
357
+ selectedGrow: ring?.selectedGrow ?? previous.selectedGrow,
358
+ stroke: strokeOps.resolve(ring?.stroke ?? previous.stroke),
359
+ shadow: shadowOps.resolve(ring?.shadow ?? previous.shadow),
360
+ }
361
+ }
362
+
363
+ function lerpRingConfig(
364
+ from: RingConfig,
365
+ to: RingConfig,
366
+ t: number
367
+ ): RingConfig {
368
+ return {
369
+ gap: lerpNumber(from.gap, to.gap, t),
370
+ holeRadius: lerpNumber(from.holeRadius, to.holeRadius, t),
371
+ startAngle: lerpNumber(from.startAngle, to.startAngle, t),
372
+ selectedGrow: lerpNumber(from.selectedGrow, to.selectedGrow, t),
373
+ stroke: strokeOps.lerp(
374
+ from.stroke as StrokeResolved[],
375
+ to.stroke as StrokeResolved[],
376
+ t
377
+ ),
378
+ shadow: shadowOps.lerp(
379
+ from.shadow as ShadowResolved[],
380
+ to.shadow as ShadowResolved[],
381
+ t
382
+ ),
383
+ }
384
+ }
385
+
386
+ function resolveLabelConfig(
387
+ label: Partial<LabelConfig> | undefined,
388
+ previous: LabelConfig
389
+ ): LabelConfig {
390
+ return {
391
+ textStyle: textOps.resolveStyle(label?.textStyle, previous.textStyle),
392
+ percentStyle: textOps.resolveStyle(
393
+ label?.percentStyle,
394
+ previous.percentStyle
395
+ ),
396
+ insideStyle: textOps.resolveStyle(label?.insideStyle, previous.insideStyle),
397
+ leaderStroke: strokeOps.resolve(
398
+ label?.leaderStroke ?? previous.leaderStroke
399
+ ),
400
+ }
401
+ }
402
+
403
+ function lerpLabelConfig(
404
+ from: LabelConfig,
405
+ to: LabelConfig,
406
+ t: number
407
+ ): LabelConfig {
408
+ return {
409
+ textStyle: textOps.lerpStyle(from.textStyle, to.textStyle, t),
410
+ percentStyle: textOps.lerpStyle(from.percentStyle, to.percentStyle, t),
411
+ insideStyle: textOps.lerpStyle(from.insideStyle, to.insideStyle, t),
412
+ leaderStroke: strokeOps.lerp(
413
+ from.leaderStroke as StrokeResolved[],
414
+ to.leaderStroke as StrokeResolved[],
415
+ t
416
+ ),
417
+ }
418
+ }
419
+
420
+ function resolveCenterConfig(
421
+ center: Partial<CenterConfig> | undefined,
422
+ previous: CenterConfig
423
+ ): CenterConfig {
424
+ return {
425
+ labelStyle: textOps.resolveStyle(center?.labelStyle, previous.labelStyle),
426
+ captionStyle: textOps.resolveStyle(
427
+ center?.captionStyle,
428
+ previous.captionStyle
429
+ ),
430
+ }
431
+ }
432
+
433
+ function lerpCenterConfig(
434
+ from: CenterConfig,
435
+ to: CenterConfig,
436
+ t: number
437
+ ): CenterConfig {
438
+ return {
439
+ labelStyle: textOps.lerpStyle(from.labelStyle, to.labelStyle, t),
440
+ captionStyle: textOps.lerpStyle(from.captionStyle, to.captionStyle, t),
441
+ }
442
+ }
443
+
444
+ /**
445
+ * {@link PieChart}'s `theme` @property mapper: merges the author's partial
446
+ * {@link PieChartTheme} onto `previous` (falling back to
447
+ * {@link DEFAULT_PIE_CHART_THEME} on first resolution), fully resolving every
448
+ * leaf so the tween below always has resolved data to interpolate.
449
+ */
450
+ export function resolvePieChartTheme(
451
+ theme: PieChartTheme | undefined,
452
+ previous?: PieChartConfig
453
+ ): PieChartConfig {
454
+ const base = previous ?? DEFAULT_PIE_CHART_THEME
455
+ return {
456
+ sliceFills: resolveSeriesFills(theme?.sliceFills, base.sliceFills),
457
+ ring: resolveRingConfig(theme?.ring, base.ring),
458
+ label: resolveLabelConfig(theme?.label, base.label),
459
+ center: resolveCenterConfig(theme?.center, base.center),
460
+ legend: resolveLegendConfig(theme?.legend, base.legend),
461
+ spotlight: {
462
+ dimOpacity: theme?.spotlight?.dimOpacity ?? base.spotlight.dimOpacity,
463
+ },
464
+ }
465
+ }
466
+
467
+ /** {@link PieChart}'s `theme` @property tween — leaf by leaf. */
468
+ export function lerpPieChartTheme(
469
+ from: PieChartConfig,
470
+ to: PieChartConfig,
471
+ t: number
472
+ ): PieChartConfig {
473
+ return {
474
+ // A palette is a list of independent paints rather than one value, so it
475
+ // interpolates pairwise by index; one that grows or shrinks holds the longer
476
+ // side's tail, exactly as the cartesian charts' palettes do.
477
+ sliceFills: lerpSeriesFills(from.sliceFills, to.sliceFills, t),
478
+ ring: lerpRingConfig(from.ring, to.ring, t),
479
+ label: lerpLabelConfig(from.label, to.label, t),
480
+ center: lerpCenterConfig(from.center, to.center, t),
481
+ legend: lerpLegendConfig(from.legend, to.legend, t),
482
+ spotlight: {
483
+ dimOpacity: lerpNumber(
484
+ from.spotlight.dimOpacity,
485
+ to.spotlight.dimOpacity,
486
+ t
487
+ ),
488
+ },
489
+ }
490
+ }
package/README.md DELETED
@@ -1,4 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
- If no other versions are published within 30 days, this package and version will be deleted.