@redvars/peacock 3.16.0 → 3.17.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.
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.js +19 -19
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/card-content.js +8 -7
- package/dist/card-content.js.map +1 -1
- package/dist/card.js +142 -98
- package/dist/card.js.map +1 -1
- package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
- package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
- package/dist/chart-area.js +78 -0
- package/dist/chart-area.js.map +1 -0
- package/dist/chart-bar.js +283 -213
- package/dist/chart-bar.js.map +1 -1
- package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
- package/dist/chart-base-C2qRMF48.js.map +1 -0
- package/dist/chart-doughnut.js +55 -287
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +626 -0
- package/dist/chart-line.js.map +1 -0
- package/dist/chart-pie.js +637 -195
- package/dist/chart-pie.js.map +1 -1
- package/dist/code-editor.js +704 -131
- package/dist/code-editor.js.map +1 -1
- package/dist/code-group.js +188 -0
- package/dist/code-group.js.map +1 -0
- package/dist/code-highlighter.js +895 -257
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +1675 -222
- package/dist/custom-elements.json +13351 -3970
- package/dist/image.js +5 -1
- package/dist/image.js.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/loader-full.js +1 -1
- package/dist/loader.js +9 -3
- package/dist/loader.js.map +1 -1
- package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
- package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
- package/dist/path-CJ0Arqcy.js +166 -0
- package/dist/path-CJ0Arqcy.js.map +1 -0
- package/dist/snackbar.js +89 -34
- package/dist/snackbar.js.map +1 -1
- package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
- package/dist/src/__internal/chart/chart-base.d.ts +113 -0
- package/dist/src/__internal/chart/paths.d.ts +5 -0
- package/dist/src/__internal/chart/types.d.ts +42 -0
- package/dist/src/card/card-content.d.ts +2 -3
- package/dist/src/card/card.d.ts +31 -17
- package/dist/src/chart-area/chart-area.d.ts +54 -0
- package/dist/src/chart-area/index.d.ts +1 -0
- package/dist/src/chart-bar/chart-bar.d.ts +44 -33
- package/dist/src/chart-bar/index.d.ts +0 -1
- package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
- package/dist/src/chart-line/chart-line.d.ts +69 -0
- package/dist/src/chart-line/index.d.ts +1 -0
- package/dist/src/chart-pie/chart-pie.d.ts +63 -28
- package/dist/src/code-editor/code-editor.d.ts +52 -13
- package/dist/src/code-editor/editor-theme.d.ts +60 -0
- package/dist/src/code-highlighter/code-group.d.ts +52 -0
- package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
- package/dist/src/code-highlighter/index.d.ts +1 -0
- package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
- package/dist/src/code-highlighter/local.d.ts +4 -1
- package/dist/src/code-highlighter/token-colors.d.ts +8 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/snackbar/snackbar.d.ts +13 -1
- package/dist/src/toolbar/toolbar.d.ts +56 -51
- package/dist/table.js +9 -4
- package/dist/table.js.map +1 -1
- package/dist/test/chart.test.d.ts +1 -0
- package/dist/test/code-highlighter.test.d.ts +1 -0
- package/dist/token-colors-0TFHWbcq.js +81 -0
- package/dist/token-colors-0TFHWbcq.js.map +1 -0
- package/dist/toolbar.js +195 -184
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/readme.md +7 -6
- package/scss/_code-block.scss +139 -0
- package/scss/tokens.css +24 -0
- package/src/__internal/chart/cartesian-chart.ts +404 -0
- package/src/__internal/chart/chart-base.scss +252 -0
- package/src/__internal/chart/chart-base.ts +474 -0
- package/src/__internal/chart/paths.ts +28 -0
- package/src/__internal/chart/types.ts +49 -0
- package/src/card/card-content.ts +12 -9
- package/src/card/card.scss +66 -54
- package/src/card/card.ts +109 -73
- package/src/chart-area/chart-area.ts +82 -0
- package/src/chart-area/index.ts +1 -0
- package/src/chart-bar/chart-bar.ts +336 -250
- package/src/chart-bar/index.ts +0 -1
- package/src/chart-doughnut/chart-doughnut.ts +62 -262
- package/src/chart-doughnut/demo/index.html +14 -22
- package/src/chart-line/chart-line.scss +25 -0
- package/src/chart-line/chart-line.ts +346 -0
- package/src/chart-line/index.ts +1 -0
- package/src/chart-pie/chart-pie.scss +35 -16
- package/src/chart-pie/chart-pie.ts +282 -188
- package/src/chart-pie/demo/index.html +13 -21
- package/src/code-editor/code-editor.scss +132 -36
- package/src/code-editor/code-editor.ts +308 -88
- package/src/code-editor/demo/index.html +39 -12
- package/src/code-editor/editor-theme.ts +213 -0
- package/src/code-highlighter/code-group.scss +34 -0
- package/src/code-highlighter/code-group.ts +173 -0
- package/src/code-highlighter/code-highlighter.scss +226 -111
- package/src/code-highlighter/code-highlighter.ts +554 -199
- package/src/code-highlighter/demo/index.html +68 -4
- package/src/code-highlighter/index.ts +1 -0
- package/src/code-highlighter/line-ranges.ts +81 -0
- package/src/code-highlighter/local.ts +9 -3
- package/src/code-highlighter/token-colors.ts +42 -0
- package/src/index.ts +4 -2
- package/src/loader.ts +8 -2
- package/src/snackbar/demo/index.html +39 -4
- package/src/snackbar/snackbar.scss +27 -10
- package/src/snackbar/snackbar.ts +80 -37
- package/src/table/table.scss +7 -1
- package/src/table/table.ts +4 -3
- package/src/toolbar/toolbar-colors.scss +6 -7
- package/src/toolbar/toolbar.scss +35 -106
- package/src/toolbar/toolbar.ts +180 -80
- package/dist/array-D5vjT2Xm.js +0 -14
- package/dist/array-D5vjT2Xm.js.map +0 -1
- package/dist/chart-bar-D5dGFJfK.js.map +0 -1
- package/dist/chart-stacked-bar.js +0 -403
- package/dist/chart-stacked-bar.js.map +0 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
- package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
- package/dist/pie-Dz0IDiPt.js +0 -537
- package/dist/pie-Dz0IDiPt.js.map +0 -1
- package/dist/pierre-dark-DFWl0m-C.js +0 -4
- package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
- package/dist/pierre-light-BEkAPImt.js +0 -4
- package/dist/pierre-light-BEkAPImt.js.map +0 -1
- package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
- package/dist/src/code-highlighter/constants.d.ts +0 -1
- package/dist/transform-DSwFSqzD.js.map +0 -1
- package/src/chart-bar/chart-bar.scss +0 -58
- package/src/chart-bar/chart-stacked-bar.ts +0 -398
- package/src/chart-doughnut/chart-donut.scss +0 -37
- package/src/code-highlighter/constants.ts +0 -117
- /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
package/dist/chart-pie.js
CHANGED
|
@@ -1,265 +1,707 @@
|
|
|
1
|
-
import { i, _ as __decorate, I as IndividualComponent,
|
|
1
|
+
import { i, _ as __decorate, I as IndividualComponent, b, w } from './IndividualComponent-Bdwyrvd6.js';
|
|
2
2
|
import { n } from './property-B49QQ8pS.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { o } from './style-map-BQD5Et1D.js';
|
|
4
|
+
import { a as constant, b as array, c as css_248z$1, C as ChartBase, d as chartColor, s as select, e as cubicOut, i as interpolate } from './chart-base-C2qRMF48.js';
|
|
5
|
+
import { w as withPath } from './path-CJ0Arqcy.js';
|
|
6
|
+
import './directive-ZPhl09Yt.js';
|
|
7
|
+
import './state-DkTK9EGF.js';
|
|
8
|
+
import './query-CHb9Ft_d.js';
|
|
6
9
|
import './base-Cl6v8-BZ.js';
|
|
7
|
-
import './
|
|
10
|
+
import './class-map-DG7CA1et.js';
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const abs = Math.abs;
|
|
13
|
+
const atan2 = Math.atan2;
|
|
14
|
+
const cos = Math.cos;
|
|
15
|
+
const max = Math.max;
|
|
16
|
+
const min = Math.min;
|
|
17
|
+
const sin = Math.sin;
|
|
18
|
+
const sqrt = Math.sqrt;
|
|
19
|
+
|
|
20
|
+
const epsilon = 1e-12;
|
|
21
|
+
const pi = Math.PI;
|
|
22
|
+
const halfPi = pi / 2;
|
|
23
|
+
const tau = 2 * pi;
|
|
24
|
+
|
|
25
|
+
function acos(x) {
|
|
26
|
+
return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function asin(x) {
|
|
30
|
+
return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function arcInnerRadius(d) {
|
|
34
|
+
return d.innerRadius;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function arcOuterRadius(d) {
|
|
38
|
+
return d.outerRadius;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function arcStartAngle(d) {
|
|
42
|
+
return d.startAngle;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function arcEndAngle(d) {
|
|
46
|
+
return d.endAngle;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function arcPadAngle(d) {
|
|
50
|
+
return d && d.padAngle; // Note: optional!
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
|
54
|
+
var x10 = x1 - x0, y10 = y1 - y0,
|
|
55
|
+
x32 = x3 - x2, y32 = y3 - y2,
|
|
56
|
+
t = y32 * x10 - x32 * y10;
|
|
57
|
+
if (t * t < epsilon) return;
|
|
58
|
+
t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
|
|
59
|
+
return [x0 + t * x10, y0 + t * y10];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Compute perpendicular offset line of length rc.
|
|
63
|
+
// http://mathworld.wolfram.com/Circle-LineIntersection.html
|
|
64
|
+
function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
|
|
65
|
+
var x01 = x0 - x1,
|
|
66
|
+
y01 = y0 - y1,
|
|
67
|
+
lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
|
|
68
|
+
ox = lo * y01,
|
|
69
|
+
oy = -lo * x01,
|
|
70
|
+
x11 = x0 + ox,
|
|
71
|
+
y11 = y0 + oy,
|
|
72
|
+
x10 = x1 + ox,
|
|
73
|
+
y10 = y1 + oy,
|
|
74
|
+
x00 = (x11 + x10) / 2,
|
|
75
|
+
y00 = (y11 + y10) / 2,
|
|
76
|
+
dx = x10 - x11,
|
|
77
|
+
dy = y10 - y11,
|
|
78
|
+
d2 = dx * dx + dy * dy,
|
|
79
|
+
r = r1 - rc,
|
|
80
|
+
D = x11 * y10 - x10 * y11,
|
|
81
|
+
d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
|
|
82
|
+
cx0 = (D * dy - dx * d) / d2,
|
|
83
|
+
cy0 = (-D * dx - dy * d) / d2,
|
|
84
|
+
cx1 = (D * dy + dx * d) / d2,
|
|
85
|
+
cy1 = (-D * dx + dy * d) / d2,
|
|
86
|
+
dx0 = cx0 - x00,
|
|
87
|
+
dy0 = cy0 - y00,
|
|
88
|
+
dx1 = cx1 - x00,
|
|
89
|
+
dy1 = cy1 - y00;
|
|
90
|
+
|
|
91
|
+
// Pick the closer of the two intersection points.
|
|
92
|
+
// TODO Is there a faster way to determine which intersection to use?
|
|
93
|
+
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
cx: cx0,
|
|
97
|
+
cy: cy0,
|
|
98
|
+
x01: -ox,
|
|
99
|
+
y01: -oy,
|
|
100
|
+
x11: cx0 * (r1 / r - 1),
|
|
101
|
+
y11: cy0 * (r1 / r - 1)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function arc() {
|
|
106
|
+
var innerRadius = arcInnerRadius,
|
|
107
|
+
outerRadius = arcOuterRadius,
|
|
108
|
+
cornerRadius = constant(0),
|
|
109
|
+
padRadius = null,
|
|
110
|
+
startAngle = arcStartAngle,
|
|
111
|
+
endAngle = arcEndAngle,
|
|
112
|
+
padAngle = arcPadAngle,
|
|
113
|
+
context = null,
|
|
114
|
+
path = withPath(arc);
|
|
115
|
+
|
|
116
|
+
function arc() {
|
|
117
|
+
var buffer,
|
|
118
|
+
r,
|
|
119
|
+
r0 = +innerRadius.apply(this, arguments),
|
|
120
|
+
r1 = +outerRadius.apply(this, arguments),
|
|
121
|
+
a0 = startAngle.apply(this, arguments) - halfPi,
|
|
122
|
+
a1 = endAngle.apply(this, arguments) - halfPi,
|
|
123
|
+
da = abs(a1 - a0),
|
|
124
|
+
cw = a1 > a0;
|
|
125
|
+
|
|
126
|
+
if (!context) context = buffer = path();
|
|
127
|
+
|
|
128
|
+
// Ensure that the outer radius is always larger than the inner radius.
|
|
129
|
+
if (r1 < r0) r = r1, r1 = r0, r0 = r;
|
|
130
|
+
|
|
131
|
+
// Is it a point?
|
|
132
|
+
if (!(r1 > epsilon)) context.moveTo(0, 0);
|
|
133
|
+
|
|
134
|
+
// Or is it a circle or annulus?
|
|
135
|
+
else if (da > tau - epsilon) {
|
|
136
|
+
context.moveTo(r1 * cos(a0), r1 * sin(a0));
|
|
137
|
+
context.arc(0, 0, r1, a0, a1, !cw);
|
|
138
|
+
if (r0 > epsilon) {
|
|
139
|
+
context.moveTo(r0 * cos(a1), r0 * sin(a1));
|
|
140
|
+
context.arc(0, 0, r0, a1, a0, cw);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Or is it a circular or annular sector?
|
|
145
|
+
else {
|
|
146
|
+
var a01 = a0,
|
|
147
|
+
a11 = a1,
|
|
148
|
+
a00 = a0,
|
|
149
|
+
a10 = a1,
|
|
150
|
+
da0 = da,
|
|
151
|
+
da1 = da,
|
|
152
|
+
ap = padAngle.apply(this, arguments) / 2,
|
|
153
|
+
rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
|
|
154
|
+
rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
|
|
155
|
+
rc0 = rc,
|
|
156
|
+
rc1 = rc,
|
|
157
|
+
t0,
|
|
158
|
+
t1;
|
|
159
|
+
|
|
160
|
+
// Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
|
|
161
|
+
if (rp > epsilon) {
|
|
162
|
+
var p0 = asin(rp / r0 * sin(ap)),
|
|
163
|
+
p1 = asin(rp / r1 * sin(ap));
|
|
164
|
+
if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
|
|
165
|
+
else da0 = 0, a00 = a10 = (a0 + a1) / 2;
|
|
166
|
+
if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
|
|
167
|
+
else da1 = 0, a01 = a11 = (a0 + a1) / 2;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var x01 = r1 * cos(a01),
|
|
171
|
+
y01 = r1 * sin(a01),
|
|
172
|
+
x10 = r0 * cos(a10),
|
|
173
|
+
y10 = r0 * sin(a10);
|
|
174
|
+
|
|
175
|
+
// Apply rounded corners?
|
|
176
|
+
if (rc > epsilon) {
|
|
177
|
+
var x11 = r1 * cos(a11),
|
|
178
|
+
y11 = r1 * sin(a11),
|
|
179
|
+
x00 = r0 * cos(a00),
|
|
180
|
+
y00 = r0 * sin(a00),
|
|
181
|
+
oc;
|
|
182
|
+
|
|
183
|
+
// Restrict the corner radius according to the sector angle. If this
|
|
184
|
+
// intersection fails, it’s probably because the arc is too small, so
|
|
185
|
+
// disable the corner radius entirely.
|
|
186
|
+
if (da < pi) {
|
|
187
|
+
if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
|
|
188
|
+
var ax = x01 - oc[0],
|
|
189
|
+
ay = y01 - oc[1],
|
|
190
|
+
bx = x11 - oc[0],
|
|
191
|
+
by = y11 - oc[1],
|
|
192
|
+
kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
|
|
193
|
+
lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
|
|
194
|
+
rc0 = min(rc, (r0 - lc) / (kc - 1));
|
|
195
|
+
rc1 = min(rc, (r1 - lc) / (kc + 1));
|
|
196
|
+
} else {
|
|
197
|
+
rc0 = rc1 = 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Is the sector collapsed to a line?
|
|
203
|
+
if (!(da1 > epsilon)) context.moveTo(x01, y01);
|
|
204
|
+
|
|
205
|
+
// Does the sector’s outer ring have rounded corners?
|
|
206
|
+
else if (rc1 > epsilon) {
|
|
207
|
+
t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
|
208
|
+
t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
|
209
|
+
|
|
210
|
+
context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
|
211
|
+
|
|
212
|
+
// Have the corners merged?
|
|
213
|
+
if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
|
214
|
+
|
|
215
|
+
// Otherwise, draw the two corners and the ring.
|
|
216
|
+
else {
|
|
217
|
+
context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
|
218
|
+
context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
|
|
219
|
+
context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Or is the outer ring just a circular arc?
|
|
224
|
+
else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
|
|
225
|
+
|
|
226
|
+
// Is there no inner ring, and it’s a circular sector?
|
|
227
|
+
// Or perhaps it’s an annular sector collapsed due to padding?
|
|
228
|
+
if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
|
|
229
|
+
|
|
230
|
+
// Does the sector’s inner ring (or point) have rounded corners?
|
|
231
|
+
else if (rc0 > epsilon) {
|
|
232
|
+
t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
|
233
|
+
t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
|
234
|
+
|
|
235
|
+
context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
|
236
|
+
|
|
237
|
+
// Have the corners merged?
|
|
238
|
+
if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
|
239
|
+
|
|
240
|
+
// Otherwise, draw the two corners and the ring.
|
|
241
|
+
else {
|
|
242
|
+
context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
|
243
|
+
context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
|
|
244
|
+
context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Or is the inner ring just a circular arc?
|
|
249
|
+
else context.arc(0, 0, r0, a10, a00, cw);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
context.closePath();
|
|
253
|
+
|
|
254
|
+
if (buffer) return context = null, buffer + "" || null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
arc.centroid = function() {
|
|
258
|
+
var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
|
|
259
|
+
a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
|
|
260
|
+
return [cos(a) * r, sin(a) * r];
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
arc.innerRadius = function(_) {
|
|
264
|
+
return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant(+_), arc) : innerRadius;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
arc.outerRadius = function(_) {
|
|
268
|
+
return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant(+_), arc) : outerRadius;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
arc.cornerRadius = function(_) {
|
|
272
|
+
return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant(+_), arc) : cornerRadius;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
arc.padRadius = function(_) {
|
|
276
|
+
return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant(+_), arc) : padRadius;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
arc.startAngle = function(_) {
|
|
280
|
+
return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), arc) : startAngle;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
arc.endAngle = function(_) {
|
|
284
|
+
return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), arc) : endAngle;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
arc.padAngle = function(_) {
|
|
288
|
+
return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), arc) : padAngle;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
arc.context = function(_) {
|
|
292
|
+
return arguments.length ? ((context = _ == null ? null : _), arc) : context;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
return arc;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function descending(a, b) {
|
|
299
|
+
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
|
12
300
|
}
|
|
13
301
|
|
|
14
|
-
|
|
15
|
-
|
|
302
|
+
function identity(d) {
|
|
303
|
+
return d;
|
|
16
304
|
}
|
|
17
305
|
|
|
18
|
-
|
|
19
|
-
|
|
306
|
+
function pie() {
|
|
307
|
+
var value = identity,
|
|
308
|
+
sortValues = descending,
|
|
309
|
+
sort = null,
|
|
310
|
+
startAngle = constant(0),
|
|
311
|
+
endAngle = constant(tau),
|
|
312
|
+
padAngle = constant(0);
|
|
313
|
+
|
|
314
|
+
function pie(data) {
|
|
315
|
+
var i,
|
|
316
|
+
n = (data = array(data)).length,
|
|
317
|
+
j,
|
|
318
|
+
k,
|
|
319
|
+
sum = 0,
|
|
320
|
+
index = new Array(n),
|
|
321
|
+
arcs = new Array(n),
|
|
322
|
+
a0 = +startAngle.apply(this, arguments),
|
|
323
|
+
da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
|
|
324
|
+
a1,
|
|
325
|
+
p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
|
|
326
|
+
pa = p * (da < 0 ? -1 : 1),
|
|
327
|
+
v;
|
|
328
|
+
|
|
329
|
+
for (i = 0; i < n; ++i) {
|
|
330
|
+
if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
|
|
331
|
+
sum += v;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Optionally sort the arcs by previously-computed values or by data.
|
|
336
|
+
if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
|
|
337
|
+
else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
|
|
338
|
+
|
|
339
|
+
// Compute the arcs! They are stored in the original data's order.
|
|
340
|
+
for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
|
|
341
|
+
j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
|
|
342
|
+
data: data[j],
|
|
343
|
+
index: i,
|
|
344
|
+
value: v,
|
|
345
|
+
startAngle: a0,
|
|
346
|
+
endAngle: a1,
|
|
347
|
+
padAngle: p
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return arcs;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
pie.value = function(_) {
|
|
355
|
+
return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), pie) : value;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
pie.sortValues = function(_) {
|
|
359
|
+
return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
pie.sort = function(_) {
|
|
363
|
+
return arguments.length ? (sort = _, sortValues = null, pie) : sort;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
pie.startAngle = function(_) {
|
|
367
|
+
return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), pie) : startAngle;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
pie.endAngle = function(_) {
|
|
371
|
+
return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), pie) : endAngle;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
pie.padAngle = function(_) {
|
|
375
|
+
return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), pie) : padAngle;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
return pie;
|
|
20
379
|
}
|
|
21
380
|
|
|
22
|
-
|
|
23
|
-
|
|
381
|
+
var css_248z = i`.slice {
|
|
382
|
+
stroke: none;
|
|
383
|
+
transition: opacity var(--duration-short3) var(--easing-standard), transform var(--duration-short4) var(--easing-emphasized-decelerate);
|
|
24
384
|
}
|
|
25
385
|
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
386
|
+
.slice-label {
|
|
387
|
+
font-family: var(--typography-label-medium-font-family) !important;
|
|
388
|
+
font-size: var(--typography-label-medium-font-size) !important;
|
|
389
|
+
font-weight: var(--typography-label-medium-font-weight) !important;
|
|
390
|
+
line-height: var(--typography-label-medium-line-height) !important;
|
|
391
|
+
letter-spacing: var(--typography-label-medium-letter-spacing) !important;
|
|
392
|
+
fill: var(--color-surface);
|
|
393
|
+
pointer-events: none;
|
|
29
394
|
}
|
|
30
|
-
|
|
31
|
-
|
|
395
|
+
|
|
396
|
+
.center {
|
|
397
|
+
position: absolute;
|
|
398
|
+
inset: 0;
|
|
399
|
+
display: flex;
|
|
400
|
+
flex-direction: column;
|
|
401
|
+
align-items: center;
|
|
402
|
+
justify-content: center;
|
|
403
|
+
pointer-events: none;
|
|
404
|
+
text-align: center;
|
|
32
405
|
}
|
|
33
406
|
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
407
|
+
.center-value {
|
|
408
|
+
font-family: var(--typography-headline-medium-font-family) !important;
|
|
409
|
+
font-size: var(--typography-headline-medium-font-size) !important;
|
|
410
|
+
font-weight: var(--typography-headline-medium-font-weight) !important;
|
|
411
|
+
line-height: var(--typography-headline-medium-line-height) !important;
|
|
412
|
+
letter-spacing: var(--typography-headline-medium-letter-spacing) !important;
|
|
413
|
+
color: var(--color-on-surface);
|
|
414
|
+
font-variant-numeric: tabular-nums;
|
|
38
415
|
}
|
|
39
416
|
|
|
40
|
-
.
|
|
41
|
-
fill: var(--color-on-surface);
|
|
417
|
+
.center-label {
|
|
42
418
|
font-family: var(--typography-label-medium-font-family) !important;
|
|
43
419
|
font-size: var(--typography-label-medium-font-size) !important;
|
|
44
420
|
font-weight: var(--typography-label-medium-font-weight) !important;
|
|
45
421
|
line-height: var(--typography-label-medium-line-height) !important;
|
|
46
422
|
letter-spacing: var(--typography-label-medium-letter-spacing) !important;
|
|
423
|
+
color: var(--color-on-surface-variant);
|
|
424
|
+
max-width: var(--_center-width, 8rem);
|
|
425
|
+
overflow: hidden;
|
|
426
|
+
text-overflow: ellipsis;
|
|
427
|
+
white-space: nowrap;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
@media (prefers-reduced-motion: reduce) {
|
|
431
|
+
.slice {
|
|
432
|
+
transition: none;
|
|
433
|
+
}
|
|
47
434
|
}`;
|
|
48
435
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
clearTimeout(timer);
|
|
59
|
-
timer = setTimeout(() => fn(...args), wait);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
436
|
+
const DURATION = 450;
|
|
437
|
+
/** Distance a hovered slice moves out from the centre. */
|
|
438
|
+
const PULL_OUT = 6;
|
|
439
|
+
/** Room around the pie for the hovered slice. */
|
|
440
|
+
const PADDING = PULL_OUT + 2;
|
|
441
|
+
/** Gap between slices, in pixels at the outer edge. */
|
|
442
|
+
const SLICE_GAP = 2;
|
|
443
|
+
/** Smallest slice angle that gets a percentage label. */
|
|
444
|
+
const MIN_LABEL_ANGLE = 0.35;
|
|
62
445
|
/**
|
|
63
|
-
* @label Chart
|
|
446
|
+
* @label Pie Chart
|
|
64
447
|
* @tag wc-chart-pie
|
|
65
448
|
* @rawTag chart-pie
|
|
66
|
-
* @summary
|
|
449
|
+
* @summary Shows how parts make up a whole. Best with a handful of slices.
|
|
67
450
|
* @tags charts
|
|
68
451
|
*
|
|
69
452
|
* @example
|
|
70
453
|
* ```html
|
|
71
|
-
* <wc-chart-pie
|
|
454
|
+
* <wc-chart-pie label="Visitors by browser"></wc-chart-pie>
|
|
72
455
|
* <script>
|
|
73
456
|
* document.querySelector('wc-chart-pie').data = [
|
|
74
|
-
* { name: '
|
|
75
|
-
* { name: '
|
|
76
|
-
* { name: '
|
|
457
|
+
* { name: 'chrome', label: 'Chrome', value: 275 },
|
|
458
|
+
* { name: 'safari', label: 'Safari', value: 200 },
|
|
459
|
+
* { name: 'firefox', label: 'Firefox', value: 187 },
|
|
77
460
|
* ];
|
|
78
461
|
* </script>
|
|
79
462
|
* ```
|
|
463
|
+
*
|
|
464
|
+
* @slot empty - Shown when there is no data. Defaults to "No data".
|
|
465
|
+
*
|
|
466
|
+
* @fires chart-select - A slice was clicked or chosen with Enter. `detail` holds `index`, `series` (the slice name) and `datum`.
|
|
467
|
+
*
|
|
468
|
+
* @csspart container - The outer wrapper.
|
|
469
|
+
* @csspart plot - The focusable plot area holding the SVG.
|
|
470
|
+
* @csspart tooltip - The tooltip.
|
|
471
|
+
* @csspart legend - The legend.
|
|
472
|
+
*
|
|
473
|
+
* @cssprop --color-chart-1 - Color of the first slice; slices cycle through `--color-chart-1` to `--color-chart-8`.
|
|
474
|
+
* @cssprop --chart-dim-opacity - Opacity of slices that are not hovered. Defaults to `0.4`.
|
|
80
475
|
*/
|
|
81
|
-
let ChartPie = class ChartPie extends
|
|
476
|
+
let ChartPie = class ChartPie extends ChartBase {
|
|
82
477
|
constructor() {
|
|
478
|
+
// ── Static
|
|
83
479
|
super(...arguments);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/** Margin around the chart. */
|
|
87
|
-
this.margin = 10;
|
|
88
|
-
/** Whether to show labels outside the chart. */
|
|
89
|
-
this.showLabels = true;
|
|
90
|
-
/** Chart data array. Each item should have name, value, and optional label and color. */
|
|
480
|
+
// ── Properties
|
|
481
|
+
/** Slices to draw. */
|
|
91
482
|
this.data = [];
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
|
|
483
|
+
/** Size of the hole as a fraction of the radius, from 0 (pie) to 0.9. */
|
|
484
|
+
this.innerRadius = 0;
|
|
485
|
+
/** Prints each slice's percentage inside it when it fits. */
|
|
486
|
+
this.showLabels = false;
|
|
487
|
+
// ── Private fields
|
|
488
|
+
/** Arcs from the last draw. */
|
|
489
|
+
this.arcs = [];
|
|
490
|
+
/** Outer radius from the last draw. */
|
|
491
|
+
this.radius = 0;
|
|
492
|
+
/** Pie centre from the last draw, in plot coordinates. */
|
|
493
|
+
this.center = { x: 0, y: 0 };
|
|
96
494
|
}
|
|
97
|
-
|
|
98
|
-
|
|
495
|
+
// ── Private methods
|
|
496
|
+
drawProperties() {
|
|
497
|
+
return [...super.drawProperties(), 'data', 'innerRadius', 'showLabels'];
|
|
99
498
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this._initialized = true;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const watchedProps = ['width', 'margin', 'showLabels', 'data'];
|
|
106
|
-
const hasChanged = watchedProps.some(prop => changedProperties.has(prop));
|
|
107
|
-
if (hasChanged) {
|
|
108
|
-
this._debouncedRenderChart();
|
|
109
|
-
}
|
|
499
|
+
hasData() {
|
|
500
|
+
return this.data.some(item => item.value > 0);
|
|
110
501
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
502
|
+
getSeries() {
|
|
503
|
+
return this.data.map((item, i) => ({
|
|
504
|
+
key: item.name,
|
|
505
|
+
label: item.label ?? item.name,
|
|
506
|
+
color: item.color ?? chartColor(i),
|
|
507
|
+
}));
|
|
114
508
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
509
|
+
legendVisible() {
|
|
510
|
+
return !this.hideLegend;
|
|
511
|
+
}
|
|
512
|
+
getItemCount() {
|
|
513
|
+
return this.data.length;
|
|
514
|
+
}
|
|
515
|
+
/** Sum of the visible slices. */
|
|
516
|
+
visibleTotal() {
|
|
517
|
+
return this.data
|
|
518
|
+
.filter(item => !this.isHidden(item.name))
|
|
519
|
+
.reduce((sum, item) => sum + Math.max(item.value, 0), 0);
|
|
120
520
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.
|
|
521
|
+
percent(value) {
|
|
522
|
+
const total = this.visibleTotal();
|
|
523
|
+
return total
|
|
524
|
+
? new Intl.NumberFormat(undefined, {
|
|
525
|
+
style: 'percent',
|
|
526
|
+
maximumFractionDigits: 1,
|
|
527
|
+
}).format(value / total)
|
|
528
|
+
: '';
|
|
125
529
|
}
|
|
126
|
-
|
|
530
|
+
innerFraction() {
|
|
531
|
+
return Math.min(Math.max(this.innerRadius || 0, 0), 0.9);
|
|
532
|
+
}
|
|
533
|
+
draw(animate) {
|
|
127
534
|
if (!this.svgElement)
|
|
128
535
|
return;
|
|
129
|
-
const
|
|
130
|
-
const radius =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
.
|
|
149
|
-
.
|
|
536
|
+
const { width, height } = this.svgSize();
|
|
537
|
+
const radius = Math.max(Math.min(width, height) / 2 - PADDING, 0);
|
|
538
|
+
this.radius = radius;
|
|
539
|
+
this.center = { x: width / 2, y: height / 2 };
|
|
540
|
+
const inner = radius * this.innerFraction();
|
|
541
|
+
const colors = new Map(this.getSeries().map(s => [s.key, s.color]));
|
|
542
|
+
const arcs = pie()
|
|
543
|
+
.sort(null)
|
|
544
|
+
.value(item => (this.isHidden(item.name) ? 0 : Math.max(item.value, 0)))
|
|
545
|
+
.padAngle(radius ? SLICE_GAP / radius : 0)(this.data);
|
|
546
|
+
this.arcs = arcs;
|
|
547
|
+
const sliceArc = arc()
|
|
548
|
+
.innerRadius(inner)
|
|
549
|
+
.outerRadius(radius)
|
|
550
|
+
.cornerRadius(Math.min(4, (radius - inner) / 4));
|
|
551
|
+
const root = select(this.svgElement)
|
|
552
|
+
.select('.pie')
|
|
553
|
+
.attr('transform', `translate(${this.center.x},${this.center.y})`);
|
|
554
|
+
const slices = root
|
|
555
|
+
.select('.slices')
|
|
556
|
+
.selectAll('path.slice')
|
|
557
|
+
.data(arcs, d => d.data.name)
|
|
150
558
|
.join('path')
|
|
151
|
-
.attr('class', '
|
|
152
|
-
.
|
|
559
|
+
.attr('class', 'slice mark')
|
|
560
|
+
.attr('data-key', d => d.data.name)
|
|
561
|
+
.style('fill', d => colors.get(d.data.name) ?? '');
|
|
153
562
|
if (animate) {
|
|
154
|
-
|
|
563
|
+
slices
|
|
155
564
|
.transition()
|
|
156
565
|
.duration(DURATION)
|
|
157
|
-
.ease(
|
|
566
|
+
.ease(cubicOut)
|
|
158
567
|
.attrTween('d', function (d) {
|
|
159
|
-
const
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
const prev = self._prevDatum ?? {
|
|
568
|
+
const el = this;
|
|
569
|
+
// New slices sweep open from their start angle.
|
|
570
|
+
const from = el.__current ?? {
|
|
163
571
|
startAngle: d.startAngle,
|
|
164
572
|
endAngle: d.startAngle,
|
|
165
573
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
574
|
+
const tween = interpolate(from, {
|
|
575
|
+
startAngle: d.startAngle,
|
|
576
|
+
endAngle: d.endAngle,
|
|
577
|
+
});
|
|
578
|
+
el.__current = { startAngle: d.startAngle, endAngle: d.endAngle };
|
|
579
|
+
return t => sliceArc({ ...tween(t), padAngle: d.padAngle }) ?? '';
|
|
170
580
|
});
|
|
171
581
|
}
|
|
172
582
|
else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// Label polylines and text
|
|
181
|
-
const $chartContainer = svg.select('.chart-container');
|
|
182
|
-
if (this.showLabels) {
|
|
183
|
-
const pointsFn = (d) => {
|
|
184
|
-
const posA = pieArc.centroid(d);
|
|
185
|
-
const posB = labelsArc.centroid(d);
|
|
186
|
-
const posC = posB.slice();
|
|
187
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
188
|
-
posC[0] = radius * (midAngle < Math.PI ? 1 : -1);
|
|
189
|
-
return [posA, posB, posC].map(p => p.join(',')).join(' ');
|
|
190
|
-
};
|
|
191
|
-
const transformFn = (d) => {
|
|
192
|
-
const pos = labelsArc.centroid(d);
|
|
193
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
194
|
-
pos[0] = radius * (midAngle < Math.PI ? 1 : -1);
|
|
195
|
-
return `translate(${pos})`;
|
|
196
|
-
};
|
|
197
|
-
const anchorFn = (d) => {
|
|
198
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
199
|
-
return midAngle < Math.PI ? 'start' : 'end';
|
|
200
|
-
};
|
|
201
|
-
const $polylines = $chartContainer
|
|
202
|
-
.selectAll('.item-polyline')
|
|
203
|
-
.data(pieData, d => d.data.name)
|
|
204
|
-
.join('polyline')
|
|
205
|
-
.attr('class', 'item-polyline');
|
|
206
|
-
const $labels = $chartContainer
|
|
207
|
-
.selectAll('.item-label')
|
|
208
|
-
.data(pieData, d => d.data.name)
|
|
209
|
-
.join('text')
|
|
210
|
-
.attr('class', 'item-label')
|
|
211
|
-
.text(d => d.data.label ?? '');
|
|
212
|
-
if (animate) {
|
|
213
|
-
$polylines
|
|
214
|
-
.transition()
|
|
215
|
-
.duration(DURATION)
|
|
216
|
-
.ease(cubicInOut)
|
|
217
|
-
.attr('points', pointsFn);
|
|
218
|
-
$labels
|
|
219
|
-
.transition()
|
|
220
|
-
.duration(DURATION)
|
|
221
|
-
.ease(cubicInOut)
|
|
222
|
-
.attr('transform', transformFn)
|
|
223
|
-
.style('text-anchor', anchorFn);
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
$polylines.attr('points', pointsFn);
|
|
227
|
-
$labels.attr('transform', transformFn).style('text-anchor', anchorFn);
|
|
228
|
-
}
|
|
583
|
+
slices.interrupt().each(function (d) {
|
|
584
|
+
this.__current = {
|
|
585
|
+
startAngle: d.startAngle,
|
|
586
|
+
endAngle: d.endAngle,
|
|
587
|
+
};
|
|
588
|
+
});
|
|
589
|
+
slices.attr('d', d => sliceArc(d) ?? '');
|
|
229
590
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
591
|
+
// Percentages inside slices big enough to hold them.
|
|
592
|
+
const labelArc = arc()
|
|
593
|
+
.innerRadius(inner + (radius - inner) / 2)
|
|
594
|
+
.outerRadius(inner + (radius - inner) / 2);
|
|
595
|
+
const labelled = this.showLabels
|
|
596
|
+
? arcs.filter(d => d.endAngle - d.startAngle >= MIN_LABEL_ANGLE)
|
|
597
|
+
: [];
|
|
598
|
+
root
|
|
599
|
+
.select('.slice-labels')
|
|
600
|
+
.selectAll('text')
|
|
601
|
+
.data(labelled, d => d.data.name)
|
|
602
|
+
.join('text')
|
|
603
|
+
.attr('class', 'slice-label')
|
|
604
|
+
.attr('text-anchor', 'middle')
|
|
605
|
+
.attr('dominant-baseline', 'middle')
|
|
606
|
+
.attr('transform', d => `translate(${labelArc.centroid(d)})`)
|
|
607
|
+
.text(d => this.percent(d.data.value));
|
|
608
|
+
}
|
|
609
|
+
drawHighlight() {
|
|
610
|
+
if (!this.svgElement)
|
|
611
|
+
return;
|
|
612
|
+
const { activeIndex, activeSeries } = this;
|
|
613
|
+
const activeName = activeIndex >= 0 ? this.data[activeIndex]?.name : activeSeries;
|
|
614
|
+
select(this.svgElement)
|
|
615
|
+
.select('.slices')
|
|
616
|
+
.selectAll('path.slice')
|
|
617
|
+
.classed('is-dimmed', d => activeName !== undefined && d.data.name !== activeName)
|
|
618
|
+
.style('transform', d => {
|
|
619
|
+
if (d.data.name !== activeName)
|
|
620
|
+
return 'translate(0px, 0px)';
|
|
621
|
+
const mid = (d.startAngle + d.endAngle) / 2;
|
|
622
|
+
return `translate(${Math.sin(mid) * PULL_OUT}px, ${-Math.cos(mid) * PULL_OUT}px)`;
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
itemAtPoint(x, y) {
|
|
626
|
+
const dx = x - this.center.x;
|
|
627
|
+
const dy = y - this.center.y;
|
|
628
|
+
const distance = Math.hypot(dx, dy);
|
|
629
|
+
if (distance > this.radius + PULL_OUT ||
|
|
630
|
+
distance < this.radius * this.innerFraction()) {
|
|
631
|
+
return -1;
|
|
233
632
|
}
|
|
633
|
+
let angle = Math.atan2(dx, -dy);
|
|
634
|
+
if (angle < 0)
|
|
635
|
+
angle += Math.PI * 2;
|
|
636
|
+
const hit = this.arcs.find(d => d.endAngle > d.startAngle &&
|
|
637
|
+
angle >= d.startAngle &&
|
|
638
|
+
angle < d.endAngle);
|
|
639
|
+
return hit ? hit.index : -1;
|
|
640
|
+
}
|
|
641
|
+
getTooltip(index) {
|
|
642
|
+
const item = this.data[index];
|
|
643
|
+
const slice = this.arcs.find(d => d.index === index);
|
|
644
|
+
if (!item || !slice || this.isHidden(item.name))
|
|
645
|
+
return undefined;
|
|
646
|
+
const mid = (slice.startAngle + slice.endAngle) / 2;
|
|
647
|
+
const reach = this.radius * 0.75;
|
|
648
|
+
return {
|
|
649
|
+
title: '',
|
|
650
|
+
rows: [
|
|
651
|
+
{
|
|
652
|
+
key: item.name,
|
|
653
|
+
label: item.label ?? item.name,
|
|
654
|
+
color: item.color ?? chartColor(index),
|
|
655
|
+
value: `${this.formatValue(item.value)} · ${this.percent(item.value)}`,
|
|
656
|
+
},
|
|
657
|
+
],
|
|
658
|
+
x: this.center.x + Math.sin(mid) * reach,
|
|
659
|
+
y: this.center.y - Math.cos(mid) * reach,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
getSelectDetail(index) {
|
|
663
|
+
return { index, series: this.data[index]?.name, datum: this.data[index] };
|
|
664
|
+
}
|
|
665
|
+
// ── Render helpers
|
|
666
|
+
renderSkeleton() {
|
|
667
|
+
return b `<div
|
|
668
|
+
class="skeleton skeleton-circle"
|
|
669
|
+
style=${o({ height: `${this.height}px` })}
|
|
670
|
+
aria-hidden="true"
|
|
671
|
+
>
|
|
672
|
+
<span></span>
|
|
673
|
+
</div>`;
|
|
234
674
|
}
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
</
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
675
|
+
renderSvgContent() {
|
|
676
|
+
return w `<g class="pie"><g class="slices"></g><g class="slice-labels"></g></g>`;
|
|
677
|
+
}
|
|
678
|
+
renderTable() {
|
|
679
|
+
return b `<thead>
|
|
680
|
+
<tr>
|
|
681
|
+
<th scope="col">Name</th>
|
|
682
|
+
<th scope="col">Value</th>
|
|
683
|
+
<th scope="col">Share</th>
|
|
684
|
+
</tr>
|
|
685
|
+
</thead>
|
|
686
|
+
<tbody>
|
|
687
|
+
${this.data.map(item => b `<tr>
|
|
688
|
+
<th scope="row">${item.label ?? item.name}</th>
|
|
689
|
+
<td>${this.formatValue(item.value)}</td>
|
|
690
|
+
<td>${this.percent(item.value)}</td>
|
|
691
|
+
</tr>`)}
|
|
692
|
+
</tbody>`;
|
|
245
693
|
}
|
|
246
694
|
};
|
|
247
|
-
ChartPie.styles = [css_248z];
|
|
248
|
-
__decorate([
|
|
249
|
-
e('svg')
|
|
250
|
-
], ChartPie.prototype, "svgElement", void 0);
|
|
695
|
+
ChartPie.styles = [css_248z$1, css_248z];
|
|
251
696
|
__decorate([
|
|
252
|
-
n({ type:
|
|
253
|
-
], ChartPie.prototype, "
|
|
697
|
+
n({ type: Array })
|
|
698
|
+
], ChartPie.prototype, "data", void 0);
|
|
254
699
|
__decorate([
|
|
255
|
-
n({ type: Number,
|
|
256
|
-
], ChartPie.prototype, "
|
|
700
|
+
n({ type: Number, attribute: 'inner-radius' })
|
|
701
|
+
], ChartPie.prototype, "innerRadius", void 0);
|
|
257
702
|
__decorate([
|
|
258
|
-
n({ type: Boolean,
|
|
703
|
+
n({ type: Boolean, attribute: 'show-labels' })
|
|
259
704
|
], ChartPie.prototype, "showLabels", void 0);
|
|
260
|
-
__decorate([
|
|
261
|
-
n({ type: Array })
|
|
262
|
-
], ChartPie.prototype, "data", void 0);
|
|
263
705
|
ChartPie = __decorate([
|
|
264
706
|
IndividualComponent
|
|
265
707
|
], ChartPie);
|