@motionscript/charts 0.1.1-alpha.0 → 0.1.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +98 -28
- package/dist/bar-chart/bar-chart.d.ts +233 -39
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +215 -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 +52 -52
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +80 -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 +36 -65
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +68 -117
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-R3Q5EE6E.js +2 -0
- package/dist/browser/chunks/chunk-R3Q5EE6E.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 +49 -15
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +79 -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 +254 -0
- package/dist/kit/style.d.ts.map +1 -0
- package/dist/kit/style.js +197 -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 +257 -18
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +282 -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 +37 -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 +53 -61
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +41 -121
- 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 +218 -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 +43 -0
- package/dist/radar-chart/radar-grid.d.ts.map +1 -0
- package/dist/radar-chart/radar-grid.js +61 -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 +73 -0
- package/dist/radar-chart/shared.d.ts.map +1 -0
- package/dist/radar-chart/shared.js +123 -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 +216 -0
- package/dist/radial-chart/radial-chart.d.ts.map +1 -0
- package/dist/radial-chart/radial-chart.js +174 -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 +73 -0
- package/dist/radial-chart/shared.d.ts.map +1 -0
- package/dist/radial-chart/shared.js +79 -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 +252 -179
- package/src/bar-chart/category-axis.ts +46 -40
- package/src/bar-chart/chart-bars.ts +97 -117
- package/src/bar-chart/index.ts +7 -10
- package/src/bar-chart/shared.ts +78 -238
- package/src/engine.ts +5 -2
- package/src/index.ts +2 -0
- package/src/kit/cartesian.ts +118 -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 +257 -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 +347 -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 +52 -35
- package/src/pie-chart/pie-ring.ts +92 -71
- package/src/pie-chart/shared.ts +68 -266
- package/src/radar-chart/index.ts +4 -0
- package/src/radar-chart/radar-chart.ts +287 -0
- package/src/radar-chart/radar-grid.ts +78 -0
- package/src/radar-chart/radar-series.ts +88 -0
- package/src/radar-chart/shared.ts +146 -0
- package/src/radial-chart/index.ts +5 -0
- package/src/radial-chart/radial-chart.ts +210 -0
- package/src/radial-chart/radial-rings.ts +328 -0
- package/src/radial-chart/shared.ts +114 -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
package/src/pie-chart/shared.ts
CHANGED
|
@@ -1,85 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clamp,
|
|
3
|
-
lerpNumber,
|
|
4
|
-
shadowOps,
|
|
5
|
-
strokeOps,
|
|
6
|
-
textOps,
|
|
7
|
-
type DataRecord,
|
|
8
|
-
type Fill,
|
|
9
|
-
type Shadow,
|
|
10
|
-
type ShadowResolved,
|
|
11
|
-
type Stroke,
|
|
12
|
-
type StrokeResolved,
|
|
13
|
-
type TextStyle,
|
|
14
|
-
type Vector2,
|
|
15
|
-
} from "@motionscript/sdk"
|
|
1
|
+
import { Types, type Fill, type TextStyle, type Stroke, type FillResolved as _FillResolved } from "@motionscript/sdk"
|
|
16
2
|
|
|
17
3
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
text,
|
|
27
|
-
type LegendConfig,
|
|
28
|
-
type LegendTheme,
|
|
29
|
-
} from "../kit/shared"
|
|
4
|
+
CHART_COLORS,
|
|
5
|
+
CHART_LEGEND,
|
|
6
|
+
CHART_TEXT,
|
|
7
|
+
legendConfigOf,
|
|
8
|
+
type ChartStyleBase,
|
|
9
|
+
} from "../kit/style"
|
|
10
|
+
import { num, text, type LegendConfig } from "../kit/shared"
|
|
11
|
+
import { DEG, PIE_SPOTLIGHT_DIM, ringPoint, selectionFade, type CenterConfig, type PieSlice } from "../kit/polar"
|
|
30
12
|
|
|
31
|
-
|
|
32
|
-
export interface PieSlice {
|
|
33
|
-
/** Label and legend caption. */
|
|
34
|
-
category: string
|
|
35
|
-
/** The wedge covers `value / (sum of all values)`. */
|
|
36
|
-
value: number
|
|
37
|
-
/** Wedge and swatch paint. */
|
|
38
|
-
fill: Fill
|
|
39
|
-
}
|
|
13
|
+
export { DEG, PIE_SPOTLIGHT_DIM, ringPoint, selectionFade, type CenterConfig, type PieSlice }
|
|
40
14
|
|
|
41
15
|
/**
|
|
42
16
|
* One slice per row, painted from `palette` by row order (cycling). Paint comes
|
|
43
17
|
* from the palette, not the rows, because a pie's mark is a row where a line's
|
|
44
18
|
* colour belongs to a column; that lets a pie be fed a CSV of plain numbers.
|
|
45
19
|
*/
|
|
46
|
-
export function resolvePieSlices(
|
|
47
|
-
data: DataRecord[],
|
|
48
|
-
category: string,
|
|
49
|
-
value: string,
|
|
50
|
-
palette: Fill[]
|
|
51
|
-
): PieSlice[] {
|
|
20
|
+
export function resolvePieSlices(data: readonly Record<string, unknown>[], category: string, value: string, palette: readonly Fill[]): PieSlice[] {
|
|
52
21
|
return data.map((row, i) => ({
|
|
53
|
-
category: text(row, category),
|
|
54
|
-
value: num(row, value),
|
|
55
|
-
fill:
|
|
56
|
-
palette.length > 0 ? palette[i % palette.length] : ("white" as Fill),
|
|
22
|
+
category: text(row as never, category),
|
|
23
|
+
value: num(row as never, value),
|
|
24
|
+
fill: palette.length > 0 ? palette[i % palette.length] : ("white" as Fill),
|
|
57
25
|
}))
|
|
58
26
|
}
|
|
59
27
|
|
|
60
28
|
/** What a {@link PieChart}'s labels say. */
|
|
61
29
|
export type PieLabelMode =
|
|
62
|
-
/** Two lines, whose order flips with placement:
|
|
30
|
+
/** Two lines, whose order flips with placement: an outside label reads category over percentage, an inside label reads the percentage big over a small category. */
|
|
63
31
|
| "both"
|
|
64
32
|
| "category"
|
|
65
33
|
| "percent"
|
|
66
34
|
/** No labels and no leader lines. */
|
|
67
35
|
| "none"
|
|
68
36
|
|
|
69
|
-
/** `"inside"` centres the label in the wedge's band with no leader or gutter, so the ring draws bigger; `"
|
|
70
|
-
export type PieLabelPlacement = "inside" | "
|
|
71
|
-
|
|
72
|
-
export const DEG = Math.PI / 180
|
|
37
|
+
/** `"inside"` centres the label in the wedge's band with no leader or gutter, so the ring draws bigger; `"outside"` sets it on a leader, which a sliver too narrow for text needs. */
|
|
38
|
+
export type PieLabelPlacement = "inside" | "outside" | "none"
|
|
73
39
|
|
|
74
|
-
/**
|
|
75
|
-
* Opacity of a slice under the selection: 1 while nothing is out (`focus` is the
|
|
76
|
-
* most-grown pop) and for the selected slice itself, falling toward `dimOpacity`
|
|
77
|
-
* for the rest as the selection grows.
|
|
78
|
-
*/
|
|
79
|
-
export function selectionFade(focus: number, dimOpacity: number, pop: number): number {
|
|
80
|
-
if (focus <= 0) return 1
|
|
81
|
-
return 1 - (1 - clamp(dimOpacity, 0, 1)) * focus * (1 - pop)
|
|
82
|
-
}
|
|
83
40
|
|
|
84
41
|
/** A slice's plotted value: negatives and non-finite values count as 0. */
|
|
85
42
|
export function sliceValue(slice: PieSlice): number {
|
|
@@ -93,11 +50,6 @@ export function sliceTotal(slices: PieSlice[]): number {
|
|
|
93
50
|
return sum
|
|
94
51
|
}
|
|
95
52
|
|
|
96
|
-
/** The point at radius `r`, angle `a` on a ring about the origin in centred y-up space. Angles run clockwise from 12 o'clock. */
|
|
97
|
-
export function ringPoint(r: number, a: number): Vector2 {
|
|
98
|
-
return { x: r * Math.sin(a), y: r * Math.cos(a) }
|
|
99
|
-
}
|
|
100
|
-
|
|
101
53
|
/** One slice's resolved angular span on the ring. */
|
|
102
54
|
export interface PieArc {
|
|
103
55
|
/** Index of the slice in the source list. */
|
|
@@ -149,12 +101,7 @@ interface LabelSlot {
|
|
|
149
101
|
* cannot hold them all, the reverse pass wins and the crowding is shared evenly.
|
|
150
102
|
* Mutates each `y` and returns `slots` ordered top to bottom.
|
|
151
103
|
*/
|
|
152
|
-
export function relaxLabels<T extends LabelSlot>(
|
|
153
|
-
slots: T[],
|
|
154
|
-
minGap: number,
|
|
155
|
-
top: number,
|
|
156
|
-
bottom: number
|
|
157
|
-
): T[] {
|
|
104
|
+
export function relaxLabels<T extends LabelSlot>(slots: T[], minGap: number, top: number, bottom: number): T[] {
|
|
158
105
|
slots.sort((a, b) => b.ideal - a.ideal)
|
|
159
106
|
|
|
160
107
|
let ceiling = top
|
|
@@ -172,7 +119,7 @@ export function relaxLabels<T extends LabelSlot>(
|
|
|
172
119
|
return slots
|
|
173
120
|
}
|
|
174
121
|
|
|
175
|
-
/** The ring's geometry
|
|
122
|
+
/** The ring's geometry: everything about the wedges but their colour. */
|
|
176
123
|
export interface RingConfig {
|
|
177
124
|
/** Channel between adjacent slices in px, constant across the band (an angular gap would splay open toward the rim). */
|
|
178
125
|
gap: number
|
|
@@ -182,226 +129,81 @@ export interface RingConfig {
|
|
|
182
129
|
startAngle: number
|
|
183
130
|
/** How far a selected slice's rim reaches, as a multiple of the outer radius so the emphasis scales with the chart. Clamped to `[1, 1.6]`. */
|
|
184
131
|
selectedGrow: number
|
|
185
|
-
|
|
186
|
-
|
|
132
|
+
/** Rounding of each wedge corner, px. */
|
|
133
|
+
cornerRadius: number
|
|
187
134
|
}
|
|
188
135
|
|
|
189
136
|
/** How the ring's labels are set, and the leader lines that point at them. */
|
|
190
137
|
export interface LabelConfig {
|
|
191
|
-
/** The category caption. */
|
|
138
|
+
/** The category caption outside the ring. */
|
|
192
139
|
textStyle: TextStyle
|
|
193
|
-
/** The percentage. */
|
|
140
|
+
/** The percentage outside the ring. */
|
|
194
141
|
percentStyle: TextStyle
|
|
195
|
-
/** Both lines of a label inside its wedge
|
|
142
|
+
/** Both lines of a label inside its wedge; its fill is set per wedge, for contrast against the paint. */
|
|
196
143
|
insideStyle: TextStyle
|
|
197
144
|
/** Runs from a wedge out to its label. */
|
|
198
145
|
leaderStroke: Stroke
|
|
199
146
|
}
|
|
200
147
|
|
|
201
|
-
/**
|
|
202
|
-
export interface
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
export type PieChartTheme = {
|
|
221
|
-
sliceFills?: Fill[]
|
|
222
|
-
ring?: Partial<RingConfig>
|
|
223
|
-
label?: Partial<LabelConfig>
|
|
224
|
-
center?: Partial<CenterConfig>
|
|
225
|
-
legend?: LegendTheme
|
|
226
|
-
spotlight?: Partial<PieChartConfig["spotlight"]>
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const LABEL_TEXT_STYLE: TextStyle = {
|
|
230
|
-
fontSize: 26,
|
|
231
|
-
fontWeight: 600,
|
|
232
|
-
textAlign: "center",
|
|
233
|
-
fill: CHART_PALETTE.markerColor,
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Fainter than `SPOTLIGHT_DIM`: a ring's slices touch, so at that a selected slice barely separates. */
|
|
237
|
-
export const PIE_SPOTLIGHT_DIM = 0.1
|
|
238
|
-
|
|
239
|
-
export const DEFAULT_PIE_CHART_THEME: PieChartConfig = {
|
|
240
|
-
sliceFills: DEFAULT_SERIES_FILLS,
|
|
241
|
-
ring: {
|
|
242
|
-
gap: 6,
|
|
243
|
-
// A donut by default: the hole is the one place a conclusion can be set.
|
|
244
|
-
holeRadius: 0.6,
|
|
245
|
-
startAngle: 0,
|
|
246
|
-
selectedGrow: 1.08,
|
|
247
|
-
stroke: [],
|
|
248
|
-
shadow: [],
|
|
148
|
+
/** What a pie's `style` resolves to. */
|
|
149
|
+
export interface PieStyle extends ChartStyleBase {
|
|
150
|
+
readonly innerRadius: number
|
|
151
|
+
readonly sliceGap: number
|
|
152
|
+
readonly sliceRadius: number
|
|
153
|
+
readonly labelPlacement: PieLabelPlacement
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The groups of a pie's `style`: no grid, as nothing is ruled. */
|
|
157
|
+
export const PIE_STYLE_GROUPS = {
|
|
158
|
+
colors: CHART_COLORS,
|
|
159
|
+
text: CHART_TEXT,
|
|
160
|
+
marks: {
|
|
161
|
+
/** Hole radius as a fraction of the outer radius: 0 is a pie, about 0.6 a donut. */
|
|
162
|
+
innerRadius: Types.number(0, { min: 0, max: 0.9, step: 0.05 }),
|
|
163
|
+
/** Channel between neighbouring wedges, px. */
|
|
164
|
+
sliceGap: Types.number(3, { min: 0, max: 40, step: 1, unit: "px" }),
|
|
165
|
+
/** Rounding of each wedge corner, px. */
|
|
166
|
+
sliceRadius: Types.number(4, { min: 0, max: 60, step: 1, unit: "px" }),
|
|
249
167
|
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
// On a mid-tone wedge, so the panel colour rather than the axis ink.
|
|
254
|
-
insideStyle: { ...LABEL_TEXT_STYLE, fontWeight: 800, fill: "#15130e" },
|
|
255
|
-
leaderStroke: { weight: 2, fill: CHART_PALETTE.markerColor },
|
|
256
|
-
},
|
|
257
|
-
center: {
|
|
258
|
-
labelStyle: {
|
|
259
|
-
fontSize: 46,
|
|
260
|
-
fontWeight: 800,
|
|
261
|
-
textAlign: "center",
|
|
262
|
-
fill: CHART_PALETTE.markerColor,
|
|
263
|
-
},
|
|
264
|
-
captionStyle: {
|
|
265
|
-
fontSize: 22,
|
|
266
|
-
fontWeight: 500,
|
|
267
|
-
textAlign: "center",
|
|
268
|
-
fill: CHART_PALETTE.markerColor,
|
|
269
|
-
},
|
|
168
|
+
labels: {
|
|
169
|
+
/** Read as the chart is built: inside the wedge, outside on a leader, or none. */
|
|
170
|
+
labelPlacement: Types.oneOf(["inside", "outside", "none"] as const, { animatable: false }),
|
|
270
171
|
},
|
|
271
|
-
legend:
|
|
272
|
-
spotlight: { dimOpacity: PIE_SPOTLIGHT_DIM },
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function resolveRingConfig(
|
|
276
|
-
ring: Partial<RingConfig> | undefined,
|
|
277
|
-
previous: RingConfig
|
|
278
|
-
): RingConfig {
|
|
279
|
-
return {
|
|
280
|
-
gap: ring?.gap ?? previous.gap,
|
|
281
|
-
holeRadius: ring?.holeRadius ?? previous.holeRadius,
|
|
282
|
-
startAngle: ring?.startAngle ?? previous.startAngle,
|
|
283
|
-
selectedGrow: ring?.selectedGrow ?? previous.selectedGrow,
|
|
284
|
-
stroke: strokeOps.resolve(ring?.stroke ?? previous.stroke),
|
|
285
|
-
shadow: shadowOps.resolve(ring?.shadow ?? previous.shadow),
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function lerpRingConfig(
|
|
290
|
-
from: RingConfig,
|
|
291
|
-
to: RingConfig,
|
|
292
|
-
t: number
|
|
293
|
-
): RingConfig {
|
|
294
|
-
return {
|
|
295
|
-
gap: lerpNumber(from.gap, to.gap, t),
|
|
296
|
-
holeRadius: lerpNumber(from.holeRadius, to.holeRadius, t),
|
|
297
|
-
startAngle: lerpNumber(from.startAngle, to.startAngle, t),
|
|
298
|
-
selectedGrow: lerpNumber(from.selectedGrow, to.selectedGrow, t),
|
|
299
|
-
stroke: strokeOps.lerp(
|
|
300
|
-
from.stroke as StrokeResolved[],
|
|
301
|
-
to.stroke as StrokeResolved[],
|
|
302
|
-
t
|
|
303
|
-
),
|
|
304
|
-
shadow: shadowOps.lerp(
|
|
305
|
-
from.shadow as ShadowResolved[],
|
|
306
|
-
to.shadow as ShadowResolved[],
|
|
307
|
-
t
|
|
308
|
-
),
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function resolveLabelConfig(
|
|
313
|
-
label: Partial<LabelConfig> | undefined,
|
|
314
|
-
previous: LabelConfig
|
|
315
|
-
): LabelConfig {
|
|
316
|
-
return {
|
|
317
|
-
textStyle: textOps.resolveStyle(label?.textStyle, previous.textStyle),
|
|
318
|
-
percentStyle: textOps.resolveStyle(
|
|
319
|
-
label?.percentStyle,
|
|
320
|
-
previous.percentStyle
|
|
321
|
-
),
|
|
322
|
-
insideStyle: textOps.resolveStyle(label?.insideStyle, previous.insideStyle),
|
|
323
|
-
leaderStroke: strokeOps.resolve(
|
|
324
|
-
label?.leaderStroke ?? previous.leaderStroke
|
|
325
|
-
),
|
|
326
|
-
}
|
|
172
|
+
legend: CHART_LEGEND,
|
|
327
173
|
}
|
|
328
174
|
|
|
329
|
-
function
|
|
330
|
-
|
|
331
|
-
to: LabelConfig,
|
|
332
|
-
t: number
|
|
333
|
-
): LabelConfig {
|
|
334
|
-
return {
|
|
335
|
-
textStyle: textOps.lerpStyle(from.textStyle, to.textStyle, t),
|
|
336
|
-
percentStyle: textOps.lerpStyle(from.percentStyle, to.percentStyle, t),
|
|
337
|
-
insideStyle: textOps.lerpStyle(from.insideStyle, to.insideStyle, t),
|
|
338
|
-
leaderStroke: strokeOps.lerp(
|
|
339
|
-
from.leaderStroke as StrokeResolved[],
|
|
340
|
-
to.leaderStroke as StrokeResolved[],
|
|
341
|
-
t
|
|
342
|
-
),
|
|
343
|
-
}
|
|
175
|
+
export function legendOf(style: PieStyle): LegendConfig {
|
|
176
|
+
return legendConfigOf(style)
|
|
344
177
|
}
|
|
345
178
|
|
|
346
|
-
function
|
|
347
|
-
|
|
348
|
-
previous: CenterConfig
|
|
349
|
-
): CenterConfig {
|
|
350
|
-
return {
|
|
351
|
-
labelStyle: textOps.resolveStyle(center?.labelStyle, previous.labelStyle),
|
|
352
|
-
captionStyle: textOps.resolveStyle(
|
|
353
|
-
center?.captionStyle,
|
|
354
|
-
previous.captionStyle
|
|
355
|
-
),
|
|
356
|
-
}
|
|
179
|
+
function face(style: PieStyle): Pick<TextStyle, "fontFamily"> {
|
|
180
|
+
return style.fontFamily ? { fontFamily: style.fontFamily } : {}
|
|
357
181
|
}
|
|
358
182
|
|
|
359
|
-
function
|
|
360
|
-
|
|
361
|
-
to: CenterConfig,
|
|
362
|
-
t: number
|
|
363
|
-
): CenterConfig {
|
|
364
|
-
return {
|
|
365
|
-
labelStyle: textOps.lerpStyle(from.labelStyle, to.labelStyle, t),
|
|
366
|
-
captionStyle: textOps.lerpStyle(from.captionStyle, to.captionStyle, t),
|
|
367
|
-
}
|
|
183
|
+
export function ringConfigOf(style: PieStyle): RingConfig {
|
|
184
|
+
return { gap: style.sliceGap, holeRadius: style.innerRadius, startAngle: 0, selectedGrow: 1.08, cornerRadius: style.sliceRadius }
|
|
368
185
|
}
|
|
369
186
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
previous?: PieChartConfig
|
|
374
|
-
): PieChartConfig {
|
|
375
|
-
const base = previous ?? DEFAULT_PIE_CHART_THEME
|
|
187
|
+
export function labelConfigOf(style: PieStyle): LabelConfig {
|
|
188
|
+
const base: TextStyle = { ...face(style), fontSize: style.fontSize, fontWeight: style.fontWeight, textAlign: "center", fill: style.muted }
|
|
189
|
+
const bold = Math.min(900, style.fontWeight + 200)
|
|
376
190
|
return {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
legend: resolveLegendConfig(theme?.legend, base.legend),
|
|
382
|
-
spotlight: {
|
|
383
|
-
dimOpacity: theme?.spotlight?.dimOpacity ?? base.spotlight.dimOpacity,
|
|
384
|
-
},
|
|
191
|
+
textStyle: base,
|
|
192
|
+
percentStyle: { ...base, fontWeight: bold, fill: style.foreground },
|
|
193
|
+
insideStyle: { ...base, fontSize: Math.round(style.fontSize * 1.9), fontWeight: bold, fill: "#111113" },
|
|
194
|
+
leaderStroke: { weight: 2, fill: style.muted },
|
|
385
195
|
}
|
|
386
196
|
}
|
|
387
197
|
|
|
388
|
-
export function
|
|
389
|
-
from: PieChartConfig,
|
|
390
|
-
to: PieChartConfig,
|
|
391
|
-
t: number
|
|
392
|
-
): PieChartConfig {
|
|
198
|
+
export function centerConfigOf(style: PieStyle): CenterConfig {
|
|
393
199
|
return {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
dimOpacity: lerpNumber(
|
|
401
|
-
from.spotlight.dimOpacity,
|
|
402
|
-
to.spotlight.dimOpacity,
|
|
403
|
-
t
|
|
404
|
-
),
|
|
200
|
+
labelStyle: {
|
|
201
|
+
...face(style),
|
|
202
|
+
fontSize: Math.round(style.fontSize * 1.8),
|
|
203
|
+
fontWeight: Math.min(900, style.fontWeight + 300),
|
|
204
|
+
textAlign: "center",
|
|
205
|
+
fill: style.foreground,
|
|
405
206
|
},
|
|
207
|
+
captionStyle: { ...face(style), fontSize: Math.round(style.fontSize * 0.8), fontWeight: style.fontWeight, textAlign: "center", fill: style.muted },
|
|
406
208
|
}
|
|
407
209
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { RadarChart, radarFractions, radarScale, type RadarValues } from "./radar-chart"
|
|
2
|
+
export { RadarGrid } from "./radar-grid"
|
|
3
|
+
export { RadarSeries, seriesVertices } from "./radar-series"
|
|
4
|
+
export { RADAR_GRID, RADAR_MARKS, fitRadius, niceCeil, spokeDirection } from "./shared"
|