@carbon/charts 1.16.5 → 1.16.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +3 -4
  3. package/dist/angle-utils-BSzg7qin.mjs +1681 -0
  4. package/dist/angle-utils-BSzg7qin.mjs.map +1 -0
  5. package/dist/array-BRmw0x1E.mjs +32 -0
  6. package/dist/array-BRmw0x1E.mjs.map +1 -0
  7. package/dist/choropleth-BwaUZYh6.mjs +11722 -0
  8. package/dist/choropleth-BwaUZYh6.mjs.map +1 -0
  9. package/dist/color-scale-utils-DAbXVtf-.mjs +5722 -0
  10. package/dist/color-scale-utils-DAbXVtf-.mjs.map +1 -0
  11. package/dist/components/essentials/geo-projection.d.ts +7 -5
  12. package/dist/components/essentials/highlights.d.ts +1 -1
  13. package/dist/components/essentials/threshold.d.ts +1 -1
  14. package/dist/components/essentials/tooltip.d.ts +1 -1
  15. package/dist/components/index.mjs +3 -3
  16. package/dist/demo/index.mjs +244 -264
  17. package/dist/demo/index.mjs.map +1 -1
  18. package/dist/enums-DwsxZqjR.mjs.map +1 -1
  19. package/dist/index-DnyOi0rJ.mjs +1477 -0
  20. package/dist/index-DnyOi0rJ.mjs.map +1 -0
  21. package/dist/index.mjs +35 -35
  22. package/dist/interfaces/axis-scales.d.ts +3 -3
  23. package/dist/interfaces/charts.d.ts +5 -3
  24. package/dist/interfaces/components.d.ts +4 -3
  25. package/dist/interfaces/model.d.ts +30 -6
  26. package/dist/model/index.mjs +1321 -17
  27. package/dist/model/index.mjs.map +1 -1
  28. package/dist/services/index.mjs +16 -16
  29. package/dist/umd/bundle.umd.js +11 -11
  30. package/dist/umd/bundle.umd.js.map +1 -1
  31. package/package.json +2 -15
  32. package/dist/_baseEach-Bp7pBkX8.mjs +0 -20
  33. package/dist/_baseEach-Bp7pBkX8.mjs.map +0 -1
  34. package/dist/angle-utils-BCx3SRS2.mjs +0 -849
  35. package/dist/angle-utils-BCx3SRS2.mjs.map +0 -1
  36. package/dist/choropleth-B7eXF9sA.mjs +0 -8662
  37. package/dist/choropleth-B7eXF9sA.mjs.map +0 -1
  38. package/dist/color-scale-utils-BaTmNvWt.mjs +0 -3467
  39. package/dist/color-scale-utils-BaTmNvWt.mjs.map +0 -1
  40. package/dist/wordcloud-BsEQRUwL.mjs +0 -1169
  41. package/dist/wordcloud-BsEQRUwL.mjs.map +0 -1
  42. package/dist/zoom-E2POxw6n.mjs +0 -739
  43. package/dist/zoom-E2POxw6n.mjs.map +0 -1
