@redvars/peacock 3.15.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 (157) 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 +2278 -677
  31. package/dist/custom-elements.json +13962 -3690
  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/pagination.js +408 -110
  42. package/dist/pagination.js.map +1 -1
  43. package/dist/path-CJ0Arqcy.js +166 -0
  44. package/dist/path-CJ0Arqcy.js.map +1 -0
  45. package/dist/snackbar.js +89 -34
  46. package/dist/snackbar.js.map +1 -1
  47. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  48. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  49. package/dist/src/__internal/chart/paths.d.ts +5 -0
  50. package/dist/src/__internal/chart/types.d.ts +42 -0
  51. package/dist/src/card/card-content.d.ts +2 -3
  52. package/dist/src/card/card.d.ts +31 -17
  53. package/dist/src/chart-area/chart-area.d.ts +54 -0
  54. package/dist/src/chart-area/index.d.ts +1 -0
  55. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  56. package/dist/src/chart-bar/index.d.ts +0 -1
  57. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  58. package/dist/src/chart-line/chart-line.d.ts +69 -0
  59. package/dist/src/chart-line/index.d.ts +1 -0
  60. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  61. package/dist/src/code-editor/code-editor.d.ts +52 -13
  62. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  63. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  64. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  65. package/dist/src/code-highlighter/index.d.ts +1 -0
  66. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  67. package/dist/src/code-highlighter/local.d.ts +4 -1
  68. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  69. package/dist/src/index.d.ts +4 -2
  70. package/dist/src/pagination/page-items.d.ts +14 -0
  71. package/dist/src/pagination/pagination.d.ts +46 -7
  72. package/dist/src/snackbar/snackbar.d.ts +13 -1
  73. package/dist/src/table/table.d.ts +125 -27
  74. package/dist/src/toolbar/toolbar.d.ts +56 -51
  75. package/dist/table.js +1007 -338
  76. package/dist/table.js.map +1 -1
  77. package/dist/test/chart.test.d.ts +1 -0
  78. package/dist/test/code-highlighter.test.d.ts +1 -0
  79. package/dist/test/pagination.test.d.ts +1 -0
  80. package/dist/test/table.test.d.ts +1 -0
  81. package/dist/token-colors-0TFHWbcq.js +81 -0
  82. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  83. package/dist/toolbar.js +195 -184
  84. package/dist/toolbar.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -2
  87. package/readme.md +7 -6
  88. package/scss/_code-block.scss +139 -0
  89. package/scss/tokens.css +24 -0
  90. package/src/__internal/chart/cartesian-chart.ts +404 -0
  91. package/src/__internal/chart/chart-base.scss +252 -0
  92. package/src/__internal/chart/chart-base.ts +474 -0
  93. package/src/__internal/chart/paths.ts +28 -0
  94. package/src/__internal/chart/types.ts +49 -0
  95. package/src/card/card-content.ts +12 -9
  96. package/src/card/card.scss +66 -54
  97. package/src/card/card.ts +109 -73
  98. package/src/chart-area/chart-area.ts +82 -0
  99. package/src/chart-area/index.ts +1 -0
  100. package/src/chart-bar/chart-bar.ts +336 -250
  101. package/src/chart-bar/index.ts +0 -1
  102. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  103. package/src/chart-doughnut/demo/index.html +14 -22
  104. package/src/chart-line/chart-line.scss +25 -0
  105. package/src/chart-line/chart-line.ts +346 -0
  106. package/src/chart-line/index.ts +1 -0
  107. package/src/chart-pie/chart-pie.scss +35 -16
  108. package/src/chart-pie/chart-pie.ts +282 -188
  109. package/src/chart-pie/demo/index.html +13 -21
  110. package/src/code-editor/code-editor.scss +132 -36
  111. package/src/code-editor/code-editor.ts +308 -88
  112. package/src/code-editor/demo/index.html +39 -12
  113. package/src/code-editor/editor-theme.ts +213 -0
  114. package/src/code-highlighter/code-group.scss +34 -0
  115. package/src/code-highlighter/code-group.ts +173 -0
  116. package/src/code-highlighter/code-highlighter.scss +226 -111
  117. package/src/code-highlighter/code-highlighter.ts +554 -199
  118. package/src/code-highlighter/demo/index.html +68 -4
  119. package/src/code-highlighter/index.ts +1 -0
  120. package/src/code-highlighter/line-ranges.ts +81 -0
  121. package/src/code-highlighter/local.ts +9 -3
  122. package/src/code-highlighter/token-colors.ts +42 -0
  123. package/src/index.ts +4 -2
  124. package/src/loader.ts +8 -2
  125. package/src/pagination/page-items.ts +50 -0
  126. package/src/pagination/pagination.scss +159 -44
  127. package/src/pagination/pagination.ts +275 -74
  128. package/src/snackbar/demo/index.html +39 -4
  129. package/src/snackbar/snackbar.scss +27 -10
  130. package/src/snackbar/snackbar.ts +80 -37
  131. package/src/table/table.scss +337 -109
  132. package/src/table/table.ts +812 -272
  133. package/src/toolbar/toolbar-colors.scss +6 -7
  134. package/src/toolbar/toolbar.scss +35 -106
  135. package/src/toolbar/toolbar.ts +180 -80
  136. package/dist/array-D5vjT2Xm.js +0 -14
  137. package/dist/array-D5vjT2Xm.js.map +0 -1
  138. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  139. package/dist/chart-stacked-bar.js +0 -403
  140. package/dist/chart-stacked-bar.js.map +0 -1
  141. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  142. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  143. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  144. package/dist/pie-Dz0IDiPt.js +0 -537
  145. package/dist/pie-Dz0IDiPt.js.map +0 -1
  146. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  147. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  148. package/dist/pierre-light-BEkAPImt.js +0 -4
  149. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  150. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  151. package/dist/src/code-highlighter/constants.d.ts +0 -1
  152. package/dist/transform-DSwFSqzD.js.map +0 -1
  153. package/src/chart-bar/chart-bar.scss +0 -58
  154. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  155. package/src/chart-doughnut/chart-donut.scss +0 -37
  156. package/src/code-highlighter/constants.ts +0 -117
  157. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -0,0 +1,626 @@
