@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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { f as interpolateNumber, i as interpolate, a as constant, b as array, C as ChartBase, d as chartColor, s as select } from './chart-base-C2qRMF48.js';
|
|
2
|
+
import { _ as __decorate, w, b } from './IndividualComponent-Bdwyrvd6.js';
|
|
3
|
+
import { n } from './property-B49QQ8pS.js';
|
|
3
4
|
|
|
4
5
|
function ascending(a, b) {
|
|
5
6
|
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
|
@@ -67,13 +68,58 @@ function zero() {
|
|
|
67
68
|
return 0;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
function number$
|
|
71
|
+
function number$1(x) {
|
|
71
72
|
return x === null ? NaN : +x;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
const ascendingBisect = bisector(ascending);
|
|
75
76
|
const bisectRight = ascendingBisect.right;
|
|
76
|
-
bisector(number$
|
|
77
|
+
bisector(number$1).center;
|
|
78
|
+
|
|
79
|
+
class InternMap extends Map {
|
|
80
|
+
constructor(entries, key = keyof) {
|
|
81
|
+
super();
|
|
82
|
+
Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
|
|
83
|
+
if (entries != null) for (const [key, value] of entries) this.set(key, value);
|
|
84
|
+
}
|
|
85
|
+
get(key) {
|
|
86
|
+
return super.get(intern_get(this, key));
|
|
87
|
+
}
|
|
88
|
+
has(key) {
|
|
89
|
+
return super.has(intern_get(this, key));
|
|
90
|
+
}
|
|
91
|
+
set(key, value) {
|
|
92
|
+
return super.set(intern_set(this, key), value);
|
|
93
|
+
}
|
|
94
|
+
delete(key) {
|
|
95
|
+
return super.delete(intern_delete(this, key));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function intern_get({_intern, _key}, value) {
|
|
100
|
+
const key = _key(value);
|
|
101
|
+
return _intern.has(key) ? _intern.get(key) : value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function intern_set({_intern, _key}, value) {
|
|
105
|
+
const key = _key(value);
|
|
106
|
+
if (_intern.has(key)) return _intern.get(key);
|
|
107
|
+
_intern.set(key, value);
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function intern_delete({_intern, _key}, value) {
|
|
112
|
+
const key = _key(value);
|
|
113
|
+
if (_intern.has(key)) {
|
|
114
|
+
value = _intern.get(key);
|
|
115
|
+
_intern.delete(key);
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function keyof(value) {
|
|
121
|
+
return value !== null && typeof value === "object" ? value.valueOf() : value;
|
|
122
|
+
}
|
|
77
123
|
|
|
78
124
|
const e10 = Math.sqrt(50),
|
|
79
125
|
e5 = Math.sqrt(10),
|
|
@@ -152,6 +198,19 @@ function max(values, valueof) {
|
|
|
152
198
|
return max;
|
|
153
199
|
}
|
|
154
200
|
|
|
201
|
+
function min(values, valueof) {
|
|
202
|
+
let min;
|
|
203
|
+
{
|
|
204
|
+
for (const value of values) {
|
|
205
|
+
if (value != null
|
|
206
|
+
&& (min > value || (min === undefined && value >= value))) {
|
|
207
|
+
min = value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return min;
|
|
212
|
+
}
|
|
213
|
+
|
|
155
214
|
function range(start, stop, step) {
|
|
156
215
|
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
|
157
216
|
|
|
@@ -166,248 +225,6 @@ function range(start, stop, step) {
|
|
|
166
225
|
return range;
|
|
167
226
|
}
|
|
168
227
|
|
|
169
|
-
function identity$2(x) {
|
|
170
|
-
return x;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
var top = 1,
|
|
174
|
-
right = 2,
|
|
175
|
-
bottom = 3,
|
|
176
|
-
left = 4,
|
|
177
|
-
epsilon = 1e-6;
|
|
178
|
-
|
|
179
|
-
function translateX(x) {
|
|
180
|
-
return "translate(" + x + ",0)";
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function translateY(y) {
|
|
184
|
-
return "translate(0," + y + ")";
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function number$1(scale) {
|
|
188
|
-
return d => +scale(d);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function center(scale, offset) {
|
|
192
|
-
offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
|
|
193
|
-
if (scale.round()) offset = Math.round(offset);
|
|
194
|
-
return d => +scale(d) + offset;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function entering() {
|
|
198
|
-
return !this.__axis;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function axis(orient, scale) {
|
|
202
|
-
var tickArguments = [],
|
|
203
|
-
tickValues = null,
|
|
204
|
-
tickFormat = null,
|
|
205
|
-
tickSizeInner = 6,
|
|
206
|
-
tickSizeOuter = 6,
|
|
207
|
-
tickPadding = 3,
|
|
208
|
-
offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
|
|
209
|
-
k = orient === top || orient === left ? -1 : 1,
|
|
210
|
-
x = orient === left || orient === right ? "x" : "y",
|
|
211
|
-
transform = orient === top || orient === bottom ? translateX : translateY;
|
|
212
|
-
|
|
213
|
-
function axis(context) {
|
|
214
|
-
var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
|
|
215
|
-
format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$2) : tickFormat,
|
|
216
|
-
spacing = Math.max(tickSizeInner, 0) + tickPadding,
|
|
217
|
-
range = scale.range(),
|
|
218
|
-
range0 = +range[0] + offset,
|
|
219
|
-
range1 = +range[range.length - 1] + offset,
|
|
220
|
-
position = (scale.bandwidth ? center : number$1)(scale.copy(), offset),
|
|
221
|
-
selection = context.selection ? context.selection() : context,
|
|
222
|
-
path = selection.selectAll(".domain").data([null]),
|
|
223
|
-
tick = selection.selectAll(".tick").data(values, scale).order(),
|
|
224
|
-
tickExit = tick.exit(),
|
|
225
|
-
tickEnter = tick.enter().append("g").attr("class", "tick"),
|
|
226
|
-
line = tick.select("line"),
|
|
227
|
-
text = tick.select("text");
|
|
228
|
-
|
|
229
|
-
path = path.merge(path.enter().insert("path", ".tick")
|
|
230
|
-
.attr("class", "domain")
|
|
231
|
-
.attr("stroke", "currentColor"));
|
|
232
|
-
|
|
233
|
-
tick = tick.merge(tickEnter);
|
|
234
|
-
|
|
235
|
-
line = line.merge(tickEnter.append("line")
|
|
236
|
-
.attr("stroke", "currentColor")
|
|
237
|
-
.attr(x + "2", k * tickSizeInner));
|
|
238
|
-
|
|
239
|
-
text = text.merge(tickEnter.append("text")
|
|
240
|
-
.attr("fill", "currentColor")
|
|
241
|
-
.attr(x, k * spacing)
|
|
242
|
-
.attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
|
|
243
|
-
|
|
244
|
-
if (context !== selection) {
|
|
245
|
-
path = path.transition(context);
|
|
246
|
-
tick = tick.transition(context);
|
|
247
|
-
line = line.transition(context);
|
|
248
|
-
text = text.transition(context);
|
|
249
|
-
|
|
250
|
-
tickExit = tickExit.transition(context)
|
|
251
|
-
.attr("opacity", epsilon)
|
|
252
|
-
.attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
|
|
253
|
-
|
|
254
|
-
tickEnter
|
|
255
|
-
.attr("opacity", epsilon)
|
|
256
|
-
.attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
tickExit.remove();
|
|
260
|
-
|
|
261
|
-
path
|
|
262
|
-
.attr("d", orient === left || orient === right
|
|
263
|
-
? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
|
|
264
|
-
: (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
|
|
265
|
-
|
|
266
|
-
tick
|
|
267
|
-
.attr("opacity", 1)
|
|
268
|
-
.attr("transform", function(d) { return transform(position(d) + offset); });
|
|
269
|
-
|
|
270
|
-
line
|
|
271
|
-
.attr(x + "2", k * tickSizeInner);
|
|
272
|
-
|
|
273
|
-
text
|
|
274
|
-
.attr(x, k * spacing)
|
|
275
|
-
.text(format);
|
|
276
|
-
|
|
277
|
-
selection.filter(entering)
|
|
278
|
-
.attr("fill", "none")
|
|
279
|
-
.attr("font-size", 10)
|
|
280
|
-
.attr("font-family", "sans-serif")
|
|
281
|
-
.attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
|
|
282
|
-
|
|
283
|
-
selection
|
|
284
|
-
.each(function() { this.__axis = position; });
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
axis.scale = function(_) {
|
|
288
|
-
return arguments.length ? (scale = _, axis) : scale;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
axis.ticks = function() {
|
|
292
|
-
return tickArguments = Array.from(arguments), axis;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
axis.tickArguments = function(_) {
|
|
296
|
-
return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
axis.tickValues = function(_) {
|
|
300
|
-
return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
axis.tickFormat = function(_) {
|
|
304
|
-
return arguments.length ? (tickFormat = _, axis) : tickFormat;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
axis.tickSize = function(_) {
|
|
308
|
-
return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
axis.tickSizeInner = function(_) {
|
|
312
|
-
return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
axis.tickSizeOuter = function(_) {
|
|
316
|
-
return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
axis.tickPadding = function(_) {
|
|
320
|
-
return arguments.length ? (tickPadding = +_, axis) : tickPadding;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
axis.offset = function(_) {
|
|
324
|
-
return arguments.length ? (offset = +_, axis) : offset;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
return axis;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function axisBottom(scale) {
|
|
331
|
-
return axis(bottom, scale);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function axisLeft(scale) {
|
|
335
|
-
return axis(left, scale);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function numberArray(a, b) {
|
|
339
|
-
if (!b) b = [];
|
|
340
|
-
var n = a ? Math.min(b.length, a.length) : 0,
|
|
341
|
-
c = b.slice(),
|
|
342
|
-
i;
|
|
343
|
-
return function(t) {
|
|
344
|
-
for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
|
|
345
|
-
return c;
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function isNumberArray(x) {
|
|
350
|
-
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function genericArray(a, b) {
|
|
354
|
-
var nb = b ? b.length : 0,
|
|
355
|
-
na = a ? Math.min(nb, a.length) : 0,
|
|
356
|
-
x = new Array(na),
|
|
357
|
-
c = new Array(nb),
|
|
358
|
-
i;
|
|
359
|
-
|
|
360
|
-
for (i = 0; i < na; ++i) x[i] = interpolate(a[i], b[i]);
|
|
361
|
-
for (; i < nb; ++i) c[i] = b[i];
|
|
362
|
-
|
|
363
|
-
return function(t) {
|
|
364
|
-
for (i = 0; i < na; ++i) c[i] = x[i](t);
|
|
365
|
-
return c;
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function date(a, b) {
|
|
370
|
-
var d = new Date;
|
|
371
|
-
return a = +a, b = +b, function(t) {
|
|
372
|
-
return d.setTime(a * (1 - t) + b * t), d;
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
function object(a, b) {
|
|
377
|
-
var i = {},
|
|
378
|
-
c = {},
|
|
379
|
-
k;
|
|
380
|
-
|
|
381
|
-
if (a === null || typeof a !== "object") a = {};
|
|
382
|
-
if (b === null || typeof b !== "object") b = {};
|
|
383
|
-
|
|
384
|
-
for (k in b) {
|
|
385
|
-
if (k in a) {
|
|
386
|
-
i[k] = interpolate(a[k], b[k]);
|
|
387
|
-
} else {
|
|
388
|
-
c[k] = b[k];
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return function(t) {
|
|
393
|
-
for (k in i) c[k] = i[k](t);
|
|
394
|
-
return c;
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function interpolate(a, b) {
|
|
399
|
-
var t = typeof b, c;
|
|
400
|
-
return b == null || t === "boolean" ? constant(b)
|
|
401
|
-
: (t === "number" ? interpolateNumber
|
|
402
|
-
: t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
|
|
403
|
-
: b instanceof color ? interpolateRgb
|
|
404
|
-
: b instanceof Date ? date
|
|
405
|
-
: isNumberArray(b) ? numberArray
|
|
406
|
-
: Array.isArray(b) ? genericArray
|
|
407
|
-
: typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
|
|
408
|
-
: interpolateNumber)(a, b);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
228
|
function interpolateRound(a, b) {
|
|
412
229
|
return a = +a, b = +b, function(t) {
|
|
413
230
|
return Math.round(a * (1 - t) + b * t);
|
|
@@ -740,6 +557,59 @@ function precisionRound(step, max) {
|
|
|
740
557
|
return Math.max(0, exponent(max) - exponent(step)) + 1;
|
|
741
558
|
}
|
|
742
559
|
|
|
560
|
+
function initRange(domain, range) {
|
|
561
|
+
switch (arguments.length) {
|
|
562
|
+
case 0: break;
|
|
563
|
+
case 1: this.range(domain); break;
|
|
564
|
+
default: this.range(range).domain(domain); break;
|
|
565
|
+
}
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const implicit = Symbol("implicit");
|
|
570
|
+
|
|
571
|
+
function ordinal() {
|
|
572
|
+
var index = new InternMap(),
|
|
573
|
+
domain = [],
|
|
574
|
+
range = [],
|
|
575
|
+
unknown = implicit;
|
|
576
|
+
|
|
577
|
+
function scale(d) {
|
|
578
|
+
let i = index.get(d);
|
|
579
|
+
if (i === undefined) {
|
|
580
|
+
if (unknown !== implicit) return unknown;
|
|
581
|
+
index.set(d, i = domain.push(d) - 1);
|
|
582
|
+
}
|
|
583
|
+
return range[i % range.length];
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
scale.domain = function(_) {
|
|
587
|
+
if (!arguments.length) return domain.slice();
|
|
588
|
+
domain = [], index = new InternMap();
|
|
589
|
+
for (const value of _) {
|
|
590
|
+
if (index.has(value)) continue;
|
|
591
|
+
index.set(value, domain.push(value) - 1);
|
|
592
|
+
}
|
|
593
|
+
return scale;
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
scale.range = function(_) {
|
|
597
|
+
return arguments.length ? (range = Array.from(_), scale) : range.slice();
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
scale.unknown = function(_) {
|
|
601
|
+
return arguments.length ? (unknown = _, scale) : unknown;
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
scale.copy = function() {
|
|
605
|
+
return ordinal(domain, range).unknown(unknown);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
initRange.apply(scale, arguments);
|
|
609
|
+
|
|
610
|
+
return scale;
|
|
611
|
+
}
|
|
612
|
+
|
|
743
613
|
function band() {
|
|
744
614
|
var scale = ordinal().unknown(undefined),
|
|
745
615
|
domain = scale.domain,
|
|
@@ -820,6 +690,24 @@ function band() {
|
|
|
820
690
|
return initRange.apply(rescale(), arguments);
|
|
821
691
|
}
|
|
822
692
|
|
|
693
|
+
function pointish(scale) {
|
|
694
|
+
var copy = scale.copy;
|
|
695
|
+
|
|
696
|
+
scale.padding = scale.paddingOuter;
|
|
697
|
+
delete scale.paddingInner;
|
|
698
|
+
delete scale.paddingOuter;
|
|
699
|
+
|
|
700
|
+
scale.copy = function() {
|
|
701
|
+
return pointish(copy());
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
return scale;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function point() {
|
|
708
|
+
return pointish(band.apply(null, arguments).paddingInner(1));
|
|
709
|
+
}
|
|
710
|
+
|
|
823
711
|
function constants(x) {
|
|
824
712
|
return function() {
|
|
825
713
|
return x;
|
|
@@ -1044,83 +932,412 @@ function linear() {
|
|
|
1044
932
|
return linearish(scale);
|
|
1045
933
|
}
|
|
1046
934
|
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
935
|
+
function stackOffsetNone(series, order) {
|
|
936
|
+
if (!((n = series.length) > 1)) return;
|
|
937
|
+
for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
|
938
|
+
s0 = s1, s1 = series[order[i]];
|
|
939
|
+
for (j = 0; j < m; ++j) {
|
|
940
|
+
s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
|
|
941
|
+
}
|
|
942
|
+
}
|
|
1050
943
|
}
|
|
1051
944
|
|
|
1052
|
-
|
|
1053
|
-
|
|
945
|
+
function none(series) {
|
|
946
|
+
var n = series.length, o = new Array(n);
|
|
947
|
+
while (--n >= 0) o[n] = n;
|
|
948
|
+
return o;
|
|
1054
949
|
}
|
|
1055
950
|
|
|
1056
|
-
|
|
1057
|
-
|
|
951
|
+
function stackValue(d, key) {
|
|
952
|
+
return d[key];
|
|
1058
953
|
}
|
|
1059
954
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
955
|
+
function stackSeries(key) {
|
|
956
|
+
const series = [];
|
|
957
|
+
series.key = key;
|
|
958
|
+
return series;
|
|
1063
959
|
}
|
|
1064
960
|
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
box-shadow: var(--elevation-level1);
|
|
1071
|
-
}
|
|
961
|
+
function stack() {
|
|
962
|
+
var keys = constant([]),
|
|
963
|
+
order = none,
|
|
964
|
+
offset = stackOffsetNone,
|
|
965
|
+
value = stackValue;
|
|
1072
966
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
967
|
+
function stack(data) {
|
|
968
|
+
var sz = Array.from(keys.apply(this, arguments), stackSeries),
|
|
969
|
+
i, n = sz.length, j = -1,
|
|
970
|
+
oz;
|
|
1077
971
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
letter-spacing: var(--typography-label-medium-letter-spacing) !important;
|
|
1084
|
-
fill: var(--color-on-surface-variant);
|
|
1085
|
-
}
|
|
972
|
+
for (const d of data) {
|
|
973
|
+
for (i = 0, ++j; i < n; ++i) {
|
|
974
|
+
(sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
1086
977
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
font-weight: var(--typography-label-small-font-weight) !important;
|
|
1091
|
-
line-height: var(--typography-label-small-line-height) !important;
|
|
1092
|
-
letter-spacing: var(--typography-label-small-letter-spacing) !important;
|
|
1093
|
-
fill: var(--color-on-surface);
|
|
1094
|
-
}
|
|
978
|
+
for (i = 0, oz = array(order(sz)); i < n; ++i) {
|
|
979
|
+
sz[oz[i]].index = i;
|
|
980
|
+
}
|
|
1095
981
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
982
|
+
offset(sz, oz);
|
|
983
|
+
return sz;
|
|
984
|
+
}
|
|
1100
985
|
|
|
1101
|
-
.
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
.
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
986
|
+
stack.keys = function(_) {
|
|
987
|
+
return arguments.length ? (keys = typeof _ === "function" ? _ : constant(Array.from(_)), stack) : keys;
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
stack.value = function(_) {
|
|
991
|
+
return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), stack) : value;
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
stack.order = function(_) {
|
|
995
|
+
return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant(Array.from(_)), stack) : order;
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
stack.offset = function(_) {
|
|
999
|
+
return arguments.length ? (offset = _ == null ? stackOffsetNone : _, stack) : offset;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
return stack;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/** Rough width of a `label-medium` character, used to size axes before text is measured. */
|
|
1006
|
+
const CHAR_WIDTH = 7;
|
|
1007
|
+
const AXIS_GAP = 8;
|
|
1008
|
+
const X_AXIS_HEIGHT = 24;
|
|
1009
|
+
const MAX_CATEGORY_AXIS_WIDTH = 120;
|
|
1010
|
+
/**
|
|
1011
|
+
* Base for charts with a category axis and a value axis (bar, line, area). Data is an array of
|
|
1012
|
+
* rows; `index` names the category field and `config` names the series fields.
|
|
1013
|
+
*/
|
|
1014
|
+
class CartesianChart extends ChartBase {
|
|
1015
|
+
constructor() {
|
|
1016
|
+
// ── Properties
|
|
1017
|
+
super(...arguments);
|
|
1018
|
+
/** Rows to plot. Each row holds the category field (`index`) and a number per series. */
|
|
1019
|
+
this.data = [];
|
|
1020
|
+
/** Series to plot, keyed by data field, with optional label and color. Defaults to every numeric field. */
|
|
1021
|
+
this.config = {};
|
|
1022
|
+
/** Data field that holds the category label, for example `month`. */
|
|
1023
|
+
this.index = '';
|
|
1024
|
+
/** Hides the gridlines. */
|
|
1025
|
+
this.hideGrid = false;
|
|
1026
|
+
/** Hides the category axis labels. */
|
|
1027
|
+
this.hideCategoryAxis = false;
|
|
1028
|
+
/** Hides the value axis labels. */
|
|
1029
|
+
this.hideValueAxis = false;
|
|
1030
|
+
// ── Private fields
|
|
1031
|
+
/** Current plot layout, set by `computeLayout()`. */
|
|
1032
|
+
this.layout = {
|
|
1033
|
+
left: 0,
|
|
1034
|
+
top: 0,
|
|
1035
|
+
right: 0,
|
|
1036
|
+
bottom: 0,
|
|
1037
|
+
innerWidth: 0,
|
|
1038
|
+
innerHeight: 0,
|
|
1039
|
+
};
|
|
1040
|
+
/** Which axis carries the categories. */
|
|
1041
|
+
this.orientation = 'vertical';
|
|
1042
|
+
/** Category centers along the category axis, in inner plot coordinates. */
|
|
1043
|
+
this.centers = [];
|
|
1044
|
+
/** Width of one category slot along the category axis. */
|
|
1045
|
+
this.step = 0;
|
|
1046
|
+
/** Tooltip anchor per category, in plot element coordinates. */
|
|
1047
|
+
this.anchors = [];
|
|
1048
|
+
/** Whether the cursor is a band (bars) or a line (line, area). */
|
|
1049
|
+
this.cursorKind = 'band';
|
|
1050
|
+
}
|
|
1051
|
+
// ── Overrides
|
|
1052
|
+
drawProperties() {
|
|
1053
|
+
return [
|
|
1054
|
+
...super.drawProperties(),
|
|
1055
|
+
'data',
|
|
1056
|
+
'config',
|
|
1057
|
+
'index',
|
|
1058
|
+
'hideGrid',
|
|
1059
|
+
'hideCategoryAxis',
|
|
1060
|
+
'hideValueAxis',
|
|
1061
|
+
];
|
|
1062
|
+
}
|
|
1063
|
+
hasData() {
|
|
1064
|
+
return this.data.length > 0 && this.seriesKeys().length > 0;
|
|
1065
|
+
}
|
|
1066
|
+
getSeries() {
|
|
1067
|
+
return this.seriesKeys().map((key, i) => ({
|
|
1068
|
+
key,
|
|
1069
|
+
label: this.config[key]?.label ?? key,
|
|
1070
|
+
color: this.config[key]?.color ?? chartColor(i),
|
|
1071
|
+
}));
|
|
1072
|
+
}
|
|
1073
|
+
getItemCount() {
|
|
1074
|
+
return this.data.length;
|
|
1075
|
+
}
|
|
1076
|
+
itemAtPoint(x, y) {
|
|
1077
|
+
const { left, top, innerWidth, innerHeight } = this.layout;
|
|
1078
|
+
const px = x - left;
|
|
1079
|
+
const py = y - top;
|
|
1080
|
+
if (px < 0 || py < 0 || px > innerWidth || py > innerHeight)
|
|
1081
|
+
return -1;
|
|
1082
|
+
const along = this.orientation === 'vertical' ? px : py;
|
|
1083
|
+
let best = -1;
|
|
1084
|
+
let bestDistance = Infinity;
|
|
1085
|
+
this.centers.forEach((center, i) => {
|
|
1086
|
+
const distance = Math.abs(center - along);
|
|
1087
|
+
if (distance < bestDistance) {
|
|
1088
|
+
bestDistance = distance;
|
|
1089
|
+
best = i;
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
return best;
|
|
1093
|
+
}
|
|
1094
|
+
getTooltip(index) {
|
|
1095
|
+
const datum = this.data[index];
|
|
1096
|
+
if (!datum)
|
|
1097
|
+
return undefined;
|
|
1098
|
+
const anchor = this.anchors[index] ?? { x: 0, y: 0 };
|
|
1099
|
+
return {
|
|
1100
|
+
title: this.categoryLabel(index),
|
|
1101
|
+
rows: this.visibleSeries().map(series => ({
|
|
1102
|
+
key: series.key,
|
|
1103
|
+
label: series.label,
|
|
1104
|
+
color: series.color,
|
|
1105
|
+
value: this.formatValue(this.seriesValue(datum, series.key)),
|
|
1106
|
+
})),
|
|
1107
|
+
x: anchor.x,
|
|
1108
|
+
y: anchor.y,
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
getSelectDetail(index) {
|
|
1112
|
+
return { index, datum: this.data[index] };
|
|
1113
|
+
}
|
|
1114
|
+
drawHighlight() {
|
|
1115
|
+
const root = this.plotArea();
|
|
1116
|
+
if (!root)
|
|
1117
|
+
return;
|
|
1118
|
+
const cursor = root.select('.cursor');
|
|
1119
|
+
const index = this.activeIndex;
|
|
1120
|
+
if (index < 0 || this.centers[index] === undefined) {
|
|
1121
|
+
cursor.classed('is-visible', false);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
const { innerWidth, innerHeight } = this.layout;
|
|
1125
|
+
const center = this.centers[index];
|
|
1126
|
+
const size = this.cursorKind === 'band' ? this.step : 1;
|
|
1127
|
+
cursor
|
|
1128
|
+
.classed('cursor-line', this.cursorKind === 'line')
|
|
1129
|
+
.classed('is-visible', true);
|
|
1130
|
+
if (this.orientation === 'vertical') {
|
|
1131
|
+
cursor
|
|
1132
|
+
.attr('x', center - size / 2)
|
|
1133
|
+
.attr('y', 0)
|
|
1134
|
+
.attr('width', size)
|
|
1135
|
+
.attr('height', innerHeight);
|
|
1136
|
+
}
|
|
1137
|
+
else {
|
|
1138
|
+
cursor
|
|
1139
|
+
.attr('x', 0)
|
|
1140
|
+
.attr('y', center - size / 2)
|
|
1141
|
+
.attr('width', innerWidth)
|
|
1142
|
+
.attr('height', size);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
renderSvgContent() {
|
|
1146
|
+
return w `<defs></defs>
|
|
1147
|
+
<g class="plot-area">
|
|
1148
|
+
<g class="grid"></g>
|
|
1149
|
+
<rect class="cursor"></rect>
|
|
1150
|
+
<g class="marks"></g>
|
|
1151
|
+
<g class="value-labels"></g>
|
|
1152
|
+
<g class="category-axis"></g>
|
|
1153
|
+
<g class="value-axis"></g>
|
|
1154
|
+
<g class="active-layer"></g>
|
|
1155
|
+
</g>`;
|
|
1156
|
+
}
|
|
1157
|
+
renderTable() {
|
|
1158
|
+
const series = this.getSeries();
|
|
1159
|
+
return b `<thead>
|
|
1160
|
+
<tr>
|
|
1161
|
+
<th scope="col">${this.index || 'Category'}</th>
|
|
1162
|
+
${series.map(s => b `<th scope="col">${s.label}</th>`)}
|
|
1163
|
+
</tr>
|
|
1164
|
+
</thead>
|
|
1165
|
+
<tbody>
|
|
1166
|
+
${this.data.map((datum, i) => b `<tr>
|
|
1167
|
+
<th scope="row">${this.categoryLabel(i)}</th>
|
|
1168
|
+
${series.map(s => b `<td>
|
|
1169
|
+
${this.formatValue(this.seriesValue(datum, s.key))}
|
|
1170
|
+
</td>`)}
|
|
1171
|
+
</tr>`)}
|
|
1172
|
+
</tbody>`;
|
|
1173
|
+
}
|
|
1174
|
+
// ── Helpers for subclasses
|
|
1175
|
+
/** Series keys from `config`, or every numeric field of the first row except `index`. */
|
|
1176
|
+
seriesKeys() {
|
|
1177
|
+
const configured = Object.keys(this.config ?? {});
|
|
1178
|
+
if (configured.length)
|
|
1179
|
+
return configured;
|
|
1180
|
+
const first = this.data[0];
|
|
1181
|
+
if (!first)
|
|
1182
|
+
return [];
|
|
1183
|
+
return Object.keys(first).filter(key => key !== this.index && typeof first[key] === 'number');
|
|
1184
|
+
}
|
|
1185
|
+
/** Series not switched off in the legend. */
|
|
1186
|
+
visibleSeries() {
|
|
1187
|
+
return this.getSeries().filter(series => !this.isHidden(series.key));
|
|
1188
|
+
}
|
|
1189
|
+
/** A row's value for a series, 0 when missing. */
|
|
1190
|
+
seriesValue(datum, key) {
|
|
1191
|
+
const value = Number(datum[key]);
|
|
1192
|
+
return Number.isFinite(value) ? value : 0;
|
|
1193
|
+
}
|
|
1194
|
+
/** Category label of a row. */
|
|
1195
|
+
categoryLabel(index) {
|
|
1196
|
+
const datum = this.data[index];
|
|
1197
|
+
if (!datum)
|
|
1198
|
+
return '';
|
|
1199
|
+
return this.index ? String(datum[this.index] ?? '') : String(index + 1);
|
|
1200
|
+
}
|
|
1201
|
+
/** Category domain: row positions, so repeated labels stay distinct. */
|
|
1202
|
+
categoryDomain() {
|
|
1203
|
+
return this.data.map((_, i) => String(i));
|
|
1204
|
+
}
|
|
1205
|
+
/** The `.plot-area` group, or undefined before the SVG renders. */
|
|
1206
|
+
plotArea() {
|
|
1207
|
+
if (!this.svgElement)
|
|
1208
|
+
return undefined;
|
|
1209
|
+
return select(this.svgElement).select('.plot-area');
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Sets `layout` from the value scale's ticks and the category labels. Call before setting the
|
|
1213
|
+
* scales' ranges. `valueLabelSpace` reserves room for value labels at the end of the marks.
|
|
1214
|
+
*/
|
|
1215
|
+
computeLayout(valueScale, valueLabelSpace = 0) {
|
|
1216
|
+
const { width, height } = this.svgSize();
|
|
1217
|
+
const tickWidth = Math.max(...valueScale.ticks(5).map(t => this.formatTick(t).length), 1) *
|
|
1218
|
+
CHAR_WIDTH +
|
|
1219
|
+
AXIS_GAP;
|
|
1220
|
+
const categoryWidth = Math.min(Math.max(...this.data.map((_, i) => this.categoryLabel(i).length), 1) *
|
|
1221
|
+
CHAR_WIDTH +
|
|
1222
|
+
AXIS_GAP, MAX_CATEGORY_AXIS_WIDTH);
|
|
1223
|
+
let left;
|
|
1224
|
+
let bottom;
|
|
1225
|
+
let top = 8;
|
|
1226
|
+
let right = 8;
|
|
1227
|
+
if (this.orientation === 'vertical') {
|
|
1228
|
+
left = this.hideValueAxis ? 4 : tickWidth;
|
|
1229
|
+
bottom = this.hideCategoryAxis ? 4 : X_AXIS_HEIGHT;
|
|
1230
|
+
top += valueLabelSpace ? 12 : 0;
|
|
1231
|
+
// Room for half of the last category label.
|
|
1232
|
+
right += this.hideCategoryAxis ? 0 : 4;
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
left = this.hideCategoryAxis ? 4 : categoryWidth;
|
|
1236
|
+
bottom = this.hideValueAxis ? 4 : X_AXIS_HEIGHT;
|
|
1237
|
+
right += valueLabelSpace;
|
|
1238
|
+
}
|
|
1239
|
+
this.layout = {
|
|
1240
|
+
left,
|
|
1241
|
+
top,
|
|
1242
|
+
right,
|
|
1243
|
+
bottom,
|
|
1244
|
+
innerWidth: Math.max(width - left - right, 0),
|
|
1245
|
+
innerHeight: Math.max(height - top - bottom, 0),
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Draws gridlines, the zero baseline and both axes' labels, and records category centers.
|
|
1250
|
+
* The scales must already have their ranges set from `layout`.
|
|
1251
|
+
*/
|
|
1252
|
+
drawFrame(categoryScale, valueScale) {
|
|
1253
|
+
const root = this.plotArea();
|
|
1254
|
+
if (!root)
|
|
1255
|
+
return;
|
|
1256
|
+
const { left, top, innerWidth, innerHeight } = this.layout;
|
|
1257
|
+
const vertical = this.orientation === 'vertical';
|
|
1258
|
+
root.attr('transform', `translate(${left},${top})`);
|
|
1259
|
+
const domain = categoryScale.domain();
|
|
1260
|
+
const bandwidth = categoryScale.bandwidth();
|
|
1261
|
+
this.step = categoryScale.step();
|
|
1262
|
+
this.centers = domain.map(key => (categoryScale(key) ?? 0) + bandwidth / 2);
|
|
1263
|
+
// Gridlines at each value tick; the zero line is solid.
|
|
1264
|
+
const ticks = valueScale.ticks(5);
|
|
1265
|
+
const gridTicks = this.hideGrid ? [] : ticks.filter(t => t !== 0);
|
|
1266
|
+
root
|
|
1267
|
+
.select('.grid')
|
|
1268
|
+
.selectAll('line.gridline')
|
|
1269
|
+
.data(gridTicks, d => String(d))
|
|
1270
|
+
.join('line')
|
|
1271
|
+
.attr('class', 'gridline')
|
|
1272
|
+
.attr('x1', d => (vertical ? 0 : valueScale(d)))
|
|
1273
|
+
.attr('x2', d => (vertical ? innerWidth : valueScale(d)))
|
|
1274
|
+
.attr('y1', d => (vertical ? valueScale(d) : 0))
|
|
1275
|
+
.attr('y2', d => (vertical ? valueScale(d) : innerHeight));
|
|
1276
|
+
const zero = valueScale(0);
|
|
1277
|
+
root
|
|
1278
|
+
.select('.grid')
|
|
1279
|
+
.selectAll('line.baseline')
|
|
1280
|
+
.data([zero])
|
|
1281
|
+
.join('line')
|
|
1282
|
+
.attr('class', 'baseline')
|
|
1283
|
+
.attr('x1', vertical ? 0 : zero)
|
|
1284
|
+
.attr('x2', vertical ? innerWidth : zero)
|
|
1285
|
+
.attr('y1', vertical ? zero : 0)
|
|
1286
|
+
.attr('y2', vertical ? zero : innerHeight);
|
|
1287
|
+
// Value axis labels.
|
|
1288
|
+
const showValueAxis = !this.hideValueAxis;
|
|
1289
|
+
root
|
|
1290
|
+
.select('.value-axis')
|
|
1291
|
+
.selectAll('text')
|
|
1292
|
+
.data(showValueAxis ? ticks : [], d => String(d))
|
|
1293
|
+
.join('text')
|
|
1294
|
+
.attr('class', 'axis-label')
|
|
1295
|
+
.attr('text-anchor', vertical ? 'end' : 'middle')
|
|
1296
|
+
.attr('dominant-baseline', vertical ? 'middle' : 'hanging')
|
|
1297
|
+
.attr('x', d => (vertical ? -AXIS_GAP : valueScale(d)))
|
|
1298
|
+
.attr('y', d => (vertical ? valueScale(d) : innerHeight + AXIS_GAP))
|
|
1299
|
+
.text(d => this.formatTick(d));
|
|
1300
|
+
// Category axis labels, thinned out when they would overlap.
|
|
1301
|
+
const showCategoryAxis = !this.hideCategoryAxis;
|
|
1302
|
+
const longest = Math.max(...domain.map((_, i) => this.categoryLabel(i).length), 1);
|
|
1303
|
+
const labelSize = vertical ? longest * CHAR_WIDTH + AXIS_GAP : 18;
|
|
1304
|
+
const every = Math.max(1, Math.ceil(labelSize / Math.max(this.step, 1)));
|
|
1305
|
+
const shown = showCategoryAxis
|
|
1306
|
+
? domain.filter((_, i) => i % every === 0)
|
|
1307
|
+
: [];
|
|
1308
|
+
root
|
|
1309
|
+
.select('.category-axis')
|
|
1310
|
+
.selectAll('text')
|
|
1311
|
+
.data(shown, d => d)
|
|
1312
|
+
.join('text')
|
|
1313
|
+
.attr('class', 'axis-label')
|
|
1314
|
+
.attr('text-anchor', vertical ? 'middle' : 'end')
|
|
1315
|
+
.attr('dominant-baseline', vertical ? 'hanging' : 'middle')
|
|
1316
|
+
.attr('x', d => vertical ? (categoryScale(d) ?? 0) + bandwidth / 2 : -AXIS_GAP)
|
|
1317
|
+
.attr('y', d => vertical
|
|
1318
|
+
? innerHeight + AXIS_GAP
|
|
1319
|
+
: (categoryScale(d) ?? 0) + bandwidth / 2)
|
|
1320
|
+
.text(d => this.categoryLabel(Number(d)));
|
|
1321
|
+
}
|
|
1117
1322
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1323
|
+
__decorate([
|
|
1324
|
+
n({ type: Array })
|
|
1325
|
+
], CartesianChart.prototype, "data", void 0);
|
|
1326
|
+
__decorate([
|
|
1327
|
+
n({ type: Object })
|
|
1328
|
+
], CartesianChart.prototype, "config", void 0);
|
|
1329
|
+
__decorate([
|
|
1330
|
+
n({ type: String })
|
|
1331
|
+
], CartesianChart.prototype, "index", void 0);
|
|
1332
|
+
__decorate([
|
|
1333
|
+
n({ type: Boolean, attribute: 'hide-grid' })
|
|
1334
|
+
], CartesianChart.prototype, "hideGrid", void 0);
|
|
1335
|
+
__decorate([
|
|
1336
|
+
n({ type: Boolean, attribute: 'hide-category-axis' })
|
|
1337
|
+
], CartesianChart.prototype, "hideCategoryAxis", void 0);
|
|
1338
|
+
__decorate([
|
|
1339
|
+
n({ type: Boolean, attribute: 'hide-value-axis' })
|
|
1340
|
+
], CartesianChart.prototype, "hideValueAxis", void 0);
|
|
1341
|
+
|
|
1342
|
+
export { CartesianChart as C, max as a, band as b, stackOffsetNone as c, linear as l, min as m, point as p, stack as s };
|
|
1343
|
+
//# sourceMappingURL=cartesian-chart-DgE4USyC.js.map
|