@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.
Files changed (147) hide show
  1. package/dist/assets/styles.css +1 -1
  2. package/dist/assets/styles.css.map +1 -1
  3. package/dist/assets/theme.js +19 -19
  4. package/dist/assets/tokens.css +1 -1
  5. package/dist/assets/tokens.css.map +1 -1
  6. package/dist/card-content.js +8 -7
  7. package/dist/card-content.js.map +1 -1
  8. package/dist/card.js +142 -98
  9. package/dist/card.js.map +1 -1
  10. package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
  11. package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
  12. package/dist/chart-area.js +78 -0
  13. package/dist/chart-area.js.map +1 -0
  14. package/dist/chart-bar.js +283 -213
  15. package/dist/chart-bar.js.map +1 -1
  16. package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
  17. package/dist/chart-base-C2qRMF48.js.map +1 -0
  18. package/dist/chart-doughnut.js +55 -287
  19. package/dist/chart-doughnut.js.map +1 -1
  20. package/dist/chart-line.js +626 -0
  21. package/dist/chart-line.js.map +1 -0
  22. package/dist/chart-pie.js +637 -195
  23. package/dist/chart-pie.js.map +1 -1
  24. package/dist/code-editor.js +704 -131
  25. package/dist/code-editor.js.map +1 -1
  26. package/dist/code-group.js +188 -0
  27. package/dist/code-group.js.map +1 -0
  28. package/dist/code-highlighter.js +895 -257
  29. package/dist/code-highlighter.js.map +1 -1
  30. package/dist/custom-elements-jsdocs.json +1675 -222
  31. package/dist/custom-elements.json +13351 -3970
  32. package/dist/image.js +5 -1
  33. package/dist/image.js.map +1 -1
  34. package/dist/index.js +8 -7
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader-full.js +1 -1
  37. package/dist/loader.js +9 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
  40. package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
  41. package/dist/path-CJ0Arqcy.js +166 -0
  42. package/dist/path-CJ0Arqcy.js.map +1 -0
  43. package/dist/snackbar.js +89 -34
  44. package/dist/snackbar.js.map +1 -1
  45. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  46. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  47. package/dist/src/__internal/chart/paths.d.ts +5 -0
  48. package/dist/src/__internal/chart/types.d.ts +42 -0
  49. package/dist/src/card/card-content.d.ts +2 -3
  50. package/dist/src/card/card.d.ts +31 -17
  51. package/dist/src/chart-area/chart-area.d.ts +54 -0
  52. package/dist/src/chart-area/index.d.ts +1 -0
  53. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  54. package/dist/src/chart-bar/index.d.ts +0 -1
  55. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  56. package/dist/src/chart-line/chart-line.d.ts +69 -0
  57. package/dist/src/chart-line/index.d.ts +1 -0
  58. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  59. package/dist/src/code-editor/code-editor.d.ts +52 -13
  60. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  61. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  62. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  63. package/dist/src/code-highlighter/index.d.ts +1 -0
  64. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  65. package/dist/src/code-highlighter/local.d.ts +4 -1
  66. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  67. package/dist/src/index.d.ts +4 -2
  68. package/dist/src/snackbar/snackbar.d.ts +13 -1
  69. package/dist/src/toolbar/toolbar.d.ts +56 -51
  70. package/dist/table.js +9 -4
  71. package/dist/table.js.map +1 -1
  72. package/dist/test/chart.test.d.ts +1 -0
  73. package/dist/test/code-highlighter.test.d.ts +1 -0
  74. package/dist/token-colors-0TFHWbcq.js +81 -0
  75. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  76. package/dist/toolbar.js +195 -184
  77. package/dist/toolbar.js.map +1 -1
  78. package/dist/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +1 -2
  80. package/readme.md +7 -6
  81. package/scss/_code-block.scss +139 -0
  82. package/scss/tokens.css +24 -0
  83. package/src/__internal/chart/cartesian-chart.ts +404 -0
  84. package/src/__internal/chart/chart-base.scss +252 -0
  85. package/src/__internal/chart/chart-base.ts +474 -0
  86. package/src/__internal/chart/paths.ts +28 -0
  87. package/src/__internal/chart/types.ts +49 -0
  88. package/src/card/card-content.ts +12 -9
  89. package/src/card/card.scss +66 -54
  90. package/src/card/card.ts +109 -73
  91. package/src/chart-area/chart-area.ts +82 -0
  92. package/src/chart-area/index.ts +1 -0
  93. package/src/chart-bar/chart-bar.ts +336 -250
  94. package/src/chart-bar/index.ts +0 -1
  95. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  96. package/src/chart-doughnut/demo/index.html +14 -22
  97. package/src/chart-line/chart-line.scss +25 -0
  98. package/src/chart-line/chart-line.ts +346 -0
  99. package/src/chart-line/index.ts +1 -0
  100. package/src/chart-pie/chart-pie.scss +35 -16
  101. package/src/chart-pie/chart-pie.ts +282 -188
  102. package/src/chart-pie/demo/index.html +13 -21
  103. package/src/code-editor/code-editor.scss +132 -36
  104. package/src/code-editor/code-editor.ts +308 -88
  105. package/src/code-editor/demo/index.html +39 -12
  106. package/src/code-editor/editor-theme.ts +213 -0
  107. package/src/code-highlighter/code-group.scss +34 -0
  108. package/src/code-highlighter/code-group.ts +173 -0
  109. package/src/code-highlighter/code-highlighter.scss +226 -111
  110. package/src/code-highlighter/code-highlighter.ts +554 -199
  111. package/src/code-highlighter/demo/index.html +68 -4
  112. package/src/code-highlighter/index.ts +1 -0
  113. package/src/code-highlighter/line-ranges.ts +81 -0
  114. package/src/code-highlighter/local.ts +9 -3
  115. package/src/code-highlighter/token-colors.ts +42 -0
  116. package/src/index.ts +4 -2
  117. package/src/loader.ts +8 -2
  118. package/src/snackbar/demo/index.html +39 -4
  119. package/src/snackbar/snackbar.scss +27 -10
  120. package/src/snackbar/snackbar.ts +80 -37
  121. package/src/table/table.scss +7 -1
  122. package/src/table/table.ts +4 -3
  123. package/src/toolbar/toolbar-colors.scss +6 -7
  124. package/src/toolbar/toolbar.scss +35 -106
  125. package/src/toolbar/toolbar.ts +180 -80
  126. package/dist/array-D5vjT2Xm.js +0 -14
  127. package/dist/array-D5vjT2Xm.js.map +0 -1
  128. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  129. package/dist/chart-stacked-bar.js +0 -403
  130. package/dist/chart-stacked-bar.js.map +0 -1
  131. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  132. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  133. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  134. package/dist/pie-Dz0IDiPt.js +0 -537
  135. package/dist/pie-Dz0IDiPt.js.map +0 -1
  136. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  137. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  138. package/dist/pierre-light-BEkAPImt.js +0 -4
  139. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  140. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  141. package/dist/src/code-highlighter/constants.d.ts +0 -1
  142. package/dist/transform-DSwFSqzD.js.map +0 -1
  143. package/src/chart-bar/chart-bar.scss +0 -58
  144. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  145. package/src/chart-doughnut/chart-donut.scss +0 -37
  146. package/src/code-highlighter/constants.ts +0 -117
  147. /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, a as i$1, b } from './IndividualComponent-Bdwyrvd6.js';
