25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

32270 satır
1.2 MiB

  1. /*!
  2. * ApexCharts v3.54.1
  3. * (c) 2018-2024 ApexCharts
  4. * Released under the MIT License.
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ApexCharts = factory());
  10. })(this, (function () { 'use strict';
  11. function _arrayLikeToArray(r, a) {
  12. (null == a || a > r.length) && (a = r.length);
  13. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  14. return n;
  15. }
  16. function _arrayWithHoles(r) {
  17. if (Array.isArray(r)) return r;
  18. }
  19. function _arrayWithoutHoles(r) {
  20. if (Array.isArray(r)) return _arrayLikeToArray(r);
  21. }
  22. function _assertThisInitialized(e) {
  23. if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  24. return e;
  25. }
  26. function _classCallCheck(a, n) {
  27. if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
  28. }
  29. function _defineProperties(e, r) {
  30. for (var t = 0; t < r.length; t++) {
  31. var o = r[t];
  32. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
  33. }
  34. }
  35. function _createClass(e, r, t) {
  36. return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
  37. writable: !1
  38. }), e;
  39. }
  40. function _createForOfIteratorHelper(r, e) {
  41. var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  42. if (!t) {
  43. if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
  44. t && (r = t);
  45. var n = 0,
  46. F = function () {};
  47. return {
  48. s: F,
  49. n: function () {
  50. return n >= r.length ? {
  51. done: !0
  52. } : {
  53. done: !1,
  54. value: r[n++]
  55. };
  56. },
  57. e: function (r) {
  58. throw r;
  59. },
  60. f: F
  61. };
  62. }
  63. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  64. }
  65. var o,
  66. a = !0,
  67. u = !1;
  68. return {
  69. s: function () {
  70. t = t.call(r);
  71. },
  72. n: function () {
  73. var r = t.next();
  74. return a = r.done, r;
  75. },
  76. e: function (r) {
  77. u = !0, o = r;
  78. },
  79. f: function () {
  80. try {
  81. a || null == t.return || t.return();
  82. } finally {
  83. if (u) throw o;
  84. }
  85. }
  86. };
  87. }
  88. function _createSuper(t) {
  89. var r = _isNativeReflectConstruct();
  90. return function () {
  91. var e,
  92. o = _getPrototypeOf(t);
  93. if (r) {
  94. var s = _getPrototypeOf(this).constructor;
  95. e = Reflect.construct(o, arguments, s);
  96. } else e = o.apply(this, arguments);
  97. return _possibleConstructorReturn(this, e);
  98. };
  99. }
  100. function _defineProperty(e, r, t) {
  101. return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
  102. value: t,
  103. enumerable: !0,
  104. configurable: !0,
  105. writable: !0
  106. }) : e[r] = t, e;
  107. }
  108. function _getPrototypeOf(t) {
  109. return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
  110. return t.__proto__ || Object.getPrototypeOf(t);
  111. }, _getPrototypeOf(t);
  112. }
  113. function _inherits(t, e) {
  114. if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
  115. t.prototype = Object.create(e && e.prototype, {
  116. constructor: {
  117. value: t,
  118. writable: !0,
  119. configurable: !0
  120. }
  121. }), Object.defineProperty(t, "prototype", {
  122. writable: !1
  123. }), e && _setPrototypeOf(t, e);
  124. }
  125. function _isNativeReflectConstruct() {
  126. try {
  127. var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  128. } catch (t) {}
  129. return (_isNativeReflectConstruct = function () {
  130. return !!t;
  131. })();
  132. }
  133. function _iterableToArray(r) {
  134. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  135. }
  136. function _iterableToArrayLimit(r, l) {
  137. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  138. if (null != t) {
  139. var e,
  140. n,
  141. i,
  142. u,
  143. a = [],
  144. f = !0,
  145. o = !1;
  146. try {
  147. if (i = (t = t.call(r)).next, 0 === l) {
  148. if (Object(t) !== t) return;
  149. f = !1;
  150. } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  151. } catch (r) {
  152. o = !0, n = r;
  153. } finally {
  154. try {
  155. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  156. } finally {
  157. if (o) throw n;
  158. }
  159. }
  160. return a;
  161. }
  162. }
  163. function _nonIterableRest() {
  164. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  165. }
  166. function _nonIterableSpread() {
  167. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  168. }
  169. function ownKeys(e, r) {
  170. var t = Object.keys(e);
  171. if (Object.getOwnPropertySymbols) {
  172. var o = Object.getOwnPropertySymbols(e);
  173. r && (o = o.filter(function (r) {
  174. return Object.getOwnPropertyDescriptor(e, r).enumerable;
  175. })), t.push.apply(t, o);
  176. }
  177. return t;
  178. }
  179. function _objectSpread2(e) {
  180. for (var r = 1; r < arguments.length; r++) {
  181. var t = null != arguments[r] ? arguments[r] : {};
  182. r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
  183. _defineProperty(e, r, t[r]);
  184. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
  185. Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
  186. });
  187. }
  188. return e;
  189. }
  190. function _possibleConstructorReturn(t, e) {
  191. if (e && ("object" == typeof e || "function" == typeof e)) return e;
  192. if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
  193. return _assertThisInitialized(t);
  194. }
  195. function _setPrototypeOf(t, e) {
  196. return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
  197. return t.__proto__ = e, t;
  198. }, _setPrototypeOf(t, e);
  199. }
  200. function _slicedToArray(r, e) {
  201. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  202. }
  203. function _toConsumableArray(r) {
  204. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  205. }
  206. function _toPrimitive(t, r) {
  207. if ("object" != typeof t || !t) return t;
  208. var e = t[Symbol.toPrimitive];
  209. if (void 0 !== e) {
  210. var i = e.call(t, r || "default");
  211. if ("object" != typeof i) return i;
  212. throw new TypeError("@@toPrimitive must return a primitive value.");
  213. }
  214. return ("string" === r ? String : Number)(t);
  215. }
  216. function _toPropertyKey(t) {
  217. var i = _toPrimitive(t, "string");
  218. return "symbol" == typeof i ? i : i + "";
  219. }
  220. function _typeof(o) {
  221. "@babel/helpers - typeof";
  222. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  223. return typeof o;
  224. } : function (o) {
  225. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  226. }, _typeof(o);
  227. }
  228. function _unsupportedIterableToArray(r, a) {
  229. if (r) {
  230. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  231. var t = {}.toString.call(r).slice(8, -1);
  232. 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;
  233. }
  234. }
  235. /*
  236. ** Generic functions which are not dependent on ApexCharts
  237. */
  238. var Utils$1 = /*#__PURE__*/function () {
  239. function Utils() {
  240. _classCallCheck(this, Utils);
  241. }
  242. _createClass(Utils, [{
  243. key: "shadeRGBColor",
  244. value: function shadeRGBColor(percent, color) {
  245. var f = color.split(','),
  246. t = percent < 0 ? 0 : 255,
  247. p = percent < 0 ? percent * -1 : percent,
  248. R = parseInt(f[0].slice(4), 10),
  249. G = parseInt(f[1], 10),
  250. B = parseInt(f[2], 10);
  251. return 'rgb(' + (Math.round((t - R) * p) + R) + ',' + (Math.round((t - G) * p) + G) + ',' + (Math.round((t - B) * p) + B) + ')';
  252. }
  253. }, {
  254. key: "shadeHexColor",
  255. value: function shadeHexColor(percent, color) {
  256. var f = parseInt(color.slice(1), 16),
  257. t = percent < 0 ? 0 : 255,
  258. p = percent < 0 ? percent * -1 : percent,
  259. R = f >> 16,
  260. G = f >> 8 & 0x00ff,
  261. B = f & 0x0000ff;
  262. 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);
  263. }
  264. // beautiful color shading blending code
  265. // http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors
  266. }, {
  267. key: "shadeColor",
  268. value: function shadeColor(p, color) {
  269. if (Utils.isColorHex(color)) {
  270. return this.shadeHexColor(p, color);
  271. } else {
  272. return this.shadeRGBColor(p, color);
  273. }
  274. }
  275. }], [{
  276. key: "bind",
  277. value: function bind(fn, me) {
  278. return function () {
  279. return fn.apply(me, arguments);
  280. };
  281. }
  282. }, {
  283. key: "isObject",
  284. value: function isObject(item) {
  285. return item && _typeof(item) === 'object' && !Array.isArray(item) && item != null;
  286. }
  287. // Type checking that works across different window objects
  288. }, {
  289. key: "is",
  290. value: function is(type, val) {
  291. return Object.prototype.toString.call(val) === '[object ' + type + ']';
  292. }
  293. }, {
  294. key: "listToArray",
  295. value: function listToArray(list) {
  296. var i,
  297. array = [];
  298. for (i = 0; i < list.length; i++) {
  299. array[i] = list[i];
  300. }
  301. return array;
  302. }
  303. // to extend defaults with user options
  304. // credit: http://stackoverflow.com/questions/27936772/deep-object-merging-in-es6-es7#answer-34749873
  305. }, {
  306. key: "extend",
  307. value: function extend(target, source) {
  308. var _this = this;
  309. if (typeof Object.assign !== 'function') {
  310. (function () {
  311. Object.assign = function (target) {
  312. // We must check against these specific cases.
  313. if (target === undefined || target === null) {
  314. throw new TypeError('Cannot convert undefined or null to object');
  315. }
  316. var output = Object(target);
  317. for (var index = 1; index < arguments.length; index++) {
  318. var _source = arguments[index];
  319. if (_source !== undefined && _source !== null) {
  320. for (var nextKey in _source) {
  321. if (_source.hasOwnProperty(nextKey)) {
  322. output[nextKey] = _source[nextKey];
  323. }
  324. }
  325. }
  326. }
  327. return output;
  328. };
  329. })();
  330. }
  331. var output = Object.assign({}, target);
  332. if (this.isObject(target) && this.isObject(source)) {
  333. Object.keys(source).forEach(function (key) {
  334. if (_this.isObject(source[key])) {
  335. if (!(key in target)) {
  336. Object.assign(output, _defineProperty({}, key, source[key]));
  337. } else {
  338. output[key] = _this.extend(target[key], source[key]);
  339. }
  340. } else {
  341. Object.assign(output, _defineProperty({}, key, source[key]));
  342. }
  343. });
  344. }
  345. return output;
  346. }
  347. }, {
  348. key: "extendArray",
  349. value: function extendArray(arrToExtend, resultArr) {
  350. var extendedArr = [];
  351. arrToExtend.map(function (item) {
  352. extendedArr.push(Utils.extend(resultArr, item));
  353. });
  354. arrToExtend = extendedArr;
  355. return arrToExtend;
  356. }
  357. // If month counter exceeds 12, it starts again from 1
  358. }, {
  359. key: "monthMod",
  360. value: function monthMod(month) {
  361. return month % 12;
  362. }
  363. }, {
  364. key: "clone",
  365. value: function clone(source) {
  366. if (Utils.is('Array', source)) {
  367. var cloneResult = [];
  368. for (var i = 0; i < source.length; i++) {
  369. cloneResult[i] = this.clone(source[i]);
  370. }
  371. return cloneResult;
  372. } else if (Utils.is('Null', source)) {
  373. // fixes an issue where null values were converted to {}
  374. return null;
  375. } else if (Utils.is('Date', source)) {
  376. return source;
  377. } else if (_typeof(source) === 'object') {
  378. var _cloneResult = {};
  379. for (var prop in source) {
  380. if (source.hasOwnProperty(prop)) {
  381. _cloneResult[prop] = this.clone(source[prop]);
  382. }
  383. }
  384. return _cloneResult;
  385. } else {
  386. return source;
  387. }
  388. }
  389. }, {
  390. key: "log10",
  391. value: function log10(x) {
  392. return Math.log(x) / Math.LN10;
  393. }
  394. }, {
  395. key: "roundToBase10",
  396. value: function roundToBase10(x) {
  397. return Math.pow(10, Math.floor(Math.log10(x)));
  398. }
  399. }, {
  400. key: "roundToBase",
  401. value: function roundToBase(x, base) {
  402. return Math.pow(base, Math.floor(Math.log(x) / Math.log(base)));
  403. }
  404. }, {
  405. key: "parseNumber",
  406. value: function parseNumber(val) {
  407. if (val === null) return val;
  408. return parseFloat(val);
  409. }
  410. }, {
  411. key: "stripNumber",
  412. value: function stripNumber(num) {
  413. var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
  414. return Number.isInteger(num) ? num : parseFloat(num.toPrecision(precision));
  415. }
  416. }, {
  417. key: "randomId",
  418. value: function randomId() {
  419. return (Math.random() + 1).toString(36).substring(4);
  420. }
  421. }, {
  422. key: "noExponents",
  423. value: function noExponents(val) {
  424. var data = String(val).split(/[eE]/);
  425. if (data.length === 1) return data[0];
  426. var z = '',
  427. sign = val < 0 ? '-' : '',
  428. str = data[0].replace('.', ''),
  429. mag = Number(data[1]) + 1;
  430. if (mag < 0) {
  431. z = sign + '0.';
  432. while (mag++) {
  433. z += '0';
  434. }
  435. return z + str.replace(/^-/, '');
  436. }
  437. mag -= str.length;
  438. while (mag--) {
  439. z += '0';
  440. }
  441. return str + z;
  442. }
  443. }, {
  444. key: "getDimensions",
  445. value: function getDimensions(el) {
  446. var computedStyle = getComputedStyle(el, null);
  447. var elementHeight = el.clientHeight;
  448. var elementWidth = el.clientWidth;
  449. elementHeight -= parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom);
  450. elementWidth -= parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight);
  451. return [elementWidth, elementHeight];
  452. }
  453. }, {
  454. key: "getBoundingClientRect",
  455. value: function getBoundingClientRect(element) {
  456. var rect = element.getBoundingClientRect();
  457. return {
  458. top: rect.top,
  459. right: rect.right,
  460. bottom: rect.bottom,
  461. left: rect.left,
  462. width: element.clientWidth,
  463. height: element.clientHeight,
  464. x: rect.left,
  465. y: rect.top
  466. };
  467. }
  468. }, {
  469. key: "getLargestStringFromArr",
  470. value: function getLargestStringFromArr(arr) {
  471. return arr.reduce(function (a, b) {
  472. if (Array.isArray(b)) {
  473. b = b.reduce(function (aa, bb) {
  474. return aa.length > bb.length ? aa : bb;
  475. });
  476. }
  477. return a.length > b.length ? a : b;
  478. }, 0);
  479. }
  480. // http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb#answer-12342275
  481. }, {
  482. key: "hexToRgba",
  483. value: function hexToRgba() {
  484. var hex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#999999';
  485. var opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.6;
  486. if (hex.substring(0, 1) !== '#') {
  487. hex = '#999999';
  488. }
  489. var h = hex.replace('#', '');
  490. h = h.match(new RegExp('(.{' + h.length / 3 + '})', 'g'));
  491. for (var i = 0; i < h.length; i++) {
  492. h[i] = parseInt(h[i].length === 1 ? h[i] + h[i] : h[i], 16);
  493. }
  494. if (typeof opacity !== 'undefined') h.push(opacity);
  495. return 'rgba(' + h.join(',') + ')';
  496. }
  497. }, {
  498. key: "getOpacityFromRGBA",
  499. value: function getOpacityFromRGBA(rgba) {
  500. return parseFloat(rgba.replace(/^.*,(.+)\)/, '$1'));
  501. }
  502. }, {
  503. key: "rgb2hex",
  504. value: function rgb2hex(rgb) {
  505. rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  506. 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) : '';
  507. }
  508. }, {
  509. key: "isColorHex",
  510. value: function isColorHex(color) {
  511. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)|(^#[0-9A-F]{8}$)/i.test(color);
  512. }
  513. }, {
  514. key: "getPolygonPos",
  515. value: function getPolygonPos(size, dataPointsLen) {
  516. var dotsArray = [];
  517. var angle = Math.PI * 2 / dataPointsLen;
  518. for (var i = 0; i < dataPointsLen; i++) {
  519. var curPos = {};
  520. curPos.x = size * Math.sin(i * angle);
  521. curPos.y = -size * Math.cos(i * angle);
  522. dotsArray.push(curPos);
  523. }
  524. return dotsArray;
  525. }
  526. }, {
  527. key: "polarToCartesian",
  528. value: function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
  529. var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
  530. return {
  531. x: centerX + radius * Math.cos(angleInRadians),
  532. y: centerY + radius * Math.sin(angleInRadians)
  533. };
  534. }
  535. }, {
  536. key: "escapeString",
  537. value: function escapeString(str) {
  538. var escapeWith = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'x';
  539. var newStr = str.toString().slice();
  540. newStr = newStr.replace(/[` ~!@#$%^&*()|+\=?;:'",.<>{}[\]\\/]/gi, escapeWith);
  541. return newStr;
  542. }
  543. }, {
  544. key: "negToZero",
  545. value: function negToZero(val) {
  546. return val < 0 ? 0 : val;
  547. }
  548. }, {
  549. key: "moveIndexInArray",
  550. value: function moveIndexInArray(arr, old_index, new_index) {
  551. if (new_index >= arr.length) {
  552. var k = new_index - arr.length + 1;
  553. while (k--) {
  554. arr.push(undefined);
  555. }
  556. }
  557. arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
  558. return arr;
  559. }
  560. }, {
  561. key: "extractNumber",
  562. value: function extractNumber(s) {
  563. return parseFloat(s.replace(/[^\d.]*/g, ''));
  564. }
  565. }, {
  566. key: "findAncestor",
  567. value: function findAncestor(el, cls) {
  568. while ((el = el.parentElement) && !el.classList.contains(cls)) {
  569. }
  570. return el;
  571. }
  572. }, {
  573. key: "setELstyles",
  574. value: function setELstyles(el, styles) {
  575. for (var key in styles) {
  576. if (styles.hasOwnProperty(key)) {
  577. el.style.key = styles[key];
  578. }
  579. }
  580. }
  581. // prevents JS prevision errors when adding
  582. }, {
  583. key: "preciseAddition",
  584. value: function preciseAddition(a, b) {
  585. var aDecimals = (String(a).split('.')[1] || '').length;
  586. var bDecimals = (String(b).split('.')[1] || '').length;
  587. var factor = Math.pow(10, Math.max(aDecimals, bDecimals));
  588. return (Math.round(a * factor) + Math.round(b * factor)) / factor;
  589. }
  590. }, {
  591. key: "isNumber",
  592. value: function isNumber(value) {
  593. return !isNaN(value) && parseFloat(Number(value)) === value && !isNaN(parseInt(value, 10));
  594. }
  595. }, {
  596. key: "isFloat",
  597. value: function isFloat(n) {
  598. return Number(n) === n && n % 1 !== 0;
  599. }
  600. }, {
  601. key: "isSafari",
  602. value: function isSafari() {
  603. return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  604. }
  605. }, {
  606. key: "isFirefox",
  607. value: function isFirefox() {
  608. return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  609. }
  610. }, {
  611. key: "isMsEdge",
  612. value: function isMsEdge() {
  613. var ua = window.navigator.userAgent;
  614. var edge = ua.indexOf('Edge/');
  615. if (edge > 0) {
  616. // Edge (IE 12+) => return version number
  617. return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
  618. }
  619. // other browser
  620. return false;
  621. }
  622. //
  623. // Find the Greatest Common Divisor of two numbers
  624. //
  625. }, {
  626. key: "getGCD",
  627. value: function getGCD(a, b) {
  628. var p = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 7;
  629. var big = Math.pow(10, p - Math.floor(Math.log10(Math.max(a, b))));
  630. a = Math.round(Math.abs(a) * big);
  631. b = Math.round(Math.abs(b) * big);
  632. while (b) {
  633. var t = b;
  634. b = a % b;
  635. a = t;
  636. }
  637. return a / big;
  638. }
  639. }, {
  640. key: "getPrimeFactors",
  641. value: function getPrimeFactors(n) {
  642. var factors = [];
  643. var divisor = 2;
  644. while (n >= 2) {
  645. if (n % divisor == 0) {
  646. factors.push(divisor);
  647. n = n / divisor;
  648. } else {
  649. divisor++;
  650. }
  651. }
  652. return factors;
  653. }
  654. }, {
  655. key: "mod",
  656. value: function mod(a, b) {
  657. var p = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 7;
  658. var big = Math.pow(10, p - Math.floor(Math.log10(Math.max(a, b))));
  659. a = Math.round(Math.abs(a) * big);
  660. b = Math.round(Math.abs(b) * big);
  661. return a % b / big;
  662. }
  663. }]);
  664. return Utils;
  665. }();
  666. /**
  667. * ApexCharts Animation Class.
  668. *
  669. * @module Animations
  670. **/
  671. var Animations = /*#__PURE__*/function () {
  672. function Animations(ctx) {
  673. _classCallCheck(this, Animations);
  674. this.ctx = ctx;
  675. this.w = ctx.w;
  676. this.setEasingFunctions();
  677. }
  678. _createClass(Animations, [{
  679. key: "setEasingFunctions",
  680. value: function setEasingFunctions() {
  681. var easing;
  682. if (this.w.globals.easing) return;
  683. var userDefinedEasing = this.w.config.chart.animations.easing;
  684. switch (userDefinedEasing) {
  685. case 'linear':
  686. {
  687. easing = '-';
  688. break;
  689. }
  690. case 'easein':
  691. {
  692. easing = '<';
  693. break;
  694. }
  695. case 'easeout':
  696. {
  697. easing = '>';
  698. break;
  699. }
  700. case 'easeinout':
  701. {
  702. easing = '<>';
  703. break;
  704. }
  705. case 'swing':
  706. {
  707. easing = function easing(pos) {
  708. var s = 1.70158;
  709. var ret = (pos -= 1) * pos * ((s + 1) * pos + s) + 1;
  710. return ret;
  711. };
  712. break;
  713. }
  714. case 'bounce':
  715. {
  716. easing = function easing(pos) {
  717. var ret = '';
  718. if (pos < 1 / 2.75) {
  719. ret = 7.5625 * pos * pos;
  720. } else if (pos < 2 / 2.75) {
  721. ret = 7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75;
  722. } else if (pos < 2.5 / 2.75) {
  723. ret = 7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375;
  724. } else {
  725. ret = 7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375;
  726. }
  727. return ret;
  728. };
  729. break;
  730. }
  731. case 'elastic':
  732. {
  733. easing = function easing(pos) {
  734. if (pos === !!pos) return pos;
  735. return Math.pow(2, -10 * pos) * Math.sin((pos - 0.075) * (2 * Math.PI) / 0.3) + 1;
  736. };
  737. break;
  738. }
  739. default:
  740. {
  741. easing = '<>';
  742. }
  743. }
  744. this.w.globals.easing = easing;
  745. }
  746. }, {
  747. key: "animateLine",
  748. value: function animateLine(el, from, to, speed) {
  749. el.attr(from).animate(speed).attr(to);
  750. }
  751. /*
  752. ** Animate radius of a circle element
  753. */
  754. }, {
  755. key: "animateMarker",
  756. value: function animateMarker(el, speed, easing, cb) {
  757. el.attr({
  758. opacity: 0
  759. }).animate(speed, easing).attr({
  760. opacity: 1
  761. }).afterAll(function () {
  762. cb();
  763. });
  764. }
  765. /*
  766. ** Animate rect properties
  767. */
  768. }, {
  769. key: "animateRect",
  770. value: function animateRect(el, from, to, speed, fn) {
  771. el.attr(from).animate(speed).attr(to).afterAll(function () {
  772. return fn();
  773. });
  774. }
  775. }, {
  776. key: "animatePathsGradually",
  777. value: function animatePathsGradually(params) {
  778. var el = params.el,
  779. realIndex = params.realIndex,
  780. j = params.j,
  781. fill = params.fill,
  782. pathFrom = params.pathFrom,
  783. pathTo = params.pathTo,
  784. speed = params.speed,
  785. delay = params.delay;
  786. var me = this;
  787. var w = this.w;
  788. var delayFactor = 0;
  789. if (w.config.chart.animations.animateGradually.enabled) {
  790. delayFactor = w.config.chart.animations.animateGradually.delay;
  791. }
  792. if (w.config.chart.animations.dynamicAnimation.enabled && w.globals.dataChanged && w.config.chart.type !== 'bar') {
  793. // disabled due to this bug - https://github.com/apexcharts/vue-apexcharts/issues/75
  794. delayFactor = 0;
  795. }
  796. me.morphSVG(el, realIndex, j, w.config.chart.type === 'line' && !w.globals.comboCharts ? 'stroke' : fill, pathFrom, pathTo, speed, delay * delayFactor);
  797. }
  798. }, {
  799. key: "showDelayedElements",
  800. value: function showDelayedElements() {
  801. this.w.globals.delayedElements.forEach(function (d) {
  802. var ele = d.el;
  803. ele.classList.remove('apexcharts-element-hidden');
  804. ele.classList.add('apexcharts-hidden-element-shown');
  805. });
  806. }
  807. }, {
  808. key: "animationCompleted",
  809. value: function animationCompleted(el) {
  810. var w = this.w;
  811. if (w.globals.animationEnded) return;
  812. w.globals.animationEnded = true;
  813. this.showDelayedElements();
  814. if (typeof w.config.chart.events.animationEnd === 'function') {
  815. w.config.chart.events.animationEnd(this.ctx, {
  816. el: el,
  817. w: w
  818. });
  819. }
  820. }
  821. // SVG.js animation for morphing one path to another
  822. }, {
  823. key: "morphSVG",
  824. value: function morphSVG(el, realIndex, j, fill, pathFrom, pathTo, speed, delay) {
  825. var _this = this;
  826. var w = this.w;
  827. if (!pathFrom) {
  828. pathFrom = el.attr('pathFrom');
  829. }
  830. if (!pathTo) {
  831. pathTo = el.attr('pathTo');
  832. }
  833. var disableAnimationForCorrupPath = function disableAnimationForCorrupPath(path) {
  834. if (w.config.chart.type === 'radar') {
  835. // radar chart drops the path to bottom and hence a corrup path looks ugly
  836. // therefore, disable animation for such a case
  837. speed = 1;
  838. }
  839. return "M 0 ".concat(w.globals.gridHeight);
  840. };
  841. if (!pathFrom || pathFrom.indexOf('undefined') > -1 || pathFrom.indexOf('NaN') > -1) {
  842. pathFrom = disableAnimationForCorrupPath();
  843. }
  844. if (!pathTo || pathTo.indexOf('undefined') > -1 || pathTo.indexOf('NaN') > -1) {
  845. pathTo = disableAnimationForCorrupPath();
  846. }
  847. if (!w.globals.shouldAnimate) {
  848. speed = 1;
  849. }
  850. el.plot(pathFrom).animate(1, w.globals.easing, delay).plot(pathFrom).animate(speed, w.globals.easing, delay).plot(pathTo).afterAll(function () {
  851. // a flag to indicate that the original mount function can return true now as animation finished here
  852. if (Utils$1.isNumber(j)) {
  853. if (j === w.globals.series[w.globals.maxValsInArrayIndex].length - 2 && w.globals.shouldAnimate) {
  854. _this.animationCompleted(el);
  855. }
  856. } else if (fill !== 'none' && w.globals.shouldAnimate) {
  857. if (!w.globals.comboCharts && realIndex === w.globals.series.length - 1 || w.globals.comboCharts) {
  858. _this.animationCompleted(el);
  859. }
  860. }
  861. _this.showDelayedElements();
  862. });
  863. }
  864. }]);
  865. return Animations;
  866. }();
  867. /**
  868. * ApexCharts Filters Class for setting hover/active states on the paths.
  869. *
  870. * @module Formatters
  871. **/
  872. var Filters = /*#__PURE__*/function () {
  873. function Filters(ctx) {
  874. _classCallCheck(this, Filters);
  875. this.ctx = ctx;
  876. this.w = ctx.w;
  877. }
  878. // create a re-usable filter which can be appended other filter effects and applied to multiple elements
  879. _createClass(Filters, [{
  880. key: "getDefaultFilter",
  881. value: function getDefaultFilter(el, i) {
  882. var w = this.w;
  883. el.unfilter(true);
  884. var filter = new window.SVG.Filter();
  885. filter.size('120%', '180%', '-5%', '-40%');
  886. if (w.config.states.normal.filter !== 'none') {
  887. this.applyFilter(el, i, w.config.states.normal.filter.type, w.config.states.normal.filter.value);
  888. } else {
  889. if (w.config.chart.dropShadow.enabled) {
  890. this.dropShadow(el, w.config.chart.dropShadow, i);
  891. }
  892. }
  893. }
  894. }, {
  895. key: "addNormalFilter",
  896. value: function addNormalFilter(el, i) {
  897. var w = this.w;
  898. // revert shadow if it was there
  899. // but, ignore marker as marker don't have dropshadow yet
  900. if (w.config.chart.dropShadow.enabled && !el.node.classList.contains('apexcharts-marker')) {
  901. this.dropShadow(el, w.config.chart.dropShadow, i);
  902. }
  903. }
  904. // appends dropShadow to the filter object which can be chained with other filter effects
  905. }, {
  906. key: "addLightenFilter",
  907. value: function addLightenFilter(el, i, attrs) {
  908. var _this = this;
  909. var w = this.w;
  910. var intensity = attrs.intensity;
  911. el.unfilter(true);
  912. var filter = new window.SVG.Filter();
  913. el.filter(function (add) {
  914. var shadowAttr = w.config.chart.dropShadow;
  915. if (shadowAttr.enabled) {
  916. filter = _this.addShadow(add, i, shadowAttr);
  917. } else {
  918. filter = add;
  919. }
  920. filter.componentTransfer({
  921. rgb: {
  922. type: 'linear',
  923. slope: 1.5,
  924. intercept: intensity
  925. }
  926. });
  927. });
  928. el.filterer.node.setAttribute('filterUnits', 'userSpaceOnUse');
  929. this._scaleFilterSize(el.filterer.node);
  930. }
  931. // appends dropShadow to the filter object which can be chained with other filter effects
  932. }, {
  933. key: "addDarkenFilter",
  934. value: function addDarkenFilter(el, i, attrs) {
  935. var _this2 = this;
  936. var w = this.w;
  937. var intensity = attrs.intensity;
  938. el.unfilter(true);
  939. var filter = new window.SVG.Filter();
  940. el.filter(function (add) {
  941. var shadowAttr = w.config.chart.dropShadow;
  942. if (shadowAttr.enabled) {
  943. filter = _this2.addShadow(add, i, shadowAttr);
  944. } else {
  945. filter = add;
  946. }
  947. filter.componentTransfer({
  948. rgb: {
  949. type: 'linear',
  950. slope: intensity
  951. }
  952. });
  953. });
  954. el.filterer.node.setAttribute('filterUnits', 'userSpaceOnUse');
  955. this._scaleFilterSize(el.filterer.node);
  956. }
  957. }, {
  958. key: "applyFilter",
  959. value: function applyFilter(el, i, filter) {
  960. var intensity = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.5;
  961. switch (filter) {
  962. case 'none':
  963. {
  964. this.addNormalFilter(el, i);
  965. break;
  966. }
  967. case 'lighten':
  968. {
  969. this.addLightenFilter(el, i, {
  970. intensity: intensity
  971. });
  972. break;
  973. }
  974. case 'darken':
  975. {
  976. this.addDarkenFilter(el, i, {
  977. intensity: intensity
  978. });
  979. break;
  980. }
  981. }
  982. }
  983. // appends dropShadow to the filter object which can be chained with other filter effects
  984. }, {
  985. key: "addShadow",
  986. value: function addShadow(add, i, attrs) {
  987. var _w$config$chart$dropS;
  988. var w = this.w;
  989. var blur = attrs.blur,
  990. top = attrs.top,
  991. left = attrs.left,
  992. color = attrs.color,
  993. opacity = attrs.opacity;
  994. 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) {
  995. if (w.config.chart.dropShadow.enabledOnSeries.indexOf(i) === -1) {
  996. return add;
  997. }
  998. }
  999. var shadowBlur = add.flood(Array.isArray(color) ? color[i] : color, opacity).composite(add.sourceAlpha, 'in').offset(left, top).gaussianBlur(blur).merge(add.source);
  1000. return add.blend(add.source, shadowBlur);
  1001. }
  1002. // directly adds dropShadow to the element and returns the same element.
  1003. // the only way it is different from the addShadow() function is that addShadow is chainable to other filters, while this function discards all filters and add dropShadow
  1004. }, {
  1005. key: "dropShadow",
  1006. value: function dropShadow(el, attrs) {
  1007. var _w$config$chart$dropS2;
  1008. var i = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  1009. var top = attrs.top,
  1010. left = attrs.left,
  1011. blur = attrs.blur,
  1012. color = attrs.color,
  1013. opacity = attrs.opacity,
  1014. noUserSpaceOnUse = attrs.noUserSpaceOnUse;
  1015. var w = this.w;
  1016. el.unfilter(true);
  1017. if (Utils$1.isMsEdge() && w.config.chart.type === 'radialBar') {
  1018. // in radialbar charts, dropshadow is clipping actual drawing in IE
  1019. return el;
  1020. }
  1021. 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) {
  1022. var _w$config$chart$dropS3;
  1023. 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) {
  1024. return el;
  1025. }
  1026. }
  1027. color = Array.isArray(color) ? color[i] : color;
  1028. el.filter(function (add) {
  1029. var shadowBlur = null;
  1030. if (Utils$1.isSafari() || Utils$1.isFirefox() || Utils$1.isMsEdge()) {
  1031. // safari/firefox/IE have some alternative way to use this filter
  1032. shadowBlur = add.flood(color, opacity).composite(add.sourceAlpha, 'in').offset(left, top).gaussianBlur(blur);
  1033. } else {
  1034. shadowBlur = add.flood(color, opacity).composite(add.sourceAlpha, 'in').offset(left, top).gaussianBlur(blur).merge(add.source);
  1035. }
  1036. add.blend(add.source, shadowBlur);
  1037. });
  1038. if (!noUserSpaceOnUse) {
  1039. el.filterer.node.setAttribute('filterUnits', 'userSpaceOnUse');
  1040. }
  1041. this._scaleFilterSize(el.filterer.node);
  1042. return el;
  1043. }
  1044. }, {
  1045. key: "setSelectionFilter",
  1046. value: function setSelectionFilter(el, realIndex, dataPointIndex) {
  1047. var w = this.w;
  1048. if (typeof w.globals.selectedDataPoints[realIndex] !== 'undefined') {
  1049. if (w.globals.selectedDataPoints[realIndex].indexOf(dataPointIndex) > -1) {
  1050. el.node.setAttribute('selected', true);
  1051. var activeFilter = w.config.states.active.filter;
  1052. if (activeFilter !== 'none') {
  1053. this.applyFilter(el, realIndex, activeFilter.type, activeFilter.value);
  1054. }
  1055. }
  1056. }
  1057. }
  1058. }, {
  1059. key: "_scaleFilterSize",
  1060. value: function _scaleFilterSize(el) {
  1061. var setAttributes = function setAttributes(attrs) {
  1062. for (var key in attrs) {
  1063. if (attrs.hasOwnProperty(key)) {
  1064. el.setAttribute(key, attrs[key]);
  1065. }
  1066. }
  1067. };
  1068. setAttributes({
  1069. width: '200%',
  1070. height: '200%',
  1071. x: '-50%',
  1072. y: '-50%'
  1073. });
  1074. }
  1075. }]);
  1076. return Filters;
  1077. }();
  1078. /**
  1079. * ApexCharts Graphics Class for all drawing operations.
  1080. *
  1081. * @module Graphics
  1082. **/
  1083. var Graphics = /*#__PURE__*/function () {
  1084. function Graphics(ctx) {
  1085. _classCallCheck(this, Graphics);
  1086. this.ctx = ctx;
  1087. this.w = ctx.w;
  1088. }
  1089. /*****************************************************************************
  1090. * *
  1091. * SVG Path Rounding Function *
  1092. * Copyright (C) 2014 Yona Appletree *
  1093. * *
  1094. * Licensed under the Apache License, Version 2.0 (the "License"); *
  1095. * you may not use this file except in compliance with the License. *
  1096. * You may obtain a copy of the License at *
  1097. * *
  1098. * http://www.apache.org/licenses/LICENSE-2.0 *
  1099. * *
  1100. * Unless required by applicable law or agreed to in writing, software *
  1101. * distributed under the License is distributed on an "AS IS" BASIS, *
  1102. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  1103. * See the License for the specific language governing permissions and *
  1104. * limitations under the License. *
  1105. * *
  1106. *****************************************************************************/
  1107. /**
  1108. * SVG Path rounding function. Takes an input path string and outputs a path
  1109. * string where all line-line corners have been rounded. Only supports absolute
  1110. * commands at the moment.
  1111. *
  1112. * @param pathString The SVG input path
  1113. * @param radius The amount to round the corners, either a value in the SVG
  1114. * coordinate space, or, if useFractionalRadius is true, a value
  1115. * from 0 to 1.
  1116. * @returns A new SVG path string with the rounding
  1117. */
  1118. _createClass(Graphics, [{
  1119. key: "roundPathCorners",
  1120. value: function roundPathCorners(pathString, radius) {
  1121. if (pathString.indexOf('NaN') > -1) pathString = '';
  1122. function moveTowardsLength(movingPoint, targetPoint, amount) {
  1123. var width = targetPoint.x - movingPoint.x;
  1124. var height = targetPoint.y - movingPoint.y;
  1125. var distance = Math.sqrt(width * width + height * height);
  1126. return moveTowardsFractional(movingPoint, targetPoint, Math.min(1, amount / distance));
  1127. }
  1128. function moveTowardsFractional(movingPoint, targetPoint, fraction) {
  1129. return {
  1130. x: movingPoint.x + (targetPoint.x - movingPoint.x) * fraction,
  1131. y: movingPoint.y + (targetPoint.y - movingPoint.y) * fraction
  1132. };
  1133. }
  1134. // Adjusts the ending position of a command
  1135. function adjustCommand(cmd, newPoint) {
  1136. if (cmd.length > 2) {
  1137. cmd[cmd.length - 2] = newPoint.x;
  1138. cmd[cmd.length - 1] = newPoint.y;
  1139. }
  1140. }
  1141. // Gives an {x, y} object for a command's ending position
  1142. function pointForCommand(cmd) {
  1143. return {
  1144. x: parseFloat(cmd[cmd.length - 2]),
  1145. y: parseFloat(cmd[cmd.length - 1])
  1146. };
  1147. }
  1148. // Split apart the path, handing concatonated letters and numbers
  1149. var pathParts = pathString.split(/[,\s]/).reduce(function (parts, part) {
  1150. var match = part.match('([a-zA-Z])(.+)');
  1151. if (match) {
  1152. parts.push(match[1]);
  1153. parts.push(match[2]);
  1154. } else {
  1155. parts.push(part);
  1156. }
  1157. return parts;
  1158. }, []);
  1159. // Group the commands with their arguments for easier handling
  1160. var commands = pathParts.reduce(function (commands, part) {
  1161. if (parseFloat(part) == part && commands.length) {
  1162. commands[commands.length - 1].push(part);
  1163. } else {
  1164. commands.push([part]);
  1165. }
  1166. return commands;
  1167. }, []);
  1168. // The resulting commands, also grouped
  1169. var resultCommands = [];
  1170. if (commands.length > 1) {
  1171. var startPoint = pointForCommand(commands[0]);
  1172. // Handle the close path case with a "virtual" closing line
  1173. var virtualCloseLine = null;
  1174. if (commands[commands.length - 1][0] == 'Z' && commands[0].length > 2) {
  1175. virtualCloseLine = ['L', startPoint.x, startPoint.y];
  1176. commands[commands.length - 1] = virtualCloseLine;
  1177. }
  1178. // We always use the first command (but it may be mutated)
  1179. resultCommands.push(commands[0]);
  1180. for (var cmdIndex = 1; cmdIndex < commands.length; cmdIndex++) {
  1181. var prevCmd = resultCommands[resultCommands.length - 1];
  1182. var curCmd = commands[cmdIndex];
  1183. // Handle closing case
  1184. var nextCmd = curCmd == virtualCloseLine ? commands[1] : commands[cmdIndex + 1];
  1185. // Nasty logic to decide if this path is a candidite.
  1186. if (nextCmd && prevCmd && prevCmd.length > 2 && curCmd[0] == 'L' && nextCmd.length > 2 && nextCmd[0] == 'L') {
  1187. // Calc the points we're dealing with
  1188. var prevPoint = pointForCommand(prevCmd);
  1189. var curPoint = pointForCommand(curCmd);
  1190. var nextPoint = pointForCommand(nextCmd);
  1191. // The start and end of the cuve are just our point moved towards the previous and next points, respectivly
  1192. var curveStart, curveEnd;
  1193. curveStart = moveTowardsLength(curPoint, prevPoint, radius);
  1194. curveEnd = moveTowardsLength(curPoint, nextPoint, radius);
  1195. // Adjust the current command and add it
  1196. adjustCommand(curCmd, curveStart);
  1197. curCmd.origPoint = curPoint;
  1198. resultCommands.push(curCmd);
  1199. // The curve control points are halfway between the start/end of the curve and
  1200. // the original point
  1201. var startControl = moveTowardsFractional(curveStart, curPoint, 0.5);
  1202. var endControl = moveTowardsFractional(curPoint, curveEnd, 0.5);
  1203. // Create the curve
  1204. var curveCmd = ['C', startControl.x, startControl.y, endControl.x, endControl.y, curveEnd.x, curveEnd.y];
  1205. // Save the original point for fractional calculations
  1206. curveCmd.origPoint = curPoint;
  1207. resultCommands.push(curveCmd);
  1208. } else {
  1209. // Pass through commands that don't qualify
  1210. resultCommands.push(curCmd);
  1211. }
  1212. }
  1213. // Fix up the starting point and restore the close path if the path was orignally closed
  1214. if (virtualCloseLine) {
  1215. var newStartPoint = pointForCommand(resultCommands[resultCommands.length - 1]);
  1216. resultCommands.push(['Z']);
  1217. adjustCommand(resultCommands[0], newStartPoint);
  1218. }
  1219. } else {
  1220. resultCommands = commands;
  1221. }
  1222. return resultCommands.reduce(function (str, c) {
  1223. return str + c.join(' ') + ' ';
  1224. }, '');
  1225. }
  1226. }, {
  1227. key: "drawLine",
  1228. value: function drawLine(x1, y1, x2, y2) {
  1229. var lineColor = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '#a8a8a8';
  1230. var dashArray = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  1231. var strokeWidth = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
  1232. var strokeLineCap = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'butt';
  1233. var w = this.w;
  1234. var line = w.globals.dom.Paper.line().attr({
  1235. x1: x1,
  1236. y1: y1,
  1237. x2: x2,
  1238. y2: y2,
  1239. stroke: lineColor,
  1240. 'stroke-dasharray': dashArray,
  1241. 'stroke-width': strokeWidth,
  1242. 'stroke-linecap': strokeLineCap
  1243. });
  1244. return line;
  1245. }
  1246. }, {
  1247. key: "drawRect",
  1248. value: function drawRect() {
  1249. var x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1250. var y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  1251. var x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  1252. var y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  1253. var radius = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  1254. var color = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '#fefefe';
  1255. var opacity = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 1;
  1256. var strokeWidth = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
  1257. var strokeColor = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
  1258. var strokeDashArray = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 0;
  1259. var w = this.w;
  1260. var rect = w.globals.dom.Paper.rect();
  1261. rect.attr({
  1262. x: x1,
  1263. y: y1,
  1264. width: x2 > 0 ? x2 : 0,
  1265. height: y2 > 0 ? y2 : 0,
  1266. rx: radius,
  1267. ry: radius,
  1268. opacity: opacity,
  1269. 'stroke-width': strokeWidth !== null ? strokeWidth : 0,
  1270. stroke: strokeColor !== null ? strokeColor : 'none',
  1271. 'stroke-dasharray': strokeDashArray
  1272. });
  1273. // fix apexcharts.js#1410
  1274. rect.node.setAttribute('fill', color);
  1275. return rect;
  1276. }
  1277. }, {
  1278. key: "drawPolygon",
  1279. value: function drawPolygon(polygonString) {
  1280. var stroke = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '#e1e1e1';
  1281. var strokeWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  1282. var fill = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'none';
  1283. var w = this.w;
  1284. var polygon = w.globals.dom.Paper.polygon(polygonString).attr({
  1285. fill: fill,
  1286. stroke: stroke,
  1287. 'stroke-width': strokeWidth
  1288. });
  1289. return polygon;
  1290. }
  1291. }, {
  1292. key: "drawCircle",
  1293. value: function drawCircle(radius) {
  1294. var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  1295. var w = this.w;
  1296. if (radius < 0) radius = 0;
  1297. var c = w.globals.dom.Paper.circle(radius * 2);
  1298. if (attrs !== null) {
  1299. c.attr(attrs);
  1300. }
  1301. return c;
  1302. }
  1303. }, {
  1304. key: "drawPath",
  1305. value: function drawPath(_ref) {
  1306. var _ref$d = _ref.d,
  1307. d = _ref$d === void 0 ? '' : _ref$d,
  1308. _ref$stroke = _ref.stroke,
  1309. stroke = _ref$stroke === void 0 ? '#a8a8a8' : _ref$stroke,
  1310. _ref$strokeWidth = _ref.strokeWidth,
  1311. strokeWidth = _ref$strokeWidth === void 0 ? 1 : _ref$strokeWidth,
  1312. fill = _ref.fill,
  1313. _ref$fillOpacity = _ref.fillOpacity,
  1314. fillOpacity = _ref$fillOpacity === void 0 ? 1 : _ref$fillOpacity,
  1315. _ref$strokeOpacity = _ref.strokeOpacity,
  1316. strokeOpacity = _ref$strokeOpacity === void 0 ? 1 : _ref$strokeOpacity,
  1317. classes = _ref.classes,
  1318. _ref$strokeLinecap = _ref.strokeLinecap,
  1319. strokeLinecap = _ref$strokeLinecap === void 0 ? null : _ref$strokeLinecap,
  1320. _ref$strokeDashArray = _ref.strokeDashArray,
  1321. strokeDashArray = _ref$strokeDashArray === void 0 ? 0 : _ref$strokeDashArray;
  1322. var w = this.w;
  1323. if (strokeLinecap === null) {
  1324. strokeLinecap = w.config.stroke.lineCap;
  1325. }
  1326. if (d.indexOf('undefined') > -1 || d.indexOf('NaN') > -1) {
  1327. d = "M 0 ".concat(w.globals.gridHeight);
  1328. }
  1329. var p = w.globals.dom.Paper.path(d).attr({
  1330. fill: fill,
  1331. 'fill-opacity': fillOpacity,
  1332. stroke: stroke,
  1333. 'stroke-opacity': strokeOpacity,
  1334. 'stroke-linecap': strokeLinecap,
  1335. 'stroke-width': strokeWidth,
  1336. 'stroke-dasharray': strokeDashArray,
  1337. class: classes
  1338. });
  1339. return p;
  1340. }
  1341. }, {
  1342. key: "group",
  1343. value: function group() {
  1344. var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  1345. var w = this.w;
  1346. var g = w.globals.dom.Paper.group();
  1347. if (attrs !== null) {
  1348. g.attr(attrs);
  1349. }
  1350. return g;
  1351. }
  1352. }, {
  1353. key: "move",
  1354. value: function move(x, y) {
  1355. var move = ['M', x, y].join(' ');
  1356. return move;
  1357. }
  1358. }, {
  1359. key: "line",
  1360. value: function line(x, y) {
  1361. var hORv = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1362. var line = null;
  1363. if (hORv === null) {
  1364. line = [' L', x, y].join(' ');
  1365. } else if (hORv === 'H') {
  1366. line = [' H', x].join(' ');
  1367. } else if (hORv === 'V') {
  1368. line = [' V', y].join(' ');
  1369. }
  1370. return line;
  1371. }
  1372. }, {
  1373. key: "curve",
  1374. value: function curve(x1, y1, x2, y2, x, y) {
  1375. var curve = ['C', x1, y1, x2, y2, x, y].join(' ');
  1376. return curve;
  1377. }
  1378. }, {
  1379. key: "quadraticCurve",
  1380. value: function quadraticCurve(x1, y1, x, y) {
  1381. var curve = ['Q', x1, y1, x, y].join(' ');
  1382. return curve;
  1383. }
  1384. }, {
  1385. key: "arc",
  1386. value: function arc(rx, ry, axisRotation, largeArcFlag, sweepFlag, x, y) {
  1387. var relative = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
  1388. var coord = 'A';
  1389. if (relative) coord = 'a';
  1390. var arc = [coord, rx, ry, axisRotation, largeArcFlag, sweepFlag, x, y].join(' ');
  1391. return arc;
  1392. }
  1393. /**
  1394. * @memberof Graphics
  1395. * @param {object}
  1396. * i = series's index
  1397. * 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
  1398. * pathFrom = existing pathFrom to animateTo
  1399. * pathTo = new Path to which d attr will be animated from pathFrom to pathTo
  1400. * stroke = line Color
  1401. * strokeWidth = width of path Line
  1402. * fill = it can be gradient, single color, pattern or image
  1403. * animationDelay = how much to delay when starting animation (in milliseconds)
  1404. * dataChangeSpeed = for dynamic animations, when data changes
  1405. * className = class attribute to add
  1406. * @return {object} svg.js path object
  1407. **/
  1408. }, {
  1409. key: "renderPaths",
  1410. value: function renderPaths(_ref2) {
  1411. var j = _ref2.j,
  1412. realIndex = _ref2.realIndex,
  1413. pathFrom = _ref2.pathFrom,
  1414. pathTo = _ref2.pathTo,
  1415. stroke = _ref2.stroke,
  1416. strokeWidth = _ref2.strokeWidth,
  1417. strokeLinecap = _ref2.strokeLinecap,
  1418. fill = _ref2.fill,
  1419. animationDelay = _ref2.animationDelay,
  1420. initialSpeed = _ref2.initialSpeed,
  1421. dataChangeSpeed = _ref2.dataChangeSpeed,
  1422. className = _ref2.className,
  1423. chartType = _ref2.chartType,
  1424. _ref2$shouldClipToGri = _ref2.shouldClipToGrid,
  1425. shouldClipToGrid = _ref2$shouldClipToGri === void 0 ? true : _ref2$shouldClipToGri,
  1426. _ref2$bindEventsOnPat = _ref2.bindEventsOnPaths,
  1427. bindEventsOnPaths = _ref2$bindEventsOnPat === void 0 ? true : _ref2$bindEventsOnPat,
  1428. _ref2$drawShadow = _ref2.drawShadow,
  1429. drawShadow = _ref2$drawShadow === void 0 ? true : _ref2$drawShadow;
  1430. var w = this.w;
  1431. var filters = new Filters(this.ctx);
  1432. var anim = new Animations(this.ctx);
  1433. var initialAnim = this.w.config.chart.animations.enabled;
  1434. var dynamicAnim = initialAnim && this.w.config.chart.animations.dynamicAnimation.enabled;
  1435. var d;
  1436. var shouldAnimate = !!(initialAnim && !w.globals.resized || dynamicAnim && w.globals.dataChanged && w.globals.shouldAnimate);
  1437. if (shouldAnimate) {
  1438. d = pathFrom;
  1439. } else {
  1440. d = pathTo;
  1441. w.globals.animationEnded = true;
  1442. }
  1443. var strokeDashArrayOpt = w.config.stroke.dashArray;
  1444. var strokeDashArray = 0;
  1445. if (Array.isArray(strokeDashArrayOpt)) {
  1446. strokeDashArray = strokeDashArrayOpt[realIndex];
  1447. } else {
  1448. strokeDashArray = w.config.stroke.dashArray;
  1449. }
  1450. var el = this.drawPath({
  1451. d: d,
  1452. stroke: stroke,
  1453. strokeWidth: strokeWidth,
  1454. fill: fill,
  1455. fillOpacity: 1,
  1456. classes: className,
  1457. strokeLinecap: strokeLinecap,
  1458. strokeDashArray: strokeDashArray
  1459. });
  1460. el.attr('index', realIndex);
  1461. if (shouldClipToGrid) {
  1462. if (chartType === 'bar' && !w.globals.isHorizontal || w.globals.comboCharts) {
  1463. el.attr({
  1464. 'clip-path': "url(#gridRectBarMask".concat(w.globals.cuid, ")")
  1465. });
  1466. } else {
  1467. el.attr({
  1468. 'clip-path': "url(#gridRectMask".concat(w.globals.cuid, ")")
  1469. });
  1470. }
  1471. }
  1472. // const defaultFilter = el.filterer
  1473. if (w.config.states.normal.filter.type !== 'none') {
  1474. filters.getDefaultFilter(el, realIndex);
  1475. } else {
  1476. if (w.config.chart.dropShadow.enabled && drawShadow) {
  1477. var shadow = w.config.chart.dropShadow;
  1478. filters.dropShadow(el, shadow, realIndex);
  1479. }
  1480. }
  1481. if (bindEventsOnPaths) {
  1482. el.node.addEventListener('mouseenter', this.pathMouseEnter.bind(this, el));
  1483. el.node.addEventListener('mouseleave', this.pathMouseLeave.bind(this, el));
  1484. el.node.addEventListener('mousedown', this.pathMouseDown.bind(this, el));
  1485. }
  1486. el.attr({
  1487. pathTo: pathTo,
  1488. pathFrom: pathFrom
  1489. });
  1490. var defaultAnimateOpts = {
  1491. el: el,
  1492. j: j,
  1493. realIndex: realIndex,
  1494. pathFrom: pathFrom,
  1495. pathTo: pathTo,
  1496. fill: fill,
  1497. strokeWidth: strokeWidth,
  1498. delay: animationDelay
  1499. };
  1500. if (initialAnim && !w.globals.resized && !w.globals.dataChanged) {
  1501. anim.animatePathsGradually(_objectSpread2(_objectSpread2({}, defaultAnimateOpts), {}, {
  1502. speed: initialSpeed
  1503. }));
  1504. } else {
  1505. if (w.globals.resized || !w.globals.dataChanged) {
  1506. anim.showDelayedElements();
  1507. }
  1508. }
  1509. if (w.globals.dataChanged && dynamicAnim && shouldAnimate) {
  1510. anim.animatePathsGradually(_objectSpread2(_objectSpread2({}, defaultAnimateOpts), {}, {
  1511. speed: dataChangeSpeed
  1512. }));
  1513. }
  1514. return el;
  1515. }
  1516. }, {
  1517. key: "drawPattern",
  1518. value: function drawPattern(style, width, height) {
  1519. var stroke = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '#a8a8a8';
  1520. var strokeWidth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  1521. var w = this.w;
  1522. var p = w.globals.dom.Paper.pattern(width, height, function (add) {
  1523. if (style === 'horizontalLines') {
  1524. add.line(0, 0, height, 0).stroke({
  1525. color: stroke,
  1526. width: strokeWidth + 1
  1527. });
  1528. } else if (style === 'verticalLines') {
  1529. add.line(0, 0, 0, width).stroke({
  1530. color: stroke,
  1531. width: strokeWidth + 1
  1532. });
  1533. } else if (style === 'slantedLines') {
  1534. add.line(0, 0, width, height).stroke({
  1535. color: stroke,
  1536. width: strokeWidth
  1537. });
  1538. } else if (style === 'squares') {
  1539. add.rect(width, height).fill('none').stroke({
  1540. color: stroke,
  1541. width: strokeWidth
  1542. });
  1543. } else if (style === 'circles') {
  1544. add.circle(width).fill('none').stroke({
  1545. color: stroke,
  1546. width: strokeWidth
  1547. });
  1548. }
  1549. });
  1550. return p;
  1551. }
  1552. }, {
  1553. key: "drawGradient",
  1554. value: function drawGradient(style, gfrom, gto, opacityFrom, opacityTo) {
  1555. var size = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
  1556. var stops = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
  1557. var colorStops = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
  1558. var i = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 0;
  1559. var w = this.w;
  1560. var g;
  1561. if (gfrom.length < 9 && gfrom.indexOf('#') === 0) {
  1562. // if the hex contains alpha and is of 9 digit, skip the opacity
  1563. gfrom = Utils$1.hexToRgba(gfrom, opacityFrom);
  1564. }
  1565. if (gto.length < 9 && gto.indexOf('#') === 0) {
  1566. gto = Utils$1.hexToRgba(gto, opacityTo);
  1567. }
  1568. var stop1 = 0;
  1569. var stop2 = 1;
  1570. var stop3 = 1;
  1571. var stop4 = null;
  1572. if (stops !== null) {
  1573. stop1 = typeof stops[0] !== 'undefined' ? stops[0] / 100 : 0;
  1574. stop2 = typeof stops[1] !== 'undefined' ? stops[1] / 100 : 1;
  1575. stop3 = typeof stops[2] !== 'undefined' ? stops[2] / 100 : 1;
  1576. stop4 = typeof stops[3] !== 'undefined' ? stops[3] / 100 : null;
  1577. }
  1578. var radial = !!(w.config.chart.type === 'donut' || w.config.chart.type === 'pie' || w.config.chart.type === 'polarArea' || w.config.chart.type === 'bubble');
  1579. if (colorStops === null || colorStops.length === 0) {
  1580. g = w.globals.dom.Paper.gradient(radial ? 'radial' : 'linear', function (stop) {
  1581. stop.at(stop1, gfrom, opacityFrom);
  1582. stop.at(stop2, gto, opacityTo);
  1583. stop.at(stop3, gto, opacityTo);
  1584. if (stop4 !== null) {
  1585. stop.at(stop4, gfrom, opacityFrom);
  1586. }
  1587. });
  1588. } else {
  1589. g = w.globals.dom.Paper.gradient(radial ? 'radial' : 'linear', function (stop) {
  1590. var gradientStops = Array.isArray(colorStops[i]) ? colorStops[i] : colorStops;
  1591. gradientStops.forEach(function (s) {
  1592. stop.at(s.offset / 100, s.color, s.opacity);
  1593. });
  1594. });
  1595. }
  1596. if (!radial) {
  1597. if (style === 'vertical') {
  1598. g.from(0, 0).to(0, 1);
  1599. } else if (style === 'diagonal') {
  1600. g.from(0, 0).to(1, 1);
  1601. } else if (style === 'horizontal') {
  1602. g.from(0, 1).to(1, 1);
  1603. } else if (style === 'diagonal2') {
  1604. g.from(1, 0).to(0, 1);
  1605. }
  1606. } else {
  1607. var offx = w.globals.gridWidth / 2;
  1608. var offy = w.globals.gridHeight / 2;
  1609. if (w.config.chart.type !== 'bubble') {
  1610. g.attr({
  1611. gradientUnits: 'userSpaceOnUse',
  1612. cx: offx,
  1613. cy: offy,
  1614. r: size
  1615. });
  1616. } else {
  1617. g.attr({
  1618. cx: 0.5,
  1619. cy: 0.5,
  1620. r: 0.8,
  1621. fx: 0.2,
  1622. fy: 0.2
  1623. });
  1624. }
  1625. }
  1626. return g;
  1627. }
  1628. }, {
  1629. key: "getTextBasedOnMaxWidth",
  1630. value: function getTextBasedOnMaxWidth(_ref3) {
  1631. var text = _ref3.text,
  1632. maxWidth = _ref3.maxWidth,
  1633. fontSize = _ref3.fontSize,
  1634. fontFamily = _ref3.fontFamily;
  1635. var tRects = this.getTextRects(text, fontSize, fontFamily);
  1636. var wordWidth = tRects.width / text.length;
  1637. var wordsBasedOnWidth = Math.floor(maxWidth / wordWidth);
  1638. if (maxWidth < tRects.width) {
  1639. return text.slice(0, wordsBasedOnWidth - 3) + '...';
  1640. }
  1641. return text;
  1642. }
  1643. }, {
  1644. key: "drawText",
  1645. value: function drawText(_ref4) {
  1646. var _this = this;
  1647. var x = _ref4.x,
  1648. y = _ref4.y,
  1649. text = _ref4.text,
  1650. textAnchor = _ref4.textAnchor,
  1651. fontSize = _ref4.fontSize,
  1652. fontFamily = _ref4.fontFamily,
  1653. fontWeight = _ref4.fontWeight,
  1654. foreColor = _ref4.foreColor,
  1655. opacity = _ref4.opacity,
  1656. maxWidth = _ref4.maxWidth,
  1657. _ref4$cssClass = _ref4.cssClass,
  1658. cssClass = _ref4$cssClass === void 0 ? '' : _ref4$cssClass,
  1659. _ref4$isPlainText = _ref4.isPlainText,
  1660. isPlainText = _ref4$isPlainText === void 0 ? true : _ref4$isPlainText,
  1661. _ref4$dominantBaselin = _ref4.dominantBaseline,
  1662. dominantBaseline = _ref4$dominantBaselin === void 0 ? 'auto' : _ref4$dominantBaselin;
  1663. var w = this.w;
  1664. if (typeof text === 'undefined') text = '';
  1665. var truncatedText = text;
  1666. if (!textAnchor) {
  1667. textAnchor = 'start';
  1668. }
  1669. if (!foreColor || !foreColor.length) {
  1670. foreColor = w.config.chart.foreColor;
  1671. }
  1672. fontFamily = fontFamily || w.config.chart.fontFamily;
  1673. fontSize = fontSize || '11px';
  1674. fontWeight = fontWeight || 'regular';
  1675. var commonProps = {
  1676. maxWidth: maxWidth,
  1677. fontSize: fontSize,
  1678. fontFamily: fontFamily
  1679. };
  1680. var elText;
  1681. if (Array.isArray(text)) {
  1682. elText = w.globals.dom.Paper.text(function (add) {
  1683. for (var i = 0; i < text.length; i++) {
  1684. truncatedText = text[i];
  1685. if (maxWidth) {
  1686. truncatedText = _this.getTextBasedOnMaxWidth(_objectSpread2({
  1687. text: text[i]
  1688. }, commonProps));
  1689. }
  1690. i === 0 ? add.tspan(truncatedText) : add.tspan(truncatedText).newLine();
  1691. }
  1692. });
  1693. } else {
  1694. if (maxWidth) {
  1695. truncatedText = this.getTextBasedOnMaxWidth(_objectSpread2({
  1696. text: text
  1697. }, commonProps));
  1698. }
  1699. elText = isPlainText ? w.globals.dom.Paper.plain(text) : w.globals.dom.Paper.text(function (add) {
  1700. return add.tspan(truncatedText);
  1701. });
  1702. }
  1703. elText.attr({
  1704. x: x,
  1705. y: y,
  1706. 'text-anchor': textAnchor,
  1707. 'dominant-baseline': dominantBaseline,
  1708. 'font-size': fontSize,
  1709. 'font-family': fontFamily,
  1710. 'font-weight': fontWeight,
  1711. fill: foreColor,
  1712. class: 'apexcharts-text ' + cssClass
  1713. });
  1714. elText.node.style.fontFamily = fontFamily;
  1715. elText.node.style.opacity = opacity;
  1716. return elText;
  1717. }
  1718. }, {
  1719. key: "getMarkerPath",
  1720. value: function getMarkerPath(x, y, type, size) {
  1721. var d = '';
  1722. switch (type) {
  1723. case 'cross':
  1724. size = size / 1.4;
  1725. 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);
  1726. break;
  1727. case 'plus':
  1728. size = size / 1.12;
  1729. 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);
  1730. break;
  1731. case 'star':
  1732. case 'sparkle':
  1733. var points = 5;
  1734. size = size * 1.15;
  1735. if (type === 'sparkle') {
  1736. size = size / 1.1;
  1737. points = 4;
  1738. }
  1739. var step = Math.PI / points;
  1740. for (var i = 0; i <= 2 * points; i++) {
  1741. var angle = i * step;
  1742. var radius = i % 2 === 0 ? size : size / 2;
  1743. var xPos = x + radius * Math.sin(angle);
  1744. var yPos = y - radius * Math.cos(angle);
  1745. d += (i === 0 ? 'M' : 'L') + xPos + ',' + yPos;
  1746. }
  1747. d += 'Z';
  1748. break;
  1749. case 'triangle':
  1750. 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");
  1751. break;
  1752. case 'square':
  1753. case 'rect':
  1754. size = size / 1.125;
  1755. 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");
  1756. break;
  1757. case 'diamond':
  1758. size = size * 1.05;
  1759. 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");
  1760. break;
  1761. case 'line':
  1762. size = size / 1.1;
  1763. d = "M ".concat(x - size, " ").concat(y, " \n L ").concat(x + size, " ").concat(y);
  1764. break;
  1765. case 'circle':
  1766. default:
  1767. size = size * 2;
  1768. 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");
  1769. break;
  1770. }
  1771. return d;
  1772. }
  1773. /**
  1774. * @param {number} x - The x-coordinate of the marker
  1775. * @param {number} y - The y-coordinate of the marker.
  1776. * @param {number} size - The size of the marker
  1777. * @param {Object} opts - The options for the marker.
  1778. * @returns {Object} The created marker.
  1779. */
  1780. }, {
  1781. key: "drawMarkerShape",
  1782. value: function drawMarkerShape(x, y, type, size, opts) {
  1783. var path = this.drawPath({
  1784. d: this.getMarkerPath(x, y, type, size, opts),
  1785. stroke: opts.pointStrokeColor,
  1786. strokeDashArray: opts.pointStrokeDashArray,
  1787. strokeWidth: opts.pointStrokeWidth,
  1788. fill: opts.pointFillColor,
  1789. fillOpacity: opts.pointFillOpacity,
  1790. strokeOpacity: opts.pointStrokeOpacity
  1791. });
  1792. path.attr({
  1793. cx: x,
  1794. cy: y,
  1795. shape: opts.shape,
  1796. class: opts.class ? opts.class : ''
  1797. });
  1798. return path;
  1799. }
  1800. }, {
  1801. key: "drawMarker",
  1802. value: function drawMarker(x, y, opts) {
  1803. x = x || 0;
  1804. var size = opts.pSize || 0;
  1805. if (!Utils$1.isNumber(y)) {
  1806. size = 0;
  1807. y = 0;
  1808. }
  1809. 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' ? {
  1810. pointStrokeColor: opts.pointFillColor,
  1811. pointStrokeOpacity: opts.pointFillOpacity
  1812. } : {}));
  1813. }
  1814. }, {
  1815. key: "pathMouseEnter",
  1816. value: function pathMouseEnter(path, e) {
  1817. var w = this.w;
  1818. var filters = new Filters(this.ctx);
  1819. var i = parseInt(path.node.getAttribute('index'), 10);
  1820. var j = parseInt(path.node.getAttribute('j'), 10);
  1821. if (typeof w.config.chart.events.dataPointMouseEnter === 'function') {
  1822. w.config.chart.events.dataPointMouseEnter(e, this.ctx, {
  1823. seriesIndex: i,
  1824. dataPointIndex: j,
  1825. w: w
  1826. });
  1827. }
  1828. this.ctx.events.fireEvent('dataPointMouseEnter', [e, this.ctx, {
  1829. seriesIndex: i,
  1830. dataPointIndex: j,
  1831. w: w
  1832. }]);
  1833. if (w.config.states.active.filter.type !== 'none') {
  1834. if (path.node.getAttribute('selected') === 'true') {
  1835. return;
  1836. }
  1837. }
  1838. if (w.config.states.hover.filter.type !== 'none') {
  1839. if (!w.globals.isTouchDevice) {
  1840. var hoverFilter = w.config.states.hover.filter;
  1841. filters.applyFilter(path, i, hoverFilter.type, hoverFilter.value);
  1842. }
  1843. }
  1844. }
  1845. }, {
  1846. key: "pathMouseLeave",
  1847. value: function pathMouseLeave(path, e) {
  1848. var w = this.w;
  1849. var filters = new Filters(this.ctx);
  1850. var i = parseInt(path.node.getAttribute('index'), 10);
  1851. var j = parseInt(path.node.getAttribute('j'), 10);
  1852. if (typeof w.config.chart.events.dataPointMouseLeave === 'function') {
  1853. w.config.chart.events.dataPointMouseLeave(e, this.ctx, {
  1854. seriesIndex: i,
  1855. dataPointIndex: j,
  1856. w: w
  1857. });
  1858. }
  1859. this.ctx.events.fireEvent('dataPointMouseLeave', [e, this.ctx, {
  1860. seriesIndex: i,
  1861. dataPointIndex: j,
  1862. w: w
  1863. }]);
  1864. if (w.config.states.active.filter.type !== 'none') {
  1865. if (path.node.getAttribute('selected') === 'true') {
  1866. return;
  1867. }
  1868. }
  1869. if (w.config.states.hover.filter.type !== 'none') {
  1870. filters.getDefaultFilter(path, i);
  1871. }
  1872. }
  1873. }, {
  1874. key: "pathMouseDown",
  1875. value: function pathMouseDown(path, e) {
  1876. var w = this.w;
  1877. var filters = new Filters(this.ctx);
  1878. var i = parseInt(path.node.getAttribute('index'), 10);
  1879. var j = parseInt(path.node.getAttribute('j'), 10);
  1880. var selected = 'false';
  1881. if (path.node.getAttribute('selected') === 'true') {
  1882. path.node.setAttribute('selected', 'false');
  1883. if (w.globals.selectedDataPoints[i].indexOf(j) > -1) {
  1884. var index = w.globals.selectedDataPoints[i].indexOf(j);
  1885. w.globals.selectedDataPoints[i].splice(index, 1);
  1886. }
  1887. } else {
  1888. if (!w.config.states.active.allowMultipleDataPointsSelection && w.globals.selectedDataPoints.length > 0) {
  1889. w.globals.selectedDataPoints = [];
  1890. var elPaths = w.globals.dom.Paper.select('.apexcharts-series path').members;
  1891. var elCircles = w.globals.dom.Paper.select('.apexcharts-series circle, .apexcharts-series rect').members;
  1892. var deSelect = function deSelect(els) {
  1893. Array.prototype.forEach.call(els, function (el) {
  1894. el.node.setAttribute('selected', 'false');
  1895. filters.getDefaultFilter(el, i);
  1896. });
  1897. };
  1898. deSelect(elPaths);
  1899. deSelect(elCircles);
  1900. }
  1901. path.node.setAttribute('selected', 'true');
  1902. selected = 'true';
  1903. if (typeof w.globals.selectedDataPoints[i] === 'undefined') {
  1904. w.globals.selectedDataPoints[i] = [];
  1905. }
  1906. w.globals.selectedDataPoints[i].push(j);
  1907. }
  1908. if (selected === 'true') {
  1909. var activeFilter = w.config.states.active.filter;
  1910. if (activeFilter !== 'none') {
  1911. filters.applyFilter(path, i, activeFilter.type, activeFilter.value);
  1912. } else {
  1913. // Reapply the hover filter in case it was removed by `deselect`when there is no active filter and it is not a touch device
  1914. if (w.config.states.hover.filter !== 'none') {
  1915. if (!w.globals.isTouchDevice) {
  1916. var hoverFilter = w.config.states.hover.filter;
  1917. filters.applyFilter(path, i, hoverFilter.type, hoverFilter.value);
  1918. }
  1919. }
  1920. }
  1921. } else {
  1922. // If the item was deselected, apply hover state filter if it is not a touch device
  1923. if (w.config.states.active.filter.type !== 'none') {
  1924. if (w.config.states.hover.filter.type !== 'none' && !w.globals.isTouchDevice) {
  1925. var hoverFilter = w.config.states.hover.filter;
  1926. filters.applyFilter(path, i, hoverFilter.type, hoverFilter.value);
  1927. } else {
  1928. filters.getDefaultFilter(path, i);
  1929. }
  1930. }
  1931. }
  1932. if (typeof w.config.chart.events.dataPointSelection === 'function') {
  1933. w.config.chart.events.dataPointSelection(e, this.ctx, {
  1934. selectedDataPoints: w.globals.selectedDataPoints,
  1935. seriesIndex: i,
  1936. dataPointIndex: j,
  1937. w: w
  1938. });
  1939. }
  1940. if (e) {
  1941. this.ctx.events.fireEvent('dataPointSelection', [e, this.ctx, {
  1942. selectedDataPoints: w.globals.selectedDataPoints,
  1943. seriesIndex: i,
  1944. dataPointIndex: j,
  1945. w: w
  1946. }]);
  1947. }
  1948. }
  1949. }, {
  1950. key: "rotateAroundCenter",
  1951. value: function rotateAroundCenter(el) {
  1952. var coord = {};
  1953. if (el && typeof el.getBBox === 'function') {
  1954. coord = el.getBBox();
  1955. }
  1956. var x = coord.x + coord.width / 2;
  1957. var y = coord.y + coord.height / 2;
  1958. return {
  1959. x: x,
  1960. y: y
  1961. };
  1962. }
  1963. }, {
  1964. key: "getTextRects",
  1965. value: function getTextRects(text, fontSize, fontFamily, transform) {
  1966. var useBBox = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  1967. var w = this.w;
  1968. var virtualText = this.drawText({
  1969. x: -200,
  1970. y: -200,
  1971. text: text,
  1972. textAnchor: 'start',
  1973. fontSize: fontSize,
  1974. fontFamily: fontFamily,
  1975. foreColor: '#fff',
  1976. opacity: 0
  1977. });
  1978. if (transform) {
  1979. virtualText.attr('transform', transform);
  1980. }
  1981. w.globals.dom.Paper.add(virtualText);
  1982. var rect = virtualText.bbox();
  1983. if (!useBBox) {
  1984. rect = virtualText.node.getBoundingClientRect();
  1985. }
  1986. virtualText.remove();
  1987. return {
  1988. width: rect.width,
  1989. height: rect.height
  1990. };
  1991. }
  1992. /**
  1993. * append ... to long text
  1994. * http://stackoverflow.com/questions/9241315/trimming-text-to-a-given-pixel-width-in-svg
  1995. * @memberof Graphics
  1996. **/
  1997. }, {
  1998. key: "placeTextWithEllipsis",
  1999. value: function placeTextWithEllipsis(textObj, textString, width) {
  2000. if (typeof textObj.getComputedTextLength !== 'function') return;
  2001. textObj.textContent = textString;
  2002. if (textString.length > 0) {
  2003. // ellipsis is needed
  2004. if (textObj.getComputedTextLength() >= width / 1.1) {
  2005. for (var x = textString.length - 3; x > 0; x -= 3) {
  2006. if (textObj.getSubStringLength(0, x) <= width / 1.1) {
  2007. textObj.textContent = textString.substring(0, x) + '...';
  2008. return;
  2009. }
  2010. }
  2011. textObj.textContent = '.'; // can't place at all
  2012. }
  2013. }
  2014. }
  2015. }], [{
  2016. key: "setAttrs",
  2017. value: function setAttrs(el, attrs) {
  2018. for (var key in attrs) {
  2019. if (attrs.hasOwnProperty(key)) {
  2020. el.setAttribute(key, attrs[key]);
  2021. }
  2022. }
  2023. }
  2024. }]);
  2025. return Graphics;
  2026. }();
  2027. /*
  2028. ** Util functions which are dependent on ApexCharts instance
  2029. */
  2030. var CoreUtils = /*#__PURE__*/function () {
  2031. function CoreUtils(ctx) {
  2032. _classCallCheck(this, CoreUtils);
  2033. this.ctx = ctx;
  2034. this.w = ctx.w;
  2035. }
  2036. _createClass(CoreUtils, [{
  2037. key: "getStackedSeriesTotals",
  2038. value:
  2039. /**
  2040. * @memberof CoreUtils
  2041. * returns the sum of all individual values in a multiple stacked series
  2042. * Eg. w.globals.series = [[32,33,43,12], [2,3,5,1]]
  2043. * @return [34,36,48,13]
  2044. **/
  2045. function getStackedSeriesTotals() {
  2046. var excludedSeriesIndices = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  2047. var w = this.w;
  2048. var total = [];
  2049. if (w.globals.series.length === 0) return total;
  2050. for (var i = 0; i < w.globals.series[w.globals.maxValsInArrayIndex].length; i++) {
  2051. var t = 0;
  2052. for (var j = 0; j < w.globals.series.length; j++) {
  2053. if (typeof w.globals.series[j][i] !== 'undefined' && excludedSeriesIndices.indexOf(j) === -1) {
  2054. t += w.globals.series[j][i];
  2055. }
  2056. }
  2057. total.push(t);
  2058. }
  2059. return total;
  2060. }
  2061. // get total of the all values inside all series
  2062. }, {
  2063. key: "getSeriesTotalByIndex",
  2064. value: function getSeriesTotalByIndex() {
  2065. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2066. if (index === null) {
  2067. // non-plot chart types - pie / donut / circle
  2068. return this.w.config.series.reduce(function (acc, cur) {
  2069. return acc + cur;
  2070. }, 0);
  2071. } else {
  2072. // axis charts - supporting multiple series
  2073. return this.w.globals.series[index].reduce(function (acc, cur) {
  2074. return acc + cur;
  2075. }, 0);
  2076. }
  2077. }
  2078. /**
  2079. * @memberof CoreUtils
  2080. * returns the sum of values in a multiple stacked grouped charts
  2081. * Eg. w.globals.series = [[32,33,43,12], [2,3,5,1], [43, 23, 34, 22]]
  2082. * series 1 and 2 are in a group, while series 3 is in another group
  2083. * @return [[34, 36, 48, 12], [43, 23, 34, 22]]
  2084. **/
  2085. }, {
  2086. key: "getStackedSeriesTotalsByGroups",
  2087. value: function getStackedSeriesTotalsByGroups() {
  2088. var _this = this;
  2089. var w = this.w;
  2090. var total = [];
  2091. w.globals.seriesGroups.forEach(function (sg) {
  2092. var includedIndexes = [];
  2093. w.config.series.forEach(function (s, si) {
  2094. if (sg.indexOf(w.globals.seriesNames[si]) > -1) {
  2095. includedIndexes.push(si);
  2096. }
  2097. });
  2098. var excludedIndices = w.globals.series.map(function (_, fi) {
  2099. return includedIndexes.indexOf(fi) === -1 ? fi : -1;
  2100. }).filter(function (f) {
  2101. return f !== -1;
  2102. });
  2103. total.push(_this.getStackedSeriesTotals(excludedIndices));
  2104. });
  2105. return total;
  2106. }
  2107. }, {
  2108. key: "setSeriesYAxisMappings",
  2109. value: function setSeriesYAxisMappings() {
  2110. var gl = this.w.globals;
  2111. var cnf = this.w.config;
  2112. // The old config method to map multiple series to a y axis is to
  2113. // include one yaxis config per series but set each yaxis seriesName to the
  2114. // same series name. This relies on indexing equivalence to map series to
  2115. // an axis: series[n] => yaxis[n]. This needs to be retained for compatibility.
  2116. // But we introduce an alternative that explicitly configures yaxis elements
  2117. // with the series that will be referenced to them (seriesName: []). This
  2118. // only requires including the yaxis elements that will be seen on the chart.
  2119. // Old way:
  2120. // ya: s
  2121. // 0: 0
  2122. // 1: 1
  2123. // 2: 1
  2124. // 3: 1
  2125. // 4: 1
  2126. // Axes 0..4 are all scaled and all will be rendered unless the axes are
  2127. // show: false. If the chart is stacked, it's assumed that series 1..4 are
  2128. // the contributing series. This is not particularly intuitive.
  2129. // New way:
  2130. // ya: s
  2131. // 0: [0]
  2132. // 1: [1,2,3,4]
  2133. // If the chart is stacked, it can be assumed that any axis with multiple
  2134. // series is stacked.
  2135. //
  2136. // If this is an old chart and we are being backward compatible, it will be
  2137. // expected that each series is associated with it's corresponding yaxis
  2138. // through their indices, one-to-one.
  2139. // If yaxis.seriesName matches series.name, we have indices yi and si.
  2140. // A name match where yi != si is interpretted as yaxis[yi] and yaxis[si]
  2141. // will both be scaled to fit the combined series[si] and series[yi].
  2142. // Consider series named: S0,S1,S2 and yaxes A0,A1,A2.
  2143. //
  2144. // Example 1: A0 and A1 scaled the same.
  2145. // A0.seriesName: S0
  2146. // A1.seriesName: S0
  2147. // A2.seriesName: S2
  2148. // Then A1 <-> A0
  2149. //
  2150. // Example 2: A0, A1 and A2 all scaled the same.
  2151. // A0.seriesName: S2
  2152. // A1.seriesName: S0
  2153. // A2.seriesName: S1
  2154. // A0 <-> A2, A1 <-> A0, A2 <-> A1 --->>> A0 <-> A1 <-> A2
  2155. var axisSeriesMap = [];
  2156. var seriesYAxisReverseMap = [];
  2157. var unassignedSeriesIndices = [];
  2158. var seriesNameArrayStyle = gl.series.length > cnf.yaxis.length || cnf.yaxis.some(function (a) {
  2159. return Array.isArray(a.seriesName);
  2160. });
  2161. cnf.series.forEach(function (s, i) {
  2162. unassignedSeriesIndices.push(i);
  2163. seriesYAxisReverseMap.push(null);
  2164. });
  2165. cnf.yaxis.forEach(function (yaxe, yi) {
  2166. axisSeriesMap[yi] = [];
  2167. });
  2168. var unassignedYAxisIndices = [];
  2169. // here, we loop through the yaxis array and find the item which has "seriesName" property
  2170. cnf.yaxis.forEach(function (yaxe, yi) {
  2171. var assigned = false;
  2172. // Allow seriesName to be either a string (for backward compatibility),
  2173. // in which case, handle multiple yaxes referencing the same series.
  2174. // or an array of strings so that a yaxis can reference multiple series.
  2175. // Feature request #4237
  2176. if (yaxe.seriesName) {
  2177. var seriesNames = [];
  2178. if (Array.isArray(yaxe.seriesName)) {
  2179. seriesNames = yaxe.seriesName;
  2180. } else {
  2181. seriesNames.push(yaxe.seriesName);
  2182. }
  2183. seriesNames.forEach(function (name) {
  2184. cnf.series.forEach(function (s, si) {
  2185. if (s.name === name) {
  2186. var remove = si;
  2187. if (yi === si || seriesNameArrayStyle) {
  2188. // New style, don't allow series to be double referenced
  2189. if (!seriesNameArrayStyle || unassignedSeriesIndices.indexOf(si) > -1) {
  2190. axisSeriesMap[yi].push([yi, si]);
  2191. } else {
  2192. 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.');
  2193. }
  2194. } else {
  2195. // The series index refers to the target yaxis and the current
  2196. // yaxis index refers to the actual referenced series.
  2197. axisSeriesMap[si].push([si, yi]);
  2198. remove = yi;
  2199. }
  2200. assigned = true;
  2201. remove = unassignedSeriesIndices.indexOf(remove);
  2202. if (remove !== -1) {
  2203. unassignedSeriesIndices.splice(remove, 1);
  2204. }
  2205. }
  2206. });
  2207. });
  2208. }
  2209. if (!assigned) {
  2210. unassignedYAxisIndices.push(yi);
  2211. }
  2212. });
  2213. axisSeriesMap = axisSeriesMap.map(function (yaxe, yi) {
  2214. var ra = [];
  2215. yaxe.forEach(function (sa) {
  2216. seriesYAxisReverseMap[sa[1]] = sa[0];
  2217. ra.push(sa[1]);
  2218. });
  2219. return ra;
  2220. });
  2221. // All series referenced directly by yaxes have been assigned to those axes.
  2222. // Any series so far unassigned will be assigned to any yaxes that have yet
  2223. // to reference series directly, one-for-one in order of appearance, with
  2224. // all left-over series assigned to either the last unassigned yaxis, or the
  2225. // last yaxis if all have assigned series. This captures the
  2226. // default single and multiaxis config options which simply includes zero,
  2227. // one or as many yaxes as there are series but do not reference them by name.
  2228. var lastUnassignedYAxis = cnf.yaxis.length - 1;
  2229. for (var i = 0; i < unassignedYAxisIndices.length; i++) {
  2230. lastUnassignedYAxis = unassignedYAxisIndices[i];
  2231. axisSeriesMap[lastUnassignedYAxis] = [];
  2232. if (unassignedSeriesIndices) {
  2233. var si = unassignedSeriesIndices[0];
  2234. unassignedSeriesIndices.shift();
  2235. axisSeriesMap[lastUnassignedYAxis].push(si);
  2236. seriesYAxisReverseMap[si] = lastUnassignedYAxis;
  2237. } else {
  2238. break;
  2239. }
  2240. }
  2241. unassignedSeriesIndices.forEach(function (i) {
  2242. axisSeriesMap[lastUnassignedYAxis].push(i);
  2243. seriesYAxisReverseMap[i] = lastUnassignedYAxis;
  2244. });
  2245. // For the old-style seriesName-as-string-only, leave the zero-length yaxis
  2246. // array elements in for compatibility so that series.length == yaxes.length
  2247. // for multi axis charts.
  2248. gl.seriesYAxisMap = axisSeriesMap.map(function (x) {
  2249. return x;
  2250. });
  2251. gl.seriesYAxisReverseMap = seriesYAxisReverseMap.map(function (x) {
  2252. return x;
  2253. });
  2254. // Set default series group names
  2255. gl.seriesYAxisMap.forEach(function (axisSeries, ai) {
  2256. axisSeries.forEach(function (si) {
  2257. // series may be bare until loaded in realtime
  2258. if (cnf.series[si] && cnf.series[si].group === undefined) {
  2259. // A series with no group defined will be named after the axis that
  2260. // referenced it and thus form a group automatically.
  2261. cnf.series[si].group = 'apexcharts-axis-'.concat(ai.toString());
  2262. }
  2263. });
  2264. });
  2265. }
  2266. }, {
  2267. key: "isSeriesNull",
  2268. value: function isSeriesNull() {
  2269. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2270. var r = [];
  2271. if (index === null) {
  2272. // non-plot chart types - pie / donut / circle
  2273. r = this.w.config.series.filter(function (d) {
  2274. return d !== null;
  2275. });
  2276. } else {
  2277. // axis charts - supporting multiple series
  2278. r = this.w.config.series[index].data.filter(function (d) {
  2279. return d !== null;
  2280. });
  2281. }
  2282. return r.length === 0;
  2283. }
  2284. }, {
  2285. key: "seriesHaveSameValues",
  2286. value: function seriesHaveSameValues(index) {
  2287. return this.w.globals.series[index].every(function (val, i, arr) {
  2288. return val === arr[0];
  2289. });
  2290. }
  2291. }, {
  2292. key: "getCategoryLabels",
  2293. value: function getCategoryLabels(labels) {
  2294. var w = this.w;
  2295. var catLabels = labels.slice();
  2296. if (w.config.xaxis.convertedCatToNumeric) {
  2297. catLabels = labels.map(function (i, li) {
  2298. return w.config.xaxis.labels.formatter(i - w.globals.minX + 1);
  2299. });
  2300. }
  2301. return catLabels;
  2302. }
  2303. // maxValsInArrayIndex is the index of series[] which has the largest number of items
  2304. }, {
  2305. key: "getLargestSeries",
  2306. value: function getLargestSeries() {
  2307. var w = this.w;
  2308. w.globals.maxValsInArrayIndex = w.globals.series.map(function (a) {
  2309. return a.length;
  2310. }).indexOf(Math.max.apply(Math, w.globals.series.map(function (a) {
  2311. return a.length;
  2312. })));
  2313. }
  2314. }, {
  2315. key: "getLargestMarkerSize",
  2316. value: function getLargestMarkerSize() {
  2317. var w = this.w;
  2318. var size = 0;
  2319. w.globals.markers.size.forEach(function (m) {
  2320. size = Math.max(size, m);
  2321. });
  2322. if (w.config.markers.discrete && w.config.markers.discrete.length) {
  2323. w.config.markers.discrete.forEach(function (m) {
  2324. size = Math.max(size, m.size);
  2325. });
  2326. }
  2327. if (size > 0) {
  2328. if (w.config.markers.hover.size > 0) {
  2329. size = w.config.markers.hover.size;
  2330. } else {
  2331. size += w.config.markers.hover.sizeOffset;
  2332. }
  2333. }
  2334. w.globals.markers.largestSize = size;
  2335. return size;
  2336. }
  2337. /**
  2338. * @memberof Core
  2339. * returns the sum of all values in a series
  2340. * Eg. w.globals.series = [[32,33,43,12], [2,3,5,1]]
  2341. * @return [120, 11]
  2342. **/
  2343. }, {
  2344. key: "getSeriesTotals",
  2345. value: function getSeriesTotals() {
  2346. var w = this.w;
  2347. w.globals.seriesTotals = w.globals.series.map(function (ser, index) {
  2348. var total = 0;
  2349. if (Array.isArray(ser)) {
  2350. for (var j = 0; j < ser.length; j++) {
  2351. total += ser[j];
  2352. }
  2353. } else {
  2354. // for pie/donuts/gauges
  2355. total += ser;
  2356. }
  2357. return total;
  2358. });
  2359. }
  2360. }, {
  2361. key: "getSeriesTotalsXRange",
  2362. value: function getSeriesTotalsXRange(minX, maxX) {
  2363. var w = this.w;
  2364. var seriesTotalsXRange = w.globals.series.map(function (ser, index) {
  2365. var total = 0;
  2366. for (var j = 0; j < ser.length; j++) {
  2367. if (w.globals.seriesX[index][j] > minX && w.globals.seriesX[index][j] < maxX) {
  2368. total += ser[j];
  2369. }
  2370. }
  2371. return total;
  2372. });
  2373. return seriesTotalsXRange;
  2374. }
  2375. /**
  2376. * @memberof CoreUtils
  2377. * returns the percentage value of all individual values which can be used in a 100% stacked series
  2378. * Eg. w.globals.series = [[32, 33, 43, 12], [2, 3, 5, 1]]
  2379. * @return [[94.11, 91.66, 89.58, 92.30], [5.88, 8.33, 10.41, 7.7]]
  2380. **/
  2381. }, {
  2382. key: "getPercentSeries",
  2383. value: function getPercentSeries() {
  2384. var w = this.w;
  2385. w.globals.seriesPercent = w.globals.series.map(function (ser, index) {
  2386. var seriesPercent = [];
  2387. if (Array.isArray(ser)) {
  2388. for (var j = 0; j < ser.length; j++) {
  2389. var total = w.globals.stackedSeriesTotals[j];
  2390. var percent = 0;
  2391. if (total) {
  2392. percent = 100 * ser[j] / total;
  2393. }
  2394. seriesPercent.push(percent);
  2395. }
  2396. } else {
  2397. var _total = w.globals.seriesTotals.reduce(function (acc, val) {
  2398. return acc + val;
  2399. }, 0);
  2400. var _percent = 100 * ser / _total;
  2401. seriesPercent.push(_percent);
  2402. }
  2403. return seriesPercent;
  2404. });
  2405. }
  2406. }, {
  2407. key: "getCalculatedRatios",
  2408. value: function getCalculatedRatios() {
  2409. var _this2 = this;
  2410. var w = this.w;
  2411. var gl = w.globals;
  2412. var yRatio = [];
  2413. var invertedYRatio = 0;
  2414. var xRatio = 0;
  2415. var invertedXRatio = 0;
  2416. var zRatio = 0;
  2417. var baseLineY = [];
  2418. var baseLineInvertedY = 0.1;
  2419. var baseLineX = 0;
  2420. gl.yRange = [];
  2421. if (gl.isMultipleYAxis) {
  2422. for (var i = 0; i < gl.minYArr.length; i++) {
  2423. gl.yRange.push(Math.abs(gl.minYArr[i] - gl.maxYArr[i]));
  2424. baseLineY.push(0);
  2425. }
  2426. } else {
  2427. gl.yRange.push(Math.abs(gl.minY - gl.maxY));
  2428. }
  2429. gl.xRange = Math.abs(gl.maxX - gl.minX);
  2430. gl.zRange = Math.abs(gl.maxZ - gl.minZ);
  2431. // multiple y axis
  2432. for (var _i = 0; _i < gl.yRange.length; _i++) {
  2433. yRatio.push(gl.yRange[_i] / gl.gridHeight);
  2434. }
  2435. xRatio = gl.xRange / gl.gridWidth;
  2436. invertedYRatio = gl.yRange / gl.gridWidth;
  2437. invertedXRatio = gl.xRange / gl.gridHeight;
  2438. zRatio = gl.zRange / gl.gridHeight * 16;
  2439. if (!zRatio) {
  2440. zRatio = 1;
  2441. }
  2442. if (gl.minY !== Number.MIN_VALUE && Math.abs(gl.minY) !== 0) {
  2443. // Negative numbers present in series
  2444. gl.hasNegs = true;
  2445. }
  2446. // Check we have a map as series may still to be added/updated.
  2447. if (w.globals.seriesYAxisReverseMap.length > 0) {
  2448. var scaleBaseLineYScale = function scaleBaseLineYScale(y, i) {
  2449. var yAxis = w.config.yaxis[w.globals.seriesYAxisReverseMap[i]];
  2450. var sign = y < 0 ? -1 : 1;
  2451. y = Math.abs(y);
  2452. if (yAxis.logarithmic) {
  2453. y = _this2.getBaseLog(yAxis.logBase, y);
  2454. }
  2455. return -sign * y / yRatio[i];
  2456. };
  2457. if (gl.isMultipleYAxis) {
  2458. baseLineY = [];
  2459. // baseline variables is the 0 of the yaxis which will be needed when there are negatives
  2460. for (var _i2 = 0; _i2 < yRatio.length; _i2++) {
  2461. baseLineY.push(scaleBaseLineYScale(gl.minYArr[_i2], _i2));
  2462. }
  2463. } else {
  2464. baseLineY = [];
  2465. baseLineY.push(scaleBaseLineYScale(gl.minY, 0));
  2466. if (gl.minY !== Number.MIN_VALUE && Math.abs(gl.minY) !== 0) {
  2467. baseLineInvertedY = -gl.minY / invertedYRatio; // this is for bar chart
  2468. baseLineX = gl.minX / xRatio;
  2469. }
  2470. }
  2471. } else {
  2472. baseLineY = [];
  2473. baseLineY.push(0);
  2474. baseLineInvertedY = 0;
  2475. baseLineX = 0;
  2476. }
  2477. return {
  2478. yRatio: yRatio,
  2479. invertedYRatio: invertedYRatio,
  2480. zRatio: zRatio,
  2481. xRatio: xRatio,
  2482. invertedXRatio: invertedXRatio,
  2483. baseLineInvertedY: baseLineInvertedY,
  2484. baseLineY: baseLineY,
  2485. baseLineX: baseLineX
  2486. };
  2487. }
  2488. }, {
  2489. key: "getLogSeries",
  2490. value: function getLogSeries(series) {
  2491. var _this3 = this;
  2492. var w = this.w;
  2493. w.globals.seriesLog = series.map(function (s, i) {
  2494. var yAxisIndex = w.globals.seriesYAxisReverseMap[i];
  2495. if (w.config.yaxis[yAxisIndex] && w.config.yaxis[yAxisIndex].logarithmic) {
  2496. return s.map(function (d) {
  2497. if (d === null) return null;
  2498. return _this3.getLogVal(w.config.yaxis[yAxisIndex].logBase, d, i);
  2499. });
  2500. } else {
  2501. return s;
  2502. }
  2503. });
  2504. return w.globals.invalidLogScale ? series : w.globals.seriesLog;
  2505. }
  2506. }, {
  2507. key: "getBaseLog",
  2508. value: function getBaseLog(base, value) {
  2509. return Math.log(value) / Math.log(base);
  2510. }
  2511. }, {
  2512. key: "getLogVal",
  2513. value: function getLogVal(b, d, seriesIndex) {
  2514. if (d <= 0) {
  2515. return 0; // Should be Number.NEGATIVE_INFINITY
  2516. }
  2517. var w = this.w;
  2518. var min_log_val = w.globals.minYArr[seriesIndex] === 0 ? -1 // make sure we dont calculate log of 0
  2519. : this.getBaseLog(b, w.globals.minYArr[seriesIndex]);
  2520. var max_log_val = w.globals.maxYArr[seriesIndex] === 0 ? 0 // make sure we dont calculate log of 0
  2521. : this.getBaseLog(b, w.globals.maxYArr[seriesIndex]);
  2522. var number_of_height_levels = max_log_val - min_log_val;
  2523. if (d < 1) return d / number_of_height_levels;
  2524. var log_height_value = this.getBaseLog(b, d) - min_log_val;
  2525. return log_height_value / number_of_height_levels;
  2526. }
  2527. }, {
  2528. key: "getLogYRatios",
  2529. value: function getLogYRatios(yRatio) {
  2530. var _this4 = this;
  2531. var w = this.w;
  2532. var gl = this.w.globals;
  2533. gl.yLogRatio = yRatio.slice();
  2534. gl.logYRange = gl.yRange.map(function (_, i) {
  2535. var yAxisIndex = w.globals.seriesYAxisReverseMap[i];
  2536. if (w.config.yaxis[yAxisIndex] && _this4.w.config.yaxis[yAxisIndex].logarithmic) {
  2537. var maxY = -Number.MAX_VALUE;
  2538. var minY = Number.MIN_VALUE;
  2539. var range = 1;
  2540. gl.seriesLog.forEach(function (s, si) {
  2541. s.forEach(function (v) {
  2542. if (w.config.yaxis[si] && w.config.yaxis[si].logarithmic) {
  2543. maxY = Math.max(v, maxY);
  2544. minY = Math.min(v, minY);
  2545. }
  2546. });
  2547. });
  2548. range = Math.pow(gl.yRange[i], Math.abs(minY - maxY) / gl.yRange[i]);
  2549. gl.yLogRatio[i] = range / gl.gridHeight;
  2550. return range;
  2551. }
  2552. });
  2553. return gl.invalidLogScale ? yRatio.slice() : gl.yLogRatio;
  2554. }
  2555. // Some config objects can be array - and we need to extend them correctly
  2556. }, {
  2557. key: "drawSeriesByGroup",
  2558. value:
  2559. // Series of the same group and type can be stacked together distinct from
  2560. // other series of the same type on the same axis.
  2561. function drawSeriesByGroup(typeSeries, typeGroups, type, chartClass) {
  2562. var w = this.w;
  2563. var graph = [];
  2564. if (typeSeries.series.length > 0) {
  2565. // draw each group separately
  2566. typeGroups.forEach(function (gn) {
  2567. var gs = [];
  2568. var gi = [];
  2569. typeSeries.i.forEach(function (i, ii) {
  2570. if (w.config.series[i].group === gn) {
  2571. gs.push(typeSeries.series[ii]);
  2572. gi.push(i);
  2573. }
  2574. });
  2575. gs.length > 0 && graph.push(chartClass.draw(gs, type, gi));
  2576. });
  2577. }
  2578. return graph;
  2579. }
  2580. }], [{
  2581. key: "checkComboSeries",
  2582. value: function checkComboSeries(series, chartType) {
  2583. var comboCharts = false;
  2584. var comboBarCount = 0;
  2585. var comboCount = 0;
  2586. if (chartType === undefined) {
  2587. chartType = 'line';
  2588. }
  2589. // Check if user specified a type in series that may make us a combo chart.
  2590. // The default type for chart is "line" and the default for series is the
  2591. // chart type, therefore, if the types of all series match the chart type,
  2592. // this should not be considered a combo chart.
  2593. if (series.length && typeof series[0].type !== 'undefined') {
  2594. series.forEach(function (s) {
  2595. if (s.type === 'bar' || s.type === 'column' || s.type === 'candlestick' || s.type === 'boxPlot') {
  2596. comboBarCount++;
  2597. }
  2598. if (typeof s.type !== 'undefined' && s.type !== chartType) {
  2599. comboCount++;
  2600. }
  2601. });
  2602. }
  2603. if (comboCount > 0) {
  2604. comboCharts = true;
  2605. }
  2606. return {
  2607. comboBarCount: comboBarCount,
  2608. comboCharts: comboCharts
  2609. };
  2610. }
  2611. }, {
  2612. key: "extendArrayProps",
  2613. value: function extendArrayProps(configInstance, options, w) {
  2614. var _options, _options2;
  2615. if ((_options = options) !== null && _options !== void 0 && _options.yaxis) {
  2616. options = configInstance.extendYAxis(options, w);
  2617. }
  2618. if ((_options2 = options) !== null && _options2 !== void 0 && _options2.annotations) {
  2619. var _options3, _options3$annotations, _options4, _options4$annotations;
  2620. if (options.annotations.yaxis) {
  2621. options = configInstance.extendYAxisAnnotations(options);
  2622. }
  2623. if ((_options3 = options) !== null && _options3 !== void 0 && (_options3$annotations = _options3.annotations) !== null && _options3$annotations !== void 0 && _options3$annotations.xaxis) {
  2624. options = configInstance.extendXAxisAnnotations(options);
  2625. }
  2626. if ((_options4 = options) !== null && _options4 !== void 0 && (_options4$annotations = _options4.annotations) !== null && _options4$annotations !== void 0 && _options4$annotations.points) {
  2627. options = configInstance.extendPointAnnotations(options);
  2628. }
  2629. }
  2630. return options;
  2631. }
  2632. }]);
  2633. return CoreUtils;
  2634. }();
  2635. var Helpers$4 = /*#__PURE__*/function () {
  2636. function Helpers(annoCtx) {
  2637. _classCallCheck(this, Helpers);
  2638. this.w = annoCtx.w;
  2639. this.annoCtx = annoCtx;
  2640. }
  2641. _createClass(Helpers, [{
  2642. key: "setOrientations",
  2643. value: function setOrientations(anno) {
  2644. var annoIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  2645. var w = this.w;
  2646. if (anno.label.orientation === 'vertical') {
  2647. var i = annoIndex !== null ? annoIndex : 0;
  2648. var xAnno = w.globals.dom.baseEl.querySelector(".apexcharts-xaxis-annotations .apexcharts-xaxis-annotation-label[rel='".concat(i, "']"));
  2649. if (xAnno !== null) {
  2650. var xAnnoCoord = xAnno.getBoundingClientRect();
  2651. xAnno.setAttribute('x', parseFloat(xAnno.getAttribute('x')) - xAnnoCoord.height + 4);
  2652. var yOffset = anno.label.position === 'top' ? xAnnoCoord.width : -xAnnoCoord.width;
  2653. xAnno.setAttribute('y', parseFloat(xAnno.getAttribute('y')) + yOffset);
  2654. var _this$annoCtx$graphic = this.annoCtx.graphics.rotateAroundCenter(xAnno),
  2655. x = _this$annoCtx$graphic.x,
  2656. y = _this$annoCtx$graphic.y;
  2657. xAnno.setAttribute('transform', "rotate(-90 ".concat(x, " ").concat(y, ")"));
  2658. }
  2659. }
  2660. }
  2661. }, {
  2662. key: "addBackgroundToAnno",
  2663. value: function addBackgroundToAnno(annoEl, anno) {
  2664. var w = this.w;
  2665. if (!annoEl || !anno.label.text || !String(anno.label.text).trim()) {
  2666. return null;
  2667. }
  2668. var elGridRect = w.globals.dom.baseEl.querySelector('.apexcharts-grid').getBoundingClientRect();
  2669. var coords = annoEl.getBoundingClientRect();
  2670. var _anno$label$style$pad = anno.label.style.padding,
  2671. pleft = _anno$label$style$pad.left,
  2672. pright = _anno$label$style$pad.right,
  2673. ptop = _anno$label$style$pad.top,
  2674. pbottom = _anno$label$style$pad.bottom;
  2675. if (anno.label.orientation === 'vertical') {
  2676. var _ref = [pleft, pright, ptop, pbottom];
  2677. ptop = _ref[0];
  2678. pbottom = _ref[1];
  2679. pleft = _ref[2];
  2680. pright = _ref[3];
  2681. }
  2682. var x1 = coords.left - elGridRect.left - pleft;
  2683. var y1 = coords.top - elGridRect.top - ptop;
  2684. 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);
  2685. if (anno.id) {
  2686. elRect.node.classList.add(anno.id);
  2687. }
  2688. return elRect;
  2689. }
  2690. }, {
  2691. key: "annotationsBackground",
  2692. value: function annotationsBackground() {
  2693. var _this = this;
  2694. var w = this.w;
  2695. var add = function add(anno, i, type) {
  2696. var annoLabel = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-annotations .apexcharts-").concat(type, "-annotation-label[rel='").concat(i, "']"));
  2697. if (annoLabel) {
  2698. var parent = annoLabel.parentNode;
  2699. var elRect = _this.addBackgroundToAnno(annoLabel, anno);
  2700. if (elRect) {
  2701. parent.insertBefore(elRect.node, annoLabel);
  2702. if (anno.label.mouseEnter) {
  2703. elRect.node.addEventListener('mouseenter', anno.label.mouseEnter.bind(_this, anno));
  2704. }
  2705. if (anno.label.mouseLeave) {
  2706. elRect.node.addEventListener('mouseleave', anno.label.mouseLeave.bind(_this, anno));
  2707. }
  2708. if (anno.label.click) {
  2709. elRect.node.addEventListener('click', anno.label.click.bind(_this, anno));
  2710. }
  2711. }
  2712. }
  2713. };
  2714. w.config.annotations.xaxis.forEach(function (anno, i) {
  2715. return add(anno, i, 'xaxis');
  2716. });
  2717. w.config.annotations.yaxis.forEach(function (anno, i) {
  2718. return add(anno, i, 'yaxis');
  2719. });
  2720. w.config.annotations.points.forEach(function (anno, i) {
  2721. return add(anno, i, 'point');
  2722. });
  2723. }
  2724. }, {
  2725. key: "getY1Y2",
  2726. value: function getY1Y2(type, anno) {
  2727. var w = this.w;
  2728. var y = type === 'y1' ? anno.y : anno.y2;
  2729. var yP;
  2730. var clipped = false;
  2731. if (this.annoCtx.invertAxis) {
  2732. var labels = w.config.xaxis.convertedCatToNumeric ? w.globals.categoryLabels : w.globals.labels;
  2733. var catIndex = labels.indexOf(y);
  2734. var xLabel = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis-texts-g text:nth-child(".concat(catIndex + 1, ")"));
  2735. yP = xLabel ? parseFloat(xLabel.getAttribute('y')) : (w.globals.gridHeight / labels.length - 1) * (catIndex + 1) - w.globals.barHeight;
  2736. if (anno.seriesIndex !== undefined && w.globals.barHeight) {
  2737. yP -= w.globals.barHeight / 2 * (w.globals.series.length - 1) - w.globals.barHeight * anno.seriesIndex;
  2738. }
  2739. } else {
  2740. var _w$config$yaxis$anno$;
  2741. var seriesIndex = w.globals.seriesYAxisMap[anno.yAxisIndex][0];
  2742. 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);
  2743. yP = w.globals.gridHeight - Math.min(Math.max(yPos, 0), w.globals.gridHeight);
  2744. clipped = yPos > w.globals.gridHeight || yPos < 0;
  2745. if (anno.marker && (anno.y === undefined || anno.y === null)) {
  2746. yP = 0;
  2747. }
  2748. if ((_w$config$yaxis$anno$ = w.config.yaxis[anno.yAxisIndex]) !== null && _w$config$yaxis$anno$ !== void 0 && _w$config$yaxis$anno$.reversed) {
  2749. yP = yPos;
  2750. }
  2751. }
  2752. if (typeof y === 'string' && y.includes('px')) {
  2753. yP = parseFloat(y);
  2754. }
  2755. return {
  2756. yP: yP,
  2757. clipped: clipped
  2758. };
  2759. }
  2760. }, {
  2761. key: "getX1X2",
  2762. value: function getX1X2(type, anno) {
  2763. var w = this.w;
  2764. var x = type === 'x1' ? anno.x : anno.x2;
  2765. var min = this.annoCtx.invertAxis ? w.globals.minY : w.globals.minX;
  2766. var max = this.annoCtx.invertAxis ? w.globals.maxY : w.globals.maxX;
  2767. var range = this.annoCtx.invertAxis ? w.globals.yRange[0] : w.globals.xRange;
  2768. var clipped = false;
  2769. var xP = this.annoCtx.inversedReversedAxis ? (max - x) / (range / w.globals.gridWidth) : (x - min) / (range / w.globals.gridWidth);
  2770. if ((w.config.xaxis.type === 'category' || w.config.xaxis.convertedCatToNumeric) && !this.annoCtx.invertAxis && !w.globals.dataFormatXNumeric) {
  2771. if (!w.config.chart.sparkline.enabled) {
  2772. xP = this.getStringX(x);
  2773. }
  2774. }
  2775. if (typeof x === 'string' && x.includes('px')) {
  2776. xP = parseFloat(x);
  2777. }
  2778. if ((x === undefined || x === null) && anno.marker) {
  2779. xP = w.globals.gridWidth;
  2780. }
  2781. if (anno.seriesIndex !== undefined && w.globals.barWidth && !this.annoCtx.invertAxis) {
  2782. xP -= w.globals.barWidth / 2 * (w.globals.series.length - 1) - w.globals.barWidth * anno.seriesIndex;
  2783. }
  2784. if (xP > w.globals.gridWidth) {
  2785. xP = w.globals.gridWidth;
  2786. clipped = true;
  2787. } else if (xP < 0) {
  2788. xP = 0;
  2789. clipped = true;
  2790. }
  2791. return {
  2792. x: xP,
  2793. clipped: clipped
  2794. };
  2795. }
  2796. }, {
  2797. key: "getStringX",
  2798. value: function getStringX(x) {
  2799. var w = this.w;
  2800. var rX = x;
  2801. if (w.config.xaxis.convertedCatToNumeric && w.globals.categoryLabels.length) {
  2802. x = w.globals.categoryLabels.indexOf(x) + 1;
  2803. }
  2804. var catIndex = w.globals.labels.map(function (item) {
  2805. return Array.isArray(item) ? item.join(' ') : item;
  2806. }).indexOf(x);
  2807. var xLabel = w.globals.dom.baseEl.querySelector(".apexcharts-xaxis-texts-g text:nth-child(".concat(catIndex + 1, ")"));
  2808. if (xLabel) {
  2809. rX = parseFloat(xLabel.getAttribute('x'));
  2810. }
  2811. return rX;
  2812. }
  2813. }]);
  2814. return Helpers;
  2815. }();
  2816. var XAnnotations = /*#__PURE__*/function () {
  2817. function XAnnotations(annoCtx) {
  2818. _classCallCheck(this, XAnnotations);
  2819. this.w = annoCtx.w;
  2820. this.annoCtx = annoCtx;
  2821. this.invertAxis = this.annoCtx.invertAxis;
  2822. this.helpers = new Helpers$4(this.annoCtx);
  2823. }
  2824. _createClass(XAnnotations, [{
  2825. key: "addXaxisAnnotation",
  2826. value: function addXaxisAnnotation(anno, parent, index) {
  2827. var w = this.w;
  2828. var result = this.helpers.getX1X2('x1', anno);
  2829. var x1 = result.x;
  2830. var clipX1 = result.clipped;
  2831. var clipX2 = true;
  2832. var x2;
  2833. var text = anno.label.text;
  2834. var strokeDashArray = anno.strokeDashArray;
  2835. if (!Utils$1.isNumber(x1)) return;
  2836. if (anno.x2 === null || typeof anno.x2 === 'undefined') {
  2837. if (!clipX1) {
  2838. var line = this.annoCtx.graphics.drawLine(x1 + anno.offsetX,
  2839. // x1
  2840. 0 + anno.offsetY,
  2841. // y1
  2842. x1 + anno.offsetX,
  2843. // x2
  2844. w.globals.gridHeight + anno.offsetY,
  2845. // y2
  2846. anno.borderColor,
  2847. // lineColor
  2848. strokeDashArray,
  2849. //dashArray
  2850. anno.borderWidth);
  2851. parent.appendChild(line.node);
  2852. if (anno.id) {
  2853. line.node.classList.add(anno.id);
  2854. }
  2855. }
  2856. } else {
  2857. var _result = this.helpers.getX1X2('x2', anno);
  2858. x2 = _result.x;
  2859. clipX2 = _result.clipped;
  2860. if (!(clipX1 && clipX2)) {
  2861. if (x2 < x1) {
  2862. var temp = x1;
  2863. x1 = x2;
  2864. x2 = temp;
  2865. }
  2866. var rect = this.annoCtx.graphics.drawRect(x1 + anno.offsetX,
  2867. // x1
  2868. 0 + anno.offsetY,
  2869. // y1
  2870. x2 - x1,
  2871. // x2
  2872. w.globals.gridHeight + anno.offsetY,
  2873. // y2
  2874. 0,
  2875. // radius
  2876. anno.fillColor,
  2877. // color
  2878. anno.opacity,
  2879. // opacity,
  2880. 1,
  2881. // strokeWidth
  2882. anno.borderColor,
  2883. // strokeColor
  2884. strokeDashArray // stokeDashArray
  2885. );
  2886. rect.node.classList.add('apexcharts-annotation-rect');
  2887. rect.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
  2888. parent.appendChild(rect.node);
  2889. if (anno.id) {
  2890. rect.node.classList.add(anno.id);
  2891. }
  2892. }
  2893. }
  2894. if (!(clipX1 && clipX2)) {
  2895. var textRects = this.annoCtx.graphics.getTextRects(text, parseFloat(anno.label.style.fontSize));
  2896. 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;
  2897. var elText = this.annoCtx.graphics.drawText({
  2898. x: x1 + anno.label.offsetX,
  2899. y: textY + anno.label.offsetY - (anno.label.orientation === 'vertical' ? anno.label.position === 'top' ? textRects.width / 2 - 12 : -textRects.width / 2 : 0),
  2900. text: text,
  2901. textAnchor: anno.label.textAnchor,
  2902. fontSize: anno.label.style.fontSize,
  2903. fontFamily: anno.label.style.fontFamily,
  2904. fontWeight: anno.label.style.fontWeight,
  2905. foreColor: anno.label.style.color,
  2906. cssClass: "apexcharts-xaxis-annotation-label ".concat(anno.label.style.cssClass, " ").concat(anno.id ? anno.id : '')
  2907. });
  2908. elText.attr({
  2909. rel: index
  2910. });
  2911. parent.appendChild(elText.node);
  2912. // after placing the annotations on svg, set any vertically placed annotations
  2913. this.annoCtx.helpers.setOrientations(anno, index);
  2914. }
  2915. }
  2916. }, {
  2917. key: "drawXAxisAnnotations",
  2918. value: function drawXAxisAnnotations() {
  2919. var _this = this;
  2920. var w = this.w;
  2921. var elg = this.annoCtx.graphics.group({
  2922. class: 'apexcharts-xaxis-annotations'
  2923. });
  2924. w.config.annotations.xaxis.map(function (anno, index) {
  2925. _this.addXaxisAnnotation(anno, elg.node, index);
  2926. });
  2927. return elg;
  2928. }
  2929. }]);
  2930. return XAnnotations;
  2931. }();
  2932. /**
  2933. * DateTime Class to manipulate datetime values.
  2934. *
  2935. * @module DateTime
  2936. **/
  2937. var DateTime = /*#__PURE__*/function () {
  2938. function DateTime(ctx) {
  2939. _classCallCheck(this, DateTime);
  2940. this.ctx = ctx;
  2941. this.w = ctx.w;
  2942. this.months31 = [1, 3, 5, 7, 8, 10, 12];
  2943. this.months30 = [2, 4, 6, 9, 11];
  2944. this.daysCntOfYear = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
  2945. }
  2946. _createClass(DateTime, [{
  2947. key: "isValidDate",
  2948. value: function isValidDate(date) {
  2949. if (typeof date === 'number') {
  2950. return false; // don't test for timestamps
  2951. }
  2952. return !isNaN(this.parseDate(date));
  2953. }
  2954. }, {
  2955. key: "getTimeStamp",
  2956. value: function getTimeStamp(dateStr) {
  2957. if (!Date.parse(dateStr)) {
  2958. return dateStr;
  2959. }
  2960. var utc = this.w.config.xaxis.labels.datetimeUTC;
  2961. return !utc ? new Date(dateStr).getTime() : new Date(new Date(dateStr).toISOString().substr(0, 25)).getTime();
  2962. }
  2963. }, {
  2964. key: "getDate",
  2965. value: function getDate(timestamp) {
  2966. var utc = this.w.config.xaxis.labels.datetimeUTC;
  2967. return utc ? new Date(new Date(timestamp).toUTCString()) : new Date(timestamp);
  2968. }
  2969. }, {
  2970. key: "parseDate",
  2971. value: function parseDate(dateStr) {
  2972. var parsed = Date.parse(dateStr);
  2973. if (!isNaN(parsed)) {
  2974. return this.getTimeStamp(dateStr);
  2975. }
  2976. var output = Date.parse(dateStr.replace(/-/g, '/').replace(/[a-z]+/gi, ' '));
  2977. output = this.getTimeStamp(output);
  2978. return output;
  2979. }
  2980. // This fixes the difference of x-axis labels between chrome/safari
  2981. // Fixes #1726, #1544, #1485, #1255
  2982. }, {
  2983. key: "parseDateWithTimezone",
  2984. value: function parseDateWithTimezone(dateStr) {
  2985. return Date.parse(dateStr.replace(/-/g, '/').replace(/[a-z]+/gi, ' '));
  2986. }
  2987. // http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript#answer-14638191
  2988. }, {
  2989. key: "formatDate",
  2990. value: function formatDate(date, format) {
  2991. var locale = this.w.globals.locale;
  2992. var utc = this.w.config.xaxis.labels.datetimeUTC;
  2993. var MMMM = ['\x00'].concat(_toConsumableArray(locale.months));
  2994. var MMM = ['\x01'].concat(_toConsumableArray(locale.shortMonths));
  2995. var dddd = ['\x02'].concat(_toConsumableArray(locale.days));
  2996. var ddd = ['\x03'].concat(_toConsumableArray(locale.shortDays));
  2997. function ii(i, len) {
  2998. var s = i + '';
  2999. len = len || 2;
  3000. while (s.length < len) {
  3001. s = '0' + s;
  3002. }
  3003. return s;
  3004. }
  3005. var y = utc ? date.getUTCFullYear() : date.getFullYear();
  3006. format = format.replace(/(^|[^\\])yyyy+/g, '$1' + y);
  3007. format = format.replace(/(^|[^\\])yy/g, '$1' + y.toString().substr(2, 2));
  3008. format = format.replace(/(^|[^\\])y/g, '$1' + y);
  3009. var M = (utc ? date.getUTCMonth() : date.getMonth()) + 1;
  3010. format = format.replace(/(^|[^\\])MMMM+/g, '$1' + MMMM[0]);
  3011. format = format.replace(/(^|[^\\])MMM/g, '$1' + MMM[0]);
  3012. format = format.replace(/(^|[^\\])MM/g, '$1' + ii(M));
  3013. format = format.replace(/(^|[^\\])M/g, '$1' + M);
  3014. var d = utc ? date.getUTCDate() : date.getDate();
  3015. format = format.replace(/(^|[^\\])dddd+/g, '$1' + dddd[0]);
  3016. format = format.replace(/(^|[^\\])ddd/g, '$1' + ddd[0]);
  3017. format = format.replace(/(^|[^\\])dd/g, '$1' + ii(d));
  3018. format = format.replace(/(^|[^\\])d/g, '$1' + d);
  3019. var H = utc ? date.getUTCHours() : date.getHours();
  3020. format = format.replace(/(^|[^\\])HH+/g, '$1' + ii(H));
  3021. format = format.replace(/(^|[^\\])H/g, '$1' + H);
  3022. var h = H > 12 ? H - 12 : H === 0 ? 12 : H;
  3023. format = format.replace(/(^|[^\\])hh+/g, '$1' + ii(h));
  3024. format = format.replace(/(^|[^\\])h/g, '$1' + h);
  3025. var m = utc ? date.getUTCMinutes() : date.getMinutes();
  3026. format = format.replace(/(^|[^\\])mm+/g, '$1' + ii(m));
  3027. format = format.replace(/(^|[^\\])m/g, '$1' + m);
  3028. var s = utc ? date.getUTCSeconds() : date.getSeconds();
  3029. format = format.replace(/(^|[^\\])ss+/g, '$1' + ii(s));
  3030. format = format.replace(/(^|[^\\])s/g, '$1' + s);
  3031. var f = utc ? date.getUTCMilliseconds() : date.getMilliseconds();
  3032. format = format.replace(/(^|[^\\])fff+/g, '$1' + ii(f, 3));
  3033. f = Math.round(f / 10);
  3034. format = format.replace(/(^|[^\\])ff/g, '$1' + ii(f));
  3035. f = Math.round(f / 10);
  3036. format = format.replace(/(^|[^\\])f/g, '$1' + f);
  3037. var T = H < 12 ? 'AM' : 'PM';
  3038. format = format.replace(/(^|[^\\])TT+/g, '$1' + T);
  3039. format = format.replace(/(^|[^\\])T/g, '$1' + T.charAt(0));
  3040. var t = T.toLowerCase();
  3041. format = format.replace(/(^|[^\\])tt+/g, '$1' + t);
  3042. format = format.replace(/(^|[^\\])t/g, '$1' + t.charAt(0));
  3043. var tz = -date.getTimezoneOffset();
  3044. var K = utc || !tz ? 'Z' : tz > 0 ? '+' : '-';
  3045. if (!utc) {
  3046. tz = Math.abs(tz);
  3047. var tzHrs = Math.floor(tz / 60);
  3048. var tzMin = tz % 60;
  3049. K += ii(tzHrs) + ':' + ii(tzMin);
  3050. }
  3051. format = format.replace(/(^|[^\\])K/g, '$1' + K);
  3052. var day = (utc ? date.getUTCDay() : date.getDay()) + 1;
  3053. format = format.replace(new RegExp(dddd[0], 'g'), dddd[day]);
  3054. format = format.replace(new RegExp(ddd[0], 'g'), ddd[day]);
  3055. format = format.replace(new RegExp(MMMM[0], 'g'), MMMM[M]);
  3056. format = format.replace(new RegExp(MMM[0], 'g'), MMM[M]);
  3057. format = format.replace(/\\(.)/g, '$1');
  3058. return format;
  3059. }
  3060. }, {
  3061. key: "getTimeUnitsfromTimestamp",
  3062. value: function getTimeUnitsfromTimestamp(minX, maxX, utc) {
  3063. var w = this.w;
  3064. if (w.config.xaxis.min !== undefined) {
  3065. minX = w.config.xaxis.min;
  3066. }
  3067. if (w.config.xaxis.max !== undefined) {
  3068. maxX = w.config.xaxis.max;
  3069. }
  3070. var tsMin = this.getDate(minX);
  3071. var tsMax = this.getDate(maxX);
  3072. var minD = this.formatDate(tsMin, 'yyyy MM dd HH mm ss fff').split(' ');
  3073. var maxD = this.formatDate(tsMax, 'yyyy MM dd HH mm ss fff').split(' ');
  3074. return {
  3075. minMillisecond: parseInt(minD[6], 10),
  3076. maxMillisecond: parseInt(maxD[6], 10),
  3077. minSecond: parseInt(minD[5], 10),
  3078. maxSecond: parseInt(maxD[5], 10),
  3079. minMinute: parseInt(minD[4], 10),
  3080. maxMinute: parseInt(maxD[4], 10),
  3081. minHour: parseInt(minD[3], 10),
  3082. maxHour: parseInt(maxD[3], 10),
  3083. minDate: parseInt(minD[2], 10),
  3084. maxDate: parseInt(maxD[2], 10),
  3085. minMonth: parseInt(minD[1], 10) - 1,
  3086. maxMonth: parseInt(maxD[1], 10) - 1,
  3087. minYear: parseInt(minD[0], 10),
  3088. maxYear: parseInt(maxD[0], 10)
  3089. };
  3090. }
  3091. }, {
  3092. key: "isLeapYear",
  3093. value: function isLeapYear(year) {
  3094. return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
  3095. }
  3096. }, {
  3097. key: "calculcateLastDaysOfMonth",
  3098. value: function calculcateLastDaysOfMonth(month, year, subtract) {
  3099. var days = this.determineDaysOfMonths(month, year);
  3100. // whatever days we get, subtract the number of days asked
  3101. return days - subtract;
  3102. }
  3103. }, {
  3104. key: "determineDaysOfYear",
  3105. value: function determineDaysOfYear(year) {
  3106. var days = 365;
  3107. if (this.isLeapYear(year)) {
  3108. days = 366;
  3109. }
  3110. return days;
  3111. }
  3112. }, {
  3113. key: "determineRemainingDaysOfYear",
  3114. value: function determineRemainingDaysOfYear(year, month, date) {
  3115. var dayOfYear = this.daysCntOfYear[month] + date;
  3116. if (month > 1 && this.isLeapYear()) dayOfYear++;
  3117. return dayOfYear;
  3118. }
  3119. }, {
  3120. key: "determineDaysOfMonths",
  3121. value: function determineDaysOfMonths(month, year) {
  3122. var days = 30;
  3123. month = Utils$1.monthMod(month);
  3124. switch (true) {
  3125. case this.months30.indexOf(month) > -1:
  3126. if (month === 2) {
  3127. if (this.isLeapYear(year)) {
  3128. days = 29;
  3129. } else {
  3130. days = 28;
  3131. }
  3132. }
  3133. break;
  3134. case this.months31.indexOf(month) > -1:
  3135. days = 31;
  3136. break;
  3137. default:
  3138. days = 31;
  3139. break;
  3140. }
  3141. return days;
  3142. }
  3143. }]);
  3144. return DateTime;
  3145. }();
  3146. /**
  3147. * ApexCharts Formatter Class for setting value formatters for axes as well as tooltips.
  3148. *
  3149. * @module Formatters
  3150. **/
  3151. var Formatters = /*#__PURE__*/function () {
  3152. function Formatters(ctx) {
  3153. _classCallCheck(this, Formatters);
  3154. this.ctx = ctx;
  3155. this.w = ctx.w;
  3156. this.tooltipKeyFormat = 'dd MMM';
  3157. }
  3158. _createClass(Formatters, [{
  3159. key: "xLabelFormat",
  3160. value: function xLabelFormat(fn, val, timestamp, opts) {
  3161. var w = this.w;
  3162. if (w.config.xaxis.type === 'datetime') {
  3163. if (w.config.xaxis.labels.formatter === undefined) {
  3164. // if user has not specified a custom formatter, use the default tooltip.x.format
  3165. if (w.config.tooltip.x.formatter === undefined) {
  3166. var datetimeObj = new DateTime(this.ctx);
  3167. return datetimeObj.formatDate(datetimeObj.getDate(val), w.config.tooltip.x.format);
  3168. }
  3169. }
  3170. }
  3171. return fn(val, timestamp, opts);
  3172. }
  3173. }, {
  3174. key: "defaultGeneralFormatter",
  3175. value: function defaultGeneralFormatter(val) {
  3176. if (Array.isArray(val)) {
  3177. return val.map(function (v) {
  3178. return v;
  3179. });
  3180. } else {
  3181. return val;
  3182. }
  3183. }
  3184. }, {
  3185. key: "defaultYFormatter",
  3186. value: function defaultYFormatter(v, yaxe, i) {
  3187. var w = this.w;
  3188. if (Utils$1.isNumber(v)) {
  3189. if (w.globals.yValueDecimal !== 0) {
  3190. v = v.toFixed(yaxe.decimalsInFloat !== undefined ? yaxe.decimalsInFloat : w.globals.yValueDecimal);
  3191. } else {
  3192. // We have an integer value but the label is not an integer. We can
  3193. // deduce this is due to the number of ticks exceeding the even lower
  3194. // integer range. Add an additional decimal place only in this case.
  3195. var f = v.toFixed(0);
  3196. // Do not change the == to ===
  3197. v = v == f ? f : v.toFixed(1);
  3198. }
  3199. }
  3200. return v;
  3201. }
  3202. }, {
  3203. key: "setLabelFormatters",
  3204. value: function setLabelFormatters() {
  3205. var _this = this;
  3206. var w = this.w;
  3207. w.globals.xaxisTooltipFormatter = function (val) {
  3208. return _this.defaultGeneralFormatter(val);
  3209. };
  3210. w.globals.ttKeyFormatter = function (val) {
  3211. return _this.defaultGeneralFormatter(val);
  3212. };
  3213. w.globals.ttZFormatter = function (val) {
  3214. return val;
  3215. };
  3216. w.globals.legendFormatter = function (val) {
  3217. return _this.defaultGeneralFormatter(val);
  3218. };
  3219. // formatter function will always overwrite format property
  3220. if (w.config.xaxis.labels.formatter !== undefined) {
  3221. w.globals.xLabelFormatter = w.config.xaxis.labels.formatter;
  3222. } else {
  3223. w.globals.xLabelFormatter = function (val) {
  3224. if (Utils$1.isNumber(val)) {
  3225. if (!w.config.xaxis.convertedCatToNumeric && w.config.xaxis.type === 'numeric') {
  3226. if (Utils$1.isNumber(w.config.xaxis.decimalsInFloat)) {
  3227. return val.toFixed(w.config.xaxis.decimalsInFloat);
  3228. } else {
  3229. var diff = w.globals.maxX - w.globals.minX;
  3230. if (diff > 0 && diff < 100) {
  3231. return val.toFixed(1);
  3232. }
  3233. return val.toFixed(0);
  3234. }
  3235. }
  3236. if (w.globals.isBarHorizontal) {
  3237. var range = w.globals.maxY - w.globals.minYArr;
  3238. if (range < 4) {
  3239. return val.toFixed(1);
  3240. }
  3241. }
  3242. return val.toFixed(0);
  3243. }
  3244. return val;
  3245. };
  3246. }
  3247. if (typeof w.config.tooltip.x.formatter === 'function') {
  3248. w.globals.ttKeyFormatter = w.config.tooltip.x.formatter;
  3249. } else {
  3250. w.globals.ttKeyFormatter = w.globals.xLabelFormatter;
  3251. }
  3252. if (typeof w.config.xaxis.tooltip.formatter === 'function') {
  3253. w.globals.xaxisTooltipFormatter = w.config.xaxis.tooltip.formatter;
  3254. }
  3255. if (Array.isArray(w.config.tooltip.y)) {
  3256. w.globals.ttVal = w.config.tooltip.y;
  3257. } else {
  3258. if (w.config.tooltip.y.formatter !== undefined) {
  3259. w.globals.ttVal = w.config.tooltip.y;
  3260. }
  3261. }
  3262. if (w.config.tooltip.z.formatter !== undefined) {
  3263. w.globals.ttZFormatter = w.config.tooltip.z.formatter;
  3264. }
  3265. // legend formatter - if user wants to append any global values of series to legend text
  3266. if (w.config.legend.formatter !== undefined) {
  3267. w.globals.legendFormatter = w.config.legend.formatter;
  3268. }
  3269. // formatter function will always overwrite format property
  3270. w.config.yaxis.forEach(function (yaxe, i) {
  3271. if (yaxe.labels.formatter !== undefined) {
  3272. w.globals.yLabelFormatters[i] = yaxe.labels.formatter;
  3273. } else {
  3274. w.globals.yLabelFormatters[i] = function (val) {
  3275. if (!w.globals.xyCharts) return val;
  3276. if (Array.isArray(val)) {
  3277. return val.map(function (v) {
  3278. return _this.defaultYFormatter(v, yaxe, i);
  3279. });
  3280. } else {
  3281. return _this.defaultYFormatter(val, yaxe, i);
  3282. }
  3283. };
  3284. }
  3285. });
  3286. return w.globals;
  3287. }
  3288. }, {
  3289. key: "heatmapLabelFormatters",
  3290. value: function heatmapLabelFormatters() {
  3291. var w = this.w;
  3292. if (w.config.chart.type === 'heatmap') {
  3293. w.globals.yAxisScale[0].result = w.globals.seriesNames.slice();
  3294. // get the longest string from the labels array and also apply label formatter to it
  3295. var longest = w.globals.seriesNames.reduce(function (a, b) {
  3296. return a.length > b.length ? a : b;
  3297. }, 0);
  3298. w.globals.yAxisScale[0].niceMax = longest;
  3299. w.globals.yAxisScale[0].niceMin = longest;
  3300. }
  3301. }
  3302. }]);
  3303. return Formatters;
  3304. }();
  3305. var AxesUtils = /*#__PURE__*/function () {
  3306. function AxesUtils(ctx) {
  3307. _classCallCheck(this, AxesUtils);
  3308. this.ctx = ctx;
  3309. this.w = ctx.w;
  3310. }
  3311. // Based on the formatter function, get the label text and position
  3312. _createClass(AxesUtils, [{
  3313. key: "getLabel",
  3314. value: function getLabel(labels, timescaleLabels, x, i) {
  3315. var drawnLabels = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  3316. var fontSize = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '12px';
  3317. var isLeafGroup = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
  3318. var w = this.w;
  3319. var rawLabel = typeof labels[i] === 'undefined' ? '' : labels[i];
  3320. var label = rawLabel;
  3321. var xlbFormatter = w.globals.xLabelFormatter;
  3322. var customFormatter = w.config.xaxis.labels.formatter;
  3323. var isBold = false;
  3324. var xFormat = new Formatters(this.ctx);
  3325. var timestamp = rawLabel;
  3326. if (isLeafGroup) {
  3327. label = xFormat.xLabelFormat(xlbFormatter, rawLabel, timestamp, {
  3328. i: i,
  3329. dateFormatter: new DateTime(this.ctx).formatDate,
  3330. w: w
  3331. });
  3332. if (customFormatter !== undefined) {
  3333. label = customFormatter(rawLabel, labels[i], {
  3334. i: i,
  3335. dateFormatter: new DateTime(this.ctx).formatDate,
  3336. w: w
  3337. });
  3338. }
  3339. }
  3340. var determineHighestUnit = function determineHighestUnit(unit) {
  3341. var highestUnit = null;
  3342. timescaleLabels.forEach(function (t) {
  3343. if (t.unit === 'month') {
  3344. highestUnit = 'year';
  3345. } else if (t.unit === 'day') {
  3346. highestUnit = 'month';
  3347. } else if (t.unit === 'hour') {
  3348. highestUnit = 'day';
  3349. } else if (t.unit === 'minute') {
  3350. highestUnit = 'hour';
  3351. }
  3352. });
  3353. return highestUnit === unit;
  3354. };
  3355. if (timescaleLabels.length > 0) {
  3356. isBold = determineHighestUnit(timescaleLabels[i].unit);
  3357. x = timescaleLabels[i].position;
  3358. label = timescaleLabels[i].value;
  3359. } else {
  3360. if (w.config.xaxis.type === 'datetime' && customFormatter === undefined) {
  3361. label = '';
  3362. }
  3363. }
  3364. if (typeof label === 'undefined') label = '';
  3365. label = Array.isArray(label) ? label : label.toString();
  3366. var graphics = new Graphics(this.ctx);
  3367. var textRect = {};
  3368. if (w.globals.rotateXLabels && isLeafGroup) {
  3369. textRect = graphics.getTextRects(label, parseInt(fontSize, 10), null, "rotate(".concat(w.config.xaxis.labels.rotate, " 0 0)"), false);
  3370. } else {
  3371. textRect = graphics.getTextRects(label, parseInt(fontSize, 10));
  3372. }
  3373. var allowDuplicatesInTimeScale = !w.config.xaxis.labels.showDuplicates && this.ctx.timeScale;
  3374. if (!Array.isArray(label) && (String(label) === 'NaN' || drawnLabels.indexOf(label) >= 0 && allowDuplicatesInTimeScale)) {
  3375. label = '';
  3376. }
  3377. return {
  3378. x: x,
  3379. text: label,
  3380. textRect: textRect,
  3381. isBold: isBold
  3382. };
  3383. }
  3384. }, {
  3385. key: "checkLabelBasedOnTickamount",
  3386. value: function checkLabelBasedOnTickamount(i, label, labelsLen) {
  3387. var w = this.w;
  3388. var ticks = w.config.xaxis.tickAmount;
  3389. if (ticks === 'dataPoints') ticks = Math.round(w.globals.gridWidth / 120);
  3390. if (ticks > labelsLen) return label;
  3391. var tickMultiple = Math.round(labelsLen / (ticks + 1));
  3392. if (i % tickMultiple === 0) {
  3393. return label;
  3394. } else {
  3395. label.text = '';
  3396. }
  3397. return label;
  3398. }
  3399. }, {
  3400. key: "checkForOverflowingLabels",
  3401. value: function checkForOverflowingLabels(i, label, labelsLen, drawnLabels, drawnLabelsRects) {
  3402. var w = this.w;
  3403. if (i === 0) {
  3404. // check if first label is being truncated
  3405. if (w.globals.skipFirstTimelinelabel) {
  3406. label.text = '';
  3407. }
  3408. }
  3409. if (i === labelsLen - 1) {
  3410. // check if last label is being truncated
  3411. if (w.globals.skipLastTimelinelabel) {
  3412. label.text = '';
  3413. }
  3414. }
  3415. if (w.config.xaxis.labels.hideOverlappingLabels && drawnLabels.length > 0) {
  3416. var prev = drawnLabelsRects[drawnLabelsRects.length - 1];
  3417. if (label.x < prev.textRect.width / (w.globals.rotateXLabels ? Math.abs(w.config.xaxis.labels.rotate) / 12 : 1.01) + prev.x) {
  3418. label.text = '';
  3419. }
  3420. }
  3421. return label;
  3422. }
  3423. }, {
  3424. key: "checkForReversedLabels",
  3425. value: function checkForReversedLabels(i, labels) {
  3426. var w = this.w;
  3427. if (w.config.yaxis[i] && w.config.yaxis[i].reversed) {
  3428. labels.reverse();
  3429. }
  3430. return labels;
  3431. }
  3432. }, {
  3433. key: "yAxisAllSeriesCollapsed",
  3434. value: function yAxisAllSeriesCollapsed(index) {
  3435. var gl = this.w.globals;
  3436. return !gl.seriesYAxisMap[index].some(function (si) {
  3437. return gl.collapsedSeriesIndices.indexOf(si) === -1;
  3438. });
  3439. }
  3440. // Method to translate annotation.yAxisIndex values from
  3441. // seriesName-as-a-string values to seriesName-as-an-array values (old style
  3442. // series mapping to new style).
  3443. }, {
  3444. key: "translateYAxisIndex",
  3445. value: function translateYAxisIndex(index) {
  3446. var w = this.w;
  3447. var gl = w.globals;
  3448. var yaxis = w.config.yaxis;
  3449. var newStyle = gl.series.length > yaxis.length || yaxis.some(function (a) {
  3450. return Array.isArray(a.seriesName);
  3451. });
  3452. if (newStyle) {
  3453. return index;
  3454. } else {
  3455. return gl.seriesYAxisReverseMap[index];
  3456. }
  3457. }
  3458. }, {
  3459. key: "isYAxisHidden",
  3460. value: function isYAxisHidden(index) {
  3461. var w = this.w;
  3462. var yaxis = w.config.yaxis[index];
  3463. if (!yaxis.show || this.yAxisAllSeriesCollapsed(index)) {
  3464. return true;
  3465. }
  3466. if (!yaxis.showForNullSeries) {
  3467. var seriesIndices = w.globals.seriesYAxisMap[index];
  3468. var coreUtils = new CoreUtils(this.ctx);
  3469. return seriesIndices.every(function (si) {
  3470. return coreUtils.isSeriesNull(si);
  3471. });
  3472. }
  3473. return false;
  3474. }
  3475. // get the label color for y-axis
  3476. // realIndex is the actual series index, while i is the tick Index
  3477. }, {
  3478. key: "getYAxisForeColor",
  3479. value: function getYAxisForeColor(yColors, realIndex) {
  3480. var w = this.w;
  3481. if (Array.isArray(yColors) && w.globals.yAxisScale[realIndex]) {
  3482. this.ctx.theme.pushExtraColors(yColors, w.globals.yAxisScale[realIndex].result.length, false);
  3483. }
  3484. return yColors;
  3485. }
  3486. }, {
  3487. key: "drawYAxisTicks",
  3488. value: function drawYAxisTicks(x, tickAmount, axisBorder, axisTicks, realIndex, labelsDivider, elYaxis) {
  3489. var w = this.w;
  3490. var graphics = new Graphics(this.ctx);
  3491. // initial label position = 0;
  3492. var tY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY;
  3493. if (w.globals.isBarHorizontal) {
  3494. tY = 0;
  3495. } else if (w.config.chart.type === 'heatmap') {
  3496. tY += labelsDivider / 2;
  3497. }
  3498. if (axisTicks.show && tickAmount > 0) {
  3499. if (w.config.yaxis[realIndex].opposite === true) x = x + axisTicks.width;
  3500. for (var i = tickAmount; i >= 0; i--) {
  3501. var elTick = graphics.drawLine(x + axisBorder.offsetX - axisTicks.width + axisTicks.offsetX, tY + axisTicks.offsetY, x + axisBorder.offsetX + axisTicks.offsetX, tY + axisTicks.offsetY, axisTicks.color);
  3502. elYaxis.add(elTick);
  3503. tY += labelsDivider;
  3504. }
  3505. }
  3506. }
  3507. }]);
  3508. return AxesUtils;
  3509. }();
  3510. var YAnnotations = /*#__PURE__*/function () {
  3511. function YAnnotations(annoCtx) {
  3512. _classCallCheck(this, YAnnotations);
  3513. this.w = annoCtx.w;
  3514. this.annoCtx = annoCtx;
  3515. this.helpers = new Helpers$4(this.annoCtx);
  3516. this.axesUtils = new AxesUtils(this.annoCtx);
  3517. }
  3518. _createClass(YAnnotations, [{
  3519. key: "addYaxisAnnotation",
  3520. value: function addYaxisAnnotation(anno, parent, index) {
  3521. var w = this.w;
  3522. var strokeDashArray = anno.strokeDashArray;
  3523. var result = this.helpers.getY1Y2('y1', anno);
  3524. var y1 = result.yP;
  3525. var clipY1 = result.clipped;
  3526. var y2;
  3527. var clipY2 = true;
  3528. var drawn = false;
  3529. var text = anno.label.text;
  3530. if (anno.y2 === null || typeof anno.y2 === 'undefined') {
  3531. if (!clipY1) {
  3532. drawn = true;
  3533. var line = this.annoCtx.graphics.drawLine(0 + anno.offsetX,
  3534. // x1
  3535. y1 + anno.offsetY,
  3536. // y1
  3537. this._getYAxisAnnotationWidth(anno),
  3538. // x2
  3539. y1 + anno.offsetY,
  3540. // y2
  3541. anno.borderColor,
  3542. // lineColor
  3543. strokeDashArray,
  3544. // dashArray
  3545. anno.borderWidth);
  3546. parent.appendChild(line.node);
  3547. if (anno.id) {
  3548. line.node.classList.add(anno.id);
  3549. }
  3550. }
  3551. } else {
  3552. result = this.helpers.getY1Y2('y2', anno);
  3553. y2 = result.yP;
  3554. clipY2 = result.clipped;
  3555. if (y2 > y1) {
  3556. var temp = y1;
  3557. y1 = y2;
  3558. y2 = temp;
  3559. }
  3560. if (!(clipY1 && clipY2)) {
  3561. drawn = true;
  3562. var rect = this.annoCtx.graphics.drawRect(0 + anno.offsetX,
  3563. // x1
  3564. y2 + anno.offsetY,
  3565. // y1
  3566. this._getYAxisAnnotationWidth(anno),
  3567. // x2
  3568. y1 - y2,
  3569. // y2
  3570. 0,
  3571. // radius
  3572. anno.fillColor,
  3573. // color
  3574. anno.opacity,
  3575. // opacity,
  3576. 1,
  3577. // strokeWidth
  3578. anno.borderColor,
  3579. // strokeColor
  3580. strokeDashArray // stokeDashArray
  3581. );
  3582. rect.node.classList.add('apexcharts-annotation-rect');
  3583. rect.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
  3584. parent.appendChild(rect.node);
  3585. if (anno.id) {
  3586. rect.node.classList.add(anno.id);
  3587. }
  3588. }
  3589. }
  3590. if (drawn) {
  3591. var textX = anno.label.position === 'right' ? w.globals.gridWidth : anno.label.position === 'center' ? w.globals.gridWidth / 2 : 0;
  3592. var elText = this.annoCtx.graphics.drawText({
  3593. x: textX + anno.label.offsetX,
  3594. y: (y2 != null ? y2 : y1) + anno.label.offsetY - 3,
  3595. text: text,
  3596. textAnchor: anno.label.textAnchor,
  3597. fontSize: anno.label.style.fontSize,
  3598. fontFamily: anno.label.style.fontFamily,
  3599. fontWeight: anno.label.style.fontWeight,
  3600. foreColor: anno.label.style.color,
  3601. cssClass: "apexcharts-yaxis-annotation-label ".concat(anno.label.style.cssClass, " ").concat(anno.id ? anno.id : '')
  3602. });
  3603. elText.attr({
  3604. rel: index
  3605. });
  3606. parent.appendChild(elText.node);
  3607. }
  3608. }
  3609. }, {
  3610. key: "_getYAxisAnnotationWidth",
  3611. value: function _getYAxisAnnotationWidth(anno) {
  3612. // issue apexcharts.js#2009
  3613. var w = this.w;
  3614. var width = w.globals.gridWidth;
  3615. if (anno.width.indexOf('%') > -1) {
  3616. width = w.globals.gridWidth * parseInt(anno.width, 10) / 100;
  3617. } else {
  3618. width = parseInt(anno.width, 10);
  3619. }
  3620. return width + anno.offsetX;
  3621. }
  3622. }, {
  3623. key: "drawYAxisAnnotations",
  3624. value: function drawYAxisAnnotations() {
  3625. var _this = this;
  3626. var w = this.w;
  3627. var elg = this.annoCtx.graphics.group({
  3628. class: 'apexcharts-yaxis-annotations'
  3629. });
  3630. w.config.annotations.yaxis.forEach(function (anno, index) {
  3631. anno.yAxisIndex = _this.axesUtils.translateYAxisIndex(anno.yAxisIndex);
  3632. if (!(_this.axesUtils.isYAxisHidden(anno.yAxisIndex) && _this.axesUtils.yAxisAllSeriesCollapsed(anno.yAxisIndex))) {
  3633. _this.addYaxisAnnotation(anno, elg.node, index);
  3634. }
  3635. });
  3636. return elg;
  3637. }
  3638. }]);
  3639. return YAnnotations;
  3640. }();
  3641. var PointAnnotations = /*#__PURE__*/function () {
  3642. function PointAnnotations(annoCtx) {
  3643. _classCallCheck(this, PointAnnotations);
  3644. this.w = annoCtx.w;
  3645. this.annoCtx = annoCtx;
  3646. this.helpers = new Helpers$4(this.annoCtx);
  3647. }
  3648. _createClass(PointAnnotations, [{
  3649. key: "addPointAnnotation",
  3650. value: function addPointAnnotation(anno, parent, index) {
  3651. var w = this.w;
  3652. if (w.globals.collapsedSeriesIndices.indexOf(anno.seriesIndex) > -1) {
  3653. return;
  3654. }
  3655. var result = this.helpers.getX1X2('x1', anno);
  3656. var x = result.x;
  3657. var clipX = result.clipped;
  3658. result = this.helpers.getY1Y2('y1', anno);
  3659. var y = result.yP;
  3660. var clipY = result.clipped;
  3661. if (!Utils$1.isNumber(x)) return;
  3662. if (!(clipY || clipX)) {
  3663. var optsPoints = {
  3664. pSize: anno.marker.size,
  3665. pointStrokeWidth: anno.marker.strokeWidth,
  3666. pointFillColor: anno.marker.fillColor,
  3667. pointStrokeColor: anno.marker.strokeColor,
  3668. shape: anno.marker.shape,
  3669. pRadius: anno.marker.radius,
  3670. class: "apexcharts-point-annotation-marker ".concat(anno.marker.cssClass, " ").concat(anno.id ? anno.id : '')
  3671. };
  3672. var point = this.annoCtx.graphics.drawMarker(x + anno.marker.offsetX, y + anno.marker.offsetY, optsPoints);
  3673. parent.appendChild(point.node);
  3674. var text = anno.label.text ? anno.label.text : '';
  3675. var elText = this.annoCtx.graphics.drawText({
  3676. x: x + anno.label.offsetX,
  3677. y: y + anno.label.offsetY - anno.marker.size - parseFloat(anno.label.style.fontSize) / 1.6,
  3678. text: text,
  3679. textAnchor: anno.label.textAnchor,
  3680. fontSize: anno.label.style.fontSize,
  3681. fontFamily: anno.label.style.fontFamily,
  3682. fontWeight: anno.label.style.fontWeight,
  3683. foreColor: anno.label.style.color,
  3684. cssClass: "apexcharts-point-annotation-label ".concat(anno.label.style.cssClass, " ").concat(anno.id ? anno.id : '')
  3685. });
  3686. elText.attr({
  3687. rel: index
  3688. });
  3689. parent.appendChild(elText.node);
  3690. // TODO: deprecate this as we will use custom
  3691. if (anno.customSVG.SVG) {
  3692. var g = this.annoCtx.graphics.group({
  3693. class: 'apexcharts-point-annotations-custom-svg ' + anno.customSVG.cssClass
  3694. });
  3695. g.attr({
  3696. transform: "translate(".concat(x + anno.customSVG.offsetX, ", ").concat(y + anno.customSVG.offsetY, ")")
  3697. });
  3698. g.node.innerHTML = anno.customSVG.SVG;
  3699. parent.appendChild(g.node);
  3700. }
  3701. if (anno.image.path) {
  3702. var imgWidth = anno.image.width ? anno.image.width : 20;
  3703. var imgHeight = anno.image.height ? anno.image.height : 20;
  3704. point = this.annoCtx.addImage({
  3705. x: x + anno.image.offsetX - imgWidth / 2,
  3706. y: y + anno.image.offsetY - imgHeight / 2,
  3707. width: imgWidth,
  3708. height: imgHeight,
  3709. path: anno.image.path,
  3710. appendTo: '.apexcharts-point-annotations'
  3711. });
  3712. }
  3713. if (anno.mouseEnter) {
  3714. point.node.addEventListener('mouseenter', anno.mouseEnter.bind(this, anno));
  3715. }
  3716. if (anno.mouseLeave) {
  3717. point.node.addEventListener('mouseleave', anno.mouseLeave.bind(this, anno));
  3718. }
  3719. if (anno.click) {
  3720. point.node.addEventListener('click', anno.click.bind(this, anno));
  3721. }
  3722. }
  3723. }
  3724. }, {
  3725. key: "drawPointAnnotations",
  3726. value: function drawPointAnnotations() {
  3727. var _this = this;
  3728. var w = this.w;
  3729. var elg = this.annoCtx.graphics.group({
  3730. class: 'apexcharts-point-annotations'
  3731. });
  3732. w.config.annotations.points.map(function (anno, index) {
  3733. _this.addPointAnnotation(anno, elg.node, index);
  3734. });
  3735. return elg;
  3736. }
  3737. }]);
  3738. return PointAnnotations;
  3739. }();
  3740. const name = "en";
  3741. const options = {
  3742. months: [
  3743. "January",
  3744. "February",
  3745. "March",
  3746. "April",
  3747. "May",
  3748. "June",
  3749. "July",
  3750. "August",
  3751. "September",
  3752. "October",
  3753. "November",
  3754. "December"
  3755. ],
  3756. shortMonths: [
  3757. "Jan",
  3758. "Feb",
  3759. "Mar",
  3760. "Apr",
  3761. "May",
  3762. "Jun",
  3763. "Jul",
  3764. "Aug",
  3765. "Sep",
  3766. "Oct",
  3767. "Nov",
  3768. "Dec"
  3769. ],
  3770. days: [
  3771. "Sunday",
  3772. "Monday",
  3773. "Tuesday",
  3774. "Wednesday",
  3775. "Thursday",
  3776. "Friday",
  3777. "Saturday"
  3778. ],
  3779. shortDays: [
  3780. "Sun",
  3781. "Mon",
  3782. "Tue",
  3783. "Wed",
  3784. "Thu",
  3785. "Fri",
  3786. "Sat"
  3787. ],
  3788. toolbar: {
  3789. exportToSVG: "Download SVG",
  3790. exportToPNG: "Download PNG",
  3791. exportToCSV: "Download CSV",
  3792. menu: "Menu",
  3793. selection: "Selection",
  3794. selectionZoom: "Selection Zoom",
  3795. zoomIn: "Zoom In",
  3796. zoomOut: "Zoom Out",
  3797. pan: "Panning",
  3798. reset: "Reset Zoom"
  3799. }
  3800. };
  3801. var en = {
  3802. name: name,
  3803. options: options
  3804. };
  3805. var Options = /*#__PURE__*/function () {
  3806. function Options() {
  3807. _classCallCheck(this, Options);
  3808. this.yAxis = {
  3809. show: true,
  3810. showAlways: false,
  3811. showForNullSeries: true,
  3812. seriesName: undefined,
  3813. opposite: false,
  3814. reversed: false,
  3815. logarithmic: false,
  3816. logBase: 10,
  3817. tickAmount: undefined,
  3818. stepSize: undefined,
  3819. forceNiceScale: false,
  3820. max: undefined,
  3821. min: undefined,
  3822. floating: false,
  3823. decimalsInFloat: undefined,
  3824. labels: {
  3825. show: true,
  3826. showDuplicates: false,
  3827. minWidth: 0,
  3828. maxWidth: 160,
  3829. offsetX: 0,
  3830. offsetY: 0,
  3831. align: undefined,
  3832. rotate: 0,
  3833. padding: 20,
  3834. style: {
  3835. colors: [],
  3836. fontSize: '11px',
  3837. fontWeight: 400,
  3838. fontFamily: undefined,
  3839. cssClass: ''
  3840. },
  3841. formatter: undefined
  3842. },
  3843. axisBorder: {
  3844. show: false,
  3845. color: '#e0e0e0',
  3846. width: 1,
  3847. offsetX: 0,
  3848. offsetY: 0
  3849. },
  3850. axisTicks: {
  3851. show: false,
  3852. color: '#e0e0e0',
  3853. width: 6,
  3854. offsetX: 0,
  3855. offsetY: 0
  3856. },
  3857. title: {
  3858. text: undefined,
  3859. rotate: -90,
  3860. offsetY: 0,
  3861. offsetX: 0,
  3862. style: {
  3863. color: undefined,
  3864. fontSize: '11px',
  3865. fontWeight: 900,
  3866. fontFamily: undefined,
  3867. cssClass: ''
  3868. }
  3869. },
  3870. tooltip: {
  3871. enabled: false,
  3872. offsetX: 0
  3873. },
  3874. crosshairs: {
  3875. show: true,
  3876. position: 'front',
  3877. stroke: {
  3878. color: '#b6b6b6',
  3879. width: 1,
  3880. dashArray: 0
  3881. }
  3882. }
  3883. };
  3884. this.pointAnnotation = {
  3885. id: undefined,
  3886. x: 0,
  3887. y: null,
  3888. yAxisIndex: 0,
  3889. seriesIndex: undefined,
  3890. mouseEnter: undefined,
  3891. mouseLeave: undefined,
  3892. click: undefined,
  3893. marker: {
  3894. size: 4,
  3895. fillColor: '#fff',
  3896. strokeWidth: 2,
  3897. strokeColor: '#333',
  3898. shape: 'circle',
  3899. offsetX: 0,
  3900. offsetY: 0,
  3901. // radius: 2, // DEPRECATED
  3902. cssClass: ''
  3903. },
  3904. label: {
  3905. borderColor: '#c2c2c2',
  3906. borderWidth: 1,
  3907. borderRadius: 2,
  3908. text: undefined,
  3909. textAnchor: 'middle',
  3910. offsetX: 0,
  3911. offsetY: 0,
  3912. mouseEnter: undefined,
  3913. mouseLeave: undefined,
  3914. click: undefined,
  3915. style: {
  3916. background: '#fff',
  3917. color: undefined,
  3918. fontSize: '11px',
  3919. fontFamily: undefined,
  3920. fontWeight: 400,
  3921. cssClass: '',
  3922. padding: {
  3923. left: 5,
  3924. right: 5,
  3925. top: 2,
  3926. bottom: 2
  3927. }
  3928. }
  3929. },
  3930. customSVG: {
  3931. // this will be deprecated in the next major version as it is going to be replaced with a better alternative below (image)
  3932. SVG: undefined,
  3933. cssClass: undefined,
  3934. offsetX: 0,
  3935. offsetY: 0
  3936. },
  3937. image: {
  3938. path: undefined,
  3939. width: 20,
  3940. height: 20,
  3941. offsetX: 0,
  3942. offsetY: 0
  3943. }
  3944. };
  3945. this.yAxisAnnotation = {
  3946. id: undefined,
  3947. y: 0,
  3948. y2: null,
  3949. strokeDashArray: 1,
  3950. fillColor: '#c2c2c2',
  3951. borderColor: '#c2c2c2',
  3952. borderWidth: 1,
  3953. opacity: 0.3,
  3954. offsetX: 0,
  3955. offsetY: 0,
  3956. width: '100%',
  3957. yAxisIndex: 0,
  3958. label: {
  3959. borderColor: '#c2c2c2',
  3960. borderWidth: 1,
  3961. borderRadius: 2,
  3962. text: undefined,
  3963. textAnchor: 'end',
  3964. position: 'right',
  3965. offsetX: 0,
  3966. offsetY: -3,
  3967. mouseEnter: undefined,
  3968. mouseLeave: undefined,
  3969. click: undefined,
  3970. style: {
  3971. background: '#fff',
  3972. color: undefined,
  3973. fontSize: '11px',
  3974. fontFamily: undefined,
  3975. fontWeight: 400,
  3976. cssClass: '',
  3977. padding: {
  3978. left: 5,
  3979. right: 5,
  3980. top: 2,
  3981. bottom: 2
  3982. }
  3983. }
  3984. }
  3985. };
  3986. this.xAxisAnnotation = {
  3987. id: undefined,
  3988. x: 0,
  3989. x2: null,
  3990. strokeDashArray: 1,
  3991. fillColor: '#c2c2c2',
  3992. borderColor: '#c2c2c2',
  3993. borderWidth: 1,
  3994. opacity: 0.3,
  3995. offsetX: 0,
  3996. offsetY: 0,
  3997. label: {
  3998. borderColor: '#c2c2c2',
  3999. borderWidth: 1,
  4000. borderRadius: 2,
  4001. text: undefined,
  4002. textAnchor: 'middle',
  4003. orientation: 'vertical',
  4004. position: 'top',
  4005. offsetX: 0,
  4006. offsetY: 0,
  4007. mouseEnter: undefined,
  4008. mouseLeave: undefined,
  4009. click: undefined,
  4010. style: {
  4011. background: '#fff',
  4012. color: undefined,
  4013. fontSize: '11px',
  4014. fontFamily: undefined,
  4015. fontWeight: 400,
  4016. cssClass: '',
  4017. padding: {
  4018. left: 5,
  4019. right: 5,
  4020. top: 2,
  4021. bottom: 2
  4022. }
  4023. }
  4024. }
  4025. };
  4026. this.text = {
  4027. x: 0,
  4028. y: 0,
  4029. text: '',
  4030. textAnchor: 'start',
  4031. foreColor: undefined,
  4032. fontSize: '13px',
  4033. fontFamily: undefined,
  4034. fontWeight: 400,
  4035. appendTo: '.apexcharts-annotations',
  4036. backgroundColor: 'transparent',
  4037. borderColor: '#c2c2c2',
  4038. borderRadius: 0,
  4039. borderWidth: 0,
  4040. paddingLeft: 4,
  4041. paddingRight: 4,
  4042. paddingTop: 2,
  4043. paddingBottom: 2
  4044. };
  4045. }
  4046. _createClass(Options, [{
  4047. key: "init",
  4048. value: function init() {
  4049. return {
  4050. annotations: {
  4051. yaxis: [this.yAxisAnnotation],
  4052. xaxis: [this.xAxisAnnotation],
  4053. points: [this.pointAnnotation],
  4054. texts: [],
  4055. images: [],
  4056. shapes: []
  4057. },
  4058. chart: {
  4059. animations: {
  4060. enabled: true,
  4061. easing: 'easeinout',
  4062. // linear, easeout, easein, easeinout, swing, bounce, elastic
  4063. speed: 800,
  4064. animateGradually: {
  4065. delay: 150,
  4066. enabled: true
  4067. },
  4068. dynamicAnimation: {
  4069. enabled: true,
  4070. speed: 350
  4071. }
  4072. },
  4073. background: '',
  4074. locales: [en],
  4075. defaultLocale: 'en',
  4076. dropShadow: {
  4077. enabled: false,
  4078. enabledOnSeries: undefined,
  4079. top: 2,
  4080. left: 2,
  4081. blur: 4,
  4082. color: '#000',
  4083. opacity: 0.35
  4084. },
  4085. events: {
  4086. animationEnd: undefined,
  4087. beforeMount: undefined,
  4088. mounted: undefined,
  4089. updated: undefined,
  4090. click: undefined,
  4091. mouseMove: undefined,
  4092. mouseLeave: undefined,
  4093. xAxisLabelClick: undefined,
  4094. legendClick: undefined,
  4095. markerClick: undefined,
  4096. selection: undefined,
  4097. dataPointSelection: undefined,
  4098. dataPointMouseEnter: undefined,
  4099. dataPointMouseLeave: undefined,
  4100. beforeZoom: undefined,
  4101. beforeResetZoom: undefined,
  4102. zoomed: undefined,
  4103. scrolled: undefined,
  4104. brushScrolled: undefined
  4105. },
  4106. foreColor: '#373d3f',
  4107. fontFamily: 'Helvetica, Arial, sans-serif',
  4108. height: 'auto',
  4109. parentHeightOffset: 15,
  4110. redrawOnParentResize: true,
  4111. redrawOnWindowResize: true,
  4112. id: undefined,
  4113. group: undefined,
  4114. nonce: undefined,
  4115. offsetX: 0,
  4116. offsetY: 0,
  4117. selection: {
  4118. enabled: false,
  4119. type: 'x',
  4120. // selectedPoints: undefined, // default datapoints that should be selected automatically
  4121. fill: {
  4122. color: '#24292e',
  4123. opacity: 0.1
  4124. },
  4125. stroke: {
  4126. width: 1,
  4127. color: '#24292e',
  4128. opacity: 0.4,
  4129. dashArray: 3
  4130. },
  4131. xaxis: {
  4132. min: undefined,
  4133. max: undefined
  4134. },
  4135. yaxis: {
  4136. min: undefined,
  4137. max: undefined
  4138. }
  4139. },
  4140. sparkline: {
  4141. enabled: false
  4142. },
  4143. brush: {
  4144. enabled: false,
  4145. autoScaleYaxis: true,
  4146. target: undefined,
  4147. targets: undefined
  4148. },
  4149. stacked: false,
  4150. stackOnlyBar: true,
  4151. // mixed chart with stacked bars and line series - incorrect line draw #907
  4152. stackType: 'normal',
  4153. toolbar: {
  4154. show: true,
  4155. offsetX: 0,
  4156. offsetY: 0,
  4157. tools: {
  4158. download: true,
  4159. selection: true,
  4160. zoom: true,
  4161. zoomin: true,
  4162. zoomout: true,
  4163. pan: true,
  4164. reset: true,
  4165. customIcons: []
  4166. },
  4167. export: {
  4168. csv: {
  4169. filename: undefined,
  4170. columnDelimiter: ',',
  4171. headerCategory: 'category',
  4172. headerValue: 'value',
  4173. categoryFormatter: undefined,
  4174. valueFormatter: undefined
  4175. },
  4176. png: {
  4177. filename: undefined
  4178. },
  4179. svg: {
  4180. filename: undefined
  4181. },
  4182. scale: undefined,
  4183. width: undefined
  4184. },
  4185. autoSelected: 'zoom' // accepts -> zoom, pan, selection
  4186. },
  4187. type: 'line',
  4188. width: '100%',
  4189. zoom: {
  4190. enabled: true,
  4191. type: 'x',
  4192. autoScaleYaxis: false,
  4193. allowMouseWheelZoom: true,
  4194. zoomedArea: {
  4195. fill: {
  4196. color: '#90CAF9',
  4197. opacity: 0.4
  4198. },
  4199. stroke: {
  4200. color: '#0D47A1',
  4201. opacity: 0.4,
  4202. width: 1
  4203. }
  4204. }
  4205. }
  4206. },
  4207. plotOptions: {
  4208. line: {
  4209. isSlopeChart: false
  4210. },
  4211. area: {
  4212. fillTo: 'origin'
  4213. },
  4214. bar: {
  4215. horizontal: false,
  4216. columnWidth: '70%',
  4217. // should be in percent 0 - 100
  4218. barHeight: '70%',
  4219. // should be in percent 0 - 100
  4220. distributed: false,
  4221. borderRadius: 0,
  4222. borderRadiusApplication: 'around',
  4223. // [around, end]
  4224. borderRadiusWhenStacked: 'last',
  4225. // [all, last]
  4226. rangeBarOverlap: true,
  4227. rangeBarGroupRows: false,
  4228. hideZeroBarsWhenGrouped: false,
  4229. isDumbbell: false,
  4230. dumbbellColors: undefined,
  4231. isFunnel: false,
  4232. isFunnel3d: true,
  4233. colors: {
  4234. ranges: [],
  4235. backgroundBarColors: [],
  4236. backgroundBarOpacity: 1,
  4237. backgroundBarRadius: 0
  4238. },
  4239. dataLabels: {
  4240. position: 'top',
  4241. // top, center, bottom
  4242. maxItems: 100,
  4243. hideOverflowingLabels: true,
  4244. orientation: 'horizontal',
  4245. total: {
  4246. enabled: false,
  4247. formatter: undefined,
  4248. offsetX: 0,
  4249. offsetY: 0,
  4250. style: {
  4251. color: '#373d3f',
  4252. fontSize: '12px',
  4253. fontFamily: undefined,
  4254. fontWeight: 600
  4255. }
  4256. }
  4257. }
  4258. },
  4259. bubble: {
  4260. zScaling: true,
  4261. minBubbleRadius: undefined,
  4262. maxBubbleRadius: undefined
  4263. },
  4264. candlestick: {
  4265. colors: {
  4266. upward: '#00B746',
  4267. downward: '#EF403C'
  4268. },
  4269. wick: {
  4270. useFillColor: true
  4271. }
  4272. },
  4273. boxPlot: {
  4274. colors: {
  4275. upper: '#00E396',
  4276. lower: '#008FFB'
  4277. }
  4278. },
  4279. heatmap: {
  4280. radius: 2,
  4281. enableShades: true,
  4282. shadeIntensity: 0.5,
  4283. reverseNegativeShade: false,
  4284. distributed: false,
  4285. useFillColorAsStroke: false,
  4286. colorScale: {
  4287. inverse: false,
  4288. ranges: [],
  4289. min: undefined,
  4290. max: undefined
  4291. }
  4292. },
  4293. treemap: {
  4294. enableShades: true,
  4295. shadeIntensity: 0.5,
  4296. distributed: false,
  4297. reverseNegativeShade: false,
  4298. useFillColorAsStroke: false,
  4299. borderRadius: 4,
  4300. dataLabels: {
  4301. format: 'scale' // scale | truncate
  4302. },
  4303. colorScale: {
  4304. inverse: false,
  4305. ranges: [],
  4306. min: undefined,
  4307. max: undefined
  4308. }
  4309. },
  4310. radialBar: {
  4311. inverseOrder: false,
  4312. startAngle: 0,
  4313. endAngle: 360,
  4314. offsetX: 0,
  4315. offsetY: 0,
  4316. hollow: {
  4317. margin: 5,
  4318. size: '50%',
  4319. background: 'transparent',
  4320. image: undefined,
  4321. imageWidth: 150,
  4322. imageHeight: 150,
  4323. imageOffsetX: 0,
  4324. imageOffsetY: 0,
  4325. imageClipped: true,
  4326. position: 'front',
  4327. dropShadow: {
  4328. enabled: false,
  4329. top: 0,
  4330. left: 0,
  4331. blur: 3,
  4332. color: '#000',
  4333. opacity: 0.5
  4334. }
  4335. },
  4336. track: {
  4337. show: true,
  4338. startAngle: undefined,
  4339. endAngle: undefined,
  4340. background: '#f2f2f2',
  4341. strokeWidth: '97%',
  4342. opacity: 1,
  4343. margin: 5,
  4344. // margin is in pixels
  4345. dropShadow: {
  4346. enabled: false,
  4347. top: 0,
  4348. left: 0,
  4349. blur: 3,
  4350. color: '#000',
  4351. opacity: 0.5
  4352. }
  4353. },
  4354. dataLabels: {
  4355. show: true,
  4356. name: {
  4357. show: true,
  4358. fontSize: '16px',
  4359. fontFamily: undefined,
  4360. fontWeight: 600,
  4361. color: undefined,
  4362. offsetY: 0,
  4363. formatter: function formatter(val) {
  4364. return val;
  4365. }
  4366. },
  4367. value: {
  4368. show: true,
  4369. fontSize: '14px',
  4370. fontFamily: undefined,
  4371. fontWeight: 400,
  4372. color: undefined,
  4373. offsetY: 16,
  4374. formatter: function formatter(val) {
  4375. return val + '%';
  4376. }
  4377. },
  4378. total: {
  4379. show: false,
  4380. label: 'Total',
  4381. fontSize: '16px',
  4382. fontWeight: 600,
  4383. fontFamily: undefined,
  4384. color: undefined,
  4385. formatter: function formatter(w) {
  4386. return w.globals.seriesTotals.reduce(function (a, b) {
  4387. return a + b;
  4388. }, 0) / w.globals.series.length + '%';
  4389. }
  4390. }
  4391. },
  4392. barLabels: {
  4393. enabled: false,
  4394. offsetX: 0,
  4395. offsetY: 0,
  4396. useSeriesColors: true,
  4397. fontFamily: undefined,
  4398. fontWeight: 600,
  4399. fontSize: '16px',
  4400. formatter: function formatter(val) {
  4401. return val;
  4402. },
  4403. onClick: undefined
  4404. }
  4405. },
  4406. pie: {
  4407. customScale: 1,
  4408. offsetX: 0,
  4409. offsetY: 0,
  4410. startAngle: 0,
  4411. endAngle: 360,
  4412. expandOnClick: true,
  4413. dataLabels: {
  4414. // These are the percentage values which are displayed on slice
  4415. offset: 0,
  4416. // offset by which labels will move outside
  4417. minAngleToShowLabel: 10
  4418. },
  4419. donut: {
  4420. size: '65%',
  4421. background: 'transparent',
  4422. labels: {
  4423. // These are the inner labels appearing inside donut
  4424. show: false,
  4425. name: {
  4426. show: true,
  4427. fontSize: '16px',
  4428. fontFamily: undefined,
  4429. fontWeight: 600,
  4430. color: undefined,
  4431. offsetY: -10,
  4432. formatter: function formatter(val) {
  4433. return val;
  4434. }
  4435. },
  4436. value: {
  4437. show: true,
  4438. fontSize: '20px',
  4439. fontFamily: undefined,
  4440. fontWeight: 400,
  4441. color: undefined,
  4442. offsetY: 10,
  4443. formatter: function formatter(val) {
  4444. return val;
  4445. }
  4446. },
  4447. total: {
  4448. show: false,
  4449. showAlways: false,
  4450. label: 'Total',
  4451. fontSize: '16px',
  4452. fontWeight: 400,
  4453. fontFamily: undefined,
  4454. color: undefined,
  4455. formatter: function formatter(w) {
  4456. return w.globals.seriesTotals.reduce(function (a, b) {
  4457. return a + b;
  4458. }, 0);
  4459. }
  4460. }
  4461. }
  4462. }
  4463. },
  4464. polarArea: {
  4465. rings: {
  4466. strokeWidth: 1,
  4467. strokeColor: '#e8e8e8'
  4468. },
  4469. spokes: {
  4470. strokeWidth: 1,
  4471. connectorColors: '#e8e8e8'
  4472. }
  4473. },
  4474. radar: {
  4475. size: undefined,
  4476. offsetX: 0,
  4477. offsetY: 0,
  4478. polygons: {
  4479. // strokeColor: '#e8e8e8', // should be deprecated in the minor version i.e 3.2
  4480. strokeWidth: 1,
  4481. strokeColors: '#e8e8e8',
  4482. connectorColors: '#e8e8e8',
  4483. fill: {
  4484. colors: undefined
  4485. }
  4486. }
  4487. }
  4488. },
  4489. colors: undefined,
  4490. dataLabels: {
  4491. enabled: true,
  4492. enabledOnSeries: undefined,
  4493. formatter: function formatter(val) {
  4494. return val !== null ? val : '';
  4495. },
  4496. textAnchor: 'middle',
  4497. distributed: false,
  4498. offsetX: 0,
  4499. offsetY: 0,
  4500. style: {
  4501. fontSize: '12px',
  4502. fontFamily: undefined,
  4503. fontWeight: 600,
  4504. colors: undefined
  4505. },
  4506. background: {
  4507. enabled: true,
  4508. foreColor: '#fff',
  4509. borderRadius: 2,
  4510. padding: 4,
  4511. opacity: 0.9,
  4512. borderWidth: 1,
  4513. borderColor: '#fff',
  4514. dropShadow: {
  4515. enabled: false,
  4516. top: 1,
  4517. left: 1,
  4518. blur: 1,
  4519. color: '#000',
  4520. opacity: 0.45
  4521. }
  4522. },
  4523. dropShadow: {
  4524. enabled: false,
  4525. top: 1,
  4526. left: 1,
  4527. blur: 1,
  4528. color: '#000',
  4529. opacity: 0.45
  4530. }
  4531. },
  4532. fill: {
  4533. type: 'solid',
  4534. colors: undefined,
  4535. // array of colors
  4536. opacity: 0.85,
  4537. gradient: {
  4538. shade: 'dark',
  4539. type: 'horizontal',
  4540. shadeIntensity: 0.5,
  4541. gradientToColors: undefined,
  4542. inverseColors: true,
  4543. opacityFrom: 1,
  4544. opacityTo: 1,
  4545. stops: [0, 50, 100],
  4546. colorStops: []
  4547. },
  4548. image: {
  4549. src: [],
  4550. width: undefined,
  4551. // optional
  4552. height: undefined // optional
  4553. },
  4554. pattern: {
  4555. style: 'squares',
  4556. // String | Array of Strings
  4557. width: 6,
  4558. height: 6,
  4559. strokeWidth: 2
  4560. }
  4561. },
  4562. forecastDataPoints: {
  4563. count: 0,
  4564. fillOpacity: 0.5,
  4565. strokeWidth: undefined,
  4566. dashArray: 4
  4567. },
  4568. grid: {
  4569. show: true,
  4570. borderColor: '#e0e0e0',
  4571. strokeDashArray: 0,
  4572. position: 'back',
  4573. xaxis: {
  4574. lines: {
  4575. show: false
  4576. }
  4577. },
  4578. yaxis: {
  4579. lines: {
  4580. show: true
  4581. }
  4582. },
  4583. row: {
  4584. colors: undefined,
  4585. // takes as array which will be repeated on rows
  4586. opacity: 0.5
  4587. },
  4588. column: {
  4589. colors: undefined,
  4590. // takes an array which will be repeated on columns
  4591. opacity: 0.5
  4592. },
  4593. padding: {
  4594. top: 0,
  4595. right: 10,
  4596. bottom: 0,
  4597. left: 12
  4598. }
  4599. },
  4600. labels: [],
  4601. legend: {
  4602. show: true,
  4603. showForSingleSeries: false,
  4604. showForNullSeries: true,
  4605. showForZeroSeries: true,
  4606. floating: false,
  4607. position: 'bottom',
  4608. // whether to position legends in 1 of 4
  4609. // direction - top, bottom, left, right
  4610. horizontalAlign: 'center',
  4611. // when position top/bottom, you can specify whether to align legends left, right or center
  4612. inverseOrder: false,
  4613. fontSize: '12px',
  4614. fontFamily: undefined,
  4615. fontWeight: 400,
  4616. width: undefined,
  4617. height: undefined,
  4618. formatter: undefined,
  4619. tooltipHoverFormatter: undefined,
  4620. offsetX: -20,
  4621. offsetY: 4,
  4622. customLegendItems: [],
  4623. labels: {
  4624. colors: undefined,
  4625. useSeriesColors: false
  4626. },
  4627. markers: {
  4628. size: 7,
  4629. fillColors: undefined,
  4630. strokeWidth: 1,
  4631. shape: undefined,
  4632. offsetX: 0,
  4633. offsetY: 0,
  4634. customHTML: undefined,
  4635. onClick: undefined
  4636. },
  4637. itemMargin: {
  4638. horizontal: 5,
  4639. vertical: 4
  4640. },
  4641. onItemClick: {
  4642. toggleDataSeries: true
  4643. },
  4644. onItemHover: {
  4645. highlightDataSeries: true
  4646. }
  4647. },
  4648. markers: {
  4649. discrete: [],
  4650. size: 0,
  4651. colors: undefined,
  4652. strokeColors: '#fff',
  4653. strokeWidth: 2,
  4654. strokeOpacity: 0.9,
  4655. strokeDashArray: 0,
  4656. fillOpacity: 1,
  4657. shape: 'circle',
  4658. offsetX: 0,
  4659. offsetY: 0,
  4660. showNullDataPoints: true,
  4661. onClick: undefined,
  4662. onDblClick: undefined,
  4663. hover: {
  4664. size: undefined,
  4665. sizeOffset: 3
  4666. }
  4667. },
  4668. noData: {
  4669. text: undefined,
  4670. align: 'center',
  4671. verticalAlign: 'middle',
  4672. offsetX: 0,
  4673. offsetY: 0,
  4674. style: {
  4675. color: undefined,
  4676. fontSize: '14px',
  4677. fontFamily: undefined
  4678. }
  4679. },
  4680. responsive: [],
  4681. // breakpoints should follow ascending order 400, then 700, then 1000
  4682. series: undefined,
  4683. states: {
  4684. normal: {
  4685. filter: {
  4686. type: 'none',
  4687. value: 0
  4688. }
  4689. },
  4690. hover: {
  4691. filter: {
  4692. type: 'lighten',
  4693. value: 0.1
  4694. }
  4695. },
  4696. active: {
  4697. allowMultipleDataPointsSelection: false,
  4698. filter: {
  4699. type: 'darken',
  4700. value: 0.5
  4701. }
  4702. }
  4703. },
  4704. title: {
  4705. text: undefined,
  4706. align: 'left',
  4707. margin: 5,
  4708. offsetX: 0,
  4709. offsetY: 0,
  4710. floating: false,
  4711. style: {
  4712. fontSize: '14px',
  4713. fontWeight: 900,
  4714. fontFamily: undefined,
  4715. color: undefined
  4716. }
  4717. },
  4718. subtitle: {
  4719. text: undefined,
  4720. align: 'left',
  4721. margin: 5,
  4722. offsetX: 0,
  4723. offsetY: 30,
  4724. floating: false,
  4725. style: {
  4726. fontSize: '12px',
  4727. fontWeight: 400,
  4728. fontFamily: undefined,
  4729. color: undefined
  4730. }
  4731. },
  4732. stroke: {
  4733. show: true,
  4734. curve: 'smooth',
  4735. // "smooth" / "straight" / "monotoneCubic" / "stepline" / "linestep"
  4736. lineCap: 'butt',
  4737. // round, butt , square
  4738. width: 2,
  4739. colors: undefined,
  4740. // array of colors
  4741. dashArray: 0,
  4742. // single value or array of values
  4743. fill: {
  4744. type: 'solid',
  4745. colors: undefined,
  4746. // array of colors
  4747. opacity: 0.85,
  4748. gradient: {
  4749. shade: 'dark',
  4750. type: 'horizontal',
  4751. shadeIntensity: 0.5,
  4752. gradientToColors: undefined,
  4753. inverseColors: true,
  4754. opacityFrom: 1,
  4755. opacityTo: 1,
  4756. stops: [0, 50, 100],
  4757. colorStops: []
  4758. }
  4759. }
  4760. },
  4761. tooltip: {
  4762. enabled: true,
  4763. enabledOnSeries: undefined,
  4764. shared: true,
  4765. hideEmptySeries: false,
  4766. followCursor: false,
  4767. // when disabled, the tooltip will show on top of the series instead of mouse position
  4768. intersect: false,
  4769. // when enabled, tooltip will only show when user directly hovers over point
  4770. inverseOrder: false,
  4771. custom: undefined,
  4772. fillSeriesColor: false,
  4773. theme: 'light',
  4774. cssClass: '',
  4775. style: {
  4776. fontSize: '12px',
  4777. fontFamily: undefined
  4778. },
  4779. onDatasetHover: {
  4780. highlightDataSeries: false
  4781. },
  4782. x: {
  4783. // x value
  4784. show: true,
  4785. format: 'dd MMM',
  4786. // dd/MM, dd MMM yy, dd MMM yyyy
  4787. formatter: undefined // a custom user supplied formatter function
  4788. },
  4789. y: {
  4790. formatter: undefined,
  4791. title: {
  4792. formatter: function formatter(seriesName) {
  4793. return seriesName ? seriesName + ': ' : '';
  4794. }
  4795. }
  4796. },
  4797. z: {
  4798. formatter: undefined,
  4799. title: 'Size: '
  4800. },
  4801. marker: {
  4802. show: true,
  4803. fillColors: undefined
  4804. },
  4805. items: {
  4806. display: 'flex'
  4807. },
  4808. fixed: {
  4809. enabled: false,
  4810. position: 'topRight',
  4811. // topRight, topLeft, bottomRight, bottomLeft
  4812. offsetX: 0,
  4813. offsetY: 0
  4814. }
  4815. },
  4816. xaxis: {
  4817. type: 'category',
  4818. categories: [],
  4819. convertedCatToNumeric: false,
  4820. // internal property which should not be altered outside
  4821. offsetX: 0,
  4822. offsetY: 0,
  4823. overwriteCategories: undefined,
  4824. labels: {
  4825. show: true,
  4826. rotate: -45,
  4827. rotateAlways: false,
  4828. hideOverlappingLabels: true,
  4829. trim: false,
  4830. minHeight: undefined,
  4831. maxHeight: 120,
  4832. showDuplicates: true,
  4833. style: {
  4834. colors: [],
  4835. fontSize: '12px',
  4836. fontWeight: 400,
  4837. fontFamily: undefined,
  4838. cssClass: ''
  4839. },
  4840. offsetX: 0,
  4841. offsetY: 0,
  4842. format: undefined,
  4843. formatter: undefined,
  4844. // custom formatter function which will override format
  4845. datetimeUTC: true,
  4846. datetimeFormatter: {
  4847. year: 'yyyy',
  4848. month: "MMM 'yy",
  4849. day: 'dd MMM',
  4850. hour: 'HH:mm',
  4851. minute: 'HH:mm:ss',
  4852. second: 'HH:mm:ss'
  4853. }
  4854. },
  4855. group: {
  4856. groups: [],
  4857. style: {
  4858. colors: [],
  4859. fontSize: '12px',
  4860. fontWeight: 400,
  4861. fontFamily: undefined,
  4862. cssClass: ''
  4863. }
  4864. },
  4865. axisBorder: {
  4866. show: true,
  4867. color: '#e0e0e0',
  4868. width: '100%',
  4869. height: 1,
  4870. offsetX: 0,
  4871. offsetY: 0
  4872. },
  4873. axisTicks: {
  4874. show: true,
  4875. color: '#e0e0e0',
  4876. height: 6,
  4877. offsetX: 0,
  4878. offsetY: 0
  4879. },
  4880. stepSize: undefined,
  4881. tickAmount: undefined,
  4882. tickPlacement: 'on',
  4883. min: undefined,
  4884. max: undefined,
  4885. range: undefined,
  4886. floating: false,
  4887. decimalsInFloat: undefined,
  4888. position: 'bottom',
  4889. title: {
  4890. text: undefined,
  4891. offsetX: 0,
  4892. offsetY: 0,
  4893. style: {
  4894. color: undefined,
  4895. fontSize: '12px',
  4896. fontWeight: 900,
  4897. fontFamily: undefined,
  4898. cssClass: ''
  4899. }
  4900. },
  4901. crosshairs: {
  4902. show: true,
  4903. width: 1,
  4904. // tickWidth/barWidth or an integer
  4905. position: 'back',
  4906. opacity: 0.9,
  4907. stroke: {
  4908. color: '#b6b6b6',
  4909. width: 1,
  4910. dashArray: 3
  4911. },
  4912. fill: {
  4913. type: 'solid',
  4914. // solid, gradient
  4915. color: '#B1B9C4',
  4916. gradient: {
  4917. colorFrom: '#D8E3F0',
  4918. colorTo: '#BED1E6',
  4919. stops: [0, 100],
  4920. opacityFrom: 0.4,
  4921. opacityTo: 0.5
  4922. }
  4923. },
  4924. dropShadow: {
  4925. enabled: false,
  4926. left: 0,
  4927. top: 0,
  4928. blur: 1,
  4929. opacity: 0.4
  4930. }
  4931. },
  4932. tooltip: {
  4933. enabled: true,
  4934. offsetY: 0,
  4935. formatter: undefined,
  4936. style: {
  4937. fontSize: '12px',
  4938. fontFamily: undefined
  4939. }
  4940. }
  4941. },
  4942. yaxis: this.yAxis,
  4943. theme: {
  4944. mode: '',
  4945. palette: 'palette1',
  4946. // If defined, it will overwrite globals.colors variable
  4947. monochrome: {
  4948. // monochrome allows you to select just 1 color and fill out the rest with light/dark shade (intensity can be selected)
  4949. enabled: false,
  4950. color: '#008FFB',
  4951. shadeTo: 'light',
  4952. shadeIntensity: 0.65
  4953. }
  4954. }
  4955. };
  4956. }
  4957. }]);
  4958. return Options;
  4959. }();
  4960. /**
  4961. * ApexCharts Annotations Class for drawing lines/rects on both xaxis and yaxis.
  4962. *
  4963. * @module Annotations
  4964. **/
  4965. var Annotations = /*#__PURE__*/function () {
  4966. function Annotations(ctx) {
  4967. _classCallCheck(this, Annotations);
  4968. this.ctx = ctx;
  4969. this.w = ctx.w;
  4970. this.graphics = new Graphics(this.ctx);
  4971. if (this.w.globals.isBarHorizontal) {
  4972. this.invertAxis = true;
  4973. }
  4974. this.helpers = new Helpers$4(this);
  4975. this.xAxisAnnotations = new XAnnotations(this);
  4976. this.yAxisAnnotations = new YAnnotations(this);
  4977. this.pointsAnnotations = new PointAnnotations(this);
  4978. if (this.w.globals.isBarHorizontal && this.w.config.yaxis[0].reversed) {
  4979. this.inversedReversedAxis = true;
  4980. }
  4981. this.xDivision = this.w.globals.gridWidth / this.w.globals.dataPoints;
  4982. }
  4983. _createClass(Annotations, [{
  4984. key: "drawAxesAnnotations",
  4985. value: function drawAxesAnnotations() {
  4986. var w = this.w;
  4987. if (w.globals.axisCharts && w.globals.dataPoints) {
  4988. // w.globals.dataPoints check added to fix #1832
  4989. var yAnnotations = this.yAxisAnnotations.drawYAxisAnnotations();
  4990. var xAnnotations = this.xAxisAnnotations.drawXAxisAnnotations();
  4991. var pointAnnotations = this.pointsAnnotations.drawPointAnnotations();
  4992. var initialAnim = w.config.chart.animations.enabled;
  4993. var annoArray = [yAnnotations, xAnnotations, pointAnnotations];
  4994. var annoElArray = [xAnnotations.node, yAnnotations.node, pointAnnotations.node];
  4995. for (var i = 0; i < 3; i++) {
  4996. w.globals.dom.elGraphical.add(annoArray[i]);
  4997. if (initialAnim && !w.globals.resized && !w.globals.dataChanged) {
  4998. // fixes apexcharts/apexcharts.js#685
  4999. if (w.config.chart.type !== 'scatter' && w.config.chart.type !== 'bubble' && w.globals.dataPoints > 1) {
  5000. annoElArray[i].classList.add('apexcharts-element-hidden');
  5001. }
  5002. }
  5003. w.globals.delayedElements.push({
  5004. el: annoElArray[i],
  5005. index: 0
  5006. });
  5007. }
  5008. // background sizes needs to be calculated after text is drawn, so calling them last
  5009. this.helpers.annotationsBackground();
  5010. }
  5011. }
  5012. }, {
  5013. key: "drawImageAnnos",
  5014. value: function drawImageAnnos() {
  5015. var _this = this;
  5016. var w = this.w;
  5017. w.config.annotations.images.map(function (s, index) {
  5018. _this.addImage(s, index);
  5019. });
  5020. }
  5021. }, {
  5022. key: "drawTextAnnos",
  5023. value: function drawTextAnnos() {
  5024. var _this2 = this;
  5025. var w = this.w;
  5026. w.config.annotations.texts.map(function (t, index) {
  5027. _this2.addText(t, index);
  5028. });
  5029. }
  5030. }, {
  5031. key: "addXaxisAnnotation",
  5032. value: function addXaxisAnnotation(anno, parent, index) {
  5033. this.xAxisAnnotations.addXaxisAnnotation(anno, parent, index);
  5034. }
  5035. }, {
  5036. key: "addYaxisAnnotation",
  5037. value: function addYaxisAnnotation(anno, parent, index) {
  5038. this.yAxisAnnotations.addYaxisAnnotation(anno, parent, index);
  5039. }
  5040. }, {
  5041. key: "addPointAnnotation",
  5042. value: function addPointAnnotation(anno, parent, index) {
  5043. this.pointsAnnotations.addPointAnnotation(anno, parent, index);
  5044. }
  5045. }, {
  5046. key: "addText",
  5047. value: function addText(params, index) {
  5048. var x = params.x,
  5049. y = params.y,
  5050. text = params.text,
  5051. textAnchor = params.textAnchor,
  5052. foreColor = params.foreColor,
  5053. fontSize = params.fontSize,
  5054. fontFamily = params.fontFamily,
  5055. fontWeight = params.fontWeight,
  5056. cssClass = params.cssClass,
  5057. backgroundColor = params.backgroundColor,
  5058. borderWidth = params.borderWidth,
  5059. strokeDashArray = params.strokeDashArray,
  5060. borderRadius = params.borderRadius,
  5061. borderColor = params.borderColor,
  5062. _params$appendTo = params.appendTo,
  5063. appendTo = _params$appendTo === void 0 ? '.apexcharts-svg' : _params$appendTo,
  5064. _params$paddingLeft = params.paddingLeft,
  5065. paddingLeft = _params$paddingLeft === void 0 ? 4 : _params$paddingLeft,
  5066. _params$paddingRight = params.paddingRight,
  5067. paddingRight = _params$paddingRight === void 0 ? 4 : _params$paddingRight,
  5068. _params$paddingBottom = params.paddingBottom,
  5069. paddingBottom = _params$paddingBottom === void 0 ? 2 : _params$paddingBottom,
  5070. _params$paddingTop = params.paddingTop,
  5071. paddingTop = _params$paddingTop === void 0 ? 2 : _params$paddingTop;
  5072. var w = this.w;
  5073. var elText = this.graphics.drawText({
  5074. x: x,
  5075. y: y,
  5076. text: text,
  5077. textAnchor: textAnchor || 'start',
  5078. fontSize: fontSize || '12px',
  5079. fontWeight: fontWeight || 'regular',
  5080. fontFamily: fontFamily || w.config.chart.fontFamily,
  5081. foreColor: foreColor || w.config.chart.foreColor,
  5082. cssClass: 'apexcharts-text ' + cssClass ? cssClass : ''
  5083. });
  5084. var parent = w.globals.dom.baseEl.querySelector(appendTo);
  5085. if (parent) {
  5086. parent.appendChild(elText.node);
  5087. }
  5088. var textRect = elText.bbox();
  5089. if (text) {
  5090. 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);
  5091. parent.insertBefore(elRect.node, elText.node);
  5092. }
  5093. }
  5094. }, {
  5095. key: "addImage",
  5096. value: function addImage(params, index) {
  5097. var w = this.w;
  5098. var path = params.path,
  5099. _params$x = params.x,
  5100. x = _params$x === void 0 ? 0 : _params$x,
  5101. _params$y = params.y,
  5102. y = _params$y === void 0 ? 0 : _params$y,
  5103. _params$width = params.width,
  5104. width = _params$width === void 0 ? 20 : _params$width,
  5105. _params$height = params.height,
  5106. height = _params$height === void 0 ? 20 : _params$height,
  5107. _params$appendTo2 = params.appendTo,
  5108. appendTo = _params$appendTo2 === void 0 ? '.apexcharts-svg' : _params$appendTo2;
  5109. var img = w.globals.dom.Paper.image(path);
  5110. img.size(width, height).move(x, y);
  5111. var parent = w.globals.dom.baseEl.querySelector(appendTo);
  5112. if (parent) {
  5113. parent.appendChild(img.node);
  5114. }
  5115. return img;
  5116. }
  5117. // 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
  5118. }, {
  5119. key: "addXaxisAnnotationExternal",
  5120. value: function addXaxisAnnotationExternal(params, pushToMemory, context) {
  5121. this.addAnnotationExternal({
  5122. params: params,
  5123. pushToMemory: pushToMemory,
  5124. context: context,
  5125. type: 'xaxis',
  5126. contextMethod: context.addXaxisAnnotation
  5127. });
  5128. return context;
  5129. }
  5130. }, {
  5131. key: "addYaxisAnnotationExternal",
  5132. value: function addYaxisAnnotationExternal(params, pushToMemory, context) {
  5133. this.addAnnotationExternal({
  5134. params: params,
  5135. pushToMemory: pushToMemory,
  5136. context: context,
  5137. type: 'yaxis',
  5138. contextMethod: context.addYaxisAnnotation
  5139. });
  5140. return context;
  5141. }
  5142. }, {
  5143. key: "addPointAnnotationExternal",
  5144. value: function addPointAnnotationExternal(params, pushToMemory, context) {
  5145. if (typeof this.invertAxis === 'undefined') {
  5146. this.invertAxis = context.w.globals.isBarHorizontal;
  5147. }
  5148. this.addAnnotationExternal({
  5149. params: params,
  5150. pushToMemory: pushToMemory,
  5151. context: context,
  5152. type: 'point',
  5153. contextMethod: context.addPointAnnotation
  5154. });
  5155. return context;
  5156. }
  5157. }, {
  5158. key: "addAnnotationExternal",
  5159. value: function addAnnotationExternal(_ref) {
  5160. var params = _ref.params,
  5161. pushToMemory = _ref.pushToMemory,
  5162. context = _ref.context,
  5163. type = _ref.type,
  5164. contextMethod = _ref.contextMethod;
  5165. var me = context;
  5166. var w = me.w;
  5167. var parent = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-annotations"));
  5168. var index = parent.childNodes.length + 1;
  5169. var options = new Options();
  5170. var axesAnno = Object.assign({}, type === 'xaxis' ? options.xAxisAnnotation : type === 'yaxis' ? options.yAxisAnnotation : options.pointAnnotation);
  5171. var anno = Utils$1.extend(axesAnno, params);
  5172. switch (type) {
  5173. case 'xaxis':
  5174. this.addXaxisAnnotation(anno, parent, index);
  5175. break;
  5176. case 'yaxis':
  5177. this.addYaxisAnnotation(anno, parent, index);
  5178. break;
  5179. case 'point':
  5180. this.addPointAnnotation(anno, parent, index);
  5181. break;
  5182. }
  5183. // add background
  5184. var axesAnnoLabel = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-annotations .apexcharts-").concat(type, "-annotation-label[rel='").concat(index, "']"));
  5185. var elRect = this.helpers.addBackgroundToAnno(axesAnnoLabel, anno);
  5186. if (elRect) {
  5187. parent.insertBefore(elRect.node, axesAnnoLabel);
  5188. }
  5189. if (pushToMemory) {
  5190. w.globals.memory.methodsToExec.push({
  5191. context: me,
  5192. id: anno.id ? anno.id : Utils$1.randomId(),
  5193. method: contextMethod,
  5194. label: 'addAnnotation',
  5195. params: params
  5196. });
  5197. }
  5198. return context;
  5199. }
  5200. }, {
  5201. key: "clearAnnotations",
  5202. value: function clearAnnotations(ctx) {
  5203. var w = ctx.w;
  5204. var annos = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxis-annotations, .apexcharts-xaxis-annotations, .apexcharts-point-annotations');
  5205. // annotations added externally should be cleared out too
  5206. for (var i = w.globals.memory.methodsToExec.length - 1; i >= 0; i--) {
  5207. if (w.globals.memory.methodsToExec[i].label === 'addText' || w.globals.memory.methodsToExec[i].label === 'addAnnotation') {
  5208. w.globals.memory.methodsToExec.splice(i, 1);
  5209. }
  5210. }
  5211. annos = Utils$1.listToArray(annos);
  5212. // delete the DOM elements
  5213. Array.prototype.forEach.call(annos, function (a) {
  5214. while (a.firstChild) {
  5215. a.removeChild(a.firstChild);
  5216. }
  5217. });
  5218. }
  5219. }, {
  5220. key: "removeAnnotation",
  5221. value: function removeAnnotation(ctx, id) {
  5222. var w = ctx.w;
  5223. var annos = w.globals.dom.baseEl.querySelectorAll(".".concat(id));
  5224. if (annos) {
  5225. w.globals.memory.methodsToExec.map(function (m, i) {
  5226. if (m.id === id) {
  5227. w.globals.memory.methodsToExec.splice(i, 1);
  5228. }
  5229. });
  5230. Array.prototype.forEach.call(annos, function (a) {
  5231. a.parentElement.removeChild(a);
  5232. });
  5233. }
  5234. }
  5235. }]);
  5236. return Annotations;
  5237. }();
  5238. /**
  5239. * ApexCharts Default Class for setting default options for all chart types.
  5240. *
  5241. * @module Defaults
  5242. **/
  5243. var getRangeValues = function getRangeValues(_ref) {
  5244. var _w$config$series$seri;
  5245. var isTimeline = _ref.isTimeline,
  5246. ctx = _ref.ctx,
  5247. seriesIndex = _ref.seriesIndex,
  5248. dataPointIndex = _ref.dataPointIndex,
  5249. y1 = _ref.y1,
  5250. y2 = _ref.y2,
  5251. w = _ref.w;
  5252. var start = w.globals.seriesRangeStart[seriesIndex][dataPointIndex];
  5253. var end = w.globals.seriesRangeEnd[seriesIndex][dataPointIndex];
  5254. var ylabel = w.globals.labels[dataPointIndex];
  5255. var seriesName = w.config.series[seriesIndex].name ? w.config.series[seriesIndex].name : '';
  5256. var yLbFormatter = w.globals.ttKeyFormatter;
  5257. var yLbTitleFormatter = w.config.tooltip.y.title.formatter;
  5258. var opts = {
  5259. w: w,
  5260. seriesIndex: seriesIndex,
  5261. dataPointIndex: dataPointIndex,
  5262. start: start,
  5263. end: end
  5264. };
  5265. if (typeof yLbTitleFormatter === 'function') {
  5266. seriesName = yLbTitleFormatter(seriesName, opts);
  5267. }
  5268. if ((_w$config$series$seri = w.config.series[seriesIndex].data[dataPointIndex]) !== null && _w$config$series$seri !== void 0 && _w$config$series$seri.x) {
  5269. ylabel = w.config.series[seriesIndex].data[dataPointIndex].x;
  5270. }
  5271. if (!isTimeline) {
  5272. if (w.config.xaxis.type === 'datetime') {
  5273. var xFormat = new Formatters(ctx);
  5274. ylabel = xFormat.xLabelFormat(w.globals.ttKeyFormatter, ylabel, ylabel, {
  5275. i: undefined,
  5276. dateFormatter: new DateTime(ctx).formatDate,
  5277. w: w
  5278. });
  5279. }
  5280. }
  5281. if (typeof yLbFormatter === 'function') {
  5282. ylabel = yLbFormatter(ylabel, opts);
  5283. }
  5284. if (Number.isFinite(y1) && Number.isFinite(y2)) {
  5285. start = y1;
  5286. end = y2;
  5287. }
  5288. var startVal = '';
  5289. var endVal = '';
  5290. var color = w.globals.colors[seriesIndex];
  5291. if (w.config.tooltip.x.formatter === undefined) {
  5292. if (w.config.xaxis.type === 'datetime') {
  5293. var datetimeObj = new DateTime(ctx);
  5294. startVal = datetimeObj.formatDate(datetimeObj.getDate(start), w.config.tooltip.x.format);
  5295. endVal = datetimeObj.formatDate(datetimeObj.getDate(end), w.config.tooltip.x.format);
  5296. } else {
  5297. startVal = start;
  5298. endVal = end;
  5299. }
  5300. } else {
  5301. startVal = w.config.tooltip.x.formatter(start);
  5302. endVal = w.config.tooltip.x.formatter(end);
  5303. }
  5304. return {
  5305. start: start,
  5306. end: end,
  5307. startVal: startVal,
  5308. endVal: endVal,
  5309. ylabel: ylabel,
  5310. color: color,
  5311. seriesName: seriesName
  5312. };
  5313. };
  5314. var buildRangeTooltipHTML = function buildRangeTooltipHTML(opts) {
  5315. var color = opts.color,
  5316. seriesName = opts.seriesName,
  5317. ylabel = opts.ylabel,
  5318. start = opts.start,
  5319. end = opts.end,
  5320. seriesIndex = opts.seriesIndex,
  5321. dataPointIndex = opts.dataPointIndex;
  5322. var formatter = opts.ctx.tooltip.tooltipLabels.getFormatters(seriesIndex);
  5323. start = formatter.yLbFormatter(start);
  5324. end = formatter.yLbFormatter(end);
  5325. var val = formatter.yLbFormatter(opts.w.globals.series[seriesIndex][dataPointIndex]);
  5326. var valueHTML = '';
  5327. 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>");
  5328. if (opts.w.globals.comboCharts) {
  5329. if (opts.w.config.series[seriesIndex].type === 'rangeArea' || opts.w.config.series[seriesIndex].type === 'rangeBar') {
  5330. valueHTML = rangeValues;
  5331. } else {
  5332. valueHTML = "<span>".concat(val, "</span>");
  5333. }
  5334. } else {
  5335. valueHTML = rangeValues;
  5336. }
  5337. 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>';
  5338. };
  5339. var Defaults = /*#__PURE__*/function () {
  5340. function Defaults(opts) {
  5341. _classCallCheck(this, Defaults);
  5342. this.opts = opts;
  5343. }
  5344. _createClass(Defaults, [{
  5345. key: "hideYAxis",
  5346. value: function hideYAxis() {
  5347. this.opts.yaxis[0].show = false;
  5348. this.opts.yaxis[0].title.text = '';
  5349. this.opts.yaxis[0].axisBorder.show = false;
  5350. this.opts.yaxis[0].axisTicks.show = false;
  5351. this.opts.yaxis[0].floating = true;
  5352. }
  5353. }, {
  5354. key: "line",
  5355. value: function line() {
  5356. return {
  5357. chart: {
  5358. animations: {
  5359. easing: 'swing'
  5360. }
  5361. },
  5362. dataLabels: {
  5363. enabled: false
  5364. },
  5365. stroke: {
  5366. width: 5,
  5367. curve: 'straight'
  5368. },
  5369. markers: {
  5370. size: 0,
  5371. hover: {
  5372. sizeOffset: 6
  5373. }
  5374. },
  5375. xaxis: {
  5376. crosshairs: {
  5377. width: 1
  5378. }
  5379. }
  5380. };
  5381. }
  5382. }, {
  5383. key: "sparkline",
  5384. value: function sparkline(defaults) {
  5385. this.hideYAxis();
  5386. var ret = {
  5387. grid: {
  5388. show: false,
  5389. padding: {
  5390. left: 0,
  5391. right: 0,
  5392. top: 0,
  5393. bottom: 0
  5394. }
  5395. },
  5396. legend: {
  5397. show: false
  5398. },
  5399. xaxis: {
  5400. labels: {
  5401. show: false
  5402. },
  5403. tooltip: {
  5404. enabled: false
  5405. },
  5406. axisBorder: {
  5407. show: false
  5408. },
  5409. axisTicks: {
  5410. show: false
  5411. }
  5412. },
  5413. chart: {
  5414. toolbar: {
  5415. show: false
  5416. },
  5417. zoom: {
  5418. enabled: false
  5419. }
  5420. },
  5421. dataLabels: {
  5422. enabled: false
  5423. }
  5424. };
  5425. return Utils$1.extend(defaults, ret);
  5426. }
  5427. }, {
  5428. key: "slope",
  5429. value: function slope() {
  5430. this.hideYAxis();
  5431. return {
  5432. chart: {
  5433. toolbar: {
  5434. show: false
  5435. },
  5436. zoom: {
  5437. enabled: false
  5438. }
  5439. },
  5440. dataLabels: {
  5441. enabled: true,
  5442. formatter: function formatter(val, opts) {
  5443. var seriesName = opts.w.config.series[opts.seriesIndex].name;
  5444. return val !== null ? seriesName + ': ' + val : '';
  5445. },
  5446. background: {
  5447. enabled: false
  5448. },
  5449. offsetX: -5
  5450. },
  5451. grid: {
  5452. xaxis: {
  5453. lines: {
  5454. show: true
  5455. }
  5456. },
  5457. yaxis: {
  5458. lines: {
  5459. show: false
  5460. }
  5461. }
  5462. },
  5463. xaxis: {
  5464. position: 'top',
  5465. labels: {
  5466. style: {
  5467. fontSize: 14,
  5468. fontWeight: 900
  5469. }
  5470. },
  5471. tooltip: {
  5472. enabled: false
  5473. },
  5474. crosshairs: {
  5475. show: false
  5476. }
  5477. },
  5478. markers: {
  5479. size: 8,
  5480. hover: {
  5481. sizeOffset: 1
  5482. }
  5483. },
  5484. legend: {
  5485. show: false
  5486. },
  5487. tooltip: {
  5488. shared: false,
  5489. intersect: true,
  5490. followCursor: true
  5491. },
  5492. stroke: {
  5493. width: 5,
  5494. curve: 'straight'
  5495. }
  5496. };
  5497. }
  5498. }, {
  5499. key: "bar",
  5500. value: function bar() {
  5501. return {
  5502. chart: {
  5503. stacked: false,
  5504. animations: {
  5505. easing: 'swing'
  5506. }
  5507. },
  5508. plotOptions: {
  5509. bar: {
  5510. dataLabels: {
  5511. position: 'center'
  5512. }
  5513. }
  5514. },
  5515. dataLabels: {
  5516. style: {
  5517. colors: ['#fff']
  5518. },
  5519. background: {
  5520. enabled: false
  5521. }
  5522. },
  5523. stroke: {
  5524. width: 0,
  5525. lineCap: 'round'
  5526. },
  5527. fill: {
  5528. opacity: 0.85
  5529. },
  5530. legend: {
  5531. markers: {
  5532. shape: 'square'
  5533. }
  5534. },
  5535. tooltip: {
  5536. shared: false,
  5537. intersect: true
  5538. },
  5539. xaxis: {
  5540. tooltip: {
  5541. enabled: false
  5542. },
  5543. tickPlacement: 'between',
  5544. crosshairs: {
  5545. width: 'barWidth',
  5546. position: 'back',
  5547. fill: {
  5548. type: 'gradient'
  5549. },
  5550. dropShadow: {
  5551. enabled: false
  5552. },
  5553. stroke: {
  5554. width: 0
  5555. }
  5556. }
  5557. }
  5558. };
  5559. }
  5560. }, {
  5561. key: "funnel",
  5562. value: function funnel() {
  5563. this.hideYAxis();
  5564. return _objectSpread2(_objectSpread2({}, this.bar()), {}, {
  5565. chart: {
  5566. animations: {
  5567. easing: 'linear',
  5568. speed: 800,
  5569. animateGradually: {
  5570. enabled: false
  5571. }
  5572. }
  5573. },
  5574. plotOptions: {
  5575. bar: {
  5576. horizontal: true,
  5577. borderRadiusApplication: 'around',
  5578. borderRadius: 0,
  5579. dataLabels: {
  5580. position: 'center'
  5581. }
  5582. }
  5583. },
  5584. grid: {
  5585. show: false,
  5586. padding: {
  5587. left: 0,
  5588. right: 0
  5589. }
  5590. },
  5591. xaxis: {
  5592. labels: {
  5593. show: false
  5594. },
  5595. tooltip: {
  5596. enabled: false
  5597. },
  5598. axisBorder: {
  5599. show: false
  5600. },
  5601. axisTicks: {
  5602. show: false
  5603. }
  5604. }
  5605. });
  5606. }
  5607. }, {
  5608. key: "candlestick",
  5609. value: function candlestick() {
  5610. var _this = this;
  5611. return {
  5612. stroke: {
  5613. width: 1,
  5614. colors: ['#333']
  5615. },
  5616. fill: {
  5617. opacity: 1
  5618. },
  5619. dataLabels: {
  5620. enabled: false
  5621. },
  5622. tooltip: {
  5623. shared: true,
  5624. custom: function custom(_ref2) {
  5625. var seriesIndex = _ref2.seriesIndex,
  5626. dataPointIndex = _ref2.dataPointIndex,
  5627. w = _ref2.w;
  5628. return _this._getBoxTooltip(w, seriesIndex, dataPointIndex, ['Open', 'High', '', 'Low', 'Close'], 'candlestick');
  5629. }
  5630. },
  5631. states: {
  5632. active: {
  5633. filter: {
  5634. type: 'none'
  5635. }
  5636. }
  5637. },
  5638. xaxis: {
  5639. crosshairs: {
  5640. width: 1
  5641. }
  5642. }
  5643. };
  5644. }
  5645. }, {
  5646. key: "boxPlot",
  5647. value: function boxPlot() {
  5648. var _this2 = this;
  5649. return {
  5650. chart: {
  5651. animations: {
  5652. dynamicAnimation: {
  5653. enabled: false
  5654. }
  5655. }
  5656. },
  5657. stroke: {
  5658. width: 1,
  5659. colors: ['#24292e']
  5660. },
  5661. dataLabels: {
  5662. enabled: false
  5663. },
  5664. tooltip: {
  5665. shared: true,
  5666. custom: function custom(_ref3) {
  5667. var seriesIndex = _ref3.seriesIndex,
  5668. dataPointIndex = _ref3.dataPointIndex,
  5669. w = _ref3.w;
  5670. return _this2._getBoxTooltip(w, seriesIndex, dataPointIndex, ['Minimum', 'Q1', 'Median', 'Q3', 'Maximum'], 'boxPlot');
  5671. }
  5672. },
  5673. markers: {
  5674. size: 7,
  5675. strokeWidth: 1,
  5676. strokeColors: '#111'
  5677. },
  5678. xaxis: {
  5679. crosshairs: {
  5680. width: 1
  5681. }
  5682. }
  5683. };
  5684. }
  5685. }, {
  5686. key: "rangeBar",
  5687. value: function rangeBar() {
  5688. var handleTimelineTooltip = function handleTimelineTooltip(opts) {
  5689. var _getRangeValues = getRangeValues(_objectSpread2(_objectSpread2({}, opts), {}, {
  5690. isTimeline: true
  5691. })),
  5692. color = _getRangeValues.color,
  5693. seriesName = _getRangeValues.seriesName,
  5694. ylabel = _getRangeValues.ylabel,
  5695. startVal = _getRangeValues.startVal,
  5696. endVal = _getRangeValues.endVal;
  5697. return buildRangeTooltipHTML(_objectSpread2(_objectSpread2({}, opts), {}, {
  5698. color: color,
  5699. seriesName: seriesName,
  5700. ylabel: ylabel,
  5701. start: startVal,
  5702. end: endVal
  5703. }));
  5704. };
  5705. var handleRangeColumnTooltip = function handleRangeColumnTooltip(opts) {
  5706. var _getRangeValues2 = getRangeValues(opts),
  5707. color = _getRangeValues2.color,
  5708. seriesName = _getRangeValues2.seriesName,
  5709. ylabel = _getRangeValues2.ylabel,
  5710. start = _getRangeValues2.start,
  5711. end = _getRangeValues2.end;
  5712. return buildRangeTooltipHTML(_objectSpread2(_objectSpread2({}, opts), {}, {
  5713. color: color,
  5714. seriesName: seriesName,
  5715. ylabel: ylabel,
  5716. start: start,
  5717. end: end
  5718. }));
  5719. };
  5720. return {
  5721. chart: {
  5722. animations: {
  5723. animateGradually: false
  5724. }
  5725. },
  5726. stroke: {
  5727. width: 0,
  5728. lineCap: 'square'
  5729. },
  5730. plotOptions: {
  5731. bar: {
  5732. borderRadius: 0,
  5733. dataLabels: {
  5734. position: 'center'
  5735. }
  5736. }
  5737. },
  5738. dataLabels: {
  5739. enabled: false,
  5740. formatter: function formatter(val, _ref4) {
  5741. _ref4.ctx;
  5742. var seriesIndex = _ref4.seriesIndex,
  5743. dataPointIndex = _ref4.dataPointIndex,
  5744. w = _ref4.w;
  5745. var getVal = function getVal() {
  5746. var start = w.globals.seriesRangeStart[seriesIndex][dataPointIndex];
  5747. var end = w.globals.seriesRangeEnd[seriesIndex][dataPointIndex];
  5748. return end - start;
  5749. };
  5750. if (w.globals.comboCharts) {
  5751. if (w.config.series[seriesIndex].type === 'rangeBar' || w.config.series[seriesIndex].type === 'rangeArea') {
  5752. return getVal();
  5753. } else {
  5754. return val;
  5755. }
  5756. } else {
  5757. return getVal();
  5758. }
  5759. },
  5760. background: {
  5761. enabled: false
  5762. },
  5763. style: {
  5764. colors: ['#fff']
  5765. }
  5766. },
  5767. markers: {
  5768. size: 10
  5769. },
  5770. tooltip: {
  5771. shared: false,
  5772. followCursor: true,
  5773. custom: function custom(opts) {
  5774. if (opts.w.config.plotOptions && opts.w.config.plotOptions.bar && opts.w.config.plotOptions.bar.horizontal) {
  5775. return handleTimelineTooltip(opts);
  5776. } else {
  5777. return handleRangeColumnTooltip(opts);
  5778. }
  5779. }
  5780. },
  5781. xaxis: {
  5782. tickPlacement: 'between',
  5783. tooltip: {
  5784. enabled: false
  5785. },
  5786. crosshairs: {
  5787. stroke: {
  5788. width: 0
  5789. }
  5790. }
  5791. }
  5792. };
  5793. }
  5794. }, {
  5795. key: "dumbbell",
  5796. value: function dumbbell(opts) {
  5797. var _opts$plotOptions$bar, _opts$plotOptions$bar2;
  5798. if (!((_opts$plotOptions$bar = opts.plotOptions.bar) !== null && _opts$plotOptions$bar !== void 0 && _opts$plotOptions$bar.barHeight)) {
  5799. opts.plotOptions.bar.barHeight = 2;
  5800. }
  5801. if (!((_opts$plotOptions$bar2 = opts.plotOptions.bar) !== null && _opts$plotOptions$bar2 !== void 0 && _opts$plotOptions$bar2.columnWidth)) {
  5802. opts.plotOptions.bar.columnWidth = 2;
  5803. }
  5804. return opts;
  5805. }
  5806. }, {
  5807. key: "area",
  5808. value: function area() {
  5809. return {
  5810. stroke: {
  5811. width: 4,
  5812. fill: {
  5813. type: 'solid',
  5814. gradient: {
  5815. inverseColors: false,
  5816. shade: 'light',
  5817. type: 'vertical',
  5818. opacityFrom: 0.65,
  5819. opacityTo: 0.5,
  5820. stops: [0, 100, 100]
  5821. }
  5822. }
  5823. },
  5824. fill: {
  5825. type: 'gradient',
  5826. gradient: {
  5827. inverseColors: false,
  5828. shade: 'light',
  5829. type: 'vertical',
  5830. opacityFrom: 0.65,
  5831. opacityTo: 0.5,
  5832. stops: [0, 100, 100]
  5833. }
  5834. },
  5835. markers: {
  5836. size: 0,
  5837. hover: {
  5838. sizeOffset: 6
  5839. }
  5840. },
  5841. tooltip: {
  5842. followCursor: false
  5843. }
  5844. };
  5845. }
  5846. }, {
  5847. key: "rangeArea",
  5848. value: function rangeArea() {
  5849. var handleRangeAreaTooltip = function handleRangeAreaTooltip(opts) {
  5850. var _getRangeValues3 = getRangeValues(opts),
  5851. color = _getRangeValues3.color,
  5852. seriesName = _getRangeValues3.seriesName,
  5853. ylabel = _getRangeValues3.ylabel,
  5854. start = _getRangeValues3.start,
  5855. end = _getRangeValues3.end;
  5856. return buildRangeTooltipHTML(_objectSpread2(_objectSpread2({}, opts), {}, {
  5857. color: color,
  5858. seriesName: seriesName,
  5859. ylabel: ylabel,
  5860. start: start,
  5861. end: end
  5862. }));
  5863. };
  5864. return {
  5865. stroke: {
  5866. curve: 'straight',
  5867. width: 0
  5868. },
  5869. fill: {
  5870. type: 'solid',
  5871. opacity: 0.6
  5872. },
  5873. markers: {
  5874. size: 0
  5875. },
  5876. states: {
  5877. hover: {
  5878. filter: {
  5879. type: 'none'
  5880. }
  5881. },
  5882. active: {
  5883. filter: {
  5884. type: 'none'
  5885. }
  5886. }
  5887. },
  5888. tooltip: {
  5889. intersect: false,
  5890. shared: true,
  5891. followCursor: true,
  5892. custom: function custom(opts) {
  5893. return handleRangeAreaTooltip(opts);
  5894. }
  5895. }
  5896. };
  5897. }
  5898. }, {
  5899. key: "brush",
  5900. value: function brush(defaults) {
  5901. var ret = {
  5902. chart: {
  5903. toolbar: {
  5904. autoSelected: 'selection',
  5905. show: false
  5906. },
  5907. zoom: {
  5908. enabled: false
  5909. }
  5910. },
  5911. dataLabels: {
  5912. enabled: false
  5913. },
  5914. stroke: {
  5915. width: 1
  5916. },
  5917. tooltip: {
  5918. enabled: false
  5919. },
  5920. xaxis: {
  5921. tooltip: {
  5922. enabled: false
  5923. }
  5924. }
  5925. };
  5926. return Utils$1.extend(defaults, ret);
  5927. }
  5928. }, {
  5929. key: "stacked100",
  5930. value: function stacked100(opts) {
  5931. opts.dataLabels = opts.dataLabels || {};
  5932. opts.dataLabels.formatter = opts.dataLabels.formatter || undefined;
  5933. var existingDataLabelFormatter = opts.dataLabels.formatter;
  5934. opts.yaxis.forEach(function (yaxe, index) {
  5935. opts.yaxis[index].min = 0;
  5936. opts.yaxis[index].max = 100;
  5937. });
  5938. var isBar = opts.chart.type === 'bar';
  5939. if (isBar) {
  5940. opts.dataLabels.formatter = existingDataLabelFormatter || function (val) {
  5941. if (typeof val === 'number') {
  5942. return val ? val.toFixed(0) + '%' : val;
  5943. }
  5944. return val;
  5945. };
  5946. }
  5947. return opts;
  5948. }
  5949. }, {
  5950. key: "stackedBars",
  5951. value: function stackedBars() {
  5952. var barDefaults = this.bar();
  5953. return _objectSpread2(_objectSpread2({}, barDefaults), {}, {
  5954. plotOptions: _objectSpread2(_objectSpread2({}, barDefaults.plotOptions), {}, {
  5955. bar: _objectSpread2(_objectSpread2({}, barDefaults.plotOptions.bar), {}, {
  5956. borderRadiusApplication: 'end',
  5957. borderRadiusWhenStacked: 'last'
  5958. })
  5959. })
  5960. });
  5961. }
  5962. // 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
  5963. }, {
  5964. key: "convertCatToNumeric",
  5965. value: function convertCatToNumeric(opts) {
  5966. opts.xaxis.convertedCatToNumeric = true;
  5967. return opts;
  5968. }
  5969. }, {
  5970. key: "convertCatToNumericXaxis",
  5971. value: function convertCatToNumericXaxis(opts, ctx, cats) {
  5972. opts.xaxis.type = 'numeric';
  5973. opts.xaxis.labels = opts.xaxis.labels || {};
  5974. opts.xaxis.labels.formatter = opts.xaxis.labels.formatter || function (val) {
  5975. return Utils$1.isNumber(val) ? Math.floor(val) : val;
  5976. };
  5977. var defaultFormatter = opts.xaxis.labels.formatter;
  5978. var labels = opts.xaxis.categories && opts.xaxis.categories.length ? opts.xaxis.categories : opts.labels;
  5979. if (cats && cats.length) {
  5980. labels = cats.map(function (c) {
  5981. return Array.isArray(c) ? c : String(c);
  5982. });
  5983. }
  5984. if (labels && labels.length) {
  5985. opts.xaxis.labels.formatter = function (val) {
  5986. return Utils$1.isNumber(val) ? defaultFormatter(labels[Math.floor(val) - 1]) : defaultFormatter(val);
  5987. };
  5988. }
  5989. opts.xaxis.categories = [];
  5990. opts.labels = [];
  5991. opts.xaxis.tickAmount = opts.xaxis.tickAmount || 'dataPoints';
  5992. return opts;
  5993. }
  5994. }, {
  5995. key: "bubble",
  5996. value: function bubble() {
  5997. return {
  5998. dataLabels: {
  5999. style: {
  6000. colors: ['#fff']
  6001. }
  6002. },
  6003. tooltip: {
  6004. shared: false,
  6005. intersect: true
  6006. },
  6007. xaxis: {
  6008. crosshairs: {
  6009. width: 0
  6010. }
  6011. },
  6012. fill: {
  6013. type: 'solid',
  6014. gradient: {
  6015. shade: 'light',
  6016. inverse: true,
  6017. shadeIntensity: 0.55,
  6018. opacityFrom: 0.4,
  6019. opacityTo: 0.8
  6020. }
  6021. }
  6022. };
  6023. }
  6024. }, {
  6025. key: "scatter",
  6026. value: function scatter() {
  6027. return {
  6028. dataLabels: {
  6029. enabled: false
  6030. },
  6031. tooltip: {
  6032. shared: false,
  6033. intersect: true
  6034. },
  6035. markers: {
  6036. size: 6,
  6037. strokeWidth: 1,
  6038. hover: {
  6039. sizeOffset: 2
  6040. }
  6041. }
  6042. };
  6043. }
  6044. }, {
  6045. key: "heatmap",
  6046. value: function heatmap() {
  6047. return {
  6048. chart: {
  6049. stacked: false
  6050. },
  6051. fill: {
  6052. opacity: 1
  6053. },
  6054. dataLabels: {
  6055. style: {
  6056. colors: ['#fff']
  6057. }
  6058. },
  6059. stroke: {
  6060. colors: ['#fff']
  6061. },
  6062. tooltip: {
  6063. followCursor: true,
  6064. marker: {
  6065. show: false
  6066. },
  6067. x: {
  6068. show: false
  6069. }
  6070. },
  6071. legend: {
  6072. position: 'top',
  6073. markers: {
  6074. shape: 'square'
  6075. }
  6076. },
  6077. grid: {
  6078. padding: {
  6079. right: 20
  6080. }
  6081. }
  6082. };
  6083. }
  6084. }, {
  6085. key: "treemap",
  6086. value: function treemap() {
  6087. return {
  6088. chart: {
  6089. zoom: {
  6090. enabled: false
  6091. }
  6092. },
  6093. dataLabels: {
  6094. style: {
  6095. fontSize: 14,
  6096. fontWeight: 600,
  6097. colors: ['#fff']
  6098. }
  6099. },
  6100. stroke: {
  6101. show: true,
  6102. width: 2,
  6103. colors: ['#fff']
  6104. },
  6105. legend: {
  6106. show: false
  6107. },
  6108. fill: {
  6109. opacity: 1,
  6110. gradient: {
  6111. stops: [0, 100]
  6112. }
  6113. },
  6114. tooltip: {
  6115. followCursor: true,
  6116. x: {
  6117. show: false
  6118. }
  6119. },
  6120. grid: {
  6121. padding: {
  6122. left: 0,
  6123. right: 0
  6124. }
  6125. },
  6126. xaxis: {
  6127. crosshairs: {
  6128. show: false
  6129. },
  6130. tooltip: {
  6131. enabled: false
  6132. }
  6133. }
  6134. };
  6135. }
  6136. }, {
  6137. key: "pie",
  6138. value: function pie() {
  6139. return {
  6140. chart: {
  6141. toolbar: {
  6142. show: false
  6143. }
  6144. },
  6145. plotOptions: {
  6146. pie: {
  6147. donut: {
  6148. labels: {
  6149. show: false
  6150. }
  6151. }
  6152. }
  6153. },
  6154. dataLabels: {
  6155. formatter: function formatter(val) {
  6156. return val.toFixed(1) + '%';
  6157. },
  6158. style: {
  6159. colors: ['#fff']
  6160. },
  6161. background: {
  6162. enabled: false
  6163. },
  6164. dropShadow: {
  6165. enabled: true
  6166. }
  6167. },
  6168. stroke: {
  6169. colors: ['#fff']
  6170. },
  6171. fill: {
  6172. opacity: 1,
  6173. gradient: {
  6174. shade: 'light',
  6175. stops: [0, 100]
  6176. }
  6177. },
  6178. tooltip: {
  6179. theme: 'dark',
  6180. fillSeriesColor: true
  6181. },
  6182. legend: {
  6183. position: 'right'
  6184. },
  6185. grid: {
  6186. padding: {
  6187. left: 0,
  6188. right: 0,
  6189. top: 0,
  6190. bottom: 0
  6191. }
  6192. }
  6193. };
  6194. }
  6195. }, {
  6196. key: "donut",
  6197. value: function donut() {
  6198. return {
  6199. chart: {
  6200. toolbar: {
  6201. show: false
  6202. }
  6203. },
  6204. dataLabels: {
  6205. formatter: function formatter(val) {
  6206. return val.toFixed(1) + '%';
  6207. },
  6208. style: {
  6209. colors: ['#fff']
  6210. },
  6211. background: {
  6212. enabled: false
  6213. },
  6214. dropShadow: {
  6215. enabled: true
  6216. }
  6217. },
  6218. stroke: {
  6219. colors: ['#fff']
  6220. },
  6221. fill: {
  6222. opacity: 1,
  6223. gradient: {
  6224. shade: 'light',
  6225. shadeIntensity: 0.35,
  6226. stops: [80, 100],
  6227. opacityFrom: 1,
  6228. opacityTo: 1
  6229. }
  6230. },
  6231. tooltip: {
  6232. theme: 'dark',
  6233. fillSeriesColor: true
  6234. },
  6235. legend: {
  6236. position: 'right'
  6237. },
  6238. grid: {
  6239. padding: {
  6240. left: 0,
  6241. right: 0,
  6242. top: 0,
  6243. bottom: 0
  6244. }
  6245. }
  6246. };
  6247. }
  6248. }, {
  6249. key: "polarArea",
  6250. value: function polarArea() {
  6251. return {
  6252. chart: {
  6253. toolbar: {
  6254. show: false
  6255. }
  6256. },
  6257. dataLabels: {
  6258. formatter: function formatter(val) {
  6259. return val.toFixed(1) + '%';
  6260. },
  6261. enabled: false
  6262. },
  6263. stroke: {
  6264. show: true,
  6265. width: 2
  6266. },
  6267. fill: {
  6268. opacity: 0.7
  6269. },
  6270. tooltip: {
  6271. theme: 'dark',
  6272. fillSeriesColor: true
  6273. },
  6274. legend: {
  6275. position: 'right'
  6276. },
  6277. grid: {
  6278. padding: {
  6279. left: 0,
  6280. right: 0,
  6281. top: 0,
  6282. bottom: 0
  6283. }
  6284. }
  6285. };
  6286. }
  6287. }, {
  6288. key: "radar",
  6289. value: function radar() {
  6290. this.opts.yaxis[0].labels.offsetY = this.opts.yaxis[0].labels.offsetY ? this.opts.yaxis[0].labels.offsetY : 6;
  6291. return {
  6292. dataLabels: {
  6293. enabled: false,
  6294. style: {
  6295. fontSize: '11px'
  6296. }
  6297. },
  6298. stroke: {
  6299. width: 2
  6300. },
  6301. markers: {
  6302. size: 5,
  6303. strokeWidth: 1,
  6304. strokeOpacity: 1
  6305. },
  6306. fill: {
  6307. opacity: 0.2
  6308. },
  6309. tooltip: {
  6310. shared: false,
  6311. intersect: true,
  6312. followCursor: true
  6313. },
  6314. grid: {
  6315. show: false,
  6316. padding: {
  6317. left: 0,
  6318. right: 0,
  6319. top: 0,
  6320. bottom: 0
  6321. }
  6322. },
  6323. xaxis: {
  6324. labels: {
  6325. formatter: function formatter(val) {
  6326. return val;
  6327. },
  6328. style: {
  6329. colors: ['#a8a8a8'],
  6330. fontSize: '11px'
  6331. }
  6332. },
  6333. tooltip: {
  6334. enabled: false
  6335. },
  6336. crosshairs: {
  6337. show: false
  6338. }
  6339. }
  6340. };
  6341. }
  6342. }, {
  6343. key: "radialBar",
  6344. value: function radialBar() {
  6345. return {
  6346. chart: {
  6347. animations: {
  6348. dynamicAnimation: {
  6349. enabled: true,
  6350. speed: 800
  6351. }
  6352. },
  6353. toolbar: {
  6354. show: false
  6355. }
  6356. },
  6357. fill: {
  6358. gradient: {
  6359. shade: 'dark',
  6360. shadeIntensity: 0.4,
  6361. inverseColors: false,
  6362. type: 'diagonal2',
  6363. opacityFrom: 1,
  6364. opacityTo: 1,
  6365. stops: [70, 98, 100]
  6366. }
  6367. },
  6368. legend: {
  6369. show: false,
  6370. position: 'right'
  6371. },
  6372. tooltip: {
  6373. enabled: false,
  6374. fillSeriesColor: true
  6375. },
  6376. grid: {
  6377. padding: {
  6378. left: 0,
  6379. right: 0,
  6380. top: 0,
  6381. bottom: 0
  6382. }
  6383. }
  6384. };
  6385. }
  6386. }, {
  6387. key: "_getBoxTooltip",
  6388. value: function _getBoxTooltip(w, seriesIndex, dataPointIndex, labels, chartType) {
  6389. var o = w.globals.seriesCandleO[seriesIndex][dataPointIndex];
  6390. var h = w.globals.seriesCandleH[seriesIndex][dataPointIndex];
  6391. var m = w.globals.seriesCandleM[seriesIndex][dataPointIndex];
  6392. var l = w.globals.seriesCandleL[seriesIndex][dataPointIndex];
  6393. var c = w.globals.seriesCandleC[seriesIndex][dataPointIndex];
  6394. if (w.config.series[seriesIndex].type && w.config.series[seriesIndex].type !== chartType) {
  6395. 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>");
  6396. } else {
  6397. 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>';
  6398. }
  6399. }
  6400. }]);
  6401. return Defaults;
  6402. }();
  6403. /**
  6404. * ApexCharts Config Class for extending user options with pre-defined ApexCharts config.
  6405. *
  6406. * @module Config
  6407. **/
  6408. var Config = /*#__PURE__*/function () {
  6409. function Config(opts) {
  6410. _classCallCheck(this, Config);
  6411. this.opts = opts;
  6412. }
  6413. _createClass(Config, [{
  6414. key: "init",
  6415. value: function init(_ref) {
  6416. var responsiveOverride = _ref.responsiveOverride;
  6417. var opts = this.opts;
  6418. var options = new Options();
  6419. var defaults = new Defaults(opts);
  6420. this.chartType = opts.chart.type;
  6421. opts = this.extendYAxis(opts);
  6422. opts = this.extendAnnotations(opts);
  6423. var config = options.init();
  6424. var newDefaults = {};
  6425. if (opts && _typeof(opts) === 'object') {
  6426. 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;
  6427. var chartDefaults = {};
  6428. var chartTypes = ['line', 'area', 'bar', 'candlestick', 'boxPlot', 'rangeBar', 'rangeArea', 'bubble', 'scatter', 'heatmap', 'treemap', 'pie', 'polarArea', 'donut', 'radar', 'radialBar'];
  6429. if (chartTypes.indexOf(opts.chart.type) !== -1) {
  6430. chartDefaults = defaults[opts.chart.type]();
  6431. } else {
  6432. chartDefaults = defaults.line();
  6433. }
  6434. 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) {
  6435. chartDefaults = defaults.funnel();
  6436. }
  6437. if (opts.chart.stacked && opts.chart.type === 'bar') {
  6438. chartDefaults = defaults.stackedBars();
  6439. }
  6440. if ((_opts$chart$brush = opts.chart.brush) !== null && _opts$chart$brush !== void 0 && _opts$chart$brush.enabled) {
  6441. chartDefaults = defaults.brush(chartDefaults);
  6442. }
  6443. 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) {
  6444. chartDefaults = defaults.slope();
  6445. }
  6446. if (opts.chart.stacked && opts.chart.stackType === '100%') {
  6447. opts = defaults.stacked100(opts);
  6448. }
  6449. 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) {
  6450. opts = defaults.dumbbell(opts);
  6451. }
  6452. // If user has specified a dark theme, make the tooltip dark too
  6453. this.checkForDarkTheme(window.Apex); // check global window Apex options
  6454. this.checkForDarkTheme(opts); // check locally passed options
  6455. opts.xaxis = opts.xaxis || window.Apex.xaxis || {};
  6456. // an important boolean needs to be set here
  6457. // otherwise all the charts will have this flag set to true window.Apex.xaxis is set globally
  6458. if (!responsiveOverride) {
  6459. opts.xaxis.convertedCatToNumeric = false;
  6460. }
  6461. opts = this.checkForCatToNumericXAxis(this.chartType, chartDefaults, opts);
  6462. 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) {
  6463. chartDefaults = defaults.sparkline(chartDefaults);
  6464. }
  6465. newDefaults = Utils$1.extend(config, chartDefaults);
  6466. }
  6467. // config should cascade in this fashion
  6468. // default-config < global-apex-variable-config < user-defined-config
  6469. // get GLOBALLY defined options and merge with the default config
  6470. var mergedWithDefaultConfig = Utils$1.extend(newDefaults, window.Apex);
  6471. // get the merged config and extend with user defined config
  6472. config = Utils$1.extend(mergedWithDefaultConfig, opts);
  6473. // some features are not supported. those mismatches should be handled
  6474. config = this.handleUserInputErrors(config);
  6475. return config;
  6476. }
  6477. }, {
  6478. key: "checkForCatToNumericXAxis",
  6479. value: function checkForCatToNumericXAxis(chartType, chartDefaults, opts) {
  6480. var _opts$plotOptions4, _opts$plotOptions4$ba;
  6481. var defaults = new Defaults(opts);
  6482. 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);
  6483. var unsupportedZoom = chartType === 'pie' || chartType === 'polarArea' || chartType === 'donut' || chartType === 'radar' || chartType === 'radialBar' || chartType === 'heatmap';
  6484. var notNumericXAxis = opts.xaxis.type !== 'datetime' && opts.xaxis.type !== 'numeric';
  6485. var tickPlacement = opts.xaxis.tickPlacement ? opts.xaxis.tickPlacement : chartDefaults.xaxis && chartDefaults.xaxis.tickPlacement;
  6486. if (!isBarHorizontal && !unsupportedZoom && notNumericXAxis && tickPlacement !== 'between') {
  6487. opts = defaults.convertCatToNumeric(opts);
  6488. }
  6489. return opts;
  6490. }
  6491. }, {
  6492. key: "extendYAxis",
  6493. value: function extendYAxis(opts, w) {
  6494. var options = new Options();
  6495. if (typeof opts.yaxis === 'undefined' || !opts.yaxis || Array.isArray(opts.yaxis) && opts.yaxis.length === 0) {
  6496. opts.yaxis = {};
  6497. }
  6498. // extend global yaxis config (only if object is provided / not an array)
  6499. if (opts.yaxis.constructor !== Array && window.Apex.yaxis && window.Apex.yaxis.constructor !== Array) {
  6500. opts.yaxis = Utils$1.extend(opts.yaxis, window.Apex.yaxis);
  6501. }
  6502. // as we can't extend nested object's array with extend, we need to do it first
  6503. // user can provide either an array or object in yaxis config
  6504. if (opts.yaxis.constructor !== Array) {
  6505. // convert the yaxis to array if user supplied object
  6506. opts.yaxis = [Utils$1.extend(options.yAxis, opts.yaxis)];
  6507. } else {
  6508. opts.yaxis = Utils$1.extendArray(opts.yaxis, options.yAxis);
  6509. }
  6510. var isLogY = false;
  6511. opts.yaxis.forEach(function (y) {
  6512. if (y.logarithmic) {
  6513. isLogY = true;
  6514. }
  6515. });
  6516. var series = opts.series;
  6517. if (w && !series) {
  6518. series = w.config.series;
  6519. }
  6520. // A logarithmic chart works correctly when each series has a corresponding y-axis
  6521. // If this is not the case, we manually create yaxis for multi-series log chart
  6522. if (isLogY && series.length !== opts.yaxis.length && series.length) {
  6523. opts.yaxis = series.map(function (s, i) {
  6524. if (!s.name) {
  6525. series[i].name = "series-".concat(i + 1);
  6526. }
  6527. if (opts.yaxis[i]) {
  6528. opts.yaxis[i].seriesName = series[i].name;
  6529. return opts.yaxis[i];
  6530. } else {
  6531. var newYaxis = Utils$1.extend(options.yAxis, opts.yaxis[0]);
  6532. newYaxis.show = false;
  6533. return newYaxis;
  6534. }
  6535. });
  6536. }
  6537. if (isLogY && series.length > 1 && series.length !== opts.yaxis.length) {
  6538. console.warn('A multi-series logarithmic chart should have equal number of series and y-axes');
  6539. }
  6540. return opts;
  6541. }
  6542. // annotations also accepts array, so we need to extend them manually
  6543. }, {
  6544. key: "extendAnnotations",
  6545. value: function extendAnnotations(opts) {
  6546. if (typeof opts.annotations === 'undefined') {
  6547. opts.annotations = {};
  6548. opts.annotations.yaxis = [];
  6549. opts.annotations.xaxis = [];
  6550. opts.annotations.points = [];
  6551. }
  6552. opts = this.extendYAxisAnnotations(opts);
  6553. opts = this.extendXAxisAnnotations(opts);
  6554. opts = this.extendPointAnnotations(opts);
  6555. return opts;
  6556. }
  6557. }, {
  6558. key: "extendYAxisAnnotations",
  6559. value: function extendYAxisAnnotations(opts) {
  6560. var options = new Options();
  6561. opts.annotations.yaxis = Utils$1.extendArray(typeof opts.annotations.yaxis !== 'undefined' ? opts.annotations.yaxis : [], options.yAxisAnnotation);
  6562. return opts;
  6563. }
  6564. }, {
  6565. key: "extendXAxisAnnotations",
  6566. value: function extendXAxisAnnotations(opts) {
  6567. var options = new Options();
  6568. opts.annotations.xaxis = Utils$1.extendArray(typeof opts.annotations.xaxis !== 'undefined' ? opts.annotations.xaxis : [], options.xAxisAnnotation);
  6569. return opts;
  6570. }
  6571. }, {
  6572. key: "extendPointAnnotations",
  6573. value: function extendPointAnnotations(opts) {
  6574. var options = new Options();
  6575. opts.annotations.points = Utils$1.extendArray(typeof opts.annotations.points !== 'undefined' ? opts.annotations.points : [], options.pointAnnotation);
  6576. return opts;
  6577. }
  6578. }, {
  6579. key: "checkForDarkTheme",
  6580. value: function checkForDarkTheme(opts) {
  6581. if (opts.theme && opts.theme.mode === 'dark') {
  6582. if (!opts.tooltip) {
  6583. opts.tooltip = {};
  6584. }
  6585. if (opts.tooltip.theme !== 'light') {
  6586. opts.tooltip.theme = 'dark';
  6587. }
  6588. if (!opts.chart.foreColor) {
  6589. opts.chart.foreColor = '#f6f7f8';
  6590. }
  6591. if (!opts.theme.palette) {
  6592. opts.theme.palette = 'palette4';
  6593. }
  6594. }
  6595. }
  6596. }, {
  6597. key: "handleUserInputErrors",
  6598. value: function handleUserInputErrors(opts) {
  6599. var config = opts;
  6600. // conflicting tooltip option. intersect makes sure to focus on 1 point at a time. Shared cannot be used along with it
  6601. if (config.tooltip.shared && config.tooltip.intersect) {
  6602. throw new Error('tooltip.shared cannot be enabled when tooltip.intersect is true. Turn off any other option by setting it to false.');
  6603. }
  6604. if (config.chart.type === 'bar' && config.plotOptions.bar.horizontal) {
  6605. // No multiple yaxis for bars
  6606. if (config.yaxis.length > 1) {
  6607. throw new Error('Multiple Y Axis for bars are not supported. Switch to column chart by setting plotOptions.bar.horizontal=false');
  6608. }
  6609. // if yaxis is reversed in horizontal bar chart, you should draw the y-axis on right side
  6610. if (config.yaxis[0].reversed) {
  6611. config.yaxis[0].opposite = true;
  6612. }
  6613. config.xaxis.tooltip.enabled = false; // no xaxis tooltip for horizontal bar
  6614. config.yaxis[0].tooltip.enabled = false; // no xaxis tooltip for horizontal bar
  6615. config.chart.zoom.enabled = false; // no zooming for horz bars
  6616. }
  6617. if (config.chart.type === 'bar' || config.chart.type === 'rangeBar') {
  6618. if (config.tooltip.shared) {
  6619. if (config.xaxis.crosshairs.width === 'barWidth' && config.series.length > 1) {
  6620. config.xaxis.crosshairs.width = 'tickWidth';
  6621. }
  6622. }
  6623. }
  6624. if (config.chart.type === 'candlestick' || config.chart.type === 'boxPlot') {
  6625. if (config.yaxis[0].reversed) {
  6626. console.warn("Reversed y-axis in ".concat(config.chart.type, " chart is not supported."));
  6627. config.yaxis[0].reversed = false;
  6628. }
  6629. }
  6630. return config;
  6631. }
  6632. }]);
  6633. return Config;
  6634. }();
  6635. var Globals = /*#__PURE__*/function () {
  6636. function Globals() {
  6637. _classCallCheck(this, Globals);
  6638. }
  6639. _createClass(Globals, [{
  6640. key: "initGlobalVars",
  6641. value: function initGlobalVars(gl) {
  6642. gl.series = []; // the MAIN series array (y values)
  6643. gl.seriesCandleO = [];
  6644. gl.seriesCandleH = [];
  6645. gl.seriesCandleM = [];
  6646. gl.seriesCandleL = [];
  6647. gl.seriesCandleC = [];
  6648. gl.seriesRangeStart = [];
  6649. gl.seriesRangeEnd = [];
  6650. gl.seriesRange = [];
  6651. gl.seriesPercent = [];
  6652. gl.seriesGoals = [];
  6653. gl.seriesX = [];
  6654. gl.seriesZ = [];
  6655. gl.seriesNames = [];
  6656. gl.seriesTotals = [];
  6657. gl.seriesLog = [];
  6658. gl.seriesColors = [];
  6659. gl.stackedSeriesTotals = [];
  6660. gl.seriesXvalues = []; // we will need this in tooltip (it's x position)
  6661. // when we will have unequal x values, we will need
  6662. // some way to get x value depending on mouse pointer
  6663. gl.seriesYvalues = []; // we will need this when deciding which series
  6664. // user hovered on
  6665. gl.labels = [];
  6666. gl.hasXaxisGroups = false;
  6667. gl.groups = [];
  6668. gl.barGroups = [];
  6669. gl.lineGroups = [];
  6670. gl.areaGroups = [];
  6671. gl.hasSeriesGroups = false;
  6672. gl.seriesGroups = [];
  6673. gl.categoryLabels = [];
  6674. gl.timescaleLabels = [];
  6675. gl.noLabelsProvided = false;
  6676. gl.resizeTimer = null;
  6677. gl.selectionResizeTimer = null;
  6678. gl.lastWheelExecution = 0;
  6679. gl.delayedElements = [];
  6680. gl.pointsArray = [];
  6681. gl.dataLabelsRects = [];
  6682. gl.isXNumeric = false;
  6683. gl.skipLastTimelinelabel = false;
  6684. gl.skipFirstTimelinelabel = false;
  6685. gl.isDataXYZ = false;
  6686. gl.isMultiLineX = false;
  6687. gl.isMultipleYAxis = false;
  6688. gl.maxY = -Number.MAX_VALUE;
  6689. gl.minY = Number.MIN_VALUE;
  6690. gl.minYArr = [];
  6691. gl.maxYArr = [];
  6692. gl.maxX = -Number.MAX_VALUE;
  6693. gl.minX = Number.MAX_VALUE;
  6694. gl.initialMaxX = -Number.MAX_VALUE;
  6695. gl.initialMinX = Number.MAX_VALUE;
  6696. gl.maxDate = 0;
  6697. gl.minDate = Number.MAX_VALUE;
  6698. gl.minZ = Number.MAX_VALUE;
  6699. gl.maxZ = -Number.MAX_VALUE;
  6700. gl.minXDiff = Number.MAX_VALUE;
  6701. gl.yAxisScale = [];
  6702. gl.xAxisScale = null;
  6703. gl.xAxisTicksPositions = [];
  6704. gl.yLabelsCoords = [];
  6705. gl.yTitleCoords = [];
  6706. gl.barPadForNumericAxis = 0;
  6707. gl.padHorizontal = 0;
  6708. gl.xRange = 0;
  6709. gl.yRange = [];
  6710. gl.zRange = 0;
  6711. gl.dataPoints = 0;
  6712. gl.xTickAmount = 0;
  6713. gl.multiAxisTickAmount = 0;
  6714. }
  6715. }, {
  6716. key: "globalVars",
  6717. value: function globalVars(config) {
  6718. return {
  6719. chartID: null,
  6720. // chart ID - apexcharts-cuid
  6721. cuid: null,
  6722. // chart ID - random numbers excluding "apexcharts" part
  6723. events: {
  6724. beforeMount: [],
  6725. mounted: [],
  6726. updated: [],
  6727. clicked: [],
  6728. selection: [],
  6729. dataPointSelection: [],
  6730. zoomed: [],
  6731. scrolled: []
  6732. },
  6733. colors: [],
  6734. clientX: null,
  6735. clientY: null,
  6736. fill: {
  6737. colors: []
  6738. },
  6739. stroke: {
  6740. colors: []
  6741. },
  6742. dataLabels: {
  6743. style: {
  6744. colors: []
  6745. }
  6746. },
  6747. radarPolygons: {
  6748. fill: {
  6749. colors: []
  6750. }
  6751. },
  6752. markers: {
  6753. colors: [],
  6754. size: config.markers.size,
  6755. largestSize: 0
  6756. },
  6757. animationEnded: false,
  6758. isTouchDevice: 'ontouchstart' in window || navigator.msMaxTouchPoints,
  6759. isDirty: false,
  6760. // chart has been updated after the initial render. This is different than dataChanged property. isDirty means user manually called some method to update
  6761. isExecCalled: false,
  6762. // whether user updated the chart through the exec method
  6763. initialConfig: null,
  6764. // we will store the first config user has set to go back when user finishes interactions like zooming and come out of it
  6765. initialSeries: [],
  6766. lastXAxis: [],
  6767. lastYAxis: [],
  6768. columnSeries: null,
  6769. labels: [],
  6770. // store the text to draw on x axis
  6771. // Don't mutate the labels, many things including tooltips depends on it!
  6772. timescaleLabels: [],
  6773. // store the timescaleLabels Labels in another variable
  6774. noLabelsProvided: false,
  6775. // if user didn't provide any categories/labels or x values, fallback to 1,2,3,4...
  6776. allSeriesCollapsed: false,
  6777. collapsedSeries: [],
  6778. // when user collapses a series, it goes into this array
  6779. collapsedSeriesIndices: [],
  6780. // this stores the index of the collapsedSeries instead of whole object for quick access
  6781. ancillaryCollapsedSeries: [],
  6782. // when user collapses an "alwaysVisible" series, it goes into this array
  6783. ancillaryCollapsedSeriesIndices: [],
  6784. // this stores the index of the ancillaryCollapsedSeries whose y-axis is always visible
  6785. risingSeries: [],
  6786. // when user re-opens a collapsed series, it goes here
  6787. dataFormatXNumeric: false,
  6788. // boolean value to indicate user has passed numeric x values
  6789. capturedSeriesIndex: -1,
  6790. capturedDataPointIndex: -1,
  6791. selectedDataPoints: [],
  6792. invalidLogScale: false,
  6793. // if a user enabled log scale but the data provided is not valid to generate a log scale, turn on this flag
  6794. ignoreYAxisIndexes: [],
  6795. // when series are being collapsed in multiple y axes, ignore certain index
  6796. maxValsInArrayIndex: 0,
  6797. radialSize: 0,
  6798. selection: undefined,
  6799. zoomEnabled: config.chart.toolbar.autoSelected === 'zoom' && config.chart.toolbar.tools.zoom && config.chart.zoom.enabled,
  6800. panEnabled: config.chart.toolbar.autoSelected === 'pan' && config.chart.toolbar.tools.pan,
  6801. selectionEnabled: config.chart.toolbar.autoSelected === 'selection' && config.chart.toolbar.tools.selection,
  6802. yaxis: null,
  6803. mousedown: false,
  6804. lastClientPosition: {},
  6805. // don't reset this variable this the chart is destroyed. It is used to detect right or left mousemove in panning
  6806. visibleXRange: undefined,
  6807. yValueDecimal: 0,
  6808. // are there floating numbers in the series. If yes, this represent the len of the decimals
  6809. total: 0,
  6810. SVGNS: 'http://www.w3.org/2000/svg',
  6811. // svg namespace
  6812. svgWidth: 0,
  6813. // the whole svg width
  6814. svgHeight: 0,
  6815. // the whole svg height
  6816. noData: false,
  6817. // whether there is any data to display or not
  6818. locale: {},
  6819. // the current locale values will be preserved here for global access
  6820. dom: {},
  6821. // for storing all dom nodes in this particular property
  6822. memory: {
  6823. methodsToExec: []
  6824. },
  6825. shouldAnimate: true,
  6826. skipLastTimelinelabel: false,
  6827. // when last label is cropped, skip drawing it
  6828. skipFirstTimelinelabel: false,
  6829. // when first label is cropped, skip drawing it
  6830. delayedElements: [],
  6831. // element which appear after animation has finished
  6832. axisCharts: true,
  6833. // chart type = line or area or bar
  6834. // (refer them also as plot charts in the code)
  6835. isDataXYZ: false,
  6836. // bool: data was provided in a {[x,y,z]} pattern
  6837. isSlopeChart: config.plotOptions.line.isSlopeChart,
  6838. resized: false,
  6839. // bool: user has resized
  6840. resizeTimer: null,
  6841. // timeout function to make a small delay before
  6842. // drawing when user resized
  6843. comboCharts: false,
  6844. // bool: whether it's a combination of line/column
  6845. dataChanged: false,
  6846. // bool: has data changed dynamically
  6847. previousPaths: [],
  6848. // array: when data is changed, it will animate from
  6849. // previous paths
  6850. allSeriesHasEqualX: true,
  6851. pointsArray: [],
  6852. // store the points positions here to draw later on hover
  6853. // format is - [[x,y],[x,y]... [x,y]]
  6854. dataLabelsRects: [],
  6855. // store the positions of datalabels to prevent collision
  6856. lastDrawnDataLabelsIndexes: [],
  6857. hasNullValues: false,
  6858. // bool: whether series contains null values
  6859. easing: null,
  6860. // function: animation effect to apply
  6861. zoomed: false,
  6862. // whether user has zoomed or not
  6863. gridWidth: 0,
  6864. // drawable width of actual graphs (series paths)
  6865. gridHeight: 0,
  6866. // drawable height of actual graphs (series paths)
  6867. rotateXLabels: false,
  6868. defaultLabels: false,
  6869. xLabelFormatter: undefined,
  6870. // formatter for x axis labels
  6871. yLabelFormatters: [],
  6872. xaxisTooltipFormatter: undefined,
  6873. // formatter for x axis tooltip
  6874. ttKeyFormatter: undefined,
  6875. ttVal: undefined,
  6876. ttZFormatter: undefined,
  6877. LINE_HEIGHT_RATIO: 1.618,
  6878. xAxisLabelsHeight: 0,
  6879. xAxisGroupLabelsHeight: 0,
  6880. xAxisLabelsWidth: 0,
  6881. yAxisLabelsWidth: 0,
  6882. scaleX: 1,
  6883. scaleY: 1,
  6884. translateX: 0,
  6885. translateY: 0,
  6886. translateYAxisX: [],
  6887. yAxisWidths: [],
  6888. translateXAxisY: 0,
  6889. translateXAxisX: 0,
  6890. tooltip: null,
  6891. // Rules for niceScaleAllowedMagMsd:
  6892. // 1) An array of two arrays only ([[],[]]):
  6893. // * array[0][]: influences labelling of data series that contain only integers
  6894. // - must contain only integers (or expect ugly ticks)
  6895. // * array[1][]: influences labelling of data series that contain at least one float
  6896. // - may contain floats
  6897. // * both arrays:
  6898. // - each array[][i] ideally satisfy: 10 mod array[][i] == 0 (or expect ugly ticks)
  6899. // - to avoid clipping data point keep each array[][i] >= i
  6900. // 2) each array[i][] contains 11 values, for all possible index values 0..10.
  6901. // array[][0] should not be needed (not proven) but ensures non-zero is returned.
  6902. //
  6903. // Users can effectively force their preferred "magMsd" through stepSize and
  6904. // forceNiceScale. With forceNiceScale: true, stepSize becomes normalizable to the
  6905. // axis's min..max range, which allows users to set stepSize to an integer 1..10, for
  6906. // example, stepSize: 3. This value will be preferred to the value determined through
  6907. // this array. The range-normalized value is checked for consistency with other
  6908. // user defined options and will be ignored if inconsistent.
  6909. niceScaleAllowedMagMsd: [[1, 1, 2, 5, 5, 5, 10, 10, 10, 10, 10], [1, 1, 2, 5, 5, 5, 10, 10, 10, 10, 10]],
  6910. // Default ticks based on SVG size. These values have high numbers
  6911. // of divisors. The array is indexed using a calculated maxTicks value
  6912. // divided by 2 simply to halve the array size. See Scales.niceScale().
  6913. 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],
  6914. seriesYAxisMap: [],
  6915. // Given yAxis index, return all series indices belonging to it. Multiple series can be referenced to each yAxis.
  6916. seriesYAxisReverseMap: [] // Given a Series index, return its yAxis index.
  6917. };
  6918. }
  6919. }, {
  6920. key: "init",
  6921. value: function init(config) {
  6922. var globals = this.globalVars(config);
  6923. this.initGlobalVars(globals);
  6924. globals.initialConfig = Utils$1.extend({}, config);
  6925. globals.initialSeries = Utils$1.clone(config.series);
  6926. globals.lastXAxis = Utils$1.clone(globals.initialConfig.xaxis);
  6927. globals.lastYAxis = Utils$1.clone(globals.initialConfig.yaxis);
  6928. return globals;
  6929. }
  6930. }]);
  6931. return Globals;
  6932. }();
  6933. /**
  6934. * ApexCharts Base Class for extending user options with pre-defined ApexCharts config.
  6935. *
  6936. * @module Base
  6937. **/
  6938. var Base = /*#__PURE__*/function () {
  6939. function Base(opts) {
  6940. _classCallCheck(this, Base);
  6941. this.opts = opts;
  6942. }
  6943. _createClass(Base, [{
  6944. key: "init",
  6945. value: function init() {
  6946. var config = new Config(this.opts).init({
  6947. responsiveOverride: false
  6948. });
  6949. var globals = new Globals().init(config);
  6950. var w = {
  6951. config: config,
  6952. globals: globals
  6953. };
  6954. return w;
  6955. }
  6956. }]);
  6957. return Base;
  6958. }();
  6959. /**
  6960. * ApexCharts Fill Class for setting fill options of the paths.
  6961. *
  6962. * @module Fill
  6963. **/
  6964. var Fill = /*#__PURE__*/function () {
  6965. function Fill(ctx) {
  6966. _classCallCheck(this, Fill);
  6967. this.ctx = ctx;
  6968. this.w = ctx.w;
  6969. this.opts = null;
  6970. this.seriesIndex = 0;
  6971. this.patternIDs = [];
  6972. }
  6973. _createClass(Fill, [{
  6974. key: "clippedImgArea",
  6975. value: function clippedImgArea(params) {
  6976. var w = this.w;
  6977. var cnf = w.config;
  6978. var svgW = parseInt(w.globals.gridWidth, 10);
  6979. var svgH = parseInt(w.globals.gridHeight, 10);
  6980. var size = svgW > svgH ? svgW : svgH;
  6981. var fillImg = params.image;
  6982. var imgWidth = 0;
  6983. var imgHeight = 0;
  6984. if (typeof params.width === 'undefined' && typeof params.height === 'undefined') {
  6985. if (cnf.fill.image.width !== undefined && cnf.fill.image.height !== undefined) {
  6986. imgWidth = cnf.fill.image.width + 1;
  6987. imgHeight = cnf.fill.image.height;
  6988. } else {
  6989. imgWidth = size + 1;
  6990. imgHeight = size;
  6991. }
  6992. } else {
  6993. imgWidth = params.width;
  6994. imgHeight = params.height;
  6995. }
  6996. var elPattern = document.createElementNS(w.globals.SVGNS, 'pattern');
  6997. Graphics.setAttrs(elPattern, {
  6998. id: params.patternID,
  6999. patternUnits: params.patternUnits ? params.patternUnits : 'userSpaceOnUse',
  7000. width: imgWidth + 'px',
  7001. height: imgHeight + 'px'
  7002. });
  7003. var elImage = document.createElementNS(w.globals.SVGNS, 'image');
  7004. elPattern.appendChild(elImage);
  7005. elImage.setAttributeNS(window.SVG.xlink, 'href', fillImg);
  7006. Graphics.setAttrs(elImage, {
  7007. x: 0,
  7008. y: 0,
  7009. preserveAspectRatio: 'none',
  7010. width: imgWidth + 'px',
  7011. height: imgHeight + 'px'
  7012. });
  7013. elImage.style.opacity = params.opacity;
  7014. w.globals.dom.elDefs.node.appendChild(elPattern);
  7015. }
  7016. }, {
  7017. key: "getSeriesIndex",
  7018. value: function getSeriesIndex(opts) {
  7019. var w = this.w;
  7020. var cType = w.config.chart.type;
  7021. if ((cType === 'bar' || cType === 'rangeBar') && w.config.plotOptions.bar.distributed || cType === 'heatmap' || cType === 'treemap') {
  7022. this.seriesIndex = opts.seriesNumber;
  7023. } else {
  7024. this.seriesIndex = opts.seriesNumber % w.globals.series.length;
  7025. }
  7026. return this.seriesIndex;
  7027. }
  7028. }, {
  7029. key: "fillPath",
  7030. value: function fillPath(opts) {
  7031. var w = this.w;
  7032. this.opts = opts;
  7033. var cnf = this.w.config;
  7034. var pathFill;
  7035. var patternFill, gradientFill;
  7036. this.seriesIndex = this.getSeriesIndex(opts);
  7037. var fillColors = this.getFillColors();
  7038. var fillColor = fillColors[this.seriesIndex];
  7039. //override fillcolor if user inputted color with data
  7040. if (w.globals.seriesColors[this.seriesIndex] !== undefined) {
  7041. fillColor = w.globals.seriesColors[this.seriesIndex];
  7042. }
  7043. if (typeof fillColor === 'function') {
  7044. fillColor = fillColor({
  7045. seriesIndex: this.seriesIndex,
  7046. dataPointIndex: opts.dataPointIndex,
  7047. value: opts.value,
  7048. w: w
  7049. });
  7050. }
  7051. var fillType = opts.fillType ? opts.fillType : this.getFillType(this.seriesIndex);
  7052. var fillOpacity = Array.isArray(cnf.fill.opacity) ? cnf.fill.opacity[this.seriesIndex] : cnf.fill.opacity;
  7053. if (opts.color) {
  7054. fillColor = opts.color;
  7055. }
  7056. // in case a color is undefined, fallback to white color to prevent runtime error
  7057. if (!fillColor) {
  7058. fillColor = '#fff';
  7059. console.warn('undefined color - ApexCharts');
  7060. }
  7061. var defaultColor = fillColor;
  7062. if (fillColor.indexOf('rgb') === -1) {
  7063. if (fillColor.length < 9) {
  7064. // if the hex contains alpha and is of 9 digit, skip the opacity
  7065. defaultColor = Utils$1.hexToRgba(fillColor, fillOpacity);
  7066. }
  7067. } else {
  7068. if (fillColor.indexOf('rgba') > -1) {
  7069. fillOpacity = Utils$1.getOpacityFromRGBA(fillColor);
  7070. }
  7071. }
  7072. if (opts.opacity) fillOpacity = opts.opacity;
  7073. if (fillType === 'pattern') {
  7074. patternFill = this.handlePatternFill({
  7075. fillConfig: opts.fillConfig,
  7076. patternFill: patternFill,
  7077. fillColor: fillColor,
  7078. fillOpacity: fillOpacity,
  7079. defaultColor: defaultColor
  7080. });
  7081. }
  7082. if (fillType === 'gradient') {
  7083. gradientFill = this.handleGradientFill({
  7084. fillConfig: opts.fillConfig,
  7085. fillColor: fillColor,
  7086. fillOpacity: fillOpacity,
  7087. i: this.seriesIndex
  7088. });
  7089. }
  7090. if (fillType === 'image') {
  7091. var imgSrc = cnf.fill.image.src;
  7092. var patternID = opts.patternID ? opts.patternID : '';
  7093. var patternKey = "pattern".concat(w.globals.cuid).concat(opts.seriesNumber + 1).concat(patternID);
  7094. if (this.patternIDs.indexOf(patternKey) === -1) {
  7095. this.clippedImgArea({
  7096. opacity: fillOpacity,
  7097. image: Array.isArray(imgSrc) ? opts.seriesNumber < imgSrc.length ? imgSrc[opts.seriesNumber] : imgSrc[0] : imgSrc,
  7098. width: opts.width ? opts.width : undefined,
  7099. height: opts.height ? opts.height : undefined,
  7100. patternUnits: opts.patternUnits,
  7101. patternID: patternKey
  7102. });
  7103. this.patternIDs.push(patternKey);
  7104. }
  7105. pathFill = "url(#".concat(patternKey, ")");
  7106. } else if (fillType === 'gradient') {
  7107. pathFill = gradientFill;
  7108. } else if (fillType === 'pattern') {
  7109. pathFill = patternFill;
  7110. } else {
  7111. pathFill = defaultColor;
  7112. }
  7113. // override pattern/gradient if opts.solid is true
  7114. if (opts.solid) {
  7115. pathFill = defaultColor;
  7116. }
  7117. return pathFill;
  7118. }
  7119. }, {
  7120. key: "getFillType",
  7121. value: function getFillType(seriesIndex) {
  7122. var w = this.w;
  7123. if (Array.isArray(w.config.fill.type)) {
  7124. return w.config.fill.type[seriesIndex];
  7125. } else {
  7126. return w.config.fill.type;
  7127. }
  7128. }
  7129. }, {
  7130. key: "getFillColors",
  7131. value: function getFillColors() {
  7132. var w = this.w;
  7133. var cnf = w.config;
  7134. var opts = this.opts;
  7135. var fillColors = [];
  7136. if (w.globals.comboCharts) {
  7137. if (w.config.series[this.seriesIndex].type === 'line') {
  7138. if (Array.isArray(w.globals.stroke.colors)) {
  7139. fillColors = w.globals.stroke.colors;
  7140. } else {
  7141. fillColors.push(w.globals.stroke.colors);
  7142. }
  7143. } else {
  7144. if (Array.isArray(w.globals.fill.colors)) {
  7145. fillColors = w.globals.fill.colors;
  7146. } else {
  7147. fillColors.push(w.globals.fill.colors);
  7148. }
  7149. }
  7150. } else {
  7151. if (cnf.chart.type === 'line') {
  7152. if (Array.isArray(w.globals.stroke.colors)) {
  7153. fillColors = w.globals.stroke.colors;
  7154. } else {
  7155. fillColors.push(w.globals.stroke.colors);
  7156. }
  7157. } else {
  7158. if (Array.isArray(w.globals.fill.colors)) {
  7159. fillColors = w.globals.fill.colors;
  7160. } else {
  7161. fillColors.push(w.globals.fill.colors);
  7162. }
  7163. }
  7164. }
  7165. // colors passed in arguments
  7166. if (typeof opts.fillColors !== 'undefined') {
  7167. fillColors = [];
  7168. if (Array.isArray(opts.fillColors)) {
  7169. fillColors = opts.fillColors.slice();
  7170. } else {
  7171. fillColors.push(opts.fillColors);
  7172. }
  7173. }
  7174. return fillColors;
  7175. }
  7176. }, {
  7177. key: "handlePatternFill",
  7178. value: function handlePatternFill(_ref) {
  7179. var fillConfig = _ref.fillConfig,
  7180. patternFill = _ref.patternFill,
  7181. fillColor = _ref.fillColor,
  7182. fillOpacity = _ref.fillOpacity,
  7183. defaultColor = _ref.defaultColor;
  7184. var fillCnf = this.w.config.fill;
  7185. if (fillConfig) {
  7186. fillCnf = fillConfig;
  7187. }
  7188. var opts = this.opts;
  7189. var graphics = new Graphics(this.ctx);
  7190. var patternStrokeWidth = Array.isArray(fillCnf.pattern.strokeWidth) ? fillCnf.pattern.strokeWidth[this.seriesIndex] : fillCnf.pattern.strokeWidth;
  7191. var patternLineColor = fillColor;
  7192. if (Array.isArray(fillCnf.pattern.style)) {
  7193. if (typeof fillCnf.pattern.style[opts.seriesNumber] !== 'undefined') {
  7194. var pf = graphics.drawPattern(fillCnf.pattern.style[opts.seriesNumber], fillCnf.pattern.width, fillCnf.pattern.height, patternLineColor, patternStrokeWidth, fillOpacity);
  7195. patternFill = pf;
  7196. } else {
  7197. patternFill = defaultColor;
  7198. }
  7199. } else {
  7200. patternFill = graphics.drawPattern(fillCnf.pattern.style, fillCnf.pattern.width, fillCnf.pattern.height, patternLineColor, patternStrokeWidth, fillOpacity);
  7201. }
  7202. return patternFill;
  7203. }
  7204. }, {
  7205. key: "handleGradientFill",
  7206. value: function handleGradientFill(_ref2) {
  7207. var fillColor = _ref2.fillColor,
  7208. fillOpacity = _ref2.fillOpacity,
  7209. fillConfig = _ref2.fillConfig,
  7210. i = _ref2.i;
  7211. var fillCnf = this.w.config.fill;
  7212. if (fillConfig) {
  7213. fillCnf = _objectSpread2(_objectSpread2({}, fillCnf), fillConfig);
  7214. }
  7215. var opts = this.opts;
  7216. var graphics = new Graphics(this.ctx);
  7217. var utils = new Utils$1();
  7218. var type = fillCnf.gradient.type;
  7219. var gradientFrom = fillColor;
  7220. var gradientTo;
  7221. var opacityFrom = fillCnf.gradient.opacityFrom === undefined ? fillOpacity : Array.isArray(fillCnf.gradient.opacityFrom) ? fillCnf.gradient.opacityFrom[i] : fillCnf.gradient.opacityFrom;
  7222. if (gradientFrom.indexOf('rgba') > -1) {
  7223. opacityFrom = Utils$1.getOpacityFromRGBA(gradientFrom);
  7224. }
  7225. var opacityTo = fillCnf.gradient.opacityTo === undefined ? fillOpacity : Array.isArray(fillCnf.gradient.opacityTo) ? fillCnf.gradient.opacityTo[i] : fillCnf.gradient.opacityTo;
  7226. if (fillCnf.gradient.gradientToColors === undefined || fillCnf.gradient.gradientToColors.length === 0) {
  7227. if (fillCnf.gradient.shade === 'dark') {
  7228. gradientTo = utils.shadeColor(parseFloat(fillCnf.gradient.shadeIntensity) * -1, fillColor.indexOf('rgb') > -1 ? Utils$1.rgb2hex(fillColor) : fillColor);
  7229. } else {
  7230. gradientTo = utils.shadeColor(parseFloat(fillCnf.gradient.shadeIntensity), fillColor.indexOf('rgb') > -1 ? Utils$1.rgb2hex(fillColor) : fillColor);
  7231. }
  7232. } else {
  7233. if (fillCnf.gradient.gradientToColors[opts.seriesNumber]) {
  7234. var gToColor = fillCnf.gradient.gradientToColors[opts.seriesNumber];
  7235. gradientTo = gToColor;
  7236. if (gToColor.indexOf('rgba') > -1) {
  7237. opacityTo = Utils$1.getOpacityFromRGBA(gToColor);
  7238. }
  7239. } else {
  7240. gradientTo = fillColor;
  7241. }
  7242. }
  7243. if (fillCnf.gradient.gradientFrom) {
  7244. gradientFrom = fillCnf.gradient.gradientFrom;
  7245. }
  7246. if (fillCnf.gradient.gradientTo) {
  7247. gradientTo = fillCnf.gradient.gradientTo;
  7248. }
  7249. if (fillCnf.gradient.inverseColors) {
  7250. var t = gradientFrom;
  7251. gradientFrom = gradientTo;
  7252. gradientTo = t;
  7253. }
  7254. if (gradientFrom.indexOf('rgb') > -1) {
  7255. gradientFrom = Utils$1.rgb2hex(gradientFrom);
  7256. }
  7257. if (gradientTo.indexOf('rgb') > -1) {
  7258. gradientTo = Utils$1.rgb2hex(gradientTo);
  7259. }
  7260. return graphics.drawGradient(type, gradientFrom, gradientTo, opacityFrom, opacityTo, opts.size, fillCnf.gradient.stops, fillCnf.gradient.colorStops, i);
  7261. }
  7262. }]);
  7263. return Fill;
  7264. }();
  7265. /**
  7266. * ApexCharts Markers Class for drawing points on y values in axes charts.
  7267. *
  7268. * @module Markers
  7269. **/
  7270. var Markers = /*#__PURE__*/function () {
  7271. function Markers(ctx, opts) {
  7272. _classCallCheck(this, Markers);
  7273. this.ctx = ctx;
  7274. this.w = ctx.w;
  7275. }
  7276. _createClass(Markers, [{
  7277. key: "setGlobalMarkerSize",
  7278. value: function setGlobalMarkerSize() {
  7279. var w = this.w;
  7280. w.globals.markers.size = Array.isArray(w.config.markers.size) ? w.config.markers.size : [w.config.markers.size];
  7281. if (w.globals.markers.size.length > 0) {
  7282. if (w.globals.markers.size.length < w.globals.series.length + 1) {
  7283. for (var i = 0; i <= w.globals.series.length; i++) {
  7284. if (typeof w.globals.markers.size[i] === 'undefined') {
  7285. w.globals.markers.size.push(w.globals.markers.size[0]);
  7286. }
  7287. }
  7288. }
  7289. } else {
  7290. w.globals.markers.size = w.config.series.map(function (s) {
  7291. return w.config.markers.size;
  7292. });
  7293. }
  7294. }
  7295. }, {
  7296. key: "plotChartMarkers",
  7297. value: function plotChartMarkers(pointsPos, seriesIndex, j, pSize) {
  7298. var alwaysDrawMarker = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  7299. var w = this.w;
  7300. var i = seriesIndex;
  7301. var p = pointsPos;
  7302. var elPointsWrap = null;
  7303. var graphics = new Graphics(this.ctx);
  7304. var point;
  7305. var hasDiscreteMarkers = w.config.markers.discrete && w.config.markers.discrete.length;
  7306. if (w.globals.markers.size[seriesIndex] > 0 || alwaysDrawMarker || hasDiscreteMarkers) {
  7307. elPointsWrap = graphics.group({
  7308. class: alwaysDrawMarker || hasDiscreteMarkers ? '' : 'apexcharts-series-markers'
  7309. });
  7310. elPointsWrap.attr('clip-path', "url(#gridRectMarkerMask".concat(w.globals.cuid, ")"));
  7311. }
  7312. if (Array.isArray(p.x)) {
  7313. for (var q = 0; q < p.x.length; q++) {
  7314. var dataPointIndex = j;
  7315. // a small hack as we have 2 points for the first val to connect it
  7316. if (j === 1 && q === 0) dataPointIndex = 0;
  7317. if (j === 1 && q === 1) dataPointIndex = 1;
  7318. var PointClasses = 'apexcharts-marker';
  7319. if ((w.config.chart.type === 'line' || w.config.chart.type === 'area') && !w.globals.comboCharts && !w.config.tooltip.intersect) {
  7320. PointClasses += ' no-pointer-events';
  7321. }
  7322. var shouldMarkerDraw = Array.isArray(w.config.markers.size) ? w.globals.markers.size[seriesIndex] > 0 : w.config.markers.size > 0;
  7323. if (shouldMarkerDraw || alwaysDrawMarker || hasDiscreteMarkers) {
  7324. if (Utils$1.isNumber(p.y[q])) {
  7325. PointClasses += " w".concat(Utils$1.randomId());
  7326. } else {
  7327. PointClasses = 'apexcharts-nullpoint';
  7328. }
  7329. var opts = this.getMarkerConfig({
  7330. cssClass: PointClasses,
  7331. seriesIndex: seriesIndex,
  7332. dataPointIndex: dataPointIndex
  7333. });
  7334. if (w.config.series[i].data[dataPointIndex]) {
  7335. if (w.config.series[i].data[dataPointIndex].fillColor) {
  7336. opts.pointFillColor = w.config.series[i].data[dataPointIndex].fillColor;
  7337. }
  7338. if (w.config.series[i].data[dataPointIndex].strokeColor) {
  7339. opts.pointStrokeColor = w.config.series[i].data[dataPointIndex].strokeColor;
  7340. }
  7341. }
  7342. if (typeof pSize !== 'undefined') {
  7343. opts.pSize = pSize;
  7344. }
  7345. 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) {
  7346. opts.pSize = 0;
  7347. }
  7348. point = graphics.drawMarker(p.x[q], p.y[q], opts);
  7349. point.attr('rel', dataPointIndex);
  7350. point.attr('j', dataPointIndex);
  7351. point.attr('index', seriesIndex);
  7352. point.node.setAttribute('default-marker-size', opts.pSize);
  7353. var filters = new Filters(this.ctx);
  7354. filters.setSelectionFilter(point, seriesIndex, dataPointIndex);
  7355. this.addEvents(point);
  7356. if (elPointsWrap) {
  7357. elPointsWrap.add(point);
  7358. }
  7359. } else {
  7360. // dynamic array creation - multidimensional
  7361. if (typeof w.globals.pointsArray[seriesIndex] === 'undefined') w.globals.pointsArray[seriesIndex] = [];
  7362. w.globals.pointsArray[seriesIndex].push([p.x[q], p.y[q]]);
  7363. }
  7364. }
  7365. }
  7366. return elPointsWrap;
  7367. }
  7368. }, {
  7369. key: "getMarkerConfig",
  7370. value: function getMarkerConfig(_ref) {
  7371. var cssClass = _ref.cssClass,
  7372. seriesIndex = _ref.seriesIndex,
  7373. _ref$dataPointIndex = _ref.dataPointIndex,
  7374. dataPointIndex = _ref$dataPointIndex === void 0 ? null : _ref$dataPointIndex,
  7375. _ref$radius = _ref.radius,
  7376. radius = _ref$radius === void 0 ? null : _ref$radius,
  7377. _ref$size = _ref.size,
  7378. size = _ref$size === void 0 ? null : _ref$size,
  7379. _ref$strokeWidth = _ref.strokeWidth,
  7380. strokeWidth = _ref$strokeWidth === void 0 ? null : _ref$strokeWidth;
  7381. var w = this.w;
  7382. var pStyle = this.getMarkerStyle(seriesIndex);
  7383. var pSize = size === null ? w.globals.markers.size[seriesIndex] : size;
  7384. var m = w.config.markers;
  7385. // discrete markers is an option where user can specify a particular marker with different shape, size and color
  7386. if (dataPointIndex !== null && m.discrete.length) {
  7387. m.discrete.map(function (marker) {
  7388. if (marker.seriesIndex === seriesIndex && marker.dataPointIndex === dataPointIndex) {
  7389. pStyle.pointStrokeColor = marker.strokeColor;
  7390. pStyle.pointFillColor = marker.fillColor;
  7391. pSize = marker.size;
  7392. pStyle.pointShape = marker.shape;
  7393. }
  7394. });
  7395. }
  7396. return {
  7397. pSize: radius === null ? pSize : radius,
  7398. pRadius: radius !== null ? radius : m.radius,
  7399. pointStrokeWidth: strokeWidth !== null ? strokeWidth : Array.isArray(m.strokeWidth) ? m.strokeWidth[seriesIndex] : m.strokeWidth,
  7400. pointStrokeColor: pStyle.pointStrokeColor,
  7401. pointFillColor: pStyle.pointFillColor,
  7402. shape: pStyle.pointShape || (Array.isArray(m.shape) ? m.shape[seriesIndex] : m.shape),
  7403. class: cssClass,
  7404. pointStrokeOpacity: Array.isArray(m.strokeOpacity) ? m.strokeOpacity[seriesIndex] : m.strokeOpacity,
  7405. pointStrokeDashArray: Array.isArray(m.strokeDashArray) ? m.strokeDashArray[seriesIndex] : m.strokeDashArray,
  7406. pointFillOpacity: Array.isArray(m.fillOpacity) ? m.fillOpacity[seriesIndex] : m.fillOpacity,
  7407. seriesIndex: seriesIndex
  7408. };
  7409. }
  7410. }, {
  7411. key: "addEvents",
  7412. value: function addEvents(marker) {
  7413. var w = this.w;
  7414. var graphics = new Graphics(this.ctx);
  7415. marker.node.addEventListener('mouseenter', graphics.pathMouseEnter.bind(this.ctx, marker));
  7416. marker.node.addEventListener('mouseleave', graphics.pathMouseLeave.bind(this.ctx, marker));
  7417. marker.node.addEventListener('mousedown', graphics.pathMouseDown.bind(this.ctx, marker));
  7418. marker.node.addEventListener('click', w.config.markers.onClick);
  7419. marker.node.addEventListener('dblclick', w.config.markers.onDblClick);
  7420. marker.node.addEventListener('touchstart', graphics.pathMouseDown.bind(this.ctx, marker), {
  7421. passive: true
  7422. });
  7423. }
  7424. }, {
  7425. key: "getMarkerStyle",
  7426. value: function getMarkerStyle(seriesIndex) {
  7427. var w = this.w;
  7428. var colors = w.globals.markers.colors;
  7429. var strokeColors = w.config.markers.strokeColor || w.config.markers.strokeColors;
  7430. var pointStrokeColor = Array.isArray(strokeColors) ? strokeColors[seriesIndex] : strokeColors;
  7431. var pointFillColor = Array.isArray(colors) ? colors[seriesIndex] : colors;
  7432. return {
  7433. pointStrokeColor: pointStrokeColor,
  7434. pointFillColor: pointFillColor
  7435. };
  7436. }
  7437. }]);
  7438. return Markers;
  7439. }();
  7440. /**
  7441. * ApexCharts Scatter Class.
  7442. * This Class also handles bubbles chart as currently there is no major difference in drawing them,
  7443. * @module Scatter
  7444. **/
  7445. var Scatter = /*#__PURE__*/function () {
  7446. function Scatter(ctx) {
  7447. _classCallCheck(this, Scatter);
  7448. this.ctx = ctx;
  7449. this.w = ctx.w;
  7450. this.initialAnim = this.w.config.chart.animations.enabled;
  7451. }
  7452. _createClass(Scatter, [{
  7453. key: "draw",
  7454. value: function draw(elSeries, j, opts) {
  7455. var w = this.w;
  7456. var graphics = new Graphics(this.ctx);
  7457. var realIndex = opts.realIndex;
  7458. var pointsPos = opts.pointsPos;
  7459. var zRatio = opts.zRatio;
  7460. var elPointsMain = opts.elParent;
  7461. var elPointsWrap = graphics.group({
  7462. class: "apexcharts-series-markers apexcharts-series-".concat(w.config.chart.type)
  7463. });
  7464. elPointsWrap.attr('clip-path', "url(#gridRectMarkerMask".concat(w.globals.cuid, ")"));
  7465. if (Array.isArray(pointsPos.x)) {
  7466. for (var q = 0; q < pointsPos.x.length; q++) {
  7467. var dataPointIndex = j + 1;
  7468. var shouldDraw = true;
  7469. // a small hack as we have 2 points for the first val to connect it
  7470. if (j === 0 && q === 0) dataPointIndex = 0;
  7471. if (j === 0 && q === 1) dataPointIndex = 1;
  7472. var radius = w.globals.markers.size[realIndex];
  7473. if (zRatio !== Infinity) {
  7474. // means we have a bubble
  7475. var bubble = w.config.plotOptions.bubble;
  7476. radius = w.globals.seriesZ[realIndex][dataPointIndex];
  7477. if (bubble.zScaling) {
  7478. radius /= zRatio;
  7479. }
  7480. if (bubble.minBubbleRadius && radius < bubble.minBubbleRadius) {
  7481. radius = bubble.minBubbleRadius;
  7482. }
  7483. if (bubble.maxBubbleRadius && radius > bubble.maxBubbleRadius) {
  7484. radius = bubble.maxBubbleRadius;
  7485. }
  7486. }
  7487. var x = pointsPos.x[q];
  7488. var y = pointsPos.y[q];
  7489. radius = radius || 0;
  7490. if (y === null || typeof w.globals.series[realIndex][dataPointIndex] === 'undefined') {
  7491. shouldDraw = false;
  7492. }
  7493. if (shouldDraw) {
  7494. var point = this.drawPoint(x, y, radius, realIndex, dataPointIndex, j);
  7495. elPointsWrap.add(point);
  7496. }
  7497. elPointsMain.add(elPointsWrap);
  7498. }
  7499. }
  7500. }
  7501. }, {
  7502. key: "drawPoint",
  7503. value: function drawPoint(x, y, radius, realIndex, dataPointIndex, j) {
  7504. var w = this.w;
  7505. var i = realIndex;
  7506. var anim = new Animations(this.ctx);
  7507. var filters = new Filters(this.ctx);
  7508. var fill = new Fill(this.ctx);
  7509. var markers = new Markers(this.ctx);
  7510. var graphics = new Graphics(this.ctx);
  7511. var markerConfig = markers.getMarkerConfig({
  7512. cssClass: 'apexcharts-marker',
  7513. seriesIndex: i,
  7514. dataPointIndex: dataPointIndex,
  7515. radius: w.config.chart.type === 'bubble' || w.globals.comboCharts && w.config.series[realIndex] && w.config.series[realIndex].type === 'bubble' ? radius : null
  7516. });
  7517. var pathFillCircle = fill.fillPath({
  7518. seriesNumber: realIndex,
  7519. dataPointIndex: dataPointIndex,
  7520. color: markerConfig.pointFillColor,
  7521. patternUnits: 'objectBoundingBox',
  7522. value: w.globals.series[realIndex][j]
  7523. });
  7524. var el = graphics.drawMarker(x, y, markerConfig);
  7525. if (w.config.series[i].data[dataPointIndex]) {
  7526. if (w.config.series[i].data[dataPointIndex].fillColor) {
  7527. pathFillCircle = w.config.series[i].data[dataPointIndex].fillColor;
  7528. }
  7529. }
  7530. el.attr({
  7531. fill: pathFillCircle
  7532. });
  7533. if (w.config.chart.dropShadow.enabled) {
  7534. var dropShadow = w.config.chart.dropShadow;
  7535. filters.dropShadow(el, dropShadow, realIndex);
  7536. }
  7537. if (this.initialAnim && !w.globals.dataChanged && !w.globals.resized) {
  7538. var speed = w.config.chart.animations.speed;
  7539. anim.animateMarker(el, speed, w.globals.easing, function () {
  7540. window.setTimeout(function () {
  7541. anim.animationCompleted(el);
  7542. }, 100);
  7543. });
  7544. } else {
  7545. w.globals.animationEnded = true;
  7546. }
  7547. el.attr({
  7548. rel: dataPointIndex,
  7549. j: dataPointIndex,
  7550. index: realIndex,
  7551. 'default-marker-size': markerConfig.pSize
  7552. });
  7553. filters.setSelectionFilter(el, realIndex, dataPointIndex);
  7554. markers.addEvents(el);
  7555. el.node.classList.add('apexcharts-marker');
  7556. return el;
  7557. }
  7558. }, {
  7559. key: "centerTextInBubble",
  7560. value: function centerTextInBubble(y) {
  7561. var w = this.w;
  7562. y = y + parseInt(w.config.dataLabels.style.fontSize, 10) / 4;
  7563. return {
  7564. y: y
  7565. };
  7566. }
  7567. }]);
  7568. return Scatter;
  7569. }();
  7570. /**
  7571. * ApexCharts DataLabels Class for drawing dataLabels on Axes based Charts.
  7572. *
  7573. * @module DataLabels
  7574. **/
  7575. var DataLabels = /*#__PURE__*/function () {
  7576. function DataLabels(ctx) {
  7577. _classCallCheck(this, DataLabels);
  7578. this.ctx = ctx;
  7579. this.w = ctx.w;
  7580. }
  7581. // 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
  7582. // Also, when datalabels exceeds the drawable area and get clipped off, we need to adjust and move some pixels to make them visible again
  7583. _createClass(DataLabels, [{
  7584. key: "dataLabelsCorrection",
  7585. value: function dataLabelsCorrection(x, y, val, i, dataPointIndex, alwaysDrawDataLabel, fontSize) {
  7586. var w = this.w;
  7587. var graphics = new Graphics(this.ctx);
  7588. var drawnextLabel = false; //
  7589. var textRects = graphics.getTextRects(val, fontSize);
  7590. var width = textRects.width;
  7591. var height = textRects.height;
  7592. if (y < 0) y = 0;
  7593. if (y > w.globals.gridHeight + height) y = w.globals.gridHeight + height / 2;
  7594. // first value in series, so push an empty array
  7595. if (typeof w.globals.dataLabelsRects[i] === 'undefined') w.globals.dataLabelsRects[i] = [];
  7596. // then start pushing actual rects in that sub-array
  7597. w.globals.dataLabelsRects[i].push({
  7598. x: x,
  7599. y: y,
  7600. width: width,
  7601. height: height
  7602. });
  7603. var len = w.globals.dataLabelsRects[i].length - 2;
  7604. var lastDrawnIndex = typeof w.globals.lastDrawnDataLabelsIndexes[i] !== 'undefined' ? w.globals.lastDrawnDataLabelsIndexes[i][w.globals.lastDrawnDataLabelsIndexes[i].length - 1] : 0;
  7605. if (typeof w.globals.dataLabelsRects[i][len] !== 'undefined') {
  7606. var lastDataLabelRect = w.globals.dataLabelsRects[i][lastDrawnIndex];
  7607. if (
  7608. // next label forward and x not intersecting
  7609. 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
  7610. ) {
  7611. // the 2 indexes don't override, so OK to draw next label
  7612. drawnextLabel = true;
  7613. }
  7614. }
  7615. if (dataPointIndex === 0 || alwaysDrawDataLabel) {
  7616. drawnextLabel = true;
  7617. }
  7618. return {
  7619. x: x,
  7620. y: y,
  7621. textRects: textRects,
  7622. drawnextLabel: drawnextLabel
  7623. };
  7624. }
  7625. }, {
  7626. key: "drawDataLabel",
  7627. value: function drawDataLabel(_ref) {
  7628. var _this = this;
  7629. var type = _ref.type,
  7630. pos = _ref.pos,
  7631. i = _ref.i,
  7632. j = _ref.j,
  7633. isRangeStart = _ref.isRangeStart,
  7634. _ref$strokeWidth = _ref.strokeWidth,
  7635. strokeWidth = _ref$strokeWidth === void 0 ? 2 : _ref$strokeWidth;
  7636. // this method handles line, area, bubble, scatter charts as those charts contains markers/points which have pre-defined x/y positions
  7637. // all other charts like radar / bars / heatmaps will define their own drawDataLabel routine
  7638. var w = this.w;
  7639. var graphics = new Graphics(this.ctx);
  7640. var dataLabelsConfig = w.config.dataLabels;
  7641. var x = 0;
  7642. var y = 0;
  7643. var dataPointIndex = j;
  7644. var elDataLabelsWrap = null;
  7645. var seriesCollapsed = w.globals.collapsedSeriesIndices.indexOf(i) !== -1;
  7646. if (seriesCollapsed || !dataLabelsConfig.enabled || !Array.isArray(pos.x)) {
  7647. return elDataLabelsWrap;
  7648. }
  7649. elDataLabelsWrap = graphics.group({
  7650. class: 'apexcharts-data-labels'
  7651. });
  7652. for (var q = 0; q < pos.x.length; q++) {
  7653. x = pos.x[q] + dataLabelsConfig.offsetX;
  7654. y = pos.y[q] + dataLabelsConfig.offsetY + strokeWidth;
  7655. if (!isNaN(x)) {
  7656. // a small hack as we have 2 points for the first val to connect it
  7657. if (j === 1 && q === 0) dataPointIndex = 0;
  7658. if (j === 1 && q === 1) dataPointIndex = 1;
  7659. var val = w.globals.series[i][dataPointIndex];
  7660. if (type === 'rangeArea') {
  7661. if (isRangeStart) {
  7662. val = w.globals.seriesRangeStart[i][dataPointIndex];
  7663. } else {
  7664. val = w.globals.seriesRangeEnd[i][dataPointIndex];
  7665. }
  7666. }
  7667. var text = '';
  7668. var getText = function getText(v) {
  7669. return w.config.dataLabels.formatter(v, {
  7670. ctx: _this.ctx,
  7671. seriesIndex: i,
  7672. dataPointIndex: dataPointIndex,
  7673. w: w
  7674. });
  7675. };
  7676. if (w.config.chart.type === 'bubble') {
  7677. val = w.globals.seriesZ[i][dataPointIndex];
  7678. text = getText(val);
  7679. y = pos.y[q];
  7680. var scatter = new Scatter(this.ctx);
  7681. var centerTextInBubbleCoords = scatter.centerTextInBubble(y, i, dataPointIndex);
  7682. y = centerTextInBubbleCoords.y;
  7683. } else {
  7684. if (typeof val !== 'undefined') {
  7685. text = getText(val);
  7686. }
  7687. }
  7688. var textAnchor = w.config.dataLabels.textAnchor;
  7689. if (w.globals.isSlopeChart) {
  7690. if (dataPointIndex === 0) {
  7691. textAnchor = 'end';
  7692. } else if (dataPointIndex === w.config.series[i].data.length - 1) {
  7693. textAnchor = 'start';
  7694. } else {
  7695. textAnchor = 'middle';
  7696. }
  7697. }
  7698. this.plotDataLabelsText({
  7699. x: x,
  7700. y: y,
  7701. text: text,
  7702. i: i,
  7703. j: dataPointIndex,
  7704. parent: elDataLabelsWrap,
  7705. offsetCorrection: true,
  7706. dataLabelsConfig: w.config.dataLabels,
  7707. textAnchor: textAnchor
  7708. });
  7709. }
  7710. }
  7711. return elDataLabelsWrap;
  7712. }
  7713. }, {
  7714. key: "plotDataLabelsText",
  7715. value: function plotDataLabelsText(opts) {
  7716. var w = this.w;
  7717. var graphics = new Graphics(this.ctx);
  7718. var x = opts.x,
  7719. y = opts.y,
  7720. i = opts.i,
  7721. j = opts.j,
  7722. text = opts.text,
  7723. textAnchor = opts.textAnchor,
  7724. fontSize = opts.fontSize,
  7725. parent = opts.parent,
  7726. dataLabelsConfig = opts.dataLabelsConfig,
  7727. color = opts.color,
  7728. alwaysDrawDataLabel = opts.alwaysDrawDataLabel,
  7729. offsetCorrection = opts.offsetCorrection,
  7730. className = opts.className;
  7731. var dataLabelText = null;
  7732. if (Array.isArray(w.config.dataLabels.enabledOnSeries)) {
  7733. if (w.config.dataLabels.enabledOnSeries.indexOf(i) < 0) {
  7734. return dataLabelText;
  7735. }
  7736. }
  7737. var correctedLabels = {
  7738. x: x,
  7739. y: y,
  7740. drawnextLabel: true,
  7741. textRects: null
  7742. };
  7743. if (offsetCorrection) {
  7744. correctedLabels = this.dataLabelsCorrection(x, y, text, i, j, alwaysDrawDataLabel, parseInt(dataLabelsConfig.style.fontSize, 10));
  7745. }
  7746. // when zoomed, we don't need to correct labels offsets,
  7747. // but if normally, labels get cropped, correct them
  7748. if (!w.globals.zoomed) {
  7749. x = correctedLabels.x;
  7750. y = correctedLabels.y;
  7751. }
  7752. if (correctedLabels.textRects) {
  7753. // fixes #2264
  7754. if (x < -20 - correctedLabels.textRects.width || x > w.globals.gridWidth + correctedLabels.textRects.width + 30) {
  7755. // datalabels fall outside drawing area, so draw a blank label
  7756. text = '';
  7757. }
  7758. }
  7759. var dataLabelColor = w.globals.dataLabels.style.colors[i];
  7760. if ((w.config.chart.type === 'bar' || w.config.chart.type === 'rangeBar') && w.config.plotOptions.bar.distributed || w.config.dataLabels.distributed) {
  7761. dataLabelColor = w.globals.dataLabels.style.colors[j];
  7762. }
  7763. if (typeof dataLabelColor === 'function') {
  7764. dataLabelColor = dataLabelColor({
  7765. series: w.globals.series,
  7766. seriesIndex: i,
  7767. dataPointIndex: j,
  7768. w: w
  7769. });
  7770. }
  7771. if (color) {
  7772. dataLabelColor = color;
  7773. }
  7774. var offX = dataLabelsConfig.offsetX;
  7775. var offY = dataLabelsConfig.offsetY;
  7776. if (w.config.chart.type === 'bar' || w.config.chart.type === 'rangeBar') {
  7777. // for certain chart types, we handle offsets while calculating datalabels pos
  7778. // why? because bars/column may have negative values and based on that
  7779. // offsets becomes reversed
  7780. offX = 0;
  7781. offY = 0;
  7782. }
  7783. if (w.globals.isSlopeChart) {
  7784. if (j !== 0) {
  7785. offX = dataLabelsConfig.offsetX * -2 + 5;
  7786. }
  7787. if (j !== 0 && j !== w.config.series[i].data.length - 1) {
  7788. offX = 0;
  7789. }
  7790. }
  7791. if (correctedLabels.drawnextLabel) {
  7792. dataLabelText = graphics.drawText({
  7793. width: 100,
  7794. height: parseInt(dataLabelsConfig.style.fontSize, 10),
  7795. x: x + offX,
  7796. y: y + offY,
  7797. foreColor: dataLabelColor,
  7798. textAnchor: textAnchor || dataLabelsConfig.textAnchor,
  7799. text: text,
  7800. fontSize: fontSize || dataLabelsConfig.style.fontSize,
  7801. fontFamily: dataLabelsConfig.style.fontFamily,
  7802. fontWeight: dataLabelsConfig.style.fontWeight || 'normal'
  7803. });
  7804. dataLabelText.attr({
  7805. class: className || 'apexcharts-datalabel',
  7806. cx: x,
  7807. cy: y
  7808. });
  7809. if (dataLabelsConfig.dropShadow.enabled) {
  7810. var textShadow = dataLabelsConfig.dropShadow;
  7811. var filters = new Filters(this.ctx);
  7812. filters.dropShadow(dataLabelText, textShadow);
  7813. }
  7814. parent.add(dataLabelText);
  7815. if (typeof w.globals.lastDrawnDataLabelsIndexes[i] === 'undefined') {
  7816. w.globals.lastDrawnDataLabelsIndexes[i] = [];
  7817. }
  7818. w.globals.lastDrawnDataLabelsIndexes[i].push(j);
  7819. }
  7820. return dataLabelText;
  7821. }
  7822. }, {
  7823. key: "addBackgroundToDataLabel",
  7824. value: function addBackgroundToDataLabel(el, coords) {
  7825. var w = this.w;
  7826. var bCnf = w.config.dataLabels.background;
  7827. var paddingH = bCnf.padding;
  7828. var paddingV = bCnf.padding / 2;
  7829. var width = coords.width;
  7830. var height = coords.height;
  7831. var graphics = new Graphics(this.ctx);
  7832. 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);
  7833. if (bCnf.dropShadow.enabled) {
  7834. var filters = new Filters(this.ctx);
  7835. filters.dropShadow(elRect, bCnf.dropShadow);
  7836. }
  7837. return elRect;
  7838. }
  7839. }, {
  7840. key: "dataLabelsBackground",
  7841. value: function dataLabelsBackground() {
  7842. var w = this.w;
  7843. if (w.config.chart.type === 'bubble') return;
  7844. var elDataLabels = w.globals.dom.baseEl.querySelectorAll('.apexcharts-datalabels text');
  7845. for (var i = 0; i < elDataLabels.length; i++) {
  7846. var el = elDataLabels[i];
  7847. var coords = el.getBBox();
  7848. var elRect = null;
  7849. if (coords.width && coords.height) {
  7850. elRect = this.addBackgroundToDataLabel(el, coords);
  7851. }
  7852. if (elRect) {
  7853. el.parentNode.insertBefore(elRect.node, el);
  7854. var background = el.getAttribute('fill');
  7855. var shouldAnim = w.config.chart.animations.enabled && !w.globals.resized && !w.globals.dataChanged;
  7856. if (shouldAnim) {
  7857. elRect.animate().attr({
  7858. fill: background
  7859. });
  7860. } else {
  7861. elRect.attr({
  7862. fill: background
  7863. });
  7864. }
  7865. el.setAttribute('fill', w.config.dataLabels.background.foreColor);
  7866. }
  7867. }
  7868. }
  7869. }, {
  7870. key: "bringForward",
  7871. value: function bringForward() {
  7872. var w = this.w;
  7873. var elDataLabelsNodes = w.globals.dom.baseEl.querySelectorAll('.apexcharts-datalabels');
  7874. var elSeries = w.globals.dom.baseEl.querySelector('.apexcharts-plot-series:last-child');
  7875. for (var i = 0; i < elDataLabelsNodes.length; i++) {
  7876. if (elSeries) {
  7877. elSeries.insertBefore(elDataLabelsNodes[i], elSeries.nextSibling);
  7878. }
  7879. }
  7880. }
  7881. }]);
  7882. return DataLabels;
  7883. }();
  7884. /**
  7885. * ApexCharts Series Class for interaction with the Series of the chart.
  7886. *
  7887. * @module Series
  7888. **/
  7889. var Series = /*#__PURE__*/function () {
  7890. function Series(ctx) {
  7891. _classCallCheck(this, Series);
  7892. this.ctx = ctx;
  7893. this.w = ctx.w;
  7894. this.legendInactiveClass = 'legend-mouseover-inactive';
  7895. }
  7896. _createClass(Series, [{
  7897. key: "getAllSeriesEls",
  7898. value: function getAllSeriesEls() {
  7899. return this.w.globals.dom.baseEl.getElementsByClassName("apexcharts-series");
  7900. }
  7901. }, {
  7902. key: "getSeriesByName",
  7903. value: function getSeriesByName(seriesName) {
  7904. return this.w.globals.dom.baseEl.querySelector(".apexcharts-inner .apexcharts-series[seriesName='".concat(Utils$1.escapeString(seriesName), "']"));
  7905. }
  7906. }, {
  7907. key: "isSeriesHidden",
  7908. value: function isSeriesHidden(seriesName) {
  7909. var targetElement = this.getSeriesByName(seriesName);
  7910. var realIndex = parseInt(targetElement.getAttribute('data:realIndex'), 10);
  7911. var isHidden = targetElement.classList.contains('apexcharts-series-collapsed');
  7912. return {
  7913. isHidden: isHidden,
  7914. realIndex: realIndex
  7915. };
  7916. }
  7917. }, {
  7918. key: "addCollapsedClassToSeries",
  7919. value: function addCollapsedClassToSeries(elSeries, index) {
  7920. var w = this.w;
  7921. function iterateOnAllCollapsedSeries(series) {
  7922. for (var cs = 0; cs < series.length; cs++) {
  7923. if (series[cs].index === index) {
  7924. elSeries.node.classList.add('apexcharts-series-collapsed');
  7925. }
  7926. }
  7927. }
  7928. iterateOnAllCollapsedSeries(w.globals.collapsedSeries);
  7929. iterateOnAllCollapsedSeries(w.globals.ancillaryCollapsedSeries);
  7930. }
  7931. }, {
  7932. key: "toggleSeries",
  7933. value: function toggleSeries(seriesName) {
  7934. var isSeriesHidden = this.isSeriesHidden(seriesName);
  7935. this.ctx.legend.legendHelpers.toggleDataSeries(isSeriesHidden.realIndex, isSeriesHidden.isHidden);
  7936. return isSeriesHidden.isHidden;
  7937. }
  7938. }, {
  7939. key: "showSeries",
  7940. value: function showSeries(seriesName) {
  7941. var isSeriesHidden = this.isSeriesHidden(seriesName);
  7942. if (isSeriesHidden.isHidden) {
  7943. this.ctx.legend.legendHelpers.toggleDataSeries(isSeriesHidden.realIndex, true);
  7944. }
  7945. }
  7946. }, {
  7947. key: "hideSeries",
  7948. value: function hideSeries(seriesName) {
  7949. var isSeriesHidden = this.isSeriesHidden(seriesName);
  7950. if (!isSeriesHidden.isHidden) {
  7951. this.ctx.legend.legendHelpers.toggleDataSeries(isSeriesHidden.realIndex, false);
  7952. }
  7953. }
  7954. }, {
  7955. key: "resetSeries",
  7956. value: function resetSeries() {
  7957. var shouldUpdateChart = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  7958. var shouldResetZoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  7959. var shouldResetCollapsed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  7960. var w = this.w;
  7961. var series = Utils$1.clone(w.globals.initialSeries);
  7962. w.globals.previousPaths = [];
  7963. if (shouldResetCollapsed) {
  7964. w.globals.collapsedSeries = [];
  7965. w.globals.ancillaryCollapsedSeries = [];
  7966. w.globals.collapsedSeriesIndices = [];
  7967. w.globals.ancillaryCollapsedSeriesIndices = [];
  7968. } else {
  7969. series = this.emptyCollapsedSeries(series);
  7970. }
  7971. w.config.series = series;
  7972. if (shouldUpdateChart) {
  7973. if (shouldResetZoom) {
  7974. w.globals.zoomed = false;
  7975. this.ctx.updateHelpers.revertDefaultAxisMinMax();
  7976. }
  7977. this.ctx.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
  7978. }
  7979. }
  7980. }, {
  7981. key: "emptyCollapsedSeries",
  7982. value: function emptyCollapsedSeries(series) {
  7983. var w = this.w;
  7984. for (var i = 0; i < series.length; i++) {
  7985. if (w.globals.collapsedSeriesIndices.indexOf(i) > -1) {
  7986. series[i].data = [];
  7987. }
  7988. }
  7989. return series;
  7990. }
  7991. }, {
  7992. key: "highlightSeries",
  7993. value: function highlightSeries(seriesName) {
  7994. var w = this.w;
  7995. var targetElement = this.getSeriesByName(seriesName);
  7996. var realIndex = parseInt(targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute('data:realIndex'), 10);
  7997. var allSeriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-series, .apexcharts-datalabels, .apexcharts-yaxis");
  7998. var seriesEl = null;
  7999. var dataLabelEl = null;
  8000. var yaxisEl = null;
  8001. if (w.globals.axisCharts || w.config.chart.type === 'radialBar') {
  8002. if (w.globals.axisCharts) {
  8003. seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[data\\:realIndex='".concat(realIndex, "']"));
  8004. dataLabelEl = w.globals.dom.baseEl.querySelector(".apexcharts-datalabels[data\\:realIndex='".concat(realIndex, "']"));
  8005. var yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex];
  8006. yaxisEl = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(yaxisIndex, "']"));
  8007. } else {
  8008. seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[rel='".concat(realIndex + 1, "']"));
  8009. }
  8010. } else {
  8011. seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[rel='".concat(realIndex + 1, "'] path"));
  8012. }
  8013. for (var se = 0; se < allSeriesEls.length; se++) {
  8014. allSeriesEls[se].classList.add(this.legendInactiveClass);
  8015. }
  8016. if (seriesEl) {
  8017. if (!w.globals.axisCharts) {
  8018. seriesEl.parentNode.classList.remove(this.legendInactiveClass);
  8019. }
  8020. seriesEl.classList.remove(this.legendInactiveClass);
  8021. if (dataLabelEl !== null) {
  8022. dataLabelEl.classList.remove(this.legendInactiveClass);
  8023. }
  8024. if (yaxisEl !== null) {
  8025. yaxisEl.classList.remove(this.legendInactiveClass);
  8026. }
  8027. } else {
  8028. for (var _se = 0; _se < allSeriesEls.length; _se++) {
  8029. allSeriesEls[_se].classList.remove(this.legendInactiveClass);
  8030. }
  8031. }
  8032. }
  8033. }, {
  8034. key: "toggleSeriesOnHover",
  8035. value: function toggleSeriesOnHover(e, targetElement) {
  8036. var w = this.w;
  8037. if (!targetElement) targetElement = e.target;
  8038. var allSeriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-series, .apexcharts-datalabels, .apexcharts-yaxis");
  8039. if (e.type === 'mousemove') {
  8040. var realIndex = parseInt(targetElement.getAttribute('rel'), 10) - 1;
  8041. this.highlightSeries(w.globals.seriesNames[realIndex]);
  8042. } else if (e.type === 'mouseout') {
  8043. for (var se = 0; se < allSeriesEls.length; se++) {
  8044. allSeriesEls[se].classList.remove(this.legendInactiveClass);
  8045. }
  8046. }
  8047. }
  8048. }, {
  8049. key: "highlightRangeInSeries",
  8050. value: function highlightRangeInSeries(e, targetElement) {
  8051. var _this = this;
  8052. var w = this.w;
  8053. var allHeatMapElements = w.globals.dom.baseEl.getElementsByClassName('apexcharts-heatmap-rect');
  8054. var activeInactive = function activeInactive(action) {
  8055. for (var i = 0; i < allHeatMapElements.length; i++) {
  8056. allHeatMapElements[i].classList[action](_this.legendInactiveClass);
  8057. }
  8058. };
  8059. var removeInactiveClassFromHoveredRange = function removeInactiveClassFromHoveredRange(range, rangeMax) {
  8060. for (var i = 0; i < allHeatMapElements.length; i++) {
  8061. var val = Number(allHeatMapElements[i].getAttribute('val'));
  8062. if (val >= range.from && (val < range.to || range.to === rangeMax && val === rangeMax)) {
  8063. allHeatMapElements[i].classList.remove(_this.legendInactiveClass);
  8064. }
  8065. }
  8066. };
  8067. if (e.type === 'mousemove') {
  8068. var seriesCnt = parseInt(targetElement.getAttribute('rel'), 10) - 1;
  8069. activeInactive('add');
  8070. var ranges = w.config.plotOptions.heatmap.colorScale.ranges;
  8071. var range = ranges[seriesCnt];
  8072. var rangeMax = ranges.reduce(function (acc, cur) {
  8073. return Math.max(acc, cur.to);
  8074. }, 0);
  8075. removeInactiveClassFromHoveredRange(range, rangeMax);
  8076. } else if (e.type === 'mouseout') {
  8077. activeInactive('remove');
  8078. }
  8079. }
  8080. }, {
  8081. key: "getActiveConfigSeriesIndex",
  8082. value: function getActiveConfigSeriesIndex() {
  8083. var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'asc';
  8084. var chartTypes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  8085. var w = this.w;
  8086. var activeIndex = 0;
  8087. if (w.config.series.length > 1) {
  8088. // active series flag is required to know if user has not deactivated via legend click
  8089. var activeSeriesIndex = w.config.series.map(function (s, index) {
  8090. var checkChartType = function checkChartType() {
  8091. if (w.globals.comboCharts) {
  8092. return chartTypes.length === 0 || chartTypes.length && chartTypes.indexOf(w.config.series[index].type) > -1;
  8093. }
  8094. return true;
  8095. };
  8096. var hasData = s.data && s.data.length > 0 && w.globals.collapsedSeriesIndices.indexOf(index) === -1;
  8097. return hasData && checkChartType() ? index : -1;
  8098. });
  8099. for (var a = order === 'asc' ? 0 : activeSeriesIndex.length - 1; order === 'asc' ? a < activeSeriesIndex.length : a >= 0; order === 'asc' ? a++ : a--) {
  8100. if (activeSeriesIndex[a] !== -1) {
  8101. activeIndex = activeSeriesIndex[a];
  8102. break;
  8103. }
  8104. }
  8105. }
  8106. return activeIndex;
  8107. }
  8108. }, {
  8109. key: "getBarSeriesIndices",
  8110. value: function getBarSeriesIndices() {
  8111. var w = this.w;
  8112. if (w.globals.comboCharts) {
  8113. return this.w.config.series.map(function (s, i) {
  8114. return s.type === 'bar' || s.type === 'column' ? i : -1;
  8115. }).filter(function (i) {
  8116. return i !== -1;
  8117. });
  8118. }
  8119. return this.w.config.series.map(function (s, i) {
  8120. return i;
  8121. });
  8122. }
  8123. }, {
  8124. key: "getPreviousPaths",
  8125. value: function getPreviousPaths() {
  8126. var w = this.w;
  8127. w.globals.previousPaths = [];
  8128. function pushPaths(seriesEls, i, type) {
  8129. var paths = seriesEls[i].childNodes;
  8130. var dArr = {
  8131. type: type,
  8132. paths: [],
  8133. realIndex: seriesEls[i].getAttribute('data:realIndex')
  8134. };
  8135. for (var j = 0; j < paths.length; j++) {
  8136. if (paths[j].hasAttribute('pathTo')) {
  8137. var d = paths[j].getAttribute('pathTo');
  8138. dArr.paths.push({
  8139. d: d
  8140. });
  8141. }
  8142. }
  8143. w.globals.previousPaths.push(dArr);
  8144. }
  8145. var getPaths = function getPaths(chartType) {
  8146. return w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(chartType, "-series .apexcharts-series"));
  8147. };
  8148. var chartTypes = ['line', 'area', 'bar', 'rangebar', 'rangeArea', 'candlestick', 'radar'];
  8149. chartTypes.forEach(function (type) {
  8150. var paths = getPaths(type);
  8151. for (var p = 0; p < paths.length; p++) {
  8152. pushPaths(paths, p, type);
  8153. }
  8154. });
  8155. this.handlePrevBubbleScatterPaths('bubble');
  8156. this.handlePrevBubbleScatterPaths('scatter');
  8157. var heatTreeSeries = w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(w.config.chart.type, " .apexcharts-series"));
  8158. if (heatTreeSeries.length > 0) {
  8159. var _loop = function _loop(h) {
  8160. var seriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(w.config.chart.type, " .apexcharts-series[data\\:realIndex='").concat(h, "'] rect"));
  8161. var dArr = [];
  8162. var _loop2 = function _loop2(i) {
  8163. var getAttr = function getAttr(x) {
  8164. return seriesEls[i].getAttribute(x);
  8165. };
  8166. var rect = {
  8167. x: parseFloat(getAttr('x')),
  8168. y: parseFloat(getAttr('y')),
  8169. width: parseFloat(getAttr('width')),
  8170. height: parseFloat(getAttr('height'))
  8171. };
  8172. dArr.push({
  8173. rect: rect,
  8174. color: seriesEls[i].getAttribute('color')
  8175. });
  8176. };
  8177. for (var i = 0; i < seriesEls.length; i++) {
  8178. _loop2(i);
  8179. }
  8180. w.globals.previousPaths.push(dArr);
  8181. };
  8182. for (var h = 0; h < heatTreeSeries.length; h++) {
  8183. _loop(h);
  8184. }
  8185. }
  8186. if (!w.globals.axisCharts) {
  8187. // for non-axis charts (i.e., circular charts, pathFrom is not usable. We need whole series)
  8188. w.globals.previousPaths = w.globals.series;
  8189. }
  8190. }
  8191. }, {
  8192. key: "handlePrevBubbleScatterPaths",
  8193. value: function handlePrevBubbleScatterPaths(type) {
  8194. var w = this.w;
  8195. var paths = w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(type, "-series .apexcharts-series"));
  8196. if (paths.length > 0) {
  8197. for (var s = 0; s < paths.length; s++) {
  8198. var seriesEls = w.globals.dom.baseEl.querySelectorAll(".apexcharts-".concat(type, "-series .apexcharts-series[data\\:realIndex='").concat(s, "'] circle"));
  8199. var dArr = [];
  8200. for (var i = 0; i < seriesEls.length; i++) {
  8201. dArr.push({
  8202. x: seriesEls[i].getAttribute('cx'),
  8203. y: seriesEls[i].getAttribute('cy'),
  8204. r: seriesEls[i].getAttribute('r')
  8205. });
  8206. }
  8207. w.globals.previousPaths.push(dArr);
  8208. }
  8209. }
  8210. }
  8211. }, {
  8212. key: "clearPreviousPaths",
  8213. value: function clearPreviousPaths() {
  8214. var w = this.w;
  8215. w.globals.previousPaths = [];
  8216. w.globals.allSeriesCollapsed = false;
  8217. }
  8218. }, {
  8219. key: "handleNoData",
  8220. value: function handleNoData() {
  8221. var w = this.w;
  8222. var me = this;
  8223. var noDataOpts = w.config.noData;
  8224. var graphics = new Graphics(me.ctx);
  8225. var x = w.globals.svgWidth / 2;
  8226. var y = w.globals.svgHeight / 2;
  8227. var textAnchor = 'middle';
  8228. w.globals.noData = true;
  8229. w.globals.animationEnded = true;
  8230. if (noDataOpts.align === 'left') {
  8231. x = 10;
  8232. textAnchor = 'start';
  8233. } else if (noDataOpts.align === 'right') {
  8234. x = w.globals.svgWidth - 10;
  8235. textAnchor = 'end';
  8236. }
  8237. if (noDataOpts.verticalAlign === 'top') {
  8238. y = 50;
  8239. } else if (noDataOpts.verticalAlign === 'bottom') {
  8240. y = w.globals.svgHeight - 50;
  8241. }
  8242. x = x + noDataOpts.offsetX;
  8243. y = y + parseInt(noDataOpts.style.fontSize, 10) + 2 + noDataOpts.offsetY;
  8244. if (noDataOpts.text !== undefined && noDataOpts.text !== '') {
  8245. var titleText = graphics.drawText({
  8246. x: x,
  8247. y: y,
  8248. text: noDataOpts.text,
  8249. textAnchor: textAnchor,
  8250. fontSize: noDataOpts.style.fontSize,
  8251. fontFamily: noDataOpts.style.fontFamily,
  8252. foreColor: noDataOpts.style.color,
  8253. opacity: 1,
  8254. class: 'apexcharts-text-nodata'
  8255. });
  8256. w.globals.dom.Paper.add(titleText);
  8257. }
  8258. }
  8259. // When user clicks on legends, the collapsed series is filled with [0,0,0,...,0]
  8260. // This is because we don't want to alter the series' length as it is used at many places
  8261. }, {
  8262. key: "setNullSeriesToZeroValues",
  8263. value: function setNullSeriesToZeroValues(series) {
  8264. var w = this.w;
  8265. for (var sl = 0; sl < series.length; sl++) {
  8266. if (series[sl].length === 0) {
  8267. for (var j = 0; j < series[w.globals.maxValsInArrayIndex].length; j++) {
  8268. series[sl].push(0);
  8269. }
  8270. }
  8271. }
  8272. return series;
  8273. }
  8274. }, {
  8275. key: "hasAllSeriesEqualX",
  8276. value: function hasAllSeriesEqualX() {
  8277. var equalLen = true;
  8278. var w = this.w;
  8279. var filteredSerX = this.filteredSeriesX();
  8280. for (var i = 0; i < filteredSerX.length - 1; i++) {
  8281. if (filteredSerX[i][0] !== filteredSerX[i + 1][0]) {
  8282. equalLen = false;
  8283. break;
  8284. }
  8285. }
  8286. w.globals.allSeriesHasEqualX = equalLen;
  8287. return equalLen;
  8288. }
  8289. }, {
  8290. key: "filteredSeriesX",
  8291. value: function filteredSeriesX() {
  8292. var w = this.w;
  8293. var filteredSeriesX = w.globals.seriesX.map(function (ser) {
  8294. return ser.length > 0 ? ser : [];
  8295. });
  8296. return filteredSeriesX;
  8297. }
  8298. }]);
  8299. return Series;
  8300. }();
  8301. var Data = /*#__PURE__*/function () {
  8302. function Data(ctx) {
  8303. _classCallCheck(this, Data);
  8304. this.ctx = ctx;
  8305. this.w = ctx.w;
  8306. this.twoDSeries = [];
  8307. this.threeDSeries = [];
  8308. this.twoDSeriesX = [];
  8309. this.seriesGoals = [];
  8310. this.coreUtils = new CoreUtils(this.ctx);
  8311. }
  8312. _createClass(Data, [{
  8313. key: "isMultiFormat",
  8314. value: function isMultiFormat() {
  8315. return this.isFormatXY() || this.isFormat2DArray();
  8316. }
  8317. // given format is [{x, y}, {x, y}]
  8318. }, {
  8319. key: "isFormatXY",
  8320. value: function isFormatXY() {
  8321. var series = this.w.config.series.slice();
  8322. var sr = new Series(this.ctx);
  8323. this.activeSeriesIndex = sr.getActiveConfigSeriesIndex();
  8324. 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) {
  8325. return true;
  8326. }
  8327. }
  8328. // given format is [[x, y], [x, y]]
  8329. }, {
  8330. key: "isFormat2DArray",
  8331. value: function isFormat2DArray() {
  8332. var series = this.w.config.series.slice();
  8333. var sr = new Series(this.ctx);
  8334. this.activeSeriesIndex = sr.getActiveConfigSeriesIndex();
  8335. 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) {
  8336. return true;
  8337. }
  8338. }
  8339. }, {
  8340. key: "handleFormat2DArray",
  8341. value: function handleFormat2DArray(ser, i) {
  8342. var cnf = this.w.config;
  8343. var gl = this.w.globals;
  8344. var isBoxPlot = cnf.chart.type === 'boxPlot' || cnf.series[i].type === 'boxPlot';
  8345. for (var j = 0; j < ser[i].data.length; j++) {
  8346. if (typeof ser[i].data[j][1] !== 'undefined') {
  8347. if (Array.isArray(ser[i].data[j][1]) && ser[i].data[j][1].length === 4 && !isBoxPlot) {
  8348. // candlestick nested ohlc format
  8349. this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j][1][3]));
  8350. } else if (ser[i].data[j].length >= 5) {
  8351. // candlestick non-nested ohlc format
  8352. this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j][4]));
  8353. } else {
  8354. this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j][1]));
  8355. }
  8356. gl.dataFormatXNumeric = true;
  8357. }
  8358. if (cnf.xaxis.type === 'datetime') {
  8359. // if timestamps are provided and xaxis type is datetime,
  8360. var ts = new Date(ser[i].data[j][0]);
  8361. ts = new Date(ts).getTime();
  8362. this.twoDSeriesX.push(ts);
  8363. } else {
  8364. this.twoDSeriesX.push(ser[i].data[j][0]);
  8365. }
  8366. }
  8367. for (var _j = 0; _j < ser[i].data.length; _j++) {
  8368. if (typeof ser[i].data[_j][2] !== 'undefined') {
  8369. this.threeDSeries.push(ser[i].data[_j][2]);
  8370. gl.isDataXYZ = true;
  8371. }
  8372. }
  8373. }
  8374. }, {
  8375. key: "handleFormatXY",
  8376. value: function handleFormatXY(ser, i) {
  8377. var cnf = this.w.config;
  8378. var gl = this.w.globals;
  8379. var dt = new DateTime(this.ctx);
  8380. var activeI = i;
  8381. if (gl.collapsedSeriesIndices.indexOf(i) > -1) {
  8382. // fix #368
  8383. activeI = this.activeSeriesIndex;
  8384. }
  8385. // get series
  8386. for (var j = 0; j < ser[i].data.length; j++) {
  8387. if (typeof ser[i].data[j].y !== 'undefined') {
  8388. if (Array.isArray(ser[i].data[j].y)) {
  8389. this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j].y[ser[i].data[j].y.length - 1]));
  8390. } else {
  8391. this.twoDSeries.push(Utils$1.parseNumber(ser[i].data[j].y));
  8392. }
  8393. }
  8394. if (typeof ser[i].data[j].goals !== 'undefined' && Array.isArray(ser[i].data[j].goals)) {
  8395. if (typeof this.seriesGoals[i] === 'undefined') {
  8396. this.seriesGoals[i] = [];
  8397. }
  8398. this.seriesGoals[i].push(ser[i].data[j].goals);
  8399. } else {
  8400. if (typeof this.seriesGoals[i] === 'undefined') {
  8401. this.seriesGoals[i] = [];
  8402. }
  8403. this.seriesGoals[i].push(null);
  8404. }
  8405. }
  8406. // get seriesX
  8407. for (var _j2 = 0; _j2 < ser[activeI].data.length; _j2++) {
  8408. var isXString = typeof ser[activeI].data[_j2].x === 'string';
  8409. var isXArr = Array.isArray(ser[activeI].data[_j2].x);
  8410. var isXDate = !isXArr && !!dt.isValidDate(ser[activeI].data[_j2].x);
  8411. if (isXString || isXDate) {
  8412. // user supplied '01/01/2017' or a date string (a JS date object is not supported)
  8413. if (isXString || cnf.xaxis.convertedCatToNumeric) {
  8414. var isRangeColumn = gl.isBarHorizontal && gl.isRangeData;
  8415. if (cnf.xaxis.type === 'datetime' && !isRangeColumn) {
  8416. this.twoDSeriesX.push(dt.parseDate(ser[activeI].data[_j2].x));
  8417. } else {
  8418. // a category and not a numeric x value
  8419. this.fallbackToCategory = true;
  8420. this.twoDSeriesX.push(ser[activeI].data[_j2].x);
  8421. if (!isNaN(ser[activeI].data[_j2].x) && this.w.config.xaxis.type !== 'category' && typeof ser[activeI].data[_j2].x !== 'string') {
  8422. gl.isXNumeric = true;
  8423. }
  8424. }
  8425. } else {
  8426. if (cnf.xaxis.type === 'datetime') {
  8427. this.twoDSeriesX.push(dt.parseDate(ser[activeI].data[_j2].x.toString()));
  8428. } else {
  8429. gl.dataFormatXNumeric = true;
  8430. gl.isXNumeric = true;
  8431. this.twoDSeriesX.push(parseFloat(ser[activeI].data[_j2].x));
  8432. }
  8433. }
  8434. } else if (isXArr) {
  8435. // a multiline label described in array format
  8436. this.fallbackToCategory = true;
  8437. this.twoDSeriesX.push(ser[activeI].data[_j2].x);
  8438. } else {
  8439. // a numeric value in x property
  8440. gl.isXNumeric = true;
  8441. gl.dataFormatXNumeric = true;
  8442. this.twoDSeriesX.push(ser[activeI].data[_j2].x);
  8443. }
  8444. }
  8445. if (ser[i].data[0] && typeof ser[i].data[0].z !== 'undefined') {
  8446. for (var t = 0; t < ser[i].data.length; t++) {
  8447. this.threeDSeries.push(ser[i].data[t].z);
  8448. }
  8449. gl.isDataXYZ = true;
  8450. }
  8451. }
  8452. }, {
  8453. key: "handleRangeData",
  8454. value: function handleRangeData(ser, i) {
  8455. var gl = this.w.globals;
  8456. var range = {};
  8457. if (this.isFormat2DArray()) {
  8458. range = this.handleRangeDataFormat('array', ser, i);
  8459. } else if (this.isFormatXY()) {
  8460. range = this.handleRangeDataFormat('xy', ser, i);
  8461. }
  8462. // Fix: RangeArea Chart: hide all series results in a crash #3984
  8463. gl.seriesRangeStart.push(range.start === undefined ? [] : range.start);
  8464. gl.seriesRangeEnd.push(range.end === undefined ? [] : range.end);
  8465. gl.seriesRange.push(range.rangeUniques);
  8466. // check for overlaps to avoid clashes in a timeline chart
  8467. gl.seriesRange.forEach(function (sr, si) {
  8468. if (sr) {
  8469. sr.forEach(function (sarr, sarri) {
  8470. sarr.y.forEach(function (arr, arri) {
  8471. for (var sri = 0; sri < sarr.y.length; sri++) {
  8472. if (arri !== sri) {
  8473. var range1y1 = arr.y1;
  8474. var range1y2 = arr.y2;
  8475. var range2y1 = sarr.y[sri].y1;
  8476. var range2y2 = sarr.y[sri].y2;
  8477. if (range1y1 <= range2y2 && range2y1 <= range1y2) {
  8478. if (sarr.overlaps.indexOf(arr.rangeName) < 0) {
  8479. sarr.overlaps.push(arr.rangeName);
  8480. }
  8481. if (sarr.overlaps.indexOf(sarr.y[sri].rangeName) < 0) {
  8482. sarr.overlaps.push(sarr.y[sri].rangeName);
  8483. }
  8484. }
  8485. }
  8486. }
  8487. });
  8488. });
  8489. }
  8490. });
  8491. return range;
  8492. }
  8493. }, {
  8494. key: "handleCandleStickBoxData",
  8495. value: function handleCandleStickBoxData(ser, i) {
  8496. var gl = this.w.globals;
  8497. var ohlc = {};
  8498. if (this.isFormat2DArray()) {
  8499. ohlc = this.handleCandleStickBoxDataFormat('array', ser, i);
  8500. } else if (this.isFormatXY()) {
  8501. ohlc = this.handleCandleStickBoxDataFormat('xy', ser, i);
  8502. }
  8503. gl.seriesCandleO[i] = ohlc.o;
  8504. gl.seriesCandleH[i] = ohlc.h;
  8505. gl.seriesCandleM[i] = ohlc.m;
  8506. gl.seriesCandleL[i] = ohlc.l;
  8507. gl.seriesCandleC[i] = ohlc.c;
  8508. return ohlc;
  8509. }
  8510. }, {
  8511. key: "handleRangeDataFormat",
  8512. value: function handleRangeDataFormat(format, ser, i) {
  8513. var rangeStart = [];
  8514. var rangeEnd = [];
  8515. var uniqueKeys = ser[i].data.filter(function (thing, index, self) {
  8516. return index === self.findIndex(function (t) {
  8517. return t.x === thing.x;
  8518. });
  8519. }).map(function (r, index) {
  8520. return {
  8521. x: r.x,
  8522. overlaps: [],
  8523. y: []
  8524. };
  8525. });
  8526. if (format === 'array') {
  8527. for (var j = 0; j < ser[i].data.length; j++) {
  8528. if (Array.isArray(ser[i].data[j])) {
  8529. rangeStart.push(ser[i].data[j][1][0]);
  8530. rangeEnd.push(ser[i].data[j][1][1]);
  8531. } else {
  8532. rangeStart.push(ser[i].data[j]);
  8533. rangeEnd.push(ser[i].data[j]);
  8534. }
  8535. }
  8536. } else if (format === 'xy') {
  8537. var _loop = function _loop(_j3) {
  8538. var isDataPoint2D = Array.isArray(ser[i].data[_j3].y);
  8539. var id = Utils$1.randomId();
  8540. var x = ser[i].data[_j3].x;
  8541. var y = {
  8542. y1: isDataPoint2D ? ser[i].data[_j3].y[0] : ser[i].data[_j3].y,
  8543. y2: isDataPoint2D ? ser[i].data[_j3].y[1] : ser[i].data[_j3].y,
  8544. rangeName: id
  8545. };
  8546. // CAUTION: mutating config object by adding a new property
  8547. // TODO: As this is specifically for timeline rangebar charts, update the docs mentioning the series only supports xy format
  8548. ser[i].data[_j3].rangeName = id;
  8549. var uI = uniqueKeys.findIndex(function (t) {
  8550. return t.x === x;
  8551. });
  8552. uniqueKeys[uI].y.push(y);
  8553. rangeStart.push(y.y1);
  8554. rangeEnd.push(y.y2);
  8555. };
  8556. for (var _j3 = 0; _j3 < ser[i].data.length; _j3++) {
  8557. _loop(_j3);
  8558. }
  8559. }
  8560. return {
  8561. start: rangeStart,
  8562. end: rangeEnd,
  8563. rangeUniques: uniqueKeys
  8564. };
  8565. }
  8566. }, {
  8567. key: "handleCandleStickBoxDataFormat",
  8568. value: function handleCandleStickBoxDataFormat(format, ser, i) {
  8569. var w = this.w;
  8570. var isBoxPlot = w.config.chart.type === 'boxPlot' || w.config.series[i].type === 'boxPlot';
  8571. var serO = [];
  8572. var serH = [];
  8573. var serM = [];
  8574. var serL = [];
  8575. var serC = [];
  8576. if (format === 'array') {
  8577. if (isBoxPlot && ser[i].data[0].length === 6 || !isBoxPlot && ser[i].data[0].length === 5) {
  8578. for (var j = 0; j < ser[i].data.length; j++) {
  8579. serO.push(ser[i].data[j][1]);
  8580. serH.push(ser[i].data[j][2]);
  8581. if (isBoxPlot) {
  8582. serM.push(ser[i].data[j][3]);
  8583. serL.push(ser[i].data[j][4]);
  8584. serC.push(ser[i].data[j][5]);
  8585. } else {
  8586. serL.push(ser[i].data[j][3]);
  8587. serC.push(ser[i].data[j][4]);
  8588. }
  8589. }
  8590. } else {
  8591. for (var _j4 = 0; _j4 < ser[i].data.length; _j4++) {
  8592. if (Array.isArray(ser[i].data[_j4][1])) {
  8593. serO.push(ser[i].data[_j4][1][0]);
  8594. serH.push(ser[i].data[_j4][1][1]);
  8595. if (isBoxPlot) {
  8596. serM.push(ser[i].data[_j4][1][2]);
  8597. serL.push(ser[i].data[_j4][1][3]);
  8598. serC.push(ser[i].data[_j4][1][4]);
  8599. } else {
  8600. serL.push(ser[i].data[_j4][1][2]);
  8601. serC.push(ser[i].data[_j4][1][3]);
  8602. }
  8603. }
  8604. }
  8605. }
  8606. } else if (format === 'xy') {
  8607. for (var _j5 = 0; _j5 < ser[i].data.length; _j5++) {
  8608. if (Array.isArray(ser[i].data[_j5].y)) {
  8609. serO.push(ser[i].data[_j5].y[0]);
  8610. serH.push(ser[i].data[_j5].y[1]);
  8611. if (isBoxPlot) {
  8612. serM.push(ser[i].data[_j5].y[2]);
  8613. serL.push(ser[i].data[_j5].y[3]);
  8614. serC.push(ser[i].data[_j5].y[4]);
  8615. } else {
  8616. serL.push(ser[i].data[_j5].y[2]);
  8617. serC.push(ser[i].data[_j5].y[3]);
  8618. }
  8619. }
  8620. }
  8621. }
  8622. return {
  8623. o: serO,
  8624. h: serH,
  8625. m: serM,
  8626. l: serL,
  8627. c: serC
  8628. };
  8629. }
  8630. }, {
  8631. key: "parseDataAxisCharts",
  8632. value: function parseDataAxisCharts(ser) {
  8633. var _this = this;
  8634. var ctx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.ctx;
  8635. var cnf = this.w.config;
  8636. var gl = this.w.globals;
  8637. var dt = new DateTime(ctx);
  8638. var xlabels = cnf.labels.length > 0 ? cnf.labels.slice() : cnf.xaxis.categories.slice();
  8639. gl.isRangeBar = cnf.chart.type === 'rangeBar' && gl.isBarHorizontal;
  8640. gl.hasXaxisGroups = cnf.xaxis.type === 'category' && cnf.xaxis.group.groups.length > 0;
  8641. if (gl.hasXaxisGroups) {
  8642. gl.groups = cnf.xaxis.group.groups;
  8643. }
  8644. ser.forEach(function (s, i) {
  8645. if (s.name !== undefined) {
  8646. gl.seriesNames.push(s.name);
  8647. } else {
  8648. gl.seriesNames.push('series-' + parseInt(i + 1, 10));
  8649. }
  8650. });
  8651. this.coreUtils.setSeriesYAxisMappings();
  8652. // At this point, every series that didn't have a user defined group name
  8653. // has been given a name according to the yaxis the series is referenced by.
  8654. // This fits the existing behaviour where all series associated with an axis
  8655. // are defacto presented as a single group. It is now formalised.
  8656. var buckets = [];
  8657. var groups = _toConsumableArray(new Set(cnf.series.map(function (s) {
  8658. return s.group;
  8659. })));
  8660. cnf.series.forEach(function (s, i) {
  8661. var index = groups.indexOf(s.group);
  8662. if (!buckets[index]) buckets[index] = [];
  8663. buckets[index].push(gl.seriesNames[i]);
  8664. });
  8665. gl.seriesGroups = buckets;
  8666. var handleDates = function handleDates() {
  8667. for (var j = 0; j < xlabels.length; j++) {
  8668. if (typeof xlabels[j] === 'string') {
  8669. // user provided date strings
  8670. var isDate = dt.isValidDate(xlabels[j]);
  8671. if (isDate) {
  8672. _this.twoDSeriesX.push(dt.parseDate(xlabels[j]));
  8673. } else {
  8674. throw new Error('You have provided invalid Date format. Please provide a valid JavaScript Date');
  8675. }
  8676. } else {
  8677. // user provided timestamps
  8678. _this.twoDSeriesX.push(xlabels[j]);
  8679. }
  8680. }
  8681. };
  8682. for (var i = 0; i < ser.length; i++) {
  8683. this.twoDSeries = [];
  8684. this.twoDSeriesX = [];
  8685. this.threeDSeries = [];
  8686. if (typeof ser[i].data === 'undefined') {
  8687. console.error("It is a possibility that you may have not included 'data' property in series.");
  8688. return;
  8689. }
  8690. if (cnf.chart.type === 'rangeBar' || cnf.chart.type === 'rangeArea' || ser[i].type === 'rangeBar' || ser[i].type === 'rangeArea') {
  8691. gl.isRangeData = true;
  8692. if (cnf.chart.type === 'rangeBar' || cnf.chart.type === 'rangeArea') {
  8693. this.handleRangeData(ser, i);
  8694. }
  8695. }
  8696. if (this.isMultiFormat()) {
  8697. if (this.isFormat2DArray()) {
  8698. this.handleFormat2DArray(ser, i);
  8699. } else if (this.isFormatXY()) {
  8700. this.handleFormatXY(ser, i);
  8701. }
  8702. if (cnf.chart.type === 'candlestick' || ser[i].type === 'candlestick' || cnf.chart.type === 'boxPlot' || ser[i].type === 'boxPlot') {
  8703. this.handleCandleStickBoxData(ser, i);
  8704. }
  8705. gl.series.push(this.twoDSeries);
  8706. gl.labels.push(this.twoDSeriesX);
  8707. gl.seriesX.push(this.twoDSeriesX);
  8708. gl.seriesGoals = this.seriesGoals;
  8709. if (i === this.activeSeriesIndex && !this.fallbackToCategory) {
  8710. gl.isXNumeric = true;
  8711. }
  8712. } else {
  8713. if (cnf.xaxis.type === 'datetime') {
  8714. // user didn't supplied [{x,y}] or [[x,y]], but single array in data.
  8715. // Also labels/categories were supplied differently
  8716. gl.isXNumeric = true;
  8717. handleDates();
  8718. gl.seriesX.push(this.twoDSeriesX);
  8719. } else if (cnf.xaxis.type === 'numeric') {
  8720. gl.isXNumeric = true;
  8721. if (xlabels.length > 0) {
  8722. this.twoDSeriesX = xlabels;
  8723. gl.seriesX.push(this.twoDSeriesX);
  8724. }
  8725. }
  8726. gl.labels.push(this.twoDSeriesX);
  8727. var singleArray = ser[i].data.map(function (d) {
  8728. return Utils$1.parseNumber(d);
  8729. });
  8730. gl.series.push(singleArray);
  8731. }
  8732. gl.seriesZ.push(this.threeDSeries);
  8733. // overrided default color if user inputs color with series data
  8734. if (ser[i].color !== undefined) {
  8735. gl.seriesColors.push(ser[i].color);
  8736. } else {
  8737. gl.seriesColors.push(undefined);
  8738. }
  8739. }
  8740. return this.w;
  8741. }
  8742. }, {
  8743. key: "parseDataNonAxisCharts",
  8744. value: function parseDataNonAxisCharts(ser) {
  8745. var gl = this.w.globals;
  8746. var cnf = this.w.config;
  8747. gl.series = ser.slice();
  8748. gl.seriesNames = cnf.labels.slice();
  8749. for (var i = 0; i < gl.series.length; i++) {
  8750. if (gl.seriesNames[i] === undefined) {
  8751. gl.seriesNames.push('series-' + (i + 1));
  8752. }
  8753. }
  8754. return this.w;
  8755. }
  8756. /** User possibly set string categories in xaxis.categories or labels prop
  8757. * Or didn't set xaxis labels at all - in which case we manually do it.
  8758. * If user passed series data as [[3, 2], [4, 5]] or [{ x: 3, y: 55 }],
  8759. * this shouldn't be called
  8760. * @param {array} ser - the series which user passed to the config
  8761. */
  8762. }, {
  8763. key: "handleExternalLabelsData",
  8764. value: function handleExternalLabelsData(ser) {
  8765. var cnf = this.w.config;
  8766. var gl = this.w.globals;
  8767. if (cnf.xaxis.categories.length > 0) {
  8768. // user provided labels in xaxis.category prop
  8769. gl.labels = cnf.xaxis.categories;
  8770. } else if (cnf.labels.length > 0) {
  8771. // user provided labels in labels props
  8772. gl.labels = cnf.labels.slice();
  8773. } else if (this.fallbackToCategory) {
  8774. // 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
  8775. gl.labels = gl.labels[0];
  8776. if (gl.seriesRange.length) {
  8777. gl.seriesRange.map(function (srt) {
  8778. srt.forEach(function (sr) {
  8779. if (gl.labels.indexOf(sr.x) < 0 && sr.x) {
  8780. gl.labels.push(sr.x);
  8781. }
  8782. });
  8783. });
  8784. // remove duplicate x-axis labels
  8785. gl.labels = Array.from(new Set(gl.labels.map(JSON.stringify)), JSON.parse);
  8786. }
  8787. if (cnf.xaxis.convertedCatToNumeric) {
  8788. var defaults = new Defaults(cnf);
  8789. defaults.convertCatToNumericXaxis(cnf, this.ctx, gl.seriesX[0]);
  8790. this._generateExternalLabels(ser);
  8791. }
  8792. } else {
  8793. this._generateExternalLabels(ser);
  8794. }
  8795. }
  8796. }, {
  8797. key: "_generateExternalLabels",
  8798. value: function _generateExternalLabels(ser) {
  8799. var gl = this.w.globals;
  8800. var cnf = this.w.config;
  8801. // user didn't provided any labels, fallback to 1-2-3-4-5
  8802. var labelArr = [];
  8803. if (gl.axisCharts) {
  8804. if (gl.series.length > 0) {
  8805. if (this.isFormatXY()) {
  8806. // in case there is a combo chart (boxplot/scatter)
  8807. // and there are duplicated x values, we need to eliminate duplicates
  8808. var seriesDataFiltered = cnf.series.map(function (serie, s) {
  8809. return serie.data.filter(function (v, i, a) {
  8810. return a.findIndex(function (t) {
  8811. return t.x === v.x;
  8812. }) === i;
  8813. });
  8814. });
  8815. var len = seriesDataFiltered.reduce(function (p, c, i, a) {
  8816. return a[p].length > c.length ? p : i;
  8817. }, 0);
  8818. for (var i = 0; i < seriesDataFiltered[len].length; i++) {
  8819. labelArr.push(i + 1);
  8820. }
  8821. } else {
  8822. for (var _i = 0; _i < gl.series[gl.maxValsInArrayIndex].length; _i++) {
  8823. labelArr.push(_i + 1);
  8824. }
  8825. }
  8826. }
  8827. gl.seriesX = [];
  8828. // create gl.seriesX as it will be used in calculations of x positions
  8829. for (var _i2 = 0; _i2 < ser.length; _i2++) {
  8830. gl.seriesX.push(labelArr);
  8831. }
  8832. // turn on the isXNumeric flag to allow minX and maxX to function properly
  8833. if (!this.w.globals.isBarHorizontal) {
  8834. gl.isXNumeric = true;
  8835. }
  8836. }
  8837. // no series to pull labels from, put a 0-10 series
  8838. // possibly, user collapsed all series. Hence we can't work with above calc
  8839. if (labelArr.length === 0) {
  8840. labelArr = gl.axisCharts ? [] : gl.series.map(function (gls, glsi) {
  8841. return glsi + 1;
  8842. });
  8843. for (var _i3 = 0; _i3 < ser.length; _i3++) {
  8844. gl.seriesX.push(labelArr);
  8845. }
  8846. }
  8847. // Finally, pass the labelArr in gl.labels which will be printed on x-axis
  8848. gl.labels = labelArr;
  8849. if (cnf.xaxis.convertedCatToNumeric) {
  8850. gl.categoryLabels = labelArr.map(function (l) {
  8851. return cnf.xaxis.labels.formatter(l);
  8852. });
  8853. }
  8854. // Turn on this global flag to indicate no labels were provided by user
  8855. gl.noLabelsProvided = true;
  8856. }
  8857. // Segregate user provided data into appropriate vars
  8858. }, {
  8859. key: "parseData",
  8860. value: function parseData(ser) {
  8861. var w = this.w;
  8862. var cnf = w.config;
  8863. var gl = w.globals;
  8864. this.excludeCollapsedSeriesInYAxis();
  8865. // If we detected string in X prop of series, we fallback to category x-axis
  8866. this.fallbackToCategory = false;
  8867. this.ctx.core.resetGlobals();
  8868. this.ctx.core.isMultipleY();
  8869. if (gl.axisCharts) {
  8870. // axisCharts includes line / area / column / scatter
  8871. this.parseDataAxisCharts(ser);
  8872. this.coreUtils.getLargestSeries();
  8873. } else {
  8874. // non-axis charts are pie / donut
  8875. this.parseDataNonAxisCharts(ser);
  8876. }
  8877. // set Null values to 0 in all series when user hides/shows some series
  8878. if (cnf.chart.stacked) {
  8879. var series = new Series(this.ctx);
  8880. gl.series = series.setNullSeriesToZeroValues(gl.series);
  8881. }
  8882. this.coreUtils.getSeriesTotals();
  8883. if (gl.axisCharts) {
  8884. gl.stackedSeriesTotals = this.coreUtils.getStackedSeriesTotals();
  8885. gl.stackedSeriesTotalsByGroups = this.coreUtils.getStackedSeriesTotalsByGroups();
  8886. }
  8887. this.coreUtils.getPercentSeries();
  8888. if (!gl.dataFormatXNumeric && (!gl.isXNumeric || cnf.xaxis.type === 'numeric' && cnf.labels.length === 0 && cnf.xaxis.categories.length === 0)) {
  8889. // x-axis labels couldn't be detected; hence try searching every option in config
  8890. this.handleExternalLabelsData(ser);
  8891. }
  8892. // check for multiline xaxis
  8893. var catLabels = this.coreUtils.getCategoryLabels(gl.labels);
  8894. for (var l = 0; l < catLabels.length; l++) {
  8895. if (Array.isArray(catLabels[l])) {
  8896. gl.isMultiLineX = true;
  8897. break;
  8898. }
  8899. }
  8900. }
  8901. }, {
  8902. key: "excludeCollapsedSeriesInYAxis",
  8903. value: function excludeCollapsedSeriesInYAxis() {
  8904. var w = this.w;
  8905. // Post revision 3.46.0 there is no longer a strict one-to-one
  8906. // correspondence between series and Y axes.
  8907. // An axis can be ignored only while all series referenced by it
  8908. // are collapsed.
  8909. var yAxisIndexes = [];
  8910. w.globals.seriesYAxisMap.forEach(function (yAxisArr, yi) {
  8911. var collapsedCount = 0;
  8912. yAxisArr.forEach(function (seriesIndex) {
  8913. if (w.globals.collapsedSeriesIndices.indexOf(seriesIndex) !== -1) {
  8914. collapsedCount++;
  8915. }
  8916. });
  8917. // It's possible to have a yaxis that doesn't reference any series yet,
  8918. // eg, because there are no series' yet, so don't list it as ignored
  8919. // prematurely.
  8920. if (collapsedCount > 0 && collapsedCount == yAxisArr.length) {
  8921. yAxisIndexes.push(yi);
  8922. }
  8923. });
  8924. w.globals.ignoreYAxisIndexes = yAxisIndexes.map(function (x) {
  8925. return x;
  8926. });
  8927. }
  8928. }]);
  8929. return Data;
  8930. }();
  8931. var Exports = /*#__PURE__*/function () {
  8932. function Exports(ctx) {
  8933. _classCallCheck(this, Exports);
  8934. this.ctx = ctx;
  8935. this.w = ctx.w;
  8936. }
  8937. _createClass(Exports, [{
  8938. key: "scaleSvgNode",
  8939. value: function scaleSvgNode(svg, scale) {
  8940. // get current both width and height of the svg
  8941. var svgWidth = parseFloat(svg.getAttributeNS(null, 'width'));
  8942. var svgHeight = parseFloat(svg.getAttributeNS(null, 'height'));
  8943. // set new width and height based on the scale
  8944. svg.setAttributeNS(null, 'width', svgWidth * scale);
  8945. svg.setAttributeNS(null, 'height', svgHeight * scale);
  8946. svg.setAttributeNS(null, 'viewBox', '0 0 ' + svgWidth + ' ' + svgHeight);
  8947. }
  8948. }, {
  8949. key: "getSvgString",
  8950. value: function getSvgString() {
  8951. var _this = this;
  8952. return new Promise(function (resolve) {
  8953. var w = _this.w;
  8954. var width = w.config.chart.toolbar.export.width;
  8955. var scale = w.config.chart.toolbar.export.scale || width / w.globals.svgWidth;
  8956. if (!scale) {
  8957. scale = 1; // if no scale is specified, don't scale...
  8958. }
  8959. var svgString = _this.w.globals.dom.Paper.svg();
  8960. // clone the svg node so it remains intact in the UI
  8961. var svgNode = _this.w.globals.dom.Paper.node.cloneNode(true);
  8962. // in case the scale is different than 1, the svg needs to be rescaled
  8963. if (scale !== 1) {
  8964. // scale the image
  8965. _this.scaleSvgNode(svgNode, scale);
  8966. }
  8967. // Convert image URLs to base64
  8968. _this.convertImagesToBase64(svgNode).then(function () {
  8969. svgString = new XMLSerializer().serializeToString(svgNode);
  8970. resolve(svgString.replace(/&nbsp;/g, '&#160;'));
  8971. });
  8972. });
  8973. }
  8974. }, {
  8975. key: "convertImagesToBase64",
  8976. value: function convertImagesToBase64(svgNode) {
  8977. var _this2 = this;
  8978. var images = svgNode.getElementsByTagName('image');
  8979. var promises = Array.from(images).map(function (img) {
  8980. var href = img.getAttributeNS('http://www.w3.org/1999/xlink', 'href');
  8981. if (href && !href.startsWith('data:')) {
  8982. return _this2.getBase64FromUrl(href).then(function (base64) {
  8983. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', base64);
  8984. }).catch(function (error) {
  8985. console.error('Error converting image to base64:', error);
  8986. });
  8987. }
  8988. return Promise.resolve();
  8989. });
  8990. return Promise.all(promises);
  8991. }
  8992. }, {
  8993. key: "getBase64FromUrl",
  8994. value: function getBase64FromUrl(url) {
  8995. return new Promise(function (resolve, reject) {
  8996. var img = new Image();
  8997. img.crossOrigin = 'Anonymous';
  8998. img.onload = function () {
  8999. var canvas = document.createElement('canvas');
  9000. canvas.width = img.width;
  9001. canvas.height = img.height;
  9002. var ctx = canvas.getContext('2d');
  9003. ctx.drawImage(img, 0, 0);
  9004. resolve(canvas.toDataURL());
  9005. };
  9006. img.onerror = reject;
  9007. img.src = url;
  9008. });
  9009. }
  9010. }, {
  9011. key: "cleanup",
  9012. value: function cleanup() {
  9013. var w = this.w;
  9014. // hide some elements to avoid printing them on exported svg
  9015. var xcrosshairs = w.globals.dom.baseEl.getElementsByClassName('apexcharts-xcrosshairs');
  9016. var ycrosshairs = w.globals.dom.baseEl.getElementsByClassName('apexcharts-ycrosshairs');
  9017. var zoomSelectionRects = w.globals.dom.baseEl.querySelectorAll('.apexcharts-zoom-rect, .apexcharts-selection-rect');
  9018. Array.prototype.forEach.call(zoomSelectionRects, function (z) {
  9019. z.setAttribute('width', 0);
  9020. });
  9021. if (xcrosshairs && xcrosshairs[0]) {
  9022. xcrosshairs[0].setAttribute('x', -500);
  9023. xcrosshairs[0].setAttribute('x1', -500);
  9024. xcrosshairs[0].setAttribute('x2', -500);
  9025. }
  9026. if (ycrosshairs && ycrosshairs[0]) {
  9027. ycrosshairs[0].setAttribute('y', -100);
  9028. ycrosshairs[0].setAttribute('y1', -100);
  9029. ycrosshairs[0].setAttribute('y2', -100);
  9030. }
  9031. }
  9032. }, {
  9033. key: "svgUrl",
  9034. value: function svgUrl() {
  9035. var _this3 = this;
  9036. return new Promise(function (resolve) {
  9037. _this3.cleanup();
  9038. _this3.getSvgString().then(function (svgData) {
  9039. var svgBlob = new Blob([svgData], {
  9040. type: 'image/svg+xml;charset=utf-8'
  9041. });
  9042. resolve(URL.createObjectURL(svgBlob));
  9043. });
  9044. });
  9045. }
  9046. }, {
  9047. key: "dataURI",
  9048. value: function dataURI(options) {
  9049. var _this4 = this;
  9050. return new Promise(function (resolve) {
  9051. var w = _this4.w;
  9052. var scale = options ? options.scale || options.width / w.globals.svgWidth : 1;
  9053. _this4.cleanup();
  9054. var canvas = document.createElement('canvas');
  9055. canvas.width = w.globals.svgWidth * scale;
  9056. canvas.height = parseInt(w.globals.dom.elWrap.style.height, 10) * scale; // because of resizeNonAxisCharts
  9057. var canvasBg = w.config.chart.background === 'transparent' || !w.config.chart.background ? '#fff' : w.config.chart.background;
  9058. var ctx = canvas.getContext('2d');
  9059. ctx.fillStyle = canvasBg;
  9060. ctx.fillRect(0, 0, canvas.width * scale, canvas.height * scale);
  9061. _this4.getSvgString().then(function (svgData) {
  9062. var svgUrl = 'data:image/svg+xml,' + encodeURIComponent(svgData);
  9063. var img = new Image();
  9064. img.crossOrigin = 'anonymous';
  9065. img.onload = function () {
  9066. ctx.drawImage(img, 0, 0);
  9067. if (canvas.msToBlob) {
  9068. // Microsoft Edge can't navigate to data urls, so we return the blob instead
  9069. var blob = canvas.msToBlob();
  9070. resolve({
  9071. blob: blob
  9072. });
  9073. } else {
  9074. var imgURI = canvas.toDataURL('image/png');
  9075. resolve({
  9076. imgURI: imgURI
  9077. });
  9078. }
  9079. };
  9080. img.src = svgUrl;
  9081. });
  9082. });
  9083. }
  9084. }, {
  9085. key: "exportToSVG",
  9086. value: function exportToSVG() {
  9087. var _this5 = this;
  9088. this.svgUrl().then(function (url) {
  9089. _this5.triggerDownload(url, _this5.w.config.chart.toolbar.export.svg.filename, '.svg');
  9090. });
  9091. }
  9092. }, {
  9093. key: "exportToPng",
  9094. value: function exportToPng() {
  9095. var _this6 = this;
  9096. var scale = this.w.config.chart.toolbar.export.scale;
  9097. var width = this.w.config.chart.toolbar.export.width;
  9098. var option = scale ? {
  9099. scale: scale
  9100. } : width ? {
  9101. width: width
  9102. } : undefined;
  9103. this.dataURI(option).then(function (_ref) {
  9104. var imgURI = _ref.imgURI,
  9105. blob = _ref.blob;
  9106. if (blob) {
  9107. navigator.msSaveOrOpenBlob(blob, _this6.w.globals.chartID + '.png');
  9108. } else {
  9109. _this6.triggerDownload(imgURI, _this6.w.config.chart.toolbar.export.png.filename, '.png');
  9110. }
  9111. });
  9112. }
  9113. }, {
  9114. key: "exportToCSV",
  9115. value: function exportToCSV(_ref2) {
  9116. var _this7 = this;
  9117. var series = _ref2.series,
  9118. fileName = _ref2.fileName,
  9119. _ref2$columnDelimiter = _ref2.columnDelimiter,
  9120. columnDelimiter = _ref2$columnDelimiter === void 0 ? ',' : _ref2$columnDelimiter,
  9121. _ref2$lineDelimiter = _ref2.lineDelimiter,
  9122. lineDelimiter = _ref2$lineDelimiter === void 0 ? '\n' : _ref2$lineDelimiter;
  9123. var w = this.w;
  9124. if (!series) series = w.config.series;
  9125. var columns = [];
  9126. var rows = [];
  9127. var result = '';
  9128. var universalBOM = "\uFEFF";
  9129. var gSeries = w.globals.series.map(function (s, i) {
  9130. return w.globals.collapsedSeriesIndices.indexOf(i) === -1 ? s : [];
  9131. });
  9132. var getFormattedCategory = function getFormattedCategory(cat) {
  9133. if (typeof w.config.chart.toolbar.export.csv.categoryFormatter === 'function') {
  9134. return w.config.chart.toolbar.export.csv.categoryFormatter(cat);
  9135. }
  9136. if (w.config.xaxis.type === 'datetime' && String(cat).length >= 10) {
  9137. return new Date(cat).toDateString();
  9138. }
  9139. return Utils$1.isNumber(cat) ? cat : cat.split(columnDelimiter).join('');
  9140. };
  9141. var getFormattedValue = function getFormattedValue(value) {
  9142. return typeof w.config.chart.toolbar.export.csv.valueFormatter === 'function' ? w.config.chart.toolbar.export.csv.valueFormatter(value) : value;
  9143. };
  9144. var seriesMaxDataLength = Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
  9145. return s.data ? s.data.length : 0;
  9146. })));
  9147. var dataFormat = new Data(this.ctx);
  9148. var axesUtils = new AxesUtils(this.ctx);
  9149. var getCat = function getCat(i) {
  9150. var cat = '';
  9151. // pie / donut/ radial
  9152. if (!w.globals.axisCharts) {
  9153. cat = w.config.labels[i];
  9154. } else {
  9155. // xy charts
  9156. // non datetime
  9157. if (w.config.xaxis.type === 'category' || w.config.xaxis.convertedCatToNumeric) {
  9158. if (w.globals.isBarHorizontal) {
  9159. var lbFormatter = w.globals.yLabelFormatters[0];
  9160. var sr = new Series(_this7.ctx);
  9161. var activeSeries = sr.getActiveConfigSeriesIndex();
  9162. cat = lbFormatter(w.globals.labels[i], {
  9163. seriesIndex: activeSeries,
  9164. dataPointIndex: i,
  9165. w: w
  9166. });
  9167. } else {
  9168. cat = axesUtils.getLabel(w.globals.labels, w.globals.timescaleLabels, 0, i).text;
  9169. }
  9170. }
  9171. // datetime, but labels specified in categories or labels
  9172. if (w.config.xaxis.type === 'datetime') {
  9173. if (w.config.xaxis.categories.length) {
  9174. cat = w.config.xaxis.categories[i];
  9175. } else if (w.config.labels.length) {
  9176. cat = w.config.labels[i];
  9177. }
  9178. }
  9179. }
  9180. // let the caller know the current category is null. this can happen for example
  9181. // when dealing with line charts having inconsistent time series data
  9182. if (cat === null) return 'nullvalue';
  9183. if (Array.isArray(cat)) {
  9184. cat = cat.join(' ');
  9185. }
  9186. return Utils$1.isNumber(cat) ? cat : cat.split(columnDelimiter).join('');
  9187. };
  9188. // Fix https://github.com/apexcharts/apexcharts.js/issues/3365
  9189. var getEmptyDataForCsvColumn = function getEmptyDataForCsvColumn() {
  9190. return _toConsumableArray(Array(seriesMaxDataLength)).map(function () {
  9191. return '';
  9192. });
  9193. };
  9194. var handleAxisRowsColumns = function handleAxisRowsColumns(s, sI) {
  9195. if (columns.length && sI === 0) {
  9196. // It's the first series. Go ahead and create the first row with header information.
  9197. rows.push(columns.join(columnDelimiter));
  9198. }
  9199. if (s.data) {
  9200. // Use the data we have, or generate a properly sized empty array with empty data if some data is missing.
  9201. s.data = s.data.length && s.data || getEmptyDataForCsvColumn();
  9202. for (var i = 0; i < s.data.length; i++) {
  9203. // Reset the columns array so that we can start building columns for this row.
  9204. columns = [];
  9205. var cat = getCat(i);
  9206. // current category is null, let's move on to the next one
  9207. if (cat === 'nullvalue') continue;
  9208. if (!cat) {
  9209. if (dataFormat.isFormatXY()) {
  9210. cat = series[sI].data[i].x;
  9211. } else if (dataFormat.isFormat2DArray()) {
  9212. cat = series[sI].data[i] ? series[sI].data[i][0] : '';
  9213. }
  9214. }
  9215. if (sI === 0) {
  9216. // It's the first series. Also handle the category.
  9217. columns.push(getFormattedCategory(cat));
  9218. for (var ci = 0; ci < w.globals.series.length; ci++) {
  9219. var _series$ci$data$i;
  9220. 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];
  9221. columns.push(getFormattedValue(value));
  9222. }
  9223. }
  9224. if (w.config.chart.type === 'candlestick' || s.type && s.type === 'candlestick') {
  9225. columns.pop();
  9226. columns.push(w.globals.seriesCandleO[sI][i]);
  9227. columns.push(w.globals.seriesCandleH[sI][i]);
  9228. columns.push(w.globals.seriesCandleL[sI][i]);
  9229. columns.push(w.globals.seriesCandleC[sI][i]);
  9230. }
  9231. if (w.config.chart.type === 'boxPlot' || s.type && s.type === 'boxPlot') {
  9232. columns.pop();
  9233. columns.push(w.globals.seriesCandleO[sI][i]);
  9234. columns.push(w.globals.seriesCandleH[sI][i]);
  9235. columns.push(w.globals.seriesCandleM[sI][i]);
  9236. columns.push(w.globals.seriesCandleL[sI][i]);
  9237. columns.push(w.globals.seriesCandleC[sI][i]);
  9238. }
  9239. if (w.config.chart.type === 'rangeBar') {
  9240. columns.pop();
  9241. columns.push(w.globals.seriesRangeStart[sI][i]);
  9242. columns.push(w.globals.seriesRangeEnd[sI][i]);
  9243. }
  9244. if (columns.length) {
  9245. rows.push(columns.join(columnDelimiter));
  9246. }
  9247. }
  9248. }
  9249. };
  9250. var handleUnequalXValues = function handleUnequalXValues() {
  9251. var categories = new Set();
  9252. var data = {};
  9253. series.forEach(function (s, sI) {
  9254. s === null || s === void 0 ? void 0 : s.data.forEach(function (dataItem) {
  9255. var cat, value;
  9256. if (dataFormat.isFormatXY()) {
  9257. cat = dataItem.x;
  9258. value = dataItem.y;
  9259. } else if (dataFormat.isFormat2DArray()) {
  9260. cat = dataItem[0];
  9261. value = dataItem[1];
  9262. } else {
  9263. return;
  9264. }
  9265. if (!data[cat]) {
  9266. data[cat] = Array(series.length).fill('');
  9267. }
  9268. data[cat][sI] = getFormattedValue(value);
  9269. categories.add(cat);
  9270. });
  9271. });
  9272. if (columns.length) {
  9273. rows.push(columns.join(columnDelimiter));
  9274. }
  9275. Array.from(categories).sort().forEach(function (cat) {
  9276. rows.push([getFormattedCategory(cat), data[cat].join(columnDelimiter)]);
  9277. });
  9278. };
  9279. columns.push(w.config.chart.toolbar.export.csv.headerCategory);
  9280. if (w.config.chart.type === 'boxPlot') {
  9281. columns.push('minimum');
  9282. columns.push('q1');
  9283. columns.push('median');
  9284. columns.push('q3');
  9285. columns.push('maximum');
  9286. } else if (w.config.chart.type === 'candlestick') {
  9287. columns.push('open');
  9288. columns.push('high');
  9289. columns.push('low');
  9290. columns.push('close');
  9291. } else if (w.config.chart.type === 'rangeBar') {
  9292. columns.push('minimum');
  9293. columns.push('maximum');
  9294. } else {
  9295. series.map(function (s, sI) {
  9296. var sname = (s.name ? s.name : "series-".concat(sI)) + '';
  9297. if (w.globals.axisCharts) {
  9298. columns.push(sname.split(columnDelimiter).join('') ? sname.split(columnDelimiter).join('') : "series-".concat(sI));
  9299. }
  9300. });
  9301. }
  9302. if (!w.globals.axisCharts) {
  9303. columns.push(w.config.chart.toolbar.export.csv.headerValue);
  9304. rows.push(columns.join(columnDelimiter));
  9305. }
  9306. if (!w.globals.allSeriesHasEqualX && w.globals.axisCharts && !w.config.xaxis.categories.length && !w.config.labels.length) {
  9307. handleUnequalXValues();
  9308. } else {
  9309. series.map(function (s, sI) {
  9310. if (w.globals.axisCharts) {
  9311. handleAxisRowsColumns(s, sI);
  9312. } else {
  9313. columns = [];
  9314. columns.push(getFormattedCategory(w.globals.labels[sI]));
  9315. columns.push(getFormattedValue(gSeries[sI]));
  9316. rows.push(columns.join(columnDelimiter));
  9317. }
  9318. });
  9319. }
  9320. result += rows.join(lineDelimiter);
  9321. this.triggerDownload('data:text/csv; charset=utf-8,' + encodeURIComponent(universalBOM + result), fileName ? fileName : w.config.chart.toolbar.export.csv.filename, '.csv');
  9322. }
  9323. }, {
  9324. key: "triggerDownload",
  9325. value: function triggerDownload(href, filename, ext) {
  9326. var downloadLink = document.createElement('a');
  9327. downloadLink.href = href;
  9328. downloadLink.download = (filename ? filename : this.w.globals.chartID) + ext;
  9329. document.body.appendChild(downloadLink);
  9330. downloadLink.click();
  9331. document.body.removeChild(downloadLink);
  9332. }
  9333. }]);
  9334. return Exports;
  9335. }();
  9336. /**
  9337. * ApexCharts XAxis Class for drawing X-Axis.
  9338. *
  9339. * @module XAxis
  9340. **/
  9341. var XAxis = /*#__PURE__*/function () {
  9342. function XAxis(ctx, elgrid) {
  9343. _classCallCheck(this, XAxis);
  9344. this.ctx = ctx;
  9345. this.elgrid = elgrid;
  9346. this.w = ctx.w;
  9347. var w = this.w;
  9348. this.axesUtils = new AxesUtils(ctx);
  9349. this.xaxisLabels = w.globals.labels.slice();
  9350. if (w.globals.timescaleLabels.length > 0 && !w.globals.isBarHorizontal) {
  9351. // timeline labels are there and chart is not rangeabr timeline
  9352. this.xaxisLabels = w.globals.timescaleLabels.slice();
  9353. }
  9354. if (w.config.xaxis.overwriteCategories) {
  9355. this.xaxisLabels = w.config.xaxis.overwriteCategories;
  9356. }
  9357. this.drawnLabels = [];
  9358. this.drawnLabelsRects = [];
  9359. if (w.config.xaxis.position === 'top') {
  9360. this.offY = 0;
  9361. } else {
  9362. this.offY = w.globals.gridHeight;
  9363. }
  9364. this.offY = this.offY + w.config.xaxis.axisBorder.offsetY;
  9365. this.isCategoryBarHorizontal = w.config.chart.type === 'bar' && w.config.plotOptions.bar.horizontal;
  9366. this.xaxisFontSize = w.config.xaxis.labels.style.fontSize;
  9367. this.xaxisFontFamily = w.config.xaxis.labels.style.fontFamily;
  9368. this.xaxisForeColors = w.config.xaxis.labels.style.colors;
  9369. this.xaxisBorderWidth = w.config.xaxis.axisBorder.width;
  9370. if (this.isCategoryBarHorizontal) {
  9371. this.xaxisBorderWidth = w.config.yaxis[0].axisBorder.width.toString();
  9372. }
  9373. if (this.xaxisBorderWidth.indexOf('%') > -1) {
  9374. this.xaxisBorderWidth = w.globals.gridWidth * parseInt(this.xaxisBorderWidth, 10) / 100;
  9375. } else {
  9376. this.xaxisBorderWidth = parseInt(this.xaxisBorderWidth, 10);
  9377. }
  9378. this.xaxisBorderHeight = w.config.xaxis.axisBorder.height;
  9379. // For bars, we will only consider single y xais,
  9380. // as we are not providing multiple yaxis for bar charts
  9381. this.yaxis = w.config.yaxis[0];
  9382. }
  9383. _createClass(XAxis, [{
  9384. key: "drawXaxis",
  9385. value: function drawXaxis() {
  9386. var w = this.w;
  9387. var graphics = new Graphics(this.ctx);
  9388. var elXaxis = graphics.group({
  9389. class: 'apexcharts-xaxis',
  9390. transform: "translate(".concat(w.config.xaxis.offsetX, ", ").concat(w.config.xaxis.offsetY, ")")
  9391. });
  9392. var elXaxisTexts = graphics.group({
  9393. class: 'apexcharts-xaxis-texts-g',
  9394. transform: "translate(".concat(w.globals.translateXAxisX, ", ").concat(w.globals.translateXAxisY, ")")
  9395. });
  9396. elXaxis.add(elXaxisTexts);
  9397. var labels = [];
  9398. for (var i = 0; i < this.xaxisLabels.length; i++) {
  9399. labels.push(this.xaxisLabels[i]);
  9400. }
  9401. this.drawXAxisLabelAndGroup(true, graphics, elXaxisTexts, labels, w.globals.isXNumeric, function (i, colWidth) {
  9402. return colWidth;
  9403. });
  9404. if (w.globals.hasXaxisGroups) {
  9405. var labelsGroup = w.globals.groups;
  9406. labels = [];
  9407. for (var _i = 0; _i < labelsGroup.length; _i++) {
  9408. labels.push(labelsGroup[_i].title);
  9409. }
  9410. var overwriteStyles = {};
  9411. if (w.config.xaxis.group.style) {
  9412. overwriteStyles.xaxisFontSize = w.config.xaxis.group.style.fontSize;
  9413. overwriteStyles.xaxisFontFamily = w.config.xaxis.group.style.fontFamily;
  9414. overwriteStyles.xaxisForeColors = w.config.xaxis.group.style.colors;
  9415. overwriteStyles.fontWeight = w.config.xaxis.group.style.fontWeight;
  9416. overwriteStyles.cssClass = w.config.xaxis.group.style.cssClass;
  9417. }
  9418. this.drawXAxisLabelAndGroup(false, graphics, elXaxisTexts, labels, false, function (i, colWidth) {
  9419. return labelsGroup[i].cols * colWidth;
  9420. }, overwriteStyles);
  9421. }
  9422. if (w.config.xaxis.title.text !== undefined) {
  9423. var elXaxisTitle = graphics.group({
  9424. class: 'apexcharts-xaxis-title'
  9425. });
  9426. var elXAxisTitleText = graphics.drawText({
  9427. x: w.globals.gridWidth / 2 + w.config.xaxis.title.offsetX,
  9428. y: this.offY + parseFloat(this.xaxisFontSize) + (w.config.xaxis.position === 'bottom' ? w.globals.xAxisLabelsHeight : -w.globals.xAxisLabelsHeight - 10) + w.config.xaxis.title.offsetY,
  9429. text: w.config.xaxis.title.text,
  9430. textAnchor: 'middle',
  9431. fontSize: w.config.xaxis.title.style.fontSize,
  9432. fontFamily: w.config.xaxis.title.style.fontFamily,
  9433. fontWeight: w.config.xaxis.title.style.fontWeight,
  9434. foreColor: w.config.xaxis.title.style.color,
  9435. cssClass: 'apexcharts-xaxis-title-text ' + w.config.xaxis.title.style.cssClass
  9436. });
  9437. elXaxisTitle.add(elXAxisTitleText);
  9438. elXaxis.add(elXaxisTitle);
  9439. }
  9440. if (w.config.xaxis.axisBorder.show) {
  9441. var offX = w.globals.barPadForNumericAxis;
  9442. 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);
  9443. if (this.elgrid && this.elgrid.elGridBorders && w.config.grid.show) {
  9444. this.elgrid.elGridBorders.add(elHorzLine);
  9445. } else {
  9446. elXaxis.add(elHorzLine);
  9447. }
  9448. }
  9449. return elXaxis;
  9450. }
  9451. }, {
  9452. key: "drawXAxisLabelAndGroup",
  9453. value: function drawXAxisLabelAndGroup(isLeafGroup, graphics, elXaxisTexts, labels, isXNumeric, colWidthCb) {
  9454. var _this = this;
  9455. var overwriteStyles = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
  9456. var drawnLabels = [];
  9457. var drawnLabelsRects = [];
  9458. var w = this.w;
  9459. var xaxisFontSize = overwriteStyles.xaxisFontSize || this.xaxisFontSize;
  9460. var xaxisFontFamily = overwriteStyles.xaxisFontFamily || this.xaxisFontFamily;
  9461. var xaxisForeColors = overwriteStyles.xaxisForeColors || this.xaxisForeColors;
  9462. var fontWeight = overwriteStyles.fontWeight || w.config.xaxis.labels.style.fontWeight;
  9463. var cssClass = overwriteStyles.cssClass || w.config.xaxis.labels.style.cssClass;
  9464. var colWidth;
  9465. // initial x Position (keep adding column width in the loop)
  9466. var xPos = w.globals.padHorizontal;
  9467. var labelsLen = labels.length;
  9468. /**
  9469. * labelsLen can be different (whether you are drawing x-axis labels or x-axis group labels)
  9470. * hence, we introduce dataPoints to be consistent.
  9471. * Also, in datetime/numeric xaxis, dataPoints can be misleading, so we resort to labelsLen for such xaxis type
  9472. */
  9473. var dataPoints = w.config.xaxis.type === 'category' ? w.globals.dataPoints : labelsLen;
  9474. // when all series are collapsed, fixes #3381
  9475. if (dataPoints === 0 && labelsLen > dataPoints) dataPoints = labelsLen;
  9476. if (isXNumeric) {
  9477. var len = dataPoints > 1 ? dataPoints - 1 : dataPoints;
  9478. colWidth = w.globals.gridWidth / Math.min(len, labelsLen - 1);
  9479. xPos = xPos + colWidthCb(0, colWidth) / 2 + w.config.xaxis.labels.offsetX;
  9480. } else {
  9481. colWidth = w.globals.gridWidth / dataPoints;
  9482. xPos = xPos + colWidthCb(0, colWidth) + w.config.xaxis.labels.offsetX;
  9483. }
  9484. var _loop = function _loop(i) {
  9485. var x = xPos - colWidthCb(i, colWidth) / 2 + w.config.xaxis.labels.offsetX;
  9486. if (i === 0 && labelsLen === 1 && colWidth / 2 === xPos && dataPoints === 1) {
  9487. // single datapoint
  9488. x = w.globals.gridWidth / 2;
  9489. }
  9490. var label = _this.axesUtils.getLabel(labels, w.globals.timescaleLabels, x, i, drawnLabels, xaxisFontSize, isLeafGroup);
  9491. var offsetYCorrection = 28;
  9492. if (w.globals.rotateXLabels && isLeafGroup) {
  9493. offsetYCorrection = 22;
  9494. }
  9495. if (w.config.xaxis.title.text && w.config.xaxis.position === 'top') {
  9496. offsetYCorrection += parseFloat(w.config.xaxis.title.style.fontSize) + 2;
  9497. }
  9498. if (!isLeafGroup) {
  9499. offsetYCorrection = offsetYCorrection + parseFloat(xaxisFontSize) + (w.globals.xAxisLabelsHeight - w.globals.xAxisGroupLabelsHeight) + (w.globals.rotateXLabels ? 10 : 0);
  9500. }
  9501. var isCategoryTickAmounts = typeof w.config.xaxis.tickAmount !== 'undefined' && w.config.xaxis.tickAmount !== 'dataPoints' && w.config.xaxis.type !== 'datetime';
  9502. if (isCategoryTickAmounts) {
  9503. label = _this.axesUtils.checkLabelBasedOnTickamount(i, label, labelsLen);
  9504. } else {
  9505. label = _this.axesUtils.checkForOverflowingLabels(i, label, labelsLen, drawnLabels, drawnLabelsRects);
  9506. }
  9507. var getCatForeColor = function getCatForeColor() {
  9508. return isLeafGroup && w.config.xaxis.convertedCatToNumeric ? xaxisForeColors[w.globals.minX + i - 1] : xaxisForeColors[i];
  9509. };
  9510. if (w.config.xaxis.labels.show) {
  9511. var elText = graphics.drawText({
  9512. x: label.x,
  9513. y: _this.offY + w.config.xaxis.labels.offsetY + offsetYCorrection - (w.config.xaxis.position === 'top' ? w.globals.xAxisHeight + w.config.xaxis.axisTicks.height - 2 : 0),
  9514. text: label.text,
  9515. textAnchor: 'middle',
  9516. fontWeight: label.isBold ? 600 : fontWeight,
  9517. fontSize: xaxisFontSize,
  9518. fontFamily: xaxisFontFamily,
  9519. foreColor: Array.isArray(xaxisForeColors) ? getCatForeColor() : xaxisForeColors,
  9520. isPlainText: false,
  9521. cssClass: (isLeafGroup ? 'apexcharts-xaxis-label ' : 'apexcharts-xaxis-group-label ') + cssClass
  9522. });
  9523. elXaxisTexts.add(elText);
  9524. elText.on('click', function (e) {
  9525. if (typeof w.config.chart.events.xAxisLabelClick === 'function') {
  9526. var opts = Object.assign({}, w, {
  9527. labelIndex: i
  9528. });
  9529. w.config.chart.events.xAxisLabelClick(e, _this.ctx, opts);
  9530. }
  9531. });
  9532. if (isLeafGroup) {
  9533. var elTooltipTitle = document.createElementNS(w.globals.SVGNS, 'title');
  9534. elTooltipTitle.textContent = Array.isArray(label.text) ? label.text.join(' ') : label.text;
  9535. elText.node.appendChild(elTooltipTitle);
  9536. if (label.text !== '') {
  9537. drawnLabels.push(label.text);
  9538. drawnLabelsRects.push(label);
  9539. }
  9540. }
  9541. }
  9542. if (i < labelsLen - 1) {
  9543. xPos = xPos + colWidthCb(i + 1, colWidth);
  9544. }
  9545. };
  9546. for (var i = 0; i <= labelsLen - 1; i++) {
  9547. _loop(i);
  9548. }
  9549. }
  9550. // this actually becomes the vertical axis (for bar charts)
  9551. }, {
  9552. key: "drawXaxisInversed",
  9553. value: function drawXaxisInversed(realIndex) {
  9554. var _this2 = this;
  9555. var w = this.w;
  9556. var graphics = new Graphics(this.ctx);
  9557. var translateYAxisX = w.config.yaxis[0].opposite ? w.globals.translateYAxisX[realIndex] : 0;
  9558. var elYaxis = graphics.group({
  9559. class: 'apexcharts-yaxis apexcharts-xaxis-inversed',
  9560. rel: realIndex
  9561. });
  9562. var elYaxisTexts = graphics.group({
  9563. class: 'apexcharts-yaxis-texts-g apexcharts-xaxis-inversed-texts-g',
  9564. transform: 'translate(' + translateYAxisX + ', 0)'
  9565. });
  9566. elYaxis.add(elYaxisTexts);
  9567. var colHeight;
  9568. // initial x Position (keep adding column width in the loop)
  9569. var yPos;
  9570. var labels = [];
  9571. if (w.config.yaxis[realIndex].show) {
  9572. for (var i = 0; i < this.xaxisLabels.length; i++) {
  9573. labels.push(this.xaxisLabels[i]);
  9574. }
  9575. }
  9576. colHeight = w.globals.gridHeight / labels.length;
  9577. yPos = -(colHeight / 2.2);
  9578. var lbFormatter = w.globals.yLabelFormatters[0];
  9579. var ylabels = w.config.yaxis[0].labels;
  9580. if (ylabels.show) {
  9581. var _loop2 = function _loop2(_i2) {
  9582. var label = typeof labels[_i2] === 'undefined' ? '' : labels[_i2];
  9583. label = lbFormatter(label, {
  9584. seriesIndex: realIndex,
  9585. dataPointIndex: _i2,
  9586. w: w
  9587. });
  9588. var yColors = _this2.axesUtils.getYAxisForeColor(ylabels.style.colors, realIndex);
  9589. var getForeColor = function getForeColor() {
  9590. return Array.isArray(yColors) ? yColors[_i2] : yColors;
  9591. };
  9592. var multiY = 0;
  9593. if (Array.isArray(label)) {
  9594. multiY = label.length / 2 * parseInt(ylabels.style.fontSize, 10);
  9595. }
  9596. var offsetX = ylabels.offsetX - 15;
  9597. var textAnchor = 'end';
  9598. if (_this2.yaxis.opposite) {
  9599. textAnchor = 'start';
  9600. }
  9601. if (w.config.yaxis[0].labels.align === 'left') {
  9602. offsetX = ylabels.offsetX;
  9603. textAnchor = 'start';
  9604. } else if (w.config.yaxis[0].labels.align === 'center') {
  9605. offsetX = ylabels.offsetX;
  9606. textAnchor = 'middle';
  9607. } else if (w.config.yaxis[0].labels.align === 'right') {
  9608. textAnchor = 'end';
  9609. }
  9610. var elLabel = graphics.drawText({
  9611. x: offsetX,
  9612. y: yPos + colHeight + ylabels.offsetY - multiY,
  9613. text: label,
  9614. textAnchor: textAnchor,
  9615. foreColor: getForeColor(),
  9616. fontSize: ylabels.style.fontSize,
  9617. fontFamily: ylabels.style.fontFamily,
  9618. fontWeight: ylabels.style.fontWeight,
  9619. isPlainText: false,
  9620. cssClass: 'apexcharts-yaxis-label ' + ylabels.style.cssClass,
  9621. maxWidth: ylabels.maxWidth
  9622. });
  9623. elYaxisTexts.add(elLabel);
  9624. elLabel.on('click', function (e) {
  9625. if (typeof w.config.chart.events.xAxisLabelClick === 'function') {
  9626. var opts = Object.assign({}, w, {
  9627. labelIndex: _i2
  9628. });
  9629. w.config.chart.events.xAxisLabelClick(e, _this2.ctx, opts);
  9630. }
  9631. });
  9632. var elTooltipTitle = document.createElementNS(w.globals.SVGNS, 'title');
  9633. elTooltipTitle.textContent = Array.isArray(label) ? label.join(' ') : label;
  9634. elLabel.node.appendChild(elTooltipTitle);
  9635. if (w.config.yaxis[realIndex].labels.rotate !== 0) {
  9636. var labelRotatingCenter = graphics.rotateAroundCenter(elLabel.node);
  9637. elLabel.node.setAttribute('transform', "rotate(".concat(w.config.yaxis[realIndex].labels.rotate, " 0 ").concat(labelRotatingCenter.y, ")"));
  9638. }
  9639. yPos = yPos + colHeight;
  9640. };
  9641. for (var _i2 = 0; _i2 <= labels.length - 1; _i2++) {
  9642. _loop2(_i2);
  9643. }
  9644. }
  9645. if (w.config.yaxis[0].title.text !== undefined) {
  9646. var elXaxisTitle = graphics.group({
  9647. class: 'apexcharts-yaxis-title apexcharts-xaxis-title-inversed',
  9648. transform: 'translate(' + translateYAxisX + ', 0)'
  9649. });
  9650. var elXAxisTitleText = graphics.drawText({
  9651. x: w.config.yaxis[0].title.offsetX,
  9652. y: w.globals.gridHeight / 2 + w.config.yaxis[0].title.offsetY,
  9653. text: w.config.yaxis[0].title.text,
  9654. textAnchor: 'middle',
  9655. foreColor: w.config.yaxis[0].title.style.color,
  9656. fontSize: w.config.yaxis[0].title.style.fontSize,
  9657. fontWeight: w.config.yaxis[0].title.style.fontWeight,
  9658. fontFamily: w.config.yaxis[0].title.style.fontFamily,
  9659. cssClass: 'apexcharts-yaxis-title-text ' + w.config.yaxis[0].title.style.cssClass
  9660. });
  9661. elXaxisTitle.add(elXAxisTitleText);
  9662. elYaxis.add(elXaxisTitle);
  9663. }
  9664. var offX = 0;
  9665. if (this.isCategoryBarHorizontal && w.config.yaxis[0].opposite) {
  9666. offX = w.globals.gridWidth;
  9667. }
  9668. var axisBorder = w.config.xaxis.axisBorder;
  9669. if (axisBorder.show) {
  9670. 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);
  9671. if (this.elgrid && this.elgrid.elGridBorders && w.config.grid.show) {
  9672. this.elgrid.elGridBorders.add(elVerticalLine);
  9673. } else {
  9674. elYaxis.add(elVerticalLine);
  9675. }
  9676. }
  9677. if (w.config.yaxis[0].axisTicks.show) {
  9678. this.axesUtils.drawYAxisTicks(offX, labels.length, w.config.yaxis[0].axisBorder, w.config.yaxis[0].axisTicks, 0, colHeight, elYaxis);
  9679. }
  9680. return elYaxis;
  9681. }
  9682. }, {
  9683. key: "drawXaxisTicks",
  9684. value: function drawXaxisTicks(x1, y2, appendToElement) {
  9685. var w = this.w;
  9686. var x2 = x1;
  9687. if (x1 < 0 || x1 - 2 > w.globals.gridWidth) return;
  9688. var y1 = this.offY + w.config.xaxis.axisTicks.offsetY;
  9689. y2 = y2 + y1 + w.config.xaxis.axisTicks.height;
  9690. if (w.config.xaxis.position === 'top') {
  9691. y2 = y1 - w.config.xaxis.axisTicks.height;
  9692. }
  9693. if (w.config.xaxis.axisTicks.show) {
  9694. var graphics = new Graphics(this.ctx);
  9695. 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);
  9696. // we are not returning anything, but appending directly to the element passed in param
  9697. appendToElement.add(line);
  9698. line.node.classList.add('apexcharts-xaxis-tick');
  9699. }
  9700. }
  9701. }, {
  9702. key: "getXAxisTicksPositions",
  9703. value: function getXAxisTicksPositions() {
  9704. var w = this.w;
  9705. var xAxisTicksPositions = [];
  9706. var xCount = this.xaxisLabels.length;
  9707. var x1 = w.globals.padHorizontal;
  9708. if (w.globals.timescaleLabels.length > 0) {
  9709. for (var i = 0; i < xCount; i++) {
  9710. x1 = this.xaxisLabels[i].position;
  9711. xAxisTicksPositions.push(x1);
  9712. }
  9713. } else {
  9714. var xCountForCategoryCharts = xCount;
  9715. for (var _i3 = 0; _i3 < xCountForCategoryCharts; _i3++) {
  9716. var x1Count = xCountForCategoryCharts;
  9717. if (w.globals.isXNumeric && w.config.chart.type !== 'bar') {
  9718. x1Count -= 1;
  9719. }
  9720. x1 = x1 + w.globals.gridWidth / x1Count;
  9721. xAxisTicksPositions.push(x1);
  9722. }
  9723. }
  9724. return xAxisTicksPositions;
  9725. }
  9726. // to rotate x-axis labels or to put ... for longer text in xaxis
  9727. }, {
  9728. key: "xAxisLabelCorrections",
  9729. value: function xAxisLabelCorrections() {
  9730. var w = this.w;
  9731. var graphics = new Graphics(this.ctx);
  9732. var xAxis = w.globals.dom.baseEl.querySelector('.apexcharts-xaxis-texts-g');
  9733. var xAxisTexts = w.globals.dom.baseEl.querySelectorAll('.apexcharts-xaxis-texts-g text:not(.apexcharts-xaxis-group-label)');
  9734. var yAxisTextsInversed = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxis-inversed text');
  9735. var xAxisTextsInversed = w.globals.dom.baseEl.querySelectorAll('.apexcharts-xaxis-inversed-texts-g text tspan');
  9736. if (w.globals.rotateXLabels || w.config.xaxis.labels.rotateAlways) {
  9737. for (var xat = 0; xat < xAxisTexts.length; xat++) {
  9738. var textRotatingCenter = graphics.rotateAroundCenter(xAxisTexts[xat]);
  9739. textRotatingCenter.y = textRotatingCenter.y - 1; // + tickWidth/4;
  9740. textRotatingCenter.x = textRotatingCenter.x + 1;
  9741. xAxisTexts[xat].setAttribute('transform', "rotate(".concat(w.config.xaxis.labels.rotate, " ").concat(textRotatingCenter.x, " ").concat(textRotatingCenter.y, ")"));
  9742. xAxisTexts[xat].setAttribute('text-anchor', "end");
  9743. var offsetHeight = 10;
  9744. xAxis.setAttribute('transform', "translate(0, ".concat(-offsetHeight, ")"));
  9745. var tSpan = xAxisTexts[xat].childNodes;
  9746. if (w.config.xaxis.labels.trim) {
  9747. Array.prototype.forEach.call(tSpan, function (ts) {
  9748. graphics.placeTextWithEllipsis(ts, ts.textContent, w.globals.xAxisLabelsHeight - (w.config.legend.position === 'bottom' ? 20 : 10));
  9749. });
  9750. }
  9751. }
  9752. } else {
  9753. (function () {
  9754. var width = w.globals.gridWidth / (w.globals.labels.length + 1);
  9755. for (var _xat = 0; _xat < xAxisTexts.length; _xat++) {
  9756. var _tSpan = xAxisTexts[_xat].childNodes;
  9757. if (w.config.xaxis.labels.trim && w.config.xaxis.type !== 'datetime') {
  9758. Array.prototype.forEach.call(_tSpan, function (ts) {
  9759. graphics.placeTextWithEllipsis(ts, ts.textContent, width);
  9760. });
  9761. }
  9762. }
  9763. })();
  9764. }
  9765. if (yAxisTextsInversed.length > 0) {
  9766. // truncate rotated y axis in bar chart (x axis)
  9767. var firstLabelPosX = yAxisTextsInversed[yAxisTextsInversed.length - 1].getBBox();
  9768. var lastLabelPosX = yAxisTextsInversed[0].getBBox();
  9769. if (firstLabelPosX.x < -20) {
  9770. yAxisTextsInversed[yAxisTextsInversed.length - 1].parentNode.removeChild(yAxisTextsInversed[yAxisTextsInversed.length - 1]);
  9771. }
  9772. if (lastLabelPosX.x + lastLabelPosX.width > w.globals.gridWidth && !w.globals.isBarHorizontal) {
  9773. yAxisTextsInversed[0].parentNode.removeChild(yAxisTextsInversed[0]);
  9774. }
  9775. // truncate rotated x axis in bar chart (y axis)
  9776. for (var _xat2 = 0; _xat2 < xAxisTextsInversed.length; _xat2++) {
  9777. 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);
  9778. }
  9779. }
  9780. }
  9781. // renderXAxisBands() {
  9782. // let w = this.w;
  9783. // let plotBand = document.createElementNS(w.globals.SVGNS, 'rect')
  9784. // w.globals.dom.elGraphical.add(plotBand)
  9785. // }
  9786. }]);
  9787. return XAxis;
  9788. }();
  9789. /**
  9790. * ApexCharts Grid Class for drawing Cartesian Grid.
  9791. *
  9792. * @module Grid
  9793. **/
  9794. var Grid = /*#__PURE__*/function () {
  9795. function Grid(ctx) {
  9796. _classCallCheck(this, Grid);
  9797. this.ctx = ctx;
  9798. this.w = ctx.w;
  9799. var w = this.w;
  9800. this.xaxisLabels = w.globals.labels.slice();
  9801. this.axesUtils = new AxesUtils(ctx);
  9802. this.isRangeBar = w.globals.seriesRange.length && w.globals.isBarHorizontal;
  9803. if (w.globals.timescaleLabels.length > 0) {
  9804. // timescaleLabels labels are there
  9805. this.xaxisLabels = w.globals.timescaleLabels.slice();
  9806. }
  9807. }
  9808. _createClass(Grid, [{
  9809. key: "drawGridArea",
  9810. value: function drawGridArea() {
  9811. var elGrid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  9812. var w = this.w;
  9813. var graphics = new Graphics(this.ctx);
  9814. if (!elGrid) {
  9815. elGrid = graphics.group({
  9816. class: 'apexcharts-grid'
  9817. });
  9818. }
  9819. var elVerticalLine = graphics.drawLine(w.globals.padHorizontal, 1, w.globals.padHorizontal, w.globals.gridHeight, 'transparent');
  9820. var elHorzLine = graphics.drawLine(w.globals.padHorizontal, w.globals.gridHeight, w.globals.gridWidth, w.globals.gridHeight, 'transparent');
  9821. elGrid.add(elHorzLine);
  9822. elGrid.add(elVerticalLine);
  9823. return elGrid;
  9824. }
  9825. }, {
  9826. key: "drawGrid",
  9827. value: function drawGrid() {
  9828. var gl = this.w.globals;
  9829. if (gl.axisCharts) {
  9830. var elgrid = this.renderGrid();
  9831. this.drawGridArea(elgrid.el);
  9832. return elgrid;
  9833. }
  9834. return null;
  9835. }
  9836. }, {
  9837. key: "createGridMask",
  9838. value: function createGridMask() {
  9839. var w = this.w;
  9840. var gl = w.globals;
  9841. var graphics = new Graphics(this.ctx);
  9842. var strokeSize = Array.isArray(w.config.stroke.width) ? Math.max.apply(Math, _toConsumableArray(w.config.stroke.width)) : w.config.stroke.width;
  9843. var createClipPath = function createClipPath(id) {
  9844. var clipPath = document.createElementNS(gl.SVGNS, 'clipPath');
  9845. clipPath.setAttribute('id', id);
  9846. return clipPath;
  9847. };
  9848. gl.dom.elGridRectMask = createClipPath("gridRectMask".concat(gl.cuid));
  9849. gl.dom.elGridRectBarMask = createClipPath("gridRectBarMask".concat(gl.cuid));
  9850. gl.dom.elGridRectMarkerMask = createClipPath("gridRectMarkerMask".concat(gl.cuid));
  9851. gl.dom.elForecastMask = createClipPath("forecastMask".concat(gl.cuid));
  9852. gl.dom.elNonForecastMask = createClipPath("nonForecastMask".concat(gl.cuid));
  9853. var hasBar = ['bar', 'rangeBar', 'candlestick', 'boxPlot'].includes(w.config.chart.type) || w.globals.comboBarCount > 0;
  9854. var barWidthLeft = 0;
  9855. var barWidthRight = 0;
  9856. if (hasBar && w.globals.isXNumeric && !w.globals.isBarHorizontal) {
  9857. barWidthLeft = Math.max(w.config.grid.padding.left, gl.barPadForNumericAxis);
  9858. barWidthRight = Math.max(w.config.grid.padding.right, gl.barPadForNumericAxis);
  9859. }
  9860. gl.dom.elGridRect = graphics.drawRect(0, 0, gl.gridWidth, gl.gridHeight, 0, '#fff');
  9861. gl.dom.elGridRectBar = graphics.drawRect(-strokeSize / 2 - barWidthLeft - 2, -strokeSize / 2 - 2, gl.gridWidth + strokeSize + barWidthRight + barWidthLeft + 4, gl.gridHeight + strokeSize + 4, 0, '#fff');
  9862. var markerSize = w.globals.markers.largestSize;
  9863. gl.dom.elGridRectMarker = graphics.drawRect(-markerSize, -markerSize, gl.gridWidth + markerSize * 2, gl.gridHeight + markerSize * 2, 0, '#fff');
  9864. gl.dom.elGridRectMask.appendChild(gl.dom.elGridRect.node);
  9865. gl.dom.elGridRectBarMask.appendChild(gl.dom.elGridRectBar.node);
  9866. gl.dom.elGridRectMarkerMask.appendChild(gl.dom.elGridRectMarker.node);
  9867. var defs = gl.dom.baseEl.querySelector('defs');
  9868. defs.appendChild(gl.dom.elGridRectMask);
  9869. defs.appendChild(gl.dom.elGridRectBarMask);
  9870. defs.appendChild(gl.dom.elGridRectMarkerMask);
  9871. defs.appendChild(gl.dom.elForecastMask);
  9872. defs.appendChild(gl.dom.elNonForecastMask);
  9873. }
  9874. }, {
  9875. key: "_drawGridLines",
  9876. value: function _drawGridLines(_ref) {
  9877. var i = _ref.i,
  9878. x1 = _ref.x1,
  9879. y1 = _ref.y1,
  9880. x2 = _ref.x2,
  9881. y2 = _ref.y2,
  9882. xCount = _ref.xCount,
  9883. parent = _ref.parent;
  9884. var w = this.w;
  9885. var shouldDraw = function shouldDraw() {
  9886. if (i === 0 && w.globals.skipFirstTimelinelabel) return false;
  9887. if (i === xCount - 1 && w.globals.skipLastTimelinelabel && !w.config.xaxis.labels.formatter) return false;
  9888. if (w.config.chart.type === 'radar') return false;
  9889. return true;
  9890. };
  9891. if (shouldDraw()) {
  9892. if (w.config.grid.xaxis.lines.show) {
  9893. this._drawGridLine({
  9894. i: i,
  9895. x1: x1,
  9896. y1: y1,
  9897. x2: x2,
  9898. y2: y2,
  9899. xCount: xCount,
  9900. parent: parent
  9901. });
  9902. }
  9903. var y_2 = 0;
  9904. if (w.globals.hasXaxisGroups && w.config.xaxis.tickPlacement === 'between') {
  9905. var groups = w.globals.groups;
  9906. if (groups) {
  9907. var gacc = 0;
  9908. for (var gi = 0; gacc < i && gi < groups.length; gi++) {
  9909. gacc += groups[gi].cols;
  9910. }
  9911. if (gacc === i) {
  9912. y_2 = w.globals.xAxisLabelsHeight * 0.6;
  9913. }
  9914. }
  9915. }
  9916. var xAxis = new XAxis(this.ctx);
  9917. xAxis.drawXaxisTicks(x1, y_2, w.globals.dom.elGraphical);
  9918. }
  9919. }
  9920. }, {
  9921. key: "_drawGridLine",
  9922. value: function _drawGridLine(_ref2) {
  9923. var i = _ref2.i,
  9924. x1 = _ref2.x1,
  9925. y1 = _ref2.y1,
  9926. x2 = _ref2.x2,
  9927. y2 = _ref2.y2,
  9928. xCount = _ref2.xCount,
  9929. parent = _ref2.parent;
  9930. var w = this.w;
  9931. var isHorzLine = parent.node.classList.contains('apexcharts-gridlines-horizontal');
  9932. var offX = w.globals.barPadForNumericAxis;
  9933. 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);
  9934. var graphics = new Graphics(this);
  9935. var line = graphics.drawLine(x1 - (isHorzLine ? offX : 0), y1, x2 + (isHorzLine ? offX : 0), y2, w.config.grid.borderColor, w.config.grid.strokeDashArray);
  9936. line.node.classList.add('apexcharts-gridline');
  9937. if (excludeBorders && w.config.grid.show) {
  9938. this.elGridBorders.add(line);
  9939. } else {
  9940. parent.add(line);
  9941. }
  9942. }
  9943. }, {
  9944. key: "_drawGridBandRect",
  9945. value: function _drawGridBandRect(_ref3) {
  9946. var c = _ref3.c,
  9947. x1 = _ref3.x1,
  9948. y1 = _ref3.y1,
  9949. x2 = _ref3.x2,
  9950. y2 = _ref3.y2,
  9951. type = _ref3.type;
  9952. var w = this.w;
  9953. var graphics = new Graphics(this.ctx);
  9954. var offX = w.globals.barPadForNumericAxis;
  9955. var color = w.config.grid[type].colors[c];
  9956. var rect = graphics.drawRect(x1 - (type === 'row' ? offX : 0), y1, x2 + (type === 'row' ? offX * 2 : 0), y2, 0, color, w.config.grid[type].opacity);
  9957. this.elg.add(rect);
  9958. rect.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
  9959. rect.node.classList.add("apexcharts-grid-".concat(type));
  9960. }
  9961. }, {
  9962. key: "_drawXYLines",
  9963. value: function _drawXYLines(_ref4) {
  9964. var _this = this;
  9965. var xCount = _ref4.xCount,
  9966. tickAmount = _ref4.tickAmount;
  9967. var w = this.w;
  9968. var datetimeLines = function datetimeLines(_ref5) {
  9969. var xC = _ref5.xC,
  9970. x1 = _ref5.x1,
  9971. y1 = _ref5.y1,
  9972. x2 = _ref5.x2,
  9973. y2 = _ref5.y2;
  9974. for (var i = 0; i < xC; i++) {
  9975. x1 = _this.xaxisLabels[i].position;
  9976. x2 = _this.xaxisLabels[i].position;
  9977. _this._drawGridLines({
  9978. i: i,
  9979. x1: x1,
  9980. y1: y1,
  9981. x2: x2,
  9982. y2: y2,
  9983. xCount: xCount,
  9984. parent: _this.elgridLinesV
  9985. });
  9986. }
  9987. };
  9988. var categoryLines = function categoryLines(_ref6) {
  9989. var xC = _ref6.xC,
  9990. x1 = _ref6.x1,
  9991. y1 = _ref6.y1,
  9992. x2 = _ref6.x2,
  9993. y2 = _ref6.y2;
  9994. for (var i = 0; i < xC + (w.globals.isXNumeric ? 0 : 1); i++) {
  9995. if (i === 0 && xC === 1 && w.globals.dataPoints === 1) {
  9996. x1 = w.globals.gridWidth / 2;
  9997. x2 = x1;
  9998. }
  9999. _this._drawGridLines({
  10000. i: i,
  10001. x1: x1,
  10002. y1: y1,
  10003. x2: x2,
  10004. y2: y2,
  10005. xCount: xCount,
  10006. parent: _this.elgridLinesV
  10007. });
  10008. x1 += w.globals.gridWidth / (w.globals.isXNumeric ? xC - 1 : xC);
  10009. x2 = x1;
  10010. }
  10011. };
  10012. if (w.config.grid.xaxis.lines.show || w.config.xaxis.axisTicks.show) {
  10013. var x1 = w.globals.padHorizontal;
  10014. var y1 = 0;
  10015. var x2;
  10016. var y2 = w.globals.gridHeight;
  10017. if (w.globals.timescaleLabels.length) {
  10018. datetimeLines({
  10019. xC: xCount,
  10020. x1: x1,
  10021. y1: y1,
  10022. x2: x2,
  10023. y2: y2
  10024. });
  10025. } else {
  10026. if (w.globals.isXNumeric) {
  10027. xCount = w.globals.xAxisScale.result.length;
  10028. }
  10029. categoryLines({
  10030. xC: xCount,
  10031. x1: x1,
  10032. y1: y1,
  10033. x2: x2,
  10034. y2: y2
  10035. });
  10036. }
  10037. }
  10038. if (w.config.grid.yaxis.lines.show) {
  10039. var _x = 0;
  10040. var _y = 0;
  10041. var _y2 = 0;
  10042. var _x2 = w.globals.gridWidth;
  10043. var tA = tickAmount + 1;
  10044. if (this.isRangeBar) {
  10045. tA = w.globals.labels.length;
  10046. }
  10047. for (var i = 0; i < tA + (this.isRangeBar ? 1 : 0); i++) {
  10048. this._drawGridLine({
  10049. i: i,
  10050. xCount: tA + (this.isRangeBar ? 1 : 0),
  10051. x1: _x,
  10052. y1: _y,
  10053. x2: _x2,
  10054. y2: _y2,
  10055. parent: this.elgridLinesH
  10056. });
  10057. _y += w.globals.gridHeight / (this.isRangeBar ? tA : tickAmount);
  10058. _y2 = _y;
  10059. }
  10060. }
  10061. }
  10062. }, {
  10063. key: "_drawInvertedXYLines",
  10064. value: function _drawInvertedXYLines(_ref7) {
  10065. var xCount = _ref7.xCount;
  10066. var w = this.w;
  10067. if (w.config.grid.xaxis.lines.show || w.config.xaxis.axisTicks.show) {
  10068. var x1 = w.globals.padHorizontal;
  10069. var y1 = 0;
  10070. var x2;
  10071. var y2 = w.globals.gridHeight;
  10072. for (var i = 0; i < xCount + 1; i++) {
  10073. if (w.config.grid.xaxis.lines.show) {
  10074. this._drawGridLine({
  10075. i: i,
  10076. xCount: xCount + 1,
  10077. x1: x1,
  10078. y1: y1,
  10079. x2: x2,
  10080. y2: y2,
  10081. parent: this.elgridLinesV
  10082. });
  10083. }
  10084. var xAxis = new XAxis(this.ctx);
  10085. xAxis.drawXaxisTicks(x1, 0, w.globals.dom.elGraphical);
  10086. x1 += w.globals.gridWidth / xCount;
  10087. x2 = x1;
  10088. }
  10089. }
  10090. if (w.config.grid.yaxis.lines.show) {
  10091. var _x3 = 0;
  10092. var _y3 = 0;
  10093. var _y4 = 0;
  10094. var _x4 = w.globals.gridWidth;
  10095. for (var _i = 0; _i < w.globals.dataPoints + 1; _i++) {
  10096. this._drawGridLine({
  10097. i: _i,
  10098. xCount: w.globals.dataPoints + 1,
  10099. x1: _x3,
  10100. y1: _y3,
  10101. x2: _x4,
  10102. y2: _y4,
  10103. parent: this.elgridLinesH
  10104. });
  10105. _y3 += w.globals.gridHeight / w.globals.dataPoints;
  10106. _y4 = _y3;
  10107. }
  10108. }
  10109. }
  10110. }, {
  10111. key: "renderGrid",
  10112. value: function renderGrid() {
  10113. var w = this.w;
  10114. var gl = w.globals;
  10115. var graphics = new Graphics(this.ctx);
  10116. this.elg = graphics.group({
  10117. class: 'apexcharts-grid'
  10118. });
  10119. this.elgridLinesH = graphics.group({
  10120. class: 'apexcharts-gridlines-horizontal'
  10121. });
  10122. this.elgridLinesV = graphics.group({
  10123. class: 'apexcharts-gridlines-vertical'
  10124. });
  10125. this.elGridBorders = graphics.group({
  10126. class: 'apexcharts-grid-borders'
  10127. });
  10128. this.elg.add(this.elgridLinesH);
  10129. this.elg.add(this.elgridLinesV);
  10130. if (!w.config.grid.show) {
  10131. this.elgridLinesV.hide();
  10132. this.elgridLinesH.hide();
  10133. this.elGridBorders.hide();
  10134. }
  10135. var gridAxisIndex = 0;
  10136. while (gridAxisIndex < gl.seriesYAxisMap.length && gl.ignoreYAxisIndexes.includes(gridAxisIndex)) {
  10137. gridAxisIndex++;
  10138. }
  10139. if (gridAxisIndex === gl.seriesYAxisMap.length) {
  10140. gridAxisIndex = 0;
  10141. }
  10142. var yTickAmount = gl.yAxisScale[gridAxisIndex].result.length - 1;
  10143. var xCount;
  10144. if (!gl.isBarHorizontal || this.isRangeBar) {
  10145. xCount = this.xaxisLabels.length;
  10146. if (this.isRangeBar) {
  10147. var _gl$yAxisScale, _gl$yAxisScale$gridAx, _gl$yAxisScale$gridAx2;
  10148. yTickAmount = gl.labels.length;
  10149. if (w.config.xaxis.tickAmount && w.config.xaxis.labels.formatter) {
  10150. xCount = w.config.xaxis.tickAmount;
  10151. }
  10152. 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') {
  10153. xCount = gl.yAxisScale[gridAxisIndex].result.length - 1;
  10154. }
  10155. }
  10156. this._drawXYLines({
  10157. xCount: xCount,
  10158. tickAmount: yTickAmount
  10159. });
  10160. } else {
  10161. xCount = yTickAmount;
  10162. // for horizontal bar chart, get the xaxis tickamount
  10163. yTickAmount = gl.xTickAmount;
  10164. this._drawInvertedXYLines({
  10165. xCount: xCount,
  10166. tickAmount: yTickAmount
  10167. });
  10168. }
  10169. this.drawGridBands(xCount, yTickAmount);
  10170. return {
  10171. el: this.elg,
  10172. elGridBorders: this.elGridBorders,
  10173. xAxisTickWidth: gl.gridWidth / xCount
  10174. };
  10175. }
  10176. }, {
  10177. key: "drawGridBands",
  10178. value: function drawGridBands(xCount, tickAmount) {
  10179. var _this2 = this,
  10180. _w$config$grid$row$co,
  10181. _w$config$grid$column;
  10182. var w = this.w;
  10183. var drawBands = function drawBands(type, count, x1, y1, x2, y2) {
  10184. for (var i = 0, c = 0; i < count; i++, c++) {
  10185. if (c >= w.config.grid[type].colors.length) {
  10186. c = 0;
  10187. }
  10188. _this2._drawGridBandRect({
  10189. c: c,
  10190. x1: x1,
  10191. y1: y1,
  10192. x2: x2,
  10193. y2: y2,
  10194. type: type
  10195. });
  10196. y1 += w.globals.gridHeight / tickAmount;
  10197. }
  10198. };
  10199. 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) {
  10200. drawBands('row', tickAmount, 0, 0, w.globals.gridWidth, w.globals.gridHeight / tickAmount);
  10201. }
  10202. 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) {
  10203. var xc = !w.globals.isBarHorizontal && w.config.xaxis.tickPlacement === 'on' && (w.config.xaxis.type === 'category' || w.config.xaxis.convertedCatToNumeric) ? xCount - 1 : xCount;
  10204. if (w.globals.isXNumeric) {
  10205. xc = w.globals.xAxisScale.result.length - 1;
  10206. }
  10207. var x1 = w.globals.padHorizontal;
  10208. var y1 = 0;
  10209. var x2 = w.globals.padHorizontal + w.globals.gridWidth / xc;
  10210. var y2 = w.globals.gridHeight;
  10211. for (var i = 0, c = 0; i < xCount; i++, c++) {
  10212. if (c >= w.config.grid.column.colors.length) {
  10213. c = 0;
  10214. }
  10215. if (w.config.xaxis.type === 'datetime') {
  10216. var _this$xaxisLabels;
  10217. x1 = this.xaxisLabels[i].position;
  10218. x2 = (((_this$xaxisLabels = this.xaxisLabels[i + 1]) === null || _this$xaxisLabels === void 0 ? void 0 : _this$xaxisLabels.position) || w.globals.gridWidth) - this.xaxisLabels[i].position;
  10219. }
  10220. this._drawGridBandRect({
  10221. c: c,
  10222. x1: x1,
  10223. y1: y1,
  10224. x2: x2,
  10225. y2: y2,
  10226. type: 'column'
  10227. });
  10228. x1 += w.globals.gridWidth / xc;
  10229. }
  10230. }
  10231. }
  10232. }]);
  10233. return Grid;
  10234. }();
  10235. var Scales = /*#__PURE__*/function () {
  10236. function Scales(ctx) {
  10237. _classCallCheck(this, Scales);
  10238. this.ctx = ctx;
  10239. this.w = ctx.w;
  10240. this.coreUtils = new CoreUtils(this.ctx);
  10241. }
  10242. // http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis
  10243. // This routine creates the Y axis values for a graph.
  10244. _createClass(Scales, [{
  10245. key: "niceScale",
  10246. value: function niceScale(yMin, yMax) {
  10247. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  10248. // Calculate Min amd Max graphical labels and graph
  10249. // increments.
  10250. //
  10251. // Output will be an array of the Y axis values that
  10252. // encompass the Y values.
  10253. var jsPrecision = 1e-11; // JS precision errors
  10254. var w = this.w;
  10255. var gl = w.globals;
  10256. var axisCnf;
  10257. var maxTicks;
  10258. var gotMin;
  10259. var gotMax;
  10260. if (gl.isBarHorizontal) {
  10261. axisCnf = w.config.xaxis;
  10262. // The most ticks we can fit into the svg chart dimensions
  10263. maxTicks = Math.max((gl.svgWidth - 100) / 25, 2); // Guestimate
  10264. } else {
  10265. axisCnf = w.config.yaxis[index];
  10266. maxTicks = Math.max((gl.svgHeight - 100) / 15, 2);
  10267. }
  10268. if (!Utils$1.isNumber(maxTicks)) {
  10269. maxTicks = 10;
  10270. }
  10271. gotMin = axisCnf.min !== undefined && axisCnf.min !== null;
  10272. gotMax = axisCnf.max !== undefined && axisCnf.min !== null;
  10273. var gotStepSize = axisCnf.stepSize !== undefined && axisCnf.stepSize !== null;
  10274. var gotTickAmount = axisCnf.tickAmount !== undefined && axisCnf.tickAmount !== null;
  10275. var ticks = gotTickAmount ? axisCnf.tickAmount : gl.niceScaleDefaultTicks[Math.min(Math.round(maxTicks / 2), gl.niceScaleDefaultTicks.length - 1)];
  10276. // In case we have a multi axis chart:
  10277. // Ensure subsequent series start with the same tickAmount as series[0],
  10278. // because the tick lines are drawn based on series[0]. This does not
  10279. // override user defined options for any yaxis.
  10280. if (gl.isMultipleYAxis && !gotTickAmount && gl.multiAxisTickAmount > 0) {
  10281. ticks = gl.multiAxisTickAmount;
  10282. gotTickAmount = true;
  10283. }
  10284. if (ticks === 'dataPoints') {
  10285. ticks = gl.dataPoints - 1;
  10286. } else {
  10287. // Ensure ticks is an integer
  10288. ticks = Math.abs(Math.round(ticks));
  10289. }
  10290. if (yMin === Number.MIN_VALUE && yMax === 0 || !Utils$1.isNumber(yMin) && !Utils$1.isNumber(yMax) || yMin === Number.MIN_VALUE && yMax === -Number.MAX_VALUE) {
  10291. // when all values are 0
  10292. yMin = Utils$1.isNumber(axisCnf.min) ? axisCnf.min : 0;
  10293. yMax = Utils$1.isNumber(axisCnf.max) ? axisCnf.max : yMin + ticks;
  10294. gl.allSeriesCollapsed = false;
  10295. }
  10296. if (yMin > yMax) {
  10297. // if somehow due to some wrong config, user sent max less than min,
  10298. // adjust the min/max again
  10299. console.warn('axis.min cannot be greater than axis.max: swapping min and max');
  10300. var temp = yMax;
  10301. yMax = yMin;
  10302. yMin = temp;
  10303. } else if (yMin === yMax) {
  10304. // If yMin and yMax are identical, then
  10305. // adjust the yMin and yMax values to actually
  10306. // make a graph. Also avoids division by zero errors.
  10307. yMin = yMin === 0 ? 0 : yMin - 1; // choose an integer in case yValueDecimals=0
  10308. yMax = yMax === 0 ? 2 : yMax + 1; // choose an integer in case yValueDecimals=0
  10309. }
  10310. var result = [];
  10311. if (ticks < 1) {
  10312. ticks = 1;
  10313. }
  10314. var tiks = ticks;
  10315. // Determine Range
  10316. var range = Math.abs(yMax - yMin);
  10317. // Snap min or max to zero if close
  10318. var proximityRatio = 0.15;
  10319. if (!gotMin && yMin > 0 && yMin / range < proximityRatio) {
  10320. yMin = 0;
  10321. gotMin = true;
  10322. }
  10323. if (!gotMax && yMax < 0 && -yMax / range < proximityRatio) {
  10324. yMax = 0;
  10325. gotMax = true;
  10326. }
  10327. range = Math.abs(yMax - yMin);
  10328. // Calculate a pretty step value based on ticks
  10329. // Initial stepSize
  10330. var stepSize = range / tiks;
  10331. var niceStep = stepSize;
  10332. var mag = Math.floor(Math.log10(niceStep));
  10333. var magPow = Math.pow(10, mag);
  10334. // ceil() is used below in conjunction with the values populating
  10335. // niceScaleAllowedMagMsd[][] to ensure that (niceStep * tiks)
  10336. // produces a range that doesn't clip data points after stretching
  10337. // the raw range out a little to match the prospective new range.
  10338. var magMsd = Math.ceil(niceStep / magPow);
  10339. // See globals.js for info on what niceScaleAllowedMagMsd does
  10340. magMsd = gl.niceScaleAllowedMagMsd[gl.yValueDecimal === 0 ? 0 : 1][magMsd];
  10341. niceStep = magMsd * magPow;
  10342. // Initial stepSize
  10343. stepSize = niceStep;
  10344. // Get step value
  10345. if (gl.isBarHorizontal && axisCnf.stepSize && axisCnf.type !== 'datetime') {
  10346. stepSize = axisCnf.stepSize;
  10347. gotStepSize = true;
  10348. } else if (gotStepSize) {
  10349. stepSize = axisCnf.stepSize;
  10350. }
  10351. if (gotStepSize) {
  10352. if (axisCnf.forceNiceScale) {
  10353. // Check that given stepSize is sane with respect to the range.
  10354. //
  10355. // The user can, by setting forceNiceScale = true,
  10356. // define a stepSize that will be scaled to a useful value before
  10357. // it's checked for consistency.
  10358. //
  10359. // If, for example, the range = 4 and the user defined stepSize = 8
  10360. // (or 8000 or 0.0008, etc), then stepSize is inapplicable as
  10361. // it is. Reducing it to 0.8 will fit with 5 ticks.
  10362. //
  10363. var stepMag = Math.floor(Math.log10(stepSize));
  10364. stepSize *= Math.pow(10, mag - stepMag);
  10365. }
  10366. }
  10367. // Start applying some rules
  10368. if (gotMin && gotMax) {
  10369. var crudeStep = range / tiks;
  10370. // min and max (range) cannot be changed
  10371. if (gotTickAmount) {
  10372. if (gotStepSize) {
  10373. if (Utils$1.mod(range, stepSize) != 0) {
  10374. // stepSize conflicts with range
  10375. var gcdStep = Utils$1.getGCD(stepSize, crudeStep);
  10376. // gcdStep is a multiple of range because crudeStep is a multiple.
  10377. // gcdStep is also a multiple of stepSize, so it partially honoured
  10378. // All three could be equal, which would be very nice
  10379. // if the computed stepSize generates too many ticks they will be
  10380. // reduced later, unless the number is prime, in which case,
  10381. // the chart will display all of them or just one (plus the X axis)
  10382. // depending on svg dimensions. Setting forceNiceScale: true will force
  10383. // the display of at least the default number of ticks.
  10384. if (crudeStep / gcdStep < 10) {
  10385. stepSize = gcdStep;
  10386. } else {
  10387. // stepSize conflicts and no reasonable adjustment, but must
  10388. // honour tickAmount
  10389. stepSize = crudeStep;
  10390. }
  10391. } else {
  10392. // stepSize fits
  10393. if (Utils$1.mod(stepSize, crudeStep) == 0) {
  10394. // crudeStep is a multiple of stepSize, or vice versa
  10395. // but we know that crudeStep will generate tickAmount ticks
  10396. stepSize = crudeStep;
  10397. } else {
  10398. // stepSize conflicts with tickAmount
  10399. // if the user is setting up a multi-axis chart and wants
  10400. // synced axis ticks then they should not define stepSize
  10401. // or ensure there is no conflict between any of their options
  10402. // on any axis.
  10403. crudeStep = stepSize;
  10404. // De-prioritizing ticks from now on
  10405. gotTickAmount = false;
  10406. }
  10407. }
  10408. } else {
  10409. // no user stepSize, honour tickAmount
  10410. stepSize = crudeStep;
  10411. }
  10412. } else {
  10413. // default ticks in use, tiks can change
  10414. if (gotStepSize) {
  10415. if (Utils$1.mod(range, stepSize) == 0) {
  10416. // user stepSize fits
  10417. crudeStep = stepSize;
  10418. } else {
  10419. stepSize = crudeStep;
  10420. }
  10421. } else {
  10422. // no user stepSize
  10423. if (Utils$1.mod(range, stepSize) == 0) {
  10424. // generated nice stepSize fits
  10425. crudeStep = stepSize;
  10426. } else {
  10427. tiks = Math.ceil(range / stepSize);
  10428. crudeStep = range / tiks;
  10429. var _gcdStep = Utils$1.getGCD(range, stepSize);
  10430. if (range / _gcdStep < maxTicks) {
  10431. crudeStep = _gcdStep;
  10432. }
  10433. stepSize = crudeStep;
  10434. }
  10435. }
  10436. }
  10437. tiks = Math.round(range / stepSize);
  10438. } else {
  10439. // Snap range to ticks
  10440. if (!gotMin && !gotMax) {
  10441. if (gl.isMultipleYAxis && gotTickAmount) {
  10442. // Ensure graph doesn't clip.
  10443. var tMin = stepSize * Math.floor(yMin / stepSize);
  10444. var tMax = tMin + stepSize * tiks;
  10445. if (tMax < yMax) {
  10446. stepSize *= 2;
  10447. }
  10448. yMin = tMin;
  10449. tMax = yMax;
  10450. yMax = yMin + stepSize * tiks;
  10451. // Snap min or max to zero if possible
  10452. range = Math.abs(yMax - yMin);
  10453. if (yMin > 0 && yMin < Math.abs(tMax - yMax)) {
  10454. yMin = 0;
  10455. yMax = stepSize * tiks;
  10456. }
  10457. if (yMax < 0 && -yMax < Math.abs(tMin - yMin)) {
  10458. yMax = 0;
  10459. yMin = -stepSize * tiks;
  10460. }
  10461. } else {
  10462. yMin = stepSize * Math.floor(yMin / stepSize);
  10463. yMax = stepSize * Math.ceil(yMax / stepSize);
  10464. }
  10465. } else if (gotMax) {
  10466. if (gotTickAmount) {
  10467. yMin = yMax - stepSize * tiks;
  10468. } else {
  10469. var yMinPrev = yMin;
  10470. yMin = stepSize * Math.floor(yMin / stepSize);
  10471. if (Math.abs(yMax - yMin) / Utils$1.getGCD(range, stepSize) > maxTicks) {
  10472. // Use default ticks to compute yMin then shrinkwrap
  10473. yMin = yMax - stepSize * ticks;
  10474. yMin += stepSize * Math.floor((yMinPrev - yMin) / stepSize);
  10475. }
  10476. }
  10477. } else if (gotMin) {
  10478. if (gotTickAmount) {
  10479. yMax = yMin + stepSize * tiks;
  10480. } else {
  10481. var yMaxPrev = yMax;
  10482. yMax = stepSize * Math.ceil(yMax / stepSize);
  10483. if (Math.abs(yMax - yMin) / Utils$1.getGCD(range, stepSize) > maxTicks) {
  10484. // Use default ticks to compute yMin then shrinkwrap
  10485. yMax = yMin + stepSize * ticks;
  10486. yMax += stepSize * Math.ceil((yMaxPrev - yMax) / stepSize);
  10487. }
  10488. }
  10489. }
  10490. range = Math.abs(yMax - yMin);
  10491. // Final check and possible adjustment of stepSize to prevent
  10492. // overriding the user's min or max choice.
  10493. stepSize = Utils$1.getGCD(range, stepSize);
  10494. tiks = Math.round(range / stepSize);
  10495. }
  10496. // Shrinkwrap ticks to the range
  10497. if (!gotTickAmount && !(gotMin || gotMax)) {
  10498. tiks = Math.ceil((range - jsPrecision) / (stepSize + jsPrecision));
  10499. // No user tickAmount, or min or max, we are free to adjust to avoid a
  10500. // prime number. This helps when reducing ticks for small svg dimensions.
  10501. if (tiks > 16 && Utils$1.getPrimeFactors(tiks).length < 2) {
  10502. tiks++;
  10503. }
  10504. }
  10505. // Prune tiks down to range if series is all integers. Since tiks > range,
  10506. // range is very low (< 10 or so). Skip this step if gotTickAmount is true
  10507. // because either the user set tickAmount or the chart is multiscale and
  10508. // this axis is not determining the number of grid lines.
  10509. if (!gotTickAmount && axisCnf.forceNiceScale && gl.yValueDecimal === 0 && tiks > range) {
  10510. tiks = range;
  10511. stepSize = Math.round(range / tiks);
  10512. }
  10513. if (tiks > maxTicks && (!(gotTickAmount || gotStepSize) || axisCnf.forceNiceScale)) {
  10514. // Reduce the number of ticks nicely if chart svg dimensions shrink too far.
  10515. // The reduced tick set should always be a subset of the full set.
  10516. //
  10517. // This following products of prime factors method works as follows:
  10518. // We compute the prime factors of the full tick count (tiks), then all the
  10519. // possible products of those factors in order from smallest to biggest,
  10520. // until we find a product P such that: tiks/P < maxTicks.
  10521. //
  10522. // Example:
  10523. // Computing products of the prime factors of 30.
  10524. //
  10525. // tiks | pf | 1 2 3 4 5 6 <-- compute order
  10526. // --------------------------------------------------
  10527. // 30 | 5 | 5 5 5 <-- Multiply all
  10528. // | 3 | 3 3 3 3 <-- primes in each
  10529. // | 2 | 2 2 2 <-- column = P
  10530. // --------------------------------------------------
  10531. // 15 10 6 5 2 1 <-- tiks/P
  10532. //
  10533. // tiks = 30 has prime factors [2, 3, 5]
  10534. // The loop below computes the products [2,3,5,6,15,30].
  10535. // The last product of P = 2*3*5 is skipped since 30/P = 1.
  10536. // This yields tiks/P = [15,10,6,5,2,1], checked in order until
  10537. // tiks/P < maxTicks.
  10538. //
  10539. // Pros:
  10540. // 1) The ticks in the reduced set are always members of the
  10541. // full set of ticks.
  10542. // Cons:
  10543. // 1) None: if tiks is prime, we get all or one, nothing between, so
  10544. // the worst case is to display all, which is the status quo. Really
  10545. // only a problem visually for larger tick numbers, say, > 7.
  10546. //
  10547. var pf = Utils$1.getPrimeFactors(tiks);
  10548. var last = pf.length - 1;
  10549. var tt = tiks;
  10550. reduceLoop: for (var xFactors = 0; xFactors < last; xFactors++) {
  10551. for (var lowest = 0; lowest <= last - xFactors; lowest++) {
  10552. var stop = Math.min(lowest + xFactors, last);
  10553. var t = tt;
  10554. var div = 1;
  10555. for (var next = lowest; next <= stop; next++) {
  10556. div *= pf[next];
  10557. }
  10558. t /= div;
  10559. if (t < maxTicks) {
  10560. tt = t;
  10561. break reduceLoop;
  10562. }
  10563. }
  10564. }
  10565. if (tt === tiks) {
  10566. // Could not reduce ticks at all, go all in and display just the
  10567. // X axis and one tick.
  10568. stepSize = range;
  10569. } else {
  10570. stepSize = range / tt;
  10571. }
  10572. tiks = Math.round(range / stepSize);
  10573. }
  10574. // Record final tiks for use by other series that call niceScale().
  10575. // Note: some don't, like logarithmicScale(), etc.
  10576. if (gl.isMultipleYAxis && gl.multiAxisTickAmount == 0 && gl.ignoreYAxisIndexes.indexOf(index) < 0) {
  10577. gl.multiAxisTickAmount = tiks;
  10578. }
  10579. // build Y label array.
  10580. var val = yMin - stepSize;
  10581. // Ensure we don't under/over shoot due to JS precision errors.
  10582. // This also fixes (amongst others):
  10583. // https://github.com/apexcharts/apexcharts.js/issues/430
  10584. var err = stepSize * jsPrecision;
  10585. do {
  10586. val += stepSize;
  10587. result.push(Utils$1.stripNumber(val, 7));
  10588. } while (yMax - val > err);
  10589. return {
  10590. result: result,
  10591. niceMin: result[0],
  10592. niceMax: result[result.length - 1]
  10593. };
  10594. }
  10595. }, {
  10596. key: "linearScale",
  10597. value: function linearScale(yMin, yMax) {
  10598. var ticks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
  10599. var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  10600. var step = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
  10601. var range = Math.abs(yMax - yMin);
  10602. var result = [];
  10603. if (yMin === yMax) {
  10604. result = [yMin];
  10605. return {
  10606. result: result,
  10607. niceMin: result[0],
  10608. niceMax: result[result.length - 1]
  10609. };
  10610. }
  10611. ticks = this._adjustTicksForSmallRange(ticks, index, range);
  10612. if (ticks === 'dataPoints') {
  10613. ticks = this.w.globals.dataPoints - 1;
  10614. }
  10615. if (!step) {
  10616. step = range / ticks;
  10617. }
  10618. step = Math.round((step + Number.EPSILON) * 10) / 10;
  10619. if (ticks === Number.MAX_VALUE) {
  10620. ticks = 5;
  10621. step = 1;
  10622. }
  10623. var v = yMin;
  10624. while (ticks >= 0) {
  10625. result.push(v);
  10626. v = Utils$1.preciseAddition(v, step);
  10627. ticks -= 1;
  10628. }
  10629. return {
  10630. result: result,
  10631. niceMin: result[0],
  10632. niceMax: result[result.length - 1]
  10633. };
  10634. }
  10635. }, {
  10636. key: "logarithmicScaleNice",
  10637. value: function logarithmicScaleNice(yMin, yMax, base) {
  10638. // Basic validation to avoid for loop starting at -inf.
  10639. if (yMax <= 0) yMax = Math.max(yMin, base);
  10640. if (yMin <= 0) yMin = Math.min(yMax, base);
  10641. var logs = [];
  10642. // Get powers of base for our max and min
  10643. var logMax = Math.ceil(Math.log(yMax) / Math.log(base) + 1);
  10644. var logMin = Math.floor(Math.log(yMin) / Math.log(base));
  10645. for (var i = logMin; i < logMax; i++) {
  10646. logs.push(Math.pow(base, i));
  10647. }
  10648. return {
  10649. result: logs,
  10650. niceMin: logs[0],
  10651. niceMax: logs[logs.length - 1]
  10652. };
  10653. }
  10654. }, {
  10655. key: "logarithmicScale",
  10656. value: function logarithmicScale(yMin, yMax, base) {
  10657. // Basic validation to avoid for loop starting at -inf.
  10658. if (yMax <= 0) yMax = Math.max(yMin, base);
  10659. if (yMin <= 0) yMin = Math.min(yMax, base);
  10660. var logs = [];
  10661. // Get the logarithmic range.
  10662. var logMax = Math.log(yMax) / Math.log(base);
  10663. var logMin = Math.log(yMin) / Math.log(base);
  10664. // Get the exact logarithmic range.
  10665. // (This is the exact number of multiples of the base there are between yMin and yMax).
  10666. var logRange = logMax - logMin;
  10667. // Round the logarithmic range to get the number of ticks we will create.
  10668. // If the chosen min/max values are multiples of each other WRT the base, this will be neat.
  10669. // If the chosen min/max aren't, we will at least still provide USEFUL ticks.
  10670. var ticks = Math.round(logRange);
  10671. // Get the logarithmic spacing between ticks.
  10672. var logTickSpacing = logRange / ticks;
  10673. // Create as many ticks as there is range in the logs.
  10674. for (var i = 0, logTick = logMin; i < ticks; i++, logTick += logTickSpacing) {
  10675. logs.push(Math.pow(base, logTick));
  10676. }
  10677. // Add a final tick at the yMax.
  10678. logs.push(Math.pow(base, logMax));
  10679. return {
  10680. result: logs,
  10681. niceMin: yMin,
  10682. niceMax: yMax
  10683. };
  10684. }
  10685. }, {
  10686. key: "_adjustTicksForSmallRange",
  10687. value: function _adjustTicksForSmallRange(ticks, index, range) {
  10688. var newTicks = ticks;
  10689. if (typeof index !== 'undefined' && this.w.config.yaxis[index].labels.formatter && this.w.config.yaxis[index].tickAmount === undefined) {
  10690. var formattedVal = Number(this.w.config.yaxis[index].labels.formatter(1));
  10691. if (Utils$1.isNumber(formattedVal) && this.w.globals.yValueDecimal === 0) {
  10692. newTicks = Math.ceil(range);
  10693. }
  10694. }
  10695. return newTicks < ticks ? newTicks : ticks;
  10696. }
  10697. }, {
  10698. key: "setYScaleForIndex",
  10699. value: function setYScaleForIndex(index, minY, maxY) {
  10700. var gl = this.w.globals;
  10701. var cnf = this.w.config;
  10702. var y = gl.isBarHorizontal ? cnf.xaxis : cnf.yaxis[index];
  10703. if (typeof gl.yAxisScale[index] === 'undefined') {
  10704. gl.yAxisScale[index] = [];
  10705. }
  10706. var range = Math.abs(maxY - minY);
  10707. if (y.logarithmic && range <= 5) {
  10708. gl.invalidLogScale = true;
  10709. }
  10710. if (y.logarithmic && range > 5) {
  10711. gl.allSeriesCollapsed = false;
  10712. gl.yAxisScale[index] = y.forceNiceScale ? this.logarithmicScaleNice(minY, maxY, y.logBase) : this.logarithmicScale(minY, maxY, y.logBase);
  10713. } else {
  10714. if (maxY === -Number.MAX_VALUE || !Utils$1.isNumber(maxY) || minY === Number.MAX_VALUE || !Utils$1.isNumber(minY)) {
  10715. // no data in the chart.
  10716. // Either all series collapsed or user passed a blank array.
  10717. // Show the user's yaxis with their scale options but with a range.
  10718. gl.yAxisScale[index] = this.niceScale(Number.MIN_VALUE, 0, index);
  10719. } else {
  10720. // there is some data. Turn off the allSeriesCollapsed flag
  10721. gl.allSeriesCollapsed = false;
  10722. gl.yAxisScale[index] = this.niceScale(minY, maxY, index);
  10723. }
  10724. }
  10725. }
  10726. }, {
  10727. key: "setXScale",
  10728. value: function setXScale(minX, maxX) {
  10729. var w = this.w;
  10730. var gl = w.globals;
  10731. var diff = Math.abs(maxX - minX);
  10732. if (maxX === -Number.MAX_VALUE || !Utils$1.isNumber(maxX)) {
  10733. // no data in the chart. Either all series collapsed or user passed a blank array
  10734. gl.xAxisScale = this.linearScale(0, 10, 10);
  10735. } else {
  10736. var ticks = gl.xTickAmount + 1;
  10737. if (diff < 10 && diff > 1) {
  10738. ticks = diff;
  10739. }
  10740. gl.xAxisScale = this.linearScale(minX, maxX, ticks, 0, w.config.xaxis.stepSize);
  10741. }
  10742. return gl.xAxisScale;
  10743. }
  10744. }, {
  10745. key: "scaleMultipleYAxes",
  10746. value: function scaleMultipleYAxes() {
  10747. var _this = this;
  10748. var cnf = this.w.config;
  10749. var gl = this.w.globals;
  10750. this.coreUtils.setSeriesYAxisMappings();
  10751. var axisSeriesMap = gl.seriesYAxisMap;
  10752. var minYArr = gl.minYArr;
  10753. var maxYArr = gl.maxYArr;
  10754. // Compute min..max for each yaxis
  10755. gl.allSeriesCollapsed = true;
  10756. gl.barGroups = [];
  10757. axisSeriesMap.forEach(function (axisSeries, ai) {
  10758. var groupNames = [];
  10759. axisSeries.forEach(function (as) {
  10760. var group = cnf.series[as].group;
  10761. if (groupNames.indexOf(group) < 0) {
  10762. groupNames.push(group);
  10763. }
  10764. });
  10765. if (axisSeries.length > 0) {
  10766. (function () {
  10767. var minY = Number.MAX_VALUE;
  10768. var maxY = -Number.MAX_VALUE;
  10769. var lowestY = minY;
  10770. var highestY = maxY;
  10771. var seriesType;
  10772. var seriesGroupName;
  10773. if (cnf.chart.stacked) {
  10774. (function () {
  10775. // Series' on this axis with the same group name will be stacked.
  10776. // Sum series in each group separately
  10777. var mapSeries = new Array(gl.dataPoints).fill(0);
  10778. var sumSeries = [];
  10779. var posSeries = [];
  10780. var negSeries = [];
  10781. groupNames.forEach(function () {
  10782. sumSeries.push(mapSeries.map(function () {
  10783. return Number.MIN_VALUE;
  10784. }));
  10785. posSeries.push(mapSeries.map(function () {
  10786. return Number.MIN_VALUE;
  10787. }));
  10788. negSeries.push(mapSeries.map(function () {
  10789. return Number.MIN_VALUE;
  10790. }));
  10791. });
  10792. var _loop = function _loop(i) {
  10793. // Assume chart type but the first series that has a type overrides.
  10794. if (!seriesType && cnf.series[axisSeries[i]].type) {
  10795. seriesType = cnf.series[axisSeries[i]].type;
  10796. }
  10797. // Sum all series for this yaxis at each corresponding datapoint
  10798. // For bar and column charts we need to keep positive and negative
  10799. // values separate, for each group separately.
  10800. var si = axisSeries[i];
  10801. if (cnf.series[si].group) {
  10802. seriesGroupName = cnf.series[si].group;
  10803. } else {
  10804. seriesGroupName = 'axis-'.concat(ai);
  10805. }
  10806. var collapsed = !(gl.collapsedSeriesIndices.indexOf(si) < 0 && gl.ancillaryCollapsedSeriesIndices.indexOf(si) < 0);
  10807. if (!collapsed) {
  10808. gl.allSeriesCollapsed = false;
  10809. groupNames.forEach(function (gn, gni) {
  10810. // Undefined group names will be grouped together as their own
  10811. // group.
  10812. if (cnf.series[si].group === gn) {
  10813. for (var j = 0; j < gl.series[si].length; j++) {
  10814. var val = gl.series[si][j];
  10815. if (val >= 0) {
  10816. posSeries[gni][j] += val;
  10817. } else {
  10818. negSeries[gni][j] += val;
  10819. }
  10820. sumSeries[gni][j] += val;
  10821. // For non bar-like series' we need these point max/min values.
  10822. lowestY = Math.min(lowestY, val);
  10823. highestY = Math.max(highestY, val);
  10824. }
  10825. }
  10826. });
  10827. }
  10828. if (seriesType === 'bar' || seriesType === 'column') {
  10829. gl.barGroups.push(seriesGroupName);
  10830. }
  10831. };
  10832. for (var i = 0; i < axisSeries.length; i++) {
  10833. _loop(i);
  10834. }
  10835. if (!seriesType) {
  10836. seriesType = cnf.chart.type;
  10837. }
  10838. if (seriesType === 'bar' || seriesType === 'column') {
  10839. groupNames.forEach(function (gn, gni) {
  10840. minY = Math.min(minY, Math.min.apply(null, negSeries[gni]));
  10841. maxY = Math.max(maxY, Math.max.apply(null, posSeries[gni]));
  10842. });
  10843. } else {
  10844. groupNames.forEach(function (gn, gni) {
  10845. lowestY = Math.min(lowestY, Math.min.apply(null, sumSeries[gni]));
  10846. highestY = Math.max(highestY, Math.max.apply(null, sumSeries[gni]));
  10847. });
  10848. minY = lowestY;
  10849. maxY = highestY;
  10850. }
  10851. if (minY === Number.MIN_VALUE && maxY === Number.MIN_VALUE) {
  10852. // No series data
  10853. maxY = -Number.MAX_VALUE;
  10854. }
  10855. })();
  10856. } else {
  10857. for (var i = 0; i < axisSeries.length; i++) {
  10858. var si = axisSeries[i];
  10859. minY = Math.min(minY, minYArr[si]);
  10860. maxY = Math.max(maxY, maxYArr[si]);
  10861. var collapsed = !(gl.collapsedSeriesIndices.indexOf(si) < 0 && gl.ancillaryCollapsedSeriesIndices.indexOf(si) < 0);
  10862. if (!collapsed) {
  10863. gl.allSeriesCollapsed = false;
  10864. }
  10865. }
  10866. }
  10867. if (cnf.yaxis[ai].min !== undefined) {
  10868. if (typeof cnf.yaxis[ai].min === 'function') {
  10869. minY = cnf.yaxis[ai].min(minY);
  10870. } else {
  10871. minY = cnf.yaxis[ai].min;
  10872. }
  10873. }
  10874. if (cnf.yaxis[ai].max !== undefined) {
  10875. if (typeof cnf.yaxis[ai].max === 'function') {
  10876. maxY = cnf.yaxis[ai].max(maxY);
  10877. } else {
  10878. maxY = cnf.yaxis[ai].max;
  10879. }
  10880. }
  10881. gl.barGroups = gl.barGroups.filter(function (v, i, a) {
  10882. return a.indexOf(v) === i;
  10883. });
  10884. // Set the scale for this yaxis
  10885. _this.setYScaleForIndex(ai, minY, maxY);
  10886. // Set individual series min and max to nice values
  10887. axisSeries.forEach(function (si) {
  10888. minYArr[si] = gl.yAxisScale[ai].niceMin;
  10889. maxYArr[si] = gl.yAxisScale[ai].niceMax;
  10890. });
  10891. })();
  10892. } else {
  10893. // No series referenced by this yaxis
  10894. _this.setYScaleForIndex(ai, 0, -Number.MAX_VALUE);
  10895. }
  10896. });
  10897. }
  10898. }]);
  10899. return Scales;
  10900. }();
  10901. /**
  10902. * Range is used to generates values between min and max.
  10903. *
  10904. * @module Range
  10905. **/
  10906. var Range = /*#__PURE__*/function () {
  10907. function Range(ctx) {
  10908. _classCallCheck(this, Range);
  10909. this.ctx = ctx;
  10910. this.w = ctx.w;
  10911. this.scales = new Scales(ctx);
  10912. }
  10913. _createClass(Range, [{
  10914. key: "init",
  10915. value: function init() {
  10916. this.setYRange();
  10917. this.setXRange();
  10918. this.setZRange();
  10919. }
  10920. }, {
  10921. key: "getMinYMaxY",
  10922. value: function getMinYMaxY(startingSeriesIndex) {
  10923. var lowestY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.MAX_VALUE;
  10924. var highestY = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -Number.MAX_VALUE;
  10925. var endingSeriesIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  10926. var cnf = this.w.config;
  10927. var gl = this.w.globals;
  10928. var maxY = -Number.MAX_VALUE;
  10929. var minY = Number.MIN_VALUE;
  10930. if (endingSeriesIndex === null) {
  10931. endingSeriesIndex = startingSeriesIndex + 1;
  10932. }
  10933. var series = gl.series;
  10934. var seriesMin = series;
  10935. var seriesMax = series;
  10936. if (cnf.chart.type === 'candlestick') {
  10937. seriesMin = gl.seriesCandleL;
  10938. seriesMax = gl.seriesCandleH;
  10939. } else if (cnf.chart.type === 'boxPlot') {
  10940. seriesMin = gl.seriesCandleO;
  10941. seriesMax = gl.seriesCandleC;
  10942. } else if (gl.isRangeData) {
  10943. seriesMin = gl.seriesRangeStart;
  10944. seriesMax = gl.seriesRangeEnd;
  10945. }
  10946. var autoScaleYaxis = false;
  10947. if (gl.seriesX.length >= endingSeriesIndex) {
  10948. var _gl$brushSource;
  10949. // Eventually brushSource will be set if the current chart is a target.
  10950. // That is, after the appropriate event causes us to update.
  10951. var brush = (_gl$brushSource = gl.brushSource) === null || _gl$brushSource === void 0 ? void 0 : _gl$brushSource.w.config.chart.brush;
  10952. if (cnf.chart.zoom.enabled && cnf.chart.zoom.autoScaleYaxis || brush !== null && brush !== void 0 && brush.enabled && brush !== null && brush !== void 0 && brush.autoScaleYaxis) {
  10953. autoScaleYaxis = true;
  10954. }
  10955. }
  10956. for (var i = startingSeriesIndex; i < endingSeriesIndex; i++) {
  10957. gl.dataPoints = Math.max(gl.dataPoints, series[i].length);
  10958. var seriesType = cnf.series[i].type;
  10959. if (gl.categoryLabels.length) {
  10960. gl.dataPoints = gl.categoryLabels.filter(function (label) {
  10961. return typeof label !== 'undefined';
  10962. }).length;
  10963. }
  10964. if (gl.labels.length && cnf.xaxis.type !== 'datetime' && gl.series.reduce(function (a, c) {
  10965. return a + c.length;
  10966. }, 0) !== 0) {
  10967. // the condition cnf.xaxis.type !== 'datetime' fixes #3897 and #3905
  10968. gl.dataPoints = Math.max(gl.dataPoints, gl.labels.length);
  10969. }
  10970. var firstXIndex = 0;
  10971. var lastXIndex = series[i].length - 1;
  10972. if (autoScaleYaxis) {
  10973. // Scale the Y axis to the min..max within the possibly zoomed X axis domain.
  10974. if (cnf.xaxis.min) {
  10975. for (; firstXIndex < lastXIndex && gl.seriesX[i][firstXIndex] < cnf.xaxis.min; firstXIndex++) {}
  10976. }
  10977. if (cnf.xaxis.max) {
  10978. for (; lastXIndex > firstXIndex && gl.seriesX[i][lastXIndex] > cnf.xaxis.max; lastXIndex--) {}
  10979. }
  10980. }
  10981. for (var j = firstXIndex; j <= lastXIndex && j < gl.series[i].length; j++) {
  10982. var val = series[i][j];
  10983. if (val !== null && Utils$1.isNumber(val)) {
  10984. if (typeof seriesMax[i][j] !== 'undefined') {
  10985. maxY = Math.max(maxY, seriesMax[i][j]);
  10986. lowestY = Math.min(lowestY, seriesMax[i][j]);
  10987. }
  10988. if (typeof seriesMin[i][j] !== 'undefined') {
  10989. lowestY = Math.min(lowestY, seriesMin[i][j]);
  10990. highestY = Math.max(highestY, seriesMin[i][j]);
  10991. }
  10992. // These series arrays are dual purpose:
  10993. // Array : CandleO, CandleH, CandleM, CandleL, CandleC
  10994. // Candlestick: O H L C
  10995. // Boxplot : Min Q1 Median Q3 Max
  10996. switch (seriesType) {
  10997. case 'candlestick':
  10998. {
  10999. if (typeof gl.seriesCandleC[i][j] !== 'undefined') {
  11000. maxY = Math.max(maxY, gl.seriesCandleH[i][j]);
  11001. lowestY = Math.min(lowestY, gl.seriesCandleL[i][j]);
  11002. }
  11003. }
  11004. break;
  11005. case 'boxPlot':
  11006. {
  11007. if (typeof gl.seriesCandleC[i][j] !== 'undefined') {
  11008. maxY = Math.max(maxY, gl.seriesCandleC[i][j]);
  11009. lowestY = Math.min(lowestY, gl.seriesCandleO[i][j]);
  11010. }
  11011. }
  11012. break;
  11013. }
  11014. // there is a combo chart and the specified series in not either
  11015. // candlestick, boxplot, or rangeArea/rangeBar; find the max there.
  11016. if (seriesType && seriesType !== 'candlestick' && seriesType !== 'boxPlot' && seriesType !== 'rangeArea' && seriesType !== 'rangeBar') {
  11017. maxY = Math.max(maxY, gl.series[i][j]);
  11018. lowestY = Math.min(lowestY, gl.series[i][j]);
  11019. }
  11020. highestY = maxY;
  11021. if (gl.seriesGoals[i] && gl.seriesGoals[i][j] && Array.isArray(gl.seriesGoals[i][j])) {
  11022. gl.seriesGoals[i][j].forEach(function (g) {
  11023. if (minY !== Number.MIN_VALUE) {
  11024. minY = Math.min(minY, g.value);
  11025. lowestY = minY;
  11026. }
  11027. maxY = Math.max(maxY, g.value);
  11028. highestY = maxY;
  11029. });
  11030. }
  11031. if (Utils$1.isFloat(val)) {
  11032. val = Utils$1.noExponents(val);
  11033. gl.yValueDecimal = Math.max(gl.yValueDecimal, val.toString().split('.')[1].length);
  11034. }
  11035. if (minY > seriesMin[i][j] && seriesMin[i][j] < 0) {
  11036. minY = seriesMin[i][j];
  11037. }
  11038. } else {
  11039. gl.hasNullValues = true;
  11040. }
  11041. }
  11042. if (seriesType === 'bar' || seriesType === 'column') {
  11043. if (minY < 0 && maxY < 0) {
  11044. // all negative values in a bar series, hence make the max to 0
  11045. maxY = 0;
  11046. highestY = Math.max(highestY, 0);
  11047. }
  11048. if (minY === Number.MIN_VALUE) {
  11049. minY = 0;
  11050. lowestY = Math.min(lowestY, 0);
  11051. }
  11052. }
  11053. }
  11054. if (cnf.chart.type === 'rangeBar' && gl.seriesRangeStart.length && gl.isBarHorizontal) {
  11055. minY = lowestY;
  11056. }
  11057. if (cnf.chart.type === 'bar') {
  11058. if (minY < 0 && maxY < 0) {
  11059. // all negative values in a bar chart, hence make the max to 0
  11060. maxY = 0;
  11061. }
  11062. if (minY === Number.MIN_VALUE) {
  11063. minY = 0;
  11064. }
  11065. }
  11066. return {
  11067. minY: minY,
  11068. maxY: maxY,
  11069. lowestY: lowestY,
  11070. highestY: highestY
  11071. };
  11072. }
  11073. }, {
  11074. key: "setYRange",
  11075. value: function setYRange() {
  11076. var gl = this.w.globals;
  11077. var cnf = this.w.config;
  11078. gl.maxY = -Number.MAX_VALUE;
  11079. gl.minY = Number.MIN_VALUE;
  11080. var lowestYInAllSeries = Number.MAX_VALUE;
  11081. var minYMaxY;
  11082. if (gl.isMultipleYAxis) {
  11083. // we need to get minY and maxY for multiple y axis
  11084. lowestYInAllSeries = Number.MAX_VALUE;
  11085. for (var i = 0; i < gl.series.length; i++) {
  11086. minYMaxY = this.getMinYMaxY(i);
  11087. gl.minYArr[i] = minYMaxY.lowestY;
  11088. gl.maxYArr[i] = minYMaxY.highestY;
  11089. lowestYInAllSeries = Math.min(lowestYInAllSeries, minYMaxY.lowestY);
  11090. }
  11091. }
  11092. // and then, get the minY and maxY from all series
  11093. minYMaxY = this.getMinYMaxY(0, lowestYInAllSeries, null, gl.series.length);
  11094. if (cnf.chart.type === 'bar') {
  11095. gl.minY = minYMaxY.minY;
  11096. gl.maxY = minYMaxY.maxY;
  11097. } else {
  11098. gl.minY = minYMaxY.lowestY;
  11099. gl.maxY = minYMaxY.highestY;
  11100. }
  11101. lowestYInAllSeries = minYMaxY.lowestY;
  11102. if (cnf.chart.stacked) {
  11103. this._setStackedMinMax();
  11104. }
  11105. // if the numbers are too big, reduce the range
  11106. // for eg, if number is between 100000-110000, putting 0 as the lowest
  11107. // value is not so good idea. So change the gl.minY for
  11108. // line/area/scatter/candlesticks/boxPlot/vertical rangebar
  11109. 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) {
  11110. if (gl.minY === Number.MIN_VALUE && lowestYInAllSeries !== -Number.MAX_VALUE && lowestYInAllSeries !== gl.maxY // single value possibility
  11111. ) {
  11112. gl.minY = lowestYInAllSeries;
  11113. }
  11114. } else {
  11115. gl.minY = gl.minY !== Number.MIN_VALUE ? Math.min(minYMaxY.minY, gl.minY) : minYMaxY.minY;
  11116. }
  11117. cnf.yaxis.forEach(function (yaxe, index) {
  11118. // override all min/max values by user defined values (y axis)
  11119. if (yaxe.max !== undefined) {
  11120. if (typeof yaxe.max === 'number') {
  11121. gl.maxYArr[index] = yaxe.max;
  11122. } else if (typeof yaxe.max === 'function') {
  11123. // fixes apexcharts.js/issues/2098
  11124. gl.maxYArr[index] = yaxe.max(gl.isMultipleYAxis ? gl.maxYArr[index] : gl.maxY);
  11125. }
  11126. // gl.maxY is for single y-axis chart, it will be ignored in multi-yaxis
  11127. gl.maxY = gl.maxYArr[index];
  11128. }
  11129. if (yaxe.min !== undefined) {
  11130. if (typeof yaxe.min === 'number') {
  11131. gl.minYArr[index] = yaxe.min;
  11132. } else if (typeof yaxe.min === 'function') {
  11133. // fixes apexcharts.js/issues/2098
  11134. gl.minYArr[index] = yaxe.min(gl.isMultipleYAxis ? gl.minYArr[index] === Number.MIN_VALUE ? 0 : gl.minYArr[index] : gl.minY);
  11135. }
  11136. // gl.minY is for single y-axis chart, it will be ignored in multi-yaxis
  11137. gl.minY = gl.minYArr[index];
  11138. }
  11139. });
  11140. // for horizontal bar charts, we need to check xaxis min/max as user may have specified there
  11141. if (gl.isBarHorizontal) {
  11142. var minmax = ['min', 'max'];
  11143. minmax.forEach(function (m) {
  11144. if (cnf.xaxis[m] !== undefined && typeof cnf.xaxis[m] === 'number') {
  11145. m === 'min' ? gl.minY = cnf.xaxis[m] : gl.maxY = cnf.xaxis[m];
  11146. }
  11147. });
  11148. }
  11149. if (gl.isMultipleYAxis) {
  11150. this.scales.scaleMultipleYAxes();
  11151. gl.minY = lowestYInAllSeries;
  11152. } else {
  11153. this.scales.setYScaleForIndex(0, gl.minY, gl.maxY);
  11154. gl.minY = gl.yAxisScale[0].niceMin;
  11155. gl.maxY = gl.yAxisScale[0].niceMax;
  11156. gl.minYArr[0] = gl.minY;
  11157. gl.maxYArr[0] = gl.maxY;
  11158. }
  11159. gl.barGroups = [];
  11160. gl.lineGroups = [];
  11161. gl.areaGroups = [];
  11162. cnf.series.forEach(function (s) {
  11163. var type = s.type || cnf.chart.type;
  11164. switch (type) {
  11165. case 'bar':
  11166. case 'column':
  11167. gl.barGroups.push(s.group);
  11168. break;
  11169. case 'line':
  11170. gl.lineGroups.push(s.group);
  11171. break;
  11172. case 'area':
  11173. gl.areaGroups.push(s.group);
  11174. break;
  11175. }
  11176. });
  11177. // Uniquify the group names in each stackable chart type.
  11178. gl.barGroups = gl.barGroups.filter(function (v, i, a) {
  11179. return a.indexOf(v) === i;
  11180. });
  11181. gl.lineGroups = gl.lineGroups.filter(function (v, i, a) {
  11182. return a.indexOf(v) === i;
  11183. });
  11184. gl.areaGroups = gl.areaGroups.filter(function (v, i, a) {
  11185. return a.indexOf(v) === i;
  11186. });
  11187. return {
  11188. minY: gl.minY,
  11189. maxY: gl.maxY,
  11190. minYArr: gl.minYArr,
  11191. maxYArr: gl.maxYArr,
  11192. yAxisScale: gl.yAxisScale
  11193. };
  11194. }
  11195. }, {
  11196. key: "setXRange",
  11197. value: function setXRange() {
  11198. var gl = this.w.globals;
  11199. var cnf = this.w.config;
  11200. var isXNumeric = cnf.xaxis.type === 'numeric' || cnf.xaxis.type === 'datetime' || cnf.xaxis.type === 'category' && !gl.noLabelsProvided || gl.noLabelsProvided || gl.isXNumeric;
  11201. var getInitialMinXMaxX = function getInitialMinXMaxX() {
  11202. for (var i = 0; i < gl.series.length; i++) {
  11203. if (gl.labels[i]) {
  11204. for (var j = 0; j < gl.labels[i].length; j++) {
  11205. if (gl.labels[i][j] !== null && Utils$1.isNumber(gl.labels[i][j])) {
  11206. gl.maxX = Math.max(gl.maxX, gl.labels[i][j]);
  11207. gl.initialMaxX = Math.max(gl.maxX, gl.labels[i][j]);
  11208. gl.minX = Math.min(gl.minX, gl.labels[i][j]);
  11209. gl.initialMinX = Math.min(gl.minX, gl.labels[i][j]);
  11210. }
  11211. }
  11212. }
  11213. }
  11214. };
  11215. // minX maxX starts here
  11216. if (gl.isXNumeric) {
  11217. getInitialMinXMaxX();
  11218. }
  11219. if (gl.noLabelsProvided) {
  11220. if (cnf.xaxis.categories.length === 0) {
  11221. gl.maxX = gl.labels[gl.labels.length - 1];
  11222. gl.initialMaxX = gl.labels[gl.labels.length - 1];
  11223. gl.minX = 1;
  11224. gl.initialMinX = 1;
  11225. }
  11226. }
  11227. if (gl.isXNumeric || gl.noLabelsProvided || gl.dataFormatXNumeric) {
  11228. var ticks = 10;
  11229. if (cnf.xaxis.tickAmount === undefined) {
  11230. ticks = Math.round(gl.svgWidth / 150);
  11231. // no labels provided and total number of dataPoints is less than 30
  11232. if (cnf.xaxis.type === 'numeric' && gl.dataPoints < 30) {
  11233. ticks = gl.dataPoints - 1;
  11234. }
  11235. // this check is for when ticks exceeds total datapoints and that would result in duplicate labels
  11236. if (ticks > gl.dataPoints && gl.dataPoints !== 0) {
  11237. ticks = gl.dataPoints - 1;
  11238. }
  11239. } else if (cnf.xaxis.tickAmount === 'dataPoints') {
  11240. if (gl.series.length > 1) {
  11241. ticks = gl.series[gl.maxValsInArrayIndex].length - 1;
  11242. }
  11243. if (gl.isXNumeric) {
  11244. var diff = gl.maxX - gl.minX;
  11245. if (diff < 30) {
  11246. ticks = diff - 1;
  11247. }
  11248. }
  11249. } else {
  11250. ticks = cnf.xaxis.tickAmount;
  11251. }
  11252. gl.xTickAmount = ticks;
  11253. // override all min/max values by user defined values (x axis)
  11254. if (cnf.xaxis.max !== undefined && typeof cnf.xaxis.max === 'number') {
  11255. gl.maxX = cnf.xaxis.max;
  11256. }
  11257. if (cnf.xaxis.min !== undefined && typeof cnf.xaxis.min === 'number') {
  11258. gl.minX = cnf.xaxis.min;
  11259. }
  11260. // if range is provided, adjust the new minX
  11261. if (cnf.xaxis.range !== undefined) {
  11262. gl.minX = gl.maxX - cnf.xaxis.range;
  11263. }
  11264. if (gl.minX !== Number.MAX_VALUE && gl.maxX !== -Number.MAX_VALUE) {
  11265. if (cnf.xaxis.convertedCatToNumeric && !gl.dataFormatXNumeric) {
  11266. var catScale = [];
  11267. for (var i = gl.minX - 1; i < gl.maxX; i++) {
  11268. catScale.push(i + 1);
  11269. }
  11270. gl.xAxisScale = {
  11271. result: catScale,
  11272. niceMin: catScale[0],
  11273. niceMax: catScale[catScale.length - 1]
  11274. };
  11275. } else {
  11276. gl.xAxisScale = this.scales.setXScale(gl.minX, gl.maxX);
  11277. }
  11278. } else {
  11279. gl.xAxisScale = this.scales.linearScale(0, ticks, ticks, 0, cnf.xaxis.stepSize);
  11280. if (gl.noLabelsProvided && gl.labels.length > 0) {
  11281. gl.xAxisScale = this.scales.linearScale(1, gl.labels.length, ticks - 1, 0, cnf.xaxis.stepSize);
  11282. // this is the only place seriesX is again mutated
  11283. gl.seriesX = gl.labels.slice();
  11284. }
  11285. }
  11286. // we will still store these labels as the count for this will be different (to draw grid and labels placement)
  11287. if (isXNumeric) {
  11288. gl.labels = gl.xAxisScale.result.slice();
  11289. }
  11290. }
  11291. if (gl.isBarHorizontal && gl.labels.length) {
  11292. gl.xTickAmount = gl.labels.length;
  11293. }
  11294. // single dataPoint
  11295. this._handleSingleDataPoint();
  11296. // minimum x difference to calculate bar width in numeric bars
  11297. this._getMinXDiff();
  11298. return {
  11299. minX: gl.minX,
  11300. maxX: gl.maxX
  11301. };
  11302. }
  11303. }, {
  11304. key: "setZRange",
  11305. value: function setZRange() {
  11306. // minZ, maxZ starts here
  11307. var gl = this.w.globals;
  11308. if (!gl.isDataXYZ) return;
  11309. for (var i = 0; i < gl.series.length; i++) {
  11310. if (typeof gl.seriesZ[i] !== 'undefined') {
  11311. for (var j = 0; j < gl.seriesZ[i].length; j++) {
  11312. if (gl.seriesZ[i][j] !== null && Utils$1.isNumber(gl.seriesZ[i][j])) {
  11313. gl.maxZ = Math.max(gl.maxZ, gl.seriesZ[i][j]);
  11314. gl.minZ = Math.min(gl.minZ, gl.seriesZ[i][j]);
  11315. }
  11316. }
  11317. }
  11318. }
  11319. }
  11320. }, {
  11321. key: "_handleSingleDataPoint",
  11322. value: function _handleSingleDataPoint() {
  11323. var gl = this.w.globals;
  11324. var cnf = this.w.config;
  11325. if (gl.minX === gl.maxX) {
  11326. var datetimeObj = new DateTime(this.ctx);
  11327. if (cnf.xaxis.type === 'datetime') {
  11328. var newMinX = datetimeObj.getDate(gl.minX);
  11329. if (cnf.xaxis.labels.datetimeUTC) {
  11330. newMinX.setUTCDate(newMinX.getUTCDate() - 2);
  11331. } else {
  11332. newMinX.setDate(newMinX.getDate() - 2);
  11333. }
  11334. gl.minX = new Date(newMinX).getTime();
  11335. var newMaxX = datetimeObj.getDate(gl.maxX);
  11336. if (cnf.xaxis.labels.datetimeUTC) {
  11337. newMaxX.setUTCDate(newMaxX.getUTCDate() + 2);
  11338. } else {
  11339. newMaxX.setDate(newMaxX.getDate() + 2);
  11340. }
  11341. gl.maxX = new Date(newMaxX).getTime();
  11342. } else if (cnf.xaxis.type === 'numeric' || cnf.xaxis.type === 'category' && !gl.noLabelsProvided) {
  11343. gl.minX = gl.minX - 2;
  11344. gl.initialMinX = gl.minX;
  11345. gl.maxX = gl.maxX + 2;
  11346. gl.initialMaxX = gl.maxX;
  11347. }
  11348. }
  11349. }
  11350. }, {
  11351. key: "_getMinXDiff",
  11352. value: function _getMinXDiff() {
  11353. var gl = this.w.globals;
  11354. if (gl.isXNumeric) {
  11355. // get the least x diff if numeric x axis is present
  11356. gl.seriesX.forEach(function (sX, i) {
  11357. if (sX.length === 1) {
  11358. // a small hack to prevent overlapping multiple bars when there is just 1 datapoint in bar series.
  11359. // fix #811
  11360. sX.push(gl.seriesX[gl.maxValsInArrayIndex][gl.seriesX[gl.maxValsInArrayIndex].length - 1]);
  11361. }
  11362. // fix #983 (clone the array to avoid side effects)
  11363. var seriesX = sX.slice();
  11364. seriesX.sort(function (a, b) {
  11365. return a - b;
  11366. });
  11367. seriesX.forEach(function (s, j) {
  11368. if (j > 0) {
  11369. var xDiff = s - seriesX[j - 1];
  11370. if (xDiff > 0) {
  11371. gl.minXDiff = Math.min(xDiff, gl.minXDiff);
  11372. }
  11373. }
  11374. });
  11375. if (gl.dataPoints === 1 || gl.minXDiff === Number.MAX_VALUE) {
  11376. // fixes apexcharts.js #1221
  11377. gl.minXDiff = 0.5;
  11378. }
  11379. });
  11380. }
  11381. }
  11382. }, {
  11383. key: "_setStackedMinMax",
  11384. value: function _setStackedMinMax() {
  11385. var _this = this;
  11386. var gl = this.w.globals;
  11387. // for stacked charts, we calculate each series's parallel values.
  11388. // i.e, series[0][j] + series[1][j] .... [series[i.length][j]]
  11389. // and get the max out of it
  11390. if (!gl.series.length) return;
  11391. var seriesGroups = gl.seriesGroups;
  11392. if (!seriesGroups.length) {
  11393. seriesGroups = [this.w.globals.seriesNames.map(function (name) {
  11394. return name;
  11395. })];
  11396. }
  11397. var stackedPoss = {};
  11398. var stackedNegs = {};
  11399. seriesGroups.forEach(function (group) {
  11400. stackedPoss[group] = [];
  11401. stackedNegs[group] = [];
  11402. var indicesOfSeriesInGroup = _this.w.config.series.map(function (serie, si) {
  11403. return group.indexOf(gl.seriesNames[si]) > -1 ? si : null;
  11404. }).filter(function (f) {
  11405. return f !== null;
  11406. });
  11407. indicesOfSeriesInGroup.forEach(function (i) {
  11408. for (var j = 0; j < gl.series[gl.maxValsInArrayIndex].length; j++) {
  11409. var _this$w$config$series, _this$w$config$series2, _this$w$config$series3, _this$w$config$series4;
  11410. if (typeof stackedPoss[group][j] === 'undefined') {
  11411. stackedPoss[group][j] = 0;
  11412. stackedNegs[group][j] = 0;
  11413. }
  11414. 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');
  11415. if (stackSeries) {
  11416. if (gl.series[i][j] !== null && Utils$1.isNumber(gl.series[i][j])) {
  11417. gl.series[i][j] > 0 ? stackedPoss[group][j] += parseFloat(gl.series[i][j]) + 0.0001 : stackedNegs[group][j] += parseFloat(gl.series[i][j]);
  11418. }
  11419. }
  11420. }
  11421. });
  11422. });
  11423. Object.entries(stackedPoss).forEach(function (_ref) {
  11424. var _ref2 = _slicedToArray(_ref, 1),
  11425. key = _ref2[0];
  11426. stackedPoss[key].forEach(function (_, stgi) {
  11427. gl.maxY = Math.max(gl.maxY, stackedPoss[key][stgi]);
  11428. gl.minY = Math.min(gl.minY, stackedNegs[key][stgi]);
  11429. });
  11430. });
  11431. }
  11432. }]);
  11433. return Range;
  11434. }();
  11435. /**
  11436. * ApexCharts YAxis Class for drawing Y-Axis.
  11437. *
  11438. * @module YAxis
  11439. **/
  11440. var YAxis = /*#__PURE__*/function () {
  11441. function YAxis(ctx, elgrid) {
  11442. _classCallCheck(this, YAxis);
  11443. this.ctx = ctx;
  11444. this.elgrid = elgrid;
  11445. this.w = ctx.w;
  11446. var w = this.w;
  11447. this.xaxisFontSize = w.config.xaxis.labels.style.fontSize;
  11448. this.axisFontFamily = w.config.xaxis.labels.style.fontFamily;
  11449. this.xaxisForeColors = w.config.xaxis.labels.style.colors;
  11450. this.isCategoryBarHorizontal = w.config.chart.type === 'bar' && w.config.plotOptions.bar.horizontal;
  11451. this.xAxisoffX = w.config.xaxis.position === 'bottom' ? w.globals.gridHeight : 0;
  11452. this.drawnLabels = [];
  11453. this.axesUtils = new AxesUtils(ctx);
  11454. }
  11455. _createClass(YAxis, [{
  11456. key: "drawYaxis",
  11457. value: function drawYaxis(realIndex) {
  11458. var w = this.w;
  11459. var graphics = new Graphics(this.ctx);
  11460. var yaxisStyle = w.config.yaxis[realIndex].labels.style;
  11461. var yaxisFontSize = yaxisStyle.fontSize,
  11462. yaxisFontFamily = yaxisStyle.fontFamily,
  11463. yaxisFontWeight = yaxisStyle.fontWeight;
  11464. var elYaxis = graphics.group({
  11465. class: 'apexcharts-yaxis',
  11466. rel: realIndex,
  11467. transform: "translate(".concat(w.globals.translateYAxisX[realIndex], ", 0)")
  11468. });
  11469. if (this.axesUtils.isYAxisHidden(realIndex)) return elYaxis;
  11470. var elYaxisTexts = graphics.group({
  11471. class: 'apexcharts-yaxis-texts-g'
  11472. });
  11473. elYaxis.add(elYaxisTexts);
  11474. var tickAmount = w.globals.yAxisScale[realIndex].result.length - 1;
  11475. var labelsDivider = w.globals.gridHeight / tickAmount;
  11476. var lbFormatter = w.globals.yLabelFormatters[realIndex];
  11477. var labels = this.axesUtils.checkForReversedLabels(realIndex, w.globals.yAxisScale[realIndex].result.slice());
  11478. if (w.config.yaxis[realIndex].labels.show) {
  11479. var lY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY;
  11480. if (w.globals.isBarHorizontal) lY = 0;else if (w.config.chart.type === 'heatmap') lY -= labelsDivider / 2;
  11481. lY += parseInt(yaxisFontSize, 10) / 3;
  11482. for (var i = tickAmount; i >= 0; i--) {
  11483. var val = lbFormatter(labels[i], i, w);
  11484. var xPad = w.config.yaxis[realIndex].labels.padding;
  11485. if (w.config.yaxis[realIndex].opposite && w.config.yaxis.length !== 0) xPad *= -1;
  11486. var textAnchor = this.getTextAnchor(w.config.yaxis[realIndex].labels.align, w.config.yaxis[realIndex].opposite);
  11487. var yColors = this.axesUtils.getYAxisForeColor(yaxisStyle.colors, realIndex);
  11488. var foreColor = Array.isArray(yColors) ? yColors[i] : yColors;
  11489. var existingYLabels = Utils$1.listToArray(w.globals.dom.baseEl.querySelectorAll(".apexcharts-yaxis[rel='".concat(realIndex, "'] .apexcharts-yaxis-label tspan"))).map(function (label) {
  11490. return label.textContent;
  11491. });
  11492. var label = graphics.drawText({
  11493. x: xPad,
  11494. y: lY,
  11495. text: existingYLabels.includes(val) && !w.config.yaxis[realIndex].labels.showDuplicates ? '' : val,
  11496. textAnchor: textAnchor,
  11497. fontSize: yaxisFontSize,
  11498. fontFamily: yaxisFontFamily,
  11499. fontWeight: yaxisFontWeight,
  11500. maxWidth: w.config.yaxis[realIndex].labels.maxWidth,
  11501. foreColor: foreColor,
  11502. isPlainText: false,
  11503. cssClass: "apexcharts-yaxis-label ".concat(yaxisStyle.cssClass)
  11504. });
  11505. elYaxisTexts.add(label);
  11506. this.addTooltip(label, val);
  11507. if (w.config.yaxis[realIndex].labels.rotate !== 0) {
  11508. this.rotateLabel(graphics, label, firstLabel, w.config.yaxis[realIndex].labels.rotate);
  11509. }
  11510. lY += labelsDivider;
  11511. }
  11512. }
  11513. this.addYAxisTitle(graphics, elYaxis, realIndex);
  11514. this.addAxisBorder(graphics, elYaxis, realIndex, tickAmount, labelsDivider);
  11515. return elYaxis;
  11516. }
  11517. }, {
  11518. key: "getTextAnchor",
  11519. value: function getTextAnchor(align, opposite) {
  11520. if (align === 'left') return 'start';
  11521. if (align === 'center') return 'middle';
  11522. if (align === 'right') return 'end';
  11523. return opposite ? 'start' : 'end';
  11524. }
  11525. }, {
  11526. key: "addTooltip",
  11527. value: function addTooltip(label, val) {
  11528. var elTooltipTitle = document.createElementNS(this.w.globals.SVGNS, 'title');
  11529. elTooltipTitle.textContent = Array.isArray(val) ? val.join(' ') : val;
  11530. label.node.appendChild(elTooltipTitle);
  11531. }
  11532. }, {
  11533. key: "rotateLabel",
  11534. value: function rotateLabel(graphics, label, firstLabel, rotate) {
  11535. var firstLabelCenter = graphics.rotateAroundCenter(firstLabel.node);
  11536. var labelCenter = graphics.rotateAroundCenter(label.node);
  11537. label.node.setAttribute('transform', "rotate(".concat(rotate, " ").concat(firstLabelCenter.x, " ").concat(labelCenter.y, ")"));
  11538. }
  11539. }, {
  11540. key: "addYAxisTitle",
  11541. value: function addYAxisTitle(graphics, elYaxis, realIndex) {
  11542. var w = this.w;
  11543. if (w.config.yaxis[realIndex].title.text !== undefined) {
  11544. var elYaxisTitle = graphics.group({
  11545. class: 'apexcharts-yaxis-title'
  11546. });
  11547. var x = w.config.yaxis[realIndex].opposite ? w.globals.translateYAxisX[realIndex] : 0;
  11548. var elYAxisTitleText = graphics.drawText({
  11549. x: x,
  11550. y: w.globals.gridHeight / 2 + w.globals.translateY + w.config.yaxis[realIndex].title.offsetY,
  11551. text: w.config.yaxis[realIndex].title.text,
  11552. textAnchor: 'end',
  11553. foreColor: w.config.yaxis[realIndex].title.style.color,
  11554. fontSize: w.config.yaxis[realIndex].title.style.fontSize,
  11555. fontWeight: w.config.yaxis[realIndex].title.style.fontWeight,
  11556. fontFamily: w.config.yaxis[realIndex].title.style.fontFamily,
  11557. cssClass: "apexcharts-yaxis-title-text ".concat(w.config.yaxis[realIndex].title.style.cssClass)
  11558. });
  11559. elYaxisTitle.add(elYAxisTitleText);
  11560. elYaxis.add(elYaxisTitle);
  11561. }
  11562. }
  11563. }, {
  11564. key: "addAxisBorder",
  11565. value: function addAxisBorder(graphics, elYaxis, realIndex, tickAmount, labelsDivider) {
  11566. var w = this.w;
  11567. var axisBorder = w.config.yaxis[realIndex].axisBorder;
  11568. var x = 31 + axisBorder.offsetX;
  11569. if (w.config.yaxis[realIndex].opposite) x = -31 - axisBorder.offsetX;
  11570. if (axisBorder.show) {
  11571. 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);
  11572. elYaxis.add(elVerticalLine);
  11573. }
  11574. if (w.config.yaxis[realIndex].axisTicks.show) {
  11575. this.axesUtils.drawYAxisTicks(x, tickAmount, axisBorder, w.config.yaxis[realIndex].axisTicks, realIndex, labelsDivider, elYaxis);
  11576. }
  11577. }
  11578. }, {
  11579. key: "drawYaxisInversed",
  11580. value: function drawYaxisInversed(realIndex) {
  11581. var w = this.w;
  11582. var graphics = new Graphics(this.ctx);
  11583. var elXaxis = graphics.group({
  11584. class: 'apexcharts-xaxis apexcharts-yaxis-inversed'
  11585. });
  11586. var elXaxisTexts = graphics.group({
  11587. class: 'apexcharts-xaxis-texts-g',
  11588. transform: "translate(".concat(w.globals.translateXAxisX, ", ").concat(w.globals.translateXAxisY, ")")
  11589. });
  11590. elXaxis.add(elXaxisTexts);
  11591. var tickAmount = w.globals.yAxisScale[realIndex].result.length - 1;
  11592. var labelsDivider = w.globals.gridWidth / tickAmount + 0.1;
  11593. var l = labelsDivider + w.config.xaxis.labels.offsetX;
  11594. var lbFormatter = w.globals.xLabelFormatter;
  11595. var labels = this.axesUtils.checkForReversedLabels(realIndex, w.globals.yAxisScale[realIndex].result.slice());
  11596. var timescaleLabels = w.globals.timescaleLabels;
  11597. if (timescaleLabels.length > 0) {
  11598. this.xaxisLabels = timescaleLabels.slice();
  11599. labels = timescaleLabels.slice();
  11600. tickAmount = labels.length;
  11601. }
  11602. if (w.config.xaxis.labels.show) {
  11603. for (var i = timescaleLabels.length ? 0 : tickAmount; timescaleLabels.length ? i < timescaleLabels.length : i >= 0; timescaleLabels.length ? i++ : i--) {
  11604. var val = lbFormatter(labels[i], i, w);
  11605. var x = w.globals.gridWidth + w.globals.padHorizontal - (l - labelsDivider + w.config.xaxis.labels.offsetX);
  11606. if (timescaleLabels.length) {
  11607. var label = this.axesUtils.getLabel(labels, timescaleLabels, x, i, this.drawnLabels, this.xaxisFontSize);
  11608. x = label.x;
  11609. val = label.text;
  11610. this.drawnLabels.push(label.text);
  11611. if (i === 0 && w.globals.skipFirstTimelinelabel) val = '';
  11612. if (i === labels.length - 1 && w.globals.skipLastTimelinelabel) val = '';
  11613. }
  11614. var elTick = graphics.drawText({
  11615. x: x,
  11616. y: this.xAxisoffX + w.config.xaxis.labels.offsetY + 30 - (w.config.xaxis.position === 'top' ? w.globals.xAxisHeight + w.config.xaxis.axisTicks.height - 2 : 0),
  11617. text: val,
  11618. textAnchor: 'middle',
  11619. foreColor: Array.isArray(this.xaxisForeColors) ? this.xaxisForeColors[realIndex] : this.xaxisForeColors,
  11620. fontSize: this.xaxisFontSize,
  11621. fontFamily: this.xaxisFontFamily,
  11622. fontWeight: w.config.xaxis.labels.style.fontWeight,
  11623. isPlainText: false,
  11624. cssClass: "apexcharts-xaxis-label ".concat(w.config.xaxis.labels.style.cssClass)
  11625. });
  11626. elXaxisTexts.add(elTick);
  11627. elTick.tspan(val);
  11628. this.addTooltip(elTick, val);
  11629. l += labelsDivider;
  11630. }
  11631. }
  11632. this.inversedYAxisTitleText(elXaxis);
  11633. this.inversedYAxisBorder(elXaxis);
  11634. return elXaxis;
  11635. }
  11636. }, {
  11637. key: "inversedYAxisBorder",
  11638. value: function inversedYAxisBorder(parent) {
  11639. var w = this.w;
  11640. var graphics = new Graphics(this.ctx);
  11641. var axisBorder = w.config.xaxis.axisBorder;
  11642. if (axisBorder.show) {
  11643. var lineCorrection = 0;
  11644. if (w.config.chart.type === 'bar' && w.globals.isXNumeric) lineCorrection -= 15;
  11645. var elHorzLine = graphics.drawLine(w.globals.padHorizontal + lineCorrection + axisBorder.offsetX, this.xAxisoffX, w.globals.gridWidth, this.xAxisoffX, axisBorder.color, 0, axisBorder.height);
  11646. if (this.elgrid && this.elgrid.elGridBorders && w.config.grid.show) {
  11647. this.elgrid.elGridBorders.add(elHorzLine);
  11648. } else {
  11649. parent.add(elHorzLine);
  11650. }
  11651. }
  11652. }
  11653. }, {
  11654. key: "inversedYAxisTitleText",
  11655. value: function inversedYAxisTitleText(parent) {
  11656. var w = this.w;
  11657. var graphics = new Graphics(this.ctx);
  11658. if (w.config.xaxis.title.text !== undefined) {
  11659. var elYaxisTitle = graphics.group({
  11660. class: 'apexcharts-xaxis-title apexcharts-yaxis-title-inversed'
  11661. });
  11662. var elYAxisTitleText = graphics.drawText({
  11663. x: w.globals.gridWidth / 2 + w.config.xaxis.title.offsetX,
  11664. y: this.xAxisoffX + parseFloat(this.xaxisFontSize) + parseFloat(w.config.xaxis.title.style.fontSize) + w.config.xaxis.title.offsetY + 20,
  11665. text: w.config.xaxis.title.text,
  11666. textAnchor: 'middle',
  11667. fontSize: w.config.xaxis.title.style.fontSize,
  11668. fontFamily: w.config.xaxis.title.style.fontFamily,
  11669. fontWeight: w.config.xaxis.title.style.fontWeight,
  11670. foreColor: w.config.xaxis.title.style.color,
  11671. cssClass: "apexcharts-xaxis-title-text ".concat(w.config.xaxis.title.style.cssClass)
  11672. });
  11673. elYaxisTitle.add(elYAxisTitleText);
  11674. parent.add(elYaxisTitle);
  11675. }
  11676. }
  11677. }, {
  11678. key: "yAxisTitleRotate",
  11679. value: function yAxisTitleRotate(realIndex, yAxisOpposite) {
  11680. var w = this.w;
  11681. var graphics = new Graphics(this.ctx);
  11682. var elYAxisLabelsWrap = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(realIndex, "'] .apexcharts-yaxis-texts-g"));
  11683. var yAxisLabelsCoord = elYAxisLabelsWrap ? elYAxisLabelsWrap.getBoundingClientRect() : {
  11684. width: 0,
  11685. height: 0
  11686. };
  11687. var yAxisTitle = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(realIndex, "'] .apexcharts-yaxis-title text"));
  11688. var yAxisTitleCoord = yAxisTitle ? yAxisTitle.getBoundingClientRect() : {
  11689. width: 0,
  11690. height: 0
  11691. };
  11692. if (yAxisTitle) {
  11693. var x = this.xPaddingForYAxisTitle(realIndex, yAxisLabelsCoord, yAxisTitleCoord, yAxisOpposite);
  11694. yAxisTitle.setAttribute('x', x.xPos - (yAxisOpposite ? 10 : 0));
  11695. var titleRotatingCenter = graphics.rotateAroundCenter(yAxisTitle);
  11696. 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, ")"));
  11697. }
  11698. }
  11699. }, {
  11700. key: "xPaddingForYAxisTitle",
  11701. value: function xPaddingForYAxisTitle(realIndex, yAxisLabelsCoord, yAxisTitleCoord, yAxisOpposite) {
  11702. var w = this.w;
  11703. var x = 0;
  11704. var padd = 10;
  11705. if (w.config.yaxis[realIndex].title.text === undefined || realIndex < 0) {
  11706. return {
  11707. xPos: x,
  11708. padd: 0
  11709. };
  11710. }
  11711. if (yAxisOpposite) {
  11712. x = yAxisLabelsCoord.width + w.config.yaxis[realIndex].title.offsetX + yAxisTitleCoord.width / 2 + padd / 2;
  11713. } else {
  11714. x = yAxisLabelsCoord.width * -1 + w.config.yaxis[realIndex].title.offsetX + padd / 2 + yAxisTitleCoord.width / 2;
  11715. if (w.globals.isBarHorizontal) {
  11716. padd = 25;
  11717. x = yAxisLabelsCoord.width * -1 - w.config.yaxis[realIndex].title.offsetX - padd;
  11718. }
  11719. }
  11720. return {
  11721. xPos: x,
  11722. padd: padd
  11723. };
  11724. }
  11725. }, {
  11726. key: "setYAxisXPosition",
  11727. value: function setYAxisXPosition(yaxisLabelCoords, yTitleCoords) {
  11728. var w = this.w;
  11729. var xLeft = 0;
  11730. var xRight = 0;
  11731. var leftOffsetX = 18;
  11732. var rightOffsetX = 1;
  11733. if (w.config.yaxis.length > 1) this.multipleYs = true;
  11734. w.config.yaxis.forEach(function (yaxe, index) {
  11735. var shouldNotDrawAxis = w.globals.ignoreYAxisIndexes.includes(index) || !yaxe.show || yaxe.floating || yaxisLabelCoords[index].width === 0;
  11736. var axisWidth = yaxisLabelCoords[index].width + yTitleCoords[index].width;
  11737. if (!yaxe.opposite) {
  11738. xLeft = w.globals.translateX - leftOffsetX;
  11739. if (!shouldNotDrawAxis) leftOffsetX += axisWidth + 20;
  11740. w.globals.translateYAxisX[index] = xLeft + yaxe.labels.offsetX;
  11741. } else {
  11742. if (w.globals.isBarHorizontal) {
  11743. xRight = w.globals.gridWidth + w.globals.translateX - 1;
  11744. w.globals.translateYAxisX[index] = xRight - yaxe.labels.offsetX;
  11745. } else {
  11746. xRight = w.globals.gridWidth + w.globals.translateX + rightOffsetX;
  11747. if (!shouldNotDrawAxis) rightOffsetX += axisWidth + 20;
  11748. w.globals.translateYAxisX[index] = xRight - yaxe.labels.offsetX + 20;
  11749. }
  11750. }
  11751. });
  11752. }
  11753. }, {
  11754. key: "setYAxisTextAlignments",
  11755. value: function setYAxisTextAlignments() {
  11756. var w = this.w;
  11757. var yaxis = Utils$1.listToArray(w.globals.dom.baseEl.getElementsByClassName('apexcharts-yaxis'));
  11758. yaxis.forEach(function (y, index) {
  11759. var yaxe = w.config.yaxis[index];
  11760. if (yaxe && !yaxe.floating && yaxe.labels.align !== undefined) {
  11761. var yAxisInner = w.globals.dom.baseEl.querySelector(".apexcharts-yaxis[rel='".concat(index, "'] .apexcharts-yaxis-texts-g"));
  11762. var yAxisTexts = Utils$1.listToArray(w.globals.dom.baseEl.querySelectorAll(".apexcharts-yaxis[rel='".concat(index, "'] .apexcharts-yaxis-label")));
  11763. var rect = yAxisInner.getBoundingClientRect();
  11764. yAxisTexts.forEach(function (label) {
  11765. label.setAttribute('text-anchor', yaxe.labels.align);
  11766. });
  11767. if (yaxe.labels.align === 'left' && !yaxe.opposite) {
  11768. yAxisInner.setAttribute('transform', "translate(-".concat(rect.width, ", 0)"));
  11769. } else if (yaxe.labels.align === 'center') {
  11770. yAxisInner.setAttribute('transform', "translate(".concat(rect.width / 2 * (!yaxe.opposite ? -1 : 1), ", 0)"));
  11771. } else if (yaxe.labels.align === 'right' && yaxe.opposite) {
  11772. yAxisInner.setAttribute('transform', "translate(".concat(rect.width, ", 0)"));
  11773. }
  11774. }
  11775. });
  11776. }
  11777. }]);
  11778. return YAxis;
  11779. }();
  11780. var Events = /*#__PURE__*/function () {
  11781. function Events(ctx) {
  11782. _classCallCheck(this, Events);
  11783. this.ctx = ctx;
  11784. this.w = ctx.w;
  11785. this.documentEvent = Utils$1.bind(this.documentEvent, this);
  11786. }
  11787. _createClass(Events, [{
  11788. key: "addEventListener",
  11789. value: function addEventListener(name, handler) {
  11790. var w = this.w;
  11791. if (w.globals.events.hasOwnProperty(name)) {
  11792. w.globals.events[name].push(handler);
  11793. } else {
  11794. w.globals.events[name] = [handler];
  11795. }
  11796. }
  11797. }, {
  11798. key: "removeEventListener",
  11799. value: function removeEventListener(name, handler) {
  11800. var w = this.w;
  11801. if (!w.globals.events.hasOwnProperty(name)) {
  11802. return;
  11803. }
  11804. var index = w.globals.events[name].indexOf(handler);
  11805. if (index !== -1) {
  11806. w.globals.events[name].splice(index, 1);
  11807. }
  11808. }
  11809. }, {
  11810. key: "fireEvent",
  11811. value: function fireEvent(name, args) {
  11812. var w = this.w;
  11813. if (!w.globals.events.hasOwnProperty(name)) {
  11814. return;
  11815. }
  11816. if (!args || !args.length) {
  11817. args = [];
  11818. }
  11819. var evs = w.globals.events[name];
  11820. var l = evs.length;
  11821. for (var i = 0; i < l; i++) {
  11822. evs[i].apply(null, args);
  11823. }
  11824. }
  11825. }, {
  11826. key: "setupEventHandlers",
  11827. value: function setupEventHandlers() {
  11828. var _this = this;
  11829. var w = this.w;
  11830. var me = this.ctx;
  11831. var clickableArea = w.globals.dom.baseEl.querySelector(w.globals.chartClass);
  11832. this.ctx.eventList.forEach(function (event) {
  11833. clickableArea.addEventListener(event, function (e) {
  11834. var opts = Object.assign({}, w, {
  11835. seriesIndex: w.globals.axisCharts ? w.globals.capturedSeriesIndex : 0,
  11836. dataPointIndex: w.globals.capturedDataPointIndex
  11837. });
  11838. if (e.type === 'mousemove' || e.type === 'touchmove') {
  11839. if (typeof w.config.chart.events.mouseMove === 'function') {
  11840. w.config.chart.events.mouseMove(e, me, opts);
  11841. }
  11842. } else if (e.type === 'mouseleave' || e.type === 'touchleave') {
  11843. if (typeof w.config.chart.events.mouseLeave === 'function') {
  11844. w.config.chart.events.mouseLeave(e, me, opts);
  11845. }
  11846. } else if (e.type === 'mouseup' && e.which === 1 || e.type === 'touchend') {
  11847. if (typeof w.config.chart.events.click === 'function') {
  11848. w.config.chart.events.click(e, me, opts);
  11849. }
  11850. me.ctx.events.fireEvent('click', [e, me, opts]);
  11851. }
  11852. }, {
  11853. capture: false,
  11854. passive: true
  11855. });
  11856. });
  11857. this.ctx.eventList.forEach(function (event) {
  11858. w.globals.dom.baseEl.addEventListener(event, _this.documentEvent, {
  11859. passive: true
  11860. });
  11861. });
  11862. this.ctx.core.setupBrushHandler();
  11863. }
  11864. }, {
  11865. key: "documentEvent",
  11866. value: function documentEvent(e) {
  11867. var w = this.w;
  11868. var target = e.target.className;
  11869. if (e.type === 'click') {
  11870. var elMenu = w.globals.dom.baseEl.querySelector('.apexcharts-menu');
  11871. if (elMenu && elMenu.classList.contains('apexcharts-menu-open') && target !== 'apexcharts-menu-icon') {
  11872. elMenu.classList.remove('apexcharts-menu-open');
  11873. }
  11874. }
  11875. w.globals.clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
  11876. w.globals.clientY = e.type === 'touchmove' ? e.touches[0].clientY : e.clientY;
  11877. }
  11878. }]);
  11879. return Events;
  11880. }();
  11881. var Localization = /*#__PURE__*/function () {
  11882. function Localization(ctx) {
  11883. _classCallCheck(this, Localization);
  11884. this.ctx = ctx;
  11885. this.w = ctx.w;
  11886. }
  11887. _createClass(Localization, [{
  11888. key: "setCurrentLocaleValues",
  11889. value: function setCurrentLocaleValues(localeName) {
  11890. var locales = this.w.config.chart.locales;
  11891. // check if user has specified locales in global Apex variable
  11892. // if yes - then extend those with local chart's locale
  11893. if (window.Apex.chart && window.Apex.chart.locales && window.Apex.chart.locales.length > 0) {
  11894. locales = this.w.config.chart.locales.concat(window.Apex.chart.locales);
  11895. }
  11896. // find the locale from the array of locales which user has set (either by chart.defaultLocale or by calling setLocale() method.)
  11897. var selectedLocale = locales.filter(function (c) {
  11898. return c.name === localeName;
  11899. })[0];
  11900. if (selectedLocale) {
  11901. // create a complete locale object by extending defaults so you don't get undefined errors.
  11902. var ret = Utils$1.extend(en, selectedLocale);
  11903. // store these locale options in global var for ease access
  11904. this.w.globals.locale = ret.options;
  11905. } else {
  11906. throw new Error('Wrong locale name provided. Please make sure you set the correct locale name in options');
  11907. }
  11908. }
  11909. }]);
  11910. return Localization;
  11911. }();
  11912. var Axes = /*#__PURE__*/function () {
  11913. function Axes(ctx) {
  11914. _classCallCheck(this, Axes);
  11915. this.ctx = ctx;
  11916. this.w = ctx.w;
  11917. }
  11918. _createClass(Axes, [{
  11919. key: "drawAxis",
  11920. value: function drawAxis(type, elgrid) {
  11921. var _this = this;
  11922. var gl = this.w.globals;
  11923. var cnf = this.w.config;
  11924. var xAxis = new XAxis(this.ctx, elgrid);
  11925. var yAxis = new YAxis(this.ctx, elgrid);
  11926. if (gl.axisCharts && type !== 'radar') {
  11927. var elXaxis, elYaxis;
  11928. if (gl.isBarHorizontal) {
  11929. elYaxis = yAxis.drawYaxisInversed(0);
  11930. elXaxis = xAxis.drawXaxisInversed(0);
  11931. gl.dom.elGraphical.add(elXaxis);
  11932. gl.dom.elGraphical.add(elYaxis);
  11933. } else {
  11934. elXaxis = xAxis.drawXaxis();
  11935. gl.dom.elGraphical.add(elXaxis);
  11936. cnf.yaxis.map(function (yaxe, index) {
  11937. if (gl.ignoreYAxisIndexes.indexOf(index) === -1) {
  11938. elYaxis = yAxis.drawYaxis(index);
  11939. gl.dom.Paper.add(elYaxis);
  11940. if (_this.w.config.grid.position === 'back') {
  11941. var inner = gl.dom.Paper.children()[1];
  11942. inner.remove();
  11943. gl.dom.Paper.add(inner);
  11944. }
  11945. }
  11946. });
  11947. }
  11948. }
  11949. }
  11950. }]);
  11951. return Axes;
  11952. }();
  11953. var Crosshairs = /*#__PURE__*/function () {
  11954. function Crosshairs(ctx) {
  11955. _classCallCheck(this, Crosshairs);
  11956. this.ctx = ctx;
  11957. this.w = ctx.w;
  11958. }
  11959. _createClass(Crosshairs, [{
  11960. key: "drawXCrosshairs",
  11961. value: function drawXCrosshairs() {
  11962. var w = this.w;
  11963. var graphics = new Graphics(this.ctx);
  11964. var filters = new Filters(this.ctx);
  11965. var crosshairGradient = w.config.xaxis.crosshairs.fill.gradient;
  11966. var crosshairShadow = w.config.xaxis.crosshairs.dropShadow;
  11967. var fillType = w.config.xaxis.crosshairs.fill.type;
  11968. var gradientFrom = crosshairGradient.colorFrom;
  11969. var gradientTo = crosshairGradient.colorTo;
  11970. var opacityFrom = crosshairGradient.opacityFrom;
  11971. var opacityTo = crosshairGradient.opacityTo;
  11972. var stops = crosshairGradient.stops;
  11973. var shadow = 'none';
  11974. var dropShadow = crosshairShadow.enabled;
  11975. var shadowLeft = crosshairShadow.left;
  11976. var shadowTop = crosshairShadow.top;
  11977. var shadowBlur = crosshairShadow.blur;
  11978. var shadowColor = crosshairShadow.color;
  11979. var shadowOpacity = crosshairShadow.opacity;
  11980. var xcrosshairsFill = w.config.xaxis.crosshairs.fill.color;
  11981. if (w.config.xaxis.crosshairs.show) {
  11982. if (fillType === 'gradient') {
  11983. xcrosshairsFill = graphics.drawGradient('vertical', gradientFrom, gradientTo, opacityFrom, opacityTo, null, stops, null);
  11984. }
  11985. var xcrosshairs = graphics.drawRect();
  11986. if (w.config.xaxis.crosshairs.width === 1) {
  11987. // to prevent drawing 2 lines, convert rect to line
  11988. xcrosshairs = graphics.drawLine();
  11989. }
  11990. var gridHeight = w.globals.gridHeight;
  11991. if (!Utils$1.isNumber(gridHeight) || gridHeight < 0) {
  11992. gridHeight = 0;
  11993. }
  11994. var crosshairsWidth = w.config.xaxis.crosshairs.width;
  11995. if (!Utils$1.isNumber(crosshairsWidth) || crosshairsWidth < 0) {
  11996. crosshairsWidth = 0;
  11997. }
  11998. xcrosshairs.attr({
  11999. class: 'apexcharts-xcrosshairs',
  12000. x: 0,
  12001. y: 0,
  12002. y2: gridHeight,
  12003. width: crosshairsWidth,
  12004. height: gridHeight,
  12005. fill: xcrosshairsFill,
  12006. filter: shadow,
  12007. 'fill-opacity': w.config.xaxis.crosshairs.opacity,
  12008. stroke: w.config.xaxis.crosshairs.stroke.color,
  12009. 'stroke-width': w.config.xaxis.crosshairs.stroke.width,
  12010. 'stroke-dasharray': w.config.xaxis.crosshairs.stroke.dashArray
  12011. });
  12012. if (dropShadow) {
  12013. xcrosshairs = filters.dropShadow(xcrosshairs, {
  12014. left: shadowLeft,
  12015. top: shadowTop,
  12016. blur: shadowBlur,
  12017. color: shadowColor,
  12018. opacity: shadowOpacity
  12019. });
  12020. }
  12021. w.globals.dom.elGraphical.add(xcrosshairs);
  12022. }
  12023. }
  12024. }, {
  12025. key: "drawYCrosshairs",
  12026. value: function drawYCrosshairs() {
  12027. var w = this.w;
  12028. var graphics = new Graphics(this.ctx);
  12029. var crosshair = w.config.yaxis[0].crosshairs;
  12030. var offX = w.globals.barPadForNumericAxis;
  12031. if (w.config.yaxis[0].crosshairs.show) {
  12032. var ycrosshairs = graphics.drawLine(-offX, 0, w.globals.gridWidth + offX, 0, crosshair.stroke.color, crosshair.stroke.dashArray, crosshair.stroke.width);
  12033. ycrosshairs.attr({
  12034. class: 'apexcharts-ycrosshairs'
  12035. });
  12036. w.globals.dom.elGraphical.add(ycrosshairs);
  12037. }
  12038. // draw an invisible crosshair to help in positioning the yaxis tooltip
  12039. var ycrosshairsHidden = graphics.drawLine(-offX, 0, w.globals.gridWidth + offX, 0, crosshair.stroke.color, 0, 0);
  12040. ycrosshairsHidden.attr({
  12041. class: 'apexcharts-ycrosshairs-hidden'
  12042. });
  12043. w.globals.dom.elGraphical.add(ycrosshairsHidden);
  12044. }
  12045. }]);
  12046. return Crosshairs;
  12047. }();
  12048. /**
  12049. * ApexCharts Responsive Class to override options for different screen sizes.
  12050. *
  12051. * @module Responsive
  12052. **/
  12053. var Responsive = /*#__PURE__*/function () {
  12054. function Responsive(ctx) {
  12055. _classCallCheck(this, Responsive);
  12056. this.ctx = ctx;
  12057. this.w = ctx.w;
  12058. }
  12059. // the opts parameter if not null has to be set overriding everything
  12060. // as the opts is set by user externally
  12061. _createClass(Responsive, [{
  12062. key: "checkResponsiveConfig",
  12063. value: function checkResponsiveConfig(opts) {
  12064. var _this = this;
  12065. var w = this.w;
  12066. var cnf = w.config;
  12067. // check if responsive config exists
  12068. if (cnf.responsive.length === 0) return;
  12069. var res = cnf.responsive.slice();
  12070. res.sort(function (a, b) {
  12071. return a.breakpoint > b.breakpoint ? 1 : b.breakpoint > a.breakpoint ? -1 : 0;
  12072. }).reverse();
  12073. var config = new Config({});
  12074. var iterateResponsiveOptions = function iterateResponsiveOptions() {
  12075. var newOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12076. var largestBreakpoint = res[0].breakpoint;
  12077. var width = window.innerWidth > 0 ? window.innerWidth : screen.width;
  12078. if (width > largestBreakpoint) {
  12079. var initialConfig = Utils$1.clone(w.globals.initialConfig);
  12080. // Retain state of series in case any have been collapsed
  12081. // (indicated by series.data === [], these series' will be zeroed later
  12082. // enabling stacking to work correctly)
  12083. initialConfig.series = Utils$1.clone(w.config.series);
  12084. var options = CoreUtils.extendArrayProps(config, initialConfig, w);
  12085. newOptions = Utils$1.extend(options, newOptions);
  12086. newOptions = Utils$1.extend(w.config, newOptions);
  12087. _this.overrideResponsiveOptions(newOptions);
  12088. } else {
  12089. for (var i = 0; i < res.length; i++) {
  12090. if (width < res[i].breakpoint) {
  12091. newOptions = CoreUtils.extendArrayProps(config, res[i].options, w);
  12092. newOptions = Utils$1.extend(w.config, newOptions);
  12093. _this.overrideResponsiveOptions(newOptions);
  12094. }
  12095. }
  12096. }
  12097. };
  12098. if (opts) {
  12099. var options = CoreUtils.extendArrayProps(config, opts, w);
  12100. options = Utils$1.extend(w.config, options);
  12101. options = Utils$1.extend(options, opts);
  12102. iterateResponsiveOptions(options);
  12103. } else {
  12104. iterateResponsiveOptions({});
  12105. }
  12106. }
  12107. }, {
  12108. key: "overrideResponsiveOptions",
  12109. value: function overrideResponsiveOptions(newOptions) {
  12110. var newConfig = new Config(newOptions).init({
  12111. responsiveOverride: true
  12112. });
  12113. this.w.config = newConfig;
  12114. }
  12115. }]);
  12116. return Responsive;
  12117. }();
  12118. /**
  12119. * ApexCharts Theme Class for setting the colors and palettes.
  12120. *
  12121. * @module Theme
  12122. **/
  12123. var Theme = /*#__PURE__*/function () {
  12124. function Theme(ctx) {
  12125. _classCallCheck(this, Theme);
  12126. this.ctx = ctx;
  12127. this.w = ctx.w;
  12128. this.colors = [];
  12129. this.isColorFn = false;
  12130. this.isHeatmapDistributed = this.checkHeatmapDistributed();
  12131. this.isBarDistributed = this.checkBarDistributed();
  12132. }
  12133. _createClass(Theme, [{
  12134. key: "checkHeatmapDistributed",
  12135. value: function checkHeatmapDistributed() {
  12136. var _this$w$config = this.w.config,
  12137. chart = _this$w$config.chart,
  12138. plotOptions = _this$w$config.plotOptions;
  12139. return chart.type === 'treemap' && plotOptions.treemap && plotOptions.treemap.distributed || chart.type === 'heatmap' && plotOptions.heatmap && plotOptions.heatmap.distributed;
  12140. }
  12141. }, {
  12142. key: "checkBarDistributed",
  12143. value: function checkBarDistributed() {
  12144. var _this$w$config2 = this.w.config,
  12145. chart = _this$w$config2.chart,
  12146. plotOptions = _this$w$config2.plotOptions;
  12147. return plotOptions.bar && plotOptions.bar.distributed && (chart.type === 'bar' || chart.type === 'rangeBar');
  12148. }
  12149. }, {
  12150. key: "init",
  12151. value: function init() {
  12152. this.setDefaultColors();
  12153. }
  12154. }, {
  12155. key: "setDefaultColors",
  12156. value: function setDefaultColors() {
  12157. var w = this.w;
  12158. var utils = new Utils$1();
  12159. w.globals.dom.elWrap.classList.add("apexcharts-theme-".concat(w.config.theme.mode));
  12160. // Create a copy of config.colors array to avoid mutating the original config.colors
  12161. var configColors = _toConsumableArray(w.config.colors || w.config.fill.colors || []);
  12162. w.globals.colors = this.getColors(configColors);
  12163. this.applySeriesColors(w.globals.seriesColors, w.globals.colors);
  12164. if (w.config.theme.monochrome.enabled) {
  12165. w.globals.colors = this.getMonochromeColors(w.config.theme.monochrome, w.globals.series, utils);
  12166. }
  12167. var defaultColors = w.globals.colors.slice();
  12168. this.pushExtraColors(w.globals.colors);
  12169. this.applyColorTypes(['fill', 'stroke'], defaultColors);
  12170. this.applyDataLabelsColors(defaultColors);
  12171. this.applyRadarPolygonsColors();
  12172. this.applyMarkersColors(defaultColors);
  12173. }
  12174. }, {
  12175. key: "getColors",
  12176. value: function getColors(configColors) {
  12177. var _this = this;
  12178. var w = this.w;
  12179. if (!configColors || configColors.length === 0) {
  12180. return this.predefined();
  12181. }
  12182. if (Array.isArray(configColors) && configColors.length > 0 && typeof configColors[0] === 'function') {
  12183. this.isColorFn = true;
  12184. return w.config.series.map(function (s, i) {
  12185. var c = configColors[i] || configColors[0];
  12186. return typeof c === 'function' ? c({
  12187. value: w.globals.axisCharts ? w.globals.series[i][0] || 0 : w.globals.series[i],
  12188. seriesIndex: i,
  12189. dataPointIndex: i,
  12190. w: _this.w
  12191. }) : c;
  12192. });
  12193. }
  12194. return configColors;
  12195. }
  12196. }, {
  12197. key: "applySeriesColors",
  12198. value: function applySeriesColors(seriesColors, globalsColors) {
  12199. seriesColors.forEach(function (c, i) {
  12200. if (c) {
  12201. globalsColors[i] = c;
  12202. }
  12203. });
  12204. }
  12205. }, {
  12206. key: "getMonochromeColors",
  12207. value: function getMonochromeColors(monochrome, series, utils) {
  12208. var color = monochrome.color,
  12209. shadeIntensity = monochrome.shadeIntensity,
  12210. shadeTo = monochrome.shadeTo;
  12211. var glsCnt = this.isBarDistributed || this.isHeatmapDistributed ? series[0].length * series.length : series.length;
  12212. var part = 1 / (glsCnt / shadeIntensity);
  12213. var percent = 0;
  12214. return Array.from({
  12215. length: glsCnt
  12216. }, function () {
  12217. var newColor = shadeTo === 'dark' ? utils.shadeColor(percent * -1, color) : utils.shadeColor(percent, color);
  12218. percent += part;
  12219. return newColor;
  12220. });
  12221. }
  12222. }, {
  12223. key: "applyColorTypes",
  12224. value: function applyColorTypes(colorTypes, defaultColors) {
  12225. var _this2 = this;
  12226. var w = this.w;
  12227. colorTypes.forEach(function (c) {
  12228. w.globals[c].colors = w.config[c].colors === undefined ? _this2.isColorFn ? w.config.colors : defaultColors : w.config[c].colors.slice();
  12229. _this2.pushExtraColors(w.globals[c].colors);
  12230. });
  12231. }
  12232. }, {
  12233. key: "applyDataLabelsColors",
  12234. value: function applyDataLabelsColors(defaultColors) {
  12235. var w = this.w;
  12236. w.globals.dataLabels.style.colors = w.config.dataLabels.style.colors === undefined ? defaultColors : w.config.dataLabels.style.colors.slice();
  12237. this.pushExtraColors(w.globals.dataLabels.style.colors, 50);
  12238. }
  12239. }, {
  12240. key: "applyRadarPolygonsColors",
  12241. value: function applyRadarPolygonsColors() {
  12242. var w = this.w;
  12243. w.globals.radarPolygons.fill.colors = w.config.plotOptions.radar.polygons.fill.colors === undefined ? [w.config.theme.mode === 'dark' ? '#424242' : 'none'] : w.config.plotOptions.radar.polygons.fill.colors.slice();
  12244. this.pushExtraColors(w.globals.radarPolygons.fill.colors, 20);
  12245. }
  12246. }, {
  12247. key: "applyMarkersColors",
  12248. value: function applyMarkersColors(defaultColors) {
  12249. var w = this.w;
  12250. w.globals.markers.colors = w.config.markers.colors === undefined ? defaultColors : w.config.markers.colors.slice();
  12251. this.pushExtraColors(w.globals.markers.colors);
  12252. }
  12253. }, {
  12254. key: "pushExtraColors",
  12255. value: function pushExtraColors(colorSeries, length) {
  12256. var distributed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12257. var w = this.w;
  12258. var len = length || w.globals.series.length;
  12259. if (distributed === null) {
  12260. distributed = this.isBarDistributed || this.isHeatmapDistributed || w.config.chart.type === 'heatmap' && w.config.plotOptions.heatmap && w.config.plotOptions.heatmap.colorScale.inverse;
  12261. }
  12262. if (distributed && w.globals.series.length) {
  12263. len = w.globals.series[w.globals.maxValsInArrayIndex].length * w.globals.series.length;
  12264. }
  12265. if (colorSeries.length < len) {
  12266. var diff = len - colorSeries.length;
  12267. for (var i = 0; i < diff; i++) {
  12268. colorSeries.push(colorSeries[i]);
  12269. }
  12270. }
  12271. }
  12272. }, {
  12273. key: "updateThemeOptions",
  12274. value: function updateThemeOptions(options) {
  12275. options.chart = options.chart || {};
  12276. options.tooltip = options.tooltip || {};
  12277. var mode = options.theme.mode;
  12278. var palette = mode === 'dark' ? 'palette4' : mode === 'light' ? 'palette1' : options.theme.palette || 'palette1';
  12279. var foreColor = mode === 'dark' ? '#f6f7f8' : mode === 'light' ? '#373d3f' : options.chart.foreColor || '#373d3f';
  12280. options.tooltip.theme = mode || 'light';
  12281. options.chart.foreColor = foreColor;
  12282. options.theme.palette = palette;
  12283. return options;
  12284. }
  12285. }, {
  12286. key: "predefined",
  12287. value: function predefined() {
  12288. var palette = this.w.config.theme.palette;
  12289. var palettes = {
  12290. palette1: ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0'],
  12291. palette2: ['#3f51b5', '#03a9f4', '#4caf50', '#f9ce1d', '#FF9800'],
  12292. palette3: ['#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B'],
  12293. palette4: ['#4ecdc4', '#c7f464', '#81D4FA', '#fd6a6a', '#546E7A'],
  12294. palette5: ['#2b908f', '#f9a3a4', '#90ee7e', '#fa4443', '#69d2e7'],
  12295. palette6: ['#449DD1', '#F86624', '#EA3546', '#662E9B', '#C5D86D'],
  12296. palette7: ['#D7263D', '#1B998B', '#2E294E', '#F46036', '#E2C044'],
  12297. palette8: ['#662E9B', '#F86624', '#F9C80E', '#EA3546', '#43BCCD'],
  12298. palette9: ['#5C4742', '#A5978B', '#8D5B4C', '#5A2A27', '#C4BBAF'],
  12299. palette10: ['#A300D6', '#7D02EB', '#5653FE', '#2983FF', '#00B1F2'],
  12300. default: ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0']
  12301. };
  12302. return palettes[palette] || palettes.default;
  12303. }
  12304. }]);
  12305. return Theme;
  12306. }();
  12307. var TitleSubtitle = /*#__PURE__*/function () {
  12308. function TitleSubtitle(ctx) {
  12309. _classCallCheck(this, TitleSubtitle);
  12310. this.ctx = ctx;
  12311. this.w = ctx.w;
  12312. }
  12313. _createClass(TitleSubtitle, [{
  12314. key: "draw",
  12315. value: function draw() {
  12316. this.drawTitleSubtitle('title');
  12317. this.drawTitleSubtitle('subtitle');
  12318. }
  12319. }, {
  12320. key: "drawTitleSubtitle",
  12321. value: function drawTitleSubtitle(type) {
  12322. var w = this.w;
  12323. var tsConfig = type === 'title' ? w.config.title : w.config.subtitle;
  12324. var x = w.globals.svgWidth / 2;
  12325. var y = tsConfig.offsetY;
  12326. var textAnchor = 'middle';
  12327. if (tsConfig.align === 'left') {
  12328. x = 10;
  12329. textAnchor = 'start';
  12330. } else if (tsConfig.align === 'right') {
  12331. x = w.globals.svgWidth - 10;
  12332. textAnchor = 'end';
  12333. }
  12334. x = x + tsConfig.offsetX;
  12335. y = y + parseInt(tsConfig.style.fontSize, 10) + tsConfig.margin / 2;
  12336. if (tsConfig.text !== undefined) {
  12337. var graphics = new Graphics(this.ctx);
  12338. var titleText = graphics.drawText({
  12339. x: x,
  12340. y: y,
  12341. text: tsConfig.text,
  12342. textAnchor: textAnchor,
  12343. fontSize: tsConfig.style.fontSize,
  12344. fontFamily: tsConfig.style.fontFamily,
  12345. fontWeight: tsConfig.style.fontWeight,
  12346. foreColor: tsConfig.style.color,
  12347. opacity: 1
  12348. });
  12349. titleText.node.setAttribute('class', "apexcharts-".concat(type, "-text"));
  12350. w.globals.dom.Paper.add(titleText);
  12351. }
  12352. }
  12353. }]);
  12354. return TitleSubtitle;
  12355. }();
  12356. var Helpers$3 = /*#__PURE__*/function () {
  12357. function Helpers(dCtx) {
  12358. _classCallCheck(this, Helpers);
  12359. this.w = dCtx.w;
  12360. this.dCtx = dCtx;
  12361. }
  12362. /**
  12363. * Get Chart Title/Subtitle Dimensions
  12364. * @memberof Dimensions
  12365. * @return {{width, height}}
  12366. **/
  12367. _createClass(Helpers, [{
  12368. key: "getTitleSubtitleCoords",
  12369. value: function getTitleSubtitleCoords(type) {
  12370. var w = this.w;
  12371. var width = 0;
  12372. var height = 0;
  12373. var floating = type === 'title' ? w.config.title.floating : w.config.subtitle.floating;
  12374. var el = w.globals.dom.baseEl.querySelector(".apexcharts-".concat(type, "-text"));
  12375. if (el !== null && !floating) {
  12376. var coord = el.getBoundingClientRect();
  12377. width = coord.width;
  12378. height = w.globals.axisCharts ? coord.height + 5 : coord.height;
  12379. }
  12380. return {
  12381. width: width,
  12382. height: height
  12383. };
  12384. }
  12385. }, {
  12386. key: "getLegendsRect",
  12387. value: function getLegendsRect() {
  12388. var w = this.w;
  12389. var elLegendWrap = w.globals.dom.elLegendWrap;
  12390. if (!w.config.legend.height && (w.config.legend.position === 'top' || w.config.legend.position === 'bottom')) {
  12391. // avoid legend to take up all the space
  12392. elLegendWrap.style.maxHeight = w.globals.svgHeight / 2 + 'px';
  12393. }
  12394. var lgRect = Object.assign({}, Utils$1.getBoundingClientRect(elLegendWrap));
  12395. if (elLegendWrap !== null && !w.config.legend.floating && w.config.legend.show) {
  12396. this.dCtx.lgRect = {
  12397. x: lgRect.x,
  12398. y: lgRect.y,
  12399. height: lgRect.height,
  12400. width: lgRect.height === 0 ? 0 : lgRect.width
  12401. };
  12402. } else {
  12403. this.dCtx.lgRect = {
  12404. x: 0,
  12405. y: 0,
  12406. height: 0,
  12407. width: 0
  12408. };
  12409. }
  12410. // if legend takes up all of the chart space, we need to restrict it.
  12411. if (w.config.legend.position === 'left' || w.config.legend.position === 'right') {
  12412. if (this.dCtx.lgRect.width * 1.5 > w.globals.svgWidth) {
  12413. this.dCtx.lgRect.width = w.globals.svgWidth / 1.5;
  12414. }
  12415. }
  12416. return this.dCtx.lgRect;
  12417. }
  12418. /**
  12419. * Get Y Axis Dimensions
  12420. * @memberof Dimensions
  12421. * @return {{width, height}}
  12422. **/
  12423. }, {
  12424. key: "getDatalabelsRect",
  12425. value: function getDatalabelsRect() {
  12426. var _this = this;
  12427. var w = this.w;
  12428. var allLabels = [];
  12429. w.config.series.forEach(function (serie, seriesIndex) {
  12430. serie.data.forEach(function (datum, dataPointIndex) {
  12431. var getText = function getText(v) {
  12432. return w.config.dataLabels.formatter(v, {
  12433. ctx: _this.dCtx.ctx,
  12434. seriesIndex: seriesIndex,
  12435. dataPointIndex: dataPointIndex,
  12436. w: w
  12437. });
  12438. };
  12439. val = getText(w.globals.series[seriesIndex][dataPointIndex]);
  12440. allLabels.push(val);
  12441. });
  12442. });
  12443. var val = Utils$1.getLargestStringFromArr(allLabels);
  12444. var graphics = new Graphics(this.dCtx.ctx);
  12445. var dataLabelsStyle = w.config.dataLabels.style;
  12446. var labelrect = graphics.getTextRects(val, parseInt(dataLabelsStyle.fontSize), dataLabelsStyle.fontFamily);
  12447. return {
  12448. width: labelrect.width * 1.05,
  12449. height: labelrect.height
  12450. };
  12451. }
  12452. }, {
  12453. key: "getLargestStringFromMultiArr",
  12454. value: function getLargestStringFromMultiArr(val, arr) {
  12455. var w = this.w;
  12456. var valArr = val;
  12457. if (w.globals.isMultiLineX) {
  12458. // if the xaxis labels has multiline texts (array)
  12459. var maxArrs = arr.map(function (xl, idx) {
  12460. return Array.isArray(xl) ? xl.length : 1;
  12461. });
  12462. var maxArrLen = Math.max.apply(Math, _toConsumableArray(maxArrs));
  12463. var maxArrIndex = maxArrs.indexOf(maxArrLen);
  12464. valArr = arr[maxArrIndex];
  12465. }
  12466. return valArr;
  12467. }
  12468. }]);
  12469. return Helpers;
  12470. }();
  12471. var DimXAxis = /*#__PURE__*/function () {
  12472. function DimXAxis(dCtx) {
  12473. _classCallCheck(this, DimXAxis);
  12474. this.w = dCtx.w;
  12475. this.dCtx = dCtx;
  12476. }
  12477. /**
  12478. * Get X Axis Dimensions
  12479. * @memberof Dimensions
  12480. * @return {{width, height}}
  12481. **/
  12482. _createClass(DimXAxis, [{
  12483. key: "getxAxisLabelsCoords",
  12484. value: function getxAxisLabelsCoords() {
  12485. var w = this.w;
  12486. var xaxisLabels = w.globals.labels.slice();
  12487. if (w.config.xaxis.convertedCatToNumeric && xaxisLabels.length === 0) {
  12488. xaxisLabels = w.globals.categoryLabels;
  12489. }
  12490. var rect;
  12491. if (w.globals.timescaleLabels.length > 0) {
  12492. var coords = this.getxAxisTimeScaleLabelsCoords();
  12493. rect = {
  12494. width: coords.width,
  12495. height: coords.height
  12496. };
  12497. w.globals.rotateXLabels = false;
  12498. } else {
  12499. this.dCtx.lgWidthForSideLegends = (w.config.legend.position === 'left' || w.config.legend.position === 'right') && !w.config.legend.floating ? this.dCtx.lgRect.width : 0;
  12500. // get the longest string from the labels array and also apply label formatter
  12501. var xlbFormatter = w.globals.xLabelFormatter;
  12502. // prevent changing xaxisLabels to avoid issues in multi-yaxes - fix #522
  12503. var val = Utils$1.getLargestStringFromArr(xaxisLabels);
  12504. var valArr = this.dCtx.dimHelpers.getLargestStringFromMultiArr(val, xaxisLabels);
  12505. // the labels gets changed for bar charts
  12506. if (w.globals.isBarHorizontal) {
  12507. val = w.globals.yAxisScale[0].result.reduce(function (a, b) {
  12508. return a.length > b.length ? a : b;
  12509. }, 0);
  12510. valArr = val;
  12511. }
  12512. var xFormat = new Formatters(this.dCtx.ctx);
  12513. var timestamp = val;
  12514. val = xFormat.xLabelFormat(xlbFormatter, val, timestamp, {
  12515. i: undefined,
  12516. dateFormatter: new DateTime(this.dCtx.ctx).formatDate,
  12517. w: w
  12518. });
  12519. valArr = xFormat.xLabelFormat(xlbFormatter, valArr, timestamp, {
  12520. i: undefined,
  12521. dateFormatter: new DateTime(this.dCtx.ctx).formatDate,
  12522. w: w
  12523. });
  12524. if (w.config.xaxis.convertedCatToNumeric && typeof val === 'undefined' || String(val).trim() === '') {
  12525. val = '1';
  12526. valArr = val;
  12527. }
  12528. var graphics = new Graphics(this.dCtx.ctx);
  12529. var xLabelrect = graphics.getTextRects(val, w.config.xaxis.labels.style.fontSize);
  12530. var xArrLabelrect = xLabelrect;
  12531. if (val !== valArr) {
  12532. xArrLabelrect = graphics.getTextRects(valArr, w.config.xaxis.labels.style.fontSize);
  12533. }
  12534. rect = {
  12535. width: xLabelrect.width >= xArrLabelrect.width ? xLabelrect.width : xArrLabelrect.width,
  12536. height: xLabelrect.height >= xArrLabelrect.height ? xLabelrect.height : xArrLabelrect.height
  12537. };
  12538. 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) {
  12539. if (!w.globals.isBarHorizontal) {
  12540. w.globals.rotateXLabels = true;
  12541. var getRotatedTextRects = function getRotatedTextRects(text) {
  12542. 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);
  12543. };
  12544. xLabelrect = getRotatedTextRects(val);
  12545. if (val !== valArr) {
  12546. xArrLabelrect = getRotatedTextRects(valArr);
  12547. }
  12548. rect.height = (xLabelrect.height > xArrLabelrect.height ? xLabelrect.height : xArrLabelrect.height) / 1.5;
  12549. rect.width = xLabelrect.width > xArrLabelrect.width ? xLabelrect.width : xArrLabelrect.width;
  12550. }
  12551. } else {
  12552. w.globals.rotateXLabels = false;
  12553. }
  12554. }
  12555. if (!w.config.xaxis.labels.show) {
  12556. rect = {
  12557. width: 0,
  12558. height: 0
  12559. };
  12560. }
  12561. return {
  12562. width: rect.width,
  12563. height: rect.height
  12564. };
  12565. }
  12566. /**
  12567. * Get X Axis Label Group height
  12568. * @memberof Dimensions
  12569. * @return {{width, height}}
  12570. */
  12571. }, {
  12572. key: "getxAxisGroupLabelsCoords",
  12573. value: function getxAxisGroupLabelsCoords() {
  12574. var _w$config$xaxis$group;
  12575. var w = this.w;
  12576. if (!w.globals.hasXaxisGroups) {
  12577. return {
  12578. width: 0,
  12579. height: 0
  12580. };
  12581. }
  12582. 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;
  12583. var xaxisLabels = w.globals.groups.map(function (g) {
  12584. return g.title;
  12585. });
  12586. var rect;
  12587. // prevent changing xaxisLabels to avoid issues in multi-yaxes - fix #522
  12588. var val = Utils$1.getLargestStringFromArr(xaxisLabels);
  12589. var valArr = this.dCtx.dimHelpers.getLargestStringFromMultiArr(val, xaxisLabels);
  12590. var graphics = new Graphics(this.dCtx.ctx);
  12591. var xLabelrect = graphics.getTextRects(val, fontSize);
  12592. var xArrLabelrect = xLabelrect;
  12593. if (val !== valArr) {
  12594. xArrLabelrect = graphics.getTextRects(valArr, fontSize);
  12595. }
  12596. rect = {
  12597. width: xLabelrect.width >= xArrLabelrect.width ? xLabelrect.width : xArrLabelrect.width,
  12598. height: xLabelrect.height >= xArrLabelrect.height ? xLabelrect.height : xArrLabelrect.height
  12599. };
  12600. if (!w.config.xaxis.labels.show) {
  12601. rect = {
  12602. width: 0,
  12603. height: 0
  12604. };
  12605. }
  12606. return {
  12607. width: rect.width,
  12608. height: rect.height
  12609. };
  12610. }
  12611. /**
  12612. * Get X Axis Title Dimensions
  12613. * @memberof Dimensions
  12614. * @return {{width, height}}
  12615. **/
  12616. }, {
  12617. key: "getxAxisTitleCoords",
  12618. value: function getxAxisTitleCoords() {
  12619. var w = this.w;
  12620. var width = 0;
  12621. var height = 0;
  12622. if (w.config.xaxis.title.text !== undefined) {
  12623. var graphics = new Graphics(this.dCtx.ctx);
  12624. var rect = graphics.getTextRects(w.config.xaxis.title.text, w.config.xaxis.title.style.fontSize);
  12625. width = rect.width;
  12626. height = rect.height;
  12627. }
  12628. return {
  12629. width: width,
  12630. height: height
  12631. };
  12632. }
  12633. }, {
  12634. key: "getxAxisTimeScaleLabelsCoords",
  12635. value: function getxAxisTimeScaleLabelsCoords() {
  12636. var w = this.w;
  12637. var rect;
  12638. this.dCtx.timescaleLabels = w.globals.timescaleLabels.slice();
  12639. var labels = this.dCtx.timescaleLabels.map(function (label) {
  12640. return label.value;
  12641. });
  12642. // get the longest string from the labels array and also apply label formatter to it
  12643. var val = labels.reduce(function (a, b) {
  12644. // if undefined, maybe user didn't pass the datetime(x) values
  12645. if (typeof a === 'undefined') {
  12646. console.error('You have possibly supplied invalid Date format. Please supply a valid JavaScript Date');
  12647. return 0;
  12648. } else {
  12649. return a.length > b.length ? a : b;
  12650. }
  12651. }, 0);
  12652. var graphics = new Graphics(this.dCtx.ctx);
  12653. rect = graphics.getTextRects(val, w.config.xaxis.labels.style.fontSize);
  12654. var totalWidthRotated = rect.width * 1.05 * labels.length;
  12655. if (totalWidthRotated > w.globals.gridWidth && w.config.xaxis.labels.rotate !== 0) {
  12656. w.globals.overlappingXLabels = true;
  12657. }
  12658. return rect;
  12659. }
  12660. // In certain cases, the last labels gets cropped in xaxis.
  12661. // 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
  12662. }, {
  12663. key: "additionalPaddingXLabels",
  12664. value: function additionalPaddingXLabels(xaxisLabelCoords) {
  12665. var _this = this;
  12666. var w = this.w;
  12667. var gl = w.globals;
  12668. var cnf = w.config;
  12669. var xtype = cnf.xaxis.type;
  12670. var lbWidth = xaxisLabelCoords.width;
  12671. gl.skipLastTimelinelabel = false;
  12672. gl.skipFirstTimelinelabel = false;
  12673. var isBarOpposite = w.config.yaxis[0].opposite && w.globals.isBarHorizontal;
  12674. var isCollapsed = function isCollapsed(i) {
  12675. return gl.collapsedSeriesIndices.indexOf(i) !== -1;
  12676. };
  12677. var rightPad = function rightPad(yaxe) {
  12678. if (_this.dCtx.timescaleLabels && _this.dCtx.timescaleLabels.length) {
  12679. // for timeline labels, we take the last label and check if it exceeds gridWidth
  12680. var firstimescaleLabel = _this.dCtx.timescaleLabels[0];
  12681. var lastTimescaleLabel = _this.dCtx.timescaleLabels[_this.dCtx.timescaleLabels.length - 1];
  12682. var lastLabelPosition = lastTimescaleLabel.position + lbWidth / 1.75 - _this.dCtx.yAxisWidthRight;
  12683. var firstLabelPosition = firstimescaleLabel.position - lbWidth / 1.75 + _this.dCtx.yAxisWidthLeft;
  12684. var lgRightRectWidth = w.config.legend.position === 'right' && _this.dCtx.lgRect.width > 0 ? _this.dCtx.lgRect.width : 0;
  12685. if (lastLabelPosition > gl.svgWidth - gl.translateX - lgRightRectWidth) {
  12686. gl.skipLastTimelinelabel = true;
  12687. }
  12688. 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)) {
  12689. gl.skipFirstTimelinelabel = true;
  12690. }
  12691. } else if (xtype === 'datetime') {
  12692. // If user has enabled DateTime, but uses own's formatter
  12693. if (_this.dCtx.gridPad.right < lbWidth && !gl.rotateXLabels) {
  12694. gl.skipLastTimelinelabel = true;
  12695. }
  12696. } else if (xtype !== 'datetime') {
  12697. if (_this.dCtx.gridPad.right < lbWidth / 2 - _this.dCtx.yAxisWidthRight && !gl.rotateXLabels && !w.config.xaxis.labels.trim) {
  12698. _this.dCtx.xPadRight = lbWidth / 2 + 1;
  12699. }
  12700. }
  12701. };
  12702. var padYAxe = function padYAxe(yaxe, i) {
  12703. if (cnf.yaxis.length > 1 && isCollapsed(i)) return;
  12704. rightPad(yaxe);
  12705. };
  12706. cnf.yaxis.forEach(function (yaxe, i) {
  12707. if (isBarOpposite) {
  12708. if (_this.dCtx.gridPad.left < lbWidth) {
  12709. _this.dCtx.xPadLeft = lbWidth / 2 + 1;
  12710. }
  12711. _this.dCtx.xPadRight = lbWidth / 2 + 1;
  12712. } else {
  12713. padYAxe(yaxe, i);
  12714. }
  12715. });
  12716. }
  12717. }]);
  12718. return DimXAxis;
  12719. }();
  12720. var DimYAxis = /*#__PURE__*/function () {
  12721. function DimYAxis(dCtx) {
  12722. _classCallCheck(this, DimYAxis);
  12723. this.w = dCtx.w;
  12724. this.dCtx = dCtx;
  12725. }
  12726. /**
  12727. * Get Y Axis Dimensions
  12728. * @memberof Dimensions
  12729. * @return {{width, height}}
  12730. **/
  12731. _createClass(DimYAxis, [{
  12732. key: "getyAxisLabelsCoords",
  12733. value: function getyAxisLabelsCoords() {
  12734. var _this = this;
  12735. var w = this.w;
  12736. var width = 0;
  12737. var height = 0;
  12738. var ret = [];
  12739. var labelPad = 10;
  12740. var axesUtils = new AxesUtils(this.dCtx.ctx);
  12741. w.config.yaxis.map(function (yaxe, index) {
  12742. var formatterArgs = {
  12743. seriesIndex: index,
  12744. dataPointIndex: -1,
  12745. w: w
  12746. };
  12747. var yS = w.globals.yAxisScale[index];
  12748. var yAxisMinWidth = 0;
  12749. if (!axesUtils.isYAxisHidden(index) && yaxe.labels.show && yaxe.labels.minWidth !== undefined) yAxisMinWidth = yaxe.labels.minWidth;
  12750. if (!axesUtils.isYAxisHidden(index) && yaxe.labels.show && yS.result.length) {
  12751. var lbFormatter = w.globals.yLabelFormatters[index];
  12752. var minV = yS.niceMin === Number.MIN_VALUE ? 0 : yS.niceMin;
  12753. var val = yS.result.reduce(function (acc, curr) {
  12754. var _String, _String2;
  12755. 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;
  12756. }, minV);
  12757. val = lbFormatter(val, formatterArgs);
  12758. // the second parameter -1 is the index of tick which user can use in the formatter
  12759. var valArr = val;
  12760. // 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.
  12761. if (typeof val === 'undefined' || val.length === 0) {
  12762. val = yS.niceMax;
  12763. }
  12764. if (w.globals.isBarHorizontal) {
  12765. labelPad = 0;
  12766. var barYaxisLabels = w.globals.labels.slice();
  12767. // get the longest string from the labels array and also apply label formatter to it
  12768. val = Utils$1.getLargestStringFromArr(barYaxisLabels);
  12769. val = lbFormatter(val, {
  12770. seriesIndex: index,
  12771. dataPointIndex: -1,
  12772. w: w
  12773. });
  12774. valArr = _this.dCtx.dimHelpers.getLargestStringFromMultiArr(val, barYaxisLabels);
  12775. }
  12776. var graphics = new Graphics(_this.dCtx.ctx);
  12777. var rotateStr = 'rotate('.concat(yaxe.labels.rotate, ' 0 0)');
  12778. var rect = graphics.getTextRects(val, yaxe.labels.style.fontSize, yaxe.labels.style.fontFamily, rotateStr, false);
  12779. var arrLabelrect = rect;
  12780. if (val !== valArr) {
  12781. arrLabelrect = graphics.getTextRects(valArr, yaxe.labels.style.fontSize, yaxe.labels.style.fontFamily, rotateStr, false);
  12782. }
  12783. ret.push({
  12784. width: (yAxisMinWidth > arrLabelrect.width || yAxisMinWidth > rect.width ? yAxisMinWidth : arrLabelrect.width > rect.width ? arrLabelrect.width : rect.width) + labelPad,
  12785. height: arrLabelrect.height > rect.height ? arrLabelrect.height : rect.height
  12786. });
  12787. } else {
  12788. ret.push({
  12789. width: width,
  12790. height: height
  12791. });
  12792. }
  12793. });
  12794. return ret;
  12795. }
  12796. /**
  12797. * Get Y Axis Dimensions
  12798. * @memberof Dimensions
  12799. * @return {{width, height}}
  12800. **/
  12801. }, {
  12802. key: "getyAxisTitleCoords",
  12803. value: function getyAxisTitleCoords() {
  12804. var _this2 = this;
  12805. var w = this.w;
  12806. var ret = [];
  12807. w.config.yaxis.map(function (yaxe, index) {
  12808. if (yaxe.show && yaxe.title.text !== undefined) {
  12809. var graphics = new Graphics(_this2.dCtx.ctx);
  12810. var rotateStr = 'rotate('.concat(yaxe.title.rotate, ' 0 0)');
  12811. var rect = graphics.getTextRects(yaxe.title.text, yaxe.title.style.fontSize, yaxe.title.style.fontFamily, rotateStr, false);
  12812. ret.push({
  12813. width: rect.width,
  12814. height: rect.height
  12815. });
  12816. } else {
  12817. ret.push({
  12818. width: 0,
  12819. height: 0
  12820. });
  12821. }
  12822. });
  12823. return ret;
  12824. }
  12825. }, {
  12826. key: "getTotalYAxisWidth",
  12827. value: function getTotalYAxisWidth() {
  12828. var w = this.w;
  12829. var yAxisWidth = 0;
  12830. var yAxisWidthLeft = 0;
  12831. var yAxisWidthRight = 0;
  12832. var padding = w.globals.yAxisScale.length > 1 ? 10 : 0;
  12833. var axesUtils = new AxesUtils(this.dCtx.ctx);
  12834. var isHiddenYAxis = function isHiddenYAxis(index) {
  12835. return w.globals.ignoreYAxisIndexes.indexOf(index) > -1;
  12836. };
  12837. var padForLabelTitle = function padForLabelTitle(coord, index) {
  12838. var floating = w.config.yaxis[index].floating;
  12839. var width = 0;
  12840. if (coord.width > 0 && !floating) {
  12841. width = coord.width + padding;
  12842. if (isHiddenYAxis(index)) {
  12843. width = width - coord.width - padding;
  12844. }
  12845. } else {
  12846. width = floating || axesUtils.isYAxisHidden(index) ? 0 : 5;
  12847. }
  12848. w.config.yaxis[index].opposite ? yAxisWidthRight = yAxisWidthRight + width : yAxisWidthLeft = yAxisWidthLeft + width;
  12849. yAxisWidth = yAxisWidth + width;
  12850. };
  12851. w.globals.yLabelsCoords.map(function (yLabelCoord, index) {
  12852. padForLabelTitle(yLabelCoord, index);
  12853. });
  12854. w.globals.yTitleCoords.map(function (yTitleCoord, index) {
  12855. padForLabelTitle(yTitleCoord, index);
  12856. });
  12857. if (w.globals.isBarHorizontal && !w.config.yaxis[0].floating) {
  12858. yAxisWidth = w.globals.yLabelsCoords[0].width + w.globals.yTitleCoords[0].width + 15;
  12859. }
  12860. this.dCtx.yAxisWidthLeft = yAxisWidthLeft;
  12861. this.dCtx.yAxisWidthRight = yAxisWidthRight;
  12862. return yAxisWidth;
  12863. }
  12864. }]);
  12865. return DimYAxis;
  12866. }();
  12867. var DimGrid = /*#__PURE__*/function () {
  12868. function DimGrid(dCtx) {
  12869. _classCallCheck(this, DimGrid);
  12870. this.w = dCtx.w;
  12871. this.dCtx = dCtx;
  12872. }
  12873. _createClass(DimGrid, [{
  12874. key: "gridPadForColumnsInNumericAxis",
  12875. value: function gridPadForColumnsInNumericAxis(gridWidth) {
  12876. var w = this.w;
  12877. var cnf = w.config,
  12878. gl = w.globals;
  12879. if (gl.noData || gl.collapsedSeries.length + gl.ancillaryCollapsedSeries.length === cnf.series.length) {
  12880. return 0;
  12881. }
  12882. var hasBar = function hasBar(type) {
  12883. return ['bar', 'rangeBar', 'candlestick', 'boxPlot'].includes(type);
  12884. };
  12885. var type = cnf.chart.type;
  12886. var barWidth = 0;
  12887. var seriesLen = hasBar(type) ? cnf.series.length : 1;
  12888. if (gl.comboBarCount > 0) {
  12889. seriesLen = gl.comboBarCount;
  12890. }
  12891. gl.collapsedSeries.forEach(function (c) {
  12892. if (hasBar(c.type)) {
  12893. seriesLen -= 1;
  12894. }
  12895. });
  12896. if (cnf.chart.stacked) {
  12897. seriesLen = 1;
  12898. }
  12899. var barsPresent = hasBar(type) || gl.comboBarCount > 0;
  12900. var xRange = Math.abs(gl.initialMaxX - gl.initialMinX);
  12901. if (barsPresent && gl.isXNumeric && !gl.isBarHorizontal && seriesLen > 0 && xRange !== 0) {
  12902. if (xRange <= 3) {
  12903. xRange = gl.dataPoints;
  12904. }
  12905. var xRatio = xRange / gridWidth;
  12906. var xDivision = gl.minXDiff && gl.minXDiff / xRatio > 0 ? gl.minXDiff / xRatio : 0;
  12907. if (xDivision > gridWidth / 2) {
  12908. xDivision /= 2;
  12909. }
  12910. // Here, barWidth is assumed to be the width occupied by a group of bars.
  12911. // There will be one bar in the group for each series plotted.
  12912. // Note: This version of the following math is different to that over in
  12913. // Helpers.js. Don't assume they should be the same. Over there,
  12914. // xDivision is computed differently and it's used on different charts.
  12915. // They were the same, but the solution to
  12916. // https://github.com/apexcharts/apexcharts.js/issues/4178
  12917. // was to remove the division by seriesLen.
  12918. barWidth = xDivision * parseInt(cnf.plotOptions.bar.columnWidth, 10) / 100;
  12919. if (barWidth < 1) {
  12920. barWidth = 1;
  12921. }
  12922. gl.barPadForNumericAxis = barWidth;
  12923. }
  12924. return barWidth;
  12925. }
  12926. }, {
  12927. key: "gridPadFortitleSubtitle",
  12928. value: function gridPadFortitleSubtitle() {
  12929. var _this = this;
  12930. var w = this.w;
  12931. var gl = w.globals;
  12932. var gridShrinkOffset = this.dCtx.isSparkline || !gl.axisCharts ? 0 : 10;
  12933. var titleSubtitle = ['title', 'subtitle'];
  12934. titleSubtitle.forEach(function (t) {
  12935. if (w.config[t].text !== undefined) {
  12936. gridShrinkOffset += w.config[t].margin;
  12937. } else {
  12938. gridShrinkOffset += _this.dCtx.isSparkline || !gl.axisCharts ? 0 : 5;
  12939. }
  12940. });
  12941. if (w.config.legend.show && w.config.legend.position === 'bottom' && !w.config.legend.floating && !gl.axisCharts) {
  12942. gridShrinkOffset += 10;
  12943. }
  12944. var titleCoords = this.dCtx.dimHelpers.getTitleSubtitleCoords('title');
  12945. var subtitleCoords = this.dCtx.dimHelpers.getTitleSubtitleCoords('subtitle');
  12946. gl.gridHeight -= titleCoords.height + subtitleCoords.height + gridShrinkOffset;
  12947. gl.translateY += titleCoords.height + subtitleCoords.height + gridShrinkOffset;
  12948. }
  12949. }, {
  12950. key: "setGridXPosForDualYAxis",
  12951. value: function setGridXPosForDualYAxis(yTitleCoords, yaxisLabelCoords) {
  12952. var w = this.w;
  12953. var axesUtils = new AxesUtils(this.dCtx.ctx);
  12954. w.config.yaxis.forEach(function (yaxe, index) {
  12955. if (w.globals.ignoreYAxisIndexes.indexOf(index) === -1 && !yaxe.floating && !axesUtils.isYAxisHidden(index)) {
  12956. if (yaxe.opposite) {
  12957. w.globals.translateX -= yaxisLabelCoords[index].width + yTitleCoords[index].width + parseInt(yaxe.labels.style.fontSize, 10) / 1.2 + 12;
  12958. }
  12959. // fixes apexcharts.js#1599
  12960. if (w.globals.translateX < 2) {
  12961. w.globals.translateX = 2;
  12962. }
  12963. }
  12964. });
  12965. }
  12966. }]);
  12967. return DimGrid;
  12968. }();
  12969. /**
  12970. * ApexCharts Dimensions Class for calculating rects of all elements that are drawn and will be drawn.
  12971. *
  12972. * @module Dimensions
  12973. **/
  12974. var Dimensions = /*#__PURE__*/function () {
  12975. function Dimensions(ctx) {
  12976. _classCallCheck(this, Dimensions);
  12977. this.ctx = ctx;
  12978. this.w = ctx.w;
  12979. this.lgRect = {};
  12980. this.yAxisWidth = 0;
  12981. this.yAxisWidthLeft = 0;
  12982. this.yAxisWidthRight = 0;
  12983. this.xAxisHeight = 0;
  12984. this.isSparkline = this.w.config.chart.sparkline.enabled;
  12985. this.dimHelpers = new Helpers$3(this);
  12986. this.dimYAxis = new DimYAxis(this);
  12987. this.dimXAxis = new DimXAxis(this);
  12988. this.dimGrid = new DimGrid(this);
  12989. this.lgWidthForSideLegends = 0;
  12990. this.gridPad = this.w.config.grid.padding;
  12991. this.xPadRight = 0;
  12992. this.xPadLeft = 0;
  12993. }
  12994. /**
  12995. * @memberof Dimensions
  12996. * @param {object} w - chart context
  12997. **/
  12998. _createClass(Dimensions, [{
  12999. key: "plotCoords",
  13000. value: function plotCoords() {
  13001. var _this = this;
  13002. var w = this.w;
  13003. var gl = w.globals;
  13004. this.lgRect = this.dimHelpers.getLegendsRect();
  13005. this.datalabelsCoords = {
  13006. width: 0,
  13007. height: 0
  13008. };
  13009. var maxStrokeWidth = Array.isArray(w.config.stroke.width) ? Math.max.apply(Math, _toConsumableArray(w.config.stroke.width)) : w.config.stroke.width;
  13010. if (this.isSparkline) {
  13011. if (w.config.markers.discrete.length > 0 || w.config.markers.size > 0) {
  13012. Object.entries(this.gridPad).forEach(function (_ref) {
  13013. var _ref2 = _slicedToArray(_ref, 2),
  13014. k = _ref2[0],
  13015. v = _ref2[1];
  13016. _this.gridPad[k] = Math.max(v, _this.w.globals.markers.largestSize / 1.5);
  13017. });
  13018. }
  13019. this.gridPad.top = Math.max(maxStrokeWidth / 2, this.gridPad.top);
  13020. this.gridPad.bottom = Math.max(maxStrokeWidth / 2, this.gridPad.bottom);
  13021. }
  13022. if (gl.axisCharts) {
  13023. // for line / area / scatter / column
  13024. this.setDimensionsForAxisCharts();
  13025. } else {
  13026. // for pie / donuts / circle
  13027. this.setDimensionsForNonAxisCharts();
  13028. }
  13029. this.dimGrid.gridPadFortitleSubtitle();
  13030. // after calculating everything, apply padding set by user
  13031. gl.gridHeight = gl.gridHeight - this.gridPad.top - this.gridPad.bottom;
  13032. gl.gridWidth = gl.gridWidth - this.gridPad.left - this.gridPad.right - this.xPadRight - this.xPadLeft;
  13033. var barWidth = this.dimGrid.gridPadForColumnsInNumericAxis(gl.gridWidth);
  13034. gl.gridWidth = gl.gridWidth - barWidth * 2;
  13035. gl.translateX = gl.translateX + this.gridPad.left + this.xPadLeft + (barWidth > 0 ? barWidth : 0);
  13036. gl.translateY = gl.translateY + this.gridPad.top;
  13037. }
  13038. }, {
  13039. key: "setDimensionsForAxisCharts",
  13040. value: function setDimensionsForAxisCharts() {
  13041. var _this2 = this;
  13042. var w = this.w;
  13043. var gl = w.globals;
  13044. var yaxisLabelCoords = this.dimYAxis.getyAxisLabelsCoords();
  13045. var yTitleCoords = this.dimYAxis.getyAxisTitleCoords();
  13046. if (gl.isSlopeChart) {
  13047. this.datalabelsCoords = this.dimHelpers.getDatalabelsRect();
  13048. }
  13049. w.globals.yLabelsCoords = [];
  13050. w.globals.yTitleCoords = [];
  13051. w.config.yaxis.map(function (yaxe, index) {
  13052. // store the labels and titles coords in global vars
  13053. w.globals.yLabelsCoords.push({
  13054. width: yaxisLabelCoords[index].width,
  13055. index: index
  13056. });
  13057. w.globals.yTitleCoords.push({
  13058. width: yTitleCoords[index].width,
  13059. index: index
  13060. });
  13061. });
  13062. this.yAxisWidth = this.dimYAxis.getTotalYAxisWidth();
  13063. var xaxisLabelCoords = this.dimXAxis.getxAxisLabelsCoords();
  13064. var xaxisGroupLabelCoords = this.dimXAxis.getxAxisGroupLabelsCoords();
  13065. var xtitleCoords = this.dimXAxis.getxAxisTitleCoords();
  13066. this.conditionalChecksForAxisCoords(xaxisLabelCoords, xtitleCoords, xaxisGroupLabelCoords);
  13067. gl.translateXAxisY = w.globals.rotateXLabels ? this.xAxisHeight / 8 : -4;
  13068. gl.translateXAxisX = w.globals.rotateXLabels && w.globals.isXNumeric && w.config.xaxis.labels.rotate <= -45 ? -this.xAxisWidth / 4 : 0;
  13069. if (w.globals.isBarHorizontal) {
  13070. gl.rotateXLabels = false;
  13071. gl.translateXAxisY = -1 * (parseInt(w.config.xaxis.labels.style.fontSize, 10) / 1.5);
  13072. }
  13073. gl.translateXAxisY = gl.translateXAxisY + w.config.xaxis.labels.offsetY;
  13074. gl.translateXAxisX = gl.translateXAxisX + w.config.xaxis.labels.offsetX;
  13075. var yAxisWidth = this.yAxisWidth;
  13076. var xAxisHeight = this.xAxisHeight;
  13077. gl.xAxisLabelsHeight = this.xAxisHeight - xtitleCoords.height;
  13078. gl.xAxisGroupLabelsHeight = gl.xAxisLabelsHeight - xaxisLabelCoords.height;
  13079. gl.xAxisLabelsWidth = this.xAxisWidth;
  13080. gl.xAxisHeight = this.xAxisHeight;
  13081. var translateY = 10;
  13082. if (w.config.chart.type === 'radar' || this.isSparkline) {
  13083. yAxisWidth = 0;
  13084. xAxisHeight = 0;
  13085. }
  13086. if (this.isSparkline) {
  13087. this.lgRect = {
  13088. height: 0,
  13089. width: 0
  13090. };
  13091. }
  13092. if (this.isSparkline || w.config.chart.type === 'treemap') {
  13093. yAxisWidth = 0;
  13094. xAxisHeight = 0;
  13095. translateY = 0;
  13096. }
  13097. if (!this.isSparkline && w.config.chart.type !== 'treemap') {
  13098. this.dimXAxis.additionalPaddingXLabels(xaxisLabelCoords);
  13099. }
  13100. var legendTopBottom = function legendTopBottom() {
  13101. gl.translateX = yAxisWidth + _this2.datalabelsCoords.width;
  13102. gl.gridHeight = gl.svgHeight - _this2.lgRect.height - xAxisHeight - (!_this2.isSparkline && w.config.chart.type !== 'treemap' ? w.globals.rotateXLabels ? 10 : 15 : 0);
  13103. gl.gridWidth = gl.svgWidth - yAxisWidth - _this2.datalabelsCoords.width * 2;
  13104. };
  13105. if (w.config.xaxis.position === 'top') translateY = gl.xAxisHeight - w.config.xaxis.axisTicks.height - 5;
  13106. switch (w.config.legend.position) {
  13107. case 'bottom':
  13108. gl.translateY = translateY;
  13109. legendTopBottom();
  13110. break;
  13111. case 'top':
  13112. gl.translateY = this.lgRect.height + translateY;
  13113. legendTopBottom();
  13114. break;
  13115. case 'left':
  13116. gl.translateY = translateY;
  13117. gl.translateX = this.lgRect.width + yAxisWidth + this.datalabelsCoords.width;
  13118. gl.gridHeight = gl.svgHeight - xAxisHeight - 12;
  13119. gl.gridWidth = gl.svgWidth - this.lgRect.width - yAxisWidth - this.datalabelsCoords.width * 2;
  13120. break;
  13121. case 'right':
  13122. gl.translateY = translateY;
  13123. gl.translateX = yAxisWidth + this.datalabelsCoords.width;
  13124. gl.gridHeight = gl.svgHeight - xAxisHeight - 12;
  13125. gl.gridWidth = gl.svgWidth - this.lgRect.width - yAxisWidth - this.datalabelsCoords.width * 2 - 5;
  13126. break;
  13127. default:
  13128. throw new Error('Legend position not supported');
  13129. }
  13130. this.dimGrid.setGridXPosForDualYAxis(yTitleCoords, yaxisLabelCoords);
  13131. // after drawing everything, set the Y axis positions
  13132. var objyAxis = new YAxis(this.ctx);
  13133. objyAxis.setYAxisXPosition(yaxisLabelCoords, yTitleCoords);
  13134. }
  13135. }, {
  13136. key: "setDimensionsForNonAxisCharts",
  13137. value: function setDimensionsForNonAxisCharts() {
  13138. var w = this.w;
  13139. var gl = w.globals;
  13140. var cnf = w.config;
  13141. var xPad = 0;
  13142. if (w.config.legend.show && !w.config.legend.floating) {
  13143. xPad = 20;
  13144. }
  13145. var type = cnf.chart.type === 'pie' || cnf.chart.type === 'polarArea' || cnf.chart.type === 'donut' ? 'pie' : 'radialBar';
  13146. var offY = cnf.plotOptions[type].offsetY;
  13147. var offX = cnf.plotOptions[type].offsetX;
  13148. if (!cnf.legend.show || cnf.legend.floating) {
  13149. gl.gridHeight = gl.svgHeight;
  13150. var maxWidth = gl.dom.elWrap.getBoundingClientRect().width;
  13151. gl.gridWidth = Math.min(maxWidth, gl.gridHeight);
  13152. gl.translateY = offY;
  13153. gl.translateX = offX + (gl.svgWidth - gl.gridWidth) / 2;
  13154. return;
  13155. }
  13156. switch (cnf.legend.position) {
  13157. case 'bottom':
  13158. gl.gridHeight = gl.svgHeight - this.lgRect.height;
  13159. gl.gridWidth = gl.svgWidth;
  13160. gl.translateY = offY - 10;
  13161. gl.translateX = offX + (gl.svgWidth - gl.gridWidth) / 2;
  13162. break;
  13163. case 'top':
  13164. gl.gridHeight = gl.svgHeight - this.lgRect.height;
  13165. gl.gridWidth = gl.svgWidth;
  13166. gl.translateY = this.lgRect.height + offY + 10;
  13167. gl.translateX = offX + (gl.svgWidth - gl.gridWidth) / 2;
  13168. break;
  13169. case 'left':
  13170. gl.gridWidth = gl.svgWidth - this.lgRect.width - xPad;
  13171. gl.gridHeight = cnf.chart.height !== 'auto' ? gl.svgHeight : gl.gridWidth;
  13172. gl.translateY = offY;
  13173. gl.translateX = offX + this.lgRect.width + xPad;
  13174. break;
  13175. case 'right':
  13176. gl.gridWidth = gl.svgWidth - this.lgRect.width - xPad - 5;
  13177. gl.gridHeight = cnf.chart.height !== 'auto' ? gl.svgHeight : gl.gridWidth;
  13178. gl.translateY = offY;
  13179. gl.translateX = offX + 10;
  13180. break;
  13181. default:
  13182. throw new Error('Legend position not supported');
  13183. }
  13184. }
  13185. }, {
  13186. key: "conditionalChecksForAxisCoords",
  13187. value: function conditionalChecksForAxisCoords(xaxisLabelCoords, xtitleCoords, xaxisGroupLabelCoords) {
  13188. var w = this.w;
  13189. var xAxisNum = w.globals.hasXaxisGroups ? 2 : 1;
  13190. var baseXAxisHeight = xaxisGroupLabelCoords.height + xaxisLabelCoords.height + xtitleCoords.height;
  13191. var xAxisHeightMultiplicate = w.globals.isMultiLineX ? 1.2 : w.globals.LINE_HEIGHT_RATIO;
  13192. var rotatedXAxisOffset = w.globals.rotateXLabels ? 22 : 10;
  13193. var rotatedXAxisLegendOffset = w.globals.rotateXLabels && w.config.legend.position === 'bottom';
  13194. var additionalOffset = rotatedXAxisLegendOffset ? 10 : 0;
  13195. this.xAxisHeight = baseXAxisHeight * xAxisHeightMultiplicate + xAxisNum * rotatedXAxisOffset + additionalOffset;
  13196. this.xAxisWidth = xaxisLabelCoords.width;
  13197. if (this.xAxisHeight - xtitleCoords.height > w.config.xaxis.labels.maxHeight) {
  13198. this.xAxisHeight = w.config.xaxis.labels.maxHeight;
  13199. }
  13200. if (w.config.xaxis.labels.minHeight && this.xAxisHeight < w.config.xaxis.labels.minHeight) {
  13201. this.xAxisHeight = w.config.xaxis.labels.minHeight;
  13202. }
  13203. if (w.config.xaxis.floating) {
  13204. this.xAxisHeight = 0;
  13205. }
  13206. var minYAxisWidth = 0;
  13207. var maxYAxisWidth = 0;
  13208. w.config.yaxis.forEach(function (y) {
  13209. minYAxisWidth += y.labels.minWidth;
  13210. maxYAxisWidth += y.labels.maxWidth;
  13211. });
  13212. if (this.yAxisWidth < minYAxisWidth) {
  13213. this.yAxisWidth = minYAxisWidth;
  13214. }
  13215. if (this.yAxisWidth > maxYAxisWidth) {
  13216. this.yAxisWidth = maxYAxisWidth;
  13217. }
  13218. }
  13219. }]);
  13220. return Dimensions;
  13221. }();
  13222. var Helpers$2 = /*#__PURE__*/function () {
  13223. function Helpers(lgCtx) {
  13224. _classCallCheck(this, Helpers);
  13225. this.w = lgCtx.w;
  13226. this.lgCtx = lgCtx;
  13227. }
  13228. _createClass(Helpers, [{
  13229. key: "getLegendStyles",
  13230. value: function getLegendStyles() {
  13231. var _this$lgCtx$ctx, _this$lgCtx$ctx$opts, _this$lgCtx$ctx$opts$;
  13232. var stylesheet = document.createElement('style');
  13233. stylesheet.setAttribute('type', 'text/css');
  13234. 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;
  13235. if (nonce) {
  13236. stylesheet.setAttribute('nonce', nonce);
  13237. }
  13238. 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.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 }\n .apexcharts-legend.apx-legend-position-bottom.apexcharts-align-center, .apexcharts-legend.apx-legend-position-top.apexcharts-align-center {\n justify-content: 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 }\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 }";
  13239. var rules = document.createTextNode(text);
  13240. stylesheet.appendChild(rules);
  13241. return stylesheet;
  13242. }
  13243. }, {
  13244. key: "getLegendDimensions",
  13245. value: function getLegendDimensions() {
  13246. var w = this.w;
  13247. var currLegendsWrap = w.globals.dom.baseEl.querySelector('.apexcharts-legend');
  13248. var _currLegendsWrap$getB = currLegendsWrap.getBoundingClientRect(),
  13249. currLegendsWrapWidth = _currLegendsWrap$getB.width,
  13250. currLegendsWrapHeight = _currLegendsWrap$getB.height;
  13251. return {
  13252. clwh: currLegendsWrapHeight,
  13253. clww: currLegendsWrapWidth
  13254. };
  13255. }
  13256. }, {
  13257. key: "appendToForeignObject",
  13258. value: function appendToForeignObject() {
  13259. var gl = this.w.globals;
  13260. gl.dom.elLegendForeign.appendChild(this.getLegendStyles());
  13261. }
  13262. }, {
  13263. key: "toggleDataSeries",
  13264. value: function toggleDataSeries(seriesCnt, isHidden) {
  13265. var _this = this;
  13266. var w = this.w;
  13267. if (w.globals.axisCharts || w.config.chart.type === 'radialBar') {
  13268. w.globals.resized = true; // we don't want initial animations again
  13269. var seriesEl = null;
  13270. var realIndex = null;
  13271. // yes, make it null. 1 series will rise at a time
  13272. w.globals.risingSeries = [];
  13273. if (w.globals.axisCharts) {
  13274. seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[data\\:realIndex='".concat(seriesCnt, "']"));
  13275. realIndex = parseInt(seriesEl.getAttribute('data:realIndex'), 10);
  13276. } else {
  13277. seriesEl = w.globals.dom.baseEl.querySelector(".apexcharts-series[rel='".concat(seriesCnt + 1, "']"));
  13278. realIndex = parseInt(seriesEl.getAttribute('rel'), 10) - 1;
  13279. }
  13280. if (isHidden) {
  13281. var seriesToMakeVisible = [{
  13282. cs: w.globals.collapsedSeries,
  13283. csi: w.globals.collapsedSeriesIndices
  13284. }, {
  13285. cs: w.globals.ancillaryCollapsedSeries,
  13286. csi: w.globals.ancillaryCollapsedSeriesIndices
  13287. }];
  13288. seriesToMakeVisible.forEach(function (r) {
  13289. _this.riseCollapsedSeries(r.cs, r.csi, realIndex);
  13290. });
  13291. } else {
  13292. this.hideSeries({
  13293. seriesEl: seriesEl,
  13294. realIndex: realIndex
  13295. });
  13296. }
  13297. } else {
  13298. // for non-axis charts i.e pie / donuts
  13299. var _seriesEl = w.globals.dom.Paper.select(" .apexcharts-series[rel='".concat(seriesCnt + 1, "'] path"));
  13300. var type = w.config.chart.type;
  13301. if (type === 'pie' || type === 'polarArea' || type === 'donut') {
  13302. var dataLabels = w.config.plotOptions.pie.donut.labels;
  13303. var graphics = new Graphics(this.lgCtx.ctx);
  13304. graphics.pathMouseDown(_seriesEl.members[0], null);
  13305. this.lgCtx.ctx.pie.printDataLabelsInner(_seriesEl.members[0].node, dataLabels);
  13306. }
  13307. _seriesEl.fire('click');
  13308. }
  13309. }
  13310. }, {
  13311. key: "getSeriesAfterCollapsing",
  13312. value: function getSeriesAfterCollapsing(_ref) {
  13313. var realIndex = _ref.realIndex;
  13314. var w = this.w;
  13315. var gl = w.globals;
  13316. var series = Utils$1.clone(w.config.series);
  13317. if (gl.axisCharts) {
  13318. var yaxis = w.config.yaxis[gl.seriesYAxisReverseMap[realIndex]];
  13319. var collapseData = {
  13320. index: realIndex,
  13321. data: series[realIndex].data.slice(),
  13322. type: series[realIndex].type || w.config.chart.type
  13323. };
  13324. if (yaxis && yaxis.show && yaxis.showAlways) {
  13325. if (gl.ancillaryCollapsedSeriesIndices.indexOf(realIndex) < 0) {
  13326. gl.ancillaryCollapsedSeries.push(collapseData);
  13327. gl.ancillaryCollapsedSeriesIndices.push(realIndex);
  13328. }
  13329. } else {
  13330. if (gl.collapsedSeriesIndices.indexOf(realIndex) < 0) {
  13331. gl.collapsedSeries.push(collapseData);
  13332. gl.collapsedSeriesIndices.push(realIndex);
  13333. var removeIndexOfRising = gl.risingSeries.indexOf(realIndex);
  13334. gl.risingSeries.splice(removeIndexOfRising, 1);
  13335. }
  13336. }
  13337. } else {
  13338. gl.collapsedSeries.push({
  13339. index: realIndex,
  13340. data: series[realIndex]
  13341. });
  13342. gl.collapsedSeriesIndices.push(realIndex);
  13343. }
  13344. gl.allSeriesCollapsed = gl.collapsedSeries.length + gl.ancillaryCollapsedSeries.length === w.config.series.length;
  13345. return this._getSeriesBasedOnCollapsedState(series);
  13346. }
  13347. }, {
  13348. key: "hideSeries",
  13349. value: function hideSeries(_ref2) {
  13350. var seriesEl = _ref2.seriesEl,
  13351. realIndex = _ref2.realIndex;
  13352. var w = this.w;
  13353. var series = this.getSeriesAfterCollapsing({
  13354. realIndex: realIndex
  13355. });
  13356. var seriesChildren = seriesEl.childNodes;
  13357. for (var sc = 0; sc < seriesChildren.length; sc++) {
  13358. if (seriesChildren[sc].classList.contains('apexcharts-series-markers-wrap')) {
  13359. if (seriesChildren[sc].classList.contains('apexcharts-hide')) {
  13360. seriesChildren[sc].classList.remove('apexcharts-hide');
  13361. } else {
  13362. seriesChildren[sc].classList.add('apexcharts-hide');
  13363. }
  13364. }
  13365. }
  13366. this.lgCtx.ctx.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
  13367. }
  13368. }, {
  13369. key: "riseCollapsedSeries",
  13370. value: function riseCollapsedSeries(collapsedSeries, seriesIndices, realIndex) {
  13371. var w = this.w;
  13372. var series = Utils$1.clone(w.config.series);
  13373. if (collapsedSeries.length > 0) {
  13374. for (var c = 0; c < collapsedSeries.length; c++) {
  13375. if (collapsedSeries[c].index === realIndex) {
  13376. if (w.globals.axisCharts) {
  13377. series[realIndex].data = collapsedSeries[c].data.slice();
  13378. } else {
  13379. series[realIndex] = collapsedSeries[c].data;
  13380. }
  13381. series[realIndex].hidden = false;
  13382. collapsedSeries.splice(c, 1);
  13383. seriesIndices.splice(c, 1);
  13384. w.globals.risingSeries.push(realIndex);
  13385. }
  13386. }
  13387. series = this._getSeriesBasedOnCollapsedState(series);
  13388. this.lgCtx.ctx.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
  13389. }
  13390. }
  13391. }, {
  13392. key: "_getSeriesBasedOnCollapsedState",
  13393. value: function _getSeriesBasedOnCollapsedState(series) {
  13394. var w = this.w;
  13395. var collapsed = 0;
  13396. if (w.globals.axisCharts) {
  13397. series.forEach(function (s, sI) {
  13398. if (!(w.globals.collapsedSeriesIndices.indexOf(sI) < 0 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(sI) < 0)) {
  13399. series[sI].data = [];
  13400. collapsed++;
  13401. }
  13402. });
  13403. } else {
  13404. series.forEach(function (s, sI) {
  13405. if (!w.globals.collapsedSeriesIndices.indexOf(sI) < 0) {
  13406. series[sI] = 0;
  13407. collapsed++;
  13408. }
  13409. });
  13410. }
  13411. w.globals.allSeriesCollapsed = collapsed === series.length;
  13412. return series;
  13413. }
  13414. }]);
  13415. return Helpers;
  13416. }();
  13417. /**
  13418. * ApexCharts Legend Class to draw legend.
  13419. *
  13420. * @module Legend
  13421. **/
  13422. var Legend = /*#__PURE__*/function () {
  13423. function Legend(ctx) {
  13424. _classCallCheck(this, Legend);
  13425. this.ctx = ctx;
  13426. this.w = ctx.w;
  13427. this.onLegendClick = this.onLegendClick.bind(this);
  13428. this.onLegendHovered = this.onLegendHovered.bind(this);
  13429. this.isBarsDistributed = this.w.config.chart.type === 'bar' && this.w.config.plotOptions.bar.distributed && this.w.config.series.length === 1;
  13430. this.legendHelpers = new Helpers$2(this);
  13431. }
  13432. _createClass(Legend, [{
  13433. key: "init",
  13434. value: function init() {
  13435. var w = this.w;
  13436. var gl = w.globals;
  13437. var cnf = w.config;
  13438. var showLegendAlways = cnf.legend.showForSingleSeries && gl.series.length === 1 || this.isBarsDistributed || gl.series.length > 1;
  13439. this.legendHelpers.appendToForeignObject();
  13440. if ((showLegendAlways || !gl.axisCharts) && cnf.legend.show) {
  13441. while (gl.dom.elLegendWrap.firstChild) {
  13442. gl.dom.elLegendWrap.removeChild(gl.dom.elLegendWrap.firstChild);
  13443. }
  13444. this.drawLegends();
  13445. if (cnf.legend.position === 'bottom' || cnf.legend.position === 'top') {
  13446. this.legendAlignHorizontal();
  13447. } else if (cnf.legend.position === 'right' || cnf.legend.position === 'left') {
  13448. this.legendAlignVertical();
  13449. }
  13450. }
  13451. }
  13452. }, {
  13453. key: "createLegendMarker",
  13454. value: function createLegendMarker(_ref) {
  13455. var i = _ref.i,
  13456. fillcolor = _ref.fillcolor;
  13457. var w = this.w;
  13458. var elMarker = document.createElement('span');
  13459. elMarker.classList.add('apexcharts-legend-marker');
  13460. var mShape = w.config.legend.markers.shape || w.config.markers.shape;
  13461. var shape = mShape;
  13462. if (Array.isArray(mShape)) {
  13463. shape = mShape[i];
  13464. }
  13465. var mSize = Array.isArray(w.config.legend.markers.size) ? parseFloat(w.config.legend.markers.size[i]) : parseFloat(w.config.legend.markers.size);
  13466. var mOffsetX = Array.isArray(w.config.legend.markers.offsetX) ? parseFloat(w.config.legend.markers.offsetX[i]) : parseFloat(w.config.legend.markers.offsetX);
  13467. var mOffsetY = Array.isArray(w.config.legend.markers.offsetY) ? parseFloat(w.config.legend.markers.offsetY[i]) : parseFloat(w.config.legend.markers.offsetY);
  13468. var mBorderWidth = Array.isArray(w.config.legend.markers.strokeWidth) ? parseFloat(w.config.legend.markers.strokeWidth[i]) : parseFloat(w.config.legend.markers.strokeWidth);
  13469. var mStyle = elMarker.style;
  13470. mStyle.height = (mSize + mBorderWidth) * 2 + 'px';
  13471. mStyle.width = (mSize + mBorderWidth) * 2 + 'px';
  13472. mStyle.left = mOffsetX + 'px';
  13473. mStyle.top = mOffsetY + 'px';
  13474. if (w.config.legend.markers.customHTML) {
  13475. mStyle.background = 'transparent';
  13476. mStyle.color = fillcolor[i];
  13477. if (Array.isArray(w.config.legend.markers.customHTML)) {
  13478. if (w.config.legend.markers.customHTML[i]) {
  13479. elMarker.innerHTML = w.config.legend.markers.customHTML[i]();
  13480. }
  13481. } else {
  13482. elMarker.innerHTML = w.config.legend.markers.customHTML();
  13483. }
  13484. } else {
  13485. var markers = new Markers(this.ctx);
  13486. var markerConfig = markers.getMarkerConfig({
  13487. cssClass: "apexcharts-legend-marker apexcharts-marker apexcharts-marker-".concat(shape),
  13488. seriesIndex: i,
  13489. strokeWidth: mBorderWidth,
  13490. size: mSize
  13491. });
  13492. var SVGMarker = SVG(elMarker).size('100%', '100%');
  13493. var marker = new Graphics(this.ctx).drawMarker(0, 0, _objectSpread2(_objectSpread2({}, markerConfig), {}, {
  13494. pointFillColor: Array.isArray(fillcolor) ? fillcolor[i] : markerConfig.pointFillColor,
  13495. shape: shape
  13496. }));
  13497. var shapesEls = SVG.select('.apexcharts-legend-marker.apexcharts-marker').members;
  13498. shapesEls.forEach(function (shapeEl) {
  13499. if (shapeEl.node.classList.contains('apexcharts-marker-triangle')) {
  13500. shapeEl.node.style.transform = 'translate(50%, 45%)';
  13501. } else {
  13502. shapeEl.node.style.transform = 'translate(50%, 50%)';
  13503. }
  13504. });
  13505. SVGMarker.add(marker);
  13506. }
  13507. return elMarker;
  13508. }
  13509. }, {
  13510. key: "drawLegends",
  13511. value: function drawLegends() {
  13512. var me = this;
  13513. var w = this.w;
  13514. var fontFamily = w.config.legend.fontFamily;
  13515. var legendNames = w.globals.seriesNames;
  13516. var fillcolor = w.config.legend.markers.fillColors ? w.config.legend.markers.fillColors.slice() : w.globals.colors.slice();
  13517. if (w.config.chart.type === 'heatmap') {
  13518. var ranges = w.config.plotOptions.heatmap.colorScale.ranges;
  13519. legendNames = ranges.map(function (colorScale) {
  13520. return colorScale.name ? colorScale.name : colorScale.from + ' - ' + colorScale.to;
  13521. });
  13522. fillcolor = ranges.map(function (color) {
  13523. return color.color;
  13524. });
  13525. } else if (this.isBarsDistributed) {
  13526. legendNames = w.globals.labels.slice();
  13527. }
  13528. if (w.config.legend.customLegendItems.length) {
  13529. legendNames = w.config.legend.customLegendItems;
  13530. }
  13531. var legendFormatter = w.globals.legendFormatter;
  13532. var isLegendInversed = w.config.legend.inverseOrder;
  13533. for (var i = isLegendInversed ? legendNames.length - 1 : 0; isLegendInversed ? i >= 0 : i <= legendNames.length - 1; isLegendInversed ? i-- : i++) {
  13534. var _w$config$legend$labe;
  13535. var text = legendFormatter(legendNames[i], {
  13536. seriesIndex: i,
  13537. w: w
  13538. });
  13539. var collapsedSeries = false;
  13540. var ancillaryCollapsedSeries = false;
  13541. if (w.globals.collapsedSeries.length > 0) {
  13542. for (var c = 0; c < w.globals.collapsedSeries.length; c++) {
  13543. if (w.globals.collapsedSeries[c].index === i) {
  13544. collapsedSeries = true;
  13545. }
  13546. }
  13547. }
  13548. if (w.globals.ancillaryCollapsedSeriesIndices.length > 0) {
  13549. for (var _c = 0; _c < w.globals.ancillaryCollapsedSeriesIndices.length; _c++) {
  13550. if (w.globals.ancillaryCollapsedSeriesIndices[_c] === i) {
  13551. ancillaryCollapsedSeries = true;
  13552. }
  13553. }
  13554. }
  13555. var elMarker = this.createLegendMarker({
  13556. i: i,
  13557. fillcolor: fillcolor
  13558. });
  13559. Graphics.setAttrs(elMarker, {
  13560. rel: i + 1,
  13561. 'data:collapsed': collapsedSeries || ancillaryCollapsedSeries
  13562. });
  13563. if (collapsedSeries || ancillaryCollapsedSeries) {
  13564. elMarker.classList.add('apexcharts-inactive-legend');
  13565. }
  13566. var elLegend = document.createElement('div');
  13567. var elLegendText = document.createElement('span');
  13568. elLegendText.classList.add('apexcharts-legend-text');
  13569. elLegendText.innerHTML = Array.isArray(text) ? text.join(' ') : text;
  13570. 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;
  13571. if (!textColor) {
  13572. textColor = w.config.chart.foreColor;
  13573. }
  13574. elLegendText.style.color = textColor;
  13575. elLegendText.style.fontSize = parseFloat(w.config.legend.fontSize) + 'px';
  13576. elLegendText.style.fontWeight = w.config.legend.fontWeight;
  13577. elLegendText.style.fontFamily = fontFamily || w.config.chart.fontFamily;
  13578. Graphics.setAttrs(elLegendText, {
  13579. rel: i + 1,
  13580. i: i,
  13581. 'data:default-text': encodeURIComponent(text),
  13582. 'data:collapsed': collapsedSeries || ancillaryCollapsedSeries
  13583. });
  13584. elLegend.appendChild(elMarker);
  13585. elLegend.appendChild(elLegendText);
  13586. var coreUtils = new CoreUtils(this.ctx);
  13587. if (!w.config.legend.showForZeroSeries) {
  13588. var total = coreUtils.getSeriesTotalByIndex(i);
  13589. if (total === 0 && coreUtils.seriesHaveSameValues(i) && !coreUtils.isSeriesNull(i) && w.globals.collapsedSeriesIndices.indexOf(i) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(i) === -1) {
  13590. elLegend.classList.add('apexcharts-hidden-zero-series');
  13591. }
  13592. }
  13593. if (!w.config.legend.showForNullSeries) {
  13594. if (coreUtils.isSeriesNull(i) && w.globals.collapsedSeriesIndices.indexOf(i) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(i) === -1) {
  13595. elLegend.classList.add('apexcharts-hidden-null-series');
  13596. }
  13597. }
  13598. w.globals.dom.elLegendWrap.appendChild(elLegend);
  13599. w.globals.dom.elLegendWrap.classList.add("apexcharts-align-".concat(w.config.legend.horizontalAlign));
  13600. w.globals.dom.elLegendWrap.classList.add('apx-legend-position-' + w.config.legend.position);
  13601. elLegend.classList.add('apexcharts-legend-series');
  13602. elLegend.style.margin = "".concat(w.config.legend.itemMargin.vertical, "px ").concat(w.config.legend.itemMargin.horizontal, "px");
  13603. w.globals.dom.elLegendWrap.style.width = w.config.legend.width ? w.config.legend.width + 'px' : '';
  13604. w.globals.dom.elLegendWrap.style.height = w.config.legend.height ? w.config.legend.height + 'px' : '';
  13605. Graphics.setAttrs(elLegend, {
  13606. rel: i + 1,
  13607. seriesName: Utils$1.escapeString(legendNames[i]),
  13608. 'data:collapsed': collapsedSeries || ancillaryCollapsedSeries
  13609. });
  13610. if (collapsedSeries || ancillaryCollapsedSeries) {
  13611. elLegend.classList.add('apexcharts-inactive-legend');
  13612. }
  13613. if (!w.config.legend.onItemClick.toggleDataSeries) {
  13614. elLegend.classList.add('apexcharts-no-click');
  13615. }
  13616. }
  13617. w.globals.dom.elWrap.addEventListener('click', me.onLegendClick, true);
  13618. if (w.config.legend.onItemHover.highlightDataSeries && w.config.legend.customLegendItems.length === 0) {
  13619. w.globals.dom.elWrap.addEventListener('mousemove', me.onLegendHovered, true);
  13620. w.globals.dom.elWrap.addEventListener('mouseout', me.onLegendHovered, true);
  13621. }
  13622. }
  13623. }, {
  13624. key: "setLegendWrapXY",
  13625. value: function setLegendWrapXY(offsetX, offsetY) {
  13626. var w = this.w;
  13627. var elLegendWrap = w.globals.dom.elLegendWrap;
  13628. var legendHeight = elLegendWrap.clientHeight;
  13629. var x = 0;
  13630. var y = 0;
  13631. if (w.config.legend.position === 'bottom') {
  13632. y = w.globals.svgHeight - Math.min(legendHeight, w.globals.svgHeight / 2) - 5;
  13633. } else if (w.config.legend.position === 'top') {
  13634. var dim = new Dimensions(this.ctx);
  13635. var titleH = dim.dimHelpers.getTitleSubtitleCoords('title').height;
  13636. var subtitleH = dim.dimHelpers.getTitleSubtitleCoords('subtitle').height;
  13637. y = (titleH > 0 ? titleH - 10 : 0) + (subtitleH > 0 ? subtitleH - 10 : 0);
  13638. }
  13639. elLegendWrap.style.position = 'absolute';
  13640. x = x + offsetX + w.config.legend.offsetX;
  13641. y = y + offsetY + w.config.legend.offsetY;
  13642. elLegendWrap.style.left = x + 'px';
  13643. elLegendWrap.style.top = y + 'px';
  13644. if (w.config.legend.position === 'right') {
  13645. elLegendWrap.style.left = 'auto';
  13646. elLegendWrap.style.right = 25 + w.config.legend.offsetX + 'px';
  13647. }
  13648. var fixedHeigthWidth = ['width', 'height'];
  13649. fixedHeigthWidth.forEach(function (hw) {
  13650. if (elLegendWrap.style[hw]) {
  13651. elLegendWrap.style[hw] = parseInt(w.config.legend[hw], 10) + 'px';
  13652. }
  13653. });
  13654. }
  13655. }, {
  13656. key: "legendAlignHorizontal",
  13657. value: function legendAlignHorizontal() {
  13658. var w = this.w;
  13659. var elLegendWrap = w.globals.dom.elLegendWrap;
  13660. elLegendWrap.style.right = 0;
  13661. var dimensions = new Dimensions(this.ctx);
  13662. var titleRect = dimensions.dimHelpers.getTitleSubtitleCoords('title');
  13663. var subtitleRect = dimensions.dimHelpers.getTitleSubtitleCoords('subtitle');
  13664. var offsetX = 20;
  13665. var offsetY = 0;
  13666. if (w.config.legend.position === 'top') {
  13667. offsetY = titleRect.height + subtitleRect.height + w.config.title.margin + w.config.subtitle.margin - 10;
  13668. }
  13669. this.setLegendWrapXY(offsetX, offsetY);
  13670. }
  13671. }, {
  13672. key: "legendAlignVertical",
  13673. value: function legendAlignVertical() {
  13674. var w = this.w;
  13675. var lRect = this.legendHelpers.getLegendDimensions();
  13676. var offsetY = 20;
  13677. var offsetX = 0;
  13678. if (w.config.legend.position === 'left') {
  13679. offsetX = 20;
  13680. }
  13681. if (w.config.legend.position === 'right') {
  13682. offsetX = w.globals.svgWidth - lRect.clww - 10;
  13683. }
  13684. this.setLegendWrapXY(offsetX, offsetY);
  13685. }
  13686. }, {
  13687. key: "onLegendHovered",
  13688. value: function onLegendHovered(e) {
  13689. var w = this.w;
  13690. var hoverOverLegend = e.target.classList.contains('apexcharts-legend-series') || e.target.classList.contains('apexcharts-legend-text') || e.target.classList.contains('apexcharts-legend-marker');
  13691. if (w.config.chart.type !== 'heatmap' && !this.isBarsDistributed) {
  13692. if (!e.target.classList.contains('apexcharts-inactive-legend') && hoverOverLegend) {
  13693. var series = new Series(this.ctx);
  13694. series.toggleSeriesOnHover(e, e.target);
  13695. }
  13696. } else {
  13697. // for heatmap handling
  13698. if (hoverOverLegend) {
  13699. var seriesCnt = parseInt(e.target.getAttribute('rel'), 10) - 1;
  13700. this.ctx.events.fireEvent('legendHover', [this.ctx, seriesCnt, this.w]);
  13701. var _series = new Series(this.ctx);
  13702. _series.highlightRangeInSeries(e, e.target);
  13703. }
  13704. }
  13705. }
  13706. }, {
  13707. key: "onLegendClick",
  13708. value: function onLegendClick(e) {
  13709. var w = this.w;
  13710. if (w.config.legend.customLegendItems.length) return;
  13711. if (e.target.classList.contains('apexcharts-legend-series') || e.target.classList.contains('apexcharts-legend-text') || e.target.classList.contains('apexcharts-legend-marker')) {
  13712. var seriesCnt = parseInt(e.target.getAttribute('rel'), 10) - 1;
  13713. var isHidden = e.target.getAttribute('data:collapsed') === 'true';
  13714. var legendClick = this.w.config.chart.events.legendClick;
  13715. if (typeof legendClick === 'function') {
  13716. legendClick(this.ctx, seriesCnt, this.w);
  13717. }
  13718. this.ctx.events.fireEvent('legendClick', [this.ctx, seriesCnt, this.w]);
  13719. var markerClick = this.w.config.legend.markers.onClick;
  13720. if (typeof markerClick === 'function' && e.target.classList.contains('apexcharts-legend-marker')) {
  13721. markerClick(this.ctx, seriesCnt, this.w);
  13722. this.ctx.events.fireEvent('legendMarkerClick', [this.ctx, seriesCnt, this.w]);
  13723. }
  13724. // for now - just prevent click on heatmap legend - and allow hover only
  13725. var clickAllowed = w.config.chart.type !== 'treemap' && w.config.chart.type !== 'heatmap' && !this.isBarsDistributed;
  13726. if (clickAllowed && w.config.legend.onItemClick.toggleDataSeries) {
  13727. this.legendHelpers.toggleDataSeries(seriesCnt, isHidden);
  13728. }
  13729. }
  13730. }
  13731. }]);
  13732. return Legend;
  13733. }();
  13734. 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>";
  13735. 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>";
  13736. 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>";
  13737. 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";
  13738. 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";
  13739. 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>";
  13740. 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>";
  13741. /**
  13742. * ApexCharts Toolbar Class for creating toolbar in axis based charts.
  13743. *
  13744. * @module Toolbar
  13745. **/
  13746. var Toolbar = /*#__PURE__*/function () {
  13747. function Toolbar(ctx) {
  13748. _classCallCheck(this, Toolbar);
  13749. this.ctx = ctx;
  13750. this.w = ctx.w;
  13751. var w = this.w;
  13752. this.ev = this.w.config.chart.events;
  13753. this.selectedClass = 'apexcharts-selected';
  13754. this.localeValues = this.w.globals.locale.toolbar;
  13755. this.minX = w.globals.minX;
  13756. this.maxX = w.globals.maxX;
  13757. }
  13758. _createClass(Toolbar, [{
  13759. key: "createToolbar",
  13760. value: function createToolbar() {
  13761. var _this = this;
  13762. var w = this.w;
  13763. var createDiv = function createDiv() {
  13764. return document.createElement('div');
  13765. };
  13766. var elToolbarWrap = createDiv();
  13767. elToolbarWrap.setAttribute('class', 'apexcharts-toolbar');
  13768. elToolbarWrap.style.top = w.config.chart.toolbar.offsetY + 'px';
  13769. elToolbarWrap.style.right = -w.config.chart.toolbar.offsetX + 3 + 'px';
  13770. w.globals.dom.elWrap.appendChild(elToolbarWrap);
  13771. this.elZoom = createDiv();
  13772. this.elZoomIn = createDiv();
  13773. this.elZoomOut = createDiv();
  13774. this.elPan = createDiv();
  13775. this.elSelection = createDiv();
  13776. this.elZoomReset = createDiv();
  13777. this.elMenuIcon = createDiv();
  13778. this.elMenu = createDiv();
  13779. this.elCustomIcons = [];
  13780. this.t = w.config.chart.toolbar.tools;
  13781. if (Array.isArray(this.t.customIcons)) {
  13782. for (var i = 0; i < this.t.customIcons.length; i++) {
  13783. this.elCustomIcons.push(createDiv());
  13784. }
  13785. }
  13786. var toolbarControls = [];
  13787. var appendZoomControl = function appendZoomControl(type, el, ico) {
  13788. var tool = type.toLowerCase();
  13789. if (_this.t[tool] && w.config.chart.zoom.enabled) {
  13790. toolbarControls.push({
  13791. el: el,
  13792. icon: typeof _this.t[tool] === 'string' ? _this.t[tool] : ico,
  13793. title: _this.localeValues[type],
  13794. class: "apexcharts-".concat(tool, "-icon")
  13795. });
  13796. }
  13797. };
  13798. appendZoomControl('zoomIn', this.elZoomIn, icoZoomIn);
  13799. appendZoomControl('zoomOut', this.elZoomOut, icoZoomOut);
  13800. var zoomSelectionCtrls = function zoomSelectionCtrls(z) {
  13801. if (_this.t[z] && w.config.chart[z].enabled) {
  13802. toolbarControls.push({
  13803. el: z === 'zoom' ? _this.elZoom : _this.elSelection,
  13804. icon: typeof _this.t[z] === 'string' ? _this.t[z] : z === 'zoom' ? icoZoom : icoSelect,
  13805. title: _this.localeValues[z === 'zoom' ? 'selectionZoom' : 'selection'],
  13806. class: w.globals.isTouchDevice ? 'apexcharts-element-hidden' : "apexcharts-".concat(z, "-icon")
  13807. });
  13808. }
  13809. };
  13810. zoomSelectionCtrls('zoom');
  13811. zoomSelectionCtrls('selection');
  13812. if (this.t.pan && w.config.chart.zoom.enabled) {
  13813. toolbarControls.push({
  13814. el: this.elPan,
  13815. icon: typeof this.t.pan === 'string' ? this.t.pan : icoPan,
  13816. title: this.localeValues.pan,
  13817. class: w.globals.isTouchDevice ? 'apexcharts-element-hidden' : 'apexcharts-pan-icon'
  13818. });
  13819. }
  13820. appendZoomControl('reset', this.elZoomReset, icoReset);
  13821. if (this.t.download) {
  13822. toolbarControls.push({
  13823. el: this.elMenuIcon,
  13824. icon: typeof this.t.download === 'string' ? this.t.download : icoMenu,
  13825. title: this.localeValues.menu,
  13826. class: 'apexcharts-menu-icon'
  13827. });
  13828. }
  13829. for (var _i = 0; _i < this.elCustomIcons.length; _i++) {
  13830. toolbarControls.push({
  13831. el: this.elCustomIcons[_i],
  13832. icon: this.t.customIcons[_i].icon,
  13833. title: this.t.customIcons[_i].title,
  13834. index: this.t.customIcons[_i].index,
  13835. class: 'apexcharts-toolbar-custom-icon ' + this.t.customIcons[_i].class
  13836. });
  13837. }
  13838. toolbarControls.forEach(function (t, index) {
  13839. if (t.index) {
  13840. Utils$1.moveIndexInArray(toolbarControls, index, t.index);
  13841. }
  13842. });
  13843. for (var _i2 = 0; _i2 < toolbarControls.length; _i2++) {
  13844. Graphics.setAttrs(toolbarControls[_i2].el, {
  13845. class: toolbarControls[_i2].class,
  13846. title: toolbarControls[_i2].title
  13847. });
  13848. toolbarControls[_i2].el.innerHTML = toolbarControls[_i2].icon;
  13849. elToolbarWrap.appendChild(toolbarControls[_i2].el);
  13850. }
  13851. this._createHamburgerMenu(elToolbarWrap);
  13852. if (w.globals.zoomEnabled) {
  13853. this.elZoom.classList.add(this.selectedClass);
  13854. } else if (w.globals.panEnabled) {
  13855. this.elPan.classList.add(this.selectedClass);
  13856. } else if (w.globals.selectionEnabled) {
  13857. this.elSelection.classList.add(this.selectedClass);
  13858. }
  13859. this.addToolbarEventListeners();
  13860. }
  13861. }, {
  13862. key: "_createHamburgerMenu",
  13863. value: function _createHamburgerMenu(parent) {
  13864. this.elMenuItems = [];
  13865. parent.appendChild(this.elMenu);
  13866. Graphics.setAttrs(this.elMenu, {
  13867. class: 'apexcharts-menu'
  13868. });
  13869. var menuItems = [{
  13870. name: 'exportSVG',
  13871. title: this.localeValues.exportToSVG
  13872. }, {
  13873. name: 'exportPNG',
  13874. title: this.localeValues.exportToPNG
  13875. }, {
  13876. name: 'exportCSV',
  13877. title: this.localeValues.exportToCSV
  13878. }];
  13879. for (var i = 0; i < menuItems.length; i++) {
  13880. this.elMenuItems.push(document.createElement('div'));
  13881. this.elMenuItems[i].innerHTML = menuItems[i].title;
  13882. Graphics.setAttrs(this.elMenuItems[i], {
  13883. class: "apexcharts-menu-item ".concat(menuItems[i].name),
  13884. title: menuItems[i].title
  13885. });
  13886. this.elMenu.appendChild(this.elMenuItems[i]);
  13887. }
  13888. }
  13889. }, {
  13890. key: "addToolbarEventListeners",
  13891. value: function addToolbarEventListeners() {
  13892. var _this2 = this;
  13893. this.elZoomReset.addEventListener('click', this.handleZoomReset.bind(this));
  13894. this.elSelection.addEventListener('click', this.toggleZoomSelection.bind(this, 'selection'));
  13895. this.elZoom.addEventListener('click', this.toggleZoomSelection.bind(this, 'zoom'));
  13896. this.elZoomIn.addEventListener('click', this.handleZoomIn.bind(this));
  13897. this.elZoomOut.addEventListener('click', this.handleZoomOut.bind(this));
  13898. this.elPan.addEventListener('click', this.togglePanning.bind(this));
  13899. this.elMenuIcon.addEventListener('click', this.toggleMenu.bind(this));
  13900. this.elMenuItems.forEach(function (m) {
  13901. if (m.classList.contains('exportSVG')) {
  13902. m.addEventListener('click', _this2.handleDownload.bind(_this2, 'svg'));
  13903. } else if (m.classList.contains('exportPNG')) {
  13904. m.addEventListener('click', _this2.handleDownload.bind(_this2, 'png'));
  13905. } else if (m.classList.contains('exportCSV')) {
  13906. m.addEventListener('click', _this2.handleDownload.bind(_this2, 'csv'));
  13907. }
  13908. });
  13909. for (var i = 0; i < this.t.customIcons.length; i++) {
  13910. this.elCustomIcons[i].addEventListener('click', this.t.customIcons[i].click.bind(this, this.ctx, this.ctx.w));
  13911. }
  13912. }
  13913. }, {
  13914. key: "toggleZoomSelection",
  13915. value: function toggleZoomSelection(type) {
  13916. var charts = this.ctx.getSyncedCharts();
  13917. charts.forEach(function (ch) {
  13918. ch.ctx.toolbar.toggleOtherControls();
  13919. var el = type === 'selection' ? ch.ctx.toolbar.elSelection : ch.ctx.toolbar.elZoom;
  13920. var enabledType = type === 'selection' ? 'selectionEnabled' : 'zoomEnabled';
  13921. ch.w.globals[enabledType] = !ch.w.globals[enabledType];
  13922. if (!el.classList.contains(ch.ctx.toolbar.selectedClass)) {
  13923. el.classList.add(ch.ctx.toolbar.selectedClass);
  13924. } else {
  13925. el.classList.remove(ch.ctx.toolbar.selectedClass);
  13926. }
  13927. });
  13928. }
  13929. }, {
  13930. key: "getToolbarIconsReference",
  13931. value: function getToolbarIconsReference() {
  13932. var w = this.w;
  13933. if (!this.elZoom) {
  13934. this.elZoom = w.globals.dom.baseEl.querySelector('.apexcharts-zoom-icon');
  13935. }
  13936. if (!this.elPan) {
  13937. this.elPan = w.globals.dom.baseEl.querySelector('.apexcharts-pan-icon');
  13938. }
  13939. if (!this.elSelection) {
  13940. this.elSelection = w.globals.dom.baseEl.querySelector('.apexcharts-selection-icon');
  13941. }
  13942. }
  13943. }, {
  13944. key: "enableZoomPanFromToolbar",
  13945. value: function enableZoomPanFromToolbar(type) {
  13946. this.toggleOtherControls();
  13947. type === 'pan' ? this.w.globals.panEnabled = true : this.w.globals.zoomEnabled = true;
  13948. var el = type === 'pan' ? this.elPan : this.elZoom;
  13949. var el2 = type === 'pan' ? this.elZoom : this.elPan;
  13950. if (el) {
  13951. el.classList.add(this.selectedClass);
  13952. }
  13953. if (el2) {
  13954. el2.classList.remove(this.selectedClass);
  13955. }
  13956. }
  13957. }, {
  13958. key: "togglePanning",
  13959. value: function togglePanning() {
  13960. var charts = this.ctx.getSyncedCharts();
  13961. charts.forEach(function (ch) {
  13962. ch.ctx.toolbar.toggleOtherControls();
  13963. ch.w.globals.panEnabled = !ch.w.globals.panEnabled;
  13964. if (!ch.ctx.toolbar.elPan.classList.contains(ch.ctx.toolbar.selectedClass)) {
  13965. ch.ctx.toolbar.elPan.classList.add(ch.ctx.toolbar.selectedClass);
  13966. } else {
  13967. ch.ctx.toolbar.elPan.classList.remove(ch.ctx.toolbar.selectedClass);
  13968. }
  13969. });
  13970. }
  13971. }, {
  13972. key: "toggleOtherControls",
  13973. value: function toggleOtherControls() {
  13974. var _this3 = this;
  13975. var w = this.w;
  13976. w.globals.panEnabled = false;
  13977. w.globals.zoomEnabled = false;
  13978. w.globals.selectionEnabled = false;
  13979. this.getToolbarIconsReference();
  13980. var toggleEls = [this.elPan, this.elSelection, this.elZoom];
  13981. toggleEls.forEach(function (el) {
  13982. if (el) {
  13983. el.classList.remove(_this3.selectedClass);
  13984. }
  13985. });
  13986. }
  13987. }, {
  13988. key: "handleZoomIn",
  13989. value: function handleZoomIn() {
  13990. var w = this.w;
  13991. if (w.globals.isRangeBar) {
  13992. this.minX = w.globals.minY;
  13993. this.maxX = w.globals.maxY;
  13994. }
  13995. var centerX = (this.minX + this.maxX) / 2;
  13996. var newMinX = (this.minX + centerX) / 2;
  13997. var newMaxX = (this.maxX + centerX) / 2;
  13998. var newMinXMaxX = this._getNewMinXMaxX(newMinX, newMaxX);
  13999. if (!w.globals.disableZoomIn) {
  14000. this.zoomUpdateOptions(newMinXMaxX.minX, newMinXMaxX.maxX);
  14001. }
  14002. }
  14003. }, {
  14004. key: "handleZoomOut",
  14005. value: function handleZoomOut() {
  14006. var w = this.w;
  14007. if (w.globals.isRangeBar) {
  14008. this.minX = w.globals.minY;
  14009. this.maxX = w.globals.maxY;
  14010. }
  14011. // avoid zooming out beyond 1000 which may result in NaN values being printed on x-axis
  14012. if (w.config.xaxis.type === 'datetime' && new Date(this.minX).getUTCFullYear() < 1000) {
  14013. return;
  14014. }
  14015. var centerX = (this.minX + this.maxX) / 2;
  14016. var newMinX = this.minX - (centerX - this.minX);
  14017. var newMaxX = this.maxX - (centerX - this.maxX);
  14018. var newMinXMaxX = this._getNewMinXMaxX(newMinX, newMaxX);
  14019. if (!w.globals.disableZoomOut) {
  14020. this.zoomUpdateOptions(newMinXMaxX.minX, newMinXMaxX.maxX);
  14021. }
  14022. }
  14023. }, {
  14024. key: "_getNewMinXMaxX",
  14025. value: function _getNewMinXMaxX(newMinX, newMaxX) {
  14026. var shouldFloor = this.w.config.xaxis.convertedCatToNumeric;
  14027. return {
  14028. minX: shouldFloor ? Math.floor(newMinX) : newMinX,
  14029. maxX: shouldFloor ? Math.floor(newMaxX) : newMaxX
  14030. };
  14031. }
  14032. }, {
  14033. key: "zoomUpdateOptions",
  14034. value: function zoomUpdateOptions(newMinX, newMaxX) {
  14035. var w = this.w;
  14036. if (newMinX === undefined && newMaxX === undefined) {
  14037. this.handleZoomReset();
  14038. return;
  14039. }
  14040. if (w.config.xaxis.convertedCatToNumeric) {
  14041. // in category charts, avoid zooming out beyond min and max
  14042. if (newMinX < 1) {
  14043. newMinX = 1;
  14044. newMaxX = w.globals.dataPoints;
  14045. }
  14046. if (newMaxX - newMinX < 2) {
  14047. return;
  14048. }
  14049. }
  14050. var xaxis = {
  14051. min: newMinX,
  14052. max: newMaxX
  14053. };
  14054. var beforeZoomRange = this.getBeforeZoomRange(xaxis);
  14055. if (beforeZoomRange) {
  14056. xaxis = beforeZoomRange.xaxis;
  14057. }
  14058. var options = {
  14059. xaxis: xaxis
  14060. };
  14061. var yaxis = Utils$1.clone(w.globals.initialConfig.yaxis);
  14062. if (!w.config.chart.group) {
  14063. // if chart in a group, prevent yaxis update here
  14064. // fix issue #650
  14065. options.yaxis = yaxis;
  14066. }
  14067. this.w.globals.zoomed = true;
  14068. this.ctx.updateHelpers._updateOptions(options, false, this.w.config.chart.animations.dynamicAnimation.enabled);
  14069. this.zoomCallback(xaxis, yaxis);
  14070. }
  14071. }, {
  14072. key: "zoomCallback",
  14073. value: function zoomCallback(xaxis, yaxis) {
  14074. if (typeof this.ev.zoomed === 'function') {
  14075. this.ev.zoomed(this.ctx, {
  14076. xaxis: xaxis,
  14077. yaxis: yaxis
  14078. });
  14079. }
  14080. }
  14081. }, {
  14082. key: "getBeforeZoomRange",
  14083. value: function getBeforeZoomRange(xaxis, yaxis) {
  14084. var newRange = null;
  14085. if (typeof this.ev.beforeZoom === 'function') {
  14086. newRange = this.ev.beforeZoom(this, {
  14087. xaxis: xaxis,
  14088. yaxis: yaxis
  14089. });
  14090. }
  14091. return newRange;
  14092. }
  14093. }, {
  14094. key: "toggleMenu",
  14095. value: function toggleMenu() {
  14096. var _this4 = this;
  14097. window.setTimeout(function () {
  14098. if (_this4.elMenu.classList.contains('apexcharts-menu-open')) {
  14099. _this4.elMenu.classList.remove('apexcharts-menu-open');
  14100. } else {
  14101. _this4.elMenu.classList.add('apexcharts-menu-open');
  14102. }
  14103. }, 0);
  14104. }
  14105. }, {
  14106. key: "handleDownload",
  14107. value: function handleDownload(type) {
  14108. var w = this.w;
  14109. var exprt = new Exports(this.ctx);
  14110. switch (type) {
  14111. case 'svg':
  14112. exprt.exportToSVG(this.ctx);
  14113. break;
  14114. case 'png':
  14115. exprt.exportToPng(this.ctx);
  14116. break;
  14117. case 'csv':
  14118. exprt.exportToCSV({
  14119. series: w.config.series,
  14120. columnDelimiter: w.config.chart.toolbar.export.csv.columnDelimiter
  14121. });
  14122. break;
  14123. }
  14124. }
  14125. }, {
  14126. key: "handleZoomReset",
  14127. value: function handleZoomReset(e) {
  14128. var charts = this.ctx.getSyncedCharts();
  14129. charts.forEach(function (ch) {
  14130. var w = ch.w;
  14131. // forget lastXAxis min/max as reset button isn't resetting the x-axis completely if zoomX is called before
  14132. w.globals.lastXAxis.min = w.globals.initialConfig.xaxis.min;
  14133. w.globals.lastXAxis.max = w.globals.initialConfig.xaxis.max;
  14134. ch.updateHelpers.revertDefaultAxisMinMax();
  14135. if (typeof w.config.chart.events.beforeResetZoom === 'function') {
  14136. // here, user get an option to control xaxis and yaxis when resetZoom is called
  14137. // at this point, whatever is returned from w.config.chart.events.beforeResetZoom
  14138. // is set as the new xaxis/yaxis min/max
  14139. var resetZoomRange = w.config.chart.events.beforeResetZoom(ch, w);
  14140. if (resetZoomRange) {
  14141. ch.updateHelpers.revertDefaultAxisMinMax(resetZoomRange);
  14142. }
  14143. }
  14144. if (typeof w.config.chart.events.zoomed === 'function') {
  14145. ch.ctx.toolbar.zoomCallback({
  14146. min: w.config.xaxis.min,
  14147. max: w.config.xaxis.max
  14148. });
  14149. }
  14150. w.globals.zoomed = false;
  14151. // if user has some series collapsed before hitting zoom reset button,
  14152. // those series should stay collapsed
  14153. var series = ch.ctx.series.emptyCollapsedSeries(Utils$1.clone(w.globals.initialSeries));
  14154. ch.updateHelpers._updateSeries(series, w.config.chart.animations.dynamicAnimation.enabled);
  14155. });
  14156. }
  14157. }, {
  14158. key: "destroy",
  14159. value: function destroy() {
  14160. this.elZoom = null;
  14161. this.elZoomIn = null;
  14162. this.elZoomOut = null;
  14163. this.elPan = null;
  14164. this.elSelection = null;
  14165. this.elZoomReset = null;
  14166. this.elMenuIcon = null;
  14167. }
  14168. }]);
  14169. return Toolbar;
  14170. }();
  14171. /**
  14172. * ApexCharts Zoom Class for handling zooming and panning on axes based charts.
  14173. *
  14174. * @module ZoomPanSelection
  14175. **/
  14176. var ZoomPanSelection = /*#__PURE__*/function (_Toolbar) {
  14177. _inherits(ZoomPanSelection, _Toolbar);
  14178. var _super = _createSuper(ZoomPanSelection);
  14179. function ZoomPanSelection(ctx) {
  14180. var _this;
  14181. _classCallCheck(this, ZoomPanSelection);
  14182. _this = _super.call(this, ctx);
  14183. _this.ctx = ctx;
  14184. _this.w = ctx.w;
  14185. _this.dragged = false;
  14186. _this.graphics = new Graphics(_this.ctx);
  14187. _this.eventList = ['mousedown', 'mouseleave', 'mousemove', 'touchstart', 'touchmove', 'mouseup', 'touchend', 'wheel'];
  14188. _this.clientX = 0;
  14189. _this.clientY = 0;
  14190. _this.startX = 0;
  14191. _this.endX = 0;
  14192. _this.dragX = 0;
  14193. _this.startY = 0;
  14194. _this.endY = 0;
  14195. _this.dragY = 0;
  14196. _this.moveDirection = 'none';
  14197. _this.debounceTimer = null;
  14198. _this.debounceDelay = 100;
  14199. _this.wheelDelay = 400;
  14200. return _this;
  14201. }
  14202. _createClass(ZoomPanSelection, [{
  14203. key: "init",
  14204. value: function init(_ref) {
  14205. var _this2 = this;
  14206. var xyRatios = _ref.xyRatios;
  14207. var w = this.w;
  14208. var me = this;
  14209. this.xyRatios = xyRatios;
  14210. this.zoomRect = this.graphics.drawRect(0, 0, 0, 0);
  14211. this.selectionRect = this.graphics.drawRect(0, 0, 0, 0);
  14212. this.gridRect = w.globals.dom.baseEl.querySelector('.apexcharts-grid');
  14213. this.zoomRect.node.classList.add('apexcharts-zoom-rect');
  14214. this.selectionRect.node.classList.add('apexcharts-selection-rect');
  14215. w.globals.dom.elGraphical.add(this.zoomRect);
  14216. w.globals.dom.elGraphical.add(this.selectionRect);
  14217. if (w.config.chart.selection.type === 'x') {
  14218. this.slDraggableRect = this.selectionRect.draggable({
  14219. minX: 0,
  14220. minY: 0,
  14221. maxX: w.globals.gridWidth,
  14222. maxY: w.globals.gridHeight
  14223. }).on('dragmove', this.selectionDragging.bind(this, 'dragging'));
  14224. } else if (w.config.chart.selection.type === 'y') {
  14225. this.slDraggableRect = this.selectionRect.draggable({
  14226. minX: 0,
  14227. maxX: w.globals.gridWidth
  14228. }).on('dragmove', this.selectionDragging.bind(this, 'dragging'));
  14229. } else {
  14230. this.slDraggableRect = this.selectionRect.draggable().on('dragmove', this.selectionDragging.bind(this, 'dragging'));
  14231. }
  14232. this.preselectedSelection();
  14233. this.hoverArea = w.globals.dom.baseEl.querySelector("".concat(w.globals.chartClass, " .apexcharts-svg"));
  14234. this.hoverArea.classList.add('apexcharts-zoomable');
  14235. this.eventList.forEach(function (event) {
  14236. _this2.hoverArea.addEventListener(event, me.svgMouseEvents.bind(me, xyRatios), {
  14237. capture: false,
  14238. passive: true
  14239. });
  14240. });
  14241. if (w.config.chart.zoom.allowMouseWheelZoom) {
  14242. this.hoverArea.addEventListener('wheel', me.mouseWheelEvent.bind(me), {
  14243. capture: false,
  14244. passive: false
  14245. });
  14246. }
  14247. }
  14248. // remove the event listeners which were previously added on hover area
  14249. }, {
  14250. key: "destroy",
  14251. value: function destroy() {
  14252. if (this.slDraggableRect) {
  14253. this.slDraggableRect.draggable(false);
  14254. this.slDraggableRect.off();
  14255. this.selectionRect.off();
  14256. }
  14257. this.selectionRect = null;
  14258. this.zoomRect = null;
  14259. this.gridRect = null;
  14260. }
  14261. }, {
  14262. key: "svgMouseEvents",
  14263. value: function svgMouseEvents(xyRatios, e) {
  14264. var w = this.w;
  14265. var me = this;
  14266. var toolbar = this.ctx.toolbar;
  14267. var zoomtype = w.globals.zoomEnabled ? w.config.chart.zoom.type : w.config.chart.selection.type;
  14268. var autoSelected = w.config.chart.toolbar.autoSelected;
  14269. if (e.shiftKey) {
  14270. this.shiftWasPressed = true;
  14271. toolbar.enableZoomPanFromToolbar(autoSelected === 'pan' ? 'zoom' : 'pan');
  14272. } else {
  14273. if (this.shiftWasPressed) {
  14274. toolbar.enableZoomPanFromToolbar(autoSelected);
  14275. this.shiftWasPressed = false;
  14276. }
  14277. }
  14278. if (!e.target) return;
  14279. var tc = e.target.classList;
  14280. var pc;
  14281. if (e.target.parentNode && e.target.parentNode !== null) {
  14282. pc = e.target.parentNode.classList;
  14283. }
  14284. var falsePositives = tc.contains('apexcharts-selection-rect') || tc.contains('apexcharts-legend-marker') || tc.contains('apexcharts-legend-text') || pc && pc.contains('apexcharts-toolbar');
  14285. if (falsePositives) return;
  14286. me.clientX = e.type === 'touchmove' || e.type === 'touchstart' ? e.touches[0].clientX : e.type === 'touchend' ? e.changedTouches[0].clientX : e.clientX;
  14287. me.clientY = e.type === 'touchmove' || e.type === 'touchstart' ? e.touches[0].clientY : e.type === 'touchend' ? e.changedTouches[0].clientY : e.clientY;
  14288. if (e.type === 'mousedown' && e.which === 1) {
  14289. var gridRectDim = me.gridRect.getBoundingClientRect();
  14290. me.startX = me.clientX - gridRectDim.left;
  14291. me.startY = me.clientY - gridRectDim.top;
  14292. me.dragged = false;
  14293. me.w.globals.mousedown = true;
  14294. }
  14295. if (e.type === 'mousemove' && e.which === 1 || e.type === 'touchmove') {
  14296. me.dragged = true;
  14297. if (w.globals.panEnabled) {
  14298. w.globals.selection = null;
  14299. if (me.w.globals.mousedown) {
  14300. me.panDragging({
  14301. context: me,
  14302. zoomtype: zoomtype,
  14303. xyRatios: xyRatios
  14304. });
  14305. }
  14306. } else {
  14307. if (me.w.globals.mousedown && w.globals.zoomEnabled || me.w.globals.mousedown && w.globals.selectionEnabled) {
  14308. me.selection = me.selectionDrawing({
  14309. context: me,
  14310. zoomtype: zoomtype
  14311. });
  14312. }
  14313. }
  14314. }
  14315. if (e.type === 'mouseup' || e.type === 'touchend' || e.type === 'mouseleave') {
  14316. var _me$gridRect;
  14317. // we will be calling getBoundingClientRect on each mousedown/mousemove/mouseup
  14318. var _gridRectDim = (_me$gridRect = me.gridRect) === null || _me$gridRect === void 0 ? void 0 : _me$gridRect.getBoundingClientRect();
  14319. if (_gridRectDim && me.w.globals.mousedown) {
  14320. // user released the drag, now do all the calculations
  14321. me.endX = me.clientX - _gridRectDim.left;
  14322. me.endY = me.clientY - _gridRectDim.top;
  14323. me.dragX = Math.abs(me.endX - me.startX);
  14324. me.dragY = Math.abs(me.endY - me.startY);
  14325. if (w.globals.zoomEnabled || w.globals.selectionEnabled) {
  14326. me.selectionDrawn({
  14327. context: me,
  14328. zoomtype: zoomtype
  14329. });
  14330. }
  14331. if (w.globals.panEnabled && w.config.xaxis.convertedCatToNumeric) {
  14332. me.delayedPanScrolled();
  14333. }
  14334. }
  14335. if (w.globals.zoomEnabled) {
  14336. me.hideSelectionRect(this.selectionRect);
  14337. }
  14338. me.dragged = false;
  14339. me.w.globals.mousedown = false;
  14340. }
  14341. this.makeSelectionRectDraggable();
  14342. }
  14343. }, {
  14344. key: "mouseWheelEvent",
  14345. value: function mouseWheelEvent(e) {
  14346. var _this3 = this;
  14347. var w = this.w;
  14348. e.preventDefault();
  14349. var now = Date.now();
  14350. // Execute immediately if it's the first action or enough time has passed
  14351. if (now - w.globals.lastWheelExecution > this.wheelDelay) {
  14352. this.executeMouseWheelZoom(e);
  14353. w.globals.lastWheelExecution = now;
  14354. }
  14355. if (this.debounceTimer) clearTimeout(this.debounceTimer);
  14356. this.debounceTimer = setTimeout(function () {
  14357. if (now - w.globals.lastWheelExecution > _this3.wheelDelay) {
  14358. _this3.executeMouseWheelZoom(e);
  14359. w.globals.lastWheelExecution = now;
  14360. }
  14361. }, this.debounceDelay);
  14362. }
  14363. }, {
  14364. key: "executeMouseWheelZoom",
  14365. value: function executeMouseWheelZoom(e) {
  14366. var _this$gridRect;
  14367. var w = this.w;
  14368. this.minX = w.globals.isRangeBar ? w.globals.minY : w.globals.minX;
  14369. this.maxX = w.globals.isRangeBar ? w.globals.maxY : w.globals.maxX;
  14370. // Calculate the relative position of the mouse on the chart
  14371. var gridRectDim = (_this$gridRect = this.gridRect) === null || _this$gridRect === void 0 ? void 0 : _this$gridRect.getBoundingClientRect();
  14372. if (!gridRectDim) return;
  14373. var mouseX = (e.clientX - gridRectDim.left) / gridRectDim.width;
  14374. var currentMinX = this.minX;
  14375. var currentMaxX = this.maxX;
  14376. var totalX = currentMaxX - currentMinX;
  14377. // Determine zoom factor
  14378. var zoomFactorIn = 0.5;
  14379. var zoomFactorOut = 1.5;
  14380. var zoomRange;
  14381. var newMinX, newMaxX;
  14382. if (e.deltaY < 0) {
  14383. // Zoom In
  14384. zoomRange = zoomFactorIn * totalX;
  14385. var midPoint = currentMinX + mouseX * totalX;
  14386. newMinX = midPoint - zoomRange / 2;
  14387. newMaxX = midPoint + zoomRange / 2;
  14388. } else {
  14389. // Zoom Out
  14390. zoomRange = zoomFactorOut * totalX;
  14391. newMinX = currentMinX - zoomRange / 2;
  14392. newMaxX = currentMaxX + zoomRange / 2;
  14393. }
  14394. // Constrain within original chart bounds
  14395. if (!w.globals.isRangeBar) {
  14396. newMinX = Math.max(newMinX, w.globals.initialMinX);
  14397. newMaxX = Math.min(newMaxX, w.globals.initialMaxX);
  14398. // Ensure minimum range
  14399. var minRange = (w.globals.initialMaxX - w.globals.initialMinX) * 0.01;
  14400. if (newMaxX - newMinX < minRange) {
  14401. var _midPoint = (newMinX + newMaxX) / 2;
  14402. newMinX = _midPoint - minRange / 2;
  14403. newMaxX = _midPoint + minRange / 2;
  14404. }
  14405. }
  14406. var newMinXMaxX = this._getNewMinXMaxX(newMinX, newMaxX);
  14407. // Apply zoom if valid
  14408. if (!isNaN(newMinXMaxX.minX) && !isNaN(newMinXMaxX.maxX)) {
  14409. this.zoomUpdateOptions(newMinXMaxX.minX, newMinXMaxX.maxX);
  14410. }
  14411. }
  14412. }, {
  14413. key: "makeSelectionRectDraggable",
  14414. value: function makeSelectionRectDraggable() {
  14415. var w = this.w;
  14416. if (!this.selectionRect) return;
  14417. var rectDim = this.selectionRect.node.getBoundingClientRect();
  14418. if (rectDim.width > 0 && rectDim.height > 0) {
  14419. this.slDraggableRect.selectize({
  14420. points: 'l, r',
  14421. pointSize: 8,
  14422. pointType: 'rect'
  14423. }).resize({
  14424. constraint: {
  14425. minX: 0,
  14426. minY: 0,
  14427. maxX: w.globals.gridWidth,
  14428. maxY: w.globals.gridHeight
  14429. }
  14430. }).on('resizing', this.selectionDragging.bind(this, 'resizing'));
  14431. }
  14432. }
  14433. }, {
  14434. key: "preselectedSelection",
  14435. value: function preselectedSelection() {
  14436. var w = this.w;
  14437. var xyRatios = this.xyRatios;
  14438. if (!w.globals.zoomEnabled) {
  14439. if (typeof w.globals.selection !== 'undefined' && w.globals.selection !== null) {
  14440. this.drawSelectionRect(w.globals.selection);
  14441. } else {
  14442. if (w.config.chart.selection.xaxis.min !== undefined && w.config.chart.selection.xaxis.max !== undefined) {
  14443. var x = (w.config.chart.selection.xaxis.min - w.globals.minX) / xyRatios.xRatio;
  14444. var width = w.globals.gridWidth - (w.globals.maxX - w.config.chart.selection.xaxis.max) / xyRatios.xRatio - x;
  14445. if (w.globals.isRangeBar) {
  14446. // rangebars put datetime data in y axis
  14447. x =
  14448. // calculation: (selection left time - chart left time) / milliseconds per pixel = selection X value in pixels
  14449. (w.config.chart.selection.xaxis.min - w.globals.yAxisScale[0].niceMin) / xyRatios.invertedYRatio;
  14450. width = (w.config.chart.selection.xaxis.max - w.config.chart.selection.xaxis.min) / xyRatios.invertedYRatio;
  14451. }
  14452. var selectionRect = {
  14453. x: x,
  14454. y: 0,
  14455. width: width,
  14456. height: w.globals.gridHeight,
  14457. translateX: 0,
  14458. translateY: 0,
  14459. selectionEnabled: true
  14460. };
  14461. this.drawSelectionRect(selectionRect);
  14462. this.makeSelectionRectDraggable();
  14463. if (typeof w.config.chart.events.selection === 'function') {
  14464. w.config.chart.events.selection(this.ctx, {
  14465. xaxis: {
  14466. min: w.config.chart.selection.xaxis.min,
  14467. max: w.config.chart.selection.xaxis.max
  14468. },
  14469. yaxis: {}
  14470. });
  14471. }
  14472. }
  14473. }
  14474. }
  14475. }
  14476. }, {
  14477. key: "drawSelectionRect",
  14478. value: function drawSelectionRect(_ref2) {
  14479. var x = _ref2.x,
  14480. y = _ref2.y,
  14481. width = _ref2.width,
  14482. height = _ref2.height,
  14483. _ref2$translateX = _ref2.translateX,
  14484. translateX = _ref2$translateX === void 0 ? 0 : _ref2$translateX,
  14485. _ref2$translateY = _ref2.translateY,
  14486. translateY = _ref2$translateY === void 0 ? 0 : _ref2$translateY;
  14487. var w = this.w;
  14488. var zoomRect = this.zoomRect;
  14489. var selectionRect = this.selectionRect;
  14490. if (this.dragged || w.globals.selection !== null) {
  14491. var scalingAttrs = {
  14492. transform: 'translate(' + translateX + ', ' + translateY + ')'
  14493. };
  14494. // change styles based on zoom or selection
  14495. // zoom is Enabled and user has dragged, so draw blue rect
  14496. if (w.globals.zoomEnabled && this.dragged) {
  14497. if (width < 0) width = 1; // fixes apexcharts.js#1168
  14498. zoomRect.attr({
  14499. x: x,
  14500. y: y,
  14501. width: width,
  14502. height: height,
  14503. fill: w.config.chart.zoom.zoomedArea.fill.color,
  14504. 'fill-opacity': w.config.chart.zoom.zoomedArea.fill.opacity,
  14505. stroke: w.config.chart.zoom.zoomedArea.stroke.color,
  14506. 'stroke-width': w.config.chart.zoom.zoomedArea.stroke.width,
  14507. 'stroke-opacity': w.config.chart.zoom.zoomedArea.stroke.opacity
  14508. });
  14509. Graphics.setAttrs(zoomRect.node, scalingAttrs);
  14510. }
  14511. // selection is enabled
  14512. if (w.globals.selectionEnabled) {
  14513. selectionRect.attr({
  14514. x: x,
  14515. y: y,
  14516. width: width > 0 ? width : 0,
  14517. height: height > 0 ? height : 0,
  14518. fill: w.config.chart.selection.fill.color,
  14519. 'fill-opacity': w.config.chart.selection.fill.opacity,
  14520. stroke: w.config.chart.selection.stroke.color,
  14521. 'stroke-width': w.config.chart.selection.stroke.width,
  14522. 'stroke-dasharray': w.config.chart.selection.stroke.dashArray,
  14523. 'stroke-opacity': w.config.chart.selection.stroke.opacity
  14524. });
  14525. Graphics.setAttrs(selectionRect.node, scalingAttrs);
  14526. }
  14527. }
  14528. }
  14529. }, {
  14530. key: "hideSelectionRect",
  14531. value: function hideSelectionRect(rect) {
  14532. if (rect) {
  14533. rect.attr({
  14534. x: 0,
  14535. y: 0,
  14536. width: 0,
  14537. height: 0
  14538. });
  14539. }
  14540. }
  14541. }, {
  14542. key: "selectionDrawing",
  14543. value: function selectionDrawing(_ref3) {
  14544. var context = _ref3.context,
  14545. zoomtype = _ref3.zoomtype;
  14546. var w = this.w;
  14547. var me = context;
  14548. var gridRectDim = this.gridRect.getBoundingClientRect();
  14549. var startX = me.startX - 1;
  14550. var startY = me.startY;
  14551. var inversedX = false;
  14552. var inversedY = false;
  14553. var selectionWidth = me.clientX - gridRectDim.left - startX;
  14554. var selectionHeight = me.clientY - gridRectDim.top - startY;
  14555. var selectionRect = {};
  14556. if (Math.abs(selectionWidth + startX) > w.globals.gridWidth) {
  14557. // user dragged the mouse outside drawing area to the right
  14558. selectionWidth = w.globals.gridWidth - startX;
  14559. } else if (me.clientX - gridRectDim.left < 0) {
  14560. // user dragged the mouse outside drawing area to the left
  14561. selectionWidth = startX;
  14562. }
  14563. // inverse selection X
  14564. if (startX > me.clientX - gridRectDim.left) {
  14565. inversedX = true;
  14566. selectionWidth = Math.abs(selectionWidth);
  14567. }
  14568. // inverse selection Y
  14569. if (startY > me.clientY - gridRectDim.top) {
  14570. inversedY = true;
  14571. selectionHeight = Math.abs(selectionHeight);
  14572. }
  14573. if (zoomtype === 'x') {
  14574. selectionRect = {
  14575. x: inversedX ? startX - selectionWidth : startX,
  14576. y: 0,
  14577. width: selectionWidth,
  14578. height: w.globals.gridHeight
  14579. };
  14580. } else if (zoomtype === 'y') {
  14581. selectionRect = {
  14582. x: 0,
  14583. y: inversedY ? startY - selectionHeight : startY,
  14584. width: w.globals.gridWidth,
  14585. height: selectionHeight
  14586. };
  14587. } else {
  14588. selectionRect = {
  14589. x: inversedX ? startX - selectionWidth : startX,
  14590. y: inversedY ? startY - selectionHeight : startY,
  14591. width: selectionWidth,
  14592. height: selectionHeight
  14593. };
  14594. }
  14595. me.drawSelectionRect(selectionRect);
  14596. me.selectionDragging('resizing');
  14597. return selectionRect;
  14598. }
  14599. }, {
  14600. key: "selectionDragging",
  14601. value: function selectionDragging(type, e) {
  14602. var _this4 = this;
  14603. var w = this.w;
  14604. var xyRatios = this.xyRatios;
  14605. var selRect = this.selectionRect;
  14606. var timerInterval = 0;
  14607. if (type === 'resizing') {
  14608. timerInterval = 30;
  14609. }
  14610. // update selection when selection rect is dragged
  14611. var getSelAttr = function getSelAttr(attr) {
  14612. return parseFloat(selRect.node.getAttribute(attr));
  14613. };
  14614. var draggedProps = {
  14615. x: getSelAttr('x'),
  14616. y: getSelAttr('y'),
  14617. width: getSelAttr('width'),
  14618. height: getSelAttr('height')
  14619. };
  14620. w.globals.selection = draggedProps;
  14621. // update selection ends
  14622. if (typeof w.config.chart.events.selection === 'function' && w.globals.selectionEnabled) {
  14623. // a small debouncer is required when resizing to avoid freezing the chart
  14624. clearTimeout(this.w.globals.selectionResizeTimer);
  14625. this.w.globals.selectionResizeTimer = window.setTimeout(function () {
  14626. var gridRectDim = _this4.gridRect.getBoundingClientRect();
  14627. var selectionRect = selRect.node.getBoundingClientRect();
  14628. var minX, maxX, minY, maxY;
  14629. if (!w.globals.isRangeBar) {
  14630. // original code is in the IF. rangeBar exception is in the ELSE.
  14631. minX = w.globals.xAxisScale.niceMin + (selectionRect.left - gridRectDim.left) * xyRatios.xRatio;
  14632. maxX = w.globals.xAxisScale.niceMin + (selectionRect.right - gridRectDim.left) * xyRatios.xRatio;
  14633. minY = w.globals.yAxisScale[0].niceMin + (gridRectDim.bottom - selectionRect.bottom) * xyRatios.yRatio[0];
  14634. maxY = w.globals.yAxisScale[0].niceMax - (selectionRect.top - gridRectDim.top) * xyRatios.yRatio[0];
  14635. } else {
  14636. // rangeBars use x as the category, and y as the datetime data. // find data in y axis and use Y ratio
  14637. minX = w.globals.yAxisScale[0].niceMin + (selectionRect.left - gridRectDim.left) * xyRatios.invertedYRatio;
  14638. maxX = w.globals.yAxisScale[0].niceMin + (selectionRect.right - gridRectDim.left) * xyRatios.invertedYRatio;
  14639. minY = 0; // there is no y min/max with rangebars (it uses categories, not numeric data), so use dummy values
  14640. maxY = 1;
  14641. }
  14642. var xyAxis = {
  14643. xaxis: {
  14644. min: minX,
  14645. max: maxX
  14646. },
  14647. yaxis: {
  14648. min: minY,
  14649. max: maxY
  14650. }
  14651. };
  14652. w.config.chart.events.selection(_this4.ctx, xyAxis);
  14653. if (w.config.chart.brush.enabled && w.config.chart.events.brushScrolled !== undefined) {
  14654. w.config.chart.events.brushScrolled(_this4.ctx, xyAxis);
  14655. }
  14656. }, timerInterval);
  14657. }
  14658. }
  14659. }, {
  14660. key: "selectionDrawn",
  14661. value: function selectionDrawn(_ref4) {
  14662. var context = _ref4.context,
  14663. zoomtype = _ref4.zoomtype;
  14664. var w = this.w;
  14665. var me = context;
  14666. var xyRatios = this.xyRatios;
  14667. var toolbar = this.ctx.toolbar;
  14668. if (me.startX > me.endX) {
  14669. var tempX = me.startX;
  14670. me.startX = me.endX;
  14671. me.endX = tempX;
  14672. }
  14673. if (me.startY > me.endY) {
  14674. var tempY = me.startY;
  14675. me.startY = me.endY;
  14676. me.endY = tempY;
  14677. }
  14678. var xLowestValue = undefined;
  14679. var xHighestValue = undefined;
  14680. if (!w.globals.isRangeBar) {
  14681. xLowestValue = w.globals.xAxisScale.niceMin + me.startX * xyRatios.xRatio;
  14682. xHighestValue = w.globals.xAxisScale.niceMin + me.endX * xyRatios.xRatio;
  14683. } else {
  14684. xLowestValue = w.globals.yAxisScale[0].niceMin + me.startX * xyRatios.invertedYRatio;
  14685. xHighestValue = w.globals.yAxisScale[0].niceMin + me.endX * xyRatios.invertedYRatio;
  14686. }
  14687. // TODO: we will consider the 1st y axis values here for getting highest and lowest y
  14688. var yHighestValue = [];
  14689. var yLowestValue = [];
  14690. w.config.yaxis.forEach(function (yaxe, index) {
  14691. // We can use the index of any series referenced by the Yaxis
  14692. // because they will all return the same value, so we choose the first.
  14693. var seriesIndex = w.globals.seriesYAxisMap[index][0];
  14694. yHighestValue.push(w.globals.yAxisScale[index].niceMax - xyRatios.yRatio[seriesIndex] * me.startY);
  14695. yLowestValue.push(w.globals.yAxisScale[index].niceMax - xyRatios.yRatio[seriesIndex] * me.endY);
  14696. });
  14697. if (me.dragged && (me.dragX > 10 || me.dragY > 10) && xLowestValue !== xHighestValue) {
  14698. if (w.globals.zoomEnabled) {
  14699. var yaxis = Utils$1.clone(w.globals.initialConfig.yaxis);
  14700. var xaxis = Utils$1.clone(w.globals.initialConfig.xaxis);
  14701. w.globals.zoomed = true;
  14702. if (w.config.xaxis.convertedCatToNumeric) {
  14703. xLowestValue = Math.floor(xLowestValue);
  14704. xHighestValue = Math.floor(xHighestValue);
  14705. if (xLowestValue < 1) {
  14706. xLowestValue = 1;
  14707. xHighestValue = w.globals.dataPoints;
  14708. }
  14709. if (xHighestValue - xLowestValue < 2) {
  14710. xHighestValue = xLowestValue + 1;
  14711. }
  14712. }
  14713. if (zoomtype === 'xy' || zoomtype === 'x') {
  14714. xaxis = {
  14715. min: xLowestValue,
  14716. max: xHighestValue
  14717. };
  14718. }
  14719. if (zoomtype === 'xy' || zoomtype === 'y') {
  14720. yaxis.forEach(function (yaxe, index) {
  14721. yaxis[index].min = yLowestValue[index];
  14722. yaxis[index].max = yHighestValue[index];
  14723. });
  14724. }
  14725. if (toolbar) {
  14726. var beforeZoomRange = toolbar.getBeforeZoomRange(xaxis, yaxis);
  14727. if (beforeZoomRange) {
  14728. xaxis = beforeZoomRange.xaxis ? beforeZoomRange.xaxis : xaxis;
  14729. yaxis = beforeZoomRange.yaxis ? beforeZoomRange.yaxis : yaxis;
  14730. }
  14731. }
  14732. var options = {
  14733. xaxis: xaxis
  14734. };
  14735. if (!w.config.chart.group) {
  14736. // if chart in a group, prevent yaxis update here
  14737. // fix issue #650
  14738. options.yaxis = yaxis;
  14739. }
  14740. me.ctx.updateHelpers._updateOptions(options, false, me.w.config.chart.animations.dynamicAnimation.enabled);
  14741. if (typeof w.config.chart.events.zoomed === 'function') {
  14742. toolbar.zoomCallback(xaxis, yaxis);
  14743. }
  14744. } else if (w.globals.selectionEnabled) {
  14745. var _yaxis = null;
  14746. var _xaxis = null;
  14747. _xaxis = {
  14748. min: xLowestValue,
  14749. max: xHighestValue
  14750. };
  14751. if (zoomtype === 'xy' || zoomtype === 'y') {
  14752. _yaxis = Utils$1.clone(w.config.yaxis);
  14753. _yaxis.forEach(function (yaxe, index) {
  14754. _yaxis[index].min = yLowestValue[index];
  14755. _yaxis[index].max = yHighestValue[index];
  14756. });
  14757. }
  14758. w.globals.selection = me.selection;
  14759. if (typeof w.config.chart.events.selection === 'function') {
  14760. w.config.chart.events.selection(me.ctx, {
  14761. xaxis: _xaxis,
  14762. yaxis: _yaxis
  14763. });
  14764. }
  14765. }
  14766. }
  14767. }
  14768. }, {
  14769. key: "panDragging",
  14770. value: function panDragging(_ref5) {
  14771. var context = _ref5.context;
  14772. var w = this.w;
  14773. var me = context;
  14774. // check to make sure there is data to compare against
  14775. if (typeof w.globals.lastClientPosition.x !== 'undefined') {
  14776. // get the change from last position to this position
  14777. var deltaX = w.globals.lastClientPosition.x - me.clientX;
  14778. var deltaY = w.globals.lastClientPosition.y - me.clientY;
  14779. // check which direction had the highest amplitude and then figure out direction by checking if the value is greater or less than zero
  14780. if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX > 0) {
  14781. this.moveDirection = 'left';
  14782. } else if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX < 0) {
  14783. this.moveDirection = 'right';
  14784. } else if (Math.abs(deltaY) > Math.abs(deltaX) && deltaY > 0) {
  14785. this.moveDirection = 'up';
  14786. } else if (Math.abs(deltaY) > Math.abs(deltaX) && deltaY < 0) {
  14787. this.moveDirection = 'down';
  14788. }
  14789. }
  14790. // set the new last position to the current for next time (to get the position of drag)
  14791. w.globals.lastClientPosition = {
  14792. x: me.clientX,
  14793. y: me.clientY
  14794. };
  14795. var xLowestValue = w.globals.isRangeBar ? w.globals.minY : w.globals.minX;
  14796. var xHighestValue = w.globals.isRangeBar ? w.globals.maxY : w.globals.maxX;
  14797. // on a category, we don't pan continuosly as it causes bugs
  14798. if (!w.config.xaxis.convertedCatToNumeric) {
  14799. me.panScrolled(xLowestValue, xHighestValue);
  14800. }
  14801. }
  14802. }, {
  14803. key: "delayedPanScrolled",
  14804. value: function delayedPanScrolled() {
  14805. var w = this.w;
  14806. var newMinX = w.globals.minX;
  14807. var newMaxX = w.globals.maxX;
  14808. var centerX = (w.globals.maxX - w.globals.minX) / 2;
  14809. if (this.moveDirection === 'left') {
  14810. newMinX = w.globals.minX + centerX;
  14811. newMaxX = w.globals.maxX + centerX;
  14812. } else if (this.moveDirection === 'right') {
  14813. newMinX = w.globals.minX - centerX;
  14814. newMaxX = w.globals.maxX - centerX;
  14815. }
  14816. newMinX = Math.floor(newMinX);
  14817. newMaxX = Math.floor(newMaxX);
  14818. this.updateScrolledChart({
  14819. xaxis: {
  14820. min: newMinX,
  14821. max: newMaxX
  14822. }
  14823. }, newMinX, newMaxX);
  14824. }
  14825. }, {
  14826. key: "panScrolled",
  14827. value: function panScrolled(xLowestValue, xHighestValue) {
  14828. var w = this.w;
  14829. var xyRatios = this.xyRatios;
  14830. var yaxis = Utils$1.clone(w.globals.initialConfig.yaxis);
  14831. var xRatio = xyRatios.xRatio;
  14832. var minX = w.globals.minX;
  14833. var maxX = w.globals.maxX;
  14834. if (w.globals.isRangeBar) {
  14835. xRatio = xyRatios.invertedYRatio;
  14836. minX = w.globals.minY;
  14837. maxX = w.globals.maxY;
  14838. }
  14839. if (this.moveDirection === 'left') {
  14840. xLowestValue = minX + w.globals.gridWidth / 15 * xRatio;
  14841. xHighestValue = maxX + w.globals.gridWidth / 15 * xRatio;
  14842. } else if (this.moveDirection === 'right') {
  14843. xLowestValue = minX - w.globals.gridWidth / 15 * xRatio;
  14844. xHighestValue = maxX - w.globals.gridWidth / 15 * xRatio;
  14845. }
  14846. if (!w.globals.isRangeBar) {
  14847. if (xLowestValue < w.globals.initialMinX || xHighestValue > w.globals.initialMaxX) {
  14848. xLowestValue = minX;
  14849. xHighestValue = maxX;
  14850. }
  14851. }
  14852. var options = {
  14853. xaxis: {
  14854. min: xLowestValue,
  14855. max: xHighestValue
  14856. }
  14857. };
  14858. if (!w.config.chart.group) {
  14859. // if chart in a group, prevent yaxis update here
  14860. // fix issue #650
  14861. options.yaxis = yaxis;
  14862. }
  14863. this.updateScrolledChart(options, xLowestValue, xHighestValue);
  14864. }
  14865. }, {
  14866. key: "updateScrolledChart",
  14867. value: function updateScrolledChart(options, xLowestValue, xHighestValue) {
  14868. var w = this.w;
  14869. this.ctx.updateHelpers._updateOptions(options, false, false);
  14870. if (typeof w.config.chart.events.scrolled === 'function') {
  14871. w.config.chart.events.scrolled(this.ctx, {
  14872. xaxis: {
  14873. min: xLowestValue,
  14874. max: xHighestValue
  14875. }
  14876. });
  14877. }
  14878. }
  14879. }]);
  14880. return ZoomPanSelection;
  14881. }(Toolbar);
  14882. /**
  14883. * ApexCharts Tooltip.Utils Class to support Tooltip functionality.
  14884. *
  14885. * @module Tooltip.Utils
  14886. **/
  14887. var Utils = /*#__PURE__*/function () {
  14888. function Utils(tooltipContext) {
  14889. _classCallCheck(this, Utils);
  14890. this.w = tooltipContext.w;
  14891. this.ttCtx = tooltipContext;
  14892. this.ctx = tooltipContext.ctx;
  14893. }
  14894. /**
  14895. ** When hovering over series, you need to capture which series is being hovered on.
  14896. ** This function will return both capturedseries index as well as inner index of that series
  14897. * @memberof Utils
  14898. * @param {object}
  14899. * - hoverArea = the rect on which user hovers
  14900. * - elGrid = dimensions of the hover rect (it can be different than hoverarea)
  14901. */
  14902. _createClass(Utils, [{
  14903. key: "getNearestValues",
  14904. value: function getNearestValues(_ref) {
  14905. var hoverArea = _ref.hoverArea,
  14906. elGrid = _ref.elGrid,
  14907. clientX = _ref.clientX,
  14908. clientY = _ref.clientY;
  14909. var w = this.w;
  14910. var seriesBound = elGrid.getBoundingClientRect();
  14911. var hoverWidth = seriesBound.width;
  14912. var hoverHeight = seriesBound.height;
  14913. var xDivisor = hoverWidth / (w.globals.dataPoints - 1);
  14914. var yDivisor = hoverHeight / w.globals.dataPoints;
  14915. var hasBars = this.hasBars();
  14916. if ((w.globals.comboCharts || hasBars) && !w.config.xaxis.convertedCatToNumeric) {
  14917. xDivisor = hoverWidth / w.globals.dataPoints;
  14918. }
  14919. var hoverX = clientX - seriesBound.left - w.globals.barPadForNumericAxis;
  14920. var hoverY = clientY - seriesBound.top;
  14921. var notInRect = hoverX < 0 || hoverY < 0 || hoverX > hoverWidth || hoverY > hoverHeight;
  14922. if (notInRect) {
  14923. hoverArea.classList.remove('hovering-zoom');
  14924. hoverArea.classList.remove('hovering-pan');
  14925. } else {
  14926. if (w.globals.zoomEnabled) {
  14927. hoverArea.classList.remove('hovering-pan');
  14928. hoverArea.classList.add('hovering-zoom');
  14929. } else if (w.globals.panEnabled) {
  14930. hoverArea.classList.remove('hovering-zoom');
  14931. hoverArea.classList.add('hovering-pan');
  14932. }
  14933. }
  14934. var j = Math.round(hoverX / xDivisor);
  14935. var jHorz = Math.floor(hoverY / yDivisor);
  14936. if (hasBars && !w.config.xaxis.convertedCatToNumeric) {
  14937. j = Math.ceil(hoverX / xDivisor);
  14938. j = j - 1;
  14939. }
  14940. var capturedSeries = null;
  14941. var closest = null;
  14942. var seriesXValArr = w.globals.seriesXvalues.map(function (seriesXVal) {
  14943. return seriesXVal.filter(function (s) {
  14944. return Utils$1.isNumber(s);
  14945. });
  14946. });
  14947. var seriesYValArr = w.globals.seriesYvalues.map(function (seriesYVal) {
  14948. return seriesYVal.filter(function (s) {
  14949. return Utils$1.isNumber(s);
  14950. });
  14951. });
  14952. // 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
  14953. if (w.globals.isXNumeric) {
  14954. // Change origin of cursor position so that we can compute the relative nearest point to the cursor on our chart
  14955. // we only need to scale because all points are relative to the bounds.left and bounds.top => origin is virtually (0, 0)
  14956. var chartGridEl = this.ttCtx.getElGrid();
  14957. var chartGridElBoundingRect = chartGridEl.getBoundingClientRect();
  14958. var transformedHoverX = hoverX * (chartGridElBoundingRect.width / hoverWidth);
  14959. var transformedHoverY = hoverY * (chartGridElBoundingRect.height / hoverHeight);
  14960. closest = this.closestInMultiArray(transformedHoverX, transformedHoverY, seriesXValArr, seriesYValArr);
  14961. capturedSeries = closest.index;
  14962. j = closest.j;
  14963. if (capturedSeries !== null) {
  14964. // initial push, it should be a little smaller than the 1st val
  14965. seriesXValArr = w.globals.seriesXvalues[capturedSeries];
  14966. closest = this.closestInArray(transformedHoverX, seriesXValArr);
  14967. j = closest.index;
  14968. }
  14969. }
  14970. w.globals.capturedSeriesIndex = capturedSeries === null ? -1 : capturedSeries;
  14971. if (!j || j < 1) j = 0;
  14972. if (w.globals.isBarHorizontal) {
  14973. w.globals.capturedDataPointIndex = jHorz;
  14974. } else {
  14975. w.globals.capturedDataPointIndex = j;
  14976. }
  14977. return {
  14978. capturedSeries: capturedSeries,
  14979. j: w.globals.isBarHorizontal ? jHorz : j,
  14980. hoverX: hoverX,
  14981. hoverY: hoverY
  14982. };
  14983. }
  14984. }, {
  14985. key: "closestInMultiArray",
  14986. value: function closestInMultiArray(hoverX, hoverY, Xarrays, Yarrays) {
  14987. var w = this.w;
  14988. var activeIndex = 0;
  14989. var currIndex = null;
  14990. var j = -1;
  14991. if (w.globals.series.length > 1) {
  14992. activeIndex = this.getFirstActiveXArray(Xarrays);
  14993. } else {
  14994. currIndex = 0;
  14995. }
  14996. var currX = Xarrays[activeIndex][0];
  14997. var diffX = Math.abs(hoverX - currX);
  14998. // find nearest point on x-axis
  14999. Xarrays.forEach(function (arrX) {
  15000. arrX.forEach(function (x, iX) {
  15001. var newDiff = Math.abs(hoverX - x);
  15002. if (newDiff <= diffX) {
  15003. diffX = newDiff;
  15004. j = iX;
  15005. }
  15006. });
  15007. });
  15008. if (j !== -1) {
  15009. // find nearest graph on y-axis relevanted to nearest point on x-axis
  15010. var currY = Yarrays[activeIndex][j];
  15011. var diffY = Math.abs(hoverY - currY);
  15012. currIndex = activeIndex;
  15013. Yarrays.forEach(function (arrY, iAY) {
  15014. var newDiff = Math.abs(hoverY - arrY[j]);
  15015. if (newDiff <= diffY) {
  15016. diffY = newDiff;
  15017. currIndex = iAY;
  15018. }
  15019. });
  15020. }
  15021. return {
  15022. index: currIndex,
  15023. j: j
  15024. };
  15025. }
  15026. }, {
  15027. key: "getFirstActiveXArray",
  15028. value: function getFirstActiveXArray(Xarrays) {
  15029. var w = this.w;
  15030. var activeIndex = 0;
  15031. var firstActiveSeriesIndex = Xarrays.map(function (xarr, index) {
  15032. return xarr.length > 0 ? index : -1;
  15033. });
  15034. for (var a = 0; a < firstActiveSeriesIndex.length; a++) {
  15035. if (firstActiveSeriesIndex[a] !== -1 && w.globals.collapsedSeriesIndices.indexOf(a) === -1 && w.globals.ancillaryCollapsedSeriesIndices.indexOf(a) === -1) {
  15036. activeIndex = firstActiveSeriesIndex[a];
  15037. break;
  15038. }
  15039. }
  15040. return activeIndex;
  15041. }
  15042. }, {
  15043. key: "closestInArray",
  15044. value: function closestInArray(val, arr) {
  15045. var curr = arr[0];
  15046. var currIndex = null;
  15047. var diff = Math.abs(val - curr);
  15048. for (var i = 0; i < arr.length; i++) {
  15049. var newdiff = Math.abs(val - arr[i]);
  15050. if (newdiff < diff) {
  15051. diff = newdiff;
  15052. currIndex = i;
  15053. }
  15054. }
  15055. return {
  15056. index: currIndex
  15057. };
  15058. }
  15059. /**
  15060. * When there are multiple series, it is possible to have different x values for each series.
  15061. * But it may be possible in those multiple series, that there is same x value for 2 or more
  15062. * series.
  15063. * @memberof Utils
  15064. * @param {int}
  15065. * - j = is the inner index of series -> (series[i][j])
  15066. * @return {bool}
  15067. */
  15068. }, {
  15069. key: "isXoverlap",
  15070. value: function isXoverlap(j) {
  15071. var w = this.w;
  15072. var xSameForAllSeriesJArr = [];
  15073. var seriesX = w.globals.seriesX.filter(function (s) {
  15074. return typeof s[0] !== 'undefined';
  15075. });
  15076. if (seriesX.length > 0) {
  15077. for (var i = 0; i < seriesX.length - 1; i++) {
  15078. if (typeof seriesX[i][j] !== 'undefined' && typeof seriesX[i + 1][j] !== 'undefined') {
  15079. if (seriesX[i][j] !== seriesX[i + 1][j]) {
  15080. xSameForAllSeriesJArr.push('unEqual');
  15081. }
  15082. }
  15083. }
  15084. }
  15085. if (xSameForAllSeriesJArr.length === 0) {
  15086. return true;
  15087. }
  15088. return false;
  15089. }
  15090. }, {
  15091. key: "isInitialSeriesSameLen",
  15092. value: function isInitialSeriesSameLen() {
  15093. var sameLen = true;
  15094. var initialSeries = this.w.globals.initialSeries;
  15095. for (var i = 0; i < initialSeries.length - 1; i++) {
  15096. if (initialSeries[i].data.length !== initialSeries[i + 1].data.length) {
  15097. sameLen = false;
  15098. break;
  15099. }
  15100. }
  15101. return sameLen;
  15102. }
  15103. }, {
  15104. key: "getBarsHeight",
  15105. value: function getBarsHeight(allbars) {
  15106. var bars = _toConsumableArray(allbars);
  15107. var totalHeight = bars.reduce(function (acc, bar) {
  15108. return acc + bar.getBBox().height;
  15109. }, 0);
  15110. return totalHeight;
  15111. }
  15112. }, {
  15113. key: "getElMarkers",
  15114. value: function getElMarkers(capturedSeries) {
  15115. // The selector .apexcharts-series-markers-wrap > * includes marker groups for which the
  15116. // .apexcharts-series-markers class is not added due to null values or discrete markers
  15117. if (typeof capturedSeries == 'number') {
  15118. return this.w.globals.dom.baseEl.querySelectorAll(".apexcharts-series[data\\:realIndex='".concat(capturedSeries, "'] .apexcharts-series-markers-wrap > *"));
  15119. }
  15120. return this.w.globals.dom.baseEl.querySelectorAll('.apexcharts-series-markers-wrap > *');
  15121. }
  15122. }, {
  15123. key: "getAllMarkers",
  15124. value: function getAllMarkers() {
  15125. // first get all marker parents. This parent class contains series-index
  15126. // which helps to sort the markers as they are dynamic
  15127. var markersWraps = this.w.globals.dom.baseEl.querySelectorAll('.apexcharts-series-markers-wrap');
  15128. markersWraps = _toConsumableArray(markersWraps);
  15129. markersWraps.sort(function (a, b) {
  15130. var indexA = Number(a.getAttribute('data:realIndex'));
  15131. var indexB = Number(b.getAttribute('data:realIndex'));
  15132. return indexB < indexA ? 1 : indexB > indexA ? -1 : 0;
  15133. });
  15134. var markers = [];
  15135. markersWraps.forEach(function (m) {
  15136. markers.push(m.querySelector('.apexcharts-marker'));
  15137. });
  15138. return markers;
  15139. }
  15140. }, {
  15141. key: "hasMarkers",
  15142. value: function hasMarkers(capturedSeries) {
  15143. var markers = this.getElMarkers(capturedSeries);
  15144. return markers.length > 0;
  15145. }
  15146. }, {
  15147. key: "getPathFromPoint",
  15148. value: function getPathFromPoint(point, size) {
  15149. var cx = Number(point.getAttribute('cx'));
  15150. var cy = Number(point.getAttribute('cy'));
  15151. var shape = point.getAttribute('shape');
  15152. return new Graphics(this.ctx).getMarkerPath(cx, cy, shape, size);
  15153. }
  15154. }, {
  15155. key: "getElBars",
  15156. value: function getElBars() {
  15157. return this.w.globals.dom.baseEl.querySelectorAll('.apexcharts-bar-series, .apexcharts-candlestick-series, .apexcharts-boxPlot-series, .apexcharts-rangebar-series');
  15158. }
  15159. }, {
  15160. key: "hasBars",
  15161. value: function hasBars() {
  15162. var bars = this.getElBars();
  15163. return bars.length > 0;
  15164. }
  15165. }, {
  15166. key: "getHoverMarkerSize",
  15167. value: function getHoverMarkerSize(index) {
  15168. var w = this.w;
  15169. var hoverSize = w.config.markers.hover.size;
  15170. if (hoverSize === undefined) {
  15171. hoverSize = w.globals.markers.size[index] + w.config.markers.hover.sizeOffset;
  15172. }
  15173. return hoverSize;
  15174. }
  15175. }, {
  15176. key: "toggleAllTooltipSeriesGroups",
  15177. value: function toggleAllTooltipSeriesGroups(state) {
  15178. var w = this.w;
  15179. var ttCtx = this.ttCtx;
  15180. if (ttCtx.allTooltipSeriesGroups.length === 0) {
  15181. ttCtx.allTooltipSeriesGroups = w.globals.dom.baseEl.querySelectorAll('.apexcharts-tooltip-series-group');
  15182. }
  15183. var allTooltipSeriesGroups = ttCtx.allTooltipSeriesGroups;
  15184. for (var i = 0; i < allTooltipSeriesGroups.length; i++) {
  15185. if (state === 'enable') {
  15186. allTooltipSeriesGroups[i].classList.add('apexcharts-active');
  15187. allTooltipSeriesGroups[i].style.display = w.config.tooltip.items.display;
  15188. } else {
  15189. allTooltipSeriesGroups[i].classList.remove('apexcharts-active');
  15190. allTooltipSeriesGroups[i].style.display = 'none';
  15191. }
  15192. }
  15193. }
  15194. }]);
  15195. return Utils;
  15196. }();
  15197. /**
  15198. * ApexCharts Tooltip.Labels Class to draw texts on the tooltip.
  15199. * This file deals with printing actual text on the tooltip.
  15200. *
  15201. * @module Tooltip.Labels
  15202. **/
  15203. var Labels = /*#__PURE__*/function () {
  15204. function Labels(tooltipContext) {
  15205. _classCallCheck(this, Labels);
  15206. this.w = tooltipContext.w;
  15207. this.ctx = tooltipContext.ctx;
  15208. this.ttCtx = tooltipContext;
  15209. this.tooltipUtil = new Utils(tooltipContext);
  15210. }
  15211. _createClass(Labels, [{
  15212. key: "drawSeriesTexts",
  15213. value: function drawSeriesTexts(_ref) {
  15214. var _ref$shared = _ref.shared,
  15215. shared = _ref$shared === void 0 ? true : _ref$shared,
  15216. ttItems = _ref.ttItems,
  15217. _ref$i = _ref.i,
  15218. i = _ref$i === void 0 ? 0 : _ref$i,
  15219. _ref$j = _ref.j,
  15220. j = _ref$j === void 0 ? null : _ref$j,
  15221. y1 = _ref.y1,
  15222. y2 = _ref.y2,
  15223. e = _ref.e;
  15224. var w = this.w;
  15225. if (w.config.tooltip.custom !== undefined) {
  15226. this.handleCustomTooltip({
  15227. i: i,
  15228. j: j,
  15229. y1: y1,
  15230. y2: y2,
  15231. w: w
  15232. });
  15233. } else {
  15234. this.toggleActiveInactiveSeries(shared, i);
  15235. }
  15236. var values = this.getValuesToPrint({
  15237. i: i,
  15238. j: j
  15239. });
  15240. this.printLabels({
  15241. i: i,
  15242. j: j,
  15243. values: values,
  15244. ttItems: ttItems,
  15245. shared: shared,
  15246. e: e
  15247. });
  15248. // Re-calculate tooltip dimensions now that we have drawn the text
  15249. var tooltipEl = this.ttCtx.getElTooltip();
  15250. this.ttCtx.tooltipRect.ttWidth = tooltipEl.getBoundingClientRect().width;
  15251. this.ttCtx.tooltipRect.ttHeight = tooltipEl.getBoundingClientRect().height;
  15252. }
  15253. }, {
  15254. key: "printLabels",
  15255. value: function printLabels(_ref2) {
  15256. var _this = this;
  15257. var i = _ref2.i,
  15258. j = _ref2.j,
  15259. values = _ref2.values,
  15260. ttItems = _ref2.ttItems,
  15261. shared = _ref2.shared,
  15262. e = _ref2.e;
  15263. var w = this.w;
  15264. var val;
  15265. var goalVals = [];
  15266. var hasGoalValues = function hasGoalValues(gi) {
  15267. return w.globals.seriesGoals[gi] && w.globals.seriesGoals[gi][j] && Array.isArray(w.globals.seriesGoals[gi][j]);
  15268. };
  15269. var xVal = values.xVal,
  15270. zVal = values.zVal,
  15271. xAxisTTVal = values.xAxisTTVal;
  15272. var seriesName = '';
  15273. var pColor = w.globals.colors[i]; // The pColor here is for the markers inside tooltip
  15274. if (j !== null && w.config.plotOptions.bar.distributed) {
  15275. pColor = w.globals.colors[j];
  15276. }
  15277. var _loop = function _loop(t, inverset) {
  15278. var f = _this.getFormatters(i);
  15279. seriesName = _this.getSeriesName({
  15280. fn: f.yLbTitleFormatter,
  15281. index: i,
  15282. seriesIndex: i,
  15283. j: j
  15284. });
  15285. if (w.config.chart.type === 'treemap') {
  15286. seriesName = f.yLbTitleFormatter(String(w.config.series[i].data[j].x), {
  15287. series: w.globals.series,
  15288. seriesIndex: i,
  15289. dataPointIndex: j,
  15290. w: w
  15291. });
  15292. }
  15293. var tIndex = w.config.tooltip.inverseOrder ? inverset : t;
  15294. if (w.globals.axisCharts) {
  15295. var getValBySeriesIndex = function getValBySeriesIndex(index) {
  15296. if (w.globals.isRangeData) {
  15297. var _w$globals$seriesRang, _w$globals$seriesRang2, _w$globals$seriesRang3, _w$globals$seriesRang4;
  15298. 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], {
  15299. series: w.globals.seriesRangeStart,
  15300. seriesIndex: index,
  15301. dataPointIndex: j,
  15302. w: w
  15303. }) + ' - ' + 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], {
  15304. series: w.globals.seriesRangeEnd,
  15305. seriesIndex: index,
  15306. dataPointIndex: j,
  15307. w: w
  15308. });
  15309. }
  15310. return f.yLbFormatter(w.globals.series[index][j], {
  15311. series: w.globals.series,
  15312. seriesIndex: index,
  15313. dataPointIndex: j,
  15314. w: w
  15315. });
  15316. };
  15317. if (shared) {
  15318. f = _this.getFormatters(tIndex);
  15319. seriesName = _this.getSeriesName({
  15320. fn: f.yLbTitleFormatter,
  15321. index: tIndex,
  15322. seriesIndex: i,
  15323. j: j
  15324. });
  15325. pColor = w.globals.colors[tIndex];
  15326. val = getValBySeriesIndex(tIndex);
  15327. if (hasGoalValues(tIndex)) {
  15328. goalVals = w.globals.seriesGoals[tIndex][j].map(function (goal) {
  15329. return {
  15330. attrs: goal,
  15331. val: f.yLbFormatter(goal.value, {
  15332. seriesIndex: tIndex,
  15333. dataPointIndex: j,
  15334. w: w
  15335. })
  15336. };
  15337. });
  15338. }
  15339. } else {
  15340. var _e$target;
  15341. // get a color from a hover area (if it's a line pattern then get from a first line)
  15342. var targetFill = e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.getAttribute('fill');
  15343. if (targetFill) {
  15344. if (targetFill.indexOf('url') !== -1) {
  15345. // pattern fill
  15346. if (targetFill.indexOf('Pattern') !== -1) {
  15347. pColor = w.globals.dom.baseEl.querySelector(targetFill.substr(4).slice(0, -1)).childNodes[0].getAttribute('stroke');
  15348. }
  15349. } else {
  15350. pColor = targetFill;
  15351. }
  15352. }
  15353. val = getValBySeriesIndex(i);
  15354. if (hasGoalValues(i) && Array.isArray(w.globals.seriesGoals[i][j])) {
  15355. goalVals = w.globals.seriesGoals[i][j].map(function (goal) {
  15356. return {
  15357. attrs: goal,
  15358. val: f.yLbFormatter(goal.value, {
  15359. seriesIndex: i,
  15360. dataPointIndex: j,
  15361. w: w
  15362. })
  15363. };
  15364. });
  15365. }
  15366. }
  15367. }
  15368. // for pie / donuts
  15369. if (j === null) {
  15370. val = f.yLbFormatter(w.globals.series[i], _objectSpread2(_objectSpread2({}, w), {}, {
  15371. seriesIndex: i,
  15372. dataPointIndex: i
  15373. }));
  15374. }
  15375. _this.DOMHandling({
  15376. i: i,
  15377. t: tIndex,
  15378. j: j,
  15379. ttItems: ttItems,
  15380. values: {
  15381. val: val,
  15382. goalVals: goalVals,
  15383. xVal: xVal,
  15384. xAxisTTVal: xAxisTTVal,
  15385. zVal: zVal
  15386. },
  15387. seriesName: seriesName,
  15388. shared: shared,
  15389. pColor: pColor
  15390. });
  15391. };
  15392. for (var t = 0, inverset = w.globals.series.length - 1; t < w.globals.series.length; t++, inverset--) {
  15393. _loop(t, inverset);
  15394. }
  15395. }
  15396. }, {
  15397. key: "getFormatters",
  15398. value: function getFormatters(i) {
  15399. var w = this.w;
  15400. var yLbFormatter = w.globals.yLabelFormatters[i];
  15401. var yLbTitleFormatter;
  15402. if (w.globals.ttVal !== undefined) {
  15403. if (Array.isArray(w.globals.ttVal)) {
  15404. yLbFormatter = w.globals.ttVal[i] && w.globals.ttVal[i].formatter;
  15405. yLbTitleFormatter = w.globals.ttVal[i] && w.globals.ttVal[i].title && w.globals.ttVal[i].title.formatter;
  15406. } else {
  15407. yLbFormatter = w.globals.ttVal.formatter;
  15408. if (typeof w.globals.ttVal.title.formatter === 'function') {
  15409. yLbTitleFormatter = w.globals.ttVal.title.formatter;
  15410. }
  15411. }
  15412. } else {
  15413. yLbTitleFormatter = w.config.tooltip.y.title.formatter;
  15414. }
  15415. if (typeof yLbFormatter !== 'function') {
  15416. if (w.globals.yLabelFormatters[0]) {
  15417. yLbFormatter = w.globals.yLabelFormatters[0];
  15418. } else {
  15419. yLbFormatter = function yLbFormatter(label) {
  15420. return label;
  15421. };
  15422. }
  15423. }
  15424. if (typeof yLbTitleFormatter !== 'function') {
  15425. yLbTitleFormatter = function yLbTitleFormatter(label) {
  15426. return label;
  15427. };
  15428. }
  15429. return {
  15430. yLbFormatter: yLbFormatter,
  15431. yLbTitleFormatter: yLbTitleFormatter
  15432. };
  15433. }
  15434. }, {
  15435. key: "getSeriesName",
  15436. value: function getSeriesName(_ref3) {
  15437. var fn = _ref3.fn,
  15438. index = _ref3.index,
  15439. seriesIndex = _ref3.seriesIndex,
  15440. j = _ref3.j;
  15441. var w = this.w;
  15442. return fn(String(w.globals.seriesNames[index]), {
  15443. series: w.globals.series,
  15444. seriesIndex: seriesIndex,
  15445. dataPointIndex: j,
  15446. w: w
  15447. });
  15448. }
  15449. }, {
  15450. key: "DOMHandling",
  15451. value: function DOMHandling(_ref4) {
  15452. _ref4.i;
  15453. var t = _ref4.t,
  15454. j = _ref4.j,
  15455. ttItems = _ref4.ttItems,
  15456. values = _ref4.values,
  15457. seriesName = _ref4.seriesName,
  15458. shared = _ref4.shared,
  15459. pColor = _ref4.pColor;
  15460. var w = this.w;
  15461. var ttCtx = this.ttCtx;
  15462. var val = values.val,
  15463. goalVals = values.goalVals,
  15464. xVal = values.xVal,
  15465. xAxisTTVal = values.xAxisTTVal,
  15466. zVal = values.zVal;
  15467. var ttItemsChildren = null;
  15468. ttItemsChildren = ttItems[t].children;
  15469. if (w.config.tooltip.fillSeriesColor) {
  15470. ttItems[t].style.backgroundColor = pColor;
  15471. ttItemsChildren[0].style.display = 'none';
  15472. }
  15473. if (ttCtx.showTooltipTitle) {
  15474. if (ttCtx.tooltipTitle === null) {
  15475. // get it once if null, and store it in class property
  15476. ttCtx.tooltipTitle = w.globals.dom.baseEl.querySelector('.apexcharts-tooltip-title');
  15477. }
  15478. ttCtx.tooltipTitle.innerHTML = xVal;
  15479. }
  15480. // if xaxis tooltip is constructed, we need to replace the innerHTML
  15481. if (ttCtx.isXAxisTooltipEnabled) {
  15482. ttCtx.xaxisTooltipText.innerHTML = xAxisTTVal !== '' ? xAxisTTVal : xVal;
  15483. }
  15484. var ttYLabel = ttItems[t].querySelector('.apexcharts-tooltip-text-y-label');
  15485. if (ttYLabel) {
  15486. ttYLabel.innerHTML = seriesName ? seriesName : '';
  15487. }
  15488. var ttYVal = ttItems[t].querySelector('.apexcharts-tooltip-text-y-value');
  15489. if (ttYVal) {
  15490. ttYVal.innerHTML = typeof val !== 'undefined' ? val : '';
  15491. }
  15492. if (ttItemsChildren[0] && ttItemsChildren[0].classList.contains('apexcharts-tooltip-marker')) {
  15493. if (w.config.tooltip.marker.fillColors && Array.isArray(w.config.tooltip.marker.fillColors)) {
  15494. pColor = w.config.tooltip.marker.fillColors[t];
  15495. }
  15496. ttItemsChildren[0].style.backgroundColor = pColor;
  15497. }
  15498. if (!w.config.tooltip.marker.show) {
  15499. ttItemsChildren[0].style.display = 'none';
  15500. }
  15501. var ttGLabel = ttItems[t].querySelector('.apexcharts-tooltip-text-goals-label');
  15502. var ttGVal = ttItems[t].querySelector('.apexcharts-tooltip-text-goals-value');
  15503. if (goalVals.length && w.globals.seriesGoals[t]) {
  15504. var createGoalsHtml = function createGoalsHtml() {
  15505. var gLabels = '<div >';
  15506. var gVals = '<div>';
  15507. goalVals.forEach(function (goal, gi) {
  15508. 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>");
  15509. gVals += "<div>".concat(goal.val, "</div>");
  15510. });
  15511. ttGLabel.innerHTML = gLabels + "</div>";
  15512. ttGVal.innerHTML = gVals + "</div>";
  15513. };
  15514. if (shared) {
  15515. if (w.globals.seriesGoals[t][j] && Array.isArray(w.globals.seriesGoals[t][j])) {
  15516. createGoalsHtml();
  15517. } else {
  15518. ttGLabel.innerHTML = '';
  15519. ttGVal.innerHTML = '';
  15520. }
  15521. } else {
  15522. createGoalsHtml();
  15523. }
  15524. } else {
  15525. ttGLabel.innerHTML = '';
  15526. ttGVal.innerHTML = '';
  15527. }
  15528. if (zVal !== null) {
  15529. var ttZLabel = ttItems[t].querySelector('.apexcharts-tooltip-text-z-label');
  15530. ttZLabel.innerHTML = w.config.tooltip.z.title;
  15531. var ttZVal = ttItems[t].querySelector('.apexcharts-tooltip-text-z-value');
  15532. ttZVal.innerHTML = typeof zVal !== 'undefined' ? zVal : '';
  15533. }
  15534. if (shared && ttItemsChildren[0]) {
  15535. // hide when no Val or series collapsed
  15536. if (w.config.tooltip.hideEmptySeries) {
  15537. var ttItemMarker = ttItems[t].querySelector('.apexcharts-tooltip-marker');
  15538. var ttItemText = ttItems[t].querySelector('.apexcharts-tooltip-text');
  15539. if (parseFloat(val) == 0) {
  15540. ttItemMarker.style.display = 'none';
  15541. ttItemText.style.display = 'none';
  15542. } else {
  15543. ttItemMarker.style.display = 'block';
  15544. ttItemText.style.display = 'block';
  15545. }
  15546. }
  15547. 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) {
  15548. ttItemsChildren[0].parentNode.style.display = 'none';
  15549. } else {
  15550. ttItemsChildren[0].parentNode.style.display = w.config.tooltip.items.display;
  15551. }
  15552. } else {
  15553. if (Array.isArray(ttCtx.tConfig.enabledOnSeries) && ttCtx.tConfig.enabledOnSeries.indexOf(t) === -1) {
  15554. ttItemsChildren[0].parentNode.style.display = 'none';
  15555. }
  15556. }
  15557. }
  15558. }, {
  15559. key: "toggleActiveInactiveSeries",
  15560. value: function toggleActiveInactiveSeries(shared, i) {
  15561. var w = this.w;
  15562. if (shared) {
  15563. // make all tooltips active
  15564. this.tooltipUtil.toggleAllTooltipSeriesGroups('enable');
  15565. } else {
  15566. // disable all tooltip text groups
  15567. this.tooltipUtil.toggleAllTooltipSeriesGroups('disable');
  15568. // enable the first tooltip text group
  15569. var firstTooltipSeriesGroup = w.globals.dom.baseEl.querySelector(".apexcharts-tooltip-series-group-".concat(i));
  15570. if (firstTooltipSeriesGroup) {
  15571. firstTooltipSeriesGroup.classList.add('apexcharts-active');
  15572. firstTooltipSeriesGroup.style.display = w.config.tooltip.items.display;
  15573. }
  15574. }
  15575. }
  15576. }, {
  15577. key: "getValuesToPrint",
  15578. value: function getValuesToPrint(_ref5) {
  15579. var i = _ref5.i,
  15580. j = _ref5.j;
  15581. var w = this.w;
  15582. var filteredSeriesX = this.ctx.series.filteredSeriesX();
  15583. var xVal = '';
  15584. var xAxisTTVal = '';
  15585. var zVal = null;
  15586. var val = null;
  15587. var customFormatterOpts = {
  15588. series: w.globals.series,
  15589. seriesIndex: i,
  15590. dataPointIndex: j,
  15591. w: w
  15592. };
  15593. var zFormatter = w.globals.ttZFormatter;
  15594. if (j === null) {
  15595. val = w.globals.series[i];
  15596. } else {
  15597. if (w.globals.isXNumeric && w.config.chart.type !== 'treemap') {
  15598. xVal = filteredSeriesX[i][j];
  15599. if (filteredSeriesX[i].length === 0) {
  15600. // a series (possibly the first one) might be collapsed, so get the next active index
  15601. var firstActiveSeriesIndex = this.tooltipUtil.getFirstActiveXArray(filteredSeriesX);
  15602. xVal = filteredSeriesX[firstActiveSeriesIndex][j];
  15603. }
  15604. } else {
  15605. var dataFormat = new Data(this.ctx);
  15606. if (dataFormat.isFormatXY()) {
  15607. xVal = typeof w.config.series[i].data[j] !== 'undefined' ? w.config.series[i].data[j].x : '';
  15608. } else {
  15609. xVal = typeof w.globals.labels[j] !== 'undefined' ? w.globals.labels[j] : '';
  15610. }
  15611. }
  15612. }
  15613. var bufferXVal = xVal;
  15614. if (w.globals.isXNumeric && w.config.xaxis.type === 'datetime') {
  15615. var xFormat = new Formatters(this.ctx);
  15616. xVal = xFormat.xLabelFormat(w.globals.ttKeyFormatter, bufferXVal, bufferXVal, {
  15617. i: undefined,
  15618. dateFormatter: new DateTime(this.ctx).formatDate,
  15619. w: this.w
  15620. });
  15621. } else {
  15622. if (w.globals.isBarHorizontal) {
  15623. xVal = w.globals.yLabelFormatters[0](bufferXVal, customFormatterOpts);
  15624. } else {
  15625. xVal = w.globals.xLabelFormatter(bufferXVal, customFormatterOpts);
  15626. }
  15627. }
  15628. // override default x-axis formatter with tooltip formatter
  15629. if (w.config.tooltip.x.formatter !== undefined) {
  15630. xVal = w.globals.ttKeyFormatter(bufferXVal, customFormatterOpts);
  15631. }
  15632. if (w.globals.seriesZ.length > 0 && w.globals.seriesZ[i].length > 0) {
  15633. zVal = zFormatter(w.globals.seriesZ[i][j], w);
  15634. }
  15635. if (typeof w.config.xaxis.tooltip.formatter === 'function') {
  15636. xAxisTTVal = w.globals.xaxisTooltipFormatter(bufferXVal, customFormatterOpts);
  15637. } else {
  15638. xAxisTTVal = xVal;
  15639. }
  15640. return {
  15641. val: Array.isArray(val) ? val.join(' ') : val,
  15642. xVal: Array.isArray(xVal) ? xVal.join(' ') : xVal,
  15643. xAxisTTVal: Array.isArray(xAxisTTVal) ? xAxisTTVal.join(' ') : xAxisTTVal,
  15644. zVal: zVal
  15645. };
  15646. }
  15647. }, {
  15648. key: "handleCustomTooltip",
  15649. value: function handleCustomTooltip(_ref6) {
  15650. var i = _ref6.i,
  15651. j = _ref6.j,
  15652. y1 = _ref6.y1,
  15653. y2 = _ref6.y2,
  15654. w = _ref6.w;
  15655. var tooltipEl = this.ttCtx.getElTooltip();
  15656. var fn = w.config.tooltip.custom;
  15657. if (Array.isArray(fn) && fn[i]) {
  15658. fn = fn[i];
  15659. }
  15660. // override everything with a custom html tooltip and replace it
  15661. tooltipEl.innerHTML = fn({
  15662. ctx: this.ctx,
  15663. series: w.globals.series,
  15664. seriesIndex: i,
  15665. dataPointIndex: j,
  15666. y1: y1,
  15667. y2: y2,
  15668. w: w
  15669. });
  15670. }
  15671. }]);
  15672. return Labels;
  15673. }();
  15674. /**
  15675. * ApexCharts Tooltip.Position Class to move the tooltip based on x and y position.
  15676. *
  15677. * @module Tooltip.Position
  15678. **/
  15679. var Position = /*#__PURE__*/function () {
  15680. function Position(tooltipContext) {
  15681. _classCallCheck(this, Position);
  15682. this.ttCtx = tooltipContext;
  15683. this.ctx = tooltipContext.ctx;
  15684. this.w = tooltipContext.w;
  15685. }
  15686. /**
  15687. * This will move the crosshair (the vertical/horz line that moves along with mouse)
  15688. * Along with this, this function also calls the xaxisMove function
  15689. * @memberof Position
  15690. * @param {int} - cx = point's x position, wherever point's x is, you need to move crosshair
  15691. */
  15692. _createClass(Position, [{
  15693. key: "moveXCrosshairs",
  15694. value: function moveXCrosshairs(cx) {
  15695. var j = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  15696. var ttCtx = this.ttCtx;
  15697. var w = this.w;
  15698. var xcrosshairs = ttCtx.getElXCrosshairs();
  15699. var x = cx - ttCtx.xcrosshairsWidth / 2;
  15700. var tickAmount = w.globals.labels.slice().length;
  15701. if (j !== null) {
  15702. x = w.globals.gridWidth / tickAmount * j;
  15703. }
  15704. if (xcrosshairs !== null && !w.globals.isBarHorizontal) {
  15705. xcrosshairs.setAttribute('x', x);
  15706. xcrosshairs.setAttribute('x1', x);
  15707. xcrosshairs.setAttribute('x2', x);
  15708. xcrosshairs.setAttribute('y2', w.globals.gridHeight);
  15709. xcrosshairs.classList.add('apexcharts-active');
  15710. }
  15711. if (x < 0) {
  15712. x = 0;
  15713. }
  15714. if (x > w.globals.gridWidth) {
  15715. x = w.globals.gridWidth;
  15716. }
  15717. if (ttCtx.isXAxisTooltipEnabled) {
  15718. var tx = x;
  15719. if (w.config.xaxis.crosshairs.width === 'tickWidth' || w.config.xaxis.crosshairs.width === 'barWidth') {
  15720. tx = x + ttCtx.xcrosshairsWidth / 2;
  15721. }
  15722. this.moveXAxisTooltip(tx);
  15723. }
  15724. }
  15725. /**
  15726. * This will move the crosshair (the vertical/horz line that moves along with mouse)
  15727. * Along with this, this function also calls the xaxisMove function
  15728. * @memberof Position
  15729. * @param {int} - cx = point's x position, wherever point's x is, you need to move crosshair
  15730. */
  15731. }, {
  15732. key: "moveYCrosshairs",
  15733. value: function moveYCrosshairs(cy) {
  15734. var ttCtx = this.ttCtx;
  15735. if (ttCtx.ycrosshairs !== null) {
  15736. Graphics.setAttrs(ttCtx.ycrosshairs, {
  15737. y1: cy,
  15738. y2: cy
  15739. });
  15740. }
  15741. if (ttCtx.ycrosshairsHidden !== null) {
  15742. Graphics.setAttrs(ttCtx.ycrosshairsHidden, {
  15743. y1: cy,
  15744. y2: cy
  15745. });
  15746. }
  15747. }
  15748. /**
  15749. ** AxisTooltip is the small rectangle which appears on x axis with x value, when user moves
  15750. * @memberof Position
  15751. * @param {int} - cx = point's x position, wherever point's x is, you need to move
  15752. */
  15753. }, {
  15754. key: "moveXAxisTooltip",
  15755. value: function moveXAxisTooltip(cx) {
  15756. var w = this.w;
  15757. var ttCtx = this.ttCtx;
  15758. if (ttCtx.xaxisTooltip !== null && ttCtx.xcrosshairsWidth !== 0) {
  15759. ttCtx.xaxisTooltip.classList.add('apexcharts-active');
  15760. var cy = ttCtx.xaxisOffY + w.config.xaxis.tooltip.offsetY + w.globals.translateY + 1 + w.config.xaxis.offsetY;
  15761. var xaxisTTText = ttCtx.xaxisTooltip.getBoundingClientRect();
  15762. var xaxisTTTextWidth = xaxisTTText.width;
  15763. cx = cx - xaxisTTTextWidth / 2;
  15764. if (!isNaN(cx)) {
  15765. cx = cx + w.globals.translateX;
  15766. var textRect = 0;
  15767. var graphics = new Graphics(this.ctx);
  15768. textRect = graphics.getTextRects(ttCtx.xaxisTooltipText.innerHTML);
  15769. ttCtx.xaxisTooltipText.style.minWidth = textRect.width + 'px';
  15770. ttCtx.xaxisTooltip.style.left = cx + 'px';
  15771. ttCtx.xaxisTooltip.style.top = cy + 'px';
  15772. }
  15773. }
  15774. }
  15775. }, {
  15776. key: "moveYAxisTooltip",
  15777. value: function moveYAxisTooltip(index) {
  15778. var w = this.w;
  15779. var ttCtx = this.ttCtx;
  15780. if (ttCtx.yaxisTTEls === null) {
  15781. ttCtx.yaxisTTEls = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxistooltip');
  15782. }
  15783. var ycrosshairsHiddenRectY1 = parseInt(ttCtx.ycrosshairsHidden.getAttribute('y1'), 10);
  15784. var cy = w.globals.translateY + ycrosshairsHiddenRectY1;
  15785. var yAxisTTRect = ttCtx.yaxisTTEls[index].getBoundingClientRect();
  15786. var yAxisTTHeight = yAxisTTRect.height;
  15787. var cx = w.globals.translateYAxisX[index] - 2;
  15788. if (w.config.yaxis[index].opposite) {
  15789. cx = cx - 26;
  15790. }
  15791. cy = cy - yAxisTTHeight / 2;
  15792. if (w.globals.ignoreYAxisIndexes.indexOf(index) === -1) {
  15793. ttCtx.yaxisTTEls[index].classList.add('apexcharts-active');
  15794. ttCtx.yaxisTTEls[index].style.top = cy + 'px';
  15795. ttCtx.yaxisTTEls[index].style.left = cx + w.config.yaxis[index].tooltip.offsetX + 'px';
  15796. } else {
  15797. ttCtx.yaxisTTEls[index].classList.remove('apexcharts-active');
  15798. }
  15799. }
  15800. /**
  15801. ** moves the whole tooltip by changing x, y attrs
  15802. * @memberof Position
  15803. * @param {int} - cx = point's x position, wherever point's x is, you need to move tooltip
  15804. * @param {int} - cy = point's y position, wherever point's y is, you need to move tooltip
  15805. * @param {int} - markerSize = point's size
  15806. */
  15807. }, {
  15808. key: "moveTooltip",
  15809. value: function moveTooltip(cx, cy) {
  15810. var markerSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  15811. var w = this.w;
  15812. var ttCtx = this.ttCtx;
  15813. var tooltipEl = ttCtx.getElTooltip();
  15814. var tooltipRect = ttCtx.tooltipRect;
  15815. var pointSize = markerSize !== null ? parseFloat(markerSize) : 1;
  15816. var x = parseFloat(cx) + pointSize + 5;
  15817. var y = parseFloat(cy) + pointSize / 2; // - tooltipRect.ttHeight / 2
  15818. if (x > w.globals.gridWidth / 2) {
  15819. x = x - tooltipRect.ttWidth - pointSize - 10;
  15820. }
  15821. if (x > w.globals.gridWidth - tooltipRect.ttWidth - 10) {
  15822. x = w.globals.gridWidth - tooltipRect.ttWidth;
  15823. }
  15824. if (x < -20) {
  15825. x = -20;
  15826. }
  15827. if (w.config.tooltip.followCursor) {
  15828. var elGrid = ttCtx.getElGrid();
  15829. var seriesBound = elGrid.getBoundingClientRect();
  15830. x = ttCtx.e.clientX - seriesBound.left;
  15831. if (x > w.globals.gridWidth / 2) {
  15832. x = x - ttCtx.tooltipRect.ttWidth;
  15833. }
  15834. y = ttCtx.e.clientY + w.globals.translateY - seriesBound.top;
  15835. if (y > w.globals.gridHeight / 2) {
  15836. y = y - ttCtx.tooltipRect.ttHeight;
  15837. }
  15838. } else {
  15839. if (!w.globals.isBarHorizontal) {
  15840. if (tooltipRect.ttHeight / 2 + y > w.globals.gridHeight) {
  15841. y = w.globals.gridHeight - tooltipRect.ttHeight + w.globals.translateY;
  15842. }
  15843. }
  15844. }
  15845. if (!isNaN(x)) {
  15846. x = x + w.globals.translateX;
  15847. tooltipEl.style.left = x + 'px';
  15848. tooltipEl.style.top = y + 'px';
  15849. }
  15850. }
  15851. }, {
  15852. key: "moveMarkers",
  15853. value: function moveMarkers(i, j) {
  15854. var w = this.w;
  15855. var ttCtx = this.ttCtx;
  15856. if (w.globals.markers.size[i] > 0) {
  15857. var allPoints = w.globals.dom.baseEl.querySelectorAll(" .apexcharts-series[data\\:realIndex='".concat(i, "'] .apexcharts-marker"));
  15858. for (var p = 0; p < allPoints.length; p++) {
  15859. if (parseInt(allPoints[p].getAttribute('rel'), 10) === j) {
  15860. ttCtx.marker.resetPointsSize();
  15861. ttCtx.marker.enlargeCurrentPoint(j, allPoints[p]);
  15862. }
  15863. }
  15864. } else {
  15865. ttCtx.marker.resetPointsSize();
  15866. this.moveDynamicPointOnHover(j, i);
  15867. }
  15868. }
  15869. // This function is used when you need to show markers/points only on hover -
  15870. // DIFFERENT X VALUES in multiple series
  15871. }, {
  15872. key: "moveDynamicPointOnHover",
  15873. value: function moveDynamicPointOnHover(j, capturedSeries) {
  15874. var _pointsArr$capturedSe, _pointsArr$capturedSe2;
  15875. var w = this.w;
  15876. var ttCtx = this.ttCtx;
  15877. var cx = 0;
  15878. var cy = 0;
  15879. var graphics = new Graphics(this.ctx);
  15880. var pointsArr = w.globals.pointsArray;
  15881. var hoverSize = ttCtx.tooltipUtil.getHoverMarkerSize(capturedSeries);
  15882. var serType = w.config.series[capturedSeries].type;
  15883. if (serType && (serType === 'column' || serType === 'candlestick' || serType === 'boxPlot')) {
  15884. // fix error mentioned in #811
  15885. return;
  15886. }
  15887. cx = (_pointsArr$capturedSe = pointsArr[capturedSeries][j]) === null || _pointsArr$capturedSe === void 0 ? void 0 : _pointsArr$capturedSe[0];
  15888. cy = ((_pointsArr$capturedSe2 = pointsArr[capturedSeries][j]) === null || _pointsArr$capturedSe2 === void 0 ? void 0 : _pointsArr$capturedSe2[1]) || 0;
  15889. var point = w.globals.dom.baseEl.querySelector(".apexcharts-series[data\\:realIndex='".concat(capturedSeries, "'] .apexcharts-series-markers path"));
  15890. if (point && cy < w.globals.gridHeight && cy > 0) {
  15891. var shape = point.getAttribute('shape');
  15892. var path = graphics.getMarkerPath(cx, cy, shape, hoverSize * 1.5);
  15893. point.setAttribute('d', path);
  15894. }
  15895. this.moveXCrosshairs(cx);
  15896. if (!ttCtx.fixedTooltip) {
  15897. this.moveTooltip(cx, cy, hoverSize);
  15898. }
  15899. }
  15900. // This function is used when you need to show markers/points only on hover -
  15901. // SAME X VALUES in multiple series
  15902. }, {
  15903. key: "moveDynamicPointsOnHover",
  15904. value: function moveDynamicPointsOnHover(j) {
  15905. var ttCtx = this.ttCtx;
  15906. var w = ttCtx.w;
  15907. var cx = 0;
  15908. var cy = 0;
  15909. var activeSeries = 0;
  15910. var pointsArr = w.globals.pointsArray;
  15911. var series = new Series(this.ctx);
  15912. var graphics = new Graphics(this.ctx);
  15913. activeSeries = series.getActiveConfigSeriesIndex('asc', ['line', 'area', 'scatter', 'bubble']);
  15914. var hoverSize = ttCtx.tooltipUtil.getHoverMarkerSize(activeSeries);
  15915. if (pointsArr[activeSeries]) {
  15916. cx = pointsArr[activeSeries][j][0];
  15917. cy = pointsArr[activeSeries][j][1];
  15918. }
  15919. var points = ttCtx.tooltipUtil.getAllMarkers();
  15920. if (points !== null) {
  15921. for (var p = 0; p < w.globals.series.length; p++) {
  15922. var pointArr = pointsArr[p];
  15923. if (w.globals.comboCharts) {
  15924. // 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
  15925. if (typeof pointArr === 'undefined') {
  15926. // nodelist to array
  15927. points.splice(p, 0, null);
  15928. }
  15929. }
  15930. if (pointArr && pointArr.length) {
  15931. var pcy = pointsArr[p][j][1];
  15932. var pcy2 = void 0;
  15933. points[p].setAttribute('cx', cx);
  15934. var shape = points[p].getAttribute('shape');
  15935. if (w.config.chart.type === 'rangeArea' && !w.globals.comboCharts) {
  15936. var rangeStartIndex = j + w.globals.series[p].length;
  15937. pcy2 = pointsArr[p][rangeStartIndex][1];
  15938. var pcyDiff = Math.abs(pcy - pcy2) / 2;
  15939. pcy = pcy - pcyDiff;
  15940. }
  15941. if (pcy !== null && !isNaN(pcy) && pcy < w.globals.gridHeight + hoverSize && pcy + hoverSize > 0) {
  15942. var path = graphics.getMarkerPath(cx, pcy, shape, hoverSize);
  15943. points[p].setAttribute('d', path);
  15944. } else {
  15945. points[p].setAttribute('d', '');
  15946. }
  15947. }
  15948. }
  15949. }
  15950. this.moveXCrosshairs(cx);
  15951. if (!ttCtx.fixedTooltip) {
  15952. this.moveTooltip(cx, cy || w.globals.gridHeight, hoverSize);
  15953. }
  15954. }
  15955. }, {
  15956. key: "moveStickyTooltipOverBars",
  15957. value: function moveStickyTooltipOverBars(j, capturedSeries) {
  15958. var w = this.w;
  15959. var ttCtx = this.ttCtx;
  15960. var barLen = w.globals.columnSeries ? w.globals.columnSeries.length : w.globals.series.length;
  15961. var i = barLen >= 2 && barLen % 2 === 0 ? Math.floor(barLen / 2) : Math.floor(barLen / 2) + 1;
  15962. if (w.globals.isBarHorizontal) {
  15963. var series = new Series(this.ctx);
  15964. i = series.getActiveConfigSeriesIndex('desc') + 1;
  15965. }
  15966. 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, "']"));
  15967. if (!jBar && typeof capturedSeries === 'number') {
  15968. // Try with captured series index
  15969. 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, "']"));
  15970. }
  15971. var bcx = jBar ? parseFloat(jBar.getAttribute('cx')) : 0;
  15972. var bcy = jBar ? parseFloat(jBar.getAttribute('cy')) : 0;
  15973. var bw = jBar ? parseFloat(jBar.getAttribute('barWidth')) : 0;
  15974. var elGrid = ttCtx.getElGrid();
  15975. var seriesBound = elGrid.getBoundingClientRect();
  15976. var isBoxOrCandle = jBar && (jBar.classList.contains('apexcharts-candlestick-area') || jBar.classList.contains('apexcharts-boxPlot-area'));
  15977. if (w.globals.isXNumeric) {
  15978. if (jBar && !isBoxOrCandle) {
  15979. bcx = bcx - (barLen % 2 !== 0 ? bw / 2 : 0);
  15980. }
  15981. if (jBar &&
  15982. // fixes apexcharts.js#2354
  15983. isBoxOrCandle && w.globals.comboCharts) {
  15984. bcx = bcx - bw / 2;
  15985. }
  15986. } else {
  15987. if (!w.globals.isBarHorizontal) {
  15988. bcx = ttCtx.xAxisTicksPositions[j - 1] + ttCtx.dataPointsDividedWidth / 2;
  15989. if (isNaN(bcx)) {
  15990. bcx = ttCtx.xAxisTicksPositions[j] - ttCtx.dataPointsDividedWidth / 2;
  15991. }
  15992. }
  15993. }
  15994. if (!w.globals.isBarHorizontal) {
  15995. if (w.config.tooltip.followCursor) {
  15996. bcy = ttCtx.e.clientY - seriesBound.top - ttCtx.tooltipRect.ttHeight / 2;
  15997. } else {
  15998. if (bcy + ttCtx.tooltipRect.ttHeight + 15 > w.globals.gridHeight) {
  15999. bcy = w.globals.gridHeight;
  16000. }
  16001. }
  16002. } else {
  16003. bcy = bcy - ttCtx.tooltipRect.ttHeight;
  16004. }
  16005. if (!w.globals.isBarHorizontal) {
  16006. this.moveXCrosshairs(bcx);
  16007. }
  16008. if (!ttCtx.fixedTooltip) {
  16009. this.moveTooltip(bcx, bcy || w.globals.gridHeight);
  16010. }
  16011. }
  16012. }]);
  16013. return Position;
  16014. }();
  16015. /**
  16016. * ApexCharts Tooltip.Marker Class to draw texts on the tooltip.
  16017. * This file deals with the markers that appear near tooltip in line/area charts.
  16018. * These markers helps the user to associate the data-points and the values
  16019. * that are shown in the tooltip
  16020. *
  16021. * @module Tooltip.Marker
  16022. **/
  16023. var Marker = /*#__PURE__*/function () {
  16024. function Marker(tooltipContext) {
  16025. _classCallCheck(this, Marker);
  16026. this.w = tooltipContext.w;
  16027. this.ttCtx = tooltipContext;
  16028. this.ctx = tooltipContext.ctx;
  16029. this.tooltipPosition = new Position(tooltipContext);
  16030. }
  16031. _createClass(Marker, [{
  16032. key: "drawDynamicPoints",
  16033. value: function drawDynamicPoints() {
  16034. var w = this.w;
  16035. var graphics = new Graphics(this.ctx);
  16036. var marker = new Markers(this.ctx);
  16037. var elsSeries = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series');
  16038. elsSeries = _toConsumableArray(elsSeries);
  16039. if (w.config.chart.stacked) {
  16040. elsSeries.sort(function (a, b) {
  16041. return parseFloat(a.getAttribute('data:realIndex')) - parseFloat(b.getAttribute('data:realIndex'));
  16042. });
  16043. }
  16044. for (var i = 0; i < elsSeries.length; i++) {
  16045. var pointsMain = elsSeries[i].querySelector(".apexcharts-series-markers-wrap");
  16046. if (pointsMain !== null) {
  16047. // it can be null as we have tooltips in donut/bar charts
  16048. var point = void 0;
  16049. var PointClasses = "apexcharts-marker w".concat((Math.random() + 1).toString(36).substring(4));
  16050. if ((w.config.chart.type === 'line' || w.config.chart.type === 'area') && !w.globals.comboCharts && !w.config.tooltip.intersect) {
  16051. PointClasses += ' no-pointer-events';
  16052. }
  16053. var elPointOptions = marker.getMarkerConfig({
  16054. cssClass: PointClasses,
  16055. seriesIndex: Number(pointsMain.getAttribute('data:realIndex')) // fixes apexcharts/apexcharts.js #1427
  16056. });
  16057. point = graphics.drawMarker(0, 0, elPointOptions);
  16058. point.node.setAttribute('default-marker-size', 0);
  16059. var elPointsG = document.createElementNS(w.globals.SVGNS, 'g');
  16060. elPointsG.classList.add('apexcharts-series-markers');
  16061. elPointsG.appendChild(point.node);
  16062. pointsMain.appendChild(elPointsG);
  16063. }
  16064. }
  16065. }
  16066. }, {
  16067. key: "enlargeCurrentPoint",
  16068. value: function enlargeCurrentPoint(rel, point) {
  16069. var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  16070. var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  16071. var w = this.w;
  16072. if (w.config.chart.type !== 'bubble') {
  16073. this.newPointSize(rel, point);
  16074. }
  16075. var cx = point.getAttribute('cx');
  16076. var cy = point.getAttribute('cy');
  16077. if (x !== null && y !== null) {
  16078. cx = x;
  16079. cy = y;
  16080. }
  16081. this.tooltipPosition.moveXCrosshairs(cx);
  16082. if (!this.fixedTooltip) {
  16083. if (w.config.chart.type === 'radar') {
  16084. var elGrid = this.ttCtx.getElGrid();
  16085. var seriesBound = elGrid.getBoundingClientRect();
  16086. cx = this.ttCtx.e.clientX - seriesBound.left;
  16087. }
  16088. this.tooltipPosition.moveTooltip(cx, cy, w.config.markers.hover.size);
  16089. }
  16090. }
  16091. }, {
  16092. key: "enlargePoints",
  16093. value: function enlargePoints(j) {
  16094. var w = this.w;
  16095. var me = this;
  16096. var ttCtx = this.ttCtx;
  16097. var col = j;
  16098. var points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series:not(.apexcharts-series-collapsed) .apexcharts-marker');
  16099. var newSize = w.config.markers.hover.size;
  16100. for (var p = 0; p < points.length; p++) {
  16101. var rel = points[p].getAttribute('rel');
  16102. var index = points[p].getAttribute('index');
  16103. if (newSize === undefined) {
  16104. newSize = w.globals.markers.size[index] + w.config.markers.hover.sizeOffset;
  16105. }
  16106. if (col === parseInt(rel, 10)) {
  16107. me.newPointSize(col, points[p]);
  16108. var cx = points[p].getAttribute('cx');
  16109. var cy = points[p].getAttribute('cy');
  16110. me.tooltipPosition.moveXCrosshairs(cx);
  16111. if (!ttCtx.fixedTooltip) {
  16112. me.tooltipPosition.moveTooltip(cx, cy, newSize);
  16113. }
  16114. } else {
  16115. me.oldPointSize(points[p]);
  16116. }
  16117. }
  16118. }
  16119. }, {
  16120. key: "newPointSize",
  16121. value: function newPointSize(rel, point) {
  16122. var w = this.w;
  16123. var newSize = w.config.markers.hover.size;
  16124. var elPoint = rel === 0 ? point.parentNode.firstChild : point.parentNode.lastChild;
  16125. if (elPoint.getAttribute('default-marker-size') !== '0') {
  16126. var index = parseInt(elPoint.getAttribute('index'), 10);
  16127. if (newSize === undefined) {
  16128. newSize = w.globals.markers.size[index] + w.config.markers.hover.sizeOffset;
  16129. }
  16130. if (newSize < 0) {
  16131. newSize = 0;
  16132. }
  16133. var path = this.ttCtx.tooltipUtil.getPathFromPoint(point, newSize);
  16134. point.setAttribute('d', path);
  16135. }
  16136. }
  16137. }, {
  16138. key: "oldPointSize",
  16139. value: function oldPointSize(point) {
  16140. var size = parseFloat(point.getAttribute('default-marker-size'));
  16141. var path = this.ttCtx.tooltipUtil.getPathFromPoint(point, size);
  16142. point.setAttribute('d', path);
  16143. }
  16144. }, {
  16145. key: "resetPointsSize",
  16146. value: function resetPointsSize() {
  16147. var w = this.w;
  16148. var points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series:not(.apexcharts-series-collapsed) .apexcharts-marker');
  16149. for (var p = 0; p < points.length; p++) {
  16150. var size = parseFloat(points[p].getAttribute('default-marker-size'));
  16151. if (Utils$1.isNumber(size) && size >= 0) {
  16152. var path = this.ttCtx.tooltipUtil.getPathFromPoint(points[p], size);
  16153. points[p].setAttribute('d', path);
  16154. } else {
  16155. points[p].setAttribute('d', 'M0,0');
  16156. }
  16157. }
  16158. }
  16159. }]);
  16160. return Marker;
  16161. }();
  16162. /**
  16163. * ApexCharts Tooltip.Intersect Class.
  16164. * This file deals with functions related to intersecting tooltips
  16165. * (tooltips that appear when user hovers directly over a data-point whether)
  16166. *
  16167. * @module Tooltip.Intersect
  16168. **/
  16169. var Intersect = /*#__PURE__*/function () {
  16170. function Intersect(tooltipContext) {
  16171. _classCallCheck(this, Intersect);
  16172. this.w = tooltipContext.w;
  16173. var w = this.w;
  16174. this.ttCtx = tooltipContext;
  16175. this.isVerticalGroupedRangeBar = !w.globals.isBarHorizontal && w.config.chart.type === 'rangeBar' && w.config.plotOptions.bar.rangeBarGroupRows;
  16176. }
  16177. // a helper function to get an element's attribute value
  16178. _createClass(Intersect, [{
  16179. key: "getAttr",
  16180. value: function getAttr(e, attr) {
  16181. return parseFloat(e.target.getAttribute(attr));
  16182. }
  16183. // handle tooltip for heatmaps and treemaps
  16184. }, {
  16185. key: "handleHeatTreeTooltip",
  16186. value: function handleHeatTreeTooltip(_ref) {
  16187. var e = _ref.e,
  16188. opt = _ref.opt,
  16189. x = _ref.x,
  16190. y = _ref.y,
  16191. type = _ref.type;
  16192. var ttCtx = this.ttCtx;
  16193. var w = this.w;
  16194. if (e.target.classList.contains("apexcharts-".concat(type, "-rect"))) {
  16195. var i = this.getAttr(e, 'i');
  16196. var j = this.getAttr(e, 'j');
  16197. var cx = this.getAttr(e, 'cx');
  16198. var cy = this.getAttr(e, 'cy');
  16199. var width = this.getAttr(e, 'width');
  16200. var height = this.getAttr(e, 'height');
  16201. ttCtx.tooltipLabels.drawSeriesTexts({
  16202. ttItems: opt.ttItems,
  16203. i: i,
  16204. j: j,
  16205. shared: false,
  16206. e: e
  16207. });
  16208. w.globals.capturedSeriesIndex = i;
  16209. w.globals.capturedDataPointIndex = j;
  16210. x = cx + ttCtx.tooltipRect.ttWidth / 2 + width;
  16211. y = cy + ttCtx.tooltipRect.ttHeight / 2 - height / 2;
  16212. ttCtx.tooltipPosition.moveXCrosshairs(cx + width / 2);
  16213. if (x > w.globals.gridWidth / 2) {
  16214. x = cx - ttCtx.tooltipRect.ttWidth / 2 + width;
  16215. }
  16216. if (ttCtx.w.config.tooltip.followCursor) {
  16217. var seriesBound = w.globals.dom.elWrap.getBoundingClientRect();
  16218. x = w.globals.clientX - seriesBound.left - (x > w.globals.gridWidth / 2 ? ttCtx.tooltipRect.ttWidth : 0);
  16219. y = w.globals.clientY - seriesBound.top - (y > w.globals.gridHeight / 2 ? ttCtx.tooltipRect.ttHeight : 0);
  16220. }
  16221. }
  16222. return {
  16223. x: x,
  16224. y: y
  16225. };
  16226. }
  16227. /**
  16228. * handle tooltips for line/area/scatter charts where tooltip.intersect is true
  16229. * when user hovers over the marker directly, this function is executed
  16230. */
  16231. }, {
  16232. key: "handleMarkerTooltip",
  16233. value: function handleMarkerTooltip(_ref2) {
  16234. var e = _ref2.e,
  16235. opt = _ref2.opt,
  16236. x = _ref2.x,
  16237. y = _ref2.y;
  16238. var w = this.w;
  16239. var ttCtx = this.ttCtx;
  16240. var i;
  16241. var j;
  16242. if (e.target.classList.contains('apexcharts-marker')) {
  16243. var cx = parseInt(opt.paths.getAttribute('cx'), 10);
  16244. var cy = parseInt(opt.paths.getAttribute('cy'), 10);
  16245. var val = parseFloat(opt.paths.getAttribute('val'));
  16246. j = parseInt(opt.paths.getAttribute('rel'), 10);
  16247. i = parseInt(opt.paths.parentNode.parentNode.parentNode.getAttribute('rel'), 10) - 1;
  16248. if (ttCtx.intersect) {
  16249. var el = Utils$1.findAncestor(opt.paths, 'apexcharts-series');
  16250. if (el) {
  16251. i = parseInt(el.getAttribute('data:realIndex'), 10);
  16252. }
  16253. }
  16254. ttCtx.tooltipLabels.drawSeriesTexts({
  16255. ttItems: opt.ttItems,
  16256. i: i,
  16257. j: j,
  16258. shared: ttCtx.showOnIntersect ? false : w.config.tooltip.shared,
  16259. e: e
  16260. });
  16261. if (e.type === 'mouseup') {
  16262. ttCtx.markerClick(e, i, j);
  16263. }
  16264. w.globals.capturedSeriesIndex = i;
  16265. w.globals.capturedDataPointIndex = j;
  16266. x = cx;
  16267. y = cy + w.globals.translateY - ttCtx.tooltipRect.ttHeight * 1.4;
  16268. if (ttCtx.w.config.tooltip.followCursor) {
  16269. var elGrid = ttCtx.getElGrid();
  16270. var seriesBound = elGrid.getBoundingClientRect();
  16271. y = ttCtx.e.clientY + w.globals.translateY - seriesBound.top;
  16272. }
  16273. if (val < 0) {
  16274. y = cy;
  16275. }
  16276. ttCtx.marker.enlargeCurrentPoint(j, opt.paths, x, y);
  16277. }
  16278. return {
  16279. x: x,
  16280. y: y
  16281. };
  16282. }
  16283. /**
  16284. * handle tooltips for bar/column charts
  16285. */
  16286. }, {
  16287. key: "handleBarTooltip",
  16288. value: function handleBarTooltip(_ref3) {
  16289. var e = _ref3.e,
  16290. opt = _ref3.opt;
  16291. var w = this.w;
  16292. var ttCtx = this.ttCtx;
  16293. var tooltipEl = ttCtx.getElTooltip();
  16294. var bx = 0;
  16295. var x = 0;
  16296. var y = 0;
  16297. var i = 0;
  16298. var strokeWidth;
  16299. var barXY = this.getBarTooltipXY({
  16300. e: e,
  16301. opt: opt
  16302. });
  16303. i = barXY.i;
  16304. var j = barXY.j;
  16305. w.globals.capturedSeriesIndex = i;
  16306. w.globals.capturedDataPointIndex = j;
  16307. if (w.globals.isBarHorizontal && ttCtx.tooltipUtil.hasBars() || !w.config.tooltip.shared) {
  16308. x = barXY.x;
  16309. y = barXY.y;
  16310. strokeWidth = Array.isArray(w.config.stroke.width) ? w.config.stroke.width[i] : w.config.stroke.width;
  16311. bx = x;
  16312. } else {
  16313. if (!w.globals.comboCharts && !w.config.tooltip.shared) {
  16314. // todo: re-check this condition as it's always 0
  16315. bx = bx / 2;
  16316. }
  16317. }
  16318. // y is NaN, make it touch the bottom of grid area
  16319. if (isNaN(y)) {
  16320. y = w.globals.svgHeight - ttCtx.tooltipRect.ttHeight;
  16321. }
  16322. var seriesIndex = parseInt(opt.paths.parentNode.getAttribute('data:realIndex'), 10);
  16323. w.globals.isMultipleYAxis ? w.config.yaxis[seriesIndex] && w.config.yaxis[seriesIndex].reversed : w.config.yaxis[0].reversed;
  16324. if (x + ttCtx.tooltipRect.ttWidth > w.globals.gridWidth) {
  16325. x = x - ttCtx.tooltipRect.ttWidth;
  16326. } else if (x < 0) {
  16327. x = 0;
  16328. }
  16329. if (ttCtx.w.config.tooltip.followCursor) {
  16330. var elGrid = ttCtx.getElGrid();
  16331. var seriesBound = elGrid.getBoundingClientRect();
  16332. y = ttCtx.e.clientY - seriesBound.top;
  16333. }
  16334. // if tooltip is still null, querySelector
  16335. if (ttCtx.tooltip === null) {
  16336. ttCtx.tooltip = w.globals.dom.baseEl.querySelector('.apexcharts-tooltip');
  16337. }
  16338. if (!w.config.tooltip.shared) {
  16339. if (w.globals.comboBarCount > 0) {
  16340. ttCtx.tooltipPosition.moveXCrosshairs(bx + strokeWidth / 2);
  16341. } else {
  16342. ttCtx.tooltipPosition.moveXCrosshairs(bx);
  16343. }
  16344. }
  16345. // move tooltip here
  16346. if (!ttCtx.fixedTooltip && (!w.config.tooltip.shared || w.globals.isBarHorizontal && ttCtx.tooltipUtil.hasBars())) {
  16347. y = y + w.globals.translateY - ttCtx.tooltipRect.ttHeight / 2;
  16348. tooltipEl.style.left = x + w.globals.translateX + 'px';
  16349. tooltipEl.style.top = y + 'px';
  16350. }
  16351. }
  16352. }, {
  16353. key: "getBarTooltipXY",
  16354. value: function getBarTooltipXY(_ref4) {
  16355. var _this = this;
  16356. var e = _ref4.e,
  16357. opt = _ref4.opt;
  16358. var w = this.w;
  16359. var j = null;
  16360. var ttCtx = this.ttCtx;
  16361. var i = 0;
  16362. var x = 0;
  16363. var y = 0;
  16364. var barWidth = 0;
  16365. var barHeight = 0;
  16366. var cl = e.target.classList;
  16367. if (cl.contains('apexcharts-bar-area') || cl.contains('apexcharts-candlestick-area') || cl.contains('apexcharts-boxPlot-area') || cl.contains('apexcharts-rangebar-area')) {
  16368. var bar = e.target;
  16369. var barRect = bar.getBoundingClientRect();
  16370. var seriesBound = opt.elGrid.getBoundingClientRect();
  16371. var bh = barRect.height;
  16372. barHeight = barRect.height;
  16373. var bw = barRect.width;
  16374. var cx = parseInt(bar.getAttribute('cx'), 10);
  16375. var cy = parseInt(bar.getAttribute('cy'), 10);
  16376. barWidth = parseFloat(bar.getAttribute('barWidth'));
  16377. var clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
  16378. j = parseInt(bar.getAttribute('j'), 10);
  16379. i = parseInt(bar.parentNode.getAttribute('rel'), 10) - 1;
  16380. var y1 = bar.getAttribute('data-range-y1');
  16381. var y2 = bar.getAttribute('data-range-y2');
  16382. if (w.globals.comboCharts) {
  16383. i = parseInt(bar.parentNode.getAttribute('data:realIndex'), 10);
  16384. }
  16385. var handleXForColumns = function handleXForColumns(x) {
  16386. if (w.globals.isXNumeric) {
  16387. x = cx - bw / 2;
  16388. } else {
  16389. if (_this.isVerticalGroupedRangeBar) {
  16390. x = cx + bw / 2;
  16391. } else {
  16392. x = cx - ttCtx.dataPointsDividedWidth + bw / 2;
  16393. }
  16394. }
  16395. return x;
  16396. };
  16397. var handleYForBars = function handleYForBars() {
  16398. return cy - ttCtx.dataPointsDividedHeight + bh / 2 - ttCtx.tooltipRect.ttHeight / 2;
  16399. };
  16400. ttCtx.tooltipLabels.drawSeriesTexts({
  16401. ttItems: opt.ttItems,
  16402. i: i,
  16403. j: j,
  16404. y1: y1 ? parseInt(y1, 10) : null,
  16405. y2: y2 ? parseInt(y2, 10) : null,
  16406. shared: ttCtx.showOnIntersect ? false : w.config.tooltip.shared,
  16407. e: e
  16408. });
  16409. if (w.config.tooltip.followCursor) {
  16410. if (w.globals.isBarHorizontal) {
  16411. x = clientX - seriesBound.left + 15;
  16412. y = handleYForBars();
  16413. } else {
  16414. x = handleXForColumns(x);
  16415. y = e.clientY - seriesBound.top - ttCtx.tooltipRect.ttHeight / 2 - 15;
  16416. }
  16417. } else {
  16418. if (w.globals.isBarHorizontal) {
  16419. x = cx;
  16420. if (x < ttCtx.xyRatios.baseLineInvertedY) {
  16421. x = cx - ttCtx.tooltipRect.ttWidth;
  16422. }
  16423. y = handleYForBars();
  16424. } else {
  16425. x = handleXForColumns(x);
  16426. y = cy; // - ttCtx.tooltipRect.ttHeight / 2 + 10
  16427. }
  16428. }
  16429. }
  16430. return {
  16431. x: x,
  16432. y: y,
  16433. barHeight: barHeight,
  16434. barWidth: barWidth,
  16435. i: i,
  16436. j: j
  16437. };
  16438. }
  16439. }]);
  16440. return Intersect;
  16441. }();
  16442. /**
  16443. * ApexCharts Tooltip.AxesTooltip Class.
  16444. * This file deals with the x-axis and y-axis tooltips.
  16445. *
  16446. * @module Tooltip.AxesTooltip
  16447. **/
  16448. var AxesTooltip = /*#__PURE__*/function () {
  16449. function AxesTooltip(tooltipContext) {
  16450. _classCallCheck(this, AxesTooltip);
  16451. this.w = tooltipContext.w;
  16452. this.ttCtx = tooltipContext;
  16453. }
  16454. /**
  16455. * This method adds the secondary tooltip which appears below x axis
  16456. * @memberof Tooltip
  16457. **/
  16458. _createClass(AxesTooltip, [{
  16459. key: "drawXaxisTooltip",
  16460. value: function drawXaxisTooltip() {
  16461. var w = this.w;
  16462. var ttCtx = this.ttCtx;
  16463. var isBottom = w.config.xaxis.position === 'bottom';
  16464. ttCtx.xaxisOffY = isBottom ? w.globals.gridHeight + 1 : -w.globals.xAxisHeight - w.config.xaxis.axisTicks.height + 3;
  16465. var tooltipCssClass = isBottom ? 'apexcharts-xaxistooltip apexcharts-xaxistooltip-bottom' : 'apexcharts-xaxistooltip apexcharts-xaxistooltip-top';
  16466. var renderTo = w.globals.dom.elWrap;
  16467. if (ttCtx.isXAxisTooltipEnabled) {
  16468. var xaxisTooltip = w.globals.dom.baseEl.querySelector('.apexcharts-xaxistooltip');
  16469. if (xaxisTooltip === null) {
  16470. ttCtx.xaxisTooltip = document.createElement('div');
  16471. ttCtx.xaxisTooltip.setAttribute('class', tooltipCssClass + ' apexcharts-theme-' + w.config.tooltip.theme);
  16472. renderTo.appendChild(ttCtx.xaxisTooltip);
  16473. ttCtx.xaxisTooltipText = document.createElement('div');
  16474. ttCtx.xaxisTooltipText.classList.add('apexcharts-xaxistooltip-text');
  16475. ttCtx.xaxisTooltipText.style.fontFamily = w.config.xaxis.tooltip.style.fontFamily || w.config.chart.fontFamily;
  16476. ttCtx.xaxisTooltipText.style.fontSize = w.config.xaxis.tooltip.style.fontSize;
  16477. ttCtx.xaxisTooltip.appendChild(ttCtx.xaxisTooltipText);
  16478. }
  16479. }
  16480. }
  16481. /**
  16482. * This method adds the secondary tooltip which appears below x axis
  16483. * @memberof Tooltip
  16484. **/
  16485. }, {
  16486. key: "drawYaxisTooltip",
  16487. value: function drawYaxisTooltip() {
  16488. var w = this.w;
  16489. var ttCtx = this.ttCtx;
  16490. for (var i = 0; i < w.config.yaxis.length; i++) {
  16491. var isRight = w.config.yaxis[i].opposite || w.config.yaxis[i].crosshairs.opposite;
  16492. ttCtx.yaxisOffX = isRight ? w.globals.gridWidth + 1 : 1;
  16493. var tooltipCssClass = isRight ? "apexcharts-yaxistooltip apexcharts-yaxistooltip-".concat(i, " apexcharts-yaxistooltip-right") : "apexcharts-yaxistooltip apexcharts-yaxistooltip-".concat(i, " apexcharts-yaxistooltip-left");
  16494. var renderTo = w.globals.dom.elWrap;
  16495. var yaxisTooltip = w.globals.dom.baseEl.querySelector(".apexcharts-yaxistooltip apexcharts-yaxistooltip-".concat(i));
  16496. if (yaxisTooltip === null) {
  16497. ttCtx.yaxisTooltip = document.createElement('div');
  16498. ttCtx.yaxisTooltip.setAttribute('class', tooltipCssClass + ' apexcharts-theme-' + w.config.tooltip.theme);
  16499. renderTo.appendChild(ttCtx.yaxisTooltip);
  16500. if (i === 0) ttCtx.yaxisTooltipText = [];
  16501. ttCtx.yaxisTooltipText[i] = document.createElement('div');
  16502. ttCtx.yaxisTooltipText[i].classList.add('apexcharts-yaxistooltip-text');
  16503. ttCtx.yaxisTooltip.appendChild(ttCtx.yaxisTooltipText[i]);
  16504. }
  16505. }
  16506. }
  16507. /**
  16508. * @memberof Tooltip
  16509. **/
  16510. }, {
  16511. key: "setXCrosshairWidth",
  16512. value: function setXCrosshairWidth() {
  16513. var w = this.w;
  16514. var ttCtx = this.ttCtx;
  16515. // set xcrosshairs width
  16516. var xcrosshairs = ttCtx.getElXCrosshairs();
  16517. ttCtx.xcrosshairsWidth = parseInt(w.config.xaxis.crosshairs.width, 10);
  16518. if (!w.globals.comboCharts) {
  16519. if (w.config.xaxis.crosshairs.width === 'tickWidth') {
  16520. var count = w.globals.labels.length;
  16521. ttCtx.xcrosshairsWidth = w.globals.gridWidth / count;
  16522. } else if (w.config.xaxis.crosshairs.width === 'barWidth') {
  16523. var bar = w.globals.dom.baseEl.querySelector('.apexcharts-bar-area');
  16524. if (bar !== null) {
  16525. var barWidth = parseFloat(bar.getAttribute('barWidth'));
  16526. ttCtx.xcrosshairsWidth = barWidth;
  16527. } else {
  16528. ttCtx.xcrosshairsWidth = 1;
  16529. }
  16530. }
  16531. } else {
  16532. var _bar = w.globals.dom.baseEl.querySelector('.apexcharts-bar-area');
  16533. if (_bar !== null && w.config.xaxis.crosshairs.width === 'barWidth') {
  16534. var _barWidth = parseFloat(_bar.getAttribute('barWidth'));
  16535. ttCtx.xcrosshairsWidth = _barWidth;
  16536. } else {
  16537. if (w.config.xaxis.crosshairs.width === 'tickWidth') {
  16538. var _count = w.globals.labels.length;
  16539. ttCtx.xcrosshairsWidth = w.globals.gridWidth / _count;
  16540. }
  16541. }
  16542. }
  16543. if (w.globals.isBarHorizontal) {
  16544. ttCtx.xcrosshairsWidth = 0;
  16545. }
  16546. if (xcrosshairs !== null && ttCtx.xcrosshairsWidth > 0) {
  16547. xcrosshairs.setAttribute('width', ttCtx.xcrosshairsWidth);
  16548. }
  16549. }
  16550. }, {
  16551. key: "handleYCrosshair",
  16552. value: function handleYCrosshair() {
  16553. var w = this.w;
  16554. var ttCtx = this.ttCtx;
  16555. // set ycrosshairs height
  16556. ttCtx.ycrosshairs = w.globals.dom.baseEl.querySelector('.apexcharts-ycrosshairs');
  16557. ttCtx.ycrosshairsHidden = w.globals.dom.baseEl.querySelector('.apexcharts-ycrosshairs-hidden');
  16558. }
  16559. }, {
  16560. key: "drawYaxisTooltipText",
  16561. value: function drawYaxisTooltipText(index, clientY, xyRatios) {
  16562. var ttCtx = this.ttCtx;
  16563. var w = this.w;
  16564. var gl = w.globals;
  16565. var yAxisSeriesArr = gl.seriesYAxisMap[index];
  16566. if (ttCtx.yaxisTooltips[index] && yAxisSeriesArr.length > 0) {
  16567. var lbFormatter = gl.yLabelFormatters[index];
  16568. var elGrid = ttCtx.getElGrid();
  16569. var seriesBound = elGrid.getBoundingClientRect();
  16570. // We can use the index of any series referenced by the Yaxis
  16571. // because they will all return the same value.
  16572. var seriesIndex = yAxisSeriesArr[0];
  16573. var translationsIndex = 0;
  16574. if (xyRatios.yRatio.length > 1) {
  16575. translationsIndex = seriesIndex;
  16576. }
  16577. var hoverY = (clientY - seriesBound.top) * xyRatios.yRatio[translationsIndex];
  16578. var height = gl.maxYArr[seriesIndex] - gl.minYArr[seriesIndex];
  16579. var val = gl.minYArr[seriesIndex] + (height - hoverY);
  16580. if (w.config.yaxis[index].reversed) {
  16581. val = gl.maxYArr[seriesIndex] - (height - hoverY);
  16582. }
  16583. ttCtx.tooltipPosition.moveYCrosshairs(clientY - seriesBound.top);
  16584. ttCtx.yaxisTooltipText[index].innerHTML = lbFormatter(val);
  16585. ttCtx.tooltipPosition.moveYAxisTooltip(index);
  16586. }
  16587. }
  16588. }]);
  16589. return AxesTooltip;
  16590. }();
  16591. /**
  16592. * ApexCharts Core Tooltip Class to handle the tooltip generation.
  16593. *
  16594. * @module Tooltip
  16595. **/
  16596. var Tooltip = /*#__PURE__*/function () {
  16597. function Tooltip(ctx) {
  16598. _classCallCheck(this, Tooltip);
  16599. this.ctx = ctx;
  16600. this.w = ctx.w;
  16601. var w = this.w;
  16602. this.tConfig = w.config.tooltip;
  16603. this.tooltipUtil = new Utils(this);
  16604. this.tooltipLabels = new Labels(this);
  16605. this.tooltipPosition = new Position(this);
  16606. this.marker = new Marker(this);
  16607. this.intersect = new Intersect(this);
  16608. this.axesTooltip = new AxesTooltip(this);
  16609. this.showOnIntersect = this.tConfig.intersect;
  16610. this.showTooltipTitle = this.tConfig.x.show;
  16611. this.fixedTooltip = this.tConfig.fixed.enabled;
  16612. this.xaxisTooltip = null;
  16613. this.yaxisTTEls = null;
  16614. this.isBarShared = !w.globals.isBarHorizontal && this.tConfig.shared;
  16615. this.lastHoverTime = Date.now();
  16616. }
  16617. _createClass(Tooltip, [{
  16618. key: "getElTooltip",
  16619. value: function getElTooltip(ctx) {
  16620. if (!ctx) ctx = this;
  16621. if (!ctx.w.globals.dom.baseEl) return null;
  16622. return ctx.w.globals.dom.baseEl.querySelector('.apexcharts-tooltip');
  16623. }
  16624. }, {
  16625. key: "getElXCrosshairs",
  16626. value: function getElXCrosshairs() {
  16627. return this.w.globals.dom.baseEl.querySelector('.apexcharts-xcrosshairs');
  16628. }
  16629. }, {
  16630. key: "getElGrid",
  16631. value: function getElGrid() {
  16632. return this.w.globals.dom.baseEl.querySelector('.apexcharts-grid');
  16633. }
  16634. }, {
  16635. key: "drawTooltip",
  16636. value: function drawTooltip(xyRatios) {
  16637. var w = this.w;
  16638. this.xyRatios = xyRatios;
  16639. this.isXAxisTooltipEnabled = w.config.xaxis.tooltip.enabled && w.globals.axisCharts;
  16640. this.yaxisTooltips = w.config.yaxis.map(function (y, i) {
  16641. return y.show && y.tooltip.enabled && w.globals.axisCharts ? true : false;
  16642. });
  16643. this.allTooltipSeriesGroups = [];
  16644. if (!w.globals.axisCharts) {
  16645. this.showTooltipTitle = false;
  16646. }
  16647. var tooltipEl = document.createElement('div');
  16648. tooltipEl.classList.add('apexcharts-tooltip');
  16649. if (w.config.tooltip.cssClass) {
  16650. tooltipEl.classList.add(w.config.tooltip.cssClass);
  16651. }
  16652. tooltipEl.classList.add("apexcharts-theme-".concat(this.tConfig.theme));
  16653. w.globals.dom.elWrap.appendChild(tooltipEl);
  16654. if (w.globals.axisCharts) {
  16655. this.axesTooltip.drawXaxisTooltip();
  16656. this.axesTooltip.drawYaxisTooltip();
  16657. this.axesTooltip.setXCrosshairWidth();
  16658. this.axesTooltip.handleYCrosshair();
  16659. var xAxis = new XAxis(this.ctx);
  16660. this.xAxisTicksPositions = xAxis.getXAxisTicksPositions();
  16661. }
  16662. // we forcefully set intersect true for these conditions
  16663. if ((w.globals.comboCharts || this.tConfig.intersect || w.config.chart.type === 'rangeBar') && !this.tConfig.shared) {
  16664. this.showOnIntersect = true;
  16665. }
  16666. if (w.config.markers.size === 0 || w.globals.markers.largestSize === 0) {
  16667. // when user don't want to show points all the time, but only on when hovering on series
  16668. this.marker.drawDynamicPoints(this);
  16669. }
  16670. // no visible series, exit
  16671. if (w.globals.collapsedSeries.length === w.globals.series.length) return;
  16672. this.dataPointsDividedHeight = w.globals.gridHeight / w.globals.dataPoints;
  16673. this.dataPointsDividedWidth = w.globals.gridWidth / w.globals.dataPoints;
  16674. if (this.showTooltipTitle) {
  16675. this.tooltipTitle = document.createElement('div');
  16676. this.tooltipTitle.classList.add('apexcharts-tooltip-title');
  16677. this.tooltipTitle.style.fontFamily = this.tConfig.style.fontFamily || w.config.chart.fontFamily;
  16678. this.tooltipTitle.style.fontSize = this.tConfig.style.fontSize;
  16679. tooltipEl.appendChild(this.tooltipTitle);
  16680. }
  16681. var ttItemsCnt = w.globals.series.length; // whether shared or not, default is shared
  16682. if ((w.globals.xyCharts || w.globals.comboCharts) && this.tConfig.shared) {
  16683. if (!this.showOnIntersect) {
  16684. ttItemsCnt = w.globals.series.length;
  16685. } else {
  16686. ttItemsCnt = 1;
  16687. }
  16688. }
  16689. this.legendLabels = w.globals.dom.baseEl.querySelectorAll('.apexcharts-legend-text');
  16690. this.ttItems = this.createTTElements(ttItemsCnt);
  16691. this.addSVGEvents();
  16692. }
  16693. }, {
  16694. key: "createTTElements",
  16695. value: function createTTElements(ttItemsCnt) {
  16696. var _this = this;
  16697. var w = this.w;
  16698. var ttItems = [];
  16699. var tooltipEl = this.getElTooltip();
  16700. var _loop = function _loop(i) {
  16701. var gTxt = document.createElement('div');
  16702. gTxt.classList.add('apexcharts-tooltip-series-group', "apexcharts-tooltip-series-group-".concat(i));
  16703. gTxt.style.order = w.config.tooltip.inverseOrder ? ttItemsCnt - i : i + 1;
  16704. var point = document.createElement('span');
  16705. point.classList.add('apexcharts-tooltip-marker');
  16706. point.style.backgroundColor = w.globals.colors[i];
  16707. gTxt.appendChild(point);
  16708. var gYZ = document.createElement('div');
  16709. gYZ.classList.add('apexcharts-tooltip-text');
  16710. gYZ.style.fontFamily = _this.tConfig.style.fontFamily || w.config.chart.fontFamily;
  16711. gYZ.style.fontSize = _this.tConfig.style.fontSize;
  16712. ['y', 'goals', 'z'].forEach(function (g) {
  16713. var gValText = document.createElement('div');
  16714. gValText.classList.add("apexcharts-tooltip-".concat(g, "-group"));
  16715. var txtLabel = document.createElement('span');
  16716. txtLabel.classList.add("apexcharts-tooltip-text-".concat(g, "-label"));
  16717. gValText.appendChild(txtLabel);
  16718. var txtValue = document.createElement('span');
  16719. txtValue.classList.add("apexcharts-tooltip-text-".concat(g, "-value"));
  16720. gValText.appendChild(txtValue);
  16721. gYZ.appendChild(gValText);
  16722. });
  16723. gTxt.appendChild(gYZ);
  16724. tooltipEl.appendChild(gTxt);
  16725. ttItems.push(gTxt);
  16726. };
  16727. for (var i = 0; i < ttItemsCnt; i++) {
  16728. _loop(i);
  16729. }
  16730. return ttItems;
  16731. }
  16732. }, {
  16733. key: "addSVGEvents",
  16734. value: function addSVGEvents() {
  16735. var w = this.w;
  16736. var type = w.config.chart.type;
  16737. var tooltipEl = this.getElTooltip();
  16738. var commonBar = !!(type === 'bar' || type === 'candlestick' || type === 'boxPlot' || type === 'rangeBar');
  16739. var chartWithmarkers = type === 'area' || type === 'line' || type === 'scatter' || type === 'bubble' || type === 'radar';
  16740. var hoverArea = w.globals.dom.Paper.node;
  16741. var elGrid = this.getElGrid();
  16742. if (elGrid) {
  16743. this.seriesBound = elGrid.getBoundingClientRect();
  16744. }
  16745. var tooltipY = [];
  16746. var tooltipX = [];
  16747. var seriesHoverParams = {
  16748. hoverArea: hoverArea,
  16749. elGrid: elGrid,
  16750. tooltipEl: tooltipEl,
  16751. tooltipY: tooltipY,
  16752. tooltipX: tooltipX,
  16753. ttItems: this.ttItems
  16754. };
  16755. var points;
  16756. if (w.globals.axisCharts) {
  16757. if (chartWithmarkers) {
  16758. points = w.globals.dom.baseEl.querySelectorAll(".apexcharts-series[data\\:longestSeries='true'] .apexcharts-marker");
  16759. } else if (commonBar) {
  16760. 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');
  16761. } else if (type === 'heatmap' || type === 'treemap') {
  16762. points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series .apexcharts-heatmap, .apexcharts-series .apexcharts-treemap');
  16763. }
  16764. if (points && points.length) {
  16765. for (var p = 0; p < points.length; p++) {
  16766. tooltipY.push(points[p].getAttribute('cy'));
  16767. tooltipX.push(points[p].getAttribute('cx'));
  16768. }
  16769. }
  16770. }
  16771. var validSharedChartTypes = w.globals.xyCharts && !this.showOnIntersect || w.globals.comboCharts && !this.showOnIntersect || commonBar && this.tooltipUtil.hasBars() && this.tConfig.shared;
  16772. if (validSharedChartTypes) {
  16773. this.addPathsEventListeners([hoverArea], seriesHoverParams);
  16774. } else if (commonBar && !w.globals.comboCharts || chartWithmarkers && this.showOnIntersect) {
  16775. this.addDatapointEventsListeners(seriesHoverParams);
  16776. } else if (!w.globals.axisCharts || type === 'heatmap' || type === 'treemap') {
  16777. var seriesAll = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series');
  16778. this.addPathsEventListeners(seriesAll, seriesHoverParams);
  16779. }
  16780. if (this.showOnIntersect) {
  16781. var lineAreaPoints = w.globals.dom.baseEl.querySelectorAll('.apexcharts-line-series .apexcharts-marker, .apexcharts-area-series .apexcharts-marker');
  16782. if (lineAreaPoints.length > 0) {
  16783. // if we find any lineSeries, addEventListeners for them
  16784. this.addPathsEventListeners(lineAreaPoints, seriesHoverParams);
  16785. }
  16786. // combo charts may have bars, so add event listeners here too
  16787. if (this.tooltipUtil.hasBars() && !this.tConfig.shared) {
  16788. this.addDatapointEventsListeners(seriesHoverParams);
  16789. }
  16790. }
  16791. }
  16792. }, {
  16793. key: "drawFixedTooltipRect",
  16794. value: function drawFixedTooltipRect() {
  16795. var w = this.w;
  16796. var tooltipEl = this.getElTooltip();
  16797. var tooltipRect = tooltipEl.getBoundingClientRect();
  16798. var ttWidth = tooltipRect.width + 10;
  16799. var ttHeight = tooltipRect.height + 10;
  16800. var x = this.tConfig.fixed.offsetX;
  16801. var y = this.tConfig.fixed.offsetY;
  16802. var fixed = this.tConfig.fixed.position.toLowerCase();
  16803. if (fixed.indexOf('right') > -1) {
  16804. x = x + w.globals.svgWidth - ttWidth + 10;
  16805. }
  16806. if (fixed.indexOf('bottom') > -1) {
  16807. y = y + w.globals.svgHeight - ttHeight - 10;
  16808. }
  16809. tooltipEl.style.left = x + 'px';
  16810. tooltipEl.style.top = y + 'px';
  16811. return {
  16812. x: x,
  16813. y: y,
  16814. ttWidth: ttWidth,
  16815. ttHeight: ttHeight
  16816. };
  16817. }
  16818. }, {
  16819. key: "addDatapointEventsListeners",
  16820. value: function addDatapointEventsListeners(seriesHoverParams) {
  16821. var w = this.w;
  16822. var points = w.globals.dom.baseEl.querySelectorAll('.apexcharts-series-markers .apexcharts-marker, .apexcharts-bar-area, .apexcharts-candlestick-area, .apexcharts-boxPlot-area, .apexcharts-rangebar-area');
  16823. this.addPathsEventListeners(points, seriesHoverParams);
  16824. }
  16825. }, {
  16826. key: "addPathsEventListeners",
  16827. value: function addPathsEventListeners(paths, opts) {
  16828. var self = this;
  16829. var _loop2 = function _loop2(p) {
  16830. var extendedOpts = {
  16831. paths: paths[p],
  16832. tooltipEl: opts.tooltipEl,
  16833. tooltipY: opts.tooltipY,
  16834. tooltipX: opts.tooltipX,
  16835. elGrid: opts.elGrid,
  16836. hoverArea: opts.hoverArea,
  16837. ttItems: opts.ttItems
  16838. };
  16839. var events = ['mousemove', 'mouseup', 'touchmove', 'mouseout', 'touchend'];
  16840. events.map(function (ev) {
  16841. return paths[p].addEventListener(ev, self.onSeriesHover.bind(self, extendedOpts), {
  16842. capture: false,
  16843. passive: true
  16844. });
  16845. });
  16846. };
  16847. for (var p = 0; p < paths.length; p++) {
  16848. _loop2(p);
  16849. }
  16850. }
  16851. /*
  16852. ** Check to see if the tooltips should be updated based on a mouse / touch event
  16853. */
  16854. }, {
  16855. key: "onSeriesHover",
  16856. value: function onSeriesHover(opt, e) {
  16857. var _this2 = this;
  16858. // If a user is moving their mouse quickly, don't bother updating the tooltip every single frame
  16859. var targetDelay = 100;
  16860. var timeSinceLastUpdate = Date.now() - this.lastHoverTime;
  16861. if (timeSinceLastUpdate >= targetDelay) {
  16862. // The tooltip was last updated over 100ms ago - redraw it even if the user is still moving their
  16863. // mouse so they get some feedback that their moves are being registered
  16864. this.seriesHover(opt, e);
  16865. } else {
  16866. // The tooltip was last updated less than 100ms ago
  16867. // Cancel any other delayed draw, so we don't show stale data
  16868. clearTimeout(this.seriesHoverTimeout);
  16869. // Schedule the next draw so that it happens about 100ms after the last update
  16870. this.seriesHoverTimeout = setTimeout(function () {
  16871. _this2.seriesHover(opt, e);
  16872. }, targetDelay - timeSinceLastUpdate);
  16873. }
  16874. }
  16875. /*
  16876. ** The actual series hover function
  16877. */
  16878. }, {
  16879. key: "seriesHover",
  16880. value: function seriesHover(opt, e) {
  16881. var _this3 = this;
  16882. this.lastHoverTime = Date.now();
  16883. var chartGroups = [];
  16884. var w = this.w;
  16885. // if user has more than one charts in group, we need to sync
  16886. if (w.config.chart.group) {
  16887. chartGroups = this.ctx.getGroupedCharts();
  16888. }
  16889. if (w.globals.axisCharts && (w.globals.minX === -Infinity && w.globals.maxX === Infinity || w.globals.dataPoints === 0)) {
  16890. return;
  16891. }
  16892. if (chartGroups.length) {
  16893. chartGroups.forEach(function (ch) {
  16894. var tooltipEl = _this3.getElTooltip(ch);
  16895. var newOpts = {
  16896. paths: opt.paths,
  16897. tooltipEl: tooltipEl,
  16898. tooltipY: opt.tooltipY,
  16899. tooltipX: opt.tooltipX,
  16900. elGrid: opt.elGrid,
  16901. hoverArea: opt.hoverArea,
  16902. ttItems: ch.w.globals.tooltip.ttItems
  16903. };
  16904. // all the charts should have the same minX and maxX (same xaxis) for multiple tooltips to work correctly
  16905. if (ch.w.globals.minX === _this3.w.globals.minX && ch.w.globals.maxX === _this3.w.globals.maxX) {
  16906. ch.w.globals.tooltip.seriesHoverByContext({
  16907. chartCtx: ch,
  16908. ttCtx: ch.w.globals.tooltip,
  16909. opt: newOpts,
  16910. e: e
  16911. });
  16912. }
  16913. });
  16914. } else {
  16915. this.seriesHoverByContext({
  16916. chartCtx: this.ctx,
  16917. ttCtx: this.w.globals.tooltip,
  16918. opt: opt,
  16919. e: e
  16920. });
  16921. }
  16922. }
  16923. }, {
  16924. key: "seriesHoverByContext",
  16925. value: function seriesHoverByContext(_ref) {
  16926. var chartCtx = _ref.chartCtx,
  16927. ttCtx = _ref.ttCtx,
  16928. opt = _ref.opt,
  16929. e = _ref.e;
  16930. var w = chartCtx.w;
  16931. var tooltipEl = this.getElTooltip(chartCtx);
  16932. if (!tooltipEl) return;
  16933. // tooltipRect is calculated on every mousemove, because the text is dynamic
  16934. ttCtx.tooltipRect = {
  16935. x: 0,
  16936. y: 0,
  16937. ttWidth: tooltipEl.getBoundingClientRect().width,
  16938. ttHeight: tooltipEl.getBoundingClientRect().height
  16939. };
  16940. ttCtx.e = e;
  16941. // highlight the current hovered bars
  16942. if (ttCtx.tooltipUtil.hasBars() && !w.globals.comboCharts && !ttCtx.isBarShared) {
  16943. if (this.tConfig.onDatasetHover.highlightDataSeries) {
  16944. var series = new Series(chartCtx);
  16945. series.toggleSeriesOnHover(e, e.target.parentNode);
  16946. }
  16947. }
  16948. if (ttCtx.fixedTooltip) {
  16949. ttCtx.drawFixedTooltipRect();
  16950. }
  16951. if (w.globals.axisCharts) {
  16952. ttCtx.axisChartsTooltips({
  16953. e: e,
  16954. opt: opt,
  16955. tooltipRect: ttCtx.tooltipRect
  16956. });
  16957. } else {
  16958. // non-plot charts i.e pie/donut/circle
  16959. ttCtx.nonAxisChartsTooltips({
  16960. e: e,
  16961. opt: opt,
  16962. tooltipRect: ttCtx.tooltipRect
  16963. });
  16964. }
  16965. }
  16966. // tooltip handling for line/area/bar/columns/scatter
  16967. }, {
  16968. key: "axisChartsTooltips",
  16969. value: function axisChartsTooltips(_ref2) {
  16970. var e = _ref2.e,
  16971. opt = _ref2.opt;
  16972. var w = this.w;
  16973. var x, y;
  16974. var seriesBound = opt.elGrid.getBoundingClientRect();
  16975. var clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
  16976. var clientY = e.type === 'touchmove' ? e.touches[0].clientY : e.clientY;
  16977. this.clientY = clientY;
  16978. this.clientX = clientX;
  16979. w.globals.capturedSeriesIndex = -1;
  16980. w.globals.capturedDataPointIndex = -1;
  16981. if (clientY < seriesBound.top || clientY > seriesBound.top + seriesBound.height) {
  16982. this.handleMouseOut(opt);
  16983. return;
  16984. }
  16985. if (Array.isArray(this.tConfig.enabledOnSeries) && !w.config.tooltip.shared) {
  16986. var index = parseInt(opt.paths.getAttribute('index'), 10);
  16987. if (this.tConfig.enabledOnSeries.indexOf(index) < 0) {
  16988. this.handleMouseOut(opt);
  16989. return;
  16990. }
  16991. }
  16992. var tooltipEl = this.getElTooltip();
  16993. var xcrosshairs = this.getElXCrosshairs();
  16994. var syncedCharts = [];
  16995. if (w.config.chart.group) {
  16996. // we need to fallback to sticky tooltip in case charts are synced
  16997. syncedCharts = this.ctx.getSyncedCharts();
  16998. }
  16999. 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();
  17000. if (e.type === 'mousemove' || e.type === 'touchmove' || e.type === 'mouseup') {
  17001. // there is no series to hover over
  17002. if (w.globals.collapsedSeries.length + w.globals.ancillaryCollapsedSeries.length === w.globals.series.length) {
  17003. return;
  17004. }
  17005. if (xcrosshairs !== null) {
  17006. xcrosshairs.classList.add('apexcharts-active');
  17007. }
  17008. var hasYAxisTooltip = this.yaxisTooltips.filter(function (b) {
  17009. return b === true;
  17010. });
  17011. if (this.ycrosshairs !== null && hasYAxisTooltip.length) {
  17012. this.ycrosshairs.classList.add('apexcharts-active');
  17013. }
  17014. if (isStickyTooltip && !this.showOnIntersect || syncedCharts.length > 1) {
  17015. this.handleStickyTooltip(e, clientX, clientY, opt);
  17016. } else {
  17017. if (w.config.chart.type === 'heatmap' || w.config.chart.type === 'treemap') {
  17018. var markerXY = this.intersect.handleHeatTreeTooltip({
  17019. e: e,
  17020. opt: opt,
  17021. x: x,
  17022. y: y,
  17023. type: w.config.chart.type
  17024. });
  17025. x = markerXY.x;
  17026. y = markerXY.y;
  17027. tooltipEl.style.left = x + 'px';
  17028. tooltipEl.style.top = y + 'px';
  17029. } else {
  17030. if (this.tooltipUtil.hasBars()) {
  17031. this.intersect.handleBarTooltip({
  17032. e: e,
  17033. opt: opt
  17034. });
  17035. }
  17036. if (this.tooltipUtil.hasMarkers()) {
  17037. // intersect - line/area/scatter/bubble
  17038. this.intersect.handleMarkerTooltip({
  17039. e: e,
  17040. opt: opt,
  17041. x: x,
  17042. y: y
  17043. });
  17044. }
  17045. }
  17046. }
  17047. if (this.yaxisTooltips.length) {
  17048. for (var yt = 0; yt < w.config.yaxis.length; yt++) {
  17049. this.axesTooltip.drawYaxisTooltipText(yt, clientY, this.xyRatios);
  17050. }
  17051. }
  17052. w.globals.dom.baseEl.classList.add('apexcharts-tooltip-active');
  17053. opt.tooltipEl.classList.add('apexcharts-active');
  17054. } else if (e.type === 'mouseout' || e.type === 'touchend') {
  17055. this.handleMouseOut(opt);
  17056. }
  17057. }
  17058. // tooltip handling for pie/donuts
  17059. }, {
  17060. key: "nonAxisChartsTooltips",
  17061. value: function nonAxisChartsTooltips(_ref3) {
  17062. var e = _ref3.e,
  17063. opt = _ref3.opt,
  17064. tooltipRect = _ref3.tooltipRect;
  17065. var w = this.w;
  17066. var rel = opt.paths.getAttribute('rel');
  17067. var tooltipEl = this.getElTooltip();
  17068. var seriesBound = w.globals.dom.elWrap.getBoundingClientRect();
  17069. if (e.type === 'mousemove' || e.type === 'touchmove') {
  17070. w.globals.dom.baseEl.classList.add('apexcharts-tooltip-active');
  17071. tooltipEl.classList.add('apexcharts-active');
  17072. this.tooltipLabels.drawSeriesTexts({
  17073. ttItems: opt.ttItems,
  17074. i: parseInt(rel, 10) - 1,
  17075. shared: false
  17076. });
  17077. var x = w.globals.clientX - seriesBound.left - tooltipRect.ttWidth / 2;
  17078. var y = w.globals.clientY - seriesBound.top - tooltipRect.ttHeight - 10;
  17079. tooltipEl.style.left = x + 'px';
  17080. tooltipEl.style.top = y + 'px';
  17081. if (w.config.legend.tooltipHoverFormatter) {
  17082. var legendFormatter = w.config.legend.tooltipHoverFormatter;
  17083. var i = rel - 1;
  17084. var legendName = this.legendLabels[i].getAttribute('data:default-text');
  17085. var text = legendFormatter(legendName, {
  17086. seriesIndex: i,
  17087. dataPointIndex: i,
  17088. w: w
  17089. });
  17090. this.legendLabels[i].innerHTML = text;
  17091. }
  17092. } else if (e.type === 'mouseout' || e.type === 'touchend') {
  17093. tooltipEl.classList.remove('apexcharts-active');
  17094. w.globals.dom.baseEl.classList.remove('apexcharts-tooltip-active');
  17095. if (w.config.legend.tooltipHoverFormatter) {
  17096. this.legendLabels.forEach(function (l) {
  17097. var defaultText = l.getAttribute('data:default-text');
  17098. l.innerHTML = decodeURIComponent(defaultText);
  17099. });
  17100. }
  17101. }
  17102. }
  17103. }, {
  17104. key: "handleStickyTooltip",
  17105. value: function handleStickyTooltip(e, clientX, clientY, opt) {
  17106. var w = this.w;
  17107. var capj = this.tooltipUtil.getNearestValues({
  17108. context: this,
  17109. hoverArea: opt.hoverArea,
  17110. elGrid: opt.elGrid,
  17111. clientX: clientX,
  17112. clientY: clientY
  17113. });
  17114. var j = capj.j;
  17115. var capturedSeries = capj.capturedSeries;
  17116. if (w.globals.collapsedSeriesIndices.includes(capturedSeries)) capturedSeries = null;
  17117. var bounds = opt.elGrid.getBoundingClientRect();
  17118. if (capj.hoverX < 0 || capj.hoverX > bounds.width) {
  17119. this.handleMouseOut(opt);
  17120. return;
  17121. }
  17122. if (capturedSeries !== null) {
  17123. this.handleStickyCapturedSeries(e, capturedSeries, opt, j);
  17124. } else {
  17125. // couldn't capture any series. check if shared X is same,
  17126. // if yes, draw a grouped tooltip
  17127. if (this.tooltipUtil.isXoverlap(j) || w.globals.isBarHorizontal) {
  17128. var firstVisibleSeries = w.globals.series.findIndex(function (s, i) {
  17129. return !w.globals.collapsedSeriesIndices.includes(i);
  17130. });
  17131. this.create(e, this, firstVisibleSeries, j, opt.ttItems);
  17132. }
  17133. }
  17134. }
  17135. }, {
  17136. key: "handleStickyCapturedSeries",
  17137. value: function handleStickyCapturedSeries(e, capturedSeries, opt, j) {
  17138. var w = this.w;
  17139. if (!this.tConfig.shared) {
  17140. var ignoreNull = w.globals.series[capturedSeries][j] === null;
  17141. if (ignoreNull) {
  17142. this.handleMouseOut(opt);
  17143. return;
  17144. }
  17145. }
  17146. if (typeof w.globals.series[capturedSeries][j] !== 'undefined') {
  17147. if (this.tConfig.shared && this.tooltipUtil.isXoverlap(j) && this.tooltipUtil.isInitialSeriesSameLen()) {
  17148. this.create(e, this, capturedSeries, j, opt.ttItems);
  17149. } else {
  17150. this.create(e, this, capturedSeries, j, opt.ttItems, false);
  17151. }
  17152. } else {
  17153. if (this.tooltipUtil.isXoverlap(j)) {
  17154. var firstVisibleSeries = w.globals.series.findIndex(function (s, i) {
  17155. return !w.globals.collapsedSeriesIndices.includes(i);
  17156. });
  17157. this.create(e, this, firstVisibleSeries, j, opt.ttItems);
  17158. }
  17159. }
  17160. }
  17161. }, {
  17162. key: "deactivateHoverFilter",
  17163. value: function deactivateHoverFilter() {
  17164. var w = this.w;
  17165. var graphics = new Graphics(this.ctx);
  17166. var allPaths = w.globals.dom.Paper.select(".apexcharts-bar-area");
  17167. for (var b = 0; b < allPaths.length; b++) {
  17168. graphics.pathMouseLeave(allPaths[b]);
  17169. }
  17170. }
  17171. }, {
  17172. key: "handleMouseOut",
  17173. value: function handleMouseOut(opt) {
  17174. var w = this.w;
  17175. var xcrosshairs = this.getElXCrosshairs();
  17176. w.globals.dom.baseEl.classList.remove('apexcharts-tooltip-active');
  17177. opt.tooltipEl.classList.remove('apexcharts-active');
  17178. this.deactivateHoverFilter();
  17179. if (w.config.chart.type !== 'bubble') {
  17180. this.marker.resetPointsSize();
  17181. }
  17182. if (xcrosshairs !== null) {
  17183. xcrosshairs.classList.remove('apexcharts-active');
  17184. }
  17185. if (this.ycrosshairs !== null) {
  17186. this.ycrosshairs.classList.remove('apexcharts-active');
  17187. }
  17188. if (this.isXAxisTooltipEnabled) {
  17189. this.xaxisTooltip.classList.remove('apexcharts-active');
  17190. }
  17191. if (this.yaxisTooltips.length) {
  17192. if (this.yaxisTTEls === null) {
  17193. this.yaxisTTEls = w.globals.dom.baseEl.querySelectorAll('.apexcharts-yaxistooltip');
  17194. }
  17195. for (var i = 0; i < this.yaxisTTEls.length; i++) {
  17196. this.yaxisTTEls[i].classList.remove('apexcharts-active');
  17197. }
  17198. }
  17199. if (w.config.legend.tooltipHoverFormatter) {
  17200. this.legendLabels.forEach(function (l) {
  17201. var defaultText = l.getAttribute('data:default-text');
  17202. l.innerHTML = decodeURIComponent(defaultText);
  17203. });
  17204. }
  17205. }
  17206. }, {
  17207. key: "markerClick",
  17208. value: function markerClick(e, seriesIndex, dataPointIndex) {
  17209. var w = this.w;
  17210. if (typeof w.config.chart.events.markerClick === 'function') {
  17211. w.config.chart.events.markerClick(e, this.ctx, {
  17212. seriesIndex: seriesIndex,
  17213. dataPointIndex: dataPointIndex,
  17214. w: w
  17215. });
  17216. }
  17217. this.ctx.events.fireEvent('markerClick', [e, this.ctx, {
  17218. seriesIndex: seriesIndex,
  17219. dataPointIndex: dataPointIndex,
  17220. w: w
  17221. }]);
  17222. }
  17223. }, {
  17224. key: "create",
  17225. value: function create(e, context, capturedSeries, j, ttItems) {
  17226. 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;
  17227. var shared = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
  17228. var w = this.w;
  17229. var ttCtx = context;
  17230. if (e.type === 'mouseup') {
  17231. this.markerClick(e, capturedSeries, j);
  17232. }
  17233. if (shared === null) shared = this.tConfig.shared;
  17234. var hasMarkers = this.tooltipUtil.hasMarkers(capturedSeries);
  17235. var bars = this.tooltipUtil.getElBars();
  17236. if (w.config.legend.tooltipHoverFormatter) {
  17237. var legendFormatter = w.config.legend.tooltipHoverFormatter;
  17238. var els = Array.from(this.legendLabels);
  17239. // reset all legend values first
  17240. els.forEach(function (l) {
  17241. var legendName = l.getAttribute('data:default-text');
  17242. l.innerHTML = decodeURIComponent(legendName);
  17243. });
  17244. // for irregular time series
  17245. for (var i = 0; i < els.length; i++) {
  17246. var l = els[i];
  17247. var lsIndex = parseInt(l.getAttribute('i'), 10);
  17248. var legendName = decodeURIComponent(l.getAttribute('data:default-text'));
  17249. var text = legendFormatter(legendName, {
  17250. seriesIndex: shared ? lsIndex : capturedSeries,
  17251. dataPointIndex: j,
  17252. w: w
  17253. });
  17254. if (!shared) {
  17255. l.innerHTML = lsIndex === capturedSeries ? text : legendName;
  17256. if (capturedSeries === lsIndex) {
  17257. break;
  17258. }
  17259. } else {
  17260. l.innerHTML = w.globals.collapsedSeriesIndices.indexOf(lsIndex) < 0 ? text : legendName;
  17261. }
  17262. }
  17263. }
  17264. var commonSeriesTextsParams = _objectSpread2(_objectSpread2({
  17265. ttItems: ttItems,
  17266. i: capturedSeries,
  17267. j: j
  17268. }, 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' && {
  17269. 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
  17270. }), 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' && {
  17271. 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
  17272. });
  17273. if (shared) {
  17274. ttCtx.tooltipLabels.drawSeriesTexts(_objectSpread2(_objectSpread2({}, commonSeriesTextsParams), {}, {
  17275. shared: this.showOnIntersect ? false : this.tConfig.shared
  17276. }));
  17277. if (hasMarkers) {
  17278. if (w.globals.markers.largestSize > 0) {
  17279. ttCtx.marker.enlargePoints(j);
  17280. } else {
  17281. ttCtx.tooltipPosition.moveDynamicPointsOnHover(j);
  17282. }
  17283. } else if (this.tooltipUtil.hasBars()) {
  17284. this.barSeriesHeight = this.tooltipUtil.getBarsHeight(bars);
  17285. if (this.barSeriesHeight > 0) {
  17286. // hover state, activate snap filter
  17287. var graphics = new Graphics(this.ctx);
  17288. var paths = w.globals.dom.Paper.select(".apexcharts-bar-area[j='".concat(j, "']"));
  17289. // de-activate first
  17290. this.deactivateHoverFilter();
  17291. this.tooltipPosition.moveStickyTooltipOverBars(j, capturedSeries);
  17292. for (var b = 0; b < paths.length; b++) {
  17293. graphics.pathMouseEnter(paths[b]);
  17294. }
  17295. }
  17296. }
  17297. } else {
  17298. ttCtx.tooltipLabels.drawSeriesTexts(_objectSpread2({
  17299. shared: false
  17300. }, commonSeriesTextsParams));
  17301. if (this.tooltipUtil.hasBars()) {
  17302. ttCtx.tooltipPosition.moveStickyTooltipOverBars(j, capturedSeries);
  17303. }
  17304. if (hasMarkers) {
  17305. ttCtx.tooltipPosition.moveMarkers(capturedSeries, j);
  17306. }
  17307. }
  17308. }
  17309. }]);
  17310. return Tooltip;
  17311. }();
  17312. var BarDataLabels = /*#__PURE__*/function () {
  17313. function BarDataLabels(barCtx) {
  17314. _classCallCheck(this, BarDataLabels);
  17315. this.w = barCtx.w;
  17316. this.barCtx = barCtx;
  17317. this.totalFormatter = this.w.config.plotOptions.bar.dataLabels.total.formatter;
  17318. if (!this.totalFormatter) {
  17319. this.totalFormatter = this.w.config.dataLabels.formatter;
  17320. }
  17321. }
  17322. /** handleBarDataLabels is used to calculate the positions for the data-labels
  17323. * It also sets the element's data attr for bars and calls drawCalculatedBarDataLabels()
  17324. * After calculating, it also calls the function to draw data labels
  17325. * @memberof Bar
  17326. * @param {object} {barProps} most of the bar properties used throughout the bar
  17327. * drawing function
  17328. * @return {object} dataLabels node-element which you can append later
  17329. **/
  17330. _createClass(BarDataLabels, [{
  17331. key: "handleBarDataLabels",
  17332. value: function handleBarDataLabels(opts) {
  17333. var x = opts.x,
  17334. y = opts.y,
  17335. y1 = opts.y1,
  17336. y2 = opts.y2,
  17337. i = opts.i,
  17338. j = opts.j,
  17339. realIndex = opts.realIndex,
  17340. columnGroupIndex = opts.columnGroupIndex,
  17341. series = opts.series,
  17342. barHeight = opts.barHeight,
  17343. barWidth = opts.barWidth,
  17344. barXPosition = opts.barXPosition,
  17345. barYPosition = opts.barYPosition,
  17346. visibleSeries = opts.visibleSeries,
  17347. renderedPath = opts.renderedPath;
  17348. var w = this.w;
  17349. var graphics = new Graphics(this.barCtx.ctx);
  17350. var strokeWidth = Array.isArray(this.barCtx.strokeWidth) ? this.barCtx.strokeWidth[realIndex] : this.barCtx.strokeWidth;
  17351. var bcx;
  17352. var bcy;
  17353. if (w.globals.isXNumeric && !w.globals.isBarHorizontal) {
  17354. bcx = x + parseFloat(barWidth * (visibleSeries + 1));
  17355. bcy = y + parseFloat(barHeight * (visibleSeries + 1)) - strokeWidth;
  17356. } else {
  17357. bcx = x + parseFloat(barWidth * visibleSeries);
  17358. bcy = y + parseFloat(barHeight * visibleSeries);
  17359. }
  17360. var dataLabels = null;
  17361. var totalDataLabels = null;
  17362. var dataLabelsX = x;
  17363. var dataLabelsY = y;
  17364. var dataLabelsPos = {};
  17365. var dataLabelsConfig = w.config.dataLabels;
  17366. var barDataLabelsConfig = this.barCtx.barOptions.dataLabels;
  17367. var barTotalDataLabelsConfig = this.barCtx.barOptions.dataLabels.total;
  17368. if (typeof barYPosition !== 'undefined' && this.barCtx.isRangeBar) {
  17369. bcy = barYPosition;
  17370. dataLabelsY = barYPosition;
  17371. }
  17372. if (typeof barXPosition !== 'undefined' && this.barCtx.isVerticalGroupedRangeBar) {
  17373. bcx = barXPosition;
  17374. dataLabelsX = barXPosition;
  17375. }
  17376. var offX = dataLabelsConfig.offsetX;
  17377. var offY = dataLabelsConfig.offsetY;
  17378. var textRects = {
  17379. width: 0,
  17380. height: 0
  17381. };
  17382. if (w.config.dataLabels.enabled) {
  17383. var yLabel = w.globals.series[i][j];
  17384. textRects = graphics.getTextRects(w.config.dataLabels.formatter ? w.config.dataLabels.formatter(yLabel, _objectSpread2(_objectSpread2({}, w), {}, {
  17385. seriesIndex: i,
  17386. dataPointIndex: j,
  17387. w: w
  17388. })) : w.globals.yLabelFormatters[0](yLabel), parseFloat(dataLabelsConfig.style.fontSize));
  17389. }
  17390. var params = {
  17391. x: x,
  17392. y: y,
  17393. i: i,
  17394. j: j,
  17395. realIndex: realIndex,
  17396. columnGroupIndex: columnGroupIndex,
  17397. renderedPath: renderedPath,
  17398. bcx: bcx,
  17399. bcy: bcy,
  17400. barHeight: barHeight,
  17401. barWidth: barWidth,
  17402. textRects: textRects,
  17403. strokeWidth: strokeWidth,
  17404. dataLabelsX: dataLabelsX,
  17405. dataLabelsY: dataLabelsY,
  17406. dataLabelsConfig: dataLabelsConfig,
  17407. barDataLabelsConfig: barDataLabelsConfig,
  17408. barTotalDataLabelsConfig: barTotalDataLabelsConfig,
  17409. offX: offX,
  17410. offY: offY
  17411. };
  17412. if (this.barCtx.isHorizontal) {
  17413. dataLabelsPos = this.calculateBarsDataLabelsPosition(params);
  17414. } else {
  17415. dataLabelsPos = this.calculateColumnsDataLabelsPosition(params);
  17416. }
  17417. renderedPath.attr({
  17418. cy: dataLabelsPos.bcy,
  17419. cx: dataLabelsPos.bcx,
  17420. j: j,
  17421. val: w.globals.series[i][j],
  17422. barHeight: barHeight,
  17423. barWidth: barWidth
  17424. });
  17425. dataLabels = this.drawCalculatedDataLabels({
  17426. x: dataLabelsPos.dataLabelsX,
  17427. y: dataLabelsPos.dataLabelsY,
  17428. val: this.barCtx.isRangeBar ? [y1, y2] : w.config.chart.stackType === '100%' ? series[realIndex][j] : w.globals.series[realIndex][j],
  17429. i: realIndex,
  17430. j: j,
  17431. barWidth: barWidth,
  17432. barHeight: barHeight,
  17433. textRects: textRects,
  17434. dataLabelsConfig: dataLabelsConfig
  17435. });
  17436. if (w.config.chart.stacked && barTotalDataLabelsConfig.enabled) {
  17437. totalDataLabels = this.drawTotalDataLabels({
  17438. x: dataLabelsPos.totalDataLabelsX,
  17439. y: dataLabelsPos.totalDataLabelsY,
  17440. barWidth: barWidth,
  17441. barHeight: barHeight,
  17442. realIndex: realIndex,
  17443. textAnchor: dataLabelsPos.totalDataLabelsAnchor,
  17444. val: this.getStackedTotalDataLabel({
  17445. realIndex: realIndex,
  17446. j: j
  17447. }),
  17448. dataLabelsConfig: dataLabelsConfig,
  17449. barTotalDataLabelsConfig: barTotalDataLabelsConfig
  17450. });
  17451. }
  17452. return {
  17453. dataLabels: dataLabels,
  17454. totalDataLabels: totalDataLabels
  17455. };
  17456. }
  17457. }, {
  17458. key: "getStackedTotalDataLabel",
  17459. value: function getStackedTotalDataLabel(_ref) {
  17460. var realIndex = _ref.realIndex,
  17461. j = _ref.j;
  17462. var w = this.w;
  17463. var val = this.barCtx.stackedSeriesTotals[j];
  17464. if (this.totalFormatter) {
  17465. val = this.totalFormatter(val, _objectSpread2(_objectSpread2({}, w), {}, {
  17466. seriesIndex: realIndex,
  17467. dataPointIndex: j,
  17468. w: w
  17469. }));
  17470. }
  17471. return val;
  17472. }
  17473. }, {
  17474. key: "calculateColumnsDataLabelsPosition",
  17475. value: function calculateColumnsDataLabelsPosition(opts) {
  17476. var w = this.w;
  17477. var i = opts.i,
  17478. j = opts.j,
  17479. realIndex = opts.realIndex;
  17480. opts.columnGroupIndex;
  17481. var y = opts.y,
  17482. bcx = opts.bcx,
  17483. barWidth = opts.barWidth,
  17484. barHeight = opts.barHeight,
  17485. textRects = opts.textRects,
  17486. dataLabelsX = opts.dataLabelsX,
  17487. dataLabelsY = opts.dataLabelsY,
  17488. dataLabelsConfig = opts.dataLabelsConfig,
  17489. barDataLabelsConfig = opts.barDataLabelsConfig,
  17490. barTotalDataLabelsConfig = opts.barTotalDataLabelsConfig,
  17491. strokeWidth = opts.strokeWidth,
  17492. offX = opts.offX,
  17493. offY = opts.offY;
  17494. var totalDataLabelsY;
  17495. var totalDataLabelsX;
  17496. var totalDataLabelsAnchor = 'middle';
  17497. var totalDataLabelsBcx = bcx;
  17498. barHeight = Math.abs(barHeight);
  17499. var vertical = w.config.plotOptions.bar.dataLabels.orientation === 'vertical';
  17500. var _this$barCtx$barHelpe = this.barCtx.barHelpers.getZeroValueEncounters({
  17501. i: i,
  17502. j: j
  17503. }),
  17504. zeroEncounters = _this$barCtx$barHelpe.zeroEncounters;
  17505. bcx = bcx - strokeWidth / 2;
  17506. var dataPointsDividedWidth = w.globals.gridWidth / w.globals.dataPoints;
  17507. if (this.barCtx.isVerticalGroupedRangeBar) {
  17508. dataLabelsX += barWidth / 2;
  17509. } else {
  17510. if (w.globals.isXNumeric) {
  17511. dataLabelsX = bcx - barWidth / 2 + offX;
  17512. } else {
  17513. dataLabelsX = bcx - dataPointsDividedWidth + barWidth / 2 + offX;
  17514. }
  17515. if (zeroEncounters > 0 && w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
  17516. dataLabelsX -= barWidth * zeroEncounters;
  17517. }
  17518. }
  17519. if (vertical) {
  17520. var offsetDLX = 2;
  17521. dataLabelsX = dataLabelsX + textRects.height / 2 - strokeWidth / 2 - offsetDLX;
  17522. }
  17523. var valIsNegative = w.globals.series[i][j] < 0;
  17524. var newY = y;
  17525. if (this.barCtx.isReversed) {
  17526. newY = y + (valIsNegative ? barHeight : -barHeight);
  17527. }
  17528. switch (barDataLabelsConfig.position) {
  17529. case 'center':
  17530. if (vertical) {
  17531. if (valIsNegative) {
  17532. dataLabelsY = newY - barHeight / 2 + offY;
  17533. } else {
  17534. dataLabelsY = newY + barHeight / 2 - offY;
  17535. }
  17536. } else {
  17537. if (valIsNegative) {
  17538. dataLabelsY = newY - barHeight / 2 + textRects.height / 2 + offY;
  17539. } else {
  17540. dataLabelsY = newY + barHeight / 2 + textRects.height / 2 - offY;
  17541. }
  17542. }
  17543. break;
  17544. case 'bottom':
  17545. if (vertical) {
  17546. if (valIsNegative) {
  17547. dataLabelsY = newY - barHeight + offY;
  17548. } else {
  17549. dataLabelsY = newY + barHeight - offY;
  17550. }
  17551. } else {
  17552. if (valIsNegative) {
  17553. dataLabelsY = newY - barHeight + textRects.height + strokeWidth + offY;
  17554. } else {
  17555. dataLabelsY = newY + barHeight - textRects.height / 2 + strokeWidth - offY;
  17556. }
  17557. }
  17558. break;
  17559. case 'top':
  17560. if (vertical) {
  17561. if (valIsNegative) {
  17562. dataLabelsY = newY + offY;
  17563. } else {
  17564. dataLabelsY = newY - offY;
  17565. }
  17566. } else {
  17567. if (valIsNegative) {
  17568. dataLabelsY = newY - textRects.height / 2 - offY;
  17569. } else {
  17570. dataLabelsY = newY + textRects.height + offY;
  17571. }
  17572. }
  17573. break;
  17574. }
  17575. if (this.barCtx.lastActiveBarSerieIndex === realIndex && barTotalDataLabelsConfig.enabled) {
  17576. var ADDITIONAL_OFFY = 18;
  17577. var graphics = new Graphics(this.barCtx.ctx);
  17578. var totalLabeltextRects = graphics.getTextRects(this.getStackedTotalDataLabel({
  17579. realIndex: realIndex,
  17580. j: j
  17581. }), dataLabelsConfig.fontSize);
  17582. if (valIsNegative) {
  17583. totalDataLabelsY = newY - totalLabeltextRects.height / 2 - offY - barTotalDataLabelsConfig.offsetY + ADDITIONAL_OFFY;
  17584. } else {
  17585. totalDataLabelsY = newY + totalLabeltextRects.height + offY + barTotalDataLabelsConfig.offsetY - ADDITIONAL_OFFY;
  17586. }
  17587. // width divided into equal parts
  17588. var xDivision = dataPointsDividedWidth;
  17589. 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;
  17590. }
  17591. if (!w.config.chart.stacked) {
  17592. if (dataLabelsY < 0) {
  17593. dataLabelsY = 0 + strokeWidth;
  17594. } else if (dataLabelsY + textRects.height / 3 > w.globals.gridHeight) {
  17595. dataLabelsY = w.globals.gridHeight - strokeWidth;
  17596. }
  17597. }
  17598. return {
  17599. bcx: bcx,
  17600. bcy: y,
  17601. dataLabelsX: dataLabelsX,
  17602. dataLabelsY: dataLabelsY,
  17603. totalDataLabelsX: totalDataLabelsX,
  17604. totalDataLabelsY: totalDataLabelsY,
  17605. totalDataLabelsAnchor: totalDataLabelsAnchor
  17606. };
  17607. }
  17608. }, {
  17609. key: "calculateBarsDataLabelsPosition",
  17610. value: function calculateBarsDataLabelsPosition(opts) {
  17611. var w = this.w;
  17612. var x = opts.x,
  17613. i = opts.i,
  17614. j = opts.j,
  17615. realIndex = opts.realIndex,
  17616. bcy = opts.bcy,
  17617. barHeight = opts.barHeight,
  17618. barWidth = opts.barWidth,
  17619. textRects = opts.textRects,
  17620. dataLabelsX = opts.dataLabelsX,
  17621. strokeWidth = opts.strokeWidth,
  17622. dataLabelsConfig = opts.dataLabelsConfig,
  17623. barDataLabelsConfig = opts.barDataLabelsConfig,
  17624. barTotalDataLabelsConfig = opts.barTotalDataLabelsConfig,
  17625. offX = opts.offX,
  17626. offY = opts.offY;
  17627. var dataPointsDividedHeight = w.globals.gridHeight / w.globals.dataPoints;
  17628. barWidth = Math.abs(barWidth);
  17629. var dataLabelsY = bcy - (this.barCtx.isRangeBar ? 0 : dataPointsDividedHeight) + barHeight / 2 + textRects.height / 2 + offY - 3;
  17630. var totalDataLabelsX;
  17631. var totalDataLabelsY;
  17632. var totalDataLabelsAnchor = 'start';
  17633. var valIsNegative = w.globals.series[i][j] < 0;
  17634. var newX = x;
  17635. if (this.barCtx.isReversed) {
  17636. newX = x + (valIsNegative ? -barWidth : barWidth);
  17637. totalDataLabelsAnchor = valIsNegative ? 'start' : 'end';
  17638. }
  17639. switch (barDataLabelsConfig.position) {
  17640. case 'center':
  17641. if (valIsNegative) {
  17642. dataLabelsX = newX + barWidth / 2 - offX;
  17643. } else {
  17644. dataLabelsX = Math.max(textRects.width / 2, newX - barWidth / 2) + offX;
  17645. }
  17646. break;
  17647. case 'bottom':
  17648. if (valIsNegative) {
  17649. dataLabelsX = newX + barWidth - strokeWidth - offX;
  17650. } else {
  17651. dataLabelsX = newX - barWidth + strokeWidth + offX;
  17652. }
  17653. break;
  17654. case 'top':
  17655. if (valIsNegative) {
  17656. dataLabelsX = newX - strokeWidth - offX;
  17657. } else {
  17658. dataLabelsX = newX - strokeWidth + offX;
  17659. }
  17660. break;
  17661. }
  17662. if (this.barCtx.lastActiveBarSerieIndex === realIndex && barTotalDataLabelsConfig.enabled) {
  17663. var graphics = new Graphics(this.barCtx.ctx);
  17664. var totalLabeltextRects = graphics.getTextRects(this.getStackedTotalDataLabel({
  17665. realIndex: realIndex,
  17666. j: j
  17667. }), dataLabelsConfig.fontSize);
  17668. if (valIsNegative) {
  17669. totalDataLabelsX = newX - strokeWidth - offX - barTotalDataLabelsConfig.offsetX;
  17670. totalDataLabelsAnchor = 'end';
  17671. } else {
  17672. totalDataLabelsX = newX + offX + barTotalDataLabelsConfig.offsetX + (this.barCtx.isReversed ? -(barWidth + strokeWidth) : strokeWidth);
  17673. }
  17674. totalDataLabelsY = dataLabelsY - textRects.height / 2 + totalLabeltextRects.height / 2 + barTotalDataLabelsConfig.offsetY + strokeWidth;
  17675. }
  17676. if (!w.config.chart.stacked) {
  17677. if (dataLabelsConfig.textAnchor === 'start') {
  17678. if (dataLabelsX - textRects.width < 0) {
  17679. dataLabelsX = valIsNegative ? textRects.width + strokeWidth : strokeWidth;
  17680. } else if (dataLabelsX + textRects.width > w.globals.gridWidth) {
  17681. dataLabelsX = valIsNegative ? w.globals.gridWidth - strokeWidth : w.globals.gridWidth - textRects.width - strokeWidth;
  17682. }
  17683. } else if (dataLabelsConfig.textAnchor === 'middle') {
  17684. if (dataLabelsX - textRects.width / 2 < 0) {
  17685. dataLabelsX = textRects.width / 2 + strokeWidth;
  17686. } else if (dataLabelsX + textRects.width / 2 > w.globals.gridWidth) {
  17687. dataLabelsX = w.globals.gridWidth - textRects.width / 2 - strokeWidth;
  17688. }
  17689. } else if (dataLabelsConfig.textAnchor === 'end') {
  17690. if (dataLabelsX < 1) {
  17691. dataLabelsX = textRects.width + strokeWidth;
  17692. } else if (dataLabelsX + 1 > w.globals.gridWidth) {
  17693. dataLabelsX = w.globals.gridWidth - textRects.width - strokeWidth;
  17694. }
  17695. }
  17696. }
  17697. return {
  17698. bcx: x,
  17699. bcy: bcy,
  17700. dataLabelsX: dataLabelsX,
  17701. dataLabelsY: dataLabelsY,
  17702. totalDataLabelsX: totalDataLabelsX,
  17703. totalDataLabelsY: totalDataLabelsY,
  17704. totalDataLabelsAnchor: totalDataLabelsAnchor
  17705. };
  17706. }
  17707. }, {
  17708. key: "drawCalculatedDataLabels",
  17709. value: function drawCalculatedDataLabels(_ref2) {
  17710. var x = _ref2.x,
  17711. y = _ref2.y,
  17712. val = _ref2.val,
  17713. i = _ref2.i,
  17714. j = _ref2.j,
  17715. textRects = _ref2.textRects,
  17716. barHeight = _ref2.barHeight,
  17717. barWidth = _ref2.barWidth,
  17718. dataLabelsConfig = _ref2.dataLabelsConfig;
  17719. var w = this.w;
  17720. var rotate = 'rotate(0)';
  17721. if (w.config.plotOptions.bar.dataLabels.orientation === 'vertical') rotate = "rotate(-90, ".concat(x, ", ").concat(y, ")");
  17722. var dataLabels = new DataLabels(this.barCtx.ctx);
  17723. var graphics = new Graphics(this.barCtx.ctx);
  17724. var formatter = dataLabelsConfig.formatter;
  17725. var elDataLabelsWrap = null;
  17726. var isSeriesNotCollapsed = w.globals.collapsedSeriesIndices.indexOf(i) > -1;
  17727. if (dataLabelsConfig.enabled && !isSeriesNotCollapsed) {
  17728. elDataLabelsWrap = graphics.group({
  17729. class: 'apexcharts-data-labels',
  17730. transform: rotate
  17731. });
  17732. var text = '';
  17733. if (typeof val !== 'undefined') {
  17734. text = formatter(val, _objectSpread2(_objectSpread2({}, w), {}, {
  17735. seriesIndex: i,
  17736. dataPointIndex: j,
  17737. w: w
  17738. }));
  17739. }
  17740. if (!val && w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
  17741. text = '';
  17742. }
  17743. var valIsNegative = w.globals.series[i][j] < 0;
  17744. var position = w.config.plotOptions.bar.dataLabels.position;
  17745. if (w.config.plotOptions.bar.dataLabels.orientation === 'vertical') {
  17746. if (position === 'top') {
  17747. if (valIsNegative) dataLabelsConfig.textAnchor = 'end';else dataLabelsConfig.textAnchor = 'start';
  17748. }
  17749. if (position === 'center') {
  17750. dataLabelsConfig.textAnchor = 'middle';
  17751. }
  17752. if (position === 'bottom') {
  17753. if (valIsNegative) dataLabelsConfig.textAnchor = 'end';else dataLabelsConfig.textAnchor = 'start';
  17754. }
  17755. }
  17756. if (this.barCtx.isRangeBar && this.barCtx.barOptions.dataLabels.hideOverflowingLabels) {
  17757. // hide the datalabel if it cannot fit into the rect
  17758. var txRect = graphics.getTextRects(text, parseFloat(dataLabelsConfig.style.fontSize));
  17759. if (barWidth < txRect.width) {
  17760. text = '';
  17761. }
  17762. }
  17763. if (w.config.chart.stacked && this.barCtx.barOptions.dataLabels.hideOverflowingLabels) {
  17764. // if there is not enough space to draw the label in the bar/column rect, check hideOverflowingLabels property to prevent overflowing on wrong rect
  17765. // Note: This issue is only seen in stacked charts
  17766. if (this.barCtx.isHorizontal) {
  17767. if (textRects.width / 1.6 > Math.abs(barWidth)) {
  17768. text = '';
  17769. }
  17770. } else {
  17771. if (textRects.height / 1.6 > Math.abs(barHeight)) {
  17772. text = '';
  17773. }
  17774. }
  17775. }
  17776. var modifiedDataLabelsConfig = _objectSpread2({}, dataLabelsConfig);
  17777. if (this.barCtx.isHorizontal) {
  17778. if (val < 0) {
  17779. if (dataLabelsConfig.textAnchor === 'start') {
  17780. modifiedDataLabelsConfig.textAnchor = 'end';
  17781. } else if (dataLabelsConfig.textAnchor === 'end') {
  17782. modifiedDataLabelsConfig.textAnchor = 'start';
  17783. }
  17784. }
  17785. }
  17786. dataLabels.plotDataLabelsText({
  17787. x: x,
  17788. y: y,
  17789. text: text,
  17790. i: i,
  17791. j: j,
  17792. parent: elDataLabelsWrap,
  17793. dataLabelsConfig: modifiedDataLabelsConfig,
  17794. alwaysDrawDataLabel: true,
  17795. offsetCorrection: true
  17796. });
  17797. }
  17798. return elDataLabelsWrap;
  17799. }
  17800. }, {
  17801. key: "drawTotalDataLabels",
  17802. value: function drawTotalDataLabels(_ref3) {
  17803. var x = _ref3.x,
  17804. y = _ref3.y,
  17805. val = _ref3.val,
  17806. realIndex = _ref3.realIndex,
  17807. textAnchor = _ref3.textAnchor,
  17808. barTotalDataLabelsConfig = _ref3.barTotalDataLabelsConfig;
  17809. this.w;
  17810. var graphics = new Graphics(this.barCtx.ctx);
  17811. var totalDataLabelText;
  17812. if (barTotalDataLabelsConfig.enabled && typeof x !== 'undefined' && typeof y !== 'undefined' && this.barCtx.lastActiveBarSerieIndex === realIndex) {
  17813. totalDataLabelText = graphics.drawText({
  17814. x: x,
  17815. y: y,
  17816. foreColor: barTotalDataLabelsConfig.style.color,
  17817. text: val,
  17818. textAnchor: textAnchor,
  17819. fontFamily: barTotalDataLabelsConfig.style.fontFamily,
  17820. fontSize: barTotalDataLabelsConfig.style.fontSize,
  17821. fontWeight: barTotalDataLabelsConfig.style.fontWeight
  17822. });
  17823. }
  17824. return totalDataLabelText;
  17825. }
  17826. }]);
  17827. return BarDataLabels;
  17828. }();
  17829. var Helpers$1 = /*#__PURE__*/function () {
  17830. function Helpers(barCtx) {
  17831. _classCallCheck(this, Helpers);
  17832. this.w = barCtx.w;
  17833. this.barCtx = barCtx;
  17834. }
  17835. _createClass(Helpers, [{
  17836. key: "initVariables",
  17837. value: function initVariables(series) {
  17838. var w = this.w;
  17839. this.barCtx.series = series;
  17840. this.barCtx.totalItems = 0;
  17841. this.barCtx.seriesLen = 0;
  17842. this.barCtx.visibleI = -1; // visible Series
  17843. this.barCtx.visibleItems = 1; // number of visible bars after user zoomed in/out
  17844. for (var sl = 0; sl < series.length; sl++) {
  17845. if (series[sl].length > 0) {
  17846. this.barCtx.seriesLen = this.barCtx.seriesLen + 1;
  17847. this.barCtx.totalItems += series[sl].length;
  17848. }
  17849. if (w.globals.isXNumeric) {
  17850. // get max visible items
  17851. for (var _j = 0; _j < series[sl].length; _j++) {
  17852. if (w.globals.seriesX[sl][_j] > w.globals.minX && w.globals.seriesX[sl][_j] < w.globals.maxX) {
  17853. this.barCtx.visibleItems++;
  17854. }
  17855. }
  17856. } else {
  17857. this.barCtx.visibleItems = w.globals.dataPoints;
  17858. }
  17859. }
  17860. this.arrBorderRadius = this.createBorderRadiusArr(w.globals.series);
  17861. if (this.barCtx.seriesLen === 0) {
  17862. // A small adjustment when combo charts are used
  17863. this.barCtx.seriesLen = 1;
  17864. }
  17865. this.barCtx.zeroSerieses = [];
  17866. if (!w.globals.comboCharts) {
  17867. this.checkZeroSeries({
  17868. series: series
  17869. });
  17870. }
  17871. }
  17872. }, {
  17873. key: "initialPositions",
  17874. value: function initialPositions() {
  17875. var w = this.w;
  17876. var x, y, yDivision, xDivision, barHeight, barWidth, zeroH, zeroW;
  17877. var dataPoints = w.globals.dataPoints;
  17878. if (this.barCtx.isRangeBar) {
  17879. // timeline rangebar chart
  17880. dataPoints = w.globals.labels.length;
  17881. }
  17882. var seriesLen = this.barCtx.seriesLen;
  17883. if (w.config.plotOptions.bar.rangeBarGroupRows) {
  17884. seriesLen = 1;
  17885. }
  17886. if (this.barCtx.isHorizontal) {
  17887. // height divided into equal parts
  17888. yDivision = w.globals.gridHeight / dataPoints;
  17889. barHeight = yDivision / seriesLen;
  17890. if (w.globals.isXNumeric) {
  17891. yDivision = w.globals.gridHeight / this.barCtx.totalItems;
  17892. barHeight = yDivision / this.barCtx.seriesLen;
  17893. }
  17894. barHeight = barHeight * parseInt(this.barCtx.barOptions.barHeight, 10) / 100;
  17895. if (String(this.barCtx.barOptions.barHeight).indexOf('%') === -1) {
  17896. barHeight = parseInt(this.barCtx.barOptions.barHeight, 10);
  17897. }
  17898. zeroW = this.barCtx.baseLineInvertedY + w.globals.padHorizontal + (this.barCtx.isReversed ? w.globals.gridWidth : 0) - (this.barCtx.isReversed ? this.barCtx.baseLineInvertedY * 2 : 0);
  17899. if (this.barCtx.isFunnel) {
  17900. zeroW = w.globals.gridWidth / 2;
  17901. }
  17902. y = (yDivision - barHeight * this.barCtx.seriesLen) / 2;
  17903. } else {
  17904. // width divided into equal parts
  17905. xDivision = w.globals.gridWidth / this.barCtx.visibleItems;
  17906. if (w.config.xaxis.convertedCatToNumeric) {
  17907. xDivision = w.globals.gridWidth / w.globals.dataPoints;
  17908. }
  17909. barWidth = xDivision / seriesLen * parseInt(this.barCtx.barOptions.columnWidth, 10) / 100;
  17910. if (w.globals.isXNumeric) {
  17911. // max barwidth should be equal to minXDiff to avoid overlap
  17912. var xRatio = this.barCtx.xRatio;
  17913. if (w.globals.minXDiff && w.globals.minXDiff !== 0.5 && w.globals.minXDiff / xRatio > 0) {
  17914. xDivision = w.globals.minXDiff / xRatio;
  17915. }
  17916. barWidth = xDivision / seriesLen * parseInt(this.barCtx.barOptions.columnWidth, 10) / 100;
  17917. if (barWidth < 1) {
  17918. barWidth = 1;
  17919. }
  17920. }
  17921. if (String(this.barCtx.barOptions.columnWidth).indexOf('%') === -1) {
  17922. barWidth = parseInt(this.barCtx.barOptions.columnWidth, 10);
  17923. }
  17924. 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);
  17925. x = w.globals.padHorizontal + (xDivision - barWidth * this.barCtx.seriesLen) / 2;
  17926. }
  17927. w.globals.barHeight = barHeight;
  17928. w.globals.barWidth = barWidth;
  17929. return {
  17930. x: x,
  17931. y: y,
  17932. yDivision: yDivision,
  17933. xDivision: xDivision,
  17934. barHeight: barHeight,
  17935. barWidth: barWidth,
  17936. zeroH: zeroH,
  17937. zeroW: zeroW
  17938. };
  17939. }
  17940. }, {
  17941. key: "initializeStackedPrevVars",
  17942. value: function initializeStackedPrevVars(ctx) {
  17943. var w = ctx.w;
  17944. w.globals.seriesGroups.forEach(function (group) {
  17945. if (!ctx[group]) ctx[group] = {};
  17946. ctx[group].prevY = [];
  17947. ctx[group].prevX = [];
  17948. ctx[group].prevYF = [];
  17949. ctx[group].prevXF = [];
  17950. ctx[group].prevYVal = [];
  17951. ctx[group].prevXVal = [];
  17952. });
  17953. }
  17954. }, {
  17955. key: "initializeStackedXYVars",
  17956. value: function initializeStackedXYVars(ctx) {
  17957. var w = ctx.w;
  17958. w.globals.seriesGroups.forEach(function (group) {
  17959. if (!ctx[group]) ctx[group] = {};
  17960. ctx[group].xArrj = [];
  17961. ctx[group].xArrjF = [];
  17962. ctx[group].xArrjVal = [];
  17963. ctx[group].yArrj = [];
  17964. ctx[group].yArrjF = [];
  17965. ctx[group].yArrjVal = [];
  17966. });
  17967. }
  17968. }, {
  17969. key: "getPathFillColor",
  17970. value: function getPathFillColor(series, i, j, realIndex) {
  17971. var _w$config$series$i$da, _w$config$series$i$da2, _w$config$series$i$da3, _w$config$series$i$da4, _w$config$series$i$da5;
  17972. var w = this.w;
  17973. var fill = this.barCtx.ctx.fill;
  17974. var fillColor = null;
  17975. var seriesNumber = this.barCtx.barOptions.distributed ? j : i;
  17976. if (this.barCtx.barOptions.colors.ranges.length > 0) {
  17977. var colorRange = this.barCtx.barOptions.colors.ranges;
  17978. colorRange.map(function (range) {
  17979. if (series[i][j] >= range.from && series[i][j] <= range.to) {
  17980. fillColor = range.color;
  17981. }
  17982. });
  17983. }
  17984. if ((_w$config$series$i$da = w.config.series[i].data[j]) !== null && _w$config$series$i$da !== void 0 && _w$config$series$i$da.fillColor) {
  17985. fillColor = w.config.series[i].data[j].fillColor;
  17986. }
  17987. var pathFill = fill.fillPath({
  17988. seriesNumber: this.barCtx.barOptions.distributed ? seriesNumber : realIndex,
  17989. dataPointIndex: j,
  17990. color: fillColor,
  17991. value: series[i][j],
  17992. fillConfig: (_w$config$series$i$da2 = w.config.series[i].data[j]) === null || _w$config$series$i$da2 === void 0 ? void 0 : _w$config$series$i$da2.fill,
  17993. fillType: (_w$config$series$i$da3 = w.config.series[i].data[j]) !== null && _w$config$series$i$da3 !== void 0 && (_w$config$series$i$da4 = _w$config$series$i$da3.fill) !== null && _w$config$series$i$da4 !== void 0 && _w$config$series$i$da4.type ? (_w$config$series$i$da5 = w.config.series[i].data[j]) === null || _w$config$series$i$da5 === void 0 ? void 0 : _w$config$series$i$da5.fill.type : Array.isArray(w.config.fill.type) ? w.config.fill.type[realIndex] : w.config.fill.type
  17994. });
  17995. return pathFill;
  17996. }
  17997. }, {
  17998. key: "getStrokeWidth",
  17999. value: function getStrokeWidth(i, j, realIndex) {
  18000. var strokeWidth = 0;
  18001. var w = this.w;
  18002. if (!this.barCtx.series[i][j]) {
  18003. this.barCtx.isNullValue = true;
  18004. } else {
  18005. this.barCtx.isNullValue = false;
  18006. }
  18007. if (w.config.stroke.show) {
  18008. if (!this.barCtx.isNullValue) {
  18009. strokeWidth = Array.isArray(this.barCtx.strokeWidth) ? this.barCtx.strokeWidth[realIndex] : this.barCtx.strokeWidth;
  18010. }
  18011. }
  18012. return strokeWidth;
  18013. }
  18014. }, {
  18015. key: "createBorderRadiusArr",
  18016. value: function createBorderRadiusArr(series) {
  18017. var w = this.w;
  18018. var alwaysApplyRadius = !this.w.config.chart.stacked || w.config.plotOptions.bar.borderRadiusWhenStacked !== 'last' || w.config.plotOptions.bar.borderRadius <= 0;
  18019. var numSeries = series.length;
  18020. var numColumns = series[0].length;
  18021. var output = Array.from({
  18022. length: numSeries
  18023. }, function () {
  18024. return Array(numColumns).fill(alwaysApplyRadius ? 'top' : 'none');
  18025. });
  18026. if (alwaysApplyRadius) return output;
  18027. for (var _j2 = 0; _j2 < numColumns; _j2++) {
  18028. var positiveIndices = [];
  18029. var negativeIndices = [];
  18030. var nonZeroCount = 0;
  18031. // Collect positive and negative indices
  18032. for (var i = 0; i < numSeries; i++) {
  18033. var value = series[i][_j2];
  18034. if (value > 0) {
  18035. positiveIndices.push(i);
  18036. nonZeroCount++;
  18037. } else if (value < 0) {
  18038. negativeIndices.push(i);
  18039. nonZeroCount++;
  18040. }
  18041. }
  18042. if (positiveIndices.length > 0 && negativeIndices.length === 0) {
  18043. // Only positive values in this column
  18044. if (positiveIndices.length === 1) {
  18045. // Single positive value
  18046. output[positiveIndices[0]][_j2] = 'both';
  18047. } else {
  18048. // Multiple positive values
  18049. var firstPositiveIndex = positiveIndices[0];
  18050. var lastPositiveIndex = positiveIndices[positiveIndices.length - 1];
  18051. var _iterator = _createForOfIteratorHelper(positiveIndices),
  18052. _step;
  18053. try {
  18054. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  18055. var _i2 = _step.value;
  18056. if (_i2 === firstPositiveIndex) {
  18057. output[_i2][_j2] = 'bottom';
  18058. } else if (_i2 === lastPositiveIndex) {
  18059. output[_i2][_j2] = 'top';
  18060. } else {
  18061. output[_i2][_j2] = 'none';
  18062. }
  18063. }
  18064. } catch (err) {
  18065. _iterator.e(err);
  18066. } finally {
  18067. _iterator.f();
  18068. }
  18069. }
  18070. } else if (negativeIndices.length > 0 && positiveIndices.length === 0) {
  18071. // Only negative values in this column
  18072. if (negativeIndices.length === 1) {
  18073. // Single negative value
  18074. output[negativeIndices[0]][_j2] = 'both';
  18075. } else {
  18076. // Multiple negative values
  18077. var firstNegativeIndex = negativeIndices[0];
  18078. var lastNegativeIndex = negativeIndices[negativeIndices.length - 1];
  18079. var _iterator2 = _createForOfIteratorHelper(negativeIndices),
  18080. _step2;
  18081. try {
  18082. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  18083. var _i3 = _step2.value;
  18084. if (_i3 === firstNegativeIndex) {
  18085. output[_i3][_j2] = 'bottom';
  18086. } else if (_i3 === lastNegativeIndex) {
  18087. output[_i3][_j2] = 'top';
  18088. } else {
  18089. output[_i3][_j2] = 'none';
  18090. }
  18091. }
  18092. } catch (err) {
  18093. _iterator2.e(err);
  18094. } finally {
  18095. _iterator2.f();
  18096. }
  18097. }
  18098. } else if (positiveIndices.length > 0 && negativeIndices.length > 0) {
  18099. // Mixed positive and negative values
  18100. // Assign 'top' to the last positive bar
  18101. var _lastPositiveIndex = positiveIndices[positiveIndices.length - 1];
  18102. var _iterator3 = _createForOfIteratorHelper(positiveIndices),
  18103. _step3;
  18104. try {
  18105. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  18106. var _i4 = _step3.value;
  18107. if (_i4 === _lastPositiveIndex) {
  18108. output[_i4][_j2] = 'top';
  18109. } else {
  18110. output[_i4][_j2] = 'none';
  18111. }
  18112. }
  18113. // Assign 'bottom' to the last negative bar (closest to axis)
  18114. } catch (err) {
  18115. _iterator3.e(err);
  18116. } finally {
  18117. _iterator3.f();
  18118. }
  18119. var _lastNegativeIndex = negativeIndices[negativeIndices.length - 1];
  18120. var _iterator4 = _createForOfIteratorHelper(negativeIndices),
  18121. _step4;
  18122. try {
  18123. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  18124. var _i5 = _step4.value;
  18125. if (_i5 === _lastNegativeIndex) {
  18126. output[_i5][_j2] = 'bottom';
  18127. } else {
  18128. output[_i5][_j2] = 'none';
  18129. }
  18130. }
  18131. } catch (err) {
  18132. _iterator4.e(err);
  18133. } finally {
  18134. _iterator4.f();
  18135. }
  18136. } else if (nonZeroCount === 1) {
  18137. // Only one non-zero value (either positive or negative)
  18138. var index = positiveIndices[0] || negativeIndices[0];
  18139. output[index][_j2] = 'both';
  18140. }
  18141. }
  18142. return output;
  18143. }
  18144. }, {
  18145. key: "barBackground",
  18146. value: function barBackground(_ref) {
  18147. var j = _ref.j,
  18148. i = _ref.i,
  18149. x1 = _ref.x1,
  18150. x2 = _ref.x2,
  18151. y1 = _ref.y1,
  18152. y2 = _ref.y2,
  18153. elSeries = _ref.elSeries;
  18154. var w = this.w;
  18155. var graphics = new Graphics(this.barCtx.ctx);
  18156. var sr = new Series(this.barCtx.ctx);
  18157. var activeSeriesIndex = sr.getActiveConfigSeriesIndex();
  18158. if (this.barCtx.barOptions.colors.backgroundBarColors.length > 0 && activeSeriesIndex === i) {
  18159. if (j >= this.barCtx.barOptions.colors.backgroundBarColors.length) {
  18160. j %= this.barCtx.barOptions.colors.backgroundBarColors.length;
  18161. }
  18162. var bcolor = this.barCtx.barOptions.colors.backgroundBarColors[j];
  18163. 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);
  18164. elSeries.add(rect);
  18165. rect.node.classList.add('apexcharts-backgroundBar');
  18166. }
  18167. }
  18168. }, {
  18169. key: "getColumnPaths",
  18170. value: function getColumnPaths(_ref2) {
  18171. var _w$config$series$real;
  18172. var barWidth = _ref2.barWidth,
  18173. barXPosition = _ref2.barXPosition,
  18174. y1 = _ref2.y1,
  18175. y2 = _ref2.y2,
  18176. strokeWidth = _ref2.strokeWidth,
  18177. isReversed = _ref2.isReversed,
  18178. series = _ref2.series,
  18179. seriesGroup = _ref2.seriesGroup,
  18180. realIndex = _ref2.realIndex,
  18181. i = _ref2.i,
  18182. j = _ref2.j,
  18183. w = _ref2.w;
  18184. var graphics = new Graphics(this.barCtx.ctx);
  18185. strokeWidth = Array.isArray(strokeWidth) ? strokeWidth[realIndex] : strokeWidth;
  18186. if (!strokeWidth) strokeWidth = 0;
  18187. var bW = barWidth;
  18188. var bXP = barXPosition;
  18189. if ((_w$config$series$real = w.config.series[realIndex].data[j]) !== null && _w$config$series$real !== void 0 && _w$config$series$real.columnWidthOffset) {
  18190. bXP = barXPosition - w.config.series[realIndex].data[j].columnWidthOffset / 2;
  18191. bW = barWidth + w.config.series[realIndex].data[j].columnWidthOffset;
  18192. }
  18193. // Center the stroke on the coordinates
  18194. var strokeCenter = strokeWidth / 2;
  18195. var x1 = bXP + strokeCenter;
  18196. var x2 = bXP + bW - strokeCenter;
  18197. var direction = (series[i][j] >= 0 ? 1 : -1) * (isReversed ? -1 : 1);
  18198. // append tiny pixels to avoid exponentials (which cause issues in border-radius)
  18199. y1 += 0.001 - strokeCenter * direction;
  18200. y2 += 0.001 + strokeCenter * direction;
  18201. var pathTo = graphics.move(x1, y1);
  18202. var pathFrom = graphics.move(x1, y1);
  18203. var sl = graphics.line(x2, y1);
  18204. if (w.globals.previousPaths.length > 0) {
  18205. pathFrom = this.barCtx.getPreviousPath(realIndex, j, false);
  18206. }
  18207. pathTo = pathTo + graphics.line(x1, y2) + graphics.line(x2, y2) + sl + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
  18208. // the lines in pathFrom are repeated to equal it to the points of pathTo
  18209. // this is to avoid weird animation (bug in svg.js)
  18210. 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');
  18211. if (this.arrBorderRadius[realIndex][j] !== 'none') {
  18212. pathTo = graphics.roundPathCorners(pathTo, w.config.plotOptions.bar.borderRadius);
  18213. }
  18214. if (w.config.chart.stacked) {
  18215. var _ctx = this.barCtx;
  18216. _ctx = this.barCtx[seriesGroup];
  18217. _ctx.yArrj.push(y2 - strokeCenter * direction);
  18218. _ctx.yArrjF.push(Math.abs(y1 - y2 + strokeWidth * direction));
  18219. _ctx.yArrjVal.push(this.barCtx.series[i][j]);
  18220. }
  18221. return {
  18222. pathTo: pathTo,
  18223. pathFrom: pathFrom
  18224. };
  18225. }
  18226. }, {
  18227. key: "getBarpaths",
  18228. value: function getBarpaths(_ref3) {
  18229. var _w$config$series$real2;
  18230. var barYPosition = _ref3.barYPosition,
  18231. barHeight = _ref3.barHeight,
  18232. x1 = _ref3.x1,
  18233. x2 = _ref3.x2,
  18234. strokeWidth = _ref3.strokeWidth,
  18235. isReversed = _ref3.isReversed,
  18236. series = _ref3.series,
  18237. seriesGroup = _ref3.seriesGroup,
  18238. realIndex = _ref3.realIndex,
  18239. i = _ref3.i,
  18240. j = _ref3.j,
  18241. w = _ref3.w;
  18242. var graphics = new Graphics(this.barCtx.ctx);
  18243. strokeWidth = Array.isArray(strokeWidth) ? strokeWidth[realIndex] : strokeWidth;
  18244. if (!strokeWidth) strokeWidth = 0;
  18245. var bYP = barYPosition;
  18246. var bH = barHeight;
  18247. if ((_w$config$series$real2 = w.config.series[realIndex].data[j]) !== null && _w$config$series$real2 !== void 0 && _w$config$series$real2.barHeightOffset) {
  18248. bYP = barYPosition - w.config.series[realIndex].data[j].barHeightOffset / 2;
  18249. bH = barHeight + w.config.series[realIndex].data[j].barHeightOffset;
  18250. }
  18251. // Center the stroke on the coordinates
  18252. var strokeCenter = strokeWidth / 2;
  18253. var y1 = bYP + strokeCenter;
  18254. var y2 = bYP + bH - strokeCenter;
  18255. var direction = (series[i][j] >= 0 ? 1 : -1) * (isReversed ? -1 : 1);
  18256. // append tiny pixels to avoid exponentials (which cause issues in border-radius)
  18257. x1 += 0.001 + strokeCenter * direction;
  18258. x2 += 0.001 - strokeCenter * direction;
  18259. var pathTo = graphics.move(x1, y1);
  18260. var pathFrom = graphics.move(x1, y1);
  18261. if (w.globals.previousPaths.length > 0) {
  18262. pathFrom = this.barCtx.getPreviousPath(realIndex, j, false);
  18263. }
  18264. var sl = graphics.line(x1, y2);
  18265. pathTo = pathTo + graphics.line(x2, y1) + graphics.line(x2, y2) + sl + (w.config.plotOptions.bar.borderRadiusApplication === 'around' || this.arrBorderRadius[realIndex][j] === 'both' ? ' Z' : ' z');
  18266. 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');
  18267. if (this.arrBorderRadius[realIndex][j] !== 'none') {
  18268. pathTo = graphics.roundPathCorners(pathTo, w.config.plotOptions.bar.borderRadius);
  18269. }
  18270. if (w.config.chart.stacked) {
  18271. var _ctx = this.barCtx;
  18272. _ctx = this.barCtx[seriesGroup];
  18273. _ctx.xArrj.push(x2 + strokeCenter * direction);
  18274. _ctx.xArrjF.push(Math.abs(x1 - x2 - strokeWidth * direction));
  18275. _ctx.xArrjVal.push(this.barCtx.series[i][j]);
  18276. }
  18277. return {
  18278. pathTo: pathTo,
  18279. pathFrom: pathFrom
  18280. };
  18281. }
  18282. }, {
  18283. key: "checkZeroSeries",
  18284. value: function checkZeroSeries(_ref4) {
  18285. var series = _ref4.series;
  18286. var w = this.w;
  18287. for (var zs = 0; zs < series.length; zs++) {
  18288. var total = 0;
  18289. for (var zsj = 0; zsj < series[w.globals.maxValsInArrayIndex].length; zsj++) {
  18290. total += series[zs][zsj];
  18291. }
  18292. if (total === 0) {
  18293. this.barCtx.zeroSerieses.push(zs);
  18294. }
  18295. }
  18296. }
  18297. }, {
  18298. key: "getXForValue",
  18299. value: function getXForValue(value, zeroW) {
  18300. var zeroPositionForNull = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  18301. var xForVal = zeroPositionForNull ? zeroW : null;
  18302. if (typeof value !== 'undefined' && value !== null) {
  18303. xForVal = zeroW + value / this.barCtx.invertedYRatio - (this.barCtx.isReversed ? value / this.barCtx.invertedYRatio : 0) * 2;
  18304. }
  18305. return xForVal;
  18306. }
  18307. }, {
  18308. key: "getYForValue",
  18309. value: function getYForValue(value, zeroH, translationsIndex) {
  18310. var zeroPositionForNull = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  18311. var yForVal = zeroPositionForNull ? zeroH : null;
  18312. if (typeof value !== 'undefined' && value !== null) {
  18313. yForVal = zeroH - value / this.barCtx.yRatio[translationsIndex] + (this.barCtx.isReversed ? value / this.barCtx.yRatio[translationsIndex] : 0) * 2;
  18314. }
  18315. return yForVal;
  18316. }
  18317. }, {
  18318. key: "getGoalValues",
  18319. value: function getGoalValues(type, zeroW, zeroH, i, j, translationsIndex) {
  18320. var _this = this;
  18321. var w = this.w;
  18322. var goals = [];
  18323. var pushGoal = function pushGoal(value, attrs) {
  18324. var _goals$push;
  18325. 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));
  18326. };
  18327. if (w.globals.seriesGoals[i] && w.globals.seriesGoals[i][j] && Array.isArray(w.globals.seriesGoals[i][j])) {
  18328. w.globals.seriesGoals[i][j].forEach(function (goal) {
  18329. pushGoal(goal.value, goal);
  18330. });
  18331. }
  18332. if (this.barCtx.barOptions.isDumbbell && w.globals.seriesRange.length) {
  18333. var colors = this.barCtx.barOptions.dumbbellColors ? this.barCtx.barOptions.dumbbellColors : w.globals.colors;
  18334. var commonAttrs = {
  18335. strokeHeight: type === 'x' ? 0 : w.globals.markers.size[i],
  18336. strokeWidth: type === 'x' ? w.globals.markers.size[i] : 0,
  18337. strokeDashArray: 0,
  18338. strokeLineCap: 'round',
  18339. strokeColor: Array.isArray(colors[i]) ? colors[i][0] : colors[i]
  18340. };
  18341. pushGoal(w.globals.seriesRangeStart[i][j], commonAttrs);
  18342. pushGoal(w.globals.seriesRangeEnd[i][j], _objectSpread2(_objectSpread2({}, commonAttrs), {}, {
  18343. strokeColor: Array.isArray(colors[i]) ? colors[i][1] : colors[i]
  18344. }));
  18345. }
  18346. return goals;
  18347. }
  18348. }, {
  18349. key: "drawGoalLine",
  18350. value: function drawGoalLine(_ref5) {
  18351. var barXPosition = _ref5.barXPosition,
  18352. barYPosition = _ref5.barYPosition,
  18353. goalX = _ref5.goalX,
  18354. goalY = _ref5.goalY,
  18355. barWidth = _ref5.barWidth,
  18356. barHeight = _ref5.barHeight;
  18357. var graphics = new Graphics(this.barCtx.ctx);
  18358. var lineGroup = graphics.group({
  18359. className: 'apexcharts-bar-goals-groups'
  18360. });
  18361. lineGroup.node.classList.add('apexcharts-element-hidden');
  18362. this.barCtx.w.globals.delayedElements.push({
  18363. el: lineGroup.node
  18364. });
  18365. lineGroup.attr('clip-path', "url(#gridRectMarkerMask".concat(this.barCtx.w.globals.cuid, ")"));
  18366. var line = null;
  18367. if (this.barCtx.isHorizontal) {
  18368. if (Array.isArray(goalX)) {
  18369. goalX.forEach(function (goal) {
  18370. // Need a tiny margin of 1 each side so goals don't disappear at extremeties
  18371. if (goal.x >= -1 && goal.x <= graphics.w.globals.gridWidth + 1) {
  18372. var sHeight = typeof goal.attrs.strokeHeight !== 'undefined' ? goal.attrs.strokeHeight : barHeight / 2;
  18373. var y = barYPosition + sHeight + barHeight / 2;
  18374. 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);
  18375. lineGroup.add(line);
  18376. }
  18377. });
  18378. }
  18379. } else {
  18380. if (Array.isArray(goalY)) {
  18381. goalY.forEach(function (goal) {
  18382. // Need a tiny margin of 1 each side so goals don't disappear at extremeties
  18383. if (goal.y >= -1 && goal.y <= graphics.w.globals.gridHeight + 1) {
  18384. var sWidth = typeof goal.attrs.strokeWidth !== 'undefined' ? goal.attrs.strokeWidth : barWidth / 2;
  18385. var x = barXPosition + sWidth + barWidth / 2;
  18386. 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);
  18387. lineGroup.add(line);
  18388. }
  18389. });
  18390. }
  18391. }
  18392. return lineGroup;
  18393. }
  18394. }, {
  18395. key: "drawBarShadow",
  18396. value: function drawBarShadow(_ref6) {
  18397. var prevPaths = _ref6.prevPaths,
  18398. currPaths = _ref6.currPaths,
  18399. color = _ref6.color;
  18400. var w = this.w;
  18401. var prevX2 = prevPaths.x,
  18402. prevX1 = prevPaths.x1,
  18403. prevY1 = prevPaths.barYPosition;
  18404. var currX2 = currPaths.x,
  18405. currX1 = currPaths.x1,
  18406. currY1 = currPaths.barYPosition;
  18407. var prevY2 = prevY1 + currPaths.barHeight;
  18408. var graphics = new Graphics(this.barCtx.ctx);
  18409. var utils = new Utils$1();
  18410. 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');
  18411. return graphics.drawPath({
  18412. d: shadowPath,
  18413. fill: utils.shadeColor(0.5, Utils$1.rgb2hex(color)),
  18414. stroke: 'none',
  18415. strokeWidth: 0,
  18416. fillOpacity: 1,
  18417. classes: 'apexcharts-bar-shadows'
  18418. });
  18419. }
  18420. }, {
  18421. key: "getZeroValueEncounters",
  18422. value: function getZeroValueEncounters(_ref7) {
  18423. var _w$globals$columnSeri;
  18424. var i = _ref7.i,
  18425. j = _ref7.j;
  18426. var w = this.w;
  18427. var nonZeroColumns = 0;
  18428. var zeroEncounters = 0;
  18429. var seriesIndices = w.config.plotOptions.bar.horizontal ? w.globals.series.map(function (_, _i) {
  18430. return _i;
  18431. }) : ((_w$globals$columnSeri = w.globals.columnSeries) === null || _w$globals$columnSeri === void 0 ? void 0 : _w$globals$columnSeri.i.map(function (_i) {
  18432. return _i;
  18433. })) || [];
  18434. seriesIndices.forEach(function (_si) {
  18435. var val = w.globals.seriesPercent[_si][j];
  18436. if (val) {
  18437. nonZeroColumns++;
  18438. }
  18439. if (_si < i && val === 0) {
  18440. zeroEncounters++;
  18441. }
  18442. });
  18443. return {
  18444. nonZeroColumns: nonZeroColumns,
  18445. zeroEncounters: zeroEncounters
  18446. };
  18447. }
  18448. }, {
  18449. key: "getGroupIndex",
  18450. value: function getGroupIndex(seriesIndex) {
  18451. var w = this.w;
  18452. // groupIndex is the index of group buckets (group1, group2, ...)
  18453. var groupIndex = w.globals.seriesGroups.findIndex(function (group) {
  18454. return (
  18455. // w.config.series[i].name may be undefined, so use
  18456. // w.globals.seriesNames[i], which has default names for those
  18457. // series. w.globals.seriesGroups[] uses the same default naming.
  18458. group.indexOf(w.globals.seriesNames[seriesIndex]) > -1
  18459. );
  18460. });
  18461. // We need the column groups to be indexable as 0,1,2,... for their
  18462. // positioning relative to each other.
  18463. var cGI = this.barCtx.columnGroupIndices;
  18464. var columnGroupIndex = cGI.indexOf(groupIndex);
  18465. if (columnGroupIndex < 0) {
  18466. cGI.push(groupIndex);
  18467. columnGroupIndex = cGI.length - 1;
  18468. }
  18469. return {
  18470. groupIndex: groupIndex,
  18471. columnGroupIndex: columnGroupIndex
  18472. };
  18473. }
  18474. }]);
  18475. return Helpers;
  18476. }();
  18477. /**
  18478. * ApexCharts Bar Class responsible for drawing both Columns and Bars.
  18479. *
  18480. * @module Bar
  18481. **/
  18482. var Bar = /*#__PURE__*/function () {
  18483. function Bar(ctx, xyRatios) {
  18484. _classCallCheck(this, Bar);
  18485. this.ctx = ctx;
  18486. this.w = ctx.w;
  18487. var w = this.w;
  18488. this.barOptions = w.config.plotOptions.bar;
  18489. this.isHorizontal = this.barOptions.horizontal;
  18490. this.strokeWidth = w.config.stroke.width;
  18491. this.isNullValue = false;
  18492. this.isRangeBar = w.globals.seriesRange.length && this.isHorizontal;
  18493. this.isVerticalGroupedRangeBar = !w.globals.isBarHorizontal && w.globals.seriesRange.length && w.config.plotOptions.bar.rangeBarGroupRows;
  18494. this.isFunnel = this.barOptions.isFunnel;
  18495. this.xyRatios = xyRatios;
  18496. if (this.xyRatios !== null) {
  18497. this.xRatio = xyRatios.xRatio;
  18498. this.yRatio = xyRatios.yRatio;
  18499. this.invertedXRatio = xyRatios.invertedXRatio;
  18500. this.invertedYRatio = xyRatios.invertedYRatio;
  18501. this.baseLineY = xyRatios.baseLineY;
  18502. this.baseLineInvertedY = xyRatios.baseLineInvertedY;
  18503. }
  18504. this.yaxisIndex = 0;
  18505. this.translationsIndex = 0;
  18506. this.seriesLen = 0;
  18507. this.pathArr = [];
  18508. var ser = new Series(this.ctx);
  18509. this.lastActiveBarSerieIndex = ser.getActiveConfigSeriesIndex('desc', ['bar', 'column']);
  18510. this.columnGroupIndices = [];
  18511. var barSeriesIndices = ser.getBarSeriesIndices();
  18512. var coreUtils = new CoreUtils(this.ctx);
  18513. this.stackedSeriesTotals = coreUtils.getStackedSeriesTotals(this.w.config.series.map(function (s, i) {
  18514. return barSeriesIndices.indexOf(i) === -1 ? i : -1;
  18515. }).filter(function (s) {
  18516. return s !== -1;
  18517. }));
  18518. this.barHelpers = new Helpers$1(this);
  18519. }
  18520. /** primary draw method which is called on bar object
  18521. * @memberof Bar
  18522. * @param {array} series - user supplied series values
  18523. * @param {int} seriesIndex - the index by which series will be drawn on the svg
  18524. * @return {node} element which is supplied to parent chart draw method for appending
  18525. **/
  18526. _createClass(Bar, [{
  18527. key: "draw",
  18528. value: function draw(series, seriesIndex) {
  18529. var w = this.w;
  18530. var graphics = new Graphics(this.ctx);
  18531. var coreUtils = new CoreUtils(this.ctx, w);
  18532. series = coreUtils.getLogSeries(series);
  18533. this.series = series;
  18534. this.yRatio = coreUtils.getLogYRatios(this.yRatio);
  18535. this.barHelpers.initVariables(series);
  18536. var ret = graphics.group({
  18537. class: 'apexcharts-bar-series apexcharts-plot-series'
  18538. });
  18539. if (w.config.dataLabels.enabled) {
  18540. if (this.totalItems > this.barOptions.dataLabels.maxItems) {
  18541. console.warn('WARNING: DataLabels are enabled but there are too many to display. This may cause performance issue when rendering - ApexCharts');
  18542. }
  18543. }
  18544. for (var i = 0, bc = 0; i < series.length; i++, bc++) {
  18545. var x = void 0,
  18546. y = void 0,
  18547. xDivision = void 0,
  18548. // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
  18549. yDivision = void 0,
  18550. // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
  18551. zeroH = void 0,
  18552. // zeroH is the baseline where 0 meets y axis
  18553. zeroW = void 0; // zeroW is the baseline where 0 meets x axis
  18554. var yArrj = []; // hold y values of current iterating series
  18555. var xArrj = []; // hold x values of current iterating series
  18556. var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
  18557. var _this$barHelpers$getG = this.barHelpers.getGroupIndex(realIndex),
  18558. columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
  18559. // el to which series will be drawn
  18560. var elSeries = graphics.group({
  18561. class: "apexcharts-series",
  18562. rel: i + 1,
  18563. seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
  18564. 'data:realIndex': realIndex
  18565. });
  18566. this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
  18567. if (series[i].length > 0) {
  18568. this.visibleI = this.visibleI + 1;
  18569. }
  18570. var barHeight = 0;
  18571. var barWidth = 0;
  18572. if (this.yRatio.length > 1) {
  18573. this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex];
  18574. this.translationsIndex = realIndex;
  18575. }
  18576. var translationsIndex = this.translationsIndex;
  18577. this.isReversed = w.config.yaxis[this.yaxisIndex] && w.config.yaxis[this.yaxisIndex].reversed;
  18578. var initPositions = this.barHelpers.initialPositions();
  18579. y = initPositions.y;
  18580. barHeight = initPositions.barHeight;
  18581. yDivision = initPositions.yDivision;
  18582. zeroW = initPositions.zeroW;
  18583. x = initPositions.x;
  18584. barWidth = initPositions.barWidth;
  18585. xDivision = initPositions.xDivision;
  18586. zeroH = initPositions.zeroH;
  18587. if (!this.horizontal) {
  18588. xArrj.push(x + barWidth / 2);
  18589. }
  18590. // eldatalabels
  18591. var elDataLabelsWrap = graphics.group({
  18592. class: 'apexcharts-datalabels',
  18593. 'data:realIndex': realIndex
  18594. });
  18595. w.globals.delayedElements.push({
  18596. el: elDataLabelsWrap.node
  18597. });
  18598. elDataLabelsWrap.node.classList.add('apexcharts-element-hidden');
  18599. var elGoalsMarkers = graphics.group({
  18600. class: 'apexcharts-bar-goals-markers'
  18601. });
  18602. var elBarShadows = graphics.group({
  18603. class: 'apexcharts-bar-shadows'
  18604. });
  18605. w.globals.delayedElements.push({
  18606. el: elBarShadows.node
  18607. });
  18608. elBarShadows.node.classList.add('apexcharts-element-hidden');
  18609. for (var j = 0; j < series[i].length; j++) {
  18610. var strokeWidth = this.barHelpers.getStrokeWidth(i, j, realIndex);
  18611. var paths = null;
  18612. var pathsParams = {
  18613. indexes: {
  18614. i: i,
  18615. j: j,
  18616. realIndex: realIndex,
  18617. translationsIndex: translationsIndex,
  18618. bc: bc
  18619. },
  18620. x: x,
  18621. y: y,
  18622. strokeWidth: strokeWidth,
  18623. elSeries: elSeries
  18624. };
  18625. if (this.isHorizontal) {
  18626. paths = this.drawBarPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
  18627. barHeight: barHeight,
  18628. zeroW: zeroW,
  18629. yDivision: yDivision
  18630. }));
  18631. barWidth = this.series[i][j] / this.invertedYRatio;
  18632. } else {
  18633. paths = this.drawColumnPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
  18634. xDivision: xDivision,
  18635. barWidth: barWidth,
  18636. zeroH: zeroH
  18637. }));
  18638. barHeight = this.series[i][j] / this.yRatio[translationsIndex];
  18639. }
  18640. var pathFill = this.barHelpers.getPathFillColor(series, i, j, realIndex);
  18641. if (this.isFunnel && this.barOptions.isFunnel3d && this.pathArr.length && j > 0) {
  18642. var barShadow = this.barHelpers.drawBarShadow({
  18643. color: typeof pathFill === 'string' && (pathFill === null || pathFill === void 0 ? void 0 : pathFill.indexOf('url')) === -1 ? pathFill : Utils$1.hexToRgba(w.globals.colors[i]),
  18644. prevPaths: this.pathArr[this.pathArr.length - 1],
  18645. currPaths: paths
  18646. });
  18647. if (barShadow) {
  18648. elBarShadows.add(barShadow);
  18649. }
  18650. }
  18651. this.pathArr.push(paths);
  18652. var barGoalLine = this.barHelpers.drawGoalLine({
  18653. barXPosition: paths.barXPosition,
  18654. barYPosition: paths.barYPosition,
  18655. goalX: paths.goalX,
  18656. goalY: paths.goalY,
  18657. barHeight: barHeight,
  18658. barWidth: barWidth
  18659. });
  18660. if (barGoalLine) {
  18661. elGoalsMarkers.add(barGoalLine);
  18662. }
  18663. y = paths.y;
  18664. x = paths.x;
  18665. // push current X
  18666. if (j > 0) {
  18667. xArrj.push(x + barWidth / 2);
  18668. }
  18669. yArrj.push(y);
  18670. this.renderSeries({
  18671. realIndex: realIndex,
  18672. pathFill: pathFill,
  18673. j: j,
  18674. i: i,
  18675. columnGroupIndex: columnGroupIndex,
  18676. pathFrom: paths.pathFrom,
  18677. pathTo: paths.pathTo,
  18678. strokeWidth: strokeWidth,
  18679. elSeries: elSeries,
  18680. x: x,
  18681. y: y,
  18682. series: series,
  18683. barHeight: Math.abs(paths.barHeight ? paths.barHeight : barHeight),
  18684. barWidth: Math.abs(paths.barWidth ? paths.barWidth : barWidth),
  18685. elDataLabelsWrap: elDataLabelsWrap,
  18686. elGoalsMarkers: elGoalsMarkers,
  18687. elBarShadows: elBarShadows,
  18688. visibleSeries: this.visibleI,
  18689. type: 'bar'
  18690. });
  18691. }
  18692. // push all x val arrays into main xArr
  18693. w.globals.seriesXvalues[realIndex] = xArrj;
  18694. w.globals.seriesYvalues[realIndex] = yArrj;
  18695. ret.add(elSeries);
  18696. }
  18697. return ret;
  18698. }
  18699. }, {
  18700. key: "renderSeries",
  18701. value: function renderSeries(_ref) {
  18702. var realIndex = _ref.realIndex,
  18703. pathFill = _ref.pathFill,
  18704. lineFill = _ref.lineFill,
  18705. j = _ref.j,
  18706. i = _ref.i,
  18707. columnGroupIndex = _ref.columnGroupIndex,
  18708. pathFrom = _ref.pathFrom,
  18709. pathTo = _ref.pathTo,
  18710. strokeWidth = _ref.strokeWidth,
  18711. elSeries = _ref.elSeries,
  18712. x = _ref.x,
  18713. y = _ref.y,
  18714. y1 = _ref.y1,
  18715. y2 = _ref.y2,
  18716. series = _ref.series,
  18717. barHeight = _ref.barHeight,
  18718. barWidth = _ref.barWidth,
  18719. barXPosition = _ref.barXPosition,
  18720. barYPosition = _ref.barYPosition,
  18721. elDataLabelsWrap = _ref.elDataLabelsWrap,
  18722. elGoalsMarkers = _ref.elGoalsMarkers,
  18723. elBarShadows = _ref.elBarShadows,
  18724. visibleSeries = _ref.visibleSeries,
  18725. type = _ref.type,
  18726. classes = _ref.classes;
  18727. var w = this.w;
  18728. var graphics = new Graphics(this.ctx);
  18729. if (!lineFill) {
  18730. // if user provided a function in colors, we need to eval here
  18731. // Note: the position of this function logic (ex. stroke: { colors: ["",function(){}] }) i.e array index 1 depicts the realIndex/seriesIndex.
  18732. var fetchColor = function fetchColor(i) {
  18733. var exp = w.config.stroke.colors;
  18734. var c;
  18735. if (Array.isArray(exp) && exp.length > 0) {
  18736. c = exp[i];
  18737. if (!c) c = '';
  18738. if (typeof c === 'function') {
  18739. return c({
  18740. value: w.globals.series[i][j],
  18741. dataPointIndex: j,
  18742. w: w
  18743. });
  18744. }
  18745. }
  18746. return c;
  18747. };
  18748. var checkAvailableColor = typeof w.globals.stroke.colors[realIndex] === 'function' ? fetchColor(realIndex) : w.globals.stroke.colors[realIndex];
  18749. /* fix apexcharts#341 */
  18750. lineFill = this.barOptions.distributed ? w.globals.stroke.colors[j] : checkAvailableColor;
  18751. }
  18752. if (w.config.series[i].data[j] && w.config.series[i].data[j].strokeColor) {
  18753. lineFill = w.config.series[i].data[j].strokeColor;
  18754. }
  18755. if (this.isNullValue) {
  18756. pathFill = 'none';
  18757. }
  18758. var delay = j / w.config.chart.animations.animateGradually.delay * (w.config.chart.animations.speed / w.globals.dataPoints) / 2.4;
  18759. var renderedPath = graphics.renderPaths({
  18760. i: i,
  18761. j: j,
  18762. realIndex: realIndex,
  18763. pathFrom: pathFrom,
  18764. pathTo: pathTo,
  18765. stroke: lineFill,
  18766. strokeWidth: strokeWidth,
  18767. strokeLineCap: w.config.stroke.lineCap,
  18768. fill: pathFill,
  18769. animationDelay: delay,
  18770. initialSpeed: w.config.chart.animations.speed,
  18771. dataChangeSpeed: w.config.chart.animations.dynamicAnimation.speed,
  18772. className: "apexcharts-".concat(type, "-area ").concat(classes),
  18773. chartType: type
  18774. });
  18775. renderedPath.attr('clip-path', "url(#gridRectBarMask".concat(w.globals.cuid, ")"));
  18776. var forecast = w.config.forecastDataPoints;
  18777. if (forecast.count > 0) {
  18778. if (j >= w.globals.dataPoints - forecast.count) {
  18779. renderedPath.node.setAttribute('stroke-dasharray', forecast.dashArray);
  18780. renderedPath.node.setAttribute('stroke-width', forecast.strokeWidth);
  18781. renderedPath.node.setAttribute('fill-opacity', forecast.fillOpacity);
  18782. }
  18783. }
  18784. if (typeof y1 !== 'undefined' && typeof y2 !== 'undefined') {
  18785. renderedPath.attr('data-range-y1', y1);
  18786. renderedPath.attr('data-range-y2', y2);
  18787. }
  18788. var filters = new Filters(this.ctx);
  18789. filters.setSelectionFilter(renderedPath, realIndex, j);
  18790. elSeries.add(renderedPath);
  18791. var barDataLabels = new BarDataLabels(this);
  18792. var dataLabelsObj = barDataLabels.handleBarDataLabels({
  18793. x: x,
  18794. y: y,
  18795. y1: y1,
  18796. y2: y2,
  18797. i: i,
  18798. j: j,
  18799. series: series,
  18800. realIndex: realIndex,
  18801. columnGroupIndex: columnGroupIndex,
  18802. barHeight: barHeight,
  18803. barWidth: barWidth,
  18804. barXPosition: barXPosition,
  18805. barYPosition: barYPosition,
  18806. renderedPath: renderedPath,
  18807. visibleSeries: visibleSeries
  18808. });
  18809. if (dataLabelsObj.dataLabels !== null) {
  18810. elDataLabelsWrap.add(dataLabelsObj.dataLabels);
  18811. }
  18812. if (dataLabelsObj.totalDataLabels) {
  18813. elDataLabelsWrap.add(dataLabelsObj.totalDataLabels);
  18814. }
  18815. elSeries.add(elDataLabelsWrap);
  18816. if (elGoalsMarkers) {
  18817. elSeries.add(elGoalsMarkers);
  18818. }
  18819. if (elBarShadows) {
  18820. elSeries.add(elBarShadows);
  18821. }
  18822. return elSeries;
  18823. }
  18824. }, {
  18825. key: "drawBarPaths",
  18826. value: function drawBarPaths(_ref2) {
  18827. var indexes = _ref2.indexes,
  18828. barHeight = _ref2.barHeight,
  18829. strokeWidth = _ref2.strokeWidth,
  18830. zeroW = _ref2.zeroW,
  18831. x = _ref2.x,
  18832. y = _ref2.y,
  18833. yDivision = _ref2.yDivision,
  18834. elSeries = _ref2.elSeries;
  18835. var w = this.w;
  18836. var i = indexes.i;
  18837. var j = indexes.j;
  18838. var barYPosition;
  18839. if (w.globals.isXNumeric) {
  18840. y = (w.globals.seriesX[i][j] - w.globals.minX) / this.invertedXRatio - barHeight;
  18841. barYPosition = y + barHeight * this.visibleI;
  18842. } else {
  18843. if (w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
  18844. var nonZeroColumns = 0;
  18845. var zeroEncounters = 0;
  18846. w.globals.seriesPercent.forEach(function (_s, _si) {
  18847. if (_s[j]) {
  18848. nonZeroColumns++;
  18849. }
  18850. if (_si < i && _s[j] === 0) {
  18851. zeroEncounters++;
  18852. }
  18853. });
  18854. if (nonZeroColumns > 0) {
  18855. barHeight = this.seriesLen * barHeight / nonZeroColumns;
  18856. }
  18857. barYPosition = y + barHeight * this.visibleI;
  18858. barYPosition -= barHeight * zeroEncounters;
  18859. } else {
  18860. barYPosition = y + barHeight * this.visibleI;
  18861. }
  18862. }
  18863. if (this.isFunnel) {
  18864. zeroW = zeroW - (this.barHelpers.getXForValue(this.series[i][j], zeroW) - zeroW) / 2;
  18865. }
  18866. x = this.barHelpers.getXForValue(this.series[i][j], zeroW);
  18867. var paths = this.barHelpers.getBarpaths({
  18868. barYPosition: barYPosition,
  18869. barHeight: barHeight,
  18870. x1: zeroW,
  18871. x2: x,
  18872. strokeWidth: strokeWidth,
  18873. isReversed: this.isReversed,
  18874. series: this.series,
  18875. realIndex: indexes.realIndex,
  18876. i: i,
  18877. j: j,
  18878. w: w
  18879. });
  18880. if (!w.globals.isXNumeric) {
  18881. y = y + yDivision;
  18882. }
  18883. this.barHelpers.barBackground({
  18884. j: j,
  18885. i: i,
  18886. y1: barYPosition - barHeight * this.visibleI,
  18887. y2: barHeight * this.seriesLen,
  18888. elSeries: elSeries
  18889. });
  18890. return {
  18891. pathTo: paths.pathTo,
  18892. pathFrom: paths.pathFrom,
  18893. x1: zeroW,
  18894. x: x,
  18895. y: y,
  18896. goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j),
  18897. barYPosition: barYPosition,
  18898. barHeight: barHeight
  18899. };
  18900. }
  18901. }, {
  18902. key: "drawColumnPaths",
  18903. value: function drawColumnPaths(_ref3) {
  18904. var indexes = _ref3.indexes,
  18905. x = _ref3.x,
  18906. y = _ref3.y,
  18907. xDivision = _ref3.xDivision,
  18908. barWidth = _ref3.barWidth,
  18909. zeroH = _ref3.zeroH,
  18910. strokeWidth = _ref3.strokeWidth,
  18911. elSeries = _ref3.elSeries;
  18912. var w = this.w;
  18913. var realIndex = indexes.realIndex;
  18914. var translationsIndex = indexes.translationsIndex;
  18915. var i = indexes.i;
  18916. var j = indexes.j;
  18917. var bc = indexes.bc;
  18918. var barXPosition;
  18919. if (w.globals.isXNumeric) {
  18920. var xForNumericX = this.getBarXForNumericXAxis({
  18921. x: x,
  18922. j: j,
  18923. realIndex: realIndex,
  18924. barWidth: barWidth
  18925. });
  18926. x = xForNumericX.x;
  18927. barXPosition = xForNumericX.barXPosition;
  18928. } else {
  18929. if (w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
  18930. var _this$barHelpers$getZ = this.barHelpers.getZeroValueEncounters({
  18931. i: i,
  18932. j: j
  18933. }),
  18934. nonZeroColumns = _this$barHelpers$getZ.nonZeroColumns,
  18935. zeroEncounters = _this$barHelpers$getZ.zeroEncounters;
  18936. if (nonZeroColumns > 0) {
  18937. barWidth = this.seriesLen * barWidth / nonZeroColumns;
  18938. }
  18939. barXPosition = x + barWidth * this.visibleI;
  18940. barXPosition -= barWidth * zeroEncounters;
  18941. } else {
  18942. barXPosition = x + barWidth * this.visibleI;
  18943. }
  18944. }
  18945. y = this.barHelpers.getYForValue(this.series[i][j], zeroH, translationsIndex);
  18946. var paths = this.barHelpers.getColumnPaths({
  18947. barXPosition: barXPosition,
  18948. barWidth: barWidth,
  18949. y1: zeroH,
  18950. y2: y,
  18951. strokeWidth: strokeWidth,
  18952. isReversed: this.isReversed,
  18953. series: this.series,
  18954. realIndex: realIndex,
  18955. i: i,
  18956. j: j,
  18957. w: w
  18958. });
  18959. if (!w.globals.isXNumeric) {
  18960. x = x + xDivision;
  18961. }
  18962. this.barHelpers.barBackground({
  18963. bc: bc,
  18964. j: j,
  18965. i: i,
  18966. x1: barXPosition - strokeWidth / 2 - barWidth * this.visibleI,
  18967. x2: barWidth * this.seriesLen + strokeWidth / 2,
  18968. elSeries: elSeries
  18969. });
  18970. return {
  18971. pathTo: paths.pathTo,
  18972. pathFrom: paths.pathFrom,
  18973. x: x,
  18974. y: y,
  18975. goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
  18976. barXPosition: barXPosition,
  18977. barWidth: barWidth
  18978. };
  18979. }
  18980. }, {
  18981. key: "getBarXForNumericXAxis",
  18982. value: function getBarXForNumericXAxis(_ref4) {
  18983. var x = _ref4.x,
  18984. barWidth = _ref4.barWidth,
  18985. realIndex = _ref4.realIndex,
  18986. j = _ref4.j;
  18987. var w = this.w;
  18988. var sxI = realIndex;
  18989. if (!w.globals.seriesX[realIndex].length) {
  18990. sxI = w.globals.maxValsInArrayIndex;
  18991. }
  18992. if (w.globals.seriesX[sxI][j]) {
  18993. x = (w.globals.seriesX[sxI][j] - w.globals.minX) / this.xRatio - barWidth * this.seriesLen / 2;
  18994. }
  18995. return {
  18996. barXPosition: x + barWidth * this.visibleI,
  18997. x: x
  18998. };
  18999. }
  19000. /** getPreviousPath is a common function for bars/columns which is used to get previous paths when data changes.
  19001. * @memberof Bar
  19002. * @param {int} realIndex - current iterating i
  19003. * @param {int} j - current iterating series's j index
  19004. * @return {string} pathFrom is the string which will be appended in animations
  19005. **/
  19006. }, {
  19007. key: "getPreviousPath",
  19008. value: function getPreviousPath(realIndex, j) {
  19009. var w = this.w;
  19010. var pathFrom;
  19011. for (var pp = 0; pp < w.globals.previousPaths.length; pp++) {
  19012. var gpp = w.globals.previousPaths[pp];
  19013. if (gpp.paths && gpp.paths.length > 0 && parseInt(gpp.realIndex, 10) === parseInt(realIndex, 10)) {
  19014. if (typeof w.globals.previousPaths[pp].paths[j] !== 'undefined') {
  19015. pathFrom = w.globals.previousPaths[pp].paths[j].d;
  19016. }
  19017. }
  19018. }
  19019. return pathFrom;
  19020. }
  19021. }]);
  19022. return Bar;
  19023. }();
  19024. /**
  19025. * ApexCharts BarStacked Class responsible for drawing both Stacked Columns and Bars.
  19026. *
  19027. * @module BarStacked
  19028. * The whole calculation for stacked bar/column is different from normal bar/column,
  19029. * hence it makes sense to derive a new class for it extending most of the props of Parent Bar
  19030. **/
  19031. var BarStacked = /*#__PURE__*/function (_Bar) {
  19032. _inherits(BarStacked, _Bar);
  19033. var _super = _createSuper(BarStacked);
  19034. function BarStacked() {
  19035. _classCallCheck(this, BarStacked);
  19036. return _super.apply(this, arguments);
  19037. }
  19038. _createClass(BarStacked, [{
  19039. key: "draw",
  19040. value: function draw(series, seriesIndex) {
  19041. var _this = this;
  19042. var w = this.w;
  19043. this.graphics = new Graphics(this.ctx);
  19044. this.bar = new Bar(this.ctx, this.xyRatios);
  19045. var coreUtils = new CoreUtils(this.ctx, w);
  19046. series = coreUtils.getLogSeries(series);
  19047. this.yRatio = coreUtils.getLogYRatios(this.yRatio);
  19048. this.barHelpers.initVariables(series);
  19049. if (w.config.chart.stackType === '100%') {
  19050. series = w.globals.comboCharts ? seriesIndex.map(function (_) {
  19051. return w.globals.seriesPercent[_];
  19052. }) : w.globals.seriesPercent.slice();
  19053. }
  19054. this.series = series;
  19055. this.barHelpers.initializeStackedPrevVars(this);
  19056. var ret = this.graphics.group({
  19057. class: 'apexcharts-bar-series apexcharts-plot-series'
  19058. });
  19059. var x = 0;
  19060. var y = 0;
  19061. var _loop = function _loop(i, bc) {
  19062. var xDivision = void 0; // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
  19063. var yDivision = void 0; // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
  19064. var zeroH = void 0; // zeroH is the baseline where 0 meets y axis
  19065. var zeroW = void 0; // zeroW is the baseline where 0 meets x axis
  19066. var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
  19067. var _this$barHelpers$getG = _this.barHelpers.getGroupIndex(realIndex),
  19068. groupIndex = _this$barHelpers$getG.groupIndex,
  19069. columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
  19070. _this.groupCtx = _this[w.globals.seriesGroups[groupIndex]];
  19071. var xArrValues = [];
  19072. var yArrValues = [];
  19073. var translationsIndex = 0;
  19074. if (_this.yRatio.length > 1) {
  19075. _this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0];
  19076. translationsIndex = realIndex;
  19077. }
  19078. _this.isReversed = w.config.yaxis[_this.yaxisIndex] && w.config.yaxis[_this.yaxisIndex].reversed;
  19079. // el to which series will be drawn
  19080. var elSeries = _this.graphics.group({
  19081. class: "apexcharts-series",
  19082. seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
  19083. rel: i + 1,
  19084. 'data:realIndex': realIndex
  19085. });
  19086. _this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
  19087. // eldatalabels
  19088. var elDataLabelsWrap = _this.graphics.group({
  19089. class: 'apexcharts-datalabels',
  19090. 'data:realIndex': realIndex
  19091. });
  19092. var elGoalsMarkers = _this.graphics.group({
  19093. class: 'apexcharts-bar-goals-markers'
  19094. });
  19095. var barHeight = 0;
  19096. var barWidth = 0;
  19097. var initPositions = _this.initialPositions(x, y, xDivision, yDivision, zeroH, zeroW, translationsIndex);
  19098. y = initPositions.y;
  19099. barHeight = initPositions.barHeight;
  19100. yDivision = initPositions.yDivision;
  19101. zeroW = initPositions.zeroW;
  19102. x = initPositions.x;
  19103. barWidth = initPositions.barWidth;
  19104. xDivision = initPositions.xDivision;
  19105. zeroH = initPositions.zeroH;
  19106. w.globals.barHeight = barHeight;
  19107. w.globals.barWidth = barWidth;
  19108. _this.barHelpers.initializeStackedXYVars(_this);
  19109. // where all stack bar disappear after collapsing the first series
  19110. if (_this.groupCtx.prevY.length === 1 && _this.groupCtx.prevY[0].every(function (val) {
  19111. return isNaN(val);
  19112. })) {
  19113. _this.groupCtx.prevY[0] = _this.groupCtx.prevY[0].map(function () {
  19114. return zeroH;
  19115. });
  19116. _this.groupCtx.prevYF[0] = _this.groupCtx.prevYF[0].map(function () {
  19117. return 0;
  19118. });
  19119. }
  19120. for (var j = 0; j < w.globals.dataPoints; j++) {
  19121. var strokeWidth = _this.barHelpers.getStrokeWidth(i, j, realIndex);
  19122. var commonPathOpts = {
  19123. indexes: {
  19124. i: i,
  19125. j: j,
  19126. realIndex: realIndex,
  19127. translationsIndex: translationsIndex,
  19128. bc: bc
  19129. },
  19130. strokeWidth: strokeWidth,
  19131. x: x,
  19132. y: y,
  19133. elSeries: elSeries,
  19134. columnGroupIndex: columnGroupIndex,
  19135. seriesGroup: w.globals.seriesGroups[groupIndex]
  19136. };
  19137. var paths = null;
  19138. if (_this.isHorizontal) {
  19139. paths = _this.drawStackedBarPaths(_objectSpread2(_objectSpread2({}, commonPathOpts), {}, {
  19140. zeroW: zeroW,
  19141. barHeight: barHeight,
  19142. yDivision: yDivision
  19143. }));
  19144. barWidth = _this.series[i][j] / _this.invertedYRatio;
  19145. } else {
  19146. paths = _this.drawStackedColumnPaths(_objectSpread2(_objectSpread2({}, commonPathOpts), {}, {
  19147. xDivision: xDivision,
  19148. barWidth: barWidth,
  19149. zeroH: zeroH
  19150. }));
  19151. barHeight = _this.series[i][j] / _this.yRatio[translationsIndex];
  19152. }
  19153. var barGoalLine = _this.barHelpers.drawGoalLine({
  19154. barXPosition: paths.barXPosition,
  19155. barYPosition: paths.barYPosition,
  19156. goalX: paths.goalX,
  19157. goalY: paths.goalY,
  19158. barHeight: barHeight,
  19159. barWidth: barWidth
  19160. });
  19161. if (barGoalLine) {
  19162. elGoalsMarkers.add(barGoalLine);
  19163. }
  19164. y = paths.y;
  19165. x = paths.x;
  19166. xArrValues.push(x);
  19167. yArrValues.push(y);
  19168. var pathFill = _this.barHelpers.getPathFillColor(series, i, j, realIndex);
  19169. var classes = '';
  19170. if (w.globals.isBarHorizontal) {
  19171. if (_this.barHelpers.arrBorderRadius[realIndex][j] === 'bottom' && w.globals.series[realIndex][j] > 0) {
  19172. classes = 'apexcharts-flip-x';
  19173. }
  19174. } else {
  19175. if (_this.barHelpers.arrBorderRadius[realIndex][j] === 'bottom' && w.globals.series[realIndex][j] > 0) {
  19176. classes = 'apexcharts-flip-y';
  19177. }
  19178. }
  19179. elSeries = _this.renderSeries({
  19180. realIndex: realIndex,
  19181. pathFill: pathFill,
  19182. j: j,
  19183. i: i,
  19184. columnGroupIndex: columnGroupIndex,
  19185. pathFrom: paths.pathFrom,
  19186. pathTo: paths.pathTo,
  19187. strokeWidth: strokeWidth,
  19188. elSeries: elSeries,
  19189. x: x,
  19190. y: y,
  19191. series: series,
  19192. barHeight: barHeight,
  19193. barWidth: barWidth,
  19194. elDataLabelsWrap: elDataLabelsWrap,
  19195. elGoalsMarkers: elGoalsMarkers,
  19196. type: 'bar',
  19197. visibleSeries: columnGroupIndex,
  19198. classes: classes
  19199. });
  19200. }
  19201. // push all x val arrays into main xArr
  19202. w.globals.seriesXvalues[realIndex] = xArrValues;
  19203. w.globals.seriesYvalues[realIndex] = yArrValues;
  19204. // push all current y values array to main PrevY Array
  19205. _this.groupCtx.prevY.push(_this.groupCtx.yArrj);
  19206. _this.groupCtx.prevYF.push(_this.groupCtx.yArrjF);
  19207. _this.groupCtx.prevYVal.push(_this.groupCtx.yArrjVal);
  19208. _this.groupCtx.prevX.push(_this.groupCtx.xArrj);
  19209. _this.groupCtx.prevXF.push(_this.groupCtx.xArrjF);
  19210. _this.groupCtx.prevXVal.push(_this.groupCtx.xArrjVal);
  19211. ret.add(elSeries);
  19212. };
  19213. for (var i = 0, bc = 0; i < series.length; i++, bc++) {
  19214. _loop(i, bc);
  19215. }
  19216. return ret;
  19217. }
  19218. }, {
  19219. key: "initialPositions",
  19220. value: function initialPositions(x, y, xDivision, yDivision, zeroH, zeroW, translationsIndex) {
  19221. var w = this.w;
  19222. var barHeight, barWidth;
  19223. if (this.isHorizontal) {
  19224. // height divided into equal parts
  19225. yDivision = w.globals.gridHeight / w.globals.dataPoints;
  19226. var userBarHeight = w.config.plotOptions.bar.barHeight;
  19227. if (String(userBarHeight).indexOf('%') === -1) {
  19228. barHeight = parseInt(userBarHeight, 10);
  19229. } else {
  19230. barHeight = yDivision * parseInt(userBarHeight, 10) / 100;
  19231. }
  19232. zeroW = w.globals.padHorizontal + (this.isReversed ? w.globals.gridWidth - this.baseLineInvertedY : this.baseLineInvertedY);
  19233. // initial y position is half of barHeight * half of number of Bars
  19234. y = (yDivision - barHeight) / 2;
  19235. } else {
  19236. // width divided into equal parts
  19237. xDivision = w.globals.gridWidth / w.globals.dataPoints;
  19238. barWidth = xDivision;
  19239. var userColumnWidth = w.config.plotOptions.bar.columnWidth;
  19240. if (w.globals.isXNumeric && w.globals.dataPoints > 1) {
  19241. xDivision = w.globals.minXDiff / this.xRatio;
  19242. barWidth = xDivision * parseInt(this.barOptions.columnWidth, 10) / 100;
  19243. } else if (String(userColumnWidth).indexOf('%') === -1) {
  19244. barWidth = parseInt(userColumnWidth, 10);
  19245. } else {
  19246. barWidth *= parseInt(userColumnWidth, 10) / 100;
  19247. }
  19248. if (this.isReversed) {
  19249. zeroH = this.baseLineY[translationsIndex];
  19250. } else {
  19251. zeroH = w.globals.gridHeight - this.baseLineY[translationsIndex];
  19252. }
  19253. // initial x position is the left-most edge of the first bar relative to
  19254. // the left-most side of the grid area.
  19255. x = w.globals.padHorizontal + (xDivision - barWidth) / 2;
  19256. }
  19257. // Up to this point, barWidth is the width that will accommodate all bars
  19258. // at each datapoint or category.
  19259. // The crude subdivision here assumes the series within each group are
  19260. // stacked. If there is no stacking then the barWidth/barHeight is
  19261. // further divided later by the number of series in the group. So, eg, two
  19262. // groups of three series would become six bars side-by-side unstacked,
  19263. // or two bars stacked.
  19264. var subDivisions = w.globals.barGroups.length || 1;
  19265. return {
  19266. x: x,
  19267. y: y,
  19268. yDivision: yDivision,
  19269. xDivision: xDivision,
  19270. barHeight: barHeight / subDivisions,
  19271. barWidth: barWidth / subDivisions,
  19272. zeroH: zeroH,
  19273. zeroW: zeroW
  19274. };
  19275. }
  19276. }, {
  19277. key: "drawStackedBarPaths",
  19278. value: function drawStackedBarPaths(_ref) {
  19279. var indexes = _ref.indexes,
  19280. barHeight = _ref.barHeight,
  19281. strokeWidth = _ref.strokeWidth,
  19282. zeroW = _ref.zeroW,
  19283. x = _ref.x,
  19284. y = _ref.y,
  19285. columnGroupIndex = _ref.columnGroupIndex,
  19286. seriesGroup = _ref.seriesGroup,
  19287. yDivision = _ref.yDivision,
  19288. elSeries = _ref.elSeries;
  19289. var w = this.w;
  19290. var barYPosition = y + columnGroupIndex * barHeight;
  19291. var barXPosition;
  19292. var i = indexes.i;
  19293. var j = indexes.j;
  19294. var realIndex = indexes.realIndex;
  19295. var translationsIndex = indexes.translationsIndex;
  19296. var prevBarW = 0;
  19297. for (var k = 0; k < this.groupCtx.prevXF.length; k++) {
  19298. prevBarW = prevBarW + this.groupCtx.prevXF[k][j];
  19299. }
  19300. var gsi = i; // an index to keep track of the series inside a group
  19301. gsi = seriesGroup.indexOf(w.config.series[realIndex].name);
  19302. if (gsi > 0) {
  19303. var bXP = zeroW;
  19304. if (this.groupCtx.prevXVal[gsi - 1][j] < 0) {
  19305. bXP = this.series[i][j] >= 0 ? this.groupCtx.prevX[gsi - 1][j] + prevBarW - (this.isReversed ? prevBarW : 0) * 2 : this.groupCtx.prevX[gsi - 1][j];
  19306. } else if (this.groupCtx.prevXVal[gsi - 1][j] >= 0) {
  19307. bXP = this.series[i][j] >= 0 ? this.groupCtx.prevX[gsi - 1][j] : this.groupCtx.prevX[gsi - 1][j] - prevBarW + (this.isReversed ? prevBarW : 0) * 2;
  19308. }
  19309. barXPosition = bXP;
  19310. } else {
  19311. // the first series will not have prevX values
  19312. barXPosition = zeroW;
  19313. }
  19314. if (this.series[i][j] === null) {
  19315. x = barXPosition;
  19316. } else {
  19317. x = barXPosition + this.series[i][j] / this.invertedYRatio - (this.isReversed ? this.series[i][j] / this.invertedYRatio : 0) * 2;
  19318. }
  19319. var paths = this.barHelpers.getBarpaths({
  19320. barYPosition: barYPosition,
  19321. barHeight: barHeight,
  19322. x1: barXPosition,
  19323. x2: x,
  19324. strokeWidth: strokeWidth,
  19325. isReversed: this.isReversed,
  19326. series: this.series,
  19327. realIndex: indexes.realIndex,
  19328. seriesGroup: seriesGroup,
  19329. i: i,
  19330. j: j,
  19331. w: w
  19332. });
  19333. this.barHelpers.barBackground({
  19334. j: j,
  19335. i: i,
  19336. y1: barYPosition,
  19337. y2: barHeight,
  19338. elSeries: elSeries
  19339. });
  19340. y = y + yDivision;
  19341. return {
  19342. pathTo: paths.pathTo,
  19343. pathFrom: paths.pathFrom,
  19344. goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j, translationsIndex),
  19345. barXPosition: barXPosition,
  19346. barYPosition: barYPosition,
  19347. x: x,
  19348. y: y
  19349. };
  19350. }
  19351. }, {
  19352. key: "drawStackedColumnPaths",
  19353. value: function drawStackedColumnPaths(_ref2) {
  19354. var indexes = _ref2.indexes,
  19355. x = _ref2.x,
  19356. y = _ref2.y,
  19357. xDivision = _ref2.xDivision,
  19358. barWidth = _ref2.barWidth,
  19359. zeroH = _ref2.zeroH,
  19360. columnGroupIndex = _ref2.columnGroupIndex,
  19361. seriesGroup = _ref2.seriesGroup,
  19362. elSeries = _ref2.elSeries;
  19363. var w = this.w;
  19364. var i = indexes.i;
  19365. var j = indexes.j;
  19366. var bc = indexes.bc;
  19367. var realIndex = indexes.realIndex;
  19368. var translationsIndex = indexes.translationsIndex;
  19369. if (w.globals.isXNumeric) {
  19370. var seriesVal = w.globals.seriesX[realIndex][j];
  19371. if (!seriesVal) seriesVal = 0;
  19372. // TODO: move the barWidth factor to barXPosition
  19373. x = (seriesVal - w.globals.minX) / this.xRatio - barWidth / 2 * w.globals.barGroups.length;
  19374. }
  19375. var barXPosition = x + columnGroupIndex * barWidth;
  19376. var barYPosition;
  19377. var prevBarH = 0;
  19378. for (var k = 0; k < this.groupCtx.prevYF.length; k++) {
  19379. // fix issue #1215
  19380. // in case where this.groupCtx.prevYF[k][j] is NaN, use 0 instead
  19381. prevBarH = prevBarH + (!isNaN(this.groupCtx.prevYF[k][j]) ? this.groupCtx.prevYF[k][j] : 0);
  19382. }
  19383. var gsi = i; // an index to keep track of the series inside a group
  19384. if (seriesGroup) {
  19385. gsi = seriesGroup.indexOf(w.globals.seriesNames[realIndex]);
  19386. }
  19387. if (gsi > 0 && !w.globals.isXNumeric || gsi > 0 && w.globals.isXNumeric && w.globals.seriesX[realIndex - 1][j] === w.globals.seriesX[realIndex][j]) {
  19388. var _this$groupCtx$prevYF;
  19389. var bYP;
  19390. var prevYValue;
  19391. var p = Math.min(this.yRatio.length + 1, realIndex + 1);
  19392. if (this.groupCtx.prevY[gsi - 1] !== undefined && this.groupCtx.prevY[gsi - 1].length) {
  19393. for (var ii = 1; ii < p; ii++) {
  19394. var _this$groupCtx$prevY;
  19395. if (!isNaN((_this$groupCtx$prevY = this.groupCtx.prevY[gsi - ii]) === null || _this$groupCtx$prevY === void 0 ? void 0 : _this$groupCtx$prevY[j])) {
  19396. // find the previous available value to give prevYValue
  19397. prevYValue = this.groupCtx.prevY[gsi - ii][j];
  19398. // if found it, break the loop
  19399. break;
  19400. }
  19401. }
  19402. }
  19403. for (var _ii = 1; _ii < p; _ii++) {
  19404. var _this$groupCtx$prevYV, _this$groupCtx$prevYV2;
  19405. // find the previous available value(non-NaN) to give bYP
  19406. if (((_this$groupCtx$prevYV = this.groupCtx.prevYVal[gsi - _ii]) === null || _this$groupCtx$prevYV === void 0 ? void 0 : _this$groupCtx$prevYV[j]) < 0) {
  19407. bYP = this.series[i][j] >= 0 ? prevYValue - prevBarH + (this.isReversed ? prevBarH : 0) * 2 : prevYValue;
  19408. // found it? break the loop
  19409. break;
  19410. } else if (((_this$groupCtx$prevYV2 = this.groupCtx.prevYVal[gsi - _ii]) === null || _this$groupCtx$prevYV2 === void 0 ? void 0 : _this$groupCtx$prevYV2[j]) >= 0) {
  19411. bYP = this.series[i][j] >= 0 ? prevYValue : prevYValue + prevBarH - (this.isReversed ? prevBarH : 0) * 2;
  19412. // found it? break the loop
  19413. break;
  19414. }
  19415. }
  19416. if (typeof bYP === 'undefined') bYP = w.globals.gridHeight;
  19417. // if this.prevYF[0] is all 0 resulted from line #486
  19418. // AND every arr starting from the second only contains NaN
  19419. if ((_this$groupCtx$prevYF = this.groupCtx.prevYF[0]) !== null && _this$groupCtx$prevYF !== void 0 && _this$groupCtx$prevYF.every(function (val) {
  19420. return val === 0;
  19421. }) && this.groupCtx.prevYF.slice(1, gsi).every(function (arr) {
  19422. return arr.every(function (val) {
  19423. return isNaN(val);
  19424. });
  19425. })) {
  19426. barYPosition = zeroH;
  19427. } else {
  19428. // Nothing special
  19429. barYPosition = bYP;
  19430. }
  19431. } else {
  19432. // the first series will not have prevY values, also if the prev index's
  19433. // series X doesn't matches the current index's series X, then start from
  19434. // zero
  19435. barYPosition = zeroH;
  19436. }
  19437. if (this.series[i][j]) {
  19438. y = barYPosition - this.series[i][j] / this.yRatio[translationsIndex] + (this.isReversed ? this.series[i][j] / this.yRatio[translationsIndex] : 0) * 2;
  19439. } else {
  19440. // fixes #3610
  19441. y = barYPosition;
  19442. }
  19443. var paths = this.barHelpers.getColumnPaths({
  19444. barXPosition: barXPosition,
  19445. barWidth: barWidth,
  19446. y1: barYPosition,
  19447. y2: y,
  19448. yRatio: this.yRatio[translationsIndex],
  19449. strokeWidth: this.strokeWidth,
  19450. isReversed: this.isReversed,
  19451. series: this.series,
  19452. seriesGroup: seriesGroup,
  19453. realIndex: indexes.realIndex,
  19454. i: i,
  19455. j: j,
  19456. w: w
  19457. });
  19458. this.barHelpers.barBackground({
  19459. bc: bc,
  19460. j: j,
  19461. i: i,
  19462. x1: barXPosition,
  19463. x2: barWidth,
  19464. elSeries: elSeries
  19465. });
  19466. return {
  19467. pathTo: paths.pathTo,
  19468. pathFrom: paths.pathFrom,
  19469. goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j),
  19470. barXPosition: barXPosition,
  19471. x: w.globals.isXNumeric ? x : x + xDivision,
  19472. y: y
  19473. };
  19474. }
  19475. }]);
  19476. return BarStacked;
  19477. }(Bar);
  19478. /**
  19479. * ApexCharts BoxCandleStick Class responsible for drawing both Stacked Columns and Bars.
  19480. *
  19481. * @module BoxCandleStick
  19482. **/
  19483. var BoxCandleStick = /*#__PURE__*/function (_Bar) {
  19484. _inherits(BoxCandleStick, _Bar);
  19485. var _super = _createSuper(BoxCandleStick);
  19486. function BoxCandleStick() {
  19487. _classCallCheck(this, BoxCandleStick);
  19488. return _super.apply(this, arguments);
  19489. }
  19490. _createClass(BoxCandleStick, [{
  19491. key: "draw",
  19492. value: function draw(series, ctype, seriesIndex) {
  19493. var _this = this;
  19494. var w = this.w;
  19495. var graphics = new Graphics(this.ctx);
  19496. var type = w.globals.comboCharts ? ctype : w.config.chart.type;
  19497. var fill = new Fill(this.ctx);
  19498. this.candlestickOptions = this.w.config.plotOptions.candlestick;
  19499. this.boxOptions = this.w.config.plotOptions.boxPlot;
  19500. this.isHorizontal = w.config.plotOptions.bar.horizontal;
  19501. var coreUtils = new CoreUtils(this.ctx, w);
  19502. series = coreUtils.getLogSeries(series);
  19503. this.series = series;
  19504. this.yRatio = coreUtils.getLogYRatios(this.yRatio);
  19505. this.barHelpers.initVariables(series);
  19506. var ret = graphics.group({
  19507. class: "apexcharts-".concat(type, "-series apexcharts-plot-series")
  19508. });
  19509. var _loop = function _loop(i) {
  19510. _this.isBoxPlot = w.config.chart.type === 'boxPlot' || w.config.series[i].type === 'boxPlot';
  19511. var x = void 0,
  19512. y = void 0,
  19513. xDivision = void 0,
  19514. // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
  19515. yDivision = void 0,
  19516. // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
  19517. zeroH = void 0,
  19518. // zeroH is the baseline where 0 meets y axis
  19519. zeroW = void 0; // zeroW is the baseline where 0 meets x axis
  19520. var yArrj = []; // hold y values of current iterating series
  19521. var xArrj = []; // hold x values of current iterating series
  19522. var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
  19523. // As BoxCandleStick derives from Bar, we need this to render.
  19524. var _this$barHelpers$getG = _this.barHelpers.getGroupIndex(realIndex),
  19525. columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
  19526. // el to which series will be drawn
  19527. var elSeries = graphics.group({
  19528. class: "apexcharts-series",
  19529. seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
  19530. rel: i + 1,
  19531. 'data:realIndex': realIndex
  19532. });
  19533. _this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
  19534. if (series[i].length > 0) {
  19535. _this.visibleI = _this.visibleI + 1;
  19536. }
  19537. var barHeight = 0;
  19538. var barWidth = 0;
  19539. var translationsIndex = 0;
  19540. if (_this.yRatio.length > 1) {
  19541. _this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0];
  19542. translationsIndex = realIndex;
  19543. }
  19544. var initPositions = _this.barHelpers.initialPositions();
  19545. y = initPositions.y;
  19546. barHeight = initPositions.barHeight;
  19547. yDivision = initPositions.yDivision;
  19548. zeroW = initPositions.zeroW;
  19549. x = initPositions.x;
  19550. barWidth = initPositions.barWidth;
  19551. xDivision = initPositions.xDivision;
  19552. zeroH = initPositions.zeroH;
  19553. xArrj.push(x + barWidth / 2);
  19554. // eldatalabels
  19555. var elDataLabelsWrap = graphics.group({
  19556. class: 'apexcharts-datalabels',
  19557. 'data:realIndex': realIndex
  19558. });
  19559. var _loop2 = function _loop2(j) {
  19560. var strokeWidth = _this.barHelpers.getStrokeWidth(i, j, realIndex);
  19561. var paths = null;
  19562. var pathsParams = {
  19563. indexes: {
  19564. i: i,
  19565. j: j,
  19566. realIndex: realIndex,
  19567. translationsIndex: translationsIndex
  19568. },
  19569. x: x,
  19570. y: y,
  19571. strokeWidth: strokeWidth,
  19572. elSeries: elSeries
  19573. };
  19574. if (_this.isHorizontal) {
  19575. paths = _this.drawHorizontalBoxPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
  19576. yDivision: yDivision,
  19577. barHeight: barHeight,
  19578. zeroW: zeroW
  19579. }));
  19580. } else {
  19581. paths = _this.drawVerticalBoxPaths(_objectSpread2(_objectSpread2({}, pathsParams), {}, {
  19582. xDivision: xDivision,
  19583. barWidth: barWidth,
  19584. zeroH: zeroH
  19585. }));
  19586. }
  19587. y = paths.y;
  19588. x = paths.x;
  19589. // push current X
  19590. if (j > 0) {
  19591. xArrj.push(x + barWidth / 2);
  19592. }
  19593. yArrj.push(y);
  19594. paths.pathTo.forEach(function (pathTo, pi) {
  19595. var lineFill = !_this.isBoxPlot && _this.candlestickOptions.wick.useFillColor ? paths.color[pi] : w.globals.stroke.colors[i];
  19596. var pathFill = fill.fillPath({
  19597. seriesNumber: realIndex,
  19598. dataPointIndex: j,
  19599. color: paths.color[pi],
  19600. value: series[i][j]
  19601. });
  19602. _this.renderSeries({
  19603. realIndex: realIndex,
  19604. pathFill: pathFill,
  19605. lineFill: lineFill,
  19606. j: j,
  19607. i: i,
  19608. pathFrom: paths.pathFrom,
  19609. pathTo: pathTo,
  19610. strokeWidth: strokeWidth,
  19611. elSeries: elSeries,
  19612. x: x,
  19613. y: y,
  19614. series: series,
  19615. columnGroupIndex: columnGroupIndex,
  19616. barHeight: barHeight,
  19617. barWidth: barWidth,
  19618. elDataLabelsWrap: elDataLabelsWrap,
  19619. visibleSeries: _this.visibleI,
  19620. type: w.config.chart.type
  19621. });
  19622. });
  19623. };
  19624. for (var j = 0; j < w.globals.dataPoints; j++) {
  19625. _loop2(j);
  19626. }
  19627. // push all x val arrays into main xArr
  19628. w.globals.seriesXvalues[realIndex] = xArrj;
  19629. w.globals.seriesYvalues[realIndex] = yArrj;
  19630. ret.add(elSeries);
  19631. };
  19632. for (var i = 0; i < series.length; i++) {
  19633. _loop(i);
  19634. }
  19635. return ret;
  19636. }
  19637. }, {
  19638. key: "drawVerticalBoxPaths",
  19639. value: function drawVerticalBoxPaths(_ref) {
  19640. var indexes = _ref.indexes,
  19641. x = _ref.x;
  19642. _ref.y;
  19643. var xDivision = _ref.xDivision,
  19644. barWidth = _ref.barWidth,
  19645. zeroH = _ref.zeroH,
  19646. strokeWidth = _ref.strokeWidth;
  19647. var w = this.w;
  19648. var graphics = new Graphics(this.ctx);
  19649. var i = indexes.i;
  19650. var j = indexes.j;
  19651. var isPositive = true;
  19652. var colorPos = w.config.plotOptions.candlestick.colors.upward;
  19653. var colorNeg = w.config.plotOptions.candlestick.colors.downward;
  19654. var color = '';
  19655. if (this.isBoxPlot) {
  19656. color = [this.boxOptions.colors.lower, this.boxOptions.colors.upper];
  19657. }
  19658. var yRatio = this.yRatio[indexes.translationsIndex];
  19659. var realIndex = indexes.realIndex;
  19660. var ohlc = this.getOHLCValue(realIndex, j);
  19661. var l1 = zeroH;
  19662. var l2 = zeroH;
  19663. if (ohlc.o > ohlc.c) {
  19664. isPositive = false;
  19665. }
  19666. var y1 = Math.min(ohlc.o, ohlc.c);
  19667. var y2 = Math.max(ohlc.o, ohlc.c);
  19668. var m = ohlc.m;
  19669. if (w.globals.isXNumeric) {
  19670. x = (w.globals.seriesX[realIndex][j] - w.globals.minX) / this.xRatio - barWidth / 2;
  19671. }
  19672. var barXPosition = x + barWidth * this.visibleI;
  19673. if (typeof this.series[i][j] === 'undefined' || this.series[i][j] === null) {
  19674. y1 = zeroH;
  19675. y2 = zeroH;
  19676. } else {
  19677. y1 = zeroH - y1 / yRatio;
  19678. y2 = zeroH - y2 / yRatio;
  19679. l1 = zeroH - ohlc.h / yRatio;
  19680. l2 = zeroH - ohlc.l / yRatio;
  19681. m = zeroH - ohlc.m / yRatio;
  19682. }
  19683. var pathTo = graphics.move(barXPosition, zeroH);
  19684. var pathFrom = graphics.move(barXPosition + barWidth / 2, y1);
  19685. if (w.globals.previousPaths.length > 0) {
  19686. pathFrom = this.getPreviousPath(realIndex, j, true);
  19687. }
  19688. if (this.isBoxPlot) {
  19689. 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'];
  19690. } else {
  19691. // candlestick
  19692. 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)];
  19693. }
  19694. pathFrom = pathFrom + graphics.move(barXPosition, y1);
  19695. if (!w.globals.isXNumeric) {
  19696. x = x + xDivision;
  19697. }
  19698. return {
  19699. pathTo: pathTo,
  19700. pathFrom: pathFrom,
  19701. x: x,
  19702. y: y2,
  19703. barXPosition: barXPosition,
  19704. color: this.isBoxPlot ? color : isPositive ? [colorPos] : [colorNeg]
  19705. };
  19706. }
  19707. }, {
  19708. key: "drawHorizontalBoxPaths",
  19709. value: function drawHorizontalBoxPaths(_ref2) {
  19710. var indexes = _ref2.indexes;
  19711. _ref2.x;
  19712. var y = _ref2.y,
  19713. yDivision = _ref2.yDivision,
  19714. barHeight = _ref2.barHeight,
  19715. zeroW = _ref2.zeroW,
  19716. strokeWidth = _ref2.strokeWidth;
  19717. var w = this.w;
  19718. var graphics = new Graphics(this.ctx);
  19719. var i = indexes.i;
  19720. var j = indexes.j;
  19721. var color = this.boxOptions.colors.lower;
  19722. if (this.isBoxPlot) {
  19723. color = [this.boxOptions.colors.lower, this.boxOptions.colors.upper];
  19724. }
  19725. var yRatio = this.invertedYRatio;
  19726. var realIndex = indexes.realIndex;
  19727. var ohlc = this.getOHLCValue(realIndex, j);
  19728. var l1 = zeroW;
  19729. var l2 = zeroW;
  19730. var x1 = Math.min(ohlc.o, ohlc.c);
  19731. var x2 = Math.max(ohlc.o, ohlc.c);
  19732. var m = ohlc.m;
  19733. if (w.globals.isXNumeric) {
  19734. y = (w.globals.seriesX[realIndex][j] - w.globals.minX) / this.invertedXRatio - barHeight / 2;
  19735. }
  19736. var barYPosition = y + barHeight * this.visibleI;
  19737. if (typeof this.series[i][j] === 'undefined' || this.series[i][j] === null) {
  19738. x1 = zeroW;
  19739. x2 = zeroW;
  19740. } else {
  19741. x1 = zeroW + x1 / yRatio;
  19742. x2 = zeroW + x2 / yRatio;
  19743. l1 = zeroW + ohlc.h / yRatio;
  19744. l2 = zeroW + ohlc.l / yRatio;
  19745. m = zeroW + ohlc.m / yRatio;
  19746. }
  19747. var pathTo = graphics.move(zeroW, barYPosition);
  19748. var pathFrom = graphics.move(x1, barYPosition + barHeight / 2);
  19749. if (w.globals.previousPaths.length > 0) {
  19750. pathFrom = this.getPreviousPath(realIndex, j, true);
  19751. }
  19752. 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'];
  19753. pathFrom = pathFrom + graphics.move(x1, barYPosition);
  19754. if (!w.globals.isXNumeric) {
  19755. y = y + yDivision;
  19756. }
  19757. return {
  19758. pathTo: pathTo,
  19759. pathFrom: pathFrom,
  19760. x: x2,
  19761. y: y,
  19762. barYPosition: barYPosition,
  19763. color: color
  19764. };
  19765. }
  19766. }, {
  19767. key: "getOHLCValue",
  19768. value: function getOHLCValue(i, j) {
  19769. var w = this.w;
  19770. return {
  19771. o: this.isBoxPlot ? w.globals.seriesCandleH[i][j] : w.globals.seriesCandleO[i][j],
  19772. h: this.isBoxPlot ? w.globals.seriesCandleO[i][j] : w.globals.seriesCandleH[i][j],
  19773. m: w.globals.seriesCandleM[i][j],
  19774. l: this.isBoxPlot ? w.globals.seriesCandleC[i][j] : w.globals.seriesCandleL[i][j],
  19775. c: this.isBoxPlot ? w.globals.seriesCandleL[i][j] : w.globals.seriesCandleC[i][j]
  19776. };
  19777. }
  19778. }]);
  19779. return BoxCandleStick;
  19780. }(Bar);
  19781. var TreemapHelpers = /*#__PURE__*/function () {
  19782. function TreemapHelpers(ctx) {
  19783. _classCallCheck(this, TreemapHelpers);
  19784. this.ctx = ctx;
  19785. this.w = ctx.w;
  19786. }
  19787. _createClass(TreemapHelpers, [{
  19788. key: "checkColorRange",
  19789. value: function checkColorRange() {
  19790. var w = this.w;
  19791. var negRange = false;
  19792. var chartOpts = w.config.plotOptions[w.config.chart.type];
  19793. if (chartOpts.colorScale.ranges.length > 0) {
  19794. chartOpts.colorScale.ranges.map(function (range, index) {
  19795. if (range.from <= 0) {
  19796. negRange = true;
  19797. }
  19798. });
  19799. }
  19800. return negRange;
  19801. }
  19802. }, {
  19803. key: "getShadeColor",
  19804. value: function getShadeColor(chartType, i, j, negRange) {
  19805. var w = this.w;
  19806. var colorShadePercent = 1;
  19807. var shadeIntensity = w.config.plotOptions[chartType].shadeIntensity;
  19808. var colorProps = this.determineColor(chartType, i, j);
  19809. if (w.globals.hasNegs || negRange) {
  19810. if (w.config.plotOptions[chartType].reverseNegativeShade) {
  19811. if (colorProps.percent < 0) {
  19812. colorShadePercent = colorProps.percent / 100 * (shadeIntensity * 1.25);
  19813. } else {
  19814. colorShadePercent = (1 - colorProps.percent / 100) * (shadeIntensity * 1.25);
  19815. }
  19816. } else {
  19817. if (colorProps.percent <= 0) {
  19818. colorShadePercent = 1 - (1 + colorProps.percent / 100) * shadeIntensity;
  19819. } else {
  19820. colorShadePercent = (1 - colorProps.percent / 100) * shadeIntensity;
  19821. }
  19822. }
  19823. } else {
  19824. colorShadePercent = 1 - colorProps.percent / 100;
  19825. if (chartType === 'treemap') {
  19826. colorShadePercent = (1 - colorProps.percent / 100) * (shadeIntensity * 1.25);
  19827. }
  19828. }
  19829. var color = colorProps.color;
  19830. var utils = new Utils$1();
  19831. if (w.config.plotOptions[chartType].enableShades) {
  19832. // The shadeColor function may return either an RGB or a hex color value
  19833. // However, hexToRgba requires the input to be in hex format
  19834. // The ternary operator checks if the color is in RGB format, and if so, converts it to hex
  19835. if (this.w.config.theme.mode === 'dark') {
  19836. var shadeColor = utils.shadeColor(colorShadePercent * -1, colorProps.color);
  19837. color = Utils$1.hexToRgba(Utils$1.isColorHex(shadeColor) ? shadeColor : Utils$1.rgb2hex(shadeColor), w.config.fill.opacity);
  19838. } else {
  19839. var _shadeColor = utils.shadeColor(colorShadePercent, colorProps.color);
  19840. color = Utils$1.hexToRgba(Utils$1.isColorHex(_shadeColor) ? _shadeColor : Utils$1.rgb2hex(_shadeColor), w.config.fill.opacity);
  19841. }
  19842. }
  19843. return {
  19844. color: color,
  19845. colorProps: colorProps
  19846. };
  19847. }
  19848. }, {
  19849. key: "determineColor",
  19850. value: function determineColor(chartType, i, j) {
  19851. var w = this.w;
  19852. var val = w.globals.series[i][j];
  19853. var chartOpts = w.config.plotOptions[chartType];
  19854. var seriesNumber = chartOpts.colorScale.inverse ? j : i;
  19855. if (chartOpts.distributed && w.config.chart.type === 'treemap') {
  19856. seriesNumber = j;
  19857. }
  19858. var color = w.globals.colors[seriesNumber];
  19859. var foreColor = null;
  19860. var min = Math.min.apply(Math, _toConsumableArray(w.globals.series[i]));
  19861. var max = Math.max.apply(Math, _toConsumableArray(w.globals.series[i]));
  19862. if (!chartOpts.distributed && chartType === 'heatmap') {
  19863. min = w.globals.minY;
  19864. max = w.globals.maxY;
  19865. }
  19866. if (typeof chartOpts.colorScale.min !== 'undefined') {
  19867. min = chartOpts.colorScale.min < w.globals.minY ? chartOpts.colorScale.min : w.globals.minY;
  19868. max = chartOpts.colorScale.max > w.globals.maxY ? chartOpts.colorScale.max : w.globals.maxY;
  19869. }
  19870. var total = Math.abs(max) + Math.abs(min);
  19871. var percent = 100 * val / (total === 0 ? total - 0.000001 : total);
  19872. if (chartOpts.colorScale.ranges.length > 0) {
  19873. var colorRange = chartOpts.colorScale.ranges;
  19874. colorRange.map(function (range, index) {
  19875. if (val >= range.from && val <= range.to) {
  19876. color = range.color;
  19877. foreColor = range.foreColor ? range.foreColor : null;
  19878. min = range.from;
  19879. max = range.to;
  19880. var rTotal = Math.abs(max) + Math.abs(min);
  19881. percent = 100 * val / (rTotal === 0 ? rTotal - 0.000001 : rTotal);
  19882. }
  19883. });
  19884. }
  19885. return {
  19886. color: color,
  19887. foreColor: foreColor,
  19888. percent: percent
  19889. };
  19890. }
  19891. }, {
  19892. key: "calculateDataLabels",
  19893. value: function calculateDataLabels(_ref) {
  19894. var text = _ref.text,
  19895. x = _ref.x,
  19896. y = _ref.y,
  19897. i = _ref.i,
  19898. j = _ref.j,
  19899. colorProps = _ref.colorProps,
  19900. fontSize = _ref.fontSize;
  19901. var w = this.w;
  19902. var dataLabelsConfig = w.config.dataLabels;
  19903. var graphics = new Graphics(this.ctx);
  19904. var dataLabels = new DataLabels(this.ctx);
  19905. var elDataLabelsWrap = null;
  19906. if (dataLabelsConfig.enabled) {
  19907. elDataLabelsWrap = graphics.group({
  19908. class: 'apexcharts-data-labels'
  19909. });
  19910. var offX = dataLabelsConfig.offsetX;
  19911. var offY = dataLabelsConfig.offsetY;
  19912. var dataLabelsX = x + offX;
  19913. var dataLabelsY = y + parseFloat(dataLabelsConfig.style.fontSize) / 3 + offY;
  19914. dataLabels.plotDataLabelsText({
  19915. x: dataLabelsX,
  19916. y: dataLabelsY,
  19917. text: text,
  19918. i: i,
  19919. j: j,
  19920. color: colorProps.foreColor,
  19921. parent: elDataLabelsWrap,
  19922. fontSize: fontSize,
  19923. dataLabelsConfig: dataLabelsConfig
  19924. });
  19925. }
  19926. return elDataLabelsWrap;
  19927. }
  19928. }, {
  19929. key: "addListeners",
  19930. value: function addListeners(elRect) {
  19931. var graphics = new Graphics(this.ctx);
  19932. elRect.node.addEventListener('mouseenter', graphics.pathMouseEnter.bind(this, elRect));
  19933. elRect.node.addEventListener('mouseleave', graphics.pathMouseLeave.bind(this, elRect));
  19934. elRect.node.addEventListener('mousedown', graphics.pathMouseDown.bind(this, elRect));
  19935. }
  19936. }]);
  19937. return TreemapHelpers;
  19938. }();
  19939. /**
  19940. * ApexCharts HeatMap Class.
  19941. * @module HeatMap
  19942. **/
  19943. var HeatMap = /*#__PURE__*/function () {
  19944. function HeatMap(ctx, xyRatios) {
  19945. _classCallCheck(this, HeatMap);
  19946. this.ctx = ctx;
  19947. this.w = ctx.w;
  19948. this.xRatio = xyRatios.xRatio;
  19949. this.yRatio = xyRatios.yRatio;
  19950. this.dynamicAnim = this.w.config.chart.animations.dynamicAnimation;
  19951. this.helpers = new TreemapHelpers(ctx);
  19952. this.rectRadius = this.w.config.plotOptions.heatmap.radius;
  19953. this.strokeWidth = this.w.config.stroke.show ? this.w.config.stroke.width : 0;
  19954. }
  19955. _createClass(HeatMap, [{
  19956. key: "draw",
  19957. value: function draw(series) {
  19958. var w = this.w;
  19959. var graphics = new Graphics(this.ctx);
  19960. var ret = graphics.group({
  19961. class: 'apexcharts-heatmap'
  19962. });
  19963. ret.attr('clip-path', "url(#gridRectMask".concat(w.globals.cuid, ")"));
  19964. // width divided into equal parts
  19965. var xDivision = w.globals.gridWidth / w.globals.dataPoints;
  19966. var yDivision = w.globals.gridHeight / w.globals.series.length;
  19967. var y1 = 0;
  19968. var rev = false;
  19969. this.negRange = this.helpers.checkColorRange();
  19970. var heatSeries = series.slice();
  19971. if (w.config.yaxis[0].reversed) {
  19972. rev = true;
  19973. heatSeries.reverse();
  19974. }
  19975. for (var i = rev ? 0 : heatSeries.length - 1; rev ? i < heatSeries.length : i >= 0; rev ? i++ : i--) {
  19976. // el to which series will be drawn
  19977. var elSeries = graphics.group({
  19978. class: "apexcharts-series apexcharts-heatmap-series",
  19979. seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
  19980. rel: i + 1,
  19981. 'data:realIndex': i
  19982. });
  19983. this.ctx.series.addCollapsedClassToSeries(elSeries, i);
  19984. if (w.config.chart.dropShadow.enabled) {
  19985. var shadow = w.config.chart.dropShadow;
  19986. var filters = new Filters(this.ctx);
  19987. filters.dropShadow(elSeries, shadow, i);
  19988. }
  19989. var x1 = 0;
  19990. var shadeIntensity = w.config.plotOptions.heatmap.shadeIntensity;
  19991. for (var j = 0; j < heatSeries[i].length; j++) {
  19992. var heatColor = this.helpers.getShadeColor(w.config.chart.type, i, j, this.negRange);
  19993. var color = heatColor.color;
  19994. var heatColorProps = heatColor.colorProps;
  19995. if (w.config.fill.type === 'image') {
  19996. var fill = new Fill(this.ctx);
  19997. color = fill.fillPath({
  19998. seriesNumber: i,
  19999. dataPointIndex: j,
  20000. opacity: w.globals.hasNegs ? heatColorProps.percent < 0 ? 1 - (1 + heatColorProps.percent / 100) : shadeIntensity + heatColorProps.percent / 100 : heatColorProps.percent / 100,
  20001. patternID: Utils$1.randomId(),
  20002. width: w.config.fill.image.width ? w.config.fill.image.width : xDivision,
  20003. height: w.config.fill.image.height ? w.config.fill.image.height : yDivision
  20004. });
  20005. }
  20006. var radius = this.rectRadius;
  20007. var rect = graphics.drawRect(x1, y1, xDivision, yDivision, radius);
  20008. rect.attr({
  20009. cx: x1,
  20010. cy: y1
  20011. });
  20012. rect.node.classList.add('apexcharts-heatmap-rect');
  20013. elSeries.add(rect);
  20014. rect.attr({
  20015. fill: color,
  20016. i: i,
  20017. index: i,
  20018. j: j,
  20019. val: series[i][j],
  20020. 'stroke-width': this.strokeWidth,
  20021. stroke: w.config.plotOptions.heatmap.useFillColorAsStroke ? color : w.globals.stroke.colors[0],
  20022. color: color
  20023. });
  20024. this.helpers.addListeners(rect);
  20025. if (w.config.chart.animations.enabled && !w.globals.dataChanged) {
  20026. var speed = 1;
  20027. if (!w.globals.resized) {
  20028. speed = w.config.chart.animations.speed;
  20029. }
  20030. this.animateHeatMap(rect, x1, y1, xDivision, yDivision, speed);
  20031. }
  20032. if (w.globals.dataChanged) {
  20033. var _speed = 1;
  20034. if (this.dynamicAnim.enabled && w.globals.shouldAnimate) {
  20035. _speed = this.dynamicAnim.speed;
  20036. var colorFrom = w.globals.previousPaths[i] && w.globals.previousPaths[i][j] && w.globals.previousPaths[i][j].color;
  20037. if (!colorFrom) colorFrom = 'rgba(255, 255, 255, 0)';
  20038. this.animateHeatColor(rect, Utils$1.isColorHex(colorFrom) ? colorFrom : Utils$1.rgb2hex(colorFrom), Utils$1.isColorHex(color) ? color : Utils$1.rgb2hex(color), _speed);
  20039. }
  20040. }
  20041. var formatter = w.config.dataLabels.formatter;
  20042. var formattedText = formatter(w.globals.series[i][j], {
  20043. value: w.globals.series[i][j],
  20044. seriesIndex: i,
  20045. dataPointIndex: j,
  20046. w: w
  20047. });
  20048. var dataLabels = this.helpers.calculateDataLabels({
  20049. text: formattedText,
  20050. x: x1 + xDivision / 2,
  20051. y: y1 + yDivision / 2,
  20052. i: i,
  20053. j: j,
  20054. colorProps: heatColorProps,
  20055. series: heatSeries
  20056. });
  20057. if (dataLabels !== null) {
  20058. elSeries.add(dataLabels);
  20059. }
  20060. x1 = x1 + xDivision;
  20061. }
  20062. y1 = y1 + yDivision;
  20063. ret.add(elSeries);
  20064. }
  20065. // adjust yaxis labels for heatmap
  20066. var yAxisScale = w.globals.yAxisScale[0].result.slice();
  20067. if (w.config.yaxis[0].reversed) {
  20068. yAxisScale.unshift('');
  20069. } else {
  20070. yAxisScale.push('');
  20071. }
  20072. w.globals.yAxisScale[0].result = yAxisScale;
  20073. return ret;
  20074. }
  20075. }, {
  20076. key: "animateHeatMap",
  20077. value: function animateHeatMap(el, x, y, width, height, speed) {
  20078. var animations = new Animations(this.ctx);
  20079. animations.animateRect(el, {
  20080. x: x + width / 2,
  20081. y: y + height / 2,
  20082. width: 0,
  20083. height: 0
  20084. }, {
  20085. x: x,
  20086. y: y,
  20087. width: width,
  20088. height: height
  20089. }, speed, function () {
  20090. animations.animationCompleted(el);
  20091. });
  20092. }
  20093. }, {
  20094. key: "animateHeatColor",
  20095. value: function animateHeatColor(el, colorFrom, colorTo, speed) {
  20096. el.attr({
  20097. fill: colorFrom
  20098. }).animate(speed).attr({
  20099. fill: colorTo
  20100. });
  20101. }
  20102. }]);
  20103. return HeatMap;
  20104. }();
  20105. var CircularChartsHelpers = /*#__PURE__*/function () {
  20106. function CircularChartsHelpers(ctx) {
  20107. _classCallCheck(this, CircularChartsHelpers);
  20108. this.ctx = ctx;
  20109. this.w = ctx.w;
  20110. }
  20111. _createClass(CircularChartsHelpers, [{
  20112. key: "drawYAxisTexts",
  20113. value: function drawYAxisTexts(x, y, i, text) {
  20114. var w = this.w;
  20115. var yaxisConfig = w.config.yaxis[0];
  20116. var formatter = w.globals.yLabelFormatters[0];
  20117. var graphics = new Graphics(this.ctx);
  20118. var yaxisLabel = graphics.drawText({
  20119. x: x + yaxisConfig.labels.offsetX,
  20120. y: y + yaxisConfig.labels.offsetY,
  20121. text: formatter(text, i),
  20122. textAnchor: 'middle',
  20123. fontSize: yaxisConfig.labels.style.fontSize,
  20124. fontFamily: yaxisConfig.labels.style.fontFamily,
  20125. foreColor: Array.isArray(yaxisConfig.labels.style.colors) ? yaxisConfig.labels.style.colors[i] : yaxisConfig.labels.style.colors
  20126. });
  20127. return yaxisLabel;
  20128. }
  20129. }]);
  20130. return CircularChartsHelpers;
  20131. }();
  20132. /**
  20133. * ApexCharts Pie Class for drawing Pie / Donut Charts.
  20134. * @module Pie
  20135. **/
  20136. var Pie = /*#__PURE__*/function () {
  20137. function Pie(ctx) {
  20138. _classCallCheck(this, Pie);
  20139. this.ctx = ctx;
  20140. this.w = ctx.w;
  20141. var w = this.w;
  20142. this.chartType = this.w.config.chart.type;
  20143. this.initialAnim = this.w.config.chart.animations.enabled;
  20144. this.dynamicAnim = this.initialAnim && this.w.config.chart.animations.dynamicAnimation.enabled;
  20145. this.animBeginArr = [0];
  20146. this.animDur = 0;
  20147. this.donutDataLabels = this.w.config.plotOptions.pie.donut.labels;
  20148. this.lineColorArr = w.globals.stroke.colors !== undefined ? w.globals.stroke.colors : w.globals.colors;
  20149. this.defaultSize = Math.min(w.globals.gridWidth, w.globals.gridHeight);
  20150. this.centerY = this.defaultSize / 2;
  20151. this.centerX = w.globals.gridWidth / 2;
  20152. if (w.config.chart.type === 'radialBar') {
  20153. this.fullAngle = 360;
  20154. } else {
  20155. this.fullAngle = Math.abs(w.config.plotOptions.pie.endAngle - w.config.plotOptions.pie.startAngle);
  20156. }
  20157. this.initialAngle = w.config.plotOptions.pie.startAngle % this.fullAngle;
  20158. w.globals.radialSize = this.defaultSize / 2.05 - w.config.stroke.width - (!w.config.chart.sparkline.enabled ? w.config.chart.dropShadow.blur : 0);
  20159. this.donutSize = w.globals.radialSize * parseInt(w.config.plotOptions.pie.donut.size, 10) / 100;
  20160. var scaleSize = w.config.plotOptions.pie.customScale;
  20161. var halfW = w.globals.gridWidth / 2;
  20162. var halfH = w.globals.gridHeight / 2;
  20163. this.translateX = halfW - halfW * scaleSize;
  20164. this.translateY = halfH - halfH * scaleSize;
  20165. this.dataLabelsGroup = new Graphics(this.ctx).group({
  20166. class: 'apexcharts-datalabels-group',
  20167. transform: "translate(".concat(this.translateX, ", ").concat(this.translateY, ") scale(").concat(scaleSize, ")")
  20168. });
  20169. this.maxY = 0;
  20170. this.sliceLabels = [];
  20171. this.sliceSizes = [];
  20172. this.prevSectorAngleArr = []; // for dynamic animations
  20173. }
  20174. _createClass(Pie, [{
  20175. key: "draw",
  20176. value: function draw(series) {
  20177. var _this = this;
  20178. var self = this;
  20179. var w = this.w;
  20180. var graphics = new Graphics(this.ctx);
  20181. var elPie = graphics.group({
  20182. class: 'apexcharts-pie'
  20183. });
  20184. if (w.globals.noData) return elPie;
  20185. var total = 0;
  20186. for (var k = 0; k < series.length; k++) {
  20187. // CALCULATE THE TOTAL
  20188. total += Utils$1.negToZero(series[k]);
  20189. }
  20190. var sectorAngleArr = [];
  20191. // el to which series will be drawn
  20192. var elSeries = graphics.group();
  20193. // prevent division by zero error if there is no data
  20194. if (total === 0) {
  20195. total = 0.00001;
  20196. }
  20197. series.forEach(function (m) {
  20198. _this.maxY = Math.max(_this.maxY, m);
  20199. });
  20200. // override maxY if user provided in config
  20201. if (w.config.yaxis[0].max) {
  20202. this.maxY = w.config.yaxis[0].max;
  20203. }
  20204. if (w.config.grid.position === 'back' && this.chartType === 'polarArea') {
  20205. this.drawPolarElements(elPie);
  20206. }
  20207. for (var i = 0; i < series.length; i++) {
  20208. // CALCULATE THE ANGLES
  20209. var angle = this.fullAngle * Utils$1.negToZero(series[i]) / total;
  20210. sectorAngleArr.push(angle);
  20211. if (this.chartType === 'polarArea') {
  20212. sectorAngleArr[i] = this.fullAngle / series.length;
  20213. this.sliceSizes.push(w.globals.radialSize * series[i] / this.maxY);
  20214. } else {
  20215. this.sliceSizes.push(w.globals.radialSize);
  20216. }
  20217. }
  20218. if (w.globals.dataChanged) {
  20219. var prevTotal = 0;
  20220. for (var _k = 0; _k < w.globals.previousPaths.length; _k++) {
  20221. // CALCULATE THE PREV TOTAL
  20222. prevTotal += Utils$1.negToZero(w.globals.previousPaths[_k]);
  20223. }
  20224. var previousAngle;
  20225. for (var _i = 0; _i < w.globals.previousPaths.length; _i++) {
  20226. // CALCULATE THE PREVIOUS ANGLES
  20227. previousAngle = this.fullAngle * Utils$1.negToZero(w.globals.previousPaths[_i]) / prevTotal;
  20228. this.prevSectorAngleArr.push(previousAngle);
  20229. }
  20230. }
  20231. // on small chart size after few count of resizes browser window donutSize can be negative
  20232. if (this.donutSize < 0) {
  20233. this.donutSize = 0;
  20234. }
  20235. if (this.chartType === 'donut') {
  20236. // draw the inner circle and add some text to it
  20237. var circle = graphics.drawCircle(this.donutSize);
  20238. circle.attr({
  20239. cx: this.centerX,
  20240. cy: this.centerY,
  20241. fill: w.config.plotOptions.pie.donut.background ? w.config.plotOptions.pie.donut.background : 'transparent'
  20242. });
  20243. elSeries.add(circle);
  20244. }
  20245. var elG = self.drawArcs(sectorAngleArr, series);
  20246. // add slice dataLabels at the end
  20247. this.sliceLabels.forEach(function (s) {
  20248. elG.add(s);
  20249. });
  20250. elSeries.attr({
  20251. transform: "translate(".concat(this.translateX, ", ").concat(this.translateY, ") scale(").concat(w.config.plotOptions.pie.customScale, ")")
  20252. });
  20253. elSeries.add(elG);
  20254. elPie.add(elSeries);
  20255. if (this.donutDataLabels.show) {
  20256. var dataLabels = this.renderInnerDataLabels(this.dataLabelsGroup, this.donutDataLabels, {
  20257. hollowSize: this.donutSize,
  20258. centerX: this.centerX,
  20259. centerY: this.centerY,
  20260. opacity: this.donutDataLabels.show
  20261. });
  20262. elPie.add(dataLabels);
  20263. }
  20264. if (w.config.grid.position === 'front' && this.chartType === 'polarArea') {
  20265. this.drawPolarElements(elPie);
  20266. }
  20267. return elPie;
  20268. }
  20269. // core function for drawing pie arcs
  20270. }, {
  20271. key: "drawArcs",
  20272. value: function drawArcs(sectorAngleArr, series) {
  20273. var w = this.w;
  20274. var filters = new Filters(this.ctx);
  20275. var graphics = new Graphics(this.ctx);
  20276. var fill = new Fill(this.ctx);
  20277. var g = graphics.group({
  20278. class: 'apexcharts-slices'
  20279. });
  20280. var startAngle = this.initialAngle;
  20281. var prevStartAngle = this.initialAngle;
  20282. var endAngle = this.initialAngle;
  20283. var prevEndAngle = this.initialAngle;
  20284. this.strokeWidth = w.config.stroke.show ? w.config.stroke.width : 0;
  20285. for (var i = 0; i < sectorAngleArr.length; i++) {
  20286. var elPieArc = graphics.group({
  20287. class: "apexcharts-series apexcharts-pie-series",
  20288. seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
  20289. rel: i + 1,
  20290. 'data:realIndex': i
  20291. });
  20292. g.add(elPieArc);
  20293. startAngle = endAngle;
  20294. prevStartAngle = prevEndAngle;
  20295. endAngle = startAngle + sectorAngleArr[i];
  20296. prevEndAngle = prevStartAngle + this.prevSectorAngleArr[i];
  20297. var angle = endAngle < startAngle ? this.fullAngle + endAngle - startAngle : endAngle - startAngle;
  20298. var pathFill = fill.fillPath({
  20299. seriesNumber: i,
  20300. size: this.sliceSizes[i],
  20301. value: series[i]
  20302. }); // additionally, pass size for gradient drawing in the fillPath function
  20303. var path = this.getChangedPath(prevStartAngle, prevEndAngle);
  20304. var elPath = graphics.drawPath({
  20305. d: path,
  20306. stroke: Array.isArray(this.lineColorArr) ? this.lineColorArr[i] : this.lineColorArr,
  20307. strokeWidth: 0,
  20308. fill: pathFill,
  20309. fillOpacity: w.config.fill.opacity,
  20310. classes: "apexcharts-pie-area apexcharts-".concat(this.chartType.toLowerCase(), "-slice-").concat(i)
  20311. });
  20312. elPath.attr({
  20313. index: 0,
  20314. j: i
  20315. });
  20316. filters.setSelectionFilter(elPath, 0, i);
  20317. if (w.config.chart.dropShadow.enabled) {
  20318. var shadow = w.config.chart.dropShadow;
  20319. filters.dropShadow(elPath, shadow, i);
  20320. }
  20321. this.addListeners(elPath, this.donutDataLabels);
  20322. Graphics.setAttrs(elPath.node, {
  20323. 'data:angle': angle,
  20324. 'data:startAngle': startAngle,
  20325. 'data:strokeWidth': this.strokeWidth,
  20326. 'data:value': series[i]
  20327. });
  20328. var labelPosition = {
  20329. x: 0,
  20330. y: 0
  20331. };
  20332. if (this.chartType === 'pie' || this.chartType === 'polarArea') {
  20333. labelPosition = Utils$1.polarToCartesian(this.centerX, this.centerY, w.globals.radialSize / 1.25 + w.config.plotOptions.pie.dataLabels.offset, (startAngle + angle / 2) % this.fullAngle);
  20334. } else if (this.chartType === 'donut') {
  20335. 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);
  20336. }
  20337. elPieArc.add(elPath);
  20338. // Animation code starts
  20339. var dur = 0;
  20340. if (this.initialAnim && !w.globals.resized && !w.globals.dataChanged) {
  20341. dur = angle / this.fullAngle * w.config.chart.animations.speed;
  20342. if (dur === 0) dur = 1;
  20343. this.animDur = dur + this.animDur;
  20344. this.animBeginArr.push(this.animDur);
  20345. } else {
  20346. this.animBeginArr.push(0);
  20347. }
  20348. if (this.dynamicAnim && w.globals.dataChanged) {
  20349. this.animatePaths(elPath, {
  20350. size: this.sliceSizes[i],
  20351. endAngle: endAngle,
  20352. startAngle: startAngle,
  20353. prevStartAngle: prevStartAngle,
  20354. prevEndAngle: prevEndAngle,
  20355. animateStartingPos: true,
  20356. i: i,
  20357. animBeginArr: this.animBeginArr,
  20358. shouldSetPrevPaths: true,
  20359. dur: w.config.chart.animations.dynamicAnimation.speed
  20360. });
  20361. } else {
  20362. this.animatePaths(elPath, {
  20363. size: this.sliceSizes[i],
  20364. endAngle: endAngle,
  20365. startAngle: startAngle,
  20366. i: i,
  20367. totalItems: sectorAngleArr.length - 1,
  20368. animBeginArr: this.animBeginArr,
  20369. dur: dur
  20370. });
  20371. }
  20372. // animation code ends
  20373. if (w.config.plotOptions.pie.expandOnClick && this.chartType !== 'polarArea') {
  20374. elPath.node.addEventListener('mouseup', this.pieClicked.bind(this, i));
  20375. }
  20376. if (typeof w.globals.selectedDataPoints[0] !== 'undefined' && w.globals.selectedDataPoints[0].indexOf(i) > -1) {
  20377. this.pieClicked(i);
  20378. }
  20379. if (w.config.dataLabels.enabled) {
  20380. var xPos = labelPosition.x;
  20381. var yPos = labelPosition.y;
  20382. var text = 100 * angle / this.fullAngle + '%';
  20383. if (angle !== 0 && w.config.plotOptions.pie.dataLabels.minAngleToShowLabel < sectorAngleArr[i]) {
  20384. var formatter = w.config.dataLabels.formatter;
  20385. if (formatter !== undefined) {
  20386. text = formatter(w.globals.seriesPercent[i][0], {
  20387. seriesIndex: i,
  20388. w: w
  20389. });
  20390. }
  20391. var foreColor = w.globals.dataLabels.style.colors[i];
  20392. var elPieLabelWrap = graphics.group({
  20393. class: "apexcharts-datalabels"
  20394. });
  20395. var elPieLabel = graphics.drawText({
  20396. x: xPos,
  20397. y: yPos,
  20398. text: text,
  20399. textAnchor: 'middle',
  20400. fontSize: w.config.dataLabels.style.fontSize,
  20401. fontFamily: w.config.dataLabels.style.fontFamily,
  20402. fontWeight: w.config.dataLabels.style.fontWeight,
  20403. foreColor: foreColor
  20404. });
  20405. elPieLabelWrap.add(elPieLabel);
  20406. if (w.config.dataLabels.dropShadow.enabled) {
  20407. var textShadow = w.config.dataLabels.dropShadow;
  20408. filters.dropShadow(elPieLabel, textShadow);
  20409. }
  20410. elPieLabel.node.classList.add('apexcharts-pie-label');
  20411. if (w.config.chart.animations.animate && w.globals.resized === false) {
  20412. elPieLabel.node.classList.add('apexcharts-pie-label-delay');
  20413. elPieLabel.node.style.animationDelay = w.config.chart.animations.speed / 940 + 's';
  20414. }
  20415. this.sliceLabels.push(elPieLabelWrap);
  20416. }
  20417. }
  20418. }
  20419. return g;
  20420. }
  20421. }, {
  20422. key: "addListeners",
  20423. value: function addListeners(elPath, dataLabels) {
  20424. var graphics = new Graphics(this.ctx);
  20425. // append filters on mouseenter and mouseleave
  20426. elPath.node.addEventListener('mouseenter', graphics.pathMouseEnter.bind(this, elPath));
  20427. elPath.node.addEventListener('mouseleave', graphics.pathMouseLeave.bind(this, elPath));
  20428. elPath.node.addEventListener('mouseleave', this.revertDataLabelsInner.bind(this, elPath.node, dataLabels));
  20429. elPath.node.addEventListener('mousedown', graphics.pathMouseDown.bind(this, elPath));
  20430. if (!this.donutDataLabels.total.showAlways) {
  20431. elPath.node.addEventListener('mouseenter', this.printDataLabelsInner.bind(this, elPath.node, dataLabels));
  20432. elPath.node.addEventListener('mousedown', this.printDataLabelsInner.bind(this, elPath.node, dataLabels));
  20433. }
  20434. }
  20435. // This function can be used for other circle charts too
  20436. }, {
  20437. key: "animatePaths",
  20438. value: function animatePaths(el, opts) {
  20439. var w = this.w;
  20440. var me = this;
  20441. var angle = opts.endAngle < opts.startAngle ? this.fullAngle + opts.endAngle - opts.startAngle : opts.endAngle - opts.startAngle;
  20442. var prevAngle = angle;
  20443. var fromStartAngle = opts.startAngle;
  20444. var toStartAngle = opts.startAngle;
  20445. if (opts.prevStartAngle !== undefined && opts.prevEndAngle !== undefined) {
  20446. fromStartAngle = opts.prevEndAngle;
  20447. prevAngle = opts.prevEndAngle < opts.prevStartAngle ? this.fullAngle + opts.prevEndAngle - opts.prevStartAngle : opts.prevEndAngle - opts.prevStartAngle;
  20448. }
  20449. if (opts.i === w.config.series.length - 1) {
  20450. // some adjustments for the last overlapping paths
  20451. if (angle + toStartAngle > this.fullAngle) {
  20452. opts.endAngle = opts.endAngle - (angle + toStartAngle);
  20453. } else if (angle + toStartAngle < this.fullAngle) {
  20454. opts.endAngle = opts.endAngle + (this.fullAngle - (angle + toStartAngle));
  20455. }
  20456. }
  20457. if (angle === this.fullAngle) angle = this.fullAngle - 0.01;
  20458. me.animateArc(el, fromStartAngle, toStartAngle, angle, prevAngle, opts);
  20459. }
  20460. }, {
  20461. key: "animateArc",
  20462. value: function animateArc(el, fromStartAngle, toStartAngle, angle, prevAngle, opts) {
  20463. var me = this;
  20464. var w = this.w;
  20465. var animations = new Animations(this.ctx);
  20466. var size = opts.size;
  20467. var path;
  20468. if (isNaN(fromStartAngle) || isNaN(prevAngle)) {
  20469. fromStartAngle = toStartAngle;
  20470. prevAngle = angle;
  20471. opts.dur = 0;
  20472. }
  20473. var currAngle = angle;
  20474. var startAngle = toStartAngle;
  20475. var fromAngle = fromStartAngle < toStartAngle ? this.fullAngle + fromStartAngle - toStartAngle : fromStartAngle - toStartAngle;
  20476. if (w.globals.dataChanged && opts.shouldSetPrevPaths) {
  20477. // to avoid flicker when updating, set prev path first and then animate from there
  20478. if (opts.prevEndAngle) {
  20479. path = me.getPiePath({
  20480. me: me,
  20481. startAngle: opts.prevStartAngle,
  20482. angle: opts.prevEndAngle < opts.prevStartAngle ? this.fullAngle + opts.prevEndAngle - opts.prevStartAngle : opts.prevEndAngle - opts.prevStartAngle,
  20483. size: size
  20484. });
  20485. el.attr({
  20486. d: path
  20487. });
  20488. }
  20489. }
  20490. if (opts.dur !== 0) {
  20491. el.animate(opts.dur, w.globals.easing, opts.animBeginArr[opts.i]).afterAll(function () {
  20492. if (me.chartType === 'pie' || me.chartType === 'donut' || me.chartType === 'polarArea') {
  20493. this.animate(w.config.chart.animations.dynamicAnimation.speed).attr({
  20494. 'stroke-width': me.strokeWidth
  20495. });
  20496. }
  20497. if (opts.i === w.config.series.length - 1) {
  20498. animations.animationCompleted(el);
  20499. }
  20500. }).during(function (pos) {
  20501. currAngle = fromAngle + (angle - fromAngle) * pos;
  20502. if (opts.animateStartingPos) {
  20503. currAngle = prevAngle + (angle - prevAngle) * pos;
  20504. startAngle = fromStartAngle - prevAngle + (toStartAngle - (fromStartAngle - prevAngle)) * pos;
  20505. }
  20506. path = me.getPiePath({
  20507. me: me,
  20508. startAngle: startAngle,
  20509. angle: currAngle,
  20510. size: size
  20511. });
  20512. el.node.setAttribute('data:pathOrig', path);
  20513. el.attr({
  20514. d: path
  20515. });
  20516. });
  20517. } else {
  20518. path = me.getPiePath({
  20519. me: me,
  20520. startAngle: startAngle,
  20521. angle: angle,
  20522. size: size
  20523. });
  20524. if (!opts.isTrack) {
  20525. w.globals.animationEnded = true;
  20526. }
  20527. el.node.setAttribute('data:pathOrig', path);
  20528. el.attr({
  20529. d: path,
  20530. 'stroke-width': me.strokeWidth
  20531. });
  20532. }
  20533. }
  20534. }, {
  20535. key: "pieClicked",
  20536. value: function pieClicked(i) {
  20537. var w = this.w;
  20538. var me = this;
  20539. var path;
  20540. var size = me.sliceSizes[i] + (w.config.plotOptions.pie.expandOnClick ? 4 : 0);
  20541. var elPath = w.globals.dom.Paper.select(".apexcharts-".concat(me.chartType.toLowerCase(), "-slice-").concat(i)).members[0];
  20542. if (elPath.attr('data:pieClicked') === 'true') {
  20543. elPath.attr({
  20544. 'data:pieClicked': 'false'
  20545. });
  20546. this.revertDataLabelsInner(elPath.node, this.donutDataLabels);
  20547. var origPath = elPath.attr('data:pathOrig');
  20548. elPath.attr({
  20549. d: origPath
  20550. });
  20551. return;
  20552. } else {
  20553. // reset all elems
  20554. var allEls = w.globals.dom.baseEl.getElementsByClassName('apexcharts-pie-area');
  20555. Array.prototype.forEach.call(allEls, function (pieSlice) {
  20556. pieSlice.setAttribute('data:pieClicked', 'false');
  20557. var origPath = pieSlice.getAttribute('data:pathOrig');
  20558. if (origPath) {
  20559. pieSlice.setAttribute('d', origPath);
  20560. }
  20561. });
  20562. w.globals.capturedDataPointIndex = i;
  20563. elPath.attr('data:pieClicked', 'true');
  20564. }
  20565. var startAngle = parseInt(elPath.attr('data:startAngle'), 10);
  20566. var angle = parseInt(elPath.attr('data:angle'), 10);
  20567. path = me.getPiePath({
  20568. me: me,
  20569. startAngle: startAngle,
  20570. angle: angle,
  20571. size: size
  20572. });
  20573. if (angle === 360) return;
  20574. elPath.plot(path);
  20575. }
  20576. }, {
  20577. key: "getChangedPath",
  20578. value: function getChangedPath(prevStartAngle, prevEndAngle) {
  20579. var path = '';
  20580. if (this.dynamicAnim && this.w.globals.dataChanged) {
  20581. path = this.getPiePath({
  20582. me: this,
  20583. startAngle: prevStartAngle,
  20584. angle: prevEndAngle - prevStartAngle,
  20585. size: this.size
  20586. });
  20587. }
  20588. return path;
  20589. }
  20590. }, {
  20591. key: "getPiePath",
  20592. value: function getPiePath(_ref) {
  20593. var me = _ref.me,
  20594. startAngle = _ref.startAngle,
  20595. angle = _ref.angle,
  20596. size = _ref.size;
  20597. var path;
  20598. var graphics = new Graphics(this.ctx);
  20599. var startDeg = startAngle;
  20600. var startRadians = Math.PI * (startDeg - 90) / 180;
  20601. var endDeg = angle + startAngle;
  20602. // prevent overlap
  20603. if (Math.ceil(endDeg) >= this.fullAngle + this.w.config.plotOptions.pie.startAngle % this.fullAngle) {
  20604. endDeg = this.fullAngle + this.w.config.plotOptions.pie.startAngle % this.fullAngle - 0.01;
  20605. }
  20606. if (Math.ceil(endDeg) > this.fullAngle) endDeg -= this.fullAngle;
  20607. var endRadians = Math.PI * (endDeg - 90) / 180;
  20608. var x1 = me.centerX + size * Math.cos(startRadians);
  20609. var y1 = me.centerY + size * Math.sin(startRadians);
  20610. var x2 = me.centerX + size * Math.cos(endRadians);
  20611. var y2 = me.centerY + size * Math.sin(endRadians);
  20612. var startInner = Utils$1.polarToCartesian(me.centerX, me.centerY, me.donutSize, endDeg);
  20613. var endInner = Utils$1.polarToCartesian(me.centerX, me.centerY, me.donutSize, startDeg);
  20614. var largeArc = angle > 180 ? 1 : 0;
  20615. var pathBeginning = ['M', x1, y1, 'A', size, size, 0, largeArc, 1, x2, y2];
  20616. if (me.chartType === 'donut') {
  20617. 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(' ');
  20618. } else if (me.chartType === 'pie' || me.chartType === 'polarArea') {
  20619. path = [].concat(pathBeginning, ['L', me.centerX, me.centerY, 'L', x1, y1]).join(' ');
  20620. } else {
  20621. path = [].concat(pathBeginning).join(' ');
  20622. }
  20623. return graphics.roundPathCorners(path, this.strokeWidth * 2);
  20624. }
  20625. }, {
  20626. key: "drawPolarElements",
  20627. value: function drawPolarElements(parent) {
  20628. var w = this.w;
  20629. var scale = new Scales(this.ctx);
  20630. var graphics = new Graphics(this.ctx);
  20631. var helpers = new CircularChartsHelpers(this.ctx);
  20632. var gCircles = graphics.group();
  20633. var gYAxis = graphics.group();
  20634. var yScale = scale.niceScale(0, Math.ceil(this.maxY), 0);
  20635. var yTexts = yScale.result.reverse();
  20636. var len = yScale.result.length;
  20637. this.maxY = yScale.niceMax;
  20638. var circleSize = w.globals.radialSize;
  20639. var diff = circleSize / (len - 1);
  20640. for (var i = 0; i < len - 1; i++) {
  20641. var circle = graphics.drawCircle(circleSize);
  20642. circle.attr({
  20643. cx: this.centerX,
  20644. cy: this.centerY,
  20645. fill: 'none',
  20646. 'stroke-width': w.config.plotOptions.polarArea.rings.strokeWidth,
  20647. stroke: w.config.plotOptions.polarArea.rings.strokeColor
  20648. });
  20649. if (w.config.yaxis[0].show) {
  20650. var yLabel = helpers.drawYAxisTexts(this.centerX, this.centerY - circleSize + parseInt(w.config.yaxis[0].labels.style.fontSize, 10) / 2, i, yTexts[i]);
  20651. gYAxis.add(yLabel);
  20652. }
  20653. gCircles.add(circle);
  20654. circleSize = circleSize - diff;
  20655. }
  20656. this.drawSpokes(parent);
  20657. parent.add(gCircles);
  20658. parent.add(gYAxis);
  20659. }
  20660. }, {
  20661. key: "renderInnerDataLabels",
  20662. value: function renderInnerDataLabels(dataLabelsGroup, dataLabelsConfig, opts) {
  20663. var w = this.w;
  20664. var graphics = new Graphics(this.ctx);
  20665. var showTotal = dataLabelsConfig.total.show;
  20666. dataLabelsGroup.node.innerHTML = '';
  20667. dataLabelsGroup.node.style.opacity = opts.opacity;
  20668. var x = opts.centerX;
  20669. var y = !this.donutDataLabels.total.label ? opts.centerY - opts.centerY / 6 : opts.centerY;
  20670. var labelColor, valueColor;
  20671. if (dataLabelsConfig.name.color === undefined) {
  20672. labelColor = w.globals.colors[0];
  20673. } else {
  20674. labelColor = dataLabelsConfig.name.color;
  20675. }
  20676. var labelFontSize = dataLabelsConfig.name.fontSize;
  20677. var labelFontFamily = dataLabelsConfig.name.fontFamily;
  20678. var labelFontWeight = dataLabelsConfig.name.fontWeight;
  20679. if (dataLabelsConfig.value.color === undefined) {
  20680. valueColor = w.config.chart.foreColor;
  20681. } else {
  20682. valueColor = dataLabelsConfig.value.color;
  20683. }
  20684. var lbFormatter = dataLabelsConfig.value.formatter;
  20685. var val = '';
  20686. var name = '';
  20687. if (showTotal) {
  20688. labelColor = dataLabelsConfig.total.color;
  20689. labelFontSize = dataLabelsConfig.total.fontSize;
  20690. labelFontFamily = dataLabelsConfig.total.fontFamily;
  20691. labelFontWeight = dataLabelsConfig.total.fontWeight;
  20692. name = !this.donutDataLabels.total.label ? '' : dataLabelsConfig.total.label;
  20693. val = dataLabelsConfig.total.formatter(w);
  20694. } else {
  20695. if (w.globals.series.length === 1) {
  20696. val = lbFormatter(w.globals.series[0], w);
  20697. name = w.globals.seriesNames[0];
  20698. }
  20699. }
  20700. if (name) {
  20701. name = dataLabelsConfig.name.formatter(name, dataLabelsConfig.total.show, w);
  20702. }
  20703. if (dataLabelsConfig.name.show) {
  20704. var elLabel = graphics.drawText({
  20705. x: x,
  20706. y: y + parseFloat(dataLabelsConfig.name.offsetY),
  20707. text: name,
  20708. textAnchor: 'middle',
  20709. foreColor: labelColor,
  20710. fontSize: labelFontSize,
  20711. fontWeight: labelFontWeight,
  20712. fontFamily: labelFontFamily
  20713. });
  20714. elLabel.node.classList.add('apexcharts-datalabel-label');
  20715. dataLabelsGroup.add(elLabel);
  20716. }
  20717. if (dataLabelsConfig.value.show) {
  20718. var valOffset = dataLabelsConfig.name.show ? parseFloat(dataLabelsConfig.value.offsetY) + 16 : dataLabelsConfig.value.offsetY;
  20719. var elValue = graphics.drawText({
  20720. x: x,
  20721. y: y + valOffset,
  20722. text: val,
  20723. textAnchor: 'middle',
  20724. foreColor: valueColor,
  20725. fontWeight: dataLabelsConfig.value.fontWeight,
  20726. fontSize: dataLabelsConfig.value.fontSize,
  20727. fontFamily: dataLabelsConfig.value.fontFamily
  20728. });
  20729. elValue.node.classList.add('apexcharts-datalabel-value');
  20730. dataLabelsGroup.add(elValue);
  20731. }
  20732. // for a multi-series circle chart, we need to show total value instead of first series labels
  20733. return dataLabelsGroup;
  20734. }
  20735. /**
  20736. *
  20737. * @param {string} name - The name of the series
  20738. * @param {string} val - The value of that series
  20739. * @param {object} el - Optional el (indicates which series was hovered/clicked). If this param is not present, means we need to show total
  20740. */
  20741. }, {
  20742. key: "printInnerLabels",
  20743. value: function printInnerLabels(labelsConfig, name, val, el) {
  20744. var w = this.w;
  20745. var labelColor;
  20746. if (el) {
  20747. if (labelsConfig.name.color === undefined) {
  20748. labelColor = w.globals.colors[parseInt(el.parentNode.getAttribute('rel'), 10) - 1];
  20749. } else {
  20750. labelColor = labelsConfig.name.color;
  20751. }
  20752. } else {
  20753. if (w.globals.series.length > 1 && labelsConfig.total.show) {
  20754. labelColor = labelsConfig.total.color;
  20755. }
  20756. }
  20757. var elLabel = w.globals.dom.baseEl.querySelector('.apexcharts-datalabel-label');
  20758. var elValue = w.globals.dom.baseEl.querySelector('.apexcharts-datalabel-value');
  20759. var lbFormatter = labelsConfig.value.formatter;
  20760. val = lbFormatter(val, w);
  20761. // we need to show Total Val - so get the formatter of it
  20762. if (!el && typeof labelsConfig.total.formatter === 'function') {
  20763. val = labelsConfig.total.formatter(w);
  20764. }
  20765. var isTotal = name === labelsConfig.total.label;
  20766. name = !this.donutDataLabels.total.label ? '' : labelsConfig.name.formatter(name, isTotal, w);
  20767. if (elLabel !== null) {
  20768. elLabel.textContent = name;
  20769. }
  20770. if (elValue !== null) {
  20771. elValue.textContent = val;
  20772. }
  20773. if (elLabel !== null) {
  20774. elLabel.style.fill = labelColor;
  20775. }
  20776. }
  20777. }, {
  20778. key: "printDataLabelsInner",
  20779. value: function printDataLabelsInner(el, dataLabelsConfig) {
  20780. var w = this.w;
  20781. var val = el.getAttribute('data:value');
  20782. var name = w.globals.seriesNames[parseInt(el.parentNode.getAttribute('rel'), 10) - 1];
  20783. if (w.globals.series.length > 1) {
  20784. this.printInnerLabels(dataLabelsConfig, name, val, el);
  20785. }
  20786. var dataLabelsGroup = w.globals.dom.baseEl.querySelector('.apexcharts-datalabels-group');
  20787. if (dataLabelsGroup !== null) {
  20788. dataLabelsGroup.style.opacity = 1;
  20789. }
  20790. }
  20791. }, {
  20792. key: "drawSpokes",
  20793. value: function drawSpokes(parent) {
  20794. var _this2 = this;
  20795. var w = this.w;
  20796. var graphics = new Graphics(this.ctx);
  20797. var spokeConfig = w.config.plotOptions.polarArea.spokes;
  20798. if (spokeConfig.strokeWidth === 0) return;
  20799. var spokes = [];
  20800. var angleDivision = 360 / w.globals.series.length;
  20801. for (var i = 0; i < w.globals.series.length; i++) {
  20802. spokes.push(Utils$1.polarToCartesian(this.centerX, this.centerY, w.globals.radialSize, w.config.plotOptions.pie.startAngle + angleDivision * i));
  20803. }
  20804. spokes.forEach(function (p, i) {
  20805. var line = graphics.drawLine(p.x, p.y, _this2.centerX, _this2.centerY, Array.isArray(spokeConfig.connectorColors) ? spokeConfig.connectorColors[i] : spokeConfig.connectorColors);
  20806. parent.add(line);
  20807. });
  20808. }
  20809. }, {
  20810. key: "revertDataLabelsInner",
  20811. value: function revertDataLabelsInner() {
  20812. var w = this.w;
  20813. if (this.donutDataLabels.show) {
  20814. var dataLabelsGroup = w.globals.dom.Paper.select(".apexcharts-datalabels-group").members[0];
  20815. var dataLabels = this.renderInnerDataLabels(dataLabelsGroup, this.donutDataLabels, {
  20816. hollowSize: this.donutSize,
  20817. centerX: this.centerX,
  20818. centerY: this.centerY,
  20819. opacity: this.donutDataLabels.show
  20820. });
  20821. var elPie = w.globals.dom.Paper.select('.apexcharts-radialbar, .apexcharts-pie').members[0];
  20822. elPie.add(dataLabels);
  20823. }
  20824. }
  20825. }]);
  20826. return Pie;
  20827. }();
  20828. /**
  20829. * ApexCharts Radar Class for Spider/Radar Charts.
  20830. * @module Radar
  20831. **/
  20832. var Radar = /*#__PURE__*/function () {
  20833. function Radar(ctx) {
  20834. _classCallCheck(this, Radar);
  20835. this.ctx = ctx;
  20836. this.w = ctx.w;
  20837. this.chartType = this.w.config.chart.type;
  20838. this.initialAnim = this.w.config.chart.animations.enabled;
  20839. this.dynamicAnim = this.initialAnim && this.w.config.chart.animations.dynamicAnimation.enabled;
  20840. this.animDur = 0;
  20841. var w = this.w;
  20842. this.graphics = new Graphics(this.ctx);
  20843. this.lineColorArr = w.globals.stroke.colors !== undefined ? w.globals.stroke.colors : w.globals.colors;
  20844. this.defaultSize = w.globals.svgHeight < w.globals.svgWidth ? w.globals.gridHeight : w.globals.gridWidth;
  20845. this.isLog = w.config.yaxis[0].logarithmic;
  20846. this.logBase = w.config.yaxis[0].logBase;
  20847. this.coreUtils = new CoreUtils(this.ctx);
  20848. this.maxValue = this.isLog ? this.coreUtils.getLogVal(this.logBase, w.globals.maxY, 0) : w.globals.maxY;
  20849. this.minValue = this.isLog ? this.coreUtils.getLogVal(this.logBase, this.w.globals.minY, 0) : w.globals.minY;
  20850. this.polygons = w.config.plotOptions.radar.polygons;
  20851. this.strokeWidth = w.config.stroke.show ? w.config.stroke.width : 0;
  20852. this.size = this.defaultSize / 2.1 - this.strokeWidth - w.config.chart.dropShadow.blur;
  20853. if (w.config.xaxis.labels.show) {
  20854. this.size = this.size - w.globals.xAxisLabelsWidth / 1.75;
  20855. }
  20856. if (w.config.plotOptions.radar.size !== undefined) {
  20857. this.size = w.config.plotOptions.radar.size;
  20858. }
  20859. this.dataRadiusOfPercent = [];
  20860. this.dataRadius = [];
  20861. this.angleArr = [];
  20862. this.yaxisLabelsTextsPos = [];
  20863. }
  20864. _createClass(Radar, [{
  20865. key: "draw",
  20866. value: function draw(series) {
  20867. var _this = this;
  20868. var w = this.w;
  20869. var fill = new Fill(this.ctx);
  20870. var allSeries = [];
  20871. var dataLabels = new DataLabels(this.ctx);
  20872. if (series.length) {
  20873. this.dataPointsLen = series[w.globals.maxValsInArrayIndex].length;
  20874. }
  20875. this.disAngle = Math.PI * 2 / this.dataPointsLen;
  20876. var halfW = w.globals.gridWidth / 2;
  20877. var halfH = w.globals.gridHeight / 2;
  20878. var translateX = halfW + w.config.plotOptions.radar.offsetX;
  20879. var translateY = halfH + w.config.plotOptions.radar.offsetY;
  20880. var ret = this.graphics.group({
  20881. class: 'apexcharts-radar-series apexcharts-plot-series',
  20882. transform: "translate(".concat(translateX || 0, ", ").concat(translateY || 0, ")")
  20883. });
  20884. var dataPointsPos = [];
  20885. var elPointsMain = null;
  20886. var elDataPointsMain = null;
  20887. this.yaxisLabels = this.graphics.group({
  20888. class: 'apexcharts-yaxis'
  20889. });
  20890. series.forEach(function (s, i) {
  20891. var longestSeries = s.length === w.globals.dataPoints;
  20892. // el to which series will be drawn
  20893. var elSeries = _this.graphics.group().attr({
  20894. class: "apexcharts-series",
  20895. 'data:longestSeries': longestSeries,
  20896. seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
  20897. rel: i + 1,
  20898. 'data:realIndex': i
  20899. });
  20900. _this.dataRadiusOfPercent[i] = [];
  20901. _this.dataRadius[i] = [];
  20902. _this.angleArr[i] = [];
  20903. s.forEach(function (dv, j) {
  20904. var range = Math.abs(_this.maxValue - _this.minValue);
  20905. dv = dv - _this.minValue;
  20906. if (_this.isLog) {
  20907. dv = _this.coreUtils.getLogVal(_this.logBase, dv, 0);
  20908. }
  20909. _this.dataRadiusOfPercent[i][j] = dv / range;
  20910. _this.dataRadius[i][j] = _this.dataRadiusOfPercent[i][j] * _this.size;
  20911. _this.angleArr[i][j] = j * _this.disAngle;
  20912. });
  20913. dataPointsPos = _this.getDataPointsPos(_this.dataRadius[i], _this.angleArr[i]);
  20914. var paths = _this.createPaths(dataPointsPos, {
  20915. x: 0,
  20916. y: 0
  20917. });
  20918. // points
  20919. elPointsMain = _this.graphics.group({
  20920. class: 'apexcharts-series-markers-wrap apexcharts-element-hidden'
  20921. });
  20922. // datapoints
  20923. elDataPointsMain = _this.graphics.group({
  20924. class: "apexcharts-datalabels",
  20925. 'data:realIndex': i
  20926. });
  20927. w.globals.delayedElements.push({
  20928. el: elPointsMain.node,
  20929. index: i
  20930. });
  20931. var defaultRenderedPathOptions = {
  20932. i: i,
  20933. realIndex: i,
  20934. animationDelay: i,
  20935. initialSpeed: w.config.chart.animations.speed,
  20936. dataChangeSpeed: w.config.chart.animations.dynamicAnimation.speed,
  20937. className: "apexcharts-radar",
  20938. shouldClipToGrid: false,
  20939. bindEventsOnPaths: false,
  20940. stroke: w.globals.stroke.colors[i],
  20941. strokeLineCap: w.config.stroke.lineCap
  20942. };
  20943. var pathFrom = null;
  20944. if (w.globals.previousPaths.length > 0) {
  20945. pathFrom = _this.getPreviousPath(i);
  20946. }
  20947. for (var p = 0; p < paths.linePathsTo.length; p++) {
  20948. var renderedLinePath = _this.graphics.renderPaths(_objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
  20949. pathFrom: pathFrom === null ? paths.linePathsFrom[p] : pathFrom,
  20950. pathTo: paths.linePathsTo[p],
  20951. strokeWidth: Array.isArray(_this.strokeWidth) ? _this.strokeWidth[i] : _this.strokeWidth,
  20952. fill: 'none',
  20953. drawShadow: false
  20954. }));
  20955. elSeries.add(renderedLinePath);
  20956. var pathFill = fill.fillPath({
  20957. seriesNumber: i
  20958. });
  20959. var renderedAreaPath = _this.graphics.renderPaths(_objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
  20960. pathFrom: pathFrom === null ? paths.areaPathsFrom[p] : pathFrom,
  20961. pathTo: paths.areaPathsTo[p],
  20962. strokeWidth: 0,
  20963. fill: pathFill,
  20964. drawShadow: false
  20965. }));
  20966. if (w.config.chart.dropShadow.enabled) {
  20967. var filters = new Filters(_this.ctx);
  20968. var shadow = w.config.chart.dropShadow;
  20969. filters.dropShadow(renderedAreaPath, Object.assign({}, shadow, {
  20970. noUserSpaceOnUse: true
  20971. }), i);
  20972. }
  20973. elSeries.add(renderedAreaPath);
  20974. }
  20975. s.forEach(function (sj, j) {
  20976. var markers = new Markers(_this.ctx);
  20977. var opts = markers.getMarkerConfig({
  20978. cssClass: 'apexcharts-marker',
  20979. seriesIndex: i,
  20980. dataPointIndex: j
  20981. });
  20982. var point = _this.graphics.drawMarker(dataPointsPos[j].x, dataPointsPos[j].y, opts);
  20983. point.attr('rel', j);
  20984. point.attr('j', j);
  20985. point.attr('index', i);
  20986. point.node.setAttribute('default-marker-size', opts.pSize);
  20987. var elPointsWrap = _this.graphics.group({
  20988. class: 'apexcharts-series-markers'
  20989. });
  20990. if (elPointsWrap) {
  20991. elPointsWrap.add(point);
  20992. }
  20993. elPointsMain.add(elPointsWrap);
  20994. elSeries.add(elPointsMain);
  20995. var dataLabelsConfig = w.config.dataLabels;
  20996. if (dataLabelsConfig.enabled) {
  20997. var text = dataLabelsConfig.formatter(w.globals.series[i][j], {
  20998. seriesIndex: i,
  20999. dataPointIndex: j,
  21000. w: w
  21001. });
  21002. dataLabels.plotDataLabelsText({
  21003. x: dataPointsPos[j].x,
  21004. y: dataPointsPos[j].y,
  21005. text: text,
  21006. textAnchor: 'middle',
  21007. i: i,
  21008. j: i,
  21009. parent: elDataPointsMain,
  21010. offsetCorrection: false,
  21011. dataLabelsConfig: _objectSpread2({}, dataLabelsConfig)
  21012. });
  21013. }
  21014. elSeries.add(elDataPointsMain);
  21015. });
  21016. allSeries.push(elSeries);
  21017. });
  21018. this.drawPolygons({
  21019. parent: ret
  21020. });
  21021. if (w.config.xaxis.labels.show) {
  21022. var xaxisTexts = this.drawXAxisTexts();
  21023. ret.add(xaxisTexts);
  21024. }
  21025. allSeries.forEach(function (elS) {
  21026. ret.add(elS);
  21027. });
  21028. ret.add(this.yaxisLabels);
  21029. return ret;
  21030. }
  21031. }, {
  21032. key: "drawPolygons",
  21033. value: function drawPolygons(opts) {
  21034. var _this2 = this;
  21035. var w = this.w;
  21036. var parent = opts.parent;
  21037. var helpers = new CircularChartsHelpers(this.ctx);
  21038. var yaxisTexts = w.globals.yAxisScale[0].result.reverse();
  21039. var layers = yaxisTexts.length;
  21040. var radiusSizes = [];
  21041. var layerDis = this.size / (layers - 1);
  21042. for (var i = 0; i < layers; i++) {
  21043. radiusSizes[i] = layerDis * i;
  21044. }
  21045. radiusSizes.reverse();
  21046. var polygonStrings = [];
  21047. var lines = [];
  21048. radiusSizes.forEach(function (radiusSize, r) {
  21049. var polygon = Utils$1.getPolygonPos(radiusSize, _this2.dataPointsLen);
  21050. var string = '';
  21051. polygon.forEach(function (p, i) {
  21052. if (r === 0) {
  21053. var line = _this2.graphics.drawLine(p.x, p.y, 0, 0, Array.isArray(_this2.polygons.connectorColors) ? _this2.polygons.connectorColors[i] : _this2.polygons.connectorColors);
  21054. lines.push(line);
  21055. }
  21056. if (i === 0) {
  21057. _this2.yaxisLabelsTextsPos.push({
  21058. x: p.x,
  21059. y: p.y
  21060. });
  21061. }
  21062. string += p.x + ',' + p.y + ' ';
  21063. });
  21064. polygonStrings.push(string);
  21065. });
  21066. polygonStrings.forEach(function (p, i) {
  21067. var strokeColors = _this2.polygons.strokeColors;
  21068. var strokeWidth = _this2.polygons.strokeWidth;
  21069. var polygon = _this2.graphics.drawPolygon(p, Array.isArray(strokeColors) ? strokeColors[i] : strokeColors, Array.isArray(strokeWidth) ? strokeWidth[i] : strokeWidth, w.globals.radarPolygons.fill.colors[i]);
  21070. parent.add(polygon);
  21071. });
  21072. lines.forEach(function (l) {
  21073. parent.add(l);
  21074. });
  21075. if (w.config.yaxis[0].show) {
  21076. this.yaxisLabelsTextsPos.forEach(function (p, i) {
  21077. var yText = helpers.drawYAxisTexts(p.x, p.y, i, yaxisTexts[i]);
  21078. _this2.yaxisLabels.add(yText);
  21079. });
  21080. }
  21081. }
  21082. }, {
  21083. key: "drawXAxisTexts",
  21084. value: function drawXAxisTexts() {
  21085. var _this3 = this;
  21086. var w = this.w;
  21087. var xaxisLabelsConfig = w.config.xaxis.labels;
  21088. var elXAxisWrap = this.graphics.group({
  21089. class: 'apexcharts-xaxis'
  21090. });
  21091. var polygonPos = Utils$1.getPolygonPos(this.size, this.dataPointsLen);
  21092. w.globals.labels.forEach(function (label, i) {
  21093. var formatter = w.config.xaxis.labels.formatter;
  21094. var dataLabels = new DataLabels(_this3.ctx);
  21095. if (polygonPos[i]) {
  21096. var textPos = _this3.getTextPos(polygonPos[i], _this3.size);
  21097. var text = formatter(label, {
  21098. seriesIndex: -1,
  21099. dataPointIndex: i,
  21100. w: w
  21101. });
  21102. var dataLabelText = dataLabels.plotDataLabelsText({
  21103. x: textPos.newX,
  21104. y: textPos.newY,
  21105. text: text,
  21106. textAnchor: textPos.textAnchor,
  21107. i: i,
  21108. j: i,
  21109. parent: elXAxisWrap,
  21110. className: 'apexcharts-xaxis-label',
  21111. color: Array.isArray(xaxisLabelsConfig.style.colors) && xaxisLabelsConfig.style.colors[i] ? xaxisLabelsConfig.style.colors[i] : '#a8a8a8',
  21112. dataLabelsConfig: _objectSpread2({
  21113. textAnchor: textPos.textAnchor,
  21114. dropShadow: {
  21115. enabled: false
  21116. }
  21117. }, xaxisLabelsConfig),
  21118. offsetCorrection: false
  21119. });
  21120. dataLabelText.on('click', function (e) {
  21121. if (typeof w.config.chart.events.xAxisLabelClick === 'function') {
  21122. var opts = Object.assign({}, w, {
  21123. labelIndex: i
  21124. });
  21125. w.config.chart.events.xAxisLabelClick(e, _this3.ctx, opts);
  21126. }
  21127. });
  21128. }
  21129. });
  21130. return elXAxisWrap;
  21131. }
  21132. }, {
  21133. key: "createPaths",
  21134. value: function createPaths(pos, origin) {
  21135. var _this4 = this;
  21136. var linePathsTo = [];
  21137. var linePathsFrom = [];
  21138. var areaPathsTo = [];
  21139. var areaPathsFrom = [];
  21140. if (pos.length) {
  21141. linePathsFrom = [this.graphics.move(origin.x, origin.y)];
  21142. areaPathsFrom = [this.graphics.move(origin.x, origin.y)];
  21143. var linePathTo = this.graphics.move(pos[0].x, pos[0].y);
  21144. var areaPathTo = this.graphics.move(pos[0].x, pos[0].y);
  21145. pos.forEach(function (p, i) {
  21146. linePathTo += _this4.graphics.line(p.x, p.y);
  21147. areaPathTo += _this4.graphics.line(p.x, p.y);
  21148. if (i === pos.length - 1) {
  21149. linePathTo += 'Z';
  21150. areaPathTo += 'Z';
  21151. }
  21152. });
  21153. linePathsTo.push(linePathTo);
  21154. areaPathsTo.push(areaPathTo);
  21155. }
  21156. return {
  21157. linePathsFrom: linePathsFrom,
  21158. linePathsTo: linePathsTo,
  21159. areaPathsFrom: areaPathsFrom,
  21160. areaPathsTo: areaPathsTo
  21161. };
  21162. }
  21163. }, {
  21164. key: "getTextPos",
  21165. value: function getTextPos(pos, polygonSize) {
  21166. var limit = 10;
  21167. var textAnchor = 'middle';
  21168. var newX = pos.x;
  21169. var newY = pos.y;
  21170. if (Math.abs(pos.x) >= limit) {
  21171. if (pos.x > 0) {
  21172. textAnchor = 'start';
  21173. newX += 10;
  21174. } else if (pos.x < 0) {
  21175. textAnchor = 'end';
  21176. newX -= 10;
  21177. }
  21178. } else {
  21179. textAnchor = 'middle';
  21180. }
  21181. if (Math.abs(pos.y) >= polygonSize - limit) {
  21182. if (pos.y < 0) {
  21183. newY -= 10;
  21184. } else if (pos.y > 0) {
  21185. newY += 10;
  21186. }
  21187. }
  21188. return {
  21189. textAnchor: textAnchor,
  21190. newX: newX,
  21191. newY: newY
  21192. };
  21193. }
  21194. }, {
  21195. key: "getPreviousPath",
  21196. value: function getPreviousPath(realIndex) {
  21197. var w = this.w;
  21198. var pathFrom = null;
  21199. for (var pp = 0; pp < w.globals.previousPaths.length; pp++) {
  21200. var gpp = w.globals.previousPaths[pp];
  21201. if (gpp.paths.length > 0 && parseInt(gpp.realIndex, 10) === parseInt(realIndex, 10)) {
  21202. if (typeof w.globals.previousPaths[pp].paths[0] !== 'undefined') {
  21203. pathFrom = w.globals.previousPaths[pp].paths[0].d;
  21204. }
  21205. }
  21206. }
  21207. return pathFrom;
  21208. }
  21209. }, {
  21210. key: "getDataPointsPos",
  21211. value: function getDataPointsPos(dataRadiusArr, angleArr) {
  21212. var dataPointsLen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.dataPointsLen;
  21213. dataRadiusArr = dataRadiusArr || [];
  21214. angleArr = angleArr || [];
  21215. var dataPointsPosArray = [];
  21216. for (var j = 0; j < dataPointsLen; j++) {
  21217. var curPointPos = {};
  21218. curPointPos.x = dataRadiusArr[j] * Math.sin(angleArr[j]);
  21219. curPointPos.y = -dataRadiusArr[j] * Math.cos(angleArr[j]);
  21220. dataPointsPosArray.push(curPointPos);
  21221. }
  21222. return dataPointsPosArray;
  21223. }
  21224. }]);
  21225. return Radar;
  21226. }();
  21227. /**
  21228. * ApexCharts Radial Class for drawing Circle / Semi Circle Charts.
  21229. * @module Radial
  21230. **/
  21231. var Radial = /*#__PURE__*/function (_Pie) {
  21232. _inherits(Radial, _Pie);
  21233. var _super = _createSuper(Radial);
  21234. function Radial(ctx) {
  21235. var _this;
  21236. _classCallCheck(this, Radial);
  21237. _this = _super.call(this, ctx);
  21238. _this.ctx = ctx;
  21239. _this.w = ctx.w;
  21240. _this.animBeginArr = [0];
  21241. _this.animDur = 0;
  21242. var w = _this.w;
  21243. _this.startAngle = w.config.plotOptions.radialBar.startAngle;
  21244. _this.endAngle = w.config.plotOptions.radialBar.endAngle;
  21245. _this.totalAngle = Math.abs(w.config.plotOptions.radialBar.endAngle - w.config.plotOptions.radialBar.startAngle);
  21246. _this.trackStartAngle = w.config.plotOptions.radialBar.track.startAngle;
  21247. _this.trackEndAngle = w.config.plotOptions.radialBar.track.endAngle;
  21248. _this.barLabels = _this.w.config.plotOptions.radialBar.barLabels;
  21249. _this.donutDataLabels = _this.w.config.plotOptions.radialBar.dataLabels;
  21250. _this.radialDataLabels = _this.donutDataLabels; // make a copy for easy reference
  21251. if (!_this.trackStartAngle) _this.trackStartAngle = _this.startAngle;
  21252. if (!_this.trackEndAngle) _this.trackEndAngle = _this.endAngle;
  21253. if (_this.endAngle === 360) _this.endAngle = 359.99;
  21254. _this.margin = parseInt(w.config.plotOptions.radialBar.track.margin, 10);
  21255. _this.onBarLabelClick = _this.onBarLabelClick.bind(_assertThisInitialized(_this));
  21256. return _this;
  21257. }
  21258. _createClass(Radial, [{
  21259. key: "draw",
  21260. value: function draw(series) {
  21261. var w = this.w;
  21262. var graphics = new Graphics(this.ctx);
  21263. var ret = graphics.group({
  21264. class: 'apexcharts-radialbar'
  21265. });
  21266. if (w.globals.noData) return ret;
  21267. var elSeries = graphics.group();
  21268. var centerY = this.defaultSize / 2;
  21269. var centerX = w.globals.gridWidth / 2;
  21270. var size = this.defaultSize / 2.05;
  21271. if (!w.config.chart.sparkline.enabled) {
  21272. size = size - w.config.stroke.width - w.config.chart.dropShadow.blur;
  21273. }
  21274. var colorArr = w.globals.fill.colors;
  21275. if (w.config.plotOptions.radialBar.track.show) {
  21276. var elTracks = this.drawTracks({
  21277. size: size,
  21278. centerX: centerX,
  21279. centerY: centerY,
  21280. colorArr: colorArr,
  21281. series: series
  21282. });
  21283. elSeries.add(elTracks);
  21284. }
  21285. var elG = this.drawArcs({
  21286. size: size,
  21287. centerX: centerX,
  21288. centerY: centerY,
  21289. colorArr: colorArr,
  21290. series: series
  21291. });
  21292. var totalAngle = 360;
  21293. if (w.config.plotOptions.radialBar.startAngle < 0) {
  21294. totalAngle = this.totalAngle;
  21295. }
  21296. var angleRatio = (360 - totalAngle) / 360;
  21297. w.globals.radialSize = size - size * angleRatio;
  21298. if (this.radialDataLabels.value.show) {
  21299. var offset = Math.max(this.radialDataLabels.value.offsetY, this.radialDataLabels.name.offsetY);
  21300. w.globals.radialSize += offset * angleRatio;
  21301. }
  21302. elSeries.add(elG.g);
  21303. if (w.config.plotOptions.radialBar.hollow.position === 'front') {
  21304. elG.g.add(elG.elHollow);
  21305. if (elG.dataLabels) {
  21306. elG.g.add(elG.dataLabels);
  21307. }
  21308. }
  21309. ret.add(elSeries);
  21310. return ret;
  21311. }
  21312. }, {
  21313. key: "drawTracks",
  21314. value: function drawTracks(opts) {
  21315. var w = this.w;
  21316. var graphics = new Graphics(this.ctx);
  21317. var g = graphics.group({
  21318. class: 'apexcharts-tracks'
  21319. });
  21320. var filters = new Filters(this.ctx);
  21321. var fill = new Fill(this.ctx);
  21322. var strokeWidth = this.getStrokeWidth(opts);
  21323. opts.size = opts.size - strokeWidth / 2;
  21324. for (var i = 0; i < opts.series.length; i++) {
  21325. var elRadialBarTrack = graphics.group({
  21326. class: 'apexcharts-radialbar-track apexcharts-track'
  21327. });
  21328. g.add(elRadialBarTrack);
  21329. elRadialBarTrack.attr({
  21330. rel: i + 1
  21331. });
  21332. opts.size = opts.size - strokeWidth - this.margin;
  21333. var trackConfig = w.config.plotOptions.radialBar.track;
  21334. var pathFill = fill.fillPath({
  21335. seriesNumber: 0,
  21336. size: opts.size,
  21337. fillColors: Array.isArray(trackConfig.background) ? trackConfig.background[i] : trackConfig.background,
  21338. solid: true
  21339. });
  21340. var startAngle = this.trackStartAngle;
  21341. var endAngle = this.trackEndAngle;
  21342. if (Math.abs(endAngle) + Math.abs(startAngle) >= 360) endAngle = 360 - Math.abs(this.startAngle) - 0.1;
  21343. var elPath = graphics.drawPath({
  21344. d: '',
  21345. stroke: pathFill,
  21346. strokeWidth: strokeWidth * parseInt(trackConfig.strokeWidth, 10) / 100,
  21347. fill: 'none',
  21348. strokeOpacity: trackConfig.opacity,
  21349. classes: 'apexcharts-radialbar-area'
  21350. });
  21351. if (trackConfig.dropShadow.enabled) {
  21352. var shadow = trackConfig.dropShadow;
  21353. filters.dropShadow(elPath, shadow);
  21354. }
  21355. elRadialBarTrack.add(elPath);
  21356. elPath.attr('id', 'apexcharts-radialbarTrack-' + i);
  21357. this.animatePaths(elPath, {
  21358. centerX: opts.centerX,
  21359. centerY: opts.centerY,
  21360. endAngle: endAngle,
  21361. startAngle: startAngle,
  21362. size: opts.size,
  21363. i: i,
  21364. totalItems: 2,
  21365. animBeginArr: 0,
  21366. dur: 0,
  21367. isTrack: true,
  21368. easing: w.globals.easing
  21369. });
  21370. }
  21371. return g;
  21372. }
  21373. }, {
  21374. key: "drawArcs",
  21375. value: function drawArcs(opts) {
  21376. var w = this.w;
  21377. // size, donutSize, centerX, centerY, colorArr, lineColorArr, sectorAngleArr, series
  21378. var graphics = new Graphics(this.ctx);
  21379. var fill = new Fill(this.ctx);
  21380. var filters = new Filters(this.ctx);
  21381. var g = graphics.group();
  21382. var strokeWidth = this.getStrokeWidth(opts);
  21383. opts.size = opts.size - strokeWidth / 2;
  21384. var hollowFillID = w.config.plotOptions.radialBar.hollow.background;
  21385. var hollowSize = opts.size - strokeWidth * opts.series.length - this.margin * opts.series.length - strokeWidth * parseInt(w.config.plotOptions.radialBar.track.strokeWidth, 10) / 100 / 2;
  21386. var hollowRadius = hollowSize - w.config.plotOptions.radialBar.hollow.margin;
  21387. if (w.config.plotOptions.radialBar.hollow.image !== undefined) {
  21388. hollowFillID = this.drawHollowImage(opts, g, hollowSize, hollowFillID);
  21389. }
  21390. var elHollow = this.drawHollow({
  21391. size: hollowRadius,
  21392. centerX: opts.centerX,
  21393. centerY: opts.centerY,
  21394. fill: hollowFillID ? hollowFillID : 'transparent'
  21395. });
  21396. if (w.config.plotOptions.radialBar.hollow.dropShadow.enabled) {
  21397. var shadow = w.config.plotOptions.radialBar.hollow.dropShadow;
  21398. filters.dropShadow(elHollow, shadow);
  21399. }
  21400. var shown = 1;
  21401. if (!this.radialDataLabels.total.show && w.globals.series.length > 1) {
  21402. shown = 0;
  21403. }
  21404. var dataLabels = null;
  21405. if (this.radialDataLabels.show) {
  21406. var dataLabelsGroup = w.globals.dom.Paper.select(".apexcharts-datalabels-group").members[0];
  21407. dataLabels = this.renderInnerDataLabels(dataLabelsGroup, this.radialDataLabels, {
  21408. hollowSize: hollowSize,
  21409. centerX: opts.centerX,
  21410. centerY: opts.centerY,
  21411. opacity: shown
  21412. });
  21413. }
  21414. if (w.config.plotOptions.radialBar.hollow.position === 'back') {
  21415. g.add(elHollow);
  21416. if (dataLabels) {
  21417. g.add(dataLabels);
  21418. }
  21419. }
  21420. var reverseLoop = false;
  21421. if (w.config.plotOptions.radialBar.inverseOrder) {
  21422. reverseLoop = true;
  21423. }
  21424. for (var i = reverseLoop ? opts.series.length - 1 : 0; reverseLoop ? i >= 0 : i < opts.series.length; reverseLoop ? i-- : i++) {
  21425. var elRadialBarArc = graphics.group({
  21426. class: "apexcharts-series apexcharts-radial-series",
  21427. seriesName: Utils$1.escapeString(w.globals.seriesNames[i])
  21428. });
  21429. g.add(elRadialBarArc);
  21430. elRadialBarArc.attr({
  21431. rel: i + 1,
  21432. 'data:realIndex': i
  21433. });
  21434. this.ctx.series.addCollapsedClassToSeries(elRadialBarArc, i);
  21435. opts.size = opts.size - strokeWidth - this.margin;
  21436. var pathFill = fill.fillPath({
  21437. seriesNumber: i,
  21438. size: opts.size,
  21439. value: opts.series[i]
  21440. });
  21441. var startAngle = this.startAngle;
  21442. var prevStartAngle = void 0;
  21443. // if data exceeds 100, make it 100
  21444. var dataValue = Utils$1.negToZero(opts.series[i] > 100 ? 100 : opts.series[i]) / 100;
  21445. var endAngle = Math.round(this.totalAngle * dataValue) + this.startAngle;
  21446. var prevEndAngle = void 0;
  21447. if (w.globals.dataChanged) {
  21448. prevStartAngle = this.startAngle;
  21449. prevEndAngle = Math.round(this.totalAngle * Utils$1.negToZero(w.globals.previousPaths[i]) / 100) + prevStartAngle;
  21450. }
  21451. var currFullAngle = Math.abs(endAngle) + Math.abs(startAngle);
  21452. if (currFullAngle > 360) {
  21453. endAngle = endAngle - 0.01;
  21454. }
  21455. var prevFullAngle = Math.abs(prevEndAngle) + Math.abs(prevStartAngle);
  21456. if (prevFullAngle > 360) {
  21457. prevEndAngle = prevEndAngle - 0.01;
  21458. }
  21459. var angle = endAngle - startAngle;
  21460. var dashArray = Array.isArray(w.config.stroke.dashArray) ? w.config.stroke.dashArray[i] : w.config.stroke.dashArray;
  21461. var elPath = graphics.drawPath({
  21462. d: '',
  21463. stroke: pathFill,
  21464. strokeWidth: strokeWidth,
  21465. fill: 'none',
  21466. fillOpacity: w.config.fill.opacity,
  21467. classes: 'apexcharts-radialbar-area apexcharts-radialbar-slice-' + i,
  21468. strokeDashArray: dashArray
  21469. });
  21470. Graphics.setAttrs(elPath.node, {
  21471. 'data:angle': angle,
  21472. 'data:value': opts.series[i]
  21473. });
  21474. if (w.config.chart.dropShadow.enabled) {
  21475. var _shadow = w.config.chart.dropShadow;
  21476. filters.dropShadow(elPath, _shadow, i);
  21477. }
  21478. filters.setSelectionFilter(elPath, 0, i);
  21479. this.addListeners(elPath, this.radialDataLabels);
  21480. elRadialBarArc.add(elPath);
  21481. elPath.attr({
  21482. index: 0,
  21483. j: i
  21484. });
  21485. if (this.barLabels.enabled) {
  21486. var barStartCords = Utils$1.polarToCartesian(opts.centerX, opts.centerY, opts.size, startAngle);
  21487. var text = this.barLabels.formatter(w.globals.seriesNames[i], {
  21488. seriesIndex: i,
  21489. w: w
  21490. });
  21491. var classes = ['apexcharts-radialbar-label'];
  21492. if (!this.barLabels.onClick) {
  21493. classes.push('apexcharts-no-click');
  21494. }
  21495. var textColor = this.barLabels.useSeriesColors ? w.globals.colors[i] : w.config.chart.foreColor;
  21496. if (!textColor) {
  21497. textColor = w.config.chart.foreColor;
  21498. }
  21499. var x = barStartCords.x + this.barLabels.offsetX;
  21500. var y = barStartCords.y + this.barLabels.offsetY;
  21501. var elText = graphics.drawText({
  21502. x: x,
  21503. y: y,
  21504. text: text,
  21505. textAnchor: 'end',
  21506. dominantBaseline: 'middle',
  21507. fontFamily: this.barLabels.fontFamily,
  21508. fontWeight: this.barLabels.fontWeight,
  21509. fontSize: this.barLabels.fontSize,
  21510. foreColor: textColor,
  21511. cssClass: classes.join(' ')
  21512. });
  21513. elText.on('click', this.onBarLabelClick);
  21514. elText.attr({
  21515. rel: i + 1
  21516. });
  21517. if (startAngle !== 0) {
  21518. elText.attr({
  21519. 'transform-origin': "".concat(x, " ").concat(y),
  21520. transform: "rotate(".concat(startAngle, " 0 0)")
  21521. });
  21522. }
  21523. elRadialBarArc.add(elText);
  21524. }
  21525. var dur = 0;
  21526. if (this.initialAnim && !w.globals.resized && !w.globals.dataChanged) {
  21527. dur = w.config.chart.animations.speed;
  21528. }
  21529. if (w.globals.dataChanged) {
  21530. dur = w.config.chart.animations.dynamicAnimation.speed;
  21531. }
  21532. this.animDur = dur / (opts.series.length * 1.2) + this.animDur;
  21533. this.animBeginArr.push(this.animDur);
  21534. this.animatePaths(elPath, {
  21535. centerX: opts.centerX,
  21536. centerY: opts.centerY,
  21537. endAngle: endAngle,
  21538. startAngle: startAngle,
  21539. prevEndAngle: prevEndAngle,
  21540. prevStartAngle: prevStartAngle,
  21541. size: opts.size,
  21542. i: i,
  21543. totalItems: 2,
  21544. animBeginArr: this.animBeginArr,
  21545. dur: dur,
  21546. shouldSetPrevPaths: true,
  21547. easing: w.globals.easing
  21548. });
  21549. }
  21550. return {
  21551. g: g,
  21552. elHollow: elHollow,
  21553. dataLabels: dataLabels
  21554. };
  21555. }
  21556. }, {
  21557. key: "drawHollow",
  21558. value: function drawHollow(opts) {
  21559. var graphics = new Graphics(this.ctx);
  21560. var circle = graphics.drawCircle(opts.size * 2);
  21561. circle.attr({
  21562. class: 'apexcharts-radialbar-hollow',
  21563. cx: opts.centerX,
  21564. cy: opts.centerY,
  21565. r: opts.size,
  21566. fill: opts.fill
  21567. });
  21568. return circle;
  21569. }
  21570. }, {
  21571. key: "drawHollowImage",
  21572. value: function drawHollowImage(opts, g, hollowSize, hollowFillID) {
  21573. var w = this.w;
  21574. var fill = new Fill(this.ctx);
  21575. var randID = Utils$1.randomId();
  21576. var hollowFillImg = w.config.plotOptions.radialBar.hollow.image;
  21577. if (w.config.plotOptions.radialBar.hollow.imageClipped) {
  21578. fill.clippedImgArea({
  21579. width: hollowSize,
  21580. height: hollowSize,
  21581. image: hollowFillImg,
  21582. patternID: "pattern".concat(w.globals.cuid).concat(randID)
  21583. });
  21584. hollowFillID = "url(#pattern".concat(w.globals.cuid).concat(randID, ")");
  21585. } else {
  21586. var imgWidth = w.config.plotOptions.radialBar.hollow.imageWidth;
  21587. var imgHeight = w.config.plotOptions.radialBar.hollow.imageHeight;
  21588. if (imgWidth === undefined && imgHeight === undefined) {
  21589. var image = w.globals.dom.Paper.image(hollowFillImg).loaded(function (loader) {
  21590. this.move(opts.centerX - loader.width / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetX, opts.centerY - loader.height / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetY);
  21591. });
  21592. g.add(image);
  21593. } else {
  21594. var _image = w.globals.dom.Paper.image(hollowFillImg).loaded(function (loader) {
  21595. this.move(opts.centerX - imgWidth / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetX, opts.centerY - imgHeight / 2 + w.config.plotOptions.radialBar.hollow.imageOffsetY);
  21596. this.size(imgWidth, imgHeight);
  21597. });
  21598. g.add(_image);
  21599. }
  21600. }
  21601. return hollowFillID;
  21602. }
  21603. }, {
  21604. key: "getStrokeWidth",
  21605. value: function getStrokeWidth(opts) {
  21606. var w = this.w;
  21607. return opts.size * (100 - parseInt(w.config.plotOptions.radialBar.hollow.size, 10)) / 100 / (opts.series.length + 1) - this.margin;
  21608. }
  21609. }, {
  21610. key: "onBarLabelClick",
  21611. value: function onBarLabelClick(e) {
  21612. var seriesIndex = parseInt(e.target.getAttribute('rel'), 10) - 1;
  21613. var legendClick = this.barLabels.onClick;
  21614. var w = this.w;
  21615. if (legendClick) {
  21616. legendClick(w.globals.seriesNames[seriesIndex], {
  21617. w: w,
  21618. seriesIndex: seriesIndex
  21619. });
  21620. }
  21621. }
  21622. }]);
  21623. return Radial;
  21624. }(Pie);
  21625. /**
  21626. * ApexCharts RangeBar Class responsible for drawing Range/Timeline Bars.
  21627. *
  21628. * @module RangeBar
  21629. **/
  21630. var RangeBar = /*#__PURE__*/function (_Bar) {
  21631. _inherits(RangeBar, _Bar);
  21632. var _super = _createSuper(RangeBar);
  21633. function RangeBar() {
  21634. _classCallCheck(this, RangeBar);
  21635. return _super.apply(this, arguments);
  21636. }
  21637. _createClass(RangeBar, [{
  21638. key: "draw",
  21639. value: function draw(series, seriesIndex) {
  21640. var w = this.w;
  21641. var graphics = new Graphics(this.ctx);
  21642. this.rangeBarOptions = this.w.config.plotOptions.rangeBar;
  21643. this.series = series;
  21644. this.seriesRangeStart = w.globals.seriesRangeStart;
  21645. this.seriesRangeEnd = w.globals.seriesRangeEnd;
  21646. this.barHelpers.initVariables(series);
  21647. var ret = graphics.group({
  21648. class: 'apexcharts-rangebar-series apexcharts-plot-series'
  21649. });
  21650. for (var i = 0; i < series.length; i++) {
  21651. var x = void 0,
  21652. y = void 0,
  21653. xDivision = void 0,
  21654. // xDivision is the GRIDWIDTH divided by number of datapoints (columns)
  21655. yDivision = void 0,
  21656. // yDivision is the GRIDHEIGHT divided by number of datapoints (bars)
  21657. zeroH = void 0,
  21658. // zeroH is the baseline where 0 meets y axis
  21659. zeroW = void 0; // zeroW is the baseline where 0 meets x axis
  21660. var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
  21661. var _this$barHelpers$getG = this.barHelpers.getGroupIndex(realIndex),
  21662. columnGroupIndex = _this$barHelpers$getG.columnGroupIndex;
  21663. // el to which series will be drawn
  21664. var elSeries = graphics.group({
  21665. class: "apexcharts-series",
  21666. seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex]),
  21667. rel: i + 1,
  21668. 'data:realIndex': realIndex
  21669. });
  21670. this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex);
  21671. if (series[i].length > 0) {
  21672. this.visibleI = this.visibleI + 1;
  21673. }
  21674. var barHeight = 0;
  21675. var barWidth = 0;
  21676. var translationsIndex = 0;
  21677. if (this.yRatio.length > 1) {
  21678. this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0];
  21679. translationsIndex = realIndex;
  21680. }
  21681. var initPositions = this.barHelpers.initialPositions();
  21682. y = initPositions.y;
  21683. zeroW = initPositions.zeroW;
  21684. x = initPositions.x;
  21685. barWidth = initPositions.barWidth;
  21686. barHeight = initPositions.barHeight;
  21687. xDivision = initPositions.xDivision;
  21688. yDivision = initPositions.yDivision;
  21689. zeroH = initPositions.zeroH;
  21690. // eldatalabels
  21691. var elDataLabelsWrap = graphics.group({
  21692. class: 'apexcharts-datalabels',
  21693. 'data:realIndex': realIndex
  21694. });
  21695. var elGoalsMarkers = graphics.group({
  21696. class: 'apexcharts-rangebar-goals-markers'
  21697. });
  21698. for (var j = 0; j < w.globals.dataPoints; j++) {
  21699. var strokeWidth = this.barHelpers.getStrokeWidth(i, j, realIndex);
  21700. var y1 = this.seriesRangeStart[i][j];
  21701. var y2 = this.seriesRangeEnd[i][j];
  21702. var paths = null;
  21703. var barXPosition = null;
  21704. var barYPosition = null;
  21705. var params = {
  21706. x: x,
  21707. y: y,
  21708. strokeWidth: strokeWidth,
  21709. elSeries: elSeries
  21710. };
  21711. var seriesLen = this.seriesLen;
  21712. if (w.config.plotOptions.bar.rangeBarGroupRows) {
  21713. seriesLen = 1;
  21714. }
  21715. if (typeof w.config.series[i].data[j] === 'undefined') {
  21716. // no data exists for further indexes, hence we need to get out the innr loop.
  21717. // As we are iterating over total datapoints, there is a possiblity the series might not have data for j index
  21718. break;
  21719. }
  21720. if (this.isHorizontal) {
  21721. barYPosition = y + barHeight * this.visibleI;
  21722. var srty = (yDivision - barHeight * seriesLen) / 2;
  21723. if (w.config.series[i].data[j].x) {
  21724. var positions = this.detectOverlappingBars({
  21725. i: i,
  21726. j: j,
  21727. barYPosition: barYPosition,
  21728. srty: srty,
  21729. barHeight: barHeight,
  21730. yDivision: yDivision,
  21731. initPositions: initPositions
  21732. });
  21733. barHeight = positions.barHeight;
  21734. barYPosition = positions.barYPosition;
  21735. }
  21736. paths = this.drawRangeBarPaths(_objectSpread2({
  21737. indexes: {
  21738. i: i,
  21739. j: j,
  21740. realIndex: realIndex
  21741. },
  21742. barHeight: barHeight,
  21743. barYPosition: barYPosition,
  21744. zeroW: zeroW,
  21745. yDivision: yDivision,
  21746. y1: y1,
  21747. y2: y2
  21748. }, params));
  21749. barWidth = paths.barWidth;
  21750. } else {
  21751. if (w.globals.isXNumeric) {
  21752. x = (w.globals.seriesX[i][j] - w.globals.minX) / this.xRatio - barWidth / 2;
  21753. }
  21754. barXPosition = x + barWidth * this.visibleI;
  21755. var srtx = (xDivision - barWidth * seriesLen) / 2;
  21756. if (w.config.series[i].data[j].x) {
  21757. var _positions = this.detectOverlappingBars({
  21758. i: i,
  21759. j: j,
  21760. barXPosition: barXPosition,
  21761. srtx: srtx,
  21762. barWidth: barWidth,
  21763. xDivision: xDivision,
  21764. initPositions: initPositions
  21765. });
  21766. barWidth = _positions.barWidth;
  21767. barXPosition = _positions.barXPosition;
  21768. }
  21769. paths = this.drawRangeColumnPaths(_objectSpread2({
  21770. indexes: {
  21771. i: i,
  21772. j: j,
  21773. realIndex: realIndex,
  21774. translationsIndex: translationsIndex
  21775. },
  21776. barWidth: barWidth,
  21777. barXPosition: barXPosition,
  21778. zeroH: zeroH,
  21779. xDivision: xDivision
  21780. }, params));
  21781. barHeight = paths.barHeight;
  21782. }
  21783. var barGoalLine = this.barHelpers.drawGoalLine({
  21784. barXPosition: paths.barXPosition,
  21785. barYPosition: barYPosition,
  21786. goalX: paths.goalX,
  21787. goalY: paths.goalY,
  21788. barHeight: barHeight,
  21789. barWidth: barWidth
  21790. });
  21791. if (barGoalLine) {
  21792. elGoalsMarkers.add(barGoalLine);
  21793. }
  21794. y = paths.y;
  21795. x = paths.x;
  21796. var pathFill = this.barHelpers.getPathFillColor(series, i, j, realIndex);
  21797. var lineFill = w.globals.stroke.colors[realIndex];
  21798. this.renderSeries({
  21799. realIndex: realIndex,
  21800. pathFill: pathFill,
  21801. lineFill: lineFill,
  21802. j: j,
  21803. i: i,
  21804. x: x,
  21805. y: y,
  21806. y1: y1,
  21807. y2: y2,
  21808. pathFrom: paths.pathFrom,
  21809. pathTo: paths.pathTo,
  21810. strokeWidth: strokeWidth,
  21811. elSeries: elSeries,
  21812. series: series,
  21813. barHeight: barHeight,
  21814. barWidth: barWidth,
  21815. barXPosition: barXPosition,
  21816. barYPosition: barYPosition,
  21817. columnGroupIndex: columnGroupIndex,
  21818. elDataLabelsWrap: elDataLabelsWrap,
  21819. elGoalsMarkers: elGoalsMarkers,
  21820. visibleSeries: this.visibleI,
  21821. type: 'rangebar'
  21822. });
  21823. }
  21824. ret.add(elSeries);
  21825. }
  21826. return ret;
  21827. }
  21828. }, {
  21829. key: "detectOverlappingBars",
  21830. value: function detectOverlappingBars(_ref) {
  21831. var i = _ref.i,
  21832. j = _ref.j,
  21833. barYPosition = _ref.barYPosition,
  21834. barXPosition = _ref.barXPosition,
  21835. srty = _ref.srty,
  21836. srtx = _ref.srtx,
  21837. barHeight = _ref.barHeight,
  21838. barWidth = _ref.barWidth,
  21839. yDivision = _ref.yDivision,
  21840. xDivision = _ref.xDivision,
  21841. initPositions = _ref.initPositions;
  21842. var w = this.w;
  21843. var overlaps = [];
  21844. var rangeName = w.config.series[i].data[j].rangeName;
  21845. var x = w.config.series[i].data[j].x;
  21846. var labelX = Array.isArray(x) ? x.join(' ') : x;
  21847. var rowIndex = w.globals.labels.map(function (_) {
  21848. return Array.isArray(_) ? _.join(' ') : _;
  21849. }).indexOf(labelX);
  21850. var overlappedIndex = w.globals.seriesRange[i].findIndex(function (tx) {
  21851. return tx.x === labelX && tx.overlaps.length > 0;
  21852. });
  21853. if (this.isHorizontal) {
  21854. if (w.config.plotOptions.bar.rangeBarGroupRows) {
  21855. barYPosition = srty + yDivision * rowIndex;
  21856. } else {
  21857. barYPosition = srty + barHeight * this.visibleI + yDivision * rowIndex;
  21858. }
  21859. if (overlappedIndex > -1 && !w.config.plotOptions.bar.rangeBarOverlap) {
  21860. overlaps = w.globals.seriesRange[i][overlappedIndex].overlaps;
  21861. if (overlaps.indexOf(rangeName) > -1) {
  21862. barHeight = initPositions.barHeight / overlaps.length;
  21863. barYPosition = barHeight * this.visibleI + yDivision * (100 - parseInt(this.barOptions.barHeight, 10)) / 100 / 2 + barHeight * (this.visibleI + overlaps.indexOf(rangeName)) + yDivision * rowIndex;
  21864. }
  21865. }
  21866. } else {
  21867. if (rowIndex > -1 && !w.globals.timescaleLabels.length) {
  21868. if (w.config.plotOptions.bar.rangeBarGroupRows) {
  21869. barXPosition = srtx + xDivision * rowIndex;
  21870. } else {
  21871. barXPosition = srtx + barWidth * this.visibleI + xDivision * rowIndex;
  21872. }
  21873. }
  21874. if (overlappedIndex > -1 && !w.config.plotOptions.bar.rangeBarOverlap) {
  21875. overlaps = w.globals.seriesRange[i][overlappedIndex].overlaps;
  21876. if (overlaps.indexOf(rangeName) > -1) {
  21877. barWidth = initPositions.barWidth / overlaps.length;
  21878. barXPosition = barWidth * this.visibleI + xDivision * (100 - parseInt(this.barOptions.barWidth, 10)) / 100 / 2 + barWidth * (this.visibleI + overlaps.indexOf(rangeName)) + xDivision * rowIndex;
  21879. }
  21880. }
  21881. }
  21882. return {
  21883. barYPosition: barYPosition,
  21884. barXPosition: barXPosition,
  21885. barHeight: barHeight,
  21886. barWidth: barWidth
  21887. };
  21888. }
  21889. }, {
  21890. key: "drawRangeColumnPaths",
  21891. value: function drawRangeColumnPaths(_ref2) {
  21892. var indexes = _ref2.indexes,
  21893. x = _ref2.x,
  21894. xDivision = _ref2.xDivision,
  21895. barWidth = _ref2.barWidth,
  21896. barXPosition = _ref2.barXPosition,
  21897. zeroH = _ref2.zeroH;
  21898. var w = this.w;
  21899. var i = indexes.i,
  21900. j = indexes.j,
  21901. realIndex = indexes.realIndex,
  21902. translationsIndex = indexes.translationsIndex;
  21903. var yRatio = this.yRatio[translationsIndex];
  21904. var range = this.getRangeValue(realIndex, j);
  21905. var y1 = Math.min(range.start, range.end);
  21906. var y2 = Math.max(range.start, range.end);
  21907. if (typeof this.series[i][j] === 'undefined' || this.series[i][j] === null) {
  21908. y1 = zeroH;
  21909. } else {
  21910. y1 = zeroH - y1 / yRatio;
  21911. y2 = zeroH - y2 / yRatio;
  21912. }
  21913. var barHeight = Math.abs(y2 - y1);
  21914. var paths = this.barHelpers.getColumnPaths({
  21915. barXPosition: barXPosition,
  21916. barWidth: barWidth,
  21917. y1: y1,
  21918. y2: y2,
  21919. strokeWidth: this.strokeWidth,
  21920. series: this.seriesRangeEnd,
  21921. realIndex: realIndex,
  21922. i: realIndex,
  21923. j: j,
  21924. w: w
  21925. });
  21926. if (!w.globals.isXNumeric) {
  21927. x = x + xDivision;
  21928. } else {
  21929. var xForNumericXAxis = this.getBarXForNumericXAxis({
  21930. x: x,
  21931. j: j,
  21932. realIndex: realIndex,
  21933. barWidth: barWidth
  21934. });
  21935. x = xForNumericXAxis.x;
  21936. barXPosition = xForNumericXAxis.barXPosition;
  21937. }
  21938. return {
  21939. pathTo: paths.pathTo,
  21940. pathFrom: paths.pathFrom,
  21941. barHeight: barHeight,
  21942. x: x,
  21943. y: range.start < 0 && range.end < 0 ? y1 : y2,
  21944. goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
  21945. barXPosition: barXPosition
  21946. };
  21947. }
  21948. }, {
  21949. key: "preventBarOverflow",
  21950. value: function preventBarOverflow(val) {
  21951. var w = this.w;
  21952. if (val < 0) {
  21953. val = 0;
  21954. }
  21955. if (val > w.globals.gridWidth) {
  21956. val = w.globals.gridWidth;
  21957. }
  21958. return val;
  21959. }
  21960. }, {
  21961. key: "drawRangeBarPaths",
  21962. value: function drawRangeBarPaths(_ref3) {
  21963. var indexes = _ref3.indexes,
  21964. y = _ref3.y,
  21965. y1 = _ref3.y1,
  21966. y2 = _ref3.y2,
  21967. yDivision = _ref3.yDivision,
  21968. barHeight = _ref3.barHeight,
  21969. barYPosition = _ref3.barYPosition,
  21970. zeroW = _ref3.zeroW;
  21971. var w = this.w;
  21972. var realIndex = indexes.realIndex,
  21973. j = indexes.j;
  21974. var x1 = this.preventBarOverflow(zeroW + y1 / this.invertedYRatio);
  21975. var x2 = this.preventBarOverflow(zeroW + y2 / this.invertedYRatio);
  21976. var range = this.getRangeValue(realIndex, j);
  21977. var barWidth = Math.abs(x2 - x1);
  21978. var paths = this.barHelpers.getBarpaths({
  21979. barYPosition: barYPosition,
  21980. barHeight: barHeight,
  21981. x1: x1,
  21982. x2: x2,
  21983. strokeWidth: this.strokeWidth,
  21984. series: this.seriesRangeEnd,
  21985. i: realIndex,
  21986. realIndex: realIndex,
  21987. j: j,
  21988. w: w
  21989. });
  21990. if (!w.globals.isXNumeric) {
  21991. y = y + yDivision;
  21992. }
  21993. return {
  21994. pathTo: paths.pathTo,
  21995. pathFrom: paths.pathFrom,
  21996. barWidth: barWidth,
  21997. x: range.start < 0 && range.end < 0 ? x1 : x2,
  21998. goalX: this.barHelpers.getGoalValues('x', zeroW, null, realIndex, j),
  21999. y: y
  22000. };
  22001. }
  22002. }, {
  22003. key: "getRangeValue",
  22004. value: function getRangeValue(i, j) {
  22005. var w = this.w;
  22006. return {
  22007. start: w.globals.seriesRangeStart[i][j],
  22008. end: w.globals.seriesRangeEnd[i][j]
  22009. };
  22010. }
  22011. }]);
  22012. return RangeBar;
  22013. }(Bar);
  22014. var Helpers = /*#__PURE__*/function () {
  22015. function Helpers(lineCtx) {
  22016. _classCallCheck(this, Helpers);
  22017. this.w = lineCtx.w;
  22018. this.lineCtx = lineCtx;
  22019. }
  22020. _createClass(Helpers, [{
  22021. key: "sameValueSeriesFix",
  22022. value: function sameValueSeriesFix(i, series) {
  22023. var w = this.w;
  22024. if (w.config.fill.type === 'gradient' || w.config.fill.type[i] === 'gradient') {
  22025. var coreUtils = new CoreUtils(this.lineCtx.ctx, w);
  22026. // applied only to LINE chart
  22027. // a small adjustment to allow gradient line to draw correctly for all same values
  22028. /* #fix https://github.com/apexcharts/apexcharts.js/issues/358 */
  22029. if (coreUtils.seriesHaveSameValues(i)) {
  22030. var gSeries = series[i].slice();
  22031. gSeries[gSeries.length - 1] = gSeries[gSeries.length - 1] + 0.000001;
  22032. series[i] = gSeries;
  22033. }
  22034. }
  22035. return series;
  22036. }
  22037. }, {
  22038. key: "calculatePoints",
  22039. value: function calculatePoints(_ref) {
  22040. var series = _ref.series,
  22041. realIndex = _ref.realIndex,
  22042. x = _ref.x,
  22043. y = _ref.y,
  22044. i = _ref.i,
  22045. j = _ref.j,
  22046. prevY = _ref.prevY;
  22047. var w = this.w;
  22048. var ptX = [];
  22049. var ptY = [];
  22050. if (j === 0) {
  22051. var xPT1st = this.lineCtx.categoryAxisCorrection + w.config.markers.offsetX;
  22052. // the first point for line series
  22053. // we need to check whether it's not a time series, because a time series may
  22054. // start from the middle of the x axis
  22055. if (w.globals.isXNumeric) {
  22056. xPT1st = (w.globals.seriesX[realIndex][0] - w.globals.minX) / this.lineCtx.xRatio + w.config.markers.offsetX;
  22057. }
  22058. // push 2 points for the first data values
  22059. ptX.push(xPT1st);
  22060. ptY.push(Utils$1.isNumber(series[i][0]) ? prevY + w.config.markers.offsetY : null);
  22061. ptX.push(x + w.config.markers.offsetX);
  22062. ptY.push(Utils$1.isNumber(series[i][j + 1]) ? y + w.config.markers.offsetY : null);
  22063. } else {
  22064. ptX.push(x + w.config.markers.offsetX);
  22065. ptY.push(Utils$1.isNumber(series[i][j + 1]) ? y + w.config.markers.offsetY : null);
  22066. }
  22067. var pointsPos = {
  22068. x: ptX,
  22069. y: ptY
  22070. };
  22071. return pointsPos;
  22072. }
  22073. }, {
  22074. key: "checkPreviousPaths",
  22075. value: function checkPreviousPaths(_ref2) {
  22076. var pathFromLine = _ref2.pathFromLine,
  22077. pathFromArea = _ref2.pathFromArea,
  22078. realIndex = _ref2.realIndex;
  22079. var w = this.w;
  22080. for (var pp = 0; pp < w.globals.previousPaths.length; pp++) {
  22081. var gpp = w.globals.previousPaths[pp];
  22082. if ((gpp.type === 'line' || gpp.type === 'area') && gpp.paths.length > 0 && parseInt(gpp.realIndex, 10) === parseInt(realIndex, 10)) {
  22083. if (gpp.type === 'line') {
  22084. this.lineCtx.appendPathFrom = false;
  22085. pathFromLine = w.globals.previousPaths[pp].paths[0].d;
  22086. } else if (gpp.type === 'area') {
  22087. this.lineCtx.appendPathFrom = false;
  22088. pathFromArea = w.globals.previousPaths[pp].paths[0].d;
  22089. if (w.config.stroke.show && w.globals.previousPaths[pp].paths[1]) {
  22090. pathFromLine = w.globals.previousPaths[pp].paths[1].d;
  22091. }
  22092. }
  22093. }
  22094. }
  22095. return {
  22096. pathFromLine: pathFromLine,
  22097. pathFromArea: pathFromArea
  22098. };
  22099. }
  22100. }, {
  22101. key: "determineFirstPrevY",
  22102. value: function determineFirstPrevY(_ref3) {
  22103. var _this$w$config$series, _this$w$config$series2, _series$i;
  22104. var i = _ref3.i,
  22105. realIndex = _ref3.realIndex,
  22106. series = _ref3.series,
  22107. prevY = _ref3.prevY,
  22108. lineYPosition = _ref3.lineYPosition,
  22109. translationsIndex = _ref3.translationsIndex;
  22110. var w = this.w;
  22111. 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');
  22112. if (typeof ((_series$i = series[i]) === null || _series$i === void 0 ? void 0 : _series$i[0]) !== 'undefined') {
  22113. if (stackSeries) {
  22114. if (i > 0) {
  22115. // 1st y value of previous series
  22116. lineYPosition = this.lineCtx.prevSeriesY[i - 1][0];
  22117. } else {
  22118. // the first series will not have prevY values
  22119. lineYPosition = this.lineCtx.zeroY;
  22120. }
  22121. } else {
  22122. lineYPosition = this.lineCtx.zeroY;
  22123. }
  22124. prevY = lineYPosition - series[i][0] / this.lineCtx.yRatio[translationsIndex] + (this.lineCtx.isReversed ? series[i][0] / this.lineCtx.yRatio[translationsIndex] : 0) * 2;
  22125. } else {
  22126. // the first value in the current series is null
  22127. if (stackSeries && i > 0 && typeof series[i][0] === 'undefined') {
  22128. // check for undefined value (undefined value will occur when we clear the series while user clicks on legend to hide serieses)
  22129. for (var s = i - 1; s >= 0; s--) {
  22130. // for loop to get to 1st previous value until we get it
  22131. if (series[s][0] !== null && typeof series[s][0] !== 'undefined') {
  22132. lineYPosition = this.lineCtx.prevSeriesY[s][0];
  22133. prevY = lineYPosition;
  22134. break;
  22135. }
  22136. }
  22137. }
  22138. }
  22139. return {
  22140. prevY: prevY,
  22141. lineYPosition: lineYPosition
  22142. };
  22143. }
  22144. }]);
  22145. return Helpers;
  22146. }();
  22147. /**
  22148. *
  22149. * @yr/monotone-cubic-spline (https://github.com/YR/monotone-cubic-spline)
  22150. *
  22151. * The MIT License (MIT)
  22152. *
  22153. * Copyright (c) 2015 yr.no
  22154. *
  22155. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  22156. * this software and associated documentation files (the "Software"), to deal in
  22157. * the Software without restriction, including without limitation the rights to
  22158. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  22159. * the Software, and to permit persons to whom the Software is furnished to do so,
  22160. * subject to the following conditions:
  22161. *
  22162. * The above copyright notice and this permission notice shall be included in all
  22163. * copies or substantial portions of the Software.
  22164. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22165. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  22166. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  22167. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  22168. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22169. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22170. */
  22171. /**
  22172. * Generate tangents for 'points'
  22173. * @param {Array} points
  22174. * @returns {Array}
  22175. */
  22176. var tangents = function tangents(points) {
  22177. var m = finiteDifferences(points);
  22178. var n = points.length - 1;
  22179. var ε = 1e-6;
  22180. var tgts = [];
  22181. var a, b, d, s;
  22182. for (var i = 0; i < n; i++) {
  22183. d = slope(points[i], points[i + 1]);
  22184. if (Math.abs(d) < ε) {
  22185. m[i] = m[i + 1] = 0;
  22186. } else {
  22187. a = m[i] / d;
  22188. b = m[i + 1] / d;
  22189. s = a * a + b * b;
  22190. if (s > 9) {
  22191. s = d * 3 / Math.sqrt(s);
  22192. m[i] = s * a;
  22193. m[i + 1] = s * b;
  22194. }
  22195. }
  22196. }
  22197. for (var _i = 0; _i <= n; _i++) {
  22198. s = (points[Math.min(n, _i + 1)][0] - points[Math.max(0, _i - 1)][0]) / (6 * (1 + m[_i] * m[_i]));
  22199. tgts.push([s || 0, m[_i] * s || 0]);
  22200. }
  22201. return tgts;
  22202. };
  22203. /**
  22204. * Convert 'points' to svg path
  22205. * @param {Array} points
  22206. * @returns {String}
  22207. */
  22208. var svgPath = function svgPath(points) {
  22209. var p = '';
  22210. for (var i = 0; i < points.length; i++) {
  22211. var point = points[i];
  22212. var n = point.length;
  22213. if (n > 4) {
  22214. p += "C".concat(point[0], ", ").concat(point[1]);
  22215. p += ", ".concat(point[2], ", ").concat(point[3]);
  22216. p += ", ".concat(point[4], ", ").concat(point[5]);
  22217. } else if (n > 2) {
  22218. p += "S".concat(point[0], ", ").concat(point[1]);
  22219. p += ", ".concat(point[2], ", ").concat(point[3]);
  22220. }
  22221. }
  22222. return p;
  22223. };
  22224. var spline = {
  22225. /**
  22226. * Convert 'points' to bezier
  22227. * @param {Array} points
  22228. * @returns {Array}
  22229. */
  22230. points: function points(_points) {
  22231. var tgts = tangents(_points);
  22232. var p = _points[1];
  22233. var p0 = _points[0];
  22234. var pts = [];
  22235. var t = tgts[1];
  22236. var t0 = tgts[0];
  22237. // Add starting 'M' and 'C' points
  22238. pts.push(p0, [p0[0] + t0[0], p0[1] + t0[1], p[0] - t[0], p[1] - t[1], p[0], p[1]]);
  22239. // Add 'S' points
  22240. for (var i = 2, n = tgts.length; i < n; i++) {
  22241. var _p = _points[i];
  22242. var _t = tgts[i];
  22243. pts.push([_p[0] - _t[0], _p[1] - _t[1], _p[0], _p[1]]);
  22244. }
  22245. return pts;
  22246. },
  22247. /**
  22248. * Slice out a segment of 'points'
  22249. * @param {Array} points
  22250. * @param {Number} start
  22251. * @param {Number} end
  22252. * @returns {Array}
  22253. */
  22254. slice: function slice(points, start, end) {
  22255. var pts = points.slice(start, end);
  22256. if (start) {
  22257. // Add additional 'C' points
  22258. if (end - start > 1 && pts[1].length < 6) {
  22259. var n = pts[0].length;
  22260. pts[1] = [pts[0][n - 2] * 2 - pts[0][n - 4], pts[0][n - 1] * 2 - pts[0][n - 3]].concat(pts[1]);
  22261. }
  22262. // Remove control points for 'M'
  22263. pts[0] = pts[0].slice(-2);
  22264. }
  22265. return pts;
  22266. }
  22267. };
  22268. /**
  22269. * Compute slope from point 'p0' to 'p1'
  22270. * @param {Array} p0
  22271. * @param {Array} p1
  22272. * @returns {Number}
  22273. */
  22274. function slope(p0, p1) {
  22275. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  22276. }
  22277. /**
  22278. * Compute three-point differences for 'points'
  22279. * @param {Array} points
  22280. * @returns {Array}
  22281. */
  22282. function finiteDifferences(points) {
  22283. var m = [];
  22284. var p0 = points[0];
  22285. var p1 = points[1];
  22286. var d = m[0] = slope(p0, p1);
  22287. var i = 1;
  22288. for (var n = points.length - 1; i < n; i++) {
  22289. p0 = p1;
  22290. p1 = points[i + 1];
  22291. m[i] = (d + (d = slope(p0, p1))) * 0.5;
  22292. }
  22293. m[i] = d;
  22294. return m;
  22295. }
  22296. /**
  22297. * ApexCharts Line Class responsible for drawing Line / Area / RangeArea Charts.
  22298. * This class is also responsible for generating values for Bubble/Scatter charts, so need to rename it to Axis Charts to avoid confusions
  22299. * @module Line
  22300. **/
  22301. var Line = /*#__PURE__*/function () {
  22302. function Line(ctx, xyRatios, isPointsChart) {
  22303. _classCallCheck(this, Line);
  22304. this.ctx = ctx;
  22305. this.w = ctx.w;
  22306. this.xyRatios = xyRatios;
  22307. this.pointsChart = !(this.w.config.chart.type !== 'bubble' && this.w.config.chart.type !== 'scatter') || isPointsChart;
  22308. this.scatter = new Scatter(this.ctx);
  22309. this.noNegatives = this.w.globals.minX === Number.MAX_VALUE;
  22310. this.lineHelpers = new Helpers(this);
  22311. this.markers = new Markers(this.ctx);
  22312. this.prevSeriesY = [];
  22313. this.categoryAxisCorrection = 0;
  22314. this.yaxisIndex = 0;
  22315. }
  22316. _createClass(Line, [{
  22317. key: "draw",
  22318. value: function draw(series, ctype, seriesIndex, seriesRangeEnd) {
  22319. var _w$config$series$;
  22320. var w = this.w;
  22321. var graphics = new Graphics(this.ctx);
  22322. var type = w.globals.comboCharts ? ctype : w.config.chart.type;
  22323. var ret = graphics.group({
  22324. class: "apexcharts-".concat(type, "-series apexcharts-plot-series")
  22325. });
  22326. var coreUtils = new CoreUtils(this.ctx, w);
  22327. this.yRatio = this.xyRatios.yRatio;
  22328. this.zRatio = this.xyRatios.zRatio;
  22329. this.xRatio = this.xyRatios.xRatio;
  22330. this.baseLineY = this.xyRatios.baseLineY;
  22331. series = coreUtils.getLogSeries(series);
  22332. this.yRatio = coreUtils.getLogYRatios(this.yRatio);
  22333. // We call draw() for each series group
  22334. this.prevSeriesY = [];
  22335. // push all series in an array, so we can draw in reverse order
  22336. // (for stacked charts)
  22337. var allSeries = [];
  22338. for (var i = 0; i < series.length; i++) {
  22339. series = this.lineHelpers.sameValueSeriesFix(i, series);
  22340. var realIndex = w.globals.comboCharts ? seriesIndex[i] : i;
  22341. var translationsIndex = this.yRatio.length > 1 ? realIndex : 0;
  22342. this._initSerieVariables(series, i, realIndex);
  22343. var yArrj = []; // hold y values of current iterating series
  22344. var y2Arrj = []; // holds y2 values in range-area charts
  22345. var xArrj = []; // hold x values of current iterating series
  22346. var x = w.globals.padHorizontal + this.categoryAxisCorrection;
  22347. var y = 1;
  22348. var linePaths = [];
  22349. var areaPaths = [];
  22350. this.ctx.series.addCollapsedClassToSeries(this.elSeries, realIndex);
  22351. if (w.globals.isXNumeric && w.globals.seriesX.length > 0) {
  22352. x = (w.globals.seriesX[realIndex][0] - w.globals.minX) / this.xRatio;
  22353. }
  22354. xArrj.push(x);
  22355. var pX = x;
  22356. var pY = void 0;
  22357. var pY2 = void 0;
  22358. var prevX = pX;
  22359. var prevY = this.zeroY;
  22360. var prevY2 = this.zeroY;
  22361. var lineYPosition = 0;
  22362. // the first value in the current series is not null or undefined
  22363. var firstPrevY = this.lineHelpers.determineFirstPrevY({
  22364. i: i,
  22365. realIndex: realIndex,
  22366. series: series,
  22367. prevY: prevY,
  22368. lineYPosition: lineYPosition,
  22369. translationsIndex: translationsIndex
  22370. });
  22371. prevY = firstPrevY.prevY;
  22372. if (w.config.stroke.curve === 'monotoneCubic' && series[i][0] === null) {
  22373. // we have to discard the y position if 1st dataPoint is null as it
  22374. // causes issues with monotoneCubic path creation
  22375. yArrj.push(null);
  22376. } else {
  22377. yArrj.push(prevY);
  22378. }
  22379. pY = prevY;
  22380. // y2 are needed for range-area charts
  22381. var firstPrevY2 = void 0;
  22382. if (type === 'rangeArea') {
  22383. firstPrevY2 = this.lineHelpers.determineFirstPrevY({
  22384. i: i,
  22385. realIndex: realIndex,
  22386. series: seriesRangeEnd,
  22387. prevY: prevY2,
  22388. lineYPosition: lineYPosition,
  22389. translationsIndex: translationsIndex
  22390. });
  22391. prevY2 = firstPrevY2.prevY;
  22392. pY2 = prevY2;
  22393. y2Arrj.push(yArrj[0] !== null ? prevY2 : null);
  22394. }
  22395. var pathsFrom = this._calculatePathsFrom({
  22396. type: type,
  22397. series: series,
  22398. i: i,
  22399. realIndex: realIndex,
  22400. translationsIndex: translationsIndex,
  22401. prevX: prevX,
  22402. prevY: prevY,
  22403. prevY2: prevY2
  22404. });
  22405. // RangeArea will resume with these for the upper path creation
  22406. var rYArrj = [yArrj[0]];
  22407. var rY2Arrj = [y2Arrj[0]];
  22408. var iteratingOpts = {
  22409. type: type,
  22410. series: series,
  22411. realIndex: realIndex,
  22412. translationsIndex: translationsIndex,
  22413. i: i,
  22414. x: x,
  22415. y: y,
  22416. pX: pX,
  22417. pY: pY,
  22418. pathsFrom: pathsFrom,
  22419. linePaths: linePaths,
  22420. areaPaths: areaPaths,
  22421. seriesIndex: seriesIndex,
  22422. lineYPosition: lineYPosition,
  22423. xArrj: xArrj,
  22424. yArrj: yArrj,
  22425. y2Arrj: y2Arrj,
  22426. seriesRangeEnd: seriesRangeEnd
  22427. };
  22428. var paths = this._iterateOverDataPoints(_objectSpread2(_objectSpread2({}, iteratingOpts), {}, {
  22429. iterations: type === 'rangeArea' ? series[i].length - 1 : undefined,
  22430. isRangeStart: true
  22431. }));
  22432. if (type === 'rangeArea') {
  22433. var pathsFrom2 = this._calculatePathsFrom({
  22434. series: seriesRangeEnd,
  22435. i: i,
  22436. realIndex: realIndex,
  22437. prevX: prevX,
  22438. prevY: prevY2
  22439. });
  22440. var rangePaths = this._iterateOverDataPoints(_objectSpread2(_objectSpread2({}, iteratingOpts), {}, {
  22441. series: seriesRangeEnd,
  22442. xArrj: [x],
  22443. yArrj: rYArrj,
  22444. y2Arrj: rY2Arrj,
  22445. pY: pY2,
  22446. areaPaths: paths.areaPaths,
  22447. pathsFrom: pathsFrom2,
  22448. iterations: seriesRangeEnd[i].length - 1,
  22449. isRangeStart: false
  22450. }));
  22451. // Path may be segmented by nulls in data.
  22452. // paths.linePaths should hold (segments * 2) paths (upper and lower)
  22453. // the first n segments belong to the lower and the last n segments
  22454. // belong to the upper.
  22455. // paths.linePaths and rangePaths.linepaths are actually equivalent
  22456. // but we retain the distinction below for consistency with the
  22457. // unsegmented paths conditional branch.
  22458. var segments = paths.linePaths.length / 2;
  22459. for (var s = 0; s < segments; s++) {
  22460. paths.linePaths[s] = rangePaths.linePaths[s + segments] + paths.linePaths[s];
  22461. }
  22462. paths.linePaths.splice(segments);
  22463. paths.pathFromLine = rangePaths.pathFromLine + paths.pathFromLine;
  22464. } else {
  22465. paths.pathFromArea += 'z';
  22466. }
  22467. this._handlePaths({
  22468. type: type,
  22469. realIndex: realIndex,
  22470. i: i,
  22471. paths: paths
  22472. });
  22473. this.elSeries.add(this.elPointsMain);
  22474. this.elSeries.add(this.elDataLabelsWrap);
  22475. allSeries.push(this.elSeries);
  22476. }
  22477. if (typeof ((_w$config$series$ = w.config.series[0]) === null || _w$config$series$ === void 0 ? void 0 : _w$config$series$.zIndex) !== 'undefined') {
  22478. allSeries.sort(function (a, b) {
  22479. return Number(a.node.getAttribute('zIndex')) - Number(b.node.getAttribute('zIndex'));
  22480. });
  22481. }
  22482. if (w.config.chart.stacked) {
  22483. for (var _s = allSeries.length - 1; _s >= 0; _s--) {
  22484. ret.add(allSeries[_s]);
  22485. }
  22486. } else {
  22487. for (var _s2 = 0; _s2 < allSeries.length; _s2++) {
  22488. ret.add(allSeries[_s2]);
  22489. }
  22490. }
  22491. return ret;
  22492. }
  22493. }, {
  22494. key: "_initSerieVariables",
  22495. value: function _initSerieVariables(series, i, realIndex) {
  22496. var w = this.w;
  22497. var graphics = new Graphics(this.ctx);
  22498. // width divided into equal parts
  22499. this.xDivision = w.globals.gridWidth / (w.globals.dataPoints - (w.config.xaxis.tickPlacement === 'on' ? 1 : 0));
  22500. this.strokeWidth = Array.isArray(w.config.stroke.width) ? w.config.stroke.width[realIndex] : w.config.stroke.width;
  22501. var translationsIndex = 0;
  22502. if (this.yRatio.length > 1) {
  22503. this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex];
  22504. translationsIndex = realIndex;
  22505. }
  22506. this.isReversed = w.config.yaxis[this.yaxisIndex] && w.config.yaxis[this.yaxisIndex].reversed;
  22507. // zeroY is the 0 value in y series which can be used in negative charts
  22508. this.zeroY = w.globals.gridHeight - this.baseLineY[translationsIndex] - (this.isReversed ? w.globals.gridHeight : 0) + (this.isReversed ? this.baseLineY[translationsIndex] * 2 : 0);
  22509. this.areaBottomY = this.zeroY;
  22510. if (this.zeroY > w.globals.gridHeight || w.config.plotOptions.area.fillTo === 'end') {
  22511. this.areaBottomY = w.globals.gridHeight;
  22512. }
  22513. this.categoryAxisCorrection = this.xDivision / 2;
  22514. // el to which series will be drawn
  22515. this.elSeries = graphics.group({
  22516. class: "apexcharts-series",
  22517. zIndex: typeof w.config.series[realIndex].zIndex !== 'undefined' ? w.config.series[realIndex].zIndex : realIndex,
  22518. seriesName: Utils$1.escapeString(w.globals.seriesNames[realIndex])
  22519. });
  22520. // points
  22521. this.elPointsMain = graphics.group({
  22522. class: 'apexcharts-series-markers-wrap',
  22523. 'data:realIndex': realIndex
  22524. });
  22525. // eldatalabels
  22526. this.elDataLabelsWrap = graphics.group({
  22527. class: 'apexcharts-datalabels',
  22528. 'data:realIndex': realIndex
  22529. });
  22530. var longestSeries = series[i].length === w.globals.dataPoints;
  22531. this.elSeries.attr({
  22532. 'data:longestSeries': longestSeries,
  22533. rel: i + 1,
  22534. 'data:realIndex': realIndex
  22535. });
  22536. this.appendPathFrom = true;
  22537. }
  22538. }, {
  22539. key: "_calculatePathsFrom",
  22540. value: function _calculatePathsFrom(_ref) {
  22541. var type = _ref.type,
  22542. series = _ref.series,
  22543. i = _ref.i,
  22544. realIndex = _ref.realIndex,
  22545. translationsIndex = _ref.translationsIndex,
  22546. prevX = _ref.prevX,
  22547. prevY = _ref.prevY,
  22548. prevY2 = _ref.prevY2;
  22549. var w = this.w;
  22550. var graphics = new Graphics(this.ctx);
  22551. var linePath, areaPath, pathFromLine, pathFromArea;
  22552. if (series[i][0] === null) {
  22553. // when the first value itself is null, we need to move the pointer to a location where a null value is not found
  22554. for (var s = 0; s < series[i].length; s++) {
  22555. if (series[i][s] !== null) {
  22556. prevX = this.xDivision * s;
  22557. prevY = this.zeroY - series[i][s] / this.yRatio[translationsIndex];
  22558. linePath = graphics.move(prevX, prevY);
  22559. areaPath = graphics.move(prevX, this.areaBottomY);
  22560. break;
  22561. }
  22562. }
  22563. } else {
  22564. linePath = graphics.move(prevX, prevY);
  22565. if (type === 'rangeArea') {
  22566. linePath = graphics.move(prevX, prevY2) + graphics.line(prevX, prevY);
  22567. }
  22568. areaPath = graphics.move(prevX, this.areaBottomY) + graphics.line(prevX, prevY);
  22569. }
  22570. pathFromLine = graphics.move(0, this.zeroY) + graphics.line(0, this.zeroY);
  22571. pathFromArea = graphics.move(0, this.zeroY) + graphics.line(0, this.zeroY);
  22572. if (w.globals.previousPaths.length > 0) {
  22573. var pathFrom = this.lineHelpers.checkPreviousPaths({
  22574. pathFromLine: pathFromLine,
  22575. pathFromArea: pathFromArea,
  22576. realIndex: realIndex
  22577. });
  22578. pathFromLine = pathFrom.pathFromLine;
  22579. pathFromArea = pathFrom.pathFromArea;
  22580. }
  22581. return {
  22582. prevX: prevX,
  22583. prevY: prevY,
  22584. linePath: linePath,
  22585. areaPath: areaPath,
  22586. pathFromLine: pathFromLine,
  22587. pathFromArea: pathFromArea
  22588. };
  22589. }
  22590. }, {
  22591. key: "_handlePaths",
  22592. value: function _handlePaths(_ref2) {
  22593. var type = _ref2.type,
  22594. realIndex = _ref2.realIndex,
  22595. i = _ref2.i,
  22596. paths = _ref2.paths;
  22597. var w = this.w;
  22598. var graphics = new Graphics(this.ctx);
  22599. var fill = new Fill(this.ctx);
  22600. // push all current y values array to main PrevY Array
  22601. this.prevSeriesY.push(paths.yArrj);
  22602. // push all x val arrays into main xArr
  22603. w.globals.seriesXvalues[realIndex] = paths.xArrj;
  22604. w.globals.seriesYvalues[realIndex] = paths.yArrj;
  22605. var forecast = w.config.forecastDataPoints;
  22606. if (forecast.count > 0 && type !== 'rangeArea') {
  22607. var forecastCutoff = w.globals.seriesXvalues[realIndex][w.globals.seriesXvalues[realIndex].length - forecast.count - 1];
  22608. var elForecastMask = graphics.drawRect(forecastCutoff, 0, w.globals.gridWidth, w.globals.gridHeight, 0);
  22609. w.globals.dom.elForecastMask.appendChild(elForecastMask.node);
  22610. var elNonForecastMask = graphics.drawRect(0, 0, forecastCutoff, w.globals.gridHeight, 0);
  22611. w.globals.dom.elNonForecastMask.appendChild(elNonForecastMask.node);
  22612. }
  22613. // these elements will be shown after area path animation completes
  22614. if (!this.pointsChart) {
  22615. w.globals.delayedElements.push({
  22616. el: this.elPointsMain.node,
  22617. index: realIndex
  22618. });
  22619. }
  22620. var defaultRenderedPathOptions = {
  22621. i: i,
  22622. realIndex: realIndex,
  22623. animationDelay: i,
  22624. initialSpeed: w.config.chart.animations.speed,
  22625. dataChangeSpeed: w.config.chart.animations.dynamicAnimation.speed,
  22626. className: "apexcharts-".concat(type)
  22627. };
  22628. if (type === 'area') {
  22629. var pathFill = fill.fillPath({
  22630. seriesNumber: realIndex
  22631. });
  22632. for (var p = 0; p < paths.areaPaths.length; p++) {
  22633. var renderedPath = graphics.renderPaths(_objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
  22634. pathFrom: paths.pathFromArea,
  22635. pathTo: paths.areaPaths[p],
  22636. stroke: 'none',
  22637. strokeWidth: 0,
  22638. strokeLineCap: null,
  22639. fill: pathFill
  22640. }));
  22641. this.elSeries.add(renderedPath);
  22642. }
  22643. }
  22644. if (w.config.stroke.show && !this.pointsChart) {
  22645. var lineFill = null;
  22646. if (type === 'line') {
  22647. lineFill = fill.fillPath({
  22648. seriesNumber: realIndex,
  22649. i: i
  22650. });
  22651. } else {
  22652. if (w.config.stroke.fill.type === 'solid') {
  22653. lineFill = w.globals.stroke.colors[realIndex];
  22654. } else {
  22655. var prevFill = w.config.fill;
  22656. w.config.fill = w.config.stroke.fill;
  22657. lineFill = fill.fillPath({
  22658. seriesNumber: realIndex,
  22659. i: i
  22660. });
  22661. w.config.fill = prevFill;
  22662. }
  22663. }
  22664. // range-area paths are drawn using linePaths
  22665. for (var _p = 0; _p < paths.linePaths.length; _p++) {
  22666. var _pathFill = lineFill;
  22667. if (type === 'rangeArea') {
  22668. _pathFill = fill.fillPath({
  22669. seriesNumber: realIndex
  22670. });
  22671. }
  22672. var linePathCommonOpts = _objectSpread2(_objectSpread2({}, defaultRenderedPathOptions), {}, {
  22673. pathFrom: paths.pathFromLine,
  22674. pathTo: paths.linePaths[_p],
  22675. stroke: lineFill,
  22676. strokeWidth: this.strokeWidth,
  22677. strokeLineCap: w.config.stroke.lineCap,
  22678. fill: type === 'rangeArea' ? _pathFill : 'none'
  22679. });
  22680. var _renderedPath = graphics.renderPaths(linePathCommonOpts);
  22681. this.elSeries.add(_renderedPath);
  22682. _renderedPath.attr('fill-rule', "evenodd");
  22683. if (forecast.count > 0 && type !== 'rangeArea') {
  22684. var renderedForecastPath = graphics.renderPaths(linePathCommonOpts);
  22685. renderedForecastPath.node.setAttribute('stroke-dasharray', forecast.dashArray);
  22686. if (forecast.strokeWidth) {
  22687. renderedForecastPath.node.setAttribute('stroke-width', forecast.strokeWidth);
  22688. }
  22689. this.elSeries.add(renderedForecastPath);
  22690. renderedForecastPath.attr('clip-path', "url(#forecastMask".concat(w.globals.cuid, ")"));
  22691. _renderedPath.attr('clip-path', "url(#nonForecastMask".concat(w.globals.cuid, ")"));
  22692. }
  22693. }
  22694. }
  22695. }
  22696. }, {
  22697. key: "_iterateOverDataPoints",
  22698. value: function _iterateOverDataPoints(_ref3) {
  22699. var _this = this,
  22700. _this$w$config$series,
  22701. _this$w$config$series2;
  22702. var type = _ref3.type,
  22703. series = _ref3.series,
  22704. iterations = _ref3.iterations,
  22705. realIndex = _ref3.realIndex,
  22706. translationsIndex = _ref3.translationsIndex,
  22707. i = _ref3.i,
  22708. x = _ref3.x,
  22709. y = _ref3.y,
  22710. pX = _ref3.pX,
  22711. pY = _ref3.pY,
  22712. pathsFrom = _ref3.pathsFrom,
  22713. linePaths = _ref3.linePaths,
  22714. areaPaths = _ref3.areaPaths,
  22715. seriesIndex = _ref3.seriesIndex,
  22716. lineYPosition = _ref3.lineYPosition,
  22717. xArrj = _ref3.xArrj,
  22718. yArrj = _ref3.yArrj,
  22719. y2Arrj = _ref3.y2Arrj,
  22720. isRangeStart = _ref3.isRangeStart,
  22721. seriesRangeEnd = _ref3.seriesRangeEnd;
  22722. var w = this.w;
  22723. var graphics = new Graphics(this.ctx);
  22724. var yRatio = this.yRatio;
  22725. var prevY = pathsFrom.prevY,
  22726. linePath = pathsFrom.linePath,
  22727. areaPath = pathsFrom.areaPath,
  22728. pathFromLine = pathsFrom.pathFromLine,
  22729. pathFromArea = pathsFrom.pathFromArea;
  22730. var minY = Utils$1.isNumber(w.globals.minYArr[realIndex]) ? w.globals.minYArr[realIndex] : w.globals.minY;
  22731. if (!iterations) {
  22732. iterations = w.globals.dataPoints > 1 ? w.globals.dataPoints - 1 : w.globals.dataPoints;
  22733. }
  22734. var getY = function getY(_y, lineYPos) {
  22735. return lineYPos - _y / yRatio[translationsIndex] + (_this.isReversed ? _y / yRatio[translationsIndex] : 0) * 2;
  22736. };
  22737. var y2 = y;
  22738. 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');
  22739. var curve = w.config.stroke.curve;
  22740. if (Array.isArray(curve)) {
  22741. if (Array.isArray(seriesIndex)) {
  22742. curve = curve[seriesIndex[i]];
  22743. } else {
  22744. curve = curve[i];
  22745. }
  22746. }
  22747. var pathState = 0;
  22748. var segmentStartX;
  22749. for (var j = 0; j < iterations; j++) {
  22750. var isNull = typeof series[i][j + 1] === 'undefined' || series[i][j + 1] === null;
  22751. if (w.globals.isXNumeric) {
  22752. var sX = w.globals.seriesX[realIndex][j + 1];
  22753. if (typeof w.globals.seriesX[realIndex][j + 1] === 'undefined') {
  22754. /* fix #374 */
  22755. sX = w.globals.seriesX[realIndex][iterations - 1];
  22756. }
  22757. x = (sX - w.globals.minX) / this.xRatio;
  22758. } else {
  22759. x = x + this.xDivision;
  22760. }
  22761. if (stackSeries) {
  22762. if (i > 0 && w.globals.collapsedSeries.length < w.config.series.length - 1) {
  22763. // a collapsed series in a stacked chart may provide wrong result
  22764. // for the next series, hence find the prevIndex of prev series
  22765. // which is not collapsed - fixes apexcharts.js#1372
  22766. var prevIndex = function prevIndex(pi) {
  22767. for (var pii = pi; pii > 0; pii--) {
  22768. if (w.globals.collapsedSeriesIndices.indexOf((seriesIndex === null || seriesIndex === void 0 ? void 0 : seriesIndex[pii]) || pii) > -1) {
  22769. pii--;
  22770. } else {
  22771. return pii;
  22772. }
  22773. }
  22774. return 0;
  22775. };
  22776. lineYPosition = this.prevSeriesY[prevIndex(i - 1)][j + 1];
  22777. } else {
  22778. // the first series will not have prevY values
  22779. lineYPosition = this.zeroY;
  22780. }
  22781. } else {
  22782. lineYPosition = this.zeroY;
  22783. }
  22784. if (isNull) {
  22785. y = getY(minY, lineYPosition);
  22786. } else {
  22787. y = getY(series[i][j + 1], lineYPosition);
  22788. if (type === 'rangeArea') {
  22789. y2 = getY(seriesRangeEnd[i][j + 1], lineYPosition);
  22790. }
  22791. }
  22792. // push current X
  22793. xArrj.push(x);
  22794. // push current Y that will be used as next series's bottom position
  22795. if (isNull && (w.config.stroke.curve === 'smooth' || w.config.stroke.curve === 'monotoneCubic')) {
  22796. yArrj.push(null);
  22797. y2Arrj.push(null);
  22798. } else {
  22799. yArrj.push(y);
  22800. y2Arrj.push(y2);
  22801. }
  22802. var pointsPos = this.lineHelpers.calculatePoints({
  22803. series: series,
  22804. x: x,
  22805. y: y,
  22806. realIndex: realIndex,
  22807. i: i,
  22808. j: j,
  22809. prevY: prevY
  22810. });
  22811. var calculatedPaths = this._createPaths({
  22812. type: type,
  22813. series: series,
  22814. i: i,
  22815. realIndex: realIndex,
  22816. j: j,
  22817. x: x,
  22818. y: y,
  22819. y2: y2,
  22820. xArrj: xArrj,
  22821. yArrj: yArrj,
  22822. y2Arrj: y2Arrj,
  22823. pX: pX,
  22824. pY: pY,
  22825. pathState: pathState,
  22826. segmentStartX: segmentStartX,
  22827. linePath: linePath,
  22828. areaPath: areaPath,
  22829. linePaths: linePaths,
  22830. areaPaths: areaPaths,
  22831. curve: curve,
  22832. isRangeStart: isRangeStart
  22833. });
  22834. areaPaths = calculatedPaths.areaPaths;
  22835. linePaths = calculatedPaths.linePaths;
  22836. pX = calculatedPaths.pX;
  22837. pY = calculatedPaths.pY;
  22838. pathState = calculatedPaths.pathState;
  22839. segmentStartX = calculatedPaths.segmentStartX;
  22840. areaPath = calculatedPaths.areaPath;
  22841. linePath = calculatedPaths.linePath;
  22842. if (this.appendPathFrom && !(curve === 'monotoneCubic' && type === 'rangeArea')) {
  22843. pathFromLine += graphics.line(x, this.zeroY);
  22844. pathFromArea += graphics.line(x, this.zeroY);
  22845. }
  22846. this.handleNullDataPoints(series, pointsPos, i, j, realIndex);
  22847. this._handleMarkersAndLabels({
  22848. type: type,
  22849. pointsPos: pointsPos,
  22850. i: i,
  22851. j: j,
  22852. realIndex: realIndex,
  22853. isRangeStart: isRangeStart
  22854. });
  22855. }
  22856. return {
  22857. yArrj: yArrj,
  22858. xArrj: xArrj,
  22859. pathFromArea: pathFromArea,
  22860. areaPaths: areaPaths,
  22861. pathFromLine: pathFromLine,
  22862. linePaths: linePaths,
  22863. linePath: linePath,
  22864. areaPath: areaPath
  22865. };
  22866. }
  22867. }, {
  22868. key: "_handleMarkersAndLabels",
  22869. value: function _handleMarkersAndLabels(_ref4) {
  22870. var type = _ref4.type,
  22871. pointsPos = _ref4.pointsPos,
  22872. isRangeStart = _ref4.isRangeStart,
  22873. i = _ref4.i,
  22874. j = _ref4.j,
  22875. realIndex = _ref4.realIndex;
  22876. var w = this.w;
  22877. var dataLabels = new DataLabels(this.ctx);
  22878. if (!this.pointsChart) {
  22879. if (w.globals.series[i].length > 1) {
  22880. this.elPointsMain.node.classList.add('apexcharts-element-hidden');
  22881. }
  22882. var elPointsWrap = this.markers.plotChartMarkers(pointsPos, realIndex, j + 1);
  22883. if (elPointsWrap !== null) {
  22884. this.elPointsMain.add(elPointsWrap);
  22885. }
  22886. } else {
  22887. // scatter / bubble chart points creation
  22888. this.scatter.draw(this.elSeries, j, {
  22889. realIndex: realIndex,
  22890. pointsPos: pointsPos,
  22891. zRatio: this.zRatio,
  22892. elParent: this.elPointsMain
  22893. });
  22894. }
  22895. var drawnLabels = dataLabels.drawDataLabel({
  22896. type: type,
  22897. isRangeStart: isRangeStart,
  22898. pos: pointsPos,
  22899. i: realIndex,
  22900. j: j + 1
  22901. });
  22902. if (drawnLabels !== null) {
  22903. this.elDataLabelsWrap.add(drawnLabels);
  22904. }
  22905. }
  22906. }, {
  22907. key: "_createPaths",
  22908. value: function _createPaths(_ref5) {
  22909. var type = _ref5.type,
  22910. series = _ref5.series,
  22911. i = _ref5.i;
  22912. _ref5.realIndex;
  22913. var j = _ref5.j,
  22914. x = _ref5.x,
  22915. y = _ref5.y,
  22916. xArrj = _ref5.xArrj,
  22917. yArrj = _ref5.yArrj,
  22918. y2 = _ref5.y2,
  22919. y2Arrj = _ref5.y2Arrj,
  22920. pX = _ref5.pX,
  22921. pY = _ref5.pY,
  22922. pathState = _ref5.pathState,
  22923. segmentStartX = _ref5.segmentStartX,
  22924. linePath = _ref5.linePath,
  22925. areaPath = _ref5.areaPath,
  22926. linePaths = _ref5.linePaths,
  22927. areaPaths = _ref5.areaPaths,
  22928. curve = _ref5.curve,
  22929. isRangeStart = _ref5.isRangeStart;
  22930. var graphics = new Graphics(this.ctx);
  22931. var areaBottomY = this.areaBottomY;
  22932. var rangeArea = type === 'rangeArea';
  22933. var isLowerRangeAreaPath = type === 'rangeArea' && isRangeStart;
  22934. switch (curve) {
  22935. case 'monotoneCubic':
  22936. var yAj = isRangeStart ? yArrj : y2Arrj;
  22937. var getSmoothInputs = function getSmoothInputs(xArr, yArr) {
  22938. return xArr.map(function (_, i) {
  22939. return [_, yArr[i]];
  22940. }).filter(function (_) {
  22941. return _[1] !== null;
  22942. });
  22943. };
  22944. var getSegmentLengths = function getSegmentLengths(yArr) {
  22945. // Get the segment lengths so the segments can be extracted from
  22946. // the null-filtered smoothInputs array
  22947. var segLens = [];
  22948. var count = 0;
  22949. yArr.forEach(function (_) {
  22950. if (_ !== null) {
  22951. count++;
  22952. } else if (count > 0) {
  22953. segLens.push(count);
  22954. count = 0;
  22955. }
  22956. });
  22957. if (count > 0) {
  22958. segLens.push(count);
  22959. }
  22960. return segLens;
  22961. };
  22962. var getSegments = function getSegments(yArr, points) {
  22963. var segLens = getSegmentLengths(yArr);
  22964. var segments = [];
  22965. for (var _i = 0, len = 0; _i < segLens.length; len += segLens[_i++]) {
  22966. segments[_i] = spline.slice(points, len, len + segLens[_i]);
  22967. }
  22968. return segments;
  22969. };
  22970. switch (pathState) {
  22971. case 0:
  22972. // Find start of segment
  22973. if (yAj[j + 1] === null) {
  22974. break;
  22975. }
  22976. pathState = 1;
  22977. // continue through to pathState 1
  22978. case 1:
  22979. if (!(rangeArea ? xArrj.length === series[i].length : j === series[i].length - 2)) {
  22980. break;
  22981. }
  22982. // continue through to pathState 2
  22983. case 2:
  22984. // Interpolate the full series with nulls excluded then extract the
  22985. // null delimited segments with interpolated points included.
  22986. var _xAj = isRangeStart ? xArrj : xArrj.slice().reverse();
  22987. var _yAj = isRangeStart ? yAj : yAj.slice().reverse();
  22988. var smoothInputs = getSmoothInputs(_xAj, _yAj);
  22989. var points = smoothInputs.length > 1 ? spline.points(smoothInputs) : smoothInputs;
  22990. var smoothInputsLower = [];
  22991. if (rangeArea) {
  22992. if (isLowerRangeAreaPath) {
  22993. // As we won't be needing it, borrow areaPaths to retain our
  22994. // rangeArea lower points.
  22995. areaPaths = smoothInputs;
  22996. } else {
  22997. // Retrieve the corresponding lower raw interpolated points so we
  22998. // can join onto its end points. Note: the upper Y2 segments will
  22999. // be in the reverse order relative to the lower segments.
  23000. smoothInputsLower = areaPaths.reverse();
  23001. }
  23002. }
  23003. var segmentCount = 0;
  23004. var smoothInputsIndex = 0;
  23005. getSegments(_yAj, points).forEach(function (_) {
  23006. segmentCount++;
  23007. var svgPoints = svgPath(_);
  23008. var _start = smoothInputsIndex;
  23009. smoothInputsIndex += _.length;
  23010. var _end = smoothInputsIndex - 1;
  23011. if (isLowerRangeAreaPath) {
  23012. linePath = graphics.move(smoothInputs[_start][0], smoothInputs[_start][1]) + svgPoints;
  23013. } else if (rangeArea) {
  23014. 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]);
  23015. } else {
  23016. linePath = graphics.move(smoothInputs[_start][0], smoothInputs[_start][1]) + svgPoints;
  23017. areaPath = linePath + graphics.line(smoothInputs[_end][0], areaBottomY) + graphics.line(smoothInputs[_start][0], areaBottomY) + 'z';
  23018. areaPaths.push(areaPath);
  23019. }
  23020. linePaths.push(linePath);
  23021. });
  23022. if (rangeArea && segmentCount > 1 && !isLowerRangeAreaPath) {
  23023. // Reverse the order of the upper path segments
  23024. var upperLinePaths = linePaths.slice(segmentCount).reverse();
  23025. linePaths.splice(segmentCount);
  23026. upperLinePaths.forEach(function (u) {
  23027. return linePaths.push(u);
  23028. });
  23029. }
  23030. pathState = 0;
  23031. break;
  23032. }
  23033. break;
  23034. case 'smooth':
  23035. var length = (x - pX) * 0.35;
  23036. if (series[i][j] === null) {
  23037. pathState = 0;
  23038. } else {
  23039. switch (pathState) {
  23040. case 0:
  23041. // Beginning of segment
  23042. segmentStartX = pX;
  23043. if (isLowerRangeAreaPath) {
  23044. // Need to add path portion that will join to the upper path
  23045. linePath = graphics.move(pX, y2Arrj[j]) + graphics.line(pX, pY);
  23046. } else {
  23047. linePath = graphics.move(pX, pY);
  23048. }
  23049. areaPath = graphics.move(pX, pY);
  23050. // Check for single isolated point
  23051. if (series[i][j + 1] === null) {
  23052. linePaths.push(linePath);
  23053. areaPaths.push(areaPath);
  23054. // Stay in pathState = 0;
  23055. break;
  23056. }
  23057. pathState = 1;
  23058. if (j < series[i].length - 2) {
  23059. var p = graphics.curve(pX + length, pY, x - length, y, x, y);
  23060. linePath += p;
  23061. areaPath += p;
  23062. break;
  23063. }
  23064. // Continue on with pathState 1 to finish the path and exit
  23065. case 1:
  23066. // Continuing with segment
  23067. if (series[i][j + 1] === null) {
  23068. // Segment ends here
  23069. if (isLowerRangeAreaPath) {
  23070. linePath += graphics.line(pX, y2);
  23071. } else {
  23072. linePath += graphics.move(pX, pY);
  23073. }
  23074. areaPath += graphics.line(pX, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
  23075. linePaths.push(linePath);
  23076. areaPaths.push(areaPath);
  23077. pathState = -1;
  23078. } else {
  23079. var _p2 = graphics.curve(pX + length, pY, x - length, y, x, y);
  23080. linePath += _p2;
  23081. areaPath += _p2;
  23082. if (j >= series[i].length - 2) {
  23083. if (isLowerRangeAreaPath) {
  23084. // Need to add path portion that will join to the upper path
  23085. linePath += graphics.curve(x, y, x, y, x, y2) + graphics.move(x, y2);
  23086. }
  23087. areaPath += graphics.curve(x, y, x, y, x, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
  23088. linePaths.push(linePath);
  23089. areaPaths.push(areaPath);
  23090. pathState = -1;
  23091. }
  23092. }
  23093. break;
  23094. }
  23095. }
  23096. pX = x;
  23097. pY = y;
  23098. break;
  23099. default:
  23100. var pathToPoint = function pathToPoint(curve, x, y) {
  23101. var path = [];
  23102. switch (curve) {
  23103. case 'stepline':
  23104. path = graphics.line(x, null, 'H') + graphics.line(null, y, 'V');
  23105. break;
  23106. case 'linestep':
  23107. path = graphics.line(null, y, 'V') + graphics.line(x, null, 'H');
  23108. break;
  23109. case 'straight':
  23110. path = graphics.line(x, y);
  23111. break;
  23112. }
  23113. return path;
  23114. };
  23115. if (series[i][j] === null) {
  23116. pathState = 0;
  23117. } else {
  23118. switch (pathState) {
  23119. case 0:
  23120. // Beginning of segment
  23121. segmentStartX = pX;
  23122. if (isLowerRangeAreaPath) {
  23123. // Need to add path portion that will join to the upper path
  23124. linePath = graphics.move(pX, y2Arrj[j]) + graphics.line(pX, pY);
  23125. } else {
  23126. linePath = graphics.move(pX, pY);
  23127. }
  23128. areaPath = graphics.move(pX, pY);
  23129. // Check for single isolated point
  23130. if (series[i][j + 1] === null) {
  23131. linePaths.push(linePath);
  23132. areaPaths.push(areaPath);
  23133. // Stay in pathState = 0
  23134. break;
  23135. }
  23136. pathState = 1;
  23137. if (j < series[i].length - 2) {
  23138. var _p3 = pathToPoint(curve, x, y);
  23139. linePath += _p3;
  23140. areaPath += _p3;
  23141. break;
  23142. }
  23143. // Continue on with pathState 1 to finish the path and exit
  23144. case 1:
  23145. // Continuing with segment
  23146. if (series[i][j + 1] === null) {
  23147. // Segment ends here
  23148. if (isLowerRangeAreaPath) {
  23149. linePath += graphics.line(pX, y2);
  23150. } else {
  23151. linePath += graphics.move(pX, pY);
  23152. }
  23153. areaPath += graphics.line(pX, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
  23154. linePaths.push(linePath);
  23155. areaPaths.push(areaPath);
  23156. pathState = -1;
  23157. } else {
  23158. var _p4 = pathToPoint(curve, x, y);
  23159. linePath += _p4;
  23160. areaPath += _p4;
  23161. if (j >= series[i].length - 2) {
  23162. if (isLowerRangeAreaPath) {
  23163. // Need to add path portion that will join to the upper path
  23164. linePath += graphics.line(x, y2);
  23165. }
  23166. areaPath += graphics.line(x, areaBottomY) + graphics.line(segmentStartX, areaBottomY) + 'z';
  23167. linePaths.push(linePath);
  23168. areaPaths.push(areaPath);
  23169. pathState = -1;
  23170. }
  23171. }
  23172. break;
  23173. }
  23174. }
  23175. pX = x;
  23176. pY = y;
  23177. break;
  23178. }
  23179. return {
  23180. linePaths: linePaths,
  23181. areaPaths: areaPaths,
  23182. pX: pX,
  23183. pY: pY,
  23184. pathState: pathState,
  23185. segmentStartX: segmentStartX,
  23186. linePath: linePath,
  23187. areaPath: areaPath
  23188. };
  23189. }
  23190. }, {
  23191. key: "handleNullDataPoints",
  23192. value: function handleNullDataPoints(series, pointsPos, i, j, realIndex) {
  23193. var w = this.w;
  23194. if (series[i][j] === null && w.config.markers.showNullDataPoints || series[i].length === 1) {
  23195. var pSize = this.strokeWidth - w.config.markers.strokeWidth / 2;
  23196. if (!(pSize > 0)) {
  23197. pSize = 0;
  23198. }
  23199. // fixes apexcharts.js#1282, #1252
  23200. var elPointsWrap = this.markers.plotChartMarkers(pointsPos, realIndex, j + 1, pSize, true);
  23201. if (elPointsWrap !== null) {
  23202. this.elPointsMain.add(elPointsWrap);
  23203. }
  23204. }
  23205. }
  23206. }]);
  23207. return Line;
  23208. }();
  23209. /*
  23210. * treemap-squarify.js - open source implementation of squarified treemaps
  23211. *
  23212. * Treemap Squared 0.5 - Treemap Charting library
  23213. *
  23214. * https://github.com/imranghory/treemap-squared/
  23215. *
  23216. * Copyright (c) 2012 Imran Ghory (imranghory@gmail.com)
  23217. * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  23218. *
  23219. *
  23220. * Implementation of the squarify treemap algorithm described in:
  23221. *
  23222. * Bruls, Mark; Huizing, Kees; van Wijk, Jarke J. (2000), "Squarified treemaps"
  23223. * in de Leeuw, W.; van Liere, R., Data Visualization 2000:
  23224. * Proc. Joint Eurographics and IEEE TCVG Symp. on Visualization, Springer-Verlag, pp. 33–42.
  23225. *
  23226. * Paper is available online at: http://www.win.tue.nl/~vanwijk/stm.pdf
  23227. *
  23228. * The code in this file is completeley decoupled from the drawing code so it should be trivial
  23229. * to port it to any other vector drawing library. Given an array of datapoints this library returns
  23230. * an array of cartesian coordinates that represent the rectangles that make up the treemap.
  23231. *
  23232. * The library also supports multidimensional data (nested treemaps) and performs normalization on the data.
  23233. *
  23234. * See the README file for more details.
  23235. */
  23236. window.TreemapSquared = {};
  23237. (function () {
  23238. window.TreemapSquared.generate = function () {
  23239. function Container(xoffset, yoffset, width, height) {
  23240. this.xoffset = xoffset; // offset from the the top left hand corner
  23241. this.yoffset = yoffset; // ditto
  23242. this.height = height;
  23243. this.width = width;
  23244. this.shortestEdge = function () {
  23245. return Math.min(this.height, this.width);
  23246. };
  23247. // getCoordinates - for a row of boxes which we've placed
  23248. // return an array of their cartesian coordinates
  23249. this.getCoordinates = function (row) {
  23250. var coordinates = [];
  23251. var subxoffset = this.xoffset,
  23252. subyoffset = this.yoffset; //our offset within the container
  23253. var areawidth = sumArray(row) / this.height;
  23254. var areaheight = sumArray(row) / this.width;
  23255. var i;
  23256. if (this.width >= this.height) {
  23257. for (i = 0; i < row.length; i++) {
  23258. coordinates.push([subxoffset, subyoffset, subxoffset + areawidth, subyoffset + row[i] / areawidth]);
  23259. subyoffset = subyoffset + row[i] / areawidth;
  23260. }
  23261. } else {
  23262. for (i = 0; i < row.length; i++) {
  23263. coordinates.push([subxoffset, subyoffset, subxoffset + row[i] / areaheight, subyoffset + areaheight]);
  23264. subxoffset = subxoffset + row[i] / areaheight;
  23265. }
  23266. }
  23267. return coordinates;
  23268. };
  23269. // cutArea - once we've placed some boxes into an row we then need to identify the remaining area,
  23270. // this function takes the area of the boxes we've placed and calculates the location and
  23271. // dimensions of the remaining space and returns a container box defined by the remaining area
  23272. this.cutArea = function (area) {
  23273. var newcontainer;
  23274. if (this.width >= this.height) {
  23275. var areawidth = area / this.height;
  23276. var newwidth = this.width - areawidth;
  23277. newcontainer = new Container(this.xoffset + areawidth, this.yoffset, newwidth, this.height);
  23278. } else {
  23279. var areaheight = area / this.width;
  23280. var newheight = this.height - areaheight;
  23281. newcontainer = new Container(this.xoffset, this.yoffset + areaheight, this.width, newheight);
  23282. }
  23283. return newcontainer;
  23284. };
  23285. }
  23286. // normalize - the Bruls algorithm assumes we're passing in areas that nicely fit into our
  23287. // container box, this method takes our raw data and normalizes the data values into
  23288. // area values so that this assumption is valid.
  23289. function normalize(data, area) {
  23290. var normalizeddata = [];
  23291. var sum = sumArray(data);
  23292. var multiplier = area / sum;
  23293. var i;
  23294. for (i = 0; i < data.length; i++) {
  23295. normalizeddata[i] = data[i] * multiplier;
  23296. }
  23297. return normalizeddata;
  23298. }
  23299. // treemapMultidimensional - takes multidimensional data (aka [[23,11],[11,32]] - nested array)
  23300. // and recursively calls itself using treemapSingledimensional
  23301. // to create a patchwork of treemaps and merge them
  23302. function treemapMultidimensional(data, width, height, xoffset, yoffset) {
  23303. xoffset = typeof xoffset === 'undefined' ? 0 : xoffset;
  23304. yoffset = typeof yoffset === 'undefined' ? 0 : yoffset;
  23305. var mergeddata = [];
  23306. var mergedtreemap;
  23307. var results = [];
  23308. var i;
  23309. if (isArray(data[0])) {
  23310. // if we've got more dimensions of depth
  23311. for (i = 0; i < data.length; i++) {
  23312. mergeddata[i] = sumMultidimensionalArray(data[i]);
  23313. }
  23314. mergedtreemap = treemapSingledimensional(mergeddata, width, height, xoffset, yoffset);
  23315. for (i = 0; i < data.length; i++) {
  23316. results.push(treemapMultidimensional(data[i], mergedtreemap[i][2] - mergedtreemap[i][0], mergedtreemap[i][3] - mergedtreemap[i][1], mergedtreemap[i][0], mergedtreemap[i][1]));
  23317. }
  23318. } else {
  23319. results = treemapSingledimensional(data, width, height, xoffset, yoffset);
  23320. }
  23321. return results;
  23322. }
  23323. // treemapSingledimensional - simple wrapper around squarify
  23324. function treemapSingledimensional(data, width, height, xoffset, yoffset) {
  23325. xoffset = typeof xoffset === 'undefined' ? 0 : xoffset;
  23326. yoffset = typeof yoffset === 'undefined' ? 0 : yoffset;
  23327. var rawtreemap = squarify(normalize(data, width * height), [], new Container(xoffset, yoffset, width, height), []);
  23328. return flattenTreemap(rawtreemap);
  23329. }
  23330. // flattenTreemap - squarify implementation returns an array of arrays of coordinates
  23331. // because we have a new array everytime we switch to building a new row
  23332. // this converts it into an array of coordinates.
  23333. function flattenTreemap(rawtreemap) {
  23334. var flattreemap = [];
  23335. var i, j;
  23336. for (i = 0; i < rawtreemap.length; i++) {
  23337. for (j = 0; j < rawtreemap[i].length; j++) {
  23338. flattreemap.push(rawtreemap[i][j]);
  23339. }
  23340. }
  23341. return flattreemap;
  23342. }
  23343. // squarify - as per the Bruls paper
  23344. // plus coordinates stack and containers so we get
  23345. // usable data out of it
  23346. function squarify(data, currentrow, container, stack) {
  23347. var length;
  23348. var nextdatapoint;
  23349. var newcontainer;
  23350. if (data.length === 0) {
  23351. stack.push(container.getCoordinates(currentrow));
  23352. return;
  23353. }
  23354. length = container.shortestEdge();
  23355. nextdatapoint = data[0];
  23356. if (improvesRatio(currentrow, nextdatapoint, length)) {
  23357. currentrow.push(nextdatapoint);
  23358. squarify(data.slice(1), currentrow, container, stack);
  23359. } else {
  23360. newcontainer = container.cutArea(sumArray(currentrow), stack);
  23361. stack.push(container.getCoordinates(currentrow));
  23362. squarify(data, [], newcontainer, stack);
  23363. }
  23364. return stack;
  23365. }
  23366. // improveRatio - implements the worse calculation and comparision as given in Bruls
  23367. // (note the error in the original paper; fixed here)
  23368. function improvesRatio(currentrow, nextnode, length) {
  23369. var newrow;
  23370. if (currentrow.length === 0) {
  23371. return true;
  23372. }
  23373. newrow = currentrow.slice();
  23374. newrow.push(nextnode);
  23375. var currentratio = calculateRatio(currentrow, length);
  23376. var newratio = calculateRatio(newrow, length);
  23377. // the pseudocode in the Bruls paper has the direction of the comparison
  23378. // wrong, this is the correct one.
  23379. return currentratio >= newratio;
  23380. }
  23381. // calculateRatio - calculates the maximum width to height ratio of the
  23382. // boxes in this row
  23383. function calculateRatio(row, length) {
  23384. var min = Math.min.apply(Math, row);
  23385. var max = Math.max.apply(Math, row);
  23386. var sum = sumArray(row);
  23387. return Math.max(Math.pow(length, 2) * max / Math.pow(sum, 2), Math.pow(sum, 2) / (Math.pow(length, 2) * min));
  23388. }
  23389. // isArray - checks if arr is an array
  23390. function isArray(arr) {
  23391. return arr && arr.constructor === Array;
  23392. }
  23393. // sumArray - sums a single dimensional array
  23394. function sumArray(arr) {
  23395. var sum = 0;
  23396. var i;
  23397. for (i = 0; i < arr.length; i++) {
  23398. sum += arr[i];
  23399. }
  23400. return sum;
  23401. }
  23402. // sumMultidimensionalArray - sums the values in a nested array (aka [[0,1],[[2,3]]])
  23403. function sumMultidimensionalArray(arr) {
  23404. var i,
  23405. total = 0;
  23406. if (isArray(arr[0])) {
  23407. for (i = 0; i < arr.length; i++) {
  23408. total += sumMultidimensionalArray(arr[i]);
  23409. }
  23410. } else {
  23411. total = sumArray(arr);
  23412. }
  23413. return total;
  23414. }
  23415. return treemapMultidimensional;
  23416. }();
  23417. })();
  23418. /**
  23419. * ApexCharts TreemapChart Class.
  23420. * @module TreemapChart
  23421. **/
  23422. var TreemapChart = /*#__PURE__*/function () {
  23423. function TreemapChart(ctx, xyRatios) {
  23424. _classCallCheck(this, TreemapChart);
  23425. this.ctx = ctx;
  23426. this.w = ctx.w;
  23427. this.strokeWidth = this.w.config.stroke.width;
  23428. this.helpers = new TreemapHelpers(ctx);
  23429. this.dynamicAnim = this.w.config.chart.animations.dynamicAnimation;
  23430. this.labels = [];
  23431. }
  23432. _createClass(TreemapChart, [{
  23433. key: "draw",
  23434. value: function draw(series) {
  23435. var _this = this;
  23436. var w = this.w;
  23437. var graphics = new Graphics(this.ctx);
  23438. var fill = new Fill(this.ctx);
  23439. var ret = graphics.group({
  23440. class: 'apexcharts-treemap'
  23441. });
  23442. if (w.globals.noData) return ret;
  23443. var ser = [];
  23444. series.forEach(function (s) {
  23445. var d = s.map(function (v) {
  23446. return Math.abs(v);
  23447. });
  23448. ser.push(d);
  23449. });
  23450. this.negRange = this.helpers.checkColorRange();
  23451. w.config.series.forEach(function (s, i) {
  23452. s.data.forEach(function (l) {
  23453. if (!Array.isArray(_this.labels[i])) _this.labels[i] = [];
  23454. _this.labels[i].push(l.x);
  23455. });
  23456. });
  23457. var nodes = window.TreemapSquared.generate(ser, w.globals.gridWidth, w.globals.gridHeight);
  23458. nodes.forEach(function (node, i) {
  23459. var elSeries = graphics.group({
  23460. class: "apexcharts-series apexcharts-treemap-series",
  23461. seriesName: Utils$1.escapeString(w.globals.seriesNames[i]),
  23462. rel: i + 1,
  23463. 'data:realIndex': i
  23464. });
  23465. if (w.config.chart.dropShadow.enabled) {
  23466. var shadow = w.config.chart.dropShadow;
  23467. var filters = new Filters(_this.ctx);
  23468. filters.dropShadow(ret, shadow, i);
  23469. }
  23470. var elDataLabelWrap = graphics.group({
  23471. class: 'apexcharts-data-labels'
  23472. });
  23473. node.forEach(function (r, j) {
  23474. var x1 = r[0];
  23475. var y1 = r[1];
  23476. var x2 = r[2];
  23477. var y2 = r[3];
  23478. 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]);
  23479. elRect.attr({
  23480. cx: x1,
  23481. cy: y1,
  23482. index: i,
  23483. i: i,
  23484. j: j,
  23485. width: x2 - x1,
  23486. height: y2 - y1
  23487. });
  23488. var colorProps = _this.helpers.getShadeColor(w.config.chart.type, i, j, _this.negRange);
  23489. var color = colorProps.color;
  23490. if (typeof w.config.series[i].data[j] !== 'undefined' && w.config.series[i].data[j].fillColor) {
  23491. color = w.config.series[i].data[j].fillColor;
  23492. }
  23493. var pathFill = fill.fillPath({
  23494. color: color,
  23495. seriesNumber: i,
  23496. dataPointIndex: j
  23497. });
  23498. elRect.node.classList.add('apexcharts-treemap-rect');
  23499. elRect.attr({
  23500. fill: pathFill
  23501. });
  23502. _this.helpers.addListeners(elRect);
  23503. var fromRect = {
  23504. x: x1 + (x2 - x1) / 2,
  23505. y: y1 + (y2 - y1) / 2,
  23506. width: 0,
  23507. height: 0
  23508. };
  23509. var toRect = {
  23510. x: x1,
  23511. y: y1,
  23512. width: x2 - x1,
  23513. height: y2 - y1
  23514. };
  23515. if (w.config.chart.animations.enabled && !w.globals.dataChanged) {
  23516. var speed = 1;
  23517. if (!w.globals.resized) {
  23518. speed = w.config.chart.animations.speed;
  23519. }
  23520. _this.animateTreemap(elRect, fromRect, toRect, speed);
  23521. }
  23522. if (w.globals.dataChanged) {
  23523. var _speed = 1;
  23524. if (_this.dynamicAnim.enabled && w.globals.shouldAnimate) {
  23525. _speed = _this.dynamicAnim.speed;
  23526. if (w.globals.previousPaths[i] && w.globals.previousPaths[i][j] && w.globals.previousPaths[i][j].rect) {
  23527. fromRect = w.globals.previousPaths[i][j].rect;
  23528. }
  23529. _this.animateTreemap(elRect, fromRect, toRect, _speed);
  23530. }
  23531. }
  23532. var fontSize = _this.getFontSize(r);
  23533. var formattedText = w.config.dataLabels.formatter(_this.labels[i][j], {
  23534. value: w.globals.series[i][j],
  23535. seriesIndex: i,
  23536. dataPointIndex: j,
  23537. w: w
  23538. });
  23539. if (w.config.plotOptions.treemap.dataLabels.format === 'truncate') {
  23540. fontSize = parseInt(w.config.dataLabels.style.fontSize, 10);
  23541. formattedText = _this.truncateLabels(formattedText, fontSize, x1, y1, x2, y2);
  23542. }
  23543. var dataLabels = null;
  23544. if (w.globals.series[i][j]) {
  23545. dataLabels = _this.helpers.calculateDataLabels({
  23546. text: formattedText,
  23547. x: (x1 + x2) / 2,
  23548. y: (y1 + y2) / 2 + _this.strokeWidth / 2 + fontSize / 3,
  23549. i: i,
  23550. j: j,
  23551. colorProps: colorProps,
  23552. fontSize: fontSize,
  23553. series: series
  23554. });
  23555. }
  23556. if (w.config.dataLabels.enabled && dataLabels) {
  23557. _this.rotateToFitLabel(dataLabels, fontSize, formattedText, x1, y1, x2, y2);
  23558. }
  23559. elSeries.add(elRect);
  23560. if (dataLabels !== null) {
  23561. elSeries.add(dataLabels);
  23562. }
  23563. });
  23564. elSeries.add(elDataLabelWrap);
  23565. ret.add(elSeries);
  23566. });
  23567. return ret;
  23568. }
  23569. // This calculates a font-size based upon
  23570. // average label length and the size of the box the label is
  23571. // going into. The maximum font size is set in chart config.
  23572. }, {
  23573. key: "getFontSize",
  23574. value: function getFontSize(coordinates) {
  23575. var w = this.w;
  23576. // total length of labels (i.e [["Italy"],["Spain", "Greece"]] -> 16)
  23577. function totalLabelLength(arr) {
  23578. var i,
  23579. total = 0;
  23580. if (Array.isArray(arr[0])) {
  23581. for (i = 0; i < arr.length; i++) {
  23582. total += totalLabelLength(arr[i]);
  23583. }
  23584. } else {
  23585. for (i = 0; i < arr.length; i++) {
  23586. total += arr[i].length;
  23587. }
  23588. }
  23589. return total;
  23590. }
  23591. // count of labels (i.e [["Italy"],["Spain", "Greece"]] -> 3)
  23592. function countLabels(arr) {
  23593. var i,
  23594. total = 0;
  23595. if (Array.isArray(arr[0])) {
  23596. for (i = 0; i < arr.length; i++) {
  23597. total += countLabels(arr[i]);
  23598. }
  23599. } else {
  23600. for (i = 0; i < arr.length; i++) {
  23601. total += 1;
  23602. }
  23603. }
  23604. return total;
  23605. }
  23606. var averagelabelsize = totalLabelLength(this.labels) / countLabels(this.labels);
  23607. function fontSize(width, height) {
  23608. // the font size should be proportional to the size of the box (and the value)
  23609. // otherwise you can end up creating a visual distortion where two boxes of identical
  23610. // size have different sized labels, and thus make it look as if the two boxes
  23611. // represent different sizes
  23612. var area = width * height;
  23613. var arearoot = Math.pow(area, 0.5);
  23614. return Math.min(arearoot / averagelabelsize, parseInt(w.config.dataLabels.style.fontSize, 10));
  23615. }
  23616. return fontSize(coordinates[2] - coordinates[0], coordinates[3] - coordinates[1]);
  23617. }
  23618. }, {
  23619. key: "rotateToFitLabel",
  23620. value: function rotateToFitLabel(elText, fontSize, text, x1, y1, x2, y2) {
  23621. var graphics = new Graphics(this.ctx);
  23622. var textRect = graphics.getTextRects(text, fontSize);
  23623. //if the label fits better sideways then rotate it
  23624. if (textRect.width + this.w.config.stroke.width + 5 > x2 - x1 && textRect.width <= y2 - y1) {
  23625. var labelRotatingCenter = graphics.rotateAroundCenter(elText.node);
  23626. elText.node.setAttribute('transform', "rotate(-90 ".concat(labelRotatingCenter.x, " ").concat(labelRotatingCenter.y, ") translate(").concat(textRect.height / 3, ")"));
  23627. }
  23628. }
  23629. // This is an alternative label formatting method that uses a
  23630. // consistent font size, and trims the edge of long labels
  23631. }, {
  23632. key: "truncateLabels",
  23633. value: function truncateLabels(text, fontSize, x1, y1, x2, y2) {
  23634. var graphics = new Graphics(this.ctx);
  23635. var textRect = graphics.getTextRects(text, fontSize);
  23636. // Determine max width based on ideal orientation of text
  23637. var labelMaxWidth = textRect.width + this.w.config.stroke.width + 5 > x2 - x1 && y2 - y1 > x2 - x1 ? y2 - y1 : x2 - x1;
  23638. var truncatedText = graphics.getTextBasedOnMaxWidth({
  23639. text: text,
  23640. maxWidth: labelMaxWidth,
  23641. fontSize: fontSize
  23642. });
  23643. // Return empty label when text has been trimmed for very small rects
  23644. if (text.length !== truncatedText.length && labelMaxWidth / fontSize < 5) {
  23645. return '';
  23646. } else {
  23647. return truncatedText;
  23648. }
  23649. }
  23650. }, {
  23651. key: "animateTreemap",
  23652. value: function animateTreemap(el, fromRect, toRect, speed) {
  23653. var animations = new Animations(this.ctx);
  23654. animations.animateRect(el, {
  23655. x: fromRect.x,
  23656. y: fromRect.y,
  23657. width: fromRect.width,
  23658. height: fromRect.height
  23659. }, {
  23660. x: toRect.x,
  23661. y: toRect.y,
  23662. width: toRect.width,
  23663. height: toRect.height
  23664. }, speed, function () {
  23665. animations.animationCompleted(el);
  23666. });
  23667. }
  23668. }]);
  23669. return TreemapChart;
  23670. }();
  23671. var MINUTES_IN_DAY = 24 * 60;
  23672. var SECONDS_IN_DAY = MINUTES_IN_DAY * 60;
  23673. var MIN_ZOOM_DAYS = 10 / SECONDS_IN_DAY;
  23674. /**
  23675. * ApexCharts TimeScale Class for generating time ticks for x-axis.
  23676. *
  23677. * @module TimeScale
  23678. **/
  23679. var TimeScale = /*#__PURE__*/function () {
  23680. function TimeScale(ctx) {
  23681. _classCallCheck(this, TimeScale);
  23682. this.ctx = ctx;
  23683. this.w = ctx.w;
  23684. this.timeScaleArray = [];
  23685. this.utc = this.w.config.xaxis.labels.datetimeUTC;
  23686. }
  23687. _createClass(TimeScale, [{
  23688. key: "calculateTimeScaleTicks",
  23689. value: function calculateTimeScaleTicks(minX, maxX) {
  23690. var _this = this;
  23691. var w = this.w;
  23692. // null check when no series to show
  23693. if (w.globals.allSeriesCollapsed) {
  23694. w.globals.labels = [];
  23695. w.globals.timescaleLabels = [];
  23696. return [];
  23697. }
  23698. var dt = new DateTime(this.ctx);
  23699. var daysDiff = (maxX - minX) / (1000 * SECONDS_IN_DAY);
  23700. this.determineInterval(daysDiff);
  23701. w.globals.disableZoomIn = false;
  23702. w.globals.disableZoomOut = false;
  23703. if (daysDiff < MIN_ZOOM_DAYS) {
  23704. w.globals.disableZoomIn = true;
  23705. } else if (daysDiff > 50000) {
  23706. w.globals.disableZoomOut = true;
  23707. }
  23708. var timeIntervals = dt.getTimeUnitsfromTimestamp(minX, maxX, this.utc);
  23709. var daysWidthOnXAxis = w.globals.gridWidth / daysDiff;
  23710. var hoursWidthOnXAxis = daysWidthOnXAxis / 24;
  23711. var minutesWidthOnXAxis = hoursWidthOnXAxis / 60;
  23712. var secondsWidthOnXAxis = minutesWidthOnXAxis / 60;
  23713. var numberOfHours = Math.floor(daysDiff * 24);
  23714. var numberOfMinutes = Math.floor(daysDiff * MINUTES_IN_DAY);
  23715. var numberOfSeconds = Math.floor(daysDiff * SECONDS_IN_DAY);
  23716. var numberOfDays = Math.floor(daysDiff);
  23717. var numberOfMonths = Math.floor(daysDiff / 30);
  23718. var numberOfYears = Math.floor(daysDiff / 365);
  23719. var firstVal = {
  23720. minMillisecond: timeIntervals.minMillisecond,
  23721. minSecond: timeIntervals.minSecond,
  23722. minMinute: timeIntervals.minMinute,
  23723. minHour: timeIntervals.minHour,
  23724. minDate: timeIntervals.minDate,
  23725. minMonth: timeIntervals.minMonth,
  23726. minYear: timeIntervals.minYear
  23727. };
  23728. var currentMillisecond = firstVal.minMillisecond;
  23729. var currentSecond = firstVal.minSecond;
  23730. var currentMinute = firstVal.minMinute;
  23731. var currentHour = firstVal.minHour;
  23732. var currentMonthDate = firstVal.minDate;
  23733. var currentDate = firstVal.minDate;
  23734. var currentMonth = firstVal.minMonth;
  23735. var currentYear = firstVal.minYear;
  23736. var params = {
  23737. firstVal: firstVal,
  23738. currentMillisecond: currentMillisecond,
  23739. currentSecond: currentSecond,
  23740. currentMinute: currentMinute,
  23741. currentHour: currentHour,
  23742. currentMonthDate: currentMonthDate,
  23743. currentDate: currentDate,
  23744. currentMonth: currentMonth,
  23745. currentYear: currentYear,
  23746. daysWidthOnXAxis: daysWidthOnXAxis,
  23747. hoursWidthOnXAxis: hoursWidthOnXAxis,
  23748. minutesWidthOnXAxis: minutesWidthOnXAxis,
  23749. secondsWidthOnXAxis: secondsWidthOnXAxis,
  23750. numberOfSeconds: numberOfSeconds,
  23751. numberOfMinutes: numberOfMinutes,
  23752. numberOfHours: numberOfHours,
  23753. numberOfDays: numberOfDays,
  23754. numberOfMonths: numberOfMonths,
  23755. numberOfYears: numberOfYears
  23756. };
  23757. switch (this.tickInterval) {
  23758. case 'years':
  23759. {
  23760. this.generateYearScale(params);
  23761. break;
  23762. }
  23763. case 'months':
  23764. case 'half_year':
  23765. {
  23766. this.generateMonthScale(params);
  23767. break;
  23768. }
  23769. case 'months_days':
  23770. case 'months_fortnight':
  23771. case 'days':
  23772. case 'week_days':
  23773. {
  23774. this.generateDayScale(params);
  23775. break;
  23776. }
  23777. case 'hours':
  23778. {
  23779. this.generateHourScale(params);
  23780. break;
  23781. }
  23782. case 'minutes_fives':
  23783. case 'minutes':
  23784. this.generateMinuteScale(params);
  23785. break;
  23786. case 'seconds_tens':
  23787. case 'seconds_fives':
  23788. case 'seconds':
  23789. this.generateSecondScale(params);
  23790. break;
  23791. }
  23792. // first, we will adjust the month values index
  23793. // as in the upper function, it is starting from 0
  23794. // we will start them from 1
  23795. var adjustedMonthInTimeScaleArray = this.timeScaleArray.map(function (ts) {
  23796. var defaultReturn = {
  23797. position: ts.position,
  23798. unit: ts.unit,
  23799. year: ts.year,
  23800. day: ts.day ? ts.day : 1,
  23801. hour: ts.hour ? ts.hour : 0,
  23802. month: ts.month + 1
  23803. };
  23804. if (ts.unit === 'month') {
  23805. return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
  23806. day: 1,
  23807. value: ts.value + 1
  23808. });
  23809. } else if (ts.unit === 'day' || ts.unit === 'hour') {
  23810. return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
  23811. value: ts.value
  23812. });
  23813. } else if (ts.unit === 'minute') {
  23814. return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
  23815. value: ts.value,
  23816. minute: ts.value
  23817. });
  23818. } else if (ts.unit === 'second') {
  23819. return _objectSpread2(_objectSpread2({}, defaultReturn), {}, {
  23820. value: ts.value,
  23821. minute: ts.minute,
  23822. second: ts.second
  23823. });
  23824. }
  23825. return ts;
  23826. });
  23827. var filteredTimeScale = adjustedMonthInTimeScaleArray.filter(function (ts) {
  23828. var modulo = 1;
  23829. var ticks = Math.ceil(w.globals.gridWidth / 120);
  23830. var value = ts.value;
  23831. if (w.config.xaxis.tickAmount !== undefined) {
  23832. ticks = w.config.xaxis.tickAmount;
  23833. }
  23834. if (adjustedMonthInTimeScaleArray.length > ticks) {
  23835. modulo = Math.floor(adjustedMonthInTimeScaleArray.length / ticks);
  23836. }
  23837. var shouldNotSkipUnit = false; // there is a big change in unit i.e days to months
  23838. var shouldNotPrint = false; // should skip these values
  23839. switch (_this.tickInterval) {
  23840. case 'years':
  23841. // make years label denser
  23842. if (ts.unit === 'year') {
  23843. shouldNotSkipUnit = true;
  23844. }
  23845. break;
  23846. case 'half_year':
  23847. modulo = 7;
  23848. if (ts.unit === 'year') {
  23849. shouldNotSkipUnit = true;
  23850. }
  23851. break;
  23852. case 'months':
  23853. modulo = 1;
  23854. if (ts.unit === 'year') {
  23855. shouldNotSkipUnit = true;
  23856. }
  23857. break;
  23858. case 'months_fortnight':
  23859. modulo = 15;
  23860. if (ts.unit === 'year' || ts.unit === 'month') {
  23861. shouldNotSkipUnit = true;
  23862. }
  23863. if (value === 30) {
  23864. shouldNotPrint = true;
  23865. }
  23866. break;
  23867. case 'months_days':
  23868. modulo = 10;
  23869. if (ts.unit === 'month') {
  23870. shouldNotSkipUnit = true;
  23871. }
  23872. if (value === 30) {
  23873. shouldNotPrint = true;
  23874. }
  23875. break;
  23876. case 'week_days':
  23877. modulo = 8;
  23878. if (ts.unit === 'month') {
  23879. shouldNotSkipUnit = true;
  23880. }
  23881. break;
  23882. case 'days':
  23883. modulo = 1;
  23884. if (ts.unit === 'month') {
  23885. shouldNotSkipUnit = true;
  23886. }
  23887. break;
  23888. case 'hours':
  23889. if (ts.unit === 'day') {
  23890. shouldNotSkipUnit = true;
  23891. }
  23892. break;
  23893. case 'minutes_fives':
  23894. if (value % 5 !== 0) {
  23895. shouldNotPrint = true;
  23896. }
  23897. break;
  23898. case 'seconds_tens':
  23899. if (value % 10 !== 0) {
  23900. shouldNotPrint = true;
  23901. }
  23902. break;
  23903. case 'seconds_fives':
  23904. if (value % 5 !== 0) {
  23905. shouldNotPrint = true;
  23906. }
  23907. break;
  23908. }
  23909. if (_this.tickInterval === 'hours' || _this.tickInterval === 'minutes_fives' || _this.tickInterval === 'seconds_tens' || _this.tickInterval === 'seconds_fives') {
  23910. if (!shouldNotPrint) {
  23911. return true;
  23912. }
  23913. } else {
  23914. if ((value % modulo === 0 || shouldNotSkipUnit) && !shouldNotPrint) {
  23915. return true;
  23916. }
  23917. }
  23918. });
  23919. return filteredTimeScale;
  23920. }
  23921. }, {
  23922. key: "recalcDimensionsBasedOnFormat",
  23923. value: function recalcDimensionsBasedOnFormat(filteredTimeScale, inverted) {
  23924. var w = this.w;
  23925. var reformattedTimescaleArray = this.formatDates(filteredTimeScale);
  23926. var removedOverlappingTS = this.removeOverlappingTS(reformattedTimescaleArray);
  23927. w.globals.timescaleLabels = removedOverlappingTS.slice();
  23928. // at this stage, we need to re-calculate coords of the grid as timeline labels may have altered the xaxis labels coords
  23929. // 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
  23930. // Dependency on Dimensions(), need to refactor correctly
  23931. // TODO - find an alternate way to avoid calling this Heavy method twice
  23932. var dimensions = new Dimensions(this.ctx);
  23933. dimensions.plotCoords();
  23934. }
  23935. }, {
  23936. key: "determineInterval",
  23937. value: function determineInterval(daysDiff) {
  23938. var yearsDiff = daysDiff / 365;
  23939. var hoursDiff = daysDiff * 24;
  23940. var minutesDiff = hoursDiff * 60;
  23941. var secondsDiff = minutesDiff * 60;
  23942. switch (true) {
  23943. case yearsDiff > 5:
  23944. this.tickInterval = 'years';
  23945. break;
  23946. case daysDiff > 800:
  23947. this.tickInterval = 'half_year';
  23948. break;
  23949. case daysDiff > 180:
  23950. this.tickInterval = 'months';
  23951. break;
  23952. case daysDiff > 90:
  23953. this.tickInterval = 'months_fortnight';
  23954. break;
  23955. case daysDiff > 60:
  23956. this.tickInterval = 'months_days';
  23957. break;
  23958. case daysDiff > 30:
  23959. this.tickInterval = 'week_days';
  23960. break;
  23961. case daysDiff > 2:
  23962. this.tickInterval = 'days';
  23963. break;
  23964. case hoursDiff > 2.4:
  23965. this.tickInterval = 'hours';
  23966. break;
  23967. case minutesDiff > 15:
  23968. this.tickInterval = 'minutes_fives';
  23969. break;
  23970. case minutesDiff > 5:
  23971. this.tickInterval = 'minutes';
  23972. break;
  23973. case minutesDiff > 1:
  23974. this.tickInterval = 'seconds_tens';
  23975. break;
  23976. case secondsDiff > 20:
  23977. this.tickInterval = 'seconds_fives';
  23978. break;
  23979. default:
  23980. this.tickInterval = 'seconds';
  23981. break;
  23982. }
  23983. }
  23984. }, {
  23985. key: "generateYearScale",
  23986. value: function generateYearScale(_ref) {
  23987. var firstVal = _ref.firstVal,
  23988. currentMonth = _ref.currentMonth,
  23989. currentYear = _ref.currentYear,
  23990. daysWidthOnXAxis = _ref.daysWidthOnXAxis,
  23991. numberOfYears = _ref.numberOfYears;
  23992. var firstTickValue = firstVal.minYear;
  23993. var firstTickPosition = 0;
  23994. var dt = new DateTime(this.ctx);
  23995. var unit = 'year';
  23996. if (firstVal.minDate > 1 || firstVal.minMonth > 0) {
  23997. var remainingDays = dt.determineRemainingDaysOfYear(firstVal.minYear, firstVal.minMonth, firstVal.minDate);
  23998. // remainingDaysofFirstMonth is used to reacht the 2nd tick position
  23999. var remainingDaysOfFirstYear = dt.determineDaysOfYear(firstVal.minYear) - remainingDays + 1;
  24000. // calculate the first tick position
  24001. firstTickPosition = remainingDaysOfFirstYear * daysWidthOnXAxis;
  24002. firstTickValue = firstVal.minYear + 1;
  24003. // push the first tick in the array
  24004. this.timeScaleArray.push({
  24005. position: firstTickPosition,
  24006. value: firstTickValue,
  24007. unit: unit,
  24008. year: firstTickValue,
  24009. month: Utils$1.monthMod(currentMonth + 1)
  24010. });
  24011. } else if (firstVal.minDate === 1 && firstVal.minMonth === 0) {
  24012. // push the first tick in the array
  24013. this.timeScaleArray.push({
  24014. position: firstTickPosition,
  24015. value: firstTickValue,
  24016. unit: unit,
  24017. year: currentYear,
  24018. month: Utils$1.monthMod(currentMonth + 1)
  24019. });
  24020. }
  24021. var year = firstTickValue;
  24022. var pos = firstTickPosition;
  24023. // keep drawing rest of the ticks
  24024. for (var i = 0; i < numberOfYears; i++) {
  24025. year++;
  24026. pos = dt.determineDaysOfYear(year - 1) * daysWidthOnXAxis + pos;
  24027. this.timeScaleArray.push({
  24028. position: pos,
  24029. value: year,
  24030. unit: unit,
  24031. year: year,
  24032. month: 1
  24033. });
  24034. }
  24035. }
  24036. }, {
  24037. key: "generateMonthScale",
  24038. value: function generateMonthScale(_ref2) {
  24039. var firstVal = _ref2.firstVal,
  24040. currentMonthDate = _ref2.currentMonthDate,
  24041. currentMonth = _ref2.currentMonth,
  24042. currentYear = _ref2.currentYear,
  24043. daysWidthOnXAxis = _ref2.daysWidthOnXAxis,
  24044. numberOfMonths = _ref2.numberOfMonths;
  24045. var firstTickValue = currentMonth;
  24046. var firstTickPosition = 0;
  24047. var dt = new DateTime(this.ctx);
  24048. var unit = 'month';
  24049. var yrCounter = 0;
  24050. if (firstVal.minDate > 1) {
  24051. // remainingDaysofFirstMonth is used to reacht the 2nd tick position
  24052. var remainingDaysOfFirstMonth = dt.determineDaysOfMonths(currentMonth + 1, firstVal.minYear) - currentMonthDate + 1;
  24053. // calculate the first tick position
  24054. firstTickPosition = remainingDaysOfFirstMonth * daysWidthOnXAxis;
  24055. firstTickValue = Utils$1.monthMod(currentMonth + 1);
  24056. var year = currentYear + yrCounter;
  24057. var _month = Utils$1.monthMod(firstTickValue);
  24058. var value = firstTickValue;
  24059. // it's Jan, so update the year
  24060. if (firstTickValue === 0) {
  24061. unit = 'year';
  24062. value = year;
  24063. _month = 1;
  24064. yrCounter += 1;
  24065. year = year + yrCounter;
  24066. }
  24067. // push the first tick in the array
  24068. this.timeScaleArray.push({
  24069. position: firstTickPosition,
  24070. value: value,
  24071. unit: unit,
  24072. year: year,
  24073. month: _month
  24074. });
  24075. } else {
  24076. // push the first tick in the array
  24077. this.timeScaleArray.push({
  24078. position: firstTickPosition,
  24079. value: firstTickValue,
  24080. unit: unit,
  24081. year: currentYear,
  24082. month: Utils$1.monthMod(currentMonth)
  24083. });
  24084. }
  24085. var month = firstTickValue + 1;
  24086. var pos = firstTickPosition;
  24087. // keep drawing rest of the ticks
  24088. for (var i = 0, j = 1; i < numberOfMonths; i++, j++) {
  24089. month = Utils$1.monthMod(month);
  24090. if (month === 0) {
  24091. unit = 'year';
  24092. yrCounter += 1;
  24093. } else {
  24094. unit = 'month';
  24095. }
  24096. var _year = this._getYear(currentYear, month, yrCounter);
  24097. pos = dt.determineDaysOfMonths(month, _year) * daysWidthOnXAxis + pos;
  24098. var monthVal = month === 0 ? _year : month;
  24099. this.timeScaleArray.push({
  24100. position: pos,
  24101. value: monthVal,
  24102. unit: unit,
  24103. year: _year,
  24104. month: month === 0 ? 1 : month
  24105. });
  24106. month++;
  24107. }
  24108. }
  24109. }, {
  24110. key: "generateDayScale",
  24111. value: function generateDayScale(_ref3) {
  24112. var firstVal = _ref3.firstVal,
  24113. currentMonth = _ref3.currentMonth,
  24114. currentYear = _ref3.currentYear,
  24115. hoursWidthOnXAxis = _ref3.hoursWidthOnXAxis,
  24116. numberOfDays = _ref3.numberOfDays;
  24117. var dt = new DateTime(this.ctx);
  24118. var unit = 'day';
  24119. var firstTickValue = firstVal.minDate + 1;
  24120. var date = firstTickValue;
  24121. var changeMonth = function changeMonth(dateVal, month, year) {
  24122. var monthdays = dt.determineDaysOfMonths(month + 1, year);
  24123. if (dateVal > monthdays) {
  24124. month = month + 1;
  24125. date = 1;
  24126. unit = 'month';
  24127. val = month;
  24128. return month;
  24129. }
  24130. return month;
  24131. };
  24132. var remainingHours = 24 - firstVal.minHour;
  24133. var yrCounter = 0;
  24134. // calculate the first tick position
  24135. var firstTickPosition = remainingHours * hoursWidthOnXAxis;
  24136. var val = firstTickValue;
  24137. var month = changeMonth(date, currentMonth, currentYear);
  24138. if (firstVal.minHour === 0 && firstVal.minDate === 1) {
  24139. // the first value is the first day of month
  24140. firstTickPosition = 0;
  24141. val = Utils$1.monthMod(firstVal.minMonth);
  24142. unit = 'month';
  24143. date = firstVal.minDate;
  24144. // numberOfDays++
  24145. // removed the above line to fix https://github.com/apexcharts/apexcharts.js/issues/305#issuecomment-1019520513
  24146. } else if (firstVal.minDate !== 1 && firstVal.minHour === 0 && firstVal.minMinute === 0) {
  24147. // fixes apexcharts/apexcharts.js/issues/1730
  24148. firstTickPosition = 0;
  24149. firstTickValue = firstVal.minDate;
  24150. date = firstTickValue;
  24151. val = firstTickValue;
  24152. // in case it's the last date of month, we need to check it
  24153. month = changeMonth(date, currentMonth, currentYear);
  24154. }
  24155. // push the first tick in the array
  24156. this.timeScaleArray.push({
  24157. position: firstTickPosition,
  24158. value: val,
  24159. unit: unit,
  24160. year: this._getYear(currentYear, month, yrCounter),
  24161. month: Utils$1.monthMod(month),
  24162. day: date
  24163. });
  24164. var pos = firstTickPosition;
  24165. // keep drawing rest of the ticks
  24166. for (var i = 0; i < numberOfDays; i++) {
  24167. date += 1;
  24168. unit = 'day';
  24169. month = changeMonth(date, month, this._getYear(currentYear, month, yrCounter));
  24170. var year = this._getYear(currentYear, month, yrCounter);
  24171. pos = 24 * hoursWidthOnXAxis + pos;
  24172. var value = date === 1 ? Utils$1.monthMod(month) : date;
  24173. this.timeScaleArray.push({
  24174. position: pos,
  24175. value: value,
  24176. unit: unit,
  24177. year: year,
  24178. month: Utils$1.monthMod(month),
  24179. day: value
  24180. });
  24181. }
  24182. }
  24183. }, {
  24184. key: "generateHourScale",
  24185. value: function generateHourScale(_ref4) {
  24186. var firstVal = _ref4.firstVal,
  24187. currentDate = _ref4.currentDate,
  24188. currentMonth = _ref4.currentMonth,
  24189. currentYear = _ref4.currentYear,
  24190. minutesWidthOnXAxis = _ref4.minutesWidthOnXAxis,
  24191. numberOfHours = _ref4.numberOfHours;
  24192. var dt = new DateTime(this.ctx);
  24193. var yrCounter = 0;
  24194. var unit = 'hour';
  24195. var changeDate = function changeDate(dateVal, month) {
  24196. var monthdays = dt.determineDaysOfMonths(month + 1, currentYear);
  24197. if (dateVal > monthdays) {
  24198. date = 1;
  24199. month = month + 1;
  24200. }
  24201. return {
  24202. month: month,
  24203. date: date
  24204. };
  24205. };
  24206. var changeMonth = function changeMonth(dateVal, month) {
  24207. var monthdays = dt.determineDaysOfMonths(month + 1, currentYear);
  24208. if (dateVal > monthdays) {
  24209. month = month + 1;
  24210. return month;
  24211. }
  24212. return month;
  24213. };
  24214. // factor in minSeconds as well
  24215. var remainingMins = 60 - (firstVal.minMinute + firstVal.minSecond / 60.0);
  24216. var firstTickPosition = remainingMins * minutesWidthOnXAxis;
  24217. var firstTickValue = firstVal.minHour + 1;
  24218. var hour = firstTickValue;
  24219. if (remainingMins === 60) {
  24220. firstTickPosition = 0;
  24221. firstTickValue = firstVal.minHour;
  24222. hour = firstTickValue;
  24223. }
  24224. var date = currentDate;
  24225. // we need to apply date switching logic here as well, to avoid duplicated labels
  24226. if (hour >= 24) {
  24227. hour = 0;
  24228. date += 1;
  24229. unit = 'day';
  24230. }
  24231. var checkNextMonth = changeDate(date, currentMonth);
  24232. var month = checkNextMonth.month;
  24233. month = changeMonth(date, month);
  24234. // push the first tick in the array
  24235. this.timeScaleArray.push({
  24236. position: firstTickPosition,
  24237. value: firstTickValue,
  24238. unit: unit,
  24239. day: date,
  24240. hour: hour,
  24241. year: currentYear,
  24242. month: Utils$1.monthMod(month)
  24243. });
  24244. hour++;
  24245. var pos = firstTickPosition;
  24246. // keep drawing rest of the ticks
  24247. for (var i = 0; i < numberOfHours; i++) {
  24248. unit = 'hour';
  24249. if (hour >= 24) {
  24250. hour = 0;
  24251. date += 1;
  24252. unit = 'day';
  24253. var _checkNextMonth = changeDate(date, month);
  24254. month = _checkNextMonth.month;
  24255. month = changeMonth(date, month);
  24256. }
  24257. var year = this._getYear(currentYear, month, yrCounter);
  24258. pos = 60 * minutesWidthOnXAxis + pos;
  24259. var val = hour === 0 ? date : hour;
  24260. this.timeScaleArray.push({
  24261. position: pos,
  24262. value: val,
  24263. unit: unit,
  24264. hour: hour,
  24265. day: date,
  24266. year: year,
  24267. month: Utils$1.monthMod(month)
  24268. });
  24269. hour++;
  24270. }
  24271. }
  24272. }, {
  24273. key: "generateMinuteScale",
  24274. value: function generateMinuteScale(_ref5) {
  24275. var currentMillisecond = _ref5.currentMillisecond,
  24276. currentSecond = _ref5.currentSecond,
  24277. currentMinute = _ref5.currentMinute,
  24278. currentHour = _ref5.currentHour,
  24279. currentDate = _ref5.currentDate,
  24280. currentMonth = _ref5.currentMonth,
  24281. currentYear = _ref5.currentYear,
  24282. minutesWidthOnXAxis = _ref5.minutesWidthOnXAxis,
  24283. secondsWidthOnXAxis = _ref5.secondsWidthOnXAxis,
  24284. numberOfMinutes = _ref5.numberOfMinutes;
  24285. var yrCounter = 0;
  24286. var unit = 'minute';
  24287. var remainingSecs = 60 - currentSecond;
  24288. var firstTickPosition = (remainingSecs - currentMillisecond / 1000) * secondsWidthOnXAxis;
  24289. var minute = currentMinute + 1;
  24290. var date = currentDate;
  24291. var month = currentMonth;
  24292. var year = currentYear;
  24293. var hour = currentHour;
  24294. var pos = firstTickPosition;
  24295. for (var i = 0; i < numberOfMinutes; i++) {
  24296. if (minute >= 60) {
  24297. minute = 0;
  24298. hour += 1;
  24299. if (hour === 24) {
  24300. hour = 0;
  24301. }
  24302. }
  24303. this.timeScaleArray.push({
  24304. position: pos,
  24305. value: minute,
  24306. unit: unit,
  24307. hour: hour,
  24308. minute: minute,
  24309. day: date,
  24310. year: this._getYear(year, month, yrCounter),
  24311. month: Utils$1.monthMod(month)
  24312. });
  24313. pos += minutesWidthOnXAxis;
  24314. minute++;
  24315. }
  24316. }
  24317. }, {
  24318. key: "generateSecondScale",
  24319. value: function generateSecondScale(_ref6) {
  24320. var currentMillisecond = _ref6.currentMillisecond,
  24321. currentSecond = _ref6.currentSecond,
  24322. currentMinute = _ref6.currentMinute,
  24323. currentHour = _ref6.currentHour,
  24324. currentDate = _ref6.currentDate,
  24325. currentMonth = _ref6.currentMonth,
  24326. currentYear = _ref6.currentYear,
  24327. secondsWidthOnXAxis = _ref6.secondsWidthOnXAxis,
  24328. numberOfSeconds = _ref6.numberOfSeconds;
  24329. var yrCounter = 0;
  24330. var unit = 'second';
  24331. var remainingMillisecs = 1000 - currentMillisecond;
  24332. var firstTickPosition = remainingMillisecs / 1000 * secondsWidthOnXAxis;
  24333. var second = currentSecond + 1;
  24334. var minute = currentMinute;
  24335. var date = currentDate;
  24336. var month = currentMonth;
  24337. var year = currentYear;
  24338. var hour = currentHour;
  24339. var pos = firstTickPosition;
  24340. for (var i = 0; i < numberOfSeconds; i++) {
  24341. if (second >= 60) {
  24342. minute++;
  24343. second = 0;
  24344. if (minute >= 60) {
  24345. hour++;
  24346. minute = 0;
  24347. if (hour === 24) {
  24348. hour = 0;
  24349. }
  24350. }
  24351. }
  24352. this.timeScaleArray.push({
  24353. position: pos,
  24354. value: second,
  24355. unit: unit,
  24356. hour: hour,
  24357. minute: minute,
  24358. second: second,
  24359. day: date,
  24360. year: this._getYear(year, month, yrCounter),
  24361. month: Utils$1.monthMod(month)
  24362. });
  24363. pos += secondsWidthOnXAxis;
  24364. second++;
  24365. }
  24366. }
  24367. }, {
  24368. key: "createRawDateString",
  24369. value: function createRawDateString(ts, value) {
  24370. var raw = ts.year;
  24371. if (ts.month === 0) {
  24372. // invalid month, correct it
  24373. ts.month = 1;
  24374. }
  24375. raw += '-' + ('0' + ts.month.toString()).slice(-2);
  24376. // unit is day
  24377. if (ts.unit === 'day') {
  24378. raw += ts.unit === 'day' ? '-' + ('0' + value).slice(-2) : '-01';
  24379. } else {
  24380. raw += '-' + ('0' + (ts.day ? ts.day : '1')).slice(-2);
  24381. }
  24382. // unit is hour
  24383. if (ts.unit === 'hour') {
  24384. raw += ts.unit === 'hour' ? 'T' + ('0' + value).slice(-2) : 'T00';
  24385. } else {
  24386. raw += 'T' + ('0' + (ts.hour ? ts.hour : '0')).slice(-2);
  24387. }
  24388. if (ts.unit === 'minute') {
  24389. raw += ':' + ('0' + value).slice(-2);
  24390. } else {
  24391. raw += ':' + (ts.minute ? ('0' + ts.minute).slice(-2) : '00');
  24392. }
  24393. if (ts.unit === 'second') {
  24394. raw += ':' + ('0' + value).slice(-2);
  24395. } else {
  24396. raw += ':00';
  24397. }
  24398. if (this.utc) {
  24399. raw += '.000Z';
  24400. }
  24401. return raw;
  24402. }
  24403. }, {
  24404. key: "formatDates",
  24405. value: function formatDates(filteredTimeScale) {
  24406. var _this2 = this;
  24407. var w = this.w;
  24408. var reformattedTimescaleArray = filteredTimeScale.map(function (ts) {
  24409. var value = ts.value.toString();
  24410. var dt = new DateTime(_this2.ctx);
  24411. var raw = _this2.createRawDateString(ts, value);
  24412. var dateToFormat = dt.getDate(dt.parseDate(raw));
  24413. if (!_this2.utc) {
  24414. // Fixes #1726, #1544, #1485, #1255
  24415. dateToFormat = dt.getDate(dt.parseDateWithTimezone(raw));
  24416. }
  24417. if (w.config.xaxis.labels.format === undefined) {
  24418. var customFormat = 'dd MMM';
  24419. var dtFormatter = w.config.xaxis.labels.datetimeFormatter;
  24420. if (ts.unit === 'year') customFormat = dtFormatter.year;
  24421. if (ts.unit === 'month') customFormat = dtFormatter.month;
  24422. if (ts.unit === 'day') customFormat = dtFormatter.day;
  24423. if (ts.unit === 'hour') customFormat = dtFormatter.hour;
  24424. if (ts.unit === 'minute') customFormat = dtFormatter.minute;
  24425. if (ts.unit === 'second') customFormat = dtFormatter.second;
  24426. value = dt.formatDate(dateToFormat, customFormat);
  24427. } else {
  24428. value = dt.formatDate(dateToFormat, w.config.xaxis.labels.format);
  24429. }
  24430. return {
  24431. dateString: raw,
  24432. position: ts.position,
  24433. value: value,
  24434. unit: ts.unit,
  24435. year: ts.year,
  24436. month: ts.month
  24437. };
  24438. });
  24439. return reformattedTimescaleArray;
  24440. }
  24441. }, {
  24442. key: "removeOverlappingTS",
  24443. value: function removeOverlappingTS(arr) {
  24444. var _this3 = this;
  24445. var graphics = new Graphics(this.ctx);
  24446. var equalLabelLengthFlag = false; // These labels got same length?
  24447. var constantLabelWidth; // If true, what is the constant length to use
  24448. if (arr.length > 0 &&
  24449. // check arr length
  24450. arr[0].value &&
  24451. // check arr[0] contains value
  24452. arr.every(function (lb) {
  24453. return lb.value.length === arr[0].value.length;
  24454. }) // check every arr label value is the same as the first one
  24455. ) {
  24456. equalLabelLengthFlag = true; // These labels got same length
  24457. constantLabelWidth = graphics.getTextRects(arr[0].value).width; // The constant label width to use
  24458. }
  24459. var lastDrawnIndex = 0;
  24460. var filteredArray = arr.map(function (item, index) {
  24461. if (index > 0 && _this3.w.config.xaxis.labels.hideOverlappingLabels) {
  24462. var prevLabelWidth = !equalLabelLengthFlag // if vary in label length
  24463. ? graphics.getTextRects(arr[lastDrawnIndex].value).width // get individual length
  24464. : constantLabelWidth; // else: use constant length
  24465. var prevPos = arr[lastDrawnIndex].position;
  24466. var pos = item.position;
  24467. if (pos > prevPos + prevLabelWidth + 10) {
  24468. lastDrawnIndex = index;
  24469. return item;
  24470. } else {
  24471. return null;
  24472. }
  24473. } else {
  24474. return item;
  24475. }
  24476. });
  24477. filteredArray = filteredArray.filter(function (f) {
  24478. return f !== null;
  24479. });
  24480. return filteredArray;
  24481. }
  24482. }, {
  24483. key: "_getYear",
  24484. value: function _getYear(currentYear, month, yrCounter) {
  24485. return currentYear + Math.floor(month / 12) + yrCounter;
  24486. }
  24487. }]);
  24488. return TimeScale;
  24489. }();
  24490. /**
  24491. * ApexCharts Core Class responsible for major calculations and creating elements.
  24492. *
  24493. * @module Core
  24494. **/
  24495. var Core = /*#__PURE__*/function () {
  24496. function Core(el, ctx) {
  24497. _classCallCheck(this, Core);
  24498. this.ctx = ctx;
  24499. this.w = ctx.w;
  24500. this.el = el;
  24501. }
  24502. _createClass(Core, [{
  24503. key: "setupElements",
  24504. value: function setupElements() {
  24505. var _this$w = this.w,
  24506. gl = _this$w.globals,
  24507. cnf = _this$w.config;
  24508. var ct = cnf.chart.type;
  24509. var axisChartsArrTypes = ['line', 'area', 'bar', 'rangeBar', 'rangeArea', 'candlestick', 'boxPlot', 'scatter', 'bubble', 'radar', 'heatmap', 'treemap'];
  24510. var xyChartsArrTypes = ['line', 'area', 'bar', 'rangeBar', 'rangeArea', 'candlestick', 'boxPlot', 'scatter', 'bubble'];
  24511. gl.axisCharts = axisChartsArrTypes.includes(ct);
  24512. gl.xyCharts = xyChartsArrTypes.includes(ct);
  24513. gl.isBarHorizontal = ['bar', 'rangeBar', 'boxPlot'].includes(ct) && cnf.plotOptions.bar.horizontal;
  24514. gl.chartClass = ".apexcharts".concat(gl.chartID);
  24515. gl.dom.baseEl = this.el;
  24516. gl.dom.elWrap = document.createElement('div');
  24517. Graphics.setAttrs(gl.dom.elWrap, {
  24518. id: gl.chartClass.substring(1),
  24519. class: "apexcharts-canvas ".concat(gl.chartClass.substring(1))
  24520. });
  24521. this.el.appendChild(gl.dom.elWrap);
  24522. gl.dom.Paper = new window.SVG.Doc(gl.dom.elWrap);
  24523. gl.dom.Paper.attr({
  24524. class: 'apexcharts-svg',
  24525. 'xmlns:data': 'ApexChartsNS',
  24526. transform: "translate(".concat(cnf.chart.offsetX, ", ").concat(cnf.chart.offsetY, ")")
  24527. });
  24528. gl.dom.Paper.node.style.background = cnf.theme.mode === 'dark' && !cnf.chart.background ? '#424242' : cnf.theme.mode === 'light' && !cnf.chart.background ? '#fff' : cnf.chart.background;
  24529. this.setSVGDimensions();
  24530. gl.dom.elLegendForeign = document.createElementNS(gl.SVGNS, 'foreignObject');
  24531. Graphics.setAttrs(gl.dom.elLegendForeign, {
  24532. x: 0,
  24533. y: 0,
  24534. width: gl.svgWidth,
  24535. height: gl.svgHeight
  24536. });
  24537. gl.dom.elLegendWrap = document.createElement('div');
  24538. gl.dom.elLegendWrap.classList.add('apexcharts-legend');
  24539. gl.dom.elLegendWrap.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
  24540. gl.dom.elLegendForeign.appendChild(gl.dom.elLegendWrap);
  24541. gl.dom.Paper.node.appendChild(gl.dom.elLegendForeign);
  24542. gl.dom.elGraphical = gl.dom.Paper.group().attr({
  24543. class: 'apexcharts-inner apexcharts-graphical'
  24544. });
  24545. gl.dom.elDefs = gl.dom.Paper.defs();
  24546. gl.dom.Paper.add(gl.dom.elGraphical);
  24547. gl.dom.elGraphical.add(gl.dom.elDefs);
  24548. }
  24549. }, {
  24550. key: "plotChartType",
  24551. value: function plotChartType(ser, xyRatios) {
  24552. var w = this.w,
  24553. ctx = this.ctx;
  24554. var cnf = w.config,
  24555. gl = w.globals;
  24556. var seriesTypes = {
  24557. line: {
  24558. series: [],
  24559. i: []
  24560. },
  24561. area: {
  24562. series: [],
  24563. i: []
  24564. },
  24565. scatter: {
  24566. series: [],
  24567. i: []
  24568. },
  24569. bubble: {
  24570. series: [],
  24571. i: []
  24572. },
  24573. column: {
  24574. series: [],
  24575. i: []
  24576. },
  24577. candlestick: {
  24578. series: [],
  24579. i: []
  24580. },
  24581. boxPlot: {
  24582. series: [],
  24583. i: []
  24584. },
  24585. rangeBar: {
  24586. series: [],
  24587. i: []
  24588. },
  24589. rangeArea: {
  24590. series: [],
  24591. seriesRangeEnd: [],
  24592. i: []
  24593. }
  24594. };
  24595. var chartType = cnf.chart.type || 'line';
  24596. var nonComboType = null;
  24597. var comboCount = 0;
  24598. gl.series.forEach(function (serie, st) {
  24599. var seriesType = ser[st].type || chartType;
  24600. if (seriesTypes[seriesType]) {
  24601. if (seriesType === 'rangeArea') {
  24602. seriesTypes[seriesType].series.push(gl.seriesRangeStart[st]);
  24603. seriesTypes[seriesType].seriesRangeEnd.push(gl.seriesRangeEnd[st]);
  24604. } else {
  24605. seriesTypes[seriesType].series.push(serie);
  24606. }
  24607. seriesTypes[seriesType].i.push(st);
  24608. if (seriesType === 'column' || seriesType === 'bar') w.globals.columnSeries = seriesTypes.column;
  24609. } else if (['heatmap', 'treemap', 'pie', 'donut', 'polarArea', 'radialBar', 'radar'].includes(seriesType)) {
  24610. nonComboType = seriesType;
  24611. } else if (seriesType === 'bar') {
  24612. seriesTypes['column'].series.push(serie);
  24613. seriesTypes['column'].i.push(st);
  24614. } else {
  24615. console.warn("You have specified an unrecognized series type (".concat(seriesType, ")."));
  24616. }
  24617. if (chartType !== seriesType && seriesType !== 'scatter') comboCount++;
  24618. });
  24619. if (comboCount > 0) {
  24620. if (nonComboType) {
  24621. console.warn("Chart or series type ".concat(nonComboType, " cannot appear with other chart or series types."));
  24622. }
  24623. if (seriesTypes.column.series.length > 0 && cnf.plotOptions.bar.horizontal) {
  24624. comboCount -= seriesTypes.column.series.length;
  24625. seriesTypes.column = {
  24626. series: [],
  24627. i: []
  24628. };
  24629. w.globals.columnSeries = {
  24630. series: [],
  24631. i: []
  24632. };
  24633. console.warn('Horizontal bars are not supported in a mixed/combo chart. Please turn off `plotOptions.bar.horizontal`');
  24634. }
  24635. }
  24636. gl.comboCharts || (gl.comboCharts = comboCount > 0);
  24637. var line = new Line(ctx, xyRatios);
  24638. var boxCandlestick = new BoxCandleStick(ctx, xyRatios);
  24639. ctx.pie = new Pie(ctx);
  24640. var radialBar = new Radial(ctx);
  24641. ctx.rangeBar = new RangeBar(ctx, xyRatios);
  24642. var radar = new Radar(ctx);
  24643. var elGraph = [];
  24644. if (gl.comboCharts) {
  24645. var coreUtils = new CoreUtils(ctx);
  24646. if (seriesTypes.area.series.length > 0) {
  24647. var _elGraph;
  24648. (_elGraph = elGraph).push.apply(_elGraph, _toConsumableArray(coreUtils.drawSeriesByGroup(seriesTypes.area, gl.areaGroups, 'area', line)));
  24649. }
  24650. if (seriesTypes.column.series.length > 0) {
  24651. if (cnf.chart.stacked) {
  24652. var barStacked = new BarStacked(ctx, xyRatios);
  24653. elGraph.push(barStacked.draw(seriesTypes.column.series, seriesTypes.column.i));
  24654. } else {
  24655. ctx.bar = new Bar(ctx, xyRatios);
  24656. elGraph.push(ctx.bar.draw(seriesTypes.column.series, seriesTypes.column.i));
  24657. }
  24658. }
  24659. if (seriesTypes.rangeArea.series.length > 0) {
  24660. elGraph.push(line.draw(seriesTypes.rangeArea.series, 'rangeArea', seriesTypes.rangeArea.i, seriesTypes.rangeArea.seriesRangeEnd));
  24661. }
  24662. if (seriesTypes.line.series.length > 0) {
  24663. var _elGraph2;
  24664. (_elGraph2 = elGraph).push.apply(_elGraph2, _toConsumableArray(coreUtils.drawSeriesByGroup(seriesTypes.line, gl.lineGroups, 'line', line)));
  24665. }
  24666. if (seriesTypes.candlestick.series.length > 0) {
  24667. elGraph.push(boxCandlestick.draw(seriesTypes.candlestick.series, 'candlestick', seriesTypes.candlestick.i));
  24668. }
  24669. if (seriesTypes.boxPlot.series.length > 0) {
  24670. elGraph.push(boxCandlestick.draw(seriesTypes.boxPlot.series, 'boxPlot', seriesTypes.boxPlot.i));
  24671. }
  24672. if (seriesTypes.rangeBar.series.length > 0) {
  24673. elGraph.push(ctx.rangeBar.draw(seriesTypes.rangeBar.series, seriesTypes.rangeBar.i));
  24674. }
  24675. if (seriesTypes.scatter.series.length > 0) {
  24676. var scatterLine = new Line(ctx, xyRatios, true);
  24677. elGraph.push(scatterLine.draw(seriesTypes.scatter.series, 'scatter', seriesTypes.scatter.i));
  24678. }
  24679. if (seriesTypes.bubble.series.length > 0) {
  24680. var bubbleLine = new Line(ctx, xyRatios, true);
  24681. elGraph.push(bubbleLine.draw(seriesTypes.bubble.series, 'bubble', seriesTypes.bubble.i));
  24682. }
  24683. } else {
  24684. switch (cnf.chart.type) {
  24685. case 'line':
  24686. elGraph = line.draw(gl.series, 'line');
  24687. break;
  24688. case 'area':
  24689. elGraph = line.draw(gl.series, 'area');
  24690. break;
  24691. case 'bar':
  24692. if (cnf.chart.stacked) {
  24693. var _barStacked = new BarStacked(ctx, xyRatios);
  24694. elGraph = _barStacked.draw(gl.series);
  24695. } else {
  24696. ctx.bar = new Bar(ctx, xyRatios);
  24697. elGraph = ctx.bar.draw(gl.series);
  24698. }
  24699. break;
  24700. case 'candlestick':
  24701. var candleStick = new BoxCandleStick(ctx, xyRatios);
  24702. elGraph = candleStick.draw(gl.series, 'candlestick');
  24703. break;
  24704. case 'boxPlot':
  24705. var boxPlot = new BoxCandleStick(ctx, xyRatios);
  24706. elGraph = boxPlot.draw(gl.series, cnf.chart.type);
  24707. break;
  24708. case 'rangeBar':
  24709. elGraph = ctx.rangeBar.draw(gl.series);
  24710. break;
  24711. case 'rangeArea':
  24712. elGraph = line.draw(gl.seriesRangeStart, 'rangeArea', undefined, gl.seriesRangeEnd);
  24713. break;
  24714. case 'heatmap':
  24715. var heatmap = new HeatMap(ctx, xyRatios);
  24716. elGraph = heatmap.draw(gl.series);
  24717. break;
  24718. case 'treemap':
  24719. var treemap = new TreemapChart(ctx, xyRatios);
  24720. elGraph = treemap.draw(gl.series);
  24721. break;
  24722. case 'pie':
  24723. case 'donut':
  24724. case 'polarArea':
  24725. elGraph = ctx.pie.draw(gl.series);
  24726. break;
  24727. case 'radialBar':
  24728. elGraph = radialBar.draw(gl.series);
  24729. break;
  24730. case 'radar':
  24731. elGraph = radar.draw(gl.series);
  24732. break;
  24733. default:
  24734. elGraph = line.draw(gl.series);
  24735. }
  24736. }
  24737. return elGraph;
  24738. }
  24739. }, {
  24740. key: "setSVGDimensions",
  24741. value: function setSVGDimensions() {
  24742. var _this$w2 = this.w,
  24743. gl = _this$w2.globals,
  24744. cnf = _this$w2.config;
  24745. cnf.chart.width = cnf.chart.width || '100%';
  24746. cnf.chart.height = cnf.chart.height || 'auto';
  24747. gl.svgWidth = cnf.chart.width;
  24748. gl.svgHeight = cnf.chart.height;
  24749. var elDim = Utils$1.getDimensions(this.el);
  24750. var widthUnit = cnf.chart.width.toString().split(/[0-9]+/g).pop();
  24751. if (widthUnit === '%') {
  24752. if (Utils$1.isNumber(elDim[0])) {
  24753. if (elDim[0].width === 0) {
  24754. elDim = Utils$1.getDimensions(this.el.parentNode);
  24755. }
  24756. gl.svgWidth = elDim[0] * parseInt(cnf.chart.width, 10) / 100;
  24757. }
  24758. } else if (widthUnit === 'px' || widthUnit === '') {
  24759. gl.svgWidth = parseInt(cnf.chart.width, 10);
  24760. }
  24761. var heightUnit = String(cnf.chart.height).toString().split(/[0-9]+/g).pop();
  24762. if (gl.svgHeight !== 'auto' && gl.svgHeight !== '') {
  24763. if (heightUnit === '%') {
  24764. var elParentDim = Utils$1.getDimensions(this.el.parentNode);
  24765. gl.svgHeight = elParentDim[1] * parseInt(cnf.chart.height, 10) / 100;
  24766. } else {
  24767. gl.svgHeight = parseInt(cnf.chart.height, 10);
  24768. }
  24769. } else {
  24770. gl.svgHeight = gl.axisCharts ? gl.svgWidth / 1.61 : gl.svgWidth / 1.2;
  24771. }
  24772. gl.svgWidth = Math.max(gl.svgWidth, 0);
  24773. gl.svgHeight = Math.max(gl.svgHeight, 0);
  24774. Graphics.setAttrs(gl.dom.Paper.node, {
  24775. width: gl.svgWidth,
  24776. height: gl.svgHeight
  24777. });
  24778. if (heightUnit !== '%') {
  24779. var offsetY = cnf.chart.sparkline.enabled ? 0 : gl.axisCharts ? cnf.chart.parentHeightOffset : 0;
  24780. gl.dom.Paper.node.parentNode.parentNode.style.minHeight = "".concat(gl.svgHeight + offsetY, "px");
  24781. }
  24782. gl.dom.elWrap.style.width = "".concat(gl.svgWidth, "px");
  24783. gl.dom.elWrap.style.height = "".concat(gl.svgHeight, "px");
  24784. }
  24785. }, {
  24786. key: "shiftGraphPosition",
  24787. value: function shiftGraphPosition() {
  24788. var gl = this.w.globals;
  24789. var tY = gl.translateY,
  24790. tX = gl.translateX;
  24791. Graphics.setAttrs(gl.dom.elGraphical.node, {
  24792. transform: "translate(".concat(tX, ", ").concat(tY, ")")
  24793. });
  24794. }
  24795. }, {
  24796. key: "resizeNonAxisCharts",
  24797. value: function resizeNonAxisCharts() {
  24798. var w = this.w;
  24799. var gl = w.globals;
  24800. var legendHeight = 0;
  24801. var offY = w.config.chart.sparkline.enabled ? 1 : 15;
  24802. offY += w.config.grid.padding.bottom;
  24803. if (['top', 'bottom'].includes(w.config.legend.position) && w.config.legend.show && !w.config.legend.floating) {
  24804. legendHeight = new Legend(this.ctx).legendHelpers.getLegendDimensions().clwh + 7;
  24805. }
  24806. var el = w.globals.dom.baseEl.querySelector('.apexcharts-radialbar, .apexcharts-pie');
  24807. var chartInnerDimensions = w.globals.radialSize * 2.05;
  24808. if (el && !w.config.chart.sparkline.enabled && w.config.plotOptions.radialBar.startAngle !== 0) {
  24809. var elRadialRect = Utils$1.getBoundingClientRect(el);
  24810. chartInnerDimensions = elRadialRect.bottom;
  24811. var maxHeight = elRadialRect.bottom - elRadialRect.top;
  24812. chartInnerDimensions = Math.max(w.globals.radialSize * 2.05, maxHeight);
  24813. }
  24814. var newHeight = Math.ceil(chartInnerDimensions + gl.translateY + legendHeight + offY);
  24815. if (gl.dom.elLegendForeign) {
  24816. gl.dom.elLegendForeign.setAttribute('height', newHeight);
  24817. }
  24818. if (w.config.chart.height && String(w.config.chart.height).includes('%')) return;
  24819. gl.dom.elWrap.style.height = "".concat(newHeight, "px");
  24820. Graphics.setAttrs(gl.dom.Paper.node, {
  24821. height: newHeight
  24822. });
  24823. gl.dom.Paper.node.parentNode.parentNode.style.minHeight = "".concat(newHeight, "px");
  24824. }
  24825. }, {
  24826. key: "coreCalculations",
  24827. value: function coreCalculations() {
  24828. new Range(this.ctx).init();
  24829. }
  24830. }, {
  24831. key: "resetGlobals",
  24832. value: function resetGlobals() {
  24833. var _this = this;
  24834. var resetxyValues = function resetxyValues() {
  24835. return _this.w.config.series.map(function () {
  24836. return [];
  24837. });
  24838. };
  24839. var globalObj = new Globals();
  24840. var gl = this.w.globals;
  24841. globalObj.initGlobalVars(gl);
  24842. gl.seriesXvalues = resetxyValues();
  24843. gl.seriesYvalues = resetxyValues();
  24844. }
  24845. }, {
  24846. key: "isMultipleY",
  24847. value: function isMultipleY() {
  24848. if (Array.isArray(this.w.config.yaxis) && this.w.config.yaxis.length > 1) {
  24849. this.w.globals.isMultipleYAxis = true;
  24850. return true;
  24851. }
  24852. return false;
  24853. }
  24854. }, {
  24855. key: "xySettings",
  24856. value: function xySettings() {
  24857. var w = this.w;
  24858. var xyRatios = null;
  24859. if (w.globals.axisCharts) {
  24860. if (w.config.xaxis.crosshairs.position === 'back') {
  24861. new Crosshairs(this.ctx).drawXCrosshairs();
  24862. }
  24863. if (w.config.yaxis[0].crosshairs.position === 'back') {
  24864. new Crosshairs(this.ctx).drawYCrosshairs();
  24865. }
  24866. if (w.config.xaxis.type === 'datetime' && w.config.xaxis.labels.formatter === undefined) {
  24867. this.ctx.timeScale = new TimeScale(this.ctx);
  24868. var formattedTimeScale = [];
  24869. if (isFinite(w.globals.minX) && isFinite(w.globals.maxX) && !w.globals.isBarHorizontal) {
  24870. formattedTimeScale = this.ctx.timeScale.calculateTimeScaleTicks(w.globals.minX, w.globals.maxX);
  24871. } else if (w.globals.isBarHorizontal) {
  24872. formattedTimeScale = this.ctx.timeScale.calculateTimeScaleTicks(w.globals.minY, w.globals.maxY);
  24873. }
  24874. this.ctx.timeScale.recalcDimensionsBasedOnFormat(formattedTimeScale);
  24875. }
  24876. var coreUtils = new CoreUtils(this.ctx);
  24877. xyRatios = coreUtils.getCalculatedRatios();
  24878. }
  24879. return xyRatios;
  24880. }
  24881. }, {
  24882. key: "updateSourceChart",
  24883. value: function updateSourceChart(targetChart) {
  24884. this.ctx.w.globals.selection = undefined;
  24885. this.ctx.updateHelpers._updateOptions({
  24886. chart: {
  24887. selection: {
  24888. xaxis: {
  24889. min: targetChart.w.globals.minX,
  24890. max: targetChart.w.globals.maxX
  24891. }
  24892. }
  24893. }
  24894. }, false, false);
  24895. }
  24896. }, {
  24897. key: "setupBrushHandler",
  24898. value: function setupBrushHandler() {
  24899. var _this2 = this;
  24900. var w = this.w;
  24901. if (!w.config.chart.brush.enabled) return;
  24902. if (typeof w.config.chart.events.selection !== 'function') {
  24903. var targets = Array.isArray(w.config.chart.brush.targets) ? w.config.chart.brush.targets : [w.config.chart.brush.target];
  24904. targets.forEach(function (target) {
  24905. var targetChart = ApexCharts.getChartByID(target);
  24906. targetChart.w.globals.brushSource = _this2.ctx;
  24907. if (typeof targetChart.w.config.chart.events.zoomed !== 'function') {
  24908. targetChart.w.config.chart.events.zoomed = function () {
  24909. return _this2.updateSourceChart(targetChart);
  24910. };
  24911. }
  24912. if (typeof targetChart.w.config.chart.events.scrolled !== 'function') {
  24913. targetChart.w.config.chart.events.scrolled = function () {
  24914. return _this2.updateSourceChart(targetChart);
  24915. };
  24916. }
  24917. });
  24918. w.config.chart.events.selection = function (chart, e) {
  24919. targets.forEach(function (target) {
  24920. var targetChart = ApexCharts.getChartByID(target);
  24921. targetChart.ctx.updateHelpers._updateOptions({
  24922. xaxis: {
  24923. min: e.xaxis.min,
  24924. max: e.xaxis.max
  24925. }
  24926. }, false, false, false, false);
  24927. });
  24928. };
  24929. }
  24930. }
  24931. }]);
  24932. return Core;
  24933. }();
  24934. var UpdateHelpers = /*#__PURE__*/function () {
  24935. function UpdateHelpers(ctx) {
  24936. _classCallCheck(this, UpdateHelpers);
  24937. this.ctx = ctx;
  24938. this.w = ctx.w;
  24939. }
  24940. /**
  24941. * private method to update Options.
  24942. *
  24943. * @param {object} options - A new config object can be passed which will be merged with the existing config object
  24944. * @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
  24945. * @param {boolean} animate - should animate or not on updating Options
  24946. * @param {boolean} overwriteInitialConfig - should update the initial config or not
  24947. */
  24948. _createClass(UpdateHelpers, [{
  24949. key: "_updateOptions",
  24950. value: function _updateOptions(options) {
  24951. var _this = this;
  24952. var redraw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  24953. var animate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  24954. var updateSyncedCharts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  24955. var overwriteInitialConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  24956. return new Promise(function (resolve) {
  24957. var charts = [_this.ctx];
  24958. if (updateSyncedCharts) {
  24959. charts = _this.ctx.getSyncedCharts();
  24960. }
  24961. if (_this.ctx.w.globals.isExecCalled) {
  24962. // If the user called exec method, we don't want to get grouped charts as user specifically provided a chartID to update
  24963. charts = [_this.ctx];
  24964. _this.ctx.w.globals.isExecCalled = false;
  24965. }
  24966. charts.forEach(function (ch, chartIndex) {
  24967. var w = ch.w;
  24968. w.globals.shouldAnimate = animate;
  24969. if (!redraw) {
  24970. w.globals.resized = true;
  24971. w.globals.dataChanged = true;
  24972. if (animate) {
  24973. ch.series.getPreviousPaths();
  24974. }
  24975. }
  24976. if (options && _typeof(options) === 'object') {
  24977. ch.config = new Config(options);
  24978. options = CoreUtils.extendArrayProps(ch.config, options, w);
  24979. // fixes #914, #623
  24980. if (ch.w.globals.chartID !== _this.ctx.w.globals.chartID) {
  24981. // don't overwrite series of synchronized charts
  24982. delete options.series;
  24983. }
  24984. w.config = Utils$1.extend(w.config, options);
  24985. if (overwriteInitialConfig) {
  24986. // 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.
  24987. w.globals.lastXAxis = options.xaxis ? Utils$1.clone(options.xaxis) : [];
  24988. w.globals.lastYAxis = options.yaxis ? Utils$1.clone(options.yaxis) : [];
  24989. // After forgetting lastAxes, we need to restore the new config in initialConfig/initialSeries
  24990. w.globals.initialConfig = Utils$1.extend({}, w.config);
  24991. w.globals.initialSeries = Utils$1.clone(w.config.series);
  24992. if (options.series) {
  24993. // Replace the collapsed series data
  24994. for (var i = 0; i < w.globals.collapsedSeriesIndices.length; i++) {
  24995. var series = w.config.series[w.globals.collapsedSeriesIndices[i]];
  24996. w.globals.collapsedSeries[i].data = w.globals.axisCharts ? series.data.slice() : series;
  24997. }
  24998. for (var _i = 0; _i < w.globals.ancillaryCollapsedSeriesIndices.length; _i++) {
  24999. var _series = w.config.series[w.globals.ancillaryCollapsedSeriesIndices[_i]];
  25000. w.globals.ancillaryCollapsedSeries[_i].data = w.globals.axisCharts ? _series.data.slice() : _series;
  25001. }
  25002. // Ensure that auto-generated axes are scaled to the visible data
  25003. ch.series.emptyCollapsedSeries(w.config.series);
  25004. }
  25005. }
  25006. }
  25007. return ch.update(options).then(function () {
  25008. if (chartIndex === charts.length - 1) {
  25009. resolve(ch);
  25010. }
  25011. });
  25012. });
  25013. });
  25014. }
  25015. /**
  25016. * Private method to update Series.
  25017. *
  25018. * @param {array} series - New series which will override the existing
  25019. */
  25020. }, {
  25021. key: "_updateSeries",
  25022. value: function _updateSeries(newSeries, animate) {
  25023. var _this2 = this;
  25024. var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  25025. return new Promise(function (resolve) {
  25026. var w = _this2.w;
  25027. w.globals.shouldAnimate = animate;
  25028. w.globals.dataChanged = true;
  25029. if (animate) {
  25030. _this2.ctx.series.getPreviousPaths();
  25031. }
  25032. var existingSeries;
  25033. // axis charts
  25034. if (w.globals.axisCharts) {
  25035. existingSeries = newSeries.map(function (s, i) {
  25036. return _this2._extendSeries(s, i);
  25037. });
  25038. if (existingSeries.length === 0) {
  25039. existingSeries = [{
  25040. data: []
  25041. }];
  25042. }
  25043. w.config.series = existingSeries;
  25044. } else {
  25045. // non-axis chart (pie/radialbar)
  25046. w.config.series = newSeries.slice();
  25047. }
  25048. if (overwriteInitialSeries) {
  25049. w.globals.initialConfig.series = Utils$1.clone(w.config.series);
  25050. w.globals.initialSeries = Utils$1.clone(w.config.series);
  25051. }
  25052. return _this2.ctx.update().then(function () {
  25053. resolve(_this2.ctx);
  25054. });
  25055. });
  25056. }
  25057. }, {
  25058. key: "_extendSeries",
  25059. value: function _extendSeries(s, i) {
  25060. var w = this.w;
  25061. var ser = w.config.series[i];
  25062. return _objectSpread2(_objectSpread2({}, w.config.series[i]), {}, {
  25063. name: s.name ? s.name : ser === null || ser === void 0 ? void 0 : ser.name,
  25064. color: s.color ? s.color : ser === null || ser === void 0 ? void 0 : ser.color,
  25065. type: s.type ? s.type : ser === null || ser === void 0 ? void 0 : ser.type,
  25066. group: s.group ? s.group : ser === null || ser === void 0 ? void 0 : ser.group,
  25067. hidden: typeof s.hidden !== 'undefined' ? s.hidden : ser === null || ser === void 0 ? void 0 : ser.hidden,
  25068. data: s.data ? s.data : ser === null || ser === void 0 ? void 0 : ser.data,
  25069. zIndex: typeof s.zIndex !== 'undefined' ? s.zIndex : i
  25070. });
  25071. }
  25072. }, {
  25073. key: "toggleDataPointSelection",
  25074. value: function toggleDataPointSelection(seriesIndex, dataPointIndex) {
  25075. var w = this.w;
  25076. var elPath = null;
  25077. var parent = ".apexcharts-series[data\\:realIndex='".concat(seriesIndex, "']");
  25078. if (w.globals.axisCharts) {
  25079. elPath = w.globals.dom.Paper.select("".concat(parent, " path[j='").concat(dataPointIndex, "'], ").concat(parent, " circle[j='").concat(dataPointIndex, "'], ").concat(parent, " rect[j='").concat(dataPointIndex, "']")).members[0];
  25080. } else {
  25081. // dataPointIndex will be undefined here, hence using seriesIndex
  25082. if (typeof dataPointIndex === 'undefined') {
  25083. elPath = w.globals.dom.Paper.select("".concat(parent, " path[j='").concat(seriesIndex, "']")).members[0];
  25084. if (w.config.chart.type === 'pie' || w.config.chart.type === 'polarArea' || w.config.chart.type === 'donut') {
  25085. this.ctx.pie.pieClicked(seriesIndex);
  25086. }
  25087. }
  25088. }
  25089. if (elPath) {
  25090. var graphics = new Graphics(this.ctx);
  25091. graphics.pathMouseDown(elPath, null);
  25092. } else {
  25093. console.warn('toggleDataPointSelection: Element not found');
  25094. return null;
  25095. }
  25096. return elPath.node ? elPath.node : null;
  25097. }
  25098. }, {
  25099. key: "forceXAxisUpdate",
  25100. value: function forceXAxisUpdate(options) {
  25101. var w = this.w;
  25102. var minmax = ['min', 'max'];
  25103. minmax.forEach(function (a) {
  25104. if (typeof options.xaxis[a] !== 'undefined') {
  25105. w.config.xaxis[a] = options.xaxis[a];
  25106. w.globals.lastXAxis[a] = options.xaxis[a];
  25107. }
  25108. });
  25109. if (options.xaxis.categories && options.xaxis.categories.length) {
  25110. w.config.xaxis.categories = options.xaxis.categories;
  25111. }
  25112. if (w.config.xaxis.convertedCatToNumeric) {
  25113. var defaults = new Defaults(options);
  25114. options = defaults.convertCatToNumericXaxis(options, this.ctx);
  25115. }
  25116. return options;
  25117. }
  25118. }, {
  25119. key: "forceYAxisUpdate",
  25120. value: function forceYAxisUpdate(options) {
  25121. if (options.chart && options.chart.stacked && options.chart.stackType === '100%') {
  25122. if (Array.isArray(options.yaxis)) {
  25123. options.yaxis.forEach(function (yaxe, index) {
  25124. options.yaxis[index].min = 0;
  25125. options.yaxis[index].max = 100;
  25126. });
  25127. } else {
  25128. options.yaxis.min = 0;
  25129. options.yaxis.max = 100;
  25130. }
  25131. }
  25132. return options;
  25133. }
  25134. /**
  25135. * This function reverts the yaxis and xaxis min/max values to what it was when the chart was defined.
  25136. * 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
  25137. * Also, this should never be called internally on zoom/pan - the reset should only happen when user calls the updateSeries() function externally
  25138. * The function also accepts an object {xaxis, yaxis} which when present is set as the new xaxis/yaxis
  25139. */
  25140. }, {
  25141. key: "revertDefaultAxisMinMax",
  25142. value: function revertDefaultAxisMinMax(opts) {
  25143. var _this3 = this;
  25144. var w = this.w;
  25145. var xaxis = w.globals.lastXAxis;
  25146. var yaxis = w.globals.lastYAxis;
  25147. if (opts && opts.xaxis) {
  25148. xaxis = opts.xaxis;
  25149. }
  25150. if (opts && opts.yaxis) {
  25151. yaxis = opts.yaxis;
  25152. }
  25153. w.config.xaxis.min = xaxis.min;
  25154. w.config.xaxis.max = xaxis.max;
  25155. var getLastYAxis = function getLastYAxis(index) {
  25156. if (typeof yaxis[index] !== 'undefined') {
  25157. w.config.yaxis[index].min = yaxis[index].min;
  25158. w.config.yaxis[index].max = yaxis[index].max;
  25159. }
  25160. };
  25161. w.config.yaxis.map(function (yaxe, index) {
  25162. if (w.globals.zoomed) {
  25163. // user has zoomed, check the last yaxis
  25164. getLastYAxis(index);
  25165. } else {
  25166. // user hasn't zoomed, check the last yaxis first
  25167. if (typeof yaxis[index] !== 'undefined') {
  25168. getLastYAxis(index);
  25169. } else {
  25170. // if last y-axis don't exist, check the original yaxis
  25171. if (typeof _this3.ctx.opts.yaxis[index] !== 'undefined') {
  25172. yaxe.min = _this3.ctx.opts.yaxis[index].min;
  25173. yaxe.max = _this3.ctx.opts.yaxis[index].max;
  25174. }
  25175. }
  25176. }
  25177. });
  25178. }
  25179. }]);
  25180. return UpdateHelpers;
  25181. }();
  25182. (function (root, factory) {
  25183. /* istanbul ignore next */
  25184. if (typeof define === 'function' && define.amd) {
  25185. define(function () {
  25186. return factory(root, root.document);
  25187. });
  25188. /* below check fixes #412 */
  25189. } else if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined') {
  25190. module.exports = root.document ? factory(root, root.document) : function (w) {
  25191. return factory(w, w.document);
  25192. };
  25193. } else {
  25194. root.SVG = factory(root, root.document);
  25195. }
  25196. })(typeof window !== 'undefined' ? window : undefined, function (window, document) {
  25197. // Find global reference - uses 'this' by default when available,
  25198. // falls back to 'window' otherwise (for bundlers like Webpack)
  25199. var globalRef = typeof this !== 'undefined' ? this : window;
  25200. // The main wrapping element
  25201. var SVG = globalRef.SVG = function (element) {
  25202. if (SVG.supported) {
  25203. element = new SVG.Doc(element);
  25204. if (!SVG.parser.draw) {
  25205. SVG.prepare();
  25206. }
  25207. return element;
  25208. }
  25209. };
  25210. // Default namespaces
  25211. SVG.ns = 'http://www.w3.org/2000/svg';
  25212. SVG.xmlns = 'http://www.w3.org/2000/xmlns/';
  25213. SVG.xlink = 'http://www.w3.org/1999/xlink';
  25214. SVG.svgjs = 'http://svgjs.dev';
  25215. // Svg support test
  25216. SVG.supported = function () {
  25217. return true;
  25218. // !!document.createElementNS &&
  25219. // !! document.createElementNS(SVG.ns,'svg').createSVGRect
  25220. }();
  25221. // Don't bother to continue if SVG is not supported
  25222. if (!SVG.supported) return false;
  25223. // Element id sequence
  25224. SVG.did = 1000;
  25225. // Get next named element id
  25226. SVG.eid = function (name) {
  25227. return 'Svgjs' + capitalize(name) + SVG.did++;
  25228. };
  25229. // Method for element creation
  25230. SVG.create = function (name) {
  25231. // create element
  25232. var element = document.createElementNS(this.ns, name);
  25233. // apply unique id
  25234. element.setAttribute('id', this.eid(name));
  25235. return element;
  25236. };
  25237. // Method for extending objects
  25238. SVG.extend = function () {
  25239. var modules, methods;
  25240. // Get list of modules
  25241. modules = [].slice.call(arguments);
  25242. // Get object with extensions
  25243. methods = modules.pop();
  25244. for (var i = modules.length - 1; i >= 0; i--) {
  25245. if (modules[i]) {
  25246. for (var key in methods) {
  25247. modules[i].prototype[key] = methods[key];
  25248. }
  25249. }
  25250. }
  25251. // Make sure SVG.Set inherits any newly added methods
  25252. if (SVG.Set && SVG.Set.inherit) {
  25253. SVG.Set.inherit();
  25254. }
  25255. };
  25256. // Invent new element
  25257. SVG.invent = function (config) {
  25258. // Create element initializer
  25259. var initializer = typeof config.create === 'function' ? config.create : function () {
  25260. this.constructor.call(this, SVG.create(config.create));
  25261. };
  25262. // Inherit prototype
  25263. if (config.inherit) {
  25264. initializer.prototype = new config.inherit();
  25265. }
  25266. // Extend with methods
  25267. if (config.extend) {
  25268. SVG.extend(initializer, config.extend);
  25269. }
  25270. // Attach construct method to parent
  25271. if (config.construct) {
  25272. SVG.extend(config.parent || SVG.Container, config.construct);
  25273. }
  25274. return initializer;
  25275. };
  25276. // Adopt existing svg elements
  25277. SVG.adopt = function (node) {
  25278. // check for presence of node
  25279. if (!node) return null;
  25280. // make sure a node isn't already adopted
  25281. if (node.instance) return node.instance;
  25282. // initialize variables
  25283. var element;
  25284. // adopt with element-specific settings
  25285. if (node.nodeName == 'svg') {
  25286. element = node.parentNode instanceof window.SVGElement ? new SVG.Nested() : new SVG.Doc();
  25287. } else if (node.nodeName == 'linearGradient') {
  25288. element = new SVG.Gradient('linear');
  25289. } else if (node.nodeName == 'radialGradient') {
  25290. element = new SVG.Gradient('radial');
  25291. } else if (SVG[capitalize(node.nodeName)]) {
  25292. element = new SVG[capitalize(node.nodeName)]();
  25293. } else {
  25294. element = new SVG.Element(node);
  25295. }
  25296. // ensure references
  25297. element.type = node.nodeName;
  25298. element.node = node;
  25299. node.instance = element;
  25300. // SVG.Class specific preparations
  25301. if (element instanceof SVG.Doc) {
  25302. element.namespace().defs();
  25303. }
  25304. // pull svgjs data from the dom (getAttributeNS doesn't work in html5)
  25305. element.setData(JSON.parse(node.getAttribute('svgjs:data')) || {});
  25306. return element;
  25307. };
  25308. // Initialize parsing element
  25309. SVG.prepare = function () {
  25310. // Select document body and create invisible svg element
  25311. var body = document.getElementsByTagName('body')[0],
  25312. draw = (body ? new SVG.Doc(body) : SVG.adopt(document.documentElement).nested()).size(2, 0);
  25313. // Create parser object
  25314. SVG.parser = {
  25315. body: body || document.documentElement,
  25316. draw: draw.style('opacity:0;position:absolute;left:-100%;top:-100%;overflow:hidden').node,
  25317. poly: draw.polyline().node,
  25318. path: draw.path().node,
  25319. native: SVG.create('svg')
  25320. };
  25321. };
  25322. SVG.parser = {
  25323. native: SVG.create('svg')
  25324. };
  25325. document.addEventListener('DOMContentLoaded', function () {
  25326. if (!SVG.parser.draw) {
  25327. SVG.prepare();
  25328. }
  25329. }, false);
  25330. // Storage for regular expressions
  25331. SVG.regex = {
  25332. // Parse unit value
  25333. numberAndUnit: /^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i,
  25334. // Parse hex value
  25335. hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,
  25336. // Parse rgb value
  25337. rgb: /rgb\((\d+),(\d+),(\d+)\)/,
  25338. // Parse reference id
  25339. reference: /#([a-z0-9\-_]+)/i,
  25340. // splits a transformation chain
  25341. transforms: /\)\s*,?\s*/,
  25342. // Whitespace
  25343. whitespace: /\s/g,
  25344. // Test hex value
  25345. isHex: /^#[a-f0-9]{3,6}$/i,
  25346. // Test rgb value
  25347. isRgb: /^rgb\(/,
  25348. // Test css declaration
  25349. isCss: /[^:]+:[^;]+;?/,
  25350. // Test for blank string
  25351. isBlank: /^(\s+)?$/,
  25352. // Test for numeric string
  25353. isNumber: /^[+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
  25354. // Test for percent value
  25355. isPercent: /^-?[\d\.]+%$/,
  25356. // Test for image url
  25357. isImage: /\.(jpg|jpeg|png|gif|svg)(\?[^=]+.*)?/i,
  25358. // split at whitespace and comma
  25359. delimiter: /[\s,]+/,
  25360. // The following regex are used to parse the d attribute of a path
  25361. // Matches all hyphens which are not after an exponent
  25362. hyphen: /([^e])\-/gi,
  25363. // Replaces and tests for all path letters
  25364. pathLetters: /[MLHVCSQTAZ]/gi,
  25365. // yes we need this one, too
  25366. isPathLetter: /[MLHVCSQTAZ]/i,
  25367. // matches 0.154.23.45
  25368. numbersWithDots: /((\d?\.\d+(?:e[+-]?\d+)?)((?:\.\d+(?:e[+-]?\d+)?)+))+/gi,
  25369. // matches .
  25370. dots: /\./g
  25371. };
  25372. SVG.utils = {
  25373. // Map function
  25374. map: function map(array, block) {
  25375. var il = array.length,
  25376. result = [];
  25377. for (var i = 0; i < il; i++) {
  25378. result.push(block(array[i]));
  25379. }
  25380. return result;
  25381. },
  25382. // Filter function
  25383. filter: function filter(array, block) {
  25384. var il = array.length,
  25385. result = [];
  25386. for (var i = 0; i < il; i++) {
  25387. if (block(array[i])) {
  25388. result.push(array[i]);
  25389. }
  25390. }
  25391. return result;
  25392. },
  25393. filterSVGElements: function filterSVGElements(nodes) {
  25394. return this.filter(nodes, function (el) {
  25395. return el instanceof window.SVGElement;
  25396. });
  25397. }
  25398. };
  25399. SVG.defaults = {
  25400. // Default attribute values
  25401. attrs: {
  25402. // fill and stroke
  25403. 'fill-opacity': 1,
  25404. 'stroke-opacity': 1,
  25405. 'stroke-width': 0,
  25406. 'stroke-linejoin': 'miter',
  25407. 'stroke-linecap': 'butt',
  25408. fill: '#000000',
  25409. stroke: '#000000',
  25410. opacity: 1,
  25411. // position
  25412. x: 0,
  25413. y: 0,
  25414. cx: 0,
  25415. cy: 0,
  25416. // size
  25417. width: 0,
  25418. height: 0,
  25419. // radius
  25420. r: 0,
  25421. rx: 0,
  25422. ry: 0,
  25423. // gradient
  25424. offset: 0,
  25425. 'stop-opacity': 1,
  25426. 'stop-color': '#000000',
  25427. // text
  25428. 'font-size': 16,
  25429. 'font-family': 'Helvetica, Arial, sans-serif',
  25430. 'text-anchor': 'start'
  25431. }
  25432. };
  25433. // Module for color convertions
  25434. SVG.Color = function (color) {
  25435. var match;
  25436. // initialize defaults
  25437. this.r = 0;
  25438. this.g = 0;
  25439. this.b = 0;
  25440. if (!color) return;
  25441. // parse color
  25442. if (typeof color === 'string') {
  25443. if (SVG.regex.isRgb.test(color)) {
  25444. // get rgb values
  25445. match = SVG.regex.rgb.exec(color.replace(SVG.regex.whitespace, ''));
  25446. // parse numeric values
  25447. this.r = parseInt(match[1]);
  25448. this.g = parseInt(match[2]);
  25449. this.b = parseInt(match[3]);
  25450. } else if (SVG.regex.isHex.test(color)) {
  25451. // get hex values
  25452. match = SVG.regex.hex.exec(fullHex(color));
  25453. // parse numeric values
  25454. this.r = parseInt(match[1], 16);
  25455. this.g = parseInt(match[2], 16);
  25456. this.b = parseInt(match[3], 16);
  25457. }
  25458. } else if (_typeof(color) === 'object') {
  25459. this.r = color.r;
  25460. this.g = color.g;
  25461. this.b = color.b;
  25462. }
  25463. };
  25464. SVG.extend(SVG.Color, {
  25465. // Default to hex conversion
  25466. toString: function toString() {
  25467. return this.toHex();
  25468. },
  25469. // Build hex value
  25470. toHex: function toHex() {
  25471. return '#' + compToHex(this.r) + compToHex(this.g) + compToHex(this.b);
  25472. },
  25473. // Build rgb value
  25474. toRgb: function toRgb() {
  25475. return 'rgb(' + [this.r, this.g, this.b].join() + ')';
  25476. },
  25477. // Calculate true brightness
  25478. brightness: function brightness() {
  25479. return this.r / 255 * 0.30 + this.g / 255 * 0.59 + this.b / 255 * 0.11;
  25480. },
  25481. // Make color morphable
  25482. morph: function morph(color) {
  25483. this.destination = new SVG.Color(color);
  25484. return this;
  25485. },
  25486. // Get morphed color at given position
  25487. at: function at(pos) {
  25488. // make sure a destination is defined
  25489. if (!this.destination) return this;
  25490. // normalise pos
  25491. pos = pos < 0 ? 0 : pos > 1 ? 1 : pos;
  25492. // generate morphed color
  25493. return new SVG.Color({
  25494. r: ~~(this.r + (this.destination.r - this.r) * pos),
  25495. g: ~~(this.g + (this.destination.g - this.g) * pos),
  25496. b: ~~(this.b + (this.destination.b - this.b) * pos)
  25497. });
  25498. }
  25499. });
  25500. // Testers
  25501. // Test if given value is a color string
  25502. SVG.Color.test = function (color) {
  25503. color += '';
  25504. return SVG.regex.isHex.test(color) || SVG.regex.isRgb.test(color);
  25505. };
  25506. // Test if given value is a rgb object
  25507. SVG.Color.isRgb = function (color) {
  25508. return color && typeof color.r === 'number' && typeof color.g === 'number' && typeof color.b === 'number';
  25509. };
  25510. // Test if given value is a color
  25511. SVG.Color.isColor = function (color) {
  25512. return SVG.Color.isRgb(color) || SVG.Color.test(color);
  25513. };
  25514. // Module for array conversion
  25515. SVG.Array = function (array, fallback) {
  25516. array = (array || []).valueOf();
  25517. // if array is empty and fallback is provided, use fallback
  25518. if (array.length == 0 && fallback) {
  25519. array = fallback.valueOf();
  25520. }
  25521. // parse array
  25522. this.value = this.parse(array);
  25523. };
  25524. SVG.extend(SVG.Array, {
  25525. // Convert array to string
  25526. toString: function toString() {
  25527. return this.value.join(' ');
  25528. },
  25529. // Real value
  25530. valueOf: function valueOf() {
  25531. return this.value;
  25532. },
  25533. // Parse whitespace separated string
  25534. parse: function parse(array) {
  25535. array = array.valueOf();
  25536. // if already is an array, no need to parse it
  25537. if (Array.isArray(array)) return array;
  25538. return this.split(array);
  25539. }
  25540. });
  25541. // Poly points array
  25542. SVG.PointArray = function (array, fallback) {
  25543. SVG.Array.call(this, array, fallback || [[0, 0]]);
  25544. };
  25545. // Inherit from SVG.Array
  25546. SVG.PointArray.prototype = new SVG.Array();
  25547. SVG.PointArray.prototype.constructor = SVG.PointArray;
  25548. var pathHandlers = {
  25549. M: function M(c, p, p0) {
  25550. p.x = p0.x = c[0];
  25551. p.y = p0.y = c[1];
  25552. return ['M', p.x, p.y];
  25553. },
  25554. L: function L(c, p) {
  25555. p.x = c[0];
  25556. p.y = c[1];
  25557. return ['L', c[0], c[1]];
  25558. },
  25559. H: function H(c, p) {
  25560. p.x = c[0];
  25561. return ['H', c[0]];
  25562. },
  25563. V: function V(c, p) {
  25564. p.y = c[0];
  25565. return ['V', c[0]];
  25566. },
  25567. C: function C(c, p) {
  25568. p.x = c[4];
  25569. p.y = c[5];
  25570. return ['C', c[0], c[1], c[2], c[3], c[4], c[5]];
  25571. },
  25572. Q: function Q(c, p) {
  25573. p.x = c[2];
  25574. p.y = c[3];
  25575. return ['Q', c[0], c[1], c[2], c[3]];
  25576. },
  25577. S: function S(c, p) {
  25578. p.x = c[2];
  25579. p.y = c[3];
  25580. return ['S', c[0], c[1], c[2], c[3]];
  25581. },
  25582. Z: function Z(c, p, p0) {
  25583. p.x = p0.x;
  25584. p.y = p0.y;
  25585. return ['Z'];
  25586. }
  25587. };
  25588. var mlhvqtcsa = 'mlhvqtcsaz'.split('');
  25589. for (var i = 0, il = mlhvqtcsa.length; i < il; ++i) {
  25590. pathHandlers[mlhvqtcsa[i]] = function (i) {
  25591. return function (c, p, p0) {
  25592. if (i == 'H') c[0] = c[0] + p.x;else if (i == 'V') c[0] = c[0] + p.y;else if (i == 'A') {
  25593. c[5] = c[5] + p.x, c[6] = c[6] + p.y;
  25594. } else {
  25595. for (var j = 0, jl = c.length; j < jl; ++j) {
  25596. c[j] = c[j] + (j % 2 ? p.y : p.x);
  25597. }
  25598. }
  25599. if (pathHandlers && typeof pathHandlers[i] === 'function') {
  25600. // this check fixes jest unit tests
  25601. return pathHandlers[i](c, p, p0);
  25602. }
  25603. };
  25604. }(mlhvqtcsa[i].toUpperCase());
  25605. }
  25606. // Path points array
  25607. SVG.PathArray = function (array, fallback) {
  25608. SVG.Array.call(this, array, fallback || [['M', 0, 0]]);
  25609. };
  25610. // Inherit from SVG.Array
  25611. SVG.PathArray.prototype = new SVG.Array();
  25612. SVG.PathArray.prototype.constructor = SVG.PathArray;
  25613. SVG.extend(SVG.PathArray, {
  25614. // Convert array to string
  25615. toString: function toString() {
  25616. return arrayToString(this.value);
  25617. },
  25618. // Move path string
  25619. move: function move(x, y) {
  25620. // get bounding box of current situation
  25621. var box = this.bbox();
  25622. // get relative offset
  25623. x -= box.x;
  25624. y -= box.y;
  25625. return this;
  25626. },
  25627. // Get morphed path array at given position
  25628. at: function at(pos) {
  25629. // make sure a destination is defined
  25630. if (!this.destination) return this;
  25631. var sourceArray = this.value,
  25632. destinationArray = this.destination.value,
  25633. array = [],
  25634. pathArray = new SVG.PathArray(),
  25635. il,
  25636. jl;
  25637. // Animate has specified in the SVG spec
  25638. // See: https://www.w3.org/TR/SVG11/paths.html#PathElement
  25639. for (var i = 0, il = sourceArray.length; i < il; i++) {
  25640. array[i] = [sourceArray[i][0]];
  25641. for (var j = 1, jl = sourceArray[i].length; j < jl; j++) {
  25642. array[i][j] = sourceArray[i][j] + (destinationArray[i][j] - sourceArray[i][j]) * pos;
  25643. }
  25644. // For the two flags of the elliptical arc command, the SVG spec say:
  25645. // Flags and booleans are interpolated as fractions between zero and one, with any non-zero value considered to be a value of one/true
  25646. // Elliptical arc command as an array followed by corresponding indexes:
  25647. // ['A', rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x, y]
  25648. // 0 1 2 3 4 5 6 7
  25649. if (array[i][0] === 'A') {
  25650. array[i][4] = +(array[i][4] != 0);
  25651. array[i][5] = +(array[i][5] != 0);
  25652. }
  25653. }
  25654. // Directly modify the value of a path array, this is done this way for performance
  25655. pathArray.value = array;
  25656. return pathArray;
  25657. },
  25658. // Absolutize and parse path to array
  25659. parse: function parse(array) {
  25660. // if it's already a patharray, no need to parse it
  25661. if (array instanceof SVG.PathArray) return array.valueOf();
  25662. // prepare for parsing
  25663. var s,
  25664. arr,
  25665. paramCnt = {
  25666. 'M': 2,
  25667. 'L': 2,
  25668. 'H': 1,
  25669. 'V': 1,
  25670. 'C': 6,
  25671. 'S': 4,
  25672. 'Q': 4,
  25673. 'T': 2,
  25674. 'A': 7,
  25675. 'Z': 0
  25676. };
  25677. if (typeof array === 'string') {
  25678. array = array.replace(SVG.regex.numbersWithDots, pathRegReplace) // convert 45.123.123 to 45.123 .123
  25679. .replace(SVG.regex.pathLetters, ' $& ') // put some room between letters and numbers
  25680. .replace(SVG.regex.hyphen, '$1 -') // add space before hyphen
  25681. .trim() // trim
  25682. .split(SVG.regex.delimiter); // split into array
  25683. } else {
  25684. array = array.reduce(function (prev, curr) {
  25685. return [].concat.call(prev, curr);
  25686. }, []);
  25687. }
  25688. // array now is an array containing all parts of a path e.g. ['M', '0', '0', 'L', '30', '30' ...]
  25689. var arr = [],
  25690. p = new SVG.Point(),
  25691. p0 = new SVG.Point(),
  25692. index = 0,
  25693. len = array.length;
  25694. do {
  25695. // Test if we have a path letter
  25696. if (SVG.regex.isPathLetter.test(array[index])) {
  25697. s = array[index];
  25698. ++index;
  25699. // If last letter was a move command and we got no new, it defaults to [L]ine
  25700. } else if (s == 'M') {
  25701. s = 'L';
  25702. } else if (s == 'm') {
  25703. s = 'l';
  25704. }
  25705. arr.push(pathHandlers[s].call(null, array.slice(index, index = index + paramCnt[s.toUpperCase()]).map(parseFloat), p, p0));
  25706. } while (len > index);
  25707. return arr;
  25708. },
  25709. // Get bounding box of path
  25710. bbox: function bbox() {
  25711. if (!SVG.parser.draw) {
  25712. SVG.prepare();
  25713. }
  25714. SVG.parser.path.setAttribute('d', this.toString());
  25715. return SVG.parser.path.getBBox();
  25716. }
  25717. });
  25718. // Module for unit convertions
  25719. SVG.Number = SVG.invent({
  25720. // Initialize
  25721. create: function create(value, unit) {
  25722. // initialize defaults
  25723. this.value = 0;
  25724. this.unit = unit || '';
  25725. // parse value
  25726. if (typeof value === 'number') {
  25727. // ensure a valid numeric value
  25728. this.value = isNaN(value) ? 0 : !isFinite(value) ? value < 0 ? -3.4e+38 : +3.4e+38 : value;
  25729. } else if (typeof value === 'string') {
  25730. unit = value.match(SVG.regex.numberAndUnit);
  25731. if (unit) {
  25732. // make value numeric
  25733. this.value = parseFloat(unit[1]);
  25734. // normalize
  25735. if (unit[5] == '%') {
  25736. this.value /= 100;
  25737. } else if (unit[5] == 's') {
  25738. this.value *= 1000;
  25739. }
  25740. // store unit
  25741. this.unit = unit[5];
  25742. }
  25743. } else {
  25744. if (value instanceof SVG.Number) {
  25745. this.value = value.valueOf();
  25746. this.unit = value.unit;
  25747. }
  25748. }
  25749. },
  25750. // Add methods
  25751. extend: {
  25752. // Stringalize
  25753. toString: function toString() {
  25754. return (this.unit == '%' ? ~~(this.value * 1e8) / 1e6 : this.unit == 's' ? this.value / 1e3 : this.value) + this.unit;
  25755. },
  25756. toJSON: function toJSON() {
  25757. return this.toString();
  25758. },
  25759. // Convert to primitive
  25760. valueOf: function valueOf() {
  25761. return this.value;
  25762. },
  25763. // Add number
  25764. plus: function plus(number) {
  25765. number = new SVG.Number(number);
  25766. return new SVG.Number(this + number, this.unit || number.unit);
  25767. },
  25768. // Subtract number
  25769. minus: function minus(number) {
  25770. number = new SVG.Number(number);
  25771. return new SVG.Number(this - number, this.unit || number.unit);
  25772. },
  25773. // Multiply number
  25774. times: function times(number) {
  25775. number = new SVG.Number(number);
  25776. return new SVG.Number(this * number, this.unit || number.unit);
  25777. },
  25778. // Divide number
  25779. divide: function divide(number) {
  25780. number = new SVG.Number(number);
  25781. return new SVG.Number(this / number, this.unit || number.unit);
  25782. },
  25783. // Convert to different unit
  25784. to: function to(unit) {
  25785. var number = new SVG.Number(this);
  25786. if (typeof unit === 'string') {
  25787. number.unit = unit;
  25788. }
  25789. return number;
  25790. },
  25791. // Make number morphable
  25792. morph: function morph(number) {
  25793. this.destination = new SVG.Number(number);
  25794. if (number.relative) {
  25795. this.destination.value += this.value;
  25796. }
  25797. return this;
  25798. },
  25799. // Get morphed number at given position
  25800. at: function at(pos) {
  25801. // Make sure a destination is defined
  25802. if (!this.destination) return this;
  25803. // Generate new morphed number
  25804. return new SVG.Number(this.destination).minus(this).times(pos).plus(this);
  25805. }
  25806. }
  25807. });
  25808. SVG.Element = SVG.invent({
  25809. // Initialize node
  25810. create: function create(node) {
  25811. // make stroke value accessible dynamically
  25812. this._stroke = SVG.defaults.attrs.stroke;
  25813. this._event = null;
  25814. // initialize data object
  25815. this.dom = {};
  25816. // create circular reference
  25817. if (this.node = node) {
  25818. this.type = node.nodeName;
  25819. this.node.instance = this;
  25820. // store current attribute value
  25821. this._stroke = node.getAttribute('stroke') || this._stroke;
  25822. }
  25823. },
  25824. // Add class methods
  25825. extend: {
  25826. // Move over x-axis
  25827. x: function x(_x) {
  25828. return this.attr('x', _x);
  25829. },
  25830. // Move over y-axis
  25831. y: function y(_y) {
  25832. return this.attr('y', _y);
  25833. },
  25834. // Move by center over x-axis
  25835. cx: function cx(x) {
  25836. return x == null ? this.x() + this.width() / 2 : this.x(x - this.width() / 2);
  25837. },
  25838. // Move by center over y-axis
  25839. cy: function cy(y) {
  25840. return y == null ? this.y() + this.height() / 2 : this.y(y - this.height() / 2);
  25841. },
  25842. // Move element to given x and y values
  25843. move: function move(x, y) {
  25844. return this.x(x).y(y);
  25845. },
  25846. // Move element by its center
  25847. center: function center(x, y) {
  25848. return this.cx(x).cy(y);
  25849. },
  25850. // Set width of element
  25851. width: function width(_width) {
  25852. return this.attr('width', _width);
  25853. },
  25854. // Set height of element
  25855. height: function height(_height) {
  25856. return this.attr('height', _height);
  25857. },
  25858. // Set element size to given width and height
  25859. size: function size(width, height) {
  25860. var p = proportionalSize(this, width, height);
  25861. return this.width(new SVG.Number(p.width)).height(new SVG.Number(p.height));
  25862. },
  25863. // Clone element
  25864. clone: function clone(parent) {
  25865. // write dom data to the dom so the clone can pickup the data
  25866. this.writeDataToDom();
  25867. // clone element and assign new id
  25868. var clone = assignNewId(this.node.cloneNode(true));
  25869. // insert the clone in the given parent or after myself
  25870. if (parent) parent.add(clone);else this.after(clone);
  25871. return clone;
  25872. },
  25873. // Remove element
  25874. remove: function remove() {
  25875. if (this.parent()) {
  25876. this.parent().removeElement(this);
  25877. }
  25878. return this;
  25879. },
  25880. // Replace element
  25881. replace: function replace(element) {
  25882. this.after(element).remove();
  25883. return element;
  25884. },
  25885. // Add element to given container and return self
  25886. addTo: function addTo(parent) {
  25887. return parent.put(this);
  25888. },
  25889. // Add element to given container and return container
  25890. putIn: function putIn(parent) {
  25891. return parent.add(this);
  25892. },
  25893. // Get / set id
  25894. id: function id(_id) {
  25895. return this.attr('id', _id);
  25896. },
  25897. // Show element
  25898. show: function show() {
  25899. return this.style('display', '');
  25900. },
  25901. // Hide element
  25902. hide: function hide() {
  25903. return this.style('display', 'none');
  25904. },
  25905. // Is element visible?
  25906. visible: function visible() {
  25907. return this.style('display') != 'none';
  25908. },
  25909. // Return id on string conversion
  25910. toString: function toString() {
  25911. return this.attr('id');
  25912. },
  25913. // Return array of classes on the node
  25914. classes: function classes() {
  25915. var attr = this.attr('class');
  25916. return attr == null ? [] : attr.trim().split(SVG.regex.delimiter);
  25917. },
  25918. // Return true if class exists on the node, false otherwise
  25919. hasClass: function hasClass(name) {
  25920. return this.classes().indexOf(name) != -1;
  25921. },
  25922. // Add class to the node
  25923. addClass: function addClass(name) {
  25924. if (!this.hasClass(name)) {
  25925. var array = this.classes();
  25926. array.push(name);
  25927. this.attr('class', array.join(' '));
  25928. }
  25929. return this;
  25930. },
  25931. // Remove class from the node
  25932. removeClass: function removeClass(name) {
  25933. if (this.hasClass(name)) {
  25934. this.attr('class', this.classes().filter(function (c) {
  25935. return c != name;
  25936. }).join(' '));
  25937. }
  25938. return this;
  25939. },
  25940. // Toggle the presence of a class on the node
  25941. toggleClass: function toggleClass(name) {
  25942. return this.hasClass(name) ? this.removeClass(name) : this.addClass(name);
  25943. },
  25944. // Get referenced element form attribute value
  25945. reference: function reference(attr) {
  25946. return SVG.get(this.attr(attr));
  25947. },
  25948. // Returns the parent element instance
  25949. parent: function parent(type) {
  25950. var parent = this;
  25951. // check for parent
  25952. if (!parent.node.parentNode) return null;
  25953. // get parent element
  25954. parent = SVG.adopt(parent.node.parentNode);
  25955. if (!type) return parent;
  25956. // loop trough ancestors if type is given
  25957. while (parent && parent.node instanceof window.SVGElement) {
  25958. if (typeof type === 'string' ? parent.matches(type) : parent instanceof type) return parent;
  25959. if (!parent.node.parentNode || parent.node.parentNode.nodeName == '#document') return null; // #759, #720
  25960. parent = SVG.adopt(parent.node.parentNode);
  25961. }
  25962. },
  25963. // Get parent document
  25964. doc: function doc() {
  25965. return this instanceof SVG.Doc ? this : this.parent(SVG.Doc);
  25966. },
  25967. // return array of all ancestors of given type up to the root svg
  25968. parents: function parents(type) {
  25969. var parents = [],
  25970. parent = this;
  25971. do {
  25972. parent = parent.parent(type);
  25973. if (!parent || !parent.node) break;
  25974. parents.push(parent);
  25975. } while (parent.parent);
  25976. return parents;
  25977. },
  25978. // matches the element vs a css selector
  25979. matches: function matches(selector) {
  25980. return _matches(this.node, selector);
  25981. },
  25982. // Returns the svg node to call native svg methods on it
  25983. native: function native() {
  25984. return this.node;
  25985. },
  25986. // Import raw svg
  25987. svg: function svg(_svg) {
  25988. // create temporary holder
  25989. var well = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  25990. // act as a setter if svg is given
  25991. if (_svg && this instanceof SVG.Parent) {
  25992. // dump raw svg
  25993. well.innerHTML = '<svg>' + _svg.replace(/\n/, '').replace(/<([\w:-]+)([^<]+?)\/>/g, '<$1$2></$1>') + '</svg>';
  25994. // transplant nodes
  25995. for (var i = 0, il = well.firstChild.childNodes.length; i < il; i++) {
  25996. this.node.appendChild(well.firstChild.firstChild);
  25997. }
  25998. // otherwise act as a getter
  25999. } else {
  26000. // create a wrapping svg element in case of partial content
  26001. well.appendChild(_svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'));
  26002. // write svgjs data to the dom
  26003. this.writeDataToDom();
  26004. // insert a copy of this node
  26005. _svg.appendChild(this.node.cloneNode(true));
  26006. // return target element
  26007. return well.innerHTML.replace(/^<svg>/, '').replace(/<\/svg>$/, '');
  26008. }
  26009. return this;
  26010. },
  26011. // write svgjs data to the dom
  26012. writeDataToDom: function writeDataToDom() {
  26013. // dump variables recursively
  26014. if (this.each || this.lines) {
  26015. var fn = this.each ? this : this.lines();
  26016. fn.each(function () {
  26017. this.writeDataToDom();
  26018. });
  26019. }
  26020. // remove previously set data
  26021. this.node.removeAttribute('svgjs:data');
  26022. if (Object.keys(this.dom).length) {
  26023. this.node.setAttribute('svgjs:data', JSON.stringify(this.dom));
  26024. } // see #428
  26025. return this;
  26026. },
  26027. // set given data to the elements data property
  26028. setData: function setData(o) {
  26029. this.dom = o;
  26030. return this;
  26031. },
  26032. is: function is(obj) {
  26033. return _is(this, obj);
  26034. }
  26035. }
  26036. });
  26037. SVG.easing = {
  26038. '-': function _(pos) {
  26039. return pos;
  26040. },
  26041. '<>': function _(pos) {
  26042. return -Math.cos(pos * Math.PI) / 2 + 0.5;
  26043. },
  26044. '>': function _(pos) {
  26045. return Math.sin(pos * Math.PI / 2);
  26046. },
  26047. '<': function _(pos) {
  26048. return -Math.cos(pos * Math.PI / 2) + 1;
  26049. }
  26050. };
  26051. SVG.morph = function (pos) {
  26052. return function (from, to) {
  26053. return new SVG.MorphObj(from, to).at(pos);
  26054. };
  26055. };
  26056. SVG.Situation = SVG.invent({
  26057. create: function create(o) {
  26058. this.init = false;
  26059. this.reversed = false;
  26060. this.reversing = false;
  26061. this.duration = new SVG.Number(o.duration).valueOf();
  26062. this.delay = new SVG.Number(o.delay).valueOf();
  26063. this.start = +new Date() + this.delay;
  26064. this.finish = this.start + this.duration;
  26065. this.ease = o.ease;
  26066. // this.loop is incremented from 0 to this.loops
  26067. // it is also incremented when in an infinite loop (when this.loops is true)
  26068. this.loop = 0;
  26069. this.loops = false;
  26070. this.animations = {
  26071. // functionToCall: [list of morphable objects]
  26072. // e.g. move: [SVG.Number, SVG.Number]
  26073. };
  26074. this.attrs = {
  26075. // holds all attributes which are not represented from a function svg.js provides
  26076. // e.g. someAttr: SVG.Number
  26077. };
  26078. this.styles = {
  26079. // holds all styles which should be animated
  26080. // e.g. fill-color: SVG.Color
  26081. };
  26082. this.transforms = [
  26083. // holds all transformations as transformation objects
  26084. // e.g. [SVG.Rotate, SVG.Translate, SVG.Matrix]
  26085. ];
  26086. this.once = {
  26087. // functions to fire at a specific position
  26088. // e.g. "0.5": function foo(){}
  26089. };
  26090. }
  26091. });
  26092. SVG.FX = SVG.invent({
  26093. create: function create(element) {
  26094. this._target = element;
  26095. this.situations = [];
  26096. this.active = false;
  26097. this.situation = null;
  26098. this.paused = false;
  26099. this.lastPos = 0;
  26100. this.pos = 0;
  26101. // The absolute position of an animation is its position in the context of its complete duration (including delay and loops)
  26102. // When performing a delay, absPos is below 0 and when performing a loop, its value is above 1
  26103. this.absPos = 0;
  26104. this._speed = 1;
  26105. },
  26106. extend: {
  26107. /**
  26108. * sets or returns the target of this animation
  26109. * @param o object || number In case of Object it holds all parameters. In case of number its the duration of the animation
  26110. * @param ease function || string Function which should be used for easing or easing keyword
  26111. * @param delay Number indicating the delay before the animation starts
  26112. * @return target || this
  26113. */
  26114. animate: function animate(o, ease, delay) {
  26115. if (_typeof(o) === 'object') {
  26116. ease = o.ease;
  26117. delay = o.delay;
  26118. o = o.duration;
  26119. }
  26120. var situation = new SVG.Situation({
  26121. duration: o || 1000,
  26122. delay: delay || 0,
  26123. ease: SVG.easing[ease || '-'] || ease
  26124. });
  26125. this.queue(situation);
  26126. return this;
  26127. },
  26128. /**
  26129. * sets a delay before the next element of the queue is called
  26130. * @param delay Duration of delay in milliseconds
  26131. * @return this.target()
  26132. */
  26133. /**
  26134. * sets or returns the target of this animation
  26135. * @param null || target SVG.Element which should be set as new target
  26136. * @return target || this
  26137. */
  26138. target: function target(_target) {
  26139. if (_target && _target instanceof SVG.Element) {
  26140. this._target = _target;
  26141. return this;
  26142. }
  26143. return this._target;
  26144. },
  26145. // returns the absolute position at a given time
  26146. timeToAbsPos: function timeToAbsPos(timestamp) {
  26147. return (timestamp - this.situation.start) / (this.situation.duration / this._speed);
  26148. },
  26149. // returns the timestamp from a given absolute positon
  26150. absPosToTime: function absPosToTime(absPos) {
  26151. return this.situation.duration / this._speed * absPos + this.situation.start;
  26152. },
  26153. // starts the animationloop
  26154. startAnimFrame: function startAnimFrame() {
  26155. this.stopAnimFrame();
  26156. this.animationFrame = window.requestAnimationFrame(function () {
  26157. this.step();
  26158. }.bind(this));
  26159. },
  26160. // cancels the animationframe
  26161. stopAnimFrame: function stopAnimFrame() {
  26162. window.cancelAnimationFrame(this.animationFrame);
  26163. },
  26164. // kicks off the animation - only does something when the queue is currently not active and at least one situation is set
  26165. start: function start() {
  26166. // dont start if already started
  26167. if (!this.active && this.situation) {
  26168. this.active = true;
  26169. this.startCurrent();
  26170. }
  26171. return this;
  26172. },
  26173. // start the current situation
  26174. startCurrent: function startCurrent() {
  26175. this.situation.start = +new Date() + this.situation.delay / this._speed;
  26176. this.situation.finish = this.situation.start + this.situation.duration / this._speed;
  26177. return this.initAnimations().step();
  26178. },
  26179. /**
  26180. * adds a function / Situation to the animation queue
  26181. * @param fn function / situation to add
  26182. * @return this
  26183. */
  26184. queue: function queue(fn) {
  26185. if (typeof fn === 'function' || fn instanceof SVG.Situation) {
  26186. this.situations.push(fn);
  26187. }
  26188. if (!this.situation) this.situation = this.situations.shift();
  26189. return this;
  26190. },
  26191. /**
  26192. * pulls next element from the queue and execute it
  26193. * @return this
  26194. */
  26195. dequeue: function dequeue() {
  26196. // stop current animation
  26197. this.stop();
  26198. // get next animation from queue
  26199. this.situation = this.situations.shift();
  26200. if (this.situation) {
  26201. if (this.situation instanceof SVG.Situation) {
  26202. this.start();
  26203. } else {
  26204. // If it is not a SVG.Situation, then it is a function, we execute it
  26205. this.situation.call(this);
  26206. }
  26207. }
  26208. return this;
  26209. },
  26210. // updates all animations to the current state of the element
  26211. // this is important when one property could be changed from another property
  26212. initAnimations: function initAnimations() {
  26213. var source;
  26214. var s = this.situation;
  26215. if (s.init) return this;
  26216. for (var i in s.animations) {
  26217. source = this.target()[i]();
  26218. if (!Array.isArray(source)) {
  26219. source = [source];
  26220. }
  26221. if (!Array.isArray(s.animations[i])) {
  26222. s.animations[i] = [s.animations[i]];
  26223. }
  26224. // if(s.animations[i].length > source.length) {
  26225. // source.concat = source.concat(s.animations[i].slice(source.length, s.animations[i].length))
  26226. // }
  26227. for (var j = source.length; j--;) {
  26228. // The condition is because some methods return a normal number instead
  26229. // of a SVG.Number
  26230. if (s.animations[i][j] instanceof SVG.Number) {
  26231. source[j] = new SVG.Number(source[j]);
  26232. }
  26233. s.animations[i][j] = source[j].morph(s.animations[i][j]);
  26234. }
  26235. }
  26236. for (var i in s.attrs) {
  26237. s.attrs[i] = new SVG.MorphObj(this.target().attr(i), s.attrs[i]);
  26238. }
  26239. for (var i in s.styles) {
  26240. s.styles[i] = new SVG.MorphObj(this.target().style(i), s.styles[i]);
  26241. }
  26242. s.initialTransformation = this.target().matrixify();
  26243. s.init = true;
  26244. return this;
  26245. },
  26246. clearQueue: function clearQueue() {
  26247. this.situations = [];
  26248. return this;
  26249. },
  26250. clearCurrent: function clearCurrent() {
  26251. this.situation = null;
  26252. return this;
  26253. },
  26254. /** stops the animation immediately
  26255. * @param jumpToEnd A Boolean indicating whether to complete the current animation immediately.
  26256. * @param clearQueue A Boolean indicating whether to remove queued animation as well.
  26257. * @return this
  26258. */
  26259. stop: function stop(jumpToEnd, clearQueue) {
  26260. var active = this.active;
  26261. this.active = false;
  26262. if (clearQueue) {
  26263. this.clearQueue();
  26264. }
  26265. if (jumpToEnd && this.situation) {
  26266. // initialize the situation if it was not
  26267. !active && this.startCurrent();
  26268. this.atEnd();
  26269. }
  26270. this.stopAnimFrame();
  26271. return this.clearCurrent();
  26272. },
  26273. after: function after(fn) {
  26274. var c = this.last(),
  26275. wrapper = function wrapper(e) {
  26276. if (e.detail.situation == c) {
  26277. fn.call(this, c);
  26278. this.off('finished.fx', wrapper); // prevent memory leak
  26279. }
  26280. };
  26281. this.target().on('finished.fx', wrapper);
  26282. return this._callStart();
  26283. },
  26284. // adds a callback which is called whenever one animation step is performed
  26285. during: function during(fn) {
  26286. var c = this.last(),
  26287. wrapper = function wrapper(e) {
  26288. if (e.detail.situation == c) {
  26289. fn.call(this, e.detail.pos, SVG.morph(e.detail.pos), e.detail.eased, c);
  26290. }
  26291. };
  26292. // see above
  26293. this.target().off('during.fx', wrapper).on('during.fx', wrapper);
  26294. this.after(function () {
  26295. this.off('during.fx', wrapper);
  26296. });
  26297. return this._callStart();
  26298. },
  26299. // calls after ALL animations in the queue are finished
  26300. afterAll: function afterAll(fn) {
  26301. var wrapper = function wrapper(e) {
  26302. fn.call(this);
  26303. this.off('allfinished.fx', wrapper);
  26304. };
  26305. // see above
  26306. this.target().off('allfinished.fx', wrapper).on('allfinished.fx', wrapper);
  26307. return this._callStart();
  26308. },
  26309. last: function last() {
  26310. return this.situations.length ? this.situations[this.situations.length - 1] : this.situation;
  26311. },
  26312. // adds one property to the animations
  26313. add: function add(method, args, type) {
  26314. this.last()[type || 'animations'][method] = args;
  26315. return this._callStart();
  26316. },
  26317. /** perform one step of the animation
  26318. * @param ignoreTime Boolean indicating whether to ignore time and use position directly or recalculate position based on time
  26319. * @return this
  26320. */
  26321. step: function step(ignoreTime) {
  26322. // convert current time to an absolute position
  26323. if (!ignoreTime) this.absPos = this.timeToAbsPos(+new Date());
  26324. // This part convert an absolute position to a position
  26325. if (this.situation.loops !== false) {
  26326. var absPos, absPosInt, lastLoop;
  26327. // If the absolute position is below 0, we just treat it as if it was 0
  26328. absPos = Math.max(this.absPos, 0);
  26329. absPosInt = Math.floor(absPos);
  26330. if (this.situation.loops === true || absPosInt < this.situation.loops) {
  26331. this.pos = absPos - absPosInt;
  26332. lastLoop = this.situation.loop;
  26333. this.situation.loop = absPosInt;
  26334. } else {
  26335. this.absPos = this.situation.loops;
  26336. this.pos = 1;
  26337. // The -1 here is because we don't want to toggle reversed when all the loops have been completed
  26338. lastLoop = this.situation.loop - 1;
  26339. this.situation.loop = this.situation.loops;
  26340. }
  26341. if (this.situation.reversing) {
  26342. // Toggle reversed if an odd number of loops as occured since the last call of step
  26343. this.situation.reversed = this.situation.reversed != Boolean((this.situation.loop - lastLoop) % 2);
  26344. }
  26345. } else {
  26346. // If there are no loop, the absolute position must not be above 1
  26347. this.absPos = Math.min(this.absPos, 1);
  26348. this.pos = this.absPos;
  26349. }
  26350. // while the absolute position can be below 0, the position must not be below 0
  26351. if (this.pos < 0) this.pos = 0;
  26352. if (this.situation.reversed) this.pos = 1 - this.pos;
  26353. // apply easing
  26354. var eased = this.situation.ease(this.pos);
  26355. // call once-callbacks
  26356. for (var i in this.situation.once) {
  26357. if (i > this.lastPos && i <= eased) {
  26358. this.situation.once[i].call(this.target(), this.pos, eased);
  26359. delete this.situation.once[i];
  26360. }
  26361. }
  26362. // fire during callback with position, eased position and current situation as parameter
  26363. if (this.active) this.target().fire('during', {
  26364. pos: this.pos,
  26365. eased: eased,
  26366. fx: this,
  26367. situation: this.situation
  26368. });
  26369. // the user may call stop or finish in the during callback
  26370. // so make sure that we still have a valid situation
  26371. if (!this.situation) {
  26372. return this;
  26373. }
  26374. // apply the actual animation to every property
  26375. this.eachAt();
  26376. // do final code when situation is finished
  26377. if (this.pos == 1 && !this.situation.reversed || this.situation.reversed && this.pos == 0) {
  26378. // stop animation callback
  26379. this.stopAnimFrame();
  26380. // fire finished callback with current situation as parameter
  26381. this.target().fire('finished', {
  26382. fx: this,
  26383. situation: this.situation
  26384. });
  26385. if (!this.situations.length) {
  26386. this.target().fire('allfinished');
  26387. // Recheck the length since the user may call animate in the afterAll callback
  26388. if (!this.situations.length) {
  26389. this.target().off('.fx'); // there shouldnt be any binding left, but to make sure...
  26390. this.active = false;
  26391. }
  26392. }
  26393. // start next animation
  26394. if (this.active) this.dequeue();else this.clearCurrent();
  26395. } else if (!this.paused && this.active) {
  26396. // we continue animating when we are not at the end
  26397. this.startAnimFrame();
  26398. }
  26399. // save last eased position for once callback triggering
  26400. this.lastPos = eased;
  26401. return this;
  26402. },
  26403. // calculates the step for every property and calls block with it
  26404. eachAt: function eachAt() {
  26405. var len,
  26406. at,
  26407. self = this,
  26408. target = this.target(),
  26409. s = this.situation;
  26410. // apply animations which can be called trough a method
  26411. for (var i in s.animations) {
  26412. at = [].concat(s.animations[i]).map(function (el) {
  26413. return typeof el !== 'string' && el.at ? el.at(s.ease(self.pos), self.pos) : el;
  26414. });
  26415. target[i].apply(target, at);
  26416. }
  26417. // apply animation which has to be applied with attr()
  26418. for (var i in s.attrs) {
  26419. at = [i].concat(s.attrs[i]).map(function (el) {
  26420. return typeof el !== 'string' && el.at ? el.at(s.ease(self.pos), self.pos) : el;
  26421. });
  26422. target.attr.apply(target, at);
  26423. }
  26424. // apply animation which has to be applied with style()
  26425. for (var i in s.styles) {
  26426. at = [i].concat(s.styles[i]).map(function (el) {
  26427. return typeof el !== 'string' && el.at ? el.at(s.ease(self.pos), self.pos) : el;
  26428. });
  26429. target.style.apply(target, at);
  26430. }
  26431. // animate initialTransformation which has to be chained
  26432. if (s.transforms.length) {
  26433. // get initial initialTransformation
  26434. at = s.initialTransformation;
  26435. for (var i = 0, len = s.transforms.length; i < len; i++) {
  26436. // get next transformation in chain
  26437. var a = s.transforms[i];
  26438. // multiply matrix directly
  26439. if (a instanceof SVG.Matrix) {
  26440. if (a.relative) {
  26441. at = at.multiply(new SVG.Matrix().morph(a).at(s.ease(this.pos)));
  26442. } else {
  26443. at = at.morph(a).at(s.ease(this.pos));
  26444. }
  26445. continue;
  26446. }
  26447. // when transformation is absolute we have to reset the needed transformation first
  26448. if (!a.relative) {
  26449. a.undo(at.extract());
  26450. }
  26451. // and reapply it after
  26452. at = at.multiply(a.at(s.ease(this.pos)));
  26453. }
  26454. // set new matrix on element
  26455. target.matrix(at);
  26456. }
  26457. return this;
  26458. },
  26459. // adds an once-callback which is called at a specific position and never again
  26460. once: function once(pos, fn, isEased) {
  26461. var c = this.last();
  26462. if (!isEased) pos = c.ease(pos);
  26463. c.once[pos] = fn;
  26464. return this;
  26465. },
  26466. _callStart: function _callStart() {
  26467. setTimeout(function () {
  26468. this.start();
  26469. }.bind(this), 0);
  26470. return this;
  26471. }
  26472. },
  26473. parent: SVG.Element,
  26474. // Add method to parent elements
  26475. construct: {
  26476. // Get fx module or create a new one, then animate with given duration and ease
  26477. animate: function animate(o, ease, delay) {
  26478. return (this.fx || (this.fx = new SVG.FX(this))).animate(o, ease, delay);
  26479. },
  26480. delay: function delay(_delay) {
  26481. return (this.fx || (this.fx = new SVG.FX(this))).delay(_delay);
  26482. },
  26483. stop: function stop(jumpToEnd, clearQueue) {
  26484. if (this.fx) {
  26485. this.fx.stop(jumpToEnd, clearQueue);
  26486. }
  26487. return this;
  26488. },
  26489. finish: function finish() {
  26490. if (this.fx) {
  26491. this.fx.finish();
  26492. }
  26493. return this;
  26494. }
  26495. }
  26496. });
  26497. // MorphObj is used whenever no morphable object is given
  26498. SVG.MorphObj = SVG.invent({
  26499. create: function create(from, to) {
  26500. // prepare color for morphing
  26501. if (SVG.Color.isColor(to)) return new SVG.Color(from).morph(to);
  26502. // check if we have a list of values
  26503. if (SVG.regex.delimiter.test(from)) {
  26504. // prepare path for morphing
  26505. if (SVG.regex.pathLetters.test(from)) return new SVG.PathArray(from).morph(to);
  26506. // prepare value list for morphing
  26507. else return new SVG.Array(from).morph(to);
  26508. }
  26509. // prepare number for morphing
  26510. if (SVG.regex.numberAndUnit.test(to)) return new SVG.Number(from).morph(to);
  26511. // prepare for plain morphing
  26512. this.value = from;
  26513. this.destination = to;
  26514. },
  26515. extend: {
  26516. at: function at(pos, real) {
  26517. return real < 1 ? this.value : this.destination;
  26518. },
  26519. valueOf: function valueOf() {
  26520. return this.value;
  26521. }
  26522. }
  26523. });
  26524. SVG.extend(SVG.FX, {
  26525. // Add animatable attributes
  26526. attr: function attr(a, v, relative) {
  26527. // apply attributes individually
  26528. if (_typeof(a) === 'object') {
  26529. for (var key in a) {
  26530. this.attr(key, a[key]);
  26531. }
  26532. } else {
  26533. this.add(a, v, 'attrs');
  26534. }
  26535. return this;
  26536. },
  26537. // Add animatable plot
  26538. plot: function plot(a, b, c, d) {
  26539. // Lines can be plotted with 4 arguments
  26540. if (arguments.length == 4) {
  26541. return this.plot([a, b, c, d]);
  26542. }
  26543. return this.add('plot', new (this.target().morphArray)(a));
  26544. }
  26545. });
  26546. SVG.Box = SVG.invent({
  26547. create: function create(x, y, width, height) {
  26548. if (_typeof(x) === 'object' && !(x instanceof SVG.Element)) {
  26549. // chromes getBoundingClientRect has no x and y property
  26550. return SVG.Box.call(this, x.left != null ? x.left : x.x, x.top != null ? x.top : x.y, x.width, x.height);
  26551. } else if (arguments.length == 4) {
  26552. this.x = x;
  26553. this.y = y;
  26554. this.width = width;
  26555. this.height = height;
  26556. }
  26557. // add center, right, bottom...
  26558. fullBox(this);
  26559. }
  26560. });
  26561. SVG.BBox = SVG.invent({
  26562. // Initialize
  26563. create: function create(element) {
  26564. SVG.Box.apply(this, [].slice.call(arguments));
  26565. // get values if element is given
  26566. if (element instanceof SVG.Element) {
  26567. var box;
  26568. // yes this is ugly, but Firefox can be a pain when it comes to elements that are not yet rendered
  26569. try {
  26570. if (!document.documentElement.contains) {
  26571. // This is IE - it does not support contains() for top-level SVGs
  26572. var topParent = element.node;
  26573. while (topParent.parentNode) {
  26574. topParent = topParent.parentNode;
  26575. }
  26576. if (topParent != document) throw new Error('Element not in the dom');
  26577. } else {
  26578. // the element is NOT in the dom, throw error
  26579. // disabling the check below which fixes issue #76
  26580. // if (!document.documentElement.contains(element.node)) throw new Exception('Element not in the dom')
  26581. }
  26582. // find native bbox
  26583. box = element.node.getBBox();
  26584. } catch (e) {
  26585. if (element instanceof SVG.Shape) {
  26586. if (!SVG.parser.draw) {
  26587. // fixes apexcharts/vue-apexcharts #14
  26588. SVG.prepare();
  26589. }
  26590. var clone = element.clone(SVG.parser.draw.instance).show();
  26591. if (clone && clone.node && typeof clone.node.getBBox === 'function') {
  26592. // this check fixes jest unit tests
  26593. box = clone.node.getBBox();
  26594. }
  26595. if (clone && typeof clone.remove === 'function') {
  26596. clone.remove();
  26597. }
  26598. } else {
  26599. box = {
  26600. x: element.node.clientLeft,
  26601. y: element.node.clientTop,
  26602. width: element.node.clientWidth,
  26603. height: element.node.clientHeight
  26604. };
  26605. }
  26606. }
  26607. SVG.Box.call(this, box);
  26608. }
  26609. },
  26610. // Define ancestor
  26611. inherit: SVG.Box,
  26612. // Define Parent
  26613. parent: SVG.Element,
  26614. // Constructor
  26615. construct: {
  26616. // Get bounding box
  26617. bbox: function bbox() {
  26618. return new SVG.BBox(this);
  26619. }
  26620. }
  26621. });
  26622. SVG.BBox.prototype.constructor = SVG.BBox;
  26623. SVG.Matrix = SVG.invent({
  26624. // Initialize
  26625. create: function create(source) {
  26626. var base = arrayToMatrix([1, 0, 0, 1, 0, 0]);
  26627. // ensure source as object
  26628. source = source === null ? base : source instanceof SVG.Element ? source.matrixify() : typeof source === 'string' ? arrayToMatrix(source.split(SVG.regex.delimiter).map(parseFloat)) : arguments.length == 6 ? arrayToMatrix([].slice.call(arguments)) : Array.isArray(source) ? arrayToMatrix(source) : source && _typeof(source) === 'object' ? source : base;
  26629. // merge source
  26630. for (var i = abcdef.length - 1; i >= 0; --i) {
  26631. this[abcdef[i]] = source[abcdef[i]] != null ? source[abcdef[i]] : base[abcdef[i]];
  26632. }
  26633. },
  26634. // Add methods
  26635. extend: {
  26636. // Extract individual transformations
  26637. extract: function extract() {
  26638. // find delta transform points
  26639. var px = deltaTransformPoint(this, 0, 1);
  26640. deltaTransformPoint(this, 1, 0);
  26641. var skewX = 180 / Math.PI * Math.atan2(px.y, px.x) - 90;
  26642. return {
  26643. // translation
  26644. x: this.e,
  26645. y: this.f,
  26646. transformedX: (this.e * Math.cos(skewX * Math.PI / 180) + this.f * Math.sin(skewX * Math.PI / 180)) / Math.sqrt(this.a * this.a + this.b * this.b),
  26647. transformedY: (this.f * Math.cos(skewX * Math.PI / 180) + this.e * Math.sin(-skewX * Math.PI / 180)) / Math.sqrt(this.c * this.c + this.d * this.d),
  26648. // rotation
  26649. rotation: skewX,
  26650. a: this.a,
  26651. b: this.b,
  26652. c: this.c,
  26653. d: this.d,
  26654. e: this.e,
  26655. f: this.f,
  26656. matrix: new SVG.Matrix(this)
  26657. };
  26658. },
  26659. // Clone matrix
  26660. clone: function clone() {
  26661. return new SVG.Matrix(this);
  26662. },
  26663. // Morph one matrix into another
  26664. morph: function morph(matrix) {
  26665. // store new destination
  26666. this.destination = new SVG.Matrix(matrix);
  26667. return this;
  26668. },
  26669. // Multiplies by given matrix
  26670. multiply: function multiply(matrix) {
  26671. return new SVG.Matrix(this.native().multiply(parseMatrix(matrix).native()));
  26672. },
  26673. // Inverses matrix
  26674. inverse: function inverse() {
  26675. return new SVG.Matrix(this.native().inverse());
  26676. },
  26677. // Translate matrix
  26678. translate: function translate(x, y) {
  26679. return new SVG.Matrix(this.native().translate(x || 0, y || 0));
  26680. },
  26681. // Convert to native SVGMatrix
  26682. native: function native() {
  26683. // create new matrix
  26684. var matrix = SVG.parser.native.createSVGMatrix();
  26685. // update with current values
  26686. for (var i = abcdef.length - 1; i >= 0; i--) {
  26687. matrix[abcdef[i]] = this[abcdef[i]];
  26688. }
  26689. return matrix;
  26690. },
  26691. // Convert matrix to string
  26692. toString: function toString() {
  26693. // Construct the matrix directly, avoid values that are too small
  26694. return 'matrix(' + float32String(this.a) + ',' + float32String(this.b) + ',' + float32String(this.c) + ',' + float32String(this.d) + ',' + float32String(this.e) + ',' + float32String(this.f) + ')';
  26695. }
  26696. },
  26697. // Define parent
  26698. parent: SVG.Element,
  26699. // Add parent method
  26700. construct: {
  26701. // Get current matrix
  26702. ctm: function ctm() {
  26703. return new SVG.Matrix(this.node.getCTM());
  26704. },
  26705. // Get current screen matrix
  26706. screenCTM: function screenCTM() {
  26707. /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537
  26708. This is needed because FF does not return the transformation matrix
  26709. for the inner coordinate system when getScreenCTM() is called on nested svgs.
  26710. However all other Browsers do that */
  26711. if (this instanceof SVG.Nested) {
  26712. var rect = this.rect(1, 1);
  26713. var m = rect.node.getScreenCTM();
  26714. rect.remove();
  26715. return new SVG.Matrix(m);
  26716. }
  26717. return new SVG.Matrix(this.node.getScreenCTM());
  26718. }
  26719. }
  26720. });
  26721. SVG.Point = SVG.invent({
  26722. // Initialize
  26723. create: function create(x, y) {
  26724. var source,
  26725. base = {
  26726. x: 0,
  26727. y: 0
  26728. };
  26729. // ensure source as object
  26730. source = Array.isArray(x) ? {
  26731. x: x[0],
  26732. y: x[1]
  26733. } : _typeof(x) === 'object' ? {
  26734. x: x.x,
  26735. y: x.y
  26736. } : x != null ? {
  26737. x: x,
  26738. y: y != null ? y : x
  26739. } : base; // If y has no value, then x is used has its value
  26740. // merge source
  26741. this.x = source.x;
  26742. this.y = source.y;
  26743. },
  26744. // Add methods
  26745. extend: {
  26746. // Clone point
  26747. clone: function clone() {
  26748. return new SVG.Point(this);
  26749. },
  26750. // Morph one point into another
  26751. morph: function morph(x, y) {
  26752. // store new destination
  26753. this.destination = new SVG.Point(x, y);
  26754. return this;
  26755. }
  26756. }
  26757. });
  26758. SVG.extend(SVG.Element, {
  26759. // Get point
  26760. point: function point(x, y) {
  26761. return new SVG.Point(x, y).transform(this.screenCTM().inverse());
  26762. }
  26763. });
  26764. SVG.extend(SVG.Element, {
  26765. // Set svg element attribute
  26766. attr: function attr(a, v, n) {
  26767. // act as full getter
  26768. if (a == null) {
  26769. // get an object of attributes
  26770. a = {};
  26771. v = this.node.attributes;
  26772. for (var n = v.length - 1; n >= 0; n--) {
  26773. a[v[n].nodeName] = SVG.regex.isNumber.test(v[n].nodeValue) ? parseFloat(v[n].nodeValue) : v[n].nodeValue;
  26774. }
  26775. return a;
  26776. } else if (_typeof(a) === 'object') {
  26777. // apply every attribute individually if an object is passed
  26778. for (var v_ in a) {
  26779. this.attr(v_, a[v_]);
  26780. }
  26781. } else if (v === null) {
  26782. // remove value
  26783. this.node.removeAttribute(a);
  26784. } else if (v == null) {
  26785. // act as a getter if the first and only argument is not an object
  26786. v = this.node.getAttribute(a);
  26787. return v == null ? SVG.defaults.attrs[a] : SVG.regex.isNumber.test(v) ? parseFloat(v) : v;
  26788. } else {
  26789. // BUG FIX: some browsers will render a stroke if a color is given even though stroke width is 0
  26790. if (a == 'stroke-width') {
  26791. this.attr('stroke', parseFloat(v) > 0 ? this._stroke : null);
  26792. } else if (a == 'stroke') {
  26793. this._stroke = v;
  26794. }
  26795. // convert image fill and stroke to patterns
  26796. if (a == 'fill' || a == 'stroke') {
  26797. if (SVG.regex.isImage.test(v)) {
  26798. v = this.doc().defs().image(v, 0, 0);
  26799. }
  26800. if (v instanceof SVG.Image) {
  26801. v = this.doc().defs().pattern(0, 0, function () {
  26802. this.add(v);
  26803. });
  26804. }
  26805. }
  26806. // ensure correct numeric values (also accepts NaN and Infinity)
  26807. if (typeof v === 'number') {
  26808. v = new SVG.Number(v);
  26809. }
  26810. // ensure full hex color
  26811. else if (SVG.Color.isColor(v)) {
  26812. v = new SVG.Color(v);
  26813. }
  26814. // parse array values
  26815. else if (Array.isArray(v)) {
  26816. v = new SVG.Array(v);
  26817. }
  26818. // if the passed attribute is leading...
  26819. if (a == 'leading') {
  26820. // ... call the leading method instead
  26821. if (this.leading) {
  26822. this.leading(v);
  26823. }
  26824. } else {
  26825. // set given attribute on node
  26826. typeof n === 'string' ? this.node.setAttributeNS(n, a, v.toString()) : this.node.setAttribute(a, v.toString());
  26827. }
  26828. // rebuild if required
  26829. if (this.rebuild && (a == 'font-size' || a == 'x')) {
  26830. this.rebuild(a, v);
  26831. }
  26832. }
  26833. return this;
  26834. }
  26835. });
  26836. SVG.extend(SVG.Element, {
  26837. // Add transformations
  26838. transform: function transform(o, relative) {
  26839. // get target in case of the fx module, otherwise reference this
  26840. var target = this,
  26841. matrix;
  26842. // act as a getter
  26843. if (_typeof(o) !== 'object') {
  26844. // get current matrix
  26845. matrix = new SVG.Matrix(target).extract();
  26846. return typeof o === 'string' ? matrix[o] : matrix;
  26847. }
  26848. // get current matrix
  26849. matrix = new SVG.Matrix(target);
  26850. // ensure relative flag
  26851. relative = !!relative || !!o.relative;
  26852. // act on matrix
  26853. if (o.a != null) {
  26854. matrix = relative
  26855. // relative
  26856. ? matrix.multiply(new SVG.Matrix(o))
  26857. // absolute
  26858. : new SVG.Matrix(o);
  26859. }
  26860. return this.attr('transform', matrix);
  26861. }
  26862. });
  26863. SVG.extend(SVG.Element, {
  26864. // Reset all transformations
  26865. untransform: function untransform() {
  26866. return this.attr('transform', null);
  26867. },
  26868. // merge the whole transformation chain into one matrix and returns it
  26869. matrixify: function matrixify() {
  26870. var matrix = (this.attr('transform') || ''
  26871. // split transformations
  26872. ).split(SVG.regex.transforms).slice(0, -1).map(function (str) {
  26873. // generate key => value pairs
  26874. var kv = str.trim().split('(');
  26875. return [kv[0], kv[1].split(SVG.regex.delimiter).map(function (str) {
  26876. return parseFloat(str);
  26877. })];
  26878. })
  26879. // merge every transformation into one matrix
  26880. .reduce(function (matrix, transform) {
  26881. if (transform[0] == 'matrix') return matrix.multiply(arrayToMatrix(transform[1]));
  26882. return matrix[transform[0]].apply(matrix, transform[1]);
  26883. }, new SVG.Matrix());
  26884. return matrix;
  26885. },
  26886. // add an element to another parent without changing the visual representation on the screen
  26887. toParent: function toParent(parent) {
  26888. if (this == parent) return this;
  26889. var ctm = this.screenCTM();
  26890. var pCtm = parent.screenCTM().inverse();
  26891. this.addTo(parent).untransform().transform(pCtm.multiply(ctm));
  26892. return this;
  26893. },
  26894. // same as above with parent equals root-svg
  26895. toDoc: function toDoc() {
  26896. return this.toParent(this.doc());
  26897. }
  26898. });
  26899. SVG.Transformation = SVG.invent({
  26900. create: function create(source, inversed) {
  26901. if (arguments.length > 1 && typeof inversed !== 'boolean') {
  26902. return this.constructor.call(this, [].slice.call(arguments));
  26903. }
  26904. if (Array.isArray(source)) {
  26905. for (var i = 0, len = this.arguments.length; i < len; ++i) {
  26906. this[this.arguments[i]] = source[i];
  26907. }
  26908. } else if (source && _typeof(source) === 'object') {
  26909. for (var i = 0, len = this.arguments.length; i < len; ++i) {
  26910. this[this.arguments[i]] = source[this.arguments[i]];
  26911. }
  26912. }
  26913. this.inversed = false;
  26914. if (inversed === true) {
  26915. this.inversed = true;
  26916. }
  26917. }
  26918. });
  26919. SVG.Translate = SVG.invent({
  26920. parent: SVG.Matrix,
  26921. inherit: SVG.Transformation,
  26922. create: function create(source, inversed) {
  26923. this.constructor.apply(this, [].slice.call(arguments));
  26924. },
  26925. extend: {
  26926. arguments: ['transformedX', 'transformedY'],
  26927. method: 'translate'
  26928. }
  26929. });
  26930. SVG.extend(SVG.Element, {
  26931. // Dynamic style generator
  26932. style: function style(s, v) {
  26933. if (arguments.length == 0) {
  26934. // get full style
  26935. return this.node.style.cssText || '';
  26936. } else if (arguments.length < 2) {
  26937. // apply every style individually if an object is passed
  26938. if (_typeof(s) === 'object') {
  26939. for (var v_ in s) {
  26940. this.style(v_, s[v_]);
  26941. }
  26942. } else if (SVG.regex.isCss.test(s)) {
  26943. // parse css string
  26944. s = s.split(/\s*;\s*/)
  26945. // filter out suffix ; and stuff like ;;
  26946. .filter(function (e) {
  26947. return !!e;
  26948. }).map(function (e) {
  26949. return e.split(/\s*:\s*/);
  26950. });
  26951. // apply every definition individually
  26952. while (v = s.pop()) {
  26953. this.style(v[0], v[1]);
  26954. }
  26955. } else {
  26956. // act as a getter if the first and only argument is not an object
  26957. return this.node.style[camelCase(s)];
  26958. }
  26959. } else {
  26960. this.node.style[camelCase(s)] = v === null || SVG.regex.isBlank.test(v) ? '' : v;
  26961. }
  26962. return this;
  26963. }
  26964. });
  26965. SVG.Parent = SVG.invent({
  26966. // Initialize node
  26967. create: function create(element) {
  26968. this.constructor.call(this, element);
  26969. },
  26970. // Inherit from
  26971. inherit: SVG.Element,
  26972. // Add class methods
  26973. extend: {
  26974. // Returns all child elements
  26975. children: function children() {
  26976. return SVG.utils.map(SVG.utils.filterSVGElements(this.node.childNodes), function (node) {
  26977. return SVG.adopt(node);
  26978. });
  26979. },
  26980. // Add given element at a position
  26981. add: function add(element, i) {
  26982. if (i == null) {
  26983. this.node.appendChild(element.node);
  26984. } else if (element.node != this.node.childNodes[i]) {
  26985. this.node.insertBefore(element.node, this.node.childNodes[i]);
  26986. }
  26987. return this;
  26988. },
  26989. // Basically does the same as `add()` but returns the added element instead
  26990. put: function put(element, i) {
  26991. this.add(element, i);
  26992. return element;
  26993. },
  26994. // Checks if the given element is a child
  26995. has: function has(element) {
  26996. return this.index(element) >= 0;
  26997. },
  26998. // Gets index of given element
  26999. index: function index(element) {
  27000. return [].slice.call(this.node.childNodes).indexOf(element.node);
  27001. },
  27002. // Get a element at the given index
  27003. get: function get(i) {
  27004. return SVG.adopt(this.node.childNodes[i]);
  27005. },
  27006. // Get first child
  27007. first: function first() {
  27008. return this.get(0);
  27009. },
  27010. // Get the last child
  27011. last: function last() {
  27012. return this.get(this.node.childNodes.length - 1);
  27013. },
  27014. // Iterates over all children and invokes a given block
  27015. each: function each(block, deep) {
  27016. var il,
  27017. children = this.children();
  27018. for (var i = 0, il = children.length; i < il; i++) {
  27019. if (children[i] instanceof SVG.Element) {
  27020. block.apply(children[i], [i, children]);
  27021. }
  27022. if (deep && children[i] instanceof SVG.Container) {
  27023. children[i].each(block, deep);
  27024. }
  27025. }
  27026. return this;
  27027. },
  27028. // Remove a given child
  27029. removeElement: function removeElement(element) {
  27030. this.node.removeChild(element.node);
  27031. return this;
  27032. },
  27033. // Remove all elements in this container
  27034. clear: function clear() {
  27035. // remove children
  27036. while (this.node.hasChildNodes()) {
  27037. this.node.removeChild(this.node.lastChild);
  27038. }
  27039. // remove defs reference
  27040. delete this._defs;
  27041. return this;
  27042. },
  27043. // Get defs
  27044. defs: function defs() {
  27045. return this.doc().defs();
  27046. }
  27047. }
  27048. });
  27049. SVG.extend(SVG.Parent, {
  27050. ungroup: function ungroup(parent, depth) {
  27051. if (depth === 0 || this instanceof SVG.Defs || this.node == SVG.parser.draw) return this;
  27052. parent = parent || (this instanceof SVG.Doc ? this : this.parent(SVG.Parent));
  27053. depth = depth || Infinity;
  27054. this.each(function () {
  27055. if (this instanceof SVG.Defs) return this;
  27056. if (this instanceof SVG.Parent) return this.ungroup(parent, depth - 1);
  27057. return this.toParent(parent);
  27058. });
  27059. this.node.firstChild || this.remove();
  27060. return this;
  27061. },
  27062. flatten: function flatten(parent, depth) {
  27063. return this.ungroup(parent, depth);
  27064. }
  27065. });
  27066. SVG.Container = SVG.invent({
  27067. // Initialize node
  27068. create: function create(element) {
  27069. this.constructor.call(this, element);
  27070. },
  27071. // Inherit from
  27072. inherit: SVG.Parent
  27073. });
  27074. SVG.ViewBox = SVG.invent({
  27075. // Define parent
  27076. parent: SVG.Container,
  27077. // Add parent method
  27078. construct: {}
  27079. })
  27080. // Add events to elements
  27081. ;
  27082. ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove',
  27083. // , 'mouseenter' -> not supported by IE
  27084. // , 'mouseleave' -> not supported by IE
  27085. 'touchstart', 'touchmove', 'touchleave', 'touchend', 'touchcancel'].forEach(function (event) {
  27086. // add event to SVG.Element
  27087. SVG.Element.prototype[event] = function (f) {
  27088. // bind event to element rather than element node
  27089. SVG.on(this.node, event, f);
  27090. return this;
  27091. };
  27092. });
  27093. // Initialize listeners stack
  27094. SVG.listeners = [];
  27095. SVG.handlerMap = [];
  27096. SVG.listenerId = 0;
  27097. // Add event binder in the SVG namespace
  27098. SVG.on = function (node, event, listener, binding, options) {
  27099. // create listener, get object-index
  27100. var l = listener.bind(binding || node.instance || node),
  27101. index = (SVG.handlerMap.indexOf(node) + 1 || SVG.handlerMap.push(node)) - 1,
  27102. ev = event.split('.')[0],
  27103. ns = event.split('.')[1] || '*';
  27104. // ensure valid object
  27105. SVG.listeners[index] = SVG.listeners[index] || {};
  27106. SVG.listeners[index][ev] = SVG.listeners[index][ev] || {};
  27107. SVG.listeners[index][ev][ns] = SVG.listeners[index][ev][ns] || {};
  27108. if (!listener._svgjsListenerId) {
  27109. listener._svgjsListenerId = ++SVG.listenerId;
  27110. }
  27111. // reference listener
  27112. SVG.listeners[index][ev][ns][listener._svgjsListenerId] = l;
  27113. // add listener
  27114. node.addEventListener(ev, l, options || {
  27115. passive: false
  27116. });
  27117. };
  27118. // Add event unbinder in the SVG namespace
  27119. SVG.off = function (node, event, listener) {
  27120. var index = SVG.handlerMap.indexOf(node),
  27121. ev = event && event.split('.')[0],
  27122. ns = event && event.split('.')[1],
  27123. namespace = '';
  27124. if (index == -1) return;
  27125. if (listener) {
  27126. if (typeof listener === 'function') listener = listener._svgjsListenerId;
  27127. if (!listener) return;
  27128. // remove listener reference
  27129. if (SVG.listeners[index][ev] && SVG.listeners[index][ev][ns || '*']) {
  27130. // remove listener
  27131. node.removeEventListener(ev, SVG.listeners[index][ev][ns || '*'][listener], false);
  27132. delete SVG.listeners[index][ev][ns || '*'][listener];
  27133. }
  27134. } else if (ns && ev) {
  27135. // remove all listeners for a namespaced event
  27136. if (SVG.listeners[index][ev] && SVG.listeners[index][ev][ns]) {
  27137. for (var listener_ in SVG.listeners[index][ev][ns]) {
  27138. SVG.off(node, [ev, ns].join('.'), listener_);
  27139. }
  27140. delete SVG.listeners[index][ev][ns];
  27141. }
  27142. } else if (ns) {
  27143. // remove all listeners for a specific namespace
  27144. for (var event_ in SVG.listeners[index]) {
  27145. for (var namespace in SVG.listeners[index][event_]) {
  27146. if (ns === namespace) {
  27147. SVG.off(node, [event_, ns].join('.'));
  27148. }
  27149. }
  27150. }
  27151. } else if (ev) {
  27152. // remove all listeners for the event
  27153. if (SVG.listeners[index][ev]) {
  27154. for (var namespace in SVG.listeners[index][ev]) {
  27155. SVG.off(node, [ev, namespace].join('.'));
  27156. }
  27157. delete SVG.listeners[index][ev];
  27158. }
  27159. } else {
  27160. // remove all listeners on a given node
  27161. for (var event_ in SVG.listeners[index]) {
  27162. SVG.off(node, event_);
  27163. }
  27164. delete SVG.listeners[index];
  27165. delete SVG.handlerMap[index];
  27166. }
  27167. };
  27168. //
  27169. SVG.extend(SVG.Element, {
  27170. // Bind given event to listener
  27171. on: function on(event, listener, binding, options) {
  27172. SVG.on(this.node, event, listener, binding, options);
  27173. return this;
  27174. },
  27175. // Unbind event from listener
  27176. off: function off(event, listener) {
  27177. SVG.off(this.node, event, listener);
  27178. return this;
  27179. },
  27180. // Fire given event
  27181. fire: function fire(event, data) {
  27182. // Dispatch event
  27183. if (event instanceof window.Event) {
  27184. this.node.dispatchEvent(event);
  27185. } else {
  27186. this.node.dispatchEvent(event = new SVG.CustomEvent(event, {
  27187. detail: data,
  27188. cancelable: true
  27189. }));
  27190. }
  27191. this._event = event;
  27192. return this;
  27193. },
  27194. event: function event() {
  27195. return this._event;
  27196. }
  27197. });
  27198. SVG.Defs = SVG.invent({
  27199. // Initialize node
  27200. create: 'defs',
  27201. // Inherit from
  27202. inherit: SVG.Container
  27203. });
  27204. SVG.G = SVG.invent({
  27205. // Initialize node
  27206. create: 'g',
  27207. // Inherit from
  27208. inherit: SVG.Container,
  27209. // Add class methods
  27210. extend: {
  27211. // Move over x-axis
  27212. x: function x(_x2) {
  27213. return _x2 == null ? this.transform('x') : this.transform({
  27214. x: _x2 - this.x()
  27215. }, true);
  27216. }
  27217. },
  27218. // Add parent method
  27219. construct: {
  27220. // Create a group element
  27221. group: function group() {
  27222. return this.put(new SVG.G());
  27223. }
  27224. }
  27225. });
  27226. SVG.Doc = SVG.invent({
  27227. // Initialize node
  27228. create: function create(element) {
  27229. if (element) {
  27230. // ensure the presence of a dom element
  27231. element = typeof element === 'string' ? document.getElementById(element) : element;
  27232. // If the target is an svg element, use that element as the main wrapper.
  27233. // This allows svg.js to work with svg documents as well.
  27234. if (element.nodeName == 'svg') {
  27235. this.constructor.call(this, element);
  27236. } else {
  27237. this.constructor.call(this, SVG.create('svg'));
  27238. element.appendChild(this.node);
  27239. this.size('100%', '100%');
  27240. }
  27241. // set svg element attributes and ensure defs node
  27242. this.namespace().defs();
  27243. }
  27244. },
  27245. // Inherit from
  27246. inherit: SVG.Container,
  27247. // Add class methods
  27248. extend: {
  27249. // Add namespaces
  27250. namespace: function namespace() {
  27251. return this.attr({
  27252. xmlns: SVG.ns,
  27253. version: '1.1'
  27254. }).attr('xmlns:xlink', SVG.xlink, SVG.xmlns).attr('xmlns:svgjs', SVG.svgjs, SVG.xmlns);
  27255. },
  27256. // Creates and returns defs element
  27257. defs: function defs() {
  27258. if (!this._defs) {
  27259. var defs;
  27260. // Find or create a defs element in this instance
  27261. if (defs = this.node.getElementsByTagName('defs')[0]) {
  27262. this._defs = SVG.adopt(defs);
  27263. } else {
  27264. this._defs = new SVG.Defs();
  27265. }
  27266. // Make sure the defs node is at the end of the stack
  27267. this.node.appendChild(this._defs.node);
  27268. }
  27269. return this._defs;
  27270. },
  27271. // custom parent method
  27272. parent: function parent() {
  27273. if (!this.node.parentNode || this.node.parentNode.nodeName == '#document') return null;
  27274. return this.node.parentNode;
  27275. },
  27276. // Removes the doc from the DOM
  27277. remove: function remove() {
  27278. if (this.parent()) {
  27279. this.parent().removeChild(this.node);
  27280. }
  27281. return this;
  27282. },
  27283. clear: function clear() {
  27284. // remove children
  27285. while (this.node.hasChildNodes()) {
  27286. this.node.removeChild(this.node.lastChild);
  27287. }
  27288. // remove defs reference
  27289. delete this._defs;
  27290. // add back parser
  27291. if (SVG.parser.draw && !SVG.parser.draw.parentNode) {
  27292. this.node.appendChild(SVG.parser.draw);
  27293. }
  27294. return this;
  27295. },
  27296. clone: function clone(parent) {
  27297. // write dom data to the dom so the clone can pickup the data
  27298. this.writeDataToDom();
  27299. // get reference to node
  27300. var node = this.node;
  27301. // clone element and assign new id
  27302. var clone = assignNewId(node.cloneNode(true));
  27303. // insert the clone in the given parent or after myself
  27304. if (parent) {
  27305. (parent.node || parent).appendChild(clone.node);
  27306. } else {
  27307. node.parentNode.insertBefore(clone.node, node.nextSibling);
  27308. }
  27309. return clone;
  27310. }
  27311. }
  27312. });
  27313. // ### This module adds backward / forward functionality to elements.
  27314. //
  27315. SVG.extend(SVG.Element, {
  27316. // Get all siblings, including myself
  27317. });
  27318. SVG.Gradient = SVG.invent({
  27319. // Initialize node
  27320. create: function create(type) {
  27321. this.constructor.call(this, SVG.create(type + 'Gradient'));
  27322. // store type
  27323. this.type = type;
  27324. },
  27325. // Inherit from
  27326. inherit: SVG.Container,
  27327. // Add class methods
  27328. extend: {
  27329. // Add a color stop
  27330. at: function at(offset, color, opacity) {
  27331. return this.put(new SVG.Stop()).update(offset, color, opacity);
  27332. },
  27333. // Update gradient
  27334. update: function update(block) {
  27335. // remove all stops
  27336. this.clear();
  27337. // invoke passed block
  27338. if (typeof block === 'function') {
  27339. block.call(this, this);
  27340. }
  27341. return this;
  27342. },
  27343. // Return the fill id
  27344. fill: function fill() {
  27345. return 'url(#' + this.id() + ')';
  27346. },
  27347. // Alias string convertion to fill
  27348. toString: function toString() {
  27349. return this.fill();
  27350. },
  27351. // custom attr to handle transform
  27352. attr: function attr(a, b, c) {
  27353. if (a == 'transform') a = 'gradientTransform';
  27354. return SVG.Container.prototype.attr.call(this, a, b, c);
  27355. }
  27356. },
  27357. // Add parent method
  27358. construct: {
  27359. // Create gradient element in defs
  27360. gradient: function gradient(type, block) {
  27361. return this.defs().gradient(type, block);
  27362. }
  27363. }
  27364. });
  27365. // Add animatable methods to both gradient and fx module
  27366. SVG.extend(SVG.Gradient, SVG.FX, {
  27367. // From position
  27368. from: function from(x, y) {
  27369. return (this._target || this).type == 'radial' ? this.attr({
  27370. fx: new SVG.Number(x),
  27371. fy: new SVG.Number(y)
  27372. }) : this.attr({
  27373. x1: new SVG.Number(x),
  27374. y1: new SVG.Number(y)
  27375. });
  27376. },
  27377. // To position
  27378. to: function to(x, y) {
  27379. return (this._target || this).type == 'radial' ? this.attr({
  27380. cx: new SVG.Number(x),
  27381. cy: new SVG.Number(y)
  27382. }) : this.attr({
  27383. x2: new SVG.Number(x),
  27384. y2: new SVG.Number(y)
  27385. });
  27386. }
  27387. });
  27388. // Base gradient generation
  27389. SVG.extend(SVG.Defs, {
  27390. // define gradient
  27391. gradient: function gradient(type, block) {
  27392. return this.put(new SVG.Gradient(type)).update(block);
  27393. }
  27394. });
  27395. SVG.Stop = SVG.invent({
  27396. // Initialize node
  27397. create: 'stop',
  27398. // Inherit from
  27399. inherit: SVG.Element,
  27400. // Add class methods
  27401. extend: {
  27402. // add color stops
  27403. update: function update(o) {
  27404. if (typeof o === 'number' || o instanceof SVG.Number) {
  27405. o = {
  27406. offset: arguments[0],
  27407. color: arguments[1],
  27408. opacity: arguments[2]
  27409. };
  27410. }
  27411. // set attributes
  27412. if (o.opacity != null) this.attr('stop-opacity', o.opacity);
  27413. if (o.color != null) this.attr('stop-color', o.color);
  27414. if (o.offset != null) this.attr('offset', new SVG.Number(o.offset));
  27415. return this;
  27416. }
  27417. }
  27418. });
  27419. SVG.Pattern = SVG.invent({
  27420. // Initialize node
  27421. create: 'pattern',
  27422. // Inherit from
  27423. inherit: SVG.Container,
  27424. // Add class methods
  27425. extend: {
  27426. // Return the fill id
  27427. fill: function fill() {
  27428. return 'url(#' + this.id() + ')';
  27429. },
  27430. // Update pattern by rebuilding
  27431. update: function update(block) {
  27432. // remove content
  27433. this.clear();
  27434. // invoke passed block
  27435. if (typeof block === 'function') {
  27436. block.call(this, this);
  27437. }
  27438. return this;
  27439. },
  27440. // Alias string convertion to fill
  27441. toString: function toString() {
  27442. return this.fill();
  27443. },
  27444. // custom attr to handle transform
  27445. attr: function attr(a, b, c) {
  27446. if (a == 'transform') a = 'patternTransform';
  27447. return SVG.Container.prototype.attr.call(this, a, b, c);
  27448. }
  27449. },
  27450. // Add parent method
  27451. construct: {
  27452. // Create pattern element in defs
  27453. pattern: function pattern(width, height, block) {
  27454. return this.defs().pattern(width, height, block);
  27455. }
  27456. }
  27457. });
  27458. SVG.extend(SVG.Defs, {
  27459. // Define gradient
  27460. pattern: function pattern(width, height, block) {
  27461. return this.put(new SVG.Pattern()).update(block).attr({
  27462. x: 0,
  27463. y: 0,
  27464. width: width,
  27465. height: height,
  27466. patternUnits: 'userSpaceOnUse'
  27467. });
  27468. }
  27469. });
  27470. SVG.Shape = SVG.invent({
  27471. // Initialize node
  27472. create: function create(element) {
  27473. this.constructor.call(this, element);
  27474. },
  27475. // Inherit from
  27476. inherit: SVG.Element
  27477. });
  27478. SVG.Symbol = SVG.invent({
  27479. // Initialize node
  27480. create: 'symbol',
  27481. // Inherit from
  27482. inherit: SVG.Container,
  27483. construct: {
  27484. // create symbol
  27485. symbol: function symbol() {
  27486. return this.put(new SVG.Symbol());
  27487. }
  27488. }
  27489. });
  27490. SVG.Use = SVG.invent({
  27491. // Initialize node
  27492. create: 'use',
  27493. // Inherit from
  27494. inherit: SVG.Shape,
  27495. // Add class methods
  27496. extend: {
  27497. // Use element as a reference
  27498. element: function element(_element, file) {
  27499. // Set lined element
  27500. return this.attr('href', (file || '') + '#' + _element, SVG.xlink);
  27501. }
  27502. },
  27503. // Add parent method
  27504. construct: {
  27505. // Create a use element
  27506. use: function use(element, file) {
  27507. return this.put(new SVG.Use()).element(element, file);
  27508. }
  27509. }
  27510. });
  27511. SVG.Rect = SVG.invent({
  27512. // Initialize node
  27513. create: 'rect',
  27514. // Inherit from
  27515. inherit: SVG.Shape,
  27516. // Add parent method
  27517. construct: {
  27518. // Create a rect element
  27519. rect: function rect(width, height) {
  27520. return this.put(new SVG.Rect()).size(width, height);
  27521. }
  27522. }
  27523. });
  27524. SVG.Circle = SVG.invent({
  27525. // Initialize node
  27526. create: 'circle',
  27527. // Inherit from
  27528. inherit: SVG.Shape,
  27529. // Add parent method
  27530. construct: {
  27531. // Create circle element, based on ellipse
  27532. circle: function circle(size) {
  27533. return this.put(new SVG.Circle()).rx(new SVG.Number(size).divide(2)).move(0, 0);
  27534. }
  27535. }
  27536. });
  27537. SVG.extend(SVG.Circle, SVG.FX, {
  27538. // Radius x value
  27539. rx: function rx(_rx) {
  27540. return this.attr('r', _rx);
  27541. },
  27542. // Alias radius x value
  27543. ry: function ry(_ry) {
  27544. return this.rx(_ry);
  27545. }
  27546. });
  27547. SVG.Ellipse = SVG.invent({
  27548. // Initialize node
  27549. create: 'ellipse',
  27550. // Inherit from
  27551. inherit: SVG.Shape,
  27552. // Add parent method
  27553. construct: {
  27554. // Create an ellipse
  27555. ellipse: function ellipse(width, height) {
  27556. return this.put(new SVG.Ellipse()).size(width, height).move(0, 0);
  27557. }
  27558. }
  27559. });
  27560. SVG.extend(SVG.Ellipse, SVG.Rect, SVG.FX, {
  27561. // Radius x value
  27562. rx: function rx(_rx2) {
  27563. return this.attr('rx', _rx2);
  27564. },
  27565. // Radius y value
  27566. ry: function ry(_ry2) {
  27567. return this.attr('ry', _ry2);
  27568. }
  27569. });
  27570. // Add common method
  27571. SVG.extend(SVG.Circle, SVG.Ellipse, {
  27572. // Move over x-axis
  27573. x: function x(_x3) {
  27574. return _x3 == null ? this.cx() - this.rx() : this.cx(_x3 + this.rx());
  27575. },
  27576. // Move over y-axis
  27577. y: function y(_y2) {
  27578. return _y2 == null ? this.cy() - this.ry() : this.cy(_y2 + this.ry());
  27579. },
  27580. // Move by center over x-axis
  27581. cx: function cx(x) {
  27582. return x == null ? this.attr('cx') : this.attr('cx', x);
  27583. },
  27584. // Move by center over y-axis
  27585. cy: function cy(y) {
  27586. return y == null ? this.attr('cy') : this.attr('cy', y);
  27587. },
  27588. // Set width of element
  27589. width: function width(_width2) {
  27590. return _width2 == null ? this.rx() * 2 : this.rx(new SVG.Number(_width2).divide(2));
  27591. },
  27592. // Set height of element
  27593. height: function height(_height2) {
  27594. return _height2 == null ? this.ry() * 2 : this.ry(new SVG.Number(_height2).divide(2));
  27595. },
  27596. // Custom size function
  27597. size: function size(width, height) {
  27598. var p = proportionalSize(this, width, height);
  27599. return this.rx(new SVG.Number(p.width).divide(2)).ry(new SVG.Number(p.height).divide(2));
  27600. }
  27601. });
  27602. SVG.Line = SVG.invent({
  27603. // Initialize node
  27604. create: 'line',
  27605. // Inherit from
  27606. inherit: SVG.Shape,
  27607. // Add class methods
  27608. extend: {
  27609. // Get array
  27610. array: function array() {
  27611. return new SVG.PointArray([[this.attr('x1'), this.attr('y1')], [this.attr('x2'), this.attr('y2')]]);
  27612. },
  27613. // Overwrite native plot() method
  27614. plot: function plot(x1, y1, x2, y2) {
  27615. if (x1 == null) {
  27616. return this.array();
  27617. } else if (typeof y1 !== 'undefined') {
  27618. x1 = {
  27619. x1: x1,
  27620. y1: y1,
  27621. x2: x2,
  27622. y2: y2
  27623. };
  27624. } else {
  27625. x1 = new SVG.PointArray(x1).toLine();
  27626. }
  27627. return this.attr(x1);
  27628. },
  27629. // Move by left top corner
  27630. move: function move(x, y) {
  27631. return this.attr(this.array().move(x, y).toLine());
  27632. },
  27633. // Set element size to given width and height
  27634. size: function size(width, height) {
  27635. var p = proportionalSize(this, width, height);
  27636. return this.attr(this.array().size(p.width, p.height).toLine());
  27637. }
  27638. },
  27639. // Add parent method
  27640. construct: {
  27641. // Create a line element
  27642. line: function line(x1, y1, x2, y2) {
  27643. // make sure plot is called as a setter
  27644. // x1 is not necessarily a number, it can also be an array, a string and a SVG.PointArray
  27645. return SVG.Line.prototype.plot.apply(this.put(new SVG.Line()), x1 != null ? [x1, y1, x2, y2] : [0, 0, 0, 0]);
  27646. }
  27647. }
  27648. });
  27649. SVG.Polyline = SVG.invent({
  27650. // Initialize node
  27651. create: 'polyline',
  27652. // Inherit from
  27653. inherit: SVG.Shape,
  27654. // Add parent method
  27655. construct: {
  27656. // Create a wrapped polyline element
  27657. polyline: function polyline(p) {
  27658. // make sure plot is called as a setter
  27659. return this.put(new SVG.Polyline()).plot(p || new SVG.PointArray());
  27660. }
  27661. }
  27662. });
  27663. SVG.Polygon = SVG.invent({
  27664. // Initialize node
  27665. create: 'polygon',
  27666. // Inherit from
  27667. inherit: SVG.Shape,
  27668. // Add parent method
  27669. construct: {
  27670. // Create a wrapped polygon element
  27671. polygon: function polygon(p) {
  27672. // make sure plot is called as a setter
  27673. return this.put(new SVG.Polygon()).plot(p || new SVG.PointArray());
  27674. }
  27675. }
  27676. });
  27677. // Add polygon-specific functions
  27678. SVG.extend(SVG.Polyline, SVG.Polygon, {
  27679. // Get array
  27680. array: function array() {
  27681. return this._array || (this._array = new SVG.PointArray(this.attr('points')));
  27682. },
  27683. // Plot new path
  27684. plot: function plot(p) {
  27685. return p == null ? this.array() : this.clear().attr('points', typeof p === 'string' ? p : this._array = new SVG.PointArray(p));
  27686. },
  27687. // Clear array cache
  27688. clear: function clear() {
  27689. delete this._array;
  27690. return this;
  27691. },
  27692. // Move by left top corner
  27693. move: function move(x, y) {
  27694. return this.attr('points', this.array().move(x, y));
  27695. },
  27696. // Set element size to given width and height
  27697. size: function size(width, height) {
  27698. var p = proportionalSize(this, width, height);
  27699. return this.attr('points', this.array().size(p.width, p.height));
  27700. }
  27701. });
  27702. // unify all point to point elements
  27703. SVG.extend(SVG.Line, SVG.Polyline, SVG.Polygon, {
  27704. // Define morphable array
  27705. morphArray: SVG.PointArray,
  27706. // Move by left top corner over x-axis
  27707. x: function x(_x4) {
  27708. return _x4 == null ? this.bbox().x : this.move(_x4, this.bbox().y);
  27709. },
  27710. // Move by left top corner over y-axis
  27711. y: function y(_y3) {
  27712. return _y3 == null ? this.bbox().y : this.move(this.bbox().x, _y3);
  27713. },
  27714. // Set width of element
  27715. width: function width(_width3) {
  27716. var b = this.bbox();
  27717. return _width3 == null ? b.width : this.size(_width3, b.height);
  27718. },
  27719. // Set height of element
  27720. height: function height(_height3) {
  27721. var b = this.bbox();
  27722. return _height3 == null ? b.height : this.size(b.width, _height3);
  27723. }
  27724. });
  27725. SVG.Path = SVG.invent({
  27726. // Initialize node
  27727. create: 'path',
  27728. // Inherit from
  27729. inherit: SVG.Shape,
  27730. // Add class methods
  27731. extend: {
  27732. // Define morphable array
  27733. morphArray: SVG.PathArray,
  27734. // Get array
  27735. array: function array() {
  27736. return this._array || (this._array = new SVG.PathArray(this.attr('d')));
  27737. },
  27738. // Plot new path
  27739. plot: function plot(d) {
  27740. return d == null ? this.array() : this.clear().attr('d', typeof d === 'string' ? d : this._array = new SVG.PathArray(d));
  27741. },
  27742. // Clear array cache
  27743. clear: function clear() {
  27744. delete this._array;
  27745. return this;
  27746. }
  27747. },
  27748. // Add parent method
  27749. construct: {
  27750. // Create a wrapped path element
  27751. path: function path(d) {
  27752. // make sure plot is called as a setter
  27753. return this.put(new SVG.Path()).plot(d || new SVG.PathArray());
  27754. }
  27755. }
  27756. });
  27757. SVG.Image = SVG.invent({
  27758. // Initialize node
  27759. create: 'image',
  27760. // Inherit from
  27761. inherit: SVG.Shape,
  27762. // Add class methods
  27763. extend: {
  27764. // (re)load image
  27765. load: function load(url) {
  27766. if (!url) return this;
  27767. var self = this,
  27768. img = new window.Image();
  27769. // preload image
  27770. SVG.on(img, 'load', function () {
  27771. SVG.off(img);
  27772. var p = self.parent(SVG.Pattern);
  27773. if (p === null) return;
  27774. // ensure image size
  27775. if (self.width() == 0 && self.height() == 0) {
  27776. self.size(img.width, img.height);
  27777. }
  27778. // ensure pattern size if not set
  27779. if (p && p.width() == 0 && p.height() == 0) {
  27780. p.size(self.width(), self.height());
  27781. }
  27782. // callback
  27783. if (typeof self._loaded === 'function') {
  27784. self._loaded.call(self, {
  27785. width: img.width,
  27786. height: img.height,
  27787. ratio: img.width / img.height,
  27788. url: url
  27789. });
  27790. }
  27791. });
  27792. SVG.on(img, 'error', function (e) {
  27793. SVG.off(img);
  27794. if (typeof self._error === 'function') {
  27795. self._error.call(self, e);
  27796. }
  27797. });
  27798. return this.attr('href', img.src = this.src = url, SVG.xlink);
  27799. },
  27800. // Add loaded callback
  27801. loaded: function loaded(_loaded) {
  27802. this._loaded = _loaded;
  27803. return this;
  27804. },
  27805. error: function error(_error) {
  27806. this._error = _error;
  27807. return this;
  27808. }
  27809. },
  27810. // Add parent method
  27811. construct: {
  27812. // create image element, load image and set its size
  27813. image: function image(source, width, height) {
  27814. return this.put(new SVG.Image()).load(source).size(width || 0, height || width || 0);
  27815. }
  27816. }
  27817. });
  27818. SVG.Text = SVG.invent({
  27819. // Initialize node
  27820. create: function create() {
  27821. this.constructor.call(this, SVG.create('text'));
  27822. this.dom.leading = new SVG.Number(1.3); // store leading value for rebuilding
  27823. this._rebuild = true; // enable automatic updating of dy values
  27824. this._build = false; // disable build mode for adding multiple lines
  27825. // set default font
  27826. this.attr('font-family', SVG.defaults.attrs['font-family']);
  27827. },
  27828. // Inherit from
  27829. inherit: SVG.Shape,
  27830. // Add class methods
  27831. extend: {
  27832. // Move over x-axis
  27833. x: function x(_x5) {
  27834. // act as getter
  27835. if (_x5 == null) {
  27836. return this.attr('x');
  27837. }
  27838. return this.attr('x', _x5);
  27839. },
  27840. // Set the text content
  27841. text: function text(_text) {
  27842. // act as getter
  27843. if (typeof _text === 'undefined') {
  27844. var _text = '';
  27845. var children = this.node.childNodes;
  27846. for (var i = 0, len = children.length; i < len; ++i) {
  27847. // add newline if its not the first child and newLined is set to true
  27848. if (i != 0 && children[i].nodeType != 3 && SVG.adopt(children[i]).dom.newLined == true) {
  27849. _text += '\n';
  27850. }
  27851. // add content of this node
  27852. _text += children[i].textContent;
  27853. }
  27854. return _text;
  27855. }
  27856. // remove existing content
  27857. this.clear().build(true);
  27858. if (typeof _text === 'function') {
  27859. // call block
  27860. _text.call(this, this);
  27861. } else {
  27862. // store text and make sure text is not blank
  27863. _text = _text.split('\n');
  27864. // build new lines
  27865. for (var i = 0, il = _text.length; i < il; i++) {
  27866. this.tspan(_text[i]).newLine();
  27867. }
  27868. }
  27869. // disable build mode and rebuild lines
  27870. return this.build(false).rebuild();
  27871. },
  27872. // Set font size
  27873. size: function size(_size) {
  27874. return this.attr('font-size', _size).rebuild();
  27875. },
  27876. // Set / get leading
  27877. leading: function leading(value) {
  27878. // act as getter
  27879. if (value == null) {
  27880. return this.dom.leading;
  27881. }
  27882. // act as setter
  27883. this.dom.leading = new SVG.Number(value);
  27884. return this.rebuild();
  27885. },
  27886. // Get all the first level lines
  27887. lines: function lines() {
  27888. var node = (this.textPath && this.textPath() || this).node;
  27889. // filter tspans and map them to SVG.js instances
  27890. var lines = SVG.utils.map(SVG.utils.filterSVGElements(node.childNodes), function (el) {
  27891. return SVG.adopt(el);
  27892. });
  27893. // return an instance of SVG.set
  27894. return new SVG.Set(lines);
  27895. },
  27896. // Rebuild appearance type
  27897. rebuild: function rebuild(_rebuild) {
  27898. // store new rebuild flag if given
  27899. if (typeof _rebuild === 'boolean') {
  27900. this._rebuild = _rebuild;
  27901. }
  27902. // define position of all lines
  27903. if (this._rebuild) {
  27904. var self = this,
  27905. blankLineOffset = 0,
  27906. dy = this.dom.leading * new SVG.Number(this.attr('font-size'));
  27907. this.lines().each(function () {
  27908. if (this.dom.newLined) {
  27909. if (!self.textPath()) {
  27910. this.attr('x', self.attr('x'));
  27911. }
  27912. if (this.text() == '\n') {
  27913. blankLineOffset += dy;
  27914. } else {
  27915. this.attr('dy', dy + blankLineOffset);
  27916. blankLineOffset = 0;
  27917. }
  27918. }
  27919. });
  27920. this.fire('rebuild');
  27921. }
  27922. return this;
  27923. },
  27924. // Enable / disable build mode
  27925. build: function build(_build) {
  27926. this._build = !!_build;
  27927. return this;
  27928. },
  27929. // overwrite method from parent to set data properly
  27930. setData: function setData(o) {
  27931. this.dom = o;
  27932. this.dom.leading = new SVG.Number(o.leading || 1.3);
  27933. return this;
  27934. }
  27935. },
  27936. // Add parent method
  27937. construct: {
  27938. // Create text element
  27939. text: function text(_text2) {
  27940. return this.put(new SVG.Text()).text(_text2);
  27941. },
  27942. // Create plain text element
  27943. plain: function plain(text) {
  27944. return this.put(new SVG.Text()).plain(text);
  27945. }
  27946. }
  27947. });
  27948. SVG.Tspan = SVG.invent({
  27949. // Initialize node
  27950. create: 'tspan',
  27951. // Inherit from
  27952. inherit: SVG.Shape,
  27953. // Add class methods
  27954. extend: {
  27955. // Set text content
  27956. text: function text(_text3) {
  27957. if (_text3 == null) return this.node.textContent + (this.dom.newLined ? '\n' : '');
  27958. typeof _text3 === 'function' ? _text3.call(this, this) : this.plain(_text3);
  27959. return this;
  27960. },
  27961. // Shortcut dx
  27962. dx: function dx(_dx) {
  27963. return this.attr('dx', _dx);
  27964. },
  27965. // Shortcut dy
  27966. dy: function dy(_dy) {
  27967. return this.attr('dy', _dy);
  27968. },
  27969. // Create new line
  27970. newLine: function newLine() {
  27971. // fetch text parent
  27972. var t = this.parent(SVG.Text);
  27973. // mark new line
  27974. this.dom.newLined = true;
  27975. // apply new hy¡n
  27976. return this.dy(t.dom.leading * t.attr('font-size')).attr('x', t.x());
  27977. }
  27978. }
  27979. });
  27980. SVG.extend(SVG.Text, SVG.Tspan, {
  27981. // Create plain text node
  27982. plain: function plain(text) {
  27983. // clear if build mode is disabled
  27984. if (this._build === false) {
  27985. this.clear();
  27986. }
  27987. // create text node
  27988. this.node.appendChild(document.createTextNode(text));
  27989. return this;
  27990. },
  27991. // Create a tspan
  27992. tspan: function tspan(text) {
  27993. var node = (this.textPath && this.textPath() || this).node,
  27994. tspan = new SVG.Tspan();
  27995. // clear if build mode is disabled
  27996. if (this._build === false) {
  27997. this.clear();
  27998. }
  27999. // add new tspan
  28000. node.appendChild(tspan.node);
  28001. return tspan.text(text);
  28002. },
  28003. // Clear all lines
  28004. clear: function clear() {
  28005. var node = (this.textPath && this.textPath() || this).node;
  28006. // remove existing child nodes
  28007. while (node.hasChildNodes()) {
  28008. node.removeChild(node.lastChild);
  28009. }
  28010. return this;
  28011. },
  28012. // Get length of text element
  28013. length: function length() {
  28014. return this.node.getComputedTextLength();
  28015. }
  28016. });
  28017. SVG.TextPath = SVG.invent({
  28018. // Initialize node
  28019. create: 'textPath',
  28020. // Inherit from
  28021. inherit: SVG.Parent,
  28022. // Define parent class
  28023. parent: SVG.Text,
  28024. // Add parent method
  28025. construct: {
  28026. morphArray: SVG.PathArray,
  28027. // return the array of the path track element
  28028. array: function array() {
  28029. var track = this.track();
  28030. return track ? track.array() : null;
  28031. },
  28032. // Plot path if any
  28033. plot: function plot(d) {
  28034. var track = this.track(),
  28035. pathArray = null;
  28036. if (track) {
  28037. pathArray = track.plot(d);
  28038. }
  28039. return d == null ? pathArray : this;
  28040. },
  28041. // Get the path track element
  28042. track: function track() {
  28043. var path = this.textPath();
  28044. if (path) {
  28045. return path.reference('href');
  28046. }
  28047. },
  28048. // Get the textPath child
  28049. textPath: function textPath() {
  28050. if (this.node.firstChild && this.node.firstChild.nodeName == 'textPath') {
  28051. return SVG.adopt(this.node.firstChild);
  28052. }
  28053. }
  28054. }
  28055. });
  28056. SVG.Nested = SVG.invent({
  28057. // Initialize node
  28058. create: function create() {
  28059. this.constructor.call(this, SVG.create('svg'));
  28060. this.style('overflow', 'visible');
  28061. },
  28062. // Inherit from
  28063. inherit: SVG.Container,
  28064. // Add parent method
  28065. construct: {
  28066. // Create nested svg document
  28067. nested: function nested() {
  28068. return this.put(new SVG.Nested());
  28069. }
  28070. }
  28071. });
  28072. // Define list of available attributes for stroke and fill
  28073. var sugar = {
  28074. stroke: ['color', 'width', 'opacity', 'linecap', 'linejoin', 'miterlimit', 'dasharray', 'dashoffset'],
  28075. fill: ['color', 'opacity', 'rule'],
  28076. prefix: function prefix(t, a) {
  28077. return a == 'color' ? t : t + '-' + a;
  28078. }
  28079. }
  28080. // Add sugar for fill and stroke
  28081. ;
  28082. ['fill', 'stroke'].forEach(function (m) {
  28083. var extension = {};
  28084. extension[m] = function (o) {
  28085. if (typeof o === 'undefined') {
  28086. return this;
  28087. }
  28088. if (typeof o === 'string' || SVG.Color.isRgb(o) || o && typeof o.fill === 'function') {
  28089. this.attr(m, o);
  28090. } else
  28091. // set all attributes from sugar.fill and sugar.stroke list
  28092. {
  28093. for (var i = sugar[m].length - 1; i >= 0; i--) {
  28094. if (o[sugar[m][i]] != null) {
  28095. this.attr(sugar.prefix(m, sugar[m][i]), o[sugar[m][i]]);
  28096. }
  28097. }
  28098. }
  28099. return this;
  28100. };
  28101. SVG.extend(SVG.Element, SVG.FX, extension);
  28102. });
  28103. SVG.extend(SVG.Element, SVG.FX, {
  28104. // Map translate to transform
  28105. translate: function translate(x, y) {
  28106. return this.transform({
  28107. x: x,
  28108. y: y
  28109. });
  28110. },
  28111. // Map matrix to transform
  28112. matrix: function matrix(m) {
  28113. return this.attr('transform', new SVG.Matrix(arguments.length == 6 ? [].slice.call(arguments) : m));
  28114. },
  28115. // Opacity
  28116. opacity: function opacity(value) {
  28117. return this.attr('opacity', value);
  28118. },
  28119. // Relative move over x axis
  28120. dx: function dx(x) {
  28121. return this.x(new SVG.Number(x).plus(this instanceof SVG.FX ? 0 : this.x()), true);
  28122. },
  28123. // Relative move over y axis
  28124. dy: function dy(y) {
  28125. return this.y(new SVG.Number(y).plus(this instanceof SVG.FX ? 0 : this.y()), true);
  28126. }
  28127. });
  28128. SVG.extend(SVG.Path, {
  28129. // Get path length
  28130. length: function length() {
  28131. return this.node.getTotalLength();
  28132. },
  28133. // Get point at length
  28134. pointAt: function pointAt(length) {
  28135. return this.node.getPointAtLength(length);
  28136. }
  28137. });
  28138. SVG.Set = SVG.invent({
  28139. // Initialize
  28140. create: function create(members) {
  28141. // Set initial state
  28142. Array.isArray(members) ? this.members = members : this.clear();
  28143. },
  28144. // Add class methods
  28145. extend: {
  28146. // Add element to set
  28147. add: function add() {
  28148. var il,
  28149. elements = [].slice.call(arguments);
  28150. for (var i = 0, il = elements.length; i < il; i++) {
  28151. this.members.push(elements[i]);
  28152. }
  28153. return this;
  28154. },
  28155. // Remove element from set
  28156. remove: function remove(element) {
  28157. var i = this.index(element);
  28158. // remove given child
  28159. if (i > -1) {
  28160. this.members.splice(i, 1);
  28161. }
  28162. return this;
  28163. },
  28164. // Iterate over all members
  28165. each: function each(block) {
  28166. for (var i = 0, il = this.members.length; i < il; i++) {
  28167. block.apply(this.members[i], [i, this.members]);
  28168. }
  28169. return this;
  28170. },
  28171. // Restore to defaults
  28172. clear: function clear() {
  28173. // initialize store
  28174. this.members = [];
  28175. return this;
  28176. },
  28177. // Get the length of a set
  28178. length: function length() {
  28179. return this.members.length;
  28180. },
  28181. // Checks if a given element is present in set
  28182. has: function has(element) {
  28183. return this.index(element) >= 0;
  28184. },
  28185. // retuns index of given element in set
  28186. index: function index(element) {
  28187. return this.members.indexOf(element);
  28188. },
  28189. // Get member at given index
  28190. get: function get(i) {
  28191. return this.members[i];
  28192. },
  28193. // Get first member
  28194. first: function first() {
  28195. return this.get(0);
  28196. },
  28197. // Get last member
  28198. last: function last() {
  28199. return this.get(this.members.length - 1);
  28200. },
  28201. // Default value
  28202. valueOf: function valueOf() {
  28203. return this.members;
  28204. }
  28205. },
  28206. // Add parent method
  28207. construct: {
  28208. // Create a new set
  28209. set: function set(members) {
  28210. return new SVG.Set(members);
  28211. }
  28212. }
  28213. });
  28214. SVG.FX.Set = SVG.invent({
  28215. // Initialize node
  28216. create: function create(set) {
  28217. // store reference to set
  28218. this.set = set;
  28219. }
  28220. });
  28221. // Alias methods
  28222. SVG.Set.inherit = function () {
  28223. var methods = [];
  28224. // gather shape methods
  28225. for (var m in SVG.Shape.prototype) {
  28226. if (typeof SVG.Shape.prototype[m] === 'function' && typeof SVG.Set.prototype[m] !== 'function') {
  28227. methods.push(m);
  28228. }
  28229. }
  28230. // apply shape aliasses
  28231. methods.forEach(function (method) {
  28232. SVG.Set.prototype[method] = function () {
  28233. for (var i = 0, il = this.members.length; i < il; i++) {
  28234. if (this.members[i] && typeof this.members[i][method] === 'function') {
  28235. this.members[i][method].apply(this.members[i], arguments);
  28236. }
  28237. }
  28238. return method == 'animate' ? this.fx || (this.fx = new SVG.FX.Set(this)) : this;
  28239. };
  28240. });
  28241. // clear methods for the next round
  28242. methods = [];
  28243. // gather fx methods
  28244. for (var m in SVG.FX.prototype) {
  28245. if (typeof SVG.FX.prototype[m] === 'function' && typeof SVG.FX.Set.prototype[m] !== 'function') {
  28246. methods.push(m);
  28247. }
  28248. }
  28249. // apply fx aliasses
  28250. methods.forEach(function (method) {
  28251. SVG.FX.Set.prototype[method] = function () {
  28252. for (var i = 0, il = this.set.members.length; i < il; i++) {
  28253. this.set.members[i].fx[method].apply(this.set.members[i].fx, arguments);
  28254. }
  28255. return this;
  28256. };
  28257. });
  28258. };
  28259. SVG.extend(SVG.Element, {});
  28260. SVG.extend(SVG.Element, {
  28261. // Remember arbitrary data
  28262. remember: function remember(k, v) {
  28263. // remember every item in an object individually
  28264. if (_typeof(arguments[0]) === 'object') {
  28265. for (var v_ in k) {
  28266. this.remember(v_, k[v_]);
  28267. }
  28268. }
  28269. // retrieve memory
  28270. else if (arguments.length == 1) {
  28271. return this.memory()[k];
  28272. }
  28273. // store memory
  28274. else {
  28275. this.memory()[k] = v;
  28276. }
  28277. return this;
  28278. },
  28279. // Erase a given memory
  28280. forget: function forget() {
  28281. if (arguments.length == 0) {
  28282. this._memory = {};
  28283. } else {
  28284. for (var i = arguments.length - 1; i >= 0; i--) {
  28285. delete this.memory()[arguments[i]];
  28286. }
  28287. }
  28288. return this;
  28289. },
  28290. // Initialize or return local memory object
  28291. memory: function memory() {
  28292. return this._memory || (this._memory = {});
  28293. }
  28294. });
  28295. // Method for getting an element by id
  28296. SVG.get = function (id) {
  28297. var node = document.getElementById(idFromReference(id) || id);
  28298. return SVG.adopt(node);
  28299. };
  28300. // Select elements by query string
  28301. SVG.select = function (query, parent) {
  28302. return new SVG.Set(SVG.utils.map((parent || document).querySelectorAll(query), function (node) {
  28303. return SVG.adopt(node);
  28304. }));
  28305. };
  28306. SVG.extend(SVG.Parent, {
  28307. // Scoped select method
  28308. select: function select(query) {
  28309. return SVG.select(query, this.node);
  28310. }
  28311. });
  28312. function pathRegReplace(a, b, c, d) {
  28313. return c + d.replace(SVG.regex.dots, ' .');
  28314. }
  28315. // tests if a given element is instance of an object
  28316. function _is(el, obj) {
  28317. return el instanceof obj;
  28318. }
  28319. // tests if a given selector matches an element
  28320. function _matches(el, selector) {
  28321. return (el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(el, selector);
  28322. }
  28323. // Convert dash-separated-string to camelCase
  28324. function camelCase(s) {
  28325. return s.toLowerCase().replace(/-(.)/g, function (m, g) {
  28326. return g.toUpperCase();
  28327. });
  28328. }
  28329. // Capitalize first letter of a string
  28330. function capitalize(s) {
  28331. return s.charAt(0).toUpperCase() + s.slice(1);
  28332. }
  28333. // Ensure to six-based hex
  28334. function fullHex(hex) {
  28335. return hex.length == 4 ? ['#', hex.substring(1, 2), hex.substring(1, 2), hex.substring(2, 3), hex.substring(2, 3), hex.substring(3, 4), hex.substring(3, 4)].join('') : hex;
  28336. }
  28337. // Component to hex value
  28338. function compToHex(comp) {
  28339. var hex = comp.toString(16);
  28340. return hex.length == 1 ? '0' + hex : hex;
  28341. }
  28342. // Calculate proportional width and height values when necessary
  28343. function proportionalSize(element, width, height) {
  28344. if (width == null || height == null) {
  28345. var box = element.bbox();
  28346. if (width == null) {
  28347. width = box.width / box.height * height;
  28348. } else if (height == null) {
  28349. height = box.height / box.width * width;
  28350. }
  28351. }
  28352. return {
  28353. width: width,
  28354. height: height
  28355. };
  28356. }
  28357. // Delta transform point
  28358. function deltaTransformPoint(matrix, x, y) {
  28359. return {
  28360. x: x * matrix.a + y * matrix.c + 0,
  28361. y: x * matrix.b + y * matrix.d + 0
  28362. };
  28363. }
  28364. // Map matrix array to object
  28365. function arrayToMatrix(a) {
  28366. return {
  28367. a: a[0],
  28368. b: a[1],
  28369. c: a[2],
  28370. d: a[3],
  28371. e: a[4],
  28372. f: a[5]
  28373. };
  28374. }
  28375. // Parse matrix if required
  28376. function parseMatrix(matrix) {
  28377. if (!(matrix instanceof SVG.Matrix)) {
  28378. matrix = new SVG.Matrix(matrix);
  28379. }
  28380. return matrix;
  28381. }
  28382. // PathArray Helpers
  28383. function arrayToString(a) {
  28384. for (var i = 0, il = a.length, s = ''; i < il; i++) {
  28385. s += a[i][0];
  28386. if (a[i][1] != null) {
  28387. s += a[i][1];
  28388. if (a[i][2] != null) {
  28389. s += ' ';
  28390. s += a[i][2];
  28391. if (a[i][3] != null) {
  28392. s += ' ';
  28393. s += a[i][3];
  28394. s += ' ';
  28395. s += a[i][4];
  28396. if (a[i][5] != null) {
  28397. s += ' ';
  28398. s += a[i][5];
  28399. s += ' ';
  28400. s += a[i][6];
  28401. if (a[i][7] != null) {
  28402. s += ' ';
  28403. s += a[i][7];
  28404. }
  28405. }
  28406. }
  28407. }
  28408. }
  28409. }
  28410. return s + ' ';
  28411. }
  28412. // Deep new id assignment
  28413. function assignNewId(node) {
  28414. // do the same for SVG child nodes as well
  28415. for (var i = node.childNodes.length - 1; i >= 0; i--) {
  28416. if (node.childNodes[i] instanceof window.SVGElement) {
  28417. assignNewId(node.childNodes[i]);
  28418. }
  28419. }
  28420. return SVG.adopt(node).id(SVG.eid(node.nodeName));
  28421. }
  28422. // Add more bounding box properties
  28423. function fullBox(b) {
  28424. if (b.x == null) {
  28425. b.x = 0;
  28426. b.y = 0;
  28427. b.width = 0;
  28428. b.height = 0;
  28429. }
  28430. b.w = b.width;
  28431. b.h = b.height;
  28432. b.x2 = b.x + b.width;
  28433. b.y2 = b.y + b.height;
  28434. b.cx = b.x + b.width / 2;
  28435. b.cy = b.y + b.height / 2;
  28436. return b;
  28437. }
  28438. // Get id from reference string
  28439. function idFromReference(url) {
  28440. var m = (url || '').toString().match(SVG.regex.reference);
  28441. if (m) return m[1];
  28442. }
  28443. // If values like 1e-88 are passed, this is not a valid 32 bit float,
  28444. // but in those cases, we are so close to 0 that 0 works well!
  28445. function float32String(v) {
  28446. return Math.abs(v) > 1e-37 ? v : 0;
  28447. }
  28448. // Create matrix array for looping
  28449. var abcdef = 'abcdef'.split('');
  28450. // Add CustomEvent to IE9 and IE10
  28451. if (typeof window.CustomEvent !== 'function') {
  28452. // Code from: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
  28453. var CustomEventPoly = function CustomEventPoly(event, options) {
  28454. options = options || {
  28455. bubbles: false,
  28456. cancelable: false,
  28457. detail: undefined
  28458. };
  28459. var e = document.createEvent('CustomEvent');
  28460. e.initCustomEvent(event, options.bubbles, options.cancelable, options.detail);
  28461. return e;
  28462. };
  28463. CustomEventPoly.prototype = window.Event.prototype;
  28464. SVG.CustomEvent = CustomEventPoly;
  28465. } else {
  28466. SVG.CustomEvent = window.CustomEvent;
  28467. }
  28468. return SVG;
  28469. });
  28470. /*! svg.filter.js - v2.0.2 - 2016-02-24
  28471. * https://github.com/wout/svg.filter.js
  28472. * Copyright (c) 2016 Wout Fierens; Licensed MIT */
  28473. (function() {
  28474. // Main filter class
  28475. SVG.Filter = SVG.invent({
  28476. create: 'filter',
  28477. inherit: SVG.Parent,
  28478. extend: {
  28479. // Static strings
  28480. source: 'SourceGraphic',
  28481. sourceAlpha: 'SourceAlpha',
  28482. background: 'BackgroundImage',
  28483. backgroundAlpha: 'BackgroundAlpha',
  28484. fill: 'FillPaint',
  28485. stroke: 'StrokePaint',
  28486. autoSetIn: true,
  28487. // Custom put method for leaner code
  28488. put: function(element, i) {
  28489. this.add(element, i);
  28490. if(!element.attr('in') && this.autoSetIn){
  28491. element.attr('in',this.source);
  28492. }
  28493. if(!element.attr('result')){
  28494. element.attr('result',element);
  28495. }
  28496. return element
  28497. },
  28498. // Blend effect
  28499. blend: function(in1, in2, mode) {
  28500. return this.put(new SVG.BlendEffect(in1, in2, mode))
  28501. },
  28502. // ColorMatrix effect
  28503. colorMatrix: function(type, values) {
  28504. return this.put(new SVG.ColorMatrixEffect(type, values))
  28505. },
  28506. // ConvolveMatrix effect
  28507. convolveMatrix: function(matrix) {
  28508. return this.put(new SVG.ConvolveMatrixEffect(matrix))
  28509. },
  28510. // ComponentTransfer effect
  28511. componentTransfer: function(components) {
  28512. return this.put(new SVG.ComponentTransferEffect(components))
  28513. },
  28514. // Composite effect
  28515. composite: function(in1, in2, operator) {
  28516. return this.put(new SVG.CompositeEffect(in1, in2, operator))
  28517. },
  28518. // Flood effect
  28519. flood: function(color, opacity) {
  28520. return this.put(new SVG.FloodEffect(color, opacity))
  28521. },
  28522. // Offset effect
  28523. offset: function(x, y) {
  28524. return this.put(new SVG.OffsetEffect(x,y))
  28525. },
  28526. // Image effect
  28527. image: function(src) {
  28528. return this.put(new SVG.ImageEffect(src))
  28529. },
  28530. // Merge effect
  28531. merge: function() {
  28532. //pass the array of arguments to the constructor because we dont know if the user gave us an array as the first arguemnt or wether they listed the effects in the arguments
  28533. var args = [undefined];
  28534. for(var i in arguments) args.push(arguments[i]);
  28535. return this.put(new (SVG.MergeEffect.bind.apply(SVG.MergeEffect,args)))
  28536. },
  28537. // Gaussian Blur effect
  28538. gaussianBlur: function(x,y) {
  28539. return this.put(new SVG.GaussianBlurEffect(x,y))
  28540. },
  28541. // Morphology effect
  28542. morphology: function(operator,radius){
  28543. return this.put(new SVG.MorphologyEffect(operator,radius))
  28544. },
  28545. // DiffuseLighting effect
  28546. diffuseLighting: function(surfaceScale,diffuseConstant,kernelUnitLength){
  28547. return this.put(new SVG.DiffuseLightingEffect(surfaceScale,diffuseConstant,kernelUnitLength))
  28548. },
  28549. // DisplacementMap effect
  28550. displacementMap: function(in1,in2,scale,xChannelSelector,yChannelSelector){
  28551. return this.put(new SVG.DisplacementMapEffect(in1,in2,scale,xChannelSelector,yChannelSelector))
  28552. },
  28553. // SpecularLighting effect
  28554. specularLighting: function(surfaceScale,diffuseConstant,specularExponent,kernelUnitLength){
  28555. return this.put(new SVG.SpecularLightingEffect(surfaceScale,diffuseConstant,specularExponent,kernelUnitLength))
  28556. },
  28557. // Tile effect
  28558. tile: function(){
  28559. return this.put(new SVG.TileEffect());
  28560. },
  28561. // Turbulence effect
  28562. turbulence: function(baseFrequency,numOctaves,seed,stitchTiles,type){
  28563. return this.put(new SVG.TurbulenceEffect(baseFrequency,numOctaves,seed,stitchTiles,type))
  28564. },
  28565. // Default string value
  28566. toString: function() {
  28567. return 'url(#' + this.attr('id') + ')'
  28568. }
  28569. }
  28570. });
  28571. //add .filter function
  28572. SVG.extend(SVG.Defs, {
  28573. // Define filter
  28574. filter: function(block) {
  28575. var filter = this.put(new SVG.Filter);
  28576. /* invoke passed block */
  28577. if (typeof block === 'function')
  28578. block.call(filter, filter);
  28579. return filter
  28580. }
  28581. });
  28582. SVG.extend(SVG.Container, {
  28583. // Define filter on defs
  28584. filter: function(block) {
  28585. return this.defs().filter(block)
  28586. }
  28587. });
  28588. SVG.extend(SVG.Element, SVG.G, SVG.Nested, {
  28589. // Create filter element in defs and store reference
  28590. filter: function(block) {
  28591. this.filterer = block instanceof SVG.Element ?
  28592. block : this.doc().filter(block);
  28593. if(this.doc() && this.filterer.doc() !== this.doc()){
  28594. this.doc().defs().add(this.filterer);
  28595. }
  28596. this.attr('filter', this.filterer);
  28597. return this.filterer
  28598. },
  28599. // Remove filter
  28600. unfilter: function(remove) {
  28601. /* also remove the filter node */
  28602. if (this.filterer && remove === true)
  28603. this.filterer.remove();
  28604. /* delete reference to filterer */
  28605. delete this.filterer;
  28606. /* remove filter attribute */
  28607. return this.attr('filter', null)
  28608. }
  28609. });
  28610. // Create SVG.Effect class
  28611. SVG.Effect = SVG.invent({
  28612. create: function(){
  28613. this.constructor.call(this);
  28614. },
  28615. inherit: SVG.Element,
  28616. extend: {
  28617. // Set in attribute
  28618. in: function(effect) {
  28619. return effect == null? this.parent() && this.parent().select('[result="'+this.attr('in')+'"]').get(0) || this.attr('in') : this.attr('in', effect)
  28620. },
  28621. // Named result
  28622. result: function(result) {
  28623. return result == null? this.attr('result') : this.attr('result',result)
  28624. },
  28625. // Stringification
  28626. toString: function() {
  28627. return this.result()
  28628. }
  28629. }
  28630. });
  28631. // create class for parent effects like merge
  28632. // Inherit from SVG.Parent
  28633. SVG.ParentEffect = SVG.invent({
  28634. create: function(){
  28635. this.constructor.call(this);
  28636. },
  28637. inherit: SVG.Parent,
  28638. extend: {
  28639. // Set in attribute
  28640. in: function(effect) {
  28641. return effect == null? this.parent() && this.parent().select('[result="'+this.attr('in')+'"]').get(0) || this.attr('in') : this.attr('in', effect)
  28642. },
  28643. // Named result
  28644. result: function(result) {
  28645. return result == null? this.attr('result') : this.attr('result',result)
  28646. },
  28647. // Stringification
  28648. toString: function() {
  28649. return this.result()
  28650. }
  28651. }
  28652. });
  28653. //chaining
  28654. var chainingEffects = {
  28655. // Blend effect
  28656. blend: function(in2, mode) {
  28657. return this.parent() && this.parent().blend(this, in2, mode) //pass this as the first input
  28658. },
  28659. // ColorMatrix effect
  28660. colorMatrix: function(type, values) {
  28661. return this.parent() && this.parent().colorMatrix(type, values).in(this)
  28662. },
  28663. // ConvolveMatrix effect
  28664. convolveMatrix: function(matrix) {
  28665. return this.parent() && this.parent().convolveMatrix(matrix).in(this)
  28666. },
  28667. // ComponentTransfer effect
  28668. componentTransfer: function(components) {
  28669. return this.parent() && this.parent().componentTransfer(components).in(this)
  28670. },
  28671. // Composite effect
  28672. composite: function(in2, operator) {
  28673. return this.parent() && this.parent().composite(this, in2, operator) //pass this as the first input
  28674. },
  28675. // Flood effect
  28676. flood: function(color, opacity) {
  28677. return this.parent() && this.parent().flood(color, opacity) //this effect dont have inputs
  28678. },
  28679. // Offset effect
  28680. offset: function(x, y) {
  28681. return this.parent() && this.parent().offset(x,y).in(this)
  28682. },
  28683. // Image effect
  28684. image: function(src) {
  28685. return this.parent() && this.parent().image(src) //this effect dont have inputs
  28686. },
  28687. // Merge effect
  28688. merge: function() {
  28689. return this.parent() && this.parent().merge.apply(this.parent(),[this].concat(arguments)) //pass this as the first argument
  28690. },
  28691. // Gaussian Blur effect
  28692. gaussianBlur: function(x,y) {
  28693. return this.parent() && this.parent().gaussianBlur(x,y).in(this)
  28694. },
  28695. // Morphology effect
  28696. morphology: function(operator,radius){
  28697. return this.parent() && this.parent().morphology(operator,radius).in(this)
  28698. },
  28699. // DiffuseLighting effect
  28700. diffuseLighting: function(surfaceScale,diffuseConstant,kernelUnitLength){
  28701. return this.parent() && this.parent().diffuseLighting(surfaceScale,diffuseConstant,kernelUnitLength).in(this)
  28702. },
  28703. // DisplacementMap effect
  28704. displacementMap: function(in2,scale,xChannelSelector,yChannelSelector){
  28705. return this.parent() && this.parent().displacementMap(this,in2,scale,xChannelSelector,yChannelSelector) //pass this as the first input
  28706. },
  28707. // SpecularLighting effect
  28708. specularLighting: function(surfaceScale,diffuseConstant,specularExponent,kernelUnitLength){
  28709. return this.parent() && this.parent().specularLighting(surfaceScale,diffuseConstant,specularExponent,kernelUnitLength).in(this)
  28710. },
  28711. // Tile effect
  28712. tile: function(){
  28713. return this.parent() && this.parent().tile().in(this)
  28714. },
  28715. // Turbulence effect
  28716. turbulence: function(baseFrequency,numOctaves,seed,stitchTiles,type){
  28717. return this.parent() && this.parent().turbulence(baseFrequency,numOctaves,seed,stitchTiles,type).in(this)
  28718. }
  28719. };
  28720. SVG.extend(SVG.Effect,chainingEffects);
  28721. SVG.extend(SVG.ParentEffect,chainingEffects);
  28722. //crea class for child effects, like MergeNode, FuncR and lights
  28723. SVG.ChildEffect = SVG.invent({
  28724. create: function(){
  28725. this.constructor.call(this);
  28726. },
  28727. inherit: SVG.Element,
  28728. extend: {
  28729. in: function(effect){
  28730. this.attr('in',effect);
  28731. }
  28732. //dont include any "result" functions because these types of nodes dont have them
  28733. }
  28734. });
  28735. // Create all different effects
  28736. var effects = {
  28737. blend: function(in1,in2,mode){
  28738. this.attr({
  28739. in: in1,
  28740. in2: in2,
  28741. mode: mode || 'normal'
  28742. });
  28743. },
  28744. colorMatrix: function(type,values){
  28745. if (type == 'matrix')
  28746. values = normaliseMatrix(values);
  28747. this.attr({
  28748. type: type
  28749. , values: typeof values == 'undefined' ? null : values
  28750. });
  28751. },
  28752. convolveMatrix: function(matrix){
  28753. matrix = normaliseMatrix(matrix);
  28754. this.attr({
  28755. order: Math.sqrt(matrix.split(' ').length)
  28756. , kernelMatrix: matrix
  28757. });
  28758. },
  28759. composite: function(in1, in2, operator){
  28760. this.attr({
  28761. in: in1,
  28762. in2: in2,
  28763. operator: operator
  28764. });
  28765. },
  28766. flood: function(color,opacity){
  28767. this.attr('flood-color',color);
  28768. if(opacity != null) this.attr('flood-opacity',opacity);
  28769. },
  28770. offset: function(x,y){
  28771. this.attr({
  28772. dx: x,
  28773. dy: y
  28774. });
  28775. },
  28776. image: function(src){
  28777. this.attr('href', src, SVG.xlink);
  28778. },
  28779. displacementMap: function(in1,in2,scale,xChannelSelector,yChannelSelector){
  28780. this.attr({
  28781. in: in1,
  28782. in2: in2,
  28783. scale: scale,
  28784. xChannelSelector: xChannelSelector,
  28785. yChannelSelector: yChannelSelector
  28786. });
  28787. },
  28788. gaussianBlur: function(x,y){
  28789. if(x != null || y != null)
  28790. this.attr('stdDeviation', listString(Array.prototype.slice.call(arguments)));
  28791. else
  28792. this.attr('stdDeviation', '0 0');
  28793. },
  28794. morphology: function(operator,radius){
  28795. this.attr({
  28796. operator: operator,
  28797. radius: radius
  28798. });
  28799. },
  28800. tile: function(){
  28801. },
  28802. turbulence: function(baseFrequency,numOctaves,seed,stitchTiles,type){
  28803. this.attr({
  28804. numOctaves: numOctaves,
  28805. seed: seed,
  28806. stitchTiles: stitchTiles,
  28807. baseFrequency: baseFrequency,
  28808. type: type
  28809. });
  28810. }
  28811. };
  28812. // Create all parent effects
  28813. var parentEffects = {
  28814. merge: function(){
  28815. var children;
  28816. //test to see if we have a set
  28817. if(arguments[0] instanceof SVG.Set){
  28818. var that = this;
  28819. arguments[0].each(function(i){
  28820. if(this instanceof SVG.MergeNode)
  28821. that.put(this);
  28822. else if(this instanceof SVG.Effect || this instanceof SVG.ParentEffect)
  28823. that.put(new SVG.MergeNode(this));
  28824. });
  28825. }
  28826. else {
  28827. //if the first argument is an array use it
  28828. if(Array.isArray(arguments[0]))
  28829. children = arguments[0];
  28830. else
  28831. children = arguments;
  28832. for(var i = 0; i < children.length; i++){
  28833. if(children[i] instanceof SVG.MergeNode){
  28834. this.put(children[i]);
  28835. }
  28836. else this.put(new SVG.MergeNode(children[i]));
  28837. }
  28838. }
  28839. },
  28840. componentTransfer: function(compontents){
  28841. /* create rgb set */
  28842. this.rgb = new SVG.Set
  28843. /* create components */
  28844. ;(['r', 'g', 'b', 'a']).forEach(function(c) {
  28845. /* create component */
  28846. this[c] = new SVG['Func' + c.toUpperCase()]('identity');
  28847. /* store component in set */
  28848. this.rgb.add(this[c]);
  28849. /* add component node */
  28850. this.node.appendChild(this[c].node);
  28851. }.bind(this)); //lost context in foreach
  28852. /* set components */
  28853. if (compontents) {
  28854. if (compontents.rgb) {
  28855. (['r', 'g', 'b']).forEach(function(c) {
  28856. this[c].attr(compontents.rgb);
  28857. }.bind(this));
  28858. delete compontents.rgb;
  28859. }
  28860. /* set individual components */
  28861. for (var c in compontents)
  28862. this[c].attr(compontents[c]);
  28863. }
  28864. },
  28865. diffuseLighting: function(surfaceScale,diffuseConstant,kernelUnitLength){
  28866. this.attr({
  28867. surfaceScale: surfaceScale,
  28868. diffuseConstant: diffuseConstant,
  28869. kernelUnitLength: kernelUnitLength
  28870. });
  28871. },
  28872. specularLighting: function(surfaceScale,diffuseConstant,specularExponent,kernelUnitLength){
  28873. this.attr({
  28874. surfaceScale: surfaceScale,
  28875. diffuseConstant: diffuseConstant,
  28876. specularExponent: specularExponent,
  28877. kernelUnitLength: kernelUnitLength
  28878. });
  28879. },
  28880. };
  28881. // Create child effects like PointLight and MergeNode
  28882. var childEffects = {
  28883. distantLight: function(azimuth, elevation){
  28884. this.attr({
  28885. azimuth: azimuth,
  28886. elevation: elevation
  28887. });
  28888. },
  28889. pointLight: function(x,y,z){
  28890. this.attr({
  28891. x: x,
  28892. y: y,
  28893. z: z
  28894. });
  28895. },
  28896. spotLight: function(x,y,z,pointsAtX,pointsAtY,pointsAtZ){
  28897. this.attr({
  28898. x: x,
  28899. y: y,
  28900. z: z,
  28901. pointsAtX: pointsAtX,
  28902. pointsAtY: pointsAtY,
  28903. pointsAtZ: pointsAtZ
  28904. });
  28905. },
  28906. mergeNode: function(in1){
  28907. this.attr('in',in1);
  28908. }
  28909. }
  28910. // Create compontent functions
  28911. ;(['r', 'g', 'b', 'a']).forEach(function(c) {
  28912. /* create class */
  28913. childEffects['Func' + c.toUpperCase()] = function(type) {
  28914. this.attr('type',type);
  28915. // take diffent arguments based on the type
  28916. switch(type){
  28917. case 'table':
  28918. this.attr('tableValues',arguments[1]);
  28919. break
  28920. case 'linear':
  28921. this.attr('slope',arguments[1]);
  28922. this.attr('intercept',arguments[2]);
  28923. break
  28924. case 'gamma':
  28925. this.attr('amplitude',arguments[1]);
  28926. this.attr('exponent',arguments[2]);
  28927. this.attr('offset',arguments[2]);
  28928. break
  28929. }
  28930. };
  28931. });
  28932. //create effects
  28933. foreach(effects,function(effect,i){
  28934. /* capitalize name */
  28935. var name = i.charAt(0).toUpperCase() + i.slice(1);
  28936. var proto = {};
  28937. /* create class */
  28938. SVG[name + 'Effect'] = SVG.invent({
  28939. create: function() {
  28940. //call super
  28941. this.constructor.call(this, SVG.create('fe' + name));
  28942. //call constructor for this effect
  28943. effect.apply(this,arguments);
  28944. //set the result
  28945. this.result(this.attr('id') + 'Out');
  28946. },
  28947. inherit: SVG.Effect,
  28948. extend: proto
  28949. });
  28950. });
  28951. //create parent effects
  28952. foreach(parentEffects,function(effect,i){
  28953. /* capitalize name */
  28954. var name = i.charAt(0).toUpperCase() + i.slice(1);
  28955. var proto = {};
  28956. /* create class */
  28957. SVG[name + 'Effect'] = SVG.invent({
  28958. create: function() {
  28959. //call super
  28960. this.constructor.call(this, SVG.create('fe' + name));
  28961. //call constructor for this effect
  28962. effect.apply(this,arguments);
  28963. //set the result
  28964. this.result(this.attr('id') + 'Out');
  28965. },
  28966. inherit: SVG.ParentEffect,
  28967. extend: proto
  28968. });
  28969. });
  28970. //create child effects
  28971. foreach(childEffects,function(effect,i){
  28972. /* capitalize name */
  28973. var name = i.charAt(0).toUpperCase() + i.slice(1);
  28974. var proto = {};
  28975. /* create class */
  28976. SVG[name] = SVG.invent({
  28977. create: function() {
  28978. //call super
  28979. this.constructor.call(this, SVG.create('fe' + name));
  28980. //call constructor for this effect
  28981. effect.apply(this,arguments);
  28982. },
  28983. inherit: SVG.ChildEffect,
  28984. extend: proto
  28985. });
  28986. });
  28987. // Effect-specific extensions
  28988. SVG.extend(SVG.MergeEffect,{
  28989. in: function(effect){
  28990. if(effect instanceof SVG.MergeNode)
  28991. this.add(effect,0);
  28992. else
  28993. this.add(new SVG.MergeNode(effect),0);
  28994. return this
  28995. }
  28996. });
  28997. SVG.extend(SVG.CompositeEffect,SVG.BlendEffect,SVG.DisplacementMapEffect,{
  28998. in2: function(effect){
  28999. return effect == null? this.parent() && this.parent().select('[result="'+this.attr('in2')+'"]').get(0) || this.attr('in2') : this.attr('in2', effect)
  29000. }
  29001. });
  29002. // Presets
  29003. SVG.filter = {
  29004. sepiatone: [ .343, .669, .119, 0, 0
  29005. , .249, .626, .130, 0, 0
  29006. , .172, .334, .111, 0, 0
  29007. , .000, .000, .000, 1, 0 ]
  29008. };
  29009. // Helpers
  29010. function normaliseMatrix(matrix) {
  29011. /* convert possible array value to string */
  29012. if (Array.isArray(matrix))
  29013. matrix = new SVG.Array(matrix);
  29014. /* ensure there are no leading, tailing or double spaces */
  29015. return matrix.toString().replace(/^\s+/, '').replace(/\s+$/, '').replace(/\s+/g, ' ')
  29016. }
  29017. function listString(list) {
  29018. if (!Array.isArray(list))
  29019. return list
  29020. for (var i = 0, l = list.length, s = []; i < l; i++)
  29021. s.push(list[i]);
  29022. return s.join(' ')
  29023. }
  29024. function foreach(){ //loops through mutiple objects
  29025. var fn = function(){};
  29026. if(typeof arguments[arguments.length-1] == 'function'){
  29027. fn = arguments[arguments.length-1];
  29028. Array.prototype.splice.call(arguments,arguments.length-1,1);
  29029. }
  29030. for(var k in arguments){
  29031. for(var i in arguments[k]){
  29032. fn(arguments[k][i],i,arguments[k]);
  29033. }
  29034. }
  29035. }
  29036. }).call(undefined);
  29037. (function() {
  29038. SVG.extend(SVG.PathArray, {
  29039. morph: function(array) {
  29040. var startArr = this.value
  29041. , destArr = this.parse(array);
  29042. var startOffsetM = 0
  29043. , destOffsetM = 0;
  29044. var startOffsetNextM = false
  29045. , destOffsetNextM = false;
  29046. while(true){
  29047. // stop if there is no M anymore
  29048. if(startOffsetM === false && destOffsetM === false) break
  29049. // find the next M in path array
  29050. startOffsetNextM = findNextM(startArr, startOffsetM === false ? false : startOffsetM+1);
  29051. destOffsetNextM = findNextM( destArr, destOffsetM === false ? false : destOffsetM+1);
  29052. // We have to add one M to the startArray
  29053. if(startOffsetM === false){
  29054. var bbox = new SVG.PathArray(result.start).bbox();
  29055. // when the last block had no bounding box we simply take the first M we got
  29056. if(bbox.height == 0 || bbox.width == 0){
  29057. startOffsetM = startArr.push(startArr[0]) - 1;
  29058. }else {
  29059. // we take the middle of the bbox instead when we got one
  29060. startOffsetM = startArr.push( ['M', bbox.x + bbox.width/2, bbox.y + bbox.height/2 ] ) - 1;
  29061. }
  29062. }
  29063. // We have to add one M to the destArray
  29064. if( destOffsetM === false){
  29065. var bbox = new SVG.PathArray(result.dest).bbox();
  29066. if(bbox.height == 0 || bbox.width == 0){
  29067. destOffsetM = destArr.push(destArr[0]) - 1;
  29068. }else {
  29069. destOffsetM = destArr.push( ['M', bbox.x + bbox.width/2, bbox.y + bbox.height/2 ] ) - 1;
  29070. }
  29071. }
  29072. // handle block from M to next M
  29073. var result = handleBlock(startArr, startOffsetM, startOffsetNextM, destArr, destOffsetM, destOffsetNextM);
  29074. // update the arrays to their new values
  29075. startArr = startArr.slice(0, startOffsetM).concat(result.start, startOffsetNextM === false ? [] : startArr.slice(startOffsetNextM));
  29076. destArr = destArr.slice(0, destOffsetM).concat(result.dest , destOffsetNextM === false ? [] : destArr.slice( destOffsetNextM));
  29077. // update offsets
  29078. startOffsetM = startOffsetNextM === false ? false : startOffsetM + result.start.length;
  29079. destOffsetM = destOffsetNextM === false ? false : destOffsetM + result.dest.length;
  29080. }
  29081. // copy back arrays
  29082. this.value = startArr;
  29083. this.destination = new SVG.PathArray();
  29084. this.destination.value = destArr;
  29085. return this
  29086. }
  29087. });
  29088. // sorry for the long declaration
  29089. // slices out one block (from M to M) and syncronize it so the types and length match
  29090. function handleBlock(startArr, startOffsetM, startOffsetNextM, destArr, destOffsetM, destOffsetNextM, undefined$1){
  29091. // slice out the block we need
  29092. var startArrTemp = startArr.slice(startOffsetM, startOffsetNextM || undefined$1)
  29093. , destArrTemp = destArr.slice( destOffsetM, destOffsetNextM || undefined$1);
  29094. var i = 0
  29095. , posStart = {pos:[0,0], start:[0,0]}
  29096. , posDest = {pos:[0,0], start:[0,0]};
  29097. do{
  29098. // convert shorthand types to long form
  29099. startArrTemp[i] = simplyfy.call(posStart, startArrTemp[i]);
  29100. destArrTemp[i] = simplyfy.call(posDest , destArrTemp[i]);
  29101. // check if both shape types match
  29102. // 2 elliptical arc curve commands ('A'), are considered different if the
  29103. // flags (large-arc-flag, sweep-flag) don't match
  29104. if(startArrTemp[i][0] != destArrTemp[i][0] || startArrTemp[i][0] == 'M' ||
  29105. (startArrTemp[i][0] == 'A' &&
  29106. (startArrTemp[i][4] != destArrTemp[i][4] || startArrTemp[i][5] != destArrTemp[i][5])
  29107. )
  29108. ) {
  29109. // if not, convert shapes to beziere
  29110. Array.prototype.splice.apply(startArrTemp, [i, 1].concat(toBeziere.call(posStart, startArrTemp[i])));
  29111. Array.prototype.splice.apply(destArrTemp, [i, 1].concat(toBeziere.call(posDest, destArrTemp[i])));
  29112. } else {
  29113. // only update positions otherwise
  29114. startArrTemp[i] = setPosAndReflection.call(posStart, startArrTemp[i]);
  29115. destArrTemp[i] = setPosAndReflection.call(posDest , destArrTemp[i]);
  29116. }
  29117. // we are at the end at both arrays. stop here
  29118. if(++i == startArrTemp.length && i == destArrTemp.length) break
  29119. // destArray is longer. Add one element
  29120. if(i == startArrTemp.length){
  29121. startArrTemp.push([
  29122. 'C',
  29123. posStart.pos[0],
  29124. posStart.pos[1],
  29125. posStart.pos[0],
  29126. posStart.pos[1],
  29127. posStart.pos[0],
  29128. posStart.pos[1],
  29129. ]);
  29130. }
  29131. // startArr is longer. Add one element
  29132. if(i == destArrTemp.length){
  29133. destArrTemp.push([
  29134. 'C',
  29135. posDest.pos[0],
  29136. posDest.pos[1],
  29137. posDest.pos[0],
  29138. posDest.pos[1],
  29139. posDest.pos[0],
  29140. posDest.pos[1]
  29141. ]);
  29142. }
  29143. }while(true)
  29144. // return the updated block
  29145. return {start:startArrTemp, dest:destArrTemp}
  29146. }
  29147. // converts shorthand types to long form
  29148. function simplyfy(val){
  29149. switch(val[0]){
  29150. case 'z': // shorthand line to start
  29151. case 'Z':
  29152. val[0] = 'L';
  29153. val[1] = this.start[0];
  29154. val[2] = this.start[1];
  29155. break
  29156. case 'H': // shorthand horizontal line
  29157. val[0] = 'L';
  29158. val[2] = this.pos[1];
  29159. break
  29160. case 'V': // shorthand vertical line
  29161. val[0] = 'L';
  29162. val[2] = val[1];
  29163. val[1] = this.pos[0];
  29164. break
  29165. case 'T': // shorthand quadratic beziere
  29166. val[0] = 'Q';
  29167. val[3] = val[1];
  29168. val[4] = val[2];
  29169. val[1] = this.reflection[1];
  29170. val[2] = this.reflection[0];
  29171. break
  29172. case 'S': // shorthand cubic beziere
  29173. val[0] = 'C';
  29174. val[6] = val[4];
  29175. val[5] = val[3];
  29176. val[4] = val[2];
  29177. val[3] = val[1];
  29178. val[2] = this.reflection[1];
  29179. val[1] = this.reflection[0];
  29180. break
  29181. }
  29182. return val
  29183. }
  29184. // updates reflection point and current position
  29185. function setPosAndReflection(val){
  29186. var len = val.length;
  29187. this.pos = [ val[len-2], val[len-1] ];
  29188. if('SCQT'.indexOf(val[0]) != -1)
  29189. this.reflection = [ 2 * this.pos[0] - val[len-4], 2 * this.pos[1] - val[len-3] ];
  29190. return val
  29191. }
  29192. // converts all types to cubic beziere
  29193. function toBeziere(val){
  29194. var retVal = [val];
  29195. switch(val[0]){
  29196. case 'M': // special handling for M
  29197. this.pos = this.start = [val[1], val[2]];
  29198. return retVal
  29199. case 'L':
  29200. val[5] = val[3] = val[1];
  29201. val[6] = val[4] = val[2];
  29202. val[1] = this.pos[0];
  29203. val[2] = this.pos[1];
  29204. break
  29205. case 'Q':
  29206. val[6] = val[4];
  29207. val[5] = val[3];
  29208. val[4] = val[4] * 1/3 + val[2] * 2/3;
  29209. val[3] = val[3] * 1/3 + val[1] * 2/3;
  29210. val[2] = this.pos[1] * 1/3 + val[2] * 2/3;
  29211. val[1] = this.pos[0] * 1/3 + val[1] * 2/3;
  29212. break
  29213. case 'A':
  29214. retVal = arcToBeziere(this.pos, val);
  29215. val = retVal[0];
  29216. break
  29217. }
  29218. val[0] = 'C';
  29219. this.pos = [val[5], val[6]];
  29220. this.reflection = [2 * val[5] - val[3], 2 * val[6] - val[4]];
  29221. return retVal
  29222. }
  29223. // finds the next position of type M
  29224. function findNextM(arr, offset){
  29225. if(offset === false) return false
  29226. for(var i = offset, len = arr.length;i < len;++i){
  29227. if(arr[i][0] == 'M') return i
  29228. }
  29229. return false
  29230. }
  29231. // Convert an arc segment into equivalent cubic Bezier curves
  29232. // Depending on the arc, up to 4 curves might be used to represent it since a
  29233. // curve gives a good approximation for only a quarter of an ellipse
  29234. // The curves are returned as an array of SVG curve commands:
  29235. // [ ['C', x1, y1, x2, y2, x, y] ... ]
  29236. function arcToBeziere(pos, val) {
  29237. // Parameters extraction, handle out-of-range parameters as specified in the SVG spec
  29238. // See: https://www.w3.org/TR/SVG11/implnote.html#ArcOutOfRangeParameters
  29239. var rx = Math.abs(val[1]), ry = Math.abs(val[2]), xAxisRotation = val[3] % 360
  29240. , largeArcFlag = val[4], sweepFlag = val[5], x = val[6], y = val[7]
  29241. , A = new SVG.Point(pos), B = new SVG.Point(x, y)
  29242. , primedCoord, lambda, mat, k, c, cSquare, t, O, OA, OB, tetaStart, tetaEnd
  29243. , deltaTeta, nbSectors, f, arcSegPoints, angle, sinAngle, cosAngle, pt, i, il
  29244. , retVal = [], x1, y1, x2, y2;
  29245. // Ensure radii are non-zero
  29246. if(rx === 0 || ry === 0 || (A.x === B.x && A.y === B.y)) {
  29247. // treat this arc as a straight line segment
  29248. return [['C', A.x, A.y, B.x, B.y, B.x, B.y]]
  29249. }
  29250. // Ensure radii are large enough using the algorithm provided in the SVG spec
  29251. // See: https://www.w3.org/TR/SVG11/implnote.html#ArcCorrectionOutOfRangeRadii
  29252. primedCoord = new SVG.Point((A.x-B.x)/2, (A.y-B.y)/2).transform(new SVG.Matrix().rotate(xAxisRotation));
  29253. lambda = (primedCoord.x * primedCoord.x) / (rx * rx) + (primedCoord.y * primedCoord.y) / (ry * ry);
  29254. if(lambda > 1) {
  29255. lambda = Math.sqrt(lambda);
  29256. rx = lambda*rx;
  29257. ry = lambda*ry;
  29258. }
  29259. // To simplify calculations, we make the arc part of a unit circle (rayon is 1) instead of an ellipse
  29260. mat = new SVG.Matrix().rotate(xAxisRotation).scale(1/rx, 1/ry).rotate(-xAxisRotation);
  29261. A = A.transform(mat);
  29262. B = B.transform(mat);
  29263. // Calculate the horizontal and vertical distance between the initial and final point of the arc
  29264. k = [B.x-A.x, B.y-A.y];
  29265. // Find the length of the chord formed by A and B
  29266. cSquare = k[0]*k[0] + k[1]*k[1];
  29267. c = Math.sqrt(cSquare);
  29268. // Calculate the ratios of the horizontal and vertical distance on the length of the chord
  29269. k[0] /= c;
  29270. k[1] /= c;
  29271. // Calculate the distance between the circle center and the chord midpoint
  29272. // using this formula: t = sqrt(r^2 - c^2 / 4)
  29273. // where t is the distance between the cirle center and the chord midpoint,
  29274. // r is the rayon of the circle and c is the chord length
  29275. // From: http://www.ajdesigner.com/phpcircle/circle_segment_chord_t.php
  29276. // Because of the imprecision of floating point numbers, cSquare might end
  29277. // up being slightly above 4 which would result in a negative radicand
  29278. // To prevent that, a test is made before computing the square root
  29279. t = (cSquare < 4) ? Math.sqrt(1 - cSquare/4) : 0;
  29280. // For most situations, there are actually two different ellipses that
  29281. // satisfy the constraints imposed by the points A and B, the radii rx and ry,
  29282. // and the xAxisRotation
  29283. // When the flags largeArcFlag and sweepFlag are equal, it means that the
  29284. // second ellipse is used as a solution
  29285. // See: https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
  29286. if(largeArcFlag === sweepFlag) {
  29287. t *= -1;
  29288. }
  29289. // Calculate the coordinates of the center of the circle from the midpoint of the chord
  29290. // This is done by multiplying the ratios calculated previously by the distance between
  29291. // the circle center and the chord midpoint and using these values to go from the midpoint
  29292. // to the center of the circle
  29293. // The negative of the vertical distance ratio is used to modify the x coordinate while
  29294. // the horizontal distance ratio is used to modify the y coordinate
  29295. // That is because the center of the circle is perpendicular to the chord and perpendicular
  29296. // lines are negative reciprocals
  29297. O = new SVG.Point((B.x+A.x)/2 + t*-k[1], (B.y+A.y)/2 + t*k[0]);
  29298. // Move the center of the circle at the origin
  29299. OA = new SVG.Point(A.x-O.x, A.y-O.y);
  29300. OB = new SVG.Point(B.x-O.x, B.y-O.y);
  29301. // Calculate the start and end angle
  29302. tetaStart = Math.acos(OA.x/Math.sqrt(OA.x*OA.x + OA.y*OA.y));
  29303. if (OA.y < 0) {
  29304. tetaStart *= -1;
  29305. }
  29306. tetaEnd = Math.acos(OB.x/Math.sqrt(OB.x*OB.x + OB.y*OB.y));
  29307. if (OB.y < 0) {
  29308. tetaEnd *= -1;
  29309. }
  29310. // If sweep-flag is '1', then the arc will be drawn in a "positive-angle" direction,
  29311. // make sure that the end angle is above the start angle
  29312. if (sweepFlag && tetaStart > tetaEnd) {
  29313. tetaEnd += 2*Math.PI;
  29314. }
  29315. // If sweep-flag is '0', then the arc will be drawn in a "negative-angle" direction,
  29316. // make sure that the end angle is below the start angle
  29317. if (!sweepFlag && tetaStart < tetaEnd) {
  29318. tetaEnd -= 2*Math.PI;
  29319. }
  29320. // Find the number of Bezier curves that are required to represent the arc
  29321. // A cubic Bezier curve gives a good enough approximation when representing at most a quarter of a circle
  29322. nbSectors = Math.ceil(Math.abs(tetaStart-tetaEnd) * 2/Math.PI);
  29323. // Calculate the coordinates of the points of all the Bezier curves required to represent the arc
  29324. // For an in-depth explanation of this part see: http://pomax.github.io/bezierinfo/#circles_cubic
  29325. arcSegPoints = [];
  29326. angle = tetaStart;
  29327. deltaTeta = (tetaEnd-tetaStart)/nbSectors;
  29328. f = 4*Math.tan(deltaTeta/4)/3;
  29329. for (i = 0; i <= nbSectors; i++) { // The <= is because a Bezier curve have a start and a endpoint
  29330. cosAngle = Math.cos(angle);
  29331. sinAngle = Math.sin(angle);
  29332. pt = new SVG.Point(O.x+cosAngle, O.y+sinAngle);
  29333. arcSegPoints[i] = [new SVG.Point(pt.x+f*sinAngle, pt.y-f*cosAngle), pt, new SVG.Point(pt.x-f*sinAngle, pt.y+f*cosAngle)];
  29334. angle += deltaTeta;
  29335. }
  29336. // Remove the first control point of the first segment point and remove the second control point of the last segment point
  29337. // These two control points are not used in the approximation of the arc, that is why they are removed
  29338. arcSegPoints[0][0] = arcSegPoints[0][1].clone();
  29339. arcSegPoints[arcSegPoints.length-1][2] = arcSegPoints[arcSegPoints.length-1][1].clone();
  29340. // Revert the transformation that was applied to make the arc part of a unit circle instead of an ellipse
  29341. mat = new SVG.Matrix().rotate(xAxisRotation).scale(rx, ry).rotate(-xAxisRotation);
  29342. for (i = 0, il = arcSegPoints.length; i < il; i++) {
  29343. arcSegPoints[i][0] = arcSegPoints[i][0].transform(mat);
  29344. arcSegPoints[i][1] = arcSegPoints[i][1].transform(mat);
  29345. arcSegPoints[i][2] = arcSegPoints[i][2].transform(mat);
  29346. }
  29347. // Convert the segments points to SVG curve commands
  29348. for (i = 1, il = arcSegPoints.length; i < il; i++) {
  29349. pt = arcSegPoints[i-1][2];
  29350. x1 = pt.x;
  29351. y1 = pt.y;
  29352. pt = arcSegPoints[i][0];
  29353. x2 = pt.x;
  29354. y2 = pt.y;
  29355. pt = arcSegPoints[i][1];
  29356. x = pt.x;
  29357. y = pt.y;
  29358. retVal.push(['C', x1, y1, x2, y2, x, y]);
  29359. }
  29360. return retVal
  29361. }
  29362. }());
  29363. /*! svg.draggable.js - v2.2.2 - 2019-01-08
  29364. * https://github.com/svgdotjs/svg.draggable.js
  29365. * Copyright (c) 2019 Wout Fierens; Licensed MIT */
  29366. (function() {
  29367. // creates handler, saves it
  29368. function DragHandler(el){
  29369. el.remember('_draggable', this);
  29370. this.el = el;
  29371. }
  29372. // Sets new parameter, starts dragging
  29373. DragHandler.prototype.init = function(constraint, val){
  29374. var _this = this;
  29375. this.constraint = constraint;
  29376. this.value = val;
  29377. this.el.on('mousedown.drag', function(e){ _this.start(e); });
  29378. this.el.on('touchstart.drag', function(e){ _this.start(e); });
  29379. };
  29380. // transforms one point from screen to user coords
  29381. DragHandler.prototype.transformPoint = function(event, offset){
  29382. event = event || window.event;
  29383. var touches = event.changedTouches && event.changedTouches[0] || event;
  29384. this.p.x = touches.clientX - (offset || 0);
  29385. this.p.y = touches.clientY;
  29386. return this.p.matrixTransform(this.m)
  29387. };
  29388. // gets elements bounding box with special handling of groups, nested and use
  29389. DragHandler.prototype.getBBox = function(){
  29390. var box = this.el.bbox();
  29391. if(this.el instanceof SVG.Nested) box = this.el.rbox();
  29392. if (this.el instanceof SVG.G || this.el instanceof SVG.Use || this.el instanceof SVG.Nested) {
  29393. box.x = this.el.x();
  29394. box.y = this.el.y();
  29395. }
  29396. return box
  29397. };
  29398. // start dragging
  29399. DragHandler.prototype.start = function(e){
  29400. // check for left button
  29401. if(e.type == 'click'|| e.type == 'mousedown' || e.type == 'mousemove'){
  29402. if((e.which || e.buttons) != 1){
  29403. return
  29404. }
  29405. }
  29406. var _this = this;
  29407. // fire beforedrag event
  29408. this.el.fire('beforedrag', { event: e, handler: this });
  29409. if(this.el.event().defaultPrevented) return;
  29410. // prevent browser drag behavior as soon as possible
  29411. e.preventDefault();
  29412. // prevent propagation to a parent that might also have dragging enabled
  29413. e.stopPropagation();
  29414. // search for parent on the fly to make sure we can call
  29415. // draggable() even when element is not in the dom currently
  29416. this.parent = this.parent || this.el.parent(SVG.Nested) || this.el.parent(SVG.Doc);
  29417. this.p = this.parent.node.createSVGPoint();
  29418. // save current transformation matrix
  29419. this.m = this.el.node.getScreenCTM().inverse();
  29420. var box = this.getBBox();
  29421. var anchorOffset;
  29422. // fix text-anchor in text-element (#37)
  29423. if(this.el instanceof SVG.Text){
  29424. anchorOffset = this.el.node.getComputedTextLength();
  29425. switch(this.el.attr('text-anchor')){
  29426. case 'middle':
  29427. anchorOffset /= 2;
  29428. break
  29429. case 'start':
  29430. anchorOffset = 0;
  29431. break;
  29432. }
  29433. }
  29434. this.startPoints = {
  29435. // We take absolute coordinates since we are just using a delta here
  29436. point: this.transformPoint(e, anchorOffset),
  29437. box: box,
  29438. transform: this.el.transform()
  29439. };
  29440. // add drag and end events to window
  29441. SVG.on(window, 'mousemove.drag', function(e){ _this.drag(e); });
  29442. SVG.on(window, 'touchmove.drag', function(e){ _this.drag(e); });
  29443. SVG.on(window, 'mouseup.drag', function(e){ _this.end(e); });
  29444. SVG.on(window, 'touchend.drag', function(e){ _this.end(e); });
  29445. // fire dragstart event
  29446. this.el.fire('dragstart', {event: e, p: this.startPoints.point, m: this.m, handler: this});
  29447. };
  29448. // while dragging
  29449. DragHandler.prototype.drag = function(e){
  29450. var box = this.getBBox()
  29451. , p = this.transformPoint(e)
  29452. , x = this.startPoints.box.x + p.x - this.startPoints.point.x
  29453. , y = this.startPoints.box.y + p.y - this.startPoints.point.y
  29454. , c = this.constraint
  29455. , gx = p.x - this.startPoints.point.x
  29456. , gy = p.y - this.startPoints.point.y;
  29457. this.el.fire('dragmove', {
  29458. event: e
  29459. , p: p
  29460. , m: this.m
  29461. , handler: this
  29462. });
  29463. if(this.el.event().defaultPrevented) return p
  29464. // move the element to its new position, if possible by constraint
  29465. if (typeof c == 'function') {
  29466. var coord = c.call(this.el, x, y, this.m);
  29467. // bool, just show us if movement is allowed or not
  29468. if (typeof coord == 'boolean') {
  29469. coord = {
  29470. x: coord,
  29471. y: coord
  29472. };
  29473. }
  29474. // if true, we just move. If !false its a number and we move it there
  29475. if (coord.x === true) {
  29476. this.el.x(x);
  29477. } else if (coord.x !== false) {
  29478. this.el.x(coord.x);
  29479. }
  29480. if (coord.y === true) {
  29481. this.el.y(y);
  29482. } else if (coord.y !== false) {
  29483. this.el.y(coord.y);
  29484. }
  29485. } else if (typeof c == 'object') {
  29486. // keep element within constrained box
  29487. if (c.minX != null && x < c.minX) {
  29488. x = c.minX;
  29489. gx = x - this.startPoints.box.x;
  29490. } else if (c.maxX != null && x > c.maxX - box.width) {
  29491. x = c.maxX - box.width;
  29492. gx = x - this.startPoints.box.x;
  29493. } if (c.minY != null && y < c.minY) {
  29494. y = c.minY;
  29495. gy = y - this.startPoints.box.y;
  29496. } else if (c.maxY != null && y > c.maxY - box.height) {
  29497. y = c.maxY - box.height;
  29498. gy = y - this.startPoints.box.y;
  29499. }
  29500. if (c.snapToGrid != null) {
  29501. x = x - (x % c.snapToGrid);
  29502. y = y - (y % c.snapToGrid);
  29503. gx = gx - (gx % c.snapToGrid);
  29504. gy = gy - (gy % c.snapToGrid);
  29505. }
  29506. if(this.el instanceof SVG.G)
  29507. this.el.matrix(this.startPoints.transform).transform({x:gx, y: gy}, true);
  29508. else
  29509. this.el.move(x, y);
  29510. }
  29511. // so we can use it in the end-method, too
  29512. return p
  29513. };
  29514. DragHandler.prototype.end = function(e){
  29515. // final drag
  29516. var p = this.drag(e);
  29517. // fire dragend event
  29518. this.el.fire('dragend', { event: e, p: p, m: this.m, handler: this });
  29519. // unbind events
  29520. SVG.off(window, 'mousemove.drag');
  29521. SVG.off(window, 'touchmove.drag');
  29522. SVG.off(window, 'mouseup.drag');
  29523. SVG.off(window, 'touchend.drag');
  29524. };
  29525. SVG.extend(SVG.Element, {
  29526. // Make element draggable
  29527. // Constraint might be an object (as described in readme.md) or a function in the form "function (x, y)" that gets called before every move.
  29528. // The function can return a boolean or an object of the form {x, y}, to which the element will be moved. "False" skips moving, true moves to raw x, y.
  29529. draggable: function(value, constraint) {
  29530. // Check the parameters and reassign if needed
  29531. if (typeof value == 'function' || typeof value == 'object') {
  29532. constraint = value;
  29533. value = true;
  29534. }
  29535. var dragHandler = this.remember('_draggable') || new DragHandler(this);
  29536. // When no parameter is given, value is true
  29537. value = typeof value === 'undefined' ? true : value;
  29538. if(value) dragHandler.init(constraint || {}, value);
  29539. else {
  29540. this.off('mousedown.drag');
  29541. this.off('touchstart.drag');
  29542. }
  29543. return this
  29544. }
  29545. });
  29546. }).call(undefined);
  29547. (function() {
  29548. function SelectHandler(el) {
  29549. this.el = el;
  29550. el.remember('_selectHandler', this);
  29551. this.pointSelection = {isSelected: false};
  29552. this.rectSelection = {isSelected: false};
  29553. // helper list with position settings of each type of point
  29554. this.pointsList = {
  29555. lt: [ 0, 0 ],
  29556. rt: [ 'width', 0 ],
  29557. rb: [ 'width', 'height' ],
  29558. lb: [ 0, 'height' ],
  29559. t: [ 'width', 0 ],
  29560. r: [ 'width', 'height' ],
  29561. b: [ 'width', 'height' ],
  29562. l: [ 0, 'height' ]
  29563. };
  29564. // helper function to get point coordinates based on settings above and an object (bbox in our case)
  29565. this.pointCoord = function (setting, object, isPointCentered) {
  29566. var coord = typeof setting !== 'string' ? setting : object[setting];
  29567. // Top, bottom, right and left points are placed in the center of element width/height
  29568. return isPointCentered ? coord / 2 : coord
  29569. };
  29570. this.pointCoords = function (point, object) {
  29571. var settings = this.pointsList[point];
  29572. return {
  29573. x: this.pointCoord(settings[0], object, (point === 't' || point === 'b')),
  29574. y: this.pointCoord(settings[1], object, (point === 'r' || point === 'l'))
  29575. }
  29576. };
  29577. }
  29578. SelectHandler.prototype.init = function (value, options) {
  29579. var bbox = this.el.bbox();
  29580. this.options = {};
  29581. // store defaults list of points in order to verify users config
  29582. var points = this.el.selectize.defaults.points;
  29583. // Merging the defaults and the options-object together
  29584. for (var i in this.el.selectize.defaults) {
  29585. this.options[i] = this.el.selectize.defaults[i];
  29586. if (options[i] !== undefined) {
  29587. this.options[i] = options[i];
  29588. }
  29589. }
  29590. // prepare & validate list of points to be added (or excluded)
  29591. var pointsLists = ['points', 'pointsExclude'];
  29592. for (var i in pointsLists) {
  29593. var option = this.options[pointsLists[i]];
  29594. if (typeof option === 'string') {
  29595. if (option.length > 0) {
  29596. // if set as comma separated string list => convert it into an array
  29597. option = option.split(/\s*,\s*/i);
  29598. } else {
  29599. option = [];
  29600. }
  29601. } else if (typeof option === 'boolean' && pointsLists[i] === 'points') {
  29602. // this is not needed, but let's have it for legacy support
  29603. option = option ? points : [];
  29604. }
  29605. this.options[pointsLists[i]] = option;
  29606. }
  29607. // intersect correct all points options with users config (exclude unwanted points)
  29608. // ES5 -> NO arrow functions nor Array.includes()
  29609. this.options.points = [ points, this.options.points ].reduce(
  29610. function (a, b) {
  29611. return a.filter(
  29612. function (c) {
  29613. return b.indexOf(c) > -1;
  29614. }
  29615. )
  29616. }
  29617. );
  29618. // exclude pointsExclude, if wanted
  29619. this.options.points = [ this.options.points, this.options.pointsExclude ].reduce(
  29620. function (a, b) {
  29621. return a.filter(
  29622. function (c) {
  29623. return b.indexOf(c) < 0;
  29624. }
  29625. )
  29626. }
  29627. );
  29628. this.parent = this.el.parent();
  29629. this.nested = (this.nested || this.parent.group());
  29630. this.nested.matrix(new SVG.Matrix(this.el).translate(bbox.x, bbox.y));
  29631. // When deepSelect is enabled and the element is a line/polyline/polygon, draw only points for moving
  29632. if (this.options.deepSelect && ['line', 'polyline', 'polygon'].indexOf(this.el.type) !== -1) {
  29633. this.selectPoints(value);
  29634. } else {
  29635. this.selectRect(value);
  29636. }
  29637. this.observe();
  29638. this.cleanup();
  29639. };
  29640. SelectHandler.prototype.selectPoints = function (value) {
  29641. this.pointSelection.isSelected = value;
  29642. // When set is already there we dont have to create one
  29643. if (this.pointSelection.set) {
  29644. return this;
  29645. }
  29646. // Create our set of elements
  29647. this.pointSelection.set = this.parent.set();
  29648. // draw the points and mark the element as selected
  29649. this.drawPoints();
  29650. return this;
  29651. };
  29652. // create the point-array which contains the 2 points of a line or simply the points-array of polyline/polygon
  29653. SelectHandler.prototype.getPointArray = function () {
  29654. var bbox = this.el.bbox();
  29655. return this.el.array().valueOf().map(function (el) {
  29656. return [el[0] - bbox.x, el[1] - bbox.y];
  29657. });
  29658. };
  29659. // Draws a points
  29660. SelectHandler.prototype.drawPoints = function () {
  29661. var _this = this, array = this.getPointArray();
  29662. // go through the array of points
  29663. for (var i = 0, len = array.length; i < len; ++i) {
  29664. var curriedEvent = (function (k) {
  29665. return function (ev) {
  29666. ev = ev || window.event;
  29667. ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
  29668. ev.stopPropagation();
  29669. var x = ev.pageX || ev.touches[0].pageX;
  29670. var y = ev.pageY || ev.touches[0].pageY;
  29671. _this.el.fire('point', {x: x, y: y, i: k, event: ev});
  29672. };
  29673. })(i);
  29674. // add every point to the set
  29675. // add css-classes and a touchstart-event which fires our event for moving points
  29676. var point = this.drawPoint(array[i][0], array[i][1])
  29677. .addClass(this.options.classPoints)
  29678. .addClass(this.options.classPoints + '_point')
  29679. .on('touchstart', curriedEvent)
  29680. .on('mousedown', curriedEvent);
  29681. this.pointSelection.set.add(point);
  29682. }
  29683. };
  29684. // The function to draw single point
  29685. SelectHandler.prototype.drawPoint = function (cx, cy) {
  29686. var pointType = this.options.pointType;
  29687. switch (pointType) {
  29688. case 'circle':
  29689. return this.drawCircle(cx, cy);
  29690. case 'rect':
  29691. return this.drawRect(cx, cy);
  29692. default:
  29693. if (typeof pointType === 'function') {
  29694. return pointType.call(this, cx, cy);
  29695. }
  29696. throw new Error('Unknown ' + pointType + ' point type!');
  29697. }
  29698. };
  29699. // The function to draw the circle point
  29700. SelectHandler.prototype.drawCircle = function (cx, cy) {
  29701. return this.nested.circle(this.options.pointSize)
  29702. .center(cx, cy);
  29703. };
  29704. // The function to draw the rect point
  29705. SelectHandler.prototype.drawRect = function (cx, cy) {
  29706. return this.nested.rect(this.options.pointSize, this.options.pointSize)
  29707. .center(cx, cy);
  29708. };
  29709. // every time a point is moved, we have to update the positions of our point
  29710. SelectHandler.prototype.updatePointSelection = function () {
  29711. var array = this.getPointArray();
  29712. this.pointSelection.set.each(function (i) {
  29713. if (this.cx() === array[i][0] && this.cy() === array[i][1]) {
  29714. return;
  29715. }
  29716. this.center(array[i][0], array[i][1]);
  29717. });
  29718. };
  29719. SelectHandler.prototype.updateRectSelection = function () {
  29720. var _this = this, bbox = this.el.bbox();
  29721. this.rectSelection.set.get(0).attr({
  29722. width: bbox.width,
  29723. height: bbox.height
  29724. });
  29725. // set.get(1) is always in the upper left corner. no need to move it
  29726. if (this.options.points.length) {
  29727. this.options.points.map(function (point, index) {
  29728. var coords = _this.pointCoords(point, bbox);
  29729. _this.rectSelection.set.get(index + 1).center(coords.x, coords.y);
  29730. });
  29731. }
  29732. if (this.options.rotationPoint) {
  29733. var length = this.rectSelection.set.length();
  29734. this.rectSelection.set.get(length - 1).center(bbox.width / 2, 20);
  29735. }
  29736. };
  29737. SelectHandler.prototype.selectRect = function (value) {
  29738. var _this = this, bbox = this.el.bbox();
  29739. this.rectSelection.isSelected = value;
  29740. // when set is already p
  29741. this.rectSelection.set = this.rectSelection.set || this.parent.set();
  29742. // helperFunction to create a mouse-down function which triggers the event specified in `eventName`
  29743. function getMoseDownFunc(eventName) {
  29744. return function (ev) {
  29745. ev = ev || window.event;
  29746. ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
  29747. ev.stopPropagation();
  29748. var x = ev.pageX || ev.touches[0].pageX;
  29749. var y = ev.pageY || ev.touches[0].pageY;
  29750. _this.el.fire(eventName, {x: x, y: y, event: ev});
  29751. };
  29752. }
  29753. // create the selection-rectangle and add the css-class
  29754. if (!this.rectSelection.set.get(0)) {
  29755. this.rectSelection.set.add(this.nested.rect(bbox.width, bbox.height).addClass(this.options.classRect));
  29756. }
  29757. // Draw Points at the edges, if enabled
  29758. if (this.options.points.length && this.rectSelection.set.length() < 2) {
  29759. var ename ="touchstart", mname = "mousedown";
  29760. this.options.points.map(function (point, index) {
  29761. var coords = _this.pointCoords(point, bbox);
  29762. var pointElement = _this.drawPoint(coords.x, coords.y)
  29763. .attr('class', _this.options.classPoints + '_' + point)
  29764. .on(mname, getMoseDownFunc(point))
  29765. .on(ename, getMoseDownFunc(point));
  29766. _this.rectSelection.set.add(pointElement);
  29767. });
  29768. this.rectSelection.set.each(function () {
  29769. this.addClass(_this.options.classPoints);
  29770. });
  29771. }
  29772. // draw rotationPint, if enabled
  29773. if (this.options.rotationPoint && ((this.options.points && !this.rectSelection.set.get(9)) || (!this.options.points && !this.rectSelection.set.get(1)))) {
  29774. var curriedEvent = function (ev) {
  29775. ev = ev || window.event;
  29776. ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
  29777. ev.stopPropagation();
  29778. var x = ev.pageX || ev.touches[0].pageX;
  29779. var y = ev.pageY || ev.touches[0].pageY;
  29780. _this.el.fire('rot', {x: x, y: y, event: ev});
  29781. };
  29782. var pointElement = this.drawPoint(bbox.width / 2, 20)
  29783. .attr('class', this.options.classPoints + '_rot')
  29784. .on("touchstart", curriedEvent)
  29785. .on("mousedown", curriedEvent);
  29786. this.rectSelection.set.add(pointElement);
  29787. }
  29788. };
  29789. SelectHandler.prototype.handler = function () {
  29790. var bbox = this.el.bbox();
  29791. this.nested.matrix(new SVG.Matrix(this.el).translate(bbox.x, bbox.y));
  29792. if (this.rectSelection.isSelected) {
  29793. this.updateRectSelection();
  29794. }
  29795. if (this.pointSelection.isSelected) {
  29796. this.updatePointSelection();
  29797. }
  29798. };
  29799. SelectHandler.prototype.observe = function () {
  29800. var _this = this;
  29801. if (MutationObserver) {
  29802. if (this.rectSelection.isSelected || this.pointSelection.isSelected) {
  29803. this.observerInst = this.observerInst || new MutationObserver(function () {
  29804. _this.handler();
  29805. });
  29806. this.observerInst.observe(this.el.node, {attributes: true});
  29807. } else {
  29808. try {
  29809. this.observerInst.disconnect();
  29810. delete this.observerInst;
  29811. } catch (e) {
  29812. }
  29813. }
  29814. } else {
  29815. this.el.off('DOMAttrModified.select');
  29816. if (this.rectSelection.isSelected || this.pointSelection.isSelected) {
  29817. this.el.on('DOMAttrModified.select', function () {
  29818. _this.handler();
  29819. });
  29820. }
  29821. }
  29822. };
  29823. SelectHandler.prototype.cleanup = function () {
  29824. //var _this = this;
  29825. if (!this.rectSelection.isSelected && this.rectSelection.set) {
  29826. // stop watching the element, remove the selection
  29827. this.rectSelection.set.each(function () {
  29828. this.remove();
  29829. });
  29830. this.rectSelection.set.clear();
  29831. delete this.rectSelection.set;
  29832. }
  29833. if (!this.pointSelection.isSelected && this.pointSelection.set) {
  29834. // Remove all points, clear the set, stop watching the element
  29835. this.pointSelection.set.each(function () {
  29836. this.remove();
  29837. });
  29838. this.pointSelection.set.clear();
  29839. delete this.pointSelection.set;
  29840. }
  29841. if (!this.pointSelection.isSelected && !this.rectSelection.isSelected) {
  29842. this.nested.remove();
  29843. delete this.nested;
  29844. }
  29845. };
  29846. SVG.extend(SVG.Element, {
  29847. // Select element with mouse
  29848. selectize: function (value, options) {
  29849. // Check the parameters and reassign if needed
  29850. if (typeof value === 'object') {
  29851. options = value;
  29852. value = true;
  29853. }
  29854. var selectHandler = this.remember('_selectHandler') || new SelectHandler(this);
  29855. selectHandler.init(value === undefined ? true : value, options || {});
  29856. return this;
  29857. }
  29858. });
  29859. SVG.Element.prototype.selectize.defaults = {
  29860. points: ['lt', 'rt', 'rb', 'lb', 't', 'r', 'b', 'l'], // which points to draw, default all
  29861. pointsExclude: [], // easier option if to exclude few than rewrite all
  29862. classRect: 'svg_select_boundingRect', // Css-class added to the rect
  29863. classPoints: 'svg_select_points', // Css-class added to the points
  29864. pointSize: 7, // size of point
  29865. rotationPoint: true, // If true, rotation point is drawn. Needed for rotation!
  29866. deepSelect: false, // If true, moving of single points is possible (only line, polyline, polyon)
  29867. pointType: 'circle' // Point type: circle or rect, default circle
  29868. };
  29869. }());
  29870. (function() {
  29871. (function () {
  29872. function ResizeHandler(el) {
  29873. el.remember('_resizeHandler', this);
  29874. this.el = el;
  29875. this.parameters = {};
  29876. this.lastUpdateCall = null;
  29877. this.p = el.doc().node.createSVGPoint();
  29878. }
  29879. ResizeHandler.prototype.transformPoint = function(x, y, m){
  29880. this.p.x = x - (this.offset.x - window.pageXOffset);
  29881. this.p.y = y - (this.offset.y - window.pageYOffset);
  29882. return this.p.matrixTransform(m || this.m);
  29883. };
  29884. ResizeHandler.prototype._extractPosition = function(event) {
  29885. // Extract a position from a mouse/touch event.
  29886. // Returns { x: .., y: .. }
  29887. return {
  29888. x: event.clientX != null ? event.clientX : event.touches[0].clientX,
  29889. y: event.clientY != null ? event.clientY : event.touches[0].clientY
  29890. }
  29891. };
  29892. ResizeHandler.prototype.init = function (options) {
  29893. var _this = this;
  29894. this.stop();
  29895. if (options === 'stop') {
  29896. return;
  29897. }
  29898. this.options = {};
  29899. // Merge options and defaults
  29900. for (var i in this.el.resize.defaults) {
  29901. this.options[i] = this.el.resize.defaults[i];
  29902. if (typeof options[i] !== 'undefined') {
  29903. this.options[i] = options[i];
  29904. }
  29905. }
  29906. // We listen to all these events which are specifying different edges
  29907. this.el.on('lt.resize', function(e){ _this.resize(e || window.event); }); // Left-Top
  29908. this.el.on('rt.resize', function(e){ _this.resize(e || window.event); }); // Right-Top
  29909. this.el.on('rb.resize', function(e){ _this.resize(e || window.event); }); // Right-Bottom
  29910. this.el.on('lb.resize', function(e){ _this.resize(e || window.event); }); // Left-Bottom
  29911. this.el.on('t.resize', function(e){ _this.resize(e || window.event); }); // Top
  29912. this.el.on('r.resize', function(e){ _this.resize(e || window.event); }); // Right
  29913. this.el.on('b.resize', function(e){ _this.resize(e || window.event); }); // Bottom
  29914. this.el.on('l.resize', function(e){ _this.resize(e || window.event); }); // Left
  29915. this.el.on('rot.resize', function(e){ _this.resize(e || window.event); }); // Rotation
  29916. this.el.on('point.resize', function(e){ _this.resize(e || window.event); }); // Point-Moving
  29917. // This call ensures, that the plugin reacts to a change of snapToGrid immediately
  29918. this.update();
  29919. };
  29920. ResizeHandler.prototype.stop = function(){
  29921. this.el.off('lt.resize');
  29922. this.el.off('rt.resize');
  29923. this.el.off('rb.resize');
  29924. this.el.off('lb.resize');
  29925. this.el.off('t.resize');
  29926. this.el.off('r.resize');
  29927. this.el.off('b.resize');
  29928. this.el.off('l.resize');
  29929. this.el.off('rot.resize');
  29930. this.el.off('point.resize');
  29931. return this;
  29932. };
  29933. ResizeHandler.prototype.resize = function (event) {
  29934. var _this = this;
  29935. this.m = this.el.node.getScreenCTM().inverse();
  29936. this.offset = { x: window.pageXOffset, y: window.pageYOffset };
  29937. var txPt = this._extractPosition(event.detail.event);
  29938. this.parameters = {
  29939. type: this.el.type, // the type of element
  29940. p: this.transformPoint(txPt.x, txPt.y),
  29941. x: event.detail.x, // x-position of the mouse when resizing started
  29942. y: event.detail.y, // y-position of the mouse when resizing started
  29943. box: this.el.bbox(), // The bounding-box of the element
  29944. rotation: this.el.transform().rotation // The current rotation of the element
  29945. };
  29946. // Add font-size parameter if the element type is text
  29947. if (this.el.type === "text") {
  29948. this.parameters.fontSize = this.el.attr()["font-size"];
  29949. }
  29950. // the i-param in the event holds the index of the point which is moved, when using `deepSelect`
  29951. if (event.detail.i !== undefined) {
  29952. // get the point array
  29953. var array = this.el.array().valueOf();
  29954. // Save the index and the point which is moved
  29955. this.parameters.i = event.detail.i;
  29956. this.parameters.pointCoords = [array[event.detail.i][0], array[event.detail.i][1]];
  29957. }
  29958. // Lets check which edge of the bounding-box was clicked and resize the this.el according to this
  29959. switch (event.type) {
  29960. // Left-Top-Edge
  29961. case 'lt':
  29962. // We build a calculating function for every case which gives us the new position of the this.el
  29963. this.calc = function (diffX, diffY) {
  29964. // The procedure is always the same
  29965. // First we snap the edge to the given grid (snapping to 1px grid is normal resizing)
  29966. var snap = this.snapToGrid(diffX, diffY);
  29967. // Now we check if the new height and width still valid (> 0)
  29968. if (this.parameters.box.width - snap[0] > 0 && this.parameters.box.height - snap[1] > 0) {
  29969. // ...if valid, we resize the this.el (which can include moving because the coord-system starts at the left-top and this edge is moving sometimes when resized)
  29970. /*
  29971. * but first check if the element is text box, so we can change the font size instead of
  29972. * the width and height
  29973. */
  29974. if (this.parameters.type === "text") {
  29975. this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y);
  29976. this.el.attr("font-size", this.parameters.fontSize - snap[0]);
  29977. return;
  29978. }
  29979. snap = this.checkAspectRatio(snap);
  29980. this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y + snap[1]).size(this.parameters.box.width - snap[0], this.parameters.box.height - snap[1]);
  29981. }
  29982. };
  29983. break;
  29984. // Right-Top
  29985. case 'rt':
  29986. // s.a.
  29987. this.calc = function (diffX, diffY) {
  29988. var snap = this.snapToGrid(diffX, diffY, 1 << 1);
  29989. if (this.parameters.box.width + snap[0] > 0 && this.parameters.box.height - snap[1] > 0) {
  29990. if (this.parameters.type === "text") {
  29991. this.el.move(this.parameters.box.x - snap[0], this.parameters.box.y);
  29992. this.el.attr("font-size", this.parameters.fontSize + snap[0]);
  29993. return;
  29994. }
  29995. snap = this.checkAspectRatio(snap, true);
  29996. this.el.move(this.parameters.box.x, this.parameters.box.y + snap[1]).size(this.parameters.box.width + snap[0], this.parameters.box.height - snap[1]);
  29997. }
  29998. };
  29999. break;
  30000. // Right-Bottom
  30001. case 'rb':
  30002. // s.a.
  30003. this.calc = function (diffX, diffY) {
  30004. var snap = this.snapToGrid(diffX, diffY, 0);
  30005. if (this.parameters.box.width + snap[0] > 0 && this.parameters.box.height + snap[1] > 0) {
  30006. if (this.parameters.type === "text") {
  30007. this.el.move(this.parameters.box.x - snap[0], this.parameters.box.y);
  30008. this.el.attr("font-size", this.parameters.fontSize + snap[0]);
  30009. return;
  30010. }
  30011. snap = this.checkAspectRatio(snap);
  30012. this.el.move(this.parameters.box.x, this.parameters.box.y).size(this.parameters.box.width + snap[0], this.parameters.box.height + snap[1]);
  30013. }
  30014. };
  30015. break;
  30016. // Left-Bottom
  30017. case 'lb':
  30018. // s.a.
  30019. this.calc = function (diffX, diffY) {
  30020. var snap = this.snapToGrid(diffX, diffY, 1);
  30021. if (this.parameters.box.width - snap[0] > 0 && this.parameters.box.height + snap[1] > 0) {
  30022. if (this.parameters.type === "text") {
  30023. this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y);
  30024. this.el.attr("font-size", this.parameters.fontSize - snap[0]);
  30025. return;
  30026. }
  30027. snap = this.checkAspectRatio(snap, true);
  30028. this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y).size(this.parameters.box.width - snap[0], this.parameters.box.height + snap[1]);
  30029. }
  30030. };
  30031. break;
  30032. // Top
  30033. case 't':
  30034. // s.a.
  30035. this.calc = function (diffX, diffY) {
  30036. var snap = this.snapToGrid(diffX, diffY, 1 << 1);
  30037. if (this.parameters.box.height - snap[1] > 0) {
  30038. // Disable the font-resizing if it is not from the corner of bounding-box
  30039. if (this.parameters.type === "text") {
  30040. return;
  30041. }
  30042. this.el.move(this.parameters.box.x, this.parameters.box.y + snap[1]).height(this.parameters.box.height - snap[1]);
  30043. }
  30044. };
  30045. break;
  30046. // Right
  30047. case 'r':
  30048. // s.a.
  30049. this.calc = function (diffX, diffY) {
  30050. var snap = this.snapToGrid(diffX, diffY, 0);
  30051. if (this.parameters.box.width + snap[0] > 0) {
  30052. if (this.parameters.type === "text") {
  30053. return;
  30054. }
  30055. this.el.move(this.parameters.box.x, this.parameters.box.y).width(this.parameters.box.width + snap[0]);
  30056. }
  30057. };
  30058. break;
  30059. // Bottom
  30060. case 'b':
  30061. // s.a.
  30062. this.calc = function (diffX, diffY) {
  30063. var snap = this.snapToGrid(diffX, diffY, 0);
  30064. if (this.parameters.box.height + snap[1] > 0) {
  30065. if (this.parameters.type === "text") {
  30066. return;
  30067. }
  30068. this.el.move(this.parameters.box.x, this.parameters.box.y).height(this.parameters.box.height + snap[1]);
  30069. }
  30070. };
  30071. break;
  30072. // Left
  30073. case 'l':
  30074. // s.a.
  30075. this.calc = function (diffX, diffY) {
  30076. var snap = this.snapToGrid(diffX, diffY, 1);
  30077. if (this.parameters.box.width - snap[0] > 0) {
  30078. if (this.parameters.type === "text") {
  30079. return;
  30080. }
  30081. this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y).width(this.parameters.box.width - snap[0]);
  30082. }
  30083. };
  30084. break;
  30085. // Rotation
  30086. case 'rot':
  30087. // s.a.
  30088. this.calc = function (diffX, diffY) {
  30089. // yes this is kinda stupid but we need the mouse coords back...
  30090. var current = {x: diffX + this.parameters.p.x, y: diffY + this.parameters.p.y};
  30091. // start minus middle
  30092. var sAngle = Math.atan2((this.parameters.p.y - this.parameters.box.y - this.parameters.box.height / 2), (this.parameters.p.x - this.parameters.box.x - this.parameters.box.width / 2));
  30093. // end minus middle
  30094. var pAngle = Math.atan2((current.y - this.parameters.box.y - this.parameters.box.height / 2), (current.x - this.parameters.box.x - this.parameters.box.width / 2));
  30095. var angle = this.parameters.rotation + (pAngle - sAngle) * 180 / Math.PI + this.options.snapToAngle / 2;
  30096. // We have to move the element to the center of the box first and change the rotation afterwards
  30097. // because rotation always works around a rotation-center, which is changed when moving the element
  30098. // We also set the new rotation center to the center of the box.
  30099. this.el.center(this.parameters.box.cx, this.parameters.box.cy).rotate(angle - (angle % this.options.snapToAngle), this.parameters.box.cx, this.parameters.box.cy);
  30100. };
  30101. break;
  30102. // Moving one single Point (needed when an element is deepSelected which means you can move every single point of the object)
  30103. case 'point':
  30104. this.calc = function (diffX, diffY) {
  30105. // Snapping the point to the grid
  30106. var snap = this.snapToGrid(diffX, diffY, this.parameters.pointCoords[0], this.parameters.pointCoords[1]);
  30107. // Get the point array
  30108. var array = this.el.array().valueOf();
  30109. // Changing the moved point in the array
  30110. array[this.parameters.i][0] = this.parameters.pointCoords[0] + snap[0];
  30111. array[this.parameters.i][1] = this.parameters.pointCoords[1] + snap[1];
  30112. // And plot the new this.el
  30113. this.el.plot(array);
  30114. };
  30115. }
  30116. this.el.fire('resizestart', {dx: this.parameters.x, dy: this.parameters.y, event: event});
  30117. // When resizing started, we have to register events for...
  30118. // Touches.
  30119. SVG.on(window, 'touchmove.resize', function(e) {
  30120. _this.update(e || window.event);
  30121. });
  30122. SVG.on(window, 'touchend.resize', function() {
  30123. _this.done();
  30124. });
  30125. // Mouse.
  30126. SVG.on(window, 'mousemove.resize', function (e) {
  30127. _this.update(e || window.event);
  30128. });
  30129. SVG.on(window, 'mouseup.resize', function () {
  30130. _this.done();
  30131. });
  30132. };
  30133. // The update-function redraws the element every time the mouse is moving
  30134. ResizeHandler.prototype.update = function (event) {
  30135. if (!event) {
  30136. if (this.lastUpdateCall) {
  30137. this.calc(this.lastUpdateCall[0], this.lastUpdateCall[1]);
  30138. }
  30139. return;
  30140. }
  30141. // Calculate the difference between the mouseposition at start and now
  30142. var txPt = this._extractPosition(event);
  30143. var p = this.transformPoint(txPt.x, txPt.y);
  30144. var diffX = p.x - this.parameters.p.x,
  30145. diffY = p.y - this.parameters.p.y;
  30146. this.lastUpdateCall = [diffX, diffY];
  30147. // Calculate the new position and height / width of the element
  30148. this.calc(diffX, diffY);
  30149. // Emit an event to say we have changed.
  30150. this.el.fire('resizing', {dx: diffX, dy: diffY, event: event});
  30151. };
  30152. // Is called on mouseup.
  30153. // Removes the update-function from the mousemove event
  30154. ResizeHandler.prototype.done = function () {
  30155. this.lastUpdateCall = null;
  30156. SVG.off(window, 'mousemove.resize');
  30157. SVG.off(window, 'mouseup.resize');
  30158. SVG.off(window, 'touchmove.resize');
  30159. SVG.off(window, 'touchend.resize');
  30160. this.el.fire('resizedone');
  30161. };
  30162. // The flag is used to determine whether the resizing is used with a left-Point (first bit) and top-point (second bit)
  30163. // In this cases the temp-values are calculated differently
  30164. ResizeHandler.prototype.snapToGrid = function (diffX, diffY, flag, pointCoordsY) {
  30165. var temp;
  30166. // If `pointCoordsY` is given, a single Point has to be snapped (deepSelect). That's why we need a different temp-value
  30167. if (typeof pointCoordsY !== 'undefined') {
  30168. // Note that flag = pointCoordsX in this case
  30169. temp = [(flag + diffX) % this.options.snapToGrid, (pointCoordsY + diffY) % this.options.snapToGrid];
  30170. } else {
  30171. // We check if the flag is set and if not we set a default-value (both bits set - which means upper-left-edge)
  30172. flag = flag == null ? 1 | 1 << 1 : flag;
  30173. temp = [(this.parameters.box.x + diffX + (flag & 1 ? 0 : this.parameters.box.width)) % this.options.snapToGrid, (this.parameters.box.y + diffY + (flag & (1 << 1) ? 0 : this.parameters.box.height)) % this.options.snapToGrid];
  30174. }
  30175. if(diffX < 0) {
  30176. temp[0] -= this.options.snapToGrid;
  30177. }
  30178. if(diffY < 0) {
  30179. temp[1] -= this.options.snapToGrid;
  30180. }
  30181. diffX -= (Math.abs(temp[0]) < this.options.snapToGrid / 2 ?
  30182. temp[0] :
  30183. temp[0] - (diffX < 0 ? -this.options.snapToGrid : this.options.snapToGrid));
  30184. diffY -= (Math.abs(temp[1]) < this.options.snapToGrid / 2 ?
  30185. temp[1] :
  30186. temp[1] - (diffY < 0 ? -this.options.snapToGrid : this.options.snapToGrid));
  30187. return this.constraintToBox(diffX, diffY, flag, pointCoordsY);
  30188. };
  30189. // keep element within constrained box
  30190. ResizeHandler.prototype.constraintToBox = function (diffX, diffY, flag, pointCoordsY) {
  30191. //return [diffX, diffY]
  30192. var c = this.options.constraint || {};
  30193. var orgX, orgY;
  30194. if (typeof pointCoordsY !== 'undefined') {
  30195. orgX = flag;
  30196. orgY = pointCoordsY;
  30197. } else {
  30198. orgX = this.parameters.box.x + (flag & 1 ? 0 : this.parameters.box.width);
  30199. orgY = this.parameters.box.y + (flag & (1<<1) ? 0 : this.parameters.box.height);
  30200. }
  30201. if (typeof c.minX !== 'undefined' && orgX + diffX < c.minX) {
  30202. diffX = c.minX - orgX;
  30203. }
  30204. if (typeof c.maxX !== 'undefined' && orgX + diffX > c.maxX) {
  30205. diffX = c.maxX - orgX;
  30206. }
  30207. if (typeof c.minY !== 'undefined' && orgY + diffY < c.minY) {
  30208. diffY = c.minY - orgY;
  30209. }
  30210. if (typeof c.maxY !== 'undefined' && orgY + diffY > c.maxY) {
  30211. diffY = c.maxY - orgY;
  30212. }
  30213. return [diffX, diffY];
  30214. };
  30215. ResizeHandler.prototype.checkAspectRatio = function (snap, isReverse) {
  30216. if (!this.options.saveAspectRatio) {
  30217. return snap;
  30218. }
  30219. var updatedSnap = snap.slice();
  30220. var aspectRatio = this.parameters.box.width / this.parameters.box.height;
  30221. var newW = this.parameters.box.width + snap[0];
  30222. var newH = this.parameters.box.height - snap[1];
  30223. var newAspectRatio = newW / newH;
  30224. if (newAspectRatio < aspectRatio) {
  30225. // Height is too big. Adapt it
  30226. updatedSnap[1] = newW / aspectRatio - this.parameters.box.height;
  30227. isReverse && (updatedSnap[1] = -updatedSnap[1]);
  30228. } else if (newAspectRatio > aspectRatio) {
  30229. // Width is too big. Adapt it
  30230. updatedSnap[0] = this.parameters.box.width - newH * aspectRatio;
  30231. isReverse && (updatedSnap[0] = -updatedSnap[0]);
  30232. }
  30233. return updatedSnap;
  30234. };
  30235. SVG.extend(SVG.Element, {
  30236. // Resize element with mouse
  30237. resize: function (options) {
  30238. (this.remember('_resizeHandler') || new ResizeHandler(this)).init(options || {});
  30239. return this;
  30240. }
  30241. });
  30242. SVG.Element.prototype.resize.defaults = {
  30243. snapToAngle: 0.1, // Specifies the speed the rotation is happening when moving the mouse
  30244. snapToGrid: 1, // Snaps to a grid of `snapToGrid` Pixels
  30245. constraint: {}, // keep element within constrained box
  30246. saveAspectRatio: false // Save aspect ratio when resizing using lt, rt, rb or lb points
  30247. };
  30248. }).call(this);
  30249. }());
  30250. // global Apex object which user can use to override chart's defaults globally
  30251. if (typeof window.Apex === 'undefined') {
  30252. window.Apex = {};
  30253. }
  30254. var InitCtxVariables = /*#__PURE__*/function () {
  30255. function InitCtxVariables(ctx) {
  30256. _classCallCheck(this, InitCtxVariables);
  30257. this.ctx = ctx;
  30258. this.w = ctx.w;
  30259. }
  30260. _createClass(InitCtxVariables, [{
  30261. key: "initModules",
  30262. value: function initModules() {
  30263. 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'];
  30264. this.ctx.eventList = ['click', 'mousedown', 'mousemove', 'mouseleave', 'touchstart', 'touchmove', 'touchleave', 'mouseup', 'touchend'];
  30265. this.ctx.animations = new Animations(this.ctx);
  30266. this.ctx.axes = new Axes(this.ctx);
  30267. this.ctx.core = new Core(this.ctx.el, this.ctx);
  30268. this.ctx.config = new Config({});
  30269. this.ctx.data = new Data(this.ctx);
  30270. this.ctx.grid = new Grid(this.ctx);
  30271. this.ctx.graphics = new Graphics(this.ctx);
  30272. this.ctx.coreUtils = new CoreUtils(this.ctx);
  30273. this.ctx.crosshairs = new Crosshairs(this.ctx);
  30274. this.ctx.events = new Events(this.ctx);
  30275. this.ctx.exports = new Exports(this.ctx);
  30276. this.ctx.fill = new Fill(this.ctx);
  30277. this.ctx.localization = new Localization(this.ctx);
  30278. this.ctx.options = new Options();
  30279. this.ctx.responsive = new Responsive(this.ctx);
  30280. this.ctx.series = new Series(this.ctx);
  30281. this.ctx.theme = new Theme(this.ctx);
  30282. this.ctx.formatters = new Formatters(this.ctx);
  30283. this.ctx.titleSubtitle = new TitleSubtitle(this.ctx);
  30284. this.ctx.legend = new Legend(this.ctx);
  30285. this.ctx.toolbar = new Toolbar(this.ctx);
  30286. this.ctx.tooltip = new Tooltip(this.ctx);
  30287. this.ctx.dimensions = new Dimensions(this.ctx);
  30288. this.ctx.updateHelpers = new UpdateHelpers(this.ctx);
  30289. this.ctx.zoomPanSelection = new ZoomPanSelection(this.ctx);
  30290. this.ctx.w.globals.tooltip = new Tooltip(this.ctx);
  30291. }
  30292. }]);
  30293. return InitCtxVariables;
  30294. }();
  30295. var Destroy = /*#__PURE__*/function () {
  30296. function Destroy(ctx) {
  30297. _classCallCheck(this, Destroy);
  30298. this.ctx = ctx;
  30299. this.w = ctx.w;
  30300. }
  30301. _createClass(Destroy, [{
  30302. key: "clear",
  30303. value: function clear(_ref) {
  30304. var isUpdating = _ref.isUpdating;
  30305. if (this.ctx.zoomPanSelection) {
  30306. this.ctx.zoomPanSelection.destroy();
  30307. }
  30308. if (this.ctx.toolbar) {
  30309. this.ctx.toolbar.destroy();
  30310. }
  30311. this.ctx.animations = null;
  30312. this.ctx.axes = null;
  30313. this.ctx.annotations = null;
  30314. this.ctx.core = null;
  30315. this.ctx.data = null;
  30316. this.ctx.grid = null;
  30317. this.ctx.series = null;
  30318. this.ctx.responsive = null;
  30319. this.ctx.theme = null;
  30320. this.ctx.formatters = null;
  30321. this.ctx.titleSubtitle = null;
  30322. this.ctx.legend = null;
  30323. this.ctx.dimensions = null;
  30324. this.ctx.options = null;
  30325. this.ctx.crosshairs = null;
  30326. this.ctx.zoomPanSelection = null;
  30327. this.ctx.updateHelpers = null;
  30328. this.ctx.toolbar = null;
  30329. this.ctx.localization = null;
  30330. this.ctx.w.globals.tooltip = null;
  30331. this.clearDomElements({
  30332. isUpdating: isUpdating
  30333. });
  30334. }
  30335. }, {
  30336. key: "killSVG",
  30337. value: function killSVG(draw) {
  30338. draw.each(function () {
  30339. this.removeClass('*');
  30340. this.off();
  30341. this.stop();
  30342. }, true);
  30343. draw.ungroup();
  30344. draw.clear();
  30345. }
  30346. }, {
  30347. key: "clearDomElements",
  30348. value: function clearDomElements(_ref2) {
  30349. var _this = this;
  30350. var isUpdating = _ref2.isUpdating;
  30351. var elSVG = this.w.globals.dom.Paper.node;
  30352. // fixes apexcharts.js#1654 & vue-apexcharts#256
  30353. if (elSVG.parentNode && elSVG.parentNode.parentNode && !isUpdating) {
  30354. elSVG.parentNode.parentNode.style.minHeight = 'unset';
  30355. }
  30356. // detach root event
  30357. var baseEl = this.w.globals.dom.baseEl;
  30358. if (baseEl) {
  30359. // see https://github.com/apexcharts/vue-apexcharts/issues/275
  30360. this.ctx.eventList.forEach(function (event) {
  30361. baseEl.removeEventListener(event, _this.ctx.events.documentEvent);
  30362. });
  30363. }
  30364. var domEls = this.w.globals.dom;
  30365. if (this.ctx.el !== null) {
  30366. // remove all child elements - resetting the whole chart
  30367. while (this.ctx.el.firstChild) {
  30368. this.ctx.el.removeChild(this.ctx.el.firstChild);
  30369. }
  30370. }
  30371. this.killSVG(domEls.Paper);
  30372. domEls.Paper.remove();
  30373. domEls.elWrap = null;
  30374. domEls.elGraphical = null;
  30375. domEls.elLegendWrap = null;
  30376. domEls.elLegendForeign = null;
  30377. domEls.baseEl = null;
  30378. domEls.elGridRect = null;
  30379. domEls.elGridRectMask = null;
  30380. domEls.elGridRectBarMask = null;
  30381. domEls.elGridRectMarkerMask = null;
  30382. domEls.elForecastMask = null;
  30383. domEls.elNonForecastMask = null;
  30384. domEls.elDefs = null;
  30385. }
  30386. }]);
  30387. return Destroy;
  30388. }();
  30389. // Helpers to react to element resizes, regardless of what caused them
  30390. // TODO Currently this creates a new ResizeObserver every time we want to observe an element for resizes
  30391. // Ideally, we should be able to use a single observer for all elements
  30392. var ros = new WeakMap(); // Map callbacks to ResizeObserver instances for easy removal
  30393. function addResizeListener(el, fn) {
  30394. var called = false;
  30395. if (el.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
  30396. var elRect = el.getBoundingClientRect();
  30397. if (el.style.display === 'none' || elRect.width === 0) {
  30398. // if elRect.width=0, the chart is not rendered at all
  30399. // (it has either display none or hidden in a different tab)
  30400. // fixes https://github.com/apexcharts/apexcharts.js/issues/2825
  30401. // fixes https://github.com/apexcharts/apexcharts.js/issues/2991
  30402. // fixes https://github.com/apexcharts/apexcharts.js/issues/2992
  30403. called = true;
  30404. }
  30405. }
  30406. var ro = new ResizeObserver(function (r) {
  30407. // ROs fire immediately after being created,
  30408. // per spec: https://drafts.csswg.org/resize-observer/#ref-for-element%E2%91%A3
  30409. // we don't want that so we just discard the first run
  30410. if (called) {
  30411. fn.call(el, r);
  30412. }
  30413. called = true;
  30414. });
  30415. if (el.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
  30416. // Document fragment, observe children instead (needed for Shadow DOM, see #1332)
  30417. Array.from(el.children).forEach(function (c) {
  30418. return ro.observe(c);
  30419. });
  30420. } else {
  30421. ro.observe(el);
  30422. }
  30423. ros.set(fn, ro);
  30424. }
  30425. function removeResizeListener(el, fn) {
  30426. var ro = ros.get(fn);
  30427. if (ro) {
  30428. ro.disconnect();
  30429. ros.delete(fn);
  30430. }
  30431. }
  30432. 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 width: 12px;\n height: 12px;\n position: relative;\n top: 0;\n margin-right: 10px;\n border-radius: 50%\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_boundingRect,\n.svg_select_points_rot {\n pointer-events: none;\n opacity: 0;\n visibility: hidden\n}\n\n.apexcharts-selection-rect+g .svg_select_boundingRect,\n.apexcharts-selection-rect+g .svg_select_points_rot {\n opacity: 0;\n visibility: hidden\n}\n\n.apexcharts-selection-rect+g .svg_select_points_l,\n.apexcharts-selection-rect+g .svg_select_points_r {\n cursor: ew-resize;\n opacity: 1;\n visibility: visible\n}\n\n.svg_select_points {\n fill: #efefef;\n stroke: #333;\n rx: 2\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-area-series .apexcharts-series-markers .apexcharts-marker.no-pointer-events,\n.apexcharts-gridline,\n.apexcharts-line,\n.apexcharts-line-series .apexcharts-series-markers .apexcharts-marker.no-pointer-events,\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 pointer-events: none\n}\n\n.apexcharts-tooltip-active .apexcharts-marker {\n transition: .15s ease all\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";
  30433. /**
  30434. *
  30435. * @module ApexCharts
  30436. **/
  30437. var ApexCharts$1 = /*#__PURE__*/function () {
  30438. function ApexCharts(el, opts) {
  30439. _classCallCheck(this, ApexCharts);
  30440. this.opts = opts;
  30441. this.ctx = this;
  30442. // 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.
  30443. this.w = new Base(opts).init();
  30444. this.el = el;
  30445. this.w.globals.cuid = Utils$1.randomId();
  30446. this.w.globals.chartID = this.w.config.chart.id ? Utils$1.escapeString(this.w.config.chart.id) : this.w.globals.cuid;
  30447. var initCtx = new InitCtxVariables(this);
  30448. initCtx.initModules();
  30449. this.create = Utils$1.bind(this.create, this);
  30450. this.windowResizeHandler = this._windowResizeHandler.bind(this);
  30451. this.parentResizeHandler = this._parentResizeCallback.bind(this);
  30452. }
  30453. /**
  30454. * The primary method user will call to render the chart.
  30455. */
  30456. _createClass(ApexCharts, [{
  30457. key: "render",
  30458. value: function render() {
  30459. var _this = this;
  30460. // main method
  30461. return new Promise(function (resolve, reject) {
  30462. // only draw chart, if element found
  30463. if (_this.el !== null) {
  30464. if (typeof Apex._chartInstances === 'undefined') {
  30465. Apex._chartInstances = [];
  30466. }
  30467. if (_this.w.config.chart.id) {
  30468. Apex._chartInstances.push({
  30469. id: _this.w.globals.chartID,
  30470. group: _this.w.config.chart.group,
  30471. chart: _this
  30472. });
  30473. }
  30474. // set the locale here
  30475. _this.setLocale(_this.w.config.chart.defaultLocale);
  30476. var beforeMount = _this.w.config.chart.events.beforeMount;
  30477. if (typeof beforeMount === 'function') {
  30478. beforeMount(_this, _this.w);
  30479. }
  30480. _this.events.fireEvent('beforeMount', [_this, _this.w]);
  30481. window.addEventListener('resize', _this.windowResizeHandler);
  30482. addResizeListener(_this.el.parentNode, _this.parentResizeHandler);
  30483. var rootNode = _this.el.getRootNode && _this.el.getRootNode();
  30484. var inShadowRoot = Utils$1.is('ShadowRoot', rootNode);
  30485. var doc = _this.el.ownerDocument;
  30486. var css = inShadowRoot ? rootNode.getElementById('apexcharts-css') : doc.getElementById('apexcharts-css');
  30487. if (!css) {
  30488. var _this$opts$chart;
  30489. css = document.createElement('style');
  30490. css.id = 'apexcharts-css';
  30491. css.textContent = css_248z;
  30492. 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;
  30493. if (nonce) {
  30494. css.setAttribute('nonce', nonce);
  30495. }
  30496. if (inShadowRoot) {
  30497. // We are in Shadow DOM, add to shadow root
  30498. rootNode.prepend(css);
  30499. } else {
  30500. // Add to <head> of element's document
  30501. doc.head.appendChild(css);
  30502. }
  30503. }
  30504. var graphData = _this.create(_this.w.config.series, {});
  30505. if (!graphData) return resolve(_this);
  30506. _this.mount(graphData).then(function () {
  30507. if (typeof _this.w.config.chart.events.mounted === 'function') {
  30508. _this.w.config.chart.events.mounted(_this, _this.w);
  30509. }
  30510. _this.events.fireEvent('mounted', [_this, _this.w]);
  30511. resolve(graphData);
  30512. }).catch(function (e) {
  30513. reject(e);
  30514. // handle error in case no data or element not found
  30515. });
  30516. } else {
  30517. reject(new Error('Element not found'));
  30518. }
  30519. });
  30520. }
  30521. }, {
  30522. key: "create",
  30523. value: function create(ser, opts) {
  30524. var _this2 = this;
  30525. var w = this.w;
  30526. var initCtx = new InitCtxVariables(this);
  30527. initCtx.initModules();
  30528. var gl = this.w.globals;
  30529. gl.noData = false;
  30530. gl.animationEnded = false;
  30531. this.responsive.checkResponsiveConfig(opts);
  30532. if (w.config.xaxis.convertedCatToNumeric) {
  30533. var defaults = new Defaults(w.config);
  30534. defaults.convertCatToNumericXaxis(w.config, this.ctx);
  30535. }
  30536. if (this.el === null) {
  30537. gl.animationEnded = true;
  30538. return null;
  30539. }
  30540. this.core.setupElements();
  30541. if (w.config.chart.type === 'treemap') {
  30542. w.config.grid.show = false;
  30543. w.config.yaxis[0].show = false;
  30544. }
  30545. if (gl.svgWidth === 0) {
  30546. // if the element is hidden, skip drawing
  30547. gl.animationEnded = true;
  30548. return null;
  30549. }
  30550. var series = ser;
  30551. ser.forEach(function (s, realIndex) {
  30552. if (s.hidden) {
  30553. series = _this2.legend.legendHelpers.getSeriesAfterCollapsing({
  30554. realIndex: realIndex
  30555. });
  30556. }
  30557. });
  30558. var combo = CoreUtils.checkComboSeries(series, w.config.chart.type);
  30559. gl.comboCharts = combo.comboCharts;
  30560. gl.comboBarCount = combo.comboBarCount;
  30561. var allSeriesAreEmpty = series.every(function (s) {
  30562. return s.data && s.data.length === 0;
  30563. });
  30564. if (series.length === 0 || allSeriesAreEmpty && gl.collapsedSeries.length < 1) {
  30565. this.series.handleNoData();
  30566. }
  30567. this.events.setupEventHandlers();
  30568. // 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
  30569. this.data.parseData(series);
  30570. // this is a good time to set theme colors first
  30571. this.theme.init();
  30572. // as markers accepts array, we need to setup global markers for easier access
  30573. var markers = new Markers(this);
  30574. markers.setGlobalMarkerSize();
  30575. // labelFormatters should be called before dimensions as in dimensions we need text labels width
  30576. this.formatters.setLabelFormatters();
  30577. this.titleSubtitle.draw();
  30578. // legend is calculated here before coreCalculations because it affects the plottable area
  30579. // if there is some data to show or user collapsed all series, then proceed drawing legend
  30580. if (!gl.noData || gl.collapsedSeries.length === gl.series.length || w.config.legend.showForSingleSeries) {
  30581. this.legend.init();
  30582. }
  30583. // check whether in multiple series, all series share the same X
  30584. this.series.hasAllSeriesEqualX();
  30585. // coreCalculations will give the min/max range and yaxis/axis values. It should be called here to set series variable from config to globals
  30586. if (gl.axisCharts) {
  30587. this.core.coreCalculations();
  30588. if (w.config.xaxis.type !== 'category') {
  30589. // as we have minX and maxX values, determine the default DateTimeFormat for time series
  30590. this.formatters.setLabelFormatters();
  30591. }
  30592. this.ctx.toolbar.minX = w.globals.minX;
  30593. this.ctx.toolbar.maxX = w.globals.maxX;
  30594. }
  30595. // 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
  30596. // Also we need to do this before calculating Dimensions plotCoords() method of Dimensions
  30597. this.formatters.heatmapLabelFormatters();
  30598. // get the largest marker size which will be needed in dimensions calc
  30599. var coreUtils = new CoreUtils(this);
  30600. coreUtils.getLargestMarkerSize();
  30601. // We got plottable area here, next task would be to calculate axis areas
  30602. this.dimensions.plotCoords();
  30603. var xyRatios = this.core.xySettings();
  30604. this.grid.createGridMask();
  30605. var elGraph = this.core.plotChartType(series, xyRatios);
  30606. var dataLabels = new DataLabels(this);
  30607. dataLabels.bringForward();
  30608. if (w.config.dataLabels.background.enabled) {
  30609. dataLabels.dataLabelsBackground();
  30610. }
  30611. // after all the drawing calculations, shift the graphical area (actual charts/bars) excluding legends
  30612. this.core.shiftGraphPosition();
  30613. var dim = {
  30614. plot: {
  30615. left: w.globals.translateX,
  30616. top: w.globals.translateY,
  30617. width: w.globals.gridWidth,
  30618. height: w.globals.gridHeight
  30619. }
  30620. };
  30621. return {
  30622. elGraph: elGraph,
  30623. xyRatios: xyRatios,
  30624. dimensions: dim
  30625. };
  30626. }
  30627. }, {
  30628. key: "mount",
  30629. value: function mount() {
  30630. var _this3 = this;
  30631. var graphData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  30632. var me = this;
  30633. var w = me.w;
  30634. return new Promise(function (resolve, reject) {
  30635. // no data to display
  30636. if (me.el === null) {
  30637. return reject(new Error('Not enough data to display or target element not found'));
  30638. } else if (graphData === null || w.globals.allSeriesCollapsed) {
  30639. me.series.handleNoData();
  30640. }
  30641. me.grid = new Grid(me);
  30642. var elgrid = me.grid.drawGrid();
  30643. me.annotations = new Annotations(me);
  30644. me.annotations.drawImageAnnos();
  30645. me.annotations.drawTextAnnos();
  30646. if (w.config.grid.position === 'back') {
  30647. var _elgrid$elGridBorders;
  30648. if (elgrid) {
  30649. w.globals.dom.elGraphical.add(elgrid.el);
  30650. }
  30651. if (elgrid !== null && elgrid !== void 0 && (_elgrid$elGridBorders = elgrid.elGridBorders) !== null && _elgrid$elGridBorders !== void 0 && _elgrid$elGridBorders.node) {
  30652. w.globals.dom.elGraphical.add(elgrid.elGridBorders);
  30653. }
  30654. }
  30655. if (Array.isArray(graphData.elGraph)) {
  30656. for (var g = 0; g < graphData.elGraph.length; g++) {
  30657. w.globals.dom.elGraphical.add(graphData.elGraph[g]);
  30658. }
  30659. } else {
  30660. w.globals.dom.elGraphical.add(graphData.elGraph);
  30661. }
  30662. if (w.config.grid.position === 'front') {
  30663. var _elgrid$elGridBorders2;
  30664. if (elgrid) {
  30665. w.globals.dom.elGraphical.add(elgrid.el);
  30666. }
  30667. if (elgrid !== null && elgrid !== void 0 && (_elgrid$elGridBorders2 = elgrid.elGridBorders) !== null && _elgrid$elGridBorders2 !== void 0 && _elgrid$elGridBorders2.node) {
  30668. w.globals.dom.elGraphical.add(elgrid.elGridBorders);
  30669. }
  30670. }
  30671. if (w.config.xaxis.crosshairs.position === 'front') {
  30672. me.crosshairs.drawXCrosshairs();
  30673. }
  30674. if (w.config.yaxis[0].crosshairs.position === 'front') {
  30675. me.crosshairs.drawYCrosshairs();
  30676. }
  30677. if (w.config.chart.type !== 'treemap') {
  30678. me.axes.drawAxis(w.config.chart.type, elgrid);
  30679. }
  30680. var xAxis = new XAxis(_this3.ctx, elgrid);
  30681. var yaxis = new YAxis(_this3.ctx, elgrid);
  30682. if (elgrid !== null) {
  30683. xAxis.xAxisLabelCorrections(elgrid.xAxisTickWidth);
  30684. yaxis.setYAxisTextAlignments();
  30685. w.config.yaxis.map(function (yaxe, index) {
  30686. if (w.globals.ignoreYAxisIndexes.indexOf(index) === -1) {
  30687. yaxis.yAxisTitleRotate(index, yaxe.opposite);
  30688. }
  30689. });
  30690. }
  30691. me.annotations.drawAxesAnnotations();
  30692. if (!w.globals.noData) {
  30693. // draw tooltips at the end
  30694. if (w.config.tooltip.enabled && !w.globals.noData) {
  30695. me.w.globals.tooltip.drawTooltip(graphData.xyRatios);
  30696. }
  30697. if (w.globals.axisCharts && (w.globals.isXNumeric || w.config.xaxis.convertedCatToNumeric || w.globals.isRangeBar)) {
  30698. if (w.config.chart.zoom.enabled || w.config.chart.selection && w.config.chart.selection.enabled || w.config.chart.pan && w.config.chart.pan.enabled) {
  30699. me.zoomPanSelection.init({
  30700. xyRatios: graphData.xyRatios
  30701. });
  30702. }
  30703. } else {
  30704. var tools = w.config.chart.toolbar.tools;
  30705. var toolsArr = ['zoom', 'zoomin', 'zoomout', 'selection', 'pan', 'reset'];
  30706. toolsArr.forEach(function (t) {
  30707. tools[t] = false;
  30708. });
  30709. }
  30710. if (w.config.chart.toolbar.show && !w.globals.allSeriesCollapsed) {
  30711. me.toolbar.createToolbar();
  30712. }
  30713. }
  30714. if (w.globals.memory.methodsToExec.length > 0) {
  30715. w.globals.memory.methodsToExec.forEach(function (fn) {
  30716. fn.method(fn.params, false, fn.context);
  30717. });
  30718. }
  30719. if (!w.globals.axisCharts && !w.globals.noData) {
  30720. me.core.resizeNonAxisCharts();
  30721. }
  30722. resolve(me);
  30723. });
  30724. }
  30725. /**
  30726. * Destroy the chart instance by removing all elements which also clean up event listeners on those elements.
  30727. */
  30728. }, {
  30729. key: "destroy",
  30730. value: function destroy() {
  30731. window.removeEventListener('resize', this.windowResizeHandler);
  30732. removeResizeListener(this.el.parentNode, this.parentResizeHandler);
  30733. // remove the chart's instance from the global Apex._chartInstances
  30734. var chartID = this.w.config.chart.id;
  30735. if (chartID) {
  30736. Apex._chartInstances.forEach(function (c, i) {
  30737. if (c.id === Utils$1.escapeString(chartID)) {
  30738. Apex._chartInstances.splice(i, 1);
  30739. }
  30740. });
  30741. }
  30742. new Destroy(this.ctx).clear({
  30743. isUpdating: false
  30744. });
  30745. }
  30746. /**
  30747. * Allows users to update Options after the chart has rendered.
  30748. *
  30749. * @param {object} options - A new config object can be passed which will be merged with the existing config object
  30750. * @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
  30751. * @param {boolean} animate - should animate or not on updating Options
  30752. */
  30753. }, {
  30754. key: "updateOptions",
  30755. value: function updateOptions(options) {
  30756. var _this4 = this;
  30757. var redraw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  30758. var animate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  30759. var updateSyncedCharts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  30760. var overwriteInitialConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  30761. var w = this.w;
  30762. // when called externally, clear some global variables
  30763. // fixes apexcharts.js#1488
  30764. w.globals.selection = undefined;
  30765. if (options.series) {
  30766. this.series.resetSeries(false, true, false);
  30767. if (options.series.length && options.series[0].data) {
  30768. options.series = options.series.map(function (s, i) {
  30769. return _this4.updateHelpers._extendSeries(s, i);
  30770. });
  30771. }
  30772. // user updated the series via updateOptions() function.
  30773. // Hence, we need to reset axis min/max to avoid zooming issues
  30774. this.updateHelpers.revertDefaultAxisMinMax();
  30775. }
  30776. // user has set x-axis min/max externally - hence we need to forcefully set the xaxis min/max
  30777. if (options.xaxis) {
  30778. options = this.updateHelpers.forceXAxisUpdate(options);
  30779. }
  30780. if (options.yaxis) {
  30781. options = this.updateHelpers.forceYAxisUpdate(options);
  30782. }
  30783. if (w.globals.collapsedSeriesIndices.length > 0) {
  30784. this.series.clearPreviousPaths();
  30785. }
  30786. /* update theme mode#459 */
  30787. if (options.theme) {
  30788. options = this.theme.updateThemeOptions(options);
  30789. }
  30790. return this.updateHelpers._updateOptions(options, redraw, animate, updateSyncedCharts, overwriteInitialConfig);
  30791. }
  30792. /**
  30793. * Allows users to update Series after the chart has rendered.
  30794. *
  30795. * @param {array} series - New series which will override the existing
  30796. */
  30797. }, {
  30798. key: "updateSeries",
  30799. value: function updateSeries() {
  30800. var newSeries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  30801. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30802. var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  30803. this.series.resetSeries(false);
  30804. this.updateHelpers.revertDefaultAxisMinMax();
  30805. return this.updateHelpers._updateSeries(newSeries, animate, overwriteInitialSeries);
  30806. }
  30807. /**
  30808. * Allows users to append a new series after the chart has rendered.
  30809. *
  30810. * @param {array} newSerie - New serie which will be appended to the existing series
  30811. */
  30812. }, {
  30813. key: "appendSeries",
  30814. value: function appendSeries(newSerie) {
  30815. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30816. var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  30817. var newSeries = this.w.config.series.slice();
  30818. newSeries.push(newSerie);
  30819. this.series.resetSeries(false);
  30820. this.updateHelpers.revertDefaultAxisMinMax();
  30821. return this.updateHelpers._updateSeries(newSeries, animate, overwriteInitialSeries);
  30822. }
  30823. /**
  30824. * Allows users to append Data to series.
  30825. *
  30826. * @param {array} newData - New data in the same format as series
  30827. */
  30828. }, {
  30829. key: "appendData",
  30830. value: function appendData(newData) {
  30831. var overwriteInitialSeries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30832. var me = this;
  30833. me.w.globals.dataChanged = true;
  30834. me.series.getPreviousPaths();
  30835. var newSeries = me.w.config.series.slice();
  30836. for (var i = 0; i < newSeries.length; i++) {
  30837. if (newData[i] !== null && typeof newData[i] !== 'undefined') {
  30838. for (var j = 0; j < newData[i].data.length; j++) {
  30839. newSeries[i].data.push(newData[i].data[j]);
  30840. }
  30841. }
  30842. }
  30843. me.w.config.series = newSeries;
  30844. if (overwriteInitialSeries) {
  30845. me.w.globals.initialSeries = Utils$1.clone(me.w.config.series);
  30846. }
  30847. return this.update();
  30848. }
  30849. }, {
  30850. key: "update",
  30851. value: function update(options) {
  30852. var _this5 = this;
  30853. return new Promise(function (resolve, reject) {
  30854. new Destroy(_this5.ctx).clear({
  30855. isUpdating: true
  30856. });
  30857. var graphData = _this5.create(_this5.w.config.series, options);
  30858. if (!graphData) return resolve(_this5);
  30859. _this5.mount(graphData).then(function () {
  30860. if (typeof _this5.w.config.chart.events.updated === 'function') {
  30861. _this5.w.config.chart.events.updated(_this5, _this5.w);
  30862. }
  30863. _this5.events.fireEvent('updated', [_this5, _this5.w]);
  30864. _this5.w.globals.isDirty = true;
  30865. resolve(_this5);
  30866. }).catch(function (e) {
  30867. reject(e);
  30868. });
  30869. });
  30870. }
  30871. /**
  30872. * Get all charts in the same "group" (including the instance which is called upon) to sync them when user zooms in/out or pan.
  30873. */
  30874. }, {
  30875. key: "getSyncedCharts",
  30876. value: function getSyncedCharts() {
  30877. var chartGroups = this.getGroupedCharts();
  30878. var allCharts = [this];
  30879. if (chartGroups.length) {
  30880. allCharts = [];
  30881. chartGroups.forEach(function (ch) {
  30882. allCharts.push(ch);
  30883. });
  30884. }
  30885. return allCharts;
  30886. }
  30887. /**
  30888. * 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)
  30889. */
  30890. }, {
  30891. key: "getGroupedCharts",
  30892. value: function getGroupedCharts() {
  30893. var _this6 = this;
  30894. return Apex._chartInstances.filter(function (ch) {
  30895. if (ch.group) {
  30896. return true;
  30897. }
  30898. }).map(function (ch) {
  30899. return _this6.w.config.chart.group === ch.group ? ch.chart : _this6;
  30900. });
  30901. }
  30902. }, {
  30903. key: "toggleSeries",
  30904. value: function toggleSeries(seriesName) {
  30905. return this.series.toggleSeries(seriesName);
  30906. }
  30907. }, {
  30908. key: "highlightSeriesOnLegendHover",
  30909. value: function highlightSeriesOnLegendHover(e, targetElement) {
  30910. return this.series.toggleSeriesOnHover(e, targetElement);
  30911. }
  30912. }, {
  30913. key: "showSeries",
  30914. value: function showSeries(seriesName) {
  30915. this.series.showSeries(seriesName);
  30916. }
  30917. }, {
  30918. key: "hideSeries",
  30919. value: function hideSeries(seriesName) {
  30920. this.series.hideSeries(seriesName);
  30921. }
  30922. }, {
  30923. key: "highlightSeries",
  30924. value: function highlightSeries(seriesName) {
  30925. this.series.highlightSeries(seriesName);
  30926. }
  30927. }, {
  30928. key: "isSeriesHidden",
  30929. value: function isSeriesHidden(seriesName) {
  30930. this.series.isSeriesHidden(seriesName);
  30931. }
  30932. }, {
  30933. key: "resetSeries",
  30934. value: function resetSeries() {
  30935. var shouldUpdateChart = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  30936. var shouldResetZoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30937. this.series.resetSeries(shouldUpdateChart, shouldResetZoom);
  30938. }
  30939. // Public method to add event listener on chart context
  30940. }, {
  30941. key: "addEventListener",
  30942. value: function addEventListener(name, handler) {
  30943. this.events.addEventListener(name, handler);
  30944. }
  30945. // Public method to remove event listener on chart context
  30946. }, {
  30947. key: "removeEventListener",
  30948. value: function removeEventListener(name, handler) {
  30949. this.events.removeEventListener(name, handler);
  30950. }
  30951. }, {
  30952. key: "addXaxisAnnotation",
  30953. value: function addXaxisAnnotation(opts) {
  30954. var pushToMemory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30955. var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  30956. var me = this;
  30957. if (context) {
  30958. me = context;
  30959. }
  30960. me.annotations.addXaxisAnnotationExternal(opts, pushToMemory, me);
  30961. }
  30962. }, {
  30963. key: "addYaxisAnnotation",
  30964. value: function addYaxisAnnotation(opts) {
  30965. var pushToMemory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30966. var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  30967. var me = this;
  30968. if (context) {
  30969. me = context;
  30970. }
  30971. me.annotations.addYaxisAnnotationExternal(opts, pushToMemory, me);
  30972. }
  30973. }, {
  30974. key: "addPointAnnotation",
  30975. value: function addPointAnnotation(opts) {
  30976. var pushToMemory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  30977. var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  30978. var me = this;
  30979. if (context) {
  30980. me = context;
  30981. }
  30982. me.annotations.addPointAnnotationExternal(opts, pushToMemory, me);
  30983. }
  30984. }, {
  30985. key: "clearAnnotations",
  30986. value: function clearAnnotations() {
  30987. var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
  30988. var me = this;
  30989. if (context) {
  30990. me = context;
  30991. }
  30992. me.annotations.clearAnnotations(me);
  30993. }
  30994. }, {
  30995. key: "removeAnnotation",
  30996. value: function removeAnnotation(id) {
  30997. var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
  30998. var me = this;
  30999. if (context) {
  31000. me = context;
  31001. }
  31002. me.annotations.removeAnnotation(me, id);
  31003. }
  31004. }, {
  31005. key: "getChartArea",
  31006. value: function getChartArea() {
  31007. var el = this.w.globals.dom.baseEl.querySelector('.apexcharts-inner');
  31008. return el;
  31009. }
  31010. }, {
  31011. key: "getSeriesTotalXRange",
  31012. value: function getSeriesTotalXRange(minX, maxX) {
  31013. return this.coreUtils.getSeriesTotalsXRange(minX, maxX);
  31014. }
  31015. }, {
  31016. key: "getHighestValueInSeries",
  31017. value: function getHighestValueInSeries() {
  31018. var seriesIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  31019. var range = new Range(this.ctx);
  31020. return range.getMinYMaxY(seriesIndex).highestY;
  31021. }
  31022. }, {
  31023. key: "getLowestValueInSeries",
  31024. value: function getLowestValueInSeries() {
  31025. var seriesIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  31026. var range = new Range(this.ctx);
  31027. return range.getMinYMaxY(seriesIndex).lowestY;
  31028. }
  31029. }, {
  31030. key: "getSeriesTotal",
  31031. value: function getSeriesTotal() {
  31032. return this.w.globals.seriesTotals;
  31033. }
  31034. }, {
  31035. key: "toggleDataPointSelection",
  31036. value: function toggleDataPointSelection(seriesIndex, dataPointIndex) {
  31037. return this.updateHelpers.toggleDataPointSelection(seriesIndex, dataPointIndex);
  31038. }
  31039. }, {
  31040. key: "zoomX",
  31041. value: function zoomX(min, max) {
  31042. this.ctx.toolbar.zoomUpdateOptions(min, max);
  31043. }
  31044. }, {
  31045. key: "setLocale",
  31046. value: function setLocale(localeName) {
  31047. this.localization.setCurrentLocaleValues(localeName);
  31048. }
  31049. }, {
  31050. key: "dataURI",
  31051. value: function dataURI(options) {
  31052. var exp = new Exports(this.ctx);
  31053. return exp.dataURI(options);
  31054. }
  31055. }, {
  31056. key: "exportToCSV",
  31057. value: function exportToCSV() {
  31058. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31059. var exp = new Exports(this.ctx);
  31060. return exp.exportToCSV(options);
  31061. }
  31062. }, {
  31063. key: "paper",
  31064. value: function paper() {
  31065. return this.w.globals.dom.Paper;
  31066. }
  31067. }, {
  31068. key: "_parentResizeCallback",
  31069. value: function _parentResizeCallback() {
  31070. if (this.w.globals.animationEnded && this.w.config.chart.redrawOnParentResize) {
  31071. this._windowResize();
  31072. }
  31073. }
  31074. /**
  31075. * Handle window resize and re-draw the whole chart.
  31076. */
  31077. }, {
  31078. key: "_windowResize",
  31079. value: function _windowResize() {
  31080. var _this7 = this;
  31081. clearTimeout(this.w.globals.resizeTimer);
  31082. this.w.globals.resizeTimer = window.setTimeout(function () {
  31083. _this7.w.globals.resized = true;
  31084. _this7.w.globals.dataChanged = false;
  31085. // we need to redraw the whole chart on window resize (with a small delay).
  31086. _this7.ctx.update();
  31087. }, 150);
  31088. }
  31089. }, {
  31090. key: "_windowResizeHandler",
  31091. value: function _windowResizeHandler() {
  31092. var redraw = this.w.config.chart.redrawOnWindowResize;
  31093. if (typeof redraw === 'function') {
  31094. redraw = redraw();
  31095. }
  31096. redraw && this._windowResize();
  31097. }
  31098. }], [{
  31099. key: "getChartByID",
  31100. value: function getChartByID(id) {
  31101. var chartId = Utils$1.escapeString(id);
  31102. if (!Apex._chartInstances) return undefined;
  31103. var c = Apex._chartInstances.filter(function (ch) {
  31104. return ch.id === chartId;
  31105. })[0];
  31106. return c && c.chart;
  31107. }
  31108. /**
  31109. * 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
  31110. */
  31111. }, {
  31112. key: "initOnLoad",
  31113. value: function initOnLoad() {
  31114. var els = document.querySelectorAll('[data-apexcharts]');
  31115. for (var i = 0; i < els.length; i++) {
  31116. var el = els[i];
  31117. var options = JSON.parse(els[i].getAttribute('data-options'));
  31118. var apexChart = new ApexCharts(el, options);
  31119. apexChart.render();
  31120. }
  31121. }
  31122. /**
  31123. * This static method allows users to call chart methods without necessarily from the
  31124. * instance of the chart in case user has assigned chartID to the targeted chart.
  31125. * The chartID is used for mapping the instance stored in Apex._chartInstances global variable
  31126. *
  31127. * This is helpful in cases when you don't have reference of the chart instance
  31128. * easily and need to call the method from anywhere.
  31129. * For eg, in React/Vue applications when you have many parent/child components,
  31130. * and need easy reference to other charts for performing dynamic operations
  31131. *
  31132. * @param {string} chartID - The unique identifier which will be used to call methods
  31133. * on that chart instance
  31134. * @param {function} fn - The method name to call
  31135. * @param {object} opts - The parameters which are accepted in the original method will be passed here in the same order.
  31136. */
  31137. }, {
  31138. key: "exec",
  31139. value: function exec(chartID, fn) {
  31140. var chart = this.getChartByID(chartID);
  31141. if (!chart) return;
  31142. // turn on the global exec flag to indicate this method was called
  31143. chart.w.globals.isExecCalled = true;
  31144. var ret = null;
  31145. if (chart.publicMethods.indexOf(fn) !== -1) {
  31146. for (var _len = arguments.length, opts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  31147. opts[_key - 2] = arguments[_key];
  31148. }
  31149. ret = chart[fn].apply(chart, opts);
  31150. }
  31151. return ret;
  31152. }
  31153. }, {
  31154. key: "merge",
  31155. value: function merge(target, source) {
  31156. return Utils$1.extend(target, source);
  31157. }
  31158. }]);
  31159. return ApexCharts;
  31160. }();
  31161. return ApexCharts$1;
  31162. }));