@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.
- 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 +2278 -677
- package/dist/custom-elements.json +13962 -3690
- 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/pagination.js +408 -110
- package/dist/pagination.js.map +1 -1
- 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/pagination/page-items.d.ts +14 -0
- package/dist/src/pagination/pagination.d.ts +46 -7
- package/dist/src/snackbar/snackbar.d.ts +13 -1
- package/dist/src/table/table.d.ts +125 -27
- package/dist/src/toolbar/toolbar.d.ts +56 -51
- package/dist/table.js +1007 -338
- 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/test/pagination.test.d.ts +1 -0
- package/dist/test/table.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/pagination/page-items.ts +50 -0
- package/src/pagination/pagination.scss +159 -44
- package/src/pagination/pagination.ts +275 -74
- 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 +337 -109
- package/src/table/table.ts +812 -272
- 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-doughnut.js
CHANGED
|
@@ -1,313 +1,81 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as __decorate, I as IndividualComponent, b } 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 { ChartPie } from './chart-pie.js';
|
|
5
|
+
import './directive-ZPhl09Yt.js';
|
|
6
|
+
import './chart-base-C2qRMF48.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';
|
|
11
|
+
import './path-CJ0Arqcy.js';
|
|
8
12
|
|
|
9
|
-
var css_248z = i`* {
|
|
10
|
-
box-sizing: border-box;
|
|
11
|
-
-webkit-tap-highlight-color: transparent;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.screen-reader-only {
|
|
15
|
-
display: none !important;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
[hidden] {
|
|
19
|
-
display: none !important;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
:host {
|
|
23
|
-
display: inline-block;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.title {
|
|
27
|
-
font-family: var(--typography-title-large-emphasized-font-family) !important;
|
|
28
|
-
font-size: var(--typography-title-large-emphasized-font-size) !important;
|
|
29
|
-
font-weight: var(--typography-title-large-emphasized-font-weight) !important;
|
|
30
|
-
line-height: var(--typography-title-large-emphasized-line-height) !important;
|
|
31
|
-
letter-spacing: var(--typography-title-large-emphasized-letter-spacing) !important;
|
|
32
|
-
fill: var(--color-on-surface);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.label {
|
|
36
|
-
font-family: var(--typography-title-medium-font-family) !important;
|
|
37
|
-
font-size: var(--typography-title-medium-font-size) !important;
|
|
38
|
-
font-weight: var(--typography-title-medium-font-weight) !important;
|
|
39
|
-
line-height: var(--typography-title-medium-line-height) !important;
|
|
40
|
-
letter-spacing: var(--typography-title-medium-letter-spacing) !important;
|
|
41
|
-
fill: var(--color-on-surface);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.arc {
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
transition: filter 150ms ease;
|
|
47
|
-
}
|
|
48
|
-
.arc:hover {
|
|
49
|
-
filter: brightness(1.2);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.item-polyline {
|
|
53
|
-
fill: none;
|
|
54
|
-
stroke-width: 1;
|
|
55
|
-
stroke: var(--color-on-surface);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.item-label {
|
|
59
|
-
fill: var(--color-on-surface);
|
|
60
|
-
font-family: var(--typography-label-medium-font-family) !important;
|
|
61
|
-
font-size: var(--typography-label-medium-font-size) !important;
|
|
62
|
-
font-weight: var(--typography-label-medium-font-weight) !important;
|
|
63
|
-
line-height: var(--typography-label-medium-line-height) !important;
|
|
64
|
-
letter-spacing: var(--typography-label-medium-letter-spacing) !important;
|
|
65
|
-
}`;
|
|
66
|
-
|
|
67
|
-
const chartColors = [];
|
|
68
|
-
['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {
|
|
69
|
-
chartColors.push({
|
|
70
|
-
color: `var(--color-${colorName})`,
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
function debounce(fn, wait) {
|
|
74
|
-
let timer;
|
|
75
|
-
return ((...args) => {
|
|
76
|
-
clearTimeout(timer);
|
|
77
|
-
timer = setTimeout(() => fn(...args), wait);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
13
|
/**
|
|
81
|
-
* @label Chart
|
|
14
|
+
* @label Doughnut Chart
|
|
82
15
|
* @tag wc-chart-doughnut
|
|
83
16
|
* @rawTag chart-doughnut
|
|
84
|
-
* @summary A
|
|
17
|
+
* @summary A pie chart with a hole that shows the total, or the hovered slice, in its centre.
|
|
85
18
|
* @tags charts
|
|
86
19
|
*
|
|
87
20
|
* @example
|
|
88
21
|
* ```html
|
|
89
|
-
* <wc-chart-doughnut
|
|
22
|
+
* <wc-chart-doughnut label="Visitors by browser" center-label="Visitors"></wc-chart-doughnut>
|
|
90
23
|
* <script>
|
|
91
24
|
* document.querySelector('wc-chart-doughnut').data = [
|
|
92
|
-
* { name: '
|
|
93
|
-
* { name: '
|
|
94
|
-
* { name: '
|
|
25
|
+
* { name: 'chrome', label: 'Chrome', value: 275 },
|
|
26
|
+
* { name: 'safari', label: 'Safari', value: 200 },
|
|
27
|
+
* { name: 'firefox', label: 'Firefox', value: 187 },
|
|
95
28
|
* ];
|
|
96
29
|
* </script>
|
|
97
30
|
* ```
|
|
31
|
+
*
|
|
32
|
+
* @slot center - Replaces the total and caption in the centre.
|
|
33
|
+
* @slot empty - Shown when there is no data. Defaults to "No data".
|
|
34
|
+
*
|
|
35
|
+
* @fires chart-select - A slice was clicked or chosen with Enter. `detail` holds `index`, `series` (the slice name) and `datum`.
|
|
36
|
+
*
|
|
37
|
+
* @csspart container - The outer wrapper.
|
|
38
|
+
* @csspart plot - The focusable plot area holding the SVG.
|
|
39
|
+
* @csspart center - The centre content.
|
|
40
|
+
* @csspart tooltip - The tooltip.
|
|
41
|
+
* @csspart legend - The legend.
|
|
42
|
+
*
|
|
43
|
+
* @cssprop --color-chart-1 - Color of the first slice; slices cycle through `--color-chart-1` to `--color-chart-8`.
|
|
44
|
+
* @cssprop --chart-dim-opacity - Opacity of slices that are not hovered. Defaults to `0.4`.
|
|
98
45
|
*/
|
|
99
|
-
let ChartDoughnut = class ChartDoughnut extends
|
|
46
|
+
let ChartDoughnut = class ChartDoughnut extends ChartPie {
|
|
100
47
|
constructor() {
|
|
48
|
+
// ── Properties
|
|
101
49
|
super(...arguments);
|
|
102
|
-
/**
|
|
103
|
-
this.
|
|
104
|
-
/**
|
|
105
|
-
this.
|
|
106
|
-
/** Whether to show labels outside the chart. */
|
|
107
|
-
this.showLabels = true;
|
|
108
|
-
/** Chart data array. Each item should have name, value, and optional label and color. */
|
|
109
|
-
this.data = [];
|
|
110
|
-
this._initialized = false;
|
|
111
|
-
this._debouncedRenderChart = debounce(() => {
|
|
112
|
-
this._renderChart(true);
|
|
113
|
-
}, 300);
|
|
114
|
-
}
|
|
115
|
-
firstUpdated() {
|
|
116
|
-
this._renderChart(false);
|
|
117
|
-
}
|
|
118
|
-
updated(changedProperties) {
|
|
119
|
-
if (!this._initialized) {
|
|
120
|
-
this._initialized = true;
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const watchedProps = ['width', 'margin', 'showLabels', 'data'];
|
|
124
|
-
const hasChanged = watchedProps.some(prop => changedProperties.has(prop));
|
|
125
|
-
if (hasChanged) {
|
|
126
|
-
this._debouncedRenderChart();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
_getRadius() {
|
|
130
|
-
return this.width / 2 - this.margin - 100;
|
|
131
|
-
}
|
|
132
|
-
_getTotal() {
|
|
133
|
-
return this.data.reduce((total, d) => total + d.value, 0);
|
|
134
|
-
}
|
|
135
|
-
_getPieData() {
|
|
136
|
-
const pieGenerator = pie()
|
|
137
|
-
.sort(null)
|
|
138
|
-
.value(d => d.value);
|
|
139
|
-
return pieGenerator(this.data);
|
|
50
|
+
/** Size of the hole as a fraction of the radius. */
|
|
51
|
+
this.innerRadius = 0.62;
|
|
52
|
+
/** Caption under the total in the centre. */
|
|
53
|
+
this.centerLabel = 'Total';
|
|
140
54
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.outerRadius(radius);
|
|
158
|
-
const labelsArc = arc()
|
|
159
|
-
.innerRadius(radius + 10)
|
|
160
|
-
.outerRadius(radius + 10);
|
|
161
|
-
// Update SVG dimensions and center transform
|
|
162
|
-
svg.attr('width', this.width).attr('height', this.width);
|
|
163
|
-
svg
|
|
164
|
-
.select('.chart-container')
|
|
165
|
-
.attr('transform', `translate(${this.width / 2},${this.width / 2})`);
|
|
166
|
-
// Arc paths — keyed by name so D3 matches elements across updates
|
|
167
|
-
const $paths = svg
|
|
168
|
-
.select('.arc-container')
|
|
169
|
-
.selectAll('.arc')
|
|
170
|
-
.data(pieData, d => d.data.name)
|
|
171
|
-
.join('path')
|
|
172
|
-
.attr('class', 'arc')
|
|
173
|
-
.style('fill', d => d.data.color || colorScale(d.data.name).color);
|
|
174
|
-
if (animate) {
|
|
175
|
-
$paths
|
|
176
|
-
.transition()
|
|
177
|
-
.duration(DURATION)
|
|
178
|
-
.ease(cubicInOut)
|
|
179
|
-
.attrTween('d', function (d) {
|
|
180
|
-
const self = this;
|
|
181
|
-
// Interpolate from the last rendered angles to the new ones.
|
|
182
|
-
// New (entering) arcs start collapsed at their startAngle.
|
|
183
|
-
const prev = self._prevDatum ?? {
|
|
184
|
-
startAngle: d.startAngle,
|
|
185
|
-
endAngle: d.startAngle,
|
|
186
|
-
};
|
|
187
|
-
self._prevDatum = d;
|
|
188
|
-
const iStart = interpolateNumber(prev.startAngle, d.startAngle);
|
|
189
|
-
const iEnd = interpolateNumber(prev.endAngle, d.endAngle);
|
|
190
|
-
return (t) => doughnutArc({ ...d, startAngle: iStart(t), endAngle: iEnd(t) }) ??
|
|
191
|
-
'';
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
// Initial render: draw immediately and seed previous-datum for later tweens
|
|
196
|
-
$paths
|
|
197
|
-
.each(function (d) {
|
|
198
|
-
this._prevDatum = d;
|
|
199
|
-
})
|
|
200
|
-
.attr('d', d => doughnutArc(d) ?? '');
|
|
201
|
-
}
|
|
202
|
-
// Animate the central total counter
|
|
203
|
-
const $title = svg.select('.title');
|
|
204
|
-
if (animate) {
|
|
205
|
-
$title
|
|
206
|
-
.transition()
|
|
207
|
-
.duration(DURATION)
|
|
208
|
-
.ease(cubicInOut)
|
|
209
|
-
.tween('text', function () {
|
|
210
|
-
const sel = select(this);
|
|
211
|
-
const start = parseFloat(sel.text()) || 0;
|
|
212
|
-
const interp = interpolateNumber(start, total);
|
|
213
|
-
return function (t) {
|
|
214
|
-
sel.text(Math.round(interp(t)));
|
|
215
|
-
};
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
$title.text(total);
|
|
220
|
-
}
|
|
221
|
-
// Label polylines and text
|
|
222
|
-
const $chartContainer = svg.select('.chart-container');
|
|
223
|
-
if (this.showLabels) {
|
|
224
|
-
const pointsFn = (d) => {
|
|
225
|
-
const posA = doughnutArc.centroid(d);
|
|
226
|
-
const posB = labelsArc.centroid(d);
|
|
227
|
-
const posC = posB.slice();
|
|
228
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
229
|
-
posC[0] = radius * (midAngle < Math.PI ? 1 : -1);
|
|
230
|
-
return [posA, posB, posC].map(p => p.join(',')).join(' ');
|
|
231
|
-
};
|
|
232
|
-
const transformFn = (d) => {
|
|
233
|
-
const pos = labelsArc.centroid(d);
|
|
234
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
235
|
-
pos[0] = radius * (midAngle < Math.PI ? 1 : -1);
|
|
236
|
-
return `translate(${pos})`;
|
|
237
|
-
};
|
|
238
|
-
const anchorFn = (d) => {
|
|
239
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
240
|
-
return midAngle < Math.PI ? 'start' : 'end';
|
|
241
|
-
};
|
|
242
|
-
const $polylines = $chartContainer
|
|
243
|
-
.selectAll('.item-polyline')
|
|
244
|
-
.data(pieData, d => d.data.name)
|
|
245
|
-
.join('polyline')
|
|
246
|
-
.attr('class', 'item-polyline');
|
|
247
|
-
const $labels = $chartContainer
|
|
248
|
-
.selectAll('.item-label')
|
|
249
|
-
.data(pieData, d => d.data.name)
|
|
250
|
-
.join('text')
|
|
251
|
-
.attr('class', 'item-label')
|
|
252
|
-
.text(d => d.data.label ?? '');
|
|
253
|
-
if (animate) {
|
|
254
|
-
$polylines
|
|
255
|
-
.transition()
|
|
256
|
-
.duration(DURATION)
|
|
257
|
-
.ease(cubicInOut)
|
|
258
|
-
.attr('points', pointsFn);
|
|
259
|
-
$labels
|
|
260
|
-
.transition()
|
|
261
|
-
.duration(DURATION)
|
|
262
|
-
.ease(cubicInOut)
|
|
263
|
-
.attr('transform', transformFn)
|
|
264
|
-
.style('text-anchor', anchorFn);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
$polylines.attr('points', pointsFn);
|
|
268
|
-
$labels.attr('transform', transformFn).style('text-anchor', anchorFn);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
$chartContainer.selectAll('.item-polyline').remove();
|
|
273
|
-
$chartContainer.selectAll('.item-label').remove();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
render() {
|
|
277
|
-
return b `
|
|
278
|
-
<div class="chart">
|
|
279
|
-
<svg>
|
|
280
|
-
<g class="chart-container">
|
|
281
|
-
<g class="arc-container"></g>
|
|
282
|
-
<text class="title" text-anchor="middle"></text>
|
|
283
|
-
<text class="label" text-anchor="middle" y="16">
|
|
284
|
-
${this.label}
|
|
285
|
-
</text>
|
|
286
|
-
</g>
|
|
287
|
-
</svg>
|
|
288
|
-
</div>
|
|
289
|
-
`;
|
|
55
|
+
// ── Render helpers
|
|
56
|
+
renderOverlay() {
|
|
57
|
+
const active = this.activeIndex >= 0 ? this.data[this.activeIndex] : undefined;
|
|
58
|
+
const value = active ? active.value : this.visibleTotal();
|
|
59
|
+
const caption = active ? (active.label ?? active.name) : this.centerLabel;
|
|
60
|
+
const hole = Math.max(this.radius * this.innerRadius * 2 - 16, 0);
|
|
61
|
+
return b `<div
|
|
62
|
+
class="center"
|
|
63
|
+
part="center"
|
|
64
|
+
style=${o({ '--_center-width': `${hole}px` })}
|
|
65
|
+
>
|
|
66
|
+
<slot name="center">
|
|
67
|
+
<span class="center-value">${this.formatValue(value)}</span>
|
|
68
|
+
<span class="center-label">${caption}</span>
|
|
69
|
+
</slot>
|
|
70
|
+
</div>`;
|
|
290
71
|
}
|
|
291
72
|
};
|
|
292
|
-
ChartDoughnut.styles = [css_248z];
|
|
293
|
-
__decorate([
|
|
294
|
-
e('svg')
|
|
295
|
-
], ChartDoughnut.prototype, "svgElement", void 0);
|
|
296
|
-
__decorate([
|
|
297
|
-
n({ type: Number, reflect: true })
|
|
298
|
-
], ChartDoughnut.prototype, "width", void 0);
|
|
299
|
-
__decorate([
|
|
300
|
-
n({ type: Number, reflect: true })
|
|
301
|
-
], ChartDoughnut.prototype, "margin", void 0);
|
|
302
|
-
__decorate([
|
|
303
|
-
n({ type: Boolean, reflect: true, attribute: 'show-labels' })
|
|
304
|
-
], ChartDoughnut.prototype, "showLabels", void 0);
|
|
305
73
|
__decorate([
|
|
306
|
-
n({ type:
|
|
307
|
-
], ChartDoughnut.prototype, "
|
|
74
|
+
n({ type: Number, attribute: 'inner-radius' })
|
|
75
|
+
], ChartDoughnut.prototype, "innerRadius", void 0);
|
|
308
76
|
__decorate([
|
|
309
|
-
n({ type: String })
|
|
310
|
-
], ChartDoughnut.prototype, "
|
|
77
|
+
n({ type: String, attribute: 'center-label' })
|
|
78
|
+
], ChartDoughnut.prototype, "centerLabel", void 0);
|
|
311
79
|
ChartDoughnut = __decorate([
|
|
312
80
|
IndividualComponent
|
|
313
81
|
], ChartDoughnut);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-doughnut.js","sources":["../../src/chart-doughnut/chart-doughnut.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { select, arc, pie, scaleOrdinal, easeCubicInOut, interpolateNumber, PieArcDatum, BaseType } from 'd3';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './chart-donut.scss';\n\nexport type ChartDoughnutColor = {\n color: string;\n};\n\nexport type ChartDoughnutItem = {\n name: string;\n value: number;\n label?: string;\n color?: string;\n};\n\nconst chartColors: ChartDoughnutColor[] = [];\n['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {\n chartColors.push({\n color: `var(--color-${colorName})`,\n });\n});\n\n/** SVGPathElement augmented with the last rendered arc datum for smooth tween interpolation. */\ninterface ArcPathElement extends SVGPathElement {\n _prevDatum?: PieArcDatum<ChartDoughnutItem>;\n}\n\nfunction debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {\n let timer: ReturnType<typeof setTimeout>;\n return ((...args: any[]) => {\n clearTimeout(timer);\n timer = setTimeout(() => fn(...args), wait);\n }) as T;\n}\n\n/**\n * @label Chart Doughnut\n * @tag wc-chart-doughnut\n * @rawTag chart-doughnut\n * @summary A doughnut chart is a circular chart with a blank center. The area in the center can be used to display information.\n * @tags charts\n *\n * @example\n * ```html\n * <wc-chart-doughnut width=\"400\" label=\"Total\"></wc-chart-doughnut>\n * <script>\n * document.querySelector('wc-chart-doughnut').data = [\n * { name: 'A', value: 30, label: 'Category A' },\n * { name: 'B', value: 50, label: 'Category B' },\n * { name: 'C', value: 20, label: 'Category C' },\n * ];\n * </script>\n * ```\n */\n@IndividualComponent\nexport class ChartDoughnut extends LitElement {\n static styles = [styles];\n\n @query('svg')\n private svgElement?: SVGElement;\n\n /** Width (and height) of the chart in pixels. */\n @property({ type: Number, reflect: true }) width: number = 0;\n\n /** Margin around the chart. */\n @property({ type: Number, reflect: true }) margin: number = 10;\n\n /** Whether to show labels outside the chart. */\n @property({ type: Boolean, reflect: true, attribute: 'show-labels' })\n showLabels: boolean = true;\n\n /** Chart data array. Each item should have name, value, and optional label and color. */\n @property({ type: Array }) data: ChartDoughnutItem[] = [];\n\n /** Label displayed in the center of the doughnut. */\n @property({ type: String }) label?: string;\n\n private _initialized = false;\n\n private _debouncedRenderChart = debounce(() => {\n this._renderChart(true);\n }, 300);\n\n firstUpdated() {\n this._renderChart(false);\n }\n\n updated(changedProperties: PropertyValues) {\n if (!this._initialized) {\n this._initialized = true;\n return;\n }\n const watchedProps = ['width', 'margin', 'showLabels', 'data'];\n const hasChanged = watchedProps.some(prop => changedProperties.has(prop));\n if (hasChanged) {\n this._debouncedRenderChart();\n }\n }\n\n private _getRadius(): number {\n return this.width / 2 - this.margin - 100;\n }\n\n private _getTotal(): number {\n return this.data.reduce((total, d) => total + d.value, 0);\n }\n\n private _getPieData() {\n const pieGenerator = pie<ChartDoughnutItem>()\n .sort(null)\n .value(d => d.value);\n return pieGenerator(this.data);\n }\n\n private _getColorScale() {\n return scaleOrdinal<string, ChartDoughnutColor>()\n .domain(this.data.map(d => d.name))\n .range(chartColors);\n }\n\n private _renderChart(animate: boolean) {\n if (!this.svgElement) return;\n\n const DURATION = 500;\n const radius = this._getRadius();\n const pieData = this._getPieData();\n const colorScale = this._getColorScale();\n const total = this._getTotal();\n\n const svg = select(this.svgElement);\n\n const doughnutArc = arc<PieArcDatum<ChartDoughnutItem>>()\n .innerRadius(radius * 0.72)\n .outerRadius(radius);\n\n const labelsArc = arc<PieArcDatum<ChartDoughnutItem>>()\n .innerRadius(radius + 10)\n .outerRadius(radius + 10);\n\n // Update SVG dimensions and center transform\n svg.attr('width', this.width).attr('height', this.width);\n svg\n .select('.chart-container')\n .attr('transform', `translate(${this.width / 2},${this.width / 2})`);\n\n // Arc paths — keyed by name so D3 matches elements across updates\n const $paths = svg\n .select('.arc-container')\n .selectAll<SVGPathElement, PieArcDatum<ChartDoughnutItem>>('.arc')\n .data(pieData, d => d.data.name)\n .join('path')\n .attr('class', 'arc')\n .style('fill', d => d.data.color || colorScale(d.data.name).color);\n\n if (animate) {\n $paths\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .attrTween('d', function (this: SVGPathElement, d) {\n const self = this as ArcPathElement;\n // Interpolate from the last rendered angles to the new ones.\n // New (entering) arcs start collapsed at their startAngle.\n const prev: { startAngle: number; endAngle: number } =\n self._prevDatum ?? {\n startAngle: d.startAngle,\n endAngle: d.startAngle,\n };\n self._prevDatum = d;\n const iStart = interpolateNumber(prev.startAngle, d.startAngle);\n const iEnd = interpolateNumber(prev.endAngle, d.endAngle);\n return (t: number) =>\n doughnutArc({ ...d, startAngle: iStart(t), endAngle: iEnd(t) }) ??\n '';\n });\n } else {\n // Initial render: draw immediately and seed previous-datum for later tweens\n $paths\n .each(function (this: SVGPathElement, d) {\n (this as ArcPathElement)._prevDatum = d;\n })\n .attr('d', d => doughnutArc(d) ?? '');\n }\n\n // Animate the central total counter\n const $title = svg.select('.title');\n if (animate) {\n $title\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .tween('text', function (this: BaseType) {\n const sel = select(this as SVGTextElement);\n const start = parseFloat(sel.text()) || 0;\n const interp = interpolateNumber(start, total);\n return function (t: number) {\n sel.text(Math.round(interp(t)));\n };\n });\n } else {\n $title.text(total);\n }\n\n // Label polylines and text\n const $chartContainer = svg.select('.chart-container');\n\n if (this.showLabels) {\n const pointsFn = (d: PieArcDatum<ChartDoughnutItem>) => {\n const posA = doughnutArc.centroid(d);\n const posB = labelsArc.centroid(d);\n const posC = posB.slice() as [number, number];\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n posC[0] = radius * (midAngle < Math.PI ? 1 : -1);\n return [posA, posB, posC].map(p => p.join(',')).join(' ');\n };\n\n const transformFn = (d: PieArcDatum<ChartDoughnutItem>) => {\n const pos = labelsArc.centroid(d);\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n pos[0] = radius * (midAngle < Math.PI ? 1 : -1);\n return `translate(${pos})`;\n };\n\n const anchorFn = (d: PieArcDatum<ChartDoughnutItem>) => {\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n return midAngle < Math.PI ? 'start' : 'end';\n };\n\n const $polylines = $chartContainer\n .selectAll<SVGPolylineElement, PieArcDatum<ChartDoughnutItem>>(\n '.item-polyline',\n )\n .data(pieData, d => d.data.name)\n .join('polyline')\n .attr('class', 'item-polyline');\n\n const $labels = $chartContainer\n .selectAll<SVGTextElement, PieArcDatum<ChartDoughnutItem>>('.item-label')\n .data(pieData, d => d.data.name)\n .join('text')\n .attr('class', 'item-label')\n .text(d => d.data.label ?? '');\n\n if (animate) {\n $polylines\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .attr('points', pointsFn);\n $labels\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .attr('transform', transformFn)\n .style('text-anchor', anchorFn);\n } else {\n $polylines.attr('points', pointsFn);\n $labels.attr('transform', transformFn).style('text-anchor', anchorFn);\n }\n } else {\n $chartContainer.selectAll('.item-polyline').remove();\n $chartContainer.selectAll('.item-label').remove();\n }\n }\n\n render() {\n return html`\n <div class=\"chart\">\n <svg>\n <g class=\"chart-container\">\n <g class=\"arc-container\"></g>\n <text class=\"title\" text-anchor=\"middle\"></text>\n <text class=\"label\" text-anchor=\"middle\" y=\"16\">\n ${this.label}\n </text>\n </g>\n </svg>\n </div>\n `;\n }\n}\n"],"names":["LitElement","scaleOrdinal","easeCubicInOut","html","styles","query","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,WAAW,GAAyB,EAAE;AAC5C,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,IAAG;IACzE,WAAW,CAAC,IAAI,CAAC;QACf,KAAK,EAAE,CAAA,YAAA,EAAe,SAAS,CAAA,CAAA,CAAG;AACnC,KAAA,CAAC;AACJ,CAAC,CAAC;AAOF,SAAS,QAAQ,CAAqC,EAAK,EAAE,IAAY,EAAA;AACvE,IAAA,IAAI,KAAoC;AACxC,IAAA,QAAQ,CAAC,GAAG,IAAW,KAAI;QACzB,YAAY,CAAC,KAAK,CAAC;AACnB,QAAA,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC;AAC7C,IAAA,CAAC;AACH;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQA,GAAU,CAAA;AAAtC,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,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAsB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAI/D,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE;AACzC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGA,UAAA,CAAA;AAA1B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;AAAiC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAG9B,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAiB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AApBhC,aAAa,GAAA,UAAA,CAAA;IADzB;AACY,CAAA,EAAA,aAAa,CAiOzB;;;;"}
|
|
1
|
+
{"version":3,"file":"chart-doughnut.js","sources":["../../src/chart-doughnut/chart-doughnut.ts"],"sourcesContent":["import { html } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { ChartPie } from '../chart-pie/chart-pie.js';\n\nexport type {\n ChartPieItem,\n ChartSelectDetail,\n ChartValueFormatter,\n} from '../chart-pie/chart-pie.js';\n\n/**\n * @label Doughnut Chart\n * @tag wc-chart-doughnut\n * @rawTag chart-doughnut\n * @summary A pie chart with a hole that shows the total, or the hovered slice, in its centre.\n * @tags charts\n *\n * @example\n * ```html\n * <wc-chart-doughnut label=\"Visitors by browser\" center-label=\"Visitors\"></wc-chart-doughnut>\n * <script>\n * document.querySelector('wc-chart-doughnut').data = [\n * { name: 'chrome', label: 'Chrome', value: 275 },\n * { name: 'safari', label: 'Safari', value: 200 },\n * { name: 'firefox', label: 'Firefox', value: 187 },\n * ];\n * </script>\n * ```\n *\n * @slot center - Replaces the total and caption in the centre.\n * @slot empty - Shown when there is no data. Defaults to \"No data\".\n *\n * @fires chart-select - A slice was clicked or chosen with Enter. `detail` holds `index`, `series` (the slice name) and `datum`.\n *\n * @csspart container - The outer wrapper.\n * @csspart plot - The focusable plot area holding the SVG.\n * @csspart center - The centre content.\n * @csspart tooltip - The tooltip.\n * @csspart legend - The legend.\n *\n * @cssprop --color-chart-1 - Color of the first slice; slices cycle through `--color-chart-1` to `--color-chart-8`.\n * @cssprop --chart-dim-opacity - Opacity of slices that are not hovered. Defaults to `0.4`.\n */\n@IndividualComponent\nexport class ChartDoughnut extends ChartPie {\n // ── Properties\n\n /** Size of the hole as a fraction of the radius. */\n @property({ type: Number, attribute: 'inner-radius' }) innerRadius: number =\n 0.62;\n\n /** Caption under the total in the centre. */\n @property({ type: String, attribute: 'center-label' }) centerLabel: string =\n 'Total';\n\n // ── Render helpers\n\n protected renderOverlay() {\n const active =\n this.activeIndex >= 0 ? this.data[this.activeIndex] : undefined;\n const value = active ? active.value : this.visibleTotal();\n const caption = active ? (active.label ?? active.name) : this.centerLabel;\n const hole = Math.max(this.radius * this.innerRadius * 2 - 16, 0);\n return html`<div\n class=\"center\"\n part=\"center\"\n style=${styleMap({ '--_center-width': `${hole}px` })}\n >\n <slot name=\"center\">\n <span class=\"center-value\">${this.formatValue(value)}</span>\n <span class=\"center-label\">${caption}</span>\n </slot>\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'wc-chart-doughnut': ChartDoughnut;\n }\n}\n"],"names":["html","styleMap","property"],"mappings":";;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,QAAQ,CAAA;AAApC,IAAA,WAAA,GAAA;;;;QAIkD,IAAA,CAAA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