1
+ import { i, _ as __decorate, I as IndividualComponent, b, w } from './IndividualComponent-Bdwyrvd6.js';
2
2
  import { n } from './property-B49QQ8pS.js';
3
- import { e } from './query-CHb9Ft_d.js';
4
- import { o as ordinal, s as select, c as cubicInOut, i as interpolateNumber } from './transform-DSwFSqzD.js';
5
- import { p as pie, a as arc } from './pie-Dz0IDiPt.js';
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 './array-D5vjT2Xm.js';
10
+ import './class-map-DG7CA1et.js';
8
11
 
9
- var css_248z = i`* {
10
- box-sizing: border-box;
11
- -webkit-tap-highlight-color: transparent;
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
- .screen-reader-only {
15
- display: none !important;
302
+ function identity(d) {
303
+ return d;
16
304
  }
17
305
 
18
- [hidden] {
19
- display: none !important;
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
- :host {
23
- display: inline-block;
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
- .arc {
27
- cursor: pointer;
28
- transition: filter 150ms ease;
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
- .arc:hover {
31
- filter: brightness(1.2);
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
- .item-polyline {
35
- fill: none;
36
- stroke-width: 1;
37
- stroke: var(--color-on-surface);
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
- .item-label {
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 chartColors = [];
50
- ['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {
51
- chartColors.push({
52
- color: `var(--color-${colorName})`,
53
- });
54
- });
55
- function debounce(fn, wait) {
56
- let timer;
57
- return ((...args) => {
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 Pie
446
+ * @label Pie Chart
64
447
  * @tag wc-chart-pie
65
448
  * @rawTag chart-pie
66
- * @summary A pie chart is a circular statistical graphic that visually represents numerical proportions.
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 width="400"></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: 'A', value: 30, label: 'Category A' },
75
- * { name: 'B', value: 50, label: 'Category B' },
76
- * { name: 'C', value: 20, label: 'Category C' },
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 i$1 {
476
+ let ChartPie = class ChartPie extends ChartBase {
82
477
  constructor() {
478
+ // ── Static
83
479
  super(...arguments);
84
- /** Width (and height) of the chart in pixels. */
85
- this.width = 0;
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
- this._initialized = false;
93
- this._debouncedRenderChart = debounce(() => {
94
- this._renderChart(true);
95
- }, 300);
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
- firstUpdated() {
98
- this._renderChart(false);
495
+ // ── Private methods
496
+ drawProperties() {
497
+ return [...super.drawProperties(), 'data', 'innerRadius', 'showLabels'];
99
498
  }
100
- updated(changedProperties) {
101
- if (!this._initialized) {
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
- _getRadius() {
112
- // Reserve 100px on each side for labels and padding
113
- return this.width / 2 - this.margin - 100;
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
- _getPieData() {
116
- const pieGenerator = pie()
117
- .sort(null)
118
- .value(d => d.value);
119
- return pieGenerator(this.data);
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
- _getColorScale() {
122
- return ordinal()
123
- .domain(this.data.map(d => d.name))
124
- .range(chartColors);
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
- _renderChart(animate) {
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 DURATION = 500;
130
- const radius = this._getRadius();
131
- const pieData = this._getPieData();
132
- const colorScale = this._getColorScale();
133
- const svg = select(this.svgElement);
134
- const pieArc = arc()
135
- .innerRadius(0)
136
- .outerRadius(radius);
137
- const labelsArc = arc()
138
- .innerRadius(radius + 10)
139
- .outerRadius(radius + 10);
140
- // Update SVG dimensions and center transform
141
- svg.attr('width', this.width).attr('height', this.width);
142
- svg
143
- .select('.chart-container')
144
- .attr('transform', `translate(${this.width / 2},${this.width / 2})`);
145
- // Arc paths — keyed by name so D3 matches elements across updates
146
- const $paths = svg
147
- .select('.arc-container')
148
- .selectAll('.arc')
149
- .data(pieData, d => d.data.name)
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', 'arc')
152
- .style('fill', d => d.data.color || colorScale(d.data.name).color);
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
- $paths
563
+ slices
155
564
  .transition()
156
565
  .duration(DURATION)
157
- .ease(cubicInOut)
566
+ .ease(cubicOut)
158
567
  .attrTween('d', function (d) {
159
- const self = this;
160
- // Interpolate from the last rendered angles to the new ones.
161
- // New (entering) arcs start collapsed at their startAngle.
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
- self._prevDatum = d;
167
- const iStart = interpolateNumber(prev.startAngle, d.startAngle);
168
- const iEnd = interpolateNumber(prev.endAngle, d.endAngle);
169
- return (t) => pieArc({ ...d, startAngle: iStart(t), endAngle: iEnd(t) }) ?? '';
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
- // Initial render: draw immediately and seed previous-datum for later tweens
174
- $paths
175
- .each(function (d) {
176
- this._prevDatum = d;
177
- })
178
- .attr('d', d => pieArc(d) ?? '');
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
- else {
231
- $chartContainer.selectAll('.item-polyline').remove();
232
- $chartContainer.selectAll('.item-label').remove();
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
- render() {
236
- return b `
237
- <div class="chart">
238
- <svg>
239
- <g class="chart-container">
240
- <g class="arc-container"></g>
241
- </g>
242
- </svg>
243
- </div>
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: Number, reflect: true })
253
- ], ChartPie.prototype, "width", void 0);
697
+ n({ type: Array })
698
+ ], ChartPie.prototype, "data", void 0);
254
699
  __decorate([
255
- n({ type: Number, reflect: true })
256
- ], ChartPie.prototype, "margin", void 0);
700
+ n({ type: Number, attribute: 'inner-radius' })
701
+ ], ChartPie.prototype, "innerRadius", void 0);
257
702
  __decorate([
258
- n({ type: Boolean, reflect: true, attribute: 'show-labels' })
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);