@@ -1,739 +0,0 @@
1
- import { select as se, max as ie, extent as $, scaleTime as oe, scaleLog as ae, scaleBand as re, scaleLinear as ce, curveLinear as le, curveLinearClosed as ue, curveBasis as me, curveBasisClosed as de, curveBasisOpen as he, curveBundle as ge, curveCardinal as fe, curveCardinalClosed as pe, curveCardinalOpen as xe, curveCatmullRom as De, curveCatmullRomClosed as ye, curveCatmullRomOpen as Ae, curveMonotoneX as Oe, curveMonotoneY as ve, curveNatural as Te, curveStep as Me, curveStepAfter as Pe, curveStepBefore as Se } from "d3";
2
- import { S as y, D as Re } from "./angle-utils-BCx3SRS2.mjs";
3
- import { _ as S, e as l, i as L, S as d } from "./enums-DwsxZqjR.mjs";
4
- import { _ as Be, $ as Le, a0 as Ee, a1 as Ie, a2 as K, a3 as be, a4 as Ce, a5 as Ze, a6 as we, a7 as Fe, a8 as _e, a9 as Ne, K as V, m as c, X as H, aa as g, ab as R, ac as Ve, ad as W, ae as q, H as Y, v as He, Z as Ye } from "./color-scale-utils-BaTmNvWt.mjs";
5
- function j(s) {
6
- var e = s == null ? 0 : s.length;
7
- return e ? Be(s, 1) : [];
8
- }
9
- function Xe(s) {
10
- return Le(Ee(s, void 0, j), s + "");
11
- }
12
- function ze(s, e, t) {
13
- var n = -1, i = s.length;
14
- e < 0 && (e = -e > i ? 0 : i + e), t = t > i ? i : t, t < 0 && (t += i), i = e > t ? 0 : t - e >>> 0, e >>>= 0;
15
- for (var o = Array(i); ++n < i; )
16
- o[n] = s[n + e];
17
- return o;
18
- }
19
- function Ge(s, e) {
20
- return e.length < 2 ? s : Ie(s, ze(e, 0, -1));
21
- }
22
- function ke(s, e) {
23
- return e = K(e, s), s = Ge(s, e), s == null || delete s[be(Ce(e))];
24
- }
25
- function Ue(s) {
26
- return Ze(s) ? void 0 : s;
27
- }
28
- var $e = 1, Ke = 2, We = 4, qe = Xe(function(s, e) {
29
- var t = {};
30
- if (s == null)
31
- return t;
32
- var n = !1;
33
- e = we(e, function(o) {
34
- return o = K(o, s), n || (n = o.length > 1), o;
35
- }), Fe(s, _e(s), t), n && (t = Ne(t, $e | Ke | We, Ue));
36
- for (var i = e.length; i--; )
37
- ke(t, e[i]);
38
- return t;
39
- });
40
- class pt extends y {
41
- /**
42
- * focal: object to zoom into
43
- * canvasElements: all the elements to translate and zoom on the chart area
44
- * zoomSettings: object containing duration, easing and zoomlevel for the zoom behaviours
45
- * */
46
- zoomIn(e, t, n) {
47
- let i, o, a;
48
- const r = n || V;
49
- e && (i = e.x, o = e.y, a = 2);
50
- const { width: u, height: h } = Re.getSVGElementSize(this.services.domUtils.getHolder(), {
51
- useClientDimensions: !0
52
- });
53
- t.transition().duration(r.duration).ease(r.ease).attr(
54
- "transform",
55
- `translate(${u / 2}, ${h / 2}) scale(${a}) translate(${-i},${-o})`
56
- ), this.services.events.dispatchEvent(S.CanvasZoom.CANVAS_ZOOM_IN, {
57
- element: se(e)
58
- });
59
- }
60
- zoomOut(e, t) {
61
- const n = t || V;
62
- e.transition().duration(n.duration).ease(n.ease).attr("transform", ""), this.services.events.dispatchEvent(S.CanvasZoom.CANVAS_ZOOM_OUT);
63
- }
64
- }
65
- class xt extends y {
66
- init() {
67
- this.documentFragment = document.createDocumentFragment();
68
- }
69
- addEventListener(e, t) {
70
- this.documentFragment.addEventListener(e, t);
71
- }
72
- removeEventListener(e, t) {
73
- this.documentFragment.removeEventListener(e, t);
74
- }
75
- dispatchEvent(e, t) {
76
- let n;
77
- t ? n = new CustomEvent(e, {
78
- detail: t
79
- }) : (n = document.createEvent("Event"), n.initEvent(e, !1, !0)), this.documentFragment.dispatchEvent(n);
80
- }
81
- }
82
- class Dt extends y {
83
- constructor(e, t) {
84
- super(e, t);
85
- }
86
- downloadCSV(e, t) {
87
- const n = document.createElement("a"), i = "text/csv;encoding:utf-8";
88
- if (navigator.msSaveBlob)
89
- navigator.msSaveBlob(
90
- new Blob([e], {
91
- type: i
92
- }),
93
- t
94
- );
95
- else if (URL && "download" in n) {
96
- const o = URL.createObjectURL(
97
- new Blob([e], {
98
- type: i
99
- })
100
- );
101
- n.href = o, n.setAttribute("download", t), document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(o);
102
- } else
103
- location.href = `data:application/octet-stream,${encodeURIComponent(e)}`;
104
- }
105
- downloadImage(e, t) {
106
- const n = document.createElement("a");
107
- n.download = t, n.href = e, document.body.appendChild(n), n.click(), document.body.removeChild(n);
108
- }
109
- }
110
- class yt extends y {
111
- constructor() {
112
- super(...arguments), this.pendingTransitions = {};
113
- }
114
- init() {
115
- var e;
116
- (e = this.services.events) == null || e.addEventListener(S.Model.UPDATE, () => {
117
- this.pendingTransitions = {};
118
- });
119
- }
120
- setupTransition({ transition: e, name: t, animate: n }) {
121
- return this.pendingTransitions[e._id] = e, e.on("end interrupt cancel", () => {
122
- delete this.pendingTransitions[e._id];
123
- }), this.model.getOptions().animations === !1 || n === !1 ? e.duration(0) : e.duration(
124
- c(H, t, "duration") || H.default.duration
125
- );
126
- }
127
- getPendingTransitions() {
128
- return this.pendingTransitions;
129
- }
130
- }
131
- function v(s, e) {
132
- const t = g(s), n = g(e), i = t.getTime() - n.getTime();
133
- return i < 0 ? -1 : i > 0 ? 1 : i;
134
- }
135
- function je(s, e) {
136
- const t = g(s), n = g(e);
137
- return t.getFullYear() - n.getFullYear();
138
- }
139
- function Je(s, e) {
140
- const t = g(s), n = g(e), i = v(t, n), o = Math.abs(je(t, n));
141
- t.setFullYear(1584), n.setFullYear(1584);
142
- const a = v(t, n) === -i, r = i * (o - +a);
143
- return r === 0 ? 0 : r;
144
- }
145
- function b(s, e) {
146
- const t = g(s);
147
- if (isNaN(e)) return R(s, NaN);
148
- if (!e)
149
- return t;
150
- const n = t.getDate(), i = R(s, t.getTime());
151
- i.setMonth(t.getMonth() + e + 1, 0);
152
- const o = i.getDate();
153
- return n >= o ? i : (t.setFullYear(
154
- i.getFullYear(),
155
- i.getMonth(),
156
- n
157
- ), t);
158
- }
159
- function J(s, e) {
160
- return b(s, e * 12);
161
- }
162
- function Qe(s, e) {
163
- return J(s, -e);
164
- }
165
- function et(s, e) {
166
- const t = g(s), n = g(e), i = t.getFullYear() - n.getFullYear(), o = t.getMonth() - n.getMonth();
167
- return i * 12 + o;
168
- }
169
- function tt(s) {
170
- const e = g(s);
171
- return e.setHours(23, 59, 59, 999), e;
172
- }
173
- function nt(s) {
174
- const e = g(s), t = e.getMonth();
175
- return e.setFullYear(e.getFullYear(), t + 1, 0), e.setHours(23, 59, 59, 999), e;
176
- }
177
- function st(s) {
178
- const e = g(s);
179
- return +tt(e) == +nt(e);
180
- }
181
- function it(s, e) {
182
- const t = g(s), n = g(e), i = v(t, n), o = Math.abs(
183
- et(t, n)
184
- );
185
- let a;
186
- if (o < 1)
187
- a = 0;
188
- else {
189
- t.getMonth() === 1 && t.getDate() > 27 && t.setDate(30), t.setMonth(t.getMonth() - i * o);
190
- let r = v(t, n) === -i;
191
- st(g(s)) && o === 1 && v(s, n) === 1 && (r = !1), a = i * (o - Number(r));
192
- }
193
- return a === 0 ? 0 : a;
194
- }
195
- function ot(s, e) {
196
- return b(s, -e);
197
- }
198
- function at(s, e) {
199
- const t = g(s), n = g(e), i = X(t, n), o = Math.abs(Ve(t, n));
200
- t.setDate(t.getDate() - i * o);
201
- const a = +(X(t, n) === -i), r = i * (o - a);
202
- return r === 0 ? 0 : r;
203
- }
204
- function X(s, e) {
205
- const t = s.getFullYear() - e.getFullYear() || s.getMonth() - e.getMonth() || s.getDate() - e.getDate() || s.getHours() - e.getHours() || s.getMinutes() - e.getMinutes() || s.getSeconds() - e.getSeconds() || s.getMilliseconds() - e.getMilliseconds();
206
- return t < 0 ? -1 : t > 0 ? 1 : t;
207
- }
208
- function Q(s, e) {
209
- const t = g(s);
210
- return isNaN(e) ? R(s, NaN) : (e && t.setDate(t.getDate() + e), t);
211
- }
212
- function rt(s, e) {
213
- return Q(s, -e);
214
- }
215
- function C(s) {
216
- return (e) => {
217
- const n = (s ? Math[s] : Math.trunc)(e);
218
- return n === 0 ? 0 : n;
219
- };
220
- }
221
- function Z(s, e) {
222
- return +g(s) - +g(e);
223
- }
224
- function ct(s, e, t) {
225
- const n = Z(s, e) / W;
226
- return C(t == null ? void 0 : t.roundingMethod)(n);
227
- }
228
- function w(s, e) {
229
- const t = +g(s);
230
- return R(s, t + e);
231
- }
232
- function ee(s, e) {
233
- return w(s, e * W);
234
- }
235
- function lt(s, e) {
236
- return ee(s, -e);
237
- }
238
- function z(s, e, t) {
239
- const n = Z(s, e) / q;
240
- return C(t == null ? void 0 : t.roundingMethod)(n);
241
- }
242
- function E(s, e) {
243
- return w(s, e * q);
244
- }
245
- function G(s, e) {
246
- return E(s, -e);
247
- }
248
- function k(s, e, t) {
249
- const n = Z(s, e) / 1e3;
250
- return C(t == null ? void 0 : t.roundingMethod)(n);
251
- }
252
- function I(s, e) {
253
- return w(s, e * 1e3);
254
- }
255
- function U(s, e) {
256
- return I(s, -e);
257
- }
258
- class At extends y {
259
- constructor() {
260
- super(...arguments), this.scaleTypes = {
261
- top: null,
262
- right: null,
263
- bottom: null,
264
- left: null
265
- }, this.scales = {
266
- // null or function
267
- top: null,
268
- right: null,
269
- bottom: null,
270
- left: null
271
- };
272
- }
273
- getDomainAxisPosition({ datum: e = null } = {}) {
274
- if (this.dualAxes && e) {
275
- const t = this.model.getOptions(), { groupMapsTo: n } = t.data, i = c(t, "axes", this.secondaryDomainAxisPosition), o = e[n];
276
- if (i != null && i.correspondingDatasets && i.correspondingDatasets.includes(o))
277
- return this.secondaryDomainAxisPosition;
278
- }
279
- return this.domainAxisPosition;
280
- }
281
- getRangeAxisPosition({ datum: e = null, groups: t = null } = {}) {
282
- if (this.dualAxes) {
283
- const n = this.model.getOptions(), { groupMapsTo: i } = n.data, o = c(n, "axes", this.secondaryRangeAxisPosition);
284
- let a;
285
- if (e !== null ? a = e[i] : t && t.length > 0 && (a = t[0]), o != null && o.correspondingDatasets && o.correspondingDatasets.includes(a))
286
- return this.secondaryRangeAxisPosition;
287
- }
288
- return this.rangeAxisPosition;
289
- }
290
- getAxisOptions(e) {
291
- return c(this.model.getOptions(), "axes", e);
292
- }
293
- getDomainAxisOptions() {
294
- const e = this.getDomainAxisPosition();
295
- return this.getAxisOptions(e);
296
- }
297
- getRangeAxisOptions() {
298
- const e = this.getRangeAxisPosition();
299
- return this.getAxisOptions(e);
300
- }
301
- getScaleLabel(e) {
302
- const n = this.getAxisOptions(e).title;
303
- return n || (e === l.BOTTOM || e === l.TOP ? "x-value" : "y-value");
304
- }
305
- getDomainLabel() {
306
- return this.getScaleLabel(this.getDomainAxisPosition());
307
- }
308
- getRangeLabel() {
309
- return this.getScaleLabel(this.getRangeAxisPosition());
310
- }
311
- update() {
312
- this.determineAxisDuality(), this.findDomainAndRangeAxes(), this.determineOrientation(), Object.keys(l).map(
313
- (t) => l[t]
314
- ).forEach((t) => {
315
- this.scales[t] = this.createScale(t);
316
- });
317
- }
318
- findDomainAndRangeAxes() {
319
- const e = this.findVerticalAxesPositions(), t = this.findHorizontalAxesPositions(), n = this.findDomainAndRangeAxesPositions(
320
- e,
321
- t
322
- );
323
- this.domainAxisPosition = n.primaryDomainAxisPosition, this.rangeAxisPosition = n.primaryRangeAxisPosition, this.isDualAxes() && (this.secondaryDomainAxisPosition = n.secondaryDomainAxisPosition, this.secondaryRangeAxisPosition = n.secondaryRangeAxisPosition);
324
- }
325
- determineOrientation() {
326
- (this.rangeAxisPosition === l.LEFT || this.rangeAxisPosition === l.RIGHT) && (this.domainAxisPosition === l.BOTTOM || this.domainAxisPosition === l.TOP) ? this.orientation = L.VERTICAL : this.orientation = L.HORIZONTAL;
327
- }
328
- isDualAxes() {
329
- return this.dualAxes;
330
- }
331
- // if any of the axes objects have correspondingDatasets [] asserted we flag the chart as dual axes
332
- // it does not count as dual axes if it just has another axis turned on but is not actually using it to map a dataset
333
- determineAxisDuality() {
334
- var n, i, o, a;
335
- const e = this.model.getOptions(), t = c(e, "axes");
336
- ((n = t[l.LEFT]) != null && n.correspondingDatasets && t[l.RIGHT] || (i = t[l.RIGHT]) != null && i.correspondingDatasets && t[l.LEFT] || (o = t[l.TOP]) != null && o.correspondingDatasets && t[l.BOTTOM] || (a = t[l.BOTTOM]) != null && a.correspondingDatasets && t[l.TOP]) && (this.dualAxes = !0);
337
- }
338
- getCustomDomainValuesByposition(e) {
339
- const t = c(this.model.getOptions(), "axes", e, "domain");
340
- if (t && !Array.isArray(t))
341
- throw new Error(`Domain in ${e} axis is not a valid array`);
342
- if (Array.isArray(t) && (this.scaleTypes[e] === d.LINEAR || this.scaleTypes[e] === d.TIME) && t.length !== 2)
343
- throw new Error(
344
- `There can only be 2 elements in domain for scale type: ${this.scaleTypes[e]}`
345
- );
346
- return t;
347
- }
348
- getOrientation() {
349
- return this.orientation;
350
- }
351
- getScaleByPosition(e) {
352
- return this.scales[e];
353
- }
354
- getScaleTypeByPosition(e) {
355
- return this.scaleTypes[e];
356
- }
357
- getDomainAxisScaleType() {
358
- const e = this.getDomainAxisPosition();
359
- return this.getScaleTypeByPosition(e);
360
- }
361
- getRangeAxisScaleType() {
362
- const e = this.getRangeAxisPosition();
363
- return this.getScaleTypeByPosition(e);
364
- }
365
- getDomainScale() {
366
- return this.scales[this.domainAxisPosition];
367
- }
368
- getRangeScale() {
369
- return this.scales[this.rangeAxisPosition];
370
- }
371
- // Find the main x-axis out of the 2 x-axis on the chart (when 2D axis is used)
372
- getMainXAxisPosition() {
373
- const e = [l.BOTTOM, l.TOP];
374
- return [this.domainAxisPosition, this.rangeAxisPosition].find(
375
- (t) => e.indexOf(t) > -1
376
- );
377
- }
378
- // Find the main y-axis out of the 2 y-axis on the chart (when 2D axis is used)
379
- getMainYAxisPosition() {
380
- const e = [l.LEFT, l.RIGHT];
381
- return [this.domainAxisPosition, this.rangeAxisPosition].find(
382
- (t) => e.indexOf(t) > -1
383
- );
384
- }
385
- getMainXScale() {
386
- return this.scales[this.getMainXAxisPosition()];
387
- }
388
- getMainYScale() {
389
- return this.scales[this.getMainYAxisPosition()];
390
- }
391
- getValueFromScale(e, t, n, i) {
392
- const o = this.model.getOptions(), r = c(o, "axes")[n], { mapsTo: u } = r, h = c(i, u) !== null ? i[u] : i;
393
- let p;
394
- switch (t) {
395
- case d.LABELS:
396
- p = e(h) + e.step() / 2;
397
- break;
398
- case d.TIME:
399
- p = e(new Date(h));
400
- break;
401
- default:
402
- p = e(h);
403
- }
404
- return p;
405
- }
406
- getBoundedScaledValues(e) {
407
- const { bounds: t } = this.model.getOptions(), n = this.getRangeAxisPosition({ datum: e }), i = this.scales[n], o = this.model.getOptions(), r = c(o, "axes")[n], { mapsTo: u } = r, h = e[u] !== void 0 ? e[u] : e;
408
- return [
409
- i(
410
- c(e, t.upperBoundMapsTo) !== null ? e[t.upperBoundMapsTo] : h
411
- ),
412
- i(
413
- c(e, t.lowerBoundMapsTo) !== null ? e[t.lowerBoundMapsTo] : h
414
- )
415
- ];
416
- }
417
- getValueThroughAxisPosition(e, t) {
418
- const n = this.scaleTypes[e], i = this.scales[e];
419
- return this.getValueFromScale(i, n, e, t);
420
- }
421
- getDomainValue(e) {
422
- const t = this.getDomainAxisPosition({ datum: e });
423
- return this.getValueThroughAxisPosition(t, e);
424
- }
425
- getRangeValue(e) {
426
- const t = this.getRangeAxisPosition({ datum: e });
427
- return this.getValueThroughAxisPosition(t, e);
428
- }
429
- getMainXScaleType() {
430
- return this.getScaleTypeByPosition(this.getMainXAxisPosition());
431
- }
432
- getMainYScaleType() {
433
- return this.getScaleTypeByPosition(this.getMainYAxisPosition());
434
- }
435
- getDomainIdentifier(e) {
436
- const t = this.model.getOptions();
437
- return c(t, "axes", this.getDomainAxisPosition({ datum: e }), "mapsTo");
438
- }
439
- getRangeIdentifier(e) {
440
- const t = this.model.getOptions();
441
- return c(t, "axes", this.getRangeAxisPosition({ datum: e }), "mapsTo");
442
- }
443
- extendsDomain(e, t) {
444
- const n = this.model.getOptions(), i = c(n, "axes", e);
445
- if (i.scaleType === d.TIME) {
446
- const o = c(n, "timeScale", "addSpaceOnEdges");
447
- return ut(t, o);
448
- } else
449
- return mt(t, Y.paddingRatio, i.scaleType);
450
- }
451
- findVerticalAxesPositions() {
452
- const e = this.model.getOptions(), t = c(e, "axes"), n = this.isDualAxes();
453
- return c(t, l.LEFT) === null && c(t, l.RIGHT) !== null || c(t, l.RIGHT, "main") === !0 || n && c(t, l.LEFT, "correspondingDatasets") ? {
454
- primary: l.RIGHT,
455
- secondary: l.LEFT
456
- } : { primary: l.LEFT, secondary: l.RIGHT };
457
- }
458
- findHorizontalAxesPositions() {
459
- const e = this.model.getOptions(), t = c(e, "axes"), n = this.isDualAxes();
460
- return c(t, l.BOTTOM) === null && c(t, l.TOP) !== null || c(t, l.TOP, "main") === !0 || n && c(t, l.BOTTOM, "correspondingDatasets") ? {
461
- primary: l.TOP,
462
- secondary: l.BOTTOM
463
- } : { primary: l.BOTTOM, secondary: l.TOP };
464
- }
465
- findDomainAndRangeAxesPositions(e, t) {
466
- const n = this.model.getOptions(), i = c(n, "axes", e.primary), o = c(n, "axes", t.primary), a = i.scaleType || d.LINEAR, r = o.scaleType || d.LINEAR, u = {
467
- primaryDomainAxisPosition: null,
468
- secondaryDomainAxisPosition: null,
469
- primaryRangeAxisPosition: null,
470
- secondaryRangeAxisPosition: null
471
- };
472
- return u.primaryDomainAxisPosition = t.primary, u.primaryRangeAxisPosition = e.primary, u.secondaryDomainAxisPosition = t.secondary, u.secondaryRangeAxisPosition = e.secondary, (!(r === d.LABELS || r === d.TIME) && a === d.LABELS || a === d.TIME) && (u.primaryDomainAxisPosition = e.primary, u.primaryRangeAxisPosition = t.primary, u.secondaryDomainAxisPosition = e.secondary, u.secondaryRangeAxisPosition = t.secondary), u;
473
- }
474
- getScaleDomain(e) {
475
- const t = this.model.getOptions(), n = c(t, "axes", e), i = c(t, "bounds"), { includeZero: o } = n, a = c(n, "scaleType") || d.LINEAR;
476
- if (this.model.isDataEmpty())
477
- return [];
478
- if (n.binned) {
479
- const { bins: m } = this.model.getBinConfigurations();
480
- return [0, ie(m, (f) => f.length)];
481
- } else if (n.limitDomainToBins) {
482
- const { bins: m } = this.model.getBinConfigurations(), f = this.model.getStackKeys({ bins: m });
483
- return [f[0].split(":")[0], f[f.length - 1].split(":")[1]];
484
- }
485
- const r = this.model.getDisplayData(), { extendLinearDomainBy: u, mapsTo: h, percentage: p, thresholds: D } = n, { reference: A, compareTo: T } = Y.ratio;
486
- if (n.domain)
487
- return a === d.LABELS ? n.domain : (a === d.TIME && (n.domain = n.domain.map(
488
- (m) => m.getTime === void 0 ? new Date(m) : m
489
- )), this.extendsDomain(e, n.domain));
490
- if (p)
491
- return [0, 100];
492
- if (n && a === d.LABELS)
493
- return He(r.map((m) => m[h]));
494
- let M, x;
495
- const B = this.model.getDataGroupNames();
496
- if (a === d.LABELS_RATIO)
497
- return r.map((m) => `${m[A]}/${m[T]}`);
498
- if (a === d.TIME)
499
- x = r.map((m) => +new Date(m[h]));
500
- else if (i && t.axes)
501
- x = [], r.forEach((m) => {
502
- x.push(m[h]), m[i.upperBoundMapsTo] && x.push(m[i.upperBoundMapsTo]), m[i.lowerBoundMapsTo] && x.push(m[i.lowerBoundMapsTo]);
503
- });
504
- else if (n.stacked === !0 && B && e === this.getRangeAxisPosition()) {
505
- const { groupMapsTo: m } = t.data, f = this.model.getDataValuesGroupedByKeys({
506
- groups: B
507
- }), te = r.filter(
508
- (O) => !B.includes(O[m])
509
- ), F = [];
510
- f.forEach((O) => {
511
- const { ...ne } = O;
512
- let _ = 0, N = 0;
513
- Object.values(qe(ne, "sharedStackKey")).forEach((P) => {
514
- isNaN(P) || (P < 0 ? N += P : _ += P);
515
- }), F.push([N, _]);
516
- }), x = [
517
- ...j(F),
518
- ...te.map((O) => O[h])
519
- ];
520
- } else
521
- x = [], r.forEach((m) => {
522
- const f = m[h];
523
- Array.isArray(f) && f.length === 2 ? (x.push(f[0]), x.push(f[1])) : (u && x.push(Math.max(m[h], m[u])), x.push(f));
524
- });
525
- return a !== d.TIME && a !== d.LOG && o && x.push(0), D && D.length > 0 && D.forEach((m) => {
526
- const f = c(m, "value");
527
- f !== null && x.push(f);
528
- }), M = $(x), M = this.extendsDomain(e, M), M;
529
- }
530
- createScale(e) {
531
- const t = this.model.getOptions(), n = c(t, "axes", e);
532
- if (!n)
533
- return null;
534
- const i = c(n, "scaleType") || d.LINEAR;
535
- this.scaleTypes[e] = i;
536
- let o;
537
- return i === d.TIME ? o = oe() : i === d.LOG ? o = ae().base(n.base || 10) : i === d.LABELS || i === d.LABELS_RATIO ? o = re() : o = ce(), o.domain(this.getScaleDomain(e)), o;
538
- }
539
- getDomainLowerBound(e) {
540
- let t, n = 0;
541
- return this.getOrientation() === L.VERTICAL ? t = this.getMainYScale().domain() : t = this.getMainXScale().domain(), c(this.model.getOptions(), "axes", e, "includeZero") === !1 && t[0] > 0 && t[1] > 0 && (n = t[0]), n;
542
- }
543
- getHighestDomainThreshold() {
544
- const e = c(this.model.getOptions(), "axes"), t = this.getDomainAxisPosition(), { thresholds: n } = e[t];
545
- if (!Array.isArray(n) || Array.isArray(n) && !n.length)
546
- return null;
547
- const i = this.getDomainScale(), o = n.sort((r, u) => u.value - r.value)[0];
548
- return this.getScaleTypeByPosition(t) === d.TIME && (typeof o.value == "string" || o.value.getTime === void 0) && (o.value = new Date(o.value)), {
549
- threshold: o,
550
- scaleValue: i(o.value)
551
- };
552
- }
553
- getHighestRangeThreshold() {
554
- const e = c(this.model.getOptions(), "axes"), t = this.getRangeAxisPosition(), { thresholds: n } = e[t];
555
- if (!Array.isArray(n) || Array.isArray(n) && !n.length)
556
- return null;
557
- const i = this.getRangeScale(), o = n.sort((a, r) => r.value - a.value)[0];
558
- return {
559
- threshold: o,
560
- scaleValue: i(o.value)
561
- };
562
- }
563
- }
564
- function ut(s, e) {
565
- const t = new Date(s[0]), n = new Date(s[1]);
566
- return Je(n, t) > 1 ? [Qe(t, e), J(n, e)] : it(n, t) > 1 ? [ot(t, e), b(n, e)] : at(n, t) > 1 ? [rt(t, e), Q(n, e)] : ct(n, t) > 1 ? [lt(t, e), ee(n, e)] : z(n, t) > 30 ? [
567
- G(t, e * 30),
568
- E(n, e * 30)
569
- ] : z(n, t) > 1 ? [G(t, e), E(n, e)] : k(n, t) > 15 ? [
570
- U(t, e * 15),
571
- I(n, e * 15)
572
- ] : k(n, t) > 1 ? [U(t, e), I(n, e)] : [t, n];
573
- }
574
- function mt([s, e], t, n) {
575
- const o = (e - s) * t, a = e <= 0 && e + o > 0 ? 0 : e + o;
576
- let r = s >= 0 && s - o < 0 ? 0 : s - o;
577
- if (n === d.LOG && r <= 0) {
578
- if (s <= 0)
579
- throw Error("Data must have values greater than 0 if log scale type is used.");
580
- r = s;
581
- }
582
- return [r, a];
583
- }
584
- class Ot extends y {
585
- constructor() {
586
- super(...arguments), this.curveTypes = {
587
- curveLinear: le,
588
- curveLinearClosed: ue,
589
- curveBasis: me,
590
- curveBasisClosed: de,
591
- curveBasisOpen: he,
592
- curveBundle: ge,
593
- curveCardinal: fe,
594
- curveCardinalClosed: pe,
595
- curveCardinalOpen: xe,
596
- curveCatmullRom: De,
597
- curveCatmullRomClosed: ye,
598
- curveCatmullRomOpen: Ae,
599
- curveMonotoneX: Oe,
600
- curveMonotoneY: ve,
601
- curveNatural: Te,
602
- curveStep: Me,
603
- curveStepAfter: Pe,
604
- curveStepBefore: Se
605
- };
606
- }
607
- getD3Curve() {
608
- let e = "curveLinear";
609
- const t = this.model.getOptions().curve;
610
- if (t && (typeof t == "string" ? e = t : e = t.name), this.curveTypes[e]) {
611
- let n = this.curveTypes[e];
612
- return t && Object.keys(t).forEach((i) => {
613
- n[i] && (n = n[i](t[i]));
614
- }), n;
615
- }
616
- return console.warn(`The curve type '${e}' is invalid, using 'curveLinear' instead`), this.curveTypes.curveLinear;
617
- }
618
- }
619
- class vt extends y {
620
- isZoomBarEnabled() {
621
- if (!this.services.cartesianScales || !c(this.model.getOptions(), "zoomBar", "top", "enabled"))
622
- return !1;
623
- this.services.cartesianScales.findDomainAndRangeAxes();
624
- const e = this.services.cartesianScales.getMainXAxisPosition(), t = c(
625
- this.model.getOptions(),
626
- "axes",
627
- e,
628
- "scaleType"
629
- );
630
- return e === l.BOTTOM && t === d.TIME;
631
- }
632
- // get display data for zoom bar
633
- // basically it's sum of value grouped by time
634
- getZoomBarData() {
635
- const e = this.model.getZoomBarData();
636
- return e && e.length > 1 ? e : this.model.getDisplayData();
637
- }
638
- getDefaultZoomBarDomain(e) {
639
- if (!this.services.zoom) throw new Error("Services zoom not defined");
640
- const t = e || this.services.zoom.getZoomBarData(), { cartesianScales: n } = this.services;
641
- if (!n) throw new Error("Services cartesianScales undefined");
642
- const i = n.getMainXAxisPosition(), o = n.getDomainIdentifier(), a = c(this.model.getOptions(), "axes", i, "domain");
643
- if (Array.isArray(a) && a.length === 2)
644
- return a;
645
- if (!i) throw new Error("Not defined: mainXAxisPosition");
646
- return n.extendsDomain(
647
- i,
648
- $(t, (r) => r[o])
649
- );
650
- }
651
- handleDomainChange(e, t = { dispatchEvent: !0 }) {
652
- var n;
653
- this.model.set({ zoomDomain: e }, { animate: !1 }), t.dispatchEvent && ((n = this.services.events) == null || n.dispatchEvent(S.ZoomDomain.CHANGE, {
654
- newDomain: e
655
- }));
656
- }
657
- getZoomRatio() {
658
- return c(this.model.getOptions(), "zoomBar", "zoomRatio");
659
- }
660
- // filter out data not inside zoom domain
661
- // to get better range value for axis label
662
- filterDataForRangeAxis(e, t) {
663
- var a;
664
- const n = this.model.get("zoomDomain"), i = Object.assign(
665
- { stacked: !1 },
666
- // default configs
667
- t
668
- ), o = c(this.model.getOptions(), "zoomBar", "updateRangeAxis");
669
- if (this.isZoomBarEnabled() && o && n) {
670
- const r = i.stacked ? "sharedStackKey" : (a = this.services.cartesianScales) == null ? void 0 : a.getDomainIdentifier(), u = e.filter(
671
- (h) => new Date(h[r]) >= n[0] && new Date(h[r]) <= n[1]
672
- );
673
- if (u.length > 0)
674
- return u;
675
- }
676
- return e;
677
- }
678
- zoomIn(e = this.getZoomRatio()) {
679
- var T;
680
- const t = this.model.get("zoomDomain"), n = Ye.handleWidth, i = (T = this.services.cartesianScales) == null ? void 0 : T.getMainXScale().copy();
681
- i.domain(this.getDefaultZoomBarDomain());
682
- const o = i(t[0]), a = i(t[1]);
683
- if (a - o < n + 1)
684
- return;
685
- const r = i.range(), u = a - o, h = Math.min((r[1] - r[0]) / 2 * (e / 2), u / 2);
686
- let p = o + h, D = a - h;
687
- p >= D && (p = o + u / 2 - n / 2, D = a - u / 2 + n / 2);
688
- const A = [i.invert(p), i.invert(D)];
689
- (t[0].valueOf() !== A[0].valueOf() || t[1].valueOf() !== A[1].valueOf()) && this.handleDomainChange(A);
690
- }
691
- zoomOut(e = this.getZoomRatio()) {
692
- const t = this.model.get("zoomDomain");
693
- if (!this.services.cartesianScales) throw new Error("Services cartesianScales undefined");
694
- const n = this.services.cartesianScales.getMainXScale().copy();
695
- n.domain(this.getDefaultZoomBarDomain());
696
- const i = n(t[0]), o = n(t[1]), a = n.range(), r = (a[1] - a[0]) / 2 * (e / 2), u = Math.max(i - r, a[0]), h = Math.min(o + r, a[1]), p = [n.invert(u), n.invert(h)];
697
- (t[0].valueOf() !== p[0].valueOf() || t[1].valueOf() !== p[1].valueOf()) && this.handleDomainChange(p);
698
- }
699
- resetZoomDomain() {
700
- const e = this.model.get("zoomDomain"), t = this.getDefaultZoomBarDomain();
701
- (e[0].valueOf() !== t[0].valueOf() || e[1].valueOf() !== t[1].valueOf()) && this.handleDomainChange(t);
702
- }
703
- // check if current zoom domain is already the min zoom domain
704
- // when toolbar is rendered, we don't render chart yet
705
- // don't depend on scale range
706
- isMinZoomDomain() {
707
- const e = this.model.get("zoomDomain"), t = this.getDefaultZoomBarDomain();
708
- if (!e || !t)
709
- return !1;
710
- const n = e[1].valueOf() - e[0].valueOf(), i = t[1].valueOf() - t[0].valueOf(), o = c(this.model.getOptions(), "zoomBar", "minZoomRatio");
711
- return n / i < o;
712
- }
713
- // check if current zoom domain is already the max zoom domain
714
- isMaxZoomDomain() {
715
- const e = this.model.get("zoomDomain"), t = this.getDefaultZoomBarDomain();
716
- return !!(e && t && e[0].valueOf() === t[0].valueOf() && e[1].valueOf() === t[1].valueOf());
717
- }
718
- isEmptyState() {
719
- return this.getZoomBarData().length === 0;
720
- }
721
- isZoomBarLoading(e) {
722
- return c(this.model.getOptions(), "zoomBar", e, "loading");
723
- }
724
- isZoomBarLocked(e) {
725
- return c(this.model.getOptions(), "zoomBar", e, "locked");
726
- }
727
- }
728
- export {
729
- pt as C,
730
- xt as E,
731
- Dt as F,
732
- yt as T,
733
- vt as Z,
734
- Ot as a,
735
- At as b,
736
- ze as c,
737
- j as f
738
- };
739
- //# sourceMappingURL=zoom-E2POxw6n.mjs.map