From a61f336d7147a936ad2c6904119070495944f9c3 Mon Sep 17 00:00:00 2001 From: pratu16x7 Date: Sat, 25 Nov 2017 23:39:26 +0530 Subject: [PATCH] move animate constants entirely to animate.js --- dist/frappe-charts.esm.js | 229 +++++++++++++--------------- dist/frappe-charts.min.cjs.js | 2 +- dist/frappe-charts.min.esm.js | 2 +- dist/frappe-charts.min.iife.js | 2 +- docs/assets/js/frappe-charts.min.js | 2 +- src/js/charts/AxisChart.js | 142 ++++++----------- src/js/charts/PieChart.js | 25 +-- src/js/utils/animate.js | 43 +++++- src/js/utils/animation.js | 27 +++- 9 files changed, 219 insertions(+), 255 deletions(-) diff --git a/dist/frappe-charts.esm.js b/dist/frappe-charts.esm.js index 38403af..8350f9a 100644 --- a/dist/frappe-charts.esm.js +++ b/dist/frappe-charts.esm.js @@ -450,6 +450,13 @@ var UnitRenderer = (function() { return UnitRenderer; })(); +const UNIT_ANIM_DUR = 350; +const PATH_ANIM_DUR = 350; +const MARKER_LINE_ANIM_DUR = 350; +const REPLACE_ALL_NEW_DUR = 250; + +const STD_EASING = 'easein'; + var Animator = (function() { var Animator = function(totalHeight, totalWidth, zeroLine, avgUnitWidth) { // constants @@ -469,18 +476,18 @@ var Animator = (function() { x = start + (width * index); - return [barObj, {width: width, height: height, x: x, y: y}, 350, "easein"]; - // bar.animate({height: args.newHeight, y: yTop}, 350, mina.easein); + return [barObj, {width: width, height: height, x: x, y: y}, UNIT_ANIM_DUR, STD_EASING]; + // bar.animate({height: args.newHeight, y: yTop}, UNIT_ANIM_DUR, mina.easein); }, dot: function(dotObj, x, yTop) { - return [dotObj, {cx: x, cy: yTop}, 350, "easein"]; - // dot.animate({cy: yTop}, 350, mina.easein); + return [dotObj, {cx: x, cy: yTop}, UNIT_ANIM_DUR, STD_EASING]; + // dot.animate({cy: yTop}, UNIT_ANIM_DUR, mina.easein); }, path: function(d, pathStr) { let pathComponents = []; - const animPath = [{unit: d.path, object: d, key: 'path'}, {d:"M"+pathStr}, 350, "easein"]; + const animPath = [{unit: d.path, object: d, key: 'path'}, {d:"M"+pathStr}, PATH_ANIM_DUR, STD_EASING]; pathComponents.push(animPath); if(d.regionPath) { @@ -490,14 +497,36 @@ var Animator = (function() { const animRegion = [ {unit: d.regionPath, object: d, key: 'regionPath'}, {d:"M" + regStartPt + pathStr + regEndPt}, - 350, - "easein" + PATH_ANIM_DUR, + STD_EASING ]; pathComponents.push(animRegion); } return pathComponents; }, + + verticalLine: function(xLine, newX, oldX) { + return [ + {unit: xLine, array: [0], index: 0}, + {transform: `${ newX }, 0`}, + MARKER_LINE_ANIM_DUR, + STD_EASING, + "translate", + {transform: `${ oldX }, 0`} + ]; + }, + + horizontalLine: function(yLine, newY, oldY) { + return [ + {unit: yLine, array: [0], index: 0}, + {transform: `0, ${ newY }`}, + MARKER_LINE_ANIM_DUR, + STD_EASING, + "translate", + {transform: `0, ${ oldY }`} + ]; + } }; return Animator; @@ -514,7 +543,7 @@ const EASING = { easeinout: "0.42 0 0.58 1" }; -function animateSVG(element, props, dur, easingType="linear", type=undefined, oldValues={}) { +function animateSVGElement(element, props, dur, easingType="linear", type=undefined, oldValues={}) { let animElement = element.cloneNode(true); let newElement = element.cloneNode(true); @@ -570,7 +599,7 @@ function transform(element, style) { // eslint-disable-line no-unused-vars element.style.oTransform = style; } -function runSVGAnimation(svgContainer, elements) { +function animateSVG(svgContainer, elements) { let newElements = []; let animElements = []; @@ -581,7 +610,7 @@ function runSVGAnimation(svgContainer, elements) { let animElement, newElement; element[0] = obj.unit; - [animElement, newElement] = animateSVG(...element); + [animElement, newElement] = animateSVGElement(...element); newElements.push(newElement); animElements.push([animElement, parent]); @@ -605,6 +634,25 @@ function runSVGAnimation(svgContainer, elements) { return animSvg; } +function runSMILAnimation(parent, svgElement, elementsToAnimate) { + if(elementsToAnimate.length === 0) return; + + let animSvgElement = animateSVG(svgElement, elementsToAnimate); + if(svgElement.parentNode == parent) { + parent.removeChild(svgElement); + parent.appendChild(animSvgElement); + + } + + // Replace the new svgElement (data has already been replaced) + setTimeout(() => { + if(animSvgElement.parentNode == parent) { + parent.removeChild(animSvgElement); + parent.appendChild(svgElement); + } + }, REPLACE_ALL_NEW_DUR); +} + function normalize(x) { // Calculates mantissa and exponent of a number // Returns normalized number and exponent @@ -1366,7 +1414,8 @@ class AxisChart extends BaseChart { } makeXLines(positions, values) { - let [start_at, height, text_start_at, axis_line_class] = getXLineProps(this.height, this.x_axis_mode); + let [start_at, height, text_start_at, + axis_line_class] = getXLineProps(this.height, this.x_axis_mode); this.x_axis_group.setAttribute('transform', `translate(0,${start_at})`); let char_width = 8; @@ -1406,8 +1455,8 @@ class AxisChart extends BaseChart { } makeYLines(positions, values) { - let [width, text_end_at, axis_line_class, start_at] = getYLineProps( - this.width, this.y_axis_mode); + let [width, text_end_at, axis_line_class, + start_at] = getYLineProps(this.width, this.y_axis_mode); this.yAxisLines = []; this.y_axis_group.textContent = ''; @@ -1427,25 +1476,6 @@ class AxisChart extends BaseChart { }); } - // make_y_specifics(positions, value_objs) { - // this.specific_y_group.textContent = ''; - // value_objs.map((d, i) => { - // this.specific_y_group.appendChild( - // makeYLine( - // 0, - // this.width, - // this.width + 5, - // d.title.toUpperCase(), - // 'specific-value', - // 'specific-value', - // positions[i], - // false, - // d.line_type - // ) - // ); - // }); - // } - draw_graph(init=false) { if(this.raw_chart_args.hasOwnProperty("init") && !this.raw_chart_args.init) { this.y.map((d, i) => { @@ -1589,7 +1619,6 @@ class AxisChart extends BaseChart { if(!new_x) { new_x = this.x; } - this.elements_to_animate = []; this.updating = true; this.old_x_values = this.x.slice(); @@ -1612,72 +1641,55 @@ class AxisChart extends BaseChart { this.animate_graphs(); - // Trigger animation with the animatable elements in this.elements_to_animate - this.run_animation(); - this.updating = false; } - run_animation() { - let anim_svg = runSVGAnimation(this.svg, this.elements_to_animate); - - if(this.svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(this.svg); - this.chart_wrapper.appendChild(anim_svg); - - } - - // Replace the new svg (data has long been replaced) - setTimeout(() => { - if(anim_svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(anim_svg); - this.chart_wrapper.appendChild(this.svg); - } - }, 250); - } - animate_graphs() { + this.elements_to_animate = []; + // Pre-prep, equilize no of positions between old and new + let [old_x, new_x] = equilizeNoOfElements( + this.x_old_axis_positions.slice(), + this.x_axis_positions.slice() + ); + + let [oldYAxis, newYAxis] = equilizeNoOfElements( + this.oldYAxisPositions.slice(), + this.yAxisPositions.slice() + ); + + let newXValues = this.x.slice(); + let newYValues = this.y_axis_values.slice(); + + let extra_points = this.x_axis_positions.slice().length - this.x_old_axis_positions.slice().length; + + if(extra_points > 0) { + this.makeXLines(old_x, newXValues); + } + // No Y extra check? + this.makeYLines(oldYAxis, newYValues); + + // Animation + if(extra_points !== 0) { + this.animateXLines(old_x, new_x); + } + this.animateYLines(oldYAxis, newYAxis); + this.y.map(d => { - // Pre-prep, equilize no of positions between old and new - let [old_x, new_x] = equilizeNoOfElements( - this.x_old_axis_positions.slice(), - this.x_axis_positions.slice() - ); let [old_y, new_y] = equilizeNoOfElements( this.old_y_axis_tops[d.index].slice(), d.y_tops.slice() ); - - let [oldYAxis, newYAxis] = equilizeNoOfElements( - this.oldYAxisPositions.slice(), - this.yAxisPositions.slice() - ); - - let newXValues = this.x.slice(); - let newYValues = this.y_axis_values.slice(); - - let extra_points = this.x_axis_positions.slice().length - this.x_old_axis_positions.slice().length; - if(extra_points > 0) { this.make_path && this.make_path(d, old_x, old_y, this.colors[d.index]); this.make_new_units_for_dataset(old_x, old_y, this.colors[d.index], d.index, this.y.length); - this.makeXLines(old_x, newXValues); - } - // No Y extra check? - this.makeYLines(oldYAxis, newYValues); - - if(!this.updating) { - // Animation - if(extra_points !== 0) { - this.animateXLines(old_x, new_x); - } - - d.path && this.animate_path(d, new_x, new_y); - this.animate_units(d, new_x, new_y); - this.animateYLines(oldYAxis, newYAxis); } + // Animation + d.path && this.animate_path(d, new_x, new_y); + this.animate_units(d, new_x, new_y); }); + runSMILAnimation(this.chart_wrapper, this.svg, this.elements_to_animate); + setTimeout(() => { this.y.map(d => { this.make_path && this.make_path(d, this.x_axis_positions, d.y_tops, this.colors[d.index]); @@ -1693,7 +1705,7 @@ class AxisChart extends BaseChart { animate_path(d, new_x, new_y) { const newPointsList = new_y.map((y, i) => (new_x[i] + ',' + y)); this.elements_to_animate = this.elements_to_animate - .concat(this.animator['path'](d, newPointsList.join("L"))); + .concat(this.animator.path(d, newPointsList.join("L"))); } animate_units(d, new_x, new_y) { @@ -1713,32 +1725,22 @@ class AxisChart extends BaseChart { animateXLines(oldX, newX) { this.xAxisLines.map((xLine, i) => { - this.elements_to_animate.push([ - {unit: xLine, array: [0], index: 0}, - {transform: `${ newX[i] }, 0`}, - 350, - "easein", - "translate", - {transform: `${ oldX[i] }, 0`} - ]); + this.elements_to_animate.push(this.animator.verticalLine( + xLine, newX[i], oldX[i] + )); }); } animateYLines(oldY, newY) { this.yAxisLines.map((yLine, i) => { - this.elements_to_animate.push([ - {unit: yLine, array: [0], index: 0}, - {transform: `0, ${ newY[i] }`}, - 350, - "easein", - "translate", - {transform: `0, ${ oldY[i] }`} - ]); + this.elements_to_animate.push(this.animator.horizontalLine( + yLine, newY[i], oldY[i] + )); }); } animateYAnnotations() { - + // } add_data_point(y_point, x_point, index=this.x.length) { @@ -2261,30 +2263,9 @@ class PieChart extends BaseChart { }); if(init){ - this.run_animation(); + runSMILAnimation(this.chart_wrapper, this.svg, this.elements_to_animate); } } - run_animation() { - // if(this.isAnimate) return ; - // this.isAnimate = true; - if(!this.elements_to_animate || this.elements_to_animate.length === 0) return; - let anim_svg = runSVGAnimation(this.svg, this.elements_to_animate); - - if(this.svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(this.svg); - this.chart_wrapper.appendChild(anim_svg); - - } - - // Replace the new svg (data has long been replaced) - setTimeout(() => { - // this.isAnimate = false; - if(anim_svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(anim_svg); - this.chart_wrapper.appendChild(this.svg); - } - }, 650); - } calTranslateByAngle(property){ const{radius,hoverRadio} = this; diff --git a/dist/frappe-charts.min.cjs.js b/dist/frappe-charts.min.cjs.js index 7912b2c..42cdf9c 100644 --- a/dist/frappe-charts.min.cjs.js +++ b/dist/frappe-charts.min.cjs.js @@ -1 +1 @@ -"use strict";function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function offset(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function isElementInViewport(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)}function getElementContentWidth(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=.01*i)):(n=e,0===(a=t-e)&&(a=.01*i)),[a,n]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function getXLineProps(t,e){var i=void 0,a=void 0,n=void 0,s="";return"span"===e?(i=-7,a=t+15,n=t+25):"tick"===e&&(i=t,a=6,n=9,s="x-axis-label"),[i,a,n,s]}function getYLineProps(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,a="",n=0;return"span"===e?(i=t+6,n=-6):"tick"===e&&(i=-6,a="y-axis-label"),[i,-9,a,n]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),createSVG("rect",r)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:".32em",innerHTML:a})}function makeXLine(t,e,i,a,n,s){var r=createSVG("line",{x1:0,x2:0,y1:0,y2:t}),o=createSVG("text",{className:a,x:0,y:e,dy:".71em",innerHTML:i}),l=createSVG("g",{className:"tick "+n,transform:"translate("+s+", 0)"});return l.appendChild(r),l.appendChild(o),l}function makeYLine(t,e,i,a,n,s,r){var o=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=createSVG("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=createSVG("text",{className:n,x:i,y:0,dy:".32em",innerHTML:a+""}),u=createSVG("g",{className:"tick "+s,transform:"translate(0, "+r+")","stroke-opacity":1});return o&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function animateSVG(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:EASING[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var _ in p)h.setAttribute(_,p[_]);r.appendChild(h),n?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function runSVGAnimation(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=animateSVG.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function normalize(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 getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function treatAsUtc(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function getDdMmYyyy(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 _typeof="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},asyncGenerator=function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"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)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
    \n\t\t\t\t
    '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.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]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,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"}}]),t}(),PRESET_COLOR_MAP={"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"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={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:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){var i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=e.colors,h=void 0===l?[]:l,u=e.summary,c=void 0===u?[]:u,p=e.is_navigable,_=void 0===p?0:p,d=e.has_legend,f=void 0===d?0:d,v=e.type,m=void 0===v?"":v,g=e.parent,y=e.data;classCallCheck(this,t),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=o,this.data=y,this.oldData=Object.assign({},y),this.specific_values=y.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,m),this.set_margins(a)}return createClass(t,[{key:"get_different_chart",value:function(t){if(t!==this.type){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=COLOR_COMPATIBLE_CHARTS[this.type].includes(t);return new Chart({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.length0&&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=getStringWidth(e.title+"",8);i>t&&(t=i-40)}),this.base_width=getElementContentWidth(this.parent)-t,this.width=this.base_width-2*this.translate_x}},{key:"setup_base_values",value:function(){}},{key:"setup_container",value:function(){this.container=$$1.create("div",{className:"chart-container",innerHTML:'
    '+this.title+'
    \n\t\t\t\t
    '+this.subtitle+'
    \n\t\t\t\t
    \n\t\t\t\t
    '}),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=makeSVGContainer(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=makeSVGDefs(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new SvgTip({parent:this.chart_wrapper,colors:this.colors}),this.bind_tooltip()}},{key:"show_summary",value:function(){}},{key:"show_custom_summary",value:function(){var t=this;this.summary.map(function(e){var i=$$1.create("div",{className:"stats",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+e.title+": "+e.value+"\n\t\t\t\t"});t.stats_wrapper.appendChild(i)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return makeSVGGroup(this.draw_area,t,e)}}]),t}(),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.x=i.data.labels||[],i.y=i.data.datasets||[],i.is_series=t.is_series,i.format_tooltip_y=t.format_tooltip_y,i.format_tooltip_x=t.format_tooltip_x,i.zero_line=i.height,i}return inherits(e,t),createClass(e,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 floatTwo(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=calcIntervals(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,a=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/a,this.old_multiplier||(this.old_multiplier=this.multiplier);var n=i[1]-i[0],s=n*this.multiplier,r=void 0;r=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/n:-1*i[i.length-1]/n+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-r*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,a=getXLineProps(this.height,this.x_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var h=1.5*this.avg_unit_width,u=h/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,a){var n=getStringWidth(e,8)+2;if(n>h)if(i.is_series){for(var s=1;n/s*2>h;)s++;if(a%s!=0)return}else e=e.slice(0,u-3)+" ...";var c=makeXLine(r,o,e,"x-value-text",l,t[a]);i.xAxisLines.push(c),i.x_axis_group.appendChild(c)})}},{key:"makeYLines",value:function(t,e){var i=this,a=getYLineProps(this.width,this.y_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,a){var n=makeYLine(l,s,r,e,"y-value-text",o,t[a],0===e&&0!==a);i.yAxisLines.push(n),i.y_axis_group.appendChild(n)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{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,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var i=this;t?setTimeout(function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",i).call(i,t)},500):get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,n,s,r,o){s||(s=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),s.textContent="",r.length=0;var l=new UnitRenderer(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,n);s.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(e){var i=offset(t.chart_wrapper),a=e.pageX-i.left-t.translate_x;e.pageY-i.top-t.translate_y=0;n--){var s=this.x_axis_positions[n];if(t>s-this.avg_unit_width/2){var r=s+this.translate_x,o=this.y_min_tops[n]+this.translate_y,l=i[n],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[n]):t.values[n],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new Animator(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.run_animation(),this.updating=!1}},{key:"run_animation",value:function(){var t=this,e=runSVGAnimation(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){var i=equilizeNoOfElements(t.x_old_axis_positions.slice(),t.x_axis_positions.slice()),a=slicedToArray(i,2),n=a[0],s=a[1],r=equilizeNoOfElements(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),o=slicedToArray(r,2),l=o[0],h=o[1],u=equilizeNoOfElements(t.oldYAxisPositions.slice(),t.yAxisPositions.slice()),c=slicedToArray(u,2),p=c[0],_=c[1],d=t.x.slice(),f=t.y_axis_values.slice(),v=t.x_axis_positions.slice().length-t.x_old_axis_positions.slice().length;v>0&&(t.make_path&&t.make_path(e,n,l,t.colors[e.index]),t.make_new_units_for_dataset(n,l,t.colors[e.index],e.index,t.y.length),t.makeXLines(n,d)),t.makeYLines(p,f),t.updating||(0!==v&&t.animateXLines(n,s),e.path&&t.animate_path(e,s,h),t.animate_units(e,s,h),t.animateYLines(p,_))}),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var a=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,a.join("L")))}},{key:"animate_units",value:function(t,e,i){var a=this,n=this.unit_args.type;t.svg_units.map(function(s,r){void 0!==e[r]&&void 0!==i[r]&&a.elements_to_animate.push(a.animator[n]({unit:s,array:t.svg_units,index:r},e[r],i[r],t.index,a.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:e[n]+", 0"},350,"easein","translate",{transform:t[n]+", 0"}])})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:"0, "+e[n]},350,"easein","translate",{transform:"0, "+t[n]}])})}},{key:"animateYAnnotations",value:function(){}},{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 n=this.x.slice();n.splice(i,0,e),this.updateData(a,n)}},{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.updateData(e,i)}}},{key:"getDataPoint",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 n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return floatTwo(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentage_bar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var a=offset(t.chart_wrapper),n=offset(e),s=n.left-a.left+e.offsetWidth/2,r=n.top-a.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[i]:t.labels[i])+": ",l=(100*t.slice_totals[i]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"show_summary",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{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,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,u=o/i.grand_total*FULL_ANGLE,c=n?-u:u,p=r+=c,_=e.getPositionByAngle(h,a),d=e.getPositionByAngle(p,a),f=t&&s[l],v=void 0,m=void 0;t?(v=f?f.startPosition:_,m=f?f.endPosition:_):(v=_,m=d);var g=i.makeArcPath(v,m),y=makePath(g,"pie-path","none",i.colors[l]);y.style.transition="transform .3s;",i.draw_area.appendChild(y),i.slices.push(y),i.slicesProperties.push({startPosition:_,endPosition:d,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:c}),t&&i.elements_to_animate.push([{unit:y,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(_,d)},650,"easein",null,{d:g}])}),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=runSVGAnimation(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 i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=offset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,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,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,f=void 0===d?[]:d;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=o,v.data=h,v.discrete_domains=c,v.count_label=_;var m=new Date;return v.start=a||addDays(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 inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(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()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(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=calcDistribution(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;ii)break;f.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=f}return[s,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=makeText("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("-"),n=t.month_names[parseInt(a[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-s.left+(o+2)/2,h=r.top-s.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+n+" "+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}(BaseChart),chartTypes={line:LineChart,bar:BarChart,scatter:ScatterChart,percentage:PercentageChart,heatmap:Heatmap,pie:PieChart},Chart=function t(e){return classCallCheck(this,t),getChartByType(e.type,arguments[0])};module.exports=Chart; +"use strict";function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function offset(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function isElementInViewport(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)}function getElementContentWidth(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=.01*i)):(n=e,0===(a=t-e)&&(a=.01*i)),[a,n]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function getXLineProps(t,e){var i=void 0,a=void 0,n=void 0,s="";return"span"===e?(i=-7,a=t+15,n=t+25):"tick"===e&&(i=t,a=6,n=9,s="x-axis-label"),[i,a,n,s]}function getYLineProps(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,a="",n=0;return"span"===e?(i=t+6,n=-6):"tick"===e&&(i=-6,a="y-axis-label"),[i,-9,a,n]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),createSVG("rect",r)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:".32em",innerHTML:a})}function makeXLine(t,e,i,a,n,s){var r=createSVG("line",{x1:0,x2:0,y1:0,y2:t}),o=createSVG("text",{className:a,x:0,y:e,dy:".71em",innerHTML:i}),l=createSVG("g",{className:"tick "+n,transform:"translate("+s+", 0)"});return l.appendChild(r),l.appendChild(o),l}function makeYLine(t,e,i,a,n,s,r){var o=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=createSVG("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=createSVG("text",{className:n,x:i,y:0,dy:".32em",innerHTML:a+""}),u=createSVG("g",{className:"tick "+s,transform:"translate(0, "+r+")","stroke-opacity":1});return o&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function animateSVGElement(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:EASING[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var _ in p)h.setAttribute(_,p[_]);r.appendChild(h),n?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function animateSVG(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function normalize(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 getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function treatAsUtc(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function getDdMmYyyy(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 _typeof="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},asyncGenerator=function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"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)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
      \n\t\t\t\t
      '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.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]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,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"}}]),t}(),PRESET_COLOR_MAP={"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"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={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:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){var i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=e.colors,h=void 0===l?[]:l,u=e.summary,c=void 0===u?[]:u,p=e.is_navigable,_=void 0===p?0:p,d=e.has_legend,f=void 0===d?0:d,v=e.type,m=void 0===v?"":v,g=e.parent,y=e.data;classCallCheck(this,t),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=o,this.data=y,this.oldData=Object.assign({},y),this.specific_values=y.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,m),this.set_margins(a)}return createClass(t,[{key:"get_different_chart",value:function(t){if(t!==this.type){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=COLOR_COMPATIBLE_CHARTS[this.type].includes(t);return new Chart({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.length0&&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=getStringWidth(e.title+"",8);i>t&&(t=i-40)}),this.base_width=getElementContentWidth(this.parent)-t,this.width=this.base_width-2*this.translate_x}},{key:"setup_base_values",value:function(){}},{key:"setup_container",value:function(){this.container=$$1.create("div",{className:"chart-container",innerHTML:'
      '+this.title+'
      \n\t\t\t\t
      '+this.subtitle+'
      \n\t\t\t\t
      \n\t\t\t\t
      '}),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=makeSVGContainer(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=makeSVGDefs(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new SvgTip({parent:this.chart_wrapper,colors:this.colors}),this.bind_tooltip()}},{key:"show_summary",value:function(){}},{key:"show_custom_summary",value:function(){var t=this;this.summary.map(function(e){var i=$$1.create("div",{className:"stats",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+e.title+": "+e.value+"\n\t\t\t\t"});t.stats_wrapper.appendChild(i)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return makeSVGGroup(this.draw_area,t,e)}}]),t}(),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.x=i.data.labels||[],i.y=i.data.datasets||[],i.is_series=t.is_series,i.format_tooltip_y=t.format_tooltip_y,i.format_tooltip_x=t.format_tooltip_x,i.zero_line=i.height,i}return inherits(e,t),createClass(e,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 floatTwo(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=calcIntervals(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,a=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/a,this.old_multiplier||(this.old_multiplier=this.multiplier);var n=i[1]-i[0],s=n*this.multiplier,r=void 0;r=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/n:-1*i[i.length-1]/n+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-r*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,a=getXLineProps(this.height,this.x_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var h=1.5*this.avg_unit_width,u=h/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,a){var n=getStringWidth(e,8)+2;if(n>h)if(i.is_series){for(var s=1;n/s*2>h;)s++;if(a%s!=0)return}else e=e.slice(0,u-3)+" ...";var c=makeXLine(r,o,e,"x-value-text",l,t[a]);i.xAxisLines.push(c),i.x_axis_group.appendChild(c)})}},{key:"makeYLines",value:function(t,e){var i=this,a=getYLineProps(this.width,this.y_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,a){var n=makeYLine(l,s,r,e,"y-value-text",o,t[a],0===e&&0!==a);i.yAxisLines.push(n),i.y_axis_group.appendChild(n)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{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,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var i=this;t?setTimeout(function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",i).call(i,t)},500):get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,n,s,r,o){s||(s=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),s.textContent="",r.length=0;var l=new UnitRenderer(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,n);s.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(e){var i=offset(t.chart_wrapper),a=e.pageX-i.left-t.translate_x;e.pageY-i.top-t.translate_y=0;n--){var s=this.x_axis_positions[n];if(t>s-this.avg_unit_width/2){var r=s+this.translate_x,o=this.y_min_tops[n]+this.translate_y,l=i[n],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[n]):t.values[n],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){e||(e=this.x),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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new Animator(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.updating=!1}},{key:"animate_graphs",value:function(){var t=this;this.elements_to_animate=[];var e=equilizeNoOfElements(this.x_old_axis_positions.slice(),this.x_axis_positions.slice()),i=slicedToArray(e,2),a=i[0],n=i[1],s=equilizeNoOfElements(this.oldYAxisPositions.slice(),this.yAxisPositions.slice()),r=slicedToArray(s,2),o=r[0],l=r[1],h=this.x.slice(),u=this.y_axis_values.slice(),c=this.x_axis_positions.slice().length-this.x_old_axis_positions.slice().length;c>0&&this.makeXLines(a,h),this.makeYLines(o,u),0!==c&&this.animateXLines(a,n),this.animateYLines(o,l),this.y.map(function(e){var i=equilizeNoOfElements(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),s=slicedToArray(i,2),r=s[0],o=s[1];c>0&&(t.make_path&&t.make_path(e,a,r,t.colors[e.index]),t.make_new_units_for_dataset(a,r,t.colors[e.index],e.index,t.y.length)),e.path&&t.animate_path(e,n,o),t.animate_units(e,n,o)}),runSMILAnimation(this.chart_wrapper,this.svg,this.elements_to_animate),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var a=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,a.join("L")))}},{key:"animate_units",value:function(t,e,i){var a=this,n=this.unit_args.type;t.svg_units.map(function(s,r){void 0!==e[r]&&void 0!==i[r]&&a.elements_to_animate.push(a.animator[n]({unit:s,array:t.svg_units,index:r},e[r],i[r],t.index,a.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(a,n){i.elements_to_animate.push(i.animator.verticalLine(a,e[n],t[n]))})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(a,n){i.elements_to_animate.push(i.animator.horizontalLine(a,e[n],t[n]))})}},{key:"animateYAnnotations",value:function(){}},{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 n=this.x.slice();n.splice(i,0,e),this.updateData(a,n)}},{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.updateData(e,i)}}},{key:"getDataPoint",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 n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return floatTwo(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentage_bar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var a=offset(t.chart_wrapper),n=offset(e),s=n.left-a.left+e.offsetWidth/2,r=n.top-a.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[i]:t.labels[i])+": ",l=(100*t.slice_totals[i]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"show_summary",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{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,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,u=o/i.grand_total*FULL_ANGLE,c=n?-u:u,p=r+=c,_=e.getPositionByAngle(h,a),d=e.getPositionByAngle(p,a),f=t&&s[l],v=void 0,m=void 0;t?(v=f?f.startPosition:_,m=f?f.endPosition:_):(v=_,m=d);var g=i.makeArcPath(v,m),y=makePath(g,"pie-path","none",i.colors[l]);y.style.transition="transform .3s;",i.draw_area.appendChild(y),i.slices.push(y),i.slicesProperties.push({startPosition:_,endPosition:d,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:c}),t&&i.elements_to_animate.push([{unit:y,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(_,d)},650,"easein",null,{d:g}])}),t&&runSMILAnimation(this.chart_wrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=offset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,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,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,f=void 0===d?[]:d;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=o,v.data=h,v.discrete_domains=c,v.count_label=_;var m=new Date;return v.start=a||addDays(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 inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(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()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(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=calcDistribution(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;ii)break;f.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=f}return[s,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=makeText("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("-"),n=t.month_names[parseInt(a[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-s.left+(o+2)/2,h=r.top-s.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+n+" "+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}(BaseChart),chartTypes={line:LineChart,bar:BarChart,scatter:ScatterChart,percentage:PercentageChart,heatmap:Heatmap,pie:PieChart},Chart=function t(e){return classCallCheck(this,t),getChartByType(e.type,arguments[0])};module.exports=Chart; diff --git a/dist/frappe-charts.min.esm.js b/dist/frappe-charts.min.esm.js index 9926dd7..50b809e 100644 --- a/dist/frappe-charts.min.esm.js +++ b/dist/frappe-charts.min.esm.js @@ -1 +1 @@ -function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function offset(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function isElementInViewport(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)}function getElementContentWidth(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=.01*i)):(n=e,0===(a=t-e)&&(a=.01*i)),[a,n]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function getXLineProps(t,e){var i=void 0,a=void 0,n=void 0,s="";return"span"===e?(i=-7,a=t+15,n=t+25):"tick"===e&&(i=t,a=6,n=9,s="x-axis-label"),[i,a,n,s]}function getYLineProps(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,a="",n=0;return"span"===e?(i=t+6,n=-6):"tick"===e&&(i=-6,a="y-axis-label"),[i,-9,a,n]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),createSVG("rect",r)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:".32em",innerHTML:a})}function makeXLine(t,e,i,a,n,s){var r=createSVG("line",{x1:0,x2:0,y1:0,y2:t}),o=createSVG("text",{className:a,x:0,y:e,dy:".71em",innerHTML:i}),l=createSVG("g",{className:"tick "+n,transform:"translate("+s+", 0)"});return l.appendChild(r),l.appendChild(o),l}function makeYLine(t,e,i,a,n,s,r){var o=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=createSVG("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=createSVG("text",{className:n,x:i,y:0,dy:".32em",innerHTML:a+""}),u=createSVG("g",{className:"tick "+s,transform:"translate(0, "+r+")","stroke-opacity":1});return o&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function animateSVG(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:EASING[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var _ in p)h.setAttribute(_,p[_]);r.appendChild(h),n?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function runSVGAnimation(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=animateSVG.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function normalize(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 getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function treatAsUtc(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function getDdMmYyyy(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 _typeof="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},asyncGenerator=function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"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)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
        \n\t\t\t\t
        '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.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]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,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"}}]),t}(),PRESET_COLOR_MAP={"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"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={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:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){var i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=e.colors,h=void 0===l?[]:l,u=e.summary,c=void 0===u?[]:u,p=e.is_navigable,_=void 0===p?0:p,d=e.has_legend,f=void 0===d?0:d,v=e.type,m=void 0===v?"":v,g=e.parent,y=e.data;classCallCheck(this,t),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=o,this.data=y,this.oldData=Object.assign({},y),this.specific_values=y.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,m),this.set_margins(a)}return createClass(t,[{key:"get_different_chart",value:function(t){if(t!==this.type){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=COLOR_COMPATIBLE_CHARTS[this.type].includes(t);return new Chart({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.length0&&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=getStringWidth(e.title+"",8);i>t&&(t=i-40)}),this.base_width=getElementContentWidth(this.parent)-t,this.width=this.base_width-2*this.translate_x}},{key:"setup_base_values",value:function(){}},{key:"setup_container",value:function(){this.container=$$1.create("div",{className:"chart-container",innerHTML:'
        '+this.title+'
        \n\t\t\t\t
        '+this.subtitle+'
        \n\t\t\t\t
        \n\t\t\t\t
        '}),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=makeSVGContainer(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=makeSVGDefs(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new SvgTip({parent:this.chart_wrapper,colors:this.colors}),this.bind_tooltip()}},{key:"show_summary",value:function(){}},{key:"show_custom_summary",value:function(){var t=this;this.summary.map(function(e){var i=$$1.create("div",{className:"stats",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+e.title+": "+e.value+"\n\t\t\t\t"});t.stats_wrapper.appendChild(i)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return makeSVGGroup(this.draw_area,t,e)}}]),t}(),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.x=i.data.labels||[],i.y=i.data.datasets||[],i.is_series=t.is_series,i.format_tooltip_y=t.format_tooltip_y,i.format_tooltip_x=t.format_tooltip_x,i.zero_line=i.height,i}return inherits(e,t),createClass(e,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 floatTwo(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=calcIntervals(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,a=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/a,this.old_multiplier||(this.old_multiplier=this.multiplier);var n=i[1]-i[0],s=n*this.multiplier,r=void 0;r=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/n:-1*i[i.length-1]/n+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-r*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,a=getXLineProps(this.height,this.x_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var h=1.5*this.avg_unit_width,u=h/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,a){var n=getStringWidth(e,8)+2;if(n>h)if(i.is_series){for(var s=1;n/s*2>h;)s++;if(a%s!=0)return}else e=e.slice(0,u-3)+" ...";var c=makeXLine(r,o,e,"x-value-text",l,t[a]);i.xAxisLines.push(c),i.x_axis_group.appendChild(c)})}},{key:"makeYLines",value:function(t,e){var i=this,a=getYLineProps(this.width,this.y_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,a){var n=makeYLine(l,s,r,e,"y-value-text",o,t[a],0===e&&0!==a);i.yAxisLines.push(n),i.y_axis_group.appendChild(n)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{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,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var i=this;t?setTimeout(function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",i).call(i,t)},500):get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,n,s,r,o){s||(s=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),s.textContent="",r.length=0;var l=new UnitRenderer(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,n);s.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(e){var i=offset(t.chart_wrapper),a=e.pageX-i.left-t.translate_x;e.pageY-i.top-t.translate_y=0;n--){var s=this.x_axis_positions[n];if(t>s-this.avg_unit_width/2){var r=s+this.translate_x,o=this.y_min_tops[n]+this.translate_y,l=i[n],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[n]):t.values[n],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new Animator(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.run_animation(),this.updating=!1}},{key:"run_animation",value:function(){var t=this,e=runSVGAnimation(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){var i=equilizeNoOfElements(t.x_old_axis_positions.slice(),t.x_axis_positions.slice()),a=slicedToArray(i,2),n=a[0],s=a[1],r=equilizeNoOfElements(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),o=slicedToArray(r,2),l=o[0],h=o[1],u=equilizeNoOfElements(t.oldYAxisPositions.slice(),t.yAxisPositions.slice()),c=slicedToArray(u,2),p=c[0],_=c[1],d=t.x.slice(),f=t.y_axis_values.slice(),v=t.x_axis_positions.slice().length-t.x_old_axis_positions.slice().length;v>0&&(t.make_path&&t.make_path(e,n,l,t.colors[e.index]),t.make_new_units_for_dataset(n,l,t.colors[e.index],e.index,t.y.length),t.makeXLines(n,d)),t.makeYLines(p,f),t.updating||(0!==v&&t.animateXLines(n,s),e.path&&t.animate_path(e,s,h),t.animate_units(e,s,h),t.animateYLines(p,_))}),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var a=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,a.join("L")))}},{key:"animate_units",value:function(t,e,i){var a=this,n=this.unit_args.type;t.svg_units.map(function(s,r){void 0!==e[r]&&void 0!==i[r]&&a.elements_to_animate.push(a.animator[n]({unit:s,array:t.svg_units,index:r},e[r],i[r],t.index,a.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:e[n]+", 0"},350,"easein","translate",{transform:t[n]+", 0"}])})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:"0, "+e[n]},350,"easein","translate",{transform:"0, "+t[n]}])})}},{key:"animateYAnnotations",value:function(){}},{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 n=this.x.slice();n.splice(i,0,e),this.updateData(a,n)}},{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.updateData(e,i)}}},{key:"getDataPoint",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 n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return floatTwo(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentage_bar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var a=offset(t.chart_wrapper),n=offset(e),s=n.left-a.left+e.offsetWidth/2,r=n.top-a.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[i]:t.labels[i])+": ",l=(100*t.slice_totals[i]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"show_summary",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{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,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,u=o/i.grand_total*FULL_ANGLE,c=n?-u:u,p=r+=c,_=e.getPositionByAngle(h,a),d=e.getPositionByAngle(p,a),f=t&&s[l],v=void 0,m=void 0;t?(v=f?f.startPosition:_,m=f?f.endPosition:_):(v=_,m=d);var g=i.makeArcPath(v,m),y=makePath(g,"pie-path","none",i.colors[l]);y.style.transition="transform .3s;",i.draw_area.appendChild(y),i.slices.push(y),i.slicesProperties.push({startPosition:_,endPosition:d,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:c}),t&&i.elements_to_animate.push([{unit:y,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(_,d)},650,"easein",null,{d:g}])}),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=runSVGAnimation(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 i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=offset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,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,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,f=void 0===d?[]:d;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=o,v.data=h,v.discrete_domains=c,v.count_label=_;var m=new Date;return v.start=a||addDays(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 inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(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()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(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=calcDistribution(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;ii)break;f.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=f}return[s,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=makeText("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("-"),n=t.month_names[parseInt(a[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-s.left+(o+2)/2,h=r.top-s.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+n+" "+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}(BaseChart),chartTypes={line:LineChart,bar:BarChart,scatter:ScatterChart,percentage:PercentageChart,heatmap:Heatmap,pie:PieChart},Chart=function t(e){return classCallCheck(this,t),getChartByType(e.type,arguments[0])};export default Chart; +function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function offset(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function isElementInViewport(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)}function getElementContentWidth(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=.01*i)):(n=e,0===(a=t-e)&&(a=.01*i)),[a,n]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function getXLineProps(t,e){var i=void 0,a=void 0,n=void 0,s="";return"span"===e?(i=-7,a=t+15,n=t+25):"tick"===e&&(i=t,a=6,n=9,s="x-axis-label"),[i,a,n,s]}function getYLineProps(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,a="",n=0;return"span"===e?(i=t+6,n=-6):"tick"===e&&(i=-6,a="y-axis-label"),[i,-9,a,n]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),createSVG("rect",r)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:".32em",innerHTML:a})}function makeXLine(t,e,i,a,n,s){var r=createSVG("line",{x1:0,x2:0,y1:0,y2:t}),o=createSVG("text",{className:a,x:0,y:e,dy:".71em",innerHTML:i}),l=createSVG("g",{className:"tick "+n,transform:"translate("+s+", 0)"});return l.appendChild(r),l.appendChild(o),l}function makeYLine(t,e,i,a,n,s,r){var o=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=createSVG("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=createSVG("text",{className:n,x:i,y:0,dy:".32em",innerHTML:a+""}),u=createSVG("g",{className:"tick "+s,transform:"translate(0, "+r+")","stroke-opacity":1});return o&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function animateSVGElement(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:EASING[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var _ in p)h.setAttribute(_,p[_]);r.appendChild(h),n?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function animateSVG(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function normalize(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 getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function treatAsUtc(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function getDdMmYyyy(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 _typeof="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},asyncGenerator=function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"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)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
          \n\t\t\t\t
          '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.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]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,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"}}]),t}(),PRESET_COLOR_MAP={"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"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={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:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){var i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=e.colors,h=void 0===l?[]:l,u=e.summary,c=void 0===u?[]:u,p=e.is_navigable,_=void 0===p?0:p,d=e.has_legend,f=void 0===d?0:d,v=e.type,m=void 0===v?"":v,g=e.parent,y=e.data;classCallCheck(this,t),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=o,this.data=y,this.oldData=Object.assign({},y),this.specific_values=y.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,m),this.set_margins(a)}return createClass(t,[{key:"get_different_chart",value:function(t){if(t!==this.type){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=COLOR_COMPATIBLE_CHARTS[this.type].includes(t);return new Chart({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.length0&&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=getStringWidth(e.title+"",8);i>t&&(t=i-40)}),this.base_width=getElementContentWidth(this.parent)-t,this.width=this.base_width-2*this.translate_x}},{key:"setup_base_values",value:function(){}},{key:"setup_container",value:function(){this.container=$$1.create("div",{className:"chart-container",innerHTML:'
          '+this.title+'
          \n\t\t\t\t
          '+this.subtitle+'
          \n\t\t\t\t
          \n\t\t\t\t
          '}),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=makeSVGContainer(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=makeSVGDefs(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new SvgTip({parent:this.chart_wrapper,colors:this.colors}),this.bind_tooltip()}},{key:"show_summary",value:function(){}},{key:"show_custom_summary",value:function(){var t=this;this.summary.map(function(e){var i=$$1.create("div",{className:"stats",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+e.title+": "+e.value+"\n\t\t\t\t"});t.stats_wrapper.appendChild(i)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return makeSVGGroup(this.draw_area,t,e)}}]),t}(),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.x=i.data.labels||[],i.y=i.data.datasets||[],i.is_series=t.is_series,i.format_tooltip_y=t.format_tooltip_y,i.format_tooltip_x=t.format_tooltip_x,i.zero_line=i.height,i}return inherits(e,t),createClass(e,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 floatTwo(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=calcIntervals(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,a=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/a,this.old_multiplier||(this.old_multiplier=this.multiplier);var n=i[1]-i[0],s=n*this.multiplier,r=void 0;r=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/n:-1*i[i.length-1]/n+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-r*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,a=getXLineProps(this.height,this.x_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var h=1.5*this.avg_unit_width,u=h/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,a){var n=getStringWidth(e,8)+2;if(n>h)if(i.is_series){for(var s=1;n/s*2>h;)s++;if(a%s!=0)return}else e=e.slice(0,u-3)+" ...";var c=makeXLine(r,o,e,"x-value-text",l,t[a]);i.xAxisLines.push(c),i.x_axis_group.appendChild(c)})}},{key:"makeYLines",value:function(t,e){var i=this,a=getYLineProps(this.width,this.y_axis_mode),n=slicedToArray(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,a){var n=makeYLine(l,s,r,e,"y-value-text",o,t[a],0===e&&0!==a);i.yAxisLines.push(n),i.y_axis_group.appendChild(n)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{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,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var i=this;t?setTimeout(function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",i).call(i,t)},500):get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,n,s,r,o){s||(s=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),s.textContent="",r.length=0;var l=new UnitRenderer(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,n);s.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(e){var i=offset(t.chart_wrapper),a=e.pageX-i.left-t.translate_x;e.pageY-i.top-t.translate_y=0;n--){var s=this.x_axis_positions[n];if(t>s-this.avg_unit_width/2){var r=s+this.translate_x,o=this.y_min_tops[n]+this.translate_y,l=i[n],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[n]):t.values[n],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){e||(e=this.x),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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new Animator(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.updating=!1}},{key:"animate_graphs",value:function(){var t=this;this.elements_to_animate=[];var e=equilizeNoOfElements(this.x_old_axis_positions.slice(),this.x_axis_positions.slice()),i=slicedToArray(e,2),a=i[0],n=i[1],s=equilizeNoOfElements(this.oldYAxisPositions.slice(),this.yAxisPositions.slice()),r=slicedToArray(s,2),o=r[0],l=r[1],h=this.x.slice(),u=this.y_axis_values.slice(),c=this.x_axis_positions.slice().length-this.x_old_axis_positions.slice().length;c>0&&this.makeXLines(a,h),this.makeYLines(o,u),0!==c&&this.animateXLines(a,n),this.animateYLines(o,l),this.y.map(function(e){var i=equilizeNoOfElements(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),s=slicedToArray(i,2),r=s[0],o=s[1];c>0&&(t.make_path&&t.make_path(e,a,r,t.colors[e.index]),t.make_new_units_for_dataset(a,r,t.colors[e.index],e.index,t.y.length)),e.path&&t.animate_path(e,n,o),t.animate_units(e,n,o)}),runSMILAnimation(this.chart_wrapper,this.svg,this.elements_to_animate),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var a=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,a.join("L")))}},{key:"animate_units",value:function(t,e,i){var a=this,n=this.unit_args.type;t.svg_units.map(function(s,r){void 0!==e[r]&&void 0!==i[r]&&a.elements_to_animate.push(a.animator[n]({unit:s,array:t.svg_units,index:r},e[r],i[r],t.index,a.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(a,n){i.elements_to_animate.push(i.animator.verticalLine(a,e[n],t[n]))})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(a,n){i.elements_to_animate.push(i.animator.horizontalLine(a,e[n],t[n]))})}},{key:"animateYAnnotations",value:function(){}},{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 n=this.x.slice();n.splice(i,0,e),this.updateData(a,n)}},{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.updateData(e,i)}}},{key:"getDataPoint",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 n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return floatTwo(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentage_bar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var a=offset(t.chart_wrapper),n=offset(e),s=n.left-a.left+e.offsetWidth/2,r=n.top-a.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[i]:t.labels[i])+": ",l=(100*t.slice_totals[i]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"show_summary",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{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,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,u=o/i.grand_total*FULL_ANGLE,c=n?-u:u,p=r+=c,_=e.getPositionByAngle(h,a),d=e.getPositionByAngle(p,a),f=t&&s[l],v=void 0,m=void 0;t?(v=f?f.startPosition:_,m=f?f.endPosition:_):(v=_,m=d);var g=i.makeArcPath(v,m),y=makePath(g,"pie-path","none",i.colors[l]);y.style.transition="transform .3s;",i.draw_area.appendChild(y),i.slices.push(y),i.slicesProperties.push({startPosition:_,endPosition:d,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:c}),t&&i.elements_to_animate.push([{unit:y,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(_,d)},650,"easein",null,{d:g}])}),t&&runSMILAnimation(this.chart_wrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=offset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,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,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,f=void 0===d?[]:d;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=o,v.data=h,v.discrete_domains=c,v.count_label=_;var m=new Date;return v.start=a||addDays(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 inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(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()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(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=calcDistribution(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;ii)break;f.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=f}return[s,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=makeText("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("-"),n=t.month_names[parseInt(a[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-s.left+(o+2)/2,h=r.top-s.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+n+" "+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}(BaseChart),chartTypes={line:LineChart,bar:BarChart,scatter:ScatterChart,percentage:PercentageChart,heatmap:Heatmap,pie:PieChart},Chart=function t(e){return classCallCheck(this,t),getChartByType(e.type,arguments[0])};export default Chart; diff --git a/dist/frappe-charts.min.iife.js b/dist/frappe-charts.min.iife.js index 2da44f4..2a813ad 100644 --- a/dist/frappe-charts.min.iife.js +++ b/dist/frappe-charts.min.iife.js @@ -1 +1 @@ -var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(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)}function a(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function n(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function r(t,e){return(t+"").length*e}function o(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=.01*i)):(n=e,0===(a=t-e)&&(a=.01*i)),[a,n]}function l(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=s(t,i):e=s(e,i),[t,e]}function h(t,e){var i=void 0,a=void 0,n=void 0,s="";return"span"===e?(i=-7,a=t+15,n=t+25):"tick"===e&&(i=t,a=6,n=9,s="x-axis-label"),[i,a,n,s]}function u(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,a="",n=0;return"span"===e?(i=t+6,n=-6):"tick"===e&&(i=-6,a="y-axis-label"),[i,-9,a,n]}function c(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function p(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)c(n).appendChild(i);else if("around"===a){var s=c(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":I(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function _(t,e){return p("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function d(t,e,i,a){return p("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function v(t,e,i,a){return p("svg",{className:e,inside:t,width:i,height:a})}function f(t){return p("defs",{inside:t})}function y(t,e){return p("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function g(t){return p("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 m(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=_(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),d(n,"0%",e,s[0]),d(n,"50%",e,s[1]),d(n,"100%",e,s[2]),a}function x(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),p("rect",r)}function k(t,e,i,a){return p("text",{className:t,x:e,y:i,dy:".32em",innerHTML:a})}function b(t,e,i,a,n,s){var r=p("line",{x1:0,x2:0,y1:0,y2:t}),o=p("text",{className:a,x:0,y:e,dy:".71em",innerHTML:i}),l=p("g",{className:"tick "+n,transform:"translate("+s+", 0)"});return l.appendChild(r),l.appendChild(o),l}function w(t,e,i,a,n,s,r){var o=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=p("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=p("text",{className:n,x:i,y:0,dy:".32em",innerHTML:a+""}),u=p("g",{className:"tick "+s,transform:"translate(0, "+r+")","stroke-opacity":1});return o&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function A(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:Z[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var _ in p)h.setAttribute(_,p[_]);r.appendChild(h),n?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function P(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function C(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=A.apply(void 0,V(t)),l=G(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function L(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 M(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=L(t),a=G(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=M(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function N(t){function e(t,e){for(var i=O(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,V(t)),n=Math.min.apply(Math,V(t)),s=[];if(a>=0&&n>=0)L(a)[1],s=i?O(a,n):O(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(L(a)[1],s=e(a,r)):(L(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);L(o)[1],s=(s=i?O(o,l):O(o)).reverse().map(function(t){return-1*t})}return s}function D(t,e){for(var i=Math.max.apply(Math,V(t)),a=1/(e-1),n=[],s=0;s255?255:t<0?0:t}function j(t,e){var i=at(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=T((n>>16)+e),r=T((n>>8&255)+e),o=T((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function z(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function E(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function H(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function Y(t,e){return Math.ceil(W(t,e)/7)}function W(t,e){return(E(e)-E(t))/864e5}function F(t,e){t.setDate(t.getDate()+e)}function B(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return ft[t]?new ft[t](e):new ut(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:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 I="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},q=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,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")}),R=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
            \n\t\t\t\t
            '}),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?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,a){var n=e.colors[a]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+n},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{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]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,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}(),et={"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"},it=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],at=function(t){return et[t]||t},nt=["line","scatter","bar","percentage","heatmap","pie"],st={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:[]},rt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ot=function(){function e(t){var i=t.height,a=void 0===i?240:i,n=t.title,s=void 0===n?"":n,r=t.subtitle,o=void 0===r?"":r,l=t.colors,h=void 0===l?[]:l,u=t.summary,c=void 0===u?[]:u,p=t.is_navigable,_=void 0===p?0:p,d=t.has_legend,v=void 0===d?0:d,f=t.type,y=void 0===f?"":f,g=t.parent,m=t.data;q(this,e),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=o,this.data=m,this.oldData=Object.assign({},m),this.specific_values=m.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=v,this.setColors(h,y),this.set_margins(a)}return R(e,[{key:"get_different_chart",value:function(t){if(t!==this.type){nt.includes(t)||console.error("'"+t+"' is not a valid chart type."),st[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=rt[this.type].includes(t);return new yt({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.length0&&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=r(e.title+"",8);i>t&&(t=i-40)}),this.base_width=a(this.parent)-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:'
            '+this.title+'
            \n\t\t\t\t
            '+this.subtitle+'
            \n\t\t\t\t
            \n\t\t\t\t
            '}),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=v(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=f(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=y(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new tt({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",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+i.title+": "+i.value+"\n\t\t\t\t"});e.stats_wrapper.appendChild(a)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){i(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return y(this.draw_area,t,e)}}]),e}(),lt=function(t){function i(t){q(this,i);var e=J(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 U(i,t),R(i,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 n(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=N(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,a=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/a,this.old_multiplier||(this.old_multiplier=this.multiplier);var n=i[1]-i[0],s=n*this.multiplier,r=void 0;r=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/n:-1*i[i.length-1]/n+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-r*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){X(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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,a=h(this.height,this.x_axis_mode),n=G(a,4),s=n[0],o=n[1],l=n[2],u=n[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var c=1.5*this.avg_unit_width,p=c/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,a){var n=r(e,8)+2;if(n>c)if(i.is_series){for(var s=1;n/s*2>c;)s++;if(a%s!=0)return}else e=e.slice(0,p-3)+" ...";var h=b(o,l,e,"x-value-text",u,t[a]);i.xAxisLines.push(h),i.x_axis_group.appendChild(h)})}},{key:"makeYLines",value:function(t,e){var i=this,a=u(this.width,this.y_axis_mode),n=G(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,a){var n=w(l,s,r,e,"y-value-text",o,t[a],0===e&&0!==a);i.yAxisLines.push(n),i.y_axis_group.appendChild(n)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{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,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var e=this;t?setTimeout(function(){X(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",e).call(e,t)},500):X(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,n,s,r,o){s||(s=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),s.textContent="",r.length=0;var l=new K(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,n);s.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(i){var a=e(t.chart_wrapper),n=i.pageX-a.left-t.translate_x;i.pageY-a.top-t.translate_y=0;n--){var s=this.x_axis_positions[n];if(t>s-this.avg_unit_width/2){var r=s+this.translate_x,o=this.y_min_tops[n]+this.translate_y,l=i[n],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[n]):t.values[n],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new Q(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.run_animation(),this.updating=!1}},{key:"run_animation",value:function(){var t=this,e=C(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){var i=l(t.x_old_axis_positions.slice(),t.x_axis_positions.slice()),a=G(i,2),n=a[0],s=a[1],r=l(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),o=G(r,2),h=o[0],u=o[1],c=l(t.oldYAxisPositions.slice(),t.yAxisPositions.slice()),p=G(c,2),_=p[0],d=p[1],v=t.x.slice(),f=t.y_axis_values.slice(),y=t.x_axis_positions.slice().length-t.x_old_axis_positions.slice().length;y>0&&(t.make_path&&t.make_path(e,n,h,t.colors[e.index]),t.make_new_units_for_dataset(n,h,t.colors[e.index],e.index,t.y.length),t.makeXLines(n,v)),t.makeYLines(_,f),t.updating||(0!==y&&t.animateXLines(n,s),e.path&&t.animate_path(e,s,u),t.animate_units(e,s,u),t.animateYLines(_,d))}),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var a=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,a.join("L")))}},{key:"animate_units",value:function(t,e,i){var a=this,n=this.unit_args.type;t.svg_units.map(function(s,r){void 0!==e[r]&&void 0!==i[r]&&a.elements_to_animate.push(a.animator[n]({unit:s,array:t.svg_units,index:r},e[r],i[r],t.index,a.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:e[n]+", 0"},350,"easein","translate",{transform:t[n]+", 0"}])})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:"0, "+e[n]},350,"easein","translate",{transform:"0, "+t[n]}])})}},{key:"animateYAnnotations",value:function(){}},{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 n=this.x.slice();n.splice(i,0,e),this.updateData(a,n)}},{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.updateData(e,i)}}},{key:"getDataPoint",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 n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return n(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 n=t.create("div",{className:"progress-bar",inside:e.percentage_bar,styles:{background:e.colors[a],width:100*i/e.grand_total+"%"}});e.slices.push(n)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(i,a){i.addEventListener("mouseenter",function(){var n=e(t.chart_wrapper),s=e(i),r=s.left-n.left+i.offsetWidth/2,o=s.top-n.top-6,l=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[a]:t.labels[a])+": ",h=(100*t.slice_totals[a]/t.grand_total).toFixed(1);t.tip.set_values(r,o,l,h+"%"),t.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,n){a&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[n]+":\n\t\t\t\t\t"+a+"\n\t\t\t\t")})}}]),a}(ot),_t=Math.PI/180,dt=function(i){function a(t){q(this,a);var e=J(this,(a.__proto__||Object.getPrototypeOf(a)).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 U(a,i),R(a,[{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,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var e=this,i=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,u=o/e.grand_total*360,c=n?-u:u,p=r+=c,_=a.getPositionByAngle(h,i),d=a.getPositionByAngle(p,i),v=t&&s[l],f=void 0,y=void 0;t?(f=v?v.startPosition:_,y=v?v.endPosition:_):(f=_,y=d);var m=e.makeArcPath(f,y),x=g(m,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.draw_area.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:_,endPosition:d,value:o,total:e.grand_total,startAngle:h,endAngle:p,angle:c}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(_,d)},650,"easein",null,{d:m}])}),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=C(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,i=this.hoverRadio,n=a.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+n.x*i+"px,"+n.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,i,a,n){if(t){var s=this.colors[i];if(a){P(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=j(s,50);var r=e(this.svg),o=n.pageX-r.left+10,l=n.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 P(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=s}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,n){var s=e.colors[n];a&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[n]+":\n\t\t\t\t\t"+a+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*_t)*e,y:Math.cos(t*_t)*e}}}]),a}(ot),vt=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,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,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,v=void 0===d?[]:d;q(this,e);var f=J(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));f.type="heatmap",f.domain=s,f.subdomain=o,f.data=h,f.discrete_domains=c,f.count_label=_;var y=new Date;return f.start=a||F(y,365),v=v.slice(0,5),f.legend_colors=f.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],f.distribution_size=5,f.translate_x=0,f.setup(),f}return U(e,t),R(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){z(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()&&F(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&F(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=Y(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=D(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;ii)break;v.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=v}return[s,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=k("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("-"),n=t.month_names[parseInt(a[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-s.left+(o+2)/2,h=r.top-s.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+n+" "+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}(ot),ft={line:ut,bar:ht,scatter:ct,percentage:pt,heatmap:vt,pie:dt},yt=function t(e){return q(this,t),B(e.type,arguments[0])};return yt}(); +var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(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)}function n(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function a(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function o(t,e){return(t+"").length*e}function r(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=.01*i)):(a=e,0===(n=t-e)&&(n=.01*i)),[n,a]}function l(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=s(t,i):e=s(e,i),[t,e]}function h(t,e){var i=void 0,n=void 0,a=void 0,s="";return"span"===e?(i=-7,n=t+15,a=t+25):"tick"===e&&(i=t,n=6,a=9,s="x-axis-label"),[i,n,a,s]}function u(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,n="",a=0;return"span"===e?(i=t+6,a=-6):"tick"===e&&(i=-6,n="y-axis-label"),[i,-9,n,a]}function c(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function p(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e){var a=e[n];if("inside"===n)c(a).appendChild(i);else if("around"===n){var s=c(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":q(a))&&Object.keys(a).map(function(t){i.style[t]=a[t]}):("className"===n&&(n="class"),"innerHTML"===n?i.textContent=a:i.setAttribute(n,a))}return i}function _(t,e){return p("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function d(t,e,i,n){return p("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function f(t,e,i,n){return p("svg",{className:e,inside:t,width:i,height:n})}function v(t){return p("defs",{inside:t})}function y(t,e){return p("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function g(t){return p("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 m(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=_(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),d(a,"0%",e,s[0]),d(a,"50%",e,s[1]),d(a,"100%",e,s[2]),n}function x(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},o={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(s).map(function(t){o[t]=s[t]}),p("rect",o)}function k(t,e,i,n){return p("text",{className:t,x:e,y:i,dy:".32em",innerHTML:n})}function b(t,e,i,n,a,s){var o=p("line",{x1:0,x2:0,y1:0,y2:t}),r=p("text",{className:n,x:0,y:e,dy:".71em",innerHTML:i}),l=p("g",{className:"tick "+a,transform:"translate("+s+", 0)"});return l.appendChild(o),l.appendChild(r),l}function w(t,e,i,n,a,s,o){var r=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=p("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=p("text",{className:a,x:i,y:0,dy:".32em",innerHTML:n+""}),u=p("g",{className:"tick "+s,transform:"translate(0, "+o+")","stroke-opacity":1});return r&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function A(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},o=t.cloneNode(!0),r=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:et[n],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};a&&(p.type=a);for(var _ in p)h.setAttribute(_,p[_]);o.appendChild(h),a?r.setAttribute(l,"translate("+c+")"):r.setAttribute(l,c)}return[o,r]}function P(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function C(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,s=void 0,o=void 0;t[0]=e.unit;var r=A.apply(void 0,K(t)),l=V(r,2);s=l[0],o=l[1],i.push(o),n.push([s,a]),a.replaceChild(s,e.unit),e.array?e.array[e.index]=o:e.object[e.key]=o});var a=t.cloneNode(!0);return n.map(function(t,n){t[1].replaceChild(i[n],t[0]),e[n][0]=i[n]}),a}function L(t,e,i){if(0!==i.length){var n=C(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},Z)}}function M(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 O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),n=Math.floor(e),a=i-n,s=a,o=1;a>5&&(a%2!=0&&(a=++i-n),s=a/2,o=2),a<=2&&(o=a/(s=4)),0===a&&(s=5,o=1);for(var r=[],l=0;l<=s;l++)r.push(n+o*l);return r}function N(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=M(t),n=V(i,2),a=n[0],s=n[1],o=e?e/Math.pow(10,s):0,r=O(a=a.toFixed(6),o);return r=r.map(function(t){return t*Math.pow(10,s)})}function D(t){function e(t,e){for(var i=N(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,K(t)),a=Math.min.apply(Math,K(t)),s=[];if(n>=0&&a>=0)M(n)[1],s=i?N(n,a):N(n);else if(n>0&&a<0){var o=Math.abs(a);n>=o?(M(n)[1],s=e(n,o)):(M(o)[1],s=e(o,n).map(function(t){return-1*t}))}else if(n<=0&&a<=0){var r=Math.abs(a),l=Math.abs(n);M(r)[1],s=(s=i?N(r,l):N(r)).reverse().map(function(t){return-1*t})}return s}function S(t,e){for(var i=Math.max.apply(Math,K(t)),n=1/(e-1),a=[],s=0;s255?255:t<0?0:t}function z(t,e){var i=st(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=T((a>>16)+e),o=T((a>>8&255)+e),r=T((255&a)+e);return(n?"#":"")+(r|o<<8|s<<16).toString(16)}function E(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function H(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function Y(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function W(t,e){return Math.ceil(F(t,e)/7)}function F(t,e){return(H(e)-H(t))/864e5}function B(t,e){t.setDate(t.getDate()+e)}function I(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return gt[t]?new gt[t](e):new pt(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 q="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},R=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,a){var r={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=r:(s=o=r,n(t,e))})}function n(i,s){try{var o=e[i](s),r=o.value;r instanceof t?Promise.resolve(r.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(o.done?"return":"normal",o.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?n(s.key,s.arg):o=null}var s,o;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")}),X=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
              \n\t\t\t\t
              '}),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?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,n){var a=e.colors[n]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{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 n="calc(50% + "+(this.left-e)+"px)";i.style.left=n,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]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=n,this.list_values=a,this.x=t,this.y=e,this.title_value_first=s,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}(),nt={"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"},at=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],st=function(t){return nt[t]||t},ot=["line","scatter","bar","percentage","heatmap","pie"],rt={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:[]},lt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ht=function(){function e(t){var i=t.height,n=void 0===i?240:i,a=t.title,s=void 0===a?"":a,o=t.subtitle,r=void 0===o?"":o,l=t.colors,h=void 0===l?[]:l,u=t.summary,c=void 0===u?[]:u,p=t.is_navigable,_=void 0===p?0:p,d=t.has_legend,f=void 0===d?0:d,v=t.type,y=void 0===v?"":v,g=t.parent,m=t.data;R(this,e),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=r,this.data=m,this.oldData=Object.assign({},m),this.specific_values=m.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,y),this.set_margins(n)}return X(e,[{key:"get_different_chart",value:function(t){if(t!==this.type){ot.includes(t)||console.error("'"+t+"' is not a valid chart type."),rt[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=lt[this.type].includes(t);return new mt({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.length0&&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=o(e.title+"",8);i>t&&(t=i-40)}),this.base_width=n(this.parent)-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:'
              '+this.title+'
              \n\t\t\t\t
              '+this.subtitle+'
              \n\t\t\t\t
              \n\t\t\t\t
              '}),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=f(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=v(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=y(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new it({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 n=t.create("div",{className:"stats",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+i.title+": "+i.value+"\n\t\t\t\t"});e.stats_wrapper.appendChild(n)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){i(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return y(this.draw_area,t,e)}}]),e}(),ut=function(t){function i(t){R(this,i);var e=G(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 J(i,t),X(i,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 a(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=D(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,n=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/n,this.old_multiplier||(this.old_multiplier=this.multiplier);var a=i[1]-i[0],s=a*this.multiplier,o=void 0;o=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/a:-1*i[i.length-1]/a+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-o*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){U(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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,n=h(this.height,this.x_axis_mode),a=V(n,4),s=a[0],r=a[1],l=a[2],u=a[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var c=1.5*this.avg_unit_width,p=c/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,n){var a=o(e,8)+2;if(a>c)if(i.is_series){for(var s=1;a/s*2>c;)s++;if(n%s!=0)return}else e=e.slice(0,p-3)+" ...";var h=b(r,l,e,"x-value-text",u,t[n]);i.xAxisLines.push(h),i.x_axis_group.appendChild(h)})}},{key:"makeYLines",value:function(t,e){var i=this,n=u(this.width,this.y_axis_mode),a=V(n,4),s=a[0],o=a[1],r=a[2],l=a[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,n){var a=w(l,s,o,e,"y-value-text",r,t[n],0===e&&0!==n);i.yAxisLines.push(a),i.y_axis_group.appendChild(a)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{key:"draw_new_graph_and_animate",value:function(){var t=this,e=[];this.y.map(function(i,n){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,t.x_axis_positions,i.y_tops,t.colors[n]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var e=this;t?setTimeout(function(){U(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",e).call(e,t)},500):U(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,n,a,s,o,r){s||(s=this.svg_units_groups[n]),o||(o=this.y[n].svg_units),r||(r=this.unit_args),s.textContent="",o.length=0;var l=new Q(this.height,this.zero_line,this.avg_unit_width);e.map(function(e,h){var u=l[r.type](t[h],e,r.args,i,h,n,a);s.appendChild(u),o.push(u)}),this.is_navigable&&this.bind_units(o)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(i){var n=e(t.chart_wrapper),a=i.pageX-n.left-t.translate_x;i.pageY-n.top-t.translate_y=0;a--){var s=this.x_axis_positions[a];if(t>s-this.avg_unit_width/2){var o=s+this.translate_x,r=this.y_min_tops[a]+this.translate_y,l=i[a],h=this.y.map(function(t,i){return{title:t.title,value:n?e.format_tooltip_y(t.values[a]):t.values[a],color:e.colors[i]}});this.tip.set_values(o,r,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){e||(e=this.x),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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new tt(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.updating=!1}},{key:"animate_graphs",value:function(){var t=this;this.elements_to_animate=[];var e=l(this.x_old_axis_positions.slice(),this.x_axis_positions.slice()),i=V(e,2),n=i[0],a=i[1],s=l(this.oldYAxisPositions.slice(),this.yAxisPositions.slice()),o=V(s,2),r=o[0],h=o[1],u=this.x.slice(),c=this.y_axis_values.slice(),p=this.x_axis_positions.slice().length-this.x_old_axis_positions.slice().length;p>0&&this.makeXLines(n,u),this.makeYLines(r,c),0!==p&&this.animateXLines(n,a),this.animateYLines(r,h),this.y.map(function(e){var i=l(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),s=V(i,2),o=s[0],r=s[1];p>0&&(t.make_path&&t.make_path(e,n,o,t.colors[e.index]),t.make_new_units_for_dataset(n,o,t.colors[e.index],e.index,t.y.length)),e.path&&t.animate_path(e,a,r),t.animate_units(e,a,r)}),L(this.chart_wrapper,this.svg,this.elements_to_animate),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var n=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,n.join("L")))}},{key:"animate_units",value:function(t,e,i){var n=this,a=this.unit_args.type;t.svg_units.map(function(s,o){void 0!==e[o]&&void 0!==i[o]&&n.elements_to_animate.push(n.animator[a]({unit:s,array:t.svg_units,index:o},e[o],i[o],t.index,n.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(n,a){i.elements_to_animate.push(i.animator.verticalLine(n,e[a],t[a]))})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(n,a){i.elements_to_animate.push(i.animator.horizontalLine(n,e[a],t[a]))})}},{key:"animateYAnnotations",value:function(){}},{key:"add_data_point",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.x.length,n=this.y.map(function(t){return{values:t.values}});n.map(function(e,n){e.values.splice(i,0,t[n])});var a=this.x.slice();a.splice(i,0,e),this.updateData(n,a)}},{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.updateData(e,i)}}},{key:"getDataPoint",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(n){var a=n.slice(0,n.length-1);e[a]=i[n][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return a(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"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,n){var a=t.create("div",{className:"progress-bar",inside:e.percentage_bar,styles:{background:e.colors[n],width:100*i/e.grand_total+"%"}});e.slices.push(a)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(i,n){i.addEventListener("mouseenter",function(){var a=e(t.chart_wrapper),s=e(i),o=s.left-a.left+i.offsetWidth/2,r=s.top-a.top-6,l=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[n]:t.labels[n])+": ",h=(100*t.slice_totals[n]/t.grand_total).toFixed(1);t.tip.set_values(o,r,l,h+"%"),t.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(n,a){n&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}]),n}(ht),ft=Math.PI/180,vt=function(i){function n(t){R(this,n);var e=G(this,(n.__proto__||Object.getPrototypeOf(n)).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 J(n,i),X(n,[{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 n=0;return t.data.datasets.map(function(t){n+=t.values[i]}),[n,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 n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"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,n=this.centerY,a=this.radius,s=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"make_graph_components",value:function(t){var e=this,i=this.radius,a=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var o=180-this.startAngle;this.slice_totals.map(function(r,l){var h=o,u=r/e.grand_total*360,c=a?-u:u,p=o+=c,_=n.getPositionByAngle(h,i),d=n.getPositionByAngle(p,i),f=t&&s[l],v=void 0,y=void 0;t?(v=f?f.startPosition:_,y=f?f.endPosition:_):(v=_,y=d);var m=e.makeArcPath(v,y),x=g(m,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.draw_area.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:_,endPosition:d,value:r,total:e.grand_total,startAngle:h,endAngle:p,angle:c}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(_,d)},650,"easein",null,{d:m}])}),t&&L(this.chart_wrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var e=this.radius,i=this.hoverRadio,a=n.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+a.x*i+"px,"+a.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,i,n,a){if(t){var s=this.colors[i];if(n){P(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=z(s,50);var o=e(this.svg),r=a.pageX-o.left+10,l=a.pageY-o.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(r,l,h,u+"%"),this.tip.show_tip()}else P(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=s}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,n=this.curActiveSlice,a=0;a0?this.formatted_labels:this.labels;this.legend_totals.map(function(n,a){var s=e.colors[a];n&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ft)*e,y:Math.cos(t*ft)*e}}}]),n}(ht),yt=function(t){function e(t){var i=t.start,n=void 0===i?"":i,a=t.domain,s=void 0===a?"":a,o=t.subdomain,r=void 0===o?"":o,l=t.data,h=void 0===l?{}:l,u=t.discrete_domains,c=void 0===u?0:u,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,f=void 0===d?[]:d;R(this,e);var v=G(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=r,v.data=h,v.discrete_domains=c,v.count_label=_;var y=new Date;return v.start=n||B(y,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 J(e,t),X(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){E(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()&&B(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&B(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=W(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=S(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;ii)break;f.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=f}return[s,n]}},{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 n=k("y-value-text",e+12,10,t.month_names[t.months[i]].substring(0,3));t.domain_label_group.appendChild(n)})}},{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"),n=e.target.getAttribute("data-date").split("-"),a=t.month_names[parseInt(n[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),o=e.target.getBoundingClientRect(),r=parseInt(e.target.getAttribute("width")),l=o.left-s.left+(r+2)/2,h=o.top-s.top-(r+2)/2,u=i+" "+t.count_label,c=" on "+a+" "+n[0]+", "+n[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}(ht),gt={line:pt,bar:ct,scatter:_t,percentage:dt,heatmap:yt,pie:vt},mt=function t(e){return R(this,t),I(e.type,arguments[0])};return mt}(); diff --git a/docs/assets/js/frappe-charts.min.js b/docs/assets/js/frappe-charts.min.js index 2da44f4..2a813ad 100644 --- a/docs/assets/js/frappe-charts.min.js +++ b/docs/assets/js/frappe-charts.min.js @@ -1 +1 @@ -var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(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)}function a(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function n(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function r(t,e){return(t+"").length*e}function o(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=.01*i)):(n=e,0===(a=t-e)&&(a=.01*i)),[a,n]}function l(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=s(t,i):e=s(e,i),[t,e]}function h(t,e){var i=void 0,a=void 0,n=void 0,s="";return"span"===e?(i=-7,a=t+15,n=t+25):"tick"===e&&(i=t,a=6,n=9,s="x-axis-label"),[i,a,n,s]}function u(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,a="",n=0;return"span"===e?(i=t+6,n=-6):"tick"===e&&(i=-6,a="y-axis-label"),[i,-9,a,n]}function c(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function p(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)c(n).appendChild(i);else if("around"===a){var s=c(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":I(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function _(t,e){return p("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function d(t,e,i,a){return p("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function v(t,e,i,a){return p("svg",{className:e,inside:t,width:i,height:a})}function f(t){return p("defs",{inside:t})}function y(t,e){return p("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function g(t){return p("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 m(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=_(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),d(n,"0%",e,s[0]),d(n,"50%",e,s[1]),d(n,"100%",e,s[2]),a}function x(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),p("rect",r)}function k(t,e,i,a){return p("text",{className:t,x:e,y:i,dy:".32em",innerHTML:a})}function b(t,e,i,a,n,s){var r=p("line",{x1:0,x2:0,y1:0,y2:t}),o=p("text",{className:a,x:0,y:e,dy:".71em",innerHTML:i}),l=p("g",{className:"tick "+n,transform:"translate("+s+", 0)"});return l.appendChild(r),l.appendChild(o),l}function w(t,e,i,a,n,s,r){var o=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=p("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=p("text",{className:n,x:i,y:0,dy:".32em",innerHTML:a+""}),u=p("g",{className:"tick "+s,transform:"translate(0, "+r+")","stroke-opacity":1});return o&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function A(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:Z[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var _ in p)h.setAttribute(_,p[_]);r.appendChild(h),n?o.setAttribute(l,"translate("+c+")"):o.setAttribute(l,c)}return[r,o]}function P(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function C(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=A.apply(void 0,V(t)),l=G(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function L(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 M(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=L(t),a=G(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=M(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function N(t){function e(t,e){for(var i=O(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,V(t)),n=Math.min.apply(Math,V(t)),s=[];if(a>=0&&n>=0)L(a)[1],s=i?O(a,n):O(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(L(a)[1],s=e(a,r)):(L(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);L(o)[1],s=(s=i?O(o,l):O(o)).reverse().map(function(t){return-1*t})}return s}function D(t,e){for(var i=Math.max.apply(Math,V(t)),a=1/(e-1),n=[],s=0;s255?255:t<0?0:t}function j(t,e){var i=at(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=T((n>>16)+e),r=T((n>>8&255)+e),o=T((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function z(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function E(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function H(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function Y(t,e){return Math.ceil(W(t,e)/7)}function W(t,e){return(E(e)-E(t))/864e5}function F(t,e){t.setDate(t.getDate()+e)}function B(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return ft[t]?new ft[t](e):new ut(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:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 I="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},q=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,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")}),R=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
                \n\t\t\t\t
                '}),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?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,a){var n=e.colors[a]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+n},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{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]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,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}(),et={"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"},it=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],at=function(t){return et[t]||t},nt=["line","scatter","bar","percentage","heatmap","pie"],st={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:[]},rt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ot=function(){function e(t){var i=t.height,a=void 0===i?240:i,n=t.title,s=void 0===n?"":n,r=t.subtitle,o=void 0===r?"":r,l=t.colors,h=void 0===l?[]:l,u=t.summary,c=void 0===u?[]:u,p=t.is_navigable,_=void 0===p?0:p,d=t.has_legend,v=void 0===d?0:d,f=t.type,y=void 0===f?"":f,g=t.parent,m=t.data;q(this,e),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=o,this.data=m,this.oldData=Object.assign({},m),this.specific_values=m.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=v,this.setColors(h,y),this.set_margins(a)}return R(e,[{key:"get_different_chart",value:function(t){if(t!==this.type){nt.includes(t)||console.error("'"+t+"' is not a valid chart type."),st[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=rt[this.type].includes(t);return new yt({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.length0&&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=r(e.title+"",8);i>t&&(t=i-40)}),this.base_width=a(this.parent)-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:'
                '+this.title+'
                \n\t\t\t\t
                '+this.subtitle+'
                \n\t\t\t\t
                \n\t\t\t\t
                '}),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=v(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=f(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=y(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new tt({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",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+i.title+": "+i.value+"\n\t\t\t\t"});e.stats_wrapper.appendChild(a)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){i(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return y(this.draw_area,t,e)}}]),e}(),lt=function(t){function i(t){q(this,i);var e=J(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 U(i,t),R(i,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 n(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=N(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,a=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/a,this.old_multiplier||(this.old_multiplier=this.multiplier);var n=i[1]-i[0],s=n*this.multiplier,r=void 0;r=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/n:-1*i[i.length-1]/n+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-r*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){X(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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,a=h(this.height,this.x_axis_mode),n=G(a,4),s=n[0],o=n[1],l=n[2],u=n[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var c=1.5*this.avg_unit_width,p=c/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,a){var n=r(e,8)+2;if(n>c)if(i.is_series){for(var s=1;n/s*2>c;)s++;if(a%s!=0)return}else e=e.slice(0,p-3)+" ...";var h=b(o,l,e,"x-value-text",u,t[a]);i.xAxisLines.push(h),i.x_axis_group.appendChild(h)})}},{key:"makeYLines",value:function(t,e){var i=this,a=u(this.width,this.y_axis_mode),n=G(a,4),s=n[0],r=n[1],o=n[2],l=n[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,a){var n=w(l,s,r,e,"y-value-text",o,t[a],0===e&&0!==a);i.yAxisLines.push(n),i.y_axis_group.appendChild(n)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{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,t.x_axis_positions,i.y_tops,t.colors[a]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var e=this;t?setTimeout(function(){X(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",e).call(e,t)},500):X(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,a,n,s,r,o){s||(s=this.svg_units_groups[a]),r||(r=this.y[a].svg_units),o||(o=this.unit_args),s.textContent="",r.length=0;var l=new K(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,n);s.appendChild(u),r.push(u)}),this.is_navigable&&this.bind_units(r)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(i){var a=e(t.chart_wrapper),n=i.pageX-a.left-t.translate_x;i.pageY-a.top-t.translate_y=0;n--){var s=this.x_axis_positions[n];if(t>s-this.avg_unit_width/2){var r=s+this.translate_x,o=this.y_min_tops[n]+this.translate_y,l=i[n],h=this.y.map(function(t,i){return{title:t.title,value:a?e.format_tooltip_y(t.values[n]):t.values[n],color:e.colors[i]}});this.tip.set_values(r,o,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new Q(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.run_animation(),this.updating=!1}},{key:"run_animation",value:function(){var t=this,e=C(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){var i=l(t.x_old_axis_positions.slice(),t.x_axis_positions.slice()),a=G(i,2),n=a[0],s=a[1],r=l(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),o=G(r,2),h=o[0],u=o[1],c=l(t.oldYAxisPositions.slice(),t.yAxisPositions.slice()),p=G(c,2),_=p[0],d=p[1],v=t.x.slice(),f=t.y_axis_values.slice(),y=t.x_axis_positions.slice().length-t.x_old_axis_positions.slice().length;y>0&&(t.make_path&&t.make_path(e,n,h,t.colors[e.index]),t.make_new_units_for_dataset(n,h,t.colors[e.index],e.index,t.y.length),t.makeXLines(n,v)),t.makeYLines(_,f),t.updating||(0!==y&&t.animateXLines(n,s),e.path&&t.animate_path(e,s,u),t.animate_units(e,s,u),t.animateYLines(_,d))}),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var a=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,a.join("L")))}},{key:"animate_units",value:function(t,e,i){var a=this,n=this.unit_args.type;t.svg_units.map(function(s,r){void 0!==e[r]&&void 0!==i[r]&&a.elements_to_animate.push(a.animator[n]({unit:s,array:t.svg_units,index:r},e[r],i[r],t.index,a.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:e[n]+", 0"},350,"easein","translate",{transform:t[n]+", 0"}])})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(a,n){i.elements_to_animate.push([{unit:a,array:[0],index:0},{transform:"0, "+e[n]},350,"easein","translate",{transform:"0, "+t[n]}])})}},{key:"animateYAnnotations",value:function(){}},{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 n=this.x.slice();n.splice(i,0,e),this.updateData(a,n)}},{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.updateData(e,i)}}},{key:"getDataPoint",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 n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return n(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 n=t.create("div",{className:"progress-bar",inside:e.percentage_bar,styles:{background:e.colors[a],width:100*i/e.grand_total+"%"}});e.slices.push(n)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(i,a){i.addEventListener("mouseenter",function(){var n=e(t.chart_wrapper),s=e(i),r=s.left-n.left+i.offsetWidth/2,o=s.top-n.top-6,l=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[a]:t.labels[a])+": ",h=(100*t.slice_totals[a]/t.grand_total).toFixed(1);t.tip.set_values(r,o,l,h+"%"),t.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,n){a&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[n]+":\n\t\t\t\t\t"+a+"\n\t\t\t\t")})}}]),a}(ot),_t=Math.PI/180,dt=function(i){function a(t){q(this,a);var e=J(this,(a.__proto__||Object.getPrototypeOf(a)).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 U(a,i),R(a,[{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,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"make_graph_components",value:function(t){var e=this,i=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,u=o/e.grand_total*360,c=n?-u:u,p=r+=c,_=a.getPositionByAngle(h,i),d=a.getPositionByAngle(p,i),v=t&&s[l],f=void 0,y=void 0;t?(f=v?v.startPosition:_,y=v?v.endPosition:_):(f=_,y=d);var m=e.makeArcPath(f,y),x=g(m,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.draw_area.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:_,endPosition:d,value:o,total:e.grand_total,startAngle:h,endAngle:p,angle:c}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(_,d)},650,"easein",null,{d:m}])}),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=C(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,i=this.hoverRadio,n=a.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+n.x*i+"px,"+n.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,i,a,n){if(t){var s=this.colors[i];if(a){P(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=j(s,50);var r=e(this.svg),o=n.pageX-r.left+10,l=n.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 P(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=s}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,n){var s=e.colors[n];a&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[n]+":\n\t\t\t\t\t"+a+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*_t)*e,y:Math.cos(t*_t)*e}}}]),a}(ot),vt=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,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,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,v=void 0===d?[]:d;q(this,e);var f=J(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));f.type="heatmap",f.domain=s,f.subdomain=o,f.data=h,f.discrete_domains=c,f.count_label=_;var y=new Date;return f.start=a||F(y,365),v=v.slice(0,5),f.legend_colors=f.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],f.distribution_size=5,f.translate_x=0,f.setup(),f}return U(e,t),R(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){z(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()&&F(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&F(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=Y(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=D(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;ii)break;v.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=v}return[s,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=k("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("-"),n=t.month_names[parseInt(a[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),r=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=r.left-s.left+(o+2)/2,h=r.top-s.top-(o+2)/2,u=i+" "+t.count_label,c=" on "+n+" "+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}(ot),ft={line:ut,bar:ht,scatter:ct,percentage:pt,heatmap:vt,pie:dt},yt=function t(e){return q(this,t),B(e.type,arguments[0])};return yt}(); +var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(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)}function n(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function a(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function o(t,e){return(t+"").length*e}function r(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=.01*i)):(a=e,0===(n=t-e)&&(n=.01*i)),[n,a]}function l(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=s(t,i):e=s(e,i),[t,e]}function h(t,e){var i=void 0,n=void 0,a=void 0,s="";return"span"===e?(i=-7,n=t+15,a=t+25):"tick"===e&&(i=t,n=6,a=9,s="x-axis-label"),[i,n,a,s]}function u(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2])return[t,t+5,"specific-value",0];var i=void 0,n="",a=0;return"span"===e?(i=t+6,a=-6):"tick"===e&&(i=-6,n="y-axis-label"),[i,-9,n,a]}function c(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function p(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e){var a=e[n];if("inside"===n)c(a).appendChild(i);else if("around"===n){var s=c(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":q(a))&&Object.keys(a).map(function(t){i.style[t]=a[t]}):("className"===n&&(n="class"),"innerHTML"===n?i.textContent=a:i.setAttribute(n,a))}return i}function _(t,e){return p("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function d(t,e,i,n){return p("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function f(t,e,i,n){return p("svg",{className:e,inside:t,width:i,height:n})}function v(t){return p("defs",{inside:t})}function y(t,e){return p("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function g(t){return p("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 m(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=_(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),d(a,"0%",e,s[0]),d(a,"50%",e,s[1]),d(a,"100%",e,s[2]),n}function x(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},o={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(s).map(function(t){o[t]=s[t]}),p("rect",o)}function k(t,e,i,n){return p("text",{className:t,x:e,y:i,dy:".32em",innerHTML:n})}function b(t,e,i,n,a,s){var o=p("line",{x1:0,x2:0,y1:0,y2:t}),r=p("text",{className:n,x:0,y:e,dy:".71em",innerHTML:i}),l=p("g",{className:"tick "+a,transform:"translate("+s+", 0)"});return l.appendChild(o),l.appendChild(r),l}function w(t,e,i,n,a,s,o){var r=arguments.length>7&&void 0!==arguments[7]&&arguments[7],l=p("line",{className:"dashed"===(arguments.length>8&&void 0!==arguments[8]?arguments[8]:"")?"dashed":"",x1:t,x2:e,y1:0,y2:0}),h=p("text",{className:a,x:i,y:0,dy:".32em",innerHTML:n+""}),u=p("g",{className:"tick "+s,transform:"translate(0, "+o+")","stroke-opacity":1});return r&&(l.style.stroke="rgba(27, 31, 35, 0.6)"),u.appendChild(l),u.appendChild(h),u}function A(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},o=t.cloneNode(!0),r=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=s[l]||t.getAttribute(l),c=e[l],p={attributeName:l,from:u,to:c,begin:"0s",dur:i/1e3+"s",values:u+";"+c,keySplines:et[n],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};a&&(p.type=a);for(var _ in p)h.setAttribute(_,p[_]);o.appendChild(h),a?r.setAttribute(l,"translate("+c+")"):r.setAttribute(l,c)}return[o,r]}function P(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function C(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,s=void 0,o=void 0;t[0]=e.unit;var r=A.apply(void 0,K(t)),l=V(r,2);s=l[0],o=l[1],i.push(o),n.push([s,a]),a.replaceChild(s,e.unit),e.array?e.array[e.index]=o:e.object[e.key]=o});var a=t.cloneNode(!0);return n.map(function(t,n){t[1].replaceChild(i[n],t[0]),e[n][0]=i[n]}),a}function L(t,e,i){if(0!==i.length){var n=C(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},Z)}}function M(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 O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),n=Math.floor(e),a=i-n,s=a,o=1;a>5&&(a%2!=0&&(a=++i-n),s=a/2,o=2),a<=2&&(o=a/(s=4)),0===a&&(s=5,o=1);for(var r=[],l=0;l<=s;l++)r.push(n+o*l);return r}function N(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=M(t),n=V(i,2),a=n[0],s=n[1],o=e?e/Math.pow(10,s):0,r=O(a=a.toFixed(6),o);return r=r.map(function(t){return t*Math.pow(10,s)})}function D(t){function e(t,e){for(var i=N(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,K(t)),a=Math.min.apply(Math,K(t)),s=[];if(n>=0&&a>=0)M(n)[1],s=i?N(n,a):N(n);else if(n>0&&a<0){var o=Math.abs(a);n>=o?(M(n)[1],s=e(n,o)):(M(o)[1],s=e(o,n).map(function(t){return-1*t}))}else if(n<=0&&a<=0){var r=Math.abs(a),l=Math.abs(n);M(r)[1],s=(s=i?N(r,l):N(r)).reverse().map(function(t){return-1*t})}return s}function S(t,e){for(var i=Math.max.apply(Math,K(t)),n=1/(e-1),a=[],s=0;s255?255:t<0?0:t}function z(t,e){var i=st(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=T((a>>16)+e),o=T((a>>8&255)+e),r=T((255&a)+e);return(n?"#":"")+(r|o<<8|s<<16).toString(16)}function E(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function H(t){var e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function Y(t){var e=t.getDate(),i=t.getMonth()+1;return[(e>9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function W(t,e){return Math.ceil(F(t,e)/7)}function F(t,e){return(H(e)-H(t))/864e5}function B(t,e){t.setDate(t.getDate()+e)}function I(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return gt[t]?new gt[t](e):new pt(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,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 q="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},R=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,a){var r={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=r:(s=o=r,n(t,e))})}function n(i,s){try{var o=e[i](s),r=o.value;r instanceof t?Promise.resolve(r.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(o.done?"return":"normal",o.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?n(s.key,s.arg):o=null}var s,o;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")}),X=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
                  \n\t\t\t\t
                  '}),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?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,n){var a=e.colors[n]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{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 n="calc(50% + "+(this.left-e)+"px)";i.style.left=n,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]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=n,this.list_values=a,this.x=t,this.y=e,this.title_value_first=s,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}(),nt={"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"},at=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],st=function(t){return nt[t]||t},ot=["line","scatter","bar","percentage","heatmap","pie"],rt={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:[]},lt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ht=function(){function e(t){var i=t.height,n=void 0===i?240:i,a=t.title,s=void 0===a?"":a,o=t.subtitle,r=void 0===o?"":o,l=t.colors,h=void 0===l?[]:l,u=t.summary,c=void 0===u?[]:u,p=t.is_navigable,_=void 0===p?0:p,d=t.has_legend,f=void 0===d?0:d,v=t.type,y=void 0===v?"":v,g=t.parent,m=t.data;R(this,e),this.raw_chart_args=arguments[0],this.parent="string"==typeof g?document.querySelector(g):g,this.title=s,this.subtitle=r,this.data=m,this.oldData=Object.assign({},m),this.specific_values=m.specific_values||[],this.summary=c,this.is_navigable=_,this.is_navigable&&(this.current_index=0),this.has_legend=f,this.setColors(h,y),this.set_margins(n)}return X(e,[{key:"get_different_chart",value:function(t){if(t!==this.type){ot.includes(t)||console.error("'"+t+"' is not a valid chart type."),rt[this.type].includes(t)||console.error("'"+this.type+"' chart cannot be converted to a '"+t+"' chart.");var e=lt[this.type].includes(t);return new mt({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.length0&&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=o(e.title+"",8);i>t&&(t=i-40)}),this.base_width=n(this.parent)-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:'
                  '+this.title+'
                  \n\t\t\t\t
                  '+this.subtitle+'
                  \n\t\t\t\t
                  \n\t\t\t\t
                  '}),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=f(this.chart_wrapper,"chart",this.base_width,this.base_height),this.svg_defs=v(this.svg),this.svg}},{key:"make_draw_area",value:function(){this.draw_area=y(this.svg,this.type+"-chart","translate("+this.translate_x+", "+this.translate_y+")")}},{key:"setup_components",value:function(){}},{key:"setup_values",value:function(){}},{key:"setup_utils",value:function(){}},{key:"make_tooltip",value:function(){this.tip=new it({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 n=t.create("div",{className:"stats",innerHTML:'\n\t\t\t\t\t\n\t\t\t\t\t'+i.title+": "+i.value+"\n\t\t\t\t"});e.stats_wrapper.appendChild(n)})}},{key:"setup_navigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.make_overlay(),e&&(this.bind_overlay(),document.addEventListener("keydown",function(e){i(t.chart_wrapper)&&("37"==(e=e||window.event).keyCode?t.on_left_arrow():"39"==e.keyCode?t.on_right_arrow():"38"==e.keyCode?t.on_up_arrow():"40"==e.keyCode?t.on_down_arrow():"13"==e.keyCode&&t.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:"updateData",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"updateCurrentDataPoint",value:function(){}},{key:"makeDrawAreaComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return y(this.draw_area,t,e)}}]),e}(),ut=function(t){function i(t){R(this,i);var e=G(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 J(i,t),X(i,[{key:"validate_and_prepare_data",value:function(){return this.y.forEach(function(t,e){t.index=e},this),!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 a(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(){var t=this;this.y_axis_values&&(this.y_old_axis_values=this.y_axis_values.slice());var e=this.get_all_y_values();this.y_sums&&this.y_sums.length>0&&(e=e.concat(this.y_sums)),this.y_axis_values=D(e,"line"===this.type),this.y_old_axis_values||(this.y_old_axis_values=this.y_axis_values.slice());var i=this.y_axis_values,n=i[i.length-1]-i[0];this.multiplier&&(this.old_multiplier=this.multiplier),this.multiplier=this.height/n,this.old_multiplier||(this.old_multiplier=this.multiplier);var a=i[1]-i[0],s=a*this.multiplier,o=void 0;o=i.indexOf(0)>=0?i.indexOf(0):i[0]>0?-1*i[0]/a:-1*i[i.length-1]/a+(i.length-1),this.zero_line&&(this.old_zero_line=this.zero_line),this.zero_line=this.height-o*s,this.old_zero_line||(this.old_zero_line=this.zero_line),this.yAxisPositions&&(this.oldYAxisPositions=this.yAxisPositions),this.yAxisPositions=this.y_axis_values.map(function(e){return t.zero_line-e*t.multiplier}),this.oldYAxisPositions||(this.oldYAxisPositions=this.yAxisPositions),this.yAnnotationPositions&&(this.oldYAnnotationPositions=this.yAnnotationPositions),this.yAnnotationPositions=this.specific_values.map(function(e){return t.zero_line-e.value*t.multiplier}),this.oldYAnnotationPositions||(this.oldYAnnotationPositions=this.yAnnotationPositions)}},{key:"setup_components",value:function(){U(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.makeYLines(this.yAxisPositions,this.y_axis_values),this.makeXLines(this.x_axis_positions,this.x),this.draw_graph(t)}},{key:"makeXLines",value:function(t,e){var i=this,n=h(this.height,this.x_axis_mode),a=V(n,4),s=a[0],r=a[1],l=a[2],u=a[3];this.x_axis_group.setAttribute("transform","translate(0,"+s+")");var c=1.5*this.avg_unit_width,p=c/8;this.xAxisLines=[],this.x_axis_group.textContent="",e.map(function(e,n){var a=o(e,8)+2;if(a>c)if(i.is_series){for(var s=1;a/s*2>c;)s++;if(n%s!=0)return}else e=e.slice(0,p-3)+" ...";var h=b(r,l,e,"x-value-text",u,t[n]);i.xAxisLines.push(h),i.x_axis_group.appendChild(h)})}},{key:"makeYLines",value:function(t,e){var i=this,n=u(this.width,this.y_axis_mode),a=V(n,4),s=a[0],o=a[1],r=a[2],l=a[3];this.yAxisLines=[],this.y_axis_group.textContent="",e.map(function(e,n){var a=w(l,s,o,e,"y-value-text",r,t[n],0===e&&0!==n);i.yAxisLines.push(a),i.y_axis_group.appendChild(a)})}},{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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e),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,t.x_axis_positions,e.y_tops,t.colors[i]),t.make_new_units(e)})}},{key:"draw_new_graph_and_animate",value:function(){var t=this,e=[];this.y.map(function(i,n){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,t.x_axis_positions,i.y_tops,t.colors[n]),t.make_new_units(i)}),setTimeout(function(){t.updateData(e)},350)}},{key:"setup_navigation",value:function(t){var e=this;t?setTimeout(function(){U(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",e).call(e,t)},500):U(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setup_navigation",this).call(this,t)}},{key:"make_new_units",value:function(t){this.make_new_units_for_dataset(this.x_axis_positions,t.y_tops,this.colors[t.index],t.index,this.y.length)}},{key:"make_new_units_for_dataset",value:function(t,e,i,n,a,s,o,r){s||(s=this.svg_units_groups[n]),o||(o=this.y[n].svg_units),r||(r=this.unit_args),s.textContent="",o.length=0;var l=new Q(this.height,this.zero_line,this.avg_unit_width);e.map(function(e,h){var u=l[r.type](t[h],e,r.args,i,h,n,a);s.appendChild(u),o.push(u)}),this.is_navigable&&this.bind_units(o)}},{key:"bind_tooltip",value:function(){var t=this;this.chart_wrapper.addEventListener("mousemove",function(i){var n=e(t.chart_wrapper),a=i.pageX-n.left-t.translate_x;i.pageY-n.top-t.translate_y=0;a--){var s=this.x_axis_positions[a];if(t>s-this.avg_unit_width/2){var o=s+this.translate_x,r=this.y_min_tops[a]+this.translate_y,l=i[a],h=this.y.map(function(t,i){return{title:t.title,value:n?e.format_tooltip_y(t.values[a]):t.values[a],color:e.colors[i]}});this.tip.set_values(o,r,l,"",h),this.tip.show_tip();break}}}}},{key:"updateData",value:function(t,e){e||(e=this.x),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}),t&&this.y.map(function(e){e.values=t[e.index].values}),e&&(this.x=e),this.setup_x(),this.setup_y(),this.calc_y_dependencies(),this.animator=new tt(this.height,this.width,this.zero_line,this.avg_unit_width),this.animate_graphs(),this.updating=!1}},{key:"animate_graphs",value:function(){var t=this;this.elements_to_animate=[];var e=l(this.x_old_axis_positions.slice(),this.x_axis_positions.slice()),i=V(e,2),n=i[0],a=i[1],s=l(this.oldYAxisPositions.slice(),this.yAxisPositions.slice()),o=V(s,2),r=o[0],h=o[1],u=this.x.slice(),c=this.y_axis_values.slice(),p=this.x_axis_positions.slice().length-this.x_old_axis_positions.slice().length;p>0&&this.makeXLines(n,u),this.makeYLines(r,c),0!==p&&this.animateXLines(n,a),this.animateYLines(r,h),this.y.map(function(e){var i=l(t.old_y_axis_tops[e.index].slice(),e.y_tops.slice()),s=V(i,2),o=s[0],r=s[1];p>0&&(t.make_path&&t.make_path(e,n,o,t.colors[e.index]),t.make_new_units_for_dataset(n,o,t.colors[e.index],e.index,t.y.length)),e.path&&t.animate_path(e,a,r),t.animate_units(e,a,r)}),L(this.chart_wrapper,this.svg,this.elements_to_animate),setTimeout(function(){t.y.map(function(e){t.make_path&&t.make_path(e,t.x_axis_positions,e.y_tops,t.colors[e.index]),t.make_new_units(e),t.makeYLines(t.yAxisPositions,t.y_axis_values),t.makeXLines(t.x_axis_positions,t.x)})},400)}},{key:"animate_path",value:function(t,e,i){var n=i.map(function(t,i){return e[i]+","+t});this.elements_to_animate=this.elements_to_animate.concat(this.animator.path(t,n.join("L")))}},{key:"animate_units",value:function(t,e,i){var n=this,a=this.unit_args.type;t.svg_units.map(function(s,o){void 0!==e[o]&&void 0!==i[o]&&n.elements_to_animate.push(n.animator[a]({unit:s,array:t.svg_units,index:o},e[o],i[o],t.index,n.y.length))})}},{key:"animateXLines",value:function(t,e){var i=this;this.xAxisLines.map(function(n,a){i.elements_to_animate.push(i.animator.verticalLine(n,e[a],t[a]))})}},{key:"animateYLines",value:function(t,e){var i=this;this.yAxisLines.map(function(n,a){i.elements_to_animate.push(i.animator.horizontalLine(n,e[a],t[a]))})}},{key:"animateYAnnotations",value:function(){}},{key:"add_data_point",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.x.length,n=this.y.map(function(t){return{values:t.values}});n.map(function(e,n){e.values.splice(i,0,t[n])});var a=this.x.slice();a.splice(i,0,e),this.updateData(n,a)}},{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.updateData(e,i)}}},{key:"getDataPoint",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(n){var a=n.slice(0,n.length-1);e[a]=i[n][t]}),e.label=this.x[t],e}},{key:"updateCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.x.length&&(t=this.x.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{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.length).fill(9999),this.y.map(function(e){e.y_tops=e.values.map(function(e){return a(t.zero_line-e*t.multiplier)}),e.y_tops.map(function(e,i){e0}),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 n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"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,n){var a=t.create("div",{className:"progress-bar",inside:e.percentage_bar,styles:{background:e.colors[n],width:100*i/e.grand_total+"%"}});e.slices.push(a)})}},{key:"bind_tooltip",value:function(){var t=this;this.slices.map(function(i,n){i.addEventListener("mouseenter",function(){var a=e(t.chart_wrapper),s=e(i),o=s.left-a.left+i.offsetWidth/2,r=s.top-a.top-6,l=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[n]:t.labels[n])+": ",h=(100*t.slice_totals[n]/t.grand_total).toFixed(1);t.tip.set_values(o,r,l,h+"%"),t.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(n,a){n&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}]),n}(ht),ft=Math.PI/180,vt=function(i){function n(t){R(this,n);var e=G(this,(n.__proto__||Object.getPrototypeOf(n)).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 J(n,i),X(n,[{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 n=0;return t.data.datasets.map(function(t){n+=t.values[i]}),[n,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 n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"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,n=this.centerY,a=this.radius,s=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"make_graph_components",value:function(t){var e=this,i=this.radius,a=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var o=180-this.startAngle;this.slice_totals.map(function(r,l){var h=o,u=r/e.grand_total*360,c=a?-u:u,p=o+=c,_=n.getPositionByAngle(h,i),d=n.getPositionByAngle(p,i),f=t&&s[l],v=void 0,y=void 0;t?(v=f?f.startPosition:_,y=f?f.endPosition:_):(v=_,y=d);var m=e.makeArcPath(v,y),x=g(m,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.draw_area.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:_,endPosition:d,value:r,total:e.grand_total,startAngle:h,endAngle:p,angle:c}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(_,d)},650,"easein",null,{d:m}])}),t&&L(this.chart_wrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var e=this.radius,i=this.hoverRadio,a=n.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+a.x*i+"px,"+a.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,i,n,a){if(t){var s=this.colors[i];if(n){P(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=z(s,50);var o=e(this.svg),r=a.pageX-o.left+10,l=a.pageY-o.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(r,l,h,u+"%"),this.tip.show_tip()}else P(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=s}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,n=this.curActiveSlice,a=0;a0?this.formatted_labels:this.labels;this.legend_totals.map(function(n,a){var s=e.colors[a];n&&(t.create("div",{className:"stats",inside:e.stats_wrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ft)*e,y:Math.cos(t*ft)*e}}}]),n}(ht),yt=function(t){function e(t){var i=t.start,n=void 0===i?"":i,a=t.domain,s=void 0===a?"":a,o=t.subdomain,r=void 0===o?"":o,l=t.data,h=void 0===l?{}:l,u=t.discrete_domains,c=void 0===u?0:u,p=t.count_label,_=void 0===p?"":p,d=t.legend_colors,f=void 0===d?[]:d;R(this,e);var v=G(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=r,v.data=h,v.discrete_domains=c,v.count_label=_;var y=new Date;return v.start=n||B(y,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 J(e,t),X(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){E(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()&&B(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&B(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=W(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=S(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;ii)break;f.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=f}return[s,n]}},{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 n=k("y-value-text",e+12,10,t.month_names[t.months[i]].substring(0,3));t.domain_label_group.appendChild(n)})}},{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"),n=e.target.getAttribute("data-date").split("-"),a=t.month_names[parseInt(n[1])-1].substring(0,3),s=t.chart_wrapper.getBoundingClientRect(),o=e.target.getBoundingClientRect(),r=parseInt(e.target.getAttribute("width")),l=o.left-s.left+(r+2)/2,h=o.top-s.top-(r+2)/2,u=i+" "+t.count_label,c=" on "+a+" "+n[0]+", "+n[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}(ht),gt={line:pt,bar:ct,scatter:_t,percentage:dt,heatmap:yt,pie:vt},mt=function t(e){return R(this,t),I(e.type,arguments[0])};return mt}(); diff --git a/src/js/charts/AxisChart.js b/src/js/charts/AxisChart.js index 7c8ef72..825fcf3 100644 --- a/src/js/charts/AxisChart.js +++ b/src/js/charts/AxisChart.js @@ -2,9 +2,9 @@ import { offset } from '../utils/dom'; import { UnitRenderer, makeXLine, makeYLine } from '../utils/draw'; import { equilizeNoOfElements, getXLineProps, getYLineProps } from '../utils/draw-utils'; import { Animator } from '../utils/animate'; -import { runSVGAnimation } from '../utils/animation'; +import { runSMILAnimation } from '../utils/animation'; import { calcIntervals } from '../utils/intervals'; -import { floatTwo, arraysEqual, getStringWidth } from '../utils/helpers'; +import { floatTwo, getStringWidth } from '../utils/helpers'; import BaseChart from './BaseChart'; export default class AxisChart extends BaseChart { @@ -144,7 +144,8 @@ export default class AxisChart extends BaseChart { } makeXLines(positions, values) { - let [start_at, height, text_start_at, axis_line_class] = getXLineProps(this.height, this.x_axis_mode); + let [start_at, height, text_start_at, + axis_line_class] = getXLineProps(this.height, this.x_axis_mode); this.x_axis_group.setAttribute('transform', `translate(0,${start_at})`); let char_width = 8; @@ -184,8 +185,8 @@ export default class AxisChart extends BaseChart { } makeYLines(positions, values) { - let [width, text_end_at, axis_line_class, start_at] = getYLineProps( - this.width, this.y_axis_mode); + let [width, text_end_at, axis_line_class, + start_at] = getYLineProps(this.width, this.y_axis_mode); this.yAxisLines = []; this.y_axis_group.textContent = ''; @@ -205,25 +206,6 @@ export default class AxisChart extends BaseChart { }); } - // make_y_specifics(positions, value_objs) { - // this.specific_y_group.textContent = ''; - // value_objs.map((d, i) => { - // this.specific_y_group.appendChild( - // makeYLine( - // 0, - // this.width, - // this.width + 5, - // d.title.toUpperCase(), - // 'specific-value', - // 'specific-value', - // positions[i], - // false, - // d.line_type - // ) - // ); - // }); - // } - draw_graph(init=false) { if(this.raw_chart_args.hasOwnProperty("init") && !this.raw_chart_args.init) { this.y.map((d, i) => { @@ -367,7 +349,6 @@ export default class AxisChart extends BaseChart { if(!new_x) { new_x = this.x; } - this.elements_to_animate = []; this.updating = true; this.old_x_values = this.x.slice(); @@ -390,72 +371,55 @@ export default class AxisChart extends BaseChart { this.animate_graphs(); - // Trigger animation with the animatable elements in this.elements_to_animate - this.run_animation(); - this.updating = false; } - run_animation() { - let anim_svg = runSVGAnimation(this.svg, this.elements_to_animate); - - if(this.svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(this.svg); - this.chart_wrapper.appendChild(anim_svg); - - } - - // Replace the new svg (data has long been replaced) - setTimeout(() => { - if(anim_svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(anim_svg); - this.chart_wrapper.appendChild(this.svg); - } - }, 250); - } - animate_graphs() { + this.elements_to_animate = []; + // Pre-prep, equilize no of positions between old and new + let [old_x, new_x] = equilizeNoOfElements( + this.x_old_axis_positions.slice(), + this.x_axis_positions.slice() + ); + + let [oldYAxis, newYAxis] = equilizeNoOfElements( + this.oldYAxisPositions.slice(), + this.yAxisPositions.slice() + ); + + let newXValues = this.x.slice(); + let newYValues = this.y_axis_values.slice(); + + let extra_points = this.x_axis_positions.slice().length - this.x_old_axis_positions.slice().length; + + if(extra_points > 0) { + this.makeXLines(old_x, newXValues); + } + // No Y extra check? + this.makeYLines(oldYAxis, newYValues); + + // Animation + if(extra_points !== 0) { + this.animateXLines(old_x, new_x); + } + this.animateYLines(oldYAxis, newYAxis); + this.y.map(d => { - // Pre-prep, equilize no of positions between old and new - let [old_x, new_x] = equilizeNoOfElements( - this.x_old_axis_positions.slice(), - this.x_axis_positions.slice() - ); let [old_y, new_y] = equilizeNoOfElements( this.old_y_axis_tops[d.index].slice(), d.y_tops.slice() ); - - let [oldYAxis, newYAxis] = equilizeNoOfElements( - this.oldYAxisPositions.slice(), - this.yAxisPositions.slice() - ); - - let newXValues = this.x.slice(); - let newYValues = this.y_axis_values.slice(); - - let extra_points = this.x_axis_positions.slice().length - this.x_old_axis_positions.slice().length; - if(extra_points > 0) { this.make_path && this.make_path(d, old_x, old_y, this.colors[d.index]); this.make_new_units_for_dataset(old_x, old_y, this.colors[d.index], d.index, this.y.length); - this.makeXLines(old_x, newXValues); - } - // No Y extra check? - this.makeYLines(oldYAxis, newYValues); - - if(!this.updating) { - // Animation - if(extra_points !== 0) { - this.animateXLines(old_x, new_x); - } - - d.path && this.animate_path(d, new_x, new_y); - this.animate_units(d, new_x, new_y); - this.animateYLines(oldYAxis, newYAxis); } + // Animation + d.path && this.animate_path(d, new_x, new_y); + this.animate_units(d, new_x, new_y); }); + runSMILAnimation(this.chart_wrapper, this.svg, this.elements_to_animate); + setTimeout(() => { this.y.map(d => { this.make_path && this.make_path(d, this.x_axis_positions, d.y_tops, this.colors[d.index]); @@ -471,7 +435,7 @@ export default class AxisChart extends BaseChart { animate_path(d, new_x, new_y) { const newPointsList = new_y.map((y, i) => (new_x[i] + ',' + y)); this.elements_to_animate = this.elements_to_animate - .concat(this.animator['path'](d, newPointsList.join("L"))); + .concat(this.animator.path(d, newPointsList.join("L"))); } animate_units(d, new_x, new_y) { @@ -491,32 +455,22 @@ export default class AxisChart extends BaseChart { animateXLines(oldX, newX) { this.xAxisLines.map((xLine, i) => { - this.elements_to_animate.push([ - {unit: xLine, array: [0], index: 0}, - {transform: `${ newX[i] }, 0`}, - 350, - "easein", - "translate", - {transform: `${ oldX[i] }, 0`} - ]); + this.elements_to_animate.push(this.animator.verticalLine( + xLine, newX[i], oldX[i] + )); }); } animateYLines(oldY, newY) { this.yAxisLines.map((yLine, i) => { - this.elements_to_animate.push([ - {unit: yLine, array: [0], index: 0}, - {transform: `0, ${ newY[i] }`}, - 350, - "easein", - "translate", - {transform: `0, ${ oldY[i] }`} - ]); + this.elements_to_animate.push(this.animator.horizontalLine( + yLine, newY[i], oldY[i] + )); }); } animateYAnnotations() { - + // } add_data_point(y_point, x_point, index=this.x.length) { diff --git a/src/js/charts/PieChart.js b/src/js/charts/PieChart.js index 95ef1a2..1d6498b 100644 --- a/src/js/charts/PieChart.js +++ b/src/js/charts/PieChart.js @@ -2,7 +2,7 @@ import BaseChart from './BaseChart'; import { $, offset } from '../utils/dom'; import { makePath } from '../utils/draw'; import { lightenDarkenColor } from '../utils/colors'; -import { runSVGAnimation, transform } from '../utils/animation'; +import { runSMILAnimation, transform } from '../utils/animation'; const ANGLE_RATIO = Math.PI / 180; const FULL_ANGLE = 360; @@ -118,30 +118,9 @@ export default class PieChart extends BaseChart { }); if(init){ - this.run_animation(); + runSMILAnimation(this.chart_wrapper, this.svg, this.elements_to_animate); } } - run_animation() { - // if(this.isAnimate) return ; - // this.isAnimate = true; - if(!this.elements_to_animate || this.elements_to_animate.length === 0) return; - let anim_svg = runSVGAnimation(this.svg, this.elements_to_animate); - - if(this.svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(this.svg); - this.chart_wrapper.appendChild(anim_svg); - - } - - // Replace the new svg (data has long been replaced) - setTimeout(() => { - // this.isAnimate = false; - if(anim_svg.parentNode == this.chart_wrapper) { - this.chart_wrapper.removeChild(anim_svg); - this.chart_wrapper.appendChild(this.svg); - } - }, 650); - } calTranslateByAngle(property){ const{radius,hoverRadio} = this; diff --git a/src/js/utils/animate.js b/src/js/utils/animate.js index 4587f02..5fa6804 100644 --- a/src/js/utils/animate.js +++ b/src/js/utils/animate.js @@ -1,5 +1,12 @@ import { getBarHeightAndYAttr } from './draw-utils'; +const UNIT_ANIM_DUR = 350; +const PATH_ANIM_DUR = 350; +const MARKER_LINE_ANIM_DUR = 350; +export const REPLACE_ALL_NEW_DUR = 250; + +const STD_EASING = 'easein'; + export var Animator = (function() { var Animator = function(totalHeight, totalWidth, zeroLine, avgUnitWidth) { // constants @@ -19,18 +26,18 @@ export var Animator = (function() { x = start + (width * index); - return [barObj, {width: width, height: height, x: x, y: y}, 350, "easein"]; - // bar.animate({height: args.newHeight, y: yTop}, 350, mina.easein); + return [barObj, {width: width, height: height, x: x, y: y}, UNIT_ANIM_DUR, STD_EASING]; + // bar.animate({height: args.newHeight, y: yTop}, UNIT_ANIM_DUR, mina.easein); }, dot: function(dotObj, x, yTop) { - return [dotObj, {cx: x, cy: yTop}, 350, "easein"]; - // dot.animate({cy: yTop}, 350, mina.easein); + return [dotObj, {cx: x, cy: yTop}, UNIT_ANIM_DUR, STD_EASING]; + // dot.animate({cy: yTop}, UNIT_ANIM_DUR, mina.easein); }, path: function(d, pathStr) { let pathComponents = []; - const animPath = [{unit: d.path, object: d, key: 'path'}, {d:"M"+pathStr}, 350, "easein"]; + const animPath = [{unit: d.path, object: d, key: 'path'}, {d:"M"+pathStr}, PATH_ANIM_DUR, STD_EASING]; pathComponents.push(animPath); if(d.regionPath) { @@ -40,14 +47,36 @@ export var Animator = (function() { const animRegion = [ {unit: d.regionPath, object: d, key: 'regionPath'}, {d:"M" + regStartPt + pathStr + regEndPt}, - 350, - "easein" + PATH_ANIM_DUR, + STD_EASING ]; pathComponents.push(animRegion); } return pathComponents; }, + + verticalLine: function(xLine, newX, oldX) { + return [ + {unit: xLine, array: [0], index: 0}, + {transform: `${ newX }, 0`}, + MARKER_LINE_ANIM_DUR, + STD_EASING, + "translate", + {transform: `${ oldX }, 0`} + ]; + }, + + horizontalLine: function(yLine, newY, oldY) { + return [ + {unit: yLine, array: [0], index: 0}, + {transform: `0, ${ newY }`}, + MARKER_LINE_ANIM_DUR, + STD_EASING, + "translate", + {transform: `0, ${ oldY }`} + ]; + } }; return Animator; diff --git a/src/js/utils/animation.js b/src/js/utils/animation.js index c3ef2ae..aa4d2c6 100644 --- a/src/js/utils/animation.js +++ b/src/js/utils/animation.js @@ -1,5 +1,7 @@ // Leveraging SMIL Animations +import { REPLACE_ALL_NEW_DUR } from './animate'; + const EASING = { ease: "0.25 0.1 0.25 1", linear: "0 0 1 1", @@ -9,7 +11,7 @@ const EASING = { easeinout: "0.42 0 0.58 1" }; -function animateSVG(element, props, dur, easingType="linear", type=undefined, oldValues={}) { +function animateSVGElement(element, props, dur, easingType="linear", type=undefined, oldValues={}) { let animElement = element.cloneNode(true); let newElement = element.cloneNode(true); @@ -65,7 +67,7 @@ export function transform(element, style) { // eslint-disable-line no-unused-var element.style.oTransform = style; } -export function runSVGAnimation(svgContainer, elements) { +function animateSVG(svgContainer, elements) { let newElements = []; let animElements = []; @@ -76,7 +78,7 @@ export function runSVGAnimation(svgContainer, elements) { let animElement, newElement; element[0] = obj.unit; - [animElement, newElement] = animateSVG(...element); + [animElement, newElement] = animateSVGElement(...element); newElements.push(newElement); animElements.push([animElement, parent]); @@ -99,3 +101,22 @@ export function runSVGAnimation(svgContainer, elements) { return animSvg; } + +export function runSMILAnimation(parent, svgElement, elementsToAnimate) { + if(elementsToAnimate.length === 0) return; + + let animSvgElement = animateSVG(svgElement, elementsToAnimate); + if(svgElement.parentNode == parent) { + parent.removeChild(svgElement); + parent.appendChild(animSvgElement); + + } + + // Replace the new svgElement (data has already been replaced) + setTimeout(() => { + if(animSvgElement.parentNode == parent) { + parent.removeChild(animSvgElement); + parent.appendChild(svgElement); + } + }, REPLACE_ALL_NEW_DUR); +}