mirror of
https://github.com/status-im/whispervis.git
synced 2025-02-08 11:23:53 +00:00
2 lines
53 KiB
JavaScript
Vendored
2 lines
53 KiB
JavaScript
Vendored
var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t,e,i){var a=void 0,s=void 0;return t<=e?(s=t,0===(a=e-t)&&(s-=a=.01*i)):(s=e,0===(a=t-e)&&(a=.01*i)),[a,s]}function i(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function a(t,e){var a=document.createElementNS("http://www.w3.org/2000/svg",t);for(var s in e){var n=e[s];if("inside"===s)i(n).appendChild(a);else if("around"===s){var r=i(n);r.parentNode.insertBefore(a,r),a.appendChild(r)}else"styles"===s?"object"===(void 0===n?"undefined":D(n))&&Object.keys(n).map(function(t){a.style[t]=n[t]}):("className"===s&&(s="class"),"innerHTML"===s?a.textContent=n:a.setAttribute(s,n))}return a}function s(t,e){return a("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function n(t,e,i,s){return a("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":s})}function r(t,e,i,s){return a("svg",{className:e,inside:t,width:i,height:s})}function o(t){return a("defs",{inside:t})}function l(t,e){return a("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function h(t){return a("path",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",d:t,styles:{stroke:arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",fill:arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none"}})}function u(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,r=s(t,a),o=[1,.6,.2];return i&&(o=[.4,.2,0]),n(r,"0%",e,o[0]),n(r,"50%",e,o[1]),n(r,"100%",e,o[2]),a}function c(t,e,i,s){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},o={className:t,x:e,y:i,width:s,height:s,fill:n};return Object.keys(r).map(function(t){o[t]=r[t]}),a("rect",o)}function _(t,e,i,s){return a("text",{className:t,x:e,y:i,dy:".32em",innerHTML:s})}function p(t,e,i,s,n,r){var o=a("line",{x1:0,x2:0,y1:0,y2:t}),l=a("text",{className:s,x:0,y:e,dy:".71em",innerHTML:i}),h=a("g",{className:"tick "+n,transform:"translate("+r+", 0)"});return h.appendChild(o),h.appendChild(l),h}function d(t,e,i,s,n,r,o){var l=arguments.length>7&&void 0!==arguments[7]&&arguments[7],h=a("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),u=a("text",{className:n,x:i,y:0,dy:".32em",innerHTML:s+""}),c=a("g",{className:"tick "+r,transform:"translate(0, "+o+")","stroke-opacity":1});return l&&(h.style.stroke="rgba(27, 31, 35, 0.6)"),c.appendChild(h),c.appendChild(u),c}function f(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var u=n[l]||t.getAttribute(l),c=e[l],_={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:X[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};s&&(_.type=s);for(var p in _)h.setAttribute(p,_[p]);r.appendChild(h),s?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function v(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function m(t,e){var i=[],a=[];e.map(function(t){var e=t[0],s=e.unit.parentNode,n=void 0,r=void 0;t[0]=e.unit;var o=f.apply(void 0,R(t)),l=q(o,2);n=l[0],r=l[1],i.push(r),a.push([n,s]),s.replaceChild(n,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var s=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),s}function g(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function y(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),s=i-a,n=s,r=1;s>5&&(s%2!=0&&(s=++i-a),n=s/2,r=2),s<=2&&(r=s/(n=4)),0===s&&(n=5,r=1);for(var o=[],l=0;l<=n;l++)o.push(a+r*l);return o}function x(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=g(t),a=q(i,2),s=a[0],n=a[1],r=e?e/Math.pow(10,n):0,o=y(s=s.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,n)})}function k(t){function e(t,e){for(var i=x(t),a=i[1]-i[0],s=0,n=1;s<e;n++)s+=a,i.unshift(-1*s);return i}var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,R(t)),s=Math.min.apply(Math,R(t)),n=[];if(a>=0&&s>=0)g(a)[1],n=i?x(a,s):x(a);else if(a>0&&s<0){var r=Math.abs(s);a>=r?(g(a)[1],n=e(a,r)):(g(r)[1],n=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&s<=0){var o=Math.abs(s),l=Math.abs(a);g(o)[1],n=(n=i?x(o,l):x(o)).reverse().map(function(t){return-1*t})}return n}function w(t,e){for(var i=Math.max.apply(Math,R(t)),a=1/(e-1),s=[],n=0;n<e;n++){var r=i*(a*n);s.push(r)}return s}function b(t,e){return e.filter(function(e){return e<t}).length}function C(t){return parseFloat(t.toFixed(2))}function A(t,e){if(t.length!==e.length)return!1;var i=!0;return t.map(function(t,a){e[a]!==t&&(i=!1)}),i}function M(t,e){return(t+"").length*e}function O(t){return t>255?255:t<0?0:t}function N(t,e){var i=$(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var s=parseInt(i,16),n=O((s>>16)+e),r=O((s>>8&255)+e),o=O((255&s)+e);return(a?"#":"")+(o|r<<8|n<<16).toString(16)}function P(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function L(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function T(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function S(t,e){return Math.ceil(z(t,e)/7)}function z(t,e){return(L(e)-L(t))/864e5}function j(t,e){t.setDate(t.getDate()+e)}function E(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return ht[t]?new ht[t](e):new at(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}('.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}.chart-container .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}.chart-container .graph-svg-tip ol,.chart-container .graph-svg-tip ul{padding-left:0;display:-webkit-box;display:-ms-flexbox;display:flex}.chart-container .graph-svg-tip ul.data-point-list li{min-width:90px;-webkit-box-flex:1;-ms-flex:1;flex:1;font-weight:600}.chart-container .graph-svg-tip strong{color:#dfe2e5;font-weight:600}.chart-container .graph-svg-tip .svg-pointer{position:absolute;height:5px;margin:0 0 0 -5px;content:" ";border:5px solid transparent;border-top-color:rgba(0,0,0,.8)}.chart-container .graph-svg-tip.comparison{padding:0;text-align:left;pointer-events:none}.chart-container .graph-svg-tip.comparison .title{display:block;padding:10px;margin:0;font-weight:600;line-height:1;pointer-events:none}.chart-container .graph-svg-tip.comparison ul{margin:0;white-space:nowrap;list-style:none}.chart-container .graph-svg-tip.comparison li{display:inline-block;padding:5px 10px}.chart-container .indicator,.chart-container .indicator-right{background:none;font-size:12px;vertical-align:middle;font-weight:700;color:#6c7680}.chart-container .indicator i{content:"";display:inline-block;height:8px;width:8px;border-radius:8px}.chart-container .indicator:before,.chart-container .indicator i{margin:0 4px 0 0}.chart-container .indicator-right:after{margin:0 0 0 4px}',void 0);var D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},H=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,s){var o={key:t,arg:e,resolve:i,reject:s,next:null};r?r=r.next=o:(n=r=o,a(t,e))})}function a(i,n){try{var r=e[i](n),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):s(r.done?"return":"normal",r.value)}catch(t){s("throw",t)}}function s(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?a(n.key,n.arg):r=null}var n,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),W=function(){function t(t,e){for(var i=0;i<e.length;i++){var a=e[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,i,a){return i&&t(e.prototype,i),a&&t(e,a),e}}(),I=function t(e,i,a){null===e&&(e=Function.prototype);var s=Object.getOwnPropertyDescriptor(e,i);if(void 0===s){var n=Object.getPrototypeOf(e);return null===n?void 0:t(n,i,a)}if("value"in s)return s.value;var r=s.get;if(void 0!==r)return r.call(a)},F=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},B=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},q=function(){function t(t,e){var i=[],a=!0,s=!1,n=void 0;try{for(var r,o=t[Symbol.iterator]();!(a=(r=o.next()).done)&&(i.push(r.value),!e||i.length!==e);a=!0);}catch(t){s=!0,n=t}finally{try{!a&&o.return&&o.return()}finally{if(s)throw n}}return i}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),R=function(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e<t.length;e++)i[e]=t[e];return i}return Array.from(t)};t.findNodeIndex=function(t){for(var e=0;t.previousSibling;)t=t.previousSibling,e++;return e},t.create=function(e,i){var a=document.createElement(e);for(var s in i){var n=i[s];if("inside"===s)t(n).appendChild(a);else if("around"===s){var r=t(n);r.parentNode.insertBefore(a,r),a.appendChild(r)}else"styles"===s?"object"===(void 0===n?"undefined":D(n))&&Object.keys(n).map(function(t){a.style[t]=n[t]}):s in a?a[s]=n:a.setAttribute(s,n)}return a},t.offset=function(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}},t.isElementInViewport=function(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)},t.bind=function(t,e){if(t)for(var i in e){var a=e[i];i.split(/\s+/).forEach(function(e){t.addEventListener(e,a)})}},t.unbind=function(t,e){if(t)for(var i in e){var a=e[i];i.split(/\s+/).forEach(function(e){t.removeEventListener(e,a)})}},t.fire=function(t,e,i){var a=document.createEvent("HTMLEvents");a.initEvent(e,!0,!0);for(var s in i)a[s]=i[s];return t.dispatchEvent(a)};var Y=function(){var t=function(t,e,i){this.totalHeight=t,this.zeroLine=e,this.avgUnitWidth=i};return t.prototype={bar:function(t,i,s,n,r,o,l){var h=this.avgUnitWidth-s.spaceWidth,u=h/l,c=t-h/2+u*o,_=e(i,this.zeroLine,this.totalHeight),p=q(_,2),d=p[0];return a("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":r,x:c,y:p[1],width:u,height:d})},dot:function(t,e,i,s,n){return a("circle",{style:"fill: "+s,"data-point-index":n,cx:t,cy:e,r:i.radius})}},t}(),U=function(){var t=function(t,e,i,a){this.totalHeight=t,this.totalWidth=e,this.avgUnitWidth=a,this.zeroLine=i};return t.prototype={bar:function(t,i,a,s,n){var r=i-this.avgUnitWidth/4,o=this.avgUnitWidth/2/n,l=e(a,this.zeroLine,this.totalHeight),h=q(l,2);return i=r+o*s,[t,{width:o,height:h[0],x:i,y:h[1]},350,"easein"]},dot:function(t,e,i){return[t,{cx:e,cy:i},350,"easein"]},path:function(t,e){var i=[],a=[{unit:t.path,object:t,key:"path"},{d:"M"+e},350,"easein"];if(i.push(a),t.regionPath){var s="0,"+this.zeroLine+"L",n="L"+this.totalWidth+", "+this.zeroLine,r=[{unit:t.regionPath,object:t,key:"regionPath"},{d:"M"+s+e+n},350,"easein"];i.push(r)}return i}},t}(),X={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},V=function(){function e(t){var i=t.parent,a=void 0===i?null:i,s=t.colors,n=void 0===s?[]:s;H(this,e),this.parent=a,this.colors=n,this.title_name="",this.title_value="",this.list_values=[],this.title_value_first=0,this.x=0,this.y=0,this.top=0,this.left=0,this.setup()}return W(e,[{key:"setup",value:function(){this.make_tooltip()}},{key:"refresh",value:function(){this.fill(),this.calc_position()}},{key:"make_tooltip",value:function(){var e=this;this.container=t.create("div",{inside:this.parent,className:"graph-svg-tip comparison",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>'}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){e.hide_tip()})}},{key:"fill",value:function(){var e=this,i=void 0;i=this.title_value_first?"<strong>"+this.title_value+"</strong>"+this.title_name:this.title_name+"<strong>"+this.title_value+"</strong>",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,a){var s=e.colors[a]||"black",n=t.create("li",{styles:{"border-top":"3px solid "+s},innerHTML:'<strong style="display: block;">'+(0===i.value||i.value?i.value:"")+"</strong>\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(n)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var a="calc(50% + "+(this.left-e)+"px)";i.style.left=a,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=s,this.x=t,this.y=e,this.title_value_first=n,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),e}(),G={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},J=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],$=function(t){return G[t]||t},K=["line","scatter","bar","percentage","heatmap","pie"],Q={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},Z={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},tt=function(){function e(t){var i=t.height,a=void 0===i?240:i,s=t.title,n=void 0===s?"":s,r=t.subtitle,o=void 0===r?"":r,l=t.colors,h=void 0===l?[]:l,u=t.summary,c=void 0===u?[]:u,_=t.is_navigable,p=void 0===_?0:_,d=t.has_legend,f=void 0===d?0:d,v=t.type,m=void 0===v?"":v,g=t.parent,y=t.data;H(this,e),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=n,this.subtitle=o,this.data=y,this.specific_values=y.specific_values||[],this.summary=c,this.is_navigable=p,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,m),this.set_margins(a)}return W(e,[{key:"get_different_chart",value:function(t){if(t!==this.type){K.includes(t)||console.error("'"+t+"' is not a valid chart type."),Q[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=Z[this.type].includes(t);return new ut({parent:this.raw_chart_args.parent,title:this.title,data:this.raw_chart_args.data,type:t,height:this.raw_chart_args.height,colors:e?this.colors:void 0})}}},{key:"setColors",value:function(t,e){this.colors=t;var i="percentage"===e||"pie"===e?this.data.labels:this.data.datasets;(!this.colors||i&&this.colors.length<i.length)&&(this.colors=J),this.colors=this.colors.map(function(t){return $(t)})}},{key:"set_margins",value:function(t){this.base_height=t,this.height=t-40,this.translate_x=60,this.translate_y=10}},{key:"setup",value:function(){if(!this.parent)return void console.error("No parent element to render on was provided.");this.validate_and_prepare_data()&&(this.bind_window_events(),this.refresh(!0))}},{key:"validate_and_prepare_data",value:function(){return!0}},{key:"bind_window_events",value:function(){var t=this;window.addEventListener("resize",function(){return t.refresh()}),window.addEventListener("orientationchange",function(){return t.refresh()})}},{key:"refresh",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.setup_base_values(),this.set_width(),this.setup_container(),this.setup_components(),this.setup_values(),this.setup_utils(),this.make_graph_components(t),this.make_tooltip(),this.summary.length>0?this.show_custom_summary():this.show_summary(),this.is_navigable&&this.setup_navigation(t)}},{key:"set_width",value:function(){var t=0;this.specific_values.map(function(e){var i=M(e.title+"",8);i>t&&(t=i-40)}),this.base_width=this.parent.offsetWidth-t,this.width=this.base_width-2*this.translate_x}},{key:"setup_base_values",value:function(){}},{key:"setup_container",value:function(){this.container=t.create("div",{className:"chart-container",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>'}),this.parent.innerHTML="",this.parent.appendChild(this.container),this.chart_wrapper=this.container.querySelector(".frappe-chart"),this.stats_wrapper=this.container.querySelector(".graph-stats-container"),this.make_chart_area(),this.make_draw_area()}},{key:"make_chart_area",value:function(){return this.svg=r(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=o(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=l(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new V({parent:this.chart_wrapper,colors:this.colors}),this.bind_tooltip()}},{key:"show_summary",value:function(){}},{key:"show_custom_summary",value:function(){var e=this;this.summary.map(function(i){var a=t.create("div",{className:"stats",styles:{background:i.color},innerHTML:'<span class="indicator">'+i.title+": "+i.value+"</span>"});e.stats_wrapper.appendChild(a)})}},{key:"setup_navigation",value:function(){var e=this,i=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),i&&(this.bind_overlay(),document.addEventListener("keydown",function(i){t.isElementInViewport(e.chart_wrapper)&&("37"==(i=i||window.event).keyCode?e.on_left_arrow():"39"==i.keyCode?e.on_right_arrow():"38"==i.keyCode?e.on_up_arrow():"40"==i.keyCode?e.on_down_arrow():"13"==i.keyCode&&e.on_enter_key())}))}},{key:"make_overlay",value:function(){}},{key:"bind_overlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"on_left_arrow",value:function(){}},{key:"on_right_arrow",value:function(){}},{key:"on_up_arrow",value:function(){}},{key:"on_down_arrow",value:function(){}},{key:"on_enter_key",value:function(){}},{key:"get_data_point",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.current_index,e={index:t},i=this.y[0];return["svg_units","y_tops","values"].map(function(a){var s=a.slice(0,a.length-1);e[s]=i[a][t]}),e.label=this.x[t],e}},{key:"update_current_data_point",value:function(e){(e=parseInt(e))<0&&(e=0),e>=this.x.length&&(e=this.x.length-1),e!==this.current_index&&(this.current_index=e,t.fire(this.parent,"data-select",this.get_data_point()))}},{key:"setup_utils",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return l(this.draw_area,t,e)}}]),e}(),et=function(e){function i(t){H(this,i);var e=B(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t));return e.x=e.data.labels||[],e.y=e.data.datasets||[],e.is_series=t.is_series,e.format_tooltip_y=t.format_tooltip_y,e.format_tooltip_x=t.format_tooltip_x,e.zero_line=e.height,e}return F(i,e),W(i,[{key:"validate_and_prepare_data",value:function(){return!0}},{key:"setup_values",value:function(){this.data.datasets.map(function(t){t.values=t.values.map(function(t){return isNaN(t)?0:t})}),this.setup_x(),this.setup_y()}},{key:"setup_x",value:function(){var t=this;this.set_avg_unit_width_and_x_offset(),this.x_axis_positions&&(this.x_old_axis_positions=this.x_axis_positions.slice()),this.x_axis_positions=this.x.map(function(e,i){return C(t.x_offset+i*t.avg_unit_width)}),this.x_old_axis_positions||(this.x_old_axis_positions=this.x_axis_positions.slice())}},{key:"setup_y",value:function(){this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var t=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(t=t.concat(this.y_sums)),this.y_axis_values=k(t,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var e=this.y_axis_values,i=e[e.length-1]-e[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/i,this.old_multiplier||(this.old_multiplier=this.multiplier);var a=e[1]-e[0],s=a*this.multiplier,n=void 0;n=e.indexOf(0)>=0?e.indexOf(0):e[0]>0?-1*e[0]/a:-1*e[e.length-1]/a+(e.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-n*s,this.old_zero_line||(this.old_zero_line=this.zero_line)}},{key:"setup_components",value:function(){I(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_components",this).call(this),this.setup_marker_components(),this.setup_aggregation_components(),this.setup_graph_components()}},{key:"setup_marker_components",value:function(){this.y_axis_group=this.makeDrawAreaComponent("y axis"),this.x_axis_group=this.makeDrawAreaComponent("x axis"),this.specific_y_group=this.makeDrawAreaComponent("specific axis")}},{key:"setup_aggregation_components",value:function(){this.sum_group=this.makeDrawAreaComponent("data-points"),this.average_group=this.makeDrawAreaComponent("chart-area")}},{key:"setup_graph_components",value:function(){var t=this;this.svg_units_groups=[],this.y.map(function(e,i){t.svg_units_groups[i]=t.makeDrawAreaComponent("data-points data-points-"+i)})}},{key:"make_graph_components",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_y_axis(),this.make_x_axis(),this.draw_graph(t),this.make_y_specifics()}},{key:"make_x_axis",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=void 0,a=void 0,s=void 0,n="";if("span"===this.x_axis_mode?(i=-7,a=this.height+15,s=this.height+25):"tick"===this.x_axis_mode&&(i=this.height,a=6,s=9,n="x-axis-label"),this.x_axis_group.setAttribute("transform","translate(0,"+i+")"),e)return void this.make_anim_x_axis(a,s,n);var r=1.5*this.avg_unit_width,o=r/8;this.x_axis_group.textContent="",this.x.map(function(e,i){var l=M(e,8)+2;if(l>r)if(t.is_series){for(var h=1;l/h*2>r;)h++;if(i%h!=0)return}else e=e.slice(0,o-3)+" ...";t.x_axis_group.appendChild(p(a,s,e,"x-value-text",n,t.x_axis_positions[i]))})}},{key:"make_y_axis",value:function(){var t=this;if(arguments.length>0&&void 0!==arguments[0]&&arguments[0])return this.make_anim_y_axis(),void this.make_anim_y_specifics();var e=this.get_y_axis_line_props(),i=q(e,4),a=i[0],s=i[1],n=i[2],r=i[3];this.y_axis_group.textContent="",this.y_axis_values.map(function(e,i){t.y_axis_group.appendChild(d(r,a,s,e,"y-value-text",n,t.zero_line-e*t.multiplier,0===e&&0!==i))})}},{key:"get_y_axis_line_props",value:function(){if(arguments.length>0&&void 0!==arguments[0]&&arguments[0])return[this.width,this.width+5,"specific-value",0];var t=void 0,e="",i=0;return"span"===this.y_axis_mode?(t=this.width+6,i=-6):"tick"===this.y_axis_mode&&(t=-6,e="y-axis-label"),[t,-9,e,i]}},{key:"draw_graph",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.raw_chart_args.hasOwnProperty("init")&&!this.raw_chart_args.init?void this.y.map(function(e,i){e.svg_units=[],t.make_path&&t.make_path(e,i,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e,i),t.calc_y_dependencies()}):e?void this.draw_new_graph_and_animate():void this.y.map(function(e,i){e.svg_units=[],t.make_path&&t.make_path(e,i,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e,i)})}},{key:"draw_new_graph_and_animate",value:function(){var t=this,e=[];this.y.map(function(i,a){i.y_tops=new Array(i.values.length).fill(t.zero_line),e.push({values:i.values}),i.svg_units=[],t.make_path&&t.make_path(i,a,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i,a)}),setTimeout(function(){t.update_values(e)},350)}},{key:"setup_navigation",value:function(t){var e=this;t?setTimeout(function(){I(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",e).call(e,t)},500):I(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t,e){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[e],e,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,s,n,r,o){n||(n=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),n.textContent="",r.length=0;var l=new Y(this.height,this.zero_line,this.avg_unit_width);e.map(function(e,h){var u=l[o.type](t[h],e,o.args,i,h,a,s);n.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"make_y_specifics",value:function(){var t=this;this.specific_y_group.textContent="",this.specific_values.map(function(e){t.specific_y_group.appendChild(d(0,t.width,t.width+5,e.title.toUpperCase(),"specific-value","specific-value",t.zero_line-e.value*t.multiplier,!1,e.line_type))})}},{key:"bind_tooltip",value:function(){var e=this;this.chart_wrapper.addEventListener("mousemove",function(i){var a=t.offset(e.chart_wrapper),s=i.pageX-a.left-e.translate_x;i.pageY-a.top-e.translate_y<e.height+2*e.translate_y?e.map_tooltip_x_position_and_show(s):e.tip.hide_tip()})}},{key:"map_tooltip_x_position_and_show",value:function(t){var e=this;if(this.y_min_tops){var i=this.x;this.format_tooltip_x&&this.format_tooltip_x(this.x[0])&&(i=this.x.map(function(t){return e.format_tooltip_x(t)}));for(var a=this.format_tooltip_y&&this.format_tooltip_y(this.y[0].values[0]),s=this.x_axis_positions.length-1;s>=0;s--){var n=this.x_axis_positions[s];if(t>n-this.avg_unit_width/2){var r=n+this.translate_x,o=this.y_min_tops[s]+this.translate_y,l=i[s],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[s]):t.values[s],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"show_sums",value:function(){var t=this;this.updating=!0,this.y_sums=new Array(this.x_axis_positions.length).fill(0),this.y.map(function(e){e.values.map(function(e,i){t.y_sums[i]+=e})}),this.update_values(),this.sum_units=[],this.make_new_units_for_dataset(this.x_axis_positions,this.y_sums.map(function(e){return C(t.zero_line-e*t.multiplier)}),"#f0f4f7",0,1,this.sum_group,this.sum_units),this.updating=!1}},{key:"hide_sums",value:function(){this.updating||(this.y_sums=[],this.sum_group.textContent="",this.sum_units=[],this.update_values())}},{key:"show_averages",value:function(){var t=this;this.old_specific_values=this.specific_values.slice(),this.y.map(function(e,i){var a=0;e.values.map(function(t){a+=t});var s=a/e.values.length;t.specific_values.push({title:"AVG "+(i+1),line_type:"dashed",value:s,auto:1})}),this.update_values()}},{key:"hide_averages",value:function(){var t=this;this.old_specific_values=this.specific_values.slice();var e=[];this.specific_values.map(function(t,i){t.auto&&e.unshift(i)}),e.map(function(e){t.specific_values.splice(e,1)}),this.update_values()}},{key:"update_values",value:function(t,e){var i=this;e||(e=this.x),this.elements_to_animate=[],this.updating=!0,this.old_x_values=this.x.slice(),this.old_y_axis_tops=this.y.map(function(t){return t.y_tops.slice()}),this.old_y_values=this.y.map(function(t){return t.values}),this.no_of_extra_pts=e.length-this.x.length,t&&this.y.map(function(e,i){e.values=t[i].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new U(this.height,this.width,this.zero_line,this.avg_unit_width),A(this.x_old_axis_positions,this.x_axis_positions)||(this.make_x_axis(!0),setTimeout(function(){i.updating||i.make_x_axis()},350)),(!A(this.y_old_axis_values,this.y_axis_values)||this.old_specific_values&&!A(this.old_specific_values,this.specific_values))&&(this.make_y_axis(!0),setTimeout(function(){i.updating||(i.make_y_axis(),i.make_y_specifics())},350)),this.animate_graphs(),this.run_animation(),this.updating=!1}},{key:"add_data_point",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.x.length,a=this.y.map(function(t){return{values:t.values}});a.map(function(e,a){e.values.splice(i,0,t[a])});var s=this.x.slice();s.splice(i,0,e),this.update_values(a,s)}},{key:"remove_data_point",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.x.length-1;if(!(this.x.length<3)){var e=this.y.map(function(t){return{values:t.values}});e.map(function(e){e.values.splice(t,1)});var i=this.x.slice();i.splice(t,1),this.update_values(e,i)}}},{key:"run_animation",value:function(){var t=this,e=m(this.svg,this.elements_to_animate);this.svg.parentNode==this.chart_wrapper&&(this.chart_wrapper.removeChild(this.svg),this.chart_wrapper.appendChild(e)),setTimeout(function(){e.parentNode==t.chart_wrapper&&(t.chart_wrapper.removeChild(e),t.chart_wrapper.appendChild(t.svg))},250)}},{key:"animate_graphs",value:function(){var t=this;this.y.map(function(e,i){var a=t.calc_old_and_new_postions(e,i),s=q(a,4),n=s[0],r=s[1],o=s[2],l=s[3];t.no_of_extra_pts>=0&&(t.make_path&&t.make_path(e,i,n,r,t.colors[i]),t.make_new_units_for_dataset(n,r,t.colors[i],i,t.y.length)),e.path&&t.animate_path(e,i,n,r,o,l),t.animate_units(e,i,n,r,o,l)}),setTimeout(function(){t.y.map(function(e,i){t.make_path&&t.make_path(e,i,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e,i)})},400)}},{key:"animate_path",value:function(t,e,i,a,s,n){var r=n.map(function(t,e){return s[e]+","+t}).join("L");this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,r))}},{key:"animate_units",value:function(t,e,i,a,s,n){var r=this,o=this.unit_args.type;t.svg_units.map(function(i,a){void 0!==s[a]&&void 0!==n[a]&&r.elements_to_animate.push(r.animator[o]({unit:i,array:t.svg_units,index:a},s[a],n[a],e,r.y.length))})}},{key:"calc_old_and_new_postions",value:function(t,e){var i=this.x_old_axis_positions.slice(),a=this.x_axis_positions.slice(),s=this.old_y_axis_tops[e].slice(),n=t.y_tops.slice(),r=i[i.length-1],o=s[s.length-1],l=a[a.length-1],h=n[n.length-1];if(this.no_of_extra_pts>=0){var u=new Array(Math.abs(this.no_of_extra_pts)).fill(r),c=new Array(Math.abs(this.no_of_extra_pts)).fill(o);i=i.concat(u),s=s.concat(c)}else{var _=new Array(Math.abs(this.no_of_extra_pts)).fill(l),p=new Array(Math.abs(this.no_of_extra_pts)).fill(h);a=a.concat(_),n=n.concat(p)}return[i,s,a,n]}},{key:"make_anim_x_axis",value:function(t,e,i){var a=this,s=this.x_old_axis_positions,n=this.x_axis_positions,r=this.old_x_values,o=this.x,l=s[s.length-1],h=function(s,n,r){"string"==typeof r&&(r=parseInt(r.substring(0,r.length-1)));var o=p(t,e,s,"x-value-text",i,n);a.x_axis_group.appendChild(o),a.elements_to_animate&&a.elements_to_animate.push([{unit:o,array:[0],index:0},{transform:r+", 0"},350,"easein","translate",{transform:n+", 0"}])};this.x_axis_group.textContent="",this.make_new_axis_anim_lines(s,n,r,o,l,h)}},{key:"make_anim_y_axis",value:function(){var t=this,e=this.y_old_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),i=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),a=this.y_old_axis_values,s=this.y_axis_values,n=e[e.length-1];this.y_axis_group.textContent="",this.make_new_axis_anim_lines(e,i,a,s,n,this.add_and_animate_y_line.bind(this),this.y_axis_group)}},{key:"make_anim_y_specifics",value:function(){var t=this;this.specific_y_group.textContent="",this.specific_values.map(function(e){t.add_and_animate_y_line(e.title,t.old_zero_line-e.value*t.old_multiplier,t.zero_line-e.value*t.multiplier,0,t.specific_y_group,e.line_type,!0)})}},{key:"make_new_axis_anim_lines",value:function(t,e,i,a,s,n,r){var o=void 0,l=void 0,h=a.length-i.length;if(h>0)o=e.slice(0,t.length),l=a.slice(0,i.length);else{var u=new Array(Math.abs(h)).fill("");l=a.concat(u);var c=new Array(Math.abs(h)).fill(s+"F");o=e.concat(c)}if(l.map(function(e,i){n(e,t[i],o[i],i,r)}),h>0){var _=a.slice(i.length),p=e.slice(t.length);_.map(function(t,e){n(t,s,p[e],e,r)})}}},{key:"add_and_animate_y_line",value:function(t,e,i,a,s,n){var r=arguments.length>6&&void 0!==arguments[6]&&arguments[6],o=!1;"string"==typeof i&&(i=parseInt(i.substring(0,i.length-1)),o=!0);var l={transform:"0, "+i},h={transform:"0, "+e};o&&(l["stroke-opacity"]=0);var u=this.get_y_axis_line_props(r),c=q(u,4),_=c[0],p=c[1],f=c[2],v=c[3],m=r?"specific-value":"y-value-text",g=d(v,_,p,t=r?(t+"").toUpperCase():t,m,f,e,0===t&&0!==a,n);s.appendChild(g),this.elements_to_animate&&this.elements_to_animate.push([{unit:g,array:[0],index:0},l,350,"easein","translate",h])}},{key:"set_avg_unit_width_and_x_offset",value:function(){this.avg_unit_width=this.width/(this.x.length-1),this.x_offset=0}},{key:"get_all_y_values",value:function(){var t=[];return this.y.map(function(e){t=t.concat(e.values)}),t.concat(this.specific_values.map(function(t){return t.value}))}},{key:"calc_y_dependencies",value:function(){var t=this;this.y_min_tops=new Array(this.x_axis_positions.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return C(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e<t.y_min_tops[i]&&(t.y_min_tops[i]=e)})})}}]),i}(tt),it=function(t){function e(t){H(this,e);var i=B(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="bar",i.x_axis_mode=t.x_axis_mode||"tick",i.y_axis_mode=t.y_axis_mode||"span",i.setup(),i}return F(e,t),W(e,[{key:"setup_values",value:function(){I(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.x_offset=this.avg_unit_width,this.unit_args={type:"bar",args:{spaceWidth:this.avg_unit_width/2}}}},{key:"make_overlay",value:function(){var t=this.x.length-1,e=this.y[0].svg_units[t];this.update_current_data_point(t),this.overlay&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=e.cloneNode(),this.overlay.style.fill="#000000",this.overlay.style.opacity="0.4",this.draw_area.appendChild(this.overlay)}},{key:"bind_overlay",value:function(){var t=this;this.parent.addEventListener("data-select",function(e){t.update_overlay(e.svg_unit)})}},{key:"bind_units",value:function(t){var e=this;t.map(function(t){t.addEventListener("click",function(){var i=t.getAttribute("data-point-index");e.update_current_data_point(i)})})}},{key:"update_overlay",value:function(t){var e=this,i=[];Object.keys(t.attributes).map(function(e){i.push(t.attributes[e])}),i.filter(function(t){return t.specified}).map(function(t){e.overlay.setAttribute(t.name,t.nodeValue)}),this.overlay.style.fill="#000000",this.overlay.style.opacity="0.4"}},{key:"on_left_arrow",value:function(){this.update_current_data_point(this.current_index-1)}},{key:"on_right_arrow",value:function(){this.update_current_data_point(this.current_index+1)}},{key:"set_avg_unit_width_and_x_offset",value:function(){this.avg_unit_width=this.width/(this.x.length+1),this.x_offset=this.avg_unit_width}}]),e}(et),at=function(t){function e(t){H(this,e);var i=B(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.x_axis_mode=t.x_axis_mode||"span",i.y_axis_mode=t.y_axis_mode||"span",t.hasOwnProperty("show_dots")?i.show_dots=t.show_dots:i.show_dots=1,i.region_fill=t.region_fill,Object.getPrototypeOf(i)!==e.prototype?B(i):(i.dot_radius=t.dot_radius||4,i.heatline=t.heatline,i.type="line",i.setup(),i)}return F(e,t),W(e,[{key:"setup_graph_components",value:function(){this.setup_path_groups(),I(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_graph_components",this).call(this)}},{key:"setup_path_groups",value:function(){var t=this;this.paths_groups=[],this.y.map(function(e,i){t.paths_groups[i]=l(t.draw_area,"path-group path-group-"+i)})}},{key:"setup_values",value:function(){I(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dot_radius}}}},{key:"make_new_units_for_dataset",value:function(t,i,a,s,n,r,o,l){this.show_dots&&I(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"make_new_units_for_dataset",this).call(this,t,i,a,s,n,r,o,l)}},{key:"make_paths",value:function(){var t=this;this.y.map(function(e,i){t.make_path(e,i,t.x_axis_positions,e.y_tops,e.color||t.colors[i])})}},{key:"make_path",value:function(t,e,i,a,s){var n=a.map(function(t,e){return i[e]+","+t}).join("L");if(this.paths_groups[e].textContent="",t.path=h("M"+n,"line-graph-path",s),this.paths_groups[e].appendChild(t.path),this.heatline){var r=u(this.svg_defs,s);t.path.style.stroke="url(#"+r+")"}this.region_fill&&this.fill_region_for_dataset(t,e,s,n)}},{key:"fill_region_for_dataset",value:function(t,e,i,a){var s=u(this.svg_defs,i,!0),n="M0,"+this.zero_line+"L"+a+"L"+this.width+","+this.zero_line;t.regionPath=h(n,"region-fill","none","url(#"+s+")"),this.paths_groups[e].appendChild(t.regionPath)}}]),e}(et),st=function(t){function e(t){H(this,e);var i=B(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="scatter",t.dot_radius?i.dot_radius=t.dot_radius:i.dot_radius=8,i.setup(),i}return F(e,t),W(e,[{key:"setup_graph_components",value:function(){this.setup_path_groups(),I(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_graph_components",this).call(this)}},{key:"setup_path_groups",value:function(){}},{key:"setup_values",value:function(){I(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dot_radius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(at),nt=function(e){function i(t){H(this,i);var e=B(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t));return e.type="percentage",e.max_slices=10,e.max_legend_points=6,e.setup(),e}return F(i,e),W(i,[{key:"make_chart_area",value:function(){this.chart_wrapper.className+=" graph-focus-margin",this.chart_wrapper.style.marginTop="45px",this.stats_wrapper.className+=" graph-focus-margin",this.stats_wrapper.style.marginBottom="30px",this.stats_wrapper.style.paddingTop="0px"}},{key:"make_draw_area",value:function(){this.chart_div=t.create("div",{className:"div",inside:this.chart_wrapper}),this.chart=t.create("div",{className:"progress-chart",inside:this.chart_div})}},{key:"setup_components",value:function(){this.percentage_bar=t.create("div",{className:"progress",inside:this.chart})}},{key:"setup_values",value:function(){var t=this;this.slice_totals=[];var e=this.data.labels.map(function(e,i){var a=0;return t.data.datasets.map(function(t){a+=t.values[i]}),[a,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"make_graph_components",value:function(){var e=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(i,a){var s=t.create("div",{className:"progress-bar",inside:e.percentage_bar,styles:{background:e.colors[a],width:100*i/e.grand_total+"%"}});e.slices.push(s)})}},{key:"bind_tooltip",value:function(){var e=this;this.slices.map(function(i,a){i.addEventListener("mouseenter",function(){var s=t.offset(e.chart_wrapper),n=t.offset(i),r=n.left-s.left+i.offsetWidth/2,o=n.top-s.top-6,l=(e.formatted_labels&&e.formatted_labels.length>0?e.formatted_labels[a]:e.labels[a])+": ",h=(100*e.slice_totals[a]/e.grand_total).toFixed(1);e.tip.set_values(r,o,l,h+"%"),e.tip.show_tip()})})}},{key:"show_summary",value:function(){var e=this,i=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,s){a&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='<span class="indicator">\n\t\t\t\t\t<i style="background: '+e.colors[s]+'"></i>\n\t\t\t\t\t<span class="text-muted">'+i[s]+":</span>\n\t\t\t\t\t"+a+"\n\t\t\t\t</span>")})}}]),i}(tt),rt=Math.PI/180,ot=function(e){function i(t){H(this,i);var e=B(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t));return e.type="pie",e.elements_to_animate=null,e.hoverRadio=t.hoverRadio||.1,e.max_slices=10,e.max_legend_points=6,e.isAnimate=!1,e.startAngle=t.startAngle||0,e.clockWise=t.clockWise||!1,e.mouseMove=e.mouseMove.bind(e),e.mouseLeave=e.mouseLeave.bind(e),e.setup(),e}return F(i,e),W(i,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var a=0;return t.data.datasets.map(function(t){a+=t.values[i]}),[a,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,a=this.centerY,s=this.radius,n=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+s+" "+s+" 0 0 "+(n?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var e=this,a=this.radius,s=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var n=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var u=r,c=o/e.grand_total*360,_=s?-c:c,p=r+=_,d=i.getPositionByAngle(u,a),f=i.getPositionByAngle(p,a),v=t&&n[l],m=void 0,g=void 0;t?(m=v?v.startPosition:d,g=v?v.endPosition:d):(m=d,g=f);var y=e.makeArcPath(m,g),x=h(y,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.draw_area.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:e.grand_total,startAngle:u,endAngle:p,angle:_}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&this.run_animation()}},{key:"run_animation",value:function(){var t=this;if(this.elements_to_animate&&0!==this.elements_to_animate.length){var e=m(this.svg,this.elements_to_animate);this.svg.parentNode==this.chart_wrapper&&(this.chart_wrapper.removeChild(this.svg),this.chart_wrapper.appendChild(e)),setTimeout(function(){e.parentNode==t.chart_wrapper&&(t.chart_wrapper.removeChild(e),t.chart_wrapper.appendChild(t.svg))},650)}}},{key:"calTranslateByAngle",value:function(t){var e=this.radius,a=this.hoverRadio,s=i.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+s.x*a+"px,"+s.y*a+"px,0)"}},{key:"hoverSlice",value:function(e,i,a,s){if(e){var n=this.colors[i];if(a){v(e,this.calTranslateByAngle(this.slicesProperties[i])),e.style.fill=N(n,50);var r=t.offset(this.svg),o=s.pageX-r.left+10,l=s.pageY-r.top-10,h=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[i]:this.labels[i])+": ",u=(100*this.slice_totals[i]/this.grand_total).toFixed(1);this.tip.set_values(o,l,h,u+"%"),this.tip.show_tip()}else v(e,"translate3d(0,0,0)"),this.tip.hide_tip(),e.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,s=0;s<this.slices.length;s++)if(e===this.slices[s]){this.hoverSlice(a,i,!1),this.curActiveSlice=e,this.curActiveSliceIndex=s,this.hoverSlice(e,s,!0,t);break}}},{key:"mouseLeave",value:function(){this.hoverSlice(this.curActiveSlice,this.curActiveSliceIndex,!1)}},{key:"bind_tooltip",value:function(){this.draw_area.addEventListener("mousemove",this.mouseMove),this.draw_area.addEventListener("mouseleave",this.mouseLeave)}},{key:"show_summary",value:function(){var e=this,i=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,s){var n=e.colors[s];a&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='<span class="indicator">\n\t\t\t\t\t<i style="background-color:'+n+';"></i>\n\t\t\t\t\t<span class="text-muted">'+i[s]+":</span>\n\t\t\t\t\t"+a+"\n\t\t\t\t</span>")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*rt)*e,y:Math.cos(t*rt)*e}}}]),i}(tt),lt=function(t){function e(t){var i=t.start,a=void 0===i?"":i,s=t.domain,n=void 0===s?"":s,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,u=t.discrete_domains,c=void 0===u?0:u,_=t.count_label,p=void 0===_?"":_,d=t.legend_colors,f=void 0===d?[]:d;H(this,e);var v=B(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=n,v.subdomain=o,v.data=h,v.discrete_domains=c,v.count_label=p;var m=new Date;return v.start=a||j(m,365),f=f.slice(0,5),v.legend_colors=v.validate_colors(f)?f:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],v.distribution_size=5,v.translate_x=0,v.setup(),v}return F(e,t),W(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){P(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"setup_base_values",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&j(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&j(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=S(this.first_week_start+"",this.last_week_start+"")+1}},{key:"set_width",value:function(){this.base_width=12*(this.no_of_cols+3),this.discrete_domains&&(this.base_width+=144)}},{key:"setup_components",value:function(){this.domain_label_group=this.makeDrawAreaComponent("domain-label-group chart-label"),this.data_groups=this.makeDrawAreaComponent("data-groups","translate(0, 20)")}},{key:"setup_values",value:function(){var t=this;this.domain_label_group.textContent="",this.data_groups.textContent="";var e=Object.keys(this.data).map(function(e){return t.data[e]});this.distribution=w(e,this.distribution_size),this.month_names=["January","February","March","April","May","June","July","August","September","October","November","December"],this.render_all_weeks_and_store_x_values(this.no_of_cols)}},{key:"render_all_weeks_and_store_x_values",value:function(t){var e=new Date(this.first_week_start);this.week_col=0,this.current_month=e.getMonth(),this.months=[this.current_month+""],this.month_weeks={},this.month_start_points=[],this.month_weeks[this.current_month]=0,this.month_start_points.push(13);for(var i=0;i<t;i++){var a=void 0,s=0,n=new Date(e),r=this.get_week_squares_group(n,this.week_col),o=q(r,2);a=o[0],s=o[1],this.data_groups.appendChild(a),this.week_col+=1+parseInt(this.discrete_domains&&s),this.month_weeks[this.current_month]++,s&&(this.current_month=(this.current_month+1)%12,this.months.push(this.current_month+""),this.month_weeks[this.current_month]=1),j(e,7)}this.render_month_labels()}},{key:"get_week_squares_group",value:function(t,e){for(var i=this.today.getTime(),a=0,s=0,n=l(this.data_groups,"data-group"),r=0,o=0;o<7;o+=1,r+=12){var h=0,u=0,_=t.getTime()/1e3,p=Math.floor(_-_%86400).toFixed(1);this.data[p]&&(h=this.data[p]),this.data[Math.round(p)]&&(h=this.data[Math.round(p)]),h&&(u=b(h,this.distribution));var d=13+12*(e+s),f={"data-date":T(t),"data-value":h,"data-day":t.getDay()},v=c("day",d,r,10,this.legend_colors[u],f);n.appendChild(v);var m=new Date(t);if(j(m,1),m.getTime()>i)break;m.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(s=1),this.month_start_points.push(13+12*(e+s))),t=m}return[n,a]}},{key:"render_month_labels",value:function(){var t=this;this.months.shift(),this.month_start_points.shift(),this.months.pop(),this.month_start_points.pop(),this.month_start_points.map(function(e,i){var a=_("y-value-text",e+12,10,t.month_names[t.months[i]].substring(0,3));t.domain_label_group.appendChild(a)})}},{key:"make_graph_components",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chart_wrapper.style.marginTop="0px",this.chart_wrapper.style.paddingTop="0px"}},{key:"bind_tooltip",value:function(){var t=this;Array.prototype.slice.call(document.querySelectorAll(".data-group .day")).map(function(e){e.addEventListener("mouseenter",function(e){var i=e.target.getAttribute("data-value"),a=e.target.getAttribute("data-date").split("-"),s=t.month_names[parseInt(a[1])-1].substring(0,3),n=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-n.left+(o+2)/2,h=r.top-n.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+s+" "+a[0]+", "+a[2];t.tip.set_values(l,h,c,u,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bind_tooltip()}}]),e}(tt),ht={line:at,bar:it,scatter:st,percentage:nt,heatmap:lt,pie:ot},ut=function t(e){return H(this,t),E(e.type,arguments[0])};return ut}();
|