1
+ import { i, _ as __decorate, I as IndividualComponent } from './IndividualComponent-Bdwyrvd6.js';
2
+ import { n } from './property-B49QQ8pS.js';
3
+ import { b as array, a as constant, c as css_248z$1, s as select } from './chart-base-C2qRMF48.js';
4
+ import { C as CartesianChart, l as linear, p as point$1, s as stack, c as stackOffsetNone, m as min, a as max } from './cartesian-chart-DgE4USyC.js';
5
+ import { w as withPath } from './path-CJ0Arqcy.js';
6
+ import './state-DkTK9EGF.js';
7
+ import './query-CHb9Ft_d.js';
8
+ import './base-Cl6v8-BZ.js';
9
+ import './class-map-DG7CA1et.js';
10
+ import './directive-ZPhl09Yt.js';
11
+ import './style-map-BQD5Et1D.js';
12
+
13
+ function Linear(context) {
14
+ this._context = context;
15
+ }
16
+
17
+ Linear.prototype = {
18
+ areaStart: function() {
19
+ this._line = 0;
20
+ },
21
+ areaEnd: function() {
22
+ this._line = NaN;
23
+ },
24
+ lineStart: function() {
25
+ this._point = 0;
26
+ },
27
+ lineEnd: function() {
28
+ if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
29
+ this._line = 1 - this._line;
30
+ },
31
+ point: function(x, y) {
32
+ x = +x, y = +y;
33
+ switch (this._point) {
34
+ case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
35
+ case 1: this._point = 2; // falls through
36
+ default: this._context.lineTo(x, y); break;
37
+ }
38
+ }
39
+ };
40
+
41
+ function curveLinear(context) {
42
+ return new Linear(context);
43
+ }
44
+
45
+ function x(p) {
46
+ return p[0];
47
+ }
48
+
49
+ function y(p) {
50
+ return p[1];
51
+ }
52
+
53
+ function line(x$1, y$1) {
54
+ var defined = constant(true),
55
+ context = null,
56
+ curve = curveLinear,
57
+ output = null,
58
+ path = withPath(line);
59
+
60
+ x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant(x$1);
61
+ y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant(y$1);
62
+
63
+ function line(data) {
64
+ var i,
65
+ n = (data = array(data)).length,
66
+ d,
67
+ defined0 = false,
68
+ buffer;
69
+
70
+ if (context == null) output = curve(buffer = path());
71
+
72
+ for (i = 0; i <= n; ++i) {
73
+ if (!(i < n && defined(d = data[i], i, data)) === defined0) {
74
+ if (defined0 = !defined0) output.lineStart();
75
+ else output.lineEnd();
76
+ }
77
+ if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
78
+ }
79
+
80
+ if (buffer) return output = null, buffer + "" || null;
81
+ }
82
+
83
+ line.x = function(_) {
84
+ return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant(+_), line) : x$1;
85
+ };
86
+
87
+ line.y = function(_) {
88
+ return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant(+_), line) : y$1;
89
+ };
90
+
91
+ line.defined = function(_) {
92
+ return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined;
93
+ };
94
+
95
+ line.curve = function(_) {
96
+ return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
97
+ };
98
+
99
+ line.context = function(_) {
100
+ return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
101
+ };
102
+
103
+ return line;
104
+ }
105
+
106
+ function area(x0, y0, y1) {
107
+ var x1 = null,
108
+ defined = constant(true),
109
+ context = null,
110
+ curve = curveLinear,
111
+ output = null,
112
+ path = withPath(area);
113
+
114
+ x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant(+x0);
115
+ y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant(0) : constant(+y0);
116
+ y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant(+y1);
117
+
118
+ function area(data) {
119
+ var i,
120
+ j,
121
+ k,
122
+ n = (data = array(data)).length,
123
+ d,
124
+ defined0 = false,
125
+ buffer,
126
+ x0z = new Array(n),
127
+ y0z = new Array(n);
128
+
129
+ if (context == null) output = curve(buffer = path());
130
+
131
+ for (i = 0; i <= n; ++i) {
132
+ if (!(i < n && defined(d = data[i], i, data)) === defined0) {
133
+ if (defined0 = !defined0) {
134
+ j = i;
135
+ output.areaStart();
136
+ output.lineStart();
137
+ } else {
138
+ output.lineEnd();
139
+ output.lineStart();
140
+ for (k = i - 1; k >= j; --k) {
141
+ output.point(x0z[k], y0z[k]);
142
+ }
143
+ output.lineEnd();
144
+ output.areaEnd();
145
+ }
146
+ }
147
+ if (defined0) {
148
+ x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
149
+ output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
150
+ }
151
+ }
152
+
153
+ if (buffer) return output = null, buffer + "" || null;
154
+ }
155
+
156
+ function arealine() {
157
+ return line().defined(defined).curve(curve).context(context);
158
+ }
159
+
160
+ area.x = function(_) {
161
+ return arguments.length ? (x0 = typeof _ === "function" ? _ : constant(+_), x1 = null, area) : x0;
162
+ };
163
+
164
+ area.x0 = function(_) {
165
+ return arguments.length ? (x0 = typeof _ === "function" ? _ : constant(+_), area) : x0;
166
+ };
167
+
168
+ area.x1 = function(_) {
169
+ return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant(+_), area) : x1;
170
+ };
171
+
172
+ area.y = function(_) {
173
+ return arguments.length ? (y0 = typeof _ === "function" ? _ : constant(+_), y1 = null, area) : y0;
174
+ };
175
+
176
+ area.y0 = function(_) {
177
+ return arguments.length ? (y0 = typeof _ === "function" ? _ : constant(+_), area) : y0;
178
+ };
179
+
180
+ area.y1 = function(_) {
181
+ return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant(+_), area) : y1;
182
+ };
183
+
184
+ area.lineX0 =
185
+ area.lineY0 = function() {
186
+ return arealine().x(x0).y(y0);
187
+ };
188
+
189
+ area.lineY1 = function() {
190
+ return arealine().x(x0).y(y1);
191
+ };
192
+
193
+ area.lineX1 = function() {
194
+ return arealine().x(x1).y(y0);
195
+ };
196
+
197
+ area.defined = function(_) {
198
+ return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), area) : defined;
199
+ };
200
+
201
+ area.curve = function(_) {
202
+ return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
203
+ };
204
+
205
+ area.context = function(_) {
206
+ return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
207
+ };
208
+
209
+ return area;
210
+ }
211
+
212
+ function sign(x) {
213
+ return x < 0 ? -1 : 1;
214
+ }
215
+
216
+ // Calculate the slopes of the tangents (Hermite-type interpolation) based on
217
+ // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
218
+ // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
219
+ // NOV(II), P. 443, 1990.
220
+ function slope3(that, x2, y2) {
221
+ var h0 = that._x1 - that._x0,
222
+ h1 = x2 - that._x1,
223
+ s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
224
+ s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
225
+ p = (s0 * h1 + s1 * h0) / (h0 + h1);
226
+ return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
227
+ }
228
+
229
+ // Calculate a one-sided slope.
230
+ function slope2(that, t) {
231
+ var h = that._x1 - that._x0;
232
+ return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
233
+ }
234
+
235
+ // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
236
+ // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
237
+ // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
238
+ function point(that, t0, t1) {
239
+ var x0 = that._x0,
240
+ y0 = that._y0,
241
+ x1 = that._x1,
242
+ y1 = that._y1,
243
+ dx = (x1 - x0) / 3;
244
+ that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
245
+ }
246
+
247
+ function MonotoneX(context) {
248
+ this._context = context;
249
+ }
250
+
251
+ MonotoneX.prototype = {
252
+ areaStart: function() {
253
+ this._line = 0;
254
+ },
255
+ areaEnd: function() {
256
+ this._line = NaN;
257
+ },
258
+ lineStart: function() {
259
+ this._x0 = this._x1 =
260
+ this._y0 = this._y1 =
261
+ this._t0 = NaN;
262
+ this._point = 0;
263
+ },
264
+ lineEnd: function() {
265
+ switch (this._point) {
266
+ case 2: this._context.lineTo(this._x1, this._y1); break;
267
+ case 3: point(this, this._t0, slope2(this, this._t0)); break;
268
+ }
269
+ if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
270
+ this._line = 1 - this._line;
271
+ },
272
+ point: function(x, y) {
273
+ var t1 = NaN;
274
+
275
+ x = +x, y = +y;
276
+ if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
277
+ switch (this._point) {
278
+ case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
279
+ case 1: this._point = 2; break;
280
+ case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
281
+ default: point(this, this._t0, t1 = slope3(this, x, y)); break;
282
+ }
283
+
284
+ this._x0 = this._x1, this._x1 = x;
285
+ this._y0 = this._y1, this._y1 = y;
286
+ this._t0 = t1;
287
+ }
288
+ };
289
+
290
+ (Object.create(MonotoneX.prototype)).point = function(x, y) {
291
+ MonotoneX.prototype.point.call(this, y, x);
292
+ };
293
+
294
+ function monotoneX(context) {
295
+ return new MonotoneX(context);
296
+ }
297
+
298
+ function Step(context, t) {
299
+ this._context = context;
300
+ this._t = t;
301
+ }
302
+
303
+ Step.prototype = {
304
+ areaStart: function() {
305
+ this._line = 0;
306
+ },
307
+ areaEnd: function() {
308
+ this._line = NaN;
309
+ },
310
+ lineStart: function() {
311
+ this._x = this._y = NaN;
312
+ this._point = 0;
313
+ },
314
+ lineEnd: function() {
315
+ if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
316
+ if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
317
+ if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
318
+ },
319
+ point: function(x, y) {
320
+ x = +x, y = +y;
321
+ switch (this._point) {
322
+ case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
323
+ case 1: this._point = 2; // falls through
324
+ default: {
325
+ if (this._t <= 0) {
326
+ this._context.lineTo(this._x, y);
327
+ this._context.lineTo(x, y);
328
+ } else {
329
+ var x1 = this._x * (1 - this._t) + x * this._t;
330
+ this._context.lineTo(x1, this._y);
331
+ this._context.lineTo(x1, y);
332
+ }
333
+ break;
334
+ }
335
+ }
336
+ this._x = x, this._y = y;
337
+ }
338
+ };
339
+
340
+ function stepAfter(context) {
341
+ return new Step(context, 1);
342
+ }
343
+
344
+ var css_248z = i`:host {
345
+ --_chart-line-width: var(--chart-line-width, 2px);
346
+ }
347
+
348
+ .line {
349
+ fill: none;
350
+ stroke-width: var(--_chart-line-width);
351
+ stroke-linecap: round;
352
+ stroke-linejoin: round;
353
+ }
354
+
355
+ .stop-start {
356
+ stop-opacity: 0.4;
357
+ }
358
+
359
+ .stop-end {
360
+ stop-opacity: 0.02;
361
+ }
362
+
363
+ .dot,
364
+ .active-dot {
365
+ stroke: var(--color-surface);
366
+ stroke-width: 2px;
367
+ pointer-events: none;
368
+ }`;
369
+
370
+ const CURVES = {
371
+ monotone: monotoneX,
372
+ linear: curveLinear,
373
+ step: stepAfter,
374
+ };
375
+ /**
376
+ * @label Line Chart
377
+ * @tag wc-chart-line
378
+ * @rawTag chart-line
379
+ * @summary Shows how values change across ordered categories such as time, with one line per series.
380
+ * @tags charts
381
+ *
382
+ * @example
383
+ * ```html
384
+ * <wc-chart-line index="month" label="Visitors by month"></wc-chart-line>
385
+ * <script>
386
+ * const chart = document.querySelector('wc-chart-line');
387
+ * chart.config = {
388
+ * desktop: { label: 'Desktop' },
389
+ * mobile: { label: 'Mobile' },
390
+ * };
391
+ * chart.data = [
392
+ * { month: 'January', desktop: 186, mobile: 80 },
393
+ * { month: 'February', desktop: 305, mobile: 200 },
394
+ * { month: 'March', desktop: 237, mobile: 120 },
395
+ * ];
396
+ * </script>
397
+ * ```
398
+ *
399
+ * @slot empty - Shown when there is no data. Defaults to "No data".
400
+ *
401
+ * @fires chart-select - A category was clicked or chosen with Enter. `detail` holds `index` and `datum`.
402
+ *
403
+ * @csspart container - The outer wrapper.
404
+ * @csspart plot - The focusable plot area holding the SVG.
405
+ * @csspart tooltip - The tooltip.
406
+ * @csspart legend - The legend.
407
+ *
408
+ * @cssprop --color-chart-1 - Color of the first series; series cycle through `--color-chart-1` to `--color-chart-8`.
409
+ * @cssprop --chart-line-width - Stroke width of the lines. Defaults to `2px`.
410
+ * @cssprop --chart-grid-color - Gridline and baseline color. Defaults to `--color-outline-variant`.
411
+ * @cssprop --chart-axis-color - Axis label color. Defaults to `--color-on-surface-variant`.
412
+ * @cssprop --chart-dim-opacity - Opacity of series that are not highlighted. Defaults to `0.4`.
413
+ */
414
+ let ChartLine = class ChartLine extends CartesianChart {
415
+ // ── Constructor
416
+ constructor() {
417
+ super();
418
+ // ── Properties
419
+ /** How points are joined: `monotone` (smooth), `linear` or `step`. */
420
+ this.curve = 'monotone';
421
+ /** Draws a dot at every point. Dots always show for the hovered category. */
422
+ this.showDots = false;
423
+ // ── Private fields
424
+ /** Whether the area under each line is filled. */
425
+ this.filled = false;
426
+ /** Value scale from the last draw, used to place active dots. */
427
+ this.y = linear();
428
+ /** Category positions from the last draw. */
429
+ this.x = point$1();
430
+ /** Series from the last draw. */
431
+ this.models = [];
432
+ this.cursorKind = 'line';
433
+ }
434
+ // ── Private methods
435
+ drawProperties() {
436
+ return [...super.drawProperties(), 'curve', 'showDots'];
437
+ }
438
+ /** Whether series stack on each other. Only areas stack. */
439
+ isStacked() {
440
+ return false;
441
+ }
442
+ buildModels() {
443
+ const all = this.getSeries();
444
+ const visible = this.visibleSeries();
445
+ const gradientId = (key) => `chart-gradient-${all.findIndex(s => s.key === key)}`;
446
+ if (this.isStacked()) {
447
+ const layers = stack()
448
+ .keys(visible.map(s => s.key))
449
+ .value((d, key) => this.seriesValue(d, key))
450
+ .offset(stackOffsetNone)(this.data);
451
+ return visible.map((series, i) => ({
452
+ key: series.key,
453
+ color: series.color,
454
+ gradient: gradientId(series.key),
455
+ points: layers[i].map((point, index) => ({
456
+ index,
457
+ y0: point[0],
458
+ y1: point[1],
459
+ })),
460
+ }));
461
+ }
462
+ return visible.map(series => ({
463
+ key: series.key,
464
+ color: series.color,
465
+ gradient: gradientId(series.key),
466
+ points: this.data.map((datum, index) => ({
467
+ index,
468
+ y0: 0,
469
+ y1: this.seriesValue(datum, series.key),
470
+ })),
471
+ }));
472
+ }
473
+ draw(animate) {
474
+ const root = this.plotArea();
475
+ if (!root || !this.svgElement)
476
+ return;
477
+ const models = this.buildModels();
478
+ this.models = models;
479
+ const values = models.flatMap(m => m.points.flatMap(p => [p.y0, p.y1]));
480
+ const y = linear()
481
+ .domain([
482
+ Math.min(min(values) ?? 0, 0),
483
+ Math.max(max(values) ?? 0, 0) || 1,
484
+ ])
485
+ .nice(5);
486
+ this.computeLayout(y);
487
+ const { left, top, innerWidth, innerHeight } = this.layout;
488
+ const x = point$1()
489
+ .domain(this.categoryDomain())
490
+ .range([0, innerWidth])
491
+ .padding(this.data.length > 1 ? 0 : 0.5);
492
+ y.range([innerHeight, 0]);
493
+ this.x = x;
494
+ this.y = y;
495
+ this.drawFrame(x, y);
496
+ const curve = CURVES[this.curve] ?? monotoneX;
497
+ const px = (p) => x(String(p.index)) ?? 0;
498
+ const lineFor = (flat) => line()
499
+ .x(px)
500
+ .y(p => y(flat ? 0 : p.y1))
501
+ .curve(curve);
502
+ const areaFor = (flat) => area()
503
+ .x(px)
504
+ .y0(p => y(flat ? 0 : p.y0))
505
+ .y1(p => y(flat ? 0 : p.y1))
506
+ .curve(curve);
507
+ // Vertical gradients for the area fills.
508
+ {
509
+ const gradients = select(this.svgElement)
510
+ .select('defs')
511
+ .selectAll('linearGradient')
512
+ .data(this.filled ? models : [], d => d.key)
513
+ .join(enter => {
514
+ const g = enter
515
+ .append('linearGradient')
516
+ .attr('x1', 0)
517
+ .attr('y1', 0)
518
+ .attr('x2', 0)
519
+ .attr('y2', 1);
520
+ g.append('stop').attr('class', 'stop-start').attr('offset', '0%');
521
+ g.append('stop').attr('class', 'stop-end').attr('offset', '100%');
522
+ return g;
523
+ })
524
+ .attr('id', d => d.gradient);
525
+ gradients.select('.stop-start').style('stop-color', d => d.color);
526
+ gradients.select('.stop-end').style('stop-color', d => d.color);
527
+ }
528
+ const groups = root
529
+ .select('.marks')
530
+ .selectAll('g.series')
531
+ .data(models, d => d.key)
532
+ .join(enter => {
533
+ const g = enter.append('g').attr('class', 'series mark');
534
+ g.append('path')
535
+ .attr('class', 'area')
536
+ .attr('d', d => areaFor(true)(d.points));
537
+ g.append('path')
538
+ .attr('class', 'line')
539
+ .attr('d', d => lineFor(true)(d.points));
540
+ return g;
541
+ })
542
+ .attr('data-key', d => d.key);
543
+ const areas = groups
544
+ .select('path.area')
545
+ .style('display', this.filled ? 'inline' : 'none')
546
+ .style('fill', d => `url(#${d.gradient})`);
547
+ const lines = groups
548
+ .select('path.line')
549
+ .style('stroke', d => d.color);
550
+ this.motion(areas, animate).attr('d', d => areaFor(false)(d.points));
551
+ this.motion(lines, animate).attr('d', d => lineFor(false)(d.points));
552
+ const dots = this.showDots
553
+ ? models.flatMap(m => m.points.map(p => ({
554
+ id: `${m.key}:${p.index}`,
555
+ key: m.key,
556
+ color: m.color,
557
+ index: p.index,
558
+ value: p.y1,
559
+ })))
560
+ : [];
561
+ const dotSelection = root
562
+ .select('.marks')
563
+ .selectAll('circle.dot')
564
+ .data(dots, d => d.id)
565
+ .join(enter => enter
566
+ .append('circle')
567
+ .attr('class', 'dot mark')
568
+ .attr('r', 3)
569
+ .attr('cx', d => x(String(d.index)) ?? 0)
570
+ .attr('cy', y(0)))
571
+ .attr('data-key', d => d.key)
572
+ .style('fill', d => d.color);
573
+ this.motion(dotSelection, animate)
574
+ .attr('cx', d => x(String(d.index)) ?? 0)
575
+ .attr('cy', d => y(d.value));
576
+ this.anchors = this.data.map((_, index) => {
577
+ const highest = max(models, m => m.points[index]?.y1) ?? 0;
578
+ return {
579
+ x: left + (x(String(index)) ?? 0),
580
+ y: top + Math.max(y(highest), 24),
581
+ };
582
+ });
583
+ }
584
+ drawHighlight() {
585
+ super.drawHighlight();
586
+ const root = this.plotArea();
587
+ if (!root)
588
+ return;
589
+ const { activeIndex, activeSeries } = this;
590
+ root
591
+ .select('.marks')
592
+ .selectAll('.mark')
593
+ .classed('is-dimmed', d => activeSeries !== undefined && d.key !== activeSeries);
594
+ const active = activeIndex >= 0
595
+ ? this.models.map(m => ({
596
+ key: m.key,
597
+ color: m.color,
598
+ value: m.points[activeIndex]?.y1 ?? 0,
599
+ }))
600
+ : [];
601
+ root
602
+ .select('.active-layer')
603
+ .selectAll('circle')
604
+ .data(active, d => d.key)
605
+ .join('circle')
606
+ .attr('class', 'active-dot')
607
+ .attr('r', 4)
608
+ .attr('cx', this.x(String(activeIndex)) ?? 0)
609
+ .attr('cy', d => this.y(d.value))
610
+ .style('fill', d => d.color);
611
+ }
612
+ };
613
+ // ── Static
614
+ ChartLine.styles = [css_248z$1, css_248z];
615
+ __decorate([
616
+ n({ type: String, reflect: true })
617
+ ], ChartLine.prototype, "curve", void 0);
618
+ __decorate([
619
+ n({ type: Boolean, attribute: 'show-dots' })
620
+ ], ChartLine.prototype, "showDots", void 0);
621
+ ChartLine = __decorate([
622
+ IndividualComponent
623
+ ], ChartLine);
624
+
625
+ export { ChartLine };
626
+ //# sourceMappingURL=chart-line.js.map