@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
@@ -0,0 +1,346 @@
1
+ import { property } from 'lit/decorators.js';
2
+ import {
3
+ area,
4
+ curveLinear,
5
+ curveMonotoneX,
6
+ curveStepAfter,
7
+ CurveFactory,
8
+ line,
9
+ max,
10
+ min,
11
+ scaleLinear,
12
+ scalePoint,
13
+ select,
14
+ stack,
15
+ stackOffsetNone,
16
+ } from 'd3';
17
+ import IndividualComponent from '@/IndividualComponent.js';
18
+ import { CartesianChart } from '../__internal/chart/cartesian-chart.js';
19
+ import baseStyles from '../__internal/chart/chart-base.scss';
20
+ import styles from './chart-line.scss';
21
+
22
+ export type {
23
+ ChartConfig,
24
+ ChartDatum,
25
+ ChartSelectDetail,
26
+ ChartSeriesConfig,
27
+ ChartValueFormatter,
28
+ } from '../__internal/chart/types.js';
29
+
30
+ export type ChartCurve = 'monotone' | 'linear' | 'step';
31
+
32
+ const CURVES: Record<ChartCurve, CurveFactory> = {
33
+ monotone: curveMonotoneX,
34
+ linear: curveLinear,
35
+ step: curveStepAfter,
36
+ };
37
+
38
+ /** One point of a series: the category index and the value range it covers. */
39
+ type LinePoint = { index: number; y0: number; y1: number };
40
+
41
+ /** One series as drawn: its points, color and gradient id. */
42
+ type LineSeriesModel = {
43
+ key: string;
44
+ color: string;
45
+ gradient: string;
46
+ points: LinePoint[];
47
+ };
48
+
49
+ /** One dot. */
50
+ type DotModel = {
51
+ id: string;
52
+ key: string;
53
+ color: string;
54
+ index: number;
55
+ value: number;
56
+ };
57
+
58
+ /**
59
+ * @label Line Chart
60
+ * @tag wc-chart-line
61
+ * @rawTag chart-line
62
+ * @summary Shows how values change across ordered categories such as time, with one line per series.
63
+ * @tags charts
64
+ *
65
+ * @example
66
+ * ```html
67
+ * <wc-chart-line index="month" label="Visitors by month"></wc-chart-line>
68
+ * <script>
69
+ * const chart = document.querySelector('wc-chart-line');
70
+ * chart.config = {
71
+ * desktop: { label: 'Desktop' },
72
+ * mobile: { label: 'Mobile' },
73
+ * };
74
+ * chart.data = [
75
+ * { month: 'January', desktop: 186, mobile: 80 },
76
+ * { month: 'February', desktop: 305, mobile: 200 },
77
+ * { month: 'March', desktop: 237, mobile: 120 },
78
+ * ];
79
+ * </script>
80
+ * ```
81
+ *
82
+ * @slot empty - Shown when there is no data. Defaults to "No data".
83
+ *
84
+ * @fires chart-select - A category was clicked or chosen with Enter. `detail` holds `index` and `datum`.
85
+ *
86
+ * @csspart container - The outer wrapper.
87
+ * @csspart plot - The focusable plot area holding the SVG.
88
+ * @csspart tooltip - The tooltip.
89
+ * @csspart legend - The legend.
90
+ *
91
+ * @cssprop --color-chart-1 - Color of the first series; series cycle through `--color-chart-1` to `--color-chart-8`.
92
+ * @cssprop --chart-line-width - Stroke width of the lines. Defaults to `2px`.
93
+ * @cssprop --chart-grid-color - Gridline and baseline color. Defaults to `--color-outline-variant`.
94
+ * @cssprop --chart-axis-color - Axis label color. Defaults to `--color-on-surface-variant`.
95
+ * @cssprop --chart-dim-opacity - Opacity of series that are not highlighted. Defaults to `0.4`.
96
+ */
97
+ @IndividualComponent
98
+ export class ChartLine extends CartesianChart {
99
+ // ── Static
100
+
101
+ static styles = [baseStyles, styles];
102
+
103
+ // ── Properties
104
+
105
+ /** How points are joined: `monotone` (smooth), `linear` or `step`. */
106
+ @property({ type: String, reflect: true }) curve: ChartCurve = 'monotone';
107
+
108
+ /** Draws a dot at every point. Dots always show for the hovered category. */
109
+ @property({ type: Boolean, attribute: 'show-dots' }) showDots: boolean =
110
+ false;
111
+
112
+ // ── Private fields
113
+
114
+ /** Whether the area under each line is filled. */
115
+ protected filled = false;
116
+
117
+ /** Value scale from the last draw, used to place active dots. */
118
+ private y = scaleLinear();
119
+
120
+ /** Category positions from the last draw. */
121
+ private x = scalePoint<string>();
122
+
123
+ /** Series from the last draw. */
124
+ private models: LineSeriesModel[] = [];
125
+
126
+ // ── Constructor
127
+
128
+ constructor() {
129
+ super();
130
+ this.cursorKind = 'line';
131
+ }
132
+
133
+ // ── Private methods
134
+
135
+ protected drawProperties(): string[] {
136
+ return [...super.drawProperties(), 'curve', 'showDots'];
137
+ }
138
+
139
+ /** Whether series stack on each other. Only areas stack. */
140
+ protected isStacked(): boolean {
141
+ return false;
142
+ }
143
+
144
+ private buildModels(): LineSeriesModel[] {
145
+ const all = this.getSeries();
146
+ const visible = this.visibleSeries();
147
+ const gradientId = (key: string) =>
148
+ `chart-gradient-${all.findIndex(s => s.key === key)}`;
149
+
150
+ if (this.isStacked()) {
151
+ const layers = stack<Record<string, unknown>, string>()
152
+ .keys(visible.map(s => s.key))
153
+ .value((d, key) => this.seriesValue(d, key))
154
+ .offset(stackOffsetNone)(this.data);
155
+ return visible.map((series, i) => ({
156
+ key: series.key,
157
+ color: series.color,
158
+ gradient: gradientId(series.key),
159
+ points: layers[i].map((point, index) => ({
160
+ index,
161
+ y0: point[0],
162
+ y1: point[1],
163
+ })),
164
+ }));
165
+ }
166
+
167
+ return visible.map(series => ({
168
+ key: series.key,
169
+ color: series.color,
170
+ gradient: gradientId(series.key),
171
+ points: this.data.map((datum, index) => ({
172
+ index,
173
+ y0: 0,
174
+ y1: this.seriesValue(datum, series.key),
175
+ })),
176
+ }));
177
+ }
178
+
179
+ protected draw(animate: boolean): void {
180
+ const root = this.plotArea();
181
+ if (!root || !this.svgElement) return;
182
+ const models = this.buildModels();
183
+ this.models = models;
184
+
185
+ const values = models.flatMap(m => m.points.flatMap(p => [p.y0, p.y1]));
186
+ const y = scaleLinear()
187
+ .domain([
188
+ Math.min(min(values) ?? 0, 0),
189
+ Math.max(max(values) ?? 0, 0) || 1,
190
+ ])
191
+ .nice(5);
192
+ this.computeLayout(y);
193
+ const { left, top, innerWidth, innerHeight } = this.layout;
194
+
195
+ const x = scalePoint<string>()
196
+ .domain(this.categoryDomain())
197
+ .range([0, innerWidth])
198
+ .padding(this.data.length > 1 ? 0 : 0.5);
199
+ y.range([innerHeight, 0]);
200
+ this.x = x;
201
+ this.y = y;
202
+ this.drawFrame(x, y);
203
+
204
+ const curve = CURVES[this.curve] ?? curveMonotoneX;
205
+ const px = (p: LinePoint) => x(String(p.index)) ?? 0;
206
+ const lineFor = (flat: boolean) =>
207
+ line<LinePoint>()
208
+ .x(px)
209
+ .y(p => y(flat ? 0 : p.y1))
210
+ .curve(curve);
211
+ const areaFor = (flat: boolean) =>
212
+ area<LinePoint>()
213
+ .x(px)
214
+ .y0(p => y(flat ? 0 : p.y0))
215
+ .y1(p => y(flat ? 0 : p.y1))
216
+ .curve(curve);
217
+
218
+ // Vertical gradients for the area fills.
219
+ {
220
+ const gradients = select(this.svgElement)
221
+ .select('defs')
222
+ .selectAll<SVGLinearGradientElement, LineSeriesModel>('linearGradient')
223
+ .data(this.filled ? models : [], d => d.key)
224
+ .join(enter => {
225
+ const g = enter
226
+ .append('linearGradient')
227
+ .attr('x1', 0)
228
+ .attr('y1', 0)
229
+ .attr('x2', 0)
230
+ .attr('y2', 1);
231
+ g.append('stop').attr('class', 'stop-start').attr('offset', '0%');
232
+ g.append('stop').attr('class', 'stop-end').attr('offset', '100%');
233
+ return g;
234
+ })
235
+ .attr('id', d => d.gradient);
236
+ gradients.select('.stop-start').style('stop-color', d => d.color);
237
+ gradients.select('.stop-end').style('stop-color', d => d.color);
238
+ }
239
+
240
+ const groups = root
241
+ .select('.marks')
242
+ .selectAll<SVGGElement, LineSeriesModel>('g.series')
243
+ .data(models, d => d.key)
244
+ .join(enter => {
245
+ const g = enter.append('g').attr('class', 'series mark');
246
+ g.append('path')
247
+ .attr('class', 'area')
248
+ .attr('d', d => areaFor(true)(d.points));
249
+ g.append('path')
250
+ .attr('class', 'line')
251
+ .attr('d', d => lineFor(true)(d.points));
252
+ return g;
253
+ })
254
+ .attr('data-key', d => d.key);
255
+
256
+ const areas = groups
257
+ .select<SVGPathElement>('path.area')
258
+ .style('display', this.filled ? 'inline' : 'none')
259
+ .style('fill', d => `url(#${d.gradient})`);
260
+ const lines = groups
261
+ .select<SVGPathElement>('path.line')
262
+ .style('stroke', d => d.color);
263
+ this.motion(areas, animate).attr('d', d => areaFor(false)(d.points));
264
+ this.motion(lines, animate).attr('d', d => lineFor(false)(d.points));
265
+
266
+ const dots: DotModel[] = this.showDots
267
+ ? models.flatMap(m =>
268
+ m.points.map(p => ({
269
+ id: `${m.key}:${p.index}`,
270
+ key: m.key,
271
+ color: m.color,
272
+ index: p.index,
273
+ value: p.y1,
274
+ })),
275
+ )
276
+ : [];
277
+ const dotSelection = root
278
+ .select('.marks')
279
+ .selectAll<SVGCircleElement, DotModel>('circle.dot')
280
+ .data(dots, d => d.id)
281
+ .join(enter =>
282
+ enter
283
+ .append('circle')
284
+ .attr('class', 'dot mark')
285
+ .attr('r', 3)
286
+ .attr('cx', d => x(String(d.index)) ?? 0)
287
+ .attr('cy', y(0)),
288
+ )
289
+ .attr('data-key', d => d.key)
290
+ .style('fill', d => d.color);
291
+ this.motion(dotSelection, animate)
292
+ .attr('cx', d => x(String(d.index)) ?? 0)
293
+ .attr('cy', d => y(d.value));
294
+
295
+ this.anchors = this.data.map((_, index) => {
296
+ const highest = max(models, m => m.points[index]?.y1) ?? 0;
297
+ return {
298
+ x: left + (x(String(index)) ?? 0),
299
+ y: top + Math.max(y(highest), 24),
300
+ };
301
+ });
302
+ }
303
+
304
+ protected drawHighlight(): void {
305
+ super.drawHighlight();
306
+ const root = this.plotArea();
307
+ if (!root) return;
308
+ const { activeIndex, activeSeries } = this;
309
+
310
+ root
311
+ .select('.marks')
312
+ .selectAll<SVGElement, { key: string }>('.mark')
313
+ .classed(
314
+ 'is-dimmed',
315
+ d => activeSeries !== undefined && d.key !== activeSeries,
316
+ );
317
+
318
+ const active =
319
+ activeIndex >= 0
320
+ ? this.models.map(m => ({
321
+ key: m.key,
322
+ color: m.color,
323
+ value: m.points[activeIndex]?.y1 ?? 0,
324
+ }))
325
+ : [];
326
+ root
327
+ .select('.active-layer')
328
+ .selectAll<
329
+ SVGCircleElement,
330
+ { key: string; color: string; value: number }
331
+ >('circle')
332
+ .data(active, d => d.key)
333
+ .join('circle')
334
+ .attr('class', 'active-dot')
335
+ .attr('r', 4)
336
+ .attr('cx', this.x(String(activeIndex)) ?? 0)
337
+ .attr('cy', d => this.y(d.value))
338
+ .style('fill', d => d.color);
339
+ }
340
+ }
341
+
342
+ declare global {
343
+ interface HTMLElementTagNameMap {
344
+ 'wc-chart-line': ChartLine;
345
+ }
346
+ }
@@ -0,0 +1 @@
1
+ export { ChartLine } from './chart-line.js';
@@ -1,27 +1,46 @@
1
1
  @use '../../scss/mixin';
