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

3288 linhas
98 KiB

  1. 'use strict';
  2. function __$styleInject(css, returnValue) {
  3. if (typeof document === 'undefined') {
  4. return returnValue;
  5. }
  6. css = css || '';
  7. var head = document.head || document.getElementsByTagName('head')[0];
  8. var style = document.createElement('style');
  9. style.type = 'text/css';
  10. head.appendChild(style);
  11. if (style.styleSheet){
  12. style.styleSheet.cssText = css;
  13. } else {
  14. style.appendChild(document.createTextNode(css));
  15. }
  16. return returnValue;
  17. }
  18. __$styleInject(".chart-container{font-family:Roboto,Geneva,Tahoma,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{font-size:11px;fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .data-points circle{stroke:#fff;stroke-width:2}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .tick.x-axis-label{display:block}.chart-container .tick .specific-value{text-anchor:start}.chart-container .tick .y-value-text{text-anchor:end}.chart-container .tick .x-value-text{text-anchor:middle}.chart-container .progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f5f5f5;border-radius:4px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);box-shadow:inset 0 1px 2px rgba(0,0,0,.1)}.chart-container .progress-bar{float:left;width:0;height:100%;font-size:12px;line-height:20px;color:#fff;text-align:center;background-color:#36414c;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,.15);-webkit-transition:width .6s ease;transition:width .6s ease}.graph-svg-tip{position:absolute;z-index:1;padding:10px;font-size:12px;color:#959da5;text-align:center;background:rgba(0,0,0,.8);border-radius:3px}.graph-svg-tip ol,.graph-svg-tip ul{padding-left:0;display:-webkit-box;display:-ms-flexbox;display:flex}.graph-svg-tip ul.data-point-list li{min-width:90px;-webkit-box-flex:1;-ms-flex:1;flex:1;font-weight:600}.graph-svg-tip strong{color:#dfe2e5;font-weight:600}.graph-svg-tip .svg-pointer{position:absolute;bottom:-10px;left:50%;width:5px;height:5px;margin:0 0 0 -5px;content:\" \";border:5px solid transparent;border-top-color:rgba(0,0,0,.8)}.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}.indicator,.indicator-right{background:none;font-size:12px;vertical-align:middle;font-weight:700;color:#6c7680}.indicator-right:after,.indicator:before,.indicator i{content:\"\";display:inline-block;height:8px;width:8px;border-radius:8px}.indicator:before,.indicator i{margin:0 4px 0 0}.indicator-right:after{margin:0 0 0 4px}.background.grey,.indicator-right.grey:after,.indicator.grey:before,.indicator.grey i{background:#bdd3e6}.background.light-grey,.indicator-right.light-grey:after,.indicator.light-grey:before,.indicator.light-grey i{background:#f0f4f7}.background.blue,.indicator-right.blue:after,.indicator.blue:before,.indicator.blue i{background:#5e64ff}.background.red,.indicator-right.red:after,.indicator.red:before,.indicator.red i{background:#ff5858}.background.green,.indicator-right.green:after,.indicator.green:before,.indicator.green i{background:#28a745}.background.light-green,.indicator-right.light-green:after,.indicator.light-green:before,.indicator.light-green i{background:#98d85b}.background.orange,.indicator-right.orange:after,.indicator.orange:before,.indicator.orange i{background:#ffa00a}.background.violet,.indicator-right.violet:after,.indicator.violet:before,.indicator.violet i{background:#743ee2}.background.dark-grey,.indicator-right.dark-grey:after,.indicator.dark-grey:before,.indicator.dark-grey i{background:#b8c2cc}.background.black,.indicator-right.black:after,.indicator.black:before,.indicator.black i{background:#36414c}.background.yellow,.indicator-right.yellow:after,.indicator.yellow:before,.indicator.yellow i{background:#feef72}.background.light-blue,.indicator-right.light-blue:after,.indicator.light-blue:before,.indicator.light-blue i{background:#7cd6fd}.background.purple,.indicator-right.purple:after,.indicator.purple:before,.indicator.purple i{background:#b554ff}.background.magenta,.indicator-right.magenta:after,.indicator.magenta:before,.indicator.magenta i{background:#ffa3ef}.stroke.grey{stroke:#bdd3e6}.stroke.light-grey{stroke:#f0f4f7}.stroke.blue{stroke:#5e64ff}.stroke.red{stroke:#ff5858}.stroke.light-green{stroke:#98d85b}.stroke.green{stroke:#28a745}.stroke.orange{stroke:#ffa00a}.stroke.violet{stroke:#743ee2}.stroke.dark-grey{stroke:#b8c2cc}.stroke.black{stroke:#36414c}.stroke.yellow{stroke:#feef72}.stroke.light-blue{stroke:#7cd6fd}.stroke.purple{stroke:#b554ff}.stroke.magenta{stroke:#ffa3ef}.fill.grey{fill:#bdd3e6}.fill.light-grey{fill:#f0f4f7}.fill.blue{fill:#5e64ff}.fill.red{fill:#ff5858}.fill.light-green{fill:#98d85b}.fill.green{fill:#28a745}.fill.orange{fill:#ffa00a}.fill.violet{fill:#743ee2}.fill.dark-grey{fill:#b8c2cc}.fill.black{fill:#36414c}.fill.yellow{fill:#feef72}.fill.light-blue{fill:#7cd6fd}.fill.purple{fill:#b554ff}.fill.magenta{fill:#ffa3ef}.border-top.grey{border-top:3px solid #bdd3e6}.border-top.light-grey{border-top:3px solid #f0f4f7}.border-top.blue{border-top:3px solid #5e64ff}.border-top.red{border-top:3px solid #ff5858}.border-top.light-green{border-top:3px solid #98d85b}.border-top.green{border-top:3px solid #28a745}.border-top.orange{border-top:3px solid #ffa00a}.border-top.violet{border-top:3px solid #743ee2}.border-top.dark-grey{border-top:3px solid #b8c2cc}.border-top.black{border-top:3px solid #36414c}.border-top.yellow{border-top:3px solid #feef72}.border-top.light-blue{border-top:3px solid #7cd6fd}.border-top.purple{border-top:3px solid #b554ff}.border-top.magenta{border-top:3px solid #ffa3ef}.stop-color.grey{stop-color:#bdd3e6}.stop-color.light-grey{stop-color:#f0f4f7}.stop-color.blue{stop-color:#5e64ff}.stop-color.red{stop-color:#ff5858}.stop-color.light-green{stop-color:#98d85b}.stop-color.green{stop-color:#28a745}.stop-color.orange{stop-color:#ffa00a}.stop-color.violet{stop-color:#743ee2}.stop-color.dark-grey{stop-color:#b8c2cc}.stop-color.black{stop-color:#36414c}.stop-color.yellow{stop-color:#feef72}.stop-color.light-blue{stop-color:#7cd6fd}.stop-color.purple{stop-color:#b554ff}.stop-color.magenta{stop-color:#ffa3ef}", undefined);
  19. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  20. return typeof obj;
  21. } : function (obj) {
  22. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  23. };
  24. var asyncGenerator = function () {
  25. function AwaitValue(value) {
  26. this.value = value;
  27. }
  28. function AsyncGenerator(gen) {
  29. var front, back;
  30. function send(key, arg) {
  31. return new Promise(function (resolve, reject) {
  32. var request = {
  33. key: key,
  34. arg: arg,
  35. resolve: resolve,
  36. reject: reject,
  37. next: null
  38. };
  39. if (back) {
  40. back = back.next = request;
  41. } else {
  42. front = back = request;
  43. resume(key, arg);
  44. }
  45. });
  46. }
  47. function resume(key, arg) {
  48. try {
  49. var result = gen[key](arg);
  50. var value = result.value;
  51. if (value instanceof AwaitValue) {
  52. Promise.resolve(value.value).then(function (arg) {
  53. resume("next", arg);
  54. }, function (arg) {
  55. resume("throw", arg);
  56. });
  57. } else {
  58. settle(result.done ? "return" : "normal", result.value);
  59. }
  60. } catch (err) {
  61. settle("throw", err);
  62. }
  63. }
  64. function settle(type, value) {
  65. switch (type) {
  66. case "return":
  67. front.resolve({
  68. value: value,
  69. done: true
  70. });
  71. break;
  72. case "throw":
  73. front.reject(value);
  74. break;
  75. default:
  76. front.resolve({
  77. value: value,
  78. done: false
  79. });
  80. break;
  81. }
  82. front = front.next;
  83. if (front) {
  84. resume(front.key, front.arg);
  85. } else {
  86. back = null;
  87. }
  88. }
  89. this._invoke = send;
  90. if (typeof gen.return !== "function") {
  91. this.return = undefined;
  92. }
  93. }
  94. if (typeof Symbol === "function" && Symbol.asyncIterator) {
  95. AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
  96. return this;
  97. };
  98. }
  99. AsyncGenerator.prototype.next = function (arg) {
  100. return this._invoke("next", arg);
  101. };
  102. AsyncGenerator.prototype.throw = function (arg) {
  103. return this._invoke("throw", arg);
  104. };
  105. AsyncGenerator.prototype.return = function (arg) {
  106. return this._invoke("return", arg);
  107. };
  108. return {
  109. wrap: function (fn) {
  110. return function () {
  111. return new AsyncGenerator(fn.apply(this, arguments));
  112. };
  113. },
  114. await: function (value) {
  115. return new AwaitValue(value);
  116. }
  117. };
  118. }();
  119. var classCallCheck = function (instance, Constructor) {
  120. if (!(instance instanceof Constructor)) {
  121. throw new TypeError("Cannot call a class as a function");
  122. }
  123. };
  124. var createClass = function () {
  125. function defineProperties(target, props) {
  126. for (var i = 0; i < props.length; i++) {
  127. var descriptor = props[i];
  128. descriptor.enumerable = descriptor.enumerable || false;
  129. descriptor.configurable = true;
  130. if ("value" in descriptor) descriptor.writable = true;
  131. Object.defineProperty(target, descriptor.key, descriptor);
  132. }
  133. }
  134. return function (Constructor, protoProps, staticProps) {
  135. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  136. if (staticProps) defineProperties(Constructor, staticProps);
  137. return Constructor;
  138. };
  139. }();
  140. var get = function get(object, property, receiver) {
  141. if (object === null) object = Function.prototype;
  142. var desc = Object.getOwnPropertyDescriptor(object, property);
  143. if (desc === undefined) {
  144. var parent = Object.getPrototypeOf(object);
  145. if (parent === null) {
  146. return undefined;
  147. } else {
  148. return get(parent, property, receiver);
  149. }
  150. } else if ("value" in desc) {
  151. return desc.value;
  152. } else {
  153. var getter = desc.get;
  154. if (getter === undefined) {
  155. return undefined;
  156. }
  157. return getter.call(receiver);
  158. }
  159. };
  160. var inherits = function (subClass, superClass) {
  161. if (typeof superClass !== "function" && superClass !== null) {
  162. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  163. }
  164. subClass.prototype = Object.create(superClass && superClass.prototype, {
  165. constructor: {
  166. value: subClass,
  167. enumerable: false,
  168. writable: true,
  169. configurable: true
  170. }
  171. });
  172. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  173. };
  174. var possibleConstructorReturn = function (self, call) {
  175. if (!self) {
  176. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  177. }
  178. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  179. };
  180. var slicedToArray = function () {
  181. function sliceIterator(arr, i) {
  182. var _arr = [];
  183. var _n = true;
  184. var _d = false;
  185. var _e = undefined;
  186. try {
  187. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  188. _arr.push(_s.value);
  189. if (i && _arr.length === i) break;
  190. }
  191. } catch (err) {
  192. _d = true;
  193. _e = err;
  194. } finally {
  195. try {
  196. if (!_n && _i["return"]) _i["return"]();
  197. } finally {
  198. if (_d) throw _e;
  199. }
  200. }
  201. return _arr;
  202. }
  203. return function (arr, i) {
  204. if (Array.isArray(arr)) {
  205. return arr;
  206. } else if (Symbol.iterator in Object(arr)) {
  207. return sliceIterator(arr, i);
  208. } else {
  209. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  210. }
  211. };
  212. }();
  213. var toConsumableArray = function (arr) {
  214. if (Array.isArray(arr)) {
  215. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  216. return arr2;
  217. } else {
  218. return Array.from(arr);
  219. }
  220. };
  221. function $(expr, con) {
  222. return typeof expr === "string" ? (con || document).querySelector(expr) : expr || null;
  223. }
  224. var EASING = {
  225. ease: "0.25 0.1 0.25 1",
  226. linear: "0 0 1 1",
  227. // easein: "0.42 0 1 1",
  228. easein: "0.1 0.8 0.2 1",
  229. easeout: "0 0 0.58 1",
  230. easeinout: "0.42 0 0.58 1"
  231. };
  232. $.findNodeIndex = function (node) {
  233. var i = 0;
  234. while (node.previousSibling) {
  235. node = node.previousSibling;
  236. i++;
  237. }
  238. return i;
  239. };
  240. $.create = function (tag, o) {
  241. var element = document.createElement(tag);
  242. for (var i in o) {
  243. var val = o[i];
  244. if (i === "inside") {
  245. $(val).appendChild(element);
  246. } else if (i === "around") {
  247. var ref = $(val);
  248. ref.parentNode.insertBefore(element, ref);
  249. element.appendChild(ref);
  250. } else if (i === "styles") {
  251. if ((typeof val === "undefined" ? "undefined" : _typeof(val)) === "object") {
  252. Object.keys(val).map(function (prop) {
  253. element.style[prop] = val[prop];
  254. });
  255. }
  256. } else if (i in element) {
  257. element[i] = val;
  258. } else {
  259. element.setAttribute(i, val);
  260. }
  261. }
  262. return element;
  263. };
  264. $.createSVG = function (tag, o) {
  265. var element = document.createElementNS("http://www.w3.org/2000/svg", tag);
  266. for (var i in o) {
  267. var val = o[i];
  268. if (i === "inside") {
  269. $(val).appendChild(element);
  270. } else if (i === "around") {
  271. var ref = $(val);
  272. ref.parentNode.insertBefore(element, ref);
  273. element.appendChild(ref);
  274. } else {
  275. if (i === "className") {
  276. i = "class";
  277. }
  278. if (i === "innerHTML") {
  279. element['textContent'] = val;
  280. } else {
  281. element.setAttribute(i, val);
  282. }
  283. }
  284. }
  285. return element;
  286. };
  287. $.runSVGAnimation = function (svg_container, elements) {
  288. // let parent = elements[0][0]['unit'].parentNode;
  289. var new_elements = [];
  290. var anim_elements = [];
  291. elements.map(function (element) {
  292. var obj = element[0];
  293. var parent = obj.unit.parentNode;
  294. // let index = let findNodeIndex(obj.unit);
  295. var anim_element = void 0,
  296. new_element = void 0;
  297. element[0] = obj.unit;
  298. var _$$animateSVG = $.animateSVG.apply($, toConsumableArray(element));
  299. var _$$animateSVG2 = slicedToArray(_$$animateSVG, 2);
  300. anim_element = _$$animateSVG2[0];
  301. new_element = _$$animateSVG2[1];
  302. new_elements.push(new_element);
  303. anim_elements.push([anim_element, parent]);
  304. parent.replaceChild(anim_element, obj.unit);
  305. if (obj.array) {
  306. obj.array[obj.index] = new_element;
  307. } else {
  308. obj.object[obj.key] = new_element;
  309. }
  310. });
  311. var anim_svg = svg_container.cloneNode(true);
  312. anim_elements.map(function (anim_element, i) {
  313. anim_element[1].replaceChild(new_elements[i], anim_element[0]);
  314. elements[i][0] = new_elements[i];
  315. });
  316. return anim_svg;
  317. };
  318. $.transform = function (element, style) {
  319. element.style.transform = style;
  320. element.style.webkitTransform = style;
  321. element.style.msTransform = style;
  322. element.style.mozTransform = style;
  323. element.style.oTransform = style;
  324. };
  325. $.animateSVG = function (element, props, dur) {
  326. var easing_type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "linear";
  327. var type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
  328. var old_values = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  329. var anim_element = element.cloneNode(true);
  330. var new_element = element.cloneNode(true);
  331. for (var attributeName in props) {
  332. var animate_element = void 0;
  333. if (attributeName === 'transform') {
  334. animate_element = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");
  335. } else {
  336. animate_element = document.createElementNS("http://www.w3.org/2000/svg", "animate");
  337. }
  338. var current_value = old_values[attributeName] || element.getAttribute(attributeName);
  339. var value = props[attributeName];
  340. var anim_attr = {
  341. attributeName: attributeName,
  342. from: current_value,
  343. to: value,
  344. begin: "0s",
  345. dur: dur / 1000 + "s",
  346. values: current_value + ";" + value,
  347. keySplines: EASING[easing_type],
  348. keyTimes: "0;1",
  349. calcMode: "spline",
  350. fill: 'freeze'
  351. };
  352. if (type) {
  353. anim_attr["type"] = type;
  354. }
  355. for (var i in anim_attr) {
  356. animate_element.setAttribute(i, anim_attr[i]);
  357. }
  358. anim_element.appendChild(animate_element);
  359. if (type) {
  360. new_element.setAttribute(attributeName, "translate(" + value + ")");
  361. } else {
  362. new_element.setAttribute(attributeName, value);
  363. }
  364. }
  365. return [anim_element, new_element];
  366. };
  367. $.offset = function (element) {
  368. var rect = element.getBoundingClientRect();
  369. return {
  370. // https://stackoverflow.com/a/7436602/6495043
  371. // rect.top varies with scroll, so we add whatever has been
  372. // scrolled to it to get absolute distance from actual page top
  373. top: rect.top + (document.documentElement.scrollTop || document.body.scrollTop),
  374. left: rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft)
  375. };
  376. };
  377. $.isElementInViewport = function (el) {
  378. // Although straightforward: https://stackoverflow.com/a/7557433/6495043
  379. var rect = el.getBoundingClientRect();
  380. return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
  381. rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
  382. ;
  383. };
  384. $.bind = function (element, o) {
  385. if (element) {
  386. for (var event in o) {
  387. var callback = o[event];
  388. event.split(/\s+/).forEach(function (event) {
  389. element.addEventListener(event, callback);
  390. });
  391. }
  392. }
  393. };
  394. $.unbind = function (element, o) {
  395. if (element) {
  396. for (var event in o) {
  397. var callback = o[event];
  398. event.split(/\s+/).forEach(function (event) {
  399. element.removeEventListener(event, callback);
  400. });
  401. }
  402. }
  403. };
  404. $.fire = function (target, type, properties) {
  405. var evt = document.createEvent("HTMLEvents");
  406. evt.initEvent(type, true, true);
  407. for (var j in properties) {
  408. evt[j] = properties[j];
  409. }
  410. return target.dispatchEvent(evt);
  411. };
  412. function float_2(d) {
  413. return parseFloat(d.toFixed(2));
  414. }
  415. function arrays_equal(arr1, arr2) {
  416. if (arr1.length !== arr2.length) return false;
  417. var are_equal = true;
  418. arr1.map(function (d, i) {
  419. if (arr2[i] !== d) are_equal = false;
  420. });
  421. return are_equal;
  422. }
  423. function limitColor(r) {
  424. if (r > 255) return 255;else if (r < 0) return 0;
  425. return r;
  426. }
  427. function lightenDarkenColor(col, amt) {
  428. var usePound = false;
  429. if (col[0] == "#") {
  430. col = col.slice(1);
  431. usePound = true;
  432. }
  433. var num = parseInt(col, 16);
  434. var r = limitColor((num >> 16) + amt);
  435. var b = limitColor((num >> 8 & 0x00FF) + amt);
  436. var g = limitColor((num & 0x0000FF) + amt);
  437. return (usePound ? "#" : "") + (g | b << 8 | r << 16).toString(16);
  438. }
  439. var SvgTip = function () {
  440. function SvgTip(_ref) {
  441. var _ref$parent = _ref.parent,
  442. parent = _ref$parent === undefined ? null : _ref$parent;
  443. classCallCheck(this, SvgTip);
  444. this.parent = parent;
  445. this.title_name = '';
  446. this.title_value = '';
  447. this.list_values = [];
  448. this.title_value_first = 0;
  449. this.x = 0;
  450. this.y = 0;
  451. this.top = 0;
  452. this.left = 0;
  453. this.setup();
  454. }
  455. createClass(SvgTip, [{
  456. key: 'setup',
  457. value: function setup() {
  458. this.make_tooltip();
  459. }
  460. }, {
  461. key: 'refresh',
  462. value: function refresh() {
  463. this.fill();
  464. this.calc_position();
  465. // this.show_tip();
  466. }
  467. }, {
  468. key: 'make_tooltip',
  469. value: function make_tooltip() {
  470. var _this = this;
  471. this.container = $.create('div', {
  472. inside: this.parent,
  473. className: 'graph-svg-tip comparison',
  474. 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>'
  475. });
  476. this.hide_tip();
  477. this.title = this.container.querySelector('.title');
  478. this.data_point_list = this.container.querySelector('.data-point-list');
  479. this.parent.addEventListener('mouseleave', function () {
  480. _this.hide_tip();
  481. });
  482. }
  483. }, {
  484. key: 'fill',
  485. value: function fill() {
  486. var _this2 = this;
  487. var title = void 0;
  488. if (this.title_value_first) {
  489. title = '<strong>' + this.title_value + '</strong>' + this.title_name;
  490. } else {
  491. title = this.title_name + '<strong>' + this.title_value + '</strong>';
  492. }
  493. this.title.innerHTML = title;
  494. this.data_point_list.innerHTML = '';
  495. this.list_values.map(function (set$$1) {
  496. var li = $.create('li', {
  497. className: 'border-top ' + (set$$1.color || 'black'),
  498. innerHTML: '<strong style="display: block;">' + (set$$1.value ? set$$1.value : '') + '</strong>\n\t\t\t\t\t' + (set$$1.title ? set$$1.title : '')
  499. });
  500. _this2.data_point_list.appendChild(li);
  501. });
  502. }
  503. }, {
  504. key: 'calc_position',
  505. value: function calc_position() {
  506. this.top = this.y - this.container.offsetHeight;
  507. this.left = this.x - this.container.offsetWidth / 2;
  508. var max_left = this.parent.offsetWidth - this.container.offsetWidth;
  509. var pointer = this.container.querySelector('.svg-pointer');
  510. if (this.left < 0) {
  511. pointer.style.left = 'calc(50% - ' + -1 * this.left + 'px)';
  512. this.left = 0;
  513. } else if (this.left > max_left) {
  514. var delta = this.left - max_left;
  515. pointer.style.left = 'calc(50% + ' + delta + 'px)';
  516. this.left = max_left;
  517. } else {
  518. pointer.style.left = '50%';
  519. }
  520. }
  521. }, {
  522. key: 'set_values',
  523. value: function set_values(x, y) {
  524. var title_name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  525. var title_value = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
  526. var list_values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  527. var title_value_first = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  528. this.title_name = title_name;
  529. this.title_value = title_value;
  530. this.list_values = list_values;
  531. this.x = x;
  532. this.y = y;
  533. this.title_value_first = title_value_first;
  534. this.refresh();
  535. }
  536. }, {
  537. key: 'hide_tip',
  538. value: function hide_tip() {
  539. this.container.style.top = '0px';
  540. this.container.style.left = '0px';
  541. this.container.style.opacity = '0';
  542. }
  543. }, {
  544. key: 'show_tip',
  545. value: function show_tip() {
  546. this.container.style.top = this.top + 'px';
  547. this.container.style.left = this.left + 'px';
  548. this.container.style.opacity = '1';
  549. }
  550. }]);
  551. return SvgTip;
  552. }();
  553. var BaseChart = function () {
  554. function BaseChart(_ref) {
  555. var _ref$height = _ref.height,
  556. height = _ref$height === undefined ? 240 : _ref$height,
  557. _ref$title = _ref.title,
  558. title = _ref$title === undefined ? '' : _ref$title,
  559. _ref$subtitle = _ref.subtitle,
  560. subtitle = _ref$subtitle === undefined ? '' : _ref$subtitle,
  561. _ref$format_lambdas = _ref.format_lambdas,
  562. format_lambdas = _ref$format_lambdas === undefined ? {} : _ref$format_lambdas,
  563. _ref$summary = _ref.summary,
  564. summary = _ref$summary === undefined ? [] : _ref$summary,
  565. _ref$is_navigable = _ref.is_navigable,
  566. is_navigable = _ref$is_navigable === undefined ? 0 : _ref$is_navigable,
  567. _ref$has_legend = _ref.has_legend,
  568. has_legend = _ref$has_legend === undefined ? 0 : _ref$has_legend,
  569. _ref$type = _ref.type,
  570. type = _ref$type === undefined ? '' : _ref$type,
  571. parent = _ref.parent,
  572. data = _ref.data;
  573. classCallCheck(this, BaseChart);
  574. this.raw_chart_args = arguments[0];
  575. this.parent = document.querySelector(parent);
  576. this.title = title;
  577. this.subtitle = subtitle;
  578. this.data = data;
  579. this.format_lambdas = format_lambdas;
  580. this.specific_values = data.specific_values || [];
  581. this.summary = summary;
  582. this.is_navigable = is_navigable;
  583. if (this.is_navigable) {
  584. this.current_index = 0;
  585. }
  586. this.has_legend = has_legend;
  587. this.chart_types = ['line', 'scatter', 'bar', 'percentage', 'heatmap', 'pie'];
  588. this.set_margins(height);
  589. }
  590. createClass(BaseChart, [{
  591. key: 'get_different_chart',
  592. value: function get_different_chart(type) {
  593. if (!this.chart_types.includes(type)) {
  594. console.error('\'' + type + '\' is not a valid chart type.');
  595. }
  596. if (type === this.type) return;
  597. // Only across compatible types
  598. var compatible_types = {
  599. bar: ['line', 'scatter', 'percentage', 'pie'],
  600. line: ['scatter', 'bar', 'percentage', 'pie'],
  601. pie: ['line', 'scatter', 'percentage', 'bar'],
  602. scatter: ['line', 'bar', 'percentage', 'pie'],
  603. percentage: ['bar', 'line', 'scatter', 'pie'],
  604. heatmap: []
  605. };
  606. if (!compatible_types[this.type].includes(type)) {
  607. console.error('\'' + this.type + '\' chart cannot be converted to a \'' + type + '\' chart.');
  608. }
  609. // Okay, this is anticlimactic
  610. // this function will need to actually be 'change_chart_type(type)'
  611. // that will update only the required elements, but for now ...
  612. return new Chart({
  613. parent: this.raw_chart_args.parent,
  614. title: this.title,
  615. data: this.raw_chart_args.data,
  616. type: type,
  617. height: this.raw_chart_args.height
  618. });
  619. }
  620. }, {
  621. key: 'set_margins',
  622. value: function set_margins(height) {
  623. this.base_height = height;
  624. this.height = height - 40;
  625. this.translate_x = 60;
  626. this.translate_y = 10;
  627. }
  628. }, {
  629. key: 'setup',
  630. value: function setup() {
  631. if (!this.parent) {
  632. console.error("No parent element to render on was provided.");
  633. return;
  634. }
  635. this.bind_window_events();
  636. this.refresh(true);
  637. }
  638. }, {
  639. key: 'bind_window_events',
  640. value: function bind_window_events() {
  641. var _this = this;
  642. window.addEventListener('resize', function () {
  643. return _this.refresh();
  644. });
  645. window.addEventListener('orientationchange', function () {
  646. return _this.refresh();
  647. });
  648. }
  649. }, {
  650. key: 'refresh',
  651. value: function refresh() {
  652. var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  653. this.setup_base_values();
  654. this.set_width();
  655. this.setup_container();
  656. this.setup_components();
  657. this.setup_values();
  658. this.setup_utils();
  659. this.make_graph_components(init);
  660. this.make_tooltip();
  661. if (this.summary.length > 0) {
  662. this.show_custom_summary();
  663. } else {
  664. this.show_summary();
  665. }
  666. if (this.is_navigable) {
  667. this.setup_navigation(init);
  668. }
  669. }
  670. }, {
  671. key: 'set_width',
  672. value: function set_width() {
  673. var _this2 = this;
  674. var special_values_width = 0;
  675. this.specific_values.map(function (val) {
  676. if (_this2.get_strwidth(val.title) > special_values_width) {
  677. special_values_width = _this2.get_strwidth(val.title) - 40;
  678. }
  679. });
  680. this.base_width = this.parent.offsetWidth - special_values_width;
  681. this.width = this.base_width - this.translate_x * 2;
  682. }
  683. }, {
  684. key: 'setup_base_values',
  685. value: function setup_base_values() {}
  686. }, {
  687. key: 'setup_container',
  688. value: function setup_container() {
  689. this.container = $.create('div', {
  690. className: 'chart-container',
  691. innerHTML: '<h6 class="title">' + this.title + '</h6>\n\t\t\t\t<h6 class="sub-title uppercase">' + this.subtitle + '</h6>\n\t\t\t\t<div class="frappe-chart graphics"></div>\n\t\t\t\t<div class="graph-stats-container"></div>'
  692. });
  693. // Chart needs a dedicated parent element
  694. this.parent.innerHTML = '';
  695. this.parent.appendChild(this.container);
  696. this.chart_wrapper = this.container.querySelector('.frappe-chart');
  697. this.stats_wrapper = this.container.querySelector('.graph-stats-container');
  698. this.make_chart_area();
  699. this.make_draw_area();
  700. }
  701. }, {
  702. key: 'make_chart_area',
  703. value: function make_chart_area() {
  704. this.svg = $.createSVG('svg', {
  705. className: 'chart',
  706. inside: this.chart_wrapper,
  707. width: this.base_width,
  708. height: this.base_height
  709. });
  710. this.svg_defs = $.createSVG('defs', {
  711. inside: this.svg
  712. });
  713. return this.svg;
  714. }
  715. }, {
  716. key: 'make_draw_area',
  717. value: function make_draw_area() {
  718. this.draw_area = $.createSVG("g", {
  719. className: this.type + '-chart',
  720. inside: this.svg,
  721. transform: 'translate(' + this.translate_x + ', ' + this.translate_y + ')'
  722. });
  723. }
  724. }, {
  725. key: 'setup_components',
  726. value: function setup_components() {}
  727. }, {
  728. key: 'make_tooltip',
  729. value: function make_tooltip() {
  730. this.tip = new SvgTip({
  731. parent: this.chart_wrapper
  732. });
  733. this.bind_tooltip();
  734. }
  735. }, {
  736. key: 'show_summary',
  737. value: function show_summary() {}
  738. }, {
  739. key: 'show_custom_summary',
  740. value: function show_custom_summary() {
  741. var _this3 = this;
  742. this.summary.map(function (d) {
  743. var stats = $.create('div', {
  744. className: 'stats',
  745. innerHTML: '<span class="indicator ' + d.color + '">' + d.title + ': ' + d.value + '</span>'
  746. });
  747. _this3.stats_wrapper.appendChild(stats);
  748. });
  749. }
  750. }, {
  751. key: 'setup_navigation',
  752. value: function setup_navigation() {
  753. var _this4 = this;
  754. var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  755. this.make_overlay();
  756. if (init) {
  757. this.bind_overlay();
  758. document.addEventListener('keydown', function (e) {
  759. if ($.isElementInViewport(_this4.chart_wrapper)) {
  760. e = e || window.event;
  761. if (e.keyCode == '37') {
  762. _this4.on_left_arrow();
  763. } else if (e.keyCode == '39') {
  764. _this4.on_right_arrow();
  765. } else if (e.keyCode == '38') {
  766. _this4.on_up_arrow();
  767. } else if (e.keyCode == '40') {
  768. _this4.on_down_arrow();
  769. } else if (e.keyCode == '13') {
  770. _this4.on_enter_key();
  771. }
  772. }
  773. });
  774. }
  775. }
  776. }, {
  777. key: 'make_overlay',
  778. value: function make_overlay() {}
  779. }, {
  780. key: 'bind_overlay',
  781. value: function bind_overlay() {}
  782. }, {
  783. key: 'bind_units',
  784. value: function bind_units() {}
  785. }, {
  786. key: 'on_left_arrow',
  787. value: function on_left_arrow() {}
  788. }, {
  789. key: 'on_right_arrow',
  790. value: function on_right_arrow() {}
  791. }, {
  792. key: 'on_up_arrow',
  793. value: function on_up_arrow() {}
  794. }, {
  795. key: 'on_down_arrow',
  796. value: function on_down_arrow() {}
  797. }, {
  798. key: 'on_enter_key',
  799. value: function on_enter_key() {}
  800. }, {
  801. key: 'get_data_point',
  802. value: function get_data_point() {
  803. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.current_index;
  804. // check for length
  805. var data_point = {
  806. index: index
  807. };
  808. var y = this.y[0];
  809. ['svg_units', 'y_tops', 'values'].map(function (key) {
  810. var data_key = key.slice(0, key.length - 1);
  811. data_point[data_key] = y[key][index];
  812. });
  813. data_point.label = this.x[index];
  814. return data_point;
  815. }
  816. }, {
  817. key: 'update_current_data_point',
  818. value: function update_current_data_point(index) {
  819. index = parseInt(index);
  820. if (index < 0) index = 0;
  821. if (index >= this.x.length) index = this.x.length - 1;
  822. if (index === this.current_index) return;
  823. this.current_index = index;
  824. $.fire(this.parent, "data-select", this.get_data_point());
  825. }
  826. // Helpers
  827. }, {
  828. key: 'get_strwidth',
  829. value: function get_strwidth(string) {
  830. return (string + "").length * 8;
  831. }
  832. // Objects
  833. }, {
  834. key: 'setup_utils',
  835. value: function setup_utils() {}
  836. }]);
  837. return BaseChart;
  838. }();
  839. var AxisChart = function (_BaseChart) {
  840. inherits(AxisChart, _BaseChart);
  841. function AxisChart(args) {
  842. classCallCheck(this, AxisChart);
  843. var _this = possibleConstructorReturn(this, (AxisChart.__proto__ || Object.getPrototypeOf(AxisChart)).call(this, args));
  844. _this.x = _this.data.labels;
  845. _this.y = _this.data.datasets;
  846. _this.is_series = args.is_series;
  847. _this.get_y_label = _this.format_lambdas.y_label;
  848. _this.get_y_tooltip = _this.format_lambdas.y_tooltip;
  849. _this.get_x_tooltip = _this.format_lambdas.x_tooltip;
  850. _this.colors = ['green', 'blue', 'violet', 'red', 'orange', 'yellow', 'light-blue', 'light-green', 'purple', 'magenta'];
  851. _this.zero_line = _this.height;
  852. return _this;
  853. }
  854. createClass(AxisChart, [{
  855. key: 'setup_values',
  856. value: function setup_values() {
  857. this.data.datasets.map(function (d) {
  858. d.values = d.values.map(function (val) {
  859. return !isNaN(val) ? val : 0;
  860. });
  861. });
  862. this.setup_x();
  863. this.setup_y();
  864. }
  865. }, {
  866. key: 'setup_x',
  867. value: function setup_x() {
  868. var _this2 = this;
  869. this.set_avg_unit_width_and_x_offset();
  870. if (this.x_axis_positions) {
  871. this.x_old_axis_positions = this.x_axis_positions.slice();
  872. }
  873. this.x_axis_positions = this.x.map(function (d, i) {
  874. return float_2(_this2.x_offset + i * _this2.avg_unit_width);
  875. });
  876. if (!this.x_old_axis_positions) {
  877. this.x_old_axis_positions = this.x_axis_positions.slice();
  878. }
  879. }
  880. }, {
  881. key: 'setup_y',
  882. value: function setup_y() {
  883. if (this.y_axis_values) {
  884. this.y_old_axis_values = this.y_axis_values.slice();
  885. }
  886. var values = this.get_all_y_values();
  887. if (this.y_sums && this.y_sums.length > 0) {
  888. values = values.concat(this.y_sums);
  889. }
  890. this.y_axis_values = this.get_y_axis_points(values);
  891. if (!this.y_old_axis_values) {
  892. this.y_old_axis_values = this.y_axis_values.slice();
  893. }
  894. var y_pts = this.y_axis_values;
  895. var value_range = y_pts[y_pts.length - 1] - y_pts[0];
  896. if (this.multiplier) this.old_multiplier = this.multiplier;
  897. this.multiplier = this.height / value_range;
  898. if (!this.old_multiplier) this.old_multiplier = this.multiplier;
  899. var zero_index = y_pts.indexOf(0);
  900. var interval = y_pts[1] - y_pts[0];
  901. var interval_height = interval * this.multiplier;
  902. if (this.zero_line) this.old_zero_line = this.zero_line;
  903. this.zero_line = this.height - zero_index * interval_height;
  904. if (!this.old_zero_line) this.old_zero_line = this.zero_line;
  905. }
  906. }, {
  907. key: 'setup_components',
  908. value: function setup_components() {
  909. get(AxisChart.prototype.__proto__ || Object.getPrototypeOf(AxisChart.prototype), 'setup_components', this).call(this);
  910. this.setup_marker_components();
  911. this.setup_aggregation_components();
  912. this.setup_graph_components();
  913. }
  914. }, {
  915. key: 'setup_marker_components',
  916. value: function setup_marker_components() {
  917. this.y_axis_group = $.createSVG('g', { className: 'y axis', inside: this.draw_area });
  918. this.x_axis_group = $.createSVG('g', { className: 'x axis', inside: this.draw_area });
  919. this.specific_y_group = $.createSVG('g', { className: 'specific axis', inside: this.draw_area });
  920. }
  921. }, {
  922. key: 'setup_aggregation_components',
  923. value: function setup_aggregation_components() {
  924. this.sum_group = $.createSVG('g', { className: 'data-points', inside: this.draw_area });
  925. this.average_group = $.createSVG('g', { className: 'chart-area', inside: this.draw_area });
  926. }
  927. }, {
  928. key: 'setup_graph_components',
  929. value: function setup_graph_components() {
  930. var _this3 = this;
  931. this.svg_units_groups = [];
  932. this.y.map(function (d, i) {
  933. _this3.svg_units_groups[i] = $.createSVG('g', {
  934. className: 'data-points data-points-' + i,
  935. inside: _this3.draw_area
  936. });
  937. });
  938. }
  939. }, {
  940. key: 'make_graph_components',
  941. value: function make_graph_components() {
  942. var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  943. this.make_y_axis();
  944. this.make_x_axis();
  945. this.draw_graph(init);
  946. this.make_y_specifics();
  947. }
  948. // make VERTICAL lines for x values
  949. }, {
  950. key: 'make_x_axis',
  951. value: function make_x_axis() {
  952. var _this4 = this;
  953. var animate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  954. var start_at = void 0,
  955. height = void 0,
  956. text_start_at = void 0,
  957. axis_line_class = '';
  958. if (this.x_axis_mode === 'span') {
  959. // long spanning lines
  960. start_at = -7;
  961. height = this.height + 15;
  962. text_start_at = this.height + 25;
  963. } else if (this.x_axis_mode === 'tick') {
  964. // short label lines
  965. start_at = this.height;
  966. height = 6;
  967. text_start_at = 9;
  968. axis_line_class = 'x-axis-label';
  969. }
  970. this.x_axis_group.setAttribute('transform', 'translate(0,' + start_at + ')');
  971. if (animate) {
  972. this.make_anim_x_axis(height, text_start_at, axis_line_class);
  973. return;
  974. }
  975. var allowed_space = this.avg_unit_width * 1.5;
  976. var allowed_letters = allowed_space / 8;
  977. this.x_axis_group.textContent = '';
  978. this.x.map(function (point, i) {
  979. var space_taken = _this4.get_strwidth(point) + 2;
  980. if (space_taken > allowed_space) {
  981. if (_this4.is_series) {
  982. // Skip some axis lines if X axis is a series
  983. var skips = 1;
  984. while (space_taken / skips * 2 > allowed_space) {
  985. skips++;
  986. }
  987. if (i % skips !== 0) {
  988. return;
  989. }
  990. } else {
  991. point = point.slice(0, allowed_letters - 3) + " ...";
  992. }
  993. }
  994. _this4.x_axis_group.appendChild(_this4.make_x_line(height, text_start_at, point, 'x-value-text', axis_line_class, _this4.x_axis_positions[i]));
  995. });
  996. }
  997. // make HORIZONTAL lines for y values
  998. }, {
  999. key: 'make_y_axis',
  1000. value: function make_y_axis() {
  1001. var _this5 = this;
  1002. var animate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1003. if (animate) {
  1004. this.make_anim_y_axis();
  1005. this.make_anim_y_specifics();
  1006. return;
  1007. }
  1008. var _get_y_axis_line_prop = this.get_y_axis_line_props(),
  1009. _get_y_axis_line_prop2 = slicedToArray(_get_y_axis_line_prop, 4),
  1010. width = _get_y_axis_line_prop2[0],
  1011. text_end_at = _get_y_axis_line_prop2[1],
  1012. axis_line_class = _get_y_axis_line_prop2[2],
  1013. start_at = _get_y_axis_line_prop2[3];
  1014. this.y_axis_group.textContent = '';
  1015. this.y_axis_values.map(function (value, i) {
  1016. _this5.y_axis_group.appendChild(_this5.make_y_line(start_at, width, text_end_at, value, 'y-value-text', axis_line_class, _this5.zero_line - value * _this5.multiplier, value === 0 && i !== 0 // Non-first Zero line
  1017. ));
  1018. });
  1019. }
  1020. }, {
  1021. key: 'get_y_axis_line_props',
  1022. value: function get_y_axis_line_props() {
  1023. var specific = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1024. if (specific) {
  1025. return [this.width, this.width + 5, 'specific-value', 0];
  1026. }
  1027. var width = void 0,
  1028. text_end_at = -9,
  1029. axis_line_class = '',
  1030. start_at = 0;
  1031. if (this.y_axis_mode === 'span') {
  1032. // long spanning lines
  1033. width = this.width + 6;
  1034. start_at = -6;
  1035. } else if (this.y_axis_mode === 'tick') {
  1036. // short label lines
  1037. width = -6;
  1038. axis_line_class = 'y-axis-label';
  1039. }
  1040. return [width, text_end_at, axis_line_class, start_at];
  1041. }
  1042. }, {
  1043. key: 'draw_graph',
  1044. value: function draw_graph() {
  1045. var _this6 = this;
  1046. var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1047. if (this.raw_chart_args.hasOwnProperty("init") && !this.raw_chart_args.init) {
  1048. this.y.map(function (d, i) {
  1049. d.svg_units = [];
  1050. _this6.make_path && _this6.make_path(d, i, _this6.x_axis_positions, d.y_tops, d.color || _this6.colors[i]);
  1051. _this6.make_new_units(d, i);
  1052. _this6.calc_y_dependencies();
  1053. });
  1054. return;
  1055. }
  1056. if (init) {
  1057. this.draw_new_graph_and_animate();
  1058. return;
  1059. }
  1060. this.y.map(function (d, i) {
  1061. d.svg_units = [];
  1062. _this6.make_path && _this6.make_path(d, i, _this6.x_axis_positions, d.y_tops, d.color || _this6.colors[i]);
  1063. _this6.make_new_units(d, i);
  1064. });
  1065. }
  1066. }, {
  1067. key: 'draw_new_graph_and_animate',
  1068. value: function draw_new_graph_and_animate() {
  1069. var _this7 = this;
  1070. var data = [];
  1071. this.y.map(function (d, i) {
  1072. // Anim: Don't draw initial values, store them and update later
  1073. d.y_tops = new Array(d.values.length).fill(_this7.zero_line); // no value
  1074. data.push({ values: d.values });
  1075. d.svg_units = [];
  1076. _this7.make_path && _this7.make_path(d, i, _this7.x_axis_positions, d.y_tops, d.color || _this7.colors[i]);
  1077. _this7.make_new_units(d, i);
  1078. });
  1079. setTimeout(function () {
  1080. _this7.update_values(data);
  1081. }, 350);
  1082. }
  1083. }, {
  1084. key: 'setup_navigation',
  1085. value: function setup_navigation(init) {
  1086. var _this8 = this;
  1087. if (init) {
  1088. // Hack: defer nav till initial update_values
  1089. setTimeout(function () {
  1090. get(AxisChart.prototype.__proto__ || Object.getPrototypeOf(AxisChart.prototype), 'setup_navigation', _this8).call(_this8, init);
  1091. }, 500);
  1092. } else {
  1093. get(AxisChart.prototype.__proto__ || Object.getPrototypeOf(AxisChart.prototype), 'setup_navigation', this).call(this, init);
  1094. }
  1095. }
  1096. }, {
  1097. key: 'make_new_units',
  1098. value: function make_new_units(d, i) {
  1099. this.make_new_units_for_dataset(this.x_axis_positions, d.y_tops, d.color || this.colors[i], i, this.y.length);
  1100. }
  1101. }, {
  1102. key: 'make_new_units_for_dataset',
  1103. value: function make_new_units_for_dataset(x_values, y_values, color, dataset_index, no_of_datasets, units_group, units_array, unit) {
  1104. var _this9 = this;
  1105. if (!units_group) units_group = this.svg_units_groups[dataset_index];
  1106. if (!units_array) units_array = this.y[dataset_index].svg_units;
  1107. if (!unit) unit = this.unit_args;
  1108. units_group.textContent = '';
  1109. units_array.length = 0;
  1110. y_values.map(function (y, i) {
  1111. var data_unit = _this9.draw[unit.type](x_values[i], y, unit.args, color, i, dataset_index, no_of_datasets);
  1112. units_group.appendChild(data_unit);
  1113. units_array.push(data_unit);
  1114. });
  1115. if (this.is_navigable) {
  1116. this.bind_units(units_array);
  1117. }
  1118. }
  1119. }, {
  1120. key: 'make_y_specifics',
  1121. value: function make_y_specifics() {
  1122. var _this10 = this;
  1123. this.specific_y_group.textContent = '';
  1124. this.specific_values.map(function (d) {
  1125. _this10.specific_y_group.appendChild(_this10.make_y_line(0, _this10.width, _this10.width + 5, d.title.toUpperCase(), 'specific-value', 'specific-value', _this10.zero_line - d.value * _this10.multiplier, false, d.line_type));
  1126. });
  1127. }
  1128. }, {
  1129. key: 'bind_tooltip',
  1130. value: function bind_tooltip() {
  1131. var _this11 = this;
  1132. // TODO: could be in tooltip itself, as it is a given functionality for its parent
  1133. this.chart_wrapper.addEventListener('mousemove', function (e) {
  1134. var offset = $.offset(_this11.chart_wrapper);
  1135. var relX = e.pageX - offset.left - _this11.translate_x;
  1136. var relY = e.pageY - offset.top - _this11.translate_y;
  1137. if (relY < _this11.height + _this11.translate_y * 2) {
  1138. _this11.map_tooltip_x_position_and_show(relX);
  1139. } else {
  1140. _this11.tip.hide_tip();
  1141. }
  1142. });
  1143. }
  1144. }, {
  1145. key: 'map_tooltip_x_position_and_show',
  1146. value: function map_tooltip_x_position_and_show(relX) {
  1147. var _this12 = this;
  1148. if (!this.y_min_tops) return;
  1149. for (var i = this.x_axis_positions.length - 1; i >= 0; i--) {
  1150. var x_val = this.x_axis_positions[i];
  1151. // let delta = i === 0 ? this.avg_unit_width : x_val - this.x_axis_positions[i-1];
  1152. if (relX > x_val - this.avg_unit_width / 2) {
  1153. var x = x_val + this.translate_x;
  1154. var y = this.y_min_tops[i] + this.translate_y;
  1155. var title = this.x.formatted && this.x.formatted.length > 0 ? this.x.formatted[i] : this.x[i];
  1156. var values = this.y.map(function (set$$1, j) {
  1157. return {
  1158. title: set$$1.title,
  1159. value: set$$1.formatted ? set$$1.formatted[i] : set$$1.values[i],
  1160. color: set$$1.color || _this12.colors[j]
  1161. };
  1162. });
  1163. // TODO: upside-down tooltips for negative values?
  1164. this.tip.set_values(x, y, title, '', values);
  1165. this.tip.show_tip();
  1166. break;
  1167. }
  1168. }
  1169. }
  1170. // API
  1171. }, {
  1172. key: 'show_sums',
  1173. value: function show_sums() {
  1174. var _this13 = this;
  1175. this.updating = true;
  1176. this.y_sums = new Array(this.x_axis_positions.length).fill(0);
  1177. this.y.map(function (d) {
  1178. d.values.map(function (value, i) {
  1179. _this13.y_sums[i] += value;
  1180. });
  1181. });
  1182. // Remake y axis, animate
  1183. this.update_values();
  1184. // Then make sum units, don't animate
  1185. this.sum_units = [];
  1186. this.make_new_units_for_dataset(this.x_axis_positions, this.y_sums.map(function (val) {
  1187. return float_2(_this13.zero_line - val * _this13.multiplier);
  1188. }), 'light-grey', 0, 1, this.sum_group, this.sum_units);
  1189. // this.make_path && this.make_path(d, i, old_x, old_y, d.color || this.colors[i]);
  1190. this.updating = false;
  1191. }
  1192. }, {
  1193. key: 'hide_sums',
  1194. value: function hide_sums() {
  1195. if (this.updating) return;
  1196. this.y_sums = [];
  1197. this.sum_group.textContent = '';
  1198. this.sum_units = [];
  1199. this.update_values();
  1200. }
  1201. }, {
  1202. key: 'show_averages',
  1203. value: function show_averages() {
  1204. var _this14 = this;
  1205. this.old_specific_values = this.specific_values.slice();
  1206. this.y.map(function (d, i) {
  1207. var sum = 0;
  1208. d.values.map(function (e) {
  1209. sum += e;
  1210. });
  1211. var average = sum / d.values.length;
  1212. _this14.specific_values.push({
  1213. title: "AVG" + " " + (i + 1),
  1214. line_type: "dashed",
  1215. value: average,
  1216. auto: 1
  1217. });
  1218. });
  1219. this.update_values();
  1220. }
  1221. }, {
  1222. key: 'hide_averages',
  1223. value: function hide_averages() {
  1224. var _this15 = this;
  1225. this.old_specific_values = this.specific_values.slice();
  1226. var indices_to_remove = [];
  1227. this.specific_values.map(function (d, i) {
  1228. if (d.auto) indices_to_remove.unshift(i);
  1229. });
  1230. indices_to_remove.map(function (index) {
  1231. _this15.specific_values.splice(index, 1);
  1232. });
  1233. this.update_values();
  1234. }
  1235. }, {
  1236. key: 'update_values',
  1237. value: function update_values(new_y, new_x) {
  1238. var _this16 = this;
  1239. if (!new_x) {
  1240. new_x = this.x;
  1241. }
  1242. this.elements_to_animate = [];
  1243. this.updating = true;
  1244. this.old_x_values = this.x.slice();
  1245. this.old_y_axis_tops = this.y.map(function (d) {
  1246. return d.y_tops.slice();
  1247. });
  1248. this.old_y_values = this.y.map(function (d) {
  1249. return d.values;
  1250. });
  1251. this.no_of_extra_pts = new_x.length - this.x.length;
  1252. // Just update values prop, setup_x/y() will do the rest
  1253. if (new_y) this.y.map(function (d, i) {
  1254. d.values = new_y[i].values;
  1255. });
  1256. if (new_x) this.x = new_x;
  1257. this.setup_x();
  1258. this.setup_y();
  1259. // Animate only if positions have changed
  1260. if (!arrays_equal(this.x_old_axis_positions, this.x_axis_positions)) {
  1261. this.make_x_axis(true);
  1262. setTimeout(function () {
  1263. if (!_this16.updating) _this16.make_x_axis();
  1264. }, 350);
  1265. }
  1266. if (!arrays_equal(this.y_old_axis_values, this.y_axis_values) || this.old_specific_values && !arrays_equal(this.old_specific_values, this.specific_values)) {
  1267. this.make_y_axis(true);
  1268. setTimeout(function () {
  1269. if (!_this16.updating) {
  1270. _this16.make_y_axis();
  1271. _this16.make_y_specifics();
  1272. }
  1273. }, 350);
  1274. }
  1275. // Change in data, so calculate dependencies
  1276. this.calc_y_dependencies();
  1277. this.animate_graphs();
  1278. // Trigger animation with the animatable elements in this.elements_to_animate
  1279. this.run_animation();
  1280. this.updating = false;
  1281. }
  1282. }, {
  1283. key: 'add_data_point',
  1284. value: function add_data_point(y_point, x_point) {
  1285. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.x.length;
  1286. var new_y = this.y.map(function (data_set) {
  1287. return { values: data_set.values };
  1288. });
  1289. new_y.map(function (d, i) {
  1290. d.values.splice(index, 0, y_point[i]);
  1291. });
  1292. var new_x = this.x.slice();
  1293. new_x.splice(index, 0, x_point);
  1294. this.update_values(new_y, new_x);
  1295. }
  1296. }, {
  1297. key: 'remove_data_point',
  1298. value: function remove_data_point() {
  1299. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.x.length - 1;
  1300. if (this.x.length < 3) return;
  1301. var new_y = this.y.map(function (data_set) {
  1302. return { values: data_set.values };
  1303. });
  1304. new_y.map(function (d) {
  1305. d.values.splice(index, 1);
  1306. });
  1307. var new_x = this.x.slice();
  1308. new_x.splice(index, 1);
  1309. this.update_values(new_y, new_x);
  1310. }
  1311. }, {
  1312. key: 'run_animation',
  1313. value: function run_animation() {
  1314. var _this17 = this;
  1315. var anim_svg = $.runSVGAnimation(this.svg, this.elements_to_animate);
  1316. if (this.svg.parentNode == this.chart_wrapper) {
  1317. this.chart_wrapper.removeChild(this.svg);
  1318. this.chart_wrapper.appendChild(anim_svg);
  1319. }
  1320. // Replace the new svg (data has long been replaced)
  1321. setTimeout(function () {
  1322. if (anim_svg.parentNode == _this17.chart_wrapper) {
  1323. _this17.chart_wrapper.removeChild(anim_svg);
  1324. _this17.chart_wrapper.appendChild(_this17.svg);
  1325. }
  1326. }, 250);
  1327. }
  1328. }, {
  1329. key: 'animate_graphs',
  1330. value: function animate_graphs() {
  1331. var _this18 = this;
  1332. this.y.map(function (d, i) {
  1333. // Pre-prep, equilize no of positions between old and new
  1334. var _calc_old_and_new_pos = _this18.calc_old_and_new_postions(d, i),
  1335. _calc_old_and_new_pos2 = slicedToArray(_calc_old_and_new_pos, 4),
  1336. old_x = _calc_old_and_new_pos2[0],
  1337. old_y = _calc_old_and_new_pos2[1],
  1338. new_x = _calc_old_and_new_pos2[2],
  1339. new_y = _calc_old_and_new_pos2[3];
  1340. if (_this18.no_of_extra_pts >= 0) {
  1341. _this18.make_path && _this18.make_path(d, i, old_x, old_y, d.color || _this18.colors[i]);
  1342. _this18.make_new_units_for_dataset(old_x, old_y, d.color || _this18.colors[i], i, _this18.y.length);
  1343. }
  1344. d.path && _this18.animate_path(d, i, old_x, old_y, new_x, new_y);
  1345. _this18.animate_units(d, i, old_x, old_y, new_x, new_y);
  1346. });
  1347. // TODO: replace with real units
  1348. setTimeout(function () {
  1349. _this18.y.map(function (d, i) {
  1350. _this18.make_path && _this18.make_path(d, i, _this18.x_axis_positions, d.y_tops, d.color || _this18.colors[i]);
  1351. _this18.make_new_units(d, i);
  1352. });
  1353. }, 400);
  1354. }
  1355. }, {
  1356. key: 'animate_path',
  1357. value: function animate_path(d, i, old_x, old_y, new_x, new_y) {
  1358. // Animate path
  1359. var new_points_list = new_y.map(function (y, i) {
  1360. return new_x[i] + ',' + y;
  1361. });
  1362. var new_path_str = new_points_list.join("L");
  1363. var path_args = [{ unit: d.path, object: d, key: 'path' }, { d: "M" + new_path_str }, 350, "easein"];
  1364. this.elements_to_animate.push(path_args);
  1365. // Animate region
  1366. if (d.region_path) {
  1367. var reg_start_pt = '0,' + this.zero_line + 'L';
  1368. var reg_end_pt = 'L' + this.width + ',' + this.zero_line;
  1369. var region_args = [{ unit: d.region_path, object: d, key: 'region_path' }, { d: "M" + reg_start_pt + new_path_str + reg_end_pt }, 350, "easein"];
  1370. this.elements_to_animate.push(region_args);
  1371. }
  1372. }
  1373. }, {
  1374. key: 'animate_units',
  1375. value: function animate_units(d, index, old_x, old_y, new_x, new_y) {
  1376. var _this19 = this;
  1377. var type = this.unit_args.type;
  1378. d.svg_units.map(function (unit, i) {
  1379. if (new_x[i] === undefined || new_y[i] === undefined) return;
  1380. _this19.elements_to_animate.push(_this19.animate[type]({ unit: unit, array: d.svg_units, index: i }, // unit, with info to replace where it came from in the data
  1381. new_x[i], new_y[i], index));
  1382. });
  1383. }
  1384. }, {
  1385. key: 'calc_old_and_new_postions',
  1386. value: function calc_old_and_new_postions(d, i) {
  1387. var old_x = this.x_old_axis_positions.slice();
  1388. var new_x = this.x_axis_positions.slice();
  1389. var old_y = this.old_y_axis_tops[i].slice();
  1390. var new_y = d.y_tops.slice();
  1391. var last_old_x_pos = old_x[old_x.length - 1];
  1392. var last_old_y_pos = old_y[old_y.length - 1];
  1393. var last_new_x_pos = new_x[new_x.length - 1];
  1394. var last_new_y_pos = new_y[new_y.length - 1];
  1395. if (this.no_of_extra_pts >= 0) {
  1396. // First substitute current path with a squiggled one (looking the same but
  1397. // having more points at end),
  1398. // then animate to stretch it later to new points
  1399. // (new points already have more points)
  1400. // Hence, the extra end points will correspond to current(old) positions
  1401. var filler_x = new Array(Math.abs(this.no_of_extra_pts)).fill(last_old_x_pos);
  1402. var filler_y = new Array(Math.abs(this.no_of_extra_pts)).fill(last_old_y_pos);
  1403. old_x = old_x.concat(filler_x);
  1404. old_y = old_y.concat(filler_y);
  1405. } else {
  1406. // Just modify the new points to have extra points
  1407. // with the same position at end
  1408. var _filler_x = new Array(Math.abs(this.no_of_extra_pts)).fill(last_new_x_pos);
  1409. var _filler_y = new Array(Math.abs(this.no_of_extra_pts)).fill(last_new_y_pos);
  1410. new_x = new_x.concat(_filler_x);
  1411. new_y = new_y.concat(_filler_y);
  1412. }
  1413. return [old_x, old_y, new_x, new_y];
  1414. }
  1415. }, {
  1416. key: 'make_anim_x_axis',
  1417. value: function make_anim_x_axis(height, text_start_at, axis_line_class) {
  1418. var _this20 = this;
  1419. // Animate X AXIS to account for more or less axis lines
  1420. var old_pos = this.x_old_axis_positions;
  1421. var new_pos = this.x_axis_positions;
  1422. var old_vals = this.old_x_values;
  1423. var new_vals = this.x;
  1424. var last_line_pos = old_pos[old_pos.length - 1];
  1425. var add_and_animate_line = function add_and_animate_line(value, old_pos, new_pos) {
  1426. if (typeof new_pos === 'string') {
  1427. new_pos = parseInt(new_pos.substring(0, new_pos.length - 1));
  1428. }
  1429. var x_line = _this20.make_x_line(height, text_start_at, value, // new value
  1430. 'x-value-text', axis_line_class, old_pos // old position
  1431. );
  1432. _this20.x_axis_group.appendChild(x_line);
  1433. _this20.elements_to_animate && _this20.elements_to_animate.push([{ unit: x_line, array: [0], index: 0 }, { transform: new_pos + ', 0' }, 350, "easein", "translate", { transform: old_pos + ', 0' }]);
  1434. };
  1435. this.x_axis_group.textContent = '';
  1436. this.make_new_axis_anim_lines(old_pos, new_pos, old_vals, new_vals, last_line_pos, add_and_animate_line);
  1437. }
  1438. }, {
  1439. key: 'make_anim_y_axis',
  1440. value: function make_anim_y_axis() {
  1441. var _this21 = this;
  1442. // Animate Y AXIS to account for more or less axis lines
  1443. var old_pos = this.y_old_axis_values.map(function (value) {
  1444. return _this21.zero_line - value * _this21.multiplier;
  1445. });
  1446. var new_pos = this.y_axis_values.map(function (value) {
  1447. return _this21.zero_line - value * _this21.multiplier;
  1448. });
  1449. var old_vals = this.y_old_axis_values;
  1450. var new_vals = this.y_axis_values;
  1451. var last_line_pos = old_pos[old_pos.length - 1];
  1452. this.y_axis_group.textContent = '';
  1453. this.make_new_axis_anim_lines(old_pos, new_pos, old_vals, new_vals, last_line_pos, this.add_and_animate_y_line.bind(this), this.y_axis_group);
  1454. }
  1455. }, {
  1456. key: 'make_anim_y_specifics',
  1457. value: function make_anim_y_specifics() {
  1458. var _this22 = this;
  1459. this.specific_y_group.textContent = '';
  1460. this.specific_values.map(function (d) {
  1461. _this22.add_and_animate_y_line(d.title, _this22.old_zero_line - d.value * _this22.old_multiplier, _this22.zero_line - d.value * _this22.multiplier, 0, _this22.specific_y_group, d.line_type, true);
  1462. });
  1463. }
  1464. }, {
  1465. key: 'make_new_axis_anim_lines',
  1466. value: function make_new_axis_anim_lines(old_pos, new_pos, old_vals, new_vals, last_line_pos, add_and_animate_line, group) {
  1467. var superimposed_positions = void 0,
  1468. superimposed_values = void 0;
  1469. var no_of_extras = new_vals.length - old_vals.length;
  1470. if (no_of_extras > 0) {
  1471. // More axis are needed
  1472. // First make only the superimposed (same position) ones
  1473. // Add in the extras at the end later
  1474. superimposed_positions = new_pos.slice(0, old_pos.length);
  1475. superimposed_values = new_vals.slice(0, old_vals.length);
  1476. } else {
  1477. // Axis have to be reduced
  1478. // Fake it by moving all current extra axis to the last position
  1479. // You'll need filler positions and values in the new arrays
  1480. var filler_vals = new Array(Math.abs(no_of_extras)).fill("");
  1481. superimposed_values = new_vals.concat(filler_vals);
  1482. var filler_pos = new Array(Math.abs(no_of_extras)).fill(last_line_pos + "F");
  1483. superimposed_positions = new_pos.concat(filler_pos);
  1484. }
  1485. superimposed_values.map(function (value, i) {
  1486. add_and_animate_line(value, old_pos[i], superimposed_positions[i], i, group);
  1487. });
  1488. if (no_of_extras > 0) {
  1489. // Add in extra axis in the end
  1490. // and then animate to new positions
  1491. var extra_values = new_vals.slice(old_vals.length);
  1492. var extra_positions = new_pos.slice(old_pos.length);
  1493. extra_values.map(function (value, i) {
  1494. add_and_animate_line(value, last_line_pos, extra_positions[i], i, group);
  1495. });
  1496. }
  1497. }
  1498. }, {
  1499. key: 'make_x_line',
  1500. value: function make_x_line(height, text_start_at, point, label_class, axis_line_class, x_pos) {
  1501. var line = $.createSVG('line', {
  1502. x1: 0,
  1503. x2: 0,
  1504. y1: 0,
  1505. y2: height
  1506. });
  1507. var text = $.createSVG('text', {
  1508. className: label_class,
  1509. x: 0,
  1510. y: text_start_at,
  1511. dy: '.71em',
  1512. innerHTML: point
  1513. });
  1514. var x_level = $.createSVG('g', {
  1515. className: 'tick ' + axis_line_class,
  1516. transform: 'translate(' + x_pos + ', 0)'
  1517. });
  1518. x_level.appendChild(line);
  1519. x_level.appendChild(text);
  1520. return x_level;
  1521. }
  1522. }, {
  1523. key: 'make_y_line',
  1524. value: function make_y_line(start_at, width, text_end_at, point, label_class, axis_line_class, y_pos) {
  1525. var darker = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
  1526. var line_type = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : "";
  1527. var line = $.createSVG('line', {
  1528. className: line_type === "dashed" ? "dashed" : "",
  1529. x1: start_at,
  1530. x2: width,
  1531. y1: 0,
  1532. y2: 0
  1533. });
  1534. var text = $.createSVG('text', {
  1535. className: label_class,
  1536. x: text_end_at,
  1537. y: 0,
  1538. dy: '.32em',
  1539. innerHTML: point + ""
  1540. });
  1541. var y_level = $.createSVG('g', {
  1542. className: 'tick ' + axis_line_class,
  1543. transform: 'translate(0, ' + y_pos + ')',
  1544. 'stroke-opacity': 1
  1545. });
  1546. if (darker) {
  1547. line.style.stroke = "rgba(27, 31, 35, 0.6)";
  1548. }
  1549. y_level.appendChild(line);
  1550. y_level.appendChild(text);
  1551. return y_level;
  1552. }
  1553. }, {
  1554. key: 'add_and_animate_y_line',
  1555. value: function add_and_animate_y_line(value, old_pos, new_pos, i, group, type) {
  1556. var specific = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
  1557. var filler = false;
  1558. if (typeof new_pos === 'string') {
  1559. new_pos = parseInt(new_pos.substring(0, new_pos.length - 1));
  1560. filler = true;
  1561. }
  1562. var new_props = { transform: '0, ' + new_pos };
  1563. var old_props = { transform: '0, ' + old_pos };
  1564. if (filler) {
  1565. new_props['stroke-opacity'] = 0;
  1566. // old_props['stroke-opacity'] = 1;
  1567. }
  1568. var _get_y_axis_line_prop3 = this.get_y_axis_line_props(specific),
  1569. _get_y_axis_line_prop4 = slicedToArray(_get_y_axis_line_prop3, 4),
  1570. width = _get_y_axis_line_prop4[0],
  1571. text_end_at = _get_y_axis_line_prop4[1],
  1572. axis_line_class = _get_y_axis_line_prop4[2],
  1573. start_at = _get_y_axis_line_prop4[3];
  1574. var axis_label_class = !specific ? 'y-value-text' : 'specific-value';
  1575. value = !specific ? value : (value + "").toUpperCase();
  1576. var y_line = this.make_y_line(start_at, width, text_end_at, value, axis_label_class, axis_line_class, old_pos, // old position
  1577. value === 0 && i !== 0, // Non-first Zero line
  1578. type);
  1579. group.appendChild(y_line);
  1580. this.elements_to_animate && this.elements_to_animate.push([{ unit: y_line, array: [0], index: 0 }, new_props, 350, "easein", "translate", old_props]);
  1581. }
  1582. }, {
  1583. key: 'get_y_axis_points',
  1584. value: function get_y_axis_points(array) {
  1585. var _this23 = this;
  1586. //*** Where the magic happens ***
  1587. // Calculates best-fit y intervals from given values
  1588. // and returns the interval array
  1589. // TODO: Fractions
  1590. var max_bound = void 0,
  1591. min_bound = void 0,
  1592. pos_no_of_parts = void 0,
  1593. neg_no_of_parts = void 0,
  1594. part_size = void 0; // eslint-disable-line no-unused-vars
  1595. // Critical values
  1596. var max_val = parseInt(Math.max.apply(Math, toConsumableArray(array)));
  1597. var min_val = parseInt(Math.min.apply(Math, toConsumableArray(array)));
  1598. if (min_val >= 0) {
  1599. min_val = 0;
  1600. }
  1601. var get_params = function get_params(value1, value2) {
  1602. var bound1 = void 0,
  1603. bound2 = void 0,
  1604. no_of_parts_1 = void 0,
  1605. no_of_parts_2 = void 0,
  1606. interval_size = void 0;
  1607. if ((value1 + "").length <= 1) {
  1608. bound1 = 10;
  1609. no_of_parts_1 = 5;
  1610. } else {
  1611. var _calc_upper_bound_and = _this23.calc_upper_bound_and_no_of_parts(value1);
  1612. var _calc_upper_bound_and2 = slicedToArray(_calc_upper_bound_and, 2);
  1613. bound1 = _calc_upper_bound_and2[0];
  1614. no_of_parts_1 = _calc_upper_bound_and2[1];
  1615. }
  1616. interval_size = bound1 / no_of_parts_1;
  1617. no_of_parts_2 = _this23.calc_no_of_parts(value2, interval_size);
  1618. bound2 = no_of_parts_2 * interval_size;
  1619. return [bound1, bound2, no_of_parts_1, no_of_parts_2, interval_size];
  1620. };
  1621. var abs_min_val = min_val * -1;
  1622. if (abs_min_val <= max_val) {
  1623. var _get_params = get_params(max_val, abs_min_val);
  1624. // Get the positive region intervals
  1625. // then calc negative ones accordingly
  1626. var _get_params2 = slicedToArray(_get_params, 5);
  1627. min_bound = _get_params2[1];
  1628. pos_no_of_parts = _get_params2[2];
  1629. neg_no_of_parts = _get_params2[3];
  1630. part_size = _get_params2[4];
  1631. if (abs_min_val === 0) {
  1632. min_bound = 0;neg_no_of_parts = 0;
  1633. }
  1634. } else {
  1635. var _get_params3 = get_params(abs_min_val, max_val);
  1636. // Get the negative region here first
  1637. var _get_params4 = slicedToArray(_get_params3, 5);
  1638. min_bound = _get_params4[0];
  1639. neg_no_of_parts = _get_params4[2];
  1640. pos_no_of_parts = _get_params4[3];
  1641. part_size = _get_params4[4];
  1642. }
  1643. // Make both region parts even
  1644. if (pos_no_of_parts % 2 !== 0 && neg_no_of_parts > 0) pos_no_of_parts++;
  1645. if (neg_no_of_parts % 2 !== 0) {
  1646. // every increase in no_of_parts entails an increase in corresponding bound
  1647. // except here, it happens implicitly after every calc_no_of_parts() call
  1648. neg_no_of_parts++;
  1649. min_bound += part_size;
  1650. }
  1651. var no_of_parts = pos_no_of_parts + neg_no_of_parts;
  1652. if (no_of_parts > 5) {
  1653. no_of_parts /= 2;
  1654. part_size *= 2;
  1655. pos_no_of_parts /= 2;
  1656. }
  1657. if (max_val < (pos_no_of_parts - 1) * part_size) {
  1658. no_of_parts--;
  1659. }
  1660. return this.get_intervals(-1 * min_bound, part_size, no_of_parts);
  1661. }
  1662. }, {
  1663. key: 'get_intervals',
  1664. value: function get_intervals(start, interval_size, count) {
  1665. var intervals = [];
  1666. for (var i = 0; i <= count; i++) {
  1667. intervals.push(start);
  1668. start += interval_size;
  1669. }
  1670. return intervals;
  1671. }
  1672. }, {
  1673. key: 'calc_upper_bound_and_no_of_parts',
  1674. value: function calc_upper_bound_and_no_of_parts(max_val) {
  1675. // Given a positive value, calculates a nice-number upper bound
  1676. // and a consequent optimal number of parts
  1677. var part_size = Math.pow(10, (max_val + "").length - 1);
  1678. var no_of_parts = this.calc_no_of_parts(max_val, part_size);
  1679. // Use it to get a nice even upper bound
  1680. var upper_bound = part_size * no_of_parts;
  1681. return [upper_bound, no_of_parts];
  1682. }
  1683. }, {
  1684. key: 'calc_no_of_parts',
  1685. value: function calc_no_of_parts(value, divisor) {
  1686. // value should be a positive number, divisor should be greater than 0
  1687. // returns an even no of parts
  1688. var no_of_parts = Math.ceil(value / divisor);
  1689. if (no_of_parts % 2 !== 0) no_of_parts++; // Make it an even number
  1690. return no_of_parts;
  1691. }
  1692. }, {
  1693. key: 'get_optimal_no_of_parts',
  1694. value: function get_optimal_no_of_parts(no_of_parts) {
  1695. // aka Divide by 2 if too large
  1696. return no_of_parts < 5 ? no_of_parts : no_of_parts / 2;
  1697. }
  1698. }, {
  1699. key: 'set_avg_unit_width_and_x_offset',
  1700. value: function set_avg_unit_width_and_x_offset() {
  1701. // Set the ... you get it
  1702. this.avg_unit_width = this.width / (this.x.length - 1);
  1703. this.x_offset = 0;
  1704. }
  1705. }, {
  1706. key: 'get_all_y_values',
  1707. value: function get_all_y_values() {
  1708. var all_values = [];
  1709. // Add in all the y values in the datasets
  1710. this.y.map(function (d) {
  1711. all_values = all_values.concat(d.values);
  1712. });
  1713. // Add in all the specific values
  1714. return all_values.concat(this.specific_values.map(function (d) {
  1715. return d.value;
  1716. }));
  1717. }
  1718. }, {
  1719. key: 'calc_y_dependencies',
  1720. value: function calc_y_dependencies() {
  1721. var _this24 = this;
  1722. this.y_min_tops = new Array(this.x_axis_positions.length).fill(9999);
  1723. this.y.map(function (d) {
  1724. d.y_tops = d.values.map(function (val) {
  1725. return float_2(_this24.zero_line - val * _this24.multiplier);
  1726. });
  1727. d.y_tops.map(function (y_top, i) {
  1728. if (y_top < _this24.y_min_tops[i]) {
  1729. _this24.y_min_tops[i] = y_top;
  1730. }
  1731. });
  1732. });
  1733. // this.chart_wrapper.removeChild(this.tip.container);
  1734. // this.make_tooltip();
  1735. }
  1736. }, {
  1737. key: 'get_bar_height_and_y_attr',
  1738. value: function get_bar_height_and_y_attr(y_top) {
  1739. var height = void 0,
  1740. y = void 0;
  1741. if (y_top <= this.zero_line) {
  1742. height = this.zero_line - y_top;
  1743. y = y_top;
  1744. // In case of invisible bars
  1745. if (height === 0) {
  1746. height = this.height * 0.01;
  1747. y -= height;
  1748. }
  1749. } else {
  1750. height = y_top - this.zero_line;
  1751. y = this.zero_line;
  1752. // In case of invisible bars
  1753. if (height === 0) {
  1754. height = this.height * 0.01;
  1755. }
  1756. }
  1757. return [height, y];
  1758. }
  1759. }, {
  1760. key: 'setup_utils',
  1761. value: function setup_utils() {
  1762. var _this25 = this;
  1763. this.draw = {
  1764. 'bar': function bar(x, y_top, args, color, index, dataset_index, no_of_datasets) {
  1765. var total_width = _this25.avg_unit_width - args.space_width;
  1766. var start_x = x - total_width / 2;
  1767. var width = total_width / no_of_datasets;
  1768. var current_x = start_x + width * dataset_index;
  1769. var _get_bar_height_and_y = _this25.get_bar_height_and_y_attr(y_top),
  1770. _get_bar_height_and_y2 = slicedToArray(_get_bar_height_and_y, 2),
  1771. height = _get_bar_height_and_y2[0],
  1772. y = _get_bar_height_and_y2[1];
  1773. return $.createSVG('rect', {
  1774. className: 'bar mini fill ' + color,
  1775. 'data-point-index': index,
  1776. x: current_x,
  1777. y: y,
  1778. width: width,
  1779. height: height
  1780. });
  1781. },
  1782. 'dot': function dot(x, y, args, color, index) {
  1783. return $.createSVG('circle', {
  1784. className: 'fill ' + color,
  1785. 'data-point-index': index,
  1786. cx: x,
  1787. cy: y,
  1788. r: args.radius
  1789. });
  1790. }
  1791. };
  1792. this.animate = {
  1793. 'bar': function bar(bar_obj, x, y_top, index) {
  1794. var start = x - _this25.avg_unit_width / 4;
  1795. var width = _this25.avg_unit_width / 2 / _this25.y.length;
  1796. var _get_bar_height_and_y3 = _this25.get_bar_height_and_y_attr(y_top),
  1797. _get_bar_height_and_y4 = slicedToArray(_get_bar_height_and_y3, 2),
  1798. height = _get_bar_height_and_y4[0],
  1799. y = _get_bar_height_and_y4[1];
  1800. x = start + width * index;
  1801. return [bar_obj, { width: width, height: height, x: x, y: y }, 350, "easein"];
  1802. // bar.animate({height: args.new_height, y: y_top}, 350, mina.easein);
  1803. },
  1804. 'dot': function dot(dot_obj, x, y_top) {
  1805. return [dot_obj, { cx: x, cy: y_top }, 350, "easein"];
  1806. // dot.animate({cy: y_top}, 350, mina.easein);
  1807. }
  1808. };
  1809. }
  1810. }]);
  1811. return AxisChart;
  1812. }(BaseChart);
  1813. var BarChart = function (_AxisChart) {
  1814. inherits(BarChart, _AxisChart);
  1815. function BarChart(args) {
  1816. classCallCheck(this, BarChart);
  1817. var _this = possibleConstructorReturn(this, (BarChart.__proto__ || Object.getPrototypeOf(BarChart)).call(this, args));
  1818. _this.type = 'bar';
  1819. _this.x_axis_mode = args.x_axis_mode || 'tick';
  1820. _this.y_axis_mode = args.y_axis_mode || 'span';
  1821. _this.setup();
  1822. return _this;
  1823. }
  1824. createClass(BarChart, [{
  1825. key: 'setup_values',
  1826. value: function setup_values() {
  1827. get(BarChart.prototype.__proto__ || Object.getPrototypeOf(BarChart.prototype), 'setup_values', this).call(this);
  1828. this.x_offset = this.avg_unit_width;
  1829. this.unit_args = {
  1830. type: 'bar',
  1831. args: {
  1832. space_width: this.avg_unit_width / 2
  1833. }
  1834. };
  1835. }
  1836. }, {
  1837. key: 'make_overlay',
  1838. value: function make_overlay() {
  1839. // Just make one out of the first element
  1840. var index = this.x.length - 1;
  1841. var unit = this.y[0].svg_units[index];
  1842. this.update_current_data_point(index);
  1843. if (this.overlay) {
  1844. this.overlay.parentNode.removeChild(this.overlay);
  1845. }
  1846. this.overlay = unit.cloneNode();
  1847. this.overlay.style.fill = '#000000';
  1848. this.overlay.style.opacity = '0.4';
  1849. this.draw_area.appendChild(this.overlay);
  1850. }
  1851. }, {
  1852. key: 'bind_overlay',
  1853. value: function bind_overlay() {
  1854. var _this2 = this;
  1855. // on event, update overlay
  1856. this.parent.addEventListener('data-select', function (e) {
  1857. _this2.update_overlay(e.svg_unit);
  1858. });
  1859. }
  1860. }, {
  1861. key: 'bind_units',
  1862. value: function bind_units(units_array) {
  1863. var _this3 = this;
  1864. units_array.map(function (unit) {
  1865. unit.addEventListener('click', function () {
  1866. var index = unit.getAttribute('data-point-index');
  1867. _this3.update_current_data_point(index);
  1868. });
  1869. });
  1870. }
  1871. }, {
  1872. key: 'update_overlay',
  1873. value: function update_overlay(unit) {
  1874. var _this4 = this;
  1875. var attributes = [];
  1876. Object.keys(unit.attributes).map(function (index) {
  1877. attributes.push(unit.attributes[index]);
  1878. });
  1879. attributes.filter(function (attr) {
  1880. return attr.specified;
  1881. }).map(function (attr) {
  1882. _this4.overlay.setAttribute(attr.name, attr.nodeValue);
  1883. });
  1884. }
  1885. }, {
  1886. key: 'on_left_arrow',
  1887. value: function on_left_arrow() {
  1888. this.update_current_data_point(this.current_index - 1);
  1889. }
  1890. }, {
  1891. key: 'on_right_arrow',
  1892. value: function on_right_arrow() {
  1893. this.update_current_data_point(this.current_index + 1);
  1894. }
  1895. }, {
  1896. key: 'set_avg_unit_width_and_x_offset',
  1897. value: function set_avg_unit_width_and_x_offset() {
  1898. this.avg_unit_width = this.width / (this.x.length + 1);
  1899. this.x_offset = this.avg_unit_width;
  1900. }
  1901. }]);
  1902. return BarChart;
  1903. }(AxisChart);
  1904. var LineChart = function (_AxisChart) {
  1905. inherits(LineChart, _AxisChart);
  1906. function LineChart(args) {
  1907. classCallCheck(this, LineChart);
  1908. var _this = possibleConstructorReturn(this, (LineChart.__proto__ || Object.getPrototypeOf(LineChart)).call(this, args));
  1909. _this.x_axis_mode = args.x_axis_mode || 'span';
  1910. _this.y_axis_mode = args.y_axis_mode || 'span';
  1911. if (args.hasOwnProperty('show_dots')) {
  1912. _this.show_dots = args.show_dots;
  1913. } else {
  1914. _this.show_dots = 1;
  1915. }
  1916. _this.region_fill = args.region_fill;
  1917. if (Object.getPrototypeOf(_this) !== LineChart.prototype) {
  1918. return possibleConstructorReturn(_this);
  1919. }
  1920. _this.dot_radius = args.dot_radius || 4;
  1921. _this.heatline = args.heatline;
  1922. _this.type = 'line';
  1923. _this.setup();
  1924. return _this;
  1925. }
  1926. createClass(LineChart, [{
  1927. key: 'setup_graph_components',
  1928. value: function setup_graph_components() {
  1929. this.setup_path_groups();
  1930. get(LineChart.prototype.__proto__ || Object.getPrototypeOf(LineChart.prototype), 'setup_graph_components', this).call(this);
  1931. }
  1932. }, {
  1933. key: 'setup_path_groups',
  1934. value: function setup_path_groups() {
  1935. var _this2 = this;
  1936. this.paths_groups = [];
  1937. this.y.map(function (d, i) {
  1938. _this2.paths_groups[i] = $.createSVG('g', {
  1939. className: 'path-group path-group-' + i,
  1940. inside: _this2.draw_area
  1941. });
  1942. });
  1943. }
  1944. }, {
  1945. key: 'setup_values',
  1946. value: function setup_values() {
  1947. get(LineChart.prototype.__proto__ || Object.getPrototypeOf(LineChart.prototype), 'setup_values', this).call(this);
  1948. this.unit_args = {
  1949. type: 'dot',
  1950. args: { radius: this.dot_radius }
  1951. };
  1952. }
  1953. }, {
  1954. key: 'make_new_units_for_dataset',
  1955. value: function make_new_units_for_dataset(x_values, y_values, color, dataset_index, no_of_datasets, units_group, units_array, unit) {
  1956. if (this.show_dots) {
  1957. get(LineChart.prototype.__proto__ || Object.getPrototypeOf(LineChart.prototype), 'make_new_units_for_dataset', this).call(this, x_values, y_values, color, dataset_index, no_of_datasets, units_group, units_array, unit);
  1958. }
  1959. }
  1960. }, {
  1961. key: 'make_paths',
  1962. value: function make_paths() {
  1963. var _this3 = this;
  1964. this.y.map(function (d, i) {
  1965. _this3.make_path(d, i, _this3.x_axis_positions, d.y_tops, d.color || _this3.colors[i]);
  1966. });
  1967. }
  1968. }, {
  1969. key: 'make_path',
  1970. value: function make_path(d, i, x_positions, y_positions, color) {
  1971. var points_list = y_positions.map(function (y, i) {
  1972. return x_positions[i] + ',' + y;
  1973. });
  1974. var points_str = points_list.join("L");
  1975. this.paths_groups[i].textContent = '';
  1976. d.path = $.createSVG('path', {
  1977. inside: this.paths_groups[i],
  1978. className: 'stroke ' + color,
  1979. d: "M" + points_str
  1980. });
  1981. if (this.heatline) {
  1982. var gradient_id = this.make_gradient(color);
  1983. d.path.style.stroke = 'url(#' + gradient_id + ')';
  1984. }
  1985. if (this.region_fill) {
  1986. this.fill_region_for_dataset(d, i, color, points_str);
  1987. }
  1988. }
  1989. }, {
  1990. key: 'fill_region_for_dataset',
  1991. value: function fill_region_for_dataset(d, i, color, points_str) {
  1992. var gradient_id = this.make_gradient(color, true);
  1993. d.region_path = $.createSVG('path', {
  1994. inside: this.paths_groups[i],
  1995. className: 'region-fill',
  1996. d: "M" + ('0,' + this.zero_line + 'L') + points_str + ('L' + this.width + ',' + this.zero_line)
  1997. });
  1998. d.region_path.style.stroke = "none";
  1999. d.region_path.style.fill = 'url(#' + gradient_id + ')';
  2000. }
  2001. }, {
  2002. key: 'make_gradient',
  2003. value: function make_gradient(color) {
  2004. var lighter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2005. var gradient_id = 'path-fill-gradient' + '-' + color;
  2006. var gradient_def = $.createSVG('linearGradient', {
  2007. inside: this.svg_defs,
  2008. id: gradient_id,
  2009. x1: 0,
  2010. x2: 0,
  2011. y1: 0,
  2012. y2: 1
  2013. });
  2014. var set_gradient_stop = function set_gradient_stop(grad_elem, offset, color, opacity) {
  2015. $.createSVG('stop', {
  2016. 'className': 'stop-color ' + color,
  2017. 'inside': grad_elem,
  2018. 'offset': offset,
  2019. 'stop-opacity': opacity
  2020. });
  2021. };
  2022. var opacities = [1, 0.6, 0.2];
  2023. if (lighter) {
  2024. opacities = [0.4, 0.2, 0];
  2025. }
  2026. set_gradient_stop(gradient_def, "0%", color, opacities[0]);
  2027. set_gradient_stop(gradient_def, "50%", color, opacities[1]);
  2028. set_gradient_stop(gradient_def, "100%", color, opacities[2]);
  2029. return gradient_id;
  2030. }
  2031. }]);
  2032. return LineChart;
  2033. }(AxisChart);
  2034. var ScatterChart = function (_LineChart) {
  2035. inherits(ScatterChart, _LineChart);
  2036. function ScatterChart(args) {
  2037. classCallCheck(this, ScatterChart);
  2038. var _this = possibleConstructorReturn(this, (ScatterChart.__proto__ || Object.getPrototypeOf(ScatterChart)).call(this, args));
  2039. _this.type = 'scatter';
  2040. if (!args.dot_radius) {
  2041. _this.dot_radius = 8;
  2042. } else {
  2043. _this.dot_radius = args.dot_radius;
  2044. }
  2045. _this.setup();
  2046. return _this;
  2047. }
  2048. createClass(ScatterChart, [{
  2049. key: 'setup_graph_components',
  2050. value: function setup_graph_components() {
  2051. this.setup_path_groups();
  2052. get(ScatterChart.prototype.__proto__ || Object.getPrototypeOf(ScatterChart.prototype), 'setup_graph_components', this).call(this);
  2053. }
  2054. }, {
  2055. key: 'setup_path_groups',
  2056. value: function setup_path_groups() {}
  2057. }, {
  2058. key: 'setup_values',
  2059. value: function setup_values() {
  2060. get(ScatterChart.prototype.__proto__ || Object.getPrototypeOf(ScatterChart.prototype), 'setup_values', this).call(this);
  2061. this.unit_args = {
  2062. type: 'dot',
  2063. args: { radius: this.dot_radius }
  2064. };
  2065. }
  2066. }, {
  2067. key: 'make_paths',
  2068. value: function make_paths() {}
  2069. }, {
  2070. key: 'make_path',
  2071. value: function make_path() {}
  2072. }]);
  2073. return ScatterChart;
  2074. }(LineChart);
  2075. var PercentageChart = function (_BaseChart) {
  2076. inherits(PercentageChart, _BaseChart);
  2077. function PercentageChart(args) {
  2078. classCallCheck(this, PercentageChart);
  2079. var _this = possibleConstructorReturn(this, (PercentageChart.__proto__ || Object.getPrototypeOf(PercentageChart)).call(this, args));
  2080. _this.type = 'percentage';
  2081. _this.get_y_label = _this.format_lambdas.y_label;
  2082. _this.get_x_tooltip = _this.format_lambdas.x_tooltip;
  2083. _this.get_y_tooltip = _this.format_lambdas.y_tooltip;
  2084. _this.max_slices = 10;
  2085. _this.max_legend_points = 6;
  2086. _this.colors = args.colors;
  2087. if (!_this.colors || _this.colors.length < _this.data.labels.length) {
  2088. _this.colors = ['light-blue', 'blue', 'violet', 'red', 'orange', 'yellow', 'green', 'light-green', 'purple', 'magenta'];
  2089. }
  2090. _this.setup();
  2091. return _this;
  2092. }
  2093. createClass(PercentageChart, [{
  2094. key: 'make_chart_area',
  2095. value: function make_chart_area() {
  2096. this.chart_wrapper.className += ' ' + 'graph-focus-margin';
  2097. this.chart_wrapper.style.marginTop = '45px';
  2098. this.stats_wrapper.className += ' ' + 'graph-focus-margin';
  2099. this.stats_wrapper.style.marginBottom = '30px';
  2100. this.stats_wrapper.style.paddingTop = '0px';
  2101. }
  2102. }, {
  2103. key: 'make_draw_area',
  2104. value: function make_draw_area() {
  2105. this.chart_div = $.create('div', {
  2106. className: 'div',
  2107. inside: this.chart_wrapper
  2108. });
  2109. this.chart = $.create('div', {
  2110. className: 'progress-chart',
  2111. inside: this.chart_div
  2112. });
  2113. }
  2114. }, {
  2115. key: 'setup_components',
  2116. value: function setup_components() {
  2117. this.percentage_bar = $.create('div', {
  2118. className: 'progress',
  2119. inside: this.chart
  2120. });
  2121. }
  2122. }, {
  2123. key: 'setup_values',
  2124. value: function setup_values() {
  2125. var _this2 = this;
  2126. this.slice_totals = [];
  2127. var all_totals = this.data.labels.map(function (d, i) {
  2128. var total = 0;
  2129. _this2.data.datasets.map(function (e) {
  2130. total += e.values[i];
  2131. });
  2132. return [total, d];
  2133. }).filter(function (d) {
  2134. return d[0] > 0;
  2135. }); // keep only positive results
  2136. var totals = all_totals;
  2137. if (all_totals.length > this.max_slices) {
  2138. all_totals.sort(function (a, b) {
  2139. return b[0] - a[0];
  2140. });
  2141. totals = all_totals.slice(0, this.max_slices - 1);
  2142. var others = all_totals.slice(this.max_slices - 1);
  2143. var sum_of_others = 0;
  2144. others.map(function (d) {
  2145. sum_of_others += d[0];
  2146. });
  2147. totals.push([sum_of_others, 'Rest']);
  2148. this.colors[this.max_slices - 1] = 'grey';
  2149. }
  2150. this.labels = [];
  2151. totals.map(function (d) {
  2152. _this2.slice_totals.push(d[0]);
  2153. _this2.labels.push(d[1]);
  2154. });
  2155. this.legend_totals = this.slice_totals.slice(0, this.max_legend_points);
  2156. }
  2157. }, {
  2158. key: 'setup_utils',
  2159. value: function setup_utils() {}
  2160. }, {
  2161. key: 'make_graph_components',
  2162. value: function make_graph_components() {
  2163. var _this3 = this;
  2164. this.grand_total = this.slice_totals.reduce(function (a, b) {
  2165. return a + b;
  2166. }, 0);
  2167. this.slices = [];
  2168. this.slice_totals.map(function (total, i) {
  2169. var slice = $.create('div', {
  2170. className: 'progress-bar background ' + _this3.colors[i],
  2171. inside: _this3.percentage_bar,
  2172. styles: {
  2173. width: total * 100 / _this3.grand_total + "%"
  2174. }
  2175. });
  2176. _this3.slices.push(slice);
  2177. });
  2178. }
  2179. }, {
  2180. key: 'bind_tooltip',
  2181. value: function bind_tooltip() {
  2182. var _this4 = this;
  2183. this.slices.map(function (slice, i) {
  2184. slice.addEventListener('mouseenter', function () {
  2185. var g_off = $.offset(_this4.chart_wrapper),
  2186. p_off = $.offset(slice);
  2187. var x = p_off.left - g_off.left + slice.offsetWidth / 2;
  2188. var y = p_off.top - g_off.top - 6;
  2189. var title = (_this4.formatted_labels && _this4.formatted_labels.length > 0 ? _this4.formatted_labels[i] : _this4.labels[i]) + ': ';
  2190. var percent = (_this4.slice_totals[i] * 100 / _this4.grand_total).toFixed(1);
  2191. _this4.tip.set_values(x, y, title, percent + "%");
  2192. _this4.tip.show_tip();
  2193. });
  2194. });
  2195. }
  2196. }, {
  2197. key: 'show_summary',
  2198. value: function show_summary() {
  2199. var _this5 = this;
  2200. var x_values = this.formatted_labels && this.formatted_labels.length > 0 ? this.formatted_labels : this.labels;
  2201. this.legend_totals.map(function (d, i) {
  2202. if (d) {
  2203. var stats = $.create('div', {
  2204. className: 'stats',
  2205. inside: _this5.stats_wrapper
  2206. });
  2207. stats.innerHTML = '<span class="indicator ' + _this5.colors[i] + '">\n\t\t\t\t\t<span class="text-muted">' + x_values[i] + ':</span>\n\t\t\t\t\t' + d + '\n\t\t\t\t</span>';
  2208. }
  2209. });
  2210. }
  2211. }]);
  2212. return PercentageChart;
  2213. }(BaseChart);
  2214. var ANGLE_RATIO = Math.PI / 180;
  2215. var FULL_ANGLE = 360;
  2216. var PieChart = function (_BaseChart) {
  2217. inherits(PieChart, _BaseChart);
  2218. function PieChart(args) {
  2219. classCallCheck(this, PieChart);
  2220. var _this = possibleConstructorReturn(this, (PieChart.__proto__ || Object.getPrototypeOf(PieChart)).call(this, args));
  2221. _this.type = 'pie';
  2222. _this.get_y_label = _this.format_lambdas.y_label;
  2223. _this.get_x_tooltip = _this.format_lambdas.x_tooltip;
  2224. _this.get_y_tooltip = _this.format_lambdas.y_tooltip;
  2225. _this.elements_to_animate = null;
  2226. _this.hoverRadio = args.hoverRadio || 0.1;
  2227. _this.max_slices = 10;
  2228. _this.max_legend_points = 6;
  2229. _this.isAnimate = false;
  2230. _this.colors = args.colors;
  2231. _this.startAngle = args.startAngle || 0;
  2232. _this.clockWise = args.clockWise || false;
  2233. if (!_this.colors || _this.colors.length < _this.data.labels.length) {
  2234. _this.colors = ['#7cd6fd', '#5e64ff', '#743ee2', '#ff5858', '#ffa00a', '#FEEF72', '#28a745', '#98d85b', '#b554ff', '#ffa3ef'];
  2235. }
  2236. _this.mouseMove = _this.mouseMove.bind(_this);
  2237. _this.mouseLeave = _this.mouseLeave.bind(_this);
  2238. _this.setup();
  2239. return _this;
  2240. }
  2241. createClass(PieChart, [{
  2242. key: 'setup_values',
  2243. value: function setup_values() {
  2244. var _this2 = this;
  2245. this.centerX = this.width / 2;
  2246. this.centerY = this.height / 2;
  2247. this.radius = this.height > this.width ? this.centerX : this.centerY;
  2248. this.slice_totals = [];
  2249. var all_totals = this.data.labels.map(function (d, i) {
  2250. var total = 0;
  2251. _this2.data.datasets.map(function (e) {
  2252. total += e.values[i];
  2253. });
  2254. return [total, d];
  2255. }).filter(function (d) {
  2256. return d[0] > 0;
  2257. }); // keep only positive results
  2258. var totals = all_totals;
  2259. if (all_totals.length > this.max_slices) {
  2260. all_totals.sort(function (a, b) {
  2261. return b[0] - a[0];
  2262. });
  2263. totals = all_totals.slice(0, this.max_slices - 1);
  2264. var others = all_totals.slice(this.max_slices - 1);
  2265. var sum_of_others = 0;
  2266. others.map(function (d) {
  2267. sum_of_others += d[0];
  2268. });
  2269. totals.push([sum_of_others, 'Rest']);
  2270. this.colors[this.max_slices - 1] = 'grey';
  2271. }
  2272. this.labels = [];
  2273. totals.map(function (d) {
  2274. _this2.slice_totals.push(d[0]);
  2275. _this2.labels.push(d[1]);
  2276. });
  2277. this.legend_totals = this.slice_totals.slice(0, this.max_legend_points);
  2278. }
  2279. }, {
  2280. key: 'setup_utils',
  2281. value: function setup_utils() {}
  2282. }, {
  2283. key: 'makeArcPath',
  2284. value: function makeArcPath(startPosition, endPosition) {
  2285. var centerX = this.centerX,
  2286. centerY = this.centerY,
  2287. radius = this.radius,
  2288. clockWise = this.clockWise;
  2289. return 'M' + centerX + ' ' + centerY + ' L' + (centerX + startPosition.x) + ' ' + (centerY + startPosition.y) + ' A ' + radius + ' ' + radius + ' 0 0 ' + (clockWise ? 1 : 0) + ' ' + (centerX + endPosition.x) + ' ' + (centerY + endPosition.y) + ' z';
  2290. }
  2291. }, {
  2292. key: 'make_graph_components',
  2293. value: function make_graph_components(init) {
  2294. var _this3 = this;
  2295. var radius = this.radius,
  2296. clockWise = this.clockWise;
  2297. this.grand_total = this.slice_totals.reduce(function (a, b) {
  2298. return a + b;
  2299. }, 0);
  2300. var prevSlicesProperties = this.slicesProperties || [];
  2301. this.slices = [];
  2302. this.elements_to_animate = [];
  2303. this.slicesProperties = [];
  2304. var curAngle = 180 - this.startAngle;
  2305. this.slice_totals.map(function (total, i) {
  2306. var startAngle = curAngle;
  2307. var originDiffAngle = total / _this3.grand_total * FULL_ANGLE;
  2308. var diffAngle = clockWise ? -originDiffAngle : originDiffAngle;
  2309. var endAngle = curAngle = curAngle + diffAngle;
  2310. var startPosition = PieChart.getPositionByAngle(startAngle, radius);
  2311. var endPosition = PieChart.getPositionByAngle(endAngle, radius);
  2312. var prevProperty = init && prevSlicesProperties[i];
  2313. var curStart = void 0,
  2314. curEnd = void 0;
  2315. if (init) {
  2316. curStart = prevProperty ? prevProperty.startPosition : startPosition;
  2317. curEnd = prevProperty ? prevProperty.endPosition : startPosition;
  2318. } else {
  2319. curStart = startPosition;
  2320. curEnd = endPosition;
  2321. }
  2322. var curPath = _this3.makeArcPath(curStart, curEnd);
  2323. var slice = $.createSVG('path', {
  2324. inside: _this3.draw_area,
  2325. className: 'pie-path',
  2326. style: 'transition:transform .3s;',
  2327. d: curPath,
  2328. fill: _this3.colors[i]
  2329. });
  2330. _this3.slices.push(slice);
  2331. _this3.slicesProperties.push({
  2332. startPosition: startPosition,
  2333. endPosition: endPosition,
  2334. value: total,
  2335. total: _this3.grand_total,
  2336. startAngle: startAngle,
  2337. endAngle: endAngle,
  2338. angle: diffAngle
  2339. });
  2340. if (init) {
  2341. _this3.elements_to_animate.push([{ unit: slice, array: _this3.slices, index: _this3.slices.length - 1 }, { d: _this3.makeArcPath(startPosition, endPosition) }, 650, "easein", null, {
  2342. d: curPath
  2343. }]);
  2344. }
  2345. });
  2346. if (init) {
  2347. this.run_animation();
  2348. }
  2349. }
  2350. }, {
  2351. key: 'run_animation',
  2352. value: function run_animation() {
  2353. var _this4 = this;
  2354. // if(this.isAnimate) return ;
  2355. // this.isAnimate = true;
  2356. if (!this.elements_to_animate || this.elements_to_animate.length === 0) return;
  2357. var anim_svg = $.runSVGAnimation(this.svg, this.elements_to_animate);
  2358. if (this.svg.parentNode == this.chart_wrapper) {
  2359. this.chart_wrapper.removeChild(this.svg);
  2360. this.chart_wrapper.appendChild(anim_svg);
  2361. }
  2362. // Replace the new svg (data has long been replaced)
  2363. setTimeout(function () {
  2364. // this.isAnimate = false;
  2365. if (anim_svg.parentNode == _this4.chart_wrapper) {
  2366. _this4.chart_wrapper.removeChild(anim_svg);
  2367. _this4.chart_wrapper.appendChild(_this4.svg);
  2368. }
  2369. }, 650);
  2370. }
  2371. }, {
  2372. key: 'calTranslateByAngle',
  2373. value: function calTranslateByAngle(property) {
  2374. var radius = this.radius,
  2375. hoverRadio = this.hoverRadio;
  2376. var position = PieChart.getPositionByAngle(property.startAngle + property.angle / 2, radius);
  2377. return 'translate3d(' + position.x * hoverRadio + 'px,' + position.y * hoverRadio + 'px,0)';
  2378. }
  2379. }, {
  2380. key: 'hoverSlice',
  2381. value: function hoverSlice(path, i, flag, e) {
  2382. if (!path) return;
  2383. if (flag) {
  2384. $.transform(path, this.calTranslateByAngle(this.slicesProperties[i]));
  2385. path.setAttribute('fill', lightenDarkenColor(this.colors[i], 50));
  2386. var g_off = $.offset(this.svg);
  2387. var x = e.pageX - g_off.left + 10;
  2388. var y = e.pageY - g_off.top - 10;
  2389. var title = (this.formatted_labels && this.formatted_labels.length > 0 ? this.formatted_labels[i] : this.labels[i]) + ': ';
  2390. var percent = (this.slice_totals[i] * 100 / this.grand_total).toFixed(1);
  2391. this.tip.set_values(x, y, title, percent + "%");
  2392. this.tip.show_tip();
  2393. } else {
  2394. $.transform(path, 'translate3d(0,0,0)');
  2395. this.tip.hide_tip();
  2396. path.setAttribute('fill', this.colors[i]);
  2397. }
  2398. }
  2399. }, {
  2400. key: 'mouseMove',
  2401. value: function mouseMove(e) {
  2402. var target = e.target;
  2403. var prevIndex = this.curActiveSliceIndex;
  2404. var prevAcitve = this.curActiveSlice;
  2405. for (var i = 0; i < this.slices.length; i++) {
  2406. if (target === this.slices[i]) {
  2407. this.hoverSlice(prevAcitve, prevIndex, false);
  2408. this.curActiveSlice = target;
  2409. this.curActiveSliceIndex = i;
  2410. this.hoverSlice(target, i, true, e);
  2411. break;
  2412. }
  2413. }
  2414. }
  2415. }, {
  2416. key: 'mouseLeave',
  2417. value: function mouseLeave() {
  2418. this.hoverSlice(this.curActiveSlice, this.curActiveSliceIndex, false);
  2419. }
  2420. }, {
  2421. key: 'bind_tooltip',
  2422. value: function bind_tooltip() {
  2423. this.draw_area.addEventListener('mousemove', this.mouseMove);
  2424. this.draw_area.addEventListener('mouseleave', this.mouseLeave);
  2425. }
  2426. }, {
  2427. key: 'show_summary',
  2428. value: function show_summary() {
  2429. var _this5 = this;
  2430. var x_values = this.formatted_labels && this.formatted_labels.length > 0 ? this.formatted_labels : this.labels;
  2431. this.legend_totals.map(function (d, i) {
  2432. if (d) {
  2433. var stats = $.create('div', {
  2434. className: 'stats',
  2435. inside: _this5.stats_wrapper
  2436. });
  2437. stats.innerHTML = '<span class="indicator">\n\t\t\t\t\t<i style="background-color:' + _this5.colors[i] + ';"></i>\n\t\t\t\t\t<span class="text-muted">' + x_values[i] + ':</span>\n\t\t\t\t\t' + d + '\n\t\t\t\t</span>';
  2438. }
  2439. });
  2440. }
  2441. }], [{
  2442. key: 'getPositionByAngle',
  2443. value: function getPositionByAngle(angle, radius) {
  2444. return {
  2445. x: Math.sin(angle * ANGLE_RATIO) * radius,
  2446. y: Math.cos(angle * ANGLE_RATIO) * radius
  2447. };
  2448. }
  2449. }]);
  2450. return PieChart;
  2451. }(BaseChart);
  2452. var Heatmap = function (_BaseChart) {
  2453. inherits(Heatmap, _BaseChart);
  2454. function Heatmap(_ref) {
  2455. var _ref$start = _ref.start,
  2456. start = _ref$start === undefined ? '' : _ref$start,
  2457. _ref$domain = _ref.domain,
  2458. domain = _ref$domain === undefined ? '' : _ref$domain,
  2459. _ref$subdomain = _ref.subdomain,
  2460. subdomain = _ref$subdomain === undefined ? '' : _ref$subdomain,
  2461. _ref$data = _ref.data,
  2462. data = _ref$data === undefined ? {} : _ref$data,
  2463. _ref$discrete_domains = _ref.discrete_domains,
  2464. discrete_domains = _ref$discrete_domains === undefined ? 0 : _ref$discrete_domains,
  2465. _ref$count_label = _ref.count_label,
  2466. count_label = _ref$count_label === undefined ? '' : _ref$count_label;
  2467. classCallCheck(this, Heatmap);
  2468. var _this = possibleConstructorReturn(this, (Heatmap.__proto__ || Object.getPrototypeOf(Heatmap)).call(this, arguments[0]));
  2469. _this.type = 'heatmap';
  2470. _this.domain = domain;
  2471. _this.subdomain = subdomain;
  2472. _this.data = data;
  2473. _this.discrete_domains = discrete_domains;
  2474. _this.count_label = count_label;
  2475. var today = new Date();
  2476. _this.start = start || _this.add_days(today, 365);
  2477. _this.legend_colors = ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127'];
  2478. _this.translate_x = 0;
  2479. _this.setup();
  2480. return _this;
  2481. }
  2482. createClass(Heatmap, [{
  2483. key: 'setup_base_values',
  2484. value: function setup_base_values() {
  2485. this.today = new Date();
  2486. if (!this.start) {
  2487. this.start = new Date();
  2488. this.start.setFullYear(this.start.getFullYear() - 1);
  2489. }
  2490. this.first_week_start = new Date(this.start.toDateString());
  2491. this.last_week_start = new Date(this.today.toDateString());
  2492. if (this.first_week_start.getDay() !== 7) {
  2493. this.add_days(this.first_week_start, -1 * this.first_week_start.getDay());
  2494. }
  2495. if (this.last_week_start.getDay() !== 7) {
  2496. this.add_days(this.last_week_start, -1 * this.last_week_start.getDay());
  2497. }
  2498. this.no_of_cols = this.get_weeks_between(this.first_week_start + '', this.last_week_start + '') + 1;
  2499. }
  2500. }, {
  2501. key: 'set_width',
  2502. value: function set_width() {
  2503. this.base_width = (this.no_of_cols + 3) * 12;
  2504. if (this.discrete_domains) {
  2505. this.base_width += 12 * 12;
  2506. }
  2507. }
  2508. }, {
  2509. key: 'setup_components',
  2510. value: function setup_components() {
  2511. this.domain_label_group = $.createSVG("g", {
  2512. className: "domain-label-group chart-label",
  2513. inside: this.draw_area
  2514. });
  2515. this.data_groups = $.createSVG("g", {
  2516. className: "data-groups",
  2517. inside: this.draw_area,
  2518. transform: 'translate(0, 20)'
  2519. });
  2520. }
  2521. }, {
  2522. key: 'setup_values',
  2523. value: function setup_values() {
  2524. this.domain_label_group.textContent = '';
  2525. this.data_groups.textContent = '';
  2526. this.distribution = this.get_distribution(this.data, this.legend_colors);
  2527. this.month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  2528. this.render_all_weeks_and_store_x_values(this.no_of_cols);
  2529. }
  2530. }, {
  2531. key: 'render_all_weeks_and_store_x_values',
  2532. value: function render_all_weeks_and_store_x_values(no_of_weeks) {
  2533. var current_week_sunday = new Date(this.first_week_start);
  2534. this.week_col = 0;
  2535. this.current_month = current_week_sunday.getMonth();
  2536. this.months = [this.current_month + ''];
  2537. this.month_weeks = {}, this.month_start_points = [];
  2538. this.month_weeks[this.current_month] = 0;
  2539. this.month_start_points.push(13);
  2540. for (var i = 0; i < no_of_weeks; i++) {
  2541. var data_group = void 0,
  2542. month_change = 0;
  2543. var day = new Date(current_week_sunday);
  2544. var _get_week_squares_gro = this.get_week_squares_group(day, this.week_col);
  2545. var _get_week_squares_gro2 = slicedToArray(_get_week_squares_gro, 2);
  2546. data_group = _get_week_squares_gro2[0];
  2547. month_change = _get_week_squares_gro2[1];
  2548. this.data_groups.appendChild(data_group);
  2549. this.week_col += 1 + parseInt(this.discrete_domains && month_change);
  2550. this.month_weeks[this.current_month]++;
  2551. if (month_change) {
  2552. this.current_month = (this.current_month + 1) % 12;
  2553. this.months.push(this.current_month + '');
  2554. this.month_weeks[this.current_month] = 1;
  2555. }
  2556. this.add_days(current_week_sunday, 7);
  2557. }
  2558. this.render_month_labels();
  2559. }
  2560. }, {
  2561. key: 'get_week_squares_group',
  2562. value: function get_week_squares_group(current_date, index) {
  2563. var no_of_weekdays = 7;
  2564. var square_side = 10;
  2565. var cell_padding = 2;
  2566. var step = 1;
  2567. var month_change = 0;
  2568. var week_col_change = 0;
  2569. var data_group = $.createSVG("g", {
  2570. className: "data-group",
  2571. inside: this.data_groups
  2572. });
  2573. for (var y = 0, i = 0; i < no_of_weekdays; i += step, y += square_side + cell_padding) {
  2574. var data_value = 0;
  2575. var color_index = 0;
  2576. var current_timestamp = current_date.getTime() / 1000;
  2577. var timestamp = Math.floor(current_timestamp - current_timestamp % 86400).toFixed(1);
  2578. if (this.data[timestamp]) {
  2579. data_value = this.data[timestamp];
  2580. color_index = this.get_max_checkpoint(data_value, this.distribution);
  2581. }
  2582. if (this.data[Math.round(timestamp)]) {
  2583. data_value = this.data[Math.round(timestamp)];
  2584. color_index = this.get_max_checkpoint(data_value, this.distribution);
  2585. }
  2586. var x = 13 + (index + week_col_change) * 12;
  2587. $.createSVG("rect", {
  2588. className: 'day',
  2589. inside: data_group,
  2590. x: x,
  2591. y: y,
  2592. width: square_side,
  2593. height: square_side,
  2594. fill: this.legend_colors[color_index],
  2595. 'data-date': this.get_dd_mm_yyyy(current_date),
  2596. 'data-value': data_value,
  2597. 'data-day': current_date.getDay()
  2598. });
  2599. var next_date = new Date(current_date);
  2600. this.add_days(next_date, 1);
  2601. if (next_date.getMonth() - current_date.getMonth()) {
  2602. month_change = 1;
  2603. if (this.discrete_domains) {
  2604. week_col_change = 1;
  2605. }
  2606. this.month_start_points.push(13 + (index + week_col_change) * 12);
  2607. }
  2608. current_date = next_date;
  2609. }
  2610. return [data_group, month_change];
  2611. }
  2612. }, {
  2613. key: 'render_month_labels',
  2614. value: function render_month_labels() {
  2615. var _this2 = this;
  2616. // this.first_month_label = 1;
  2617. // if (this.first_week_start.getDate() > 8) {
  2618. // this.first_month_label = 0;
  2619. // }
  2620. // this.last_month_label = 1;
  2621. // let first_month = this.months.shift();
  2622. // let first_month_start = this.month_start_points.shift();
  2623. // render first month if
  2624. // let last_month = this.months.pop();
  2625. // let last_month_start = this.month_start_points.pop();
  2626. // render last month if
  2627. this.months.shift();
  2628. this.month_start_points.shift();
  2629. this.months.pop();
  2630. this.month_start_points.pop();
  2631. this.month_start_points.map(function (start, i) {
  2632. var month_name = _this2.month_names[_this2.months[i]].substring(0, 3);
  2633. $.createSVG('text', {
  2634. className: 'y-value-text',
  2635. inside: _this2.domain_label_group,
  2636. x: start + 12,
  2637. y: 10,
  2638. dy: '.32em',
  2639. innerHTML: month_name
  2640. });
  2641. });
  2642. }
  2643. }, {
  2644. key: 'make_graph_components',
  2645. value: function make_graph_components() {
  2646. Array.prototype.slice.call(this.container.querySelectorAll('.graph-stats-container, .sub-title, .title')).map(function (d) {
  2647. d.style.display = 'None';
  2648. });
  2649. this.chart_wrapper.style.marginTop = '0px';
  2650. this.chart_wrapper.style.paddingTop = '0px';
  2651. }
  2652. }, {
  2653. key: 'bind_tooltip',
  2654. value: function bind_tooltip() {
  2655. var _this3 = this;
  2656. Array.prototype.slice.call(document.querySelectorAll(".data-group .day")).map(function (el) {
  2657. el.addEventListener('mouseenter', function (e) {
  2658. var count = e.target.getAttribute('data-value');
  2659. var date_parts = e.target.getAttribute('data-date').split('-');
  2660. var month = _this3.month_names[parseInt(date_parts[1]) - 1].substring(0, 3);
  2661. var g_off = _this3.chart_wrapper.getBoundingClientRect(),
  2662. p_off = e.target.getBoundingClientRect();
  2663. var width = parseInt(e.target.getAttribute('width'));
  2664. var x = p_off.left - g_off.left + (width + 2) / 2;
  2665. var y = p_off.top - g_off.top - (width + 2) / 2;
  2666. var value = count + ' ' + _this3.count_label;
  2667. var name = ' on ' + month + ' ' + date_parts[0] + ', ' + date_parts[2];
  2668. _this3.tip.set_values(x, y, name, value, [], 1);
  2669. _this3.tip.show_tip();
  2670. });
  2671. });
  2672. }
  2673. }, {
  2674. key: 'update',
  2675. value: function update(data) {
  2676. this.data = data;
  2677. this.setup_values();
  2678. this.bind_tooltip();
  2679. }
  2680. }, {
  2681. key: 'get_distribution',
  2682. value: function get_distribution() {
  2683. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  2684. var mapper_array = arguments[1];
  2685. var data_values = Object.keys(data).map(function (key) {
  2686. return data[key];
  2687. });
  2688. var data_max_value = Math.max.apply(Math, toConsumableArray(data_values));
  2689. var distribution_step = 1 / (mapper_array.length - 1);
  2690. var distribution = [];
  2691. mapper_array.map(function (color, i) {
  2692. var checkpoint = data_max_value * (distribution_step * i);
  2693. distribution.push(checkpoint);
  2694. });
  2695. return distribution;
  2696. }
  2697. }, {
  2698. key: 'get_max_checkpoint',
  2699. value: function get_max_checkpoint(value, distribution) {
  2700. return distribution.filter(function (d, i) {
  2701. if (i === 1) {
  2702. return distribution[0] < value;
  2703. }
  2704. return d <= value;
  2705. }).length - 1;
  2706. }
  2707. // TODO: date utils, move these out
  2708. // https://stackoverflow.com/a/11252167/6495043
  2709. }, {
  2710. key: 'treat_as_utc',
  2711. value: function treat_as_utc(date_str) {
  2712. var result = new Date(date_str);
  2713. result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
  2714. return result;
  2715. }
  2716. }, {
  2717. key: 'get_dd_mm_yyyy',
  2718. value: function get_dd_mm_yyyy(date) {
  2719. var dd = date.getDate();
  2720. var mm = date.getMonth() + 1; // getMonth() is zero-based
  2721. return [(dd > 9 ? '' : '0') + dd, (mm > 9 ? '' : '0') + mm, date.getFullYear()].join('-');
  2722. }
  2723. }, {
  2724. key: 'get_weeks_between',
  2725. value: function get_weeks_between(start_date_str, end_date_str) {
  2726. return Math.ceil(this.get_days_between(start_date_str, end_date_str) / 7);
  2727. }
  2728. }, {
  2729. key: 'get_days_between',
  2730. value: function get_days_between(start_date_str, end_date_str) {
  2731. var milliseconds_per_day = 24 * 60 * 60 * 1000;
  2732. return (this.treat_as_utc(end_date_str) - this.treat_as_utc(start_date_str)) / milliseconds_per_day;
  2733. }
  2734. // mutates
  2735. }, {
  2736. key: 'add_days',
  2737. value: function add_days(date, number_of_days) {
  2738. date.setDate(date.getDate() + number_of_days);
  2739. }
  2740. }, {
  2741. key: 'get_month_name',
  2742. value: function get_month_name() {}
  2743. }]);
  2744. return Heatmap;
  2745. }(BaseChart);
  2746. // if ("development" !== 'production') {
  2747. // // Enable LiveReload
  2748. // document.write(
  2749. // '<script src="http://' + (location.host || 'localhost').split(':')[0] +
  2750. // ':35729/livereload.js?snipver=1"></' + 'script>'
  2751. // );
  2752. // }
  2753. var chartTypes = {
  2754. line: LineChart,
  2755. bar: BarChart,
  2756. scatter: ScatterChart,
  2757. percentage: PercentageChart,
  2758. heatmap: Heatmap,
  2759. pie: PieChart
  2760. };
  2761. function getChartByType() {
  2762. var chartType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'line';
  2763. var options = arguments[1];
  2764. if (!chartTypes[chartType]) {
  2765. return new LineChart(options);
  2766. }
  2767. return new chartTypes[chartType](options);
  2768. }
  2769. var Chart = function Chart(args) {
  2770. classCallCheck(this, Chart);
  2771. return getChartByType(args.type, arguments[0]);
  2772. };
  2773. module.exports = Chart;