diff --git a/dist/frappe-charts.esm.js b/dist/frappe-charts.esm.js index d8ea2ce..2986072 100644 --- a/dist/frappe-charts.esm.js +++ b/dist/frappe-charts.esm.js @@ -234,7 +234,7 @@ function getStringWidth(string, charWidth) { function getBarHeightAndYAttr(yTop, zeroLine) { let height, y; - if (yTop < zeroLine) { + if (yTop <= zeroLine) { height = zeroLine - yTop; y = yTop; } else { @@ -286,13 +286,14 @@ const REPLACE_ALL_NEW_DUR = 250; const STD_EASING = 'easein'; function translate(unit, oldCoord, newCoord, duration) { + let old = typeof oldCoord === 'string' ? oldCoord : oldCoord.join(', '); return [ unit, {transform: newCoord.join(', ')}, duration, STD_EASING, "translate", - {transform: oldCoord.join(', ')} + {transform: old} ]; } @@ -319,6 +320,42 @@ function animateRegion(rectGroup, newY1, newY2, oldY2) { return [rectAnim, groupAnim]; } +function animateBar(bar, x, yTop, width, index=0, meta={}) { + let [height, y] = getBarHeightAndYAttr(yTop, meta.zeroLine); + if(bar.nodeName !== 'rect') { + let rect = bar.childNodes[0]; + let rectAnim = [ + rect, + {width: width, height: height}, + UNIT_ANIM_DUR, + STD_EASING + ]; + + let old = bar.getAttribute("transform").split("(")[1].slice(0, -1); + let groupAnim = translate(bar, old, [x, y], MARKER_LINE_ANIM_DUR); + return [rectAnim, groupAnim]; + } else { + return [[bar, {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); +} + +/* + + + + + + + + + + + filter: url(#glow); + fill: #fff; + +*/ + const AXIS_TICK_LENGTH = 6; const LABEL_MARGIN = 4; const FONT_SIZE = 10; @@ -383,13 +420,7 @@ function makeSVGGroup(parent, className, transform='') { }); } -function wrapInSVGGroup(elements, className='') { - let g = createSVG('g', { - className: className - }); - elements.forEach(e => g.appendChild(e)); - return g; -} + function makePath(pathStr, className='', stroke='none', fill='none') { return createSVG('path', { @@ -627,31 +658,40 @@ function yRegion(y1, y2, width, label) { function datasetBar(x, yTop, width, color, label='', index=0, offset=0, meta={}) { let [height, y] = getBarHeightAndYAttr(yTop, meta.zeroLine); // console.log(yTop, meta.zeroLine, y, offset); + y -= offset; let rect = createSVG('rect', { className: `bar mini`, style: `fill: ${color}`, 'data-point-index': index, - x: x - meta.barsWidth/2, - y: y - offset, + x: x, + y: y, width: width, - height: height || meta.minHeight + height: height || meta.minHeight // TODO: correct y for positive min height }); if(!label && !label.length) { return rect; } else { + rect.setAttribute('y', 0); + rect.setAttribute('x', 0); let text = createSVG('text', { className: 'data-point-value', - x: x, - y: y - offset, + x: width/2, + y: 0, dy: (FONT_SIZE / 2 * -1) + 'px', 'font-size': FONT_SIZE + 'px', 'text-anchor': 'middle', innerHTML: label }); - return wrapInSVGGroup([rect, text]); + let group = createSVG('g', { + transform: `translate(${x}, ${y})` + }); + group.appendChild(rect); + group.appendChild(text); + + return group; } } @@ -1227,11 +1267,11 @@ function zeroDataPrep(realData) { let zeroArray = new Array(datasetLength).fill(0); let zeroData = { - labels: realData.labels, + labels: realData.labels.slice(0, -1), datasets: realData.datasets.map(d => { return { name: '', - values: zeroArray, + values: zeroArray.slice(0, -1), chartType: d.chartType } }), @@ -1261,14 +1301,12 @@ class ChartComponent$1 { getData, makeElements, - postMake, animateElements }) { this.layerTransform = layerTransform; this.constants = constants; this.makeElements = makeElements; - this.postMake = postMake; this.getData = getData; this.animateElements = animateElements; @@ -1291,9 +1329,7 @@ class ChartComponent$1 { } make() { - this.preMake && this.preMake(); this.render(this.data); - this.postMake && this.postMake(); this.oldData = this.data; } @@ -1331,8 +1367,8 @@ let componentConfigs = { }, animateElements(newData) { - let newPos = newData.positions; - let newLabels = newData.labels; + let newPos = newData.positions; + let newLabels = newData.labels; let oldPos = this.oldData.positions; let oldLabels = this.oldData.labels; @@ -1362,8 +1398,8 @@ let componentConfigs = { }, animateElements(newData) { - let newPos = newData.positions; - let newLabels = newData.labels; + let newPos = newData.positions; + let newLabels = newData.labels; let oldPos = this.oldData.positions; let oldLabels = this.oldData.labels; @@ -1394,8 +1430,8 @@ let componentConfigs = { animateElements(newData) { [this.oldData, newData] = equilizeNoOfElements(this.oldData, newData); - let newPos = newData.map(d => d.position); - let newLabels = newData.map(d => d.label); + let newPos = newData.map(d => d.position); + let newLabels = newData.map(d => d.label); let oldPos = this.oldData.map(d => d.position); let oldLabels = this.oldData.map(d => d.label); @@ -1426,9 +1462,9 @@ let componentConfigs = { animateElements(newData) { [this.oldData, newData] = equilizeNoOfElements(this.oldData, newData); - let newPos = newData.map(d => d.end); - let newLabels = newData.map(d => d.label); - let newStarts = newData.map(d => d.start); + let newPos = newData.map(d => d.end); + let newLabels = newData.map(d => d.label); + let newStarts = newData.map(d => d.start); let oldPos = this.oldData.map(d => d.end); let oldLabels = this.oldData.map(d => d.label); @@ -1459,57 +1495,67 @@ let componentConfigs = { makeElements(data) { let c = this.constants; return data.yPositions.map((y, j) => { - // console.log(data.cumulativeYPos, data.cumulativeYPos[j]); return datasetBar( data.xPositions[j], y, - c.barWidth, + data.barWidth, c.color, (c.valuesOverPoints ? (c.stacked ? data.cumulativeYs[j] : data.values[j]) : ''), j, y - (c.stacked ? data.cumulativeYPos[j] : y), { - zeroLine: c.zeroLine, - barsWidth: c.barsWidth, + zeroLine: data.zeroLine, + barsWidth: data.barsWidth, minHeight: c.minHeight } ) }); }, - postMake() { - if((!this.constants.stacked)) { - this.layer.setAttribute('transform', - `translate(${this.constants.width * this.constants.index}, 0)`); - } - }, animateElements(newData) { - // [this.oldData, newData] = equilizeNoOfElements(this.oldData, newData); + let c = this.constants; + + let newXPos = newData.xPositions; + let newYPos = newData.yPositions; + let newCYPos = newData.cumulativeYPos; + let newValues = newData.values; + let newCYs = newData.cumulativeYs; + - // let newPos = newData.map(d => d.end); - // let newLabels = newData.map(d => d.label); - // let newStarts = newData.map(d => d.start); + let oldXPos = this.oldData.xPositions; + let oldYPos = this.oldData.yPositions; + let oldCYPos = this.oldData.cumulativeYPos; + let oldValues = this.oldData.values; + let oldCYs = this.oldData.cumulativeYs; - // let oldPos = this.oldData.map(d => d.end); - // let oldLabels = this.oldData.map(d => d.label); - // let oldStarts = this.oldData.map(d => d.start); + [oldXPos, newXPos] = equilizeNoOfElements(oldXPos, newXPos); + [oldYPos, newYPos] = equilizeNoOfElements(oldYPos, newYPos); + [oldCYPos, newCYPos] = equilizeNoOfElements(oldCYPos, newCYPos); + [oldValues, newValues] = equilizeNoOfElements(oldValues, newValues); + [oldCYs, newCYs] = equilizeNoOfElements(oldCYs, newCYs); - // this.render(oldPos.map((pos, i) => { - // return { - // start: oldStarts[i], - // end: oldPos[i], - // label: newLabels[i] - // } - // })); + this.render({ + xPositions: oldXPos, + yPositions: oldYPos, + cumulativeYPos: oldCYPos, + + values: newValues, + cumulativeYs: newCYs, + + zeroLine: this.oldData.zeroLine, + barsWidth: this.oldData.barsWidth, + barWidth: this.oldData.barWidth, + }); - // let animateElements = []; + let animateElements = []; - // this.store.map((rectGroup, i) => { - // animateElements = animateElements.concat(animateRegion( - // rectGroup, newStarts[i], newPos[i], oldPos[i] - // )); - // }); + this.store.map((bar, i) => { + animateElements = animateElements.concat(animateBar( + bar, newXPos[i], newYPos[i], newData.barWidth, c.index, + {zeroLine: newData.zeroLine} + )); + }); - // return animateElements; + return animateElements; } }, @@ -1519,7 +1565,8 @@ let componentConfigs = { }; function getComponent(name, constants, getData) { - let config = componentConfigs[name]; + let keys = Object.keys(componentConfigs).filter(k => name.includes(k)); + let config = componentConfigs[keys[0]]; Object.assign(config, { constants: constants, getData: getData @@ -1891,9 +1938,6 @@ class AxisChart extends BaseChart { } initComponents() { - let s = this.state; - // console.log('this.state', Object.assign({}, this.state)); - // console.log('this.state', this.state); this.componentConfigs = [ [ 'yAxis', @@ -1936,14 +1980,11 @@ class AxisChart extends BaseChart { // console.log('barDatasets', barDatasets, this.state.datasets); // Bars - let spaceRatio = this.barOptions.spaceRatio || BAR_CHART_SPACE_RATIO; - let barsWidth = s.unitWidth * (1 - spaceRatio); - let barWidth = barsWidth/(this.barOptions.stacked ? 1 : barDatasets.length); let barsConfigs = barDatasets.map(d => { let index = d.index; return [ - 'barGraph', + 'barGraph' + '-' + d.index, { index: index, color: this.colors[index], @@ -1951,20 +1992,28 @@ class AxisChart extends BaseChart { // same for all datasets valuesOverPoints: this.valuesOverPoints, minHeight: this.height * MIN_BAR_PERCENT_HEIGHT, - barsWidth: barsWidth, - barWidth: barWidth, - zeroLine: s.yAxis.zeroLine }, function() { let s = this.state; let d = s.datasets[index]; + + let spaceRatio = this.barOptions.spaceRatio || BAR_CHART_SPACE_RATIO; + let barsWidth = s.unitWidth * (1 - spaceRatio); + let barWidth = barsWidth/(this.barOptions.stacked ? 1 : barDatasets.length); + + let xPositions = s.xAxis.positions.map(x => x - barsWidth/2 + barWidth * index); + return { - xPositions: s.xAxis.positions, + xPositions: xPositions, yPositions: d.yPositions, cumulativeYPos: d.cumulativeYPos, values: d.values, - cumulativeYs: d.cumulativeYs + cumulativeYs: d.cumulativeYs, + + zeroLine: s.yAxis.zeroLine, + barsWidth: barsWidth, + barWidth: barWidth, }; }.bind(this) ]; diff --git a/dist/frappe-charts.min.cjs.js b/dist/frappe-charts.min.cjs.js index d83fd52..5145001 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 a=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");return i.type="text/css",a.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function getOffset(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),a=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-a}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];a||(a=i?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(a);return t=i?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var a=void 0,i=void 0;return t2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return a>0?t=fillArray(t,a):e=fillArray(e,a),[t,e]}function translate(t,e,a,i){return[t,{transform:a.join(", ")},i,STD_EASING,"translate",{transform:e.join(", ")}]}function translateVertLine(t,e,a){return translate(t,[a,0],[e,0],MARKER_LINE_ANIM_DUR)}function translateHoriLine(t,e,a){return translate(t,[0,a],[0,e],MARKER_LINE_ANIM_DUR)}function animateRegion(t,e,a,i){var n=e-a,s=t.childNodes[0];return[[s,{height:n,"stroke-dasharray":s.getAttribute("width")+", "+n},MARKER_LINE_ANIM_DUR,STD_EASING],translate(t,[0,i],[0,a],MARKER_LINE_ANIM_DUR)]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var a=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in e){var n=e[i];if("inside"===i)$$2(n).appendChild(a);else if("around"===i){var s=$$2(n);s.parentNode.insertBefore(a,s),a.appendChild(s)}else"styles"===i?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){a.style[t]=n[t]}):("className"===i&&(i="class"),"innerHTML"===i?a.textContent=n:a.setAttribute(i,n))}return a}function makeSVGContainer(t,e,a,i){return createSVG("svg",{className:e,inside:t,width:a,height:i})}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 wrapInSVGGroup(t){var e=createSVG("g",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""});return t.forEach(function(t){return e.appendChild(t)}),e}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 makeHeatSquare(t,e,a,i){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:a,width:i,height:i,fill:1};return Object.keys(n).map(function(t){s[t]=n[t]}),createSVG("rect",s)}function makeText(t,e,a,i){return createSVG("text",{className:t,x:e,y:a,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:i})}function makeVertLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR);var s=createSVG("line",{className:"line-vertical "+n.className,x1:0,x2:0,y1:a,y2:i,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:a>i?a+LABEL_MARGIN:a-LABEL_MARGIN-FONT_SIZE,dy:FONT_SIZE+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:e}),o=createSVG("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function makeHoriLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR),n.lineType||(n.lineType="");var s=createSVG("line",{className:"line-horizontal "+n.className+("dashed"===n.lineType?"dashed":""),x1:a,x2:i,y1:0,y2:0,styles:{stroke:n.stroke}}),r=createSVG("text",{x:a3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=-1*AXIS_TICK_LENGTH,s="span"===i.mode?a+AXIS_TICK_LENGTH:0;return"tick"===i.mode&&"right"===i.pos&&(n=a+AXIS_TICK_LENGTH,s=a),n+=i.offset,s+=i.offset,makeHoriLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function xLine(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=a+AXIS_TICK_LENGTH,s="span"===i.mode?-1*AXIS_TICK_LENGTH:a;return"tick"===i.mode&&"top"===i.pos&&(n=-1*AXIS_TICK_LENGTH,s=0),makeVertLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function yMarker(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=createSVG("text",{className:"chart-label",x:a-getStringWidth(e,5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),s=makeHoriLine(t,"",0,a,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return s.appendChild(n),s}function yRegion(t,e,a,i){var n=t-e,s=createSVG("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:BASE_LINE_COLOR,"stroke-dasharray":a+", "+n},x:0,y:0,width:a,height:n}),r=createSVG("text",{className:"chart-label",x:a-getStringWidth(i,4.5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{transform:"translate(0, "+e+")"});return o.appendChild(s),o.appendChild(r),o}function datasetBar(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:{},l=getBarHeightAndYAttr(e,o.zeroLine),h=slicedToArray(l,2),c=h[0],u=h[1],p=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":s,x:t-o.barsWidth/2,y:u-r,width:a,height:c||o.minHeight});return n||n.length?wrapInSVGGroup([p,createSVG("text",{className:"data-point-value",x:t,y:u-r,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:n})]):p}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var a=getColor(t),i=!1;"#"==a[0]&&(a=a.slice(1),i=!0);var n=parseInt(a,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(i?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,a){if(t!==e){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var i=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:a.parent,title:a.title,data:a.data,type:t,height:a.height,colors:i?a.colors:void 0})}}function animateSVGElement(t,e,a){var i=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 c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:a/1e3+"s",values:c+";"+u,keySplines:EASING[i],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),n?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}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 a=[],i=[];e.map(function(t){var e=t[0],n=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],a.push(r),i.push([s,n]),n.replaceChild(s,e)});var n=t.cloneNode(!0);return i.map(function(t,i){t[1].replaceChild(a[i],t[0]),e[i][0]=a[i]}),n}function runSMILAnimation(t,e,a){if(0!==a.length){var i=animateSVG(e,a);e.parentNode==t&&(t.removeChild(e),t.appendChild(i)),setTimeout(function(){i.parentNode==t&&(t.removeChild(i),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function dataPrep(t,e){t.labels=t.labels||[];var a=t.labels.length,i=t.datasets,n=new Array(a).fill(0);return i||(i=[{values:n}]),i.map(function(t,i){if(t.values){var s=t.values;s=(s=s.map(function(t){return isNaN(t)?0:t})).length>a?s.slice(0,a):fillArray(s,a-s.length,0)}else t.values=n;t.chartType||(AXIS_DATASET_CHART_TYPES.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(function(t){if(t.end0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var a=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,a)),a]}function getChartRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=Math.ceil(t),i=Math.floor(e),n=a-i,s=n,r=1;n>5&&(n%2!=0&&(n=++a-i),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(i+r*l);return o}function getChartIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=normalize(t),i=slicedToArray(a,2),n=i[0],s=i[1],r=e?e/Math.pow(10,s):0,o=getChartRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcChartIntervals(t){function e(t,e){for(var a=getChartIntervals(t),i=a[1]-a[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],i=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(i>=0&&n>=0)normalize(i)[1],s=a?getChartIntervals(i,n):getChartIntervals(i);else if(i>0&&n<0){var r=Math.abs(n);i>=r?(normalize(i)[1],s=e(i,r)):(normalize(r)[1],s=e(r,i).map(function(t){return-1*t}))}else if(i<=0&&n<=0){var o=Math.abs(n),l=Math.abs(i);normalize(o)[1],s=(s=a?getChartIntervals(o,l):getChartIntervals(o)).reverse().map(function(t){return-1*t})}return s}function getZeroIndex(t){var e=getIntervalSize(t);return t.indexOf(0)>=0?t.indexOf(0):t[0]>0?-1*t[0]/e:-1*t[t.length-1]/e+(t.length-1)}function getIntervalSize(t){return t[1]-t[0]}function getValueRange(t){return t[t.length-1]-t[0]}function scale(t,e){return floatTwo(e.zeroLine-t*e.scaleMultiplier)}function calcDistribution(t,e){for(var a=Math.max.apply(Math,toConsumableArray(t)),i=1/(e-1),n=[],s=0;s9?"":"0")+e,(a>9?"":"0")+a,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"line"===t?(e.type="line",new AxisChart(e)):"bar"===t?(e.type="bar",new AxisChart(e)):chartTypes[t]?new chartTypes[t](e):void console.error("Undefined chart type: "+t)}__$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{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path,.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .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 a(t,e){return new Promise(function(a,n){var o={key:t,arg:e,resolve:a,reject:n,next:null};r?r=r.next=o:(s=r=o,i(t,e))})}function i(a,s){try{var r=e[a](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){i("next",t)},function(t){i("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)?i(s.key,s.arg):r=null}var s,r;this._invoke=a,"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 a=0;a\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,a){var i=t.colors[a]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+i},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,a=this.container.querySelector(".svg-pointer");if(this.left<0)a.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var i="calc(50% + "+(this.left-e)+"px)";a.style.left=i,this.left=e}else a.style.left="50%"}},{key:"set_values",value:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=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=a,this.title_value=i,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}(),UNIT_ANIM_DUR=350,PATH_ANIM_DUR=350,MARKER_LINE_ANIM_DUR=UNIT_ANIM_DUR,REPLACE_ALL_NEW_DUR=250,STD_EASING="easein",AXIS_TICK_LENGTH=6,LABEL_MARGIN=4,FONT_SIZE=10,BASE_LINE_COLOR="#dadada",AxisChartRenderer=function(){function t(e){classCallCheck(this,t),this.refreshState(e)}return createClass(t,[{key:"refreshState",value:function(t){this.totalHeight=t.totalHeight,this.totalWidth=t.totalWidth,this.zeroLine=t.zeroLine,this.unitWidth=t.unitWidth,this.xAxisMode=t.xAxisMode,this.yAxisMode=t.yAxisMode}},{key:"setZeroline",value:function(t){this.zeroLine=t}},{key:"xMarker",value:function(){}},{key:"xRegion",value:function(){return createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"animatebar",value:function(t,e,a,i,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(a,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*i,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,a){return[t,{cx:e,cy:a},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var a=[],i=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];if(a.push(i),t[1]){var n="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+n+e+s},PATH_ANIM_DUR,STD_EASING];a.push(r)}return a}}]),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:[]},EASING={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},BaseChart=function(){function t(e){var a=e.height,i=void 0===a?240:a,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type),u=void 0===c?"":c,p=e.parent,d=e.data;classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof p?document.querySelector(p):p,this.title=s,this.subtitle=o,this.argHeight=i,this.type=u,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.realData=this.prepareData(d),this.data=this.prepareFirstData(this.realData),this.colors=[],this.config={},this.state={},this.options={},this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){var e=this;this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:1},this.setMargins(),window.addEventListener("resize",function(){return e.draw()}),window.addEventListener("orientationchange",function(){return e.draw()})}},{key:"setColors",value:function(){var t=this.rawChartArgs,e="percentage"===t.type||"pie"===t.type?t.data.labels:t.data.datasets;!t.colors||e&&t.colors.length'+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.chartWrapper=this.container.querySelector(".frappe-chart"),this.statsWrapper=this.container.querySelector(".graph-stats-container")}},{key:"makeTooltip",value:function(){this.tip=new SvgTip({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.makeChartArea(),this.calc(),this.initComponents(),this.setupComponents(),this.components.forEach(function(e){return e.setup(t.drawArea)}),this.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),e&&(this.data=this.realData,setTimeout(function(){t.update()},1e3))}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data;this.data=this.prepareData(t),this.calc(),this.render()}},{key:"prepareData",value:function(){}},{key:"calc",value:function(){}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.components,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=[];t.forEach(function(t){a=a.concat(t.update(e))}),a.length>0&&runSMILAnimation(this.chartWrapper,this.svg,a)}},{key:"makeChartArea",value:function(){this.svg&&this.chartWrapper.removeChild(this.svg),this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"renderLegend",value:function(){}},{key:"setupNavigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isNavigable||(this.makeOverlay(),e&&(this.bindOverlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chartWrapper)&&("37"==(e=e||window.event).keyCode?t.onLeftArrow():"39"==e.keyCode?t.onRightArrow():"38"==e.keyCode?t.onUpArrow():"40"==e.keyCode?t.onDownArrow():"13"==e.keyCode&&t.onEnterKey())})))}},{key:"makeOverlay",value:function(){}},{key:"bindOverlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"onLeftArrow",value:function(){}},{key:"onRightArrow",value:function(){}},{key:"onUpArrow",value:function(){}},{key:"onDownArrow",value:function(){}},{key:"onEnterKey",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"setCurrentDataPoint",value:function(t){}},{key:"updateDataset",value:function(t,e){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"updateDatasets",value:function(t){}},{key:"updateDataPoint",value:function(t){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,MIN_BAR_PERCENT_HEIGHT=.01,DEFAULT_AXIS_CHART_TYPE="line",AXIS_DATASET_CHART_TYPES=["line","bar"],BAR_CHART_SPACE_RATIO=.5,ChartComponent$1=function(){function t(e){var a=e.layerClass,i=void 0===a?"":a,n=e.layerTransform,s=void 0===n?"":n,r=e.constants,o=e.getData,l=e.makeElements,h=e.postMake,c=e.animateElements;classCallCheck(this,t),this.layerTransform=s,this.constants=r,this.makeElements=l,this.postMake=h,this.getData=o,this.animateElements=c,this.store=[],this.layerClass=i,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}return createClass(t,[{key:"refresh",value:function(t){this.data=t||this.getData()}},{key:"setup",value:function(t){this.layer=makeSVGGroup(t,this.layerClass,this.layerTransform)}},{key:"make",value:function(){this.preMake&&this.preMake(),this.render(this.data),this.postMake&&this.postMake(),this.oldData=this.data}},{key:"render",value:function(t){var e=this;this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(function(t){e.layer.appendChild(t)})}},{key:"update",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refresh();var a=[];return e&&(a=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),a}}]),t}(),componentConfigs={yAxis:{layerClass:"y axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return yLine(a,t.labels[i],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateHoriLine(t,e[a],i[a])})}},xAxis:{layerClass:"x axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return xLine(a,t.labels[i],e.constants.height,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateVertLine(t,e[a],i[a])})}},yMarkers:{layerClass:"y-markers",makeElements:function(t){var e=this;return t.map(function(t){return yMarker(t.position,t.label,e.constants.width,{pos:"right",mode:"span",lineType:"dashed"})})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.position}),n=t.map(function(t){return t.label}),s=this.oldData.map(function(t){return t.position});this.oldData.map(function(t){return t.label});return this.render(s.map(function(t,e){return{position:s[e],label:n[e]}})),this.store.map(function(t,e){return translateHoriLine(t,i[e],s[e])})}},yRegions:{layerClass:"y-regions",makeElements:function(t){var e=this;return t.map(function(t){return yRegion(t.start,t.end,e.constants.width,t.label)})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.end}),n=t.map(function(t){return t.label}),s=t.map(function(t){return t.start}),r=this.oldData.map(function(t){return t.end}),o=(this.oldData.map(function(t){return t.label}),this.oldData.map(function(t){return t.start}));this.render(r.map(function(t,e){return{start:o[e],end:r[e],label:n[e]}}));var l=[];return this.store.map(function(t,e){l=l.concat(animateRegion(t,s[e],i[e],r[e]))}),l}},barGraph:{layerClass:function(){return"dataset-units dataset-"+this.constants.index},makeElements:function(t){var e=this.constants;return t.yPositions.map(function(a,i){return datasetBar(t.xPositions[i],a,e.barWidth,e.color,e.valuesOverPoints?e.stacked?t.cumulativeYs[i]:t.values[i]:"",i,a-(e.stacked?t.cumulativeYPos[i]:a),{zeroLine:e.zeroLine,barsWidth:e.barsWidth,minHeight:e.minHeight})})},postMake:function(){this.constants.stacked||this.layer.setAttribute("transform","translate("+this.constants.width*this.constants.index+", 0)")},animateElements:function(t){}},lineGraph:{}},AxisChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.isSeries=t.isSeries,a.valuesOverPoints=t.valuesOverPoints,a.formatTooltipY=t.formatTooltipY,a.formatTooltipX=t.formatTooltipX,a.barOptions=t.barOptions||{},a.lineOptions=t.lineOptions||{},a.type=t.type||"line",a.xAxisMode=t.xAxisMode||"span",a.yAxisMode=t.yAxisMode||"span",a.zeroLine=a.height,a.setup(),a}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this),this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"prepareData",value:function(){return dataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data,this.type)}},{key:"prepareFirstData",value:function(){return zeroDataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data)}},{key:"calc",value:function(){this.calcXPositions(),this.calcYAxisParameters(this.getAllYValues(),"line"===this.type)}},{key:"calcXPositions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map(function(e,a){return floatTwo(t.xOffset+a*t.unitWidth)})}}},{key:"calcYAxisParameters",value:function(t){var e=calcChartIntervals(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"false"),a=this.height/getValueRange(e),i=getIntervalSize(e)*a,n=this.height-getZeroIndex(e)*i;this.state.yAxis={labels:e,positions:e.map(function(t){return n-t*a}),scaleMultiplier:a,zeroLine:n},this.calcYUnits(),this.calcYExtremes(),this.calcYRegions()}},{key:"calcYUnits",value:function(){var t=this.state,e=function(e){return e.map(function(e){return scale(e,t.yAxis)})};t.datasets=this.data.datasets.map(function(t,a){var i=t.values,n=t.cumulativeYs||[];return{name:t.name,index:a,chartType:t.chartType,values:i,yPositions:e(i),cumulativeYs:n,cumulativeYPos:e(n)}})}},{key:"calcYExtremes",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,a){e.yPositions.map(function(e,a){e0)for(var l=0;l0&&(t=getPaths(r,s,a.colors[e],a.config.heatline,a.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var p=n.map(function(t,e){return i[e]+","+t});a.elementsToAnimate=a.elementsToAnimate.concat(a.renderer.animatepath(t,p.join("L")))}})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var a=getOffset(t.chartWrapper),i=e.pageX-a.left-t.translateXLeft;e.pageY-a.top-t.translateY=0;s--){var r=a.xAxis.positions[s];if(t>r-a.unitWidth/2){var o=r+this.translateXLeft,l=a.yExtremes[s]+this.translateY,h=this.data.datasets.map(function(t,a){return{title:t.title,value:n?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[a]}});this.tip.set_values(o,l,i[s],"",h),this.tip.show_tip();break}}}}},{key:"getDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.current_index,e={index:t},a=this.y[0];return["svg_units","yUnitPositions","values"].map(function(i){var n=i.slice(0,i.length-1);e[n]=a[i][t]}),e.label=this.xAxis.labels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxis.labels.length&&(t=this.xAxis.labels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,a){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"addDataPoint",this).call(this,t,a,i),this.data.labels.splice(i,0,t),this.data.datasets.map(function(t,e){t.values.splice(i,0,a[e])}),this.update(this.data)}},{key:"removeDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.datasetLength-1;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"removeDataPoint",this).call(this,t),this.data.labels.splice(t,1),this.data.datasets.map(function(e){e.values.splice(t,1)}),this.update(this.data)}}]),e}(BaseChart),LineChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="line",Object.getPrototypeOf(a)!==e.prototype?possibleConstructorReturn(a):(a.setup(),a)}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"span",this.config.yAxisMode=t.yAxisMode||"span",this.config.dotRadius=t.dotRadius||4,this.config.heatline=t.heatline||0,this.config.regionFill=t.regionFill||0,this.config.showDots=t.showDots||1}},{key:"configUnits",value:function(){this.unitArgs={type:"dot",args:{radius:this.config.dotRadius}}}},{key:"setUnitWidthAndXOffset",value:function(){this.state.unitWidth=this.width/(this.state.datasetLength-1),this.state.xOffset=0}}]),e}(AxisChart),ScatterChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="scatter",t.dotRadius?a.dotRadius=t.dotRadius:a.dotRadius=8,a.setup(),a}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dotRadius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(LineChart),MultiAxisChart=function(t){function e(t){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return inherits(e,t),createClass(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this);var t=this.data.datasets.filter(function(t){return"left"===t.axisPosition}).length;this.translateXLeft=t*Y_AXIS_MARGIN||Y_AXIS_MARGIN,this.translateXRight=(this.data.datasets.length-t)*Y_AXIS_MARGIN||Y_AXIS_MARGIN}},{key:"prepareYAxis",value:function(){}},{key:"prepareData",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var a=0,i=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?a++:i++}})}},{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"tick",this.config.yAxisMode=t.yAxisMode||"span"}},{key:"configUnits",value:function(){this.unitArgs={type:"bar",args:{spaceWidth:this.state.unitWidth/2}}}},{key:"setYAxis",value:function(){var t=this;this.state.datasets.map(function(e){t.calcYAxisParameters(e.yAxis,e.values,"line"===t.unitType)})}},{key:"calcYUnits",value:function(){this.state.datasets.map(function(t){t.positions=t.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"renderConstants",value:function(){var t=this;this.state.datasets.map(function(e){var a="left"===e.yAxis.position?-1*e.yAxis.index*Y_AXIS_MARGIN:t.width+e.yAxis.index*Y_AXIS_MARGIN;t.renderer.xLine(a,"",{pos:"top",mode:"span",stroke:t.colors[i],className:"y-axis-guide"})})}},{key:"getYAxesComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"y axis y-axis-"+a,make:function(){var e=t.state.datasets[a].yAxis;t.renderer.setZeroline(e.zeroline);var i={pos:e.position,mode:"tick",offset:e.index*Y_AXIS_MARGIN,stroke:t.colors[a]};return e.positions.map(function(a,n){return t.renderer.yLine(a,e.labels[n],i)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"dataset-units dataset-"+a,make:function(){var e=t.state.datasets[a],i=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,n){return t.renderer[i.type](t.state.xAxisPositions[n],e,i.args,t.colors[a],n,a,t.state.datasetLength)})},animate:function(e){var i=t.state.datasets[a],n=t.unitArgs.type,s=t.state.xAxisPositions,r=t.state.datasets[a].positions,o=e[e.length-1],l=o.parentNode;if(t.oldState.xExtra>0)for(var h=0;h0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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:"renderComponents",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,a){var i=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[a],width:100*e/t.grand_total+"%"}});t.slices.push(i)})}},{key:"calc",value:function(){}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,a){e.addEventListener("mouseenter",function(){var i=getOffset(t.chartWrapper),n=getOffset(e),s=n.left-i.left+e.offsetWidth/2,r=n.top-i.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[a]:t.labels[a])+": ",l=(100*t.slice_totals[a]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"renderLegend",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="pie",a.elements_to_animate=null,a.hoverRadio=t.hoverRadio||.1,a.max_slices=10,a.max_legend_points=6,a.isAnimate=!1,a.startAngle=t.startAngle||0,a.clockWise=t.clockWise||!1,a.mouseMove=a.mouseMove.bind(a),a.mouseLeave=a.mouseLeave.bind(a),a.setup(),a}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,a){var i=0;return t.data.datasets.map(function(t){i+=t.values[a]}),[i,e]}).filter(function(t){return t[0]>0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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 a=this.centerX,i=this.centerY,n=this.radius,s=this.clockWise;return"M"+a+" "+i+" L"+(a+t.x)+" "+(i+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(a+e.x)+" "+(i+e.y)+" z"}},{key:"renderComponents",value:function(t){var a=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,c=o/a.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,i),f=e.getPositionByAngle(p,i),v=t&&s[l],g=void 0,m=void 0;t?(g=v?v.startPosition:d,m=v?v.endPosition:d):(g=d,m=f);var y=a.makeArcPath(g,m),_=makePath(y,"pie-path","none",a.colors[l]);_.style.transition="transform .3s;",a.drawArea.appendChild(_),a.slices.push(_),a.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:a.grand_total,startAngle:h,endAngle:p,angle:u}),t&&a.elements_to_animate.push([{unit:_,array:a.slices,index:a.slices.length-1},{d:a.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var a=this.radius,i=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,a);return"translate3d("+n.x*i+"px,"+n.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,e,a,i){if(t){var n=this.colors[e];if(a){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=i.pageX-s.left+10,o=i.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,a=this.curActiveSliceIndex,i=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){var n=t.colors[i];a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=t.start,i=void 0===a?"":a,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,c=t.discrete_domains,u=void 0===c?0:c,p=t.count_label,d=void 0===p?"":p,f=t.legend_colors,v=void 0===f?[]:f;classCallCheck(this,e);var g=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));g.type="heatmap",g.domain=s,g.subdomain=o,g.data=h,g.discrete_domains=u,g.count_label=d;var m=new Date;return g.start=i||addDays(m,365),v=v.slice(0,5),g.legend_colors=g.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],g.distribution_size=5,g.translateX=0,g}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:"configure",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),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:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("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 a=0;aa)break;v.getMonth()-t.getMonth()&&(i=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=v}return[s,i]}},{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,a){var i=makeText("y-value-text",e+12,10,t.month_names[t.months[a]].substring(0,3));t.domain_label_group.appendChild(i)})}},{key:"renderComponents",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chartWrapper.style.marginTop="0px",this.chartWrapper.style.paddingTop="0px"}},{key:"bindTooltip",value:function(){var t=this;Array.prototype.slice.call(document.querySelectorAll(".data-group .day")).map(function(e){e.addEventListener("mouseenter",function(e){var a=e.target.getAttribute("data-value"),i=e.target.getAttribute("data-date").split("-"),n=t.month_names[parseInt(i[1])-1].substring(0,3),s=t.chartWrapper.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,c=a+" "+t.count_label,u=" on "+n+" "+i[0]+", "+i[2];t.tip.set_values(l,h,u,c,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bindTooltip()}}]),e}(BaseChart),chartTypes={mixed:AxisChart,multiaxis:MultiAxisChart,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 a=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");return i.type="text/css",a.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function getOffset(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),a=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-a}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];a||(a=i?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(a);return t=i?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var a=void 0,i=void 0;return t<=e?(a=e-t,i=t):(a=t-e,i=e),[a,i]}function equilizeNoOfElements(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return a>0?t=fillArray(t,a):e=fillArray(e,a),[t,e]}function translate(t,e,a,i){var n="string"==typeof e?e:e.join(", ");return[t,{transform:a.join(", ")},i,STD_EASING,"translate",{transform:n}]}function translateVertLine(t,e,a){return translate(t,[a,0],[e,0],MARKER_LINE_ANIM_DUR)}function translateHoriLine(t,e,a){return translate(t,[0,a],[0,e],MARKER_LINE_ANIM_DUR)}function animateRegion(t,e,a,i){var n=e-a,s=t.childNodes[0];return[[s,{height:n,"stroke-dasharray":s.getAttribute("width")+", "+n},MARKER_LINE_ANIM_DUR,STD_EASING],translate(t,[0,i],[0,a],MARKER_LINE_ANIM_DUR)]}function animateBar(t,e,a,i){var n=getBarHeightAndYAttr(a,(arguments.length>5&&void 0!==arguments[5]?arguments[5]:{}).zeroLine),s=slicedToArray(n,2),r=s[0],o=s[1];return"rect"!==t.nodeName?[[t.childNodes[0],{width:i,height:r},UNIT_ANIM_DUR,STD_EASING],translate(t,t.getAttribute("transform").split("(")[1].slice(0,-1),[e,o],MARKER_LINE_ANIM_DUR)]:[[t,{width:i,height:r,x:e,y:o},UNIT_ANIM_DUR,STD_EASING]]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var a=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in e){var n=e[i];if("inside"===i)$$2(n).appendChild(a);else if("around"===i){var s=$$2(n);s.parentNode.insertBefore(a,s),a.appendChild(s)}else"styles"===i?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){a.style[t]=n[t]}):("className"===i&&(i="class"),"innerHTML"===i?a.textContent=n:a.setAttribute(i,n))}return a}function makeSVGContainer(t,e,a,i){return createSVG("svg",{className:e,inside:t,width:a,height:i})}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 makeHeatSquare(t,e,a,i){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:a,width:i,height:i,fill:1};return Object.keys(n).map(function(t){s[t]=n[t]}),createSVG("rect",s)}function makeText(t,e,a,i){return createSVG("text",{className:t,x:e,y:a,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:i})}function makeVertLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR);var s=createSVG("line",{className:"line-vertical "+n.className,x1:0,x2:0,y1:a,y2:i,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:a>i?a+LABEL_MARGIN:a-LABEL_MARGIN-FONT_SIZE,dy:FONT_SIZE+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:e}),o=createSVG("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function makeHoriLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR),n.lineType||(n.lineType="");var s=createSVG("line",{className:"line-horizontal "+n.className+("dashed"===n.lineType?"dashed":""),x1:a,x2:i,y1:0,y2:0,styles:{stroke:n.stroke}}),r=createSVG("text",{x:a3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=-1*AXIS_TICK_LENGTH,s="span"===i.mode?a+AXIS_TICK_LENGTH:0;return"tick"===i.mode&&"right"===i.pos&&(n=a+AXIS_TICK_LENGTH,s=a),n+=i.offset,s+=i.offset,makeHoriLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function xLine(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=a+AXIS_TICK_LENGTH,s="span"===i.mode?-1*AXIS_TICK_LENGTH:a;return"tick"===i.mode&&"top"===i.pos&&(n=-1*AXIS_TICK_LENGTH,s=0),makeVertLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function yMarker(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=createSVG("text",{className:"chart-label",x:a-getStringWidth(e,5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),s=makeHoriLine(t,"",0,a,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return s.appendChild(n),s}function yRegion(t,e,a,i){var n=t-e,s=createSVG("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:BASE_LINE_COLOR,"stroke-dasharray":a+", "+n},x:0,y:0,width:a,height:n}),r=createSVG("text",{className:"chart-label",x:a-getStringWidth(i,4.5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{transform:"translate(0, "+e+")"});return o.appendChild(s),o.appendChild(r),o}function datasetBar(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:{},l=getBarHeightAndYAttr(e,o.zeroLine),h=slicedToArray(l,2),c=h[0],u=h[1],p=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":s,x:t,y:u-=r,width:a,height:c||o.minHeight});if(n||n.length){p.setAttribute("y",0),p.setAttribute("x",0);var d=createSVG("text",{className:"data-point-value",x:a/2,y:0,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:n}),f=createSVG("g",{transform:"translate("+t+", "+u+")"});return f.appendChild(p),f.appendChild(d),f}return p}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var a=getColor(t),i=!1;"#"==a[0]&&(a=a.slice(1),i=!0);var n=parseInt(a,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(i?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,a){if(t!==e){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var i=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:a.parent,title:a.title,data:a.data,type:t,height:a.height,colors:i?a.colors:void 0})}}function animateSVGElement(t,e,a){var i=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 c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:a/1e3+"s",values:c+";"+u,keySplines:EASING[i],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),n?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}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 a=[],i=[];e.map(function(t){var e=t[0],n=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],a.push(r),i.push([s,n]),n.replaceChild(s,e)});var n=t.cloneNode(!0);return i.map(function(t,i){t[1].replaceChild(a[i],t[0]),e[i][0]=a[i]}),n}function runSMILAnimation(t,e,a){if(0!==a.length){var i=animateSVG(e,a);e.parentNode==t&&(t.removeChild(e),t.appendChild(i)),setTimeout(function(){i.parentNode==t&&(t.removeChild(i),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function dataPrep(t,e){t.labels=t.labels||[];var a=t.labels.length,i=t.datasets,n=new Array(a).fill(0);return i||(i=[{values:n}]),i.map(function(t,i){if(t.values){var s=t.values;s=(s=s.map(function(t){return isNaN(t)?0:t})).length>a?s.slice(0,a):fillArray(s,a-s.length,0)}else t.values=n;t.chartType||(AXIS_DATASET_CHART_TYPES.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(function(t){if(t.end0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var a=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,a)),a]}function getChartRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=Math.ceil(t),i=Math.floor(e),n=a-i,s=n,r=1;n>5&&(n%2!=0&&(n=++a-i),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(i+r*l);return o}function getChartIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=normalize(t),i=slicedToArray(a,2),n=i[0],s=i[1],r=e?e/Math.pow(10,s):0,o=getChartRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcChartIntervals(t){function e(t,e){for(var a=getChartIntervals(t),i=a[1]-a[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],i=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(i>=0&&n>=0)normalize(i)[1],s=a?getChartIntervals(i,n):getChartIntervals(i);else if(i>0&&n<0){var r=Math.abs(n);i>=r?(normalize(i)[1],s=e(i,r)):(normalize(r)[1],s=e(r,i).map(function(t){return-1*t}))}else if(i<=0&&n<=0){var o=Math.abs(n),l=Math.abs(i);normalize(o)[1],s=(s=a?getChartIntervals(o,l):getChartIntervals(o)).reverse().map(function(t){return-1*t})}return s}function getZeroIndex(t){var e=getIntervalSize(t);return t.indexOf(0)>=0?t.indexOf(0):t[0]>0?-1*t[0]/e:-1*t[t.length-1]/e+(t.length-1)}function getIntervalSize(t){return t[1]-t[0]}function getValueRange(t){return t[t.length-1]-t[0]}function scale(t,e){return floatTwo(e.zeroLine-t*e.scaleMultiplier)}function calcDistribution(t,e){for(var a=Math.max.apply(Math,toConsumableArray(t)),i=1/(e-1),n=[],s=0;s9?"":"0")+e,(a>9?"":"0")+a,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"line"===t?(e.type="line",new AxisChart(e)):"bar"===t?(e.type="bar",new AxisChart(e)):chartTypes[t]?new chartTypes[t](e):void console.error("Undefined chart type: "+t)}__$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{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path,.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .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 a(t,e){return new Promise(function(a,n){var o={key:t,arg:e,resolve:a,reject:n,next:null};r?r=r.next=o:(s=r=o,i(t,e))})}function i(a,s){try{var r=e[a](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){i("next",t)},function(t){i("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)?i(s.key,s.arg):r=null}var s,r;this._invoke=a,"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 a=0;a\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,a){var i=t.colors[a]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+i},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,a=this.container.querySelector(".svg-pointer");if(this.left<0)a.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var i="calc(50% + "+(this.left-e)+"px)";a.style.left=i,this.left=e}else a.style.left="50%"}},{key:"set_values",value:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=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=a,this.title_value=i,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}(),UNIT_ANIM_DUR=350,PATH_ANIM_DUR=350,MARKER_LINE_ANIM_DUR=UNIT_ANIM_DUR,REPLACE_ALL_NEW_DUR=250,STD_EASING="easein",AXIS_TICK_LENGTH=6,LABEL_MARGIN=4,FONT_SIZE=10,BASE_LINE_COLOR="#dadada",AxisChartRenderer=function(){function t(e){classCallCheck(this,t),this.refreshState(e)}return createClass(t,[{key:"refreshState",value:function(t){this.totalHeight=t.totalHeight,this.totalWidth=t.totalWidth,this.zeroLine=t.zeroLine,this.unitWidth=t.unitWidth,this.xAxisMode=t.xAxisMode,this.yAxisMode=t.yAxisMode}},{key:"setZeroline",value:function(t){this.zeroLine=t}},{key:"xMarker",value:function(){}},{key:"xRegion",value:function(){return createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"animatebar",value:function(t,e,a,i,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(a,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*i,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,a){return[t,{cx:e,cy:a},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var a=[],i=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];if(a.push(i),t[1]){var n="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+n+e+s},PATH_ANIM_DUR,STD_EASING];a.push(r)}return a}}]),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:[]},EASING={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},BaseChart=function(){function t(e){var a=e.height,i=void 0===a?240:a,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type),u=void 0===c?"":c,p=e.parent,d=e.data;classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof p?document.querySelector(p):p,this.title=s,this.subtitle=o,this.argHeight=i,this.type=u,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.realData=this.prepareData(d),this.data=this.prepareFirstData(this.realData),this.colors=[],this.config={},this.state={},this.options={},this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){var e=this;this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:1},this.setMargins(),window.addEventListener("resize",function(){return e.draw()}),window.addEventListener("orientationchange",function(){return e.draw()})}},{key:"setColors",value:function(){var t=this.rawChartArgs,e="percentage"===t.type||"pie"===t.type?t.data.labels:t.data.datasets;!t.colors||e&&t.colors.length'+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.chartWrapper=this.container.querySelector(".frappe-chart"),this.statsWrapper=this.container.querySelector(".graph-stats-container")}},{key:"makeTooltip",value:function(){this.tip=new SvgTip({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.makeChartArea(),this.calc(),this.initComponents(),this.setupComponents(),this.components.forEach(function(e){return e.setup(t.drawArea)}),this.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),e&&(this.data=this.realData,setTimeout(function(){t.update()},1e3))}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data;this.data=this.prepareData(t),this.calc(),this.render()}},{key:"prepareData",value:function(){}},{key:"calc",value:function(){}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.components,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=[];t.forEach(function(t){a=a.concat(t.update(e))}),a.length>0&&runSMILAnimation(this.chartWrapper,this.svg,a)}},{key:"makeChartArea",value:function(){this.svg&&this.chartWrapper.removeChild(this.svg),this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"renderLegend",value:function(){}},{key:"setupNavigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isNavigable||(this.makeOverlay(),e&&(this.bindOverlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chartWrapper)&&("37"==(e=e||window.event).keyCode?t.onLeftArrow():"39"==e.keyCode?t.onRightArrow():"38"==e.keyCode?t.onUpArrow():"40"==e.keyCode?t.onDownArrow():"13"==e.keyCode&&t.onEnterKey())})))}},{key:"makeOverlay",value:function(){}},{key:"bindOverlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"onLeftArrow",value:function(){}},{key:"onRightArrow",value:function(){}},{key:"onUpArrow",value:function(){}},{key:"onDownArrow",value:function(){}},{key:"onEnterKey",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"setCurrentDataPoint",value:function(t){}},{key:"updateDataset",value:function(t,e){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"updateDatasets",value:function(t){}},{key:"updateDataPoint",value:function(t){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,MIN_BAR_PERCENT_HEIGHT=.01,DEFAULT_AXIS_CHART_TYPE="line",AXIS_DATASET_CHART_TYPES=["line","bar"],BAR_CHART_SPACE_RATIO=.5,ChartComponent$1=function(){function t(e){var a=e.layerClass,i=void 0===a?"":a,n=e.layerTransform,s=void 0===n?"":n,r=e.constants,o=e.getData,l=e.makeElements,h=e.animateElements;classCallCheck(this,t),this.layerTransform=s,this.constants=r,this.makeElements=l,this.getData=o,this.animateElements=h,this.store=[],this.layerClass=i,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}return createClass(t,[{key:"refresh",value:function(t){this.data=t||this.getData()}},{key:"setup",value:function(t){this.layer=makeSVGGroup(t,this.layerClass,this.layerTransform)}},{key:"make",value:function(){this.render(this.data),this.oldData=this.data}},{key:"render",value:function(t){var e=this;this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(function(t){e.layer.appendChild(t)})}},{key:"update",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refresh();var a=[];return e&&(a=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),a}}]),t}(),componentConfigs={yAxis:{layerClass:"y axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return yLine(a,t.labels[i],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateHoriLine(t,e[a],i[a])})}},xAxis:{layerClass:"x axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return xLine(a,t.labels[i],e.constants.height,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateVertLine(t,e[a],i[a])})}},yMarkers:{layerClass:"y-markers",makeElements:function(t){var e=this;return t.map(function(t){return yMarker(t.position,t.label,e.constants.width,{pos:"right",mode:"span",lineType:"dashed"})})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.position}),n=t.map(function(t){return t.label}),s=this.oldData.map(function(t){return t.position});this.oldData.map(function(t){return t.label});return this.render(s.map(function(t,e){return{position:s[e],label:n[e]}})),this.store.map(function(t,e){return translateHoriLine(t,i[e],s[e])})}},yRegions:{layerClass:"y-regions",makeElements:function(t){var e=this;return t.map(function(t){return yRegion(t.start,t.end,e.constants.width,t.label)})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.end}),n=t.map(function(t){return t.label}),s=t.map(function(t){return t.start}),r=this.oldData.map(function(t){return t.end}),o=(this.oldData.map(function(t){return t.label}),this.oldData.map(function(t){return t.start}));this.render(r.map(function(t,e){return{start:o[e],end:r[e],label:n[e]}}));var l=[];return this.store.map(function(t,e){l=l.concat(animateRegion(t,s[e],i[e],r[e]))}),l}},barGraph:{layerClass:function(){return"dataset-units dataset-"+this.constants.index},makeElements:function(t){var e=this.constants;return t.yPositions.map(function(a,i){return datasetBar(t.xPositions[i],a,t.barWidth,e.color,e.valuesOverPoints?e.stacked?t.cumulativeYs[i]:t.values[i]:"",i,a-(e.stacked?t.cumulativeYPos[i]:a),{zeroLine:t.zeroLine,barsWidth:t.barsWidth,minHeight:e.minHeight})})},animateElements:function(t){var e=this.constants,a=t.xPositions,i=t.yPositions,n=t.cumulativeYPos,s=t.values,r=t.cumulativeYs,o=this.oldData.xPositions,l=this.oldData.yPositions,h=this.oldData.cumulativeYPos,c=this.oldData.values,u=this.oldData.cumulativeYs,p=equilizeNoOfElements(o,a),d=slicedToArray(p,2);o=d[0],a=d[1];var f=equilizeNoOfElements(l,i),v=slicedToArray(f,2);l=v[0],i=v[1];var m=equilizeNoOfElements(h,n),g=slicedToArray(m,2);h=g[0],n=g[1];var y=equilizeNoOfElements(c,s),_=slicedToArray(y,2);c=_[0],s=_[1];var x=equilizeNoOfElements(u,r),b=slicedToArray(x,2);u=b[0],r=b[1],this.render({xPositions:o,yPositions:l,cumulativeYPos:h,values:s,cumulativeYs:r,zeroLine:this.oldData.zeroLine,barsWidth:this.oldData.barsWidth,barWidth:this.oldData.barWidth});var A=[];return this.store.map(function(n,s){A=A.concat(animateBar(n,a[s],i[s],t.barWidth,e.index,{zeroLine:t.zeroLine}))}),A}},lineGraph:{}},AxisChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.isSeries=t.isSeries,a.valuesOverPoints=t.valuesOverPoints,a.formatTooltipY=t.formatTooltipY,a.formatTooltipX=t.formatTooltipX,a.barOptions=t.barOptions||{},a.lineOptions=t.lineOptions||{},a.type=t.type||"line",a.xAxisMode=t.xAxisMode||"span",a.yAxisMode=t.yAxisMode||"span",a.zeroLine=a.height,a.setup(),a}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this),this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"prepareData",value:function(){return dataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data,this.type)}},{key:"prepareFirstData",value:function(){return zeroDataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data)}},{key:"calc",value:function(){this.calcXPositions(),this.calcYAxisParameters(this.getAllYValues(),"line"===this.type)}},{key:"calcXPositions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map(function(e,a){return floatTwo(t.xOffset+a*t.unitWidth)})}}},{key:"calcYAxisParameters",value:function(t){var e=calcChartIntervals(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"false"),a=this.height/getValueRange(e),i=getIntervalSize(e)*a,n=this.height-getZeroIndex(e)*i;this.state.yAxis={labels:e,positions:e.map(function(t){return n-t*a}),scaleMultiplier:a,zeroLine:n},this.calcYUnits(),this.calcYExtremes(),this.calcYRegions()}},{key:"calcYUnits",value:function(){var t=this.state,e=function(e){return e.map(function(e){return scale(e,t.yAxis)})};t.datasets=this.data.datasets.map(function(t,a){var i=t.values,n=t.cumulativeYs||[];return{name:t.name,index:a,chartType:t.chartType,values:i,yPositions:e(i),cumulativeYs:n,cumulativeYPos:e(n)}})}},{key:"calcYExtremes",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,a){e.yPositions.map(function(e,a){e0)for(var l=0;l0&&(t=getPaths(r,s,a.colors[e],a.config.heatline,a.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var p=n.map(function(t,e){return i[e]+","+t});a.elementsToAnimate=a.elementsToAnimate.concat(a.renderer.animatepath(t,p.join("L")))}})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var a=getOffset(t.chartWrapper),i=e.pageX-a.left-t.translateXLeft;e.pageY-a.top-t.translateY=0;s--){var r=a.xAxis.positions[s];if(t>r-a.unitWidth/2){var o=r+this.translateXLeft,l=a.yExtremes[s]+this.translateY,h=this.data.datasets.map(function(t,a){return{title:t.title,value:n?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[a]}});this.tip.set_values(o,l,i[s],"",h),this.tip.show_tip();break}}}}},{key:"getDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.current_index,e={index:t},a=this.y[0];return["svg_units","yUnitPositions","values"].map(function(i){var n=i.slice(0,i.length-1);e[n]=a[i][t]}),e.label=this.xAxis.labels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxis.labels.length&&(t=this.xAxis.labels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,a){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"addDataPoint",this).call(this,t,a,i),this.data.labels.splice(i,0,t),this.data.datasets.map(function(t,e){t.values.splice(i,0,a[e])}),this.update(this.data)}},{key:"removeDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.datasetLength-1;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"removeDataPoint",this).call(this,t),this.data.labels.splice(t,1),this.data.datasets.map(function(e){e.values.splice(t,1)}),this.update(this.data)}}]),e}(BaseChart),LineChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="line",Object.getPrototypeOf(a)!==e.prototype?possibleConstructorReturn(a):(a.setup(),a)}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"span",this.config.yAxisMode=t.yAxisMode||"span",this.config.dotRadius=t.dotRadius||4,this.config.heatline=t.heatline||0,this.config.regionFill=t.regionFill||0,this.config.showDots=t.showDots||1}},{key:"configUnits",value:function(){this.unitArgs={type:"dot",args:{radius:this.config.dotRadius}}}},{key:"setUnitWidthAndXOffset",value:function(){this.state.unitWidth=this.width/(this.state.datasetLength-1),this.state.xOffset=0}}]),e}(AxisChart),ScatterChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="scatter",t.dotRadius?a.dotRadius=t.dotRadius:a.dotRadius=8,a.setup(),a}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dotRadius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(LineChart),MultiAxisChart=function(t){function e(t){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return inherits(e,t),createClass(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this);var t=this.data.datasets.filter(function(t){return"left"===t.axisPosition}).length;this.translateXLeft=t*Y_AXIS_MARGIN||Y_AXIS_MARGIN,this.translateXRight=(this.data.datasets.length-t)*Y_AXIS_MARGIN||Y_AXIS_MARGIN}},{key:"prepareYAxis",value:function(){}},{key:"prepareData",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var a=0,i=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?a++:i++}})}},{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"tick",this.config.yAxisMode=t.yAxisMode||"span"}},{key:"configUnits",value:function(){this.unitArgs={type:"bar",args:{spaceWidth:this.state.unitWidth/2}}}},{key:"setYAxis",value:function(){var t=this;this.state.datasets.map(function(e){t.calcYAxisParameters(e.yAxis,e.values,"line"===t.unitType)})}},{key:"calcYUnits",value:function(){this.state.datasets.map(function(t){t.positions=t.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"renderConstants",value:function(){var t=this;this.state.datasets.map(function(e){var a="left"===e.yAxis.position?-1*e.yAxis.index*Y_AXIS_MARGIN:t.width+e.yAxis.index*Y_AXIS_MARGIN;t.renderer.xLine(a,"",{pos:"top",mode:"span",stroke:t.colors[i],className:"y-axis-guide"})})}},{key:"getYAxesComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"y axis y-axis-"+a,make:function(){var e=t.state.datasets[a].yAxis;t.renderer.setZeroline(e.zeroline);var i={pos:e.position,mode:"tick",offset:e.index*Y_AXIS_MARGIN,stroke:t.colors[a]};return e.positions.map(function(a,n){return t.renderer.yLine(a,e.labels[n],i)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"dataset-units dataset-"+a,make:function(){var e=t.state.datasets[a],i=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,n){return t.renderer[i.type](t.state.xAxisPositions[n],e,i.args,t.colors[a],n,a,t.state.datasetLength)})},animate:function(e){var i=t.state.datasets[a],n=t.unitArgs.type,s=t.state.xAxisPositions,r=t.state.datasets[a].positions,o=e[e.length-1],l=o.parentNode;if(t.oldState.xExtra>0)for(var h=0;h0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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:"renderComponents",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,a){var i=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[a],width:100*e/t.grand_total+"%"}});t.slices.push(i)})}},{key:"calc",value:function(){}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,a){e.addEventListener("mouseenter",function(){var i=getOffset(t.chartWrapper),n=getOffset(e),s=n.left-i.left+e.offsetWidth/2,r=n.top-i.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[a]:t.labels[a])+": ",l=(100*t.slice_totals[a]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"renderLegend",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="pie",a.elements_to_animate=null,a.hoverRadio=t.hoverRadio||.1,a.max_slices=10,a.max_legend_points=6,a.isAnimate=!1,a.startAngle=t.startAngle||0,a.clockWise=t.clockWise||!1,a.mouseMove=a.mouseMove.bind(a),a.mouseLeave=a.mouseLeave.bind(a),a.setup(),a}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,a){var i=0;return t.data.datasets.map(function(t){i+=t.values[a]}),[i,e]}).filter(function(t){return t[0]>0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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 a=this.centerX,i=this.centerY,n=this.radius,s=this.clockWise;return"M"+a+" "+i+" L"+(a+t.x)+" "+(i+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(a+e.x)+" "+(i+e.y)+" z"}},{key:"renderComponents",value:function(t){var a=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,c=o/a.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,i),f=e.getPositionByAngle(p,i),v=t&&s[l],m=void 0,g=void 0;t?(m=v?v.startPosition:d,g=v?v.endPosition:d):(m=d,g=f);var y=a.makeArcPath(m,g),_=makePath(y,"pie-path","none",a.colors[l]);_.style.transition="transform .3s;",a.drawArea.appendChild(_),a.slices.push(_),a.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:a.grand_total,startAngle:h,endAngle:p,angle:u}),t&&a.elements_to_animate.push([{unit:_,array:a.slices,index:a.slices.length-1},{d:a.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var a=this.radius,i=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,a);return"translate3d("+n.x*i+"px,"+n.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,e,a,i){if(t){var n=this.colors[e];if(a){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=i.pageX-s.left+10,o=i.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,a=this.curActiveSliceIndex,i=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){var n=t.colors[i];a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=t.start,i=void 0===a?"":a,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,c=t.discrete_domains,u=void 0===c?0:c,p=t.count_label,d=void 0===p?"":p,f=t.legend_colors,v=void 0===f?[]:f;classCallCheck(this,e);var m=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));m.type="heatmap",m.domain=s,m.subdomain=o,m.data=h,m.discrete_domains=u,m.count_label=d;var g=new Date;return m.start=i||addDays(g,365),v=v.slice(0,5),m.legend_colors=m.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],m.distribution_size=5,m.translateX=0,m}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:"configure",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),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:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("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 a=0;aa)break;v.getMonth()-t.getMonth()&&(i=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=v}return[s,i]}},{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,a){var i=makeText("y-value-text",e+12,10,t.month_names[t.months[a]].substring(0,3));t.domain_label_group.appendChild(i)})}},{key:"renderComponents",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chartWrapper.style.marginTop="0px",this.chartWrapper.style.paddingTop="0px"}},{key:"bindTooltip",value:function(){var t=this;Array.prototype.slice.call(document.querySelectorAll(".data-group .day")).map(function(e){e.addEventListener("mouseenter",function(e){var a=e.target.getAttribute("data-value"),i=e.target.getAttribute("data-date").split("-"),n=t.month_names[parseInt(i[1])-1].substring(0,3),s=t.chartWrapper.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,c=a+" "+t.count_label,u=" on "+n+" "+i[0]+", "+i[2];t.tip.set_values(l,h,u,c,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bindTooltip()}}]),e}(BaseChart),chartTypes={mixed:AxisChart,multiaxis:MultiAxisChart,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 a76245b..0b0360e 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 a=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");return i.type="text/css",a.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function getOffset(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),a=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-a}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];a||(a=i?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(a);return t=i?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var a=void 0,i=void 0;return t2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return a>0?t=fillArray(t,a):e=fillArray(e,a),[t,e]}function translate(t,e,a,i){return[t,{transform:a.join(", ")},i,STD_EASING,"translate",{transform:e.join(", ")}]}function translateVertLine(t,e,a){return translate(t,[a,0],[e,0],MARKER_LINE_ANIM_DUR)}function translateHoriLine(t,e,a){return translate(t,[0,a],[0,e],MARKER_LINE_ANIM_DUR)}function animateRegion(t,e,a,i){var n=e-a,s=t.childNodes[0];return[[s,{height:n,"stroke-dasharray":s.getAttribute("width")+", "+n},MARKER_LINE_ANIM_DUR,STD_EASING],translate(t,[0,i],[0,a],MARKER_LINE_ANIM_DUR)]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var a=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in e){var n=e[i];if("inside"===i)$$2(n).appendChild(a);else if("around"===i){var s=$$2(n);s.parentNode.insertBefore(a,s),a.appendChild(s)}else"styles"===i?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){a.style[t]=n[t]}):("className"===i&&(i="class"),"innerHTML"===i?a.textContent=n:a.setAttribute(i,n))}return a}function makeSVGContainer(t,e,a,i){return createSVG("svg",{className:e,inside:t,width:a,height:i})}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 wrapInSVGGroup(t){var e=createSVG("g",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""});return t.forEach(function(t){return e.appendChild(t)}),e}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 makeHeatSquare(t,e,a,i){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:a,width:i,height:i,fill:1};return Object.keys(n).map(function(t){s[t]=n[t]}),createSVG("rect",s)}function makeText(t,e,a,i){return createSVG("text",{className:t,x:e,y:a,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:i})}function makeVertLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR);var s=createSVG("line",{className:"line-vertical "+n.className,x1:0,x2:0,y1:a,y2:i,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:a>i?a+LABEL_MARGIN:a-LABEL_MARGIN-FONT_SIZE,dy:FONT_SIZE+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:e}),o=createSVG("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function makeHoriLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR),n.lineType||(n.lineType="");var s=createSVG("line",{className:"line-horizontal "+n.className+("dashed"===n.lineType?"dashed":""),x1:a,x2:i,y1:0,y2:0,styles:{stroke:n.stroke}}),r=createSVG("text",{x:a3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=-1*AXIS_TICK_LENGTH,s="span"===i.mode?a+AXIS_TICK_LENGTH:0;return"tick"===i.mode&&"right"===i.pos&&(n=a+AXIS_TICK_LENGTH,s=a),n+=i.offset,s+=i.offset,makeHoriLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function xLine(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=a+AXIS_TICK_LENGTH,s="span"===i.mode?-1*AXIS_TICK_LENGTH:a;return"tick"===i.mode&&"top"===i.pos&&(n=-1*AXIS_TICK_LENGTH,s=0),makeVertLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function yMarker(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=createSVG("text",{className:"chart-label",x:a-getStringWidth(e,5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),s=makeHoriLine(t,"",0,a,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return s.appendChild(n),s}function yRegion(t,e,a,i){var n=t-e,s=createSVG("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:BASE_LINE_COLOR,"stroke-dasharray":a+", "+n},x:0,y:0,width:a,height:n}),r=createSVG("text",{className:"chart-label",x:a-getStringWidth(i,4.5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{transform:"translate(0, "+e+")"});return o.appendChild(s),o.appendChild(r),o}function datasetBar(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:{},l=getBarHeightAndYAttr(e,o.zeroLine),h=slicedToArray(l,2),c=h[0],u=h[1],p=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":s,x:t-o.barsWidth/2,y:u-r,width:a,height:c||o.minHeight});return n||n.length?wrapInSVGGroup([p,createSVG("text",{className:"data-point-value",x:t,y:u-r,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:n})]):p}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var a=getColor(t),i=!1;"#"==a[0]&&(a=a.slice(1),i=!0);var n=parseInt(a,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(i?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,a){if(t!==e){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var i=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:a.parent,title:a.title,data:a.data,type:t,height:a.height,colors:i?a.colors:void 0})}}function animateSVGElement(t,e,a){var i=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 c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:a/1e3+"s",values:c+";"+u,keySplines:EASING[i],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),n?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}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 a=[],i=[];e.map(function(t){var e=t[0],n=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],a.push(r),i.push([s,n]),n.replaceChild(s,e)});var n=t.cloneNode(!0);return i.map(function(t,i){t[1].replaceChild(a[i],t[0]),e[i][0]=a[i]}),n}function runSMILAnimation(t,e,a){if(0!==a.length){var i=animateSVG(e,a);e.parentNode==t&&(t.removeChild(e),t.appendChild(i)),setTimeout(function(){i.parentNode==t&&(t.removeChild(i),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function dataPrep(t,e){t.labels=t.labels||[];var a=t.labels.length,i=t.datasets,n=new Array(a).fill(0);return i||(i=[{values:n}]),i.map(function(t,i){if(t.values){var s=t.values;s=(s=s.map(function(t){return isNaN(t)?0:t})).length>a?s.slice(0,a):fillArray(s,a-s.length,0)}else t.values=n;t.chartType||(AXIS_DATASET_CHART_TYPES.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(function(t){if(t.end0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var a=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,a)),a]}function getChartRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=Math.ceil(t),i=Math.floor(e),n=a-i,s=n,r=1;n>5&&(n%2!=0&&(n=++a-i),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(i+r*l);return o}function getChartIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=normalize(t),i=slicedToArray(a,2),n=i[0],s=i[1],r=e?e/Math.pow(10,s):0,o=getChartRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcChartIntervals(t){function e(t,e){for(var a=getChartIntervals(t),i=a[1]-a[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],i=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(i>=0&&n>=0)normalize(i)[1],s=a?getChartIntervals(i,n):getChartIntervals(i);else if(i>0&&n<0){var r=Math.abs(n);i>=r?(normalize(i)[1],s=e(i,r)):(normalize(r)[1],s=e(r,i).map(function(t){return-1*t}))}else if(i<=0&&n<=0){var o=Math.abs(n),l=Math.abs(i);normalize(o)[1],s=(s=a?getChartIntervals(o,l):getChartIntervals(o)).reverse().map(function(t){return-1*t})}return s}function getZeroIndex(t){var e=getIntervalSize(t);return t.indexOf(0)>=0?t.indexOf(0):t[0]>0?-1*t[0]/e:-1*t[t.length-1]/e+(t.length-1)}function getIntervalSize(t){return t[1]-t[0]}function getValueRange(t){return t[t.length-1]-t[0]}function scale(t,e){return floatTwo(e.zeroLine-t*e.scaleMultiplier)}function calcDistribution(t,e){for(var a=Math.max.apply(Math,toConsumableArray(t)),i=1/(e-1),n=[],s=0;s9?"":"0")+e,(a>9?"":"0")+a,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"line"===t?(e.type="line",new AxisChart(e)):"bar"===t?(e.type="bar",new AxisChart(e)):chartTypes[t]?new chartTypes[t](e):void console.error("Undefined chart type: "+t)}__$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{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path,.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .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 a(t,e){return new Promise(function(a,n){var o={key:t,arg:e,resolve:a,reject:n,next:null};r?r=r.next=o:(s=r=o,i(t,e))})}function i(a,s){try{var r=e[a](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){i("next",t)},function(t){i("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)?i(s.key,s.arg):r=null}var s,r;this._invoke=a,"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 a=0;a\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,a){var i=t.colors[a]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+i},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,a=this.container.querySelector(".svg-pointer");if(this.left<0)a.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var i="calc(50% + "+(this.left-e)+"px)";a.style.left=i,this.left=e}else a.style.left="50%"}},{key:"set_values",value:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=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=a,this.title_value=i,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}(),UNIT_ANIM_DUR=350,PATH_ANIM_DUR=350,MARKER_LINE_ANIM_DUR=UNIT_ANIM_DUR,REPLACE_ALL_NEW_DUR=250,STD_EASING="easein",AXIS_TICK_LENGTH=6,LABEL_MARGIN=4,FONT_SIZE=10,BASE_LINE_COLOR="#dadada",AxisChartRenderer=function(){function t(e){classCallCheck(this,t),this.refreshState(e)}return createClass(t,[{key:"refreshState",value:function(t){this.totalHeight=t.totalHeight,this.totalWidth=t.totalWidth,this.zeroLine=t.zeroLine,this.unitWidth=t.unitWidth,this.xAxisMode=t.xAxisMode,this.yAxisMode=t.yAxisMode}},{key:"setZeroline",value:function(t){this.zeroLine=t}},{key:"xMarker",value:function(){}},{key:"xRegion",value:function(){return createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"animatebar",value:function(t,e,a,i,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(a,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*i,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,a){return[t,{cx:e,cy:a},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var a=[],i=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];if(a.push(i),t[1]){var n="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+n+e+s},PATH_ANIM_DUR,STD_EASING];a.push(r)}return a}}]),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:[]},EASING={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},BaseChart=function(){function t(e){var a=e.height,i=void 0===a?240:a,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type),u=void 0===c?"":c,p=e.parent,d=e.data;classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof p?document.querySelector(p):p,this.title=s,this.subtitle=o,this.argHeight=i,this.type=u,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.realData=this.prepareData(d),this.data=this.prepareFirstData(this.realData),this.colors=[],this.config={},this.state={},this.options={},this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){var e=this;this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:1},this.setMargins(),window.addEventListener("resize",function(){return e.draw()}),window.addEventListener("orientationchange",function(){return e.draw()})}},{key:"setColors",value:function(){var t=this.rawChartArgs,e="percentage"===t.type||"pie"===t.type?t.data.labels:t.data.datasets;!t.colors||e&&t.colors.length'+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.chartWrapper=this.container.querySelector(".frappe-chart"),this.statsWrapper=this.container.querySelector(".graph-stats-container")}},{key:"makeTooltip",value:function(){this.tip=new SvgTip({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.makeChartArea(),this.calc(),this.initComponents(),this.setupComponents(),this.components.forEach(function(e){return e.setup(t.drawArea)}),this.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),e&&(this.data=this.realData,setTimeout(function(){t.update()},1e3))}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data;this.data=this.prepareData(t),this.calc(),this.render()}},{key:"prepareData",value:function(){}},{key:"calc",value:function(){}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.components,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=[];t.forEach(function(t){a=a.concat(t.update(e))}),a.length>0&&runSMILAnimation(this.chartWrapper,this.svg,a)}},{key:"makeChartArea",value:function(){this.svg&&this.chartWrapper.removeChild(this.svg),this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"renderLegend",value:function(){}},{key:"setupNavigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isNavigable||(this.makeOverlay(),e&&(this.bindOverlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chartWrapper)&&("37"==(e=e||window.event).keyCode?t.onLeftArrow():"39"==e.keyCode?t.onRightArrow():"38"==e.keyCode?t.onUpArrow():"40"==e.keyCode?t.onDownArrow():"13"==e.keyCode&&t.onEnterKey())})))}},{key:"makeOverlay",value:function(){}},{key:"bindOverlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"onLeftArrow",value:function(){}},{key:"onRightArrow",value:function(){}},{key:"onUpArrow",value:function(){}},{key:"onDownArrow",value:function(){}},{key:"onEnterKey",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"setCurrentDataPoint",value:function(t){}},{key:"updateDataset",value:function(t,e){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"updateDatasets",value:function(t){}},{key:"updateDataPoint",value:function(t){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,MIN_BAR_PERCENT_HEIGHT=.01,DEFAULT_AXIS_CHART_TYPE="line",AXIS_DATASET_CHART_TYPES=["line","bar"],BAR_CHART_SPACE_RATIO=.5,ChartComponent$1=function(){function t(e){var a=e.layerClass,i=void 0===a?"":a,n=e.layerTransform,s=void 0===n?"":n,r=e.constants,o=e.getData,l=e.makeElements,h=e.postMake,c=e.animateElements;classCallCheck(this,t),this.layerTransform=s,this.constants=r,this.makeElements=l,this.postMake=h,this.getData=o,this.animateElements=c,this.store=[],this.layerClass=i,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}return createClass(t,[{key:"refresh",value:function(t){this.data=t||this.getData()}},{key:"setup",value:function(t){this.layer=makeSVGGroup(t,this.layerClass,this.layerTransform)}},{key:"make",value:function(){this.preMake&&this.preMake(),this.render(this.data),this.postMake&&this.postMake(),this.oldData=this.data}},{key:"render",value:function(t){var e=this;this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(function(t){e.layer.appendChild(t)})}},{key:"update",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refresh();var a=[];return e&&(a=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),a}}]),t}(),componentConfigs={yAxis:{layerClass:"y axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return yLine(a,t.labels[i],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateHoriLine(t,e[a],i[a])})}},xAxis:{layerClass:"x axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return xLine(a,t.labels[i],e.constants.height,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateVertLine(t,e[a],i[a])})}},yMarkers:{layerClass:"y-markers",makeElements:function(t){var e=this;return t.map(function(t){return yMarker(t.position,t.label,e.constants.width,{pos:"right",mode:"span",lineType:"dashed"})})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.position}),n=t.map(function(t){return t.label}),s=this.oldData.map(function(t){return t.position});this.oldData.map(function(t){return t.label});return this.render(s.map(function(t,e){return{position:s[e],label:n[e]}})),this.store.map(function(t,e){return translateHoriLine(t,i[e],s[e])})}},yRegions:{layerClass:"y-regions",makeElements:function(t){var e=this;return t.map(function(t){return yRegion(t.start,t.end,e.constants.width,t.label)})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.end}),n=t.map(function(t){return t.label}),s=t.map(function(t){return t.start}),r=this.oldData.map(function(t){return t.end}),o=(this.oldData.map(function(t){return t.label}),this.oldData.map(function(t){return t.start}));this.render(r.map(function(t,e){return{start:o[e],end:r[e],label:n[e]}}));var l=[];return this.store.map(function(t,e){l=l.concat(animateRegion(t,s[e],i[e],r[e]))}),l}},barGraph:{layerClass:function(){return"dataset-units dataset-"+this.constants.index},makeElements:function(t){var e=this.constants;return t.yPositions.map(function(a,i){return datasetBar(t.xPositions[i],a,e.barWidth,e.color,e.valuesOverPoints?e.stacked?t.cumulativeYs[i]:t.values[i]:"",i,a-(e.stacked?t.cumulativeYPos[i]:a),{zeroLine:e.zeroLine,barsWidth:e.barsWidth,minHeight:e.minHeight})})},postMake:function(){this.constants.stacked||this.layer.setAttribute("transform","translate("+this.constants.width*this.constants.index+", 0)")},animateElements:function(t){}},lineGraph:{}},AxisChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.isSeries=t.isSeries,a.valuesOverPoints=t.valuesOverPoints,a.formatTooltipY=t.formatTooltipY,a.formatTooltipX=t.formatTooltipX,a.barOptions=t.barOptions||{},a.lineOptions=t.lineOptions||{},a.type=t.type||"line",a.xAxisMode=t.xAxisMode||"span",a.yAxisMode=t.yAxisMode||"span",a.zeroLine=a.height,a.setup(),a}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this),this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"prepareData",value:function(){return dataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data,this.type)}},{key:"prepareFirstData",value:function(){return zeroDataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data)}},{key:"calc",value:function(){this.calcXPositions(),this.calcYAxisParameters(this.getAllYValues(),"line"===this.type)}},{key:"calcXPositions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map(function(e,a){return floatTwo(t.xOffset+a*t.unitWidth)})}}},{key:"calcYAxisParameters",value:function(t){var e=calcChartIntervals(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"false"),a=this.height/getValueRange(e),i=getIntervalSize(e)*a,n=this.height-getZeroIndex(e)*i;this.state.yAxis={labels:e,positions:e.map(function(t){return n-t*a}),scaleMultiplier:a,zeroLine:n},this.calcYUnits(),this.calcYExtremes(),this.calcYRegions()}},{key:"calcYUnits",value:function(){var t=this.state,e=function(e){return e.map(function(e){return scale(e,t.yAxis)})};t.datasets=this.data.datasets.map(function(t,a){var i=t.values,n=t.cumulativeYs||[];return{name:t.name,index:a,chartType:t.chartType,values:i,yPositions:e(i),cumulativeYs:n,cumulativeYPos:e(n)}})}},{key:"calcYExtremes",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,a){e.yPositions.map(function(e,a){e0)for(var l=0;l0&&(t=getPaths(r,s,a.colors[e],a.config.heatline,a.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var p=n.map(function(t,e){return i[e]+","+t});a.elementsToAnimate=a.elementsToAnimate.concat(a.renderer.animatepath(t,p.join("L")))}})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var a=getOffset(t.chartWrapper),i=e.pageX-a.left-t.translateXLeft;e.pageY-a.top-t.translateY=0;s--){var r=a.xAxis.positions[s];if(t>r-a.unitWidth/2){var o=r+this.translateXLeft,l=a.yExtremes[s]+this.translateY,h=this.data.datasets.map(function(t,a){return{title:t.title,value:n?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[a]}});this.tip.set_values(o,l,i[s],"",h),this.tip.show_tip();break}}}}},{key:"getDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.current_index,e={index:t},a=this.y[0];return["svg_units","yUnitPositions","values"].map(function(i){var n=i.slice(0,i.length-1);e[n]=a[i][t]}),e.label=this.xAxis.labels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxis.labels.length&&(t=this.xAxis.labels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,a){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"addDataPoint",this).call(this,t,a,i),this.data.labels.splice(i,0,t),this.data.datasets.map(function(t,e){t.values.splice(i,0,a[e])}),this.update(this.data)}},{key:"removeDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.datasetLength-1;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"removeDataPoint",this).call(this,t),this.data.labels.splice(t,1),this.data.datasets.map(function(e){e.values.splice(t,1)}),this.update(this.data)}}]),e}(BaseChart),LineChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="line",Object.getPrototypeOf(a)!==e.prototype?possibleConstructorReturn(a):(a.setup(),a)}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"span",this.config.yAxisMode=t.yAxisMode||"span",this.config.dotRadius=t.dotRadius||4,this.config.heatline=t.heatline||0,this.config.regionFill=t.regionFill||0,this.config.showDots=t.showDots||1}},{key:"configUnits",value:function(){this.unitArgs={type:"dot",args:{radius:this.config.dotRadius}}}},{key:"setUnitWidthAndXOffset",value:function(){this.state.unitWidth=this.width/(this.state.datasetLength-1),this.state.xOffset=0}}]),e}(AxisChart),ScatterChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="scatter",t.dotRadius?a.dotRadius=t.dotRadius:a.dotRadius=8,a.setup(),a}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dotRadius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(LineChart),MultiAxisChart=function(t){function e(t){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return inherits(e,t),createClass(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this);var t=this.data.datasets.filter(function(t){return"left"===t.axisPosition}).length;this.translateXLeft=t*Y_AXIS_MARGIN||Y_AXIS_MARGIN,this.translateXRight=(this.data.datasets.length-t)*Y_AXIS_MARGIN||Y_AXIS_MARGIN}},{key:"prepareYAxis",value:function(){}},{key:"prepareData",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var a=0,i=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?a++:i++}})}},{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"tick",this.config.yAxisMode=t.yAxisMode||"span"}},{key:"configUnits",value:function(){this.unitArgs={type:"bar",args:{spaceWidth:this.state.unitWidth/2}}}},{key:"setYAxis",value:function(){var t=this;this.state.datasets.map(function(e){t.calcYAxisParameters(e.yAxis,e.values,"line"===t.unitType)})}},{key:"calcYUnits",value:function(){this.state.datasets.map(function(t){t.positions=t.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"renderConstants",value:function(){var t=this;this.state.datasets.map(function(e){var a="left"===e.yAxis.position?-1*e.yAxis.index*Y_AXIS_MARGIN:t.width+e.yAxis.index*Y_AXIS_MARGIN;t.renderer.xLine(a,"",{pos:"top",mode:"span",stroke:t.colors[i],className:"y-axis-guide"})})}},{key:"getYAxesComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"y axis y-axis-"+a,make:function(){var e=t.state.datasets[a].yAxis;t.renderer.setZeroline(e.zeroline);var i={pos:e.position,mode:"tick",offset:e.index*Y_AXIS_MARGIN,stroke:t.colors[a]};return e.positions.map(function(a,n){return t.renderer.yLine(a,e.labels[n],i)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"dataset-units dataset-"+a,make:function(){var e=t.state.datasets[a],i=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,n){return t.renderer[i.type](t.state.xAxisPositions[n],e,i.args,t.colors[a],n,a,t.state.datasetLength)})},animate:function(e){var i=t.state.datasets[a],n=t.unitArgs.type,s=t.state.xAxisPositions,r=t.state.datasets[a].positions,o=e[e.length-1],l=o.parentNode;if(t.oldState.xExtra>0)for(var h=0;h0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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:"renderComponents",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,a){var i=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[a],width:100*e/t.grand_total+"%"}});t.slices.push(i)})}},{key:"calc",value:function(){}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,a){e.addEventListener("mouseenter",function(){var i=getOffset(t.chartWrapper),n=getOffset(e),s=n.left-i.left+e.offsetWidth/2,r=n.top-i.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[a]:t.labels[a])+": ",l=(100*t.slice_totals[a]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"renderLegend",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="pie",a.elements_to_animate=null,a.hoverRadio=t.hoverRadio||.1,a.max_slices=10,a.max_legend_points=6,a.isAnimate=!1,a.startAngle=t.startAngle||0,a.clockWise=t.clockWise||!1,a.mouseMove=a.mouseMove.bind(a),a.mouseLeave=a.mouseLeave.bind(a),a.setup(),a}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,a){var i=0;return t.data.datasets.map(function(t){i+=t.values[a]}),[i,e]}).filter(function(t){return t[0]>0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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 a=this.centerX,i=this.centerY,n=this.radius,s=this.clockWise;return"M"+a+" "+i+" L"+(a+t.x)+" "+(i+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(a+e.x)+" "+(i+e.y)+" z"}},{key:"renderComponents",value:function(t){var a=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,c=o/a.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,i),f=e.getPositionByAngle(p,i),v=t&&s[l],g=void 0,m=void 0;t?(g=v?v.startPosition:d,m=v?v.endPosition:d):(g=d,m=f);var y=a.makeArcPath(g,m),_=makePath(y,"pie-path","none",a.colors[l]);_.style.transition="transform .3s;",a.drawArea.appendChild(_),a.slices.push(_),a.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:a.grand_total,startAngle:h,endAngle:p,angle:u}),t&&a.elements_to_animate.push([{unit:_,array:a.slices,index:a.slices.length-1},{d:a.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var a=this.radius,i=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,a);return"translate3d("+n.x*i+"px,"+n.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,e,a,i){if(t){var n=this.colors[e];if(a){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=i.pageX-s.left+10,o=i.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,a=this.curActiveSliceIndex,i=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){var n=t.colors[i];a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=t.start,i=void 0===a?"":a,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,c=t.discrete_domains,u=void 0===c?0:c,p=t.count_label,d=void 0===p?"":p,f=t.legend_colors,v=void 0===f?[]:f;classCallCheck(this,e);var g=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));g.type="heatmap",g.domain=s,g.subdomain=o,g.data=h,g.discrete_domains=u,g.count_label=d;var m=new Date;return g.start=i||addDays(m,365),v=v.slice(0,5),g.legend_colors=g.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],g.distribution_size=5,g.translateX=0,g}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:"configure",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),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:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("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 a=0;aa)break;v.getMonth()-t.getMonth()&&(i=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=v}return[s,i]}},{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,a){var i=makeText("y-value-text",e+12,10,t.month_names[t.months[a]].substring(0,3));t.domain_label_group.appendChild(i)})}},{key:"renderComponents",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chartWrapper.style.marginTop="0px",this.chartWrapper.style.paddingTop="0px"}},{key:"bindTooltip",value:function(){var t=this;Array.prototype.slice.call(document.querySelectorAll(".data-group .day")).map(function(e){e.addEventListener("mouseenter",function(e){var a=e.target.getAttribute("data-value"),i=e.target.getAttribute("data-date").split("-"),n=t.month_names[parseInt(i[1])-1].substring(0,3),s=t.chartWrapper.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,c=a+" "+t.count_label,u=" on "+n+" "+i[0]+", "+i[2];t.tip.set_values(l,h,u,c,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bindTooltip()}}]),e}(BaseChart),chartTypes={mixed:AxisChart,multiaxis:MultiAxisChart,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 a=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");return i.type="text/css",a.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function getOffset(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),a=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-a}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];a||(a=i?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(a);return t=i?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var a=void 0,i=void 0;return t<=e?(a=e-t,i=t):(a=t-e,i=e),[a,i]}function equilizeNoOfElements(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return a>0?t=fillArray(t,a):e=fillArray(e,a),[t,e]}function translate(t,e,a,i){var n="string"==typeof e?e:e.join(", ");return[t,{transform:a.join(", ")},i,STD_EASING,"translate",{transform:n}]}function translateVertLine(t,e,a){return translate(t,[a,0],[e,0],MARKER_LINE_ANIM_DUR)}function translateHoriLine(t,e,a){return translate(t,[0,a],[0,e],MARKER_LINE_ANIM_DUR)}function animateRegion(t,e,a,i){var n=e-a,s=t.childNodes[0];return[[s,{height:n,"stroke-dasharray":s.getAttribute("width")+", "+n},MARKER_LINE_ANIM_DUR,STD_EASING],translate(t,[0,i],[0,a],MARKER_LINE_ANIM_DUR)]}function animateBar(t,e,a,i){var n=getBarHeightAndYAttr(a,(arguments.length>5&&void 0!==arguments[5]?arguments[5]:{}).zeroLine),s=slicedToArray(n,2),r=s[0],o=s[1];return"rect"!==t.nodeName?[[t.childNodes[0],{width:i,height:r},UNIT_ANIM_DUR,STD_EASING],translate(t,t.getAttribute("transform").split("(")[1].slice(0,-1),[e,o],MARKER_LINE_ANIM_DUR)]:[[t,{width:i,height:r,x:e,y:o},UNIT_ANIM_DUR,STD_EASING]]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var a=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in e){var n=e[i];if("inside"===i)$$2(n).appendChild(a);else if("around"===i){var s=$$2(n);s.parentNode.insertBefore(a,s),a.appendChild(s)}else"styles"===i?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){a.style[t]=n[t]}):("className"===i&&(i="class"),"innerHTML"===i?a.textContent=n:a.setAttribute(i,n))}return a}function makeSVGContainer(t,e,a,i){return createSVG("svg",{className:e,inside:t,width:a,height:i})}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 makeHeatSquare(t,e,a,i){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:a,width:i,height:i,fill:1};return Object.keys(n).map(function(t){s[t]=n[t]}),createSVG("rect",s)}function makeText(t,e,a,i){return createSVG("text",{className:t,x:e,y:a,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:i})}function makeVertLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR);var s=createSVG("line",{className:"line-vertical "+n.className,x1:0,x2:0,y1:a,y2:i,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:a>i?a+LABEL_MARGIN:a-LABEL_MARGIN-FONT_SIZE,dy:FONT_SIZE+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:e}),o=createSVG("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function makeHoriLine(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=BASE_LINE_COLOR),n.lineType||(n.lineType="");var s=createSVG("line",{className:"line-horizontal "+n.className+("dashed"===n.lineType?"dashed":""),x1:a,x2:i,y1:0,y2:0,styles:{stroke:n.stroke}}),r=createSVG("text",{x:a3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=-1*AXIS_TICK_LENGTH,s="span"===i.mode?a+AXIS_TICK_LENGTH:0;return"tick"===i.mode&&"right"===i.pos&&(n=a+AXIS_TICK_LENGTH,s=a),n+=i.offset,s+=i.offset,makeHoriLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function xLine(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var n=a+AXIS_TICK_LENGTH,s="span"===i.mode?-1*AXIS_TICK_LENGTH:a;return"tick"===i.mode&&"top"===i.pos&&(n=-1*AXIS_TICK_LENGTH,s=0),makeVertLine(t,e,n,s,{stroke:i.stroke,className:i.className,lineType:i.lineType})}function yMarker(t,e,a){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=createSVG("text",{className:"chart-label",x:a-getStringWidth(e,5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),s=makeHoriLine(t,"",0,a,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return s.appendChild(n),s}function yRegion(t,e,a,i){var n=t-e,s=createSVG("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:BASE_LINE_COLOR,"stroke-dasharray":a+", "+n},x:0,y:0,width:a,height:n}),r=createSVG("text",{className:"chart-label",x:a-getStringWidth(i,4.5)-LABEL_MARGIN,y:0,dy:FONT_SIZE/-2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{transform:"translate(0, "+e+")"});return o.appendChild(s),o.appendChild(r),o}function datasetBar(t,e,a,i){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:{},l=getBarHeightAndYAttr(e,o.zeroLine),h=slicedToArray(l,2),c=h[0],u=h[1],p=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":s,x:t,y:u-=r,width:a,height:c||o.minHeight});if(n||n.length){p.setAttribute("y",0),p.setAttribute("x",0);var d=createSVG("text",{className:"data-point-value",x:a/2,y:0,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:n}),f=createSVG("g",{transform:"translate("+t+", "+u+")"});return f.appendChild(p),f.appendChild(d),f}return p}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var a=getColor(t),i=!1;"#"==a[0]&&(a=a.slice(1),i=!0);var n=parseInt(a,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(i?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,a){if(t!==e){ALL_CHART_TYPES.includes(t)||console.error("'"+t+"' is not a valid chart type."),COMPATIBLE_CHARTS[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var i=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:a.parent,title:a.title,data:a.data,type:t,height:a.height,colors:i?a.colors:void 0})}}function animateSVGElement(t,e,a){var i=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 c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:a/1e3+"s",values:c+";"+u,keySplines:EASING[i],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),n?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}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 a=[],i=[];e.map(function(t){var e=t[0],n=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],a.push(r),i.push([s,n]),n.replaceChild(s,e)});var n=t.cloneNode(!0);return i.map(function(t,i){t[1].replaceChild(a[i],t[0]),e[i][0]=a[i]}),n}function runSMILAnimation(t,e,a){if(0!==a.length){var i=animateSVG(e,a);e.parentNode==t&&(t.removeChild(e),t.appendChild(i)),setTimeout(function(){i.parentNode==t&&(t.removeChild(i),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function dataPrep(t,e){t.labels=t.labels||[];var a=t.labels.length,i=t.datasets,n=new Array(a).fill(0);return i||(i=[{values:n}]),i.map(function(t,i){if(t.values){var s=t.values;s=(s=s.map(function(t){return isNaN(t)?0:t})).length>a?s.slice(0,a):fillArray(s,a-s.length,0)}else t.values=n;t.chartType||(AXIS_DATASET_CHART_TYPES.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(function(t){if(t.end0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var a=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,a)),a]}function getChartRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=Math.ceil(t),i=Math.floor(e),n=a-i,s=n,r=1;n>5&&(n%2!=0&&(n=++a-i),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(i+r*l);return o}function getChartIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=normalize(t),i=slicedToArray(a,2),n=i[0],s=i[1],r=e?e/Math.pow(10,s):0,o=getChartRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcChartIntervals(t){function e(t,e){for(var a=getChartIntervals(t),i=a[1]-a[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],i=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(i>=0&&n>=0)normalize(i)[1],s=a?getChartIntervals(i,n):getChartIntervals(i);else if(i>0&&n<0){var r=Math.abs(n);i>=r?(normalize(i)[1],s=e(i,r)):(normalize(r)[1],s=e(r,i).map(function(t){return-1*t}))}else if(i<=0&&n<=0){var o=Math.abs(n),l=Math.abs(i);normalize(o)[1],s=(s=a?getChartIntervals(o,l):getChartIntervals(o)).reverse().map(function(t){return-1*t})}return s}function getZeroIndex(t){var e=getIntervalSize(t);return t.indexOf(0)>=0?t.indexOf(0):t[0]>0?-1*t[0]/e:-1*t[t.length-1]/e+(t.length-1)}function getIntervalSize(t){return t[1]-t[0]}function getValueRange(t){return t[t.length-1]-t[0]}function scale(t,e){return floatTwo(e.zeroLine-t*e.scaleMultiplier)}function calcDistribution(t,e){for(var a=Math.max.apply(Math,toConsumableArray(t)),i=1/(e-1),n=[],s=0;s9?"":"0")+e,(a>9?"":"0")+a,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"line"===t?(e.type="line",new AxisChart(e)):"bar"===t?(e.type="bar",new AxisChart(e)):chartTypes[t]?new chartTypes[t](e):void console.error("Undefined chart type: "+t)}__$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{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path,.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .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 a(t,e){return new Promise(function(a,n){var o={key:t,arg:e,resolve:a,reject:n,next:null};r?r=r.next=o:(s=r=o,i(t,e))})}function i(a,s){try{var r=e[a](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){i("next",t)},function(t){i("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)?i(s.key,s.arg):r=null}var s,r;this._invoke=a,"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 a=0;a\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,a){var i=t.colors[a]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+i},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,a=this.container.querySelector(".svg-pointer");if(this.left<0)a.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var i="calc(50% + "+(this.left-e)+"px)";a.style.left=i,this.left=e}else a.style.left="50%"}},{key:"set_values",value:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=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=a,this.title_value=i,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}(),UNIT_ANIM_DUR=350,PATH_ANIM_DUR=350,MARKER_LINE_ANIM_DUR=UNIT_ANIM_DUR,REPLACE_ALL_NEW_DUR=250,STD_EASING="easein",AXIS_TICK_LENGTH=6,LABEL_MARGIN=4,FONT_SIZE=10,BASE_LINE_COLOR="#dadada",AxisChartRenderer=function(){function t(e){classCallCheck(this,t),this.refreshState(e)}return createClass(t,[{key:"refreshState",value:function(t){this.totalHeight=t.totalHeight,this.totalWidth=t.totalWidth,this.zeroLine=t.zeroLine,this.unitWidth=t.unitWidth,this.xAxisMode=t.xAxisMode,this.yAxisMode=t.yAxisMode}},{key:"setZeroline",value:function(t){this.zeroLine=t}},{key:"xMarker",value:function(){}},{key:"xRegion",value:function(){return createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"animatebar",value:function(t,e,a,i,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(a,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*i,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,a){return[t,{cx:e,cy:a},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var a=[],i=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];if(a.push(i),t[1]){var n="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+n+e+s},PATH_ANIM_DUR,STD_EASING];a.push(r)}return a}}]),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:[]},EASING={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},BaseChart=function(){function t(e){var a=e.height,i=void 0===a?240:a,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type),u=void 0===c?"":c,p=e.parent,d=e.data;classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof p?document.querySelector(p):p,this.title=s,this.subtitle=o,this.argHeight=i,this.type=u,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.realData=this.prepareData(d),this.data=this.prepareFirstData(this.realData),this.colors=[],this.config={},this.state={},this.options={},this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){var e=this;this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:1},this.setMargins(),window.addEventListener("resize",function(){return e.draw()}),window.addEventListener("orientationchange",function(){return e.draw()})}},{key:"setColors",value:function(){var t=this.rawChartArgs,e="percentage"===t.type||"pie"===t.type?t.data.labels:t.data.datasets;!t.colors||e&&t.colors.length'+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.chartWrapper=this.container.querySelector(".frappe-chart"),this.statsWrapper=this.container.querySelector(".graph-stats-container")}},{key:"makeTooltip",value:function(){this.tip=new SvgTip({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.makeChartArea(),this.calc(),this.initComponents(),this.setupComponents(),this.components.forEach(function(e){return e.setup(t.drawArea)}),this.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),e&&(this.data=this.realData,setTimeout(function(){t.update()},1e3))}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data;this.data=this.prepareData(t),this.calc(),this.render()}},{key:"prepareData",value:function(){}},{key:"calc",value:function(){}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.components,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=[];t.forEach(function(t){a=a.concat(t.update(e))}),a.length>0&&runSMILAnimation(this.chartWrapper,this.svg,a)}},{key:"makeChartArea",value:function(){this.svg&&this.chartWrapper.removeChild(this.svg),this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"renderLegend",value:function(){}},{key:"setupNavigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isNavigable||(this.makeOverlay(),e&&(this.bindOverlay(),document.addEventListener("keydown",function(e){isElementInViewport(t.chartWrapper)&&("37"==(e=e||window.event).keyCode?t.onLeftArrow():"39"==e.keyCode?t.onRightArrow():"38"==e.keyCode?t.onUpArrow():"40"==e.keyCode?t.onDownArrow():"13"==e.keyCode&&t.onEnterKey())})))}},{key:"makeOverlay",value:function(){}},{key:"bindOverlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"onLeftArrow",value:function(){}},{key:"onRightArrow",value:function(){}},{key:"onUpArrow",value:function(){}},{key:"onDownArrow",value:function(){}},{key:"onEnterKey",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"setCurrentDataPoint",value:function(t){}},{key:"updateDataset",value:function(t,e){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"updateDatasets",value:function(t){}},{key:"updateDataPoint",value:function(t){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,MIN_BAR_PERCENT_HEIGHT=.01,DEFAULT_AXIS_CHART_TYPE="line",AXIS_DATASET_CHART_TYPES=["line","bar"],BAR_CHART_SPACE_RATIO=.5,ChartComponent$1=function(){function t(e){var a=e.layerClass,i=void 0===a?"":a,n=e.layerTransform,s=void 0===n?"":n,r=e.constants,o=e.getData,l=e.makeElements,h=e.animateElements;classCallCheck(this,t),this.layerTransform=s,this.constants=r,this.makeElements=l,this.getData=o,this.animateElements=h,this.store=[],this.layerClass=i,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}return createClass(t,[{key:"refresh",value:function(t){this.data=t||this.getData()}},{key:"setup",value:function(t){this.layer=makeSVGGroup(t,this.layerClass,this.layerTransform)}},{key:"make",value:function(){this.render(this.data),this.oldData=this.data}},{key:"render",value:function(t){var e=this;this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(function(t){e.layer.appendChild(t)})}},{key:"update",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refresh();var a=[];return e&&(a=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),a}}]),t}(),componentConfigs={yAxis:{layerClass:"y axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return yLine(a,t.labels[i],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateHoriLine(t,e[a],i[a])})}},xAxis:{layerClass:"x axis",makeElements:function(t){var e=this;return t.positions.map(function(a,i){return xLine(a,t.labels[i],e.constants.height,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,a=t.labels,i=this.oldData.positions,n=this.oldData.labels,s=equilizeNoOfElements(i,e),r=slicedToArray(s,2);i=r[0],e=r[1];var o=equilizeNoOfElements(n,a),l=slicedToArray(o,2);return n=l[0],a=l[1],this.render({positions:i,labels:a}),this.store.map(function(t,a){return translateVertLine(t,e[a],i[a])})}},yMarkers:{layerClass:"y-markers",makeElements:function(t){var e=this;return t.map(function(t){return yMarker(t.position,t.label,e.constants.width,{pos:"right",mode:"span",lineType:"dashed"})})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.position}),n=t.map(function(t){return t.label}),s=this.oldData.map(function(t){return t.position});this.oldData.map(function(t){return t.label});return this.render(s.map(function(t,e){return{position:s[e],label:n[e]}})),this.store.map(function(t,e){return translateHoriLine(t,i[e],s[e])})}},yRegions:{layerClass:"y-regions",makeElements:function(t){var e=this;return t.map(function(t){return yRegion(t.start,t.end,e.constants.width,t.label)})},animateElements:function(t){var e=equilizeNoOfElements(this.oldData,t),a=slicedToArray(e,2);this.oldData=a[0];var i=(t=a[1]).map(function(t){return t.end}),n=t.map(function(t){return t.label}),s=t.map(function(t){return t.start}),r=this.oldData.map(function(t){return t.end}),o=(this.oldData.map(function(t){return t.label}),this.oldData.map(function(t){return t.start}));this.render(r.map(function(t,e){return{start:o[e],end:r[e],label:n[e]}}));var l=[];return this.store.map(function(t,e){l=l.concat(animateRegion(t,s[e],i[e],r[e]))}),l}},barGraph:{layerClass:function(){return"dataset-units dataset-"+this.constants.index},makeElements:function(t){var e=this.constants;return t.yPositions.map(function(a,i){return datasetBar(t.xPositions[i],a,t.barWidth,e.color,e.valuesOverPoints?e.stacked?t.cumulativeYs[i]:t.values[i]:"",i,a-(e.stacked?t.cumulativeYPos[i]:a),{zeroLine:t.zeroLine,barsWidth:t.barsWidth,minHeight:e.minHeight})})},animateElements:function(t){var e=this.constants,a=t.xPositions,i=t.yPositions,n=t.cumulativeYPos,s=t.values,r=t.cumulativeYs,o=this.oldData.xPositions,l=this.oldData.yPositions,h=this.oldData.cumulativeYPos,c=this.oldData.values,u=this.oldData.cumulativeYs,p=equilizeNoOfElements(o,a),d=slicedToArray(p,2);o=d[0],a=d[1];var f=equilizeNoOfElements(l,i),v=slicedToArray(f,2);l=v[0],i=v[1];var m=equilizeNoOfElements(h,n),g=slicedToArray(m,2);h=g[0],n=g[1];var y=equilizeNoOfElements(c,s),_=slicedToArray(y,2);c=_[0],s=_[1];var x=equilizeNoOfElements(u,r),b=slicedToArray(x,2);u=b[0],r=b[1],this.render({xPositions:o,yPositions:l,cumulativeYPos:h,values:s,cumulativeYs:r,zeroLine:this.oldData.zeroLine,barsWidth:this.oldData.barsWidth,barWidth:this.oldData.barWidth});var A=[];return this.store.map(function(n,s){A=A.concat(animateBar(n,a[s],i[s],t.barWidth,e.index,{zeroLine:t.zeroLine}))}),A}},lineGraph:{}},AxisChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.isSeries=t.isSeries,a.valuesOverPoints=t.valuesOverPoints,a.formatTooltipY=t.formatTooltipY,a.formatTooltipX=t.formatTooltipX,a.barOptions=t.barOptions||{},a.lineOptions=t.lineOptions||{},a.type=t.type||"line",a.xAxisMode=t.xAxisMode||"span",a.yAxisMode=t.yAxisMode||"span",a.zeroLine=a.height,a.setup(),a}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this),this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"prepareData",value:function(){return dataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data,this.type)}},{key:"prepareFirstData",value:function(){return zeroDataPrep(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data)}},{key:"calc",value:function(){this.calcXPositions(),this.calcYAxisParameters(this.getAllYValues(),"line"===this.type)}},{key:"calcXPositions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map(function(e,a){return floatTwo(t.xOffset+a*t.unitWidth)})}}},{key:"calcYAxisParameters",value:function(t){var e=calcChartIntervals(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"false"),a=this.height/getValueRange(e),i=getIntervalSize(e)*a,n=this.height-getZeroIndex(e)*i;this.state.yAxis={labels:e,positions:e.map(function(t){return n-t*a}),scaleMultiplier:a,zeroLine:n},this.calcYUnits(),this.calcYExtremes(),this.calcYRegions()}},{key:"calcYUnits",value:function(){var t=this.state,e=function(e){return e.map(function(e){return scale(e,t.yAxis)})};t.datasets=this.data.datasets.map(function(t,a){var i=t.values,n=t.cumulativeYs||[];return{name:t.name,index:a,chartType:t.chartType,values:i,yPositions:e(i),cumulativeYs:n,cumulativeYPos:e(n)}})}},{key:"calcYExtremes",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,a){e.yPositions.map(function(e,a){e0)for(var l=0;l0&&(t=getPaths(r,s,a.colors[e],a.config.heatline,a.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var p=n.map(function(t,e){return i[e]+","+t});a.elementsToAnimate=a.elementsToAnimate.concat(a.renderer.animatepath(t,p.join("L")))}})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var a=getOffset(t.chartWrapper),i=e.pageX-a.left-t.translateXLeft;e.pageY-a.top-t.translateY=0;s--){var r=a.xAxis.positions[s];if(t>r-a.unitWidth/2){var o=r+this.translateXLeft,l=a.yExtremes[s]+this.translateY,h=this.data.datasets.map(function(t,a){return{title:t.title,value:n?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[a]}});this.tip.set_values(o,l,i[s],"",h),this.tip.show_tip();break}}}}},{key:"getDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.current_index,e={index:t},a=this.y[0];return["svg_units","yUnitPositions","values"].map(function(i){var n=i.slice(0,i.length-1);e[n]=a[i][t]}),e.label=this.xAxis.labels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxis.labels.length&&(t=this.xAxis.labels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,a){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"addDataPoint",this).call(this,t,a,i),this.data.labels.splice(i,0,t),this.data.datasets.map(function(t,e){t.values.splice(i,0,a[e])}),this.update(this.data)}},{key:"removeDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.datasetLength-1;get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"removeDataPoint",this).call(this,t),this.data.labels.splice(t,1),this.data.datasets.map(function(e){e.values.splice(t,1)}),this.update(this.data)}}]),e}(BaseChart),LineChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="line",Object.getPrototypeOf(a)!==e.prototype?possibleConstructorReturn(a):(a.setup(),a)}return inherits(e,t),createClass(e,[{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"span",this.config.yAxisMode=t.yAxisMode||"span",this.config.dotRadius=t.dotRadius||4,this.config.heatline=t.heatline||0,this.config.regionFill=t.regionFill||0,this.config.showDots=t.showDots||1}},{key:"configUnits",value:function(){this.unitArgs={type:"dot",args:{radius:this.config.dotRadius}}}},{key:"setUnitWidthAndXOffset",value:function(){this.state.unitWidth=this.width/(this.state.datasetLength-1),this.state.xOffset=0}}]),e}(AxisChart),ScatterChart=function(t){function e(t){classCallCheck(this,e);var a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="scatter",t.dotRadius?a.dotRadius=t.dotRadius:a.dotRadius=8,a.setup(),a}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dotRadius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(LineChart),MultiAxisChart=function(t){function e(t){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return inherits(e,t),createClass(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setMargins",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this);var t=this.data.datasets.filter(function(t){return"left"===t.axisPosition}).length;this.translateXLeft=t*Y_AXIS_MARGIN||Y_AXIS_MARGIN,this.translateXRight=(this.data.datasets.length-t)*Y_AXIS_MARGIN||Y_AXIS_MARGIN}},{key:"prepareYAxis",value:function(){}},{key:"prepareData",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var a=0,i=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?a++:i++}})}},{key:"configure",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"tick",this.config.yAxisMode=t.yAxisMode||"span"}},{key:"configUnits",value:function(){this.unitArgs={type:"bar",args:{spaceWidth:this.state.unitWidth/2}}}},{key:"setYAxis",value:function(){var t=this;this.state.datasets.map(function(e){t.calcYAxisParameters(e.yAxis,e.values,"line"===t.unitType)})}},{key:"calcYUnits",value:function(){this.state.datasets.map(function(t){t.positions=t.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"renderConstants",value:function(){var t=this;this.state.datasets.map(function(e){var a="left"===e.yAxis.position?-1*e.yAxis.index*Y_AXIS_MARGIN:t.width+e.yAxis.index*Y_AXIS_MARGIN;t.renderer.xLine(a,"",{pos:"top",mode:"span",stroke:t.colors[i],className:"y-axis-guide"})})}},{key:"getYAxesComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"y axis y-axis-"+a,make:function(){var e=t.state.datasets[a].yAxis;t.renderer.setZeroline(e.zeroline);var i={pos:e.position,mode:"tick",offset:e.index*Y_AXIS_MARGIN,stroke:t.colors[a]};return e.positions.map(function(a,n){return t.renderer.yLine(a,e.labels[n],i)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,a){return new ChartComponent({layerClass:"dataset-units dataset-"+a,make:function(){var e=t.state.datasets[a],i=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,n){return t.renderer[i.type](t.state.xAxisPositions[n],e,i.args,t.colors[a],n,a,t.state.datasetLength)})},animate:function(e){var i=t.state.datasets[a],n=t.unitArgs.type,s=t.state.xAxisPositions,r=t.state.datasets[a].positions,o=e[e.length-1],l=o.parentNode;if(t.oldState.xExtra>0)for(var h=0;h0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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:"renderComponents",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,a){var i=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[a],width:100*e/t.grand_total+"%"}});t.slices.push(i)})}},{key:"calc",value:function(){}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,a){e.addEventListener("mouseenter",function(){var i=getOffset(t.chartWrapper),n=getOffset(e),s=n.left-i.left+e.offsetWidth/2,r=n.top-i.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[a]:t.labels[a])+": ",l=(100*t.slice_totals[a]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"renderLegend",value:function(){var t=this,e=this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.type="pie",a.elements_to_animate=null,a.hoverRadio=t.hoverRadio||.1,a.max_slices=10,a.max_legend_points=6,a.isAnimate=!1,a.startAngle=t.startAngle||0,a.clockWise=t.clockWise||!1,a.mouseMove=a.mouseMove.bind(a),a.mouseLeave=a.mouseLeave.bind(a),a.setup(),a}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,a){var i=0;return t.data.datasets.map(function(t){i+=t.values[a]}),[i,e]}).filter(function(t){return t[0]>0}),a=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),a=e.slice(0,this.max_slices-1);var i=0;e.slice(this.max_slices-1).map(function(t){i+=t[0]}),a.push([i,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],a.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 a=this.centerX,i=this.centerY,n=this.radius,s=this.clockWise;return"M"+a+" "+i+" L"+(a+t.x)+" "+(i+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(a+e.x)+" "+(i+e.y)+" z"}},{key:"renderComponents",value:function(t){var a=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,c=o/a.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,i),f=e.getPositionByAngle(p,i),v=t&&s[l],m=void 0,g=void 0;t?(m=v?v.startPosition:d,g=v?v.endPosition:d):(m=d,g=f);var y=a.makeArcPath(m,g),_=makePath(y,"pie-path","none",a.colors[l]);_.style.transition="transform .3s;",a.drawArea.appendChild(_),a.slices.push(_),a.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:a.grand_total,startAngle:h,endAngle:p,angle:u}),t&&a.elements_to_animate.push([{unit:_,array:a.slices,index:a.slices.length-1},{d:a.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var a=this.radius,i=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,a);return"translate3d("+n.x*i+"px,"+n.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,e,a,i){if(t){var n=this.colors[e];if(a){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=i.pageX-s.left+10,o=i.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,a=this.curActiveSliceIndex,i=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(a,i){var n=t.colors[i];a&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[i]+":\n\t\t\t\t\t"+a+"\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 a=t.start,i=void 0===a?"":a,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,c=t.discrete_domains,u=void 0===c?0:c,p=t.count_label,d=void 0===p?"":p,f=t.legend_colors,v=void 0===f?[]:f;classCallCheck(this,e);var m=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));m.type="heatmap",m.domain=s,m.subdomain=o,m.data=h,m.discrete_domains=u,m.count_label=d;var g=new Date;return m.start=i||addDays(g,365),v=v.slice(0,5),m.legend_colors=m.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],m.distribution_size=5,m.translateX=0,m}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:"configure",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),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:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("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 a=0;aa)break;v.getMonth()-t.getMonth()&&(i=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=v}return[s,i]}},{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,a){var i=makeText("y-value-text",e+12,10,t.month_names[t.months[a]].substring(0,3));t.domain_label_group.appendChild(i)})}},{key:"renderComponents",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chartWrapper.style.marginTop="0px",this.chartWrapper.style.paddingTop="0px"}},{key:"bindTooltip",value:function(){var t=this;Array.prototype.slice.call(document.querySelectorAll(".data-group .day")).map(function(e){e.addEventListener("mouseenter",function(e){var a=e.target.getAttribute("data-value"),i=e.target.getAttribute("data-date").split("-"),n=t.month_names[parseInt(i[1])-1].substring(0,3),s=t.chartWrapper.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,c=a+" "+t.count_label,u=" on "+n+" "+i[0]+", "+i[2];t.tip.set_values(l,h,u,c,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bindTooltip()}}]),e}(BaseChart),chartTypes={mixed:AxisChart,multiaxis:MultiAxisChart,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 2c4ccc3..62403cb 100644 --- a/dist/frappe-charts.min.iife.js +++ b/dist/frappe-charts.min.iife.js @@ -1,2 +1,2 @@ -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 a(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 s(t){return parseFloat(t.toFixed(2))}function r(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 o(t,e){return(t+"").length*e}function l(t,e){var i=void 0,a=void 0;return t2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=r(t,i):e=r(e,i),[t,e]}function c(t,e,i,a){return[t,{transform:i.join(", ")},a,vt,"translate",{transform:e.join(", ")}]}function u(t,e,i){return c(t,[i,0],[e,0],dt)}function p(t,e,i){return c(t,[0,i],[0,e],dt)}function d(t,e,i,a){var n=e-i,s=t.childNodes[0];return[[s,{height:n,"stroke-dasharray":s.getAttribute("width")+", "+n},dt,vt],c(t,[0,a],[0,i],dt)]}function f(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function v(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)f(n).appendChild(i);else if("around"===a){var s=f(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":nt(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 m(t,e,i,a){return v("svg",{className:e,inside:t,width:i,height:a})}function g(t){return v("defs",{inside:t})}function y(t,e){return v("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function x(t){var e=v("g",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""});return t.forEach(function(t){return e.appendChild(t)}),e}function b(t){return v("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 _(t,e,i,a){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:i,width:a,height:a,fill:1};return Object.keys(n).map(function(t){s[t]=n[t]}),v("rect",s)}function k(t,e,i,a){return v("text",{className:t,x:e,y:i,dy:yt/2+"px","font-size":yt+"px",innerHTML:a})}function w(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=xt);var s=v("line",{className:"line-vertical "+n.className,x1:0,x2:0,y1:i,y2:a,styles:{stroke:n.stroke}}),r=v("text",{x:0,y:i>a?i+gt:i-gt-yt,dy:yt+"px","font-size":yt+"px","text-anchor":"middle",innerHTML:e}),o=v("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function A(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=xt),n.lineType||(n.lineType="");var s=v("line",{className:"line-horizontal "+n.className+("dashed"===n.lineType?"dashed":""),x1:i,x2:a,y1:0,y2:0,styles:{stroke:n.stroke}}),r=v("text",{x:i3&&void 0!==arguments[3]?arguments[3]:{};a.pos||(a.pos="left"),a.offset||(a.offset=0),a.mode||(a.mode="span"),a.stroke||(a.stroke=xt),a.className||(a.className="");var n=-1*mt,s="span"===a.mode?i+mt:0;return"tick"===a.mode&&"right"===a.pos&&(n=i+mt,s=i),n+=a.offset,s+=a.offset,A(t,e,n,s,{stroke:a.stroke,className:a.className,lineType:a.lineType})}function M(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};a.pos||(a.pos="bottom"),a.offset||(a.offset=0),a.mode||(a.mode="span"),a.stroke||(a.stroke=xt),a.className||(a.className="");var n=i+mt,s="span"===a.mode?-1*mt:i;return"tick"===a.mode&&"top"===a.pos&&(n=-1*mt,s=0),w(t,e,n,s,{stroke:a.stroke,className:a.className,lineType:a.lineType})}function T(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=v("text",{className:"chart-label",x:i-o(e,5)-gt,y:0,dy:yt/-2+"px","font-size":yt+"px","text-anchor":"start",innerHTML:e+""}),s=A(t,"",0,i,{stroke:a.stroke||xt,className:a.className||"",lineType:a.lineType});return s.appendChild(n),s}function P(t,e,i,a){var n=t-e,s=v("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:xt,"stroke-dasharray":i+", "+n},x:0,y:0,width:i,height:n}),r=v("text",{className:"chart-label",x:i-o(a,4.5)-gt,y:0,dy:yt/-2+"px","font-size":yt+"px","text-anchor":"start",innerHTML:a+""}),l=v("g",{transform:"translate(0, "+e+")"});return l.appendChild(s),l.appendChild(r),l}function O(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:{},h=l(e,o.zeroLine),c=ct(h,2),u=c[0],p=c[1],d=v("rect",{className:"bar mini",style:"fill: "+a,"data-point-index":s,x:t-o.barsWidth/2,y:p-r,width:i,height:u||o.minHeight});return n||n.length?x([d,v("text",{className:"data-point-value",x:t,y:p-r,dy:yt/2*-1+"px","font-size":yt+"px","text-anchor":"middle",innerHTML:n})]):d}function L(t){return t>255?255:t<0?0:t}function D(t,e){var i=kt(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=L((n>>16)+e),r=L((n>>8&255)+e),o=L((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function N(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function E(t,e,i){if(t!==e){wt.includes(t)||console.error("'"+t+"' is not a valid chart type."),At[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var a=Ct[e].includes(t);return new Rt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:a?i.colors:void 0})}}function W(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 c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:i/1e3+"s",values:c+";"+u,keySplines:Mt[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),n?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}return[r,o]}function S(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function Y(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=W.apply(void 0,ut(t)),l=ct(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e)});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 j(t,e,i){if(0!==i.length){var a=Y(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},ft)}}function z(t,e){t.labels=t.labels||[];var i=t.labels.length,a=t.datasets,n=new Array(i).fill(0);return a||(a=[{values:n}]),a.map(function(t,a){if(t.values){var s=t.values;s=(s=s.map(function(t){return isNaN(t)?0:t})).length>i?s.slice(0,i):r(s,i-s.length,0)}else t.values=n;t.chartType||(Pt.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(function(t){if(t.end0?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 F(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 B(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=X(t),a=ct(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=F(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function U(t){function e(t,e){for(var i=B(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,ut(t)),n=Math.min.apply(Math,ut(t)),s=[];if(a>=0&&n>=0)X(a)[1],s=i?B(a,n):B(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(X(a)[1],s=e(a,r)):(X(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);X(o)[1],s=(s=i?B(o,l):B(o)).reverse().map(function(t){return-1*t})}return s}function I(t){var e=q(t);return t.indexOf(0)>=0?t.indexOf(0):t[0]>0?-1*t[0]/e:-1*t[t.length-1]/e+(t.length-1)}function q(t){return t[1]-t[0]}function G(t){return t[t.length-1]-t[0]}function Z(t,e){return s(e.zeroLine-t*e.scaleMultiplier)}function J(t,e){for(var i=Math.max.apply(Math,ut(t)),a=1/(e-1),n=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function tt(t,e){return Math.ceil(et(t,e)/7)}function et(t,e){return(V(e)-V(t))/864e5}function it(t,e){t.setDate(t.getDate()+e)}function at(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"line"===t?(e.type="line",new Dt(e)):"bar"===t?(e.type="bar",new Dt(e)):zt[t]?new zt[t](e):void console.error("Undefined chart type: "+t)}!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{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path,.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .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 nt="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},st=(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")}),rt=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}(),dt=350,ft=250,vt="easein",mt=6,gt=4,yt=10,xt="#dadada",bt=(function(){function t(e){st(this,t),this.refreshState(e)}rt(t,[{key:"refreshState",value:function(t){this.totalHeight=t.totalHeight,this.totalWidth=t.totalWidth,this.zeroLine=t.zeroLine,this.unitWidth=t.unitWidth,this.xAxisMode=t.xAxisMode,this.yAxisMode=t.yAxisMode}},{key:"setZeroline",value:function(t){this.zeroLine=t}},{key:"xMarker",value:function(){}},{key:"xRegion",value:function(){return v("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"animatebar",value:function(t,e,i,a,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=l(i,this.zeroLine,this.totalHeight),h=ct(o,2);return e=s+r*a,[t,{width:r,height:h[0],x:e,y:h[1]},350,vt]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},350,vt]}},{key:"animatepath",value:function(t,e){var i=[],a=[t[0],{d:"M"+e},350,vt];if(i.push(a),t[1]){var n="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+n+e+s},350,vt];i.push(r)}return i}}])}(),{"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"}),_t=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],kt=function(t){return bt[t]||t},wt=["line","scatter","bar","percentage","heatmap","pie"],At={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:[]},Ct={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},Mt={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},Tt=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,t.isNavigable),h=void 0===l?0:l,c=(t.showLegend,t.type),u=void 0===c?"":c,p=t.parent,d=t.data;st(this,e),this.rawChartArgs=arguments[0],this.parent="string"==typeof p?document.querySelector(p):p,this.title=s,this.subtitle=o,this.argHeight=a,this.type=u,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.realData=this.prepareData(d),this.data=this.prepareFirstData(this.realData),this.colors=[],this.config={},this.state={},this.options={},this.configure(arguments[0])}return rt(e,[{key:"configure",value:function(t){var e=this;this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:1},this.setMargins(),window.addEventListener("resize",function(){return e.draw()}),window.addEventListener("orientationchange",function(){return e.draw()})}},{key:"setColors",value:function(){var t=this.rawChartArgs,e="percentage"===t.type||"pie"===t.type?t.data.labels:t.data.datasets;!t.colors||e&&t.colors.length'+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.chartWrapper=this.container.querySelector(".frappe-chart"),this.statsWrapper=this.container.querySelector(".graph-stats-container")}},{key:"makeTooltip",value:function(){this.tip=new pt({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.makeChartArea(),this.calc(),this.initComponents(),this.setupComponents(),this.components.forEach(function(e){return e.setup(t.drawArea)}),this.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),e&&(this.data=this.realData,setTimeout(function(){t.update()},1e3))}},{key:"calcWidth",value:function(){this.baseWidth=n(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data;this.data=this.prepareData(t),this.calc(),this.render()}},{key:"prepareData",value:function(){}},{key:"calc",value:function(){}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.components,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=[];t.forEach(function(t){i=i.concat(t.update(e))}),i.length>0&&j(this.chartWrapper,this.svg,i)}},{key:"makeChartArea",value:function(){this.svg&&this.chartWrapper.removeChild(this.svg),this.svg=m(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=g(this.svg),this.drawArea=y(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"renderLegend",value:function(){}},{key:"setupNavigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isNavigable||(this.makeOverlay(),e&&(this.bindOverlay(),document.addEventListener("keydown",function(e){a(t.chartWrapper)&&("37"==(e=e||window.event).keyCode?t.onLeftArrow():"39"==e.keyCode?t.onRightArrow():"38"==e.keyCode?t.onUpArrow():"40"==e.keyCode?t.onDownArrow():"13"==e.keyCode&&t.onEnterKey())})))}},{key:"makeOverlay",value:function(){}},{key:"bindOverlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"onLeftArrow",value:function(){}},{key:"onRightArrow",value:function(){}},{key:"onUpArrow",value:function(){}},{key:"onDownArrow",value:function(){}},{key:"onEnterKey",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"setCurrentDataPoint",value:function(t){}},{key:"updateDataset",value:function(t,e){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"updateDatasets",value:function(t){}},{key:"updateDataPoint",value:function(t){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return E(t,this.type,this.rawChartArgs)}}]),e}(),Pt=["line","bar"],Ot=function(){function t(e){var i=e.layerClass,a=void 0===i?"":i,n=e.layerTransform,s=void 0===n?"":n,r=e.constants,o=e.getData,l=e.makeElements,h=e.postMake,c=e.animateElements;st(this,t),this.layerTransform=s,this.constants=r,this.makeElements=l,this.postMake=h,this.getData=o,this.animateElements=c,this.store=[],this.layerClass=a,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}return rt(t,[{key:"refresh",value:function(t){this.data=t||this.getData()}},{key:"setup",value:function(t){this.layer=y(t,this.layerClass,this.layerTransform)}},{key:"make",value:function(){this.preMake&&this.preMake(),this.render(this.data),this.postMake&&this.postMake(),this.oldData=this.data}},{key:"render",value:function(t){var e=this;this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(function(t){e.layer.appendChild(t)})}},{key:"update",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refresh();var i=[];return e&&(i=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),i}}]),t}(),Lt={yAxis:{layerClass:"y axis",makeElements:function(t){var e=this;return t.positions.map(function(i,a){return C(i,t.labels[a],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,i=t.labels,a=this.oldData.positions,n=this.oldData.labels,s=h(a,e),r=ct(s,2);a=r[0],e=r[1];var o=h(n,i),l=ct(o,2);return n=l[0],i=l[1],this.render({positions:a,labels:i}),this.store.map(function(t,i){return p(t,e[i],a[i])})}},xAxis:{layerClass:"x axis",makeElements:function(t){var e=this;return t.positions.map(function(i,a){return M(i,t.labels[a],e.constants.height,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,i=t.labels,a=this.oldData.positions,n=this.oldData.labels,s=h(a,e),r=ct(s,2);a=r[0],e=r[1];var o=h(n,i),l=ct(o,2);return n=l[0],i=l[1],this.render({positions:a,labels:i}),this.store.map(function(t,i){return u(t,e[i],a[i])})}},yMarkers:{layerClass:"y-markers",makeElements:function(t){var e=this;return t.map(function(t){return T(t.position,t.label,e.constants.width,{pos:"right",mode:"span",lineType:"dashed"})})},animateElements:function(t){var e=h(this.oldData,t),i=ct(e,2);this.oldData=i[0];var a=(t=i[1]).map(function(t){return t.position}),n=t.map(function(t){return t.label}),s=this.oldData.map(function(t){return t.position});this.oldData.map(function(t){return t.label});return this.render(s.map(function(t,e){return{position:s[e],label:n[e]}})),this.store.map(function(t,e){return p(t,a[e],s[e])})}},yRegions:{layerClass:"y-regions",makeElements:function(t){var e=this;return t.map(function(t){return P(t.start,t.end,e.constants.width,t.label)})},animateElements:function(t){var e=h(this.oldData,t),i=ct(e,2);this.oldData=i[0];var a=(t=i[1]).map(function(t){return t.end}),n=t.map(function(t){return t.label}),s=t.map(function(t){return t.start}),r=this.oldData.map(function(t){return t.end}),o=(this.oldData.map(function(t){return t.label}),this.oldData.map(function(t){return t.start}));this.render(r.map(function(t,e){return{start:o[e],end:r[e],label:n[e]}}));var l=[];return this.store.map(function(t,e){l=l.concat(d(t,s[e],a[e],r[e]))}),l}},barGraph:{layerClass:function(){return"dataset-units dataset-"+this.constants.index},makeElements:function(t){var e=this.constants;return t.yPositions.map(function(i,a){return O(t.xPositions[a],i,e.barWidth,e.color,e.valuesOverPoints?e.stacked?t.cumulativeYs[a]:t.values[a]:"",a,i-(e.stacked?t.cumulativeYPos[a]:i),{zeroLine:e.zeroLine,barsWidth:e.barsWidth,minHeight:e.minHeight})})},postMake:function(){this.constants.stacked||this.layer.setAttribute("transform","translate("+this.constants.width*this.constants.index+", 0)")},animateElements:function(t){}},lineGraph:{}},Dt=function(t){function i(t){st(this,i);var e=ht(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t));return e.isSeries=t.isSeries,e.valuesOverPoints=t.valuesOverPoints,e.formatTooltipY=t.formatTooltipY,e.formatTooltipX=t.formatTooltipX,e.barOptions=t.barOptions||{},e.lineOptions=t.lineOptions||{},e.type=t.type||"line",e.xAxisMode=t.xAxisMode||"span",e.yAxisMode=t.yAxisMode||"span",e.zeroLine=e.height,e.setup(),e}return lt(i,t),rt(i,[{key:"configure",value:function(t){ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"setMargins",value:function(){ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setMargins",this).call(this),this.translateXLeft=60,this.translateXRight=60}},{key:"prepareData",value:function(){return z(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data,this.type)}},{key:"prepareFirstData",value:function(){return R(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data)}},{key:"calc",value:function(){this.calcXPositions(),this.calcYAxisParameters(this.getAllYValues(),"line"===this.type)}},{key:"calcXPositions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map(function(e,i){return s(t.xOffset+i*t.unitWidth)})}}},{key:"calcYAxisParameters",value:function(t){var e=U(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"false"),i=this.height/G(e),a=q(e)*i,n=this.height-I(e)*a;this.state.yAxis={labels:e,positions:e.map(function(t){return n-t*i}),scaleMultiplier:i,zeroLine:n},this.calcYUnits(),this.calcYExtremes(),this.calcYRegions()}},{key:"calcYUnits",value:function(){var t=this.state,e=function(e){return e.map(function(e){return Z(e,t.yAxis)})};t.datasets=this.data.datasets.map(function(t,i){var a=t.values,n=t.cumulativeYs||[];return{name:t.name,index:i,chartType:t.chartType,values:a,yPositions:e(a),cumulativeYs:n,cumulativeYPos:e(n)}})}},{key:"calcYExtremes",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.yPositions.map(function(e,i){e0)for(var l=0;l0&&(t=getPaths(r,s,i.colors[e],i.config.heatline,i.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var d=n.map(function(t,e){return a[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,d.join("L")))}})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(i){var a=e(t.chartWrapper),n=i.pageX-a.left-t.translateXLeft;i.pageY-a.top-t.translateY=0;s--){var r=i.xAxis.positions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=this.data.datasets.map(function(t,i){return{title:t.title,value:n?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[i]}});this.tip.set_values(o,l,a[s],"",h),this.tip.show_tip();break}}}}},{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","yUnitPositions","values"].map(function(a){var n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.xAxis.labels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxis.labels.length&&(t=this.xAxis.labels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"addDataPoint",this).call(this,t,e,a),this.data.labels.splice(a,0,t),this.data.datasets.map(function(t,i){t.values.splice(a,0,e[i])}),this.update(this.data)}},{key:"removeDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.datasetLength-1;ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"removeDataPoint",this).call(this,t),this.data.labels.splice(t,1),this.data.datasets.map(function(e){e.values.splice(t,1)}),this.update(this.data)}}]),i}(Tt),Nt=function(t){function e(t){st(this,e);var i=ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="scatter",t.dotRadius?i.dotRadius=t.dotRadius:i.dotRadius=8,i.setup(),i}return lt(e,t),rt(e,[{key:"setup_values",value:function(){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dotRadius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(function(t){function e(t){st(this,e);var i=ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?ht(i):(i.setup(),i)}return lt(e,t),rt(e,[{key:"configure",value:function(t){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"span",this.config.yAxisMode=t.yAxisMode||"span",this.config.dotRadius=t.dotRadius||4,this.config.heatline=t.heatline||0,this.config.regionFill=t.regionFill||0,this.config.showDots=t.showDots||1}},{key:"configUnits",value:function(){this.unitArgs={type:"dot",args:{radius:this.config.dotRadius}}}},{key:"setUnitWidthAndXOffset",value:function(){this.state.unitWidth=this.width/(this.state.datasetLength-1),this.state.xOffset=0}}]),e}(Dt)),Et=function(t){function e(t){return st(this,e),ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return lt(e,t),rt(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setMargins",value:function(){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this);var t=this.data.datasets.filter(function(t){return"left"===t.axisPosition}).length;this.translateXLeft=60*t||60,this.translateXRight=60*(this.data.datasets.length-t)||60}},{key:"prepareYAxis",value:function(){}},{key:"prepareData",value:function(t){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var i=0,a=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?i++:a++}})}},{key:"configure",value:function(t){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"tick",this.config.yAxisMode=t.yAxisMode||"span"}},{key:"configUnits",value:function(){this.unitArgs={type:"bar",args:{spaceWidth:this.state.unitWidth/2}}}},{key:"setYAxis",value:function(){var t=this;this.state.datasets.map(function(e){t.calcYAxisParameters(e.yAxis,e.values,"line"===t.unitType)})}},{key:"calcYUnits",value:function(){this.state.datasets.map(function(t){t.positions=t.values.map(function(e){return s(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"renderConstants",value:function(){var t=this;this.state.datasets.map(function(e){var a="left"===e.yAxis.position?-1*e.yAxis.index*60:t.width+60*e.yAxis.index;t.renderer.xLine(a,"",{pos:"top",mode:"span",stroke:t.colors[i],className:"y-axis-guide"})})}},{key:"getYAxesComponents",value:function(){var t=this;return this.data.datasets.map(function(e,i){return new ChartComponent({layerClass:"y axis y-axis-"+i,make:function(){var e=t.state.datasets[i].yAxis;t.renderer.setZeroline(e.zeroline);var a={pos:e.position,mode:"tick",offset:60*e.index,stroke:t.colors[i]};return e.positions.map(function(i,n){return t.renderer.yLine(i,e.labels[n],a)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,i){return new ChartComponent({layerClass:"dataset-units dataset-"+i,make:function(){var e=t.state.datasets[i],a=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,n){return t.renderer[a.type](t.state.xAxisPositions[n],e,a.args,t.colors[i],n,i,t.state.datasetLength)})},animate:function(e){var a=t.state.datasets[i],n=t.unitArgs.type,s=t.state.xAxisPositions,r=t.state.datasets[i].positions,o=e[e.length-1],l=o.parentNode;if(t.oldState.xExtra>0)for(var h=0;h0}),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:"renderComponents",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.percentageBar,styles:{background:e.colors[a],width:100*i/e.grand_total+"%"}});e.slices.push(n)})}},{key:"calc",value:function(){}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(i,a){i.addEventListener("mouseenter",function(){var n=e(t.chartWrapper),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:"renderLegend",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.statsWrapper}).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}(Tt),St=Math.PI/180,Yt=function(i){function a(t){st(this,a);var e=ht(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 lt(a,i),rt(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:"renderComponents",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,c=o/e.grand_total*360,u=n?-c:c,p=r+=u,d=a.getPositionByAngle(h,i),f=a.getPositionByAngle(p,i),v=t&&s[l],m=void 0,g=void 0;t?(m=v?v.startPosition:d,g=v?v.endPosition:d):(m=d,g=f);var y=e.makeArcPath(m,g),x=b(y,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.drawArea.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:e.grand_total,startAngle:h,endAngle:p,angle:u}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&j(this.chartWrapper,this.svg,this.elements_to_animate)}},{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){S(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=D(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])+": ",c=(100*this.slice_totals[i]/this.grand_total).toFixed(1);this.tip.set_values(o,l,h,c+"%"),this.tip.show_tip()}else S(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.statsWrapper}).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*St)*e,y:Math.cos(t*St)*e}}}]),a}(Tt),jt=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,c=t.discrete_domains,u=void 0===c?0:c,p=t.count_label,d=void 0===p?"":p,f=t.legend_colors,v=void 0===f?[]:f;st(this,e);var m=ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));m.type="heatmap",m.domain=s,m.subdomain=o,m.data=h,m.discrete_domains=u,m.count_label=d;var g=new Date;return m.start=a||it(g,365),v=v.slice(0,5),m.legend_colors=m.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],m.distribution_size=5,m.translateX=0,m}return lt(e,t),rt(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){N(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"configure",value:function(){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),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()&&it(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&it(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=tt(this.first_week_start+"",this.last_week_start+"")+1}},{key:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("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=J(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:"renderComponents",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chartWrapper.style.marginTop="0px",this.chartWrapper.style.paddingTop="0px"}},{key:"bindTooltip",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.chartWrapper.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,c=i+" "+t.count_label,u=" on "+n+" "+a[0]+", "+a[2];t.tip.set_values(l,h,u,c,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bindTooltip()}}]),e}(Tt),zt={mixed:Dt,multiaxis:Et,scatter:Nt,percentage:Wt,heatmap:jt,pie:Yt},Rt=function t(e){return st(this,t),at(e.type,arguments[0])};return Rt}(); +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 a(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 s(t){return parseFloat(t.toFixed(2))}function r(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 o(t,e){return(t+"").length*e}function l(t,e){var i=void 0,a=void 0;return t<=e?(i=e-t,a=t):(i=t-e,a=e),[i,a]}function h(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=r(t,i):e=r(e,i),[t,e]}function c(t,e,i,a){var n="string"==typeof e?e:e.join(", ");return[t,{transform:i.join(", ")},a,mt,"translate",{transform:n}]}function u(t,e,i){return c(t,[i,0],[e,0],ft)}function p(t,e,i){return c(t,[0,i],[0,e],ft)}function d(t,e,i,a){var n=e-i,s=t.childNodes[0];return[[s,{height:n,"stroke-dasharray":s.getAttribute("width")+", "+n},ft,mt],c(t,[0,a],[0,i],ft)]}function f(t,e,i,a){var n=l(i,(arguments.length>5&&void 0!==arguments[5]?arguments[5]:{}).zeroLine),s=ct(n,2),r=s[0],o=s[1];return"rect"!==t.nodeName?[[t.childNodes[0],{width:a,height:r},dt,mt],c(t,t.getAttribute("transform").split("(")[1].slice(0,-1),[e,o],ft)]:[[t,{width:a,height:r,x:e,y:o},dt,mt]]}function v(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function m(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)v(n).appendChild(i);else if("around"===a){var s=v(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":nt(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 g(t,e,i,a){return m("svg",{className:e,inside:t,width:i,height:a})}function y(t){return m("defs",{inside:t})}function x(t,e){return m("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function b(t){return m("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 _(t,e,i,a){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:i,width:a,height:a,fill:1};return Object.keys(n).map(function(t){s[t]=n[t]}),m("rect",s)}function k(t,e,i,a){return m("text",{className:t,x:e,y:i,dy:xt/2+"px","font-size":xt+"px",innerHTML:a})}function w(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=bt);var s=m("line",{className:"line-vertical "+n.className,x1:0,x2:0,y1:i,y2:a,styles:{stroke:n.stroke}}),r=m("text",{x:0,y:i>a?i+yt:i-yt-xt,dy:xt+"px","font-size":xt+"px","text-anchor":"middle",innerHTML:e}),o=m("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function A(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};n.stroke||(n.stroke=bt),n.lineType||(n.lineType="");var s=m("line",{className:"line-horizontal "+n.className+("dashed"===n.lineType?"dashed":""),x1:i,x2:a,y1:0,y2:0,styles:{stroke:n.stroke}}),r=m("text",{x:i3&&void 0!==arguments[3]?arguments[3]:{};a.pos||(a.pos="left"),a.offset||(a.offset=0),a.mode||(a.mode="span"),a.stroke||(a.stroke=bt),a.className||(a.className="");var n=-1*gt,s="span"===a.mode?i+gt:0;return"tick"===a.mode&&"right"===a.pos&&(n=i+gt,s=i),n+=a.offset,s+=a.offset,A(t,e,n,s,{stroke:a.stroke,className:a.className,lineType:a.lineType})}function M(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};a.pos||(a.pos="bottom"),a.offset||(a.offset=0),a.mode||(a.mode="span"),a.stroke||(a.stroke=bt),a.className||(a.className="");var n=i+gt,s="span"===a.mode?-1*gt:i;return"tick"===a.mode&&"top"===a.pos&&(n=-1*gt,s=0),w(t,e,n,s,{stroke:a.stroke,className:a.className,lineType:a.lineType})}function P(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=m("text",{className:"chart-label",x:i-o(e,5)-yt,y:0,dy:xt/-2+"px","font-size":xt+"px","text-anchor":"start",innerHTML:e+""}),s=A(t,"",0,i,{stroke:a.stroke||bt,className:a.className||"",lineType:a.lineType});return s.appendChild(n),s}function T(t,e,i,a){var n=t-e,s=m("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:bt,"stroke-dasharray":i+", "+n},x:0,y:0,width:i,height:n}),r=m("text",{className:"chart-label",x:i-o(a,4.5)-yt,y:0,dy:xt/-2+"px","font-size":xt+"px","text-anchor":"start",innerHTML:a+""}),l=m("g",{transform:"translate(0, "+e+")"});return l.appendChild(s),l.appendChild(r),l}function D(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:{},h=l(e,o.zeroLine),c=ct(h,2),u=c[0],p=c[1],d=m("rect",{className:"bar mini",style:"fill: "+a,"data-point-index":s,x:t,y:p-=r,width:i,height:u||o.minHeight});if(n||n.length){d.setAttribute("y",0),d.setAttribute("x",0);var f=m("text",{className:"data-point-value",x:i/2,y:0,dy:xt/2*-1+"px","font-size":xt+"px","text-anchor":"middle",innerHTML:n}),v=m("g",{transform:"translate("+t+", "+p+")"});return v.appendChild(d),v.appendChild(f),v}return d}function L(t){return t>255?255:t<0?0:t}function O(t,e){var i=wt(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=L((n>>16)+e),r=L((n>>8&255)+e),o=L((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function N(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function W(t,e,i){if(t!==e){At.includes(t)||console.error("'"+t+"' is not a valid chart type."),Ct[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var a=Mt[e].includes(t);return new Ht({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:a?i.colors:void 0})}}function E(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 c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:i/1e3+"s",values:c+";"+u,keySplines:Pt[a],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};n&&(p.type=n);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),n?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}return[r,o]}function S(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function Y(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=E.apply(void 0,ut(t)),l=ct(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e)});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 z(t,e,i){if(0!==i.length){var a=Y(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},vt)}}function j(t,e){t.labels=t.labels||[];var i=t.labels.length,a=t.datasets,n=new Array(i).fill(0);return a||(a=[{values:n}]),a.map(function(t,a){if(t.values){var s=t.values;s=(s=s.map(function(t){return isNaN(t)?0:t})).length>i?s.slice(0,i):r(s,i-s.length,0)}else t.values=n;t.chartType||(Dt.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(function(t){if(t.end0?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 F(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 B(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=X(t),a=ct(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=F(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function U(t){function e(t,e){for(var i=B(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,ut(t)),n=Math.min.apply(Math,ut(t)),s=[];if(a>=0&&n>=0)X(a)[1],s=i?B(a,n):B(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(X(a)[1],s=e(a,r)):(X(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);X(o)[1],s=(s=i?B(o,l):B(o)).reverse().map(function(t){return-1*t})}return s}function I(t){var e=q(t);return t.indexOf(0)>=0?t.indexOf(0):t[0]>0?-1*t[0]/e:-1*t[t.length-1]/e+(t.length-1)}function q(t){return t[1]-t[0]}function G(t){return t[t.length-1]-t[0]}function Z(t,e){return s(e.zeroLine-t*e.scaleMultiplier)}function J(t,e){for(var i=Math.max.apply(Math,ut(t)),a=1/(e-1),n=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function tt(t,e){return Math.ceil(et(t,e)/7)}function et(t,e){return(V(e)-V(t))/864e5}function it(t,e){t.setDate(t.getDate()+e)}function at(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"line"===t?(e.type="line",new Nt(e)):"bar"===t?(e.type="bar",new Nt(e)):Rt[t]?new Rt[t](e):void console.error("Undefined chart type: "+t)}!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{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path,.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .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 nt="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},st=(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")}),rt=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}(),dt=350,ft=dt,vt=250,mt="easein",gt=6,yt=4,xt=10,bt="#dadada",_t=(function(){function t(e){st(this,t),this.refreshState(e)}rt(t,[{key:"refreshState",value:function(t){this.totalHeight=t.totalHeight,this.totalWidth=t.totalWidth,this.zeroLine=t.zeroLine,this.unitWidth=t.unitWidth,this.xAxisMode=t.xAxisMode,this.yAxisMode=t.yAxisMode}},{key:"setZeroline",value:function(t){this.zeroLine=t}},{key:"xMarker",value:function(){}},{key:"xRegion",value:function(){return m("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"animatebar",value:function(t,e,i,a,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=l(i,this.zeroLine,this.totalHeight),h=ct(o,2);return e=s+r*a,[t,{width:r,height:h[0],x:e,y:h[1]},dt,mt]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},dt,mt]}},{key:"animatepath",value:function(t,e){var i=[],a=[t[0],{d:"M"+e},350,mt];if(i.push(a),t[1]){var n="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+n+e+s},350,mt];i.push(r)}return i}}])}(),{"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"}),kt=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],wt=function(t){return _t[t]||t},At=["line","scatter","bar","percentage","heatmap","pie"],Ct={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:[]},Mt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},Pt={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"},Tt=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,t.isNavigable),h=void 0===l?0:l,c=(t.showLegend,t.type),u=void 0===c?"":c,p=t.parent,d=t.data;st(this,e),this.rawChartArgs=arguments[0],this.parent="string"==typeof p?document.querySelector(p):p,this.title=s,this.subtitle=o,this.argHeight=a,this.type=u,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.realData=this.prepareData(d),this.data=this.prepareFirstData(this.realData),this.colors=[],this.config={},this.state={},this.options={},this.configure(arguments[0])}return rt(e,[{key:"configure",value:function(t){var e=this;this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:1},this.setMargins(),window.addEventListener("resize",function(){return e.draw()}),window.addEventListener("orientationchange",function(){return e.draw()})}},{key:"setColors",value:function(){var t=this.rawChartArgs,e="percentage"===t.type||"pie"===t.type?t.data.labels:t.data.datasets;!t.colors||e&&t.colors.length'+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.chartWrapper=this.container.querySelector(".frappe-chart"),this.statsWrapper=this.container.querySelector(".graph-stats-container")}},{key:"makeTooltip",value:function(){this.tip=new pt({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.makeChartArea(),this.calc(),this.initComponents(),this.setupComponents(),this.components.forEach(function(e){return e.setup(t.drawArea)}),this.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),e&&(this.data=this.realData,setTimeout(function(){t.update()},1e3))}},{key:"calcWidth",value:function(){this.baseWidth=n(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data;this.data=this.prepareData(t),this.calc(),this.render()}},{key:"prepareData",value:function(){}},{key:"calc",value:function(){}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.components,e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=[];t.forEach(function(t){i=i.concat(t.update(e))}),i.length>0&&z(this.chartWrapper,this.svg,i)}},{key:"makeChartArea",value:function(){this.svg&&this.chartWrapper.removeChild(this.svg),this.svg=g(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=y(this.svg),this.drawArea=x(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"renderLegend",value:function(){}},{key:"setupNavigation",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isNavigable||(this.makeOverlay(),e&&(this.bindOverlay(),document.addEventListener("keydown",function(e){a(t.chartWrapper)&&("37"==(e=e||window.event).keyCode?t.onLeftArrow():"39"==e.keyCode?t.onRightArrow():"38"==e.keyCode?t.onUpArrow():"40"==e.keyCode?t.onDownArrow():"13"==e.keyCode&&t.onEnterKey())})))}},{key:"makeOverlay",value:function(){}},{key:"bindOverlay",value:function(){}},{key:"bind_units",value:function(){}},{key:"onLeftArrow",value:function(){}},{key:"onRightArrow",value:function(){}},{key:"onUpArrow",value:function(){}},{key:"onDownArrow",value:function(){}},{key:"onEnterKey",value:function(){}},{key:"getDataPoint",value:function(){}},{key:"setCurrentDataPoint",value:function(t){}},{key:"updateDataset",value:function(t,e){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"updateDatasets",value:function(t){}},{key:"updateDataPoint",value:function(t){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return W(t,this.type,this.rawChartArgs)}}]),e}(),Dt=["line","bar"],Lt=function(){function t(e){var i=e.layerClass,a=void 0===i?"":i,n=e.layerTransform,s=void 0===n?"":n,r=e.constants,o=e.getData,l=e.makeElements,h=e.animateElements;st(this,t),this.layerTransform=s,this.constants=r,this.makeElements=l,this.getData=o,this.animateElements=h,this.store=[],this.layerClass=a,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}return rt(t,[{key:"refresh",value:function(t){this.data=t||this.getData()}},{key:"setup",value:function(t){this.layer=x(t,this.layerClass,this.layerTransform)}},{key:"make",value:function(){this.render(this.data),this.oldData=this.data}},{key:"render",value:function(t){var e=this;this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(function(t){e.layer.appendChild(t)})}},{key:"update",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refresh();var i=[];return e&&(i=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),i}}]),t}(),Ot={yAxis:{layerClass:"y axis",makeElements:function(t){var e=this;return t.positions.map(function(i,a){return C(i,t.labels[a],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,i=t.labels,a=this.oldData.positions,n=this.oldData.labels,s=h(a,e),r=ct(s,2);a=r[0],e=r[1];var o=h(n,i),l=ct(o,2);return n=l[0],i=l[1],this.render({positions:a,labels:i}),this.store.map(function(t,i){return p(t,e[i],a[i])})}},xAxis:{layerClass:"x axis",makeElements:function(t){var e=this;return t.positions.map(function(i,a){return M(i,t.labels[a],e.constants.height,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,i=t.labels,a=this.oldData.positions,n=this.oldData.labels,s=h(a,e),r=ct(s,2);a=r[0],e=r[1];var o=h(n,i),l=ct(o,2);return n=l[0],i=l[1],this.render({positions:a,labels:i}),this.store.map(function(t,i){return u(t,e[i],a[i])})}},yMarkers:{layerClass:"y-markers",makeElements:function(t){var e=this;return t.map(function(t){return P(t.position,t.label,e.constants.width,{pos:"right",mode:"span",lineType:"dashed"})})},animateElements:function(t){var e=h(this.oldData,t),i=ct(e,2);this.oldData=i[0];var a=(t=i[1]).map(function(t){return t.position}),n=t.map(function(t){return t.label}),s=this.oldData.map(function(t){return t.position});this.oldData.map(function(t){return t.label});return this.render(s.map(function(t,e){return{position:s[e],label:n[e]}})),this.store.map(function(t,e){return p(t,a[e],s[e])})}},yRegions:{layerClass:"y-regions",makeElements:function(t){var e=this;return t.map(function(t){return T(t.start,t.end,e.constants.width,t.label)})},animateElements:function(t){var e=h(this.oldData,t),i=ct(e,2);this.oldData=i[0];var a=(t=i[1]).map(function(t){return t.end}),n=t.map(function(t){return t.label}),s=t.map(function(t){return t.start}),r=this.oldData.map(function(t){return t.end}),o=(this.oldData.map(function(t){return t.label}),this.oldData.map(function(t){return t.start}));this.render(r.map(function(t,e){return{start:o[e],end:r[e],label:n[e]}}));var l=[];return this.store.map(function(t,e){l=l.concat(d(t,s[e],a[e],r[e]))}),l}},barGraph:{layerClass:function(){return"dataset-units dataset-"+this.constants.index},makeElements:function(t){var e=this.constants;return t.yPositions.map(function(i,a){return D(t.xPositions[a],i,t.barWidth,e.color,e.valuesOverPoints?e.stacked?t.cumulativeYs[a]:t.values[a]:"",a,i-(e.stacked?t.cumulativeYPos[a]:i),{zeroLine:t.zeroLine,barsWidth:t.barsWidth,minHeight:e.minHeight})})},animateElements:function(t){var e=this.constants,i=t.xPositions,a=t.yPositions,n=t.cumulativeYPos,s=t.values,r=t.cumulativeYs,o=this.oldData.xPositions,l=this.oldData.yPositions,c=this.oldData.cumulativeYPos,u=this.oldData.values,p=this.oldData.cumulativeYs,d=h(o,i),v=ct(d,2);o=v[0],i=v[1];var m=h(l,a),g=ct(m,2);l=g[0],a=g[1];var y=h(c,n),x=ct(y,2);c=x[0],n=x[1];var b=h(u,s),_=ct(b,2);u=_[0],s=_[1];var k=h(p,r),w=ct(k,2);p=w[0],r=w[1],this.render({xPositions:o,yPositions:l,cumulativeYPos:c,values:s,cumulativeYs:r,zeroLine:this.oldData.zeroLine,barsWidth:this.oldData.barsWidth,barWidth:this.oldData.barWidth});var A=[];return this.store.map(function(n,s){A=A.concat(f(n,i[s],a[s],t.barWidth,e.index,{zeroLine:t.zeroLine}))}),A}},lineGraph:{}},Nt=function(t){function i(t){st(this,i);var e=ht(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t));return e.isSeries=t.isSeries,e.valuesOverPoints=t.valuesOverPoints,e.formatTooltipY=t.formatTooltipY,e.formatTooltipX=t.formatTooltipX,e.barOptions=t.barOptions||{},e.lineOptions=t.lineOptions||{},e.type=t.type||"line",e.xAxisMode=t.xAxisMode||"span",e.yAxisMode=t.yAxisMode||"span",e.zeroLine=e.height,e.setup(),e}return lt(i,t),rt(i,[{key:"configure",value:function(t){ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"setMargins",value:function(){ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setMargins",this).call(this),this.translateXLeft=60,this.translateXRight=60}},{key:"prepareData",value:function(){return j(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data,this.type)}},{key:"prepareFirstData",value:function(){return R(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.data)}},{key:"calc",value:function(){this.calcXPositions(),this.calcYAxisParameters(this.getAllYValues(),"line"===this.type)}},{key:"calcXPositions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map(function(e,i){return s(t.xOffset+i*t.unitWidth)})}}},{key:"calcYAxisParameters",value:function(t){var e=U(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"false"),i=this.height/G(e),a=q(e)*i,n=this.height-I(e)*a;this.state.yAxis={labels:e,positions:e.map(function(t){return n-t*i}),scaleMultiplier:i,zeroLine:n},this.calcYUnits(),this.calcYExtremes(),this.calcYRegions()}},{key:"calcYUnits",value:function(){var t=this.state,e=function(e){return e.map(function(e){return Z(e,t.yAxis)})};t.datasets=this.data.datasets.map(function(t,i){var a=t.values,n=t.cumulativeYs||[];return{name:t.name,index:i,chartType:t.chartType,values:a,yPositions:e(a),cumulativeYs:n,cumulativeYPos:e(n)}})}},{key:"calcYExtremes",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.yPositions.map(function(e,i){e0)for(var l=0;l0&&(t=getPaths(r,s,i.colors[e],i.config.heatline,i.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var d=n.map(function(t,e){return a[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,d.join("L")))}})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(i){var a=e(t.chartWrapper),n=i.pageX-a.left-t.translateXLeft;i.pageY-a.top-t.translateY=0;s--){var r=i.xAxis.positions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=this.data.datasets.map(function(t,i){return{title:t.title,value:n?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[i]}});this.tip.set_values(o,l,a[s],"",h),this.tip.show_tip();break}}}}},{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","yUnitPositions","values"].map(function(a){var n=a.slice(0,a.length-1);e[n]=i[a][t]}),e.label=this.xAxis.labels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxis.labels.length&&(t=this.xAxis.labels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"addDataPoint",this).call(this,t,e,a),this.data.labels.splice(a,0,t),this.data.datasets.map(function(t,i){t.values.splice(a,0,e[i])}),this.update(this.data)}},{key:"removeDataPoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.datasetLength-1;ot(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"removeDataPoint",this).call(this,t),this.data.labels.splice(t,1),this.data.datasets.map(function(e){e.values.splice(t,1)}),this.update(this.data)}}]),i}(Tt),Wt=function(t){function e(t){st(this,e);var i=ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="scatter",t.dotRadius?i.dotRadius=t.dotRadius:i.dotRadius=8,i.setup(),i}return lt(e,t),rt(e,[{key:"setup_values",value:function(){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setup_values",this).call(this),this.unit_args={type:"dot",args:{radius:this.dotRadius}}}},{key:"make_paths",value:function(){}},{key:"make_path",value:function(){}}]),e}(function(t){function e(t){st(this,e);var i=ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?ht(i):(i.setup(),i)}return lt(e,t),rt(e,[{key:"configure",value:function(t){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"span",this.config.yAxisMode=t.yAxisMode||"span",this.config.dotRadius=t.dotRadius||4,this.config.heatline=t.heatline||0,this.config.regionFill=t.regionFill||0,this.config.showDots=t.showDots||1}},{key:"configUnits",value:function(){this.unitArgs={type:"dot",args:{radius:this.config.dotRadius}}}},{key:"setUnitWidthAndXOffset",value:function(){this.state.unitWidth=this.width/(this.state.datasetLength-1),this.state.xOffset=0}}]),e}(Nt)),Et=function(t){function e(t){return st(this,e),ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return lt(e,t),rt(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setMargins",value:function(){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setMargins",this).call(this);var t=this.data.datasets.filter(function(t){return"left"===t.axisPosition}).length;this.translateXLeft=60*t||60,this.translateXRight=60*(this.data.datasets.length-t)||60}},{key:"prepareYAxis",value:function(){}},{key:"prepareData",value:function(t){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var i=0,a=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?i++:a++}})}},{key:"configure",value:function(t){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this,t),this.config.xAxisMode=t.xAxisMode||"tick",this.config.yAxisMode=t.yAxisMode||"span"}},{key:"configUnits",value:function(){this.unitArgs={type:"bar",args:{spaceWidth:this.state.unitWidth/2}}}},{key:"setYAxis",value:function(){var t=this;this.state.datasets.map(function(e){t.calcYAxisParameters(e.yAxis,e.values,"line"===t.unitType)})}},{key:"calcYUnits",value:function(){this.state.datasets.map(function(t){t.positions=t.values.map(function(e){return s(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"renderConstants",value:function(){var t=this;this.state.datasets.map(function(e){var a="left"===e.yAxis.position?-1*e.yAxis.index*60:t.width+60*e.yAxis.index;t.renderer.xLine(a,"",{pos:"top",mode:"span",stroke:t.colors[i],className:"y-axis-guide"})})}},{key:"getYAxesComponents",value:function(){var t=this;return this.data.datasets.map(function(e,i){return new ChartComponent({layerClass:"y axis y-axis-"+i,make:function(){var e=t.state.datasets[i].yAxis;t.renderer.setZeroline(e.zeroline);var a={pos:e.position,mode:"tick",offset:60*e.index,stroke:t.colors[i]};return e.positions.map(function(i,n){return t.renderer.yLine(i,e.labels[n],a)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,i){return new ChartComponent({layerClass:"dataset-units dataset-"+i,make:function(){var e=t.state.datasets[i],a=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,n){return t.renderer[a.type](t.state.xAxisPositions[n],e,a.args,t.colors[i],n,i,t.state.datasetLength)})},animate:function(e){var a=t.state.datasets[i],n=t.unitArgs.type,s=t.state.xAxisPositions,r=t.state.datasets[i].positions,o=e[e.length-1],l=o.parentNode;if(t.oldState.xExtra>0)for(var h=0;h0}),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:"renderComponents",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.percentageBar,styles:{background:e.colors[a],width:100*i/e.grand_total+"%"}});e.slices.push(n)})}},{key:"calc",value:function(){}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(i,a){i.addEventListener("mouseenter",function(){var n=e(t.chartWrapper),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:"renderLegend",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.statsWrapper}).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}(Tt),Yt=Math.PI/180,zt=function(i){function a(t){st(this,a);var e=ht(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 lt(a,i),rt(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:"renderComponents",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,c=o/e.grand_total*360,u=n?-c:c,p=r+=u,d=a.getPositionByAngle(h,i),f=a.getPositionByAngle(p,i),v=t&&s[l],m=void 0,g=void 0;t?(m=v?v.startPosition:d,g=v?v.endPosition:d):(m=d,g=f);var y=e.makeArcPath(m,g),x=b(y,"pie-path","none",e.colors[l]);x.style.transition="transform .3s;",e.drawArea.appendChild(x),e.slices.push(x),e.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:e.grand_total,startAngle:h,endAngle:p,angle:u}),t&&e.elements_to_animate.push([{unit:x,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(d,f)},650,"easein",null,{d:y}])}),t&&z(this.chartWrapper,this.svg,this.elements_to_animate)}},{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){S(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=O(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])+": ",c=(100*this.slice_totals[i]/this.grand_total).toFixed(1);this.tip.set_values(o,l,h,c+"%"),this.tip.show_tip()}else S(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.statsWrapper}).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*Yt)*e,y:Math.cos(t*Yt)*e}}}]),a}(Tt),jt=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,c=t.discrete_domains,u=void 0===c?0:c,p=t.count_label,d=void 0===p?"":p,f=t.legend_colors,v=void 0===f?[]:f;st(this,e);var m=ht(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));m.type="heatmap",m.domain=s,m.subdomain=o,m.data=h,m.discrete_domains=u,m.count_label=d;var g=new Date;return m.start=a||it(g,365),v=v.slice(0,5),m.legend_colors=m.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],m.distribution_size=5,m.translateX=0,m}return lt(e,t),rt(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){N(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"configure",value:function(){ot(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"configure",this).call(this),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()&&it(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&it(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=tt(this.first_week_start+"",this.last_week_start+"")+1}},{key:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("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=J(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:"renderComponents",value:function(){Array.prototype.slice.call(this.container.querySelectorAll(".graph-stats-container, .sub-title, .title")).map(function(t){t.style.display="None"}),this.chartWrapper.style.marginTop="0px",this.chartWrapper.style.paddingTop="0px"}},{key:"bindTooltip",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.chartWrapper.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,c=i+" "+t.count_label,u=" on "+n+" "+a[0]+", "+a[2];t.tip.set_values(l,h,u,c,[],1),t.tip.show_tip()})})}},{key:"update",value:function(t){this.data=t,this.setup_values(),this.bindTooltip()}}]),e}(Tt),Rt={mixed:Nt,multiaxis:Et,scatter:Wt,percentage:St,heatmap:jt,pie:zt},Ht=function t(e){return st(this,t),at(e.type,arguments[0])};return Ht}(); //# sourceMappingURL=frappe-charts.min.iife.js.map diff --git a/dist/frappe-charts.min.iife.js.map b/dist/frappe-charts.min.iife.js.map index e40f22f..b8fb1f3 100644 --- a/dist/frappe-charts.min.iife.js.map +++ b/dist/frappe-charts.min.iife.js.map @@ -1 +1 @@ -{"version":3,"file":"frappe-charts.min.iife.js","sources":["../src/js/utils/dom.js","../src/js/utils/helpers.js","../src/js/utils/draw-utils.js","../src/js/utils/animate.js","../src/js/utils/draw.js","../src/js/utils/colors.js","../src/js/config.js","../src/js/utils/animation.js","../src/js/charts/axis-chart-utils.js","../src/js/objects/ChartComponents.js","../src/js/utils/intervals.js","../src/js/utils/date-utils.js","../src/js/chart.js","../src/js/objects/SvgTip.js","../src/js/charts/BaseChart.js","../src/js/utils/constants.js","../src/js/charts/AxisChart.js","../src/js/charts/ScatterChart.js","../src/js/charts/LineChart.js","../src/js/charts/MultiAxisChart.js","../src/js/charts/PercentageChart.js","../src/js/charts/PieChart.js","../src/js/charts/Heatmap.js"],"sourcesContent":["export function $(expr, con) {\n\treturn typeof expr === \"string\"? (con || document).querySelector(expr) : expr || null;\n}\n\nexport function findNodeIndex(node)\n{\n\tvar i = 0;\n\twhile (node.previousSibling) {\n\t\tnode = node.previousSibling;\n\t\ti++;\n\t}\n\treturn i;\n}\n\n$.create = (tag, o) => {\n\tvar element = document.createElement(tag);\n\n\tfor (var i in o) {\n\t\tvar val = o[i];\n\n\t\tif (i === \"inside\") {\n\t\t\t$(val).appendChild(element);\n\t\t}\n\t\telse if (i === \"around\") {\n\t\t\tvar ref = $(val);\n\t\t\tref.parentNode.insertBefore(element, ref);\n\t\t\telement.appendChild(ref);\n\n\t\t} else if (i === \"styles\") {\n\t\t\tif(typeof val === \"object\") {\n\t\t\t\tObject.keys(val).map(prop => {\n\t\t\t\t\telement.style[prop] = val[prop];\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (i in element ) {\n\t\t\telement[i] = val;\n\t\t}\n\t\telse {\n\t\t\telement.setAttribute(i, val);\n\t\t}\n\t}\n\n\treturn element;\n};\n\nexport function getOffset(element) {\n\tlet rect = element.getBoundingClientRect();\n\treturn {\n\t\t// https://stackoverflow.com/a/7436602/6495043\n\t\t// rect.top varies with scroll, so we add whatever has been\n\t\t// scrolled to it to get absolute distance from actual page top\n\t\ttop: rect.top + (document.documentElement.scrollTop || document.body.scrollTop),\n\t\tleft: rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft)\n\t};\n}\n\nexport function isElementInViewport(el) {\n\t// Although straightforward: https://stackoverflow.com/a/7557433/6495043\n\tvar rect = el.getBoundingClientRect();\n\n\treturn (\n\t\trect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */\n rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */\n\t);\n}\n\nexport function getElementContentWidth(element) {\n\tvar styles = window.getComputedStyle(element);\n\tvar padding = parseFloat(styles.paddingLeft) +\n\t\tparseFloat(styles.paddingRight);\n\n\treturn element.clientWidth - padding;\n}\n\nexport function bind(element, o){\n\tif (element) {\n\t\tfor (var event in o) {\n\t\t\tvar callback = o[event];\n\n\t\t\tevent.split(/\\s+/).forEach(function (event) {\n\t\t\t\telement.addEventListener(event, callback);\n\t\t\t});\n\t\t}\n\t}\n}\n\nexport function unbind(element, o){\n\tif (element) {\n\t\tfor (var event in o) {\n\t\t\tvar callback = o[event];\n\n\t\t\tevent.split(/\\s+/).forEach(function(event) {\n\t\t\t\telement.removeEventListener(event, callback);\n\t\t\t});\n\t\t}\n\t}\n}\n\nexport function fire(target, type, properties) {\n\tvar evt = document.createEvent(\"HTMLEvents\");\n\n\tevt.initEvent(type, true, true );\n\n\tfor (var j in properties) {\n\t\tevt[j] = properties[j];\n\t}\n\n\treturn target.dispatchEvent(evt);\n}\n","/**\n * Returns the value of a number upto 2 decimal places.\n * @param {Number} d Any number\n */\nexport function floatTwo(d) {\n\treturn parseFloat(d.toFixed(2));\n}\n\n/**\n * Returns whether or not two given arrays are equal.\n * @param {Array} arr1 First array\n * @param {Array} arr2 Second array\n */\nexport function arraysEqual(arr1, arr2) {\n\tif(arr1.length !== arr2.length) return false;\n\tlet areEqual = true;\n\tarr1.map((d, i) => {\n\t\tif(arr2[i] !== d) areEqual = false;\n\t});\n\treturn areEqual;\n}\n\n/**\n * Shuffles array in place. ES6 version\n * @param {Array} array An array containing the items.\n */\nexport function shuffle(array) {\n\t// Awesomeness: https://bost.ocks.org/mike/shuffle/\n\t// https://stackoverflow.com/a/2450976/6495043\n\t// https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array?noredirect=1&lq=1\n\n\tfor (let i = array.length - 1; i > 0; i--) {\n\t\tlet j = Math.floor(Math.random() * (i + 1));\n\t\t[array[i], array[j]] = [array[j], array[i]];\n\t}\n\n\treturn array;\n}\n\n/**\n * Fill an array with extra points\n * @param {Array} array Array\n * @param {Number} count number of filler elements\n * @param {Object} element element to fill with\n * @param {Boolean} start fill at start?\n */\nexport function fillArray(array, count, element, start=false) {\n\tif(!element) {\n\t\telement = start ? array[0] : array[array.length - 1];\n\t}\n\tlet fillerArray = new Array(Math.abs(count)).fill(element);\n\tarray = start ? fillerArray.concat(array) : array.concat(fillerArray);\n\treturn array;\n}\n\n/**\n * Returns pixel width of string.\n * @param {String} string\n * @param {Number} charWidth Width of single char in pixels\n */\nexport function getStringWidth(string, charWidth) {\n\treturn (string+\"\").length * charWidth;\n}\n\nexport function bindChange(obj, getFn, setFn) {\n\treturn new Proxy(obj, {\n\t\tset: function(target, prop, value) {\n\t\t\tsetFn();\n\t\t\treturn Reflect.set(target, prop, value);\n\t\t},\n\t\tget: function(target, prop, value) {\n\t\t\tgetFn();\n\t\t\treturn Reflect.get(target, prop);\n\t\t}\n\t});\n}\n","import { fillArray } from './helpers';\n\nexport function getBarHeightAndYAttr(yTop, zeroLine) {\n\tlet height, y;\n\tif (yTop < zeroLine) {\n\t\theight = zeroLine - yTop;\n\t\ty = yTop;\n\t} else {\n\t\theight = yTop - zeroLine;\n\t\ty = zeroLine;\n\t}\n\n\treturn [height, y];\n}\n\nexport function equilizeNoOfElements(array1, array2,\n\textra_count=array2.length - array1.length) {\n\n\t// Doesn't work if either has zero elements.\n\tif(extra_count > 0) {\n\t\tarray1 = fillArray(array1, extra_count);\n\t} else {\n\t\tarray2 = fillArray(array2, extra_count);\n\t}\n\treturn [array1, array2];\n}\n\n// let char_width = 8;\n// let allowed_space = avgUnitWidth * 1.5;\n// let allowed_letters = allowed_space / 8;\n\n// return values.map((value, i) => {\n// \tlet space_taken = getStringWidth(value, char_width) + 2;\n// \tif(space_taken > allowed_space) {\n// \t\tif(isSeries) {\n// \t\t\t// Skip some axis lines if X axis is a series\n// \t\t\tlet skips = 1;\n// \t\t\twhile((space_taken/skips)*2 > allowed_space) {\n// \t\t\t\tskips++;\n// \t\t\t}\n// \t\t\tif(i % skips !== 0) {\n// \t\t\t\treturn;\n// \t\t\t}\n// \t\t} else {\n// \t\t\tvalue = value.slice(0, allowed_letters-3) + \" ...\";\n// \t\t}\n// \t}\n","import { getBarHeightAndYAttr } from './draw-utils';\n\nexport const UNIT_ANIM_DUR = 350;\nexport const PATH_ANIM_DUR = 350;\nexport const MARKER_LINE_ANIM_DUR = UNIT_ANIM_DUR;\nexport const REPLACE_ALL_NEW_DUR = 250;\n\nexport const STD_EASING = 'easein';\n\nexport function translate(unit, oldCoord, newCoord, duration) {\n\treturn [\n\t\tunit,\n\t\t{transform: newCoord.join(', ')},\n\t\tduration,\n\t\tSTD_EASING,\n\t\t\"translate\",\n\t\t{transform: oldCoord.join(', ')}\n\t];\n}\n\nexport function translateVertLine(xLine, newX, oldX) {\n\treturn translate(xLine, [oldX, 0], [newX, 0], MARKER_LINE_ANIM_DUR);\n}\n\nexport function translateHoriLine(yLine, newY, oldY) {\n\treturn translate(yLine, [0, oldY], [0, newY], MARKER_LINE_ANIM_DUR);\n}\n\nexport function animateRegion(rectGroup, newY1, newY2, oldY2) {\n\tlet newHeight = newY1 - newY2;\n\tlet rect = rectGroup.childNodes[0];\n\tlet width = rect.getAttribute(\"width\");\n\tlet rectAnim = [\n\t\trect,\n\t\t{ height: newHeight, 'stroke-dasharray': `${width}, ${newHeight}` },\n\t\tMARKER_LINE_ANIM_DUR,\n\t\tSTD_EASING\n\t]\n\n\tlet groupAnim = translate(rectGroup, [0, oldY2], [0, newY2], MARKER_LINE_ANIM_DUR);\n\treturn [rectAnim, groupAnim];\n}\n\nexport var Animator = (function() {\n\tvar Animator = function(totalHeight, totalWidth, zeroLine, avgUnitWidth) {\n\t\t// constants\n\t\tthis.totalHeight = totalHeight;\n\t\tthis.totalWidth = totalWidth;\n\n\t\t// changeables\n\t\tthis.avgUnitWidth = avgUnitWidth;\n\t\tthis.zeroLine = zeroLine;\n\t};\n\n\tAnimator.prototype = {\n\t\tbar: function(barObj, x, yTop, index, noOfDatasets) {\n\t\t\tlet start = x - this.avgUnitWidth/4;\n\t\t\tlet width = (this.avgUnitWidth/2)/noOfDatasets;\n\t\t\tlet [height, y] = getBarHeightAndYAttr(yTop, this.zeroLine, this.totalHeight);\n\n\t\t\tx = start + (width * index);\n\n\t\t\treturn [barObj, {width: width, height: height, x: x, y: y}, UNIT_ANIM_DUR, STD_EASING];\n\t\t\t// bar.animate({height: args.newHeight, y: yTop}, UNIT_ANIM_DUR, mina.easein);\n\t\t},\n\n\t\tdot: function(dotObj, x, yTop) {\n\t\t\treturn [dotObj, {cx: x, cy: yTop}, UNIT_ANIM_DUR, STD_EASING];\n\t\t\t// dot.animate({cy: yTop}, UNIT_ANIM_DUR, mina.easein);\n\t\t},\n\n\t\tpath: function(d, pathStr) {\n\t\t\tlet pathComponents = [];\n\t\t\tconst animPath = [{unit: d.path, object: d, key: 'path'}, {d:\"M\"+pathStr}, PATH_ANIM_DUR, STD_EASING];\n\t\t\tpathComponents.push(animPath);\n\n\t\t\tif(d.regionPath) {\n\t\t\t\tlet regStartPt = `0,${this.zeroLine}L`;\n\t\t\t\tlet regEndPt = `L${this.totalWidth}, ${this.zeroLine}`;\n\n\t\t\t\tconst animRegion = [\n\t\t\t\t\t{unit: d.regionPath, object: d, key: 'regionPath'},\n\t\t\t\t\t{d:\"M\" + regStartPt + pathStr + regEndPt},\n\t\t\t\t\tPATH_ANIM_DUR,\n\t\t\t\t\tSTD_EASING\n\t\t\t\t];\n\t\t\t\tpathComponents.push(animRegion);\n\t\t\t}\n\n\t\t\treturn pathComponents;\n\t\t}\n\t};\n\n\treturn Animator;\n})();\n\n\n","import { getBarHeightAndYAttr } from './draw-utils';\nimport { getStringWidth } from './helpers';\nimport { STD_EASING, UNIT_ANIM_DUR, MARKER_LINE_ANIM_DUR, PATH_ANIM_DUR } from './animate';\n\n/*\n\n\n\t\n\t\n\t\t\n\t\t\n\t\t\n\t\n\n\n filter: url(#glow);\n fill: #fff;\n\n*/\n\nconst AXIS_TICK_LENGTH = 6;\nconst LABEL_MARGIN = 4;\nexport const FONT_SIZE = 10;\nconst BASE_LINE_COLOR = '#dadada';\nconst BASE_BG_COLOR = '#F7FAFC';\n\nfunction $(expr, con) {\n\treturn typeof expr === \"string\"? (con || document).querySelector(expr) : expr || null;\n}\n\nexport function createSVG(tag, o) {\n\tvar element = document.createElementNS(\"http://www.w3.org/2000/svg\", tag);\n\n\tfor (var i in o) {\n\t\tvar val = o[i];\n\n\t\tif (i === \"inside\") {\n\t\t\t$(val).appendChild(element);\n\t\t}\n\t\telse if (i === \"around\") {\n\t\t\tvar ref = $(val);\n\t\t\tref.parentNode.insertBefore(element, ref);\n\t\t\telement.appendChild(ref);\n\n\t\t} else if (i === \"styles\") {\n\t\t\tif(typeof val === \"object\") {\n\t\t\t\tObject.keys(val).map(prop => {\n\t\t\t\t\telement.style[prop] = val[prop];\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tif(i === \"className\") { i = \"class\"; }\n\t\t\tif(i === \"innerHTML\") {\n\t\t\t\telement['textContent'] = val;\n\t\t\t} else {\n\t\t\t\telement.setAttribute(i, val);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn element;\n}\n\nfunction renderVerticalGradient(svgDefElem, gradientId) {\n\treturn createSVG('linearGradient', {\n\t\tinside: svgDefElem,\n\t\tid: gradientId,\n\t\tx1: 0,\n\t\tx2: 0,\n\t\ty1: 0,\n\t\ty2: 1\n\t});\n}\n\nfunction setGradientStop(gradElem, offset, color, opacity) {\n\treturn createSVG('stop', {\n\t\t'inside': gradElem,\n\t\t'style': `stop-color: ${color}`,\n\t\t'offset': offset,\n\t\t'stop-opacity': opacity\n\t});\n}\n\nexport function makeSVGContainer(parent, className, width, height) {\n\treturn createSVG('svg', {\n\t\tclassName: className,\n\t\tinside: parent,\n\t\twidth: width,\n\t\theight: height\n\t});\n}\n\nexport function makeSVGDefs(svgContainer) {\n\treturn createSVG('defs', {\n\t\tinside: svgContainer,\n\t});\n}\n\nexport function makeSVGGroup(parent, className, transform='') {\n\treturn createSVG('g', {\n\t\tclassName: className,\n\t\tinside: parent,\n\t\ttransform: transform\n\t});\n}\n\nexport function wrapInSVGGroup(elements, className='') {\n\tlet g = createSVG('g', {\n\t\tclassName: className\n\t});\n\telements.forEach(e => g.appendChild(e));\n\treturn g;\n}\n\nexport function makePath(pathStr, className='', stroke='none', fill='none') {\n\treturn createSVG('path', {\n\t\tclassName: className,\n\t\td: pathStr,\n\t\tstyles: {\n\t\t\tstroke: stroke,\n\t\t\tfill: fill\n\t\t}\n\t});\n}\n\nexport function makeGradient(svgDefElem, color, lighter = false) {\n\tlet gradientId ='path-fill-gradient' + '-' + color;\n\tlet gradientDef = renderVerticalGradient(svgDefElem, gradientId);\n\tlet opacities = [1, 0.6, 0.2];\n\tif(lighter) {\n\t\topacities = [0.4, 0.2, 0];\n\t}\n\n\tsetGradientStop(gradientDef, \"0%\", color, opacities[0]);\n\tsetGradientStop(gradientDef, \"50%\", color, opacities[1]);\n\tsetGradientStop(gradientDef, \"100%\", color, opacities[2]);\n\n\treturn gradientId;\n}\n\nexport function makeHeatSquare(className, x, y, size, fill='none', data={}) {\n\tlet args = {\n\t\tclassName: className,\n\t\tx: x,\n\t\ty: y,\n\t\twidth: size,\n\t\theight: size,\n\t\tfill: 1\n\t};\n\n\tObject.keys(data).map(key => {\n\t\targs[key] = data[key];\n\t});\n\n\treturn createSVG(\"rect\", args);\n}\n\nexport function makeText(className, x, y, content) {\n\treturn createSVG('text', {\n\t\tclassName: className,\n\t\tx: x,\n\t\ty: y,\n\t\tdy: (FONT_SIZE / 2) + 'px',\n\t\t'font-size': FONT_SIZE + 'px',\n\t\tinnerHTML: content\n\t});\n}\n\nfunction makeVertLine(x, label, y1, y2, options={}) {\n\tif(!options.stroke) options.stroke = BASE_LINE_COLOR;\n\tlet l = createSVG('line', {\n\t\tclassName: 'line-vertical ' + options.className,\n\t\tx1: 0,\n\t\tx2: 0,\n\t\ty1: y1,\n\t\ty2: y2,\n\t\tstyles: {\n\t\t\tstroke: options.stroke\n\t\t}\n\t});\n\n\tlet text = createSVG('text', {\n\t\tx: 0,\n\t\ty: y1 > y2 ? y1 + LABEL_MARGIN : y1 - LABEL_MARGIN - FONT_SIZE,\n\t\tdy: FONT_SIZE + 'px',\n\t\t'font-size': FONT_SIZE + 'px',\n\t\t'text-anchor': 'middle',\n\t\tinnerHTML: label\n\t});\n\n\tlet line = createSVG('g', {\n\t\ttransform: `translate(${ x }, 0)`\n\t});\n\n\tline.appendChild(l);\n\tline.appendChild(text);\n\n\treturn line;\n}\n\nfunction makeHoriLine(y, label, x1, x2, options={}) {\n\tif(!options.stroke) options.stroke = BASE_LINE_COLOR;\n\tif(!options.lineType) options.lineType = '';\n\tlet className = 'line-horizontal ' + options.className +\n\t\t(options.lineType === \"dashed\" ? \"dashed\": \"\");\n\n\tlet l = createSVG('line', {\n\t\tclassName: className,\n\t\tx1: x1,\n\t\tx2: x2,\n\t\ty1: 0,\n\t\ty2: 0,\n\t\tstyles: {\n\t\t\tstroke: options.stroke\n\t\t}\n\t});\n\n\tlet text = createSVG('text', {\n\t\tx: x1 < x2 ? x1 - LABEL_MARGIN : x1 + LABEL_MARGIN,\n\t\ty: 0,\n\t\tdy: (FONT_SIZE / 2 - 2) + 'px',\n\t\t'font-size': FONT_SIZE + 'px',\n\t\t'text-anchor': x1 < x2 ? 'end' : 'start',\n\t\tinnerHTML: label+\"\"\n\t});\n\n\tlet line = createSVG('g', {\n\t\ttransform: `translate(0, ${y})`,\n\t\t'stroke-opacity': 1\n\t});\n\n\tif(text === 0 || text === '0') {\n\t\tline.style.stroke = \"rgba(27, 31, 35, 0.6)\";\n\t}\n\n\tline.appendChild(l);\n\tline.appendChild(text);\n\n\treturn line;\n}\n\nexport function yLine(y, label, width, options={}) {\n\tif(!options.pos) options.pos = 'left';\n\tif(!options.offset) options.offset = 0;\n\tif(!options.mode) options.mode = 'span';\n\tif(!options.stroke) options.stroke = BASE_LINE_COLOR;\n\tif(!options.className) options.className = '';\n\n\tlet x1 = -1 * AXIS_TICK_LENGTH;\n\tlet x2 = options.mode === 'span' ? width + AXIS_TICK_LENGTH : 0;\n\n\tif(options.mode === 'tick' && options.pos === 'right') {\n\t\tx1 = width + AXIS_TICK_LENGTH\n\t\tx2 = width;\n\t}\n\n\tlet offset = options.pos === 'left' ? -1 * options.offset : options.offset;\n\n\tx1 += options.offset;\n\tx2 += options.offset;\n\n\treturn makeHoriLine(y, label, x1, x2, {\n\t\tstroke: options.stroke,\n\t\tclassName: options.className,\n\t\tlineType: options.lineType\n\t});\n}\n\nexport function xLine(x, label, height, options={}) {\n\tif(!options.pos) options.pos = 'bottom';\n\tif(!options.offset) options.offset = 0;\n\tif(!options.mode) options.mode = 'span';\n\tif(!options.stroke) options.stroke = BASE_LINE_COLOR;\n\tif(!options.className) options.className = '';\n\n\t// Draw X axis line in span/tick mode with optional label\n\t// \ty2(span)\n\t// \t\t\t\t\t\t|\n\t// \t\t\t\t\t\t|\n\t//\t\t\t\tx line\t|\n\t//\t\t\t\t\t\t|\n\t// \t\t\t\t\t \t|\n\t// ---------------------+-- y2(tick)\n\t//\t\t\t\t\t\t|\n\t//\t\t\t\t\t\t\ty1\n\n\tlet y1 = height + AXIS_TICK_LENGTH;\n\tlet y2 = options.mode === 'span' ? -1 * AXIS_TICK_LENGTH : height;\n\n\tif(options.mode === 'tick' && options.pos === 'top') {\n\t\t// top axis ticks\n\t\ty1 = -1 * AXIS_TICK_LENGTH;\n\t\ty2 = 0;\n\t}\n\n\treturn makeVertLine(x, label, y1, y2, {\n\t\tstroke: options.stroke,\n\t\tclassName: options.className,\n\t\tlineType: options.lineType\n\t});\n}\n\nexport function yMarker(y, label, width, options={}) {\n\tlet labelSvg = createSVG('text', {\n\t\tclassName: 'chart-label',\n\t\tx: width - getStringWidth(label, 5) - LABEL_MARGIN,\n\t\ty: 0,\n\t\tdy: (FONT_SIZE / -2) + 'px',\n\t\t'font-size': FONT_SIZE + 'px',\n\t\t'text-anchor': 'start',\n\t\tinnerHTML: label+\"\"\n\t});\n\n\tlet line = makeHoriLine(y, '', 0, width, {\n\t\tstroke: options.stroke || BASE_LINE_COLOR,\n\t\tclassName: options.className || '',\n\t\tlineType: options.lineType\n\t});\n\n\tline.appendChild(labelSvg);\n\n\treturn line;\n}\n\nexport function yRegion(y1, y2, width, label) {\n\t// return a group\n\tlet height = y1 - y2;\n\n\tlet rect = createSVG('rect', {\n\t\tclassName: `bar mini`, // remove class\n\t\tstyles: {\n\t\t\tfill: `rgba(228, 234, 239, 0.49)`,\n\t\t\tstroke: BASE_LINE_COLOR,\n\t\t\t'stroke-dasharray': `${width}, ${height}`\n\t\t},\n\t\t// 'data-point-index': index,\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: width,\n\t\theight: height\n\t});\n\n\tlet labelSvg = createSVG('text', {\n\t\tclassName: 'chart-label',\n\t\tx: width - getStringWidth(label, 4.5) - LABEL_MARGIN,\n\t\ty: 0,\n\t\tdy: (FONT_SIZE / -2) + 'px',\n\t\t'font-size': FONT_SIZE + 'px',\n\t\t'text-anchor': 'start',\n\t\tinnerHTML: label+\"\"\n\t});\n\n\tlet region = createSVG('g', {\n\t\ttransform: `translate(0, ${y2})`\n\t});\n\n\tregion.appendChild(rect);\n\tregion.appendChild(labelSvg);\n\n\treturn region;\n}\n\nexport function datasetBar(x, yTop, width, color, label='', index=0, offset=0, meta={}) {\n\tlet [height, y] = getBarHeightAndYAttr(yTop, meta.zeroLine);\n\t// console.log(yTop, meta.zeroLine, y, offset);\n\n\tlet rect = createSVG('rect', {\n\t\tclassName: `bar mini`,\n\t\tstyle: `fill: ${color}`,\n\t\t'data-point-index': index,\n\t\tx: x - meta.barsWidth/2,\n\t\ty: y - offset,\n\t\twidth: width,\n\t\theight: height || meta.minHeight\n\t});\n\n\tif(!label && !label.length) {\n\t\treturn rect;\n\t} else {\n\t\tlet text = createSVG('text', {\n\t\t\tclassName: 'data-point-value',\n\t\t\tx: x,\n\t\t\ty: y - offset,\n\t\t\tdy: (FONT_SIZE / 2 * -1) + 'px',\n\t\t\t'font-size': FONT_SIZE + 'px',\n\t\t\t'text-anchor': 'middle',\n\t\t\tinnerHTML: label\n\t\t});\n\n\t\treturn wrapInSVGGroup([rect, text]);\n\t}\n}\n\nexport class AxisChartRenderer {\n\tconstructor(state) {\n\t\tthis.refreshState(state);\n\t}\n\n\trefreshState(state) {\n\t\tthis.totalHeight = state.totalHeight;\n\t\tthis.totalWidth = state.totalWidth;\n\t\tthis.zeroLine = state.zeroLine;\n\t\tthis.unitWidth = state.unitWidth;\n\t\tthis.xAxisMode = state.xAxisMode;\n\t\tthis.yAxisMode = state.yAxisMode;\n\t}\n\n\tsetZeroline(zeroLine) {\n\t\tthis.zeroLine = zeroLine;\n\t}\n\n\txMarker() {}\n\n\n\txRegion() {\n\t\treturn createSVG('rect', {\n\t\t\tclassName: `bar mini`, // remove class\n\t\t\tstyle: `fill: rgba(228, 234, 239, 0.49)`,\n\t\t\t// 'data-point-index': index,\n\t\t\tx: 0,\n\t\t\ty: y2,\n\t\t\twidth: this.totalWidth,\n\t\t\theight: y1 - y2\n\t\t});\n\n\t\treturn region;\n\t}\n\n\tanimatebar(bar, x, yTop, index, noOfDatasets) {\n\t\tlet start = x - this.avgUnitWidth/4;\n\t\tlet width = (this.avgUnitWidth/2)/noOfDatasets;\n\t\tlet [height, y] = getBarHeightAndYAttr(yTop, this.zeroLine, this.totalHeight);\n\n\t\tx = start + (width * index);\n\n\t\treturn [bar, {width: width, height: height, x: x, y: y}, UNIT_ANIM_DUR, STD_EASING];\n\t\t// bar.animate({height: args.newHeight, y: yTop}, UNIT_ANIM_DUR, mina.easein);\n\t}\n\n\tanimatedot(dot, x, yTop) {\n\t\treturn [dot, {cx: x, cy: yTop}, UNIT_ANIM_DUR, STD_EASING];\n\t\t// dot.animate({cy: yTop}, UNIT_ANIM_DUR, mina.easein);\n\t}\n\n\tanimatepath(paths, pathStr) {\n\t\tlet pathComponents = [];\n\t\tconst animPath = [paths[0], {d:\"M\"+pathStr}, PATH_ANIM_DUR, STD_EASING];\n\t\tpathComponents.push(animPath);\n\n\t\tif(paths[1]) {\n\t\t\tlet regStartPt = `0,${this.zeroLine}L`;\n\t\t\tlet regEndPt = `L${this.totalWidth}, ${this.zeroLine}`;\n\n\t\t\tconst animRegion = [\n\t\t\t\tpaths[1],\n\t\t\t\t{d:\"M\" + regStartPt + pathStr + regEndPt},\n\t\t\t\tPATH_ANIM_DUR,\n\t\t\t\tSTD_EASING\n\t\t\t];\n\t\t\tpathComponents.push(animRegion);\n\t\t}\n\n\t\treturn pathComponents;\n\t}\n}\n","const PRESET_COLOR_MAP = {\n\t'light-blue': '#7cd6fd',\n\t'blue': '#5e64ff',\n\t'violet': '#743ee2',\n\t'red': '#ff5858',\n\t'orange': '#ffa00a',\n\t'yellow': '#feef72',\n\t'green': '#28a745',\n\t'light-green': '#98d85b',\n\t'purple': '#b554ff',\n\t'magenta': '#ffa3ef',\n\t'black': '#36114C',\n\t'grey': '#bdd3e6',\n\t'light-grey': '#f0f4f7',\n\t'dark-grey': '#b8c2cc'\n};\n\nexport const DEFAULT_COLORS = ['light-blue', 'blue', 'violet', 'red', 'orange',\n\t'yellow', 'green', 'light-green', 'purple', 'magenta'];\n\nfunction limitColor(r){\n\tif (r > 255) return 255;\n\telse if (r < 0) return 0;\n\treturn r;\n}\n\nexport function lightenDarkenColor(color, amt) {\n\tlet col = getColor(color);\n\tlet usePound = false;\n\tif (col[0] == \"#\") {\n\t\tcol = col.slice(1);\n\t\tusePound = true;\n\t}\n\tlet num = parseInt(col,16);\n\tlet r = limitColor((num >> 16) + amt);\n\tlet b = limitColor(((num >> 8) & 0x00FF) + amt);\n\tlet g = limitColor((num & 0x0000FF) + amt);\n\treturn (usePound?\"#\":\"\") + (g | (b << 8) | (r << 16)).toString(16);\n}\n\nexport function isValidColor(string) {\n\t// https://stackoverflow.com/a/8027444/6495043\n\treturn /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(string);\n}\n\nexport const getColor = (color) => {\n\treturn PRESET_COLOR_MAP[color] || color;\n};\n","import Chart from './chart';\n\nconst ALL_CHART_TYPES = ['line', 'scatter', 'bar', 'percentage', 'heatmap', 'pie'];\n\nconst COMPATIBLE_CHARTS = {\n\tbar: ['line', 'scatter', 'percentage', 'pie'],\n\tline: ['scatter', 'bar', 'percentage', 'pie'],\n\tpie: ['line', 'scatter', 'percentage', 'bar'],\n\tscatter: ['line', 'bar', 'percentage', 'pie'],\n\tpercentage: ['bar', 'line', 'scatter', 'pie'],\n\theatmap: []\n};\n\n// Needs structure as per only labels/datasets\nconst COLOR_COMPATIBLE_CHARTS = {\n\tbar: ['line', 'scatter'],\n\tline: ['scatter', 'bar'],\n\tpie: ['percentage'],\n\tscatter: ['line', 'bar'],\n\tpercentage: ['pie'],\n\theatmap: []\n};\n\nexport function getDifferentChart(type, current_type, args) {\n\tif(type === current_type) return;\n\n\tif(!ALL_CHART_TYPES.includes(type)) {\n\t\tconsole.error(`'${type}' is not a valid chart type.`);\n\t}\n\n\tif(!COMPATIBLE_CHARTS[current_type].includes(type)) {\n\t\tconsole.error(`'${current_type}' chart cannot be converted to a '${type}' chart.`);\n\t}\n\n\t// whether the new chart can use the existing colors\n\tconst useColor = COLOR_COMPATIBLE_CHARTS[current_type].includes(type);\n\n\t// Okay, this is anticlimactic\n\t// this function will need to actually be 'changeChartType(type)'\n\t// that will update only the required elements, but for now ...\n\treturn new Chart({\n\t\tparent: args.parent,\n\t\ttitle: args.title,\n\t\tdata: args.data,\n\t\ttype: type,\n\t\theight: args.height,\n\t\tcolors: useColor ? args.colors : undefined\n\t});\n}","// Leveraging SMIL Animations\n\nimport { REPLACE_ALL_NEW_DUR } from './animate';\n\nconst EASING = {\n\tease: \"0.25 0.1 0.25 1\",\n\tlinear: \"0 0 1 1\",\n\t// easein: \"0.42 0 1 1\",\n\teasein: \"0.1 0.8 0.2 1\",\n\teaseout: \"0 0 0.58 1\",\n\teaseinout: \"0.42 0 0.58 1\"\n};\n\nfunction animateSVGElement(element, props, dur, easingType=\"linear\", type=undefined, oldValues={}) {\n\n\tlet animElement = element.cloneNode(true);\n\tlet newElement = element.cloneNode(true);\n\n\tfor(var attributeName in props) {\n\t\tlet animateElement;\n\t\tif(attributeName === 'transform') {\n\t\t\tanimateElement = document.createElementNS(\"http://www.w3.org/2000/svg\", \"animateTransform\");\n\t\t} else {\n\t\t\tanimateElement = document.createElementNS(\"http://www.w3.org/2000/svg\", \"animate\");\n\t\t}\n\t\tlet currentValue = oldValues[attributeName] || element.getAttribute(attributeName);\n\t\tlet value = props[attributeName];\n\n\t\tlet animAttr = {\n\t\t\tattributeName: attributeName,\n\t\t\tfrom: currentValue,\n\t\t\tto: value,\n\t\t\tbegin: \"0s\",\n\t\t\tdur: dur/1000 + \"s\",\n\t\t\tvalues: currentValue + \";\" + value,\n\t\t\tkeySplines: EASING[easingType],\n\t\t\tkeyTimes: \"0;1\",\n\t\t\tcalcMode: \"spline\",\n\t\t\tfill: 'freeze'\n\t\t};\n\n\t\tif(type) {\n\t\t\tanimAttr[\"type\"] = type;\n\t\t}\n\n\t\tfor (var i in animAttr) {\n\t\t\tanimateElement.setAttribute(i, animAttr[i]);\n\t\t}\n\n\t\tanimElement.appendChild(animateElement);\n\n\t\tif(type) {\n\t\t\tnewElement.setAttribute(attributeName, `translate(${value})`);\n\t\t} else {\n\t\t\tnewElement.setAttribute(attributeName, value);\n\t\t}\n\t}\n\n\treturn [animElement, newElement];\n}\n\nexport function transform(element, style) { // eslint-disable-line no-unused-vars\n\telement.style.transform = style;\n\telement.style.webkitTransform = style;\n\telement.style.msTransform = style;\n\telement.style.mozTransform = style;\n\telement.style.oTransform = style;\n}\n\nfunction animateSVG(svgContainer, elements) {\n\tlet newElements = [];\n\tlet animElements = [];\n\n\telements.map(element => {\n\t\tlet unit = element[0];\n\t\tlet parent = unit.parentNode;\n\n\t\tlet animElement, newElement;\n\n\t\telement[0] = unit;\n\t\t[animElement, newElement] = animateSVGElement(...element);\n\n\t\tnewElements.push(newElement);\n\t\tanimElements.push([animElement, parent]);\n\n\t\tparent.replaceChild(animElement, unit);\n\t});\n\n\tlet animSvg = svgContainer.cloneNode(true);\n\n\tanimElements.map((animElement, i) => {\n\t\tanimElement[1].replaceChild(newElements[i], animElement[0]);\n\t\telements[i][0] = newElements[i];\n\t});\n\n\treturn animSvg;\n}\n\nexport function runSMILAnimation(parent, svgElement, elementsToAnimate) {\n\tif(elementsToAnimate.length === 0) return;\n\n\tlet animSvgElement = animateSVG(svgElement, elementsToAnimate);\n\tif(svgElement.parentNode == parent) {\n\t\tparent.removeChild(svgElement);\n\t\tparent.appendChild(animSvgElement);\n\n\t}\n\n\t// Replace the new svgElement (data has already been replaced)\n\tsetTimeout(() => {\n\t\tif(animSvgElement.parentNode == parent) {\n\t\t\tparent.removeChild(animSvgElement);\n\t\t\tparent.appendChild(svgElement);\n\t\t}\n\t}, REPLACE_ALL_NEW_DUR);\n}\n","import { floatTwo, fillArray } from '../utils/helpers';\nimport { DEFAULT_AXIS_CHART_TYPE, AXIS_DATASET_CHART_TYPES } from '../utils/constants';\n\nexport function dataPrep(data, type) {\n\tdata.labels = data.labels || [];\n\n\tlet datasetLength = data.labels.length;\n\n\t// Datasets\n\tlet datasets = data.datasets;\n\tlet zeroArray = new Array(datasetLength).fill(0);\n\tif(!datasets) {\n\t\t// default\n\t\tdatasets = [{\n\t\t\tvalues: zeroArray\n\t\t}];\n\t}\n\n\tdatasets.map((d, i)=> {\n\t\t// Set values\n\t\tif(!d.values) {\n\t\t\td.values = zeroArray;\n\t\t} else {\n\t\t\t// Check for non values\n\t\t\tlet vals = d.values;\n\t\t\tvals = vals.map(val => (!isNaN(val) ? val : 0));\n\n\t\t\t// Trim or extend\n\t\t\tif(vals.length > datasetLength) {\n\t\t\t\tvals = vals.slice(0, datasetLength);\n\t\t\t} else {\n\t\t\t\tvals = fillArray(vals, datasetLength - vals.length, 0);\n\t\t\t}\n\t\t}\n\n\t\t// Set labels\n\t\t//\n\n\t\t// Set type\n\t\tif(!d.chartType ) {\n\t\t\tif(!AXIS_DATASET_CHART_TYPES.includes(type)) type === DEFAULT_AXIS_CHART_TYPE;\n\t\t\td.chartType = type;\n\t\t}\n\n\t});\n\n\t// Markers\n\n\t// Regions\n\t// data.yRegions = data.yRegions || [];\n\tif(data.yRegions) {\n\t\tdata.yRegions.map(d => {\n\t\t\tif(d.end < d.start) {\n\t\t\t\t[d.start, d.end] = [d.end, start];\n\t\t\t}\n\t\t});\n\t}\n\n\treturn data;\n}\n\nexport function zeroDataPrep(realData) {\n\tlet datasetLength = realData.labels.length;\n\tlet zeroArray = new Array(datasetLength).fill(0);\n\n\tlet zeroData = {\n\t\tlabels: realData.labels,\n\t\tdatasets: realData.datasets.map(d => {\n\t\t\treturn {\n\t\t\t\tname: '',\n\t\t\t\tvalues: zeroArray,\n\t\t\t\tchartType: d.chartType\n\t\t\t}\n\t\t}),\n\t\tyRegions: [\n\t\t\t{\n\t\t\t\tstart: 0,\n\t\t\t\tend: 0,\n\t\t\t\tlabel: ''\n\t\t\t}\n\t\t],\n\t\tyMarkers: [\n\t\t\t{\n\t\t\t\tvalue: 0,\n\t\t\t\tlabel: ''\n\t\t\t}\n\t\t]\n\t};\n\n\treturn zeroData;\n}","import { makeSVGGroup } from '../utils/draw';\nimport { xLine, yLine, yMarker, yRegion, datasetBar } from '../utils/draw';\nimport { equilizeNoOfElements } from '../utils/draw-utils';\nimport { Animator, translateHoriLine, translateVertLine, animateRegion } from '../utils/animate';\n\nclass ChartComponent {\n\tconstructor({\n\t\tlayerClass = '',\n\t\tlayerTransform = '',\n\t\tconstants,\n\n\t\tgetData,\n\t\tmakeElements,\n\t\tpostMake,\n\t\tanimateElements\n\t}) {\n\t\tthis.layerTransform = layerTransform;\n\t\tthis.constants = constants;\n\n\t\tthis.makeElements = makeElements;\n\t\tthis.postMake = postMake;\n\t\tthis.getData = getData;\n\n\t\tthis.animateElements = animateElements;\n\n\t\tthis.store = [];\n\n\t\tthis.layerClass = layerClass;\n\t\tthis.layerClass = typeof(this.layerClass) === 'function'\n\t\t\t? this.layerClass() : this.layerClass;\n\n\t\tthis.refresh();\n\t}\n\n\trefresh(data) {\n\t\tthis.data = data || this.getData();\n\t}\n\n\tsetup(parent) {\n\t\tthis.layer = makeSVGGroup(parent, this.layerClass, this.layerTransform);\n\t}\n\n\tmake() {\n\t\tthis.preMake && this.preMake();\n\t\tthis.render(this.data);\n\t\tthis.postMake && this.postMake();\n\t\tthis.oldData = this.data;\n\t}\n\n\trender(data) {\n\t\tthis.store = this.makeElements(data);\n\n\t\tthis.layer.textContent = '';\n\t\tthis.store.forEach(element => {\n\t\t\tthis.layer.appendChild(element);\n\t\t});\n\t}\n\n\tupdate(animate = true) {\n\t\tthis.refresh();\n\t\tlet animateElements = []\n\t\tif(animate) {\n\t\t\tanimateElements = this.animateElements(this.data);\n\t\t}\n\t\t// TODO: Can we remove this?\n\t\tsetTimeout(() => {\n\t\t\tthis.make();\n\t\t}, 1400);\n\t\treturn animateElements;\n\t}\n}\n\nlet componentConfigs = {\n\tyAxis: {\n\t\tlayerClass: 'y axis',\n\t\tmakeElements(data) {\n\t\t\treturn data.positions.map((position, i) =>\n\t\t\t\tyLine(position, data.labels[i], this.constants.width,\n\t\t\t\t\t{mode: this.constants.mode, pos: this.constants.pos})\n\t\t\t);\n\t\t},\n\n\t\tanimateElements(newData) {\n\t\t\tlet newPos = newData.positions;\n\t\t\tlet newLabels = newData.labels;\n\t\t\tlet oldPos = this.oldData.positions;\n\t\t\tlet oldLabels = this.oldData.labels;\n\n\t\t\t[oldPos, newPos] = equilizeNoOfElements(oldPos, newPos);\n\t\t\t[oldLabels, newLabels] = equilizeNoOfElements(oldLabels, newLabels);\n\n\t\t\tthis.render({\n\t\t\t\tpositions: oldPos,\n\t\t\t\tlabels: newLabels\n\t\t\t});\n\n\t\t\treturn this.store.map((line, i) => {\n\t\t\t\treturn translateHoriLine(\n\t\t\t\t\tline, newPos[i], oldPos[i]\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t},\n\n\txAxis: {\n\t\tlayerClass: 'x axis',\n\t\tmakeElements(data) {\n\t\t\treturn data.positions.map((position, i) =>\n\t\t\t\txLine(position, data.labels[i], this.constants.height,\n\t\t\t\t\t{mode: this.constants.mode, pos: this.constants.pos})\n\t\t\t);\n\t\t},\n\n\t\tanimateElements(newData) {\n\t\t\tlet newPos = newData.positions;\n\t\t\tlet newLabels = newData.labels;\n\t\t\tlet oldPos = this.oldData.positions;\n\t\t\tlet oldLabels = this.oldData.labels;\n\n\t\t\t[oldPos, newPos] = equilizeNoOfElements(oldPos, newPos);\n\t\t\t[oldLabels, newLabels] = equilizeNoOfElements(oldLabels, newLabels);\n\n\t\t\tthis.render({\n\t\t\t\tpositions: oldPos,\n\t\t\t\tlabels: newLabels\n\t\t\t});\n\n\t\t\treturn this.store.map((line, i) => {\n\t\t\t\treturn translateVertLine(\n\t\t\t\t\tline, newPos[i], oldPos[i]\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t},\n\n\tyMarkers: {\n\t\tlayerClass: 'y-markers',\n\t\tmakeElements(data) {\n\t\t\treturn data.map(marker =>\n\t\t\t\tyMarker(marker.position, marker.label, this.constants.width,\n\t\t\t\t\t{pos:'right', mode: 'span', lineType: 'dashed'})\n\t\t\t);\n\t\t},\n\t\tanimateElements(newData) {\n\t\t\t[this.oldData, newData] = equilizeNoOfElements(this.oldData, newData);\n\n\t\t\tlet newPos = newData.map(d => d.position);\n\t\t\tlet newLabels = newData.map(d => d.label);\n\n\t\t\tlet oldPos = this.oldData.map(d => d.position);\n\t\t\tlet oldLabels = this.oldData.map(d => d.label);\n\n\t\t\tthis.render(oldPos.map((pos, i) => {\n\t\t\t\treturn {\n\t\t\t\t\tposition: oldPos[i],\n\t\t\t\t\tlabel: newLabels[i]\n\t\t\t\t}\n\t\t\t}));\n\n\t\t\treturn this.store.map((line, i) => {\n\t\t\t\treturn translateHoriLine(\n\t\t\t\t\tline, newPos[i], oldPos[i]\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t},\n\n\tyRegions: {\n\t\tlayerClass: 'y-regions',\n\t\tmakeElements(data) {\n\t\t\treturn data.map(region =>\n\t\t\t\tyRegion(region.start, region.end, this.constants.width,\n\t\t\t\t\tregion.label)\n\t\t\t);\n\t\t},\n\t\tanimateElements(newData) {\n\t\t\t[this.oldData, newData] = equilizeNoOfElements(this.oldData, newData);\n\n\t\t\tlet newPos = newData.map(d => d.end);\n\t\t\tlet newLabels = newData.map(d => d.label);\n\t\t\tlet newStarts = newData.map(d => d.start);\n\n\t\t\tlet oldPos = this.oldData.map(d => d.end);\n\t\t\tlet oldLabels = this.oldData.map(d => d.label);\n\t\t\tlet oldStarts = this.oldData.map(d => d.start);\n\n\t\t\tthis.render(oldPos.map((pos, i) => {\n\t\t\t\treturn {\n\t\t\t\t\tstart: oldStarts[i],\n\t\t\t\t\tend: oldPos[i],\n\t\t\t\t\tlabel: newLabels[i]\n\t\t\t\t}\n\t\t\t}));\n\n\t\t\tlet animateElements = [];\n\n\t\t\tthis.store.map((rectGroup, i) => {\n\t\t\t\tanimateElements = animateElements.concat(animateRegion(\n\t\t\t\t\trectGroup, newStarts[i], newPos[i], oldPos[i]\n\t\t\t\t));\n\t\t\t});\n\n\t\t\treturn animateElements;\n\t\t}\n\t},\n\n\tbarGraph: {\n\t\tlayerClass: function() { return 'dataset-units dataset-' + this.constants.index; },\n\t\tmakeElements(data) {\n\t\t\tlet c = this.constants;\n\t\t\treturn data.yPositions.map((y, j) => {\n\t\t\t\t// console.log(data.cumulativeYPos, data.cumulativeYPos[j]);\n\t\t\t\treturn datasetBar(\n\t\t\t\t\tdata.xPositions[j],\n\t\t\t\t\ty,\n\t\t\t\t\tc.barWidth,\n\t\t\t\t\tc.color,\n\t\t\t\t\t(c.valuesOverPoints ? (c.stacked ? data.cumulativeYs[j] : data.values[j]) : ''),\n\t\t\t\t\tj,\n\t\t\t\t\ty - (c.stacked ? data.cumulativeYPos[j] : y),\n\t\t\t\t\t{\n\t\t\t\t\t\tzeroLine: c.zeroLine,\n\t\t\t\t\t\tbarsWidth: c.barsWidth,\n\t\t\t\t\t\tminHeight: c.minHeight\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t});\n\t\t},\n\t\tpostMake() {\n\t\t\tif((!this.constants.stacked)) {\n\t\t\t\tthis.layer.setAttribute('transform',\n\t\t\t\t\t`translate(${this.constants.width * this.constants.index}, 0)`);\n\t\t\t}\n\t\t},\n\t\tanimateElements(newData) {\n\t\t\t// [this.oldData, newData] = equilizeNoOfElements(this.oldData, newData);\n\n\t\t\t// let newPos = newData.map(d => d.end);\n\t\t\t// let newLabels = newData.map(d => d.label);\n\t\t\t// let newStarts = newData.map(d => d.start);\n\n\t\t\t// let oldPos = this.oldData.map(d => d.end);\n\t\t\t// let oldLabels = this.oldData.map(d => d.label);\n\t\t\t// let oldStarts = this.oldData.map(d => d.start);\n\n\t\t\t// this.render(oldPos.map((pos, i) => {\n\t\t\t// \treturn {\n\t\t\t// \t\tstart: oldStarts[i],\n\t\t\t// \t\tend: oldPos[i],\n\t\t\t// \t\tlabel: newLabels[i]\n\t\t\t// \t}\n\t\t\t// }));\n\n\t\t\t// let animateElements = [];\n\n\t\t\t// this.store.map((rectGroup, i) => {\n\t\t\t// \tanimateElements = animateElements.concat(animateRegion(\n\t\t\t// \t\trectGroup, newStarts[i], newPos[i], oldPos[i]\n\t\t\t// \t));\n\t\t\t// });\n\n\t\t\t// return animateElements;\n\t\t}\n\t},\n\n\tlineGraph: {\n\n\t}\n}\n\nexport function getComponent(name, constants, getData) {\n\tlet config = componentConfigs[name];\n\tObject.assign(config, {\n\t\tconstants: constants,\n\t\tgetData: getData\n\t})\n\treturn new ChartComponent(config);\n}\n","import { floatTwo } from './helpers';\n\nfunction normalize(x) {\n\t// Calculates mantissa and exponent of a number\n\t// Returns normalized number and exponent\n\t// https://stackoverflow.com/q/9383593/6495043\n\n\tif(x===0) {\n\t\treturn [0, 0];\n\t}\n\tif(isNaN(x)) {\n\t\treturn {mantissa: -6755399441055744, exponent: 972};\n\t}\n\tvar sig = x > 0 ? 1 : -1;\n\tif(!isFinite(x)) {\n\t\treturn {mantissa: sig * 4503599627370496, exponent: 972};\n\t}\n\n\tx = Math.abs(x);\n\tvar exp = Math.floor(Math.log10(x));\n\tvar man = x/Math.pow(10, exp);\n\n\treturn [sig * man, exp];\n}\n\nfunction getChartRangeIntervals(max, min=0) {\n\tlet upperBound = Math.ceil(max);\n\tlet lowerBound = Math.floor(min);\n\tlet range = upperBound - lowerBound;\n\n\tlet noOfParts = range;\n\tlet partSize = 1;\n\n\t// To avoid too many partitions\n\tif(range > 5) {\n\t\tif(range % 2 !== 0) {\n\t\t\tupperBound++;\n\t\t\t// Recalc range\n\t\t\trange = upperBound - lowerBound;\n\t\t}\n\t\tnoOfParts = range/2;\n\t\tpartSize = 2;\n\t}\n\n\t// Special case: 1 and 2\n\tif(range <= 2) {\n\t\tnoOfParts = 4;\n\t\tpartSize = range/noOfParts;\n\t}\n\n\t// Special case: 0\n\tif(range === 0) {\n\t\tnoOfParts = 5;\n\t\tpartSize = 1;\n\t}\n\n\tlet intervals = [];\n\tfor(var i = 0; i <= noOfParts; i++){\n\t\tintervals.push(lowerBound + partSize * i);\n\t}\n\treturn intervals;\n}\n\nfunction getChartIntervals(maxValue, minValue=0) {\n\tlet [normalMaxValue, exponent] = normalize(maxValue);\n\tlet normalMinValue = minValue ? minValue/Math.pow(10, exponent): 0;\n\n\t// Allow only 7 significant digits\n\tnormalMaxValue = normalMaxValue.toFixed(6);\n\n\tlet intervals = getChartRangeIntervals(normalMaxValue, normalMinValue);\n\tintervals = intervals.map(value => value * Math.pow(10, exponent));\n\treturn intervals;\n}\n\nexport function calcChartIntervals(values, withMinimum=false) {\n\t//*** Where the magic happens ***\n\n\t// Calculates best-fit y intervals from given values\n\t// and returns the interval array\n\n\tlet maxValue = Math.max(...values);\n\tlet minValue = Math.min(...values);\n\n\t// Exponent to be used for pretty print\n\tlet exponent = 0, intervals = []; // eslint-disable-line no-unused-vars\n\n\tfunction getPositiveFirstIntervals(maxValue, absMinValue) {\n\t\tlet intervals = getChartIntervals(maxValue);\n\n\t\tlet intervalSize = intervals[1] - intervals[0];\n\n\t\t// Then unshift the negative values\n\t\tlet value = 0;\n\t\tfor(var i = 1; value < absMinValue; i++) {\n\t\t\tvalue += intervalSize;\n\t\t\tintervals.unshift((-1) * value);\n\t\t}\n\t\treturn intervals;\n\t}\n\n\t// CASE I: Both non-negative\n\n\tif(maxValue >= 0 && minValue >= 0) {\n\t\texponent = normalize(maxValue)[1];\n\t\tif(!withMinimum) {\n\t\t\tintervals = getChartIntervals(maxValue);\n\t\t} else {\n\t\t\tintervals = getChartIntervals(maxValue, minValue);\n\t\t}\n\t}\n\n\t// CASE II: Only minValue negative\n\n\telse if(maxValue > 0 && minValue < 0) {\n\t\t// `withMinimum` irrelevant in this case,\n\t\t// We'll be handling both sides of zero separately\n\t\t// (both starting from zero)\n\t\t// Because ceil() and floor() behave differently\n\t\t// in those two regions\n\n\t\tlet absMinValue = Math.abs(minValue);\n\n\t\tif(maxValue >= absMinValue) {\n\t\t\texponent = normalize(maxValue)[1];\n\t\t\tintervals = getPositiveFirstIntervals(maxValue, absMinValue);\n\t\t} else {\n\t\t\t// Mirror: maxValue => absMinValue, then change sign\n\t\t\texponent = normalize(absMinValue)[1];\n\t\t\tlet posIntervals = getPositiveFirstIntervals(absMinValue, maxValue);\n\t\t\tintervals = posIntervals.map(d => d * (-1));\n\t\t}\n\n\t}\n\n\t// CASE III: Both non-positive\n\n\telse if(maxValue <= 0 && minValue <= 0) {\n\t\t// Mirrored Case I:\n\t\t// Work with positives, then reverse the sign and array\n\n\t\tlet pseudoMaxValue = Math.abs(minValue);\n\t\tlet pseudoMinValue = Math.abs(maxValue);\n\n\t\texponent = normalize(pseudoMaxValue)[1];\n\t\tif(!withMinimum) {\n\t\t\tintervals = getChartIntervals(pseudoMaxValue);\n\t\t} else {\n\t\t\tintervals = getChartIntervals(pseudoMaxValue, pseudoMinValue);\n\t\t}\n\n\t\tintervals = intervals.reverse().map(d => d * (-1));\n\t}\n\n\treturn intervals;\n}\n\nexport function getZeroIndex(yPts) {\n\tlet zeroIndex;\n\tlet interval = getIntervalSize(yPts);\n\tif(yPts.indexOf(0) >= 0) {\n\t\t// the range has a given zero\n\t\t// zero-line on the chart\n\t\tzeroIndex = yPts.indexOf(0);\n\t} else if(yPts[0] > 0) {\n\t\t// Minimum value is positive\n\t\t// zero-line is off the chart: below\n\t\tlet min = yPts[0];\n\t\tzeroIndex = (-1) * min / interval;\n\t} else {\n\t\t// Maximum value is negative\n\t\t// zero-line is off the chart: above\n\t\tlet max = yPts[yPts.length - 1];\n\t\tzeroIndex = (-1) * max / interval + (yPts.length - 1);\n\t}\n\treturn zeroIndex;\n}\n\nexport function getRealIntervals(max, noOfIntervals, min = 0, asc = 1) {\n\tlet range = max - min;\n\tlet part = range * 1.0 / noOfIntervals;\n\tlet intervals = [];\n\n\tfor(var i = 0; i <= noOfIntervals; i++) {\n\t\tintervals.push(min + part * i);\n\t}\n\n\treturn asc ? intervals : intervals.reverse();\n}\n\nexport function getIntervalSize(orderedArray) {\n\treturn orderedArray[1] - orderedArray[0];\n}\n\nexport function getValueRange(orderedArray) {\n\treturn orderedArray[orderedArray.length-1] - orderedArray[0];\n}\n\nexport function scale(val, yAxis) {\n\treturn floatTwo(yAxis.zeroLine - val * yAxis.scaleMultiplier)\n}\n\nexport function calcDistribution(values, distributionSize) {\n\t// Assume non-negative values,\n\t// implying distribution minimum at zero\n\n\tlet dataMaxValue = Math.max(...values);\n\n\tlet distributionStep = 1 / (distributionSize - 1);\n\tlet distribution = [];\n\n\tfor(var i = 0; i < distributionSize; i++) {\n\t\tlet checkpoint = dataMaxValue * (distributionStep * i);\n\t\tdistribution.push(checkpoint);\n\t}\n\n\treturn distribution;\n}\n\nexport function getMaxCheckpoint(value, distribution) {\n\treturn distribution.filter(d => d < value).length;\n}\n","// Playing around with dates\n\n// https://stackoverflow.com/a/11252167/6495043\nfunction treatAsUtc(dateStr) {\n\tlet result = new Date(dateStr);\n\tresult.setMinutes(result.getMinutes() - result.getTimezoneOffset());\n\treturn result;\n}\n\nexport function getDdMmYyyy(date) {\n\tlet dd = date.getDate();\n\tlet mm = date.getMonth() + 1; // getMonth() is zero-based\n\treturn [\n\t\t(dd>9 ? '' : '0') + dd,\n\t\t(mm>9 ? '' : '0') + mm,\n\t\tdate.getFullYear()\n\t].join('-');\n}\n\nexport function getWeeksBetween(startDateStr, endDateStr) {\n\treturn Math.ceil(getDaysBetween(startDateStr, endDateStr) / 7);\n}\n\nexport function getDaysBetween(startDateStr, endDateStr) {\n\tlet millisecondsPerDay = 24 * 60 * 60 * 1000;\n\treturn (treatAsUtc(endDateStr) - treatAsUtc(startDateStr)) / millisecondsPerDay;\n}\n\n// mutates\nexport function addDays(date, numberOfDays) {\n\tdate.setDate(date.getDate() + numberOfDays);\n}\n\n// export function getMonthName() {}\n","import '../scss/charts.scss';\n\nimport ScatterChart from './charts/ScatterChart';\nimport MultiAxisChart from './charts/MultiAxisChart';\nimport PercentageChart from './charts/PercentageChart';\nimport PieChart from './charts/PieChart';\nimport Heatmap from './charts/Heatmap';\nimport AxisChart from './charts/AxisChart';\n\n// if (ENV !== 'production') {\n// \t// Enable LiveReload\n// \tdocument.write(\n// \t\t'