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.
 
 
 

3286 linhas
98 KiB

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