2
2
 
3
- @include mixin.base-styles;
4
-
5
- :host {
6
- display: inline-block;
3
+ .slice {
4
+ stroke: none;
5
+ transition:
6
+ opacity var(--duration-short3) var(--easing-standard),
7
+ transform var(--duration-short4) var(--easing-emphasized-decelerate);
7
8
  }
8
9
 
9
- .arc {
10
- cursor: pointer;
11
- transition: filter 150ms ease;
10
+ .slice-label {
11
+ @include mixin.get-typography('label-medium');
12
+ fill: var(--color-surface);
13
+ pointer-events: none;
14
+ }
12
15
 
13
- &:hover {
14
- filter: brightness(1.2);
15
- }
16
+ .center {
17
+ position: absolute;
18
+ inset: 0;
19
+ display: flex;
20
+ flex-direction: column;
21
+ align-items: center;
22
+ justify-content: center;
23
+ pointer-events: none;
24
+ text-align: center;
16
25
  }
17
26
 
18
- .item-polyline {
19
- fill: none;
20
- stroke-width: 1;
21
- stroke: var(--color-on-surface);
27
+ .center-value {
28
+ @include mixin.get-typography('headline-medium');
29
+ color: var(--color-on-surface);
30
+ font-variant-numeric: tabular-nums;
22
31
  }
23
32
 
24
- .item-label {
25
- fill: var(--color-on-surface);
33
+ .center-label {
26
34
  @include mixin.get-typography('label-medium');
35
+ color: var(--color-on-surface-variant);
36
+ max-width: var(--_center-width, 8rem);
37
+ overflow: hidden;
38
+ text-overflow: ellipsis;
39
+ white-space: nowrap;
40
+ }
41
+
42
+ @media (prefers-reduced-motion: reduce) {
43
+ .slice {
44
+ transition: none;
45
+ }
27
46
  }