Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

4468 linhas
138 KiB

  1. function _typeof(obj) {
  2. "@babel/helpers - typeof";
  3. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  4. _typeof = function (obj) {
  5. return typeof obj;
  6. };
  7. } else {
  8. _typeof = function (obj) {
  9. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  10. };
  11. }
  12. return _typeof(obj);
  13. }
  14. function _classCallCheck(instance, Constructor) {
  15. if (!(instance instanceof Constructor)) {
  16. throw new TypeError("Cannot call a class as a function");
  17. }
  18. }
  19. function _defineProperties(target, props) {
  20. for (var i = 0; i < props.length; i++) {
  21. var descriptor = props[i];
  22. descriptor.enumerable = descriptor.enumerable || false;
  23. descriptor.configurable = true;
  24. if ("value" in descriptor) descriptor.writable = true;
  25. Object.defineProperty(target, descriptor.key, descriptor);
  26. }
  27. }
  28. function _createClass(Constructor, protoProps, staticProps) {
  29. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30. if (staticProps) _defineProperties(Constructor, staticProps);
  31. return Constructor;
  32. }
  33. function _inherits(subClass, superClass) {
  34. if (typeof superClass !== "function" && superClass !== null) {
  35. throw new TypeError("Super expression must either be null or a function");
  36. }
  37. subClass.prototype = Object.create(superClass && superClass.prototype, {
  38. constructor: {
  39. value: subClass,
  40. writable: true,
  41. configurable: true
  42. }
  43. });
  44. if (superClass) _setPrototypeOf(subClass, superClass);
  45. }
  46. function _getPrototypeOf(o) {
  47. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  48. return o.__proto__ || Object.getPrototypeOf(o);
  49. };
  50. return _getPrototypeOf(o);
  51. }
  52. function _setPrototypeOf(o, p) {
  53. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  54. o.__proto__ = p;
  55. return o;
  56. };
  57. return _setPrototypeOf(o, p);
  58. }
  59. function _isNativeReflectConstruct() {
  60. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  61. if (Reflect.construct.sham) return false;
  62. if (typeof Proxy === "function") return true;
  63. try {
  64. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  65. return true;
  66. } catch (e) {
  67. return false;
  68. }
  69. }
  70. function _assertThisInitialized(self) {
  71. if (self === void 0) {
  72. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  73. }
  74. return self;
  75. }
  76. function _possibleConstructorReturn(self, call) {
  77. if (call && (typeof call === "object" || typeof call === "function")) {
  78. return call;
  79. }
  80. return _assertThisInitialized(self);
  81. }
  82. function _createSuper(Derived) {
  83. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  84. return function _createSuperInternal() {
  85. var Super = _getPrototypeOf(Derived),
  86. result;
  87. if (hasNativeReflectConstruct) {
  88. var NewTarget = _getPrototypeOf(this).constructor;
  89. result = Reflect.construct(Super, arguments, NewTarget);
  90. } else {
  91. result = Super.apply(this, arguments);
  92. }
  93. return _possibleConstructorReturn(this, result);
  94. };
  95. }
  96. function _superPropBase(object, property) {
  97. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  98. object = _getPrototypeOf(object);
  99. if (object === null) break;
  100. }
  101. return object;
  102. }
  103. function _get(target, property, receiver) {
  104. if (typeof Reflect !== "undefined" && Reflect.get) {
  105. _get = Reflect.get;
  106. } else {
  107. _get = function _get(target, property, receiver) {
  108. var base = _superPropBase(target, property);
  109. if (!base) return;
  110. var desc = Object.getOwnPropertyDescriptor(base, property);
  111. if (desc.get) {
  112. return desc.get.call(receiver);
  113. }
  114. return desc.value;
  115. };
  116. }
  117. return _get(target, property, receiver || target);
  118. }
  119. function _slicedToArray(arr, i) {
  120. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  121. }
  122. function _toConsumableArray(arr) {
  123. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  124. }
  125. function _arrayWithoutHoles(arr) {
  126. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  127. }
  128. function _arrayWithHoles(arr) {
  129. if (Array.isArray(arr)) return arr;
  130. }
  131. function _iterableToArray(iter) {
  132. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  133. }
  134. function _iterableToArrayLimit(arr, i) {
  135. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  136. var _arr = [];
  137. var _n = true;
  138. var _d = false;
  139. var _e = undefined;
  140. try {
  141. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  142. _arr.push(_s.value);
  143. if (i && _arr.length === i) break;
  144. }
  145. } catch (err) {
  146. _d = true;
  147. _e = err;
  148. } finally {
  149. try {
  150. if (!_n && _i["return"] != null) _i["return"]();
  151. } finally {
  152. if (_d) throw _e;
  153. }
  154. }
  155. return _arr;
  156. }
  157. function _unsupportedIterableToArray(o, minLen) {
  158. if (!o) return;
  159. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  160. var n = Object.prototype.toString.call(o).slice(8, -1);
  161. if (n === "Object" && o.constructor) n = o.constructor.name;
  162. if (n === "Map" || n === "Set") return Array.from(o);
  163. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  164. }
  165. function _arrayLikeToArray(arr, len) {
  166. if (len == null || len > arr.length) len = arr.length;
  167. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  168. return arr2;
  169. }
  170. function _nonIterableSpread() {
  171. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  172. }
  173. function _nonIterableRest() {
  174. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  175. }
  176. function styleInject(css, ref) {
  177. if ( ref === void 0 ) ref = {};
  178. var insertAt = ref.insertAt;
  179. if (!css || typeof document === 'undefined') { return; }
  180. var head = document.head || document.getElementsByTagName('head')[0];
  181. var style = document.createElement('style');
  182. style.type = 'text/css';
  183. if (insertAt === 'top') {
  184. if (head.firstChild) {
  185. head.insertBefore(style, head.firstChild);
  186. } else {
  187. head.appendChild(style);
  188. }
  189. } else {
  190. head.appendChild(style);
  191. }
  192. if (style.styleSheet) {
  193. style.styleSheet.cssText = css;
  194. } else {
  195. style.appendChild(document.createTextNode(css));
  196. }
  197. }
  198. var css_248z = ".chart-container {\n position: relative;\n /* for absolutely positioned tooltip */\n /* https://www.smashingmagazine.com/2015/11/using-system-ui-fonts-practical-guide/ */\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; }\n .chart-container .axis, .chart-container .chart-label {\n fill: #313B44; }\n .chart-container .axis line, .chart-container .chart-label line {\n stroke: #E2E6E9; }\n .chart-container .dataset-units circle {\n stroke: #fff;\n stroke-width: 2; }\n .chart-container .dataset-units path {\n fill: none;\n stroke-opacity: 1;\n stroke-width: 2px; }\n .chart-container .dataset-path {\n stroke-width: 2px; }\n .chart-container .path-group path {\n fill: none;\n stroke-opacity: 1;\n stroke-width: 2px; }\n .chart-container line.dashed {\n stroke-dasharray: 5, 3; }\n .chart-container .axis-line .specific-value {\n text-anchor: start; }\n .chart-container .axis-line .y-line {\n text-anchor: end; }\n .chart-container .axis-line .x-line {\n text-anchor: middle; }\n .chart-container .legend-dataset-text {\n fill: #6c7680;\n font-weight: 600; }\n\n.graph-svg-tip {\n position: absolute;\n z-index: 99999;\n padding: 10px;\n font-size: 12px;\n text-align: center;\n background: #FFFFFF;\n box-shadow: 0px 1px 4px rgba(17, 43, 66, 0.1), 0px 2px 6px rgba(17, 43, 66, 0.08), 0px 40px 30px -30px rgba(17, 43, 66, 0.1);\n border-radius: 6px; }\n .graph-svg-tip ul {\n padding-left: 0;\n display: flex; }\n .graph-svg-tip ol {\n padding-left: 0;\n display: flex; }\n .graph-svg-tip ul.data-point-list li {\n min-width: 90px;\n font-weight: 600; }\n .graph-svg-tip .svg-pointer {\n position: absolute;\n height: 12px;\n width: 12px;\n border-radius: 2px;\n background: white;\n transform: rotate(45deg);\n margin-top: -7px;\n margin-left: -6px; }\n .graph-svg-tip.comparison {\n text-align: left;\n padding: 0px;\n pointer-events: none; }\n .graph-svg-tip.comparison .title {\n display: block;\n padding: 16px;\n margin: 0;\n color: #313B44;\n font-weight: 600;\n line-height: 1;\n pointer-events: none;\n text-transform: uppercase; }\n .graph-svg-tip.comparison ul {\n margin: 0;\n white-space: nowrap;\n list-style: none; }\n .graph-svg-tip.comparison ul.tooltip-grid {\n display: grid;\n grid-template-columns: repeat(4, minmax(0, 1fr));\n gap: 5px; }\n .graph-svg-tip.comparison li {\n display: inline-block;\n display: flex;\n flex-direction: row;\n font-weight: 600;\n line-height: 1;\n padding: 5px 15px 15px 15px; }\n .graph-svg-tip.comparison li .tooltip-legend {\n height: 12px;\n width: 12px;\n margin-right: 8px;\n border-radius: 2px; }\n .graph-svg-tip.comparison li .tooltip-label {\n margin-top: 4px;\n font-size: 11px;\n max-width: 100px;\n color: #313B44;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap; }\n .graph-svg-tip.comparison li .tooltip-value {\n color: #192734; }\n";
  199. styleInject(css_248z);
  200. function $(expr, con) {
  201. return typeof expr === "string" ? (con || document).querySelector(expr) : expr || null;
  202. }
  203. $.create = function (tag, o) {
  204. var element = document.createElement(tag);
  205. for (var i in o) {
  206. var val = o[i];
  207. if (i === "inside") {
  208. $(val).appendChild(element);
  209. } else if (i === "around") {
  210. var ref = $(val);
  211. ref.parentNode.insertBefore(element, ref);
  212. element.appendChild(ref);
  213. } else if (i === "styles") {
  214. if (_typeof(val) === "object") {
  215. Object.keys(val).map(function (prop) {
  216. element.style[prop] = val[prop];
  217. });
  218. }
  219. } else if (i in element) {
  220. element[i] = val;
  221. } else {
  222. element.setAttribute(i, val);
  223. }
  224. }
  225. return element;
  226. };
  227. function getOffset(element) {
  228. var rect = element.getBoundingClientRect();
  229. return {
  230. // https://stackoverflow.com/a/7436602/6495043
  231. // rect.top varies with scroll, so we add whatever has been
  232. // scrolled to it to get absolute distance from actual page top
  233. top: rect.top + (document.documentElement.scrollTop || document.body.scrollTop),
  234. left: rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft)
  235. };
  236. } // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
  237. // an element's offsetParent property will return null whenever it, or any of its parents,
  238. // is hidden via the display style property.
  239. function isHidden(el) {
  240. return el.offsetParent === null;
  241. }
  242. function isElementInViewport(el) {
  243. // Although straightforward: https://stackoverflow.com/a/7557433/6495043
  244. var rect = el.getBoundingClientRect();
  245. return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
  246. /*or $(window).height() */
  247. rect.right <= (window.innerWidth || document.documentElement.clientWidth)
  248. /*or $(window).width() */
  249. ;
  250. }
  251. function getElementContentWidth(element) {
  252. var styles = window.getComputedStyle(element);
  253. var padding = parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight);
  254. return element.clientWidth - padding;
  255. }
  256. function fire(target, type, properties) {
  257. var evt = document.createEvent("HTMLEvents");
  258. evt.initEvent(type, true, true);
  259. for (var j in properties) {
  260. evt[j] = properties[j];
  261. }
  262. return target.dispatchEvent(evt);
  263. } // https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
  264. var BASE_MEASURES = {
  265. margins: {
  266. top: 10,
  267. bottom: 10,
  268. left: 20,
  269. right: 20
  270. },
  271. paddings: {
  272. top: 20,
  273. bottom: 40,
  274. left: 30,
  275. right: 10
  276. },
  277. baseHeight: 240,
  278. titleHeight: 20,
  279. legendHeight: 30,
  280. titleFontSize: 12
  281. };
  282. function getTopOffset(m) {
  283. return m.titleHeight + m.margins.top + m.paddings.top;
  284. }
  285. function getLeftOffset(m) {
  286. return m.margins.left + m.paddings.left;
  287. }
  288. function getExtraHeight(m) {
  289. var totalExtraHeight = m.margins.top + m.margins.bottom + m.paddings.top + m.paddings.bottom + m.titleHeight + m.legendHeight;
  290. return totalExtraHeight;
  291. }
  292. function getExtraWidth(m) {
  293. var totalExtraWidth = m.margins.left + m.margins.right + m.paddings.left + m.paddings.right;
  294. return totalExtraWidth;
  295. }
  296. var INIT_CHART_UPDATE_TIMEOUT = 700;
  297. var CHART_POST_ANIMATE_TIMEOUT = 400;
  298. var AXIS_LEGEND_BAR_SIZE = 100;
  299. var BAR_CHART_SPACE_RATIO = 0.5;
  300. var MIN_BAR_PERCENT_HEIGHT = 0.00;
  301. var LINE_CHART_DOT_SIZE = 4;
  302. var DOT_OVERLAY_SIZE_INCR = 4;
  303. var PERCENTAGE_BAR_DEFAULT_HEIGHT = 20;
  304. var PERCENTAGE_BAR_DEFAULT_DEPTH = 2; // Fixed 5-color theme,
  305. // More colors are difficult to parse visually
  306. var HEATMAP_DISTRIBUTION_SIZE = 5;
  307. var HEATMAP_SQUARE_SIZE = 10;
  308. var HEATMAP_GUTTER_SIZE = 2;
  309. var DEFAULT_CHAR_WIDTH = 7;
  310. var TOOLTIP_POINTER_TRIANGLE_HEIGHT = 7.48;
  311. var DEFAULT_CHART_COLORS = ['pink', 'blue', 'green', 'grey', 'red', 'yellow', 'purple', 'teal', 'cyan', 'orange'];
  312. var HEATMAP_COLORS_GREEN = ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127'];
  313. var DEFAULT_COLORS = {
  314. bar: DEFAULT_CHART_COLORS,
  315. line: DEFAULT_CHART_COLORS,
  316. pie: DEFAULT_CHART_COLORS,
  317. percentage: DEFAULT_CHART_COLORS,
  318. heatmap: HEATMAP_COLORS_GREEN,
  319. donut: DEFAULT_CHART_COLORS
  320. }; // Universal constants
  321. var ANGLE_RATIO = Math.PI / 180;
  322. var FULL_ANGLE = 360;
  323. var SvgTip = /*#__PURE__*/function () {
  324. function SvgTip(_ref) {
  325. var _ref$parent = _ref.parent,
  326. parent = _ref$parent === void 0 ? null : _ref$parent,
  327. _ref$colors = _ref.colors,
  328. colors = _ref$colors === void 0 ? [] : _ref$colors;
  329. _classCallCheck(this, SvgTip);
  330. this.parent = parent;
  331. this.colors = colors;
  332. this.titleName = '';
  333. this.titleValue = '';
  334. this.listValues = [];
  335. this.titleValueFirst = 0;
  336. this.x = 0;
  337. this.y = 0;
  338. this.top = 0;
  339. this.left = 0;
  340. this.setup();
  341. }
  342. _createClass(SvgTip, [{
  343. key: "setup",
  344. value: function setup() {
  345. this.makeTooltip();
  346. }
  347. }, {
  348. key: "refresh",
  349. value: function refresh() {
  350. this.fill();
  351. this.calcPosition();
  352. }
  353. }, {
  354. key: "makeTooltip",
  355. value: function makeTooltip() {
  356. var _this = this;
  357. this.container = $.create('div', {
  358. inside: this.parent,
  359. className: 'graph-svg-tip comparison',
  360. innerHTML: "<span class=\"title\"></span>\n\t\t\t\t<ul class=\"data-point-list\"></ul>\n\t\t\t\t<div class=\"svg-pointer\"></div>"
  361. });
  362. this.hideTip();
  363. this.title = this.container.querySelector('.title');
  364. this.list = this.container.querySelector('.data-point-list');
  365. this.dataPointList = this.container.querySelector('.data-point-list');
  366. this.parent.addEventListener('mouseleave', function () {
  367. _this.hideTip();
  368. });
  369. }
  370. }, {
  371. key: "fill",
  372. value: function fill() {
  373. var _this2 = this;
  374. var title;
  375. if (this.index) {
  376. this.container.setAttribute('data-point-index', this.index);
  377. }
  378. if (this.titleValueFirst) {
  379. title = "<strong>".concat(this.titleValue, "</strong>").concat(this.titleName);
  380. } else {
  381. title = "".concat(this.titleName, "<strong>").concat(this.titleValue, "</strong>");
  382. }
  383. if (this.listValues.length > 4) {
  384. this.list.classList.add('tooltip-grid');
  385. } else {
  386. this.list.classList.remove('tooltip-grid');
  387. }
  388. this.title.innerHTML = title;
  389. this.dataPointList.innerHTML = '';
  390. this.listValues.map(function (set, i) {
  391. var color = _this2.colors[i] || 'black';
  392. var value = set.formatted === 0 || set.formatted ? set.formatted : set.value;
  393. var li = $.create('li', {
  394. innerHTML: "<div class=\"tooltip-legend\" style=\"background: ".concat(color, ";\"></div>\n\t\t\t\t\t<div>\n\t\t\t\t\t\t<div class=\"tooltip-value\">").concat(value === 0 || value ? value : '', "</div>\n\t\t\t\t\t\t<div class=\"tooltip-label\">").concat(set.title ? set.title : '', "</div>\n\t\t\t\t\t</div>")
  395. });
  396. _this2.dataPointList.appendChild(li);
  397. });
  398. }
  399. }, {
  400. key: "calcPosition",
  401. value: function calcPosition() {
  402. var width = this.container.offsetWidth;
  403. this.top = this.y - this.container.offsetHeight - TOOLTIP_POINTER_TRIANGLE_HEIGHT;
  404. this.left = this.x - width / 2;
  405. var maxLeft = this.parent.offsetWidth - width;
  406. var pointer = this.container.querySelector('.svg-pointer');
  407. if (this.left < 0) {
  408. pointer.style.left = "calc(50% - ".concat(-1 * this.left, "px)");
  409. this.left = 0;
  410. } else if (this.left > maxLeft) {
  411. var delta = this.left - maxLeft;
  412. var pointerOffset = "calc(50% + ".concat(delta, "px)");
  413. pointer.style.left = pointerOffset;
  414. this.left = maxLeft;
  415. } else {
  416. pointer.style.left = "50%";
  417. }
  418. }
  419. }, {
  420. key: "setValues",
  421. value: function setValues(x, y) {
  422. var title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  423. var listValues = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  424. var index = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
  425. this.titleName = title.name;
  426. this.titleValue = title.value;
  427. this.listValues = listValues;
  428. this.x = x;
  429. this.y = y;
  430. this.titleValueFirst = title.valueFirst || 0;
  431. this.index = index;
  432. this.refresh();
  433. }
  434. }, {
  435. key: "hideTip",
  436. value: function hideTip() {
  437. this.container.style.top = '0px';
  438. this.container.style.left = '0px';
  439. this.container.style.opacity = '0';
  440. }
  441. }, {
  442. key: "showTip",
  443. value: function showTip() {
  444. this.container.style.top = this.top + 'px';
  445. this.container.style.left = this.left + 'px';
  446. this.container.style.opacity = '1';
  447. }
  448. }]);
  449. return SvgTip;
  450. }();
  451. /**
  452. * Returns the value of a number upto 2 decimal places.
  453. * @param {Number} d Any number
  454. */
  455. function floatTwo(d) {
  456. return parseFloat(d.toFixed(2));
  457. }
  458. /**
  459. * Fill an array with extra points
  460. * @param {Array} array Array
  461. * @param {Number} count number of filler elements
  462. * @param {Object} element element to fill with
  463. * @param {Boolean} start fill at start?
  464. */
  465. function fillArray(array, count, element) {
  466. var start = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  467. if (!element) {
  468. element = start ? array[0] : array[array.length - 1];
  469. }
  470. var fillerArray = new Array(Math.abs(count)).fill(element);
  471. array = start ? fillerArray.concat(array) : array.concat(fillerArray);
  472. return array;
  473. }
  474. /**
  475. * Returns pixel width of string.
  476. * @param {String} string
  477. * @param {Number} charWidth Width of single char in pixels
  478. */
  479. function getStringWidth(string, charWidth) {
  480. return (string + "").length * charWidth;
  481. }
  482. function getPositionByAngle(angle, radius) {
  483. return {
  484. x: Math.sin(angle * ANGLE_RATIO) * radius,
  485. y: Math.cos(angle * ANGLE_RATIO) * radius
  486. };
  487. }
  488. /**
  489. * Check if a number is valid for svg attributes
  490. * @param {object} candidate Candidate to test
  491. * @param {Boolean} nonNegative flag to treat negative number as invalid
  492. */
  493. function isValidNumber(candidate) {
  494. var nonNegative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  495. if (Number.isNaN(candidate)) return false;else if (candidate === undefined) return false;else if (!Number.isFinite(candidate)) return false;else if (nonNegative && candidate < 0) return false;else return true;
  496. }
  497. /**
  498. * Round a number to the closes precision, max max precision 4
  499. * @param {Number} d Any Number
  500. */
  501. function round(d) {
  502. // https://floating-point-gui.de/
  503. // https://www.jacklmoore.com/notes/rounding-in-javascript/
  504. return Number(Math.round(d + 'e4') + 'e-4');
  505. }
  506. function getBarHeightAndYAttr(yTop, zeroLine) {
  507. var height, y;
  508. if (yTop <= zeroLine) {
  509. height = zeroLine - yTop;
  510. y = yTop;
  511. } else {
  512. height = yTop - zeroLine;
  513. y = zeroLine;
  514. }
  515. return [height, y];
  516. }
  517. function equilizeNoOfElements(array1, array2) {
  518. var extraCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : array2.length - array1.length;
  519. // Doesn't work if either has zero elements.
  520. if (extraCount > 0) {
  521. array1 = fillArray(array1, extraCount);
  522. } else {
  523. array2 = fillArray(array2, extraCount);
  524. }
  525. return [array1, array2];
  526. }
  527. function truncateString(txt, len) {
  528. if (!txt) {
  529. return;
  530. }
  531. if (txt.length > len) {
  532. return txt.slice(0, len - 3) + '...';
  533. } else {
  534. return txt;
  535. }
  536. }
  537. function shortenLargeNumber(label) {
  538. var number;
  539. if (typeof label === 'number') number = label;else if (typeof label === 'string') {
  540. number = Number(label);
  541. if (Number.isNaN(number)) return label;
  542. } // Using absolute since log wont work for negative numbers
  543. var p = Math.floor(Math.log10(Math.abs(number)));
  544. if (p <= 2) return number; // Return as is for a 3 digit number of less
  545. var l = Math.floor(p / 3);
  546. var shortened = Math.pow(10, p - l * 3) * +(number / Math.pow(10, p)).toFixed(1); // Correct for floating point error upto 2 decimal places
  547. return Math.round(shortened * 100) / 100 + ' ' + ['', 'K', 'M', 'B', 'T'][l];
  548. } // cubic bezier curve calculation (from example by François Romain)
  549. function getSplineCurvePointsStr(xList, yList) {
  550. var points = [];
  551. for (var i = 0; i < xList.length; i++) {
  552. points.push([xList[i], yList[i]]);
  553. }
  554. var smoothing = 0.2;
  555. var line = function line(pointA, pointB) {
  556. var lengthX = pointB[0] - pointA[0];
  557. var lengthY = pointB[1] - pointA[1];
  558. return {
  559. length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
  560. angle: Math.atan2(lengthY, lengthX)
  561. };
  562. };
  563. var controlPoint = function controlPoint(current, previous, next, reverse) {
  564. var p = previous || current;
  565. var n = next || current;
  566. var o = line(p, n);
  567. var angle = o.angle + (reverse ? Math.PI : 0);
  568. var length = o.length * smoothing;
  569. var x = current[0] + Math.cos(angle) * length;
  570. var y = current[1] + Math.sin(angle) * length;
  571. return [x, y];
  572. };
  573. var bezierCommand = function bezierCommand(point, i, a) {
  574. var cps = controlPoint(a[i - 1], a[i - 2], point);
  575. var cpe = controlPoint(point, a[i - 1], a[i + 1], true);
  576. return "C ".concat(cps[0], ",").concat(cps[1], " ").concat(cpe[0], ",").concat(cpe[1], " ").concat(point[0], ",").concat(point[1]);
  577. };
  578. var pointStr = function pointStr(points, command) {
  579. return points.reduce(function (acc, point, i, a) {
  580. return i === 0 ? "".concat(point[0], ",").concat(point[1]) : "".concat(acc, " ").concat(command(point, i, a));
  581. }, '');
  582. };
  583. return pointStr(points, bezierCommand);
  584. }
  585. var PRESET_COLOR_MAP = {
  586. 'pink': '#F683AE',
  587. 'blue': '#318AD8',
  588. 'green': '#48BB74',
  589. 'grey': '#A6B1B9',
  590. 'red': '#F56B6B',
  591. 'yellow': '#FACF7A',
  592. 'purple': '#44427B',
  593. 'teal': '#5FD8C4',
  594. 'cyan': '#15CCEF',
  595. 'orange': '#F8814F',
  596. 'light-pink': '#FED7E5',
  597. 'light-blue': '#BFDDF7',
  598. 'light-green': '#48BB74',
  599. 'light-grey': '#F4F5F6',
  600. 'light-red': '#F6DFDF',
  601. 'light-yellow': '#FEE9BF',
  602. 'light-purple': '#E8E8F7',
  603. 'light-teal': '#D3FDF6',
  604. 'light-cyan': '#DDF8FD',
  605. 'light-orange': '#FECDB8'
  606. };
  607. function limitColor(r) {
  608. if (r > 255) return 255;else if (r < 0) return 0;
  609. return r;
  610. }
  611. function lightenDarkenColor(color, amt) {
  612. var col = getColor(color);
  613. var usePound = false;
  614. if (col[0] == "#") {
  615. col = col.slice(1);
  616. usePound = true;
  617. }
  618. var num = parseInt(col, 16);
  619. var r = limitColor((num >> 16) + amt);
  620. var b = limitColor((num >> 8 & 0x00FF) + amt);
  621. var g = limitColor((num & 0x0000FF) + amt);
  622. return (usePound ? "#" : "") + (g | b << 8 | r << 16).toString(16);
  623. }
  624. function isValidColor(string) {
  625. // https://stackoverflow.com/a/32685393
  626. var HEX_RE = /(^\s*)(#)((?:[A-Fa-f0-9]{3}){1,2})$/i;
  627. var RGB_RE = /(^\s*)(rgb|hsl)(a?)[(]\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*,\s*([\d.]+\s*%?)\s*(?:,\s*([\d.]+)\s*)?[)]$/i;
  628. return HEX_RE.test(string) || RGB_RE.test(string);
  629. }
  630. var getColor = function getColor(color) {
  631. return PRESET_COLOR_MAP[color] || color;
  632. };
  633. var AXIS_TICK_LENGTH = 6;
  634. var LABEL_MARGIN = 4;
  635. var LABEL_MAX_CHARS = 15;
  636. var FONT_SIZE = 10;
  637. var BASE_LINE_COLOR = '#E2E6E9';
  638. var FONT_FILL = '#313B44';
  639. function $$1(expr, con) {
  640. return typeof expr === "string" ? (con || document).querySelector(expr) : expr || null;
  641. }
  642. function createSVG(tag, o) {
  643. var element = document.createElementNS("http://www.w3.org/2000/svg", tag);
  644. for (var i in o) {
  645. var val = o[i];
  646. if (i === "inside") {
  647. $$1(val).appendChild(element);
  648. } else if (i === "around") {
  649. var ref = $$1(val);
  650. ref.parentNode.insertBefore(element, ref);
  651. element.appendChild(ref);
  652. } else if (i === "styles") {
  653. if (_typeof(val) === "object") {
  654. Object.keys(val).map(function (prop) {
  655. element.style[prop] = val[prop];
  656. });
  657. }
  658. } else {
  659. if (i === "className") {
  660. i = "class";
  661. }
  662. if (i === "innerHTML") {
  663. element['textContent'] = val;
  664. } else {
  665. element.setAttribute(i, val);
  666. }
  667. }
  668. }
  669. return element;
  670. }
  671. function renderVerticalGradient(svgDefElem, gradientId) {
  672. return createSVG('linearGradient', {
  673. inside: svgDefElem,
  674. id: gradientId,
  675. x1: 0,
  676. x2: 0,
  677. y1: 0,
  678. y2: 1
  679. });
  680. }
  681. function setGradientStop(gradElem, offset, color, opacity) {
  682. return createSVG('stop', {
  683. 'inside': gradElem,
  684. 'style': "stop-color: ".concat(color),
  685. 'offset': offset,
  686. 'stop-opacity': opacity
  687. });
  688. }
  689. function makeSVGContainer(parent, className, width, height) {
  690. return createSVG('svg', {
  691. className: className,
  692. inside: parent,
  693. width: width,
  694. height: height
  695. });
  696. }
  697. function makeSVGDefs(svgContainer) {
  698. return createSVG('defs', {
  699. inside: svgContainer
  700. });
  701. }
  702. function makeSVGGroup(className) {
  703. var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  704. var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  705. var args = {
  706. className: className,
  707. transform: transform
  708. };
  709. if (parent) args.inside = parent;
  710. return createSVG('g', args);
  711. }
  712. function makePath(pathStr) {
  713. var className = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  714. var stroke = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'none';
  715. var fill = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'none';
  716. var strokeWidth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 2;
  717. return createSVG('path', {
  718. className: className,
  719. d: pathStr,
  720. styles: {
  721. stroke: stroke,
  722. fill: fill,
  723. 'stroke-width': strokeWidth
  724. }
  725. });
  726. }
  727. function makeArcPathStr(startPosition, endPosition, center, radius) {
  728. var clockWise = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  729. var largeArc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  730. var arcStartX = center.x + startPosition.x,
  731. arcStartY = center.y + startPosition.y;
  732. var arcEndX = center.x + endPosition.x,
  733. arcEndY = center.y + endPosition.y;
  734. return "M".concat(center.x, " ").concat(center.y, "\n\t\tL").concat(arcStartX, " ").concat(arcStartY, "\n\t\tA ").concat(radius, " ").concat(radius, " 0 ").concat(largeArc, " ").concat(clockWise ? 1 : 0, "\n\t\t").concat(arcEndX, " ").concat(arcEndY, " z");
  735. }
  736. function makeCircleStr(startPosition, endPosition, center, radius) {
  737. var clockWise = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  738. var largeArc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  739. var arcStartX = center.x + startPosition.x,
  740. arcStartY = center.y + startPosition.y;
  741. var arcEndX = center.x + endPosition.x,
  742. midArc = center.y * 2,
  743. arcEndY = center.y + endPosition.y;
  744. return "M".concat(center.x, " ").concat(center.y, "\n\t\tL").concat(arcStartX, " ").concat(arcStartY, "\n\t\tA ").concat(radius, " ").concat(radius, " 0 ").concat(largeArc, " ").concat(clockWise ? 1 : 0, "\n\t\t").concat(arcEndX, " ").concat(midArc, " z\n\t\tL").concat(arcStartX, " ").concat(midArc, "\n\t\tA ").concat(radius, " ").concat(radius, " 0 ").concat(largeArc, " ").concat(clockWise ? 1 : 0, "\n\t\t").concat(arcEndX, " ").concat(arcEndY, " z");
  745. }
  746. function makeArcStrokePathStr(startPosition, endPosition, center, radius) {
  747. var clockWise = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  748. var largeArc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  749. var arcStartX = center.x + startPosition.x,
  750. arcStartY = center.y + startPosition.y;
  751. var arcEndX = center.x + endPosition.x,
  752. arcEndY = center.y + endPosition.y;
  753. return "M".concat(arcStartX, " ").concat(arcStartY, "\n\t\tA ").concat(radius, " ").concat(radius, " 0 ").concat(largeArc, " ").concat(clockWise ? 1 : 0, "\n\t\t").concat(arcEndX, " ").concat(arcEndY);
  754. }
  755. function makeStrokeCircleStr(startPosition, endPosition, center, radius) {
  756. var clockWise = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  757. var largeArc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  758. var arcStartX = center.x + startPosition.x,
  759. arcStartY = center.y + startPosition.y;
  760. var arcEndX = center.x + endPosition.x,
  761. midArc = radius * 2 + arcStartY,
  762. arcEndY = center.y + startPosition.y;
  763. return "M".concat(arcStartX, " ").concat(arcStartY, "\n\t\tA ").concat(radius, " ").concat(radius, " 0 ").concat(largeArc, " ").concat(clockWise ? 1 : 0, "\n\t\t").concat(arcEndX, " ").concat(midArc, "\n\t\tM").concat(arcStartX, " ").concat(midArc, "\n\t\tA ").concat(radius, " ").concat(radius, " 0 ").concat(largeArc, " ").concat(clockWise ? 1 : 0, "\n\t\t").concat(arcEndX, " ").concat(arcEndY);
  764. }
  765. function makeGradient(svgDefElem, color) {
  766. var lighter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  767. var gradientId = 'path-fill-gradient' + '-' + color + '-' + (lighter ? 'lighter' : 'default');
  768. var gradientDef = renderVerticalGradient(svgDefElem, gradientId);
  769. var opacities = [1, 0.6, 0.2];
  770. if (lighter) {
  771. opacities = [0.4, 0.2, 0];
  772. }
  773. setGradientStop(gradientDef, "0%", color, opacities[0]);
  774. setGradientStop(gradientDef, "50%", color, opacities[1]);
  775. setGradientStop(gradientDef, "100%", color, opacities[2]);
  776. return gradientId;
  777. }
  778. function percentageBar(x, y, width, height) {
  779. var depth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : PERCENTAGE_BAR_DEFAULT_DEPTH;
  780. var fill = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'none';
  781. var args = {
  782. className: 'percentage-bar',
  783. x: x,
  784. y: y,
  785. width: width,
  786. height: height,
  787. fill: fill,
  788. styles: {
  789. 'stroke': lightenDarkenColor(fill, -25),
  790. // Diabolically good: https://stackoverflow.com/a/9000859
  791. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
  792. 'stroke-dasharray': "0, ".concat(height + width, ", ").concat(width, ", ").concat(height),
  793. 'stroke-width': depth
  794. }
  795. };
  796. return createSVG("rect", args);
  797. }
  798. function heatSquare(className, x, y, size, radius) {
  799. var fill = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'none';
  800. var data = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
  801. var args = {
  802. className: className,
  803. x: x,
  804. y: y,
  805. width: size,
  806. height: size,
  807. rx: radius,
  808. fill: fill
  809. };
  810. Object.keys(data).map(function (key) {
  811. args[key] = data[key];
  812. });
  813. return createSVG("rect", args);
  814. }
  815. function legendBar(x, y, size) {
  816. var fill = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'none';
  817. var label = arguments.length > 4 ? arguments[4] : undefined;
  818. var truncate = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  819. label = truncate ? truncateString(label, LABEL_MAX_CHARS) : label;
  820. var args = {
  821. className: 'legend-bar',
  822. x: 0,
  823. y: 0,
  824. width: size,
  825. height: '2px',
  826. fill: fill
  827. };
  828. var text = createSVG('text', {
  829. className: 'legend-dataset-text',
  830. x: 0,
  831. y: 0,
  832. dy: FONT_SIZE * 2 + 'px',
  833. 'font-size': FONT_SIZE * 1.2 + 'px',
  834. 'text-anchor': 'start',
  835. fill: FONT_FILL,
  836. innerHTML: label
  837. });
  838. var group = createSVG('g', {
  839. transform: "translate(".concat(x, ", ").concat(y, ")")
  840. });
  841. group.appendChild(createSVG("rect", args));
  842. group.appendChild(text);
  843. return group;
  844. }
  845. function legendDot(x, y, size) {
  846. var fill = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'none';
  847. var label = arguments.length > 4 ? arguments[4] : undefined;
  848. var truncate = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  849. label = truncate ? truncateString(label, LABEL_MAX_CHARS) : label;
  850. var args = {
  851. className: 'legend-dot',
  852. cx: 0,
  853. cy: 0,
  854. r: size,
  855. fill: fill
  856. };
  857. var text = createSVG('text', {
  858. className: 'legend-dataset-text',
  859. x: 0,
  860. y: 0,
  861. dx: FONT_SIZE + 'px',
  862. dy: FONT_SIZE / 3 + 'px',
  863. 'font-size': FONT_SIZE * 1.2 + 'px',
  864. 'text-anchor': 'start',
  865. fill: FONT_FILL,
  866. innerHTML: label
  867. });
  868. var group = createSVG('g', {
  869. transform: "translate(".concat(x, ", ").concat(y, ")")
  870. });
  871. group.appendChild(createSVG("circle", args));
  872. group.appendChild(text);
  873. return group;
  874. }
  875. function makeText(className, x, y, content) {
  876. var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  877. var fontSize = options.fontSize || FONT_SIZE;
  878. var dy = options.dy !== undefined ? options.dy : fontSize / 2;
  879. var fill = options.fill || FONT_FILL;
  880. var textAnchor = options.textAnchor || 'start';
  881. return createSVG('text', {
  882. className: className,
  883. x: x,
  884. y: y,
  885. dy: dy + 'px',
  886. 'font-size': fontSize + 'px',
  887. fill: fill,
  888. 'text-anchor': textAnchor,
  889. innerHTML: content
  890. });
  891. }
  892. function makeVertLine(x, label, y1, y2) {
  893. var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  894. if (!options.stroke) options.stroke = BASE_LINE_COLOR;
  895. var l = createSVG('line', {
  896. className: 'line-vertical ' + options.className,
  897. x1: 0,
  898. x2: 0,
  899. y1: y1,
  900. y2: y2,
  901. styles: {
  902. stroke: options.stroke
  903. }
  904. });
  905. var text = createSVG('text', {
  906. x: 0,
  907. y: y1 > y2 ? y1 + LABEL_MARGIN : y1 - LABEL_MARGIN - FONT_SIZE,
  908. dy: FONT_SIZE + 'px',
  909. 'font-size': FONT_SIZE + 'px',
  910. 'text-anchor': 'middle',
  911. innerHTML: label + ""
  912. });
  913. var line = createSVG('g', {
  914. transform: "translate(".concat(x, ", 0)")
  915. });
  916. line.appendChild(l);
  917. line.appendChild(text);
  918. return line;
  919. }
  920. function makeHoriLine(y, label, x1, x2) {
  921. var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  922. if (!options.stroke) options.stroke = BASE_LINE_COLOR;
  923. if (!options.lineType) options.lineType = '';
  924. if (options.shortenNumbers) label = shortenLargeNumber(label);
  925. var className = 'line-horizontal ' + options.className + (options.lineType === "dashed" ? "dashed" : "");
  926. var l = createSVG('line', {
  927. className: className,
  928. x1: x1,
  929. x2: x2,
  930. y1: 0,
  931. y2: 0,
  932. styles: {
  933. stroke: options.stroke
  934. }
  935. });
  936. var text = createSVG('text', {
  937. x: x1 < x2 ? x1 - LABEL_MARGIN : x1 + LABEL_MARGIN,
  938. y: 0,
  939. dy: FONT_SIZE / 2 - 2 + 'px',
  940. 'font-size': FONT_SIZE + 'px',
  941. 'text-anchor': x1 < x2 ? 'end' : 'start',
  942. innerHTML: label + ""
  943. });
  944. var line = createSVG('g', {
  945. transform: "translate(0, ".concat(y, ")"),
  946. 'stroke-opacity': 1
  947. });
  948. if (text === 0 || text === '0') {
  949. line.style.stroke = "rgba(27, 31, 35, 0.6)";
  950. }
  951. line.appendChild(l);
  952. line.appendChild(text);
  953. return line;
  954. }
  955. function yLine(y, label, width) {
  956. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  957. if (!isValidNumber(y)) y = 0;
  958. if (!options.pos) options.pos = 'left';
  959. if (!options.offset) options.offset = 0;
  960. if (!options.mode) options.mode = 'span';
  961. if (!options.stroke) options.stroke = BASE_LINE_COLOR;
  962. if (!options.className) options.className = '';
  963. var x1 = -1 * AXIS_TICK_LENGTH;
  964. var x2 = options.mode === 'span' ? width + AXIS_TICK_LENGTH : 0;
  965. if (options.mode === 'tick' && options.pos === 'right') {
  966. x1 = width + AXIS_TICK_LENGTH;
  967. x2 = width;
  968. } // let offset = options.pos === 'left' ? -1 * options.offset : options.offset;
  969. x1 += options.offset;
  970. x2 += options.offset;
  971. return makeHoriLine(y, label, x1, x2, {
  972. stroke: options.stroke,
  973. className: options.className,
  974. lineType: options.lineType,
  975. shortenNumbers: options.shortenNumbers
  976. });
  977. }
  978. function xLine(x, label, height) {
  979. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  980. if (!isValidNumber(x)) x = 0;
  981. if (!options.pos) options.pos = 'bottom';
  982. if (!options.offset) options.offset = 0;
  983. if (!options.mode) options.mode = 'span';
  984. if (!options.stroke) options.stroke = BASE_LINE_COLOR;
  985. if (!options.className) options.className = ''; // Draw X axis line in span/tick mode with optional label
  986. // y2(span)
  987. // |
  988. // |
  989. // x line |
  990. // |
  991. // |
  992. // ---------------------+-- y2(tick)
  993. // |
  994. // y1
  995. var y1 = height + AXIS_TICK_LENGTH;
  996. var y2 = options.mode === 'span' ? -1 * AXIS_TICK_LENGTH : height;
  997. if (options.mode === 'tick' && options.pos === 'top') {
  998. // top axis ticks
  999. y1 = -1 * AXIS_TICK_LENGTH;
  1000. y2 = 0;
  1001. }
  1002. return makeVertLine(x, label, y1, y2, {
  1003. stroke: options.stroke,
  1004. className: options.className,
  1005. lineType: options.lineType
  1006. });
  1007. }
  1008. function yMarker(y, label, width) {
  1009. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  1010. if (!options.labelPos) options.labelPos = 'right';
  1011. var x = options.labelPos === 'left' ? LABEL_MARGIN : width - getStringWidth(label, 5) - LABEL_MARGIN;
  1012. var labelSvg = createSVG('text', {
  1013. className: 'chart-label',
  1014. x: x,
  1015. y: 0,
  1016. dy: FONT_SIZE / -2 + 'px',
  1017. 'font-size': FONT_SIZE + 'px',
  1018. 'text-anchor': 'start',
  1019. innerHTML: label + ""
  1020. });
  1021. var line = makeHoriLine(y, '', 0, width, {
  1022. stroke: options.stroke || BASE_LINE_COLOR,
  1023. className: options.className || '',
  1024. lineType: options.lineType
  1025. });
  1026. line.appendChild(labelSvg);
  1027. return line;
  1028. }
  1029. function yRegion(y1, y2, width, label) {
  1030. var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  1031. // return a group
  1032. var height = y1 - y2;
  1033. var rect = createSVG('rect', {
  1034. className: "bar mini",
  1035. // remove class
  1036. styles: {
  1037. fill: "rgba(228, 234, 239, 0.49)",
  1038. stroke: BASE_LINE_COLOR,
  1039. 'stroke-dasharray': "".concat(width, ", ").concat(height)
  1040. },
  1041. // 'data-point-index': index,
  1042. x: 0,
  1043. y: 0,
  1044. width: width,
  1045. height: height
  1046. });
  1047. if (!options.labelPos) options.labelPos = 'right';
  1048. var x = options.labelPos === 'left' ? LABEL_MARGIN : width - getStringWidth(label + "", 4.5) - LABEL_MARGIN;
  1049. var labelSvg = createSVG('text', {
  1050. className: 'chart-label',
  1051. x: x,
  1052. y: 0,
  1053. dy: FONT_SIZE / -2 + 'px',
  1054. 'font-size': FONT_SIZE + 'px',
  1055. 'text-anchor': 'start',
  1056. innerHTML: label + ""
  1057. });
  1058. var region = createSVG('g', {
  1059. transform: "translate(0, ".concat(y2, ")")
  1060. });
  1061. region.appendChild(rect);
  1062. region.appendChild(labelSvg);
  1063. return region;
  1064. }
  1065. function datasetBar(x, yTop, width, color) {
  1066. var label = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
  1067. var index = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  1068. var offset = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
  1069. var meta = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : {};
  1070. var _getBarHeightAndYAttr = getBarHeightAndYAttr(yTop, meta.zeroLine),
  1071. _getBarHeightAndYAttr2 = _slicedToArray(_getBarHeightAndYAttr, 2),
  1072. height = _getBarHeightAndYAttr2[0],
  1073. y = _getBarHeightAndYAttr2[1];
  1074. y -= offset;
  1075. if (height === 0) {
  1076. height = meta.minHeight;
  1077. y -= meta.minHeight;
  1078. } // Preprocess numbers to avoid svg building errors
  1079. if (!isValidNumber(x)) x = 0;
  1080. if (!isValidNumber(y)) y = 0;
  1081. if (!isValidNumber(height, true)) height = 0;
  1082. if (!isValidNumber(width, true)) width = 0;
  1083. var rect = createSVG('rect', {
  1084. className: "bar mini",
  1085. style: "fill: ".concat(color),
  1086. 'data-point-index': index,
  1087. x: x,
  1088. y: y,
  1089. width: width,
  1090. height: height
  1091. });
  1092. label += "";
  1093. if (!label && !label.length) {
  1094. return rect;
  1095. } else {
  1096. rect.setAttribute('y', 0);
  1097. rect.setAttribute('x', 0);
  1098. var text = createSVG('text', {
  1099. className: 'data-point-value',
  1100. x: width / 2,
  1101. y: 0,
  1102. dy: FONT_SIZE / 2 * -1 + 'px',
  1103. 'font-size': FONT_SIZE + 'px',
  1104. 'text-anchor': 'middle',
  1105. innerHTML: label
  1106. });
  1107. var group = createSVG('g', {
  1108. 'data-point-index': index,
  1109. transform: "translate(".concat(x, ", ").concat(y, ")")
  1110. });
  1111. group.appendChild(rect);
  1112. group.appendChild(text);
  1113. return group;
  1114. }
  1115. }
  1116. function datasetDot(x, y, radius, color) {
  1117. var label = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
  1118. var index = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  1119. var dot = createSVG('circle', {
  1120. style: "fill: ".concat(color),
  1121. 'data-point-index': index,
  1122. cx: x,
  1123. cy: y,
  1124. r: radius
  1125. });
  1126. label += "";
  1127. if (!label && !label.length) {
  1128. return dot;
  1129. } else {
  1130. dot.setAttribute('cy', 0);
  1131. dot.setAttribute('cx', 0);
  1132. var text = createSVG('text', {
  1133. className: 'data-point-value',
  1134. x: 0,
  1135. y: 0,
  1136. dy: FONT_SIZE / 2 * -1 - radius + 'px',
  1137. 'font-size': FONT_SIZE + 'px',
  1138. 'text-anchor': 'middle',
  1139. innerHTML: label
  1140. });
  1141. var group = createSVG('g', {
  1142. 'data-point-index': index,
  1143. transform: "translate(".concat(x, ", ").concat(y, ")")
  1144. });
  1145. group.appendChild(dot);
  1146. group.appendChild(text);
  1147. return group;
  1148. }
  1149. }
  1150. function getPaths(xList, yList, color) {
  1151. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  1152. var meta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  1153. var pointsList = yList.map(function (y, i) {
  1154. return xList[i] + ',' + y;
  1155. });
  1156. var pointsStr = pointsList.join("L"); // Spline
  1157. if (options.spline) pointsStr = getSplineCurvePointsStr(xList, yList);
  1158. var path = makePath("M" + pointsStr, 'line-graph-path', color); // HeatLine
  1159. if (options.heatline) {
  1160. var gradient_id = makeGradient(meta.svgDefs, color);
  1161. path.style.stroke = "url(#".concat(gradient_id, ")");
  1162. }
  1163. var paths = {
  1164. path: path
  1165. }; // Region
  1166. if (options.regionFill) {
  1167. var gradient_id_region = makeGradient(meta.svgDefs, color, true);
  1168. var pathStr = "M" + "".concat(xList[0], ",").concat(meta.zeroLine, "L") + pointsStr + "L".concat(xList.slice(-1)[0], ",").concat(meta.zeroLine);
  1169. paths.region = makePath(pathStr, "region-fill", 'none', "url(#".concat(gradient_id_region, ")"));
  1170. }
  1171. return paths;
  1172. }
  1173. var makeOverlay = {
  1174. 'bar': function bar(unit) {
  1175. var transformValue;
  1176. if (unit.nodeName !== 'rect') {
  1177. transformValue = unit.getAttribute('transform');
  1178. unit = unit.childNodes[0];
  1179. }
  1180. var overlay = unit.cloneNode();
  1181. overlay.style.fill = '#000000';
  1182. overlay.style.opacity = '0.4';
  1183. if (transformValue) {
  1184. overlay.setAttribute('transform', transformValue);
  1185. }
  1186. return overlay;
  1187. },
  1188. 'dot': function dot(unit) {
  1189. var transformValue;
  1190. if (unit.nodeName !== 'circle') {
  1191. transformValue = unit.getAttribute('transform');
  1192. unit = unit.childNodes[0];
  1193. }
  1194. var overlay = unit.cloneNode();
  1195. var radius = unit.getAttribute('r');
  1196. var fill = unit.getAttribute('fill');
  1197. overlay.setAttribute('r', parseInt(radius) + DOT_OVERLAY_SIZE_INCR);
  1198. overlay.setAttribute('fill', fill);
  1199. overlay.style.opacity = '0.6';
  1200. if (transformValue) {
  1201. overlay.setAttribute('transform', transformValue);
  1202. }
  1203. return overlay;
  1204. },
  1205. 'heat_square': function heat_square(unit) {
  1206. var transformValue;
  1207. if (unit.nodeName !== 'circle') {
  1208. transformValue = unit.getAttribute('transform');
  1209. unit = unit.childNodes[0];
  1210. }
  1211. var overlay = unit.cloneNode();
  1212. var radius = unit.getAttribute('r');
  1213. var fill = unit.getAttribute('fill');
  1214. overlay.setAttribute('r', parseInt(radius) + DOT_OVERLAY_SIZE_INCR);
  1215. overlay.setAttribute('fill', fill);
  1216. overlay.style.opacity = '0.6';
  1217. if (transformValue) {
  1218. overlay.setAttribute('transform', transformValue);
  1219. }
  1220. return overlay;
  1221. }
  1222. };
  1223. var updateOverlay = {
  1224. 'bar': function bar(unit, overlay) {
  1225. var transformValue;
  1226. if (unit.nodeName !== 'rect') {
  1227. transformValue = unit.getAttribute('transform');
  1228. unit = unit.childNodes[0];
  1229. }
  1230. var attributes = ['x', 'y', 'width', 'height'];
  1231. Object.values(unit.attributes).filter(function (attr) {
  1232. return attributes.includes(attr.name) && attr.specified;
  1233. }).map(function (attr) {
  1234. overlay.setAttribute(attr.name, attr.nodeValue);
  1235. });
  1236. if (transformValue) {
  1237. overlay.setAttribute('transform', transformValue);
  1238. }
  1239. },
  1240. 'dot': function dot(unit, overlay) {
  1241. var transformValue;
  1242. if (unit.nodeName !== 'circle') {
  1243. transformValue = unit.getAttribute('transform');
  1244. unit = unit.childNodes[0];
  1245. }
  1246. var attributes = ['cx', 'cy'];
  1247. Object.values(unit.attributes).filter(function (attr) {
  1248. return attributes.includes(attr.name) && attr.specified;
  1249. }).map(function (attr) {
  1250. overlay.setAttribute(attr.name, attr.nodeValue);
  1251. });
  1252. if (transformValue) {
  1253. overlay.setAttribute('transform', transformValue);
  1254. }
  1255. },
  1256. 'heat_square': function heat_square(unit, overlay) {
  1257. var transformValue;
  1258. if (unit.nodeName !== 'circle') {
  1259. transformValue = unit.getAttribute('transform');
  1260. unit = unit.childNodes[0];
  1261. }
  1262. var attributes = ['cx', 'cy'];
  1263. Object.values(unit.attributes).filter(function (attr) {
  1264. return attributes.includes(attr.name) && attr.specified;
  1265. }).map(function (attr) {
  1266. overlay.setAttribute(attr.name, attr.nodeValue);
  1267. });
  1268. if (transformValue) {
  1269. overlay.setAttribute('transform', transformValue);
  1270. }
  1271. }
  1272. };
  1273. var UNIT_ANIM_DUR = 350;
  1274. var PATH_ANIM_DUR = 350;
  1275. var MARKER_LINE_ANIM_DUR = UNIT_ANIM_DUR;
  1276. var REPLACE_ALL_NEW_DUR = 250;
  1277. var STD_EASING = 'easein';
  1278. function translate(unit, oldCoord, newCoord, duration) {
  1279. var old = typeof oldCoord === 'string' ? oldCoord : oldCoord.join(', ');
  1280. return [unit, {
  1281. transform: newCoord.join(', ')
  1282. }, duration, STD_EASING, "translate", {
  1283. transform: old
  1284. }];
  1285. }
  1286. function translateVertLine(xLine, newX, oldX) {
  1287. return translate(xLine, [oldX, 0], [newX, 0], MARKER_LINE_ANIM_DUR);
  1288. }
  1289. function translateHoriLine(yLine, newY, oldY) {
  1290. return translate(yLine, [0, oldY], [0, newY], MARKER_LINE_ANIM_DUR);
  1291. }
  1292. function animateRegion(rectGroup, newY1, newY2, oldY2) {
  1293. var newHeight = newY1 - newY2;
  1294. var rect = rectGroup.childNodes[0];
  1295. var width = rect.getAttribute("width");
  1296. var rectAnim = [rect, {
  1297. height: newHeight,
  1298. 'stroke-dasharray': "".concat(width, ", ").concat(newHeight)
  1299. }, MARKER_LINE_ANIM_DUR, STD_EASING];
  1300. var groupAnim = translate(rectGroup, [0, oldY2], [0, newY2], MARKER_LINE_ANIM_DUR);
  1301. return [rectAnim, groupAnim];
  1302. }
  1303. function animateBar(bar, x, yTop, width) {
  1304. var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  1305. var meta = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  1306. var _getBarHeightAndYAttr = getBarHeightAndYAttr(yTop, meta.zeroLine),
  1307. _getBarHeightAndYAttr2 = _slicedToArray(_getBarHeightAndYAttr, 2),
  1308. height = _getBarHeightAndYAttr2[0],
  1309. y = _getBarHeightAndYAttr2[1];
  1310. y -= offset;
  1311. if (bar.nodeName !== 'rect') {
  1312. var rect = bar.childNodes[0];
  1313. var rectAnim = [rect, {
  1314. width: width,
  1315. height: height
  1316. }, UNIT_ANIM_DUR, STD_EASING];
  1317. var oldCoordStr = bar.getAttribute("transform").split("(")[1].slice(0, -1);
  1318. var groupAnim = translate(bar, oldCoordStr, [x, y], MARKER_LINE_ANIM_DUR);
  1319. return [rectAnim, groupAnim];
  1320. } else {
  1321. return [[bar, {
  1322. width: width,
  1323. height: height,
  1324. x: x,
  1325. y: y
  1326. }, UNIT_ANIM_DUR, STD_EASING]];
  1327. } // bar.animate({height: args.newHeight, y: yTop}, UNIT_ANIM_DUR, mina.easein);
  1328. }
  1329. function animateDot(dot, x, y) {
  1330. if (dot.nodeName !== 'circle') {
  1331. var oldCoordStr = dot.getAttribute("transform").split("(")[1].slice(0, -1);
  1332. var groupAnim = translate(dot, oldCoordStr, [x, y], MARKER_LINE_ANIM_DUR);
  1333. return [groupAnim];
  1334. } else {
  1335. return [[dot, {
  1336. cx: x,
  1337. cy: y
  1338. }, UNIT_ANIM_DUR, STD_EASING]];
  1339. } // dot.animate({cy: yTop}, UNIT_ANIM_DUR, mina.easein);
  1340. }
  1341. function animatePath(paths, newXList, newYList, zeroLine, spline) {
  1342. var pathComponents = [];
  1343. var pointsStr = newYList.map(function (y, i) {
  1344. return newXList[i] + ',' + y;
  1345. }).join("L");
  1346. if (spline) pointsStr = getSplineCurvePointsStr(newXList, newYList);
  1347. var animPath = [paths.path, {
  1348. d: "M" + pointsStr
  1349. }, PATH_ANIM_DUR, STD_EASING];
  1350. pathComponents.push(animPath);
  1351. if (paths.region) {
  1352. var regStartPt = "".concat(newXList[0], ",").concat(zeroLine, "L");
  1353. var regEndPt = "L".concat(newXList.slice(-1)[0], ", ").concat(zeroLine);
  1354. var animRegion = [paths.region, {
  1355. d: "M" + regStartPt + pointsStr + regEndPt
  1356. }, PATH_ANIM_DUR, STD_EASING];
  1357. pathComponents.push(animRegion);
  1358. }
  1359. return pathComponents;
  1360. }
  1361. function animatePathStr(oldPath, pathStr) {
  1362. return [oldPath, {
  1363. d: pathStr
  1364. }, UNIT_ANIM_DUR, STD_EASING];
  1365. }
  1366. var EASING = {
  1367. ease: "0.25 0.1 0.25 1",
  1368. linear: "0 0 1 1",
  1369. // easein: "0.42 0 1 1",
  1370. easein: "0.1 0.8 0.2 1",
  1371. easeout: "0 0 0.58 1",
  1372. easeinout: "0.42 0 0.58 1"
  1373. };
  1374. function animateSVGElement(element, props, dur) {
  1375. var easingType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "linear";
  1376. var type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
  1377. var oldValues = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  1378. var animElement = element.cloneNode(true);
  1379. var newElement = element.cloneNode(true);
  1380. for (var attributeName in props) {
  1381. var animateElement = void 0;
  1382. if (attributeName === 'transform') {
  1383. animateElement = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");
  1384. } else {
  1385. animateElement = document.createElementNS("http://www.w3.org/2000/svg", "animate");
  1386. }
  1387. var currentValue = oldValues[attributeName] || element.getAttribute(attributeName);
  1388. var value = props[attributeName];
  1389. var animAttr = {
  1390. attributeName: attributeName,
  1391. from: currentValue,
  1392. to: value,
  1393. begin: "0s",
  1394. dur: dur / 1000 + "s",
  1395. values: currentValue + ";" + value,
  1396. keySplines: EASING[easingType],
  1397. keyTimes: "0;1",
  1398. calcMode: "spline",
  1399. fill: 'freeze'
  1400. };
  1401. if (type) {
  1402. animAttr["type"] = type;
  1403. }
  1404. for (var i in animAttr) {
  1405. animateElement.setAttribute(i, animAttr[i]);
  1406. }
  1407. animElement.appendChild(animateElement);
  1408. if (type) {
  1409. newElement.setAttribute(attributeName, "translate(".concat(value, ")"));
  1410. } else {
  1411. newElement.setAttribute(attributeName, value);
  1412. }
  1413. }
  1414. return [animElement, newElement];
  1415. }
  1416. function transform(element, style) {
  1417. // eslint-disable-line no-unused-vars
  1418. element.style.transform = style;
  1419. element.style.webkitTransform = style;
  1420. element.style.msTransform = style;
  1421. element.style.mozTransform = style;
  1422. element.style.oTransform = style;
  1423. }
  1424. function animateSVG(svgContainer, elements) {
  1425. var newElements = [];
  1426. var animElements = [];
  1427. elements.map(function (element) {
  1428. var unit = element[0];
  1429. var parent = unit.parentNode;
  1430. var animElement, newElement;
  1431. element[0] = unit;
  1432. var _animateSVGElement = animateSVGElement.apply(void 0, _toConsumableArray(element));
  1433. var _animateSVGElement2 = _slicedToArray(_animateSVGElement, 2);
  1434. animElement = _animateSVGElement2[0];
  1435. newElement = _animateSVGElement2[1];
  1436. newElements.push(newElement);
  1437. animElements.push([animElement, parent]);
  1438. parent.replaceChild(animElement, unit);
  1439. });
  1440. var animSvg = svgContainer.cloneNode(true);
  1441. animElements.map(function (animElement, i) {
  1442. animElement[1].replaceChild(newElements[i], animElement[0]);
  1443. elements[i][0] = newElements[i];
  1444. });
  1445. return animSvg;
  1446. }
  1447. function runSMILAnimation(parent, svgElement, elementsToAnimate) {
  1448. if (elementsToAnimate.length === 0) return;
  1449. var animSvgElement = animateSVG(svgElement, elementsToAnimate);
  1450. if (svgElement.parentNode == parent) {
  1451. parent.removeChild(svgElement);
  1452. parent.appendChild(animSvgElement);
  1453. } // Replace the new svgElement (data has already been replaced)
  1454. setTimeout(function () {
  1455. if (animSvgElement.parentNode == parent) {
  1456. parent.removeChild(animSvgElement);
  1457. parent.appendChild(svgElement);
  1458. }
  1459. }, REPLACE_ALL_NEW_DUR);
  1460. }
  1461. var CSSTEXT = ".chart-container{position:relative;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Fira Sans','Droid Sans','Helvetica Neue',sans-serif}.chart-container .axis,.chart-container .chart-label{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .legend-dataset-text{fill:#6c7680;font-weight:600}.graph-svg-tip{position:absolute;z-index:99999;padding:10px;font-size:12px;color:#959da5;text-align:center;background:rgba(0,0,0,.8);border-radius:3px}.graph-svg-tip ul{padding-left:0;display:flex}.graph-svg-tip ol{padding-left:0;display:flex}.graph-svg-tip ul.data-point-list li{min-width:90px;flex:1;font-weight:600}.graph-svg-tip strong{color:#dfe2e5;font-weight:600}.graph-svg-tip .svg-pointer{position:absolute;height:5px;margin:0 0 0 -5px;content:' ';border:5px solid transparent;}.graph-svg-tip.comparison{padding:0;text-align:left;pointer-events:none}.graph-svg-tip.comparison .title{display:block;padding:10px;margin:0;font-weight:600;line-height:1;pointer-events:none}.graph-svg-tip.comparison ul{margin:0;white-space:nowrap;list-style:none}.graph-svg-tip.comparison li{display:inline-block;padding:5px 10px}";
  1462. function downloadFile(filename, data) {
  1463. var a = document.createElement('a');
  1464. a.style = "display: none";
  1465. var blob = new Blob(data, {
  1466. type: "image/svg+xml; charset=utf-8"
  1467. });
  1468. var url = window.URL.createObjectURL(blob);
  1469. a.href = url;
  1470. a.download = filename;
  1471. document.body.appendChild(a);
  1472. a.click();
  1473. setTimeout(function () {
  1474. document.body.removeChild(a);
  1475. window.URL.revokeObjectURL(url);
  1476. }, 300);
  1477. }
  1478. function prepareForExport(svg) {
  1479. var clone = svg.cloneNode(true);
  1480. clone.classList.add('chart-container');
  1481. clone.setAttribute('xmlns', "http://www.w3.org/2000/svg");
  1482. clone.setAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
  1483. var styleEl = $.create('style', {
  1484. 'innerHTML': CSSTEXT
  1485. });
  1486. clone.insertBefore(styleEl, clone.firstChild);
  1487. var container = $.create('div');
  1488. container.appendChild(clone);
  1489. return container.innerHTML;
  1490. }
  1491. var BaseChart = /*#__PURE__*/function () {
  1492. function BaseChart(parent, options) {
  1493. _classCallCheck(this, BaseChart);
  1494. this.parent = typeof parent === 'string' ? document.querySelector(parent) : parent;
  1495. if (!(this.parent instanceof HTMLElement)) {
  1496. throw new Error('No `parent` element to render on was provided.');
  1497. }
  1498. this.rawChartArgs = options;
  1499. this.title = options.title || '';
  1500. this.type = options.type || '';
  1501. this.realData = this.prepareData(options.data);
  1502. this.data = this.prepareFirstData(this.realData);
  1503. this.colors = this.validateColors(options.colors, this.type);
  1504. this.config = {
  1505. showTooltip: 1,
  1506. // calculate
  1507. showLegend: 1,
  1508. // calculate
  1509. isNavigable: options.isNavigable || 0,
  1510. animate: typeof options.animate !== 'undefined' ? options.animate : 1,
  1511. truncateLegends: options.truncateLegends || 1
  1512. };
  1513. this.measures = JSON.parse(JSON.stringify(BASE_MEASURES));
  1514. var m = this.measures;
  1515. this.setMeasures(options);
  1516. if (!this.title.length) {
  1517. m.titleHeight = 0;
  1518. }
  1519. if (!this.config.showLegend) m.legendHeight = 0;
  1520. this.argHeight = options.height || m.baseHeight;
  1521. this.state = {};
  1522. this.options = {};
  1523. this.initTimeout = INIT_CHART_UPDATE_TIMEOUT;
  1524. if (this.config.isNavigable) {
  1525. this.overlays = [];
  1526. }
  1527. this.configure(options);
  1528. }
  1529. _createClass(BaseChart, [{
  1530. key: "prepareData",
  1531. value: function prepareData(data) {
  1532. return data;
  1533. }
  1534. }, {
  1535. key: "prepareFirstData",
  1536. value: function prepareFirstData(data) {
  1537. return data;
  1538. }
  1539. }, {
  1540. key: "validateColors",
  1541. value: function validateColors(colors, type) {
  1542. var validColors = [];
  1543. colors = (colors || []).concat(DEFAULT_COLORS[type]);
  1544. colors.forEach(function (string) {
  1545. var color = getColor(string);
  1546. if (!isValidColor(color)) {
  1547. console.warn('"' + string + '" is not a valid color.');
  1548. } else {
  1549. validColors.push(color);
  1550. }
  1551. });
  1552. return validColors;
  1553. }
  1554. }, {
  1555. key: "setMeasures",
  1556. value: function setMeasures() {// Override measures, including those for title and legend
  1557. // set config for legend and title
  1558. }
  1559. }, {
  1560. key: "configure",
  1561. value: function configure() {
  1562. var _this = this;
  1563. var height = this.argHeight;
  1564. this.baseHeight = height;
  1565. this.height = height - getExtraHeight(this.measures); // Bind window events
  1566. this.boundDrawFn = function () {
  1567. return _this.draw(true);
  1568. };
  1569. window.addEventListener('resize', this.boundDrawFn);
  1570. window.addEventListener('orientationchange', this.boundDrawFn);
  1571. }
  1572. }, {
  1573. key: "destroy",
  1574. value: function destroy() {
  1575. window.removeEventListener('resize', this.boundDrawFn);
  1576. window.removeEventListener('orientationchange', this.boundDrawFn);
  1577. } // Has to be called manually
  1578. }, {
  1579. key: "setup",
  1580. value: function setup() {
  1581. this.makeContainer();
  1582. this.updateWidth();
  1583. this.makeTooltip();
  1584. this.draw(false, true);
  1585. }
  1586. }, {
  1587. key: "makeContainer",
  1588. value: function makeContainer() {
  1589. // Chart needs a dedicated parent element
  1590. this.parent.innerHTML = '';
  1591. var args = {
  1592. inside: this.parent,
  1593. className: 'chart-container'
  1594. };
  1595. if (this.independentWidth) {
  1596. args.styles = {
  1597. width: this.independentWidth + 'px'
  1598. };
  1599. }
  1600. this.container = $.create('div', args);
  1601. }
  1602. }, {
  1603. key: "makeTooltip",
  1604. value: function makeTooltip() {
  1605. this.tip = new SvgTip({
  1606. parent: this.container,
  1607. colors: this.colors
  1608. });
  1609. this.bindTooltip();
  1610. }
  1611. }, {
  1612. key: "bindTooltip",
  1613. value: function bindTooltip() {}
  1614. }, {
  1615. key: "draw",
  1616. value: function draw() {
  1617. var _this2 = this;
  1618. var onlyWidthChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1619. var init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1620. if (onlyWidthChange && isHidden(this.parent)) {
  1621. // Don't update anything if the chart is hidden
  1622. return;
  1623. }
  1624. this.updateWidth();
  1625. this.calc(onlyWidthChange);
  1626. this.makeChartArea();
  1627. this.setupComponents();
  1628. this.components.forEach(function (c) {
  1629. return c.setup(_this2.drawArea);
  1630. }); // this.components.forEach(c => c.make());
  1631. this.render(this.components, false);
  1632. if (init) {
  1633. this.data = this.realData;
  1634. setTimeout(function () {
  1635. _this2.update(_this2.data);
  1636. }, this.initTimeout);
  1637. }
  1638. this.renderLegend();
  1639. this.setupNavigation(init);
  1640. }
  1641. }, {
  1642. key: "calc",
  1643. value: function calc() {} // builds state
  1644. }, {
  1645. key: "updateWidth",
  1646. value: function updateWidth() {
  1647. this.baseWidth = getElementContentWidth(this.parent);
  1648. this.width = this.baseWidth - getExtraWidth(this.measures);
  1649. }
  1650. }, {
  1651. key: "makeChartArea",
  1652. value: function makeChartArea() {
  1653. if (this.svg) {
  1654. this.container.removeChild(this.svg);
  1655. }
  1656. var m = this.measures;
  1657. this.svg = makeSVGContainer(this.container, 'frappe-chart chart', this.baseWidth, this.baseHeight);
  1658. this.svgDefs = makeSVGDefs(this.svg);
  1659. if (this.title.length) {
  1660. this.titleEL = makeText('title', m.margins.left, m.margins.top, this.title, {
  1661. fontSize: m.titleFontSize,
  1662. fill: '#666666',
  1663. dy: m.titleFontSize
  1664. });
  1665. }
  1666. var top = getTopOffset(m);
  1667. this.drawArea = makeSVGGroup(this.type + '-chart chart-draw-area', "translate(".concat(getLeftOffset(m), ", ").concat(top, ")"));
  1668. if (this.config.showLegend) {
  1669. top += this.height + m.paddings.bottom;
  1670. this.legendArea = makeSVGGroup('chart-legend', "translate(".concat(getLeftOffset(m), ", ").concat(top, ")"));
  1671. }
  1672. if (this.title.length) {
  1673. this.svg.appendChild(this.titleEL);
  1674. }
  1675. this.svg.appendChild(this.drawArea);
  1676. if (this.config.showLegend) {
  1677. this.svg.appendChild(this.legendArea);
  1678. }
  1679. this.updateTipOffset(getLeftOffset(m), getTopOffset(m));
  1680. }
  1681. }, {
  1682. key: "updateTipOffset",
  1683. value: function updateTipOffset(x, y) {
  1684. this.tip.offset = {
  1685. x: x,
  1686. y: y
  1687. };
  1688. }
  1689. }, {
  1690. key: "setupComponents",
  1691. value: function setupComponents() {
  1692. this.components = new Map();
  1693. }
  1694. }, {
  1695. key: "update",
  1696. value: function update(data) {
  1697. if (!data) {
  1698. console.error('No data to update.');
  1699. }
  1700. this.data = this.prepareData(data);
  1701. this.calc(); // builds state
  1702. this.render(this.components, this.config.animate);
  1703. }
  1704. }, {
  1705. key: "render",
  1706. value: function render() {
  1707. var _this3 = this;
  1708. var components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.components;
  1709. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  1710. if (this.config.isNavigable) {
  1711. // Remove all existing overlays
  1712. this.overlays.map(function (o) {
  1713. return o.parentNode.removeChild(o);
  1714. }); // ref.parentNode.insertBefore(element, ref);
  1715. }
  1716. var elementsToAnimate = []; // Can decouple to this.refreshComponents() first to save animation timeout
  1717. components.forEach(function (c) {
  1718. elementsToAnimate = elementsToAnimate.concat(c.update(animate));
  1719. });
  1720. if (elementsToAnimate.length > 0) {
  1721. runSMILAnimation(this.container, this.svg, elementsToAnimate);
  1722. setTimeout(function () {
  1723. components.forEach(function (c) {
  1724. return c.make();
  1725. });
  1726. _this3.updateNav();
  1727. }, CHART_POST_ANIMATE_TIMEOUT);
  1728. } else {
  1729. components.forEach(function (c) {
  1730. return c.make();
  1731. });
  1732. this.updateNav();
  1733. }
  1734. }
  1735. }, {
  1736. key: "updateNav",
  1737. value: function updateNav() {
  1738. if (this.config.isNavigable) {
  1739. this.makeOverlay();
  1740. this.bindUnits();
  1741. }
  1742. }
  1743. }, {
  1744. key: "renderLegend",
  1745. value: function renderLegend() {}
  1746. }, {
  1747. key: "setupNavigation",
  1748. value: function setupNavigation() {
  1749. var _this4 = this;
  1750. var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1751. if (!this.config.isNavigable) return;
  1752. if (init) {
  1753. this.bindOverlay();
  1754. this.keyActions = {
  1755. '13': this.onEnterKey.bind(this),
  1756. '37': this.onLeftArrow.bind(this),
  1757. '38': this.onUpArrow.bind(this),
  1758. '39': this.onRightArrow.bind(this),
  1759. '40': this.onDownArrow.bind(this)
  1760. };
  1761. document.addEventListener('keydown', function (e) {
  1762. if (isElementInViewport(_this4.container)) {
  1763. e = e || window.event;
  1764. if (_this4.keyActions[e.keyCode]) {
  1765. _this4.keyActions[e.keyCode]();
  1766. }
  1767. }
  1768. });
  1769. }
  1770. }
  1771. }, {
  1772. key: "makeOverlay",
  1773. value: function makeOverlay() {}
  1774. }, {
  1775. key: "updateOverlay",
  1776. value: function updateOverlay() {}
  1777. }, {
  1778. key: "bindOverlay",
  1779. value: function bindOverlay() {}
  1780. }, {
  1781. key: "bindUnits",
  1782. value: function bindUnits() {}
  1783. }, {
  1784. key: "onLeftArrow",
  1785. value: function onLeftArrow() {}
  1786. }, {
  1787. key: "onRightArrow",
  1788. value: function onRightArrow() {}
  1789. }, {
  1790. key: "onUpArrow",
  1791. value: function onUpArrow() {}
  1792. }, {
  1793. key: "onDownArrow",
  1794. value: function onDownArrow() {}
  1795. }, {
  1796. key: "onEnterKey",
  1797. value: function onEnterKey() {}
  1798. }, {
  1799. key: "addDataPoint",
  1800. value: function addDataPoint() {}
  1801. }, {
  1802. key: "removeDataPoint",
  1803. value: function removeDataPoint() {}
  1804. }, {
  1805. key: "getDataPoint",
  1806. value: function getDataPoint() {}
  1807. }, {
  1808. key: "setCurrentDataPoint",
  1809. value: function setCurrentDataPoint() {}
  1810. }, {
  1811. key: "updateDataset",
  1812. value: function updateDataset() {}
  1813. }, {
  1814. key: "export",
  1815. value: function _export() {
  1816. var chartSvg = prepareForExport(this.svg);
  1817. downloadFile(this.title || 'Chart', [chartSvg]);
  1818. }
  1819. }]);
  1820. return BaseChart;
  1821. }();
  1822. var AggregationChart = /*#__PURE__*/function (_BaseChart) {
  1823. _inherits(AggregationChart, _BaseChart);
  1824. var _super = _createSuper(AggregationChart);
  1825. function AggregationChart(parent, args) {
  1826. _classCallCheck(this, AggregationChart);
  1827. return _super.call(this, parent, args);
  1828. }
  1829. _createClass(AggregationChart, [{
  1830. key: "configure",
  1831. value: function configure(args) {
  1832. _get(_getPrototypeOf(AggregationChart.prototype), "configure", this).call(this, args);
  1833. this.config.maxSlices = args.maxSlices || 20;
  1834. this.config.maxLegendPoints = args.maxLegendPoints || 20;
  1835. }
  1836. }, {
  1837. key: "calc",
  1838. value: function calc() {
  1839. var _this = this;
  1840. var s = this.state;
  1841. var maxSlices = this.config.maxSlices;
  1842. s.sliceTotals = [];
  1843. var allTotals = this.data.labels.map(function (label, i) {
  1844. var total = 0;
  1845. _this.data.datasets.map(function (e) {
  1846. total += e.values[i];
  1847. });
  1848. return [total, label];
  1849. }).filter(function (d) {
  1850. return d[0] >= 0;
  1851. }); // keep only positive results
  1852. var totals = allTotals;
  1853. if (allTotals.length > maxSlices) {
  1854. // Prune and keep a grey area for rest as per maxSlices
  1855. allTotals.sort(function (a, b) {
  1856. return b[0] - a[0];
  1857. });
  1858. totals = allTotals.slice(0, maxSlices - 1);
  1859. var remaining = allTotals.slice(maxSlices - 1);
  1860. var sumOfRemaining = 0;
  1861. remaining.map(function (d) {
  1862. sumOfRemaining += d[0];
  1863. });
  1864. totals.push([sumOfRemaining, 'Rest']);
  1865. this.colors[maxSlices - 1] = 'grey';
  1866. }
  1867. s.labels = [];
  1868. totals.map(function (d) {
  1869. s.sliceTotals.push(d[0]);
  1870. s.labels.push(d[1]);
  1871. });
  1872. s.grandTotal = s.sliceTotals.reduce(function (a, b) {
  1873. return a + b;
  1874. }, 0);
  1875. this.center = {
  1876. x: this.width / 2,
  1877. y: this.height / 2
  1878. };
  1879. }
  1880. }, {
  1881. key: "renderLegend",
  1882. value: function renderLegend() {
  1883. var _this2 = this;
  1884. var s = this.state;
  1885. this.legendArea.textContent = '';
  1886. this.legendTotals = s.sliceTotals.slice(0, this.config.maxLegendPoints);
  1887. var count = 0;
  1888. var y = 0;
  1889. this.legendTotals.map(function (d, i) {
  1890. var barWidth = 150;
  1891. var divisor = Math.floor((_this2.width - getExtraWidth(_this2.measures)) / barWidth);
  1892. if (_this2.legendTotals.length < divisor) {
  1893. barWidth = _this2.width / _this2.legendTotals.length;
  1894. }
  1895. if (count > divisor) {
  1896. count = 0;
  1897. y += 20;
  1898. }
  1899. var x = barWidth * count + 5;
  1900. var label = _this2.config.truncateLegends ? truncateString(s.labels[i], barWidth / 10) : s.labels[i];
  1901. var dot = legendDot(x, y, 5, _this2.colors[i], "".concat(label, ": ").concat(d), false);
  1902. _this2.legendArea.appendChild(dot);
  1903. count++;
  1904. });
  1905. }
  1906. }]);
  1907. return AggregationChart;
  1908. }(BaseChart);
  1909. // Playing around with dates
  1910. var NO_OF_YEAR_MONTHS = 12;
  1911. var NO_OF_DAYS_IN_WEEK = 7;
  1912. var NO_OF_MILLIS = 1000;
  1913. var SEC_IN_DAY = 86400;
  1914. var MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  1915. var DAY_NAMES_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  1916. function treatAsUtc(date) {
  1917. var result = new Date(date);
  1918. result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
  1919. return result;
  1920. }
  1921. function getYyyyMmDd(date) {
  1922. var dd = date.getDate();
  1923. var mm = date.getMonth() + 1; // getMonth() is zero-based
  1924. return [date.getFullYear(), (mm > 9 ? '' : '0') + mm, (dd > 9 ? '' : '0') + dd].join('-');
  1925. }
  1926. function clone(date) {
  1927. return new Date(date.getTime());
  1928. }
  1929. function getWeeksBetween(startDate, endDate) {
  1930. var weekStartDate = setDayToSunday(startDate);
  1931. return Math.ceil(getDaysBetween(weekStartDate, endDate) / NO_OF_DAYS_IN_WEEK);
  1932. }
  1933. function getDaysBetween(startDate, endDate) {
  1934. var millisecondsPerDay = SEC_IN_DAY * NO_OF_MILLIS;
  1935. return (treatAsUtc(endDate) - treatAsUtc(startDate)) / millisecondsPerDay;
  1936. }
  1937. function areInSameMonth(startDate, endDate) {
  1938. return startDate.getMonth() === endDate.getMonth() && startDate.getFullYear() === endDate.getFullYear();
  1939. }
  1940. function getMonthName(i) {
  1941. var short = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1942. var monthName = MONTH_NAMES[i];
  1943. return short ? monthName.slice(0, 3) : monthName;
  1944. }
  1945. function getLastDateInMonth(month, year) {
  1946. return new Date(year, month + 1, 0); // 0: last day in previous month
  1947. } // mutates
  1948. function setDayToSunday(date) {
  1949. var newDate = clone(date);
  1950. var day = newDate.getDay();
  1951. if (day !== 0) {
  1952. addDays(newDate, -1 * day);
  1953. }
  1954. return newDate;
  1955. } // mutates
  1956. function addDays(date, numberOfDays) {
  1957. date.setDate(date.getDate() + numberOfDays);
  1958. }
  1959. var ChartComponent = /*#__PURE__*/function () {
  1960. function ChartComponent(_ref) {
  1961. var _ref$layerClass = _ref.layerClass,
  1962. layerClass = _ref$layerClass === void 0 ? '' : _ref$layerClass,
  1963. _ref$layerTransform = _ref.layerTransform,
  1964. layerTransform = _ref$layerTransform === void 0 ? '' : _ref$layerTransform,
  1965. constants = _ref.constants,
  1966. getData = _ref.getData,
  1967. makeElements = _ref.makeElements,
  1968. animateElements = _ref.animateElements;
  1969. _classCallCheck(this, ChartComponent);
  1970. this.layerTransform = layerTransform;
  1971. this.constants = constants;
  1972. this.makeElements = makeElements;
  1973. this.getData = getData;
  1974. this.animateElements = animateElements;
  1975. this.store = [];
  1976. this.labels = [];
  1977. this.layerClass = layerClass;
  1978. this.layerClass = typeof this.layerClass === 'function' ? this.layerClass() : this.layerClass;
  1979. this.refresh();
  1980. }
  1981. _createClass(ChartComponent, [{
  1982. key: "refresh",
  1983. value: function refresh(data) {
  1984. this.data = data || this.getData();
  1985. }
  1986. }, {
  1987. key: "setup",
  1988. value: function setup(parent) {
  1989. this.layer = makeSVGGroup(this.layerClass, this.layerTransform, parent);
  1990. }
  1991. }, {
  1992. key: "make",
  1993. value: function make() {
  1994. this.render(this.data);
  1995. this.oldData = this.data;
  1996. }
  1997. }, {
  1998. key: "render",
  1999. value: function render(data) {
  2000. var _this = this;
  2001. this.store = this.makeElements(data);
  2002. this.layer.textContent = '';
  2003. this.store.forEach(function (element) {
  2004. _this.layer.appendChild(element);
  2005. });
  2006. this.labels.forEach(function (element) {
  2007. _this.layer.appendChild(element);
  2008. });
  2009. }
  2010. }, {
  2011. key: "update",
  2012. value: function update() {
  2013. var animate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  2014. this.refresh();
  2015. var animateElements = [];
  2016. if (animate) {
  2017. animateElements = this.animateElements(this.data) || [];
  2018. }
  2019. return animateElements;
  2020. }
  2021. }]);
  2022. return ChartComponent;
  2023. }();
  2024. var componentConfigs = {
  2025. donutSlices: {
  2026. layerClass: 'donut-slices',
  2027. makeElements: function makeElements(data) {
  2028. return data.sliceStrings.map(function (s, i) {
  2029. var slice = makePath(s, 'donut-path', data.colors[i], 'none', data.strokeWidth);
  2030. slice.style.transition = 'transform .3s;';
  2031. return slice;
  2032. });
  2033. },
  2034. animateElements: function animateElements(newData) {
  2035. return this.store.map(function (slice, i) {
  2036. return animatePathStr(slice, newData.sliceStrings[i]);
  2037. });
  2038. }
  2039. },
  2040. pieSlices: {
  2041. layerClass: 'pie-slices',
  2042. makeElements: function makeElements(data) {
  2043. return data.sliceStrings.map(function (s, i) {
  2044. var slice = makePath(s, 'pie-path', 'none', data.colors[i]);
  2045. slice.style.transition = 'transform .3s;';
  2046. return slice;
  2047. });
  2048. },
  2049. animateElements: function animateElements(newData) {
  2050. return this.store.map(function (slice, i) {
  2051. return animatePathStr(slice, newData.sliceStrings[i]);
  2052. });
  2053. }
  2054. },
  2055. percentageBars: {
  2056. layerClass: 'percentage-bars',
  2057. makeElements: function makeElements(data) {
  2058. var _this2 = this;
  2059. return data.xPositions.map(function (x, i) {
  2060. var y = 0;
  2061. var bar = percentageBar(x, y, data.widths[i], _this2.constants.barHeight, _this2.constants.barDepth, data.colors[i]);
  2062. return bar;
  2063. });
  2064. },
  2065. animateElements: function animateElements(newData) {
  2066. if (newData) return [];
  2067. }
  2068. },
  2069. yAxis: {
  2070. layerClass: 'y axis',
  2071. makeElements: function makeElements(data) {
  2072. var _this3 = this;
  2073. return data.positions.map(function (position, i) {
  2074. return yLine(position, data.labels[i], _this3.constants.width, {
  2075. mode: _this3.constants.mode,
  2076. pos: _this3.constants.pos,
  2077. shortenNumbers: _this3.constants.shortenNumbers
  2078. });
  2079. });
  2080. },
  2081. animateElements: function animateElements(newData) {
  2082. var newPos = newData.positions;
  2083. var newLabels = newData.labels;
  2084. var oldPos = this.oldData.positions;
  2085. var oldLabels = this.oldData.labels;
  2086. var _equilizeNoOfElements = equilizeNoOfElements(oldPos, newPos);
  2087. var _equilizeNoOfElements2 = _slicedToArray(_equilizeNoOfElements, 2);
  2088. oldPos = _equilizeNoOfElements2[0];
  2089. newPos = _equilizeNoOfElements2[1];
  2090. var _equilizeNoOfElements3 = equilizeNoOfElements(oldLabels, newLabels);
  2091. var _equilizeNoOfElements4 = _slicedToArray(_equilizeNoOfElements3, 2);
  2092. oldLabels = _equilizeNoOfElements4[0];
  2093. newLabels = _equilizeNoOfElements4[1];
  2094. this.render({
  2095. positions: oldPos,
  2096. labels: newLabels
  2097. });
  2098. return this.store.map(function (line, i) {
  2099. return translateHoriLine(line, newPos[i], oldPos[i]);
  2100. });
  2101. }
  2102. },
  2103. xAxis: {
  2104. layerClass: 'x axis',
  2105. makeElements: function makeElements(data) {
  2106. var _this4 = this;
  2107. return data.positions.map(function (position, i) {
  2108. return xLine(position, data.calcLabels[i], _this4.constants.height, {
  2109. mode: _this4.constants.mode,
  2110. pos: _this4.constants.pos
  2111. });
  2112. });
  2113. },
  2114. animateElements: function animateElements(newData) {
  2115. var newPos = newData.positions;
  2116. var newLabels = newData.calcLabels;
  2117. var oldPos = this.oldData.positions;
  2118. var oldLabels = this.oldData.calcLabels;
  2119. var _equilizeNoOfElements5 = equilizeNoOfElements(oldPos, newPos);
  2120. var _equilizeNoOfElements6 = _slicedToArray(_equilizeNoOfElements5, 2);
  2121. oldPos = _equilizeNoOfElements6[0];
  2122. newPos = _equilizeNoOfElements6[1];
  2123. var _equilizeNoOfElements7 = equilizeNoOfElements(oldLabels, newLabels);
  2124. var _equilizeNoOfElements8 = _slicedToArray(_equilizeNoOfElements7, 2);
  2125. oldLabels = _equilizeNoOfElements8[0];
  2126. newLabels = _equilizeNoOfElements8[1];
  2127. this.render({
  2128. positions: oldPos,
  2129. calcLabels: newLabels
  2130. });
  2131. return this.store.map(function (line, i) {
  2132. return translateVertLine(line, newPos[i], oldPos[i]);
  2133. });
  2134. }
  2135. },
  2136. yMarkers: {
  2137. layerClass: 'y-markers',
  2138. makeElements: function makeElements(data) {
  2139. var _this5 = this;
  2140. return data.map(function (m) {
  2141. return yMarker(m.position, m.label, _this5.constants.width, {
  2142. labelPos: m.options.labelPos,
  2143. mode: 'span',
  2144. lineType: 'dashed'
  2145. });
  2146. });
  2147. },
  2148. animateElements: function animateElements(newData) {
  2149. var _equilizeNoOfElements9 = equilizeNoOfElements(this.oldData, newData);
  2150. var _equilizeNoOfElements10 = _slicedToArray(_equilizeNoOfElements9, 2);
  2151. this.oldData = _equilizeNoOfElements10[0];
  2152. newData = _equilizeNoOfElements10[1];
  2153. var newPos = newData.map(function (d) {
  2154. return d.position;
  2155. });
  2156. var newLabels = newData.map(function (d) {
  2157. return d.label;
  2158. });
  2159. var newOptions = newData.map(function (d) {
  2160. return d.options;
  2161. });
  2162. var oldPos = this.oldData.map(function (d) {
  2163. return d.position;
  2164. });
  2165. this.render(oldPos.map(function (pos, i) {
  2166. return {
  2167. position: oldPos[i],
  2168. label: newLabels[i],
  2169. options: newOptions[i]
  2170. };
  2171. }));
  2172. return this.store.map(function (line, i) {
  2173. return translateHoriLine(line, newPos[i], oldPos[i]);
  2174. });
  2175. }
  2176. },
  2177. yRegions: {
  2178. layerClass: 'y-regions',
  2179. makeElements: function makeElements(data) {
  2180. var _this6 = this;
  2181. return data.map(function (r) {
  2182. return yRegion(r.startPos, r.endPos, _this6.constants.width, r.label, {
  2183. labelPos: r.options.labelPos
  2184. });
  2185. });
  2186. },
  2187. animateElements: function animateElements(newData) {
  2188. var _equilizeNoOfElements11 = equilizeNoOfElements(this.oldData, newData);
  2189. var _equilizeNoOfElements12 = _slicedToArray(_equilizeNoOfElements11, 2);
  2190. this.oldData = _equilizeNoOfElements12[0];
  2191. newData = _equilizeNoOfElements12[1];
  2192. var newPos = newData.map(function (d) {
  2193. return d.endPos;
  2194. });
  2195. var newLabels = newData.map(function (d) {
  2196. return d.label;
  2197. });
  2198. var newStarts = newData.map(function (d) {
  2199. return d.startPos;
  2200. });
  2201. var newOptions = newData.map(function (d) {
  2202. return d.options;
  2203. });
  2204. var oldPos = this.oldData.map(function (d) {
  2205. return d.endPos;
  2206. });
  2207. var oldStarts = this.oldData.map(function (d) {
  2208. return d.startPos;
  2209. });
  2210. this.render(oldPos.map(function (pos, i) {
  2211. return {
  2212. startPos: oldStarts[i],
  2213. endPos: oldPos[i],
  2214. label: newLabels[i],
  2215. options: newOptions[i]
  2216. };
  2217. }));
  2218. var animateElements = [];
  2219. this.store.map(function (rectGroup, i) {
  2220. animateElements = animateElements.concat(animateRegion(rectGroup, newStarts[i], newPos[i], oldPos[i]));
  2221. });
  2222. return animateElements;
  2223. }
  2224. },
  2225. heatDomain: {
  2226. layerClass: function layerClass() {
  2227. return 'heat-domain domain-' + this.constants.index;
  2228. },
  2229. makeElements: function makeElements(data) {
  2230. var _this7 = this;
  2231. var _this$constants = this.constants,
  2232. index = _this$constants.index,
  2233. colWidth = _this$constants.colWidth,
  2234. rowHeight = _this$constants.rowHeight,
  2235. squareSize = _this$constants.squareSize,
  2236. radius = _this$constants.radius,
  2237. xTranslate = _this$constants.xTranslate;
  2238. var monthNameHeight = -12;
  2239. var x = xTranslate,
  2240. y = 0;
  2241. this.serializedSubDomains = [];
  2242. data.cols.map(function (week, weekNo) {
  2243. if (weekNo === 1) {
  2244. _this7.labels.push(makeText('domain-name', x, monthNameHeight, getMonthName(index, true).toUpperCase(), {
  2245. fontSize: 9
  2246. }));
  2247. }
  2248. week.map(function (day, i) {
  2249. if (day.fill) {
  2250. var _data = {
  2251. 'data-date': day.yyyyMmDd,
  2252. 'data-value': day.dataValue,
  2253. 'data-day': i
  2254. };
  2255. var square = heatSquare('day', x, y, squareSize, radius, day.fill, _data);
  2256. _this7.serializedSubDomains.push(square);
  2257. }
  2258. y += rowHeight;
  2259. });
  2260. y = 0;
  2261. x += colWidth;
  2262. });
  2263. return this.serializedSubDomains;
  2264. },
  2265. animateElements: function animateElements(newData) {
  2266. if (newData) return [];
  2267. }
  2268. },
  2269. barGraph: {
  2270. layerClass: function layerClass() {
  2271. return 'dataset-units dataset-bars dataset-' + this.constants.index;
  2272. },
  2273. makeElements: function makeElements(data) {
  2274. var c = this.constants;
  2275. this.unitType = 'bar';
  2276. this.units = data.yPositions.map(function (y, j) {
  2277. return datasetBar(data.xPositions[j], y, data.barWidth, c.color, data.labels[j], j, data.offsets[j], {
  2278. zeroLine: data.zeroLine,
  2279. barsWidth: data.barsWidth,
  2280. minHeight: c.minHeight
  2281. });
  2282. });
  2283. return this.units;
  2284. },
  2285. animateElements: function animateElements(newData) {
  2286. var newXPos = newData.xPositions;
  2287. var newYPos = newData.yPositions;
  2288. var newOffsets = newData.offsets;
  2289. var newLabels = newData.labels;
  2290. var oldXPos = this.oldData.xPositions;
  2291. var oldYPos = this.oldData.yPositions;
  2292. var oldOffsets = this.oldData.offsets;
  2293. var oldLabels = this.oldData.labels;
  2294. var _equilizeNoOfElements13 = equilizeNoOfElements(oldXPos, newXPos);
  2295. var _equilizeNoOfElements14 = _slicedToArray(_equilizeNoOfElements13, 2);
  2296. oldXPos = _equilizeNoOfElements14[0];
  2297. newXPos = _equilizeNoOfElements14[1];
  2298. var _equilizeNoOfElements15 = equilizeNoOfElements(oldYPos, newYPos);
  2299. var _equilizeNoOfElements16 = _slicedToArray(_equilizeNoOfElements15, 2);
  2300. oldYPos = _equilizeNoOfElements16[0];
  2301. newYPos = _equilizeNoOfElements16[1];
  2302. var _equilizeNoOfElements17 = equilizeNoOfElements(oldOffsets, newOffsets);
  2303. var _equilizeNoOfElements18 = _slicedToArray(_equilizeNoOfElements17, 2);
  2304. oldOffsets = _equilizeNoOfElements18[0];
  2305. newOffsets = _equilizeNoOfElements18[1];
  2306. var _equilizeNoOfElements19 = equilizeNoOfElements(oldLabels, newLabels);
  2307. var _equilizeNoOfElements20 = _slicedToArray(_equilizeNoOfElements19, 2);
  2308. oldLabels = _equilizeNoOfElements20[0];
  2309. newLabels = _equilizeNoOfElements20[1];
  2310. this.render({
  2311. xPositions: oldXPos,
  2312. yPositions: oldYPos,
  2313. offsets: oldOffsets,
  2314. labels: newLabels,
  2315. zeroLine: this.oldData.zeroLine,
  2316. barsWidth: this.oldData.barsWidth,
  2317. barWidth: this.oldData.barWidth
  2318. });
  2319. var animateElements = [];
  2320. this.store.map(function (bar, i) {
  2321. animateElements = animateElements.concat(animateBar(bar, newXPos[i], newYPos[i], newData.barWidth, newOffsets[i], {
  2322. zeroLine: newData.zeroLine
  2323. }));
  2324. });
  2325. return animateElements;
  2326. }
  2327. },
  2328. lineGraph: {
  2329. layerClass: function layerClass() {
  2330. return 'dataset-units dataset-line dataset-' + this.constants.index;
  2331. },
  2332. makeElements: function makeElements(data) {
  2333. var c = this.constants;
  2334. this.unitType = 'dot';
  2335. this.paths = {};
  2336. if (!c.hideLine) {
  2337. this.paths = getPaths(data.xPositions, data.yPositions, c.color, {
  2338. heatline: c.heatline,
  2339. regionFill: c.regionFill,
  2340. spline: c.spline
  2341. }, {
  2342. svgDefs: c.svgDefs,
  2343. zeroLine: data.zeroLine
  2344. });
  2345. }
  2346. this.units = [];
  2347. if (!c.hideDots) {
  2348. this.units = data.yPositions.map(function (y, j) {
  2349. return datasetDot(data.xPositions[j], y, data.radius, c.color, c.valuesOverPoints ? data.values[j] : '', j);
  2350. });
  2351. }
  2352. return Object.values(this.paths).concat(this.units);
  2353. },
  2354. animateElements: function animateElements(newData) {
  2355. var newXPos = newData.xPositions;
  2356. var newYPos = newData.yPositions;
  2357. var newValues = newData.values;
  2358. var oldXPos = this.oldData.xPositions;
  2359. var oldYPos = this.oldData.yPositions;
  2360. var oldValues = this.oldData.values;
  2361. var _equilizeNoOfElements21 = equilizeNoOfElements(oldXPos, newXPos);
  2362. var _equilizeNoOfElements22 = _slicedToArray(_equilizeNoOfElements21, 2);
  2363. oldXPos = _equilizeNoOfElements22[0];
  2364. newXPos = _equilizeNoOfElements22[1];
  2365. var _equilizeNoOfElements23 = equilizeNoOfElements(oldYPos, newYPos);
  2366. var _equilizeNoOfElements24 = _slicedToArray(_equilizeNoOfElements23, 2);
  2367. oldYPos = _equilizeNoOfElements24[0];
  2368. newYPos = _equilizeNoOfElements24[1];
  2369. var _equilizeNoOfElements25 = equilizeNoOfElements(oldValues, newValues);
  2370. var _equilizeNoOfElements26 = _slicedToArray(_equilizeNoOfElements25, 2);
  2371. oldValues = _equilizeNoOfElements26[0];
  2372. newValues = _equilizeNoOfElements26[1];
  2373. this.render({
  2374. xPositions: oldXPos,
  2375. yPositions: oldYPos,
  2376. values: newValues,
  2377. zeroLine: this.oldData.zeroLine,
  2378. radius: this.oldData.radius
  2379. });
  2380. var animateElements = [];
  2381. if (Object.keys(this.paths).length) {
  2382. animateElements = animateElements.concat(animatePath(this.paths, newXPos, newYPos, newData.zeroLine, this.constants.spline));
  2383. }
  2384. if (this.units.length) {
  2385. this.units.map(function (dot, i) {
  2386. animateElements = animateElements.concat(animateDot(dot, newXPos[i], newYPos[i]));
  2387. });
  2388. }
  2389. return animateElements;
  2390. }
  2391. }
  2392. };
  2393. function getComponent(name, constants, getData) {
  2394. var keys = Object.keys(componentConfigs).filter(function (k) {
  2395. return name.includes(k);
  2396. });
  2397. var config = componentConfigs[keys[0]];
  2398. Object.assign(config, {
  2399. constants: constants,
  2400. getData: getData
  2401. });
  2402. return new ChartComponent(config);
  2403. }
  2404. var PercentageChart = /*#__PURE__*/function (_AggregationChart) {
  2405. _inherits(PercentageChart, _AggregationChart);
  2406. var _super = _createSuper(PercentageChart);
  2407. function PercentageChart(parent, args) {
  2408. var _this;
  2409. _classCallCheck(this, PercentageChart);
  2410. _this = _super.call(this, parent, args);
  2411. _this.type = 'percentage';
  2412. _this.setup();
  2413. return _this;
  2414. }
  2415. _createClass(PercentageChart, [{
  2416. key: "setMeasures",
  2417. value: function setMeasures(options) {
  2418. var m = this.measures;
  2419. this.barOptions = options.barOptions || {};
  2420. var b = this.barOptions;
  2421. b.height = b.height || PERCENTAGE_BAR_DEFAULT_HEIGHT;
  2422. b.depth = b.depth || PERCENTAGE_BAR_DEFAULT_DEPTH;
  2423. m.paddings.right = 30;
  2424. m.legendHeight = 60;
  2425. m.baseHeight = (b.height + b.depth * 0.5) * 8;
  2426. }
  2427. }, {
  2428. key: "setupComponents",
  2429. value: function setupComponents() {
  2430. var s = this.state;
  2431. var componentConfigs = [['percentageBars', {
  2432. barHeight: this.barOptions.height,
  2433. barDepth: this.barOptions.depth
  2434. }, function () {
  2435. return {
  2436. xPositions: s.xPositions,
  2437. widths: s.widths,
  2438. colors: this.colors
  2439. };
  2440. }.bind(this)]];
  2441. this.components = new Map(componentConfigs.map(function (args) {
  2442. var component = getComponent.apply(void 0, _toConsumableArray(args));
  2443. return [args[0], component];
  2444. }));
  2445. }
  2446. }, {
  2447. key: "calc",
  2448. value: function calc() {
  2449. var _this2 = this;
  2450. _get(_getPrototypeOf(PercentageChart.prototype), "calc", this).call(this);
  2451. var s = this.state;
  2452. s.xPositions = [];
  2453. s.widths = [];
  2454. var xPos = 0;
  2455. s.sliceTotals.map(function (value) {
  2456. var width = _this2.width * value / s.grandTotal;
  2457. s.widths.push(width);
  2458. s.xPositions.push(xPos);
  2459. xPos += width;
  2460. });
  2461. }
  2462. }, {
  2463. key: "makeDataByIndex",
  2464. value: function makeDataByIndex() {}
  2465. }, {
  2466. key: "bindTooltip",
  2467. value: function bindTooltip() {
  2468. var _this3 = this;
  2469. var s = this.state;
  2470. this.container.addEventListener('mousemove', function (e) {
  2471. var bars = _this3.components.get('percentageBars').store;
  2472. var bar = e.target;
  2473. if (bars.includes(bar)) {
  2474. var i = bars.indexOf(bar);
  2475. var gOff = getOffset(_this3.container),
  2476. pOff = getOffset(bar);
  2477. var x = pOff.left - gOff.left + parseInt(bar.getAttribute('width')) / 2;
  2478. var y = pOff.top - gOff.top;
  2479. var title = (_this3.formattedLabels && _this3.formattedLabels.length > 0 ? _this3.formattedLabels[i] : _this3.state.labels[i]) + ': ';
  2480. var fraction = s.sliceTotals[i] / s.grandTotal;
  2481. _this3.tip.setValues(x, y, {
  2482. name: title,
  2483. value: (fraction * 100).toFixed(1) + "%"
  2484. });
  2485. _this3.tip.showTip();
  2486. }
  2487. });
  2488. }
  2489. }]);
  2490. return PercentageChart;
  2491. }(AggregationChart);
  2492. var PieChart = /*#__PURE__*/function (_AggregationChart) {
  2493. _inherits(PieChart, _AggregationChart);
  2494. var _super = _createSuper(PieChart);
  2495. function PieChart(parent, args) {
  2496. var _this;
  2497. _classCallCheck(this, PieChart);
  2498. _this = _super.call(this, parent, args);
  2499. _this.type = 'pie';
  2500. _this.initTimeout = 0;
  2501. _this.init = 1;
  2502. _this.setup();
  2503. return _this;
  2504. }
  2505. _createClass(PieChart, [{
  2506. key: "configure",
  2507. value: function configure(args) {
  2508. _get(_getPrototypeOf(PieChart.prototype), "configure", this).call(this, args);
  2509. this.mouseMove = this.mouseMove.bind(this);
  2510. this.mouseLeave = this.mouseLeave.bind(this);
  2511. this.hoverRadio = args.hoverRadio || 0.1;
  2512. this.config.startAngle = args.startAngle || 0;
  2513. this.clockWise = args.clockWise || false;
  2514. }
  2515. }, {
  2516. key: "calc",
  2517. value: function calc() {
  2518. var _this2 = this;
  2519. _get(_getPrototypeOf(PieChart.prototype), "calc", this).call(this);
  2520. var s = this.state;
  2521. this.radius = this.height > this.width ? this.center.x : this.center.y;
  2522. var radius = this.radius,
  2523. clockWise = this.clockWise;
  2524. var prevSlicesProperties = s.slicesProperties || [];
  2525. s.sliceStrings = [];
  2526. s.slicesProperties = [];
  2527. var curAngle = 180 - this.config.startAngle;
  2528. s.sliceTotals.map(function (total, i) {
  2529. var startAngle = curAngle;
  2530. var originDiffAngle = total / s.grandTotal * FULL_ANGLE;
  2531. var largeArc = originDiffAngle > 180 ? 1 : 0;
  2532. var diffAngle = clockWise ? -originDiffAngle : originDiffAngle;
  2533. var endAngle = curAngle = curAngle + diffAngle;
  2534. var startPosition = getPositionByAngle(startAngle, radius);
  2535. var endPosition = getPositionByAngle(endAngle, radius);
  2536. var prevProperty = _this2.init && prevSlicesProperties[i];
  2537. var curStart, curEnd;
  2538. if (_this2.init) {
  2539. curStart = prevProperty ? prevProperty.startPosition : startPosition;
  2540. curEnd = prevProperty ? prevProperty.endPosition : startPosition;
  2541. } else {
  2542. curStart = startPosition;
  2543. curEnd = endPosition;
  2544. }
  2545. var curPath = originDiffAngle === 360 ? makeCircleStr(curStart, curEnd, _this2.center, _this2.radius, clockWise, largeArc) : makeArcPathStr(curStart, curEnd, _this2.center, _this2.radius, clockWise, largeArc);
  2546. s.sliceStrings.push(curPath);
  2547. s.slicesProperties.push({
  2548. startPosition: startPosition,
  2549. endPosition: endPosition,
  2550. value: total,
  2551. total: s.grandTotal,
  2552. startAngle: startAngle,
  2553. endAngle: endAngle,
  2554. angle: diffAngle
  2555. });
  2556. });
  2557. this.init = 0;
  2558. }
  2559. }, {
  2560. key: "setupComponents",
  2561. value: function setupComponents() {
  2562. var s = this.state;
  2563. var componentConfigs = [['pieSlices', {}, function () {
  2564. return {
  2565. sliceStrings: s.sliceStrings,
  2566. colors: this.colors
  2567. };
  2568. }.bind(this)]];
  2569. this.components = new Map(componentConfigs.map(function (args) {
  2570. var component = getComponent.apply(void 0, _toConsumableArray(args));
  2571. return [args[0], component];
  2572. }));
  2573. }
  2574. }, {
  2575. key: "calTranslateByAngle",
  2576. value: function calTranslateByAngle(property) {
  2577. var radius = this.radius,
  2578. hoverRadio = this.hoverRadio;
  2579. var position = getPositionByAngle(property.startAngle + property.angle / 2, radius);
  2580. return "translate3d(".concat(position.x * hoverRadio, "px,").concat(position.y * hoverRadio, "px,0)");
  2581. }
  2582. }, {
  2583. key: "hoverSlice",
  2584. value: function hoverSlice(path, i, flag, e) {
  2585. if (!path) return;
  2586. var color = this.colors[i];
  2587. if (flag) {
  2588. transform(path, this.calTranslateByAngle(this.state.slicesProperties[i]));
  2589. path.style.fill = lightenDarkenColor(color, 50);
  2590. var g_off = getOffset(this.svg);
  2591. var x = e.pageX - g_off.left + 10;
  2592. var y = e.pageY - g_off.top - 10;
  2593. var title = (this.formatted_labels && this.formatted_labels.length > 0 ? this.formatted_labels[i] : this.state.labels[i]) + ': ';
  2594. var percent = (this.state.sliceTotals[i] * 100 / this.state.grandTotal).toFixed(1);
  2595. this.tip.setValues(x, y, {
  2596. name: title,
  2597. value: percent + "%"
  2598. });
  2599. this.tip.showTip();
  2600. } else {
  2601. transform(path, 'translate3d(0,0,0)');
  2602. this.tip.hideTip();
  2603. path.style.fill = color;
  2604. }
  2605. }
  2606. }, {
  2607. key: "bindTooltip",
  2608. value: function bindTooltip() {
  2609. this.container.addEventListener('mousemove', this.mouseMove);
  2610. this.container.addEventListener('mouseleave', this.mouseLeave);
  2611. }
  2612. }, {
  2613. key: "mouseMove",
  2614. value: function mouseMove(e) {
  2615. var target = e.target;
  2616. var slices = this.components.get('pieSlices').store;
  2617. var prevIndex = this.curActiveSliceIndex;
  2618. var prevAcitve = this.curActiveSlice;
  2619. if (slices.includes(target)) {
  2620. var i = slices.indexOf(target);
  2621. this.hoverSlice(prevAcitve, prevIndex, false);
  2622. this.curActiveSlice = target;
  2623. this.curActiveSliceIndex = i;
  2624. this.hoverSlice(target, i, true, e);
  2625. } else {
  2626. this.mouseLeave();
  2627. }
  2628. }
  2629. }, {
  2630. key: "mouseLeave",
  2631. value: function mouseLeave() {
  2632. this.hoverSlice(this.curActiveSlice, this.curActiveSliceIndex, false);
  2633. }
  2634. }]);
  2635. return PieChart;
  2636. }(AggregationChart);
  2637. function normalize(x) {
  2638. // Calculates mantissa and exponent of a number
  2639. // Returns normalized number and exponent
  2640. // https://stackoverflow.com/q/9383593/6495043
  2641. if (x === 0) {
  2642. return [0, 0];
  2643. }
  2644. if (isNaN(x)) {
  2645. return {
  2646. mantissa: -6755399441055744,
  2647. exponent: 972
  2648. };
  2649. }
  2650. var sig = x > 0 ? 1 : -1;
  2651. if (!isFinite(x)) {
  2652. return {
  2653. mantissa: sig * 4503599627370496,
  2654. exponent: 972
  2655. };
  2656. }
  2657. x = Math.abs(x);
  2658. var exp = Math.floor(Math.log10(x));
  2659. var man = x / Math.pow(10, exp);
  2660. return [sig * man, exp];
  2661. }
  2662. function getChartRangeIntervals(max) {
  2663. var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  2664. var upperBound = Math.ceil(max);
  2665. var lowerBound = Math.floor(min);
  2666. var range = upperBound - lowerBound;
  2667. var noOfParts = range;
  2668. var partSize = 1; // To avoid too many partitions
  2669. if (range > 5) {
  2670. if (range % 2 !== 0) {
  2671. upperBound++; // Recalc range
  2672. range = upperBound - lowerBound;
  2673. }
  2674. if(maxValue >= absMinValue) {
  2675. exponent = normalize(maxValue)[1];
  2676. intervals = getPositiveFirstIntervals(maxValue, absMinValue);
  2677. } else {
  2678. // Mirror: maxValue => absMinValue, then change sign
  2679. exponent = normalize(absMinValue)[1];
  2680. let posIntervals = getPositiveFirstIntervals(absMinValue, maxValue);
  2681. intervals = posIntervals.reverse().map(d => d * (-1));
  2682. }
  2683. if (range <= 2) {
  2684. noOfParts = 4;
  2685. partSize = range / noOfParts;
  2686. } // Special case: 0
  2687. if (range === 0) {
  2688. noOfParts = 5;
  2689. partSize = 1;
  2690. }
  2691. var intervals = [];
  2692. for (var i = 0; i <= noOfParts; i++) {
  2693. intervals.push(lowerBound + partSize * i);
  2694. }
  2695. return intervals;
  2696. }
  2697. function getChartIntervals(maxValue) {
  2698. var minValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  2699. var _normalize = normalize(maxValue),
  2700. _normalize2 = _slicedToArray(_normalize, 2),
  2701. normalMaxValue = _normalize2[0],
  2702. exponent = _normalize2[1];
  2703. var normalMinValue = minValue ? minValue / Math.pow(10, exponent) : 0; // Allow only 7 significant digits
  2704. normalMaxValue = normalMaxValue.toFixed(6);
  2705. var intervals = getChartRangeIntervals(normalMaxValue, normalMinValue);
  2706. intervals = intervals.map(function (value) {
  2707. return value * Math.pow(10, exponent);
  2708. });
  2709. return intervals;
  2710. }
  2711. function calcChartIntervals(values) {
  2712. var withMinimum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2713. //*** Where the magic happens ***
  2714. // Calculates best-fit y intervals from given values
  2715. // and returns the interval array
  2716. var maxValue = Math.max.apply(Math, _toConsumableArray(values));
  2717. var minValue = Math.min.apply(Math, _toConsumableArray(values)); // Exponent to be used for pretty print
  2718. var exponent = 0,
  2719. intervals = []; // eslint-disable-line no-unused-vars
  2720. function getPositiveFirstIntervals(maxValue, absMinValue) {
  2721. var intervals = getChartIntervals(maxValue);
  2722. var intervalSize = intervals[1] - intervals[0]; // Then unshift the negative values
  2723. var value = 0;
  2724. for (var i = 1; value < absMinValue; i++) {
  2725. value += intervalSize;
  2726. intervals.unshift(-1 * value);
  2727. }
  2728. return intervals;
  2729. } // CASE I: Both non-negative
  2730. if (maxValue >= 0 && minValue >= 0) {
  2731. exponent = normalize(maxValue)[1];
  2732. if (!withMinimum) {
  2733. intervals = getChartIntervals(maxValue);
  2734. } else {
  2735. intervals = getChartIntervals(maxValue, minValue);
  2736. }
  2737. } // CASE II: Only minValue negative
  2738. else if (maxValue > 0 && minValue < 0) {
  2739. // `withMinimum` irrelevant in this case,
  2740. // We'll be handling both sides of zero separately
  2741. // (both starting from zero)
  2742. // Because ceil() and floor() behave differently
  2743. // in those two regions
  2744. var absMinValue = Math.abs(minValue);
  2745. if (maxValue >= absMinValue) {
  2746. exponent = normalize(maxValue)[1];
  2747. intervals = getPositiveFirstIntervals(maxValue, absMinValue);
  2748. } else {
  2749. // Mirror: maxValue => absMinValue, then change sign
  2750. exponent = normalize(absMinValue)[1];
  2751. var posIntervals = getPositiveFirstIntervals(absMinValue, maxValue);
  2752. intervals = posIntervals.map(function (d) {
  2753. return d * -1;
  2754. });
  2755. }
  2756. } // CASE III: Both non-positive
  2757. else if (maxValue <= 0 && minValue <= 0) {
  2758. // Mirrored Case I:
  2759. // Work with positives, then reverse the sign and array
  2760. var pseudoMaxValue = Math.abs(minValue);
  2761. var pseudoMinValue = Math.abs(maxValue);
  2762. exponent = normalize(pseudoMaxValue)[1];
  2763. if (!withMinimum) {
  2764. intervals = getChartIntervals(pseudoMaxValue);
  2765. } else {
  2766. intervals = getChartIntervals(pseudoMaxValue, pseudoMinValue);
  2767. }
  2768. intervals = intervals.reverse().map(function (d) {
  2769. return d * -1;
  2770. });
  2771. }
  2772. return intervals;
  2773. }
  2774. function getZeroIndex(yPts) {
  2775. var zeroIndex;
  2776. var interval = getIntervalSize(yPts);
  2777. if (yPts.indexOf(0) >= 0) {
  2778. // the range has a given zero
  2779. // zero-line on the chart
  2780. zeroIndex = yPts.indexOf(0);
  2781. } else if (yPts[0] > 0) {
  2782. // Minimum value is positive
  2783. // zero-line is off the chart: below
  2784. var min = yPts[0];
  2785. zeroIndex = -1 * min / interval;
  2786. } else {
  2787. // Maximum value is negative
  2788. // zero-line is off the chart: above
  2789. var max = yPts[yPts.length - 1];
  2790. zeroIndex = -1 * max / interval + (yPts.length - 1);
  2791. }
  2792. return zeroIndex;
  2793. }
  2794. function getIntervalSize(orderedArray) {
  2795. return orderedArray[1] - orderedArray[0];
  2796. }
  2797. function getValueRange(orderedArray) {
  2798. return orderedArray[orderedArray.length - 1] - orderedArray[0];
  2799. }
  2800. function scale(val, yAxis) {
  2801. return floatTwo(yAxis.zeroLine - val * yAxis.scaleMultiplier);
  2802. }
  2803. function getClosestInArray(goal, arr) {
  2804. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  2805. var closest = arr.reduce(function (prev, curr) {
  2806. return Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev;
  2807. }, []);
  2808. return index ? arr.indexOf(closest) : closest;
  2809. }
  2810. function calcDistribution(values, distributionSize) {
  2811. // Assume non-negative values,
  2812. // implying distribution minimum at zero
  2813. var dataMaxValue = Math.max.apply(Math, _toConsumableArray(values));
  2814. var distributionStep = 1 / (distributionSize - 1);
  2815. var distribution = [];
  2816. for (var i = 0; i < distributionSize; i++) {
  2817. var checkpoint = dataMaxValue * (distributionStep * i);
  2818. distribution.push(checkpoint);
  2819. }
  2820. return distribution;
  2821. }
  2822. function getMaxCheckpoint(value, distribution) {
  2823. return distribution.filter(function (d) {
  2824. return d < value;
  2825. }).length;
  2826. }
  2827. var COL_WIDTH = HEATMAP_SQUARE_SIZE + HEATMAP_GUTTER_SIZE;
  2828. var ROW_HEIGHT = COL_WIDTH; // const DAY_INCR = 1;
  2829. var Heatmap = /*#__PURE__*/function (_BaseChart) {
  2830. _inherits(Heatmap, _BaseChart);
  2831. var _super = _createSuper(Heatmap);
  2832. function Heatmap(parent, options) {
  2833. var _this;
  2834. _classCallCheck(this, Heatmap);
  2835. _this = _super.call(this, parent, options);
  2836. _this.type = 'heatmap';
  2837. _this.countLabel = options.countLabel || '';
  2838. var validStarts = ['Sunday', 'Monday'];
  2839. var startSubDomain = validStarts.includes(options.startSubDomain) ? options.startSubDomain : 'Sunday';
  2840. _this.startSubDomainIndex = validStarts.indexOf(startSubDomain);
  2841. _this.setup();
  2842. return _this;
  2843. }
  2844. _createClass(Heatmap, [{
  2845. key: "setMeasures",
  2846. value: function setMeasures(options) {
  2847. var m = this.measures;
  2848. this.discreteDomains = options.discreteDomains === 0 ? 0 : 1;
  2849. m.paddings.top = ROW_HEIGHT * 3;
  2850. m.paddings.bottom = 0;
  2851. m.legendHeight = ROW_HEIGHT * 2;
  2852. m.baseHeight = ROW_HEIGHT * NO_OF_DAYS_IN_WEEK + getExtraHeight(m);
  2853. var d = this.data;
  2854. var spacing = this.discreteDomains ? NO_OF_YEAR_MONTHS : 0;
  2855. this.independentWidth = (getWeeksBetween(d.start, d.end) + spacing) * COL_WIDTH + getExtraWidth(m);
  2856. }
  2857. }, {
  2858. key: "updateWidth",
  2859. value: function updateWidth() {
  2860. var spacing = this.discreteDomains ? NO_OF_YEAR_MONTHS : 0;
  2861. var noOfWeeks = this.state.noOfWeeks ? this.state.noOfWeeks : 52;
  2862. this.baseWidth = (noOfWeeks + spacing) * COL_WIDTH + getExtraWidth(this.measures);
  2863. }
  2864. }, {
  2865. key: "prepareData",
  2866. value: function prepareData() {
  2867. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.data;
  2868. if (data.start && data.end && data.start > data.end) {
  2869. throw new Error('Start date cannot be greater than end date.');
  2870. }
  2871. if (!data.start) {
  2872. data.start = new Date();
  2873. data.start.setFullYear(data.start.getFullYear() - 1);
  2874. }
  2875. if (!data.end) {
  2876. data.end = new Date();
  2877. }
  2878. data.dataPoints = data.dataPoints || {};
  2879. if (parseInt(Object.keys(data.dataPoints)[0]) > 100000) {
  2880. var points = {};
  2881. Object.keys(data.dataPoints).forEach(function (timestampSec) {
  2882. var date = new Date(timestampSec * NO_OF_MILLIS);
  2883. points[getYyyyMmDd(date)] = data.dataPoints[timestampSec];
  2884. });
  2885. data.dataPoints = points;
  2886. }
  2887. return data;
  2888. }
  2889. }, {
  2890. key: "calc",
  2891. value: function calc() {
  2892. var s = this.state;
  2893. s.start = clone(this.data.start);
  2894. s.end = clone(this.data.end);
  2895. s.firstWeekStart = clone(s.start);
  2896. s.noOfWeeks = getWeeksBetween(s.start, s.end);
  2897. s.distribution = calcDistribution(Object.values(this.data.dataPoints), HEATMAP_DISTRIBUTION_SIZE);
  2898. s.domainConfigs = this.getDomains();
  2899. }
  2900. }, {
  2901. key: "setupComponents",
  2902. value: function setupComponents() {
  2903. var _this2 = this;
  2904. var s = this.state;
  2905. var lessCol = this.discreteDomains ? 0 : 1;
  2906. var componentConfigs = s.domainConfigs.map(function (config, i) {
  2907. return ['heatDomain', {
  2908. index: config.index,
  2909. colWidth: COL_WIDTH,
  2910. rowHeight: ROW_HEIGHT,
  2911. squareSize: HEATMAP_SQUARE_SIZE,
  2912. radius: _this2.rawChartArgs.radius || 0,
  2913. xTranslate: s.domainConfigs.filter(function (config, j) {
  2914. return j < i;
  2915. }).map(function (config) {
  2916. return config.cols.length - lessCol;
  2917. }).reduce(function (a, b) {
  2918. return a + b;
  2919. }, 0) * COL_WIDTH
  2920. }, function () {
  2921. return s.domainConfigs[i];
  2922. }.bind(_this2)];
  2923. });
  2924. this.components = new Map(componentConfigs.map(function (args, i) {
  2925. var component = getComponent.apply(void 0, _toConsumableArray(args));
  2926. return [args[0] + '-' + i, component];
  2927. }));
  2928. var y = 0;
  2929. DAY_NAMES_SHORT.forEach(function (dayName, i) {
  2930. if ([1, 3, 5].includes(i)) {
  2931. var dayText = makeText('subdomain-name', -COL_WIDTH / 2, y, dayName, {
  2932. fontSize: HEATMAP_SQUARE_SIZE,
  2933. dy: 8,
  2934. textAnchor: 'end'
  2935. });
  2936. _this2.drawArea.appendChild(dayText);
  2937. }
  2938. y += ROW_HEIGHT;
  2939. });
  2940. }
  2941. }, {
  2942. key: "update",
  2943. value: function update(data) {
  2944. if (!data) {
  2945. console.error('No data to update.');
  2946. }
  2947. this.data = this.prepareData(data);
  2948. this.draw();
  2949. this.bindTooltip();
  2950. }
  2951. }, {
  2952. key: "bindTooltip",
  2953. value: function bindTooltip() {
  2954. var _this3 = this;
  2955. this.container.addEventListener('mousemove', function (e) {
  2956. _this3.components.forEach(function (comp) {
  2957. var daySquares = comp.store;
  2958. var daySquare = e.target;
  2959. if (daySquares.includes(daySquare)) {
  2960. var count = daySquare.getAttribute('data-value');
  2961. var dateParts = daySquare.getAttribute('data-date').split('-');
  2962. var month = getMonthName(parseInt(dateParts[1]) - 1, true);
  2963. var gOff = _this3.container.getBoundingClientRect(),
  2964. pOff = daySquare.getBoundingClientRect();
  2965. var width = parseInt(e.target.getAttribute('width'));
  2966. var x = pOff.left - gOff.left + width / 2;
  2967. var y = pOff.top - gOff.top;
  2968. var value = count + ' ' + _this3.countLabel;
  2969. var name = ' on ' + month + ' ' + dateParts[0] + ', ' + dateParts[2];
  2970. _this3.tip.setValues(x, y, {
  2971. name: name,
  2972. value: value,
  2973. valueFirst: 1
  2974. }, []);
  2975. _this3.tip.showTip();
  2976. }
  2977. });
  2978. });
  2979. }
  2980. }, {
  2981. key: "renderLegend",
  2982. value: function renderLegend() {
  2983. var _this4 = this;
  2984. this.legendArea.textContent = '';
  2985. var x = 0;
  2986. var y = ROW_HEIGHT;
  2987. var radius = this.rawChartArgs.radius || 0;
  2988. var lessText = makeText('subdomain-name', x, y, 'Less', {
  2989. fontSize: HEATMAP_SQUARE_SIZE + 1,
  2990. dy: 9
  2991. });
  2992. x = COL_WIDTH * 2 + COL_WIDTH / 2;
  2993. this.legendArea.appendChild(lessText);
  2994. this.colors.slice(0, HEATMAP_DISTRIBUTION_SIZE).map(function (color, i) {
  2995. var square = heatSquare('heatmap-legend-unit', x + (COL_WIDTH + 3) * i, y, HEATMAP_SQUARE_SIZE, radius, color);
  2996. _this4.legendArea.appendChild(square);
  2997. });
  2998. var moreTextX = x + HEATMAP_DISTRIBUTION_SIZE * (COL_WIDTH + 3) + COL_WIDTH / 4;
  2999. var moreText = makeText('subdomain-name', moreTextX, y, 'More', {
  3000. fontSize: HEATMAP_SQUARE_SIZE + 1,
  3001. dy: 9
  3002. });
  3003. this.legendArea.appendChild(moreText);
  3004. }
  3005. }, {
  3006. key: "getDomains",
  3007. value: function getDomains() {
  3008. var s = this.state;
  3009. var _ref = [s.start.getMonth(), s.start.getFullYear()],
  3010. startMonth = _ref[0],
  3011. startYear = _ref[1];
  3012. var _ref2 = [s.end.getMonth(), s.end.getFullYear()],
  3013. endMonth = _ref2[0],
  3014. endYear = _ref2[1];
  3015. var noOfMonths = endMonth - startMonth + 1 + (endYear - startYear) * 12;
  3016. var domainConfigs = [];
  3017. var startOfMonth = clone(s.start);
  3018. for (var i = 0; i < noOfMonths; i++) {
  3019. var endDate = s.end;
  3020. if (!areInSameMonth(startOfMonth, s.end)) {
  3021. var _ref3 = [startOfMonth.getMonth(), startOfMonth.getFullYear()],
  3022. month = _ref3[0],
  3023. year = _ref3[1];
  3024. endDate = getLastDateInMonth(month, year);
  3025. }
  3026. domainConfigs.push(this.getDomainConfig(startOfMonth, endDate));
  3027. addDays(endDate, 1);
  3028. startOfMonth = endDate;
  3029. }
  3030. return domainConfigs;
  3031. }
  3032. }, {
  3033. key: "getDomainConfig",
  3034. value: function getDomainConfig(startDate) {
  3035. var endDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  3036. var _ref4 = [startDate.getMonth(), startDate.getFullYear()],
  3037. month = _ref4[0],
  3038. year = _ref4[1];
  3039. var startOfWeek = setDayToSunday(startDate); // TODO: Monday as well
  3040. endDate = clone(endDate) || getLastDateInMonth(month, year);
  3041. var domainConfig = {
  3042. index: month,
  3043. cols: []
  3044. };
  3045. addDays(endDate, 1);
  3046. var noOfMonthWeeks = getWeeksBetween(startOfWeek, endDate);
  3047. var cols = [],
  3048. col;
  3049. for (var i = 0; i < noOfMonthWeeks; i++) {
  3050. col = this.getCol(startOfWeek, month);
  3051. cols.push(col);
  3052. startOfWeek = new Date(col[NO_OF_DAYS_IN_WEEK - 1].yyyyMmDd);
  3053. addDays(startOfWeek, 1);
  3054. }
  3055. if (col[NO_OF_DAYS_IN_WEEK - 1].dataValue !== undefined) {
  3056. addDays(startOfWeek, 1);
  3057. cols.push(this.getCol(startOfWeek, month, true));
  3058. }
  3059. domainConfig.cols = cols;
  3060. return domainConfig;
  3061. }
  3062. }, {
  3063. key: "getCol",
  3064. value: function getCol(startDate, month) {
  3065. var empty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3066. var s = this.state; // startDate is the start of week
  3067. var currentDate = clone(startDate);
  3068. var col = [];
  3069. for (var i = 0; i < NO_OF_DAYS_IN_WEEK; i++, addDays(currentDate, 1)) {
  3070. var config = {}; // Non-generic adjustment for entire heatmap, needs state
  3071. var currentDateWithinData = currentDate >= s.start && currentDate <= s.end;
  3072. if (empty || currentDate.getMonth() !== month || !currentDateWithinData) {
  3073. config.yyyyMmDd = getYyyyMmDd(currentDate);
  3074. } else {
  3075. config = this.getSubDomainConfig(currentDate);
  3076. }
  3077. col.push(config);
  3078. }
  3079. return col;
  3080. }
  3081. }, {
  3082. key: "getSubDomainConfig",
  3083. value: function getSubDomainConfig(date) {
  3084. var yyyyMmDd = getYyyyMmDd(date);
  3085. var dataValue = this.data.dataPoints[yyyyMmDd];
  3086. var config = {
  3087. yyyyMmDd: yyyyMmDd,
  3088. dataValue: dataValue || 0,
  3089. fill: this.colors[getMaxCheckpoint(dataValue, this.state.distribution)]
  3090. };
  3091. return config;
  3092. }
  3093. }]);
  3094. return Heatmap;
  3095. }(BaseChart);
  3096. function dataPrep(data, type) {
  3097. data.labels = data.labels || [];
  3098. var datasetLength = data.labels.length; // Datasets
  3099. var datasets = data.datasets;
  3100. var zeroArray = new Array(datasetLength).fill(0);
  3101. if (!datasets) {
  3102. // default
  3103. datasets = [{
  3104. values: zeroArray
  3105. }];
  3106. }
  3107. datasets.map(function (d) {
  3108. // Set values
  3109. if (!d.values) {
  3110. d.values = zeroArray;
  3111. } else {
  3112. // Check for non values
  3113. var vals = d.values;
  3114. vals = vals.map(function (val) {
  3115. return !isNaN(val) ? val : 0;
  3116. }); // Trim or extend
  3117. if (vals.length > datasetLength) {
  3118. vals = vals.slice(0, datasetLength);
  3119. } else {
  3120. vals = fillArray(vals, datasetLength - vals.length, 0);
  3121. }
  3122. } // Set labels
  3123. //
  3124. // Set type
  3125. if (!d.chartType) {
  3126. d.chartType = type;
  3127. }
  3128. }); // Markers
  3129. // Regions
  3130. // data.yRegions = data.yRegions || [];
  3131. if (data.yRegions) {
  3132. data.yRegions.map(function (d) {
  3133. if (d.end < d.start) {
  3134. var _ref = [d.end, d.start];
  3135. d.start = _ref[0];
  3136. d.end = _ref[1];
  3137. }
  3138. });
  3139. }
  3140. return data;
  3141. }
  3142. function zeroDataPrep(realData) {
  3143. var datasetLength = realData.labels.length;
  3144. var zeroArray = new Array(datasetLength).fill(0);
  3145. var zeroData = {
  3146. labels: realData.labels.slice(0, -1),
  3147. datasets: realData.datasets.map(function (d) {
  3148. return {
  3149. name: '',
  3150. values: zeroArray.slice(0, -1),
  3151. chartType: d.chartType
  3152. };
  3153. })
  3154. };
  3155. if (realData.yMarkers) {
  3156. zeroData.yMarkers = [{
  3157. value: 0,
  3158. label: ''
  3159. }];
  3160. }
  3161. if (realData.yRegions) {
  3162. zeroData.yRegions = [{
  3163. start: 0,
  3164. end: 0,
  3165. label: ''
  3166. }];
  3167. }
  3168. return zeroData;
  3169. }
  3170. function getShortenedLabels(chartWidth) {
  3171. var labels = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  3172. var isSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  3173. var allowedSpace = chartWidth / labels.length;
  3174. if (allowedSpace <= 0) allowedSpace = 1;
  3175. var allowedLetters = allowedSpace / DEFAULT_CHAR_WIDTH;
  3176. var seriesMultiple;
  3177. if (isSeries) {
  3178. // Find the maximum label length for spacing calculations
  3179. var maxLabelLength = Math.max.apply(Math, _toConsumableArray(labels.map(function (label) {
  3180. return label.length;
  3181. })));
  3182. seriesMultiple = Math.ceil(maxLabelLength / allowedLetters);
  3183. }
  3184. var calcLabels = labels.map(function (label, i) {
  3185. label += "";
  3186. if (label.length > allowedLetters) {
  3187. if (!isSeries) {
  3188. if (allowedLetters - 3 > 0) {
  3189. label = label.slice(0, allowedLetters - 3) + " ...";
  3190. } else {
  3191. label = label.slice(0, allowedLetters) + '..';
  3192. }
  3193. } else {
  3194. if (i % seriesMultiple !== 0) {
  3195. label = "";
  3196. }
  3197. }
  3198. }
  3199. return label;
  3200. });
  3201. return calcLabels;
  3202. }
  3203. var AxisChart = /*#__PURE__*/function (_BaseChart) {
  3204. _inherits(AxisChart, _BaseChart);
  3205. var _super = _createSuper(AxisChart);
  3206. function AxisChart(parent, args) {
  3207. var _this;
  3208. _classCallCheck(this, AxisChart);
  3209. _this = _super.call(this, parent, args);
  3210. _this.barOptions = args.barOptions || {};
  3211. _this.lineOptions = args.lineOptions || {};
  3212. _this.type = args.type || 'line';
  3213. _this.init = 1;
  3214. _this.setup();
  3215. return _this;
  3216. }
  3217. _createClass(AxisChart, [{
  3218. key: "setMeasures",
  3219. value: function setMeasures() {
  3220. if (this.data.datasets.length <= 1) {
  3221. this.config.showLegend = 0;
  3222. this.measures.paddings.bottom = 30;
  3223. }
  3224. }
  3225. }, {
  3226. key: "configure",
  3227. value: function configure(options) {
  3228. _get(_getPrototypeOf(AxisChart.prototype), "configure", this).call(this, options);
  3229. options.axisOptions = options.axisOptions || {};
  3230. options.tooltipOptions = options.tooltipOptions || {};
  3231. this.config.xAxisMode = options.axisOptions.xAxisMode || 'span';
  3232. this.config.yAxisMode = options.axisOptions.yAxisMode || 'span';
  3233. this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
  3234. this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
  3235. this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
  3236. this.config.formatTooltipY = options.tooltipOptions.formatTooltipY;
  3237. this.config.valuesOverPoints = options.valuesOverPoints;
  3238. }
  3239. }, {
  3240. key: "prepareData",
  3241. value: function prepareData() {
  3242. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.data;
  3243. return dataPrep(data, this.type);
  3244. }
  3245. }, {
  3246. key: "prepareFirstData",
  3247. value: function prepareFirstData() {
  3248. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.data;
  3249. return zeroDataPrep(data);
  3250. }
  3251. }, {
  3252. key: "calc",
  3253. value: function calc() {
  3254. var onlyWidthChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3255. this.calcXPositions();
  3256. if (!onlyWidthChange) {
  3257. this.calcYAxisParameters(this.getAllYValues(), this.type === 'line');
  3258. }
  3259. this.makeDataByIndex();
  3260. }
  3261. }, {
  3262. key: "calcXPositions",
  3263. value: function calcXPositions() {
  3264. var s = this.state;
  3265. var labels = this.data.labels;
  3266. s.datasetLength = labels.length;
  3267. s.unitWidth = this.width / s.datasetLength; // Default, as per bar, and mixed. Only line will be a special case
  3268. s.xOffset = s.unitWidth / 2; // // For a pure Line Chart
  3269. // s.unitWidth = this.width/(s.datasetLength - 1);
  3270. // s.xOffset = 0;
  3271. s.xAxis = {
  3272. labels: labels,
  3273. positions: labels.map(function (d, i) {
  3274. return floatTwo(s.xOffset + i * s.unitWidth);
  3275. })
  3276. };
  3277. }
  3278. }, {
  3279. key: "calcYAxisParameters",
  3280. value: function calcYAxisParameters(dataValues) {
  3281. var withMinimum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'false';
  3282. var yPts = calcChartIntervals(dataValues, withMinimum);
  3283. var scaleMultiplier = this.height / getValueRange(yPts);
  3284. var intervalHeight = getIntervalSize(yPts) * scaleMultiplier;
  3285. var zeroLine = this.height - getZeroIndex(yPts) * intervalHeight;
  3286. this.state.yAxis = {
  3287. labels: yPts,
  3288. positions: yPts.map(function (d) {
  3289. return zeroLine - d * scaleMultiplier;
  3290. }),
  3291. scaleMultiplier: scaleMultiplier,
  3292. zeroLine: zeroLine
  3293. }; // Dependent if above changes
  3294. this.calcDatasetPoints();
  3295. this.calcYExtremes();
  3296. this.calcYRegions();
  3297. }
  3298. }, {
  3299. key: "calcDatasetPoints",
  3300. value: function calcDatasetPoints() {
  3301. var s = this.state;
  3302. var scaleAll = function scaleAll(values) {
  3303. return values.map(function (val) {
  3304. return scale(val, s.yAxis);
  3305. });
  3306. };
  3307. s.datasets = this.data.datasets.map(function (d, i) {
  3308. var values = d.values;
  3309. var cumulativeYs = d.cumulativeYs || [];
  3310. return {
  3311. name: d.name,
  3312. index: i,
  3313. chartType: d.chartType,
  3314. values: values,
  3315. yPositions: scaleAll(values),
  3316. cumulativeYs: cumulativeYs,
  3317. cumulativeYPos: scaleAll(cumulativeYs)
  3318. };
  3319. });
  3320. }
  3321. }, {
  3322. key: "calcYExtremes",
  3323. value: function calcYExtremes() {
  3324. var s = this.state;
  3325. if (this.barOptions.stacked) {
  3326. s.yExtremes = s.datasets[s.datasets.length - 1].cumulativeYPos;
  3327. return;
  3328. }
  3329. s.yExtremes = new Array(s.datasetLength).fill(9999);
  3330. s.datasets.map(function (d) {
  3331. d.yPositions.map(function (pos, j) {
  3332. if (pos < s.yExtremes[j]) {
  3333. s.yExtremes[j] = pos;
  3334. }
  3335. });
  3336. });
  3337. }
  3338. }, {
  3339. key: "calcYRegions",
  3340. value: function calcYRegions() {
  3341. var s = this.state;
  3342. if (this.data.yMarkers) {
  3343. this.state.yMarkers = this.data.yMarkers.map(function (d) {
  3344. d.position = scale(d.value, s.yAxis);
  3345. if (!d.options) d.options = {}; // if(!d.label.includes(':')) {
  3346. // d.label += ': ' + d.value;
  3347. // }
  3348. return d;
  3349. });
  3350. }
  3351. if (this.data.yRegions) {
  3352. this.state.yRegions = this.data.yRegions.map(function (d) {
  3353. d.startPos = scale(d.start, s.yAxis);
  3354. d.endPos = scale(d.end, s.yAxis);
  3355. if (!d.options) d.options = {};
  3356. return d;
  3357. });
  3358. }
  3359. }
  3360. }, {
  3361. key: "getAllYValues",
  3362. value: function getAllYValues() {
  3363. var _this2 = this,
  3364. _ref;
  3365. var key = 'values';
  3366. if (this.barOptions.stacked) {
  3367. key = 'cumulativeYs';
  3368. var cumulative = new Array(this.state.datasetLength).fill(0);
  3369. this.data.datasets.map(function (d, i) {
  3370. var values = _this2.data.datasets[i].values;
  3371. d[key] = cumulative = cumulative.map(function (c, i) {
  3372. return c + values[i];
  3373. });
  3374. });
  3375. }
  3376. var allValueLists = this.data.datasets.map(function (d) {
  3377. return d[key];
  3378. });
  3379. if (this.data.yMarkers) {
  3380. allValueLists.push(this.data.yMarkers.map(function (d) {
  3381. return d.value;
  3382. }));
  3383. }
  3384. if (this.data.yRegions) {
  3385. this.data.yRegions.map(function (d) {
  3386. allValueLists.push([d.end, d.start]);
  3387. });
  3388. }
  3389. return (_ref = []).concat.apply(_ref, _toConsumableArray(allValueLists));
  3390. }
  3391. }, {
  3392. key: "setupComponents",
  3393. value: function setupComponents() {
  3394. var _this3 = this;
  3395. var componentConfigs = [['yAxis', {
  3396. mode: this.config.yAxisMode,
  3397. width: this.width,
  3398. shortenNumbers: this.config.shortenYAxisNumbers // pos: 'right'
  3399. }, function () {
  3400. return this.state.yAxis;
  3401. }.bind(this)], ['xAxis', {
  3402. mode: this.config.xAxisMode,
  3403. height: this.height // pos: 'right'
  3404. }, function () {
  3405. var s = this.state;
  3406. s.xAxis.calcLabels = getShortenedLabels(this.width, s.xAxis.labels, this.config.xIsSeries);
  3407. return s.xAxis;
  3408. }.bind(this)], ['yRegions', {
  3409. width: this.width,
  3410. pos: 'right'
  3411. }, function () {
  3412. return this.state.yRegions;
  3413. }.bind(this)]];
  3414. var barDatasets = this.state.datasets.filter(function (d) {
  3415. return d.chartType === 'bar';
  3416. });
  3417. var lineDatasets = this.state.datasets.filter(function (d) {
  3418. return d.chartType === 'line';
  3419. });
  3420. var barsConfigs = barDatasets.map(function (d) {
  3421. var index = d.index;
  3422. return ['barGraph' + '-' + d.index, {
  3423. index: index,
  3424. color: _this3.colors[index],
  3425. stacked: _this3.barOptions.stacked,
  3426. // same for all datasets
  3427. valuesOverPoints: _this3.config.valuesOverPoints,
  3428. minHeight: _this3.height * MIN_BAR_PERCENT_HEIGHT
  3429. }, function () {
  3430. var s = this.state;
  3431. var d = s.datasets[index];
  3432. var stacked = this.barOptions.stacked;
  3433. var spaceRatio = this.barOptions.spaceRatio || BAR_CHART_SPACE_RATIO;
  3434. var barsWidth = s.unitWidth * (1 - spaceRatio);
  3435. var barWidth = barsWidth / (stacked ? 1 : barDatasets.length);
  3436. var xPositions = s.xAxis.positions.map(function (x) {
  3437. return x - barsWidth / 2;
  3438. });
  3439. if (!stacked) {
  3440. xPositions = xPositions.map(function (p) {
  3441. return p + barWidth * index;
  3442. });
  3443. }
  3444. var labels = new Array(s.datasetLength).fill('');
  3445. if (this.config.valuesOverPoints) {
  3446. if (stacked && d.index === s.datasets.length - 1) {
  3447. labels = d.cumulativeYs;
  3448. } else {
  3449. labels = d.values;
  3450. }
  3451. }
  3452. var offsets = new Array(s.datasetLength).fill(0);
  3453. if (stacked) {
  3454. offsets = d.yPositions.map(function (y, j) {
  3455. return y - d.cumulativeYPos[j];
  3456. });
  3457. }
  3458. return {
  3459. xPositions: xPositions,
  3460. yPositions: d.yPositions,
  3461. offsets: offsets,
  3462. // values: d.values,
  3463. labels: labels,
  3464. zeroLine: s.yAxis.zeroLine,
  3465. barsWidth: barsWidth,
  3466. barWidth: barWidth
  3467. };
  3468. }.bind(_this3)];
  3469. });
  3470. var lineConfigs = lineDatasets.map(function (d) {
  3471. var index = d.index;
  3472. return ['lineGraph' + '-' + d.index, {
  3473. index: index,
  3474. color: _this3.colors[index],
  3475. svgDefs: _this3.svgDefs,
  3476. heatline: _this3.lineOptions.heatline,
  3477. regionFill: _this3.lineOptions.regionFill,
  3478. spline: _this3.lineOptions.spline,
  3479. hideDots: _this3.lineOptions.hideDots,
  3480. hideLine: _this3.lineOptions.hideLine,
  3481. // same for all datasets
  3482. valuesOverPoints: _this3.config.valuesOverPoints
  3483. }, function () {
  3484. var s = this.state;
  3485. var d = s.datasets[index];
  3486. var minLine = s.yAxis.positions[0] < s.yAxis.zeroLine ? s.yAxis.positions[0] : s.yAxis.zeroLine;
  3487. return {
  3488. xPositions: s.xAxis.positions,
  3489. yPositions: d.yPositions,
  3490. values: d.values,
  3491. zeroLine: minLine,
  3492. radius: this.lineOptions.dotSize || LINE_CHART_DOT_SIZE
  3493. };
  3494. }.bind(_this3)];
  3495. });
  3496. var markerConfigs = [['yMarkers', {
  3497. width: this.width,
  3498. pos: 'right'
  3499. }, function () {
  3500. return this.state.yMarkers;
  3501. }.bind(this)]];
  3502. componentConfigs = componentConfigs.concat(barsConfigs, lineConfigs, markerConfigs);
  3503. var optionals = ['yMarkers', 'yRegions'];
  3504. this.dataUnitComponents = [];
  3505. this.components = new Map(componentConfigs.filter(function (args) {
  3506. return !optionals.includes(args[0]) || _this3.state[args[0]];
  3507. }).map(function (args) {
  3508. var component = getComponent.apply(void 0, _toConsumableArray(args));
  3509. if (args[0].includes('lineGraph') || args[0].includes('barGraph')) {
  3510. _this3.dataUnitComponents.push(component);
  3511. }
  3512. return [args[0], component];
  3513. }));
  3514. }
  3515. }, {
  3516. key: "makeDataByIndex",
  3517. value: function makeDataByIndex() {
  3518. var _this4 = this;
  3519. this.dataByIndex = {};
  3520. var s = this.state;
  3521. var formatX = this.config.formatTooltipX;
  3522. var formatY = this.config.formatTooltipY;
  3523. var titles = s.xAxis.labels;
  3524. titles.map(function (label, index) {
  3525. var values = _this4.state.datasets.map(function (set, i) {
  3526. var value = set.values[index];
  3527. return {
  3528. title: set.name,
  3529. value: value,
  3530. yPos: set.yPositions[index],
  3531. color: _this4.colors[i],
  3532. formatted: formatY ? formatY(value) : value
  3533. };
  3534. });
  3535. _this4.dataByIndex[index] = {
  3536. label: label,
  3537. formattedLabel: formatX ? formatX(label) : label,
  3538. xPos: s.xAxis.positions[index],
  3539. values: values,
  3540. yExtreme: s.yExtremes[index]
  3541. };
  3542. });
  3543. }
  3544. }, {
  3545. key: "bindTooltip",
  3546. value: function bindTooltip() {
  3547. var _this5 = this;
  3548. // NOTE: could be in tooltip itself, as it is a given functionality for its parent
  3549. this.container.addEventListener('mousemove', function (e) {
  3550. var m = _this5.measures;
  3551. var o = getOffset(_this5.container);
  3552. var relX = e.pageX - o.left - getLeftOffset(m);
  3553. var relY = e.pageY - o.top;
  3554. if (relY < _this5.height + getTopOffset(m) && relY > getTopOffset(m)) {
  3555. _this5.mapTooltipXPosition(relX);
  3556. } else {
  3557. _this5.tip.hideTip();
  3558. }
  3559. });
  3560. }
  3561. }, {
  3562. key: "mapTooltipXPosition",
  3563. value: function mapTooltipXPosition(relX) {
  3564. var s = this.state;
  3565. if (!s.yExtremes) return;
  3566. var index = getClosestInArray(relX, s.xAxis.positions, true);
  3567. if (index >= 0) {
  3568. var dbi = this.dataByIndex[index];
  3569. this.tip.setValues(dbi.xPos + this.tip.offset.x, dbi.yExtreme + this.tip.offset.y, {
  3570. name: dbi.formattedLabel,
  3571. value: ''
  3572. }, dbi.values, index);
  3573. this.tip.showTip();
  3574. }
  3575. }
  3576. }, {
  3577. key: "renderLegend",
  3578. value: function renderLegend() {
  3579. var _this6 = this;
  3580. var s = this.data;
  3581. if (s.datasets.length > 1) {
  3582. this.legendArea.textContent = '';
  3583. s.datasets.map(function (d, i) {
  3584. var barWidth = AXIS_LEGEND_BAR_SIZE; // let rightEndPoint = this.baseWidth - this.measures.margins.left - this.measures.margins.right;
  3585. // let multiplier = s.datasets.length - i;
  3586. var rect = legendBar( // rightEndPoint - multiplier * barWidth, // To right align
  3587. barWidth * i, '0', barWidth, _this6.colors[i], d.name, _this6.config.truncateLegends);
  3588. _this6.legendArea.appendChild(rect);
  3589. });
  3590. }
  3591. } // Overlay
  3592. }, {
  3593. key: "makeOverlay",
  3594. value: function makeOverlay$1() {
  3595. var _this7 = this;
  3596. if (this.init) {
  3597. this.init = 0;
  3598. return;
  3599. }
  3600. if (this.overlayGuides) {
  3601. this.overlayGuides.forEach(function (g) {
  3602. var o = g.overlay;
  3603. o.parentNode.removeChild(o);
  3604. });
  3605. }
  3606. this.overlayGuides = this.dataUnitComponents.map(function (c) {
  3607. return {
  3608. type: c.unitType,
  3609. overlay: undefined,
  3610. units: c.units
  3611. };
  3612. });
  3613. if (this.state.currentIndex === undefined) {
  3614. this.state.currentIndex = this.state.datasetLength - 1;
  3615. } // Render overlays
  3616. this.overlayGuides.map(function (d) {
  3617. var currentUnit = d.units[_this7.state.currentIndex];
  3618. d.overlay = makeOverlay[d.type](currentUnit);
  3619. _this7.drawArea.appendChild(d.overlay);
  3620. });
  3621. }
  3622. }, {
  3623. key: "updateOverlayGuides",
  3624. value: function updateOverlayGuides() {
  3625. if (this.overlayGuides) {
  3626. this.overlayGuides.forEach(function (g) {
  3627. var o = g.overlay;
  3628. o.parentNode.removeChild(o);
  3629. });
  3630. }
  3631. }
  3632. }, {
  3633. key: "bindOverlay",
  3634. value: function bindOverlay() {
  3635. var _this8 = this;
  3636. this.parent.addEventListener('data-select', function () {
  3637. _this8.updateOverlay();
  3638. });
  3639. }
  3640. }, {
  3641. key: "bindUnits",
  3642. value: function bindUnits() {
  3643. var _this9 = this;
  3644. this.dataUnitComponents.map(function (c) {
  3645. c.units.map(function (unit) {
  3646. unit.addEventListener('click', function () {
  3647. var index = unit.getAttribute('data-point-index');
  3648. _this9.setCurrentDataPoint(index);
  3649. });
  3650. });
  3651. }); // Note: Doesn't work as tooltip is absolutely positioned
  3652. this.tip.container.addEventListener('click', function () {
  3653. var index = _this9.tip.container.getAttribute('data-point-index');
  3654. _this9.setCurrentDataPoint(index);
  3655. });
  3656. }
  3657. }, {
  3658. key: "updateOverlay",
  3659. value: function updateOverlay$1() {
  3660. var _this10 = this;
  3661. this.overlayGuides.map(function (d) {
  3662. var currentUnit = d.units[_this10.state.currentIndex];
  3663. updateOverlay[d.type](currentUnit, d.overlay);
  3664. });
  3665. }
  3666. }, {
  3667. key: "onLeftArrow",
  3668. value: function onLeftArrow() {
  3669. this.setCurrentDataPoint(this.state.currentIndex - 1);
  3670. }
  3671. }, {
  3672. key: "onRightArrow",
  3673. value: function onRightArrow() {
  3674. this.setCurrentDataPoint(this.state.currentIndex + 1);
  3675. }
  3676. }, {
  3677. key: "getDataPoint",
  3678. value: function getDataPoint() {
  3679. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.currentIndex;
  3680. var s = this.state;
  3681. var data_point = {
  3682. index: index,
  3683. label: s.xAxis.labels[index],
  3684. values: s.datasets.map(function (d) {
  3685. return d.values[index];
  3686. })
  3687. };
  3688. return data_point;
  3689. }
  3690. }, {
  3691. key: "setCurrentDataPoint",
  3692. value: function setCurrentDataPoint(index) {
  3693. var s = this.state;
  3694. index = parseInt(index);
  3695. if (index < 0) index = 0;
  3696. if (index >= s.xAxis.labels.length) index = s.xAxis.labels.length - 1;
  3697. if (index === s.currentIndex) return;
  3698. s.currentIndex = index;
  3699. fire(this.parent, "data-select", this.getDataPoint());
  3700. } // API
  3701. }, {
  3702. key: "addDataPoint",
  3703. value: function addDataPoint(label, datasetValues) {
  3704. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.state.datasetLength;
  3705. _get(_getPrototypeOf(AxisChart.prototype), "addDataPoint", this).call(this, label, datasetValues, index);
  3706. this.data.labels.splice(index, 0, label);
  3707. this.data.datasets.map(function (d, i) {
  3708. d.values.splice(index, 0, datasetValues[i]);
  3709. });
  3710. this.update(this.data);
  3711. }
  3712. }, {
  3713. key: "removeDataPoint",
  3714. value: function removeDataPoint() {
  3715. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.datasetLength - 1;
  3716. if (this.data.labels.length <= 1) {
  3717. return;
  3718. }
  3719. _get(_getPrototypeOf(AxisChart.prototype), "removeDataPoint", this).call(this, index);
  3720. this.data.labels.splice(index, 1);
  3721. this.data.datasets.map(function (d) {
  3722. d.values.splice(index, 1);
  3723. });
  3724. this.update(this.data);
  3725. }
  3726. }, {
  3727. key: "updateDataset",
  3728. value: function updateDataset(datasetValues) {
  3729. var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  3730. this.data.datasets[index].values = datasetValues;
  3731. this.update(this.data);
  3732. } // addDataset(dataset, index) {}
  3733. // removeDataset(index = 0) {}
  3734. }, {
  3735. key: "updateDatasets",
  3736. value: function updateDatasets(datasets) {
  3737. this.data.datasets.map(function (d, i) {
  3738. if (datasets[i]) {
  3739. d.values = datasets[i];
  3740. }
  3741. });
  3742. this.update(this.data);
  3743. } // updateDataPoint(dataPoint, index = 0) {}
  3744. // addDataPoint(dataPoint, index = 0) {}
  3745. // removeDataPoint(index = 0) {}
  3746. }]);
  3747. return AxisChart;
  3748. }(BaseChart);
  3749. var DonutChart = /*#__PURE__*/function (_AggregationChart) {
  3750. _inherits(DonutChart, _AggregationChart);
  3751. var _super = _createSuper(DonutChart);
  3752. function DonutChart(parent, args) {
  3753. var _this;
  3754. _classCallCheck(this, DonutChart);
  3755. _this = _super.call(this, parent, args);
  3756. _this.type = 'donut';
  3757. _this.initTimeout = 0;
  3758. _this.init = 1;
  3759. _this.setup();
  3760. return _this;
  3761. }
  3762. _createClass(DonutChart, [{
  3763. key: "configure",
  3764. value: function configure(args) {
  3765. _get(_getPrototypeOf(DonutChart.prototype), "configure", this).call(this, args);
  3766. this.mouseMove = this.mouseMove.bind(this);
  3767. this.mouseLeave = this.mouseLeave.bind(this);
  3768. this.hoverRadio = args.hoverRadio || 0.1;
  3769. this.config.startAngle = args.startAngle || 0;
  3770. this.clockWise = args.clockWise || false;
  3771. this.strokeWidth = args.strokeWidth || 30;
  3772. }
  3773. }, {
  3774. key: "calc",
  3775. value: function calc() {
  3776. var _this2 = this;
  3777. _get(_getPrototypeOf(DonutChart.prototype), "calc", this).call(this);
  3778. var s = this.state;
  3779. this.radius = this.height > this.width ? this.center.x - this.strokeWidth / 2 : this.center.y - this.strokeWidth / 2;
  3780. var radius = this.radius,
  3781. clockWise = this.clockWise;
  3782. var prevSlicesProperties = s.slicesProperties || [];
  3783. s.sliceStrings = [];
  3784. s.slicesProperties = [];
  3785. var curAngle = 180 - this.config.startAngle;
  3786. s.sliceTotals.map(function (total, i) {
  3787. var startAngle = curAngle;
  3788. var originDiffAngle = total / s.grandTotal * FULL_ANGLE;
  3789. var largeArc = originDiffAngle > 180 ? 1 : 0;
  3790. var diffAngle = clockWise ? -originDiffAngle : originDiffAngle;
  3791. var endAngle = curAngle = curAngle + diffAngle;
  3792. var startPosition = getPositionByAngle(startAngle, radius);
  3793. var endPosition = getPositionByAngle(endAngle, radius);
  3794. var prevProperty = _this2.init && prevSlicesProperties[i];
  3795. var curStart, curEnd;
  3796. if (_this2.init) {
  3797. curStart = prevProperty ? prevProperty.startPosition : startPosition;
  3798. curEnd = prevProperty ? prevProperty.endPosition : startPosition;
  3799. } else {
  3800. curStart = startPosition;
  3801. curEnd = endPosition;
  3802. }
  3803. var curPath = originDiffAngle === 360 ? makeStrokeCircleStr(curStart, curEnd, _this2.center, _this2.radius, _this2.clockWise, largeArc) : makeArcStrokePathStr(curStart, curEnd, _this2.center, _this2.radius, _this2.clockWise, largeArc);
  3804. s.sliceStrings.push(curPath);
  3805. s.slicesProperties.push({
  3806. startPosition: startPosition,
  3807. endPosition: endPosition,
  3808. value: total,
  3809. total: s.grandTotal,
  3810. startAngle: startAngle,
  3811. endAngle: endAngle,
  3812. angle: diffAngle
  3813. });
  3814. });
  3815. this.init = 0;
  3816. }
  3817. }, {
  3818. key: "setupComponents",
  3819. value: function setupComponents() {
  3820. var s = this.state;
  3821. var componentConfigs = [['donutSlices', {}, function () {
  3822. return {
  3823. sliceStrings: s.sliceStrings,
  3824. colors: this.colors,
  3825. strokeWidth: this.strokeWidth
  3826. };
  3827. }.bind(this)]];
  3828. this.components = new Map(componentConfigs.map(function (args) {
  3829. var component = getComponent.apply(void 0, _toConsumableArray(args));
  3830. return [args[0], component];
  3831. }));
  3832. }
  3833. }, {
  3834. key: "calTranslateByAngle",
  3835. value: function calTranslateByAngle(property) {
  3836. var radius = this.radius,
  3837. hoverRadio = this.hoverRadio;
  3838. var position = getPositionByAngle(property.startAngle + property.angle / 2, radius);
  3839. return "translate3d(".concat(position.x * hoverRadio, "px,").concat(position.y * hoverRadio, "px,0)");
  3840. }
  3841. }, {
  3842. key: "hoverSlice",
  3843. value: function hoverSlice(path, i, flag, e) {
  3844. if (!path) return;
  3845. var color = this.colors[i];
  3846. if (flag) {
  3847. transform(path, this.calTranslateByAngle(this.state.slicesProperties[i]));
  3848. path.style.stroke = lightenDarkenColor(color, 50);
  3849. var g_off = getOffset(this.svg);
  3850. var x = e.pageX - g_off.left + 10;
  3851. var y = e.pageY - g_off.top - 10;
  3852. var title = (this.formatted_labels && this.formatted_labels.length > 0 ? this.formatted_labels[i] : this.state.labels[i]) + ': ';
  3853. var percent = (this.state.sliceTotals[i] * 100 / this.state.grandTotal).toFixed(1);
  3854. this.tip.setValues(x, y, {
  3855. name: title,
  3856. value: percent + "%"
  3857. });
  3858. this.tip.showTip();
  3859. } else {
  3860. transform(path, 'translate3d(0,0,0)');
  3861. this.tip.hideTip();
  3862. path.style.stroke = color;
  3863. }
  3864. }
  3865. }, {
  3866. key: "bindTooltip",
  3867. value: function bindTooltip() {
  3868. this.container.addEventListener('mousemove', this.mouseMove);
  3869. this.container.addEventListener('mouseleave', this.mouseLeave);
  3870. }
  3871. }, {
  3872. key: "mouseMove",
  3873. value: function mouseMove(e) {
  3874. var target = e.target;
  3875. var slices = this.components.get('donutSlices').store;
  3876. var prevIndex = this.curActiveSliceIndex;
  3877. var prevAcitve = this.curActiveSlice;
  3878. if (slices.includes(target)) {
  3879. var i = slices.indexOf(target);
  3880. this.hoverSlice(prevAcitve, prevIndex, false);
  3881. this.curActiveSlice = target;
  3882. this.curActiveSliceIndex = i;
  3883. this.hoverSlice(target, i, true, e);
  3884. } else {
  3885. this.mouseLeave();
  3886. }
  3887. }
  3888. }, {
  3889. key: "mouseLeave",
  3890. value: function mouseLeave() {
  3891. this.hoverSlice(this.curActiveSlice, this.curActiveSliceIndex, false);
  3892. }
  3893. }]);
  3894. return DonutChart;
  3895. }(AggregationChart);
  3896. var chartTypes = {
  3897. bar: AxisChart,
  3898. line: AxisChart,
  3899. // multiaxis: MultiAxisChart,
  3900. percentage: PercentageChart,
  3901. heatmap: Heatmap,
  3902. pie: PieChart,
  3903. donut: DonutChart
  3904. };
  3905. function getChartByType() {
  3906. var chartType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'line';
  3907. var parent = arguments.length > 1 ? arguments[1] : undefined;
  3908. var options = arguments.length > 2 ? arguments[2] : undefined;
  3909. if (chartType === 'axis-mixed') {
  3910. options.type = 'line';
  3911. return new AxisChart(parent, options);
  3912. }
  3913. if (!chartTypes[chartType]) {
  3914. console.error("Undefined chart type: " + chartType);
  3915. return;
  3916. }
  3917. return new chartTypes[chartType](parent, options);
  3918. }
  3919. var Chart = function Chart(parent, options) {
  3920. _classCallCheck(this, Chart);
  3921. return getChartByType(options.type, parent, options);
  3922. };
  3923. export { AxisChart, Chart, Heatmap, PercentageChart, PieChart };