@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
|
@@ -1,283 +1,83 @@
|
|
|
1
|
-
import { html
|
|
2
|
-
import { property
|
|
3
|
-
import {
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
4
4
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
5
|
-
import
|
|
5
|
+
import { ChartPie } from '../chart-pie/chart-pie.js';
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
name: string;
|
|
13
|
-
value: number;
|
|
14
|
-
label?: string;
|
|
15
|
-
color?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const chartColors: ChartDoughnutColor[] = [];
|
|
19
|
-
['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {
|
|
20
|
-
chartColors.push({
|
|
21
|
-
color: `var(--color-${colorName})`,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
/** SVGPathElement augmented with the last rendered arc datum for smooth tween interpolation. */
|
|
26
|
-
interface ArcPathElement extends SVGPathElement {
|
|
27
|
-
_prevDatum?: PieArcDatum<ChartDoughnutItem>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {
|
|
31
|
-
let timer: ReturnType<typeof setTimeout>;
|
|
32
|
-
return ((...args: any[]) => {
|
|
33
|
-
clearTimeout(timer);
|
|
34
|
-
timer = setTimeout(() => fn(...args), wait);
|
|
35
|
-
}) as T;
|
|
36
|
-
}
|
|
7
|
+
export type {
|
|
8
|
+
ChartPieItem,
|
|
9
|
+
ChartSelectDetail,
|
|
10
|
+
ChartValueFormatter,
|
|
11
|
+
} from '../chart-pie/chart-pie.js';
|
|
37
12
|
|
|
38
13
|
/**
|
|
39
|
-
* @label Chart
|
|
14
|
+
* @label Doughnut Chart
|
|
40
15
|
* @tag wc-chart-doughnut
|
|
41
16
|
* @rawTag chart-doughnut
|
|
42
|
-
* @summary A
|
|
17
|
+
* @summary A pie chart with a hole that shows the total, or the hovered slice, in its centre.
|
|
43
18
|
* @tags charts
|
|
44
19
|
*
|
|
45
20
|
* @example
|
|
46
21
|
* ```html
|
|
47
|
-
* <wc-chart-doughnut
|
|
22
|
+
* <wc-chart-doughnut label="Visitors by browser" center-label="Visitors"></wc-chart-doughnut>
|
|
48
23
|
* <script>
|
|
49
24
|
* document.querySelector('wc-chart-doughnut').data = [
|
|
50
|
-
* { name: '
|
|
51
|
-
* { name: '
|
|
52
|
-
* { name: '
|
|
25
|
+
* { name: 'chrome', label: 'Chrome', value: 275 },
|
|
26
|
+
* { name: 'safari', label: 'Safari', value: 200 },
|
|
27
|
+
* { name: 'firefox', label: 'Firefox', value: 187 },
|
|
53
28
|
* ];
|
|
54
29
|
* </script>
|
|
55
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`.
|
|
56
45
|
*/
|
|
57
46
|
@IndividualComponent
|
|
58
|
-
export class ChartDoughnut extends
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this._renderChart(false);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
updated(changedProperties: PropertyValues) {
|
|
91
|
-
if (!this._initialized) {
|
|
92
|
-
this._initialized = true;
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const watchedProps = ['width', 'margin', 'showLabels', 'data'];
|
|
96
|
-
const hasChanged = watchedProps.some(prop => changedProperties.has(prop));
|
|
97
|
-
if (hasChanged) {
|
|
98
|
-
this._debouncedRenderChart();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private _getRadius(): number {
|
|
103
|
-
return this.width / 2 - this.margin - 100;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private _getTotal(): number {
|
|
107
|
-
return this.data.reduce((total, d) => total + d.value, 0);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private _getPieData() {
|
|
111
|
-
const pieGenerator = pie<ChartDoughnutItem>()
|
|
112
|
-
.sort(null)
|
|
113
|
-
.value(d => d.value);
|
|
114
|
-
return pieGenerator(this.data);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private _getColorScale() {
|
|
118
|
-
return scaleOrdinal<string, ChartDoughnutColor>()
|
|
119
|
-
.domain(this.data.map(d => d.name))
|
|
120
|
-
.range(chartColors);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private _renderChart(animate: boolean) {
|
|
124
|
-
if (!this.svgElement) return;
|
|
125
|
-
|
|
126
|
-
const DURATION = 500;
|
|
127
|
-
const radius = this._getRadius();
|
|
128
|
-
const pieData = this._getPieData();
|
|
129
|
-
const colorScale = this._getColorScale();
|
|
130
|
-
const total = this._getTotal();
|
|
131
|
-
|
|
132
|
-
const svg = select(this.svgElement);
|
|
133
|
-
|
|
134
|
-
const doughnutArc = arc<PieArcDatum<ChartDoughnutItem>>()
|
|
135
|
-
.innerRadius(radius * 0.72)
|
|
136
|
-
.outerRadius(radius);
|
|
137
|
-
|
|
138
|
-
const labelsArc = arc<PieArcDatum<ChartDoughnutItem>>()
|
|
139
|
-
.innerRadius(radius + 10)
|
|
140
|
-
.outerRadius(radius + 10);
|
|
141
|
-
|
|
142
|
-
// Update SVG dimensions and center transform
|
|
143
|
-
svg.attr('width', this.width).attr('height', this.width);
|
|
144
|
-
svg
|
|
145
|
-
.select('.chart-container')
|
|
146
|
-
.attr('transform', `translate(${this.width / 2},${this.width / 2})`);
|
|
147
|
-
|
|
148
|
-
// Arc paths — keyed by name so D3 matches elements across updates
|
|
149
|
-
const $paths = svg
|
|
150
|
-
.select('.arc-container')
|
|
151
|
-
.selectAll<SVGPathElement, PieArcDatum<ChartDoughnutItem>>('.arc')
|
|
152
|
-
.data(pieData, d => d.data.name)
|
|
153
|
-
.join('path')
|
|
154
|
-
.attr('class', 'arc')
|
|
155
|
-
.style('fill', d => d.data.color || colorScale(d.data.name).color);
|
|
156
|
-
|
|
157
|
-
if (animate) {
|
|
158
|
-
$paths
|
|
159
|
-
.transition()
|
|
160
|
-
.duration(DURATION)
|
|
161
|
-
.ease(easeCubicInOut)
|
|
162
|
-
.attrTween('d', function (this: SVGPathElement, d) {
|
|
163
|
-
const self = this as ArcPathElement;
|
|
164
|
-
// Interpolate from the last rendered angles to the new ones.
|
|
165
|
-
// New (entering) arcs start collapsed at their startAngle.
|
|
166
|
-
const prev: { startAngle: number; endAngle: number } =
|
|
167
|
-
self._prevDatum ?? {
|
|
168
|
-
startAngle: d.startAngle,
|
|
169
|
-
endAngle: d.startAngle,
|
|
170
|
-
};
|
|
171
|
-
self._prevDatum = d;
|
|
172
|
-
const iStart = interpolateNumber(prev.startAngle, d.startAngle);
|
|
173
|
-
const iEnd = interpolateNumber(prev.endAngle, d.endAngle);
|
|
174
|
-
return (t: number) =>
|
|
175
|
-
doughnutArc({ ...d, startAngle: iStart(t), endAngle: iEnd(t) }) ??
|
|
176
|
-
'';
|
|
177
|
-
});
|
|
178
|
-
} else {
|
|
179
|
-
// Initial render: draw immediately and seed previous-datum for later tweens
|
|
180
|
-
$paths
|
|
181
|
-
.each(function (this: SVGPathElement, d) {
|
|
182
|
-
(this as ArcPathElement)._prevDatum = d;
|
|
183
|
-
})
|
|
184
|
-
.attr('d', d => doughnutArc(d) ?? '');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Animate the central total counter
|
|
188
|
-
const $title = svg.select('.title');
|
|
189
|
-
if (animate) {
|
|
190
|
-
$title
|
|
191
|
-
.transition()
|
|
192
|
-
.duration(DURATION)
|
|
193
|
-
.ease(easeCubicInOut)
|
|
194
|
-
.tween('text', function (this: BaseType) {
|
|
195
|
-
const sel = select(this as SVGTextElement);
|
|
196
|
-
const start = parseFloat(sel.text()) || 0;
|
|
197
|
-
const interp = interpolateNumber(start, total);
|
|
198
|
-
return function (t: number) {
|
|
199
|
-
sel.text(Math.round(interp(t)));
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
} else {
|
|
203
|
-
$title.text(total);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Label polylines and text
|
|
207
|
-
const $chartContainer = svg.select('.chart-container');
|
|
208
|
-
|
|
209
|
-
if (this.showLabels) {
|
|
210
|
-
const pointsFn = (d: PieArcDatum<ChartDoughnutItem>) => {
|
|
211
|
-
const posA = doughnutArc.centroid(d);
|
|
212
|
-
const posB = labelsArc.centroid(d);
|
|
213
|
-
const posC = posB.slice() as [number, number];
|
|
214
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
215
|
-
posC[0] = radius * (midAngle < Math.PI ? 1 : -1);
|
|
216
|
-
return [posA, posB, posC].map(p => p.join(',')).join(' ');
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const transformFn = (d: PieArcDatum<ChartDoughnutItem>) => {
|
|
220
|
-
const pos = labelsArc.centroid(d);
|
|
221
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
222
|
-
pos[0] = radius * (midAngle < Math.PI ? 1 : -1);
|
|
223
|
-
return `translate(${pos})`;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const anchorFn = (d: PieArcDatum<ChartDoughnutItem>) => {
|
|
227
|
-
const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
228
|
-
return midAngle < Math.PI ? 'start' : 'end';
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const $polylines = $chartContainer
|
|
232
|
-
.selectAll<SVGPolylineElement, PieArcDatum<ChartDoughnutItem>>(
|
|
233
|
-
'.item-polyline',
|
|
234
|
-
)
|
|
235
|
-
.data(pieData, d => d.data.name)
|
|
236
|
-
.join('polyline')
|
|
237
|
-
.attr('class', 'item-polyline');
|
|
238
|
-
|
|
239
|
-
const $labels = $chartContainer
|
|
240
|
-
.selectAll<SVGTextElement, PieArcDatum<ChartDoughnutItem>>('.item-label')
|
|
241
|
-
.data(pieData, d => d.data.name)
|
|
242
|
-
.join('text')
|
|
243
|
-
.attr('class', 'item-label')
|
|
244
|
-
.text(d => d.data.label ?? '');
|
|
245
|
-
|
|
246
|
-
if (animate) {
|
|
247
|
-
$polylines
|
|
248
|
-
.transition()
|
|
249
|
-
.duration(DURATION)
|
|
250
|
-
.ease(easeCubicInOut)
|
|
251
|
-
.attr('points', pointsFn);
|
|
252
|
-
$labels
|
|
253
|
-
.transition()
|
|
254
|
-
.duration(DURATION)
|
|
255
|
-
.ease(easeCubicInOut)
|
|
256
|
-
.attr('transform', transformFn)
|
|
257
|
-
.style('text-anchor', anchorFn);
|
|
258
|
-
} else {
|
|
259
|
-
$polylines.attr('points', pointsFn);
|
|
260
|
-
$labels.attr('transform', transformFn).style('text-anchor', anchorFn);
|
|
261
|
-
}
|
|
262
|
-
} else {
|
|
263
|
-
$chartContainer.selectAll('.item-polyline').remove();
|
|
264
|
-
$chartContainer.selectAll('.item-label').remove();
|
|
265
|
-
}
|
|
47
|
+
export class ChartDoughnut extends ChartPie {
|
|
48
|
+
// ── Properties
|
|
49
|
+
|
|
50
|
+
/** Size of the hole as a fraction of the radius. */
|
|
51
|
+
@property({ type: Number, attribute: 'inner-radius' }) innerRadius: number =
|
|
52
|
+
0.62;
|
|
53
|
+
|
|
54
|
+
/** Caption under the total in the centre. */
|
|
55
|
+
@property({ type: String, attribute: 'center-label' }) centerLabel: string =
|
|
56
|
+
'Total';
|
|
57
|
+
|
|
58
|
+
// ── Render helpers
|
|
59
|
+
|
|
60
|
+
protected renderOverlay() {
|
|
61
|
+
const active =
|
|
62
|
+
this.activeIndex >= 0 ? this.data[this.activeIndex] : undefined;
|
|
63
|
+
const value = active ? active.value : this.visibleTotal();
|
|
64
|
+
const caption = active ? (active.label ?? active.name) : this.centerLabel;
|
|
65
|
+
const hole = Math.max(this.radius * this.innerRadius * 2 - 16, 0);
|
|
66
|
+
return html`<div
|
|
67
|
+
class="center"
|
|
68
|
+
part="center"
|
|
69
|
+
style=${styleMap({ '--_center-width': `${hole}px` })}
|
|
70
|
+
>
|
|
71
|
+
<slot name="center">
|
|
72
|
+
<span class="center-value">${this.formatValue(value)}</span>
|
|
73
|
+
<span class="center-label">${caption}</span>
|
|
74
|
+
</slot>
|
|
75
|
+
</div>`;
|
|
266
76
|
}
|
|
77
|
+
}
|
|
267
78
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
<svg>
|
|
272
|
-
<g class="chart-container">
|
|
273
|
-
<g class="arc-container"></g>
|
|
274
|
-
<text class="title" text-anchor="middle"></text>
|
|
275
|
-
<text class="label" text-anchor="middle" y="16">
|
|
276
|
-
${this.label}
|
|
277
|
-
</text>
|
|
278
|
-
</g>
|
|
279
|
-
</svg>
|
|
280
|
-
</div>
|
|
281
|
-
`;
|
|
79
|
+
declare global {
|
|
80
|
+
interface HTMLElementTagNameMap {
|
|
81
|
+
'wc-chart-doughnut': ChartDoughnut;
|
|
282
82
|
}
|
|
283
83
|
}
|
|
@@ -4,47 +4,39 @@
|
|
|
4
4
|
<meta charset='utf-8'>
|
|
5
5
|
<meta name='viewport' content='width=device-width, initial-scale=1.0, viewport-fit=cover' />
|
|
6
6
|
<link rel='stylesheet' href='/dist/assets/styles.css' />
|
|
7
|
-
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
|
|
8
|
-
|
|
9
7
|
<style>
|
|
10
8
|
body {
|
|
11
|
-
background:
|
|
9
|
+
background: var(--color-surface);
|
|
10
|
+
max-width: 480px;
|
|
11
|
+
margin: 2rem auto;
|
|
12
12
|
}
|
|
13
13
|
</style>
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
|
|
17
|
-
<wc-button id=
|
|
18
|
-
<br />
|
|
17
|
+
<wc-button id='randomize'>Randomize</wc-button>
|
|
19
18
|
|
|
20
|
-
<wc-chart-doughnut
|
|
19
|
+
<wc-chart-doughnut label='Visitors by browser' center-label='Visitors'></wc-chart-doughnut>
|
|
21
20
|
|
|
22
21
|
<script>
|
|
23
22
|
const chart = document.querySelector('wc-chart-doughnut');
|
|
24
|
-
chart.label = "Browsers";
|
|
25
23
|
chart.data = [
|
|
26
|
-
{
|
|
27
|
-
{
|
|
28
|
-
{
|
|
29
|
-
{
|
|
30
|
-
{
|
|
24
|
+
{ name: 'chrome', label: 'Chrome', value: 275 },
|
|
25
|
+
{ name: 'safari', label: 'Safari', value: 200 },
|
|
26
|
+
{ name: 'firefox', label: 'Firefox', value: 187 },
|
|
27
|
+
{ name: 'edge', label: 'Edge', value: 173 },
|
|
28
|
+
{ name: 'other', label: 'Other', value: 90 },
|
|
31
29
|
];
|
|
32
30
|
|
|
33
|
-
function randomNumber(min, max) {
|
|
34
|
-
return parseInt(Math.random() * (max - min) + min);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let count = 1;
|
|
38
31
|
document.querySelector('#randomize').addEventListener('click', () => {
|
|
39
|
-
chart.data = chart.data.map(d => ({ ...d, value:
|
|
40
|
-
chart.width = randomNumber(400, 600);
|
|
32
|
+
chart.data = chart.data.map(d => ({ ...d, value: Math.round(Math.random() * 300) + 20 }));
|
|
41
33
|
});
|
|
42
34
|
</script>
|
|
43
35
|
|
|
44
|
-
|
|
45
36
|
<script type='module'>
|
|
46
|
-
import { Button
|
|
47
|
-
|
|
37
|
+
import { Button } from '/dist/button.js';
|
|
38
|
+
import { ChartDoughnut } from '/dist/chart-doughnut.js';
|
|
39
|
+
window.customElements.define('wc-chart-doughnut', ChartDoughnut);
|
|
48
40
|
window.customElements.define('wc-button', Button);
|
|
49
41
|
</script>
|
|
50
42
|
</body>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--_chart-line-width: var(--chart-line-width, 2px);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.line {
|
|
6
|
+
fill: none;
|
|
7
|
+
stroke-width: var(--_chart-line-width);
|
|
8
|
+
stroke-linecap: round;
|
|
9
|
+
stroke-linejoin: round;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.stop-start {
|
|
13
|
+
stop-opacity: 0.4;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.stop-end {
|
|
17
|
+
stop-opacity: 0.02;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.dot,
|
|
21
|
+
.active-dot {
|
|
22
|
+
stroke: var(--color-surface);
|
|
23
|
+
stroke-width: 2px;
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
}
|