Debian Codegraph @

blazar_dashboard/static/leases/js/vendor/apexcharts.js

raw
1 /*!
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2018 ApexCharts
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 /*!
25 * ApexCharts v4.7.0
26 * (c) 2018-2025 ApexCharts
27 * Released under the MIT License.
28 */
29 (function (global, factory) {
30 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
31 typeof define === 'function' && define.amd ? define(factory) :
32 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ApexCharts = factory());
33 })(this, (function () { 'use strict';
34
35 function _arrayLikeToArray(r, a) {
36 (null == a || a > r.length) && (a = r.length);
37 for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
38 return n;
39 }
40 function _arrayWithHoles(r) {
41 if (Array.isArray(r)) return r;
42 }
43 function _arrayWithoutHoles(r) {
44 if (Array.isArray(r)) return _arrayLikeToArray(r);
45 }
46 function _assertThisInitialized(e) {
47 if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
48 return e;
49 }
50 function _classCallCheck(a, n) {
51 if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
52 }
53 function _defineProperties(e, r) {
54 for (var t = 0; t < r.length; t++) {
55 var o = r[t];
56 o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
57 }
58 }
59 function _createClass(e, r, t) {
60 return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
61 writable: !1
62 }), e;
63 }
64 function _createForOfIteratorHelper(r, e) {
65 var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
66 if (!t) {
67 if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
68 t && (r = t);
69 var n = 0,
70 F = function () {};
71 return {
72 s: F,
73 n: function () {
74 return n >= r.length ? {
75 done: !0
76 } : {
77 done: !1,
78 value: r[n++]
79 };
80 },
81 e: function (r) {
82 throw r;
83 },
84 f: F
85 };
86 }
87 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
88 }
89 var o,
90 a = !0,
91 u = !1;
92 return {
93 s: function () {
94 t = t.call(r);
95 },
96 n: function () {
97 var r = t.next();
98 return a = r.done, r;
99 },
100 e: function (r) {
101 u = !0, o = r;
102 },
103 f: function () {
104 try {
105 a || null == t.return || t.return();
106 } finally {
107 if (u) throw o;
108 }
109 }
110 };
111 }
112 function _createSuper(t) {
113 var r = _isNativeReflectConstruct();
114 return function () {
115 var e,
116 o = _getPrototypeOf(t);
117 if (r) {
118 var s = _getPrototypeOf(this).constructor;
119 e = Reflect.construct(o, arguments, s);
120 } else e = o.apply(this, arguments);
121 return _possibleConstructorReturn(this, e);
122 };
123 }
124 function _defineProperty(e, r, t) {
125 return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
126 value: t,
127 enumerable: !0,
128 configurable: !0,
129 writable: !0
130 }) : e[r] = t, e;
131 }
132 function _getPrototypeOf(t) {
133 return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
134 return t.__proto__ || Object.getPrototypeOf(t);
135 }, _getPrototypeOf(t);
136 }
137 function _inherits(t, e) {
138 if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
139 t.prototype = Object.create(e && e.prototype, {
140 constructor: {
141 value: t,
142 writable: !0,
143 configurable: !0
144 }
145 }), Object.defineProperty(t, "prototype", {
146 writable: !1
147 }), e && _setPrototypeOf(t, e);
148 }
149 function _isNativeReflectConstruct() {
150 try {
151 var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
152 } catch (t) {}
153 return (_isNativeReflectConstruct = function () {
154 return !!t;
155 })();
156 }
157 function _iterableToArray(r) {
158 if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
159 }
160 function _iterableToArrayLimit(r, l) {
161 var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
162 if (null != t) {
163 var e,
164 n,
165 i,
166 u,
167 a = [],
168 f = !0,
169 o = !1;
170 try {
171 if (i = (t = t.call(r)).next, 0 === l) {
172 if (Object(t) !== t) return;
173 f = !1;
174 } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
175 } catch (r) {
176 o = !0, n = r;
177 } finally {
178 try {
179 if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
180 } finally {
181 if (o) throw n;
182 }
183 }
184 return a;
185 }
186 }
187 function _nonIterableRest() {
188 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
189 }
190 function _nonIterableSpread() {
191 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
192 }
193 function ownKeys(e, r) {
194 var t = Object.keys(e);
195 if (Object.getOwnPropertySymbols) {
196 var o = Object.getOwnPropertySymbols(e);
197 r && (o = o.filter(function (r) {
198 return Object.getOwnPropertyDescriptor(e, r).enumerable;
199 })), t.push.apply(t, o);
200 }
201 return t;
202 }
203 function _objectSpread2(e) {
204 for (var r = 1; r < arguments.length; r++) {
205 var t = null != arguments[r] ? arguments[r] : {};
206 r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
207 _defineProperty(e, r, t[r]);
208 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
209 Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
210 });
211 }
212 return e;
213 }
214 function _possibleConstructorReturn(t, e) {
215 if (e && ("object" == typeof e || "function" == typeof e)) return e;
216 if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
217 return _assertThisInitialized(t);
218 }
219 function _setPrototypeOf(t, e) {
220 return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
221 return t.__proto__ = e, t;
222 }, _setPrototypeOf(t, e);
223 }
224 function _slicedToArray(r, e) {
225 return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
226 }
227 function _toConsumableArray(r) {
228 return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
229 }
230 function _toPrimitive(t, r) {
231 if ("object" != typeof t || !t) return t;
232 var e = t[Symbol.toPrimitive];
233 if (void 0 !== e) {
234 var i = e.call(t, r || "default");
235 if ("object" != typeof i) return i;
236 throw new TypeError("@@toPrimitive must return a primitive value.");
237 }
238 return ("string" === r ? String : Number)(t);
239 }
240 function _toPropertyKey(t) {
241 var i = _toPrimitive(t, "string");
242 return "symbol" == typeof i ? i : i + "";
243 }
244 function _typeof(o) {
245 "@babel/helpers - typeof";
246
247 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
248 return typeof o;
249 } : function (o) {
250 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
251 }, _typeof(o);
252 }
253 function _unsupportedIterableToArray(r, a) {
254 if (r) {
255 if ("string" == typeof r) return _arrayLikeToArray(r, a);
256 var t = {}.toString.call(r).slice(8, -1);
257 return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
258 }
259 }
260
261 /*
262 ** Generic functions which are not dependent on ApexCharts
263 */
264 var Utils$1 = /*#__PURE__*/function () {
265 function Utils() {
266 _classCallCheck(this, Utils);
267 }
268 _createClass(Utils, [{
269 key: "shadeRGBColor",
270 value: function shadeRGBColor(percent, color) {
271 var f = color.split(','),
272 t = percent < 0 ? 0 : 255,
273 p = percent < 0 ? percent * -1 : percent,
274 R = parseInt(f[0].slice(4), 10),
275 G = parseInt(f[1], 10),
276 B = parseInt(f[2], 10);
277 return 'rgb(' + (Math.round((t - R) * p) + R) + ',' + (Math.round((t - G) * p) + G) + ',' + (Math.round((t - B) * p) + B) + ')';
278 }
279 }, {
280 key: "shadeHexColor",
281 value: function shadeHexColor(percent, color) {
282 var f = parseInt(color.slice(1), 16),
283 t = percent < 0 ? 0 : 255,
284 p = percent < 0 ? percent * -1 : percent,
285 R = f >> 16,
286 G = f >> 8 & 0x00ff,
287 B = f & 0x0000ff;
288 return '#' + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
289 }
290
291 // beautiful color shading blending code
292 // http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors
293 }, {
294 key: "shadeColor",
295 value: function shadeColor(p, color) {
296 if (Utils.isColorHex(color)) {
297 return this.shadeHexColor(p, color);
298 } else {
299 return this.shadeRGBColor(p, color);
300 }
301 }
302 }], [{
303 key: "bind",
304 value: function bind(fn, me) {
305 return function () {
306 return fn.apply(me, arguments);
307 };
308 }
309 }, {
310 key: "isObject",
311 value: function isObject(item) {
312 return item && _typeof(item) === 'object' && !Array.isArray(item) && item != null;
313 }
314
315 // Type checking that works across different window objects
316 }, {
317 key: "is",
318 value: function is(type, val) {
319 return Object.prototype.toString.call(val) === '[object ' + type + ']';
320 }
321 }, {
322 key: "isSafari",
323 value: function isSafari() {
324 return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
325 }
326 }, {
327 key: "listToArray",
328 value: function listToArray(list) {
329 var i,
330 array = [];
331 for (i = 0; i < list.length; i++) {
332 array[i] = list[i];
333 }
334 return array;
335 }
336
337 // to extend defaults with user options
338 // credit: http://stackoverflow.com/questions/27936772/deep-object-merging-in-es6-es7#answer-34749873
339 }, {
340 key: "extend",
341 value: function extend(target, source) {
342 var _this = this;
343 if (typeof Object.assign !== 'function') {
344 (function () {
345 Object.assign = function (target) {
346
347 // We must check against these specific cases.
348 if (target === undefined || target === null) {
349 throw new TypeError('Cannot convert undefined or null to object');
350 }
351 var output = Object(target);
352 for (var index = 1; index < arguments.length; index++) {
353 var _source = arguments[index];
354 if (_source !== undefined && _source !== null) {
355 for (var nextKey in _source) {
356 if (_source.hasOwnProperty(nextKey)) {
357 output[nextKey] = _source[nextKey];
358 }
359 }
360 }
361 }
362 return output;
363 };
364 })();
365 }
366 var output = Object.assign({}, target);
367 if (this.isObject(target) && this.isObject(source)) {
368 Object.keys(source).forEach(function (key) {
369 if (_this.isObject(source[key])) {
370 if (!(key in target)) {
371 Object.assign(output, _defineProperty({}, key, source[key]));
372 } else {
373 output[key] = _this.extend(target[key], source[key]);
374 }
375 } else {
376 Object.assign(output, _defineProperty({}, key, source[key]));
377 }
378 });
379 }
380 return output;
381 }
382 }, {
383 key: "extendArray",
384 value: function extendArray(arrToExtend, resultArr) {
385 var extendedArr = [];
386 arrToExtend.map(function (item) {
387 extendedArr.push(Utils.extend(resultArr, item));
388 });
389 arrToExtend = extendedArr;
390 return arrToExtend;
391 }
392
393 // If month counter exceeds 12, it starts again from 1
394 }, {
395 key: "monthMod",
396 value: function monthMod(month) {
397 return month % 12;
398 }
399 }, {
400 key: "clone",
401 value: function clone(source) {
402 var visited = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
403 if (source === null || _typeof(source) !== 'object') {
404 return source;
405 }
406 if (visited.has(source)) {
407 return visited.get(source);
408 }
409 var cloneResult;
410 if (Array.isArray(source)) {
411 cloneResult = [];
412 visited.set(source, cloneResult);
413 for (var i = 0; i < source.length; i++) {
414 cloneResult[i] = this.clone(source[i], visited);
415 }
416 } else if (source instanceof Date) {
417 cloneResult = new Date(source.getTime());
418 } else {
419 cloneResult = {};
420 visited.set(source, cloneResult);
421 for (var prop in source) {
422 if (source.hasOwnProperty(prop)) {
423 cloneResult[prop] = this.clone(source[prop], visited);
424 }
425 }
426 }
427 return cloneResult;
428 }
429 }, {
430 key: "log10",
431 value: function log10(x) {
432 return Math.log(x) / Math.LN10;
433 }
434 }, {
435 key: "roundToBase10",
436 value: function roundToBase10(x) {
437 return Math.pow(10, Math.floor(Math.log10(x)));
438 }
439 }, {
440 key: "roundToBase",
441 value: function roundToBase(x, base) {
442 return Math.pow(base, Math.floor(Math.log(x) / Math.log(base)));
443 }
444 }, {
445 key: "parseNumber",
446 value: function parseNumber(val) {
447 if (val === null) return val;
448 return parseFloat(val);
449 }
450 }, {
451 key: "stripNumber",
452 value: function stripNumber(num) {
453 var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
454 return Number.isInteger(num) ? num : parseFloat(num.toPrecision(precision));
455 }
456 }, {
457 key: "randomId",
458 value: function randomId() {
459 return (Math.random() + 1).toString(36).substring(4);
460 }
461 }, {
462 key: "noExponents",
463 value: function noExponents(num) {
464 // Check if the number contains 'e' (exponential notation)
465 if (num.toString().includes('e')) {
466 return Math.round(num); // Round the number
467 }
468 return num; // Return as-is if no exponential notation
469 }
470 }, {
471 key: "elementExists",
472 value: function elementExists(element) {
473 if (!element || !element.isConnected) {
474 return false;
475 }
476 return true;
477 }
478 }, {
479 key: "getDimensions",
480 value: function getDimensions(el) {
481 var computedStyle = getComputedStyle(el, null);
482 var elementHeight = el.clientHeight;
483 var elementWidth = el.clientWidth;
484 elementHeight -= parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom);
485 elementWidth -= parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight);
486 return [elementWidth, elementHeight];
487 }
488 }, {
489 key: "getBoundingClientRect",
490 value: function getBoundingClientRect(element) {
491 var rect = element.getBoundingClientRect();
492 return {
493 top: rect.top,
494 right: rect.right,
495 bottom: rect.bottom,
496 left: rect.left,
497 width: element.clientWidth,
498 height: element.clientHeight,
499 x: rect.left,
500 y: rect.top
501 };
502 }
503 }, {
504 key: "getLargestStringFromArr",
505 value: function getLargestStringFromArr(arr) {
506 return arr.reduce(function (a, b) {
507 if (Array.isArray(b)) {
508 b = b.reduce(function (aa, bb) {
509 return aa.length > bb.length ? aa : bb;
510 });
511 }
512 return a.length > b.length ? a : b;
513 }, 0);
514 }
515
516 // http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb#answer-12342275
517 }, {
518 key: "hexToRgba",
519 value: function hexToRgba() {
520 var hex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#999999';
521 var opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.6;
522 if (hex.substring(0, 1) !== '#') {
523 hex = '#999999';
524 }
525 var h = hex.replace('#', '');
526 h = h.match(new RegExp('(.{' + h.length / 3 + '})', 'g'));
527 for (var i = 0; i < h.length; i++) {
528 h[i] = parseInt(h[i].length === 1 ? h[i] + h[i] : h[i], 16);
529 }
530 if (typeof opacity !== 'undefined') h.push(opacity);
531 return 'rgba(' + h.join(',') + ')';
532 }
533 }, {
534 key: "getOpacityFromRGBA",
535 value: function getOpacityFromRGBA(rgba) {
536 return parseFloat(rgba.replace(/^.*,(.+)\)/, '$1'));
537 }
538 }, {
539 key: "rgb2hex",
540 value: function rgb2hex(rgb) {
541 rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
542 return rgb && rgb.length === 4 ? '#' + ('0' + parseInt(rgb[1], 10).toString(16)).slice(-2) + ('0' + parseInt(rgb[2], 10).toString(16)).slice(-2) + ('0' + parseInt(rgb[3], 10).toString(16)).slice(-2) : '';
543 }
544 }, {
545 key: "isColorHex",
546 value: function isColorHex(color) {
547 return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)|(^#[0-9A-F]{8}$)/i.test(color);
548 }
549 }, {
550 key: "getPolygonPos",
551 value: function getPolygonPos(size, dataPointsLen) {
552 var dotsArray = [];
553 var angle = Math.PI * 2 / dataPointsLen;
554 for (var i = 0; i < dataPointsLen; i++) {
555 var curPos = {};
556 curPos.x = size * Math.sin(i * angle);
557 curPos.y = -size * Math.cos(i * angle);
558 dotsArray.push(curPos);
559 }
560 return dotsArray;
561 }
562 }, {
563 key: "polarToCartesian",
564 value: function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
565 var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
566 return {
567 x: centerX + radius * Math.cos(angleInRadians),
568 y: centerY + radius * Math.sin(angleInRadians)
569 };
570 }
571 }, {
572 key: "escapeString",
573 value: function escapeString(str) {
574 var escapeWith = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'x';
575 var newStr = str.toString().slice();
576 newStr = newStr.replace(/[` ~!@#$%^&*()|+\=?;:'",.<>{}[\]\\/]/gi, escapeWith);
577 return newStr;
578 }
579 }, {
580 key: "negToZero",
581 value: function negToZero(val) {
582 return val < 0 ? 0 : val;
583 }
584 }, {
585 key: "moveIndexInArray",
586 value: function moveIndexInArray(arr, old_index, new_index) {
587 if (new_index >= arr.length) {
588 var k = new_index - arr.length + 1;
589 while (k--) {
590 arr.push(undefined);
591 }
592 }
593 arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
594 return arr;
595 }
596 }, {
597 key: "extractNumber",
598 value: function extractNumber(s) {
599 return parseFloat(s.replace(/[^\d.]*/g, ''));
600 }
601 }, {
602 key: "findAncestor",
603 value: function findAncestor(el, cls) {
604 while ((el = el.parentElement) && !el.classList.contains(cls)) {
605 }
606 return el;
607 }
608 }, {
609 key: "setELstyles",
610 value: function setELstyles(el, styles) {
611 for (var key in styles) {
612 if (styles.hasOwnProperty(key)) {
613 el.style.key = styles[key];
614 }
615 }
616 }
617 // prevents JS prevision errors when adding
618 }, {
619 key: "preciseAddition",
620 value: function preciseAddition(a, b) {
621 var aDecimals = (String(a).split('.')[1] || '').length;
622 var bDecimals = (String(b).split('.')[1] || '').length;
623 var factor = Math.pow(10, Math.max(aDecimals, bDecimals));
624 return (Math.round(a * factor) + Math.round(b * factor)) / factor;
625 }
626 }, {
627 key: "isNumber",
628 value: function isNumber(value) {
629 return !isNaN(value) && parseFloat(Number(value)) === value && !isNaN(parseInt(value, 10));
630 }
631 }, {
632 key: "isFloat",
633 value: function isFloat(n) {
634 return Number(n) === n && n % 1 !== 0;
635 }
636 }, {
637 key: "isMsEdge",
638 value: function isMsEdge() {
639 var ua = window.navigator.userAgent;
640 var edge = ua.indexOf('Edge/');
641 if (edge > 0) {
642 // Edge (IE 12+) => return version number
643 return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
644 }
645
646 // other browser
647 return false;
648 }
649 //
650 // Find the Greatest Common Divisor of two numbers
651 //
652 }, {
653 key: "getGCD",
654 value: function getGCD(a, b) {
655 var p = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 7;
656 var big = Math.pow(10, p - Math.floor(Math.log10(Math.max(a, b))));
657 a = Math.round(Math.abs(a) * big);
658 b = Math.round(Math.abs(b) * big);
659 while (b) {
660 var t = b;
661 b = a % b;
662 a = t;
663 }
664 return a / big;
665 }
666 }, {
667 key: "getPrimeFactors",
668 value: function getPrimeFactors(n) {
669 var factors = [];
670 var divisor = 2;
671 while (n >= 2) {
672 if (n % divisor == 0) {
673 factors.push(divisor);
674 n = n / divisor;
675 } else {
676 divisor++;
677 }
678 }
679 return factors;
680 }
681 }, {
682 key: "mod",
683 value: function mod(a, b) {
684 var p = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 7;
685 var big = Math.pow(10, p - Math.floor(Math.log10(Math.max(a, b))));
686 a = Math.round(Math.abs(a) * big);
687 b = Math.round(Math.abs(b) * big);
688 return a % b / big;
689 }
690 }]);
691 return Utils;
692 }();
693
694 /**
695 * ApexCharts Animation Class.
696 *
697 * @module Animations
698 **/
699 var Animations = /*#__PURE__*/function () {
700 function Animations(ctx) {
701 _classCallCheck(this, Animations);
702 this.ctx = ctx;
703 this.w = ctx.w;
704 }
705 _createClass(Animations, [{
706 key: "animateLine",
707 value: function animateLine(el, from, to, speed) {
708 el.attr(from).animate(speed).attr(to);
709 }
710
711 /*
712 ** Animate radius of a circle element
713 */
714 }, {
715 key: "animateMarker",
716 value: function animateMarker(el, speed, easing, cb) {
717 el.attr({
718 opacity: 0
719 }).animate(speed).attr({
720 opacity: 1
721 }).after(function () {
722 cb();
723 });
724 }
725
726 /*
727 ** Animate rect properties
728 */
729 }, {
730 key: "animateRect",
731 value: function animateRect(el, from, to, speed, fn) {
732 el.attr(from).animate(speed).attr(to).after(function () {
733 return fn();
734 });
735 }
736 }, {
737 key: "animatePathsGradually",
738 value: function animatePathsGradually(params) {
739 var el = params.el,
740 realIndex = params.realIndex,
741 j = params.j,
742 fill = params.fill,
743 pathFrom = params.pathFrom,
744 pathTo = params.pathTo,
745 speed = params.speed,
746 delay = params.delay;
747 var me = this;
748 var w = this.w;
749 var delayFactor = 0;
750 if (w.config.chart.animations.animateGradually.enabled) {
751 delayFactor = w.config.chart.animations.animateGradually.delay;
752 }
753 if (w.config.chart.animations.dynamicAnimation.enabled && w.globals.dataChanged && w.config.chart.type !== 'bar') {
754 // disabled due to this bug - https://github.com/apexcharts/vue-apexcharts/issues/75
755 delayFactor = 0;
756 }
757 me.morphSVG(el, realIndex, j, w.config.chart.type === 'line' && !w.globals.comboCharts ? 'stroke' : fill, pathFrom, pathTo, speed, delay * delayFactor);
758 }
759 }, {
760 key: "showDelayedElements",
761 value: function showDelayedElements() {
762 this.w.globals.delayedElements.forEach(function (d) {
763 var ele = d.el;
764 ele.classList.remove('apexcharts-element-hidden');
765 ele.classList.add('apexcharts-hidden-element-shown');
766 });
767 }
768 }, {
769 key: "animationCompleted",
770 value: function animationCompleted(el) {
771 var w = this.w;
772 if (w.globals.animationEnded) return;
773 w.globals.animationEnded = true;
774 this.showDelayedElements();
775 if (typeof w.config.chart.events.animationEnd === 'function') {
776 w.config.chart.events.animationEnd(this.ctx, {
777 el: el,
778 w: w
779 });
780 }
781 }
782
783 // SVG.js animation for morphing one path to another
784 }, {
785 key: "morphSVG",
786 value: function morphSVG(el, realIndex, j, fill, pathFrom, pathTo, speed, delay) {
787 var _this = this;
788 var w = this.w;
789 if (!pathFrom) {
790 pathFrom = el.attr('pathFrom');
791 }
792 if (!pathTo) {
793 pathTo = el.attr('pathTo');
794 }
795 var disableAnimationForCorrupPath = function disableAnimationForCorrupPath(path) {
796 if (w.config.chart.type === 'radar') {
797 // radar chart drops the path to bottom and hence a corrup path looks ugly
798 // therefore, disable animation for such a case
799 speed = 1;
800 }
801 return "M 0 ".concat(w.globals.gridHeight);
802 };
803 if (!pathFrom || pathFrom.indexOf('undefined') > -1 || pathFrom.indexOf('NaN') > -1) {
804 pathFrom = disableAnimationForCorrupPath();
805 }
806 if (!pathTo.trim() || pathTo.indexOf('undefined') > -1 || pathTo.indexOf('NaN') > -1) {
807 pathTo = disableAnimationForCorrupPath();
808 }
809 if (!w.globals.shouldAnimate) {
810 speed = 1;
811 }
812 el.plot(pathFrom).animate(1, delay).plot(pathFrom).animate(speed, delay).plot(pathTo).after(function () {
813 // a flag to indicate that the original mount function can return true now as animation finished here
814 if (Utils$1.isNumber(j)) {
815 if (j === w.globals.series[w.globals.maxValsInArrayIndex].length - 2 && w.globals.shouldAnimate) {
816 _this.animationCompleted(el);
817 }
818 } else if (fill !== 'none' && w.globals.shouldAnimate) {
819 if (!w.globals.comboCharts && realIndex === w.globals.series.length - 1 || w.globals.comboCharts) {
820 _this.animationCompleted(el);
821 }
822 }
823 _this.showDelayedElements();
824 });
825 }
826 }]);
827 return Animations;
828 }();
829
830 const methods$1 = {};
831 const names = [];
832
833 function registerMethods(name, m) {
834 if (Array.isArray(name)) {
835 for (const _name of name) {
836 registerMethods(_name, m);
837 }
838 return
839 }
840
841 if (typeof name === 'object') {
842 for (const _name in name) {
843 registerMethods(_name, name[_name]);
844 }
845 return
846 }
847
848 addMethodNames(Object.getOwnPropertyNames(m));
849 methods$1[name] = Object.assign(methods$1[name] || {}, m);
850 }
851
852 function getMethodsFor(name) {
853 return methods$1[name] || {}
854 }
855
856 function getMethodNames() {
857 return [...new Set(names)]
858 }
859
860 function addMethodNames(_names) {
861 names.push(..._names);
862 }
863
864 // Map function
865 function map(array, block) {
866 let i;
867 const il = array.length;
868 const result = [];
869
870 for (i = 0; i < il; i++) {
871 result.push(block(array[i]));
872 }
873
874 return result
875 }
876
877 // Filter function
878 function filter(array, block) {
879 let i;
880 const il = array.length;
881 const result = [];
882
883 for (i = 0; i < il; i++) {
884 if (block(array[i])) {
885 result.push(array[i]);
886 }
887 }
888
889 return result
890 }
891
892 // Degrees to radians
893 function radians(d) {
894 return ((d % 360) * Math.PI) / 180
895 }
896
897 // Convert camel cased string to dash separated
898 function unCamelCase(s) {
899 return s.replace(/([A-Z])/g, function (m, g) {
900 return '-' + g.toLowerCase()
901 })
902 }
903
904 // Capitalize first letter of a string
905 function capitalize(s) {
906 return s.charAt(0).toUpperCase() + s.slice(1)
907 }
908
909 // Calculate proportional width and height values when necessary
910 function proportionalSize(element, width, height, box) {
911 if (width == null || height == null) {
912 box = box || element.bbox();
913
914 if (width == null) {
915 width = (box.width / box.height) * height;
916 } else if (height == null) {
917 height = (box.height / box.width) * width;
918 }
919 }
920
921 return {
922 width: width,
923 height: height
924 }
925 }
926
927 /**
928 * This function adds support for string origins.
929 * It searches for an origin in o.origin o.ox and o.originX.
930 * This way, origin: {x: 'center', y: 50} can be passed as well as ox: 'center', oy: 50
931 **/
932 function getOrigin(o, element) {
933 const origin = o.origin;
934 // First check if origin is in ox or originX
935 let ox = o.ox != null ? o.ox : o.originX != null ? o.originX : 'center';
936 let oy = o.oy != null ? o.oy : o.originY != null ? o.originY : 'center';
937
938 // Then check if origin was used and overwrite in that case
939 if (origin != null) {
940 [ox, oy] = Array.isArray(origin)
941 ? origin
942 : typeof origin === 'object'
943 ? [origin.x, origin.y]
944 : [origin, origin];
945 }
946
947 // Make sure to only call bbox when actually needed
948 const condX = typeof ox === 'string';
949 const condY = typeof oy === 'string';
950 if (condX || condY) {
951 const { height, width, x, y } = element.bbox();
952
953 // And only overwrite if string was passed for this specific axis
954 if (condX) {
955 ox = ox.includes('left')
956 ? x
957 : ox.includes('right')
958 ? x + width
959 : x + width / 2;
960 }
961
962 if (condY) {
963 oy = oy.includes('top')
964 ? y
965 : oy.includes('bottom')
966 ? y + height
967 : y + height / 2;
968 }
969 }
970
971 // Return the origin as it is if it wasn't a string
972 return [ox, oy]
973 }
974
975 const descriptiveElements = new Set(['desc', 'metadata', 'title']);
976 const isDescriptive = (element) =>
977 descriptiveElements.has(element.nodeName);
978
979 const writeDataToDom = (element, data, defaults = {}) => {
980 const cloned = { ...data };
981
982 for (const key in cloned) {
983 if (cloned[key].valueOf() === defaults[key]) {
984 delete cloned[key];
985 }
986 }
987
988 if (Object.keys(cloned).length) {
989 element.node.setAttribute('data-svgjs', JSON.stringify(cloned)); // see #428
990 } else {
991 element.node.removeAttribute('data-svgjs');
992 element.node.removeAttribute('svgjs:data');
993 }
994 };
995
996 // Default namespaces
997 const svg = 'http://www.w3.org/2000/svg';
998 const html = 'http://www.w3.org/1999/xhtml';
999 const xmlns = 'http://www.w3.org/2000/xmlns/';
1000 const xlink = 'http://www.w3.org/1999/xlink';
1001
1002 const globals = {
1003 window: typeof window === 'undefined' ? null : window,
1004 document: typeof document === 'undefined' ? null : document
1005 };
1006
1007 function getWindow() {
1008 return globals.window
1009 }
1010
1011 let Base$1 = class Base {
1012 // constructor (node/*, {extensions = []} */) {
1013 // // this.tags = []
1014 // //
1015 // // for (let extension of extensions) {
1016 // // extension.setup.call(this, node)
1017 // // this.tags.push(extension.name)
1018 // // }
1019 // }
1020 };
1021
1022 const elements = {};
1023 const root = '___SYMBOL___ROOT___';
1024
1025 // Method for element creation
1026 function create(name, ns = svg) {
1027 // create element
1028 return globals.document.createElementNS(ns, name)
1029 }
1030
1031 function makeInstance(element, isHTML = false) {
1032 if (element instanceof Base$1) return element
1033
1034 if (typeof element === 'object') {
1035 return adopter(element)
1036 }
1037
1038 if (element == null) {
1039 return new elements[root]()
1040 }
1041
1042 if (typeof element === 'string' && element.charAt(0) !== '<') {
1043 return adopter(globals.document.querySelector(element))
1044 }
1045
1046 // Make sure, that HTML elements are created with the correct namespace
1047 const wrapper = isHTML ? globals.document.createElement('div') : create('svg');
1048 wrapper.innerHTML = element;
1049
1050 // We can use firstChild here because we know,
1051 // that the first char is < and thus an element
1052 element = adopter(wrapper.firstChild);
1053
1054 // make sure, that element doesn't have its wrapper attached
1055 wrapper.removeChild(wrapper.firstChild);
1056 return element
1057 }
1058
1059 function nodeOrNew(name, node) {
1060 return node &&
1061 (node instanceof globals.window.Node ||
1062 (node.ownerDocument &&
1063 node instanceof node.ownerDocument.defaultView.Node))
1064 ? node
1065 : create(name)
1066 }
1067
1068 // Adopt existing svg elements
1069 function adopt(node) {
1070 // check for presence of node
1071 if (!node) return null
1072
1073 // make sure a node isn't already adopted
1074 if (node.instance instanceof Base$1) return node.instance
1075
1076 if (node.nodeName === '#document-fragment') {
1077 return new elements.Fragment(node)
1078 }
1079
1080 // initialize variables
1081 let className = capitalize(node.nodeName || 'Dom');
1082
1083 // Make sure that gradients are adopted correctly
1084 if (className === 'LinearGradient' || className === 'RadialGradient') {
1085 className = 'Gradient';
1086
1087 // Fallback to Dom if element is not known
1088 } else if (!elements[className]) {
1089 className = 'Dom';
1090 }
1091
1092 return new elements[className](node)
1093 }
1094
1095 let adopter = adopt;
1096
1097 function register(element, name = element.name, asRoot = false) {
1098 elements[name] = element;
1099 if (asRoot) elements[root] = element;
1100
1101 addMethodNames(Object.getOwnPropertyNames(element.prototype));
1102
1103 return element
1104 }
1105
1106 function getClass(name) {
1107 return elements[name]
1108 }
1109
1110 // Element id sequence
1111 let did = 1000;
1112
1113 // Get next named element id
1114 function eid(name) {
1115 return 'Svgjs' + capitalize(name) + did++
1116 }
1117
1118 // Deep new id assignment
1119 function assignNewId(node) {
1120 // do the same for SVG child nodes as well
1121 for (let i = node.children.length - 1; i >= 0; i--) {
1122 assignNewId(node.children[i]);
1123 }
1124
1125 if (node.id) {
1126 node.id = eid(node.nodeName);
1127 return node
1128 }
1129
1130 return node
1131 }
1132
1133 // Method for extending objects
1134 function extend(modules, methods) {
1135 let key, i;
1136
1137 modules = Array.isArray(modules) ? modules : [modules];
1138
1139 for (i = modules.length - 1; i >= 0; i--) {
1140 for (key in methods) {
1141 modules[i].prototype[key] = methods[key];
1142 }
1143 }
1144 }
1145
1146 function wrapWithAttrCheck(fn) {
1147 return function (...args) {
1148 const o = args[args.length - 1];
1149
1150 if (o && o.constructor === Object && !(o instanceof Array)) {
1151 return fn.apply(this, args.slice(0, -1)).attr(o)
1152 } else {
1153 return fn.apply(this, args)
1154 }
1155 }
1156 }
1157
1158 // Get all siblings, including myself
1159 function siblings() {
1160 return this.parent().children()
1161 }
1162
1163 // Get the current position siblings
1164 function position() {
1165 return this.parent().index(this)
1166 }
1167
1168 // Get the next element (will return null if there is none)
1169 function next() {
1170 return this.siblings()[this.position() + 1]
1171 }
1172
1173 // Get the next element (will return null if there is none)
1174 function prev() {
1175 return this.siblings()[this.position() - 1]
1176 }
1177
1178 // Send given element one step forward
1179 function forward() {
1180 const i = this.position();
1181 const p = this.parent();
1182
1183 // move node one step forward
1184 p.add(this.remove(), i + 1);
1185
1186 return this
1187 }
1188
1189 // Send given element one step backward
1190 function backward() {
1191 const i = this.position();
1192 const p = this.parent();
1193
1194 p.add(this.remove(), i ? i - 1 : 0);
1195
1196 return this
1197 }
1198
1199 // Send given element all the way to the front
1200 function front() {
1201 const p = this.parent();
1202
1203 // Move node forward
1204 p.add(this.remove());
1205
1206 return this
1207 }
1208
1209 // Send given element all the way to the back
1210 function back() {
1211 const p = this.parent();
1212
1213 // Move node back
1214 p.add(this.remove(), 0);
1215
1216 return this
1217 }
1218
1219 // Inserts a given element before the targeted element
1220 function before(element) {
1221 element = makeInstance(element);
1222 element.remove();
1223
1224 const i = this.position();
1225
1226 this.parent().add(element, i);
1227
1228 return this
1229 }
1230
1231 // Inserts a given element after the targeted element
1232 function after(element) {
1233 element = makeInstance(element);
1234 element.remove();
1235
1236 const i = this.position();
1237
1238 this.parent().add(element, i + 1);
1239
1240 return this
1241 }
1242
1243 function insertBefore(element) {
1244 element = makeInstance(element);
1245 element.before(this);
1246 return this
1247 }
1248
1249 function insertAfter(element) {
1250 element = makeInstance(element);
1251 element.after(this);
1252 return this
1253 }
1254
1255 registerMethods('Dom', {
1256 siblings,
1257 position,
1258 next,
1259 prev,
1260 forward,
1261 backward,
1262 front,
1263 back,
1264 before,
1265 after,
1266 insertBefore,
1267 insertAfter
1268 });
1269
1270 // Parse unit value
1271 const numberAndUnit =
1272 /^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i;
1273
1274 // Parse hex value
1275 const hex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
1276
1277 // Parse rgb value
1278 const rgb = /rgb\((\d+),(\d+),(\d+)\)/;
1279
1280 // Parse reference id
1281 const reference = /(#[a-z_][a-z0-9\-_]*)/i;
1282
1283 // splits a transformation chain
1284 const transforms = /\)\s*,?\s*/;
1285
1286 // Whitespace
1287 const whitespace = /\s/g;
1288
1289 // Test hex value
1290 const isHex = /^#[a-f0-9]{3}$|^#[a-f0-9]{6}$/i;
1291
1292 // Test rgb value
1293 const isRgb = /^rgb\(/;
1294
1295 // Test for blank string
1296 const isBlank = /^(\s+)?$/;
1297
1298 // Test for numeric string
1299 const isNumber = /^[+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
1300
1301 // Test for image url
1302 const isImage = /\.(jpg|jpeg|png|gif|svg)(\?[^=]+.*)?/i;
1303
1304 // split at whitespace and comma
1305 const delimiter = /[\s,]+/;
1306
1307 // Test for path letter
1308 const isPathLetter = /[MLHVCSQTAZ]/i;
1309
1310 // Return array of classes on the node
1311 function classes() {
1312 const attr = this.attr('class');
1313 return attr == null ? [] : attr.trim().split(delimiter)
1314 }
1315
1316 // Return true if class exists on the node, false otherwise
1317 function hasClass(name) {
1318 return this.classes().indexOf(name) !== -1
1319 }
1320
1321 // Add class to the node
1322 function addClass(name) {
1323 if (!this.hasClass(name)) {
1324 const array = this.classes();
1325 array.push(name);
1326 this.attr('class', array.join(' '));
1327 }
1328
1329 return this
1330 }
1331
1332 // Remove class from the node
1333 function removeClass(name) {
1334 if (this.hasClass(name)) {
1335 this.attr(
1336 'class',
1337 this.classes()
1338 .filter(function (c) {
1339 return c !== name
1340 })
1341 .join(' ')
1342 );
1343 }
1344
1345 return this
1346 }
1347
1348 // Toggle the presence of a class on the node
1349 function toggleClass(name) {
1350 return this.hasClass(name) ? this.removeClass(name) : this.addClass(name)
1351 }
1352
1353 registerMethods('Dom', {
1354 classes,
1355 hasClass,
1356 addClass,
1357 removeClass,
1358 toggleClass
1359 });
1360
1361 // Dynamic style generator
1362 function css(style, val) {
1363 const ret = {};
1364 if (arguments.length === 0) {
1365 // get full style as object
1366 this.node.style.cssText
1367 .split(/\s*;\s*/)
1368 .filter(function (el) {
1369 return !!el.length
1370 })
1371 .forEach(function (el) {
1372 const t = el.split(/\s*:\s*/);
1373 ret[t[0]] = t[1];
1374 });
1375 return ret
1376 }
1377
1378 if (arguments.length < 2) {
1379 // get style properties as array
1380 if (Array.isArray(style)) {
1381 for (const name of style) {
1382 const cased = name;
1383 ret[name] = this.node.style.getPropertyValue(cased);
1384 }
1385 return ret
1386 }
1387
1388 // get style for property
1389 if (typeof style === 'string') {
1390 return this.node.style.getPropertyValue(style)
1391 }
1392
1393 // set styles in object
1394 if (typeof style === 'object') {
1395 for (const name in style) {
1396 // set empty string if null/undefined/'' was given
1397 this.node.style.setProperty(
1398 name,
1399 style[name] == null || isBlank.test(style[name]) ? '' : style[name]
1400 );
1401 }
1402 }
1403 }
1404
1405 // set style for property
1406 if (arguments.length === 2) {
1407 this.node.style.setProperty(
1408 style,
1409 val == null || isBlank.test(val) ? '' : val
1410 );
1411 }
1412
1413 return this
1414 }
1415
1416 // Show element
1417 function show() {
1418 return this.css('display', '')
1419 }
1420
1421 // Hide element
1422 function hide() {
1423 return this.css('display', 'none')
1424 }
1425
1426 // Is element visible?
1427 function visible() {
1428 return this.css('display') !== 'none'
1429 }
1430
1431 registerMethods('Dom', {
1432 css,
1433 show,
1434 hide,
1435 visible
1436 });
1437
1438 // Store data values on svg nodes
1439 function data(a, v, r) {
1440 if (a == null) {
1441 // get an object of attributes
1442 return this.data(
1443 map(
1444 filter(
1445 this.node.attributes,
1446 (el) => el.nodeName.indexOf('data-') === 0
1447 ),
1448 (el) => el.nodeName.slice(5)
1449 )
1450 )
1451 } else if (a instanceof Array) {
1452 const data = {};
1453 for (const key of a) {
1454 data[key] = this.data(key);
1455 }
1456 return data
1457 } else if (typeof a === 'object') {
1458 for (v in a) {
1459 this.data(v, a[v]);
1460 }
1461 } else if (arguments.length < 2) {
1462 try {
1463 return JSON.parse(this.attr('data-' + a))
1464 } catch (e) {
1465 return this.attr('data-' + a)
1466 }
1467 } else {
1468 this.attr(
1469 'data-' + a,
1470 v === null
1471 ? null
1472 : r === true || typeof v === 'string' || typeof v === 'number'
1473 ? v
1474 : JSON.stringify(v)
1475 );
1476 }
1477
1478 return this
1479 }
1480
1481 registerMethods('Dom', { data });
1482
1483 // Remember arbitrary data
1484 function remember(k, v) {
1485 // remember every item in an object individually
1486 if (typeof arguments[0] === 'object') {
1487 for (const key in k) {
1488 this.remember(key, k[key]);
1489 }
1490 } else if (arguments.length === 1) {
1491 // retrieve memory
1492 return this.memory()[k]
1493 } else {
1494 // store memory
1495 this.memory()[k] = v;
1496 }
1497
1498 return this
1499 }
1500
1501 // Erase a given memory
1502 function forget() {
1503 if (arguments.length === 0) {
1504 this._memory = {};
1505 } else {
1506 for (let i = arguments.length - 1; i >= 0; i--) {
1507 delete this.memory()[arguments[i]];
1508 }
1509 }
1510 return this
1511 }
1512
1513 // This triggers creation of a new hidden class which is not performant
1514 // However, this function is not rarely used so it will not happen frequently
1515 // Return local memory object
1516 function memory() {
1517 return (this._memory = this._memory || {})
1518 }
1519
1520 registerMethods('Dom', { remember, forget, memory });
1521
1522 function sixDigitHex(hex) {
1523 return hex.length === 4
1524 ? [
1525 '#',
1526 hex.substring(1, 2),
1527 hex.substring(1, 2),
1528 hex.substring(2, 3),
1529 hex.substring(2, 3),
1530 hex.substring(3, 4),
1531 hex.substring(3, 4)
1532 ].join('')
1533 : hex
1534 }
1535
1536 function componentHex(component) {
1537 const integer = Math.round(component);
1538 const bounded = Math.max(0, Math.min(255, integer));
1539 const hex = bounded.toString(16);
1540 return hex.length === 1 ? '0' + hex : hex
1541 }
1542
1543 function is(object, space) {
1544 for (let i = space.length; i--; ) {
1545 if (object[space[i]] == null) {
1546 return false
1547 }
1548 }
1549 return true
1550 }
1551
1552 function getParameters(a, b) {
1553 const params = is(a, 'rgb')
1554 ? { _a: a.r, _b: a.g, _c: a.b, _d: 0, space: 'rgb' }
1555 : is(a, 'xyz')
1556 ? { _a: a.x, _b: a.y, _c: a.z, _d: 0, space: 'xyz' }
1557 : is(a, 'hsl')
1558 ? { _a: a.h, _b: a.s, _c: a.l, _d: 0, space: 'hsl' }
1559 : is(a, 'lab')
1560 ? { _a: a.l, _b: a.a, _c: a.b, _d: 0, space: 'lab' }
1561 : is(a, 'lch')
1562 ? { _a: a.l, _b: a.c, _c: a.h, _d: 0, space: 'lch' }
1563 : is(a, 'cmyk')
1564 ? { _a: a.c, _b: a.m, _c: a.y, _d: a.k, space: 'cmyk' }
1565 : { _a: 0, _b: 0, _c: 0, space: 'rgb' };
1566
1567 params.space = b || params.space;
1568 return params
1569 }
1570
1571 function cieSpace(space) {
1572 if (space === 'lab' || space === 'xyz' || space === 'lch') {
1573 return true
1574 } else {
1575 return false
1576 }
1577 }
1578
1579 function hueToRgb(p, q, t) {
1580 if (t < 0) t += 1;
1581 if (t > 1) t -= 1;
1582 if (t < 1 / 6) return p + (q - p) * 6 * t
1583 if (t < 1 / 2) return q
1584 if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
1585 return p
1586 }
1587
1588 class Color {
1589 constructor(...inputs) {
1590 this.init(...inputs);
1591 }
1592
1593 // Test if given value is a color
1594 static isColor(color) {
1595 return (
1596 color && (color instanceof Color || this.isRgb(color) || this.test(color))
1597 )
1598 }
1599
1600 // Test if given value is an rgb object
1601 static isRgb(color) {
1602 return (
1603 color &&
1604 typeof color.r === 'number' &&
1605 typeof color.g === 'number' &&
1606 typeof color.b === 'number'
1607 )
1608 }
1609
1610 /*
1611 Generating random colors
1612 */
1613 static random(mode = 'vibrant', t) {
1614 // Get the math modules
1615 const { random, round, sin, PI: pi } = Math;
1616
1617 // Run the correct generator
1618 if (mode === 'vibrant') {
1619 const l = (81 - 57) * random() + 57;
1620 const c = (83 - 45) * random() + 45;
1621 const h = 360 * random();
1622 const color = new Color(l, c, h, 'lch');
1623 return color
1624 } else if (mode === 'sine') {
1625 t = t == null ? random() : t;
1626 const r = round(80 * sin((2 * pi * t) / 0.5 + 0.01) + 150);
1627 const g = round(50 * sin((2 * pi * t) / 0.5 + 4.6) + 200);
1628 const b = round(100 * sin((2 * pi * t) / 0.5 + 2.3) + 150);
1629 const color = new Color(r, g, b);
1630 return color
1631 } else if (mode === 'pastel') {
1632 const l = (94 - 86) * random() + 86;
1633 const c = (26 - 9) * random() + 9;
1634 const h = 360 * random();
1635 const color = new Color(l, c, h, 'lch');
1636 return color
1637 } else if (mode === 'dark') {
1638 const l = 10 + 10 * random();
1639 const c = (125 - 75) * random() + 86;
1640 const h = 360 * random();
1641 const color = new Color(l, c, h, 'lch');
1642 return color
1643 } else if (mode === 'rgb') {
1644 const r = 255 * random();
1645 const g = 255 * random();
1646 const b = 255 * random();
1647 const color = new Color(r, g, b);
1648 return color
1649 } else if (mode === 'lab') {
1650 const l = 100 * random();
1651 const a = 256 * random() - 128;
1652 const b = 256 * random() - 128;
1653 const color = new Color(l, a, b, 'lab');
1654 return color
1655 } else if (mode === 'grey') {
1656 const grey = 255 * random();
1657 const color = new Color(grey, grey, grey);
1658 return color
1659 } else {
1660 throw new Error('Unsupported random color mode')
1661 }
1662 }
1663
1664 // Test if given value is a color string
1665 static test(color) {
1666 return typeof color === 'string' && (isHex.test(color) || isRgb.test(color))
1667 }
1668
1669 cmyk() {
1670 // Get the rgb values for the current color
1671 const { _a, _b, _c } = this.rgb();
1672 const [r, g, b] = [_a, _b, _c].map((v) => v / 255);
1673
1674 // Get the cmyk values in an unbounded format
1675 const k = Math.min(1 - r, 1 - g, 1 - b);
1676
1677 if (k === 1) {
1678 // Catch the black case
1679 return new Color(0, 0, 0, 1, 'cmyk')
1680 }
1681
1682 const c = (1 - r - k) / (1 - k);
1683 const m = (1 - g - k) / (1 - k);
1684 const y = (1 - b - k) / (1 - k);
1685
1686 // Construct the new color
1687 const color = new Color(c, m, y, k, 'cmyk');
1688 return color
1689 }
1690
1691 hsl() {
1692 // Get the rgb values
1693 const { _a, _b, _c } = this.rgb();
1694 const [r, g, b] = [_a, _b, _c].map((v) => v / 255);
1695
1696 // Find the maximum and minimum values to get the lightness
1697 const max = Math.max(r, g, b);
1698 const min = Math.min(r, g, b);
1699 const l = (max + min) / 2;
1700
1701 // If the r, g, v values are identical then we are grey
1702 const isGrey = max === min;
1703
1704 // Calculate the hue and saturation
1705 const delta = max - min;
1706 const s = isGrey
1707 ? 0
1708 : l > 0.5
1709 ? delta / (2 - max - min)
1710 : delta / (max + min);
1711 const h = isGrey
1712 ? 0
1713 : max === r
1714 ? ((g - b) / delta + (g < b ? 6 : 0)) / 6
1715 : max === g
1716 ? ((b - r) / delta + 2) / 6
1717 : max === b
1718 ? ((r - g) / delta + 4) / 6
1719 : 0;
1720
1721 // Construct and return the new color
1722 const color = new Color(360 * h, 100 * s, 100 * l, 'hsl');
1723 return color
1724 }
1725
1726 init(a = 0, b = 0, c = 0, d = 0, space = 'rgb') {
1727 // This catches the case when a falsy value is passed like ''
1728 a = !a ? 0 : a;
1729
1730 // Reset all values in case the init function is rerun with new color space
1731 if (this.space) {
1732 for (const component in this.space) {
1733 delete this[this.space[component]];
1734 }
1735 }
1736
1737 if (typeof a === 'number') {
1738 // Allow for the case that we don't need d...
1739 space = typeof d === 'string' ? d : space;
1740 d = typeof d === 'string' ? 0 : d;
1741
1742 // Assign the values straight to the color
1743 Object.assign(this, { _a: a, _b: b, _c: c, _d: d, space });
1744 // If the user gave us an array, make the color from it
1745 } else if (a instanceof Array) {
1746 this.space = b || (typeof a[3] === 'string' ? a[3] : a[4]) || 'rgb';
1747 Object.assign(this, { _a: a[0], _b: a[1], _c: a[2], _d: a[3] || 0 });
1748 } else if (a instanceof Object) {
1749 // Set the object up and assign its values directly
1750 const values = getParameters(a, b);
1751 Object.assign(this, values);
1752 } else if (typeof a === 'string') {
1753 if (isRgb.test(a)) {
1754 const noWhitespace = a.replace(whitespace, '');
1755 const [_a, _b, _c] = rgb
1756 .exec(noWhitespace)
1757 .slice(1, 4)
1758 .map((v) => parseInt(v));
1759 Object.assign(this, { _a, _b, _c, _d: 0, space: 'rgb' });
1760 } else if (isHex.test(a)) {
1761 const hexParse = (v) => parseInt(v, 16);
1762 const [, _a, _b, _c] = hex.exec(sixDigitHex(a)).map(hexParse);
1763 Object.assign(this, { _a, _b, _c, _d: 0, space: 'rgb' });
1764 } else throw Error("Unsupported string format, can't construct Color")
1765 }
1766
1767 // Now add the components as a convenience
1768 const { _a, _b, _c, _d } = this;
1769 const components =
1770 this.space === 'rgb'
1771 ? { r: _a, g: _b, b: _c }
1772 : this.space === 'xyz'
1773 ? { x: _a, y: _b, z: _c }
1774 : this.space === 'hsl'
1775 ? { h: _a, s: _b, l: _c }
1776 : this.space === 'lab'
1777 ? { l: _a, a: _b, b: _c }
1778 : this.space === 'lch'
1779 ? { l: _a, c: _b, h: _c }
1780 : this.space === 'cmyk'
1781 ? { c: _a, m: _b, y: _c, k: _d }
1782 : {};
1783 Object.assign(this, components);
1784 }
1785
1786 lab() {
1787 // Get the xyz color
1788 const { x, y, z } = this.xyz();
1789
1790 // Get the lab components
1791 const l = 116 * y - 16;
1792 const a = 500 * (x - y);
1793 const b = 200 * (y - z);
1794
1795 // Construct and return a new color
1796 const color = new Color(l, a, b, 'lab');
1797 return color
1798 }
1799
1800 lch() {
1801 // Get the lab color directly
1802 const { l, a, b } = this.lab();
1803
1804 // Get the chromaticity and the hue using polar coordinates
1805 const c = Math.sqrt(a ** 2 + b ** 2);
1806 let h = (180 * Math.atan2(b, a)) / Math.PI;
1807 if (h < 0) {
1808 h *= -1;
1809 h = 360 - h;
1810 }
1811
1812 // Make a new color and return it
1813 const color = new Color(l, c, h, 'lch');
1814 return color
1815 }
1816 /*
1817 Conversion Methods
1818 */
1819
1820 rgb() {
1821 if (this.space === 'rgb') {
1822 return this
1823 } else if (cieSpace(this.space)) {
1824 // Convert to the xyz color space
1825 let { x, y, z } = this;
1826 if (this.space === 'lab' || this.space === 'lch') {
1827 // Get the values in the lab space
1828 let { l, a, b } = this;
1829 if (this.space === 'lch') {
1830 const { c, h } = this;
1831 const dToR = Math.PI / 180;
1832 a = c * Math.cos(dToR * h);
1833 b = c * Math.sin(dToR * h);
1834 }
1835
1836 // Undo the nonlinear function
1837 const yL = (l + 16) / 116;
1838 const xL = a / 500 + yL;
1839 const zL = yL - b / 200;
1840
1841 // Get the xyz values
1842 const ct = 16 / 116;
1843 const mx = 0.008856;
1844 const nm = 7.787;
1845 x = 0.95047 * (xL ** 3 > mx ? xL ** 3 : (xL - ct) / nm);
1846 y = 1.0 * (yL ** 3 > mx ? yL ** 3 : (yL - ct) / nm);
1847 z = 1.08883 * (zL ** 3 > mx ? zL ** 3 : (zL - ct) / nm);
1848 }
1849
1850 // Convert xyz to unbounded rgb values
1851 const rU = x * 3.2406 + y * -1.5372 + z * -0.4986;
1852 const gU = x * -0.9689 + y * 1.8758 + z * 0.0415;
1853 const bU = x * 0.0557 + y * -0.204 + z * 1.057;
1854
1855 // Convert the values to true rgb values
1856 const pow = Math.pow;
1857 const bd = 0.0031308;
1858 const r = rU > bd ? 1.055 * pow(rU, 1 / 2.4) - 0.055 : 12.92 * rU;
1859 const g = gU > bd ? 1.055 * pow(gU, 1 / 2.4) - 0.055 : 12.92 * gU;
1860 const b = bU > bd ? 1.055 * pow(bU, 1 / 2.4) - 0.055 : 12.92 * bU;
1861
1862 // Make and return the color
1863 const color = new Color(255 * r, 255 * g, 255 * b);
1864 return color
1865 } else if (this.space === 'hsl') {
1866 // https://bgrins.github.io/TinyColor/docs/tinycolor.html
1867 // Get the current hsl values
1868 let { h, s, l } = this;
1869 h /= 360;
1870 s /= 100;
1871 l /= 100;
1872
1873 // If we are grey, then just make the color directly
1874 if (s === 0) {
1875 l *= 255;
1876 const color = new Color(l, l, l);
1877 return color
1878 }
1879
1880 // TODO I have no idea what this does :D If you figure it out, tell me!
1881 const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1882 const p = 2 * l - q;
1883
1884 // Get the rgb values
1885 const r = 255 * hueToRgb(p, q, h + 1 / 3);
1886 const g = 255 * hueToRgb(p, q, h);
1887 const b = 255 * hueToRgb(p, q, h - 1 / 3);
1888
1889 // Make a new color
1890 const color = new Color(r, g, b);
1891 return color
1892 } else if (this.space === 'cmyk') {
1893 // https://gist.github.com/felipesabino/5066336
1894 // Get the normalised cmyk values
1895 const { c, m, y, k } = this;
1896
1897 // Get the rgb values
1898 const r = 255 * (1 - Math.min(1, c * (1 - k) + k));
1899 const g = 255 * (1 - Math.min(1, m * (1 - k) + k));
1900 const b = 255 * (1 - Math.min(1, y * (1 - k) + k));
1901
1902 // Form the color and return it
1903 const color = new Color(r, g, b);
1904 return color
1905 } else {
1906 return this
1907 }
1908 }
1909
1910 toArray() {
1911 const { _a, _b, _c, _d, space } = this;
1912 return [_a, _b, _c, _d, space]
1913 }
1914
1915 toHex() {
1916 const [r, g, b] = this._clamped().map(componentHex);
1917 return `#${r}${g}${b}`
1918 }
1919
1920 toRgb() {
1921 const [rV, gV, bV] = this._clamped();
1922 const string = `rgb(${rV},${gV},${bV})`;
1923 return string
1924 }
1925
1926 toString() {
1927 return this.toHex()
1928 }
1929
1930 xyz() {
1931 // Normalise the red, green and blue values
1932 const { _a: r255, _b: g255, _c: b255 } = this.rgb();
1933 const [r, g, b] = [r255, g255, b255].map((v) => v / 255);
1934
1935 // Convert to the lab rgb space
1936 const rL = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
1937 const gL = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
1938 const bL = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
1939
1940 // Convert to the xyz color space without bounding the values
1941 const xU = (rL * 0.4124 + gL * 0.3576 + bL * 0.1805) / 0.95047;
1942 const yU = (rL * 0.2126 + gL * 0.7152 + bL * 0.0722) / 1.0;
1943 const zU = (rL * 0.0193 + gL * 0.1192 + bL * 0.9505) / 1.08883;
1944
1945 // Get the proper xyz values by applying the bounding
1946 const x = xU > 0.008856 ? Math.pow(xU, 1 / 3) : 7.787 * xU + 16 / 116;
1947 const y = yU > 0.008856 ? Math.pow(yU, 1 / 3) : 7.787 * yU + 16 / 116;
1948 const z = zU > 0.008856 ? Math.pow(zU, 1 / 3) : 7.787 * zU + 16 / 116;
1949
1950 // Make and return the color
1951 const color = new Color(x, y, z, 'xyz');
1952 return color
1953 }
1954
1955 /*
1956 Input and Output methods
1957 */
1958
1959 _clamped() {
1960 const { _a, _b, _c } = this.rgb();
1961 const { max, min, round } = Math;
1962 const format = (v) => max(0, min(round(v), 255));
1963 return [_a, _b, _c].map(format)
1964 }
1965
1966 /*
1967 Constructing colors
1968 */
1969 }
1970
1971 class Point {
1972 // Initialize
1973 constructor(...args) {
1974 this.init(...args);
1975 }
1976
1977 // Clone point
1978 clone() {
1979 return new Point(this)
1980 }
1981
1982 init(x, y) {
1983 const base = { x: 0, y: 0 };
1984
1985 // ensure source as object
1986 const source = Array.isArray(x)
1987 ? { x: x[0], y: x[1] }
1988 : typeof x === 'object'
1989 ? { x: x.x, y: x.y }
1990 : { x: x, y: y };
1991
1992 // merge source
1993 this.x = source.x == null ? base.x : source.x;
1994 this.y = source.y == null ? base.y : source.y;
1995
1996 return this
1997 }
1998
1999 toArray() {
2000 return [this.x, this.y]
2001 }
2002
2003 transform(m) {
2004 return this.clone().transformO(m)
2005 }
2006
2007 // Transform point with matrix
2008 transformO(m) {
2009 if (!Matrix.isMatrixLike(m)) {
2010 m = new Matrix(m);
2011 }
2012
2013 const { x, y } = this;
2014
2015 // Perform the matrix multiplication
2016 this.x = m.a * x + m.c * y + m.e;
2017 this.y = m.b * x + m.d * y + m.f;
2018
2019 return this
2020 }
2021 }
2022
2023 function point(x, y) {
2024 return new Point(x, y).transformO(this.screenCTM().inverseO())
2025 }
2026
2027 function closeEnough(a, b, threshold) {
2028 return Math.abs(b - a) < (threshold || 1e-6)
2029 }
2030
2031 class Matrix {
2032 constructor(...args) {
2033 this.init(...args);
2034 }
2035
2036 static formatTransforms(o) {
2037 // Get all of the parameters required to form the matrix
2038 const flipBoth = o.flip === 'both' || o.flip === true;
2039 const flipX = o.flip && (flipBoth || o.flip === 'x') ? -1 : 1;
2040 const flipY = o.flip && (flipBoth || o.flip === 'y') ? -1 : 1;
2041 const skewX =
2042 o.skew && o.skew.length
2043 ? o.skew[0]
2044 : isFinite(o.skew)
2045 ? o.skew
2046 : isFinite(o.skewX)
2047 ? o.skewX
2048 : 0;
2049 const skewY =
2050 o.skew && o.skew.length
2051 ? o.skew[1]
2052 : isFinite(o.skew)
2053 ? o.skew
2054 : isFinite(o.skewY)
2055 ? o.skewY
2056 : 0;
2057 const scaleX =
2058 o.scale && o.scale.length
2059 ? o.scale[0] * flipX
2060 : isFinite(o.scale)
2061 ? o.scale * flipX
2062 : isFinite(o.scaleX)
2063 ? o.scaleX * flipX
2064 : flipX;
2065 const scaleY =
2066 o.scale && o.scale.length
2067 ? o.scale[1] * flipY
2068 : isFinite(o.scale)
2069 ? o.scale * flipY
2070 : isFinite(o.scaleY)
2071 ? o.scaleY * flipY
2072 : flipY;
2073 const shear = o.shear || 0;
2074 const theta = o.rotate || o.theta || 0;
2075 const origin = new Point(
2076 o.origin || o.around || o.ox || o.originX,
2077 o.oy || o.originY
2078 );
2079 const ox = origin.x;
2080 const oy = origin.y;
2081 // We need Point to be invalid if nothing was passed because we cannot default to 0 here. That is why NaN
2082 const position = new Point(
2083 o.position || o.px || o.positionX || NaN,
2084 o.py || o.positionY || NaN
2085 );
2086 const px = position.x;
2087 const py = position.y;
2088 const translate = new Point(
2089 o.translate || o.tx || o.translateX,
2090 o.ty || o.translateY
2091 );
2092 const tx = translate.x;
2093 const ty = translate.y;
2094 const relative = new Point(
2095 o.relative || o.rx || o.relativeX,
2096 o.ry || o.relativeY
2097 );
2098 const rx = relative.x;
2099 const ry = relative.y;
2100
2101 // Populate all of the values
2102 return {
2103 scaleX,
2104 scaleY,
2105 skewX,
2106 skewY,
2107 shear,
2108 theta,
2109 rx,
2110 ry,
2111 tx,
2112 ty,
2113 ox,
2114 oy,
2115 px,
2116 py
2117 }
2118 }
2119
2120 static fromArray(a) {
2121 return { a: a[0], b: a[1], c: a[2], d: a[3], e: a[4], f: a[5] }
2122 }
2123
2124 static isMatrixLike(o) {
2125 return (
2126 o.a != null ||
2127 o.b != null ||
2128 o.c != null ||
2129 o.d != null ||
2130 o.e != null ||
2131 o.f != null
2132 )
2133 }
2134
2135 // left matrix, right matrix, target matrix which is overwritten
2136 static matrixMultiply(l, r, o) {
2137 // Work out the product directly
2138 const a = l.a * r.a + l.c * r.b;
2139 const b = l.b * r.a + l.d * r.b;
2140 const c = l.a * r.c + l.c * r.d;
2141 const d = l.b * r.c + l.d * r.d;
2142 const e = l.e + l.a * r.e + l.c * r.f;
2143 const f = l.f + l.b * r.e + l.d * r.f;
2144
2145 // make sure to use local variables because l/r and o could be the same
2146 o.a = a;
2147 o.b = b;
2148 o.c = c;
2149 o.d = d;
2150 o.e = e;
2151 o.f = f;
2152
2153 return o
2154 }
2155
2156 around(cx, cy, matrix) {
2157 return this.clone().aroundO(cx, cy, matrix)
2158 }
2159
2160 // Transform around a center point
2161 aroundO(cx, cy, matrix) {
2162 const dx = cx || 0;
2163 const dy = cy || 0;
2164 return this.translateO(-dx, -dy).lmultiplyO(matrix).translateO(dx, dy)
2165 }
2166
2167 // Clones this matrix
2168 clone() {
2169 return new Matrix(this)
2170 }
2171
2172 // Decomposes this matrix into its affine parameters
2173 decompose(cx = 0, cy = 0) {
2174 // Get the parameters from the matrix
2175 const a = this.a;
2176 const b = this.b;
2177 const c = this.c;
2178 const d = this.d;
2179 const e = this.e;
2180 const f = this.f;
2181
2182 // Figure out if the winding direction is clockwise or counterclockwise
2183 const determinant = a * d - b * c;
2184 const ccw = determinant > 0 ? 1 : -1;
2185
2186 // Since we only shear in x, we can use the x basis to get the x scale
2187 // and the rotation of the resulting matrix
2188 const sx = ccw * Math.sqrt(a * a + b * b);
2189 const thetaRad = Math.atan2(ccw * b, ccw * a);
2190 const theta = (180 / Math.PI) * thetaRad;
2191 const ct = Math.cos(thetaRad);
2192 const st = Math.sin(thetaRad);
2193
2194 // We can then solve the y basis vector simultaneously to get the other
2195 // two affine parameters directly from these parameters
2196 const lam = (a * c + b * d) / determinant;
2197 const sy = (c * sx) / (lam * a - b) || (d * sx) / (lam * b + a);
2198
2199 // Use the translations
2200 const tx = e - cx + cx * ct * sx + cy * (lam * ct * sx - st * sy);
2201 const ty = f - cy + cx * st * sx + cy * (lam * st * sx + ct * sy);
2202
2203 // Construct the decomposition and return it
2204 return {
2205 // Return the affine parameters
2206 scaleX: sx,
2207 scaleY: sy,
2208 shear: lam,
2209 rotate: theta,
2210 translateX: tx,
2211 translateY: ty,
2212 originX: cx,
2213 originY: cy,
2214
2215 // Return the matrix parameters
2216 a: this.a,
2217 b: this.b,
2218 c: this.c,
2219 d: this.d,
2220 e: this.e,
2221 f: this.f
2222 }
2223 }
2224
2225 // Check if two matrices are equal
2226 equals(other) {
2227 if (other === this) return true
2228 const comp = new Matrix(other);
2229 return (
2230 closeEnough(this.a, comp.a) &&
2231 closeEnough(this.b, comp.b) &&
2232 closeEnough(this.c, comp.c) &&
2233 closeEnough(this.d, comp.d) &&
2234 closeEnough(this.e, comp.e) &&
2235 closeEnough(this.f, comp.f)
2236 )
2237 }
2238
2239 // Flip matrix on x or y, at a given offset
2240 flip(axis, around) {
2241 return this.clone().flipO(axis, around)
2242 }
2243
2244 flipO(axis, around) {
2245 return axis === 'x'
2246 ? this.scaleO(-1, 1, around, 0)
2247 : axis === 'y'
2248 ? this.scaleO(1, -1, 0, around)
2249 : this.scaleO(-1, -1, axis, around || axis) // Define an x, y flip point
2250 }
2251
2252 // Initialize
2253 init(source) {
2254 const base = Matrix.fromArray([1, 0, 0, 1, 0, 0]);
2255
2256 // ensure source as object
2257 source =
2258 source instanceof Element$1
2259 ? source.matrixify()
2260 : typeof source === 'string'
2261 ? Matrix.fromArray(source.split(delimiter).map(parseFloat))
2262 : Array.isArray(source)
2263 ? Matrix.fromArray(source)
2264 : typeof source === 'object' && Matrix.isMatrixLike(source)
2265 ? source
2266 : typeof source === 'object'
2267 ? new Matrix().transform(source)
2268 : arguments.length === 6
2269 ? Matrix.fromArray([].slice.call(arguments))
2270 : base;
2271
2272 // Merge the source matrix with the base matrix
2273 this.a = source.a != null ? source.a : base.a;
2274 this.b = source.b != null ? source.b : base.b;
2275 this.c = source.c != null ? source.c : base.c;
2276 this.d = source.d != null ? source.d : base.d;
2277 this.e = source.e != null ? source.e : base.e;
2278 this.f = source.f != null ? source.f : base.f;
2279
2280 return this
2281 }
2282
2283 inverse() {
2284 return this.clone().inverseO()
2285 }
2286
2287 // Inverses matrix
2288 inverseO() {
2289 // Get the current parameters out of the matrix
2290 const a = this.a;
2291 const b = this.b;
2292 const c = this.c;
2293 const d = this.d;
2294 const e = this.e;
2295 const f = this.f;
2296
2297 // Invert the 2x2 matrix in the top left
2298 const det = a * d - b * c;
2299 if (!det) throw new Error('Cannot invert ' + this)
2300
2301 // Calculate the top 2x2 matrix
2302 const na = d / det;
2303 const nb = -b / det;
2304 const nc = -c / det;
2305 const nd = a / det;
2306
2307 // Apply the inverted matrix to the top right
2308 const ne = -(na * e + nc * f);
2309 const nf = -(nb * e + nd * f);
2310
2311 // Construct the inverted matrix
2312 this.a = na;
2313 this.b = nb;
2314 this.c = nc;
2315 this.d = nd;
2316 this.e = ne;
2317 this.f = nf;
2318
2319 return this
2320 }
2321
2322 lmultiply(matrix) {
2323 return this.clone().lmultiplyO(matrix)
2324 }
2325
2326 lmultiplyO(matrix) {
2327 const r = this;
2328 const l = matrix instanceof Matrix ? matrix : new Matrix(matrix);
2329
2330 return Matrix.matrixMultiply(l, r, this)
2331 }
2332
2333 // Left multiplies by the given matrix
2334 multiply(matrix) {
2335 return this.clone().multiplyO(matrix)
2336 }
2337
2338 multiplyO(matrix) {
2339 // Get the matrices
2340 const l = this;
2341 const r = matrix instanceof Matrix ? matrix : new Matrix(matrix);
2342
2343 return Matrix.matrixMultiply(l, r, this)
2344 }
2345
2346 // Rotate matrix
2347 rotate(r, cx, cy) {
2348 return this.clone().rotateO(r, cx, cy)
2349 }
2350
2351 rotateO(r, cx = 0, cy = 0) {
2352 // Convert degrees to radians
2353 r = radians(r);
2354
2355 const cos = Math.cos(r);
2356 const sin = Math.sin(r);
2357
2358 const { a, b, c, d, e, f } = this;
2359
2360 this.a = a * cos - b * sin;
2361 this.b = b * cos + a * sin;
2362 this.c = c * cos - d * sin;
2363 this.d = d * cos + c * sin;
2364 this.e = e * cos - f * sin + cy * sin - cx * cos + cx;
2365 this.f = f * cos + e * sin - cx * sin - cy * cos + cy;
2366
2367 return this
2368 }
2369
2370 // Scale matrix
2371 scale() {
2372 return this.clone().scaleO(...arguments)
2373 }
2374
2375 scaleO(x, y = x, cx = 0, cy = 0) {
2376 // Support uniform scaling
2377 if (arguments.length === 3) {
2378 cy = cx;
2379 cx = y;
2380 y = x;
2381 }
2382
2383 const { a, b, c, d, e, f } = this;
2384
2385 this.a = a * x;
2386 this.b = b * y;
2387 this.c = c * x;
2388 this.d = d * y;
2389 this.e = e * x - cx * x + cx;
2390 this.f = f * y - cy * y + cy;
2391
2392 return this
2393 }
2394
2395 // Shear matrix
2396 shear(a, cx, cy) {
2397 return this.clone().shearO(a, cx, cy)
2398 }
2399
2400 // eslint-disable-next-line no-unused-vars
2401 shearO(lx, cx = 0, cy = 0) {
2402 const { a, b, c, d, e, f } = this;
2403
2404 this.a = a + b * lx;
2405 this.c = c + d * lx;
2406 this.e = e + f * lx - cy * lx;
2407
2408 return this
2409 }
2410
2411 // Skew Matrix
2412 skew() {
2413 return this.clone().skewO(...arguments)
2414 }
2415
2416 skewO(x, y = x, cx = 0, cy = 0) {
2417 // support uniformal skew
2418 if (arguments.length === 3) {
2419 cy = cx;
2420 cx = y;
2421 y = x;
2422 }
2423
2424 // Convert degrees to radians
2425 x = radians(x);
2426 y = radians(y);
2427
2428 const lx = Math.tan(x);
2429 const ly = Math.tan(y);
2430
2431 const { a, b, c, d, e, f } = this;
2432
2433 this.a = a + b * lx;
2434 this.b = b + a * ly;
2435 this.c = c + d * lx;
2436 this.d = d + c * ly;
2437 this.e = e + f * lx - cy * lx;
2438 this.f = f + e * ly - cx * ly;
2439
2440 return this
2441 }
2442
2443 // SkewX
2444 skewX(x, cx, cy) {
2445 return this.skew(x, 0, cx, cy)
2446 }
2447
2448 // SkewY
2449 skewY(y, cx, cy) {
2450 return this.skew(0, y, cx, cy)
2451 }
2452
2453 toArray() {
2454 return [this.a, this.b, this.c, this.d, this.e, this.f]
2455 }
2456
2457 // Convert matrix to string
2458 toString() {
2459 return (
2460 'matrix(' +
2461 this.a +
2462 ',' +
2463 this.b +
2464 ',' +
2465 this.c +
2466 ',' +
2467 this.d +
2468 ',' +
2469 this.e +
2470 ',' +
2471 this.f +
2472 ')'
2473 )
2474 }
2475
2476 // Transform a matrix into another matrix by manipulating the space
2477 transform(o) {
2478 // Check if o is a matrix and then left multiply it directly
2479 if (Matrix.isMatrixLike(o)) {
2480 const matrix = new Matrix(o);
2481 return matrix.multiplyO(this)
2482 }
2483
2484 // Get the proposed transformations and the current transformations
2485 const t = Matrix.formatTransforms(o);
2486 const current = this;
2487 const { x: ox, y: oy } = new Point(t.ox, t.oy).transform(current);
2488
2489 // Construct the resulting matrix
2490 const transformer = new Matrix()
2491 .translateO(t.rx, t.ry)
2492 .lmultiplyO(current)
2493 .translateO(-ox, -oy)
2494 .scaleO(t.scaleX, t.scaleY)
2495 .skewO(t.skewX, t.skewY)
2496 .shearO(t.shear)
2497 .rotateO(t.theta)
2498 .translateO(ox, oy);
2499
2500 // If we want the origin at a particular place, we force it there
2501 if (isFinite(t.px) || isFinite(t.py)) {
2502 const origin = new Point(ox, oy).transform(transformer);
2503 // TODO: Replace t.px with isFinite(t.px)
2504 // Doesn't work because t.px is also 0 if it wasn't passed
2505 const dx = isFinite(t.px) ? t.px - origin.x : 0;
2506 const dy = isFinite(t.py) ? t.py - origin.y : 0;
2507 transformer.translateO(dx, dy);
2508 }
2509
2510 // Translate now after positioning
2511 transformer.translateO(t.tx, t.ty);
2512 return transformer
2513 }
2514
2515 // Translate matrix
2516 translate(x, y) {
2517 return this.clone().translateO(x, y)
2518 }
2519
2520 translateO(x, y) {
2521 this.e += x || 0;
2522 this.f += y || 0;
2523 return this
2524 }
2525
2526 valueOf() {
2527 return {
2528 a: this.a,
2529 b: this.b,
2530 c: this.c,
2531 d: this.d,
2532 e: this.e,
2533 f: this.f
2534 }
2535 }
2536 }
2537
2538 function ctm() {
2539 return new Matrix(this.node.getCTM())
2540 }
2541
2542 function screenCTM() {
2543 try {
2544 /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537
2545 This is needed because FF does not return the transformation matrix
2546 for the inner coordinate system when getScreenCTM() is called on nested svgs.
2547 However all other Browsers do that */
2548 if (typeof this.isRoot === 'function' && !this.isRoot()) {
2549 const rect = this.rect(1, 1);
2550 const m = rect.node.getScreenCTM();
2551 rect.remove();
2552 return new Matrix(m)
2553 }
2554 return new Matrix(this.node.getScreenCTM())
2555 } catch (e) {
2556 console.warn(
2557 `Cannot get CTM from SVG node ${this.node.nodeName}. Is the element rendered?`
2558 );
2559 return new Matrix()
2560 }
2561 }
2562
2563 register(Matrix, 'Matrix');
2564
2565 function parser() {
2566 // Reuse cached element if possible
2567 if (!parser.nodes) {
2568 const svg = makeInstance().size(2, 0);
2569 svg.node.style.cssText = [
2570 'opacity: 0',
2571 'position: absolute',
2572 'left: -100%',
2573 'top: -100%',
2574 'overflow: hidden'
2575 ].join(';');
2576
2577 svg.attr('focusable', 'false');
2578 svg.attr('aria-hidden', 'true');
2579
2580 const path = svg.path().node;
2581
2582 parser.nodes = { svg, path };
2583 }
2584
2585 if (!parser.nodes.svg.node.parentNode) {
2586 const b = globals.document.body || globals.document.documentElement;
2587 parser.nodes.svg.addTo(b);
2588 }
2589
2590 return parser.nodes
2591 }
2592
2593 function isNulledBox(box) {
2594 return !box.width && !box.height && !box.x && !box.y
2595 }
2596
2597 function domContains(node) {
2598 return (
2599 node === globals.document ||
2600 (
2601 globals.document.documentElement.contains ||
2602 function (node) {
2603 // This is IE - it does not support contains() for top-level SVGs
2604 while (node.parentNode) {
2605 node = node.parentNode;
2606 }
2607 return node === globals.document
2608 }
2609 ).call(globals.document.documentElement, node)
2610 )
2611 }
2612
2613 class Box {
2614 constructor(...args) {
2615 this.init(...args);
2616 }
2617
2618 addOffset() {
2619 // offset by window scroll position, because getBoundingClientRect changes when window is scrolled
2620 this.x += globals.window.pageXOffset;
2621 this.y += globals.window.pageYOffset;
2622 return new Box(this)
2623 }
2624
2625 init(source) {
2626 const base = [0, 0, 0, 0];
2627 source =
2628 typeof source === 'string'
2629 ? source.split(delimiter).map(parseFloat)
2630 : Array.isArray(source)
2631 ? source
2632 : typeof source === 'object'
2633 ? [
2634 source.left != null ? source.left : source.x,
2635 source.top != null ? source.top : source.y,
2636 source.width,
2637 source.height
2638 ]
2639 : arguments.length === 4
2640 ? [].slice.call(arguments)
2641 : base;
2642
2643 this.x = source[0] || 0;
2644 this.y = source[1] || 0;
2645 this.width = this.w = source[2] || 0;
2646 this.height = this.h = source[3] || 0;
2647
2648 // Add more bounding box properties
2649 this.x2 = this.x + this.w;
2650 this.y2 = this.y + this.h;
2651 this.cx = this.x + this.w / 2;
2652 this.cy = this.y + this.h / 2;
2653
2654 return this
2655 }
2656
2657 isNulled() {
2658 return isNulledBox(this)
2659 }
2660
2661 // Merge rect box with another, return a new instance
2662 merge(box) {
2663 const x = Math.min(this.x, box.x);
2664 const y = Math.min(this.y, box.y);
2665 const width = Math.max(this.x + this.width, box.x + box.width) - x;
2666 const height = Math.max(this.y + this.height, box.y + box.height) - y;
2667
2668 return new Box(x, y, width, height)
2669 }
2670
2671 toArray() {
2672 return [this.x, this.y, this.width, this.height]
2673 }
2674
2675 toString() {
2676 return this.x + ' ' + this.y + ' ' + this.width + ' ' + this.height
2677 }
2678
2679 transform(m) {
2680 if (!(m instanceof Matrix)) {
2681 m = new Matrix(m);
2682 }
2683
2684 let xMin = Infinity;
2685 let xMax = -Infinity;
2686 let yMin = Infinity;
2687 let yMax = -Infinity;
2688
2689 const pts = [
2690 new Point(this.x, this.y),
2691 new Point(this.x2, this.y),
2692 new Point(this.x, this.y2),
2693 new Point(this.x2, this.y2)
2694 ];
2695
2696 pts.forEach(function (p) {
2697 p = p.transform(m);
2698 xMin = Math.min(xMin, p.x);
2699 xMax = Math.max(xMax, p.x);
2700 yMin = Math.min(yMin, p.y);
2701 yMax = Math.max(yMax, p.y);
2702 });
2703
2704 return new Box(xMin, yMin, xMax - xMin, yMax - yMin)
2705 }
2706 }
2707
2708 function getBox(el, getBBoxFn, retry) {
2709 let box;
2710
2711 try {
2712 // Try to get the box with the provided function
2713 box = getBBoxFn(el.node);
2714
2715 // If the box is worthless and not even in the dom, retry
2716 // by throwing an error here...
2717 if (isNulledBox(box) && !domContains(el.node)) {
2718 throw new Error('Element not in the dom')
2719 }
2720 } catch (e) {
2721 // ... and calling the retry handler here
2722 box = retry(el);
2723 }
2724
2725 return box
2726 }
2727
2728 function bbox() {
2729 // Function to get bbox is getBBox()
2730 const getBBox = (node) => node.getBBox();
2731
2732 // Take all measures so that a stupid browser renders the element
2733 // so we can get the bbox from it when we try again
2734 const retry = (el) => {
2735 try {
2736 const clone = el.clone().addTo(parser().svg).show();
2737 const box = clone.node.getBBox();
2738 clone.remove();
2739 return box
2740 } catch (e) {
2741 // We give up...
2742 throw new Error(
2743 `Getting bbox of element "${
2744 el.node.nodeName
2745 }" is not possible: ${e.toString()}`
2746 )
2747 }
2748 };
2749
2750 const box = getBox(this, getBBox, retry);
2751 const bbox = new Box(box);
2752
2753 return bbox
2754 }
2755
2756 function rbox(el) {
2757 const getRBox = (node) => node.getBoundingClientRect();
2758 const retry = (el) => {
2759 // There is no point in trying tricks here because if we insert the element into the dom ourselves
2760 // it obviously will be at the wrong position
2761 throw new Error(
2762 `Getting rbox of element "${el.node.nodeName}" is not possible`
2763 )
2764 };
2765
2766 const box = getBox(this, getRBox, retry);
2767 const rbox = new Box(box);
2768
2769 // If an element was passed, we want the bbox in the coordinate system of that element
2770 if (el) {
2771 return rbox.transform(el.screenCTM().inverseO())
2772 }
2773
2774 // Else we want it in absolute screen coordinates
2775 // Therefore we need to add the scrollOffset
2776 return rbox.addOffset()
2777 }
2778
2779 // Checks whether the given point is inside the bounding box
2780 function inside(x, y) {
2781 const box = this.bbox();
2782
2783 return (
2784 x > box.x && y > box.y && x < box.x + box.width && y < box.y + box.height
2785 )
2786 }
2787
2788 registerMethods({
2789 viewbox: {
2790 viewbox(x, y, width, height) {
2791 // act as getter
2792 if (x == null) return new Box(this.attr('viewBox'))
2793
2794 // act as setter
2795 return this.attr('viewBox', new Box(x, y, width, height))
2796 },
2797
2798 zoom(level, point) {
2799 // Its best to rely on the attributes here and here is why:
2800 // clientXYZ: Doesn't work on non-root svgs because they dont have a CSSBox (silly!)
2801 // getBoundingClientRect: Doesn't work because Chrome just ignores width and height of nested svgs completely
2802 // that means, their clientRect is always as big as the content.
2803 // Furthermore this size is incorrect if the element is further transformed by its parents
2804 // computedStyle: Only returns meaningful values if css was used with px. We dont go this route here!
2805 // getBBox: returns the bounding box of its content - that doesn't help!
2806 let { width, height } = this.attr(['width', 'height']);
2807
2808 // Width and height is a string when a number with a unit is present which we can't use
2809 // So we try clientXYZ
2810 if (
2811 (!width && !height) ||
2812 typeof width === 'string' ||
2813 typeof height === 'string'
2814 ) {
2815 width = this.node.clientWidth;
2816 height = this.node.clientHeight;
2817 }
2818
2819 // Giving up...
2820 if (!width || !height) {
2821 throw new Error(
2822 'Impossible to get absolute width and height. Please provide an absolute width and height attribute on the zooming element'
2823 )
2824 }
2825
2826 const v = this.viewbox();
2827
2828 const zoomX = width / v.width;
2829 const zoomY = height / v.height;
2830 const zoom = Math.min(zoomX, zoomY);
2831
2832 if (level == null) {
2833 return zoom
2834 }
2835
2836 let zoomAmount = zoom / level;
2837
2838 // Set the zoomAmount to the highest value which is safe to process and recover from
2839 // The * 100 is a bit of wiggle room for the matrix transformation
2840 if (zoomAmount === Infinity) zoomAmount = Number.MAX_SAFE_INTEGER / 100;
2841
2842 point =
2843 point || new Point(width / 2 / zoomX + v.x, height / 2 / zoomY + v.y);
2844
2845 const box = new Box(v).transform(
2846 new Matrix({ scale: zoomAmount, origin: point })
2847 );
2848
2849 return this.viewbox(box)
2850 }
2851 }
2852 });
2853
2854 register(Box, 'Box');
2855
2856 // import { subClassArray } from './ArrayPolyfill.js'
2857
2858 class List extends Array {
2859 constructor(arr = [], ...args) {
2860 super(arr, ...args);
2861 if (typeof arr === 'number') return this
2862 this.length = 0;
2863 this.push(...arr);
2864 }
2865 }
2866
2867 extend([List], {
2868 each(fnOrMethodName, ...args) {
2869 if (typeof fnOrMethodName === 'function') {
2870 return this.map((el, i, arr) => {
2871 return fnOrMethodName.call(el, el, i, arr)
2872 })
2873 } else {
2874 return this.map((el) => {
2875 return el[fnOrMethodName](...args)
2876 })
2877 }
2878 },
2879
2880 toArray() {
2881 return Array.prototype.concat.apply([], this)
2882 }
2883 });
2884
2885 const reserved = ['toArray', 'constructor', 'each'];
2886
2887 List.extend = function (methods) {
2888 methods = methods.reduce((obj, name) => {
2889 // Don't overwrite own methods
2890 if (reserved.includes(name)) return obj
2891
2892 // Don't add private methods
2893 if (name[0] === '_') return obj
2894
2895 // Allow access to original Array methods through a prefix
2896 if (name in Array.prototype) {
2897 obj['$' + name] = Array.prototype[name];
2898 }
2899
2900 // Relay every call to each()
2901 obj[name] = function (...attrs) {
2902 return this.each(name, ...attrs)
2903 };
2904 return obj
2905 }, {});
2906
2907 extend([List], methods);
2908 };
2909
2910 function baseFind(query, parent) {
2911 return new List(
2912 map((parent || globals.document).querySelectorAll(query), function (node) {
2913 return adopt(node)
2914 })
2915 )
2916 }
2917
2918 // Scoped find method
2919 function find(query) {
2920 return baseFind(query, this.node)
2921 }
2922
2923 function findOne(query) {
2924 return adopt(this.node.querySelector(query))
2925 }
2926
2927 let listenerId = 0;
2928 const windowEvents = {};
2929
2930 function getEvents(instance) {
2931 let n = instance.getEventHolder();
2932
2933 // We dont want to save events in global space
2934 if (n === globals.window) n = windowEvents;
2935 if (!n.events) n.events = {};
2936 return n.events
2937 }
2938
2939 function getEventTarget(instance) {
2940 return instance.getEventTarget()
2941 }
2942
2943 function clearEvents(instance) {
2944 let n = instance.getEventHolder();
2945 if (n === globals.window) n = windowEvents;
2946 if (n.events) n.events = {};
2947 }
2948
2949 // Add event binder in the SVG namespace
2950 function on(node, events, listener, binding, options) {
2951 const l = listener.bind(binding || node);
2952 const instance = makeInstance(node);
2953 const bag = getEvents(instance);
2954 const n = getEventTarget(instance);
2955
2956 // events can be an array of events or a string of events
2957 events = Array.isArray(events) ? events : events.split(delimiter);
2958
2959 // add id to listener
2960 if (!listener._svgjsListenerId) {
2961 listener._svgjsListenerId = ++listenerId;
2962 }
2963
2964 events.forEach(function (event) {
2965 const ev = event.split('.')[0];
2966 const ns = event.split('.')[1] || '*';
2967
2968 // ensure valid object
2969 bag[ev] = bag[ev] || {};
2970 bag[ev][ns] = bag[ev][ns] || {};
2971
2972 // reference listener
2973 bag[ev][ns][listener._svgjsListenerId] = l;
2974
2975 // add listener
2976 n.addEventListener(ev, l, options || false);
2977 });
2978 }
2979
2980 // Add event unbinder in the SVG namespace
2981 function off(node, events, listener, options) {
2982 const instance = makeInstance(node);
2983 const bag = getEvents(instance);
2984 const n = getEventTarget(instance);
2985
2986 // listener can be a function or a number
2987 if (typeof listener === 'function') {
2988 listener = listener._svgjsListenerId;
2989 if (!listener) return
2990 }
2991
2992 // events can be an array of events or a string or undefined
2993 events = Array.isArray(events) ? events : (events || '').split(delimiter);
2994
2995 events.forEach(function (event) {
2996 const ev = event && event.split('.')[0];
2997 const ns = event && event.split('.')[1];
2998 let namespace, l;
2999
3000 if (listener) {
3001 // remove listener reference
3002 if (bag[ev] && bag[ev][ns || '*']) {
3003 // removeListener
3004 n.removeEventListener(
3005 ev,
3006 bag[ev][ns || '*'][listener],
3007 options || false
3008 );
3009
3010 delete bag[ev][ns || '*'][listener];
3011 }
3012 } else if (ev && ns) {
3013 // remove all listeners for a namespaced event
3014 if (bag[ev] && bag[ev][ns]) {
3015 for (l in bag[ev][ns]) {
3016 off(n, [ev, ns].join('.'), l);
3017 }
3018
3019 delete bag[ev][ns];
3020 }
3021 } else if (ns) {
3022 // remove all listeners for a specific namespace
3023 for (event in bag) {
3024 for (namespace in bag[event]) {
3025 if (ns === namespace) {
3026 off(n, [event, ns].join('.'));
3027 }
3028 }
3029 }
3030 } else if (ev) {
3031 // remove all listeners for the event
3032 if (bag[ev]) {
3033 for (namespace in bag[ev]) {
3034 off(n, [ev, namespace].join('.'));
3035 }
3036
3037 delete bag[ev];
3038 }
3039 } else {
3040 // remove all listeners on a given node
3041 for (event in bag) {
3042 off(n, event);
3043 }
3044
3045 clearEvents(instance);
3046 }
3047 });
3048 }
3049
3050 function dispatch(node, event, data, options) {
3051 const n = getEventTarget(node);
3052
3053 // Dispatch event
3054 if (event instanceof globals.window.Event) {
3055 n.dispatchEvent(event);
3056 } else {
3057 event = new globals.window.CustomEvent(event, {
3058 detail: data,
3059 cancelable: true,
3060 ...options
3061 });
3062 n.dispatchEvent(event);
3063 }
3064 return event
3065 }
3066
3067 class EventTarget extends Base$1 {
3068 addEventListener() {}
3069
3070 dispatch(event, data, options) {
3071 return dispatch(this, event, data, options)
3072 }
3073
3074 dispatchEvent(event) {
3075 const bag = this.getEventHolder().events;
3076 if (!bag) return true
3077
3078 const events = bag[event.type];
3079
3080 for (const i in events) {
3081 for (const j in events[i]) {
3082 events[i][j](event);
3083 }
3084 }
3085
3086 return !event.defaultPrevented
3087 }
3088
3089 // Fire given event
3090 fire(event, data, options) {
3091 this.dispatch(event, data, options);
3092 return this
3093 }
3094
3095 getEventHolder() {
3096 return this
3097 }
3098
3099 getEventTarget() {
3100 return this
3101 }
3102
3103 // Unbind event from listener
3104 off(event, listener, options) {
3105 off(this, event, listener, options);
3106 return this
3107 }
3108
3109 // Bind given event to listener
3110 on(event, listener, binding, options) {
3111 on(this, event, listener, binding, options);
3112 return this
3113 }
3114
3115 removeEventListener() {}
3116 }
3117
3118 register(EventTarget, 'EventTarget');
3119
3120 function noop() {}
3121
3122 // Default animation values
3123 const timeline = {
3124 duration: 400,
3125 ease: '>',
3126 delay: 0
3127 };
3128
3129 // Default attribute values
3130 const attrs = {
3131 // fill and stroke
3132 'fill-opacity': 1,
3133 'stroke-opacity': 1,
3134 'stroke-width': 0,
3135 'stroke-linejoin': 'miter',
3136 'stroke-linecap': 'butt',
3137 fill: '#000000',
3138 stroke: '#000000',
3139 opacity: 1,
3140
3141 // position
3142 x: 0,
3143 y: 0,
3144 cx: 0,
3145 cy: 0,
3146
3147 // size
3148 width: 0,
3149 height: 0,
3150
3151 // radius
3152 r: 0,
3153 rx: 0,
3154 ry: 0,
3155
3156 // gradient
3157 offset: 0,
3158 'stop-opacity': 1,
3159 'stop-color': '#000000',
3160
3161 // text
3162 'text-anchor': 'start'
3163 };
3164
3165 class SVGArray extends Array {
3166 constructor(...args) {
3167 super(...args);
3168 this.init(...args);
3169 }
3170
3171 clone() {
3172 return new this.constructor(this)
3173 }
3174
3175 init(arr) {
3176 // This catches the case, that native map tries to create an array with new Array(1)
3177 if (typeof arr === 'number') return this
3178 this.length = 0;
3179 this.push(...this.parse(arr));
3180 return this
3181 }
3182
3183 // Parse whitespace separated string
3184 parse(array = []) {
3185 // If already is an array, no need to parse it
3186 if (array instanceof Array) return array
3187
3188 return array.trim().split(delimiter).map(parseFloat)
3189 }
3190
3191 toArray() {
3192 return Array.prototype.concat.apply([], this)
3193 }
3194
3195 toSet() {
3196 return new Set(this)
3197 }
3198
3199 toString() {
3200 return this.join(' ')
3201 }
3202
3203 // Flattens the array if needed
3204 valueOf() {
3205 const ret = [];
3206 ret.push(...this);
3207 return ret
3208 }
3209 }
3210
3211 // Module for unit conversions
3212 class SVGNumber {
3213 // Initialize
3214 constructor(...args) {
3215 this.init(...args);
3216 }
3217
3218 convert(unit) {
3219 return new SVGNumber(this.value, unit)
3220 }
3221
3222 // Divide number
3223 divide(number) {
3224 number = new SVGNumber(number);
3225 return new SVGNumber(this / number, this.unit || number.unit)
3226 }
3227
3228 init(value, unit) {
3229 unit = Array.isArray(value) ? value[1] : unit;
3230 value = Array.isArray(value) ? value[0] : value;
3231
3232 // initialize defaults
3233 this.value = 0;
3234 this.unit = unit || '';
3235
3236 // parse value
3237 if (typeof value === 'number') {
3238 // ensure a valid numeric value
3239 this.value = isNaN(value)
3240 ? 0
3241 : !isFinite(value)
3242 ? value < 0
3243 ? -3.4e38
3244 : +3.4e38
3245 : value;
3246 } else if (typeof value === 'string') {
3247 unit = value.match(numberAndUnit);
3248
3249 if (unit) {
3250 // make value numeric
3251 this.value = parseFloat(unit[1]);
3252
3253 // normalize
3254 if (unit[5] === '%') {
3255 this.value /= 100;
3256 } else if (unit[5] === 's') {
3257 this.value *= 1000;
3258 }
3259
3260 // store unit
3261 this.unit = unit[5];
3262 }
3263 } else {
3264 if (value instanceof SVGNumber) {
3265 this.value = value.valueOf();
3266 this.unit = value.unit;
3267 }
3268 }
3269
3270 return this
3271 }
3272
3273 // Subtract number
3274 minus(number) {
3275 number = new SVGNumber(number);
3276 return new SVGNumber(this - number, this.unit || number.unit)
3277 }
3278
3279 // Add number
3280 plus(number) {
3281 number = new SVGNumber(number);
3282 return new SVGNumber(this + number, this.unit || number.unit)
3283 }
3284
3285 // Multiply number
3286 times(number) {
3287 number = new SVGNumber(number);
3288 return new SVGNumber(this * number, this.unit || number.unit)
3289 }
3290
3291 toArray() {
3292 return [this.value, this.unit]
3293 }
3294
3295 toJSON() {
3296 return this.toString()
3297 }
3298
3299 toString() {
3300 return (
3301 (this.unit === '%'
3302 ? ~~(this.value * 1e8) / 1e6
3303 : this.unit === 's'
3304 ? this.value / 1e3
3305 : this.value) + this.unit
3306 )
3307 }
3308
3309 valueOf() {
3310 return this.value
3311 }
3312 }
3313
3314 const colorAttributes = new Set([
3315 'fill',
3316 'stroke',
3317 'color',
3318 'bgcolor',
3319 'stop-color',
3320 'flood-color',
3321 'lighting-color'
3322 ]);
3323
3324 const hooks = [];
3325 function registerAttrHook(fn) {
3326 hooks.push(fn);
3327 }
3328
3329 // Set svg element attribute
3330 function attr(attr, val, ns) {
3331 // act as full getter
3332 if (attr == null) {
3333 // get an object of attributes
3334 attr = {};
3335 val = this.node.attributes;
3336
3337 for (const node of val) {
3338 attr[node.nodeName] = isNumber.test(node.nodeValue)
3339 ? parseFloat(node.nodeValue)
3340 : node.nodeValue;
3341 }
3342
3343 return attr
3344 } else if (attr instanceof Array) {
3345 // loop through array and get all values
3346 return attr.reduce((last, curr) => {
3347 last[curr] = this.attr(curr);
3348 return last
3349 }, {})
3350 } else if (typeof attr === 'object' && attr.constructor === Object) {
3351 // apply every attribute individually if an object is passed
3352 for (val in attr) this.attr(val, attr[val]);
3353 } else if (val === null) {
3354 // remove value
3355 this.node.removeAttribute(attr);
3356 } else if (val == null) {
3357 // act as a getter if the first and only argument is not an object
3358 val = this.node.getAttribute(attr);
3359 return val == null
3360 ? attrs[attr]
3361 : isNumber.test(val)
3362 ? parseFloat(val)
3363 : val
3364 } else {
3365 // Loop through hooks and execute them to convert value
3366 val = hooks.reduce((_val, hook) => {
3367 return hook(attr, _val, this)
3368 }, val);
3369
3370 // ensure correct numeric values (also accepts NaN and Infinity)
3371 if (typeof val === 'number') {
3372 val = new SVGNumber(val);
3373 } else if (colorAttributes.has(attr) && Color.isColor(val)) {
3374 // ensure full hex color
3375 val = new Color(val);
3376 } else if (val.constructor === Array) {
3377 // Check for plain arrays and parse array values
3378 val = new SVGArray(val);
3379 }
3380
3381 // if the passed attribute is leading...
3382 if (attr === 'leading') {
3383 // ... call the leading method instead
3384 if (this.leading) {
3385 this.leading(val);
3386 }
3387 } else {
3388 // set given attribute on node
3389 typeof ns === 'string'
3390 ? this.node.setAttributeNS(ns, attr, val.toString())
3391 : this.node.setAttribute(attr, val.toString());
3392 }
3393
3394 // rebuild if required
3395 if (this.rebuild && (attr === 'font-size' || attr === 'x')) {
3396 this.rebuild();
3397 }
3398 }
3399
3400 return this
3401 }
3402
3403 class Dom extends EventTarget {
3404 constructor(node, attrs) {
3405 super();
3406 this.node = node;
3407 this.type = node.nodeName;
3408
3409 if (attrs && node !== attrs) {
3410 this.attr(attrs);
3411 }
3412 }
3413
3414 // Add given element at a position
3415 add(element, i) {
3416 element = makeInstance(element);
3417
3418 // If non-root svg nodes are added we have to remove their namespaces
3419 if (
3420 element.removeNamespace &&
3421 this.node instanceof globals.window.SVGElement
3422 ) {
3423 element.removeNamespace();
3424 }
3425
3426 if (i == null) {
3427 this.node.appendChild(element.node);
3428 } else if (element.node !== this.node.childNodes[i]) {
3429 this.node.insertBefore(element.node, this.node.childNodes[i]);
3430 }
3431
3432 return this
3433 }
3434
3435 // Add element to given container and return self
3436 addTo(parent, i) {
3437 return makeInstance(parent).put(this, i)
3438 }
3439
3440 // Returns all child elements
3441 children() {
3442 return new List(
3443 map(this.node.children, function (node) {
3444 return adopt(node)
3445 })
3446 )
3447 }
3448
3449 // Remove all elements in this container
3450 clear() {
3451 // remove children
3452 while (this.node.hasChildNodes()) {
3453 this.node.removeChild(this.node.lastChild);
3454 }
3455
3456 return this
3457 }
3458
3459 // Clone element
3460 clone(deep = true, assignNewIds = true) {
3461 // write dom data to the dom so the clone can pickup the data
3462 this.writeDataToDom();
3463
3464 // clone element
3465 let nodeClone = this.node.cloneNode(deep);
3466 if (assignNewIds) {
3467 // assign new id
3468 nodeClone = assignNewId(nodeClone);
3469 }
3470 return new this.constructor(nodeClone)
3471 }
3472
3473 // Iterates over all children and invokes a given block
3474 each(block, deep) {
3475 const children = this.children();
3476 let i, il;
3477
3478 for (i = 0, il = children.length; i < il; i++) {
3479 block.apply(children[i], [i, children]);
3480
3481 if (deep) {
3482 children[i].each(block, deep);
3483 }
3484 }
3485
3486 return this
3487 }
3488
3489 element(nodeName, attrs) {
3490 return this.put(new Dom(create(nodeName), attrs))
3491 }
3492
3493 // Get first child
3494 first() {
3495 return adopt(this.node.firstChild)
3496 }
3497
3498 // Get a element at the given index
3499 get(i) {
3500 return adopt(this.node.childNodes[i])
3501 }
3502
3503 getEventHolder() {
3504 return this.node
3505 }
3506
3507 getEventTarget() {
3508 return this.node
3509 }
3510
3511 // Checks if the given element is a child
3512 has(element) {
3513 return this.index(element) >= 0
3514 }
3515
3516 html(htmlOrFn, outerHTML) {
3517 return this.xml(htmlOrFn, outerHTML, html)
3518 }
3519
3520 // Get / set id
3521 id(id) {
3522 // generate new id if no id set
3523 if (typeof id === 'undefined' && !this.node.id) {
3524 this.node.id = eid(this.type);
3525 }
3526
3527 // don't set directly with this.node.id to make `null` work correctly
3528 return this.attr('id', id)
3529 }
3530
3531 // Gets index of given element
3532 index(element) {
3533 return [].slice.call(this.node.childNodes).indexOf(element.node)
3534 }
3535
3536 // Get the last child
3537 last() {
3538 return adopt(this.node.lastChild)
3539 }
3540
3541 // matches the element vs a css selector
3542 matches(selector) {
3543 const el = this.node;
3544 const matcher =
3545 el.matches ||
3546 el.matchesSelector ||
3547 el.msMatchesSelector ||
3548 el.mozMatchesSelector ||
3549 el.webkitMatchesSelector ||
3550 el.oMatchesSelector ||
3551 null;
3552 return matcher && matcher.call(el, selector)
3553 }
3554
3555 // Returns the parent element instance
3556 parent(type) {
3557 let parent = this;
3558
3559 // check for parent
3560 if (!parent.node.parentNode) return null
3561
3562 // get parent element
3563 parent = adopt(parent.node.parentNode);
3564
3565 if (!type) return parent
3566
3567 // loop through ancestors if type is given
3568 do {
3569 if (
3570 typeof type === 'string' ? parent.matches(type) : parent instanceof type
3571 )
3572 return parent
3573 } while ((parent = adopt(parent.node.parentNode)))
3574
3575 return parent
3576 }
3577
3578 // Basically does the same as `add()` but returns the added element instead
3579 put(element, i) {
3580 element = makeInstance(element);
3581 this.add(element, i);
3582 return element
3583 }
3584
3585 // Add element to given container and return container
3586 putIn(parent, i) {
3587 return makeInstance(parent).add(this, i)
3588 }
3589
3590 // Remove element
3591 remove() {
3592 if (this.parent()) {
3593 this.parent().removeElement(this);
3594 }
3595
3596 return this
3597 }
3598
3599 // Remove a given child
3600 removeElement(element) {
3601 this.node.removeChild(element.node);
3602
3603 return this
3604 }
3605
3606 // Replace this with element
3607 replace(element) {
3608 element = makeInstance(element);
3609
3610 if (this.node.parentNode) {
3611 this.node.parentNode.replaceChild(element.node, this.node);
3612 }
3613
3614 return element
3615 }
3616
3617 round(precision = 2, map = null) {
3618 const factor = 10 ** precision;
3619 const attrs = this.attr(map);
3620
3621 for (const i in attrs) {
3622 if (typeof attrs[i] === 'number') {
3623 attrs[i] = Math.round(attrs[i] * factor) / factor;
3624 }
3625 }
3626
3627 this.attr(attrs);
3628 return this
3629 }
3630
3631 // Import / Export raw svg
3632 svg(svgOrFn, outerSVG) {
3633 return this.xml(svgOrFn, outerSVG, svg)
3634 }
3635
3636 // Return id on string conversion
3637 toString() {
3638 return this.id()
3639 }
3640
3641 words(text) {
3642 // This is faster than removing all children and adding a new one
3643 this.node.textContent = text;
3644 return this
3645 }
3646
3647 wrap(node) {
3648 const parent = this.parent();
3649
3650 if (!parent) {
3651 return this.addTo(node)
3652 }
3653
3654 const position = parent.index(this);
3655 return parent.put(node, position).put(this)
3656 }
3657
3658 // write svgjs data to the dom
3659 writeDataToDom() {
3660 // dump variables recursively
3661 this.each(function () {
3662 this.writeDataToDom();
3663 });
3664
3665 return this
3666 }
3667
3668 // Import / Export raw svg
3669 xml(xmlOrFn, outerXML, ns) {
3670 if (typeof xmlOrFn === 'boolean') {
3671 ns = outerXML;
3672 outerXML = xmlOrFn;
3673 xmlOrFn = null;
3674 }
3675
3676 // act as getter if no svg string is given
3677 if (xmlOrFn == null || typeof xmlOrFn === 'function') {
3678 // The default for exports is, that the outerNode is included
3679 outerXML = outerXML == null ? true : outerXML;
3680
3681 // write svgjs data to the dom
3682 this.writeDataToDom();
3683 let current = this;
3684
3685 // An export modifier was passed
3686 if (xmlOrFn != null) {
3687 current = adopt(current.node.cloneNode(true));
3688
3689 // If the user wants outerHTML we need to process this node, too
3690 if (outerXML) {
3691 const result = xmlOrFn(current);
3692 current = result || current;
3693
3694 // The user does not want this node? Well, then he gets nothing
3695 if (result === false) return ''
3696 }
3697
3698 // Deep loop through all children and apply modifier
3699 current.each(function () {
3700 const result = xmlOrFn(this);
3701 const _this = result || this;
3702
3703 // If modifier returns false, discard node
3704 if (result === false) {
3705 this.remove();
3706
3707 // If modifier returns new node, use it
3708 } else if (result && this !== _this) {
3709 this.replace(_this);
3710 }
3711 }, true);
3712 }
3713
3714 // Return outer or inner content
3715 return outerXML ? current.node.outerHTML : current.node.innerHTML
3716 }
3717
3718 // Act as setter if we got a string
3719
3720 // The default for import is, that the current node is not replaced
3721 outerXML = outerXML == null ? false : outerXML;
3722
3723 // Create temporary holder
3724 const well = create('wrapper', ns);
3725 const fragment = globals.document.createDocumentFragment();
3726
3727 // Dump raw svg
3728 well.innerHTML = xmlOrFn;
3729
3730 // Transplant nodes into the fragment
3731 for (let len = well.children.length; len--; ) {
3732 fragment.appendChild(well.firstElementChild);
3733 }
3734
3735 const parent = this.parent();
3736
3737 // Add the whole fragment at once
3738 return outerXML ? this.replace(fragment) && parent : this.add(fragment)
3739 }
3740 }
3741
3742 extend(Dom, { attr, find, findOne });
3743 register(Dom, 'Dom');
3744
3745 let Element$1 = class Element extends Dom {
3746 constructor(node, attrs) {
3747 super(node, attrs);
3748
3749 // initialize data object
3750 this.dom = {};
3751
3752 // create circular reference
3753 this.node.instance = this;
3754
3755 if (node.hasAttribute('data-svgjs') || node.hasAttribute('svgjs:data')) {
3756 // pull svgjs data from the dom (getAttributeNS doesn't work in html5)
3757 this.setData(
3758 JSON.parse(node.getAttribute('data-svgjs')) ??
3759 JSON.parse(node.getAttribute('svgjs:data')) ??
3760 {}
3761 );
3762 }
3763 }
3764
3765 // Move element by its center
3766 center(x, y) {
3767 return this.cx(x).cy(y)
3768 }
3769
3770 // Move by center over x-axis
3771 cx(x) {
3772 return x == null
3773 ? this.x() + this.width() / 2
3774 : this.x(x - this.width() / 2)
3775 }
3776
3777 // Move by center over y-axis
3778 cy(y) {
3779 return y == null
3780 ? this.y() + this.height() / 2
3781 : this.y(y - this.height() / 2)
3782 }
3783
3784 // Get defs
3785 defs() {
3786 const root = this.root();
3787 return root && root.defs()
3788 }
3789
3790 // Relative move over x and y axes
3791 dmove(x, y) {
3792 return this.dx(x).dy(y)
3793 }
3794
3795 // Relative move over x axis
3796 dx(x = 0) {
3797 return this.x(new SVGNumber(x).plus(this.x()))
3798 }
3799
3800 // Relative move over y axis
3801 dy(y = 0) {
3802 return this.y(new SVGNumber(y).plus(this.y()))
3803 }
3804
3805 getEventHolder() {
3806 return this
3807 }
3808
3809 // Set height of element
3810 height(height) {
3811 return this.attr('height', height)
3812 }
3813
3814 // Move element to given x and y values
3815 move(x, y) {
3816 return this.x(x).y(y)
3817 }
3818
3819 // return array of all ancestors of given type up to the root svg
3820 parents(until = this.root()) {
3821 const isSelector = typeof until === 'string';
3822 if (!isSelector) {
3823 until = makeInstance(until);
3824 }
3825 const parents = new List();
3826 let parent = this;
3827
3828 while (
3829 (parent = parent.parent()) &&
3830 parent.node !== globals.document &&
3831 parent.nodeName !== '#document-fragment'
3832 ) {
3833 parents.push(parent);
3834
3835 if (!isSelector && parent.node === until.node) {
3836 break
3837 }
3838 if (isSelector && parent.matches(until)) {
3839 break
3840 }
3841 if (parent.node === this.root().node) {
3842 // We worked our way to the root and didn't match `until`
3843 return null
3844 }
3845 }
3846
3847 return parents
3848 }
3849
3850 // Get referenced element form attribute value
3851 reference(attr) {
3852 attr = this.attr(attr);
3853 if (!attr) return null
3854
3855 const m = (attr + '').match(reference);
3856 return m ? makeInstance(m[1]) : null
3857 }
3858
3859 // Get parent document
3860 root() {
3861 const p = this.parent(getClass(root));
3862 return p && p.root()
3863 }
3864
3865 // set given data to the elements data property
3866 setData(o) {
3867 this.dom = o;
3868 return this
3869 }
3870
3871 // Set element size to given width and height
3872 size(width, height) {
3873 const p = proportionalSize(this, width, height);
3874
3875 return this.width(new SVGNumber(p.width)).height(new SVGNumber(p.height))
3876 }
3877
3878 // Set width of element
3879 width(width) {
3880 return this.attr('width', width)
3881 }
3882
3883 // write svgjs data to the dom
3884 writeDataToDom() {
3885 writeDataToDom(this, this.dom);
3886 return super.writeDataToDom()
3887 }
3888
3889 // Move over x-axis
3890 x(x) {
3891 return this.attr('x', x)
3892 }
3893
3894 // Move over y-axis
3895 y(y) {
3896 return this.attr('y', y)
3897 }
3898 };
3899
3900 extend(Element$1, {
3901 bbox,
3902 rbox,
3903 inside,
3904 point,
3905 ctm,
3906 screenCTM
3907 });
3908
3909 register(Element$1, 'Element');
3910
3911 // Define list of available attributes for stroke and fill
3912 const sugar = {
3913 stroke: [
3914 'color',
3915 'width',
3916 'opacity',
3917 'linecap',
3918 'linejoin',
3919 'miterlimit',
3920 'dasharray',
3921 'dashoffset'
3922 ],
3923 fill: ['color', 'opacity', 'rule'],
3924 prefix: function (t, a) {
3925 return a === 'color' ? t : t + '-' + a
3926 }
3927 }
3928
3929 // Add sugar for fill and stroke
3930 ;['fill', 'stroke'].forEach(function (m) {
3931 const extension = {};
3932 let i;
3933
3934 extension[m] = function (o) {
3935 if (typeof o === 'undefined') {
3936 return this.attr(m)
3937 }
3938 if (
3939 typeof o === 'string' ||
3940 o instanceof Color ||
3941 Color.isRgb(o) ||
3942 o instanceof Element$1
3943 ) {
3944 this.attr(m, o);
3945 } else {
3946 // set all attributes from sugar.fill and sugar.stroke list
3947 for (i = sugar[m].length - 1; i >= 0; i--) {
3948 if (o[sugar[m][i]] != null) {
3949 this.attr(sugar.prefix(m, sugar[m][i]), o[sugar[m][i]]);
3950 }
3951 }
3952 }
3953
3954 return this
3955 };
3956
3957 registerMethods(['Element', 'Runner'], extension);
3958 });
3959
3960 registerMethods(['Element', 'Runner'], {
3961 // Let the user set the matrix directly
3962 matrix: function (mat, b, c, d, e, f) {
3963 // Act as a getter
3964 if (mat == null) {
3965 return new Matrix(this)
3966 }
3967
3968 // Act as a setter, the user can pass a matrix or a set of numbers
3969 return this.attr('transform', new Matrix(mat, b, c, d, e, f))
3970 },
3971
3972 // Map rotation to transform
3973 rotate: function (angle, cx, cy) {
3974 return this.transform({ rotate: angle, ox: cx, oy: cy }, true)
3975 },
3976
3977 // Map skew to transform
3978 skew: function (x, y, cx, cy) {
3979 return arguments.length === 1 || arguments.length === 3
3980 ? this.transform({ skew: x, ox: y, oy: cx }, true)
3981 : this.transform({ skew: [x, y], ox: cx, oy: cy }, true)
3982 },
3983
3984 shear: function (lam, cx, cy) {
3985 return this.transform({ shear: lam, ox: cx, oy: cy }, true)
3986 },
3987
3988 // Map scale to transform
3989 scale: function (x, y, cx, cy) {
3990 return arguments.length === 1 || arguments.length === 3
3991 ? this.transform({ scale: x, ox: y, oy: cx }, true)
3992 : this.transform({ scale: [x, y], ox: cx, oy: cy }, true)
3993 },
3994
3995 // Map translate to transform
3996 translate: function (x, y) {
3997 return this.transform({ translate: [x, y] }, true)
3998 },
3999
4000 // Map relative translations to transform
4001 relative: function (x, y) {
4002 return this.transform({ relative: [x, y] }, true)
4003 },
4004
4005 // Map flip to transform
4006 flip: function (direction = 'both', origin = 'center') {
4007 if ('xybothtrue'.indexOf(direction) === -1) {
4008 origin = direction;
4009 direction = 'both';
4010 }
4011
4012 return this.transform({ flip: direction, origin: origin }, true)
4013 },
4014
4015 // Opacity
4016 opacity: function (value) {
4017 return this.attr('opacity', value)
4018 }
4019 });
4020
4021 registerMethods('radius', {
4022 // Add x and y radius
4023 radius: function (x, y = x) {
4024 const type = (this._element || this).type;
4025 return type === 'radialGradient'
4026 ? this.attr('r', new SVGNumber(x))
4027 : this.rx(x).ry(y)
4028 }
4029 });
4030
4031 registerMethods('Path', {
4032 // Get path length
4033 length: function () {
4034 return this.node.getTotalLength()
4035 },
4036 // Get point at length
4037 pointAt: function (length) {
4038 return new Point(this.node.getPointAtLength(length))
4039 }
4040 });
4041
4042 registerMethods(['Element', 'Runner'], {
4043 // Set font
4044 font: function (a, v) {
4045 if (typeof a === 'object') {
4046 for (v in a) this.font(v, a[v]);
4047 return this
4048 }
4049
4050 return a === 'leading'
4051 ? this.leading(v)
4052 : a === 'anchor'
4053 ? this.attr('text-anchor', v)
4054 : a === 'size' ||
4055 a === 'family' ||
4056 a === 'weight' ||
4057 a === 'stretch' ||
4058 a === 'variant' ||
4059 a === 'style'
4060 ? this.attr('font-' + a, v)
4061 : this.attr(a, v)
4062 }
4063 });
4064
4065 // Add events to elements
4066 const methods = [
4067 'click',
4068 'dblclick',
4069 'mousedown',
4070 'mouseup',
4071 'mouseover',
4072 'mouseout',
4073 'mousemove',
4074 'mouseenter',
4075 'mouseleave',
4076 'touchstart',
4077 'touchmove',
4078 'touchleave',
4079 'touchend',
4080 'touchcancel',
4081 'contextmenu',
4082 'wheel',
4083 'pointerdown',
4084 'pointermove',
4085 'pointerup',
4086 'pointerleave',
4087 'pointercancel'
4088 ].reduce(function (last, event) {
4089 // add event to Element
4090 const fn = function (f) {
4091 if (f === null) {
4092 this.off(event);
4093 } else {
4094 this.on(event, f);
4095 }
4096 return this
4097 };
4098
4099 last[event] = fn;
4100 return last
4101 }, {});
4102
4103 registerMethods('Element', methods);
4104
4105 // Reset all transformations
4106 function untransform() {
4107 return this.attr('transform', null)
4108 }
4109
4110 // merge the whole transformation chain into one matrix and returns it
4111 function matrixify() {
4112 const matrix = (this.attr('transform') || '')
4113 // split transformations
4114 .split(transforms)
4115 .slice(0, -1)
4116 .map(function (str) {
4117 // generate key => value pairs
4118 const kv = str.trim().split('(');
4119 return [
4120 kv[0],
4121 kv[1].split(delimiter).map(function (str) {
4122 return parseFloat(str)
4123 })
4124 ]
4125 })
4126 .reverse()
4127 // merge every transformation into one matrix
4128 .reduce(function (matrix, transform) {
4129 if (transform[0] === 'matrix') {
4130 return matrix.lmultiply(Matrix.fromArray(transform[1]))
4131 }
4132 return matrix[transform[0]].apply(matrix, transform[1])
4133 }, new Matrix());
4134
4135 return matrix
4136 }
4137
4138 // add an element to another parent without changing the visual representation on the screen
4139 function toParent(parent, i) {
4140 if (this === parent) return this
4141
4142 if (isDescriptive(this.node)) return this.addTo(parent, i)
4143
4144 const ctm = this.screenCTM();
4145 const pCtm = parent.screenCTM().inverse();
4146
4147 this.addTo(parent, i).untransform().transform(pCtm.multiply(ctm));
4148
4149 return this
4150 }
4151
4152 // same as above with parent equals root-svg
4153 function toRoot(i) {
4154 return this.toParent(this.root(), i)
4155 }
4156
4157 // Add transformations
4158 function transform(o, relative) {
4159 // Act as a getter if no object was passed
4160 if (o == null || typeof o === 'string') {
4161 const decomposed = new Matrix(this).decompose();
4162 return o == null ? decomposed : decomposed[o]
4163 }
4164
4165 if (!Matrix.isMatrixLike(o)) {
4166 // Set the origin according to the defined transform
4167 o = { ...o, origin: getOrigin(o, this) };
4168 }
4169
4170 // The user can pass a boolean, an Element or an Matrix or nothing
4171 const cleanRelative = relative === true ? this : relative || false;
4172 const result = new Matrix(cleanRelative).transform(o);
4173 return this.attr('transform', result)
4174 }
4175
4176 registerMethods('Element', {
4177 untransform,
4178 matrixify,
4179 toParent,
4180 toRoot,
4181 transform
4182 });
4183
4184 class Container extends Element$1 {
4185 flatten() {
4186 this.each(function () {
4187 if (this instanceof Container) {
4188 return this.flatten().ungroup()
4189 }
4190 });
4191
4192 return this
4193 }
4194
4195 ungroup(parent = this.parent(), index = parent.index(this)) {
4196 // when parent != this, we want append all elements to the end
4197 index = index === -1 ? parent.children().length : index;
4198
4199 this.each(function (i, children) {
4200 // reverse each
4201 return children[children.length - i - 1].toParent(parent, index)
4202 });
4203
4204 return this.remove()
4205 }
4206 }
4207
4208 register(Container, 'Container');
4209
4210 class Defs extends Container {
4211 constructor(node, attrs = node) {
4212 super(nodeOrNew('defs', node), attrs);
4213 }
4214
4215 flatten() {
4216 return this
4217 }
4218
4219 ungroup() {
4220 return this
4221 }
4222 }
4223
4224 register(Defs, 'Defs');
4225
4226 class Shape extends Element$1 {}
4227
4228 register(Shape, 'Shape');
4229
4230 // Radius x value
4231 function rx(rx) {
4232 return this.attr('rx', rx)
4233 }
4234
4235 // Radius y value
4236 function ry(ry) {
4237 return this.attr('ry', ry)
4238 }
4239
4240 // Move over x-axis
4241 function x$3(x) {
4242 return x == null ? this.cx() - this.rx() : this.cx(x + this.rx())
4243 }
4244
4245 // Move over y-axis
4246 function y$3(y) {
4247 return y == null ? this.cy() - this.ry() : this.cy(y + this.ry())
4248 }
4249
4250 // Move by center over x-axis
4251 function cx$1(x) {
4252 return this.attr('cx', x)
4253 }
4254
4255 // Move by center over y-axis
4256 function cy$1(y) {
4257 return this.attr('cy', y)
4258 }
4259
4260 // Set width of element
4261 function width$2(width) {
4262 return width == null ? this.rx() * 2 : this.rx(new SVGNumber(width).divide(2))
4263 }
4264
4265 // Set height of element
4266 function height$2(height) {
4267 return height == null
4268 ? this.ry() * 2
4269 : this.ry(new SVGNumber(height).divide(2))
4270 }
4271
4272 var circled = /*#__PURE__*/Object.freeze({
4273 __proto__: null,
4274 cx: cx$1,
4275 cy: cy$1,
4276 height: height$2,
4277 rx: rx,
4278 ry: ry,
4279 width: width$2,
4280 x: x$3,
4281 y: y$3
4282 });
4283
4284 class Ellipse extends Shape {
4285 constructor(node, attrs = node) {
4286 super(nodeOrNew('ellipse', node), attrs);
4287 }
4288
4289 size(width, height) {
4290 const p = proportionalSize(this, width, height);
4291
4292 return this.rx(new SVGNumber(p.width).divide(2)).ry(
4293 new SVGNumber(p.height).divide(2)
4294 )
4295 }
4296 }
4297
4298 extend(Ellipse, circled);
4299
4300 registerMethods('Container', {
4301 // Create an ellipse
4302 ellipse: wrapWithAttrCheck(function (width = 0, height = width) {
4303 return this.put(new Ellipse()).size(width, height).move(0, 0)
4304 })
4305 });
4306
4307 register(Ellipse, 'Ellipse');
4308
4309 class Fragment extends Dom {
4310 constructor(node = globals.document.createDocumentFragment()) {
4311 super(node);
4312 }
4313
4314 // Import / Export raw xml
4315 xml(xmlOrFn, outerXML, ns) {
4316 if (typeof xmlOrFn === 'boolean') {
4317 ns = outerXML;
4318 outerXML = xmlOrFn;
4319 xmlOrFn = null;
4320 }
4321
4322 // because this is a fragment we have to put all elements into a wrapper first
4323 // before we can get the innerXML from it
4324 if (xmlOrFn == null || typeof xmlOrFn === 'function') {
4325 const wrapper = new Dom(create('wrapper', ns));
4326 wrapper.add(this.node.cloneNode(true));
4327
4328 return wrapper.xml(false, ns)
4329 }
4330
4331 // Act as setter if we got a string
4332 return super.xml(xmlOrFn, false, ns)
4333 }
4334 }
4335
4336 register(Fragment, 'Fragment');
4337
4338 function from(x, y) {
4339 return (this._element || this).type === 'radialGradient'
4340 ? this.attr({ fx: new SVGNumber(x), fy: new SVGNumber(y) })
4341 : this.attr({ x1: new SVGNumber(x), y1: new SVGNumber(y) })
4342 }
4343
4344 function to(x, y) {
4345 return (this._element || this).type === 'radialGradient'
4346 ? this.attr({ cx: new SVGNumber(x), cy: new SVGNumber(y) })
4347 : this.attr({ x2: new SVGNumber(x), y2: new SVGNumber(y) })
4348 }
4349
4350 var gradiented = /*#__PURE__*/Object.freeze({
4351 __proto__: null,
4352 from: from,
4353 to: to
4354 });
4355
4356 class Gradient extends Container {
4357 constructor(type, attrs) {
4358 super(
4359 nodeOrNew(type + 'Gradient', typeof type === 'string' ? null : type),
4360 attrs
4361 );
4362 }
4363
4364 // custom attr to handle transform
4365 attr(a, b, c) {
4366 if (a === 'transform') a = 'gradientTransform';
4367 return super.attr(a, b, c)
4368 }
4369
4370 bbox() {
4371 return new Box()
4372 }
4373
4374 targets() {
4375 return baseFind('svg [fill*=' + this.id() + ']')
4376 }
4377
4378 // Alias string conversion to fill
4379 toString() {
4380 return this.url()
4381 }
4382
4383 // Update gradient
4384 update(block) {
4385 // remove all stops
4386 this.clear();
4387
4388 // invoke passed block
4389 if (typeof block === 'function') {
4390 block.call(this, this);
4391 }
4392
4393 return this
4394 }
4395
4396 // Return the fill id
4397 url() {
4398 return 'url(#' + this.id() + ')'
4399 }
4400 }
4401
4402 extend(Gradient, gradiented);
4403
4404 registerMethods({
4405 Container: {
4406 // Create gradient element in defs
4407 gradient(...args) {
4408 return this.defs().gradient(...args)
4409 }
4410 },
4411 // define gradient
4412 Defs: {
4413 gradient: wrapWithAttrCheck(function (type, block) {
4414 return this.put(new Gradient(type)).update(block)
4415 })
4416 }
4417 });
4418
4419 register(Gradient, 'Gradient');
4420
4421 class Pattern extends Container {
4422 // Initialize node
4423 constructor(node, attrs = node) {
4424 super(nodeOrNew('pattern', node), attrs);
4425 }
4426
4427 // custom attr to handle transform
4428 attr(a, b, c) {
4429 if (a === 'transform') a = 'patternTransform';
4430 return super.attr(a, b, c)
4431 }
4432
4433 bbox() {
4434 return new Box()
4435 }
4436
4437 targets() {
4438 return baseFind('svg [fill*=' + this.id() + ']')
4439 }
4440
4441 // Alias string conversion to fill
4442 toString() {
4443 return this.url()
4444 }
4445
4446 // Update pattern by rebuilding
4447 update(block) {
4448 // remove content
4449 this.clear();
4450
4451 // invoke passed block
4452 if (typeof block === 'function') {
4453 block.call(this, this);
4454 }
4455
4456 return this
4457 }
4458
4459 // Return the fill id
4460 url() {
4461 return 'url(#' + this.id() + ')'
4462 }
4463 }
4464
4465 registerMethods({
4466 Container: {
4467 // Create pattern element in defs
4468 pattern(...args) {
4469 return this.defs().pattern(...args)
4470 }
4471 },
4472 Defs: {
4473 pattern: wrapWithAttrCheck(function (width, height, block) {
4474 return this.put(new Pattern()).update(block).attr({
4475 x: 0,
4476 y: 0,
4477 width: width,
4478 height: height,
4479 patternUnits: 'userSpaceOnUse'
4480 })
4481 })
4482 }
4483 });
4484
4485 register(Pattern, 'Pattern');
4486
4487 let Image$1 = class Image extends Shape {
4488 constructor(node, attrs = node) {
4489 super(nodeOrNew('image', node), attrs);
4490 }
4491
4492 // (re)load image
4493 load(url, callback) {
4494 if (!url) return this
4495
4496 const img = new globals.window.Image();
4497
4498 on(
4499 img,
4500 'load',
4501 function (e) {
4502 const p = this.parent(Pattern);
4503
4504 // ensure image size
4505 if (this.width() === 0 && this.height() === 0) {
4506 this.size(img.width, img.height);
4507 }
4508
4509 if (p instanceof Pattern) {
4510 // ensure pattern size if not set
4511 if (p.width() === 0 && p.height() === 0) {
4512 p.size(this.width(), this.height());
4513 }
4514 }
4515
4516 if (typeof callback === 'function') {
4517 callback.call(this, e);
4518 }
4519 },
4520 this
4521 );
4522
4523 on(img, 'load error', function () {
4524 // dont forget to unbind memory leaking events
4525 off(img);
4526 });
4527
4528 return this.attr('href', (img.src = url), xlink)
4529 }
4530 };
4531
4532 registerAttrHook(function (attr, val, _this) {
4533 // convert image fill and stroke to patterns
4534 if (attr === 'fill' || attr === 'stroke') {
4535 if (isImage.test(val)) {
4536 val = _this.root().defs().image(val);
4537 }
4538 }
4539
4540 if (val instanceof Image$1) {
4541 val = _this
4542 .root()
4543 .defs()
4544 .pattern(0, 0, (pattern) => {
4545 pattern.add(val);
4546 });
4547 }
4548
4549 return val
4550 });
4551
4552 registerMethods({
4553 Container: {
4554 // create image element, load image and set its size
4555 image: wrapWithAttrCheck(function (source, callback) {
4556 return this.put(new Image$1()).size(0, 0).load(source, callback)
4557 })
4558 }
4559 });
4560
4561 register(Image$1, 'Image');
4562
4563 class PointArray extends SVGArray {
4564 // Get bounding box of points
4565 bbox() {
4566 let maxX = -Infinity;
4567 let maxY = -Infinity;
4568 let minX = Infinity;
4569 let minY = Infinity;
4570 this.forEach(function (el) {
4571 maxX = Math.max(el[0], maxX);
4572 maxY = Math.max(el[1], maxY);
4573 minX = Math.min(el[0], minX);
4574 minY = Math.min(el[1], minY);
4575 });
4576 return new Box(minX, minY, maxX - minX, maxY - minY)
4577 }
4578
4579 // Move point string
4580 move(x, y) {
4581 const box = this.bbox();
4582
4583 // get relative offset
4584 x -= box.x;
4585 y -= box.y;
4586
4587 // move every point
4588 if (!isNaN(x) && !isNaN(y)) {
4589 for (let i = this.length - 1; i >= 0; i--) {
4590 this[i] = [this[i][0] + x, this[i][1] + y];
4591 }
4592 }
4593
4594 return this
4595 }
4596
4597 // Parse point string and flat array
4598 parse(array = [0, 0]) {
4599 const points = [];
4600
4601 // if it is an array, we flatten it and therefore clone it to 1 depths
4602 if (array instanceof Array) {
4603 array = Array.prototype.concat.apply([], array);
4604 } else {
4605 // Else, it is considered as a string
4606 // parse points
4607 array = array.trim().split(delimiter).map(parseFloat);
4608 }
4609
4610 // validate points - https://svgwg.org/svg2-draft/shapes.html#DataTypePoints
4611 // Odd number of coordinates is an error. In such cases, drop the last odd coordinate.
4612 if (array.length % 2 !== 0) array.pop();
4613
4614 // wrap points in two-tuples
4615 for (let i = 0, len = array.length; i < len; i = i + 2) {
4616 points.push([array[i], array[i + 1]]);
4617 }
4618
4619 return points
4620 }
4621
4622 // Resize poly string
4623 size(width, height) {
4624 let i;
4625 const box = this.bbox();
4626
4627 // recalculate position of all points according to new size
4628 for (i = this.length - 1; i >= 0; i--) {
4629 if (box.width)
4630 this[i][0] = ((this[i][0] - box.x) * width) / box.width + box.x;
4631 if (box.height)
4632 this[i][1] = ((this[i][1] - box.y) * height) / box.height + box.y;
4633 }
4634
4635 return this
4636 }
4637
4638 // Convert array to line object
4639 toLine() {
4640 return {
4641 x1: this[0][0],
4642 y1: this[0][1],
4643 x2: this[1][0],
4644 y2: this[1][1]
4645 }
4646 }
4647
4648 // Convert array to string
4649 toString() {
4650 const array = [];
4651 // convert to a poly point string
4652 for (let i = 0, il = this.length; i < il; i++) {
4653 array.push(this[i].join(','));
4654 }
4655
4656 return array.join(' ')
4657 }
4658
4659 transform(m) {
4660 return this.clone().transformO(m)
4661 }
4662
4663 // transform points with matrix (similar to Point.transform)
4664 transformO(m) {
4665 if (!Matrix.isMatrixLike(m)) {
4666 m = new Matrix(m);
4667 }
4668
4669 for (let i = this.length; i--; ) {
4670 // Perform the matrix multiplication
4671 const [x, y] = this[i];
4672 this[i][0] = m.a * x + m.c * y + m.e;
4673 this[i][1] = m.b * x + m.d * y + m.f;
4674 }
4675
4676 return this
4677 }
4678 }
4679
4680 const MorphArray = PointArray;
4681
4682 // Move by left top corner over x-axis
4683 function x$2(x) {
4684 return x == null ? this.bbox().x : this.move(x, this.bbox().y)
4685 }
4686
4687 // Move by left top corner over y-axis
4688 function y$2(y) {
4689 return y == null ? this.bbox().y : this.move(this.bbox().x, y)
4690 }
4691
4692 // Set width of element
4693 function width$1(width) {
4694 const b = this.bbox();
4695 return width == null ? b.width : this.size(width, b.height)
4696 }
4697
4698 // Set height of element
4699 function height$1(height) {
4700 const b = this.bbox();
4701 return height == null ? b.height : this.size(b.width, height)
4702 }
4703
4704 var pointed = /*#__PURE__*/Object.freeze({
4705 __proto__: null,
4706 MorphArray: MorphArray,
4707 height: height$1,
4708 width: width$1,
4709 x: x$2,
4710 y: y$2
4711 });
4712
4713 let Line$1 = class Line extends Shape {
4714 // Initialize node
4715 constructor(node, attrs = node) {
4716 super(nodeOrNew('line', node), attrs);
4717 }
4718
4719 // Get array
4720 array() {
4721 return new PointArray([
4722 [this.attr('x1'), this.attr('y1')],
4723 [this.attr('x2'), this.attr('y2')]
4724 ])
4725 }
4726
4727 // Move by left top corner
4728 move(x, y) {
4729 return this.attr(this.array().move(x, y).toLine())
4730 }
4731
4732 // Overwrite native plot() method
4733 plot(x1, y1, x2, y2) {
4734 if (x1 == null) {
4735 return this.array()
4736 } else if (typeof y1 !== 'undefined') {
4737 x1 = { x1, y1, x2, y2 };
4738 } else {
4739 x1 = new PointArray(x1).toLine();
4740 }
4741
4742 return this.attr(x1)
4743 }
4744
4745 // Set element size to given width and height
4746 size(width, height) {
4747 const p = proportionalSize(this, width, height);
4748 return this.attr(this.array().size(p.width, p.height).toLine())
4749 }
4750 };
4751
4752 extend(Line$1, pointed);
4753
4754 registerMethods({
4755 Container: {
4756 // Create a line element
4757 line: wrapWithAttrCheck(function (...args) {
4758 // make sure plot is called as a setter
4759 // x1 is not necessarily a number, it can also be an array, a string and a PointArray
4760 return Line$1.prototype.plot.apply(
4761 this.put(new Line$1()),
4762 args[0] != null ? args : [0, 0, 0, 0]
4763 )
4764 })
4765 }
4766 });
4767
4768 register(Line$1, 'Line');
4769
4770 let Marker$1 = class Marker extends Container {
4771 // Initialize node
4772 constructor(node, attrs = node) {
4773 super(nodeOrNew('marker', node), attrs);
4774 }
4775
4776 // Set height of element
4777 height(height) {
4778 return this.attr('markerHeight', height)
4779 }
4780
4781 orient(orient) {
4782 return this.attr('orient', orient)
4783 }
4784
4785 // Set marker refX and refY
4786 ref(x, y) {
4787 return this.attr('refX', x).attr('refY', y)
4788 }
4789
4790 // Return the fill id
4791 toString() {
4792 return 'url(#' + this.id() + ')'
4793 }
4794
4795 // Update marker
4796 update(block) {
4797 // remove all content
4798 this.clear();
4799
4800 // invoke passed block
4801 if (typeof block === 'function') {
4802 block.call(this, this);
4803 }
4804
4805 return this
4806 }
4807
4808 // Set width of element
4809 width(width) {
4810 return this.attr('markerWidth', width)
4811 }
4812 };
4813
4814 registerMethods({
4815 Container: {
4816 marker(...args) {
4817 // Create marker element in defs
4818 return this.defs().marker(...args)
4819 }
4820 },
4821 Defs: {
4822 // Create marker
4823 marker: wrapWithAttrCheck(function (width, height, block) {
4824 // Set default viewbox to match the width and height, set ref to cx and cy and set orient to auto
4825 return this.put(new Marker$1())
4826 .size(width, height)
4827 .ref(width / 2, height / 2)
4828 .viewbox(0, 0, width, height)
4829 .attr('orient', 'auto')
4830 .update(block)
4831 })
4832 },
4833 marker: {
4834 // Create and attach markers
4835 marker(marker, width, height, block) {
4836 let attr = ['marker'];
4837
4838 // Build attribute name
4839 if (marker !== 'all') attr.push(marker);
4840 attr = attr.join('-');
4841
4842 // Set marker attribute
4843 marker =
4844 arguments[1] instanceof Marker$1
4845 ? arguments[1]
4846 : this.defs().marker(width, height, block);
4847
4848 return this.attr(attr, marker)
4849 }
4850 }
4851 });
4852
4853 register(Marker$1, 'Marker');
4854
4855 /***
4856 Base Class
4857 ==========
4858 The base stepper class that will be
4859 ***/
4860
4861 function makeSetterGetter(k, f) {
4862 return function (v) {
4863 if (v == null) return this[k]
4864 this[k] = v;
4865 if (f) f.call(this);
4866 return this
4867 }
4868 }
4869
4870 const easing = {
4871 '-': function (pos) {
4872 return pos
4873 },
4874 '<>': function (pos) {
4875 return -Math.cos(pos * Math.PI) / 2 + 0.5
4876 },
4877 '>': function (pos) {
4878 return Math.sin((pos * Math.PI) / 2)
4879 },
4880 '<': function (pos) {
4881 return -Math.cos((pos * Math.PI) / 2) + 1
4882 },
4883 bezier: function (x1, y1, x2, y2) {
4884 // see https://www.w3.org/TR/css-easing-1/#cubic-bezier-algo
4885 return function (t) {
4886 if (t < 0) {
4887 if (x1 > 0) {
4888 return (y1 / x1) * t
4889 } else if (x2 > 0) {
4890 return (y2 / x2) * t
4891 } else {
4892 return 0
4893 }
4894 } else if (t > 1) {
4895 if (x2 < 1) {
4896 return ((1 - y2) / (1 - x2)) * t + (y2 - x2) / (1 - x2)
4897 } else if (x1 < 1) {
4898 return ((1 - y1) / (1 - x1)) * t + (y1 - x1) / (1 - x1)
4899 } else {
4900 return 1
4901 }
4902 } else {
4903 return 3 * t * (1 - t) ** 2 * y1 + 3 * t ** 2 * (1 - t) * y2 + t ** 3
4904 }
4905 }
4906 },
4907 // see https://www.w3.org/TR/css-easing-1/#step-timing-function-algo
4908 steps: function (steps, stepPosition = 'end') {
4909 // deal with "jump-" prefix
4910 stepPosition = stepPosition.split('-').reverse()[0];
4911
4912 let jumps = steps;
4913 if (stepPosition === 'none') {
4914 --jumps;
4915 } else if (stepPosition === 'both') {
4916 ++jumps;
4917 }
4918
4919 // The beforeFlag is essentially useless
4920 return (t, beforeFlag = false) => {
4921 // Step is called currentStep in referenced url
4922 let step = Math.floor(t * steps);
4923 const jumping = (t * step) % 1 === 0;
4924
4925 if (stepPosition === 'start' || stepPosition === 'both') {
4926 ++step;
4927 }
4928
4929 if (beforeFlag && jumping) {
4930 --step;
4931 }
4932
4933 if (t >= 0 && step < 0) {
4934 step = 0;
4935 }
4936
4937 if (t <= 1 && step > jumps) {
4938 step = jumps;
4939 }
4940
4941 return step / jumps
4942 }
4943 }
4944 };
4945
4946 class Stepper {
4947 done() {
4948 return false
4949 }
4950 }
4951
4952 /***
4953 Easing Functions
4954 ================
4955 ***/
4956
4957 class Ease extends Stepper {
4958 constructor(fn = timeline.ease) {
4959 super();
4960 this.ease = easing[fn] || fn;
4961 }
4962
4963 step(from, to, pos) {
4964 if (typeof from !== 'number') {
4965 return pos < 1 ? from : to
4966 }
4967 return from + (to - from) * this.ease(pos)
4968 }
4969 }
4970
4971 /***
4972 Controller Types
4973 ================
4974 ***/
4975
4976 class Controller extends Stepper {
4977 constructor(fn) {
4978 super();
4979 this.stepper = fn;
4980 }
4981
4982 done(c) {
4983 return c.done
4984 }
4985
4986 step(current, target, dt, c) {
4987 return this.stepper(current, target, dt, c)
4988 }
4989 }
4990
4991 function recalculate() {
4992 // Apply the default parameters
4993 const duration = (this._duration || 500) / 1000;
4994 const overshoot = this._overshoot || 0;
4995
4996 // Calculate the PID natural response
4997 const eps = 1e-10;
4998 const pi = Math.PI;
4999 const os = Math.log(overshoot / 100 + eps);
5000 const zeta = -os / Math.sqrt(pi * pi + os * os);
5001 const wn = 3.9 / (zeta * duration);
5002
5003 // Calculate the Spring values
5004 this.d = 2 * zeta * wn;
5005 this.k = wn * wn;
5006 }
5007
5008 class Spring extends Controller {
5009 constructor(duration = 500, overshoot = 0) {
5010 super();
5011 this.duration(duration).overshoot(overshoot);
5012 }
5013
5014 step(current, target, dt, c) {
5015 if (typeof current === 'string') return current
5016 c.done = dt === Infinity;
5017 if (dt === Infinity) return target
5018 if (dt === 0) return current
5019
5020 if (dt > 100) dt = 16;
5021
5022 dt /= 1000;
5023
5024 // Get the previous velocity
5025 const velocity = c.velocity || 0;
5026
5027 // Apply the control to get the new position and store it
5028 const acceleration = -this.d * velocity - this.k * (current - target);
5029 const newPosition = current + velocity * dt + (acceleration * dt * dt) / 2;
5030
5031 // Store the velocity
5032 c.velocity = velocity + acceleration * dt;
5033
5034 // Figure out if we have converged, and if so, pass the value
5035 c.done = Math.abs(target - newPosition) + Math.abs(velocity) < 0.002;
5036 return c.done ? target : newPosition
5037 }
5038 }
5039
5040 extend(Spring, {
5041 duration: makeSetterGetter('_duration', recalculate),
5042 overshoot: makeSetterGetter('_overshoot', recalculate)
5043 });
5044
5045 class PID extends Controller {
5046 constructor(p = 0.1, i = 0.01, d = 0, windup = 1000) {
5047 super();
5048 this.p(p).i(i).d(d).windup(windup);
5049 }
5050
5051 step(current, target, dt, c) {
5052 if (typeof current === 'string') return current
5053 c.done = dt === Infinity;
5054
5055 if (dt === Infinity) return target
5056 if (dt === 0) return current
5057
5058 const p = target - current;
5059 let i = (c.integral || 0) + p * dt;
5060 const d = (p - (c.error || 0)) / dt;
5061 const windup = this._windup;
5062
5063 // antiwindup
5064 if (windup !== false) {
5065 i = Math.max(-windup, Math.min(i, windup));
5066 }
5067
5068 c.error = p;
5069 c.integral = i;
5070
5071 c.done = Math.abs(p) < 0.001;
5072
5073 return c.done ? target : current + (this.P * p + this.I * i + this.D * d)
5074 }
5075 }
5076
5077 extend(PID, {
5078 windup: makeSetterGetter('_windup'),
5079 p: makeSetterGetter('P'),
5080 i: makeSetterGetter('I'),
5081 d: makeSetterGetter('D')
5082 });
5083
5084 const segmentParameters = {
5085 M: 2,
5086 L: 2,
5087 H: 1,
5088 V: 1,
5089 C: 6,
5090 S: 4,
5091 Q: 4,
5092 T: 2,
5093 A: 7,
5094 Z: 0
5095 };
5096
5097 const pathHandlers = {
5098 M: function (c, p, p0) {
5099 p.x = p0.x = c[0];
5100 p.y = p0.y = c[1];
5101
5102 return ['M', p.x, p.y]
5103 },
5104 L: function (c, p) {
5105 p.x = c[0];
5106 p.y = c[1];
5107 return ['L', c[0], c[1]]
5108 },
5109 H: function (c, p) {
5110 p.x = c[0];
5111 return ['H', c[0]]
5112 },
5113 V: function (c, p) {
5114 p.y = c[0];
5115 return ['V', c[0]]
5116 },
5117 C: function (c, p) {
5118 p.x = c[4];
5119 p.y = c[5];
5120 return ['C', c[0], c[1], c[2], c[3], c[4], c[5]]
5121 },
5122 S: function (c, p) {
5123 p.x = c[2];
5124 p.y = c[3];
5125 return ['S', c[0], c[1], c[2], c[3]]
5126 },
5127 Q: function (c, p) {
5128 p.x = c[2];
5129 p.y = c[3];
5130 return ['Q', c[0], c[1], c[2], c[3]]
5131 },
5132 T: function (c, p) {
5133 p.x = c[0];
5134 p.y = c[1];
5135 return ['T', c[0], c[1]]
5136 },
5137 Z: function (c, p, p0) {
5138 p.x = p0.x;
5139 p.y = p0.y;
5140 return ['Z']
5141 },
5142 A: function (c, p) {
5143 p.x = c[5];
5144 p.y = c[6];
5145 return ['A', c[0], c[1], c[2], c[3], c[4], c[5], c[6]]
5146 }
5147 };
5148
5149 const mlhvqtcsaz = 'mlhvqtcsaz'.split('');
5150
5151 for (let i = 0, il = mlhvqtcsaz.length; i < il; ++i) {
5152 pathHandlers[mlhvqtcsaz[i]] = (function (i) {
5153 return function (c, p, p0) {
5154 if (i === 'H') c[0] = c[0] + p.x;
5155 else if (i === 'V') c[0] = c[0] + p.y;
5156 else if (i === 'A') {
5157 c[5] = c[5] + p.x;
5158 c[6] = c[6] + p.y;
5159 } else {
5160 for (let j = 0, jl = c.length; j < jl; ++j) {
5161 c[j] = c[j] + (j % 2 ? p.y : p.x);
5162 }
5163 }
5164
5165 return pathHandlers[i](c, p, p0)
5166 }
5167 })(mlhvqtcsaz[i].toUpperCase());
5168 }
5169
5170 function makeAbsolut(parser) {
5171 const command = parser.segment[0];
5172 return pathHandlers[command](parser.segment.slice(1), parser.p, parser.p0)
5173 }
5174
5175 function segmentComplete(parser) {
5176 return (
5177 parser.segment.length &&
5178 parser.segment.length - 1 ===
5179 segmentParameters[parser.segment[0].toUpperCase()]
5180 )
5181 }
5182
5183 function startNewSegment(parser, token) {
5184 parser.inNumber && finalizeNumber(parser, false);
5185 const pathLetter = isPathLetter.test(token);
5186
5187 if (pathLetter) {
5188 parser.segment = [token];
5189 } else {
5190 const lastCommand = parser.lastCommand;
5191 const small = lastCommand.toLowerCase();
5192 const isSmall = lastCommand === small;
5193 parser.segment = [small === 'm' ? (isSmall ? 'l' : 'L') : lastCommand];
5194 }
5195
5196 parser.inSegment = true;
5197 parser.lastCommand = parser.segment[0];
5198
5199 return pathLetter
5200 }
5201
5202 function finalizeNumber(parser, inNumber) {
5203 if (!parser.inNumber) throw new Error('Parser Error')
5204 parser.number && parser.segment.push(parseFloat(parser.number));
5205 parser.inNumber = inNumber;
5206 parser.number = '';
5207 parser.pointSeen = false;
5208 parser.hasExponent = false;
5209
5210 if (segmentComplete(parser)) {
5211 finalizeSegment(parser);
5212 }
5213 }
5214
5215 function finalizeSegment(parser) {
5216 parser.inSegment = false;
5217 if (parser.absolute) {
5218 parser.segment = makeAbsolut(parser);
5219 }
5220 parser.segments.push(parser.segment);
5221 }
5222
5223 function isArcFlag(parser) {
5224 if (!parser.segment.length) return false
5225 const isArc = parser.segment[0].toUpperCase() === 'A';
5226 const length = parser.segment.length;
5227
5228 return isArc && (length === 4 || length === 5)
5229 }
5230
5231 function isExponential(parser) {
5232 return parser.lastToken.toUpperCase() === 'E'
5233 }
5234
5235 const pathDelimiters = new Set([' ', ',', '\t', '\n', '\r', '\f']);
5236 function pathParser(d, toAbsolute = true) {
5237 let index = 0;
5238 let token = '';
5239 const parser = {
5240 segment: [],
5241 inNumber: false,
5242 number: '',
5243 lastToken: '',
5244 inSegment: false,
5245 segments: [],
5246 pointSeen: false,
5247 hasExponent: false,
5248 absolute: toAbsolute,
5249 p0: new Point(),
5250 p: new Point()
5251 };
5252
5253 while (((parser.lastToken = token), (token = d.charAt(index++)))) {
5254 if (!parser.inSegment) {
5255 if (startNewSegment(parser, token)) {
5256 continue
5257 }
5258 }
5259
5260 if (token === '.') {
5261 if (parser.pointSeen || parser.hasExponent) {
5262 finalizeNumber(parser, false);
5263 --index;
5264 continue
5265 }
5266 parser.inNumber = true;
5267 parser.pointSeen = true;
5268 parser.number += token;
5269 continue
5270 }
5271
5272 if (!isNaN(parseInt(token))) {
5273 if (parser.number === '0' || isArcFlag(parser)) {
5274 parser.inNumber = true;
5275 parser.number = token;
5276 finalizeNumber(parser, true);
5277 continue
5278 }
5279
5280 parser.inNumber = true;
5281 parser.number += token;
5282 continue
5283 }
5284
5285 if (pathDelimiters.has(token)) {
5286 if (parser.inNumber) {
5287 finalizeNumber(parser, false);
5288 }
5289 continue
5290 }
5291
5292 if (token === '-' || token === '+') {
5293 if (parser.inNumber && !isExponential(parser)) {
5294 finalizeNumber(parser, false);
5295 --index;
5296 continue
5297 }
5298 parser.number += token;
5299 parser.inNumber = true;
5300 continue
5301 }
5302
5303 if (token.toUpperCase() === 'E') {
5304 parser.number += token;
5305 parser.hasExponent = true;
5306 continue
5307 }
5308
5309 if (isPathLetter.test(token)) {
5310 if (parser.inNumber) {
5311 finalizeNumber(parser, false);
5312 } else if (!segmentComplete(parser)) {
5313 throw new Error('parser Error')
5314 } else {
5315 finalizeSegment(parser);
5316 }
5317 --index;
5318 }
5319 }
5320
5321 if (parser.inNumber) {
5322 finalizeNumber(parser, false);
5323 }
5324
5325 if (parser.inSegment && segmentComplete(parser)) {
5326 finalizeSegment(parser);
5327 }
5328
5329 return parser.segments
5330 }
5331
5332 function arrayToString(a) {
5333 let s = '';
5334 for (let i = 0, il = a.length; i < il; i++) {
5335 s += a[i][0];
5336
5337 if (a[i][1] != null) {
5338 s += a[i][1];
5339
5340 if (a[i][2] != null) {
5341 s += ' ';
5342 s += a[i][2];
5343
5344 if (a[i][3] != null) {
5345 s += ' ';
5346 s += a[i][3];
5347 s += ' ';
5348 s += a[i][4];
5349
5350 if (a[i][5] != null) {
5351 s += ' ';
5352 s += a[i][5];
5353 s += ' ';
5354 s += a[i][6];
5355
5356 if (a[i][7] != null) {
5357 s += ' ';
5358 s += a[i][7];
5359 }
5360 }
5361 }
5362 }
5363 }
5364 }
5365
5366 return s + ' '
5367 }
5368
5369 class PathArray extends SVGArray {
5370 // Get bounding box of path
5371 bbox() {
5372 parser().path.setAttribute('d', this.toString());
5373 return new Box(parser.nodes.path.getBBox())
5374 }
5375
5376 // Move path string
5377 move(x, y) {
5378 // get bounding box of current situation
5379 const box = this.bbox();
5380
5381 // get relative offset
5382 x -= box.x;
5383 y -= box.y;
5384
5385 if (!isNaN(x) && !isNaN(y)) {
5386 // move every point
5387 for (let l, i = this.length - 1; i >= 0; i--) {
5388 l = this[i][0];
5389
5390 if (l === 'M' || l === 'L' || l === 'T') {
5391 this[i][1] += x;
5392 this[i][2] += y;
5393 } else if (l === 'H') {
5394 this[i][1] += x;
5395 } else if (l === 'V') {
5396 this[i][1] += y;
5397 } else if (l === 'C' || l === 'S' || l === 'Q') {
5398 this[i][1] += x;
5399 this[i][2] += y;
5400 this[i][3] += x;
5401 this[i][4] += y;
5402
5403 if (l === 'C') {
5404 this[i][5] += x;
5405 this[i][6] += y;
5406 }
5407 } else if (l === 'A') {
5408 this[i][6] += x;
5409 this[i][7] += y;
5410 }
5411 }
5412 }
5413
5414 return this
5415 }
5416
5417 // Absolutize and parse path to array
5418 parse(d = 'M0 0') {
5419 if (Array.isArray(d)) {
5420 d = Array.prototype.concat.apply([], d).toString();
5421 }
5422
5423 return pathParser(d)
5424 }
5425
5426 // Resize path string
5427 size(width, height) {
5428 // get bounding box of current situation
5429 const box = this.bbox();
5430 let i, l;
5431
5432 // If the box width or height is 0 then we ignore
5433 // transformations on the respective axis
5434 box.width = box.width === 0 ? 1 : box.width;
5435 box.height = box.height === 0 ? 1 : box.height;
5436
5437 // recalculate position of all points according to new size
5438 for (i = this.length - 1; i >= 0; i--) {
5439 l = this[i][0];
5440
5441 if (l === 'M' || l === 'L' || l === 'T') {
5442 this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x;
5443 this[i][2] = ((this[i][2] - box.y) * height) / box.height + box.y;
5444 } else if (l === 'H') {
5445 this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x;
5446 } else if (l === 'V') {
5447 this[i][1] = ((this[i][1] - box.y) * height) / box.height + box.y;
5448 } else if (l === 'C' || l === 'S' || l === 'Q') {
5449 this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x;
5450 this[i][2] = ((this[i][2] - box.y) * height) / box.height + box.y;
5451 this[i][3] = ((this[i][3] - box.x) * width) / box.width + box.x;
5452 this[i][4] = ((this[i][4] - box.y) * height) / box.height + box.y;
5453
5454 if (l === 'C') {
5455 this[i][5] = ((this[i][5] - box.x) * width) / box.width + box.x;
5456 this[i][6] = ((this[i][6] - box.y) * height) / box.height + box.y;
5457 }
5458 } else if (l === 'A') {
5459 // resize radii
5460 this[i][1] = (this[i][1] * width) / box.width;
5461 this[i][2] = (this[i][2] * height) / box.height;
5462
5463 // move position values
5464 this[i][6] = ((this[i][6] - box.x) * width) / box.width + box.x;
5465 this[i][7] = ((this[i][7] - box.y) * height) / box.height + box.y;
5466 }
5467 }
5468
5469 return this
5470 }
5471
5472 // Convert array to string
5473 toString() {
5474 return arrayToString(this)
5475 }
5476 }
5477
5478 const getClassForType = (value) => {
5479 const type = typeof value;
5480
5481 if (type === 'number') {
5482 return SVGNumber
5483 } else if (type === 'string') {
5484 if (Color.isColor(value)) {
5485 return Color
5486 } else if (delimiter.test(value)) {
5487 return isPathLetter.test(value) ? PathArray : SVGArray
5488 } else if (numberAndUnit.test(value)) {
5489 return SVGNumber
5490 } else {
5491 return NonMorphable
5492 }
5493 } else if (morphableTypes.indexOf(value.constructor) > -1) {
5494 return value.constructor
5495 } else if (Array.isArray(value)) {
5496 return SVGArray
5497 } else if (type === 'object') {
5498 return ObjectBag
5499 } else {
5500 return NonMorphable
5501 }
5502 };
5503
5504 class Morphable {
5505 constructor(stepper) {
5506 this._stepper = stepper || new Ease('-');
5507
5508 this._from = null;
5509 this._to = null;
5510 this._type = null;
5511 this._context = null;
5512 this._morphObj = null;
5513 }
5514
5515 at(pos) {
5516 return this._morphObj.morph(
5517 this._from,
5518 this._to,
5519 pos,
5520 this._stepper,
5521 this._context
5522 )
5523 }
5524
5525 done() {
5526 const complete = this._context.map(this._stepper.done).reduce(function (
5527 last,
5528 curr
5529 ) {
5530 return last && curr
5531 }, true);
5532 return complete
5533 }
5534
5535 from(val) {
5536 if (val == null) {
5537 return this._from
5538 }
5539
5540 this._from = this._set(val);
5541 return this
5542 }
5543
5544 stepper(stepper) {
5545 if (stepper == null) return this._stepper
5546 this._stepper = stepper;
5547 return this
5548 }
5549
5550 to(val) {
5551 if (val == null) {
5552 return this._to
5553 }
5554
5555 this._to = this._set(val);
5556 return this
5557 }
5558
5559 type(type) {
5560 // getter
5561 if (type == null) {
5562 return this._type
5563 }
5564
5565 // setter
5566 this._type = type;
5567 return this
5568 }
5569
5570 _set(value) {
5571 if (!this._type) {
5572 this.type(getClassForType(value));
5573 }
5574
5575 let result = new this._type(value);
5576 if (this._type === Color) {
5577 result = this._to
5578 ? result[this._to[4]]()
5579 : this._from
5580 ? result[this._from[4]]()
5581 : result;
5582 }
5583
5584 if (this._type === ObjectBag) {
5585 result = this._to
5586 ? result.align(this._to)
5587 : this._from
5588 ? result.align(this._from)
5589 : result;
5590 }
5591
5592 result = result.toConsumable();
5593
5594 this._morphObj = this._morphObj || new this._type();
5595 this._context =
5596 this._context ||
5597 Array.apply(null, Array(result.length))
5598 .map(Object)
5599 .map(function (o) {
5600 o.done = true;
5601 return o
5602 });
5603 return result
5604 }
5605 }
5606
5607 class NonMorphable {
5608 constructor(...args) {
5609 this.init(...args);
5610 }
5611
5612 init(val) {
5613 val = Array.isArray(val) ? val[0] : val;
5614 this.value = val;
5615 return this
5616 }
5617
5618 toArray() {
5619 return [this.value]
5620 }
5621
5622 valueOf() {
5623 return this.value
5624 }
5625 }
5626
5627 class TransformBag {
5628 constructor(...args) {
5629 this.init(...args);
5630 }
5631
5632 init(obj) {
5633 if (Array.isArray(obj)) {
5634 obj = {
5635 scaleX: obj[0],
5636 scaleY: obj[1],
5637 shear: obj[2],
5638 rotate: obj[3],
5639 translateX: obj[4],
5640 translateY: obj[5],
5641 originX: obj[6],
5642 originY: obj[7]
5643 };
5644 }
5645
5646 Object.assign(this, TransformBag.defaults, obj);
5647 return this
5648 }
5649
5650 toArray() {
5651 const v = this;
5652
5653 return [
5654 v.scaleX,
5655 v.scaleY,
5656 v.shear,
5657 v.rotate,
5658 v.translateX,
5659 v.translateY,
5660 v.originX,
5661 v.originY
5662 ]
5663 }
5664 }
5665
5666 TransformBag.defaults = {
5667 scaleX: 1,
5668 scaleY: 1,
5669 shear: 0,
5670 rotate: 0,
5671 translateX: 0,
5672 translateY: 0,
5673 originX: 0,
5674 originY: 0
5675 };
5676
5677 const sortByKey = (a, b) => {
5678 return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0
5679 };
5680
5681 class ObjectBag {
5682 constructor(...args) {
5683 this.init(...args);
5684 }
5685
5686 align(other) {
5687 const values = this.values;
5688 for (let i = 0, il = values.length; i < il; ++i) {
5689 // If the type is the same we only need to check if the color is in the correct format
5690 if (values[i + 1] === other[i + 1]) {
5691 if (values[i + 1] === Color && other[i + 7] !== values[i + 7]) {
5692 const space = other[i + 7];
5693 const color = new Color(this.values.splice(i + 3, 5))
5694 [space]()
5695 .toArray();
5696 this.values.splice(i + 3, 0, ...color);
5697 }
5698
5699 i += values[i + 2] + 2;
5700 continue
5701 }
5702
5703 if (!other[i + 1]) {
5704 return this
5705 }
5706
5707 // The types differ, so we overwrite the new type with the old one
5708 // And initialize it with the types default (e.g. black for color or 0 for number)
5709 const defaultObject = new other[i + 1]().toArray();
5710
5711 // Than we fix the values array
5712 const toDelete = values[i + 2] + 3;
5713
5714 values.splice(
5715 i,
5716 toDelete,
5717 other[i],
5718 other[i + 1],
5719 other[i + 2],
5720 ...defaultObject
5721 );
5722
5723 i += values[i + 2] + 2;
5724 }
5725 return this
5726 }
5727
5728 init(objOrArr) {
5729 this.values = [];
5730
5731 if (Array.isArray(objOrArr)) {
5732 this.values = objOrArr.slice();
5733 return
5734 }
5735
5736 objOrArr = objOrArr || {};
5737 const entries = [];
5738
5739 for (const i in objOrArr) {
5740 const Type = getClassForType(objOrArr[i]);
5741 const val = new Type(objOrArr[i]).toArray();
5742 entries.push([i, Type, val.length, ...val]);
5743 }
5744
5745 entries.sort(sortByKey);
5746
5747 this.values = entries.reduce((last, curr) => last.concat(curr), []);
5748 return this
5749 }
5750
5751 toArray() {
5752 return this.values
5753 }
5754
5755 valueOf() {
5756 const obj = {};
5757 const arr = this.values;
5758
5759 // for (var i = 0, len = arr.length; i < len; i += 2) {
5760 while (arr.length) {
5761 const key = arr.shift();
5762 const Type = arr.shift();
5763 const num = arr.shift();
5764 const values = arr.splice(0, num);
5765 obj[key] = new Type(values); // .valueOf()
5766 }
5767
5768 return obj
5769 }
5770 }
5771
5772 const morphableTypes = [NonMorphable, TransformBag, ObjectBag];
5773
5774 function registerMorphableType(type = []) {
5775 morphableTypes.push(...[].concat(type));
5776 }
5777
5778 function makeMorphable() {
5779 extend(morphableTypes, {
5780 to(val) {
5781 return new Morphable()
5782 .type(this.constructor)
5783 .from(this.toArray()) // this.valueOf())
5784 .to(val)
5785 },
5786 fromArray(arr) {
5787 this.init(arr);
5788 return this
5789 },
5790 toConsumable() {
5791 return this.toArray()
5792 },
5793 morph(from, to, pos, stepper, context) {
5794 const mapper = function (i, index) {
5795 return stepper.step(i, to[index], pos, context[index], context)
5796 };
5797
5798 return this.fromArray(from.map(mapper))
5799 }
5800 });
5801 }
5802
5803 class Path extends Shape {
5804 // Initialize node
5805 constructor(node, attrs = node) {
5806 super(nodeOrNew('path', node), attrs);
5807 }
5808
5809 // Get array
5810 array() {
5811 return this._array || (this._array = new PathArray(this.attr('d')))
5812 }
5813
5814 // Clear array cache
5815 clear() {
5816 delete this._array;
5817 return this
5818 }
5819
5820 // Set height of element
5821 height(height) {
5822 return height == null
5823 ? this.bbox().height
5824 : this.size(this.bbox().width, height)
5825 }
5826
5827 // Move by left top corner
5828 move(x, y) {
5829 return this.attr('d', this.array().move(x, y))
5830 }
5831
5832 // Plot new path
5833 plot(d) {
5834 return d == null
5835 ? this.array()
5836 : this.clear().attr(
5837 'd',
5838 typeof d === 'string' ? d : (this._array = new PathArray(d))
5839 )
5840 }
5841
5842 // Set element size to given width and height
5843 size(width, height) {
5844 const p = proportionalSize(this, width, height);
5845 return this.attr('d', this.array().size(p.width, p.height))
5846 }
5847
5848 // Set width of element
5849 width(width) {
5850 return width == null
5851 ? this.bbox().width
5852 : this.size(width, this.bbox().height)
5853 }
5854
5855 // Move by left top corner over x-axis
5856 x(x) {
5857 return x == null ? this.bbox().x : this.move(x, this.bbox().y)
5858 }
5859
5860 // Move by left top corner over y-axis
5861 y(y) {
5862 return y == null ? this.bbox().y : this.move(this.bbox().x, y)
5863 }
5864 }
5865
5866 // Define morphable array
5867 Path.prototype.MorphArray = PathArray;
5868
5869 // Add parent method
5870 registerMethods({
5871 Container: {
5872 // Create a wrapped path element
5873 path: wrapWithAttrCheck(function (d) {
5874 // make sure plot is called as a setter
5875 return this.put(new Path()).plot(d || new PathArray())
5876 })
5877 }
5878 });
5879
5880 register(Path, 'Path');
5881
5882 // Get array
5883 function array() {
5884 return this._array || (this._array = new PointArray(this.attr('points')))
5885 }
5886
5887 // Clear array cache
5888 function clear() {
5889 delete this._array;
5890 return this
5891 }
5892
5893 // Move by left top corner
5894 function move$2(x, y) {
5895 return this.attr('points', this.array().move(x, y))
5896 }
5897
5898 // Plot new path
5899 function plot(p) {
5900 return p == null
5901 ? this.array()
5902 : this.clear().attr(
5903 'points',
5904 typeof p === 'string' ? p : (this._array = new PointArray(p))
5905 )
5906 }
5907
5908 // Set element size to given width and height
5909 function size$1(width, height) {
5910 const p = proportionalSize(this, width, height);
5911 return this.attr('points', this.array().size(p.width, p.height))
5912 }
5913
5914 var poly = /*#__PURE__*/Object.freeze({
5915 __proto__: null,
5916 array: array,
5917 clear: clear,
5918 move: move$2,
5919 plot: plot,
5920 size: size$1
5921 });
5922
5923 class Polygon extends Shape {
5924 // Initialize node
5925 constructor(node, attrs = node) {
5926 super(nodeOrNew('polygon', node), attrs);
5927 }
5928 }
5929
5930 registerMethods({
5931 Container: {
5932 // Create a wrapped polygon element
5933 polygon: wrapWithAttrCheck(function (p) {
5934 // make sure plot is called as a setter
5935 return this.put(new Polygon()).plot(p || new PointArray())
5936 })
5937 }
5938 });
5939
5940 extend(Polygon, pointed);
5941 extend(Polygon, poly);
5942 register(Polygon, 'Polygon');
5943
5944 class Polyline extends Shape {
5945 // Initialize node
5946 constructor(node, attrs = node) {
5947 super(nodeOrNew('polyline', node), attrs);
5948 }
5949 }
5950
5951 registerMethods({
5952 Container: {
5953 // Create a wrapped polygon element
5954 polyline: wrapWithAttrCheck(function (p) {
5955 // make sure plot is called as a setter
5956 return this.put(new Polyline()).plot(p || new PointArray())
5957 })
5958 }
5959 });
5960
5961 extend(Polyline, pointed);
5962 extend(Polyline, poly);
5963 register(Polyline, 'Polyline');
5964
5965 class Rect extends Shape {
5966 // Initialize node
5967 constructor(node, attrs = node) {
5968 super(nodeOrNew('rect', node), attrs);
5969 }
5970 }
5971
5972 extend(Rect, { rx, ry });
5973
5974 registerMethods({
5975 Container: {
5976 // Create a rect element
5977 rect: wrapWithAttrCheck(function (width, height) {
5978 return this.put(new Rect()).size(width, height)
5979 })
5980 }
5981 });
5982
5983 register(Rect, 'Rect');
5984
5985 class Queue {
5986 constructor() {
5987 this._first = null;
5988 this._last = null;
5989 }
5990
5991 // Shows us the first item in the list
5992 first() {
5993 return this._first && this._first.value
5994 }
5995
5996 // Shows us the last item in the list
5997 last() {
5998 return this._last && this._last.value
5999 }
6000
6001 push(value) {
6002 // An item stores an id and the provided value
6003 const item =
6004 typeof value.next !== 'undefined'
6005 ? value
6006 : { value: value, next: null, prev: null };
6007
6008 // Deal with the queue being empty or populated
6009 if (this._last) {
6010 item.prev = this._last;
6011 this._last.next = item;
6012 this._last = item;
6013 } else {
6014 this._last = item;
6015 this._first = item;
6016 }
6017
6018 // Return the current item
6019 return item
6020 }
6021
6022 // Removes the item that was returned from the push
6023 remove(item) {
6024 // Relink the previous item
6025 if (item.prev) item.prev.next = item.next;
6026 if (item.next) item.next.prev = item.prev;
6027 if (item === this._last) this._last = item.prev;
6028 if (item === this._first) this._first = item.next;
6029
6030 // Invalidate item
6031 item.prev = null;
6032 item.next = null;
6033 }
6034
6035 shift() {
6036 // Check if we have a value
6037 const remove = this._first;
6038 if (!remove) return null
6039
6040 // If we do, remove it and relink things
6041 this._first = remove.next;
6042 if (this._first) this._first.prev = null;
6043 this._last = this._first ? this._last : null;
6044 return remove.value
6045 }
6046 }
6047
6048 const Animator = {
6049 nextDraw: null,
6050 frames: new Queue(),
6051 timeouts: new Queue(),
6052 immediates: new Queue(),
6053 timer: () => globals.window.performance || globals.window.Date,
6054 transforms: [],
6055
6056 frame(fn) {
6057 // Store the node
6058 const node = Animator.frames.push({ run: fn });
6059
6060 // Request an animation frame if we don't have one
6061 if (Animator.nextDraw === null) {
6062 Animator.nextDraw = globals.window.requestAnimationFrame(Animator._draw);
6063 }
6064
6065 // Return the node so we can remove it easily
6066 return node
6067 },
6068
6069 timeout(fn, delay) {
6070 delay = delay || 0;
6071
6072 // Work out when the event should fire
6073 const time = Animator.timer().now() + delay;
6074
6075 // Add the timeout to the end of the queue
6076 const node = Animator.timeouts.push({ run: fn, time: time });
6077
6078 // Request another animation frame if we need one
6079 if (Animator.nextDraw === null) {
6080 Animator.nextDraw = globals.window.requestAnimationFrame(Animator._draw);
6081 }
6082
6083 return node
6084 },
6085
6086 immediate(fn) {
6087 // Add the immediate fn to the end of the queue
6088 const node = Animator.immediates.push(fn);
6089 // Request another animation frame if we need one
6090 if (Animator.nextDraw === null) {
6091 Animator.nextDraw = globals.window.requestAnimationFrame(Animator._draw);
6092 }
6093
6094 return node
6095 },
6096
6097 cancelFrame(node) {
6098 node != null && Animator.frames.remove(node);
6099 },
6100
6101 clearTimeout(node) {
6102 node != null && Animator.timeouts.remove(node);
6103 },
6104
6105 cancelImmediate(node) {
6106 node != null && Animator.immediates.remove(node);
6107 },
6108
6109 _draw(now) {
6110 // Run all the timeouts we can run, if they are not ready yet, add them
6111 // to the end of the queue immediately! (bad timeouts!!! [sarcasm])
6112 let nextTimeout = null;
6113 const lastTimeout = Animator.timeouts.last();
6114 while ((nextTimeout = Animator.timeouts.shift())) {
6115 // Run the timeout if its time, or push it to the end
6116 if (now >= nextTimeout.time) {
6117 nextTimeout.run();
6118 } else {
6119 Animator.timeouts.push(nextTimeout);
6120 }
6121
6122 // If we hit the last item, we should stop shifting out more items
6123 if (nextTimeout === lastTimeout) break
6124 }
6125
6126 // Run all of the animation frames
6127 let nextFrame = null;
6128 const lastFrame = Animator.frames.last();
6129 while (nextFrame !== lastFrame && (nextFrame = Animator.frames.shift())) {
6130 nextFrame.run(now);
6131 }
6132
6133 let nextImmediate = null;
6134 while ((nextImmediate = Animator.immediates.shift())) {
6135 nextImmediate();
6136 }
6137
6138 // If we have remaining timeouts or frames, draw until we don't anymore
6139 Animator.nextDraw =
6140 Animator.timeouts.first() || Animator.frames.first()
6141 ? globals.window.requestAnimationFrame(Animator._draw)
6142 : null;
6143 }
6144 };
6145
6146 const makeSchedule = function (runnerInfo) {
6147 const start = runnerInfo.start;
6148 const duration = runnerInfo.runner.duration();
6149 const end = start + duration;
6150 return {
6151 start: start,
6152 duration: duration,
6153 end: end,
6154 runner: runnerInfo.runner
6155 }
6156 };
6157
6158 const defaultSource = function () {
6159 const w = globals.window;
6160 return (w.performance || w.Date).now()
6161 };
6162
6163 class Timeline extends EventTarget {
6164 // Construct a new timeline on the given element
6165 constructor(timeSource = defaultSource) {
6166 super();
6167
6168 this._timeSource = timeSource;
6169
6170 // terminate resets all variables to their initial state
6171 this.terminate();
6172 }
6173
6174 active() {
6175 return !!this._nextFrame
6176 }
6177
6178 finish() {
6179 // Go to end and pause
6180 this.time(this.getEndTimeOfTimeline() + 1);
6181 return this.pause()
6182 }
6183
6184 // Calculates the end of the timeline
6185 getEndTime() {
6186 const lastRunnerInfo = this.getLastRunnerInfo();
6187 const lastDuration = lastRunnerInfo ? lastRunnerInfo.runner.duration() : 0;
6188 const lastStartTime = lastRunnerInfo ? lastRunnerInfo.start : this._time;
6189 return lastStartTime + lastDuration
6190 }
6191
6192 getEndTimeOfTimeline() {
6193 const endTimes = this._runners.map((i) => i.start + i.runner.duration());
6194 return Math.max(0, ...endTimes)
6195 }
6196
6197 getLastRunnerInfo() {
6198 return this.getRunnerInfoById(this._lastRunnerId)
6199 }
6200
6201 getRunnerInfoById(id) {
6202 return this._runners[this._runnerIds.indexOf(id)] || null
6203 }
6204
6205 pause() {
6206 this._paused = true;
6207 return this._continue()
6208 }
6209
6210 persist(dtOrForever) {
6211 if (dtOrForever == null) return this._persist
6212 this._persist = dtOrForever;
6213 return this
6214 }
6215
6216 play() {
6217 // Now make sure we are not paused and continue the animation
6218 this._paused = false;
6219 return this.updateTime()._continue()
6220 }
6221
6222 reverse(yes) {
6223 const currentSpeed = this.speed();
6224 if (yes == null) return this.speed(-currentSpeed)
6225
6226 const positive = Math.abs(currentSpeed);
6227 return this.speed(yes ? -positive : positive)
6228 }
6229
6230 // schedules a runner on the timeline
6231 schedule(runner, delay, when) {
6232 if (runner == null) {
6233 return this._runners.map(makeSchedule)
6234 }
6235
6236 // The start time for the next animation can either be given explicitly,
6237 // derived from the current timeline time or it can be relative to the
6238 // last start time to chain animations directly
6239
6240 let absoluteStartTime = 0;
6241 const endTime = this.getEndTime();
6242 delay = delay || 0;
6243
6244 // Work out when to start the animation
6245 if (when == null || when === 'last' || when === 'after') {
6246 // Take the last time and increment
6247 absoluteStartTime = endTime;
6248 } else if (when === 'absolute' || when === 'start') {
6249 absoluteStartTime = delay;
6250 delay = 0;
6251 } else if (when === 'now') {
6252 absoluteStartTime = this._time;
6253 } else if (when === 'relative') {
6254 const runnerInfo = this.getRunnerInfoById(runner.id);
6255 if (runnerInfo) {
6256 absoluteStartTime = runnerInfo.start + delay;
6257 delay = 0;
6258 }
6259 } else if (when === 'with-last') {
6260 const lastRunnerInfo = this.getLastRunnerInfo();
6261 const lastStartTime = lastRunnerInfo ? lastRunnerInfo.start : this._time;
6262 absoluteStartTime = lastStartTime;
6263 } else {
6264 throw new Error('Invalid value for the "when" parameter')
6265 }
6266
6267 // Manage runner
6268 runner.unschedule();
6269 runner.timeline(this);
6270
6271 const persist = runner.persist();
6272 const runnerInfo = {
6273 persist: persist === null ? this._persist : persist,
6274 start: absoluteStartTime + delay,
6275 runner
6276 };
6277
6278 this._lastRunnerId = runner.id;
6279
6280 this._runners.push(runnerInfo);
6281 this._runners.sort((a, b) => a.start - b.start);
6282 this._runnerIds = this._runners.map((info) => info.runner.id);
6283
6284 this.updateTime()._continue();
6285 return this
6286 }
6287
6288 seek(dt) {
6289 return this.time(this._time + dt)
6290 }
6291
6292 source(fn) {
6293 if (fn == null) return this._timeSource
6294 this._timeSource = fn;
6295 return this
6296 }
6297
6298 speed(speed) {
6299 if (speed == null) return this._speed
6300 this._speed = speed;
6301 return this
6302 }
6303
6304 stop() {
6305 // Go to start and pause
6306 this.time(0);
6307 return this.pause()
6308 }
6309
6310 time(time) {
6311 if (time == null) return this._time
6312 this._time = time;
6313 return this._continue(true)
6314 }
6315
6316 // Remove the runner from this timeline
6317 unschedule(runner) {
6318 const index = this._runnerIds.indexOf(runner.id);
6319 if (index < 0) return this
6320
6321 this._runners.splice(index, 1);
6322 this._runnerIds.splice(index, 1);
6323
6324 runner.timeline(null);
6325 return this
6326 }
6327
6328 // Makes sure, that after pausing the time doesn't jump
6329 updateTime() {
6330 if (!this.active()) {
6331 this._lastSourceTime = this._timeSource();
6332 }
6333 return this
6334 }
6335
6336 // Checks if we are running and continues the animation
6337 _continue(immediateStep = false) {
6338 Animator.cancelFrame(this._nextFrame);
6339 this._nextFrame = null;
6340
6341 if (immediateStep) return this._stepImmediate()
6342 if (this._paused) return this
6343
6344 this._nextFrame = Animator.frame(this._step);
6345 return this
6346 }
6347
6348 _stepFn(immediateStep = false) {
6349 // Get the time delta from the last time and update the time
6350 const time = this._timeSource();
6351 let dtSource = time - this._lastSourceTime;
6352
6353 if (immediateStep) dtSource = 0;
6354
6355 const dtTime = this._speed * dtSource + (this._time - this._lastStepTime);
6356 this._lastSourceTime = time;
6357
6358 // Only update the time if we use the timeSource.
6359 // Otherwise use the current time
6360 if (!immediateStep) {
6361 // Update the time
6362 this._time += dtTime;
6363 this._time = this._time < 0 ? 0 : this._time;
6364 }
6365 this._lastStepTime = this._time;
6366 this.fire('time', this._time);
6367
6368 // This is for the case that the timeline was seeked so that the time
6369 // is now before the startTime of the runner. That is why we need to set
6370 // the runner to position 0
6371
6372 // FIXME:
6373 // However, resetting in insertion order leads to bugs. Considering the case,
6374 // where 2 runners change the same attribute but in different times,
6375 // resetting both of them will lead to the case where the later defined
6376 // runner always wins the reset even if the other runner started earlier
6377 // and therefore should win the attribute battle
6378 // this can be solved by resetting them backwards
6379 for (let k = this._runners.length; k--; ) {
6380 // Get and run the current runner and ignore it if its inactive
6381 const runnerInfo = this._runners[k];
6382 const runner = runnerInfo.runner;
6383
6384 // Make sure that we give the actual difference
6385 // between runner start time and now
6386 const dtToStart = this._time - runnerInfo.start;
6387
6388 // Dont run runner if not started yet
6389 // and try to reset it
6390 if (dtToStart <= 0) {
6391 runner.reset();
6392 }
6393 }
6394
6395 // Run all of the runners directly
6396 let runnersLeft = false;
6397 for (let i = 0, len = this._runners.length; i < len; i++) {
6398 // Get and run the current runner and ignore it if its inactive
6399 const runnerInfo = this._runners[i];
6400 const runner = runnerInfo.runner;
6401 let dt = dtTime;
6402
6403 // Make sure that we give the actual difference
6404 // between runner start time and now
6405 const dtToStart = this._time - runnerInfo.start;
6406
6407 // Dont run runner if not started yet
6408 if (dtToStart <= 0) {
6409 runnersLeft = true;
6410 continue
6411 } else if (dtToStart < dt) {
6412 // Adjust dt to make sure that animation is on point
6413 dt = dtToStart;
6414 }
6415
6416 if (!runner.active()) continue
6417
6418 // If this runner is still going, signal that we need another animation
6419 // frame, otherwise, remove the completed runner
6420 const finished = runner.step(dt).done;
6421 if (!finished) {
6422 runnersLeft = true;
6423 // continue
6424 } else if (runnerInfo.persist !== true) {
6425 // runner is finished. And runner might get removed
6426 const endTime = runner.duration() - runner.time() + this._time;
6427
6428 if (endTime + runnerInfo.persist < this._time) {
6429 // Delete runner and correct index
6430 runner.unschedule();
6431 --i;
6432 --len;
6433 }
6434 }
6435 }
6436
6437 // Basically: we continue when there are runners right from us in time
6438 // when -->, and when runners are left from us when <--
6439 if (
6440 (runnersLeft && !(this._speed < 0 && this._time === 0)) ||
6441 (this._runnerIds.length && this._speed < 0 && this._time > 0)
6442 ) {
6443 this._continue();
6444 } else {
6445 this.pause();
6446 this.fire('finished');
6447 }
6448
6449 return this
6450 }
6451
6452 terminate() {
6453 // cleanup memory
6454
6455 // Store the timing variables
6456 this._startTime = 0;
6457 this._speed = 1.0;
6458
6459 // Determines how long a runner is hold in memory. Can be a dt or true/false
6460 this._persist = 0;
6461
6462 // Keep track of the running animations and their starting parameters
6463 this._nextFrame = null;
6464 this._paused = true;
6465 this._runners = [];
6466 this._runnerIds = [];
6467 this._lastRunnerId = -1;
6468 this._time = 0;
6469 this._lastSourceTime = 0;
6470 this._lastStepTime = 0;
6471
6472 // Make sure that step is always called in class context
6473 this._step = this._stepFn.bind(this, false);
6474 this._stepImmediate = this._stepFn.bind(this, true);
6475 }
6476 }
6477
6478 registerMethods({
6479 Element: {
6480 timeline: function (timeline) {
6481 if (timeline == null) {
6482 this._timeline = this._timeline || new Timeline();
6483 return this._timeline
6484 } else {
6485 this._timeline = timeline;
6486 return this
6487 }
6488 }
6489 }
6490 });
6491
6492 class Runner extends EventTarget {
6493 constructor(options) {
6494 super();
6495
6496 // Store a unique id on the runner, so that we can identify it later
6497 this.id = Runner.id++;
6498
6499 // Ensure a default value
6500 options = options == null ? timeline.duration : options;
6501
6502 // Ensure that we get a controller
6503 options = typeof options === 'function' ? new Controller(options) : options;
6504
6505 // Declare all of the variables
6506 this._element = null;
6507 this._timeline = null;
6508 this.done = false;
6509 this._queue = [];
6510
6511 // Work out the stepper and the duration
6512 this._duration = typeof options === 'number' && options;
6513 this._isDeclarative = options instanceof Controller;
6514 this._stepper = this._isDeclarative ? options : new Ease();
6515
6516 // We copy the current values from the timeline because they can change
6517 this._history = {};
6518
6519 // Store the state of the runner
6520 this.enabled = true;
6521 this._time = 0;
6522 this._lastTime = 0;
6523
6524 // At creation, the runner is in reset state
6525 this._reseted = true;
6526
6527 // Save transforms applied to this runner
6528 this.transforms = new Matrix();
6529 this.transformId = 1;
6530
6531 // Looping variables
6532 this._haveReversed = false;
6533 this._reverse = false;
6534 this._loopsDone = 0;
6535 this._swing = false;
6536 this._wait = 0;
6537 this._times = 1;
6538
6539 this._frameId = null;
6540
6541 // Stores how long a runner is stored after being done
6542 this._persist = this._isDeclarative ? true : null;
6543 }
6544
6545 static sanitise(duration, delay, when) {
6546 // Initialise the default parameters
6547 let times = 1;
6548 let swing = false;
6549 let wait = 0;
6550 duration = duration ?? timeline.duration;
6551 delay = delay ?? timeline.delay;
6552 when = when || 'last';
6553
6554 // If we have an object, unpack the values
6555 if (typeof duration === 'object' && !(duration instanceof Stepper)) {
6556 delay = duration.delay ?? delay;
6557 when = duration.when ?? when;
6558 swing = duration.swing || swing;
6559 times = duration.times ?? times;
6560 wait = duration.wait ?? wait;
6561 duration = duration.duration ?? timeline.duration;
6562 }
6563
6564 return {
6565 duration: duration,
6566 delay: delay,
6567 swing: swing,
6568 times: times,
6569 wait: wait,
6570 when: when
6571 }
6572 }
6573
6574 active(enabled) {
6575 if (enabled == null) return this.enabled
6576 this.enabled = enabled;
6577 return this
6578 }
6579
6580 /*
6581 Private Methods
6582 ===============
6583 Methods that shouldn't be used externally
6584 */
6585 addTransform(transform) {
6586 this.transforms.lmultiplyO(transform);
6587 return this
6588 }
6589
6590 after(fn) {
6591 return this.on('finished', fn)
6592 }
6593
6594 animate(duration, delay, when) {
6595 const o = Runner.sanitise(duration, delay, when);
6596 const runner = new Runner(o.duration);
6597 if (this._timeline) runner.timeline(this._timeline);
6598 if (this._element) runner.element(this._element);
6599 return runner.loop(o).schedule(o.delay, o.when)
6600 }
6601
6602 clearTransform() {
6603 this.transforms = new Matrix();
6604 return this
6605 }
6606
6607 // TODO: Keep track of all transformations so that deletion is faster
6608 clearTransformsFromQueue() {
6609 if (
6610 !this.done ||
6611 !this._timeline ||
6612 !this._timeline._runnerIds.includes(this.id)
6613 ) {
6614 this._queue = this._queue.filter((item) => {
6615 return !item.isTransform
6616 });
6617 }
6618 }
6619
6620 delay(delay) {
6621 return this.animate(0, delay)
6622 }
6623
6624 duration() {
6625 return this._times * (this._wait + this._duration) - this._wait
6626 }
6627
6628 during(fn) {
6629 return this.queue(null, fn)
6630 }
6631
6632 ease(fn) {
6633 this._stepper = new Ease(fn);
6634 return this
6635 }
6636 /*
6637 Runner Definitions
6638 ==================
6639 These methods help us define the runtime behaviour of the Runner or they
6640 help us make new runners from the current runner
6641 */
6642
6643 element(element) {
6644 if (element == null) return this._element
6645 this._element = element;
6646 element._prepareRunner();
6647 return this
6648 }
6649
6650 finish() {
6651 return this.step(Infinity)
6652 }
6653
6654 loop(times, swing, wait) {
6655 // Deal with the user passing in an object
6656 if (typeof times === 'object') {
6657 swing = times.swing;
6658 wait = times.wait;
6659 times = times.times;
6660 }
6661
6662 // Sanitise the values and store them
6663 this._times = times || Infinity;
6664 this._swing = swing || false;
6665 this._wait = wait || 0;
6666
6667 // Allow true to be passed
6668 if (this._times === true) {
6669 this._times = Infinity;
6670 }
6671
6672 return this
6673 }
6674
6675 loops(p) {
6676 const loopDuration = this._duration + this._wait;
6677 if (p == null) {
6678 const loopsDone = Math.floor(this._time / loopDuration);
6679 const relativeTime = this._time - loopsDone * loopDuration;
6680 const position = relativeTime / this._duration;
6681 return Math.min(loopsDone + position, this._times)
6682 }
6683 const whole = Math.floor(p);
6684 const partial = p % 1;
6685 const time = loopDuration * whole + this._duration * partial;
6686 return this.time(time)
6687 }
6688
6689 persist(dtOrForever) {
6690 if (dtOrForever == null) return this._persist
6691 this._persist = dtOrForever;
6692 return this
6693 }
6694
6695 position(p) {
6696 // Get all of the variables we need
6697 const x = this._time;
6698 const d = this._duration;
6699 const w = this._wait;
6700 const t = this._times;
6701 const s = this._swing;
6702 const r = this._reverse;
6703 let position;
6704
6705 if (p == null) {
6706 /*
6707 This function converts a time to a position in the range [0, 1]
6708 The full explanation can be found in this desmos demonstration
6709 https://www.desmos.com/calculator/u4fbavgche
6710 The logic is slightly simplified here because we can use booleans
6711 */
6712
6713 // Figure out the value without thinking about the start or end time
6714 const f = function (x) {
6715 const swinging = s * Math.floor((x % (2 * (w + d))) / (w + d));
6716 const backwards = (swinging && !r) || (!swinging && r);
6717 const uncliped =
6718 (Math.pow(-1, backwards) * (x % (w + d))) / d + backwards;
6719 const clipped = Math.max(Math.min(uncliped, 1), 0);
6720 return clipped
6721 };
6722
6723 // Figure out the value by incorporating the start time
6724 const endTime = t * (w + d) - w;
6725 position =
6726 x <= 0
6727 ? Math.round(f(1e-5))
6728 : x < endTime
6729 ? f(x)
6730 : Math.round(f(endTime - 1e-5));
6731 return position
6732 }
6733
6734 // Work out the loops done and add the position to the loops done
6735 const loopsDone = Math.floor(this.loops());
6736 const swingForward = s && loopsDone % 2 === 0;
6737 const forwards = (swingForward && !r) || (r && swingForward);
6738 position = loopsDone + (forwards ? p : 1 - p);
6739 return this.loops(position)
6740 }
6741
6742 progress(p) {
6743 if (p == null) {
6744 return Math.min(1, this._time / this.duration())
6745 }
6746 return this.time(p * this.duration())
6747 }
6748
6749 /*
6750 Basic Functionality
6751 ===================
6752 These methods allow us to attach basic functions to the runner directly
6753 */
6754 queue(initFn, runFn, retargetFn, isTransform) {
6755 this._queue.push({
6756 initialiser: initFn || noop,
6757 runner: runFn || noop,
6758 retarget: retargetFn,
6759 isTransform: isTransform,
6760 initialised: false,
6761 finished: false
6762 });
6763 const timeline = this.timeline();
6764 timeline && this.timeline()._continue();
6765 return this
6766 }
6767
6768 reset() {
6769 if (this._reseted) return this
6770 this.time(0);
6771 this._reseted = true;
6772 return this
6773 }
6774
6775 reverse(reverse) {
6776 this._reverse = reverse == null ? !this._reverse : reverse;
6777 return this
6778 }
6779
6780 schedule(timeline, delay, when) {
6781 // The user doesn't need to pass a timeline if we already have one
6782 if (!(timeline instanceof Timeline)) {
6783 when = delay;
6784 delay = timeline;
6785 timeline = this.timeline();
6786 }
6787
6788 // If there is no timeline, yell at the user...
6789 if (!timeline) {
6790 throw Error('Runner cannot be scheduled without timeline')
6791 }
6792
6793 // Schedule the runner on the timeline provided
6794 timeline.schedule(this, delay, when);
6795 return this
6796 }
6797
6798 step(dt) {
6799 // If we are inactive, this stepper just gets skipped
6800 if (!this.enabled) return this
6801
6802 // Update the time and get the new position
6803 dt = dt == null ? 16 : dt;
6804 this._time += dt;
6805 const position = this.position();
6806
6807 // Figure out if we need to run the stepper in this frame
6808 const running = this._lastPosition !== position && this._time >= 0;
6809 this._lastPosition = position;
6810
6811 // Figure out if we just started
6812 const duration = this.duration();
6813 const justStarted = this._lastTime <= 0 && this._time > 0;
6814 const justFinished = this._lastTime < duration && this._time >= duration;
6815
6816 this._lastTime = this._time;
6817 if (justStarted) {
6818 this.fire('start', this);
6819 }
6820
6821 // Work out if the runner is finished set the done flag here so animations
6822 // know, that they are running in the last step (this is good for
6823 // transformations which can be merged)
6824 const declarative = this._isDeclarative;
6825 this.done = !declarative && !justFinished && this._time >= duration;
6826
6827 // Runner is running. So its not in reset state anymore
6828 this._reseted = false;
6829
6830 let converged = false;
6831 // Call initialise and the run function
6832 if (running || declarative) {
6833 this._initialise(running);
6834
6835 // clear the transforms on this runner so they dont get added again and again
6836 this.transforms = new Matrix();
6837 converged = this._run(declarative ? dt : position);
6838
6839 this.fire('step', this);
6840 }
6841 // correct the done flag here
6842 // declarative animations itself know when they converged
6843 this.done = this.done || (converged && declarative);
6844 if (justFinished) {
6845 this.fire('finished', this);
6846 }
6847 return this
6848 }
6849
6850 /*
6851 Runner animation methods
6852 ========================
6853 Control how the animation plays
6854 */
6855 time(time) {
6856 if (time == null) {
6857 return this._time
6858 }
6859 const dt = time - this._time;
6860 this.step(dt);
6861 return this
6862 }
6863
6864 timeline(timeline) {
6865 // check explicitly for undefined so we can set the timeline to null
6866 if (typeof timeline === 'undefined') return this._timeline
6867 this._timeline = timeline;
6868 return this
6869 }
6870
6871 unschedule() {
6872 const timeline = this.timeline();
6873 timeline && timeline.unschedule(this);
6874 return this
6875 }
6876
6877 // Run each initialise function in the runner if required
6878 _initialise(running) {
6879 // If we aren't running, we shouldn't initialise when not declarative
6880 if (!running && !this._isDeclarative) return
6881
6882 // Loop through all of the initialisers
6883 for (let i = 0, len = this._queue.length; i < len; ++i) {
6884 // Get the current initialiser
6885 const current = this._queue[i];
6886
6887 // Determine whether we need to initialise
6888 const needsIt = this._isDeclarative || (!current.initialised && running);
6889 running = !current.finished;
6890
6891 // Call the initialiser if we need to
6892 if (needsIt && running) {
6893 current.initialiser.call(this);
6894 current.initialised = true;
6895 }
6896 }
6897 }
6898
6899 // Save a morpher to the morpher list so that we can retarget it later
6900 _rememberMorpher(method, morpher) {
6901 this._history[method] = {
6902 morpher: morpher,
6903 caller: this._queue[this._queue.length - 1]
6904 };
6905
6906 // We have to resume the timeline in case a controller
6907 // is already done without being ever run
6908 // This can happen when e.g. this is done:
6909 // anim = el.animate(new SVG.Spring)
6910 // and later
6911 // anim.move(...)
6912 if (this._isDeclarative) {
6913 const timeline = this.timeline();
6914 timeline && timeline.play();
6915 }
6916 }
6917
6918 // Try to set the target for a morpher if the morpher exists, otherwise
6919 // Run each run function for the position or dt given
6920 _run(positionOrDt) {
6921 // Run all of the _queue directly
6922 let allfinished = true;
6923 for (let i = 0, len = this._queue.length; i < len; ++i) {
6924 // Get the current function to run
6925 const current = this._queue[i];
6926
6927 // Run the function if its not finished, we keep track of the finished
6928 // flag for the sake of declarative _queue
6929 const converged = current.runner.call(this, positionOrDt);
6930 current.finished = current.finished || converged === true;
6931 allfinished = allfinished && current.finished;
6932 }
6933
6934 // We report when all of the constructors are finished
6935 return allfinished
6936 }
6937
6938 // do nothing and return false
6939 _tryRetarget(method, target, extra) {
6940 if (this._history[method]) {
6941 // if the last method wasn't even initialised, throw it away
6942 if (!this._history[method].caller.initialised) {
6943 const index = this._queue.indexOf(this._history[method].caller);
6944 this._queue.splice(index, 1);
6945 return false
6946 }
6947
6948 // for the case of transformations, we use the special retarget function
6949 // which has access to the outer scope
6950 if (this._history[method].caller.retarget) {
6951 this._history[method].caller.retarget.call(this, target, extra);
6952 // for everything else a simple morpher change is sufficient
6953 } else {
6954 this._history[method].morpher.to(target);
6955 }
6956
6957 this._history[method].caller.finished = false;
6958 const timeline = this.timeline();
6959 timeline && timeline.play();
6960 return true
6961 }
6962 return false
6963 }
6964 }
6965
6966 Runner.id = 0;
6967
6968 class FakeRunner {
6969 constructor(transforms = new Matrix(), id = -1, done = true) {
6970 this.transforms = transforms;
6971 this.id = id;
6972 this.done = done;
6973 }
6974
6975 clearTransformsFromQueue() {}
6976 }
6977
6978 extend([Runner, FakeRunner], {
6979 mergeWith(runner) {
6980 return new FakeRunner(
6981 runner.transforms.lmultiply(this.transforms),
6982 runner.id
6983 )
6984 }
6985 });
6986
6987 // FakeRunner.emptyRunner = new FakeRunner()
6988
6989 const lmultiply = (last, curr) => last.lmultiplyO(curr);
6990 const getRunnerTransform = (runner) => runner.transforms;
6991
6992 function mergeTransforms() {
6993 // Find the matrix to apply to the element and apply it
6994 const runners = this._transformationRunners.runners;
6995 const netTransform = runners
6996 .map(getRunnerTransform)
6997 .reduce(lmultiply, new Matrix());
6998
6999 this.transform(netTransform);
7000
7001 this._transformationRunners.merge();
7002
7003 if (this._transformationRunners.length() === 1) {
7004 this._frameId = null;
7005 }
7006 }
7007
7008 class RunnerArray {
7009 constructor() {
7010 this.runners = [];
7011 this.ids = [];
7012 }
7013
7014 add(runner) {
7015 if (this.runners.includes(runner)) return
7016 const id = runner.id + 1;
7017
7018 this.runners.push(runner);
7019 this.ids.push(id);
7020
7021 return this
7022 }
7023
7024 clearBefore(id) {
7025 const deleteCnt = this.ids.indexOf(id + 1) || 1;
7026 this.ids.splice(0, deleteCnt, 0);
7027 this.runners
7028 .splice(0, deleteCnt, new FakeRunner())
7029 .forEach((r) => r.clearTransformsFromQueue());
7030 return this
7031 }
7032
7033 edit(id, newRunner) {
7034 const index = this.ids.indexOf(id + 1);
7035 this.ids.splice(index, 1, id + 1);
7036 this.runners.splice(index, 1, newRunner);
7037 return this
7038 }
7039
7040 getByID(id) {
7041 return this.runners[this.ids.indexOf(id + 1)]
7042 }
7043
7044 length() {
7045 return this.ids.length
7046 }
7047
7048 merge() {
7049 let lastRunner = null;
7050 for (let i = 0; i < this.runners.length; ++i) {
7051 const runner = this.runners[i];
7052
7053 const condition =
7054 lastRunner &&
7055 runner.done &&
7056 lastRunner.done &&
7057 // don't merge runner when persisted on timeline
7058 (!runner._timeline ||
7059 !runner._timeline._runnerIds.includes(runner.id)) &&
7060 (!lastRunner._timeline ||
7061 !lastRunner._timeline._runnerIds.includes(lastRunner.id));
7062
7063 if (condition) {
7064 // the +1 happens in the function
7065 this.remove(runner.id);
7066 const newRunner = runner.mergeWith(lastRunner);
7067 this.edit(lastRunner.id, newRunner);
7068 lastRunner = newRunner;
7069 --i;
7070 } else {
7071 lastRunner = runner;
7072 }
7073 }
7074
7075 return this
7076 }
7077
7078 remove(id) {
7079 const index = this.ids.indexOf(id + 1);
7080 this.ids.splice(index, 1);
7081 this.runners.splice(index, 1);
7082 return this
7083 }
7084 }
7085
7086 registerMethods({
7087 Element: {
7088 animate(duration, delay, when) {
7089 const o = Runner.sanitise(duration, delay, when);
7090 const timeline = this.timeline();
7091 return new Runner(o.duration)
7092 .loop(o)
7093 .element(this)
7094 .timeline(timeline.play())
7095 .schedule(o.delay, o.when)
7096 },
7097
7098 delay(by, when) {
7099 return this.animate(0, by, when)
7100 },
7101
7102 // this function searches for all runners on the element and deletes the ones
7103 // which run before the current one. This is because absolute transformations
7104 // overwrite anything anyway so there is no need to waste time computing
7105 // other runners
7106 _clearTransformRunnersBefore(currentRunner) {
7107 this._transformationRunners.clearBefore(currentRunner.id);
7108 },
7109
7110 _currentTransform(current) {
7111 return (
7112 this._transformationRunners.runners
7113 // we need the equal sign here to make sure, that also transformations
7114 // on the same runner which execute before the current transformation are
7115 // taken into account
7116 .filter((runner) => runner.id <= current.id)
7117 .map(getRunnerTransform)
7118 .reduce(lmultiply, new Matrix())
7119 )
7120 },
7121
7122 _addRunner(runner) {
7123 this._transformationRunners.add(runner);
7124
7125 // Make sure that the runner merge is executed at the very end of
7126 // all Animator functions. That is why we use immediate here to execute
7127 // the merge right after all frames are run
7128 Animator.cancelImmediate(this._frameId);
7129 this._frameId = Animator.immediate(mergeTransforms.bind(this));
7130 },
7131
7132 _prepareRunner() {
7133 if (this._frameId == null) {
7134 this._transformationRunners = new RunnerArray().add(
7135 new FakeRunner(new Matrix(this))
7136 );
7137 }
7138 }
7139 }
7140 });
7141
7142 // Will output the elements from array A that are not in the array B
7143 const difference = (a, b) => a.filter((x) => !b.includes(x));
7144
7145 extend(Runner, {
7146 attr(a, v) {
7147 return this.styleAttr('attr', a, v)
7148 },
7149
7150 // Add animatable styles
7151 css(s, v) {
7152 return this.styleAttr('css', s, v)
7153 },
7154
7155 styleAttr(type, nameOrAttrs, val) {
7156 if (typeof nameOrAttrs === 'string') {
7157 return this.styleAttr(type, { [nameOrAttrs]: val })
7158 }
7159
7160 let attrs = nameOrAttrs;
7161 if (this._tryRetarget(type, attrs)) return this
7162
7163 let morpher = new Morphable(this._stepper).to(attrs);
7164 let keys = Object.keys(attrs);
7165
7166 this.queue(
7167 function () {
7168 morpher = morpher.from(this.element()[type](keys));
7169 },
7170 function (pos) {
7171 this.element()[type](morpher.at(pos).valueOf());
7172 return morpher.done()
7173 },
7174 function (newToAttrs) {
7175 // Check if any new keys were added
7176 const newKeys = Object.keys(newToAttrs);
7177 const differences = difference(newKeys, keys);
7178
7179 // If their are new keys, initialize them and add them to morpher
7180 if (differences.length) {
7181 // Get the values
7182 const addedFromAttrs = this.element()[type](differences);
7183
7184 // Get the already initialized values
7185 const oldFromAttrs = new ObjectBag(morpher.from()).valueOf();
7186
7187 // Merge old and new
7188 Object.assign(oldFromAttrs, addedFromAttrs);
7189 morpher.from(oldFromAttrs);
7190 }
7191
7192 // Get the object from the morpher
7193 const oldToAttrs = new ObjectBag(morpher.to()).valueOf();
7194
7195 // Merge in new attributes
7196 Object.assign(oldToAttrs, newToAttrs);
7197
7198 // Change morpher target
7199 morpher.to(oldToAttrs);
7200
7201 // Make sure that we save the work we did so we don't need it to do again
7202 keys = newKeys;
7203 attrs = newToAttrs;
7204 }
7205 );
7206
7207 this._rememberMorpher(type, morpher);
7208 return this
7209 },
7210
7211 zoom(level, point) {
7212 if (this._tryRetarget('zoom', level, point)) return this
7213
7214 let morpher = new Morphable(this._stepper).to(new SVGNumber(level));
7215
7216 this.queue(
7217 function () {
7218 morpher = morpher.from(this.element().zoom());
7219 },
7220 function (pos) {
7221 this.element().zoom(morpher.at(pos), point);
7222 return morpher.done()
7223 },
7224 function (newLevel, newPoint) {
7225 point = newPoint;
7226 morpher.to(newLevel);
7227 }
7228 );
7229
7230 this._rememberMorpher('zoom', morpher);
7231 return this
7232 },
7233
7234 /**
7235 ** absolute transformations
7236 **/
7237
7238 //
7239 // M v -----|-----(D M v = F v)------|-----> T v
7240 //
7241 // 1. define the final state (T) and decompose it (once)
7242 // t = [tx, ty, the, lam, sy, sx]
7243 // 2. on every frame: pull the current state of all previous transforms
7244 // (M - m can change)
7245 // and then write this as m = [tx0, ty0, the0, lam0, sy0, sx0]
7246 // 3. Find the interpolated matrix F(pos) = m + pos * (t - m)
7247 // - Note F(0) = M
7248 // - Note F(1) = T
7249 // 4. Now you get the delta matrix as a result: D = F * inv(M)
7250
7251 transform(transforms, relative, affine) {
7252 // If we have a declarative function, we should retarget it if possible
7253 relative = transforms.relative || relative;
7254 if (
7255 this._isDeclarative &&
7256 !relative &&
7257 this._tryRetarget('transform', transforms)
7258 ) {
7259 return this
7260 }
7261
7262 // Parse the parameters
7263 const isMatrix = Matrix.isMatrixLike(transforms);
7264 affine =
7265 transforms.affine != null
7266 ? transforms.affine
7267 : affine != null
7268 ? affine
7269 : !isMatrix;
7270
7271 // Create a morpher and set its type
7272 const morpher = new Morphable(this._stepper).type(
7273 affine ? TransformBag : Matrix
7274 );
7275
7276 let origin;
7277 let element;
7278 let current;
7279 let currentAngle;
7280 let startTransform;
7281
7282 function setup() {
7283 // make sure element and origin is defined
7284 element = element || this.element();
7285 origin = origin || getOrigin(transforms, element);
7286
7287 startTransform = new Matrix(relative ? undefined : element);
7288
7289 // add the runner to the element so it can merge transformations
7290 element._addRunner(this);
7291
7292 // Deactivate all transforms that have run so far if we are absolute
7293 if (!relative) {
7294 element._clearTransformRunnersBefore(this);
7295 }
7296 }
7297
7298 function run(pos) {
7299 // clear all other transforms before this in case something is saved
7300 // on this runner. We are absolute. We dont need these!
7301 if (!relative) this.clearTransform();
7302
7303 const { x, y } = new Point(origin).transform(
7304 element._currentTransform(this)
7305 );
7306
7307 let target = new Matrix({ ...transforms, origin: [x, y] });
7308 let start = this._isDeclarative && current ? current : startTransform;
7309
7310 if (affine) {
7311 target = target.decompose(x, y);
7312 start = start.decompose(x, y);
7313
7314 // Get the current and target angle as it was set
7315 const rTarget = target.rotate;
7316 const rCurrent = start.rotate;
7317
7318 // Figure out the shortest path to rotate directly
7319 const possibilities = [rTarget - 360, rTarget, rTarget + 360];
7320 const distances = possibilities.map((a) => Math.abs(a - rCurrent));
7321 const shortest = Math.min(...distances);
7322 const index = distances.indexOf(shortest);
7323 target.rotate = possibilities[index];
7324 }
7325
7326 if (relative) {
7327 // we have to be careful here not to overwrite the rotation
7328 // with the rotate method of Matrix
7329 if (!isMatrix) {
7330 target.rotate = transforms.rotate || 0;
7331 }
7332 if (this._isDeclarative && currentAngle) {
7333 start.rotate = currentAngle;
7334 }
7335 }
7336
7337 morpher.from(start);
7338 morpher.to(target);
7339
7340 const affineParameters = morpher.at(pos);
7341 currentAngle = affineParameters.rotate;
7342 current = new Matrix(affineParameters);
7343
7344 this.addTransform(current);
7345 element._addRunner(this);
7346 return morpher.done()
7347 }
7348
7349 function retarget(newTransforms) {
7350 // only get a new origin if it changed since the last call
7351 if (
7352 (newTransforms.origin || 'center').toString() !==
7353 (transforms.origin || 'center').toString()
7354 ) {
7355 origin = getOrigin(newTransforms, element);
7356 }
7357
7358 // overwrite the old transformations with the new ones
7359 transforms = { ...newTransforms, origin };
7360 }
7361
7362 this.queue(setup, run, retarget, true);
7363 this._isDeclarative && this._rememberMorpher('transform', morpher);
7364 return this
7365 },
7366
7367 // Animatable x-axis
7368 x(x) {
7369 return this._queueNumber('x', x)
7370 },
7371
7372 // Animatable y-axis
7373 y(y) {
7374 return this._queueNumber('y', y)
7375 },
7376
7377 ax(x) {
7378 return this._queueNumber('ax', x)
7379 },
7380
7381 ay(y) {
7382 return this._queueNumber('ay', y)
7383 },
7384
7385 dx(x = 0) {
7386 return this._queueNumberDelta('x', x)
7387 },
7388
7389 dy(y = 0) {
7390 return this._queueNumberDelta('y', y)
7391 },
7392
7393 dmove(x, y) {
7394 return this.dx(x).dy(y)
7395 },
7396
7397 _queueNumberDelta(method, to) {
7398 to = new SVGNumber(to);
7399
7400 // Try to change the target if we have this method already registered
7401 if (this._tryRetarget(method, to)) return this
7402
7403 // Make a morpher and queue the animation
7404 const morpher = new Morphable(this._stepper).to(to);
7405 let from = null;
7406 this.queue(
7407 function () {
7408 from = this.element()[method]();
7409 morpher.from(from);
7410 morpher.to(from + to);
7411 },
7412 function (pos) {
7413 this.element()[method](morpher.at(pos));
7414 return morpher.done()
7415 },
7416 function (newTo) {
7417 morpher.to(from + new SVGNumber(newTo));
7418 }
7419 );
7420
7421 // Register the morpher so that if it is changed again, we can retarget it
7422 this._rememberMorpher(method, morpher);
7423 return this
7424 },
7425
7426 _queueObject(method, to) {
7427 // Try to change the target if we have this method already registered
7428 if (this._tryRetarget(method, to)) return this
7429
7430 // Make a morpher and queue the animation
7431 const morpher = new Morphable(this._stepper).to(to);
7432 this.queue(
7433 function () {
7434 morpher.from(this.element()[method]());
7435 },
7436 function (pos) {
7437 this.element()[method](morpher.at(pos));
7438 return morpher.done()
7439 }
7440 );
7441
7442 // Register the morpher so that if it is changed again, we can retarget it
7443 this._rememberMorpher(method, morpher);
7444 return this
7445 },
7446
7447 _queueNumber(method, value) {
7448 return this._queueObject(method, new SVGNumber(value))
7449 },
7450
7451 // Animatable center x-axis
7452 cx(x) {
7453 return this._queueNumber('cx', x)
7454 },
7455
7456 // Animatable center y-axis
7457 cy(y) {
7458 return this._queueNumber('cy', y)
7459 },
7460
7461 // Add animatable move
7462 move(x, y) {
7463 return this.x(x).y(y)
7464 },
7465
7466 amove(x, y) {
7467 return this.ax(x).ay(y)
7468 },
7469
7470 // Add animatable center
7471 center(x, y) {
7472 return this.cx(x).cy(y)
7473 },
7474
7475 // Add animatable size
7476 size(width, height) {
7477 // animate bbox based size for all other elements
7478 let box;
7479
7480 if (!width || !height) {
7481 box = this._element.bbox();
7482 }
7483
7484 if (!width) {
7485 width = (box.width / box.height) * height;
7486 }
7487
7488 if (!height) {
7489 height = (box.height / box.width) * width;
7490 }
7491
7492 return this.width(width).height(height)
7493 },
7494
7495 // Add animatable width
7496 width(width) {
7497 return this._queueNumber('width', width)
7498 },
7499
7500 // Add animatable height
7501 height(height) {
7502 return this._queueNumber('height', height)
7503 },
7504
7505 // Add animatable plot
7506 plot(a, b, c, d) {
7507 // Lines can be plotted with 4 arguments
7508 if (arguments.length === 4) {
7509 return this.plot([a, b, c, d])
7510 }
7511
7512 if (this._tryRetarget('plot', a)) return this
7513
7514 const morpher = new Morphable(this._stepper)
7515 .type(this._element.MorphArray)
7516 .to(a);
7517
7518 this.queue(
7519 function () {
7520 morpher.from(this._element.array());
7521 },
7522 function (pos) {
7523 this._element.plot(morpher.at(pos));
7524 return morpher.done()
7525 }
7526 );
7527
7528 this._rememberMorpher('plot', morpher);
7529 return this
7530 },
7531
7532 // Add leading method
7533 leading(value) {
7534 return this._queueNumber('leading', value)
7535 },
7536
7537 // Add animatable viewbox
7538 viewbox(x, y, width, height) {
7539 return this._queueObject('viewbox', new Box(x, y, width, height))
7540 },
7541
7542 update(o) {
7543 if (typeof o !== 'object') {
7544 return this.update({
7545 offset: arguments[0],
7546 color: arguments[1],
7547 opacity: arguments[2]
7548 })
7549 }
7550
7551 if (o.opacity != null) this.attr('stop-opacity', o.opacity);
7552 if (o.color != null) this.attr('stop-color', o.color);
7553 if (o.offset != null) this.attr('offset', o.offset);
7554
7555 return this
7556 }
7557 });
7558
7559 extend(Runner, { rx, ry, from, to });
7560 register(Runner, 'Runner');
7561
7562 class Svg extends Container {
7563 constructor(node, attrs = node) {
7564 super(nodeOrNew('svg', node), attrs);
7565 this.namespace();
7566 }
7567
7568 // Creates and returns defs element
7569 defs() {
7570 if (!this.isRoot()) return this.root().defs()
7571
7572 return adopt(this.node.querySelector('defs')) || this.put(new Defs())
7573 }
7574
7575 isRoot() {
7576 return (
7577 !this.node.parentNode ||
7578 (!(this.node.parentNode instanceof globals.window.SVGElement) &&
7579 this.node.parentNode.nodeName !== '#document-fragment')
7580 )
7581 }
7582
7583 // Add namespaces
7584 namespace() {
7585 if (!this.isRoot()) return this.root().namespace()
7586 return this.attr({ xmlns: svg, version: '1.1' }).attr(
7587 'xmlns:xlink',
7588 xlink,
7589 xmlns
7590 )
7591 }
7592
7593 removeNamespace() {
7594 return this.attr({ xmlns: null, version: null })
7595 .attr('xmlns:xlink', null, xmlns)
7596 .attr('xmlns:svgjs', null, xmlns)
7597 }
7598
7599 // Check if this is a root svg
7600 // If not, call root() from this element
7601 root() {
7602 if (this.isRoot()) return this
7603 return super.root()
7604 }
7605 }
7606
7607 registerMethods({
7608 Container: {
7609 // Create nested svg document
7610 nested: wrapWithAttrCheck(function () {
7611 return this.put(new Svg())
7612 })
7613 }
7614 });
7615
7616 register(Svg, 'Svg', true);
7617
7618 let Symbol$1 = class Symbol extends Container {
7619 // Initialize node
7620 constructor(node, attrs = node) {
7621 super(nodeOrNew('symbol', node), attrs);
7622 }
7623 };
7624
7625 registerMethods({
7626 Container: {
7627 symbol: wrapWithAttrCheck(function () {
7628 return this.put(new Symbol$1())
7629 })
7630 }
7631 });
7632
7633 register(Symbol$1, 'Symbol');
7634
7635 // Create plain text node
7636 function plain(text) {
7637 // clear if build mode is disabled
7638 if (this._build === false) {
7639 this.clear();
7640 }
7641
7642 // create text node
7643 this.node.appendChild(globals.document.createTextNode(text));
7644
7645 return this
7646 }
7647
7648 // Get length of text element
7649 function length() {
7650 return this.node.getComputedTextLength()
7651 }
7652
7653 // Move over x-axis
7654 // Text is moved by its bounding box
7655 // text-anchor does NOT matter
7656 function x$1(x, box = this.bbox()) {
7657 if (x == null) {
7658 return box.x
7659 }
7660
7661 return this.attr('x', this.attr('x') + x - box.x)
7662 }
7663
7664 // Move over y-axis
7665 function y$1(y, box = this.bbox()) {
7666 if (y == null) {
7667 return box.y
7668 }
7669
7670 return this.attr('y', this.attr('y') + y - box.y)
7671 }
7672
7673 function move$1(x, y, box = this.bbox()) {
7674 return this.x(x, box).y(y, box)
7675 }
7676
7677 // Move center over x-axis
7678 function cx(x, box = this.bbox()) {
7679 if (x == null) {
7680 return box.cx
7681 }
7682
7683 return this.attr('x', this.attr('x') + x - box.cx)
7684 }
7685
7686 // Move center over y-axis
7687 function cy(y, box = this.bbox()) {
7688 if (y == null) {
7689 return box.cy
7690 }
7691
7692 return this.attr('y', this.attr('y') + y - box.cy)
7693 }
7694
7695 function center(x, y, box = this.bbox()) {
7696 return this.cx(x, box).cy(y, box)
7697 }
7698
7699 function ax(x) {
7700 return this.attr('x', x)
7701 }
7702
7703 function ay(y) {
7704 return this.attr('y', y)
7705 }
7706
7707 function amove(x, y) {
7708 return this.ax(x).ay(y)
7709 }
7710
7711 // Enable / disable build mode
7712 function build(build) {
7713 this._build = !!build;
7714 return this
7715 }
7716
7717 var textable = /*#__PURE__*/Object.freeze({
7718 __proto__: null,
7719 amove: amove,
7720 ax: ax,
7721 ay: ay,
7722 build: build,
7723 center: center,
7724 cx: cx,
7725 cy: cy,
7726 length: length,
7727 move: move$1,
7728 plain: plain,
7729 x: x$1,
7730 y: y$1
7731 });
7732
7733 class Text extends Shape {
7734 // Initialize node
7735 constructor(node, attrs = node) {
7736 super(nodeOrNew('text', node), attrs);
7737
7738 this.dom.leading = this.dom.leading ?? new SVGNumber(1.3); // store leading value for rebuilding
7739 this._rebuild = true; // enable automatic updating of dy values
7740 this._build = false; // disable build mode for adding multiple lines
7741 }
7742
7743 // Set / get leading
7744 leading(value) {
7745 // act as getter
7746 if (value == null) {
7747 return this.dom.leading
7748 }
7749
7750 // act as setter
7751 this.dom.leading = new SVGNumber(value);
7752
7753 return this.rebuild()
7754 }
7755
7756 // Rebuild appearance type
7757 rebuild(rebuild) {
7758 // store new rebuild flag if given
7759 if (typeof rebuild === 'boolean') {
7760 this._rebuild = rebuild;
7761 }
7762
7763 // define position of all lines
7764 if (this._rebuild) {
7765 const self = this;
7766 let blankLineOffset = 0;
7767 const leading = this.dom.leading;
7768
7769 this.each(function (i) {
7770 if (isDescriptive(this.node)) return
7771
7772 const fontSize = globals.window
7773 .getComputedStyle(this.node)
7774 .getPropertyValue('font-size');
7775
7776 const dy = leading * new SVGNumber(fontSize);
7777
7778 if (this.dom.newLined) {
7779 this.attr('x', self.attr('x'));
7780
7781 if (this.text() === '\n') {
7782 blankLineOffset += dy;
7783 } else {
7784 this.attr('dy', i ? dy + blankLineOffset : 0);
7785 blankLineOffset = 0;
7786 }
7787 }
7788 });
7789
7790 this.fire('rebuild');
7791 }
7792
7793 return this
7794 }
7795
7796 // overwrite method from parent to set data properly
7797 setData(o) {
7798 this.dom = o;
7799 this.dom.leading = new SVGNumber(o.leading || 1.3);
7800 return this
7801 }
7802
7803 writeDataToDom() {
7804 writeDataToDom(this, this.dom, { leading: 1.3 });
7805 return this
7806 }
7807
7808 // Set the text content
7809 text(text) {
7810 // act as getter
7811 if (text === undefined) {
7812 const children = this.node.childNodes;
7813 let firstLine = 0;
7814 text = '';
7815
7816 for (let i = 0, len = children.length; i < len; ++i) {
7817 // skip textPaths - they are no lines
7818 if (children[i].nodeName === 'textPath' || isDescriptive(children[i])) {
7819 if (i === 0) firstLine = i + 1;
7820 continue
7821 }
7822
7823 // add newline if its not the first child and newLined is set to true
7824 if (
7825 i !== firstLine &&
7826 children[i].nodeType !== 3 &&
7827 adopt(children[i]).dom.newLined === true
7828 ) {
7829 text += '\n';
7830 }
7831
7832 // add content of this node
7833 text += children[i].textContent;
7834 }
7835
7836 return text
7837 }
7838
7839 // remove existing content
7840 this.clear().build(true);
7841
7842 if (typeof text === 'function') {
7843 // call block
7844 text.call(this, this);
7845 } else {
7846 // store text and make sure text is not blank
7847 text = (text + '').split('\n');
7848
7849 // build new lines
7850 for (let j = 0, jl = text.length; j < jl; j++) {
7851 this.newLine(text[j]);
7852 }
7853 }
7854
7855 // disable build mode and rebuild lines
7856 return this.build(false).rebuild()
7857 }
7858 }
7859
7860 extend(Text, textable);
7861
7862 registerMethods({
7863 Container: {
7864 // Create text element
7865 text: wrapWithAttrCheck(function (text = '') {
7866 return this.put(new Text()).text(text)
7867 }),
7868
7869 // Create plain text element
7870 plain: wrapWithAttrCheck(function (text = '') {
7871 return this.put(new Text()).plain(text)
7872 })
7873 }
7874 });
7875
7876 register(Text, 'Text');
7877
7878 class Tspan extends Shape {
7879 // Initialize node
7880 constructor(node, attrs = node) {
7881 super(nodeOrNew('tspan', node), attrs);
7882 this._build = false; // disable build mode for adding multiple lines
7883 }
7884
7885 // Shortcut dx
7886 dx(dx) {
7887 return this.attr('dx', dx)
7888 }
7889
7890 // Shortcut dy
7891 dy(dy) {
7892 return this.attr('dy', dy)
7893 }
7894
7895 // Create new line
7896 newLine() {
7897 // mark new line
7898 this.dom.newLined = true;
7899
7900 // fetch parent
7901 const text = this.parent();
7902
7903 // early return in case we are not in a text element
7904 if (!(text instanceof Text)) {
7905 return this
7906 }
7907
7908 const i = text.index(this);
7909
7910 const fontSize = globals.window
7911 .getComputedStyle(this.node)
7912 .getPropertyValue('font-size');
7913 const dy = text.dom.leading * new SVGNumber(fontSize);
7914
7915 // apply new position
7916 return this.dy(i ? dy : 0).attr('x', text.x())
7917 }
7918
7919 // Set text content
7920 text(text) {
7921 if (text == null)
7922 return this.node.textContent + (this.dom.newLined ? '\n' : '')
7923
7924 if (typeof text === 'function') {
7925 this.clear().build(true);
7926 text.call(this, this);
7927 this.build(false);
7928 } else {
7929 this.plain(text);
7930 }
7931
7932 return this
7933 }
7934 }
7935
7936 extend(Tspan, textable);
7937
7938 registerMethods({
7939 Tspan: {
7940 tspan: wrapWithAttrCheck(function (text = '') {
7941 const tspan = new Tspan();
7942
7943 // clear if build mode is disabled
7944 if (!this._build) {
7945 this.clear();
7946 }
7947
7948 // add new tspan
7949 return this.put(tspan).text(text)
7950 })
7951 },
7952 Text: {
7953 newLine: function (text = '') {
7954 return this.tspan(text).newLine()
7955 }
7956 }
7957 });
7958
7959 register(Tspan, 'Tspan');
7960
7961 class Circle extends Shape {
7962 constructor(node, attrs = node) {
7963 super(nodeOrNew('circle', node), attrs);
7964 }
7965
7966 radius(r) {
7967 return this.attr('r', r)
7968 }
7969
7970 // Radius x value
7971 rx(rx) {
7972 return this.attr('r', rx)
7973 }
7974
7975 // Alias radius x value
7976 ry(ry) {
7977 return this.rx(ry)
7978 }
7979
7980 size(size) {
7981 return this.radius(new SVGNumber(size).divide(2))
7982 }
7983 }
7984
7985 extend(Circle, { x: x$3, y: y$3, cx: cx$1, cy: cy$1, width: width$2, height: height$2 });
7986
7987 registerMethods({
7988 Container: {
7989 // Create circle element
7990 circle: wrapWithAttrCheck(function (size = 0) {
7991 return this.put(new Circle()).size(size).move(0, 0)
7992 })
7993 }
7994 });
7995
7996 register(Circle, 'Circle');
7997
7998 class ClipPath extends Container {
7999 constructor(node, attrs = node) {
8000 super(nodeOrNew('clipPath', node), attrs);
8001 }
8002
8003 // Unclip all clipped elements and remove itself
8004 remove() {
8005 // unclip all targets
8006 this.targets().forEach(function (el) {
8007 el.unclip();
8008 });
8009
8010 // remove clipPath from parent
8011 return super.remove()
8012 }
8013
8014 targets() {
8015 return baseFind('svg [clip-path*=' + this.id() + ']')
8016 }
8017 }
8018
8019 registerMethods({
8020 Container: {
8021 // Create clipping element
8022 clip: wrapWithAttrCheck(function () {
8023 return this.defs().put(new ClipPath())
8024 })
8025 },
8026 Element: {
8027 // Distribute clipPath to svg element
8028 clipper() {
8029 return this.reference('clip-path')
8030 },
8031
8032 clipWith(element) {
8033 // use given clip or create a new one
8034 const clipper =
8035 element instanceof ClipPath
8036 ? element
8037 : this.parent().clip().add(element);
8038
8039 // apply mask
8040 return this.attr('clip-path', 'url(#' + clipper.id() + ')')
8041 },
8042
8043 // Unclip element
8044 unclip() {
8045 return this.attr('clip-path', null)
8046 }
8047 }
8048 });
8049
8050 register(ClipPath, 'ClipPath');
8051
8052 class ForeignObject extends Element$1 {
8053 constructor(node, attrs = node) {
8054 super(nodeOrNew('foreignObject', node), attrs);
8055 }
8056 }
8057
8058 registerMethods({
8059 Container: {
8060 foreignObject: wrapWithAttrCheck(function (width, height) {
8061 return this.put(new ForeignObject()).size(width, height)
8062 })
8063 }
8064 });
8065
8066 register(ForeignObject, 'ForeignObject');
8067
8068 function dmove(dx, dy) {
8069 this.children().forEach((child) => {
8070 let bbox;
8071
8072 // We have to wrap this for elements that dont have a bbox
8073 // e.g. title and other descriptive elements
8074 try {
8075 // Get the childs bbox
8076 // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1905039
8077 // Because bbox for nested svgs returns the contents bbox in the coordinate space of the svg itself (weird!), we cant use bbox for svgs
8078 // Therefore we have to use getBoundingClientRect. But THAT is broken (as explained in the bug).
8079 // Funnily enough the broken behavior would work for us but that breaks it in chrome
8080 // So we have to replicate the broken behavior of FF by just reading the attributes of the svg itself
8081 bbox =
8082 child.node instanceof getWindow().SVGSVGElement
8083 ? new Box(child.attr(['x', 'y', 'width', 'height']))
8084 : child.bbox();
8085 } catch (e) {
8086 return
8087 }
8088
8089 // Get childs matrix
8090 const m = new Matrix(child);
8091 // Translate childs matrix by amount and
8092 // transform it back into parents space
8093 const matrix = m.translate(dx, dy).transform(m.inverse());
8094 // Calculate new x and y from old box
8095 const p = new Point(bbox.x, bbox.y).transform(matrix);
8096 // Move element
8097 child.move(p.x, p.y);
8098 });
8099
8100 return this
8101 }
8102
8103 function dx(dx) {
8104 return this.dmove(dx, 0)
8105 }
8106
8107 function dy(dy) {
8108 return this.dmove(0, dy)
8109 }
8110
8111 function height(height, box = this.bbox()) {
8112 if (height == null) return box.height
8113 return this.size(box.width, height, box)
8114 }
8115
8116 function move(x = 0, y = 0, box = this.bbox()) {
8117 const dx = x - box.x;
8118 const dy = y - box.y;
8119
8120 return this.dmove(dx, dy)
8121 }
8122
8123 function size(width, height, box = this.bbox()) {
8124 const p = proportionalSize(this, width, height, box);
8125 const scaleX = p.width / box.width;
8126 const scaleY = p.height / box.height;
8127
8128 this.children().forEach((child) => {
8129 const o = new Point(box).transform(new Matrix(child).inverse());
8130 child.scale(scaleX, scaleY, o.x, o.y);
8131 });
8132
8133 return this
8134 }
8135
8136 function width(width, box = this.bbox()) {
8137 if (width == null) return box.width
8138 return this.size(width, box.height, box)
8139 }
8140
8141 function x(x, box = this.bbox()) {
8142 if (x == null) return box.x
8143 return this.move(x, box.y, box)
8144 }
8145
8146 function y(y, box = this.bbox()) {
8147 if (y == null) return box.y
8148 return this.move(box.x, y, box)
8149 }
8150
8151 var containerGeometry = /*#__PURE__*/Object.freeze({
8152 __proto__: null,
8153 dmove: dmove,
8154 dx: dx,
8155 dy: dy,
8156 height: height,
8157 move: move,
8158 size: size,
8159 width: width,
8160 x: x,
8161 y: y
8162 });
8163
8164 class G extends Container {
8165 constructor(node, attrs = node) {
8166 super(nodeOrNew('g', node), attrs);
8167 }
8168 }
8169
8170 extend(G, containerGeometry);
8171
8172 registerMethods({
8173 Container: {
8174 // Create a group element
8175 group: wrapWithAttrCheck(function () {
8176 return this.put(new G())
8177 })
8178 }
8179 });
8180
8181 register(G, 'G');
8182
8183 class A extends Container {
8184 constructor(node, attrs = node) {
8185 super(nodeOrNew('a', node), attrs);
8186 }
8187
8188 // Link target attribute
8189 target(target) {
8190 return this.attr('target', target)
8191 }
8192
8193 // Link url
8194 to(url) {
8195 return this.attr('href', url, xlink)
8196 }
8197 }
8198
8199 extend(A, containerGeometry);
8200
8201 registerMethods({
8202 Container: {
8203 // Create a hyperlink element
8204 link: wrapWithAttrCheck(function (url) {
8205 return this.put(new A()).to(url)
8206 })
8207 },
8208 Element: {
8209 unlink() {
8210 const link = this.linker();
8211
8212 if (!link) return this
8213
8214 const parent = link.parent();
8215
8216 if (!parent) {
8217 return this.remove()
8218 }
8219
8220 const index = parent.index(link);
8221 parent.add(this, index);
8222
8223 link.remove();
8224 return this
8225 },
8226 linkTo(url) {
8227 // reuse old link if possible
8228 let link = this.linker();
8229
8230 if (!link) {
8231 link = new A();
8232 this.wrap(link);
8233 }
8234
8235 if (typeof url === 'function') {
8236 url.call(link, link);
8237 } else {
8238 link.to(url);
8239 }
8240
8241 return this
8242 },
8243 linker() {
8244 const link = this.parent();
8245 if (link && link.node.nodeName.toLowerCase() === 'a') {
8246 return link
8247 }
8248
8249 return null
8250 }
8251 }
8252 });
8253
8254 register(A, 'A');
8255
8256 class Mask extends Container {
8257 // Initialize node
8258 constructor(node, attrs = node) {
8259 super(nodeOrNew('mask', node), attrs);
8260 }
8261
8262 // Unmask all masked elements and remove itself
8263 remove() {
8264 // unmask all targets
8265 this.targets().forEach(function (el) {
8266 el.unmask();
8267 });
8268
8269 // remove mask from parent
8270 return super.remove()
8271 }
8272
8273 targets() {
8274 return baseFind('svg [mask*=' + this.id() + ']')
8275 }
8276 }
8277
8278 registerMethods({
8279 Container: {
8280 mask: wrapWithAttrCheck(function () {
8281 return this.defs().put(new Mask())
8282 })
8283 },
8284 Element: {
8285 // Distribute mask to svg element
8286 masker() {
8287 return this.reference('mask')
8288 },
8289
8290 maskWith(element) {
8291 // use given mask or create a new one
8292 const masker =
8293 element instanceof Mask ? element : this.parent().mask().add(element);
8294
8295 // apply mask
8296 return this.attr('mask', 'url(#' + masker.id() + ')')
8297 },
8298
8299 // Unmask element
8300 unmask() {
8301 return this.attr('mask', null)
8302 }
8303 }
8304 });
8305
8306 register(Mask, 'Mask');
8307
8308 class Stop extends Element$1 {
8309 constructor(node, attrs = node) {
8310 super(nodeOrNew('stop', node), attrs);
8311 }
8312
8313 // add color stops
8314 update(o) {
8315 if (typeof o === 'number' || o instanceof SVGNumber) {
8316 o = {
8317 offset: arguments[0],
8318 color: arguments[1],
8319 opacity: arguments[2]
8320 };
8321 }
8322
8323 // set attributes
8324 if (o.opacity != null) this.attr('stop-opacity', o.opacity);
8325 if (o.color != null) this.attr('stop-color', o.color);
8326 if (o.offset != null) this.attr('offset', new SVGNumber(o.offset));
8327
8328 return this
8329 }
8330 }
8331
8332 registerMethods({
8333 Gradient: {
8334 // Add a color stop
8335 stop: function (offset, color, opacity) {
8336 return this.put(new Stop()).update(offset, color, opacity)
8337 }
8338 }
8339 });
8340
8341 register(Stop, 'Stop');
8342
8343 function cssRule(selector, rule) {
8344 if (!selector) return ''
8345 if (!rule) return selector
8346
8347 let ret = selector + '{';
8348
8349 for (const i in rule) {
8350 ret += unCamelCase(i) + ':' + rule[i] + ';';
8351 }
8352
8353 ret += '}';
8354
8355 return ret
8356 }
8357
8358 class Style extends Element$1 {
8359 constructor(node, attrs = node) {
8360 super(nodeOrNew('style', node), attrs);
8361 }
8362
8363 addText(w = '') {
8364 this.node.textContent += w;
8365 return this
8366 }
8367
8368 font(name, src, params = {}) {
8369 return this.rule('@font-face', {
8370 fontFamily: name,
8371 src: src,
8372 ...params
8373 })
8374 }
8375
8376 rule(selector, obj) {
8377 return this.addText(cssRule(selector, obj))
8378 }
8379 }
8380
8381 registerMethods('Dom', {
8382 style(selector, obj) {
8383 return this.put(new Style()).rule(selector, obj)
8384 },
8385 fontface(name, src, params) {
8386 return this.put(new Style()).font(name, src, params)
8387 }
8388 });
8389
8390 register(Style, 'Style');
8391
8392 class TextPath extends Text {
8393 // Initialize node
8394 constructor(node, attrs = node) {
8395 super(nodeOrNew('textPath', node), attrs);
8396 }
8397
8398 // return the array of the path track element
8399 array() {
8400 const track = this.track();
8401
8402 return track ? track.array() : null
8403 }
8404
8405 // Plot path if any
8406 plot(d) {
8407 const track = this.track();
8408 let pathArray = null;
8409
8410 if (track) {
8411 pathArray = track.plot(d);
8412 }
8413
8414 return d == null ? pathArray : this
8415 }
8416
8417 // Get the path element
8418 track() {
8419 return this.reference('href')
8420 }
8421 }
8422
8423 registerMethods({
8424 Container: {
8425 textPath: wrapWithAttrCheck(function (text, path) {
8426 // Convert text to instance if needed
8427 if (!(text instanceof Text)) {
8428 text = this.text(text);
8429 }
8430
8431 return text.path(path)
8432 })
8433 },
8434 Text: {
8435 // Create path for text to run on
8436 path: wrapWithAttrCheck(function (track, importNodes = true) {
8437 const textPath = new TextPath();
8438
8439 // if track is a path, reuse it
8440 if (!(track instanceof Path)) {
8441 // create path element
8442 track = this.defs().path(track);
8443 }
8444
8445 // link textPath to path and add content
8446 textPath.attr('href', '#' + track, xlink);
8447
8448 // Transplant all nodes from text to textPath
8449 let node;
8450 if (importNodes) {
8451 while ((node = this.node.firstChild)) {
8452 textPath.node.appendChild(node);
8453 }
8454 }
8455
8456 // add textPath element as child node and return textPath
8457 return this.put(textPath)
8458 }),
8459
8460 // Get the textPath children
8461 textPath() {
8462 return this.findOne('textPath')
8463 }
8464 },
8465 Path: {
8466 // creates a textPath from this path
8467 text: wrapWithAttrCheck(function (text) {
8468 // Convert text to instance if needed
8469 if (!(text instanceof Text)) {
8470 text = new Text().addTo(this.parent()).text(text);
8471 }
8472
8473 // Create textPath from text and path and return
8474 return text.path(this)
8475 }),
8476
8477 targets() {
8478 return baseFind('svg textPath').filter((node) => {
8479 return (node.attr('href') || '').includes(this.id())
8480 })
8481
8482 // Does not work in IE11. Use when IE support is dropped
8483 // return baseFind('svg textPath[*|href*=' + this.id() + ']')
8484 }
8485 }
8486 });
8487
8488 TextPath.prototype.MorphArray = PathArray;
8489 register(TextPath, 'TextPath');
8490
8491 class Use extends Shape {
8492 constructor(node, attrs = node) {
8493 super(nodeOrNew('use', node), attrs);
8494 }
8495
8496 // Use element as a reference
8497 use(element, file) {
8498 // Set lined element
8499 return this.attr('href', (file || '') + '#' + element, xlink)
8500 }
8501 }
8502
8503 registerMethods({
8504 Container: {
8505 // Create a use element
8506 use: wrapWithAttrCheck(function (element, file) {
8507 return this.put(new Use()).use(element, file)
8508 })
8509 }
8510 });
8511
8512 register(Use, 'Use');
8513
8514 /* Optional Modules */
8515 const SVG = makeInstance;
8516
8517 extend([Svg, Symbol$1, Image$1, Pattern, Marker$1], getMethodsFor('viewbox'));
8518
8519 extend([Line$1, Polyline, Polygon, Path], getMethodsFor('marker'));
8520
8521 extend(Text, getMethodsFor('Text'));
8522 extend(Path, getMethodsFor('Path'));
8523
8524 extend(Defs, getMethodsFor('Defs'));
8525
8526 extend([Text, Tspan], getMethodsFor('Tspan'));
8527
8528 extend([Rect, Ellipse, Gradient, Runner], getMethodsFor('radius'));
8529
8530 extend(EventTarget, getMethodsFor('EventTarget'));
8531 extend(Dom, getMethodsFor('Dom'));
8532 extend(Element$1, getMethodsFor('Element'));
8533 extend(Shape, getMethodsFor('Shape'));
8534 extend([Container, Fragment], getMethodsFor('Container'));
8535 extend(Gradient, getMethodsFor('Gradient'));
8536
8537 extend(Runner, getMethodsFor('Runner'));
8538
8539 List.extend(getMethodNames());
8540
8541 registerMorphableType([
8542 SVGNumber,
8543 Color,
8544 Box,
8545 Matrix,
8546 SVGArray,
8547 PointArray,
8548 PathArray,
8549 Point
8550 ]);
8551
8552 makeMorphable();
8553
8554 class Filter extends Element$1 {
8555 constructor (node) {
8556 super(nodeOrNew('filter', node), node);
8557
8558 this.$source = 'SourceGraphic';
8559 this.$sourceAlpha = 'SourceAlpha';
8560 this.$background = 'BackgroundImage';
8561 this.$backgroundAlpha = 'BackgroundAlpha';
8562 this.$fill = 'FillPaint';
8563 this.$stroke = 'StrokePaint';
8564 this.$autoSetIn = true;
8565 }
8566
8567 put (element, i) {
8568 element = super.put(element, i);
8569
8570 if (!element.attr('in') && this.$autoSetIn) {
8571 element.attr('in', this.$source);
8572 }
8573 if (!element.attr('result')) {
8574 element.attr('result', element.id());
8575 }
8576
8577 return element
8578 }
8579
8580 // Unmask all masked elements and remove itself
8581 remove () {
8582 // unmask all targets
8583 this.targets().each('unfilter');
8584
8585 // remove mask from parent
8586 return super.remove()
8587 }
8588
8589 targets () {
8590 return baseFind('svg [filter*="' + this.id() + '"]')
8591 }
8592
8593 toString () {
8594 return 'url(#' + this.id() + ')'
8595 }
8596 }
8597
8598 // Create Effect class
8599 class Effect extends Element$1 {
8600 constructor (node, attr) {
8601 super(node, attr);
8602 this.result(this.id());
8603 }
8604
8605 in (effect) {
8606 // Act as getter
8607 if (effect == null) {
8608 const _in = this.attr('in');
8609 const ref = this.parent() && this.parent().find(`[result="${_in}"]`)[0];
8610 return ref || _in
8611 }
8612
8613 // Avr as setter
8614 return this.attr('in', effect)
8615 }
8616
8617 // Named result
8618 result (result) {
8619 return this.attr('result', result)
8620 }
8621
8622 // Stringification
8623 toString () {
8624 return this.result()
8625 }
8626 }
8627
8628 // This function takes an array with attr keys and sets for every key the
8629 // attribute to the value of one paramater
8630 // getAttrSetter(['a', 'b']) becomes this.attr({a: param1, b: param2})
8631 const getAttrSetter = (params) => {
8632 return function (...args) {
8633 for (let i = params.length; i--;) {
8634 if (args[i] != null) {
8635 this.attr(params[i], args[i]);
8636 }
8637 }
8638 }
8639 };
8640
8641 const updateFunctions = {
8642 blend: getAttrSetter(['in', 'in2', 'mode']),
8643 // ColorMatrix effect
8644 colorMatrix: getAttrSetter(['type', 'values']),
8645 // Composite effect
8646 composite: getAttrSetter(['in', 'in2', 'operator']),
8647 // ConvolveMatrix effect
8648 convolveMatrix: function (matrix) {
8649 matrix = new SVGArray(matrix).toString();
8650
8651 this.attr({
8652 order: Math.sqrt(matrix.split(' ').length),
8653 kernelMatrix: matrix
8654 });
8655 },
8656 // DiffuseLighting effect
8657 diffuseLighting: getAttrSetter(['surfaceScale', 'lightingColor', 'diffuseConstant', 'kernelUnitLength']),
8658 // DisplacementMap effect
8659 displacementMap: getAttrSetter(['in', 'in2', 'scale', 'xChannelSelector', 'yChannelSelector']),
8660 // DropShadow effect
8661 dropShadow: getAttrSetter(['in', 'dx', 'dy', 'stdDeviation']),
8662 // Flood effect
8663 flood: getAttrSetter(['flood-color', 'flood-opacity']),
8664 // Gaussian Blur effect
8665 gaussianBlur: function (x = 0, y = x) {
8666 this.attr('stdDeviation', x + ' ' + y);
8667 },
8668 // Image effect
8669 image: function (src) {
8670 this.attr('href', src, xlink);
8671 },
8672 // Morphology effect
8673 morphology: getAttrSetter(['operator', 'radius']),
8674 // Offset effect
8675 offset: getAttrSetter(['dx', 'dy']),
8676 // SpecularLighting effect
8677 specularLighting: getAttrSetter(['surfaceScale', 'lightingColor', 'diffuseConstant', 'specularExponent', 'kernelUnitLength']),
8678 // Tile effect
8679 tile: getAttrSetter([]),
8680 // Turbulence effect
8681 turbulence: getAttrSetter(['baseFrequency', 'numOctaves', 'seed', 'stitchTiles', 'type'])
8682 };
8683
8684 const filterNames = [
8685 'blend',
8686 'colorMatrix',
8687 'componentTransfer',
8688 'composite',
8689 'convolveMatrix',
8690 'diffuseLighting',
8691 'displacementMap',
8692 'dropShadow',
8693 'flood',
8694 'gaussianBlur',
8695 'image',
8696 'merge',
8697 'morphology',
8698 'offset',
8699 'specularLighting',
8700 'tile',
8701 'turbulence'
8702 ];
8703
8704 // For every filter create a class
8705 filterNames.forEach((effect) => {
8706 const name = capitalize(effect);
8707 const fn = updateFunctions[effect];
8708
8709 Filter[name + 'Effect'] = class extends Effect {
8710 constructor (node) {
8711 super(nodeOrNew('fe' + name, node), node);
8712 }
8713
8714 // This function takes all parameters from the factory call
8715 // and updates the attributes according to the updateFunctions
8716 update (args) {
8717 fn.apply(this, args);
8718 return this
8719 }
8720 };
8721
8722 // Add factory function to filter
8723 // Allow to pass a function or object
8724 // The attr object is catched from "wrapWithAttrCheck"
8725 Filter.prototype[effect] = wrapWithAttrCheck(function (fn, ...args) {
8726 const effect = new Filter[name + 'Effect']();
8727
8728 if (fn == null) return this.put(effect)
8729
8730 // For Effects which can take children, a function is allowed
8731 if (typeof fn === 'function') {
8732 fn.call(effect, effect);
8733 } else {
8734 // In case it is not a function, add it to arguments
8735 args.unshift(fn);
8736 }
8737 return this.put(effect).update(args)
8738 });
8739 });
8740
8741 // Correct factories which are not that simple
8742 extend(Filter, {
8743 merge (arrayOrFn) {
8744 const node = this.put(new Filter.MergeEffect());
8745
8746 // If a function was passed, execute it
8747 // That makes stuff like this possible:
8748 // filter.merge((mergeEffect) => mergeEffect.mergeNode(in))
8749 if (typeof arrayOrFn === 'function') {
8750 arrayOrFn.call(node, node);
8751 return node
8752 }
8753
8754 // Check if first child is an array, otherwise use arguments as array
8755 const children = arrayOrFn instanceof Array ? arrayOrFn : [...arguments];
8756
8757 children.forEach((child) => {
8758 if (child instanceof Filter.MergeNode) {
8759 node.put(child);
8760 } else {
8761 node.mergeNode(child);
8762 }
8763 });
8764
8765 return node
8766 },
8767 componentTransfer (components = {}) {
8768 const node = this.put(new Filter.ComponentTransferEffect());
8769
8770 if (typeof components === 'function') {
8771 components.call(node, node);
8772 return node
8773 }
8774
8775 // If no component is set, we use the given object for all components
8776 if (!components.r && !components.g && !components.b && !components.a) {
8777 const temp = components;
8778 components = {
8779 r: temp, g: temp, b: temp, a: temp
8780 };
8781 }
8782
8783 for (const c in components) {
8784 // components[c] has to hold an attributes object
8785 node.add(new Filter['Func' + c.toUpperCase()](components[c]));
8786 }
8787
8788 return node
8789 }
8790 });
8791
8792 const filterChildNodes = [
8793 'distantLight',
8794 'pointLight',
8795 'spotLight',
8796 'mergeNode',
8797 'FuncR',
8798 'FuncG',
8799 'FuncB',
8800 'FuncA'
8801 ];
8802
8803 filterChildNodes.forEach((child) => {
8804 const name = capitalize(child);
8805 Filter[name] = class extends Effect {
8806 constructor (node) {
8807 super(nodeOrNew('fe' + name, node), node);
8808 }
8809 };
8810 });
8811
8812 const componentFuncs = [
8813 'funcR',
8814 'funcG',
8815 'funcB',
8816 'funcA'
8817 ];
8818
8819 // Add an update function for componentTransfer-children
8820 componentFuncs.forEach(function (c) {
8821 const _class = Filter[capitalize(c)];
8822 const fn = wrapWithAttrCheck(function () {
8823 return this.put(new _class())
8824 });
8825
8826 Filter.ComponentTransferEffect.prototype[c] = fn;
8827 });
8828
8829 const lights = [
8830 'distantLight',
8831 'pointLight',
8832 'spotLight'
8833 ];
8834
8835 // Add light sources factories to lightining effects
8836 lights.forEach((light) => {
8837 const _class = Filter[capitalize(light)];
8838 const fn = wrapWithAttrCheck(function () {
8839 return this.put(new _class())
8840 });
8841
8842 Filter.DiffuseLightingEffect.prototype[light] = fn;
8843 Filter.SpecularLightingEffect.prototype[light] = fn;
8844 });
8845
8846 extend(Filter.MergeEffect, {
8847 mergeNode (_in) {
8848 return this.put(new Filter.MergeNode()).attr('in', _in)
8849 }
8850 });
8851
8852 // add .filter function
8853 extend(Defs, {
8854 // Define filter
8855 filter: function (block) {
8856 const filter = this.put(new Filter());
8857
8858 /* invoke passed block */
8859 if (typeof block === 'function') { block.call(filter, filter); }
8860
8861 return filter
8862 }
8863 });
8864
8865 extend(Container, {
8866 // Define filter on defs
8867 filter: function (block) {
8868 return this.defs().filter(block)
8869 }
8870 });
8871
8872 extend(Element$1, {
8873 // Create filter element in defs and store reference
8874 filterWith: function (block) {
8875 const filter = block instanceof Filter
8876 ? block
8877 : this.defs().filter(block);
8878
8879 return this.attr('filter', filter)
8880 },
8881 // Remove filter
8882 unfilter: function (remove) {
8883 /* remove filter attribute */
8884 return this.attr('filter', null)
8885 },
8886 filterer () {
8887 return this.reference('filter')
8888 }
8889 });
8890
8891 // chaining
8892 const chainingEffects = {
8893 // Blend effect
8894 blend: function (in2, mode) {
8895 return this.parent() && this.parent().blend(this, in2, mode) // pass this as the first input
8896 },
8897 // ColorMatrix effect
8898 colorMatrix: function (type, values) {
8899 return this.parent() && this.parent().colorMatrix(type, values).in(this)
8900 },
8901 // ComponentTransfer effect
8902 componentTransfer: function (components) {
8903 return this.parent() && this.parent().componentTransfer(components).in(this)
8904 },
8905 // Composite effect
8906 composite: function (in2, operator) {
8907 return this.parent() && this.parent().composite(this, in2, operator) // pass this as the first input
8908 },
8909 // ConvolveMatrix effect
8910 convolveMatrix: function (matrix) {
8911 return this.parent() && this.parent().convolveMatrix(matrix).in(this)
8912 },
8913 // DiffuseLighting effect
8914 diffuseLighting: function (surfaceScale, lightingColor, diffuseConstant, kernelUnitLength) {
8915 return this.parent() && this.parent().diffuseLighting(surfaceScale, diffuseConstant, kernelUnitLength).in(this)
8916 },
8917 // DisplacementMap effect
8918 displacementMap: function (in2, scale, xChannelSelector, yChannelSelector) {
8919 return this.parent() && this.parent().displacementMap(this, in2, scale, xChannelSelector, yChannelSelector) // pass this as the first input
8920 },
8921 // DisplacementMap effect
8922 dropShadow: function (x, y, stdDeviation) {
8923 return this.parent() && this.parent().dropShadow(this, x, y, stdDeviation).in(this) // pass this as the first input
8924 },
8925 // Flood effect
8926 flood: function (color, opacity) {
8927 return this.parent() && this.parent().flood(color, opacity) // this effect dont have inputs
8928 },
8929 // Gaussian Blur effect
8930 gaussianBlur: function (x, y) {
8931 return this.parent() && this.parent().gaussianBlur(x, y).in(this)
8932 },
8933 // Image effect
8934 image: function (src) {
8935 return this.parent() && this.parent().image(src) // this effect dont have inputs
8936 },
8937 // Merge effect
8938 merge: function (arg) {
8939 arg = arg instanceof Array ? arg : [...arg];
8940 return this.parent() && this.parent().merge(this, ...arg) // pass this as the first argument
8941 },
8942 // Morphology effect
8943 morphology: function (operator, radius) {
8944 return this.parent() && this.parent().morphology(operator, radius).in(this)
8945 },
8946 // Offset effect
8947 offset: function (dx, dy) {
8948 return this.parent() && this.parent().offset(dx, dy).in(this)
8949 },
8950 // SpecularLighting effect
8951 specularLighting: function (surfaceScale, lightingColor, diffuseConstant, specularExponent, kernelUnitLength) {
8952 return this.parent() && this.parent().specularLighting(surfaceScale, diffuseConstant, specularExponent, kernelUnitLength).in(this)
8953 },
8954 // Tile effect
8955 tile: function () {
8956 return this.parent() && this.parent().tile().in(this)
8957 },
8958 // Turbulence effect
8959 turbulence: function (baseFrequency, numOctaves, seed, stitchTiles, type) {
8960 return this.parent() && this.parent().turbulence(baseFrequency, numOctaves, seed, stitchTiles, type).in(this)
8961 }
8962 };
8963
8964 extend(Effect, chainingEffects);
8965
8966 // Effect-specific extensions
8967 extend(Filter.MergeEffect, {
8968 in: function (effect) {
8969 if (effect instanceof Filter.MergeNode) {
8970 this.add(effect, 0);
8971 } else {
8972 this.add(new Filter.MergeNode().in(effect), 0);
8973 }
8974
8975 return this
8976 }
8977 });
8978
8979 extend([Filter.CompositeEffect, Filter.BlendEffect, Filter.DisplacementMapEffect], {
8980 in2: function (effect) {
8981 if (effect == null) {
8982 const in2 = this.attr('in2');
8983 const ref = this.parent() && this.parent().find(`[result="${in2}"]`)[0];
8984 return ref || in2
8985 }
8986 return this.attr('in2', effect)
8987 }
8988 });
8989
8990 // Presets
8991 Filter.filter = {
8992 sepiatone: [
8993 0.343, 0.669, 0.119, 0, 0,
8994 0.249, 0.626, 0.130, 0, 0,
8995 0.172, 0.334, 0.111, 0, 0,
8996 0.000, 0.000, 0.000, 1, 0]
8997 };
8998
8999 /**
9000 * ApexCharts Filters Class for setting hover/active states on the paths.
9001 *
9002 * @module Formatters
9003 **/
9004 var Filters = /*#__PURE__*/function () {
9005 function Filters(ctx) {
9006 _classCallCheck(this, Filters);
9007 this.ctx = ctx;
9008 this.w = ctx.w;
9009 }
9010
9011 // create a re-usable filter which can be appended other filter effects and applied to multiple elements
9012 _createClass(Filters, [{
9013 key: "getDefaultFilter",
9014 value: function getDefaultFilter(el, i) {
9015 var w = this.w;
9016 el.unfilter(true);
9017 var filter = new Filter();
9018 filter.size('120%', '180%', '-5%', '-40%');
9019 if (w.config.chart.dropShadow.enabled) {
9020 this.dropShadow(el, w.config.chart.dropShadow, i);
9021 }
9022 }
9023 }, {
9024 key: "applyFilter",
9025 value: function applyFilter(el, i, filterType) {
9026 var _this = this,
9027 _el$filterer2;
9028 var w = this.w;
9029 el.unfilter(true);
9030 if (filterType === 'none') {
9031 this.getDefaultFilter(el, i);
9032 return;
9033 }
9034 var shadowAttr = w.config.chart.dropShadow;
9035 var brightnessFactor = filterType === 'lighten' ? 2 : 0.3;
9036 el.filterWith(function (add) {
9037 add.colorMatrix({
9038 type: 'matrix',
9039 values: "\n ".concat(brightnessFactor, " 0 0 0 0\n 0 ").concat(brightnessFactor, " 0 0 0\n 0 0 ").concat(brightnessFactor, " 0 0\n 0 0 0 1 0\n "),
9040 in: 'SourceGraphic',
9041 result: 'brightness'
9042 });
9043 if (shadowAttr.enabled) {
9044 _this.addShadow(add, i, shadowAttr, 'brightness');
9045 }
9046 });
9047 if (!shadowAttr.noUserSpaceOnUse) {
9048 var _el$filterer, _el$filterer$node;
9049 (_el$filterer = el.filterer()) === null || _el$filterer === void 0 ? void 0 : (_el$filterer$node = _el$filterer.node) === null || _el$filterer$node === void 0 ? void 0 : _el$filterer$node.setAttribute('filterUnits', 'userSpaceOnUse');
9050 }
9051
9052 // this scales the filter to a bigger size so that the dropshadow doesn't crops
9053 this._scaleFilterSize((_el$filterer2 = el.filterer()) === null || _el$filterer2 === void 0 ? void 0 : _el$filterer2.node);
9054 }
9055
9056 // appends dropShadow to the filter object which can be chained with other filter effects
9057 }, {
9058 key: "addShadow",
9059 value: function addShadow(add, i, attrs, source) {
9060 var _w$config$chart$dropS;
9061 var w = this.w;
9062 var blur = attrs.blur,
9063 top = attrs.top,
9064 left = attrs.left,
9065 color = attrs.color,
9066 opacity = attrs.opacity;
9067 color = Array.isArray(color) ? color[i] : color;
9068 if (((_w$config$chart$dropS = w.config.chart.dropShadow.enabledOnSeries) === null || _w$config$chart$dropS === void 0 ? void 0 : _w$config$chart$dropS.length) > 0) {
9069 if (w.config.chart.dropShadow.enabledOnSeries.indexOf(i) === -1) {
9070 return add;
9071 }
9072 }
9073 add.offset({
9074 in: source,
9075 dx: left,
9076 dy: top,
9077 result: 'offset'
9078 });
9079 add.gaussianBlur({
9080 in: 'offset',
9081 stdDeviation: blur,
9082 result: 'blur'
9083 });
9084 add.flood({
9085 'flood-color': color,
9086 'flood-opacity': opacity,
9087 result: 'flood'
9088 });
9089 add.composite({
9090 in: 'flood',
9091 in2: 'blur',
9092 operator: 'in',
9093 result: 'shadow'
9094 });
9095 add.merge(['shadow', source]);
9096 }
9097
9098 // directly adds dropShadow to the element and returns the same element.
9099 }, {
9100 key: "dropShadow",
9101 value: function dropShadow(el, attrs) {
9102 var _w$config$chart$dropS2,
9103 _this2 = this,
9104 _el$filterer4;
9105 var i = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
9106 var w = this.w;
9107 el.unfilter(true);
9108 if (Utils$1.isMsEdge() && w.config.chart.type === 'radialBar') {
9109 // in radialbar charts, dropshadow is clipping actual drawing in IE
9110 return el;
9111 }
9112 if (((_w$config$chart$dropS2 = w.config.chart.dropShadow.enabledOnSeries) === null || _w$config$chart$dropS2 === void 0 ? void 0 : _w$config$chart$dropS2.length) > 0) {
9113 var _w$config$chart$dropS3;
9114 if (((_w$config$chart$dropS3 = w.config.chart.dropShadow.enabledOnSeries) === null || _w$config$chart$dropS3 === void 0 ? void 0 : _w$config$chart$dropS3.indexOf(i)) === -1) {
9115 return el;
9116 }
9117 }
9118 el.filterWith(function (add) {
9119 _this2.addShadow(add, i, attrs, 'SourceGraphic');
9120 });
9121 if (!attrs.noUserSpaceOnUse) {
9122 var _el$filterer3, _el$filterer3$node;
9123 (_el$filterer3 = el.filterer()) === null || _el$filterer3 === void 0 ? void 0 : (_el$filterer3$node = _el$filterer3.node) === null || _el$filterer3$node === void 0 ? void 0 : _el$filterer3$node.setAttribute('filterUnits', 'userSpaceOnUse');
9124 }
9125
9126 // this scales the filter to a bigger size so that the dropshadow doesn't crops
9127 this._scaleFilterSize((_el$filterer4 = el.filterer()) === null || _el$filterer4 === void 0 ? void 0 : _el$filterer4.node);
9128 return el;
9129 }
9130 }, {
9131 key: "setSelectionFilter",
9132 value: function setSelectionFilter(el, realIndex, dataPointIndex) {
9133 var w = this.w;
9134 if (typeof w.globals.selectedDataPoints[realIndex] !== 'undefined') {
9135 if (w.globals.selectedDataPoints[realIndex].indexOf(dataPointIndex) > -1) {
9136 el.node.setAttribute('selected', true);
9137 var activeFilter = w.config.states.active.filter;
9138 if (activeFilter !== 'none') {
9139 this.applyFilter(el, realIndex, activeFilter.type);
9140 }
9141 }
9142 }
9143 }
9144 }, {
9145 key: "_scaleFilterSize",
9146 value: function _scaleFilterSize(el) {
9147 if (!el) return;
9148 var setAttributes = function setAttributes(attrs) {
9149 for (var key in attrs) {
9150 if (attrs.hasOwnProperty(key)) {
9151 el.setAttribute(key, attrs[key]);
9152 }
9153 }
9154 };
9155 setAttributes({
9156 width: '200%',
9157 height: '200%',
9158 x: '-50%',
9159 y: '-50%'
9160 });
9161 }
9162 }]);
9163 return Filters;
9164 }();
9165
9166 /**
9167 * ApexCharts Graphics Class for all drawing operations.
9168 *
9169 * @module Graphics
9170 **/
9171 var Graphics = /*#__PURE__*/function () {
9172 function Graphics(ctx) {
9173 _classCallCheck(this, Graphics);
9174 this.ctx = ctx;
9175 this.w = ctx.w;
9176 }
9177
9178 /*****************************************************************************
9179 * *
9180 * SVG Path Rounding Function *
9181 * Copyright (C) 2014 Yona Appletree *
9182 * *
9183 * Licensed under the Apache License, Version 2.0 (the "License"); *
9184 * you may not use this file except in compliance with the License. *
9185 * You may obtain a copy of the License at *
9186 * *
9187 * http://www.apache.org/licenses/LICENSE-2.0 *
9188 * *
9189 * Unless required by applicable law or agreed to in writing, software *
9190 * distributed under the License is distributed on an "AS IS" BASIS, *
9191 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
9192 * See the License for the specific language governing permissions and *
9193 * limitations under the License. *
9194 * *
9195 *****************************************************************************/
9196
9197 /**
9198 * SVG Path rounding function. Takes an input path string and outputs a path
9199 * string where all line-line corners have been rounded. Only supports absolute
9200 * commands at the moment.
9201 *
9202 * @param pathString The SVG input path
9203 * @param radius The amount to round the corners, either a value in the SVG
9204 * coordinate space, or, if useFractionalRadius is true, a value
9205 * from 0 to 1.
9206 * @returns A new SVG path string with the rounding
9207 */
9208 _createClass(Graphics, [{
9209 key: "roundPathCorners",
9210 value: function roundPathCorners(pathString, radius) {
9211 if (pathString.indexOf('NaN') > -1) pathString = '';
9212 function moveTowardsLength(movingPoint, targetPoint, amount) {
9213 var width = targetPoint.x - movingPoint.x;
9214 var height = targetPoint.y - movingPoint.y;
9215 var distance = Math.sqrt(width * width + height * height);
9216 return moveTowardsFractional(movingPoint, targetPoint, Math.min(1, amount / distance));
9217 }
9218 function moveTowardsFractional(movingPoint, targetPoint, fraction) {
9219 return {
9220 x: movingPoint.x + (targetPoint.x - movingPoint.x) * fraction,
9221 y: movingPoint.y + (targetPoint.y - movingPoint.y) * fraction
9222 };
9223 }
9224
9225 // Adjusts the ending position of a command
9226 function adjustCommand(cmd, newPoint) {
9227 if (cmd.length > 2) {
9228 cmd[cmd.length - 2] = newPoint.x;
9229 cmd[cmd.length - 1] = newPoint.y;
9230 }
9231 }
9232
9233 // Gives an {x, y} object for a command's ending position
9234 function pointForCommand(cmd) {
9235 return {
9236 x: parseFloat(cmd[cmd.length - 2]),
9237 y: parseFloat(cmd[cmd.length - 1])
9238 };
9239 }
9240
9241 // Split apart the path, handing concatonated letters and numbers
9242 var pathParts = pathString.split(/[,\s]/).reduce(function (parts, part) {
9243 var match = part.match(/^([a-zA-Z])(.+)/);
9244 if (match) {
9245 parts.push(match[1]);
9246 parts.push(match[2]);
9247 } else {
9248 parts.push(part);
9249 }
9250 return parts;
9251 }, []);
9252
9253 // Group the commands with their arguments for easier handling
9254 var commands = pathParts.reduce(function (commands, part) {
9255 if (parseFloat(part) == part && commands.length) {
9256 commands[commands.length - 1].push(part);
9257 } else {
9258 commands.push([part]);
9259 }
9260 return commands;
9261 }, []);
9262
9263 // The resulting commands, also grouped
9264 var resultCommands = [];
9265 if (commands.length > 1) {
9266 var startPoint = pointForCommand(commands[0]);
9267
9268 // Handle the close path case with a "virtual" closing line
9269 var virtualCloseLine = null;
9270 if (commands[commands.length - 1][0] == 'Z' && commands[0].length > 2) {
9271 virtualCloseLine = ['L', startPoint.x, startPoint.y];
9272 commands[commands.length - 1] = virtualCloseLine;
9273 }
9274
9275 // We always use the first command (but it may be mutated)
9276 resultCommands.push(commands[0]);
9277 for (var cmdIndex = 1; cmdIndex < commands.length; cmdIndex++) {
9278 var prevCmd = resultCommands[resultCommands.length - 1];
9279 var curCmd = commands[cmdIndex];
9280
9281 // Handle closing case
9282 var nextCmd = curCmd == virtualCloseLine ? commands[1] : commands[cmdIndex + 1];
9283
9284 // Nasty logic to decide if this path is a candidite.
9285 if (nextCmd && prevCmd && prevCmd.length > 2 && curCmd[0] == 'L' && nextCmd.length > 2 && nextCmd[0] == 'L') {
9286 // Calc the points we're dealing with
9287 var prevPoint = pointForCommand(prevCmd);
9288 var curPoint = pointForCommand(curCmd);
9289 var nextPoint = pointForCommand(nextCmd);
9290
9291 // The start and end of the cuve are just our point moved towards the previous and next points, respectivly
9292 var curveStart, curveEnd;
9293 curveStart = moveTowardsLength(curPoint, prevPoint, radius);
9294 curveEnd = moveTowardsLength(curPoint, nextPoint, radius);
9295
9296 // Adjust the current command and add it
9297 adjustCommand(curCmd, curveStart);
9298 curCmd.origPoint = curPoint;
9299 resultCommands.push(curCmd);
9300
9301 // The curve control points are halfway between the start/end of the curve and
9302 // the original point
9303 var startControl = moveTowardsFractional(curveStart, curPoint, 0.5);
9304 var endControl = moveTowardsFractional(curPoint, curveEnd, 0.5);
9305
9306 // Create the curve
9307 var curveCmd = ['C', startControl.x, startControl.y, endControl.x, endControl.y, curveEnd.x, curveEnd.y];
9308 // Save the original point for fractional calculations
9309 curveCmd.origPoint = curPoint;
9310 resultCommands.push(curveCmd);
9311 } else {
9312 // Pass through commands that don't qualify
9313 resultCommands.push(curCmd);
9314 }
9315 }
9316
9317 // Fix up the starting point and restore the close path if the path was orignally closed
9318 if (virtualCloseLine) {
9319 var newStartPoint = pointForCommand(resultCommands[resultCommands.length - 1]);
9320 resultCommands.push(['Z']);
9321 adjustCommand(resultCommands[0], newStartPoint);
9322 }
9323 } else {
9324 resultCommands = commands;
9325 }
9326 return resultCommands.reduce(function (str, c) {
9327 return str + c.join(' ') + ' ';
9328 }, '');
9329 }
9330 }, {
9331 key: "drawLine",
9332 value: function drawLine(x1, y1, x2, y2) {
9333 var lineColor = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '#a8a8a8';
9334 var dashArray = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
9335 var strokeWidth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
9336 var strokeLineCap = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'butt';
9337 var w = this.w;
9338 var line = w.globals.dom.Paper.line().attr({
9339 x1: x1,
9340 y1: y1,
9341 x2: x2,
9342 y2: y2,
9343 stroke: lineColor,
9344 'stroke-dasharray': dashArray,
9345 'stroke-width': strokeWidth,
9346 'stroke-linecap': strokeLineCap
9347 });
9348 return line;
9349 }
9350 }, {
9351 key: "drawRect",
9352 value: function drawRect() {
9353 var x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
9354 var y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
9355 var x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
9356 var y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
9357 var radius = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
9358 var color = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '#fefefe';
9359 var opacity = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 1;
9360 var strokeWidth = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
9361 var strokeColor = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
9362 var strokeDashArray = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 0;
9363 var w = this.w;
9364 var rect = w.globals.dom.Paper.rect();
9365 rect.attr({
9366 x: x1,
9367 y: y1,
9368 width: x2 > 0 ? x2 : 0,
9369 height: y2 > 0 ? y2 : 0,
9370 rx: radius,
9371 ry: radius,
9372 opacity: opacity,
9373 'stroke-width': strokeWidth !== null ? strokeWidth : 0,
9374 stroke: strokeColor !== null ? strokeColor : 'none',
9375 'stroke-dasharray': strokeDashArray
9376 });
9377
9378 // fix apexcharts.js#1410
9379 rect.node.setAttribute('fill', color);
9380 return rect;
9381 }
9382 }, {
9383 key: "drawPolygon",
9384 value: function drawPolygon(polygonString) {
9385 var stroke = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '#e1e1e1';
9386 var strokeWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
9387 var fill = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'none';
9388 var w = this.w;
9389 var polygon = w.globals.dom.Paper.polygon(polygonString).attr({
9390 fill: fill,
9391 stroke: stroke,
9392 'stroke-width': strokeWidth
9393 });
9394 return polygon;
9395 }
9396 }, {
9397 key: "drawCircle",
9398 value: function drawCircle(radius) {
9399 var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
9400 var w = this.w;
9401 if (radius < 0) radius = 0;
9402 var c = w.globals.dom.Paper.circle(radius * 2);
9403 if (attrs !== null) {
9404 c.attr(attrs);
9405 }
9406 return c;
9407 }
9408 }, {
9409 key: "drawPath",
9410 value: function drawPath(_ref) {
9411 var _ref$d = _ref.d,
9412 d = _ref$d === void 0 ? '' : _ref$d,
9413 _ref$stroke = _ref.stroke,
9414 stroke = _ref$stroke === void 0 ? '#a8a8a8' : _ref$stroke,
9415 _ref$strokeWidth = _ref.strokeWidth,
9416 strokeWidth = _ref$strokeWidth === void 0 ? 1 : _ref$strokeWidth,
9417 fill = _ref.fill,
9418 _ref$fillOpacity = _ref.fillOpacity,
9419 fillOpacity = _ref$fillOpacity === void 0 ? 1 : _ref$fillOpacity,
9420 _ref$strokeOpacity = _ref.strokeOpacity,
9421 strokeOpacity = _ref$strokeOpacity === void 0 ? 1 : _ref$strokeOpacity,
9422 classes = _ref.classes,
9423 _ref$strokeLinecap = _ref.strokeLinecap,
9424 strokeLinecap = _ref$strokeLinecap === void 0 ? null : _ref$strokeLinecap,
9425 _ref$strokeDashArray = _ref.strokeDashArray,
9426 strokeDashArray = _ref$strokeDashArray === void 0 ? 0 : _ref$strokeDashArray;
9427 var w = this.w;
9428 if (strokeLinecap === null) {
9429 strokeLinecap = w.config.stroke.lineCap;
9430 }
9431 if (d.indexOf('undefined') > -1 || d.indexOf('NaN') > -1) {
9432 d = "M 0 ".concat(w.globals.gridHeight);
9433 }
9434 var p = w.globals.dom.Paper.path(d).attr({
9435 fill: fill,
9436 'fill-opacity': fillOpacity,
9437 stroke: stroke,
9438 'stroke-opacity': strokeOpacity,
9439 'stroke-linecap': strokeLinecap,
9440 'stroke-width': strokeWidth,
9441 'stroke-dasharray': strokeDashArray,
9442 class: classes
9443 });
9444 return p;
9445 }
9446 }, {
9447 key: "group",
9448 value: function group() {
9449 var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
9450 var w = this.w;
9451 var g = w.globals.dom.Paper.group();
9452 if (attrs !== null) {
9453 g.attr(attrs);
9454 }
9455 return g;
9456 }
9457 }, {
9458 key: "move",
9459 value: function move(x, y) {
9460 var move = ['M', x, y].join(' ');
9461 return move;
9462 }
9463 }, {
9464 key: "line",
9465 value: function line(x, y) {
9466 var hORv = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
9467 var line = null;
9468 if (hORv === null) {
9469 line = [' L', x, y].join(' ');
9470 } else if (hORv === 'H') {
9471 line = [' H', x].join(' ');
9472 } else if (hORv === 'V') {
9473 line = [' V', y].join(' ');
9474 }
9475 return line;
9476 }
9477 }, {
9478 key: "curve",
9479 value: function curve(x1, y1, x2, y2, x, y) {
9480 var curve = ['C', x1, y1, x2, y2, x, y].join(' ');
9481 return curve;
9482 }
9483 }, {
9484 key: "quadraticCurve",
9485 value: function quadraticCurve(x1, y1, x, y) {
9486 var curve = ['Q', x1, y1, x, y].join(' ');
9487 return curve;
9488 }
9489 }, {
9490 key: "arc",
9491 value: function arc(rx, ry, axisRotation, largeArcFlag, sweepFlag, x, y) {
9492 var relative = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
9493 var coord = 'A';
9494 if (relative) coord = 'a';
9495 var arc = [coord, rx, ry, axisRotation, largeArcFlag, sweepFlag, x, y].join(' ');
9496 return arc;
9497 }
9498
9499 /**
9500 * @memberof Graphics
9501 * @param {object}
9502 * i = series's index
9503 * realIndex = realIndex is series's actual index when it was drawn time. After several redraws, the iterating "i" may change in loops, but realIndex doesn't
9504 * pathFrom = existing pathFrom to animateTo
9505 * pathTo = new Path to which d attr will be animated from pathFrom to pathTo
9506 * stroke = line Color
9507 * strokeWidth = width of path Line
9508 * fill = it can be gradient, single color, pattern or image
9509 * animationDelay = how much to delay when starting animation (in milliseconds)
9510 * dataChangeSpeed = for dynamic animations, when data changes
9511 * className = class attribute to add
9512 * @return {object} svg.js path object
9513 **/
9514 }, {
9515 key: "renderPaths",
9516 value: function renderPaths(_ref2) {
9517 var j = _ref2.j,
9518 realIndex = _ref2.realIndex,
9519 pathFrom = _ref2.pathFrom,
9520 pathTo = _ref2.pathTo,
9521 stroke = _ref2.stroke,
9522 strokeWidth = _ref2.strokeWidth,
9523 strokeLinecap = _ref2.strokeLinecap,
9524 fill = _ref2.fill,
9525 animationDelay = _ref2.animationDelay,
9526 initialSpeed = _ref2.initialSpeed,
9527 dataChangeSpeed = _ref2.dataChangeSpeed,
9528 className = _ref2.className,
9529 chartType = _ref2.chartType,
9530 _ref2$shouldClipToGri = _ref2.shouldClipToGrid,
9531 shouldClipToGrid = _ref2$shouldClipToGri === void 0 ? true : _ref2$shouldClipToGri,
9532 _ref2$bindEventsOnPat = _ref2.bindEventsOnPaths,
9533 bindEventsOnPaths = _ref2$bindEventsOnPat === void 0 ? true : _ref2$bindEventsOnPat,
9534 _ref2$drawShadow = _ref2.drawShadow,
9535 drawShadow = _ref2$drawShadow === void 0 ? true : _ref2$drawShadow;
9536 var w = this.w;
9537 var filters = new Filters(this.ctx);
9538 var anim = new Animations(this.ctx);
9539 var initialAnim = this.w.config.chart.animations.enabled;
9540 var dynamicAnim = initialAnim && this.w.config.chart.animations.dynamicAnimation.enabled;
9541
9542 // Fix for paths starting with M 0 0
9543 if (pathFrom && pathFrom.startsWith('M 0 0') && pathTo) {
9544 var moveCommand = pathTo.match(/^M\s+[\d.-]+\s+[\d.-]+/);
9545 if (moveCommand) {
9546 pathFrom = pathFrom.replace(/^M\s+0\s+0/, moveCommand[0]);
9547 }
9548 }
9549 var d;
9550 var shouldAnimate = !!(initialAnim && !w.globals.resized || dynamicAnim && w.globals.dataChanged && w.globals.shouldAnimate);
9551 if (shouldAnimate) {
9552 d = pathFrom;
9553 } else {
9554 d = pathTo;
9555 w.globals.animationEnded = true;
9556 }
9557 var strokeDashArrayOpt = w.config.stroke.dashArray;
9558 var strokeDashArray = 0;
9559 if (Array.isArray(strokeDashArrayOpt)) {
9560 strokeDashArray = strokeDashArrayOpt[realIndex];
9561 } else {
9562 strokeDashArray = w.config.stroke.dashArray;
9563 }
9564 var el = this.drawPath({
9565 d: d,
9566 stroke: stroke,
9567 strokeWidth: strokeWidth,
9568 fill: fill,
9569 fillOpacity: 1,
9570 classes: className,
9571 strokeLinecap: strokeLinecap,
9572 strokeDashArray: strokeDashArray
9573 });
9574 el.attr('index', realIndex);
9575 if (shouldClipToGrid) {
9576 if (chartType === 'bar' && !w.globals.isHorizontal || w.globals.comboCharts) {
9577 el.attr({
9578 'clip-path': "url(#gridRectBarMask".concat(w.globals.cuid, ")")
9579 });
9580 } else {
9581 el.attr({
9582 'clip-path': "url(#gridRectMask".concat(w.globals.cuid, ")")
9583 });
9584 }
9585 }
9586 if (w.config.chart.dropShadow.enabled && drawShadow) {
9587 filters.dropShadow(el, w.config.chart.dropShadow, realIndex);
9588 }
9589 if (bindEventsOnPaths) {
9590 el.node.addEventListener('mouseenter', this.pathMouseEnter.bind(this, el));
9591 el.node.addEventListener('mouseleave', this.pathMouseLeave.bind(this, el));
9592 el.node.addEventListener('mousedown', this.pathMouseDown.bind(this, el));
9593 }
9594 el.attr({
9595 pathTo: pathTo,
9596 pathFrom: pathFrom
9597 });
9598 var defaultAnimateOpts = {
9599 el: el,
9600 j: j,
9601 realIndex: realIndex,
9602 pathFrom: pathFrom,
9603 pathTo: pathTo,
9604 fill: fill,
9605 strokeWidth: strokeWidth,
9606 delay: animationDelay
9607 };
9608 if (initialAnim && !w.globals.resized && !w.globals.dataChanged) {
9609 anim.animatePathsGradually(_objectSpread2(_objectSpread2({}, defaultAnimateOpts), {}, {
9610 speed: initialSpeed
9611 }));
9612 } else {
9613 if (w.globals.resized || !w.globals.dataChanged) {
9614 anim.showDelayedElements();
9615 }
9616 }
9617 if (w.globals.dataChanged && dynamicAnim && shouldAnimate) {
9618 anim.animatePathsGradually(_objectSpread2(_objectSpread2({}, defaultAnimateOpts), {}, {
9619 speed: dataChangeSpeed
9620 }));
9621 }
9622 return el;
9623 }
9624 }, {
9625 key: "drawPattern",
9626 value: function drawPattern(style, width, height) {
9627 var stroke = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '#a8a8a8';
9628 var strokeWidth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
9629 var w = this.w;
9630 var p = w.globals.dom.Paper.pattern(width, height, function (add) {
9631 if (style === 'horizontalLines') {
9632 add.line(0, 0, height, 0).stroke({
9633 color: stroke,
9634 width: strokeWidth + 1
9635 });
9636 } else if (style === 'verticalLines') {
9637 add.line(0, 0, 0, width).stroke({
9638 color: stroke,
9639 width: strokeWidth + 1
9640 });
9641 } else if (style === 'slantedLines') {
9642 add.line(0, 0, width, height).stroke({
9643 color: stroke,
9644 width: strokeWidth
9645 });
9646 } else if (style === 'squares') {
9647 add.rect(width, height).fill('none').stroke({
9648 color: stroke,
9649 width: strokeWidth
9650 });
9651 } else if (style === 'circles') {
9652 add.circle(width).fill('none').stroke({
9653 color: stroke,
9654 width: strokeWidth
9655 });
9656 }
9657 });
9658 return p;
9659 }
9660 }, {
9661 key: "drawGradient",
9662 value: function drawGradient(style, gfrom, gto, opacityFrom, opacityTo) {
9663 var size = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
9664 var stops = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
9665 var colorStops = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : [];
9666 var i = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 0;
9667 var w = this.w;
9668 var g;
9669 if (gfrom.length < 9 && gfrom.indexOf('#') === 0) {
9670 // if the hex contains alpha and is of 9 digit, skip the opacity
9671 gfrom = Utils$1.hexToRgba(gfrom, opacityFrom);
9672 }
9673 if (gto.length < 9 && gto.indexOf('#') === 0) {
9674 gto = Utils$1.hexToRgba(gto, opacityTo);
9675 }
9676 var stop1 = 0;
9677 var stop2 = 1;
9678 var stop3 = 1;
9679 var stop4 = null;
9680 if (stops !== null) {
9681 stop1 = typeof stops[0] !== 'undefined' ? stops[0] / 100 : 0;
9682 stop2 = typeof stops[1] !== 'undefined' ? stops[1] / 100 : 1;
9683 stop3 = typeof stops[2] !== 'undefined' ? stops[2] / 100 : 1;
9684 stop4 = typeof stops[3] !== 'undefined' ? stops[3] / 100 : null;
9685 }
9686 var radial = !!(w.config.chart.type === 'donut' || w.config.chart.type === 'pie' || w.config.chart.type === 'polarArea' || w.config.chart.type === 'bubble');
9687 if (!colorStops || colorStops.length === 0) {
9688 g = w.globals.dom.Paper.gradient(radial ? 'radial' : 'linear', function (add) {
9689 add.stop(stop1, gfrom, opacityFrom);
9690 add.stop(stop2, gto, opacityTo);
9691 add.stop(stop3, gto, opacityTo);
9692 if (stop4 !== null) {
9693 add.stop(stop4, gfrom, opacityFrom);
9694 }
9695 });
9696 } else {
9697 g = w.globals.dom.Paper.gradient(radial ? 'radial' : 'linear', function (add) {
9698 var gradientStops = Array.isArray(colorStops[i]) ? colorStops[i] : colorStops;
9699 gradientStops.forEach(function (s) {
9700 add.stop(s.offset / 100, s.color, s.opacity);
9701 });
9702 });
9703 }
9704 if (!radial) {
9705 if (style === 'vertical') {
9706 g.from(0, 0).to(0, 1);
9707 } else if (style === 'diagonal') {
9708 g.from(0, 0).to(1, 1);
9709 } else if (style === 'horizontal') {
9710 g.from(0, 1).to(1, 1);
9711 } else if (style === 'diagonal2') {
9712 g.from(1, 0).to(0, 1);
9713 }
9714 } else {
9715 var offx = w.globals.gridWidth / 2;
9716 var offy = w.globals.gridHeight / 2;
9717 if (w.config.chart.type !== 'bubble') {
9718 g.attr({
9719 gradientUnits: 'userSpaceOnUse',
9720 cx: offx,
9721 cy: offy,
9722 r: size
9723 });
9724 } else {
9725 g.attr({
9726 cx: 0.5,
9727 cy: 0.5,
9728 r: 0.8,
9729 fx: 0.2,
9730 fy: 0.2
9731 });
9732 }
9733 }
9734 return g;
9735 }
9736 }, {
9737 key: "getTextBasedOnMaxWidth",
9738 value: function getTextBasedOnMaxWidth(_ref3) {
9739 var text = _ref3.text,
9740 maxWidth = _ref3.maxWidth,
9741 fontSize = _ref3.fontSize,
9742 fontFamily = _ref3.fontFamily;
9743 var tRects = this.getTextRects(text, fontSize, fontFamily);
9744 var wordWidth = tRects.width / text.length;
9745 var wordsBasedOnWidth = Math.floor(maxWidth / wordWidth);
9746 if (maxWidth < tRects.width) {
9747 return text.slice(0, wordsBasedOnWidth - 3) + '...';
9748 }
9749 return text;
9750 }
9751 }, {
9752 key: "drawText",
9753 value: function drawText(_ref4) {
9754 var _this = this;
9755 var x = _ref4.x,
9756 y = _ref4.y,
9757 text = _ref4.text,
9758 textAnchor = _ref4.textAnchor,
9759 fontSize = _ref4.fontSize,
9760 fontFamily = _ref4.fontFamily,
9761 fontWeight = _ref4.fontWeight,
9762 foreColor = _ref4.foreColor,
9763 opacity = _ref4.opacity,
9764 maxWidth = _ref4.maxWidth,
9765 _ref4$cssClass = _ref4.cssClass,
9766 cssClass = _ref4$cssClass === void 0 ? '' : _ref4$cssClass,
9767 _ref4$isPlainText = _ref4.isPlainText,
9768 isPlainText = _ref4$isPlainText === void 0 ? true : _ref4$isPlainText,
9769 _ref4$dominantBaselin = _ref4.dominantBaseline,
9770 dominantBaseline = _ref4$dominantBaselin === void 0 ? 'auto' : _ref4$dominantBaselin;
9771 var w = this.w;
9772 if (typeof text === 'undefined') text = '';
9773 var truncatedText = text;
9774 if (!textAnchor) {
9775 textAnchor = 'start';
9776 }
9777 if (!foreColor || !foreColor.length) {
9778 foreColor = w.config.chart.foreColor;
9779 }
9780 fontFamily = fontFamily || w.config.chart.fontFamily;
9781 fontSize = fontSize || '11px';
9782 fontWeight = fontWeight || 'regular';
9783 var commonProps = {
9784 maxWidth: maxWidth,
9785 fontSize: fontSize,
9786 fontFamily: fontFamily
9787 };
9788 var elText;
9789 if (Array.isArray(text)) {
9790 elText = w.globals.dom.Paper.text(function (add) {
9791 for (var i = 0; i < text.length; i++) {
9792 truncatedText = text[i];
9793 if (maxWidth) {
9794 truncatedText = _this.getTextBasedOnMaxWidth(_objectSpread2({
9795 text: text[i]
9796 }, commonProps));
9797 }
9798 i === 0 ? add.tspan(truncatedText) : add.tspan(truncatedText).newLine();
9799 }
9800 });
9801 } else {
9802 if (maxWidth) {
9803 truncatedText = this.getTextBasedOnMaxWidth(_objectSpread2({
9804 text: text
9805 }, commonProps));
9806 }
9807 elText = isPlainText ? w.globals.dom.Paper.plain(text) : w.globals.dom.Paper.text(function (add) {
9808 return add.tspan(truncatedText);
9809 });
9810 }
9811 elText.attr({
9812 x: x,
9813 y: y,
9814 'text-anchor': textAnchor,
9815 'dominant-baseline': dominantBaseline,
9816 'font-size': fontSize,
9817 'font-family': fontFamily,
9818 'font-weight': fontWeight,
9819 fill: foreColor,
9820 class: 'apexcharts-text ' + cssClass
9821 });
9822 elText.node.style.fontFamily = fontFamily;
9823 elText.node.style.opacity = opacity;
9824 return elText;
9825 }
9826 }, {
9827 key: "getMarkerPath",
9828 value: function getMarkerPath(x, y, type, size) {
9829 var d = '';
9830 switch (type) {
9831 case 'cross':
9832 size = size / 1.4;
9833 d = "M ".concat(x - size, " ").concat(y - size, " L ").concat(x + size, " ").concat(y + size, " M ").concat(x - size, " ").concat(y + size, " L ").concat(x + size, " ").concat(y - size);
9834 break;
9835 case 'plus':
9836 size = size / 1.12;
9837 d = "M ".concat(x - size, " ").concat(y, " L ").concat(x + size, " ").concat(y, " M ").concat(x, " ").concat(y - size, " L ").concat(x, " ").concat(y + size);
9838 break;
9839 case 'star':
9840 case 'sparkle':
9841 var points = 5;
9842 size = size * 1.15;
9843 if (type === 'sparkle') {
9844 size = size / 1.1;
9845 points = 4;
9846 }
9847 var step = Math.PI / points;
9848 for (var i = 0; i <= 2 * points; i++) {
9849 var angle = i * step;
9850 var radius = i % 2 === 0 ? size : size / 2;
9851 var xPos = x + radius * Math.sin(angle);
9852 var yPos = y - radius * Math.cos(angle);
9853 d += (i === 0 ? 'M' : 'L') + xPos + ',' + yPos;
9854 }
9855 d += 'Z';
9856 break;
9857 case 'triangle':
9858 d = "M ".concat(x, " ").concat(y - size, " \n L ").concat(x + size, " ").concat(y + size, " \n L ").concat(x - size, " ").concat(y + size, " \n Z");
9859 break;
9860 case 'square':
9861 case 'rect':
9862 size = size / 1.125;
9863 d = "M ".concat(x - size, " ").concat(y - size, " \n L ").concat(x + size, " ").concat(y - size, " \n L ").concat(x + size, " ").concat(y + size, " \n L ").concat(x - size, " ").concat(y + size, " \n Z");
9864 break;
9865 case 'diamond':
9866 size = size * 1.05;
9867 d = "M ".concat(x, " ").concat(y - size, " \n L ").concat(x + size, " ").concat(y, " \n L ").concat(x, " ").concat(y + size, " \n L ").concat(x - size, " ").concat(y, " \n Z");
9868 break;
9869 case 'line':
9870 size = size / 1.1;
9871 d = "M ".concat(x - size, " ").concat(y, " \n L ").concat(x + size, " ").concat(y);
9872 break;
9873 case 'circle':
9874 default:
9875 size = size * 2;
9876 d = "M ".concat(x, ", ").concat(y, " \n m -").concat(size / 2, ", 0 \n a ").concat(size / 2, ",").concat(size / 2, " 0 1,0 ").concat(size, ",0 \n a ").concat(size / 2, ",").concat(size / 2, " 0 1,0 -").concat(size, ",0");
9877 break;
9878 }
9879 return d;
9880 }
9881
9882 /**
9883 * @param {number} x - The x-coordinate of the marker
9884 * @param {number} y - The y-coordinate of the marker.
9885 * @param {number} size - The size of the marker
9886 * @param {Object} opts - The options for the marker.
9887 * @returns {Object} The created marker.
9888 */
9889 }, {
9890 key: "drawMarkerShape",
9891 value: function drawMarkerShape(x, y, type, size, opts) {
9892 var path = this.drawPath({
9893 d: this.getMarkerPath(x, y, type, size, opts),
9894 stroke: opts.pointStrokeColor,
9895 strokeDashArray: opts.pointStrokeDashArray,
9896 strokeWidth: opts.pointStrokeWidth,
9897 fill: opts.pointFillColor,
9898 fillOpacity: opts.pointFillOpacity,
9899 strokeOpacity: opts.pointStrokeOpacity
9900 });
9901 path.attr({
9902 cx: x,
9903 cy: y,
9904 shape: opts.shape,
9905 class: opts.class ? opts.class : ''
9906 });
9907 return path;
9908 }
9909 }, {
9910 key: "drawMarker",
9911 value: function drawMarker(x, y, opts) {
9912 x = x || 0;
9913 var size = opts.pSize || 0;
9914 if (!Utils$1.isNumber(y)) {
9915 size = 0;
9916 y = 0;
9917 }
9918 return this.drawMarkerShape(x, y, opts === null || opts === void 0 ? void 0 : opts.shape, size, _objectSpread2(_objectSpread2({}, opts), opts.shape === 'line' || opts.shape === 'plus' || opts.shape === 'cross' ? {
9919 pointStrokeColor: opts.pointFillColor,
9920 pointStrokeOpacity: opts.pointFillOpacity
9921 } : {}));
9922 }
9923 }, {
9924 key: "pathMouseEnter",
9925 value: function pathMouseEnter(path, e) {
9926 var w = this.w;
9927 var filters = new Filters(this.ctx);
9928 var i = parseInt(path.node.getAttribute('index'), 10);
9929 var j = parseInt(path.node.getAttribute('j'), 10);
9930 if (typeof w.config.chart.events.dataPointMouseEnter === 'function') {
9931 w.config.chart.events.dataPointMouseEnter(e, this.ctx, {
9932 seriesIndex: i,
9933 dataPointIndex: j,
9934 w: w
9935 });
9936 }
9937 this.ctx.events.fireEvent('dataPointMouseEnter', [e, this.ctx, {
9938 seriesIndex: i,
9939 dataPointIndex: j,
9940 w: w
9941 }]);
9942 if (w.config.states.active.filter.type !== 'none') {
9943 if (path.node.getAttribute('selected') === 'true') {
9944 return;
9945 }
9946 }
9947 if (w.config.states.hover.filter.type !== 'none') {
9948 if (!w.globals.isTouchDevice) {
9949 var hoverFilter = w.config.states.hover.filter;
9950 filters.applyFilter(path, i, hoverFilter.type);
9951 }
9952 }
9953 }
9954 }, {
9955 key: "pathMouseLeave",
9956 value: function pathMouseLeave(path, e) {
9957 var w = this.w;
9958 var filters = new Filters(this.ctx);
9959 var i = parseInt(path.node.getAttribute('index'), 10);
9960 var j = parseInt(path.node.getAttribute('j'), 10);
9961 if (typeof w.config.chart.events.dataPointMouseLeave === 'function') {
9962 w.config.chart.events.dataPointMouseLeave(e, this.ctx, {
9963 seriesIndex: i,
9964 dataPointIndex: j,
9965 w: w
9966 });
9967 }
9968 this.ctx.events.fireEvent('dataPointMouseLeave', [e, this.ctx, {
9969 seriesIndex: i,
9970 dataPointIndex: j,
9971 w: w
9972 }]);
9973 if (w.config.states.active.filter.type !== 'none') {
9974 if (path.node.getAttribute('selected') === 'true') {
9975 return;
9976 }
9977 }
9978 if (w.config.states.hover.filter.type !== 'none') {
9979 filters.getDefaultFilter(path, i);
9980 }
9981 }
9982 }, {
9983 key: "pathMouseDown",
9984 value: function pathMouseDown(path, e) {
9985 var w = this.w;
9986 var filters = new Filters(this.ctx);
9987 var i = parseInt(path.node.getAttribute('index'), 10);
9988 var j = parseInt(path.node.getAttribute('j'), 10);
9989 var selected = 'false';
9990 if (path.node.getAttribute('selected') === 'true') {
9991 path.node.setAttribute('selected', 'false');
9992 if (w.globals.selectedDataPoints[i].indexOf(j) > -1) {
9993 var index = w.globals.selectedDataPoints[i].indexOf(j);
9994 w.globals.selectedDataPoints[i].splice(index, 1);
9995 }
9996 } else {
9997 if (!w.config.states.active.allowMultipleDataPointsSelection && w.globals.selectedDataPoints.length > 0) {
9998 w.globals.selectedDataPoints = [];
9999 var elPaths = w.globals.dom.Paper.find('.apexcharts-series path:not(.apexcharts-decoration-element)');
10000 var elCircles = w.globals.dom.Paper.find('.apexcharts-series circle:not(.apexcharts-decoration-element), .apexcharts-series rect:not(.apexcharts-decoration-element)');
10001 var deSelect = function deSelect(els) {
10002 Array.prototype.forEach.call(els, function (el) {
10003 el.node.setAttribute('selected', 'false');
10004 filters.getDefaultFilter(el, i);
10005 });
10006 };
10007 deSelect(elPaths);
10008 deSelect(elCircles);
10009 }
10010 path.node.setAttribute('selected', 'true');
10011 selected = 'true';
10012 if (typeof w.globals.selectedDataPoints[i] === 'undefined') {
10013 w.globals.selectedDataPoints[i] = [];
10014 }
10015 w.globals.selectedDataPoints[i].push(j);
10016 }
10017 if (selected === 'true') {
10018 var activeFilter = w.config.states.active.filter;
10019 if (activeFilter !== 'none') {
10020 filters.applyFilter(path, i, activeFilter.type);
10021 } else {
10022 // Reapply the hover filter in case it was removed by `deselect`when there is no active filter and it is not a touch device
10023 if (w.config.states.hover.filter !== 'none') {
10024 if (!w.globals.isTouchDevice) {
10025 var hoverFilter = w.config.states.hover.filter;
10026 filters.applyFilter(path, i, hoverFilter.type);
10027 }
10028 }
10029 }
10030 } else {
10031 // If the item was deselected, apply hover state filter if it is not a touch device
10032 if (w.config.states.active.filter.type !== 'none') {
10033 if (w.config.states.hover.filter.type !== 'none' && !w.globals.isTouchDevice) {
10034 var hoverFilter = w.config.states.hover.filter;
10035 filters.applyFilter(path, i, hoverFilter.type);
10036 } else {
10037 filters.getDefaultFilter(path, i);
10038 }
10039 }
10040 }
10041 if (typeof w.config.chart.events.dataPointSelection === 'function') {
10042 w.config.chart.events.dataPointSelection(e, this.ctx, {
10043 selectedDataPoints: w.globals.selectedDataPoints,
10044 seriesIndex: i,
10045 dataPointIndex: j,
10046 w: w
10047 });
10048 }
10049 if (e) {
10050 this.ctx.events.fireEvent('dataPointSelection', [e, this.ctx, {
10051 selectedDataPoints: w.globals.selectedDataPoints,
10052 seriesIndex: i,
10053 dataPointIndex: j,
10054 w: w
10055 }]);
10056 }
10057 }
10058 }, {
10059 key: "rotateAroundCenter",
10060 value: function rotateAroundCenter(el) {
10061 var coord = {};
10062 if (el && typeof el.getBBox === 'function') {
10063 coord = el.getBBox();
10064 }
10065 var x = coord.x + coord.width / 2;
10066 var y = coord.y + coord.height / 2;
10067 return {
10068 x: x,
10069 y: y
10070 };
10071 }
10072 }, {
10073 key: "getTextRects",
10074 value: function getTextRects(text, fontSize, fontFamily, transform) {
10075 var useBBox = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
10076 var w = this.w;
10077 var virtualText = this.drawText({
10078 x: -200,
10079 y: -200,
10080 text: text,
10081 textAnchor: 'start',
10082 fontSize: fontSize,
10083 fontFamily: fontFamily,
10084 foreColor: '#fff',
10085 opacity: 0
10086 });
10087 if (transform) {
10088 virtualText.attr('transform', transform);
10089 }
10090 w.globals.dom.Paper.add(virtualText);
10091 var rect = virtualText.bbox();
10092 if (!useBBox) {
10093 rect = virtualText.node.getBoundingClientRect();
10094 }
10095 virtualText.remove();
10096 return {
10097 width: rect.width,
10098 height: rect.height
10099 };
10100 }
10101
10102 /**
10103 * append ... to long text
10104 * http://stackoverflow.com/questions/9241315/trimming-text-to-a-given-pixel-width-in-svg
10105 * @memberof Graphics
10106 **/
10107 }, {
10108 key: "placeTextWithEllipsis",
10109 value: function placeTextWithEllipsis(textObj, textString, width) {
10110 if (typeof textObj.getComputedTextLength !== 'function') return;
10111 textObj.textContent = textString;
10112 if (textString.length > 0) {
10113 // ellipsis is needed
10114 if (textObj.getComputedTextLength() >= width / 1.1) {
10115 for (var x = textString.length - 3; x > 0; x -= 3) {
10116 if (textObj.getSubStringLength(0, x) <= width / 1.1) {
10117 textObj.textContent = textString.substring(0, x) + '...';
10118 return;
10119 }
10120 }
10121 textObj.textContent = '.'; // can't place at all
10122 }
10123 }
10124 }
10125 }], [{
10126 key: "setAttrs",
10127 value: function setAttrs(el, attrs) {
10128 for (var key in attrs) {
10129 if (attrs.hasOwnProperty(key)) {
10130 el.setAttribute(key, attrs[key]);
10131 }
10132 }
10133 }
10134 }]);
10135 return Graphics;
10136 }();
10137
10138 /*
10139 ** Util functions which are dependent on ApexCharts instance
10140 */
10141 var CoreUtils = /*#__PURE__*/function () {
10142 function CoreUtils(ctx) {
10143 _classCallCheck(this, CoreUtils);
10144 this.ctx = ctx;
10145 this.w = ctx.w;
10146 }
10147 _createClass(CoreUtils, [{
10148 key: "getStackedSeriesTotals",
10149 value:
10150 /**
10151 * @memberof CoreUtils
10152 * returns the sum of all individual values in a multiple stacked series
10153 * Eg. w.globals.series = [[32,33,43,12], [2,3,5,1]]
10154 * @return [34,36,48,13]
10155 **/
10156 function getStackedSeriesTotals() {
10157 var excludedSeriesIndices = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
10158 var w = this.w;
10159 var total = [];
10160 if (w.globals.series.length === 0) return total;
10161 for (var i = 0; i < w.globals.series[w.globals.maxValsInArrayIndex].length; i++) {
10162 var t = 0;
10163 for (var j = 0; j < w.globals.series.length; j++) {
10164 if (typeof w.globals.series[j][i] !== 'undefined' && excludedSeriesIndices.indexOf(j) === -1) {
10165 t += w.globals.series[j][i];
10166 }
10167 }
10168 total.push(t);
10169 }
10170 return total;
10171 }
10172
10173 // get total of the all values inside all series
10174 }, {
10175 key: "getSeriesTotalByIndex",
10176 value: function getSeriesTotalByIndex() {
10177 var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
10178 if (index === null) {
10179 // non-plot chart types - pie / donut / circle
10180 return this.w.config.series.reduce(function (acc, cur) {
10181 return acc + cur;
10182 }, 0);
10183 } else {
10184 // axis charts - supporting multiple series
10185 return this.w.globals.series[index].reduce(function (acc, cur) {
10186 return acc + cur;
10187 }, 0);
10188 }
10189 }
10190
10191 /**
10192 * @memberof CoreUtils
10193 * returns the sum of values in a multiple stacked grouped charts
10194 * Eg. w.globals.series = [[32,33,43,12], [2,3,5,1], [43, 23, 34, 22]]
10195 * series 1 and 2 are in a group, while series 3 is in another group
10196 * @return [[34, 36, 48, 12], [43, 23, 34, 22]]
10197 **/
10198 }, {
10199 key: "getStackedSeriesTotalsByGroups",
10200 value: function getStackedSeriesTotalsByGroups() {
10201 var _this = this;
10202 var w = this.w;
10203 var total = [];
10204 w.globals.seriesGroups.forEach(function (sg) {
10205 var includedIndexes = [];
10206 w.config.series.forEach(function (s, si) {
10207 if (sg.indexOf(w.globals.seriesNames[si]) > -1) {
10208 includedIndexes.push(si);
10209 }
10210 });
10211 var excludedIndices = w.globals.series.map(function (_, fi) {
10212 return includedIndexes.indexOf(fi) === -1 ? fi : -1;
10213 }).filter(function (f) {
10214 return f !== -1;
10215 });
10216 total.push(_this.getStackedSeriesTotals(excludedIndices));
10217 });
10218 return total;
10219 }
10220 }, {
10221 key: "setSeriesYAxisMappings",
10222 value: function setSeriesYAxisMappings() {
10223 var gl = this.w.globals;
10224 var cnf = this.w.config;
10225
10226 // The old config method to map multiple series to a y axis is to
10227 // include one yaxis config per series but set each yaxis seriesName to the
10228 // same series name. This relies on indexing equivalence to map series to
10229 // an axis: series[n] => yaxis[n]. This needs to be retained for compatibility.
10230 // But we introduce an alternative that explicitly configures yaxis elements
10231 // with the series that will be referenced to them (seriesName: []). This
10232 // only requires including the yaxis elements that will be seen on the chart.
10233 // Old way:
10234 // ya: s
10235 // 0: 0
10236 // 1: 1
10237 // 2: 1
10238 // 3: 1
10239 // 4: 1
10240 // Axes 0..4 are all scaled and all will be rendered unless the axes are
10241 // show: false. If the chart is stacked, it's assumed that series 1..4 are
10242 // the contributing series. This is not particularly intuitive.
10243 // New way:
10244 // ya: s
10245 // 0: [0]
10246 // 1: [1,2,3,4]
10247 // If the chart is stacked, it can be assumed that any axis with multiple
10248 // series is stacked.
10249 //
10250 // If this is an old chart and we are being backward compatible, it will be
10251 // expected that each series is associated with it's corresponding yaxis
10252 // through their indices, one-to-one.
10253 // If yaxis.seriesName matches series.name, we have indices yi and si.
10254 // A name match where yi != si is interpretted as yaxis[yi] and yaxis[si]
10255 // will both be scaled to fit the combined series[si] and series[yi].
10256 // Consider series named: S0,S1,S2 and yaxes A0,A1,A2.
10257 //
10258 // Example 1: A0 and A1 scaled the same.
10259 // A0.seriesName: S0
10260 // A1.seriesName: S0
10261 // A2.seriesName: S2
10262 // Then A1 <-> A0
10263 //
10264 // Example 2: A0, A1 and A2 all scaled the same.
10265 // A0.seriesName: S2
10266 // A1.seriesName: S0
10267 // A2.seriesName: S1
10268 // A0 <-> A2, A1 <-> A0, A2 <-> A1 --->>> A0 <-> A1 <-> A2
10269
10270 var axisSeriesMap = [];
10271 var seriesYAxisReverseMap = [];
10272 var unassignedSeriesIndices = [];
10273 var seriesNameArrayStyle = gl.series.length > cnf.yaxis.length || cnf.yaxis.some(function (a) {
10274 return Array.isArray(a.seriesName);
10275 });
10276 cnf.series.forEach(function (s, i) {
10277 unassignedSeriesIndices.push(i);
10278 seriesYAxisReverseMap.push(null);
10279 });
10280 cnf.yaxis.forEach(function (yaxe, yi) {
10281 axisSeriesMap[yi] = [];
10282 });
10283 var unassignedYAxisIndices = [];
10284
10285 // here, we loop through the yaxis array and find the item which has "seriesName" property
10286 cnf.yaxis.forEach(function (yaxe, yi) {
10287 var assigned = false;
10288 // Allow seriesName to be either a string (for backward compatibility),
10289 // in which case, handle multiple yaxes referencing the same series.
10290 // or an array of strings so that a yaxis can reference multiple series.
10291 // Feature request #4237
10292 if (yaxe.seriesName) {
10293 var seriesNames = [];
10294 if (Array.isArray(yaxe.seriesName)) {
10295 seriesNames = yaxe.seriesName;
10296 } else {
10297 seriesNames.push(yaxe.seriesName);
10298 }
10299 seriesNames.forEach(function (name) {
10300 cnf.series.forEach(function (s, si) {
10301 if (s.name === name) {
10302 var remove = si;
10303 if (yi === si || seriesNameArrayStyle) {
10304 // New style, don't allow series to be double referenced
10305 if (!seriesNameArrayStyle || unassignedSeriesIndices.indexOf(si) > -1) {
10306 axisSeriesMap[yi].push([yi, si]);
10307 } else {
10308 console.warn("Series '" + s.name + "' referenced more than once in what looks like the new style." + ' That is, when using either seriesName: [],' + ' or when there are more series than yaxes.');
10309 }
10310 } else {
10311 // The series index refers to the target yaxis and the current
10312 // yaxis index refers to the actual referenced series.
10313 axisSeriesMap[si].push([si, yi]);
10314 remove = yi;
10315 }
10316 assigned = true;
10317 remove = unassignedSeriesIndices.indexOf(remove);
10318 if (remove !== -1) {
10319 unassignedSeriesIndices.splice(remove, 1);
10320 }
10321 }
10322 });
10323 });
10324 }
10325 if (!assigned) {
10326 unassignedYAxisIndices.push(yi);
10327 }
10328 });
10329 axisSeriesMap = axisSeriesMap.map(function (yaxe, yi) {
10330 var ra = [];
10331 yaxe.forEach(function (sa) {
10332 seriesYAxisReverseMap[sa[1]] = sa[0];
10333 ra.push(sa[1]);
10334 });
10335 return ra;
10336 });
10337
10338 // All series referenced directly by yaxes have been assigned to those axes.
10339 // Any series so far unassigned will be assigned to any yaxes that have yet
10340 // to reference series directly, one-for-one in order of appearance, with
10341 // all left-over series assigned to either the last unassigned yaxis, or the
10342 // last yaxis if all have assigned series. This captures the
10343 // default single and multiaxis config options which simply includes zero,
10344 // one or as many yaxes as there are series but do not reference them by name.
10345 var lastUnassignedYAxis = cnf.yaxis.length - 1;
10346 for (var i = 0; i < unassignedYAxisIndices.length; i++) {
10347 lastUnassignedYAxis = unassignedYAxisIndices[i];
10348 axisSeriesMap[lastUnassignedYAxis] = [];
10349 if (unassignedSeriesIndices) {
10350 var si = unassignedSeriesIndices[0];
10351 unassignedSeriesIndices.shift();
10352 axisSeriesMap[lastUnassignedYAxis].push(si);
10353 seriesYAxisReverseMap[si] = lastUnassignedYAxis;
10354 } else {
10355 break;
10356 }
10357 }
10358 unassignedSeriesIndices.forEach(function (i) {
10359 axisSeriesMap[lastUnassignedYAxis].push(i);
10360 seriesYAxisReverseMap[i] = lastUnassignedYAxis;
10361 });
10362
10363 // For the old-style seriesName-as-string-only, leave the zero-length yaxis
10364 // array elements in for compatibility so that series.length == yaxes.length
10365 // for multi axis charts.
10366 gl.seriesYAxisMap = axisSeriesMap.map(function (x) {
10367 return x;
10368 });
10369 gl.seriesYAxisReverseMap = seriesYAxisReverseMap.map(function (x) {
10370 return x;
10371 });
10372 // Set default series group names
10373 gl.seriesYAxisMap.forEach(function (axisSeries, ai) {
10374 axisSeries.forEach(function (si) {
10375 // series may be bare until loaded in realtime
10376 if (cnf.series[si] && cnf.series[si].group === undefined) {
10377 // A series with no group defined will be named after the axis that
10378 // referenced it and thus form a group automatically.
10379 cnf.series[si].group = 'apexcharts-axis-'.concat(ai.toString());
10380 }
10381 });
10382 });
10383 }
10384 }, {
10385 key: "isSeriesNull",
10386 value: function isSeriesNull() {
10387 var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
10388 var r = [];
10389 if (index === null) {
10390 // non-plot chart types - pie / donut / circle
10391 r = this.w.config.series.filter(function (d) {
10392 return d !== null;
10393 });
10394 } else {
10395 // axis charts - supporting multiple series
10396 r = this.w.config.series[index].data.filter(function (d) {
10397 return d !== null;
10398 });
10399 }
10400 return r.length === 0;
10401 }
10402 }, {
10403 key: "seriesHaveSameValues",
10404 value: function seriesHaveSameValues(index) {
10405 return this.w.globals.series[index].every(function (val, i, arr) {
10406 return val === arr[0];
10407 });
10408 }
10409 }, {
10410 key: "getCategoryLabels",
10411 value: function getCategoryLabels(labels) {
10412 var w = this.w;
10413 var catLabels = labels.slice();
10414 if (w.config.xaxis.convertedCatToNumeric) {
10415 catLabels = labels.map(function (i, li) {
10416 return w.config.xaxis.labels.formatter(i - w.globals.minX + 1);
10417 });
10418 }
10419 return catLabels;
10420 }
10421 // maxValsInArrayIndex is the index of series[] which has the largest number of items
10422 }, {
10423 key: "getLargestSeries",
10424 value: function getLargestSeries() {
10425 var w = this.w;
10426 w.globals.maxValsInArrayIndex = w.globals.series.map(function (a) {
10427 return a.length;
10428 }).indexOf(Math.max.apply(Math, w.globals.series.map(function (a) {
10429 return a.length;
10430 })));
10431 }
10432 }, {
10433 key: "getLargestMarkerSize",
10434 value: function getLargestMarkerSize() {
10435 var w = this.w;
10436 var size = 0;
10437 w.globals.markers.size.forEach(function (m) {
10438 size = Math.max(size, m);
10439 });
10440 if (w.config.markers.discrete && w.config.markers.discrete.length) {
10441 w.config.markers.discrete.forEach(function (m) {
10442 size = Math.max(size, m.size);
10443 });
10444 }
10445 if (size > 0) {
10446 if (w.config.markers.hover.size > 0) {
10447 size = w.config.markers.hover.size;
10448 } else {
10449 size += w.config.markers.hover.sizeOffset;
10450 }
10451 }
10452 w.globals.markers.largestSize = size;
10453 return size;
10454 }
10455
10456 /**
10457 * @memberof Core
10458 * returns the sum of all values in a series
10459 * Eg. w.globals.series = [[32,33,43,12], [2,3,5,1]]
10460 * @return [120, 11]
10461 **/
10462 }, {
10463 key: "getSeriesTotals",
10464 value: function getSeriesTotals() {
10465 var w = this.w;
10466 w.globals.seriesTotals = w.globals.series.map(function (ser, index) {
10467 var total = 0;
10468 if (Array.isArray(ser)) {
10469 for (var j = 0; j < ser.length; j++) {
10470 total += ser[j];
10471 }
10472 } else {
10473 // for pie/donuts/gauges
10474 total += ser;
10475 }
10476 return total;
10477 });
10478 }
10479 }, {
10480 key: "getSeriesTotalsXRange",
10481 value: function getSeriesTotalsXRange(minX, maxX) {
10482 var w = this.w;
10483 var seriesTotalsXRange = w.globals.series.map(function (ser, index) {
10484 var total = 0;
10485 for (var j = 0; j < ser.length; j++) {
10486 if (w.globals.seriesX[index][j] > minX && w.globals.seriesX[index][j] < maxX) {
10487 total += ser[j];
10488 }
10489 }
10490 return total;
10491 });
10492 return seriesTotalsXRange;
10493 }
10494
10495 /**
10496 * @memberof CoreUtils
10497 * returns the percentage value of all individual values which can be used in a 100% stacked series
10498 * Eg. w.globals.series = [[32, 33, 43, 12], [2, 3, 5, 1]]
10499 * @return [[94.11, 91.66, 89.58, 92.30], [5.88, 8.33, 10.41, 7.7]]
10500 **/
10501 }, {
10502 key: "getPercentSeries",
10503 value: function getPercentSeries() {
10504 var w = this.w;
10505 w.globals.seriesPercent = w.globals.series.map(function (ser, index) {
10506 var seriesPercent = [];
10507 if (Array.isArray(ser)) {
10508 for (var j = 0; j < ser.length; j++) {
10509 var total = w.globals.stackedSeriesTotals[j];
10510 var percent = 0;
10511 if (total) {
10512 percent = 100 * ser[j] / total;
10513 }
10514 seriesPercent.push(percent);
10515 }
10516 } else {
10517 var _total = w.globals.seriesTotals.reduce(function (acc, val) {
10518 return acc + val;
10519 }, 0);
10520 var _percent = 100 * ser / _total;
10521 seriesPercent.push(_percent);
10522 }
10523 return seriesPercent;
10524 });
10525 }
10526 }, {
10527 key: "getCalculatedRatios",
10528 value: function getCalculatedRatios() {
10529 var _this2 = this;
10530 var w = this.w;
10531 var gl = w.globals;
10532 var yRatio = [];
10533 var invertedYRatio = 0;
10534 var xRatio = 0;
10535 var invertedXRatio = 0;
10536 var zRatio = 0;
10537 var baseLineY = [];
10538 var baseLineInvertedY = 0.1;
10539 var baseLineX = 0;
10540 gl.yRange = [];
10541 if (gl.isMultipleYAxis) {
10542 for (var i = 0; i < gl.minYArr.length; i++) {
10543 gl.yRange.push(Math.abs(gl.minYArr[i] - gl.maxYArr[i]));
10544 baseLineY.push(0);
10545 }
10546 } else {
10547 gl.yRange.push(Math.abs(gl.minY - gl.maxY));
10548 }
10549 gl.xRange = Math.abs(gl.maxX - gl.minX);
10550 gl.zRange = Math.abs(gl.maxZ - gl.minZ);
10551
10552 // multiple y axis
10553 for (var _i = 0; _i < gl.yRange.length; _i++) {
10554 yRatio.push(gl.yRange[_i] / gl.gridHeight);
10555 }
10556 xRatio = gl.xRange / gl.gridWidth;
10557 invertedYRatio = gl.yRange / gl.gridWidth;
10558 invertedXRatio = gl.xRange / gl.gridHeight;
10559 zRatio = gl.zRange / gl.gridHeight * 16;
10560 if (!zRatio) {
10561 zRatio = 1;
10562 }
10563 if (gl.minY !== Number.MIN_VALUE && Math.abs(gl.minY) !== 0) {
10564 // Negative numbers present in series
10565 gl.hasNegs = true;
10566 }
10567
10568 // Check we have a map as series may still to be added/updated.
10569 if (w.globals.seriesYAxisReverseMap.length > 0) {
10570 var scaleBaseLineYScale = function scaleBaseLineYScale(y, i) {
10571 var yAxis = w.config.yaxis[w.globals.seriesYAxisReverseMap[i]];
10572 var sign = y < 0 ? -1 : 1;
10573 y = Math.abs(y);
10574 if (yAxis.logarithmic) {
10575 y = _this2.getBaseLog(yAxis.logBase, y);
10576 }
10577 return -sign * y / yRatio[i];
10578 };
10579 if (gl.isMultipleYAxis) {
10580 baseLineY = [];
10581 // baseline variables is the 0 of the yaxis which will be needed when there are negatives
10582 for (var _i2 = 0; _i2 < yRatio.length; _i2++) {
10583 baseLineY.push(scaleBaseLineYScale(gl.minYArr[_i2], _i2));
10584 }
10585 } else {
10586 baseLineY = [];
10587 baseLineY.push(scaleBaseLineYScale(gl.minY, 0));
10588 if (gl.minY !== Number.MIN_VALUE && Math.abs(gl.minY) !== 0) {
10589 baseLineInvertedY = -gl.minY / invertedYRatio; // this is for bar chart
10590 baseLineX = gl.minX / xRatio;
10591 }
10592 }
10593 } else {
10594 baseLineY = [];
10595 baseLineY.push(0);
10596 baseLineInvertedY = 0;
10597 baseLineX = 0;
10598 }
10599 return {
10600 yRatio: yRatio,
10601 invertedYRatio: invertedYRatio,
10602 zRatio: zRatio,
10603 xRatio: xRatio,
10604 invertedXRatio: invertedXRatio,
10605 baseLineInvertedY: baseLineInvertedY,
10606 baseLineY: baseLineY,
10607 baseLineX: baseLineX
10608 };
10609 }
10610 }, {
10611 key: "getLogSeries",
10612 value: function getLogSeries(series) {
10613 var _this3 = this;
10614 var w = this.w;
10615 w.globals.seriesLog = series.map(function (s, i) {
10616 var yAxisIndex = w.globals.seriesYAxisReverseMap[i];
10617 if (w.config.yaxis[yAxisIndex] && w.config.yaxis[yAxisIndex].logarithmic) {
10618 return s.map(function (d) {
10619 if (d === null) return null;
10620 return _this3.getLogVal(w.config.yaxis[yAxisIndex].logBase, d, i);
10621 });
10622 } else {
10623 return s;
10624 }
10625 });
10626 return w.globals.invalidLogScale ? series : w.globals.seriesLog;
10627 }
10628 }, {
10629 key: "getLogValAtSeriesIndex",
10630 value: function getLogValAtSeriesIndex(val, seriesIndex) {
10631 if (val === null) return null;
10632 var w = this.w;
10633 var yAxisIndex = w.globals.seriesYAxisReverseMap[seriesIndex];
10634 if (w.config.yaxis[yAxisIndex] && w.config.yaxis[yAxisIndex].logarithmic) {
10635 return this.getLogVal(w.config.yaxis[yAxisIndex].logBase, val, seriesIndex);
10636 }
10637 return val;
10638 }
10639 }, {
10640 key: "getBaseLog",
10641 value: function getBaseLog(base, value) {
10642 return Math.log(value) / Math.log(base);
10643 }
10644 }, {
10645 key: "getLogVal",
10646 value: function getLogVal(b, d, seriesIndex) {
10647 if (d <= 0) {
10648 return 0; // Should be Number.NEGATIVE_INFINITY
10649 }
10650 var w = this.w;
10651 var min_log_val = w.globals.minYArr[seriesIndex] === 0 ? -1 // make sure we dont calculate log of 0
10652 : this.getBaseLog(b, w.globals.minYArr[seriesIndex]);
10653 var max_log_val = w.globals.maxYArr[seriesIndex] === 0 ? 0 // make sure we dont calculate log of 0
10654 : this.getBaseLog(b, w.globals.maxYArr[seriesIndex]);
10655 var number_of_height_levels = max_log_val - min_log_val;
10656 if (d < 1) return d / number_of_height_levels;
10657 var log_height_value = this.getBaseLog(b, d) - min_log_val;
10658 return log_height_value / number_of_height_levels;
10659 }
10660 }, {
10661 key: "getLogYRatios",
10662 value: function getLogYRatios(yRatio) {
10663 var _this4 = this;
10664 var w = this.w;
10665 var gl = this.w.globals;
10666 gl.yLogRatio = yRatio.slice();
10667 gl.logYRange = gl.yRange.map(function (_, i) {
10668 var yAxisIndex = w.globals.seriesYAxisReverseMap[i];
10669 if (w.config.yaxis[yAxisIndex] && _this4.w.config.yaxis[yAxisIndex].logarithmic) {
10670 var maxY = -Number.MAX_VALUE;
10671 var minY = Number.MIN_VALUE;
10672 var range = 1;
10673 gl.seriesLog.forEach(function (s, si) {
10674 s.forEach(function (v) {
10675 if (w.config.yaxis[si] && w.config.yaxis[si].logarithmic) {
10676 maxY = Math.max(v, maxY);
10677 minY = Math.min(v, minY);
10678 }
10679 });
10680 });
10681 range = Math.pow(gl.yRange[i], Math.abs(minY - maxY) / gl.yRange[i]);
10682 gl.yLogRatio[i] = range / gl.gridHeight;
10683 return range;
10684 }
10685 });
10686 return gl.invalidLogScale ? yRatio.slice() : gl.yLogRatio;
10687 }
10688
10689 // Some config objects can be array - and we need to extend them correctly
10690 }, {
10691 key: "drawSeriesByGroup",
10692 value:
10693 // Series of the same group and type can be stacked together distinct from
10694 // other series of the same type on the same axis.
10695 function drawSeriesByGroup(typeSeries, typeGroups, type, chartClass) {
10696 var w = this.w;
10697 var graph = [];
10698 if (typeSeries.series.length > 0) {
10699 // draw each group separately
10700 typeGroups.forEach(function (gn) {
10701 var gs = [];
10702 var gi = [];
10703 typeSeries.i.forEach(function (i, ii) {
10704 if (w.config.series[i].group === gn) {
10705 gs.push(typeSeries.series[ii]);
10706 gi.push(i);
10707 }
10708 });
10709 gs.length > 0 && graph.push(chartClass.draw(gs, type, gi));
10710 });
10711 }
10712 return graph;
10713 }
10714 }], [{
10715 key: "checkComboSeries",
10716 value: function checkComboSeries(series, chartType) {
10717 var comboCharts = false;
10718 var comboBarCount = 0;
10719 var comboCount = 0;
10720 if (chartType === undefined) {
10721 chartType = 'line';
10722 }
10723
10724 // Check if user specified a type in series that may make us a combo chart.
10725 // The default type for chart is "line" and the default for series is the
10726 // chart type, therefore, if the types of all series match the chart type,
10727 // this should not be considered a combo chart.
10728 if (series.length && typeof series[0].type !== 'undefined') {
10729 series.forEach(function (s) {
10730 if (s.type === 'bar' || s.type === 'column' || s.type === 'candlestick' || s.type === 'boxPlot') {
10731 comboBarCount++;
10732 }
10733 if (typeof s.type !== 'undefined' && s.type !== chartType) {
10734 comboCount++;
10735 }
10736 });
10737 }
10738 if (comboCount > 0) {
10739 comboCharts = true;
10740 }
10741 return {
10742 comboBarCount: comboBarCount,
10743 comboCharts: comboCharts
10744 };
10745 }
10746 }, {
10747 key: "extendArrayProps",
10748 value: function extendArrayProps(configInstance, options, w) {
10749 var _options, _options2;
10750 if ((_options = options) !== null && _options !== void 0 && _options.yaxis) {
10751 options = configInstance.extendYAxis(options, w);
10752 }
10753 if ((_options2 = options) !== null && _options2 !== void 0 && _options2.annotations) {
10754 var _options3, _options3$annotations, _options4, _options4$annotations;
10755 if (options.annotations.yaxis) {
10756 options = configInstance.extendYAxisAnnotations(options);
10757 }
10758 if ((_options3 = options) !== null && _options3 !== void 0 && (_options3$annotations = _options3.annotations) !== null && _options3$annotations !== void 0 && _options3$annotations.xaxis) {
10759 options = configInstance.extendXAxisAnnotations(options);
10760 }
10761 if ((_options4 = options) !== null && _options4 !== void 0 && (_options4$annotations = _options4.annotations) !== null && _options4$annotations !== void 0 && _options4$annotations.points) {
10762 options = configInstance.extendPointAnnotations(options);
10763 }
10764 }
10765 return options;
10766 }
10767 }]);
10768 return CoreUtils;
10769 }();
10770
10771 var Helpers$4 = /*#__PURE__*/function () {
10772 function Helpers(annoCtx) {
10773 _classCallCheck(this, Helpers);
10774 this.w = annoCtx.w;
10775 this.annoCtx = annoCtx;
10776 }
10777 _createClass(Helpers, [{
10778 key: "setOrientations",
10779 value: function setOrientations(anno) {
10780 var annoIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
10781 var w = this.w;
10782 if (anno.label.orientation === 'vertical') {
10783 var i = annoIndex !== null ? annoIndex : 0;
10784 var xAnno = w.globals.dom.baseEl.querySelector(".apexcharts-xaxis-annotations .apexcharts-xaxis-annotation-label[rel='".concat(i, "']"));
10785 if (xAnno !== null) {
10786 var xAnnoCoord = xAnno.getBoundingClientRect();
10787 xAnno.setAttribute('x', parseFloat(xAnno.getAttribute('x')) - xAnnoCoord.height + 4);
10788 var yOffset = anno.label.position === 'top' ? xAnnoCoord.width : -xAnnoCoord.width;
10789 xAnno.setAttribute('y', parseFloat(xAnno.getAttribute('y')) + yOffset);
10790 var _this$annoCtx$graphic = this.annoCtx.graphics.rotateAroundCenter(xAnno),
10791 x = _this$annoCtx$graphic.x,
10792 y = _this$annoCtx$graphic.y;
10793 xAnno.setAttribute('transform', "rotate(-90 ".concat(x, " ").concat(y, ")"));
10794 }
10795 }
10796 }
10797 }, {
10798 key: "addBackgroundToAnno",
10799 value: function addBackgroundToAnno(annoEl, anno) {
10800 var w = this.w;
10801 if (!annoEl || !anno.label.text || !String(anno.label.text).trim()) {
10802 return null;
10803 }
10804 var elGridRect = w.globals.dom.baseEl.querySelector('.apexcharts-grid').getBoundingClientRect();
10805 var coords = annoEl.getBoundingClientRect();
10806 var _anno$label$style$pad = anno.label.style.padding,
10807 pleft = _anno$label$style$pad.left,
10808 pright = _anno$label$style$pad.right,
10809 ptop = _anno$label$style$pad.top,
10810 pbottom = _anno$label$style$pad.bottom;
10811 if (anno.label.orientation === 'vertical') {
10812 var _ref = [pleft, pright, ptop, pbottom];
10813 ptop = _ref[0];
10814 pbottom = _ref[1];
10815 pleft = _ref[2];
10816 pright = _ref[3];
10817 }
10818 var x1 = coords.left - elGridRect.left - pleft;
10819 var y1 = coords.top - elGridRect.top - ptop;
10820 var elRect = this.annoCtx.graphics.drawRect(x1 - w.globals.barPadForNumericAxis, y1, coords.width + pleft + pright, coords.height + ptop + pbottom, anno.label.borderRadius, anno.label.style.background, 1, anno.label.borderWidth, anno.label.borderColor, 0);
10821 if (anno.id) {
10822 elRect.node.classList.add(anno.id);
10823 }
10824 return elRect;
10825 }
10826 }, {
10827 key: "annotationsBackground",
10828 value: function annotationsBackground() {
10829 var _this = this;
10830 var w = this.w;
10831 var add = function add(anno, i, type) {
10832 var annoLabel = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-annotations .apexcharts-").concat(type, "-annotation-label[rel='").concat(i, "']"));
10833 if (annoLabel) {
10834 var parent = annoLabel.parentNode;
10835 var elRect = _this.addBackgroundToAnno(annoLabel, anno);
10836 if (elRect) {
10837 parent.insertBefore(elRect.node, annoLabel);
10838 if (anno.label.mouseEnter) {
10839 elRect.node.addEventListener('mouseenter', anno.label.mouseEnter.bind(_this, anno));
10840 }
10841 if (anno.label.mouseLeave) {
10842 elRect.node.addEventListener('mouseleave', anno.label.mouseLeave.bind(_this, anno));
10843 }
10844 if (anno.label.click) {
10845 elRect.node.addEventListener('click', anno.label.click.bind(_this, anno));
10846 }
10847 }
10848 }
10849 };
10850 w.config.annotations.xaxis.forEach(function (anno, i) {
10851 return add(anno, i, 'xaxis');
10852 });
10853 w.config.annotations.yaxis.forEach(function (anno, i) {
10854 return add(anno, i, 'yaxis');
10855 });
10856 w.config.annotations.points.forEach(function (anno, i) {
10857 return add(anno, i, 'point');
10858 });
10859 }
10860 }, {
10861 key: "getY1Y2",
10862 value: function getY1Y2(type, anno) {
10863 var w = this.w;
10864 var y = type === 'y1' ? anno.y : anno.y2;
10865 var yP;
10866 var clipped = false;
10867 if (this.annoCtx.invertAxis) {
10868 var labels = w.config.xaxis.convertedCatToNumeric ? w.globals.categoryLabels : w.globals.labels;
10869 var catIndex = labels.indexOf(y);
10870 var xLabel = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis-texts-g text:nth-child(".concat(catIndex + 1, ")"));
10871 yP = xLabel ? parseFloat(xLabel.getAttribute('y')) : (w.globals.gridHeight / labels.length - 1) * (catIndex + 1) - w.globals.barHeight;
10872 if (anno.seriesIndex !== undefined && w.globals.barHeight) {
10873 yP -= w.globals.barHeight / 2 * (w.globals.series.length - 1) - w.globals.barHeight * anno.seriesIndex;
10874 }
10875 } else {
10876 var _w$config$yaxis$anno$;
10877 var seriesIndex = w.globals.seriesYAxisMap[anno.yAxisIndex][0];
10878 var yPos = w.config.yaxis[anno.yAxisIndex].logarithmic ? new CoreUtils(this.annoCtx.ctx).getLogVal(w.config.yaxis[anno.yAxisIndex].logBase, y, seriesIndex) / w.globals.yLogRatio[seriesIndex] : (y - w.globals.minYArr[seriesIndex]) / (w.globals.yRange[seriesIndex] / w.globals.gridHeight);
10879 yP = w.globals.gridHeight - Math.min(Math.max(yPos, 0), w.globals.gridHeight);
10880 clipped = yPos > w.globals.gridHeight || yPos < 0;
10881 if (anno.marker && (anno.y === undefined || anno.y === null)) {
10882 yP = 0;
10883 }
10884 if ((_w$config$yaxis$anno$ = w.config.yaxis[anno.yAxisIndex]) !== null && _w$config$yaxis$anno$ !== void 0 && _w$config$yaxis$anno$.reversed) {
10885 yP = yPos;
10886 }
10887 }
10888 if (typeof y === 'string' && y.includes('px')) {
10889 yP = parseFloat(y);
10890 }
10891 return {
10892 yP: yP,
10893 clipped: clipped
10894 };
10895 }
10896 }, {
10897 key: "getX1X2",
10898 value: function getX1X2(type, anno) {
10899 var w = this.w;
10900 var x = type === 'x1' ? anno.x : anno.x2;
10901 var min = this.annoCtx.invertAxis ? w.globals.minY : w.globals.minX;
10902 var max = this.annoCtx.invertAxis ? w.globals.maxY : w.globals.maxX;
10903 var range = this.annoCtx.invertAxis ? w.globals.yRange[0] : w.globals.xRange;
10904 var clipped = false;
10905 var xP = this.annoCtx.inversedReversedAxis ? (max - x) / (range / w.globals.gridWidth) : (x - min) / (range / w.globals.gridWidth);
10906 if ((w.config.xaxis.type === 'category' || w.config.xaxis.convertedCatToNumeric) && !this.annoCtx.invertAxis && !w.globals.dataFormatXNumeric) {
10907 if (!w.config.chart.sparkline.enabled) {
10908 xP = this.getStringX(x);
10909 }
10910 }
10911 if (typeof x === 'string' && x.includes('px')) {
10912 xP = parseFloat(x);
10913 }
10914 if ((x === undefined || x === null) && anno.marker) {
10915 xP = w.globals.gridWidth;
10916 }
10917 if (anno.seriesIndex !== undefined && w.globals.barWidth && !this.annoCtx.invertAxis) {
10918 xP -= w.globals.barWidth / 2 * (w.globals.series.length - 1) - w.globals.barWidth * anno.seriesIndex;
10919 }
10920 if (typeof xP !== 'number') {
10921 xP = 0;
10922 clipped = true;
10923 }
10924 if (parseFloat(xP.toFixed(10)) > parseFloat(w.globals.gridWidth.toFixed(10))) {
10925 xP = w.globals.gridWidth;
10926 clipped = true;
10927 } else if (xP < 0) {
10928 xP = 0;
10929 clipped = true;
10930 }
10931 return {
10932 x: xP,
10933 clipped: clipped
10934 };
10935 }
10936 }, {
10937 key: "getStringX",
10938 value: function getStringX(x) {
10939 var w = this.w;
10940 var rX = x;
10941 if (w.config.xaxis.convertedCatToNumeric && w.globals.categoryLabels.length) {
10942 x = w.globals.categoryLabels.indexOf(x) + 1;
10943 }
10944 var catIndex = w.globals.labels.map(function (item) {
10945 return Array.isArray(item) ? item.join(' ') : item;
10946 }).indexOf(x);
10947 var xLabel = w.globals.dom.baseEl.querySelector(".apexcharts-xaxis-texts-g text:nth-child(".concat(catIndex + 1, ")"));
10948 if (xLabel) {
10949 rX = parseFloat(xLabel.getAttribute('x'));
10950 }
10951 return rX;
10952 }
10953 }]);
10954 return Helpers;
10955 }();
10956
10957 var XAnnotations = /*#__PURE__*/function () {
10958 function XAnnotations(annoCtx) {
10959 _classCallCheck(this, XAnnotations);
10960 this.w = annoCtx.w;
10961 this.annoCtx = annoCtx;
10962 this.invertAxis = this.annoCtx.invertAxis;
10963 this.helpers = new Helpers$4(this.annoCtx);
10964 }
10965 _createClass(XAnnotations, [{
10966 key: "addXaxisAnnotation",
10967 value: function addXaxisAnnotation(anno, parent, index) {
10968 var w = this.w;
10969 var result = this.helpers.getX1X2('x1', anno);
10970 var x1 = result.x;
10971 var clipX1 = result.clipped;
10972 var clipX2 = true;
10973 var x2;
10974 var text = anno.label.text;
10975 var strokeDashArray = anno.strokeDashArray;
10976 if (!Utils$1.isNumber(x1)) return;
10977 if (anno.x2 === null || typeof anno.x2 === 'undefined') {
10978 if (!clipX1) {
10979 var line = this.annoCtx.graphics.drawLine(x1 + anno.offsetX,
10980 // x1
10981 0 + anno.offsetY,
10982 // y1
10983 x1 + anno.offsetX,
10984 // x2
10985 w.globals.gridHeight + anno.offsetY,
10986 // y2
10987 anno.borderColor,
10988 // lineColor
10989 strokeDashArray,
10990 //dashArray
10991 anno.borderWidth);
10992 parent.appendChild(line.node);
10993 if (anno.id) {
10994 line.node.classList.add(anno.id);
10995 }
10996 }
10997 } else {
10998 var _result = this.helpers.getX1X2('x2', anno);
10999 x2 = _result.x;
11000 clipX2 = _result.clipped;
11001 if (x2 < x1) {
11002 var temp = x1;
11003 x1 = x2;
11004 x2 = temp;
11005 }
11006 var rect = this.annoCtx.graphics.drawRect(x1 + anno.offsetX,
11007 // x1
11008 0 + anno.offsetY,
11009 // y1
11010 x2 - x1,
11011 // x2
11012 w.globals.gridHeight + anno.offsetY,
11013 // y2
11014 0,
11015 // radius
11016 anno.fillColor,
11017 // color
11018 anno.opacity,
11019 // opacity,
11020 1,
11021 // strokeWidth
11022 anno.borderColor,
11023 // strokeColor
11024 strokeDashArray // stokeDashArray
11025 );
11026 rect.node.classList.add('apexcharts-annotation-rect');
11027 rect.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
11028 parent.appendChild(rect.node);
11029 if (anno.id) {
11030 rect.node.classList.add(anno.id);
11031 }
11032 }
11033 if (!(clipX1 && clipX2)) {
11034 var textRects = this.annoCtx.graphics.getTextRects(text, parseFloat(anno.label.style.fontSize));
11035 var textY = anno.label.position === 'top' ? 4 : anno.label.position === 'center' ? w.globals.gridHeight / 2 + (anno.label.orientation === 'vertical' ? textRects.width / 2 : 0) : w.globals.gridHeight;
11036 var elText = this.annoCtx.graphics.drawText({
11037 x: x1 + anno.label.offsetX,
11038 y: textY + anno.label.offsetY - (anno.label.orientation === 'vertical' ? anno.label.position === 'top' ? textRects.width / 2 - 12 : -textRects.width / 2 : 0),
11039 text: text,
11040 textAnchor: anno.label.textAnchor,
11041 fontSize: anno.label.style.fontSize,
11042 fontFamily: anno.label.style.fontFamily,
11043 fontWeight: anno.label.style.fontWeight,
11044 foreColor: anno.label.style.color,
11045 cssClass: "apexcharts-xaxis-annotation-label ".concat(anno.label.style.cssClass, " ").concat(anno.id ? anno.id : '')
11046 });
11047 elText.attr({
11048 rel: index
11049 });
11050 parent.appendChild(elText.node);
11051
11052 // after placing the annotations on svg, set any vertically placed annotations
11053 this.annoCtx.helpers.setOrientations(anno, index);
11054 }
11055 }
11056 }, {
11057 key: "drawXAxisAnnotations",
11058 value: function drawXAxisAnnotations() {
11059 var _this = this;
11060 var w = this.w;
11061 var elg = this.annoCtx.graphics.group({
11062 class: 'apexcharts-xaxis-annotations'
11063 });
11064 w.config.annotations.xaxis.map(function (anno, index) {
11065 _this.addXaxisAnnotation(anno, elg.node, index);
11066 });
11067 return elg;
11068 }
11069 }]);
11070 return XAnnotations;
11071 }();
11072
11073 /**
11074 * DateTime Class to manipulate datetime values.
11075 *
11076 * @module DateTime
11077 **/
11078 var DateTime = /*#__PURE__*/function () {
11079 function DateTime(ctx) {
11080 _classCallCheck(this, DateTime);
11081 this.ctx = ctx;
11082 this.w = ctx.w;
11083 this.months31 = [1, 3, 5, 7, 8, 10, 12];
11084 this.months30 = [2, 4, 6, 9, 11];
11085 this.daysCntOfYear = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
11086 }
11087 _createClass(DateTime, [{
11088 key: "isValidDate",
11089 value: function isValidDate(date) {
11090 if (typeof date === 'number') {
11091 return false; // don't test for timestamps
11092 }
11093 return !isNaN(this.parseDate(date));
11094 }
11095 }, {
11096 key: "getTimeStamp",
11097 value: function getTimeStamp(dateStr) {
11098 if (!Date.parse(dateStr)) {
11099 return dateStr;
11100 }
11101 var utc = this.w.config.xaxis.labels.datetimeUTC;
11102 return !utc ? new Date(dateStr).getTime() : new Date(new Date(dateStr).toISOString().substr(0, 25)).getTime();
11103 }
11104 }, {
11105 key: "getDate",
11106 value: function getDate(timestamp) {
11107 var utc = this.w.config.xaxis.labels.datetimeUTC;
11108 return utc ? new Date(new Date(timestamp).toUTCString()) : new Date(timestamp);
11109 }
11110 }, {
11111 key: "parseDate",
11112 value: function parseDate(dateStr) {
11113 var parsed = Date.parse(dateStr);
11114 if (!isNaN(parsed)) {
11115 return this.getTimeStamp(dateStr);
11116 }
11117 var output = Date.parse(dateStr.replace(/-/g, '/').replace(/[a-z]+/gi, ' '));
11118 output = this.getTimeStamp(output);
11119 return output;
11120 }
11121
11122 // This fixes the difference of x-axis labels between chrome/safari
11123 // Fixes #1726, #1544, #1485, #1255
11124 }, {
11125 key: "parseDateWithTimezone",
11126 value: function parseDateWithTimezone(dateStr) {
11127 return Date.parse(dateStr.replace(/-/g, '/').replace(/[a-z]+/gi, ' '));
11128 }
11129
11130 // http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript#answer-14638191
11131 }, {
11132 key: "formatDate",
11133 value: function formatDate(date, format) {
11134 var locale = this.w.globals.locale;
11135 var utc = this.w.config.xaxis.labels.datetimeUTC;
11136 var MMMM = ['\x00'].concat(_toConsumableArray(locale.months));
11137 var MMM = ['\x01'].concat(_toConsumableArray(locale.shortMonths));
11138 var dddd = ['\x02'].concat(_toConsumableArray(locale.days));
11139 var ddd = ['\x03'].concat(_toConsumableArray(locale.shortDays));
11140 function ii(i, len) {
11141 var s = i + '';
11142 len = len || 2;
11143 while (s.length < len) {
11144 s = '0' + s;
11145 }
11146 return s;
11147 }
11148 var y = utc ? date.getUTCFullYear() : date.getFullYear();
11149 format = format.replace(/(^|[^\\])yyyy+/g, '$1' + y);
11150 format = format.replace(/(^|[^\\])yy/g, '$1' + y.toString().substr(2, 2));
11151 format = format.replace(/(^|[^\\])y/g, '$1' + y);
11152 var M = (utc ? date.getUTCMonth() : date.getMonth()) + 1;
11153 format = format.replace(/(^|[^\\])MMMM+/g, '$1' + MMMM[0]);
11154 format = format.replace(/(^|[^\\])MMM/g, '$1' + MMM[0]);
11155 format = format.replace(/(^|[^\\])MM/g, '$1' + ii(M));
11156 format = format.replace(/(^|[^\\])M/g, '$1' + M);
11157 var d = utc ? date.getUTCDate() : date.getDate();
11158 format = format.replace(/(^|[^\\])dddd+/g, '$1' + dddd[0]);
11159 format = format.replace(/(^|[^\\])ddd/g, '$1' + ddd[0]);
11160 format = format.replace(/(^|[^\\])dd/g, '$1' + ii(d));
11161 format = format.replace(/(^|[^\\])d/g, '$1' + d);
11162 var H = utc ? date.getUTCHours() : date.getHours();
11163 format = format.replace(/(^|[^\\])HH+/g, '$1' + ii(H));
11164 format = format.replace(/(^|[^\\])H/g, '$1' + H);
11165 var h = H > 12 ? H - 12 : H === 0 ? 12 : H;
11166 format = format.replace(/(^|[^\\])hh+/g, '$1' + ii(h));
11167 format = format.replace(/(^|[^\\])h/g, '$1' + h);
11168 var m = utc ? date.getUTCMinutes() : date.getMinutes();
11169 format = format.replace(/(^|[^\\])mm+/g, '$1' + ii(m));
11170 format = format.replace(/(^|[^\\])m/g, '$1' + m);
11171 var s = utc ? date.getUTCSeconds() : date.getSeconds();
11172 format = format.replace(/(^|[^\\])ss+/g, '$1' + ii(s));
11173 format = format.replace(/(^|[^\\])s/g, '$1' + s);
11174 var f = utc ? date.getUTCMilliseconds() : date.getMilliseconds();
11175 format = format.replace(/(^|[^\\])fff+/g, '$1' + ii(f, 3));
11176 f = Math.round(f / 10);
11177 format = format.replace(/(^|[^\\])ff/g, '$1' + ii(f));
11178 f = Math.round(f / 10);
11179 format = format.replace(/(^|[^\\])f/g, '$1' + f);
11180 var T = H < 12 ? 'AM' : 'PM';
11181 format = format.replace(/(^|[^\\])TT+/g, '$1' + T);
11182 format = format.replace(/(^|[^\\])T/g, '$1' + T.charAt(0));
11183 var t = T.toLowerCase();
11184 format = format.replace(/(^|[^\\])tt+/g, '$1' + t);
11185 format = format.replace(/(^|[^\\])t/g, '$1' + t.charAt(0));
11186 var tz = -date.getTimezoneOffset();
11187 var K = utc || !tz ? 'Z' : tz > 0 ? '+' : '-';
11188 if (!utc) {
11189 tz = Math.abs(tz);
11190 var tzHrs = Math.floor(tz / 60);
11191 var tzMin = tz % 60;
11192 K += ii(tzHrs) + ':' + ii(tzMin);
11193 }
11194 format = format.replace(/(^|[^\\])K/g, '$1' + K);
11195 var day = (utc ? date.getUTCDay() : date.getDay()) + 1;
11196 format = format.replace(new RegExp(dddd[0], 'g'), dddd[day]);
11197 format = format.replace(new RegExp(ddd[0], 'g'), ddd[day]);
11198 format = format.replace(new RegExp(MMMM[0], 'g'), MMMM[M]);
11199 format = format.replace(new RegExp(MMM[0], 'g'), MMM[M]);
11200 format = format.replace(/\\(.)/g, '$1');
11201 return format;
11202 }
11203 }, {
11204 key: "getTimeUnitsfromTimestamp",
11205 value: function getTimeUnitsfromTimestamp(minX, maxX, utc) {
11206 var w = this.w;
11207 if (w.config.xaxis.min !== undefined) {
11208 minX = w.config.xaxis.min;
11209 }
11210 if (w.config.xaxis.max !== undefined) {
11211 maxX = w.config.xaxis.max;
11212 }
11213 var tsMin = this.getDate(minX);
11214 var tsMax = this.getDate(maxX);
11215 var minD = this.formatDate(tsMin, 'yyyy MM dd HH mm ss fff').split(' ');
11216 var maxD = this.formatDate(tsMax, 'yyyy MM dd HH mm ss fff').split(' ');
11217 return {
11218 minMillisecond: parseInt(minD[6], 10),
11219 maxMillisecond: parseInt(maxD[6], 10),
11220 minSecond: parseInt(minD[5], 10),
11221 maxSecond: parseInt(maxD[5], 10),
11222 minMinute: parseInt(minD[4], 10),
11223 maxMinute: parseInt(maxD[4], 10),
11224 minHour: parseInt(minD[3], 10),
11225 maxHour: parseInt(maxD[3], 10),
11226 minDate: parseInt(minD[2], 10),
11227 maxDate: parseInt(maxD[2], 10),
11228 minMonth: parseInt(minD[1], 10) - 1,
11229 maxMonth: parseInt(maxD[1], 10) - 1,
11230 minYear: parseInt(minD[0], 10),
11231 maxYear: parseInt(maxD[0], 10)
11232 };
11233 }
11234 }, {
11235 key: "isLeapYear",
11236 value: function isLeapYear(year) {
11237 return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
11238 }
11239 }, {
11240 key: "calculcateLastDaysOfMonth",
11241 value: function calculcateLastDaysOfMonth(month, year, subtract) {
11242 var days = this.determineDaysOfMonths(month, year);
11243
11244 // whatever days we get, subtract the number of days asked
11245 return days - subtract;
11246 }
11247 }, {
11248 key: "determineDaysOfYear",
11249 value: function determineDaysOfYear(year) {
11250 var days = 365;
11251 if (this.isLeapYear(year)) {
11252 days = 366;
11253 }
11254 return days;
11255 }
11256 }, {
11257 key: "determineRemainingDaysOfYear",
11258 value: function determineRemainingDaysOfYear(year, month, date) {
11259 var dayOfYear = this.daysCntOfYear[month] + date;
11260 if (month > 1 && this.isLeapYear()) dayOfYear++;
11261 return dayOfYear;
11262 }
11263 }, {
11264 key: "determineDaysOfMonths",
11265 value: function determineDaysOfMonths(month, year) {
11266 var days = 30;
11267 month = Utils$1.monthMod(month);
11268 switch (true) {
11269 case this.months30.indexOf(month) > -1:
11270 if (month === 2) {
11271 if (this.isLeapYear(year)) {
11272 days = 29;
11273 } else {
11274 days = 28;
11275 }
11276 }
11277 break;
11278 case this.months31.indexOf(month) > -1:
11279 days = 31;
11280 break;
11281 default:
11282 days = 31;
11283 break;
11284 }
11285 return days;
11286 }
11287 }]);
11288 return DateTime;
11289 }();
11290
11291 /**
11292 * ApexCharts Formatter Class for setting value formatters for axes as well as tooltips.
11293 *
11294 * @module Formatters
11295 **/
11296 var Formatters = /*#__PURE__*/function () {
11297 function Formatters(ctx) {
11298 _classCallCheck(this, Formatters);
11299 this.ctx = ctx;
11300 this.w = ctx.w;
11301 this.tooltipKeyFormat = 'dd MMM';
11302 }
11303 _createClass(Formatters, [{
11304 key: "xLabelFormat",
11305 value: function xLabelFormat(fn, val, timestamp, opts) {
11306 var w = this.w;
11307 if (w.config.xaxis.type === 'datetime') {
11308 if (w.config.xaxis.labels.formatter === undefined) {
11309 // if user has not specified a custom formatter, use the default tooltip.x.format
11310 if (w.config.tooltip.x.formatter === undefined) {
11311 var datetimeObj = new DateTime(this.ctx);
11312 return datetimeObj.formatDate(datetimeObj.getDate(val), w.config.tooltip.x.format);
11313 }
11314 }
11315 }
11316 return fn(val, timestamp, opts);
11317 }
11318 }, {
11319 key: "defaultGeneralFormatter",
11320 value: function defaultGeneralFormatter(val) {
11321 if (Array.isArray(val)) {
11322 return val.map(function (v) {
11323 return v;
11324 });
11325 } else {
11326 return val;
11327 }
11328 }
11329 }, {
11330 key: "defaultYFormatter",
11331 value: function defaultYFormatter(v, yaxe, i) {
11332 var w = this.w;
11333 if (Utils$1.isNumber(v)) {
11334 if (w.globals.yValueDecimal !== 0) {
11335 v = v.toFixed(yaxe.decimalsInFloat !== undefined ? yaxe.decimalsInFloat : w.globals.yValueDecimal);
11336 } else {
11337 // We have an integer value but the label is not an integer. We can
11338 // deduce this is due to the number of ticks exceeding the even lower
11339 // integer range. Add an additional decimal place only in this case.
11340 var f = v.toFixed(0);
11341 // Do not change the == to ===
11342 v = v == f ? f : v.toFixed(1);
11343 }
11344 }
11345 return v;
11346 }
11347 }, {
11348 key: "setLabelFormatters",
11349 value: function setLabelFormatters() {
11350 var _this = this;
11351 var w = this.w;
11352 w.globals.xaxisTooltipFormatter = function (val) {
11353 return _this.defaultGeneralFormatter(val);
11354 };
11355 w.globals.ttKeyFormatter = function (val) {
11356 return _this.defaultGeneralFormatter(val);
11357 };
11358 w.globals.ttZFormatter = function (val) {
11359 return val;
11360 };
11361 w.globals.legendFormatter = function (val) {
11362 return _this.defaultGeneralFormatter(val);
11363 };
11364
11365 // formatter function will always overwrite format property
11366 if (w.config.xaxis.labels.formatter !== undefined) {
11367 w.globals.xLabelFormatter = w.config.xaxis.labels.formatter;
11368 } else {
11369 w.globals.xLabelFormatter = function (val) {
11370 if (Utils$1.isNumber(val)) {
11371 if (!w.config.xaxis.convertedCatToNumeric && w.config.xaxis.type === 'numeric') {
11372 if (Utils$1.isNumber(w.config.xaxis.decimalsInFloat)) {
11373 return val.toFixed(w.config.xaxis.decimalsInFloat);
11374 } else {
11375 var diff = w.globals.maxX - w.globals.minX;
11376 if (diff > 0 && diff < 100) {
11377 return val.toFixed(1);
11378 }
11379 return val.toFixed(0);
11380 }
11381 }
11382 if (w.globals.isBarHorizontal) {
11383 var range = w.globals.maxY - w.globals.minYArr;
11384 if (range < 4) {
11385 return val.toFixed(1);
11386 }
11387 }
11388 return val.toFixed(0);
11389 }
11390 return val;
11391 };
11392 }
11393 if (typeof w.config.tooltip.x.formatter === 'function') {
11394 w.globals.ttKeyFormatter = w.config.tooltip.x.formatter;
11395 } else {
11396 w.globals.ttKeyFormatter = w.globals.xLabelFormatter;
11397 }
11398 if (typeof w.config.xaxis.tooltip.formatter === 'function') {
11399 w.globals.xaxisTooltipFormatter = w.config.xaxis.tooltip.formatter;
11400 }
11401 if (Array.isArray(w.config.tooltip.y)) {
11402 w.globals.ttVal = w.config.tooltip.y;
11403 } else {
11404 if (w.config.tooltip.y.formatter !== undefined) {
11405 w.globals.ttVal = w.config.tooltip.y;
11406 }
11407 }
11408 if (w.config.tooltip.z.formatter !== undefined) {
11409 w.globals.ttZFormatter = w.config.tooltip.z.formatter;
11410 }
11411
11412 // legend formatter - if user wants to append any global values of series to legend text
11413 if (w.config.legend.formatter !== undefined) {
11414 w.globals.legendFormatter = w.config.legend.formatter;
11415 }
11416
11417 // formatter function will always overwrite format property
11418 w.config.yaxis.forEach(function (yaxe, i) {
11419 if (yaxe.labels.formatter !== undefined) {
11420 w.globals.yLabelFormatters[i] = yaxe.labels.formatter;
11421 } else {
11422 w.globals.yLabelFormatters[i] = function (val) {
11423 if (!w.globals.xyCharts) return val;
11424 if (Array.isArray(val)) {
11425 return val.map(function (v) {
11426 return _this.defaultYFormatter(v, yaxe, i);
11427 });
11428 } else {
11429 return _this.defaultYFormatter(val, yaxe, i);
11430 }
11431 };
11432 }
11433 });
11434 return w.globals;
11435 }
11436 }, {
11437 key: "heatmapLabelFormatters",
11438 value: function heatmapLabelFormatters() {
11439 var w = this.w;
11440 if (w.config.chart.type === 'heatmap') {
11441 w.globals.yAxisScale[0].result = w.globals.seriesNames.slice();
11442
11443 // get the longest string from the labels array and also apply label formatter to it
11444 var longest = w.globals.seriesNames.reduce(function (a, b) {
11445 return a.length > b.length ? a : b;
11446 }, 0);
11447 w.globals.yAxisScale[0].niceMax = longest;
11448 w.globals.yAxisScale[0].niceMin = longest;
11449 }
11450 }
11451 }]);
11452 return Formatters;
11453 }();
11454
11455 var AxesUtils = /*#__PURE__*/function () {
11456 function AxesUtils(ctx) {
11457 _classCallCheck(this, AxesUtils);
11458 this.ctx = ctx;
11459 this.w = ctx.w;
11460 }
11461
11462 // Based on the formatter function, get the label text and position
11463 _createClass(AxesUtils, [{
11464 key: "getLabel",
11465 value: function getLabel(labels, timescaleLabels, x, i) {
11466 var drawnLabels = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
11467 var fontSize = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '12px';
11468 var isLeafGroup = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
11469 var w = this.w;
11470 var rawLabel = typeof labels[i] === 'undefined' ? '' : labels[i];
11471 var label = rawLabel;
11472 var xlbFormatter = w.globals.xLabelFormatter;
11473 var customFormatter = w.config.xaxis.labels.formatter;
11474 var isBold = false;
11475 var xFormat = new Formatters(this.ctx);
11476 var timestamp = rawLabel;
11477 if (isLeafGroup) {
11478 label = xFormat.xLabelFormat(xlbFormatter, rawLabel, timestamp, {
11479 i: i,
11480 dateFormatter: new DateTime(this.ctx).formatDate,
11481 w: w
11482 });
11483 if (customFormatter !== undefined) {
11484 label = customFormatter(rawLabel, labels[i], {
11485 i: i,
11486 dateFormatter: new DateTime(this.ctx).formatDate,
11487 w: w
11488 });
11489 }
11490 }
11491 var determineHighestUnit = function determineHighestUnit(unit) {
11492 var highestUnit = null;
11493 timescaleLabels.forEach(function (t) {
11494 if (t.unit === 'month') {
11495 highestUnit = 'year';
11496 } else if (t.unit === 'day') {
11497 highestUnit = 'month';
11498 } else if (t.unit === 'hour') {
11499 highestUnit = 'day';
11500 } else if (t.unit === 'minute') {
11501 highestUnit = 'hour';
11502 }
11503 });
11504 return highestUnit === unit;
11505 };
11506 if (timescaleLabels.length > 0) {
11507 isBold = determineHighestUnit(timescaleLabels[i].unit);
11508 x = timescaleLabels[i].position;
11509 label = timescaleLabels[i].value;
11510 } else {
11511 if (w.config.xaxis.type === 'datetime' && customFormatter === undefined) {
11512 label = '';
11513 }
11514 }
11515 if (typeof label === 'undefined') label = '';
11516 label = Array.isArray(label) ? label : label.toString();
11517 var graphics = new Graphics(this.ctx);
11518 var textRect = {};
11519 if (w.globals.rotateXLabels && isLeafGroup) {
11520 textRect = graphics.getTextRects(label, parseInt(fontSize, 10), null, "rotate(".concat(w.config.xaxis.labels.rotate, " 0 0)"), false);
11521 } else {
11522 textRect = graphics.getTextRects(label, parseInt(fontSize, 10));
11523 }
11524 var allowDuplicatesInTimeScale = !w.config.xaxis.labels.showDuplicates && this.ctx.timeScale;
11525 if (!Array.isArray(label) && (String(label) === 'NaN' || drawnLabels.indexOf(label) >= 0 && allowDuplicatesInTimeScale)) {
11526 label = '';
11527 }
11528 return {
11529 x: x,
11530 text: label,
11531 textRect: textRect,
11532 isBold: isBold
11533 };
11534 }
11535 }, {
11536 key: "checkLabelBasedOnTickamount",
11537 value: function checkLabelBasedOnTickamount(i, label, labelsLen) {
11538 var w = this.w;
11539 var ticks = w.config.xaxis.tickAmount;
11540 if (ticks === 'dataPoints') ticks = Math.round(w.globals.gridWidth / 120);
11541 if (ticks > labelsLen) return label;
11542 var tickMultiple = Math.round(labelsLen / (ticks + 1));
11543 if (i % tickMultiple === 0) {
11544 return label;
11545 } else {
11546 label.text = '';
11547 }
11548 return label;
11549 }
11550 }, {
11551 key: "checkForOverflowingLabels",
11552 value: function checkForOverflowingLabels(i, label, labelsLen, drawnLabels, drawnLabelsRects) {
11553 var w = this.w;
11554 if (i === 0) {
11555 // check if first label is being truncated
11556 if (w.globals.skipFirstTimelinelabel) {
11557 label.text = '';
11558 }
11559 }
11560 if (i === labelsLen - 1) {
11561 // check if last label is being truncated
11562 if (w.globals.skipLastTimelinelabel) {
11563 label.text = '';
11564 }
11565 }
11566 if (w.config.xaxis.labels.hideOverlappingLabels && drawnLabels.length > 0) {
11567 var prev = drawnLabelsRects[drawnLabelsRects.length - 1];
11568 if (label.x < prev.textRect.width / (w.globals.rotateXLabels ? Math.abs(w.config.xaxis.labels.rotate) / 12 : 1.01) + prev.x) {
11569 label.text = '';
11570 }
11571 }
11572 return label;
11573 }
11574 }, {
11575 key: "checkForReversedLabels",
11576 value: function checkForReversedLabels(i, labels) {
11577 var w = this.w;
11578 if (w.config.yaxis[i] && w.config.yaxis[i].reversed) {
11579 labels.reverse();
11580 }
11581 return labels;
11582 }
11583 }, {
11584 key: "yAxisAllSeriesCollapsed",
11585 value: function yAxisAllSeriesCollapsed(index) {
11586 var gl = this.w.globals;
11587 return !gl.seriesYAxisMap[index].some(function (si) {
11588 return gl.collapsedSeriesIndices.indexOf(si) === -1;
11589 });
11590 }
11591
11592 // Method to translate annotation.yAxisIndex values from
11593 // seriesName-as-a-string values to seriesName-as-an-array values (old style
11594 // series mapping to new style).
11595 }, {
11596 key: "translateYAxisIndex",
11597 value: function translateYAxisIndex(index) {
11598 var w = this.w;
11599 var gl = w.globals;
11600 var yaxis = w.config.yaxis;
11601 var newStyle = gl.series.length > yaxis.length || yaxis.some(function (a) {
11602 return Array.isArray(a.seriesName);
11603 });
11604 if (newStyle) {
11605 return index;
11606 } else {
11607 return gl.seriesYAxisReverseMap[index];
11608 }
11609 }
11610 }, {
11611 key: "isYAxisHidden",
11612 value: function isYAxisHidden(index) {
11613 var w = this.w;
11614 var yaxis = w.config.yaxis[index];
11615 if (!yaxis.show || this.yAxisAllSeriesCollapsed(index)) {
11616 return true;
11617 }
11618 if (!yaxis.showForNullSeries) {
11619 var seriesIndices = w.globals.seriesYAxisMap[index];
11620 var coreUtils = new CoreUtils(this.ctx);
11621 return seriesIndices.every(function (si) {
11622 return coreUtils.isSeriesNull(si);
11623 });
11624 }
11625 return false;
11626 }
11627
11628 // get the label color for y-axis
11629 // realIndex is the actual series index, while i is the tick Index
11630 }, {
11631 key: "getYAxisForeColor",
11632 value: function getYAxisForeColor(yColors, realIndex) {
11633 var w = this.w;
11634 if (Array.isArray(yColors) && w.globals.yAxisScale[realIndex]) {
11635 this.ctx.theme.pushExtraColors(yColors, w.globals.yAxisScale[realIndex].result.length, false);
11636 }
11637 return yColors;
11638 }
11639 }, {
11640 key: "drawYAxisTicks",
11641 value: function drawYAxisTicks(x, tickAmount, axisBorder, axisTicks, realIndex, labelsDivider, elYaxis) {
11642 var w = this.w;
11643 var graphics = new Graphics(this.ctx);
11644
11645 // initial label position = 0;
11646 var tY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY;
11647 if (w.globals.isBarHorizontal) {
11648 tY = 0;
11649 } else if (w.config.chart.type === 'heatmap') {
11650 tY += labelsDivider / 2;
11651 }
11652 if (axisTicks.show && tickAmount > 0) {
11653 if (w.config.yaxis[realIndex].opposite === true) x = x + axisTicks.width;
11654 for (var i = tickAmount; i >= 0; i--) {
11655 var elTick = graphics.drawLine(x + axisBorder.offsetX - axisTicks.width + axisTicks.offsetX, tY + axisTicks.offsetY, x + axisBorder.offsetX + axisTicks.offsetX, tY + axisTicks.offsetY, axisTicks.color);
11656 elYaxis.add(elTick);
11657 tY += labelsDivider;
11658 }
11659 }
11660 }
11661 }]);
11662 return AxesUtils;
11663 }();
11664
11665 var YAnnotations = /*#__PURE__*/function () {
11666 function YAnnotations(annoCtx) {
11667 _classCallCheck(this, YAnnotations);
11668 this.w = annoCtx.w;
11669 this.annoCtx = annoCtx;
11670 this.helpers = new Helpers$4(this.annoCtx);
11671 this.axesUtils = new AxesUtils(this.annoCtx);
11672 }
11673 _createClass(YAnnotations, [{
11674 key: "addYaxisAnnotation",
11675 value: function addYaxisAnnotation(anno, parent, index) {
11676 var w = this.w;
11677 var strokeDashArray = anno.strokeDashArray;
11678 var result = this.helpers.getY1Y2('y1', anno);
11679 var y1 = result.yP;
11680 var clipY1 = result.clipped;
11681 var y2;
11682 var clipY2 = true;
11683 var drawn = false;
11684 var text = anno.label.text;
11685 if (anno.y2 === null || typeof anno.y2 === 'undefined') {
11686 if (!clipY1) {
11687 drawn = true;
11688 var line = this.annoCtx.graphics.drawLine(0 + anno.offsetX,
11689 // x1
11690 y1 + anno.offsetY,
11691 // y1
11692 this._getYAxisAnnotationWidth(anno),
11693 // x2
11694 y1 + anno.offsetY,
11695 // y2
11696 anno.borderColor,
11697 // lineColor
11698 strokeDashArray,
11699 // dashArray
11700 anno.borderWidth);
11701 parent.appendChild(line.node);
11702 if (anno.id) {
11703 line.node.classList.add(anno.id);
11704 }
11705 }
11706 } else {
11707 result = this.helpers.getY1Y2('y2', anno);
11708 y2 = result.yP;
11709 clipY2 = result.clipped;
11710 if (y2 > y1) {
11711 var temp = y1;
11712 y1 = y2;
11713 y2 = temp;
11714 }
11715 if (!(clipY1 && clipY2)) {
11716 drawn = true;
11717 var rect = this.annoCtx.graphics.drawRect(0 + anno.offsetX,
11718 // x1
11719 y2 + anno.offsetY,
11720 // y1
11721 this._getYAxisAnnotationWidth(anno),
11722 // x2
11723 y1 - y2,
11724 // y2
11725 0,
11726 // radius
11727 anno.fillColor,
11728 // color
11729 anno.opacity,
11730 // opacity,
11731 1,
11732 // strokeWidth
11733 anno.borderColor,
11734 // strokeColor
11735 strokeDashArray // stokeDashArray
11736 );
11737 rect.node.classList.add('apexcharts-annotation-rect');
11738 rect.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
11739 parent.appendChild(rect.node);
11740 if (anno.id) {
11741 rect.node.classList.add(anno.id);
11742 }
11743 }
11744 }
11745 if (drawn) {
11746 var textX = anno.label.position === 'right' ? w.globals.gridWidth : anno.label.position === 'center' ? w.globals.gridWidth / 2 : 0;
11747 var elText = this.annoCtx.graphics.drawText({
11748 x: textX + anno.label.offsetX,
11749 y: (y2 != null ? y2 : y1) + anno.label.offsetY - 3,
11750 text: text,
11751 textAnchor: anno.label.textAnchor,
11752 fontSize: anno.label.style.fontSize,
11753 fontFamily: anno.label.style.fontFamily,
11754 fontWeight: anno.label.style.fontWeight,
11755 foreColor: anno.label.style.color,
11756 cssClass: "apexcharts-yaxis-annotation-label ".concat(anno.label.style.cssClass, " ").concat(anno.id ? anno.id : '')
11757 });
11758 elText.attr({
11759 rel: index
11760 });
11761 parent.appendChild(elText.node);
11762 }
11763 }
11764 }, {
11765 key: "_getYAxisAnnotationWidth",
11766 value: function _getYAxisAnnotationWidth(anno) {
11767 // issue apexcharts.js#2009
11768 var w = this.w;
11769 var width = w.globals.gridWidth;
11770 if (anno.width.indexOf('%') > -1) {
11771 width = w.globals.gridWidth * parseInt(anno.width, 10) / 100;
11772 } else {
11773 width = parseInt(anno.width, 10);
11774 }
11775 return width + anno.offsetX;
11776 }
11777 }, {
11778 key: "drawYAxisAnnotations",
11779 value: function drawYAxisAnnotations() {
11780 var _this = this;
11781 var w = this.w;
11782 var elg = this.annoCtx.graphics.group({
11783 class: 'apexcharts-yaxis-annotations'
11784 });
11785 w.config.annotations.yaxis.forEach(function (anno, index) {
11786 anno.yAxisIndex = _this.axesUtils.translateYAxisIndex(anno.yAxisIndex);
11787 if (!(_this.axesUtils.isYAxisHidden(anno.yAxisIndex) && _this.axesUtils.yAxisAllSeriesCollapsed(anno.yAxisIndex))) {
11788 _this.addYaxisAnnotation(anno, elg.node, index);
11789 }
11790 });
11791 return elg;
11792 }
11793 }]);
11794 return YAnnotations;
11795 }();
11796
11797 var PointAnnotations = /*#__PURE__*/function () {
11798 function PointAnnotations(annoCtx) {
11799 _classCallCheck(this, PointAnnotations);
11800 this.w = annoCtx.w;
11801 this.annoCtx = annoCtx;
11802 this.helpers = new Helpers$4(this.annoCtx);
11803 }
11804 _createClass(PointAnnotations, [{
11805 key: "addPointAnnotation",
11806 value: function addPointAnnotation(anno, parent, index) {
11807 var w = this.w;
11808 if (w.globals.collapsedSeriesIndices.indexOf(anno.seriesIndex) > -1) {
11809 return;
11810 }
11811 var result = this.helpers.getX1X2('x1', anno);
11812 var x = result.x;
11813 var clipX = result.clipped;
11814 result = this.helpers.getY1Y2('y1', anno);
11815 var y = result.yP;
11816 var clipY = result.clipped;
11817 if (!Utils$1.isNumber(x)) return;
11818 if (!(clipY || clipX)) {
11819 var optsPoints = {
11820 pSize: anno.marker.size,
11821 pointStrokeWidth: anno.marker.strokeWidth,
11822 pointFillColor: anno.marker.fillColor,
11823 pointStrokeColor: anno.marker.strokeColor,
11824 shape: anno.marker.shape,
11825 pRadius: anno.marker.radius,
11826 class: "apexcharts-point-annotation-marker ".concat(anno.marker.cssClass, " ").concat(anno.id ? anno.id : '')
11827 };
11828 var point = this.annoCtx.graphics.drawMarker(x + anno.marker.offsetX, y + anno.marker.offsetY, optsPoints);
11829 parent.appendChild(point.node);
11830 var text = anno.label.text ? anno.label.text : '';
11831 var elText = this.annoCtx.graphics.drawText({
11832 x: x + anno.label.offsetX,
11833 y: y + anno.label.offsetY - anno.marker.size - parseFloat(anno.label.style.fontSize) / 1.6,
11834 text: text,
11835 textAnchor: anno.label.textAnchor,
11836 fontSize: anno.label.style.fontSize,
11837 fontFamily: anno.label.style.fontFamily,
11838 fontWeight: anno.label.style.fontWeight,
11839 foreColor: anno.label.style.color,
11840 cssClass: "apexcharts-point-annotation-label ".concat(anno.label.style.cssClass, " ").concat(anno.id ? anno.id : '')
11841 });
11842 elText.attr({
11843 rel: index
11844 });
11845 parent.appendChild(elText.node);
11846
11847 // TODO: deprecate this as we will use custom
11848 if (anno.customSVG.SVG) {
11849 var g = this.annoCtx.graphics.group({
11850 class: 'apexcharts-point-annotations-custom-svg ' + anno.customSVG.cssClass
11851 });
11852 g.attr({
11853 transform: "translate(".concat(x + anno.customSVG.offsetX, ", ").concat(y + anno.customSVG.offsetY, ")")
11854 });
11855 g.node.innerHTML = anno.customSVG.SVG;
11856 parent.appendChild(g.node);
11857 }
11858 if (anno.image.path) {
11859 var imgWidth = anno.image.width ? anno.image.width : 20;
11860 var imgHeight = anno.image.height ? anno.image.height : 20;
11861 point = this.annoCtx.addImage({
11862 x: x + anno.image.offsetX - imgWidth / 2,
11863 y: y + anno.image.offsetY - imgHeight / 2,
11864 width: imgWidth,
11865 height: imgHeight,
11866 path: anno.image.path,
11867 appendTo: '.apexcharts-point-annotations'
11868 });
11869 }
11870 if (anno.mouseEnter) {
11871 point.node.addEventListener('mouseenter', anno.mouseEnter.bind(this, anno));
11872 }
11873 if (anno.mouseLeave) {
11874 point.node.addEventListener('mouseleave', anno.mouseLeave.bind(this, anno));
11875 }
11876 if (anno.click) {
11877 point.node.addEventListener('click', anno.click.bind(this, anno));
11878 }
11879 }
11880 }
11881 }, {
11882 key: "drawPointAnnotations",
11883 value: function drawPointAnnotations() {
11884 var _this = this;
11885 var w = this.w;
11886 var elg = this.annoCtx.graphics.group({
11887 class: 'apexcharts-point-annotations'
11888 });
11889 w.config.annotations.points.map(function (anno, index) {
11890 _this.addPointAnnotation(anno, elg.node, index);
11891 });
11892 return elg;
11893 }
11894 }]);
11895 return PointAnnotations;
11896 }();
11897
11898 const name = "en";
11899 const options = {
11900 months: [
11901 "January",
11902 "February",
11903 "March",
11904 "April",
11905 "May",
11906 "June",
11907 "July",
11908 "August",
11909 "September",
11910 "October",
11911 "November",
11912 "December"
11913 ],
11914 shortMonths: [
11915 "Jan",
11916 "Feb",
11917 "Mar",
11918 "Apr",
11919 "May",
11920 "Jun",
11921 "Jul",
11922 "Aug",
11923 "Sep",
11924 "Oct",
11925 "Nov",
11926 "Dec"
11927 ],
11928 days: [
11929 "Sunday",
11930 "Monday",
11931 "Tuesday",
11932 "Wednesday",
11933 "Thursday",
11934 "Friday",
11935 "Saturday"
11936 ],
11937 shortDays: [
11938 "Sun",
11939 "Mon",
11940 "Tue",
11941 "Wed",
11942 "Thu",
11943 "Fri",
11944 "Sat"
11945 ],
11946 toolbar: {
11947 exportToSVG: "Download SVG",
11948 exportToPNG: "Download PNG",
11949 exportToCSV: "Download CSV",
11950 menu: "Menu",
11951 selection: "Selection",
11952 selectionZoom: "Selection Zoom",
11953 zoomIn: "Zoom In",
11954 zoomOut: "Zoom Out",
11955 pan: "Panning",
11956 reset: "Reset Zoom"
11957 }
11958 };
11959 var en = {
11960 name: name,
11961 options: options
11962 };
11963
11964 var Options = /*#__PURE__*/function () {
11965 function Options() {
11966 _classCallCheck(this, Options);
11967 this.yAxis = {
11968 show: true,
11969 showAlways: false,
11970 showForNullSeries: true,
11971 seriesName: undefined,
11972 opposite: false,
11973 reversed: false,
11974 logarithmic: false,
11975 logBase: 10,
11976 tickAmount: undefined,
11977 stepSize: undefined,
11978 forceNiceScale: false,
11979 max: undefined,
11980 min: undefined,
11981 floating: false,
11982 decimalsInFloat: undefined,
11983 labels: {
11984 show: true,
11985 showDuplicates: false,
11986 minWidth: 0,
11987 maxWidth: 160,
11988 offsetX: 0,
11989 offsetY: 0,
11990 align: undefined,
11991 rotate: 0,
11992 padding: 20,
11993 style: {
11994 colors: [],
11995 fontSize: '11px',
11996 fontWeight: 400,
11997 fontFamily: undefined,
11998 cssClass: ''
11999 },
12000 formatter: undefined
12001 },
12002 axisBorder: {
12003 show: false,
12004 color: '#e0e0e0',
12005 width: 1,
12006 offsetX: 0,
12007 offsetY: 0
12008 },
12009 axisTicks: {
12010 show: false,
12011 color: '#e0e0e0',
12012 width: 6,
12013 offsetX: 0,
12014 offsetY: 0
12015 },
12016 title: {
12017 text: undefined,
12018 rotate: -90,
12019 offsetY: 0,
12020 offsetX: 0,
12021 style: {
12022 color: undefined,
12023 fontSize: '11px',
12024 fontWeight: 900,
12025 fontFamily: undefined,
12026 cssClass: ''
12027 }
12028 },
12029 tooltip: {
12030 enabled: false,
12031 offsetX: 0
12032 },
12033 crosshairs: {
12034 show: true,
12035 position: 'front',
12036 stroke: {
12037 color: '#b6b6b6',
12038 width: 1,
12039 dashArray: 0
12040 }
12041 }
12042 };
12043 this.pointAnnotation = {
12044 id: undefined,
12045 x: 0,
12046 y: null,
12047 yAxisIndex: 0,
12048 seriesIndex: undefined,
12049 mouseEnter: undefined,
12050 mouseLeave: undefined,
12051 click: undefined,
12052 marker: {
12053 size: 4,
12054 fillColor: '#fff',
12055 strokeWidth: 2,
12056 strokeColor: '#333',
12057 shape: 'circle',
12058 offsetX: 0,
12059 offsetY: 0,
12060 // radius: 2, // DEPRECATED
12061 cssClass: ''
12062 },
12063 label: {
12064 borderColor: '#c2c2c2',
12065 borderWidth: 1,
12066 borderRadius: 2,
12067 text: undefined,
12068 textAnchor: 'middle',
12069 offsetX: 0,
12070 offsetY: 0,
12071 mouseEnter: undefined,
12072 mouseLeave: undefined,
12073 click: undefined,
12074 style: {
12075 background: '#fff',
12076 color: undefined,
12077 fontSize: '11px',
12078 fontFamily: undefined,
12079 fontWeight: 400,
12080 cssClass: '',
12081 padding: {
12082 left: 5,
12083 right: 5,
12084 top: 2,
12085 bottom: 2
12086 }
12087 }
12088 },
12089 customSVG: {
12090 // this will be deprecated in the next major version as it is going to be replaced with a better alternative below (image)
12091 SVG: undefined,
12092 cssClass: undefined,
12093 offsetX: 0,
12094 offsetY: 0
12095 },
12096 image: {
12097 path: undefined,
12098 width: 20,
12099 height: 20,
12100 offsetX: 0,
12101 offsetY: 0
12102 }
12103 };
12104 this.yAxisAnnotation = {
12105 id: undefined,
12106 y: 0,
12107 y2: null,
12108 strokeDashArray: 1,
12109 fillColor: '#c2c2c2',
12110 borderColor: '#c2c2c2',
12111 borderWidth: 1,
12112 opacity: 0.3,
12113 offsetX: 0,
12114 offsetY: 0,
12115 width: '100%',
12116 yAxisIndex: 0,
12117 label: {
12118 borderColor: '#c2c2c2',
12119 borderWidth: 1,
12120 borderRadius: 2,
12121 text: undefined,
12122 textAnchor: 'end',
12123 position: 'right',
12124 offsetX: 0,
12125 offsetY: -3,
12126 mouseEnter: undefined,
12127 mouseLeave: undefined,
12128 click: undefined,
12129 style: {
12130 background: '#fff',
12131 color: undefined,
12132 fontSize: '11px',
12133 fontFamily: undefined,
12134 fontWeight: 400,
12135 cssClass: '',
12136 padding: {
12137 left: 5,
12138 right: 5,
12139 top: 2,
12140 bottom: 2
12141 }
12142 }
12143 }
12144 };
12145 this.xAxisAnnotation = {
12146 id: undefined,
12147 x: 0,
12148 x2: null,
12149 strokeDashArray: 1,
12150 fillColor: '#c2c2c2',
12151 borderColor: '#c2c2c2',
12152 borderWidth: 1,
12153 opacity: 0.3,
12154 offsetX: 0,
12155 offsetY: 0,
12156 label: {
12157 borderColor: '#c2c2c2',
12158 borderWidth: 1,
12159 borderRadius: 2,
12160 text: undefined,
12161 textAnchor: 'middle',
12162 orientation: 'vertical',
12163 position: 'top',
12164 offsetX: 0,
12165 offsetY: 0,
12166 mouseEnter: undefined,
12167 mouseLeave: undefined,
12168 click: undefined,
12169 style: {
12170 background: '#fff',
12171 color: undefined,
12172 fontSize: '11px',
12173 fontFamily: undefined,
12174 fontWeight: 400,
12175 cssClass: '',
12176 padding: {
12177 left: 5,
12178 right: 5,
12179 top: 2,
12180 bottom: 2
12181 }
12182 }
12183 }
12184 };
12185 this.text = {
12186 x: 0,
12187 y: 0,
12188 text: '',
12189 textAnchor: 'start',
12190 foreColor: undefined,
12191 fontSize: '13px',
12192 fontFamily: undefined,
12193 fontWeight: 400,
12194 appendTo: '.apexcharts-annotations',
12195 backgroundColor: 'transparent',
12196 borderColor: '#c2c2c2',
12197 borderRadius: 0,
12198 borderWidth: 0,
12199 paddingLeft: 4,
12200 paddingRight: 4,
12201 paddingTop: 2,
12202 paddingBottom: 2
12203 };
12204 }
12205 _createClass(Options, [{
12206 key: "init",
12207 value: function init() {
12208 return {
12209 annotations: {
12210 yaxis: [this.yAxisAnnotation],
12211 xaxis: [this.xAxisAnnotation],
12212 points: [this.pointAnnotation],
12213 texts: [],
12214 images: [],
12215 shapes: []
12216 },
12217 chart: {
12218 animations: {
12219 enabled: true,
12220 speed: 800,
12221 animateGradually: {
12222 delay: 150,
12223 enabled: true
12224 },
12225 dynamicAnimation: {
12226 enabled: true,
12227 speed: 350
12228 }
12229 },
12230 background: '',
12231 locales: [en],
12232 defaultLocale: 'en',
12233 dropShadow: {
12234 enabled: false,
12235 enabledOnSeries: undefined,
12236 top: 2,
12237 left: 2,
12238 blur: 4,
12239 color: '#000',
12240 opacity: 0.7
12241 },
12242 events: {
12243 animationEnd: undefined,
12244 beforeMount: undefined,
12245 mounted: undefined,
12246 updated: undefined,
12247 click: undefined,
12248 mouseMove: undefined,
12249 mouseLeave: undefined,
12250 xAxisLabelClick: undefined,
12251 legendClick: undefined,
12252 markerClick: undefined,
12253 selection: undefined,
12254 dataPointSelection: undefined,
12255 dataPointMouseEnter: undefined,
12256 dataPointMouseLeave: undefined,
12257 beforeZoom: undefined,
12258 beforeResetZoom: undefined,
12259 zoomed: undefined,
12260 scrolled: undefined,
12261 brushScrolled: undefined
12262 },
12263 foreColor: '#373d3f',
12264 fontFamily: 'Helvetica, Arial, sans-serif',
12265 height: 'auto',
12266 parentHeightOffset: 15,
12267 redrawOnParentResize: true,
12268 redrawOnWindowResize: true,
12269 id: undefined,
12270 group: undefined,
12271 nonce: undefined,
12272 offsetX: 0,
12273 offsetY: 0,
12274 selection: {
12275 enabled: false,
12276 type: 'x',
12277 // selectedPoints: undefined, // default datapoints that should be selected automatically
12278 fill: {
12279 color: '#24292e',
12280 opacity: 0.1
12281 },
12282 stroke: {
12283 width: 1,
12284 color: '#24292e',
12285 opacity: 0.4,
12286 dashArray: 3
12287 },
12288 xaxis: {
12289 min: undefined,
12290 max: undefined
12291 },
12292 yaxis: {
12293 min: undefined,
12294 max: undefined
12295 }
12296 },
12297 sparkline: {
12298 enabled: false
12299 },
12300 brush: {
12301 enabled: false,
12302 autoScaleYaxis: true,
12303 target: undefined,
12304 targets: undefined
12305 },
12306 stacked: false,
12307 stackOnlyBar: true,
12308 // mixed chart with stacked bars and line series - incorrect line draw #907
12309 stackType: 'normal',
12310 toolbar: {
12311 show: true,
12312 offsetX: 0,
12313 offsetY: 0,
12314 tools: {
12315 download: true,
12316 selection: true,
12317 zoom: true,
12318 zoomin: true,
12319 zoomout: true,
12320 pan: true,
12321 reset: true,
12322 customIcons: []
12323 },
12324 export: {
12325 csv: {
12326 filename: undefined,
12327 columnDelimiter: ',',
12328 headerCategory: 'category',
12329 headerValue: 'value',
12330 categoryFormatter: undefined,
12331 valueFormatter: undefined
12332 },
12333 png: {
12334 filename: undefined
12335 },
12336 svg: {
12337 filename: undefined
12338 },
12339 scale: undefined,
12340 width: undefined
12341 },
12342 autoSelected: 'zoom' // accepts -> zoom, pan, selection
12343 },
12344 type: 'line',
12345 width: '100%',
12346 zoom: {
12347 enabled: true,
12348 type: 'x',
12349 autoScaleYaxis: false,
12350 allowMouseWheelZoom: true,
12351 zoomedArea: {
12352 fill: {
12353 color: '#90CAF9',
12354 opacity: 0.4
12355 },
12356 stroke: {
12357 color: '#0D47A1',
12358 opacity: 0.4,
12359 width: 1
12360 }
12361 }
12362 }
12363 },
12364 plotOptions: {
12365 line: {
12366 isSlopeChart: false,
12367 colors: {
12368 threshold: 0,
12369 colorAboveThreshold: undefined,
12370 colorBelowThreshold: undefined
12371 }
12372 },
12373 area: {
12374 fillTo: 'origin'
12375 },
12376 bar: {
12377 horizontal: false,
12378 columnWidth: '70%',
12379 // should be in percent 0 - 100
12380 barHeight: '70%',
12381 // should be in percent 0 - 100
12382 distributed: false,
12383 borderRadius: 0,
12384 borderRadiusApplication: 'around',
12385 // [around, end]
12386 borderRadiusWhenStacked: 'last',
12387 // [all, last]
12388 rangeBarOverlap: true,
12389 rangeBarGroupRows: false,
12390 hideZeroBarsWhenGrouped: false,
12391 isDumbbell: false,
12392 dumbbellColors: undefined,
12393 isFunnel: false,
12394 isFunnel3d: true,
12395 colors: {
12396 ranges: [],
12397 backgroundBarColors: [],
12398 backgroundBarOpacity: 1,
12399 backgroundBarRadius: 0
12400 },
12401 dataLabels: {
12402 position: 'top',
12403 // top, center, bottom
12404 maxItems: 100,
12405 hideOverflowingLabels: true,
12406 orientation: 'horizontal',
12407 total: {
12408 enabled: false,
12409 formatter: undefined,
12410 offsetX: 0,
12411 offsetY: 0,
12412 style: {
12413 color: '#373d3f',
12414 fontSize: '12px',
12415 fontFamily: undefined,
12416 fontWeight: 600
12417 }
12418 }
12419 }
12420 },
12421 bubble: {
12422 zScaling: true,
12423 minBubbleRadius: undefined,
12424 maxBubbleRadius: undefined
12425 },
12426 candlestick: {
12427 colors: {
12428 upward: '#00B746',
12429 downward: '#EF403C'
12430 },
12431 wick: {
12432 useFillColor: true
12433 }
12434 },
12435 boxPlot: {
12436 colors: {
12437 upper: '#00E396',
12438 lower: '#008FFB'
12439 }
12440 },
12441 heatmap: {
12442 radius: 2,
12443 enableShades: true,
12444 shadeIntensity: 0.5,
12445 reverseNegativeShade: false,
12446 distributed: false,
12447 useFillColorAsStroke: false,
12448 colorScale: {
12449 inverse: false,
12450 ranges: [],
12451 min: undefined,
12452 max: undefined
12453 }
12454 },
12455 treemap: {
12456 enableShades: true,
12457 shadeIntensity: 0.5,
12458 distributed: false,
12459 reverseNegativeShade: false,
12460 useFillColorAsStroke: false,
12461 borderRadius: 4,
12462 dataLabels: {
12463 format: 'scale' // scale | truncate
12464 },
12465 colorScale: {
12466 inverse: false,
12467 ranges: [],
12468 min: undefined,
12469 max: undefined
12470 },
12471 seriesTitle: {
12472 show: true,
12473 offsetY: 1,
12474 offsetX: 1,
12475 borderColor: '#000',
12476 borderWidth: 1,
12477 borderRadius: 2,
12478 style: {
12479 background: 'rgba(0, 0, 0, 0.6)',
12480 color: '#fff',
12481 fontSize: '12px',
12482 fontFamily: undefined,
12483 fontWeight: 400,
12484 cssClass: '',
12485 padding: {
12486 left: 6,
12487 right: 6,
12488 top: 2,
12489 bottom: 2
12490 }
12491 }
12492 }
12493 },
12494 radialBar: {
12495 inverseOrder: false,
12496 startAngle: 0,
12497 endAngle: 360,
12498 offsetX: 0,
12499 offsetY: 0,
12500 hollow: {
12501 margin: 5,
12502 size: '50%',
12503 background: 'transparent',
12504 image: undefined,
12505 imageWidth: 150,
12506 imageHeight: 150,
12507 imageOffsetX: 0,
12508 imageOffsetY: 0,
12509 imageClipped: true,
12510 position: 'front',
12511 dropShadow: {
12512 enabled: false,
12513 top: 0,
12514 left: 0,
12515 blur: 3,
12516 color: '#000',
12517 opacity: 0.5
12518 }
12519 },
12520 track: {
12521 show: true,
12522 startAngle: undefined,
12523 endAngle: undefined,
12524 background: '#f2f2f2',
12525 strokeWidth: '97%',
12526 opacity: 1,
12527 margin: 5,
12528 // margin is in pixels
12529 dropShadow: {
12530 enabled: false,
12531 top: 0,
12532 left: 0,
12533 blur: 3,
12534 color: '#000',
12535 opacity: 0.5
12536 }
12537 },
12538 dataLabels: {
12539 show: true,
12540 name: {
12541 show: true,
12542 fontSize: '16px',
12543 fontFamily: undefined,
12544 fontWeight: 600,
12545 color: undefined,
12546 offsetY: 0,
12547 formatter: function formatter(val) {
12548 return val;
12549 }
12550 },
12551 value: {
12552 show: true,
12553 fontSize: '14px',
12554 fontFamily: undefined,
12555 fontWeight: 400,
12556 color: undefined,
12557 offsetY: 16,
12558 formatter: function formatter(val) {
12559 return val + '%';
12560 }
12561 },
12562 total: {
12563 show: false,
12564 label: 'Total',
12565 fontSize: '16px',
12566 fontWeight: 600,
12567 fontFamily: undefined,
12568 color: undefined,
12569 formatter: function formatter(w) {
12570 return w.globals.seriesTotals.reduce(function (a, b) {
12571 return a + b;
12572 }, 0) / w.globals.series.length + '%';
12573 }
12574 }
12575 },
12576 barLabels: {
12577 enabled: false,
12578 offsetX: 0,
12579 offsetY: 0,
12580 useSeriesColors: true,
12581 fontFamily: undefined,
12582 fontWeight: 600,
12583 fontSize: '16px',
12584 formatter: function formatter(val) {
12585 return val;
12586 },
12587 onClick: undefined
12588 }
12589 },
12590 pie: {
12591 customScale: 1,
12592 offsetX: 0,
12593 offsetY: 0,
12594 startAngle: 0,
12595 endAngle: 360,
12596 expandOnClick: true,
12597 dataLabels: {
12598 // These are the percentage values which are displayed on slice
12599 offset: 0,
12600 // offset by which labels will move outside
12601 minAngleToShowLabel: 10
12602 },
12603 donut: {
12604 size: '65%',
12605 background: 'transparent',
12606 labels: {
12607 // These are the inner labels appearing inside donut
12608 show: false,
12609 name: {
12610 show: true,
12611 fontSize: '16px',
12612 fontFamily: undefined,
12613 fontWeight: 600,
12614 color: undefined,
12615 offsetY: -10,
12616 formatter: function formatter(val) {
12617 return val;
12618 }
12619 },
12620 value: {
12621 show: true,
12622 fontSize: '20px',
12623 fontFamily: undefined,
12624 fontWeight: 400,
12625 color: undefined,
12626 offsetY: 10,
12627 formatter: function formatter(val) {
12628 return val;
12629 }
12630 },
12631 total: {
12632 show: false,
12633 showAlways: false,
12634 label: 'Total',
12635 fontSize: '16px',
12636 fontWeight: 400,
12637 fontFamily: undefined,
12638 color: undefined,
12639 formatter: function formatter(w) {
12640 return w.globals.seriesTotals.reduce(function (a, b) {
12641 return a + b;
12642 }, 0);
12643 }
12644 }
12645 }
12646 }
12647 },
12648 polarArea: {
12649 rings: {
12650 strokeWidth: 1,
12651 strokeColor: '#e8e8e8'
12652 },
12653 spokes: {
12654 strokeWidth: 1,
12655 connectorColors: '#e8e8e8'
12656 }
12657 },
12658 radar: {
12659 size: undefined,
12660 offsetX: 0,
12661 offsetY: 0,
12662 polygons: {
12663 // strokeColor: '#e8e8e8', // should be deprecated in the minor version i.e 3.2
12664 strokeWidth: 1,
12665 strokeColors: '#e8e8e8',
12666 connectorColors: '#e8e8e8',
12667 fill: {
12668 colors: undefined
12669 }
12670 }
12671 }
12672 },
12673 colors: undefined,
12674 dataLabels: {
12675 enabled: true,
12676 enabledOnSeries: undefined,
12677 formatter: function formatter(val) {
12678 return val !== null ? val : '';
12679 },
12680 textAnchor: 'middle',
12681 distributed: false,
12682 offsetX: 0,
12683 offsetY: 0,
12684 style: {
12685 fontSize: '12px',
12686 fontFamily: undefined,
12687 fontWeight: 600,
12688 colors: undefined
12689 },
12690 background: {
12691 enabled: true,
12692 foreColor: '#fff',
12693 backgroundColor: undefined,
12694 borderRadius: 2,
12695 padding: 4,
12696 opacity: 0.9,
12697 borderWidth: 1,
12698 borderColor: '#fff',
12699 dropShadow: {
12700 enabled: false,
12701 top: 1,
12702 left: 1,
12703 blur: 1,
12704 color: '#000',
12705 opacity: 0.8
12706 }
12707 },
12708 dropShadow: {
12709 enabled: false,
12710 top: 1,
12711 left: 1,
12712 blur: 1,
12713 color: '#000',
12714 opacity: 0.8
12715 }
12716 },
12717 fill: {
12718 type: 'solid',
12719 colors: undefined,
12720 // array of colors
12721 opacity: 0.85,
12722 gradient: {
12723 shade: 'dark',
12724 type: 'horizontal',
12725 shadeIntensity: 0.5,
12726 gradientToColors: undefined,
12727 inverseColors: true,
12728 opacityFrom: 1,
12729 opacityTo: 1,
12730 stops: [0, 50, 100],
12731 colorStops: []
12732 },
12733 image: {
12734 src: [],
12735 width: undefined,
12736 // optional
12737 height: undefined // optional
12738 },
12739 pattern: {
12740 style: 'squares',
12741 // String | Array of Strings
12742 width: 6,
12743 height: 6,
12744 strokeWidth: 2
12745 }
12746 },
12747 forecastDataPoints: {
12748 count: 0,
12749 fillOpacity: 0.5,
12750 strokeWidth: undefined,
12751 dashArray: 4
12752 },
12753 grid: {
12754 show: true,
12755 borderColor: '#e0e0e0',
12756 strokeDashArray: 0,
12757 position: 'back',
12758 xaxis: {
12759 lines: {
12760 show: false
12761 }
12762 },
12763 yaxis: {
12764 lines: {
12765 show: true
12766 }
12767 },
12768 row: {
12769 colors: undefined,
12770 // takes as array which will be repeated on rows
12771 opacity: 0.5
12772 },
12773 column: {
12774 colors: undefined,
12775 // takes an array which will be repeated on columns
12776 opacity: 0.5
12777 },
12778 padding: {
12779 top: 0,
12780 right: 10,
12781 bottom: 0,
12782 left: 12
12783 }
12784 },
12785 labels: [],
12786 legend: {
12787 show: true,
12788 showForSingleSeries: false,
12789 showForNullSeries: true,
12790 showForZeroSeries: true,
12791 floating: false,
12792 position: 'bottom',
12793 // whether to position legends in 1 of 4
12794 // direction - top, bottom, left, right
12795 horizontalAlign: 'center',
12796 // when position top/bottom, you can specify whether to align legends left, right or center
12797 inverseOrder: false,
12798 fontSize: '12px',
12799 fontFamily: undefined,
12800 fontWeight: 400,
12801 width: undefined,
12802 height: undefined,
12803 formatter: undefined,
12804 tooltipHoverFormatter: undefined,
12805 offsetX: -20,
12806 offsetY: 4,
12807 customLegendItems: [],
12808 clusterGroupedSeries: true,
12809 clusterGroupedSeriesOrientation: 'vertical',
12810 labels: {
12811 colors: undefined,
12812 useSeriesColors: false
12813 },
12814 markers: {
12815 size: 7,
12816 fillColors: undefined,
12817 strokeWidth: 1,
12818 shape: undefined,
12819 offsetX: 0,
12820 offsetY: 0,
12821 customHTML: undefined,
12822 onClick: undefined
12823 },
12824 itemMargin: {
12825 horizontal: 5,
12826 vertical: 4
12827 },
12828 onItemClick: {
12829 toggleDataSeries: true
12830 },
12831 onItemHover: {
12832 highlightDataSeries: true
12833 }
12834 },
12835 markers: {
12836 discrete: [],
12837 size: 0,
12838 colors: undefined,
12839 strokeColors: '#fff',
12840 strokeWidth: 2,
12841 strokeOpacity: 0.9,
12842 strokeDashArray: 0,
12843 fillOpacity: 1,
12844 shape: 'circle',
12845 offsetX: 0,
12846 offsetY: 0,
12847 showNullDataPoints: true,
12848 onClick: undefined,
12849 onDblClick: undefined,
12850 hover: {
12851 size: undefined,
12852 sizeOffset: 3
12853 }
12854 },
12855 noData: {
12856 text: undefined,
12857 align: 'center',
12858 verticalAlign: 'middle',
12859 offsetX: 0,
12860 offsetY: 0,
12861 style: {
12862 color: undefined,
12863 fontSize: '14px',
12864 fontFamily: undefined
12865 }
12866 },
12867 responsive: [],
12868 // breakpoints should follow ascending order 400, then 700, then 1000
12869 series: undefined,
12870 states: {
12871 hover: {
12872 filter: {
12873 type: 'lighten'
12874 }
12875 },
12876 active: {
12877 allowMultipleDataPointsSelection: false,
12878 filter: {
12879 type: 'darken'
12880 }
12881 }
12882 },
12883 title: {
12884 text: undefined,
12885 align: 'left',
12886 margin: 5,
12887 offsetX: 0,
12888 offsetY: 0,
12889 floating: false,
12890 style: {
12891 fontSize: '14px',
12892 fontWeight: 900,
12893 fontFamily: undefined,
12894 color: undefined
12895 }
12896 },
12897 subtitle: {
12898 text: undefined,
12899 align: 'left',
12900 margin: 5,
12901 offsetX: 0,
12902 offsetY: 30,
12903 floating: false,
12904 style: {
12905 fontSize: '12px',
12906 fontWeight: 400,
12907 fontFamily: undefined,
12908 color: undefined
12909 }
12910 },
12911 stroke: {
12912 show: true,
12913 curve: 'smooth',
12914 // "smooth" / "straight" / "monotoneCubic" / "stepline" / "linestep"
12915 lineCap: 'butt',
12916 // round, butt , square
12917 width: 2,
12918 colors: undefined,
12919 // array of colors
12920 dashArray: 0,
12921 // single value or array of values
12922 fill: {
12923 type: 'solid',
12924 colors: undefined,
12925 // array of colors
12926 opacity: 0.85,
12927 gradient: {
12928 shade: 'dark',
12929 type: 'horizontal',
12930 shadeIntensity: 0.5,
12931 gradientToColors: undefined,
12932 inverseColors: true,
12933 opacityFrom: 1,
12934 opacityTo: 1,
12935 stops: [0, 50, 100],
12936 colorStops: []
12937 }
12938 }
12939 },
12940 tooltip: {
12941 enabled: true,
12942 enabledOnSeries: undefined,
12943 shared: true,
12944 hideEmptySeries: false,
12945 followCursor: false,
12946 // when disabled, the tooltip will show on top of the series instead of mouse position
12947 intersect: false,
12948 // when enabled, tooltip will only show when user directly hovers over point
12949 inverseOrder: false,
12950 custom: undefined,
12951 fillSeriesColor: false,
12952 theme: 'light',
12953 cssClass: '',
12954 style: {
12955 fontSize: '12px',
12956 fontFamily: undefined
12957 },
12958 onDatasetHover: {
12959 highlightDataSeries: false
12960 },
12961 x: {
12962 // x value
12963 show: true,
12964 format: 'dd MMM',
12965 // dd/MM, dd MMM yy, dd MMM yyyy
12966 formatter: undefined // a custom user supplied formatter function
12967 },
12968 y: {
12969 formatter: undefined,
12970 title: {
12971 formatter: function formatter(seriesName) {
12972 return seriesName ? seriesName + ': ' : '';
12973 }
12974 }
12975 },
12976 z: {
12977 formatter: undefined,
12978 title: 'Size: '
12979 },
12980 marker: {
12981 show: true,
12982 fillColors: undefined
12983 },
12984 items: {
12985 display: 'flex'
12986 },
12987 fixed: {
12988 enabled: false,
12989 position: 'topRight',
12990 // topRight, topLeft, bottomRight, bottomLeft
12991 offsetX: 0,
12992 offsetY: 0
12993 }
12994 },
12995 xaxis: {
12996 type: 'category',
12997 categories: [],
12998 convertedCatToNumeric: false,
12999 // internal property which should not be altered outside
13000 offsetX: 0,
13001 offsetY: 0,
13002 overwriteCategories: undefined,
13003 labels: {
13004 show: true,
13005 rotate: -45,
13006 rotateAlways: false,
13007 hideOverlappingLabels: true,
13008 trim: false,
13009 minHeight: undefined,
13010 maxHeight: 120,
13011 showDuplicates: true,
13012 style: {
13013 colors: [],
13014 fontSize: '12px',
13015 fontWeight: 400,
13016 fontFamily: undefined,
13017 cssClass: ''
13018 },
13019 offsetX: 0,
13020 offsetY: 0,
13021 format: undefined,
13022 formatter: undefined,
13023 // custom formatter function which will override format
13024 datetimeUTC: true,
13025 datetimeFormatter: {
13026 year: 'yyyy',
13027 month: "MMM 'yy",
13028 day: 'dd MMM',
13029 hour: 'HH:mm',
13030 minute: 'HH:mm:ss',
13031 second: 'HH:mm:ss'
13032 }
13033 },
13034 group: {
13035 groups: [],
13036 style: {
13037 colors: [],
13038 fontSize: '12px',
13039 fontWeight: 400,
13040 fontFamily: undefined,
13041 cssClass: ''
13042 }
13043 },
13044 axisBorder: {
13045 show: true,
13046 color: '#e0e0e0',
13047 width: '100%',
13048 height: 1,
13049 offsetX: 0,
13050 offsetY: 0
13051 },
13052 axisTicks: {
13053 show: true,
13054 color: '#e0e0e0',
13055 height: 6,
13056 offsetX: 0,
13057 offsetY: 0
13058 },
13059 stepSize: undefined,
13060 tickAmount: undefined,
13061 tickPlacement: 'on',
13062 min: undefined,
13063 max: undefined,
13064 range: undefined,
13065 floating: false,
13066 decimalsInFloat: undefined,
13067 position: 'bottom',
13068 title: {
13069 text: undefined,
13070 offsetX: 0,
13071 offsetY: 0,
13072 style: {
13073 color: undefined,
13074 fontSize: '12px',
13075 fontWeight: 900,
13076 fontFamily: undefined,
13077 cssClass: ''
13078 }
13079 },
13080 crosshairs: {
13081 show: true,
13082 width: 1,
13083 // tickWidth/barWidth or an integer
13084 position: 'back',
13085 opacity: 0.9,
13086 stroke: {
13087 color: '#b6b6b6',
13088 width: 1,
13089 dashArray: 3
13090 },
13091 fill: {
13092 type: 'solid',
13093 // solid, gradient
13094 color: '#B1B9C4',
13095 gradient: {
13096 colorFrom: '#D8E3F0',
13097 colorTo: '#BED1E6',
13098 stops: [0, 100],
13099 opacityFrom: 0.4,
13100 opacityTo: 0.5
13101 }
13102 },
13103 dropShadow: {
13104 enabled: false,
13105 left: 0,
13106 top: 0,
13107 blur: 1,
13108 opacity: 0.8
13109 }
13110 },
13111 tooltip: {
13112 enabled: true,
13113 offsetY: 0,
13114 formatter: undefined,
13115 style: {
13116 fontSize: '12px',
13117 fontFamily: undefined
13118 }
13119 }
13120 },
13121 yaxis: this.yAxis,
13122 theme: {
13123 mode: '',
13124 palette: 'palette1',
13125 // If defined, it will overwrite globals.colors variable
13126 monochrome: {
13127 // monochrome allows you to select just 1 color and fill out the rest with light/dark shade (intensity can be selected)
13128 enabled: false,
13129 color: '#008FFB',
13130 shadeTo: 'light',
13131 shadeIntensity: 0.65
13132 }
13133 }
13134 };
13135 }
13136 }]);
13137 return Options;
13138 }();
13139
13140 /**
13141 * ApexCharts Annotations Class for drawing lines/rects on both xaxis and yaxis.
13142 *
13143 * @module Annotations
13144 **/
13145 var Annotations = /*#__PURE__*/function () {
13146 function Annotations(ctx) {
13147 _classCallCheck(this, Annotations);
13148 this.ctx = ctx;
13149 this.w = ctx.w;
13150 this.graphics = new Graphics(this.ctx);
13151 if (this.w.globals.isBarHorizontal) {
13152 this.invertAxis = true;
13153 }
13154 this.helpers = new Helpers$4(this);
13155 this.xAxisAnnotations = new XAnnotations(this);
13156 this.yAxisAnnotations = new YAnnotations(this);
13157 this.pointsAnnotations = new PointAnnotations(this);
13158 if (this.w.globals.isBarHorizontal && this.w.config.yaxis[0].reversed) {
13159 this.inversedReversedAxis = true;
13160 }
13161 this.xDivision = this.w.globals.gridWidth / this.w.globals.dataPoints;
13162 }
13163 _createClass(Annotations, [{
13164 key: "drawAxesAnnotations",
13165 value: function drawAxesAnnotations() {
13166 var w = this.w;
13167 if (w.globals.axisCharts && w.globals.dataPoints) {
13168 // w.globals.dataPoints check added to fix #1832
13169 var yAnnotations = this.yAxisAnnotations.drawYAxisAnnotations();
13170 var xAnnotations = this.xAxisAnnotations.drawXAxisAnnotations();
13171 var pointAnnotations = this.pointsAnnotations.drawPointAnnotations();
13172 var initialAnim = w.config.chart.animations.enabled;
13173 var annoArray = [yAnnotations, xAnnotations, pointAnnotations];
13174 var annoElArray = [xAnnotations.node, yAnnotations.node, pointAnnotations.node];
13175 for (var i = 0; i < 3; i++) {
13176 w.globals.dom.elGraphical.add(annoArray[i]);
13177 if (initialAnim && !w.globals.resized && !w.globals.dataChanged) {
13178 // fixes apexcharts/apexcharts.js#685
13179 if (w.config.chart.type !== 'scatter' && w.config.chart.type !== 'bubble' && w.globals.dataPoints > 1) {
13180 annoElArray[i].classList.add('apexcharts-element-hidden');
13181 }
13182 }
13183 w.globals.delayedElements.push({
13184 el: annoElArray[i],
13185 index: 0
13186 });
13187 }
13188
13189 // background sizes needs to be calculated after text is drawn, so calling them last
13190 this.helpers.annotationsBackground();
13191 }
13192 }
13193 }, {
13194 key: "drawImageAnnos",
13195 value: function drawImageAnnos() {
13196 var _this = this;
13197 var w = this.w;
13198 w.config.annotations.images.map(function (s, index) {
13199 _this.addImage(s, index);
13200 });
13201 }
13202 }, {
13203 key: "drawTextAnnos",
13204 value: function drawTextAnnos() {
13205 var _this2 = this;
13206 var w = this.w;
13207 w.config.annotations.texts.map(function (t, index) {
13208 _this2.addText(t, index);
13209 });
13210 }
13211 }, {
13212 key: "addXaxisAnnotation",
13213 value: function addXaxisAnnotation(anno, parent, index) {
13214 this.xAxisAnnotations.addXaxisAnnotation(anno, parent, index);
13215 }
13216 }, {
13217 key: "addYaxisAnnotation",
13218 value: function addYaxisAnnotation(anno, parent, index) {
13219 this.yAxisAnnotations.addYaxisAnnotation(anno, parent, index);
13220 }
13221 }, {
13222 key: "addPointAnnotation",
13223 value: function addPointAnnotation(anno, parent, index) {
13224 this.pointsAnnotations.addPointAnnotation(anno, parent, index);
13225 }
13226 }, {
13227 key: "addText",
13228 value: function addText(params, index) {
13229 var x = params.x,
13230 y = params.y,
13231 text = params.text,
13232 textAnchor = params.textAnchor,
13233 foreColor = params.foreColor,
13234 fontSize = params.fontSize,
13235 fontFamily = params.fontFamily,
13236 fontWeight = params.fontWeight,
13237 cssClass = params.cssClass,
13238 backgroundColor = params.backgroundColor,
13239 borderWidth = params.borderWidth,
13240 strokeDashArray = params.strokeDashArray,
13241 borderRadius = params.borderRadius,
13242 borderColor = params.borderColor,
13243 _params$appendTo = params.appendTo,
13244 appendTo = _params$appendTo === void 0 ? '.apexcharts-svg' : _params$appendTo,
13245 _params$paddingLeft = params.paddingLeft,
13246 paddingLeft = _params$paddingLeft === void 0 ? 4 : _params$paddingLeft,
13247 _params$paddingRight = params.paddingRight,
13248 paddingRight = _params$paddingRight === void 0 ? 4 : _params$paddingRight,
13249 _params$paddingBottom = params.paddingBottom,
13250 paddingBottom = _params$paddingBottom === void 0 ? 2 : _params$paddingBottom,
13251 _params$paddingTop = params.paddingTop,
13252 paddingTop = _params$paddingTop === void 0 ? 2 : _params$paddingTop;
13253 var w = this.w;
13254 var elText = this.graphics.drawText({
13255 x: x,
13256 y: y,
13257 text: text,
13258 textAnchor: textAnchor || 'start',
13259 fontSize: fontSize || '12px',
13260 fontWeight: fontWeight || 'regular',
13261 fontFamily: fontFamily || w.config.chart.fontFamily,
13262 foreColor: foreColor || w.config.chart.foreColor,
13263 cssClass: 'apexcharts-text ' + cssClass ? cssClass : ''
13264 });
13265 var parent = w.globals.dom.baseEl.querySelector(appendTo);
13266 if (parent) {
13267 parent.appendChild(elText.node);
13268 }
13269 var textRect = elText.bbox();
13270 if (text) {
13271 var elRect = this.graphics.drawRect(textRect.x - paddingLeft, textRect.y - paddingTop, textRect.width + paddingLeft + paddingRight, textRect.height + paddingBottom + paddingTop, borderRadius, backgroundColor ? backgroundColor : 'transparent', 1, borderWidth, borderColor, strokeDashArray);
13272 parent.insertBefore(elRect.node, elText.node);
13273 }
13274 }
13275 }, {
13276 key: "addImage",
13277 value: function addImage(params, index) {
13278 var w = this.w;
13279 var path = params.path,
13280 _params$x = params.x,
13281 x = _params$x === void 0 ? 0 : _params$x,
13282 _params$y = params.y,
13283 y = _params$y === void 0 ? 0 : _params$y,
13284 _params$width = params.width,
13285 width = _params$width === void 0 ? 20 : _params$width,
13286 _params$height = params.height,
13287 height = _params$height === void 0 ? 20 : _params$height,
13288 _params$appendTo2 = params.appendTo,
13289 appendTo = _params$appendTo2 === void 0 ? '.apexcharts-svg' : _params$appendTo2;
13290 var img = w.globals.dom.Paper.image(path);
13291 img.size(width, height).move(x, y);
13292 var parent = w.globals.dom.baseEl.querySelector(appendTo);
13293 if (parent) {
13294 parent.appendChild(img.node);
13295 }
13296 return img;
13297 }
13298
13299 // The addXaxisAnnotation method requires a parent class, and user calling this method externally on the chart instance may not specify parent, hence a different method
13300 }, {
13301 key: "addXaxisAnnotationExternal",
13302 value: function addXaxisAnnotationExternal(params, pushToMemory, context) {
13303 this.addAnnotationExternal({
13304 params: params,
13305 pushToMemory: pushToMemory,
13306 context: context,
13307 type: 'xaxis',
13308 contextMethod: context.addXaxisAnnotation
13309 });
13310 return context;
13311 }
13312 }, {
13313 key: "addYaxisAnnotationExternal",
13314 value: function addYaxisAnnotationExternal(params, pushToMemory, context) {
13315 this.addAnnotationExternal({
13316 params: params,
13317 pushToMemory: pushToMemory,
13318 context: context,
13319 type: 'yaxis',
13320 contextMethod: context.addYaxisAnnotation
13321 });
13322 return context;
13323 }
13324 }, {
13325 key: "addPointAnnotationExternal",
13326 value: function addPointAnnotationExternal(params, pushToMemory, context) {
13327 if (typeof this.invertAxis === 'undefined') {
13328 this.invertAxis = context.w.globals.isBarHorizontal;
13329 }
13330 this.addAnnotationExternal({
13331 params: params,
13332 pushToMemory: pushToMemory,
13333 context: context,
13334 type: 'point',
13335 contextMethod: context.addPointAnnotation
13336 });
13337 return context;
13338 }
13339 }, {
13340 key: "addAnnotationExternal",
13341 value: function addAnnotationExternal(_ref) {
13342 var params = _ref.params,
13343 pushToMemory = _ref.pushToMemory,
13344 context = _ref.context,
13345 type = _ref.type,
13346 contextMethod = _ref.contextMethod;
13347 var me = context;
13348 var w = me.w;
13349 var parent = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-annotations"));
13350 var index = parent.childNodes.length + 1;
13351 var options = new Options();
13352 var axesAnno = Object.assign({}, type === 'xaxis' ? options.xAxisAnnotation : type === 'yaxis' ? options.yAxisAnnotation : options.pointAnnotation);
13353 var anno = Utils$1.extend(axesAnno, params);
13354 switch (type) {
13355 case 'xaxis':
13356 this.addXaxisAnnotation(anno, parent, index);
13357 break;
13358 case 'yaxis':
13359 this.addYaxisAnnotation(anno, parent, index);
13360 break;
13361 case 'point':
13362 this.addPointAnnotation(anno, parent, index);
13363 break;
13364 }
13365
13366 // add background
13367 var axesAnnoLabel = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-annotations .apexcharts-").concat(type, "-annotation-label[rel='").concat(index, "']"));
13368 var elRect = this.helpers.addBackgroundToAnno(axesAnnoLabel, anno);
13369 if (elRect) {
13370 parent.insertBefore(elRect.node, axesAnnoLabel);
13371 }
13372 if (pushToMemory) {
13373 w.globals.memory.methodsToExec.push({
13374 context: me,
13375 id: anno.id ? anno.id : Utils$1.randomId(),
13376 method: contextMethod,
13377 label: 'addAnnotation',
13378 params: params
13379 });
13380 }
13381 return context;
13382 }
13383 }, {
13384 key: "clearAnnotations",
13385 value: function clearAnnotations(ctx) {
13386 var w = ctx.w;
13387 var annos = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxis-annotations, .apexcharts-xaxis-annotations, .apexcharts-point-annotations');
13388
13389 // annotations added externally should be cleared out too
13390 for (var i = w.globals.memory.methodsToExec.length - 1; i >= 0; i--) {
13391 if (w.globals.memory.methodsToExec[i].label === 'addText' || w.globals.memory.methodsToExec[i].label === 'addAnnotation') {
13392 w.globals.memory.methodsToExec.splice(i, 1);
13393 }
13394 }
13395 annos = Utils$1.listToArray(annos);
13396
13397 // delete the DOM elements
13398 Array.prototype.forEach.call(annos, function (a) {
13399 while (a.firstChild) {
13400 a.removeChild(a.firstChild);
13401 }
13402 });
13403 }
13404 }, {
13405 key: "removeAnnotation",
13406 value: function removeAnnotation(ctx, id) {
13407 var w = ctx.w;
13408 var annos = w.globals.dom.baseEl.querySelectorAll(".".concat(id));
13409 if (annos) {
13410 w.globals.memory.methodsToExec.map(function (m, i) {
13411 if (m.id === id) {
13412 w.globals.memory.methodsToExec.splice(i, 1);
13413 }
13414 });
13415 Object.keys(w.config.annotations).forEach(function (key) {
13416 var annotationArray = w.config.annotations[key];
13417 if (Array.isArray(annotationArray)) {
13418 // remove entry from the config, so on the next update it doesn't come back
13419 w.config.annotations[key] = annotationArray.filter(function (m) {
13420 return m.id !== id;
13421 });
13422 }
13423 });
13424 Array.prototype.forEach.call(annos, function (a) {
13425 a.parentElement.removeChild(a);
13426 });
13427 }
13428 }
13429 }]);
13430 return Annotations;
13431 }();
13432
13433 /**
13434 * ApexCharts Default Class for setting default options for all chart types.
13435 *
13436 * @module Defaults
13437 **/
13438
13439 var getRangeValues = function getRangeValues(_ref) {
13440 var _w$config$series$seri;
13441 var isTimeline = _ref.isTimeline,
13442 ctx = _ref.ctx,
13443 seriesIndex = _ref.seriesIndex,
13444 dataPointIndex = _ref.dataPointIndex,
13445 y1 = _ref.y1,
13446 y2 = _ref.y2,
13447 w = _ref.w;
13448 var start = w.globals.seriesRangeStart[seriesIndex][dataPointIndex];
13449 var end = w.globals.seriesRangeEnd[seriesIndex][dataPointIndex];
13450 var ylabel = w.globals.labels[dataPointIndex];
13451 var seriesName = w.config.series[seriesIndex].name ? w.config.series[seriesIndex].name : '';
13452 var yLbFormatter = w.globals.ttKeyFormatter;
13453 var yLbTitleFormatter = w.config.tooltip.y.title.formatter;
13454 var opts = {
13455 w: w,
13456 seriesIndex: seriesIndex,
13457 dataPointIndex: dataPointIndex,
13458 start: start,
13459 end: end
13460 };
13461 if (typeof yLbTitleFormatter === 'function') {
13462 seriesName = yLbTitleFormatter(seriesName, opts);
13463 }
13464 if ((_w$config$series$seri = w.config.series[seriesIndex].data[dataPointIndex]) !== null && _w$config$series$seri !== void 0 && _w$config$series$seri.x) {
13465 ylabel = w.config.series[seriesIndex].data[dataPointIndex].x;
13466 }
13467 if (!isTimeline) {
13468 if (w.config.xaxis.type === 'datetime') {
13469 var xFormat = new Formatters(ctx);
13470 ylabel = xFormat.xLabelFormat(w.globals.ttKeyFormatter, ylabel, ylabel, {
13471 i: undefined,
13472 dateFormatter: new DateTime(ctx).formatDate,
13473 w: w
13474 });
13475 }
13476 }
13477 if (typeof yLbFormatter === 'function') {
13478 ylabel = yLbFormatter(ylabel, opts);
13479 }
13480 if (Number.isFinite(y1) && Number.isFinite(y2)) {
13481 start = y1;
13482 end = y2;
13483 }
13484 var startVal = '';
13485 var endVal = '';
13486 var color = w.globals.colors[seriesIndex];
13487 if (w.config.tooltip.x.formatter === undefined) {
13488 if (w.config.xaxis.type === 'datetime') {
13489 var datetimeObj = new DateTime(ctx);
13490 startVal = datetimeObj.formatDate(datetimeObj.getDate(start), w.config.tooltip.x.format);
13491 endVal = datetimeObj.formatDate(datetimeObj.getDate(end), w.config.tooltip.x.format);
13492 } else {
13493 startVal = start;
13494 endVal = end;
13495 }
13496 } else {
13497 startVal = w.config.tooltip.x.formatter(start);
13498 endVal = w.config.tooltip.x.formatter(end);
13499 }
13500 return {
13501 start: start,
13502 end: end,
13503 startVal: startVal,
13504 endVal: endVal,
13505 ylabel: ylabel,
13506 color: color,
13507 seriesName: seriesName
13508 };
13509 };
13510 var buildRangeTooltipHTML = function buildRangeTooltipHTML(opts) {
13511 var color = opts.color,
13512 seriesName = opts.seriesName,
13513 ylabel = opts.ylabel,
13514 start = opts.start,
13515 end = opts.end,
13516 seriesIndex = opts.seriesIndex,
13517 dataPointIndex = opts.dataPointIndex;
13518 var formatter = opts.ctx.tooltip.tooltipLabels.getFormatters(seriesIndex);
13519 start = formatter.yLbFormatter(start);
13520 end = formatter.yLbFormatter(end);
13521 var val = formatter.yLbFormatter(opts.w.globals.series[seriesIndex][dataPointIndex]);
13522 var valueHTML = '';
13523 var rangeValues = "<span class=\"value start-value\">\n ".concat(start, "\n </span> <span class=\"separator\">-</span> <span class=\"value end-value\">\n ").concat(end, "\n </span>");
13524 if (opts.w.globals.comboCharts) {
13525 if (opts.w.config.series[seriesIndex].type === 'rangeArea' || opts.w.config.series[seriesIndex].type === 'rangeBar') {
13526 valueHTML = rangeValues;
13527 } else {
13528 valueHTML = "<span>".concat(val, "</span>");
13529 }
13530 } else {
13531 valueHTML = rangeValues;
13532 }
13533 return '<div class="apexcharts-tooltip-rangebar">' + '<div> <span class="series-name" style="color: ' + color + '">' + (seriesName ? seriesName : '') + '</span></div>' + '<div> <span class="category">' + ylabel + ': </span> ' + valueHTML + ' </div>' + '</div>';
13534 };
13535 var Defaults = /*#__PURE__*/function () {
13536 function Defaults(opts) {
13537 _classCallCheck(this, Defaults);
13538 this.opts = opts;
13539 }
13540 _createClass(Defaults, [{
13541 key: "hideYAxis",
13542 value: function hideYAxis() {
13543 this.opts.yaxis[0].show = false;
13544 this.opts.yaxis[0].title.text = '';
13545 this.opts.yaxis[0].axisBorder.show = false;
13546 this.opts.yaxis[0].axisTicks.show = false;
13547 this.opts.yaxis[0].floating = true;
13548 }
13549 }, {
13550 key: "line",
13551 value: function line() {
13552 return {
13553 dataLabels: {
13554 enabled: false
13555 },
13556 stroke: {
13557 width: 5,
13558 curve: 'straight'
13559 },
13560 markers: {
13561 size: 0,
13562 hover: {
13563 sizeOffset: 6
13564 }
13565 },
13566 xaxis: {
13567 crosshairs: {
13568 width: 1
13569 }
13570 }
13571 };
13572 }
13573 }, {
13574 key: "sparkline",
13575 value: function sparkline(defaults) {
13576 this.hideYAxis();
13577 var ret = {
13578 grid: {
13579 show: false,
13580 padding: {
13581 left: 0,
13582 right: 0,
13583 top: 0,
13584 bottom: 0
13585 }
13586 },
13587 legend: {
13588 show: false
13589 },
13590 xaxis: {
13591 labels: {
13592 show: false
13593 },
13594 tooltip: {
13595 enabled: false
13596 },
13597 axisBorder: {
13598 show: false
13599 },
13600 axisTicks: {
13601 show: false
13602 }
13603 },
13604 chart: {
13605 toolbar: {
13606 show: false
13607 },
13608 zoom: {
13609 enabled: false
13610 }
13611 },
13612 dataLabels: {
13613 enabled: false
13614 }
13615 };
13616 return Utils$1.extend(defaults, ret);
13617 }
13618 }, {
13619 key: "slope",
13620 value: function slope() {
13621 this.hideYAxis();
13622 return {
13623 chart: {
13624 toolbar: {
13625 show: false
13626 },
13627 zoom: {
13628 enabled: false
13629 }
13630 },
13631 dataLabels: {
13632 enabled: true,
13633 formatter: function formatter(val, opts) {
13634 var seriesName = opts.w.config.series[opts.seriesIndex].name;
13635 return val !== null ? seriesName + ': ' + val : '';
13636 },
13637 background: {
13638 enabled: false
13639 },
13640 offsetX: -5
13641 },
13642 grid: {
13643 xaxis: {
13644 lines: {
13645 show: true
13646 }
13647 },
13648 yaxis: {
13649 lines: {
13650 show: false
13651 }
13652 }
13653 },
13654 xaxis: {
13655 position: 'top',
13656 labels: {
13657 style: {
13658 fontSize: 14,
13659 fontWeight: 900
13660 }
13661 },
13662 tooltip: {
13663 enabled: false
13664 },
13665 crosshairs: {
13666 show: false
13667 }
13668 },
13669 markers: {
13670 size: 8,
13671 hover: {
13672 sizeOffset: 1
13673 }
13674 },
13675 legend: {
13676 show: false
13677 },
13678 tooltip: {
13679 shared: false,
13680 intersect: true,
13681 followCursor: true
13682 },
13683 stroke: {
13684 width: 5,
13685 curve: 'straight'
13686 }
13687 };
13688 }
13689 }, {
13690 key: "bar",
13691 value: function bar() {
13692 return {
13693 chart: {
13694 stacked: false
13695 },
13696 plotOptions: {
13697 bar: {
13698 dataLabels: {
13699 position: 'center'
13700 }
13701 }
13702 },
13703 dataLabels: {
13704 style: {
13705 colors: ['#fff']
13706 },
13707 background: {
13708 enabled: false
13709 }
13710 },
13711 stroke: {
13712 width: 0,
13713 lineCap: 'square'
13714 },
13715 fill: {
13716 opacity: 0.85
13717 },
13718 legend: {
13719 markers: {
13720 shape: 'square'
13721 }
13722 },
13723 tooltip: {
13724 shared: false,
13725 intersect: true
13726 },
13727 xaxis: {
13728 tooltip: {
13729 enabled: false
13730 },
13731 tickPlacement: 'between',
13732 crosshairs: {
13733 width: 'barWidth',
13734 position: 'back',
13735 fill: {
13736 type: 'gradient'
13737 },
13738 dropShadow: {
13739 enabled: false
13740 },
13741 stroke: {
13742 width: 0
13743 }
13744 }
13745 }
13746 };
13747 }
13748 }, {
13749 key: "funnel",
13750 value: function funnel() {
13751 this.hideYAxis();
13752 return _objectSpread2(_objectSpread2({}, this.bar()), {}, {
13753 chart: {
13754 animations: {
13755 speed: 800,
13756 animateGradually: {
13757 enabled: false
13758 }
13759 }
13760 },
13761 plotOptions: {
13762 bar: {
13763 horizontal: true,
13764 borderRadiusApplication: 'around',
13765 borderRadius: 0,
13766 dataLabels: {
13767 position: 'center'
13768 }
13769 }
13770 },
13771 grid: {
13772 show: false,
13773 padding: {
13774 left: 0,
13775 right: 0
13776 }
13777 },
13778 xaxis: {
13779 labels: {
13780 show: false
13781 },
13782 tooltip: {
13783 enabled: false
13784 },
13785 axisBorder: {
13786 show: false
13787 },
13788 axisTicks: {
13789 show: false
13790 }
13791 }
13792 });
13793 }
13794 }, {
13795 key: "candlestick",
13796 value: function candlestick() {
13797 var _this = this;
13798 return {
13799 stroke: {
13800 width: 1
13801 },
13802 fill: {
13803 opacity: 1
13804 },
13805 dataLabels: {
13806 enabled: false
13807 },
13808 tooltip: {
13809 shared: true,
13810 custom: function custom(_ref2) {
13811 var seriesIndex = _ref2.seriesIndex,
13812 dataPointIndex = _ref2.dataPointIndex,
13813 w = _ref2.w;
13814 return _this._getBoxTooltip(w, seriesIndex, dataPointIndex, ['Open', 'High', '', 'Low', 'Close'], 'candlestick');
13815 }
13816 },
13817 states: {
13818 active: {
13819 filter: {
13820 type: 'none'
13821 }
13822 }
13823 },
13824 xaxis: {
13825 crosshairs: {
13826 width: 1
13827 }
13828 }
13829 };
13830 }
13831 }, {
13832 key: "boxPlot",
13833 value: function boxPlot() {
13834 var _this2 = this;
13835 return {
13836 chart: {
13837 animations: {
13838 dynamicAnimation: {
13839 enabled: false
13840 }
13841 }
13842 },
13843 stroke: {
13844 width: 1,
13845 colors: ['#24292e']
13846 },
13847 dataLabels: {
13848 enabled: false
13849 },
13850 tooltip: {
13851 shared: true,
13852 custom: function custom(_ref3) {
13853 var seriesIndex = _ref3.seriesIndex,
13854 dataPointIndex = _ref3.dataPointIndex,
13855 w = _ref3.w;
13856 return _this2._getBoxTooltip(w, seriesIndex, dataPointIndex, ['Minimum', 'Q1', 'Median', 'Q3', 'Maximum'], 'boxPlot');
13857 }
13858 },
13859 markers: {
13860 size: 7,
13861 strokeWidth: 1,
13862 strokeColors: '#111'
13863 },
13864 xaxis: {
13865 crosshairs: {
13866 width: 1
13867 }
13868 }
13869 };
13870 }
13871 }, {
13872 key: "rangeBar",
13873 value: function rangeBar() {
13874 var handleTimelineTooltip = function handleTimelineTooltip(opts) {
13875 var _getRangeValues = getRangeValues(_objectSpread2(_objectSpread2({}, opts), {}, {
13876 isTimeline: true
13877 })),
13878 color = _getRangeValues.color,
13879 seriesName = _getRangeValues.seriesName,
13880 ylabel = _getRangeValues.ylabel,
13881 startVal = _getRangeValues.startVal,
13882 endVal = _getRangeValues.endVal;
13883 return buildRangeTooltipHTML(_objectSpread2(_objectSpread2({}, opts), {}, {
13884 color: color,
13885 seriesName: seriesName,
13886 ylabel: ylabel,
13887 start: startVal,
13888 end: endVal
13889 }));
13890 };
13891 var handleRangeColumnTooltip = function handleRangeColumnTooltip(opts) {
13892 var _getRangeValues2 = getRangeValues(opts),
13893 color = _getRangeValues2.color,
13894 seriesName = _getRangeValues2.seriesName,
13895 ylabel = _getRangeValues2.ylabel,
13896 start = _getRangeValues2.start,
13897 end = _getRangeValues2.end;
13898 return buildRangeTooltipHTML(_objectSpread2(_objectSpread2({}, opts), {}, {
13899 color: color,
13900 seriesName: seriesName,
13901 ylabel: ylabel,
13902 start: start,
13903 end: end
13904 }));
13905 };
13906 return {
13907 chart: {
13908 animations: {
13909 animateGradually: false
13910 }
13911 },
13912 stroke: {
13913 width: 0,
13914 lineCap: 'square'
13915 },
13916 plotOptions: {
13917 bar: {
13918 borderRadius: 0,
13919 dataLabels: {
13920 position: 'center'
13921 }
13922 }
13923 },
13924 dataLabels: {
13925 enabled: false,
13926 formatter: function formatter(val, _ref4) {
13927 _ref4.ctx;
13928 var seriesIndex = _ref4.seriesIndex,
13929 dataPointIndex = _ref4.dataPointIndex,
13930 w = _ref4.w;
13931 var getVal = function getVal() {
13932 var start = w.globals.seriesRangeStart[seriesIndex][dataPointIndex];
13933 var end = w.globals.seriesRangeEnd[seriesIndex][dataPointIndex];
13934 return end - start;
13935 };
13936 if (w.globals.comboCharts) {
13937 if (w.config.series[seriesIndex].type === 'rangeBar' || w.config.series[seriesIndex].type === 'rangeArea') {
13938 return getVal();
13939 } else {
13940 return val;
13941 }
13942 } else {
13943 return getVal();
13944 }
13945 },
13946 background: {
13947 enabled: false
13948 },
13949 style: {
13950 colors: ['#fff']
13951 }
13952 },
13953 markers: {
13954 size: 10
13955 },
13956 tooltip: {
13957 shared: false,
13958 followCursor: true,
13959 custom: function custom(opts) {
13960 if (opts.w.config.plotOptions && opts.w.config.plotOptions.bar && opts.w.config.plotOptions.bar.horizontal) {
13961 return handleTimelineTooltip(opts);
13962 } else {
13963 return handleRangeColumnTooltip(opts);
13964 }
13965 }
13966 },
13967 xaxis: {
13968 tickPlacement: 'between',
13969 tooltip: {
13970 enabled: false
13971 },
13972 crosshairs: {
13973 stroke: {
13974 width: 0
13975 }
13976 }
13977 }
13978 };
13979 }
13980 }, {
13981 key: "dumbbell",
13982 value: function dumbbell(opts) {
13983 var _opts$plotOptions$bar, _opts$plotOptions$bar2;
13984 if (!((_opts$plotOptions$bar = opts.plotOptions.bar) !== null && _opts$plotOptions$bar !== void 0 && _opts$plotOptions$bar.barHeight)) {
13985 opts.plotOptions.bar.barHeight = 2;
13986 }
13987 if (!((_opts$plotOptions$bar2 = opts.plotOptions.bar) !== null && _opts$plotOptions$bar2 !== void 0 && _opts$plotOptions$bar2.columnWidth)) {
13988 opts.plotOptions.bar.columnWidth = 2;
13989 }
13990 return opts;
13991 }
13992 }, {
13993 key: "area",
13994 value: function area() {
13995 return {
13996 stroke: {
13997 width: 4,
13998 fill: {
13999 type: 'solid',
14000 gradient: {
14001 inverseColors: false,
14002 shade: 'light',
14003 type: 'vertical',
14004 opacityFrom: 0.65,
14005 opacityTo: 0.5,
14006 stops: [0, 100, 100]
14007 }
14008 }
14009 },
14010 fill: {
14011 type: 'gradient',
14012 gradient: {
14013 inverseColors: false,
14014 shade: 'light',
14015 type: 'vertical',
14016 opacityFrom: 0.65,
14017 opacityTo: 0.5,
14018 stops: [0, 100, 100]
14019 }
14020 },
14021 markers: {
14022 size: 0,
14023 hover: {
14024 sizeOffset: 6
14025 }
14026 },
14027 tooltip: {
14028 followCursor: false
14029 }
14030 };
14031 }
14032 }, {
14033 key: "rangeArea",
14034 value: function rangeArea() {
14035 var handleRangeAreaTooltip = function handleRangeAreaTooltip(opts) {
14036 var _getRangeValues3 = getRangeValues(opts),
14037 color = _getRangeValues3.color,
14038 seriesName = _getRangeValues3.seriesName,
14039 ylabel = _getRangeValues3.ylabel,
14040 start = _getRangeValues3.start,
14041 end = _getRangeValues3.end;
14042 return buildRangeTooltipHTML(_objectSpread2(_objectSpread2({}, opts), {}, {
14043 color: color,
14044 seriesName: seriesName,
14045 ylabel: ylabel,
14046 start: start,
14047 end: end
14048 }));
14049 };
14050 return {
14051 stroke: {
14052 curve: 'straight',
14053 width: 0
14054 },
14055 fill: {
14056 type: 'solid',
14057 opacity: 0.6
14058 },
14059 markers: {
14060 size: 0
14061 },
14062 states: {
14063 hover: {
14064 filter: {
14065 type: 'none'
14066 }
14067 },
14068 active: {
14069 filter: {
14070 type: 'none'
14071 }
14072 }
14073 },
14074 tooltip: {
14075 intersect: false,
14076 shared: true,
14077 followCursor: true,
14078 custom: function custom(opts) {
14079 return handleRangeAreaTooltip(opts);
14080 }
14081 }
14082 };
14083 }
14084 }, {
14085 key: "brush",
14086 value: function brush(defaults) {
14087 var ret = {
14088 chart: {
14089 toolbar: {
14090 autoSelected: 'selection',
14091 show: false
14092 },
14093 zoom: {
14094 enabled: false
14095 }
14096 },
14097 dataLabels: {
14098 enabled: false
14099 },
14100 stroke: {
14101 width: 1
14102 },
14103 tooltip: {
14104 enabled: false
14105 },
14106 xaxis: {
14107 tooltip: {
14108 enabled: false
14109 }
14110 }
14111 };
14112 return Utils$1.extend(defaults, ret);
14113 }
14114 }, {
14115 key: "stacked100",
14116 value: function stacked100(opts) {
14117 opts.dataLabels = opts.dataLabels || {};
14118 opts.dataLabels.formatter = opts.dataLabels.formatter || undefined;
14119 var existingDataLabelFormatter = opts.dataLabels.formatter;
14120 opts.yaxis.forEach(function (yaxe, index) {
14121 opts.yaxis[index].min = 0;
14122 opts.yaxis[index].max = 100;
14123 });
14124 var isBar = opts.chart.type === 'bar';
14125 if (isBar) {
14126 opts.dataLabels.formatter = existingDataLabelFormatter || function (val) {
14127 if (typeof val === 'number') {
14128 return val ? val.toFixed(0) + '%' : val;
14129 }
14130 return val;
14131 };
14132 }
14133 return opts;
14134 }
14135 }, {
14136 key: "stackedBars",
14137 value: function stackedBars() {
14138 var barDefaults = this.bar();
14139 return _objectSpread2(_objectSpread2({}, barDefaults), {}, {
14140 plotOptions: _objectSpread2(_objectSpread2({}, barDefaults.plotOptions), {}, {
14141 bar: _objectSpread2(_objectSpread2({}, barDefaults.plotOptions.bar), {}, {
14142 borderRadiusApplication: 'end',
14143 borderRadiusWhenStacked: 'last'
14144 })
14145 })
14146 });
14147 }
14148
14149 // This function removes the left and right spacing in chart for line/area/scatter if xaxis type = category for those charts by converting xaxis = numeric. Numeric/Datetime xaxis prevents the unnecessary spacing in the left/right of the chart area
14150 }, {
14151 key: "convertCatToNumeric",
14152 value: function convertCatToNumeric(opts) {
14153 opts.xaxis.convertedCatToNumeric = true;
14154 return opts;
14155 }
14156 }, {
14157 key: "convertCatToNumericXaxis",
14158 value: function convertCatToNumericXaxis(opts, ctx, cats) {
14159 opts.xaxis.type = 'numeric';
14160 opts.xaxis.labels = opts.xaxis.labels || {};
14161 opts.xaxis.labels.formatter = opts.xaxis.labels.formatter || function (val) {
14162 return Utils$1.isNumber(val) ? Math.floor(val) : val;
14163 };
14164 var defaultFormatter = opts.xaxis.labels.formatter;
14165 var labels = opts.xaxis.categories && opts.xaxis.categories.length ? opts.xaxis.categories : opts.labels;
14166 if (cats && cats.length) {
14167 labels = cats.map(function (c) {
14168 return Array.isArray(c) ? c : String(c);
14169 });
14170 }
14171 if (labels && labels.length) {
14172 opts.xaxis.labels.formatter = function (val) {
14173 return Utils$1.isNumber(val) ? defaultFormatter(labels[Math.floor(val) - 1]) : defaultFormatter(val);
14174 };
14175 }
14176 opts.xaxis.categories = [];
14177 opts.labels = [];
14178 opts.xaxis.tickAmount = opts.xaxis.tickAmount || 'dataPoints';
14179 return opts;
14180 }
14181 }, {
14182 key: "bubble",
14183 value: function bubble() {
14184 return {
14185 dataLabels: {
14186 style: {
14187 colors: ['#fff']
14188 }
14189 },
14190 tooltip: {
14191 shared: false,
14192 intersect: true
14193 },
14194 xaxis: {
14195 crosshairs: {
14196 width: 0
14197 }
14198 },
14199 fill: {
14200 type: 'solid',
14201 gradient: {
14202 shade: 'light',
14203 inverse: true,
14204 shadeIntensity: 0.55,
14205 opacityFrom: 0.4,
14206 opacityTo: 0.8
14207 }
14208 }
14209 };
14210 }
14211 }, {
14212 key: "scatter",
14213 value: function scatter() {
14214 return {
14215 dataLabels: {
14216 enabled: false
14217 },
14218 tooltip: {
14219 shared: false,
14220 intersect: true
14221 },
14222 markers: {
14223 size: 6,
14224 strokeWidth: 1,
14225 hover: {
14226 sizeOffset: 2
14227 }
14228 }
14229 };
14230 }
14231 }, {
14232 key: "heatmap",
14233 value: function heatmap() {
14234 return {
14235 chart: {
14236 stacked: false
14237 },
14238 fill: {
14239 opacity: 1
14240 },
14241 dataLabels: {
14242 style: {
14243 colors: ['#fff']
14244 }
14245 },
14246 stroke: {
14247 colors: ['#fff']
14248 },
14249 tooltip: {
14250 followCursor: true,
14251 marker: {
14252 show: false
14253 },
14254 x: {
14255 show: false
14256 }
14257 },
14258 legend: {
14259 position: 'top',
14260 markers: {
14261 shape: 'square'
14262 }
14263 },
14264 grid: {
14265 padding: {
14266 right: 20
14267 }
14268 }
14269 };
14270 }
14271 }, {
14272 key: "treemap",
14273 value: function treemap() {
14274 return {
14275 chart: {
14276 zoom: {
14277 enabled: false
14278 }
14279 },
14280 dataLabels: {
14281 style: {
14282 fontSize: 14,
14283 fontWeight: 600,
14284 colors: ['#fff']
14285 }
14286 },
14287 stroke: {
14288 show: true,
14289 width: 2,
14290 colors: ['#fff']
14291 },
14292 legend: {
14293 show: false
14294 },
14295 fill: {
14296 opacity: 1,
14297 gradient: {
14298 stops: [0, 100]
14299 }
14300 },
14301 tooltip: {
14302 followCursor: true,
14303 x: {
14304 show: false
14305 }
14306 },
14307 grid: {
14308 padding: {
14309 left: 0,
14310 right: 0
14311 }
14312 },
14313 xaxis: {
14314 crosshairs: {
14315 show: false
14316 },
14317 tooltip: {
14318 enabled: false
14319 }
14320 }
14321 };
14322 }
14323 }, {
14324 key: "pie",
14325 value: function pie() {
14326 return {
14327 chart: {
14328 toolbar: {
14329 show: false
14330 }
14331 },
14332 plotOptions: {
14333 pie: {
14334 donut: {
14335 labels: {
14336 show: false
14337 }
14338 }
14339 }
14340 },
14341 dataLabels: {
14342 formatter: function formatter(val) {
14343 return val.toFixed(1) + '%';
14344 },
14345 style: {
14346 colors: ['#fff']
14347 },
14348 background: {
14349 enabled: false
14350 },
14351 dropShadow: {
14352 enabled: true
14353 }
14354 },
14355 stroke: {
14356 colors: ['#fff']
14357 },
14358 fill: {
14359 opacity: 1,
14360 gradient: {
14361 shade: 'light',
14362 stops: [0, 100]
14363 }
14364 },
14365 tooltip: {
14366 theme: 'dark',
14367 fillSeriesColor: true
14368 },
14369 legend: {
14370 position: 'right'
14371 },
14372 grid: {
14373 padding: {
14374 left: 0,
14375 right: 0,
14376 top: 0,
14377 bottom: 0
14378 }
14379 }
14380 };
14381 }
14382 }, {
14383 key: "donut",
14384 value: function donut() {
14385 return {
14386 chart: {
14387 toolbar: {
14388 show: false
14389 }
14390 },
14391 dataLabels: {
14392 formatter: function formatter(val) {
14393 return val.toFixed(1) + '%';
14394 },
14395 style: {
14396 colors: ['#fff']
14397 },
14398 background: {
14399 enabled: false
14400 },
14401 dropShadow: {
14402 enabled: true
14403 }
14404 },
14405 stroke: {
14406 colors: ['#fff']
14407 },
14408 fill: {
14409 opacity: 1,
14410 gradient: {
14411 shade: 'light',
14412 shadeIntensity: 0.35,
14413 stops: [80, 100],
14414 opacityFrom: 1,
14415 opacityTo: 1
14416 }
14417 },
14418 tooltip: {
14419 theme: 'dark',
14420 fillSeriesColor: true
14421 },
14422 legend: {
14423 position: 'right'
14424 },
14425 grid: {
14426 padding: {
14427 left: 0,
14428 right: 0,
14429 top: 0,
14430 bottom: 0
14431 }
14432 }
14433 };
14434 }
14435 }, {
14436 key: "polarArea",
14437 value: function polarArea() {
14438 return {
14439 chart: {
14440 toolbar: {
14441 show: false
14442 }
14443 },
14444 dataLabels: {
14445 formatter: function formatter(val) {
14446 return val.toFixed(1) + '%';
14447 },
14448 enabled: false
14449 },
14450 stroke: {
14451 show: true,
14452 width: 2
14453 },
14454 fill: {
14455 opacity: 0.7
14456 },
14457 tooltip: {
14458 theme: 'dark',
14459 fillSeriesColor: true
14460 },
14461 legend: {
14462 position: 'right'
14463 },
14464 grid: {
14465 padding: {
14466 left: 0,
14467 right: 0,
14468 top: 0,
14469 bottom: 0
14470 }
14471 }
14472 };
14473 }
14474 }, {
14475 key: "radar",
14476 value: function radar() {
14477 this.opts.yaxis[0].labels.offsetY = this.opts.yaxis[0].labels.offsetY ? this.opts.yaxis[0].labels.offsetY : 6;
14478 return {
14479 dataLabels: {
14480 enabled: false,
14481 style: {
14482 fontSize: '11px'
14483 }
14484 },
14485 stroke: {
14486 width: 2
14487 },
14488 markers: {
14489 size: 5,
14490 strokeWidth: 1,
14491 strokeOpacity: 1
14492 },
14493 fill: {
14494 opacity: 0.2
14495 },
14496 tooltip: {
14497 shared: false,
14498 intersect: true,
14499 followCursor: true
14500 },
14501 grid: {
14502 show: false,
14503 padding: {
14504 left: 0,
14505 right: 0,
14506 top: 0,
14507 bottom: 0
14508 }
14509 },
14510 xaxis: {
14511 labels: {
14512 formatter: function formatter(val) {
14513 return val;
14514 },
14515 style: {
14516 colors: ['#a8a8a8'],
14517 fontSize: '11px'
14518 }
14519 },
14520 tooltip: {
14521 enabled: false
14522 },
14523 crosshairs: {
14524 show: false
14525 }
14526 }
14527 };
14528 }
14529 }, {
14530 key: "radialBar",
14531 value: function radialBar() {
14532 return {
14533 chart: {
14534 animations: {
14535 dynamicAnimation: {
14536 enabled: true,
14537 speed: 800
14538 }
14539 },
14540 toolbar: {
14541 show: false
14542 }
14543 },
14544 fill: {
14545 gradient: {
14546 shade: 'dark',
14547 shadeIntensity: 0.4,
14548 inverseColors: false,
14549 type: 'diagonal2',
14550 opacityFrom: 1,
14551 opacityTo: 1,
14552 stops: [70, 98, 100]
14553 }
14554 },
14555 legend: {
14556 show: false,
14557 position: 'right'
14558 },
14559 tooltip: {
14560 enabled: false,
14561 fillSeriesColor: true
14562 },
14563 grid: {
14564 padding: {
14565 left: 0,
14566 right: 0,
14567 top: 0,
14568 bottom: 0
14569 }
14570 }
14571 };
14572 }
14573 }, {
14574 key: "_getBoxTooltip",
14575 value: function _getBoxTooltip(w, seriesIndex, dataPointIndex, labels, chartType) {
14576 var o = w.globals.seriesCandleO[seriesIndex][dataPointIndex];
14577 var h = w.globals.seriesCandleH[seriesIndex][dataPointIndex];
14578 var m = w.globals.seriesCandleM[seriesIndex][dataPointIndex];
14579 var l = w.globals.seriesCandleL[seriesIndex][dataPointIndex];
14580 var c = w.globals.seriesCandleC[seriesIndex][dataPointIndex];
14581 if (w.config.series[seriesIndex].type && w.config.series[seriesIndex].type !== chartType) {
14582 return "<div class=\"apexcharts-custom-tooltip\">\n ".concat(w.config.series[seriesIndex].name ? w.config.series[seriesIndex].name : 'series-' + (seriesIndex + 1), ": <strong>").concat(w.globals.series[seriesIndex][dataPointIndex], "</strong>\n </div>");
14583 } else {
14584 return "<div class=\"apexcharts-tooltip-box apexcharts-tooltip-".concat(w.config.chart.type, "\">") + "<div>".concat(labels[0], ": <span class=\"value\">") + o + '</span></div>' + "<div>".concat(labels[1], ": <span class=\"value\">") + h + '</span></div>' + (m ? "<div>".concat(labels[2], ": <span class=\"value\">") + m + '</span></div>' : '') + "<div>".concat(labels[3], ": <span class=\"value\">") + l + '</span></div>' + "<div>".concat(labels[4], ": <span class=\"value\">") + c + '</span></div>' + '</div>';
14585 }
14586 }
14587 }]);
14588 return Defaults;
14589 }();
14590
14591 /**
14592 * ApexCharts Config Class for extending user options with pre-defined ApexCharts config.
14593 *
14594 * @module Config
14595 **/
14596 var Config = /*#__PURE__*/function () {
14597 function Config(opts) {
14598 _classCallCheck(this, Config);
14599 this.opts = opts;
14600 }
14601 _createClass(Config, [{
14602 key: "init",
14603 value: function init(_ref) {
14604 var responsiveOverride = _ref.responsiveOverride;
14605 var opts = this.opts;
14606 var options = new Options();
14607 var defaults = new Defaults(opts);
14608 this.chartType = opts.chart.type;
14609 opts = this.extendYAxis(opts);
14610 opts = this.extendAnnotations(opts);
14611 var config = options.init();
14612 var newDefaults = {};
14613 if (opts && _typeof(opts) === 'object') {
14614 var _opts$plotOptions, _opts$plotOptions$bar, _opts$chart$brush, _opts$plotOptions2, _opts$plotOptions2$li, _opts$plotOptions3, _opts$plotOptions3$ba, _opts$chart$sparkline, _window$Apex$chart, _window$Apex$chart$sp;
14615 var chartDefaults = {};
14616 var chartTypes = ['line', 'area', 'bar', 'candlestick', 'boxPlot', 'rangeBar', 'rangeArea', 'bubble', 'scatter', 'heatmap', 'treemap', 'pie', 'polarArea', 'donut', 'radar', 'radialBar'];
14617 if (chartTypes.indexOf(opts.chart.type) !== -1) {
14618 chartDefaults = defaults[opts.chart.type]();
14619 } else {
14620 chartDefaults = defaults.line();
14621 }
14622 if ((_opts$plotOptions = opts.plotOptions) !== null && _opts$plotOptions !== void 0 && (_opts$plotOptions$bar = _opts$plotOptions.bar) !== null && _opts$plotOptions$bar !== void 0 && _opts$plotOptions$bar.isFunnel) {
14623 chartDefaults = defaults.funnel();
14624 }
14625 if (opts.chart.stacked && opts.chart.type === 'bar') {
14626 chartDefaults = defaults.stackedBars();
14627 }
14628 if ((_opts$chart$brush = opts.chart.brush) !== null && _opts$chart$brush !== void 0 && _opts$chart$brush.enabled) {
14629 chartDefaults = defaults.brush(chartDefaults);
14630 }
14631 if ((_opts$plotOptions2 = opts.plotOptions) !== null && _opts$plotOptions2 !== void 0 && (_opts$plotOptions2$li = _opts$plotOptions2.line) !== null && _opts$plotOptions2$li !== void 0 && _opts$plotOptions2$li.isSlopeChart) {
14632 chartDefaults = defaults.slope();
14633 }
14634 if (opts.chart.stacked && opts.chart.stackType === '100%') {
14635 opts = defaults.stacked100(opts);
14636 }
14637 if ((_opts$plotOptions3 = opts.plotOptions) !== null && _opts$plotOptions3 !== void 0 && (_opts$plotOptions3$ba = _opts$plotOptions3.bar) !== null && _opts$plotOptions3$ba !== void 0 && _opts$plotOptions3$ba.isDumbbell) {
14638 opts = defaults.dumbbell(opts);
14639 }
14640
14641 // If user has specified a dark theme, make the tooltip dark too
14642 this.checkForDarkTheme(window.Apex); // check global window Apex options
14643 this.checkForDarkTheme(opts); // check locally passed options
14644
14645 opts.xaxis = opts.xaxis || window.Apex.xaxis || {};
14646
14647 // an important boolean needs to be set here
14648 // otherwise all the charts will have this flag set to true window.Apex.xaxis is set globally
14649 if (!responsiveOverride) {
14650 opts.xaxis.convertedCatToNumeric = false;
14651 }
14652 opts = this.checkForCatToNumericXAxis(this.chartType, chartDefaults, opts);
14653 if ((_opts$chart$sparkline = opts.chart.sparkline) !== null && _opts$chart$sparkline !== void 0 && _opts$chart$sparkline.enabled || (_window$Apex$chart = window.Apex.chart) !== null && _window$Apex$chart !== void 0 && (_window$Apex$chart$sp = _window$Apex$chart.sparkline) !== null && _window$Apex$chart$sp !== void 0 && _window$Apex$chart$sp.enabled) {
14654 chartDefaults = defaults.sparkline(chartDefaults);
14655 }
14656 newDefaults = Utils$1.extend(config, chartDefaults);
14657 }
14658
14659 // config should cascade in this fashion
14660 // default-config < global-apex-variable-config < user-defined-config
14661
14662 // get GLOBALLY defined options and merge with the default config
14663 var mergedWithDefaultConfig = Utils$1.extend(newDefaults, window.Apex);
14664
14665 // get the merged config and extend with user defined config
14666 config = Utils$1.extend(mergedWithDefaultConfig, opts);
14667
14668 // some features are not supported. those mismatches should be handled
14669 config = this.handleUserInputErrors(config);
14670 return config;
14671 }
14672 }, {
14673 key: "checkForCatToNumericXAxis",
14674 value: function checkForCatToNumericXAxis(chartType, chartDefaults, opts) {
14675 var _opts$plotOptions4, _opts$plotOptions4$ba;
14676 var defaults = new Defaults(opts);
14677 var isBarHorizontal = (chartType === 'bar' || chartType === 'boxPlot') && ((_opts$plotOptions4 = opts.plotOptions) === null || _opts$plotOptions4 === void 0 ? void 0 : (_opts$plotOptions4$ba = _opts$plotOptions4.bar) === null || _opts$plotOptions4$ba === void 0 ? void 0 : _opts$plotOptions4$ba.horizontal);
14678 var unsupportedZoom = chartType === 'pie' || chartType === 'polarArea' || chartType === 'donut' || chartType === 'radar' || chartType === 'radialBar' || chartType === 'heatmap';
14679 var notNumericXAxis = opts.xaxis.type !== 'datetime' && opts.xaxis.type !== 'numeric';
14680 var tickPlacement = opts.xaxis.tickPlacement ? opts.xaxis.tickPlacement : chartDefaults.xaxis && chartDefaults.xaxis.tickPlacement;
14681 if (!isBarHorizontal && !unsupportedZoom && notNumericXAxis && tickPlacement !== 'between') {
14682 opts = defaults.convertCatToNumeric(opts);
14683 }
14684 return opts;
14685 }
14686 }, {
14687 key: "extendYAxis",
14688 value: function extendYAxis(opts, w) {
14689 var options = new Options();
14690 if (typeof opts.yaxis === 'undefined' || !opts.yaxis || Array.isArray(opts.yaxis) && opts.yaxis.length === 0) {
14691 opts.yaxis = {};
14692 }
14693
14694 // extend global yaxis config (only if object is provided / not an array)
14695 if (opts.yaxis.constructor !== Array && window.Apex.yaxis && window.Apex.yaxis.constructor !== Array) {
14696 opts.yaxis = Utils$1.extend(opts.yaxis, window.Apex.yaxis);
14697 }
14698
14699 // as we can't extend nested object's array with extend, we need to do it first
14700 // user can provide either an array or object in yaxis config
14701 if (opts.yaxis.constructor !== Array) {
14702 // convert the yaxis to array if user supplied object
14703 opts.yaxis = [Utils$1.extend(options.yAxis, opts.yaxis)];
14704 } else {
14705 opts.yaxis = Utils$1.extendArray(opts.yaxis, options.yAxis);
14706 }
14707 var isLogY = false;
14708 opts.yaxis.forEach(function (y) {
14709 if (y.logarithmic) {
14710 isLogY = true;
14711 }
14712 });
14713 var series = opts.series;
14714 if (w && !series) {
14715 series = w.config.series;
14716 }
14717
14718 // A logarithmic chart works correctly when each series has a corresponding y-axis
14719 // If this is not the case, we manually create yaxis for multi-series log chart
14720 if (isLogY && series.length !== opts.yaxis.length && series.length) {
14721 opts.yaxis = series.map(function (s, i) {
14722 if (!s.name) {
14723 series[i].name = "series-".concat(i + 1);
14724 }
14725 if (opts.yaxis[i]) {
14726 opts.yaxis[i].seriesName = series[i].name;
14727 return opts.yaxis[i];
14728 } else {
14729 var newYaxis = Utils$1.extend(options.yAxis, opts.yaxis[0]);
14730 newYaxis.show = false;
14731 return newYaxis;
14732 }
14733 });
14734 }
14735 if (isLogY && series.length > 1 && series.length !== opts.yaxis.length) {
14736 console.warn('A multi-series logarithmic chart should have equal number of series and y-axes');
14737 }
14738 return opts;
14739 }
14740
14741 // annotations also accepts array, so we need to extend them manually
14742 }, {
14743 key: "extendAnnotations",
14744 value: function extendAnnotations(opts) {
14745 if (typeof opts.annotations === 'undefined') {
14746 opts.annotations = {};
14747 opts.annotations.yaxis = [];
14748 opts.annotations.xaxis = [];
14749 opts.annotations.points = [];
14750 }
14751 opts = this.extendYAxisAnnotations(opts);
14752 opts = this.extendXAxisAnnotations(opts);
14753 opts = this.extendPointAnnotations(opts);
14754 return opts;
14755 }
14756 }, {
14757 key: "extendYAxisAnnotations",
14758 value: function extendYAxisAnnotations(opts) {
14759 var options = new Options();
14760 opts.annotations.yaxis = Utils$1.extendArray(typeof opts.annotations.yaxis !== 'undefined' ? opts.annotations.yaxis : [], options.yAxisAnnotation);
14761 return opts;
14762 }
14763 }, {
14764 key: "extendXAxisAnnotations",
14765 value: function extendXAxisAnnotations(opts) {
14766 var options = new Options();
14767 opts.annotations.xaxis = Utils$1.extendArray(typeof opts.annotations.xaxis !== 'undefined' ? opts.annotations.xaxis : [], options.xAxisAnnotation);
14768 return opts;
14769 }
14770 }, {
14771 key: "extendPointAnnotations",
14772 value: function extendPointAnnotations(opts) {
14773 var options = new Options();
14774 opts.annotations.points = Utils$1.extendArray(typeof opts.annotations.points !== 'undefined' ? opts.annotations.points : [], options.pointAnnotation);
14775 return opts;
14776 }
14777 }, {
14778 key: "checkForDarkTheme",
14779 value: function checkForDarkTheme(opts) {
14780 if (opts.theme && opts.theme.mode === 'dark') {
14781 if (!opts.tooltip) {
14782 opts.tooltip = {};
14783 }
14784 if (opts.tooltip.theme !== 'light') {
14785 opts.tooltip.theme = 'dark';
14786 }
14787 if (!opts.chart.foreColor) {
14788 opts.chart.foreColor = '#f6f7f8';
14789 }
14790 if (!opts.theme.palette) {
14791 opts.theme.palette = 'palette4';
14792 }
14793 }
14794 }
14795 }, {
14796 key: "handleUserInputErrors",
14797 value: function handleUserInputErrors(opts) {
14798 var config = opts;
14799 // conflicting tooltip option. intersect makes sure to focus on 1 point at a time. Shared cannot be used along with it
14800 if (config.tooltip.shared && config.tooltip.intersect) {
14801 throw new Error('tooltip.shared cannot be enabled when tooltip.intersect is true. Turn off any other option by setting it to false.');
14802 }
14803 if (config.chart.type === 'bar' && config.plotOptions.bar.horizontal) {
14804 // No multiple yaxis for bars
14805 if (config.yaxis.length > 1) {
14806 throw new Error('Multiple Y Axis for bars are not supported. Switch to column chart by setting plotOptions.bar.horizontal=false');
14807 }
14808
14809 // if yaxis is reversed in horizontal bar chart, you should draw the y-axis on right side
14810 if (config.yaxis[0].reversed) {
14811 config.yaxis[0].opposite = true;
14812 }
14813 config.xaxis.tooltip.enabled = false; // no xaxis tooltip for horizontal bar
14814 config.yaxis[0].tooltip.enabled = false; // no xaxis tooltip for horizontal bar
14815 config.chart.zoom.enabled = false; // no zooming for horz bars
14816 }
14817 if (config.chart.type === 'bar' || config.chart.type === 'rangeBar') {
14818 if (config.tooltip.shared) {
14819 if (config.xaxis.crosshairs.width === 'barWidth' && config.series.length > 1) {
14820 config.xaxis.crosshairs.width = 'tickWidth';
14821 }
14822 }
14823 }
14824 if (config.chart.type === 'candlestick' || config.chart.type === 'boxPlot') {
14825 if (config.yaxis[0].reversed) {
14826 console.warn("Reversed y-axis in ".concat(config.chart.type, " chart is not supported."));
14827 config.yaxis[0].reversed = false;
14828 }
14829 }
14830 return config;
14831 }
14832 }]);
14833 return Config;
14834 }();
14835
14836 var Globals = /*#__PURE__*/function () {
14837 function Globals() {
14838 _classCallCheck(this, Globals);
14839 }
14840 _createClass(Globals, [{
14841 key: "initGlobalVars",
14842 value: function initGlobalVars(gl) {
14843 gl.series = []; // the MAIN series array (y values)
14844 gl.seriesCandleO = [];
14845 gl.seriesCandleH = [];
14846 gl.seriesCandleM = [];
14847 gl.seriesCandleL = [];
14848 gl.seriesCandleC = [];
14849 gl.seriesRangeStart = [];
14850 gl.seriesRangeEnd = [];
14851 gl.seriesRange = [];
14852 gl.seriesPercent = [];
14853 gl.seriesGoals = [];
14854 gl.seriesX = [];
14855 gl.seriesZ = [];
14856 gl.seriesNames = [];
14857 gl.seriesTotals = [];
14858 gl.seriesLog = [];
14859 gl.seriesColors = [];
14860 gl.stackedSeriesTotals = [];
14861 gl.seriesXvalues = []; // we will need this in tooltip (it's x position)
14862 // when we will have unequal x values, we will need
14863 // some way to get x value depending on mouse pointer
14864 gl.seriesYvalues = []; // we will need this when deciding which series
14865 // user hovered on
14866 gl.labels = [];
14867 gl.hasXaxisGroups = false;
14868 gl.groups = [];
14869 gl.barGroups = [];
14870 gl.lineGroups = [];
14871 gl.areaGroups = [];
14872 gl.hasSeriesGroups = false;
14873 gl.seriesGroups = [];
14874 gl.categoryLabels = [];
14875 gl.timescaleLabels = [];
14876 gl.noLabelsProvided = false;
14877 gl.resizeTimer = null;
14878 gl.selectionResizeTimer = null;
14879 gl.lastWheelExecution = 0;
14880 gl.delayedElements = [];
14881 gl.pointsArray = [];
14882 gl.dataLabelsRects = [];
14883 gl.isXNumeric = false;
14884 gl.skipLastTimelinelabel = false;
14885 gl.skipFirstTimelinelabel = false;
14886 gl.isDataXYZ = false;
14887 gl.isMultiLineX = false;
14888 gl.isMultipleYAxis = false;
14889 gl.maxY = -Number.MAX_VALUE;
14890 gl.minY = Number.MIN_VALUE;
14891 gl.minYArr = [];
14892 gl.maxYArr = [];
14893 gl.maxX = -Number.MAX_VALUE;
14894 gl.minX = Number.MAX_VALUE;
14895 gl.initialMaxX = -Number.MAX_VALUE;
14896 gl.initialMinX = Number.MAX_VALUE;
14897 gl.maxDate = 0;
14898 gl.minDate = Number.MAX_VALUE;
14899 gl.minZ = Number.MAX_VALUE;
14900 gl.maxZ = -Number.MAX_VALUE;
14901 gl.minXDiff = Number.MAX_VALUE;
14902 gl.yAxisScale = [];
14903 gl.xAxisScale = null;
14904 gl.xAxisTicksPositions = [];
14905 gl.yLabelsCoords = [];
14906 gl.yTitleCoords = [];
14907 gl.barPadForNumericAxis = 0;
14908 gl.padHorizontal = 0;
14909 gl.xRange = 0;
14910 gl.yRange = [];
14911 gl.zRange = 0;
14912 gl.dataPoints = 0;
14913 gl.xTickAmount = 0;
14914 gl.multiAxisTickAmount = 0;
14915 }
14916 }, {
14917 key: "globalVars",
14918 value: function globalVars(config) {
14919 return {
14920 chartID: null,
14921 // chart ID - apexcharts-cuid
14922 cuid: null,
14923 // chart ID - random numbers excluding "apexcharts" part
14924 events: {
14925 beforeMount: [],
14926 mounted: [],
14927 updated: [],
14928 clicked: [],
14929 selection: [],
14930 dataPointSelection: [],
14931 zoomed: [],
14932 scrolled: []
14933 },
14934 colors: [],
14935 clientX: null,
14936 clientY: null,
14937 fill: {
14938 colors: []
14939 },
14940 stroke: {
14941 colors: []
14942 },
14943 dataLabels: {
14944 style: {
14945 colors: []
14946 }
14947 },
14948 radarPolygons: {
14949 fill: {
14950 colors: []
14951 }
14952 },
14953 markers: {
14954 colors: [],
14955 size: config.markers.size,
14956 largestSize: 0
14957 },
14958 animationEnded: false,
14959 isTouchDevice: 'ontouchstart' in window || navigator.msMaxTouchPoints,
14960 isDirty: false,
14961 // chart has been updated after the initial render. This is different than dataChanged property. isDirty means user manually called some method to update
14962 isExecCalled: false,
14963 // whether user updated the chart through the exec method
14964 initialConfig: null,
14965 // we will store the first config user has set to go back when user finishes interactions like zooming and come out of it
14966 initialSeries: [],
14967 lastXAxis: [],
14968 lastYAxis: [],
14969 columnSeries: null,
14970 labels: [],
14971 // store the text to draw on x axis
14972 // Don't mutate the labels, many things including tooltips depends on it!
14973 timescaleLabels: [],
14974 // store the timescaleLabels Labels in another variable
14975 noLabelsProvided: false,
14976 // if user didn't provide any categories/labels or x values, fallback to 1,2,3,4...
14977 allSeriesCollapsed: false,
14978 collapsedSeries: [],
14979 // when user collapses a series, it goes into this array
14980 collapsedSeriesIndices: [],
14981 // this stores the index of the collapsedSeries instead of whole object for quick access
14982 ancillaryCollapsedSeries: [],
14983 // when user collapses an "alwaysVisible" series, it goes into this array
14984 ancillaryCollapsedSeriesIndices: [],
14985 // this stores the index of the ancillaryCollapsedSeries whose y-axis is always visible
14986 risingSeries: [],
14987 // when user re-opens a collapsed series, it goes here
14988 dataFormatXNumeric: false,
14989 // boolean value to indicate user has passed numeric x values
14990 capturedSeriesIndex: -1,
14991 capturedDataPointIndex: -1,
14992 selectedDataPoints: [],
14993 invalidLogScale: false,
14994 // if a user enabled log scale but the data provided is not valid to generate a log scale, turn on this flag
14995 ignoreYAxisIndexes: [],
14996 // when series are being collapsed in multiple y axes, ignore certain index
14997 maxValsInArrayIndex: 0,
14998 radialSize: 0,
14999 selection: undefined,
15000 zoomEnabled: config.chart.toolbar.autoSelected === 'zoom' && config.chart.toolbar.tools.zoom && config.chart.zoom.enabled,
15001 panEnabled: config.chart.toolbar.autoSelected === 'pan' && config.chart.toolbar.tools.pan,
15002 selectionEnabled: config.chart.toolbar.autoSelected === 'selection' && config.chart.toolbar.tools.selection,
15003 yaxis: null,
15004 mousedown: false,
15005 lastClientPosition: {},
15006 // don't reset this variable this the chart is destroyed. It is used to detect right or left mousemove in panning
15007 visibleXRange: undefined,
15008 yValueDecimal: 0,
15009 // are there floating numbers in the series. If yes, this represent the len of the decimals
15010 total: 0,
15011 SVGNS: 'http://www.w3.org/2000/svg',
15012 // svg namespace
15013 svgWidth: 0,
15014 // the whole svg width
15015 svgHeight: 0,
15016 // the whole svg height
15017 noData: false,
15018 // whether there is any data to display or not
15019 locale: {},
15020 // the current locale values will be preserved here for global access
15021 dom: {},
15022 // for storing all dom nodes in this particular property
15023 memory: {
15024 methodsToExec: []
15025 },
15026 shouldAnimate: true,
15027 skipLastTimelinelabel: false,
15028 // when last label is cropped, skip drawing it
15029 skipFirstTimelinelabel: false,
15030 // when first label is cropped, skip drawing it
15031 delayedElements: [],
15032 // element which appear after animation has finished
15033 axisCharts: true,
15034 // chart type = line or area or bar
15035 // (refer them also as plot charts in the code)
15036 isDataXYZ: false,
15037 // bool: data was provided in a {[x,y,z]} pattern
15038 isSlopeChart: config.plotOptions.line.isSlopeChart,
15039 resized: false,
15040 // bool: user has resized
15041 resizeTimer: null,
15042 // timeout function to make a small delay before
15043 // drawing when user resized
15044 comboCharts: false,
15045 // bool: whether it's a combination of line/column
15046 dataChanged: false,
15047 // bool: has data changed dynamically
15048 previousPaths: [],
15049 // array: when data is changed, it will animate from
15050 // previous paths
15051 allSeriesHasEqualX: true,
15052 pointsArray: [],
15053 // store the points positions here to draw later on hover
15054 // format is - [[x,y],[x,y]... [x,y]]
15055 dataLabelsRects: [],
15056 // store the positions of datalabels to prevent collision
15057 lastDrawnDataLabelsIndexes: [],
15058 hasNullValues: false,
15059 // bool: whether series contains null values
15060 zoomed: false,
15061 // whether user has zoomed or not
15062 gridWidth: 0,
15063 // drawable width of actual graphs (series paths)
15064 gridHeight: 0,
15065 // drawable height of actual graphs (series paths)
15066 rotateXLabels: false,
15067 defaultLabels: false,
15068 xLabelFormatter: undefined,
15069 // formatter for x axis labels
15070 yLabelFormatters: [],
15071 xaxisTooltipFormatter: undefined,
15072 // formatter for x axis tooltip
15073 ttKeyFormatter: undefined,
15074 ttVal: undefined,
15075 ttZFormatter: undefined,
15076 LINE_HEIGHT_RATIO: 1.618,
15077 xAxisLabelsHeight: 0,
15078 xAxisGroupLabelsHeight: 0,
15079 xAxisLabelsWidth: 0,
15080 yAxisLabelsWidth: 0,
15081 scaleX: 1,
15082 scaleY: 1,
15083 translateX: 0,
15084 translateY: 0,
15085 translateYAxisX: [],
15086 yAxisWidths: [],
15087 translateXAxisY: 0,
15088 translateXAxisX: 0,
15089 tooltip: null,
15090 // Rules for niceScaleAllowedMagMsd:
15091 // 1) An array of two arrays only ([[],[]]):
15092 // * array[0][]: influences labelling of data series that contain only integers
15093 // - must contain only integers (or expect ugly ticks)
15094 // * array[1][]: influences labelling of data series that contain at least one float
15095 // - may contain floats
15096 // * both arrays:
15097 // - each array[][i] ideally satisfy: 10 mod array[][i] == 0 (or expect ugly ticks)
15098 // - to avoid clipping data point keep each array[][i] >= i
15099 // 2) each array[i][] contains 11 values, for all possible index values 0..10.
15100 // array[][0] should not be needed (not proven) but ensures non-zero is returned.
15101 //
15102 // Users can effectively force their preferred "magMsd" through stepSize and
15103 // forceNiceScale. With forceNiceScale: true, stepSize becomes normalizable to the
15104 // axis's min..max range, which allows users to set stepSize to an integer 1..10, for
15105 // example, stepSize: 3. This value will be preferred to the value determined through
15106 // this array. The range-normalized value is checked for consistency with other
15107 // user defined options and will be ignored if inconsistent.
15108 niceScaleAllowedMagMsd: [[1, 1, 2, 5, 5, 5, 10, 10, 10, 10, 10], [1, 1, 2, 5, 5, 5, 10, 10, 10, 10, 10]],
15109 // Default ticks based on SVG size. These values have high numbers
15110 // of divisors. The array is indexed using a calculated maxTicks value
15111 // divided by 2 simply to halve the array size. See Scales.niceScale().
15112 niceScaleDefaultTicks: [1, 2, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24],
15113 seriesYAxisMap: [],
15114 // Given yAxis index, return all series indices belonging to it. Multiple series can be referenced to each yAxis.
15115 seriesYAxisReverseMap: [] // Given a Series index, return its yAxis index.
15116 };
15117 }
15118 }, {
15119 key: "init",
15120 value: function init(config) {
15121 var globals = this.globalVars(config);
15122 this.initGlobalVars(globals);
15123 globals.initialConfig = Utils$1.extend({}, config);
15124 globals.initialSeries = Utils$1.clone(config.series);
15125 globals.lastXAxis = Utils$1.clone(globals.initialConfig.xaxis);
15126 globals.lastYAxis = Utils$1.clone(globals.initialConfig.yaxis);
15127 return globals;
15128 }
15129 }]);
15130 return Globals;
15131 }();
15132
15133 /**
15134 * ApexCharts Base Class for extending user options with pre-defined ApexCharts config.
15135 *
15136 * @module Base
15137 **/
15138 var Base = /*#__PURE__*/function () {
15139 function Base(opts) {
15140 _classCallCheck(this, Base);
15141 this.opts = opts;
15142 }
15143 _createClass(Base, [{
15144 key: "init",
15145 value: function init() {
15146 var config = new Config(this.opts).init({
15147 responsiveOverride: false
15148 });
15149 var globals = new Globals().init(config);
15150 var w = {
15151 config: config,
15152 globals: globals
15153 };
15154 return w;
15155 }
15156 }]);
15157 return Base;
15158 }();
15159
15160 /**
15161 * ApexCharts Fill Class for setting fill options of the paths.
15162 *
15163 * @module Fill
15164 **/
15165 var Fill = /*#__PURE__*/function () {
15166 function Fill(ctx) {
15167 _classCallCheck(this, Fill);
15168 this.ctx = ctx;
15169 this.w = ctx.w;
15170 this.opts = null;
15171 this.seriesIndex = 0;
15172 this.patternIDs = [];
15173 }
15174 _createClass(Fill, [{
15175 key: "clippedImgArea",
15176 value: function clippedImgArea(params) {
15177 var w = this.w;
15178 var cnf = w.config;
15179 var svgW = parseInt(w.globals.gridWidth, 10);
15180 var svgH = parseInt(w.globals.gridHeight, 10);
15181 var size = svgW > svgH ? svgW : svgH;
15182 var fillImg = params.image;
15183 var imgWidth = 0;
15184 var imgHeight = 0;
15185 if (typeof params.width === 'undefined' && typeof params.height === 'undefined') {
15186 if (cnf.fill.image.width !== undefined && cnf.fill.image.height !== undefined) {
15187 imgWidth = cnf.fill.image.width + 1;
15188 imgHeight = cnf.fill.image.height;
15189 } else {
15190 imgWidth = size + 1;
15191 imgHeight = size;
15192 }
15193 } else {
15194 imgWidth = params.width;
15195 imgHeight = params.height;
15196 }
15197 var elPattern = document.createElementNS(w.globals.SVGNS, 'pattern');
15198 Graphics.setAttrs(elPattern, {
15199 id: params.patternID,
15200 patternUnits: params.patternUnits ? params.patternUnits : 'userSpaceOnUse',
15201 width: imgWidth + 'px',
15202 height: imgHeight + 'px'
15203 });
15204 var elImage = document.createElementNS(w.globals.SVGNS, 'image');
15205 elPattern.appendChild(elImage);
15206 elImage.setAttributeNS(window.SVG.xlink, 'href', fillImg);
15207 Graphics.setAttrs(elImage, {
15208 x: 0,
15209 y: 0,
15210 preserveAspectRatio: 'none',
15211 width: imgWidth + 'px',
15212 height: imgHeight + 'px'
15213 });
15214 elImage.style.opacity = params.opacity;
15215 w.globals.dom.elDefs.node.appendChild(elPattern);
15216 }
15217 }, {
15218 key: "getSeriesIndex",
15219 value: function getSeriesIndex(opts) {
15220 var w = this.w;
15221 var cType = w.config.chart.type;
15222 if ((cType === 'bar' || cType === 'rangeBar') && w.config.plotOptions.bar.distributed || cType === 'heatmap' || cType === 'treemap') {
15223 this.seriesIndex = opts.seriesNumber;
15224 } else {
15225 this.seriesIndex = opts.seriesNumber % w.globals.series.length;
15226 }
15227 return this.seriesIndex;
15228 }
15229 }, {
15230 key: "computeColorStops",
15231 value: function computeColorStops(data, multiColorConfig) {
15232 var w = this.w;
15233 var maxPositive = null;
15234 var minNegative = null;
15235 var _iterator = _createForOfIteratorHelper(data),
15236 _step;
15237 try {
15238 for (_iterator.s(); !(_step = _iterator.n()).done;) {
15239 var value = _step.value;
15240 if (value >= multiColorConfig.threshold) {
15241 if (maxPositive === null || value > maxPositive) {
15242 maxPositive = value;
15243 }
15244 } else {
15245 if (minNegative === null || value < minNegative) {
15246 minNegative = value;
15247 }
15248 }
15249 }
15250 } catch (err) {
15251 _iterator.e(err);
15252 } finally {
15253 _iterator.f();
15254 }
15255 if (maxPositive === null) {
15256 maxPositive = multiColorConfig.threshold;
15257 }
15258 if (minNegative === null) {
15259 minNegative = multiColorConfig.threshold;
15260 }
15261 var totalRange = maxPositive - multiColorConfig.threshold + (multiColorConfig.threshold - minNegative);
15262 if (totalRange === 0) {
15263 totalRange = 1;
15264 }
15265 var negativePercentage = (multiColorConfig.threshold - minNegative) / totalRange * 100;
15266 var offset = 100 - negativePercentage;
15267 offset = Math.max(0, Math.min(offset, 100));
15268 return [{
15269 offset: offset,
15270 color: multiColorConfig.colorAboveThreshold,
15271 opacity: w.config.fill.opacity
15272 }, {
15273 offset: 0,
15274 color: multiColorConfig.colorBelowThreshold,
15275 opacity: w.config.fill.opacity
15276 }];
15277 }
15278 }, {
15279 key: "fillPath",
15280 value: function fillPath(opts) {
15281 var _w$config$series$this, _w$config$series$this2, _w$config$series$this3;
15282 var w = this.w;
15283 this.opts = opts;
15284 var cnf = this.w.config;
15285 var pathFill;
15286 var patternFill, gradientFill;
15287 this.seriesIndex = this.getSeriesIndex(opts);
15288 var drawMultiColorLine = cnf.plotOptions.line.colors.colorAboveThreshold && cnf.plotOptions.line.colors.colorBelowThreshold;
15289 var fillColors = this.getFillColors();
15290 var fillColor = fillColors[this.seriesIndex];
15291
15292 //override fillcolor if user inputted color with data
15293 if (w.globals.seriesColors[this.seriesIndex] !== undefined) {
15294 fillColor = w.globals.seriesColors[this.seriesIndex];
15295 }
15296 if (typeof fillColor === 'function') {
15297 fillColor = fillColor({
15298 seriesIndex: this.seriesIndex,
15299 dataPointIndex: opts.dataPointIndex,
15300 value: opts.value,
15301 w: w
15302 });
15303 }
15304 var fillType = opts.fillType ? opts.fillType : this.getFillType(this.seriesIndex);
15305 var fillOpacity = Array.isArray(cnf.fill.opacity) ? cnf.fill.opacity[this.seriesIndex] : cnf.fill.opacity;
15306
15307 // when line colors needs to be different based on values, we use gradient config to achieve this
15308 var useGradient = fillType === 'gradient' || drawMultiColorLine;
15309 if (opts.color) {
15310 fillColor = opts.color;
15311 }
15312 if ((_w$config$series$this = w.config.series[this.seriesIndex]) !== null && _w$config$series$this !== void 0 && (_w$config$series$this2 = _w$config$series$this.data) !== null && _w$config$series$this2 !== void 0 && (_w$config$series$this3 = _w$config$series$this2[opts.dataPointIndex]) !== null && _w$config$series$this3 !== void 0 && _w$config$series$this3.fillColor) {
15313 var _w$config$series$this4, _w$config$series$this5, _w$config$series$this6;
15314 fillColor = (_w$config$series$this4 = w.config.series[this.seriesIndex]) === null || _w$config$series$this4 === void 0 ? void 0 : (_w$config$series$this5 = _w$config$series$this4.data) === null || _w$config$series$this5 === void 0 ? void 0 : (_w$config$series$this6 = _w$config$series$this5[opts.dataPointIndex]) === null || _w$config$series$this6 === void 0 ? void 0 : _w$config$series$this6.fillColor;
15315 }
15316
15317 // in case a color is undefined, fallback to white color to prevent runtime error
15318 if (!fillColor) {
15319 fillColor = '#fff';
15320 console.warn('undefined color - ApexCharts');
15321 }
15322 var defaultColor = fillColor;
15323 if (fillColor.indexOf('rgb') === -1) {
15324 if (fillColor.indexOf('#') === -1) {
15325 defaultColor = fillColor;
15326 } else if (fillColor.length < 9) {
15327 // if the hex contains alpha and is of 9 digit, skip the opacity
15328 defaultColor = Utils$1.hexToRgba(fillColor, fillOpacity);
15329 }
15330 } else {
15331 if (fillColor.indexOf('rgba') > -1) {
15332 fillOpacity = Utils$1.getOpacityFromRGBA(fillColor);
15333 } else {
15334 defaultColor = Utils$1.hexToRgba(Utils$1.rgb2hex(fillColor), fillOpacity);
15335 }
15336 }
15337 if (opts.opacity) fillOpacity = opts.opacity;
15338 if (fillType === 'pattern') {
15339 patternFill = this.handlePatternFill({
15340 fillConfig: opts.fillConfig,
15341 patternFill: patternFill,
15342 fillColor: fillColor,
15343 fillOpacity: fillOpacity,
15344 defaultColor: defaultColor
15345 });
15346 }
15347 if (useGradient) {
15348 var colorStops = _toConsumableArray(cnf.fill.gradient.colorStops) || [];
15349 var type = cnf.fill.gradient.type;
15350 if (drawMultiColorLine) {
15351 colorStops[this.seriesIndex] = this.computeColorStops(w.globals.series[this.seriesIndex], cnf.plotOptions.line.colors);
15352 type = 'vertical';
15353 }
15354 gradientFill = this.handleGradientFill({
15355 type: type,
15356 fillConfig: opts.fillConfig,
15357 fillColor: fillColor,
15358 fillOpacity: fillOpacity,
15359 colorStops: colorStops,
15360 i: this.seriesIndex
15361 });
15362 }
15363 if (fillType === 'image') {
15364 var imgSrc = cnf.fill.image.src;
15365 var patternID = opts.patternID ? opts.patternID : '';
15366 var patternKey = "pattern".concat(w.globals.cuid).concat(opts.seriesNumber + 1).concat(patternID);
15367 if (this.patternIDs.indexOf(patternKey) === -1) {
15368 this.clippedImgArea({
15369 opacity: fillOpacity,
15370 image: Array.isArray(imgSrc) ? opts.seriesNumber < imgSrc.length ? imgSrc[opts.seriesNumber] : imgSrc[0] : imgSrc,
15371 width: opts.width ? opts.width : undefined,
15372 height: opts.height ? opts.height : undefined,
15373 patternUnits: opts.patternUnits,
15374 patternID: patternKey
15375 });
15376 this.patternIDs.push(patternKey);
15377 }
15378 pathFill = "url(#".concat(patternKey, ")");
15379 } else if (useGradient) {
15380 pathFill = gradientFill;
15381 } else if (fillType === 'pattern') {
15382 pathFill = patternFill;
15383 } else {
15384 pathFill = defaultColor;
15385 }
15386
15387 // override pattern/gradient if opts.solid is true
15388 if (opts.solid) {
15389 pathFill = defaultColor;
15390 }
15391 return pathFill;
15392 }
15393 }, {
15394 key: "getFillType",
15395 value: function getFillType(seriesIndex) {
15396 var w = this.w;
15397 if (Array.isArray(w.config.fill.type)) {
15398 return w.config.fill.type[seriesIndex];
15399 } else {
15400 return w.config.fill.type;
15401 }
15402 }
15403 }, {
15404 key: "getFillColors",
15405 value: function getFillColors() {
15406 var w = this.w;
15407 var cnf = w.config;
15408 var opts = this.opts;
15409 var fillColors = [];
15410 if (w.globals.comboCharts) {
15411 if (w.config.series[this.seriesIndex].type === 'line') {
15412 if (Array.isArray(w.globals.stroke.colors)) {
15413 fillColors = w.globals.stroke.colors;
15414 } else {
15415 fillColors.push(w.globals.stroke.colors);
15416 }
15417 } else {
15418 if (Array.isArray(w.globals.fill.colors)) {
15419 fillColors = w.globals.fill.colors;
15420 } else {
15421 fillColors.push(w.globals.fill.colors);
15422 }
15423 }
15424 } else {
15425 if (cnf.chart.type === 'line') {
15426 if (Array.isArray(w.globals.stroke.colors)) {
15427 fillColors = w.globals.stroke.colors;
15428 } else {
15429 fillColors.push(w.globals.stroke.colors);
15430 }
15431 } else {
15432 if (Array.isArray(w.globals.fill.colors)) {
15433 fillColors = w.globals.fill.colors;
15434 } else {
15435 fillColors.push(w.globals.fill.colors);
15436 }
15437 }
15438 }
15439
15440 // colors passed in arguments
15441 if (typeof opts.fillColors !== 'undefined') {
15442 fillColors = [];
15443 if (Array.isArray(opts.fillColors)) {
15444 fillColors = opts.fillColors.slice();
15445 } else {
15446 fillColors.push(opts.fillColors);
15447 }
15448 }
15449 return fillColors;
15450 }
15451 }, {
15452 key: "handlePatternFill",
15453 value: function handlePatternFill(_ref) {
15454 var fillConfig = _ref.fillConfig,
15455 patternFill = _ref.patternFill,
15456 fillColor = _ref.fillColor,
15457 fillOpacity = _ref.fillOpacity,
15458 defaultColor = _ref.defaultColor;
15459 var fillCnf = this.w.config.fill;
15460 if (fillConfig) {
15461 fillCnf = fillConfig;
15462 }
15463 var opts = this.opts;
15464 var graphics = new Graphics(this.ctx);
15465 var patternStrokeWidth = Array.isArray(fillCnf.pattern.strokeWidth) ? fillCnf.pattern.strokeWidth[this.seriesIndex] : fillCnf.pattern.strokeWidth;
15466 var patternLineColor = fillColor;
15467 if (Array.isArray(fillCnf.pattern.style)) {
15468 if (typeof fillCnf.pattern.style[opts.seriesNumber] !== 'undefined') {
15469 var pf = graphics.drawPattern(fillCnf.pattern.style[opts.seriesNumber], fillCnf.pattern.width, fillCnf.pattern.height, patternLineColor, patternStrokeWidth, fillOpacity);
15470 patternFill = pf;
15471 } else {
15472 patternFill = defaultColor;
15473 }
15474 } else {
15475 patternFill = graphics.drawPattern(fillCnf.pattern.style, fillCnf.pattern.width, fillCnf.pattern.height, patternLineColor, patternStrokeWidth, fillOpacity);
15476 }
15477 return patternFill;
15478 }
15479 }, {
15480 key: "handleGradientFill",
15481 value: function handleGradientFill(_ref2) {
15482 var type = _ref2.type,
15483 fillColor = _ref2.fillColor,
15484 fillOpacity = _ref2.fillOpacity,
15485 fillConfig = _ref2.fillConfig,
15486 colorStops = _ref2.colorStops,
15487 i = _ref2.i;
15488 var fillCnf = this.w.config.fill;
15489 if (fillConfig) {
15490 fillCnf = _objectSpread2(_objectSpread2({}, fillCnf), fillConfig);
15491 }
15492 var opts = this.opts;
15493 var graphics = new Graphics(this.ctx);
15494 var utils = new Utils$1();
15495 type = type || fillCnf.gradient.type;
15496 var gradientFrom = fillColor;
15497 var gradientTo;
15498 var opacityFrom = fillCnf.gradient.opacityFrom === undefined ? fillOpacity : Array.isArray(fillCnf.gradient.opacityFrom) ? fillCnf.gradient.opacityFrom[i] : fillCnf.gradient.opacityFrom;
15499 if (gradientFrom.indexOf('rgba') > -1) {
15500 opacityFrom = Utils$1.getOpacityFromRGBA(gradientFrom);
15501 }
15502 var opacityTo = fillCnf.gradient.opacityTo === undefined ? fillOpacity : Array.isArray(fillCnf.gradient.opacityTo) ? fillCnf.gradient.opacityTo[i] : fillCnf.gradient.opacityTo;
15503 if (fillCnf.gradient.gradientToColors === undefined || fillCnf.gradient.gradientToColors.length === 0) {
15504 if (fillCnf.gradient.shade === 'dark') {
15505 gradientTo = utils.shadeColor(parseFloat(fillCnf.gradient.shadeIntensity) * -1, fillColor.indexOf('rgb') > -1 ? Utils$1.rgb2hex(fillColor) : fillColor);
15506 } else {
15507 gradientTo = utils.shadeColor(parseFloat(fillCnf.gradient.shadeIntensity), fillColor.indexOf('rgb') > -1 ? Utils$1.rgb2hex(fillColor) : fillColor);
15508 }
15509 } else {
15510 if (fillCnf.gradient.gradientToColors[opts.seriesNumber]) {
15511 var gToColor = fillCnf.gradient.gradientToColors[opts.seriesNumber];
15512 gradientTo = gToColor;
15513 if (gToColor.indexOf('rgba') > -1) {
15514 opacityTo = Utils$1.getOpacityFromRGBA(gToColor);
15515 }
15516 } else {
15517 gradientTo = fillColor;
15518 }
15519 }
15520 if (fillCnf.gradient.gradientFrom) {
15521 gradientFrom = fillCnf.gradient.gradientFrom;
15522 }
15523 if (fillCnf.gradient.gradientTo) {
15524 gradientTo = fillCnf.gradient.gradientTo;
15525 }
15526 if (fillCnf.gradient.inverseColors) {
15527 var t = gradientFrom;
15528 gradientFrom = gradientTo;
15529 gradientTo = t;
15530 }
15531 if (gradientFrom.indexOf('rgb') > -1) {
15532 gradientFrom = Utils$1.rgb2hex(gradientFrom);
15533 }
15534 if (gradientTo.indexOf('rgb') > -1) {
15535 gradientTo = Utils$1.rgb2hex(gradientTo);
15536 }
15537 return graphics.drawGradient(type, gradientFrom, gradientTo, opacityFrom, opacityTo, opts.size, fillCnf.gradient.stops, colorStops, i);
15538 }
15539 }]);
15540 return Fill;
15541 }();
15542
15543 /**
15544 * ApexCharts Markers Class for drawing markers on y values in axes charts.
15545 *
15546 * @module Markers
15547 **/
15548 var Markers = /*#__PURE__*/function () {
15549 function Markers(ctx, opts) {
15550 _classCallCheck(this, Markers);
15551 this.ctx = ctx;
15552 this.w = ctx.w;
15553 }
15554 _createClass(Markers, [{
15555 key: "setGlobalMarkerSize",
15556 value: function setGlobalMarkerSize() {
15557 var w = this.w;
15558 w.globals.markers.size = Array.isArray(w.config.markers.size) ? w.config.markers.size : [w.config.markers.size];
15559 if (w.globals.markers.size.length > 0) {
15560 if (w.globals.markers.size.length < w.globals.series.length + 1) {
15561 for (var i = 0; i <= w.globals.series.length; i++) {
15562 if (typeof w.globals.markers.size[i] === 'undefined') {
15563 w.globals.markers.size.push(w.globals.markers.size[0]);
15564 }
15565 }
15566 }
15567 } else {
15568 w.globals.markers.size = w.config.series.map(function (s) {
15569 return w.config.markers.size;
15570 });
15571 }
15572 }
15573 }, {
15574 key: "plotChartMarkers",
15575 value: function plotChartMarkers(_ref) {
15576 var pointsPos = _ref.pointsPos,
15577 seriesIndex = _ref.seriesIndex,
15578 j = _ref.j,
15579 pSize = _ref.pSize,
15580 _ref$alwaysDrawMarker = _ref.alwaysDrawMarker,
15581 alwaysDrawMarker = _ref$alwaysDrawMarker === void 0 ? false : _ref$alwaysDrawMarker,
15582 _ref$isVirtualPoint = _ref.isVirtualPoint,
15583 isVirtualPoint = _ref$isVirtualPoint === void 0 ? false : _ref$isVirtualPoint;
15584 var w = this.w;
15585 var i = seriesIndex;
15586 var p = pointsPos;
15587 var elMarkersWrap = null;
15588 var graphics = new Graphics(this.ctx);
15589 var hasDiscreteMarkers = w.config.markers.discrete && w.config.markers.discrete.length;
15590 if (Array.isArray(p.x)) {
15591 for (var q = 0; q < p.x.length; q++) {
15592 var markerElement = void 0;
15593 var dataPointIndex = j;
15594 var invalidMarker = !Utils$1.isNumber(p.y[q]);
15595 if (w.globals.markers.largestSize === 0 && w.globals.hasNullValues && w.globals.series[i][j + 1] !== null && !isVirtualPoint) {
15596 invalidMarker = true;
15597 }
15598
15599 // a small hack as we have 2 points for the first val to connect it
15600 if (j === 1 && q === 0) dataPointIndex = 0;
15601 if (j === 1 && q === 1) dataPointIndex = 1;
15602 var markerClasses = 'apexcharts-marker';
15603 if ((w.config.chart.type === 'line' || w.config.chart.type === 'area') && !w.globals.comboCharts && !w.config.tooltip.intersect) {
15604 markerClasses += ' no-pointer-events';
15605 }
15606 var shouldMarkerDraw = Array.isArray(w.config.markers.size) ? w.globals.markers.size[seriesIndex] > 0 : w.config.markers.size > 0;
15607 if (shouldMarkerDraw || alwaysDrawMarker || hasDiscreteMarkers) {
15608 if (!invalidMarker) {
15609 markerClasses += " w".concat(Utils$1.randomId());
15610 }
15611 var opts = this.getMarkerConfig({
15612 cssClass: markerClasses,
15613 seriesIndex: seriesIndex,
15614 dataPointIndex: dataPointIndex
15615 });
15616 if (w.config.series[i].data[dataPointIndex]) {
15617 if (w.config.series[i].data[dataPointIndex].fillColor) {
15618 opts.pointFillColor = w.config.series[i].data[dataPointIndex].fillColor;
15619 }
15620 if (w.config.series[i].data[dataPointIndex].strokeColor) {
15621 opts.pointStrokeColor = w.config.series[i].data[dataPointIndex].strokeColor;
15622 }
15623 }
15624 if (typeof pSize !== 'undefined') {
15625 opts.pSize = pSize;
15626 }
15627 if (p.x[q] < -w.globals.markers.largestSize || p.x[q] > w.globals.gridWidth + w.globals.markers.largestSize || p.y[q] < -w.globals.markers.largestSize || p.y[q] > w.globals.gridHeight + w.globals.markers.largestSize) {
15628 opts.pSize = 0;
15629 }
15630 if (!invalidMarker) {
15631 var shouldCreateMarkerWrap = w.globals.markers.size[seriesIndex] > 0 || alwaysDrawMarker || hasDiscreteMarkers;
15632 if (shouldCreateMarkerWrap && !elMarkersWrap) {
15633 elMarkersWrap = graphics.group({
15634 class: alwaysDrawMarker || hasDiscreteMarkers ? '' : 'apexcharts-series-markers'
15635 });
15636 elMarkersWrap.attr('clip-path', "url(#gridRectMarkerMask".concat(w.globals.cuid, ")"));
15637 }
15638 markerElement = graphics.drawMarker(p.x[q], p.y[q], opts);
15639 markerElement.attr('rel', dataPointIndex);
15640 markerElement.attr('j', dataPointIndex);
15641 markerElement.attr('index', seriesIndex);
15642 markerElement.node.setAttribute('default-marker-size', opts.pSize);
15643 var filters = new Filters(this.ctx);
15644 filters.setSelectionFilter(markerElement, seriesIndex, dataPointIndex);
15645 this.addEvents(markerElement);
15646 if (elMarkersWrap) {
15647 elMarkersWrap.add(markerElement);
15648 }
15649 }
15650 } else {
15651 // dynamic array creation - multidimensional
15652 if (typeof w.globals.pointsArray[seriesIndex] === 'undefined') w.globals.pointsArray[seriesIndex] = [];
15653 w.globals.pointsArray[seriesIndex].push([p.x[q], p.y[q]]);
15654 }
15655 }
15656 }
15657 return elMarkersWrap;
15658 }
15659 }, {
15660 key: "getMarkerConfig",
15661 value: function getMarkerConfig(_ref2) {
15662 var cssClass = _ref2.cssClass,
15663 seriesIndex = _ref2.seriesIndex,
15664 _ref2$dataPointIndex = _ref2.dataPointIndex,
15665 dataPointIndex = _ref2$dataPointIndex === void 0 ? null : _ref2$dataPointIndex,
15666 _ref2$radius = _ref2.radius,
15667 radius = _ref2$radius === void 0 ? null : _ref2$radius,
15668 _ref2$size = _ref2.size,
15669 size = _ref2$size === void 0 ? null : _ref2$size,
15670 _ref2$strokeWidth = _ref2.strokeWidth,
15671 strokeWidth = _ref2$strokeWidth === void 0 ? null : _ref2$strokeWidth;
15672 var w = this.w;
15673 var pStyle = this.getMarkerStyle(seriesIndex);
15674 var pSize = size === null ? w.globals.markers.size[seriesIndex] : size;
15675 var m = w.config.markers;
15676
15677 // discrete markers is an option where user can specify a particular marker with different shape, size and color
15678
15679 if (dataPointIndex !== null && m.discrete.length) {
15680 m.discrete.map(function (marker) {
15681 if (marker.seriesIndex === seriesIndex && marker.dataPointIndex === dataPointIndex) {
15682 pStyle.pointStrokeColor = marker.strokeColor;
15683 pStyle.pointFillColor = marker.fillColor;
15684 pSize = marker.size;
15685 pStyle.pointShape = marker.shape;
15686 }
15687 });
15688 }
15689 return {
15690 pSize: radius === null ? pSize : radius,
15691 pRadius: radius !== null ? radius : m.radius,
15692 pointStrokeWidth: strokeWidth !== null ? strokeWidth : Array.isArray(m.strokeWidth) ? m.strokeWidth[seriesIndex] : m.strokeWidth,
15693 pointStrokeColor: pStyle.pointStrokeColor,
15694 pointFillColor: pStyle.pointFillColor,
15695 shape: pStyle.pointShape || (Array.isArray(m.shape) ? m.shape[seriesIndex] : m.shape),
15696 class: cssClass,
15697 pointStrokeOpacity: Array.isArray(m.strokeOpacity) ? m.strokeOpacity[seriesIndex] : m.strokeOpacity,
15698 pointStrokeDashArray: Array.isArray(m.strokeDashArray) ? m.strokeDashArray[seriesIndex] : m.strokeDashArray,
15699 pointFillOpacity: Array.isArray(m.fillOpacity) ? m.fillOpacity[seriesIndex] : m.fillOpacity,
15700 seriesIndex: seriesIndex
15701 };
15702 }
15703 }, {
15704 key: "addEvents",
15705 value: function addEvents(marker) {
15706 var w = this.w;
15707 var graphics = new Graphics(this.ctx);
15708 marker.node.addEventListener('mouseenter', graphics.pathMouseEnter.bind(this.ctx, marker));
15709 marker.node.addEventListener('mouseleave', graphics.pathMouseLeave.bind(this.ctx, marker));
15710 marker.node.addEventListener('mousedown', graphics.pathMouseDown.bind(this.ctx, marker));
15711 marker.node.addEventListener('click', w.config.markers.onClick);
15712 marker.node.addEventListener('dblclick', w.config.markers.onDblClick);
15713 marker.node.addEventListener('touchstart', graphics.pathMouseDown.bind(this.ctx, marker), {
15714 passive: true
15715 });
15716 }
15717 }, {
15718 key: "getMarkerStyle",
15719 value: function getMarkerStyle(seriesIndex) {
15720 var w = this.w;
15721 var colors = w.globals.markers.colors;
15722 var strokeColors = w.config.markers.strokeColor || w.config.markers.strokeColors;
15723 var pointStrokeColor = Array.isArray(strokeColors) ? strokeColors[seriesIndex] : strokeColors;
15724 var pointFillColor = Array.isArray(colors) ? colors[seriesIndex] : colors;
15725 return {
15726 pointStrokeColor: pointStrokeColor,
15727 pointFillColor: pointFillColor
15728 };
15729 }
15730 }]);
15731 return Markers;
15732 }();
15733
15734 /**
15735 * ApexCharts Scatter Class.
15736 * This Class also handles bubbles chart as currently there is no major difference in drawing them,
15737 * @module Scatter
15738 **/
15739 var Scatter = /*#__PURE__*/function () {
15740 function Scatter(ctx) {
15741 _classCallCheck(this, Scatter);
15742 this.ctx = ctx;
15743 this.w = ctx.w;
15744 this.initialAnim = this.w.config.chart.animations.enabled;
15745 }
15746 _createClass(Scatter, [{
15747 key: "draw",
15748 value: function draw(elSeries, j, opts) {
15749 var w = this.w;
15750 var graphics = new Graphics(this.ctx);
15751 var realIndex = opts.realIndex;
15752 var pointsPos = opts.pointsPos;
15753 var zRatio = opts.zRatio;
15754 var elPointsMain = opts.elParent;
15755 var elPointsWrap = graphics.group({
15756 class: "apexcharts-series-markers apexcharts-series-".concat(w.config.chart.type)
15757 });
15758 elPointsWrap.attr('clip-path', "url(#gridRectMarkerMask".concat(w.globals.cuid, ")"));
15759 if (Array.isArray(pointsPos.x)) {
15760 for (var q = 0; q < pointsPos.x.length; q++) {
15761 var dataPointIndex = j + 1;
15762 var shouldDraw = true;
15763
15764 // a small hack as we have 2 points for the first val to connect it
15765 if (j === 0 && q === 0) dataPointIndex = 0;
15766 if (j === 0 && q === 1) dataPointIndex = 1;
15767 var radius = w.globals.markers.size[realIndex];
15768 if (zRatio !== Infinity) {
15769 // means we have a bubble
15770 var bubble = w.config.plotOptions.bubble;
15771 radius = w.globals.seriesZ[realIndex][dataPointIndex];
15772 if (bubble.zScaling) {
15773 radius /= zRatio;
15774 }
15775 if (bubble.minBubbleRadius && radius < bubble.minBubbleRadius) {
15776 radius = bubble.minBubbleRadius;
15777 }
15778 if (bubble.maxBubbleRadius && radius > bubble.maxBubbleRadius) {
15779 radius = bubble.maxBubbleRadius;
15780 }
15781 }
15782 var x = pointsPos.x[q];
15783 var y = pointsPos.y[q];
15784 radius = radius || 0;
15785 if (y === null || typeof w.globals.series[realIndex][dataPointIndex] === 'undefined') {
15786 shouldDraw = false;
15787 }
15788 if (shouldDraw) {
15789 var point = this.drawPoint(x, y, radius, realIndex, dataPointIndex, j);
15790 elPointsWrap.add(point);
15791 }
15792 elPointsMain.add(elPointsWrap);
15793 }
15794 }
15795 }
15796 }, {
15797 key: "drawPoint",
15798 value: function drawPoint(x, y, radius, realIndex, dataPointIndex, j) {
15799 var w = this.w;
15800 var i = realIndex;
15801 var anim = new Animations(this.ctx);
15802 var filters = new Filters(this.ctx);
15803 var fill = new Fill(this.ctx);
15804 var markers = new Markers(this.ctx);
15805 var graphics = new Graphics(this.ctx);
15806 var markerConfig = markers.getMarkerConfig({
15807 cssClass: 'apexcharts-marker',
15808 seriesIndex: i,
15809 dataPointIndex: dataPointIndex,
15810 radius: w.config.chart.type === 'bubble' || w.globals.comboCharts && w.config.series[realIndex] && w.config.series[realIndex].type === 'bubble' ? radius : null
15811 });
15812 var pathFillCircle = fill.fillPath({
15813 seriesNumber: realIndex,
15814 dataPointIndex: dataPointIndex,
15815 color: markerConfig.pointFillColor,
15816 patternUnits: 'objectBoundingBox',
15817 value: w.globals.series[realIndex][j]
15818 });
15819 var el = graphics.drawMarker(x, y, markerConfig);
15820 if (w.config.series[i].data[dataPointIndex]) {
15821 if (w.config.series[i].data[dataPointIndex].fillColor) {
15822 pathFillCircle = w.config.series[i].data[dataPointIndex].fillColor;
15823 }
15824 }
15825 el.attr({
15826 fill: pathFillCircle
15827 });
15828 if (w.config.chart.dropShadow.enabled) {
15829 var dropShadow = w.config.chart.dropShadow;
15830 filters.dropShadow(el, dropShadow, realIndex);
15831 }
15832 if (this.initialAnim && !w.globals.dataChanged && !w.globals.resized) {
15833 var speed = w.config.chart.animations.speed;
15834 anim.animateMarker(el, speed, w.globals.easing, function () {
15835 window.setTimeout(function () {
15836 anim.animationCompleted(el);
15837 }, 100);
15838 });
15839 } else {
15840 w.globals.animationEnded = true;
15841 }
15842 el.attr({
15843 rel: dataPointIndex,
15844 j: dataPointIndex,
15845 index: realIndex,
15846 'default-marker-size': markerConfig.pSize
15847 });
15848 filters.setSelectionFilter(el, realIndex, dataPointIndex);
15849 markers.addEvents(el);
15850 el.node.classList.add('apexcharts-marker');
15851 return el;
15852 }
15853 }, {
15854 key: "centerTextInBubble",
15855 value: function centerTextInBubble(y) {
15856 var w = this.w;
15857 y = y + parseInt(w.config.dataLabels.style.fontSize, 10) / 4;
15858 return {
15859 y: y
15860 };
15861 }
15862 }]);
15863 return Scatter;
15864 }();
15865
15866 /**
15867 * ApexCharts DataLabels Class for drawing dataLabels on Axes based Charts.
15868 *
15869 * @module DataLabels
15870 **/
15871 var DataLabels = /*#__PURE__*/function () {
15872 function DataLabels(ctx) {
15873 _classCallCheck(this, DataLabels);
15874 this.ctx = ctx;
15875 this.w = ctx.w;
15876 }
15877
15878 // When there are many datalabels to be printed, and some of them overlaps each other in the same series, this method will take care of that
15879 // Also, when datalabels exceeds the drawable area and get clipped off, we need to adjust and move some pixels to make them visible again
15880 _createClass(DataLabels, [{
15881 key: "dataLabelsCorrection",
15882 value: function dataLabelsCorrection(x, y, val, i, dataPointIndex, alwaysDrawDataLabel, fontSize) {
15883 var w = this.w;
15884 var graphics = new Graphics(this.ctx);
15885 var drawnextLabel = false; //
15886
15887 var textRects = graphics.getTextRects(val, fontSize);
15888 var width = textRects.width;
15889 var height = textRects.height;
15890 if (y < 0) y = 0;
15891 if (y > w.globals.gridHeight + height) y = w.globals.gridHeight + height / 2;
15892
15893 // first value in series, so push an empty array
15894 if (typeof w.globals.dataLabelsRects[i] === 'undefined') w.globals.dataLabelsRects[i] = [];
15895
15896 // then start pushing actual rects in that sub-array
15897 w.globals.dataLabelsRects[i].push({
15898 x: x,
15899 y: y,
15900 width: width,
15901 height: height
15902 });
15903 var len = w.globals.dataLabelsRects[i].length - 2;
15904 var lastDrawnIndex = typeof w.globals.lastDrawnDataLabelsIndexes[i] !== 'undefined' ? w.globals.lastDrawnDataLabelsIndexes[i][w.globals.lastDrawnDataLabelsIndexes[i].length - 1] : 0;
15905 if (typeof w.globals.dataLabelsRects[i][len] !== 'undefined') {
15906 var lastDataLabelRect = w.globals.dataLabelsRects[i][lastDrawnIndex];
15907 if (
15908 // next label forward and x not intersecting
15909 x > lastDataLabelRect.x + lastDataLabelRect.width || y > lastDataLabelRect.y + lastDataLabelRect.height || y + height < lastDataLabelRect.y || x + width < lastDataLabelRect.x // next label is going to be drawn backwards
15910 ) {
15911 // the 2 indexes don't override, so OK to draw next label
15912 drawnextLabel = true;
15913 }
15914 }
15915 if (dataPointIndex === 0 || alwaysDrawDataLabel) {
15916 drawnextLabel = true;
15917 }
15918 return {
15919 x: x,
15920 y: y,
15921 textRects: textRects,
15922 drawnextLabel: drawnextLabel
15923 };
15924 }
15925 }, {
15926 key: "drawDataLabel",
15927 value: function drawDataLabel(_ref) {
15928 var _this = this;
15929 var type = _ref.type,
15930 pos = _ref.pos,
15931 i = _ref.i,
15932 j = _ref.j,
15933 isRangeStart = _ref.isRangeStart,
15934 _ref$strokeWidth = _ref.strokeWidth,
15935 strokeWidth = _ref$strokeWidth === void 0 ? 2 : _ref$strokeWidth;
15936 // this method handles line, area, bubble, scatter charts as those charts contains markers/points which have pre-defined x/y positions
15937 // all other charts like radar / bars / heatmaps will define their own drawDataLabel routine
15938 var w = this.w;
15939 var graphics = new Graphics(this.ctx);
15940 var dataLabelsConfig = w.config.dataLabels;
15941 var x = 0;
15942 var y = 0;
15943 var dataPointIndex = j;
15944 var elDataLabelsWrap = null;
15945 var seriesCollapsed = w.globals.collapsedSeriesIndices.indexOf(i) !== -1;
15946 if (seriesCollapsed || !dataLabelsConfig.enabled || !Array.isArray(pos.x)) {
15947 return elDataLabelsWrap;
15948 }
15949 elDataLabelsWrap = graphics.group({
15950 class: 'apexcharts-data-labels'
15951 });
15952 for (var q = 0; q < pos.x.length; q++) {
15953 x = pos.x[q] + dataLabelsConfig.offsetX;
15954 y = pos.y[q] + dataLabelsConfig.offsetY + strokeWidth;
15955 if (!isNaN(x)) {
15956 // a small hack as we have 2 points for the first val to connect it
15957 if (j === 1 && q === 0) dataPointIndex = 0;
15958 if (j === 1 && q === 1) dataPointIndex = 1;
15959 var val = w.globals.series[i][dataPointIndex];
15960 if (type === 'rangeArea') {
15961 if (isRangeStart) {
15962 val = w.globals.seriesRangeStart[i][dataPointIndex];
15963 } else {
15964 val = w.globals.seriesRangeEnd[i][dataPointIndex];
15965 }
15966 }
15967 var text = '';
15968 var getText = function getText(v) {
15969 return w.config.dataLabels.formatter(v, {
15970 ctx: _this.ctx,
15971 seriesIndex: i,
15972 dataPointIndex: dataPointIndex,
15973 w: w
15974 });
15975 };
15976 if (w.config.chart.type === 'bubble') {
15977 val = w.globals.seriesZ[i][dataPointIndex];
15978 text = getText(val);
15979 y = pos.y[q];
15980 var scatter = new Scatter(this.ctx);
15981 var centerTextInBubbleCoords = scatter.centerTextInBubble(y, i, dataPointIndex);
15982 y = centerTextInBubbleCoords.y;
15983 } else {
15984 if (typeof val !== 'undefined') {
15985 text = getText(val);
15986 }
15987 }
15988 var textAnchor = w.config.dataLabels.textAnchor;
15989 if (w.globals.isSlopeChart) {
15990 if (dataPointIndex === 0) {
15991 textAnchor = 'end';
15992 } else if (dataPointIndex === w.config.series[i].data.length - 1) {
15993 textAnchor = 'start';
15994 } else {
15995 textAnchor = 'middle';
15996 }
15997 }
15998 this.plotDataLabelsText({
15999 x: x,
16000 y: y,
16001 text: text,
16002 i: i,
16003 j: dataPointIndex,
16004 parent: elDataLabelsWrap,
16005 offsetCorrection: true,
16006 dataLabelsConfig: w.config.dataLabels,
16007 textAnchor: textAnchor
16008 });
16009 }
16010 }
16011 return elDataLabelsWrap;
16012 }
16013 }, {
16014 key: "plotDataLabelsText",
16015 value: function plotDataLabelsText(opts) {
16016 var w = this.w;
16017 var graphics = new Graphics(this.ctx);
16018 var x = opts.x,
16019 y = opts.y,
16020 i = opts.i,
16021 j = opts.j,
16022 text = opts.text,
16023 textAnchor = opts.textAnchor,
16024 fontSize = opts.fontSize,
16025 parent = opts.parent,
16026 dataLabelsConfig = opts.dataLabelsConfig,
16027 color = opts.color,
16028 alwaysDrawDataLabel = opts.alwaysDrawDataLabel,
16029 offsetCorrection = opts.offsetCorrection,
16030 className = opts.className;
16031 var dataLabelText = null;
16032 if (Array.isArray(w.config.dataLabels.enabledOnSeries)) {
16033 if (w.config.dataLabels.enabledOnSeries.indexOf(i) < 0) {
16034 return dataLabelText;
16035 }
16036 }
16037 var correctedLabels = {
16038 x: x,
16039 y: y,
16040 drawnextLabel: true,
16041 textRects: null
16042 };
16043 if (offsetCorrection) {
16044 correctedLabels = this.dataLabelsCorrection(x, y, text, i, j, alwaysDrawDataLabel, parseInt(dataLabelsConfig.style.fontSize, 10));
16045 }
16046
16047 // when zoomed, we don't need to correct labels offsets,
16048 // but if normally, labels get cropped, correct them
16049 if (!w.globals.zoomed) {
16050 x = correctedLabels.x;
16051 y = correctedLabels.y;
16052 }
16053 if (correctedLabels.textRects) {
16054 // fixes #2264
16055 if (x < -20 - correctedLabels.textRects.width || x > w.globals.gridWidth + correctedLabels.textRects.width + 30) {
16056 // datalabels fall outside drawing area, so draw a blank label
16057 text = '';
16058 }
16059 }
16060 var dataLabelColor = w.globals.dataLabels.style.colors[i];
16061 if ((w.config.chart.type === 'bar' || w.config.chart.type === 'rangeBar') && w.config.plotOptions.bar.distributed || w.config.dataLabels.distributed) {
16062 dataLabelColor = w.globals.dataLabels.style.colors[j];
16063 }
16064 if (typeof dataLabelColor === 'function') {
16065 dataLabelColor = dataLabelColor({
16066 series: w.globals.series,
16067 seriesIndex: i,
16068 dataPointIndex: j,
16069 w: w
16070 });
16071 }
16072 if (color) {
16073 dataLabelColor = color;
16074 }
16075 var offX = dataLabelsConfig.offsetX;
16076 var offY = dataLabelsConfig.offsetY;
16077 if (w.config.chart.type === 'bar' || w.config.chart.type === 'rangeBar') {
16078 // for certain chart types, we handle offsets while calculating datalabels pos
16079 // why? because bars/column may have negative values and based on that
16080 // offsets becomes reversed
16081 offX = 0;
16082 offY = 0;
16083 }
16084 if (w.globals.isSlopeChart) {
16085 if (j !== 0) {
16086 offX = dataLabelsConfig.offsetX * -2 + 5;
16087 }
16088 if (j !== 0 && j !== w.config.series[i].data.length - 1) {
16089 offX = 0;
16090 }
16091 }
16092 if (correctedLabels.drawnextLabel) {
16093 dataLabelText = graphics.drawText({
16094 width: 100,
16095 height: parseInt(dataLabelsConfig.style.fontSize, 10),
16096 x: x + offX,
16097 y: y + offY,
16098 foreColor: dataLabelColor,
16099 textAnchor: textAnchor || dataLabelsConfig.textAnchor,
16100 text: text,
16101 fontSize: fontSize || dataLabelsConfig.style.fontSize,
16102 fontFamily: dataLabelsConfig.style.fontFamily,
16103 fontWeight: dataLabelsConfig.style.fontWeight || 'normal'
16104 });
16105 dataLabelText.attr({
16106 class: className || 'apexcharts-datalabel',
16107 cx: x,
16108 cy: y
16109 });
16110 if (dataLabelsConfig.dropShadow.enabled) {
16111 var textShadow = dataLabelsConfig.dropShadow;
16112 var filters = new Filters(this.ctx);
16113 filters.dropShadow(dataLabelText, textShadow);
16114 }
16115 parent.add(dataLabelText);
16116 if (typeof w.globals.lastDrawnDataLabelsIndexes[i] === 'undefined') {
16117 w.globals.lastDrawnDataLabelsIndexes[i] = [];
16118 }
16119 w.globals.lastDrawnDataLabelsIndexes[i].push(j);
16120 }
16121 return dataLabelText;
16122 }
16123 }, {
16124 key: "addBackgroundToDataLabel",
16125 value: function addBackgroundToDataLabel(el, coords) {
16126 var w = this.w;
16127 var bCnf = w.config.dataLabels.background;
16128 var paddingH = bCnf.padding;
16129 var paddingV = bCnf.padding / 2;
16130 var width = coords.width;
16131 var height = coords.height;
16132 var graphics = new Graphics(this.ctx);
16133 var elRect = graphics.drawRect(coords.x - paddingH, coords.y - paddingV / 2, width + paddingH * 2, height + paddingV, bCnf.borderRadius, w.config.chart.background === 'transparent' || !w.config.chart.background ? '#fff' : w.config.chart.background, bCnf.opacity, bCnf.borderWidth, bCnf.borderColor);
16134 if (bCnf.dropShadow.enabled) {
16135 var filters = new Filters(this.ctx);
16136 filters.dropShadow(elRect, bCnf.dropShadow);
16137 }
16138 return elRect;
16139 }
16140 }, {
16141 key: "dataLabelsBackground",
16142 value: function dataLabelsBackground() {
16143 var w = this.w;
16144 if (w.config.chart.type === 'bubble') return;
16145 var elDataLabels = w.globals.dom.baseEl.querySelectorAll('.apexcharts-datalabels text');
16146 for (var i = 0; i < elDataLabels.length; i++) {
16147 var el = elDataLabels[i];
16148 var coords = el.getBBox();
16149 var elRect = null;
16150 if (coords.width && coords.height) {
16151 elRect = this.addBackgroundToDataLabel(el, coords);
16152 }
16153 if (elRect) {
16154 el.parentNode.insertBefore(elRect.node, el);
16155 var background = w.config.dataLabels.background.backgroundColor || el.getAttribute('fill');
16156 var shouldAnim = w.config.chart.animations.enabled && !w.globals.resized && !w.globals.dataChanged;
16157 if (shouldAnim) {
16158 elRect.animate().attr({
16159 fill: background
16160 });
16161 } else {
16162 elRect.attr({
16163 fill: background
16164 });
16165 }
16166 el.setAttribute('fill', w.config.dataLabels.background.foreColor);
16167 }
16168 }
16169 }
16170 }, {
16171 key: "bringForward",
16172 value: function bringForward() {
16173 var w = this.w;
16174 var elDataLabelsNodes = w.globals.dom.baseEl.querySelectorAll('.apexcharts-datalabels');
16175 var elSeries = w.globals.dom.baseEl.querySelector('.apexcharts-plot-series:last-child');
16176 for (var i = 0; i < elDataLabelsNodes.length; i++) {
16177 if (elSeries) {
16178 elSeries.insertBefore(elDataLabelsNodes[i], elSeries.nextSibling);
16179 }
16180 }
16181 }
16182 }]);
16183 return DataLabels;
16184 }();
16185
16186 /**
16187 * ApexCharts Series Class for interaction with the Series of the chart.
16188 *
16189 * @module Series
16190 **/
16191 var Series = /*#__PURE__*/function () {
16192 function Series(ctx) {
16193 _classCallCheck(this, Series);
16194 this.ctx = ctx;
16195 this.w = ctx.w;
16196 this.legendInactiveClass = 'legend-mouseover-inactive';
16197 }
16198 _createClass(Series, [{
16199 key: "getAllSeriesEls",
16200 value: function getAllSeriesEls() {
16201 return this.w.globals.dom.baseEl.getElementsByClassName("apexcharts-series");
16202 }
16203 }, {
16204 key: "getSeriesByName",
16205 value: function getSeriesByName(seriesName) {
16206 return this.w.globals.dom.baseEl.querySelector(".apexcharts-inner .apexcharts-series[seriesName='".concat(Utils$1.escapeString(seriesName), "']"));
16207 }
16208 }, {
16209 key: "isSeriesHidden",
16210 value: function isSeriesHidden(seriesName) {
16211 var targetElement = this.getSeriesByName(seriesName);
16212 var realIndex = parseInt(targetElement.getAttribute('data:realIndex'), 10);
16213 var isHidden = targetElement.classList.contains('apexcharts-series-collapsed');
16214 return {
16215 isHidden: isHidden,
16216 realIndex: realIndex
16217 };
16218 }
16219 }, {
16220 key: "addCollapsedClassToSeries",
16221 value: function addCollapsedClassToSeries(elSeries, index) {
16222 var w = this.w;
16223 function iterateOnAllCollapsedSeries(series) {
16224 for (var cs = 0; cs < series.length; cs++) {
16225 if (series[cs].index === index) {
16226 elSeries.node.classList.add('apexcharts-series-collapsed');
16227 }
16228 }
16229 }
16230 iterateOnAllCollapsedSeries(w.globals.collapsedSeries);
16231 iterateOnAllCollapsedSeries(w.globals.ancillaryCollapsedSeries);
16232 }
16233 }, {
16234 key: "toggleSeries",
16235 value: function toggleSeries(seriesName) {
16236 var isSeriesHidden = this.isSeriesHidden(seriesName);
16237 this.ctx.legend.legendHelpers.toggleDataSeries(isSeriesHidden.realIndex, isSeriesHidden.isHidden);
16238 return isSeriesHidden.isHidden;
16239 }
16240 }, {
16241 key: "showSeries",
16242 value: function showSeries(seriesName) {
16243 var isSeriesHidden = this.isSeriesHidden(seriesName);
16244 if (isSeriesHidden.isHidden) {
16245 this.ctx.legend.legendHelpers.toggleDataSeries(isSeriesHidden.realIndex, true);
16246 }
16247 }
16248 }, {
16249 key: "hideSeries",
16250 value: function hideSeries(seriesName) {
16251 var isSeriesHidden = this.isSeriesHidden(seriesName);
16252 if (!isSeriesHidden.isHidden) {
16253 this.ctx.legend.legendHelpers.toggleDataSeries(isSeriesHidden.realIndex, false);
16254 }
16255 }
16256 }, {
16257 key: "resetSeries",
16258 value: function resetSeries() {
16259 var shouldUpdateChart = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
16260 var shouldResetZoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
16261 var shouldResetCollapsed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
16262 var w = this.w;
16263 var series = Utils$1.clone(w.globals.initialSeries);
16264 w.globals.previousPaths = [];
16265 if (shouldResetCollapsed) {
16266 w.globals.collapsedSeries = [];
16267 w.globals.ancillaryCollapsedSeries = [];
16268 w.globals.collapsedSeriesIndices = [];
16269 w.globals.ancillaryCollapsedSeriesIndices = [];
16270 } else {
16271 series = this.emptyCollapsedSeries(series);
16272 }
16273 w.config.series = series;
16274 if (shouldUpdateChart) {
16275 if (shouldResetZoom) {
16276 w.globals.zoomed = false;
16277 this.ctx.updateHelpers.revertDefaultAxisMinMax();
16278 }
16279 this.ctx.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
16280 }
16281 }
16282 }, {
16283 key: "emptyCollapsedSeries",
16284 value: function emptyCollapsedSeries(series) {
16285 var w = this.w;
16286 for (var i = 0; i < series.length; i++) {
16287 if (w.globals.collapsedSeriesIndices.indexOf(i) > -1) {
16288 series[i].data = [];
16289 }
16290 }
16291 return series;
16292 }
16293 }, {
16294 key: "highlightSeries",
16295 value: function highlightSeries(seriesName) {
16296 var w = this.w;
16297 var targetElement = this.getSeriesByName(seriesName);
16298 var realIndex = parseInt(targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute('data:realIndex'), 10);
16299 var allSeriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-series, .apexcharts-datalabels, .apexcharts-yaxis");
16300 var seriesEl = null;
16301 var dataLabelEl = null;
16302 var yaxisEl = null;
16303 if (w.globals.axisCharts || w.config.chart.type === 'radialBar') {
16304 if (w.globals.axisCharts) {
16305 seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[data\\:realIndex='".concat(realIndex, "']"));
16306 dataLabelEl = w.globals.dom.baseEl.querySelector(".apexcharts-datalabels[data\\:realIndex='".concat(realIndex, "']"));
16307 var yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex];
16308 yaxisEl = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(yaxisIndex, "']"));
16309 } else {
16310 seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[rel='".concat(realIndex + 1, "']"));
16311 }
16312 } else {
16313 seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[rel='".concat(realIndex + 1, "'] path"));
16314 }
16315 for (var se = 0; se < allSeriesEls.length; se++) {
16316 allSeriesEls[se].classList.add(this.legendInactiveClass);
16317 }
16318 if (seriesEl) {
16319 if (!w.globals.axisCharts) {
16320 seriesEl.parentNode.classList.remove(this.legendInactiveClass);
16321 }
16322 seriesEl.classList.remove(this.legendInactiveClass);
16323 if (dataLabelEl !== null) {
16324 dataLabelEl.classList.remove(this.legendInactiveClass);
16325 }
16326 if (yaxisEl !== null) {
16327 yaxisEl.classList.remove(this.legendInactiveClass);
16328 }
16329 } else {
16330 for (var _se = 0; _se < allSeriesEls.length; _se++) {
16331 allSeriesEls[_se].classList.remove(this.legendInactiveClass);
16332 }
16333 }
16334 }
16335 }, {
16336 key: "toggleSeriesOnHover",
16337 value: function toggleSeriesOnHover(e, targetElement) {
16338 var w = this.w;
16339 if (!targetElement) targetElement = e.target;
16340 var allSeriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-series, .apexcharts-datalabels, .apexcharts-yaxis");
16341 if (e.type === 'mousemove') {
16342 var realIndex = parseInt(targetElement.getAttribute('rel'), 10) - 1;
16343 this.highlightSeries(w.globals.seriesNames[realIndex]);
16344 } else if (e.type === 'mouseout') {
16345 for (var se = 0; se < allSeriesEls.length; se++) {
16346 allSeriesEls[se].classList.remove(this.legendInactiveClass);
16347 }
16348 }
16349 }
16350 }, {
16351 key: "highlightRangeInSeries",
16352 value: function highlightRangeInSeries(e, targetElement) {
16353 var _this = this;
16354 var w = this.w;
16355 var allHeatMapElements = w.globals.dom.baseEl.getElementsByClassName('apexcharts-heatmap-rect');
16356 var activeInactive = function activeInactive(action) {
16357 for (var i = 0; i < allHeatMapElements.length; i++) {
16358 allHeatMapElements[i].classList[action](_this.legendInactiveClass);
16359 }
16360 };
16361 var removeInactiveClassFromHoveredRange = function removeInactiveClassFromHoveredRange(range, rangeMax) {
16362 for (var i = 0; i < allHeatMapElements.length; i++) {
16363 var val = Number(allHeatMapElements[i].getAttribute('val'));
16364 if (val >= range.from && (val < range.to || range.to === rangeMax && val === rangeMax)) {
16365 allHeatMapElements[i].classList.remove(_this.legendInactiveClass);
16366 }
16367 }
16368 };
16369 if (e.type === 'mousemove') {
16370 var seriesCnt = parseInt(targetElement.getAttribute('rel'), 10) - 1;
16371 activeInactive('add');
16372 var ranges = w.config.plotOptions.heatmap.colorScale.ranges;
16373 var range = ranges[seriesCnt];
16374 var rangeMax = ranges.reduce(function (acc, cur) {
16375 return Math.max(acc, cur.to);
16376 }, 0);
16377 removeInactiveClassFromHoveredRange(range, rangeMax);
16378 } else if (e.type === 'mouseout') {
16379 activeInactive('remove');
16380 }
16381 }
16382 }, {
16383 key: "getActiveConfigSeriesIndex",
16384 value: function getActiveConfigSeriesIndex() {
16385 var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'asc';
16386 var chartTypes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
16387 var w = this.w;
16388 var activeIndex = 0;
16389 if (w.config.series.length > 1) {
16390 // active series flag is required to know if user has not deactivated via legend click
16391 var activeSeriesIndex = w.config.series.map(function (s, index) {
16392 var checkChartType = function checkChartType() {
16393 if (w.globals.comboCharts) {
16394 return chartTypes.length === 0 || chartTypes.length && chartTypes.indexOf(w.config.series[index].type) > -1;
16395 }
16396 return true;
16397 };
16398 var hasData = s.data && s.data.length > 0 && w.globals.collapsedSeriesIndices.indexOf(index) === -1;
16399 return hasData && checkChartType() ? index : -1;
16400 });
16401 for (var a = order === 'asc' ? 0 : activeSeriesIndex.length - 1; order === 'asc' ? a < activeSeriesIndex.length : a >= 0; order === 'asc' ? a++ : a--) {
16402 if (activeSeriesIndex[a] !== -1) {
16403 activeIndex = activeSeriesIndex[a];
16404 break;
16405 }
16406 }
16407 }
16408 return activeIndex;
16409 }
16410 }, {
16411 key: "getBarSeriesIndices",
16412 value: function getBarSeriesIndices() {
16413 var w = this.w;
16414 if (w.globals.comboCharts) {
16415 return this.w.config.series.map(function (s, i) {
16416 return s.type === 'bar' || s.type === 'column' ? i : -1;
16417 }).filter(function (i) {
16418 return i !== -1;
16419 });
16420 }
16421 return this.w.config.series.map(function (s, i) {
16422 return i;
16423 });
16424 }
16425 }, {
16426 key: "getPreviousPaths",
16427 value: function getPreviousPaths() {
16428 var w = this.w;
16429 w.globals.previousPaths = [];
16430 function pushPaths(seriesEls, i, type) {
16431 var paths = seriesEls[i].childNodes;
16432 var dArr = {
16433 type: type,
16434 paths: [],
16435 realIndex: seriesEls[i].getAttribute('data:realIndex')
16436 };
16437 for (var j = 0; j < paths.length; j++) {
16438 if (paths[j].hasAttribute('pathTo')) {
16439 var d = paths[j].getAttribute('pathTo');
16440 dArr.paths.push({
16441 d: d
16442 });
16443 }
16444 }
16445 w.globals.previousPaths.push(dArr);
16446 }
16447 var getPaths = function getPaths(chartType) {
16448 return w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(chartType, "-series .apexcharts-series"));
16449 };
16450 var chartTypes = ['line', 'area', 'bar', 'rangebar', 'rangeArea', 'candlestick', 'radar'];
16451 chartTypes.forEach(function (type) {
16452 var paths = getPaths(type);
16453 for (var p = 0; p < paths.length; p++) {
16454 pushPaths(paths, p, type);
16455 }
16456 });
16457 var heatTreeSeries = w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(w.config.chart.type, " .apexcharts-series"));
16458 if (heatTreeSeries.length > 0) {
16459 var _loop = function _loop(h) {
16460 var seriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(w.config.chart.type, " .apexcharts-series[data\\:realIndex='").concat(h, "'] rect"));
16461 var dArr = [];
16462 var _loop2 = function _loop2(i) {
16463 var getAttr = function getAttr(x) {
16464 return seriesEls[i].getAttribute(x);
16465 };
16466 var rect = {
16467 x: parseFloat(getAttr('x')),
16468 y: parseFloat(getAttr('y')),
16469 width: parseFloat(getAttr('width')),
16470 height: parseFloat(getAttr('height'))
16471 };
16472 dArr.push({
16473 rect: rect,
16474 color: seriesEls[i].getAttribute('color')
16475 });
16476 };
16477 for (var i = 0; i < seriesEls.length; i++) {
16478 _loop2(i);
16479 }
16480 w.globals.previousPaths.push(dArr);
16481 };
16482 for (var h = 0; h < heatTreeSeries.length; h++) {
16483 _loop(h);
16484 }
16485 }
16486 if (!w.globals.axisCharts) {
16487 // for non-axis charts (i.e., circular charts, pathFrom is not usable. We need whole series)
16488 w.globals.previousPaths = w.globals.series;
16489 }
16490 }
16491 }, {
16492 key: "clearPreviousPaths",
16493 value: function clearPreviousPaths() {
16494 var w = this.w;
16495 w.globals.previousPaths = [];
16496 w.globals.allSeriesCollapsed = false;
16497 }
16498 }, {
16499 key: "handleNoData",
16500 value: function handleNoData() {
16501 var w = this.w;
16502 var me = this;
16503 var noDataOpts = w.config.noData;
16504 var graphics = new Graphics(me.ctx);
16505 var x = w.globals.svgWidth / 2;
16506 var y = w.globals.svgHeight / 2;
16507 var textAnchor = 'middle';
16508 w.globals.noData = true;
16509 w.globals.animationEnded = true;
16510 if (noDataOpts.align === 'left') {
16511 x = 10;
16512 textAnchor = 'start';
16513 } else if (noDataOpts.align === 'right') {
16514 x = w.globals.svgWidth - 10;
16515 textAnchor = 'end';
16516 }
16517 if (noDataOpts.verticalAlign === 'top') {
16518 y = 50;
16519 } else if (noDataOpts.verticalAlign === 'bottom') {
16520 y = w.globals.svgHeight - 50;
16521 }
16522 x = x + noDataOpts.offsetX;
16523 y = y + parseInt(noDataOpts.style.fontSize, 10) + 2 + noDataOpts.offsetY;
16524 if (noDataOpts.text !== undefined && noDataOpts.text !== '') {
16525 var titleText = graphics.drawText({
16526 x: x,
16527 y: y,
16528 text: noDataOpts.text,
16529 textAnchor: textAnchor,
16530 fontSize: noDataOpts.style.fontSize,
16531 fontFamily: noDataOpts.style.fontFamily,
16532 foreColor: noDataOpts.style.color,
16533 opacity: 1,
16534 class: 'apexcharts-text-nodata'
16535 });
16536 w.globals.dom.Paper.add(titleText);
16537 }
16538 }
16539
16540 // When user clicks on legends, the collapsed series is filled with [0,0,0,...,0]
16541 // This is because we don't want to alter the series' length as it is used at many places
16542 }, {
16543 key: "setNullSeriesToZeroValues",
16544 value: function setNullSeriesToZeroValues(series) {
16545 var w = this.w;
16546 for (var sl = 0; sl < series.length; sl++) {
16547 if (series[sl].length === 0) {
16548 for (var j = 0; j < series[w.globals.maxValsInArrayIndex].length; j++) {
16549 series[sl].push(0);
16550 }
16551 }
16552 }
16553 return series;
16554 }
16555 }, {
16556 key: "hasAllSeriesEqualX",
16557 value: function hasAllSeriesEqualX() {
16558 var equalLen = true;
16559 var w = this.w;
16560 var filteredSerX = this.filteredSeriesX();
16561 for (var i = 0; i < filteredSerX.length - 1; i++) {
16562 if (filteredSerX[i][0] !== filteredSerX[i + 1][0]) {
16563 equalLen = false;
16564 break;
16565 }
16566 }
16567 w.globals.allSeriesHasEqualX = equalLen;
16568 return equalLen;
16569 }
16570 }, {
16571 key: "filteredSeriesX",
16572 value: function filteredSeriesX() {
16573 var w = this.w;
16574 var filteredSeriesX = w.globals.seriesX.map(function (ser) {
16575 return ser.length > 0 ? ser : [];
16576 });
16577 return filteredSeriesX;
16578 }
16579 }]);
16580 return Series;
16581 }();
16582
16583 var Data = /*#__PURE__*/function () {
16584 function Data(ctx) {
16585 _classCallCheck(this, Data);
16586 this.ctx = ctx;
16587 this.w = ctx.w;
16588 this.twoDSeries = [];
16589 this.threeDSeries = [];
16590 this.twoDSeriesX = [];
16591 this.seriesGoals = [];
16592 this.coreUtils = new CoreUtils(this.ctx);
16593 }
16594 _createClass(Data, [{
16595 key: "isMultiFormat",
16596 value: function isMultiFormat() {
16597 return this.isFormatXY() || this.isFormat2DArray();
16598 }
16599
16600 // given format is [{x, y}, {x, y}]
16601 }, {
16602 key: "isFormatXY",
16603 value: function isFormatXY() {
16604 var series = this.w.config.series.slice();
16605 var sr = new Series(this.ctx);
16606 this.activeSeriesIndex = sr.getActiveConfigSeriesIndex();
16607 if (typeof series[this.activeSeriesIndex].data !== 'undefined' && series[this.activeSeriesIndex].data.length > 0 && series[this.activeSeriesIndex].data[0] !== null && typeof series[this.activeSeriesIndex].data[0].x !== 'undefined' && series[this.activeSeriesIndex].data[0] !== null) {
16608 return true;
16609 }
16610 }
16611
16612 // given format is [[x, y], [x, y]]
16613 }, {
16614 key: "isFormat2DArray",
16615 value: function isFormat2DArray() {
16616 var series = this.w.config.series.slice();
16617 var sr = new Series(this.ctx);
16618 this.activeSeriesIndex = sr.getActiveConfigSeriesIndex();
16619 if (typeof series[this.activeSeriesIndex].data !== 'undefined' && series[this.activeSeriesIndex].data.length > 0 && typeof series[this.activeSeriesIndex].data[0] !== 'undefined' && series[this.activeSeriesIndex].data[0] !== null && series[this.activeSeriesIndex].data[0].constructor === Array) {
16620 return true;
16621 }
16622 }
16623 }, {
16624 key: "handleFormat2DArray",
16625 value: function handleFormat2DArray(ser, i) {
16626 var cnf = this.w.config;
16627 var gl = this.w.globals;
16628 var isBoxPlot = cnf.chart.type === 'boxPlot' || cnf.series[i].type === 'boxPlot';
16629 for (var j = 0; j < ser[i].data.length; j++) {
16630 if (typeof ser[i].data[j][1] !== 'undefined') {
16631 if (Array.isArray(ser[i].data[j][1]) && ser[i].data[j][1].length === 4 && !isBoxPlot) {
16632 // candlestick nested ohlc format
16633 this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j][1][3]));
16634 } else if (ser[i].data[j].length >= 5) {
16635 // candlestick non-nested ohlc format
16636 this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j][4]));
16637 } else {
16638 this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j][1]));
16639 }
16640 gl.dataFormatXNumeric = true;
16641 }
16642 if (cnf.xaxis.type === 'datetime') {
16643 // if timestamps are provided and xaxis type is datetime,
16644
16645 var ts = new Date(ser[i].data[j][0]);
16646 ts = new Date(ts).getTime();
16647 this.twoDSeriesX.push(ts);
16648 } else {
16649 this.twoDSeriesX.push(ser[i].data[j][0]);
16650 }
16651 }
16652 for (var _j = 0; _j < ser[i].data.length; _j++) {
16653 if (typeof ser[i].data[_j][2] !== 'undefined') {
16654 this.threeDSeries.push(ser[i].data[_j][2]);
16655 gl.isDataXYZ = true;
16656 }
16657 }
16658 }
16659 }, {
16660 key: "handleFormatXY",
16661 value: function handleFormatXY(ser, i) {
16662 var cnf = this.w.config;
16663 var gl = this.w.globals;
16664 var dt = new DateTime(this.ctx);
16665 var activeI = i;
16666 if (gl.collapsedSeriesIndices.indexOf(i) > -1) {
16667 // fix #368
16668 activeI = this.activeSeriesIndex;
16669 }
16670
16671 // get series
16672 for (var j = 0; j < ser[i].data.length; j++) {
16673 if (typeof ser[i].data[j].y !== 'undefined') {
16674 if (Array.isArray(ser[i].data[j].y)) {
16675 this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j].y[ser[i].data[j].y.length - 1]));
16676 } else {
16677 this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j].y));
16678 }
16679 }
16680 if (typeof ser[i].data[j].goals !== 'undefined' && Array.isArray(ser[i].data[j].goals)) {
16681 if (typeof this.seriesGoals[i] === 'undefined') {
16682 this.seriesGoals[i] = [];
16683 }
16684 this.seriesGoals[i].push(ser[i].data[j].goals);
16685 } else {
16686 if (typeof this.seriesGoals[i] === 'undefined') {
16687 this.seriesGoals[i] = [];
16688 }
16689 this.seriesGoals[i].push(null);
16690 }
16691 }
16692
16693 // get seriesX
16694 for (var _j2 = 0; _j2 < ser[activeI].data.length; _j2++) {
16695 var isXString = typeof ser[activeI].data[_j2].x === 'string';
16696 var isXArr = Array.isArray(ser[activeI].data[_j2].x);
16697 var isXDate = !isXArr && !!dt.isValidDate(ser[activeI].data[_j2].x);
16698 if (isXString || isXDate) {
16699 // user supplied '01/01/2017' or a date string (a JS date object is not supported)
16700 if (isXString || cnf.xaxis.convertedCatToNumeric) {
16701 var isRangeColumn = gl.isBarHorizontal && gl.isRangeData;
16702 if (cnf.xaxis.type === 'datetime' && !isRangeColumn) {
16703 this.twoDSeriesX.push(dt.parseDate(ser[activeI].data[_j2].x));
16704 } else {
16705 // a category and not a numeric x value
16706 this.fallbackToCategory = true;
16707 this.twoDSeriesX.push(ser[activeI].data[_j2].x);
16708 if (!isNaN(ser[activeI].data[_j2].x) && this.w.config.xaxis.type !== 'category' && typeof ser[activeI].data[_j2].x !== 'string') {
16709 gl.isXNumeric = true;
16710 }
16711 }
16712 } else {
16713 if (cnf.xaxis.type === 'datetime') {
16714 this.twoDSeriesX.push(dt.parseDate(ser[activeI].data[_j2].x.toString()));
16715 } else {
16716 gl.dataFormatXNumeric = true;
16717 gl.isXNumeric = true;
16718 this.twoDSeriesX.push(parseFloat(ser[activeI].data[_j2].x));
16719 }
16720 }
16721 } else if (isXArr) {
16722 // a multiline label described in array format
16723 this.fallbackToCategory = true;
16724 this.twoDSeriesX.push(ser[activeI].data[_j2].x);
16725 } else {
16726 // a numeric value in x property
16727 gl.isXNumeric = true;
16728 gl.dataFormatXNumeric = true;
16729 this.twoDSeriesX.push(ser[activeI].data[_j2].x);
16730 }
16731 }
16732 if (ser[i].data[0] && typeof ser[i].data[0].z !== 'undefined') {
16733 for (var t = 0; t < ser[i].data.length; t++) {
16734 this.threeDSeries.push(ser[i].data[t].z);
16735 }
16736 gl.isDataXYZ = true;
16737 }
16738 }
16739 }, {
16740 key: "handleRangeData",
16741 value: function handleRangeData(ser, i) {
16742 var gl = this.w.globals;
16743 var range = {};
16744 if (this.isFormat2DArray()) {
16745 range = this.handleRangeDataFormat('array', ser, i);
16746 } else if (this.isFormatXY()) {
16747 range = this.handleRangeDataFormat('xy', ser, i);
16748 }
16749
16750 // Fix: RangeArea Chart: hide all series results in a crash #3984
16751 gl.seriesRangeStart[i] = range.start === undefined ? [] : range.start;
16752 gl.seriesRangeEnd[i] = range.end === undefined ? [] : range.end;
16753 gl.seriesRange[i] = range.rangeUniques;
16754
16755 // check for overlaps to avoid clashes in a timeline chart
16756 gl.seriesRange.forEach(function (sr, si) {
16757 if (sr) {
16758 sr.forEach(function (sarr, sarri) {
16759 sarr.y.forEach(function (arr, arri) {
16760 for (var sri = 0; sri < sarr.y.length; sri++) {
16761 if (arri !== sri) {
16762 var range1y1 = arr.y1;
16763 var range1y2 = arr.y2;
16764 var range2y1 = sarr.y[sri].y1;
16765 var range2y2 = sarr.y[sri].y2;
16766 if (range1y1 <= range2y2 && range2y1 <= range1y2) {
16767 if (sarr.overlaps.indexOf(arr.rangeName) < 0) {
16768 sarr.overlaps.push(arr.rangeName);
16769 }
16770 if (sarr.overlaps.indexOf(sarr.y[sri].rangeName) < 0) {
16771 sarr.overlaps.push(sarr.y[sri].rangeName);
16772 }
16773 }
16774 }
16775 }
16776 });
16777 });
16778 }
16779 });
16780 return range;
16781 }
16782 }, {
16783 key: "handleCandleStickBoxData",
16784 value: function handleCandleStickBoxData(ser, i) {
16785 var gl = this.w.globals;
16786 var ohlc = {};
16787 if (this.isFormat2DArray()) {
16788 ohlc = this.handleCandleStickBoxDataFormat('array', ser, i);
16789 } else if (this.isFormatXY()) {
16790 ohlc = this.handleCandleStickBoxDataFormat('xy', ser, i);
16791 }
16792 gl.seriesCandleO[i] = ohlc.o;
16793 gl.seriesCandleH[i] = ohlc.h;
16794 gl.seriesCandleM[i] = ohlc.m;
16795 gl.seriesCandleL[i] = ohlc.l;
16796 gl.seriesCandleC[i] = ohlc.c;
16797 return ohlc;
16798 }
16799 }, {
16800 key: "handleRangeDataFormat",
16801 value: function handleRangeDataFormat(format, ser, i) {
16802 var rangeStart = [];
16803 var rangeEnd = [];
16804 var uniqueKeys = ser[i].data.filter(function (thing, index, self) {
16805 return index === self.findIndex(function (t) {
16806 return t.x === thing.x;
16807 });
16808 }).map(function (r, index) {
16809 return {
16810 x: r.x,
16811 overlaps: [],
16812 y: []
16813 };
16814 });
16815 if (format === 'array') {
16816 for (var j = 0; j < ser[i].data.length; j++) {
16817 if (Array.isArray(ser[i].data[j])) {
16818 rangeStart.push(ser[i].data[j][1][0]);
16819 rangeEnd.push(ser[i].data[j][1][1]);
16820 } else {
16821 rangeStart.push(ser[i].data[j]);
16822 rangeEnd.push(ser[i].data[j]);
16823 }
16824 }
16825 } else if (format === 'xy') {
16826 var _loop = function _loop(_j3) {
16827 var isDataPoint2D = Array.isArray(ser[i].data[_j3].y);
16828 var id = Utils$1.randomId();
16829 var x = ser[i].data[_j3].x;
16830 var y = {
16831 y1: isDataPoint2D ? ser[i].data[_j3].y[0] : ser[i].data[_j3].y,
16832 y2: isDataPoint2D ? ser[i].data[_j3].y[1] : ser[i].data[_j3].y,
16833 rangeName: id
16834 };
16835
16836 // CAUTION: mutating config object by adding a new property
16837 // TODO: As this is specifically for timeline rangebar charts, update the docs mentioning the series only supports xy format
16838 ser[i].data[_j3].rangeName = id;
16839 var uI = uniqueKeys.findIndex(function (t) {
16840 return t.x === x;
16841 });
16842 uniqueKeys[uI].y.push(y);
16843 rangeStart.push(y.y1);
16844 rangeEnd.push(y.y2);
16845 };
16846 for (var _j3 = 0; _j3 < ser[i].data.length; _j3++) {
16847 _loop(_j3);
16848 }
16849 }
16850 return {
16851 start: rangeStart,
16852 end: rangeEnd,
16853 rangeUniques: uniqueKeys
16854 };
16855 }
16856 }, {
16857 key: "handleCandleStickBoxDataFormat",
16858 value: function handleCandleStickBoxDataFormat(format, ser, i) {
16859 var w = this.w;
16860 var isBoxPlot = w.config.chart.type === 'boxPlot' || w.config.series[i].type === 'boxPlot';
16861 var serO = [];
16862 var serH = [];
16863 var serM = [];
16864 var serL = [];
16865 var serC = [];
16866 if (format === 'array') {
16867 if (isBoxPlot && ser[i].data[0].length === 6 || !isBoxPlot && ser[i].data[0].length === 5) {
16868 for (var j = 0; j < ser[i].data.length; j++) {
16869 serO.push(ser[i].data[j][1]);
16870 serH.push(ser[i].data[j][2]);
16871 if (isBoxPlot) {
16872 serM.push(ser[i].data[j][3]);
16873 serL.push(ser[i].data[j][4]);
16874 serC.push(ser[i].data[j][5]);
16875 } else {
16876 serL.push(ser[i].data[j][3]);
16877 serC.push(ser[i].data[j][4]);
16878 }
16879 }
16880 } else {
16881 for (var _j4 = 0; _j4 < ser[i].data.length; _j4++) {
16882 if (Array.isArray(ser[i].data[_j4][1])) {
16883 serO.push(ser[i].data[_j4][1][0]);
16884 serH.push(ser[i].data[_j4][1][1]);
16885 if (isBoxPlot) {
16886 serM.push(ser[i].data[_j4][1][2]);
16887 serL.push(ser[i].data[_j4][1][3]);
16888 serC.push(ser[i].data[_j4][1][4]);
16889 } else {
16890 serL.push(ser[i].data[_j4][1][2]);
16891 serC.push(ser[i].data[_j4][1][3]);
16892 }
16893 }
16894 }
16895 }
16896 } else if (format === 'xy') {
16897 for (var _j5 = 0; _j5 < ser[i].data.length; _j5++) {
16898 if (Array.isArray(ser[i].data[_j5].y)) {
16899 serO.push(ser[i].data[_j5].y[0]);
16900 serH.push(ser[i].data[_j5].y[1]);
16901 if (isBoxPlot) {
16902 serM.push(ser[i].data[_j5].y[2]);
16903 serL.push(ser[i].data[_j5].y[3]);
16904 serC.push(ser[i].data[_j5].y[4]);
16905 } else {
16906 serL.push(ser[i].data[_j5].y[2]);
16907 serC.push(ser[i].data[_j5].y[3]);
16908 }
16909 }
16910 }
16911 }
16912 return {
16913 o: serO,
16914 h: serH,
16915 m: serM,
16916 l: serL,
16917 c: serC
16918 };
16919 }
16920 }, {
16921 key: "parseDataAxisCharts",
16922 value: function parseDataAxisCharts(ser) {
16923 var _this = this;
16924 var ctx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.ctx;
16925 var cnf = this.w.config;
16926 var gl = this.w.globals;
16927 var dt = new DateTime(ctx);
16928 var xlabels = cnf.labels.length > 0 ? cnf.labels.slice() : cnf.xaxis.categories.slice();
16929 gl.isRangeBar = cnf.chart.type === 'rangeBar' && gl.isBarHorizontal;
16930 gl.hasXaxisGroups = cnf.xaxis.type === 'category' && cnf.xaxis.group.groups.length > 0;
16931 if (gl.hasXaxisGroups) {
16932 gl.groups = cnf.xaxis.group.groups;
16933 }
16934 ser.forEach(function (s, i) {
16935 if (s.name !== undefined) {
16936 gl.seriesNames.push(s.name);
16937 } else {
16938 gl.seriesNames.push('series-' + parseInt(i + 1, 10));
16939 }
16940 });
16941 this.coreUtils.setSeriesYAxisMappings();
16942 // At this point, every series that didn't have a user defined group name
16943 // has been given a name according to the yaxis the series is referenced by.
16944 // This fits the existing behaviour where all series associated with an axis
16945 // are defacto presented as a single group. It is now formalised.
16946 var buckets = [];
16947 var groups = _toConsumableArray(new Set(cnf.series.map(function (s) {
16948 return s.group;
16949 })));
16950 cnf.series.forEach(function (s, i) {
16951 var index = groups.indexOf(s.group);
16952 if (!buckets[index]) buckets[index] = [];
16953 buckets[index].push(gl.seriesNames[i]);
16954 });
16955 gl.seriesGroups = buckets;
16956 var handleDates = function handleDates() {
16957 for (var j = 0; j < xlabels.length; j++) {
16958 if (typeof xlabels[j] === 'string') {
16959 // user provided date strings
16960 var isDate = dt.isValidDate(xlabels[j]);
16961 if (isDate) {
16962 _this.twoDSeriesX.push(dt.parseDate(xlabels[j]));
16963 } else {
16964 throw new Error('You have provided invalid Date format. Please provide a valid JavaScript Date');
16965 }
16966 } else {
16967 // user provided timestamps
16968 _this.twoDSeriesX.push(xlabels[j]);
16969 }
16970 }
16971 };
16972 for (var i = 0; i < ser.length; i++) {
16973 this.twoDSeries = [];
16974 this.twoDSeriesX = [];
16975 this.threeDSeries = [];
16976 if (typeof ser[i].data === 'undefined') {
16977 console.error("It is a possibility that you may have not included 'data' property in series.");
16978 return;
16979 }
16980 if (cnf.chart.type === 'rangeBar' || cnf.chart.type === 'rangeArea' || ser[i].type === 'rangeBar' || ser[i].type === 'rangeArea') {
16981 gl.isRangeData = true;
16982 this.handleRangeData(ser, i);
16983 }
16984 if (this.isMultiFormat()) {
16985 if (this.isFormat2DArray()) {
16986 this.handleFormat2DArray(ser, i);
16987 } else if (this.isFormatXY()) {
16988 this.handleFormatXY(ser, i);
16989 }
16990 if (cnf.chart.type === 'candlestick' || ser[i].type === 'candlestick' || cnf.chart.type === 'boxPlot' || ser[i].type === 'boxPlot') {
16991 this.handleCandleStickBoxData(ser, i);
16992 }
16993 gl.series.push(this.twoDSeries);
16994 gl.labels.push(this.twoDSeriesX);
16995 gl.seriesX.push(this.twoDSeriesX);
16996 gl.seriesGoals = this.seriesGoals;
16997 if (i === this.activeSeriesIndex && !this.fallbackToCategory) {
16998 gl.isXNumeric = true;
16999 }
17000 } else {
17001 if (cnf.xaxis.type === 'datetime') {
17002 // user didn't supplied [{x,y}] or [[x,y]], but single array in data.
17003 // Also labels/categories were supplied differently
17004 gl.isXNumeric = true;
17005 handleDates();
17006 gl.seriesX.push(this.twoDSeriesX);
17007 } else if (cnf.xaxis.type === 'numeric') {
17008 gl.isXNumeric = true;
17009 if (xlabels.length > 0) {
17010 this.twoDSeriesX = xlabels;
17011 gl.seriesX.push(this.twoDSeriesX);
17012 }
17013 }
17014 gl.labels.push(this.twoDSeriesX);
17015 var singleArray = ser[i].data.map(function (d) {
17016 return Utils$1.parseNumber(d);
17017 });
17018 gl.series.push(singleArray);
17019 }
17020 gl.seriesZ.push(this.threeDSeries);
17021
17022 // overrided default color if user inputs color with series data
17023 if (ser[i].color !== undefined) {
17024 gl.seriesColors.push(ser[i].color);
17025 } else {
17026 gl.seriesColors.push(undefined);
17027 }
17028 }
17029 return this.w;
17030 }
17031 }, {
17032 key: "parseDataNonAxisCharts",
17033 value: function parseDataNonAxisCharts(ser) {
17034 var gl = this.w.globals;
17035 var cnf = this.w.config;
17036 gl.series = ser.slice();
17037 gl.seriesNames = cnf.labels.slice();
17038 for (var i = 0; i < gl.series.length; i++) {
17039 if (gl.seriesNames[i] === undefined) {
17040 gl.seriesNames.push('series-' + (i + 1));
17041 }
17042 }
17043 return this.w;
17044 }
17045
17046 /** User possibly set string categories in xaxis.categories or labels prop
17047 * Or didn't set xaxis labels at all - in which case we manually do it.
17048 * If user passed series data as [[3, 2], [4, 5]] or [{ x: 3, y: 55 }],
17049 * this shouldn't be called
17050 * @param {array} ser - the series which user passed to the config
17051 */
17052 }, {
17053 key: "handleExternalLabelsData",
17054 value: function handleExternalLabelsData(ser) {
17055 var cnf = this.w.config;
17056 var gl = this.w.globals;
17057 if (cnf.xaxis.categories.length > 0) {
17058 // user provided labels in xaxis.category prop
17059 gl.labels = cnf.xaxis.categories;
17060 } else if (cnf.labels.length > 0) {
17061 // user provided labels in labels props
17062 gl.labels = cnf.labels.slice();
17063 } else if (this.fallbackToCategory) {
17064 // user provided labels in x prop in [{ x: 3, y: 55 }] data, and those labels are already stored in gl.labels[0], so just re-arrange the gl.labels array
17065 gl.labels = gl.labels[0];
17066 if (gl.seriesRange.length) {
17067 gl.seriesRange.map(function (srt) {
17068 srt.forEach(function (sr) {
17069 if (gl.labels.indexOf(sr.x) < 0 && sr.x) {
17070 gl.labels.push(sr.x);
17071 }
17072 });
17073 });
17074 // remove duplicate x-axis labels
17075 gl.labels = Array.from(new Set(gl.labels.map(JSON.stringify)), JSON.parse);
17076 }
17077 if (cnf.xaxis.convertedCatToNumeric) {
17078 var defaults = new Defaults(cnf);
17079 defaults.convertCatToNumericXaxis(cnf, this.ctx, gl.seriesX[0]);
17080 this._generateExternalLabels(ser);
17081 }
17082 } else {
17083 this._generateExternalLabels(ser);
17084 }
17085 }
17086 }, {
17087 key: "_generateExternalLabels",
17088 value: function _generateExternalLabels(ser) {
17089 var gl = this.w.globals;
17090 var cnf = this.w.config;
17091 // user didn't provided any labels, fallback to 1-2-3-4-5
17092 var labelArr = [];
17093 if (gl.axisCharts) {
17094 if (gl.series.length > 0) {
17095 if (this.isFormatXY()) {
17096 // in case there is a combo chart (boxplot/scatter)
17097 // and there are duplicated x values, we need to eliminate duplicates
17098 var seriesDataFiltered = cnf.series.map(function (serie, s) {
17099 return serie.data.filter(function (v, i, a) {
17100 return a.findIndex(function (t) {
17101 return t.x === v.x;
17102 }) === i;
17103 });
17104 });
17105 var len = seriesDataFiltered.reduce(function (p, c, i, a) {
17106 return a[p].length > c.length ? p : i;
17107 }, 0);
17108 for (var i = 0; i < seriesDataFiltered[len].length; i++) {
17109 labelArr.push(i + 1);
17110 }
17111 } else {
17112 for (var _i = 0; _i < gl.series[gl.maxValsInArrayIndex].length; _i++) {
17113 labelArr.push(_i + 1);
17114 }
17115 }
17116 }
17117 gl.seriesX = [];
17118 // create gl.seriesX as it will be used in calculations of x positions
17119 for (var _i2 = 0; _i2 < ser.length; _i2++) {
17120 gl.seriesX.push(labelArr);
17121 }
17122
17123 // turn on the isXNumeric flag to allow minX and maxX to function properly
17124 if (!this.w.globals.isBarHorizontal) {
17125 gl.isXNumeric = true;
17126 }
17127 }
17128
17129 // no series to pull labels from, put a 0-10 series
17130 // possibly, user collapsed all series. Hence we can't work with above calc
17131 if (labelArr.length === 0) {
17132 labelArr = gl.axisCharts ? [] : gl.series.map(function (gls, glsi) {
17133 return glsi + 1;
17134 });
17135 for (var _i3 = 0; _i3 < ser.length; _i3++) {
17136 gl.seriesX.push(labelArr);
17137 }
17138 }
17139
17140 // Finally, pass the labelArr in gl.labels which will be printed on x-axis
17141 gl.labels = labelArr;
17142 if (cnf.xaxis.convertedCatToNumeric) {
17143 gl.categoryLabels = labelArr.map(function (l) {
17144 return cnf.xaxis.labels.formatter(l);
17145 });
17146 }
17147
17148 // Turn on this global flag to indicate no labels were provided by user
17149 gl.noLabelsProvided = true;
17150 }
17151
17152 // Segregate user provided data into appropriate vars
17153 }, {
17154 key: "parseData",
17155 value: function parseData(ser) {
17156 var w = this.w;
17157 var cnf = w.config;
17158 var gl = w.globals;
17159 this.excludeCollapsedSeriesInYAxis();
17160
17161 // If we detected string in X prop of series, we fallback to category x-axis
17162 this.fallbackToCategory = false;
17163 this.ctx.core.resetGlobals();
17164 this.ctx.core.isMultipleY();
17165 if (gl.axisCharts) {
17166 // axisCharts includes line / area / column / scatter
17167 this.parseDataAxisCharts(ser);
17168 this.coreUtils.getLargestSeries();
17169 } else {
17170 // non-axis charts are pie / donut
17171 this.parseDataNonAxisCharts(ser);
17172 }
17173
17174 // set Null values to 0 in all series when user hides/shows some series
17175 if (cnf.chart.stacked) {
17176 var series = new Series(this.ctx);
17177 gl.series = series.setNullSeriesToZeroValues(gl.series);
17178 }
17179 this.coreUtils.getSeriesTotals();
17180 if (gl.axisCharts) {
17181 gl.stackedSeriesTotals = this.coreUtils.getStackedSeriesTotals();
17182 gl.stackedSeriesTotalsByGroups = this.coreUtils.getStackedSeriesTotalsByGroups();
17183 }
17184 this.coreUtils.getPercentSeries();
17185 if (!gl.dataFormatXNumeric && (!gl.isXNumeric || cnf.xaxis.type === 'numeric' && cnf.labels.length === 0 && cnf.xaxis.categories.length === 0)) {
17186 // x-axis labels couldn't be detected; hence try searching every option in config
17187 this.handleExternalLabelsData(ser);
17188 }
17189
17190 // check for multiline xaxis
17191 var catLabels = this.coreUtils.getCategoryLabels(gl.labels);
17192 for (var l = 0; l < catLabels.length; l++) {
17193 if (Array.isArray(catLabels[l])) {
17194 gl.isMultiLineX = true;
17195 break;
17196 }
17197 }
17198 }
17199 }, {
17200 key: "excludeCollapsedSeriesInYAxis",
17201 value: function excludeCollapsedSeriesInYAxis() {
17202 var w = this.w;
17203 // Post revision 3.46.0 there is no longer a strict one-to-one
17204 // correspondence between series and Y axes.
17205 // An axis can be ignored only while all series referenced by it
17206 // are collapsed.
17207 var yAxisIndexes = [];
17208 w.globals.seriesYAxisMap.forEach(function (yAxisArr, yi) {
17209 var collapsedCount = 0;
17210 yAxisArr.forEach(function (seriesIndex) {
17211 if (w.globals.collapsedSeriesIndices.indexOf(seriesIndex) !== -1) {
17212 collapsedCount++;
17213 }
17214 });
17215 // It's possible to have a yaxis that doesn't reference any series yet,
17216 // eg, because there are no series' yet, so don't list it as ignored
17217 // prematurely.
17218 if (collapsedCount > 0 && collapsedCount == yAxisArr.length) {
17219 yAxisIndexes.push(yi);
17220 }
17221 });
17222 w.globals.ignoreYAxisIndexes = yAxisIndexes.map(function (x) {
17223 return x;
17224 });
17225 }
17226 }]);
17227 return Data;
17228 }();
17229
17230 var Exports = /*#__PURE__*/function () {
17231 function Exports(ctx) {
17232 _classCallCheck(this, Exports);
17233 this.ctx = ctx;
17234 this.w = ctx.w;
17235 }
17236 _createClass(Exports, [{
17237 key: "svgStringToNode",
17238 value: function svgStringToNode(svgString) {
17239 var parser = new DOMParser();
17240 var svgDoc = parser.parseFromString(svgString, 'image/svg+xml');
17241 return svgDoc.documentElement;
17242 }
17243 }, {
17244 key: "scaleSvgNode",
17245 value: function scaleSvgNode(svg, scale) {
17246 // get current both width and height of the svg
17247 var svgWidth = parseFloat(svg.getAttributeNS(null, 'width'));
17248 var svgHeight = parseFloat(svg.getAttributeNS(null, 'height'));
17249 // set new width and height based on the scale
17250 svg.setAttributeNS(null, 'width', svgWidth * scale);
17251 svg.setAttributeNS(null, 'height', svgHeight * scale);
17252 svg.setAttributeNS(null, 'viewBox', '0 0 ' + svgWidth + ' ' + svgHeight);
17253 }
17254 }, {
17255 key: "getSvgString",
17256 value: function getSvgString(_scale) {
17257 var _this = this;
17258 return new Promise(function (resolve) {
17259 var w = _this.w;
17260 var scale = _scale || w.config.chart.toolbar.export.scale || w.config.chart.toolbar.export.width / w.globals.svgWidth;
17261 if (!scale) {
17262 scale = 1; // if no scale is specified, don't scale...
17263 }
17264 var width = w.globals.svgWidth * scale;
17265 var height = w.globals.svgHeight * scale;
17266 var clonedNode = w.globals.dom.elWrap.cloneNode(true);
17267 clonedNode.style.width = width + 'px';
17268 clonedNode.style.height = height + 'px';
17269 var serializedNode = new XMLSerializer().serializeToString(clonedNode);
17270 var svgString = "\n <svg xmlns=\"http://www.w3.org/2000/svg\"\n version=\"1.1\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n class=\"apexcharts-svg\"\n xmlns:data=\"ApexChartsNS\"\n transform=\"translate(0, 0)\"\n width=\"".concat(w.globals.svgWidth, "px\" height=\"").concat(w.globals.svgHeight, "px\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"width:").concat(width, "px; height:").concat(height, "px;\">\n <style type=\"text/css\">\n .apexcharts-tooltip, .apexcharts-toolbar, .apexcharts-xaxistooltip, .apexcharts-yaxistooltip, .apexcharts-xcrosshairs, .apexcharts-ycrosshairs, .apexcharts-zoom-rect, .apexcharts-selection-rect {\n display: none;\n }\n </style>\n ").concat(serializedNode, "\n </div>\n </foreignObject>\n </svg>\n ");
17271 var svgNode = _this.svgStringToNode(svgString);
17272 if (scale !== 1) {
17273 // scale the image
17274 _this.scaleSvgNode(svgNode, scale);
17275 }
17276 _this.convertImagesToBase64(svgNode).then(function () {
17277 svgString = new XMLSerializer().serializeToString(svgNode);
17278 resolve(svgString.replace(/&nbsp;/g, '&#160;'));
17279 });
17280 });
17281 }
17282 }, {
17283 key: "convertImagesToBase64",
17284 value: function convertImagesToBase64(svgNode) {
17285 var _this2 = this;
17286 var images = svgNode.getElementsByTagName('image');
17287 var promises = Array.from(images).map(function (img) {
17288 var href = img.getAttributeNS('http://www.w3.org/1999/xlink', 'href');
17289 if (href && !href.startsWith('data:')) {
17290 return _this2.getBase64FromUrl(href).then(function (base64) {
17291 img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', base64);
17292 }).catch(function (error) {
17293 console.error('Error converting image to base64:', error);
17294 });
17295 }
17296 return Promise.resolve();
17297 });
17298 return Promise.all(promises);
17299 }
17300 }, {
17301 key: "getBase64FromUrl",
17302 value: function getBase64FromUrl(url) {
17303 return new Promise(function (resolve, reject) {
17304 var img = new Image();
17305 img.crossOrigin = 'Anonymous';
17306 img.onload = function () {
17307 var canvas = document.createElement('canvas');
17308 canvas.width = img.width;
17309 canvas.height = img.height;
17310 var ctx = canvas.getContext('2d');
17311 ctx.drawImage(img, 0, 0);
17312 resolve(canvas.toDataURL());
17313 };
17314 img.onerror = reject;
17315 img.src = url;
17316 });
17317 }
17318 }, {
17319 key: "svgUrl",
17320 value: function svgUrl() {
17321 var _this3 = this;
17322 return new Promise(function (resolve) {
17323 _this3.getSvgString().then(function (svgData) {
17324 var svgBlob = new Blob([svgData], {
17325 type: 'image/svg+xml;charset=utf-8'
17326 });
17327 resolve(URL.createObjectURL(svgBlob));
17328 });
17329 });
17330 }
17331 }, {
17332 key: "dataURI",
17333 value: function dataURI(options) {
17334 var _this4 = this;
17335 return new Promise(function (resolve) {
17336 var w = _this4.w;
17337 var scale = options ? options.scale || options.width / w.globals.svgWidth : 1;
17338 var canvas = document.createElement('canvas');
17339 canvas.width = w.globals.svgWidth * scale;
17340 canvas.height = parseInt(w.globals.dom.elWrap.style.height, 10) * scale; // because of resizeNonAxisCharts
17341
17342 var canvasBg = w.config.chart.background === 'transparent' || !w.config.chart.background ? '#fff' : w.config.chart.background;
17343 var ctx = canvas.getContext('2d');
17344 ctx.fillStyle = canvasBg;
17345 ctx.fillRect(0, 0, canvas.width * scale, canvas.height * scale);
17346 _this4.getSvgString(scale).then(function (svgData) {
17347 var svgUrl = 'data:image/svg+xml,' + encodeURIComponent(svgData);
17348 var img = new Image();
17349 img.crossOrigin = 'anonymous';
17350 img.onload = function () {
17351 ctx.drawImage(img, 0, 0);
17352 if (canvas.msToBlob) {
17353 // Microsoft Edge can't navigate to data urls, so we return the blob instead
17354 var blob = canvas.msToBlob();
17355 resolve({
17356 blob: blob
17357 });
17358 } else {
17359 var imgURI = canvas.toDataURL('image/png');
17360 resolve({
17361 imgURI: imgURI
17362 });
17363 }
17364 };
17365 img.src = svgUrl;
17366 });
17367 });
17368 }
17369 }, {
17370 key: "exportToSVG",
17371 value: function exportToSVG() {
17372 var _this5 = this;
17373 this.svgUrl().then(function (url) {
17374 _this5.triggerDownload(url, _this5.w.config.chart.toolbar.export.svg.filename, '.svg');
17375 });
17376 }
17377 }, {
17378 key: "exportToPng",
17379 value: function exportToPng() {
17380 var _this6 = this;
17381 var scale = this.w.config.chart.toolbar.export.scale;
17382 var width = this.w.config.chart.toolbar.export.width;
17383 var option = scale ? {
17384 scale: scale
17385 } : width ? {
17386 width: width
17387 } : undefined;
17388 this.dataURI(option).then(function (_ref) {
17389 var imgURI = _ref.imgURI,
17390 blob = _ref.blob;
17391 if (blob) {
17392 navigator.msSaveOrOpenBlob(blob, _this6.w.globals.chartID + '.png');
17393 } else {
17394 _this6.triggerDownload(imgURI, _this6.w.config.chart.toolbar.export.png.filename, '.png');
17395 }
17396 });
17397 }
17398 }, {
17399 key: "exportToCSV",
17400 value: function exportToCSV(_ref2) {
17401 var _this7 = this;
17402 var series = _ref2.series,
17403 fileName = _ref2.fileName,
17404 _ref2$columnDelimiter = _ref2.columnDelimiter,
17405 columnDelimiter = _ref2$columnDelimiter === void 0 ? ',' : _ref2$columnDelimiter,
17406 _ref2$lineDelimiter = _ref2.lineDelimiter,
17407 lineDelimiter = _ref2$lineDelimiter === void 0 ? '\n' : _ref2$lineDelimiter;
17408 var w = this.w;
17409 if (!series) series = w.config.series;
17410 var columns = [];
17411 var rows = [];
17412 var result = '';
17413 var universalBOM = "\uFEFF";
17414 var gSeries = w.globals.series.map(function (s, i) {
17415 return w.globals.collapsedSeriesIndices.indexOf(i) === -1 ? s : [];
17416 });
17417 var getFormattedCategory = function getFormattedCategory(cat) {
17418 if (typeof w.config.chart.toolbar.export.csv.categoryFormatter === 'function') {
17419 return w.config.chart.toolbar.export.csv.categoryFormatter(cat);
17420 }
17421 if (w.config.xaxis.type === 'datetime' && String(cat).length >= 10) {
17422 return new Date(cat).toDateString();
17423 }
17424 return Utils$1.isNumber(cat) ? cat : cat.split(columnDelimiter).join('');
17425 };
17426 var getFormattedValue = function getFormattedValue(value) {
17427 return typeof w.config.chart.toolbar.export.csv.valueFormatter === 'function' ? w.config.chart.toolbar.export.csv.valueFormatter(value) : value;
17428 };
17429 var seriesMaxDataLength = Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
17430 return s.data ? s.data.length : 0;
17431 })));
17432 var dataFormat = new Data(this.ctx);
17433 var axesUtils = new AxesUtils(this.ctx);
17434 var getCat = function getCat(i) {
17435 var cat = '';
17436
17437 // pie / donut/ radial
17438 if (!w.globals.axisCharts) {
17439 cat = w.config.labels[i];
17440 } else {
17441 // xy charts
17442
17443 // non datetime
17444 if (w.config.xaxis.type === 'category' || w.config.xaxis.convertedCatToNumeric) {
17445 if (w.globals.isBarHorizontal) {
17446 var lbFormatter = w.globals.yLabelFormatters[0];
17447 var sr = new Series(_this7.ctx);
17448 var activeSeries = sr.getActiveConfigSeriesIndex();
17449 cat = lbFormatter(w.globals.labels[i], {
17450 seriesIndex: activeSeries,
17451 dataPointIndex: i,
17452 w: w
17453 });
17454 } else {
17455 cat = axesUtils.getLabel(w.globals.labels, w.globals.timescaleLabels, 0, i).text;
17456 }
17457 }
17458
17459 // datetime, but labels specified in categories or labels
17460 if (w.config.xaxis.type === 'datetime') {
17461 if (w.config.xaxis.categories.length) {
17462 cat = w.config.xaxis.categories[i];
17463 } else if (w.config.labels.length) {
17464 cat = w.config.labels[i];
17465 }
17466 }
17467 }
17468
17469 // let the caller know the current category is null. this can happen for example
17470 // when dealing with line charts having inconsistent time series data
17471 if (cat === null) return 'nullvalue';
17472 if (Array.isArray(cat)) {
17473 cat = cat.join(' ');
17474 }
17475 return Utils$1.isNumber(cat) ? cat : cat.split(columnDelimiter).join('');
17476 };
17477
17478 // Fix https://github.com/apexcharts/apexcharts.js/issues/3365
17479 var getEmptyDataForCsvColumn = function getEmptyDataForCsvColumn() {
17480 return _toConsumableArray(Array(seriesMaxDataLength)).map(function () {
17481 return '';
17482 });
17483 };
17484 var handleAxisRowsColumns = function handleAxisRowsColumns(s, sI) {
17485 if (columns.length && sI === 0) {
17486 // It's the first series. Go ahead and create the first row with header information.
17487 rows.push(columns.join(columnDelimiter));
17488 }
17489 if (s.data) {
17490 // Use the data we have, or generate a properly sized empty array with empty data if some data is missing.
17491 s.data = s.data.length && s.data || getEmptyDataForCsvColumn();
17492 for (var i = 0; i < s.data.length; i++) {
17493 // Reset the columns array so that we can start building columns for this row.
17494 columns = [];
17495 var cat = getCat(i);
17496
17497 // current category is null, let's move on to the next one
17498 if (cat === 'nullvalue') continue;
17499 if (!cat) {
17500 if (dataFormat.isFormatXY()) {
17501 cat = series[sI].data[i].x;
17502 } else if (dataFormat.isFormat2DArray()) {
17503 cat = series[sI].data[i] ? series[sI].data[i][0] : '';
17504 }
17505 }
17506 if (sI === 0) {
17507 // It's the first series. Also handle the category.
17508 columns.push(getFormattedCategory(cat));
17509 for (var ci = 0; ci < w.globals.series.length; ci++) {
17510 var _series$ci$data$i;
17511 var value = dataFormat.isFormatXY() ? (_series$ci$data$i = series[ci].data[i]) === null || _series$ci$data$i === void 0 ? void 0 : _series$ci$data$i.y : gSeries[ci][i];
17512 columns.push(getFormattedValue(value));
17513 }
17514 }
17515 if (w.config.chart.type === 'candlestick' || s.type && s.type === 'candlestick') {
17516 columns.pop();
17517 columns.push(w.globals.seriesCandleO[sI][i]);
17518 columns.push(w.globals.seriesCandleH[sI][i]);
17519 columns.push(w.globals.seriesCandleL[sI][i]);
17520 columns.push(w.globals.seriesCandleC[sI][i]);
17521 }
17522 if (w.config.chart.type === 'boxPlot' || s.type && s.type === 'boxPlot') {
17523 columns.pop();
17524 columns.push(w.globals.seriesCandleO[sI][i]);
17525 columns.push(w.globals.seriesCandleH[sI][i]);
17526 columns.push(w.globals.seriesCandleM[sI][i]);
17527 columns.push(w.globals.seriesCandleL[sI][i]);
17528 columns.push(w.globals.seriesCandleC[sI][i]);
17529 }
17530 if (w.config.chart.type === 'rangeBar') {
17531 columns.pop();
17532 columns.push(w.globals.seriesRangeStart[sI][i]);
17533 columns.push(w.globals.seriesRangeEnd[sI][i]);
17534 }
17535 if (columns.length) {
17536 rows.push(columns.join(columnDelimiter));
17537 }
17538 }
17539 }
17540 };
17541 var handleUnequalXValues = function handleUnequalXValues() {
17542 var categories = new Set();
17543 var data = {};
17544 series.forEach(function (s, sI) {
17545 s === null || s === void 0 ? void 0 : s.data.forEach(function (dataItem) {
17546 var cat, value;
17547 if (dataFormat.isFormatXY()) {
17548 cat = dataItem.x;
17549 value = dataItem.y;
17550 } else if (dataFormat.isFormat2DArray()) {
17551 cat = dataItem[0];
17552 value = dataItem[1];
17553 } else {
17554 return;
17555 }
17556 if (!data[cat]) {
17557 data[cat] = Array(series.length).fill('');
17558 }
17559 data[cat][sI] = getFormattedValue(value);
17560 categories.add(cat);
17561 });
17562 });
17563 if (columns.length) {
17564 rows.push(columns.join(columnDelimiter));
17565 }
17566 Array.from(categories).sort().forEach(function (cat) {
17567 rows.push([getFormattedCategory(cat), data[cat].join(columnDelimiter)]);
17568 });
17569 };
17570 columns.push(w.config.chart.toolbar.export.csv.headerCategory);
17571 if (w.config.chart.type === 'boxPlot') {
17572 columns.push('minimum');
17573 columns.push('q1');
17574 columns.push('median');
17575 columns.push('q3');
17576 columns.push('maximum');
17577 } else if (w.config.chart.type === 'candlestick') {
17578 columns.push('open');
17579 columns.push('high');
17580 columns.push('low');
17581 columns.push('close');
17582 } else if (w.config.chart.type === 'rangeBar') {
17583 columns.push('minimum');
17584 columns.push('maximum');
17585 } else {
17586 series.map(function (s, sI) {
17587 var sname = (s.name ? s.name : "series-".concat(sI)) + '';
17588 if (w.globals.axisCharts) {
17589 columns.push(sname.split(columnDelimiter).join('') ? sname.split(columnDelimiter).join('') : "series-".concat(sI));
17590 }
17591 });
17592 }
17593 if (!w.globals.axisCharts) {
17594 columns.push(w.config.chart.toolbar.export.csv.headerValue);
17595 rows.push(columns.join(columnDelimiter));
17596 }
17597 if (!w.globals.allSeriesHasEqualX && w.globals.axisCharts && !w.config.xaxis.categories.length && !w.config.labels.length) {
17598 handleUnequalXValues();
17599 } else {
17600 series.map(function (s, sI) {
17601 if (w.globals.axisCharts) {
17602 handleAxisRowsColumns(s, sI);
17603 } else {
17604 columns = [];
17605 columns.push(getFormattedCategory(w.globals.labels[sI]));
17606 columns.push(getFormattedValue(gSeries[sI]));
17607 rows.push(columns.join(columnDelimiter));
17608 }
17609 });
17610 }
17611 result += rows.join(lineDelimiter);
17612 this.triggerDownload('data:text/csv; charset=utf-8,' + encodeURIComponent(universalBOM + result), fileName ? fileName : w.config.chart.toolbar.export.csv.filename, '.csv');
17613 }
17614 }, {
17615 key: "triggerDownload",
17616 value: function triggerDownload(href, filename, ext) {
17617 var downloadLink = document.createElement('a');
17618 downloadLink.href = href;
17619 downloadLink.download = (filename ? filename : this.w.globals.chartID) + ext;
17620 document.body.appendChild(downloadLink);
17621 downloadLink.click();
17622 document.body.removeChild(downloadLink);
17623 }
17624 }]);
17625 return Exports;
17626 }();
17627
17628 /**
17629 * ApexCharts XAxis Class for drawing X-Axis.
17630 *
17631 * @module XAxis
17632 **/
17633 var XAxis = /*#__PURE__*/function () {
17634 function XAxis(ctx, elgrid) {
17635 _classCallCheck(this, XAxis);
17636 this.ctx = ctx;
17637 this.elgrid = elgrid;
17638 this.w = ctx.w;
17639 var w = this.w;
17640 this.axesUtils = new AxesUtils(ctx);
17641 this.xaxisLabels = w.globals.labels.slice();
17642 if (w.globals.timescaleLabels.length > 0 && !w.globals.isBarHorizontal) {
17643 // timeline labels are there and chart is not rangeabr timeline
17644 this.xaxisLabels = w.globals.timescaleLabels.slice();
17645 }
17646 if (w.config.xaxis.overwriteCategories) {
17647 this.xaxisLabels = w.config.xaxis.overwriteCategories;
17648 }
17649 this.drawnLabels = [];
17650 this.drawnLabelsRects = [];
17651 if (w.config.xaxis.position === 'top') {
17652 this.offY = 0;
17653 } else {
17654 this.offY = w.globals.gridHeight;
17655 }
17656 this.offY = this.offY + w.config.xaxis.axisBorder.offsetY;
17657 this.isCategoryBarHorizontal = w.config.chart.type === 'bar' && w.config.plotOptions.bar.horizontal;
17658 this.xaxisFontSize = w.config.xaxis.labels.style.fontSize;
17659 this.xaxisFontFamily = w.config.xaxis.labels.style.fontFamily;
17660 this.xaxisForeColors = w.config.xaxis.labels.style.colors;
17661 this.xaxisBorderWidth = w.config.xaxis.axisBorder.width;
17662 if (this.isCategoryBarHorizontal) {
17663 this.xaxisBorderWidth = w.config.yaxis[0].axisBorder.width.toString();
17664 }
17665 if (this.xaxisBorderWidth.indexOf('%') > -1) {
17666 this.xaxisBorderWidth = w.globals.gridWidth * parseInt(this.xaxisBorderWidth, 10) / 100;
17667 } else {
17668 this.xaxisBorderWidth = parseInt(this.xaxisBorderWidth, 10);
17669 }
17670 this.xaxisBorderHeight = w.config.xaxis.axisBorder.height;
17671
17672 // For bars, we will only consider single y xais,
17673 // as we are not providing multiple yaxis for bar charts
17674 this.yaxis = w.config.yaxis[0];
17675 }
17676 _createClass(XAxis, [{
17677 key: "drawXaxis",
17678 value: function drawXaxis() {
17679 var w = this.w;
17680 var graphics = new Graphics(this.ctx);
17681 var elXaxis = graphics.group({
17682 class: 'apexcharts-xaxis',
17683 transform: "translate(".concat(w.config.xaxis.offsetX, ", ").concat(w.config.xaxis.offsetY, ")")
17684 });
17685 var elXaxisTexts = graphics.group({
17686 class: 'apexcharts-xaxis-texts-g',
17687 transform: "translate(".concat(w.globals.translateXAxisX, ", ").concat(w.globals.translateXAxisY, ")")
17688 });
17689 elXaxis.add(elXaxisTexts);
17690 var labels = [];
17691 for (var i = 0; i < this.xaxisLabels.length; i++) {
17692 labels.push(this.xaxisLabels[i]);
17693 }
17694 this.drawXAxisLabelAndGroup(true, graphics, elXaxisTexts, labels, w.globals.isXNumeric, function (i, colWidth) {
17695 return colWidth;
17696 });
17697 if (w.globals.hasXaxisGroups) {
17698 var labelsGroup = w.globals.groups;
17699 labels = [];
17700 for (var _i = 0; _i < labelsGroup.length; _i++) {
17701 labels.push(labelsGroup[_i].title);
17702 }
17703 var overwriteStyles = {};
17704 if (w.config.xaxis.group.style) {
17705 overwriteStyles.xaxisFontSize = w.config.xaxis.group.style.fontSize;
17706 overwriteStyles.xaxisFontFamily = w.config.xaxis.group.style.fontFamily;
17707 overwriteStyles.xaxisForeColors = w.config.xaxis.group.style.colors;
17708 overwriteStyles.fontWeight = w.config.xaxis.group.style.fontWeight;
17709 overwriteStyles.cssClass = w.config.xaxis.group.style.cssClass;
17710 }
17711 this.drawXAxisLabelAndGroup(false, graphics, elXaxisTexts, labels, false, function (i, colWidth) {
17712 return labelsGroup[i].cols * colWidth;
17713 }, overwriteStyles);
17714 }
17715 if (w.config.xaxis.title.text !== undefined) {
17716 var elXaxisTitle = graphics.group({
17717 class: 'apexcharts-xaxis-title'
17718 });
17719 var elXAxisTitleText = graphics.drawText({
17720 x: w.globals.gridWidth / 2 + w.config.xaxis.title.offsetX,
17721 y: this.offY + parseFloat(this.xaxisFontSize) + (w.config.xaxis.position === 'bottom' ? w.globals.xAxisLabelsHeight : -w.globals.xAxisLabelsHeight - 10) + w.config.xaxis.title.offsetY,
17722 text: w.config.xaxis.title.text,
17723 textAnchor: 'middle',
17724 fontSize: w.config.xaxis.title.style.fontSize,
17725 fontFamily: w.config.xaxis.title.style.fontFamily,
17726 fontWeight: w.config.xaxis.title.style.fontWeight,
17727 foreColor: w.config.xaxis.title.style.color,
17728 cssClass: 'apexcharts-xaxis-title-text ' + w.config.xaxis.title.style.cssClass
17729 });
17730 elXaxisTitle.add(elXAxisTitleText);
17731 elXaxis.add(elXaxisTitle);
17732 }
17733 if (w.config.xaxis.axisBorder.show) {
17734 var offX = w.globals.barPadForNumericAxis;
17735 var elHorzLine = graphics.drawLine(w.globals.padHorizontal + w.config.xaxis.axisBorder.offsetX - offX, this.offY, this.xaxisBorderWidth + offX, this.offY, w.config.xaxis.axisBorder.color, 0, this.xaxisBorderHeight);
17736 if (this.elgrid && this.elgrid.elGridBorders && w.config.grid.show) {
17737 this.elgrid.elGridBorders.add(elHorzLine);
17738 } else {
17739 elXaxis.add(elHorzLine);
17740 }
17741 }
17742 return elXaxis;
17743 }
17744 }, {
17745 key: "drawXAxisLabelAndGroup",
17746 value: function drawXAxisLabelAndGroup(isLeafGroup, graphics, elXaxisTexts, labels, isXNumeric, colWidthCb) {
17747 var _this = this;
17748 var overwriteStyles = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
17749 var drawnLabels = [];
17750 var drawnLabelsRects = [];
17751 var w = this.w;
17752 var xaxisFontSize = overwriteStyles.xaxisFontSize || this.xaxisFontSize;
17753 var xaxisFontFamily = overwriteStyles.xaxisFontFamily || this.xaxisFontFamily;
17754 var xaxisForeColors = overwriteStyles.xaxisForeColors || this.xaxisForeColors;
17755 var fontWeight = overwriteStyles.fontWeight || w.config.xaxis.labels.style.fontWeight;
17756 var cssClass = overwriteStyles.cssClass || w.config.xaxis.labels.style.cssClass;
17757 var colWidth;
17758
17759 // initial x Position (keep adding column width in the loop)
17760 var xPos = w.globals.padHorizontal;
17761 var labelsLen = labels.length;
17762
17763 /**
17764 * labelsLen can be different (whether you are drawing x-axis labels or x-axis group labels)
17765 * hence, we introduce dataPoints to be consistent.
17766 * Also, in datetime/numeric xaxis, dataPoints can be misleading, so we resort to labelsLen for such xaxis type
17767 */
17768 var dataPoints = w.config.xaxis.type === 'category' ? w.globals.dataPoints : labelsLen;
17769
17770 // when all series are collapsed, fixes #3381
17771 if (dataPoints === 0 && labelsLen > dataPoints) dataPoints = labelsLen;
17772 if (isXNumeric) {
17773 var len = Math.max(Number(w.config.xaxis.tickAmount) || 1, dataPoints > 1 ? dataPoints - 1 : dataPoints);
17774 colWidth = w.globals.gridWidth / Math.min(len, labelsLen - 1);
17775 xPos = xPos + colWidthCb(0, colWidth) / 2 + w.config.xaxis.labels.offsetX;
17776 } else {
17777 colWidth = w.globals.gridWidth / dataPoints;
17778 xPos = xPos + colWidthCb(0, colWidth) + w.config.xaxis.labels.offsetX;
17779 }
17780 var _loop = function _loop(i) {
17781 var x = xPos - colWidthCb(i, colWidth) / 2 + w.config.xaxis.labels.offsetX;
17782 if (i === 0 && labelsLen === 1 && colWidth / 2 === xPos && dataPoints === 1) {
17783 // single datapoint
17784 x = w.globals.gridWidth / 2;
17785 }
17786 var label = _this.axesUtils.getLabel(labels, w.globals.timescaleLabels, x, i, drawnLabels, xaxisFontSize, isLeafGroup);
17787 var offsetYCorrection = 28;
17788 if (w.globals.rotateXLabels && isLeafGroup) {
17789 offsetYCorrection = 22;
17790 }
17791 if (w.config.xaxis.title.text && w.config.xaxis.position === 'top') {
17792 offsetYCorrection += parseFloat(w.config.xaxis.title.style.fontSize) + 2;
17793 }
17794 if (!isLeafGroup) {
17795 offsetYCorrection = offsetYCorrection + parseFloat(xaxisFontSize) + (w.globals.xAxisLabelsHeight - w.globals.xAxisGroupLabelsHeight) + (w.globals.rotateXLabels ? 10 : 0);
17796 }
17797 var isCategoryTickAmounts = typeof w.config.xaxis.tickAmount !== 'undefined' && w.config.xaxis.tickAmount !== 'dataPoints' && w.config.xaxis.type !== 'datetime';
17798 if (isCategoryTickAmounts) {
17799 label = _this.axesUtils.checkLabelBasedOnTickamount(i, label, labelsLen);
17800 } else {
17801 label = _this.axesUtils.checkForOverflowingLabels(i, label, labelsLen, drawnLabels, drawnLabelsRects);
17802 }
17803 var getCatForeColor = function getCatForeColor() {
17804 return isLeafGroup && w.config.xaxis.convertedCatToNumeric ? xaxisForeColors[w.globals.minX + i - 1] : xaxisForeColors[i];
17805 };
17806 if (w.config.xaxis.labels.show) {
17807 var elText = graphics.drawText({
17808 x: label.x,
17809 y: _this.offY + w.config.xaxis.labels.offsetY + offsetYCorrection - (w.config.xaxis.position === 'top' ? w.globals.xAxisHeight + w.config.xaxis.axisTicks.height - 2 : 0),
17810 text: label.text,
17811 textAnchor: 'middle',
17812 fontWeight: label.isBold ? 600 : fontWeight,
17813 fontSize: xaxisFontSize,
17814 fontFamily: xaxisFontFamily,
17815 foreColor: Array.isArray(xaxisForeColors) ? getCatForeColor() : xaxisForeColors,
17816 isPlainText: false,
17817 cssClass: (isLeafGroup ? 'apexcharts-xaxis-label ' : 'apexcharts-xaxis-group-label ') + cssClass
17818 });
17819 elXaxisTexts.add(elText);
17820 elText.on('click', function (e) {
17821 if (typeof w.config.chart.events.xAxisLabelClick === 'function') {
17822 var opts = Object.assign({}, w, {
17823 labelIndex: i
17824 });
17825 w.config.chart.events.xAxisLabelClick(e, _this.ctx, opts);
17826 }
17827 });
17828 if (isLeafGroup) {
17829 var elTooltipTitle = document.createElementNS(w.globals.SVGNS, 'title');
17830 elTooltipTitle.textContent = Array.isArray(label.text) ? label.text.join(' ') : label.text;
17831 elText.node.appendChild(elTooltipTitle);
17832 if (label.text !== '') {
17833 drawnLabels.push(label.text);
17834 drawnLabelsRects.push(label);
17835 }
17836 }
17837 }
17838 if (i < labelsLen - 1) {
17839 xPos = xPos + colWidthCb(i + 1, colWidth);
17840 }
17841 };
17842 for (var i = 0; i <= labelsLen - 1; i++) {
17843 _loop(i);
17844 }
17845 }
17846
17847 // this actually becomes the vertical axis (for bar charts)
17848 }, {
17849 key: "drawXaxisInversed",
17850 value: function drawXaxisInversed(realIndex) {
17851 var _this2 = this;
17852 var w = this.w;
17853 var graphics = new Graphics(this.ctx);
17854 var translateYAxisX = w.config.yaxis[0].opposite ? w.globals.translateYAxisX[realIndex] : 0;
17855 var elYaxis = graphics.group({
17856 class: 'apexcharts-yaxis apexcharts-xaxis-inversed',
17857 rel: realIndex
17858 });
17859 var elYaxisTexts = graphics.group({
17860 class: 'apexcharts-yaxis-texts-g apexcharts-xaxis-inversed-texts-g',
17861 transform: 'translate(' + translateYAxisX + ', 0)'
17862 });
17863 elYaxis.add(elYaxisTexts);
17864 var colHeight;
17865
17866 // initial x Position (keep adding column width in the loop)
17867 var yPos;
17868 var labels = [];
17869 if (w.config.yaxis[realIndex].show) {
17870 for (var i = 0; i < this.xaxisLabels.length; i++) {
17871 labels.push(this.xaxisLabels[i]);
17872 }
17873 }
17874 colHeight = w.globals.gridHeight / labels.length;
17875 yPos = -(colHeight / 2.2);
17876 var lbFormatter = w.globals.yLabelFormatters[0];
17877 var ylabels = w.config.yaxis[0].labels;
17878 if (ylabels.show) {
17879 var _loop2 = function _loop2(_i2) {
17880 var label = typeof labels[_i2] === 'undefined' ? '' : labels[_i2];
17881 label = lbFormatter(label, {
17882 seriesIndex: realIndex,
17883 dataPointIndex: _i2,
17884 w: w
17885 });
17886 var yColors = _this2.axesUtils.getYAxisForeColor(ylabels.style.colors, realIndex);
17887 var getForeColor = function getForeColor() {
17888 return Array.isArray(yColors) ? yColors[_i2] : yColors;
17889 };
17890 var multiY = 0;
17891 if (Array.isArray(label)) {
17892 multiY = label.length / 2 * parseInt(ylabels.style.fontSize, 10);
17893 }
17894 var offsetX = ylabels.offsetX - 15;
17895 var textAnchor = 'end';
17896 if (_this2.yaxis.opposite) {
17897 textAnchor = 'start';
17898 }
17899 if (w.config.yaxis[0].labels.align === 'left') {
17900 offsetX = ylabels.offsetX;
17901 textAnchor = 'start';
17902 } else if (w.config.yaxis[0].labels.align === 'center') {
17903 offsetX = ylabels.offsetX;
17904 textAnchor = 'middle';
17905 } else if (w.config.yaxis[0].labels.align === 'right') {
17906 textAnchor = 'end';
17907 }
17908 var elLabel = graphics.drawText({
17909 x: offsetX,
17910 y: yPos + colHeight + ylabels.offsetY - multiY,
17911 text: label,
17912 textAnchor: textAnchor,
17913 foreColor: getForeColor(),
17914 fontSize: ylabels.style.fontSize,
17915 fontFamily: ylabels.style.fontFamily,
17916 fontWeight: ylabels.style.fontWeight,
17917 isPlainText: false,
17918 cssClass: 'apexcharts-yaxis-label ' + ylabels.style.cssClass,
17919 maxWidth: ylabels.maxWidth
17920 });
17921 elYaxisTexts.add(elLabel);
17922 elLabel.on('click', function (e) {
17923 if (typeof w.config.chart.events.xAxisLabelClick === 'function') {
17924 var opts = Object.assign({}, w, {
17925 labelIndex: _i2
17926 });
17927 w.config.chart.events.xAxisLabelClick(e, _this2.ctx, opts);
17928 }
17929 });
17930 var elTooltipTitle = document.createElementNS(w.globals.SVGNS, 'title');
17931 elTooltipTitle.textContent = Array.isArray(label) ? label.join(' ') : label;
17932 elLabel.node.appendChild(elTooltipTitle);
17933 if (w.config.yaxis[realIndex].labels.rotate !== 0) {
17934 var labelRotatingCenter = graphics.rotateAroundCenter(elLabel.node);
17935 elLabel.node.setAttribute('transform', "rotate(".concat(w.config.yaxis[realIndex].labels.rotate, " 0 ").concat(labelRotatingCenter.y, ")"));
17936 }
17937 yPos = yPos + colHeight;
17938 };
17939 for (var _i2 = 0; _i2 <= labels.length - 1; _i2++) {
17940 _loop2(_i2);
17941 }
17942 }
17943 if (w.config.yaxis[0].title.text !== undefined) {
17944 var elXaxisTitle = graphics.group({
17945 class: 'apexcharts-yaxis-title apexcharts-xaxis-title-inversed',
17946 transform: 'translate(' + translateYAxisX + ', 0)'
17947 });
17948 var elXAxisTitleText = graphics.drawText({
17949 x: w.config.yaxis[0].title.offsetX,
17950 y: w.globals.gridHeight / 2 + w.config.yaxis[0].title.offsetY,
17951 text: w.config.yaxis[0].title.text,
17952 textAnchor: 'middle',
17953 foreColor: w.config.yaxis[0].title.style.color,
17954 fontSize: w.config.yaxis[0].title.style.fontSize,
17955 fontWeight: w.config.yaxis[0].title.style.fontWeight,
17956 fontFamily: w.config.yaxis[0].title.style.fontFamily,
17957 cssClass: 'apexcharts-yaxis-title-text ' + w.config.yaxis[0].title.style.cssClass
17958 });
17959 elXaxisTitle.add(elXAxisTitleText);
17960 elYaxis.add(elXaxisTitle);
17961 }
17962 var offX = 0;
17963 if (this.isCategoryBarHorizontal && w.config.yaxis[0].opposite) {
17964 offX = w.globals.gridWidth;
17965 }
17966 var axisBorder = w.config.xaxis.axisBorder;
17967 if (axisBorder.show) {
17968 var elVerticalLine = graphics.drawLine(w.globals.padHorizontal + axisBorder.offsetX + offX, 1 + axisBorder.offsetY, w.globals.padHorizontal + axisBorder.offsetX + offX, w.globals.gridHeight + axisBorder.offsetY, axisBorder.color, 0);
17969 if (this.elgrid && this.elgrid.elGridBorders && w.config.grid.show) {
17970 this.elgrid.elGridBorders.add(elVerticalLine);
17971 } else {
17972 elYaxis.add(elVerticalLine);
17973 }
17974 }
17975 if (w.config.yaxis[0].axisTicks.show) {
17976 this.axesUtils.drawYAxisTicks(offX, labels.length, w.config.yaxis[0].axisBorder, w.config.yaxis[0].axisTicks, 0, colHeight, elYaxis);
17977 }
17978 return elYaxis;
17979 }
17980 }, {
17981 key: "drawXaxisTicks",
17982 value: function drawXaxisTicks(x1, y2, appendToElement) {
17983 var w = this.w;
17984 var x2 = x1;
17985 if (x1 < 0 || x1 - 2 > w.globals.gridWidth) return;
17986 var y1 = this.offY + w.config.xaxis.axisTicks.offsetY;
17987 y2 = y2 + y1 + w.config.xaxis.axisTicks.height;
17988 if (w.config.xaxis.position === 'top') {
17989 y2 = y1 - w.config.xaxis.axisTicks.height;
17990 }
17991 if (w.config.xaxis.axisTicks.show) {
17992 var graphics = new Graphics(this.ctx);
17993 var line = graphics.drawLine(x1 + w.config.xaxis.axisTicks.offsetX, y1 + w.config.xaxis.offsetY, x2 + w.config.xaxis.axisTicks.offsetX, y2 + w.config.xaxis.offsetY, w.config.xaxis.axisTicks.color);
17994
17995 // we are not returning anything, but appending directly to the element passed in param
17996 appendToElement.add(line);
17997 line.node.classList.add('apexcharts-xaxis-tick');
17998 }
17999 }
18000 }, {
18001 key: "getXAxisTicksPositions",
18002 value: function getXAxisTicksPositions() {
18003 var w = this.w;
18004 var xAxisTicksPositions = [];
18005 var xCount = this.xaxisLabels.length;
18006 var x1 = w.globals.padHorizontal;
18007 if (w.globals.timescaleLabels.length > 0) {
18008 for (var i = 0; i < xCount; i++) {
18009 x1 = this.xaxisLabels[i].position;
18010 xAxisTicksPositions.push(x1);
18011 }
18012 } else {
18013 var xCountForCategoryCharts = xCount;
18014 for (var _i3 = 0; _i3 < xCountForCategoryCharts; _i3++) {
18015 var x1Count = xCountForCategoryCharts;
18016 if (w.globals.isXNumeric && w.config.chart.type !== 'bar') {
18017 x1Count -= 1;
18018 }
18019 x1 = x1 + w.globals.gridWidth / x1Count;
18020 xAxisTicksPositions.push(x1);
18021 }
18022 }
18023 return xAxisTicksPositions;
18024 }
18025
18026 // to rotate x-axis labels or to put ... for longer text in xaxis
18027 }, {
18028 key: "xAxisLabelCorrections",
18029 value: function xAxisLabelCorrections() {
18030 var w = this.w;
18031 var graphics = new Graphics(this.ctx);
18032 var xAxis = w.globals.dom.baseEl.querySelector('.apexcharts-xaxis-texts-g');
18033 var xAxisTexts = w.globals.dom.baseEl.querySelectorAll('.apexcharts-xaxis-texts-g text:not(.apexcharts-xaxis-group-label)');
18034 var yAxisTextsInversed = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxis-inversed text');
18035 var xAxisTextsInversed = w.globals.dom.baseEl.querySelectorAll('.apexcharts-xaxis-inversed-texts-g text tspan');
18036 if (w.globals.rotateXLabels || w.config.xaxis.labels.rotateAlways) {
18037 for (var xat = 0; xat < xAxisTexts.length; xat++) {
18038 var textRotatingCenter = graphics.rotateAroundCenter(xAxisTexts[xat]);
18039 textRotatingCenter.y = textRotatingCenter.y - 1; // + tickWidth/4;
18040 textRotatingCenter.x = textRotatingCenter.x + 1;
18041 xAxisTexts[xat].setAttribute('transform', "rotate(".concat(w.config.xaxis.labels.rotate, " ").concat(textRotatingCenter.x, " ").concat(textRotatingCenter.y, ")"));
18042 xAxisTexts[xat].setAttribute('text-anchor', "end");
18043 var offsetHeight = 10;
18044 xAxis.setAttribute('transform', "translate(0, ".concat(-offsetHeight, ")"));
18045 var tSpan = xAxisTexts[xat].childNodes;
18046 if (w.config.xaxis.labels.trim) {
18047 Array.prototype.forEach.call(tSpan, function (ts) {
18048 graphics.placeTextWithEllipsis(ts, ts.textContent, w.globals.xAxisLabelsHeight - (w.config.legend.position === 'bottom' ? 20 : 10));
18049 });
18050 }
18051 }
18052 } else {
18053 (function () {
18054 var width = w.globals.gridWidth / (w.globals.labels.length + 1);
18055 for (var _xat = 0; _xat < xAxisTexts.length; _xat++) {
18056 var _tSpan = xAxisTexts[_xat].childNodes;
18057 if (w.config.xaxis.labels.trim && w.config.xaxis.type !== 'datetime') {
18058 Array.prototype.forEach.call(_tSpan, function (ts) {
18059 graphics.placeTextWithEllipsis(ts, ts.textContent, width);
18060 });
18061 }
18062 }
18063 })();
18064 }
18065 if (yAxisTextsInversed.length > 0) {
18066 // truncate rotated y axis in bar chart (x axis)
18067 var firstLabelPosX = yAxisTextsInversed[yAxisTextsInversed.length - 1].getBBox();
18068 var lastLabelPosX = yAxisTextsInversed[0].getBBox();
18069 if (firstLabelPosX.x < -20) {
18070 yAxisTextsInversed[yAxisTextsInversed.length - 1].parentNode.removeChild(yAxisTextsInversed[yAxisTextsInversed.length - 1]);
18071 }
18072 if (lastLabelPosX.x + lastLabelPosX.width > w.globals.gridWidth && !w.globals.isBarHorizontal) {
18073 yAxisTextsInversed[0].parentNode.removeChild(yAxisTextsInversed[0]);
18074 }
18075
18076 // truncate rotated x axis in bar chart (y axis)
18077 for (var _xat2 = 0; _xat2 < xAxisTextsInversed.length; _xat2++) {
18078 graphics.placeTextWithEllipsis(xAxisTextsInversed[_xat2], xAxisTextsInversed[_xat2].textContent, w.config.yaxis[0].labels.maxWidth - (w.config.yaxis[0].title.text ? parseFloat(w.config.yaxis[0].title.style.fontSize) * 2 : 0) - 15);
18079 }
18080 }
18081 }
18082
18083 // renderXAxisBands() {
18084 // let w = this.w;
18085
18086 // let plotBand = document.createElementNS(w.globals.SVGNS, 'rect')
18087 // w.globals.dom.elGraphical.add(plotBand)
18088 // }
18089 }]);
18090 return XAxis;
18091 }();
18092
18093 /**
18094 * ApexCharts Grid Class for drawing Cartesian Grid.
18095 *
18096 * @module Grid
18097 **/
18098 var Grid = /*#__PURE__*/function () {
18099 function Grid(ctx) {
18100 _classCallCheck(this, Grid);
18101 this.ctx = ctx;
18102 this.w = ctx.w;
18103 var w = this.w;
18104 this.xaxisLabels = w.globals.labels.slice();
18105 this.axesUtils = new AxesUtils(ctx);
18106 this.isRangeBar = w.globals.seriesRange.length && w.globals.isBarHorizontal;
18107 if (w.globals.timescaleLabels.length > 0) {
18108 // timescaleLabels labels are there
18109 this.xaxisLabels = w.globals.timescaleLabels.slice();
18110 }
18111 }
18112 _createClass(Grid, [{
18113 key: "drawGridArea",
18114 value: function drawGridArea() {
18115 var elGrid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
18116 var w = this.w;
18117 var graphics = new Graphics(this.ctx);
18118 if (!elGrid) {
18119 elGrid = graphics.group({
18120 class: 'apexcharts-grid'
18121 });
18122 }
18123 var elVerticalLine = graphics.drawLine(w.globals.padHorizontal, 1, w.globals.padHorizontal, w.globals.gridHeight, 'transparent');
18124 var elHorzLine = graphics.drawLine(w.globals.padHorizontal, w.globals.gridHeight, w.globals.gridWidth, w.globals.gridHeight, 'transparent');
18125 elGrid.add(elHorzLine);
18126 elGrid.add(elVerticalLine);
18127 return elGrid;
18128 }
18129 }, {
18130 key: "drawGrid",
18131 value: function drawGrid() {
18132 var gl = this.w.globals;
18133 if (gl.axisCharts) {
18134 var elgrid = this.renderGrid();
18135 this.drawGridArea(elgrid.el);
18136 return elgrid;
18137 }
18138 return null;
18139 }
18140 }, {
18141 key: "createGridMask",
18142 value: function createGridMask() {
18143 var w = this.w;
18144 var gl = w.globals;
18145 var graphics = new Graphics(this.ctx);
18146 var strokeSize = Array.isArray(w.config.stroke.width) ? Math.max.apply(Math, _toConsumableArray(w.config.stroke.width)) : w.config.stroke.width;
18147 var createClipPath = function createClipPath(id) {
18148 var clipPath = document.createElementNS(gl.SVGNS, 'clipPath');
18149 clipPath.setAttribute('id', id);
18150 return clipPath;
18151 };
18152 gl.dom.elGridRectMask = createClipPath("gridRectMask".concat(gl.cuid));
18153 gl.dom.elGridRectBarMask = createClipPath("gridRectBarMask".concat(gl.cuid));
18154 gl.dom.elGridRectMarkerMask = createClipPath("gridRectMarkerMask".concat(gl.cuid));
18155 gl.dom.elForecastMask = createClipPath("forecastMask".concat(gl.cuid));
18156 gl.dom.elNonForecastMask = createClipPath("nonForecastMask".concat(gl.cuid));
18157 var hasBar = ['bar', 'rangeBar', 'candlestick', 'boxPlot'].includes(w.config.chart.type) || w.globals.comboBarCount > 0;
18158 var barWidthLeft = 0;
18159 var barWidthRight = 0;
18160 if (hasBar && w.globals.isXNumeric && !w.globals.isBarHorizontal) {
18161 barWidthLeft = Math.max(w.config.grid.padding.left, gl.barPadForNumericAxis);
18162 barWidthRight = Math.max(w.config.grid.padding.right, gl.barPadForNumericAxis);
18163 }
18164 gl.dom.elGridRect = graphics.drawRect(-strokeSize / 2 - 2, -strokeSize / 2 - 2, gl.gridWidth + strokeSize + 4, gl.gridHeight + strokeSize + 4, 0, '#fff');
18165 gl.dom.elGridRectBar = graphics.drawRect(-strokeSize / 2 - barWidthLeft - 2, -strokeSize / 2 - 2, gl.gridWidth + strokeSize + barWidthRight + barWidthLeft + 4, gl.gridHeight + strokeSize + 4, 0, '#fff');
18166 var markerSize = w.globals.markers.largestSize;
18167 gl.dom.elGridRectMarker = graphics.drawRect(-markerSize, -markerSize, gl.gridWidth + markerSize * 2, gl.gridHeight + markerSize * 2, 0, '#fff');
18168 gl.dom.elGridRectMask.appendChild(gl.dom.elGridRect.node);
18169 gl.dom.elGridRectBarMask.appendChild(gl.dom.elGridRectBar.node);
18170 gl.dom.elGridRectMarkerMask.appendChild(gl.dom.elGridRectMarker.node);
18171 var defs = gl.dom.baseEl.querySelector('defs');
18172 defs.appendChild(gl.dom.elGridRectMask);
18173 defs.appendChild(gl.dom.elGridRectBarMask);
18174 defs.appendChild(gl.dom.elGridRectMarkerMask);
18175 defs.appendChild(gl.dom.elForecastMask);
18176 defs.appendChild(gl.dom.elNonForecastMask);
18177 }
18178 }, {
18179 key: "_drawGridLines",
18180 value: function _drawGridLines(_ref) {
18181 var i = _ref.i,
18182 x1 = _ref.x1,
18183 y1 = _ref.y1,
18184 x2 = _ref.x2,
18185 y2 = _ref.y2,
18186 xCount = _ref.xCount,
18187 parent = _ref.parent;
18188 var w = this.w;
18189 var shouldDraw = function shouldDraw() {
18190 if (i === 0 && w.globals.skipFirstTimelinelabel) return false;
18191 if (i === xCount - 1 && w.globals.skipLastTimelinelabel && !w.config.xaxis.labels.formatter) return false;
18192 if (w.config.chart.type === 'radar') return false;
18193 return true;
18194 };
18195 if (shouldDraw()) {
18196 if (w.config.grid.xaxis.lines.show) {
18197 this._drawGridLine({
18198 i: i,
18199 x1: x1,
18200 y1: y1,
18201 x2: x2,
18202 y2: y2,
18203 xCount: xCount,
18204 parent: parent
18205 });
18206 }
18207 var y_2 = 0;
18208 if (w.globals.hasXaxisGroups && w.config.xaxis.tickPlacement === 'between') {
18209 var groups = w.globals.groups;
18210 if (groups) {
18211 var gacc = 0;
18212 for (var gi = 0; gacc < i && gi < groups.length; gi++) {
18213 gacc += groups[gi].cols;
18214 }
18215 if (gacc === i) {
18216 y_2 = w.globals.xAxisLabelsHeight * 0.6;
18217 }
18218 }
18219 }
18220 var xAxis = new XAxis(this.ctx);
18221 xAxis.drawXaxisTicks(x1, y_2, w.globals.dom.elGraphical);
18222 }
18223 }
18224 }, {
18225 key: "_drawGridLine",
18226 value: function _drawGridLine(_ref2) {
18227 var i = _ref2.i,
18228 x1 = _ref2.x1,
18229 y1 = _ref2.y1,
18230 x2 = _ref2.x2,
18231 y2 = _ref2.y2,
18232 xCount = _ref2.xCount,
18233 parent = _ref2.parent;
18234 var w = this.w;
18235 var isHorzLine = parent.node.classList.contains('apexcharts-gridlines-horizontal');
18236 var offX = w.globals.barPadForNumericAxis;
18237 var excludeBorders = y1 === 0 && y2 === 0 || x1 === 0 && x2 === 0 || y1 === w.globals.gridHeight && y2 === w.globals.gridHeight || w.globals.isBarHorizontal && (i === 0 || i === xCount - 1);
18238 var graphics = new Graphics(this);
18239 var line = graphics.drawLine(x1 - (isHorzLine ? offX : 0), y1, x2 + (isHorzLine ? offX : 0), y2, w.config.grid.borderColor, w.config.grid.strokeDashArray);
18240 line.node.classList.add('apexcharts-gridline');
18241 if (excludeBorders && w.config.grid.show) {
18242 this.elGridBorders.add(line);
18243 } else {
18244 parent.add(line);
18245 }
18246 }
18247 }, {
18248 key: "_drawGridBandRect",
18249 value: function _drawGridBandRect(_ref3) {
18250 var c = _ref3.c,
18251 x1 = _ref3.x1,
18252 y1 = _ref3.y1,
18253 x2 = _ref3.x2,
18254 y2 = _ref3.y2,
18255 type = _ref3.type;
18256 var w = this.w;
18257 var graphics = new Graphics(this.ctx);
18258 var offX = w.globals.barPadForNumericAxis;
18259 var color = w.config.grid[type].colors[c];
18260 var rect = graphics.drawRect(x1 - (type === 'row' ? offX : 0), y1, x2 + (type === 'row' ? offX * 2 : 0), y2, 0, color, w.config.grid[type].opacity);
18261 this.elg.add(rect);
18262 rect.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
18263 rect.node.classList.add("apexcharts-grid-".concat(type));
18264 }
18265 }, {
18266 key: "_drawXYLines",
18267 value: function _drawXYLines(_ref4) {
18268 var _this = this;
18269 var xCount = _ref4.xCount,
18270 tickAmount = _ref4.tickAmount;
18271 var w = this.w;
18272 var datetimeLines = function datetimeLines(_ref5) {
18273 var xC = _ref5.xC,
18274 x1 = _ref5.x1,
18275 y1 = _ref5.y1,
18276 x2 = _ref5.x2,
18277 y2 = _ref5.y2;
18278 for (var i = 0; i < xC; i++) {
18279 x1 = _this.xaxisLabels[i].position;
18280 x2 = _this.xaxisLabels[i].position;
18281 _this._drawGridLines({
18282 i: i,
18283 x1: x1,
18284 y1: y1,
18285 x2: x2,
18286 y2: y2,
18287 xCount: xCount,
18288 parent: _this.elgridLinesV
18289 });
18290 }
18291 };
18292 var categoryLines = function categoryLines(_ref6) {
18293 var xC = _ref6.xC,
18294 x1 = _ref6.x1,
18295 y1 = _ref6.y1,
18296 x2 = _ref6.x2,
18297 y2 = _ref6.y2;
18298 for (var i = 0; i < xC + (w.globals.isXNumeric ? 0 : 1); i++) {
18299 if (i === 0 && xC === 1 && w.globals.dataPoints === 1) {
18300 x1 = w.globals.gridWidth / 2;
18301 x2 = x1;
18302 }
18303 _this._drawGridLines({
18304 i: i,
18305 x1: x1,
18306 y1: y1,
18307 x2: x2,
18308 y2: y2,
18309 xCount: xCount,
18310 parent: _this.elgridLinesV
18311 });
18312 x1 += w.globals.gridWidth / (w.globals.isXNumeric ? xC - 1 : xC);
18313 x2 = x1;
18314 }
18315 };
18316 if (w.config.grid.xaxis.lines.show || w.config.xaxis.axisTicks.show) {
18317 var x1 = w.globals.padHorizontal;
18318 var y1 = 0;
18319 var x2;
18320 var y2 = w.globals.gridHeight;
18321 if (w.globals.timescaleLabels.length) {
18322 datetimeLines({
18323 xC: xCount,
18324 x1: x1,
18325 y1: y1,
18326 x2: x2,
18327 y2: y2
18328 });
18329 } else {
18330 if (w.globals.isXNumeric) {
18331 xCount = w.globals.xAxisScale.result.length;
18332 }
18333 categoryLines({
18334 xC: xCount,
18335 x1: x1,
18336 y1: y1,
18337 x2: x2,
18338 y2: y2
18339 });
18340 }
18341 }
18342 if (w.config.grid.yaxis.lines.show) {
18343 var _x = 0;
18344 var _y = 0;
18345 var _y2 = 0;
18346 var _x2 = w.globals.gridWidth;
18347 var tA = tickAmount + 1;
18348 if (this.isRangeBar) {
18349 tA = w.globals.labels.length;
18350 }
18351 for (var i = 0; i < tA + (this.isRangeBar ? 1 : 0); i++) {
18352 this._drawGridLine({
18353 i: i,
18354 xCount: tA + (this.isRangeBar ? 1 : 0),
18355 x1: _x,
18356 y1: _y,
18357 x2: _x2,
18358 y2: _y2,
18359 parent: this.elgridLinesH
18360 });
18361 _y += w.globals.gridHeight / (this.isRangeBar ? tA : tickAmount);
18362 _y2 = _y;
18363 }
18364 }
18365 }
18366 }, {
18367 key: "_drawInvertedXYLines",
18368 value: function _drawInvertedXYLines(_ref7) {
18369 var xCount = _ref7.xCount;
18370 var w = this.w;
18371 if (w.config.grid.xaxis.lines.show || w.config.xaxis.axisTicks.show) {
18372 var x1 = w.globals.padHorizontal;
18373 var y1 = 0;
18374 var x2;
18375 var y2 = w.globals.gridHeight;
18376 for (var i = 0; i < xCount + 1; i++) {
18377 if (w.config.grid.xaxis.lines.show) {
18378 this._drawGridLine({
18379 i: i,
18380 xCount: xCount + 1,
18381 x1: x1,
18382 y1: y1,
18383 x2: x2,
18384 y2: y2,
18385 parent: this.elgridLinesV
18386 });
18387 }
18388 var xAxis = new XAxis(this.ctx);
18389 xAxis.drawXaxisTicks(x1, 0, w.globals.dom.elGraphical);
18390 x1 += w.globals.gridWidth / xCount;
18391 x2 = x1;
18392 }
18393 }
18394 if (w.config.grid.yaxis.lines.show) {
18395 var _x3 = 0;
18396 var _y3 = 0;
18397 var _y4 = 0;
18398 var _x4 = w.globals.gridWidth;
18399 for (var _i = 0; _i < w.globals.dataPoints + 1; _i++) {
18400 this._drawGridLine({
18401 i: _i,
18402 xCount: w.globals.dataPoints + 1,
18403 x1: _x3,
18404 y1: _y3,
18405 x2: _x4,
18406 y2: _y4,
18407 parent: this.elgridLinesH
18408 });
18409 _y3 += w.globals.gridHeight / w.globals.dataPoints;
18410 _y4 = _y3;
18411 }
18412 }
18413 }
18414 }, {
18415 key: "renderGrid",
18416 value: function renderGrid() {
18417 var w = this.w;
18418 var gl = w.globals;
18419 var graphics = new Graphics(this.ctx);
18420 this.elg = graphics.group({
18421 class: 'apexcharts-grid'
18422 });
18423 this.elgridLinesH = graphics.group({
18424 class: 'apexcharts-gridlines-horizontal'
18425 });
18426 this.elgridLinesV = graphics.group({
18427 class: 'apexcharts-gridlines-vertical'
18428 });
18429 this.elGridBorders = graphics.group({
18430 class: 'apexcharts-grid-borders'
18431 });
18432 this.elg.add(this.elgridLinesH);
18433 this.elg.add(this.elgridLinesV);
18434 if (!w.config.grid.show) {
18435 this.elgridLinesV.hide();
18436 this.elgridLinesH.hide();
18437 this.elGridBorders.hide();
18438 }
18439 var gridAxisIndex = 0;
18440 while (gridAxisIndex < gl.seriesYAxisMap.length && gl.ignoreYAxisIndexes.includes(gridAxisIndex)) {
18441 gridAxisIndex++;
18442 }
18443 if (gridAxisIndex === gl.seriesYAxisMap.length) {
18444 gridAxisIndex = 0;
18445 }
18446 var yTickAmount = gl.yAxisScale[gridAxisIndex].result.length - 1;
18447 var xCount;
18448 if (!gl.isBarHorizontal || this.isRangeBar) {
18449 xCount = this.xaxisLabels.length;
18450 if (this.isRangeBar) {
18451 var _gl$yAxisScale, _gl$yAxisScale$gridAx, _gl$yAxisScale$gridAx2;
18452 yTickAmount = gl.labels.length;
18453 if (w.config.xaxis.tickAmount && w.config.xaxis.labels.formatter) {
18454 xCount = w.config.xaxis.tickAmount;
18455 }
18456 if (((_gl$yAxisScale = gl.yAxisScale) === null || _gl$yAxisScale === void 0 ? void 0 : (_gl$yAxisScale$gridAx = _gl$yAxisScale[gridAxisIndex]) === null || _gl$yAxisScale$gridAx === void 0 ? void 0 : (_gl$yAxisScale$gridAx2 = _gl$yAxisScale$gridAx.result) === null || _gl$yAxisScale$gridAx2 === void 0 ? void 0 : _gl$yAxisScale$gridAx2.length) > 0 && w.config.xaxis.type !== 'datetime') {
18457 xCount = gl.yAxisScale[gridAxisIndex].result.length - 1;
18458 }
18459 }
18460 this._drawXYLines({
18461 xCount: xCount,
18462 tickAmount: yTickAmount
18463 });
18464 } else {
18465 xCount = yTickAmount;
18466
18467 // for horizontal bar chart, get the xaxis tickamount
18468 yTickAmount = gl.xTickAmount;
18469 this._drawInvertedXYLines({
18470 xCount: xCount,
18471 tickAmount: yTickAmount
18472 });
18473 }
18474 this.drawGridBands(xCount, yTickAmount);
18475 return {
18476 el: this.elg,
18477 elGridBorders: this.elGridBorders,
18478 xAxisTickWidth: gl.gridWidth / xCount
18479 };
18480 }
18481 }, {
18482 key: "drawGridBands",
18483 value: function drawGridBands(xCount, tickAmount) {
18484 var _this2 = this,
18485 _w$config$grid$row$co,
18486 _w$config$grid$column;
18487 var w = this.w;
18488 var drawBands = function drawBands(type, count, x1, y1, x2, y2) {
18489 for (var i = 0, c = 0; i < count; i++, c++) {
18490 if (c >= w.config.grid[type].colors.length) {
18491 c = 0;
18492 }
18493 _this2._drawGridBandRect({
18494 c: c,
18495 x1: x1,
18496 y1: y1,
18497 x2: x2,
18498 y2: y2,
18499 type: type
18500 });
18501 y1 += w.globals.gridHeight / tickAmount;
18502 }
18503 };
18504 if (((_w$config$grid$row$co = w.config.grid.row.colors) === null || _w$config$grid$row$co === void 0 ? void 0 : _w$config$grid$row$co.length) > 0) {
18505 drawBands('row', tickAmount, 0, 0, w.globals.gridWidth, w.globals.gridHeight / tickAmount);
18506 }
18507 if (((_w$config$grid$column = w.config.grid.column.colors) === null || _w$config$grid$column === void 0 ? void 0 : _w$config$grid$column.length) > 0) {
18508 var xc = !w.globals.isBarHorizontal && w.config.xaxis.tickPlacement === 'on' && (w.config.xaxis.type === 'category' || w.config.xaxis.convertedCatToNumeric) ? xCount - 1 : xCount;
18509 if (w.globals.isXNumeric) {
18510 xc = w.globals.xAxisScale.result.length - 1;
18511 }
18512 var x1 = w.globals.padHorizontal;
18513 var y1 = 0;
18514 var x2 = w.globals.padHorizontal + w.globals.gridWidth / xc;
18515 var y2 = w.globals.gridHeight;
18516 for (var i = 0, c = 0; i < xCount; i++, c++) {
18517 if (c >= w.config.grid.column.colors.length) {
18518 c = 0;
18519 }
18520 if (w.config.xaxis.type === 'datetime') {
18521 var _this$xaxisLabels;
18522 x1 = this.xaxisLabels[i].position;
18523 x2 = (((_this$xaxisLabels = this.xaxisLabels[i + 1]) === null || _this$xaxisLabels === void 0 ? void 0 : _this$xaxisLabels.position) || w.globals.gridWidth) - this.xaxisLabels[i].position;
18524 }
18525 this._drawGridBandRect({
18526 c: c,
18527 x1: x1,
18528 y1: y1,
18529 x2: x2,
18530 y2: y2,
18531 type: 'column'
18532 });
18533 x1 += w.globals.gridWidth / xc;
18534 }
18535 }
18536 }
18537 }]);
18538 return Grid;
18539 }();
18540
18541 var Scales = /*#__PURE__*/function () {
18542 function Scales(ctx) {
18543 _classCallCheck(this, Scales);
18544 this.ctx = ctx;
18545 this.w = ctx.w;
18546 this.coreUtils = new CoreUtils(this.ctx);
18547 }
18548
18549 // http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis
18550 // This routine creates the Y axis values for a graph.
18551 _createClass(Scales, [{
18552 key: "niceScale",
18553 value: function niceScale(yMin, yMax) {
18554 var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
18555 // Calculate Min amd Max graphical labels and graph
18556 // increments.
18557 //
18558 // Output will be an array of the Y axis values that
18559 // encompass the Y values.
18560 var jsPrecision = 1e-11; // JS precision errors
18561 var w = this.w;
18562 var gl = w.globals;
18563 var axisCnf;
18564 var maxTicks;
18565 var gotMin;
18566 var gotMax;
18567 if (gl.isBarHorizontal) {
18568 axisCnf = w.config.xaxis;
18569 // The most ticks we can fit into the svg chart dimensions
18570 maxTicks = Math.max((gl.svgWidth - 100) / 25, 2); // Guestimate
18571 } else {
18572 axisCnf = w.config.yaxis[index];
18573 maxTicks = Math.max((gl.svgHeight - 100) / 15, 2);
18574 }
18575 if (!Utils$1.isNumber(maxTicks)) {
18576 maxTicks = 10;
18577 }
18578 gotMin = axisCnf.min !== undefined && axisCnf.min !== null;
18579 gotMax = axisCnf.max !== undefined && axisCnf.min !== null;
18580 var gotStepSize = axisCnf.stepSize !== undefined && axisCnf.stepSize !== null;
18581 var gotTickAmount = axisCnf.tickAmount !== undefined && axisCnf.tickAmount !== null;
18582 var ticks = gotTickAmount ? axisCnf.tickAmount : gl.niceScaleDefaultTicks[Math.min(Math.round(maxTicks / 2), gl.niceScaleDefaultTicks.length - 1)];
18583
18584 // In case we have a multi axis chart:
18585 // Ensure subsequent series start with the same tickAmount as series[0],
18586 // because the tick lines are drawn based on series[0]. This does not
18587 // override user defined options for any yaxis.
18588 if (gl.isMultipleYAxis && !gotTickAmount && gl.multiAxisTickAmount > 0) {
18589 ticks = gl.multiAxisTickAmount;
18590 gotTickAmount = true;
18591 }
18592 if (ticks === 'dataPoints') {
18593 ticks = gl.dataPoints - 1;
18594 } else {
18595 // Ensure ticks is an integer
18596 ticks = Math.abs(Math.round(ticks));
18597 }
18598 if (yMin === Number.MIN_VALUE && yMax === 0 || !Utils$1.isNumber(yMin) && !Utils$1.isNumber(yMax) || yMin === Number.MIN_VALUE && yMax === -Number.MAX_VALUE) {
18599 // when all values are 0
18600 yMin = Utils$1.isNumber(axisCnf.min) ? axisCnf.min : 0;
18601 yMax = Utils$1.isNumber(axisCnf.max) ? axisCnf.max : yMin + ticks;
18602 gl.allSeriesCollapsed = false;
18603 }
18604 if (yMin > yMax) {
18605 // if somehow due to some wrong config, user sent max less than min,
18606 // adjust the min/max again
18607 console.warn('axis.min cannot be greater than axis.max: swapping min and max');
18608 var temp = yMax;
18609 yMax = yMin;
18610 yMin = temp;
18611 } else if (yMin === yMax) {
18612 // If yMin and yMax are identical, then
18613 // adjust the yMin and yMax values to actually
18614 // make a graph. Also avoids division by zero errors.
18615 yMin = yMin === 0 ? 0 : yMin - 1; // choose an integer in case yValueDecimals=0
18616 yMax = yMax === 0 ? 2 : yMax + 1; // choose an integer in case yValueDecimals=0
18617 }
18618 var result = [];
18619 if (ticks < 1) {
18620 ticks = 1;
18621 }
18622 var tiks = ticks;
18623
18624 // Determine Range
18625 var range = Math.abs(yMax - yMin);
18626
18627 // Snap min or max to zero if close
18628 var proximityRatio = 0.15;
18629 if (!gotMin && yMin > 0 && yMin / range < proximityRatio) {
18630 yMin = 0;
18631 gotMin = true;
18632 }
18633 if (!gotMax && yMax < 0 && -yMax / range < proximityRatio) {
18634 yMax = 0;
18635 gotMax = true;
18636 }
18637 range = Math.abs(yMax - yMin);
18638
18639 // Calculate a pretty step value based on ticks
18640
18641 // Initial stepSize
18642 var stepSize = range / tiks;
18643 var niceStep = stepSize;
18644 var mag = Math.floor(Math.log10(niceStep));
18645 var magPow = Math.pow(10, mag);
18646 // ceil() is used below in conjunction with the values populating
18647 // niceScaleAllowedMagMsd[][] to ensure that (niceStep * tiks)
18648 // produces a range that doesn't clip data points after stretching
18649 // the raw range out a little to match the prospective new range.
18650 var magMsd = Math.ceil(niceStep / magPow);
18651 // See globals.js for info on what niceScaleAllowedMagMsd does
18652 magMsd = gl.niceScaleAllowedMagMsd[gl.yValueDecimal === 0 ? 0 : 1][magMsd];
18653 niceStep = magMsd * magPow;
18654
18655 // Initial stepSize
18656 stepSize = niceStep;
18657
18658 // Get step value
18659 if (gl.isBarHorizontal && axisCnf.stepSize && axisCnf.type !== 'datetime') {
18660 stepSize = axisCnf.stepSize;
18661 gotStepSize = true;
18662 } else if (gotStepSize) {
18663 stepSize = axisCnf.stepSize;
18664 }
18665 if (gotStepSize) {
18666 if (axisCnf.forceNiceScale) {
18667 // Check that given stepSize is sane with respect to the range.
18668 //
18669 // The user can, by setting forceNiceScale = true,
18670 // define a stepSize that will be scaled to a useful value before
18671 // it's checked for consistency.
18672 //
18673 // If, for example, the range = 4 and the user defined stepSize = 8
18674 // (or 8000 or 0.0008, etc), then stepSize is inapplicable as
18675 // it is. Reducing it to 0.8 will fit with 5 ticks.
18676 //
18677 var stepMag = Math.floor(Math.log10(stepSize));
18678 stepSize *= Math.pow(10, mag - stepMag);
18679 }
18680 }
18681
18682 // Start applying some rules
18683 if (gotMin && gotMax) {
18684 var crudeStep = range / tiks;
18685 // min and max (range) cannot be changed
18686 if (gotTickAmount) {
18687 if (gotStepSize) {
18688 if (Utils$1.mod(range, stepSize) != 0) {
18689 // stepSize conflicts with range
18690 var gcdStep = Utils$1.getGCD(stepSize, crudeStep);
18691 // gcdStep is a multiple of range because crudeStep is a multiple.
18692 // gcdStep is also a multiple of stepSize, so it partially honoured
18693 // All three could be equal, which would be very nice
18694 // if the computed stepSize generates too many ticks they will be
18695 // reduced later, unless the number is prime, in which case,
18696 // the chart will display all of them or just one (plus the X axis)
18697 // depending on svg dimensions. Setting forceNiceScale: true will force
18698 // the display of at least the default number of ticks.
18699 if (crudeStep / gcdStep < 10) {
18700 stepSize = gcdStep;
18701 } else {
18702 // stepSize conflicts and no reasonable adjustment, but must
18703 // honour tickAmount
18704 stepSize = crudeStep;
18705 }
18706 } else {
18707 // stepSize fits
18708 if (Utils$1.mod(stepSize, crudeStep) == 0) {
18709 // crudeStep is a multiple of stepSize, or vice versa
18710 // but we know that crudeStep will generate tickAmount ticks
18711 stepSize = crudeStep;
18712 } else {
18713 // stepSize conflicts with tickAmount
18714 // if the user is setting up a multi-axis chart and wants
18715 // synced axis ticks then they should not define stepSize
18716 // or ensure there is no conflict between any of their options
18717 // on any axis.
18718 crudeStep = stepSize;
18719 // De-prioritizing ticks from now on
18720 gotTickAmount = false;
18721 }
18722 }
18723 } else {
18724 // no user stepSize, honour tickAmount
18725 stepSize = crudeStep;
18726 }
18727 } else {
18728 // default ticks in use, tiks can change
18729 if (gotStepSize) {
18730 if (Utils$1.mod(range, stepSize) == 0) {
18731 // user stepSize fits
18732 crudeStep = stepSize;
18733 } else {
18734 stepSize = crudeStep;
18735 }
18736 } else {
18737 // no user stepSize
18738 if (Utils$1.mod(range, stepSize) == 0) {
18739 // generated nice stepSize fits
18740 crudeStep = stepSize;
18741 } else {
18742 tiks = Math.ceil(range / stepSize);
18743 crudeStep = range / tiks;
18744 var _gcdStep = Utils$1.getGCD(range, stepSize);
18745 if (range / _gcdStep < maxTicks) {
18746 crudeStep = _gcdStep;
18747 }
18748 stepSize = crudeStep;
18749 }
18750 }
18751 }
18752 tiks = Math.round(range / stepSize);
18753 } else {
18754 // Snap range to ticks
18755 if (!gotMin && !gotMax) {
18756 if (gl.isMultipleYAxis && gotTickAmount) {
18757 // Ensure graph doesn't clip.
18758 var tMin = stepSize * Math.floor(yMin / stepSize);
18759 var tMax = tMin + stepSize * tiks;
18760 if (tMax < yMax) {
18761 stepSize *= 2;
18762 }
18763 yMin = tMin;
18764 tMax = yMax;
18765 yMax = yMin + stepSize * tiks;
18766 // Snap min or max to zero if possible
18767 range = Math.abs(yMax - yMin);
18768 if (yMin > 0 && yMin < Math.abs(tMax - yMax)) {
18769 yMin = 0;
18770 yMax = stepSize * tiks;
18771 }
18772 if (yMax < 0 && -yMax < Math.abs(tMin - yMin)) {
18773 yMax = 0;
18774 yMin = -stepSize * tiks;
18775 }
18776 } else {
18777 yMin = stepSize * Math.floor(yMin / stepSize);
18778 yMax = stepSize * Math.ceil(yMax / stepSize);
18779 }
18780 } else if (gotMax) {
18781 if (gotTickAmount) {
18782 yMin = yMax - stepSize * tiks;
18783 } else {
18784 var yMinPrev = yMin;
18785 yMin = stepSize * Math.floor(yMin / stepSize);
18786 if (Math.abs(yMax - yMin) / Utils$1.getGCD(range, stepSize) > maxTicks) {
18787 // Use default ticks to compute yMin then shrinkwrap
18788 yMin = yMax - stepSize * ticks;
18789 yMin += stepSize * Math.floor((yMinPrev - yMin) / stepSize);
18790 }
18791 }
18792 } else if (gotMin) {
18793 if (gotTickAmount) {
18794 yMax = yMin + stepSize * tiks;
18795 } else {
18796 var yMaxPrev = yMax;
18797 yMax = stepSize * Math.ceil(yMax / stepSize);
18798 if (Math.abs(yMax - yMin) / Utils$1.getGCD(range, stepSize) > maxTicks) {
18799 // Use default ticks to compute yMin then shrinkwrap
18800 yMax = yMin + stepSize * ticks;
18801 yMax += stepSize * Math.ceil((yMaxPrev - yMax) / stepSize);
18802 }
18803 }
18804 }
18805 range = Math.abs(yMax - yMin);
18806 // Final check and possible adjustment of stepSize to prevent
18807 // overriding the user's min or max choice.
18808 stepSize = Utils$1.getGCD(range, stepSize);
18809 tiks = Math.round(range / stepSize);
18810 }
18811
18812 // Shrinkwrap ticks to the range
18813 if (!gotTickAmount && !(gotMin || gotMax)) {
18814 tiks = Math.ceil((range - jsPrecision) / (stepSize + jsPrecision));
18815 // No user tickAmount, or min or max, we are free to adjust to avoid a
18816 // prime number. This helps when reducing ticks for small svg dimensions.
18817 if (tiks > 16 && Utils$1.getPrimeFactors(tiks).length < 2) {
18818 tiks++;
18819 }
18820 }
18821
18822 // Prune tiks down to range if series is all integers. Since tiks > range,
18823 // range is very low (< 10 or so). Skip this step if gotTickAmount is true
18824 // because either the user set tickAmount or the chart is multiscale and
18825 // this axis is not determining the number of grid lines.
18826 if (!gotTickAmount && axisCnf.forceNiceScale && gl.yValueDecimal === 0 && tiks > range) {
18827 tiks = range;
18828 stepSize = Math.round(range / tiks);
18829 }
18830 if (tiks > maxTicks && (!(gotTickAmount || gotStepSize) || axisCnf.forceNiceScale)) {
18831 // Reduce the number of ticks nicely if chart svg dimensions shrink too far.
18832 // The reduced tick set should always be a subset of the full set.
18833 //
18834 // This following products of prime factors method works as follows:
18835 // We compute the prime factors of the full tick count (tiks), then all the
18836 // possible products of those factors in order from smallest to biggest,
18837 // until we find a product P such that: tiks/P < maxTicks.
18838 //
18839 // Example:
18840 // Computing products of the prime factors of 30.
18841 //
18842 // tiks | pf | 1 2 3 4 5 6 <-- compute order
18843 // --------------------------------------------------
18844 // 30 | 5 | 5 5 5 <-- Multiply all
18845 // | 3 | 3 3 3 3 <-- primes in each
18846 // | 2 | 2 2 2 <-- column = P
18847 // --------------------------------------------------
18848 // 15 10 6 5 2 1 <-- tiks/P
18849 //
18850 // tiks = 30 has prime factors [2, 3, 5]
18851 // The loop below computes the products [2,3,5,6,15,30].
18852 // The last product of P = 2*3*5 is skipped since 30/P = 1.
18853 // This yields tiks/P = [15,10,6,5,2,1], checked in order until
18854 // tiks/P < maxTicks.
18855 //
18856 // Pros:
18857 // 1) The ticks in the reduced set are always members of the
18858 // full set of ticks.
18859 // Cons:
18860 // 1) None: if tiks is prime, we get all or one, nothing between, so
18861 // the worst case is to display all, which is the status quo. Really
18862 // only a problem visually for larger tick numbers, say, > 7.
18863 //
18864 var pf = Utils$1.getPrimeFactors(tiks);
18865 var last = pf.length - 1;
18866 var tt = tiks;
18867 reduceLoop: for (var xFactors = 0; xFactors < last; xFactors++) {
18868 for (var lowest = 0; lowest <= last - xFactors; lowest++) {
18869 var stop = Math.min(lowest + xFactors, last);
18870 var t = tt;
18871 var div = 1;
18872 for (var next = lowest; next <= stop; next++) {
18873 div *= pf[next];
18874 }
18875 t /= div;
18876 if (t < maxTicks) {
18877 tt = t;
18878 break reduceLoop;
18879 }
18880 }
18881 }
18882 if (tt === tiks) {
18883 // Could not reduce ticks at all, go all in and display just the
18884 // X axis and one tick.
18885 stepSize = range;
18886 } else {
18887 stepSize = range / tt;
18888 }
18889 tiks = Math.round(range / stepSize);
18890 }
18891
18892 // Record final tiks for use by other series that call niceScale().
18893 // Note: some don't, like logarithmicScale(), etc.
18894 if (gl.isMultipleYAxis && gl.multiAxisTickAmount == 0 && gl.ignoreYAxisIndexes.indexOf(index) < 0) {
18895 gl.multiAxisTickAmount = tiks;
18896 }
18897
18898 // build Y label array.
18899
18900 var val = yMin - stepSize;
18901 // Ensure we don't under/over shoot due to JS precision errors.
18902 // This also fixes (amongst others):
18903 // https://github.com/apexcharts/apexcharts.js/issues/430
18904 var err = stepSize * jsPrecision;
18905 do {
18906 val += stepSize;
18907 result.push(Utils$1.stripNumber(val, 7));
18908 } while (yMax - val > err);
18909 return {
18910 result: result,
18911 niceMin: result[0],
18912 niceMax: result[result.length - 1]
18913 };
18914 }
18915 }, {
18916 key: "linearScale",
18917 value: function linearScale(yMin, yMax) {
18918 var ticks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
18919 var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
18920 var step = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
18921 var range = Math.abs(yMax - yMin);
18922 var result = [];
18923 if (yMin === yMax) {
18924 result = [yMin];
18925 return {
18926 result: result,
18927 niceMin: result[0],
18928 niceMax: result[result.length - 1]
18929 };
18930 }
18931 ticks = this._adjustTicksForSmallRange(ticks, index, range);
18932 if (ticks === 'dataPoints') {
18933 ticks = this.w.globals.dataPoints - 1;
18934 }
18935 if (!step) {
18936 step = range / ticks;
18937 }
18938 step = Math.round((step + Number.EPSILON) * 100) / 100;
18939 if (ticks === Number.MAX_VALUE) {
18940 ticks = 5;
18941 step = 1;
18942 }
18943 var v = yMin;
18944 while (ticks >= 0) {
18945 result.push(v);
18946 v = Utils$1.preciseAddition(v, step);
18947 ticks -= 1;
18948 }
18949 return {
18950 result: result,
18951 niceMin: result[0],
18952 niceMax: result[result.length - 1]
18953 };
18954 }
18955 }, {
18956 key: "logarithmicScaleNice",
18957 value: function logarithmicScaleNice(yMin, yMax, base) {
18958 // Basic validation to avoid for loop starting at -inf.
18959 if (yMax <= 0) yMax = Math.max(yMin, base);
18960 if (yMin <= 0) yMin = Math.min(yMax, base);
18961 var logs = [];
18962
18963 // Get powers of base for our max and min
18964 var logMax = Math.ceil(Math.log(yMax) / Math.log(base) + 1);
18965 var logMin = Math.floor(Math.log(yMin) / Math.log(base));
18966 for (var i = logMin; i < logMax; i++) {
18967 logs.push(Math.pow(base, i));
18968 }
18969 return {
18970 result: logs,
18971 niceMin: logs[0],
18972 niceMax: logs[logs.length - 1]
18973 };
18974 }
18975 }, {
18976 key: "logarithmicScale",
18977 value: function logarithmicScale(yMin, yMax, base) {
18978 // Basic validation to avoid for loop starting at -inf.
18979 if (yMax <= 0) yMax = Math.max(yMin, base);
18980 if (yMin <= 0) yMin = Math.min(yMax, base);
18981 var logs = [];
18982
18983 // Get the logarithmic range.
18984 var logMax = Math.log(yMax) / Math.log(base);
18985 var logMin = Math.log(yMin) / Math.log(base);
18986
18987 // Get the exact logarithmic range.
18988 // (This is the exact number of multiples of the base there are between yMin and yMax).
18989 var logRange = logMax - logMin;
18990
18991 // Round the logarithmic range to get the number of ticks we will create.
18992 // If the chosen min/max values are multiples of each other WRT the base, this will be neat.
18993 // If the chosen min/max aren't, we will at least still provide USEFUL ticks.
18994 var ticks = Math.round(logRange);
18995
18996 // Get the logarithmic spacing between ticks.
18997 var logTickSpacing = logRange / ticks;
18998
18999 // Create as many ticks as there is range in the logs.
19000 for (var i = 0, logTick = logMin; i < ticks; i++, logTick += logTickSpacing) {
19001 logs.push(Math.pow(base, logTick));
19002 }
19003
19004 // Add a final tick at the yMax.
19005 logs.push(Math.pow(base, logMax));
19006 return {
19007 result: logs,
19008 niceMin: yMin,
19009 niceMax: yMax
19010 };
19011 }
19012 }, {
19013 key: "_adjustTicksForSmallRange",
19014 value: function _adjustTicksForSmallRange(ticks, index, range) {
19015 var newTicks = ticks;
19016 if (typeof index !== 'undefined' && this.w.config.yaxis[index].labels.formatter && this.w.config.yaxis[index].tickAmount === undefined) {
19017 var formattedVal = Number(this.w.config.yaxis[index].labels.formatter(1));
19018 if (Utils$1.isNumber(formattedVal) && this.w.globals.yValueDecimal === 0) {
19019 newTicks = Math.ceil(range);
19020 }
19021 }
19022 return newTicks < ticks ? newTicks : ticks;
19023 }
19024 }, {
19025 key: "setYScaleForIndex",
19026 value: function setYScaleForIndex(index, minY, maxY) {
19027 var gl = this.w.globals;
19028 var cnf = this.w.config;
19029 var y = gl.isBarHorizontal ? cnf.xaxis : cnf.yaxis[index];
19030 if (typeof gl.yAxisScale[index] === 'undefined') {
19031 gl.yAxisScale[index] = [];
19032 }
19033 var range = Math.abs(maxY - minY);
19034 if (y.logarithmic && range <= 5) {
19035 gl.invalidLogScale = true;
19036 }
19037 if (y.logarithmic && range > 5) {
19038 gl.allSeriesCollapsed = false;
19039 gl.yAxisScale[index] = y.forceNiceScale ? this.logarithmicScaleNice(minY, maxY, y.logBase) : this.logarithmicScale(minY, maxY, y.logBase);
19040 } else {
19041 if (maxY === -Number.MAX_VALUE || !Utils$1.isNumber(maxY) || minY === Number.MAX_VALUE || !Utils$1.isNumber(minY)) {
19042 // no data in the chart.
19043 // Either all series collapsed or user passed a blank array.
19044 // Show the user's yaxis with their scale options but with a range.
19045 gl.yAxisScale[index] = this.niceScale(Number.MIN_VALUE, 0, index);
19046 } else {
19047 // there is some data. Turn off the allSeriesCollapsed flag
19048 gl.allSeriesCollapsed = false;
19049 gl.yAxisScale[index] = this.niceScale(minY, maxY, index);
19050 }
19051 }
19052 }
19053 }, {
19054 key: "setXScale",
19055 value: function setXScale(minX, maxX) {
19056 var w = this.w;
19057 var gl = w.globals;
19058 if (maxX === -Number.MAX_VALUE || !Utils$1.isNumber(maxX)) {
19059 // no data in the chart. Either all series collapsed or user passed a blank array
19060 gl.xAxisScale = this.linearScale(0, 10, 10);
19061 } else {
19062 var ticks = gl.xTickAmount;
19063 gl.xAxisScale = this.linearScale(minX, maxX, ticks, 0, w.config.xaxis.stepSize);
19064 }
19065 return gl.xAxisScale;
19066 }
19067 }, {
19068 key: "scaleMultipleYAxes",
19069 value: function scaleMultipleYAxes() {
19070 var _this = this;
19071 var cnf = this.w.config;
19072 var gl = this.w.globals;
19073 this.coreUtils.setSeriesYAxisMappings();
19074 var axisSeriesMap = gl.seriesYAxisMap;
19075 var minYArr = gl.minYArr;
19076 var maxYArr = gl.maxYArr;
19077
19078 // Compute min..max for each yaxis
19079 gl.allSeriesCollapsed = true;
19080 gl.barGroups = [];
19081 axisSeriesMap.forEach(function (axisSeries, ai) {
19082 var groupNames = [];
19083 axisSeries.forEach(function (as) {
19084 var _cnf$series$as;
19085 var group = (_cnf$series$as = cnf.series[as]) === null || _cnf$series$as === void 0 ? void 0 : _cnf$series$as.group;
19086 if (groupNames.indexOf(group) < 0) {
19087 groupNames.push(group);
19088 }
19089 });
19090 if (axisSeries.length > 0) {
19091 (function () {
19092 var minY = Number.MAX_VALUE;
19093 var maxY = -Number.MAX_VALUE;
19094 var lowestY = minY;
19095 var highestY = maxY;
19096 var seriesType;
19097 var seriesGroupName;
19098 if (cnf.chart.stacked) {
19099 (function () {
19100 // Series' on this axis with the same group name will be stacked.
19101 // Sum series in each group separately
19102 var mapSeries = new Array(gl.dataPoints).fill(0);
19103 var sumSeries = [];
19104 var posSeries = [];
19105 var negSeries = [];
19106 groupNames.forEach(function () {
19107 sumSeries.push(mapSeries.map(function () {
19108 return Number.MIN_VALUE;
19109 }));
19110 posSeries.push(mapSeries.map(function () {
19111 return Number.MIN_VALUE;
19112 }));
19113 negSeries.push(mapSeries.map(function () {
19114 return Number.MIN_VALUE;
19115 }));
19116 });
19117 var _loop = function _loop(i) {
19118 // Assume chart type but the first series that has a type overrides.
19119 if (!seriesType && cnf.series[axisSeries[i]].type) {
19120 seriesType = cnf.series[axisSeries[i]].type;
19121 }
19122 // Sum all series for this yaxis at each corresponding datapoint
19123 // For bar and column charts we need to keep positive and negative
19124 // values separate, for each group separately.
19125 var si = axisSeries[i];
19126 if (cnf.series[si].group) {
19127 seriesGroupName = cnf.series[si].group;
19128 } else {
19129 seriesGroupName = 'axis-'.concat(ai);
19130 }
19131 var collapsed = !(gl.collapsedSeriesIndices.indexOf(si) < 0 && gl.ancillaryCollapsedSeriesIndices.indexOf(si) < 0);
19132 if (!collapsed) {
19133 gl.allSeriesCollapsed = false;
19134 groupNames.forEach(function (gn, gni) {
19135 // Undefined group names will be grouped together as their own
19136 // group.
19137 if (cnf.series[si].group === gn) {
19138 for (var j = 0; j < gl.series[si].length; j++) {
19139 var val = gl.series[si][j];
19140 if (val >= 0) {
19141 posSeries[gni][j] += val;
19142 } else {
19143 negSeries[gni][j] += val;
19144 }
19145 sumSeries[gni][j] += val;
19146 // For non bar-like series' we need these point max/min values.
19147 lowestY = Math.min(lowestY, val);
19148 highestY = Math.max(highestY, val);
19149 }
19150 }
19151 });
19152 }
19153 if (seriesType === 'bar' || seriesType === 'column') {
19154 gl.barGroups.push(seriesGroupName);
19155 }
19156 };
19157 for (var i = 0; i < axisSeries.length; i++) {
19158 _loop(i);
19159 }
19160 if (!seriesType) {
19161 seriesType = cnf.chart.type;
19162 }
19163 if (seriesType === 'bar' || seriesType === 'column') {
19164 groupNames.forEach(function (gn, gni) {
19165 minY = Math.min(minY, Math.min.apply(null, negSeries[gni]));
19166 maxY = Math.max(maxY, Math.max.apply(null, posSeries[gni]));
19167 });
19168 } else {
19169 groupNames.forEach(function (gn, gni) {
19170 lowestY = Math.min(lowestY, Math.min.apply(null, sumSeries[gni]));
19171 highestY = Math.max(highestY, Math.max.apply(null, sumSeries[gni]));
19172 });
19173 minY = lowestY;
19174 maxY = highestY;
19175 }
19176 if (minY === Number.MIN_VALUE && maxY === Number.MIN_VALUE) {
19177 // No series data
19178 maxY = -Number.MAX_VALUE;
19179 }
19180 })();
19181 } else {
19182 for (var i = 0; i < axisSeries.length; i++) {
19183 var si = axisSeries[i];
19184 minY = Math.min(minY, minYArr[si]);
19185 maxY = Math.max(maxY, maxYArr[si]);
19186 var collapsed = !(gl.collapsedSeriesIndices.indexOf(si) < 0 && gl.ancillaryCollapsedSeriesIndices.indexOf(si) < 0);
19187 if (!collapsed) {
19188 gl.allSeriesCollapsed = false;
19189 }
19190 }
19191 }
19192 if (cnf.yaxis[ai].min !== undefined) {
19193 if (typeof cnf.yaxis[ai].min === 'function') {
19194 minY = cnf.yaxis[ai].min(minY);
19195 } else {
19196 minY = cnf.yaxis[ai].min;
19197 }
19198 }
19199 if (cnf.yaxis[ai].max !== undefined) {
19200 if (typeof cnf.yaxis[ai].max === 'function') {
19201 maxY = cnf.yaxis[ai].max(maxY);
19202 } else {
19203 maxY = cnf.yaxis[ai].max;
19204 }
19205 }
19206 gl.barGroups = gl.barGroups.filter(function (v, i, a) {
19207 return a.indexOf(v) === i;
19208 });
19209 // Set the scale for this yaxis
19210 _this.setYScaleForIndex(ai, minY, maxY);
19211 // Set individual series min and max to nice values
19212 axisSeries.forEach(function (si) {
19213 minYArr[si] = gl.yAxisScale[ai].niceMin;
19214 maxYArr[si] = gl.yAxisScale[ai].niceMax;
19215 });
19216 })();
19217 } else {
19218 // No series referenced by this yaxis
19219 _this.setYScaleForIndex(ai, 0, -Number.MAX_VALUE);
19220 }
19221 });
19222 }
19223 }]);
19224 return Scales;
19225 }();
19226
19227 /**
19228 * Range is used to generates values between min and max.
19229 *
19230 * @module Range
19231 **/
19232 var Range = /*#__PURE__*/function () {
19233 function Range(ctx) {
19234 _classCallCheck(this, Range);
19235 this.ctx = ctx;
19236 this.w = ctx.w;
19237 this.scales = new Scales(ctx);
19238 }
19239 _createClass(Range, [{
19240 key: "init",
19241 value: function init() {
19242 this.setYRange();
19243 this.setXRange();
19244 this.setZRange();
19245 }
19246 }, {
19247 key: "getMinYMaxY",
19248 value: function getMinYMaxY(startingSeriesIndex) {
19249 var lowestY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.MAX_VALUE;
19250 var highestY = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -Number.MAX_VALUE;
19251 var endingSeriesIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
19252 var cnf = this.w.config;
19253 var gl = this.w.globals;
19254 var maxY = -Number.MAX_VALUE;
19255 var minY = Number.MIN_VALUE;
19256 if (endingSeriesIndex === null) {
19257 endingSeriesIndex = startingSeriesIndex + 1;
19258 }
19259 var series = gl.series;
19260 var seriesMin = series;
19261 var seriesMax = series;
19262 if (cnf.chart.type === 'candlestick') {
19263 seriesMin = gl.seriesCandleL;
19264 seriesMax = gl.seriesCandleH;
19265 } else if (cnf.chart.type === 'boxPlot') {
19266 seriesMin = gl.seriesCandleO;
19267 seriesMax = gl.seriesCandleC;
19268 } else if (gl.isRangeData) {
19269 seriesMin = gl.seriesRangeStart;
19270 seriesMax = gl.seriesRangeEnd;
19271 }
19272 var autoScaleYaxis = false;
19273 if (gl.seriesX.length >= endingSeriesIndex) {
19274 var _gl$brushSource;
19275 // Eventually brushSource will be set if the current chart is a target.
19276 // That is, after the appropriate event causes us to update.
19277 var brush = (_gl$brushSource = gl.brushSource) === null || _gl$brushSource === void 0 ? void 0 : _gl$brushSource.w.config.chart.brush;
19278 if (cnf.chart.zoom.enabled && cnf.chart.zoom.autoScaleYaxis || brush !== null && brush !== void 0 && brush.enabled && brush !== null && brush !== void 0 && brush.autoScaleYaxis) {
19279 autoScaleYaxis = true;
19280 }
19281 }
19282 for (var i = startingSeriesIndex; i < endingSeriesIndex; i++) {
19283 gl.dataPoints = Math.max(gl.dataPoints, series[i].length);
19284 var seriesType = cnf.series[i].type;
19285 if (gl.categoryLabels.length) {
19286 gl.dataPoints = gl.categoryLabels.filter(function (label) {
19287 return typeof label !== 'undefined';
19288 }).length;
19289 }
19290 if (gl.labels.length && cnf.xaxis.type !== 'datetime' && gl.series.reduce(function (a, c) {
19291 return a + c.length;
19292 }, 0) !== 0) {
19293 // the condition cnf.xaxis.type !== 'datetime' fixes #3897 and #3905
19294 gl.dataPoints = Math.max(gl.dataPoints, gl.labels.length);
19295 }
19296 var firstXIndex = 0;
19297 var lastXIndex = series[i].length - 1;
19298 if (autoScaleYaxis) {
19299 // Scale the Y axis to the min..max within the possibly zoomed X axis domain.
19300 if (cnf.xaxis.min) {
19301 for (; firstXIndex < lastXIndex && gl.seriesX[i][firstXIndex] < cnf.xaxis.min; firstXIndex++) {}
19302 }
19303 if (cnf.xaxis.max) {
19304 for (; lastXIndex > firstXIndex && gl.seriesX[i][lastXIndex] > cnf.xaxis.max; lastXIndex--) {}
19305 }
19306 }
19307 for (var j = firstXIndex; j <= lastXIndex && j < gl.series[i].length; j++) {
19308 var val = series[i][j];
19309 if (val !== null && Utils$1.isNumber(val)) {
19310 var _seriesMax$i, _seriesMin$i, _seriesMin$i2, _seriesMin$i3;
19311 if (typeof ((_seriesMax$i = seriesMax[i]) === null || _seriesMax$i === void 0 ? void 0 : _seriesMax$i[j]) !== 'undefined') {
19312 maxY = Math.max(maxY, seriesMax[i][j]);
19313 lowestY = Math.min(lowestY, seriesMax[i][j]);
19314 }
19315 if (typeof ((_seriesMin$i = seriesMin[i]) === null || _seriesMin$i === void 0 ? void 0 : _seriesMin$i[j]) !== 'undefined') {
19316 lowestY = Math.min(lowestY, seriesMin[i][j]);
19317 highestY = Math.max(highestY, seriesMin[i][j]);
19318 }
19319
19320 // These series arrays are dual purpose:
19321 // Array : CandleO, CandleH, CandleM, CandleL, CandleC
19322 // Candlestick: O H L C
19323 // Boxplot : Min Q1 Median Q3 Max
19324 switch (seriesType) {
19325 case 'candlestick':
19326 {
19327 if (typeof gl.seriesCandleC[i][j] !== 'undefined') {
19328 maxY = Math.max(maxY, gl.seriesCandleH[i][j]);
19329 lowestY = Math.min(lowestY, gl.seriesCandleL[i][j]);
19330 }
19331 }
19332 break;
19333 case 'boxPlot':
19334 {
19335 if (typeof gl.seriesCandleC[i][j] !== 'undefined') {
19336 maxY = Math.max(maxY, gl.seriesCandleC[i][j]);
19337 lowestY = Math.min(lowestY, gl.seriesCandleO[i][j]);
19338 }
19339 }
19340 break;
19341 }
19342
19343 // there is a combo chart and the specified series in not either
19344 // candlestick, boxplot, or rangeArea/rangeBar; find the max there.
19345 if (seriesType && seriesType !== 'candlestick' && seriesType !== 'boxPlot' && seriesType !== 'rangeArea' && seriesType !== 'rangeBar') {
19346 maxY = Math.max(maxY, gl.series[i][j]);
19347 lowestY = Math.min(lowestY, gl.series[i][j]);
19348 }
19349 if (gl.seriesGoals[i] && gl.seriesGoals[i][j] && Array.isArray(gl.seriesGoals[i][j])) {
19350 gl.seriesGoals[i][j].forEach(function (g) {
19351 maxY = Math.max(maxY, g.value);
19352 lowestY = Math.min(lowestY, g.value);
19353 });
19354 }
19355 highestY = maxY;
19356 val = Utils$1.noExponents(val);
19357 if (Utils$1.isFloat(val)) {
19358 gl.yValueDecimal = Math.max(gl.yValueDecimal, val.toString().split('.')[1].length);
19359 }
19360 if (minY > ((_seriesMin$i2 = seriesMin[i]) === null || _seriesMin$i2 === void 0 ? void 0 : _seriesMin$i2[j]) && ((_seriesMin$i3 = seriesMin[i]) === null || _seriesMin$i3 === void 0 ? void 0 : _seriesMin$i3[j]) < 0) {
19361 minY = seriesMin[i][j];
19362 }
19363 } else {
19364 gl.hasNullValues = true;
19365 }
19366 }
19367 if (seriesType === 'bar' || seriesType === 'column') {
19368 if (minY < 0 && maxY < 0) {
19369 // all negative values in a bar series, hence make the max to 0
19370 maxY = 0;
19371 highestY = Math.max(highestY, 0);
19372 }
19373 if (minY === Number.MIN_VALUE) {
19374 minY = 0;
19375 lowestY = Math.min(lowestY, 0);
19376 }
19377 }
19378 }
19379 if (cnf.chart.type === 'rangeBar' && gl.seriesRangeStart.length && gl.isBarHorizontal) {
19380 minY = lowestY;
19381 }
19382 if (cnf.chart.type === 'bar') {
19383 if (minY < 0 && maxY < 0) {
19384 // all negative values in a bar chart, hence make the max to 0
19385 maxY = 0;
19386 }
19387 if (minY === Number.MIN_VALUE) {
19388 minY = 0;
19389 }
19390 }
19391 return {
19392 minY: minY,
19393 maxY: maxY,
19394 lowestY: lowestY,
19395 highestY: highestY
19396 };
19397 }
19398 }, {
19399 key: "setYRange",
19400 value: function setYRange() {
19401 var gl = this.w.globals;
19402 var cnf = this.w.config;
19403 gl.maxY = -Number.MAX_VALUE;
19404 gl.minY = Number.MIN_VALUE;
19405 var lowestYInAllSeries = Number.MAX_VALUE;
19406 var minYMaxY;
19407 if (gl.isMultipleYAxis) {
19408 // we need to get minY and maxY for multiple y axis
19409 lowestYInAllSeries = Number.MAX_VALUE;
19410 for (var i = 0; i < gl.series.length; i++) {
19411 minYMaxY = this.getMinYMaxY(i);
19412 gl.minYArr[i] = minYMaxY.lowestY;
19413 gl.maxYArr[i] = minYMaxY.highestY;
19414 lowestYInAllSeries = Math.min(lowestYInAllSeries, minYMaxY.lowestY);
19415 }
19416 }
19417
19418 // and then, get the minY and maxY from all series
19419 minYMaxY = this.getMinYMaxY(0, lowestYInAllSeries, null, gl.series.length);
19420 if (cnf.chart.type === 'bar') {
19421 gl.minY = minYMaxY.minY;
19422 gl.maxY = minYMaxY.maxY;
19423 } else {
19424 gl.minY = minYMaxY.lowestY;
19425 gl.maxY = minYMaxY.highestY;
19426 }
19427 lowestYInAllSeries = minYMaxY.lowestY;
19428 if (cnf.chart.stacked) {
19429 this._setStackedMinMax();
19430 }
19431
19432 // if the numbers are too big, reduce the range
19433 // for eg, if number is between 100000-110000, putting 0 as the lowest
19434 // value is not so good idea. So change the gl.minY for
19435 // line/area/scatter/candlesticks/boxPlot/vertical rangebar
19436 if (cnf.chart.type === 'line' || cnf.chart.type === 'area' || cnf.chart.type === 'scatter' || cnf.chart.type === 'candlestick' || cnf.chart.type === 'boxPlot' || cnf.chart.type === 'rangeBar' && !gl.isBarHorizontal) {
19437 if (gl.minY === Number.MIN_VALUE && lowestYInAllSeries !== -Number.MAX_VALUE && lowestYInAllSeries !== gl.maxY // single value possibility
19438 ) {
19439 gl.minY = lowestYInAllSeries;
19440 }
19441 } else {
19442 gl.minY = gl.minY !== Number.MIN_VALUE ? Math.min(minYMaxY.minY, gl.minY) : minYMaxY.minY;
19443 }
19444 cnf.yaxis.forEach(function (yaxe, index) {
19445 // override all min/max values by user defined values (y axis)
19446 if (yaxe.max !== undefined) {
19447 if (typeof yaxe.max === 'number') {
19448 gl.maxYArr[index] = yaxe.max;
19449 } else if (typeof yaxe.max === 'function') {
19450 // fixes apexcharts.js/issues/2098
19451 gl.maxYArr[index] = yaxe.max(gl.isMultipleYAxis ? gl.maxYArr[index] : gl.maxY);
19452 }
19453
19454 // gl.maxY is for single y-axis chart, it will be ignored in multi-yaxis
19455 gl.maxY = gl.maxYArr[index];
19456 }
19457 if (yaxe.min !== undefined) {
19458 if (typeof yaxe.min === 'number') {
19459 gl.minYArr[index] = yaxe.min;
19460 } else if (typeof yaxe.min === 'function') {
19461 // fixes apexcharts.js/issues/2098
19462 gl.minYArr[index] = yaxe.min(gl.isMultipleYAxis ? gl.minYArr[index] === Number.MIN_VALUE ? 0 : gl.minYArr[index] : gl.minY);
19463 }
19464 // gl.minY is for single y-axis chart, it will be ignored in multi-yaxis
19465 gl.minY = gl.minYArr[index];
19466 }
19467 });
19468
19469 // for horizontal bar charts, we need to check xaxis min/max as user may have specified there
19470 if (gl.isBarHorizontal) {
19471 var minmax = ['min', 'max'];
19472 minmax.forEach(function (m) {
19473 if (cnf.xaxis[m] !== undefined && typeof cnf.xaxis[m] === 'number') {
19474 m === 'min' ? gl.minY = cnf.xaxis[m] : gl.maxY = cnf.xaxis[m];
19475 }
19476 });
19477 }
19478 if (gl.isMultipleYAxis) {
19479 this.scales.scaleMultipleYAxes();
19480 gl.minY = lowestYInAllSeries;
19481 } else {
19482 this.scales.setYScaleForIndex(0, gl.minY, gl.maxY);
19483 gl.minY = gl.yAxisScale[0].niceMin;
19484 gl.maxY = gl.yAxisScale[0].niceMax;
19485 gl.minYArr[0] = gl.minY;
19486 gl.maxYArr[0] = gl.maxY;
19487 }
19488 gl.barGroups = [];
19489 gl.lineGroups = [];
19490 gl.areaGroups = [];
19491 cnf.series.forEach(function (s) {
19492 var type = s.type || cnf.chart.type;
19493 switch (type) {
19494 case 'bar':
19495 case 'column':
19496 gl.barGroups.push(s.group);
19497 break;
19498 case 'line':
19499 gl.lineGroups.push(s.group);
19500 break;
19501 case 'area':
19502 gl.areaGroups.push(s.group);
19503 break;
19504 }
19505 });
19506 // Uniquify the group names in each stackable chart type.
19507 gl.barGroups = gl.barGroups.filter(function (v, i, a) {
19508 return a.indexOf(v) === i;
19509 });
19510 gl.lineGroups = gl.lineGroups.filter(function (v, i, a) {
19511 return a.indexOf(v) === i;
19512 });
19513 gl.areaGroups = gl.areaGroups.filter(function (v, i, a) {
19514 return a.indexOf(v) === i;
19515 });
19516 return {
19517 minY: gl.minY,
19518 maxY: gl.maxY,
19519 minYArr: gl.minYArr,
19520 maxYArr: gl.maxYArr,
19521 yAxisScale: gl.yAxisScale
19522 };
19523 }
19524 }, {
19525 key: "setXRange",
19526 value: function setXRange() {
19527 var gl = this.w.globals;
19528 var cnf = this.w.config;
19529 var isXNumeric = cnf.xaxis.type === 'numeric' || cnf.xaxis.type === 'datetime' || cnf.xaxis.type === 'category' && !gl.noLabelsProvided || gl.noLabelsProvided || gl.isXNumeric;
19530 var getInitialMinXMaxX = function getInitialMinXMaxX() {
19531 for (var i = 0; i < gl.series.length; i++) {
19532 if (gl.labels[i]) {
19533 for (var j = 0; j < gl.labels[i].length; j++) {
19534 if (gl.labels[i][j] !== null && Utils$1.isNumber(gl.labels[i][j])) {
19535 gl.maxX = Math.max(gl.maxX, gl.labels[i][j]);
19536 gl.initialMaxX = Math.max(gl.maxX, gl.labels[i][j]);
19537 gl.minX = Math.min(gl.minX, gl.labels[i][j]);
19538 gl.initialMinX = Math.min(gl.minX, gl.labels[i][j]);
19539 }
19540 }
19541 }
19542 }
19543 };
19544 // minX maxX starts here
19545 if (gl.isXNumeric) {
19546 getInitialMinXMaxX();
19547 }
19548 if (gl.noLabelsProvided) {
19549 if (cnf.xaxis.categories.length === 0) {
19550 gl.maxX = gl.labels[gl.labels.length - 1];
19551 gl.initialMaxX = gl.labels[gl.labels.length - 1];
19552 gl.minX = 1;
19553 gl.initialMinX = 1;
19554 }
19555 }
19556 if (gl.isXNumeric || gl.noLabelsProvided || gl.dataFormatXNumeric) {
19557 var ticks = 10;
19558 if (cnf.xaxis.tickAmount === undefined) {
19559 ticks = Math.round(gl.svgWidth / 150);
19560
19561 // no labels provided and total number of dataPoints is less than 30
19562 if (cnf.xaxis.type === 'numeric' && gl.dataPoints < 30) {
19563 ticks = gl.dataPoints - 1;
19564 }
19565
19566 // this check is for when ticks exceeds total datapoints and that would result in duplicate labels
19567 if (ticks > gl.dataPoints && gl.dataPoints !== 0) {
19568 ticks = gl.dataPoints - 1;
19569 }
19570 } else if (cnf.xaxis.tickAmount === 'dataPoints') {
19571 if (gl.series.length > 1) {
19572 ticks = gl.series[gl.maxValsInArrayIndex].length - 1;
19573 }
19574 if (gl.isXNumeric) {
19575 var diff = Math.round(gl.maxX - gl.minX);
19576 if (diff < 30) {
19577 ticks = diff - 1;
19578 }
19579 }
19580 } else {
19581 ticks = cnf.xaxis.tickAmount;
19582 }
19583 gl.xTickAmount = ticks;
19584
19585 // override all min/max values by user defined values (x axis)
19586 if (cnf.xaxis.max !== undefined && typeof cnf.xaxis.max === 'number') {
19587 gl.maxX = cnf.xaxis.max;
19588 }
19589 if (cnf.xaxis.min !== undefined && typeof cnf.xaxis.min === 'number') {
19590 gl.minX = cnf.xaxis.min;
19591 }
19592
19593 // if range is provided, adjust the new minX
19594 if (cnf.xaxis.range !== undefined) {
19595 gl.minX = gl.maxX - cnf.xaxis.range;
19596 }
19597 if (gl.minX !== Number.MAX_VALUE && gl.maxX !== -Number.MAX_VALUE) {
19598 if (cnf.xaxis.convertedCatToNumeric && !gl.dataFormatXNumeric) {
19599 var catScale = [];
19600 for (var i = gl.minX - 1; i < gl.maxX; i++) {
19601 catScale.push(i + 1);
19602 }
19603 gl.xAxisScale = {
19604 result: catScale,
19605 niceMin: catScale[0],
19606 niceMax: catScale[catScale.length - 1]
19607 };
19608 } else {
19609 gl.xAxisScale = this.scales.setXScale(gl.minX, gl.maxX);
19610 }
19611 } else {
19612 gl.xAxisScale = this.scales.linearScale(0, ticks, ticks, 0, cnf.xaxis.stepSize);
19613 if (gl.noLabelsProvided && gl.labels.length > 0) {
19614 gl.xAxisScale = this.scales.linearScale(1, gl.labels.length, ticks - 1, 0, cnf.xaxis.stepSize);
19615
19616 // this is the only place seriesX is again mutated
19617 gl.seriesX = gl.labels.slice();
19618 }
19619 }
19620 // we will still store these labels as the count for this will be different (to draw grid and labels placement)
19621 if (isXNumeric) {
19622 gl.labels = gl.xAxisScale.result.slice();
19623 }
19624 }
19625 if (gl.isBarHorizontal && gl.labels.length) {
19626 gl.xTickAmount = gl.labels.length;
19627 }
19628
19629 // single dataPoint
19630 this._handleSingleDataPoint();
19631
19632 // minimum x difference to calculate bar width in numeric bars
19633 this._getMinXDiff();
19634 return {
19635 minX: gl.minX,
19636 maxX: gl.maxX
19637 };
19638 }
19639 }, {
19640 key: "setZRange",
19641 value: function setZRange() {
19642 // minZ, maxZ starts here
19643 var gl = this.w.globals;
19644 if (!gl.isDataXYZ) return;
19645 for (var i = 0; i < gl.series.length; i++) {
19646 if (typeof gl.seriesZ[i] !== 'undefined') {
19647 for (var j = 0; j < gl.seriesZ[i].length; j++) {
19648 if (gl.seriesZ[i][j] !== null && Utils$1.isNumber(gl.seriesZ[i][j])) {
19649 gl.maxZ = Math.max(gl.maxZ, gl.seriesZ[i][j]);
19650 gl.minZ = Math.min(gl.minZ, gl.seriesZ[i][j]);
19651 }
19652 }
19653 }
19654 }
19655 }
19656 }, {
19657 key: "_handleSingleDataPoint",
19658 value: function _handleSingleDataPoint() {
19659 var gl = this.w.globals;
19660 var cnf = this.w.config;
19661 if (gl.minX === gl.maxX) {
19662 var datetimeObj = new DateTime(this.ctx);
19663 if (cnf.xaxis.type === 'datetime') {
19664 var newMinX = datetimeObj.getDate(gl.minX);
19665 if (cnf.xaxis.labels.datetimeUTC) {
19666 newMinX.setUTCDate(newMinX.getUTCDate() - 2);
19667 } else {
19668 newMinX.setDate(newMinX.getDate() - 2);
19669 }
19670 gl.minX = new Date(newMinX).getTime();
19671 var newMaxX = datetimeObj.getDate(gl.maxX);
19672 if (cnf.xaxis.labels.datetimeUTC) {
19673 newMaxX.setUTCDate(newMaxX.getUTCDate() + 2);
19674 } else {
19675 newMaxX.setDate(newMaxX.getDate() + 2);
19676 }
19677 gl.maxX = new Date(newMaxX).getTime();
19678 } else if (cnf.xaxis.type === 'numeric' || cnf.xaxis.type === 'category' && !gl.noLabelsProvided) {
19679 gl.minX = gl.minX - 2;
19680 gl.initialMinX = gl.minX;
19681 gl.maxX = gl.maxX + 2;
19682 gl.initialMaxX = gl.maxX;
19683 }
19684 }
19685 }
19686 }, {
19687 key: "_getMinXDiff",
19688 value: function _getMinXDiff() {
19689 var gl = this.w.globals;
19690 if (gl.isXNumeric) {
19691 // get the least x diff if numeric x axis is present
19692 gl.seriesX.forEach(function (sX, i) {
19693 if (sX.length) {
19694 if (sX.length === 1) {
19695 // a small hack to prevent overlapping multiple bars when there is just 1 datapoint in bar series.
19696 // fix #811
19697 sX.push(gl.seriesX[gl.maxValsInArrayIndex][gl.seriesX[gl.maxValsInArrayIndex].length - 1]);
19698 }
19699
19700 // fix #983 (clone the array to avoid side effects)
19701 var seriesX = sX.slice();
19702 seriesX.sort(function (a, b) {
19703 return a - b;
19704 });
19705 seriesX.forEach(function (s, j) {
19706 if (j > 0) {
19707 var xDiff = s - seriesX[j - 1];
19708 if (xDiff > 0) {
19709 gl.minXDiff = Math.min(xDiff, gl.minXDiff);
19710 }
19711 }
19712 });
19713 if (gl.dataPoints === 1 || gl.minXDiff === Number.MAX_VALUE) {
19714 // fixes apexcharts.js #1221
19715 gl.minXDiff = 0.5;
19716 }
19717 }
19718 });
19719 }
19720 }
19721 }, {
19722 key: "_setStackedMinMax",
19723 value: function _setStackedMinMax() {
19724 var _this = this;
19725 var gl = this.w.globals;
19726 // for stacked charts, we calculate each series's parallel values.
19727 // i.e, series[0][j] + series[1][j] .... [series[i.length][j]]
19728 // and get the max out of it
19729
19730 if (!gl.series.length) return;
19731 var seriesGroups = gl.seriesGroups;
19732 if (!seriesGroups.length) {
19733 seriesGroups = [this.w.globals.seriesNames.map(function (name) {
19734 return name;
19735 })];
19736 }
19737 var stackedPoss = {};
19738 var stackedNegs = {};
19739 seriesGroups.forEach(function (group) {
19740 stackedPoss[group] = [];
19741 stackedNegs[group] = [];
19742 var indicesOfSeriesInGroup = _this.w.config.series.map(function (serie, si) {
19743 return group.indexOf(gl.seriesNames[si]) > -1 ? si : null;
19744 }).filter(function (f) {
19745 return f !== null;
19746 });
19747 indicesOfSeriesInGroup.forEach(function (i) {
19748 for (var j = 0; j < gl.series[gl.maxValsInArrayIndex].length; j++) {
19749 var _this$w$config$series, _this$w$config$series2, _this$w$config$series3, _this$w$config$series4;
19750 if (typeof stackedPoss[group][j] === 'undefined') {
19751 stackedPoss[group][j] = 0;
19752 stackedNegs[group][j] = 0;
19753 }
19754 var stackSeries = _this.w.config.chart.stacked && !gl.comboCharts || _this.w.config.chart.stacked && gl.comboCharts && (!_this.w.config.chart.stackOnlyBar || ((_this$w$config$series = _this.w.config.series) === null || _this$w$config$series === void 0 ? void 0 : (_this$w$config$series2 = _this$w$config$series[i]) === null || _this$w$config$series2 === void 0 ? void 0 : _this$w$config$series2.type) === 'bar' || ((_this$w$config$series3 = _this.w.config.series) === null || _this$w$config$series3 === void 0 ? void 0 : (_this$w$config$series4 = _this$w$config$series3[i]) === null || _this$w$config$series4 === void 0 ? void 0 : _this$w$config$series4.type) === 'column');
19755 if (stackSeries) {
19756 if (gl.series[i][j] !== null && Utils$1.isNumber(gl.series[i][j])) {
19757 gl.series[i][j] > 0 ? stackedPoss[group][j] += parseFloat(gl.series[i][j]) + 0.0001 : stackedNegs[group][j] += parseFloat(gl.series[i][j]);
19758 }
19759 }
19760 }
19761 });
19762 });
19763 Object.entries(stackedPoss).forEach(function (_ref) {
19764 var _ref2 = _slicedToArray(_ref, 1),
19765 key = _ref2[0];
19766 stackedPoss[key].forEach(function (_, stgi) {
19767 gl.maxY = Math.max(gl.maxY, stackedPoss[key][stgi]);
19768 gl.minY = Math.min(gl.minY, stackedNegs[key][stgi]);
19769 });
19770 });
19771 }
19772 }]);
19773 return Range;
19774 }();
19775
19776 /**
19777 * ApexCharts YAxis Class for drawing Y-Axis.
19778 *
19779 * @module YAxis
19780 **/
19781 var YAxis = /*#__PURE__*/function () {
19782 function YAxis(ctx, elgrid) {
19783 _classCallCheck(this, YAxis);
19784 this.ctx = ctx;
19785 this.elgrid = elgrid;
19786 this.w = ctx.w;
19787 var w = this.w;
19788 this.xaxisFontSize = w.config.xaxis.labels.style.fontSize;
19789 this.axisFontFamily = w.config.xaxis.labels.style.fontFamily;
19790 this.xaxisForeColors = w.config.xaxis.labels.style.colors;
19791 this.isCategoryBarHorizontal = w.config.chart.type === 'bar' && w.config.plotOptions.bar.horizontal;
19792 this.xAxisoffX = w.config.xaxis.position === 'bottom' ? w.globals.gridHeight : 0;
19793 this.drawnLabels = [];
19794 this.axesUtils = new AxesUtils(ctx);
19795 }
19796 _createClass(YAxis, [{
19797 key: "drawYaxis",
19798 value: function drawYaxis(realIndex) {
19799 var w = this.w;
19800 var graphics = new Graphics(this.ctx);
19801 var yaxisStyle = w.config.yaxis[realIndex].labels.style;
19802 var yaxisFontSize = yaxisStyle.fontSize,
19803 yaxisFontFamily = yaxisStyle.fontFamily,
19804 yaxisFontWeight = yaxisStyle.fontWeight;
19805 var elYaxis = graphics.group({
19806 class: 'apexcharts-yaxis',
19807 rel: realIndex,
19808 transform: "translate(".concat(w.globals.translateYAxisX[realIndex], ", 0)")
19809 });
19810 if (this.axesUtils.isYAxisHidden(realIndex)) return elYaxis;
19811 var elYaxisTexts = graphics.group({
19812 class: 'apexcharts-yaxis-texts-g'
19813 });
19814 elYaxis.add(elYaxisTexts);
19815 var tickAmount = w.globals.yAxisScale[realIndex].result.length - 1;
19816 var labelsDivider = w.globals.gridHeight / tickAmount;
19817 var lbFormatter = w.globals.yLabelFormatters[realIndex];
19818 var labels = this.axesUtils.checkForReversedLabels(realIndex, w.globals.yAxisScale[realIndex].result.slice());
19819 if (w.config.yaxis[realIndex].labels.show) {
19820 var lY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY;
19821 if (w.globals.isBarHorizontal) lY = 0;else if (w.config.chart.type === 'heatmap') lY -= labelsDivider / 2;
19822 lY += parseInt(yaxisFontSize, 10) / 3;
19823 for (var i = tickAmount; i >= 0; i--) {
19824 var val = lbFormatter(labels[i], i, w);
19825 var xPad = w.config.yaxis[realIndex].labels.padding;
19826 if (w.config.yaxis[realIndex].opposite && w.config.yaxis.length !== 0) xPad *= -1;
19827 var textAnchor = this.getTextAnchor(w.config.yaxis[realIndex].labels.align, w.config.yaxis[realIndex].opposite);
19828 var yColors = this.axesUtils.getYAxisForeColor(yaxisStyle.colors, realIndex);
19829 var foreColor = Array.isArray(yColors) ? yColors[i] : yColors;
19830 var existingYLabels = Utils$1.listToArray(w.globals.dom.baseEl.querySelectorAll(".apexcharts-yaxis[rel='".concat(realIndex, "'] .apexcharts-yaxis-label tspan"))).map(function (label) {
19831 return label.textContent;
19832 });
19833 var label = graphics.drawText({
19834 x: xPad,
19835 y: lY,
19836 text: existingYLabels.includes(val) && !w.config.yaxis[realIndex].labels.showDuplicates ? '' : val,
19837 textAnchor: textAnchor,
19838 fontSize: yaxisFontSize,
19839 fontFamily: yaxisFontFamily,
19840 fontWeight: yaxisFontWeight,
19841 maxWidth: w.config.yaxis[realIndex].labels.maxWidth,
19842 foreColor: foreColor,
19843 isPlainText: false,
19844 cssClass: "apexcharts-yaxis-label ".concat(yaxisStyle.cssClass)
19845 });
19846 elYaxisTexts.add(label);
19847 this.addTooltip(label, val);
19848 if (w.config.yaxis[realIndex].labels.rotate !== 0) {
19849 this.rotateLabel(graphics, label, firstLabel, w.config.yaxis[realIndex].labels.rotate);
19850 }
19851 lY += labelsDivider;
19852 }
19853 }
19854 this.addYAxisTitle(graphics, elYaxis, realIndex);
19855 this.addAxisBorder(graphics, elYaxis, realIndex, tickAmount, labelsDivider);
19856 return elYaxis;
19857 }
19858 }, {
19859 key: "getTextAnchor",
19860 value: function getTextAnchor(align, opposite) {
19861 if (align === 'left') return 'start';
19862 if (align === 'center') return 'middle';
19863 if (align === 'right') return 'end';
19864 return opposite ? 'start' : 'end';
19865 }
19866 }, {
19867 key: "addTooltip",
19868 value: function addTooltip(label, val) {
19869 var elTooltipTitle = document.createElementNS(this.w.globals.SVGNS, 'title');
19870 elTooltipTitle.textContent = Array.isArray(val) ? val.join(' ') : val;
19871 label.node.appendChild(elTooltipTitle);
19872 }
19873 }, {
19874 key: "rotateLabel",
19875 value: function rotateLabel(graphics, label, firstLabel, rotate) {
19876 var firstLabelCenter = graphics.rotateAroundCenter(firstLabel.node);
19877 var labelCenter = graphics.rotateAroundCenter(label.node);
19878 label.node.setAttribute('transform', "rotate(".concat(rotate, " ").concat(firstLabelCenter.x, " ").concat(labelCenter.y, ")"));
19879 }
19880 }, {
19881 key: "addYAxisTitle",
19882 value: function addYAxisTitle(graphics, elYaxis, realIndex) {
19883 var w = this.w;
19884 if (w.config.yaxis[realIndex].title.text !== undefined) {
19885 var elYaxisTitle = graphics.group({
19886 class: 'apexcharts-yaxis-title'
19887 });
19888 var x = w.config.yaxis[realIndex].opposite ? w.globals.translateYAxisX[realIndex] : 0;
19889 var elYAxisTitleText = graphics.drawText({
19890 x: x,
19891 y: w.globals.gridHeight / 2 + w.globals.translateY + w.config.yaxis[realIndex].title.offsetY,
19892 text: w.config.yaxis[realIndex].title.text,
19893 textAnchor: 'end',
19894 foreColor: w.config.yaxis[realIndex].title.style.color,
19895 fontSize: w.config.yaxis[realIndex].title.style.fontSize,
19896 fontWeight: w.config.yaxis[realIndex].title.style.fontWeight,
19897 fontFamily: w.config.yaxis[realIndex].title.style.fontFamily,
19898 cssClass: "apexcharts-yaxis-title-text ".concat(w.config.yaxis[realIndex].title.style.cssClass)
19899 });
19900 elYaxisTitle.add(elYAxisTitleText);
19901 elYaxis.add(elYaxisTitle);
19902 }
19903 }
19904 }, {
19905 key: "addAxisBorder",
19906 value: function addAxisBorder(graphics, elYaxis, realIndex, tickAmount, labelsDivider) {
19907 var w = this.w;
19908 var axisBorder = w.config.yaxis[realIndex].axisBorder;
19909 var x = 31 + axisBorder.offsetX;
19910 if (w.config.yaxis[realIndex].opposite) x = -31 - axisBorder.offsetX;
19911 if (axisBorder.show) {
19912 var elVerticalLine = graphics.drawLine(x, w.globals.translateY + axisBorder.offsetY - 2, x, w.globals.gridHeight + w.globals.translateY + axisBorder.offsetY + 2, axisBorder.color, 0, axisBorder.width);
19913 elYaxis.add(elVerticalLine);
19914 }
19915 if (w.config.yaxis[realIndex].axisTicks.show) {
19916 this.axesUtils.drawYAxisTicks(x, tickAmount, axisBorder, w.config.yaxis[realIndex].axisTicks, realIndex, labelsDivider, elYaxis);
19917 }
19918 }
19919 }, {
19920 key: "drawYaxisInversed",
19921 value: function drawYaxisInversed(realIndex) {
19922 var w = this.w;
19923 var graphics = new Graphics(this.ctx);
19924 var elXaxis = graphics.group({
19925 class: 'apexcharts-xaxis apexcharts-yaxis-inversed'
19926 });
19927 var elXaxisTexts = graphics.group({
19928 class: 'apexcharts-xaxis-texts-g',
19929 transform: "translate(".concat(w.globals.translateXAxisX, ", ").concat(w.globals.translateXAxisY, ")")
19930 });
19931 elXaxis.add(elXaxisTexts);
19932 var tickAmount = w.globals.yAxisScale[realIndex].result.length - 1;
19933 var labelsDivider = w.globals.gridWidth / tickAmount + 0.1;
19934 var l = labelsDivider + w.config.xaxis.labels.offsetX;
19935 var lbFormatter = w.globals.xLabelFormatter;
19936 var labels = this.axesUtils.checkForReversedLabels(realIndex, w.globals.yAxisScale[realIndex].result.slice());
19937 var timescaleLabels = w.globals.timescaleLabels;
19938 if (timescaleLabels.length > 0) {
19939 this.xaxisLabels = timescaleLabels.slice();
19940 labels = timescaleLabels.slice();
19941 tickAmount = labels.length;
19942 }
19943 if (w.config.xaxis.labels.show) {
19944 for (var i = timescaleLabels.length ? 0 : tickAmount; timescaleLabels.length ? i < timescaleLabels.length : i >= 0; timescaleLabels.length ? i++ : i--) {
19945 var val = lbFormatter(labels[i], i, w);
19946 var x = w.globals.gridWidth + w.globals.padHorizontal - (l - labelsDivider + w.config.xaxis.labels.offsetX);
19947 if (timescaleLabels.length) {
19948 var label = this.axesUtils.getLabel(labels, timescaleLabels, x, i, this.drawnLabels, this.xaxisFontSize);
19949 x = label.x;
19950 val = label.text;
19951 this.drawnLabels.push(label.text);
19952 if (i === 0 && w.globals.skipFirstTimelinelabel) val = '';
19953 if (i === labels.length - 1 && w.globals.skipLastTimelinelabel) val = '';
19954 }
19955 var elTick = graphics.drawText({
19956 x: x,
19957 y: this.xAxisoffX + w.config.xaxis.labels.offsetY + 30 - (w.config.xaxis.position === 'top' ? w.globals.xAxisHeight + w.config.xaxis.axisTicks.height - 2 : 0),
19958 text: val,
19959 textAnchor: 'middle',
19960 foreColor: Array.isArray(this.xaxisForeColors) ? this.xaxisForeColors[realIndex] : this.xaxisForeColors,
19961 fontSize: this.xaxisFontSize,
19962 fontFamily: this.xaxisFontFamily,
19963 fontWeight: w.config.xaxis.labels.style.fontWeight,
19964 isPlainText: false,
19965 cssClass: "apexcharts-xaxis-label ".concat(w.config.xaxis.labels.style.cssClass)
19966 });
19967 elXaxisTexts.add(elTick);
19968 elTick.tspan(val);
19969 this.addTooltip(elTick, val);
19970 l += labelsDivider;
19971 }
19972 }
19973 this.inversedYAxisTitleText(elXaxis);
19974 this.inversedYAxisBorder(elXaxis);
19975 return elXaxis;
19976 }
19977 }, {
19978 key: "inversedYAxisBorder",
19979 value: function inversedYAxisBorder(parent) {
19980 var w = this.w;
19981 var graphics = new Graphics(this.ctx);
19982 var axisBorder = w.config.xaxis.axisBorder;
19983 if (axisBorder.show) {
19984 var lineCorrection = 0;
19985 if (w.config.chart.type === 'bar' && w.globals.isXNumeric) lineCorrection -= 15;
19986 var elHorzLine = graphics.drawLine(w.globals.padHorizontal + lineCorrection + axisBorder.offsetX, this.xAxisoffX, w.globals.gridWidth, this.xAxisoffX, axisBorder.color, 0, axisBorder.height);
19987 if (this.elgrid && this.elgrid.elGridBorders && w.config.grid.show) {
19988 this.elgrid.elGridBorders.add(elHorzLine);
19989 } else {
19990 parent.add(elHorzLine);
19991 }
19992 }
19993 }
19994 }, {
19995 key: "inversedYAxisTitleText",
19996 value: function inversedYAxisTitleText(parent) {
19997 var w = this.w;
19998 var graphics = new Graphics(this.ctx);
19999 if (w.config.xaxis.title.text !== undefined) {
20000 var elYaxisTitle = graphics.group({
20001 class: 'apexcharts-xaxis-title apexcharts-yaxis-title-inversed'
20002 });
20003 var elYAxisTitleText = graphics.drawText({
20004 x: w.globals.gridWidth / 2 + w.config.xaxis.title.offsetX,
20005 y: this.xAxisoffX + parseFloat(this.xaxisFontSize) + parseFloat(w.config.xaxis.title.style.fontSize) + w.config.xaxis.title.offsetY + 20,
20006 text: w.config.xaxis.title.text,
20007 textAnchor: 'middle',
20008 fontSize: w.config.xaxis.title.style.fontSize,
20009 fontFamily: w.config.xaxis.title.style.fontFamily,
20010 fontWeight: w.config.xaxis.title.style.fontWeight,
20011 foreColor: w.config.xaxis.title.style.color,
20012 cssClass: "apexcharts-xaxis-title-text ".concat(w.config.xaxis.title.style.cssClass)
20013 });
20014 elYaxisTitle.add(elYAxisTitleText);
20015 parent.add(elYaxisTitle);
20016 }
20017 }
20018 }, {
20019 key: "yAxisTitleRotate",
20020 value: function yAxisTitleRotate(realIndex, yAxisOpposite) {
20021 var w = this.w;
20022 var graphics = new Graphics(this.ctx);
20023 var elYAxisLabelsWrap = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(realIndex, "'] .apexcharts-yaxis-texts-g"));
20024 var yAxisLabelsCoord = elYAxisLabelsWrap ? elYAxisLabelsWrap.getBoundingClientRect() : {
20025 width: 0,
20026 height: 0
20027 };
20028 var yAxisTitle = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(realIndex, "'] .apexcharts-yaxis-title text"));
20029 var yAxisTitleCoord = yAxisTitle ? yAxisTitle.getBoundingClientRect() : {
20030 width: 0,
20031 height: 0
20032 };
20033 if (yAxisTitle) {
20034 var x = this.xPaddingForYAxisTitle(realIndex, yAxisLabelsCoord, yAxisTitleCoord, yAxisOpposite);
20035 yAxisTitle.setAttribute('x', x.xPos - (yAxisOpposite ? 10 : 0));
20036 var titleRotatingCenter = graphics.rotateAroundCenter(yAxisTitle);
20037 yAxisTitle.setAttribute('transform', "rotate(".concat(yAxisOpposite ? w.config.yaxis[realIndex].title.rotate * -1 : w.config.yaxis[realIndex].title.rotate, " ").concat(titleRotatingCenter.x, " ").concat(titleRotatingCenter.y, ")"));
20038 }
20039 }
20040 }, {
20041 key: "xPaddingForYAxisTitle",
20042 value: function xPaddingForYAxisTitle(realIndex, yAxisLabelsCoord, yAxisTitleCoord, yAxisOpposite) {
20043 var w = this.w;
20044 var x = 0;
20045 var padd = 10;
20046 if (w.config.yaxis[realIndex].title.text === undefined || realIndex < 0) {
20047 return {
20048 xPos: x,
20049 padd: 0
20050 };
20051 }
20052 if (yAxisOpposite) {
20053 x = yAxisLabelsCoord.width + w.config.yaxis[realIndex].title.offsetX + yAxisTitleCoord.width / 2 + padd / 2;
20054 } else {
20055 x = yAxisLabelsCoord.width * -1 + w.config.yaxis[realIndex].title.offsetX + padd / 2 + yAxisTitleCoord.width / 2;
20056 if (w.globals.isBarHorizontal) {
20057 padd = 25;
20058 x = yAxisLabelsCoord.width * -1 - w.config.yaxis[realIndex].title.offsetX - padd;
20059 }
20060 }
20061 return {
20062 xPos: x,
20063 padd: padd
20064 };
20065 }
20066 }, {
20067 key: "setYAxisXPosition",
20068 value: function setYAxisXPosition(yaxisLabelCoords, yTitleCoords) {
20069 var w = this.w;
20070 var xLeft = 0;
20071 var xRight = 0;
20072 var leftOffsetX = 18;
20073 var rightOffsetX = 1;
20074 if (w.config.yaxis.length > 1) this.multipleYs = true;
20075 w.config.yaxis.forEach(function (yaxe, index) {
20076 var shouldNotDrawAxis = w.globals.ignoreYAxisIndexes.includes(index) || !yaxe.show || yaxe.floating || yaxisLabelCoords[index].width === 0;
20077 var axisWidth = yaxisLabelCoords[index].width + yTitleCoords[index].width;
20078 if (!yaxe.opposite) {
20079 xLeft = w.globals.translateX - leftOffsetX;
20080 if (!shouldNotDrawAxis) leftOffsetX += axisWidth + 20;
20081 w.globals.translateYAxisX[index] = xLeft + yaxe.labels.offsetX;
20082 } else {
20083 if (w.globals.isBarHorizontal) {
20084 xRight = w.globals.gridWidth + w.globals.translateX - 1;
20085 w.globals.translateYAxisX[index] = xRight - yaxe.labels.offsetX;
20086 } else {
20087 xRight = w.globals.gridWidth + w.globals.translateX + rightOffsetX;
20088 if (!shouldNotDrawAxis) rightOffsetX += axisWidth + 20;
20089 w.globals.translateYAxisX[index] = xRight - yaxe.labels.offsetX + 20;
20090 }
20091 }
20092 });
20093 }
20094 }, {
20095 key: "setYAxisTextAlignments",
20096 value: function setYAxisTextAlignments() {
20097 var w = this.w;
20098 var yaxis = Utils$1.listToArray(w.globals.dom.baseEl.getElementsByClassName('apexcharts-yaxis'));
20099 yaxis.forEach(function (y, index) {
20100 var yaxe = w.config.yaxis[index];
20101 if (yaxe && !yaxe.floating && yaxe.labels.align !== undefined) {
20102 var yAxisInner = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(index, "'] .apexcharts-yaxis-texts-g"));
20103 var yAxisTexts = Utils$1.listToArray(w.globals.dom.baseEl.querySelectorAll(".apexcharts-yaxis[rel='".concat(index, "'] .apexcharts-yaxis-label")));
20104 var rect = yAxisInner.getBoundingClientRect();
20105 yAxisTexts.forEach(function (label) {
20106 label.setAttribute('text-anchor', yaxe.labels.align);
20107 });
20108 if (yaxe.labels.align === 'left' && !yaxe.opposite) {
20109 yAxisInner.setAttribute('transform', "translate(-".concat(rect.width, ", 0)"));
20110 } else if (yaxe.labels.align === 'center') {
20111 yAxisInner.setAttribute('transform', "translate(".concat(rect.width / 2 * (!yaxe.opposite ? -1 : 1), ", 0)"));
20112 } else if (yaxe.labels.align === 'right' && yaxe.opposite) {
20113 yAxisInner.setAttribute('transform', "translate(".concat(rect.width, ", 0)"));
20114 }
20115 }
20116 });
20117 }
20118 }]);
20119 return YAxis;
20120 }();
20121
20122 var Events = /*#__PURE__*/function () {
20123 function Events(ctx) {
20124 _classCallCheck(this, Events);
20125 this.ctx = ctx;
20126 this.w = ctx.w;
20127 this.documentEvent = Utils$1.bind(this.documentEvent, this);
20128 }
20129 _createClass(Events, [{
20130 key: "addEventListener",
20131 value: function addEventListener(name, handler) {
20132 var w = this.w;
20133 if (w.globals.events.hasOwnProperty(name)) {
20134 w.globals.events[name].push(handler);
20135 } else {
20136 w.globals.events[name] = [handler];
20137 }
20138 }
20139 }, {
20140 key: "removeEventListener",
20141 value: function removeEventListener(name, handler) {
20142 var w = this.w;
20143 if (!w.globals.events.hasOwnProperty(name)) {
20144 return;
20145 }
20146 var index = w.globals.events[name].indexOf(handler);
20147 if (index !== -1) {
20148 w.globals.events[name].splice(index, 1);
20149 }
20150 }
20151 }, {
20152 key: "fireEvent",
20153 value: function fireEvent(name, args) {
20154 var w = this.w;
20155 if (!w.globals.events.hasOwnProperty(name)) {
20156 return;
20157 }
20158 if (!args || !args.length) {
20159 args = [];
20160 }
20161 var evs = w.globals.events[name];
20162 var l = evs.length;
20163 for (var i = 0; i < l; i++) {
20164 evs[i].apply(null, args);
20165 }
20166 }
20167 }, {
20168 key: "setupEventHandlers",
20169 value: function setupEventHandlers() {
20170 var _this = this;
20171 var w = this.w;
20172 var me = this.ctx;
20173 var clickableArea = w.globals.dom.baseEl.querySelector(w.globals.chartClass);
20174 this.ctx.eventList.forEach(function (event) {
20175 clickableArea.addEventListener(event, function (e) {
20176 var capturedSeriesIndex = e.target.getAttribute('i') === null && w.globals.capturedSeriesIndex !== -1 ? w.globals.capturedSeriesIndex : e.target.getAttribute('i');
20177 var capturedDataPointIndex = e.target.getAttribute('j') === null && w.globals.capturedDataPointIndex !== -1 ? w.globals.capturedDataPointIndex : e.target.getAttribute('j');
20178 var opts = Object.assign({}, w, {
20179 seriesIndex: w.globals.axisCharts ? capturedSeriesIndex : 0,
20180 dataPointIndex: capturedDataPointIndex
20181 });
20182 if (e.type === 'mousemove' || e.type === 'touchmove') {
20183 if (typeof w.config.chart.events.mouseMove === 'function') {
20184 w.config.chart.events.mouseMove(e, me, opts);
20185 }
20186 } else if (e.type === 'mouseleave' || e.type === 'touchleave') {
20187 if (typeof w.config.chart.events.mouseLeave === 'function') {
20188 w.config.chart.events.mouseLeave(e, me, opts);
20189 }
20190 } else if (e.type === 'mouseup' && e.which === 1 || e.type === 'touchend') {
20191 if (typeof w.config.chart.events.click === 'function') {
20192 w.config.chart.events.click(e, me, opts);
20193 }
20194 me.ctx.events.fireEvent('click', [e, me, opts]);
20195 }
20196 }, {
20197 capture: false,
20198 passive: true
20199 });
20200 });
20201 this.ctx.eventList.forEach(function (event) {
20202 w.globals.dom.baseEl.addEventListener(event, _this.documentEvent, {
20203 passive: true
20204 });
20205 });
20206 this.ctx.core.setupBrushHandler();
20207 }
20208 }, {
20209 key: "documentEvent",
20210 value: function documentEvent(e) {
20211 var w = this.w;
20212 var target = e.target.className;
20213 if (e.type === 'click') {
20214 var elMenu = w.globals.dom.baseEl.querySelector('.apexcharts-menu');
20215 if (elMenu && elMenu.classList.contains('apexcharts-menu-open') && target !== 'apexcharts-menu-icon') {
20216 elMenu.classList.remove('apexcharts-menu-open');
20217 }
20218 }
20219 w.globals.clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
20220 w.globals.clientY = e.type === 'touchmove' ? e.touches[0].clientY : e.clientY;
20221 }
20222 }]);
20223 return Events;
20224 }();
20225
20226 var Localization = /*#__PURE__*/function () {
20227 function Localization(ctx) {
20228 _classCallCheck(this, Localization);
20229 this.ctx = ctx;
20230 this.w = ctx.w;
20231 }
20232 _createClass(Localization, [{
20233 key: "setCurrentLocaleValues",
20234 value: function setCurrentLocaleValues(localeName) {
20235 var locales = this.w.config.chart.locales;
20236
20237 // check if user has specified locales in global Apex variable
20238 // if yes - then extend those with local chart's locale
20239 if (window.Apex.chart && window.Apex.chart.locales && window.Apex.chart.locales.length > 0) {
20240 locales = this.w.config.chart.locales.concat(window.Apex.chart.locales);
20241 }
20242
20243 // find the locale from the array of locales which user has set (either by chart.defaultLocale or by calling setLocale() method.)
20244 var selectedLocale = locales.filter(function (c) {
20245 return c.name === localeName;
20246 })[0];
20247 if (selectedLocale) {
20248 // create a complete locale object by extending defaults so you don't get undefined errors.
20249 var ret = Utils$1.extend(en, selectedLocale);
20250
20251 // store these locale options in global var for ease access
20252 this.w.globals.locale = ret.options;
20253 } else {
20254 throw new Error('Wrong locale name provided. Please make sure you set the correct locale name in options');
20255 }
20256 }
20257 }]);
20258 return Localization;
20259 }();
20260
20261 var Axes = /*#__PURE__*/function () {
20262 function Axes(ctx) {
20263 _classCallCheck(this, Axes);
20264 this.ctx = ctx;
20265 this.w = ctx.w;
20266 }
20267 _createClass(Axes, [{
20268 key: "drawAxis",
20269 value: function drawAxis(type, elgrid) {
20270 var _this = this;
20271 var gl = this.w.globals;
20272 var cnf = this.w.config;
20273 var xAxis = new XAxis(this.ctx, elgrid);
20274 var yAxis = new YAxis(this.ctx, elgrid);
20275 if (gl.axisCharts && type !== 'radar') {
20276 var elXaxis, elYaxis;
20277 if (gl.isBarHorizontal) {
20278 elYaxis = yAxis.drawYaxisInversed(0);
20279 elXaxis = xAxis.drawXaxisInversed(0);
20280 gl.dom.elGraphical.add(elXaxis);
20281 gl.dom.elGraphical.add(elYaxis);
20282 } else {
20283 elXaxis = xAxis.drawXaxis();
20284 gl.dom.elGraphical.add(elXaxis);
20285 cnf.yaxis.map(function (yaxe, index) {
20286 if (gl.ignoreYAxisIndexes.indexOf(index) === -1) {
20287 elYaxis = yAxis.drawYaxis(index);
20288 gl.dom.Paper.add(elYaxis);
20289 if (_this.w.config.grid.position === 'back') {
20290 var inner = gl.dom.Paper.children()[1];
20291 inner.remove();
20292 gl.dom.Paper.add(inner);
20293 }
20294 }
20295 });
20296 }
20297 }
20298 }
20299 }]);
20300 return Axes;
20301 }();
20302
20303 var Crosshairs = /*#__PURE__*/function () {
20304 function Crosshairs(ctx) {
20305 _classCallCheck(this, Crosshairs);
20306 this.ctx = ctx;
20307 this.w = ctx.w;
20308 }
20309 _createClass(Crosshairs, [{
20310 key: "drawXCrosshairs",
20311 value: function drawXCrosshairs() {
20312 var w = this.w;
20313 var graphics = new Graphics(this.ctx);
20314 var filters = new Filters(this.ctx);
20315 var crosshairGradient = w.config.xaxis.crosshairs.fill.gradient;
20316 var crosshairShadow = w.config.xaxis.crosshairs.dropShadow;
20317 var fillType = w.config.xaxis.crosshairs.fill.type;
20318 var gradientFrom = crosshairGradient.colorFrom;
20319 var gradientTo = crosshairGradient.colorTo;
20320 var opacityFrom = crosshairGradient.opacityFrom;
20321 var opacityTo = crosshairGradient.opacityTo;
20322 var stops = crosshairGradient.stops;
20323 var shadow = 'none';
20324 var dropShadow = crosshairShadow.enabled;
20325 var shadowLeft = crosshairShadow.left;
20326 var shadowTop = crosshairShadow.top;
20327 var shadowBlur = crosshairShadow.blur;
20328 var shadowColor = crosshairShadow.color;
20329 var shadowOpacity = crosshairShadow.opacity;
20330 var xcrosshairsFill = w.config.xaxis.crosshairs.fill.color;
20331 if (w.config.xaxis.crosshairs.show) {
20332 if (fillType === 'gradient') {
20333 xcrosshairsFill = graphics.drawGradient('vertical', gradientFrom, gradientTo, opacityFrom, opacityTo, null, stops, null);
20334 }
20335 var xcrosshairs = graphics.drawRect();
20336 if (w.config.xaxis.crosshairs.width === 1) {
20337 // to prevent drawing 2 lines, convert rect to line
20338 xcrosshairs = graphics.drawLine();
20339 }
20340 var gridHeight = w.globals.gridHeight;
20341 if (!Utils$1.isNumber(gridHeight) || gridHeight < 0) {
20342 gridHeight = 0;
20343 }
20344 var crosshairsWidth = w.config.xaxis.crosshairs.width;
20345 if (!Utils$1.isNumber(crosshairsWidth) || crosshairsWidth < 0) {
20346 crosshairsWidth = 0;
20347 }
20348 xcrosshairs.attr({
20349 class: 'apexcharts-xcrosshairs',
20350 x: 0,
20351 y: 0,
20352 y2: gridHeight,
20353 width: crosshairsWidth,
20354 height: gridHeight,
20355 fill: xcrosshairsFill,
20356 filter: shadow,
20357 'fill-opacity': w.config.xaxis.crosshairs.opacity,
20358 stroke: w.config.xaxis.crosshairs.stroke.color,
20359 'stroke-width': w.config.xaxis.crosshairs.stroke.width,
20360 'stroke-dasharray': w.config.xaxis.crosshairs.stroke.dashArray
20361 });
20362 if (dropShadow) {
20363 xcrosshairs = filters.dropShadow(xcrosshairs, {
20364 left: shadowLeft,
20365 top: shadowTop,
20366 blur: shadowBlur,
20367 color: shadowColor,
20368 opacity: shadowOpacity
20369 });
20370 }
20371 w.globals.dom.elGraphical.add(xcrosshairs);
20372 }
20373 }
20374 }, {
20375 key: "drawYCrosshairs",
20376 value: function drawYCrosshairs() {
20377 var w = this.w;
20378 var graphics = new Graphics(this.ctx);
20379 var crosshair = w.config.yaxis[0].crosshairs;
20380 var offX = w.globals.barPadForNumericAxis;
20381 if (w.config.yaxis[0].crosshairs.show) {
20382 var ycrosshairs = graphics.drawLine(-offX, 0, w.globals.gridWidth + offX, 0, crosshair.stroke.color, crosshair.stroke.dashArray, crosshair.stroke.width);
20383 ycrosshairs.attr({
20384 class: 'apexcharts-ycrosshairs'
20385 });
20386 w.globals.dom.elGraphical.add(ycrosshairs);
20387 }
20388
20389 // draw an invisible crosshair to help in positioning the yaxis tooltip
20390 var ycrosshairsHidden = graphics.drawLine(-offX, 0, w.globals.gridWidth + offX, 0, crosshair.stroke.color, 0, 0);
20391 ycrosshairsHidden.attr({
20392 class: 'apexcharts-ycrosshairs-hidden'
20393 });
20394 w.globals.dom.elGraphical.add(ycrosshairsHidden);
20395 }
20396 }]);
20397 return Crosshairs;
20398 }();
20399
20400 /**
20401 * ApexCharts Responsive Class to override options for different screen sizes.
20402 *
20403 * @module Responsive
20404 **/
20405 var Responsive = /*#__PURE__*/function () {
20406 function Responsive(ctx) {
20407 _classCallCheck(this, Responsive);
20408 this.ctx = ctx;
20409 this.w = ctx.w;
20410 }
20411
20412 // the opts parameter if not null has to be set overriding everything
20413 // as the opts is set by user externally
20414 _createClass(Responsive, [{
20415 key: "checkResponsiveConfig",
20416 value: function checkResponsiveConfig(opts) {
20417 var _this = this;
20418 var w = this.w;
20419 var cnf = w.config;
20420
20421 // check if responsive config exists
20422 if (cnf.responsive.length === 0) return;
20423 var res = cnf.responsive.slice();
20424 res.sort(function (a, b) {
20425 return a.breakpoint > b.breakpoint ? 1 : b.breakpoint > a.breakpoint ? -1 : 0;
20426 }).reverse();
20427 var config = new Config({});
20428 var iterateResponsiveOptions = function iterateResponsiveOptions() {
20429 var newOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20430 var largestBreakpoint = res[0].breakpoint;
20431 var width = window.innerWidth > 0 ? window.innerWidth : screen.width;
20432 if (width > largestBreakpoint) {
20433 var initialConfig = Utils$1.clone(w.globals.initialConfig);
20434 // Retain state of series in case any have been collapsed
20435 // (indicated by series.data === [], these series' will be zeroed later
20436 // enabling stacking to work correctly)
20437 initialConfig.series = Utils$1.clone(w.config.series);
20438 var options = CoreUtils.extendArrayProps(config, initialConfig, w);
20439 newOptions = Utils$1.extend(options, newOptions);
20440 newOptions = Utils$1.extend(w.config, newOptions);
20441 _this.overrideResponsiveOptions(newOptions);
20442 } else {
20443 for (var i = 0; i < res.length; i++) {
20444 if (width < res[i].breakpoint) {
20445 newOptions = CoreUtils.extendArrayProps(config, res[i].options, w);
20446 newOptions = Utils$1.extend(w.config, newOptions);
20447 _this.overrideResponsiveOptions(newOptions);
20448 }
20449 }
20450 }
20451 };
20452 if (opts) {
20453 var options = CoreUtils.extendArrayProps(config, opts, w);
20454 options = Utils$1.extend(w.config, options);
20455 options = Utils$1.extend(options, opts);
20456 iterateResponsiveOptions(options);
20457 } else {
20458 iterateResponsiveOptions({});
20459 }
20460 }
20461 }, {
20462 key: "overrideResponsiveOptions",
20463 value: function overrideResponsiveOptions(newOptions) {
20464 var newConfig = new Config(newOptions).init({
20465 responsiveOverride: true
20466 });
20467 this.w.config = newConfig;
20468 }
20469 }]);
20470 return Responsive;
20471 }();
20472
20473 /**
20474 * ApexCharts Theme Class for setting the colors and palettes.
20475 *
20476 * @module Theme
20477 **/
20478 var Theme = /*#__PURE__*/function () {
20479 function Theme(ctx) {
20480 _classCallCheck(this, Theme);
20481 this.ctx = ctx;
20482 this.w = ctx.w;
20483 this.colors = [];
20484 this.isColorFn = false;
20485 this.isHeatmapDistributed = this.checkHeatmapDistributed();
20486 this.isBarDistributed = this.checkBarDistributed();
20487 }
20488 _createClass(Theme, [{
20489 key: "checkHeatmapDistributed",
20490 value: function checkHeatmapDistributed() {
20491 var _this$w$config = this.w.config,
20492 chart = _this$w$config.chart,
20493 plotOptions = _this$w$config.plotOptions;
20494 return chart.type === 'treemap' && plotOptions.treemap && plotOptions.treemap.distributed || chart.type === 'heatmap' && plotOptions.heatmap && plotOptions.heatmap.distributed;
20495 }
20496 }, {
20497 key: "checkBarDistributed",
20498 value: function checkBarDistributed() {
20499 var _this$w$config2 = this.w.config,
20500 chart = _this$w$config2.chart,
20501 plotOptions = _this$w$config2.plotOptions;
20502 return plotOptions.bar && plotOptions.bar.distributed && (chart.type === 'bar' || chart.type === 'rangeBar');
20503 }
20504 }, {
20505 key: "init",
20506 value: function init() {
20507 this.setDefaultColors();
20508 }
20509 }, {
20510 key: "setDefaultColors",
20511 value: function setDefaultColors() {
20512 var w = this.w;
20513 var utils = new Utils$1();
20514 w.globals.dom.elWrap.classList.add("apexcharts-theme-".concat(w.config.theme.mode || 'light'));
20515
20516 // Create a copy of config.colors array to avoid mutating the original config.colors
20517 var configColors = _toConsumableArray(w.config.colors || w.config.fill.colors || []);
20518 w.globals.colors = this.getColors(configColors);
20519 this.applySeriesColors(w.globals.seriesColors, w.globals.colors);
20520 if (w.config.theme.monochrome.enabled) {
20521 w.globals.colors = this.getMonochromeColors(w.config.theme.monochrome, w.globals.series, utils);
20522 }
20523 var defaultColors = w.globals.colors.slice();
20524 this.pushExtraColors(w.globals.colors);
20525 this.applyColorTypes(['fill', 'stroke'], defaultColors);
20526 this.applyDataLabelsColors(defaultColors);
20527 this.applyRadarPolygonsColors();
20528 this.applyMarkersColors(defaultColors);
20529 }
20530 }, {
20531 key: "getColors",
20532 value: function getColors(configColors) {
20533 var _this = this;
20534 var w = this.w;
20535 if (!configColors || configColors.length === 0) {
20536 return this.predefined();
20537 }
20538 if (Array.isArray(configColors) && configColors.length > 0 && typeof configColors[0] === 'function') {
20539 this.isColorFn = true;
20540 return w.config.series.map(function (s, i) {
20541 var c = configColors[i] || configColors[0];
20542 return typeof c === 'function' ? c({
20543 value: w.globals.axisCharts ? w.globals.series[i][0] || 0 : w.globals.series[i],
20544 seriesIndex: i,
20545 dataPointIndex: i,
20546 w: _this.w
20547 }) : c;
20548 });
20549 }
20550 return configColors;
20551 }
20552 }, {
20553 key: "applySeriesColors",
20554 value: function applySeriesColors(seriesColors, globalsColors) {
20555 seriesColors.forEach(function (c, i) {
20556 if (c) {
20557 globalsColors[i] = c;
20558 }
20559 });
20560 }
20561 }, {
20562 key: "getMonochromeColors",
20563 value: function getMonochromeColors(monochrome, series, utils) {
20564 var color = monochrome.color,
20565 shadeIntensity = monochrome.shadeIntensity,
20566 shadeTo = monochrome.shadeTo;
20567 var glsCnt = this.isBarDistributed || this.isHeatmapDistributed ? series[0].length * series.length : series.length;
20568 var part = 1 / (glsCnt / shadeIntensity);
20569 var percent = 0;
20570 return Array.from({
20571 length: glsCnt
20572 }, function () {
20573 var newColor = shadeTo === 'dark' ? utils.shadeColor(percent * -1, color) : utils.shadeColor(percent, color);
20574 percent += part;
20575 return newColor;
20576 });
20577 }
20578 }, {
20579 key: "applyColorTypes",
20580 value: function applyColorTypes(colorTypes, defaultColors) {
20581 var _this2 = this;
20582 var w = this.w;
20583 colorTypes.forEach(function (c) {
20584 w.globals[c].colors = w.config[c].colors === undefined ? _this2.isColorFn ? w.config.colors : defaultColors : w.config[c].colors.slice();
20585 _this2.pushExtraColors(w.globals[c].colors);
20586 });
20587 }
20588 }, {
20589 key: "applyDataLabelsColors",
20590 value: function applyDataLabelsColors(defaultColors) {
20591 var w = this.w;
20592 w.globals.dataLabels.style.colors = w.config.dataLabels.style.colors === undefined ? defaultColors : w.config.dataLabels.style.colors.slice();
20593 this.pushExtraColors(w.globals.dataLabels.style.colors, 50);
20594 }
20595 }, {
20596 key: "applyRadarPolygonsColors",
20597 value: function applyRadarPolygonsColors() {
20598 var w = this.w;
20599 w.globals.radarPolygons.fill.colors = w.config.plotOptions.radar.polygons.fill.colors === undefined ? [w.config.theme.mode === 'dark' ? '#343A3F' : 'none'] : w.config.plotOptions.radar.polygons.fill.colors.slice();
20600 this.pushExtraColors(w.globals.radarPolygons.fill.colors, 20);
20601 }
20602 }, {
20603 key: "applyMarkersColors",
20604 value: function applyMarkersColors(defaultColors) {
20605 var w = this.w;
20606 w.globals.markers.colors = w.config.markers.colors === undefined ? defaultColors : w.config.markers.colors.slice();
20607 this.pushExtraColors(w.globals.markers.colors);
20608 }
20609 }, {
20610 key: "pushExtraColors",
20611 value: function pushExtraColors(colorSeries, length) {
20612 var distributed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
20613 var w = this.w;
20614 var len = length || w.globals.series.length;
20615 if (distributed === null) {
20616 distributed = this.isBarDistributed || this.isHeatmapDistributed || w.config.chart.type === 'heatmap' && w.config.plotOptions.heatmap && w.config.plotOptions.heatmap.colorScale.inverse;
20617 }
20618 if (distributed && w.globals.series.length) {
20619 len = w.globals.series[w.globals.maxValsInArrayIndex].length * w.globals.series.length;
20620 }
20621 if (colorSeries.length < len) {
20622 var diff = len - colorSeries.length;
20623 for (var i = 0; i < diff; i++) {
20624 colorSeries.push(colorSeries[i]);
20625 }
20626 }
20627 }
20628 }, {
20629 key: "updateThemeOptions",
20630 value: function updateThemeOptions(options) {
20631 options.chart = options.chart || {};
20632 options.tooltip = options.tooltip || {};
20633 var mode = options.theme.mode;
20634 var palette = mode === 'dark' ? 'palette4' : mode === 'light' ? 'palette1' : options.theme.palette || 'palette1';
20635 var foreColor = mode === 'dark' ? '#f6f7f8' : mode === 'light' ? '#373d3f' : options.chart.foreColor || '#373d3f';
20636 options.tooltip.theme = mode || 'light';
20637 options.chart.foreColor = foreColor;
20638 options.theme.palette = palette;
20639 return options;
20640 }
20641 }, {
20642 key: "predefined",
20643 value: function predefined() {
20644 var palette = this.w.config.theme.palette;
20645 var palettes = {
20646 palette1: ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0'],
20647 palette2: ['#3f51b5', '#03a9f4', '#4caf50', '#f9ce1d', '#FF9800'],
20648 palette3: ['#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B'],
20649 palette4: ['#4ecdc4', '#c7f464', '#81D4FA', '#fd6a6a', '#546E7A'],
20650 palette5: ['#2b908f', '#f9a3a4', '#90ee7e', '#fa4443', '#69d2e7'],
20651 palette6: ['#449DD1', '#F86624', '#EA3546', '#662E9B', '#C5D86D'],
20652 palette7: ['#D7263D', '#1B998B', '#2E294E', '#F46036', '#E2C044'],
20653 palette8: ['#662E9B', '#F86624', '#F9C80E', '#EA3546', '#43BCCD'],
20654 palette9: ['#5C4742', '#A5978B', '#8D5B4C', '#5A2A27', '#C4BBAF'],
20655 palette10: ['#A300D6', '#7D02EB', '#5653FE', '#2983FF', '#00B1F2'],
20656 default: ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0']
20657 };
20658 return palettes[palette] || palettes.default;
20659 }
20660 }]);
20661 return Theme;
20662 }();
20663
20664 var TitleSubtitle = /*#__PURE__*/function () {
20665 function TitleSubtitle(ctx) {
20666 _classCallCheck(this, TitleSubtitle);
20667 this.ctx = ctx;
20668 this.w = ctx.w;
20669 }
20670 _createClass(TitleSubtitle, [{
20671 key: "draw",
20672 value: function draw() {
20673 this.drawTitleSubtitle('title');
20674 this.drawTitleSubtitle('subtitle');
20675 }
20676 }, {
20677 key: "drawTitleSubtitle",
20678 value: function drawTitleSubtitle(type) {
20679 var w = this.w;
20680 var tsConfig = type === 'title' ? w.config.title : w.config.subtitle;
20681 var x = w.globals.svgWidth / 2;
20682 var y = tsConfig.offsetY;
20683 var textAnchor = 'middle';
20684 if (tsConfig.align === 'left') {
20685 x = 10;
20686 textAnchor = 'start';
20687 } else if (tsConfig.align === 'right') {
20688 x = w.globals.svgWidth - 10;
20689 textAnchor = 'end';
20690 }
20691 x = x + tsConfig.offsetX;
20692 y = y + parseInt(tsConfig.style.fontSize, 10) + tsConfig.margin / 2;
20693 if (tsConfig.text !== undefined) {
20694 var graphics = new Graphics(this.ctx);
20695 var titleText = graphics.drawText({
20696 x: x,
20697 y: y,
20698 text: tsConfig.text,
20699 textAnchor: textAnchor,
20700 fontSize: tsConfig.style.fontSize,
20701 fontFamily: tsConfig.style.fontFamily,
20702 fontWeight: tsConfig.style.fontWeight,
20703 foreColor: tsConfig.style.color,
20704 opacity: 1
20705 });
20706 titleText.node.setAttribute('class', "apexcharts-".concat(type, "-text"));
20707 w.globals.dom.Paper.add(titleText);
20708 }
20709 }
20710 }]);
20711 return TitleSubtitle;
20712 }();
20713
20714 var Helpers$3 = /*#__PURE__*/function () {
20715 function Helpers(dCtx) {
20716 _classCallCheck(this, Helpers);
20717 this.w = dCtx.w;
20718 this.dCtx = dCtx;
20719 }
20720
20721 /**
20722 * Get Chart Title/Subtitle Dimensions
20723 * @memberof Dimensions
20724 * @return {{width, height}}
20725 **/
20726 _createClass(Helpers, [{
20727 key: "getTitleSubtitleCoords",
20728 value: function getTitleSubtitleCoords(type) {
20729 var w = this.w;
20730 var width = 0;
20731 var height = 0;
20732 var floating = type === 'title' ? w.config.title.floating : w.config.subtitle.floating;
20733 var el = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-text"));
20734 if (el !== null && !floating) {
20735 var coord = el.getBoundingClientRect();
20736 width = coord.width;
20737 height = w.globals.axisCharts ? coord.height + 5 : coord.height;
20738 }
20739 return {
20740 width: width,
20741 height: height
20742 };
20743 }
20744 }, {
20745 key: "getLegendsRect",
20746 value: function getLegendsRect() {
20747 var w = this.w;
20748 var elLegendWrap = w.globals.dom.elLegendWrap;
20749 if (!w.config.legend.height && (w.config.legend.position === 'top' || w.config.legend.position === 'bottom')) {
20750 // avoid legend to take up all the space
20751 elLegendWrap.style.maxHeight = w.globals.svgHeight / 2 + 'px';
20752 }
20753 var lgRect = Object.assign({}, Utils$1.getBoundingClientRect(elLegendWrap));
20754 if (elLegendWrap !== null && !w.config.legend.floating && w.config.legend.show) {
20755 this.dCtx.lgRect = {
20756 x: lgRect.x,
20757 y: lgRect.y,
20758 height: lgRect.height,
20759 width: lgRect.height === 0 ? 0 : lgRect.width
20760 };
20761 } else {
20762 this.dCtx.lgRect = {
20763 x: 0,
20764 y: 0,
20765 height: 0,
20766 width: 0
20767 };
20768 }
20769
20770 // if legend takes up all of the chart space, we need to restrict it.
20771 if (w.config.legend.position === 'left' || w.config.legend.position === 'right') {
20772 if (this.dCtx.lgRect.width * 1.5 > w.globals.svgWidth) {
20773 this.dCtx.lgRect.width = w.globals.svgWidth / 1.5;
20774 }
20775 }
20776 return this.dCtx.lgRect;
20777 }
20778
20779 /**
20780 * Get Y Axis Dimensions
20781 * @memberof Dimensions
20782 * @return {{width, height}}
20783 **/
20784 }, {
20785 key: "getDatalabelsRect",
20786 value: function getDatalabelsRect() {
20787 var _this = this;
20788 var w = this.w;
20789 var allLabels = [];
20790 w.config.series.forEach(function (serie, seriesIndex) {
20791 serie.data.forEach(function (datum, dataPointIndex) {
20792 var getText = function getText(v) {
20793 return w.config.dataLabels.formatter(v, {
20794 ctx: _this.dCtx.ctx,
20795 seriesIndex: seriesIndex,
20796 dataPointIndex: dataPointIndex,
20797 w: w
20798 });
20799 };
20800 val = getText(w.globals.series[seriesIndex][dataPointIndex]);
20801 allLabels.push(val);
20802 });
20803 });
20804 var val = Utils$1.getLargestStringFromArr(allLabels);
20805 var graphics = new Graphics(this.dCtx.ctx);
20806 var dataLabelsStyle = w.config.dataLabels.style;
20807 var labelrect = graphics.getTextRects(val, parseInt(dataLabelsStyle.fontSize), dataLabelsStyle.fontFamily);
20808 return {
20809 width: labelrect.width * 1.05,
20810 height: labelrect.height
20811 };
20812 }
20813 }, {
20814 key: "getLargestStringFromMultiArr",
20815 value: function getLargestStringFromMultiArr(val, arr) {
20816 var w = this.w;
20817 var valArr = val;
20818 if (w.globals.isMultiLineX) {
20819 // if the xaxis labels has multiline texts (array)
20820 var maxArrs = arr.map(function (xl, idx) {
20821 return Array.isArray(xl) ? xl.length : 1;
20822 });
20823 var maxArrLen = Math.max.apply(Math, _toConsumableArray(maxArrs));
20824 var maxArrIndex = maxArrs.indexOf(maxArrLen);
20825 valArr = arr[maxArrIndex];
20826 }
20827 return valArr;
20828 }
20829 }]);
20830 return Helpers;
20831 }();
20832
20833 var DimXAxis = /*#__PURE__*/function () {
20834 function DimXAxis(dCtx) {
20835 _classCallCheck(this, DimXAxis);
20836 this.w = dCtx.w;
20837 this.dCtx = dCtx;
20838 }
20839
20840 /**
20841 * Get X Axis Dimensions
20842 * @memberof Dimensions
20843 * @return {{width, height}}
20844 **/
20845 _createClass(DimXAxis, [{
20846 key: "getxAxisLabelsCoords",
20847 value: function getxAxisLabelsCoords() {
20848 var w = this.w;
20849 var xaxisLabels = w.globals.labels.slice();
20850 if (w.config.xaxis.convertedCatToNumeric && xaxisLabels.length === 0) {
20851 xaxisLabels = w.globals.categoryLabels;
20852 }
20853 var rect;
20854 if (w.globals.timescaleLabels.length > 0) {
20855 var coords = this.getxAxisTimeScaleLabelsCoords();
20856 rect = {
20857 width: coords.width,
20858 height: coords.height
20859 };
20860 w.globals.rotateXLabels = false;
20861 } else {
20862 this.dCtx.lgWidthForSideLegends = (w.config.legend.position === 'left' || w.config.legend.position === 'right') && !w.config.legend.floating ? this.dCtx.lgRect.width : 0;
20863
20864 // get the longest string from the labels array and also apply label formatter
20865 var xlbFormatter = w.globals.xLabelFormatter;
20866 // prevent changing xaxisLabels to avoid issues in multi-yaxes - fix #522
20867 var val = Utils$1.getLargestStringFromArr(xaxisLabels);
20868 var valArr = this.dCtx.dimHelpers.getLargestStringFromMultiArr(val, xaxisLabels);
20869
20870 // the labels gets changed for bar charts
20871 if (w.globals.isBarHorizontal) {
20872 val = w.globals.yAxisScale[0].result.reduce(function (a, b) {
20873 return a.length > b.length ? a : b;
20874 }, 0);
20875 valArr = val;
20876 }
20877 var xFormat = new Formatters(this.dCtx.ctx);
20878 var timestamp = val;
20879 val = xFormat.xLabelFormat(xlbFormatter, val, timestamp, {
20880 i: undefined,
20881 dateFormatter: new DateTime(this.dCtx.ctx).formatDate,
20882 w: w
20883 });
20884 valArr = xFormat.xLabelFormat(xlbFormatter, valArr, timestamp, {
20885 i: undefined,
20886 dateFormatter: new DateTime(this.dCtx.ctx).formatDate,
20887 w: w
20888 });
20889 if (w.config.xaxis.convertedCatToNumeric && typeof val === 'undefined' || String(val).trim() === '') {
20890 val = '1';
20891 valArr = val;
20892 }
20893 var graphics = new Graphics(this.dCtx.ctx);
20894 var xLabelrect = graphics.getTextRects(val, w.config.xaxis.labels.style.fontSize);
20895 var xArrLabelrect = xLabelrect;
20896 if (val !== valArr) {
20897 xArrLabelrect = graphics.getTextRects(valArr, w.config.xaxis.labels.style.fontSize);
20898 }
20899 rect = {
20900 width: xLabelrect.width >= xArrLabelrect.width ? xLabelrect.width : xArrLabelrect.width,
20901 height: xLabelrect.height >= xArrLabelrect.height ? xLabelrect.height : xArrLabelrect.height
20902 };
20903 if (rect.width * xaxisLabels.length > w.globals.svgWidth - this.dCtx.lgWidthForSideLegends - this.dCtx.yAxisWidth - this.dCtx.gridPad.left - this.dCtx.gridPad.right && w.config.xaxis.labels.rotate !== 0 || w.config.xaxis.labels.rotateAlways) {
20904 if (!w.globals.isBarHorizontal) {
20905 w.globals.rotateXLabels = true;
20906 var getRotatedTextRects = function getRotatedTextRects(text) {
20907 return graphics.getTextRects(text, w.config.xaxis.labels.style.fontSize, w.config.xaxis.labels.style.fontFamily, "rotate(".concat(w.config.xaxis.labels.rotate, " 0 0)"), false);
20908 };
20909 xLabelrect = getRotatedTextRects(val);
20910 if (val !== valArr) {
20911 xArrLabelrect = getRotatedTextRects(valArr);
20912 }
20913 rect.height = (xLabelrect.height > xArrLabelrect.height ? xLabelrect.height : xArrLabelrect.height) / 1.5;
20914 rect.width = xLabelrect.width > xArrLabelrect.width ? xLabelrect.width : xArrLabelrect.width;
20915 }
20916 } else {
20917 w.globals.rotateXLabels = false;
20918 }
20919 }
20920 if (!w.config.xaxis.labels.show) {
20921 rect = {
20922 width: 0,
20923 height: 0
20924 };
20925 }
20926 return {
20927 width: rect.width,
20928 height: rect.height
20929 };
20930 }
20931
20932 /**
20933 * Get X Axis Label Group height
20934 * @memberof Dimensions
20935 * @return {{width, height}}
20936 */
20937 }, {
20938 key: "getxAxisGroupLabelsCoords",
20939 value: function getxAxisGroupLabelsCoords() {
20940 var _w$config$xaxis$group;
20941 var w = this.w;
20942 if (!w.globals.hasXaxisGroups) {
20943 return {
20944 width: 0,
20945 height: 0
20946 };
20947 }
20948 var fontSize = ((_w$config$xaxis$group = w.config.xaxis.group.style) === null || _w$config$xaxis$group === void 0 ? void 0 : _w$config$xaxis$group.fontSize) || w.config.xaxis.labels.style.fontSize;
20949 var xaxisLabels = w.globals.groups.map(function (g) {
20950 return g.title;
20951 });
20952 var rect;
20953
20954 // prevent changing xaxisLabels to avoid issues in multi-yaxes - fix #522
20955 var val = Utils$1.getLargestStringFromArr(xaxisLabels);
20956 var valArr = this.dCtx.dimHelpers.getLargestStringFromMultiArr(val, xaxisLabels);
20957 var graphics = new Graphics(this.dCtx.ctx);
20958 var xLabelrect = graphics.getTextRects(val, fontSize);
20959 var xArrLabelrect = xLabelrect;
20960 if (val !== valArr) {
20961 xArrLabelrect = graphics.getTextRects(valArr, fontSize);
20962 }
20963 rect = {
20964 width: xLabelrect.width >= xArrLabelrect.width ? xLabelrect.width : xArrLabelrect.width,
20965 height: xLabelrect.height >= xArrLabelrect.height ? xLabelrect.height : xArrLabelrect.height
20966 };
20967 if (!w.config.xaxis.labels.show) {
20968 rect = {
20969 width: 0,
20970 height: 0
20971 };
20972 }
20973 return {
20974 width: rect.width,
20975 height: rect.height
20976 };
20977 }
20978
20979 /**
20980 * Get X Axis Title Dimensions
20981 * @memberof Dimensions
20982 * @return {{width, height}}
20983 **/
20984 }, {
20985 key: "getxAxisTitleCoords",
20986 value: function getxAxisTitleCoords() {
20987 var w = this.w;
20988 var width = 0;
20989 var height = 0;
20990 if (w.config.xaxis.title.text !== undefined) {
20991 var graphics = new Graphics(this.dCtx.ctx);
20992 var rect = graphics.getTextRects(w.config.xaxis.title.text, w.config.xaxis.title.style.fontSize);
20993 width = rect.width;
20994 height = rect.height;
20995 }
20996 return {
20997 width: width,
20998 height: height
20999 };
21000 }
21001 }, {
21002 key: "getxAxisTimeScaleLabelsCoords",
21003 value: function getxAxisTimeScaleLabelsCoords() {
21004 var w = this.w;
21005 var rect;
21006 this.dCtx.timescaleLabels = w.globals.timescaleLabels.slice();
21007 var labels = this.dCtx.timescaleLabels.map(function (label) {
21008 return label.value;
21009 });
21010
21011 // get the longest string from the labels array and also apply label formatter to it
21012 var val = labels.reduce(function (a, b) {
21013 // if undefined, maybe user didn't pass the datetime(x) values
21014 if (typeof a === 'undefined') {
21015 console.error('You have possibly supplied invalid Date format. Please supply a valid JavaScript Date');
21016 return 0;
21017 } else {
21018 return a.length > b.length ? a : b;
21019 }
21020 }, 0);
21021 var graphics = new Graphics(this.dCtx.ctx);
21022 rect = graphics.getTextRects(val, w.config.xaxis.labels.style.fontSize);
21023 var totalWidthRotated = rect.width * 1.05 * labels.length;
21024 if (totalWidthRotated > w.globals.gridWidth && w.config.xaxis.labels.rotate !== 0) {
21025 w.globals.overlappingXLabels = true;
21026 }
21027 return rect;
21028 }
21029
21030 // In certain cases, the last labels gets cropped in xaxis.
21031 // Hence, we add some additional padding based on the label length to avoid the last label being cropped or we don't draw it at all
21032 }, {
21033 key: "additionalPaddingXLabels",
21034 value: function additionalPaddingXLabels(xaxisLabelCoords) {
21035 var _this = this;
21036 var w = this.w;
21037 var gl = w.globals;
21038 var cnf = w.config;
21039 var xtype = cnf.xaxis.type;
21040 var lbWidth = xaxisLabelCoords.width;
21041 gl.skipLastTimelinelabel = false;
21042 gl.skipFirstTimelinelabel = false;
21043 var isBarOpposite = w.config.yaxis[0].opposite && w.globals.isBarHorizontal;
21044 var isCollapsed = function isCollapsed(i) {
21045 return gl.collapsedSeriesIndices.indexOf(i) !== -1;
21046 };
21047 var rightPad = function rightPad(yaxe) {
21048 if (_this.dCtx.timescaleLabels && _this.dCtx.timescaleLabels.length) {
21049 // for timeline labels, we take the last label and check if it exceeds gridWidth
21050 var firstimescaleLabel = _this.dCtx.timescaleLabels[0];
21051 var lastTimescaleLabel = _this.dCtx.timescaleLabels[_this.dCtx.timescaleLabels.length - 1];
21052 var lastLabelPosition = lastTimescaleLabel.position + lbWidth / 1.75 - _this.dCtx.yAxisWidthRight;
21053 var firstLabelPosition = firstimescaleLabel.position - lbWidth / 1.75 + _this.dCtx.yAxisWidthLeft;
21054 var lgRightRectWidth = w.config.legend.position === 'right' && _this.dCtx.lgRect.width > 0 ? _this.dCtx.lgRect.width : 0;
21055 if (lastLabelPosition > gl.svgWidth - gl.translateX - lgRightRectWidth) {
21056 gl.skipLastTimelinelabel = true;
21057 }
21058 if (firstLabelPosition < -((!yaxe.show || yaxe.floating) && (cnf.chart.type === 'bar' || cnf.chart.type === 'candlestick' || cnf.chart.type === 'rangeBar' || cnf.chart.type === 'boxPlot') ? lbWidth / 1.75 : 10)) {
21059 gl.skipFirstTimelinelabel = true;
21060 }
21061 } else if (xtype === 'datetime') {
21062 // If user has enabled DateTime, but uses own's formatter
21063 if (_this.dCtx.gridPad.right < lbWidth && !gl.rotateXLabels) {
21064 gl.skipLastTimelinelabel = true;
21065 }
21066 } else if (xtype !== 'datetime') {
21067 if (_this.dCtx.gridPad.right < lbWidth / 2 - _this.dCtx.yAxisWidthRight && !gl.rotateXLabels && !w.config.xaxis.labels.trim) {
21068 _this.dCtx.xPadRight = lbWidth / 2 + 1;
21069 }
21070 }
21071 };
21072 var padYAxe = function padYAxe(yaxe, i) {
21073 if (cnf.yaxis.length > 1 && isCollapsed(i)) return;
21074 rightPad(yaxe);
21075 };
21076 cnf.yaxis.forEach(function (yaxe, i) {
21077 if (isBarOpposite) {
21078 if (_this.dCtx.gridPad.left < lbWidth) {
21079 _this.dCtx.xPadLeft = lbWidth / 2 + 1;
21080 }
21081 _this.dCtx.xPadRight = lbWidth / 2 + 1;
21082 } else {
21083 padYAxe(yaxe, i);
21084 }
21085 });
21086 }
21087 }]);
21088 return DimXAxis;
21089 }();
21090
21091 var DimYAxis = /*#__PURE__*/function () {
21092 function DimYAxis(dCtx) {
21093 _classCallCheck(this, DimYAxis);
21094 this.w = dCtx.w;
21095 this.dCtx = dCtx;
21096 }
21097
21098 /**
21099 * Get Y Axis Dimensions
21100 * @memberof Dimensions
21101 * @return {{width, height}}
21102 **/
21103 _createClass(DimYAxis, [{
21104 key: "getyAxisLabelsCoords",
21105 value: function getyAxisLabelsCoords() {
21106 var _this = this;
21107 var w = this.w;
21108 var width = 0;
21109 var height = 0;
21110 var ret = [];
21111 var labelPad = 10;
21112 var axesUtils = new AxesUtils(this.dCtx.ctx);
21113 w.config.yaxis.map(function (yaxe, index) {
21114 var formatterArgs = {
21115 seriesIndex: index,
21116 dataPointIndex: -1,
21117 w: w
21118 };
21119 var yS = w.globals.yAxisScale[index];
21120 var yAxisMinWidth = 0;
21121 if (!axesUtils.isYAxisHidden(index) && yaxe.labels.show && yaxe.labels.minWidth !== undefined) yAxisMinWidth = yaxe.labels.minWidth;
21122 if (!axesUtils.isYAxisHidden(index) && yaxe.labels.show && yS.result.length) {
21123 var lbFormatter = w.globals.yLabelFormatters[index];
21124 var minV = yS.niceMin === Number.MIN_VALUE ? 0 : yS.niceMin;
21125 var val = yS.result.reduce(function (acc, curr) {
21126 var _String, _String2;
21127 return ((_String = String(lbFormatter(acc, formatterArgs))) === null || _String === void 0 ? void 0 : _String.length) > ((_String2 = String(lbFormatter(curr, formatterArgs))) === null || _String2 === void 0 ? void 0 : _String2.length) ? acc : curr;
21128 }, minV);
21129 val = lbFormatter(val, formatterArgs);
21130
21131 // the second parameter -1 is the index of tick which user can use in the formatter
21132 var valArr = val;
21133
21134 // if user has specified a custom formatter, and the result is null or empty, we need to discard the formatter and take the value as it is.
21135 if (typeof val === 'undefined' || val.length === 0) {
21136 val = yS.niceMax;
21137 }
21138 if (w.globals.isBarHorizontal) {
21139 labelPad = 0;
21140 var barYaxisLabels = w.globals.labels.slice();
21141
21142 // get the longest string from the labels array and also apply label formatter to it
21143 val = Utils$1.getLargestStringFromArr(barYaxisLabels);
21144 val = lbFormatter(val, {
21145 seriesIndex: index,
21146 dataPointIndex: -1,
21147 w: w
21148 });
21149 valArr = _this.dCtx.dimHelpers.getLargestStringFromMultiArr(val, barYaxisLabels);
21150 }
21151 var graphics = new Graphics(_this.dCtx.ctx);
21152 var rotateStr = 'rotate('.concat(yaxe.labels.rotate, ' 0 0)');
21153 var rect = graphics.getTextRects(val, yaxe.labels.style.fontSize, yaxe.labels.style.fontFamily, rotateStr, false);
21154 var arrLabelrect = rect;
21155 if (val !== valArr) {
21156 arrLabelrect = graphics.getTextRects(valArr, yaxe.labels.style.fontSize, yaxe.labels.style.fontFamily, rotateStr, false);
21157 }
21158 ret.push({
21159 width: (yAxisMinWidth > arrLabelrect.width || yAxisMinWidth > rect.width ? yAxisMinWidth : arrLabelrect.width > rect.width ? arrLabelrect.width : rect.width) + labelPad,
21160 height: arrLabelrect.height > rect.height ? arrLabelrect.height : rect.height
21161 });
21162 } else {
21163 ret.push({
21164 width: width,
21165 height: height
21166 });
21167 }
21168 });
21169 return ret;
21170 }
21171
21172 /**
21173 * Get Y Axis Dimensions
21174 * @memberof Dimensions
21175 * @return {{width, height}}
21176 **/
21177 }, {
21178 key: "getyAxisTitleCoords",
21179 value: function getyAxisTitleCoords() {
21180 var _this2 = this;
21181 var w = this.w;
21182 var ret = [];
21183 w.config.yaxis.map(function (yaxe, index) {
21184 if (yaxe.show && yaxe.title.text !== undefined) {
21185 var graphics = new Graphics(_this2.dCtx.ctx);
21186 var rotateStr = 'rotate('.concat(yaxe.title.rotate, ' 0 0)');
21187 var rect = graphics.getTextRects(yaxe.title.text, yaxe.title.style.fontSize, yaxe.title.style.fontFamily, rotateStr, false);
21188 ret.push({
21189 width: rect.width,
21190 height: rect.height
21191 });
21192 } else {
21193 ret.push({
21194 width: 0,
21195 height: 0
21196 });
21197 }
21198 });
21199 return ret;
21200 }
21201 }, {
21202 key: "getTotalYAxisWidth",
21203 value: function getTotalYAxisWidth() {
21204 var w = this.w;
21205 var yAxisWidth = 0;
21206 var yAxisWidthLeft = 0;
21207 var yAxisWidthRight = 0;
21208 var padding = w.globals.yAxisScale.length > 1 ? 10 : 0;
21209 var axesUtils = new AxesUtils(this.dCtx.ctx);
21210 var isHiddenYAxis = function isHiddenYAxis(index) {
21211 return w.globals.ignoreYAxisIndexes.indexOf(index) > -1;
21212 };
21213 var padForLabelTitle = function padForLabelTitle(coord, index) {
21214 var floating = w.config.yaxis[index].floating;
21215 var width = 0;
21216 if (coord.width > 0 && !floating) {
21217 width = coord.width + padding;
21218 if (isHiddenYAxis(index)) {
21219 width = width - coord.width - padding;
21220 }
21221 } else {
21222 width = floating || axesUtils.isYAxisHidden(index) ? 0 : 5;
21223 }
21224 w.config.yaxis[index].opposite ? yAxisWidthRight = yAxisWidthRight + width : yAxisWidthLeft = yAxisWidthLeft + width;
21225 yAxisWidth = yAxisWidth + width;
21226 };
21227 w.globals.yLabelsCoords.map(function (yLabelCoord, index) {
21228 padForLabelTitle(yLabelCoord, index);
21229 });
21230 w.globals.yTitleCoords.map(function (yTitleCoord, index) {
21231 padForLabelTitle(yTitleCoord, index);
21232 });
21233 if (w.globals.isBarHorizontal && !w.config.yaxis[0].floating) {
21234 yAxisWidth = w.globals.yLabelsCoords[0].width + w.globals.yTitleCoords[0].width + 15;
21235 }
21236 this.dCtx.yAxisWidthLeft = yAxisWidthLeft;
21237 this.dCtx.yAxisWidthRight = yAxisWidthRight;
21238 return yAxisWidth;
21239 }
21240 }]);
21241 return DimYAxis;
21242 }();
21243
21244 var DimGrid = /*#__PURE__*/function () {
21245 function DimGrid(dCtx) {
21246 _classCallCheck(this, DimGrid);
21247 this.w = dCtx.w;
21248 this.dCtx = dCtx;
21249 }
21250 _createClass(DimGrid, [{
21251 key: "gridPadForColumnsInNumericAxis",
21252 value: function gridPadForColumnsInNumericAxis(gridWidth) {
21253 var w = this.w;
21254 var cnf = w.config,
21255 gl = w.globals;
21256 if (gl.noData || gl.collapsedSeries.length + gl.ancillaryCollapsedSeries.length === cnf.series.length) {
21257 return 0;
21258 }
21259 var hasBar = function hasBar(type) {
21260 return ['bar', 'rangeBar', 'candlestick', 'boxPlot'].includes(type);
21261 };
21262 var type = cnf.chart.type;
21263 var barWidth = 0;
21264 var seriesLen = hasBar(type) ? cnf.series.length : 1;
21265 if (gl.comboBarCount > 0) {
21266 seriesLen = gl.comboBarCount;
21267 }
21268 gl.collapsedSeries.forEach(function (c) {
21269 if (hasBar(c.type)) {
21270 seriesLen -= 1;
21271 }
21272 });
21273 if (cnf.chart.stacked) {
21274 seriesLen = 1;
21275 }
21276 var barsPresent = hasBar(type) || gl.comboBarCount > 0;
21277 var xRange = Math.abs(gl.initialMaxX - gl.initialMinX);
21278 if (barsPresent && gl.isXNumeric && !gl.isBarHorizontal && seriesLen > 0 && xRange !== 0) {
21279 if (xRange <= 3) {
21280 xRange = gl.dataPoints;
21281 }
21282 var xRatio = xRange / gridWidth;
21283 var xDivision = gl.minXDiff && gl.minXDiff / xRatio > 0 ? gl.minXDiff / xRatio : 0;
21284 if (xDivision > gridWidth / 2) {
21285 xDivision /= 2;
21286 }
21287 // Here, barWidth is assumed to be the width occupied by a group of bars.
21288 // There will be one bar in the group for each series plotted.
21289 // Note: This version of the following math is different to that over in
21290 // Helpers.js. Don't assume they should be the same. Over there,
21291 // xDivision is computed differently and it's used on different charts.
21292 // They were the same, but the solution to
21293 // https://github.com/apexcharts/apexcharts.js/issues/4178
21294 // was to remove the division by seriesLen.
21295 barWidth = xDivision * parseInt(cnf.plotOptions.bar.columnWidth, 10) / 100;
21296 if (barWidth < 1) {
21297 barWidth = 1;
21298 }
21299 gl.barPadForNumericAxis = barWidth;
21300 }
21301 return barWidth;
21302 }
21303 }, {
21304 key: "gridPadFortitleSubtitle",
21305 value: function gridPadFortitleSubtitle() {
21306 var _this = this;
21307 var w = this.w;
21308 var gl = w.globals;
21309 var gridShrinkOffset = this.dCtx.isSparkline || !gl.axisCharts ? 0 : 10;
21310 var titleSubtitle = ['title', 'subtitle'];
21311 titleSubtitle.forEach(function (t) {
21312 if (w.config[t].text !== undefined) {
21313 gridShrinkOffset += w.config[t].margin;
21314 } else {
21315 gridShrinkOffset += _this.dCtx.isSparkline || !gl.axisCharts ? 0 : 5;
21316 }
21317 });
21318 if (w.config.legend.show && w.config.legend.position === 'bottom' && !w.config.legend.floating && !gl.axisCharts) {
21319 gridShrinkOffset += 10;
21320 }
21321 var titleCoords = this.dCtx.dimHelpers.getTitleSubtitleCoords('title');
21322 var subtitleCoords = this.dCtx.dimHelpers.getTitleSubtitleCoords('subtitle');
21323 gl.gridHeight -= titleCoords.height + subtitleCoords.height + gridShrinkOffset;
21324 gl.translateY += titleCoords.height + subtitleCoords.height + gridShrinkOffset;
21325 }
21326 }, {
21327 key: "setGridXPosForDualYAxis",
21328 value: function setGridXPosForDualYAxis(yTitleCoords, yaxisLabelCoords) {
21329 var w = this.w;
21330 var axesUtils = new AxesUtils(this.dCtx.ctx);
21331 w.config.yaxis.forEach(function (yaxe, index) {
21332 if (w.globals.ignoreYAxisIndexes.indexOf(index) === -1 && !yaxe.floating && !axesUtils.isYAxisHidden(index)) {
21333 if (yaxe.opposite) {
21334 w.globals.translateX -= yaxisLabelCoords[index].width + yTitleCoords[index].width + parseInt(yaxe.labels.style.fontSize, 10) / 1.2 + 12;
21335 }
21336
21337 // fixes apexcharts.js#1599
21338 if (w.globals.translateX < 2) {
21339 w.globals.translateX = 2;
21340 }
21341 }
21342 });
21343 }
21344 }]);
21345 return DimGrid;
21346 }();
21347
21348 /**
21349 * ApexCharts Dimensions Class for calculating rects of all elements that are drawn and will be drawn.
21350 *
21351 * @module Dimensions
21352 **/
21353 var Dimensions = /*#__PURE__*/function () {
21354 function Dimensions(ctx) {
21355 _classCallCheck(this, Dimensions);
21356 this.ctx = ctx;
21357 this.w = ctx.w;
21358 this.lgRect = {};
21359 this.yAxisWidth = 0;
21360 this.yAxisWidthLeft = 0;
21361 this.yAxisWidthRight = 0;
21362 this.xAxisHeight = 0;
21363 this.isSparkline = this.w.config.chart.sparkline.enabled;
21364 this.dimHelpers = new Helpers$3(this);
21365 this.dimYAxis = new DimYAxis(this);
21366 this.dimXAxis = new DimXAxis(this);
21367 this.dimGrid = new DimGrid(this);
21368 this.lgWidthForSideLegends = 0;
21369 this.gridPad = this.w.config.grid.padding;
21370 this.xPadRight = 0;
21371 this.xPadLeft = 0;
21372 }
21373
21374 /**
21375 * @memberof Dimensions
21376 * @param {object} w - chart context
21377 **/
21378 _createClass(Dimensions, [{
21379 key: "plotCoords",
21380 value: function plotCoords() {
21381 var _this = this;
21382 var w = this.w;
21383 var gl = w.globals;
21384 this.lgRect = this.dimHelpers.getLegendsRect();
21385 this.datalabelsCoords = {
21386 width: 0,
21387 height: 0
21388 };
21389 var maxStrokeWidth = Array.isArray(w.config.stroke.width) ? Math.max.apply(Math, _toConsumableArray(w.config.stroke.width)) : w.config.stroke.width;
21390 if (this.isSparkline) {
21391 if (w.config.markers.discrete.length > 0 || w.config.markers.size > 0) {
21392 Object.entries(this.gridPad).forEach(function (_ref) {
21393 var _ref2 = _slicedToArray(_ref, 2),
21394 k = _ref2[0],
21395 v = _ref2[1];
21396 _this.gridPad[k] = Math.max(v, _this.w.globals.markers.largestSize / 1.5);
21397 });
21398 }
21399 this.gridPad.top = Math.max(maxStrokeWidth / 2, this.gridPad.top);
21400 this.gridPad.bottom = Math.max(maxStrokeWidth / 2, this.gridPad.bottom);
21401 }
21402 if (gl.axisCharts) {
21403 // for line / area / scatter / column
21404 this.setDimensionsForAxisCharts();
21405 } else {
21406 // for pie / donuts / circle
21407 this.setDimensionsForNonAxisCharts();
21408 }
21409 this.dimGrid.gridPadFortitleSubtitle();
21410
21411 // after calculating everything, apply padding set by user
21412 gl.gridHeight = gl.gridHeight - this.gridPad.top - this.gridPad.bottom;
21413 gl.gridWidth = gl.gridWidth - this.gridPad.left - this.gridPad.right - this.xPadRight - this.xPadLeft;
21414 var barWidth = this.dimGrid.gridPadForColumnsInNumericAxis(gl.gridWidth);
21415 gl.gridWidth = gl.gridWidth - barWidth * 2;
21416 gl.translateX = gl.translateX + this.gridPad.left + this.xPadLeft + (barWidth > 0 ? barWidth : 0);
21417 gl.translateY = gl.translateY + this.gridPad.top;
21418 }
21419 }, {
21420 key: "setDimensionsForAxisCharts",
21421 value: function setDimensionsForAxisCharts() {
21422 var _this2 = this;
21423 var w = this.w;
21424 var gl = w.globals;
21425 var yaxisLabelCoords = this.dimYAxis.getyAxisLabelsCoords();
21426 var yTitleCoords = this.dimYAxis.getyAxisTitleCoords();
21427 if (gl.isSlopeChart) {
21428 this.datalabelsCoords = this.dimHelpers.getDatalabelsRect();
21429 }
21430 w.globals.yLabelsCoords = [];
21431 w.globals.yTitleCoords = [];
21432 w.config.yaxis.map(function (yaxe, index) {
21433 // store the labels and titles coords in global vars
21434 w.globals.yLabelsCoords.push({
21435 width: yaxisLabelCoords[index].width,
21436 index: index
21437 });
21438 w.globals.yTitleCoords.push({
21439 width: yTitleCoords[index].width,
21440 index: index
21441 });
21442 });
21443 this.yAxisWidth = this.dimYAxis.getTotalYAxisWidth();
21444 var xaxisLabelCoords = this.dimXAxis.getxAxisLabelsCoords();
21445 var xaxisGroupLabelCoords = this.dimXAxis.getxAxisGroupLabelsCoords();
21446 var xtitleCoords = this.dimXAxis.getxAxisTitleCoords();
21447 this.conditionalChecksForAxisCoords(xaxisLabelCoords, xtitleCoords, xaxisGroupLabelCoords);
21448 gl.translateXAxisY = w.globals.rotateXLabels ? this.xAxisHeight / 8 : -4;
21449 gl.translateXAxisX = w.globals.rotateXLabels && w.globals.isXNumeric && w.config.xaxis.labels.rotate <= -45 ? -this.xAxisWidth / 4 : 0;
21450 if (w.globals.isBarHorizontal) {
21451 gl.rotateXLabels = false;
21452 gl.translateXAxisY = -1 * (parseInt(w.config.xaxis.labels.style.fontSize, 10) / 1.5);
21453 }
21454 gl.translateXAxisY = gl.translateXAxisY + w.config.xaxis.labels.offsetY;
21455 gl.translateXAxisX = gl.translateXAxisX + w.config.xaxis.labels.offsetX;
21456 var yAxisWidth = this.yAxisWidth;
21457 var xAxisHeight = this.xAxisHeight;
21458 gl.xAxisLabelsHeight = this.xAxisHeight - xtitleCoords.height;
21459 gl.xAxisGroupLabelsHeight = gl.xAxisLabelsHeight - xaxisLabelCoords.height;
21460 gl.xAxisLabelsWidth = this.xAxisWidth;
21461 gl.xAxisHeight = this.xAxisHeight;
21462 var translateY = 10;
21463 if (w.config.chart.type === 'radar' || this.isSparkline) {
21464 yAxisWidth = 0;
21465 xAxisHeight = 0;
21466 }
21467 if (this.isSparkline) {
21468 this.lgRect = {
21469 height: 0,
21470 width: 0
21471 };
21472 }
21473 if (this.isSparkline || w.config.chart.type === 'treemap') {
21474 yAxisWidth = 0;
21475 xAxisHeight = 0;
21476 translateY = 0;
21477 }
21478 if (!this.isSparkline && w.config.chart.type !== 'treemap') {
21479 this.dimXAxis.additionalPaddingXLabels(xaxisLabelCoords);
21480 }
21481 var legendTopBottom = function legendTopBottom() {
21482 gl.translateX = yAxisWidth + _this2.datalabelsCoords.width;
21483 gl.gridHeight = gl.svgHeight - _this2.lgRect.height - xAxisHeight - (!_this2.isSparkline && w.config.chart.type !== 'treemap' ? w.globals.rotateXLabels ? 10 : 15 : 0);
21484 gl.gridWidth = gl.svgWidth - yAxisWidth - _this2.datalabelsCoords.width * 2;
21485 };
21486 if (w.config.xaxis.position === 'top') translateY = gl.xAxisHeight - w.config.xaxis.axisTicks.height - 5;
21487 switch (w.config.legend.position) {
21488 case 'bottom':
21489 gl.translateY = translateY;
21490 legendTopBottom();
21491 break;
21492 case 'top':
21493 gl.translateY = this.lgRect.height + translateY;
21494 legendTopBottom();
21495 break;
21496 case 'left':
21497 gl.translateY = translateY;
21498 gl.translateX = this.lgRect.width + yAxisWidth + this.datalabelsCoords.width;
21499 gl.gridHeight = gl.svgHeight - xAxisHeight - 12;
21500 gl.gridWidth = gl.svgWidth - this.lgRect.width - yAxisWidth - this.datalabelsCoords.width * 2;
21501 break;
21502 case 'right':
21503 gl.translateY = translateY;
21504 gl.translateX = yAxisWidth + this.datalabelsCoords.width;
21505 gl.gridHeight = gl.svgHeight - xAxisHeight - 12;
21506 gl.gridWidth = gl.svgWidth - this.lgRect.width - yAxisWidth - this.datalabelsCoords.width * 2 - 5;
21507 break;
21508 default:
21509 throw new Error('Legend position not supported');
21510 }
21511 this.dimGrid.setGridXPosForDualYAxis(yTitleCoords, yaxisLabelCoords);
21512
21513 // after drawing everything, set the Y axis positions
21514 var objyAxis = new YAxis(this.ctx);
21515 objyAxis.setYAxisXPosition(yaxisLabelCoords, yTitleCoords);
21516 }
21517 }, {
21518 key: "setDimensionsForNonAxisCharts",
21519 value: function setDimensionsForNonAxisCharts() {
21520 var w = this.w;
21521 var gl = w.globals;
21522 var cnf = w.config;
21523 var xPad = 0;
21524 if (w.config.legend.show && !w.config.legend.floating) {
21525 xPad = 20;
21526 }
21527 var type = cnf.chart.type === 'pie' || cnf.chart.type === 'polarArea' || cnf.chart.type === 'donut' ? 'pie' : 'radialBar';
21528 var offY = cnf.plotOptions[type].offsetY;
21529 var offX = cnf.plotOptions[type].offsetX;
21530 if (!cnf.legend.show || cnf.legend.floating) {
21531 gl.gridHeight = gl.svgHeight;
21532 var maxWidth = gl.dom.elWrap.getBoundingClientRect().width;
21533 gl.gridWidth = Math.min(maxWidth, gl.gridHeight);
21534 gl.translateY = offY;
21535 gl.translateX = offX + (gl.svgWidth - gl.gridWidth) / 2;
21536 return;
21537 }
21538 switch (cnf.legend.position) {
21539 case 'bottom':
21540 gl.gridHeight = gl.svgHeight - this.lgRect.height;
21541 gl.gridWidth = gl.svgWidth;
21542 gl.translateY = offY - 10;
21543 gl.translateX = offX + (gl.svgWidth - gl.gridWidth) / 2;
21544 break;
21545 case 'top':
21546 gl.gridHeight = gl.svgHeight - this.lgRect.height;
21547 gl.gridWidth = gl.svgWidth;
21548 gl.translateY = this.lgRect.height + offY + 10;
21549 gl.translateX = offX + (gl.svgWidth - gl.gridWidth) / 2;
21550 break;
21551 case 'left':
21552 gl.gridWidth = gl.svgWidth - this.lgRect.width - xPad;
21553 gl.gridHeight = cnf.chart.height !== 'auto' ? gl.svgHeight : gl.gridWidth;
21554 gl.translateY = offY;
21555 gl.translateX = offX + this.lgRect.width + xPad;
21556 break;
21557 case 'right':
21558 gl.gridWidth = gl.svgWidth - this.lgRect.width - xPad - 5;
21559 gl.gridHeight = cnf.chart.height !== 'auto' ? gl.svgHeight : gl.gridWidth;
21560 gl.translateY = offY;
21561 gl.translateX = offX + 10;
21562 break;
21563 default:
21564 throw new Error('Legend position not supported');
21565 }
21566 }
21567 }, {
21568 key: "conditionalChecksForAxisCoords",
21569 value: function conditionalChecksForAxisCoords(xaxisLabelCoords, xtitleCoords, xaxisGroupLabelCoords) {
21570 var w = this.w;
21571 var xAxisNum = w.globals.hasXaxisGroups ? 2 : 1;
21572 var baseXAxisHeight = xaxisGroupLabelCoords.height + xaxisLabelCoords.height + xtitleCoords.height;
21573 var xAxisHeightMultiplicate = w.globals.isMultiLineX ? 1.2 : w.globals.LINE_HEIGHT_RATIO;
21574 var rotatedXAxisOffset = w.globals.rotateXLabels ? 22 : 10;
21575 var rotatedXAxisLegendOffset = w.globals.rotateXLabels && w.config.legend.position === 'bottom';
21576 var additionalOffset = rotatedXAxisLegendOffset ? 10 : 0;
21577 this.xAxisHeight = baseXAxisHeight * xAxisHeightMultiplicate + xAxisNum * rotatedXAxisOffset + additionalOffset;
21578 this.xAxisWidth = xaxisLabelCoords.width;
21579 if (this.xAxisHeight - xtitleCoords.height > w.config.xaxis.labels.maxHeight) {
21580 this.xAxisHeight = w.config.xaxis.labels.maxHeight;
21581 }
21582 if (w.config.xaxis.labels.minHeight && this.xAxisHeight < w.config.xaxis.labels.minHeight) {
21583 this.xAxisHeight = w.config.xaxis.labels.minHeight;
21584 }
21585 if (w.config.xaxis.floating) {
21586 this.xAxisHeight = 0;
21587 }
21588 var minYAxisWidth = 0;
21589 var maxYAxisWidth = 0;
21590 w.config.yaxis.forEach(function (y) {
21591 minYAxisWidth += y.labels.minWidth;
21592 maxYAxisWidth += y.labels.maxWidth;
21593 });
21594 if (this.yAxisWidth < minYAxisWidth) {
21595 this.yAxisWidth = minYAxisWidth;
21596 }
21597 if (this.yAxisWidth > maxYAxisWidth) {
21598 this.yAxisWidth = maxYAxisWidth;
21599 }
21600 }
21601 }]);
21602 return Dimensions;
21603 }();
21604
21605 var Helpers$2 = /*#__PURE__*/function () {
21606 function Helpers(lgCtx) {
21607 _classCallCheck(this, Helpers);
21608 this.w = lgCtx.w;
21609 this.lgCtx = lgCtx;
21610 }
21611 _createClass(Helpers, [{
21612 key: "getLegendStyles",
21613 value: function getLegendStyles() {
21614 var _this$lgCtx$ctx, _this$lgCtx$ctx$opts, _this$lgCtx$ctx$opts$;
21615 var stylesheet = document.createElement('style');
21616 stylesheet.setAttribute('type', 'text/css');
21617 var nonce = ((_this$lgCtx$ctx = this.lgCtx.ctx) === null || _this$lgCtx$ctx === void 0 ? void 0 : (_this$lgCtx$ctx$opts = _this$lgCtx$ctx.opts) === null || _this$lgCtx$ctx$opts === void 0 ? void 0 : (_this$lgCtx$ctx$opts$ = _this$lgCtx$ctx$opts.chart) === null || _this$lgCtx$ctx$opts$ === void 0 ? void 0 : _this$lgCtx$ctx$opts$.nonce) || this.w.config.chart.nonce;
21618 if (nonce) {
21619 stylesheet.setAttribute('nonce', nonce);
21620 }
21621 var text = "\n .apexcharts-flip-y {\n transform: scaleY(-1) translateY(-100%);\n transform-origin: top;\n transform-box: fill-box;\n }\n .apexcharts-flip-x {\n transform: scaleX(-1);\n transform-origin: center;\n transform-box: fill-box;\n }\n .apexcharts-legend {\n display: flex;\n overflow: auto;\n padding: 0 10px;\n }\n .apexcharts-legend.apexcharts-legend-group-horizontal {\n flex-direction: column;\n }\n .apexcharts-legend-group {\n display: flex;\n }\n .apexcharts-legend-group-vertical {\n flex-direction: column-reverse;\n }\n .apexcharts-legend.apx-legend-position-bottom, .apexcharts-legend.apx-legend-position-top {\n flex-wrap: wrap\n }\n .apexcharts-legend.apx-legend-position-right, .apexcharts-legend.apx-legend-position-left {\n flex-direction: column;\n bottom: 0;\n }\n .apexcharts-legend.apx-legend-position-bottom.apexcharts-align-left, .apexcharts-legend.apx-legend-position-top.apexcharts-align-left, .apexcharts-legend.apx-legend-position-right, .apexcharts-legend.apx-legend-position-left {\n justify-content: flex-start;\n align-items: flex-start;\n }\n .apexcharts-legend.apx-legend-position-bottom.apexcharts-align-center, .apexcharts-legend.apx-legend-position-top.apexcharts-align-center {\n justify-content: center;\n align-items: center;\n }\n .apexcharts-legend.apx-legend-position-bottom.apexcharts-align-right, .apexcharts-legend.apx-legend-position-top.apexcharts-align-right {\n justify-content: flex-end;\n align-items: flex-end;\n }\n .apexcharts-legend-series {\n cursor: pointer;\n line-height: normal;\n display: flex;\n align-items: center;\n }\n .apexcharts-legend-text {\n position: relative;\n font-size: 14px;\n }\n .apexcharts-legend-text *, .apexcharts-legend-marker * {\n pointer-events: none;\n }\n .apexcharts-legend-marker {\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n margin-right: 1px;\n }\n\n .apexcharts-legend-series.apexcharts-no-click {\n cursor: auto;\n }\n .apexcharts-legend .apexcharts-hidden-zero-series, .apexcharts-legend .apexcharts-hidden-null-series {\n display: none !important;\n }\n .apexcharts-inactive-legend {\n opacity: 0.45;\n }\n\n ";
21622 var rules = document.createTextNode(text);
21623 stylesheet.appendChild(rules);
21624 return stylesheet;
21625 }
21626 }, {
21627 key: "getLegendDimensions",
21628 value: function getLegendDimensions() {
21629 var w = this.w;
21630 var currLegendsWrap = w.globals.dom.baseEl.querySelector('.apexcharts-legend');
21631 var _currLegendsWrap$getB = currLegendsWrap.getBoundingClientRect(),
21632 currLegendsWrapWidth = _currLegendsWrap$getB.width,
21633 currLegendsWrapHeight = _currLegendsWrap$getB.height;
21634 return {
21635 clwh: currLegendsWrapHeight,
21636 clww: currLegendsWrapWidth
21637 };
21638 }
21639 }, {
21640 key: "appendToForeignObject",
21641 value: function appendToForeignObject() {
21642 var gl = this.w.globals;
21643 gl.dom.elLegendForeign.appendChild(this.getLegendStyles());
21644 }
21645 }, {
21646 key: "toggleDataSeries",
21647 value: function toggleDataSeries(seriesCnt, isHidden) {
21648 var _this = this;
21649 var w = this.w;
21650 if (w.globals.axisCharts || w.config.chart.type === 'radialBar') {
21651 w.globals.resized = true; // we don't want initial animations again
21652
21653 var seriesEl = null;
21654 var realIndex = null;
21655
21656 // yes, make it null. 1 series will rise at a time
21657 w.globals.risingSeries = [];
21658 if (w.globals.axisCharts) {
21659 seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[data\\:realIndex='".concat(seriesCnt, "']"));
21660 realIndex = parseInt(seriesEl.getAttribute('data:realIndex'), 10);
21661 } else {
21662 seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[rel='".concat(seriesCnt + 1, "']"));
21663 realIndex = parseInt(seriesEl.getAttribute('rel'), 10) - 1;
21664 }
21665 if (isHidden) {
21666 var seriesToMakeVisible = [{
21667 cs: w.globals.collapsedSeries,
21668 csi: w.globals.collapsedSeriesIndices
21669 }, {
21670 cs: w.globals.ancillaryCollapsedSeries,
21671 csi: w.globals.ancillaryCollapsedSeriesIndices
21672 }];
21673 seriesToMakeVisible.forEach(function (r) {
21674 _this.riseCollapsedSeries(r.cs, r.csi, realIndex);
21675 });
21676 } else {
21677 this.hideSeries({
21678 seriesEl: seriesEl,
21679 realIndex: realIndex
21680 });
21681 }
21682 } else {
21683 // for non-axis charts i.e pie / donuts
21684 var _seriesEl = w.globals.dom.Paper.findOne(" .apexcharts-series[rel='".concat(seriesCnt + 1, "'] path"));
21685 var type = w.config.chart.type;
21686 if (type === 'pie' || type === 'polarArea' || type === 'donut') {
21687 var dataLabels = w.config.plotOptions.pie.donut.labels;
21688 var graphics = new Graphics(this.lgCtx.ctx);
21689 graphics.pathMouseDown(_seriesEl, null);
21690 this.lgCtx.ctx.pie.printDataLabelsInner(_seriesEl.node, dataLabels);
21691 }
21692 _seriesEl.fire('click');
21693 }
21694 }
21695 }, {
21696 key: "getSeriesAfterCollapsing",
21697 value: function getSeriesAfterCollapsing(_ref) {
21698 var realIndex = _ref.realIndex;
21699 var w = this.w;
21700 var gl = w.globals;
21701 var series = Utils$1.clone(w.config.series);
21702 if (gl.axisCharts) {
21703 var yaxis = w.config.yaxis[gl.seriesYAxisReverseMap[realIndex]];
21704 var collapseData = {
21705 index: realIndex,
21706 data: series[realIndex].data.slice(),
21707 type: series[realIndex].type || w.config.chart.type
21708 };
21709 if (yaxis && yaxis.show && yaxis.showAlways) {
21710 if (gl.ancillaryCollapsedSeriesIndices.indexOf(realIndex) < 0) {
21711 gl.ancillaryCollapsedSeries.push(collapseData);
21712 gl.ancillaryCollapsedSeriesIndices.push(realIndex);
21713 }
21714 } else {
21715 if (gl.collapsedSeriesIndices.indexOf(realIndex) < 0) {
21716 gl.collapsedSeries.push(collapseData);
21717 gl.collapsedSeriesIndices.push(realIndex);
21718 var removeIndexOfRising = gl.risingSeries.indexOf(realIndex);
21719 gl.risingSeries.splice(removeIndexOfRising, 1);
21720 }
21721 }
21722 } else {
21723 gl.collapsedSeries.push({
21724 index: realIndex,
21725 data: series[realIndex]
21726 });
21727 gl.collapsedSeriesIndices.push(realIndex);
21728 }
21729 gl.allSeriesCollapsed = gl.collapsedSeries.length + gl.ancillaryCollapsedSeries.length === w.config.series.length;
21730 return this._getSeriesBasedOnCollapsedState(series);
21731 }
21732 }, {
21733 key: "hideSeries",
21734 value: function hideSeries(_ref2) {
21735 var seriesEl = _ref2.seriesEl,
21736 realIndex = _ref2.realIndex;
21737 var w = this.w;
21738 var series = this.getSeriesAfterCollapsing({
21739 realIndex: realIndex
21740 });
21741 var seriesChildren = seriesEl.childNodes;
21742 for (var sc = 0; sc < seriesChildren.length; sc++) {
21743 if (seriesChildren[sc].classList.contains('apexcharts-series-markers-wrap')) {
21744 if (seriesChildren[sc].classList.contains('apexcharts-hide')) {
21745 seriesChildren[sc].classList.remove('apexcharts-hide');
21746 } else {
21747 seriesChildren[sc].classList.add('apexcharts-hide');
21748 }
21749 }
21750 }
21751 this.lgCtx.ctx.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
21752 }
21753 }, {
21754 key: "riseCollapsedSeries",
21755 value: function riseCollapsedSeries(collapsedSeries, seriesIndices, realIndex) {
21756 var w = this.w;
21757 var series = Utils$1.clone(w.config.series);
21758 if (collapsedSeries.length > 0) {
21759 for (var c = 0; c < collapsedSeries.length; c++) {
21760 if (collapsedSeries[c].index === realIndex) {
21761 if (w.globals.axisCharts) {
21762 series[realIndex].data = collapsedSeries[c].data.slice();
21763 } else {
21764 series[realIndex] = collapsedSeries[c].data;
21765 }
21766 if (typeof series[realIndex] !== 'number') {
21767 series[realIndex].hidden = false;
21768 }
21769 collapsedSeries.splice(c, 1);
21770 seriesIndices.splice(c, 1);
21771 w.globals.risingSeries.push(realIndex);
21772 }
21773 }
21774 series = this._getSeriesBasedOnCollapsedState(series);
21775 this.lgCtx.ctx.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
21776 }
21777 }
21778 }, {
21779 key: "_getSeriesBasedOnCollapsedState",
21780 value: function _getSeriesBasedOnCollapsedState(series) {
21781 var w = this.w;
21782 var collapsed = 0;
21783 if (w.globals.axisCharts) {
21784 series.forEach(function (s, sI) {
21785 if (!(w.globals.collapsedSeriesIndices.indexOf(sI) < 0 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(sI) < 0)) {
21786 series[sI].data = [];
21787 collapsed++;
21788 }
21789 });
21790 } else {
21791 series.forEach(function (s, sI) {
21792 if (!w.globals.collapsedSeriesIndices.indexOf(sI) < 0) {
21793 series[sI] = 0;
21794 collapsed++;
21795 }
21796 });
21797 }
21798 w.globals.allSeriesCollapsed = collapsed === series.length;
21799 return series;
21800 }
21801 }]);
21802 return Helpers;
21803 }();
21804
21805 /**
21806 * ApexCharts Legend Class to draw legend.
21807 *
21808 * @module Legend
21809 **/
21810 var Legend = /*#__PURE__*/function () {
21811 function Legend(ctx) {
21812 _classCallCheck(this, Legend);
21813 this.ctx = ctx;
21814 this.w = ctx.w;
21815 this.onLegendClick = this.onLegendClick.bind(this);
21816 this.onLegendHovered = this.onLegendHovered.bind(this);
21817 this.isBarsDistributed = this.w.config.chart.type === 'bar' && this.w.config.plotOptions.bar.distributed && this.w.config.series.length === 1;
21818 this.legendHelpers = new Helpers$2(this);
21819 }
21820 _createClass(Legend, [{
21821 key: "init",
21822 value: function init() {
21823 var w = this.w;
21824 var gl = w.globals;
21825 var cnf = w.config;
21826 var showLegendAlways = cnf.legend.showForSingleSeries && gl.series.length === 1 || this.isBarsDistributed || gl.series.length > 1;
21827 this.legendHelpers.appendToForeignObject();
21828 if ((showLegendAlways || !gl.axisCharts) && cnf.legend.show) {
21829 while (gl.dom.elLegendWrap.firstChild) {
21830 gl.dom.elLegendWrap.removeChild(gl.dom.elLegendWrap.firstChild);
21831 }
21832 this.drawLegends();
21833 if (cnf.legend.position === 'bottom' || cnf.legend.position === 'top') {
21834 this.legendAlignHorizontal();
21835 } else if (cnf.legend.position === 'right' || cnf.legend.position === 'left') {
21836 this.legendAlignVertical();
21837 }
21838 }
21839 }
21840 }, {
21841 key: "createLegendMarker",
21842 value: function createLegendMarker(_ref) {
21843 var i = _ref.i,
21844 fillcolor = _ref.fillcolor;
21845 var w = this.w;
21846 var elMarker = document.createElement('span');
21847 elMarker.classList.add('apexcharts-legend-marker');
21848 var mShape = w.config.legend.markers.shape || w.config.markers.shape;
21849 var shape = mShape;
21850 if (Array.isArray(mShape)) {
21851 shape = mShape[i];
21852 }
21853 var mSize = Array.isArray(w.config.legend.markers.size) ? parseFloat(w.config.legend.markers.size[i]) : parseFloat(w.config.legend.markers.size);
21854 var mOffsetX = Array.isArray(w.config.legend.markers.offsetX) ? parseFloat(w.config.legend.markers.offsetX[i]) : parseFloat(w.config.legend.markers.offsetX);
21855 var mOffsetY = Array.isArray(w.config.legend.markers.offsetY) ? parseFloat(w.config.legend.markers.offsetY[i]) : parseFloat(w.config.legend.markers.offsetY);
21856 var mBorderWidth = Array.isArray(w.config.legend.markers.strokeWidth) ? parseFloat(w.config.legend.markers.strokeWidth[i]) : parseFloat(w.config.legend.markers.strokeWidth);
21857 var mStyle = elMarker.style;
21858 mStyle.height = (mSize + mBorderWidth) * 2 + 'px';
21859 mStyle.width = (mSize + mBorderWidth) * 2 + 'px';
21860 mStyle.left = mOffsetX + 'px';
21861 mStyle.top = mOffsetY + 'px';
21862 if (w.config.legend.markers.customHTML) {
21863 mStyle.background = 'transparent';
21864 mStyle.color = fillcolor[i];
21865 if (Array.isArray(w.config.legend.markers.customHTML)) {
21866 if (w.config.legend.markers.customHTML[i]) {
21867 elMarker.innerHTML = w.config.legend.markers.customHTML[i]();
21868 }
21869 } else {
21870 elMarker.innerHTML = w.config.legend.markers.customHTML();
21871 }
21872 } else {
21873 var markers = new Markers(this.ctx);
21874 var markerConfig = markers.getMarkerConfig({
21875 cssClass: "apexcharts-legend-marker apexcharts-marker apexcharts-marker-".concat(shape),
21876 seriesIndex: i,
21877 strokeWidth: mBorderWidth,
21878 size: mSize
21879 });
21880 var SVGMarker = window.SVG().addTo(elMarker).size('100%', '100%');
21881 var marker = new Graphics(this.ctx).drawMarker(0, 0, _objectSpread2(_objectSpread2({}, markerConfig), {}, {
21882 pointFillColor: Array.isArray(fillcolor) ? fillcolor[i] : markerConfig.pointFillColor,
21883 shape: shape
21884 }));
21885 var shapesEls = w.globals.dom.Paper.find('.apexcharts-legend-marker.apexcharts-marker');
21886 shapesEls.forEach(function (shapeEl) {
21887 if (shapeEl.node.classList.contains('apexcharts-marker-triangle')) {
21888 shapeEl.node.style.transform = 'translate(50%, 45%)';
21889 } else {
21890 shapeEl.node.style.transform = 'translate(50%, 50%)';
21891 }
21892 });
21893 SVGMarker.add(marker);
21894 }
21895 return elMarker;
21896 }
21897 }, {
21898 key: "drawLegends",
21899 value: function drawLegends() {
21900 var _this = this;
21901 var me = this;
21902 var w = this.w;
21903 var fontFamily = w.config.legend.fontFamily;
21904 var legendNames = w.globals.seriesNames;
21905 var fillcolor = w.config.legend.markers.fillColors ? w.config.legend.markers.fillColors.slice() : w.globals.colors.slice();
21906 if (w.config.chart.type === 'heatmap') {
21907 var ranges = w.config.plotOptions.heatmap.colorScale.ranges;
21908 legendNames = ranges.map(function (colorScale) {
21909 return colorScale.name ? colorScale.name : colorScale.from + ' - ' + colorScale.to;
21910 });
21911 fillcolor = ranges.map(function (color) {
21912 return color.color;
21913 });
21914 } else if (this.isBarsDistributed) {
21915 legendNames = w.globals.labels.slice();
21916 }
21917 if (w.config.legend.customLegendItems.length) {
21918 legendNames = w.config.legend.customLegendItems;
21919 }
21920 var legendFormatter = w.globals.legendFormatter;
21921 var isLegendInversed = w.config.legend.inverseOrder;
21922 var legendGroups = [];
21923 if (w.globals.seriesGroups.length > 1 && w.config.legend.clusterGroupedSeries) {
21924 w.globals.seriesGroups.forEach(function (_, gi) {
21925 legendGroups[gi] = document.createElement('div');
21926 legendGroups[gi].classList.add('apexcharts-legend-group', "apexcharts-legend-group-".concat(gi));
21927 if (w.config.legend.clusterGroupedSeriesOrientation === 'horizontal') {
21928 w.globals.dom.elLegendWrap.classList.add('apexcharts-legend-group-horizontal');
21929 } else {
21930 legendGroups[gi].classList.add('apexcharts-legend-group-vertical');
21931 }
21932 });
21933 }
21934 var _loop = function _loop(i) {
21935 var _w$config$legend$labe;
21936 var text = legendFormatter(legendNames[i], {
21937 seriesIndex: i,
21938 w: w
21939 });
21940 var collapsedSeries = false;
21941 var ancillaryCollapsedSeries = false;
21942 if (w.globals.collapsedSeries.length > 0) {
21943 for (var c = 0; c < w.globals.collapsedSeries.length; c++) {
21944 if (w.globals.collapsedSeries[c].index === i) {
21945 collapsedSeries = true;
21946 }
21947 }
21948 }
21949 if (w.globals.ancillaryCollapsedSeriesIndices.length > 0) {
21950 for (var _c = 0; _c < w.globals.ancillaryCollapsedSeriesIndices.length; _c++) {
21951 if (w.globals.ancillaryCollapsedSeriesIndices[_c] === i) {
21952 ancillaryCollapsedSeries = true;
21953 }
21954 }
21955 }
21956 var elMarker = _this.createLegendMarker({
21957 i: i,
21958 fillcolor: fillcolor
21959 });
21960 Graphics.setAttrs(elMarker, {
21961 rel: i + 1,
21962 'data:collapsed': collapsedSeries || ancillaryCollapsedSeries
21963 });
21964 if (collapsedSeries || ancillaryCollapsedSeries) {
21965 elMarker.classList.add('apexcharts-inactive-legend');
21966 }
21967 var elLegend = document.createElement('div');
21968 var elLegendText = document.createElement('span');
21969 elLegendText.classList.add('apexcharts-legend-text');
21970 elLegendText.innerHTML = Array.isArray(text) ? text.join(' ') : text;
21971 var textColor = w.config.legend.labels.useSeriesColors ? w.globals.colors[i] : Array.isArray(w.config.legend.labels.colors) ? (_w$config$legend$labe = w.config.legend.labels.colors) === null || _w$config$legend$labe === void 0 ? void 0 : _w$config$legend$labe[i] : w.config.legend.labels.colors;
21972 if (!textColor) {
21973 textColor = w.config.chart.foreColor;
21974 }
21975 elLegendText.style.color = textColor;
21976 elLegendText.style.fontSize = parseFloat(w.config.legend.fontSize) + 'px';
21977 elLegendText.style.fontWeight = w.config.legend.fontWeight;
21978 elLegendText.style.fontFamily = fontFamily || w.config.chart.fontFamily;
21979 Graphics.setAttrs(elLegendText, {
21980 rel: i + 1,
21981 i: i,
21982 'data:default-text': encodeURIComponent(text),
21983 'data:collapsed': collapsedSeries || ancillaryCollapsedSeries
21984 });
21985 elLegend.appendChild(elMarker);
21986 elLegend.appendChild(elLegendText);
21987 var coreUtils = new CoreUtils(_this.ctx);
21988 if (!w.config.legend.showForZeroSeries) {
21989 var total = coreUtils.getSeriesTotalByIndex(i);
21990 if (total === 0 && coreUtils.seriesHaveSameValues(i) && !coreUtils.isSeriesNull(i) && w.globals.collapsedSeriesIndices.indexOf(i) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(i) === -1) {
21991 elLegend.classList.add('apexcharts-hidden-zero-series');
21992 }
21993 }
21994 if (!w.config.legend.showForNullSeries) {
21995 if (coreUtils.isSeriesNull(i) && w.globals.collapsedSeriesIndices.indexOf(i) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(i) === -1) {
21996 elLegend.classList.add('apexcharts-hidden-null-series');
21997 }
21998 }
21999 if (legendGroups.length) {
22000 w.globals.seriesGroups.forEach(function (group, gi) {
22001 var _w$config$series$i;
22002 if (group.includes((_w$config$series$i = w.config.series[i]) === null || _w$config$series$i === void 0 ? void 0 : _w$config$series$i.name)) {
22003 w.globals.dom.elLegendWrap.appendChild(legendGroups[gi]);
22004 legendGroups[gi].appendChild(elLegend);
22005 }
22006 });
22007 } else {
22008 w.globals.dom.elLegendWrap.appendChild(elLegend);
22009 }
22010 w.globals.dom.elLegendWrap.classList.add("apexcharts-align-".concat(w.config.legend.horizontalAlign));
22011 w.globals.dom.elLegendWrap.classList.add('apx-legend-position-' + w.config.legend.position);
22012 elLegend.classList.add('apexcharts-legend-series');
22013 elLegend.style.margin = "".concat(w.config.legend.itemMargin.vertical, "px ").concat(w.config.legend.itemMargin.horizontal, "px");
22014 w.globals.dom.elLegendWrap.style.width = w.config.legend.width ? w.config.legend.width + 'px' : '';
22015 w.globals.dom.elLegendWrap.style.height = w.config.legend.height ? w.config.legend.height + 'px' : '';
22016 Graphics.setAttrs(elLegend, {
22017 rel: i + 1,
22018 seriesName: Utils$1.escapeString(legendNames[i]),
22019 'data:collapsed': collapsedSeries || ancillaryCollapsedSeries
22020 });
22021 if (collapsedSeries || ancillaryCollapsedSeries) {
22022 elLegend.classList.add('apexcharts-inactive-legend');
22023 }
22024 if (!w.config.legend.onItemClick.toggleDataSeries) {
22025 elLegend.classList.add('apexcharts-no-click');
22026 }
22027 };
22028 for (var i = isLegendInversed ? legendNames.length - 1 : 0; isLegendInversed ? i >= 0 : i <= legendNames.length - 1; isLegendInversed ? i-- : i++) {
22029 _loop(i);
22030 }
22031 w.globals.dom.elWrap.addEventListener('click', me.onLegendClick, true);
22032 if (w.config.legend.onItemHover.highlightDataSeries && w.config.legend.customLegendItems.length === 0) {
22033 w.globals.dom.elWrap.addEventListener('mousemove', me.onLegendHovered, true);
22034 w.globals.dom.elWrap.addEventListener('mouseout', me.onLegendHovered, true);
22035 }
22036 }
22037 }, {
22038 key: "setLegendWrapXY",
22039 value: function setLegendWrapXY(offsetX, offsetY) {
22040 var w = this.w;
22041 var elLegendWrap = w.globals.dom.elLegendWrap;
22042 var legendHeight = elLegendWrap.clientHeight;
22043 var x = 0;
22044 var y = 0;
22045 if (w.config.legend.position === 'bottom') {
22046 y = w.globals.svgHeight - Math.min(legendHeight, w.globals.svgHeight / 2) - 5;
22047 } else if (w.config.legend.position === 'top') {
22048 var dim = new Dimensions(this.ctx);
22049 var titleH = dim.dimHelpers.getTitleSubtitleCoords('title').height;
22050 var subtitleH = dim.dimHelpers.getTitleSubtitleCoords('subtitle').height;
22051 y = (titleH > 0 ? titleH - 10 : 0) + (subtitleH > 0 ? subtitleH - 10 : 0);
22052 }
22053 elLegendWrap.style.position = 'absolute';
22054 x = x + offsetX + w.config.legend.offsetX;
22055 y = y + offsetY + w.config.legend.offsetY;
22056 elLegendWrap.style.left = x + 'px';
22057 elLegendWrap.style.top = y + 'px';
22058 if (w.config.legend.position === 'right') {
22059 elLegendWrap.style.left = 'auto';
22060 elLegendWrap.style.right = 25 + w.config.legend.offsetX + 'px';
22061 }
22062 var fixedHeigthWidth = ['width', 'height'];
22063 fixedHeigthWidth.forEach(function (hw) {
22064 if (elLegendWrap.style[hw]) {
22065 elLegendWrap.style[hw] = parseInt(w.config.legend[hw], 10) + 'px';
22066 }
22067 });
22068 }
22069 }, {
22070 key: "legendAlignHorizontal",
22071 value: function legendAlignHorizontal() {
22072 var w = this.w;
22073 var elLegendWrap = w.globals.dom.elLegendWrap;
22074 elLegendWrap.style.right = 0;
22075 var dimensions = new Dimensions(this.ctx);
22076 var titleRect = dimensions.dimHelpers.getTitleSubtitleCoords('title');
22077 var subtitleRect = dimensions.dimHelpers.getTitleSubtitleCoords('subtitle');
22078 var offsetX = 20;
22079 var offsetY = 0;
22080 if (w.config.legend.position === 'top') {
22081 offsetY = titleRect.height + subtitleRect.height + w.config.title.margin + w.config.subtitle.margin - 10;
22082 }
22083 this.setLegendWrapXY(offsetX, offsetY);
22084 }
22085 }, {
22086 key: "legendAlignVertical",
22087 value: function legendAlignVertical() {
22088 var w = this.w;
22089 var lRect = this.legendHelpers.getLegendDimensions();
22090 var offsetY = 20;
22091 var offsetX = 0;
22092 if (w.config.legend.position === 'left') {
22093 offsetX = 20;
22094 }
22095 if (w.config.legend.position === 'right') {
22096 offsetX = w.globals.svgWidth - lRect.clww - 10;
22097 }
22098 this.setLegendWrapXY(offsetX, offsetY);
22099 }
22100 }, {
22101 key: "onLegendHovered",
22102 value: function onLegendHovered(e) {
22103 var w = this.w;
22104 var hoverOverLegend = e.target.classList.contains('apexcharts-legend-series') || e.target.classList.contains('apexcharts-legend-text') || e.target.classList.contains('apexcharts-legend-marker');
22105 if (w.config.chart.type !== 'heatmap' && !this.isBarsDistributed) {
22106 if (!e.target.classList.contains('apexcharts-inactive-legend') && hoverOverLegend) {
22107 var series = new Series(this.ctx);
22108 series.toggleSeriesOnHover(e, e.target);
22109 }
22110 } else {
22111 // for heatmap handling
22112 if (hoverOverLegend) {
22113 var seriesCnt = parseInt(e.target.getAttribute('rel'), 10) - 1;
22114 this.ctx.events.fireEvent('legendHover', [this.ctx, seriesCnt, this.w]);
22115 var _series = new Series(this.ctx);
22116 _series.highlightRangeInSeries(e, e.target);
22117 }
22118 }
22119 }
22120 }, {
22121 key: "onLegendClick",
22122 value: function onLegendClick(e) {
22123 var w = this.w;
22124 if (w.config.legend.customLegendItems.length) return;
22125 if (e.target.classList.contains('apexcharts-legend-series') || e.target.classList.contains('apexcharts-legend-text') || e.target.classList.contains('apexcharts-legend-marker')) {
22126 var seriesCnt = parseInt(e.target.getAttribute('rel'), 10) - 1;
22127 var isHidden = e.target.getAttribute('data:collapsed') === 'true';
22128 var legendClick = this.w.config.chart.events.legendClick;
22129 if (typeof legendClick === 'function') {
22130 legendClick(this.ctx, seriesCnt, this.w);
22131 }
22132 this.ctx.events.fireEvent('legendClick', [this.ctx, seriesCnt, this.w]);
22133 var markerClick = this.w.config.legend.markers.onClick;
22134 if (typeof markerClick === 'function' && e.target.classList.contains('apexcharts-legend-marker')) {
22135 markerClick(this.ctx, seriesCnt, this.w);
22136 this.ctx.events.fireEvent('legendMarkerClick', [this.ctx, seriesCnt, this.w]);
22137 }
22138
22139 // for now - just prevent click on heatmap legend - and allow hover only
22140 var clickAllowed = w.config.chart.type !== 'treemap' && w.config.chart.type !== 'heatmap' && !this.isBarsDistributed;
22141 if (clickAllowed && w.config.legend.onItemClick.toggleDataSeries) {
22142 this.legendHelpers.toggleDataSeries(seriesCnt, isHidden);
22143 }
22144 }
22145 }
22146 }]);
22147 return Legend;
22148 }();
22149
22150 var icoPan = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" fill=\"#000000\" height=\"24\" viewBox=\"0 0 24 24\" width=\"24\">\n <defs>\n <path d=\"M0 0h24v24H0z\" id=\"a\"/>\n </defs>\n <clipPath id=\"b\">\n <use overflow=\"visible\" xlink:href=\"#a\"/>\n </clipPath>\n <path clip-path=\"url(#b)\" d=\"M23 5.5V20c0 2.2-1.8 4-4 4h-7.3c-1.08 0-2.1-.43-2.85-1.19L1 14.83s1.26-1.23 1.3-1.25c.22-.19.49-.29.79-.29.22 0 .42.06.6.16.04.01 4.31 2.46 4.31 2.46V4c0-.83.67-1.5 1.5-1.5S11 3.17 11 4v7h1V1.5c0-.83.67-1.5 1.5-1.5S15 .67 15 1.5V11h1V2.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5V11h1V5.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5z\"/>\n</svg>";
22151
22152 var icoZoom = "<svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"#000000\" height=\"24\" viewBox=\"0 0 24 24\" width=\"24\">\n <path d=\"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z\"/>\n <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n <path d=\"M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z\"/>\n</svg>";
22153
22154 var icoReset = "<svg fill=\"#000000\" height=\"24\" viewBox=\"0 0 24 24\" width=\"24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z\"/>\n <path d=\"M0 0h24v24H0z\" fill=\"none\"/>\n</svg>";
22155
22156 var icoZoomIn = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\">\n <path d=\"M0 0h24v24H0z\" fill=\"none\"/>\n <path d=\"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4V7zm-1-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z\"/>\n</svg>\n";
22157
22158 var icoZoomOut = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\">\n <path d=\"M0 0h24v24H0z\" fill=\"none\"/>\n <path d=\"M7 11v2h10v-2H7zm5-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z\"/>\n</svg>\n";
22159
22160 var icoSelect = "<svg fill=\"#6E8192\" height=\"24\" viewBox=\"0 0 24 24\" width=\"24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M0 0h24v24H0z\" fill=\"none\"/>\n <path d=\"M3 5h2V3c-1.1 0-2 .9-2 2zm0 8h2v-2H3v2zm4 8h2v-2H7v2zM3 9h2V7H3v2zm10-6h-2v2h2V3zm6 0v2h2c0-1.1-.9-2-2-2zM5 21v-2H3c0 1.1.9 2 2 2zm-2-4h2v-2H3v2zM9 3H7v2h2V3zm2 18h2v-2h-2v2zm8-8h2v-2h-2v2zm0 8c1.1 0 2-.9 2-2h-2v2zm0-12h2V7h-2v2zm0 8h2v-2h-2v2zm-4 4h2v-2h-2v2zm0-16h2V3h-2v2z\"/>\n</svg>";
22161
22162 var icoMenu = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z\"/></svg>";
22163
22164 /**
22165 * ApexCharts Toolbar Class for creating toolbar in axis based charts.
22166 *
22167 * @module Toolbar
22168 **/
22169 var Toolbar = /*#__PURE__*/function () {
22170 function Toolbar(ctx) {
22171 _classCallCheck(this, Toolbar);
22172 this.ctx = ctx;
22173 this.w = ctx.w;
22174 var w = this.w;
22175 this.ev = this.w.config.chart.events;
22176 this.selectedClass = 'apexcharts-selected';
22177 this.localeValues = this.w.globals.locale.toolbar;
22178 this.minX = w.globals.minX;
22179 this.maxX = w.globals.maxX;
22180 }
22181 _createClass(Toolbar, [{
22182 key: "createToolbar",
22183 value: function createToolbar() {
22184 var _this = this;
22185 var w = this.w;
22186 var createDiv = function createDiv() {
22187 return document.createElement('div');
22188 };
22189 var elToolbarWrap = createDiv();
22190 elToolbarWrap.setAttribute('class', 'apexcharts-toolbar');
22191 elToolbarWrap.style.top = w.config.chart.toolbar.offsetY + 'px';
22192 elToolbarWrap.style.right = -w.config.chart.toolbar.offsetX + 3 + 'px';
22193 w.globals.dom.elWrap.appendChild(elToolbarWrap);
22194 this.elZoom = createDiv();
22195 this.elZoomIn = createDiv();
22196 this.elZoomOut = createDiv();
22197 this.elPan = createDiv();
22198 this.elSelection = createDiv();
22199 this.elZoomReset = createDiv();
22200 this.elMenuIcon = createDiv();
22201 this.elMenu = createDiv();
22202 this.elCustomIcons = [];
22203 this.t = w.config.chart.toolbar.tools;
22204 if (Array.isArray(this.t.customIcons)) {
22205 for (var i = 0; i < this.t.customIcons.length; i++) {
22206 this.elCustomIcons.push(createDiv());
22207 }
22208 }
22209 var toolbarControls = [];
22210 var appendZoomControl = function appendZoomControl(type, el, ico) {
22211 var tool = type.toLowerCase();
22212 if (_this.t[tool] && w.config.chart.zoom.enabled) {
22213 toolbarControls.push({
22214 el: el,
22215 icon: typeof _this.t[tool] === 'string' ? _this.t[tool] : ico,
22216 title: _this.localeValues[type],
22217 class: "apexcharts-".concat(tool, "-icon")
22218 });
22219 }
22220 };
22221 appendZoomControl('zoomIn', this.elZoomIn, icoZoomIn);
22222 appendZoomControl('zoomOut', this.elZoomOut, icoZoomOut);
22223 var zoomSelectionCtrls = function zoomSelectionCtrls(z) {
22224 if (_this.t[z] && w.config.chart[z].enabled) {
22225 toolbarControls.push({
22226 el: z === 'zoom' ? _this.elZoom : _this.elSelection,
22227 icon: typeof _this.t[z] === 'string' ? _this.t[z] : z === 'zoom' ? icoZoom : icoSelect,
22228 title: _this.localeValues[z === 'zoom' ? 'selectionZoom' : 'selection'],
22229 class: w.globals.isTouchDevice ? 'apexcharts-element-hidden' : "apexcharts-".concat(z, "-icon")
22230 });
22231 }
22232 };
22233 zoomSelectionCtrls('zoom');
22234 zoomSelectionCtrls('selection');
22235 if (this.t.pan && w.config.chart.zoom.enabled) {
22236 toolbarControls.push({
22237 el: this.elPan,
22238 icon: typeof this.t.pan === 'string' ? this.t.pan : icoPan,
22239 title: this.localeValues.pan,
22240 class: w.globals.isTouchDevice ? 'apexcharts-element-hidden' : 'apexcharts-pan-icon'
22241 });
22242 }
22243 appendZoomControl('reset', this.elZoomReset, icoReset);
22244 if (this.t.download) {
22245 toolbarControls.push({
22246 el: this.elMenuIcon,
22247 icon: typeof this.t.download === 'string' ? this.t.download : icoMenu,
22248 title: this.localeValues.menu,
22249 class: 'apexcharts-menu-icon'
22250 });
22251 }
22252 for (var _i = 0; _i < this.elCustomIcons.length; _i++) {
22253 toolbarControls.push({
22254 el: this.elCustomIcons[_i],
22255 icon: this.t.customIcons[_i].icon,
22256 title: this.t.customIcons[_i].title,
22257 index: this.t.customIcons[_i].index,
22258 class: 'apexcharts-toolbar-custom-icon ' + this.t.customIcons[_i].class
22259 });
22260 }
22261 toolbarControls.forEach(function (t, index) {
22262 if (t.index) {
22263 Utils$1.moveIndexInArray(toolbarControls, index, t.index);
22264 }
22265 });
22266 for (var _i2 = 0; _i2 < toolbarControls.length; _i2++) {
22267 Graphics.setAttrs(toolbarControls[_i2].el, {
22268 class: toolbarControls[_i2].class,
22269 title: toolbarControls[_i2].title
22270 });
22271 toolbarControls[_i2].el.innerHTML = toolbarControls[_i2].icon;
22272 elToolbarWrap.appendChild(toolbarControls[_i2].el);
22273 }
22274 this._createHamburgerMenu(elToolbarWrap);
22275 if (w.globals.zoomEnabled) {
22276 this.elZoom.classList.add(this.selectedClass);
22277 } else if (w.globals.panEnabled) {
22278 this.elPan.classList.add(this.selectedClass);
22279 } else if (w.globals.selectionEnabled) {
22280 this.elSelection.classList.add(this.selectedClass);
22281 }
22282 this.addToolbarEventListeners();
22283 }
22284 }, {
22285 key: "_createHamburgerMenu",
22286 value: function _createHamburgerMenu(parent) {
22287 this.elMenuItems = [];
22288 parent.appendChild(this.elMenu);
22289 Graphics.setAttrs(this.elMenu, {
22290 class: 'apexcharts-menu'
22291 });
22292 var menuItems = [{
22293 name: 'exportSVG',
22294 title: this.localeValues.exportToSVG
22295 }, {
22296 name: 'exportPNG',
22297 title: this.localeValues.exportToPNG
22298 }, {
22299 name: 'exportCSV',
22300 title: this.localeValues.exportToCSV
22301 }];
22302 for (var i = 0; i < menuItems.length; i++) {
22303 this.elMenuItems.push(document.createElement('div'));
22304 this.elMenuItems[i].innerHTML = menuItems[i].title;
22305 Graphics.setAttrs(this.elMenuItems[i], {
22306 class: "apexcharts-menu-item ".concat(menuItems[i].name),
22307 title: menuItems[i].title
22308 });
22309 this.elMenu.appendChild(this.elMenuItems[i]);
22310 }
22311 }
22312 }, {
22313 key: "addToolbarEventListeners",
22314 value: function addToolbarEventListeners() {
22315 var _this2 = this;
22316 this.elZoomReset.addEventListener('click', this.handleZoomReset.bind(this));
22317 this.elSelection.addEventListener('click', this.toggleZoomSelection.bind(this, 'selection'));
22318 this.elZoom.addEventListener('click', this.toggleZoomSelection.bind(this, 'zoom'));
22319 this.elZoomIn.addEventListener('click', this.handleZoomIn.bind(this));
22320 this.elZoomOut.addEventListener('click', this.handleZoomOut.bind(this));
22321 this.elPan.addEventListener('click', this.togglePanning.bind(this));
22322 this.elMenuIcon.addEventListener('click', this.toggleMenu.bind(this));
22323 this.elMenuItems.forEach(function (m) {
22324 if (m.classList.contains('exportSVG')) {
22325 m.addEventListener('click', _this2.handleDownload.bind(_this2, 'svg'));
22326 } else if (m.classList.contains('exportPNG')) {
22327 m.addEventListener('click', _this2.handleDownload.bind(_this2, 'png'));
22328 } else if (m.classList.contains('exportCSV')) {
22329 m.addEventListener('click', _this2.handleDownload.bind(_this2, 'csv'));
22330 }
22331 });
22332 for (var i = 0; i < this.t.customIcons.length; i++) {
22333 this.elCustomIcons[i].addEventListener('click', this.t.customIcons[i].click.bind(this, this.ctx, this.ctx.w));
22334 }
22335 }
22336 }, {
22337 key: "toggleZoomSelection",
22338 value: function toggleZoomSelection(type) {
22339 var charts = this.ctx.getSyncedCharts();
22340 charts.forEach(function (ch) {
22341 ch.ctx.toolbar.toggleOtherControls();
22342 var el = type === 'selection' ? ch.ctx.toolbar.elSelection : ch.ctx.toolbar.elZoom;
22343 var enabledType = type === 'selection' ? 'selectionEnabled' : 'zoomEnabled';
22344 ch.w.globals[enabledType] = !ch.w.globals[enabledType];
22345 if (!el.classList.contains(ch.ctx.toolbar.selectedClass)) {
22346 el.classList.add(ch.ctx.toolbar.selectedClass);
22347 } else {
22348 el.classList.remove(ch.ctx.toolbar.selectedClass);
22349 }
22350 });
22351 }
22352 }, {
22353 key: "getToolbarIconsReference",
22354 value: function getToolbarIconsReference() {
22355 var w = this.w;
22356 if (!this.elZoom) {
22357 this.elZoom = w.globals.dom.baseEl.querySelector('.apexcharts-zoom-icon');
22358 }
22359 if (!this.elPan) {
22360 this.elPan = w.globals.dom.baseEl.querySelector('.apexcharts-pan-icon');
22361 }
22362 if (!this.elSelection) {
22363 this.elSelection = w.globals.dom.baseEl.querySelector('.apexcharts-selection-icon');
22364 }
22365 }
22366 }, {
22367 key: "enableZoomPanFromToolbar",
22368 value: function enableZoomPanFromToolbar(type) {
22369 this.toggleOtherControls();
22370 type === 'pan' ? this.w.globals.panEnabled = true : this.w.globals.zoomEnabled = true;
22371 var el = type === 'pan' ? this.elPan : this.elZoom;
22372 var el2 = type === 'pan' ? this.elZoom : this.elPan;
22373 if (el) {
22374 el.classList.add(this.selectedClass);
22375 }
22376 if (el2) {
22377 el2.classList.remove(this.selectedClass);
22378 }
22379 }
22380 }, {
22381 key: "togglePanning",
22382 value: function togglePanning() {
22383 var charts = this.ctx.getSyncedCharts();
22384 charts.forEach(function (ch) {
22385 ch.ctx.toolbar.toggleOtherControls();
22386 ch.w.globals.panEnabled = !ch.w.globals.panEnabled;
22387 if (!ch.ctx.toolbar.elPan.classList.contains(ch.ctx.toolbar.selectedClass)) {
22388 ch.ctx.toolbar.elPan.classList.add(ch.ctx.toolbar.selectedClass);
22389 } else {
22390 ch.ctx.toolbar.elPan.classList.remove(ch.ctx.toolbar.selectedClass);
22391 }
22392 });
22393 }
22394 }, {
22395 key: "toggleOtherControls",
22396 value: function toggleOtherControls() {
22397 var _this3 = this;
22398 var w = this.w;
22399 w.globals.panEnabled = false;
22400 w.globals.zoomEnabled = false;
22401 w.globals.selectionEnabled = false;
22402 this.getToolbarIconsReference();
22403 var toggleEls = [this.elPan, this.elSelection, this.elZoom];
22404 toggleEls.forEach(function (el) {
22405 if (el) {
22406 el.classList.remove(_this3.selectedClass);
22407 }
22408 });
22409 }
22410 }, {
22411 key: "handleZoomIn",
22412 value: function handleZoomIn() {
22413 var w = this.w;
22414 if (w.globals.isRangeBar) {
22415 this.minX = w.globals.minY;
22416 this.maxX = w.globals.maxY;
22417 }
22418 var centerX = (this.minX + this.maxX) / 2;
22419 var newMinX = (this.minX + centerX) / 2;
22420 var newMaxX = (this.maxX + centerX) / 2;
22421 var newMinXMaxX = this._getNewMinXMaxX(newMinX, newMaxX);
22422 if (!w.globals.disableZoomIn) {
22423 this.zoomUpdateOptions(newMinXMaxX.minX, newMinXMaxX.maxX);
22424 }
22425 }
22426 }, {
22427 key: "handleZoomOut",
22428 value: function handleZoomOut() {
22429 var w = this.w;
22430 if (w.globals.isRangeBar) {
22431 this.minX = w.globals.minY;
22432 this.maxX = w.globals.maxY;
22433 }
22434
22435 // avoid zooming out beyond 1000 which may result in NaN values being printed on x-axis
22436 if (w.config.xaxis.type === 'datetime' && new Date(this.minX).getUTCFullYear() < 1000) {
22437 return;
22438 }
22439 var centerX = (this.minX + this.maxX) / 2;
22440 var newMinX = this.minX - (centerX - this.minX);
22441 var newMaxX = this.maxX - (centerX - this.maxX);
22442 var newMinXMaxX = this._getNewMinXMaxX(newMinX, newMaxX);
22443 if (!w.globals.disableZoomOut) {
22444 this.zoomUpdateOptions(newMinXMaxX.minX, newMinXMaxX.maxX);
22445 }
22446 }
22447 }, {
22448 key: "_getNewMinXMaxX",
22449 value: function _getNewMinXMaxX(newMinX, newMaxX) {
22450 var shouldFloor = this.w.config.xaxis.convertedCatToNumeric;
22451 return {
22452 minX: shouldFloor ? Math.floor(newMinX) : newMinX,
22453 maxX: shouldFloor ? Math.floor(newMaxX) : newMaxX
22454 };
22455 }
22456 }, {
22457 key: "zoomUpdateOptions",
22458 value: function zoomUpdateOptions(newMinX, newMaxX) {
22459 var w = this.w;
22460 if (newMinX === undefined && newMaxX === undefined) {
22461 this.handleZoomReset();
22462 return;
22463 }
22464 if (w.config.xaxis.convertedCatToNumeric) {
22465 // in category charts, avoid zooming out beyond min and max
22466 if (newMinX < 1) {
22467 newMinX = 1;
22468 newMaxX = w.globals.dataPoints;
22469 }
22470 if (newMaxX - newMinX < 2) {
22471 return;
22472 }
22473 }
22474 var xaxis = {
22475 min: newMinX,
22476 max: newMaxX
22477 };
22478 var beforeZoomRange = this.getBeforeZoomRange(xaxis);
22479 if (beforeZoomRange) {
22480 xaxis = beforeZoomRange.xaxis;
22481 }
22482 var options = {
22483 xaxis: xaxis
22484 };
22485 var yaxis = Utils$1.clone(w.globals.initialConfig.yaxis);
22486 if (!w.config.chart.group) {
22487 // if chart in a group, prevent yaxis update here
22488 // fix issue #650
22489 options.yaxis = yaxis;
22490 }
22491 this.w.globals.zoomed = true;
22492 this.ctx.updateHelpers._updateOptions(options, false, this.w.config.chart.animations.dynamicAnimation.enabled);
22493 this.zoomCallback(xaxis, yaxis);
22494 }
22495 }, {
22496 key: "zoomCallback",
22497 value: function zoomCallback(xaxis, yaxis) {
22498 if (typeof this.ev.zoomed === 'function') {
22499 this.ev.zoomed(this.ctx, {
22500 xaxis: xaxis,
22501 yaxis: yaxis
22502 });
22503 this.ctx.events.fireEvent('zoomed', {
22504 xaxis: xaxis,
22505 yaxis: yaxis
22506 });
22507 }
22508 }
22509 }, {
22510 key: "getBeforeZoomRange",
22511 value: function getBeforeZoomRange(xaxis, yaxis) {
22512 var newRange = null;
22513 if (typeof this.ev.beforeZoom === 'function') {
22514 newRange = this.ev.beforeZoom(this, {
22515 xaxis: xaxis,
22516 yaxis: yaxis
22517 });
22518 }
22519 return newRange;
22520 }
22521 }, {
22522 key: "toggleMenu",
22523 value: function toggleMenu() {
22524 var _this4 = this;
22525 window.setTimeout(function () {
22526 if (_this4.elMenu.classList.contains('apexcharts-menu-open')) {
22527 _this4.elMenu.classList.remove('apexcharts-menu-open');
22528 } else {
22529 _this4.elMenu.classList.add('apexcharts-menu-open');
22530 }
22531 }, 0);
22532 }
22533 }, {
22534 key: "handleDownload",
22535 value: function handleDownload(type) {
22536 var w = this.w;
22537 var exprt = new Exports(this.ctx);
22538 switch (type) {
22539 case 'svg':
22540 exprt.exportToSVG(this.ctx);
22541 break;
22542 case 'png':
22543 exprt.exportToPng(this.ctx);
22544 break;
22545 case 'csv':
22546 exprt.exportToCSV({
22547 series: w.config.series,
22548 columnDelimiter: w.config.chart.toolbar.export.csv.columnDelimiter
22549 });
22550 break;
22551 }
22552 }
22553 }, {
22554 key: "handleZoomReset",
22555 value: function handleZoomReset(e) {
22556 var charts = this.ctx.getSyncedCharts();
22557 charts.forEach(function (ch) {
22558 var w = ch.w;
22559
22560 // forget lastXAxis min/max as reset button isn't resetting the x-axis completely if zoomX is called before
22561 w.globals.lastXAxis.min = w.globals.initialConfig.xaxis.min;
22562 w.globals.lastXAxis.max = w.globals.initialConfig.xaxis.max;
22563 ch.updateHelpers.revertDefaultAxisMinMax();
22564 if (typeof w.config.chart.events.beforeResetZoom === 'function') {
22565 // here, user get an option to control xaxis and yaxis when resetZoom is called
22566 // at this point, whatever is returned from w.config.chart.events.beforeResetZoom
22567 // is set as the new xaxis/yaxis min/max
22568 var resetZoomRange = w.config.chart.events.beforeResetZoom(ch, w);
22569 if (resetZoomRange) {
22570 ch.updateHelpers.revertDefaultAxisMinMax(resetZoomRange);
22571 }
22572 }
22573 if (typeof w.config.chart.events.zoomed === 'function') {
22574 ch.ctx.toolbar.zoomCallback({
22575 min: w.config.xaxis.min,
22576 max: w.config.xaxis.max
22577 });
22578 }
22579 w.globals.zoomed = false;
22580
22581 // if user has some series collapsed before hitting zoom reset button,
22582 // those series should stay collapsed
22583 var series = ch.ctx.series.emptyCollapsedSeries(Utils$1.clone(w.globals.initialSeries));
22584 ch.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
22585 });
22586 }
22587 }, {
22588 key: "destroy",
22589 value: function destroy() {
22590 this.elZoom = null;
22591 this.elZoomIn = null;
22592 this.elZoomOut = null;
22593 this.elPan = null;
22594 this.elSelection = null;
22595 this.elZoomReset = null;
22596 this.elMenuIcon = null;
22597 }
22598 }]);
22599 return Toolbar;
22600 }();
22601
22602 /**
22603 * ApexCharts Zoom Class for handling zooming and panning on axes based charts.
22604 *
22605 * @module ZoomPanSelection
22606 **/
22607 var ZoomPanSelection = /*#__PURE__*/function (_Toolbar) {
22608 _inherits(ZoomPanSelection, _Toolbar);
22609 var _super = _createSuper(ZoomPanSelection);
22610 function ZoomPanSelection(ctx) {
22611 var _this;
22612 _classCallCheck(this, ZoomPanSelection);
22613 _this = _super.call(this, ctx);
22614 _this.ctx = ctx;
22615 _this.w = ctx.w;
22616 _this.dragged = false;
22617 _this.graphics = new Graphics(_this.ctx);
22618 _this.eventList = ['mousedown', 'mouseleave', 'mousemove', 'touchstart', 'touchmove', 'mouseup', 'touchend', 'wheel'];
22619 _this.clientX = 0;
22620 _this.clientY = 0;
22621 _this.startX = 0;
22622 _this.endX = 0;
22623 _this.dragX = 0;
22624 _this.startY = 0;
22625 _this.endY = 0;
22626 _this.dragY = 0;
22627 _this.moveDirection = 'none';
22628 _this.debounceTimer = null;
22629 _this.debounceDelay = 100;
22630 _this.wheelDelay = 400;
22631 return _this;
22632 }
22633 _createClass(ZoomPanSelection, [{
22634 key: "init",
22635 value: function init(_ref) {
22636 var _this2 = this;
22637 var xyRatios = _ref.xyRatios;
22638 var w = this.w;
22639 var me = this;
22640 this.xyRatios = xyRatios;
22641 this.zoomRect = this.graphics.drawRect(0, 0, 0, 0);
22642 this.selectionRect = this.graphics.drawRect(0, 0, 0, 0);
22643 this.gridRect = w.globals.dom.baseEl.querySelector('.apexcharts-grid');
22644 this.constraints = new Box(0, 0, w.globals.gridWidth, w.globals.gridHeight);
22645 this.zoomRect.node.classList.add('apexcharts-zoom-rect');
22646 this.selectionRect.node.classList.add('apexcharts-selection-rect');
22647 w.globals.dom.Paper.add(this.zoomRect);
22648 w.globals.dom.Paper.add(this.selectionRect);
22649 if (w.config.chart.selection.type === 'x') {
22650 this.slDraggableRect = this.selectionRect.draggable({
22651 minX: 0,
22652 minY: 0,
22653 maxX: w.globals.gridWidth,
22654 maxY: w.globals.gridHeight
22655 }).on('dragmove.namespace', this.selectionDragging.bind(this, 'dragging'));
22656 } else if (w.config.chart.selection.type === 'y') {
22657 this.slDraggableRect = this.selectionRect.draggable({
22658 minX: 0,
22659 maxX: w.globals.gridWidth
22660 }).on('dragmove.namespace', this.selectionDragging.bind(this, 'dragging'));
22661 } else {
22662 this.slDraggableRect = this.selectionRect.draggable().on('dragmove.namespace', this.selectionDragging.bind(this, 'dragging'));
22663 }
22664 this.preselectedSelection();
22665 this.hoverArea = w.globals.dom.baseEl.querySelector("".concat(w.globals.chartClass, " .apexcharts-svg"));
22666 this.hoverArea.classList.add('apexcharts-zoomable');
22667 this.eventList.forEach(function (event) {
22668 _this2.hoverArea.addEventListener(event, me.svgMouseEvents.bind(me, xyRatios), {
22669 capture: false,
22670 passive: true
22671 });
22672 });
22673 if (w.config.chart.zoom.enabled && w.config.chart.zoom.allowMouseWheelZoom) {
22674 this.hoverArea.addEventListener('wheel', me.mouseWheelEvent.bind(me), {
22675 capture: false,
22676 passive: false
22677 });
22678 }
22679 }
22680
22681 // remove the event listeners which were previously added on hover area
22682 }, {
22683 key: "destroy",
22684 value: function destroy() {
22685 if (this.slDraggableRect) {
22686 this.slDraggableRect.draggable(false);
22687 this.slDraggableRect.off();
22688 this.selectionRect.off();
22689 }
22690 this.selectionRect = null;
22691 this.zoomRect = null;
22692 this.gridRect = null;
22693 }
22694 }, {
22695 key: "svgMouseEvents",
22696 value: function svgMouseEvents(xyRatios, e) {
22697 var w = this.w;
22698 var toolbar = this.ctx.toolbar;
22699 var zoomtype = w.globals.zoomEnabled ? w.config.chart.zoom.type : w.config.chart.selection.type;
22700 var autoSelected = w.config.chart.toolbar.autoSelected;
22701 if (e.shiftKey) {
22702 this.shiftWasPressed = true;
22703 toolbar.enableZoomPanFromToolbar(autoSelected === 'pan' ? 'zoom' : 'pan');
22704 } else {
22705 if (this.shiftWasPressed) {
22706 toolbar.enableZoomPanFromToolbar(autoSelected);
22707 this.shiftWasPressed = false;
22708 }
22709 }
22710 if (!e.target) return;
22711 var tc = e.target.classList;
22712 var pc;
22713 if (e.target.parentNode && e.target.parentNode !== null) {
22714 pc = e.target.parentNode.classList;
22715 }
22716 var falsePositives = tc.contains('apexcharts-legend-marker') || tc.contains('apexcharts-legend-text') || pc && pc.contains('apexcharts-toolbar');
22717 if (falsePositives) return;
22718 this.clientX = e.type === 'touchmove' || e.type === 'touchstart' ? e.touches[0].clientX : e.type === 'touchend' ? e.changedTouches[0].clientX : e.clientX;
22719 this.clientY = e.type === 'touchmove' || e.type === 'touchstart' ? e.touches[0].clientY : e.type === 'touchend' ? e.changedTouches[0].clientY : e.clientY;
22720 if (e.type === 'mousedown' && e.which === 1 || e.type === 'touchstart') {
22721 var gridRectDim = this.gridRect.getBoundingClientRect();
22722 this.startX = this.clientX - gridRectDim.left - w.globals.barPadForNumericAxis;
22723 this.startY = this.clientY - gridRectDim.top;
22724 this.dragged = false;
22725 this.w.globals.mousedown = true;
22726 }
22727 if (e.type === 'mousemove' && e.which === 1 || e.type === 'touchmove') {
22728 this.dragged = true;
22729 if (w.globals.panEnabled) {
22730 w.globals.selection = null;
22731 if (this.w.globals.mousedown) {
22732 this.panDragging({
22733 context: this,
22734 zoomtype: zoomtype,
22735 xyRatios: xyRatios
22736 });
22737 }
22738 } else {
22739 if (this.w.globals.mousedown && w.globals.zoomEnabled || this.w.globals.mousedown && w.globals.selectionEnabled) {
22740 this.selection = this.selectionDrawing({
22741 context: this,
22742 zoomtype: zoomtype
22743 });
22744 }
22745 }
22746 }
22747 if (e.type === 'mouseup' || e.type === 'touchend' || e.type === 'mouseleave') {
22748 this.handleMouseUp({
22749 zoomtype: zoomtype
22750 });
22751 }
22752 this.makeSelectionRectDraggable();
22753 }
22754 }, {
22755 key: "handleMouseUp",
22756 value: function handleMouseUp(_ref2) {
22757 var _this$gridRect;
22758 var zoomtype = _ref2.zoomtype,
22759 isResized = _ref2.isResized;
22760 var w = this.w;
22761 // we will be calling getBoundingClientRect on each mousedown/mousemove/mouseup
22762 var gridRectDim = (_this$gridRect = this.gridRect) === null || _this$gridRect === void 0 ? void 0 : _this$gridRect.getBoundingClientRect();
22763 if (gridRectDim && (this.w.globals.mousedown || isResized)) {
22764 // user released the drag, now do all the calculations
22765 this.endX = this.clientX - gridRectDim.left - w.globals.barPadForNumericAxis;
22766 this.endY = this.clientY - gridRectDim.top;
22767 this.dragX = Math.abs(this.endX - this.startX);
22768 this.dragY = Math.abs(this.endY - this.startY);
22769 if (w.globals.zoomEnabled || w.globals.selectionEnabled) {
22770 this.selectionDrawn({
22771 context: this,
22772 zoomtype: zoomtype
22773 });
22774 }
22775
22776 // if (w.globals.panEnabled && w.config.xaxis.convertedCatToNumeric) {
22777 // this.delayedPanScrolled()
22778 // }
22779 }
22780 if (w.globals.zoomEnabled) {
22781 this.hideSelectionRect(this.selectionRect);
22782 }
22783 this.dragged = false;
22784 this.w.globals.mousedown = false;
22785 }
22786 }, {
22787 key: "mouseWheelEvent",
22788 value: function mouseWheelEvent(e) {
22789 var _this3 = this;
22790 var w = this.w;
22791 e.preventDefault();
22792 var now = Date.now();
22793
22794 // Execute immediately if it's the first action or enough time has passed
22795 if (now - w.globals.lastWheelExecution > this.wheelDelay) {
22796 this.executeMouseWheelZoom(e);
22797 w.globals.lastWheelExecution = now;
22798 }
22799 if (this.debounceTimer) clearTimeout(this.debounceTimer);
22800 this.debounceTimer = setTimeout(function () {
22801 if (now - w.globals.lastWheelExecution > _this3.wheelDelay) {
22802 _this3.executeMouseWheelZoom(e);
22803 w.globals.lastWheelExecution = now;
22804 }
22805 }, this.debounceDelay);
22806 }
22807 }, {
22808 key: "executeMouseWheelZoom",
22809 value: function executeMouseWheelZoom(e) {
22810 var _this$gridRect2;
22811 var w = this.w;
22812 this.minX = w.globals.isRangeBar ? w.globals.minY : w.globals.minX;
22813 this.maxX = w.globals.isRangeBar ? w.globals.maxY : w.globals.maxX;
22814
22815 // Calculate the relative position of the mouse on the chart
22816 var gridRectDim = (_this$gridRect2 = this.gridRect) === null || _this$gridRect2 === void 0 ? void 0 : _this$gridRect2.getBoundingClientRect();
22817 if (!gridRectDim) return;
22818 var mouseX = (e.clientX - gridRectDim.left) / gridRectDim.width;
22819 var currentMinX = this.minX;
22820 var currentMaxX = this.maxX;
22821 var totalX = currentMaxX - currentMinX;
22822
22823 // Determine zoom factor
22824 var zoomFactorIn = 0.5;
22825 var zoomFactorOut = 1.5;
22826 var zoomRange;
22827 var newMinX, newMaxX;
22828 if (e.deltaY < 0) {
22829 // Zoom In
22830 zoomRange = zoomFactorIn * totalX;
22831 var midPoint = currentMinX + mouseX * totalX;
22832 newMinX = midPoint - zoomRange / 2;
22833 newMaxX = midPoint + zoomRange / 2;
22834 } else {
22835 // Zoom Out
22836 zoomRange = zoomFactorOut * totalX;
22837 newMinX = currentMinX - zoomRange / 2;
22838 newMaxX = currentMaxX + zoomRange / 2;
22839 }
22840
22841 // Constrain within original chart bounds
22842 if (!w.globals.isRangeBar) {
22843 newMinX = Math.max(newMinX, w.globals.initialMinX);
22844 newMaxX = Math.min(newMaxX, w.globals.initialMaxX);
22845
22846 // Ensure minimum range
22847 var minRange = (w.globals.initialMaxX - w.globals.initialMinX) * 0.01;
22848 if (newMaxX - newMinX < minRange) {
22849 var _midPoint = (newMinX + newMaxX) / 2;
22850 newMinX = _midPoint - minRange / 2;
22851 newMaxX = _midPoint + minRange / 2;
22852 }
22853 }
22854 var newMinXMaxX = this._getNewMinXMaxX(newMinX, newMaxX);
22855
22856 // Apply zoom if valid
22857 if (!isNaN(newMinXMaxX.minX) && !isNaN(newMinXMaxX.maxX)) {
22858 this.zoomUpdateOptions(newMinXMaxX.minX, newMinXMaxX.maxX);
22859 }
22860 }
22861 }, {
22862 key: "makeSelectionRectDraggable",
22863 value: function makeSelectionRectDraggable() {
22864 var _this4 = this;
22865 var w = this.w;
22866 if (!this.selectionRect) return;
22867 var rectDim = this.selectionRect.node.getBoundingClientRect();
22868 if (rectDim.width > 0 && rectDim.height > 0) {
22869 this.selectionRect.select(false).resize(false);
22870 this.selectionRect.select({
22871 createRot: function createRot() {},
22872 updateRot: function updateRot() {},
22873 createHandle: function createHandle(group, p, index, pointArr, handleName) {
22874 if (handleName === 'l' || handleName === 'r') return group.circle(8).css({
22875 'stroke-width': 1,
22876 stroke: '#333',
22877 fill: '#fff'
22878 });
22879 return group.circle(0);
22880 },
22881 updateHandle: function updateHandle(group, p) {
22882 return group.center(p[0], p[1]);
22883 }
22884 }).resize().on('resize', function () {
22885 var zoomtype = w.globals.zoomEnabled ? w.config.chart.zoom.type : w.config.chart.selection.type;
22886 _this4.handleMouseUp({
22887 zoomtype: zoomtype,
22888 isResized: true
22889 });
22890 });
22891 }
22892 }
22893 }, {
22894 key: "preselectedSelection",
22895 value: function preselectedSelection() {
22896 var w = this.w;
22897 var xyRatios = this.xyRatios;
22898 if (!w.globals.zoomEnabled) {
22899 if (typeof w.globals.selection !== 'undefined' && w.globals.selection !== null) {
22900 this.drawSelectionRect(_objectSpread2(_objectSpread2({}, w.globals.selection), {}, {
22901 translateX: w.globals.translateX,
22902 translateY: w.globals.translateY
22903 }));
22904 } else {
22905 if (w.config.chart.selection.xaxis.min !== undefined && w.config.chart.selection.xaxis.max !== undefined) {
22906 var x = (w.config.chart.selection.xaxis.min - w.globals.minX) / xyRatios.xRatio;
22907 var width = w.globals.gridWidth - (w.globals.maxX - w.config.chart.selection.xaxis.max) / xyRatios.xRatio - x;
22908 if (w.globals.isRangeBar) {
22909 // rangebars put datetime data in y axis
22910 x = (w.config.chart.selection.xaxis.min - w.globals.yAxisScale[0].niceMin) / xyRatios.invertedYRatio;
22911 width = (w.config.chart.selection.xaxis.max - w.config.chart.selection.xaxis.min) / xyRatios.invertedYRatio;
22912 }
22913 var selectionRect = {
22914 x: x,
22915 y: 0,
22916 width: width,
22917 height: w.globals.gridHeight,
22918 translateX: w.globals.translateX,
22919 translateY: w.globals.translateY,
22920 selectionEnabled: true
22921 };
22922 this.drawSelectionRect(selectionRect);
22923 this.makeSelectionRectDraggable();
22924 if (typeof w.config.chart.events.selection === 'function') {
22925 w.config.chart.events.selection(this.ctx, {
22926 xaxis: {
22927 min: w.config.chart.selection.xaxis.min,
22928 max: w.config.chart.selection.xaxis.max
22929 },
22930 yaxis: {}
22931 });
22932 }
22933 }
22934 }
22935 }
22936 }
22937 }, {
22938 key: "drawSelectionRect",
22939 value: function drawSelectionRect(_ref3) {
22940 var x = _ref3.x,
22941 y = _ref3.y,
22942 width = _ref3.width,
22943 height = _ref3.height,
22944 _ref3$translateX = _ref3.translateX,
22945 translateX = _ref3$translateX === void 0 ? 0 : _ref3$translateX,
22946 _ref3$translateY = _ref3.translateY,
22947 translateY = _ref3$translateY === void 0 ? 0 : _ref3$translateY;
22948 var w = this.w;
22949 var zoomRect = this.zoomRect;
22950 var selectionRect = this.selectionRect;
22951 if (this.dragged || w.globals.selection !== null) {
22952 var scalingAttrs = {
22953 transform: 'translate(' + translateX + ', ' + translateY + ')'
22954 };
22955
22956 // change styles based on zoom or selection
22957 // zoom is Enabled and user has dragged, so draw blue rect
22958 if (w.globals.zoomEnabled && this.dragged) {
22959 if (width < 0) width = 1; // fixes apexcharts.js#1168
22960 zoomRect.attr({
22961 x: x,
22962 y: y,
22963 width: width,
22964 height: height,
22965 fill: w.config.chart.zoom.zoomedArea.fill.color,
22966 'fill-opacity': w.config.chart.zoom.zoomedArea.fill.opacity,
22967 stroke: w.config.chart.zoom.zoomedArea.stroke.color,
22968 'stroke-width': w.config.chart.zoom.zoomedArea.stroke.width,
22969 'stroke-opacity': w.config.chart.zoom.zoomedArea.stroke.opacity
22970 });
22971 Graphics.setAttrs(zoomRect.node, scalingAttrs);
22972 }
22973
22974 // selection is enabled
22975 if (w.globals.selectionEnabled) {
22976 selectionRect.attr({
22977 x: x,
22978 y: y,
22979 width: width > 0 ? width : 0,
22980 height: height > 0 ? height : 0,
22981 fill: w.config.chart.selection.fill.color,
22982 'fill-opacity': w.config.chart.selection.fill.opacity,
22983 stroke: w.config.chart.selection.stroke.color,
22984 'stroke-width': w.config.chart.selection.stroke.width,
22985 'stroke-dasharray': w.config.chart.selection.stroke.dashArray,
22986 'stroke-opacity': w.config.chart.selection.stroke.opacity
22987 });
22988 Graphics.setAttrs(selectionRect.node, scalingAttrs);
22989 }
22990 }
22991 }
22992 }, {
22993 key: "hideSelectionRect",
22994 value: function hideSelectionRect(rect) {
22995 if (rect) {
22996 rect.attr({
22997 x: 0,
22998 y: 0,
22999 width: 0,
23000 height: 0
23001 });
23002 }
23003 }
23004 }, {
23005 key: "selectionDrawing",
23006 value: function selectionDrawing(_ref4) {
23007 var context = _ref4.context,
23008 zoomtype = _ref4.zoomtype;
23009 var w = this.w;
23010 var me = context;
23011 var gridRectDim = this.gridRect.getBoundingClientRect();
23012 var startX = me.startX - 1;
23013 var startY = me.startY;
23014 var inversedX = false;
23015 var inversedY = false;
23016 var left = me.clientX - gridRectDim.left - w.globals.barPadForNumericAxis;
23017 var top = me.clientY - gridRectDim.top;
23018 var selectionWidth = left - startX;
23019 var selectionHeight = top - startY;
23020 var selectionRect = {
23021 translateX: w.globals.translateX,
23022 translateY: w.globals.translateY
23023 };
23024 if (Math.abs(selectionWidth + startX) > w.globals.gridWidth) {
23025 // user dragged the mouse outside drawing area to the right
23026 selectionWidth = w.globals.gridWidth - startX;
23027 } else if (left < 0) {
23028 // user dragged the mouse outside drawing area to the left
23029 selectionWidth = startX;
23030 }
23031
23032 // inverse selection X
23033 if (startX > left) {
23034 inversedX = true;
23035 selectionWidth = Math.abs(selectionWidth);
23036 }
23037
23038 // inverse selection Y
23039 if (startY > top) {
23040 inversedY = true;
23041 selectionHeight = Math.abs(selectionHeight);
23042 }
23043 if (zoomtype === 'x') {
23044 selectionRect = {
23045 x: inversedX ? startX - selectionWidth : startX,
23046 y: 0,
23047 width: selectionWidth,
23048 height: w.globals.gridHeight
23049 };
23050 } else if (zoomtype === 'y') {
23051 selectionRect = {
23052 x: 0,
23053 y: inversedY ? startY - selectionHeight : startY,
23054 width: w.globals.gridWidth,
23055 height: selectionHeight
23056 };
23057 } else {
23058 selectionRect = {
23059 x: inversedX ? startX - selectionWidth : startX,
23060 y: inversedY ? startY - selectionHeight : startY,
23061 width: selectionWidth,
23062 height: selectionHeight
23063 };
23064 }
23065 selectionRect = _objectSpread2(_objectSpread2({}, selectionRect), {}, {
23066 translateX: w.globals.translateX,
23067 translateY: w.globals.translateY
23068 });
23069 me.drawSelectionRect(selectionRect);
23070 me.selectionDragging('resizing');
23071 return selectionRect;
23072 }
23073 }, {
23074 key: "selectionDragging",
23075 value: function selectionDragging(type, e) {
23076 var _this5 = this;
23077 var w = this.w;
23078 if (!e) return;
23079 e.preventDefault();
23080 var _e$detail = e.detail,
23081 handler = _e$detail.handler,
23082 box = _e$detail.box;
23083 var x = box.x,
23084 y = box.y;
23085 if (x < this.constraints.x) {
23086 x = this.constraints.x;
23087 }
23088 if (y < this.constraints.y) {
23089 y = this.constraints.y;
23090 }
23091 if (box.x2 > this.constraints.x2) {
23092 x = this.constraints.x2 - box.w;
23093 }
23094 if (box.y2 > this.constraints.y2) {
23095 y = this.constraints.y2 - box.h;
23096 }
23097 handler.move(x, y);
23098 var xyRatios = this.xyRatios;
23099 var selRect = this.selectionRect;
23100 var timerInterval = 0;
23101 if (type === 'resizing') {
23102 timerInterval = 30;
23103 }
23104
23105 // update selection when selection rect is dragged
23106 var getSelAttr = function getSelAttr(attr) {
23107 return parseFloat(selRect.node.getAttribute(attr));
23108 };
23109 var draggedProps = {
23110 x: getSelAttr('x'),
23111 y: getSelAttr('y'),
23112 width: getSelAttr('width'),
23113 height: getSelAttr('height')
23114 };
23115 w.globals.selection = draggedProps;
23116 // update selection ends
23117
23118 if (typeof w.config.chart.events.selection === 'function' && w.globals.selectionEnabled) {
23119 // a small debouncer is required when resizing to avoid freezing the chart
23120 clearTimeout(this.w.globals.selectionResizeTimer);
23121 this.w.globals.selectionResizeTimer = window.setTimeout(function () {
23122 var gridRectDim = _this5.gridRect.getBoundingClientRect();
23123 var selectionRect = selRect.node.getBoundingClientRect();
23124 var minX, maxX, minY, maxY;
23125 if (!w.globals.isRangeBar) {
23126 // normal XY charts
23127 minX = w.globals.xAxisScale.niceMin + (selectionRect.left - gridRectDim.left) * xyRatios.xRatio;
23128 maxX = w.globals.xAxisScale.niceMin + (selectionRect.right - gridRectDim.left) * xyRatios.xRatio;
23129 minY = w.globals.yAxisScale[0].niceMin + (gridRectDim.bottom - selectionRect.bottom) * xyRatios.yRatio[0];
23130 maxY = w.globals.yAxisScale[0].niceMax - (selectionRect.top - gridRectDim.top) * xyRatios.yRatio[0];
23131 } else {
23132 // rangeBars use y for datetime
23133 minX = w.globals.yAxisScale[0].niceMin + (selectionRect.left - gridRectDim.left) * xyRatios.invertedYRatio;
23134 maxX = w.globals.yAxisScale[0].niceMin + (selectionRect.right - gridRectDim.left) * xyRatios.invertedYRatio;
23135 minY = 0;
23136 maxY = 1;
23137 }
23138 var xyAxis = {
23139 xaxis: {
23140 min: minX,
23141 max: maxX
23142 },
23143 yaxis: {
23144 min: minY,
23145 max: maxY
23146 }
23147 };
23148 w.config.chart.events.selection(_this5.ctx, xyAxis);
23149 if (w.config.chart.brush.enabled && w.config.chart.events.brushScrolled !== undefined) {
23150 w.config.chart.events.brushScrolled(_this5.ctx, xyAxis);
23151 }
23152 }, timerInterval);
23153 }
23154 }
23155 }, {
23156 key: "selectionDrawn",
23157 value: function selectionDrawn(_ref5) {
23158 var context = _ref5.context,
23159 zoomtype = _ref5.zoomtype;
23160 var w = this.w;
23161 var me = context;
23162 var xyRatios = this.xyRatios;
23163 var toolbar = this.ctx.toolbar;
23164
23165 // Use boundingRect for final selection area
23166 var selRect = w.globals.zoomEnabled ? me.zoomRect.node.getBoundingClientRect() : me.selectionRect.node.getBoundingClientRect();
23167 var gridRectDim = me.gridRect.getBoundingClientRect();
23168
23169 // Local coords in the chart's grid
23170 var localStartX = selRect.left - gridRectDim.left - w.globals.barPadForNumericAxis;
23171 var localEndX = selRect.right - gridRectDim.left - w.globals.barPadForNumericAxis;
23172 var localStartY = selRect.top - gridRectDim.top;
23173 var localEndY = selRect.bottom - gridRectDim.top;
23174
23175 // Convert those local coords to actual data values
23176 var xLowestValue, xHighestValue;
23177 if (!w.globals.isRangeBar) {
23178 xLowestValue = w.globals.xAxisScale.niceMin + localStartX * xyRatios.xRatio;
23179 xHighestValue = w.globals.xAxisScale.niceMin + localEndX * xyRatios.xRatio;
23180 } else {
23181 xLowestValue = w.globals.yAxisScale[0].niceMin + localStartX * xyRatios.invertedYRatio;
23182 xHighestValue = w.globals.yAxisScale[0].niceMin + localEndX * xyRatios.invertedYRatio;
23183 }
23184
23185 // For Y values, pick from the first y-axis, but handle multi-axis
23186 var yHighestValue = [];
23187 var yLowestValue = [];
23188 w.config.yaxis.forEach(function (yaxe, index) {
23189 // pick whichever series is mapped to this y-axis
23190 var seriesIndex = w.globals.seriesYAxisMap[index][0];
23191 var highestVal = w.globals.yAxisScale[index].niceMax - xyRatios.yRatio[seriesIndex] * localStartY;
23192 var lowestVal = w.globals.yAxisScale[index].niceMax - xyRatios.yRatio[seriesIndex] * localEndY;
23193 yHighestValue.push(highestVal);
23194 yLowestValue.push(lowestVal);
23195 });
23196
23197 // Only apply if user actually dragged far enough to consider it a selection
23198 if (me.dragged && (me.dragX > 10 || me.dragY > 10) && xLowestValue !== xHighestValue) {
23199 if (w.globals.zoomEnabled) {
23200 var yaxis = Utils$1.clone(w.globals.initialConfig.yaxis);
23201 var xaxis = Utils$1.clone(w.globals.initialConfig.xaxis);
23202 w.globals.zoomed = true;
23203 if (w.config.xaxis.convertedCatToNumeric) {
23204 xLowestValue = Math.floor(xLowestValue);
23205 xHighestValue = Math.floor(xHighestValue);
23206 if (xLowestValue < 1) {
23207 xLowestValue = 1;
23208 xHighestValue = w.globals.dataPoints;
23209 }
23210 if (xHighestValue - xLowestValue < 2) {
23211 xHighestValue = xLowestValue + 1;
23212 }
23213 }
23214 if (zoomtype === 'xy' || zoomtype === 'x') {
23215 xaxis = {
23216 min: xLowestValue,
23217 max: xHighestValue
23218 };
23219 }
23220 if (zoomtype === 'xy' || zoomtype === 'y') {
23221 yaxis.forEach(function (yaxe, index) {
23222 yaxis[index].min = yLowestValue[index];
23223 yaxis[index].max = yHighestValue[index];
23224 });
23225 }
23226 if (toolbar) {
23227 var beforeZoomRange = toolbar.getBeforeZoomRange(xaxis, yaxis);
23228 if (beforeZoomRange) {
23229 xaxis = beforeZoomRange.xaxis ? beforeZoomRange.xaxis : xaxis;
23230 yaxis = beforeZoomRange.yaxis ? beforeZoomRange.yaxis : yaxis;
23231 }
23232 }
23233 var options = {
23234 xaxis: xaxis
23235 };
23236 if (!w.config.chart.group) {
23237 // if chart in a group, prevent yaxis update here
23238 // fix issue #650
23239 options.yaxis = yaxis;
23240 }
23241 me.ctx.updateHelpers._updateOptions(options, false, me.w.config.chart.animations.dynamicAnimation.enabled);
23242 if (typeof w.config.chart.events.zoomed === 'function') {
23243 toolbar.zoomCallback(xaxis, yaxis);
23244 }
23245 } else if (w.globals.selectionEnabled) {
23246 var _yaxis = null;
23247 var _xaxis = null;
23248 _xaxis = {
23249 min: xLowestValue,
23250 max: xHighestValue
23251 };
23252 if (zoomtype === 'xy' || zoomtype === 'y') {
23253 _yaxis = Utils$1.clone(w.config.yaxis);
23254 _yaxis.forEach(function (yaxe, index) {
23255 _yaxis[index].min = yLowestValue[index];
23256 _yaxis[index].max = yHighestValue[index];
23257 });
23258 }
23259 w.globals.selection = me.selection;
23260 if (typeof w.config.chart.events.selection === 'function') {
23261 w.config.chart.events.selection(me.ctx, {
23262 xaxis: _xaxis,
23263 yaxis: _yaxis
23264 });
23265 }
23266 }
23267 }
23268 }
23269 }, {
23270 key: "panDragging",
23271 value: function panDragging(_ref6) {
23272 var context = _ref6.context;
23273 var w = this.w;
23274 var me = context;
23275
23276 // check to make sure there is data to compare against
23277 if (typeof w.globals.lastClientPosition.x !== 'undefined') {
23278 // get the change from last position to this position
23279 var deltaX = w.globals.lastClientPosition.x - me.clientX;
23280 var deltaY = w.globals.lastClientPosition.y - me.clientY;
23281
23282 // check which direction had the highest amplitude
23283 if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX > 0) {
23284 this.moveDirection = 'left';
23285 } else if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX < 0) {
23286 this.moveDirection = 'right';
23287 } else if (Math.abs(deltaY) > Math.abs(deltaX) && deltaY > 0) {
23288 this.moveDirection = 'up';
23289 } else if (Math.abs(deltaY) > Math.abs(deltaX) && deltaY < 0) {
23290 this.moveDirection = 'down';
23291 }
23292 }
23293
23294 // set the new last position to the current for next time (to get the position of drag)
23295 w.globals.lastClientPosition = {
23296 x: me.clientX,
23297 y: me.clientY
23298 };
23299 var xLowestValue = w.globals.isRangeBar ? w.globals.minY : w.globals.minX;
23300 var xHighestValue = w.globals.isRangeBar ? w.globals.maxY : w.globals.maxX;
23301
23302 // removed delayedPanScrolled as it doesn't seem to cause bugs anymore in convertedCatToNumeric
23303 // if (!w.config.xaxis.convertedCatToNumeric) {
23304 me.panScrolled(xLowestValue, xHighestValue);
23305 // }
23306 }
23307
23308 // delayedPanScrolled() {
23309 // const w = this.w
23310
23311 // let newMinX = w.globals.minX
23312 // let newMaxX = w.globals.maxX
23313 // const centerX = (w.globals.maxX - w.globals.minX) / 2
23314
23315 // if (this.moveDirection === 'left') {
23316 // newMinX = w.globals.minX + centerX
23317 // newMaxX = w.globals.maxX + centerX
23318 // } else if (this.moveDirection === 'right') {
23319 // newMinX = w.globals.minX - centerX
23320 // newMaxX = w.globals.maxX - centerX
23321 // }
23322
23323 // newMinX = Math.floor(newMinX)
23324 // newMaxX = Math.floor(newMaxX)
23325 // this.updateScrolledChart(
23326 // { xaxis: { min: newMinX, max: newMaxX } },
23327 // newMinX,
23328 // newMaxX
23329 // )
23330 // }
23331 }, {
23332 key: "panScrolled",
23333 value: function panScrolled(xLowestValue, xHighestValue) {
23334 var w = this.w;
23335 var xyRatios = this.xyRatios;
23336 var yaxis = Utils$1.clone(w.globals.initialConfig.yaxis);
23337 var xRatio = xyRatios.xRatio;
23338 var minX = w.globals.minX;
23339 var maxX = w.globals.maxX;
23340 if (w.globals.isRangeBar) {
23341 xRatio = xyRatios.invertedYRatio;
23342 minX = w.globals.minY;
23343 maxX = w.globals.maxY;
23344 }
23345 if (this.moveDirection === 'left') {
23346 xLowestValue = minX + w.globals.gridWidth / 15 * xRatio;
23347 xHighestValue = maxX + w.globals.gridWidth / 15 * xRatio;
23348 } else if (this.moveDirection === 'right') {
23349 xLowestValue = minX - w.globals.gridWidth / 15 * xRatio;
23350 xHighestValue = maxX - w.globals.gridWidth / 15 * xRatio;
23351 }
23352 if (!w.globals.isRangeBar) {
23353 if (xLowestValue < w.globals.initialMinX || xHighestValue > w.globals.initialMaxX) {
23354 xLowestValue = minX;
23355 xHighestValue = maxX;
23356 }
23357 }
23358 var xaxis = {
23359 min: xLowestValue,
23360 max: xHighestValue
23361 };
23362 var options = {
23363 xaxis: xaxis
23364 };
23365 if (!w.config.chart.group) {
23366 // if chart in a group, prevent yaxis update here
23367 // fix issue #650
23368 options.yaxis = yaxis;
23369 }
23370 this.updateScrolledChart(options, xLowestValue, xHighestValue);
23371 }
23372 }, {
23373 key: "updateScrolledChart",
23374 value: function updateScrolledChart(options, xLowestValue, xHighestValue) {
23375 var w = this.w;
23376 this.ctx.updateHelpers._updateOptions(options, false, false);
23377 if (typeof w.config.chart.events.scrolled === 'function') {
23378 var args = {
23379 xaxis: {
23380 min: xLowestValue,
23381 max: xHighestValue
23382 }
23383 };
23384 w.config.chart.events.scrolled(this.ctx, args);
23385 this.ctx.events.fireEvent('scrolled', args);
23386 }
23387 }
23388 }]);
23389 return ZoomPanSelection;
23390 }(Toolbar);
23391
23392 /**
23393 * ApexCharts Tooltip.Utils Class to support Tooltip functionality.
23394 *
23395 * @module Tooltip.Utils
23396 **/
23397 var Utils = /*#__PURE__*/function () {
23398 function Utils(tooltipContext) {
23399 _classCallCheck(this, Utils);
23400 this.w = tooltipContext.w;
23401 this.ttCtx = tooltipContext;
23402 this.ctx = tooltipContext.ctx;
23403 }
23404
23405 /**
23406 ** When hovering over series, you need to capture which series is being hovered on.
23407 ** This function will return both capturedseries index as well as inner index of that series
23408 * @memberof Utils
23409 * @param {object}
23410 * - hoverArea = the rect on which user hovers
23411 * - elGrid = dimensions of the hover rect (it can be different than hoverarea)
23412 */
23413 _createClass(Utils, [{
23414 key: "getNearestValues",
23415 value: function getNearestValues(_ref) {
23416 var hoverArea = _ref.hoverArea,
23417 elGrid = _ref.elGrid,
23418 clientX = _ref.clientX,
23419 clientY = _ref.clientY;
23420 var w = this.w;
23421 var seriesBound = elGrid.getBoundingClientRect();
23422 var hoverWidth = seriesBound.width;
23423 var hoverHeight = seriesBound.height;
23424 var xDivisor = hoverWidth / (w.globals.dataPoints - 1);
23425 var yDivisor = hoverHeight / w.globals.dataPoints;
23426 var hasBars = this.hasBars();
23427 if ((w.globals.comboCharts || hasBars) && !w.config.xaxis.convertedCatToNumeric) {
23428 xDivisor = hoverWidth / w.globals.dataPoints;
23429 }
23430 var hoverX = clientX - seriesBound.left - w.globals.barPadForNumericAxis;
23431 var hoverY = clientY - seriesBound.top;
23432 var notInRect = hoverX < 0 || hoverY < 0 || hoverX > hoverWidth || hoverY > hoverHeight;
23433 if (notInRect) {
23434 hoverArea.classList.remove('hovering-zoom');
23435 hoverArea.classList.remove('hovering-pan');
23436 } else {
23437 if (w.globals.zoomEnabled) {
23438 hoverArea.classList.remove('hovering-pan');
23439 hoverArea.classList.add('hovering-zoom');
23440 } else if (w.globals.panEnabled) {
23441 hoverArea.classList.remove('hovering-zoom');
23442 hoverArea.classList.add('hovering-pan');
23443 }
23444 }
23445 var j = Math.round(hoverX / xDivisor);
23446 var jHorz = Math.floor(hoverY / yDivisor);
23447 if (hasBars && !w.config.xaxis.convertedCatToNumeric) {
23448 j = Math.ceil(hoverX / xDivisor);
23449 j = j - 1;
23450 }
23451 var capturedSeries = null;
23452 var closest = null;
23453 var seriesXValArr = w.globals.seriesXvalues.map(function (seriesXVal) {
23454 return seriesXVal.filter(function (s) {
23455 return Utils$1.isNumber(s);
23456 });
23457 });
23458 var seriesYValArr = w.globals.seriesYvalues.map(function (seriesYVal) {
23459 return seriesYVal.filter(function (s) {
23460 return Utils$1.isNumber(s);
23461 });
23462 });
23463
23464 // if X axis type is not category and tooltip is not shared, then we need to find the cursor position and get the nearest value
23465 if (w.globals.isXNumeric) {
23466 // Change origin of cursor position so that we can compute the relative nearest point to the cursor on our chart
23467 // we only need to scale because all points are relative to the bounds.left and bounds.top => origin is virtually (0, 0)
23468 var chartGridEl = this.ttCtx.getElGrid();
23469 var chartGridElBoundingRect = chartGridEl.getBoundingClientRect();
23470 var transformedHoverX = hoverX * (chartGridElBoundingRect.width / hoverWidth);
23471 var transformedHoverY = hoverY * (chartGridElBoundingRect.height / hoverHeight);
23472 closest = this.closestInMultiArray(transformedHoverX, transformedHoverY, seriesXValArr, seriesYValArr);
23473 capturedSeries = closest.index;
23474 j = closest.j;
23475 if (capturedSeries !== null && w.globals.hasNullValues) {
23476 // initial push, it should be a little smaller than the 1st val
23477 seriesXValArr = w.globals.seriesXvalues[capturedSeries];
23478 closest = this.closestInArray(transformedHoverX, seriesXValArr);
23479 j = closest.j;
23480 }
23481 }
23482 w.globals.capturedSeriesIndex = capturedSeries === null ? -1 : capturedSeries;
23483 if (!j || j < 1) j = 0;
23484 if (w.globals.isBarHorizontal) {
23485 w.globals.capturedDataPointIndex = jHorz;
23486 } else {
23487 w.globals.capturedDataPointIndex = j;
23488 }
23489 return {
23490 capturedSeries: capturedSeries,
23491 j: w.globals.isBarHorizontal ? jHorz : j,
23492 hoverX: hoverX,
23493 hoverY: hoverY
23494 };
23495 }
23496 }, {
23497 key: "getFirstActiveXArray",
23498 value: function getFirstActiveXArray(Xarrays) {
23499 var w = this.w;
23500 var activeIndex = 0;
23501 var firstActiveSeriesIndex = Xarrays.map(function (xarr, index) {
23502 return xarr.length > 0 ? index : -1;
23503 });
23504 for (var a = 0; a < firstActiveSeriesIndex.length; a++) {
23505 if (firstActiveSeriesIndex[a] !== -1 && w.globals.collapsedSeriesIndices.indexOf(a) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(a) === -1) {
23506 activeIndex = firstActiveSeriesIndex[a];
23507 break;
23508 }
23509 }
23510 return activeIndex;
23511 }
23512 }, {
23513 key: "closestInMultiArray",
23514 value: function closestInMultiArray(hoverX, hoverY, Xarrays, Yarrays) {
23515 var w = this.w;
23516
23517 // Determine which series are active (not collapsed)
23518 var isActiveSeries = function isActiveSeries(seriesIndex) {
23519 return w.globals.collapsedSeriesIndices.indexOf(seriesIndex) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(seriesIndex) === -1;
23520 };
23521 var closestDist = Infinity;
23522 var closestSeriesIndex = null;
23523 var closestPointIndex = null;
23524
23525 // Iterate through all series and points to find the closest (x,y) to (hoverX, hoverY)
23526 for (var i = 0; i < Xarrays.length; i++) {
23527 if (!isActiveSeries(i)) {
23528 continue;
23529 }
23530 var xArr = Xarrays[i];
23531 var yArr = Yarrays[i];
23532 var len = Math.min(xArr.length, yArr.length);
23533 for (var j = 0; j < len; j++) {
23534 var xVal = xArr[j];
23535 var distX = hoverX - xVal;
23536 var dist = Math.sqrt(distX * distX);
23537 if (!w.globals.allSeriesHasEqualX) {
23538 var yVal = yArr[j];
23539 var distY = hoverY - yVal;
23540 dist = Math.sqrt(distX * distX + distY * distY);
23541 }
23542 if (dist < closestDist) {
23543 closestDist = dist;
23544 closestSeriesIndex = i;
23545 closestPointIndex = j;
23546 }
23547 }
23548 }
23549 return {
23550 index: closestSeriesIndex,
23551 j: closestPointIndex
23552 };
23553 }
23554 }, {
23555 key: "closestInArray",
23556 value: function closestInArray(val, arr) {
23557 var curr = arr[0];
23558 var currIndex = null;
23559 var diff = Math.abs(val - curr);
23560 for (var i = 0; i < arr.length; i++) {
23561 var newdiff = Math.abs(val - arr[i]);
23562 if (newdiff < diff) {
23563 diff = newdiff;
23564 currIndex = i;
23565 }
23566 }
23567 return {
23568 j: currIndex
23569 };
23570 }
23571
23572 /**
23573 * When there are multiple series, it is possible to have different x values for each series.
23574 * But it may be possible in those multiple series, that there is same x value for 2 or more
23575 * series.
23576 * @memberof Utils
23577 * @param {int}
23578 * - j = is the inner index of series -> (series[i][j])
23579 * @return {bool}
23580 */
23581 }, {
23582 key: "isXoverlap",
23583 value: function isXoverlap(j) {
23584 var w = this.w;
23585 var xSameForAllSeriesJArr = [];
23586 var seriesX = w.globals.seriesX.filter(function (s) {
23587 return typeof s[0] !== 'undefined';
23588 });
23589 if (seriesX.length > 0) {
23590 for (var i = 0; i < seriesX.length - 1; i++) {
23591 if (typeof seriesX[i][j] !== 'undefined' && typeof seriesX[i + 1][j] !== 'undefined') {
23592 if (seriesX[i][j] !== seriesX[i + 1][j]) {
23593 xSameForAllSeriesJArr.push('unEqual');
23594 }
23595 }
23596 }
23597 }
23598 if (xSameForAllSeriesJArr.length === 0) {
23599 return true;
23600 }
23601 return false;
23602 }
23603 }, {
23604 key: "isInitialSeriesSameLen",
23605 value: function isInitialSeriesSameLen() {
23606 var sameLen = true;
23607 var initialSeries = this.w.globals.initialSeries;
23608 for (var i = 0; i < initialSeries.length - 1; i++) {
23609 if (initialSeries[i].data.length !== initialSeries[i + 1].data.length) {
23610 sameLen = false;
23611 break;
23612 }
23613 }
23614 return sameLen;
23615 }
23616 }, {
23617 key: "getBarsHeight",
23618 value: function getBarsHeight(allbars) {
23619 var bars = _toConsumableArray(allbars);
23620 var totalHeight = bars.reduce(function (acc, bar) {
23621 return acc + bar.getBBox().height;
23622 }, 0);
23623 return totalHeight;
23624 }
23625 }, {
23626 key: "getElMarkers",
23627 value: function getElMarkers(capturedSeries) {
23628 // The selector .apexcharts-series-markers-wrap > * includes marker groups for which the
23629 // .apexcharts-series-markers class is not added due to null values or discrete markers
23630 if (typeof capturedSeries == 'number') {
23631 return this.w.globals.dom.baseEl.querySelectorAll(".apexcharts-series[data\\:realIndex='".concat(capturedSeries, "'] .apexcharts-series-markers-wrap > *"));
23632 }
23633 return this.w.globals.dom.baseEl.querySelectorAll('.apexcharts-series-markers-wrap > *');
23634 }
23635 }, {
23636 key: "getAllMarkers",
23637 value: function getAllMarkers() {
23638 var _this = this;
23639 var filterCollapsed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
23640 // first get all marker parents. This parent class contains series-index
23641 // which helps to sort the markers as they are dynamic
23642 var markersWraps = this.w.globals.dom.baseEl.querySelectorAll('.apexcharts-series-markers-wrap');
23643 markersWraps = _toConsumableArray(markersWraps);
23644 if (filterCollapsed) {
23645 markersWraps = markersWraps.filter(function (m) {
23646 var realIndex = Number(m.getAttribute('data:realIndex'));
23647 return _this.w.globals.collapsedSeriesIndices.indexOf(realIndex) === -1;
23648 });
23649 }
23650 markersWraps.sort(function (a, b) {
23651 var indexA = Number(a.getAttribute('data:realIndex'));
23652 var indexB = Number(b.getAttribute('data:realIndex'));
23653 return indexB < indexA ? 1 : indexB > indexA ? -1 : 0;
23654 });
23655 var markers = [];
23656 markersWraps.forEach(function (m) {
23657 markers.push(m.querySelector('.apexcharts-marker'));
23658 });
23659 return markers;
23660 }
23661 }, {
23662 key: "hasMarkers",
23663 value: function hasMarkers(capturedSeries) {
23664 var markers = this.getElMarkers(capturedSeries);
23665 return markers.length > 0;
23666 }
23667 }, {
23668 key: "getPathFromPoint",
23669 value: function getPathFromPoint(point, size) {
23670 var cx = Number(point.getAttribute('cx'));
23671 var cy = Number(point.getAttribute('cy'));
23672 var shape = point.getAttribute('shape');
23673 return new Graphics(this.ctx).getMarkerPath(cx, cy, shape, size);
23674 }
23675 }, {
23676 key: "getElBars",
23677 value: function getElBars() {
23678 return this.w.globals.dom.baseEl.querySelectorAll('.apexcharts-bar-series, .apexcharts-candlestick-series, .apexcharts-boxPlot-series, .apexcharts-rangebar-series');
23679 }
23680 }, {
23681 key: "hasBars",
23682 value: function hasBars() {
23683 var bars = this.getElBars();
23684 return bars.length > 0;
23685 }
23686 }, {
23687 key: "getHoverMarkerSize",
23688 value: function getHoverMarkerSize(index) {
23689 var w = this.w;
23690 var hoverSize = w.config.markers.hover.size;
23691 if (hoverSize === undefined) {
23692 hoverSize = w.globals.markers.size[index] + w.config.markers.hover.sizeOffset;
23693 }
23694 return hoverSize;
23695 }
23696 }, {
23697 key: "toggleAllTooltipSeriesGroups",
23698 value: function toggleAllTooltipSeriesGroups(state) {
23699 var w = this.w;
23700 var ttCtx = this.ttCtx;
23701 if (ttCtx.allTooltipSeriesGroups.length === 0) {
23702 ttCtx.allTooltipSeriesGroups = w.globals.dom.baseEl.querySelectorAll('.apexcharts-tooltip-series-group');
23703 }
23704 var allTooltipSeriesGroups = ttCtx.allTooltipSeriesGroups;
23705 for (var i = 0; i < allTooltipSeriesGroups.length; i++) {
23706 if (state === 'enable') {
23707 allTooltipSeriesGroups[i].classList.add('apexcharts-active');
23708 allTooltipSeriesGroups[i].style.display = w.config.tooltip.items.display;
23709 } else {
23710 allTooltipSeriesGroups[i].classList.remove('apexcharts-active');
23711 allTooltipSeriesGroups[i].style.display = 'none';
23712 }
23713 }
23714 }
23715 }]);
23716 return Utils;
23717 }();
23718
23719 /**
23720 * ApexCharts Tooltip.Labels Class to draw texts on the tooltip.
23721 * This file deals with printing actual text on the tooltip.
23722 *
23723 * @module Tooltip.Labels
23724 **/
23725 var Labels = /*#__PURE__*/function () {
23726 function Labels(tooltipContext) {
23727 _classCallCheck(this, Labels);
23728 this.w = tooltipContext.w;
23729 this.ctx = tooltipContext.ctx;
23730 this.ttCtx = tooltipContext;
23731 this.tooltipUtil = new Utils(tooltipContext);
23732 }
23733 _createClass(Labels, [{
23734 key: "drawSeriesTexts",
23735 value: function drawSeriesTexts(_ref) {
23736 var _ref$shared = _ref.shared,
23737 shared = _ref$shared === void 0 ? true : _ref$shared,
23738 ttItems = _ref.ttItems,
23739 _ref$i = _ref.i,
23740 i = _ref$i === void 0 ? 0 : _ref$i,
23741 _ref$j = _ref.j,
23742 j = _ref$j === void 0 ? null : _ref$j,
23743 y1 = _ref.y1,
23744 y2 = _ref.y2,
23745 e = _ref.e;
23746 var w = this.w;
23747 if (w.config.tooltip.custom !== undefined) {
23748 this.handleCustomTooltip({
23749 i: i,
23750 j: j,
23751 y1: y1,
23752 y2: y2,
23753 w: w
23754 });
23755 } else {
23756 this.toggleActiveInactiveSeries(shared, i);
23757 }
23758 var values = this.getValuesToPrint({
23759 i: i,
23760 j: j
23761 });
23762 this.printLabels({
23763 i: i,
23764 j: j,
23765 values: values,
23766 ttItems: ttItems,
23767 shared: shared,
23768 e: e
23769 });
23770
23771 // Re-calculate tooltip dimensions now that we have drawn the text
23772 var tooltipEl = this.ttCtx.getElTooltip();
23773 this.ttCtx.tooltipRect.ttWidth = tooltipEl.getBoundingClientRect().width;
23774 this.ttCtx.tooltipRect.ttHeight = tooltipEl.getBoundingClientRect().height;
23775 }
23776 }, {
23777 key: "printLabels",
23778 value: function printLabels(_ref2) {
23779 var _this = this;
23780 var i = _ref2.i,
23781 j = _ref2.j,
23782 values = _ref2.values,
23783 ttItems = _ref2.ttItems,
23784 shared = _ref2.shared,
23785 e = _ref2.e;
23786 var w = this.w;
23787 var val;
23788 var goalVals = [];
23789 var hasGoalValues = function hasGoalValues(gi) {
23790 return w.globals.seriesGoals[gi] && w.globals.seriesGoals[gi][j] && Array.isArray(w.globals.seriesGoals[gi][j]);
23791 };
23792 var xVal = values.xVal,
23793 zVal = values.zVal,
23794 xAxisTTVal = values.xAxisTTVal;
23795 var seriesName = '';
23796 var pColor = w.globals.colors[i]; // The pColor here is for the markers inside tooltip
23797 if (j !== null && w.config.plotOptions.bar.distributed) {
23798 pColor = w.globals.colors[j];
23799 }
23800 var _loop = function _loop(t, inverset) {
23801 var f = _this.getFormatters(i);
23802 seriesName = _this.getSeriesName({
23803 fn: f.yLbTitleFormatter,
23804 index: i,
23805 seriesIndex: i,
23806 j: j
23807 });
23808 if (w.config.chart.type === 'treemap') {
23809 seriesName = f.yLbTitleFormatter(String(w.config.series[i].data[j].x), {
23810 series: w.globals.series,
23811 seriesIndex: i,
23812 dataPointIndex: j,
23813 w: w
23814 });
23815 }
23816 var tIndex = w.config.tooltip.inverseOrder ? inverset : t;
23817 if (w.globals.axisCharts) {
23818 var getValBySeriesIndex = function getValBySeriesIndex(index) {
23819 if (w.globals.isRangeData) {
23820 var _w$globals$seriesRang, _w$globals$seriesRang2, _w$globals$seriesRang3, _w$globals$seriesRang4;
23821 return f.yLbFormatter((_w$globals$seriesRang = w.globals.seriesRangeStart) === null || _w$globals$seriesRang === void 0 ? void 0 : (_w$globals$seriesRang2 = _w$globals$seriesRang[index]) === null || _w$globals$seriesRang2 === void 0 ? void 0 : _w$globals$seriesRang2[j], {
23822 series: w.globals.seriesRangeStart,
23823 seriesIndex: index,
23824 dataPointIndex: j,
23825 w: w
23826 }) + ' - ' + f.yLbFormatter((_w$globals$seriesRang3 = w.globals.seriesRangeEnd) === null || _w$globals$seriesRang3 === void 0 ? void 0 : (_w$globals$seriesRang4 = _w$globals$seriesRang3[index]) === null || _w$globals$seriesRang4 === void 0 ? void 0 : _w$globals$seriesRang4[j], {
23827 series: w.globals.seriesRangeEnd,
23828 seriesIndex: index,
23829 dataPointIndex: j,
23830 w: w
23831 });
23832 }
23833 return f.yLbFormatter(w.globals.series[index][j], {
23834 series: w.globals.series,
23835 seriesIndex: index,
23836 dataPointIndex: j,
23837 w: w
23838 });
23839 };
23840 if (shared) {
23841 f = _this.getFormatters(tIndex);
23842 seriesName = _this.getSeriesName({
23843 fn: f.yLbTitleFormatter,
23844 index: tIndex,
23845 seriesIndex: i,
23846 j: j
23847 });
23848 pColor = w.globals.colors[tIndex];
23849 val = getValBySeriesIndex(tIndex);
23850 if (hasGoalValues(tIndex)) {
23851 goalVals = w.globals.seriesGoals[tIndex][j].map(function (goal) {
23852 return {
23853 attrs: goal,
23854 val: f.yLbFormatter(goal.value, {
23855 seriesIndex: tIndex,
23856 dataPointIndex: j,
23857 w: w
23858 })
23859 };
23860 });
23861 }
23862 } else {
23863 var _e$target;
23864 // get a color from a hover area (if it's a line pattern then get from a first line)
23865 var targetFill = e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.getAttribute('fill');
23866 if (targetFill) {
23867 if (targetFill.indexOf('url') !== -1) {
23868 // pattern fill
23869 if (targetFill.indexOf('Pattern') !== -1) {
23870 pColor = w.globals.dom.baseEl.querySelector(targetFill.substr(4).slice(0, -1)).childNodes[0].getAttribute('stroke');
23871 }
23872 } else {
23873 pColor = targetFill;
23874 }
23875 }
23876 val = getValBySeriesIndex(i);
23877 if (hasGoalValues(i) && Array.isArray(w.globals.seriesGoals[i][j])) {
23878 goalVals = w.globals.seriesGoals[i][j].map(function (goal) {
23879 return {
23880 attrs: goal,
23881 val: f.yLbFormatter(goal.value, {
23882 seriesIndex: i,
23883 dataPointIndex: j,
23884 w: w
23885 })
23886 };
23887 });
23888 }
23889 }
23890 }
23891
23892 // for pie / donuts
23893 if (j === null) {
23894 val = f.yLbFormatter(w.globals.series[i], _objectSpread2(_objectSpread2({}, w), {}, {
23895 seriesIndex: i,
23896 dataPointIndex: i
23897 }));
23898 }
23899 _this.DOMHandling({
23900 i: i,
23901 t: tIndex,
23902 j: j,
23903 ttItems: ttItems,
23904 values: {
23905 val: val,
23906 goalVals: goalVals,
23907 xVal: xVal,
23908 xAxisTTVal: xAxisTTVal,
23909 zVal: zVal
23910 },
23911 seriesName: seriesName,
23912 shared: shared,
23913 pColor: pColor
23914 });
23915 };
23916 for (var t = 0, inverset = w.globals.series.length - 1; t < w.globals.series.length; t++, inverset--) {
23917 _loop(t, inverset);
23918 }
23919 }
23920 }, {
23921 key: "getFormatters",
23922 value: function getFormatters(i) {
23923 var w = this.w;
23924 var yLbFormatter = w.globals.yLabelFormatters[i];
23925 var yLbTitleFormatter;
23926 if (w.globals.ttVal !== undefined) {
23927 if (Array.isArray(w.globals.ttVal)) {
23928 yLbFormatter = w.globals.ttVal[i] && w.globals.ttVal[i].formatter;
23929 yLbTitleFormatter = w.globals.ttVal[i] && w.globals.ttVal[i].title && w.globals.ttVal[i].title.formatter;
23930 } else {
23931 yLbFormatter = w.globals.ttVal.formatter;
23932 if (typeof w.globals.ttVal.title.formatter === 'function') {
23933 yLbTitleFormatter = w.globals.ttVal.title.formatter;
23934 }
23935 }
23936 } else {
23937 yLbTitleFormatter = w.config.tooltip.y.title.formatter;
23938 }
23939 if (typeof yLbFormatter !== 'function') {
23940 if (w.globals.yLabelFormatters[0]) {
23941 yLbFormatter = w.globals.yLabelFormatters[0];
23942 } else {
23943 yLbFormatter = function yLbFormatter(label) {
23944 return label;
23945 };
23946 }
23947 }
23948 if (typeof yLbTitleFormatter !== 'function') {
23949 yLbTitleFormatter = function yLbTitleFormatter(label) {
23950 // refrence used from line: 966 in Options.js
23951 return label ? label + ': ' : '';
23952 };
23953 }
23954 return {
23955 yLbFormatter: yLbFormatter,
23956 yLbTitleFormatter: yLbTitleFormatter
23957 };
23958 }
23959 }, {
23960 key: "getSeriesName",
23961 value: function getSeriesName(_ref3) {
23962 var fn = _ref3.fn,
23963 index = _ref3.index,
23964 seriesIndex = _ref3.seriesIndex,
23965 j = _ref3.j;
23966 var w = this.w;
23967 return fn(String(w.globals.seriesNames[index]), {
23968 series: w.globals.series,
23969 seriesIndex: seriesIndex,
23970 dataPointIndex: j,
23971 w: w
23972 });
23973 }
23974 }, {
23975 key: "DOMHandling",
23976 value: function DOMHandling(_ref4) {
23977 _ref4.i;
23978 var t = _ref4.t,
23979 j = _ref4.j,
23980 ttItems = _ref4.ttItems,
23981 values = _ref4.values,
23982 seriesName = _ref4.seriesName,
23983 shared = _ref4.shared,
23984 pColor = _ref4.pColor;
23985 var w = this.w;
23986 var ttCtx = this.ttCtx;
23987 var val = values.val,
23988 goalVals = values.goalVals,
23989 xVal = values.xVal,
23990 xAxisTTVal = values.xAxisTTVal,
23991 zVal = values.zVal;
23992 var ttItemsChildren = null;
23993 ttItemsChildren = ttItems[t].children;
23994 if (w.config.tooltip.fillSeriesColor) {
23995 ttItems[t].style.backgroundColor = pColor;
23996 ttItemsChildren[0].style.display = 'none';
23997 }
23998 if (ttCtx.showTooltipTitle) {
23999 if (ttCtx.tooltipTitle === null) {
24000 // get it once if null, and store it in class property
24001 ttCtx.tooltipTitle = w.globals.dom.baseEl.querySelector('.apexcharts-tooltip-title');
24002 }
24003 ttCtx.tooltipTitle.innerHTML = xVal;
24004 }
24005
24006 // if xaxis tooltip is constructed, we need to replace the innerHTML
24007 if (ttCtx.isXAxisTooltipEnabled) {
24008 ttCtx.xaxisTooltipText.innerHTML = xAxisTTVal !== '' ? xAxisTTVal : xVal;
24009 }
24010 var ttYLabel = ttItems[t].querySelector('.apexcharts-tooltip-text-y-label');
24011 if (ttYLabel) {
24012 ttYLabel.innerHTML = seriesName ? seriesName : '';
24013 }
24014 var ttYVal = ttItems[t].querySelector('.apexcharts-tooltip-text-y-value');
24015 if (ttYVal) {
24016 ttYVal.innerHTML = typeof val !== 'undefined' ? val : '';
24017 }
24018 if (ttItemsChildren[0] && ttItemsChildren[0].classList.contains('apexcharts-tooltip-marker')) {
24019 if (w.config.tooltip.marker.fillColors && Array.isArray(w.config.tooltip.marker.fillColors)) {
24020 pColor = w.config.tooltip.marker.fillColors[t];
24021 }
24022 if (w.config.tooltip.fillSeriesColor) {
24023 ttItemsChildren[0].style.backgroundColor = pColor;
24024 } else {
24025 ttItemsChildren[0].style.color = pColor;
24026 }
24027 }
24028 if (!w.config.tooltip.marker.show) {
24029 ttItemsChildren[0].style.display = 'none';
24030 }
24031 var ttGLabel = ttItems[t].querySelector('.apexcharts-tooltip-text-goals-label');
24032 var ttGVal = ttItems[t].querySelector('.apexcharts-tooltip-text-goals-value');
24033 if (goalVals.length && w.globals.seriesGoals[t]) {
24034 var createGoalsHtml = function createGoalsHtml() {
24035 var gLabels = '<div>';
24036 var gVals = '<div>';
24037 goalVals.forEach(function (goal, gi) {
24038 gLabels += " <div style=\"display: flex\"><span class=\"apexcharts-tooltip-marker\" style=\"background-color: ".concat(goal.attrs.strokeColor, "; height: 3px; border-radius: 0; top: 5px;\"></span> ").concat(goal.attrs.name, "</div>");
24039 gVals += "<div>".concat(goal.val, "</div>");
24040 });
24041 ttGLabel.innerHTML = gLabels + "</div>";
24042 ttGVal.innerHTML = gVals + "</div>";
24043 };
24044 if (shared) {
24045 if (w.globals.seriesGoals[t][j] && Array.isArray(w.globals.seriesGoals[t][j])) {
24046 createGoalsHtml();
24047 } else {
24048 ttGLabel.innerHTML = '';
24049 ttGVal.innerHTML = '';
24050 }
24051 } else {
24052 createGoalsHtml();
24053 }
24054 } else {
24055 ttGLabel.innerHTML = '';
24056 ttGVal.innerHTML = '';
24057 }
24058 if (zVal !== null) {
24059 var ttZLabel = ttItems[t].querySelector('.apexcharts-tooltip-text-z-label');
24060 ttZLabel.innerHTML = w.config.tooltip.z.title;
24061 var ttZVal = ttItems[t].querySelector('.apexcharts-tooltip-text-z-value');
24062 ttZVal.innerHTML = typeof zVal !== 'undefined' ? zVal : '';
24063 }
24064 if (shared && ttItemsChildren[0]) {
24065 // hide when no Val or series collapsed
24066 if (w.config.tooltip.hideEmptySeries) {
24067 var ttItemMarker = ttItems[t].querySelector('.apexcharts-tooltip-marker');
24068 var ttItemText = ttItems[t].querySelector('.apexcharts-tooltip-text');
24069 if (parseFloat(val) == 0) {
24070 ttItemMarker.style.display = 'none';
24071 ttItemText.style.display = 'none';
24072 } else {
24073 ttItemMarker.style.display = 'block';
24074 ttItemText.style.display = 'block';
24075 }
24076 }
24077 if (typeof val === 'undefined' || val === null || w.globals.ancillaryCollapsedSeriesIndices.indexOf(t) > -1 || w.globals.collapsedSeriesIndices.indexOf(t) > -1 || Array.isArray(ttCtx.tConfig.enabledOnSeries) && ttCtx.tConfig.enabledOnSeries.indexOf(t) === -1) {
24078 ttItemsChildren[0].parentNode.style.display = 'none';
24079 } else {
24080 ttItemsChildren[0].parentNode.style.display = w.config.tooltip.items.display;
24081 }
24082 } else {
24083 if (Array.isArray(ttCtx.tConfig.enabledOnSeries) && ttCtx.tConfig.enabledOnSeries.indexOf(t) === -1) {
24084 ttItemsChildren[0].parentNode.style.display = 'none';
24085 }
24086 }
24087 }
24088 }, {
24089 key: "toggleActiveInactiveSeries",
24090 value: function toggleActiveInactiveSeries(shared, i) {
24091 var w = this.w;
24092 if (shared) {
24093 // make all tooltips active
24094 this.tooltipUtil.toggleAllTooltipSeriesGroups('enable');
24095 } else {
24096 // disable all tooltip text groups
24097 this.tooltipUtil.toggleAllTooltipSeriesGroups('disable');
24098
24099 // enable the first tooltip text group
24100 var firstTooltipSeriesGroup = w.globals.dom.baseEl.querySelector(".apexcharts-tooltip-series-group-".concat(i));
24101 if (firstTooltipSeriesGroup) {
24102 firstTooltipSeriesGroup.classList.add('apexcharts-active');
24103 firstTooltipSeriesGroup.style.display = w.config.tooltip.items.display;
24104 }
24105 }
24106 }
24107 }, {
24108 key: "getValuesToPrint",
24109 value: function getValuesToPrint(_ref5) {
24110 var i = _ref5.i,
24111 j = _ref5.j;
24112 var w = this.w;
24113 var filteredSeriesX = this.ctx.series.filteredSeriesX();
24114 var xVal = '';
24115 var xAxisTTVal = '';
24116 var zVal = null;
24117 var val = null;
24118 var customFormatterOpts = {
24119 series: w.globals.series,
24120 seriesIndex: i,
24121 dataPointIndex: j,
24122 w: w
24123 };
24124 var zFormatter = w.globals.ttZFormatter;
24125 if (j === null) {
24126 val = w.globals.series[i];
24127 } else {
24128 if (w.globals.isXNumeric && w.config.chart.type !== 'treemap') {
24129 xVal = filteredSeriesX[i][j];
24130 if (filteredSeriesX[i].length === 0) {
24131 // a series (possibly the first one) might be collapsed, so get the next active index
24132 var firstActiveSeriesIndex = this.tooltipUtil.getFirstActiveXArray(filteredSeriesX);
24133 xVal = filteredSeriesX[firstActiveSeriesIndex][j];
24134 }
24135 } else {
24136 var dataFormat = new Data(this.ctx);
24137 if (dataFormat.isFormatXY()) {
24138 xVal = typeof w.config.series[i].data[j] !== 'undefined' ? w.config.series[i].data[j].x : '';
24139 } else {
24140 xVal = typeof w.globals.labels[j] !== 'undefined' ? w.globals.labels[j] : '';
24141 }
24142 }
24143 }
24144 var bufferXVal = xVal;
24145 if (w.globals.isXNumeric && w.config.xaxis.type === 'datetime') {
24146 var xFormat = new Formatters(this.ctx);
24147 xVal = xFormat.xLabelFormat(w.globals.ttKeyFormatter, bufferXVal, bufferXVal, {
24148 i: undefined,
24149 dateFormatter: new DateTime(this.ctx).formatDate,
24150 w: this.w
24151 });
24152 } else {
24153 if (w.globals.isBarHorizontal) {
24154 xVal = w.globals.yLabelFormatters[0](bufferXVal, customFormatterOpts);
24155 } else {
24156 xVal = w.globals.xLabelFormatter(bufferXVal, customFormatterOpts);
24157 }
24158 }
24159
24160 // override default x-axis formatter with tooltip formatter
24161 if (w.config.tooltip.x.formatter !== undefined) {
24162 xVal = w.globals.ttKeyFormatter(bufferXVal, customFormatterOpts);
24163 }
24164 if (w.globals.seriesZ.length > 0 && w.globals.seriesZ[i].length > 0) {
24165 zVal = zFormatter(w.globals.seriesZ[i][j], w);
24166 }
24167 if (typeof w.config.xaxis.tooltip.formatter === 'function') {
24168 xAxisTTVal = w.globals.xaxisTooltipFormatter(bufferXVal, customFormatterOpts);
24169 } else {
24170 xAxisTTVal = xVal;
24171 }
24172 return {
24173 val: Array.isArray(val) ? val.join(' ') : val,
24174 xVal: Array.isArray(xVal) ? xVal.join(' ') : xVal,
24175 xAxisTTVal: Array.isArray(xAxisTTVal) ? xAxisTTVal.join(' ') : xAxisTTVal,
24176 zVal: zVal
24177 };
24178 }
24179 }, {
24180 key: "handleCustomTooltip",
24181 value: function handleCustomTooltip(_ref6) {
24182 var i = _ref6.i,
24183 j = _ref6.j,
24184 y1 = _ref6.y1,
24185 y2 = _ref6.y2,
24186 w = _ref6.w;
24187 var tooltipEl = this.ttCtx.getElTooltip();
24188 var fn = w.config.tooltip.custom;
24189 if (Array.isArray(fn) && fn[i]) {
24190 fn = fn[i];
24191 }
24192 var customTooltip = fn({
24193 ctx: this.ctx,
24194 series: w.globals.series,
24195 seriesIndex: i,
24196 dataPointIndex: j,
24197 y1: y1,
24198 y2: y2,
24199 w: w
24200 });
24201 if (typeof customTooltip === 'string' || typeof customTooltip === 'number') {
24202 tooltipEl.innerHTML = customTooltip;
24203 } else if (customTooltip instanceof Element || typeof customTooltip.nodeName === 'string') {
24204 tooltipEl.innerHTML = '';
24205 tooltipEl.appendChild(customTooltip.cloneNode(true));
24206 }
24207 }
24208 }]);
24209 return Labels;
24210 }();
24211
24212 /**
24213 * ApexCharts Tooltip.Position Class to move the tooltip based on x and y position.
24214 *
24215 * @module Tooltip.Position
24216 **/
24217 var Position = /*#__PURE__*/function () {
24218 function Position(tooltipContext) {
24219 _classCallCheck(this, Position);
24220 this.ttCtx = tooltipContext;
24221 this.ctx = tooltipContext.ctx;
24222 this.w = tooltipContext.w;
24223 }
24224
24225 /**
24226 * This will move the crosshair (the vertical/horz line that moves along with mouse)
24227 * Along with this, this function also calls the xaxisMove function
24228 * @memberof Position
24229 * @param {int} - cx = point's x position, wherever point's x is, you need to move crosshair
24230 */
24231 _createClass(Position, [{
24232 key: "moveXCrosshairs",
24233 value: function moveXCrosshairs(cx) {
24234 var j = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
24235 var ttCtx = this.ttCtx;
24236 var w = this.w;
24237 var xcrosshairs = ttCtx.getElXCrosshairs();
24238 var x = cx - ttCtx.xcrosshairsWidth / 2;
24239 var tickAmount = w.globals.labels.slice().length;
24240 if (j !== null) {
24241 x = w.globals.gridWidth / tickAmount * j;
24242 }
24243 if (xcrosshairs !== null && !w.globals.isBarHorizontal) {
24244 xcrosshairs.setAttribute('x', x);
24245 xcrosshairs.setAttribute('x1', x);
24246 xcrosshairs.setAttribute('x2', x);
24247 xcrosshairs.setAttribute('y2', w.globals.gridHeight);
24248 xcrosshairs.classList.add('apexcharts-active');
24249 }
24250 if (x < 0) {
24251 x = 0;
24252 }
24253 if (x > w.globals.gridWidth) {
24254 x = w.globals.gridWidth;
24255 }
24256 if (ttCtx.isXAxisTooltipEnabled) {
24257 var tx = x;
24258 if (w.config.xaxis.crosshairs.width === 'tickWidth' || w.config.xaxis.crosshairs.width === 'barWidth') {
24259 tx = x + ttCtx.xcrosshairsWidth / 2;
24260 }
24261 this.moveXAxisTooltip(tx);
24262 }
24263 }
24264
24265 /**
24266 * This will move the crosshair (the vertical/horz line that moves along with mouse)
24267 * Along with this, this function also calls the xaxisMove function
24268 * @memberof Position
24269 * @param {int} - cx = point's x position, wherever point's x is, you need to move crosshair
24270 */
24271 }, {
24272 key: "moveYCrosshairs",
24273 value: function moveYCrosshairs(cy) {
24274 var ttCtx = this.ttCtx;
24275 if (ttCtx.ycrosshairs !== null) {
24276 Graphics.setAttrs(ttCtx.ycrosshairs, {
24277 y1: cy,
24278 y2: cy
24279 });
24280 }
24281 if (ttCtx.ycrosshairsHidden !== null) {
24282 Graphics.setAttrs(ttCtx.ycrosshairsHidden, {
24283 y1: cy,
24284 y2: cy
24285 });
24286 }
24287 }
24288
24289 /**
24290 ** AxisTooltip is the small rectangle which appears on x axis with x value, when user moves
24291 * @memberof Position
24292 * @param {int} - cx = point's x position, wherever point's x is, you need to move
24293 */
24294 }, {
24295 key: "moveXAxisTooltip",
24296 value: function moveXAxisTooltip(cx) {
24297 var w = this.w;
24298 var ttCtx = this.ttCtx;
24299 if (ttCtx.xaxisTooltip !== null && ttCtx.xcrosshairsWidth !== 0) {
24300 ttCtx.xaxisTooltip.classList.add('apexcharts-active');
24301 var cy = ttCtx.xaxisOffY + w.config.xaxis.tooltip.offsetY + w.globals.translateY + 1 + w.config.xaxis.offsetY;
24302 var xaxisTTText = ttCtx.xaxisTooltip.getBoundingClientRect();
24303 var xaxisTTTextWidth = xaxisTTText.width;
24304 cx = cx - xaxisTTTextWidth / 2;
24305 if (!isNaN(cx)) {
24306 cx = cx + w.globals.translateX;
24307 var textRect = 0;
24308 var graphics = new Graphics(this.ctx);
24309 textRect = graphics.getTextRects(ttCtx.xaxisTooltipText.innerHTML);
24310 ttCtx.xaxisTooltipText.style.minWidth = textRect.width + 'px';
24311 ttCtx.xaxisTooltip.style.left = cx + 'px';
24312 ttCtx.xaxisTooltip.style.top = cy + 'px';
24313 }
24314 }
24315 }
24316 }, {
24317 key: "moveYAxisTooltip",
24318 value: function moveYAxisTooltip(index) {
24319 var w = this.w;
24320 var ttCtx = this.ttCtx;
24321 if (ttCtx.yaxisTTEls === null) {
24322 ttCtx.yaxisTTEls = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxistooltip');
24323 }
24324 var ycrosshairsHiddenRectY1 = parseInt(ttCtx.ycrosshairsHidden.getAttribute('y1'), 10);
24325 var cy = w.globals.translateY + ycrosshairsHiddenRectY1;
24326 var yAxisTTRect = ttCtx.yaxisTTEls[index].getBoundingClientRect();
24327 var yAxisTTHeight = yAxisTTRect.height;
24328 var cx = w.globals.translateYAxisX[index] - 2;
24329 if (w.config.yaxis[index].opposite) {
24330 cx = cx - yAxisTTRect.width;
24331 }
24332 cy = cy - yAxisTTHeight / 2;
24333 if (w.globals.ignoreYAxisIndexes.indexOf(index) === -1 && cy > 0 && cy < w.globals.gridHeight) {
24334 ttCtx.yaxisTTEls[index].classList.add('apexcharts-active');
24335 ttCtx.yaxisTTEls[index].style.top = cy + 'px';
24336 ttCtx.yaxisTTEls[index].style.left = cx + w.config.yaxis[index].tooltip.offsetX + 'px';
24337 } else {
24338 ttCtx.yaxisTTEls[index].classList.remove('apexcharts-active');
24339 }
24340 }
24341
24342 /**
24343 ** moves the whole tooltip by changing x, y attrs
24344 * @memberof Position
24345 * @param {int} - cx = point's x position, wherever point's x is, you need to move tooltip
24346 * @param {int} - cy = point's y position, wherever point's y is, you need to move tooltip
24347 * @param {int} - markerSize = point's size
24348 */
24349 }, {
24350 key: "moveTooltip",
24351 value: function moveTooltip(cx, cy) {
24352 var markerSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
24353 var w = this.w;
24354 var ttCtx = this.ttCtx;
24355 var tooltipEl = ttCtx.getElTooltip();
24356 var tooltipRect = ttCtx.tooltipRect;
24357 var pointSize = markerSize !== null ? parseFloat(markerSize) : 1;
24358 var x = parseFloat(cx) + pointSize + 5;
24359 var y = parseFloat(cy) + pointSize / 2; // - tooltipRect.ttHeight / 2
24360
24361 if (x > w.globals.gridWidth / 2) {
24362 x = x - tooltipRect.ttWidth - pointSize - 10;
24363 }
24364 if (x > w.globals.gridWidth - tooltipRect.ttWidth - 10) {
24365 x = w.globals.gridWidth - tooltipRect.ttWidth;
24366 }
24367 if (x < -20) {
24368 x = -20;
24369 }
24370 if (w.config.tooltip.followCursor) {
24371 var elGrid = ttCtx.getElGrid();
24372 var seriesBound = elGrid.getBoundingClientRect();
24373 x = ttCtx.e.clientX - seriesBound.left;
24374 if (x > w.globals.gridWidth / 2) {
24375 x = x - ttCtx.tooltipRect.ttWidth;
24376 }
24377 y = ttCtx.e.clientY + w.globals.translateY - seriesBound.top;
24378 if (y > w.globals.gridHeight / 2) {
24379 y = y - ttCtx.tooltipRect.ttHeight;
24380 }
24381 } else {
24382 if (!w.globals.isBarHorizontal) {
24383 if (tooltipRect.ttHeight / 2 + y > w.globals.gridHeight) {
24384 y = w.globals.gridHeight - tooltipRect.ttHeight + w.globals.translateY;
24385 }
24386 }
24387 }
24388 if (!isNaN(x)) {
24389 x = x + w.globals.translateX;
24390 tooltipEl.style.left = x + 'px';
24391 tooltipEl.style.top = y + 'px';
24392 }
24393 }
24394 }, {
24395 key: "moveMarkers",
24396 value: function moveMarkers(i, j) {
24397 var w = this.w;
24398 var ttCtx = this.ttCtx;
24399 if (w.globals.markers.size[i] > 0) {
24400 var allPoints = w.globals.dom.baseEl.querySelectorAll(" .apexcharts-series[data\\:realIndex='".concat(i, "'] .apexcharts-marker"));
24401 for (var p = 0; p < allPoints.length; p++) {
24402 if (parseInt(allPoints[p].getAttribute('rel'), 10) === j) {
24403 ttCtx.marker.resetPointsSize();
24404 ttCtx.marker.enlargeCurrentPoint(j, allPoints[p]);
24405 }
24406 }
24407 } else {
24408 ttCtx.marker.resetPointsSize();
24409 this.moveDynamicPointOnHover(j, i);
24410 }
24411 }
24412
24413 // This function is used when you need to show markers/points only on hover -
24414 // DIFFERENT X VALUES in multiple series
24415 }, {
24416 key: "moveDynamicPointOnHover",
24417 value: function moveDynamicPointOnHover(j, capturedSeries) {
24418 var _pointsArr$capturedSe, _pointsArr$capturedSe2;
24419 var w = this.w;
24420 var ttCtx = this.ttCtx;
24421 var cx = 0;
24422 var cy = 0;
24423 var graphics = new Graphics(this.ctx);
24424 var pointsArr = w.globals.pointsArray;
24425 var hoverSize = ttCtx.tooltipUtil.getHoverMarkerSize(capturedSeries);
24426 var serType = w.config.series[capturedSeries].type;
24427 if (serType && (serType === 'column' || serType === 'candlestick' || serType === 'boxPlot')) {
24428 // fix error mentioned in #811
24429 return;
24430 }
24431 cx = (_pointsArr$capturedSe = pointsArr[capturedSeries][j]) === null || _pointsArr$capturedSe === void 0 ? void 0 : _pointsArr$capturedSe[0];
24432 cy = ((_pointsArr$capturedSe2 = pointsArr[capturedSeries][j]) === null || _pointsArr$capturedSe2 === void 0 ? void 0 : _pointsArr$capturedSe2[1]) || 0;
24433 var point = w.globals.dom.baseEl.querySelector(".apexcharts-series[data\\:realIndex='".concat(capturedSeries, "'] .apexcharts-series-markers path"));
24434 if (point && cy < w.globals.gridHeight && cy > 0) {
24435 var shape = point.getAttribute('shape');
24436 var path = graphics.getMarkerPath(cx, cy, shape, hoverSize * 1.5);
24437 point.setAttribute('d', path);
24438 }
24439 this.moveXCrosshairs(cx);
24440 if (!ttCtx.fixedTooltip) {
24441 this.moveTooltip(cx, cy, hoverSize);
24442 }
24443 }
24444
24445 // This function is used when you need to show markers/points only on hover -
24446 // SAME X VALUES in multiple series
24447 }, {
24448 key: "moveDynamicPointsOnHover",
24449 value: function moveDynamicPointsOnHover(j) {
24450 var ttCtx = this.ttCtx;
24451 var w = ttCtx.w;
24452 var cx = 0;
24453 var cy = 0;
24454 var activeSeries = 0;
24455 var pointsArr = w.globals.pointsArray;
24456 var series = new Series(this.ctx);
24457 var graphics = new Graphics(this.ctx);
24458 activeSeries = series.getActiveConfigSeriesIndex('asc', ['line', 'area', 'scatter', 'bubble']);
24459 var hoverSize = ttCtx.tooltipUtil.getHoverMarkerSize(activeSeries);
24460 if (pointsArr[activeSeries]) {
24461 cx = pointsArr[activeSeries][j][0];
24462 cy = pointsArr[activeSeries][j][1];
24463 }
24464 if (isNaN(cx)) {
24465 return;
24466 }
24467 var points = ttCtx.tooltipUtil.getAllMarkers();
24468 if (points.length) {
24469 for (var p = 0; p < w.globals.series.length; p++) {
24470 var pointArr = pointsArr[p];
24471 if (w.globals.comboCharts) {
24472 // in a combo chart, if column charts are present, markers will not match with the number of series, hence this patch to push a null value in points array
24473 if (typeof pointArr === 'undefined') {
24474 // nodelist to array
24475 points.splice(p, 0, null);
24476 }
24477 }
24478 if (pointArr && pointArr.length) {
24479 var pcy = pointsArr[p][j][1];
24480 var pcy2 = void 0;
24481 points[p].setAttribute('cx', cx);
24482 var shape = points[p].getAttribute('shape');
24483 if (w.config.chart.type === 'rangeArea' && !w.globals.comboCharts) {
24484 var rangeStartIndex = j + w.globals.series[p].length;
24485 pcy2 = pointsArr[p][rangeStartIndex][1];
24486 var pcyDiff = Math.abs(pcy - pcy2) / 2;
24487 pcy = pcy - pcyDiff;
24488 }
24489 if (pcy !== null && !isNaN(pcy) && pcy < w.globals.gridHeight + hoverSize && pcy + hoverSize > 0) {
24490 var path = graphics.getMarkerPath(cx, pcy, shape, hoverSize);
24491 points[p].setAttribute('d', path);
24492 } else {
24493 points[p].setAttribute('d', '');
24494 }
24495 }
24496 }
24497 }
24498 this.moveXCrosshairs(cx);
24499 if (!ttCtx.fixedTooltip) {
24500 this.moveTooltip(cx, cy || w.globals.gridHeight, hoverSize);
24501 }
24502 }
24503 }, {
24504 key: "moveStickyTooltipOverBars",
24505 value: function moveStickyTooltipOverBars(j, capturedSeries) {
24506 var w = this.w;
24507 var ttCtx = this.ttCtx;
24508 var barLen = w.globals.columnSeries ? w.globals.columnSeries.length : w.globals.series.length;
24509 if (w.config.chart.stacked) {
24510 barLen = w.globals.barGroups.length;
24511 }
24512 var i = barLen >= 2 && barLen % 2 === 0 ? Math.floor(barLen / 2) : Math.floor(barLen / 2) + 1;
24513 if (w.globals.isBarHorizontal) {
24514 var series = new Series(this.ctx);
24515 i = series.getActiveConfigSeriesIndex('desc') + 1;
24516 }
24517 var jBar = w.globals.dom.baseEl.querySelector(".apexcharts-bar-series .apexcharts-series[rel='".concat(i, "'] path[j='").concat(j, "'], .apexcharts-candlestick-series .apexcharts-series[rel='").concat(i, "'] path[j='").concat(j, "'], .apexcharts-boxPlot-series .apexcharts-series[rel='").concat(i, "'] path[j='").concat(j, "'], .apexcharts-rangebar-series .apexcharts-series[rel='").concat(i, "'] path[j='").concat(j, "']"));
24518 if (!jBar && typeof capturedSeries === 'number') {
24519 // Try with captured series index
24520 jBar = w.globals.dom.baseEl.querySelector(".apexcharts-bar-series .apexcharts-series[data\\:realIndex='".concat(capturedSeries, "'] path[j='").concat(j, "'],\n .apexcharts-candlestick-series .apexcharts-series[data\\:realIndex='").concat(capturedSeries, "'] path[j='").concat(j, "'],\n .apexcharts-boxPlot-series .apexcharts-series[data\\:realIndex='").concat(capturedSeries, "'] path[j='").concat(j, "'],\n .apexcharts-rangebar-series .apexcharts-series[data\\:realIndex='").concat(capturedSeries, "'] path[j='").concat(j, "']"));
24521 }
24522 var bcx = jBar ? parseFloat(jBar.getAttribute('cx')) : 0;
24523 var bcy = jBar ? parseFloat(jBar.getAttribute('cy')) : 0;
24524 var bw = jBar ? parseFloat(jBar.getAttribute('barWidth')) : 0;
24525 var elGrid = ttCtx.getElGrid();
24526 var seriesBound = elGrid.getBoundingClientRect();
24527 var isBoxOrCandle = jBar && (jBar.classList.contains('apexcharts-candlestick-area') || jBar.classList.contains('apexcharts-boxPlot-area'));
24528 if (w.globals.isXNumeric) {
24529 if (jBar && !isBoxOrCandle) {
24530 bcx = bcx - (barLen % 2 !== 0 ? bw / 2 : 0);
24531 }
24532 if (jBar &&
24533 // fixes apexcharts.js#2354
24534 isBoxOrCandle) {
24535 bcx = bcx - bw / 2;
24536 }
24537 } else {
24538 if (!w.globals.isBarHorizontal) {
24539 bcx = ttCtx.xAxisTicksPositions[j - 1] + ttCtx.dataPointsDividedWidth / 2;
24540 if (isNaN(bcx)) {
24541 bcx = ttCtx.xAxisTicksPositions[j] - ttCtx.dataPointsDividedWidth / 2;
24542 }
24543 }
24544 }
24545 if (!w.globals.isBarHorizontal) {
24546 if (w.config.tooltip.followCursor) {
24547 bcy = ttCtx.e.clientY - seriesBound.top - ttCtx.tooltipRect.ttHeight / 2;
24548 } else {
24549 if (bcy + ttCtx.tooltipRect.ttHeight + 15 > w.globals.gridHeight) {
24550 bcy = w.globals.gridHeight;
24551 }
24552 }
24553 } else {
24554 bcy = bcy - ttCtx.tooltipRect.ttHeight;
24555 }
24556 if (!w.globals.isBarHorizontal) {
24557 this.moveXCrosshairs(bcx);
24558 }
24559 if (!ttCtx.fixedTooltip) {
24560 this.moveTooltip(bcx, bcy || w.globals.gridHeight);
24561 }
24562 }
24563 }]);
24564 return Position;
24565 }();
24566
24567 /**
24568 * ApexCharts Tooltip.Marker Class to draw texts on the tooltip.
24569 * This file deals with the markers that appear near tooltip in line/area charts.
24570 * These markers helps the user to associate the data-points and the values
24571 * that are shown in the tooltip
24572 *
24573 * @module Tooltip.Marker
24574 **/
24575 var Marker = /*#__PURE__*/function () {
24576 function Marker(tooltipContext) {
24577 _classCallCheck(this, Marker);
24578 this.w = tooltipContext.w;
24579 this.ttCtx = tooltipContext;
24580 this.ctx = tooltipContext.ctx;
24581 this.tooltipPosition = new Position(tooltipContext);
24582 }
24583 _createClass(Marker, [{
24584 key: "drawDynamicPoints",
24585 value: function drawDynamicPoints() {
24586 var w = this.w;
24587 var graphics = new Graphics(this.ctx);
24588 var marker = new Markers(this.ctx);
24589 var elsSeries = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series');
24590 elsSeries = _toConsumableArray(elsSeries);
24591 if (w.config.chart.stacked) {
24592 elsSeries.sort(function (a, b) {
24593 return parseFloat(a.getAttribute('data:realIndex')) - parseFloat(b.getAttribute('data:realIndex'));
24594 });
24595 }
24596 for (var i = 0; i < elsSeries.length; i++) {
24597 var pointsMain = elsSeries[i].querySelector(".apexcharts-series-markers-wrap");
24598 if (pointsMain !== null) {
24599 // it can be null as we have tooltips in donut/bar charts
24600 var point = void 0;
24601 var PointClasses = "apexcharts-marker w".concat((Math.random() + 1).toString(36).substring(4));
24602 if ((w.config.chart.type === 'line' || w.config.chart.type === 'area') && !w.globals.comboCharts && !w.config.tooltip.intersect) {
24603 PointClasses += ' no-pointer-events';
24604 }
24605 var elPointOptions = marker.getMarkerConfig({
24606 cssClass: PointClasses,
24607 seriesIndex: Number(pointsMain.getAttribute('data:realIndex')) // fixes apexcharts/apexcharts.js #1427
24608 });
24609 point = graphics.drawMarker(0, 0, elPointOptions);
24610 point.node.setAttribute('default-marker-size', 0);
24611 var elPointsG = document.createElementNS(w.globals.SVGNS, 'g');
24612 elPointsG.classList.add('apexcharts-series-markers');
24613 elPointsG.appendChild(point.node);
24614 pointsMain.appendChild(elPointsG);
24615 }
24616 }
24617 }
24618 }, {
24619 key: "enlargeCurrentPoint",
24620 value: function enlargeCurrentPoint(rel, point) {
24621 var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
24622 var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
24623 var w = this.w;
24624 if (w.config.chart.type !== 'bubble') {
24625 this.newPointSize(rel, point);
24626 }
24627 var cx = point.getAttribute('cx');
24628 var cy = point.getAttribute('cy');
24629 if (x !== null && y !== null) {
24630 cx = x;
24631 cy = y;
24632 }
24633 this.tooltipPosition.moveXCrosshairs(cx);
24634 if (!this.fixedTooltip) {
24635 if (w.config.chart.type === 'radar') {
24636 var elGrid = this.ttCtx.getElGrid();
24637 var seriesBound = elGrid.getBoundingClientRect();
24638 cx = this.ttCtx.e.clientX - seriesBound.left;
24639 }
24640 this.tooltipPosition.moveTooltip(cx, cy, w.config.markers.hover.size);
24641 }
24642 }
24643 }, {
24644 key: "enlargePoints",
24645 value: function enlargePoints(j) {
24646 var w = this.w;
24647 var me = this;
24648 var ttCtx = this.ttCtx;
24649 var col = j;
24650 var points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series:not(.apexcharts-series-collapsed) .apexcharts-marker');
24651 var newSize = w.config.markers.hover.size;
24652 for (var p = 0; p < points.length; p++) {
24653 var rel = points[p].getAttribute('rel');
24654 var index = points[p].getAttribute('index');
24655 if (newSize === undefined) {
24656 newSize = w.globals.markers.size[index] + w.config.markers.hover.sizeOffset;
24657 }
24658 if (col === parseInt(rel, 10)) {
24659 me.newPointSize(col, points[p]);
24660 var cx = points[p].getAttribute('cx');
24661 var cy = points[p].getAttribute('cy');
24662 me.tooltipPosition.moveXCrosshairs(cx);
24663 if (!ttCtx.fixedTooltip) {
24664 me.tooltipPosition.moveTooltip(cx, cy, newSize);
24665 }
24666 } else {
24667 me.oldPointSize(points[p]);
24668 }
24669 }
24670 }
24671 }, {
24672 key: "newPointSize",
24673 value: function newPointSize(rel, point) {
24674 var w = this.w;
24675 var newSize = w.config.markers.hover.size;
24676 var elPoint = rel === 0 ? point.parentNode.firstChild : point.parentNode.lastChild;
24677 if (elPoint.getAttribute('default-marker-size') !== '0') {
24678 var index = parseInt(elPoint.getAttribute('index'), 10);
24679 if (newSize === undefined) {
24680 newSize = w.globals.markers.size[index] + w.config.markers.hover.sizeOffset;
24681 }
24682 if (newSize < 0) {
24683 newSize = 0;
24684 }
24685 var path = this.ttCtx.tooltipUtil.getPathFromPoint(point, newSize);
24686 point.setAttribute('d', path);
24687 }
24688 }
24689 }, {
24690 key: "oldPointSize",
24691 value: function oldPointSize(point) {
24692 var size = parseFloat(point.getAttribute('default-marker-size'));
24693 var path = this.ttCtx.tooltipUtil.getPathFromPoint(point, size);
24694 point.setAttribute('d', path);
24695 }
24696 }, {
24697 key: "resetPointsSize",
24698 value: function resetPointsSize() {
24699 var w = this.w;
24700 var points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series:not(.apexcharts-series-collapsed) .apexcharts-marker');
24701 for (var p = 0; p < points.length; p++) {
24702 var size = parseFloat(points[p].getAttribute('default-marker-size'));
24703 if (Utils$1.isNumber(size) && size > 0) {
24704 var path = this.ttCtx.tooltipUtil.getPathFromPoint(points[p], size);
24705 points[p].setAttribute('d', path);
24706 } else {
24707 points[p].setAttribute('d', 'M0,0');
24708 }
24709 }
24710 }
24711 }]);
24712 return Marker;
24713 }();
24714
24715 /**
24716 * ApexCharts Tooltip.Intersect Class.
24717 * This file deals with functions related to intersecting tooltips
24718 * (tooltips that appear when user hovers directly over a data-point whether)
24719 *
24720 * @module Tooltip.Intersect
24721 **/
24722 var Intersect = /*#__PURE__*/function () {
24723 function Intersect(tooltipContext) {
24724 _classCallCheck(this, Intersect);
24725 this.w = tooltipContext.w;
24726 var w = this.w;
24727 this.ttCtx = tooltipContext;
24728 this.isVerticalGroupedRangeBar = !w.globals.isBarHorizontal && w.config.chart.type === 'rangeBar' && w.config.plotOptions.bar.rangeBarGroupRows;
24729 }
24730
24731 // a helper function to get an element's attribute value
24732 _createClass(Intersect, [{
24733 key: "getAttr",
24734 value: function getAttr(e, attr) {
24735 return parseFloat(e.target.getAttribute(attr));
24736 }
24737
24738 // handle tooltip for heatmaps and treemaps
24739 }, {
24740 key: "handleHeatTreeTooltip",
24741 value: function handleHeatTreeTooltip(_ref) {
24742 var e = _ref.e,
24743 opt = _ref.opt,
24744 x = _ref.x,
24745 y = _ref.y,
24746 type = _ref.type;
24747 var ttCtx = this.ttCtx;
24748 var w = this.w;
24749 if (e.target.classList.contains("apexcharts-".concat(type, "-rect"))) {
24750 var i = this.getAttr(e, 'i');
24751 var j = this.getAttr(e, 'j');
24752 var cx = this.getAttr(e, 'cx');
24753 var cy = this.getAttr(e, 'cy');
24754 var width = this.getAttr(e, 'width');
24755 var height = this.getAttr(e, 'height');
24756 ttCtx.tooltipLabels.drawSeriesTexts({
24757 ttItems: opt.ttItems,
24758 i: i,
24759 j: j,
24760 shared: false,
24761 e: e
24762 });
24763 w.globals.capturedSeriesIndex = i;
24764 w.globals.capturedDataPointIndex = j;
24765 x = cx + ttCtx.tooltipRect.ttWidth / 2 + width;
24766 y = cy + ttCtx.tooltipRect.ttHeight / 2 - height / 2;
24767 ttCtx.tooltipPosition.moveXCrosshairs(cx + width / 2);
24768 if (x > w.globals.gridWidth / 2) {
24769 x = cx - ttCtx.tooltipRect.ttWidth / 2 + width;
24770 }
24771 if (ttCtx.w.config.tooltip.followCursor) {
24772 var seriesBound = w.globals.dom.elWrap.getBoundingClientRect();
24773 x = w.globals.clientX - seriesBound.left - (x > w.globals.gridWidth / 2 ? ttCtx.tooltipRect.ttWidth : 0);
24774 y = w.globals.clientY - seriesBound.top - (y > w.globals.gridHeight / 2 ? ttCtx.tooltipRect.ttHeight : 0);
24775 }
24776 }
24777 return {
24778 x: x,
24779 y: y
24780 };
24781 }
24782
24783 /**
24784 * handle tooltips for line/area/scatter charts where tooltip.intersect is true
24785 * when user hovers over the marker directly, this function is executed
24786 */
24787 }, {
24788 key: "handleMarkerTooltip",
24789 value: function handleMarkerTooltip(_ref2) {
24790 var e = _ref2.e,
24791 opt = _ref2.opt,
24792 x = _ref2.x,
24793 y = _ref2.y;
24794 var w = this.w;
24795 var ttCtx = this.ttCtx;
24796 var i;
24797 var j;
24798 if (e.target.classList.contains('apexcharts-marker')) {
24799 var cx = parseInt(opt.paths.getAttribute('cx'), 10);
24800 var cy = parseInt(opt.paths.getAttribute('cy'), 10);
24801 var val = parseFloat(opt.paths.getAttribute('val'));
24802 j = parseInt(opt.paths.getAttribute('rel'), 10);
24803 i = parseInt(opt.paths.parentNode.parentNode.parentNode.getAttribute('rel'), 10) - 1;
24804 if (ttCtx.intersect) {
24805 var el = Utils$1.findAncestor(opt.paths, 'apexcharts-series');
24806 if (el) {
24807 i = parseInt(el.getAttribute('data:realIndex'), 10);
24808 }
24809 }
24810 ttCtx.tooltipLabels.drawSeriesTexts({
24811 ttItems: opt.ttItems,
24812 i: i,
24813 j: j,
24814 shared: ttCtx.showOnIntersect ? false : w.config.tooltip.shared,
24815 e: e
24816 });
24817 if (e.type === 'mouseup') {
24818 ttCtx.markerClick(e, i, j);
24819 }
24820 w.globals.capturedSeriesIndex = i;
24821 w.globals.capturedDataPointIndex = j;
24822 x = cx;
24823 y = cy + w.globals.translateY - ttCtx.tooltipRect.ttHeight * 1.4;
24824 if (ttCtx.w.config.tooltip.followCursor) {
24825 var elGrid = ttCtx.getElGrid();
24826 var seriesBound = elGrid.getBoundingClientRect();
24827 y = ttCtx.e.clientY + w.globals.translateY - seriesBound.top;
24828 }
24829 if (val < 0) {
24830 y = cy;
24831 }
24832 ttCtx.marker.enlargeCurrentPoint(j, opt.paths, x, y);
24833 }
24834 return {
24835 x: x,
24836 y: y
24837 };
24838 }
24839
24840 /**
24841 * handle tooltips for bar/column charts
24842 */
24843 }, {
24844 key: "handleBarTooltip",
24845 value: function handleBarTooltip(_ref3) {
24846 var e = _ref3.e,
24847 opt = _ref3.opt;
24848 var w = this.w;
24849 var ttCtx = this.ttCtx;
24850 var tooltipEl = ttCtx.getElTooltip();
24851 var bx = 0;
24852 var x = 0;
24853 var y = 0;
24854 var i = 0;
24855 var strokeWidth;
24856 var barXY = this.getBarTooltipXY({
24857 e: e,
24858 opt: opt
24859 });
24860 if (barXY.j === null && barXY.barHeight === 0 && barXY.barWidth === 0) {
24861 return; // bar was not hovered and didn't receive correct coords
24862 }
24863 i = barXY.i;
24864 var j = barXY.j;
24865 w.globals.capturedSeriesIndex = i;
24866 w.globals.capturedDataPointIndex = j;
24867 if (w.globals.isBarHorizontal && ttCtx.tooltipUtil.hasBars() || !w.config.tooltip.shared) {
24868 x = barXY.x;
24869 y = barXY.y;
24870 strokeWidth = Array.isArray(w.config.stroke.width) ? w.config.stroke.width[i] : w.config.stroke.width;
24871 bx = x;
24872 } else {
24873 if (!w.globals.comboCharts && !w.config.tooltip.shared) {
24874 // todo: re-check this condition as it's always 0
24875 bx = bx / 2;
24876 }
24877 }
24878
24879 // y is NaN, make it touch the bottom of grid area
24880 if (isNaN(y)) {
24881 y = w.globals.svgHeight - ttCtx.tooltipRect.ttHeight;
24882 }
24883 parseInt(opt.paths.parentNode.getAttribute('data:realIndex'), 10);
24884 if (x + ttCtx.tooltipRect.ttWidth > w.globals.gridWidth) {
24885 x = x - ttCtx.tooltipRect.ttWidth;
24886 } else if (x < 0) {
24887 x = 0;
24888 }
24889 if (ttCtx.w.config.tooltip.followCursor) {
24890 var elGrid = ttCtx.getElGrid();
24891 var seriesBound = elGrid.getBoundingClientRect();
24892 y = ttCtx.e.clientY - seriesBound.top;
24893 }
24894
24895 // if tooltip is still null, querySelector
24896 if (ttCtx.tooltip === null) {
24897 ttCtx.tooltip = w.globals.dom.baseEl.querySelector('.apexcharts-tooltip');
24898 }
24899 if (!w.config.tooltip.shared) {
24900 if (w.globals.comboBarCount > 0) {
24901 ttCtx.tooltipPosition.moveXCrosshairs(bx + strokeWidth / 2);
24902 } else {
24903 ttCtx.tooltipPosition.moveXCrosshairs(bx);
24904 }
24905 }
24906
24907 // move tooltip here
24908 if (!ttCtx.fixedTooltip && (!w.config.tooltip.shared || w.globals.isBarHorizontal && ttCtx.tooltipUtil.hasBars())) {
24909 y = y + w.globals.translateY - ttCtx.tooltipRect.ttHeight / 2;
24910 tooltipEl.style.left = x + w.globals.translateX + 'px';
24911 tooltipEl.style.top = y + 'px';
24912 }
24913 }
24914 }, {
24915 key: "getBarTooltipXY",
24916 value: function getBarTooltipXY(_ref4) {
24917 var _this = this;
24918 var e = _ref4.e,
24919 opt = _ref4.opt;
24920 var w = this.w;
24921 var j = null;
24922 var ttCtx = this.ttCtx;
24923 var i = 0;
24924 var x = 0;
24925 var y = 0;
24926 var barWidth = 0;
24927 var barHeight = 0;
24928 var cl = e.target.classList;
24929 if (cl.contains('apexcharts-bar-area') || cl.contains('apexcharts-candlestick-area') || cl.contains('apexcharts-boxPlot-area') || cl.contains('apexcharts-rangebar-area')) {
24930 var bar = e.target;
24931 var barRect = bar.getBoundingClientRect();
24932 var seriesBound = opt.elGrid.getBoundingClientRect();
24933 var bh = barRect.height;
24934 barHeight = barRect.height;
24935 var bw = barRect.width;
24936 var cx = parseInt(bar.getAttribute('cx'), 10);
24937 var cy = parseInt(bar.getAttribute('cy'), 10);
24938 barWidth = parseFloat(bar.getAttribute('barWidth'));
24939 var clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
24940 j = parseInt(bar.getAttribute('j'), 10);
24941 i = parseInt(bar.parentNode.getAttribute('rel'), 10) - 1;
24942 var y1 = bar.getAttribute('data-range-y1');
24943 var y2 = bar.getAttribute('data-range-y2');
24944 if (w.globals.comboCharts) {
24945 i = parseInt(bar.parentNode.getAttribute('data:realIndex'), 10);
24946 }
24947 var handleXForColumns = function handleXForColumns(x) {
24948 if (w.globals.isXNumeric) {
24949 x = cx - bw / 2;
24950 } else {
24951 if (_this.isVerticalGroupedRangeBar) {
24952 x = cx + bw / 2;
24953 } else {
24954 x = cx - ttCtx.dataPointsDividedWidth + bw / 2;
24955 }
24956 }
24957 return x;
24958 };
24959 var handleYForBars = function handleYForBars() {
24960 return cy - ttCtx.dataPointsDividedHeight + bh / 2 - ttCtx.tooltipRect.ttHeight / 2;
24961 };
24962 ttCtx.tooltipLabels.drawSeriesTexts({
24963 ttItems: opt.ttItems,
24964 i: i,
24965 j: j,
24966 y1: y1 ? parseInt(y1, 10) : null,
24967 y2: y2 ? parseInt(y2, 10) : null,
24968 shared: ttCtx.showOnIntersect ? false : w.config.tooltip.shared,
24969 e: e
24970 });
24971 if (w.config.tooltip.followCursor) {
24972 if (w.globals.isBarHorizontal) {
24973 x = clientX - seriesBound.left + 15;
24974 y = handleYForBars();
24975 } else {
24976 x = handleXForColumns(x);
24977 y = e.clientY - seriesBound.top - ttCtx.tooltipRect.ttHeight / 2 - 15;
24978 }
24979 } else {
24980 if (w.globals.isBarHorizontal) {
24981 x = cx;
24982 if (x < ttCtx.xyRatios.baseLineInvertedY) {
24983 x = cx - ttCtx.tooltipRect.ttWidth;
24984 }
24985 y = handleYForBars();
24986 } else {
24987 x = handleXForColumns(x);
24988 y = cy; // - ttCtx.tooltipRect.ttHeight / 2 + 10
24989 }
24990 }
24991 }
24992 return {
24993 x: x,
24994 y: y,
24995 barHeight: barHeight,
24996 barWidth: barWidth,
24997 i: i,
24998 j: j
24999 };
25000 }
25001 }]);
25002 return Intersect;
25003 }();
25004
25005 /**
25006 * ApexCharts Tooltip.AxesTooltip Class.
25007 * This file deals with the x-axis and y-axis tooltips.
25008 *
25009 * @module Tooltip.AxesTooltip
25010 **/
25011 var AxesTooltip = /*#__PURE__*/function () {
25012 function AxesTooltip(tooltipContext) {
25013 _classCallCheck(this, AxesTooltip);
25014 this.w = tooltipContext.w;
25015 this.ttCtx = tooltipContext;
25016 }
25017
25018 /**
25019 * This method adds the secondary tooltip which appears below x axis
25020 * @memberof Tooltip
25021 **/
25022 _createClass(AxesTooltip, [{
25023 key: "drawXaxisTooltip",
25024 value: function drawXaxisTooltip() {
25025 var w = this.w;
25026 var ttCtx = this.ttCtx;
25027 var isBottom = w.config.xaxis.position === 'bottom';
25028 ttCtx.xaxisOffY = isBottom ? w.globals.gridHeight + 1 : -w.globals.xAxisHeight - w.config.xaxis.axisTicks.height + 3;
25029 var tooltipCssClass = isBottom ? 'apexcharts-xaxistooltip apexcharts-xaxistooltip-bottom' : 'apexcharts-xaxistooltip apexcharts-xaxistooltip-top';
25030 var renderTo = w.globals.dom.elWrap;
25031 if (ttCtx.isXAxisTooltipEnabled) {
25032 var xaxisTooltip = w.globals.dom.baseEl.querySelector('.apexcharts-xaxistooltip');
25033 if (xaxisTooltip === null) {
25034 ttCtx.xaxisTooltip = document.createElement('div');
25035 ttCtx.xaxisTooltip.setAttribute('class', tooltipCssClass + ' apexcharts-theme-' + w.config.tooltip.theme);
25036 renderTo.appendChild(ttCtx.xaxisTooltip);
25037 ttCtx.xaxisTooltipText = document.createElement('div');
25038 ttCtx.xaxisTooltipText.classList.add('apexcharts-xaxistooltip-text');
25039 ttCtx.xaxisTooltipText.style.fontFamily = w.config.xaxis.tooltip.style.fontFamily || w.config.chart.fontFamily;
25040 ttCtx.xaxisTooltipText.style.fontSize = w.config.xaxis.tooltip.style.fontSize;
25041 ttCtx.xaxisTooltip.appendChild(ttCtx.xaxisTooltipText);
25042 }
25043 }
25044 }
25045
25046 /**
25047 * This method adds the secondary tooltip which appears below x axis
25048 * @memberof Tooltip
25049 **/
25050 }, {
25051 key: "drawYaxisTooltip",
25052 value: function drawYaxisTooltip() {
25053 var w = this.w;
25054 var ttCtx = this.ttCtx;
25055 for (var i = 0; i < w.config.yaxis.length; i++) {
25056 var isRight = w.config.yaxis[i].opposite || w.config.yaxis[i].crosshairs.opposite;
25057 ttCtx.yaxisOffX = isRight ? w.globals.gridWidth + 1 : 1;
25058 var tooltipCssClass = isRight ? "apexcharts-yaxistooltip apexcharts-yaxistooltip-".concat(i, " apexcharts-yaxistooltip-right") : "apexcharts-yaxistooltip apexcharts-yaxistooltip-".concat(i, " apexcharts-yaxistooltip-left");
25059 var renderTo = w.globals.dom.elWrap;
25060 var yaxisTooltip = w.globals.dom.baseEl.querySelector(".apexcharts-yaxistooltip apexcharts-yaxistooltip-".concat(i));
25061 if (yaxisTooltip === null) {
25062 ttCtx.yaxisTooltip = document.createElement('div');
25063 ttCtx.yaxisTooltip.setAttribute('class', tooltipCssClass + ' apexcharts-theme-' + w.config.tooltip.theme);
25064 renderTo.appendChild(ttCtx.yaxisTooltip);
25065 if (i === 0) ttCtx.yaxisTooltipText = [];
25066 ttCtx.yaxisTooltipText[i] = document.createElement('div');
25067 ttCtx.yaxisTooltipText[i].classList.add('apexcharts-yaxistooltip-text');
25068 ttCtx.yaxisTooltip.appendChild(ttCtx.yaxisTooltipText[i]);
25069 }
25070 }
25071 }
25072
25073 /**
25074 * @memberof Tooltip
25075 **/
25076 }, {
25077 key: "setXCrosshairWidth",
25078 value: function setXCrosshairWidth() {
25079 var w = this.w;
25080 var ttCtx = this.ttCtx;
25081
25082 // set xcrosshairs width
25083 var xcrosshairs = ttCtx.getElXCrosshairs();
25084 ttCtx.xcrosshairsWidth = parseInt(w.config.xaxis.crosshairs.width, 10);
25085 if (!w.globals.comboCharts) {
25086 if (w.config.xaxis.crosshairs.width === 'tickWidth') {
25087 var count = w.globals.labels.length;
25088 ttCtx.xcrosshairsWidth = w.globals.gridWidth / count;
25089 } else if (w.config.xaxis.crosshairs.width === 'barWidth') {
25090 var bar = w.globals.dom.baseEl.querySelector('.apexcharts-bar-area');
25091 if (bar !== null) {
25092 var barWidth = parseFloat(bar.getAttribute('barWidth'));
25093 ttCtx.xcrosshairsWidth = barWidth;
25094 } else {
25095 ttCtx.xcrosshairsWidth = 1;
25096 }
25097 }
25098 } else {
25099 var _bar = w.globals.dom.baseEl.querySelector('.apexcharts-bar-area');
25100 if (_bar !== null && w.config.xaxis.crosshairs.width === 'barWidth') {
25101 var _barWidth = parseFloat(_bar.getAttribute('barWidth'));
25102 ttCtx.xcrosshairsWidth = _barWidth;
25103 } else {
25104 if (w.config.xaxis.crosshairs.width === 'tickWidth') {
25105 var _count = w.globals.labels.length;
25106 ttCtx.xcrosshairsWidth = w.globals.gridWidth / _count;
25107 }
25108 }
25109 }
25110 if (w.globals.isBarHorizontal) {
25111 ttCtx.xcrosshairsWidth = 0;
25112 }
25113 if (xcrosshairs !== null && ttCtx.xcrosshairsWidth > 0) {
25114 xcrosshairs.setAttribute('width', ttCtx.xcrosshairsWidth);
25115 }
25116 }
25117 }, {
25118 key: "handleYCrosshair",
25119 value: function handleYCrosshair() {
25120 var w = this.w;
25121 var ttCtx = this.ttCtx;
25122
25123 // set ycrosshairs height
25124 ttCtx.ycrosshairs = w.globals.dom.baseEl.querySelector('.apexcharts-ycrosshairs');
25125 ttCtx.ycrosshairsHidden = w.globals.dom.baseEl.querySelector('.apexcharts-ycrosshairs-hidden');
25126 }
25127 }, {
25128 key: "drawYaxisTooltipText",
25129 value: function drawYaxisTooltipText(index, clientY, xyRatios) {
25130 var ttCtx = this.ttCtx;
25131 var w = this.w;
25132 var gl = w.globals;
25133 var yAxisSeriesArr = gl.seriesYAxisMap[index];
25134 if (ttCtx.yaxisTooltips[index] && yAxisSeriesArr.length > 0) {
25135 var lbFormatter = gl.yLabelFormatters[index];
25136 var elGrid = ttCtx.getElGrid();
25137 var seriesBound = elGrid.getBoundingClientRect();
25138
25139 // We can use the index of any series referenced by the Yaxis
25140 // because they will all return the same value.
25141 var seriesIndex = yAxisSeriesArr[0];
25142 var translationsIndex = 0;
25143 if (xyRatios.yRatio.length > 1) {
25144 translationsIndex = seriesIndex;
25145 }
25146 var hoverY = (clientY - seriesBound.top) * xyRatios.yRatio[translationsIndex];
25147 var height = gl.maxYArr[seriesIndex] - gl.minYArr[seriesIndex];
25148 var val = gl.minYArr[seriesIndex] + (height - hoverY);
25149 if (w.config.yaxis[index].reversed) {
25150 val = gl.maxYArr[seriesIndex] - (height - hoverY);
25151 }
25152 ttCtx.tooltipPosition.moveYCrosshairs(clientY - seriesBound.top);
25153 ttCtx.yaxisTooltipText[index].innerHTML = lbFormatter(val);
25154 ttCtx.tooltipPosition.moveYAxisTooltip(index);
25155 }
25156 }
25157 }]);
25158 return AxesTooltip;
25159 }();
25160
25161 /**
25162 * ApexCharts Core Tooltip Class to handle the tooltip generation.
25163 *
25164 * @module Tooltip
25165 **/
25166 var Tooltip = /*#__PURE__*/function () {
25167 function Tooltip(ctx) {
25168 _classCallCheck(this, Tooltip);
25169 this.ctx = ctx;
25170 this.w = ctx.w;
25171 var w = this.w;
25172 this.tConfig = w.config.tooltip;
25173 this.tooltipUtil = new Utils(this);
25174 this.tooltipLabels = new Labels(this);
25175 this.tooltipPosition = new Position(this);
25176 this.marker = new Marker(this);
25177 this.intersect = new Intersect(this);
25178 this.axesTooltip = new AxesTooltip(this);
25179 this.showOnIntersect = this.tConfig.intersect;
25180 this.showTooltipTitle = this.tConfig.x.show;
25181 this.fixedTooltip = this.tConfig.fixed.enabled;
25182 this.xaxisTooltip = null;
25183 this.yaxisTTEls = null;
25184 this.isBarShared = !w.globals.isBarHorizontal && this.tConfig.shared;
25185 this.lastHoverTime = Date.now();
25186 }
25187 _createClass(Tooltip, [{
25188 key: "getElTooltip",
25189 value: function getElTooltip(ctx) {
25190 if (!ctx) ctx = this;
25191 if (!ctx.w.globals.dom.baseEl) return null;
25192 return ctx.w.globals.dom.baseEl.querySelector('.apexcharts-tooltip');
25193 }
25194 }, {
25195 key: "getElXCrosshairs",
25196 value: function getElXCrosshairs() {
25197 return this.w.globals.dom.baseEl.querySelector('.apexcharts-xcrosshairs');
25198 }
25199 }, {
25200 key: "getElGrid",
25201 value: function getElGrid() {
25202 return this.w.globals.dom.baseEl.querySelector('.apexcharts-grid');
25203 }
25204 }, {
25205 key: "drawTooltip",
25206 value: function drawTooltip(xyRatios) {
25207 var w = this.w;
25208 this.xyRatios = xyRatios;
25209 this.isXAxisTooltipEnabled = w.config.xaxis.tooltip.enabled && w.globals.axisCharts;
25210 this.yaxisTooltips = w.config.yaxis.map(function (y, i) {
25211 return y.show && y.tooltip.enabled && w.globals.axisCharts ? true : false;
25212 });
25213 this.allTooltipSeriesGroups = [];
25214 if (!w.globals.axisCharts) {
25215 this.showTooltipTitle = false;
25216 }
25217 var tooltipEl = document.createElement('div');
25218 tooltipEl.classList.add('apexcharts-tooltip');
25219 if (w.config.tooltip.cssClass) {
25220 tooltipEl.classList.add(w.config.tooltip.cssClass);
25221 }
25222 tooltipEl.classList.add("apexcharts-theme-".concat(this.tConfig.theme || 'light'));
25223 w.globals.dom.elWrap.appendChild(tooltipEl);
25224 if (w.globals.axisCharts) {
25225 this.axesTooltip.drawXaxisTooltip();
25226 this.axesTooltip.drawYaxisTooltip();
25227 this.axesTooltip.setXCrosshairWidth();
25228 this.axesTooltip.handleYCrosshair();
25229 var xAxis = new XAxis(this.ctx);
25230 this.xAxisTicksPositions = xAxis.getXAxisTicksPositions();
25231 }
25232
25233 // we forcefully set intersect true for these conditions
25234 if ((w.globals.comboCharts || this.tConfig.intersect || w.config.chart.type === 'rangeBar') && !this.tConfig.shared) {
25235 this.showOnIntersect = true;
25236 }
25237 if (w.config.markers.size === 0 || w.globals.markers.largestSize === 0) {
25238 // when user don't want to show points all the time, but only on when hovering on series
25239 this.marker.drawDynamicPoints(this);
25240 }
25241
25242 // no visible series, exit
25243 if (w.globals.collapsedSeries.length === w.globals.series.length) return;
25244 this.dataPointsDividedHeight = w.globals.gridHeight / w.globals.dataPoints;
25245 this.dataPointsDividedWidth = w.globals.gridWidth / w.globals.dataPoints;
25246 if (this.showTooltipTitle) {
25247 this.tooltipTitle = document.createElement('div');
25248 this.tooltipTitle.classList.add('apexcharts-tooltip-title');
25249 this.tooltipTitle.style.fontFamily = this.tConfig.style.fontFamily || w.config.chart.fontFamily;
25250 this.tooltipTitle.style.fontSize = this.tConfig.style.fontSize;
25251 tooltipEl.appendChild(this.tooltipTitle);
25252 }
25253 var ttItemsCnt = w.globals.series.length; // whether shared or not, default is shared
25254 if ((w.globals.xyCharts || w.globals.comboCharts) && this.tConfig.shared) {
25255 if (!this.showOnIntersect) {
25256 ttItemsCnt = w.globals.series.length;
25257 } else {
25258 ttItemsCnt = 1;
25259 }
25260 }
25261 this.legendLabels = w.globals.dom.baseEl.querySelectorAll('.apexcharts-legend-text');
25262 this.ttItems = this.createTTElements(ttItemsCnt);
25263 this.addSVGEvents();
25264 }
25265 }, {
25266 key: "createTTElements",
25267 value: function createTTElements(ttItemsCnt) {
25268 var _this = this;
25269 var w = this.w;
25270 var ttItems = [];
25271 var tooltipEl = this.getElTooltip();
25272 var _loop = function _loop(i) {
25273 var gTxt = document.createElement('div');
25274 gTxt.classList.add('apexcharts-tooltip-series-group', "apexcharts-tooltip-series-group-".concat(i));
25275 gTxt.style.order = w.config.tooltip.inverseOrder ? ttItemsCnt - i : i + 1;
25276 var point = document.createElement('span');
25277 point.classList.add('apexcharts-tooltip-marker');
25278 if (w.config.tooltip.fillSeriesColor) {
25279 point.style.backgroundColor = w.globals.colors[i];
25280 } else {
25281 point.style.color = w.globals.colors[i];
25282 }
25283 var mShape = w.config.markers.shape;
25284 var shape = mShape;
25285 if (Array.isArray(mShape)) {
25286 shape = mShape[i];
25287 }
25288 point.setAttribute('shape', shape);
25289 gTxt.appendChild(point);
25290 var gYZ = document.createElement('div');
25291 gYZ.classList.add('apexcharts-tooltip-text');
25292 gYZ.style.fontFamily = _this.tConfig.style.fontFamily || w.config.chart.fontFamily;
25293 gYZ.style.fontSize = _this.tConfig.style.fontSize;
25294 ['y', 'goals', 'z'].forEach(function (g) {
25295 var gValText = document.createElement('div');
25296 gValText.classList.add("apexcharts-tooltip-".concat(g, "-group"));
25297 var txtLabel = document.createElement('span');
25298 txtLabel.classList.add("apexcharts-tooltip-text-".concat(g, "-label"));
25299 gValText.appendChild(txtLabel);
25300 var txtValue = document.createElement('span');
25301 txtValue.classList.add("apexcharts-tooltip-text-".concat(g, "-value"));
25302 gValText.appendChild(txtValue);
25303 gYZ.appendChild(gValText);
25304 });
25305 gTxt.appendChild(gYZ);
25306 tooltipEl.appendChild(gTxt);
25307 ttItems.push(gTxt);
25308 };
25309 for (var i = 0; i < ttItemsCnt; i++) {
25310 _loop(i);
25311 }
25312 return ttItems;
25313 }
25314 }, {
25315 key: "addSVGEvents",
25316 value: function addSVGEvents() {
25317 var w = this.w;
25318 var type = w.config.chart.type;
25319 var tooltipEl = this.getElTooltip();
25320 var commonBar = !!(type === 'bar' || type === 'candlestick' || type === 'boxPlot' || type === 'rangeBar');
25321 var chartWithmarkers = type === 'area' || type === 'line' || type === 'scatter' || type === 'bubble' || type === 'radar';
25322 var hoverArea = w.globals.dom.Paper.node;
25323 var elGrid = this.getElGrid();
25324 if (elGrid) {
25325 this.seriesBound = elGrid.getBoundingClientRect();
25326 }
25327 var tooltipY = [];
25328 var tooltipX = [];
25329 var seriesHoverParams = {
25330 hoverArea: hoverArea,
25331 elGrid: elGrid,
25332 tooltipEl: tooltipEl,
25333 tooltipY: tooltipY,
25334 tooltipX: tooltipX,
25335 ttItems: this.ttItems
25336 };
25337 var points;
25338 if (w.globals.axisCharts) {
25339 if (chartWithmarkers) {
25340 points = w.globals.dom.baseEl.querySelectorAll(".apexcharts-series[data\\:longestSeries='true'] .apexcharts-marker");
25341 } else if (commonBar) {
25342 points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series .apexcharts-bar-area, .apexcharts-series .apexcharts-candlestick-area, .apexcharts-series .apexcharts-boxPlot-area, .apexcharts-series .apexcharts-rangebar-area');
25343 } else if (type === 'heatmap' || type === 'treemap') {
25344 points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series .apexcharts-heatmap, .apexcharts-series .apexcharts-treemap');
25345 }
25346 if (points && points.length) {
25347 for (var p = 0; p < points.length; p++) {
25348 tooltipY.push(points[p].getAttribute('cy'));
25349 tooltipX.push(points[p].getAttribute('cx'));
25350 }
25351 }
25352 }
25353 var validSharedChartTypes = w.globals.xyCharts && !this.showOnIntersect || w.globals.comboCharts && !this.showOnIntersect || commonBar && this.tooltipUtil.hasBars() && this.tConfig.shared;
25354 if (validSharedChartTypes) {
25355 this.addPathsEventListeners([hoverArea], seriesHoverParams);
25356 } else if (commonBar && !w.globals.comboCharts || chartWithmarkers && this.showOnIntersect) {
25357 this.addDatapointEventsListeners(seriesHoverParams);
25358 } else if (!w.globals.axisCharts || type === 'heatmap' || type === 'treemap') {
25359 var seriesAll = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series');
25360 this.addPathsEventListeners(seriesAll, seriesHoverParams);
25361 }
25362 if (this.showOnIntersect) {
25363 var lineAreaPoints = w.globals.dom.baseEl.querySelectorAll('.apexcharts-line-series .apexcharts-marker, .apexcharts-area-series .apexcharts-marker');
25364 if (lineAreaPoints.length > 0) {
25365 // if we find any lineSeries, addEventListeners for them
25366 this.addPathsEventListeners(lineAreaPoints, seriesHoverParams);
25367 }
25368
25369 // combo charts may have bars, so add event listeners here too
25370 if (this.tooltipUtil.hasBars() && !this.tConfig.shared) {
25371 this.addDatapointEventsListeners(seriesHoverParams);
25372 }
25373 }
25374 }
25375 }, {
25376 key: "drawFixedTooltipRect",
25377 value: function drawFixedTooltipRect() {
25378 var w = this.w;
25379 var tooltipEl = this.getElTooltip();
25380 var tooltipRect = tooltipEl.getBoundingClientRect();
25381 var ttWidth = tooltipRect.width + 10;
25382 var ttHeight = tooltipRect.height + 10;
25383 var x = this.tConfig.fixed.offsetX;
25384 var y = this.tConfig.fixed.offsetY;
25385 var fixed = this.tConfig.fixed.position.toLowerCase();
25386 if (fixed.indexOf('right') > -1) {
25387 x = x + w.globals.svgWidth - ttWidth + 10;
25388 }
25389 if (fixed.indexOf('bottom') > -1) {
25390 y = y + w.globals.svgHeight - ttHeight - 10;
25391 }
25392 tooltipEl.style.left = x + 'px';
25393 tooltipEl.style.top = y + 'px';
25394 return {
25395 x: x,
25396 y: y,
25397 ttWidth: ttWidth,
25398 ttHeight: ttHeight
25399 };
25400 }
25401 }, {
25402 key: "addDatapointEventsListeners",
25403 value: function addDatapointEventsListeners(seriesHoverParams) {
25404 var w = this.w;
25405 var points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series-markers .apexcharts-marker, .apexcharts-bar-area, .apexcharts-candlestick-area, .apexcharts-boxPlot-area, .apexcharts-rangebar-area');
25406 this.addPathsEventListeners(points, seriesHoverParams);
25407 }
25408 }, {
25409 key: "addPathsEventListeners",
25410 value: function addPathsEventListeners(paths, opts) {
25411 var self = this;
25412 var _loop2 = function _loop2(p) {
25413 var extendedOpts = {
25414 paths: paths[p],
25415 tooltipEl: opts.tooltipEl,
25416 tooltipY: opts.tooltipY,
25417 tooltipX: opts.tooltipX,
25418 elGrid: opts.elGrid,
25419 hoverArea: opts.hoverArea,
25420 ttItems: opts.ttItems
25421 };
25422 var events = ['mousemove', 'mouseup', 'touchmove', 'mouseout', 'touchend'];
25423 events.map(function (ev) {
25424 return paths[p].addEventListener(ev, self.onSeriesHover.bind(self, extendedOpts), {
25425 capture: false,
25426 passive: true
25427 });
25428 });
25429 };
25430 for (var p = 0; p < paths.length; p++) {
25431 _loop2(p);
25432 }
25433 }
25434
25435 /*
25436 ** Check to see if the tooltips should be updated based on a mouse / touch event
25437 */
25438 }, {
25439 key: "onSeriesHover",
25440 value: function onSeriesHover(opt, e) {
25441 var _this2 = this;
25442 // If a user is moving their mouse quickly, don't bother updating the tooltip every single frame
25443
25444 var targetDelay = 20;
25445 var timeSinceLastUpdate = Date.now() - this.lastHoverTime;
25446 if (timeSinceLastUpdate >= targetDelay) {
25447 // The tooltip was last updated over 100ms ago - redraw it even if the user is still moving their
25448 // mouse so they get some feedback that their moves are being registered
25449 this.seriesHover(opt, e);
25450 } else {
25451 // The tooltip was last updated less than 100ms ago
25452 // Cancel any other delayed draw, so we don't show stale data
25453 clearTimeout(this.seriesHoverTimeout);
25454
25455 // Schedule the next draw so that it happens about 100ms after the last update
25456 this.seriesHoverTimeout = setTimeout(function () {
25457 _this2.seriesHover(opt, e);
25458 }, targetDelay - timeSinceLastUpdate);
25459 }
25460 }
25461
25462 /*
25463 ** The actual series hover function
25464 */
25465 }, {
25466 key: "seriesHover",
25467 value: function seriesHover(opt, e) {
25468 var _this3 = this;
25469 this.lastHoverTime = Date.now();
25470 var chartGroups = [];
25471 var w = this.w;
25472
25473 // if user has more than one charts in group, we need to sync
25474 if (w.config.chart.group) {
25475 chartGroups = this.ctx.getGroupedCharts();
25476 }
25477 if (w.globals.axisCharts && (w.globals.minX === -Infinity && w.globals.maxX === Infinity || w.globals.dataPoints === 0)) {
25478 return;
25479 }
25480 if (chartGroups.length) {
25481 chartGroups.forEach(function (ch) {
25482 var tooltipEl = _this3.getElTooltip(ch);
25483 var newOpts = {
25484 paths: opt.paths,
25485 tooltipEl: tooltipEl,
25486 tooltipY: opt.tooltipY,
25487 tooltipX: opt.tooltipX,
25488 elGrid: opt.elGrid,
25489 hoverArea: opt.hoverArea,
25490 ttItems: ch.w.globals.tooltip.ttItems
25491 };
25492
25493 // all the charts should have the same minX and maxX (same xaxis) for multiple tooltips to work correctly
25494 if (ch.w.globals.minX === _this3.w.globals.minX && ch.w.globals.maxX === _this3.w.globals.maxX) {
25495 ch.w.globals.tooltip.seriesHoverByContext({
25496 chartCtx: ch,
25497 ttCtx: ch.w.globals.tooltip,
25498 opt: newOpts,
25499 e: e
25500 });
25501 }
25502 });
25503 } else {
25504 this.seriesHoverByContext({
25505 chartCtx: this.ctx,
25506 ttCtx: this.w.globals.tooltip,
25507 opt: opt,
25508 e: e
25509 });
25510 }
25511 }
25512 }, {
25513 key: "seriesHoverByContext",
25514 value: function seriesHoverByContext(_ref) {
25515 var chartCtx = _ref.chartCtx,
25516 ttCtx = _ref.ttCtx,
25517 opt = _ref.opt,
25518 e = _ref.e;
25519 var w = chartCtx.w;
25520 var tooltipEl = this.getElTooltip(chartCtx);
25521 if (!tooltipEl) return;
25522
25523 // tooltipRect is calculated on every mousemove, because the text is dynamic
25524 ttCtx.tooltipRect = {
25525 x: 0,
25526 y: 0,
25527 ttWidth: tooltipEl.getBoundingClientRect().width,
25528 ttHeight: tooltipEl.getBoundingClientRect().height
25529 };
25530 ttCtx.e = e;
25531
25532 // highlight the current hovered bars
25533 if (ttCtx.tooltipUtil.hasBars() && !w.globals.comboCharts && !ttCtx.isBarShared) {
25534 if (this.tConfig.onDatasetHover.highlightDataSeries) {
25535 var series = new Series(chartCtx);
25536 series.toggleSeriesOnHover(e, e.target.parentNode);
25537 }
25538 }
25539 if (w.globals.axisCharts) {
25540 ttCtx.axisChartsTooltips({
25541 e: e,
25542 opt: opt,
25543 tooltipRect: ttCtx.tooltipRect
25544 });
25545 } else {
25546 // non-plot charts i.e pie/donut/circle
25547 ttCtx.nonAxisChartsTooltips({
25548 e: e,
25549 opt: opt,
25550 tooltipRect: ttCtx.tooltipRect
25551 });
25552 }
25553 if (ttCtx.fixedTooltip) {
25554 ttCtx.drawFixedTooltipRect();
25555 }
25556 }
25557
25558 // tooltip handling for line/area/bar/columns/scatter
25559 }, {
25560 key: "axisChartsTooltips",
25561 value: function axisChartsTooltips(_ref2) {
25562 var e = _ref2.e,
25563 opt = _ref2.opt;
25564 var w = this.w;
25565 var x, y;
25566 var seriesBound = opt.elGrid.getBoundingClientRect();
25567 var clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
25568 var clientY = e.type === 'touchmove' ? e.touches[0].clientY : e.clientY;
25569 this.clientY = clientY;
25570 this.clientX = clientX;
25571 w.globals.capturedSeriesIndex = -1;
25572 w.globals.capturedDataPointIndex = -1;
25573 if (clientY < seriesBound.top || clientY > seriesBound.top + seriesBound.height) {
25574 this.handleMouseOut(opt);
25575 return;
25576 }
25577 if (Array.isArray(this.tConfig.enabledOnSeries) && !w.config.tooltip.shared) {
25578 var index = parseInt(opt.paths.getAttribute('index'), 10);
25579 if (this.tConfig.enabledOnSeries.indexOf(index) < 0) {
25580 this.handleMouseOut(opt);
25581 return;
25582 }
25583 }
25584 var tooltipEl = this.getElTooltip();
25585 var xcrosshairs = this.getElXCrosshairs();
25586 var syncedCharts = [];
25587 if (w.config.chart.group) {
25588 // we need to fallback to sticky tooltip in case charts are synced
25589 syncedCharts = this.ctx.getSyncedCharts();
25590 }
25591 var isStickyTooltip = w.globals.xyCharts || w.config.chart.type === 'bar' && !w.globals.isBarHorizontal && this.tooltipUtil.hasBars() && this.tConfig.shared || w.globals.comboCharts && this.tooltipUtil.hasBars();
25592 if (e.type === 'mousemove' || e.type === 'touchmove' || e.type === 'mouseup') {
25593 // there is no series to hover over
25594 if (w.globals.collapsedSeries.length + w.globals.ancillaryCollapsedSeries.length === w.globals.series.length) {
25595 return;
25596 }
25597 if (xcrosshairs !== null) {
25598 xcrosshairs.classList.add('apexcharts-active');
25599 }
25600 var hasYAxisTooltip = this.yaxisTooltips.filter(function (b) {
25601 return b === true;
25602 });
25603 if (this.ycrosshairs !== null && hasYAxisTooltip.length) {
25604 this.ycrosshairs.classList.add('apexcharts-active');
25605 }
25606 if (isStickyTooltip && !this.showOnIntersect || syncedCharts.length > 1) {
25607 this.handleStickyTooltip(e, clientX, clientY, opt);
25608 } else {
25609 if (w.config.chart.type === 'heatmap' || w.config.chart.type === 'treemap') {
25610 var markerXY = this.intersect.handleHeatTreeTooltip({
25611 e: e,
25612 opt: opt,
25613 x: x,
25614 y: y,
25615 type: w.config.chart.type
25616 });
25617 x = markerXY.x;
25618 y = markerXY.y;
25619 tooltipEl.style.left = x + 'px';
25620 tooltipEl.style.top = y + 'px';
25621 } else {
25622 if (this.tooltipUtil.hasBars()) {
25623 this.intersect.handleBarTooltip({
25624 e: e,
25625 opt: opt
25626 });
25627 }
25628 if (this.tooltipUtil.hasMarkers()) {
25629 // intersect - line/area/scatter/bubble
25630 this.intersect.handleMarkerTooltip({
25631 e: e,
25632 opt: opt,
25633 x: x,
25634 y: y
25635 });
25636 }
25637 }
25638 }
25639 if (this.yaxisTooltips.length) {
25640 for (var yt = 0; yt < w.config.yaxis.length; yt++) {
25641 this.axesTooltip.drawYaxisTooltipText(yt, clientY, this.xyRatios);
25642 }
25643 }
25644 w.globals.dom.baseEl.classList.add('apexcharts-tooltip-active');
25645 opt.tooltipEl.classList.add('apexcharts-active');
25646 } else if (e.type === 'mouseout' || e.type === 'touchend') {
25647 this.handleMouseOut(opt);
25648 }
25649 }
25650
25651 // tooltip handling for pie/donuts
25652 }, {
25653 key: "nonAxisChartsTooltips",
25654 value: function nonAxisChartsTooltips(_ref3) {
25655 var e = _ref3.e,
25656 opt = _ref3.opt,
25657 tooltipRect = _ref3.tooltipRect;
25658 var w = this.w;
25659 var rel = opt.paths.getAttribute('rel');
25660 var tooltipEl = this.getElTooltip();
25661 var seriesBound = w.globals.dom.elWrap.getBoundingClientRect();
25662 if (e.type === 'mousemove' || e.type === 'touchmove') {
25663 w.globals.dom.baseEl.classList.add('apexcharts-tooltip-active');
25664 tooltipEl.classList.add('apexcharts-active');
25665 this.tooltipLabels.drawSeriesTexts({
25666 ttItems: opt.ttItems,
25667 i: parseInt(rel, 10) - 1,
25668 shared: false
25669 });
25670 var x = w.globals.clientX - seriesBound.left - tooltipRect.ttWidth / 2;
25671 var y = w.globals.clientY - seriesBound.top - tooltipRect.ttHeight - 10;
25672 tooltipEl.style.left = x + 'px';
25673 tooltipEl.style.top = y + 'px';
25674 if (w.config.legend.tooltipHoverFormatter) {
25675 var legendFormatter = w.config.legend.tooltipHoverFormatter;
25676 var i = rel - 1;
25677 var legendName = this.legendLabels[i].getAttribute('data:default-text');
25678 var text = legendFormatter(legendName, {
25679 seriesIndex: i,
25680 dataPointIndex: i,
25681 w: w
25682 });
25683 this.legendLabels[i].innerHTML = text;
25684 }
25685 } else if (e.type === 'mouseout' || e.type === 'touchend') {
25686 tooltipEl.classList.remove('apexcharts-active');
25687 w.globals.dom.baseEl.classList.remove('apexcharts-tooltip-active');
25688 if (w.config.legend.tooltipHoverFormatter) {
25689 this.legendLabels.forEach(function (l) {
25690 var defaultText = l.getAttribute('data:default-text');
25691 l.innerHTML = decodeURIComponent(defaultText);
25692 });
25693 }
25694 }
25695 }
25696 }, {
25697 key: "handleStickyTooltip",
25698 value: function handleStickyTooltip(e, clientX, clientY, opt) {
25699 var w = this.w;
25700 var capj = this.tooltipUtil.getNearestValues({
25701 context: this,
25702 hoverArea: opt.hoverArea,
25703 elGrid: opt.elGrid,
25704 clientX: clientX,
25705 clientY: clientY
25706 });
25707 var j = capj.j;
25708 var capturedSeries = capj.capturedSeries;
25709 if (w.globals.collapsedSeriesIndices.includes(capturedSeries)) capturedSeries = null;
25710 var bounds = opt.elGrid.getBoundingClientRect();
25711 if (capj.hoverX < 0 || capj.hoverX > bounds.width) {
25712 this.handleMouseOut(opt);
25713 return;
25714 }
25715 if (capturedSeries !== null) {
25716 this.handleStickyCapturedSeries(e, capturedSeries, opt, j);
25717 } else {
25718 // couldn't capture any series. check if shared X is same,
25719 // if yes, draw a grouped tooltip
25720 if (this.tooltipUtil.isXoverlap(j) || w.globals.isBarHorizontal) {
25721 var firstVisibleSeries = w.globals.series.findIndex(function (s, i) {
25722 return !w.globals.collapsedSeriesIndices.includes(i);
25723 });
25724 this.create(e, this, firstVisibleSeries, j, opt.ttItems);
25725 }
25726 }
25727 }
25728 }, {
25729 key: "handleStickyCapturedSeries",
25730 value: function handleStickyCapturedSeries(e, capturedSeries, opt, j) {
25731 var w = this.w;
25732 if (!this.tConfig.shared) {
25733 var ignoreNull = w.globals.series[capturedSeries][j] === null;
25734 if (ignoreNull) {
25735 this.handleMouseOut(opt);
25736 return;
25737 }
25738 }
25739 if (typeof w.globals.series[capturedSeries][j] !== 'undefined') {
25740 if (this.tConfig.shared && this.tooltipUtil.isXoverlap(j) && this.tooltipUtil.isInitialSeriesSameLen()) {
25741 this.create(e, this, capturedSeries, j, opt.ttItems);
25742 } else {
25743 this.create(e, this, capturedSeries, j, opt.ttItems, false);
25744 }
25745 } else {
25746 if (this.tooltipUtil.isXoverlap(j)) {
25747 var firstVisibleSeries = w.globals.series.findIndex(function (s, i) {
25748 return !w.globals.collapsedSeriesIndices.includes(i);
25749 });
25750 this.create(e, this, firstVisibleSeries, j, opt.ttItems);
25751 }
25752 }
25753 }
25754 }, {
25755 key: "deactivateHoverFilter",
25756 value: function deactivateHoverFilter() {
25757 var w = this.w;
25758 var graphics = new Graphics(this.ctx);
25759 var allPaths = w.globals.dom.Paper.find(".apexcharts-bar-area");
25760 for (var b = 0; b < allPaths.length; b++) {
25761 graphics.pathMouseLeave(allPaths[b]);
25762 }
25763 }
25764 }, {
25765 key: "handleMouseOut",
25766 value: function handleMouseOut(opt) {
25767 var w = this.w;
25768 var xcrosshairs = this.getElXCrosshairs();
25769 w.globals.dom.baseEl.classList.remove('apexcharts-tooltip-active');
25770 opt.tooltipEl.classList.remove('apexcharts-active');
25771 this.deactivateHoverFilter();
25772 if (w.config.chart.type !== 'bubble') {
25773 this.marker.resetPointsSize();
25774 }
25775 if (xcrosshairs !== null) {
25776 xcrosshairs.classList.remove('apexcharts-active');
25777 }
25778 if (this.ycrosshairs !== null) {
25779 this.ycrosshairs.classList.remove('apexcharts-active');
25780 }
25781 if (this.isXAxisTooltipEnabled) {
25782 this.xaxisTooltip.classList.remove('apexcharts-active');
25783 }
25784 if (this.yaxisTooltips.length) {
25785 if (this.yaxisTTEls === null) {
25786 this.yaxisTTEls = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxistooltip');
25787 }
25788 for (var i = 0; i < this.yaxisTTEls.length; i++) {
25789 this.yaxisTTEls[i].classList.remove('apexcharts-active');
25790 }
25791 }
25792 if (w.config.legend.tooltipHoverFormatter) {
25793 this.legendLabels.forEach(function (l) {
25794 var defaultText = l.getAttribute('data:default-text');
25795 l.innerHTML = decodeURIComponent(defaultText);
25796 });
25797 }
25798 }
25799 }, {
25800 key: "markerClick",
25801 value: function markerClick(e, seriesIndex, dataPointIndex) {
25802 var w = this.w;
25803 if (typeof w.config.chart.events.markerClick === 'function') {
25804 w.config.chart.events.markerClick(e, this.ctx, {
25805 seriesIndex: seriesIndex,
25806 dataPointIndex: dataPointIndex,
25807 w: w
25808 });
25809 }
25810 this.ctx.events.fireEvent('markerClick', [e, this.ctx, {
25811 seriesIndex: seriesIndex,
25812 dataPointIndex: dataPointIndex,
25813 w: w
25814 }]);
25815 }
25816 }, {
25817 key: "create",
25818 value: function create(e, context, capturedSeries, j, ttItems) {
25819 var _w$globals$seriesRang, _w$globals$seriesRang2, _w$globals$seriesRang3, _w$globals$seriesRang4, _w$globals$seriesRang5, _w$globals$seriesRang6, _w$globals$seriesRang7, _w$globals$seriesRang8, _w$globals$seriesRang9, _w$globals$seriesRang10, _w$globals$seriesRang11, _w$globals$seriesRang12, _w$globals$seriesRang13, _w$globals$seriesRang14, _w$globals$seriesRang15, _w$globals$seriesRang16;
25820 var shared = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
25821 var w = this.w;
25822 var ttCtx = context;
25823 if (e.type === 'mouseup') {
25824 this.markerClick(e, capturedSeries, j);
25825 }
25826 if (shared === null) shared = this.tConfig.shared;
25827 var hasMarkers = this.tooltipUtil.hasMarkers(capturedSeries);
25828 var bars = this.tooltipUtil.getElBars();
25829 var handlePoints = function handlePoints() {
25830 if (w.globals.markers.largestSize > 0) {
25831 ttCtx.marker.enlargePoints(j);
25832 } else {
25833 ttCtx.tooltipPosition.moveDynamicPointsOnHover(j);
25834 }
25835 };
25836 if (w.config.legend.tooltipHoverFormatter) {
25837 var legendFormatter = w.config.legend.tooltipHoverFormatter;
25838 var els = Array.from(this.legendLabels);
25839
25840 // reset all legend values first
25841 els.forEach(function (l) {
25842 var legendName = l.getAttribute('data:default-text');
25843 l.innerHTML = decodeURIComponent(legendName);
25844 });
25845
25846 // for irregular time series
25847 for (var i = 0; i < els.length; i++) {
25848 var l = els[i];
25849 var lsIndex = parseInt(l.getAttribute('i'), 10);
25850 var legendName = decodeURIComponent(l.getAttribute('data:default-text'));
25851 var text = legendFormatter(legendName, {
25852 seriesIndex: shared ? lsIndex : capturedSeries,
25853 dataPointIndex: j,
25854 w: w
25855 });
25856 if (!shared) {
25857 l.innerHTML = lsIndex === capturedSeries ? text : legendName;
25858 if (capturedSeries === lsIndex) {
25859 break;
25860 }
25861 } else {
25862 l.innerHTML = w.globals.collapsedSeriesIndices.indexOf(lsIndex) < 0 ? text : legendName;
25863 }
25864 }
25865 }
25866 var commonSeriesTextsParams = _objectSpread2(_objectSpread2({
25867 ttItems: ttItems,
25868 i: capturedSeries,
25869 j: j
25870 }, typeof ((_w$globals$seriesRang = w.globals.seriesRange) === null || _w$globals$seriesRang === void 0 ? void 0 : (_w$globals$seriesRang2 = _w$globals$seriesRang[capturedSeries]) === null || _w$globals$seriesRang2 === void 0 ? void 0 : (_w$globals$seriesRang3 = _w$globals$seriesRang2[j]) === null || _w$globals$seriesRang3 === void 0 ? void 0 : (_w$globals$seriesRang4 = _w$globals$seriesRang3.y[0]) === null || _w$globals$seriesRang4 === void 0 ? void 0 : _w$globals$seriesRang4.y1) !== 'undefined' && {
25871 y1: (_w$globals$seriesRang5 = w.globals.seriesRange) === null || _w$globals$seriesRang5 === void 0 ? void 0 : (_w$globals$seriesRang6 = _w$globals$seriesRang5[capturedSeries]) === null || _w$globals$seriesRang6 === void 0 ? void 0 : (_w$globals$seriesRang7 = _w$globals$seriesRang6[j]) === null || _w$globals$seriesRang7 === void 0 ? void 0 : (_w$globals$seriesRang8 = _w$globals$seriesRang7.y[0]) === null || _w$globals$seriesRang8 === void 0 ? void 0 : _w$globals$seriesRang8.y1
25872 }), typeof ((_w$globals$seriesRang9 = w.globals.seriesRange) === null || _w$globals$seriesRang9 === void 0 ? void 0 : (_w$globals$seriesRang10 = _w$globals$seriesRang9[capturedSeries]) === null || _w$globals$seriesRang10 === void 0 ? void 0 : (_w$globals$seriesRang11 = _w$globals$seriesRang10[j]) === null || _w$globals$seriesRang11 === void 0 ? void 0 : (_w$globals$seriesRang12 = _w$globals$seriesRang11.y[0]) === null || _w$globals$seriesRang12 === void 0 ? void 0 : _w$globals$seriesRang12.y2) !== 'undefined' && {
25873 y2: (_w$globals$seriesRang13 = w.globals.seriesRange) === null || _w$globals$seriesRang13 === void 0 ? void 0 : (_w$globals$seriesRang14 = _w$globals$seriesRang13[capturedSeries]) === null || _w$globals$seriesRang14 === void 0 ? void 0 : (_w$globals$seriesRang15 = _w$globals$seriesRang14[j]) === null || _w$globals$seriesRang15 === void 0 ? void 0 : (_w$globals$seriesRang16 = _w$globals$seriesRang15.y[0]) === null || _w$globals$seriesRang16 === void 0 ? void 0 : _w$globals$seriesRang16.y2
25874 });
25875 if (shared) {
25876 ttCtx.tooltipLabels.drawSeriesTexts(_objectSpread2(_objectSpread2({}, commonSeriesTextsParams), {}, {
25877 shared: this.showOnIntersect ? false : this.tConfig.shared
25878 }));
25879 if (hasMarkers) {
25880 handlePoints();
25881 } else if (this.tooltipUtil.hasBars()) {
25882 this.barSeriesHeight = this.tooltipUtil.getBarsHeight(bars);
25883 if (this.barSeriesHeight > 0) {
25884 // hover state, activate snap filter
25885 var graphics = new Graphics(this.ctx);
25886 var paths = w.globals.dom.Paper.find(".apexcharts-bar-area[j='".concat(j, "']"));
25887
25888 // de-activate first
25889 this.deactivateHoverFilter();
25890 var points = ttCtx.tooltipUtil.getAllMarkers(true);
25891 if (points.length && !this.barSeriesHeight) {
25892 handlePoints();
25893 }
25894 ttCtx.tooltipPosition.moveStickyTooltipOverBars(j, capturedSeries);
25895 for (var b = 0; b < paths.length; b++) {
25896 graphics.pathMouseEnter(paths[b]);
25897 }
25898 }
25899 }
25900 } else {
25901 ttCtx.tooltipLabels.drawSeriesTexts(_objectSpread2({
25902 shared: false
25903 }, commonSeriesTextsParams));
25904 if (this.tooltipUtil.hasBars()) {
25905 ttCtx.tooltipPosition.moveStickyTooltipOverBars(j, capturedSeries);
25906 }
25907 if (hasMarkers) {
25908 ttCtx.tooltipPosition.moveMarkers(capturedSeries, j);
25909 }
25910 }
25911 }
25912 }]);
25913 return Tooltip;
25914 }();
25915
25916 var BarDataLabels = /*#__PURE__*/function () {
25917 function BarDataLabels(barCtx) {
25918 _classCallCheck(this, BarDataLabels);
25919 this.w = barCtx.w;
25920 this.barCtx = barCtx;
25921 this.totalFormatter = this.w.config.plotOptions.bar.dataLabels.total.formatter;
25922 if (!this.totalFormatter) {
25923 this.totalFormatter = this.w.config.dataLabels.formatter;
25924 }
25925 }
25926 /** handleBarDataLabels is used to calculate the positions for the data-labels
25927 * It also sets the element's data attr for bars and calls drawCalculatedBarDataLabels()
25928 * After calculating, it also calls the function to draw data labels
25929 * @memberof Bar
25930 * @param {object} {barProps} most of the bar properties used throughout the bar
25931 * drawing function
25932 * @return {object} dataLabels node-element which you can append later
25933 **/
25934 _createClass(BarDataLabels, [{
25935 key: "handleBarDataLabels",
25936 value: function handleBarDataLabels(opts) {
25937 var x = opts.x,
25938 y = opts.y,
25939 y1 = opts.y1,
25940 y2 = opts.y2,
25941 i = opts.i,
25942 j = opts.j,
25943 realIndex = opts.realIndex,
25944 columnGroupIndex = opts.columnGroupIndex,
25945 series = opts.series,
25946 barHeight = opts.barHeight,
25947 barWidth = opts.barWidth,
25948 barXPosition = opts.barXPosition,
25949 barYPosition = opts.barYPosition,
25950 visibleSeries = opts.visibleSeries;
25951 var w = this.w;
25952 var graphics = new Graphics(this.barCtx.ctx);
25953 var strokeWidth = Array.isArray(this.barCtx.strokeWidth) ? this.barCtx.strokeWidth[realIndex] : this.barCtx.strokeWidth;
25954 var bcx;
25955 var bcy;
25956 if (w.globals.isXNumeric && !w.globals.isBarHorizontal) {
25957 bcx = x + parseFloat(barWidth * (visibleSeries + 1));
25958 bcy = y + parseFloat(barHeight * (visibleSeries + 1)) - strokeWidth;
25959 } else {
25960 bcx = x + parseFloat(barWidth * visibleSeries);
25961 bcy = y + parseFloat(barHeight * visibleSeries);
25962 }
25963 var dataLabels = null;
25964 var totalDataLabels = null;
25965 var dataLabelsX = x;
25966 var dataLabelsY = y;
25967 var dataLabelsPos = {};
25968 var dataLabelsConfig = w.config.dataLabels;
25969 var barDataLabelsConfig = this.barCtx.barOptions.dataLabels;
25970 var barTotalDataLabelsConfig = this.barCtx.barOptions.dataLabels.total;
25971 if (typeof barYPosition !== 'undefined' && this.barCtx.isRangeBar) {
25972 bcy = barYPosition;
25973 dataLabelsY = barYPosition;
25974 }
25975 if (typeof barXPosition !== 'undefined' && this.barCtx.isVerticalGroupedRangeBar) {
25976 bcx = barXPosition;
25977 dataLabelsX = barXPosition;
25978 }
25979 var offX = dataLabelsConfig.offsetX;
25980 var offY = dataLabelsConfig.offsetY;
25981 var textRects = {
25982 width: 0,
25983 height: 0
25984 };
25985 if (w.config.dataLabels.enabled) {
25986 var yLabel = w.globals.series[i][j];
25987 textRects = graphics.getTextRects(w.config.dataLabels.formatter ? w.config.dataLabels.formatter(yLabel, _objectSpread2(_objectSpread2({}, w), {}, {
25988 seriesIndex: i,
25989 dataPointIndex: j,
25990 w: w
25991 })) : w.globals.yLabelFormatters[0](yLabel), parseFloat(dataLabelsConfig.style.fontSize));
25992 }
25993 var params = {
25994 x: x,
25995 y: y,
25996 i: i,
25997 j: j,
25998 realIndex: realIndex,
25999 columnGroupIndex: columnGroupIndex,
26000 bcx: bcx,
26001 bcy: bcy,
26002 barHeight: barHeight,
26003 barWidth: barWidth,
26004 textRects: textRects,
26005 strokeWidth: strokeWidth,
26006 dataLabelsX: dataLabelsX,
26007 dataLabelsY: dataLabelsY,
26008 dataLabelsConfig: dataLabelsConfig,
26009 barDataLabelsConfig: barDataLabelsConfig,
26010 barTotalDataLabelsConfig: barTotalDataLabelsConfig,
26011 offX: offX,
26012 offY: offY
26013 };
26014 if (this.barCtx.isHorizontal) {
26015 dataLabelsPos = this.calculateBarsDataLabelsPosition(params);
26016 } else {
26017 dataLabelsPos = this.calculateColumnsDataLabelsPosition(params);
26018 }
26019 dataLabels = this.drawCalculatedDataLabels({
26020 x: dataLabelsPos.dataLabelsX,
26021 y: dataLabelsPos.dataLabelsY,
26022 val: this.barCtx.isRangeBar ? [y1, y2] : w.config.chart.stackType === '100%' ? series[realIndex][j] : w.globals.series[realIndex][j],
26023 i: realIndex,
26024 j: j,
26025 barWidth: barWidth,
26026 barHeight: barHeight,
26027 textRects: textRects,
26028 dataLabelsConfig: dataLabelsConfig
26029 });
26030 if (w.config.chart.stacked && barTotalDataLabelsConfig.enabled) {
26031 totalDataLabels = this.drawTotalDataLabels({
26032 x: dataLabelsPos.totalDataLabelsX,
26033 y: dataLabelsPos.totalDataLabelsY,
26034 barWidth: barWidth,
26035 barHeight: barHeight,
26036 realIndex: realIndex,
26037 textAnchor: dataLabelsPos.totalDataLabelsAnchor,
26038 val: this.getStackedTotalDataLabel({
26039 realIndex: realIndex,
26040 j: j
26041 }),
26042 dataLabelsConfig: dataLabelsConfig,
26043 barTotalDataLabelsConfig: barTotalDataLabelsConfig
26044 });
26045 }
26046 return {
26047 dataLabelsPos: dataLabelsPos,
26048 dataLabels: dataLabels,
26049 totalDataLabels: totalDataLabels
26050 };
26051 }
26052 }, {
26053 key: "getStackedTotalDataLabel",
26054 value: function getStackedTotalDataLabel(_ref) {
26055 var realIndex = _ref.realIndex,
26056 j = _ref.j;
26057 var w = this.w;
26058 var val = this.barCtx.stackedSeriesTotals[j];
26059 if (this.totalFormatter) {
26060 val = this.totalFormatter(val, _objectSpread2(_objectSpread2({}, w), {}, {
26061 seriesIndex: realIndex,
26062 dataPointIndex: j,
26063 w: w
26064 }));
26065 }
26066 return val;
26067 }
26068 }, {
26069 key: "calculateColumnsDataLabelsPosition",
26070 value: function calculateColumnsDataLabelsPosition(opts) {
26071 var _this = this;
26072 var w = this.w;
26073 var i = opts.i,
26074 j = opts.j,
26075 realIndex = opts.realIndex;
26076 opts.columnGroupIndex;
26077 var y = opts.y,
26078 bcx = opts.bcx,
26079 barWidth = opts.barWidth,
26080 barHeight = opts.barHeight,
26081 textRects = opts.textRects,
26082 dataLabelsX = opts.dataLabelsX,
26083 dataLabelsY = opts.dataLabelsY,
26084 dataLabelsConfig = opts.dataLabelsConfig,
26085 barDataLabelsConfig = opts.barDataLabelsConfig,
26086 barTotalDataLabelsConfig = opts.barTotalDataLabelsConfig,
26087 strokeWidth = opts.strokeWidth,
26088 offX = opts.offX,
26089 offY = opts.offY;
26090 var totalDataLabelsY;
26091 var totalDataLabelsX;
26092 var totalDataLabelsAnchor = 'middle';
26093 var totalDataLabelsBcx = bcx;
26094 barHeight = Math.abs(barHeight);
26095 var vertical = w.config.plotOptions.bar.dataLabels.orientation === 'vertical';
26096 var _this$barCtx$barHelpe = this.barCtx.barHelpers.getZeroValueEncounters({
26097 i: i,
26098 j: j
26099 }),
26100 zeroEncounters = _this$barCtx$barHelpe.zeroEncounters;
26101 bcx = bcx - strokeWidth / 2;
26102 var dataPointsDividedWidth = w.globals.gridWidth / w.globals.dataPoints;
26103 if (this.barCtx.isVerticalGroupedRangeBar) {
26104 dataLabelsX += barWidth / 2;
26105 } else {
26106 if (w.globals.isXNumeric) {
26107 dataLabelsX = bcx - barWidth / 2 + offX;
26108 } else {
26109 dataLabelsX = bcx - dataPointsDividedWidth + barWidth / 2 + offX;
26110 }
26111 if (!w.config.chart.stacked && zeroEncounters > 0 && w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
26112 dataLabelsX -= barWidth * zeroEncounters;
26113 }
26114 }
26115 if (vertical) {
26116 var offsetDLX = 2;
26117 dataLabelsX = dataLabelsX + textRects.height / 2 - strokeWidth / 2 - offsetDLX;
26118 }
26119 var valIsNegative = w.globals.series[i][j] < 0;
26120 var newY = y;
26121 if (this.barCtx.isReversed) {
26122 newY = y + (valIsNegative ? barHeight : -barHeight);
26123 }
26124 switch (barDataLabelsConfig.position) {
26125 case 'center':
26126 if (vertical) {
26127 if (valIsNegative) {
26128 dataLabelsY = newY - barHeight / 2 + offY;
26129 } else {
26130 dataLabelsY = newY + barHeight / 2 - offY;
26131 }
26132 } else {
26133 if (valIsNegative) {
26134 dataLabelsY = newY - barHeight / 2 + textRects.height / 2 + offY;
26135 } else {
26136 dataLabelsY = newY + barHeight / 2 + textRects.height / 2 - offY;
26137 }
26138 }
26139 break;
26140 case 'bottom':
26141 if (vertical) {
26142 if (valIsNegative) {
26143 dataLabelsY = newY - barHeight + offY;
26144 } else {
26145 dataLabelsY = newY + barHeight - offY;
26146 }
26147 } else {
26148 if (valIsNegative) {
26149 dataLabelsY = newY - barHeight + textRects.height + strokeWidth + offY;
26150 } else {
26151 dataLabelsY = newY + barHeight - textRects.height / 2 + strokeWidth - offY;
26152 }
26153 }
26154 break;
26155 case 'top':
26156 if (vertical) {
26157 if (valIsNegative) {
26158 dataLabelsY = newY + offY;
26159 } else {
26160 dataLabelsY = newY - offY;
26161 }
26162 } else {
26163 if (valIsNegative) {
26164 dataLabelsY = newY - textRects.height / 2 - offY;
26165 } else {
26166 dataLabelsY = newY + textRects.height + offY;
26167 }
26168 }
26169 break;
26170 }
26171 var lowestPrevY = newY;
26172 w.globals.seriesGroups.forEach(function (sg) {
26173 var _this$barCtx$sg$join;
26174 (_this$barCtx$sg$join = _this.barCtx[sg.join(',')]) === null || _this$barCtx$sg$join === void 0 ? void 0 : _this$barCtx$sg$join.prevY.forEach(function (arr) {
26175 if (valIsNegative) {
26176 lowestPrevY = Math.max(arr[j], lowestPrevY);
26177 } else {
26178 lowestPrevY = Math.min(arr[j], lowestPrevY);
26179 }
26180 });
26181 });
26182 if (this.barCtx.lastActiveBarSerieIndex === realIndex && barTotalDataLabelsConfig.enabled) {
26183 var ADDITIONAL_OFFY = 18;
26184 var graphics = new Graphics(this.barCtx.ctx);
26185 var totalLabeltextRects = graphics.getTextRects(this.getStackedTotalDataLabel({
26186 realIndex: realIndex,
26187 j: j
26188 }), dataLabelsConfig.fontSize);
26189 if (valIsNegative) {
26190 totalDataLabelsY = lowestPrevY - totalLabeltextRects.height / 2 - offY - barTotalDataLabelsConfig.offsetY + ADDITIONAL_OFFY;
26191 } else {
26192 totalDataLabelsY = lowestPrevY + totalLabeltextRects.height + offY + barTotalDataLabelsConfig.offsetY - ADDITIONAL_OFFY;
26193 }
26194
26195 // width divided into equal parts
26196 var xDivision = dataPointsDividedWidth;
26197 totalDataLabelsX = totalDataLabelsBcx + (w.globals.isXNumeric ? -barWidth * w.globals.barGroups.length / 2 : w.globals.barGroups.length * barWidth / 2 - (w.globals.barGroups.length - 1) * barWidth - xDivision) + barTotalDataLabelsConfig.offsetX;
26198 }
26199 if (!w.config.chart.stacked) {
26200 if (dataLabelsY < 0) {
26201 dataLabelsY = 0 + strokeWidth;
26202 } else if (dataLabelsY + textRects.height / 3 > w.globals.gridHeight) {
26203 dataLabelsY = w.globals.gridHeight - strokeWidth;
26204 }
26205 }
26206 return {
26207 bcx: bcx,
26208 bcy: y,
26209 dataLabelsX: dataLabelsX,
26210 dataLabelsY: dataLabelsY,
26211 totalDataLabelsX: totalDataLabelsX,
26212 totalDataLabelsY: totalDataLabelsY,
26213 totalDataLabelsAnchor: totalDataLabelsAnchor
26214 };
26215 }
26216 }, {
26217 key: "calculateBarsDataLabelsPosition",
26218 value: function calculateBarsDataLabelsPosition(opts) {
26219 var _this2 = this;
26220 var w = this.w;
26221 var x = opts.x,
26222 i = opts.i,
26223 j = opts.j,
26224 realIndex = opts.realIndex,
26225 bcy = opts.bcy,
26226 barHeight = opts.barHeight,
26227 barWidth = opts.barWidth,
26228 textRects = opts.textRects,
26229 dataLabelsX = opts.dataLabelsX,
26230 strokeWidth = opts.strokeWidth,
26231 dataLabelsConfig = opts.dataLabelsConfig,
26232 barDataLabelsConfig = opts.barDataLabelsConfig,
26233 barTotalDataLabelsConfig = opts.barTotalDataLabelsConfig,
26234 offX = opts.offX,
26235 offY = opts.offY;
26236 var dataPointsDividedHeight = w.globals.gridHeight / w.globals.dataPoints;
26237 var _this$barCtx$barHelpe2 = this.barCtx.barHelpers.getZeroValueEncounters({
26238 i: i,
26239 j: j
26240 }),
26241 zeroEncounters = _this$barCtx$barHelpe2.zeroEncounters;
26242 barWidth = Math.abs(barWidth);
26243 var dataLabelsY = bcy - (this.barCtx.isRangeBar ? 0 : dataPointsDividedHeight) + barHeight / 2 + textRects.height / 2 + offY - 3;
26244 if (!w.config.chart.stacked && zeroEncounters > 0 && w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
26245 dataLabelsY -= barHeight * zeroEncounters;
26246 }
26247 var totalDataLabelsX;
26248 var totalDataLabelsY;
26249 var totalDataLabelsAnchor = 'start';
26250 var valIsNegative = w.globals.series[i][j] < 0;
26251 var newX = x;
26252 if (this.barCtx.isReversed) {
26253 newX = x + (valIsNegative ? -barWidth : barWidth);
26254 totalDataLabelsAnchor = valIsNegative ? 'start' : 'end';
26255 }
26256 switch (barDataLabelsConfig.position) {
26257 case 'center':
26258 if (valIsNegative) {
26259 dataLabelsX = newX + barWidth / 2 - offX;
26260 } else {
26261 dataLabelsX = Math.max(textRects.width / 2, newX - barWidth / 2) + offX;
26262 }
26263 break;
26264 case 'bottom':
26265 if (valIsNegative) {
26266 dataLabelsX = newX + barWidth - strokeWidth - offX;
26267 } else {
26268 dataLabelsX = newX - barWidth + strokeWidth + offX;
26269 }
26270 break;
26271 case 'top':
26272 if (valIsNegative) {
26273 dataLabelsX = newX - strokeWidth - offX;
26274 } else {
26275 dataLabelsX = newX - strokeWidth + offX;
26276 }
26277 break;
26278 }
26279 var lowestPrevX = newX;
26280 w.globals.seriesGroups.forEach(function (sg) {
26281 var _this2$barCtx$sg$join;
26282 (_this2$barCtx$sg$join = _this2.barCtx[sg.join(',')]) === null || _this2$barCtx$sg$join === void 0 ? void 0 : _this2$barCtx$sg$join.prevX.forEach(function (arr) {
26283 if (valIsNegative) {
26284 lowestPrevX = Math.min(arr[j], lowestPrevX);
26285 } else {
26286 lowestPrevX = Math.max(arr[j], lowestPrevX);
26287 }
26288 });
26289 });
26290 if (this.barCtx.lastActiveBarSerieIndex === realIndex && barTotalDataLabelsConfig.enabled) {
26291 var graphics = new Graphics(this.barCtx.ctx);
26292 var totalLabeltextRects = graphics.getTextRects(this.getStackedTotalDataLabel({
26293 realIndex: realIndex,
26294 j: j
26295 }), dataLabelsConfig.fontSize);
26296 if (valIsNegative) {
26297 totalDataLabelsX = lowestPrevX - strokeWidth - offX - barTotalDataLabelsConfig.offsetX;
26298 totalDataLabelsAnchor = 'end';
26299 } else {
26300 totalDataLabelsX = lowestPrevX + offX + barTotalDataLabelsConfig.offsetX + (this.barCtx.isReversed ? -(barWidth + strokeWidth) : strokeWidth);
26301 }
26302 totalDataLabelsY = dataLabelsY - textRects.height / 2 + totalLabeltextRects.height / 2 + barTotalDataLabelsConfig.offsetY + strokeWidth;
26303 if (w.globals.barGroups.length > 1) {
26304 totalDataLabelsY = totalDataLabelsY - w.globals.barGroups.length / 2 * (barHeight / 2);
26305 }
26306 }
26307 if (!w.config.chart.stacked) {
26308 if (dataLabelsConfig.textAnchor === 'start') {
26309 if (dataLabelsX - textRects.width < 0) {
26310 dataLabelsX = valIsNegative ? textRects.width + strokeWidth : strokeWidth;
26311 } else if (dataLabelsX + textRects.width > w.globals.gridWidth) {
26312 dataLabelsX = valIsNegative ? w.globals.gridWidth - strokeWidth : w.globals.gridWidth - textRects.width - strokeWidth;
26313 }
26314 } else if (dataLabelsConfig.textAnchor === 'middle') {
26315 if (dataLabelsX - textRects.width / 2 < 0) {
26316 dataLabelsX = textRects.width / 2 + strokeWidth;
26317 } else if (dataLabelsX + textRects.width / 2 > w.globals.gridWidth) {
26318 dataLabelsX = w.globals.gridWidth - textRects.width / 2 - strokeWidth;
26319 }
26320 } else if (dataLabelsConfig.textAnchor === 'end') {
26321 if (dataLabelsX < 1) {
26322 dataLabelsX = textRects.width + strokeWidth;
26323 } else if (dataLabelsX + 1 > w.globals.gridWidth) {
26324 dataLabelsX = w.globals.gridWidth - textRects.width - strokeWidth;
26325 }
26326 }
26327 }
26328 return {
26329 bcx: x,
26330 bcy: bcy,
26331 dataLabelsX: dataLabelsX,
26332 dataLabelsY: dataLabelsY,
26333 totalDataLabelsX: totalDataLabelsX,
26334 totalDataLabelsY: totalDataLabelsY,
26335 totalDataLabelsAnchor: totalDataLabelsAnchor
26336 };
26337 }
26338 }, {
26339 key: "drawCalculatedDataLabels",
26340 value: function drawCalculatedDataLabels(_ref2) {
26341 var x = _ref2.x,
26342 y = _ref2.y,
26343 val = _ref2.val,
26344 i = _ref2.i,
26345 j = _ref2.j,
26346 textRects = _ref2.textRects,
26347 barHeight = _ref2.barHeight,
26348 barWidth = _ref2.barWidth,
26349 dataLabelsConfig = _ref2.dataLabelsConfig;
26350 var w = this.w;
26351 var rotate = 'rotate(0)';
26352 if (w.config.plotOptions.bar.dataLabels.orientation === 'vertical') rotate = "rotate(-90, ".concat(x, ", ").concat(y, ")");
26353 var dataLabels = new DataLabels(this.barCtx.ctx);
26354 var graphics = new Graphics(this.barCtx.ctx);
26355 var formatter = dataLabelsConfig.formatter;
26356 var elDataLabelsWrap = null;
26357 var isSeriesNotCollapsed = w.globals.collapsedSeriesIndices.indexOf(i) > -1;
26358 if (dataLabelsConfig.enabled && !isSeriesNotCollapsed) {
26359 elDataLabelsWrap = graphics.group({
26360 class: 'apexcharts-data-labels',
26361 transform: rotate
26362 });
26363 var text = '';
26364 if (typeof val !== 'undefined') {
26365 text = formatter(val, _objectSpread2(_objectSpread2({}, w), {}, {
26366 seriesIndex: i,
26367 dataPointIndex: j,
26368 w: w
26369 }));
26370 }
26371 if (!val && w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
26372 text = '';
26373 }
26374 var valIsNegative = w.globals.series[i][j] < 0;
26375 var position = w.config.plotOptions.bar.dataLabels.position;
26376 if (w.config.plotOptions.bar.dataLabels.orientation === 'vertical') {
26377 if (position === 'top') {
26378 if (valIsNegative) dataLabelsConfig.textAnchor = 'end';else dataLabelsConfig.textAnchor = 'start';
26379 }
26380 if (position === 'center') {
26381 dataLabelsConfig.textAnchor = 'middle';
26382 }
26383 if (position === 'bottom') {
26384 if (valIsNegative) dataLabelsConfig.textAnchor = 'end';else dataLabelsConfig.textAnchor = 'start';
26385 }
26386 }
26387 if (this.barCtx.isRangeBar && this.barCtx.barOptions.dataLabels.hideOverflowingLabels) {
26388 // hide the datalabel if it cannot fit into the rect
26389 var txRect = graphics.getTextRects(text, parseFloat(dataLabelsConfig.style.fontSize));
26390 if (barWidth < txRect.width) {
26391 text = '';
26392 }
26393 }
26394 if (w.config.chart.stacked && this.barCtx.barOptions.dataLabels.hideOverflowingLabels) {
26395 // if there is not enough space to draw the label in the bar/column rect, check hideOverflowingLabels property to prevent overflowing on wrong rect
26396 // Note: This issue is only seen in stacked charts
26397 if (this.barCtx.isHorizontal) {
26398 if (textRects.width / 1.6 > Math.abs(barWidth)) {
26399 text = '';
26400 }
26401 } else {
26402 if (textRects.height / 1.6 > Math.abs(barHeight)) {
26403 text = '';
26404 }
26405 }
26406 }
26407 var modifiedDataLabelsConfig = _objectSpread2({}, dataLabelsConfig);
26408 if (this.barCtx.isHorizontal) {
26409 if (val < 0) {
26410 if (dataLabelsConfig.textAnchor === 'start') {
26411 modifiedDataLabelsConfig.textAnchor = 'end';
26412 } else if (dataLabelsConfig.textAnchor === 'end') {
26413 modifiedDataLabelsConfig.textAnchor = 'start';
26414 }
26415 }
26416 }
26417 dataLabels.plotDataLabelsText({
26418 x: x,
26419 y: y,
26420 text: text,
26421 i: i,
26422 j: j,
26423 parent: elDataLabelsWrap,
26424 dataLabelsConfig: modifiedDataLabelsConfig,
26425 alwaysDrawDataLabel: true,
26426 offsetCorrection: true
26427 });
26428 }
26429 return elDataLabelsWrap;
26430 }
26431 }, {
26432 key: "drawTotalDataLabels",
26433 value: function drawTotalDataLabels(_ref3) {
26434 var x = _ref3.x,
26435 y = _ref3.y,
26436 val = _ref3.val,
26437 realIndex = _ref3.realIndex,
26438 textAnchor = _ref3.textAnchor,
26439 barTotalDataLabelsConfig = _ref3.barTotalDataLabelsConfig;
26440 this.w;
26441 var graphics = new Graphics(this.barCtx.ctx);
26442 var totalDataLabelText;
26443 if (barTotalDataLabelsConfig.enabled && typeof x !== 'undefined' && typeof y !== 'undefined' && this.barCtx.lastActiveBarSerieIndex === realIndex) {
26444 totalDataLabelText = graphics.drawText({
26445 x: x,
26446 y: y,
26447 foreColor: barTotalDataLabelsConfig.style.color,
26448 text: val,
26449 textAnchor: textAnchor,
26450 fontFamily: barTotalDataLabelsConfig.style.fontFamily,
26451 fontSize: barTotalDataLabelsConfig.style.fontSize,
26452 fontWeight: barTotalDataLabelsConfig.style.fontWeight
26453 });
26454 }
26455 return totalDataLabelText;
26456 }
26457 }]);
26458 return BarDataLabels;
26459 }();
26460
26461 var Helpers$1 = /*#__PURE__*/function () {
26462 function Helpers(barCtx) {
26463 _classCallCheck(this, Helpers);
26464 this.w = barCtx.w;
26465 this.barCtx = barCtx;
26466 }
26467 _createClass(Helpers, [{
26468 key: "initVariables",
26469 value: function initVariables(series) {
26470 var w = this.w;
26471 this.barCtx.series = series;
26472 this.barCtx.totalItems = 0;
26473 this.barCtx.seriesLen = 0;
26474 this.barCtx.visibleI = -1; // visible Series
26475 this.barCtx.visibleItems = 1; // number of visible bars after user zoomed in/out
26476
26477 for (var sl = 0; sl < series.length; sl++) {
26478 if (series[sl].length > 0) {
26479 this.barCtx.seriesLen = this.barCtx.seriesLen + 1;
26480 this.barCtx.totalItems += series[sl].length;
26481 }
26482 if (w.globals.isXNumeric) {
26483 // get max visible items
26484 for (var _j = 0; _j < series[sl].length; _j++) {
26485 if (w.globals.seriesX[sl][_j] > w.globals.minX && w.globals.seriesX[sl][_j] < w.globals.maxX) {
26486 this.barCtx.visibleItems++;
26487 }
26488 }
26489 } else {
26490 this.barCtx.visibleItems = w.globals.dataPoints;
26491 }
26492 }
26493 this.arrBorderRadius = this.createBorderRadiusArr(w.globals.series);
26494 if (Utils$1.isSafari()) {
26495 // https://github.com/apexcharts/apexcharts.js/issues/4996
26496 // to temporarily fix the above issue, border radius is disabled
26497 this.arrBorderRadius = this.arrBorderRadius.map(function (brArr) {
26498 return brArr.map(function (_) {
26499 return 'none';
26500 });
26501 });
26502 }
26503 if (this.barCtx.seriesLen === 0) {
26504 // A small adjustment when combo charts are used
26505 this.barCtx.seriesLen = 1;
26506 }
26507 this.barCtx.zeroSerieses = [];
26508 if (!w.globals.comboCharts) {
26509 this.checkZeroSeries({
26510 series: series
26511 });
26512 }
26513 }
26514 }, {
26515 key: "initialPositions",
26516 value: function initialPositions(realIndex) {
26517 var w = this.w;
26518 var x, y, yDivision, xDivision, barHeight, barWidth, zeroH, zeroW;
26519 var dataPoints = w.globals.dataPoints;
26520 if (this.barCtx.isRangeBar) {
26521 // timeline rangebar chart
26522 dataPoints = w.globals.labels.length;
26523 }
26524 var seriesLen = this.barCtx.seriesLen;
26525 if (w.config.plotOptions.bar.rangeBarGroupRows) {
26526 seriesLen = 1;
26527 }
26528 if (this.barCtx.isHorizontal) {
26529 // height divided into equal parts
26530 yDivision = w.globals.gridHeight / dataPoints;
26531 barHeight = yDivision / seriesLen;
26532 if (w.globals.isXNumeric) {
26533 yDivision = w.globals.gridHeight / this.barCtx.totalItems;
26534 barHeight = yDivision / this.barCtx.seriesLen;
26535 }
26536 barHeight = barHeight * parseInt(this.barCtx.barOptions.barHeight, 10) / 100;
26537 if (String(this.barCtx.barOptions.barHeight).indexOf('%') === -1) {
26538 barHeight = parseInt(this.barCtx.barOptions.barHeight, 10);
26539 }
26540 zeroW = this.barCtx.baseLineInvertedY + w.globals.padHorizontal + (this.barCtx.isReversed ? w.globals.gridWidth : 0) - (this.barCtx.isReversed ? this.barCtx.baseLineInvertedY * 2 : 0);
26541 if (this.barCtx.isFunnel) {
26542 zeroW = w.globals.gridWidth / 2;
26543 }
26544 y = (yDivision - barHeight * this.barCtx.seriesLen) / 2;
26545 } else {
26546 // width divided into equal parts
26547 xDivision = w.globals.gridWidth / this.barCtx.visibleItems;
26548 if (w.config.xaxis.convertedCatToNumeric) {
26549 xDivision = w.globals.gridWidth / w.globals.dataPoints;
26550 }
26551 barWidth = xDivision / seriesLen * parseInt(this.barCtx.barOptions.columnWidth, 10) / 100;
26552 if (w.globals.isXNumeric) {
26553 // max barwidth should be equal to minXDiff to avoid overlap
26554 var xRatio = this.barCtx.xRatio;
26555 if (w.globals.minXDiff && w.globals.minXDiff !== 0.5 && w.globals.minXDiff / xRatio > 0) {
26556 xDivision = w.globals.minXDiff / xRatio;
26557 }
26558 barWidth = xDivision / seriesLen * parseInt(this.barCtx.barOptions.columnWidth, 10) / 100;
26559 if (barWidth < 1) {
26560 barWidth = 1;
26561 }
26562 }
26563 if (String(this.barCtx.barOptions.columnWidth).indexOf('%') === -1) {
26564 barWidth = parseInt(this.barCtx.barOptions.columnWidth, 10);
26565 }
26566 zeroH = w.globals.gridHeight - this.barCtx.baseLineY[this.barCtx.translationsIndex] - (this.barCtx.isReversed ? w.globals.gridHeight : 0) + (this.barCtx.isReversed ? this.barCtx.baseLineY[this.barCtx.translationsIndex] * 2 : 0);
26567 if (w.globals.isXNumeric) {
26568 var xForNumericX = this.barCtx.getBarXForNumericXAxis({
26569 x: x,
26570 j: 0,
26571 realIndex: realIndex,
26572 barWidth: barWidth
26573 });
26574 x = xForNumericX.x;
26575 } else {
26576 x = w.globals.padHorizontal + Utils$1.noExponents(xDivision - barWidth * this.barCtx.seriesLen) / 2;
26577 }
26578 }
26579 w.globals.barHeight = barHeight;
26580 w.globals.barWidth = barWidth;
26581 return {
26582 x: x,
26583 y: y,
26584 yDivision: yDivision,
26585 xDivision: xDivision,
26586 barHeight: barHeight,
26587 barWidth: barWidth,
26588 zeroH: zeroH,
26589 zeroW: zeroW
26590 };
26591 }
26592 }, {
26593 key: "initializeStackedPrevVars",
26594 value: function initializeStackedPrevVars(ctx) {
26595 var w = ctx.w;
26596 w.globals.seriesGroups.forEach(function (group) {
26597 if (!ctx[group]) ctx[group] = {};
26598 ctx[group].prevY = [];
26599 ctx[group].prevX = [];
26600 ctx[group].prevYF = [];
26601 ctx[group].prevXF = [];
26602 ctx[group].prevYVal = [];
26603 ctx[group].prevXVal = [];
26604 });
26605 }
26606 }, {
26607 key: "initializeStackedXYVars",
26608 value: function initializeStackedXYVars(ctx) {
26609 var w = ctx.w;
26610 w.globals.seriesGroups.forEach(function (group) {
26611 if (!ctx[group]) ctx[group] = {};
26612 ctx[group].xArrj = [];
26613 ctx[group].xArrjF = [];
26614 ctx[group].xArrjVal = [];
26615 ctx[group].yArrj = [];
26616 ctx[group].yArrjF = [];
26617 ctx[group].yArrjVal = [];
26618 });
26619 }
26620 }, {
26621 key: "getPathFillColor",
26622 value: function getPathFillColor(series, i, j, realIndex) {
26623 var _w$config$series$i$da, _w$config$series$i$da2, _w$config$series$i$da3, _w$config$series$i$da4;
26624 var w = this.w;
26625 var fill = this.barCtx.ctx.fill;
26626 var fillColor = null;
26627 var seriesNumber = this.barCtx.barOptions.distributed ? j : i;
26628 var useRangeColor = false;
26629 if (this.barCtx.barOptions.colors.ranges.length > 0) {
26630 var colorRange = this.barCtx.barOptions.colors.ranges;
26631 colorRange.map(function (range) {
26632 if (series[i][j] >= range.from && series[i][j] <= range.to) {
26633 fillColor = range.color;
26634 useRangeColor = true;
26635 }
26636 });
26637 }
26638 var pathFill = fill.fillPath({
26639 seriesNumber: this.barCtx.barOptions.distributed ? seriesNumber : realIndex,
26640 dataPointIndex: j,
26641 color: fillColor,
26642 value: series[i][j],
26643 fillConfig: (_w$config$series$i$da = w.config.series[i].data[j]) === null || _w$config$series$i$da === void 0 ? void 0 : _w$config$series$i$da.fill,
26644 fillType: (_w$config$series$i$da2 = w.config.series[i].data[j]) !== null && _w$config$series$i$da2 !== void 0 && (_w$config$series$i$da3 = _w$config$series$i$da2.fill) !== null && _w$config$series$i$da3 !== void 0 && _w$config$series$i$da3.type ? (_w$config$series$i$da4 = w.config.series[i].data[j]) === null || _w$config$series$i$da4 === void 0 ? void 0 : _w$config$series$i$da4.fill.type : Array.isArray(w.config.fill.type) ? w.config.fill.type[realIndex] : w.config.fill.type
26645 });
26646 return {
26647 color: pathFill,
26648 useRangeColor: useRangeColor
26649 };
26650 }
26651 }, {
26652 key: "getStrokeWidth",
26653 value: function getStrokeWidth(i, j, realIndex) {
26654 var strokeWidth = 0;
26655 var w = this.w;
26656 if (typeof this.barCtx.series[i][j] === 'undefined' || this.barCtx.series[i][j] === null) {
26657 this.barCtx.isNullValue = true;
26658 } else {
26659 this.barCtx.isNullValue = false;
26660 }
26661 if (w.config.stroke.show) {
26662 if (!this.barCtx.isNullValue) {
26663 strokeWidth = Array.isArray(this.barCtx.strokeWidth) ? this.barCtx.strokeWidth[realIndex] : this.barCtx.strokeWidth;
26664 }
26665 }
26666 return strokeWidth;
26667 }
26668 }, {
26669 key: "createBorderRadiusArr",
26670 value: function createBorderRadiusArr(series) {
26671 var _series$;
26672 var w = this.w;
26673 var alwaysApplyRadius = !this.w.config.chart.stacked || w.config.plotOptions.bar.borderRadius <= 0;
26674 var numSeries = series.length;
26675 var numColumns = ((_series$ = series[0]) === null || _series$ === void 0 ? void 0 : _series$.length) | 0;
26676 var output = Array.from({
26677 length: numSeries
26678 }, function () {
26679 return Array(numColumns).fill(alwaysApplyRadius ? 'top' : 'none');
26680 });
26681 if (alwaysApplyRadius) return output;
26682 for (var _j2 = 0; _j2 < numColumns; _j2++) {
26683 var positiveIndices = [];
26684 var negativeIndices = [];
26685 var nonZeroCount = 0;
26686
26687 // Collect positive and negative indices
26688 for (var i = 0; i < numSeries; i++) {
26689 var value = series[i][_j2];
26690 if (value > 0) {
26691 positiveIndices.push(i);
26692 nonZeroCount++;
26693 } else if (value < 0) {
26694 negativeIndices.push(i);
26695 nonZeroCount++;
26696 }
26697 }
26698 if (positiveIndices.length > 0 && negativeIndices.length === 0) {
26699 // Only positive values in this column
26700 if (positiveIndices.length === 1) {
26701 // Single positive value
26702 output[positiveIndices[0]][_j2] = 'both';
26703 } else {
26704 // Multiple positive values
26705 var firstPositiveIndex = positiveIndices[0];
26706 var lastPositiveIndex = positiveIndices[positiveIndices.length - 1];
26707 var _iterator = _createForOfIteratorHelper(positiveIndices),
26708 _step;
26709 try {
26710 for (_iterator.s(); !(_step = _iterator.n()).done;) {
26711 var _i2 = _step.value;
26712 if (_i2 === firstPositiveIndex) {
26713 output[_i2][_j2] = 'bottom';
26714 } else if (_i2 === lastPositiveIndex) {
26715 output[_i2][_j2] = 'top';
26716 } else {
26717 output[_i2][_j2] = 'none';
26718 }
26719 }
26720 } catch (err) {
26721 _iterator.e(err);
26722 } finally {
26723 _iterator.f();
26724 }
26725 }
26726 } else if (negativeIndices.length > 0 && positiveIndices.length === 0) {
26727 // Only negative values in this column
26728 if (negativeIndices.length === 1) {
26729 // Single negative value
26730 output[negativeIndices[0]][_j2] = 'both';
26731 } else {
26732 // Multiple negative values
26733 var highestNegativeIndex = Math.max.apply(Math, negativeIndices);
26734 var lowestNegativeIndex = Math.min.apply(Math, negativeIndices);
26735 var _iterator2 = _createForOfIteratorHelper(negativeIndices),
26736 _step2;
26737 try {
26738 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
26739 var _i3 = _step2.value;
26740 if (_i3 === highestNegativeIndex) {
26741 output[_i3][_j2] = 'bottom'; // Closest to axis
26742 } else if (_i3 === lowestNegativeIndex) {
26743 output[_i3][_j2] = 'top'; // Farthest from axis
26744 } else {
26745 output[_i3][_j2] = 'none';
26746 }
26747 }
26748 } catch (err) {
26749 _iterator2.e(err);
26750 } finally {
26751 _iterator2.f();
26752 }
26753 }
26754 } else if (positiveIndices.length > 0 && negativeIndices.length > 0) {
26755 // Mixed positive and negative values
26756 // Assign 'top' to the last positive bar
26757 var _lastPositiveIndex = positiveIndices[positiveIndices.length - 1];
26758 var _iterator3 = _createForOfIteratorHelper(positiveIndices),
26759 _step3;
26760 try {
26761 for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
26762 var _i4 = _step3.value;
26763 if (_i4 === _lastPositiveIndex) {
26764 output[_i4][_j2] = 'top';
26765 } else {
26766 output[_i4][_j2] = 'none';
26767 }
26768 }
26769 // Assign 'bottom' to the highest negative index (closest to axis)
26770 } catch (err) {
26771 _iterator3.e(err);
26772 } finally {
26773 _iterator3.f();
26774 }
26775 var _highestNegativeIndex = Math.max.apply(Math, negativeIndices);
26776 var _iterator4 = _createForOfIteratorHelper(negativeIndices),
26777 _step4;
26778 try {
26779 for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
26780 var _i5 = _step4.value;
26781 if (_i5 === _highestNegativeIndex) {
26782 output[_i5][_j2] = 'bottom';
26783 } else {
26784 output[_i5][_j2] = 'none';
26785 }
26786 }
26787 } catch (err) {
26788 _iterator4.e(err);
26789 } finally {
26790 _iterator4.f();
26791 }
26792 } else if (nonZeroCount === 1) {
26793 // Only one non-zero value (either positive or negative)
26794 var index = positiveIndices[0] || negativeIndices[0];
26795 output[index][_j2] = 'both';
26796 }
26797 }
26798 return output;
26799 }
26800 }, {
26801 key: "barBackground",
26802 value: function barBackground(_ref) {
26803 var j = _ref.j,
26804 i = _ref.i,
26805 x1 = _ref.x1,
26806 x2 = _ref.x2,
26807 y1 = _ref.y1,
26808 y2 = _ref.y2,
26809 elSeries = _ref.elSeries;
26810 var w = this.w;
26811 var graphics = new Graphics(this.barCtx.ctx);
26812 var sr = new Series(this.barCtx.ctx);
26813 var activeSeriesIndex = sr.getActiveConfigSeriesIndex();
26814 if (this.barCtx.barOptions.colors.backgroundBarColors.length > 0 && activeSeriesIndex === i) {
26815 if (j >= this.barCtx.barOptions.colors.backgroundBarColors.length) {
26816 j %= this.barCtx.barOptions.colors.backgroundBarColors.length;
26817 }
26818 var bcolor = this.barCtx.barOptions.colors.backgroundBarColors[j];
26819 var rect = graphics.drawRect(typeof x1 !== 'undefined' ? x1 : 0, typeof y1 !== 'undefined' ? y1 : 0, typeof x2 !== 'undefined' ? x2 : w.globals.gridWidth, typeof y2 !== 'undefined' ? y2 : w.globals.gridHeight, this.barCtx.barOptions.colors.backgroundBarRadius, bcolor, this.barCtx.barOptions.colors.backgroundBarOpacity);
26820 elSeries.add(rect);
26821 rect.node.classList.add('apexcharts-backgroundBar');
26822 }
26823 }
26824 }, {
26825 key: "getColumnPaths",
26826 value: function getColumnPaths(_ref2) {
26827 var _w$config$series$real;
26828 var barWidth = _ref2.barWidth,
26829 barXPosition = _ref2.barXPosition,
26830 y1 = _ref2.y1,
26831 y2 = _ref2.y2,
26832 strokeWidth = _ref2.strokeWidth,
26833 isReversed = _ref2.isReversed,
26834 series = _ref2.series,
26835 seriesGroup = _ref2.seriesGroup,
26836 realIndex = _ref2.realIndex,
26837 i = _ref2.i,
26838 j = _ref2.j,
26839 w = _ref2.w;
26840 var graphics = new Graphics(this.barCtx.ctx);
26841 strokeWidth = Array.isArray(strokeWidth) ? strokeWidth[realIndex] : strokeWidth;
26842 if (!strokeWidth) strokeWidth = 0;
26843 var bW = barWidth;
26844 var bXP = barXPosition;
26845 if ((_w$config$series$real = w.config.series[realIndex].data[j]) !== null && _w$config$series$real !== void 0 && _w$config$series$real.columnWidthOffset) {
26846 bXP = barXPosition - w.config.series[realIndex].data[j].columnWidthOffset / 2;
26847 bW = barWidth + w.config.series[realIndex].data[j].columnWidthOffset;
26848 }
26849
26850 // Center the stroke on the coordinates
26851 var strokeCenter = strokeWidth / 2;
26852 var x1 = bXP + strokeCenter;
26853 var x2 = bXP + bW - strokeCenter;
26854 var direction = (series[i][j] >= 0 ? 1 : -1) * (isReversed ? -1 : 1);
26855
26856 // append tiny pixels to avoid exponentials (which cause issues in border-radius)
26857 y1 += 0.001 - strokeCenter * direction;
26858 y2 += 0.001 + strokeCenter * direction;
26859 var pathTo = graphics.move(x1, y1);
26860 var pathFrom = graphics.move(x1, y1);
26861 var sl = graphics.line(x2, y1);
26862 if (w.globals.previousPaths.length > 0) {
26863 pathFrom = this.barCtx.getPreviousPath(realIndex, j, false);
26864 }
26865 pathTo = pathTo + graphics.line(x1, y2) + graphics.line(x2, y2) + sl + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
26866
26867 // the lines in pathFrom are repeated to equal it to the points of pathTo
26868 // this is to avoid weird animation (bug in svg.js)
26869 pathFrom = pathFrom + graphics.line(x1, y1) + sl + sl + sl + sl + sl + graphics.line(x1, y1) + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
26870 if (this.arrBorderRadius[realIndex][j] !== 'none') {
26871 pathTo = graphics.roundPathCorners(pathTo, w.config.plotOptions.bar.borderRadius);
26872 }
26873 if (w.config.chart.stacked) {
26874 var _ctx = this.barCtx;
26875 _ctx = this.barCtx[seriesGroup];
26876 _ctx.yArrj.push(y2 - strokeCenter * direction);
26877 _ctx.yArrjF.push(Math.abs(y1 - y2 + strokeWidth * direction));
26878 _ctx.yArrjVal.push(this.barCtx.series[i][j]);
26879 }
26880 return {
26881 pathTo: pathTo,
26882 pathFrom: pathFrom
26883 };
26884 }
26885 }, {
26886 key: "getBarpaths",
26887 value: function getBarpaths(_ref3) {
26888 var _w$config$series$real2;
26889 var barYPosition = _ref3.barYPosition,
26890 barHeight = _ref3.barHeight,
26891 x1 = _ref3.x1,
26892 x2 = _ref3.x2,
26893 strokeWidth = _ref3.strokeWidth,
26894 isReversed = _ref3.isReversed,
26895 series = _ref3.series,
26896 seriesGroup = _ref3.seriesGroup,
26897 realIndex = _ref3.realIndex,
26898 i = _ref3.i,
26899 j = _ref3.j,
26900 w = _ref3.w;
26901 var graphics = new Graphics(this.barCtx.ctx);
26902 strokeWidth = Array.isArray(strokeWidth) ? strokeWidth[realIndex] : strokeWidth;
26903 if (!strokeWidth) strokeWidth = 0;
26904 var bYP = barYPosition;
26905 var bH = barHeight;
26906 if ((_w$config$series$real2 = w.config.series[realIndex].data[j]) !== null && _w$config$series$real2 !== void 0 && _w$config$series$real2.barHeightOffset) {
26907 bYP = barYPosition - w.config.series[realIndex].data[j].barHeightOffset / 2;
26908 bH = barHeight + w.config.series[realIndex].data[j].barHeightOffset;
26909 }
26910
26911 // Center the stroke on the coordinates
26912 var strokeCenter = strokeWidth / 2;
26913 var y1 = bYP + strokeCenter;
26914 var y2 = bYP + bH - strokeCenter;
26915 var direction = (series[i][j] >= 0 ? 1 : -1) * (isReversed ? -1 : 1);
26916
26917 // append tiny pixels to avoid exponentials (which cause issues in border-radius)
26918 x1 += 0.001 + strokeCenter * direction;
26919 x2 += 0.001 - strokeCenter * direction;
26920 var pathTo = graphics.move(x1, y1);
26921 var pathFrom = graphics.move(x1, y1);
26922 if (w.globals.previousPaths.length > 0) {
26923 pathFrom = this.barCtx.getPreviousPath(realIndex, j, false);
26924 }
26925 var sl = graphics.line(x1, y2);
26926 pathTo = pathTo + graphics.line(x2, y1) + graphics.line(x2, y2) + sl + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
26927 pathFrom = pathFrom + graphics.line(x1, y1) + sl + sl + sl + sl + sl + graphics.line(x1, y1) + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
26928 if (this.arrBorderRadius[realIndex][j] !== 'none') {
26929 pathTo = graphics.roundPathCorners(pathTo, w.config.plotOptions.bar.borderRadius);
26930 }
26931 if (w.config.chart.stacked) {
26932 var _ctx = this.barCtx;
26933 _ctx = this.barCtx[seriesGroup];
26934 _ctx.xArrj.push(x2 + strokeCenter * direction);
26935 _ctx.xArrjF.push(Math.abs(x1 - x2 - strokeWidth * direction));
26936 _ctx.xArrjVal.push(this.barCtx.series[i][j]);
26937 }
26938 return {
26939 pathTo: pathTo,
26940 pathFrom: pathFrom
26941 };
26942 }
26943 }, {
26944 key: "checkZeroSeries",
26945 value: function checkZeroSeries(_ref4) {
26946 var series = _ref4.series;
26947 var w = this.w;
26948 for (var zs = 0; zs < series.length; zs++) {
26949 var total = 0;
26950 for (var zsj = 0; zsj < series[w.globals.maxValsInArrayIndex].length; zsj++) {
26951 total += series[zs][zsj];
26952 }
26953 if (total === 0) {
26954 this.barCtx.zeroSerieses.push(zs);
26955 }
26956 }
26957 }
26958 }, {
26959 key: "getXForValue",
26960 value: function getXForValue(value, zeroW) {
26961 var zeroPositionForNull = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
26962 var xForVal = zeroPositionForNull ? zeroW : null;
26963 if (typeof value !== 'undefined' && value !== null) {
26964 xForVal = zeroW + value / this.barCtx.invertedYRatio - (this.barCtx.isReversed ? value / this.barCtx.invertedYRatio : 0) * 2;
26965 }
26966 return xForVal;
26967 }
26968 }, {
26969 key: "getYForValue",
26970 value: function getYForValue(value, zeroH, translationsIndex) {
26971 var zeroPositionForNull = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
26972 var yForVal = zeroPositionForNull ? zeroH : null;
26973 if (typeof value !== 'undefined' && value !== null) {
26974 yForVal = zeroH - value / this.barCtx.yRatio[translationsIndex] + (this.barCtx.isReversed ? value / this.barCtx.yRatio[translationsIndex] : 0) * 2;
26975 }
26976 return yForVal;
26977 }
26978 }, {
26979 key: "getGoalValues",
26980 value: function getGoalValues(type, zeroW, zeroH, i, j, translationsIndex) {
26981 var _this = this;
26982 var w = this.w;
26983 var goals = [];
26984 var pushGoal = function pushGoal(value, attrs) {
26985 var _goals$push;
26986 goals.push((_goals$push = {}, _defineProperty(_goals$push, type, type === 'x' ? _this.getXForValue(value, zeroW, false) : _this.getYForValue(value, zeroH, translationsIndex, false)), _defineProperty(_goals$push, "attrs", attrs), _goals$push));
26987 };
26988 if (w.globals.seriesGoals[i] && w.globals.seriesGoals[i][j] && Array.isArray(w.globals.seriesGoals[i][j])) {
26989 w.globals.seriesGoals[i][j].forEach(function (goal) {
26990 pushGoal(goal.value, goal);
26991 });
26992 }
26993 if (this.barCtx.barOptions.isDumbbell && w.globals.seriesRange.length) {
26994 var colors = this.barCtx.barOptions.dumbbellColors ? this.barCtx.barOptions.dumbbellColors : w.globals.colors;
26995 var commonAttrs = {
26996 strokeHeight: type === 'x' ? 0 : w.globals.markers.size[i],
26997 strokeWidth: type === 'x' ? w.globals.markers.size[i] : 0,
26998 strokeDashArray: 0,
26999 strokeLineCap: 'round',
27000 strokeColor: Array.isArray(colors[i]) ? colors[i][0] : colors[i]
27001 };
27002 pushGoal(w.globals.seriesRangeStart[i][j], commonAttrs);
27003 pushGoal(w.globals.seriesRangeEnd[i][j], _objectSpread2(_objectSpread2({}, commonAttrs), {}, {
27004 strokeColor: Array.isArray(colors[i]) ? colors[i][1] : colors[i]
27005 }));
27006 }
27007 return goals;
27008 }
27009 }, {
27010 key: "drawGoalLine",
27011 value: function drawGoalLine(_ref5) {
27012 var barXPosition = _ref5.barXPosition,
27013 barYPosition = _ref5.barYPosition,
27014 goalX = _ref5.goalX,
27015 goalY = _ref5.goalY,
27016 barWidth = _ref5.barWidth,
27017 barHeight = _ref5.barHeight;
27018 var graphics = new Graphics(this.barCtx.ctx);
27019 var lineGroup = graphics.group({
27020 className: 'apexcharts-bar-goals-groups'
27021 });
27022 lineGroup.node.classList.add('apexcharts-element-hidden');
27023 this.barCtx.w.globals.delayedElements.push({
27024 el: lineGroup.node
27025 });
27026 lineGroup.attr('clip-path', "url(#gridRectMarkerMask".concat(this.barCtx.w.globals.cuid, ")"));
27027 var line = null;
27028 if (this.barCtx.isHorizontal) {
27029 if (Array.isArray(goalX)) {
27030 goalX.forEach(function (goal) {
27031 // Need a tiny margin of 1 each side so goals don't disappear at extremeties
27032 if (goal.x >= -1 && goal.x <= graphics.w.globals.gridWidth + 1) {
27033 var sHeight = typeof goal.attrs.strokeHeight !== 'undefined' ? goal.attrs.strokeHeight : barHeight / 2;
27034 var y = barYPosition + sHeight + barHeight / 2;
27035 line = graphics.drawLine(goal.x, y - sHeight * 2, goal.x, y, goal.attrs.strokeColor ? goal.attrs.strokeColor : undefined, goal.attrs.strokeDashArray, goal.attrs.strokeWidth ? goal.attrs.strokeWidth : 2, goal.attrs.strokeLineCap);
27036 lineGroup.add(line);
27037 }
27038 });
27039 }
27040 } else {
27041 if (Array.isArray(goalY)) {
27042 goalY.forEach(function (goal) {
27043 // Need a tiny margin of 1 each side so goals don't disappear at extremeties
27044 if (goal.y >= -1 && goal.y <= graphics.w.globals.gridHeight + 1) {
27045 var sWidth = typeof goal.attrs.strokeWidth !== 'undefined' ? goal.attrs.strokeWidth : barWidth / 2;
27046 var x = barXPosition + sWidth + barWidth / 2;
27047 line = graphics.drawLine(x - sWidth * 2, goal.y, x, goal.y, goal.attrs.strokeColor ? goal.attrs.strokeColor : undefined, goal.attrs.strokeDashArray, goal.attrs.strokeHeight ? goal.attrs.strokeHeight : 2, goal.attrs.strokeLineCap);
27048 lineGroup.add(line);
27049 }
27050 });
27051 }
27052 }
27053 return lineGroup;
27054 }
27055 }, {
27056 key: "drawBarShadow",
27057 value: function drawBarShadow(_ref6) {
27058 var prevPaths = _ref6.prevPaths,
27059 currPaths = _ref6.currPaths,
27060 color = _ref6.color;
27061 var w = this.w;
27062 var prevX2 = prevPaths.x,
27063 prevX1 = prevPaths.x1,
27064 prevY1 = prevPaths.barYPosition;
27065 var currX2 = currPaths.x,
27066 currX1 = currPaths.x1,
27067 currY1 = currPaths.barYPosition;
27068 var prevY2 = prevY1 + currPaths.barHeight;
27069 var graphics = new Graphics(this.barCtx.ctx);
27070 var utils = new Utils$1();
27071 var shadowPath = graphics.move(prevX1, prevY2) + graphics.line(prevX2, prevY2) + graphics.line(currX2, currY1) + graphics.line(currX1, currY1) + graphics.line(prevX1, prevY2) + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
27072 return graphics.drawPath({
27073 d: shadowPath,
27074 fill: utils.shadeColor(0.5, Utils$1.rgb2hex(color)),
27075 stroke: 'none',
27076 strokeWidth: 0,
27077 fillOpacity: 1,
27078 classes: 'apexcharts-bar-shadow apexcharts-decoration-element'
27079 });
27080 }
27081 }, {
27082 key: "getZeroValueEncounters",
27083 value: function getZeroValueEncounters(_ref7) {
27084 var _w$globals$columnSeri;
27085 var i = _ref7.i,
27086 j = _ref7.j;
27087 var w = this.w;
27088 var nonZeroColumns = 0;
27089 var zeroEncounters = 0;
27090 var seriesIndices = w.config.plotOptions.bar.horizontal ? w.globals.series.map(function (_, _i) {
27091 return _i;
27092 }) : ((_w$globals$columnSeri = w.globals.columnSeries) === null || _w$globals$columnSeri === void 0 ? void 0 : _w$globals$columnSeri.i.map(function (_i) {
27093 return _i;
27094 })) || [];
27095 seriesIndices.forEach(function (_si) {
27096 var val = w.globals.seriesPercent[_si][j];
27097 if (val) {
27098 nonZeroColumns++;
27099 }
27100 if (_si < i && val === 0) {
27101 zeroEncounters++;
27102 }
27103 });
27104 return {
27105 nonZeroColumns: nonZeroColumns,
27106 zeroEncounters: zeroEncounters
27107 };
27108 }
27109 }, {
27110 key: "getGroupIndex",
27111 value: function getGroupIndex(seriesIndex) {
27112 var w = this.w;
27113 // groupIndex is the index of group buckets (group1, group2, ...)
27114 var groupIndex = w.globals.seriesGroups.findIndex(function (group) {
27115 return (
27116 // w.config.series[i].name may be undefined, so use
27117 // w.globals.seriesNames[i], which has default names for those
27118 // series. w.globals.seriesGroups[] uses the same default naming.
27119 group.indexOf(w.globals.seriesNames[seriesIndex]) > -1
27120 );
27121 });
27122 // We need the column groups to be indexable as 0,1,2,... for their
27123 // positioning relative to each other.
27124 var cGI = this.barCtx.columnGroupIndices;
27125 var columnGroupIndex = cGI.indexOf(groupIndex);
27126 if (columnGroupIndex < 0) {
27127 cGI.push(groupIndex);
27128 columnGroupIndex = cGI.length - 1;
27129 }
27130 return {
27131 groupIndex: groupIndex,
27132 columnGroupIndex: columnGroupIndex
27133 };
27134 }
27135 }]);
27136 return Helpers;
27137 }();
27138
27139 /**
27140 * ApexCharts Bar Class responsible for drawing both Columns and Bars.
27141 *
27142 * @module Bar
27143 **/
27144 var Bar = /*#__PURE__*/function () {
27145 function Bar(ctx, xyRatios) {
27146 _classCallCheck(this, Bar);
27147 this.ctx = ctx;
27148 this.w = ctx.w;
27149 var w = this.w;
27150 this.barOptions = w.config.plotOptions.bar;
27151 this.isHorizontal = this.barOptions.horizontal;
27152 this.strokeWidth = w.config.stroke.width;
27153 this.isNullValue = false;
27154 this.isRangeBar = w.globals.seriesRange.length && this.isHorizontal;
27155 this.isVerticalGroupedRangeBar = !w.globals.isBarHorizontal && w.globals.seriesRange.length && w.config.plotOptions.bar.rangeBarGroupRows;
27156 this.isFunnel = this.barOptions.isFunnel;
27157 this.xyRatios = xyRatios;
27158 if (this.xyRatios !== null) {
27159 this.xRatio = xyRatios.xRatio;
27160 this.yRatio = xyRatios.yRatio;
27161 this.invertedXRatio = xyRatios.invertedXRatio;
27162 this.invertedYRatio = xyRatios.invertedYRatio;
27163 this.baseLineY = xyRatios.baseLineY;
27164 this.baseLineInvertedY = xyRatios.baseLineInvertedY;
27165 }
27166 this.yaxisIndex = 0;
27167 this.translationsIndex = 0;
27168 this.seriesLen = 0;
27169 this.pathArr = [];
27170 var ser = new Series(this.ctx);
27171 this.lastActiveBarSerieIndex = ser.getActiveConfigSeriesIndex('desc', ['bar', 'column']);
27172 this.columnGroupIndices = [];
27173 var barSeriesIndices = ser.getBarSeriesIndices();
27174 var coreUtils = new CoreUtils(this.ctx);
27175 this.stackedSeriesTotals = coreUtils.getStackedSeriesTotals(this.w.config.series.map(function (s, i) {
27176 return barSeriesIndices.indexOf(i) === -1 ? i : -1;
27177 }).filter(function (s) {
27178 return s !== -1;
27179 }));
27180 this.barHelpers = new Helpers$1(this);
27181 }
27182
27183 /** primary draw method which is called on bar object
27184 * @memberof Bar
27185 * @param {array} series - user supplied series values
27186 * @param {int} seriesIndex - the index by which series will be drawn on the svg
27187 * @return {node} element which is supplied to parent chart draw method for appending
27188 **/
27189 _createClass(Bar, [{
27190 key: "draw",
27191 value: function draw(series, seriesIndex) {
27192 var w = this.w;
27193 var graphics = new Graphics(this.ctx);
27194 var coreUtils = new CoreUtils(this.ctx, w);
27195 series = coreUtils.getLogSeries(series);
27196 this.series = series;
27197 this.yRatio = coreUtils.getLogYRatios(this.yRatio);
27198 this.barHelpers.initVariables(series);
27199 var ret = graphics.group({
27200 class: 'apexcharts-bar-series apexcharts-plot-series'
27201 });
27202 if (w.config.dataLabels.enabled) {
27203 if (this.totalItems > this.barOptions.dataLabels.maxItems) {
27204 console.warn('WARNING: DataLabels are enabled but there are too many to display. This may cause performance issue when rendering - ApexCharts');
27205 }
27206 }
27207 for (var i = 0, bc = 0; i < series.length; i++, bc++) {
27208 var x = void 0,
27209 y = void 0,
27210 xDivision = void 0,
27211 // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
27212 yDivision = void 0,
27213 // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
27214 zeroH = void 0,
27215 // zeroH is the baseline where 0 meets y axis
27216 zeroW = void 0; // zeroW is the baseline where 0 meets x axis
27217
27218 var yArrj = []; // hold y values of current iterating series
27219 var xArrj = []; // hold x values of current iterating series
27220
27221 var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
27222 var _this$barHelpers$getG = this.barHelpers.getGroupIndex(realIndex),
27223 columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
27224
27225 // el to which series will be drawn
27226 var elSeries = graphics.group({
27227 class: "apexcharts-series",
27228 rel: i + 1,
27229 seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
27230 'data:realIndex': realIndex
27231 });
27232 this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
27233 if (series[i].length > 0) {
27234 this.visibleI = this.visibleI + 1;
27235 }
27236 var barHeight = 0;
27237 var barWidth = 0;
27238 if (this.yRatio.length > 1) {
27239 this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex];
27240 this.translationsIndex = realIndex;
27241 }
27242 var translationsIndex = this.translationsIndex;
27243 this.isReversed = w.config.yaxis[this.yaxisIndex] && w.config.yaxis[this.yaxisIndex].reversed;
27244 var initPositions = this.barHelpers.initialPositions(realIndex);
27245 y = initPositions.y;
27246 barHeight = initPositions.barHeight;
27247 yDivision = initPositions.yDivision;
27248 zeroW = initPositions.zeroW;
27249 x = initPositions.x;
27250 barWidth = initPositions.barWidth;
27251 xDivision = initPositions.xDivision;
27252 zeroH = initPositions.zeroH;
27253 if (!this.isHorizontal) {
27254 xArrj.push(x + barWidth / 2);
27255 }
27256
27257 // eldatalabels
27258 var elDataLabelsWrap = graphics.group({
27259 class: 'apexcharts-datalabels',
27260 'data:realIndex': realIndex
27261 });
27262 w.globals.delayedElements.push({
27263 el: elDataLabelsWrap.node
27264 });
27265 elDataLabelsWrap.node.classList.add('apexcharts-element-hidden');
27266 var elGoalsMarkers = graphics.group({
27267 class: 'apexcharts-bar-goals-markers'
27268 });
27269 var elBarShadows = graphics.group({
27270 class: 'apexcharts-bar-shadows'
27271 });
27272 w.globals.delayedElements.push({
27273 el: elBarShadows.node
27274 });
27275 elBarShadows.node.classList.add('apexcharts-element-hidden');
27276 for (var j = 0; j < series[i].length; j++) {
27277 var strokeWidth = this.barHelpers.getStrokeWidth(i, j, realIndex);
27278 var paths = null;
27279 var pathsParams = {
27280 indexes: {
27281 i: i,
27282 j: j,
27283 realIndex: realIndex,
27284 translationsIndex: translationsIndex,
27285 bc: bc
27286 },
27287 x: x,
27288 y: y,
27289 strokeWidth: strokeWidth,
27290 elSeries: elSeries
27291 };
27292 if (this.isHorizontal) {
27293 paths = this.drawBarPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
27294 barHeight: barHeight,
27295 zeroW: zeroW,
27296 yDivision: yDivision
27297 }));
27298 barWidth = this.series[i][j] / this.invertedYRatio;
27299 } else {
27300 paths = this.drawColumnPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
27301 xDivision: xDivision,
27302 barWidth: barWidth,
27303 zeroH: zeroH
27304 }));
27305 barHeight = this.series[i][j] / this.yRatio[translationsIndex];
27306 }
27307 var pathFill = this.barHelpers.getPathFillColor(series, i, j, realIndex);
27308 if (this.isFunnel && this.barOptions.isFunnel3d && this.pathArr.length && j > 0) {
27309 var _pathFill$color;
27310 var barShadow = this.barHelpers.drawBarShadow({
27311 color: typeof pathFill.color === 'string' && ((_pathFill$color = pathFill.color) === null || _pathFill$color === void 0 ? void 0 : _pathFill$color.indexOf('url')) === -1 ? pathFill.color : Utils$1.hexToRgba(w.globals.colors[i]),
27312 prevPaths: this.pathArr[this.pathArr.length - 1],
27313 currPaths: paths
27314 });
27315 elBarShadows.add(barShadow);
27316 if (w.config.chart.dropShadow.enabled) {
27317 var filters = new Filters(this.ctx);
27318 filters.dropShadow(barShadow, w.config.chart.dropShadow, realIndex);
27319 }
27320 }
27321 this.pathArr.push(paths);
27322 var barGoalLine = this.barHelpers.drawGoalLine({
27323 barXPosition: paths.barXPosition,
27324 barYPosition: paths.barYPosition,
27325 goalX: paths.goalX,
27326 goalY: paths.goalY,
27327 barHeight: barHeight,
27328 barWidth: barWidth
27329 });
27330 if (barGoalLine) {
27331 elGoalsMarkers.add(barGoalLine);
27332 }
27333 y = paths.y;
27334 x = paths.x;
27335
27336 // push current X
27337 if (j > 0) {
27338 xArrj.push(x + barWidth / 2);
27339 }
27340 yArrj.push(y);
27341 this.renderSeries(_objectSpread2(_objectSpread2({
27342 realIndex: realIndex,
27343 pathFill: pathFill.color
27344 }, pathFill.useRangeColor ? {
27345 lineFill: pathFill.color
27346 } : {}), {}, {
27347 j: j,
27348 i: i,
27349 columnGroupIndex: columnGroupIndex,
27350 pathFrom: paths.pathFrom,
27351 pathTo: paths.pathTo,
27352 strokeWidth: strokeWidth,
27353 elSeries: elSeries,
27354 x: x,
27355 y: y,
27356 series: series,
27357 barHeight: Math.abs(paths.barHeight ? paths.barHeight : barHeight),
27358 barWidth: Math.abs(paths.barWidth ? paths.barWidth : barWidth),
27359 elDataLabelsWrap: elDataLabelsWrap,
27360 elGoalsMarkers: elGoalsMarkers,
27361 elBarShadows: elBarShadows,
27362 visibleSeries: this.visibleI,
27363 type: 'bar'
27364 }));
27365 }
27366
27367 // push all x val arrays into main xArr
27368 w.globals.seriesXvalues[realIndex] = xArrj;
27369 w.globals.seriesYvalues[realIndex] = yArrj;
27370 ret.add(elSeries);
27371 }
27372 return ret;
27373 }
27374 }, {
27375 key: "renderSeries",
27376 value: function renderSeries(_ref) {
27377 var realIndex = _ref.realIndex,
27378 pathFill = _ref.pathFill,
27379 lineFill = _ref.lineFill,
27380 j = _ref.j,
27381 i = _ref.i,
27382 columnGroupIndex = _ref.columnGroupIndex,
27383 pathFrom = _ref.pathFrom,
27384 pathTo = _ref.pathTo,
27385 strokeWidth = _ref.strokeWidth,
27386 elSeries = _ref.elSeries,
27387 x = _ref.x,
27388 y = _ref.y,
27389 y1 = _ref.y1,
27390 y2 = _ref.y2,
27391 series = _ref.series,
27392 barHeight = _ref.barHeight,
27393 barWidth = _ref.barWidth,
27394 barXPosition = _ref.barXPosition,
27395 barYPosition = _ref.barYPosition,
27396 elDataLabelsWrap = _ref.elDataLabelsWrap,
27397 elGoalsMarkers = _ref.elGoalsMarkers,
27398 elBarShadows = _ref.elBarShadows,
27399 visibleSeries = _ref.visibleSeries,
27400 type = _ref.type,
27401 classes = _ref.classes;
27402 var w = this.w;
27403 var graphics = new Graphics(this.ctx);
27404 var skipDrawing = false;
27405 if (!lineFill) {
27406 // if user provided a function in colors, we need to eval here
27407 // Note: the position of this function logic (ex. stroke: { colors: ["",function(){}] }) i.e array index 1 depicts the realIndex/seriesIndex.
27408 var fetchColor = function fetchColor(i) {
27409 var exp = w.config.stroke.colors;
27410 var c;
27411 if (Array.isArray(exp) && exp.length > 0) {
27412 c = exp[i];
27413 if (!c) c = '';
27414 if (typeof c === 'function') {
27415 return c({
27416 value: w.globals.series[i][j],
27417 dataPointIndex: j,
27418 w: w
27419 });
27420 }
27421 }
27422 return c;
27423 };
27424 var checkAvailableColor = typeof w.globals.stroke.colors[realIndex] === 'function' ? fetchColor(realIndex) : w.globals.stroke.colors[realIndex];
27425
27426 /* fix apexcharts#341 */
27427 lineFill = this.barOptions.distributed ? w.globals.stroke.colors[j] : checkAvailableColor;
27428 }
27429 var barDataLabels = new BarDataLabels(this);
27430 var dataLabelsObj = barDataLabels.handleBarDataLabels({
27431 x: x,
27432 y: y,
27433 y1: y1,
27434 y2: y2,
27435 i: i,
27436 j: j,
27437 series: series,
27438 realIndex: realIndex,
27439 columnGroupIndex: columnGroupIndex,
27440 barHeight: barHeight,
27441 barWidth: barWidth,
27442 barXPosition: barXPosition,
27443 barYPosition: barYPosition,
27444 visibleSeries: visibleSeries
27445 });
27446 if (!w.globals.isBarHorizontal) {
27447 if (dataLabelsObj.dataLabelsPos.dataLabelsX + barWidth < 0 || dataLabelsObj.dataLabelsPos.dataLabelsX - barWidth > w.globals.gridWidth) {
27448 skipDrawing = true;
27449 }
27450 }
27451 if (w.config.series[i].data[j] && w.config.series[i].data[j].strokeColor) {
27452 lineFill = w.config.series[i].data[j].strokeColor;
27453 }
27454 if (this.isNullValue) {
27455 pathFill = 'none';
27456 }
27457 var delay = j / w.config.chart.animations.animateGradually.delay * (w.config.chart.animations.speed / w.globals.dataPoints) / 2.4;
27458 if (!skipDrawing) {
27459 var renderedPath = graphics.renderPaths({
27460 i: i,
27461 j: j,
27462 realIndex: realIndex,
27463 pathFrom: pathFrom,
27464 pathTo: pathTo,
27465 stroke: lineFill,
27466 strokeWidth: strokeWidth,
27467 strokeLineCap: w.config.stroke.lineCap,
27468 fill: pathFill,
27469 animationDelay: delay,
27470 initialSpeed: w.config.chart.animations.speed,
27471 dataChangeSpeed: w.config.chart.animations.dynamicAnimation.speed,
27472 className: "apexcharts-".concat(type, "-area ").concat(classes),
27473 chartType: type
27474 });
27475 renderedPath.attr('clip-path', "url(#gridRectBarMask".concat(w.globals.cuid, ")"));
27476 var forecast = w.config.forecastDataPoints;
27477 if (forecast.count > 0) {
27478 if (j >= w.globals.dataPoints - forecast.count) {
27479 renderedPath.node.setAttribute('stroke-dasharray', forecast.dashArray);
27480 renderedPath.node.setAttribute('stroke-width', forecast.strokeWidth);
27481 renderedPath.node.setAttribute('fill-opacity', forecast.fillOpacity);
27482 }
27483 }
27484 if (typeof y1 !== 'undefined' && typeof y2 !== 'undefined') {
27485 renderedPath.attr('data-range-y1', y1);
27486 renderedPath.attr('data-range-y2', y2);
27487 }
27488 var filters = new Filters(this.ctx);
27489 filters.setSelectionFilter(renderedPath, realIndex, j);
27490 elSeries.add(renderedPath);
27491 renderedPath.attr({
27492 cy: dataLabelsObj.dataLabelsPos.bcy,
27493 cx: dataLabelsObj.dataLabelsPos.bcx,
27494 j: j,
27495 val: w.globals.series[i][j],
27496 barHeight: barHeight,
27497 barWidth: barWidth
27498 });
27499 if (dataLabelsObj.dataLabels !== null) {
27500 elDataLabelsWrap.add(dataLabelsObj.dataLabels);
27501 }
27502 if (dataLabelsObj.totalDataLabels) {
27503 elDataLabelsWrap.add(dataLabelsObj.totalDataLabels);
27504 }
27505 elSeries.add(elDataLabelsWrap);
27506 if (elGoalsMarkers) {
27507 elSeries.add(elGoalsMarkers);
27508 }
27509 if (elBarShadows) {
27510 elSeries.add(elBarShadows);
27511 }
27512 }
27513 return elSeries;
27514 }
27515 }, {
27516 key: "drawBarPaths",
27517 value: function drawBarPaths(_ref2) {
27518 var indexes = _ref2.indexes,
27519 barHeight = _ref2.barHeight,
27520 strokeWidth = _ref2.strokeWidth,
27521 zeroW = _ref2.zeroW,
27522 x = _ref2.x,
27523 y = _ref2.y,
27524 yDivision = _ref2.yDivision,
27525 elSeries = _ref2.elSeries;
27526 var w = this.w;
27527 var i = indexes.i;
27528 var j = indexes.j;
27529 var barYPosition;
27530 if (w.globals.isXNumeric) {
27531 y = (w.globals.seriesX[i][j] - w.globals.minX) / this.invertedXRatio - barHeight;
27532 barYPosition = y + barHeight * this.visibleI;
27533 } else {
27534 if (w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
27535 var _this$barHelpers$getZ = this.barHelpers.getZeroValueEncounters({
27536 i: i,
27537 j: j
27538 }),
27539 nonZeroColumns = _this$barHelpers$getZ.nonZeroColumns,
27540 zeroEncounters = _this$barHelpers$getZ.zeroEncounters;
27541 if (nonZeroColumns > 0) {
27542 barHeight = this.seriesLen * barHeight / nonZeroColumns;
27543 }
27544 barYPosition = y + barHeight * this.visibleI;
27545 barYPosition -= barHeight * zeroEncounters;
27546 } else {
27547 barYPosition = y + barHeight * this.visibleI;
27548 }
27549 }
27550 if (this.isFunnel) {
27551 zeroW = zeroW - (this.barHelpers.getXForValue(this.series[i][j], zeroW) - zeroW) / 2;
27552 }
27553 x = this.barHelpers.getXForValue(this.series[i][j], zeroW);
27554 var paths = this.barHelpers.getBarpaths({
27555 barYPosition: barYPosition,
27556 barHeight: barHeight,
27557 x1: zeroW,
27558 x2: x,
27559 strokeWidth: strokeWidth,
27560 isReversed: this.isReversed,
27561 series: this.series,
27562 realIndex: indexes.realIndex,
27563 i: i,
27564 j: j,
27565 w: w
27566 });
27567 if (!w.globals.isXNumeric) {
27568 y = y + yDivision;
27569 }
27570 this.barHelpers.barBackground({
27571 j: j,
27572 i: i,
27573 y1: barYPosition - barHeight * this.visibleI,
27574 y2: barHeight * this.seriesLen,
27575 elSeries: elSeries
27576 });
27577 return {
27578 pathTo: paths.pathTo,
27579 pathFrom: paths.pathFrom,
27580 x1: zeroW,
27581 x: x,
27582 y: y,
27583 goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j),
27584 barYPosition: barYPosition,
27585 barHeight: barHeight
27586 };
27587 }
27588 }, {
27589 key: "drawColumnPaths",
27590 value: function drawColumnPaths(_ref3) {
27591 var indexes = _ref3.indexes,
27592 x = _ref3.x,
27593 y = _ref3.y,
27594 xDivision = _ref3.xDivision,
27595 barWidth = _ref3.barWidth,
27596 zeroH = _ref3.zeroH,
27597 strokeWidth = _ref3.strokeWidth,
27598 elSeries = _ref3.elSeries;
27599 var w = this.w;
27600 var realIndex = indexes.realIndex;
27601 var translationsIndex = indexes.translationsIndex;
27602 var i = indexes.i;
27603 var j = indexes.j;
27604 var bc = indexes.bc;
27605 var barXPosition;
27606 if (w.globals.isXNumeric) {
27607 var xForNumericX = this.getBarXForNumericXAxis({
27608 x: x,
27609 j: j,
27610 realIndex: realIndex,
27611 barWidth: barWidth
27612 });
27613 x = xForNumericX.x;
27614 barXPosition = xForNumericX.barXPosition;
27615 } else {
27616 if (w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
27617 var _this$barHelpers$getZ2 = this.barHelpers.getZeroValueEncounters({
27618 i: i,
27619 j: j
27620 }),
27621 nonZeroColumns = _this$barHelpers$getZ2.nonZeroColumns,
27622 zeroEncounters = _this$barHelpers$getZ2.zeroEncounters;
27623 if (nonZeroColumns > 0) {
27624 barWidth = this.seriesLen * barWidth / nonZeroColumns;
27625 }
27626 barXPosition = x + barWidth * this.visibleI;
27627 barXPosition -= barWidth * zeroEncounters;
27628 } else {
27629 barXPosition = x + barWidth * this.visibleI;
27630 }
27631 }
27632 y = this.barHelpers.getYForValue(this.series[i][j], zeroH, translationsIndex);
27633 var paths = this.barHelpers.getColumnPaths({
27634 barXPosition: barXPosition,
27635 barWidth: barWidth,
27636 y1: zeroH,
27637 y2: y,
27638 strokeWidth: strokeWidth,
27639 isReversed: this.isReversed,
27640 series: this.series,
27641 realIndex: realIndex,
27642 i: i,
27643 j: j,
27644 w: w
27645 });
27646 if (!w.globals.isXNumeric) {
27647 x = x + xDivision;
27648 }
27649 this.barHelpers.barBackground({
27650 bc: bc,
27651 j: j,
27652 i: i,
27653 x1: barXPosition - strokeWidth / 2 - barWidth * this.visibleI,
27654 x2: barWidth * this.seriesLen + strokeWidth / 2,
27655 elSeries: elSeries
27656 });
27657 return {
27658 pathTo: paths.pathTo,
27659 pathFrom: paths.pathFrom,
27660 x: x,
27661 y: y,
27662 goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
27663 barXPosition: barXPosition,
27664 barWidth: barWidth
27665 };
27666 }
27667 }, {
27668 key: "getBarXForNumericXAxis",
27669 value: function getBarXForNumericXAxis(_ref4) {
27670 var x = _ref4.x,
27671 barWidth = _ref4.barWidth,
27672 realIndex = _ref4.realIndex,
27673 j = _ref4.j;
27674 var w = this.w;
27675 var sxI = realIndex;
27676 if (!w.globals.seriesX[realIndex].length) {
27677 sxI = w.globals.maxValsInArrayIndex;
27678 }
27679 if (Utils$1.isNumber(w.globals.seriesX[sxI][j])) {
27680 x = (w.globals.seriesX[sxI][j] - w.globals.minX) / this.xRatio - barWidth * this.seriesLen / 2;
27681 }
27682 return {
27683 barXPosition: x + barWidth * this.visibleI,
27684 x: x
27685 };
27686 }
27687
27688 /** getPreviousPath is a common function for bars/columns which is used to get previous paths when data changes.
27689 * @memberof Bar
27690 * @param {int} realIndex - current iterating i
27691 * @param {int} j - current iterating series's j index
27692 * @return {string} pathFrom is the string which will be appended in animations
27693 **/
27694 }, {
27695 key: "getPreviousPath",
27696 value: function getPreviousPath(realIndex, j) {
27697 var w = this.w;
27698 var pathFrom = 'M 0 0';
27699 for (var pp = 0; pp < w.globals.previousPaths.length; pp++) {
27700 var gpp = w.globals.previousPaths[pp];
27701 if (gpp.paths && gpp.paths.length > 0 && parseInt(gpp.realIndex, 10) === parseInt(realIndex, 10)) {
27702 if (typeof w.globals.previousPaths[pp].paths[j] !== 'undefined') {
27703 pathFrom = w.globals.previousPaths[pp].paths[j].d;
27704 }
27705 }
27706 }
27707 return pathFrom;
27708 }
27709 }]);
27710 return Bar;
27711 }();
27712
27713 /**
27714 * ApexCharts BarStacked Class responsible for drawing both Stacked Columns and Bars.
27715 *
27716 * @module BarStacked
27717 * The whole calculation for stacked bar/column is different from normal bar/column,
27718 * hence it makes sense to derive a new class for it extending most of the props of Parent Bar
27719 **/
27720 var BarStacked = /*#__PURE__*/function (_Bar) {
27721 _inherits(BarStacked, _Bar);
27722 var _super = _createSuper(BarStacked);
27723 function BarStacked() {
27724 _classCallCheck(this, BarStacked);
27725 return _super.apply(this, arguments);
27726 }
27727 _createClass(BarStacked, [{
27728 key: "draw",
27729 value: function draw(series, seriesIndex) {
27730 var _this = this;
27731 var w = this.w;
27732 this.graphics = new Graphics(this.ctx);
27733 this.bar = new Bar(this.ctx, this.xyRatios);
27734 var coreUtils = new CoreUtils(this.ctx, w);
27735 series = coreUtils.getLogSeries(series);
27736 this.yRatio = coreUtils.getLogYRatios(this.yRatio);
27737 this.barHelpers.initVariables(series);
27738 if (w.config.chart.stackType === '100%') {
27739 series = w.globals.comboCharts ? seriesIndex.map(function (_) {
27740 return w.globals.seriesPercent[_];
27741 }) : w.globals.seriesPercent.slice();
27742 }
27743 this.series = series;
27744 this.barHelpers.initializeStackedPrevVars(this);
27745 var ret = this.graphics.group({
27746 class: 'apexcharts-bar-series apexcharts-plot-series'
27747 });
27748 var x = 0;
27749 var y = 0;
27750 var _loop = function _loop(i, bc) {
27751 var xDivision = void 0; // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
27752 var yDivision = void 0; // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
27753 var zeroH = void 0; // zeroH is the baseline where 0 meets y axis
27754 var zeroW = void 0; // zeroW is the baseline where 0 meets x axis
27755
27756 var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
27757 var _this$barHelpers$getG = _this.barHelpers.getGroupIndex(realIndex),
27758 groupIndex = _this$barHelpers$getG.groupIndex,
27759 columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
27760 _this.groupCtx = _this[w.globals.seriesGroups[groupIndex]];
27761 var xArrValues = [];
27762 var yArrValues = [];
27763 var translationsIndex = 0;
27764 if (_this.yRatio.length > 1) {
27765 _this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0];
27766 translationsIndex = realIndex;
27767 }
27768 _this.isReversed = w.config.yaxis[_this.yaxisIndex] && w.config.yaxis[_this.yaxisIndex].reversed;
27769
27770 // el to which series will be drawn
27771 var elSeries = _this.graphics.group({
27772 class: "apexcharts-series",
27773 seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
27774 rel: i + 1,
27775 'data:realIndex': realIndex
27776 });
27777 _this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
27778
27779 // eldatalabels
27780 var elDataLabelsWrap = _this.graphics.group({
27781 class: 'apexcharts-datalabels',
27782 'data:realIndex': realIndex
27783 });
27784 var elGoalsMarkers = _this.graphics.group({
27785 class: 'apexcharts-bar-goals-markers'
27786 });
27787 var barHeight = 0;
27788 var barWidth = 0;
27789 var initPositions = _this.initialPositions(x, y, xDivision, yDivision, zeroH, zeroW, translationsIndex);
27790 y = initPositions.y;
27791 barHeight = initPositions.barHeight;
27792 yDivision = initPositions.yDivision;
27793 zeroW = initPositions.zeroW;
27794 x = initPositions.x;
27795 barWidth = initPositions.barWidth;
27796 xDivision = initPositions.xDivision;
27797 zeroH = initPositions.zeroH;
27798 w.globals.barHeight = barHeight;
27799 w.globals.barWidth = barWidth;
27800 _this.barHelpers.initializeStackedXYVars(_this);
27801
27802 // where all stack bar disappear after collapsing the first series
27803 if (_this.groupCtx.prevY.length === 1 && _this.groupCtx.prevY[0].every(function (val) {
27804 return isNaN(val);
27805 })) {
27806 _this.groupCtx.prevY[0] = _this.groupCtx.prevY[0].map(function () {
27807 return zeroH;
27808 });
27809 _this.groupCtx.prevYF[0] = _this.groupCtx.prevYF[0].map(function () {
27810 return 0;
27811 });
27812 }
27813 for (var j = 0; j < w.globals.dataPoints; j++) {
27814 var strokeWidth = _this.barHelpers.getStrokeWidth(i, j, realIndex);
27815 var commonPathOpts = {
27816 indexes: {
27817 i: i,
27818 j: j,
27819 realIndex: realIndex,
27820 translationsIndex: translationsIndex,
27821 bc: bc
27822 },
27823 strokeWidth: strokeWidth,
27824 x: x,
27825 y: y,
27826 elSeries: elSeries,
27827 columnGroupIndex: columnGroupIndex,
27828 seriesGroup: w.globals.seriesGroups[groupIndex]
27829 };
27830 var paths = null;
27831 if (_this.isHorizontal) {
27832 paths = _this.drawStackedBarPaths(_objectSpread2(_objectSpread2({}, commonPathOpts), {}, {
27833 zeroW: zeroW,
27834 barHeight: barHeight,
27835 yDivision: yDivision
27836 }));
27837 barWidth = _this.series[i][j] / _this.invertedYRatio;
27838 } else {
27839 paths = _this.drawStackedColumnPaths(_objectSpread2(_objectSpread2({}, commonPathOpts), {}, {
27840 xDivision: xDivision,
27841 barWidth: barWidth,
27842 zeroH: zeroH
27843 }));
27844 barHeight = _this.series[i][j] / _this.yRatio[translationsIndex];
27845 }
27846 var barGoalLine = _this.barHelpers.drawGoalLine({
27847 barXPosition: paths.barXPosition,
27848 barYPosition: paths.barYPosition,
27849 goalX: paths.goalX,
27850 goalY: paths.goalY,
27851 barHeight: barHeight,
27852 barWidth: barWidth
27853 });
27854 if (barGoalLine) {
27855 elGoalsMarkers.add(barGoalLine);
27856 }
27857 y = paths.y;
27858 x = paths.x;
27859 xArrValues.push(x);
27860 yArrValues.push(y);
27861 var pathFill = _this.barHelpers.getPathFillColor(series, i, j, realIndex);
27862 var classes = '';
27863 var flipClass = w.globals.isBarHorizontal ? 'apexcharts-flip-x' : 'apexcharts-flip-y';
27864 if (_this.barHelpers.arrBorderRadius[realIndex][j] === 'bottom' && w.globals.series[realIndex][j] > 0 || _this.barHelpers.arrBorderRadius[realIndex][j] === 'top' && w.globals.series[realIndex][j] < 0) {
27865 classes = flipClass;
27866 }
27867 elSeries = _this.renderSeries(_objectSpread2(_objectSpread2({
27868 realIndex: realIndex,
27869 pathFill: pathFill.color
27870 }, pathFill.useRangeColor ? {
27871 lineFill: pathFill.color
27872 } : {}), {}, {
27873 j: j,
27874 i: i,
27875 columnGroupIndex: columnGroupIndex,
27876 pathFrom: paths.pathFrom,
27877 pathTo: paths.pathTo,
27878 strokeWidth: strokeWidth,
27879 elSeries: elSeries,
27880 x: x,
27881 y: y,
27882 series: series,
27883 barHeight: barHeight,
27884 barWidth: barWidth,
27885 elDataLabelsWrap: elDataLabelsWrap,
27886 elGoalsMarkers: elGoalsMarkers,
27887 type: 'bar',
27888 visibleSeries: columnGroupIndex,
27889 classes: classes
27890 }));
27891 }
27892
27893 // push all x val arrays into main xArr
27894 w.globals.seriesXvalues[realIndex] = xArrValues;
27895 w.globals.seriesYvalues[realIndex] = yArrValues;
27896
27897 // push all current y values array to main PrevY Array
27898 _this.groupCtx.prevY.push(_this.groupCtx.yArrj);
27899 _this.groupCtx.prevYF.push(_this.groupCtx.yArrjF);
27900 _this.groupCtx.prevYVal.push(_this.groupCtx.yArrjVal);
27901 _this.groupCtx.prevX.push(_this.groupCtx.xArrj);
27902 _this.groupCtx.prevXF.push(_this.groupCtx.xArrjF);
27903 _this.groupCtx.prevXVal.push(_this.groupCtx.xArrjVal);
27904 ret.add(elSeries);
27905 };
27906 for (var i = 0, bc = 0; i < series.length; i++, bc++) {
27907 _loop(i, bc);
27908 }
27909 return ret;
27910 }
27911 }, {
27912 key: "initialPositions",
27913 value: function initialPositions(x, y, xDivision, yDivision, zeroH, zeroW, translationsIndex) {
27914 var w = this.w;
27915 var barHeight, barWidth;
27916 if (this.isHorizontal) {
27917 // height divided into equal parts
27918 yDivision = w.globals.gridHeight / w.globals.dataPoints;
27919 var userBarHeight = w.config.plotOptions.bar.barHeight;
27920 if (String(userBarHeight).indexOf('%') === -1) {
27921 barHeight = parseInt(userBarHeight, 10);
27922 } else {
27923 barHeight = yDivision * parseInt(userBarHeight, 10) / 100;
27924 }
27925 zeroW = w.globals.padHorizontal + (this.isReversed ? w.globals.gridWidth - this.baseLineInvertedY : this.baseLineInvertedY);
27926
27927 // initial y position is half of barHeight * half of number of Bars
27928 y = (yDivision - barHeight) / 2;
27929 } else {
27930 // width divided into equal parts
27931 xDivision = w.globals.gridWidth / w.globals.dataPoints;
27932 barWidth = xDivision;
27933 var userColumnWidth = w.config.plotOptions.bar.columnWidth;
27934 if (w.globals.isXNumeric && w.globals.dataPoints > 1) {
27935 xDivision = w.globals.minXDiff / this.xRatio;
27936 barWidth = xDivision * parseInt(this.barOptions.columnWidth, 10) / 100;
27937 } else if (String(userColumnWidth).indexOf('%') === -1) {
27938 barWidth = parseInt(userColumnWidth, 10);
27939 } else {
27940 barWidth *= parseInt(userColumnWidth, 10) / 100;
27941 }
27942 if (this.isReversed) {
27943 zeroH = this.baseLineY[translationsIndex];
27944 } else {
27945 zeroH = w.globals.gridHeight - this.baseLineY[translationsIndex];
27946 }
27947
27948 // initial x position is the left-most edge of the first bar relative to
27949 // the left-most side of the grid area.
27950 x = w.globals.padHorizontal + (xDivision - barWidth) / 2;
27951 }
27952
27953 // Up to this point, barWidth is the width that will accommodate all bars
27954 // at each datapoint or category.
27955
27956 // The crude subdivision here assumes the series within each group are
27957 // stacked. If there is no stacking then the barWidth/barHeight is
27958 // further divided later by the number of series in the group. So, eg, two
27959 // groups of three series would become six bars side-by-side unstacked,
27960 // or two bars stacked.
27961 var subDivisions = w.globals.barGroups.length || 1;
27962 return {
27963 x: x,
27964 y: y,
27965 yDivision: yDivision,
27966 xDivision: xDivision,
27967 barHeight: barHeight / subDivisions,
27968 barWidth: barWidth / subDivisions,
27969 zeroH: zeroH,
27970 zeroW: zeroW
27971 };
27972 }
27973 }, {
27974 key: "drawStackedBarPaths",
27975 value: function drawStackedBarPaths(_ref) {
27976 var indexes = _ref.indexes,
27977 barHeight = _ref.barHeight,
27978 strokeWidth = _ref.strokeWidth,
27979 zeroW = _ref.zeroW,
27980 x = _ref.x,
27981 y = _ref.y,
27982 columnGroupIndex = _ref.columnGroupIndex,
27983 seriesGroup = _ref.seriesGroup,
27984 yDivision = _ref.yDivision,
27985 elSeries = _ref.elSeries;
27986 var w = this.w;
27987 var barYPosition = y + columnGroupIndex * barHeight;
27988 var barXPosition;
27989 var i = indexes.i;
27990 var j = indexes.j;
27991 var realIndex = indexes.realIndex;
27992 var translationsIndex = indexes.translationsIndex;
27993 var prevBarW = 0;
27994 for (var k = 0; k < this.groupCtx.prevXF.length; k++) {
27995 prevBarW = prevBarW + this.groupCtx.prevXF[k][j];
27996 }
27997 var gsi = i; // an index to keep track of the series inside a group
27998 if (w.config.series[realIndex].name) {
27999 gsi = seriesGroup.indexOf(w.config.series[realIndex].name);
28000 }
28001 if (gsi > 0) {
28002 var bXP = zeroW;
28003 if (this.groupCtx.prevXVal[gsi - 1][j] < 0) {
28004 bXP = this.series[i][j] >= 0 ? this.groupCtx.prevX[gsi - 1][j] + prevBarW - (this.isReversed ? prevBarW : 0) * 2 : this.groupCtx.prevX[gsi - 1][j];
28005 } else if (this.groupCtx.prevXVal[gsi - 1][j] >= 0) {
28006 bXP = this.series[i][j] >= 0 ? this.groupCtx.prevX[gsi - 1][j] : this.groupCtx.prevX[gsi - 1][j] - prevBarW + (this.isReversed ? prevBarW : 0) * 2;
28007 }
28008 barXPosition = bXP;
28009 } else {
28010 // the first series will not have prevX values
28011 barXPosition = zeroW;
28012 }
28013 if (this.series[i][j] === null) {
28014 x = barXPosition;
28015 } else {
28016 x = barXPosition + this.series[i][j] / this.invertedYRatio - (this.isReversed ? this.series[i][j] / this.invertedYRatio : 0) * 2;
28017 }
28018 var paths = this.barHelpers.getBarpaths({
28019 barYPosition: barYPosition,
28020 barHeight: barHeight,
28021 x1: barXPosition,
28022 x2: x,
28023 strokeWidth: strokeWidth,
28024 isReversed: this.isReversed,
28025 series: this.series,
28026 realIndex: indexes.realIndex,
28027 seriesGroup: seriesGroup,
28028 i: i,
28029 j: j,
28030 w: w
28031 });
28032 this.barHelpers.barBackground({
28033 j: j,
28034 i: i,
28035 y1: barYPosition,
28036 y2: barHeight,
28037 elSeries: elSeries
28038 });
28039 y = y + yDivision;
28040 return {
28041 pathTo: paths.pathTo,
28042 pathFrom: paths.pathFrom,
28043 goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j, translationsIndex),
28044 barXPosition: barXPosition,
28045 barYPosition: barYPosition,
28046 x: x,
28047 y: y
28048 };
28049 }
28050 }, {
28051 key: "drawStackedColumnPaths",
28052 value: function drawStackedColumnPaths(_ref2) {
28053 var indexes = _ref2.indexes,
28054 x = _ref2.x,
28055 y = _ref2.y,
28056 xDivision = _ref2.xDivision,
28057 barWidth = _ref2.barWidth,
28058 zeroH = _ref2.zeroH,
28059 columnGroupIndex = _ref2.columnGroupIndex,
28060 seriesGroup = _ref2.seriesGroup,
28061 elSeries = _ref2.elSeries;
28062 var w = this.w;
28063 var i = indexes.i;
28064 var j = indexes.j;
28065 var bc = indexes.bc;
28066 var realIndex = indexes.realIndex;
28067 var translationsIndex = indexes.translationsIndex;
28068 if (w.globals.isXNumeric) {
28069 var seriesVal = w.globals.seriesX[realIndex][j];
28070 if (!seriesVal) seriesVal = 0;
28071 // TODO: move the barWidth factor to barXPosition
28072 x = (seriesVal - w.globals.minX) / this.xRatio - barWidth / 2 * w.globals.barGroups.length;
28073 }
28074 var barXPosition = x + columnGroupIndex * barWidth;
28075 var barYPosition;
28076 var prevBarH = 0;
28077 for (var k = 0; k < this.groupCtx.prevYF.length; k++) {
28078 // fix issue #1215
28079 // in case where this.groupCtx.prevYF[k][j] is NaN, use 0 instead
28080 prevBarH = prevBarH + (!isNaN(this.groupCtx.prevYF[k][j]) ? this.groupCtx.prevYF[k][j] : 0);
28081 }
28082 var gsi = i; // an index to keep track of the series inside a group
28083 if (seriesGroup) {
28084 gsi = seriesGroup.indexOf(w.globals.seriesNames[realIndex]);
28085 }
28086 if (gsi > 0 && !w.globals.isXNumeric || gsi > 0 && w.globals.isXNumeric && w.globals.seriesX[realIndex - 1][j] === w.globals.seriesX[realIndex][j]) {
28087 var _this$groupCtx$prevYF;
28088 var bYP;
28089 var prevYValue;
28090 var p = Math.min(this.yRatio.length + 1, realIndex + 1);
28091 if (this.groupCtx.prevY[gsi - 1] !== undefined && this.groupCtx.prevY[gsi - 1].length) {
28092 for (var ii = 1; ii < p; ii++) {
28093 var _this$groupCtx$prevY;
28094 if (!isNaN((_this$groupCtx$prevY = this.groupCtx.prevY[gsi - ii]) === null || _this$groupCtx$prevY === void 0 ? void 0 : _this$groupCtx$prevY[j])) {
28095 // find the previous available value to give prevYValue
28096 prevYValue = this.groupCtx.prevY[gsi - ii][j];
28097 // if found it, break the loop
28098 break;
28099 }
28100 }
28101 }
28102 for (var _ii = 1; _ii < p; _ii++) {
28103 var _this$groupCtx$prevYV, _this$groupCtx$prevYV2;
28104 // find the previous available value(non-NaN) to give bYP
28105 if (((_this$groupCtx$prevYV = this.groupCtx.prevYVal[gsi - _ii]) === null || _this$groupCtx$prevYV === void 0 ? void 0 : _this$groupCtx$prevYV[j]) < 0) {
28106 bYP = this.series[i][j] >= 0 ? prevYValue - prevBarH + (this.isReversed ? prevBarH : 0) * 2 : prevYValue;
28107 // found it? break the loop
28108 break;
28109 } else if (((_this$groupCtx$prevYV2 = this.groupCtx.prevYVal[gsi - _ii]) === null || _this$groupCtx$prevYV2 === void 0 ? void 0 : _this$groupCtx$prevYV2[j]) >= 0) {
28110 bYP = this.series[i][j] >= 0 ? prevYValue : prevYValue + prevBarH - (this.isReversed ? prevBarH : 0) * 2;
28111 // found it? break the loop
28112 break;
28113 }
28114 }
28115 if (typeof bYP === 'undefined') bYP = w.globals.gridHeight;
28116
28117 // if this.prevYF[0] is all 0 resulted from line #486
28118 // AND every arr starting from the second only contains NaN
28119 if ((_this$groupCtx$prevYF = this.groupCtx.prevYF[0]) !== null && _this$groupCtx$prevYF !== void 0 && _this$groupCtx$prevYF.every(function (val) {
28120 return val === 0;
28121 }) && this.groupCtx.prevYF.slice(1, gsi).every(function (arr) {
28122 return arr.every(function (val) {
28123 return isNaN(val);
28124 });
28125 })) {
28126 barYPosition = zeroH;
28127 } else {
28128 // Nothing special
28129 barYPosition = bYP;
28130 }
28131 } else {
28132 // the first series will not have prevY values, also if the prev index's
28133 // series X doesn't matches the current index's series X, then start from
28134 // zero
28135 barYPosition = zeroH;
28136 }
28137 if (this.series[i][j]) {
28138 y = barYPosition - this.series[i][j] / this.yRatio[translationsIndex] + (this.isReversed ? this.series[i][j] / this.yRatio[translationsIndex] : 0) * 2;
28139 } else {
28140 // fixes #3610
28141 y = barYPosition;
28142 }
28143 var paths = this.barHelpers.getColumnPaths({
28144 barXPosition: barXPosition,
28145 barWidth: barWidth,
28146 y1: barYPosition,
28147 y2: y,
28148 yRatio: this.yRatio[translationsIndex],
28149 strokeWidth: this.strokeWidth,
28150 isReversed: this.isReversed,
28151 series: this.series,
28152 seriesGroup: seriesGroup,
28153 realIndex: indexes.realIndex,
28154 i: i,
28155 j: j,
28156 w: w
28157 });
28158 this.barHelpers.barBackground({
28159 bc: bc,
28160 j: j,
28161 i: i,
28162 x1: barXPosition,
28163 x2: barWidth,
28164 elSeries: elSeries
28165 });
28166 return {
28167 pathTo: paths.pathTo,
28168 pathFrom: paths.pathFrom,
28169 goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j),
28170 barXPosition: barXPosition,
28171 x: w.globals.isXNumeric ? x : x + xDivision,
28172 y: y
28173 };
28174 }
28175 }]);
28176 return BarStacked;
28177 }(Bar);
28178
28179 /**
28180 * ApexCharts BoxCandleStick Class responsible for drawing both Stacked Columns and Bars.
28181 *
28182 * @module BoxCandleStick
28183 **/
28184 var BoxCandleStick = /*#__PURE__*/function (_Bar) {
28185 _inherits(BoxCandleStick, _Bar);
28186 var _super = _createSuper(BoxCandleStick);
28187 function BoxCandleStick() {
28188 _classCallCheck(this, BoxCandleStick);
28189 return _super.apply(this, arguments);
28190 }
28191 _createClass(BoxCandleStick, [{
28192 key: "draw",
28193 value: function draw(series, ctype, seriesIndex) {
28194 var _this = this;
28195 var w = this.w;
28196 var graphics = new Graphics(this.ctx);
28197 var type = w.globals.comboCharts ? ctype : w.config.chart.type;
28198 var fill = new Fill(this.ctx);
28199 this.candlestickOptions = this.w.config.plotOptions.candlestick;
28200 this.boxOptions = this.w.config.plotOptions.boxPlot;
28201 this.isHorizontal = w.config.plotOptions.bar.horizontal;
28202 // Add new property to check if we're using OHLC type
28203 this.isOHLC = this.candlestickOptions && this.candlestickOptions.type === 'ohlc';
28204 var coreUtils = new CoreUtils(this.ctx, w);
28205 series = coreUtils.getLogSeries(series);
28206 this.series = series;
28207 this.yRatio = coreUtils.getLogYRatios(this.yRatio);
28208 this.barHelpers.initVariables(series);
28209 var ret = graphics.group({
28210 class: "apexcharts-".concat(type, "-series apexcharts-plot-series")
28211 });
28212 var _loop = function _loop(i) {
28213 _this.isBoxPlot = w.config.chart.type === 'boxPlot' || w.config.series[i].type === 'boxPlot';
28214 var x = void 0,
28215 y = void 0,
28216 xDivision = void 0,
28217 // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
28218 yDivision = void 0,
28219 // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
28220 zeroH = void 0,
28221 // zeroH is the baseline where 0 meets y axis
28222 zeroW = void 0; // zeroW is the baseline where 0 meets x axis
28223
28224 var yArrj = []; // hold y values of current iterating series
28225 var xArrj = []; // hold x values of current iterating series
28226
28227 var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
28228 // As BoxCandleStick derives from Bar, we need this to render.
28229 var _this$barHelpers$getG = _this.barHelpers.getGroupIndex(realIndex),
28230 columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
28231
28232 // el to which series will be drawn
28233 var elSeries = graphics.group({
28234 class: "apexcharts-series",
28235 seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
28236 rel: i + 1,
28237 'data:realIndex': realIndex
28238 });
28239 _this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
28240 if (series[i].length > 0) {
28241 _this.visibleI = _this.visibleI + 1;
28242 }
28243 var barHeight = 0;
28244 var barWidth = 0;
28245 var translationsIndex = 0;
28246 if (_this.yRatio.length > 1) {
28247 _this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0];
28248 translationsIndex = realIndex;
28249 }
28250 var initPositions = _this.barHelpers.initialPositions(realIndex);
28251 y = initPositions.y;
28252 barHeight = initPositions.barHeight;
28253 yDivision = initPositions.yDivision;
28254 zeroW = initPositions.zeroW;
28255 x = initPositions.x;
28256 barWidth = initPositions.barWidth;
28257 xDivision = initPositions.xDivision;
28258 zeroH = initPositions.zeroH;
28259 xArrj.push(x + barWidth / 2);
28260
28261 // eldatalabels
28262 var elDataLabelsWrap = graphics.group({
28263 class: 'apexcharts-datalabels',
28264 'data:realIndex': realIndex
28265 });
28266 var elGoalsMarkers = graphics.group({
28267 class: 'apexcharts-bar-goals-markers'
28268 });
28269 var _loop2 = function _loop2(j) {
28270 var strokeWidth = _this.barHelpers.getStrokeWidth(i, j, realIndex);
28271 var paths = null;
28272 var pathsParams = {
28273 indexes: {
28274 i: i,
28275 j: j,
28276 realIndex: realIndex,
28277 translationsIndex: translationsIndex
28278 },
28279 x: x,
28280 y: y,
28281 strokeWidth: strokeWidth,
28282 elSeries: elSeries
28283 };
28284 if (_this.isHorizontal) {
28285 paths = _this.drawHorizontalBoxPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
28286 yDivision: yDivision,
28287 barHeight: barHeight,
28288 zeroW: zeroW
28289 }));
28290 } else {
28291 paths = _this.drawVerticalBoxPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
28292 xDivision: xDivision,
28293 barWidth: barWidth,
28294 zeroH: zeroH
28295 }));
28296 }
28297 y = paths.y;
28298 x = paths.x;
28299 var barGoalLine = _this.barHelpers.drawGoalLine({
28300 barXPosition: paths.barXPosition,
28301 barYPosition: paths.barYPosition,
28302 goalX: paths.goalX,
28303 goalY: paths.goalY,
28304 barHeight: barHeight,
28305 barWidth: barWidth
28306 });
28307 if (barGoalLine) {
28308 elGoalsMarkers.add(barGoalLine);
28309 }
28310
28311 // push current X
28312 if (j > 0) {
28313 xArrj.push(x + barWidth / 2);
28314 }
28315 yArrj.push(y);
28316 paths.pathTo.forEach(function (pathTo, pi) {
28317 var lineFill = !_this.isBoxPlot && _this.candlestickOptions.wick.useFillColor ? paths.color[pi] : w.globals.stroke.colors[i];
28318 var pathFill = fill.fillPath({
28319 seriesNumber: realIndex,
28320 dataPointIndex: j,
28321 color: paths.color[pi],
28322 value: series[i][j]
28323 });
28324 _this.renderSeries({
28325 realIndex: realIndex,
28326 pathFill: pathFill,
28327 lineFill: lineFill,
28328 j: j,
28329 i: i,
28330 pathFrom: paths.pathFrom,
28331 pathTo: pathTo,
28332 strokeWidth: strokeWidth,
28333 elSeries: elSeries,
28334 x: x,
28335 y: y,
28336 series: series,
28337 columnGroupIndex: columnGroupIndex,
28338 barHeight: barHeight,
28339 barWidth: barWidth,
28340 elDataLabelsWrap: elDataLabelsWrap,
28341 elGoalsMarkers: elGoalsMarkers,
28342 visibleSeries: _this.visibleI,
28343 type: w.config.chart.type
28344 });
28345 });
28346 };
28347 for (var j = 0; j < w.globals.dataPoints; j++) {
28348 _loop2(j);
28349 }
28350
28351 // push all x val arrays into main xArr
28352 w.globals.seriesXvalues[realIndex] = xArrj;
28353 w.globals.seriesYvalues[realIndex] = yArrj;
28354 ret.add(elSeries);
28355 };
28356 for (var i = 0; i < series.length; i++) {
28357 _loop(i);
28358 }
28359 return ret;
28360 }
28361 }, {
28362 key: "drawVerticalBoxPaths",
28363 value: function drawVerticalBoxPaths(_ref) {
28364 var indexes = _ref.indexes,
28365 x = _ref.x;
28366 _ref.y;
28367 var xDivision = _ref.xDivision,
28368 barWidth = _ref.barWidth,
28369 zeroH = _ref.zeroH,
28370 strokeWidth = _ref.strokeWidth;
28371 var w = this.w;
28372 var graphics = new Graphics(this.ctx);
28373 var i = indexes.i;
28374 var j = indexes.j;
28375 var candleColors = w.config.plotOptions.candlestick.colors;
28376 var boxColors = this.boxOptions.colors;
28377 var realIndex = indexes.realIndex;
28378 var getColor = function getColor(color) {
28379 return Array.isArray(color) ? color[realIndex] : color;
28380 };
28381 var colorPos = getColor(candleColors.upward);
28382 var colorNeg = getColor(candleColors.downward);
28383 var yRatio = this.yRatio[indexes.translationsIndex];
28384 var ohlc = this.getOHLCValue(realIndex, j);
28385 var l1 = zeroH;
28386 var l2 = zeroH;
28387 var color = ohlc.o < ohlc.c ? [colorPos] : [colorNeg];
28388 if (this.isBoxPlot) {
28389 color = [getColor(boxColors.lower), getColor(boxColors.upper)];
28390 }
28391 var y1 = Math.min(ohlc.o, ohlc.c);
28392 var y2 = Math.max(ohlc.o, ohlc.c);
28393 var m = ohlc.m;
28394 if (w.globals.isXNumeric) {
28395 x = (w.globals.seriesX[realIndex][j] - w.globals.minX) / this.xRatio - barWidth / 2;
28396 }
28397 var barXPosition = x + barWidth * this.visibleI;
28398 if (typeof this.series[i][j] === 'undefined' || this.series[i][j] === null) {
28399 y1 = zeroH;
28400 y2 = zeroH;
28401 } else {
28402 y1 = zeroH - y1 / yRatio;
28403 y2 = zeroH - y2 / yRatio;
28404 l1 = zeroH - ohlc.h / yRatio;
28405 l2 = zeroH - ohlc.l / yRatio;
28406 m = zeroH - ohlc.m / yRatio;
28407 }
28408 var pathTo = graphics.move(barXPosition, zeroH);
28409 var pathFrom = graphics.move(barXPosition + barWidth / 2, y1);
28410 if (w.globals.previousPaths.length > 0) {
28411 pathFrom = this.getPreviousPath(realIndex, j, true);
28412 }
28413 if (this.isOHLC) {
28414 var centerX = barXPosition + barWidth / 2;
28415 var openY = zeroH - ohlc.o / yRatio;
28416 var closeY = zeroH - ohlc.c / yRatio;
28417 pathTo = [graphics.move(centerX, l1) + graphics.line(centerX, l2) + graphics.move(centerX, openY) + graphics.line(barXPosition, openY) + graphics.move(centerX, closeY) + graphics.line(barXPosition + barWidth, closeY)];
28418 } else if (this.isBoxPlot) {
28419 pathTo = [graphics.move(barXPosition, y1) + graphics.line(barXPosition + barWidth / 2, y1) + graphics.line(barXPosition + barWidth / 2, l1) + graphics.line(barXPosition + barWidth / 4, l1) + graphics.line(barXPosition + barWidth - barWidth / 4, l1) + graphics.line(barXPosition + barWidth / 2, l1) + graphics.line(barXPosition + barWidth / 2, y1) + graphics.line(barXPosition + barWidth, y1) + graphics.line(barXPosition + barWidth, m) + graphics.line(barXPosition, m) + graphics.line(barXPosition, y1 + strokeWidth / 2), graphics.move(barXPosition, m) + graphics.line(barXPosition + barWidth, m) + graphics.line(barXPosition + barWidth, y2) + graphics.line(barXPosition + barWidth / 2, y2) + graphics.line(barXPosition + barWidth / 2, l2) + graphics.line(barXPosition + barWidth - barWidth / 4, l2) + graphics.line(barXPosition + barWidth / 4, l2) + graphics.line(barXPosition + barWidth / 2, l2) + graphics.line(barXPosition + barWidth / 2, y2) + graphics.line(barXPosition, y2) + graphics.line(barXPosition, m) + 'z'];
28420 } else {
28421 // Regular candlestick
28422 pathTo = [graphics.move(barXPosition, y2) + graphics.line(barXPosition + barWidth / 2, y2) + graphics.line(barXPosition + barWidth / 2, l1) + graphics.line(barXPosition + barWidth / 2, y2) + graphics.line(barXPosition + barWidth, y2) + graphics.line(barXPosition + barWidth, y1) + graphics.line(barXPosition + barWidth / 2, y1) + graphics.line(barXPosition + barWidth / 2, l2) + graphics.line(barXPosition + barWidth / 2, y1) + graphics.line(barXPosition, y1) + graphics.line(barXPosition, y2 - strokeWidth / 2)];
28423 }
28424 pathFrom = pathFrom + graphics.move(barXPosition, y1);
28425 if (!w.globals.isXNumeric) {
28426 x = x + xDivision;
28427 }
28428 return {
28429 pathTo: pathTo,
28430 pathFrom: pathFrom,
28431 x: x,
28432 y: y2,
28433 goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, indexes.translationsIndex),
28434 barXPosition: barXPosition,
28435 color: color
28436 };
28437 }
28438 }, {
28439 key: "drawHorizontalBoxPaths",
28440 value: function drawHorizontalBoxPaths(_ref2) {
28441 var indexes = _ref2.indexes;
28442 _ref2.x;
28443 var y = _ref2.y,
28444 yDivision = _ref2.yDivision,
28445 barHeight = _ref2.barHeight,
28446 zeroW = _ref2.zeroW,
28447 strokeWidth = _ref2.strokeWidth;
28448 var w = this.w;
28449 var graphics = new Graphics(this.ctx);
28450 var i = indexes.i;
28451 var j = indexes.j;
28452 var color = this.boxOptions.colors.lower;
28453 if (this.isBoxPlot) {
28454 color = [this.boxOptions.colors.lower, this.boxOptions.colors.upper];
28455 }
28456 var yRatio = this.invertedYRatio;
28457 var realIndex = indexes.realIndex;
28458 var ohlc = this.getOHLCValue(realIndex, j);
28459 var l1 = zeroW;
28460 var l2 = zeroW;
28461 var x1 = Math.min(ohlc.o, ohlc.c);
28462 var x2 = Math.max(ohlc.o, ohlc.c);
28463 var m = ohlc.m;
28464 if (w.globals.isXNumeric) {
28465 y = (w.globals.seriesX[realIndex][j] - w.globals.minX) / this.invertedXRatio - barHeight / 2;
28466 }
28467 var barYPosition = y + barHeight * this.visibleI;
28468 if (typeof this.series[i][j] === 'undefined' || this.series[i][j] === null) {
28469 x1 = zeroW;
28470 x2 = zeroW;
28471 } else {
28472 x1 = zeroW + x1 / yRatio;
28473 x2 = zeroW + x2 / yRatio;
28474 l1 = zeroW + ohlc.h / yRatio;
28475 l2 = zeroW + ohlc.l / yRatio;
28476 m = zeroW + ohlc.m / yRatio;
28477 }
28478 var pathTo = graphics.move(zeroW, barYPosition);
28479 var pathFrom = graphics.move(x1, barYPosition + barHeight / 2);
28480 if (w.globals.previousPaths.length > 0) {
28481 pathFrom = this.getPreviousPath(realIndex, j, true);
28482 }
28483 pathTo = [graphics.move(x1, barYPosition) + graphics.line(x1, barYPosition + barHeight / 2) + graphics.line(l1, barYPosition + barHeight / 2) + graphics.line(l1, barYPosition + barHeight / 2 - barHeight / 4) + graphics.line(l1, barYPosition + barHeight / 2 + barHeight / 4) + graphics.line(l1, barYPosition + barHeight / 2) + graphics.line(x1, barYPosition + barHeight / 2) + graphics.line(x1, barYPosition + barHeight) + graphics.line(m, barYPosition + barHeight) + graphics.line(m, barYPosition) + graphics.line(x1 + strokeWidth / 2, barYPosition), graphics.move(m, barYPosition) + graphics.line(m, barYPosition + barHeight) + graphics.line(x2, barYPosition + barHeight) + graphics.line(x2, barYPosition + barHeight / 2) + graphics.line(l2, barYPosition + barHeight / 2) + graphics.line(l2, barYPosition + barHeight - barHeight / 4) + graphics.line(l2, barYPosition + barHeight / 4) + graphics.line(l2, barYPosition + barHeight / 2) + graphics.line(x2, barYPosition + barHeight / 2) + graphics.line(x2, barYPosition) + graphics.line(m, barYPosition) + 'z'];
28484 pathFrom = pathFrom + graphics.move(x1, barYPosition);
28485 if (!w.globals.isXNumeric) {
28486 y = y + yDivision;
28487 }
28488 return {
28489 pathTo: pathTo,
28490 pathFrom: pathFrom,
28491 x: x2,
28492 y: y,
28493 goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j),
28494 barYPosition: barYPosition,
28495 color: color
28496 };
28497 }
28498 }, {
28499 key: "getOHLCValue",
28500 value: function getOHLCValue(i, j) {
28501 var w = this.w;
28502 var coreUtils = new CoreUtils(this.ctx, w);
28503 var h = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleH[i][j], i);
28504 var o = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleO[i][j], i);
28505 var m = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleM[i][j], i);
28506 var c = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleC[i][j], i);
28507 var l = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleL[i][j], i);
28508 return {
28509 o: this.isBoxPlot ? h : o,
28510 h: this.isBoxPlot ? o : h,
28511 m: m,
28512 l: this.isBoxPlot ? c : l,
28513 c: this.isBoxPlot ? l : c
28514 };
28515 }
28516 }]);
28517 return BoxCandleStick;
28518 }(Bar);
28519
28520 var TreemapHelpers = /*#__PURE__*/function () {
28521 function TreemapHelpers(ctx) {
28522 _classCallCheck(this, TreemapHelpers);
28523 this.ctx = ctx;
28524 this.w = ctx.w;
28525 }
28526 _createClass(TreemapHelpers, [{
28527 key: "checkColorRange",
28528 value: function checkColorRange() {
28529 var w = this.w;
28530 var negRange = false;
28531 var chartOpts = w.config.plotOptions[w.config.chart.type];
28532 if (chartOpts.colorScale.ranges.length > 0) {
28533 chartOpts.colorScale.ranges.map(function (range, index) {
28534 if (range.from <= 0) {
28535 negRange = true;
28536 }
28537 });
28538 }
28539 return negRange;
28540 }
28541 }, {
28542 key: "getShadeColor",
28543 value: function getShadeColor(chartType, i, j, negRange) {
28544 var w = this.w;
28545 var colorShadePercent = 1;
28546 var shadeIntensity = w.config.plotOptions[chartType].shadeIntensity;
28547 var colorProps = this.determineColor(chartType, i, j);
28548 if (w.globals.hasNegs || negRange) {
28549 if (w.config.plotOptions[chartType].reverseNegativeShade) {
28550 if (colorProps.percent < 0) {
28551 colorShadePercent = colorProps.percent / 100 * (shadeIntensity * 1.25);
28552 } else {
28553 colorShadePercent = (1 - colorProps.percent / 100) * (shadeIntensity * 1.25);
28554 }
28555 } else {
28556 if (colorProps.percent <= 0) {
28557 colorShadePercent = 1 - (1 + colorProps.percent / 100) * shadeIntensity;
28558 } else {
28559 colorShadePercent = (1 - colorProps.percent / 100) * shadeIntensity;
28560 }
28561 }
28562 } else {
28563 colorShadePercent = 1 - colorProps.percent / 100;
28564 if (chartType === 'treemap') {
28565 colorShadePercent = (1 - colorProps.percent / 100) * (shadeIntensity * 1.25);
28566 }
28567 }
28568 var color = colorProps.color;
28569 var utils = new Utils$1();
28570 if (w.config.plotOptions[chartType].enableShades) {
28571 // The shadeColor function may return either an RGB or a hex color value
28572 // However, hexToRgba requires the input to be in hex format
28573 // The ternary operator checks if the color is in RGB format, and if so, converts it to hex
28574 if (this.w.config.theme.mode === 'dark') {
28575 var shadeColor = utils.shadeColor(colorShadePercent * -1, colorProps.color);
28576 color = Utils$1.hexToRgba(Utils$1.isColorHex(shadeColor) ? shadeColor : Utils$1.rgb2hex(shadeColor), w.config.fill.opacity);
28577 } else {
28578 var _shadeColor = utils.shadeColor(colorShadePercent, colorProps.color);
28579 color = Utils$1.hexToRgba(Utils$1.isColorHex(_shadeColor) ? _shadeColor : Utils$1.rgb2hex(_shadeColor), w.config.fill.opacity);
28580 }
28581 }
28582 return {
28583 color: color,
28584 colorProps: colorProps
28585 };
28586 }
28587 }, {
28588 key: "determineColor",
28589 value: function determineColor(chartType, i, j) {
28590 var w = this.w;
28591 var val = w.globals.series[i][j];
28592 var chartOpts = w.config.plotOptions[chartType];
28593 var seriesNumber = chartOpts.colorScale.inverse ? j : i;
28594 if (chartOpts.distributed && w.config.chart.type === 'treemap') {
28595 seriesNumber = j;
28596 }
28597 var color = w.globals.colors[seriesNumber];
28598 var foreColor = null;
28599 var min = Math.min.apply(Math, _toConsumableArray(w.globals.series[i]));
28600 var max = Math.max.apply(Math, _toConsumableArray(w.globals.series[i]));
28601 if (!chartOpts.distributed && chartType === 'heatmap') {
28602 min = w.globals.minY;
28603 max = w.globals.maxY;
28604 }
28605 if (typeof chartOpts.colorScale.min !== 'undefined') {
28606 min = chartOpts.colorScale.min < w.globals.minY ? chartOpts.colorScale.min : w.globals.minY;
28607 max = chartOpts.colorScale.max > w.globals.maxY ? chartOpts.colorScale.max : w.globals.maxY;
28608 }
28609 var total = Math.abs(max) + Math.abs(min);
28610 var percent = 100 * val / (total === 0 ? total - 0.000001 : total);
28611 if (chartOpts.colorScale.ranges.length > 0) {
28612 var colorRange = chartOpts.colorScale.ranges;
28613 colorRange.map(function (range, index) {
28614 if (val >= range.from && val <= range.to) {
28615 color = range.color;
28616 foreColor = range.foreColor ? range.foreColor : null;
28617 min = range.from;
28618 max = range.to;
28619 var rTotal = Math.abs(max) + Math.abs(min);
28620 percent = 100 * val / (rTotal === 0 ? rTotal - 0.000001 : rTotal);
28621 }
28622 });
28623 }
28624 return {
28625 color: color,
28626 foreColor: foreColor,
28627 percent: percent
28628 };
28629 }
28630 }, {
28631 key: "calculateDataLabels",
28632 value: function calculateDataLabels(_ref) {
28633 var text = _ref.text,
28634 x = _ref.x,
28635 y = _ref.y,
28636 i = _ref.i,
28637 j = _ref.j,
28638 colorProps = _ref.colorProps,
28639 fontSize = _ref.fontSize;
28640 var w = this.w;
28641 var dataLabelsConfig = w.config.dataLabels;
28642 var graphics = new Graphics(this.ctx);
28643 var dataLabels = new DataLabels(this.ctx);
28644 var elDataLabelsWrap = null;
28645 if (dataLabelsConfig.enabled) {
28646 elDataLabelsWrap = graphics.group({
28647 class: 'apexcharts-data-labels'
28648 });
28649 var offX = dataLabelsConfig.offsetX;
28650 var offY = dataLabelsConfig.offsetY;
28651 var dataLabelsX = x + offX;
28652 var dataLabelsY = y + parseFloat(dataLabelsConfig.style.fontSize) / 3 + offY;
28653 dataLabels.plotDataLabelsText({
28654 x: dataLabelsX,
28655 y: dataLabelsY,
28656 text: text,
28657 i: i,
28658 j: j,
28659 color: colorProps.foreColor,
28660 parent: elDataLabelsWrap,
28661 fontSize: fontSize,
28662 dataLabelsConfig: dataLabelsConfig
28663 });
28664 }
28665 return elDataLabelsWrap;
28666 }
28667 }, {
28668 key: "addListeners",
28669 value: function addListeners(elRect) {
28670 var graphics = new Graphics(this.ctx);
28671 elRect.node.addEventListener('mouseenter', graphics.pathMouseEnter.bind(this, elRect));
28672 elRect.node.addEventListener('mouseleave', graphics.pathMouseLeave.bind(this, elRect));
28673 elRect.node.addEventListener('mousedown', graphics.pathMouseDown.bind(this, elRect));
28674 }
28675 }]);
28676 return TreemapHelpers;
28677 }();
28678
28679 /**
28680 * ApexCharts HeatMap Class.
28681 * @module HeatMap
28682 **/
28683 var HeatMap = /*#__PURE__*/function () {
28684 function HeatMap(ctx, xyRatios) {
28685 _classCallCheck(this, HeatMap);
28686 this.ctx = ctx;
28687 this.w = ctx.w;
28688 this.xRatio = xyRatios.xRatio;
28689 this.yRatio = xyRatios.yRatio;
28690 this.dynamicAnim = this.w.config.chart.animations.dynamicAnimation;
28691 this.helpers = new TreemapHelpers(ctx);
28692 this.rectRadius = this.w.config.plotOptions.heatmap.radius;
28693 this.strokeWidth = this.w.config.stroke.show ? this.w.config.stroke.width : 0;
28694 }
28695 _createClass(HeatMap, [{
28696 key: "draw",
28697 value: function draw(series) {
28698 var w = this.w;
28699 var graphics = new Graphics(this.ctx);
28700 var ret = graphics.group({
28701 class: 'apexcharts-heatmap'
28702 });
28703 ret.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
28704
28705 // width divided into equal parts
28706 var xDivision = w.globals.gridWidth / w.globals.dataPoints;
28707 var yDivision = w.globals.gridHeight / w.globals.series.length;
28708 var y1 = 0;
28709 var rev = false;
28710 this.negRange = this.helpers.checkColorRange();
28711 var heatSeries = series.slice();
28712 if (w.config.yaxis[0].reversed) {
28713 rev = true;
28714 heatSeries.reverse();
28715 }
28716 for (var i = rev ? 0 : heatSeries.length - 1; rev ? i < heatSeries.length : i >= 0; rev ? i++ : i--) {
28717 // el to which series will be drawn
28718 var elSeries = graphics.group({
28719 class: "apexcharts-series apexcharts-heatmap-series",
28720 seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
28721 rel: i + 1,
28722 'data:realIndex': i
28723 });
28724 this.ctx.series.addCollapsedClassToSeries(elSeries, i);
28725 if (w.config.chart.dropShadow.enabled) {
28726 var shadow = w.config.chart.dropShadow;
28727 var filters = new Filters(this.ctx);
28728 filters.dropShadow(elSeries, shadow, i);
28729 }
28730 var x1 = 0;
28731 var shadeIntensity = w.config.plotOptions.heatmap.shadeIntensity;
28732 var j = 0;
28733 for (var dIndex = 0; dIndex < w.globals.dataPoints; dIndex++) {
28734 // Recognize gaps and align values based on x axis
28735
28736 if (w.globals.seriesX.length && !w.globals.allSeriesHasEqualX) {
28737 if (w.globals.minX + w.globals.minXDiff * dIndex < w.globals.seriesX[i][j]) {
28738 x1 = x1 + xDivision;
28739 continue;
28740 }
28741 }
28742
28743 // Stop loop if index is out of array length
28744 if (j >= heatSeries[i].length) break;
28745 var heatColor = this.helpers.getShadeColor(w.config.chart.type, i, j, this.negRange);
28746 var color = heatColor.color;
28747 var heatColorProps = heatColor.colorProps;
28748 if (w.config.fill.type === 'image') {
28749 var fill = new Fill(this.ctx);
28750 color = fill.fillPath({
28751 seriesNumber: i,
28752 dataPointIndex: j,
28753 opacity: w.globals.hasNegs ? heatColorProps.percent < 0 ? 1 - (1 + heatColorProps.percent / 100) : shadeIntensity + heatColorProps.percent / 100 : heatColorProps.percent / 100,
28754 patternID: Utils$1.randomId(),
28755 width: w.config.fill.image.width ? w.config.fill.image.width : xDivision,
28756 height: w.config.fill.image.height ? w.config.fill.image.height : yDivision
28757 });
28758 }
28759 var radius = this.rectRadius;
28760 var rect = graphics.drawRect(x1, y1, xDivision, yDivision, radius);
28761 rect.attr({
28762 cx: x1,
28763 cy: y1
28764 });
28765 rect.node.classList.add('apexcharts-heatmap-rect');
28766 elSeries.add(rect);
28767 rect.attr({
28768 fill: color,
28769 i: i,
28770 index: i,
28771 j: j,
28772 val: series[i][j],
28773 'stroke-width': this.strokeWidth,
28774 stroke: w.config.plotOptions.heatmap.useFillColorAsStroke ? color : w.globals.stroke.colors[0],
28775 color: color
28776 });
28777 this.helpers.addListeners(rect);
28778 if (w.config.chart.animations.enabled && !w.globals.dataChanged) {
28779 var speed = 1;
28780 if (!w.globals.resized) {
28781 speed = w.config.chart.animations.speed;
28782 }
28783 this.animateHeatMap(rect, x1, y1, xDivision, yDivision, speed);
28784 }
28785 if (w.globals.dataChanged) {
28786 var _speed = 1;
28787 if (this.dynamicAnim.enabled && w.globals.shouldAnimate) {
28788 _speed = this.dynamicAnim.speed;
28789 var colorFrom = w.globals.previousPaths[i] && w.globals.previousPaths[i][j] && w.globals.previousPaths[i][j].color;
28790 if (!colorFrom) colorFrom = 'rgba(255, 255, 255, 0)';
28791 this.animateHeatColor(rect, Utils$1.isColorHex(colorFrom) ? colorFrom : Utils$1.rgb2hex(colorFrom), Utils$1.isColorHex(color) ? color : Utils$1.rgb2hex(color), _speed);
28792 }
28793 }
28794 var formatter = w.config.dataLabels.formatter;
28795 var formattedText = formatter(w.globals.series[i][j], {
28796 value: w.globals.series[i][j],
28797 seriesIndex: i,
28798 dataPointIndex: j,
28799 w: w
28800 });
28801 var dataLabels = this.helpers.calculateDataLabels({
28802 text: formattedText,
28803 x: x1 + xDivision / 2,
28804 y: y1 + yDivision / 2,
28805 i: i,
28806 j: j,
28807 colorProps: heatColorProps,
28808 series: heatSeries
28809 });
28810 if (dataLabels !== null) {
28811 elSeries.add(dataLabels);
28812 }
28813 x1 = x1 + xDivision;
28814 j++;
28815 }
28816 y1 = y1 + yDivision;
28817 ret.add(elSeries);
28818 }
28819
28820 // adjust yaxis labels for heatmap
28821 var yAxisScale = w.globals.yAxisScale[0].result.slice();
28822 if (w.config.yaxis[0].reversed) {
28823 yAxisScale.unshift('');
28824 } else {
28825 yAxisScale.push('');
28826 }
28827 w.globals.yAxisScale[0].result = yAxisScale;
28828 return ret;
28829 }
28830 }, {
28831 key: "animateHeatMap",
28832 value: function animateHeatMap(el, x, y, width, height, speed) {
28833 var animations = new Animations(this.ctx);
28834 animations.animateRect(el, {
28835 x: x + width / 2,
28836 y: y + height / 2,
28837 width: 0,
28838 height: 0
28839 }, {
28840 x: x,
28841 y: y,
28842 width: width,
28843 height: height
28844 }, speed, function () {
28845 animations.animationCompleted(el);
28846 });
28847 }
28848 }, {
28849 key: "animateHeatColor",
28850 value: function animateHeatColor(el, colorFrom, colorTo, speed) {
28851 el.attr({
28852 fill: colorFrom
28853 }).animate(speed).attr({
28854 fill: colorTo
28855 });
28856 }
28857 }]);
28858 return HeatMap;
28859 }();
28860
28861 var CircularChartsHelpers = /*#__PURE__*/function () {
28862 function CircularChartsHelpers(ctx) {
28863 _classCallCheck(this, CircularChartsHelpers);
28864 this.ctx = ctx;
28865 this.w = ctx.w;
28866 }
28867 _createClass(CircularChartsHelpers, [{
28868 key: "drawYAxisTexts",
28869 value: function drawYAxisTexts(x, y, i, text) {
28870 var w = this.w;
28871 var yaxisConfig = w.config.yaxis[0];
28872 var formatter = w.globals.yLabelFormatters[0];
28873 var graphics = new Graphics(this.ctx);
28874 var yaxisLabel = graphics.drawText({
28875 x: x + yaxisConfig.labels.offsetX,
28876 y: y + yaxisConfig.labels.offsetY,
28877 text: formatter(text, i),
28878 textAnchor: 'middle',
28879 fontSize: yaxisConfig.labels.style.fontSize,
28880 fontFamily: yaxisConfig.labels.style.fontFamily,
28881 foreColor: Array.isArray(yaxisConfig.labels.style.colors) ? yaxisConfig.labels.style.colors[i] : yaxisConfig.labels.style.colors
28882 });
28883 return yaxisLabel;
28884 }
28885 }]);
28886 return CircularChartsHelpers;
28887 }();
28888
28889 /**
28890 * ApexCharts Pie Class for drawing Pie / Donut Charts.
28891 * @module Pie
28892 **/
28893 var Pie = /*#__PURE__*/function () {
28894 function Pie(ctx) {
28895 _classCallCheck(this, Pie);
28896 this.ctx = ctx;
28897 this.w = ctx.w;
28898 var w = this.w;
28899 this.chartType = this.w.config.chart.type;
28900 this.initialAnim = this.w.config.chart.animations.enabled;
28901 this.dynamicAnim = this.initialAnim && this.w.config.chart.animations.dynamicAnimation.enabled;
28902 this.animBeginArr = [0];
28903 this.animDur = 0;
28904 this.donutDataLabels = this.w.config.plotOptions.pie.donut.labels;
28905 this.lineColorArr = w.globals.stroke.colors !== undefined ? w.globals.stroke.colors : w.globals.colors;
28906 this.defaultSize = Math.min(w.globals.gridWidth, w.globals.gridHeight);
28907 this.centerY = this.defaultSize / 2;
28908 this.centerX = w.globals.gridWidth / 2;
28909 if (w.config.chart.type === 'radialBar') {
28910 this.fullAngle = 360;
28911 } else {
28912 this.fullAngle = Math.abs(w.config.plotOptions.pie.endAngle - w.config.plotOptions.pie.startAngle);
28913 }
28914 this.initialAngle = w.config.plotOptions.pie.startAngle % this.fullAngle;
28915 w.globals.radialSize = this.defaultSize / 2.05 - w.config.stroke.width - (!w.config.chart.sparkline.enabled ? w.config.chart.dropShadow.blur : 0);
28916 this.donutSize = w.globals.radialSize * parseInt(w.config.plotOptions.pie.donut.size, 10) / 100;
28917 var scaleSize = w.config.plotOptions.pie.customScale;
28918 var halfW = w.globals.gridWidth / 2;
28919 var halfH = w.globals.gridHeight / 2;
28920 this.translateX = halfW - halfW * scaleSize;
28921 this.translateY = halfH - halfH * scaleSize;
28922 this.dataLabelsGroup = new Graphics(this.ctx).group({
28923 class: 'apexcharts-datalabels-group',
28924 transform: "translate(".concat(this.translateX, ", ").concat(this.translateY, ") scale(").concat(scaleSize, ")")
28925 });
28926 this.maxY = 0;
28927 this.sliceLabels = [];
28928 this.sliceSizes = [];
28929 this.prevSectorAngleArr = []; // for dynamic animations
28930 }
28931 _createClass(Pie, [{
28932 key: "draw",
28933 value: function draw(series) {
28934 var _this = this;
28935 var self = this;
28936 var w = this.w;
28937 var graphics = new Graphics(this.ctx);
28938 var elPie = graphics.group({
28939 class: 'apexcharts-pie'
28940 });
28941 if (w.globals.noData) return elPie;
28942 var total = 0;
28943 for (var k = 0; k < series.length; k++) {
28944 // CALCULATE THE TOTAL
28945 total += Utils$1.negToZero(series[k]);
28946 }
28947 var sectorAngleArr = [];
28948
28949 // el to which series will be drawn
28950 var elSeries = graphics.group();
28951
28952 // prevent division by zero error if there is no data
28953 if (total === 0) {
28954 total = 0.00001;
28955 }
28956 series.forEach(function (m) {
28957 _this.maxY = Math.max(_this.maxY, m);
28958 });
28959
28960 // override maxY if user provided in config
28961 if (w.config.yaxis[0].max) {
28962 this.maxY = w.config.yaxis[0].max;
28963 }
28964 if (w.config.grid.position === 'back' && this.chartType === 'polarArea') {
28965 this.drawPolarElements(elPie);
28966 }
28967 for (var i = 0; i < series.length; i++) {
28968 // CALCULATE THE ANGLES
28969 var angle = this.fullAngle * Utils$1.negToZero(series[i]) / total;
28970 sectorAngleArr.push(angle);
28971 if (this.chartType === 'polarArea') {
28972 sectorAngleArr[i] = this.fullAngle / series.length;
28973 this.sliceSizes.push(w.globals.radialSize * series[i] / this.maxY);
28974 } else {
28975 this.sliceSizes.push(w.globals.radialSize);
28976 }
28977 }
28978 if (w.globals.dataChanged) {
28979 var prevTotal = 0;
28980 for (var _k = 0; _k < w.globals.previousPaths.length; _k++) {
28981 // CALCULATE THE PREV TOTAL
28982 prevTotal += Utils$1.negToZero(w.globals.previousPaths[_k]);
28983 }
28984 var previousAngle;
28985 for (var _i = 0; _i < w.globals.previousPaths.length; _i++) {
28986 // CALCULATE THE PREVIOUS ANGLES
28987 previousAngle = this.fullAngle * Utils$1.negToZero(w.globals.previousPaths[_i]) / prevTotal;
28988 this.prevSectorAngleArr.push(previousAngle);
28989 }
28990 }
28991
28992 // on small chart size after few count of resizes browser window donutSize can be negative
28993 if (this.donutSize < 0) {
28994 this.donutSize = 0;
28995 }
28996 if (this.chartType === 'donut') {
28997 // draw the inner circle and add some text to it
28998 var circle = graphics.drawCircle(this.donutSize);
28999 circle.attr({
29000 cx: this.centerX,
29001 cy: this.centerY,
29002 fill: w.config.plotOptions.pie.donut.background ? w.config.plotOptions.pie.donut.background : 'transparent'
29003 });
29004 elSeries.add(circle);
29005 }
29006 var elG = self.drawArcs(sectorAngleArr, series);
29007
29008 // add slice dataLabels at the end
29009 this.sliceLabels.forEach(function (s) {
29010 elG.add(s);
29011 });
29012 elSeries.attr({
29013 transform: "translate(".concat(this.translateX, ", ").concat(this.translateY, ") scale(").concat(w.config.plotOptions.pie.customScale, ")")
29014 });
29015 elSeries.add(elG);
29016 elPie.add(elSeries);
29017 if (this.donutDataLabels.show) {
29018 var dataLabels = this.renderInnerDataLabels(this.dataLabelsGroup, this.donutDataLabels, {
29019 hollowSize: this.donutSize,
29020 centerX: this.centerX,
29021 centerY: this.centerY,
29022 opacity: this.donutDataLabels.show
29023 });
29024 elPie.add(dataLabels);
29025 }
29026 if (w.config.grid.position === 'front' && this.chartType === 'polarArea') {
29027 this.drawPolarElements(elPie);
29028 }
29029 return elPie;
29030 }
29031
29032 // core function for drawing pie arcs
29033 }, {
29034 key: "drawArcs",
29035 value: function drawArcs(sectorAngleArr, series) {
29036 var w = this.w;
29037 var filters = new Filters(this.ctx);
29038 var graphics = new Graphics(this.ctx);
29039 var fill = new Fill(this.ctx);
29040 var g = graphics.group({
29041 class: 'apexcharts-slices'
29042 });
29043 var startAngle = this.initialAngle;
29044 var prevStartAngle = this.initialAngle;
29045 var endAngle = this.initialAngle;
29046 var prevEndAngle = this.initialAngle;
29047 this.strokeWidth = w.config.stroke.show ? w.config.stroke.width : 0;
29048 for (var i = 0; i < sectorAngleArr.length; i++) {
29049 var elPieArc = graphics.group({
29050 class: "apexcharts-series apexcharts-pie-series",
29051 seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
29052 rel: i + 1,
29053 'data:realIndex': i
29054 });
29055 g.add(elPieArc);
29056 startAngle = endAngle;
29057 prevStartAngle = prevEndAngle;
29058 endAngle = startAngle + sectorAngleArr[i];
29059 prevEndAngle = prevStartAngle + this.prevSectorAngleArr[i];
29060 var angle = endAngle < startAngle ? this.fullAngle + endAngle - startAngle : endAngle - startAngle;
29061 var pathFill = fill.fillPath({
29062 seriesNumber: i,
29063 size: this.sliceSizes[i],
29064 value: series[i]
29065 }); // additionally, pass size for gradient drawing in the fillPath function
29066
29067 var path = this.getChangedPath(prevStartAngle, prevEndAngle);
29068 var elPath = graphics.drawPath({
29069 d: path,
29070 stroke: Array.isArray(this.lineColorArr) ? this.lineColorArr[i] : this.lineColorArr,
29071 strokeWidth: 0,
29072 fill: pathFill,
29073 fillOpacity: w.config.fill.opacity,
29074 classes: "apexcharts-pie-area apexcharts-".concat(this.chartType.toLowerCase(), "-slice-").concat(i)
29075 });
29076 elPath.attr({
29077 index: 0,
29078 j: i
29079 });
29080 filters.setSelectionFilter(elPath, 0, i);
29081 if (w.config.chart.dropShadow.enabled) {
29082 var shadow = w.config.chart.dropShadow;
29083 filters.dropShadow(elPath, shadow, i);
29084 }
29085 this.addListeners(elPath, this.donutDataLabels);
29086 Graphics.setAttrs(elPath.node, {
29087 'data:angle': angle,
29088 'data:startAngle': startAngle,
29089 'data:strokeWidth': this.strokeWidth,
29090 'data:value': series[i]
29091 });
29092 var labelPosition = {
29093 x: 0,
29094 y: 0
29095 };
29096 if (this.chartType === 'pie' || this.chartType === 'polarArea') {
29097 labelPosition = Utils$1.polarToCartesian(this.centerX, this.centerY, w.globals.radialSize / 1.25 + w.config.plotOptions.pie.dataLabels.offset, (startAngle + angle / 2) % this.fullAngle);
29098 } else if (this.chartType === 'donut') {
29099 labelPosition = Utils$1.polarToCartesian(this.centerX, this.centerY, (w.globals.radialSize + this.donutSize) / 2 + w.config.plotOptions.pie.dataLabels.offset, (startAngle + angle / 2) % this.fullAngle);
29100 }
29101 elPieArc.add(elPath);
29102
29103 // Animation code starts
29104 var dur = 0;
29105 if (this.initialAnim && !w.globals.resized && !w.globals.dataChanged) {
29106 dur = angle / this.fullAngle * w.config.chart.animations.speed;
29107 if (dur === 0) dur = 1;
29108 this.animDur = dur + this.animDur;
29109 this.animBeginArr.push(this.animDur);
29110 } else {
29111 this.animBeginArr.push(0);
29112 }
29113 if (this.dynamicAnim && w.globals.dataChanged) {
29114 this.animatePaths(elPath, {
29115 size: this.sliceSizes[i],
29116 endAngle: endAngle,
29117 startAngle: startAngle,
29118 prevStartAngle: prevStartAngle,
29119 prevEndAngle: prevEndAngle,
29120 animateStartingPos: true,
29121 i: i,
29122 animBeginArr: this.animBeginArr,
29123 shouldSetPrevPaths: true,
29124 dur: w.config.chart.animations.dynamicAnimation.speed
29125 });
29126 } else {
29127 this.animatePaths(elPath, {
29128 size: this.sliceSizes[i],
29129 endAngle: endAngle,
29130 startAngle: startAngle,
29131 i: i,
29132 totalItems: sectorAngleArr.length - 1,
29133 animBeginArr: this.animBeginArr,
29134 dur: dur
29135 });
29136 }
29137 // animation code ends
29138
29139 if (w.config.plotOptions.pie.expandOnClick && this.chartType !== 'polarArea') {
29140 elPath.node.addEventListener('mouseup', this.pieClicked.bind(this, i));
29141 }
29142 if (typeof w.globals.selectedDataPoints[0] !== 'undefined' && w.globals.selectedDataPoints[0].indexOf(i) > -1) {
29143 this.pieClicked(i);
29144 }
29145 if (w.config.dataLabels.enabled) {
29146 var xPos = labelPosition.x;
29147 var yPos = labelPosition.y;
29148 var text = 100 * angle / this.fullAngle + '%';
29149 if (angle !== 0 && w.config.plotOptions.pie.dataLabels.minAngleToShowLabel < sectorAngleArr[i]) {
29150 var formatter = w.config.dataLabels.formatter;
29151 if (formatter !== undefined) {
29152 text = formatter(w.globals.seriesPercent[i][0], {
29153 seriesIndex: i,
29154 w: w
29155 });
29156 }
29157 var foreColor = w.globals.dataLabels.style.colors[i];
29158 var elPieLabelWrap = graphics.group({
29159 class: "apexcharts-datalabels"
29160 });
29161 var elPieLabel = graphics.drawText({
29162 x: xPos,
29163 y: yPos,
29164 text: text,
29165 textAnchor: 'middle',
29166 fontSize: w.config.dataLabels.style.fontSize,
29167 fontFamily: w.config.dataLabels.style.fontFamily,
29168 fontWeight: w.config.dataLabels.style.fontWeight,
29169 foreColor: foreColor
29170 });
29171 elPieLabelWrap.add(elPieLabel);
29172 if (w.config.dataLabels.dropShadow.enabled) {
29173 var textShadow = w.config.dataLabels.dropShadow;
29174 filters.dropShadow(elPieLabel, textShadow);
29175 }
29176 elPieLabel.node.classList.add('apexcharts-pie-label');
29177 if (w.config.chart.animations.animate && w.globals.resized === false) {
29178 elPieLabel.node.classList.add('apexcharts-pie-label-delay');
29179 elPieLabel.node.style.animationDelay = w.config.chart.animations.speed / 940 + 's';
29180 }
29181 this.sliceLabels.push(elPieLabelWrap);
29182 }
29183 }
29184 }
29185 return g;
29186 }
29187 }, {
29188 key: "addListeners",
29189 value: function addListeners(elPath, dataLabels) {
29190 var graphics = new Graphics(this.ctx);
29191 // append filters on mouseenter and mouseleave
29192 elPath.node.addEventListener('mouseenter', graphics.pathMouseEnter.bind(this, elPath));
29193 elPath.node.addEventListener('mouseleave', graphics.pathMouseLeave.bind(this, elPath));
29194 elPath.node.addEventListener('mouseleave', this.revertDataLabelsInner.bind(this, elPath.node, dataLabels));
29195 elPath.node.addEventListener('mousedown', graphics.pathMouseDown.bind(this, elPath));
29196 if (!this.donutDataLabels.total.showAlways) {
29197 elPath.node.addEventListener('mouseenter', this.printDataLabelsInner.bind(this, elPath.node, dataLabels));
29198 elPath.node.addEventListener('mousedown', this.printDataLabelsInner.bind(this, elPath.node, dataLabels));
29199 }
29200 }
29201
29202 // This function can be used for other circle charts too
29203 }, {
29204 key: "animatePaths",
29205 value: function animatePaths(el, opts) {
29206 var w = this.w;
29207 var me = this;
29208 var angle = opts.endAngle < opts.startAngle ? this.fullAngle + opts.endAngle - opts.startAngle : opts.endAngle - opts.startAngle;
29209 var prevAngle = angle;
29210 var fromStartAngle = opts.startAngle;
29211 var toStartAngle = opts.startAngle;
29212 if (opts.prevStartAngle !== undefined && opts.prevEndAngle !== undefined) {
29213 fromStartAngle = opts.prevEndAngle;
29214 prevAngle = opts.prevEndAngle < opts.prevStartAngle ? this.fullAngle + opts.prevEndAngle - opts.prevStartAngle : opts.prevEndAngle - opts.prevStartAngle;
29215 }
29216 if (opts.i === w.config.series.length - 1) {
29217 // some adjustments for the last overlapping paths
29218 if (angle + toStartAngle > this.fullAngle) {
29219 opts.endAngle = opts.endAngle - (angle + toStartAngle);
29220 } else if (angle + toStartAngle < this.fullAngle) {
29221 opts.endAngle = opts.endAngle + (this.fullAngle - (angle + toStartAngle));
29222 }
29223 }
29224 if (angle === this.fullAngle) angle = this.fullAngle - 0.01;
29225 me.animateArc(el, fromStartAngle, toStartAngle, angle, prevAngle, opts);
29226 }
29227 }, {
29228 key: "animateArc",
29229 value: function animateArc(el, fromStartAngle, toStartAngle, angle, prevAngle, opts) {
29230 var me = this;
29231 var w = this.w;
29232 var animations = new Animations(this.ctx);
29233 var size = opts.size;
29234 var path;
29235 if (isNaN(fromStartAngle) || isNaN(prevAngle)) {
29236 fromStartAngle = toStartAngle;
29237 prevAngle = angle;
29238 opts.dur = 0;
29239 }
29240 var currAngle = angle;
29241 var startAngle = toStartAngle;
29242 var fromAngle = fromStartAngle < toStartAngle ? this.fullAngle + fromStartAngle - toStartAngle : fromStartAngle - toStartAngle;
29243 if (w.globals.dataChanged && opts.shouldSetPrevPaths) {
29244 // to avoid flicker when updating, set prev path first and then animate from there
29245 if (opts.prevEndAngle) {
29246 path = me.getPiePath({
29247 me: me,
29248 startAngle: opts.prevStartAngle,
29249 angle: opts.prevEndAngle < opts.prevStartAngle ? this.fullAngle + opts.prevEndAngle - opts.prevStartAngle : opts.prevEndAngle - opts.prevStartAngle,
29250 size: size
29251 });
29252 el.attr({
29253 d: path
29254 });
29255 }
29256 }
29257 if (opts.dur !== 0) {
29258 el.animate(opts.dur, opts.animBeginArr[opts.i]).after(function () {
29259 if (me.chartType === 'pie' || me.chartType === 'donut' || me.chartType === 'polarArea') {
29260 this.animate(w.config.chart.animations.dynamicAnimation.speed).attr({
29261 'stroke-width': me.strokeWidth
29262 });
29263 }
29264 if (opts.i === w.config.series.length - 1) {
29265 animations.animationCompleted(el);
29266 }
29267 }).during(function (pos) {
29268 currAngle = fromAngle + (angle - fromAngle) * pos;
29269 if (opts.animateStartingPos) {
29270 currAngle = prevAngle + (angle - prevAngle) * pos;
29271 startAngle = fromStartAngle - prevAngle + (toStartAngle - (fromStartAngle - prevAngle)) * pos;
29272 }
29273 path = me.getPiePath({
29274 me: me,
29275 startAngle: startAngle,
29276 angle: currAngle,
29277 size: size
29278 });
29279 el.node.setAttribute('data:pathOrig', path);
29280 el.attr({
29281 d: path
29282 });
29283 });
29284 } else {
29285 path = me.getPiePath({
29286 me: me,
29287 startAngle: startAngle,
29288 angle: angle,
29289 size: size
29290 });
29291 if (!opts.isTrack) {
29292 w.globals.animationEnded = true;
29293 }
29294 el.node.setAttribute('data:pathOrig', path);
29295 el.attr({
29296 d: path,
29297 'stroke-width': me.strokeWidth
29298 });
29299 }
29300 }
29301 }, {
29302 key: "pieClicked",
29303 value: function pieClicked(i) {
29304 var w = this.w;
29305 var me = this;
29306 var path;
29307 var size = me.sliceSizes[i] + (w.config.plotOptions.pie.expandOnClick ? 4 : 0);
29308 var elPath = w.globals.dom.Paper.findOne(".apexcharts-".concat(me.chartType.toLowerCase(), "-slice-").concat(i));
29309 if (elPath.attr('data:pieClicked') === 'true') {
29310 elPath.attr({
29311 'data:pieClicked': 'false'
29312 });
29313 this.revertDataLabelsInner(elPath.node, this.donutDataLabels);
29314 var origPath = elPath.attr('data:pathOrig');
29315 elPath.attr({
29316 d: origPath
29317 });
29318 return;
29319 } else {
29320 // reset all elems
29321 var allEls = w.globals.dom.baseEl.getElementsByClassName('apexcharts-pie-area');
29322 Array.prototype.forEach.call(allEls, function (pieSlice) {
29323 pieSlice.setAttribute('data:pieClicked', 'false');
29324 var origPath = pieSlice.getAttribute('data:pathOrig');
29325 if (origPath) {
29326 pieSlice.setAttribute('d', origPath);
29327 }
29328 });
29329 w.globals.capturedDataPointIndex = i;
29330 elPath.attr('data:pieClicked', 'true');
29331 }
29332 var startAngle = parseInt(elPath.attr('data:startAngle'), 10);
29333 var angle = parseInt(elPath.attr('data:angle'), 10);
29334 path = me.getPiePath({
29335 me: me,
29336 startAngle: startAngle,
29337 angle: angle,
29338 size: size
29339 });
29340 if (angle === 360) return;
29341 elPath.plot(path);
29342 }
29343 }, {
29344 key: "getChangedPath",
29345 value: function getChangedPath(prevStartAngle, prevEndAngle) {
29346 var path = '';
29347 if (this.dynamicAnim && this.w.globals.dataChanged) {
29348 path = this.getPiePath({
29349 me: this,
29350 startAngle: prevStartAngle,
29351 angle: prevEndAngle - prevStartAngle,
29352 size: this.size
29353 });
29354 }
29355 return path;
29356 }
29357 }, {
29358 key: "getPiePath",
29359 value: function getPiePath(_ref) {
29360 var me = _ref.me,
29361 startAngle = _ref.startAngle,
29362 angle = _ref.angle,
29363 size = _ref.size;
29364 var path;
29365 var graphics = new Graphics(this.ctx);
29366 var startDeg = startAngle;
29367 var startRadians = Math.PI * (startDeg - 90) / 180;
29368 var endDeg = angle + startAngle;
29369 // prevent overlap
29370 if (Math.ceil(endDeg) >= this.fullAngle + this.w.config.plotOptions.pie.startAngle % this.fullAngle) {
29371 endDeg = this.fullAngle + this.w.config.plotOptions.pie.startAngle % this.fullAngle - 0.01;
29372 }
29373 if (Math.ceil(endDeg) > this.fullAngle) endDeg -= this.fullAngle;
29374 var endRadians = Math.PI * (endDeg - 90) / 180;
29375 var x1 = me.centerX + size * Math.cos(startRadians);
29376 var y1 = me.centerY + size * Math.sin(startRadians);
29377 var x2 = me.centerX + size * Math.cos(endRadians);
29378 var y2 = me.centerY + size * Math.sin(endRadians);
29379 var startInner = Utils$1.polarToCartesian(me.centerX, me.centerY, me.donutSize, endDeg);
29380 var endInner = Utils$1.polarToCartesian(me.centerX, me.centerY, me.donutSize, startDeg);
29381 var largeArc = angle > 180 ? 1 : 0;
29382 var pathBeginning = ['M', x1, y1, 'A', size, size, 0, largeArc, 1, x2, y2];
29383 if (me.chartType === 'donut') {
29384 path = [].concat(pathBeginning, ['L', startInner.x, startInner.y, 'A', me.donutSize, me.donutSize, 0, largeArc, 0, endInner.x, endInner.y, 'L', x1, y1, 'z']).join(' ');
29385 } else if (me.chartType === 'pie' || me.chartType === 'polarArea') {
29386 path = [].concat(pathBeginning, ['L', me.centerX, me.centerY, 'L', x1, y1]).join(' ');
29387 } else {
29388 path = [].concat(pathBeginning).join(' ');
29389 }
29390 return graphics.roundPathCorners(path, this.strokeWidth * 2);
29391 }
29392 }, {
29393 key: "drawPolarElements",
29394 value: function drawPolarElements(parent) {
29395 var w = this.w;
29396 var scale = new Scales(this.ctx);
29397 var graphics = new Graphics(this.ctx);
29398 var helpers = new CircularChartsHelpers(this.ctx);
29399 var gCircles = graphics.group();
29400 var gYAxis = graphics.group();
29401 var yScale = scale.niceScale(0, Math.ceil(this.maxY), 0);
29402 var yTexts = yScale.result.reverse();
29403 var len = yScale.result.length;
29404 this.maxY = yScale.niceMax;
29405 var circleSize = w.globals.radialSize;
29406 var diff = circleSize / (len - 1);
29407 for (var i = 0; i < len - 1; i++) {
29408 var circle = graphics.drawCircle(circleSize);
29409 circle.attr({
29410 cx: this.centerX,
29411 cy: this.centerY,
29412 fill: 'none',
29413 'stroke-width': w.config.plotOptions.polarArea.rings.strokeWidth,
29414 stroke: w.config.plotOptions.polarArea.rings.strokeColor
29415 });
29416 if (w.config.yaxis[0].show) {
29417 var yLabel = helpers.drawYAxisTexts(this.centerX, this.centerY - circleSize + parseInt(w.config.yaxis[0].labels.style.fontSize, 10) / 2, i, yTexts[i]);
29418 gYAxis.add(yLabel);
29419 }
29420 gCircles.add(circle);
29421 circleSize = circleSize - diff;
29422 }
29423 this.drawSpokes(parent);
29424 parent.add(gCircles);
29425 parent.add(gYAxis);
29426 }
29427 }, {
29428 key: "renderInnerDataLabels",
29429 value: function renderInnerDataLabels(dataLabelsGroup, dataLabelsConfig, opts) {
29430 var w = this.w;
29431 var graphics = new Graphics(this.ctx);
29432 var showTotal = dataLabelsConfig.total.show;
29433 dataLabelsGroup.node.innerHTML = '';
29434 dataLabelsGroup.node.style.opacity = opts.opacity;
29435 var x = opts.centerX;
29436 var y = !this.donutDataLabels.total.label ? opts.centerY - opts.centerY / 6 : opts.centerY;
29437 var labelColor, valueColor;
29438 if (dataLabelsConfig.name.color === undefined) {
29439 labelColor = w.globals.colors[0];
29440 } else {
29441 labelColor = dataLabelsConfig.name.color;
29442 }
29443 var labelFontSize = dataLabelsConfig.name.fontSize;
29444 var labelFontFamily = dataLabelsConfig.name.fontFamily;
29445 var labelFontWeight = dataLabelsConfig.name.fontWeight;
29446 if (dataLabelsConfig.value.color === undefined) {
29447 valueColor = w.config.chart.foreColor;
29448 } else {
29449 valueColor = dataLabelsConfig.value.color;
29450 }
29451 var lbFormatter = dataLabelsConfig.value.formatter;
29452 var val = '';
29453 var name = '';
29454 if (showTotal) {
29455 labelColor = dataLabelsConfig.total.color;
29456 labelFontSize = dataLabelsConfig.total.fontSize;
29457 labelFontFamily = dataLabelsConfig.total.fontFamily;
29458 labelFontWeight = dataLabelsConfig.total.fontWeight;
29459 name = !this.donutDataLabels.total.label ? '' : dataLabelsConfig.total.label;
29460 val = dataLabelsConfig.total.formatter(w);
29461 } else {
29462 if (w.globals.series.length === 1) {
29463 val = lbFormatter(w.globals.series[0], w);
29464 name = w.globals.seriesNames[0];
29465 }
29466 }
29467 if (name) {
29468 name = dataLabelsConfig.name.formatter(name, dataLabelsConfig.total.show, w);
29469 }
29470 if (dataLabelsConfig.name.show) {
29471 var elLabel = graphics.drawText({
29472 x: x,
29473 y: y + parseFloat(dataLabelsConfig.name.offsetY),
29474 text: name,
29475 textAnchor: 'middle',
29476 foreColor: labelColor,
29477 fontSize: labelFontSize,
29478 fontWeight: labelFontWeight,
29479 fontFamily: labelFontFamily
29480 });
29481 elLabel.node.classList.add('apexcharts-datalabel-label');
29482 dataLabelsGroup.add(elLabel);
29483 }
29484 if (dataLabelsConfig.value.show) {
29485 var valOffset = dataLabelsConfig.name.show ? parseFloat(dataLabelsConfig.value.offsetY) + 16 : dataLabelsConfig.value.offsetY;
29486 var elValue = graphics.drawText({
29487 x: x,
29488 y: y + valOffset,
29489 text: val,
29490 textAnchor: 'middle',
29491 foreColor: valueColor,
29492 fontWeight: dataLabelsConfig.value.fontWeight,
29493 fontSize: dataLabelsConfig.value.fontSize,
29494 fontFamily: dataLabelsConfig.value.fontFamily
29495 });
29496 elValue.node.classList.add('apexcharts-datalabel-value');
29497 dataLabelsGroup.add(elValue);
29498 }
29499
29500 // for a multi-series circle chart, we need to show total value instead of first series labels
29501
29502 return dataLabelsGroup;
29503 }
29504
29505 /**
29506 *
29507 * @param {string} name - The name of the series
29508 * @param {string} val - The value of that series
29509 * @param {object} el - Optional el (indicates which series was hovered/clicked). If this param is not present, means we need to show total
29510 */
29511 }, {
29512 key: "printInnerLabels",
29513 value: function printInnerLabels(labelsConfig, name, val, el) {
29514 var w = this.w;
29515 var labelColor;
29516 if (el) {
29517 if (labelsConfig.name.color === undefined) {
29518 labelColor = w.globals.colors[parseInt(el.parentNode.getAttribute('rel'), 10) - 1];
29519 } else {
29520 labelColor = labelsConfig.name.color;
29521 }
29522 } else {
29523 if (w.globals.series.length > 1 && labelsConfig.total.show) {
29524 labelColor = labelsConfig.total.color;
29525 }
29526 }
29527 var elLabel = w.globals.dom.baseEl.querySelector('.apexcharts-datalabel-label');
29528 var elValue = w.globals.dom.baseEl.querySelector('.apexcharts-datalabel-value');
29529 var lbFormatter = labelsConfig.value.formatter;
29530 val = lbFormatter(val, w);
29531
29532 // we need to show Total Val - so get the formatter of it
29533 if (!el && typeof labelsConfig.total.formatter === 'function') {
29534 val = labelsConfig.total.formatter(w);
29535 }
29536 var isTotal = name === labelsConfig.total.label;
29537 name = !this.donutDataLabels.total.label ? '' : labelsConfig.name.formatter(name, isTotal, w);
29538 if (elLabel !== null) {
29539 elLabel.textContent = name;
29540 }
29541 if (elValue !== null) {
29542 elValue.textContent = val;
29543 }
29544 if (elLabel !== null) {
29545 elLabel.style.fill = labelColor;
29546 }
29547 }
29548 }, {
29549 key: "printDataLabelsInner",
29550 value: function printDataLabelsInner(el, dataLabelsConfig) {
29551 var w = this.w;
29552 var val = el.getAttribute('data:value');
29553 var name = w.globals.seriesNames[parseInt(el.parentNode.getAttribute('rel'), 10) - 1];
29554 if (w.globals.series.length > 1) {
29555 this.printInnerLabels(dataLabelsConfig, name, val, el);
29556 }
29557 var dataLabelsGroup = w.globals.dom.baseEl.querySelector('.apexcharts-datalabels-group');
29558 if (dataLabelsGroup !== null) {
29559 dataLabelsGroup.style.opacity = 1;
29560 }
29561 }
29562 }, {
29563 key: "drawSpokes",
29564 value: function drawSpokes(parent) {
29565 var _this2 = this;
29566 var w = this.w;
29567 var graphics = new Graphics(this.ctx);
29568 var spokeConfig = w.config.plotOptions.polarArea.spokes;
29569 if (spokeConfig.strokeWidth === 0) return;
29570 var spokes = [];
29571 var angleDivision = 360 / w.globals.series.length;
29572 for (var i = 0; i < w.globals.series.length; i++) {
29573 spokes.push(Utils$1.polarToCartesian(this.centerX, this.centerY, w.globals.radialSize, w.config.plotOptions.pie.startAngle + angleDivision * i));
29574 }
29575 spokes.forEach(function (p, i) {
29576 var line = graphics.drawLine(p.x, p.y, _this2.centerX, _this2.centerY, Array.isArray(spokeConfig.connectorColors) ? spokeConfig.connectorColors[i] : spokeConfig.connectorColors);
29577 parent.add(line);
29578 });
29579 }
29580 }, {
29581 key: "revertDataLabelsInner",
29582 value: function revertDataLabelsInner() {
29583 var w = this.w;
29584 if (this.donutDataLabels.show) {
29585 var dataLabelsGroup = w.globals.dom.Paper.findOne(".apexcharts-datalabels-group");
29586 var dataLabels = this.renderInnerDataLabels(dataLabelsGroup, this.donutDataLabels, {
29587 hollowSize: this.donutSize,
29588 centerX: this.centerX,
29589 centerY: this.centerY,
29590 opacity: this.donutDataLabels.show
29591 });
29592 var elPie = w.globals.dom.Paper.findOne('.apexcharts-radialbar, .apexcharts-pie');
29593 elPie.add(dataLabels);
29594 }
29595 }
29596 }]);
29597 return Pie;
29598 }();
29599
29600 /**
29601 * ApexCharts Radar Class for Spider/Radar Charts.
29602 * @module Radar
29603 **/
29604 var Radar = /*#__PURE__*/function () {
29605 function Radar(ctx) {
29606 _classCallCheck(this, Radar);
29607 this.ctx = ctx;
29608 this.w = ctx.w;
29609 this.chartType = this.w.config.chart.type;
29610 this.initialAnim = this.w.config.chart.animations.enabled;
29611 this.dynamicAnim = this.initialAnim && this.w.config.chart.animations.dynamicAnimation.enabled;
29612 this.animDur = 0;
29613 var w = this.w;
29614 this.graphics = new Graphics(this.ctx);
29615 this.lineColorArr = w.globals.stroke.colors !== undefined ? w.globals.stroke.colors : w.globals.colors;
29616 this.defaultSize = w.globals.svgHeight < w.globals.svgWidth ? w.globals.gridHeight : w.globals.gridWidth;
29617 this.isLog = w.config.yaxis[0].logarithmic;
29618 this.logBase = w.config.yaxis[0].logBase;
29619 this.coreUtils = new CoreUtils(this.ctx);
29620 this.maxValue = this.isLog ? this.coreUtils.getLogVal(this.logBase, w.globals.maxY, 0) : w.globals.maxY;
29621 this.minValue = this.isLog ? this.coreUtils.getLogVal(this.logBase, this.w.globals.minY, 0) : w.globals.minY;
29622 this.polygons = w.config.plotOptions.radar.polygons;
29623 this.strokeWidth = w.config.stroke.show ? w.config.stroke.width : 0;
29624 this.size = this.defaultSize / 2.1 - this.strokeWidth - w.config.chart.dropShadow.blur;
29625 if (w.config.xaxis.labels.show) {
29626 this.size = this.size - w.globals.xAxisLabelsWidth / 1.75;
29627 }
29628 if (w.config.plotOptions.radar.size !== undefined) {
29629 this.size = w.config.plotOptions.radar.size;
29630 }
29631 this.dataRadiusOfPercent = [];
29632 this.dataRadius = [];
29633 this.angleArr = [];
29634 this.yaxisLabelsTextsPos = [];
29635 }
29636 _createClass(Radar, [{
29637 key: "draw",
29638 value: function draw(series) {
29639 var _this = this;
29640 var w = this.w;
29641 var fill = new Fill(this.ctx);
29642 var allSeries = [];
29643 var dataLabels = new DataLabels(this.ctx);
29644 if (series.length) {
29645 this.dataPointsLen = series[w.globals.maxValsInArrayIndex].length;
29646 }
29647 this.disAngle = Math.PI * 2 / this.dataPointsLen;
29648 var halfW = w.globals.gridWidth / 2;
29649 var halfH = w.globals.gridHeight / 2;
29650 var translateX = halfW + w.config.plotOptions.radar.offsetX;
29651 var translateY = halfH + w.config.plotOptions.radar.offsetY;
29652 var ret = this.graphics.group({
29653 class: 'apexcharts-radar-series apexcharts-plot-series',
29654 transform: "translate(".concat(translateX || 0, ", ").concat(translateY || 0, ")")
29655 });
29656 var dataPointsPos = [];
29657 var elPointsMain = null;
29658 var elDataPointsMain = null;
29659 this.yaxisLabels = this.graphics.group({
29660 class: 'apexcharts-yaxis'
29661 });
29662 series.forEach(function (s, i) {
29663 var longestSeries = s.length === w.globals.dataPoints;
29664
29665 // el to which series will be drawn
29666 var elSeries = _this.graphics.group().attr({
29667 class: "apexcharts-series",
29668 'data:longestSeries': longestSeries,
29669 seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
29670 rel: i + 1,
29671 'data:realIndex': i
29672 });
29673 _this.dataRadiusOfPercent[i] = [];
29674 _this.dataRadius[i] = [];
29675 _this.angleArr[i] = [];
29676 s.forEach(function (dv, j) {
29677 var range = Math.abs(_this.maxValue - _this.minValue);
29678 dv = dv - _this.minValue;
29679 if (_this.isLog) {
29680 dv = _this.coreUtils.getLogVal(_this.logBase, dv, 0);
29681 }
29682 _this.dataRadiusOfPercent[i][j] = dv / range;
29683 _this.dataRadius[i][j] = _this.dataRadiusOfPercent[i][j] * _this.size;
29684 _this.angleArr[i][j] = j * _this.disAngle;
29685 });
29686 dataPointsPos = _this.getDataPointsPos(_this.dataRadius[i], _this.angleArr[i]);
29687 var paths = _this.createPaths(dataPointsPos, {
29688 x: 0,
29689 y: 0
29690 });
29691
29692 // points
29693 elPointsMain = _this.graphics.group({
29694 class: 'apexcharts-series-markers-wrap apexcharts-element-hidden'
29695 });
29696
29697 // datapoints
29698 elDataPointsMain = _this.graphics.group({
29699 class: "apexcharts-datalabels",
29700 'data:realIndex': i
29701 });
29702 w.globals.delayedElements.push({
29703 el: elPointsMain.node,
29704 index: i
29705 });
29706 var defaultRenderedPathOptions = {
29707 i: i,
29708 realIndex: i,
29709 animationDelay: i,
29710 initialSpeed: w.config.chart.animations.speed,
29711 dataChangeSpeed: w.config.chart.animations.dynamicAnimation.speed,
29712 className: "apexcharts-radar",
29713 shouldClipToGrid: false,
29714 bindEventsOnPaths: false,
29715 stroke: w.globals.stroke.colors[i],
29716 strokeLineCap: w.config.stroke.lineCap
29717 };
29718 var pathFrom = null;
29719 if (w.globals.previousPaths.length > 0) {
29720 pathFrom = _this.getPreviousPath(i);
29721 }
29722 for (var p = 0; p < paths.linePathsTo.length; p++) {
29723 var renderedLinePath = _this.graphics.renderPaths(_objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
29724 pathFrom: pathFrom === null ? paths.linePathsFrom[p] : pathFrom,
29725 pathTo: paths.linePathsTo[p],
29726 strokeWidth: Array.isArray(_this.strokeWidth) ? _this.strokeWidth[i] : _this.strokeWidth,
29727 fill: 'none',
29728 drawShadow: false
29729 }));
29730 elSeries.add(renderedLinePath);
29731 var pathFill = fill.fillPath({
29732 seriesNumber: i
29733 });
29734 var renderedAreaPath = _this.graphics.renderPaths(_objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
29735 pathFrom: pathFrom === null ? paths.areaPathsFrom[p] : pathFrom,
29736 pathTo: paths.areaPathsTo[p],
29737 strokeWidth: 0,
29738 fill: pathFill,
29739 drawShadow: false
29740 }));
29741 if (w.config.chart.dropShadow.enabled) {
29742 var filters = new Filters(_this.ctx);
29743 var shadow = w.config.chart.dropShadow;
29744 filters.dropShadow(renderedAreaPath, Object.assign({}, shadow, {
29745 noUserSpaceOnUse: true
29746 }), i);
29747 }
29748 elSeries.add(renderedAreaPath);
29749 }
29750 s.forEach(function (sj, j) {
29751 var markers = new Markers(_this.ctx);
29752 var opts = markers.getMarkerConfig({
29753 cssClass: 'apexcharts-marker',
29754 seriesIndex: i,
29755 dataPointIndex: j
29756 });
29757 var point = _this.graphics.drawMarker(dataPointsPos[j].x, dataPointsPos[j].y, opts);
29758 point.attr('rel', j);
29759 point.attr('j', j);
29760 point.attr('index', i);
29761 point.node.setAttribute('default-marker-size', opts.pSize);
29762 var elPointsWrap = _this.graphics.group({
29763 class: 'apexcharts-series-markers'
29764 });
29765 if (elPointsWrap) {
29766 elPointsWrap.add(point);
29767 }
29768 elPointsMain.add(elPointsWrap);
29769 elSeries.add(elPointsMain);
29770 var dataLabelsConfig = w.config.dataLabels;
29771 if (dataLabelsConfig.enabled) {
29772 var text = dataLabelsConfig.formatter(w.globals.series[i][j], {
29773 seriesIndex: i,
29774 dataPointIndex: j,
29775 w: w
29776 });
29777 dataLabels.plotDataLabelsText({
29778 x: dataPointsPos[j].x,
29779 y: dataPointsPos[j].y,
29780 text: text,
29781 textAnchor: 'middle',
29782 i: i,
29783 j: i,
29784 parent: elDataPointsMain,
29785 offsetCorrection: false,
29786 dataLabelsConfig: _objectSpread2({}, dataLabelsConfig)
29787 });
29788 }
29789 elSeries.add(elDataPointsMain);
29790 });
29791 allSeries.push(elSeries);
29792 });
29793 this.drawPolygons({
29794 parent: ret
29795 });
29796 if (w.config.xaxis.labels.show) {
29797 var xaxisTexts = this.drawXAxisTexts();
29798 ret.add(xaxisTexts);
29799 }
29800 allSeries.forEach(function (elS) {
29801 ret.add(elS);
29802 });
29803 ret.add(this.yaxisLabels);
29804 return ret;
29805 }
29806 }, {
29807 key: "drawPolygons",
29808 value: function drawPolygons(opts) {
29809 var _this2 = this;
29810 var w = this.w;
29811 var parent = opts.parent;
29812 var helpers = new CircularChartsHelpers(this.ctx);
29813 var yaxisTexts = w.globals.yAxisScale[0].result.reverse();
29814 var layers = yaxisTexts.length;
29815 var radiusSizes = [];
29816 var layerDis = this.size / (layers - 1);
29817 for (var i = 0; i < layers; i++) {
29818 radiusSizes[i] = layerDis * i;
29819 }
29820 radiusSizes.reverse();
29821 var polygonStrings = [];
29822 var lines = [];
29823 radiusSizes.forEach(function (radiusSize, r) {
29824 var polygon = Utils$1.getPolygonPos(radiusSize, _this2.dataPointsLen);
29825 var string = '';
29826 polygon.forEach(function (p, i) {
29827 if (r === 0) {
29828 var line = _this2.graphics.drawLine(p.x, p.y, 0, 0, Array.isArray(_this2.polygons.connectorColors) ? _this2.polygons.connectorColors[i] : _this2.polygons.connectorColors);
29829 lines.push(line);
29830 }
29831 if (i === 0) {
29832 _this2.yaxisLabelsTextsPos.push({
29833 x: p.x,
29834 y: p.y
29835 });
29836 }
29837 string += p.x + ',' + p.y + ' ';
29838 });
29839 polygonStrings.push(string);
29840 });
29841 polygonStrings.forEach(function (p, i) {
29842 var strokeColors = _this2.polygons.strokeColors;
29843 var strokeWidth = _this2.polygons.strokeWidth;
29844 var polygon = _this2.graphics.drawPolygon(p, Array.isArray(strokeColors) ? strokeColors[i] : strokeColors, Array.isArray(strokeWidth) ? strokeWidth[i] : strokeWidth, w.globals.radarPolygons.fill.colors[i]);
29845 parent.add(polygon);
29846 });
29847 lines.forEach(function (l) {
29848 parent.add(l);
29849 });
29850 if (w.config.yaxis[0].show) {
29851 this.yaxisLabelsTextsPos.forEach(function (p, i) {
29852 var yText = helpers.drawYAxisTexts(p.x, p.y, i, yaxisTexts[i]);
29853 _this2.yaxisLabels.add(yText);
29854 });
29855 }
29856 }
29857 }, {
29858 key: "drawXAxisTexts",
29859 value: function drawXAxisTexts() {
29860 var _this3 = this;
29861 var w = this.w;
29862 var xaxisLabelsConfig = w.config.xaxis.labels;
29863 var elXAxisWrap = this.graphics.group({
29864 class: 'apexcharts-xaxis'
29865 });
29866 var polygonPos = Utils$1.getPolygonPos(this.size, this.dataPointsLen);
29867 w.globals.labels.forEach(function (label, i) {
29868 var formatter = w.config.xaxis.labels.formatter;
29869 var dataLabels = new DataLabels(_this3.ctx);
29870 if (polygonPos[i]) {
29871 var textPos = _this3.getTextPos(polygonPos[i], _this3.size);
29872 var text = formatter(label, {
29873 seriesIndex: -1,
29874 dataPointIndex: i,
29875 w: w
29876 });
29877 var dataLabelText = dataLabels.plotDataLabelsText({
29878 x: textPos.newX,
29879 y: textPos.newY,
29880 text: text,
29881 textAnchor: textPos.textAnchor,
29882 i: i,
29883 j: i,
29884 parent: elXAxisWrap,
29885 className: 'apexcharts-xaxis-label',
29886 color: Array.isArray(xaxisLabelsConfig.style.colors) && xaxisLabelsConfig.style.colors[i] ? xaxisLabelsConfig.style.colors[i] : '#a8a8a8',
29887 dataLabelsConfig: _objectSpread2({
29888 textAnchor: textPos.textAnchor,
29889 dropShadow: {
29890 enabled: false
29891 }
29892 }, xaxisLabelsConfig),
29893 offsetCorrection: false
29894 });
29895 dataLabelText.on('click', function (e) {
29896 if (typeof w.config.chart.events.xAxisLabelClick === 'function') {
29897 var opts = Object.assign({}, w, {
29898 labelIndex: i
29899 });
29900 w.config.chart.events.xAxisLabelClick(e, _this3.ctx, opts);
29901 }
29902 });
29903 }
29904 });
29905 return elXAxisWrap;
29906 }
29907 }, {
29908 key: "createPaths",
29909 value: function createPaths(pos, origin) {
29910 var _this4 = this;
29911 var linePathsTo = [];
29912 var linePathsFrom = [];
29913 var areaPathsTo = [];
29914 var areaPathsFrom = [];
29915 if (pos.length) {
29916 linePathsFrom = [this.graphics.move(origin.x, origin.y)];
29917 areaPathsFrom = [this.graphics.move(origin.x, origin.y)];
29918 var linePathTo = this.graphics.move(pos[0].x, pos[0].y);
29919 var areaPathTo = this.graphics.move(pos[0].x, pos[0].y);
29920 pos.forEach(function (p, i) {
29921 linePathTo += _this4.graphics.line(p.x, p.y);
29922 areaPathTo += _this4.graphics.line(p.x, p.y);
29923 if (i === pos.length - 1) {
29924 linePathTo += 'Z';
29925 areaPathTo += 'Z';
29926 }
29927 });
29928 linePathsTo.push(linePathTo);
29929 areaPathsTo.push(areaPathTo);
29930 }
29931 return {
29932 linePathsFrom: linePathsFrom,
29933 linePathsTo: linePathsTo,
29934 areaPathsFrom: areaPathsFrom,
29935 areaPathsTo: areaPathsTo
29936 };
29937 }
29938 }, {
29939 key: "getTextPos",
29940 value: function getTextPos(pos, polygonSize) {
29941 var limit = 10;
29942 var textAnchor = 'middle';
29943 var newX = pos.x;
29944 var newY = pos.y;
29945 if (Math.abs(pos.x) >= limit) {
29946 if (pos.x > 0) {
29947 textAnchor = 'start';
29948 newX += 10;
29949 } else if (pos.x < 0) {
29950 textAnchor = 'end';
29951 newX -= 10;
29952 }
29953 } else {
29954 textAnchor = 'middle';
29955 }
29956 if (Math.abs(pos.y) >= polygonSize - limit) {
29957 if (pos.y < 0) {
29958 newY -= 10;
29959 } else if (pos.y > 0) {
29960 newY += 10;
29961 }
29962 }
29963 return {
29964 textAnchor: textAnchor,
29965 newX: newX,
29966 newY: newY
29967 };
29968 }
29969 }, {
29970 key: "getPreviousPath",
29971 value: function getPreviousPath(realIndex) {
29972 var w = this.w;
29973 var pathFrom = null;
29974 for (var pp = 0; pp < w.globals.previousPaths.length; pp++) {
29975 var gpp = w.globals.previousPaths[pp];
29976 if (gpp.paths.length > 0 && parseInt(gpp.realIndex, 10) === parseInt(realIndex, 10)) {
29977 if (typeof w.globals.previousPaths[pp].paths[0] !== 'undefined') {
29978 pathFrom = w.globals.previousPaths[pp].paths[0].d;
29979 }
29980 }
29981 }
29982 return pathFrom;
29983 }
29984 }, {
29985 key: "getDataPointsPos",
29986 value: function getDataPointsPos(dataRadiusArr, angleArr) {
29987 var dataPointsLen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.dataPointsLen;
29988 dataRadiusArr = dataRadiusArr || [];
29989 angleArr = angleArr || [];
29990 var dataPointsPosArray = [];
29991 for (var j = 0; j < dataPointsLen; j++) {
29992 var curPointPos = {};
29993 curPointPos.x = dataRadiusArr[j] * Math.sin(angleArr[j]);
29994 curPointPos.y = -dataRadiusArr[j] * Math.cos(angleArr[j]);
29995 dataPointsPosArray.push(curPointPos);
29996 }
29997 return dataPointsPosArray;
29998 }
29999 }]);
30000 return Radar;
30001 }();
30002
30003 /**
30004 * ApexCharts Radial Class for drawing Circle / Semi Circle Charts.
30005 * @module Radial
30006 **/
30007 var Radial = /*#__PURE__*/function (_Pie) {
30008 _inherits(Radial, _Pie);
30009 var _super = _createSuper(Radial);
30010 function Radial(ctx) {
30011 var _this;
30012 _classCallCheck(this, Radial);
30013 _this = _super.call(this, ctx);
30014 _this.ctx = ctx;
30015 _this.w = ctx.w;
30016 _this.animBeginArr = [0];
30017 _this.animDur = 0;
30018 var w = _this.w;
30019 _this.startAngle = w.config.plotOptions.radialBar.startAngle;
30020 _this.endAngle = w.config.plotOptions.radialBar.endAngle;
30021 _this.totalAngle = Math.abs(w.config.plotOptions.radialBar.endAngle - w.config.plotOptions.radialBar.startAngle);
30022 _this.trackStartAngle = w.config.plotOptions.radialBar.track.startAngle;
30023 _this.trackEndAngle = w.config.plotOptions.radialBar.track.endAngle;
30024 _this.barLabels = _this.w.config.plotOptions.radialBar.barLabels;
30025 _this.donutDataLabels = _this.w.config.plotOptions.radialBar.dataLabels;
30026 _this.radialDataLabels = _this.donutDataLabels; // make a copy for easy reference
30027
30028 if (!_this.trackStartAngle) _this.trackStartAngle = _this.startAngle;
30029 if (!_this.trackEndAngle) _this.trackEndAngle = _this.endAngle;
30030 if (_this.endAngle === 360) _this.endAngle = 359.99;
30031 _this.margin = parseInt(w.config.plotOptions.radialBar.track.margin, 10);
30032 _this.onBarLabelClick = _this.onBarLabelClick.bind(_assertThisInitialized(_this));
30033 return _this;
30034 }
30035 _createClass(Radial, [{
30036 key: "draw",
30037 value: function draw(series) {
30038 var w = this.w;
30039 var graphics = new Graphics(this.ctx);
30040 var ret = graphics.group({
30041 class: 'apexcharts-radialbar'
30042 });
30043 if (w.globals.noData) return ret;
30044 var elSeries = graphics.group();
30045 var centerY = this.defaultSize / 2;
30046 var centerX = w.globals.gridWidth / 2;
30047 var size = this.defaultSize / 2.05;
30048 if (!w.config.chart.sparkline.enabled) {
30049 size = size - w.config.stroke.width - w.config.chart.dropShadow.blur;
30050 }
30051 var colorArr = w.globals.fill.colors;
30052 if (w.config.plotOptions.radialBar.track.show) {
30053 var elTracks = this.drawTracks({
30054 size: size,
30055 centerX: centerX,
30056 centerY: centerY,
30057 colorArr: colorArr,
30058 series: series
30059 });
30060 elSeries.add(elTracks);
30061 }
30062 var elG = this.drawArcs({
30063 size: size,
30064 centerX: centerX,
30065 centerY: centerY,
30066 colorArr: colorArr,
30067 series: series
30068 });
30069 var totalAngle = 360;
30070 if (w.config.plotOptions.radialBar.startAngle < 0) {
30071 totalAngle = this.totalAngle;
30072 }
30073 var angleRatio = (360 - totalAngle) / 360;
30074 w.globals.radialSize = size - size * angleRatio;
30075 if (this.radialDataLabels.value.show) {
30076 var offset = Math.max(this.radialDataLabels.value.offsetY, this.radialDataLabels.name.offsetY);
30077 w.globals.radialSize += offset * angleRatio;
30078 }
30079 elSeries.add(elG.g);
30080 if (w.config.plotOptions.radialBar.hollow.position === 'front') {
30081 elG.g.add(elG.elHollow);
30082 if (elG.dataLabels) {
30083 elG.g.add(elG.dataLabels);
30084 }
30085 }
30086 ret.add(elSeries);
30087 return ret;
30088 }
30089 }, {
30090 key: "drawTracks",
30091 value: function drawTracks(opts) {
30092 var w = this.w;
30093 var graphics = new Graphics(this.ctx);
30094 var g = graphics.group({
30095 class: 'apexcharts-tracks'
30096 });
30097 var filters = new Filters(this.ctx);
30098 var fill = new Fill(this.ctx);
30099 var strokeWidth = this.getStrokeWidth(opts);
30100 opts.size = opts.size - strokeWidth / 2;
30101 for (var i = 0; i < opts.series.length; i++) {
30102 var elRadialBarTrack = graphics.group({
30103 class: 'apexcharts-radialbar-track apexcharts-track'
30104 });
30105 g.add(elRadialBarTrack);
30106 elRadialBarTrack.attr({
30107 rel: i + 1
30108 });
30109 opts.size = opts.size - strokeWidth - this.margin;
30110 var trackConfig = w.config.plotOptions.radialBar.track;
30111 var pathFill = fill.fillPath({
30112 seriesNumber: 0,
30113 size: opts.size,
30114 fillColors: Array.isArray(trackConfig.background) ? trackConfig.background[i] : trackConfig.background,
30115 solid: true
30116 });
30117 var startAngle = this.trackStartAngle;
30118 var endAngle = this.trackEndAngle;
30119 if (Math.abs(endAngle) + Math.abs(startAngle) >= 360) endAngle = 360 - Math.abs(this.startAngle) - 0.1;
30120 var elPath = graphics.drawPath({
30121 d: '',
30122 stroke: pathFill,
30123 strokeWidth: strokeWidth * parseInt(trackConfig.strokeWidth, 10) / 100,
30124 fill: 'none',
30125 strokeOpacity: trackConfig.opacity,
30126 classes: 'apexcharts-radialbar-area'
30127 });
30128 if (trackConfig.dropShadow.enabled) {
30129 var shadow = trackConfig.dropShadow;
30130 filters.dropShadow(elPath, shadow);
30131 }
30132 elRadialBarTrack.add(elPath);
30133 elPath.attr('id', 'apexcharts-radialbarTrack-' + i);
30134 this.animatePaths(elPath, {
30135 centerX: opts.centerX,
30136 centerY: opts.centerY,
30137 endAngle: endAngle,
30138 startAngle: startAngle,
30139 size: opts.size,
30140 i: i,
30141 totalItems: 2,
30142 animBeginArr: 0,
30143 dur: 0,
30144 isTrack: true
30145 });
30146 }
30147 return g;
30148 }
30149 }, {
30150 key: "drawArcs",
30151 value: function drawArcs(opts) {
30152 var w = this.w;
30153 // size, donutSize, centerX, centerY, colorArr, lineColorArr, sectorAngleArr, series
30154
30155 var graphics = new Graphics(this.ctx);
30156 var fill = new Fill(this.ctx);
30157 var filters = new Filters(this.ctx);
30158 var g = graphics.group();
30159 var strokeWidth = this.getStrokeWidth(opts);
30160 opts.size = opts.size - strokeWidth / 2;
30161 var hollowFillID = w.config.plotOptions.radialBar.hollow.background;
30162 var hollowSize = opts.size - strokeWidth * opts.series.length - this.margin * opts.series.length - strokeWidth * parseInt(w.config.plotOptions.radialBar.track.strokeWidth, 10) / 100 / 2;
30163 var hollowRadius = hollowSize - w.config.plotOptions.radialBar.hollow.margin;
30164 if (w.config.plotOptions.radialBar.hollow.image !== undefined) {
30165 hollowFillID = this.drawHollowImage(opts, g, hollowSize, hollowFillID);
30166 }
30167 var elHollow = this.drawHollow({
30168 size: hollowRadius,
30169 centerX: opts.centerX,
30170 centerY: opts.centerY,
30171 fill: hollowFillID ? hollowFillID : 'transparent'
30172 });
30173 if (w.config.plotOptions.radialBar.hollow.dropShadow.enabled) {
30174 var shadow = w.config.plotOptions.radialBar.hollow.dropShadow;
30175 filters.dropShadow(elHollow, shadow);
30176 }
30177 var shown = 1;
30178 if (!this.radialDataLabels.total.show && w.globals.series.length > 1) {
30179 shown = 0;
30180 }
30181 var dataLabels = null;
30182 if (this.radialDataLabels.show) {
30183 var dataLabelsGroup = w.globals.dom.Paper.findOne(".apexcharts-datalabels-group");
30184 dataLabels = this.renderInnerDataLabels(dataLabelsGroup, this.radialDataLabels, {
30185 hollowSize: hollowSize,
30186 centerX: opts.centerX,
30187 centerY: opts.centerY,
30188 opacity: shown
30189 });
30190 }
30191 if (w.config.plotOptions.radialBar.hollow.position === 'back') {
30192 g.add(elHollow);
30193 if (dataLabels) {
30194 g.add(dataLabels);
30195 }
30196 }
30197 var reverseLoop = false;
30198 if (w.config.plotOptions.radialBar.inverseOrder) {
30199 reverseLoop = true;
30200 }
30201 for (var i = reverseLoop ? opts.series.length - 1 : 0; reverseLoop ? i >= 0 : i < opts.series.length; reverseLoop ? i-- : i++) {
30202 var elRadialBarArc = graphics.group({
30203 class: "apexcharts-series apexcharts-radial-series",
30204 seriesName: Utils$1.escapeString(w.globals.seriesNames[i])
30205 });
30206 g.add(elRadialBarArc);
30207 elRadialBarArc.attr({
30208 rel: i + 1,
30209 'data:realIndex': i
30210 });
30211 this.ctx.series.addCollapsedClassToSeries(elRadialBarArc, i);
30212 opts.size = opts.size - strokeWidth - this.margin;
30213 var pathFill = fill.fillPath({
30214 seriesNumber: i,
30215 size: opts.size,
30216 value: opts.series[i]
30217 });
30218 var startAngle = this.startAngle;
30219 var prevStartAngle = void 0;
30220
30221 // if data exceeds 100, make it 100
30222 var dataValue = Utils$1.negToZero(opts.series[i] > 100 ? 100 : opts.series[i]) / 100;
30223 var endAngle = Math.round(this.totalAngle * dataValue) + this.startAngle;
30224 var prevEndAngle = void 0;
30225 if (w.globals.dataChanged) {
30226 prevStartAngle = this.startAngle;
30227 prevEndAngle = Math.round(this.totalAngle * Utils$1.negToZero(w.globals.previousPaths[i]) / 100) + prevStartAngle;
30228 }
30229 var currFullAngle = Math.abs(endAngle) + Math.abs(startAngle);
30230 if (currFullAngle > 360) {
30231 endAngle = endAngle - 0.01;
30232 }
30233 var prevFullAngle = Math.abs(prevEndAngle) + Math.abs(prevStartAngle);
30234 if (prevFullAngle > 360) {
30235 prevEndAngle = prevEndAngle - 0.01;
30236 }
30237 var angle = endAngle - startAngle;
30238 var dashArray = Array.isArray(w.config.stroke.dashArray) ? w.config.stroke.dashArray[i] : w.config.stroke.dashArray;
30239 var elPath = graphics.drawPath({
30240 d: '',
30241 stroke: pathFill,
30242 strokeWidth: strokeWidth,
30243 fill: 'none',
30244 fillOpacity: w.config.fill.opacity,
30245 classes: 'apexcharts-radialbar-area apexcharts-radialbar-slice-' + i,
30246 strokeDashArray: dashArray
30247 });
30248 Graphics.setAttrs(elPath.node, {
30249 'data:angle': angle,
30250 'data:value': opts.series[i]
30251 });
30252 if (w.config.chart.dropShadow.enabled) {
30253 var _shadow = w.config.chart.dropShadow;
30254 filters.dropShadow(elPath, _shadow, i);
30255 }
30256 filters.setSelectionFilter(elPath, 0, i);
30257 this.addListeners(elPath, this.radialDataLabels);
30258 elRadialBarArc.add(elPath);
30259 elPath.attr({
30260 index: 0,
30261 j: i
30262 });
30263 if (this.barLabels.enabled) {
30264 var barStartCords = Utils$1.polarToCartesian(opts.centerX, opts.centerY, opts.size, startAngle);
30265 var text = this.barLabels.formatter(w.globals.seriesNames[i], {
30266 seriesIndex: i,
30267 w: w
30268 });
30269 var classes = ['apexcharts-radialbar-label'];
30270 if (!this.barLabels.onClick) {
30271 classes.push('apexcharts-no-click');
30272 }
30273 var textColor = this.barLabels.useSeriesColors ? w.globals.colors[i] : w.config.chart.foreColor;
30274 if (!textColor) {
30275 textColor = w.config.chart.foreColor;
30276 }
30277 var x = barStartCords.x + this.barLabels.offsetX;
30278 var y = barStartCords.y + this.barLabels.offsetY;
30279 var elText = graphics.drawText({
30280 x: x,
30281 y: y,
30282 text: text,
30283 textAnchor: 'end',
30284 dominantBaseline: 'middle',
30285 fontFamily: this.barLabels.fontFamily,
30286 fontWeight: this.barLabels.fontWeight,
30287 fontSize: this.barLabels.fontSize,
30288 foreColor: textColor,
30289 cssClass: classes.join(' ')
30290 });
30291 elText.on('click', this.onBarLabelClick);
30292 elText.attr({
30293 rel: i + 1
30294 });
30295 if (startAngle !== 0) {
30296 elText.attr({
30297 'transform-origin': "".concat(x, " ").concat(y),
30298 transform: "rotate(".concat(startAngle, " 0 0)")
30299 });
30300 }
30301 elRadialBarArc.add(elText);
30302 }
30303 var dur = 0;
30304 if (this.initialAnim && !w.globals.resized && !w.globals.dataChanged) {
30305 dur = w.config.chart.animations.speed;
30306 }
30307 if (w.globals.dataChanged) {
30308 dur = w.config.chart.animations.dynamicAnimation.speed;
30309 }
30310 this.animDur = dur / (opts.series.length * 1.2) + this.animDur;
30311 this.animBeginArr.push(this.animDur);
30312 this.animatePaths(elPath, {
30313 centerX: opts.centerX,
30314 centerY: opts.centerY,
30315 endAngle: endAngle,
30316 startAngle: startAngle,
30317 prevEndAngle: prevEndAngle,
30318 prevStartAngle: prevStartAngle,
30319 size: opts.size,
30320 i: i,
30321 totalItems: 2,
30322 animBeginArr: this.animBeginArr,
30323 dur: dur,
30324 shouldSetPrevPaths: true
30325 });
30326 }
30327 return {
30328 g: g,
30329 elHollow: elHollow,
30330 dataLabels: dataLabels
30331 };
30332 }
30333 }, {
30334 key: "drawHollow",
30335 value: function drawHollow(opts) {
30336 var graphics = new Graphics(this.ctx);
30337 var circle = graphics.drawCircle(opts.size * 2);
30338 circle.attr({
30339 class: 'apexcharts-radialbar-hollow',
30340 cx: opts.centerX,
30341 cy: opts.centerY,
30342 r: opts.size,
30343 fill: opts.fill
30344 });
30345 return circle;
30346 }
30347 }, {
30348 key: "drawHollowImage",
30349 value: function drawHollowImage(opts, g, hollowSize, hollowFillID) {
30350 var w = this.w;
30351 var fill = new Fill(this.ctx);
30352 var randID = Utils$1.randomId();
30353 var hollowFillImg = w.config.plotOptions.radialBar.hollow.image;
30354 if (w.config.plotOptions.radialBar.hollow.imageClipped) {
30355 fill.clippedImgArea({
30356 width: hollowSize,
30357 height: hollowSize,
30358 image: hollowFillImg,
30359 patternID: "pattern".concat(w.globals.cuid).concat(randID)
30360 });
30361 hollowFillID = "url(#pattern".concat(w.globals.cuid).concat(randID, ")");
30362 } else {
30363 var imgWidth = w.config.plotOptions.radialBar.hollow.imageWidth;
30364 var imgHeight = w.config.plotOptions.radialBar.hollow.imageHeight;
30365 if (imgWidth === undefined && imgHeight === undefined) {
30366 var image = w.globals.dom.Paper.image(hollowFillImg, function (loader) {
30367 this.move(opts.centerX - loader.width / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetX, opts.centerY - loader.height / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetY);
30368 });
30369 g.add(image);
30370 } else {
30371 var _image = w.globals.dom.Paper.image(hollowFillImg, function (loader) {
30372 this.move(opts.centerX - imgWidth / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetX, opts.centerY - imgHeight / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetY);
30373 this.size(imgWidth, imgHeight);
30374 });
30375 g.add(_image);
30376 }
30377 }
30378 return hollowFillID;
30379 }
30380 }, {
30381 key: "getStrokeWidth",
30382 value: function getStrokeWidth(opts) {
30383 var w = this.w;
30384 return opts.size * (100 - parseInt(w.config.plotOptions.radialBar.hollow.size, 10)) / 100 / (opts.series.length + 1) - this.margin;
30385 }
30386 }, {
30387 key: "onBarLabelClick",
30388 value: function onBarLabelClick(e) {
30389 var seriesIndex = parseInt(e.target.getAttribute('rel'), 10) - 1;
30390 var legendClick = this.barLabels.onClick;
30391 var w = this.w;
30392 if (legendClick) {
30393 legendClick(w.globals.seriesNames[seriesIndex], {
30394 w: w,
30395 seriesIndex: seriesIndex
30396 });
30397 }
30398 }
30399 }]);
30400 return Radial;
30401 }(Pie);
30402
30403 /**
30404 * ApexCharts RangeBar Class responsible for drawing Range/Timeline Bars.
30405 *
30406 * @module RangeBar
30407 **/
30408 var RangeBar = /*#__PURE__*/function (_Bar) {
30409 _inherits(RangeBar, _Bar);
30410 var _super = _createSuper(RangeBar);
30411 function RangeBar() {
30412 _classCallCheck(this, RangeBar);
30413 return _super.apply(this, arguments);
30414 }
30415 _createClass(RangeBar, [{
30416 key: "draw",
30417 value: function draw(series, seriesIndex) {
30418 var w = this.w;
30419 var graphics = new Graphics(this.ctx);
30420 this.rangeBarOptions = this.w.config.plotOptions.rangeBar;
30421 this.series = series;
30422 this.seriesRangeStart = w.globals.seriesRangeStart;
30423 this.seriesRangeEnd = w.globals.seriesRangeEnd;
30424 this.barHelpers.initVariables(series);
30425 var ret = graphics.group({
30426 class: 'apexcharts-rangebar-series apexcharts-plot-series'
30427 });
30428 for (var i = 0; i < series.length; i++) {
30429 var x = void 0,
30430 y = void 0,
30431 xDivision = void 0,
30432 // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
30433 yDivision = void 0,
30434 // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
30435 zeroH = void 0,
30436 // zeroH is the baseline where 0 meets y axis
30437 zeroW = void 0; // zeroW is the baseline where 0 meets x axis
30438
30439 var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
30440 var _this$barHelpers$getG = this.barHelpers.getGroupIndex(realIndex),
30441 columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
30442
30443 // el to which series will be drawn
30444 var elSeries = graphics.group({
30445 class: "apexcharts-series",
30446 seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
30447 rel: i + 1,
30448 'data:realIndex': realIndex
30449 });
30450 this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
30451 if (series[i].length > 0) {
30452 this.visibleI = this.visibleI + 1;
30453 }
30454 var barHeight = 0;
30455 var barWidth = 0;
30456 var translationsIndex = 0;
30457 if (this.yRatio.length > 1) {
30458 this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0];
30459 translationsIndex = realIndex;
30460 }
30461 var initPositions = this.barHelpers.initialPositions(realIndex);
30462 y = initPositions.y;
30463 zeroW = initPositions.zeroW;
30464 x = initPositions.x;
30465 barWidth = initPositions.barWidth;
30466 barHeight = initPositions.barHeight;
30467 xDivision = initPositions.xDivision;
30468 yDivision = initPositions.yDivision;
30469 zeroH = initPositions.zeroH;
30470
30471 // eldatalabels
30472 var elDataLabelsWrap = graphics.group({
30473 class: 'apexcharts-datalabels',
30474 'data:realIndex': realIndex
30475 });
30476 var elGoalsMarkers = graphics.group({
30477 class: 'apexcharts-rangebar-goals-markers'
30478 });
30479 for (var j = 0; j < w.globals.dataPoints; j++) {
30480 var strokeWidth = this.barHelpers.getStrokeWidth(i, j, realIndex);
30481 var y1 = this.seriesRangeStart[i][j];
30482 var y2 = this.seriesRangeEnd[i][j];
30483 var paths = null;
30484 var barXPosition = null;
30485 var barYPosition = null;
30486 var params = {
30487 x: x,
30488 y: y,
30489 strokeWidth: strokeWidth,
30490 elSeries: elSeries
30491 };
30492 var seriesLen = this.seriesLen;
30493 if (w.config.plotOptions.bar.rangeBarGroupRows) {
30494 seriesLen = 1;
30495 }
30496 if (typeof w.config.series[i].data[j] === 'undefined') {
30497 // no data exists for further indexes, hence we need to get out the innr loop.
30498 // As we are iterating over total datapoints, there is a possiblity the series might not have data for j index
30499 break;
30500 }
30501 if (this.isHorizontal) {
30502 barYPosition = y + barHeight * this.visibleI;
30503 var srty = (yDivision - barHeight * seriesLen) / 2;
30504 if (w.config.series[i].data[j].x) {
30505 var positions = this.detectOverlappingBars({
30506 i: i,
30507 j: j,
30508 barYPosition: barYPosition,
30509 srty: srty,
30510 barHeight: barHeight,
30511 yDivision: yDivision,
30512 initPositions: initPositions
30513 });
30514 barHeight = positions.barHeight;
30515 barYPosition = positions.barYPosition;
30516 }
30517 paths = this.drawRangeBarPaths(_objectSpread2({
30518 indexes: {
30519 i: i,
30520 j: j,
30521 realIndex: realIndex
30522 },
30523 barHeight: barHeight,
30524 barYPosition: barYPosition,
30525 zeroW: zeroW,
30526 yDivision: yDivision,
30527 y1: y1,
30528 y2: y2
30529 }, params));
30530 barWidth = paths.barWidth;
30531 } else {
30532 if (w.globals.isXNumeric) {
30533 x = (w.globals.seriesX[i][j] - w.globals.minX) / this.xRatio - barWidth / 2;
30534 }
30535 barXPosition = x + barWidth * this.visibleI;
30536 var srtx = (xDivision - barWidth * seriesLen) / 2;
30537 if (w.config.series[i].data[j].x) {
30538 var _positions = this.detectOverlappingBars({
30539 i: i,
30540 j: j,
30541 barXPosition: barXPosition,
30542 srtx: srtx,
30543 barWidth: barWidth,
30544 xDivision: xDivision,
30545 initPositions: initPositions
30546 });
30547 barWidth = _positions.barWidth;
30548 barXPosition = _positions.barXPosition;
30549 }
30550 paths = this.drawRangeColumnPaths(_objectSpread2({
30551 indexes: {
30552 i: i,
30553 j: j,
30554 realIndex: realIndex,
30555 translationsIndex: translationsIndex
30556 },
30557 barWidth: barWidth,
30558 barXPosition: barXPosition,
30559 zeroH: zeroH,
30560 xDivision: xDivision
30561 }, params));
30562 barHeight = paths.barHeight;
30563 }
30564 var barGoalLine = this.barHelpers.drawGoalLine({
30565 barXPosition: paths.barXPosition,
30566 barYPosition: barYPosition,
30567 goalX: paths.goalX,
30568 goalY: paths.goalY,
30569 barHeight: barHeight,
30570 barWidth: barWidth
30571 });
30572 if (barGoalLine) {
30573 elGoalsMarkers.add(barGoalLine);
30574 }
30575 y = paths.y;
30576 x = paths.x;
30577 var pathFill = this.barHelpers.getPathFillColor(series, i, j, realIndex);
30578 this.renderSeries({
30579 realIndex: realIndex,
30580 pathFill: pathFill.color,
30581 lineFill: pathFill.useRangeColor ? pathFill.color : w.globals.stroke.colors[realIndex],
30582 j: j,
30583 i: i,
30584 x: x,
30585 y: y,
30586 y1: y1,
30587 y2: y2,
30588 pathFrom: paths.pathFrom,
30589 pathTo: paths.pathTo,
30590 strokeWidth: strokeWidth,
30591 elSeries: elSeries,
30592 series: series,
30593 barHeight: barHeight,
30594 barWidth: barWidth,
30595 barXPosition: barXPosition,
30596 barYPosition: barYPosition,
30597 columnGroupIndex: columnGroupIndex,
30598 elDataLabelsWrap: elDataLabelsWrap,
30599 elGoalsMarkers: elGoalsMarkers,
30600 visibleSeries: this.visibleI,
30601 type: 'rangebar'
30602 });
30603 }
30604 ret.add(elSeries);
30605 }
30606 return ret;
30607 }
30608 }, {
30609 key: "detectOverlappingBars",
30610 value: function detectOverlappingBars(_ref) {
30611 var i = _ref.i,
30612 j = _ref.j,
30613 barYPosition = _ref.barYPosition,
30614 barXPosition = _ref.barXPosition,
30615 srty = _ref.srty,
30616 srtx = _ref.srtx,
30617 barHeight = _ref.barHeight,
30618 barWidth = _ref.barWidth,
30619 yDivision = _ref.yDivision,
30620 xDivision = _ref.xDivision,
30621 initPositions = _ref.initPositions;
30622 var w = this.w;
30623 var overlaps = [];
30624 var rangeName = w.config.series[i].data[j].rangeName;
30625 var x = w.config.series[i].data[j].x;
30626 var labelX = Array.isArray(x) ? x.join(' ') : x;
30627 var rowIndex = w.globals.labels.map(function (_) {
30628 return Array.isArray(_) ? _.join(' ') : _;
30629 }).indexOf(labelX);
30630 var overlappedIndex = w.globals.seriesRange[i].findIndex(function (tx) {
30631 return tx.x === labelX && tx.overlaps.length > 0;
30632 });
30633 if (this.isHorizontal) {
30634 if (w.config.plotOptions.bar.rangeBarGroupRows) {
30635 barYPosition = srty + yDivision * rowIndex;
30636 } else {
30637 barYPosition = srty + barHeight * this.visibleI + yDivision * rowIndex;
30638 }
30639 if (overlappedIndex > -1 && !w.config.plotOptions.bar.rangeBarOverlap) {
30640 overlaps = w.globals.seriesRange[i][overlappedIndex].overlaps;
30641 if (overlaps.indexOf(rangeName) > -1) {
30642 barHeight = initPositions.barHeight / overlaps.length;
30643 barYPosition = barHeight * this.visibleI + yDivision * (100 - parseInt(this.barOptions.barHeight, 10)) / 100 / 2 + barHeight * (this.visibleI + overlaps.indexOf(rangeName)) + yDivision * rowIndex;
30644 }
30645 }
30646 } else {
30647 if (rowIndex > -1 && !w.globals.timescaleLabels.length) {
30648 if (w.config.plotOptions.bar.rangeBarGroupRows) {
30649 barXPosition = srtx + xDivision * rowIndex;
30650 } else {
30651 barXPosition = srtx + barWidth * this.visibleI + xDivision * rowIndex;
30652 }
30653 }
30654 if (overlappedIndex > -1 && !w.config.plotOptions.bar.rangeBarOverlap) {
30655 overlaps = w.globals.seriesRange[i][overlappedIndex].overlaps;
30656 if (overlaps.indexOf(rangeName) > -1) {
30657 barWidth = initPositions.barWidth / overlaps.length;
30658 barXPosition = barWidth * this.visibleI + xDivision * (100 - parseInt(this.barOptions.barWidth, 10)) / 100 / 2 + barWidth * (this.visibleI + overlaps.indexOf(rangeName)) + xDivision * rowIndex;
30659 }
30660 }
30661 }
30662 return {
30663 barYPosition: barYPosition,
30664 barXPosition: barXPosition,
30665 barHeight: barHeight,
30666 barWidth: barWidth
30667 };
30668 }
30669 }, {
30670 key: "drawRangeColumnPaths",
30671 value: function drawRangeColumnPaths(_ref2) {
30672 var indexes = _ref2.indexes,
30673 x = _ref2.x,
30674 xDivision = _ref2.xDivision,
30675 barWidth = _ref2.barWidth,
30676 barXPosition = _ref2.barXPosition,
30677 zeroH = _ref2.zeroH;
30678 var w = this.w;
30679 var i = indexes.i,
30680 j = indexes.j,
30681 realIndex = indexes.realIndex,
30682 translationsIndex = indexes.translationsIndex;
30683 var yRatio = this.yRatio[translationsIndex];
30684 var range = this.getRangeValue(realIndex, j);
30685 var y1 = Math.min(range.start, range.end);
30686 var y2 = Math.max(range.start, range.end);
30687 if (typeof this.series[i][j] === 'undefined' || this.series[i][j] === null) {
30688 y1 = zeroH;
30689 } else {
30690 y1 = zeroH - y1 / yRatio;
30691 y2 = zeroH - y2 / yRatio;
30692 }
30693 var barHeight = Math.abs(y2 - y1);
30694 var paths = this.barHelpers.getColumnPaths({
30695 barXPosition: barXPosition,
30696 barWidth: barWidth,
30697 y1: y1,
30698 y2: y2,
30699 strokeWidth: this.strokeWidth,
30700 series: this.seriesRangeEnd,
30701 realIndex: realIndex,
30702 i: realIndex,
30703 j: j,
30704 w: w
30705 });
30706 if (!w.globals.isXNumeric) {
30707 x = x + xDivision;
30708 } else {
30709 var xForNumericXAxis = this.getBarXForNumericXAxis({
30710 x: x,
30711 j: j,
30712 realIndex: realIndex,
30713 barWidth: barWidth
30714 });
30715 x = xForNumericXAxis.x;
30716 barXPosition = xForNumericXAxis.barXPosition;
30717 }
30718 return {
30719 pathTo: paths.pathTo,
30720 pathFrom: paths.pathFrom,
30721 barHeight: barHeight,
30722 x: x,
30723 y: range.start < 0 && range.end < 0 ? y1 : y2,
30724 goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
30725 barXPosition: barXPosition
30726 };
30727 }
30728 }, {
30729 key: "preventBarOverflow",
30730 value: function preventBarOverflow(val) {
30731 var w = this.w;
30732 if (val < 0) {
30733 val = 0;
30734 }
30735 if (val > w.globals.gridWidth) {
30736 val = w.globals.gridWidth;
30737 }
30738 return val;
30739 }
30740 }, {
30741 key: "drawRangeBarPaths",
30742 value: function drawRangeBarPaths(_ref3) {
30743 var indexes = _ref3.indexes,
30744 y = _ref3.y,
30745 y1 = _ref3.y1,
30746 y2 = _ref3.y2,
30747 yDivision = _ref3.yDivision,
30748 barHeight = _ref3.barHeight,
30749 barYPosition = _ref3.barYPosition,
30750 zeroW = _ref3.zeroW;
30751 var w = this.w;
30752 var realIndex = indexes.realIndex,
30753 j = indexes.j;
30754 var x1 = this.preventBarOverflow(zeroW + y1 / this.invertedYRatio);
30755 var x2 = this.preventBarOverflow(zeroW + y2 / this.invertedYRatio);
30756 var range = this.getRangeValue(realIndex, j);
30757 var barWidth = Math.abs(x2 - x1);
30758 var paths = this.barHelpers.getBarpaths({
30759 barYPosition: barYPosition,
30760 barHeight: barHeight,
30761 x1: x1,
30762 x2: x2,
30763 strokeWidth: this.strokeWidth,
30764 series: this.seriesRangeEnd,
30765 i: realIndex,
30766 realIndex: realIndex,
30767 j: j,
30768 w: w
30769 });
30770 if (!w.globals.isXNumeric) {
30771 y = y + yDivision;
30772 }
30773 return {
30774 pathTo: paths.pathTo,
30775 pathFrom: paths.pathFrom,
30776 barWidth: barWidth,
30777 x: range.start < 0 && range.end < 0 ? x1 : x2,
30778 goalX: this.barHelpers.getGoalValues('x', zeroW, null, realIndex, j),
30779 y: y
30780 };
30781 }
30782 }, {
30783 key: "getRangeValue",
30784 value: function getRangeValue(i, j) {
30785 var w = this.w;
30786 return {
30787 start: w.globals.seriesRangeStart[i][j],
30788 end: w.globals.seriesRangeEnd[i][j]
30789 };
30790 }
30791 }]);
30792 return RangeBar;
30793 }(Bar);
30794
30795 var Helpers = /*#__PURE__*/function () {
30796 function Helpers(lineCtx) {
30797 _classCallCheck(this, Helpers);
30798 this.w = lineCtx.w;
30799 this.lineCtx = lineCtx;
30800 }
30801 _createClass(Helpers, [{
30802 key: "sameValueSeriesFix",
30803 value: function sameValueSeriesFix(i, series) {
30804 var w = this.w;
30805 if (w.config.fill.type === 'gradient' || w.config.fill.type[i] === 'gradient') {
30806 var coreUtils = new CoreUtils(this.lineCtx.ctx, w);
30807
30808 // applied only to LINE chart
30809 // a small adjustment to allow gradient line to draw correctly for all same values
30810 /* #fix https://github.com/apexcharts/apexcharts.js/issues/358 */
30811 if (coreUtils.seriesHaveSameValues(i)) {
30812 var gSeries = series[i].slice();
30813 gSeries[gSeries.length - 1] = gSeries[gSeries.length - 1] + 0.000001;
30814 series[i] = gSeries;
30815 }
30816 }
30817 return series;
30818 }
30819 }, {
30820 key: "calculatePoints",
30821 value: function calculatePoints(_ref) {
30822 var series = _ref.series,
30823 realIndex = _ref.realIndex,
30824 x = _ref.x,
30825 y = _ref.y,
30826 i = _ref.i,
30827 j = _ref.j,
30828 prevY = _ref.prevY;
30829 var w = this.w;
30830 var ptX = [];
30831 var ptY = [];
30832 var xPT1st = this.lineCtx.categoryAxisCorrection + w.config.markers.offsetX;
30833
30834 // the first point for line series
30835 // we need to check whether it's not a time series, because a time series may
30836 // start from the middle of the x axis
30837 if (w.globals.isXNumeric) {
30838 xPT1st = (w.globals.seriesX[realIndex][0] - w.globals.minX) / this.lineCtx.xRatio + w.config.markers.offsetX;
30839 }
30840
30841 // push 2 points for the first data values
30842 if (j === 0) {
30843 ptX.push(xPT1st);
30844 ptY.push(Utils$1.isNumber(series[i][0]) ? prevY + w.config.markers.offsetY : null);
30845 }
30846 ptX.push(x + w.config.markers.offsetX);
30847 ptY.push(Utils$1.isNumber(series[i][j + 1]) ? y + w.config.markers.offsetY : null);
30848 return {
30849 x: ptX,
30850 y: ptY
30851 };
30852 }
30853 }, {
30854 key: "checkPreviousPaths",
30855 value: function checkPreviousPaths(_ref2) {
30856 var pathFromLine = _ref2.pathFromLine,
30857 pathFromArea = _ref2.pathFromArea,
30858 realIndex = _ref2.realIndex;
30859 var w = this.w;
30860 for (var pp = 0; pp < w.globals.previousPaths.length; pp++) {
30861 var gpp = w.globals.previousPaths[pp];
30862 if ((gpp.type === 'line' || gpp.type === 'area') && gpp.paths.length > 0 && parseInt(gpp.realIndex, 10) === parseInt(realIndex, 10)) {
30863 if (gpp.type === 'line') {
30864 this.lineCtx.appendPathFrom = false;
30865 pathFromLine = w.globals.previousPaths[pp].paths[0].d;
30866 } else if (gpp.type === 'area') {
30867 this.lineCtx.appendPathFrom = false;
30868 pathFromArea = w.globals.previousPaths[pp].paths[0].d;
30869 if (w.config.stroke.show && w.globals.previousPaths[pp].paths[1]) {
30870 pathFromLine = w.globals.previousPaths[pp].paths[1].d;
30871 }
30872 }
30873 }
30874 }
30875 return {
30876 pathFromLine: pathFromLine,
30877 pathFromArea: pathFromArea
30878 };
30879 }
30880 }, {
30881 key: "determineFirstPrevY",
30882 value: function determineFirstPrevY(_ref3) {
30883 var _this$w$config$series, _this$w$config$series2, _series$i;
30884 var i = _ref3.i,
30885 realIndex = _ref3.realIndex,
30886 series = _ref3.series,
30887 prevY = _ref3.prevY,
30888 lineYPosition = _ref3.lineYPosition,
30889 translationsIndex = _ref3.translationsIndex;
30890 var w = this.w;
30891 var stackSeries = w.config.chart.stacked && !w.globals.comboCharts || w.config.chart.stacked && w.globals.comboCharts && (!this.w.config.chart.stackOnlyBar || ((_this$w$config$series = this.w.config.series[realIndex]) === null || _this$w$config$series === void 0 ? void 0 : _this$w$config$series.type) === 'bar' || ((_this$w$config$series2 = this.w.config.series[realIndex]) === null || _this$w$config$series2 === void 0 ? void 0 : _this$w$config$series2.type) === 'column');
30892 if (typeof ((_series$i = series[i]) === null || _series$i === void 0 ? void 0 : _series$i[0]) !== 'undefined') {
30893 if (stackSeries) {
30894 if (i > 0) {
30895 // 1st y value of previous series
30896 lineYPosition = this.lineCtx.prevSeriesY[i - 1][0];
30897 } else {
30898 // the first series will not have prevY values
30899 lineYPosition = this.lineCtx.zeroY;
30900 }
30901 } else {
30902 lineYPosition = this.lineCtx.zeroY;
30903 }
30904 prevY = lineYPosition - series[i][0] / this.lineCtx.yRatio[translationsIndex] + (this.lineCtx.isReversed ? series[i][0] / this.lineCtx.yRatio[translationsIndex] : 0) * 2;
30905 } else {
30906 // the first value in the current series is null
30907 if (stackSeries && i > 0 && typeof series[i][0] === 'undefined') {
30908 // check for undefined value (undefined value will occur when we clear the series while user clicks on legend to hide serieses)
30909 for (var s = i - 1; s >= 0; s--) {
30910 // for loop to get to 1st previous value until we get it
30911 if (series[s][0] !== null && typeof series[s][0] !== 'undefined') {
30912 lineYPosition = this.lineCtx.prevSeriesY[s][0];
30913 prevY = lineYPosition;
30914 break;
30915 }
30916 }
30917 }
30918 }
30919 return {
30920 prevY: prevY,
30921 lineYPosition: lineYPosition
30922 };
30923 }
30924 }]);
30925 return Helpers;
30926 }();
30927
30928 /**
30929 *
30930 * @yr/monotone-cubic-spline (https://github.com/YR/monotone-cubic-spline)
30931 *
30932 * The MIT License (MIT)
30933 *
30934 * Copyright (c) 2015 yr.no
30935 *
30936 * Permission is hereby granted, free of charge, to any person obtaining a copy of
30937 * this software and associated documentation files (the "Software"), to deal in
30938 * the Software without restriction, including without limitation the rights to
30939 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
30940 * the Software, and to permit persons to whom the Software is furnished to do so,
30941 * subject to the following conditions:
30942 *
30943 * The above copyright notice and this permission notice shall be included in all
30944 * copies or substantial portions of the Software.
30945
30946 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30947 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
30948 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
30949 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
30950 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30951 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30952 */
30953 /**
30954 * Generate tangents for 'points'
30955 * @param {Array} points
30956 * @returns {Array}
30957 */
30958 var tangents = function tangents(points) {
30959 var m = finiteDifferences(points);
30960 var n = points.length - 1;
30961 var ε = 1e-6;
30962 var tgts = [];
30963 var a, b, d, s;
30964 for (var i = 0; i < n; i++) {
30965 d = slope(points[i], points[i + 1]);
30966 if (Math.abs(d) < ε) {
30967 m[i] = m[i + 1] = 0;
30968 } else {
30969 a = m[i] / d;
30970 b = m[i + 1] / d;
30971 s = a * a + b * b;
30972 if (s > 9) {
30973 s = d * 3 / Math.sqrt(s);
30974 m[i] = s * a;
30975 m[i + 1] = s * b;
30976 }
30977 }
30978 }
30979 for (var _i = 0; _i <= n; _i++) {
30980 s = (points[Math.min(n, _i + 1)][0] - points[Math.max(0, _i - 1)][0]) / (6 * (1 + m[_i] * m[_i]));
30981 tgts.push([s || 0, m[_i] * s || 0]);
30982 }
30983 return tgts;
30984 };
30985
30986 /**
30987 * Convert 'points' to svg path
30988 * @param {Array} points
30989 * @returns {String}
30990 */
30991 var svgPath = function svgPath(points) {
30992 var p = '';
30993 for (var i = 0; i < points.length; i++) {
30994 var point = points[i];
30995 var n = point.length;
30996 if (n > 4) {
30997 p += "C".concat(point[0], ", ").concat(point[1]);
30998 p += ", ".concat(point[2], ", ").concat(point[3]);
30999 p += ", ".concat(point[4], ", ").concat(point[5]);
31000 } else if (n > 2) {
31001 p += "S".concat(point[0], ", ").concat(point[1]);
31002 p += ", ".concat(point[2], ", ").concat(point[3]);
31003 }
31004 }
31005 return p;
31006 };
31007 var spline = {
31008 /**
31009 * Convert 'points' to bezier
31010 * @param {Array} points
31011 * @returns {Array}
31012 */
31013 points: function points(_points) {
31014 var tgts = tangents(_points);
31015 var p = _points[1];
31016 var p0 = _points[0];
31017 var pts = [];
31018 var t = tgts[1];
31019 var t0 = tgts[0];
31020
31021 // Add starting 'M' and 'C' points
31022 pts.push(p0, [p0[0] + t0[0], p0[1] + t0[1], p[0] - t[0], p[1] - t[1], p[0], p[1]]);
31023
31024 // Add 'S' points
31025 for (var i = 2, n = tgts.length; i < n; i++) {
31026 var _p = _points[i];
31027 var _t = tgts[i];
31028 pts.push([_p[0] - _t[0], _p[1] - _t[1], _p[0], _p[1]]);
31029 }
31030 return pts;
31031 },
31032 /**
31033 * Slice out a segment of 'points'
31034 * @param {Array} points
31035 * @param {Number} start
31036 * @param {Number} end
31037 * @returns {Array}
31038 */
31039 slice: function slice(points, start, end) {
31040 var pts = points.slice(start, end);
31041 if (start) {
31042 // Add additional 'C' points
31043 if (end - start > 1 && pts[1].length < 6) {
31044 var n = pts[0].length;
31045 pts[1] = [pts[0][n - 2] * 2 - pts[0][n - 4], pts[0][n - 1] * 2 - pts[0][n - 3]].concat(pts[1]);
31046 }
31047 // Remove control points for 'M'
31048 pts[0] = pts[0].slice(-2);
31049 }
31050 return pts;
31051 }
31052 };
31053
31054 /**
31055 * Compute slope from point 'p0' to 'p1'
31056 * @param {Array} p0
31057 * @param {Array} p1
31058 * @returns {Number}
31059 */
31060 function slope(p0, p1) {
31061 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
31062 }
31063
31064 /**
31065 * Compute three-point differences for 'points'
31066 * @param {Array} points
31067 * @returns {Array}
31068 */
31069 function finiteDifferences(points) {
31070 var m = [];
31071 var p0 = points[0];
31072 var p1 = points[1];
31073 var d = m[0] = slope(p0, p1);
31074 var i = 1;
31075 for (var n = points.length - 1; i < n; i++) {
31076 p0 = p1;
31077 p1 = points[i + 1];
31078 m[i] = (d + (d = slope(p0, p1))) * 0.5;
31079 }
31080 m[i] = d;
31081 return m;
31082 }
31083
31084 /**
31085 * ApexCharts Line Class responsible for drawing Line / Area / RangeArea Charts.
31086 * This class is also responsible for generating values for Bubble/Scatter charts, so need to rename it to Axis Charts to avoid confusions
31087 * @module Line
31088 **/
31089 var Line = /*#__PURE__*/function () {
31090 function Line(ctx, xyRatios, isPointsChart) {
31091 _classCallCheck(this, Line);
31092 this.ctx = ctx;
31093 this.w = ctx.w;
31094 this.xyRatios = xyRatios;
31095 this.pointsChart = !(this.w.config.chart.type !== 'bubble' && this.w.config.chart.type !== 'scatter') || isPointsChart;
31096 this.scatter = new Scatter(this.ctx);
31097 this.noNegatives = this.w.globals.minX === Number.MAX_VALUE;
31098 this.lineHelpers = new Helpers(this);
31099 this.markers = new Markers(this.ctx);
31100 this.prevSeriesY = [];
31101 this.categoryAxisCorrection = 0;
31102 this.yaxisIndex = 0;
31103 }
31104 _createClass(Line, [{
31105 key: "draw",
31106 value: function draw(series, ctype, seriesIndex, seriesRangeEnd) {
31107 var _w$config$series$;
31108 var w = this.w;
31109 var graphics = new Graphics(this.ctx);
31110 var type = w.globals.comboCharts ? ctype : w.config.chart.type;
31111 var ret = graphics.group({
31112 class: "apexcharts-".concat(type, "-series apexcharts-plot-series")
31113 });
31114 var coreUtils = new CoreUtils(this.ctx, w);
31115 this.yRatio = this.xyRatios.yRatio;
31116 this.zRatio = this.xyRatios.zRatio;
31117 this.xRatio = this.xyRatios.xRatio;
31118 this.baseLineY = this.xyRatios.baseLineY;
31119 series = coreUtils.getLogSeries(series);
31120 this.yRatio = coreUtils.getLogYRatios(this.yRatio);
31121 // We call draw() for each series group
31122 this.prevSeriesY = [];
31123
31124 // push all series in an array, so we can draw in reverse order
31125 // (for stacked charts)
31126 var allSeries = [];
31127 for (var i = 0; i < series.length; i++) {
31128 series = this.lineHelpers.sameValueSeriesFix(i, series);
31129 var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
31130 var translationsIndex = this.yRatio.length > 1 ? realIndex : 0;
31131 this._initSerieVariables(series, i, realIndex);
31132 var yArrj = []; // hold y values of current iterating series
31133 var y2Arrj = []; // holds y2 values in range-area charts
31134 var xArrj = []; // hold x values of current iterating series
31135
31136 var x = w.globals.padHorizontal + this.categoryAxisCorrection;
31137 var y = 1;
31138 var linePaths = [];
31139 var areaPaths = [];
31140 this.ctx.series.addCollapsedClassToSeries(this.elSeries, realIndex);
31141 if (w.globals.isXNumeric && w.globals.seriesX.length > 0) {
31142 x = (w.globals.seriesX[realIndex][0] - w.globals.minX) / this.xRatio;
31143 }
31144 xArrj.push(x);
31145 var pX = x;
31146 var pY = void 0;
31147 var pY2 = void 0;
31148 var prevX = pX;
31149 var prevY = this.zeroY;
31150 var prevY2 = this.zeroY;
31151 var lineYPosition = 0;
31152
31153 // the first value in the current series is not null or undefined
31154 var firstPrevY = this.lineHelpers.determineFirstPrevY({
31155 i: i,
31156 realIndex: realIndex,
31157 series: series,
31158 prevY: prevY,
31159 lineYPosition: lineYPosition,
31160 translationsIndex: translationsIndex
31161 });
31162 prevY = firstPrevY.prevY;
31163 if (w.config.stroke.curve === 'monotoneCubic' && series[i][0] === null) {
31164 // we have to discard the y position if 1st dataPoint is null as it
31165 // causes issues with monotoneCubic path creation
31166 yArrj.push(null);
31167 } else {
31168 yArrj.push(prevY);
31169 }
31170 pY = prevY;
31171
31172 // y2 are needed for range-area charts
31173 var firstPrevY2 = void 0;
31174 if (type === 'rangeArea') {
31175 firstPrevY2 = this.lineHelpers.determineFirstPrevY({
31176 i: i,
31177 realIndex: realIndex,
31178 series: seriesRangeEnd,
31179 prevY: prevY2,
31180 lineYPosition: lineYPosition,
31181 translationsIndex: translationsIndex
31182 });
31183 prevY2 = firstPrevY2.prevY;
31184 pY2 = prevY2;
31185 y2Arrj.push(yArrj[0] !== null ? prevY2 : null);
31186 }
31187 var pathsFrom = this._calculatePathsFrom({
31188 type: type,
31189 series: series,
31190 i: i,
31191 realIndex: realIndex,
31192 translationsIndex: translationsIndex,
31193 prevX: prevX,
31194 prevY: prevY,
31195 prevY2: prevY2
31196 });
31197
31198 // RangeArea will resume with these for the upper path creation
31199 var rYArrj = [yArrj[0]];
31200 var rY2Arrj = [y2Arrj[0]];
31201 var iteratingOpts = {
31202 type: type,
31203 series: series,
31204 realIndex: realIndex,
31205 translationsIndex: translationsIndex,
31206 i: i,
31207 x: x,
31208 y: y,
31209 pX: pX,
31210 pY: pY,
31211 pathsFrom: pathsFrom,
31212 linePaths: linePaths,
31213 areaPaths: areaPaths,
31214 seriesIndex: seriesIndex,
31215 lineYPosition: lineYPosition,
31216 xArrj: xArrj,
31217 yArrj: yArrj,
31218 y2Arrj: y2Arrj,
31219 seriesRangeEnd: seriesRangeEnd
31220 };
31221 var paths = this._iterateOverDataPoints(_objectSpread2(_objectSpread2({}, iteratingOpts), {}, {
31222 iterations: type === 'rangeArea' ? series[i].length - 1 : undefined,
31223 isRangeStart: true
31224 }));
31225 if (type === 'rangeArea') {
31226 var pathsFrom2 = this._calculatePathsFrom({
31227 series: seriesRangeEnd,
31228 i: i,
31229 realIndex: realIndex,
31230 prevX: prevX,
31231 prevY: prevY2
31232 });
31233 var rangePaths = this._iterateOverDataPoints(_objectSpread2(_objectSpread2({}, iteratingOpts), {}, {
31234 series: seriesRangeEnd,
31235 xArrj: [x],
31236 yArrj: rYArrj,
31237 y2Arrj: rY2Arrj,
31238 pY: pY2,
31239 areaPaths: paths.areaPaths,
31240 pathsFrom: pathsFrom2,
31241 iterations: seriesRangeEnd[i].length - 1,
31242 isRangeStart: false
31243 }));
31244
31245 // Path may be segmented by nulls in data.
31246 // paths.linePaths should hold (segments * 2) paths (upper and lower)
31247 // the first n segments belong to the lower and the last n segments
31248 // belong to the upper.
31249 // paths.linePaths and rangePaths.linepaths are actually equivalent
31250 // but we retain the distinction below for consistency with the
31251 // unsegmented paths conditional branch.
31252 var segments = paths.linePaths.length / 2;
31253 for (var s = 0; s < segments; s++) {
31254 paths.linePaths[s] = rangePaths.linePaths[s + segments] + paths.linePaths[s];
31255 }
31256 paths.linePaths.splice(segments);
31257 paths.pathFromLine = rangePaths.pathFromLine + paths.pathFromLine;
31258 } else {
31259 paths.pathFromArea += 'z';
31260 }
31261 this._handlePaths({
31262 type: type,
31263 realIndex: realIndex,
31264 i: i,
31265 paths: paths
31266 });
31267 this.elSeries.add(this.elPointsMain);
31268 this.elSeries.add(this.elDataLabelsWrap);
31269 allSeries.push(this.elSeries);
31270 }
31271 if (typeof ((_w$config$series$ = w.config.series[0]) === null || _w$config$series$ === void 0 ? void 0 : _w$config$series$.zIndex) !== 'undefined') {
31272 allSeries.sort(function (a, b) {
31273 return Number(a.node.getAttribute('zIndex')) - Number(b.node.getAttribute('zIndex'));
31274 });
31275 }
31276 if (w.config.chart.stacked) {
31277 for (var _s = allSeries.length - 1; _s >= 0; _s--) {
31278 ret.add(allSeries[_s]);
31279 }
31280 } else {
31281 for (var _s2 = 0; _s2 < allSeries.length; _s2++) {
31282 ret.add(allSeries[_s2]);
31283 }
31284 }
31285 return ret;
31286 }
31287 }, {
31288 key: "_initSerieVariables",
31289 value: function _initSerieVariables(series, i, realIndex) {
31290 var w = this.w;
31291 var graphics = new Graphics(this.ctx);
31292
31293 // width divided into equal parts
31294 this.xDivision = w.globals.gridWidth / (w.globals.dataPoints - (w.config.xaxis.tickPlacement === 'on' ? 1 : 0));
31295 this.strokeWidth = Array.isArray(w.config.stroke.width) ? w.config.stroke.width[realIndex] : w.config.stroke.width;
31296 var translationsIndex = 0;
31297 if (this.yRatio.length > 1) {
31298 this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex];
31299 translationsIndex = realIndex;
31300 }
31301 this.isReversed = w.config.yaxis[this.yaxisIndex] && w.config.yaxis[this.yaxisIndex].reversed;
31302
31303 // zeroY is the 0 value in y series which can be used in negative charts
31304 this.zeroY = w.globals.gridHeight - this.baseLineY[translationsIndex] - (this.isReversed ? w.globals.gridHeight : 0) + (this.isReversed ? this.baseLineY[translationsIndex] * 2 : 0);
31305 this.areaBottomY = this.zeroY;
31306 if (this.zeroY > w.globals.gridHeight || w.config.plotOptions.area.fillTo === 'end') {
31307 this.areaBottomY = w.globals.gridHeight;
31308 }
31309 this.categoryAxisCorrection = this.xDivision / 2;
31310
31311 // el to which series will be drawn
31312 this.elSeries = graphics.group({
31313 class: "apexcharts-series",
31314 zIndex: typeof w.config.series[realIndex].zIndex !== 'undefined' ? w.config.series[realIndex].zIndex : realIndex,
31315 seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex])
31316 });
31317
31318 // points
31319 this.elPointsMain = graphics.group({
31320 class: 'apexcharts-series-markers-wrap',
31321 'data:realIndex': realIndex
31322 });
31323 if (w.globals.hasNullValues) {
31324 // fixes https://github.com/apexcharts/apexcharts.js/issues/3641
31325 var firstPoint = this.markers.plotChartMarkers({
31326 pointsPos: {
31327 x: [0],
31328 y: [w.globals.gridHeight + w.globals.markers.largestSize]
31329 },
31330 seriesIndex: i,
31331 j: 0,
31332 pSize: 0.1,
31333 alwaysDrawMarker: true,
31334 isVirtualPoint: true
31335 });
31336 if (firstPoint !== null) {
31337 // firstPoint is rendered for cases where there are null values and when dynamic markers are required
31338 this.elPointsMain.add(firstPoint);
31339 }
31340 }
31341
31342 // eldatalabels
31343 this.elDataLabelsWrap = graphics.group({
31344 class: 'apexcharts-datalabels',
31345 'data:realIndex': realIndex
31346 });
31347 var longestSeries = series[i].length === w.globals.dataPoints;
31348 this.elSeries.attr({
31349 'data:longestSeries': longestSeries,
31350 rel: i + 1,
31351 'data:realIndex': realIndex
31352 });
31353 this.appendPathFrom = true;
31354 }
31355 }, {
31356 key: "_calculatePathsFrom",
31357 value: function _calculatePathsFrom(_ref) {
31358 var type = _ref.type,
31359 series = _ref.series,
31360 i = _ref.i,
31361 realIndex = _ref.realIndex,
31362 translationsIndex = _ref.translationsIndex,
31363 prevX = _ref.prevX,
31364 prevY = _ref.prevY,
31365 prevY2 = _ref.prevY2;
31366 var w = this.w;
31367 var graphics = new Graphics(this.ctx);
31368 var linePath, areaPath, pathFromLine, pathFromArea;
31369 if (series[i][0] === null) {
31370 // when the first value itself is null, we need to move the pointer to a location where a null value is not found
31371 for (var s = 0; s < series[i].length; s++) {
31372 if (series[i][s] !== null) {
31373 prevX = this.xDivision * s;
31374 prevY = this.zeroY - series[i][s] / this.yRatio[translationsIndex];
31375 linePath = graphics.move(prevX, prevY);
31376 areaPath = graphics.move(prevX, this.areaBottomY);
31377 break;
31378 }
31379 }
31380 } else {
31381 linePath = graphics.move(prevX, prevY);
31382 if (type === 'rangeArea') {
31383 linePath = graphics.move(prevX, prevY2) + graphics.line(prevX, prevY);
31384 }
31385 areaPath = graphics.move(prevX, this.areaBottomY) + graphics.line(prevX, prevY);
31386 }
31387 pathFromLine = graphics.move(0, this.areaBottomY) + graphics.line(0, this.areaBottomY);
31388 pathFromArea = graphics.move(0, this.areaBottomY) + graphics.line(0, this.areaBottomY);
31389 if (w.globals.previousPaths.length > 0) {
31390 var pathFrom = this.lineHelpers.checkPreviousPaths({
31391 pathFromLine: pathFromLine,
31392 pathFromArea: pathFromArea,
31393 realIndex: realIndex
31394 });
31395 pathFromLine = pathFrom.pathFromLine;
31396 pathFromArea = pathFrom.pathFromArea;
31397 }
31398 return {
31399 prevX: prevX,
31400 prevY: prevY,
31401 linePath: linePath,
31402 areaPath: areaPath,
31403 pathFromLine: pathFromLine,
31404 pathFromArea: pathFromArea
31405 };
31406 }
31407 }, {
31408 key: "_handlePaths",
31409 value: function _handlePaths(_ref2) {
31410 var type = _ref2.type,
31411 realIndex = _ref2.realIndex,
31412 i = _ref2.i,
31413 paths = _ref2.paths;
31414 var w = this.w;
31415 var graphics = new Graphics(this.ctx);
31416 var fill = new Fill(this.ctx);
31417
31418 // push all current y values array to main PrevY Array
31419 this.prevSeriesY.push(paths.yArrj);
31420
31421 // push all x val arrays into main xArr
31422 w.globals.seriesXvalues[realIndex] = paths.xArrj;
31423 w.globals.seriesYvalues[realIndex] = paths.yArrj;
31424 var forecast = w.config.forecastDataPoints;
31425 if (forecast.count > 0 && type !== 'rangeArea') {
31426 var forecastCutoff = w.globals.seriesXvalues[realIndex][w.globals.seriesXvalues[realIndex].length - forecast.count - 1];
31427 var elForecastMask = graphics.drawRect(forecastCutoff, 0, w.globals.gridWidth, w.globals.gridHeight, 0);
31428 w.globals.dom.elForecastMask.appendChild(elForecastMask.node);
31429 var elNonForecastMask = graphics.drawRect(0, 0, forecastCutoff, w.globals.gridHeight, 0);
31430 w.globals.dom.elNonForecastMask.appendChild(elNonForecastMask.node);
31431 }
31432
31433 // these elements will be shown after area path animation completes
31434 if (!this.pointsChart) {
31435 w.globals.delayedElements.push({
31436 el: this.elPointsMain.node,
31437 index: realIndex
31438 });
31439 }
31440 var defaultRenderedPathOptions = {
31441 i: i,
31442 realIndex: realIndex,
31443 animationDelay: i,
31444 initialSpeed: w.config.chart.animations.speed,
31445 dataChangeSpeed: w.config.chart.animations.dynamicAnimation.speed,
31446 className: "apexcharts-".concat(type)
31447 };
31448 if (type === 'area') {
31449 var pathFill = fill.fillPath({
31450 seriesNumber: realIndex
31451 });
31452 for (var p = 0; p < paths.areaPaths.length; p++) {
31453 var renderedPath = graphics.renderPaths(_objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
31454 pathFrom: paths.pathFromArea,
31455 pathTo: paths.areaPaths[p],
31456 stroke: 'none',
31457 strokeWidth: 0,
31458 strokeLineCap: null,
31459 fill: pathFill
31460 }));
31461 this.elSeries.add(renderedPath);
31462 }
31463 }
31464 if (w.config.stroke.show && !this.pointsChart) {
31465 var lineFill = null;
31466 if (type === 'line') {
31467 lineFill = fill.fillPath({
31468 seriesNumber: realIndex,
31469 i: i
31470 });
31471 } else {
31472 if (w.config.stroke.fill.type === 'solid') {
31473 lineFill = w.globals.stroke.colors[realIndex];
31474 } else {
31475 var prevFill = w.config.fill;
31476 w.config.fill = w.config.stroke.fill;
31477 lineFill = fill.fillPath({
31478 seriesNumber: realIndex,
31479 i: i
31480 });
31481 w.config.fill = prevFill;
31482 }
31483 }
31484
31485 // range-area paths are drawn using linePaths
31486 for (var _p = 0; _p < paths.linePaths.length; _p++) {
31487 var _pathFill = lineFill;
31488 if (type === 'rangeArea') {
31489 _pathFill = fill.fillPath({
31490 seriesNumber: realIndex
31491 });
31492 }
31493 var linePathCommonOpts = _objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
31494 pathFrom: paths.pathFromLine,
31495 pathTo: paths.linePaths[_p],
31496 stroke: lineFill,
31497 strokeWidth: this.strokeWidth,
31498 strokeLineCap: w.config.stroke.lineCap,
31499 fill: type === 'rangeArea' ? _pathFill : 'none'
31500 });
31501 var _renderedPath = graphics.renderPaths(linePathCommonOpts);
31502 this.elSeries.add(_renderedPath);
31503 _renderedPath.attr('fill-rule', "evenodd");
31504 if (forecast.count > 0 && type !== 'rangeArea') {
31505 var renderedForecastPath = graphics.renderPaths(linePathCommonOpts);
31506 renderedForecastPath.node.setAttribute('stroke-dasharray', forecast.dashArray);
31507 if (forecast.strokeWidth) {
31508 renderedForecastPath.node.setAttribute('stroke-width', forecast.strokeWidth);
31509 }
31510 this.elSeries.add(renderedForecastPath);
31511 renderedForecastPath.attr('clip-path', "url(#forecastMask".concat(w.globals.cuid, ")"));
31512 _renderedPath.attr('clip-path', "url(#nonForecastMask".concat(w.globals.cuid, ")"));
31513 }
31514 }
31515 }
31516 }
31517 }, {
31518 key: "_iterateOverDataPoints",
31519 value: function _iterateOverDataPoints(_ref3) {
31520 var _this = this,
31521 _this$w$config$series,
31522 _this$w$config$series2;
31523 var type = _ref3.type,
31524 series = _ref3.series,
31525 iterations = _ref3.iterations,
31526 realIndex = _ref3.realIndex,
31527 translationsIndex = _ref3.translationsIndex,
31528 i = _ref3.i,
31529 x = _ref3.x,
31530 y = _ref3.y,
31531 pX = _ref3.pX,
31532 pY = _ref3.pY,
31533 pathsFrom = _ref3.pathsFrom,
31534 linePaths = _ref3.linePaths,
31535 areaPaths = _ref3.areaPaths,
31536 seriesIndex = _ref3.seriesIndex,
31537 lineYPosition = _ref3.lineYPosition,
31538 xArrj = _ref3.xArrj,
31539 yArrj = _ref3.yArrj,
31540 y2Arrj = _ref3.y2Arrj,
31541 isRangeStart = _ref3.isRangeStart,
31542 seriesRangeEnd = _ref3.seriesRangeEnd;
31543 var w = this.w;
31544 var graphics = new Graphics(this.ctx);
31545 var yRatio = this.yRatio;
31546 var prevY = pathsFrom.prevY,
31547 linePath = pathsFrom.linePath,
31548 areaPath = pathsFrom.areaPath,
31549 pathFromLine = pathsFrom.pathFromLine,
31550 pathFromArea = pathsFrom.pathFromArea;
31551 var minY = Utils$1.isNumber(w.globals.minYArr[realIndex]) ? w.globals.minYArr[realIndex] : w.globals.minY;
31552 if (!iterations) {
31553 iterations = w.globals.dataPoints > 1 ? w.globals.dataPoints - 1 : w.globals.dataPoints;
31554 }
31555 var getY = function getY(_y, lineYPos) {
31556 return lineYPos - _y / yRatio[translationsIndex] + (_this.isReversed ? _y / yRatio[translationsIndex] : 0) * 2;
31557 };
31558 var y2 = y;
31559 var stackSeries = w.config.chart.stacked && !w.globals.comboCharts || w.config.chart.stacked && w.globals.comboCharts && (!this.w.config.chart.stackOnlyBar || ((_this$w$config$series = this.w.config.series[realIndex]) === null || _this$w$config$series === void 0 ? void 0 : _this$w$config$series.type) === 'bar' || ((_this$w$config$series2 = this.w.config.series[realIndex]) === null || _this$w$config$series2 === void 0 ? void 0 : _this$w$config$series2.type) === 'column');
31560 var curve = w.config.stroke.curve;
31561 if (Array.isArray(curve)) {
31562 if (Array.isArray(seriesIndex)) {
31563 curve = curve[seriesIndex[i]];
31564 } else {
31565 curve = curve[i];
31566 }
31567 }
31568 var pathState = 0;
31569 var segmentStartX;
31570 for (var j = 0; j < iterations; j++) {
31571 if (series[i].length === 0) break;
31572 var isNull = typeof series[i][j + 1] === 'undefined' || series[i][j + 1] === null;
31573 if (w.globals.isXNumeric) {
31574 var sX = w.globals.seriesX[realIndex][j + 1];
31575 if (typeof w.globals.seriesX[realIndex][j + 1] === 'undefined') {
31576 /* fix #374 */
31577 sX = w.globals.seriesX[realIndex][iterations - 1];
31578 }
31579 x = (sX - w.globals.minX) / this.xRatio;
31580 } else {
31581 x = x + this.xDivision;
31582 }
31583 if (stackSeries) {
31584 if (i > 0 && w.globals.collapsedSeries.length < w.config.series.length - 1) {
31585 // a collapsed series in a stacked chart may provide wrong result
31586 // for the next series, hence find the prevIndex of prev series
31587 // which is not collapsed - fixes apexcharts.js#1372
31588 var prevIndex = function prevIndex(pi) {
31589 for (var pii = pi; pii > 0; pii--) {
31590 if (w.globals.collapsedSeriesIndices.indexOf((seriesIndex === null || seriesIndex === void 0 ? void 0 : seriesIndex[pii]) || pii) > -1) {
31591 pii--;
31592 } else {
31593 return pii;
31594 }
31595 }
31596 return 0;
31597 };
31598 lineYPosition = this.prevSeriesY[prevIndex(i - 1)][j + 1];
31599 } else {
31600 // the first series will not have prevY values
31601 lineYPosition = this.zeroY;
31602 }
31603 } else {
31604 lineYPosition = this.zeroY;
31605 }
31606 if (isNull) {
31607 y = getY(minY, lineYPosition);
31608 } else {
31609 y = getY(series[i][j + 1], lineYPosition);
31610 if (type === 'rangeArea') {
31611 y2 = getY(seriesRangeEnd[i][j + 1], lineYPosition);
31612 }
31613 }
31614
31615 // push current X
31616 xArrj.push(series[i][j + 1] === null ? null : x);
31617
31618 // push current Y that will be used as next series's bottom position
31619 if (isNull && (w.config.stroke.curve === 'smooth' || w.config.stroke.curve === 'monotoneCubic')) {
31620 yArrj.push(null);
31621 y2Arrj.push(null);
31622 } else {
31623 yArrj.push(y);
31624 y2Arrj.push(y2);
31625 }
31626 var pointsPos = this.lineHelpers.calculatePoints({
31627 series: series,
31628 x: x,
31629 y: y,
31630 realIndex: realIndex,
31631 i: i,
31632 j: j,
31633 prevY: prevY
31634 });
31635 var calculatedPaths = this._createPaths({
31636 type: type,
31637 series: series,
31638 i: i,
31639 realIndex: realIndex,
31640 j: j,
31641 x: x,
31642 y: y,
31643 y2: y2,
31644 xArrj: xArrj,
31645 yArrj: yArrj,
31646 y2Arrj: y2Arrj,
31647 pX: pX,
31648 pY: pY,
31649 pathState: pathState,
31650 segmentStartX: segmentStartX,
31651 linePath: linePath,
31652 areaPath: areaPath,
31653 linePaths: linePaths,
31654 areaPaths: areaPaths,
31655 curve: curve,
31656 isRangeStart: isRangeStart
31657 });
31658 areaPaths = calculatedPaths.areaPaths;
31659 linePaths = calculatedPaths.linePaths;
31660 pX = calculatedPaths.pX;
31661 pY = calculatedPaths.pY;
31662 pathState = calculatedPaths.pathState;
31663 segmentStartX = calculatedPaths.segmentStartX;
31664 areaPath = calculatedPaths.areaPath;
31665 linePath = calculatedPaths.linePath;
31666 if (this.appendPathFrom && !w.globals.hasNullValues && !(curve === 'monotoneCubic' && type === 'rangeArea')) {
31667 pathFromLine += graphics.line(x, this.areaBottomY);
31668 pathFromArea += graphics.line(x, this.areaBottomY);
31669 }
31670 this.handleNullDataPoints(series, pointsPos, i, j, realIndex);
31671 this._handleMarkersAndLabels({
31672 type: type,
31673 pointsPos: pointsPos,
31674 i: i,
31675 j: j,
31676 realIndex: realIndex,
31677 isRangeStart: isRangeStart
31678 });
31679 }
31680 return {
31681 yArrj: yArrj,
31682 xArrj: xArrj,
31683 pathFromArea: pathFromArea,
31684 areaPaths: areaPaths,
31685 pathFromLine: pathFromLine,
31686 linePaths: linePaths,
31687 linePath: linePath,
31688 areaPath: areaPath
31689 };
31690 }
31691 }, {
31692 key: "_handleMarkersAndLabels",
31693 value: function _handleMarkersAndLabels(_ref4) {
31694 var type = _ref4.type,
31695 pointsPos = _ref4.pointsPos,
31696 isRangeStart = _ref4.isRangeStart,
31697 i = _ref4.i,
31698 j = _ref4.j,
31699 realIndex = _ref4.realIndex;
31700 var w = this.w;
31701 var dataLabels = new DataLabels(this.ctx);
31702 if (!this.pointsChart) {
31703 if (w.globals.series[i].length > 1) {
31704 this.elPointsMain.node.classList.add('apexcharts-element-hidden');
31705 }
31706 var elPointsWrap = this.markers.plotChartMarkers({
31707 pointsPos: pointsPos,
31708 seriesIndex: realIndex,
31709 j: j + 1
31710 });
31711 if (elPointsWrap !== null) {
31712 this.elPointsMain.add(elPointsWrap);
31713 }
31714 } else {
31715 // scatter / bubble chart points creation
31716 this.scatter.draw(this.elSeries, j, {
31717 realIndex: realIndex,
31718 pointsPos: pointsPos,
31719 zRatio: this.zRatio,
31720 elParent: this.elPointsMain
31721 });
31722 }
31723 var drawnLabels = dataLabels.drawDataLabel({
31724 type: type,
31725 isRangeStart: isRangeStart,
31726 pos: pointsPos,
31727 i: realIndex,
31728 j: j + 1
31729 });
31730 if (drawnLabels !== null) {
31731 this.elDataLabelsWrap.add(drawnLabels);
31732 }
31733 }
31734 }, {
31735 key: "_createPaths",
31736 value: function _createPaths(_ref5) {
31737 var type = _ref5.type,
31738 series = _ref5.series,
31739 i = _ref5.i;
31740 _ref5.realIndex;
31741 var j = _ref5.j,
31742 x = _ref5.x,
31743 y = _ref5.y,
31744 xArrj = _ref5.xArrj,
31745 yArrj = _ref5.yArrj,
31746 y2 = _ref5.y2,
31747 y2Arrj = _ref5.y2Arrj,
31748 pX = _ref5.pX,
31749 pY = _ref5.pY,
31750 pathState = _ref5.pathState,
31751 segmentStartX = _ref5.segmentStartX,
31752 linePath = _ref5.linePath,
31753 areaPath = _ref5.areaPath,
31754 linePaths = _ref5.linePaths,
31755 areaPaths = _ref5.areaPaths,
31756 curve = _ref5.curve,
31757 isRangeStart = _ref5.isRangeStart;
31758 var graphics = new Graphics(this.ctx);
31759 var areaBottomY = this.areaBottomY;
31760 var rangeArea = type === 'rangeArea';
31761 var isLowerRangeAreaPath = type === 'rangeArea' && isRangeStart;
31762 switch (curve) {
31763 case 'monotoneCubic':
31764 var yAj = isRangeStart ? yArrj : y2Arrj;
31765 var getSmoothInputs = function getSmoothInputs(xArr, yArr) {
31766 return xArr.map(function (_, i) {
31767 return [_, yArr[i]];
31768 }).filter(function (_) {
31769 return _[1] !== null;
31770 });
31771 };
31772 var getSegmentLengths = function getSegmentLengths(yArr) {
31773 // Get the segment lengths so the segments can be extracted from
31774 // the null-filtered smoothInputs array
31775 var segLens = [];
31776 var count = 0;
31777 yArr.forEach(function (_) {
31778 if (_ !== null) {
31779 count++;
31780 } else if (count > 0) {
31781 segLens.push(count);
31782 count = 0;
31783 }
31784 });
31785 if (count > 0) {
31786 segLens.push(count);
31787 }
31788 return segLens;
31789 };
31790 var getSegments = function getSegments(yArr, points) {
31791 var segLens = getSegmentLengths(yArr);
31792 var segments = [];
31793 for (var _i = 0, len = 0; _i < segLens.length; len += segLens[_i++]) {
31794 segments[_i] = spline.slice(points, len, len + segLens[_i]);
31795 }
31796 return segments;
31797 };
31798 switch (pathState) {
31799 case 0:
31800 // Find start of segment
31801 if (yAj[j + 1] === null) {
31802 break;
31803 }
31804 pathState = 1;
31805 // continue through to pathState 1
31806 case 1:
31807 if (!(rangeArea ? xArrj.length === series[i].length : j === series[i].length - 2)) {
31808 break;
31809 }
31810 // continue through to pathState 2
31811 case 2:
31812 // Interpolate the full series with nulls excluded then extract the
31813 // null delimited segments with interpolated points included.
31814 var _xAj = isRangeStart ? xArrj : xArrj.slice().reverse();
31815 var _yAj = isRangeStart ? yAj : yAj.slice().reverse();
31816 var smoothInputs = getSmoothInputs(_xAj, _yAj);
31817 var points = smoothInputs.length > 1 ? spline.points(smoothInputs) : smoothInputs;
31818 var smoothInputsLower = [];
31819 if (rangeArea) {
31820 if (isLowerRangeAreaPath) {
31821 // As we won't be needing it, borrow areaPaths to retain our
31822 // rangeArea lower points.
31823 areaPaths = smoothInputs;
31824 } else {
31825 // Retrieve the corresponding lower raw interpolated points so we
31826 // can join onto its end points. Note: the upper Y2 segments will
31827 // be in the reverse order relative to the lower segments.
31828 smoothInputsLower = areaPaths.reverse();
31829 }
31830 }
31831 var segmentCount = 0;
31832 var smoothInputsIndex = 0;
31833 getSegments(_yAj, points).forEach(function (_) {
31834 segmentCount++;
31835 var svgPoints = svgPath(_);
31836 var _start = smoothInputsIndex;
31837 smoothInputsIndex += _.length;
31838 var _end = smoothInputsIndex - 1;
31839 if (isLowerRangeAreaPath) {
31840 linePath = graphics.move(smoothInputs[_start][0], smoothInputs[_start][1]) + svgPoints;
31841 } else if (rangeArea) {
31842 linePath = graphics.move(smoothInputsLower[_start][0], smoothInputsLower[_start][1]) + graphics.line(smoothInputs[_start][0], smoothInputs[_start][1]) + svgPoints + graphics.line(smoothInputsLower[_end][0], smoothInputsLower[_end][1]);
31843 } else {
31844 linePath = graphics.move(smoothInputs[_start][0], smoothInputs[_start][1]) + svgPoints;
31845 areaPath = linePath + graphics.line(smoothInputs[_end][0], areaBottomY) + graphics.line(smoothInputs[_start][0], areaBottomY) + 'z';
31846 areaPaths.push(areaPath);
31847 }
31848 linePaths.push(linePath);
31849 });
31850 if (rangeArea && segmentCount > 1 && !isLowerRangeAreaPath) {
31851 // Reverse the order of the upper path segments
31852 var upperLinePaths = linePaths.slice(segmentCount).reverse();
31853 linePaths.splice(segmentCount);
31854 upperLinePaths.forEach(function (u) {
31855 return linePaths.push(u);
31856 });
31857 }
31858 pathState = 0;
31859 break;
31860 }
31861 break;
31862 case 'smooth':
31863 var length = (x - pX) * 0.35;
31864 if (series[i][j] === null) {
31865 pathState = 0;
31866 } else {
31867 switch (pathState) {
31868 case 0:
31869 // Beginning of segment
31870 segmentStartX = pX;
31871 if (isLowerRangeAreaPath) {
31872 // Need to add path portion that will join to the upper path
31873 linePath = graphics.move(pX, y2Arrj[j]) + graphics.line(pX, pY);
31874 } else {
31875 linePath = graphics.move(pX, pY);
31876 }
31877 areaPath = graphics.move(pX, pY);
31878
31879 // Check for single isolated point
31880 if (series[i][j + 1] === null || typeof series[i][j + 1] === 'undefined') {
31881 linePaths.push(linePath);
31882 areaPaths.push(areaPath);
31883 // Stay in pathState = 0;
31884 break;
31885 }
31886 pathState = 1;
31887 if (j < series[i].length - 2) {
31888 var p = graphics.curve(pX + length, pY, x - length, y, x, y);
31889 linePath += p;
31890 areaPath += p;
31891 break;
31892 }
31893 // Continue on with pathState 1 to finish the path and exit
31894 case 1:
31895 // Continuing with segment
31896 if (series[i][j + 1] === null) {
31897 // Segment ends here
31898 if (isLowerRangeAreaPath) {
31899 linePath += graphics.line(pX, y2);
31900 } else {
31901 linePath += graphics.move(pX, pY);
31902 }
31903 areaPath += graphics.line(pX, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
31904 linePaths.push(linePath);
31905 areaPaths.push(areaPath);
31906 pathState = -1;
31907 } else {
31908 var _p2 = graphics.curve(pX + length, pY, x - length, y, x, y);
31909 linePath += _p2;
31910 areaPath += _p2;
31911 if (j >= series[i].length - 2) {
31912 if (isLowerRangeAreaPath) {
31913 // Need to add path portion that will join to the upper path
31914 linePath += graphics.curve(x, y, x, y, x, y2) + graphics.move(x, y2);
31915 }
31916 areaPath += graphics.curve(x, y, x, y, x, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
31917 linePaths.push(linePath);
31918 areaPaths.push(areaPath);
31919 pathState = -1;
31920 }
31921 }
31922 break;
31923 }
31924 }
31925 pX = x;
31926 pY = y;
31927 break;
31928 default:
31929 var pathToPoint = function pathToPoint(curve, x, y) {
31930 var path = [];
31931 switch (curve) {
31932 case 'stepline':
31933 path = graphics.line(x, null, 'H') + graphics.line(null, y, 'V');
31934 break;
31935 case 'linestep':
31936 path = graphics.line(null, y, 'V') + graphics.line(x, null, 'H');
31937 break;
31938 case 'straight':
31939 path = graphics.line(x, y);
31940 break;
31941 }
31942 return path;
31943 };
31944 if (series[i][j] === null) {
31945 pathState = 0;
31946 } else {
31947 switch (pathState) {
31948 case 0:
31949 // Beginning of segment
31950 segmentStartX = pX;
31951 if (isLowerRangeAreaPath) {
31952 // Need to add path portion that will join to the upper path
31953 linePath = graphics.move(pX, y2Arrj[j]) + graphics.line(pX, pY);
31954 } else {
31955 linePath = graphics.move(pX, pY);
31956 }
31957 areaPath = graphics.move(pX, pY);
31958
31959 // Check for single isolated point
31960 if (series[i][j + 1] === null || typeof series[i][j + 1] === 'undefined') {
31961 linePaths.push(linePath);
31962 areaPaths.push(areaPath);
31963 // Stay in pathState = 0
31964 break;
31965 }
31966 pathState = 1;
31967 if (j < series[i].length - 2) {
31968 var _p3 = pathToPoint(curve, x, y);
31969 linePath += _p3;
31970 areaPath += _p3;
31971 break;
31972 }
31973 // Continue on with pathState 1 to finish the path and exit
31974 case 1:
31975 // Continuing with segment
31976 if (series[i][j + 1] === null) {
31977 // Segment ends here
31978 if (isLowerRangeAreaPath) {
31979 linePath += graphics.line(pX, y2);
31980 } else {
31981 linePath += graphics.move(pX, pY);
31982 }
31983 areaPath += graphics.line(pX, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
31984 linePaths.push(linePath);
31985 areaPaths.push(areaPath);
31986 pathState = -1;
31987 } else {
31988 var _p4 = pathToPoint(curve, x, y);
31989 linePath += _p4;
31990 areaPath += _p4;
31991 if (j >= series[i].length - 2) {
31992 if (isLowerRangeAreaPath) {
31993 // Need to add path portion that will join to the upper path
31994 linePath += graphics.line(x, y2);
31995 }
31996 areaPath += graphics.line(x, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
31997 linePaths.push(linePath);
31998 areaPaths.push(areaPath);
31999 pathState = -1;
32000 }
32001 }
32002 break;
32003 }
32004 }
32005 pX = x;
32006 pY = y;
32007 break;
32008 }
32009 return {
32010 linePaths: linePaths,
32011 areaPaths: areaPaths,
32012 pX: pX,
32013 pY: pY,
32014 pathState: pathState,
32015 segmentStartX: segmentStartX,
32016 linePath: linePath,
32017 areaPath: areaPath
32018 };
32019 }
32020 }, {
32021 key: "handleNullDataPoints",
32022 value: function handleNullDataPoints(series, pointsPos, i, j, realIndex) {
32023 var w = this.w;
32024 if (series[i][j] === null && w.config.markers.showNullDataPoints || series[i].length === 1) {
32025 var pSize = this.strokeWidth - w.config.markers.strokeWidth / 2;
32026 if (!(pSize > 0)) {
32027 pSize = 0;
32028 }
32029
32030 // fixes apexcharts.js#1282, #1252
32031 var elPointsWrap = this.markers.plotChartMarkers({
32032 pointsPos: pointsPos,
32033 seriesIndex: realIndex,
32034 j: j + 1,
32035 pSize: pSize,
32036 alwaysDrawMarker: true
32037 });
32038 if (elPointsWrap !== null) {
32039 this.elPointsMain.add(elPointsWrap);
32040 }
32041 }
32042 }
32043 }]);
32044 return Line;
32045 }();
32046
32047 /*
32048 * treemap-squarify.js - open source implementation of squarified treemaps
32049 *
32050 * Treemap Squared 0.5 - Treemap Charting library
32051 *
32052 * https://github.com/imranghory/treemap-squared/
32053 *
32054 * Copyright (c) 2012 Imran Ghory ([email protected])
32055 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
32056 *
32057 *
32058 * Implementation of the squarify treemap algorithm described in:
32059 *
32060 * Bruls, Mark; Huizing, Kees; van Wijk, Jarke J. (2000), "Squarified treemaps"
32061 * in de Leeuw, W.; van Liere, R., Data Visualization 2000:
32062 * Proc. Joint Eurographics and IEEE TCVG Symp. on Visualization, Springer-Verlag, pp. 33–42.
32063 *
32064 * Paper is available online at: http://www.win.tue.nl/~vanwijk/stm.pdf
32065 *
32066 * The code in this file is completeley decoupled from the drawing code so it should be trivial
32067 * to port it to any other vector drawing library. Given an array of datapoints this library returns
32068 * an array of cartesian coordinates that represent the rectangles that make up the treemap.
32069 *
32070 * The library also supports multidimensional data (nested treemaps) and performs normalization on the data.
32071 *
32072 * See the README file for more details.
32073 */
32074
32075 window.TreemapSquared = {};
32076 (function () {
32077
32078 window.TreemapSquared.generate = function () {
32079 function Container(xoffset, yoffset, width, height) {
32080 this.xoffset = xoffset; // offset from the the top left hand corner
32081 this.yoffset = yoffset; // ditto
32082 this.height = height;
32083 this.width = width;
32084 this.shortestEdge = function () {
32085 return Math.min(this.height, this.width);
32086 };
32087
32088 // getCoordinates - for a row of boxes which we've placed
32089 // return an array of their cartesian coordinates
32090 this.getCoordinates = function (row) {
32091 var coordinates = [];
32092 var subxoffset = this.xoffset,
32093 subyoffset = this.yoffset; //our offset within the container
32094 var areawidth = sumArray(row) / this.height;
32095 var areaheight = sumArray(row) / this.width;
32096 var i;
32097 if (this.width >= this.height) {
32098 for (i = 0; i < row.length; i++) {
32099 coordinates.push([subxoffset, subyoffset, subxoffset + areawidth, subyoffset + row[i] / areawidth]);
32100 subyoffset = subyoffset + row[i] / areawidth;
32101 }
32102 } else {
32103 for (i = 0; i < row.length; i++) {
32104 coordinates.push([subxoffset, subyoffset, subxoffset + row[i] / areaheight, subyoffset + areaheight]);
32105 subxoffset = subxoffset + row[i] / areaheight;
32106 }
32107 }
32108 return coordinates;
32109 };
32110
32111 // cutArea - once we've placed some boxes into an row we then need to identify the remaining area,
32112 // this function takes the area of the boxes we've placed and calculates the location and
32113 // dimensions of the remaining space and returns a container box defined by the remaining area
32114 this.cutArea = function (area) {
32115 var newcontainer;
32116 if (this.width >= this.height) {
32117 var areawidth = area / this.height;
32118 var newwidth = this.width - areawidth;
32119 newcontainer = new Container(this.xoffset + areawidth, this.yoffset, newwidth, this.height);
32120 } else {
32121 var areaheight = area / this.width;
32122 var newheight = this.height - areaheight;
32123 newcontainer = new Container(this.xoffset, this.yoffset + areaheight, this.width, newheight);
32124 }
32125 return newcontainer;
32126 };
32127 }
32128
32129 // normalize - the Bruls algorithm assumes we're passing in areas that nicely fit into our
32130 // container box, this method takes our raw data and normalizes the data values into
32131 // area values so that this assumption is valid.
32132 function normalize(data, area) {
32133 var normalizeddata = [];
32134 var sum = sumArray(data);
32135 var multiplier = area / sum;
32136 var i;
32137 for (i = 0; i < data.length; i++) {
32138 normalizeddata[i] = data[i] * multiplier;
32139 }
32140 return normalizeddata;
32141 }
32142
32143 // treemapMultidimensional - takes multidimensional data (aka [[23,11],[11,32]] - nested array)
32144 // and recursively calls itself using treemapSingledimensional
32145 // to create a patchwork of treemaps and merge them
32146 function treemapMultidimensional(data, width, height, xoffset, yoffset) {
32147 xoffset = typeof xoffset === 'undefined' ? 0 : xoffset;
32148 yoffset = typeof yoffset === 'undefined' ? 0 : yoffset;
32149 var mergeddata = [];
32150 var mergedtreemap;
32151 var results = [];
32152 var i;
32153 if (isArray(data[0])) {
32154 // if we've got more dimensions of depth
32155 for (i = 0; i < data.length; i++) {
32156 mergeddata[i] = sumMultidimensionalArray(data[i]);
32157 }
32158 mergedtreemap = treemapSingledimensional(mergeddata, width, height, xoffset, yoffset);
32159 for (i = 0; i < data.length; i++) {
32160 results.push(treemapMultidimensional(data[i], mergedtreemap[i][2] - mergedtreemap[i][0], mergedtreemap[i][3] - mergedtreemap[i][1], mergedtreemap[i][0], mergedtreemap[i][1]));
32161 }
32162 } else {
32163 results = treemapSingledimensional(data, width, height, xoffset, yoffset);
32164 }
32165 return results;
32166 }
32167
32168 // treemapSingledimensional - simple wrapper around squarify
32169 function treemapSingledimensional(data, width, height, xoffset, yoffset) {
32170 xoffset = typeof xoffset === 'undefined' ? 0 : xoffset;
32171 yoffset = typeof yoffset === 'undefined' ? 0 : yoffset;
32172 var rawtreemap = squarify(normalize(data, width * height), [], new Container(xoffset, yoffset, width, height), []);
32173 return flattenTreemap(rawtreemap);
32174 }
32175
32176 // flattenTreemap - squarify implementation returns an array of arrays of coordinates
32177 // because we have a new array everytime we switch to building a new row
32178 // this converts it into an array of coordinates.
32179 function flattenTreemap(rawtreemap) {
32180 var flattreemap = [];
32181 var i, j;
32182 for (i = 0; i < rawtreemap.length; i++) {
32183 for (j = 0; j < rawtreemap[i].length; j++) {
32184 flattreemap.push(rawtreemap[i][j]);
32185 }
32186 }
32187 return flattreemap;
32188 }
32189
32190 // squarify - as per the Bruls paper
32191 // plus coordinates stack and containers so we get
32192 // usable data out of it
32193 function squarify(data, currentrow, container, stack) {
32194 var length;
32195 var nextdatapoint;
32196 var newcontainer;
32197 if (data.length === 0) {
32198 stack.push(container.getCoordinates(currentrow));
32199 return;
32200 }
32201 length = container.shortestEdge();
32202 nextdatapoint = data[0];
32203 if (improvesRatio(currentrow, nextdatapoint, length)) {
32204 currentrow.push(nextdatapoint);
32205 squarify(data.slice(1), currentrow, container, stack);
32206 } else {
32207 newcontainer = container.cutArea(sumArray(currentrow), stack);
32208 stack.push(container.getCoordinates(currentrow));
32209 squarify(data, [], newcontainer, stack);
32210 }
32211 return stack;
32212 }
32213
32214 // improveRatio - implements the worse calculation and comparision as given in Bruls
32215 // (note the error in the original paper; fixed here)
32216 function improvesRatio(currentrow, nextnode, length) {
32217 var newrow;
32218 if (currentrow.length === 0) {
32219 return true;
32220 }
32221 newrow = currentrow.slice();
32222 newrow.push(nextnode);
32223 var currentratio = calculateRatio(currentrow, length);
32224 var newratio = calculateRatio(newrow, length);
32225
32226 // the pseudocode in the Bruls paper has the direction of the comparison
32227 // wrong, this is the correct one.
32228 return currentratio >= newratio;
32229 }
32230
32231 // calculateRatio - calculates the maximum width to height ratio of the
32232 // boxes in this row
32233 function calculateRatio(row, length) {
32234 var min = Math.min.apply(Math, row);
32235 var max = Math.max.apply(Math, row);
32236 var sum = sumArray(row);
32237 return Math.max(Math.pow(length, 2) * max / Math.pow(sum, 2), Math.pow(sum, 2) / (Math.pow(length, 2) * min));
32238 }
32239
32240 // isArray - checks if arr is an array
32241 function isArray(arr) {
32242 return arr && arr.constructor === Array;
32243 }
32244
32245 // sumArray - sums a single dimensional array
32246 function sumArray(arr) {
32247 var sum = 0;
32248 var i;
32249 for (i = 0; i < arr.length; i++) {
32250 sum += arr[i];
32251 }
32252 return sum;
32253 }
32254
32255 // sumMultidimensionalArray - sums the values in a nested array (aka [[0,1],[[2,3]]])
32256 function sumMultidimensionalArray(arr) {
32257 var i,
32258 total = 0;
32259 if (isArray(arr[0])) {
32260 for (i = 0; i < arr.length; i++) {
32261 total += sumMultidimensionalArray(arr[i]);
32262 }
32263 } else {
32264 total = sumArray(arr);
32265 }
32266 return total;
32267 }
32268 return treemapMultidimensional;
32269 }();
32270 })();
32271
32272 /**
32273 * ApexCharts TreemapChart Class.
32274 * @module TreemapChart
32275 **/
32276 var TreemapChart = /*#__PURE__*/function () {
32277 function TreemapChart(ctx, xyRatios) {
32278 _classCallCheck(this, TreemapChart);
32279 this.ctx = ctx;
32280 this.w = ctx.w;
32281 this.strokeWidth = this.w.config.stroke.width;
32282 this.helpers = new TreemapHelpers(ctx);
32283 this.dynamicAnim = this.w.config.chart.animations.dynamicAnimation;
32284 this.labels = [];
32285 }
32286 _createClass(TreemapChart, [{
32287 key: "draw",
32288 value: function draw(series) {
32289 var _this = this;
32290 var w = this.w;
32291 var graphics = new Graphics(this.ctx);
32292 var fill = new Fill(this.ctx);
32293 var ret = graphics.group({
32294 class: 'apexcharts-treemap'
32295 });
32296 if (w.globals.noData) return ret;
32297 var ser = [];
32298 series.forEach(function (s) {
32299 var d = s.map(function (v) {
32300 return Math.abs(v);
32301 });
32302 ser.push(d);
32303 });
32304 this.negRange = this.helpers.checkColorRange();
32305 w.config.series.forEach(function (s, i) {
32306 s.data.forEach(function (l) {
32307 if (!Array.isArray(_this.labels[i])) _this.labels[i] = [];
32308 _this.labels[i].push(l.x);
32309 });
32310 });
32311 var nodes = window.TreemapSquared.generate(ser, w.globals.gridWidth, w.globals.gridHeight);
32312 nodes.forEach(function (node, i) {
32313 var elSeries = graphics.group({
32314 class: "apexcharts-series apexcharts-treemap-series",
32315 seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
32316 rel: i + 1,
32317 'data:realIndex': i
32318 });
32319 if (w.config.chart.dropShadow.enabled) {
32320 var shadow = w.config.chart.dropShadow;
32321 var filters = new Filters(_this.ctx);
32322 filters.dropShadow(ret, shadow, i);
32323 }
32324 var elDataLabelWrap = graphics.group({
32325 class: 'apexcharts-data-labels'
32326 });
32327 var bounds = {
32328 xMin: Infinity,
32329 yMin: Infinity,
32330 xMax: -Infinity,
32331 yMax: -Infinity
32332 };
32333 node.forEach(function (r, j) {
32334 var x1 = r[0];
32335 var y1 = r[1];
32336 var x2 = r[2];
32337 var y2 = r[3];
32338 bounds.xMin = Math.min(bounds.xMin, x1);
32339 bounds.yMin = Math.min(bounds.yMin, y1);
32340 bounds.xMax = Math.max(bounds.xMax, x2);
32341 bounds.yMax = Math.max(bounds.yMax, y2);
32342 var colorProps = _this.helpers.getShadeColor(w.config.chart.type, i, j, _this.negRange);
32343 var color = colorProps.color;
32344 var pathFill = fill.fillPath({
32345 color: color,
32346 seriesNumber: i,
32347 dataPointIndex: j
32348 });
32349 var elRect = graphics.drawRect(x1, y1, x2 - x1, y2 - y1, w.config.plotOptions.treemap.borderRadius, '#fff', 1, _this.strokeWidth, w.config.plotOptions.treemap.useFillColorAsStroke ? color : w.globals.stroke.colors[i]);
32350 elRect.attr({
32351 cx: x1,
32352 cy: y1,
32353 index: i,
32354 i: i,
32355 j: j,
32356 width: x2 - x1,
32357 height: y2 - y1,
32358 fill: pathFill
32359 });
32360 elRect.node.classList.add('apexcharts-treemap-rect');
32361 _this.helpers.addListeners(elRect);
32362 var fromRect = {
32363 x: x1 + (x2 - x1) / 2,
32364 y: y1 + (y2 - y1) / 2,
32365 width: 0,
32366 height: 0
32367 };
32368 var toRect = {
32369 x: x1,
32370 y: y1,
32371 width: x2 - x1,
32372 height: y2 - y1
32373 };
32374 if (w.config.chart.animations.enabled && !w.globals.dataChanged) {
32375 var speed = 1;
32376 if (!w.globals.resized) {
32377 speed = w.config.chart.animations.speed;
32378 }
32379 _this.animateTreemap(elRect, fromRect, toRect, speed);
32380 }
32381 if (w.globals.dataChanged) {
32382 var _speed = 1;
32383 if (_this.dynamicAnim.enabled && w.globals.shouldAnimate) {
32384 _speed = _this.dynamicAnim.speed;
32385 if (w.globals.previousPaths[i] && w.globals.previousPaths[i][j] && w.globals.previousPaths[i][j].rect) {
32386 fromRect = w.globals.previousPaths[i][j].rect;
32387 }
32388 _this.animateTreemap(elRect, fromRect, toRect, _speed);
32389 }
32390 }
32391 var fontSize = _this.getFontSize(r);
32392 var formattedText = w.config.dataLabels.formatter(_this.labels[i][j], {
32393 value: w.globals.series[i][j],
32394 seriesIndex: i,
32395 dataPointIndex: j,
32396 w: w
32397 });
32398 if (w.config.plotOptions.treemap.dataLabels.format === 'truncate') {
32399 fontSize = parseInt(w.config.dataLabels.style.fontSize, 10);
32400 formattedText = _this.truncateLabels(formattedText, fontSize, x1, y1, x2, y2);
32401 }
32402 var dataLabels = null;
32403 if (w.globals.series[i][j]) {
32404 dataLabels = _this.helpers.calculateDataLabels({
32405 text: formattedText,
32406 x: (x1 + x2) / 2,
32407 y: (y1 + y2) / 2 + _this.strokeWidth / 2 + fontSize / 3,
32408 i: i,
32409 j: j,
32410 colorProps: colorProps,
32411 fontSize: fontSize,
32412 series: series
32413 });
32414 }
32415 if (w.config.dataLabels.enabled && dataLabels) {
32416 _this.rotateToFitLabel(dataLabels, fontSize, formattedText, x1, y1, x2, y2);
32417 }
32418 elSeries.add(elRect);
32419 if (dataLabels !== null) {
32420 elSeries.add(dataLabels);
32421 }
32422 });
32423 var seriesTitle = w.config.plotOptions.treemap.seriesTitle;
32424 if (w.config.series.length > 1 && seriesTitle && seriesTitle.show) {
32425 var sName = w.config.series[i].name || '';
32426 if (sName && bounds.xMin < Infinity && bounds.yMin < Infinity) {
32427 var offsetX = seriesTitle.offsetX,
32428 offsetY = seriesTitle.offsetY,
32429 borderColor = seriesTitle.borderColor,
32430 borderWidth = seriesTitle.borderWidth,
32431 borderRadius = seriesTitle.borderRadius,
32432 style = seriesTitle.style;
32433 var textColor = style.color || w.config.chart.foreColor;
32434 var padding = {
32435 left: style.padding.left,
32436 right: style.padding.right,
32437 top: style.padding.top,
32438 bottom: style.padding.bottom
32439 };
32440 var textSize = graphics.getTextRects(sName, style.fontSize, style.fontFamily);
32441 var labelRectWidth = textSize.width + padding.left + padding.right;
32442 var labelRectHeight = textSize.height + padding.top + padding.bottom;
32443
32444 // Position
32445 var labelX = bounds.xMin + (offsetX || 0);
32446 var labelY = bounds.yMin + (offsetY || 0);
32447
32448 // Draw background rect
32449 var elLabelRect = graphics.drawRect(labelX, labelY, labelRectWidth, labelRectHeight, borderRadius, style.background, 1, borderWidth, borderColor);
32450 var elLabelText = graphics.drawText({
32451 x: labelX + padding.left,
32452 y: labelY + padding.top + textSize.height * 0.75,
32453 text: sName,
32454 fontSize: style.fontSize,
32455 fontFamily: style.fontFamily,
32456 fontWeight: style.fontWeight,
32457 foreColor: textColor,
32458 cssClass: style.cssClass || ''
32459 });
32460 elSeries.add(elLabelRect);
32461 elSeries.add(elLabelText);
32462 }
32463 }
32464 elSeries.add(elDataLabelWrap);
32465 ret.add(elSeries);
32466 });
32467 return ret;
32468 }
32469
32470 // This calculates a font-size based upon
32471 // average label length and the size of the box
32472 }, {
32473 key: "getFontSize",
32474 value: function getFontSize(coordinates) {
32475 var w = this.w;
32476
32477 // total length of labels (i.e [["Italy"],["Spain", "Greece"]] -> 16)
32478 function totalLabelLength(arr) {
32479 var i,
32480 total = 0;
32481 if (Array.isArray(arr[0])) {
32482 for (i = 0; i < arr.length; i++) {
32483 total += totalLabelLength(arr[i]);
32484 }
32485 } else {
32486 for (i = 0; i < arr.length; i++) {
32487 total += arr[i].length;
32488 }
32489 }
32490 return total;
32491 }
32492
32493 // count of labels (i.e [["Italy"],["Spain", "Greece"]] -> 3)
32494 function countLabels(arr) {
32495 var i,
32496 total = 0;
32497 if (Array.isArray(arr[0])) {
32498 for (i = 0; i < arr.length; i++) {
32499 total += countLabels(arr[i]);
32500 }
32501 } else {
32502 for (i = 0; i < arr.length; i++) {
32503 total += 1;
32504 }
32505 }
32506 return total;
32507 }
32508 var averagelabelsize = totalLabelLength(this.labels) / countLabels(this.labels);
32509 function fontSize(width, height) {
32510 var area = width * height;
32511 var arearoot = Math.pow(area, 0.5);
32512 return Math.min(arearoot / averagelabelsize, parseInt(w.config.dataLabels.style.fontSize, 10));
32513 }
32514 return fontSize(coordinates[2] - coordinates[0], coordinates[3] - coordinates[1]);
32515 }
32516 }, {
32517 key: "rotateToFitLabel",
32518 value: function rotateToFitLabel(elText, fontSize, text, x1, y1, x2, y2) {
32519 var graphics = new Graphics(this.ctx);
32520 var textRect = graphics.getTextRects(text, fontSize);
32521
32522 // if the label fits better sideways then rotate it
32523 if (textRect.width + this.w.config.stroke.width + 5 > x2 - x1 && textRect.width <= y2 - y1) {
32524 var labelRotatingCenter = graphics.rotateAroundCenter(elText.node);
32525 elText.node.setAttribute('transform', "rotate(-90 ".concat(labelRotatingCenter.x, " ").concat(labelRotatingCenter.y, ") translate(").concat(textRect.height / 3, ")"));
32526 }
32527 }
32528
32529 // This is an alternative label formatting method that uses a
32530 // consistent font size, and trims the edge of long labels
32531 }, {
32532 key: "truncateLabels",
32533 value: function truncateLabels(text, fontSize, x1, y1, x2, y2) {
32534 var graphics = new Graphics(this.ctx);
32535 var textRect = graphics.getTextRects(text, fontSize);
32536
32537 // Determine max width based on ideal orientation of text
32538 var labelMaxWidth = textRect.width + this.w.config.stroke.width + 5 > x2 - x1 && y2 - y1 > x2 - x1 ? y2 - y1 : x2 - x1;
32539 var truncatedText = graphics.getTextBasedOnMaxWidth({
32540 text: text,
32541 maxWidth: labelMaxWidth,
32542 fontSize: fontSize
32543 });
32544
32545 // Return empty label when text has been trimmed for very small rects
32546 if (text.length !== truncatedText.length && labelMaxWidth / fontSize < 5) {
32547 return '';
32548 } else {
32549 return truncatedText;
32550 }
32551 }
32552 }, {
32553 key: "animateTreemap",
32554 value: function animateTreemap(el, fromRect, toRect, speed) {
32555 var animations = new Animations(this.ctx);
32556 animations.animateRect(el, fromRect, toRect, speed, function () {
32557 animations.animationCompleted(el);
32558 });
32559 }
32560 }]);
32561 return TreemapChart;
32562 }();
32563
32564 var MINUTES_IN_DAY = 24 * 60;
32565 var SECONDS_IN_DAY = MINUTES_IN_DAY * 60;
32566 var MIN_ZOOM_DAYS = 10 / SECONDS_IN_DAY;
32567
32568 /**
32569 * ApexCharts TimeScale Class for generating time ticks for x-axis.
32570 *
32571 * @module TimeScale
32572 **/
32573 var TimeScale = /*#__PURE__*/function () {
32574 function TimeScale(ctx) {
32575 _classCallCheck(this, TimeScale);
32576 this.ctx = ctx;
32577 this.w = ctx.w;
32578 this.timeScaleArray = [];
32579 this.utc = this.w.config.xaxis.labels.datetimeUTC;
32580 }
32581 _createClass(TimeScale, [{
32582 key: "calculateTimeScaleTicks",
32583 value: function calculateTimeScaleTicks(minX, maxX) {
32584 var _this = this;
32585 var w = this.w;
32586
32587 // null check when no series to show
32588 if (w.globals.allSeriesCollapsed) {
32589 w.globals.labels = [];
32590 w.globals.timescaleLabels = [];
32591 return [];
32592 }
32593 var dt = new DateTime(this.ctx);
32594 var daysDiff = (maxX - minX) / (1000 * SECONDS_IN_DAY);
32595 this.determineInterval(daysDiff);
32596 w.globals.disableZoomIn = false;
32597 w.globals.disableZoomOut = false;
32598 if (daysDiff < MIN_ZOOM_DAYS) {
32599 w.globals.disableZoomIn = true;
32600 } else if (daysDiff > 50000) {
32601 w.globals.disableZoomOut = true;
32602 }
32603 var timeIntervals = dt.getTimeUnitsfromTimestamp(minX, maxX, this.utc);
32604 var daysWidthOnXAxis = w.globals.gridWidth / daysDiff;
32605 var hoursWidthOnXAxis = daysWidthOnXAxis / 24;
32606 var minutesWidthOnXAxis = hoursWidthOnXAxis / 60;
32607 var secondsWidthOnXAxis = minutesWidthOnXAxis / 60;
32608 var numberOfHours = Math.floor(daysDiff * 24);
32609 var numberOfMinutes = Math.floor(daysDiff * MINUTES_IN_DAY);
32610 var numberOfSeconds = Math.floor(daysDiff * SECONDS_IN_DAY);
32611 var numberOfDays = Math.floor(daysDiff);
32612 var numberOfMonths = Math.floor(daysDiff / 30);
32613 var numberOfYears = Math.floor(daysDiff / 365);
32614 var firstVal = {
32615 minMillisecond: timeIntervals.minMillisecond,
32616 minSecond: timeIntervals.minSecond,
32617 minMinute: timeIntervals.minMinute,
32618 minHour: timeIntervals.minHour,
32619 minDate: timeIntervals.minDate,
32620 minMonth: timeIntervals.minMonth,
32621 minYear: timeIntervals.minYear
32622 };
32623 var currentMillisecond = firstVal.minMillisecond;
32624 var currentSecond = firstVal.minSecond;
32625 var currentMinute = firstVal.minMinute;
32626 var currentHour = firstVal.minHour;
32627 var currentMonthDate = firstVal.minDate;
32628 var currentDate = firstVal.minDate;
32629 var currentMonth = firstVal.minMonth;
32630 var currentYear = firstVal.minYear;
32631 var params = {
32632 firstVal: firstVal,
32633 currentMillisecond: currentMillisecond,
32634 currentSecond: currentSecond,
32635 currentMinute: currentMinute,
32636 currentHour: currentHour,
32637 currentMonthDate: currentMonthDate,
32638 currentDate: currentDate,
32639 currentMonth: currentMonth,
32640 currentYear: currentYear,
32641 daysWidthOnXAxis: daysWidthOnXAxis,
32642 hoursWidthOnXAxis: hoursWidthOnXAxis,
32643 minutesWidthOnXAxis: minutesWidthOnXAxis,
32644 secondsWidthOnXAxis: secondsWidthOnXAxis,
32645 numberOfSeconds: numberOfSeconds,
32646 numberOfMinutes: numberOfMinutes,
32647 numberOfHours: numberOfHours,
32648 numberOfDays: numberOfDays,
32649 numberOfMonths: numberOfMonths,
32650 numberOfYears: numberOfYears
32651 };
32652 switch (this.tickInterval) {
32653 case 'years':
32654 {
32655 this.generateYearScale(params);
32656 break;
32657 }
32658 case 'months':
32659 case 'half_year':
32660 {
32661 this.generateMonthScale(params);
32662 break;
32663 }
32664 case 'months_days':
32665 case 'months_fortnight':
32666 case 'days':
32667 case 'week_days':
32668 {
32669 this.generateDayScale(params);
32670 break;
32671 }
32672 case 'hours':
32673 {
32674 this.generateHourScale(params);
32675 break;
32676 }
32677 case 'minutes_fives':
32678 case 'minutes':
32679 this.generateMinuteScale(params);
32680 break;
32681 case 'seconds_tens':
32682 case 'seconds_fives':
32683 case 'seconds':
32684 this.generateSecondScale(params);
32685 break;
32686 }
32687
32688 // first, we will adjust the month values index
32689 // as in the upper function, it is starting from 0
32690 // we will start them from 1
32691 var adjustedMonthInTimeScaleArray = this.timeScaleArray.map(function (ts) {
32692 var defaultReturn = {
32693 position: ts.position,
32694 unit: ts.unit,
32695 year: ts.year,
32696 day: ts.day ? ts.day : 1,
32697 hour: ts.hour ? ts.hour : 0,
32698 month: ts.month + 1
32699 };
32700 if (ts.unit === 'month') {
32701 return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
32702 day: 1,
32703 value: ts.value + 1
32704 });
32705 } else if (ts.unit === 'day' || ts.unit === 'hour') {
32706 return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
32707 value: ts.value
32708 });
32709 } else if (ts.unit === 'minute') {
32710 return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
32711 value: ts.value,
32712 minute: ts.value
32713 });
32714 } else if (ts.unit === 'second') {
32715 return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
32716 value: ts.value,
32717 minute: ts.minute,
32718 second: ts.second
32719 });
32720 }
32721 return ts;
32722 });
32723 var filteredTimeScale = adjustedMonthInTimeScaleArray.filter(function (ts) {
32724 var modulo = 1;
32725 var ticks = Math.ceil(w.globals.gridWidth / 120);
32726 var value = ts.value;
32727 if (w.config.xaxis.tickAmount !== undefined) {
32728 ticks = w.config.xaxis.tickAmount;
32729 }
32730 if (adjustedMonthInTimeScaleArray.length > ticks) {
32731 modulo = Math.floor(adjustedMonthInTimeScaleArray.length / ticks);
32732 }
32733 var shouldNotSkipUnit = false; // there is a big change in unit i.e days to months
32734 var shouldNotPrint = false; // should skip these values
32735
32736 switch (_this.tickInterval) {
32737 case 'years':
32738 // make years label denser
32739 if (ts.unit === 'year') {
32740 shouldNotSkipUnit = true;
32741 }
32742 break;
32743 case 'half_year':
32744 modulo = 7;
32745 if (ts.unit === 'year') {
32746 shouldNotSkipUnit = true;
32747 }
32748 break;
32749 case 'months':
32750 modulo = 1;
32751 if (ts.unit === 'year') {
32752 shouldNotSkipUnit = true;
32753 }
32754 break;
32755 case 'months_fortnight':
32756 modulo = 15;
32757 if (ts.unit === 'year' || ts.unit === 'month') {
32758 shouldNotSkipUnit = true;
32759 }
32760 if (value === 30) {
32761 shouldNotPrint = true;
32762 }
32763 break;
32764 case 'months_days':
32765 modulo = 10;
32766 if (ts.unit === 'month') {
32767 shouldNotSkipUnit = true;
32768 }
32769 if (value === 30) {
32770 shouldNotPrint = true;
32771 }
32772 break;
32773 case 'week_days':
32774 modulo = 8;
32775 if (ts.unit === 'month') {
32776 shouldNotSkipUnit = true;
32777 }
32778 break;
32779 case 'days':
32780 modulo = 1;
32781 if (ts.unit === 'month') {
32782 shouldNotSkipUnit = true;
32783 }
32784 break;
32785 case 'hours':
32786 if (ts.unit === 'day') {
32787 shouldNotSkipUnit = true;
32788 }
32789 break;
32790 case 'minutes_fives':
32791 if (value % 5 !== 0) {
32792 shouldNotPrint = true;
32793 }
32794 break;
32795 case 'seconds_tens':
32796 if (value % 10 !== 0) {
32797 shouldNotPrint = true;
32798 }
32799 break;
32800 case 'seconds_fives':
32801 if (value % 5 !== 0) {
32802 shouldNotPrint = true;
32803 }
32804 break;
32805 }
32806 if (_this.tickInterval === 'hours' || _this.tickInterval === 'minutes_fives' || _this.tickInterval === 'seconds_tens' || _this.tickInterval === 'seconds_fives') {
32807 if (!shouldNotPrint) {
32808 return true;
32809 }
32810 } else {
32811 if ((value % modulo === 0 || shouldNotSkipUnit) && !shouldNotPrint) {
32812 return true;
32813 }
32814 }
32815 });
32816 return filteredTimeScale;
32817 }
32818 }, {
32819 key: "recalcDimensionsBasedOnFormat",
32820 value: function recalcDimensionsBasedOnFormat(filteredTimeScale, inverted) {
32821 var w = this.w;
32822 var reformattedTimescaleArray = this.formatDates(filteredTimeScale);
32823 var removedOverlappingTS = this.removeOverlappingTS(reformattedTimescaleArray);
32824 w.globals.timescaleLabels = removedOverlappingTS.slice();
32825
32826 // at this stage, we need to re-calculate coords of the grid as timeline labels may have altered the xaxis labels coords
32827 // The reason we can't do this prior to this stage is because timeline labels depends on gridWidth, and as the ticks are calculated based on available gridWidth, there can be unknown number of ticks generated for different minX and maxX
32828 // Dependency on Dimensions(), need to refactor correctly
32829 // TODO - find an alternate way to avoid calling this Heavy method twice
32830 var dimensions = new Dimensions(this.ctx);
32831 dimensions.plotCoords();
32832 }
32833 }, {
32834 key: "determineInterval",
32835 value: function determineInterval(daysDiff) {
32836 var yearsDiff = daysDiff / 365;
32837 var hoursDiff = daysDiff * 24;
32838 var minutesDiff = hoursDiff * 60;
32839 var secondsDiff = minutesDiff * 60;
32840 switch (true) {
32841 case yearsDiff > 5:
32842 this.tickInterval = 'years';
32843 break;
32844 case daysDiff > 800:
32845 this.tickInterval = 'half_year';
32846 break;
32847 case daysDiff > 180:
32848 this.tickInterval = 'months';
32849 break;
32850 case daysDiff > 90:
32851 this.tickInterval = 'months_fortnight';
32852 break;
32853 case daysDiff > 60:
32854 this.tickInterval = 'months_days';
32855 break;
32856 case daysDiff > 30:
32857 this.tickInterval = 'week_days';
32858 break;
32859 case daysDiff > 2:
32860 this.tickInterval = 'days';
32861 break;
32862 case hoursDiff > 2.4:
32863 this.tickInterval = 'hours';
32864 break;
32865 case minutesDiff > 15:
32866 this.tickInterval = 'minutes_fives';
32867 break;
32868 case minutesDiff > 5:
32869 this.tickInterval = 'minutes';
32870 break;
32871 case minutesDiff > 1:
32872 this.tickInterval = 'seconds_tens';
32873 break;
32874 case secondsDiff > 20:
32875 this.tickInterval = 'seconds_fives';
32876 break;
32877 default:
32878 this.tickInterval = 'seconds';
32879 break;
32880 }
32881 }
32882 }, {
32883 key: "generateYearScale",
32884 value: function generateYearScale(_ref) {
32885 var firstVal = _ref.firstVal,
32886 currentMonth = _ref.currentMonth,
32887 currentYear = _ref.currentYear,
32888 daysWidthOnXAxis = _ref.daysWidthOnXAxis,
32889 numberOfYears = _ref.numberOfYears;
32890 var firstTickValue = firstVal.minYear;
32891 var firstTickPosition = 0;
32892 var dt = new DateTime(this.ctx);
32893 var unit = 'year';
32894 if (firstVal.minDate > 1 || firstVal.minMonth > 0) {
32895 var remainingDays = dt.determineRemainingDaysOfYear(firstVal.minYear, firstVal.minMonth, firstVal.minDate);
32896
32897 // remainingDaysofFirstMonth is used to reacht the 2nd tick position
32898 var remainingDaysOfFirstYear = dt.determineDaysOfYear(firstVal.minYear) - remainingDays + 1;
32899
32900 // calculate the first tick position
32901 firstTickPosition = remainingDaysOfFirstYear * daysWidthOnXAxis;
32902 firstTickValue = firstVal.minYear + 1;
32903 // push the first tick in the array
32904 this.timeScaleArray.push({
32905 position: firstTickPosition,
32906 value: firstTickValue,
32907 unit: unit,
32908 year: firstTickValue,
32909 month: Utils$1.monthMod(currentMonth + 1)
32910 });
32911 } else if (firstVal.minDate === 1 && firstVal.minMonth === 0) {
32912 // push the first tick in the array
32913 this.timeScaleArray.push({
32914 position: firstTickPosition,
32915 value: firstTickValue,
32916 unit: unit,
32917 year: currentYear,
32918 month: Utils$1.monthMod(currentMonth + 1)
32919 });
32920 }
32921 var year = firstTickValue;
32922 var pos = firstTickPosition;
32923
32924 // keep drawing rest of the ticks
32925 for (var i = 0; i < numberOfYears; i++) {
32926 year++;
32927 pos = dt.determineDaysOfYear(year - 1) * daysWidthOnXAxis + pos;
32928 this.timeScaleArray.push({
32929 position: pos,
32930 value: year,
32931 unit: unit,
32932 year: year,
32933 month: 1
32934 });
32935 }
32936 }
32937 }, {
32938 key: "generateMonthScale",
32939 value: function generateMonthScale(_ref2) {
32940 var firstVal = _ref2.firstVal,
32941 currentMonthDate = _ref2.currentMonthDate,
32942 currentMonth = _ref2.currentMonth,
32943 currentYear = _ref2.currentYear,
32944 daysWidthOnXAxis = _ref2.daysWidthOnXAxis,
32945 numberOfMonths = _ref2.numberOfMonths;
32946 var firstTickValue = currentMonth;
32947 var firstTickPosition = 0;
32948 var dt = new DateTime(this.ctx);
32949 var unit = 'month';
32950 var yrCounter = 0;
32951 if (firstVal.minDate > 1) {
32952 // remainingDaysofFirstMonth is used to reacht the 2nd tick position
32953 var remainingDaysOfFirstMonth = dt.determineDaysOfMonths(currentMonth + 1, firstVal.minYear) - currentMonthDate + 1;
32954
32955 // calculate the first tick position
32956 firstTickPosition = remainingDaysOfFirstMonth * daysWidthOnXAxis;
32957 firstTickValue = Utils$1.monthMod(currentMonth + 1);
32958 var year = currentYear + yrCounter;
32959 var _month = Utils$1.monthMod(firstTickValue);
32960 var value = firstTickValue;
32961 // it's Jan, so update the year
32962 if (firstTickValue === 0) {
32963 unit = 'year';
32964 value = year;
32965 _month = 1;
32966 yrCounter += 1;
32967 year = year + yrCounter;
32968 }
32969
32970 // push the first tick in the array
32971 this.timeScaleArray.push({
32972 position: firstTickPosition,
32973 value: value,
32974 unit: unit,
32975 year: year,
32976 month: _month
32977 });
32978 } else {
32979 // push the first tick in the array
32980 this.timeScaleArray.push({
32981 position: firstTickPosition,
32982 value: firstTickValue,
32983 unit: unit,
32984 year: currentYear,
32985 month: Utils$1.monthMod(currentMonth)
32986 });
32987 }
32988 var month = firstTickValue + 1;
32989 var pos = firstTickPosition;
32990
32991 // keep drawing rest of the ticks
32992 for (var i = 0, j = 1; i < numberOfMonths; i++, j++) {
32993 month = Utils$1.monthMod(month);
32994 if (month === 0) {
32995 unit = 'year';
32996 yrCounter += 1;
32997 } else {
32998 unit = 'month';
32999 }
33000 var _year = this._getYear(currentYear, month, yrCounter);
33001 pos = dt.determineDaysOfMonths(month, _year) * daysWidthOnXAxis + pos;
33002 var monthVal = month === 0 ? _year : month;
33003 this.timeScaleArray.push({
33004 position: pos,
33005 value: monthVal,
33006 unit: unit,
33007 year: _year,
33008 month: month === 0 ? 1 : month
33009 });
33010 month++;
33011 }
33012 }
33013 }, {
33014 key: "generateDayScale",
33015 value: function generateDayScale(_ref3) {
33016 var firstVal = _ref3.firstVal,
33017 currentMonth = _ref3.currentMonth,
33018 currentYear = _ref3.currentYear,
33019 hoursWidthOnXAxis = _ref3.hoursWidthOnXAxis,
33020 numberOfDays = _ref3.numberOfDays;
33021 var dt = new DateTime(this.ctx);
33022 var unit = 'day';
33023 var firstTickValue = firstVal.minDate + 1;
33024 var date = firstTickValue;
33025 var changeMonth = function changeMonth(dateVal, month, year) {
33026 var monthdays = dt.determineDaysOfMonths(month + 1, year);
33027 if (dateVal > monthdays) {
33028 month = month + 1;
33029 date = 1;
33030 unit = 'month';
33031 val = month;
33032 return month;
33033 }
33034 return month;
33035 };
33036 var remainingHours = 24 - firstVal.minHour;
33037 var yrCounter = 0;
33038
33039 // calculate the first tick position
33040 var firstTickPosition = remainingHours * hoursWidthOnXAxis;
33041 var val = firstTickValue;
33042 var month = changeMonth(date, currentMonth, currentYear);
33043 if (firstVal.minHour === 0 && firstVal.minDate === 1) {
33044 // the first value is the first day of month
33045 firstTickPosition = 0;
33046 val = Utils$1.monthMod(firstVal.minMonth);
33047 unit = 'month';
33048 date = firstVal.minDate;
33049 // numberOfDays++
33050 // removed the above line to fix https://github.com/apexcharts/apexcharts.js/issues/305#issuecomment-1019520513
33051 } else if (firstVal.minDate !== 1 && firstVal.minHour === 0 && firstVal.minMinute === 0) {
33052 // fixes apexcharts/apexcharts.js/issues/1730
33053 firstTickPosition = 0;
33054 firstTickValue = firstVal.minDate;
33055 date = firstTickValue;
33056 val = firstTickValue;
33057 // in case it's the last date of month, we need to check it
33058 month = changeMonth(date, currentMonth, currentYear);
33059 if (val !== 1) {
33060 unit = 'day';
33061 }
33062 }
33063
33064 // push the first tick in the array
33065 this.timeScaleArray.push({
33066 position: firstTickPosition,
33067 value: val,
33068 unit: unit,
33069 year: this._getYear(currentYear, month, yrCounter),
33070 month: Utils$1.monthMod(month),
33071 day: date
33072 });
33073 var pos = firstTickPosition;
33074 // keep drawing rest of the ticks
33075 for (var i = 0; i < numberOfDays; i++) {
33076 date += 1;
33077 unit = 'day';
33078 month = changeMonth(date, month, this._getYear(currentYear, month, yrCounter));
33079 var year = this._getYear(currentYear, month, yrCounter);
33080 pos = 24 * hoursWidthOnXAxis + pos;
33081 var value = date === 1 ? Utils$1.monthMod(month) : date;
33082 this.timeScaleArray.push({
33083 position: pos,
33084 value: value,
33085 unit: unit,
33086 year: year,
33087 month: Utils$1.monthMod(month),
33088 day: value
33089 });
33090 }
33091 }
33092 }, {
33093 key: "generateHourScale",
33094 value: function generateHourScale(_ref4) {
33095 var firstVal = _ref4.firstVal,
33096 currentDate = _ref4.currentDate,
33097 currentMonth = _ref4.currentMonth,
33098 currentYear = _ref4.currentYear,
33099 minutesWidthOnXAxis = _ref4.minutesWidthOnXAxis,
33100 numberOfHours = _ref4.numberOfHours;
33101 var dt = new DateTime(this.ctx);
33102 var yrCounter = 0;
33103 var unit = 'hour';
33104 var changeDate = function changeDate(dateVal, month) {
33105 var monthdays = dt.determineDaysOfMonths(month + 1, currentYear);
33106 if (dateVal > monthdays) {
33107 date = 1;
33108 month = month + 1;
33109 }
33110 return {
33111 month: month,
33112 date: date
33113 };
33114 };
33115 var changeMonth = function changeMonth(dateVal, month) {
33116 var monthdays = dt.determineDaysOfMonths(month + 1, currentYear);
33117 if (dateVal > monthdays) {
33118 month = month + 1;
33119 return month;
33120 }
33121 return month;
33122 };
33123
33124 // factor in minSeconds as well
33125 var remainingMins = 60 - (firstVal.minMinute + firstVal.minSecond / 60.0);
33126 var firstTickPosition = remainingMins * minutesWidthOnXAxis;
33127 var firstTickValue = firstVal.minHour + 1;
33128 var hour = firstTickValue;
33129 if (remainingMins === 60) {
33130 firstTickPosition = 0;
33131 firstTickValue = firstVal.minHour;
33132 hour = firstTickValue;
33133 }
33134 var date = currentDate;
33135
33136 // we need to apply date switching logic here as well, to avoid duplicated labels
33137 if (hour >= 24) {
33138 hour = 0;
33139 date += 1;
33140 unit = 'day';
33141 // Unit changed to day , Value should align unit
33142 firstTickValue = date;
33143 }
33144 var checkNextMonth = changeDate(date, currentMonth);
33145 var month = checkNextMonth.month;
33146 month = changeMonth(date, month);
33147
33148 // Check if date is greater than 31 and change month if it is
33149 if (firstTickValue > 31) {
33150 date = 1;
33151 firstTickValue = date;
33152 }
33153
33154 // push the first tick in the array
33155 this.timeScaleArray.push({
33156 position: firstTickPosition,
33157 value: firstTickValue,
33158 unit: unit,
33159 day: date,
33160 hour: hour,
33161 year: currentYear,
33162 month: Utils$1.monthMod(month)
33163 });
33164 hour++;
33165 var pos = firstTickPosition;
33166 // keep drawing rest of the ticks
33167 for (var i = 0; i < numberOfHours; i++) {
33168 unit = 'hour';
33169 if (hour >= 24) {
33170 hour = 0;
33171 date += 1;
33172 unit = 'day';
33173 var _checkNextMonth = changeDate(date, month);
33174 month = _checkNextMonth.month;
33175 month = changeMonth(date, month);
33176 }
33177 var year = this._getYear(currentYear, month, yrCounter);
33178 pos = 60 * minutesWidthOnXAxis + pos;
33179 var val = hour === 0 ? date : hour;
33180 this.timeScaleArray.push({
33181 position: pos,
33182 value: val,
33183 unit: unit,
33184 hour: hour,
33185 day: date,
33186 year: year,
33187 month: Utils$1.monthMod(month)
33188 });
33189 hour++;
33190 }
33191 }
33192 }, {
33193 key: "generateMinuteScale",
33194 value: function generateMinuteScale(_ref5) {
33195 var currentMillisecond = _ref5.currentMillisecond,
33196 currentSecond = _ref5.currentSecond,
33197 currentMinute = _ref5.currentMinute,
33198 currentHour = _ref5.currentHour,
33199 currentDate = _ref5.currentDate,
33200 currentMonth = _ref5.currentMonth,
33201 currentYear = _ref5.currentYear,
33202 minutesWidthOnXAxis = _ref5.minutesWidthOnXAxis,
33203 secondsWidthOnXAxis = _ref5.secondsWidthOnXAxis,
33204 numberOfMinutes = _ref5.numberOfMinutes;
33205 var yrCounter = 0;
33206 var unit = 'minute';
33207 var remainingSecs = 60 - currentSecond;
33208 var firstTickPosition = (remainingSecs - currentMillisecond / 1000) * secondsWidthOnXAxis;
33209 var minute = currentMinute + 1;
33210 var date = currentDate;
33211 var month = currentMonth;
33212 var year = currentYear;
33213 var hour = currentHour;
33214 var pos = firstTickPosition;
33215 for (var i = 0; i < numberOfMinutes; i++) {
33216 if (minute >= 60) {
33217 minute = 0;
33218 hour += 1;
33219 if (hour === 24) {
33220 hour = 0;
33221 }
33222 }
33223 this.timeScaleArray.push({
33224 position: pos,
33225 value: minute,
33226 unit: unit,
33227 hour: hour,
33228 minute: minute,
33229 day: date,
33230 year: this._getYear(year, month, yrCounter),
33231 month: Utils$1.monthMod(month)
33232 });
33233 pos += minutesWidthOnXAxis;
33234 minute++;
33235 }
33236 }
33237 }, {
33238 key: "generateSecondScale",
33239 value: function generateSecondScale(_ref6) {
33240 var currentMillisecond = _ref6.currentMillisecond,
33241 currentSecond = _ref6.currentSecond,
33242 currentMinute = _ref6.currentMinute,
33243 currentHour = _ref6.currentHour,
33244 currentDate = _ref6.currentDate,
33245 currentMonth = _ref6.currentMonth,
33246 currentYear = _ref6.currentYear,
33247 secondsWidthOnXAxis = _ref6.secondsWidthOnXAxis,
33248 numberOfSeconds = _ref6.numberOfSeconds;
33249 var yrCounter = 0;
33250 var unit = 'second';
33251 var remainingMillisecs = 1000 - currentMillisecond;
33252 var firstTickPosition = remainingMillisecs / 1000 * secondsWidthOnXAxis;
33253 var second = currentSecond + 1;
33254 var minute = currentMinute;
33255 var date = currentDate;
33256 var month = currentMonth;
33257 var year = currentYear;
33258 var hour = currentHour;
33259 var pos = firstTickPosition;
33260 for (var i = 0; i < numberOfSeconds; i++) {
33261 if (second >= 60) {
33262 minute++;
33263 second = 0;
33264 if (minute >= 60) {
33265 hour++;
33266 minute = 0;
33267 if (hour === 24) {
33268 hour = 0;
33269 }
33270 }
33271 }
33272 this.timeScaleArray.push({
33273 position: pos,
33274 value: second,
33275 unit: unit,
33276 hour: hour,
33277 minute: minute,
33278 second: second,
33279 day: date,
33280 year: this._getYear(year, month, yrCounter),
33281 month: Utils$1.monthMod(month)
33282 });
33283 pos += secondsWidthOnXAxis;
33284 second++;
33285 }
33286 }
33287 }, {
33288 key: "createRawDateString",
33289 value: function createRawDateString(ts, value) {
33290 var raw = ts.year;
33291 if (ts.month === 0) {
33292 // invalid month, correct it
33293 ts.month = 1;
33294 }
33295 raw += '-' + ('0' + ts.month.toString()).slice(-2);
33296
33297 // unit is day
33298 if (ts.unit === 'day') {
33299 raw += ts.unit === 'day' ? '-' + ('0' + value).slice(-2) : '-01';
33300 } else {
33301 raw += '-' + ('0' + (ts.day ? ts.day : '1')).slice(-2);
33302 }
33303
33304 // unit is hour
33305 if (ts.unit === 'hour') {
33306 raw += ts.unit === 'hour' ? 'T' + ('0' + value).slice(-2) : 'T00';
33307 } else {
33308 raw += 'T' + ('0' + (ts.hour ? ts.hour : '0')).slice(-2);
33309 }
33310 if (ts.unit === 'minute') {
33311 raw += ':' + ('0' + value).slice(-2);
33312 } else {
33313 raw += ':' + (ts.minute ? ('0' + ts.minute).slice(-2) : '00');
33314 }
33315 if (ts.unit === 'second') {
33316 raw += ':' + ('0' + value).slice(-2);
33317 } else {
33318 raw += ':00';
33319 }
33320 if (this.utc) {
33321 raw += '.000Z';
33322 }
33323 return raw;
33324 }
33325 }, {
33326 key: "formatDates",
33327 value: function formatDates(filteredTimeScale) {
33328 var _this2 = this;
33329 var w = this.w;
33330 var reformattedTimescaleArray = filteredTimeScale.map(function (ts) {
33331 var value = ts.value.toString();
33332 var dt = new DateTime(_this2.ctx);
33333 var raw = _this2.createRawDateString(ts, value);
33334 var dateToFormat = dt.getDate(dt.parseDate(raw));
33335 if (!_this2.utc) {
33336 // Fixes #1726, #1544, #1485, #1255
33337 dateToFormat = dt.getDate(dt.parseDateWithTimezone(raw));
33338 }
33339 if (w.config.xaxis.labels.format === undefined) {
33340 var customFormat = 'dd MMM';
33341 var dtFormatter = w.config.xaxis.labels.datetimeFormatter;
33342 if (ts.unit === 'year') customFormat = dtFormatter.year;
33343 if (ts.unit === 'month') customFormat = dtFormatter.month;
33344 if (ts.unit === 'day') customFormat = dtFormatter.day;
33345 if (ts.unit === 'hour') customFormat = dtFormatter.hour;
33346 if (ts.unit === 'minute') customFormat = dtFormatter.minute;
33347 if (ts.unit === 'second') customFormat = dtFormatter.second;
33348 value = dt.formatDate(dateToFormat, customFormat);
33349 } else {
33350 value = dt.formatDate(dateToFormat, w.config.xaxis.labels.format);
33351 }
33352 return {
33353 dateString: raw,
33354 position: ts.position,
33355 value: value,
33356 unit: ts.unit,
33357 year: ts.year,
33358 month: ts.month
33359 };
33360 });
33361 return reformattedTimescaleArray;
33362 }
33363 }, {
33364 key: "removeOverlappingTS",
33365 value: function removeOverlappingTS(arr) {
33366 var _this3 = this;
33367 var graphics = new Graphics(this.ctx);
33368 var equalLabelLengthFlag = false; // These labels got same length?
33369 var constantLabelWidth; // If true, what is the constant length to use
33370 if (arr.length > 0 &&
33371 // check arr length
33372 arr[0].value &&
33373 // check arr[0] contains value
33374 arr.every(function (lb) {
33375 return lb.value.length === arr[0].value.length;
33376 }) // check every arr label value is the same as the first one
33377 ) {
33378 equalLabelLengthFlag = true; // These labels got same length
33379 constantLabelWidth = graphics.getTextRects(arr[0].value).width; // The constant label width to use
33380 }
33381 var lastDrawnIndex = 0;
33382 var filteredArray = arr.map(function (item, index) {
33383 if (index > 0 && _this3.w.config.xaxis.labels.hideOverlappingLabels) {
33384 var prevLabelWidth = !equalLabelLengthFlag // if vary in label length
33385 ? graphics.getTextRects(arr[lastDrawnIndex].value).width // get individual length
33386 : constantLabelWidth; // else: use constant length
33387 var prevPos = arr[lastDrawnIndex].position;
33388 var pos = item.position;
33389 if (pos > prevPos + prevLabelWidth + 10) {
33390 lastDrawnIndex = index;
33391 return item;
33392 } else {
33393 return null;
33394 }
33395 } else {
33396 return item;
33397 }
33398 });
33399 filteredArray = filteredArray.filter(function (f) {
33400 return f !== null;
33401 });
33402 return filteredArray;
33403 }
33404 }, {
33405 key: "_getYear",
33406 value: function _getYear(currentYear, month, yrCounter) {
33407 return currentYear + Math.floor(month / 12) + yrCounter;
33408 }
33409 }]);
33410 return TimeScale;
33411 }();
33412
33413 /**
33414 * ApexCharts Core Class responsible for major calculations and creating elements.
33415 *
33416 * @module Core
33417 **/
33418 var Core = /*#__PURE__*/function () {
33419 function Core(el, ctx) {
33420 _classCallCheck(this, Core);
33421 this.ctx = ctx;
33422 this.w = ctx.w;
33423 this.el = el;
33424 }
33425 _createClass(Core, [{
33426 key: "setupElements",
33427 value: function setupElements() {
33428 var _this$w = this.w,
33429 gl = _this$w.globals,
33430 cnf = _this$w.config;
33431 var ct = cnf.chart.type;
33432 var axisChartsArrTypes = ['line', 'area', 'bar', 'rangeBar', 'rangeArea', 'candlestick', 'boxPlot', 'scatter', 'bubble', 'radar', 'heatmap', 'treemap'];
33433 var xyChartsArrTypes = ['line', 'area', 'bar', 'rangeBar', 'rangeArea', 'candlestick', 'boxPlot', 'scatter', 'bubble'];
33434 gl.axisCharts = axisChartsArrTypes.includes(ct);
33435 gl.xyCharts = xyChartsArrTypes.includes(ct);
33436 gl.isBarHorizontal = ['bar', 'rangeBar', 'boxPlot'].includes(ct) && cnf.plotOptions.bar.horizontal;
33437 gl.chartClass = ".apexcharts".concat(gl.chartID);
33438 gl.dom.baseEl = this.el;
33439 gl.dom.elWrap = document.createElement('div');
33440 Graphics.setAttrs(gl.dom.elWrap, {
33441 id: gl.chartClass.substring(1),
33442 class: "apexcharts-canvas ".concat(gl.chartClass.substring(1))
33443 });
33444 this.el.appendChild(gl.dom.elWrap);
33445
33446 // gl.dom.Paper = new window.SVG.Doc(gl.dom.elWrap)
33447 gl.dom.Paper = window.SVG().addTo(gl.dom.elWrap);
33448 gl.dom.Paper.attr({
33449 class: 'apexcharts-svg',
33450 'xmlns:data': 'ApexChartsNS',
33451 transform: "translate(".concat(cnf.chart.offsetX, ", ").concat(cnf.chart.offsetY, ")")
33452 });
33453 gl.dom.Paper.node.style.background = cnf.theme.mode === 'dark' && !cnf.chart.background ? '#343A3F' : cnf.theme.mode === 'light' && !cnf.chart.background ? '#fff' : cnf.chart.background;
33454 this.setSVGDimensions();
33455 gl.dom.elLegendForeign = document.createElementNS(gl.SVGNS, 'foreignObject');
33456 Graphics.setAttrs(gl.dom.elLegendForeign, {
33457 x: 0,
33458 y: 0,
33459 width: gl.svgWidth,
33460 height: gl.svgHeight
33461 });
33462 gl.dom.elLegendWrap = document.createElement('div');
33463 gl.dom.elLegendWrap.classList.add('apexcharts-legend');
33464 gl.dom.elWrap.appendChild(gl.dom.elLegendWrap);
33465 gl.dom.Paper.node.appendChild(gl.dom.elLegendForeign);
33466 gl.dom.elGraphical = gl.dom.Paper.group().attr({
33467 class: 'apexcharts-inner apexcharts-graphical'
33468 });
33469 gl.dom.elDefs = gl.dom.Paper.defs();
33470 gl.dom.Paper.add(gl.dom.elGraphical);
33471 gl.dom.elGraphical.add(gl.dom.elDefs);
33472 }
33473 }, {
33474 key: "plotChartType",
33475 value: function plotChartType(ser, xyRatios) {
33476 var w = this.w,
33477 ctx = this.ctx;
33478 var cnf = w.config,
33479 gl = w.globals;
33480 var seriesTypes = {
33481 line: {
33482 series: [],
33483 i: []
33484 },
33485 area: {
33486 series: [],
33487 i: []
33488 },
33489 scatter: {
33490 series: [],
33491 i: []
33492 },
33493 bubble: {
33494 series: [],
33495 i: []
33496 },
33497 bar: {
33498 series: [],
33499 i: []
33500 },
33501 candlestick: {
33502 series: [],
33503 i: []
33504 },
33505 boxPlot: {
33506 series: [],
33507 i: []
33508 },
33509 rangeBar: {
33510 series: [],
33511 i: []
33512 },
33513 rangeArea: {
33514 series: [],
33515 seriesRangeEnd: [],
33516 i: []
33517 }
33518 };
33519 var chartType = cnf.chart.type || 'line';
33520 var nonComboType = null;
33521 var comboCount = 0;
33522 gl.series.forEach(function (serie, st) {
33523 var seriesType = ser[st].type === 'column' ? 'bar' : ser[st].type || (chartType === 'column' ? 'bar' : chartType);
33524 if (seriesTypes[seriesType]) {
33525 if (seriesType === 'rangeArea') {
33526 seriesTypes[seriesType].series.push(gl.seriesRangeStart[st]);
33527 seriesTypes[seriesType].seriesRangeEnd.push(gl.seriesRangeEnd[st]);
33528 } else {
33529 seriesTypes[seriesType].series.push(serie);
33530 }
33531 seriesTypes[seriesType].i.push(st);
33532 if (seriesType === 'bar') w.globals.columnSeries = seriesTypes.bar;
33533 } else if (['heatmap', 'treemap', 'pie', 'donut', 'polarArea', 'radialBar', 'radar'].includes(seriesType)) {
33534 nonComboType = seriesType;
33535 } else {
33536 console.warn("You have specified an unrecognized series type (".concat(seriesType, ")."));
33537 }
33538 if (chartType !== seriesType && seriesType !== 'scatter') comboCount++;
33539 });
33540 if (comboCount > 0) {
33541 if (nonComboType) {
33542 console.warn("Chart or series type ".concat(nonComboType, " cannot appear with other chart or series types."));
33543 }
33544 if (seriesTypes.bar.series.length > 0 && cnf.plotOptions.bar.horizontal) {
33545 comboCount -= seriesTypes.bar.series.length;
33546 seriesTypes.bar = {
33547 series: [],
33548 i: []
33549 };
33550 w.globals.columnSeries = {
33551 series: [],
33552 i: []
33553 };
33554 console.warn('Horizontal bars are not supported in a mixed/combo chart. Please turn off `plotOptions.bar.horizontal`');
33555 }
33556 }
33557 gl.comboCharts || (gl.comboCharts = comboCount > 0);
33558 var line = new Line(ctx, xyRatios);
33559 var boxCandlestick = new BoxCandleStick(ctx, xyRatios);
33560 ctx.pie = new Pie(ctx);
33561 var radialBar = new Radial(ctx);
33562 ctx.rangeBar = new RangeBar(ctx, xyRatios);
33563 var radar = new Radar(ctx);
33564 var elGraph = [];
33565 if (gl.comboCharts) {
33566 var coreUtils = new CoreUtils(ctx);
33567 if (seriesTypes.area.series.length > 0) {
33568 var _elGraph;
33569 (_elGraph = elGraph).push.apply(_elGraph, _toConsumableArray(coreUtils.drawSeriesByGroup(seriesTypes.area, gl.areaGroups, 'area', line)));
33570 }
33571 if (seriesTypes.bar.series.length > 0) {
33572 if (cnf.chart.stacked) {
33573 var barStacked = new BarStacked(ctx, xyRatios);
33574 elGraph.push(barStacked.draw(seriesTypes.bar.series, seriesTypes.bar.i));
33575 } else {
33576 ctx.bar = new Bar(ctx, xyRatios);
33577 elGraph.push(ctx.bar.draw(seriesTypes.bar.series, seriesTypes.bar.i));
33578 }
33579 }
33580 if (seriesTypes.rangeArea.series.length > 0) {
33581 elGraph.push(line.draw(seriesTypes.rangeArea.series, 'rangeArea', seriesTypes.rangeArea.i, seriesTypes.rangeArea.seriesRangeEnd));
33582 }
33583 if (seriesTypes.line.series.length > 0) {
33584 var _elGraph2;
33585 (_elGraph2 = elGraph).push.apply(_elGraph2, _toConsumableArray(coreUtils.drawSeriesByGroup(seriesTypes.line, gl.lineGroups, 'line', line)));
33586 }
33587 if (seriesTypes.candlestick.series.length > 0) {
33588 elGraph.push(boxCandlestick.draw(seriesTypes.candlestick.series, 'candlestick', seriesTypes.candlestick.i));
33589 }
33590 if (seriesTypes.boxPlot.series.length > 0) {
33591 elGraph.push(boxCandlestick.draw(seriesTypes.boxPlot.series, 'boxPlot', seriesTypes.boxPlot.i));
33592 }
33593 if (seriesTypes.rangeBar.series.length > 0) {
33594 elGraph.push(ctx.rangeBar.draw(seriesTypes.rangeBar.series, seriesTypes.rangeBar.i));
33595 }
33596 if (seriesTypes.scatter.series.length > 0) {
33597 var scatterLine = new Line(ctx, xyRatios, true);
33598 elGraph.push(scatterLine.draw(seriesTypes.scatter.series, 'scatter', seriesTypes.scatter.i));
33599 }
33600 if (seriesTypes.bubble.series.length > 0) {
33601 var bubbleLine = new Line(ctx, xyRatios, true);
33602 elGraph.push(bubbleLine.draw(seriesTypes.bubble.series, 'bubble', seriesTypes.bubble.i));
33603 }
33604 } else {
33605 switch (cnf.chart.type) {
33606 case 'line':
33607 elGraph = line.draw(gl.series, 'line');
33608 break;
33609 case 'area':
33610 elGraph = line.draw(gl.series, 'area');
33611 break;
33612 case 'bar':
33613 if (cnf.chart.stacked) {
33614 var _barStacked = new BarStacked(ctx, xyRatios);
33615 elGraph = _barStacked.draw(gl.series);
33616 } else {
33617 ctx.bar = new Bar(ctx, xyRatios);
33618 elGraph = ctx.bar.draw(gl.series);
33619 }
33620 break;
33621 case 'candlestick':
33622 var candleStick = new BoxCandleStick(ctx, xyRatios);
33623 elGraph = candleStick.draw(gl.series, 'candlestick');
33624 break;
33625 case 'boxPlot':
33626 var boxPlot = new BoxCandleStick(ctx, xyRatios);
33627 elGraph = boxPlot.draw(gl.series, cnf.chart.type);
33628 break;
33629 case 'rangeBar':
33630 elGraph = ctx.rangeBar.draw(gl.series);
33631 break;
33632 case 'rangeArea':
33633 elGraph = line.draw(gl.seriesRangeStart, 'rangeArea', undefined, gl.seriesRangeEnd);
33634 break;
33635 case 'heatmap':
33636 var heatmap = new HeatMap(ctx, xyRatios);
33637 elGraph = heatmap.draw(gl.series);
33638 break;
33639 case 'treemap':
33640 var treemap = new TreemapChart(ctx, xyRatios);
33641 elGraph = treemap.draw(gl.series);
33642 break;
33643 case 'pie':
33644 case 'donut':
33645 case 'polarArea':
33646 elGraph = ctx.pie.draw(gl.series);
33647 break;
33648 case 'radialBar':
33649 elGraph = radialBar.draw(gl.series);
33650 break;
33651 case 'radar':
33652 elGraph = radar.draw(gl.series);
33653 break;
33654 default:
33655 elGraph = line.draw(gl.series);
33656 }
33657 }
33658 return elGraph;
33659 }
33660 }, {
33661 key: "setSVGDimensions",
33662 value: function setSVGDimensions() {
33663 var _this$w2 = this.w,
33664 gl = _this$w2.globals,
33665 cnf = _this$w2.config;
33666 cnf.chart.width = cnf.chart.width || '100%';
33667 cnf.chart.height = cnf.chart.height || 'auto';
33668 gl.svgWidth = cnf.chart.width;
33669 gl.svgHeight = cnf.chart.height;
33670 var elDim = Utils$1.getDimensions(this.el);
33671 var widthUnit = cnf.chart.width.toString().split(/[0-9]+/g).pop();
33672 if (widthUnit === '%') {
33673 if (Utils$1.isNumber(elDim[0])) {
33674 if (elDim[0].width === 0) {
33675 elDim = Utils$1.getDimensions(this.el.parentNode);
33676 }
33677 gl.svgWidth = elDim[0] * parseInt(cnf.chart.width, 10) / 100;
33678 }
33679 } else if (widthUnit === 'px' || widthUnit === '') {
33680 gl.svgWidth = parseInt(cnf.chart.width, 10);
33681 }
33682 var heightUnit = String(cnf.chart.height).toString().split(/[0-9]+/g).pop();
33683 if (gl.svgHeight !== 'auto' && gl.svgHeight !== '') {
33684 if (heightUnit === '%') {
33685 var elParentDim = Utils$1.getDimensions(this.el.parentNode);
33686 gl.svgHeight = elParentDim[1] * parseInt(cnf.chart.height, 10) / 100;
33687 } else {
33688 gl.svgHeight = parseInt(cnf.chart.height, 10);
33689 }
33690 } else {
33691 gl.svgHeight = gl.axisCharts ? gl.svgWidth / 1.61 : gl.svgWidth / 1.2;
33692 }
33693 gl.svgWidth = Math.max(gl.svgWidth, 0);
33694 gl.svgHeight = Math.max(gl.svgHeight, 0);
33695 Graphics.setAttrs(gl.dom.Paper.node, {
33696 width: gl.svgWidth,
33697 height: gl.svgHeight
33698 });
33699 if (heightUnit !== '%') {
33700 var offsetY = cnf.chart.sparkline.enabled ? 0 : gl.axisCharts ? cnf.chart.parentHeightOffset : 0;
33701 gl.dom.Paper.node.parentNode.parentNode.style.minHeight = "".concat(gl.svgHeight + offsetY, "px");
33702 }
33703 gl.dom.elWrap.style.width = "".concat(gl.svgWidth, "px");
33704 gl.dom.elWrap.style.height = "".concat(gl.svgHeight, "px");
33705 }
33706 }, {
33707 key: "shiftGraphPosition",
33708 value: function shiftGraphPosition() {
33709 var gl = this.w.globals;
33710 var tY = gl.translateY,
33711 tX = gl.translateX;
33712 Graphics.setAttrs(gl.dom.elGraphical.node, {
33713 transform: "translate(".concat(tX, ", ").concat(tY, ")")
33714 });
33715 }
33716 }, {
33717 key: "resizeNonAxisCharts",
33718 value: function resizeNonAxisCharts() {
33719 var w = this.w;
33720 var gl = w.globals;
33721 var legendHeight = 0;
33722 var offY = w.config.chart.sparkline.enabled ? 1 : 15;
33723 offY += w.config.grid.padding.bottom;
33724 if (['top', 'bottom'].includes(w.config.legend.position) && w.config.legend.show && !w.config.legend.floating) {
33725 legendHeight = new Legend(this.ctx).legendHelpers.getLegendDimensions().clwh + 7;
33726 }
33727 var el = w.globals.dom.baseEl.querySelector('.apexcharts-radialbar, .apexcharts-pie');
33728 var chartInnerDimensions = w.globals.radialSize * 2.05;
33729 if (el && !w.config.chart.sparkline.enabled && w.config.plotOptions.radialBar.startAngle !== 0) {
33730 var elRadialRect = Utils$1.getBoundingClientRect(el);
33731 chartInnerDimensions = elRadialRect.bottom;
33732 var maxHeight = elRadialRect.bottom - elRadialRect.top;
33733 chartInnerDimensions = Math.max(w.globals.radialSize * 2.05, maxHeight);
33734 }
33735 var newHeight = Math.ceil(chartInnerDimensions + gl.translateY + legendHeight + offY);
33736 if (gl.dom.elLegendForeign) {
33737 gl.dom.elLegendForeign.setAttribute('height', newHeight);
33738 }
33739 if (w.config.chart.height && String(w.config.chart.height).includes('%')) return;
33740 gl.dom.elWrap.style.height = "".concat(newHeight, "px");
33741 Graphics.setAttrs(gl.dom.Paper.node, {
33742 height: newHeight
33743 });
33744 gl.dom.Paper.node.parentNode.parentNode.style.minHeight = "".concat(newHeight, "px");
33745 }
33746 }, {
33747 key: "coreCalculations",
33748 value: function coreCalculations() {
33749 new Range(this.ctx).init();
33750 }
33751 }, {
33752 key: "resetGlobals",
33753 value: function resetGlobals() {
33754 var _this = this;
33755 var resetxyValues = function resetxyValues() {
33756 return _this.w.config.series.map(function () {
33757 return [];
33758 });
33759 };
33760 var globalObj = new Globals();
33761 var gl = this.w.globals;
33762 globalObj.initGlobalVars(gl);
33763 gl.seriesXvalues = resetxyValues();
33764 gl.seriesYvalues = resetxyValues();
33765 }
33766 }, {
33767 key: "isMultipleY",
33768 value: function isMultipleY() {
33769 if (Array.isArray(this.w.config.yaxis) && this.w.config.yaxis.length > 1) {
33770 this.w.globals.isMultipleYAxis = true;
33771 return true;
33772 }
33773 return false;
33774 }
33775 }, {
33776 key: "xySettings",
33777 value: function xySettings() {
33778 var w = this.w;
33779 var xyRatios = null;
33780 if (w.globals.axisCharts) {
33781 if (w.config.xaxis.crosshairs.position === 'back') {
33782 new Crosshairs(this.ctx).drawXCrosshairs();
33783 }
33784 if (w.config.yaxis[0].crosshairs.position === 'back') {
33785 new Crosshairs(this.ctx).drawYCrosshairs();
33786 }
33787 if (w.config.xaxis.type === 'datetime' && w.config.xaxis.labels.formatter === undefined) {
33788 this.ctx.timeScale = new TimeScale(this.ctx);
33789 var formattedTimeScale = [];
33790 if (isFinite(w.globals.minX) && isFinite(w.globals.maxX) && !w.globals.isBarHorizontal) {
33791 formattedTimeScale = this.ctx.timeScale.calculateTimeScaleTicks(w.globals.minX, w.globals.maxX);
33792 } else if (w.globals.isBarHorizontal) {
33793 formattedTimeScale = this.ctx.timeScale.calculateTimeScaleTicks(w.globals.minY, w.globals.maxY);
33794 }
33795 this.ctx.timeScale.recalcDimensionsBasedOnFormat(formattedTimeScale);
33796 }
33797 var coreUtils = new CoreUtils(this.ctx);
33798 xyRatios = coreUtils.getCalculatedRatios();
33799 }
33800 return xyRatios;
33801 }
33802 }, {
33803 key: "updateSourceChart",
33804 value: function updateSourceChart(targetChart) {
33805 this.ctx.w.globals.selection = undefined;
33806 this.ctx.updateHelpers._updateOptions({
33807 chart: {
33808 selection: {
33809 xaxis: {
33810 min: targetChart.w.globals.minX,
33811 max: targetChart.w.globals.maxX
33812 }
33813 }
33814 }
33815 }, false, false);
33816 }
33817 }, {
33818 key: "setupBrushHandler",
33819 value: function setupBrushHandler() {
33820 var _this2 = this;
33821 var ctx = this.ctx,
33822 w = this.w;
33823 if (!w.config.chart.brush.enabled) return;
33824 if (typeof w.config.chart.events.selection !== 'function') {
33825 var targets = Array.isArray(w.config.chart.brush.targets) ? w.config.chart.brush.targets : [w.config.chart.brush.target];
33826 targets.forEach(function (target) {
33827 var targetChart = ctx.constructor.getChartByID(target);
33828 targetChart.w.globals.brushSource = _this2.ctx;
33829 if (typeof targetChart.w.config.chart.events.zoomed !== 'function') {
33830 targetChart.w.config.chart.events.zoomed = function () {
33831 return _this2.updateSourceChart(targetChart);
33832 };
33833 }
33834 if (typeof targetChart.w.config.chart.events.scrolled !== 'function') {
33835 targetChart.w.config.chart.events.scrolled = function () {
33836 return _this2.updateSourceChart(targetChart);
33837 };
33838 }
33839 });
33840 w.config.chart.events.selection = function (chart, e) {
33841 targets.forEach(function (target) {
33842 var targetChart = ctx.constructor.getChartByID(target);
33843 targetChart.ctx.updateHelpers._updateOptions({
33844 xaxis: {
33845 min: e.xaxis.min,
33846 max: e.xaxis.max
33847 }
33848 }, false, false, false, false);
33849 });
33850 };
33851 }
33852 }
33853 }]);
33854 return Core;
33855 }();
33856
33857 var UpdateHelpers = /*#__PURE__*/function () {
33858 function UpdateHelpers(ctx) {
33859 _classCallCheck(this, UpdateHelpers);
33860 this.ctx = ctx;
33861 this.w = ctx.w;
33862 }
33863
33864 /**
33865 * private method to update Options.
33866 *
33867 * @param {object} options - A new config object can be passed which will be merged with the existing config object
33868 * @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
33869 * @param {boolean} animate - should animate or not on updating Options
33870 * @param {boolean} overwriteInitialConfig - should update the initial config or not
33871 */
33872 _createClass(UpdateHelpers, [{
33873 key: "_updateOptions",
33874 value: function _updateOptions(options) {
33875 var _this = this;
33876 var redraw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
33877 var animate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
33878 var updateSyncedCharts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
33879 var overwriteInitialConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
33880 return new Promise(function (resolve) {
33881 var charts = [_this.ctx];
33882 if (updateSyncedCharts) {
33883 charts = _this.ctx.getSyncedCharts();
33884 }
33885 if (_this.ctx.w.globals.isExecCalled) {
33886 // If the user called exec method, we don't want to get grouped charts as user specifically provided a chartID to update
33887 charts = [_this.ctx];
33888 _this.ctx.w.globals.isExecCalled = false;
33889 }
33890 charts.forEach(function (ch, chartIndex) {
33891 var w = ch.w;
33892 w.globals.shouldAnimate = animate;
33893 if (!redraw) {
33894 w.globals.resized = true;
33895 w.globals.dataChanged = true;
33896 if (animate) {
33897 ch.series.getPreviousPaths();
33898 }
33899 }
33900 if (options && _typeof(options) === 'object') {
33901 ch.config = new Config(options);
33902 options = CoreUtils.extendArrayProps(ch.config, options, w);
33903
33904 // fixes #914, #623
33905 if (ch.w.globals.chartID !== _this.ctx.w.globals.chartID) {
33906 // don't overwrite series of synchronized charts
33907 delete options.series;
33908 }
33909 w.config = Utils$1.extend(w.config, options);
33910 if (overwriteInitialConfig) {
33911 // we need to forget the lastXAxis and lastYAxis as user forcefully overwriteInitialConfig. If we do not do this, and next time when user zooms the chart after setting yaxis.min/max or xaxis.min/max - the stored lastXAxis will never allow the chart to use the updated min/max by user.
33912 w.globals.lastXAxis = options.xaxis ? Utils$1.clone(options.xaxis) : [];
33913 w.globals.lastYAxis = options.yaxis ? Utils$1.clone(options.yaxis) : [];
33914
33915 // After forgetting lastAxes, we need to restore the new config in initialConfig/initialSeries
33916 w.globals.initialConfig = Utils$1.extend({}, w.config);
33917 w.globals.initialSeries = Utils$1.clone(w.config.series);
33918 if (options.series) {
33919 // Replace the collapsed series data
33920 for (var i = 0; i < w.globals.collapsedSeriesIndices.length; i++) {
33921 var series = w.config.series[w.globals.collapsedSeriesIndices[i]];
33922 w.globals.collapsedSeries[i].data = w.globals.axisCharts ? series.data.slice() : series;
33923 }
33924 for (var _i = 0; _i < w.globals.ancillaryCollapsedSeriesIndices.length; _i++) {
33925 var _series = w.config.series[w.globals.ancillaryCollapsedSeriesIndices[_i]];
33926 w.globals.ancillaryCollapsedSeries[_i].data = w.globals.axisCharts ? _series.data.slice() : _series;
33927 }
33928
33929 // Ensure that auto-generated axes are scaled to the visible data
33930 ch.series.emptyCollapsedSeries(w.config.series);
33931 }
33932 }
33933 }
33934 return ch.update(options).then(function () {
33935 if (chartIndex === charts.length - 1) {
33936 resolve(ch);
33937 }
33938 });
33939 });
33940 });
33941 }
33942
33943 /**
33944 * Private method to update Series.
33945 *
33946 * @param {array} series - New series which will override the existing
33947 */
33948 }, {
33949 key: "_updateSeries",
33950 value: function _updateSeries(newSeries, animate) {
33951 var _this2 = this;
33952 var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
33953 return new Promise(function (resolve) {
33954 var w = _this2.w;
33955 w.globals.shouldAnimate = animate;
33956 w.globals.dataChanged = true;
33957 if (animate) {
33958 _this2.ctx.series.getPreviousPaths();
33959 }
33960 var existingSeries;
33961
33962 // axis charts
33963 if (w.globals.axisCharts) {
33964 existingSeries = newSeries.map(function (s, i) {
33965 return _this2._extendSeries(s, i);
33966 });
33967 if (existingSeries.length === 0) {
33968 existingSeries = [{
33969 data: []
33970 }];
33971 }
33972 w.config.series = existingSeries;
33973 } else {
33974 // non-axis chart (pie/radialbar)
33975 w.config.series = newSeries.slice();
33976 }
33977 if (overwriteInitialSeries) {
33978 w.globals.initialConfig.series = Utils$1.clone(w.config.series);
33979 w.globals.initialSeries = Utils$1.clone(w.config.series);
33980 }
33981 return _this2.ctx.update().then(function () {
33982 resolve(_this2.ctx);
33983 });
33984 });
33985 }
33986 }, {
33987 key: "_extendSeries",
33988 value: function _extendSeries(s, i) {
33989 var w = this.w;
33990 var ser = w.config.series[i];
33991 return _objectSpread2(_objectSpread2({}, w.config.series[i]), {}, {
33992 name: s.name ? s.name : ser === null || ser === void 0 ? void 0 : ser.name,
33993 color: s.color ? s.color : ser === null || ser === void 0 ? void 0 : ser.color,
33994 type: s.type ? s.type : ser === null || ser === void 0 ? void 0 : ser.type,
33995 group: s.group ? s.group : ser === null || ser === void 0 ? void 0 : ser.group,
33996 hidden: typeof s.hidden !== 'undefined' ? s.hidden : ser === null || ser === void 0 ? void 0 : ser.hidden,
33997 data: s.data ? s.data : ser === null || ser === void 0 ? void 0 : ser.data,
33998 zIndex: typeof s.zIndex !== 'undefined' ? s.zIndex : i
33999 });
34000 }
34001 }, {
34002 key: "toggleDataPointSelection",
34003 value: function toggleDataPointSelection(seriesIndex, dataPointIndex) {
34004 var w = this.w;
34005 var elPath = null;
34006 var parent = ".apexcharts-series[data\\:realIndex='".concat(seriesIndex, "']");
34007 if (w.globals.axisCharts) {
34008 elPath = w.globals.dom.Paper.findOne("".concat(parent, " path[j='").concat(dataPointIndex, "'], ").concat(parent, " circle[j='").concat(dataPointIndex, "'], ").concat(parent, " rect[j='").concat(dataPointIndex, "']"));
34009 } else {
34010 // dataPointIndex will be undefined here, hence using seriesIndex
34011 if (typeof dataPointIndex === 'undefined') {
34012 elPath = w.globals.dom.Paper.findOne("".concat(parent, " path[j='").concat(seriesIndex, "']"));
34013 if (w.config.chart.type === 'pie' || w.config.chart.type === 'polarArea' || w.config.chart.type === 'donut') {
34014 this.ctx.pie.pieClicked(seriesIndex);
34015 }
34016 }
34017 }
34018 if (elPath) {
34019 var graphics = new Graphics(this.ctx);
34020 graphics.pathMouseDown(elPath, null);
34021 } else {
34022 console.warn('toggleDataPointSelection: Element not found');
34023 return null;
34024 }
34025 return elPath.node ? elPath.node : null;
34026 }
34027 }, {
34028 key: "forceXAxisUpdate",
34029 value: function forceXAxisUpdate(options) {
34030 var w = this.w;
34031 var minmax = ['min', 'max'];
34032 minmax.forEach(function (a) {
34033 if (typeof options.xaxis[a] !== 'undefined') {
34034 w.config.xaxis[a] = options.xaxis[a];
34035 w.globals.lastXAxis[a] = options.xaxis[a];
34036 }
34037 });
34038 if (options.xaxis.categories && options.xaxis.categories.length) {
34039 w.config.xaxis.categories = options.xaxis.categories;
34040 }
34041 if (w.config.xaxis.convertedCatToNumeric) {
34042 var defaults = new Defaults(options);
34043 options = defaults.convertCatToNumericXaxis(options, this.ctx);
34044 }
34045 return options;
34046 }
34047 }, {
34048 key: "forceYAxisUpdate",
34049 value: function forceYAxisUpdate(options) {
34050 if (options.chart && options.chart.stacked && options.chart.stackType === '100%') {
34051 if (Array.isArray(options.yaxis)) {
34052 options.yaxis.forEach(function (yaxe, index) {
34053 options.yaxis[index].min = 0;
34054 options.yaxis[index].max = 100;
34055 });
34056 } else {
34057 options.yaxis.min = 0;
34058 options.yaxis.max = 100;
34059 }
34060 }
34061 return options;
34062 }
34063
34064 /**
34065 * This function reverts the yaxis and xaxis min/max values to what it was when the chart was defined.
34066 * This function fixes an important bug where a user might load a new series after zooming in/out of previous series which resulted in wrong min/max
34067 * Also, this should never be called internally on zoom/pan - the reset should only happen when user calls the updateSeries() function externally
34068 * The function also accepts an object {xaxis, yaxis} which when present is set as the new xaxis/yaxis
34069 */
34070 }, {
34071 key: "revertDefaultAxisMinMax",
34072 value: function revertDefaultAxisMinMax(opts) {
34073 var _this3 = this;
34074 var w = this.w;
34075 var xaxis = w.globals.lastXAxis;
34076 var yaxis = w.globals.lastYAxis;
34077 if (opts && opts.xaxis) {
34078 xaxis = opts.xaxis;
34079 }
34080 if (opts && opts.yaxis) {
34081 yaxis = opts.yaxis;
34082 }
34083 w.config.xaxis.min = xaxis.min;
34084 w.config.xaxis.max = xaxis.max;
34085 var getLastYAxis = function getLastYAxis(index) {
34086 if (typeof yaxis[index] !== 'undefined') {
34087 w.config.yaxis[index].min = yaxis[index].min;
34088 w.config.yaxis[index].max = yaxis[index].max;
34089 }
34090 };
34091 w.config.yaxis.map(function (yaxe, index) {
34092 if (w.globals.zoomed) {
34093 // user has zoomed, check the last yaxis
34094 getLastYAxis(index);
34095 } else {
34096 // user hasn't zoomed, check the last yaxis first
34097 if (typeof yaxis[index] !== 'undefined') {
34098 getLastYAxis(index);
34099 } else {
34100 // if last y-axis don't exist, check the original yaxis
34101 if (typeof _this3.ctx.opts.yaxis[index] !== 'undefined') {
34102 yaxe.min = _this3.ctx.opts.yaxis[index].min;
34103 yaxe.max = _this3.ctx.opts.yaxis[index].max;
34104 }
34105 }
34106 }
34107 });
34108 }
34109 }]);
34110 return UpdateHelpers;
34111 }();
34112
34113 (function () {
34114
34115 extend(PathArray, {
34116 morph: function morph(fromArray, toArray, pos, stepper, context) {
34117 var startArr = this.parse(fromArray),
34118 destArr = this.parse(toArray);
34119 var startOffsetM = 0,
34120 destOffsetM = 0;
34121 var startOffsetNextM = false,
34122 destOffsetNextM = false;
34123 while (true) {
34124 // stop if there is no M anymore
34125 if (startOffsetM === false && destOffsetM === false) break;
34126
34127 // find the next M in path array
34128 startOffsetNextM = findNextM(startArr, startOffsetM === false ? false : startOffsetM + 1);
34129 destOffsetNextM = findNextM(destArr, destOffsetM === false ? false : destOffsetM + 1);
34130
34131 // We have to add one M to the startArray
34132 if (startOffsetM === false) {
34133 var bbox = new PathArray(result.start).bbox();
34134
34135 // when the last block had no bounding box we simply take the first M we got
34136 if (bbox.height == 0 || bbox.width == 0) {
34137 startOffsetM = startArr.push(startArr[0]) - 1;
34138 } else {
34139 // we take the middle of the bbox instead when we got one
34140 startOffsetM = startArr.push(['M', bbox.x + bbox.width / 2, bbox.y + bbox.height / 2]) - 1;
34141 }
34142 }
34143
34144 // We have to add one M to the destArray
34145 if (destOffsetM === false) {
34146 var bbox = new PathArray(result.dest).bbox();
34147 if (bbox.height == 0 || bbox.width == 0) {
34148 destOffsetM = destArr.push(destArr[0]) - 1;
34149 } else {
34150 destOffsetM = destArr.push(['M', bbox.x + bbox.width / 2, bbox.y + bbox.height / 2]) - 1;
34151 }
34152 }
34153
34154 // handle block from M to next M
34155 var result = handleBlock(startArr, startOffsetM, startOffsetNextM, destArr, destOffsetM, destOffsetNextM);
34156
34157 // update the arrays to their new values
34158 startArr = startArr.slice(0, startOffsetM).concat(result.start, startOffsetNextM === false ? [] : startArr.slice(startOffsetNextM));
34159 destArr = destArr.slice(0, destOffsetM).concat(result.dest, destOffsetNextM === false ? [] : destArr.slice(destOffsetNextM));
34160
34161 // update offsets
34162 startOffsetM = startOffsetNextM === false ? false : startOffsetM + result.start.length;
34163 destOffsetM = destOffsetNextM === false ? false : destOffsetM + result.dest.length;
34164 }
34165
34166 // copy back arrays
34167 this._array = startArr;
34168 this.destination = new PathArray();
34169 this.destination._array = destArr;
34170 var finalArr = this.fromArray(startArr.map(function (from, fromIndex) {
34171 var step = destArr[fromIndex].map(function (to, toIndex) {
34172 if (toIndex === 0) return to;
34173 return stepper.step(from[toIndex], destArr[fromIndex][toIndex], pos, context[fromIndex], context);
34174 });
34175 return step;
34176 }));
34177 return finalArr;
34178 }
34179 });
34180
34181 // sorry for the long declaration
34182 // slices out one block (from M to M) and syncronize it so the types and length match
34183 function handleBlock() {
34184 var startArr = arguments.length > 0 && arguments[0] !== undefined$1 ? arguments[0] : [];
34185 var startOffsetM = arguments.length > 1 ? arguments[1] : undefined$1;
34186 var startOffsetNextM = arguments.length > 2 ? arguments[2] : undefined$1;
34187 var destArr = arguments.length > 3 ? arguments[3] : undefined$1;
34188 var destOffsetM = arguments.length > 4 ? arguments[4] : undefined$1;
34189 var destOffsetNextM = arguments.length > 5 ? arguments[5] : undefined$1;
34190 var undefined$1 = arguments.length > 6 ? arguments[6] : undefined$1;
34191 // slice out the block we need
34192 var startArrTemp = startArr.slice(startOffsetM, startOffsetNextM || undefined$1),
34193 destArrTemp = destArr.slice(destOffsetM, destOffsetNextM || undefined$1);
34194 var i = 0,
34195 posStart = {
34196 pos: [0, 0],
34197 start: [0, 0]
34198 },
34199 posDest = {
34200 pos: [0, 0],
34201 start: [0, 0]
34202 };
34203 do {
34204 // convert shorthand types to long form
34205 startArrTemp[i] = simplyfy.call(posStart, startArrTemp[i]);
34206 destArrTemp[i] = simplyfy.call(posDest, destArrTemp[i]);
34207
34208 // check if both shape types match
34209 // 2 elliptical arc curve commands ('A'), are considered different if the
34210 // flags (large-arc-flag, sweep-flag) don't match
34211 if (startArrTemp[i][0] != destArrTemp[i][0] || startArrTemp[i][0] == 'M' || startArrTemp[i][0] == 'A' && (startArrTemp[i][4] != destArrTemp[i][4] || startArrTemp[i][5] != destArrTemp[i][5])) {
34212 // if not, convert shapes to beziere
34213 Array.prototype.splice.apply(startArrTemp, [i, 1].concat(toBeziere.call(posStart, startArrTemp[i])));
34214 Array.prototype.splice.apply(destArrTemp, [i, 1].concat(toBeziere.call(posDest, destArrTemp[i])));
34215 } else {
34216 // only update positions otherwise
34217 startArrTemp[i] = setPosAndReflection.call(posStart, startArrTemp[i]);
34218 destArrTemp[i] = setPosAndReflection.call(posDest, destArrTemp[i]);
34219 }
34220
34221 // we are at the end at both arrays. stop here
34222 if (++i == startArrTemp.length && i == destArrTemp.length) break;
34223
34224 // destArray is longer. Add one element
34225 if (i == startArrTemp.length) {
34226 startArrTemp.push(['C', posStart.pos[0], posStart.pos[1], posStart.pos[0], posStart.pos[1], posStart.pos[0], posStart.pos[1]]);
34227 }
34228
34229 // startArr is longer. Add one element
34230 if (i == destArrTemp.length) {
34231 destArrTemp.push(['C', posDest.pos[0], posDest.pos[1], posDest.pos[0], posDest.pos[1], posDest.pos[0], posDest.pos[1]]);
34232 }
34233 } while (true);
34234
34235 // return the updated block
34236 return {
34237 start: startArrTemp,
34238 dest: destArrTemp
34239 };
34240 }
34241
34242 // converts shorthand types to long form
34243 function simplyfy(val) {
34244 switch (val[0]) {
34245 case 'z': // shorthand line to start
34246 case 'Z':
34247 val[0] = 'L';
34248 val[1] = this.start[0];
34249 val[2] = this.start[1];
34250 break;
34251 case 'H':
34252 // shorthand horizontal line
34253 val[0] = 'L';
34254 val[2] = this.pos[1];
34255 break;
34256 case 'V':
34257 // shorthand vertical line
34258 val[0] = 'L';
34259 val[2] = val[1];
34260 val[1] = this.pos[0];
34261 break;
34262 case 'T':
34263 // shorthand quadratic beziere
34264 val[0] = 'Q';
34265 val[3] = val[1];
34266 val[4] = val[2];
34267 val[1] = this.reflection[1];
34268 val[2] = this.reflection[0];
34269 break;
34270 case 'S':
34271 // shorthand cubic beziere
34272 val[0] = 'C';
34273 val[6] = val[4];
34274 val[5] = val[3];
34275 val[4] = val[2];
34276 val[3] = val[1];
34277 val[2] = this.reflection[1];
34278 val[1] = this.reflection[0];
34279 break;
34280 }
34281 return val;
34282 }
34283
34284 // updates reflection point and current position
34285 function setPosAndReflection(val) {
34286 var len = val.length;
34287 this.pos = [val[len - 2], val[len - 1]];
34288 if ('SCQT'.indexOf(val[0]) != -1) this.reflection = [2 * this.pos[0] - val[len - 4], 2 * this.pos[1] - val[len - 3]];
34289 return val;
34290 }
34291
34292 // converts all types to cubic beziere
34293 function toBeziere(val) {
34294 var retVal = [val];
34295 switch (val[0]) {
34296 case 'M':
34297 // special handling for M
34298 this.pos = this.start = [val[1], val[2]];
34299 return retVal;
34300 case 'L':
34301 val[5] = val[3] = val[1];
34302 val[6] = val[4] = val[2];
34303 val[1] = this.pos[0];
34304 val[2] = this.pos[1];
34305 break;
34306 case 'Q':
34307 val[6] = val[4];
34308 val[5] = val[3];
34309 val[4] = val[4] * 1 / 3 + val[2] * 2 / 3;
34310 val[3] = val[3] * 1 / 3 + val[1] * 2 / 3;
34311 val[2] = this.pos[1] * 1 / 3 + val[2] * 2 / 3;
34312 val[1] = this.pos[0] * 1 / 3 + val[1] * 2 / 3;
34313 break;
34314 case 'A':
34315 retVal = arcToBeziere(this.pos, val);
34316 val = retVal[0];
34317 break;
34318 }
34319 val[0] = 'C';
34320 this.pos = [val[5], val[6]];
34321 this.reflection = [2 * val[5] - val[3], 2 * val[6] - val[4]];
34322 return retVal;
34323 }
34324
34325 // finds the next position of type M
34326 function findNextM() {
34327 var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
34328 var offset = arguments.length > 1 ? arguments[1] : undefined;
34329 if (offset === false) return false;
34330 for (var i = offset, len = arr.length; i < len; ++i) {
34331 if (arr[i][0] == 'M') return i;
34332 }
34333 return false;
34334 }
34335
34336 // Convert an arc segment into equivalent cubic Bezier curves
34337 // Depending on the arc, up to 4 curves might be used to represent it since a
34338 // curve gives a good approximation for only a quarter of an ellipse
34339 // The curves are returned as an array of SVG curve commands:
34340 // [ ['C', x1, y1, x2, y2, x, y] ... ]
34341 function arcToBeziere(pos, val) {
34342 // Parameters extraction, handle out-of-range parameters as specified in the SVG spec
34343 // See: https://www.w3.org/TR/SVG11/implnote.html#ArcOutOfRangeParameters
34344 var rx = Math.abs(val[1]),
34345 ry = Math.abs(val[2]),
34346 xAxisRotation = val[3] % 360,
34347 largeArcFlag = val[4],
34348 sweepFlag = val[5],
34349 x = val[6],
34350 y = val[7],
34351 A = new Point(pos),
34352 B = new Point(x, y),
34353 primedCoord,
34354 lambda,
34355 mat,
34356 k,
34357 c,
34358 cSquare,
34359 t,
34360 O,
34361 OA,
34362 OB,
34363 tetaStart,
34364 tetaEnd,
34365 deltaTeta,
34366 nbSectors,
34367 f,
34368 arcSegPoints,
34369 angle,
34370 sinAngle,
34371 cosAngle,
34372 pt,
34373 i,
34374 il,
34375 retVal = [],
34376 x1,
34377 y1,
34378 x2,
34379 y2;
34380
34381 // Ensure radii are non-zero
34382 if (rx === 0 || ry === 0 || A.x === B.x && A.y === B.y) {
34383 // treat this arc as a straight line segment
34384 return [['C', A.x, A.y, B.x, B.y, B.x, B.y]];
34385 }
34386
34387 // Ensure radii are large enough using the algorithm provided in the SVG spec
34388 // See: https://www.w3.org/TR/SVG11/implnote.html#ArcCorrectionOutOfRangeRadii
34389 primedCoord = new Point((A.x - B.x) / 2, (A.y - B.y) / 2).transform(new Matrix().rotate(xAxisRotation));
34390 lambda = primedCoord.x * primedCoord.x / (rx * rx) + primedCoord.y * primedCoord.y / (ry * ry);
34391 if (lambda > 1) {
34392 lambda = Math.sqrt(lambda);
34393 rx = lambda * rx;
34394 ry = lambda * ry;
34395 }
34396
34397 // To simplify calculations, we make the arc part of a unit circle (rayon is 1) instead of an ellipse
34398 mat = new Matrix().rotate(xAxisRotation).scale(1 / rx, 1 / ry).rotate(-xAxisRotation);
34399 A = A.transform(mat);
34400 B = B.transform(mat);
34401
34402 // Calculate the horizontal and vertical distance between the initial and final point of the arc
34403 k = [B.x - A.x, B.y - A.y];
34404
34405 // Find the length of the chord formed by A and B
34406 cSquare = k[0] * k[0] + k[1] * k[1];
34407 c = Math.sqrt(cSquare);
34408
34409 // Calculate the ratios of the horizontal and vertical distance on the length of the chord
34410 k[0] /= c;
34411 k[1] /= c;
34412
34413 // Calculate the distance between the circle center and the chord midpoint
34414 // using this formula: t = sqrt(r^2 - c^2 / 4)
34415 // where t is the distance between the cirle center and the chord midpoint,
34416 // r is the rayon of the circle and c is the chord length
34417 // From: http://www.ajdesigner.com/phpcircle/circle_segment_chord_t.php
34418 // Because of the imprecision of floating point numbers, cSquare might end
34419 // up being slightly above 4 which would result in a negative radicand
34420 // To prevent that, a test is made before computing the square root
34421 t = cSquare < 4 ? Math.sqrt(1 - cSquare / 4) : 0;
34422
34423 // For most situations, there are actually two different ellipses that
34424 // satisfy the constraints imposed by the points A and B, the radii rx and ry,
34425 // and the xAxisRotation
34426 // When the flags largeArcFlag and sweepFlag are equal, it means that the
34427 // second ellipse is used as a solution
34428 // See: https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
34429 if (largeArcFlag === sweepFlag) {
34430 t *= -1;
34431 }
34432
34433 // Calculate the coordinates of the center of the circle from the midpoint of the chord
34434 // This is done by multiplying the ratios calculated previously by the distance between
34435 // the circle center and the chord midpoint and using these values to go from the midpoint
34436 // to the center of the circle
34437 // The negative of the vertical distance ratio is used to modify the x coordinate while
34438 // the horizontal distance ratio is used to modify the y coordinate
34439 // That is because the center of the circle is perpendicular to the chord and perpendicular
34440 // lines are negative reciprocals
34441 O = new Point((B.x + A.x) / 2 + t * -k[1], (B.y + A.y) / 2 + t * k[0]);
34442 // Move the center of the circle at the origin
34443 OA = new Point(A.x - O.x, A.y - O.y);
34444 OB = new Point(B.x - O.x, B.y - O.y);
34445
34446 // Calculate the start and end angle
34447 tetaStart = Math.acos(OA.x / Math.sqrt(OA.x * OA.x + OA.y * OA.y));
34448 if (OA.y < 0) {
34449 tetaStart *= -1;
34450 }
34451 tetaEnd = Math.acos(OB.x / Math.sqrt(OB.x * OB.x + OB.y * OB.y));
34452 if (OB.y < 0) {
34453 tetaEnd *= -1;
34454 }
34455
34456 // If sweep-flag is '1', then the arc will be drawn in a "positive-angle" direction,
34457 // make sure that the end angle is above the start angle
34458 if (sweepFlag && tetaStart > tetaEnd) {
34459 tetaEnd += 2 * Math.PI;
34460 }
34461 // If sweep-flag is '0', then the arc will be drawn in a "negative-angle" direction,
34462 // make sure that the end angle is below the start angle
34463 if (!sweepFlag && tetaStart < tetaEnd) {
34464 tetaEnd -= 2 * Math.PI;
34465 }
34466
34467 // Find the number of Bezier curves that are required to represent the arc
34468 // A cubic Bezier curve gives a good enough approximation when representing at most a quarter of a circle
34469 nbSectors = Math.ceil(Math.abs(tetaStart - tetaEnd) * 2 / Math.PI);
34470
34471 // Calculate the coordinates of the points of all the Bezier curves required to represent the arc
34472 // For an in-depth explanation of this part see: http://pomax.github.io/bezierinfo/#circles_cubic
34473 arcSegPoints = [];
34474 angle = tetaStart;
34475 deltaTeta = (tetaEnd - tetaStart) / nbSectors;
34476 f = 4 * Math.tan(deltaTeta / 4) / 3;
34477 for (i = 0; i <= nbSectors; i++) {
34478 // The <= is because a Bezier curve have a start and a endpoint
34479 cosAngle = Math.cos(angle);
34480 sinAngle = Math.sin(angle);
34481 pt = new Point(O.x + cosAngle, O.y + sinAngle);
34482 arcSegPoints[i] = [new Point(pt.x + f * sinAngle, pt.y - f * cosAngle), pt, new Point(pt.x - f * sinAngle, pt.y + f * cosAngle)];
34483 angle += deltaTeta;
34484 }
34485
34486 // Remove the first control point of the first segment point and remove the second control point of the last segment point
34487 // These two control points are not used in the approximation of the arc, that is why they are removed
34488 arcSegPoints[0][0] = arcSegPoints[0][1].clone();
34489 arcSegPoints[arcSegPoints.length - 1][2] = arcSegPoints[arcSegPoints.length - 1][1].clone();
34490
34491 // Revert the transformation that was applied to make the arc part of a unit circle instead of an ellipse
34492 mat = new Matrix().rotate(xAxisRotation).scale(rx, ry).rotate(-xAxisRotation);
34493 for (i = 0, il = arcSegPoints.length; i < il; i++) {
34494 arcSegPoints[i][0] = arcSegPoints[i][0].transform(mat);
34495 arcSegPoints[i][1] = arcSegPoints[i][1].transform(mat);
34496 arcSegPoints[i][2] = arcSegPoints[i][2].transform(mat);
34497 }
34498
34499 // Convert the segments points to SVG curve commands
34500 for (i = 1, il = arcSegPoints.length; i < il; i++) {
34501 pt = arcSegPoints[i - 1][2];
34502 x1 = pt.x;
34503 y1 = pt.y;
34504 pt = arcSegPoints[i][0];
34505 x2 = pt.x;
34506 y2 = pt.y;
34507 pt = arcSegPoints[i][1];
34508 x = pt.x;
34509 y = pt.y;
34510 retVal.push(['C', x1, y1, x2, y2, x, y]);
34511 }
34512 return retVal;
34513 }
34514 })();
34515
34516 const getCoordsFromEvent$1 = (ev) => {
34517 if (ev.changedTouches) {
34518 ev = ev.changedTouches[0];
34519 }
34520 return { x: ev.clientX, y: ev.clientY }
34521 };
34522
34523 // Creates handler, saves it
34524 class DragHandler {
34525 constructor(el) {
34526 el.remember('_draggable', this);
34527 this.el = el;
34528
34529 this.drag = this.drag.bind(this);
34530 this.startDrag = this.startDrag.bind(this);
34531 this.endDrag = this.endDrag.bind(this);
34532 }
34533
34534 // Enables or disabled drag based on input
34535 init(enabled) {
34536 if (enabled) {
34537 this.el.on('mousedown.drag', this.startDrag);
34538 this.el.on('touchstart.drag', this.startDrag, { passive: false });
34539 } else {
34540 this.el.off('mousedown.drag');
34541 this.el.off('touchstart.drag');
34542 }
34543 }
34544
34545 // Start dragging
34546 startDrag(ev) {
34547 const isMouse = !ev.type.indexOf('mouse');
34548
34549 // Check for left button
34550 if (isMouse && ev.which !== 1 && ev.buttons !== 0) {
34551 return
34552 }
34553
34554 // Fire beforedrag event
34555 if (
34556 this.el.dispatch('beforedrag', { event: ev, handler: this })
34557 .defaultPrevented
34558 ) {
34559 return
34560 }
34561
34562 // Prevent browser drag behavior as soon as possible
34563 ev.preventDefault();
34564
34565 // Prevent propagation to a parent that might also have dragging enabled
34566 ev.stopPropagation();
34567
34568 // Make sure that start events are unbound so that one element
34569 // is only dragged by one input only
34570 this.init(false);
34571
34572 this.box = this.el.bbox();
34573 this.lastClick = this.el.point(getCoordsFromEvent$1(ev));
34574
34575 const eventMove = (isMouse ? 'mousemove' : 'touchmove') + '.drag';
34576 const eventEnd = (isMouse ? 'mouseup' : 'touchend') + '.drag';
34577
34578 // Bind drag and end events to window
34579 on(window, eventMove, this.drag, this, { passive: false });
34580 on(window, eventEnd, this.endDrag, this, { passive: false });
34581
34582 // Fire dragstart event
34583 this.el.fire('dragstart', { event: ev, handler: this, box: this.box });
34584 }
34585
34586 // While dragging
34587 drag(ev) {
34588 const { box, lastClick } = this;
34589
34590 const currentClick = this.el.point(getCoordsFromEvent$1(ev));
34591 const dx = currentClick.x - lastClick.x;
34592 const dy = currentClick.y - lastClick.y;
34593
34594 if (!dx && !dy) return box
34595
34596 const x = box.x + dx;
34597 const y = box.y + dy;
34598 this.box = new Box(x, y, box.w, box.h);
34599 this.lastClick = currentClick;
34600
34601 if (
34602 this.el.dispatch('dragmove', {
34603 event: ev,
34604 handler: this,
34605 box: this.box,
34606 }).defaultPrevented
34607 ) {
34608 return
34609 }
34610
34611 this.move(x, y);
34612 }
34613
34614 move(x, y) {
34615 // Svg elements bbox depends on their content even though they have
34616 // x, y, width and height - strange!
34617 // Thats why we handle them the same as groups
34618 if (this.el.type === 'svg') {
34619 G.prototype.move.call(this.el, x, y);
34620 } else {
34621 this.el.move(x, y);
34622 }
34623 }
34624
34625 endDrag(ev) {
34626 // final drag
34627 this.drag(ev);
34628
34629 // fire dragend event
34630 this.el.fire('dragend', { event: ev, handler: this, box: this.box });
34631
34632 // unbind events
34633 off(window, 'mousemove.drag');
34634 off(window, 'touchmove.drag');
34635 off(window, 'mouseup.drag');
34636 off(window, 'touchend.drag');
34637
34638 // Rebind initial Events
34639 this.init(true);
34640 }
34641 }
34642
34643 extend(Element$1, {
34644 draggable(enable = true) {
34645 const dragHandler = this.remember('_draggable') || new DragHandler(this);
34646 dragHandler.init(enable);
34647 return this
34648 },
34649 });
34650
34651 /*!
34652 * @svgdotjs/svg.select.js - An extension of svg.js which allows to select elements with mouse
34653 * @version 4.0.1
34654 * https://github.com/svgdotjs/svg.select.js
34655 *
34656 * @copyright Ulrich-Matthias Schäfer
34657 * @license MIT
34658 *
34659 * BUILT: Mon Jul 01 2024 15:04:42 GMT+0200 (Central European Summer Time)
34660 */
34661 function getMoseDownFunc$1(eventName, el, points, index = null) {
34662 return function(ev) {
34663 ev.preventDefault();
34664 ev.stopPropagation();
34665 var x = ev.pageX || ev.touches[0].pageX;
34666 var y = ev.pageY || ev.touches[0].pageY;
34667 el.fire(eventName, { x, y, event: ev, index, points });
34668 };
34669 }
34670 function transformPoint$1([x, y], { a, b, c, d, e, f }) {
34671 return [x * a + y * c + e, x * b + y * d + f];
34672 }
34673 let SelectHandler$1 = class SelectHandler {
34674 constructor(el) {
34675 this.el = el;
34676 el.remember("_selectHandler", this);
34677 this.selection = new G();
34678 this.order = ["lt", "t", "rt", "r", "rb", "b", "lb", "l", "rot"];
34679 this.mutationHandler = this.mutationHandler.bind(this);
34680 const win = getWindow();
34681 this.observer = new win.MutationObserver(this.mutationHandler);
34682 }
34683 init(options) {
34684 this.createHandle = options.createHandle || this.createHandleFn;
34685 this.createRot = options.createRot || this.createRotFn;
34686 this.updateHandle = options.updateHandle || this.updateHandleFn;
34687 this.updateRot = options.updateRot || this.updateRotFn;
34688 this.el.root().put(this.selection);
34689 this.updatePoints();
34690 this.createSelection();
34691 this.createResizeHandles();
34692 this.updateResizeHandles();
34693 this.createRotationHandle();
34694 this.updateRotationHandle();
34695 this.observer.observe(this.el.node, { attributes: true });
34696 }
34697 active(val, options) {
34698 if (!val) {
34699 this.selection.clear().remove();
34700 this.observer.disconnect();
34701 return;
34702 }
34703 this.init(options);
34704 }
34705 createSelection() {
34706 this.selection.polygon(this.handlePoints).addClass("svg_select_shape");
34707 }
34708 updateSelection() {
34709 this.selection.get(0).plot(this.handlePoints);
34710 }
34711 createResizeHandles() {
34712 this.handlePoints.forEach((p, index, arr) => {
34713 const name = this.order[index];
34714 this.createHandle.call(this, this.selection, p, index, arr, name);
34715 this.selection.get(index + 1).addClass("svg_select_handle svg_select_handle_" + name).on("mousedown.selection touchstart.selection", getMoseDownFunc$1(name, this.el, this.handlePoints, index));
34716 });
34717 }
34718 createHandleFn(group) {
34719 group.polyline();
34720 }
34721 updateHandleFn(shape, point, index, arr) {
34722 const before = arr.at(index - 1);
34723 const next = arr[(index + 1) % arr.length];
34724 const p = point;
34725 const diff1 = [p[0] - before[0], p[1] - before[1]];
34726 const diff2 = [p[0] - next[0], p[1] - next[1]];
34727 const len1 = Math.sqrt(diff1[0] * diff1[0] + diff1[1] * diff1[1]);
34728 const len2 = Math.sqrt(diff2[0] * diff2[0] + diff2[1] * diff2[1]);
34729 const normalized1 = [diff1[0] / len1, diff1[1] / len1];
34730 const normalized2 = [diff2[0] / len2, diff2[1] / len2];
34731 const beforeNew = [p[0] - normalized1[0] * 10, p[1] - normalized1[1] * 10];
34732 const nextNew = [p[0] - normalized2[0] * 10, p[1] - normalized2[1] * 10];
34733 shape.plot([beforeNew, p, nextNew]);
34734 }
34735 updateResizeHandles() {
34736 this.handlePoints.forEach((p, index, arr) => {
34737 const name = this.order[index];
34738 this.updateHandle.call(this, this.selection.get(index + 1), p, index, arr, name);
34739 });
34740 }
34741 createRotFn(group) {
34742 group.line();
34743 group.circle(5);
34744 }
34745 getPoint(name) {
34746 return this.handlePoints[this.order.indexOf(name)];
34747 }
34748 getPointHandle(name) {
34749 return this.selection.get(this.order.indexOf(name) + 1);
34750 }
34751 updateRotFn(group, rotPoint) {
34752 const topPoint = this.getPoint("t");
34753 group.get(0).plot(topPoint[0], topPoint[1], rotPoint[0], rotPoint[1]);
34754 group.get(1).center(rotPoint[0], rotPoint[1]);
34755 }
34756 createRotationHandle() {
34757 const handle = this.selection.group().addClass("svg_select_handle_rot").on("mousedown.selection touchstart.selection", getMoseDownFunc$1("rot", this.el, this.handlePoints));
34758 this.createRot.call(this, handle);
34759 }
34760 updateRotationHandle() {
34761 const group = this.selection.findOne("g.svg_select_handle_rot");
34762 this.updateRot(group, this.rotationPoint, this.handlePoints);
34763 }
34764 // gets new bounding box points and transform them into the elements space
34765 updatePoints() {
34766 const bbox = this.el.bbox();
34767 const fromShapeToUiMatrix = this.el.parent().screenCTM().inverseO().multiplyO(this.el.screenCTM());
34768 this.handlePoints = this.getHandlePoints(bbox).map((p) => transformPoint$1(p, fromShapeToUiMatrix));
34769 this.rotationPoint = transformPoint$1(this.getRotationPoint(bbox), fromShapeToUiMatrix);
34770 }
34771 // A collection of all the points we need to draw our ui
34772 getHandlePoints({ x, x2, y, y2, cx, cy } = this.el.bbox()) {
34773 return [
34774 [x, y],
34775 [cx, y],
34776 [x2, y],
34777 [x2, cy],
34778 [x2, y2],
34779 [cx, y2],
34780 [x, y2],
34781 [x, cy]
34782 ];
34783 }
34784 // A collection of all the points we need to draw our ui
34785 getRotationPoint({ y, cx } = this.el.bbox()) {
34786 return [cx, y - 20];
34787 }
34788 mutationHandler() {
34789 this.updatePoints();
34790 this.updateSelection();
34791 this.updateResizeHandles();
34792 this.updateRotationHandle();
34793 }
34794 };
34795 let PointSelectHandler$1 = class PointSelectHandler {
34796 constructor(el) {
34797 this.el = el;
34798 el.remember("_pointSelectHandler", this);
34799 this.selection = new G();
34800 this.order = ["lt", "t", "rt", "r", "rb", "b", "lb", "l", "rot"];
34801 this.mutationHandler = this.mutationHandler.bind(this);
34802 const win = getWindow();
34803 this.observer = new win.MutationObserver(this.mutationHandler);
34804 }
34805 init(options) {
34806 this.createHandle = options.createHandle || this.createHandleFn;
34807 this.updateHandle = options.updateHandle || this.updateHandleFn;
34808 this.el.root().put(this.selection);
34809 this.updatePoints();
34810 this.createSelection();
34811 this.createPointHandles();
34812 this.updatePointHandles();
34813 this.observer.observe(this.el.node, { attributes: true });
34814 }
34815 active(val, options) {
34816 if (!val) {
34817 this.selection.clear().remove();
34818 this.observer.disconnect();
34819 return;
34820 }
34821 this.init(options);
34822 }
34823 createSelection() {
34824 this.selection.polygon(this.points).addClass("svg_select_shape_pointSelect");
34825 }
34826 updateSelection() {
34827 this.selection.get(0).plot(this.points);
34828 }
34829 createPointHandles() {
34830 this.points.forEach((p, index, arr) => {
34831 this.createHandle.call(this, this.selection, p, index, arr);
34832 this.selection.get(index + 1).addClass("svg_select_handle_point").on("mousedown.selection touchstart.selection", getMoseDownFunc$1("point", this.el, this.points, index));
34833 });
34834 }
34835 createHandleFn(group) {
34836 group.circle(5);
34837 }
34838 updateHandleFn(shape, point) {
34839 shape.center(point[0], point[1]);
34840 }
34841 updatePointHandles() {
34842 this.points.forEach((p, index, arr) => {
34843 this.updateHandle.call(this, this.selection.get(index + 1), p, index, arr);
34844 });
34845 }
34846 // gets new bounding box points and transform them into the elements space
34847 updatePoints() {
34848 const fromShapeToUiMatrix = this.el.parent().screenCTM().inverseO().multiplyO(this.el.screenCTM());
34849 this.points = this.el.array().map((p) => transformPoint$1(p, fromShapeToUiMatrix));
34850 }
34851 mutationHandler() {
34852 this.updatePoints();
34853 this.updateSelection();
34854 this.updatePointHandles();
34855 }
34856 };
34857 const getSelectFn$1 = (handleClass) => {
34858 return function(enabled = true, options = {}) {
34859 if (typeof enabled === "object") {
34860 options = enabled;
34861 enabled = true;
34862 }
34863 let selectHandler = this.remember("_" + handleClass.name);
34864 if (!selectHandler) {
34865 if (enabled.prototype instanceof SelectHandler$1) {
34866 selectHandler = new enabled(this);
34867 enabled = true;
34868 } else {
34869 selectHandler = new handleClass(this);
34870 }
34871 this.remember("_" + handleClass.name, selectHandler);
34872 }
34873 selectHandler.active(enabled, options);
34874 return this;
34875 };
34876 };
34877 extend(Element$1, {
34878 select: getSelectFn$1(SelectHandler$1)
34879 });
34880 extend([Polygon, Polyline, Line$1], {
34881 pointSelect: getSelectFn$1(PointSelectHandler$1)
34882 });
34883
34884 /*!
34885 * @svgdotjs/svg.resize.js - An extension for svg.js which allows to resize elements which are selected
34886 * @version 2.0.4
34887 * https://github.com/svgdotjs/svg.resize.js
34888 *
34889 * @copyright [object Object]
34890 * @license MIT
34891 *
34892 * BUILT: Fri Sep 13 2024 12:43:14 GMT+0200 (Central European Summer Time)
34893 */
34894 /*!
34895 * @svgdotjs/svg.select.js - An extension of svg.js which allows to select elements with mouse
34896 * @version 4.0.1
34897 * https://github.com/svgdotjs/svg.select.js
34898 *
34899 * @copyright Ulrich-Matthias Schäfer
34900 * @license MIT
34901 *
34902 * BUILT: Mon Jul 01 2024 15:04:42 GMT+0200 (Central European Summer Time)
34903 */
34904 function getMoseDownFunc(eventName, el, points, index = null) {
34905 return function(ev) {
34906 ev.preventDefault();
34907 ev.stopPropagation();
34908 var x = ev.pageX || ev.touches[0].pageX;
34909 var y = ev.pageY || ev.touches[0].pageY;
34910 el.fire(eventName, { x, y, event: ev, index, points });
34911 };
34912 }
34913 function transformPoint([x, y], { a, b, c, d, e, f }) {
34914 return [x * a + y * c + e, x * b + y * d + f];
34915 }
34916 class SelectHandler {
34917 constructor(el) {
34918 this.el = el;
34919 el.remember("_selectHandler", this);
34920 this.selection = new G();
34921 this.order = ["lt", "t", "rt", "r", "rb", "b", "lb", "l", "rot"];
34922 this.mutationHandler = this.mutationHandler.bind(this);
34923 const win = getWindow();
34924 this.observer = new win.MutationObserver(this.mutationHandler);
34925 }
34926 init(options) {
34927 this.createHandle = options.createHandle || this.createHandleFn;
34928 this.createRot = options.createRot || this.createRotFn;
34929 this.updateHandle = options.updateHandle || this.updateHandleFn;
34930 this.updateRot = options.updateRot || this.updateRotFn;
34931 this.el.root().put(this.selection);
34932 this.updatePoints();
34933 this.createSelection();
34934 this.createResizeHandles();
34935 this.updateResizeHandles();
34936 this.createRotationHandle();
34937 this.updateRotationHandle();
34938 this.observer.observe(this.el.node, { attributes: true });
34939 }
34940 active(val, options) {
34941 if (!val) {
34942 this.selection.clear().remove();
34943 this.observer.disconnect();
34944 return;
34945 }
34946 this.init(options);
34947 }
34948 createSelection() {
34949 this.selection.polygon(this.handlePoints).addClass("svg_select_shape");
34950 }
34951 updateSelection() {
34952 this.selection.get(0).plot(this.handlePoints);
34953 }
34954 createResizeHandles() {
34955 this.handlePoints.forEach((p, index, arr) => {
34956 const name = this.order[index];
34957 this.createHandle.call(this, this.selection, p, index, arr, name);
34958 this.selection.get(index + 1).addClass("svg_select_handle svg_select_handle_" + name).on("mousedown.selection touchstart.selection", getMoseDownFunc(name, this.el, this.handlePoints, index));
34959 });
34960 }
34961 createHandleFn(group) {
34962 group.polyline();
34963 }
34964 updateHandleFn(shape, point, index, arr) {
34965 const before = arr.at(index - 1);
34966 const next = arr[(index + 1) % arr.length];
34967 const p = point;
34968 const diff1 = [p[0] - before[0], p[1] - before[1]];
34969 const diff2 = [p[0] - next[0], p[1] - next[1]];
34970 const len1 = Math.sqrt(diff1[0] * diff1[0] + diff1[1] * diff1[1]);
34971 const len2 = Math.sqrt(diff2[0] * diff2[0] + diff2[1] * diff2[1]);
34972 const normalized1 = [diff1[0] / len1, diff1[1] / len1];
34973 const normalized2 = [diff2[0] / len2, diff2[1] / len2];
34974 const beforeNew = [p[0] - normalized1[0] * 10, p[1] - normalized1[1] * 10];
34975 const nextNew = [p[0] - normalized2[0] * 10, p[1] - normalized2[1] * 10];
34976 shape.plot([beforeNew, p, nextNew]);
34977 }
34978 updateResizeHandles() {
34979 this.handlePoints.forEach((p, index, arr) => {
34980 const name = this.order[index];
34981 this.updateHandle.call(this, this.selection.get(index + 1), p, index, arr, name);
34982 });
34983 }
34984 createRotFn(group) {
34985 group.line();
34986 group.circle(5);
34987 }
34988 getPoint(name) {
34989 return this.handlePoints[this.order.indexOf(name)];
34990 }
34991 getPointHandle(name) {
34992 return this.selection.get(this.order.indexOf(name) + 1);
34993 }
34994 updateRotFn(group, rotPoint) {
34995 const topPoint = this.getPoint("t");
34996 group.get(0).plot(topPoint[0], topPoint[1], rotPoint[0], rotPoint[1]);
34997 group.get(1).center(rotPoint[0], rotPoint[1]);
34998 }
34999 createRotationHandle() {
35000 const handle = this.selection.group().addClass("svg_select_handle_rot").on("mousedown.selection touchstart.selection", getMoseDownFunc("rot", this.el, this.handlePoints));
35001 this.createRot.call(this, handle);
35002 }
35003 updateRotationHandle() {
35004 const group = this.selection.findOne("g.svg_select_handle_rot");
35005 this.updateRot(group, this.rotationPoint, this.handlePoints);
35006 }
35007 // gets new bounding box points and transform them into the elements space
35008 updatePoints() {
35009 const bbox = this.el.bbox();
35010 const fromShapeToUiMatrix = this.el.parent().screenCTM().inverseO().multiplyO(this.el.screenCTM());
35011 this.handlePoints = this.getHandlePoints(bbox).map((p) => transformPoint(p, fromShapeToUiMatrix));
35012 this.rotationPoint = transformPoint(this.getRotationPoint(bbox), fromShapeToUiMatrix);
35013 }
35014 // A collection of all the points we need to draw our ui
35015 getHandlePoints({ x, x2, y, y2, cx, cy } = this.el.bbox()) {
35016 return [
35017 [x, y],
35018 [cx, y],
35019 [x2, y],
35020 [x2, cy],
35021 [x2, y2],
35022 [cx, y2],
35023 [x, y2],
35024 [x, cy]
35025 ];
35026 }
35027 // A collection of all the points we need to draw our ui
35028 getRotationPoint({ y, cx } = this.el.bbox()) {
35029 return [cx, y - 20];
35030 }
35031 mutationHandler() {
35032 this.updatePoints();
35033 this.updateSelection();
35034 this.updateResizeHandles();
35035 this.updateRotationHandle();
35036 }
35037 }
35038 class PointSelectHandler {
35039 constructor(el) {
35040 this.el = el;
35041 el.remember("_pointSelectHandler", this);
35042 this.selection = new G();
35043 this.order = ["lt", "t", "rt", "r", "rb", "b", "lb", "l", "rot"];
35044 this.mutationHandler = this.mutationHandler.bind(this);
35045 const win = getWindow();
35046 this.observer = new win.MutationObserver(this.mutationHandler);
35047 }
35048 init(options) {
35049 this.createHandle = options.createHandle || this.createHandleFn;
35050 this.updateHandle = options.updateHandle || this.updateHandleFn;
35051 this.el.root().put(this.selection);
35052 this.updatePoints();
35053 this.createSelection();
35054 this.createPointHandles();
35055 this.updatePointHandles();
35056 this.observer.observe(this.el.node, { attributes: true });
35057 }
35058 active(val, options) {
35059 if (!val) {
35060 this.selection.clear().remove();
35061 this.observer.disconnect();
35062 return;
35063 }
35064 this.init(options);
35065 }
35066 createSelection() {
35067 this.selection.polygon(this.points).addClass("svg_select_shape_pointSelect");
35068 }
35069 updateSelection() {
35070 this.selection.get(0).plot(this.points);
35071 }
35072 createPointHandles() {
35073 this.points.forEach((p, index, arr) => {
35074 this.createHandle.call(this, this.selection, p, index, arr);
35075 this.selection.get(index + 1).addClass("svg_select_handle_point").on("mousedown.selection touchstart.selection", getMoseDownFunc("point", this.el, this.points, index));
35076 });
35077 }
35078 createHandleFn(group) {
35079 group.circle(5);
35080 }
35081 updateHandleFn(shape, point) {
35082 shape.center(point[0], point[1]);
35083 }
35084 updatePointHandles() {
35085 this.points.forEach((p, index, arr) => {
35086 this.updateHandle.call(this, this.selection.get(index + 1), p, index, arr);
35087 });
35088 }
35089 // gets new bounding box points and transform them into the elements space
35090 updatePoints() {
35091 const fromShapeToUiMatrix = this.el.parent().screenCTM().inverseO().multiplyO(this.el.screenCTM());
35092 this.points = this.el.array().map((p) => transformPoint(p, fromShapeToUiMatrix));
35093 }
35094 mutationHandler() {
35095 this.updatePoints();
35096 this.updateSelection();
35097 this.updatePointHandles();
35098 }
35099 }
35100 const getSelectFn = (handleClass) => {
35101 return function(enabled = true, options = {}) {
35102 if (typeof enabled === "object") {
35103 options = enabled;
35104 enabled = true;
35105 }
35106 let selectHandler = this.remember("_" + handleClass.name);
35107 if (!selectHandler) {
35108 if (enabled.prototype instanceof SelectHandler) {
35109 selectHandler = new enabled(this);
35110 enabled = true;
35111 } else {
35112 selectHandler = new handleClass(this);
35113 }
35114 this.remember("_" + handleClass.name, selectHandler);
35115 }
35116 selectHandler.active(enabled, options);
35117 return this;
35118 };
35119 };
35120 extend(Element$1, {
35121 select: getSelectFn(SelectHandler)
35122 });
35123 extend([Polygon, Polyline, Line$1], {
35124 pointSelect: getSelectFn(PointSelectHandler)
35125 });
35126 const getCoordsFromEvent = (ev) => {
35127 if (ev.changedTouches) {
35128 ev = ev.changedTouches[0];
35129 }
35130 return { x: ev.clientX, y: ev.clientY };
35131 };
35132 const maxBoxFromPoints = (points) => {
35133 let x = Infinity;
35134 let y = Infinity;
35135 let x2 = -Infinity;
35136 let y2 = -Infinity;
35137 for (let i = 0; i < points.length; i++) {
35138 const p = points[i];
35139 x = Math.min(x, p[0]);
35140 y = Math.min(y, p[1]);
35141 x2 = Math.max(x2, p[0]);
35142 y2 = Math.max(y2, p[1]);
35143 }
35144 return new Box(x, y, x2 - x, y2 - y);
35145 };
35146 function scaleBox(box, origin, scale) {
35147 const points = [
35148 [box.x, box.y],
35149 [box.x + box.width, box.y],
35150 [box.x + box.width, box.y + box.height],
35151 [box.x, box.y + box.height]
35152 ];
35153 const newPoints = points.map(([x, y]) => {
35154 const translatedX = x - origin[0];
35155 const translatedY = y - origin[1];
35156 const scaledX = translatedX * scale;
35157 const scaledY = translatedY * scale;
35158 return [scaledX + origin[0], scaledY + origin[1]];
35159 });
35160 return maxBoxFromPoints(newPoints);
35161 }
35162 class ResizeHandler {
35163 constructor(el) {
35164 this.el = el;
35165 el.remember("_ResizeHandler", this);
35166 this.lastCoordinates = null;
35167 this.eventType = "";
35168 this.lastEvent = null;
35169 this.handleResize = this.handleResize.bind(this);
35170 this.resize = this.resize.bind(this);
35171 this.endResize = this.endResize.bind(this);
35172 this.rotate = this.rotate.bind(this);
35173 this.movePoint = this.movePoint.bind(this);
35174 }
35175 active(value, options) {
35176 this.preserveAspectRatio = options.preserveAspectRatio ?? false;
35177 this.aroundCenter = options.aroundCenter ?? false;
35178 this.grid = options.grid ?? 0;
35179 this.degree = options.degree ?? 0;
35180 this.el.off(".resize");
35181 if (!value) return;
35182 this.el.on(
35183 [
35184 "lt.resize",
35185 "rt.resize",
35186 "rb.resize",
35187 "lb.resize",
35188 "t.resize",
35189 "r.resize",
35190 "b.resize",
35191 "l.resize",
35192 "rot.resize",
35193 "point.resize"
35194 ],
35195 this.handleResize
35196 );
35197 if (this.lastEvent) {
35198 if (this.eventType === "rot") {
35199 this.rotate(this.lastEvent);
35200 } else if (this.eventType === "point") {
35201 this.movePoint(this.lastEvent);
35202 } else {
35203 this.resize(this.lastEvent);
35204 }
35205 }
35206 }
35207 // This is called when a user clicks on one of the resize points
35208 handleResize(e) {
35209 this.eventType = e.type;
35210 const { event, index, points } = e.detail;
35211 const isMouse = !event.type.indexOf("mouse");
35212 if (isMouse && (event.which || event.buttons) !== 1) {
35213 return;
35214 }
35215 if (this.el.dispatch("beforeresize", { event: e, handler: this }).defaultPrevented) {
35216 return;
35217 }
35218 this.box = this.el.bbox();
35219 this.startPoint = this.el.point(getCoordsFromEvent(event));
35220 this.index = index;
35221 this.points = points.slice();
35222 const eventMove = (isMouse ? "mousemove" : "touchmove") + ".resize";
35223 const eventEnd = (isMouse ? "mouseup" : "touchcancel.resize touchend") + ".resize";
35224 if (e.type === "point") {
35225 on(window, eventMove, this.movePoint);
35226 } else if (e.type === "rot") {
35227 on(window, eventMove, this.rotate);
35228 } else {
35229 on(window, eventMove, this.resize);
35230 }
35231 on(window, eventEnd, this.endResize);
35232 }
35233 resize(e) {
35234 this.lastEvent = e;
35235 const endPoint = this.snapToGrid(this.el.point(getCoordsFromEvent(e)));
35236 let dx = endPoint.x - this.startPoint.x;
35237 let dy = endPoint.y - this.startPoint.y;
35238 if (this.preserveAspectRatio && this.aroundCenter) {
35239 dx *= 2;
35240 dy *= 2;
35241 }
35242 const x = this.box.x + dx;
35243 const y = this.box.y + dy;
35244 const x2 = this.box.x2 + dx;
35245 const y2 = this.box.y2 + dy;
35246 let box = new Box(this.box);
35247 if (this.eventType.includes("l")) {
35248 box.x = Math.min(x, this.box.x2);
35249 box.x2 = Math.max(x, this.box.x2);
35250 }
35251 if (this.eventType.includes("r")) {
35252 box.x = Math.min(x2, this.box.x);
35253 box.x2 = Math.max(x2, this.box.x);
35254 }
35255 if (this.eventType.includes("t")) {
35256 box.y = Math.min(y, this.box.y2);
35257 box.y2 = Math.max(y, this.box.y2);
35258 }
35259 if (this.eventType.includes("b")) {
35260 box.y = Math.min(y2, this.box.y);
35261 box.y2 = Math.max(y2, this.box.y);
35262 }
35263 box.width = box.x2 - box.x;
35264 box.height = box.y2 - box.y;
35265 if (this.preserveAspectRatio) {
35266 const scaleX = box.width / this.box.width;
35267 const scaleY = box.height / this.box.height;
35268 const order = ["lt", "t", "rt", "r", "rb", "b", "lb", "l"];
35269 const origin = (order.indexOf(this.eventType) + 4) % order.length;
35270 const constantPoint = this.aroundCenter ? [this.box.cx, this.box.cy] : this.points[origin];
35271 let scale = this.eventType.includes("t") || this.eventType.includes("b") ? scaleY : scaleX;
35272 scale = this.eventType.length === 2 ? Math.max(scaleX, scaleY) : scale;
35273 box = scaleBox(this.box, constantPoint, scale);
35274 }
35275 if (this.el.dispatch("resize", {
35276 box: new Box(box),
35277 angle: 0,
35278 eventType: this.eventType,
35279 event: e,
35280 handler: this
35281 }).defaultPrevented) {
35282 return;
35283 }
35284 this.el.size(box.width, box.height).move(box.x, box.y);
35285 }
35286 movePoint(e) {
35287 this.lastEvent = e;
35288 const { x, y } = this.snapToGrid(this.el.point(getCoordsFromEvent(e)));
35289 const pointArr = this.el.array().slice();
35290 pointArr[this.index] = [x, y];
35291 if (this.el.dispatch("resize", {
35292 box: maxBoxFromPoints(pointArr),
35293 angle: 0,
35294 eventType: this.eventType,
35295 event: e,
35296 handler: this
35297 }).defaultPrevented) {
35298 return;
35299 }
35300 this.el.plot(pointArr);
35301 }
35302 rotate(e) {
35303 this.lastEvent = e;
35304 const startPoint = this.startPoint;
35305 const endPoint = this.el.point(getCoordsFromEvent(e));
35306 const { cx, cy } = this.box;
35307 const dx1 = startPoint.x - cx;
35308 const dy1 = startPoint.y - cy;
35309 const dx2 = endPoint.x - cx;
35310 const dy2 = endPoint.y - cy;
35311 const c = Math.sqrt(dx1 * dx1 + dy1 * dy1) * Math.sqrt(dx2 * dx2 + dy2 * dy2);
35312 if (c === 0) {
35313 return;
35314 }
35315 let angle = Math.acos((dx1 * dx2 + dy1 * dy2) / c) / Math.PI * 180;
35316 if (!angle) return;
35317 if (endPoint.x < startPoint.x) {
35318 angle = -angle;
35319 }
35320 const matrix = new Matrix(this.el);
35321 const { x: ox, y: oy } = new Point(cx, cy).transformO(matrix);
35322 const { rotate } = matrix.decompose();
35323 const resultAngle = this.snapToAngle(rotate + angle) - rotate;
35324 if (this.el.dispatch("resize", {
35325 box: this.box,
35326 angle: resultAngle,
35327 eventType: this.eventType,
35328 event: e,
35329 handler: this
35330 }).defaultPrevented) {
35331 return;
35332 }
35333 this.el.transform(matrix.rotateO(resultAngle, ox, oy));
35334 }
35335 endResize(ev) {
35336 if (this.eventType !== "rot" && this.eventType !== "point") {
35337 this.resize(ev);
35338 }
35339 this.lastEvent = null;
35340 this.eventType = "";
35341 off(window, "mousemove.resize touchmove.resize");
35342 off(window, "mouseup.resize touchend.resize");
35343 }
35344 snapToGrid(point) {
35345 if (this.grid) {
35346 point.x = Math.round(point.x / this.grid) * this.grid;
35347 point.y = Math.round(point.y / this.grid) * this.grid;
35348 }
35349 return point;
35350 }
35351 snapToAngle(angle) {
35352 if (this.degree) {
35353 angle = Math.round(angle / this.degree) * this.degree;
35354 }
35355 return angle;
35356 }
35357 }
35358 extend(Element$1, {
35359 // Resize element with mouse
35360 resize: function(enabled = true, options = {}) {
35361 if (typeof enabled === "object") {
35362 options = enabled;
35363 enabled = true;
35364 }
35365 let resizeHandler = this.remember("_ResizeHandler");
35366 if (!resizeHandler) {
35367 if (enabled.prototype instanceof ResizeHandler) {
35368 resizeHandler = new enabled(this);
35369 enabled = true;
35370 } else {
35371 resizeHandler = new ResizeHandler(this);
35372 }
35373 this.remember("_resizeHandler", resizeHandler);
35374 }
35375 resizeHandler.active(enabled, options);
35376 return this;
35377 }
35378 });
35379
35380 if (typeof window.SVG === 'undefined') {
35381 window.SVG = SVG;
35382 }
35383
35384 // global Apex object which user can use to override chart's defaults globally
35385 if (typeof window.Apex === 'undefined') {
35386 window.Apex = {};
35387 }
35388 var InitCtxVariables = /*#__PURE__*/function () {
35389 function InitCtxVariables(ctx) {
35390 _classCallCheck(this, InitCtxVariables);
35391 this.ctx = ctx;
35392 this.w = ctx.w;
35393 }
35394 _createClass(InitCtxVariables, [{
35395 key: "initModules",
35396 value: function initModules() {
35397 this.ctx.publicMethods = ['updateOptions', 'updateSeries', 'appendData', 'appendSeries', 'isSeriesHidden', 'highlightSeries', 'toggleSeries', 'showSeries', 'hideSeries', 'setLocale', 'resetSeries', 'zoomX', 'toggleDataPointSelection', 'dataURI', 'exportToCSV', 'addXaxisAnnotation', 'addYaxisAnnotation', 'addPointAnnotation', 'clearAnnotations', 'removeAnnotation', 'paper', 'destroy'];
35398 this.ctx.eventList = ['click', 'mousedown', 'mousemove', 'mouseleave', 'touchstart', 'touchmove', 'touchleave', 'mouseup', 'touchend'];
35399 this.ctx.animations = new Animations(this.ctx);
35400 this.ctx.axes = new Axes(this.ctx);
35401 this.ctx.core = new Core(this.ctx.el, this.ctx);
35402 this.ctx.config = new Config({});
35403 this.ctx.data = new Data(this.ctx);
35404 this.ctx.grid = new Grid(this.ctx);
35405 this.ctx.graphics = new Graphics(this.ctx);
35406 this.ctx.coreUtils = new CoreUtils(this.ctx);
35407 this.ctx.crosshairs = new Crosshairs(this.ctx);
35408 this.ctx.events = new Events(this.ctx);
35409 this.ctx.exports = new Exports(this.ctx);
35410 this.ctx.fill = new Fill(this.ctx);
35411 this.ctx.localization = new Localization(this.ctx);
35412 this.ctx.options = new Options();
35413 this.ctx.responsive = new Responsive(this.ctx);
35414 this.ctx.series = new Series(this.ctx);
35415 this.ctx.theme = new Theme(this.ctx);
35416 this.ctx.formatters = new Formatters(this.ctx);
35417 this.ctx.titleSubtitle = new TitleSubtitle(this.ctx);
35418 this.ctx.legend = new Legend(this.ctx);
35419 this.ctx.toolbar = new Toolbar(this.ctx);
35420 this.ctx.tooltip = new Tooltip(this.ctx);
35421 this.ctx.dimensions = new Dimensions(this.ctx);
35422 this.ctx.updateHelpers = new UpdateHelpers(this.ctx);
35423 this.ctx.zoomPanSelection = new ZoomPanSelection(this.ctx);
35424 this.ctx.w.globals.tooltip = new Tooltip(this.ctx);
35425 }
35426 }]);
35427 return InitCtxVariables;
35428 }();
35429
35430 var Destroy = /*#__PURE__*/function () {
35431 function Destroy(ctx) {
35432 _classCallCheck(this, Destroy);
35433 this.ctx = ctx;
35434 this.w = ctx.w;
35435 }
35436 _createClass(Destroy, [{
35437 key: "clear",
35438 value: function clear(_ref) {
35439 var isUpdating = _ref.isUpdating;
35440 if (this.ctx.zoomPanSelection) {
35441 this.ctx.zoomPanSelection.destroy();
35442 }
35443 if (this.ctx.toolbar) {
35444 this.ctx.toolbar.destroy();
35445 }
35446 this.ctx.animations = null;
35447 this.ctx.axes = null;
35448 this.ctx.annotations = null;
35449 this.ctx.core = null;
35450 this.ctx.data = null;
35451 this.ctx.grid = null;
35452 this.ctx.series = null;
35453 this.ctx.responsive = null;
35454 this.ctx.theme = null;
35455 this.ctx.formatters = null;
35456 this.ctx.titleSubtitle = null;
35457 this.ctx.legend = null;
35458 this.ctx.dimensions = null;
35459 this.ctx.options = null;
35460 this.ctx.crosshairs = null;
35461 this.ctx.zoomPanSelection = null;
35462 this.ctx.updateHelpers = null;
35463 this.ctx.toolbar = null;
35464 this.ctx.localization = null;
35465 this.ctx.w.globals.tooltip = null;
35466 this.clearDomElements({
35467 isUpdating: isUpdating
35468 });
35469 }
35470 }, {
35471 key: "killSVG",
35472 value: function killSVG(draw) {
35473 draw.each(function () {
35474 this.removeClass('*');
35475 this.off();
35476 // this.stop()
35477 }, true);
35478 // draw.ungroup()
35479 draw.clear();
35480 }
35481 }, {
35482 key: "clearDomElements",
35483 value: function clearDomElements(_ref2) {
35484 var _this = this;
35485 var isUpdating = _ref2.isUpdating;
35486 var elSVG = this.w.globals.dom.Paper.node;
35487 // fixes apexcharts.js#1654 & vue-apexcharts#256
35488 if (elSVG.parentNode && elSVG.parentNode.parentNode && !isUpdating) {
35489 elSVG.parentNode.parentNode.style.minHeight = 'unset';
35490 }
35491
35492 // detach root event
35493 var baseEl = this.w.globals.dom.baseEl;
35494 if (baseEl) {
35495 // see https://github.com/apexcharts/vue-apexcharts/issues/275
35496 this.ctx.eventList.forEach(function (event) {
35497 baseEl.removeEventListener(event, _this.ctx.events.documentEvent);
35498 });
35499 }
35500 var domEls = this.w.globals.dom;
35501 if (this.ctx.el !== null) {
35502 // remove all child elements - resetting the whole chart
35503 while (this.ctx.el.firstChild) {
35504 this.ctx.el.removeChild(this.ctx.el.firstChild);
35505 }
35506 }
35507 this.killSVG(domEls.Paper);
35508 domEls.Paper.remove();
35509 domEls.elWrap = null;
35510 domEls.elGraphical = null;
35511 domEls.elLegendWrap = null;
35512 domEls.elLegendForeign = null;
35513 domEls.baseEl = null;
35514 domEls.elGridRect = null;
35515 domEls.elGridRectMask = null;
35516 domEls.elGridRectBarMask = null;
35517 domEls.elGridRectMarkerMask = null;
35518 domEls.elForecastMask = null;
35519 domEls.elNonForecastMask = null;
35520 domEls.elDefs = null;
35521 }
35522 }]);
35523 return Destroy;
35524 }();
35525
35526 // Helpers to react to element resizes, regardless of what caused them
35527 // TODO Currently this creates a new ResizeObserver every time we want to observe an element for resizes
35528 // Ideally, we should be able to use a single observer for all elements
35529 var ros = new WeakMap(); // Map callbacks to ResizeObserver instances for easy removal
35530
35531 function addResizeListener(el, fn) {
35532 var called = false;
35533 if (el.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
35534 var elRect = el.getBoundingClientRect();
35535 if (el.style.display === 'none' || elRect.width === 0) {
35536 // if elRect.width=0, the chart is not rendered at all
35537 // (it has either display none or hidden in a different tab)
35538 // fixes https://github.com/apexcharts/apexcharts.js/issues/2825
35539 // fixes https://github.com/apexcharts/apexcharts.js/issues/2991
35540 // fixes https://github.com/apexcharts/apexcharts.js/issues/2992
35541 called = true;
35542 }
35543 }
35544 var ro = new ResizeObserver(function (r) {
35545 // ROs fire immediately after being created,
35546 // per spec: https://drafts.csswg.org/resize-observer/#ref-for-element%E2%91%A3
35547 // we don't want that so we just discard the first run
35548 if (called) {
35549 fn.call(el, r);
35550 }
35551 called = true;
35552 });
35553 if (el.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
35554 // Document fragment, observe children instead (needed for Shadow DOM, see #1332)
35555 Array.from(el.children).forEach(function (c) {
35556 return ro.observe(c);
35557 });
35558 } else {
35559 ro.observe(el);
35560 }
35561 ros.set(fn, ro);
35562 }
35563 function removeResizeListener(el, fn) {
35564 var ro = ros.get(fn);
35565 if (ro) {
35566 ro.disconnect();
35567 ros.delete(fn);
35568 }
35569 }
35570
35571 var css_248z = "@keyframes opaque {\n 0% {\n opacity: 0\n }\n\n to {\n opacity: 1\n }\n}\n\n@keyframes resizeanim {\n\n 0%,\n to {\n opacity: 0\n }\n}\n\n.apexcharts-canvas {\n position: relative;\n direction: ltr !important;\n user-select: none\n}\n\n.apexcharts-canvas ::-webkit-scrollbar {\n -webkit-appearance: none;\n width: 6px\n}\n\n.apexcharts-canvas ::-webkit-scrollbar-thumb {\n border-radius: 4px;\n background-color: rgba(0, 0, 0, .5);\n box-shadow: 0 0 1px rgba(255, 255, 255, .5);\n -webkit-box-shadow: 0 0 1px rgba(255, 255, 255, .5)\n}\n\n.apexcharts-inner {\n position: relative\n}\n\n.apexcharts-text tspan {\n font-family: inherit\n}\n\nrect.legend-mouseover-inactive,\n.legend-mouseover-inactive rect,\n.legend-mouseover-inactive path,\n.legend-mouseover-inactive circle,\n.legend-mouseover-inactive line,\n.legend-mouseover-inactive text.apexcharts-yaxis-title-text,\n.legend-mouseover-inactive text.apexcharts-yaxis-label {\n transition: .15s ease all;\n opacity: .2\n}\n\n.apexcharts-legend-text {\n padding-left: 15px;\n margin-left: -15px;\n}\n\n.apexcharts-series-collapsed {\n opacity: 0\n}\n\n.apexcharts-tooltip {\n border-radius: 5px;\n box-shadow: 2px 2px 6px -4px #999;\n cursor: default;\n font-size: 14px;\n left: 62px;\n opacity: 0;\n pointer-events: none;\n position: absolute;\n top: 20px;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n white-space: nowrap;\n z-index: 12;\n transition: .15s ease all\n}\n\n.apexcharts-tooltip.apexcharts-active {\n opacity: 1;\n transition: .15s ease all\n}\n\n.apexcharts-tooltip.apexcharts-theme-light {\n border: 1px solid #e3e3e3;\n background: rgba(255, 255, 255, .96)\n}\n\n.apexcharts-tooltip.apexcharts-theme-dark {\n color: #fff;\n background: rgba(30, 30, 30, .8)\n}\n\n.apexcharts-tooltip * {\n font-family: inherit\n}\n\n.apexcharts-tooltip-title {\n padding: 6px;\n font-size: 15px;\n margin-bottom: 4px\n}\n\n.apexcharts-tooltip.apexcharts-theme-light .apexcharts-tooltip-title {\n background: #eceff1;\n border-bottom: 1px solid #ddd\n}\n\n.apexcharts-tooltip.apexcharts-theme-dark .apexcharts-tooltip-title {\n background: rgba(0, 0, 0, .7);\n border-bottom: 1px solid #333\n}\n\n.apexcharts-tooltip-text-goals-value,\n.apexcharts-tooltip-text-y-value,\n.apexcharts-tooltip-text-z-value {\n display: inline-block;\n margin-left: 5px;\n font-weight: 600\n}\n\n.apexcharts-tooltip-text-goals-label:empty,\n.apexcharts-tooltip-text-goals-value:empty,\n.apexcharts-tooltip-text-y-label:empty,\n.apexcharts-tooltip-text-y-value:empty,\n.apexcharts-tooltip-text-z-value:empty,\n.apexcharts-tooltip-title:empty {\n display: none\n}\n\n.apexcharts-tooltip-text-goals-label,\n.apexcharts-tooltip-text-goals-value {\n padding: 6px 0 5px\n}\n\n.apexcharts-tooltip-goals-group,\n.apexcharts-tooltip-text-goals-label,\n.apexcharts-tooltip-text-goals-value {\n display: flex\n}\n\n.apexcharts-tooltip-text-goals-label:not(:empty),\n.apexcharts-tooltip-text-goals-value:not(:empty) {\n margin-top: -6px\n}\n\n.apexcharts-tooltip-marker {\n display: inline-block;\n position: relative;\n width: 16px;\n height: 16px;\n font-size: 16px;\n line-height: 16px;\n margin-right: 4px;\n text-align: center;\n vertical-align: middle;\n color: inherit;\n}\n\n.apexcharts-tooltip-marker::before {\n content: \"\";\n display: inline-block;\n width: 100%;\n text-align: center;\n color: currentcolor;\n text-rendering: optimizeLegibility;\n -webkit-font-smoothing: antialiased;\n font-size: 26px;\n font-family: Arial, Helvetica, sans-serif;\n line-height: 14px;\n font-weight: 900;\n}\n\n.apexcharts-tooltip-marker[shape=\"circle\"]::before {\n content: \"\\25CF\";\n}\n\n.apexcharts-tooltip-marker[shape=\"square\"]::before,\n.apexcharts-tooltip-marker[shape=\"rect\"]::before {\n content: \"\\25A0\";\n transform: translate(-1px, -2px);\n}\n\n.apexcharts-tooltip-marker[shape=\"line\"]::before {\n content: \"\\2500\";\n}\n\n.apexcharts-tooltip-marker[shape=\"diamond\"]::before {\n content: \"\\25C6\";\n font-size: 28px;\n}\n\n.apexcharts-tooltip-marker[shape=\"triangle\"]::before {\n content: \"\\25B2\";\n font-size: 22px;\n}\n\n.apexcharts-tooltip-marker[shape=\"cross\"]::before {\n content: \"\\2715\";\n font-size: 18px;\n}\n\n.apexcharts-tooltip-marker[shape=\"plus\"]::before {\n content: \"\\2715\";\n transform: rotate(45deg) translate(-1px, -1px);\n font-size: 18px;\n}\n\n.apexcharts-tooltip-marker[shape=\"star\"]::before {\n content: \"\\2605\";\n font-size: 18px;\n}\n\n.apexcharts-tooltip-marker[shape=\"sparkle\"]::before {\n content: \"\\2726\";\n font-size: 20px;\n}\n\n.apexcharts-tooltip-series-group {\n padding: 0 10px;\n display: none;\n text-align: left;\n justify-content: left;\n align-items: center\n}\n\n.apexcharts-tooltip-series-group.apexcharts-active .apexcharts-tooltip-marker {\n opacity: 1\n}\n\n.apexcharts-tooltip-series-group.apexcharts-active,\n.apexcharts-tooltip-series-group:last-child {\n padding-bottom: 4px\n}\n\n.apexcharts-tooltip-y-group {\n padding: 6px 0 5px\n}\n\n.apexcharts-custom-tooltip,\n.apexcharts-tooltip-box {\n padding: 4px 8px\n}\n\n.apexcharts-tooltip-boxPlot {\n display: flex;\n flex-direction: column-reverse\n}\n\n.apexcharts-tooltip-box>div {\n margin: 4px 0\n}\n\n.apexcharts-tooltip-box span.value {\n font-weight: 700\n}\n\n.apexcharts-tooltip-rangebar {\n padding: 5px 8px\n}\n\n.apexcharts-tooltip-rangebar .category {\n font-weight: 600;\n color: #777\n}\n\n.apexcharts-tooltip-rangebar .series-name {\n font-weight: 700;\n display: block;\n margin-bottom: 5px\n}\n\n.apexcharts-xaxistooltip,\n.apexcharts-yaxistooltip {\n opacity: 0;\n pointer-events: none;\n color: #373d3f;\n font-size: 13px;\n text-align: center;\n border-radius: 2px;\n position: absolute;\n z-index: 10;\n background: #eceff1;\n border: 1px solid #90a4ae\n}\n\n.apexcharts-xaxistooltip {\n padding: 9px 10px;\n transition: .15s ease all\n}\n\n.apexcharts-xaxistooltip.apexcharts-theme-dark {\n background: rgba(0, 0, 0, .7);\n border: 1px solid rgba(0, 0, 0, .5);\n color: #fff\n}\n\n.apexcharts-xaxistooltip:after,\n.apexcharts-xaxistooltip:before {\n left: 50%;\n border: solid transparent;\n content: \" \";\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none\n}\n\n.apexcharts-xaxistooltip:after {\n border-color: transparent;\n border-width: 6px;\n margin-left: -6px\n}\n\n.apexcharts-xaxistooltip:before {\n border-color: transparent;\n border-width: 7px;\n margin-left: -7px\n}\n\n.apexcharts-xaxistooltip-bottom:after,\n.apexcharts-xaxistooltip-bottom:before {\n bottom: 100%\n}\n\n.apexcharts-xaxistooltip-top:after,\n.apexcharts-xaxistooltip-top:before {\n top: 100%\n}\n\n.apexcharts-xaxistooltip-bottom:after {\n border-bottom-color: #eceff1\n}\n\n.apexcharts-xaxistooltip-bottom:before {\n border-bottom-color: #90a4ae\n}\n\n.apexcharts-xaxistooltip-bottom.apexcharts-theme-dark:after,\n.apexcharts-xaxistooltip-bottom.apexcharts-theme-dark:before {\n border-bottom-color: rgba(0, 0, 0, .5)\n}\n\n.apexcharts-xaxistooltip-top:after {\n border-top-color: #eceff1\n}\n\n.apexcharts-xaxistooltip-top:before {\n border-top-color: #90a4ae\n}\n\n.apexcharts-xaxistooltip-top.apexcharts-theme-dark:after,\n.apexcharts-xaxistooltip-top.apexcharts-theme-dark:before {\n border-top-color: rgba(0, 0, 0, .5)\n}\n\n.apexcharts-xaxistooltip.apexcharts-active {\n opacity: 1;\n transition: .15s ease all\n}\n\n.apexcharts-yaxistooltip {\n padding: 4px 10px\n}\n\n.apexcharts-yaxistooltip.apexcharts-theme-dark {\n background: rgba(0, 0, 0, .7);\n border: 1px solid rgba(0, 0, 0, .5);\n color: #fff\n}\n\n.apexcharts-yaxistooltip:after,\n.apexcharts-yaxistooltip:before {\n top: 50%;\n border: solid transparent;\n content: \" \";\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none\n}\n\n.apexcharts-yaxistooltip:after {\n border-color: transparent;\n border-width: 6px;\n margin-top: -6px\n}\n\n.apexcharts-yaxistooltip:before {\n border-color: transparent;\n border-width: 7px;\n margin-top: -7px\n}\n\n.apexcharts-yaxistooltip-left:after,\n.apexcharts-yaxistooltip-left:before {\n left: 100%\n}\n\n.apexcharts-yaxistooltip-right:after,\n.apexcharts-yaxistooltip-right:before {\n right: 100%\n}\n\n.apexcharts-yaxistooltip-left:after {\n border-left-color: #eceff1\n}\n\n.apexcharts-yaxistooltip-left:before {\n border-left-color: #90a4ae\n}\n\n.apexcharts-yaxistooltip-left.apexcharts-theme-dark:after,\n.apexcharts-yaxistooltip-left.apexcharts-theme-dark:before {\n border-left-color: rgba(0, 0, 0, .5)\n}\n\n.apexcharts-yaxistooltip-right:after {\n border-right-color: #eceff1\n}\n\n.apexcharts-yaxistooltip-right:before {\n border-right-color: #90a4ae\n}\n\n.apexcharts-yaxistooltip-right.apexcharts-theme-dark:after,\n.apexcharts-yaxistooltip-right.apexcharts-theme-dark:before {\n border-right-color: rgba(0, 0, 0, .5)\n}\n\n.apexcharts-yaxistooltip.apexcharts-active {\n opacity: 1\n}\n\n.apexcharts-yaxistooltip-hidden {\n display: none\n}\n\n.apexcharts-xcrosshairs,\n.apexcharts-ycrosshairs {\n pointer-events: none;\n opacity: 0;\n transition: .15s ease all\n}\n\n.apexcharts-xcrosshairs.apexcharts-active,\n.apexcharts-ycrosshairs.apexcharts-active {\n opacity: 1;\n transition: .15s ease all\n}\n\n.apexcharts-ycrosshairs-hidden {\n opacity: 0\n}\n\n.apexcharts-selection-rect {\n cursor: move\n}\n\n.svg_select_shape {\n stroke-width: 1;\n stroke-dasharray: 10 10;\n stroke: black;\n stroke-opacity: 0.1;\n pointer-events: none;\n fill: none;\n}\n\n.svg_select_handle {\n stroke-width: 3;\n stroke: black;\n fill: none;\n}\n\n.svg_select_handle_r {\n cursor: e-resize;\n}\n\n.svg_select_handle_l {\n cursor: w-resize;\n}\n\n.apexcharts-svg.apexcharts-zoomable.hovering-zoom {\n cursor: crosshair\n}\n\n.apexcharts-svg.apexcharts-zoomable.hovering-pan {\n cursor: move\n}\n\n.apexcharts-menu-icon,\n.apexcharts-pan-icon,\n.apexcharts-reset-icon,\n.apexcharts-selection-icon,\n.apexcharts-toolbar-custom-icon,\n.apexcharts-zoom-icon,\n.apexcharts-zoomin-icon,\n.apexcharts-zoomout-icon {\n cursor: pointer;\n width: 20px;\n height: 20px;\n line-height: 24px;\n color: #6e8192;\n text-align: center\n}\n\n.apexcharts-menu-icon svg,\n.apexcharts-reset-icon svg,\n.apexcharts-zoom-icon svg,\n.apexcharts-zoomin-icon svg,\n.apexcharts-zoomout-icon svg {\n fill: #6e8192\n}\n\n.apexcharts-selection-icon svg {\n fill: #444;\n transform: scale(.76)\n}\n\n.apexcharts-theme-dark .apexcharts-menu-icon svg,\n.apexcharts-theme-dark .apexcharts-pan-icon svg,\n.apexcharts-theme-dark .apexcharts-reset-icon svg,\n.apexcharts-theme-dark .apexcharts-selection-icon svg,\n.apexcharts-theme-dark .apexcharts-toolbar-custom-icon svg,\n.apexcharts-theme-dark .apexcharts-zoom-icon svg,\n.apexcharts-theme-dark .apexcharts-zoomin-icon svg,\n.apexcharts-theme-dark .apexcharts-zoomout-icon svg {\n fill: #f3f4f5\n}\n\n.apexcharts-canvas .apexcharts-reset-zoom-icon.apexcharts-selected svg,\n.apexcharts-canvas .apexcharts-selection-icon.apexcharts-selected svg,\n.apexcharts-canvas .apexcharts-zoom-icon.apexcharts-selected svg {\n fill: #008ffb\n}\n\n.apexcharts-theme-light .apexcharts-menu-icon:hover svg,\n.apexcharts-theme-light .apexcharts-reset-icon:hover svg,\n.apexcharts-theme-light .apexcharts-selection-icon:not(.apexcharts-selected):hover svg,\n.apexcharts-theme-light .apexcharts-zoom-icon:not(.apexcharts-selected):hover svg,\n.apexcharts-theme-light .apexcharts-zoomin-icon:hover svg,\n.apexcharts-theme-light .apexcharts-zoomout-icon:hover svg {\n fill: #333\n}\n\n.apexcharts-menu-icon,\n.apexcharts-selection-icon {\n position: relative\n}\n\n.apexcharts-reset-icon {\n margin-left: 5px\n}\n\n.apexcharts-menu-icon,\n.apexcharts-reset-icon,\n.apexcharts-zoom-icon {\n transform: scale(.85)\n}\n\n.apexcharts-zoomin-icon,\n.apexcharts-zoomout-icon {\n transform: scale(.7)\n}\n\n.apexcharts-zoomout-icon {\n margin-right: 3px\n}\n\n.apexcharts-pan-icon {\n transform: scale(.62);\n position: relative;\n left: 1px;\n top: 0\n}\n\n.apexcharts-pan-icon svg {\n fill: #fff;\n stroke: #6e8192;\n stroke-width: 2\n}\n\n.apexcharts-pan-icon.apexcharts-selected svg {\n stroke: #008ffb\n}\n\n.apexcharts-pan-icon:not(.apexcharts-selected):hover svg {\n stroke: #333\n}\n\n.apexcharts-toolbar {\n position: absolute;\n z-index: 11;\n max-width: 176px;\n text-align: right;\n border-radius: 3px;\n padding: 0 6px 2px;\n display: flex;\n justify-content: space-between;\n align-items: center\n}\n\n.apexcharts-menu {\n background: #fff;\n position: absolute;\n top: 100%;\n border: 1px solid #ddd;\n border-radius: 3px;\n padding: 3px;\n right: 10px;\n opacity: 0;\n min-width: 110px;\n transition: .15s ease all;\n pointer-events: none\n}\n\n.apexcharts-menu.apexcharts-menu-open {\n opacity: 1;\n pointer-events: all;\n transition: .15s ease all\n}\n\n.apexcharts-menu-item {\n padding: 6px 7px;\n font-size: 12px;\n cursor: pointer\n}\n\n.apexcharts-theme-light .apexcharts-menu-item:hover {\n background: #eee\n}\n\n.apexcharts-theme-dark .apexcharts-menu {\n background: rgba(0, 0, 0, .7);\n color: #fff\n}\n\n@media screen and (min-width:768px) {\n .apexcharts-canvas:hover .apexcharts-toolbar {\n opacity: 1\n }\n}\n\n.apexcharts-canvas .apexcharts-element-hidden,\n.apexcharts-datalabel.apexcharts-element-hidden,\n.apexcharts-hide .apexcharts-series-points {\n opacity: 0;\n}\n\n.apexcharts-hidden-element-shown {\n opacity: 1;\n transition: 0.25s ease all;\n}\n\n.apexcharts-datalabel,\n.apexcharts-datalabel-label,\n.apexcharts-datalabel-value,\n.apexcharts-datalabels,\n.apexcharts-pie-label {\n cursor: default;\n pointer-events: none\n}\n\n.apexcharts-pie-label-delay {\n opacity: 0;\n animation-name: opaque;\n animation-duration: .3s;\n animation-fill-mode: forwards;\n animation-timing-function: ease\n}\n\n.apexcharts-radialbar-label {\n cursor: pointer;\n}\n\n.apexcharts-annotation-rect,\n.apexcharts-area-series .apexcharts-area,\n.apexcharts-gridline,\n.apexcharts-line,\n.apexcharts-point-annotation-label,\n.apexcharts-radar-series path:not(.apexcharts-marker),\n.apexcharts-radar-series polygon,\n.apexcharts-toolbar svg,\n.apexcharts-tooltip .apexcharts-marker,\n.apexcharts-xaxis-annotation-label,\n.apexcharts-yaxis-annotation-label,\n.apexcharts-zoom-rect,\n.no-pointer-events {\n pointer-events: none\n}\n\n.apexcharts-tooltip-active .apexcharts-marker {\n transition: .15s ease all\n}\n\n.apexcharts-radar-series .apexcharts-yaxis {\n pointer-events: none;\n}\n\n.resize-triggers {\n animation: 1ms resizeanim;\n visibility: hidden;\n opacity: 0;\n height: 100%;\n width: 100%;\n overflow: hidden\n}\n\n.contract-trigger:before,\n.resize-triggers,\n.resize-triggers>div {\n content: \" \";\n display: block;\n position: absolute;\n top: 0;\n left: 0\n}\n\n.resize-triggers>div {\n height: 100%;\n width: 100%;\n background: #eee;\n overflow: auto\n}\n\n.contract-trigger:before {\n overflow: hidden;\n width: 200%;\n height: 200%\n}\n\n.apexcharts-bar-goals-markers {\n pointer-events: none\n}\n\n.apexcharts-bar-shadows {\n pointer-events: none\n}\n\n.apexcharts-rangebar-goals-markers {\n pointer-events: none\n}\n\n.apexcharts-disable-transitions * {\n transition: none !important;\n}";
35572
35573 /**
35574 *
35575 * @module ApexCharts
35576 **/
35577 var ApexCharts = /*#__PURE__*/function () {
35578 function ApexCharts(el, opts) {
35579 _classCallCheck(this, ApexCharts);
35580 this.opts = opts;
35581 this.ctx = this;
35582
35583 // Pass the user supplied options to the Base Class where these options will be extended with defaults. The returned object from Base Class will become the config object in the entire codebase.
35584 this.w = new Base(opts).init();
35585 this.el = el;
35586 this.w.globals.cuid = Utils$1.randomId();
35587 this.w.globals.chartID = this.w.config.chart.id ? Utils$1.escapeString(this.w.config.chart.id) : this.w.globals.cuid;
35588 var initCtx = new InitCtxVariables(this);
35589 initCtx.initModules();
35590 this.lastUpdateOptions = null;
35591 this.create = Utils$1.bind(this.create, this);
35592 this.windowResizeHandler = this._windowResizeHandler.bind(this);
35593 this.parentResizeHandler = this._parentResizeCallback.bind(this);
35594 }
35595
35596 /**
35597 * The primary method user will call to render the chart.
35598 */
35599 _createClass(ApexCharts, [{
35600 key: "render",
35601 value: function render() {
35602 var _this = this;
35603 // main method
35604 return new Promise(function (resolve, reject) {
35605 // only draw chart, if element found
35606 if (Utils$1.elementExists(_this.el)) {
35607 if (typeof Apex._chartInstances === 'undefined') {
35608 Apex._chartInstances = [];
35609 }
35610 if (_this.w.config.chart.id) {
35611 Apex._chartInstances.push({
35612 id: _this.w.globals.chartID,
35613 group: _this.w.config.chart.group,
35614 chart: _this
35615 });
35616 }
35617
35618 // set the locale here
35619 _this.setLocale(_this.w.config.chart.defaultLocale);
35620 var beforeMount = _this.w.config.chart.events.beforeMount;
35621 if (typeof beforeMount === 'function') {
35622 beforeMount(_this, _this.w);
35623 }
35624 _this.events.fireEvent('beforeMount', [_this, _this.w]);
35625 window.addEventListener('resize', _this.windowResizeHandler);
35626 addResizeListener(_this.el.parentNode, _this.parentResizeHandler);
35627 var rootNode = _this.el.getRootNode && _this.el.getRootNode();
35628 var inShadowRoot = Utils$1.is('ShadowRoot', rootNode);
35629 var doc = _this.el.ownerDocument;
35630 var css = inShadowRoot ? rootNode.getElementById('apexcharts-css') : doc.getElementById('apexcharts-css');
35631 if (!css) {
35632 var _this$opts$chart;
35633 css = document.createElement('style');
35634 css.id = 'apexcharts-css';
35635 css.textContent = css_248z;
35636 var nonce = ((_this$opts$chart = _this.opts.chart) === null || _this$opts$chart === void 0 ? void 0 : _this$opts$chart.nonce) || _this.w.config.chart.nonce;
35637 if (nonce) {
35638 css.setAttribute('nonce', nonce);
35639 }
35640 if (inShadowRoot) {
35641 // We are in Shadow DOM, add to shadow root
35642 rootNode.prepend(css);
35643 } else {
35644 // Add to <head> of element's document
35645 doc.head.appendChild(css);
35646 }
35647 }
35648 var graphData = _this.create(_this.w.config.series, {});
35649 if (!graphData) return resolve(_this);
35650 _this.mount(graphData).then(function () {
35651 if (typeof _this.w.config.chart.events.mounted === 'function') {
35652 _this.w.config.chart.events.mounted(_this, _this.w);
35653 }
35654 _this.events.fireEvent('mounted', [_this, _this.w]);
35655 resolve(graphData);
35656 }).catch(function (e) {
35657 reject(e);
35658 // handle error in case no data or element not found
35659 });
35660 } else {
35661 reject(new Error('Element not found'));
35662 }
35663 });
35664 }
35665 }, {
35666 key: "create",
35667 value: function create(ser, opts) {
35668 var _this2 = this;
35669 var w = this.w;
35670 var initCtx = new InitCtxVariables(this);
35671 initCtx.initModules();
35672 var gl = this.w.globals;
35673 gl.noData = false;
35674 gl.animationEnded = false;
35675 if (!Utils$1.elementExists(this.el)) {
35676 gl.animationEnded = true;
35677 return null;
35678 }
35679 this.responsive.checkResponsiveConfig(opts);
35680 if (w.config.xaxis.convertedCatToNumeric) {
35681 var defaults = new Defaults(w.config);
35682 defaults.convertCatToNumericXaxis(w.config, this.ctx);
35683 }
35684 this.core.setupElements();
35685 if (w.config.chart.type === 'treemap') {
35686 w.config.grid.show = false;
35687 w.config.yaxis[0].show = false;
35688 }
35689 if (gl.svgWidth === 0) {
35690 // if the element is hidden, skip drawing
35691 gl.animationEnded = true;
35692 return null;
35693 }
35694 var series = ser;
35695 ser.forEach(function (s, realIndex) {
35696 if (s.hidden) {
35697 series = _this2.legend.legendHelpers.getSeriesAfterCollapsing({
35698 realIndex: realIndex
35699 });
35700 }
35701 });
35702 var combo = CoreUtils.checkComboSeries(series, w.config.chart.type);
35703 gl.comboCharts = combo.comboCharts;
35704 gl.comboBarCount = combo.comboBarCount;
35705 var allSeriesAreEmpty = series.every(function (s) {
35706 return s.data && s.data.length === 0;
35707 });
35708 if (series.length === 0 || allSeriesAreEmpty && gl.collapsedSeries.length < 1) {
35709 this.series.handleNoData();
35710 }
35711 this.events.setupEventHandlers();
35712
35713 // Handle the data inputted by user and set some of the global variables (for eg, if data is datetime / numeric / category). Don't calculate the range / min / max at this time
35714 this.data.parseData(series);
35715
35716 // this is a good time to set theme colors first
35717 this.theme.init();
35718
35719 // as markers accepts array, we need to setup global markers for easier access
35720 var markers = new Markers(this);
35721 markers.setGlobalMarkerSize();
35722
35723 // labelFormatters should be called before dimensions as in dimensions we need text labels width
35724 this.formatters.setLabelFormatters();
35725 this.titleSubtitle.draw();
35726
35727 // legend is calculated here before coreCalculations because it affects the plottable area
35728 // if there is some data to show or user collapsed all series, then proceed drawing legend
35729 if (!gl.noData || gl.collapsedSeries.length === gl.series.length || w.config.legend.showForSingleSeries) {
35730 this.legend.init();
35731 }
35732
35733 // check whether in multiple series, all series share the same X
35734 this.series.hasAllSeriesEqualX();
35735
35736 // coreCalculations will give the min/max range and yaxis/axis values. It should be called here to set series variable from config to globals
35737 if (gl.axisCharts) {
35738 this.core.coreCalculations();
35739 if (w.config.xaxis.type !== 'category') {
35740 // as we have minX and maxX values, determine the default DateTimeFormat for time series
35741 this.formatters.setLabelFormatters();
35742 }
35743 this.ctx.toolbar.minX = w.globals.minX;
35744 this.ctx.toolbar.maxX = w.globals.maxX;
35745 }
35746
35747 // we need to generate yaxis for heatmap separately as we are not showing numerics there, but seriesNames. There are some tweaks which are required for heatmap to align labels correctly which are done in below function
35748 // Also we need to do this before calculating Dimensions plotCoords() method of Dimensions
35749 this.formatters.heatmapLabelFormatters();
35750
35751 // get the largest marker size which will be needed in dimensions calc
35752 var coreUtils = new CoreUtils(this);
35753 coreUtils.getLargestMarkerSize();
35754
35755 // We got plottable area here, next task would be to calculate axis areas
35756 this.dimensions.plotCoords();
35757 var xyRatios = this.core.xySettings();
35758 this.grid.createGridMask();
35759 var elGraph = this.core.plotChartType(series, xyRatios);
35760 var dataLabels = new DataLabels(this);
35761 dataLabels.bringForward();
35762 if (w.config.dataLabels.background.enabled) {
35763 dataLabels.dataLabelsBackground();
35764 }
35765
35766 // after all the drawing calculations, shift the graphical area (actual charts/bars) excluding legends
35767 this.core.shiftGraphPosition();
35768 if (w.globals.dataPoints > 50) {
35769 w.globals.dom.elWrap.classList.add('apexcharts-disable-transitions');
35770 }
35771 var dim = {
35772 plot: {
35773 left: w.globals.translateX,
35774 top: w.globals.translateY,
35775 width: w.globals.gridWidth,
35776 height: w.globals.gridHeight
35777 }
35778 };
35779 return {
35780 elGraph: elGraph,
35781 xyRatios: xyRatios,
35782 dimensions: dim
35783 };
35784 }
35785 }, {
35786 key: "mount",
35787 value: function mount() {
35788 var _this3 = this;
35789 var graphData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
35790 var me = this;
35791 var w = me.w;
35792 return new Promise(function (resolve, reject) {
35793 // no data to display
35794 if (me.el === null) {
35795 return reject(new Error('Not enough data to display or target element not found'));
35796 } else if (graphData === null || w.globals.allSeriesCollapsed) {
35797 me.series.handleNoData();
35798 }
35799 me.grid = new Grid(me);
35800 var elgrid = me.grid.drawGrid();
35801 me.annotations = new Annotations(me);
35802 me.annotations.drawImageAnnos();
35803 me.annotations.drawTextAnnos();
35804 if (w.config.grid.position === 'back') {
35805 var _elgrid$elGridBorders;
35806 if (elgrid) {
35807 w.globals.dom.elGraphical.add(elgrid.el);
35808 }
35809 if (elgrid !== null && elgrid !== void 0 && (_elgrid$elGridBorders = elgrid.elGridBorders) !== null && _elgrid$elGridBorders !== void 0 && _elgrid$elGridBorders.node) {
35810 w.globals.dom.elGraphical.add(elgrid.elGridBorders);
35811 }
35812 }
35813 if (Array.isArray(graphData.elGraph)) {
35814 for (var g = 0; g < graphData.elGraph.length; g++) {
35815 w.globals.dom.elGraphical.add(graphData.elGraph[g]);
35816 }
35817 } else {
35818 w.globals.dom.elGraphical.add(graphData.elGraph);
35819 }
35820 if (w.config.grid.position === 'front') {
35821 var _elgrid$elGridBorders2;
35822 if (elgrid) {
35823 w.globals.dom.elGraphical.add(elgrid.el);
35824 }
35825 if (elgrid !== null && elgrid !== void 0 && (_elgrid$elGridBorders2 = elgrid.elGridBorders) !== null && _elgrid$elGridBorders2 !== void 0 && _elgrid$elGridBorders2.node) {
35826 w.globals.dom.elGraphical.add(elgrid.elGridBorders);
35827 }
35828 }
35829 if (w.config.xaxis.crosshairs.position === 'front') {
35830 me.crosshairs.drawXCrosshairs();
35831 }
35832 if (w.config.yaxis[0].crosshairs.position === 'front') {
35833 me.crosshairs.drawYCrosshairs();
35834 }
35835 if (w.config.chart.type !== 'treemap') {
35836 me.axes.drawAxis(w.config.chart.type, elgrid);
35837 }
35838 var xAxis = new XAxis(_this3.ctx, elgrid);
35839 var yaxis = new YAxis(_this3.ctx, elgrid);
35840 if (elgrid !== null) {
35841 xAxis.xAxisLabelCorrections(elgrid.xAxisTickWidth);
35842 yaxis.setYAxisTextAlignments();
35843 w.config.yaxis.map(function (yaxe, index) {
35844 if (w.globals.ignoreYAxisIndexes.indexOf(index) === -1) {
35845 yaxis.yAxisTitleRotate(index, yaxe.opposite);
35846 }
35847 });
35848 }
35849 me.annotations.drawAxesAnnotations();
35850 if (!w.globals.noData) {
35851 // draw tooltips at the end
35852 if (w.config.tooltip.enabled && !w.globals.noData) {
35853 me.w.globals.tooltip.drawTooltip(graphData.xyRatios);
35854 }
35855 if (w.globals.axisCharts && (w.globals.isXNumeric || w.config.xaxis.convertedCatToNumeric || w.globals.isRangeBar)) {
35856 if (w.config.chart.zoom.enabled || w.config.chart.selection && w.config.chart.selection.enabled || w.config.chart.pan && w.config.chart.pan.enabled) {
35857 me.zoomPanSelection.init({
35858 xyRatios: graphData.xyRatios
35859 });
35860 }
35861 } else {
35862 var tools = w.config.chart.toolbar.tools;
35863 var toolsArr = ['zoom', 'zoomin', 'zoomout', 'selection', 'pan', 'reset'];
35864 toolsArr.forEach(function (t) {
35865 tools[t] = false;
35866 });
35867 }
35868 if (w.config.chart.toolbar.show && !w.globals.allSeriesCollapsed) {
35869 me.toolbar.createToolbar();
35870 }
35871 }
35872 if (w.globals.memory.methodsToExec.length > 0) {
35873 w.globals.memory.methodsToExec.forEach(function (fn) {
35874 fn.method(fn.params, false, fn.context);
35875 });
35876 }
35877 if (!w.globals.axisCharts && !w.globals.noData) {
35878 me.core.resizeNonAxisCharts();
35879 }
35880 resolve(me);
35881 });
35882 }
35883
35884 /**
35885 * Destroy the chart instance by removing all elements which also clean up event listeners on those elements.
35886 */
35887 }, {
35888 key: "destroy",
35889 value: function destroy() {
35890 window.removeEventListener('resize', this.windowResizeHandler);
35891 removeResizeListener(this.el.parentNode, this.parentResizeHandler);
35892 // remove the chart's instance from the global Apex._chartInstances
35893 var chartID = this.w.config.chart.id;
35894 if (chartID) {
35895 Apex._chartInstances.forEach(function (c, i) {
35896 if (c.id === Utils$1.escapeString(chartID)) {
35897 Apex._chartInstances.splice(i, 1);
35898 }
35899 });
35900 }
35901 new Destroy(this.ctx).clear({
35902 isUpdating: false
35903 });
35904 }
35905
35906 /**
35907 * Allows users to update Options after the chart has rendered.
35908 *
35909 * @param {object} options - A new config object can be passed which will be merged with the existing config object
35910 * @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
35911 * @param {boolean} animate - should animate or not on updating Options
35912 */
35913 }, {
35914 key: "updateOptions",
35915 value: function updateOptions(options) {
35916 var _this4 = this;
35917 var redraw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
35918 var animate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
35919 var updateSyncedCharts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
35920 var overwriteInitialConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
35921 var w = this.w;
35922
35923 // when called externally, clear some global variables
35924 // fixes apexcharts.js#1488
35925 w.globals.selection = undefined;
35926 if (this.lastUpdateOptions && JSON.stringify(this.lastUpdateOptions) === JSON.stringify(options)) {
35927 // Options are identical, skip the update
35928 return this;
35929 }
35930 this.lastUpdateOptions = Utils$1.clone(options);
35931 if (options.series) {
35932 this.series.resetSeries(false, true, false);
35933 if (options.series.length && options.series[0].data) {
35934 options.series = options.series.map(function (s, i) {
35935 return _this4.updateHelpers._extendSeries(s, i);
35936 });
35937 }
35938
35939 // user updated the series via updateOptions() function.
35940 // Hence, we need to reset axis min/max to avoid zooming issues
35941 this.updateHelpers.revertDefaultAxisMinMax();
35942 }
35943 // user has set x-axis min/max externally - hence we need to forcefully set the xaxis min/max
35944 if (options.xaxis) {
35945 options = this.updateHelpers.forceXAxisUpdate(options);
35946 }
35947 if (options.yaxis) {
35948 options = this.updateHelpers.forceYAxisUpdate(options);
35949 }
35950 if (w.globals.collapsedSeriesIndices.length > 0) {
35951 this.series.clearPreviousPaths();
35952 }
35953 /* update theme mode#459 */
35954 if (options.theme) {
35955 options = this.theme.updateThemeOptions(options);
35956 }
35957 return this.updateHelpers._updateOptions(options, redraw, animate, updateSyncedCharts, overwriteInitialConfig);
35958 }
35959
35960 /**
35961 * Allows users to update Series after the chart has rendered.
35962 *
35963 * @param {array} series - New series which will override the existing
35964 */
35965 }, {
35966 key: "updateSeries",
35967 value: function updateSeries() {
35968 var newSeries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
35969 var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
35970 var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
35971 this.series.resetSeries(false);
35972 this.updateHelpers.revertDefaultAxisMinMax();
35973 return this.updateHelpers._updateSeries(newSeries, animate, overwriteInitialSeries);
35974 }
35975
35976 /**
35977 * Allows users to append a new series after the chart has rendered.
35978 *
35979 * @param {array} newSerie - New serie which will be appended to the existing series
35980 */
35981 }, {
35982 key: "appendSeries",
35983 value: function appendSeries(newSerie) {
35984 var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
35985 var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
35986 var newSeries = this.w.config.series.slice();
35987 newSeries.push(newSerie);
35988 this.series.resetSeries(false);
35989 this.updateHelpers.revertDefaultAxisMinMax();
35990 return this.updateHelpers._updateSeries(newSeries, animate, overwriteInitialSeries);
35991 }
35992
35993 /**
35994 * Allows users to append Data to series.
35995 *
35996 * @param {array} newData - New data in the same format as series
35997 */
35998 }, {
35999 key: "appendData",
36000 value: function appendData(newData) {
36001 var overwriteInitialSeries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
36002 var me = this;
36003 me.w.globals.dataChanged = true;
36004 me.series.getPreviousPaths();
36005 var newSeries = me.w.config.series.slice();
36006 for (var i = 0; i < newSeries.length; i++) {
36007 if (newData[i] !== null && typeof newData[i] !== 'undefined') {
36008 for (var j = 0; j < newData[i].data.length; j++) {
36009 newSeries[i].data.push(newData[i].data[j]);
36010 }
36011 }
36012 }
36013 me.w.config.series = newSeries;
36014 if (overwriteInitialSeries) {
36015 me.w.globals.initialSeries = Utils$1.clone(me.w.config.series);
36016 }
36017 return this.update();
36018 }
36019 }, {
36020 key: "update",
36021 value: function update(options) {
36022 var _this5 = this;
36023 return new Promise(function (resolve, reject) {
36024 if (_this5.lastUpdateOptions && JSON.stringify(_this5.lastUpdateOptions) === JSON.stringify(options)) {
36025 // Options are identical, skip the update
36026 return resolve(_this5);
36027 }
36028 _this5.lastUpdateOptions = Utils$1.clone(options);
36029 new Destroy(_this5.ctx).clear({
36030 isUpdating: true
36031 });
36032 var graphData = _this5.create(_this5.w.config.series, options);
36033 if (!graphData) return resolve(_this5);
36034 _this5.mount(graphData).then(function () {
36035 if (typeof _this5.w.config.chart.events.updated === 'function') {
36036 _this5.w.config.chart.events.updated(_this5, _this5.w);
36037 }
36038 _this5.events.fireEvent('updated', [_this5, _this5.w]);
36039 _this5.w.globals.isDirty = true;
36040 resolve(_this5);
36041 }).catch(function (e) {
36042 reject(e);
36043 });
36044 });
36045 }
36046
36047 /**
36048 * Get all charts in the same "group" (including the instance which is called upon) to sync them when user zooms in/out or pan.
36049 */
36050 }, {
36051 key: "getSyncedCharts",
36052 value: function getSyncedCharts() {
36053 var chartGroups = this.getGroupedCharts();
36054 var allCharts = [this];
36055 if (chartGroups.length) {
36056 allCharts = [];
36057 chartGroups.forEach(function (ch) {
36058 allCharts.push(ch);
36059 });
36060 }
36061 return allCharts;
36062 }
36063
36064 /**
36065 * Get charts in the same "group" (excluding the instance which is called upon) to perform operations on the other charts of the same group (eg., tooltip hovering)
36066 */
36067 }, {
36068 key: "getGroupedCharts",
36069 value: function getGroupedCharts() {
36070 var _this6 = this;
36071 return Apex._chartInstances.filter(function (ch) {
36072 if (ch.group) {
36073 return true;
36074 }
36075 }).map(function (ch) {
36076 return _this6.w.config.chart.group === ch.group ? ch.chart : _this6;
36077 });
36078 }
36079 }, {
36080 key: "toggleSeries",
36081 value: function toggleSeries(seriesName) {
36082 return this.series.toggleSeries(seriesName);
36083 }
36084 }, {
36085 key: "highlightSeriesOnLegendHover",
36086 value: function highlightSeriesOnLegendHover(e, targetElement) {
36087 return this.series.toggleSeriesOnHover(e, targetElement);
36088 }
36089 }, {
36090 key: "showSeries",
36091 value: function showSeries(seriesName) {
36092 this.series.showSeries(seriesName);
36093 }
36094 }, {
36095 key: "hideSeries",
36096 value: function hideSeries(seriesName) {
36097 this.series.hideSeries(seriesName);
36098 }
36099 }, {
36100 key: "highlightSeries",
36101 value: function highlightSeries(seriesName) {
36102 this.series.highlightSeries(seriesName);
36103 }
36104 }, {
36105 key: "isSeriesHidden",
36106 value: function isSeriesHidden(seriesName) {
36107 this.series.isSeriesHidden(seriesName);
36108 }
36109 }, {
36110 key: "resetSeries",
36111 value: function resetSeries() {
36112 var shouldUpdateChart = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
36113 var shouldResetZoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
36114 this.series.resetSeries(shouldUpdateChart, shouldResetZoom);
36115 }
36116
36117 // Public method to add event listener on chart context
36118 }, {
36119 key: "addEventListener",
36120 value: function addEventListener(name, handler) {
36121 this.events.addEventListener(name, handler);
36122 }
36123
36124 // Public method to remove event listener on chart context
36125 }, {
36126 key: "removeEventListener",
36127 value: function removeEventListener(name, handler) {
36128 this.events.removeEventListener(name, handler);
36129 }
36130 }, {
36131 key: "addXaxisAnnotation",
36132 value: function addXaxisAnnotation(opts) {
36133 var pushToMemory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
36134 var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
36135 var me = this;
36136 if (context) {
36137 me = context;
36138 }
36139 me.annotations.addXaxisAnnotationExternal(opts, pushToMemory, me);
36140 }
36141 }, {
36142 key: "addYaxisAnnotation",
36143 value: function addYaxisAnnotation(opts) {
36144 var pushToMemory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
36145 var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
36146 var me = this;
36147 if (context) {
36148 me = context;
36149 }
36150 me.annotations.addYaxisAnnotationExternal(opts, pushToMemory, me);
36151 }
36152 }, {
36153 key: "addPointAnnotation",
36154 value: function addPointAnnotation(opts) {
36155 var pushToMemory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
36156 var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
36157 var me = this;
36158 if (context) {
36159 me = context;
36160 }
36161 me.annotations.addPointAnnotationExternal(opts, pushToMemory, me);
36162 }
36163 }, {
36164 key: "clearAnnotations",
36165 value: function clearAnnotations() {
36166 var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
36167 var me = this;
36168 if (context) {
36169 me = context;
36170 }
36171 me.annotations.clearAnnotations(me);
36172 }
36173 }, {
36174 key: "removeAnnotation",
36175 value: function removeAnnotation(id) {
36176 var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
36177 var me = this;
36178 if (context) {
36179 me = context;
36180 }
36181 me.annotations.removeAnnotation(me, id);
36182 }
36183 }, {
36184 key: "getChartArea",
36185 value: function getChartArea() {
36186 var el = this.w.globals.dom.baseEl.querySelector('.apexcharts-inner');
36187 return el;
36188 }
36189 }, {
36190 key: "getSeriesTotalXRange",
36191 value: function getSeriesTotalXRange(minX, maxX) {
36192 return this.coreUtils.getSeriesTotalsXRange(minX, maxX);
36193 }
36194 }, {
36195 key: "getHighestValueInSeries",
36196 value: function getHighestValueInSeries() {
36197 var seriesIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
36198 var range = new Range(this.ctx);
36199 return range.getMinYMaxY(seriesIndex).highestY;
36200 }
36201 }, {
36202 key: "getLowestValueInSeries",
36203 value: function getLowestValueInSeries() {
36204 var seriesIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
36205 var range = new Range(this.ctx);
36206 return range.getMinYMaxY(seriesIndex).lowestY;
36207 }
36208 }, {
36209 key: "getSeriesTotal",
36210 value: function getSeriesTotal() {
36211 return this.w.globals.seriesTotals;
36212 }
36213 }, {
36214 key: "toggleDataPointSelection",
36215 value: function toggleDataPointSelection(seriesIndex, dataPointIndex) {
36216 return this.updateHelpers.toggleDataPointSelection(seriesIndex, dataPointIndex);
36217 }
36218 }, {
36219 key: "zoomX",
36220 value: function zoomX(min, max) {
36221 this.ctx.toolbar.zoomUpdateOptions(min, max);
36222 }
36223 }, {
36224 key: "setLocale",
36225 value: function setLocale(localeName) {
36226 this.localization.setCurrentLocaleValues(localeName);
36227 }
36228 }, {
36229 key: "dataURI",
36230 value: function dataURI(options) {
36231 var exp = new Exports(this.ctx);
36232 return exp.dataURI(options);
36233 }
36234 }, {
36235 key: "getSvgString",
36236 value: function getSvgString(scale) {
36237 return new Exports(this.ctx).getSvgString(scale);
36238 }
36239 }, {
36240 key: "exportToCSV",
36241 value: function exportToCSV() {
36242 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
36243 var exp = new Exports(this.ctx);
36244 return exp.exportToCSV(options);
36245 }
36246 }, {
36247 key: "paper",
36248 value: function paper() {
36249 return this.w.globals.dom.Paper;
36250 }
36251 }, {
36252 key: "_parentResizeCallback",
36253 value: function _parentResizeCallback() {
36254 if (this.w.globals.animationEnded && this.w.config.chart.redrawOnParentResize) {
36255 this._windowResize();
36256 }
36257 }
36258
36259 /**
36260 * Handle window resize and re-draw the whole chart.
36261 */
36262 }, {
36263 key: "_windowResize",
36264 value: function _windowResize() {
36265 var _this7 = this;
36266 clearTimeout(this.w.globals.resizeTimer);
36267 this.w.globals.resizeTimer = window.setTimeout(function () {
36268 _this7.w.globals.resized = true;
36269 _this7.w.globals.dataChanged = false;
36270
36271 // we need to redraw the whole chart on window resize (with a small delay).
36272 _this7.ctx.update();
36273 }, 150);
36274 }
36275 }, {
36276 key: "_windowResizeHandler",
36277 value: function _windowResizeHandler() {
36278 var redraw = this.w.config.chart.redrawOnWindowResize;
36279 if (typeof redraw === 'function') {
36280 redraw = redraw();
36281 }
36282 redraw && this._windowResize();
36283 }
36284 }], [{
36285 key: "getChartByID",
36286 value: function getChartByID(id) {
36287 var chartId = Utils$1.escapeString(id);
36288 if (!Apex._chartInstances) return undefined;
36289 var c = Apex._chartInstances.filter(function (ch) {
36290 return ch.id === chartId;
36291 })[0];
36292 return c && c.chart;
36293 }
36294
36295 /**
36296 * Allows the user to provide data attrs in the element and the chart will render automatically when this method is called by searching for the elements containing 'data-apexcharts' attribute
36297 */
36298 }, {
36299 key: "initOnLoad",
36300 value: function initOnLoad() {
36301 var els = document.querySelectorAll('[data-apexcharts]');
36302 for (var i = 0; i < els.length; i++) {
36303 var el = els[i];
36304 var options = JSON.parse(els[i].getAttribute('data-options'));
36305 var apexChart = new ApexCharts(el, options);
36306 apexChart.render();
36307 }
36308 }
36309
36310 /**
36311 * This static method allows users to call chart methods without necessarily from the
36312 * instance of the chart in case user has assigned chartID to the targeted chart.
36313 * The chartID is used for mapping the instance stored in Apex._chartInstances global variable
36314 *
36315 * This is helpful in cases when you don't have reference of the chart instance
36316 * easily and need to call the method from anywhere.
36317 * For eg, in React/Vue applications when you have many parent/child components,
36318 * and need easy reference to other charts for performing dynamic operations
36319 *
36320 * @param {string} chartID - The unique identifier which will be used to call methods
36321 * on that chart instance
36322 * @param {function} fn - The method name to call
36323 * @param {object} opts - The parameters which are accepted in the original method will be passed here in the same order.
36324 */
36325 }, {
36326 key: "exec",
36327 value: function exec(chartID, fn) {
36328 var chart = this.getChartByID(chartID);
36329 if (!chart) return;
36330
36331 // turn on the global exec flag to indicate this method was called
36332 chart.w.globals.isExecCalled = true;
36333 var ret = null;
36334 if (chart.publicMethods.indexOf(fn) !== -1) {
36335 for (var _len = arguments.length, opts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
36336 opts[_key - 2] = arguments[_key];
36337 }
36338 ret = chart[fn].apply(chart, opts);
36339 }
36340 return ret;
36341 }
36342 }, {
36343 key: "merge",
36344 value: function merge(target, source) {
36345 return Utils$1.extend(target, source);
36346 }
36347 }]);
36348 return ApexCharts;
36349 }();
36350
36351 return ApexCharts;
36352
36353 }));