Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

4460 строки
138 KiB

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