diff --git a/dist/frappe-charts.esm.js b/dist/frappe-charts.esm.js index 74c5ee5..c653f53 100644 --- a/dist/frappe-charts.esm.js +++ b/dist/frappe-charts.esm.js @@ -290,6 +290,23 @@ const REPLACE_ALL_NEW_DUR = 250; const STD_EASING = 'easein'; +function translate(unit, oldCoord, newCoord, duration) { + return [ + unit, + {transform: newCoord.join(', ')}, + duration, + STD_EASING, + "translate", + {transform: oldCoord.join(', ')} + ]; +} + + + +function translateHoriLine(yLine, newY, oldY) { + return translate(yLine, [0, oldY], [0, newY], MARKER_LINE_ANIM_DUR); +} + const AXIS_TICK_LENGTH = 6; const LABEL_MARGIN = 4; const FONT_SIZE = 10; @@ -478,8 +495,8 @@ function makeHoriLine(y, label, x1, x2, options={}) { className: className, x1: x1, x2: x2, - y1: y, - y2: y, + y1: 0, + y2: 0, styles: { stroke: options.stroke } @@ -487,7 +504,7 @@ function makeHoriLine(y, label, x1, x2, options={}) { let text = createSVG('text', { x: x1 < x2 ? x1 - LABEL_MARGIN : x1 + LABEL_MARGIN, - y: y, + y: 0, dy: (FONT_SIZE / 2 - 2) + 'px', 'font-size': FONT_SIZE + 'px', 'text-anchor': x1 < x2 ? 'end' : 'start', @@ -495,6 +512,7 @@ function makeHoriLine(y, label, x1, x2, options={}) { }); let line = createSVG('g', { + transform: `translate(0, ${y})`, 'stroke-opacity': 1 }); @@ -508,6 +526,31 @@ function makeHoriLine(y, label, x1, x2, options={}) { return line; } +function yLine(y, label, width, options={}) { + if(!options.pos) options.pos = 'left'; + if(!options.offset) options.offset = 0; + if(!options.mode) options.mode = 'span'; + if(!options.stroke) options.stroke = BASE_LINE_COLOR; + if(!options.className) options.className = ''; + + let x1 = -1 * AXIS_TICK_LENGTH; + let x2 = options.mode === 'span' ? width + AXIS_TICK_LENGTH : 0; + + if(options.mode === 'tick' && options.pos === 'right') { + x1 = width + AXIS_TICK_LENGTH; + x2 = width; + } + + x1 += options.offset; + x2 += options.offset; + + return makeHoriLine(y, label, x1, x2, { + stroke: options.stroke, + className: options.className, + lineType: options.lineType + }); +} + class AxisChartRenderer { constructor(state) { this.refreshState(state); @@ -529,7 +572,7 @@ class AxisChartRenderer { xLine(x, label, options={}) { if(!options.pos) options.pos = 'bottom'; if(!options.offset) options.offset = 0; - if(!options.mode) options.mode = this.xAxisMode; + if(!options.mode) options.mode = 'span'; if(!options.stroke) options.stroke = BASE_LINE_COLOR; if(!options.className) options.className = ''; @@ -560,30 +603,7 @@ class AxisChartRenderer { }); } - yLine(y, label, options={}) { - if(!options.pos) options.pos = 'left'; - if(!options.offset) options.offset = 0; - if(!options.mode) options.mode = this.yAxisMode; - if(!options.stroke) options.stroke = BASE_LINE_COLOR; - if(!options.className) options.className = ''; - - let x1 = -1 * AXIS_TICK_LENGTH; - let x2 = options.mode === 'span' ? this.totalWidth + AXIS_TICK_LENGTH : 0; - - if(options.mode === 'tick' && options.pos === 'right') { - x1 = this.totalWidth + AXIS_TICK_LENGTH; - x2 = this.totalWidth; - } - - x1 += options.offset; - x2 += options.offset; - return makeHoriLine(y, label, x1, x2, { - stroke: options.stroke, - className: options.className, - lineType: options.lineType - }); - } xMarker() {} @@ -713,25 +733,6 @@ class AxisChartRenderer { return pathComponents; } - - translate(unit, oldCoord, newCoord, duration) { - return [ - unit, - {transform: newCoord.join(', ')}, - duration, - STD_EASING, - "translate", - {transform: oldCoord.join(', ')} - ]; - } - - translateVertLine(xLine, newX, oldX) { - return this.translate(xLine, [oldX, 0], [newX, 0], MARKER_LINE_ANIM_DUR); - } - - translateHoriLine(yLine, newY, oldY) { - return this.translate(yLine, [0, oldY], [0, newY], MARKER_LINE_ANIM_DUR); - } } const PRESET_COLOR_MAP = { @@ -1066,11 +1067,15 @@ class BaseChart { _setup() { this.bindWindowEvents(); this.setupConstants(); - this.setupComponents(); this.setMargins(); this.makeContainer(); this.makeTooltip(); // without binding + + this.calcWidth(); + this.makeChartArea(); + this.setupComponents(); + this.draw(true); } @@ -1113,31 +1118,13 @@ class BaseChart { bindTooltip() {} draw(init=false) { - // difference from update(): draw the whole object due to groudbreaking event (init, resize, etc.) - // (draw everything, layers, groups, units) - - this.calcWidth(); - - // refresh conponent with chart - this.refresh(this.data); - - this.makeChartArea(); - this.setComponentParent(); - this.makeComponentLayers(); - + this.components.forEach(c => c.make()); // or c.build() this.renderLegend(); - this.setupNavigation(init); - - // first time plain render, so no rerender - this.renderComponents(); - this.renderConstants(); - if(this.config.animate) this.update(this.firstUpdateData); - } + this.setupNavigation(init); - update(data) { - this.refresh(data); - this.reRender(); + // TODO: remove timeout and decrease post animate time in chart component + setTimeout(() => {this.update();}, 1000); } calcWidth() { @@ -1153,15 +1140,34 @@ class BaseChart { this.width = this.baseWidth - (this.translateXLeft + this.translateXRight); } - refresh(data) { //?? refresh? - this.oldState = this.state ? JSON.parse(JSON.stringify(this.state)) : {}; - this.intermedState = {}; // use this for the extra position problems? - + update(data=this.data) { this.prepareData(data); - this.reCalc(); + this.calc(); // builds state this.refreshRenderer(); + this.render(); } + prepareData() {} + + renderConstants() {} + + calc() {} // builds state + + refreshRenderer() { + this.renderer = {}; + } + + render(animate=true) { + this.refreshComponents(); + this.elementsToAnimate = [].concat.apply([], this.components.map(c => c.update(animate))); + console.log(this.elementsToAnimate); + if(this.elementsToAnimate) { + runSMILAnimation(this.chartWrapper, this.svg, this.elementsToAnimate); + } + } + + refreshComponents() {} + makeChartArea() { this.svg = makeSVGContainer( this.chartWrapper, @@ -1185,41 +1191,6 @@ class BaseChart { ); } - prepareData() {} - - renderConstants() {} - - reCalc() {} - // Will update values(state) - // Will recalc specific parts depending on the update - - refreshRenderer() { - this.renderer = {}; - } - - reRender(animate=true) { - if(!animate) { - this.renderComponents(); - return; - } - this.elementsToAnimate = []; - this.loadAnimatedComponents(); - runSMILAnimation(this.chartWrapper, this.svg, this.elementsToAnimate); - setTimeout(() => { - this.renderComponents(); - }, 400); - // TODO: should be max anim duration required - // (opt, should not redraw if still in animate?) - } - - // convenient component array abstractions - setComponentParent() { this.components.forEach(c => c.setupParent(this.drawArea)); }; - makeComponentLayers() { this.components.forEach(c => c.makeLayer()); } - renderComponents() { this.components.forEach(c => c.render()); } - loadAnimatedComponents() { this.components.forEach(c => c.loadAnimatedComponents()); } - - refreshComponents() { this.components.forEach(c => c.refresh(this.state, this.rawChartArgs)); } - renderLegend() {} setupNavigation(init=false) { @@ -1299,66 +1270,107 @@ class BaseChart { const Y_AXIS_MARGIN = 60; -class ChartComponent { +class ChartComponent$1 { constructor({ layerClass = '', layerTransform = '', - initData, + parent, + constants, + data, // called on update - setData, preMake, - make, + makeElements, postMake, - animate + animateElements }) { + this.parent = parent; this.layerClass = layerClass; this.layerTransform = layerTransform; - - this.initData = initData; - this.setData = setData; + this.constants = constants; this.preMake = preMake; - this.make = make; + this.makeElements = makeElements; this.postMake = postMake; - this.animate = animate; + this.animateElements = animateElements; - this.layer = undefined; this.store = []; - } + this.layer = makeSVGGroup(this.parent, this.layerClass, this.layerTransform); - refresh(state, args) { - this.meta = Object.assign((this.meta || {}), args); - this.state = state; - } + this.data = data; + this.make(); + } - render() { - this.data = this.setData(); // The only without this function? + refresh(data) { + this.data = data; + } + make() { this.preMake && this.preMake(); - this.store = this.make(); + this.render(this.data); + this.postMake && this.postMake(); + this.oldData = this.data; + } + + render(data) { + this.store = this.makeElements(data); this.layer.textContent = ''; this.store.forEach(element => { this.layer.appendChild(element); }); - - this.postMake && this.postMake(); } - setupParent(parent) { - this.parent = parent; + update(animate = true) { + let animateElements = []; + if(animate) { + animateElements = this.animateElements(this.data); + } + // TODO: Can we remove this? + setTimeout(() => { + this.make(); + }, 1400); + return animateElements; } +} - loadAnimatedComponents() { - this.animate(this.store); - } +function getYAxisComponent(parent, constants, initData) { + return new ChartComponent$1({ + parent: parent, + layerClass: 'y axis', + constants: constants, + data: initData, + makeElements: function(data) { + return data.positions.map((position, i) => + yLine(position, data.labels[i], this.constants.width, + {mode: this.constants.mode, pos: this.constants.pos}) + ); + }, + + animateElements: function(newData) { + let newPos = newData.positions; + let newLabels = newData.labels; + + let oldPos = this.oldData.positions; + let oldLabels = this.oldData.labels; + + [oldPos, newPos] = equilizeNoOfElements(oldPos, newPos); + [oldLabels, newLabels] = equilizeNoOfElements(oldLabels, newLabels); + + this.render({ + positions: oldPos, + labels: newLabels + }); - makeLayer() { - this.layer = makeSVGGroup(this.parent, this.layerClass, this.layerTransform); - } + return this.store.map((line, i) => { + return translateHoriLine( + line, newPos[i], oldPos[i] + ); + }); + } + }) } const MIN_BAR_PERCENT_HEIGHT$1 = 0.01; @@ -1612,7 +1624,7 @@ function normalize(x) { return [sig * man, exp]; } -function getRangeIntervals(max, min=0) { +function getChartRangeIntervals(max, min=0) { let upperBound = Math.ceil(max); let lowerBound = Math.floor(min); let range = upperBound - lowerBound; @@ -1650,19 +1662,19 @@ function getRangeIntervals(max, min=0) { return intervals; } -function getIntervals(maxValue, minValue=0) { +function getChartIntervals(maxValue, minValue=0) { let [normalMaxValue, exponent] = normalize(maxValue); let normalMinValue = minValue ? minValue/Math.pow(10, exponent): 0; // Allow only 7 significant digits normalMaxValue = normalMaxValue.toFixed(6); - let intervals = getRangeIntervals(normalMaxValue, normalMinValue); + let intervals = getChartRangeIntervals(normalMaxValue, normalMinValue); intervals = intervals.map(value => value * Math.pow(10, exponent)); return intervals; } -function calcIntervals(values, withMinimum=false) { +function calcChartIntervals(values, withMinimum=false) { //*** Where the magic happens *** // Calculates best-fit y intervals from given values @@ -1675,7 +1687,7 @@ function calcIntervals(values, withMinimum=false) { let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars function getPositiveFirstIntervals(maxValue, absMinValue) { - let intervals = getIntervals(maxValue); + let intervals = getChartIntervals(maxValue); let intervalSize = intervals[1] - intervals[0]; @@ -1693,9 +1705,9 @@ function calcIntervals(values, withMinimum=false) { if(maxValue >= 0 && minValue >= 0) { exponent = normalize(maxValue)[1]; if(!withMinimum) { - intervals = getIntervals(maxValue); + intervals = getChartIntervals(maxValue); } else { - intervals = getIntervals(maxValue, minValue); + intervals = getChartIntervals(maxValue, minValue); } } @@ -1733,9 +1745,9 @@ function calcIntervals(values, withMinimum=false) { exponent = normalize(pseudoMaxValue)[1]; if(!withMinimum) { - intervals = getIntervals(pseudoMaxValue); + intervals = getChartIntervals(pseudoMaxValue); } else { - intervals = getIntervals(pseudoMaxValue, pseudoMinValue); + intervals = getChartIntervals(pseudoMaxValue, pseudoMinValue); } intervals = intervals.reverse().map(d => d * (-1)); @@ -1765,6 +1777,18 @@ function getZeroIndex(yPts) { return zeroIndex; } +function getRealIntervals(max, noOfIntervals, min = 0, asc = 1) { + let range = max - min; + let part = range * 1.0 / noOfIntervals; + let intervals = []; + + for(var i = 0; i <= noOfIntervals; i++) { + intervals.push(min + part * i); + } + + return asc ? intervals : intervals.reverse(); +} + function getIntervalSize(orderedArray) { return orderedArray[1] - orderedArray[0]; } @@ -1805,6 +1829,9 @@ class AxisChart extends BaseChart { this.lineOptions = args.lineOptions; this.type = args.type || 'line'; + this.xAxisMode = args.xAxisMode || 'span'; + this.yAxisMode = args.yAxisMode || 'span'; + this.setupUnitRenderer(); this.zeroLine = this.height; @@ -1908,7 +1935,7 @@ class AxisChart extends BaseChart { }; } - reCalc() { + calc() { let s = this.state; s.xAxisLabels = this.data.labels; @@ -1940,7 +1967,7 @@ class AxisChart extends BaseChart { } calcYAxisParameters(yAxis, dataValues, withMinimum = 'false') { - yAxis.labels = calcIntervals(dataValues, withMinimum); + yAxis.labels = calcChartIntervals(dataValues, withMinimum); const yPts = yAxis.labels; yAxis.scaleMultiplier = this.height / getValueRange(yPts); @@ -2040,78 +2067,63 @@ class AxisChart extends BaseChart { // this.bind_units(units_array); // } + this.yAxis = getYAxisComponent( + this.drawArea, + { + mode: this.yAxisMode, + width: this.width, + // pos: 'right' + }, + { + positions: getRealIntervals(this.height, 4, 0, 0), + labels: getRealIntervals(this.height, 4, 0, 0).map(d => d + ""), + } + ); this.components = [ - ...this.getYAxesComponents(), - this.getXAxisComponents(), - ...this.getYRegions(), - ...this.getXRegions(), - ...this.getYMarkerLines(), - // ...this.getXMarkerLines(), - ...this.getChartComponents(), - ...this.getChartLabels(), + this.yAxis + // this.getXAxisComponents(), + // ...this.getYRegions(), + // ...this.getXRegions(), + // ...this.getYMarkerLines(), + // // ...this.getXMarkerLines(), + // ...this.getChartComponents(), + // ...this.getChartLabels(), ]; } - getYAxesComponents() { - return [new ChartComponent({ - layerClass: 'y axis', - setData: () => { - // let s = this.state; - - // data = {}; - - - // return data; - }, - initializeData: function() { - this.axesPositions = this.state; - }, - make: () => { - // positions, labels, renderer - let s = this.state; - return s.yAxis.positions.map((position, i) => - this.renderer.yLine(position, s.yAxis.labels[i], {pos:'right'}) - ); - }, - animate: (yLines) => { - // Equilize - let newY = this.state.yAxis.positions; - let oldY = this.oldState.yAxis.positions; - - let extra = newY.length - oldY.length; - let lastLine = yLines[yLines.length - 1]; - let parentNode = lastLine.parentNode; - - [oldY, newY] = equilizeNoOfElements(oldY, newY); - // console.log(newY.slice(), oldY.slice()); - if(extra > 0) { - for(var i = 0; i { - // console.log(line, newY[i], oldY[i]); - this.elementsToAnimate.push(this.renderer.translateHoriLine( - line, newY[i], oldY[i] - )); - }); - } - })]; + refreshYAxis() { + let s = this.state; + this.yAxis.refresh({ + positions: s.yAxis.positions, + labels: s.yAxis.labels, + }); } getXAxisComponents() { return new ChartComponent({ layerClass: 'x axis', - setData: () => {}, - make: () => { + setData: () => { + let s = this.state; + let data = { + positions: s.xAxisPositions, + labels: s.xAxisLabels, + }; + let constants = { + mode: this.xAxisMode, + height: this.height + }; + return [data, constants]; + }, + makeElements: () => { let s = this.state; // positions // TODO: xAxis Label spacing return s.xAxisPositions.map((position, i) => - this.renderer.xLine(position, s.xAxisLabels[i] + xLine(position, s.xAxisLabels[i], this.constants.height // , {pos:'top'} ) ); @@ -2168,7 +2180,7 @@ class AxisChart extends BaseChart { layerClass: 'dataset-units dataset-' + index, setData: () => {}, preMake: () => { }, - make: () => { + makeElements: () => { let d = this.state.datasets[index]; return d.positions.map((y, j) => { @@ -2230,7 +2242,7 @@ class AxisChart extends BaseChart { return new ChartComponent({ layerClass: 'path dataset-path', setData: () => {}, - make: () => { + makeElements: () => { let d = this.state.datasets[index]; let color = this.colors[index]; @@ -2280,7 +2292,7 @@ class AxisChart extends BaseChart { return new ChartComponent({ layerClass: 'y-markers', setData: () => {}, - make: () => { + makeElements: () => { let s = this.state; return s.yMarkers.map(marker => this.renderer.yMarker(marker.value, marker.name, @@ -2301,7 +2313,7 @@ class AxisChart extends BaseChart { return new ChartComponent({ layerClass: 'y-regions', setData: () => {}, - make: () => { + makeElements: () => { let s = this.state; return s.yRegions.map(region => this.renderer.yRegion(region.start, region.end, region.name) @@ -2312,10 +2324,6 @@ class AxisChart extends BaseChart { }); } - getXRegions() { - return []; - } - refreshRenderer() { // These args are basically the current state of the chart, // with constant and alive params mixed @@ -2335,8 +2343,6 @@ class AxisChart extends BaseChart { this.renderer.refreshState(state); } - this.refreshComponents(); - let meta = { totalHeight: this.height, totalWidth: this.width, @@ -2778,40 +2784,42 @@ class PercentageChart extends BaseChart { }); } - bindTooltip() { - this.slices.map((slice, i) => { - slice.addEventListener('mouseenter', () => { - let g_off = getOffset(this.chartWrapper), p_off = getOffset(slice); + calc() {} - let x = p_off.left - g_off.left + slice.offsetWidth/2; - let y = p_off.top - g_off.top - 6; - let title = (this.formatted_labels && this.formatted_labels.length>0 - ? this.formatted_labels[i] : this.labels[i]) + ': '; - let percent = (this.slice_totals[i]*100/this.grand_total).toFixed(1); + // bindTooltip() { + // this.slices.map((slice, i) => { + // slice.addEventListener('mouseenter', () => { + // let g_off = getOffset(this.chartWrapper), p_off = getOffset(slice); - this.tip.set_values(x, y, title, percent + "%"); - this.tip.show_tip(); - }); - }); - } + // let x = p_off.left - g_off.left + slice.offsetWidth/2; + // let y = p_off.top - g_off.top - 6; + // let title = (this.formatted_labels && this.formatted_labels.length>0 + // ? this.formatted_labels[i] : this.labels[i]) + ': '; + // let percent = (this.slice_totals[i]*100/this.grand_total).toFixed(1); - renderLegend() { - let x_values = this.formatted_labels && this.formatted_labels.length > 0 - ? this.formatted_labels : this.labels; - this.legend_totals.map((d, i) => { - if(d) { - let stats = $$1.create('div', { - className: 'stats', - inside: this.statsWrapper - }); - stats.innerHTML = ` - - ${x_values[i]}: - ${d} - `; - } - }); - } + // this.tip.set_values(x, y, title, percent + "%"); + // this.tip.show_tip(); + // }); + // }); + // } + + // renderLegend() { + // let x_values = this.formatted_labels && this.formatted_labels.length > 0 + // ? this.formatted_labels : this.labels; + // this.legend_totals.map((d, i) => { + // if(d) { + // let stats = $.create('div', { + // className: 'stats', + // inside: this.statsWrapper + // }); + // stats.innerHTML = ` + // + // ${x_values[i]}: + // ${d} + // `; + // } + // }); + // } } const ANGLE_RATIO = Math.PI / 180; diff --git a/dist/frappe-charts.min.cjs.js b/dist/frappe-charts.min.cjs.js index aa6e34a..ba64e1f 100644 --- a/dist/frappe-charts.min.cjs.js +++ b/dist/frappe-charts.min.cjs.js @@ -1 +1 @@ -"use strict";function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function 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),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var i=void 0,a=void 0;return t<=e?(a=t,0===(i=e-t)&&(a-=i=totalHeight*MIN_BAR_PERCENT_HEIGHT)):(i=t-e,a=e),[i,a]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function 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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>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]}),createSVG("rect",s)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:a})}function makeVertLine(t,e,i,a){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:i,y2:a,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:i>a?i+LABEL_MARGIN:i-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,i,a){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:i,x2:a,y1:t,y2:t,styles:{stroke:n.stroke}}),r=createSVG("text",{x:i255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,i){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 a=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:a?i.colors:void 0})}}function animateSVGElement(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var 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:EASING[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 transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function animateSVG(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.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],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 runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function getPaths(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=t.map(function(t,i){return e[i]+","+t}).join("L"),r=makePath("M"+s,"line-graph-path",i);if(a){var o=makeGradient(this.svgDefs,i);r.style.stroke="url(#"+o+")"}var l=[r];if(n){var h=makeGradient(this.svgDefs,i,!0),c=this.state.yAxis.zeroLine,u="M0,"+c+"L"+s+"L"+this.width+","+c;l.push(makePath(u,"region-fill","none","url(#"+h+")"))}return l}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function 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 calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"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 i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
    \n\t\t\t\t
    '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.data_point_list.appendChild(n)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var a="calc(50% + "+(this.left-e)+"px)";i.style.left=a,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),t}(),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:"xLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode=this.xAxisMode),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var a=this.totalHeight+AXIS_TICK_LENGTH,n="span"===i.mode?-1*AXIS_TICK_LENGTH:this.totalHeight;return"tick"===i.mode&&"top"===i.pos&&(a=-1*AXIS_TICK_LENGTH,n=0),makeVertLine(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode=this.yAxisMode),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var a=-1*AXIS_TICK_LENGTH,n="span"===i.mode?this.totalWidth+AXIS_TICK_LENGTH:0;return"tick"===i.mode&&"right"===i.pos&&(a=this.totalWidth+AXIS_TICK_LENGTH,n=this.totalWidth),a+=i.offset,n+=i.offset,makeHoriLine(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(e,5)-LABEL_MARGIN,y:t-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),n=makeHoriLine(t,"",0,this.totalWidth,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return n.appendChild(a),n}},{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:"yRegion",value:function(t,e,i){var a=createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:e,width:this.totalWidth,height:t-e}),n=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:e,y2:e,styles:{stroke:BASE_LINE_COLOR}}),s=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:t,y2:t,styles:{stroke:BASE_LINE_COLOR}}),r=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(i,4.5)-LABEL_MARGIN,y:e-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{});return o.appendChild(a),o.appendChild(n),o.appendChild(s),o.appendChild(r),o}},{key:"animatebar",value:function(t,e,i,a,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(i,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var i=[],a=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];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},PATH_ANIM_DUR,STD_EASING];i.push(r)}return i}},{key:"translate",value:function(t,e,i,a){return[t,{transform:i.join(", ")},a,STD_EASING,"translate",{transform:e.join(", ")}]}},{key:"translateVertLine",value:function(t,e,i){return this.translate(t,[i,0],[e,0],MARKER_LINE_ANIM_DUR)}},{key:"translateHoriLine",value:function(t,e,i){return this.translate(t,[0,i],[0,e],MARKER_LINE_ANIM_DUR)}}]),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 i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type,e.parent);classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof c?document.querySelector(c):c,this.title=s,this.subtitle=o,this.argHeight=a,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:0},this.state={colors:this.colors}}},{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=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.refresh(this.data),this.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.renderConstants(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(t){this.refresh(t),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(t){this.oldState=this.state?JSON.parse(JSON.stringify(this.state)):{},this.intermedState={},this.prepareData(t),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){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:"prepareData",value:function(){}},{key:"renderConstants",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){this.renderer={}}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.elementsToAnimate=[],this.loadAnimatedComponents(),runSMILAnimation(this.chartWrapper,this.svg,this.elementsToAnimate),setTimeout(function(){t.renderComponents()},400)}},{key:"setComponentParent",value:function(){var t=this;this.components.forEach(function(e){return e.setupParent(t.drawArea)})}},{key:"makeComponentLayers",value:function(){this.components.forEach(function(t){return t.makeLayer()})}},{key:"renderComponents",value:function(){this.components.forEach(function(t){return t.render()})}},{key:"loadAnimatedComponents",value:function(){this.components.forEach(function(t){return t.loadAnimatedComponents()})}},{key:"refreshComponents",value:function(){var t=this;this.components.forEach(function(e){return e.refresh(t.state,t.rawChartArgs)})}},{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(){}},{key:"updateDataset",value:function(t,e){}},{key:"updateDatasets",value:function(t){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"updateDataPoint",value:function(t){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,ChartComponent=function(){function t(e){var i=e.layerClass,a=void 0===i?"":i,n=e.layerTransform,s=void 0===n?"":n,r=e.initData,o=e.setData,l=e.preMake,h=e.make,c=e.postMake,u=e.animate;classCallCheck(this,t),this.layerClass=a,this.layerTransform=s,this.initData=r,this.setData=o,this.preMake=l,this.make=h,this.postMake=c,this.animate=u,this.layer=void 0,this.store=[]}return createClass(t,[{key:"refresh",value:function(t,e){this.meta=Object.assign(this.meta||{},e),this.state=t}},{key:"render",value:function(){var t=this;this.data=this.setData(),this.preMake&&this.preMake(),this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)}),this.postMake&&this.postMake()}},{key:"setupParent",value:function(t){this.parent=t}},{key:"loadAnimatedComponents",value:function(){this.animate(this.store)}},{key:"makeLayer",value:function(){this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform)}}]),t}(),MIN_BAR_PERCENT_HEIGHT$1=.01,AxisChartController=function(){function t(e){classCallCheck(this,t),this.meta=e||{},this.setupArgs()}return createClass(t,[{key:"setupArgs",value:function(){this.consts={}}},{key:"setup",value:function(){}},{key:"refreshMeta",value:function(t){this.meta=Object.assign(this.meta||{},t)}},{key:"draw",value:function(){}},{key:"animate",value:function(){}}]),t}(),AxisController=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:"draw",value:function(t,e,i,a){return createSVG("circle",{style:"fill: "+i,"data-point-index":a,cx:t,cy:e,r:this.consts.radius})}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),BarChartController=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:"setupArgs",value:function(){this.consts={spaceRatio:.5,minHeight:this.meta.totalHeight*MIN_BAR_PERCENT_HEIGHT$1}}},{key:"refreshMeta",value:function(t){t&&get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refreshMeta",this).call(this,t);var i=this.meta;this.consts.barsWidth=i.unitWidth-i.unitWidth*this.consts.spaceRatio,this.consts.width=this.consts.barsWidth/(i.options&&i.options.stacked?i.options.stacked:i.noOfDatasets)}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=getBarHeightAndYAttr(e,this.meta.zeroLine),o=slicedToArray(r,2),l=o[0],h=o[1],c=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":n,x:t-this.consts.barsWidth/2,y:h-s,width:this.consts.width,height:l||this.consts.minHeight});return a||a.length?wrapInSVGGroup([c,createSVG("text",{className:"data-point-value",x:t,y:h-s,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):c}},{key:"animate",value:function(t,e,i,a,n){var s=e-this.meta.unitWidth/4,r=this.meta.unitWidth/2/n,o=getBarHeightAndYAttr(i,this.meta.zeroLine,this.meta.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),LineChartController=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:"setupArgs",value:function(){this.consts={radius:this.meta.dotSize||4}}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=createSVG("circle",{style:"fill: "+i,"data-point-index":arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,cx:t,cy:e,r:this.consts.radius});return a||a.length?wrapInSVGGroup([n,createSVG("text",{className:"data-point-value",x:t,y:e,dy:FONT_SIZE/2*-1-this.consts.radius+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):n}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.isSeries=t.isSeries,i.valuesOverPoints=t.valuesOverPoints,i.formatTooltipY=t.formatTooltipY,i.formatTooltipX=t.formatTooltipX,i.barOptions=t.barOptions,i.lineOptions=t.lineOptions,i.type=t.type||"line",i.setupUnitRenderer(),i.zeroLine=i.height,i.preSetup(),i.setup(),i}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:"preSetup",value:function(){}},{key:"setupUnitRenderer",value:function(){var t=this.rawChartArgs.options;this.unitRenderers={bar:new BarChartController(t),line:new LineChartController(t)}}},{key:"setHorizontalMargin",value:function(){this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"checkData",value:function(t){return!0}},{key:"getFirstUpdateData",value:function(t){}},{key:"setupConstants",value:function(){var t=this;this.state={xAxisLabels:[],xAxisPositions:[],xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode},this.data.datasets.map(function(e){e.chartType||(e.chartType=t.type)}),this.prepareYAxis()}},{key:"prepareData",value:function(t){var e=this.state;e.xAxisLabels=t.labels||[],e.datasetLength=e.xAxisLabels.length;var i=new Array(e.datasetLength).fill(0);e.datasets=t.datasets,t.datasets||(e.datasets=[{values:i}]),e.datasets.map(function(t,a){var n=t.values;n=n?(n=n.map(function(t){return isNaN(t)?0:t})).length>e.datasetLength?n.slice(0,e.datasetLength):fillArray(n,e.datasetLength-n.length,0):i,t.index=a}),e.noOfDatasets=e.datasets.length,e.yMarkers=t.yMarkers,e.yRegions=t.yRegions}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this.state;t.xAxisLabels=this.data.labels,this.calcXPositions(),t.datasetsLabels=this.data.datasets.map(function(t){return t.name}),this.setYAxis(),this.calcYUnits(),this.calcYMaximums(),this.calcYRegions(),this.configUnits()}},{key:"setYAxis",value:function(){this.calcYAxisParameters(this.state.yAxis,this.getAllYValues(),"line"===this.type),this.state.zeroLine=this.state.yAxis.zeroLine}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return floatTwo(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisParameters",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"false";t.labels=calcIntervals(e,i);var a=t.labels;t.scaleMultiplier=this.height/getValueRange(a);var n=getIntervalSize(a)*t.scaleMultiplier;t.zeroLine=this.height-getZeroIndex(a)*n,t.positions=a.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.datasets.map(function(e){e.positions=e.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})}),this.barOptions&&this.barOptions.stacked&&t.datasets.map(function(e,i){e.cumulativePositions=e.cumulativeYs.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"calcYMaximums",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativePositions);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.positions.map(function(e,i){e0)for(var h=0;h0)for(var l=0;l0)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 p=n.map(function(t,e){return a[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,p.join("L")))}})}},{key:"getYMarkerLines",value:function(){var t=this;return this.data.yMarkers?this.data.yMarkers.map(function(e,i){return new ChartComponent({layerClass:"y-markers",setData:function(){},make:function(){return t.state.yMarkers.map(function(e){return t.renderer.yMarker(e.value,e.name,{pos:"right",mode:"span",lineType:e.type})})},animate:function(){}})}):[]}},{key:"getYRegions",value:function(){var t=this;return this.data.yRegions?this.data.yRegions.map(function(e,i){return new ChartComponent({layerClass:"y-regions",setData:function(){},make:function(){return t.state.yRegions.map(function(e){return t.renderer.yRegion(e.start,e.end,e.name)})},animate:function(){}})}):[]}},{key:"getXRegions",value:function(){return[]}},{key:"refreshRenderer",value:function(){var t=this,e={totalHeight:this.height,totalWidth:this.width,xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth};this.renderer?this.renderer.refreshState(e):this.renderer=new AxisChartRenderer(e),this.refreshComponents();var i={totalHeight:this.height,totalWidth:this.width,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth,noOfDatasets:this.state.noOfDatasets};i=Object.assign(i,this.rawChartArgs.options),Object.keys(this.unitRenderers).map(function(e){i.options=t[e+"Options"],t.unitRenderers[e].refreshMeta(i)})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var i=getOffset(t.chartWrapper),a=e.pageX-i.left-t.translateXLeft;e.pageY-i.top-t.translateY=0;s--){var r=i.xAxisPositions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=i.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.xAxisLabels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxisLabels.length&&(t=this.xAxisLabels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,i){var a=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,i,a),this.data.labels.splice(a,0,t),this.data.datasets.map(function(t,e){t.values.splice(a,0,i[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 i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?possibleConstructorReturn(i):(i.setup(),i)}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 i=possibleConstructorReturn(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 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:"setHorizontalMargin",value:function(){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 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){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,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:e.index*Y_AXIS_MARGIN,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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var a=getOffset(t.chartWrapper),n=getOffset(e),s=n.left-a.left+e.offsetWidth/2,r=n.top-a.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[i]:t.labels[i])+": ",l=(100*t.slice_totals[i]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"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(i,a){i&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var a=0;return t.data.datasets.map(function(t){a+=t.values[i]}),[a,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,a=this.centerY,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"renderComponents",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,c=o/i.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,a),f=e.getPositionByAngle(p,a),v=t&&s[l],y=void 0,g=void 0;t?(y=v?v.startPosition:d,g=v?v.endPosition:d):(y=d,g=f);var m=i.makeArcPath(y,g),_=makePath(m,"pie-path","none",i.colors[l]);_.style.transition="transform .3s;",i.drawArea.appendChild(_),i.slices.push(_),i.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:u}),t&&i.elements_to_animate.push([{unit:_,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(d,f)},650,"easein",null,{d:m}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,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 y=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));y.type="heatmap",y.domain=s,y.subdomain=o,y.data=h,y.discrete_domains=u,y.count_label=d;var g=new Date;return y.start=a||addDays(g,365),v=v.slice(0,5),y.legend_colors=y.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],y.distribution_size=5,y.translateX=0,y}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:"setupConstants",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(this.first_week_start+"",this.last_week_start+"")+1}},{key:"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 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=makeText("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}(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 i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function 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),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var i=void 0,a=void 0;return t<=e?(a=t,0===(i=e-t)&&(a-=i=totalHeight*MIN_BAR_PERCENT_HEIGHT)):(i=t-e,a=e),[i,a]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function translate(t,e,i,a){return[t,{transform:i.join(", ")},a,STD_EASING,"translate",{transform:e.join(", ")}]}function translateHoriLine(t,e,i){return translate(t,[0,i],[0,e],MARKER_LINE_ANIM_DUR)}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function 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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>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]}),createSVG("rect",s)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:a})}function makeVertLine(t,e,i,a){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:i,y2:a,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:i>a?i+LABEL_MARGIN:i-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,i,a){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:i,x2:a,y1:0,y2:0,styles:{stroke:n.stroke}}),r=createSVG("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=BASE_LINE_COLOR),a.className||(a.className="");var n=-1*AXIS_TICK_LENGTH,s="span"===a.mode?i+AXIS_TICK_LENGTH:0;return"tick"===a.mode&&"right"===a.pos&&(n=i+AXIS_TICK_LENGTH,s=i),n+=a.offset,s+=a.offset,makeHoriLine(t,e,n,s,{stroke:a.stroke,className:a.className,lineType:a.lineType})}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,i){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 a=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:a?i.colors:void 0})}}function animateSVGElement(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var 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:EASING[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 transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function animateSVG(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.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],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 runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function getYAxisComponent(t,e,i){return new ChartComponent$1({parent:t,layerClass:"y axis",constants:e,data:i,makeElements:function(t){var e=this;return t.positions.map(function(i,a){return yLine(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=equilizeNoOfElements(a,e),r=slicedToArray(s,2);a=r[0],e=r[1];var o=equilizeNoOfElements(n,i),l=slicedToArray(o,2);return n=l[0],i=l[1],this.render({positions:a,labels:i}),this.store.map(function(t,i){return translateHoriLine(t,e[i],a[i])})}})}function getPaths(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=t.map(function(t,i){return e[i]+","+t}).join("L"),r=makePath("M"+s,"line-graph-path",i);if(a){var o=makeGradient(this.svgDefs,i);r.style.stroke="url(#"+o+")"}var l=[r];if(n){var h=makeGradient(this.svgDefs,i,!0),c=this.state.yAxis.zeroLine,u="M0,"+c+"L"+s+"L"+this.width+","+c;l.push(makePath(u,"region-fill","none","url(#"+h+")"))}return l}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getChartRangeIntervals(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 getChartIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=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 i=getChartIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getChartIntervals(a,n):getChartIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?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 getRealIntervals(t,e){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=1*(t-i)/e,s=[],r=0;r<=e;r++)s.push(i+n*r);return a?s:s.reverse()}function getIntervalSize(t){return t[1]-t[0]}function getValueRange(t){return t[t.length-1]-t[0]}function calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"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 i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
      \n\t\t\t\t
      '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.data_point_list.appendChild(n)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var a="calc(50% + "+(this.left-e)+"px)";i.style.left=a,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),t}(),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:"xLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};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 a=this.totalHeight+AXIS_TICK_LENGTH,n="span"===i.mode?-1*AXIS_TICK_LENGTH:this.totalHeight;return"tick"===i.mode&&"top"===i.pos&&(a=-1*AXIS_TICK_LENGTH,n=0),makeVertLine(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(e,5)-LABEL_MARGIN,y:t-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),n=makeHoriLine(t,"",0,this.totalWidth,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return n.appendChild(a),n}},{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:"yRegion",value:function(t,e,i){var a=createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:e,width:this.totalWidth,height:t-e}),n=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:e,y2:e,styles:{stroke:BASE_LINE_COLOR}}),s=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:t,y2:t,styles:{stroke:BASE_LINE_COLOR}}),r=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(i,4.5)-LABEL_MARGIN,y:e-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{});return o.appendChild(a),o.appendChild(n),o.appendChild(s),o.appendChild(r),o}},{key:"animatebar",value:function(t,e,i,a,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(i,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var i=[],a=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];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},PATH_ANIM_DUR,STD_EASING];i.push(r)}return i}}]),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 i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type,e.parent);classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof c?document.querySelector(c):c,this.title=s,this.subtitle=o,this.argHeight=a,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:0},this.state={colors:this.colors}}},{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.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),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.prepareData(t),this.calc(),this.refreshRenderer(),this.render()}},{key:"prepareData",value:function(){}},{key:"renderConstants",value:function(){}},{key:"calc",value:function(){}},{key:"refreshRenderer",value:function(){this.renderer={}}},{key:"render",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refreshComponents(),this.elementsToAnimate=[].concat.apply([],this.components.map(function(e){return e.update(t)})),console.log(this.elementsToAnimate),this.elementsToAnimate&&runSMILAnimation(this.chartWrapper,this.svg,this.elementsToAnimate)}},{key:"refreshComponents",value:function(){}},{key:"makeChartArea",value:function(){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(){}},{key:"updateDataset",value:function(t,e){}},{key:"updateDatasets",value:function(t){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"updateDataPoint",value:function(t){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,ChartComponent$1=function(){function t(e){var i=e.layerClass,a=void 0===i?"":i,n=e.layerTransform,s=void 0===n?"":n,r=e.parent,o=e.constants,l=e.data,h=e.preMake,c=e.makeElements,u=e.postMake,p=e.animateElements;classCallCheck(this,t),this.parent=r,this.layerClass=a,this.layerTransform=s,this.constants=o,this.preMake=h,this.makeElements=c,this.postMake=u,this.animateElements=p,this.store=[],this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform),this.data=l,this.make()}return createClass(t,[{key:"refresh",value:function(t){this.data=t}},{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=[];return(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(e=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),e}}]),t}(),MIN_BAR_PERCENT_HEIGHT$1=.01,AxisChartController=function(){function t(e){classCallCheck(this,t),this.meta=e||{},this.setupArgs()}return createClass(t,[{key:"setupArgs",value:function(){this.consts={}}},{key:"setup",value:function(){}},{key:"refreshMeta",value:function(t){this.meta=Object.assign(this.meta||{},t)}},{key:"draw",value:function(){}},{key:"animate",value:function(){}}]),t}(),AxisController=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:"draw",value:function(t,e,i,a){return createSVG("circle",{style:"fill: "+i,"data-point-index":a,cx:t,cy:e,r:this.consts.radius})}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),BarChartController=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:"setupArgs",value:function(){this.consts={spaceRatio:.5,minHeight:this.meta.totalHeight*MIN_BAR_PERCENT_HEIGHT$1}}},{key:"refreshMeta",value:function(t){t&&get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refreshMeta",this).call(this,t);var i=this.meta;this.consts.barsWidth=i.unitWidth-i.unitWidth*this.consts.spaceRatio,this.consts.width=this.consts.barsWidth/(i.options&&i.options.stacked?i.options.stacked:i.noOfDatasets)}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=getBarHeightAndYAttr(e,this.meta.zeroLine),o=slicedToArray(r,2),l=o[0],h=o[1],c=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":n,x:t-this.consts.barsWidth/2,y:h-s,width:this.consts.width,height:l||this.consts.minHeight});return a||a.length?wrapInSVGGroup([c,createSVG("text",{className:"data-point-value",x:t,y:h-s,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):c}},{key:"animate",value:function(t,e,i,a,n){var s=e-this.meta.unitWidth/4,r=this.meta.unitWidth/2/n,o=getBarHeightAndYAttr(i,this.meta.zeroLine,this.meta.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),LineChartController=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:"setupArgs",value:function(){this.consts={radius:this.meta.dotSize||4}}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=createSVG("circle",{style:"fill: "+i,"data-point-index":arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,cx:t,cy:e,r:this.consts.radius});return a||a.length?wrapInSVGGroup([n,createSVG("text",{className:"data-point-value",x:t,y:e,dy:FONT_SIZE/2*-1-this.consts.radius+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):n}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.isSeries=t.isSeries,i.valuesOverPoints=t.valuesOverPoints,i.formatTooltipY=t.formatTooltipY,i.formatTooltipX=t.formatTooltipX,i.barOptions=t.barOptions,i.lineOptions=t.lineOptions,i.type=t.type||"line",i.xAxisMode=t.xAxisMode||"span",i.yAxisMode=t.yAxisMode||"span",i.setupUnitRenderer(),i.zeroLine=i.height,i.preSetup(),i.setup(),i}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:"preSetup",value:function(){}},{key:"setupUnitRenderer",value:function(){var t=this.rawChartArgs.options;this.unitRenderers={bar:new BarChartController(t),line:new LineChartController(t)}}},{key:"setHorizontalMargin",value:function(){this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"checkData",value:function(t){return!0}},{key:"getFirstUpdateData",value:function(t){}},{key:"setupConstants",value:function(){var t=this;this.state={xAxisLabels:[],xAxisPositions:[],xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode},this.data.datasets.map(function(e){e.chartType||(e.chartType=t.type)}),this.prepareYAxis()}},{key:"prepareData",value:function(t){var e=this.state;e.xAxisLabels=t.labels||[],e.datasetLength=e.xAxisLabels.length;var i=new Array(e.datasetLength).fill(0);e.datasets=t.datasets,t.datasets||(e.datasets=[{values:i}]),e.datasets.map(function(t,a){var n=t.values;n=n?(n=n.map(function(t){return isNaN(t)?0:t})).length>e.datasetLength?n.slice(0,e.datasetLength):fillArray(n,e.datasetLength-n.length,0):i,t.index=a}),e.noOfDatasets=e.datasets.length,e.yMarkers=t.yMarkers,e.yRegions=t.yRegions}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"calc",value:function(){var t=this.state;t.xAxisLabels=this.data.labels,this.calcXPositions(),t.datasetsLabels=this.data.datasets.map(function(t){return t.name}),this.setYAxis(),this.calcYUnits(),this.calcYMaximums(),this.calcYRegions(),this.configUnits()}},{key:"setYAxis",value:function(){this.calcYAxisParameters(this.state.yAxis,this.getAllYValues(),"line"===this.type),this.state.zeroLine=this.state.yAxis.zeroLine}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return floatTwo(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisParameters",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"false";t.labels=calcChartIntervals(e,i);var a=t.labels;t.scaleMultiplier=this.height/getValueRange(a);var n=getIntervalSize(a)*t.scaleMultiplier;t.zeroLine=this.height-getZeroIndex(a)*n,t.positions=a.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.datasets.map(function(e){e.positions=e.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})}),this.barOptions&&this.barOptions.stacked&&t.datasets.map(function(e,i){e.cumulativePositions=e.cumulativeYs.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"calcYMaximums",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativePositions);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.positions.map(function(e,i){e0)for(var l=0;l0)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 p=n.map(function(t,e){return a[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,p.join("L")))}})}},{key:"getYMarkerLines",value:function(){var t=this;return this.data.yMarkers?this.data.yMarkers.map(function(e,i){return new ChartComponent({layerClass:"y-markers",setData:function(){},makeElements:function(){return t.state.yMarkers.map(function(e){return t.renderer.yMarker(e.value,e.name,{pos:"right",mode:"span",lineType:e.type})})},animate:function(){}})}):[]}},{key:"getYRegions",value:function(){var t=this;return this.data.yRegions?this.data.yRegions.map(function(e,i){return new ChartComponent({layerClass:"y-regions",setData:function(){},makeElements:function(){return t.state.yRegions.map(function(e){return t.renderer.yRegion(e.start,e.end,e.name)})},animate:function(){}})}):[]}},{key:"refreshRenderer",value:function(){var t=this,e={totalHeight:this.height,totalWidth:this.width,xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth};this.renderer?this.renderer.refreshState(e):this.renderer=new AxisChartRenderer(e);var i={totalHeight:this.height,totalWidth:this.width,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth,noOfDatasets:this.state.noOfDatasets};i=Object.assign(i,this.rawChartArgs.options),Object.keys(this.unitRenderers).map(function(e){i.options=t[e+"Options"],t.unitRenderers[e].refreshMeta(i)})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var i=getOffset(t.chartWrapper),a=e.pageX-i.left-t.translateXLeft;e.pageY-i.top-t.translateY=0;s--){var r=i.xAxisPositions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=i.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.xAxisLabels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxisLabels.length&&(t=this.xAxisLabels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,i){var a=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,i,a),this.data.labels.splice(a,0,t),this.data.datasets.map(function(t,e){t.values.splice(a,0,i[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 i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?possibleConstructorReturn(i):(i.setup(),i)}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 i=possibleConstructorReturn(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 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:"setHorizontalMargin",value:function(){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 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){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,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:e.index*Y_AXIS_MARGIN,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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"calc",value:function(){}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var a=0;return t.data.datasets.map(function(t){a+=t.values[i]}),[a,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,a=this.centerY,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"renderComponents",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,c=o/i.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,a),f=e.getPositionByAngle(p,a),v=t&&s[l],y=void 0,g=void 0;t?(y=v?v.startPosition:d,g=v?v.endPosition:d):(y=d,g=f);var m=i.makeArcPath(y,g),_=makePath(m,"pie-path","none",i.colors[l]);_.style.transition="transform .3s;",i.drawArea.appendChild(_),i.slices.push(_),i.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:u}),t&&i.elements_to_animate.push([{unit:_,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(d,f)},650,"easein",null,{d:m}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,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 y=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));y.type="heatmap",y.domain=s,y.subdomain=o,y.data=h,y.discrete_domains=u,y.count_label=d;var g=new Date;return y.start=a||addDays(g,365),v=v.slice(0,5),y.legend_colors=y.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],y.distribution_size=5,y.translateX=0,y}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:"setupConstants",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(this.first_week_start+"",this.last_week_start+"")+1}},{key:"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 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=makeText("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}(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 2e35601..2ee2b45 100644 --- a/dist/frappe-charts.min.esm.js +++ b/dist/frappe-charts.min.esm.js @@ -1 +1 @@ -function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function 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),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var i=void 0,a=void 0;return t<=e?(a=t,0===(i=e-t)&&(a-=i=totalHeight*MIN_BAR_PERCENT_HEIGHT)):(i=t-e,a=e),[i,a]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function 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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>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]}),createSVG("rect",s)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:a})}function makeVertLine(t,e,i,a){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:i,y2:a,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:i>a?i+LABEL_MARGIN:i-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,i,a){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:i,x2:a,y1:t,y2:t,styles:{stroke:n.stroke}}),r=createSVG("text",{x:i255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,i){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 a=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:a?i.colors:void 0})}}function animateSVGElement(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var 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:EASING[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 transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function animateSVG(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.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],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 runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function getPaths(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=t.map(function(t,i){return e[i]+","+t}).join("L"),r=makePath("M"+s,"line-graph-path",i);if(a){var o=makeGradient(this.svgDefs,i);r.style.stroke="url(#"+o+")"}var l=[r];if(n){var h=makeGradient(this.svgDefs,i,!0),c=this.state.yAxis.zeroLine,u="M0,"+c+"L"+s+"L"+this.width+","+c;l.push(makePath(u,"region-fill","none","url(#"+h+")"))}return l}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function 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 calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"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 i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
        \n\t\t\t\t
        '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.data_point_list.appendChild(n)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var a="calc(50% + "+(this.left-e)+"px)";i.style.left=a,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),t}(),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:"xLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode=this.xAxisMode),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var a=this.totalHeight+AXIS_TICK_LENGTH,n="span"===i.mode?-1*AXIS_TICK_LENGTH:this.totalHeight;return"tick"===i.mode&&"top"===i.pos&&(a=-1*AXIS_TICK_LENGTH,n=0),makeVertLine(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode=this.yAxisMode),i.stroke||(i.stroke=BASE_LINE_COLOR),i.className||(i.className="");var a=-1*AXIS_TICK_LENGTH,n="span"===i.mode?this.totalWidth+AXIS_TICK_LENGTH:0;return"tick"===i.mode&&"right"===i.pos&&(a=this.totalWidth+AXIS_TICK_LENGTH,n=this.totalWidth),a+=i.offset,n+=i.offset,makeHoriLine(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(e,5)-LABEL_MARGIN,y:t-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),n=makeHoriLine(t,"",0,this.totalWidth,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return n.appendChild(a),n}},{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:"yRegion",value:function(t,e,i){var a=createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:e,width:this.totalWidth,height:t-e}),n=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:e,y2:e,styles:{stroke:BASE_LINE_COLOR}}),s=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:t,y2:t,styles:{stroke:BASE_LINE_COLOR}}),r=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(i,4.5)-LABEL_MARGIN,y:e-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{});return o.appendChild(a),o.appendChild(n),o.appendChild(s),o.appendChild(r),o}},{key:"animatebar",value:function(t,e,i,a,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(i,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var i=[],a=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];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},PATH_ANIM_DUR,STD_EASING];i.push(r)}return i}},{key:"translate",value:function(t,e,i,a){return[t,{transform:i.join(", ")},a,STD_EASING,"translate",{transform:e.join(", ")}]}},{key:"translateVertLine",value:function(t,e,i){return this.translate(t,[i,0],[e,0],MARKER_LINE_ANIM_DUR)}},{key:"translateHoriLine",value:function(t,e,i){return this.translate(t,[0,i],[0,e],MARKER_LINE_ANIM_DUR)}}]),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 i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type,e.parent);classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof c?document.querySelector(c):c,this.title=s,this.subtitle=o,this.argHeight=a,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:0},this.state={colors:this.colors}}},{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=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.refresh(this.data),this.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.renderConstants(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(t){this.refresh(t),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(t){this.oldState=this.state?JSON.parse(JSON.stringify(this.state)):{},this.intermedState={},this.prepareData(t),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){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:"prepareData",value:function(){}},{key:"renderConstants",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){this.renderer={}}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.elementsToAnimate=[],this.loadAnimatedComponents(),runSMILAnimation(this.chartWrapper,this.svg,this.elementsToAnimate),setTimeout(function(){t.renderComponents()},400)}},{key:"setComponentParent",value:function(){var t=this;this.components.forEach(function(e){return e.setupParent(t.drawArea)})}},{key:"makeComponentLayers",value:function(){this.components.forEach(function(t){return t.makeLayer()})}},{key:"renderComponents",value:function(){this.components.forEach(function(t){return t.render()})}},{key:"loadAnimatedComponents",value:function(){this.components.forEach(function(t){return t.loadAnimatedComponents()})}},{key:"refreshComponents",value:function(){var t=this;this.components.forEach(function(e){return e.refresh(t.state,t.rawChartArgs)})}},{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(){}},{key:"updateDataset",value:function(t,e){}},{key:"updateDatasets",value:function(t){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"updateDataPoint",value:function(t){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,ChartComponent=function(){function t(e){var i=e.layerClass,a=void 0===i?"":i,n=e.layerTransform,s=void 0===n?"":n,r=e.initData,o=e.setData,l=e.preMake,h=e.make,c=e.postMake,u=e.animate;classCallCheck(this,t),this.layerClass=a,this.layerTransform=s,this.initData=r,this.setData=o,this.preMake=l,this.make=h,this.postMake=c,this.animate=u,this.layer=void 0,this.store=[]}return createClass(t,[{key:"refresh",value:function(t,e){this.meta=Object.assign(this.meta||{},e),this.state=t}},{key:"render",value:function(){var t=this;this.data=this.setData(),this.preMake&&this.preMake(),this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)}),this.postMake&&this.postMake()}},{key:"setupParent",value:function(t){this.parent=t}},{key:"loadAnimatedComponents",value:function(){this.animate(this.store)}},{key:"makeLayer",value:function(){this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform)}}]),t}(),MIN_BAR_PERCENT_HEIGHT$1=.01,AxisChartController=function(){function t(e){classCallCheck(this,t),this.meta=e||{},this.setupArgs()}return createClass(t,[{key:"setupArgs",value:function(){this.consts={}}},{key:"setup",value:function(){}},{key:"refreshMeta",value:function(t){this.meta=Object.assign(this.meta||{},t)}},{key:"draw",value:function(){}},{key:"animate",value:function(){}}]),t}(),AxisController=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:"draw",value:function(t,e,i,a){return createSVG("circle",{style:"fill: "+i,"data-point-index":a,cx:t,cy:e,r:this.consts.radius})}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),BarChartController=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:"setupArgs",value:function(){this.consts={spaceRatio:.5,minHeight:this.meta.totalHeight*MIN_BAR_PERCENT_HEIGHT$1}}},{key:"refreshMeta",value:function(t){t&&get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refreshMeta",this).call(this,t);var i=this.meta;this.consts.barsWidth=i.unitWidth-i.unitWidth*this.consts.spaceRatio,this.consts.width=this.consts.barsWidth/(i.options&&i.options.stacked?i.options.stacked:i.noOfDatasets)}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=getBarHeightAndYAttr(e,this.meta.zeroLine),o=slicedToArray(r,2),l=o[0],h=o[1],c=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":n,x:t-this.consts.barsWidth/2,y:h-s,width:this.consts.width,height:l||this.consts.minHeight});return a||a.length?wrapInSVGGroup([c,createSVG("text",{className:"data-point-value",x:t,y:h-s,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):c}},{key:"animate",value:function(t,e,i,a,n){var s=e-this.meta.unitWidth/4,r=this.meta.unitWidth/2/n,o=getBarHeightAndYAttr(i,this.meta.zeroLine,this.meta.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),LineChartController=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:"setupArgs",value:function(){this.consts={radius:this.meta.dotSize||4}}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=createSVG("circle",{style:"fill: "+i,"data-point-index":arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,cx:t,cy:e,r:this.consts.radius});return a||a.length?wrapInSVGGroup([n,createSVG("text",{className:"data-point-value",x:t,y:e,dy:FONT_SIZE/2*-1-this.consts.radius+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):n}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.isSeries=t.isSeries,i.valuesOverPoints=t.valuesOverPoints,i.formatTooltipY=t.formatTooltipY,i.formatTooltipX=t.formatTooltipX,i.barOptions=t.barOptions,i.lineOptions=t.lineOptions,i.type=t.type||"line",i.setupUnitRenderer(),i.zeroLine=i.height,i.preSetup(),i.setup(),i}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:"preSetup",value:function(){}},{key:"setupUnitRenderer",value:function(){var t=this.rawChartArgs.options;this.unitRenderers={bar:new BarChartController(t),line:new LineChartController(t)}}},{key:"setHorizontalMargin",value:function(){this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"checkData",value:function(t){return!0}},{key:"getFirstUpdateData",value:function(t){}},{key:"setupConstants",value:function(){var t=this;this.state={xAxisLabels:[],xAxisPositions:[],xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode},this.data.datasets.map(function(e){e.chartType||(e.chartType=t.type)}),this.prepareYAxis()}},{key:"prepareData",value:function(t){var e=this.state;e.xAxisLabels=t.labels||[],e.datasetLength=e.xAxisLabels.length;var i=new Array(e.datasetLength).fill(0);e.datasets=t.datasets,t.datasets||(e.datasets=[{values:i}]),e.datasets.map(function(t,a){var n=t.values;n=n?(n=n.map(function(t){return isNaN(t)?0:t})).length>e.datasetLength?n.slice(0,e.datasetLength):fillArray(n,e.datasetLength-n.length,0):i,t.index=a}),e.noOfDatasets=e.datasets.length,e.yMarkers=t.yMarkers,e.yRegions=t.yRegions}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this.state;t.xAxisLabels=this.data.labels,this.calcXPositions(),t.datasetsLabels=this.data.datasets.map(function(t){return t.name}),this.setYAxis(),this.calcYUnits(),this.calcYMaximums(),this.calcYRegions(),this.configUnits()}},{key:"setYAxis",value:function(){this.calcYAxisParameters(this.state.yAxis,this.getAllYValues(),"line"===this.type),this.state.zeroLine=this.state.yAxis.zeroLine}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return floatTwo(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisParameters",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"false";t.labels=calcIntervals(e,i);var a=t.labels;t.scaleMultiplier=this.height/getValueRange(a);var n=getIntervalSize(a)*t.scaleMultiplier;t.zeroLine=this.height-getZeroIndex(a)*n,t.positions=a.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.datasets.map(function(e){e.positions=e.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})}),this.barOptions&&this.barOptions.stacked&&t.datasets.map(function(e,i){e.cumulativePositions=e.cumulativeYs.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"calcYMaximums",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativePositions);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.positions.map(function(e,i){e0)for(var h=0;h0)for(var l=0;l0)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 p=n.map(function(t,e){return a[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,p.join("L")))}})}},{key:"getYMarkerLines",value:function(){var t=this;return this.data.yMarkers?this.data.yMarkers.map(function(e,i){return new ChartComponent({layerClass:"y-markers",setData:function(){},make:function(){return t.state.yMarkers.map(function(e){return t.renderer.yMarker(e.value,e.name,{pos:"right",mode:"span",lineType:e.type})})},animate:function(){}})}):[]}},{key:"getYRegions",value:function(){var t=this;return this.data.yRegions?this.data.yRegions.map(function(e,i){return new ChartComponent({layerClass:"y-regions",setData:function(){},make:function(){return t.state.yRegions.map(function(e){return t.renderer.yRegion(e.start,e.end,e.name)})},animate:function(){}})}):[]}},{key:"getXRegions",value:function(){return[]}},{key:"refreshRenderer",value:function(){var t=this,e={totalHeight:this.height,totalWidth:this.width,xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth};this.renderer?this.renderer.refreshState(e):this.renderer=new AxisChartRenderer(e),this.refreshComponents();var i={totalHeight:this.height,totalWidth:this.width,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth,noOfDatasets:this.state.noOfDatasets};i=Object.assign(i,this.rawChartArgs.options),Object.keys(this.unitRenderers).map(function(e){i.options=t[e+"Options"],t.unitRenderers[e].refreshMeta(i)})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var i=getOffset(t.chartWrapper),a=e.pageX-i.left-t.translateXLeft;e.pageY-i.top-t.translateY=0;s--){var r=i.xAxisPositions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=i.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.xAxisLabels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxisLabels.length&&(t=this.xAxisLabels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,i){var a=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,i,a),this.data.labels.splice(a,0,t),this.data.datasets.map(function(t,e){t.values.splice(a,0,i[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 i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?possibleConstructorReturn(i):(i.setup(),i)}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 i=possibleConstructorReturn(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 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:"setHorizontalMargin",value:function(){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 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){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,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:e.index*Y_AXIS_MARGIN,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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var a=getOffset(t.chartWrapper),n=getOffset(e),s=n.left-a.left+e.offsetWidth/2,r=n.top-a.top-6,o=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[i]:t.labels[i])+": ",l=(100*t.slice_totals[i]/t.grand_total).toFixed(1);t.tip.set_values(s,r,o,l+"%"),t.tip.show_tip()})})}},{key:"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(i,a){i&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var a=0;return t.data.datasets.map(function(t){a+=t.values[i]}),[a,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,a=this.centerY,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"renderComponents",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,c=o/i.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,a),f=e.getPositionByAngle(p,a),v=t&&s[l],y=void 0,g=void 0;t?(y=v?v.startPosition:d,g=v?v.endPosition:d):(y=d,g=f);var m=i.makeArcPath(y,g),_=makePath(m,"pie-path","none",i.colors[l]);_.style.transition="transform .3s;",i.drawArea.appendChild(_),i.slices.push(_),i.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:u}),t&&i.elements_to_animate.push([{unit:_,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(d,f)},650,"easein",null,{d:m}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,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 y=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));y.type="heatmap",y.domain=s,y.subdomain=o,y.data=h,y.discrete_domains=u,y.count_label=d;var g=new Date;return y.start=a||addDays(g,365),v=v.slice(0,5),y.legend_colors=y.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],y.distribution_size=5,y.translateX=0,y}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:"setupConstants",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(this.first_week_start+"",this.last_week_start+"")+1}},{key:"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 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=makeText("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}(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 i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $$1(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function 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),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function floatTwo(t){return parseFloat(t.toFixed(2))}function fillArray(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=a?t[0]:t[t.length-1]);var n=new Array(Math.abs(e)).fill(i);return t=a?n.concat(t):t.concat(n)}function getStringWidth(t,e){return(t+"").length*e}function getBarHeightAndYAttr(t,e){var i=void 0,a=void 0;return t<=e?(a=t,0===(i=e-t)&&(a-=i=totalHeight*MIN_BAR_PERCENT_HEIGHT)):(i=t-e,a=e),[i,a]}function equilizeNoOfElements(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length-t.length;return i>0?t=fillArray(t,i):e=fillArray(e,i),[t,e]}function translate(t,e,i,a){return[t,{transform:i.join(", ")},a,STD_EASING,"translate",{transform:e.join(", ")}]}function translateHoriLine(t,e,i){return translate(t,[0,i],[0,e],MARKER_LINE_ANIM_DUR)}function $$2(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function createSVG(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var a in e){var n=e[a];if("inside"===a)$$2(n).appendChild(i);else if("around"===a){var s=$$2(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function 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 makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>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]}),createSVG("rect",s)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:a})}function makeVertLine(t,e,i,a){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:i,y2:a,styles:{stroke:n.stroke}}),r=createSVG("text",{x:0,y:i>a?i+LABEL_MARGIN:i-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,i,a){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:i,x2:a,y1:0,y2:0,styles:{stroke:n.stroke}}),r=createSVG("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=BASE_LINE_COLOR),a.className||(a.className="");var n=-1*AXIS_TICK_LENGTH,s="span"===a.mode?i+AXIS_TICK_LENGTH:0;return"tick"===a.mode&&"right"===a.pos&&(n=i+AXIS_TICK_LENGTH,s=i),n+=a.offset,s+=a.offset,makeHoriLine(t,e,n,s,{stroke:a.stroke,className:a.className,lineType:a.lineType})}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),a=!1;"#"==i[0]&&(i=i.slice(1),a=!0);var n=parseInt(i,16),s=limitColor((n>>16)+e),r=limitColor((n>>8&255)+e),o=limitColor((255&n)+e);return(a?"#":"")+(o|r<<8|s<<16).toString(16)}function isValidColor(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function getDifferentChart(t,e,i){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 a=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:a?i.colors:void 0})}}function animateSVGElement(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var 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:EASING[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 transform(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function animateSVG(t,e){var i=[],a=[];e.map(function(t){var e=t[0],n=e.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],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 runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function getYAxisComponent(t,e,i){return new ChartComponent$1({parent:t,layerClass:"y axis",constants:e,data:i,makeElements:function(t){var e=this;return t.positions.map(function(i,a){return yLine(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=equilizeNoOfElements(a,e),r=slicedToArray(s,2);a=r[0],e=r[1];var o=equilizeNoOfElements(n,i),l=slicedToArray(o,2);return n=l[0],i=l[1],this.render({positions:a,labels:i}),this.store.map(function(t,i){return translateHoriLine(t,e[i],a[i])})}})}function getPaths(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=t.map(function(t,i){return e[i]+","+t}).join("L"),r=makePath("M"+s,"line-graph-path",i);if(a){var o=makeGradient(this.svgDefs,i);r.style.stroke="url(#"+o+")"}var l=[r];if(n){var h=makeGradient(this.svgDefs,i,!0),c=this.state.yAxis.zeroLine,u="M0,"+c+"L"+s+"L"+this.width+","+c;l.push(makePath(u,"region-fill","none","url(#"+h+")"))}return l}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getChartRangeIntervals(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 getChartIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=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 i=getChartIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getChartIntervals(a,n):getChartIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?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 getRealIntervals(t,e){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=1*(t-i)/e,s=[],r=0;r<=e;r++)s.push(i+n*r);return a?s:s.reverse()}function getIntervalSize(t){return t[1]-t[0]}function getValueRange(t){return t[t.length-1]-t[0]}function calcDistribution(t,e){for(var i=Math.max.apply(Math,toConsumableArray(t)),a=1/(e-1),n=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"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 i(t,e){return new Promise(function(i,n){var o={key:t,arg:e,resolve:i,reject:n,next:null};r?r=r.next=o:(s=r=o,a(t,e))})}function a(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){a("next",t)},function(t){a("throw",t)}):n(r.done?"return":"normal",r.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?a(s.key,s.arg):r=null}var s,r;this._invoke=i,"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
          \n\t\t\t\t
          '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){t.hide_tip()})}},{key:"fill",value:function(){var t=this,e=void 0;e=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=e,this.data_point_list.innerHTML="",this.list_values.map(function(e,i){var a=t.colors[i]||"black",n=$$1.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.data_point_list.appendChild(n)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var a="calc(50% + "+(this.left-e)+"px)";i.style.left=a,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=a,this.list_values=n,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),t}(),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:"xLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};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 a=this.totalHeight+AXIS_TICK_LENGTH,n="span"===i.mode?-1*AXIS_TICK_LENGTH:this.totalHeight;return"tick"===i.mode&&"top"===i.pos&&(a=-1*AXIS_TICK_LENGTH,n=0),makeVertLine(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(e,5)-LABEL_MARGIN,y:t-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:e+""}),n=makeHoriLine(t,"",0,this.totalWidth,{stroke:i.stroke||BASE_LINE_COLOR,className:i.className||"",lineType:i.lineType});return n.appendChild(a),n}},{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:"yRegion",value:function(t,e,i){var a=createSVG("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:e,width:this.totalWidth,height:t-e}),n=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:e,y2:e,styles:{stroke:BASE_LINE_COLOR}}),s=createSVG("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:t,y2:t,styles:{stroke:BASE_LINE_COLOR}}),r=createSVG("text",{className:"chart-label",x:this.totalWidth-getStringWidth(i,4.5)-LABEL_MARGIN,y:e-FONT_SIZE-2,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px","text-anchor":"start",innerHTML:i+""}),o=createSVG("g",{});return o.appendChild(a),o.appendChild(n),o.appendChild(s),o.appendChild(r),o}},{key:"animatebar",value:function(t,e,i,a,n){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/n,o=getBarHeightAndYAttr(i,this.zeroLine,this.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}},{key:"animatepath",value:function(t,e){var i=[],a=[t[0],{d:"M"+e},PATH_ANIM_DUR,STD_EASING];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},PATH_ANIM_DUR,STD_EASING];i.push(r)}return i}}]),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 i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,e.isNavigable),h=void 0===l?0:l,c=(e.showLegend,e.type,e.parent);classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof c?document.querySelector(c):c,this.title=s,this.subtitle=o,this.argHeight=a,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:0},this.state={colors:this.colors}}},{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.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),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.prepareData(t),this.calc(),this.refreshRenderer(),this.render()}},{key:"prepareData",value:function(){}},{key:"renderConstants",value:function(){}},{key:"calc",value:function(){}},{key:"refreshRenderer",value:function(){this.renderer={}}},{key:"render",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refreshComponents(),this.elementsToAnimate=[].concat.apply([],this.components.map(function(e){return e.update(t)})),console.log(this.elementsToAnimate),this.elementsToAnimate&&runSMILAnimation(this.chartWrapper,this.svg,this.elementsToAnimate)}},{key:"refreshComponents",value:function(){}},{key:"makeChartArea",value:function(){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(){}},{key:"updateDataset",value:function(t,e){}},{key:"updateDatasets",value:function(t){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"updateDataPoint",value:function(t){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),Y_AXIS_MARGIN=60,ChartComponent$1=function(){function t(e){var i=e.layerClass,a=void 0===i?"":i,n=e.layerTransform,s=void 0===n?"":n,r=e.parent,o=e.constants,l=e.data,h=e.preMake,c=e.makeElements,u=e.postMake,p=e.animateElements;classCallCheck(this,t),this.parent=r,this.layerClass=a,this.layerTransform=s,this.constants=o,this.preMake=h,this.makeElements=c,this.postMake=u,this.animateElements=p,this.store=[],this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform),this.data=l,this.make()}return createClass(t,[{key:"refresh",value:function(t){this.data=t}},{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=[];return(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(e=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),e}}]),t}(),MIN_BAR_PERCENT_HEIGHT$1=.01,AxisChartController=function(){function t(e){classCallCheck(this,t),this.meta=e||{},this.setupArgs()}return createClass(t,[{key:"setupArgs",value:function(){this.consts={}}},{key:"setup",value:function(){}},{key:"refreshMeta",value:function(t){this.meta=Object.assign(this.meta||{},t)}},{key:"draw",value:function(){}},{key:"animate",value:function(){}}]),t}(),AxisController=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:"draw",value:function(t,e,i,a){return createSVG("circle",{style:"fill: "+i,"data-point-index":a,cx:t,cy:e,r:this.consts.radius})}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),BarChartController=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:"setupArgs",value:function(){this.consts={spaceRatio:.5,minHeight:this.meta.totalHeight*MIN_BAR_PERCENT_HEIGHT$1}}},{key:"refreshMeta",value:function(t){t&&get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refreshMeta",this).call(this,t);var i=this.meta;this.consts.barsWidth=i.unitWidth-i.unitWidth*this.consts.spaceRatio,this.consts.width=this.consts.barsWidth/(i.options&&i.options.stacked?i.options.stacked:i.noOfDatasets)}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=getBarHeightAndYAttr(e,this.meta.zeroLine),o=slicedToArray(r,2),l=o[0],h=o[1],c=createSVG("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":n,x:t-this.consts.barsWidth/2,y:h-s,width:this.consts.width,height:l||this.consts.minHeight});return a||a.length?wrapInSVGGroup([c,createSVG("text",{className:"data-point-value",x:t,y:h-s,dy:FONT_SIZE/2*-1+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):c}},{key:"animate",value:function(t,e,i,a,n){var s=e-this.meta.unitWidth/4,r=this.meta.unitWidth/2/n,o=getBarHeightAndYAttr(i,this.meta.zeroLine,this.meta.totalHeight),l=slicedToArray(o,2);return e=s+r*a,[t,{width:r,height:l[0],x:e,y:l[1]},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),LineChartController=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:"setupArgs",value:function(){this.consts={radius:this.meta.dotSize||4}}},{key:"draw",value:function(t,e,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",n=createSVG("circle",{style:"fill: "+i,"data-point-index":arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,cx:t,cy:e,r:this.consts.radius});return a||a.length?wrapInSVGGroup([n,createSVG("text",{className:"data-point-value",x:t,y:e,dy:FONT_SIZE/2*-1-this.consts.radius+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:a})]):n}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},UNIT_ANIM_DUR,STD_EASING]}}]),e}(AxisChartController),AxisChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.isSeries=t.isSeries,i.valuesOverPoints=t.valuesOverPoints,i.formatTooltipY=t.formatTooltipY,i.formatTooltipX=t.formatTooltipX,i.barOptions=t.barOptions,i.lineOptions=t.lineOptions,i.type=t.type||"line",i.xAxisMode=t.xAxisMode||"span",i.yAxisMode=t.yAxisMode||"span",i.setupUnitRenderer(),i.zeroLine=i.height,i.preSetup(),i.setup(),i}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:"preSetup",value:function(){}},{key:"setupUnitRenderer",value:function(){var t=this.rawChartArgs.options;this.unitRenderers={bar:new BarChartController(t),line:new LineChartController(t)}}},{key:"setHorizontalMargin",value:function(){this.translateXLeft=Y_AXIS_MARGIN,this.translateXRight=Y_AXIS_MARGIN}},{key:"checkData",value:function(t){return!0}},{key:"getFirstUpdateData",value:function(t){}},{key:"setupConstants",value:function(){var t=this;this.state={xAxisLabels:[],xAxisPositions:[],xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode},this.data.datasets.map(function(e){e.chartType||(e.chartType=t.type)}),this.prepareYAxis()}},{key:"prepareData",value:function(t){var e=this.state;e.xAxisLabels=t.labels||[],e.datasetLength=e.xAxisLabels.length;var i=new Array(e.datasetLength).fill(0);e.datasets=t.datasets,t.datasets||(e.datasets=[{values:i}]),e.datasets.map(function(t,a){var n=t.values;n=n?(n=n.map(function(t){return isNaN(t)?0:t})).length>e.datasetLength?n.slice(0,e.datasetLength):fillArray(n,e.datasetLength-n.length,0):i,t.index=a}),e.noOfDatasets=e.datasets.length,e.yMarkers=t.yMarkers,e.yRegions=t.yRegions}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"calc",value:function(){var t=this.state;t.xAxisLabels=this.data.labels,this.calcXPositions(),t.datasetsLabels=this.data.datasets.map(function(t){return t.name}),this.setYAxis(),this.calcYUnits(),this.calcYMaximums(),this.calcYRegions(),this.configUnits()}},{key:"setYAxis",value:function(){this.calcYAxisParameters(this.state.yAxis,this.getAllYValues(),"line"===this.type),this.state.zeroLine=this.state.yAxis.zeroLine}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return floatTwo(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisParameters",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"false";t.labels=calcChartIntervals(e,i);var a=t.labels;t.scaleMultiplier=this.height/getValueRange(a);var n=getIntervalSize(a)*t.scaleMultiplier;t.zeroLine=this.height-getZeroIndex(a)*n,t.positions=a.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.datasets.map(function(e){e.positions=e.values.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})}),this.barOptions&&this.barOptions.stacked&&t.datasets.map(function(e,i){e.cumulativePositions=e.cumulativeYs.map(function(e){return floatTwo(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"calcYMaximums",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativePositions);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.positions.map(function(e,i){e0)for(var l=0;l0)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 p=n.map(function(t,e){return a[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,p.join("L")))}})}},{key:"getYMarkerLines",value:function(){var t=this;return this.data.yMarkers?this.data.yMarkers.map(function(e,i){return new ChartComponent({layerClass:"y-markers",setData:function(){},makeElements:function(){return t.state.yMarkers.map(function(e){return t.renderer.yMarker(e.value,e.name,{pos:"right",mode:"span",lineType:e.type})})},animate:function(){}})}):[]}},{key:"getYRegions",value:function(){var t=this;return this.data.yRegions?this.data.yRegions.map(function(e,i){return new ChartComponent({layerClass:"y-regions",setData:function(){},makeElements:function(){return t.state.yRegions.map(function(e){return t.renderer.yRegion(e.start,e.end,e.name)})},animate:function(){}})}):[]}},{key:"refreshRenderer",value:function(){var t=this,e={totalHeight:this.height,totalWidth:this.width,xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth};this.renderer?this.renderer.refreshState(e):this.renderer=new AxisChartRenderer(e);var i={totalHeight:this.height,totalWidth:this.width,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth,noOfDatasets:this.state.noOfDatasets};i=Object.assign(i,this.rawChartArgs.options),Object.keys(this.unitRenderers).map(function(e){i.options=t[e+"Options"],t.unitRenderers[e].refreshMeta(i)})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(e){var i=getOffset(t.chartWrapper),a=e.pageX-i.left-t.translateXLeft;e.pageY-i.top-t.translateY=0;s--){var r=i.xAxisPositions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=i.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.xAxisLabels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxisLabels.length&&(t=this.xAxisLabels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,i){var a=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,i,a),this.data.labels.splice(a,0,t),this.data.datasets.map(function(t,e){t.values.splice(a,0,i[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 i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?possibleConstructorReturn(i):(i.setup(),i)}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 i=possibleConstructorReturn(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 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:"setHorizontalMargin",value:function(){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 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){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,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:e.index*Y_AXIS_MARGIN,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 t=this;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0),this.slices=[],this.slice_totals.map(function(e,i){var a=$$1.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(a)})}},{key:"calc",value:function(){}}]),e}(BaseChart),ANGLE_RATIO=Math.PI/180,FULL_ANGLE=360,PieChart=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="pie",i.elements_to_animate=null,i.hoverRadio=t.hoverRadio||.1,i.max_slices=10,i.max_legend_points=6,i.isAnimate=!1,i.startAngle=t.startAngle||0,i.clockWise=t.clockWise||!1,i.mouseMove=i.mouseMove.bind(i),i.mouseLeave=i.mouseLeave.bind(i),i.setup(),i}return inherits(e,t),createClass(e,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var a=0;return t.data.datasets.map(function(t){a+=t.values[i]}),[a,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,a=this.centerY,n=this.radius,s=this.clockWise;return"M"+i+" "+a+" L"+(i+t.x)+" "+(a+t.y)+" A "+n+" "+n+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(a+e.y)+" z"}},{key:"renderComponents",value:function(t){var i=this,a=this.radius,n=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,c=o/i.grand_total*FULL_ANGLE,u=n?-c:c,p=r+=u,d=e.getPositionByAngle(h,a),f=e.getPositionByAngle(p,a),v=t&&s[l],y=void 0,g=void 0;t?(y=v?v.startPosition:d,g=v?v.endPosition:d):(y=d,g=f);var m=i.makeArcPath(y,g),_=makePath(m,"pie-path","none",i.colors[l]);_.style.transition="transform .3s;",i.drawArea.appendChild(_),i.slices.push(_),i.slicesProperties.push({startPosition:d,endPosition:f,value:o,total:i.grand_total,startAngle:h,endAngle:p,angle:u}),t&&i.elements_to_animate.push([{unit:_,array:i.slices,index:i.slices.length-1},{d:i.makeArcPath(d,f)},650,"easein",null,{d:m}])}),t&&runSMILAnimation(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var i=this.radius,a=this.hoverRadio,n=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+n.x*a+"px,"+n.y*a+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,a){if(t){var n=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(n,50);var s=getOffset(this.svg),r=a.pageX-s.left+10,o=a.pageY-s.top-10,l=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.labels[e])+": ",h=(100*this.slice_totals[e]/this.grand_total).toFixed(1);this.tip.set_values(r,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=n}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,a=this.curActiveSlice,n=0;n0?this.formatted_labels:this.labels;this.legend_totals.map(function(i,a){var n=t.colors[a];i&&($$1.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[a]+":\n\t\t\t\t\t"+i+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*ANGLE_RATIO)*e,y:Math.cos(t*ANGLE_RATIO)*e}}}]),e}(BaseChart),Heatmap=function(t){function e(t){var i=t.start,a=void 0===i?"":i,n=t.domain,s=void 0===n?"":n,r=t.subdomain,o=void 0===r?"":r,l=t.data,h=void 0===l?{}:l,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 y=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));y.type="heatmap",y.domain=s,y.subdomain=o,y.data=h,y.discrete_domains=u,y.count_label=d;var g=new Date;return y.start=a||addDays(g,365),v=v.slice(0,5),y.legend_colors=y.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],y.distribution_size=5,y.translateX=0,y}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:"setupConstants",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&addDays(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&addDays(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=getWeeksBetween(this.first_week_start+"",this.last_week_start+"")+1}},{key:"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 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=makeText("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}(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 0df661f..e26bd63 100644 --- a/dist/frappe-charts.min.iife.js +++ b/dist/frappe-charts.min.iife.js @@ -1 +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 n(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function a(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function s(t){return parseFloat(t.toFixed(2))}function r(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function o(t,e){return(t+"").length*e}function l(t,e){var i=void 0,n=void 0;return t<=e?(n=t,0===(i=e-t)&&(n-=i=totalHeight*MIN_BAR_PERCENT_HEIGHT)):(i=t-e,n=e),[i,n]}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){return"string"==typeof t?(e||document).querySelector(t):t||null}function u(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e){var a=e[n];if("inside"===n)c(a).appendChild(i);else if("around"===n){var s=c(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":V(a))&&Object.keys(a).map(function(t){i.style[t]=a[t]}):("className"===n&&(n="class"),"innerHTML"===n?i.textContent=a:i.setAttribute(n,a))}return i}function p(t,e){return u("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function d(t,e,i,n){return u("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function f(t,e,i,n){return u("svg",{className:e,inside:t,width:i,height:n})}function v(t){return u("defs",{inside:t})}function y(t,e){return u("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function g(t){var e=u("g",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""});return t.forEach(function(t){return e.appendChild(t)}),e}function m(t){return u("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 x(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=p(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),d(a,"0%",e,s[0]),d(a,"50%",e,s[1]),d(a,"100%",e,s[2]),n}function k(t,e,i,n){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:i,width:n,height:n,fill:1};return Object.keys(a).map(function(t){s[t]=a[t]}),u("rect",s)}function _(t,e,i,n){return u("text",{className:t,x:e,y:i,dy:rt/2+"px","font-size":rt+"px",innerHTML:n})}function b(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=ot);var s=u("line",{className:"line-vertical "+a.className,x1:0,x2:0,y1:i,y2:n,styles:{stroke:a.stroke}}),r=u("text",{x:0,y:i>n?i+st:i-st-rt,dy:rt+"px","font-size":rt+"px","text-anchor":"middle",innerHTML:e}),o=u("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function w(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=ot),a.lineType||(a.lineType="");var s=u("line",{className:"line-horizontal "+a.className+("dashed"===a.lineType?"dashed":""),x1:i,x2:n,y1:t,y2:t,styles:{stroke:a.stroke}}),r=u("text",{x:i255?255:t<0?0:t}function M(t,e){var i=ut(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=A((a>>16)+e),r=A((a>>8&255)+e),o=A((255&a)+e);return(n?"#":"")+(o|r<<8|s<<16).toString(16)}function C(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function L(t,e,i){if(t!==e){pt.includes(t)||console.error("'"+t+"' is not a valid chart type."),dt[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var n=ft[e].includes(t);return new Pt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function O(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},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:vt[n],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};a&&(p.type=a);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),a?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}return[r,o]}function P(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function T(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=O.apply(void 0,it(t)),l=et(o,2);s=l[0],r=l[1],i.push(r),n.push([s,a]),a.replaceChild(s,e)});var a=t.cloneNode(!0);return n.map(function(t,n){t[1].replaceChild(i[n],t[0]),e[n][0]=i[n]}),a}function D(t,e,i){if(0!==i.length){var n=T(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},at)}}function N(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=t.map(function(t,i){return e[i]+","+t}).join("L"),r=m("M"+s,"line-graph-path",i);if(n){var o=x(this.svgDefs,i);r.style.stroke="url(#"+o+")"}var l=[r];if(a){var h=x(this.svgDefs,i,!0),c=this.state.yAxis.zeroLine,u="M0,"+c+"L"+s+"L"+this.width+","+c;l.push(m(u,"region-fill","none","url(#"+h+")"))}return l}function W(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function S(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),n=Math.floor(e),a=i-n,s=a,r=1;a>5&&(a%2!=0&&(a=++i-n),s=a/2,r=2),a<=2&&(r=a/(s=4)),0===a&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(n+r*l);return o}function z(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=W(t),n=et(i,2),a=n[0],s=n[1],r=e?e/Math.pow(10,s):0,o=S(a=a.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function R(t){function e(t,e){for(var i=z(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,it(t)),a=Math.min.apply(Math,it(t)),s=[];if(n>=0&&a>=0)W(n)[1],s=i?z(n,a):z(n);else if(n>0&&a<0){var r=Math.abs(a);n>=r?(W(n)[1],s=e(n,r)):(W(r)[1],s=e(r,n).map(function(t){return-1*t}))}else if(n<=0&&a<=0){var o=Math.abs(a),l=Math.abs(n);W(o)[1],s=(s=i?z(o,l):z(o)).reverse().map(function(t){return-1*t})}return s}function E(t){var e=Y(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 Y(t){return t[1]-t[0]}function j(t){return t[t.length-1]-t[0]}function H(t,e){for(var i=Math.max.apply(Math,it(t)),n=1/(e-1),a=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function B(t,e){return Math.ceil(I(t,e)/7)}function I(t,e){return(U(e)-U(t))/864e5}function q(t,e){t.setDate(t.getDate()+e)}function J(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"line"===t?(e.type="line",new _t(e)):"bar"===t?(e.type="bar",new _t(e)):Ot[t]?new Ot[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],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{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 V="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},Z=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,a){var o={key:t,arg:e,resolve:i,reject:a,next:null};r?r=r.next=o:(s=r=o,n(t,e))})}function n(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(r.done?"return":"normal",r.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?n(s.key,s.arg):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")}),G=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
            \n\t\t\t\t
            '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){e.hide_tip()})}},{key:"fill",value:function(){var e=this,i=void 0;i=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,n){var a=e.colors[n]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var n="calc(50% + "+(this.left-e)+"px)";i.style.left=n,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=n,this.list_values=a,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),e}(),at=250,st=4,rt=10,ot="#dadada",lt=function(){function t(e){Z(this,t),this.refreshState(e)}return G(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:"xLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode=this.xAxisMode),i.stroke||(i.stroke=ot),i.className||(i.className="");var n=this.totalHeight+6,a="span"===i.mode?-6:this.totalHeight;return"tick"===i.mode&&"top"===i.pos&&(n=-6,a=0),b(t,e,n,a,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode=this.yAxisMode),i.stroke||(i.stroke=ot),i.className||(i.className="");var n=-6,a="span"===i.mode?this.totalWidth+6:0;return"tick"===i.mode&&"right"===i.pos&&(n=this.totalWidth+6,a=this.totalWidth),n+=i.offset,a+=i.offset,w(t,e,n,a,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=u("text",{className:"chart-label",x:this.totalWidth-o(e,5)-st,y:t-rt-2,dy:rt/2+"px","font-size":rt+"px","text-anchor":"start",innerHTML:e+""}),a=w(t,"",0,this.totalWidth,{stroke:i.stroke||ot,className:i.className||"",lineType:i.lineType});return a.appendChild(n),a}},{key:"xRegion",value:function(){return u("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"yRegion",value:function(t,e,i){var n=u("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:e,width:this.totalWidth,height:t-e}),a=u("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:e,y2:e,styles:{stroke:ot}}),s=u("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:t,y2:t,styles:{stroke:ot}}),r=u("text",{className:"chart-label",x:this.totalWidth-o(i,4.5)-st,y:e-rt-2,dy:rt/2+"px","font-size":rt+"px","text-anchor":"start",innerHTML:i+""}),l=u("g",{});return l.appendChild(n),l.appendChild(a),l.appendChild(s),l.appendChild(r),l}},{key:"animatebar",value:function(t,e,i,n,a){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/a,o=l(i,this.zeroLine,this.totalHeight),h=et(o,2);return e=s+r*n,[t,{width:r,height:h[0],x:e,y:h[1]},350,"easein"]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},350,"easein"]}},{key:"animatepath",value:function(t,e){var i=[],n=[t[0],{d:"M"+e},350,"easein"];if(i.push(n),t[1]){var a="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+a+e+s},350,"easein"];i.push(r)}return i}},{key:"translate",value:function(t,e,i,n){return[t,{transform:i.join(", ")},n,"easein","translate",{transform:e.join(", ")}]}},{key:"translateVertLine",value:function(t,e,i){return this.translate(t,[i,0],[e,0],350)}},{key:"translateHoriLine",value:function(t,e,i){return this.translate(t,[0,i],[0,e],350)}}]),t}(),ht={"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"},ct=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],ut=function(t){return ht[t]||t},pt=["line","scatter","bar","percentage","heatmap","pie"],dt={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:[]},ft={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},vt={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"},yt=function(){function e(t){var i=t.height,n=void 0===i?240:i,a=t.title,s=void 0===a?"":a,r=t.subtitle,o=void 0===r?"":r,l=(t.colors,t.isNavigable),h=void 0===l?0:l,c=(t.showLegend,t.type,t.parent);Z(this,e),this.rawChartArgs=arguments[0],this.parent="string"==typeof c?document.querySelector(c):c,this.title=s,this.subtitle=o,this.argHeight=n,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return G(e,[{key:"configure",value:function(t){this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:0},this.state={colors:this.colors}}},{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 nt({parent:this.chartWrapper,colors:this.colors}),this.bindTooltip()}},{key:"bindTooltip",value:function(){}},{key:"draw",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.calcWidth(),this.refresh(this.data),this.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.renderConstants(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(t){this.refresh(t),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=a(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(t){this.oldState=this.state?JSON.parse(JSON.stringify(this.state)):{},this.intermedState={},this.prepareData(t),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){this.svg=f(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=v(this.svg),this.drawArea=y(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"renderConstants",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){this.renderer={}}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.elementsToAnimate=[],this.loadAnimatedComponents(),D(this.chartWrapper,this.svg,this.elementsToAnimate),setTimeout(function(){t.renderComponents()},400)}},{key:"setComponentParent",value:function(){var t=this;this.components.forEach(function(e){return e.setupParent(t.drawArea)})}},{key:"makeComponentLayers",value:function(){this.components.forEach(function(t){return t.makeLayer()})}},{key:"renderComponents",value:function(){this.components.forEach(function(t){return t.render()})}},{key:"loadAnimatedComponents",value:function(){this.components.forEach(function(t){return t.loadAnimatedComponents()})}},{key:"refreshComponents",value:function(){var t=this;this.components.forEach(function(e){return e.refresh(t.state,t.rawChartArgs)})}},{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){n(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(){}},{key:"updateDataset",value:function(t,e){}},{key:"updateDatasets",value:function(t){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"updateDataPoint",value:function(t){}},{key:"getDifferentChart",value:function(t){return L(t,this.type,this.rawChartArgs)}}]),e}(),gt=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,s=void 0===a?"":a,r=e.initData,o=e.setData,l=e.preMake,h=e.make,c=e.postMake,u=e.animate;Z(this,t),this.layerClass=n,this.layerTransform=s,this.initData=r,this.setData=o,this.preMake=l,this.make=h,this.postMake=c,this.animate=u,this.layer=void 0,this.store=[]}return G(t,[{key:"refresh",value:function(t,e){this.meta=Object.assign(this.meta||{},e),this.state=t}},{key:"render",value:function(){var t=this;this.data=this.setData(),this.preMake&&this.preMake(),this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)}),this.postMake&&this.postMake()}},{key:"setupParent",value:function(t){this.parent=t}},{key:"loadAnimatedComponents",value:function(){this.animate(this.store)}},{key:"makeLayer",value:function(){this.layer=y(this.parent,this.layerClass,this.layerTransform)}}]),t}(),mt=function(){function t(e){Z(this,t),this.meta=e||{},this.setupArgs()}return G(t,[{key:"setupArgs",value:function(){this.consts={}}},{key:"setup",value:function(){}},{key:"refreshMeta",value:function(t){this.meta=Object.assign(this.meta||{},t)}},{key:"draw",value:function(){}},{key:"animate",value:function(){}}]),t}(),xt=(function(t){function e(t){return Z(this,e),tt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}Q(e,t),G(e,[{key:"draw",value:function(t,e,i,n){return u("circle",{style:"fill: "+i,"data-point-index":n,cx:t,cy:e,r:this.consts.radius})}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},350,"easein"]}}])}(mt),function(t){function e(t){return Z(this,e),tt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return Q(e,t),G(e,[{key:"setupArgs",value:function(){this.consts={spaceRatio:.5,minHeight:.01*this.meta.totalHeight}}},{key:"refreshMeta",value:function(t){t&&K(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refreshMeta",this).call(this,t);var i=this.meta;this.consts.barsWidth=i.unitWidth-i.unitWidth*this.consts.spaceRatio,this.consts.width=this.consts.barsWidth/(i.options&&i.options.stacked?i.options.stacked:i.noOfDatasets)}},{key:"draw",value:function(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=l(e,this.meta.zeroLine),o=et(r,2),h=o[0],c=o[1],p=u("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":a,x:t-this.consts.barsWidth/2,y:c-s,width:this.consts.width,height:h||this.consts.minHeight});return n||n.length?g([p,u("text",{className:"data-point-value",x:t,y:c-s,dy:rt/2*-1+"px","font-size":rt+"px","text-anchor":"middle",innerHTML:n})]):p}},{key:"animate",value:function(t,e,i,n,a){var s=e-this.meta.unitWidth/4,r=this.meta.unitWidth/2/a,o=l(i,this.meta.zeroLine,this.meta.totalHeight),h=et(o,2);return e=s+r*n,[t,{width:r,height:h[0],x:e,y:h[1]},350,"easein"]}}]),e}(mt)),kt=function(t){function e(t){return Z(this,e),tt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return Q(e,t),G(e,[{key:"setupArgs",value:function(){this.consts={radius:this.meta.dotSize||4}}},{key:"draw",value:function(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=u("circle",{style:"fill: "+i,"data-point-index":arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,cx:t,cy:e,r:this.consts.radius});return n||n.length?g([a,u("text",{className:"data-point-value",x:t,y:e,dy:rt/2*-1-this.consts.radius+"px","font-size":rt+"px","text-anchor":"middle",innerHTML:n})]):a}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},350,"easein"]}}]),e}(mt),_t=function(t){function i(t){Z(this,i);var e=tt(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.setupUnitRenderer(),e.zeroLine=e.height,e.preSetup(),e.setup(),e}return Q(i,t),G(i,[{key:"configure",value:function(t){K(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"preSetup",value:function(){}},{key:"setupUnitRenderer",value:function(){var t=this.rawChartArgs.options;this.unitRenderers={bar:new xt(t),line:new kt(t)}}},{key:"setHorizontalMargin",value:function(){this.translateXLeft=60,this.translateXRight=60}},{key:"checkData",value:function(t){return!0}},{key:"getFirstUpdateData",value:function(t){}},{key:"setupConstants",value:function(){var t=this;this.state={xAxisLabels:[],xAxisPositions:[],xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode},this.data.datasets.map(function(e){e.chartType||(e.chartType=t.type)}),this.prepareYAxis()}},{key:"prepareData",value:function(t){var e=this.state;e.xAxisLabels=t.labels||[],e.datasetLength=e.xAxisLabels.length;var i=new Array(e.datasetLength).fill(0);e.datasets=t.datasets,t.datasets||(e.datasets=[{values:i}]),e.datasets.map(function(t,n){var a=t.values;a=a?(a=a.map(function(t){return isNaN(t)?0:t})).length>e.datasetLength?a.slice(0,e.datasetLength):r(a,e.datasetLength-a.length,0):i,t.index=n}),e.noOfDatasets=e.datasets.length,e.yMarkers=t.yMarkers,e.yRegions=t.yRegions}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this.state;t.xAxisLabels=this.data.labels,this.calcXPositions(),t.datasetsLabels=this.data.datasets.map(function(t){return t.name}),this.setYAxis(),this.calcYUnits(),this.calcYMaximums(),this.calcYRegions(),this.configUnits()}},{key:"setYAxis",value:function(){this.calcYAxisParameters(this.state.yAxis,this.getAllYValues(),"line"===this.type),this.state.zeroLine=this.state.yAxis.zeroLine}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return s(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisParameters",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"false";t.labels=R(e,i);var n=t.labels;t.scaleMultiplier=this.height/j(n);var a=Y(n)*t.scaleMultiplier;t.zeroLine=this.height-E(n)*a,t.positions=n.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.datasets.map(function(e){e.positions=e.values.map(function(e){return s(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})}),this.barOptions&&this.barOptions.stacked&&t.datasets.map(function(e,i){e.cumulativePositions=e.cumulativeYs.map(function(e){return s(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"calcYMaximums",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativePositions);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.positions.map(function(e,i){e0)for(var c=0;c0)for(var l=0;l0)for(var l=0;l0&&(t=N(r,s,i.colors[e],i.config.heatline,i.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var d=a.map(function(t,e){return n[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,d.join("L")))}})}},{key:"getYMarkerLines",value:function(){var t=this;return this.data.yMarkers?this.data.yMarkers.map(function(e,i){return new gt({layerClass:"y-markers",setData:function(){},make:function(){return t.state.yMarkers.map(function(e){return t.renderer.yMarker(e.value,e.name,{pos:"right",mode:"span",lineType:e.type})})},animate:function(){}})}):[]}},{key:"getYRegions",value:function(){var t=this;return this.data.yRegions?this.data.yRegions.map(function(e,i){return new gt({layerClass:"y-regions",setData:function(){},make:function(){return t.state.yRegions.map(function(e){return t.renderer.yRegion(e.start,e.end,e.name)})},animate:function(){}})}):[]}},{key:"getXRegions",value:function(){return[]}},{key:"refreshRenderer",value:function(){var t=this,e={totalHeight:this.height,totalWidth:this.width,xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth};this.renderer?this.renderer.refreshState(e):this.renderer=new lt(e),this.refreshComponents();var i={totalHeight:this.height,totalWidth:this.width,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth,noOfDatasets:this.state.noOfDatasets};i=Object.assign(i,this.rawChartArgs.options),Object.keys(this.unitRenderers).map(function(e){i.options=t[e+"Options"],t.unitRenderers[e].refreshMeta(i)})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(i){var n=e(t.chartWrapper),a=i.pageX-n.left-t.translateXLeft;i.pageY-n.top-t.translateY=0;s--){var r=i.xAxisPositions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=i.datasets.map(function(t,i){return{title:t.title,value:a?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[i]}});this.tip.set_values(o,l,n[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(n){var a=n.slice(0,n.length-1);e[a]=i[n][t]}),e.label=this.xAxisLabels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxisLabels.length&&(t=this.xAxisLabels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;K(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"addDataPoint",this).call(this,t,e,n),this.data.labels.splice(n,0,t),this.data.datasets.map(function(t,i){t.values.splice(n,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;K(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}(yt),bt=function(t){function e(t){Z(this,e);var i=tt(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 Q(e,t),G(e,[{key:"setup_values",value:function(){K(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){Z(this,e);var i=tt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?tt(i):(i.setup(),i)}return Q(e,t),G(e,[{key:"configure",value:function(t){K(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}(_t)),wt=function(t){function e(t){return Z(this,e),tt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return Q(e,t),G(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setHorizontalMargin",value:function(){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){K(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var i=0,n=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?i++:n++}})}},{key:"configure",value:function(t){K(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 n="left"===e.yAxis.position?-1*e.yAxis.index*60:t.width+60*e.yAxis.index;t.renderer.xLine(n,"",{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 gt({layerClass:"y axis y-axis-"+i,make:function(){var e=t.state.datasets[i].yAxis;t.renderer.setZeroline(e.zeroline);var n={pos:e.position,mode:"tick",offset:60*e.index,stroke:t.colors[i]};return e.positions.map(function(i,a){return t.renderer.yLine(i,e.labels[a],n)})},animate:function(){}})})}},{key:"getChartComponents",value:function(){var t=this;return this.data.datasets.map(function(e,i){return new gt({layerClass:"dataset-units dataset-"+i,make:function(){var e=t.state.datasets[i],n=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,a){return t.renderer[n.type](t.state.xAxisPositions[a],e,n.args,t.colors[i],a,i,t.state.datasetLength)})},animate:function(e){var n=t.state.datasets[i],a=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 n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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,n){var a=t.create("div",{className:"progress-bar",inside:e.percentageBar,styles:{background:e.colors[n],width:100*i/e.grand_total+"%"}});e.slices.push(a)})}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(i,n){i.addEventListener("mouseenter",function(){var a=e(t.chartWrapper),s=e(i),r=s.left-a.left+i.offsetWidth/2,o=s.top-a.top-6,l=(t.formatted_labels&&t.formatted_labels.length>0?t.formatted_labels[n]:t.labels[n])+": ",h=(100*t.slice_totals[n]/t.grand_total).toFixed(1);t.tip.set_values(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(n,a){n&&(t.create("div",{className:"stats",inside:e.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}]),n}(yt),Mt=Math.PI/180,Ct=function(i){function n(t){Z(this,n);var e=tt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t));return e.type="pie",e.elements_to_animate=null,e.hoverRadio=t.hoverRadio||.1,e.max_slices=10,e.max_legend_points=6,e.isAnimate=!1,e.startAngle=t.startAngle||0,e.clockWise=t.clockWise||!1,e.mouseMove=e.mouseMove.bind(e),e.mouseLeave=e.mouseLeave.bind(e),e.setup(),e}return Q(n,i),G(n,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var n=0;return t.data.datasets.map(function(t){n+=t.values[i]}),[n,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,n=this.centerY,a=this.radius,s=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"renderComponents",value:function(t){var e=this,i=this.radius,a=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,c=o/e.grand_total*360,u=a?-c:c,p=r+=u,d=n.getPositionByAngle(h,i),f=n.getPositionByAngle(p,i),v=t&&s[l],y=void 0,g=void 0;t?(y=v?v.startPosition:d,g=v?v.endPosition:d):(y=d,g=f);var x=e.makeArcPath(y,g),k=m(x,"pie-path","none",e.colors[l]);k.style.transition="transform .3s;",e.drawArea.appendChild(k),e.slices.push(k),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:k,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(d,f)},650,"easein",null,{d:x}])}),t&&D(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var e=this.radius,i=this.hoverRadio,a=n.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+a.x*i+"px,"+a.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,i,n,a){if(t){var s=this.colors[i];if(n){P(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=M(s,50);var r=e(this.svg),o=a.pageX-r.left+10,l=a.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 P(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=s}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,n=this.curActiveSlice,a=0;a0?this.formatted_labels:this.labels;this.legend_totals.map(function(n,a){var s=e.colors[a];n&&(t.create("div",{className:"stats",inside:e.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*Mt)*e,y:Math.cos(t*Mt)*e}}}]),n}(yt),Lt=function(t){function e(t){var i=t.start,n=void 0===i?"":i,a=t.domain,s=void 0===a?"":a,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;Z(this,e);var y=tt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));y.type="heatmap",y.domain=s,y.subdomain=o,y.data=h,y.discrete_domains=u,y.count_label=d;var g=new Date;return y.start=n||q(g,365),v=v.slice(0,5),y.legend_colors=y.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],y.distribution_size=5,y.translateX=0,y}return Q(e,t),G(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){C(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"setupConstants",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&q(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&q(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=B(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=H(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()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=v}return[s,n]}},{key:"render_month_labels",value:function(){var t=this;this.months.shift(),this.month_start_points.shift(),this.months.pop(),this.month_start_points.pop(),this.month_start_points.map(function(e,i){var n=_("y-value-text",e+12,10,t.month_names[t.months[i]].substring(0,3));t.domain_label_group.appendChild(n)})}},{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"),n=e.target.getAttribute("data-date").split("-"),a=t.month_names[parseInt(n[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 "+a+" "+n[0]+", "+n[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}(yt),Ot={mixed:_t,multiaxis:wt,scatter:bt,percentage:At,heatmap:Lt,pie:Ct},Pt=function t(e){return Z(this,t),J(e.type,arguments[0])};return Pt}(); +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 n(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function a(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function s(t){return parseFloat(t.toFixed(2))}function r(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function o(t,e){return(t+"").length*e}function l(t,e){var i=void 0,n=void 0;return t<=e?(n=t,0===(i=e-t)&&(n-=i=totalHeight*MIN_BAR_PERCENT_HEIGHT)):(i=t-e,n=e),[i,n]}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,n){return[t,{transform:i.join(", ")},n,ut,"translate",{transform:e.join(", ")}]}function u(t,e,i){return c(t,[0,i],[0,e],ht)}function p(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function d(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e){var a=e[n];if("inside"===n)p(a).appendChild(i);else if("around"===n){var s=p(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":tt(a))&&Object.keys(a).map(function(t){i.style[t]=a[t]}):("className"===n&&(n="class"),"innerHTML"===n?i.textContent=a:i.setAttribute(n,a))}return i}function f(t,e){return d("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function v(t,e,i,n){return d("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function y(t,e,i,n){return d("svg",{className:e,inside:t,width:i,height:n})}function g(t){return d("defs",{inside:t})}function m(t,e){return d("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function x(t){var e=d("g",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""});return t.forEach(function(t){return e.appendChild(t)}),e}function k(t){return d("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){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=f(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),v(a,"0%",e,s[0]),v(a,"50%",e,s[1]),v(a,"100%",e,s[2]),n}function b(t,e,i,n){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:i,width:n,height:n,fill:1};return Object.keys(a).map(function(t){s[t]=a[t]}),d("rect",s)}function w(t,e,i,n){return d("text",{className:t,x:e,y:i,dy:ft/2+"px","font-size":ft+"px",innerHTML:n})}function A(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=vt);var s=d("line",{className:"line-vertical "+a.className,x1:0,x2:0,y1:i,y2:n,styles:{stroke:a.stroke}}),r=d("text",{x:0,y:i>n?i+dt:i-dt-ft,dy:ft+"px","font-size":ft+"px","text-anchor":"middle",innerHTML:e}),o=d("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function M(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=vt),a.lineType||(a.lineType="");var s=d("line",{className:"line-horizontal "+a.className+("dashed"===a.lineType?"dashed":""),x1:i,x2:n,y1:0,y2:0,styles:{stroke:a.stroke}}),r=d("text",{x:i3&&void 0!==arguments[3]?arguments[3]:{};n.pos||(n.pos="left"),n.offset||(n.offset=0),n.mode||(n.mode="span"),n.stroke||(n.stroke=vt),n.className||(n.className="");var a=-1*pt,s="span"===n.mode?i+pt:0;return"tick"===n.mode&&"right"===n.pos&&(a=i+pt,s=i),a+=n.offset,s+=n.offset,M(t,e,a,s,{stroke:n.stroke,className:n.className,lineType:n.lineType})}function L(t){return t>255?255:t<0?0:t}function O(t,e){var i=xt(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=L((a>>16)+e),r=L((a>>8&255)+e),o=L((255&a)+e);return(n?"#":"")+(o|r<<8|s<<16).toString(16)}function T(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function P(t,e,i){if(t!==e){kt.includes(t)||console.error("'"+t+"' is not a valid chart type."),_t[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var n=bt[e].includes(t);return new Rt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function D(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},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:wt[n],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};a&&(p.type=a);for(var d in p)h.setAttribute(d,p[d]);r.appendChild(h),a?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}return[r,o]}function N(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function W(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.parentNode,s=void 0,r=void 0;t[0]=e;var o=D.apply(void 0,ot(t)),l=rt(o,2);s=l[0],r=l[1],i.push(r),n.push([s,a]),a.replaceChild(s,e)});var a=t.cloneNode(!0);return n.map(function(t,n){t[1].replaceChild(i[n],t[0]),e[n][0]=i[n]}),a}function S(t,e,i){if(0!==i.length){var n=W(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},ct)}}function E(t,e,i){return new Mt({parent:t,layerClass:"y axis",constants:e,data:i,makeElements:function(t){var e=this;return t.positions.map(function(i,n){return C(i,t.labels[n],e.constants.width,{mode:e.constants.mode,pos:e.constants.pos})})},animateElements:function(t){var e=t.positions,i=t.labels,n=this.oldData.positions,a=this.oldData.labels,s=h(n,e),r=rt(s,2);n=r[0],e=r[1];var o=h(a,i),l=rt(o,2);return a=l[0],i=l[1],this.render({positions:n,labels:i}),this.store.map(function(t,i){return u(t,e[i],n[i])})}})}function z(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=t.map(function(t,i){return e[i]+","+t}).join("L"),r=k("M"+s,"line-graph-path",i);if(n){var o=_(this.svgDefs,i);r.style.stroke="url(#"+o+")"}var l=[r];if(a){var h=_(this.svgDefs,i,!0),c=this.state.yAxis.zeroLine,u="M0,"+c+"L"+s+"L"+this.width+","+c;l.push(k(u,"region-fill","none","url(#"+h+")"))}return l}function R(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function j(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),n=Math.floor(e),a=i-n,s=a,r=1;a>5&&(a%2!=0&&(a=++i-n),s=a/2,r=2),a<=2&&(r=a/(s=4)),0===a&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(n+r*l);return o}function Y(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=R(t),n=rt(i,2),a=n[0],s=n[1],r=e?e/Math.pow(10,s):0,o=j(a=a.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function H(t){function e(t,e){for(var i=Y(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,ot(t)),a=Math.min.apply(Math,ot(t)),s=[];if(n>=0&&a>=0)R(n)[1],s=i?Y(n,a):Y(n);else if(n>0&&a<0){var r=Math.abs(a);n>=r?(R(n)[1],s=e(n,r)):(R(r)[1],s=e(r,n).map(function(t){return-1*t}))}else if(n<=0&&a<=0){var o=Math.abs(a),l=Math.abs(n);R(o)[1],s=(s=i?Y(o,l):Y(o)).reverse().map(function(t){return-1*t})}return s}function X(t){var e=F(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 U(t,e){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,a=1*(t-i)/e,s=[],r=0;r<=e;r++)s.push(i+a*r);return n?s:s.reverse()}function F(t){return t[1]-t[0]}function B(t){return t[t.length-1]-t[0]}function I(t,e){for(var i=Math.max.apply(Math,ot(t)),n=1/(e-1),a=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function J(t,e){return Math.ceil(G(t,e)/7)}function G(t,e){return(V(e)-V(t))/864e5}function K(t,e){t.setDate(t.getDate()+e)}function Q(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return"line"===t?(e.type="line",new Tt(e)):"bar"===t?(e.type="bar",new Tt(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],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{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 tt="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},et=(function(){function t(t){this.value=t}function e(e){function i(t,e){return new Promise(function(i,a){var o={key:t,arg:e,resolve:i,reject:a,next:null};r?r=r.next=o:(s=r=o,n(t,e))})}function n(i,s){try{var r=e[i](s),o=r.value;o instanceof t?Promise.resolve(o.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(r.done?"return":"normal",r.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":s.resolve({value:e,done:!0});break;case"throw":s.reject(e);break;default:s.resolve({value:e,done:!1})}(s=s.next)?n(s.key,s.arg):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")}),it=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
              \n\t\t\t\t
              '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){e.hide_tip()})}},{key:"fill",value:function(){var e=this,i=void 0;i=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,n){var a=e.colors[n]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var n="calc(50% + "+(this.left-e)+"px)";i.style.left=n,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=n,this.list_values=a,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),e}(),ht=350,ct=250,ut="easein",pt=6,dt=4,ft=10,vt="#dadada",yt=function(){function t(e){et(this,t),this.refreshState(e)}return it(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:"xLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke=vt),i.className||(i.className="");var n=this.totalHeight+pt,a="span"===i.mode?-1*pt:this.totalHeight;return"tick"===i.mode&&"top"===i.pos&&(n=-1*pt,a=0),A(t,e,n,a,{stroke:i.stroke,className:i.className,lineType:i.lineType})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=d("text",{className:"chart-label",x:this.totalWidth-o(e,5)-dt,y:t-ft-2,dy:ft/2+"px","font-size":ft+"px","text-anchor":"start",innerHTML:e+""}),a=M(t,"",0,this.totalWidth,{stroke:i.stroke||vt,className:i.className||"",lineType:i.lineType});return a.appendChild(n),a}},{key:"xRegion",value:function(){return d("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:y2,width:this.totalWidth,height:y1-y2})}},{key:"yRegion",value:function(t,e,i){var n=d("rect",{className:"bar mini",style:"fill: rgba(228, 234, 239, 0.49)",x:0,y:e,width:this.totalWidth,height:t-e}),a=d("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:e,y2:e,styles:{stroke:vt}}),s=d("line",{className:"line-horizontal",x1:0,x2:this.totalWidth,y1:t,y2:t,styles:{stroke:vt}}),r=d("text",{className:"chart-label",x:this.totalWidth-o(i,4.5)-dt,y:e-ft-2,dy:ft/2+"px","font-size":ft+"px","text-anchor":"start",innerHTML:i+""}),l=d("g",{});return l.appendChild(n),l.appendChild(a),l.appendChild(s),l.appendChild(r),l}},{key:"animatebar",value:function(t,e,i,n,a){var s=e-this.avgUnitWidth/4,r=this.avgUnitWidth/2/a,o=l(i,this.zeroLine,this.totalHeight),h=rt(o,2);return e=s+r*n,[t,{width:r,height:h[0],x:e,y:h[1]},350,ut]}},{key:"animatedot",value:function(t,e,i){return[t,{cx:e,cy:i},350,ut]}},{key:"animatepath",value:function(t,e){var i=[],n=[t[0],{d:"M"+e},350,ut];if(i.push(n),t[1]){var a="0,"+this.zeroLine+"L",s="L"+this.totalWidth+", "+this.zeroLine,r=[t[1],{d:"M"+a+e+s},350,ut];i.push(r)}return i}}]),t}(),gt={"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"},mt=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],xt=function(t){return gt[t]||t},kt=["line","scatter","bar","percentage","heatmap","pie"],_t={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:[]},bt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},wt={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"},At=function(){function e(t){var i=t.height,n=void 0===i?240:i,a=t.title,s=void 0===a?"":a,r=t.subtitle,o=void 0===r?"":r,l=(t.colors,t.isNavigable),h=void 0===l?0:l,c=(t.showLegend,t.type,t.parent);et(this,e),this.rawChartArgs=arguments[0],this.parent="string"==typeof c?document.querySelector(c):c,this.title=s,this.subtitle=o,this.argHeight=n,this.isNavigable=h,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return it(e,[{key:"configure",value:function(t){this.setColors(),this.config={showTooltip:1,showLegend:1,isNavigable:0,animate:0},this.state={colors:this.colors}}},{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 lt({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.components.forEach(function(t){return t.make()}),this.renderLegend(),this.setupNavigation(e),setTimeout(function(){t.update()},1e3)}},{key:"calcWidth",value:function(){this.baseWidth=a(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.prepareData(t),this.calc(),this.refreshRenderer(),this.render()}},{key:"prepareData",value:function(){}},{key:"renderConstants",value:function(){}},{key:"calc",value:function(){}},{key:"refreshRenderer",value:function(){this.renderer={}}},{key:"render",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.refreshComponents(),this.elementsToAnimate=[].concat.apply([],this.components.map(function(e){return e.update(t)})),console.log(this.elementsToAnimate),this.elementsToAnimate&&S(this.chartWrapper,this.svg,this.elementsToAnimate)}},{key:"refreshComponents",value:function(){}},{key:"makeChartArea",value:function(){this.svg=y(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svgDefs=g(this.svg),this.drawArea=m(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){n(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(){}},{key:"updateDataset",value:function(t,e){}},{key:"updateDatasets",value:function(t){}},{key:"addDataset",value:function(t,e){}},{key:"removeDataset",value:function(){}},{key:"addDataPoint",value:function(t){}},{key:"removeDataPoint",value:function(){}},{key:"updateDataPoint",value:function(t){}},{key:"getDifferentChart",value:function(t){return P(t,this.type,this.rawChartArgs)}}]),e}(),Mt=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,s=void 0===a?"":a,r=e.parent,o=e.constants,l=e.data,h=e.preMake,c=e.makeElements,u=e.postMake,p=e.animateElements;et(this,t),this.parent=r,this.layerClass=n,this.layerTransform=s,this.constants=o,this.preMake=h,this.makeElements=c,this.postMake=u,this.animateElements=p,this.store=[],this.layer=m(this.parent,this.layerClass,this.layerTransform),this.data=l,this.make()}return it(t,[{key:"refresh",value:function(t){this.data=t}},{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=[];return(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(e=this.animateElements(this.data)),setTimeout(function(){t.make()},1400),e}}]),t}(),Ct=function(){function t(e){et(this,t),this.meta=e||{},this.setupArgs()}return it(t,[{key:"setupArgs",value:function(){this.consts={}}},{key:"setup",value:function(){}},{key:"refreshMeta",value:function(t){this.meta=Object.assign(this.meta||{},t)}},{key:"draw",value:function(){}},{key:"animate",value:function(){}}]),t}(),Lt=(function(t){function e(t){return et(this,e),st(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}at(e,t),it(e,[{key:"draw",value:function(t,e,i,n){return d("circle",{style:"fill: "+i,"data-point-index":n,cx:t,cy:e,r:this.consts.radius})}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},350,ut]}}])}(Ct),function(t){function e(t){return et(this,e),st(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return at(e,t),it(e,[{key:"setupArgs",value:function(){this.consts={spaceRatio:.5,minHeight:.01*this.meta.totalHeight}}},{key:"refreshMeta",value:function(t){t&&nt(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refreshMeta",this).call(this,t);var i=this.meta;this.consts.barsWidth=i.unitWidth-i.unitWidth*this.consts.spaceRatio,this.consts.width=this.consts.barsWidth/(i.options&&i.options.stacked?i.options.stacked:i.noOfDatasets)}},{key:"draw",value:function(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,r=l(e,this.meta.zeroLine),o=rt(r,2),h=o[0],c=o[1],u=d("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":a,x:t-this.consts.barsWidth/2,y:c-s,width:this.consts.width,height:h||this.consts.minHeight});return n||n.length?x([u,d("text",{className:"data-point-value",x:t,y:c-s,dy:ft/2*-1+"px","font-size":ft+"px","text-anchor":"middle",innerHTML:n})]):u}},{key:"animate",value:function(t,e,i,n,a){var s=e-this.meta.unitWidth/4,r=this.meta.unitWidth/2/a,o=l(i,this.meta.zeroLine,this.meta.totalHeight),h=rt(o,2);return e=s+r*n,[t,{width:r,height:h[0],x:e,y:h[1]},350,ut]}}]),e}(Ct)),Ot=function(t){function e(t){return et(this,e),st(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return at(e,t),it(e,[{key:"setupArgs",value:function(){this.consts={radius:this.meta.dotSize||4}}},{key:"draw",value:function(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=d("circle",{style:"fill: "+i,"data-point-index":arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,cx:t,cy:e,r:this.consts.radius});return n||n.length?x([a,d("text",{className:"data-point-value",x:t,y:e,dy:ft/2*-1-this.consts.radius+"px","font-size":ft+"px","text-anchor":"middle",innerHTML:n})]):a}},{key:"animate",value:function(t,e,i){return[t,{cx:e,cy:i},350,ut]}}]),e}(Ct),Tt=function(t){function i(t){et(this,i);var e=st(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.setupUnitRenderer(),e.zeroLine=e.height,e.preSetup(),e.setup(),e}return at(i,t),it(i,[{key:"configure",value:function(t){nt(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"configure",this).call(this),this.config.xAxisMode=t.xAxisMode,this.config.yAxisMode=t.yAxisMode}},{key:"preSetup",value:function(){}},{key:"setupUnitRenderer",value:function(){var t=this.rawChartArgs.options;this.unitRenderers={bar:new Lt(t),line:new Ot(t)}}},{key:"setHorizontalMargin",value:function(){this.translateXLeft=60,this.translateXRight=60}},{key:"checkData",value:function(t){return!0}},{key:"getFirstUpdateData",value:function(t){}},{key:"setupConstants",value:function(){var t=this;this.state={xAxisLabels:[],xAxisPositions:[],xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode},this.data.datasets.map(function(e){e.chartType||(e.chartType=t.type)}),this.prepareYAxis()}},{key:"prepareData",value:function(t){var e=this.state;e.xAxisLabels=t.labels||[],e.datasetLength=e.xAxisLabels.length;var i=new Array(e.datasetLength).fill(0);e.datasets=t.datasets,t.datasets||(e.datasets=[{values:i}]),e.datasets.map(function(t,n){var a=t.values;a=a?(a=a.map(function(t){return isNaN(t)?0:t})).length>e.datasetLength?a.slice(0,e.datasetLength):r(a,e.datasetLength-a.length,0):i,t.index=n}),e.noOfDatasets=e.datasets.length,e.yMarkers=t.yMarkers,e.yRegions=t.yRegions}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"calc",value:function(){var t=this.state;t.xAxisLabels=this.data.labels,this.calcXPositions(),t.datasetsLabels=this.data.datasets.map(function(t){return t.name}),this.setYAxis(),this.calcYUnits(),this.calcYMaximums(),this.calcYRegions(),this.configUnits()}},{key:"setYAxis",value:function(){this.calcYAxisParameters(this.state.yAxis,this.getAllYValues(),"line"===this.type),this.state.zeroLine=this.state.yAxis.zeroLine}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return s(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisParameters",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"false";t.labels=H(e,i);var n=t.labels;t.scaleMultiplier=this.height/B(n);var a=F(n)*t.scaleMultiplier;t.zeroLine=this.height-X(n)*a,t.positions=n.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.datasets.map(function(e){e.positions=e.values.map(function(e){return s(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})}),this.barOptions&&this.barOptions.stacked&&t.datasets.map(function(e,i){e.cumulativePositions=e.cumulativeYs.map(function(e){return s(t.yAxis.zeroLine-e*t.yAxis.scaleMultiplier)})})}},{key:"calcYMaximums",value:function(){var t=this.state;if(this.barOptions&&this.barOptions.stacked)return void(t.yExtremes=t.datasets[t.datasets.length-1].cumulativePositions);t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){e.positions.map(function(e,i){e0)for(var l=0;l0)for(var l=0;l0&&(t=z(r,s,i.colors[e],i.config.heatline,i.config.regionFill),o.textContent="",t.map(function(t){return o.appendChild(t)}));var d=a.map(function(t,e){return n[e]+","+t});i.elementsToAnimate=i.elementsToAnimate.concat(i.renderer.animatepath(t,d.join("L")))}})}},{key:"getYMarkerLines",value:function(){var t=this;return this.data.yMarkers?this.data.yMarkers.map(function(e,i){return new ChartComponent({layerClass:"y-markers",setData:function(){},makeElements:function(){return t.state.yMarkers.map(function(e){return t.renderer.yMarker(e.value,e.name,{pos:"right",mode:"span",lineType:e.type})})},animate:function(){}})}):[]}},{key:"getYRegions",value:function(){var t=this;return this.data.yRegions?this.data.yRegions.map(function(e,i){return new ChartComponent({layerClass:"y-regions",setData:function(){},makeElements:function(){return t.state.yRegions.map(function(e){return t.renderer.yRegion(e.start,e.end,e.name)})},animate:function(){}})}):[]}},{key:"refreshRenderer",value:function(){var t=this,e={totalHeight:this.height,totalWidth:this.width,xAxisMode:this.config.xAxisMode,yAxisMode:this.config.yAxisMode,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth};this.renderer?this.renderer.refreshState(e):this.renderer=new yt(e);var i={totalHeight:this.height,totalWidth:this.width,zeroLine:this.state.zeroLine,unitWidth:this.state.unitWidth,noOfDatasets:this.state.noOfDatasets};i=Object.assign(i,this.rawChartArgs.options),Object.keys(this.unitRenderers).map(function(e){i.options=t[e+"Options"],t.unitRenderers[e].refreshMeta(i)})}},{key:"bindTooltip",value:function(){var t=this;this.chartWrapper.addEventListener("mousemove",function(i){var n=e(t.chartWrapper),a=i.pageX-n.left-t.translateXLeft;i.pageY-n.top-t.translateY=0;s--){var r=i.xAxisPositions[s];if(t>r-i.unitWidth/2){var o=r+this.translateXLeft,l=i.yExtremes[s]+this.translateY,h=i.datasets.map(function(t,i){return{title:t.title,value:a?e.formatTooltipY(t.values[s]):t.values[s],color:e.colors[i]}});this.tip.set_values(o,l,n[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(n){var a=n.slice(0,n.length-1);e[a]=i[n][t]}),e.label=this.xAxisLabels[t],e}},{key:"setCurrentDataPoint",value:function(t){(t=parseInt(t))<0&&(t=0),t>=this.xAxisLabels.length&&(t=this.xAxisLabels.length-1),t!==this.current_index&&(this.current_index=t,$.fire(this.parent,"data-select",this.getDataPoint()))}},{key:"addDataPoint",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.state.datasetLength;nt(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"addDataPoint",this).call(this,t,e,n),this.data.labels.splice(n,0,t),this.data.datasets.map(function(t,i){t.values.splice(n,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;nt(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}(At),Pt=function(t){function e(t){et(this,e);var i=st(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 at(e,t),it(e,[{key:"setup_values",value:function(){nt(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){et(this,e);var i=st(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.type="line",Object.getPrototypeOf(i)!==e.prototype?st(i):(i.setup(),i)}return at(e,t),it(e,[{key:"configure",value:function(t){nt(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}(Tt)),Dt=function(t){function e(t){return et(this,e),st(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return at(e,t),it(e,[{key:"preSetup",value:function(){this.type="multiaxis"}},{key:"setHorizontalMargin",value:function(){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){nt(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"prepareData",this).call(this,t);var i=0,n=0;this.state.datasets.forEach(function(t,e){t.yAxis={position:t.axisPosition,index:"left"===t.axisPosition?i++:n++}})}},{key:"configure",value:function(t){nt(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 n="left"===e.yAxis.position?-1*e.yAxis.index*60:t.width+60*e.yAxis.index;t.renderer.xLine(n,"",{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 n={pos:e.position,mode:"tick",offset:60*e.index,stroke:t.colors[i]};return e.positions.map(function(i,a){return t.renderer.yLine(i,e.labels[a],n)})},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],n=t.unitArgs;return t.renderer.setZeroline(e.yAxis.zeroLine),e.positions.map(function(e,a){return t.renderer[n.type](t.state.xAxisPositions[a],e,n.args,t.colors[i],a,i,t.state.datasetLength)})},animate:function(e){var n=t.state.datasets[i],a=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 n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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,n){var a=t.create("div",{className:"progress-bar",inside:e.percentageBar,styles:{background:e.colors[n],width:100*i/e.grand_total+"%"}});e.slices.push(a)})}},{key:"calc",value:function(){}}]),i}(At),Wt=Math.PI/180,St=function(i){function n(t){et(this,n);var e=st(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t));return e.type="pie",e.elements_to_animate=null,e.hoverRadio=t.hoverRadio||.1,e.max_slices=10,e.max_legend_points=6,e.isAnimate=!1,e.startAngle=t.startAngle||0,e.clockWise=t.clockWise||!1,e.mouseMove=e.mouseMove.bind(e),e.mouseLeave=e.mouseLeave.bind(e),e.setup(),e}return at(n,i),it(n,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var n=0;return t.data.datasets.map(function(t){n+=t.values[i]}),[n,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,n=this.centerY,a=this.radius,s=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"renderComponents",value:function(t){var e=this,i=this.radius,a=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var s=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var r=180-this.startAngle;this.slice_totals.map(function(o,l){var h=r,c=o/e.grand_total*360,u=a?-c:c,p=r+=u,d=n.getPositionByAngle(h,i),f=n.getPositionByAngle(p,i),v=t&&s[l],y=void 0,g=void 0;t?(y=v?v.startPosition:d,g=v?v.endPosition:d):(y=d,g=f);var m=e.makeArcPath(y,g),x=k(m,"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:m}])}),t&&S(this.chartWrapper,this.svg,this.elements_to_animate)}},{key:"calTranslateByAngle",value:function(t){var e=this.radius,i=this.hoverRadio,a=n.getPositionByAngle(t.startAngle+t.angle/2,e);return"translate3d("+a.x*i+"px,"+a.y*i+"px,0)"}},{key:"hoverSlice",value:function(t,i,n,a){if(t){var s=this.colors[i];if(n){N(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=O(s,50);var r=e(this.svg),o=a.pageX-r.left+10,l=a.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 N(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=s}}},{key:"mouseMove",value:function(t){for(var e=t.target,i=this.curActiveSliceIndex,n=this.curActiveSlice,a=0;a0?this.formatted_labels:this.labels;this.legend_totals.map(function(n,a){var s=e.colors[a];n&&(t.create("div",{className:"stats",inside:e.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+i[a]+":\n\t\t\t\t\t"+n+"\n\t\t\t\t")})}}],[{key:"getPositionByAngle",value:function(t,e){return{x:Math.sin(t*Wt)*e,y:Math.cos(t*Wt)*e}}}]),n}(At),Et=function(t){function e(t){var i=t.start,n=void 0===i?"":i,a=t.domain,s=void 0===a?"":a,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;et(this,e);var y=st(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));y.type="heatmap",y.domain=s,y.subdomain=o,y.data=h,y.discrete_domains=u,y.count_label=d;var g=new Date;return y.start=n||K(g,365),v=v.slice(0,5),y.legend_colors=y.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],y.distribution_size=5,y.translateX=0,y}return at(e,t),it(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){T(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"setupConstants",value:function(){this.today=new Date,this.start||(this.start=new Date,this.start.setFullYear(this.start.getFullYear()-1)),this.first_week_start=new Date(this.start.toDateString()),this.last_week_start=new Date(this.today.toDateString()),7!==this.first_week_start.getDay()&&K(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&K(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=J(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=I(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()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=v}return[s,n]}},{key:"render_month_labels",value:function(){var t=this;this.months.shift(),this.month_start_points.shift(),this.months.pop(),this.month_start_points.pop(),this.month_start_points.map(function(e,i){var n=w("y-value-text",e+12,10,t.month_names[t.months[i]].substring(0,3));t.domain_label_group.appendChild(n)})}},{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"),n=e.target.getAttribute("data-date").split("-"),a=t.month_names[parseInt(n[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 "+a+" "+n[0]+", "+n[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}(At),zt={mixed:Tt,multiaxis:Dt,scatter:Pt,percentage:Nt,heatmap:Et,pie:St},Rt=function t(e){return et(this,t),Q(e.type,arguments[0])};return Rt}(); +//# 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 new file mode 100644 index 0000000..746fed6 --- /dev/null +++ b/dist/frappe-charts.min.iife.js.map @@ -0,0 +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/objects/ChartComponents.js","../src/js/objects/AxisChartControllers.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/charts/AxisChart.js","../src/js/utils/margins.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","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\n\t\t// In case of invisible bars\n\t\tif(height === 0) {\n\t\t\theight = totalHeight * MIN_BAR_PERCENT_HEIGHT;\n\t\t\ty -= height;\n\t\t}\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\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 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 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\txLine(x, label, options={}) {\n\t\tif(!options.pos) options.pos = 'bottom';\n\t\tif(!options.offset) options.offset = 0;\n\t\tif(!options.mode) options.mode = 'span';\n\t\tif(!options.stroke) options.stroke = BASE_LINE_COLOR;\n\t\tif(!options.className) options.className = '';\n\n\t\t// Draw X axis line in span/tick mode with optional label\n\t\t// \ty2(span)\n\t\t// \t\t\t\t\t\t|\n\t\t// \t\t\t\t\t\t|\n\t\t//\t\t\t\tx line\t|\n\t\t//\t\t\t\t\t\t|\n\t\t// \t\t\t\t\t \t|\n\t\t// ---------------------+-- y2(tick)\n\t\t//\t\t\t\t\t\t|\n\t\t//\t\t\t\t\t\t\ty1\n\n\t\tlet y1 = this.totalHeight + AXIS_TICK_LENGTH;\n\t\tlet y2 = options.mode === 'span' ? -1 * AXIS_TICK_LENGTH : this.totalHeight;\n\n\t\tif(options.mode === 'tick' && options.pos === 'top') {\n\t\t\t// top axis ticks\n\t\t\ty1 = -1 * AXIS_TICK_LENGTH;\n\t\t\ty2 = 0;\n\t\t}\n\n\t\treturn makeVertLine(x, label, y1, y2, {\n\t\t\tstroke: options.stroke,\n\t\t\tclassName: options.className,\n\t\t\tlineType: options.lineType\n\t\t});\n\t}\n\n\n\n\n\txMarker() {}\n\tyMarker(y, label, options={}) {\n\t\tlet labelSvg = createSVG('text', {\n\t\t\tclassName: 'chart-label',\n\t\t\tx: this.totalWidth - getStringWidth(label, 5) - LABEL_MARGIN,\n\t\t\ty: y - FONT_SIZE - 2,\n\t\t\tdy: (FONT_SIZE / 2) + 'px',\n\t\t\t'font-size': FONT_SIZE + 'px',\n\t\t\t'text-anchor': 'start',\n\t\t\tinnerHTML: label+\"\"\n\t\t});\n\n\t\tlet line = makeHoriLine(y, '', 0, this.totalWidth, {\n\t\t\tstroke: options.stroke || BASE_LINE_COLOR,\n\t\t\tclassName: options.className || '',\n\t\t\tlineType: options.lineType\n\t\t});\n\n\t\tline.appendChild(labelSvg);\n\n\t\treturn line;\n\t}\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\tyRegion(y1, y2, label) {\n\t\t// return a group\n\n\t\tlet rect = 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\tlet upperBorder = createSVG('line', {\n\t\t\tclassName: 'line-horizontal',\n\t\t\tx1: 0,\n\t\t\tx2: this.totalWidth,\n\t\t\ty1: y2,\n\t\t\ty2: y2,\n\t\t\tstyles: {\n\t\t\t\tstroke: BASE_LINE_COLOR\n\t\t\t}\n\t\t});\n\t\tlet lowerBorder = createSVG('line', {\n\t\t\tclassName: 'line-horizontal',\n\t\t\tx1: 0,\n\t\t\tx2: this.totalWidth,\n\t\t\ty1: y1,\n\t\t\ty2: y1,\n\t\t\tstyles: {\n\t\t\t\tstroke: BASE_LINE_COLOR\n\t\t\t}\n\t\t});\n\n\t\tlet labelSvg = createSVG('text', {\n\t\t\tclassName: 'chart-label',\n\t\t\tx: this.totalWidth - getStringWidth(label, 4.5) - LABEL_MARGIN,\n\t\t\ty: y2 - FONT_SIZE - 2,\n\t\t\tdy: (FONT_SIZE / 2) + 'px',\n\t\t\t'font-size': FONT_SIZE + 'px',\n\t\t\t'text-anchor': 'start',\n\t\t\tinnerHTML: label+\"\"\n\t\t});\n\n\t\tlet region = createSVG('g', {});\n\n\t\tregion.appendChild(rect);\n\t\tregion.appendChild(upperBorder);\n\t\tregion.appendChild(lowerBorder);\n\t\tregion.appendChild(labelSvg);\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 { makeSVGGroup } from '../utils/draw';\nimport { yLine } from '../utils/draw';\nimport { equilizeNoOfElements } from '../utils/draw-utils';\nimport { Animator, translateHoriLine } from '../utils/animate';\n\nclass ChartComponent {\n\tconstructor({\n\t\tlayerClass = '',\n\t\tlayerTransform = '',\n\t\tparent,\n\t\tconstants,\n\t\tdata,\n\n\t\t// called on update\n\t\tpreMake,\n\t\tmakeElements,\n\t\tpostMake,\n\t\tanimateElements\n\t}) {\n\t\tthis.parent = parent;\n\t\tthis.layerClass = layerClass;\n\t\tthis.layerTransform = layerTransform;\n\t\tthis.constants = constants;\n\n\t\tthis.preMake = preMake;\n\t\tthis.makeElements = makeElements;\n\t\tthis.postMake = postMake;\n\n\t\tthis.animateElements = animateElements;\n\n\t\tthis.store = [];\n\t\tthis.layer = makeSVGGroup(this.parent, this.layerClass, this.layerTransform);\n\n\t\tthis.data = data;\n\n\t\tthis.make();\n\t}\n\n\trefresh(data) {\n\t\tthis.data = data;\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\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\nexport function getYAxisComponent(parent, constants, initData) {\n\treturn new ChartComponent({\n\t\tparent: parent,\n\t\tlayerClass: 'y axis',\n\t\tconstants: constants,\n\t\tdata: initData,\n\t\tmakeElements: function(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: function(newData) {\n\t\t\tlet newPos = newData.positions;\n\t\t\tlet newLabels = newData.labels;\n\n\t\t\tlet oldPos = this.oldData.positions;\n\t\t\tlet oldLabels = this.oldData.labels;\n\n\t\t\tlet extra = newPos.length - oldPos.length;\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","import { getBarHeightAndYAttr } from '../utils/draw-utils';\nimport { createSVG, makePath, makeGradient, wrapInSVGGroup, FONT_SIZE } from '../utils/draw';\nimport { STD_EASING, UNIT_ANIM_DUR, MARKER_LINE_ANIM_DUR, PATH_ANIM_DUR } from '../utils/animate';\n\nconst MIN_BAR_PERCENT_HEIGHT = 0.01;\n\nclass AxisChartController {\n\tconstructor(meta) {\n\t\t// TODO: make configurable passing args\n\t\tthis.meta = meta || {};\n\t\tthis.setupArgs();\n\t}\n\n\tsetupArgs() {\n\t\tthis.consts = {};\n\t}\n\n\tsetup() {}\n\n\trefreshMeta(meta) {\n\t\tthis.meta = Object.assign((this.meta || {}), meta);\n\t}\n\n\tdraw() {}\n\tanimate() {}\n}\n\nexport class AxisController extends AxisChartController {\n\tconstructor(meta) {\n\t\tsuper(meta);\n\t}\n\n\tdraw(x, y, color, index) {\n\t\treturn createSVG('circle', {\n\t\t\tstyle: `fill: ${color}`,\n\t\t\t'data-point-index': index,\n\t\t\tcx: x,\n\t\t\tcy: y,\n\t\t\tr: this.consts.radius\n\t\t});\n\t}\n\n\tanimate(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\nexport class BarChartController extends AxisChartController {\n\tconstructor(meta) {\n\t\tsuper(meta);\n\t}\n\n\tsetupArgs() {\n\t\tthis.consts = {\n\t\t\tspaceRatio: 0.5,\n\t\t\tminHeight: this.meta.totalHeight * MIN_BAR_PERCENT_HEIGHT\n\t\t};\n\t}\n\n\trefreshMeta(meta) {\n\t\tif(meta) {\n\t\t\tsuper.refreshMeta(meta);\n\t\t}\n\t\tlet m = this.meta;\n\t\tthis.consts.barsWidth = m.unitWidth - m.unitWidth * this.consts.spaceRatio;\n\n\t\tthis.consts.width = this.consts.barsWidth / (m.options && m.options.stacked\n\t\t\t? m.options.stacked : m.noOfDatasets);\n\t}\n\n\tdraw(x, yTop, color, label='', index=0, offset=0) {\n\t\tlet [height, y] = getBarHeightAndYAttr(yTop, this.meta.zeroLine);\n\n\t\tlet rect = createSVG('rect', {\n\t\t\tclassName: `bar mini`,\n\t\t\tstyle: `fill: ${color}`,\n\t\t\t'data-point-index': index,\n\t\t\tx: x - this.consts.barsWidth/2,\n\t\t\ty: y - offset,\n\t\t\twidth: this.consts.width,\n\t\t\theight: height || this.consts.minHeight\n\t\t});\n\n\t\tif(!label && !label.length) {\n\t\t\treturn rect;\n\t\t} else {\n\t\t\tlet text = createSVG('text', {\n\t\t\t\tclassName: 'data-point-value',\n\t\t\t\tx: x,\n\t\t\t\ty: y - offset,\n\t\t\t\tdy: (FONT_SIZE / 2 * -1) + 'px',\n\t\t\t\t'font-size': FONT_SIZE + 'px',\n\t\t\t\t'text-anchor': 'middle',\n\t\t\t\tinnerHTML: label\n\t\t\t});\n\n\t\t\treturn wrapInSVGGroup([rect, text]);\n\t\t}\n\t}\n\n\tanimate(bar, x, yTop, index, noOfDatasets) {\n\t\tlet start = x - this.meta.unitWidth/4;\n\t\tlet width = (this.meta.unitWidth/2)/noOfDatasets;\n\t\tlet [height, y] = getBarHeightAndYAttr(yTop, this.meta.zeroLine, this.meta.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\nexport class LineChartController extends AxisChartController {\n\tconstructor(meta) {\n\t\tsuper(meta);\n\t}\n\n\tsetupArgs() {\n\t\tthis.consts = {\n\t\t\tradius: this.meta.dotSize || 4\n\t\t};\n\t}\n\n\tdraw(x, y, color, label='', index=0) {\n\t\tlet dot = createSVG('circle', {\n\t\t\tstyle: `fill: ${color}`,\n\t\t\t'data-point-index': index,\n\t\t\tcx: x,\n\t\t\tcy: y,\n\t\t\tr: this.consts.radius\n\t\t});\n\n\t\tif(!label && !label.length) {\n\t\t\treturn dot;\n\t\t} else {\n\t\t\tlet text = createSVG('text', {\n\t\t\t\tclassName: 'data-point-value',\n\t\t\t\tx: x,\n\t\t\t\ty: y,\n\t\t\t\tdy: (FONT_SIZE / 2 * -1 - this.consts.radius) + 'px',\n\t\t\t\t'font-size': FONT_SIZE + 'px',\n\t\t\t\t'text-anchor': 'middle',\n\t\t\t\tinnerHTML: label\n\t\t\t});\n\n\t\t\treturn wrapInSVGGroup([dot, text]);\n\t\t}\n\t}\n\n\tanimate(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\nexport function getPaths(yList, xList, color, heatline=false, regionFill=false) {\n\tlet pointsList = yList.map((y, i) => (xList[i] + ',' + y));\n\tlet pointsStr = pointsList.join(\"L\");\n\tlet path = makePath(\"M\"+pointsStr, 'line-graph-path', color);\n\n\t// HeatLine\n\tif(heatline) {\n\t\tlet gradient_id = makeGradient(this.svgDefs, color);\n\t\tpath.style.stroke = `url(#${gradient_id})`;\n\t}\n\n\tlet components = [path];\n\n\t// Region\n\tif(regionFill) {\n\t\tlet gradient_id_region = makeGradient(this.svgDefs, color, true);\n\n\t\tlet zeroLine = this.state.yAxis.zeroLine;\n\t\t// TODO: use zeroLine OR minimum\n\t\tlet pathStr = \"M\" + `0,${zeroLine}L` + pointsStr + `L${this.width},${zeroLine}`;\n\t\tcomponents.push(makePath(pathStr, `region-fill`, 'none', `url(#${gradient_id_region})`));\n\t}\n\n\treturn components;\n}\n\n// class BarChart extends AxisChart {\n// \tconstructor(args) {\n// \t\tsuper(args);\n// \t\tthis.type = 'bar';\n// \t\tthis.setup();\n// \t}\n\n// \tconfigure(args) {\n// \t\tsuper.configure(args);\n// \t\tthis.config.xAxisMode = args.xAxisMode || 'tick';\n// \t\tthis.config.yAxisMode = args.yAxisMode || 'span';\n// \t}\n\n// \t// =================================\n\n// \tmakeOverlay() {\n// \t\t// Just make one out of the first element\n// \t\tlet index = this.xAxisLabels.length - 1;\n// \t\tlet unit = this.y[0].svg_units[index];\n// \t\tthis.setCurrentDataPoint(index);\n\n// \t\tif(this.overlay) {\n// \t\t\tthis.overlay.parentNode.removeChild(this.overlay);\n// \t\t}\n// \t\tthis.overlay = unit.cloneNode();\n// \t\tthis.overlay.style.fill = '#000000';\n// \t\tthis.overlay.style.opacity = '0.4';\n// \t\tthis.drawArea.appendChild(this.overlay);\n// \t}\n\n// \tbindOverlay() {\n// \t\t// on event, update overlay\n// \t\tthis.parent.addEventListener('data-select', (e) => {\n// \t\t\tthis.update_overlay(e.svg_unit);\n// \t\t});\n// \t}\n\n// \tbind_units(units_array) {\n// \t\tunits_array.map(unit => {\n// \t\t\tunit.addEventListener('click', () => {\n// \t\t\t\tlet index = unit.getAttribute('data-point-index');\n// \t\t\t\tthis.setCurrentDataPoint(index);\n// \t\t\t});\n// \t\t});\n// \t}\n\n// \tupdate_overlay(unit) {\n// \t\tlet attributes = [];\n// \t\tObject.keys(unit.attributes).map(index => {\n// \t\t\tattributes.push(unit.attributes[index]);\n// \t\t});\n\n// \t\tattributes.filter(attr => attr.specified).map(attr => {\n// \t\t\tthis.overlay.setAttribute(attr.name, attr.nodeValue);\n// \t\t});\n\n// \t\tthis.overlay.style.fill = '#000000';\n// \t\tthis.overlay.style.opacity = '0.4';\n// \t}\n\n// \tonLeftArrow() {\n// \t\tthis.setCurrentDataPoint(this.currentIndex - 1);\n// \t}\n\n// \tonRightArrow() {\n// \t\tthis.setCurrentDataPoint(this.currentIndex + 1);\n// \t}\n// }\n\n","function 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 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'