From b3ca8f08199f4897f92fdb7c359bc82f2ec3b544 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 1 Jan 2018 20:29:13 +0530 Subject: [PATCH] render multiple y axis --- dist/frappe-charts.esm.js | 560 +++++++++++++++++----------- dist/frappe-charts.min.cjs.js | 2 +- dist/frappe-charts.min.css | 2 +- dist/frappe-charts.min.esm.js | 2 +- dist/frappe-charts.min.iife.js | 2 +- docs/assets/js/frappe-charts.min.js | 2 +- docs/assets/js/index.js | 26 +- src/js/chart.js | 2 + src/js/charts/AxisChart.js | 239 +++++++----- src/js/charts/BaseChart.js | 43 ++- src/js/charts/MultiAxisChart.js | 100 +++++ src/js/objects/ChartComponent.js | 15 +- src/js/utils/draw.js | 122 ++++-- src/js/utils/margins.js | 1 + src/scss/charts.scss | 12 +- 15 files changed, 713 insertions(+), 417 deletions(-) create mode 100644 src/js/charts/MultiAxisChart.js create mode 100644 src/js/utils/margins.js diff --git a/dist/frappe-charts.esm.js b/dist/frappe-charts.esm.js index 88cf3e4..48c79cd 100644 --- a/dist/frappe-charts.esm.js +++ b/dist/frappe-charts.esm.js @@ -281,6 +281,7 @@ function getBarHeightAndYAttr(yTop, zeroLine, totalHeight) { const AXIS_TICK_LENGTH = 6; const LABEL_MARGIN = 4; const FONT_SIZE = 10; +const BASE_LINE_COLOR = '#dadada'; function $$1(expr, con) { return typeof expr === "string"? (con || document).querySelector(expr) : expr || null; @@ -416,20 +417,22 @@ function makeText(className, x, y, content) { }); } -function makeVertXLine(x, label, totalHeight, mode, stroke='#dadada') { - let height = mode === 'span' ? -1 * AXIS_TICK_LENGTH : totalHeight; - +function makeVertLine(x, label, y1, y2, options={}) { + if(!options.stroke) options.stroke = BASE_LINE_COLOR; let l = createSVG('line', { + className: 'line-vertical ' + options.className, x1: 0, x2: 0, - y1: totalHeight + AXIS_TICK_LENGTH, - y2: height, - stroke: stroke + y1: y1, + y2: y2, + styles: { + stroke: options.stroke + } }); let text = createSVG('text', { x: 0, - y: totalHeight + AXIS_TICK_LENGTH + LABEL_MARGIN, + y: y1 > y2 ? y1 + LABEL_MARGIN : y1 - LABEL_MARGIN - FONT_SIZE, dy: FONT_SIZE + 'px', 'font-size': FONT_SIZE + 'px', 'text-anchor': 'middle', @@ -446,50 +449,34 @@ function makeVertXLine(x, label, totalHeight, mode, stroke='#dadada') { return line; } -function makeHoriYLine(y, label, totalWidth, mode, pos='left') { - let lineType = ''; - let w2 = mode === 'span' ? totalWidth + AXIS_TICK_LENGTH : 0; - - // temp : works correctly - let x1, x2, textX, anchor; - if(mode === 'tick') { - if(pos === 'right') { - x1 = totalWidth; - x2 = totalWidth + AXIS_TICK_LENGTH; - textX = totalWidth + AXIS_TICK_LENGTH + LABEL_MARGIN; - anchor = 'start'; - } else { - x1 = -1 * AXIS_TICK_LENGTH; - x2 = w2; - textX = -1 * (LABEL_MARGIN + AXIS_TICK_LENGTH); - anchor = 'end'; - } - } else { - x1 = -1 * AXIS_TICK_LENGTH; - x2 = w2; - textX = -1 * (LABEL_MARGIN + AXIS_TICK_LENGTH); - anchor = 'end'; - } +function makeHoriLine(y, label, x1, x2, options={}) { + if(!options.stroke) options.stroke = BASE_LINE_COLOR; + if(!options.lineType) options.lineType = ''; + let className = 'line-horizontal ' + options.className + + (options.lineType === "dashed" ? "dashed": ""); let l = createSVG('line', { - className: lineType === "dashed" ? "dashed": "", + className: className, x1: x1, x2: x2, y1: 0, - y2: 0 + y2: 0, + styles: { + stroke: options.stroke + } }); let text = createSVG('text', { - x: textX, + x: x1 < x2 ? x1 - LABEL_MARGIN : x1 + LABEL_MARGIN, y: 0, dy: (FONT_SIZE / 2 - 2) + 'px', 'font-size': FONT_SIZE + 'px', - 'text-anchor': anchor, + 'text-anchor': x1 < x2 ? 'end' : 'start', innerHTML: label+"" }); let line = createSVG('g', { - transform: `translate(0, ${y})`, + transform: `translate(0, ${ y })`, 'stroke-opacity': 1 }); @@ -517,6 +504,10 @@ class AxisChartRenderer { this.yAxisMode = state.yAxisMode; } + setZeroline(zeroLine) { + this.zeroLine = zeroLine; + } + bar(x, yTop, args, color, index, datasetIndex, noOfDatasets, prevX, prevY) { let totalWidth = this.unitWidth - args.spaceWidth; @@ -553,14 +544,61 @@ class AxisChartRenderer { }); } - // temp: stroke - xLine(x, label, pos='bottom', stroke='', mode=this.xAxisMode) { + 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.stroke) options.stroke = BASE_LINE_COLOR; + if(!options.className) options.className = ''; + // Draw X axis line in span/tick mode with optional label - return makeVertXLine(x, label, this.totalHeight, mode); + // y2(span) + // | + // | + // x line | + // | + // | + // ---------------------+-- y2(tick) + // | + // y1 + + let y1 = this.totalHeight + AXIS_TICK_LENGTH; + let y2 = options.mode === 'span' ? -1 * AXIS_TICK_LENGTH : this.totalHeight; + + if(options.mode === 'tick' && options.pos === 'top') { + // top axis ticks + y1 = -1 * AXIS_TICK_LENGTH; + y2 = 0; + } + + return makeVertLine(x, label, y1, y2, { + stroke: options.stroke, + className: options.className + }); } - yLine(y, label, pos='left', mode=this.yAxisMode) { - return makeHoriYLine(y, label, this.totalWidth, mode, pos); + 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 + }); } xMarker() {} @@ -688,6 +726,7 @@ class BaseChart { this.parent = typeof parent === 'string' ? document.querySelector(parent) : parent; this.title = title; this.subtitle = subtitle; + this.argHeight = height; this.isNavigable = isNavigable; if(this.isNavigable) { @@ -702,7 +741,6 @@ class BaseChart { // showLegend, which then all functions will check this.setColors(); - this.setMargins(args); // constants this.config = { @@ -735,12 +773,19 @@ class BaseChart { this.colors = this.colors.map(color => getColor(color)); } - setMargins(args) { - let height = args.height; + setMargins() { + // TODO: think for all + let height = this.argHeight; this.baseHeight = height; - this.height = height - 40; - this.translateX = 60; - this.translateY = 10; + this.height = height - 40; // change + this.translateY = 20; + + this.setHorizontalMargin(); + } + + setHorizontalMargin() { + this.translateXLeft = 60; + this.translateXRight = 40; } validate(){ @@ -780,7 +825,10 @@ class BaseChart { _setup() { this.bindWindowEvents(); this.setupConstants(); + this.prepareData(); this.setupComponents(); + + this.setMargins(); this.makeContainer(); this.makeTooltip(); // without binding this.draw(true); @@ -864,15 +912,16 @@ class BaseChart { // } // }); this.baseWidth = getElementContentWidth(this.parent) - outerAnnotationsWidth; - this.width = this.baseWidth - this.translateX * 2; + this.width = this.baseWidth - (this.translateXLeft + this.translateXRight); } refresh() { //?? refresh? this.oldState = this.state ? Object.assign({}, this.state) : {}; + this.intermedState = {}; + this.prepareData(); this.reCalc(); this.refreshRenderer(); - this.refreshComponents(); } makeChartArea() { @@ -887,7 +936,7 @@ class BaseChart { this.drawArea = makeSVGGroup( this.svg, this.type + '-chart', - `translate(${this.translateX}, ${this.translateY})` + `translate(${this.translateXLeft}, ${this.translateY})` ); } @@ -905,7 +954,6 @@ class BaseChart { return; } this.intermedState = this.calcIntermedState(); - this.refreshComponents(); this.animateComponents(); setTimeout(() => { this.renderComponents(); @@ -914,22 +962,15 @@ class BaseChart { // (opt, should not redraw if still in animate?) } - calcIntermedState() {} + calcIntermedState() { + this.intermedState = {}; + } // 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()); } animateComponents() { this.components.forEach(c => c.animate()); } - refreshComponents() { - let args = { - chartState: this.state, - oldChartState: this.oldState, - intermedState: this.intermedState, - chartRenderer: this.renderer - }; - this.components.forEach(c => c.refresh(args)); - } renderLegend() {} @@ -979,36 +1020,28 @@ class BaseChart { } } +const Y_AXIS_MARGIN = 60; + class ChartComponent { constructor({ layerClass = '', layerTransform = '', make, - argsKeys, animate }) { this.layerClass = layerClass; // 'y axis' this.layerTransform = layerTransform; this.make = make; - this.argsKeys = argsKeys;//['yAxisPositions', 'yAxisLabels']; this.animate = animate; this.layer = undefined; this.store = []; //[[]] depends on indexed } - refresh(args) { - this.chartState = args.chartState; - this.oldChartState = args.oldChartState; - this.intermedState = args.intermedState; - - this.chartRenderer = args.chartRenderer; - } + refresh(args) {} render() { - let args = this.argsKeys.map(key => this.chartState[key]); - args.unshift(this.chartRenderer); - this.store = this.make(...args); + this.store = this.make(); this.layer.textContent = ''; this.store.forEach(element => { @@ -1026,53 +1059,6 @@ class ChartComponent { } // Indexed according to dataset -class IndexedChartComponent extends ChartComponent { - constructor(args) { - super(args); - this.stores = []; - } - - refresh(args) { - super.refresh(args); - this.totalIndices = this.chartState[this.argsKeys[0]].length; - } - - makeLayer() { - super.makeLayer(); - this.layers = []; - for(var i = 0; i < this.totalIndices; i++) { - this.layers[i] = makeSVGGroup(this.layer, this.layerClass + '-' + i); - } - } - - addLayer() {} - - render() { - let datasetArrays = this.argsKeys.map(key => this.chartState[key]); - - // datasetArrays will have something like an array of X positions sets - // datasetArrays = [ - // xUnitPositions, yUnitPositions, colors, unitTypes, yUnitValues - // ] - // where xUnitPositions = [[0,0,0], [1,1,1]] - // i.e.: [ [[0,0,0], [1,1,1]], ... ] - for(var i = 0; i < this.totalIndices; i++) { - let args = datasetArrays.map(datasetArray => datasetArray[i]); - args.unshift(this.chartRenderer); - - args.push(i); - args.push(this.totalIndices); - - this.stores.push(this.make(...args)); - - let layer = this.layers[i]; - layer.textContent = ''; - this.stores[i].forEach(element => { - layer.appendChild(element); - }); - } - } -} const REPLACE_ALL_NEW_DUR = 250; @@ -1428,9 +1414,15 @@ class AxisChart extends BaseChart { this.is_series = args.is_series; this.format_tooltip_y = args.format_tooltip_y; this.format_tooltip_x = args.format_tooltip_x; + this.zeroLine = this.height; } + setHorizontalMargin() { + this.translateXLeft = Y_AXIS_MARGIN; + this.translateXRight = Y_AXIS_MARGIN; + } + checkData(data) { return true; } @@ -1441,7 +1433,10 @@ class AxisChart extends BaseChart { prepareData() { let s = this.state; + s.xAxisLabels = this.data.labels || []; + s.xAxisPositions = []; + s.datasetLength = s.xAxisLabels.length; let zeroArray = new Array(s.datasetLength).fill(0); @@ -1474,6 +1469,16 @@ class AxisChart extends BaseChart { }); s.noOfDatasets = s.datasets.length; + + // s.yAxis = []; + this.prepareYAxis(); + } + + prepareYAxis() { + this.state.yAxis = { + labels: [], + positions: [] + }; } reCalc() { @@ -1484,15 +1489,15 @@ class AxisChart extends BaseChart { this.calcXPositions(); // Y - s.datasetsLabels = this.data.datasets.map(d => d.label); + s.datasetsLabels = this.data.datasets.map(d => d.name); // s.yUnitValues = [[]]; indexed component // s.yUnitValues = [[[12, 34, 68], [10, 5, 46]], [[20, 20, 20]]]; // array of indexed components s.yUnitValues = s.datasets.map(d => d.values); // indexed component - s.yAxisLabels = calcIntervals(this.getAllYValues(), this.type === 'line'); - this.calcYAxisPositions(); - this.calcYUnitPositions(); + this.setYAxis(); + + this.calcYUnits(); // should be state this.configUnits(); @@ -1501,6 +1506,11 @@ class AxisChart extends BaseChart { s.unitTypes = s.datasets.map(d => d.unitArgs ? d.unitArgs : this.state.unitArgs); } + setYAxis() { + this.calcYAxisParameters(this.state.yAxis, this.getAllYValues(), this.type === 'line'); + this.state.zeroLine = this.state.yAxis.zeroLine; + } + calcXPositions() { let s = this.state; this.setUnitWidthAndXOffset(); @@ -1510,18 +1520,18 @@ class AxisChart extends BaseChart { s.xUnitPositions = new Array(s.noOfDatasets).fill(s.xAxisPositions); } - calcYAxisPositions() { - let s = this.state; - const yPts = s.yAxisLabels; + calcYAxisParameters(yAxis, dataValues, withMinimum = 'false') { + yAxis.labels = calcIntervals(dataValues, withMinimum); + const yPts = yAxis.labels; - s.scaleMultiplier = this.height / getValueRange(yPts); - const intervalHeight = getIntervalSize(yPts) * s.scaleMultiplier; - s.zeroLine = this.height - (getZeroIndex(yPts) * intervalHeight); + yAxis.scaleMultiplier = this.height / getValueRange(yPts); + const intervalHeight = getIntervalSize(yPts) * yAxis.scaleMultiplier; + yAxis.zeroLine = this.height - (getZeroIndex(yPts) * intervalHeight); - s.yAxisPositions = yPts.map(d => s.zeroLine - d * s.scaleMultiplier); + yAxis.positions = yPts.map(d => yAxis.zeroLine - d * yAxis.scaleMultiplier); } - calcYUnitPositions() { + calcYUnits() { let s = this.state; s.yUnitPositions = s.yUnitValues.map(values => values.map(val => floatTwo(s.zeroLine - val * s.scaleMultiplier)) @@ -1557,6 +1567,105 @@ class AxisChart extends BaseChart { // } + setupValues() {} + + setupComponents() { + // temp : will be an indexedchartcomponent + // this.yAxisAux = new ChartComponent({ + // layerClass: 'y axis aux', + // make: (renderer, positions, values) => { + // positions = [0, 70, 140, 270]; + // values = [300, 200, 100, 0]; + // return positions.map((position, i) => renderer.yLine(position, values[i], 'right')); + // }, + // animate: () => {} + // }); + + this.setupYAxesComponents(); + + this.xAxis = new ChartComponent({ + layerClass: 'x axis', + make: () => { + let s = this.state; + return s.xAxisPositions.map((position, i) => + this.renderer.xLine(position, s.xAxisLabels[i], {pos:'top'}) + ); + }, + // animate: (animator, lines, oldX, newX) => { + // lines.map((xLine, i) => { + // elements_to_animate.push(animator.verticalLine( + // xLine, newX[i], oldX[i] + // )); + // }); + // } + }); + + // this.dataUnits = new IndexedChartComponent({ + // layerClass: 'dataset-units', + // make: (renderer, xPosSet, yPosSet, color, unitType, + // yValueSet, datasetIndex, noOfDatasets) => {; + + // let unitSet = yPosSet.map((y, i) => { + // return renderer[unitType.type]( + // xPosSet[i], + // y, + // unitType.args, + // color, + // i, + // datasetIndex, + // noOfDatasets + // ); + // }); + + // if(this.type === 'line') { + // let pointsList = yPosSet.map((y, i) => (xPosSet[i] + ',' + y)); + // let pointsStr = pointsList.join("L"); + + // unitSet.unshift(makePath("M"+pointsStr, 'line-graph-path', color)); + // } + + // return unitSet; + // }, + // argsKeys: ['xUnitPositions', 'yUnitPositions', + // 'colors', 'unitTypes', 'yUnitValues'], + // animate: () => {} + // }); + + // TODO: rebind new units + // if(this.isNavigable) { + // this.bind_units(units_array); + // } + + this.yMarkerLines = {}; + this.xMarkerLines = {}; + + // Marker Regions + + this.components = [ + // temp + // this.yAxesAux, + ...this.yAxesComponents, + this.xAxis, + // this.yMarkerLines, + // this.xMarkerLines, + + // this.dataUnits, + ]; + } + + setupYAxesComponents() { + this.yAxesComponents = [ new ChartComponent({ + layerClass: 'y axis', + make: () => { + let s = this.state; + return s.yAxis.positions.map((position, i) => + this.renderer.yLine(position, s.yAxis.labels[i], {pos:'right'}) + ); + }, + animate: () => {} + })]; + } + refreshRenderer() { // These args are basically the current state of the chart, // with constant and alive params mixed @@ -1577,95 +1686,6 @@ class AxisChart extends BaseChart { } } - setupComponents() { - // temp : will be an indexedchartcomponent - // this.yAxisAux = new ChartComponent({ - // layerClass: 'y axis aux', - // make: (renderer, positions, values) => { - // positions = [0, 70, 140, 270]; - // values = [300, 200, 100, 0]; - // return positions.map((position, i) => renderer.yLine(position, values[i], 'right')); - // }, - // argsKeys: ['yAxisPositions', 'yAxisLabels'], - // animate: () => {} - // }); - - this.yAxis = new ChartComponent({ - layerClass: 'y axis', - make: (renderer, positions, values) => { - return positions.map((position, i) => renderer.yLine(position, values[i])); - }, - argsKeys: ['yAxisPositions', 'yAxisLabels'], - animate: () => {} - }); - - this.xAxis = new ChartComponent({ - layerClass: 'x axis', - make: (renderer, positions, values) => { - return positions.map((position, i) => renderer.xLine(position, values[i])); - }, - argsKeys: ['xAxisPositions', 'xAxisLabels'], - animate: (animator, lines, oldX, newX) => { - lines.map((xLine, i) => { - elements_to_animate.push(animator.verticalLine( - xLine, newX[i], oldX[i] - )); - }); - } - }); - - this.dataUnits = new IndexedChartComponent({ - layerClass: 'dataset-units', - make: (renderer, xPosSet, yPosSet, color, unitType, - yValueSet, datasetIndex, noOfDatasets) => { - - let unitSet = yPosSet.map((y, i) => { - return renderer[unitType.type]( - xPosSet[i], - y, - unitType.args, - color, - i, - datasetIndex, - noOfDatasets - ); - }); - - if(this.type === 'line') { - let pointsList = yPosSet.map((y, i) => (xPosSet[i] + ',' + y)); - let pointsStr = pointsList.join("L"); - - unitSet.unshift(makePath("M"+pointsStr, 'line-graph-path', color)); - } - - return unitSet; - }, - argsKeys: ['xUnitPositions', 'yUnitPositions', - 'colors', 'unitTypes', 'yUnitValues'], - animate: () => {} - }); - - // TODO: rebind new units - // if(this.isNavigable) { - // this.bind_units(units_array); - // } - - this.yMarkerLines = {}; - this.xMarkerLines = {}; - - // Marker Regions - - this.components = [ - // temp - // this.yAxisAux, - this.yAxis, - this.xAxis, - // this.yMarkerLines, - // this.xMarkerLines, - this.dataUnits, - ]; - } - } class BarChart extends AxisChart { @@ -1891,6 +1911,103 @@ class ScatterChart extends LineChart { make_path() {} } +class MultiAxisChart extends AxisChart { + constructor(args) { + super(args); + this.type = 'multiaxis'; + this.unitType = args.unitType || 'line'; + this.setup(); + } + + setHorizontalMargin() { + let noOfLeftAxes = this.data.datasets.filter(d => d.axisPosition === 'left').length; + this.translateXLeft = (noOfLeftAxes) * Y_AXIS_MARGIN; + this.translateXRight = (this.data.datasets.length - noOfLeftAxes) * Y_AXIS_MARGIN || Y_AXIS_MARGIN; + } + + prepareYAxis() { + this.state.yAxes = []; + let sets = this.state.datasets; + // let axesLeft = sets.filter(d => d.axisPosition === 'left'); + // let axesRight = sets.filter(d => d.axisPosition === 'right'); + // let axesNone = sets.filter(d => !d.axisPosition || + // !['left', 'right'].includes(d.axisPosition)); + + let leftCount = 0, rightCount = 0; + + sets.forEach((d, i) => { + this.state.yAxes.push({ + position: d.axisPosition, + color: d.color, + dataValues: d.values, + index: d.axisPosition === 'left' ? leftCount++ : rightCount++ + }); + }); + } + + configure(args) { + super.configure(args); + this.config.xAxisMode = args.xAxisMode || 'tick'; + this.config.yAxisMode = args.yAxisMode || 'span'; + } + + // setUnitWidthAndXOffset() { + // this.state.unitWidth = this.width/(this.state.datasetLength); + // this.state.xOffset = this.state.unitWidth/2; + // } + + configUnits() { + this.state.unitArgs = { + type: 'bar', + args: { + spaceWidth: this.state.unitWidth/2, + } + }; + } + + setYAxis() { + this.state.yAxes.map(yAxis => { + // console.log(yAxis); + this.calcYAxisParameters(yAxis, yAxis.dataValues, this.unitType === 'line'); + // console.log(yAxis); + }); + } + + setupYAxesComponents() { + this.yAxesComponents = this.state.yAxes.map((e, i) => { + return new ChartComponent({ + layerClass: 'y axis y-axis-' + i, + make: () => { + let d = this.state.yAxes[i]; + this.renderer.setZeroline(d.zeroline); + let axis = d.positions.map((position, j) => + this.renderer.yLine(position, d.labels[j], { + pos: d.position, + mode: 'tick', + offset: d.index * Y_AXIS_MARGIN, + stroke: this.colors[i] + }) + ); + + let guidePos = d.position === 'left' + ? -1 * d.index * Y_AXIS_MARGIN + : this.width + d.index * Y_AXIS_MARGIN; + + axis.push(this.renderer.xLine(guidePos, '', { + pos:'top', + mode: 'span', + stroke: this.colors[i], + className: 'y-axis-guide' + })); + + return axis; + }, + animate: () => {} + }); + }); + } +} + class PercentageChart extends BaseChart { constructor(args) { super(args); @@ -2499,6 +2616,7 @@ class Heatmap extends BaseChart { const chartTypes = { line: LineChart, bar: BarChart, + multiaxis: MultiAxisChart, scatter: ScatterChart, percentage: PercentageChart, heatmap: Heatmap, diff --git a/dist/frappe-charts.min.cjs.js b/dist/frappe-charts.min.cjs.js index f51a565..32ed2c3 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],n=document.createElement("style");return n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t)),e}function $(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 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 getBarHeightAndYAttr(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=i*MIN_BAR_PERCENT_HEIGHT)):(a=e,0===(n=t-e)&&(n=i*MIN_BAR_PERCENT_HEIGHT)),[n,a]}function $$1(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 n in e){var a=e[n];if("inside"===n)$$1(a).appendChild(i);else if("around"===n){var r=$$1(a);r.parentNode.insertBefore(i,r),i.appendChild(r)}else"styles"===n?"object"===(void 0===a?"undefined":_typeof(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 renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,n){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function makeSVGContainer(t,e,i,n){return createSVG("svg",{className:e,inside:t,width:i,height:n})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("path",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",d:t,styles:{stroke:arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",fill:arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none"}})}function makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=renderVerticalGradient(t,n),r=[1,.6,.2];return i&&(r=[.4,.2,0]),setGradientStop(a,"0%",e,r[0]),setGradientStop(a,"50%",e,r[1]),setGradientStop(a,"100%",e,r[2]),n}function makeHeatSquare(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(r).map(function(t){s[t]=r[t]}),createSVG("rect",s)}function makeText(t,e,i,n){return createSVG("text",{className:t,x:e,y:i,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:n})}function makeVertXLine(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#dadada",r=createSVG("line",{x1:0,x2:0,y1:i+AXIS_TICK_LENGTH,y2:"span"===n?-1*AXIS_TICK_LENGTH:i,stroke:a}),s=createSVG("text",{x:0,y:i+AXIS_TICK_LENGTH+LABEL_MARGIN,dy:FONT_SIZE+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:e}),o=createSVG("g",{transform:"translate("+t+", 0)"});return o.appendChild(r),o.appendChild(s),o}function makeHoriYLine(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"left",r="span"===n?i+AXIS_TICK_LENGTH:0,s=void 0,o=void 0,l=void 0,h=void 0;"tick"===n&&"right"===a?(s=i,o=i+AXIS_TICK_LENGTH,l=i+AXIS_TICK_LENGTH+LABEL_MARGIN,h="start"):(s=-1*AXIS_TICK_LENGTH,o=r,l=-1*(LABEL_MARGIN+AXIS_TICK_LENGTH),h="end");var c=createSVG("line",{className:"",x1:s,x2:o,y1:0,y2:0}),u=createSVG("text",{x:l,y:0,dy:FONT_SIZE/2-2+"px","font-size":FONT_SIZE+"px","text-anchor":h,innerHTML:e+""}),p=createSVG("g",{transform:"translate(0, "+t+")","stroke-opacity":1});return 0!==u&&"0"!==u||(p.style.stroke="rgba(27, 31, 35, 0.6)"),p.appendChild(c),p.appendChild(u),p}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),r=limitColor((a>>16)+e),s=limitColor((a>>8&255)+e),o=limitColor((255&a)+e);return(n?"#":"")+(o|s<<8|r<<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 n=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function animateSVGElement(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,r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s=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=r[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[n],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};a&&(p.type=a);for(var d in p)h.setAttribute(d,p[d]);s.appendChild(h),a?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}return[s,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=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,r=void 0,s=void 0;t[0]=e.unit;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);r=l[0],s=l[1],i.push(s),n.push([r,a]),a.replaceChild(r,e.unit),e.array?e.array[e.index]=s:e.object[e.key]=s});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 runSMILAnimation(t,e,i){if(0!==i.length){var n=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),n=Math.floor(e),a=i-n,r=a,s=1;a>5&&(a%2!=0&&(a=++i-n),r=a/2,s=2),a<=2&&(s=a/(r=4)),0===a&&(r=5,s=1);for(var o=[],l=0;l<=r;l++)o.push(n+s*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),n=slicedToArray(i,2),a=n[0],r=n[1],s=e?e/Math.pow(10,r):0,o=getRangeIntervals(a=a.toFixed(6),s);return o=o.map(function(t){return t*Math.pow(10,r)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),n=i[1]-i[0],a=0,r=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,toConsumableArray(t)),a=Math.min.apply(Math,toConsumableArray(t)),r=[];if(n>=0&&a>=0)normalize(n)[1],r=i?getIntervals(n,a):getIntervals(n);else if(n>0&&a<0){var s=Math.abs(a);n>=s?(normalize(n)[1],r=e(n,s)):(normalize(s)[1],r=e(s,n).map(function(t){return-1*t}))}else if(n<=0&&a<=0){var o=Math.abs(a),l=Math.abs(n);normalize(o)[1],r=(r=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return r}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)),n=1/(e-1),a=[],r=0;r9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{fill:#555b51}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path,.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,a){var o={key:t,arg:e,resolve:i,reject:a,next:null};s?s=s.next=o:(r=s=o,n(t,e))})}function n(i,r){try{var s=e[i](r),o=s.value;o instanceof t?Promise.resolve(o.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(s.done?"return":"normal",s.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):s=null}var r,s;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 n=t.colors[i]||"black",a=$.create("li",{styles:{"border-top":"3px solid "+n},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.data_point_list.appendChild(a)})}},{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]:[],r=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=r,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}(),MIN_BAR_PERCENT_HEIGHT=.01,AXIS_TICK_LENGTH=6,LABEL_MARGIN=4,FONT_SIZE=10,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:"bar",value:function(t,e,i,n,a,r,s,o,l){var h=this.unitWidth-i.spaceWidth,c=h,u=t-h/2,p=getBarHeightAndYAttr(e,this.zeroLine,this.totalHeight),d=slicedToArray(p,2),f=d[0];return createSVG("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":a,x:u,y:d[1],width:c,height:f})}},{key:"dot",value:function(t,e,i,n,a){return createSVG("circle",{style:"fill: "+n,"data-point-index":a,cx:t,cy:e,r:i.radius})}},{key:"xLine",value:function(t,e){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:this.xAxisMode;return makeVertXLine(t,e,this.totalHeight,i)}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.yAxisMode;return makeHoriYLine(t,e,this.totalWidth,n,i)}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),PRESET_COLOR_MAP={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){e.height;var i=e.title,n=void 0===i?"":i,a=e.subtitle,r=void 0===a?"":a,s=(e.colors,e.isNavigable),o=void 0===s?0:s,l=(e.showLegend,e.type,e.parent);classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof l?document.querySelector(l):l,this.title=n,this.subtitle=r,this.isNavigable=o,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){this.setColors(),this.setMargins(t),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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-2*this.translateX}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.prepareData(),this.reCalc(),this.refreshRenderer(),this.refreshComponents()}},{key:"makeChartArea",value:function(){this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateX+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.refreshComponents(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{key:"refreshComponents",value:function(){var t={chartState:this.state,oldChartState:this.oldState,intermedState:this.intermedState,chartRenderer:this.renderer};this.components.forEach(function(e){return e.refresh(t)})}},{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:"updateCurrentDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),ChartComponent=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,r=void 0===a?"":a,s=e.make,o=e.argsKeys,l=e.animate;classCallCheck(this,t),this.layerClass=n,this.layerTransform=r,this.make=s,this.argsKeys=o,this.animate=l,this.layer=void 0,this.store=[]}return createClass(t,[{key:"refresh",value:function(t){this.chartState=t.chartState,this.oldChartState=t.oldChartState,this.intermedState=t.intermedState,this.chartRenderer=t.chartRenderer}},{key:"render",value:function(){var t=this,e=this.argsKeys.map(function(e){return t.chartState[e]});e.unshift(this.chartRenderer),this.store=this.make.apply(this,toConsumableArray(e)),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform)}}]),t}(),IndexedChartComponent=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}return inherits(e,t),createClass(e,[{key:"refresh",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?a.slice(0,t.datasetLength):fillArray(a,t.datasetLength-a.length,0):e,i.index=n}),t.noOfDatasets=t.datasets.length}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.label}),e.yUnitValues=e.datasets.map(function(t){return t.values}),e.yAxisLabels=calcIntervals(this.getAllYValues(),"line"===this.type),this.calcYAxisPositions(),this.calcYUnitPositions(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{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:"calcYAxisPositions",value:function(){var t=this.state,e=t.yAxisLabels;t.scaleMultiplier=this.height/getValueRange(e);var i=getIntervalSize(e)*t.scaleMultiplier;t.zeroLine=this.height-getZeroIndex(e)*i,t.yAxisPositions=e.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnitPositions",value:function(){var t=this.state;t.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return floatTwo(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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 n=$.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(n)})}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var n=getOffset(t.chartWrapper),a=getOffset(e),r=a.left-n.left+e.offsetWidth/2,s=a.top-n.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(r,s,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,n){i&&($.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[n]+":\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 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,r=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(r?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"renderComponents",value:function(t){var i=this,n=this.radius,a=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var r=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var s=180-this.startAngle;this.slice_totals.map(function(o,l){var h=s,c=o/i.grand_total*FULL_ANGLE,u=a?-c:c,p=s+=u,d=e.getPositionByAngle(h,n),f=e.getPositionByAngle(p,n),g=t&&r[l],v=void 0,y=void 0;t?(v=g?g.startPosition:d,y=g?g.endPosition:d):(v=d,y=f);var m=i.makeArcPath(v,y),_=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,n=this.hoverRadio,a=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+a.x*n+"px,"+a.y*n+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,n){if(t){var a=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(a,50);var r=getOffset(this.svg),s=n.pageX-r.left+10,o=n.pageY-r.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(s,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=a}}},{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(i,n){var a=t.colors[n];i&&($.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[n]+":\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,n=void 0===i?"":i,a=t.domain,r=void 0===a?"":a,s=t.subdomain,o=void 0===s?"":s,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,g=void 0===f?[]:f;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=r,v.subdomain=o,v.data=h,v.discrete_domains=u,v.count_label=d;var y=new Date;return v.start=n||addDays(y,365),g=g.slice(0,5),v.legend_colors=v.validate_colors(g)?g:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],v.distribution_size=5,v.translateX=0,v}return inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"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;g.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=g}return[r,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=makeText("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),r=t.chartWrapper.getBoundingClientRect(),s=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=s.left-r.left+(o+2)/2,h=s.top-r.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}(BaseChart),chartTypes={line:LineChart,bar:BarChart,scatter:ScatterChart,percentage:PercentageChart,heatmap:Heatmap,pie:PieChart},Chart=function t(e){return classCallCheck(this,t),getChartByType(e.type,arguments[0])};module.exports=Chart; +"use strict";function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $(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 getBarHeightAndYAttr(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=i*MIN_BAR_PERCENT_HEIGHT)):(n=e,0===(a=t-e)&&(a=i*MIN_BAR_PERCENT_HEIGHT)),[a,n]}function $$1(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)$$1(n).appendChild(i);else if("around"===a){var s=$$1(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("path",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",d:t,styles:{stroke:arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",fill:arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none"}})}function makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),createSVG("rect",r)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy: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: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.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function 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 chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.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,.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=$.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}(),MIN_BAR_PERCENT_HEIGHT=.01,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:"bar",value:function(t,e,i,a,n,s,r,o,l){var h=this.unitWidth-i.spaceWidth,c=h,u=t-h/2,p=getBarHeightAndYAttr(e,this.zeroLine,this.totalHeight),d=slicedToArray(p,2),f=d[0];return createSVG("rect",{className:"bar mini",style:"fill: "+a,"data-point-index":n,x:u,y:d[1],width:c,height:f})}},{key:"dot",value:function(t,e,i,a,n){return createSVG("circle",{style:"fill: "+a,"data-point-index":n,cx:t,cy:e,r:i.radius})}},{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})}},{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})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),PRESET_COLOR_MAP={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){var i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.intermedState={},this.prepareData(),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){this.intermedState={}}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{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:"updateCurrentDataPoint",value:function(){}},{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.make,o=e.animate;classCallCheck(this,t),this.layerClass=a,this.layerTransform=s,this.make=r,this.animate=o,this.layer=void 0,this.store=[]}return createClass(t,[{key:"refresh",value:function(t){}},{key:"render",value:function(){var t=this;this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform)}}]),t}(),IndexedChartComponent=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}return inherits(e,t),createClass(e,[{key:"refresh",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?n.slice(0,t.datasetLength):fillArray(n,t.datasetLength-n.length,0):e,i.index=a}),t.noOfDatasets=t.datasets.length,this.prepareYAxis()}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.name}),e.yUnitValues=e.datasets.map(function(t){return t.values}),this.setYAxis(),this.calcYUnits(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{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.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return floatTwo(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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=$.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&&($.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),g=t&&s[l],v=void 0,y=void 0;t?(v=g?g.startPosition:d,y=g?g.endPosition:d):(v=d,y=f);var m=i.makeArcPath(v,y),_=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&&($.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,g=void 0===f?[]:f;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=o,v.data=h,v.discrete_domains=u,v.count_label=d;var y=new Date;return v.start=a||addDays(y,365),g=g.slice(0,5),v.legend_colors=v.validate_colors(g)?g:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],v.distribution_size=5,v.translateX=0,v}return inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"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;g.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=g}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={line:LineChart,bar:BarChart,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.css b/dist/frappe-charts.min.css index 53ded10..31b0b17 100644 --- a/dist/frappe-charts.min.css +++ b/dist/frappe-charts.min.css @@ -1 +1 @@ -.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 .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path,.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} \ No newline at end of file +.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.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,.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} \ No newline at end of file diff --git a/dist/frappe-charts.min.esm.js b/dist/frappe-charts.min.esm.js index ceff761..6bc4f72 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],n=document.createElement("style");return n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t)),e}function $(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 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 getBarHeightAndYAttr(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=i*MIN_BAR_PERCENT_HEIGHT)):(a=e,0===(n=t-e)&&(n=i*MIN_BAR_PERCENT_HEIGHT)),[n,a]}function $$1(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 n in e){var a=e[n];if("inside"===n)$$1(a).appendChild(i);else if("around"===n){var r=$$1(a);r.parentNode.insertBefore(i,r),i.appendChild(r)}else"styles"===n?"object"===(void 0===a?"undefined":_typeof(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 renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,n){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function makeSVGContainer(t,e,i,n){return createSVG("svg",{className:e,inside:t,width:i,height:n})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("path",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",d:t,styles:{stroke:arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",fill:arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none"}})}function makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=renderVerticalGradient(t,n),r=[1,.6,.2];return i&&(r=[.4,.2,0]),setGradientStop(a,"0%",e,r[0]),setGradientStop(a,"50%",e,r[1]),setGradientStop(a,"100%",e,r[2]),n}function makeHeatSquare(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(r).map(function(t){s[t]=r[t]}),createSVG("rect",s)}function makeText(t,e,i,n){return createSVG("text",{className:t,x:e,y:i,dy:FONT_SIZE/2+"px","font-size":FONT_SIZE+"px",innerHTML:n})}function makeVertXLine(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#dadada",r=createSVG("line",{x1:0,x2:0,y1:i+AXIS_TICK_LENGTH,y2:"span"===n?-1*AXIS_TICK_LENGTH:i,stroke:a}),s=createSVG("text",{x:0,y:i+AXIS_TICK_LENGTH+LABEL_MARGIN,dy:FONT_SIZE+"px","font-size":FONT_SIZE+"px","text-anchor":"middle",innerHTML:e}),o=createSVG("g",{transform:"translate("+t+", 0)"});return o.appendChild(r),o.appendChild(s),o}function makeHoriYLine(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"left",r="span"===n?i+AXIS_TICK_LENGTH:0,s=void 0,o=void 0,l=void 0,h=void 0;"tick"===n&&"right"===a?(s=i,o=i+AXIS_TICK_LENGTH,l=i+AXIS_TICK_LENGTH+LABEL_MARGIN,h="start"):(s=-1*AXIS_TICK_LENGTH,o=r,l=-1*(LABEL_MARGIN+AXIS_TICK_LENGTH),h="end");var c=createSVG("line",{className:"",x1:s,x2:o,y1:0,y2:0}),u=createSVG("text",{x:l,y:0,dy:FONT_SIZE/2-2+"px","font-size":FONT_SIZE+"px","text-anchor":h,innerHTML:e+""}),p=createSVG("g",{transform:"translate(0, "+t+")","stroke-opacity":1});return 0!==u&&"0"!==u||(p.style.stroke="rgba(27, 31, 35, 0.6)"),p.appendChild(c),p.appendChild(u),p}function limitColor(t){return t>255?255:t<0?0:t}function lightenDarkenColor(t,e){var i=getColor(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),r=limitColor((a>>16)+e),s=limitColor((a>>8&255)+e),o=limitColor((255&a)+e);return(n?"#":"")+(o|s<<8|r<<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 n=COLOR_COMPATIBLE_CHARTS[e].includes(t);return new Chart({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function animateSVGElement(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,r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},s=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=r[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[n],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};a&&(p.type=a);for(var d in p)h.setAttribute(d,p[d]);s.appendChild(h),a?o.setAttribute(l,"translate("+u+")"):o.setAttribute(l,u)}return[s,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=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,r=void 0,s=void 0;t[0]=e.unit;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);r=l[0],s=l[1],i.push(s),n.push([r,a]),a.replaceChild(r,e.unit),e.array?e.array[e.index]=s:e.object[e.key]=s});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 runSMILAnimation(t,e,i){if(0!==i.length){var n=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),n=Math.floor(e),a=i-n,r=a,s=1;a>5&&(a%2!=0&&(a=++i-n),r=a/2,s=2),a<=2&&(s=a/(r=4)),0===a&&(r=5,s=1);for(var o=[],l=0;l<=r;l++)o.push(n+s*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),n=slicedToArray(i,2),a=n[0],r=n[1],s=e?e/Math.pow(10,r):0,o=getRangeIntervals(a=a.toFixed(6),s);return o=o.map(function(t){return t*Math.pow(10,r)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),n=i[1]-i[0],a=0,r=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,toConsumableArray(t)),a=Math.min.apply(Math,toConsumableArray(t)),r=[];if(n>=0&&a>=0)normalize(n)[1],r=i?getIntervals(n,a):getIntervals(n);else if(n>0&&a<0){var s=Math.abs(a);n>=s?(normalize(n)[1],r=e(n,s)):(normalize(s)[1],r=e(s,n).map(function(t){return-1*t}))}else if(n<=0&&a<=0){var o=Math.abs(a),l=Math.abs(n);normalize(o)[1],r=(r=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return r}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)),n=1/(e-1),a=[],r=0;r9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function getWeeksBetween(t,e){return Math.ceil(getDaysBetween(t,e)/7)}function getDaysBetween(t,e){return(treatAsUtc(e)-treatAsUtc(t))/864e5}function addDays(t,e){t.setDate(t.getDate()+e)}function getChartByType(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{fill:#555b51}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path,.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,a){var o={key:t,arg:e,resolve:i,reject:a,next:null};s?s=s.next=o:(r=s=o,n(t,e))})}function n(i,r){try{var s=e[i](r),o=s.value;o instanceof t?Promise.resolve(o.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(s.done?"return":"normal",s.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):s=null}var r,s;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 n=t.colors[i]||"black",a=$.create("li",{styles:{"border-top":"3px solid "+n},innerHTML:''+(0===e.value||e.value?e.value:"")+"\n\t\t\t\t\t"+(e.title?e.title:"")});t.data_point_list.appendChild(a)})}},{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]:[],r=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=r,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}(),MIN_BAR_PERCENT_HEIGHT=.01,AXIS_TICK_LENGTH=6,LABEL_MARGIN=4,FONT_SIZE=10,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:"bar",value:function(t,e,i,n,a,r,s,o,l){var h=this.unitWidth-i.spaceWidth,c=h,u=t-h/2,p=getBarHeightAndYAttr(e,this.zeroLine,this.totalHeight),d=slicedToArray(p,2),f=d[0];return createSVG("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":a,x:u,y:d[1],width:c,height:f})}},{key:"dot",value:function(t,e,i,n,a){return createSVG("circle",{style:"fill: "+n,"data-point-index":a,cx:t,cy:e,r:i.radius})}},{key:"xLine",value:function(t,e){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:this.xAxisMode;return makeVertXLine(t,e,this.totalHeight,i)}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.yAxisMode;return makeHoriYLine(t,e,this.totalWidth,n,i)}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),PRESET_COLOR_MAP={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){e.height;var i=e.title,n=void 0===i?"":i,a=e.subtitle,r=void 0===a?"":a,s=(e.colors,e.isNavigable),o=void 0===s?0:s,l=(e.showLegend,e.type,e.parent);classCallCheck(this,t),this.rawChartArgs=arguments[0],this.parent="string"==typeof l?document.querySelector(l):l,this.title=n,this.subtitle=r,this.isNavigable=o,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return createClass(t,[{key:"configure",value:function(t){this.setColors(),this.setMargins(t),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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-2*this.translateX}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.prepareData(),this.reCalc(),this.refreshRenderer(),this.refreshComponents()}},{key:"makeChartArea",value:function(){this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateX+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.refreshComponents(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{key:"refreshComponents",value:function(){var t={chartState:this.state,oldChartState:this.oldState,intermedState:this.intermedState,chartRenderer:this.renderer};this.components.forEach(function(e){return e.refresh(t)})}},{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:"updateCurrentDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return getDifferentChart(t,this.type,this.rawChartArgs)}}]),t}(),ChartComponent=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,r=void 0===a?"":a,s=e.make,o=e.argsKeys,l=e.animate;classCallCheck(this,t),this.layerClass=n,this.layerTransform=r,this.make=s,this.argsKeys=o,this.animate=l,this.layer=void 0,this.store=[]}return createClass(t,[{key:"refresh",value:function(t){this.chartState=t.chartState,this.oldChartState=t.oldChartState,this.intermedState=t.intermedState,this.chartRenderer=t.chartRenderer}},{key:"render",value:function(){var t=this,e=this.argsKeys.map(function(e){return t.chartState[e]});e.unshift(this.chartRenderer),this.store=this.make.apply(this,toConsumableArray(e)),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform)}}]),t}(),IndexedChartComponent=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}return inherits(e,t),createClass(e,[{key:"refresh",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?a.slice(0,t.datasetLength):fillArray(a,t.datasetLength-a.length,0):e,i.index=n}),t.noOfDatasets=t.datasets.length}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.label}),e.yUnitValues=e.datasets.map(function(t){return t.values}),e.yAxisLabels=calcIntervals(this.getAllYValues(),"line"===this.type),this.calcYAxisPositions(),this.calcYUnitPositions(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{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:"calcYAxisPositions",value:function(){var t=this.state,e=t.yAxisLabels;t.scaleMultiplier=this.height/getValueRange(e);var i=getIntervalSize(e)*t.scaleMultiplier;t.zeroLine=this.height-getZeroIndex(e)*i,t.yAxisPositions=e.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnitPositions",value:function(){var t=this.state;t.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return floatTwo(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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 n=$.create("div",{className:"progress-bar",inside:t.percentageBar,styles:{background:t.colors[i],width:100*e/t.grand_total+"%"}});t.slices.push(n)})}},{key:"bindTooltip",value:function(){var t=this;this.slices.map(function(e,i){e.addEventListener("mouseenter",function(){var n=getOffset(t.chartWrapper),a=getOffset(e),r=a.left-n.left+e.offsetWidth/2,s=a.top-n.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(r,s,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,n){i&&($.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[n]+":\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 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,r=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(r?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"renderComponents",value:function(t){var i=this,n=this.radius,a=this.clockWise;this.grand_total=this.slice_totals.reduce(function(t,e){return t+e},0);var r=this.slicesProperties||[];this.slices=[],this.elements_to_animate=[],this.slicesProperties=[];var s=180-this.startAngle;this.slice_totals.map(function(o,l){var h=s,c=o/i.grand_total*FULL_ANGLE,u=a?-c:c,p=s+=u,d=e.getPositionByAngle(h,n),f=e.getPositionByAngle(p,n),g=t&&r[l],v=void 0,y=void 0;t?(v=g?g.startPosition:d,y=g?g.endPosition:d):(v=d,y=f);var m=i.makeArcPath(v,y),_=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,n=this.hoverRadio,a=e.getPositionByAngle(t.startAngle+t.angle/2,i);return"translate3d("+a.x*n+"px,"+a.y*n+"px,0)"}},{key:"hoverSlice",value:function(t,e,i,n){if(t){var a=this.colors[e];if(i){transform(t,this.calTranslateByAngle(this.slicesProperties[e])),t.style.fill=lightenDarkenColor(a,50);var r=getOffset(this.svg),s=n.pageX-r.left+10,o=n.pageY-r.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(s,o,l,h+"%"),this.tip.show_tip()}else transform(t,"translate3d(0,0,0)"),this.tip.hide_tip(),t.style.fill=a}}},{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(i,n){var a=t.colors[n];i&&($.create("div",{className:"stats",inside:t.statsWrapper}).innerHTML='\n\t\t\t\t\t\n\t\t\t\t\t'+e[n]+":\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,n=void 0===i?"":i,a=t.domain,r=void 0===a?"":a,s=t.subdomain,o=void 0===s?"":s,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,g=void 0===f?[]:f;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=r,v.subdomain=o,v.data=h,v.discrete_domains=u,v.count_label=d;var y=new Date;return v.start=n||addDays(y,365),g=g.slice(0,5),v.legend_colors=v.validate_colors(g)?g:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],v.distribution_size=5,v.translateX=0,v}return inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"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;g.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=g}return[r,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=makeText("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),r=t.chartWrapper.getBoundingClientRect(),s=e.target.getBoundingClientRect(),o=parseInt(e.target.getAttribute("width")),l=s.left-r.left+(o+2)/2,h=s.top-r.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}(BaseChart),chartTypes={line:LineChart,bar:BarChart,scatter:ScatterChart,percentage:PercentageChart,heatmap:Heatmap,pie:PieChart},Chart=function t(e){return classCallCheck(this,t),getChartByType(e.type,arguments[0])};export default Chart; +function __$styleInject(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");return a.type="text/css",i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t)),e}function $(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 getBarHeightAndYAttr(t,e,i){var a=void 0,n=void 0;return t<=e?(n=t,0===(a=e-t)&&(n-=a=i*MIN_BAR_PERCENT_HEIGHT)):(n=e,0===(a=t-e)&&(a=i*MIN_BAR_PERCENT_HEIGHT)),[a,n]}function $$1(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)$$1(n).appendChild(i);else if("around"===a){var s=$$1(n);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===a?"object"===(void 0===n?"undefined":_typeof(n))&&Object.keys(n).map(function(t){i.style[t]=n[t]}):("className"===a&&(a="class"),"innerHTML"===a?i.textContent=n:i.setAttribute(a,n))}return i}function renderVerticalGradient(t,e){return createSVG("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function setGradientStop(t,e,i,a){return createSVG("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":a})}function makeSVGContainer(t,e,i,a){return createSVG("svg",{className:e,inside:t,width:i,height:a})}function makeSVGDefs(t){return createSVG("defs",{inside:t})}function makeSVGGroup(t,e){return createSVG("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function makePath(t){return createSVG("path",{className:arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",d:t,styles:{stroke:arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",fill:arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none"}})}function makeGradient(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a="path-fill-gradient-"+e,n=renderVerticalGradient(t,a),s=[1,.6,.2];return i&&(s=[.4,.2,0]),setGradientStop(n,"0%",e,s[0]),setGradientStop(n,"50%",e,s[1]),setGradientStop(n,"100%",e,s[2]),a}function makeHeatSquare(t,e,i,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:a,height:a,fill:n};return Object.keys(s).map(function(t){r[t]=s[t]}),createSVG("rect",r)}function makeText(t,e,i,a){return createSVG("text",{className:t,x:e,y:i,dy: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: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.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=animateSVGElement.apply(void 0,toConsumableArray(t)),l=slicedToArray(o,2);s=l[0],r=l[1],i.push(r),a.push([s,n]),n.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var n=t.cloneNode(!0);return a.map(function(t,a){t[1].replaceChild(i[a],t[0]),e[a][0]=i[a]}),n}function runSMILAnimation(t,e,i){if(0!==i.length){var a=animateSVG(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(a)),setTimeout(function(){a.parentNode==t&&(t.removeChild(a),t.appendChild(e))},REPLACE_ALL_NEW_DUR)}}function normalize(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var i=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,i)),i]}function getRangeIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=Math.ceil(t),a=Math.floor(e),n=i-a,s=n,r=1;n>5&&(n%2!=0&&(n=++i-a),s=n/2,r=2),n<=2&&(r=n/(s=4)),0===n&&(s=5,r=1);for(var o=[],l=0;l<=s;l++)o.push(a+r*l);return o}function getIntervals(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=normalize(t),a=slicedToArray(i,2),n=a[0],s=a[1],r=e?e/Math.pow(10,s):0,o=getRangeIntervals(n=n.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function calcIntervals(t){function e(t,e){for(var i=getIntervals(t),a=i[1]-i[0],n=0,s=1;n1&&void 0!==arguments[1]&&arguments[1],a=Math.max.apply(Math,toConsumableArray(t)),n=Math.min.apply(Math,toConsumableArray(t)),s=[];if(a>=0&&n>=0)normalize(a)[1],s=i?getIntervals(a,n):getIntervals(a);else if(a>0&&n<0){var r=Math.abs(n);a>=r?(normalize(a)[1],s=e(a,r)):(normalize(r)[1],s=e(r,a).map(function(t){return-1*t}))}else if(a<=0&&n<=0){var o=Math.abs(n),l=Math.abs(a);normalize(o)[1],s=(s=i?getIntervals(o,l):getIntervals(o)).reverse().map(function(t){return-1*t})}return s}function 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 chartTypes[t]?new chartTypes[t](e):new LineChart(e)}__$styleInject('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.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,.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=$.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}(),MIN_BAR_PERCENT_HEIGHT=.01,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:"bar",value:function(t,e,i,a,n,s,r,o,l){var h=this.unitWidth-i.spaceWidth,c=h,u=t-h/2,p=getBarHeightAndYAttr(e,this.zeroLine,this.totalHeight),d=slicedToArray(p,2),f=d[0];return createSVG("rect",{className:"bar mini",style:"fill: "+a,"data-point-index":n,x:u,y:d[1],width:c,height:f})}},{key:"dot",value:function(t,e,i,a,n){return createSVG("circle",{style:"fill: "+a,"data-point-index":n,cx:t,cy:e,r:i.radius})}},{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})}},{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})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),PRESET_COLOR_MAP={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},DEFAULT_COLORS=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],getColor=function(t){return PRESET_COLOR_MAP[t]||t},ALL_CHART_TYPES=["line","scatter","bar","percentage","heatmap","pie"],COMPATIBLE_CHARTS={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},COLOR_COMPATIBLE_CHARTS={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},BaseChart=function(){function t(e){var i=e.height,a=void 0===i?240:i,n=e.title,s=void 0===n?"":n,r=e.subtitle,o=void 0===r?"":r,l=(e.colors,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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=getElementContentWidth(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.intermedState={},this.prepareData(),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){this.svg=makeSVGContainer(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=makeSVGDefs(this.svg),this.drawArea=makeSVGGroup(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){this.intermedState={}}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{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:"updateCurrentDataPoint",value:function(){}},{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.make,o=e.animate;classCallCheck(this,t),this.layerClass=a,this.layerTransform=s,this.make=r,this.animate=o,this.layer=void 0,this.store=[]}return createClass(t,[{key:"refresh",value:function(t){}},{key:"render",value:function(){var t=this;this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=makeSVGGroup(this.parent,this.layerClass,this.layerTransform)}}]),t}(),IndexedChartComponent=function(t){function e(t){classCallCheck(this,e);var i=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}return inherits(e,t),createClass(e,[{key:"refresh",value:function(t){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?n.slice(0,t.datasetLength):fillArray(n,t.datasetLength-n.length,0):e,i.index=a}),t.noOfDatasets=t.datasets.length,this.prepareYAxis()}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.name}),e.yUnitValues=e.datasets.map(function(t){return t.values}),this.setYAxis(),this.calcYUnits(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{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.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return floatTwo(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var a=0;e.slice(this.max_slices-1).map(function(t){a+=t[0]}),i.push([a,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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=$.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&&($.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),g=t&&s[l],v=void 0,y=void 0;t?(v=g?g.startPosition:d,y=g?g.endPosition:d):(v=d,y=f);var m=i.makeArcPath(v,y),_=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&&($.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,g=void 0===f?[]:f;classCallCheck(this,e);var v=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));v.type="heatmap",v.domain=s,v.subdomain=o,v.data=h,v.discrete_domains=u,v.count_label=d;var y=new Date;return v.start=a||addDays(y,365),g=g.slice(0,5),v.legend_colors=v.validate_colors(g)?g:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],v.distribution_size=5,v.translateX=0,v}return inherits(e,t),createClass(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){isValidColor(t)||(e=0,console.warn('"'+t+'" is not a valid color.'))},this),e}},{key:"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;g.getMonth()-t.getMonth()&&(a=1,this.discrete_domains&&(n=1),this.month_start_points.push(13+12*(e+n))),t=g}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={line:LineChart,bar:BarChart,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 9114621..6e5364f 100644 --- a/dist/frappe-charts.min.iife.js +++ b/dist/frappe-charts.min.iife.js @@ -1 +1 @@ -var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function n(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function a(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function r(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=i*Q)):(a=e,0===(n=t-e)&&(n=i*Q)),[n,a]}function o(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function l(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)o(a).appendChild(i);else if("around"===n){var s=o(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":B(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 h(t,e){return l("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function c(t,e,i,n){return l("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function u(t,e,i,n){return l("svg",{className:e,inside:t,width:i,height:n})}function p(t){return l("defs",{inside:t})}function d(t,e){return l("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function f(t){return l("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 v(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=h(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),c(a,"0%",e,s[0]),c(a,"50%",e,s[1]),c(a,"100%",e,s[2]),n}function g(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(s).map(function(t){r[t]=s[t]}),l("rect",r)}function y(t,e,i,n){return l("text",{className:t,x:e,y:i,dy:et/2+"px","font-size":et+"px",innerHTML:n})}function m(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#dadada",s=l("line",{x1:0,x2:0,y1:i+Z,y2:"span"===n?-1*Z:i,stroke:a}),r=l("text",{x:0,y:i+Z+tt,dy:et+"px","font-size":et+"px","text-anchor":"middle",innerHTML:e}),o=l("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function _(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"left",s="span"===n?i+Z:0,r=void 0,o=void 0,h=void 0,c=void 0;"tick"===n&&"right"===a?(r=i,o=i+Z,h=i+Z+tt,c="start"):(r=-1*Z,o=s,h=-1*(tt+Z),c="end");var u=l("line",{className:"",x1:r,x2:o,y1:0,y2:0}),p=l("text",{x:h,y:0,dy:et/2-2+"px","font-size":et+"px","text-anchor":c,innerHTML:e+""}),d=l("g",{transform:"translate(0, "+t+")","stroke-opacity":1});return 0!==p&&"0"!==p||(d.style.stroke="rgba(27, 31, 35, 0.6)"),d.appendChild(u),d.appendChild(p),d}function b(t){return t>255?255:t<0?0:t}function k(t,e){var i=st(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=b((a>>16)+e),r=b((a>>8&255)+e),o=b((255&a)+e);return(n?"#":"")+(o|r<<8|s<<16).toString(16)}function x(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function w(t,e,i){if(t!==e){rt.includes(t)||console.error("'"+t+"' is not a valid chart type."),ot[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var n=lt[e].includes(t);return new wt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function A(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},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:dt[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 C(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function L(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=A.apply(void 0,$(t)),l=J(o,2);s=l[0],r=l[1],i.push(r),n.push([s,a]),a.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});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 M(t,e,i){if(0!==i.length){var n=L(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},pt)}}function S(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 P(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 O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=S(t),n=J(i,2),a=n[0],s=n[1],r=e?e/Math.pow(10,s):0,o=P(a=a.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function W(t){function e(t,e){for(var i=O(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,$(t)),a=Math.min.apply(Math,$(t)),s=[];if(n>=0&&a>=0)S(n)[1],s=i?O(n,a):O(n);else if(n>0&&a<0){var r=Math.abs(a);n>=r?(S(n)[1],s=e(n,r)):(S(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);S(o)[1],s=(s=i?O(o,l):O(o)).reverse().map(function(t){return-1*t})}return s}function T(t){var e=D(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 D(t){return t[1]-t[0]}function N(t){return t[t.length-1]-t[0]}function j(t,e){for(var i=Math.max.apply(Math,$(t)),n=1/(e-1),a=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function z(t,e){return Math.ceil(F(t,e)/7)}function F(t,e){return(R(e)-R(t))/864e5}function H(t,e){t.setDate(t.getDate()+e)}function I(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return xt[t]?new xt[t](e):new gt(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{fill:#555b51}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path,.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 B="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},Y=(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")}),X=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
            \n\t\t\t\t
            '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){e.hide_tip()})}},{key:"fill",value:function(){var e=this,i=void 0;i=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,n){var a=e.colors[n]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var n="calc(50% + "+(this.left-e)+"px)";i.style.left=n,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=n,this.list_values=a,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),e}(),Q=.01,Z=6,tt=4,et=10,it=function(){function t(e){Y(this,t),this.refreshState(e)}return X(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:"bar",value:function(t,e,i,n,a,s,o,h,c){var u=this.unitWidth-i.spaceWidth,p=u,d=t-u/2,f=r(e,this.zeroLine,this.totalHeight),v=J(f,2),g=v[0];return l("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":a,x:d,y:v[1],width:p,height:g})}},{key:"dot",value:function(t,e,i,n,a){return l("circle",{style:"fill: "+n,"data-point-index":a,cx:t,cy:e,r:i.radius})}},{key:"xLine",value:function(t,e){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:this.xAxisMode;return m(t,e,this.totalHeight,i)}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.yAxisMode;return _(t,e,this.totalWidth,n,i)}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),nt={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},at=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],st=function(t){return nt[t]||t},rt=["line","scatter","bar","percentage","heatmap","pie"],ot={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},lt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ht=function(){function e(t){t.height;var i=t.title,n=void 0===i?"":i,a=t.subtitle,s=void 0===a?"":a,r=(t.colors,t.isNavigable),o=void 0===r?0:r,l=(t.showLegend,t.type,t.parent);Y(this,e),this.rawChartArgs=arguments[0],this.parent="string"==typeof l?document.querySelector(l):l,this.title=n,this.subtitle=s,this.isNavigable=o,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return X(e,[{key:"configure",value:function(t){this.setColors(),this.setMargins(t),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 G({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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=n(this.parent)-0,this.width=this.baseWidth-2*this.translateX}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.prepareData(),this.reCalc(),this.refreshRenderer(),this.refreshComponents()}},{key:"makeChartArea",value:function(){this.svg=u(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=p(this.svg),this.drawArea=d(this.svg,this.type+"-chart","translate("+this.translateX+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.refreshComponents(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{key:"refreshComponents",value:function(){var t={chartState:this.state,oldChartState:this.oldState,intermedState:this.intermedState,chartRenderer:this.renderer};this.components.forEach(function(e){return e.refresh(t)})}},{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){i(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:"updateCurrentDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return w(t,this.type,this.rawChartArgs)}}]),e}(),ct=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,s=void 0===a?"":a,r=e.make,o=e.argsKeys,l=e.animate;Y(this,t),this.layerClass=n,this.layerTransform=s,this.make=r,this.argsKeys=o,this.animate=l,this.layer=void 0,this.store=[]}return X(t,[{key:"refresh",value:function(t){this.chartState=t.chartState,this.oldChartState=t.oldChartState,this.intermedState=t.intermedState,this.chartRenderer=t.chartRenderer}},{key:"render",value:function(){var t=this,e=this.argsKeys.map(function(e){return t.chartState[e]});e.unshift(this.chartRenderer),this.store=this.make.apply(this,$(e)),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=d(this.parent,this.layerClass,this.layerTransform)}}]),t}(),ut=function(t){function e(t){Y(this,e);var i=V(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}return K(e,t),X(e,[{key:"refresh",value:function(t){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?a.slice(0,t.datasetLength):s(a,t.datasetLength-a.length,0):e,i.index=n}),t.noOfDatasets=t.datasets.length}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.label}),e.yUnitValues=e.datasets.map(function(t){return t.values}),e.yAxisLabels=W(this.getAllYValues(),"line"===this.type),this.calcYAxisPositions(),this.calcYUnitPositions(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return a(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisPositions",value:function(){var t=this.state,e=t.yAxisLabels;t.scaleMultiplier=this.height/N(e);var i=D(e)*t.scaleMultiplier;t.zeroLine=this.height-T(e)*i,t.yAxisPositions=e.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnitPositions",value:function(){var t=this.state;t.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return a(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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}(ht),_t=Math.PI/180,bt=function(i){function n(t){Y(this,n);var e=V(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 K(n,i),X(n,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var n=0;return t.data.datasets.map(function(t){n+=t.values[i]}),[n,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,n=this.centerY,a=this.radius,s=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"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),v=n.getPositionByAngle(p,i),g=t&&s[l],y=void 0,m=void 0;t?(y=g?g.startPosition:d,m=g?g.endPosition:d):(y=d,m=v);var _=e.makeArcPath(y,m),b=f(_,"pie-path","none",e.colors[l]);b.style.transition="transform .3s;",e.drawArea.appendChild(b),e.slices.push(b),e.slicesProperties.push({startPosition:d,endPosition:v,value:o,total:e.grand_total,startAngle:h,endAngle:p,angle:u}),t&&e.elements_to_animate.push([{unit:b,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(d,v)},650,"easein",null,{d:_}])}),t&&M(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){C(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=k(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 C(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*_t)*e,y:Math.cos(t*_t)*e}}}]),n}(ht),kt=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;Y(this,e);var g=V(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));g.type="heatmap",g.domain=s,g.subdomain=o,g.data=h,g.discrete_domains=u,g.count_label=d;var y=new Date;return g.start=n||H(y,365),v=v.slice(0,5),g.legend_colors=g.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],g.distribution_size=5,g.translateX=0,g}return K(e,t),X(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){x(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()&&H(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&H(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=z(this.first_week_start+"",this.last_week_start+"")+1}},{key:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("data-groups","translate(0, 20)")}},{key:"setup_values",value:function(){var t=this;this.domain_label_group.textContent="",this.data_groups.textContent="";var e=Object.keys(this.data).map(function(e){return t.data[e]});this.distribution=j(e,this.distribution_size),this.month_names=["January","February","March","April","May","June","July","August","September","October","November","December"],this.render_all_weeks_and_store_x_values(this.no_of_cols)}},{key:"render_all_weeks_and_store_x_values",value:function(t){var e=new Date(this.first_week_start);this.week_col=0,this.current_month=e.getMonth(),this.months=[this.current_month+""],this.month_weeks={},this.month_start_points=[],this.month_weeks[this.current_month]=0,this.month_start_points.push(13);for(var i=0;ii)break;y.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=y}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("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}(ht),xt={line:gt,bar:vt,scatter:yt,percentage:mt,heatmap:kt,pie:bt},wt=function t(e){return Y(this,t),I(e.type,arguments[0])};return wt}(); +var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function n(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function a(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function r(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=i*G)):(a=e,0===(n=t-e)&&(n=i*G)),[n,a]}function o(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function l(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)o(a).appendChild(i);else if("around"===n){var s=o(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":I(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 h(t,e){return l("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function c(t,e,i,n){return l("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function u(t,e,i,n){return l("svg",{className:e,inside:t,width:i,height:n})}function p(t){return l("defs",{inside:t})}function d(t,e){return l("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function f(t){return l("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 v(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=h(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),c(a,"0%",e,s[0]),c(a,"50%",e,s[1]),c(a,"100%",e,s[2]),n}function y(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(s).map(function(t){r[t]=s[t]}),l("rect",r)}function g(t,e,i,n){return l("text",{className:t,x:e,y:i,dy:tt/2+"px","font-size":tt+"px",innerHTML:n})}function m(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=et);var s=l("line",{className:"line-vertical "+a.className,x1:0,x2:0,y1:i,y2:n,styles:{stroke:a.stroke}}),r=l("text",{x:0,y:i>n?i+Q:i-Q-tt,dy:tt+"px","font-size":tt+"px","text-anchor":"middle",innerHTML:e}),o=l("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function _(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=et),a.lineType||(a.lineType="");var s=l("line",{className:"line-horizontal "+a.className+("dashed"===a.lineType?"dashed":""),x1:i,x2:n,y1:0,y2:0,styles:{stroke:a.stroke}}),r=l("text",{x:i255?255:t<0?0:t}function k(t,e){var i=st(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=x((a>>16)+e),r=x((a>>8&255)+e),o=x((255&a)+e);return(n?"#":"")+(o|r<<8|s<<16).toString(16)}function b(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function w(t,e,i){if(t!==e){rt.includes(t)||console.error("'"+t+"' is not a valid chart type."),ot[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var n=lt[e].includes(t);return new wt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function A(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:i/1e3+"s",values:c+";"+u,keySplines:pt[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 C(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function M(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=A.apply(void 0,Z(t)),l=J(o,2);s=l[0],r=l[1],i.push(r),n.push([s,a]),a.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var a=t.cloneNode(!0);return n.map(function(t,n){t[1].replaceChild(i[n],t[0]),e[n][0]=i[n]}),a}function L(t,e,i){if(0!==i.length){var n=M(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},ut)}}function O(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 P(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 W(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=O(t),n=J(i,2),a=n[0],s=n[1],r=e?e/Math.pow(10,s):0,o=P(a=a.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function N(t){function e(t,e){for(var i=W(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,Z(t)),a=Math.min.apply(Math,Z(t)),s=[];if(n>=0&&a>=0)O(n)[1],s=i?W(n,a):W(n);else if(n>0&&a<0){var r=Math.abs(a);n>=r?(O(n)[1],s=e(n,r)):(O(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);O(o)[1],s=(s=i?W(o,l):W(o)).reverse().map(function(t){return-1*t})}return s}function S(t){var e=T(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 T(t){return t[1]-t[0]}function D(t){return t[t.length-1]-t[0]}function j(t,e){for(var i=Math.max.apply(Math,Z(t)),n=1/(e-1),a=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function U(t,e){return Math.ceil(H(t,e)/7)}function H(t,e){return(E(e)-E(t))/864e5}function Y(t,e){t.setDate(t.getDate()+e)}function F(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return bt[t]?new bt[t](e):new vt(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.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,.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 I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X=(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")}),B=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}(),G=.01,Q=4,tt=10,et="#dadada",it=function(){function t(e){X(this,t),this.refreshState(e)}return B(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:"bar",value:function(t,e,i,n,a,s,o,h,c){var u=this.unitWidth-i.spaceWidth,p=u,d=t-u/2,f=r(e,this.zeroLine,this.totalHeight),v=J(f,2),y=v[0];return l("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":a,x:d,y:v[1],width:p,height:y})}},{key:"dot",value:function(t,e,i,n,a){return l("circle",{style:"fill: "+n,"data-point-index":a,cx:t,cy:e,r:i.radius})}},{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=et),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),m(t,e,n,a,{stroke:i.stroke,className:i.className})}},{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=et),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,_(t,e,n,a,{stroke:i.stroke,className:i.className})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),nt={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},at=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],st=function(t){return nt[t]||t},rt=["line","scatter","bar","percentage","heatmap","pie"],ot={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},lt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ht=function(){function e(t){var i=t.height,n=void 0===i?240:i,a=t.title,s=void 0===a?"":a,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);X(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 B(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 $({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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=n(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.intermedState={},this.prepareData(),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){this.svg=u(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=p(this.svg),this.drawArea=d(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){this.intermedState={}}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{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){i(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:"updateCurrentDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return w(t,this.type,this.rawChartArgs)}}]),e}(),ct=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,s=void 0===a?"":a,r=e.make,o=e.animate;X(this,t),this.layerClass=n,this.layerTransform=s,this.make=r,this.animate=o,this.layer=void 0,this.store=[]}return B(t,[{key:"refresh",value:function(t){}},{key:"render",value:function(){var t=this;this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=d(this.parent,this.layerClass,this.layerTransform)}}]),t}(),ut=(function(t){function e(t){X(this,e);var i=K(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}V(e,t),B(e,[{key:"refresh",value:function(t){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?a.slice(0,t.datasetLength):s(a,t.datasetLength-a.length,0):e,i.index=n}),t.noOfDatasets=t.datasets.length,this.prepareYAxis()}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.name}),e.yUnitValues=e.datasets.map(function(t){return t.values}),this.setYAxis(),this.calcYUnits(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{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 a(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=N(e,i);var n=t.labels;t.scaleMultiplier=this.height/D(n);var a=T(n)*t.scaleMultiplier;t.zeroLine=this.height-S(n)*a,t.positions=n.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return a(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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}(ht),_t=Math.PI/180,xt=function(i){function n(t){X(this,n);var e=K(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 V(n,i),B(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),v=n.getPositionByAngle(p,i),y=t&&s[l],g=void 0,m=void 0;t?(g=y?y.startPosition:d,m=y?y.endPosition:d):(g=d,m=v);var _=e.makeArcPath(g,m),x=f(_,"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:v,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,v)},650,"easein",null,{d:_}])}),t&&L(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){C(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=k(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 C(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*_t)*e,y:Math.cos(t*_t)*e}}}]),n}(ht),kt=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;X(this,e);var y=K(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||Y(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 V(e,t),B(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){b(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()&&Y(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&Y(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=U(this.first_week_start+"",this.last_week_start+"")+1}},{key:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("data-groups","translate(0, 20)")}},{key:"setup_values",value:function(){var t=this;this.domain_label_group.textContent="",this.data_groups.textContent="";var e=Object.keys(this.data).map(function(e){return t.data[e]});this.distribution=j(e,this.distribution_size),this.month_names=["January","February","March","April","May","June","July","August","September","October","November","December"],this.render_all_weeks_and_store_x_values(this.no_of_cols)}},{key:"render_all_weeks_and_store_x_values",value:function(t){var e=new Date(this.first_week_start);this.week_col=0,this.current_month=e.getMonth(),this.months=[this.current_month+""],this.month_weeks={},this.month_start_points=[],this.month_weeks[this.current_month]=0,this.month_start_points.push(13);for(var i=0;ii)break;g.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=g}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=g("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}(ht),bt={line:vt,bar:ft,multiaxis:gt,scatter:yt,percentage:mt,heatmap:kt,pie:xt},wt=function t(e){return X(this,t),F(e.type,arguments[0])};return wt}(); diff --git a/docs/assets/js/frappe-charts.min.js b/docs/assets/js/frappe-charts.min.js index 9114621..6e5364f 100644 --- a/docs/assets/js/frappe-charts.min.js +++ b/docs/assets/js/frappe-charts.min.js @@ -1 +1 @@ -var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function n(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function a(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function r(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=i*Q)):(a=e,0===(n=t-e)&&(n=i*Q)),[n,a]}function o(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function l(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)o(a).appendChild(i);else if("around"===n){var s=o(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":B(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 h(t,e){return l("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function c(t,e,i,n){return l("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function u(t,e,i,n){return l("svg",{className:e,inside:t,width:i,height:n})}function p(t){return l("defs",{inside:t})}function d(t,e){return l("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function f(t){return l("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 v(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=h(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),c(a,"0%",e,s[0]),c(a,"50%",e,s[1]),c(a,"100%",e,s[2]),n}function g(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(s).map(function(t){r[t]=s[t]}),l("rect",r)}function y(t,e,i,n){return l("text",{className:t,x:e,y:i,dy:et/2+"px","font-size":et+"px",innerHTML:n})}function m(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#dadada",s=l("line",{x1:0,x2:0,y1:i+Z,y2:"span"===n?-1*Z:i,stroke:a}),r=l("text",{x:0,y:i+Z+tt,dy:et+"px","font-size":et+"px","text-anchor":"middle",innerHTML:e}),o=l("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function _(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"left",s="span"===n?i+Z:0,r=void 0,o=void 0,h=void 0,c=void 0;"tick"===n&&"right"===a?(r=i,o=i+Z,h=i+Z+tt,c="start"):(r=-1*Z,o=s,h=-1*(tt+Z),c="end");var u=l("line",{className:"",x1:r,x2:o,y1:0,y2:0}),p=l("text",{x:h,y:0,dy:et/2-2+"px","font-size":et+"px","text-anchor":c,innerHTML:e+""}),d=l("g",{transform:"translate(0, "+t+")","stroke-opacity":1});return 0!==p&&"0"!==p||(d.style.stroke="rgba(27, 31, 35, 0.6)"),d.appendChild(u),d.appendChild(p),d}function b(t){return t>255?255:t<0?0:t}function k(t,e){var i=st(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=b((a>>16)+e),r=b((a>>8&255)+e),o=b((255&a)+e);return(n?"#":"")+(o|r<<8|s<<16).toString(16)}function x(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function w(t,e,i){if(t!==e){rt.includes(t)||console.error("'"+t+"' is not a valid chart type."),ot[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var n=lt[e].includes(t);return new wt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function A(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},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:dt[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 C(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function L(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=A.apply(void 0,$(t)),l=J(o,2);s=l[0],r=l[1],i.push(r),n.push([s,a]),a.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});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 M(t,e,i){if(0!==i.length){var n=L(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},pt)}}function S(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 P(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 O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=S(t),n=J(i,2),a=n[0],s=n[1],r=e?e/Math.pow(10,s):0,o=P(a=a.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function W(t){function e(t,e){for(var i=O(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,$(t)),a=Math.min.apply(Math,$(t)),s=[];if(n>=0&&a>=0)S(n)[1],s=i?O(n,a):O(n);else if(n>0&&a<0){var r=Math.abs(a);n>=r?(S(n)[1],s=e(n,r)):(S(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);S(o)[1],s=(s=i?O(o,l):O(o)).reverse().map(function(t){return-1*t})}return s}function T(t){var e=D(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 D(t){return t[1]-t[0]}function N(t){return t[t.length-1]-t[0]}function j(t,e){for(var i=Math.max.apply(Math,$(t)),n=1/(e-1),a=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function z(t,e){return Math.ceil(F(t,e)/7)}function F(t,e){return(R(e)-R(t))/864e5}function H(t,e){t.setDate(t.getDate()+e)}function I(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return xt[t]?new xt[t](e):new gt(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .graph-focus-margin{margin:0 5%}.chart-container>.title{margin-top:25px;margin-left:25px;text-align:left;font-weight:400;font-size:12px;color:#6c7680}.chart-container .graphics{margin-top:10px;padding-top:10px;padding-bottom:10px;position:relative}.chart-container .graph-stats-group{-ms-flex-pack:distribute;-webkit-box-flex:1;-ms-flex:1;flex:1}.chart-container .graph-stats-container,.chart-container .graph-stats-group{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content:space-around}.chart-container .graph-stats-container{-ms-flex-pack:distribute;padding-top:10px}.chart-container .graph-stats-container .stats{padding-bottom:15px}.chart-container .graph-stats-container .stats-title{color:#8d99a6}.chart-container .graph-stats-container .stats-value{font-size:20px;font-weight:300}.chart-container .graph-stats-container .stats-description{font-size:12px;color:#8d99a6}.chart-container .graph-stats-container .graph-data .stats-value{color:#98d85b}.chart-container .axis,.chart-container .chart-label{fill:#555b51}.chart-container .percentage-graph .progress{margin-bottom:0}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path,.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 B="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},Y=(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")}),X=function(){function t(t,e){for(var i=0;i\n\t\t\t\t
                \n\t\t\t\t
                '}),this.hide_tip(),this.title=this.container.querySelector(".title"),this.data_point_list=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",function(){e.hide_tip()})}},{key:"fill",value:function(){var e=this,i=void 0;i=this.title_value_first?""+this.title_value+""+this.title_name:this.title_name+""+this.title_value+"",this.title.innerHTML=i,this.data_point_list.innerHTML="",this.list_values.map(function(i,n){var a=e.colors[n]||"black",s=t.create("li",{styles:{"border-top":"3px solid "+a},innerHTML:''+(0===i.value||i.value?i.value:"")+"\n\t\t\t\t\t"+(i.title?i.title:"")});e.data_point_list.appendChild(s)})}},{key:"calc_position",value:function(){var t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight,this.left=this.x-t/2;var e=this.parent.offsetWidth-t,i=this.container.querySelector(".svg-pointer");if(this.left<0)i.style.left="calc(50% - "+-1*this.left+"px)",this.left=0;else if(this.left>e){var n="calc(50% + "+(this.left-e)+"px)";i.style.left=n,this.left=e}else i.style.left="50%"}},{key:"set_values",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.title_name=i,this.title_value=n,this.list_values=a,this.x=t,this.y=e,this.title_value_first=s,this.refresh()}},{key:"hide_tip",value:function(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}},{key:"show_tip",value:function(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}]),e}(),Q=.01,Z=6,tt=4,et=10,it=function(){function t(e){Y(this,t),this.refreshState(e)}return X(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:"bar",value:function(t,e,i,n,a,s,o,h,c){var u=this.unitWidth-i.spaceWidth,p=u,d=t-u/2,f=r(e,this.zeroLine,this.totalHeight),v=J(f,2),g=v[0];return l("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":a,x:d,y:v[1],width:p,height:g})}},{key:"dot",value:function(t,e,i,n,a){return l("circle",{style:"fill: "+n,"data-point-index":a,cx:t,cy:e,r:i.radius})}},{key:"xLine",value:function(t,e){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:this.xAxisMode;return m(t,e,this.totalHeight,i)}},{key:"yLine",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.yAxisMode;return _(t,e,this.totalWidth,n,i)}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),nt={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},at=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],st=function(t){return nt[t]||t},rt=["line","scatter","bar","percentage","heatmap","pie"],ot={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},lt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ht=function(){function e(t){t.height;var i=t.title,n=void 0===i?"":i,a=t.subtitle,s=void 0===a?"":a,r=(t.colors,t.isNavigable),o=void 0===r?0:r,l=(t.showLegend,t.type,t.parent);Y(this,e),this.rawChartArgs=arguments[0],this.parent="string"==typeof l?document.querySelector(l):l,this.title=n,this.subtitle=s,this.isNavigable=o,this.isNavigable&&(this.currentIndex=0),this.configure(arguments[0])}return X(e,[{key:"configure",value:function(t){this.setColors(),this.setMargins(t),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 G({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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=n(this.parent)-0,this.width=this.baseWidth-2*this.translateX}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.prepareData(),this.reCalc(),this.refreshRenderer(),this.refreshComponents()}},{key:"makeChartArea",value:function(){this.svg=u(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=p(this.svg),this.drawArea=d(this.svg,this.type+"-chart","translate("+this.translateX+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.refreshComponents(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{key:"refreshComponents",value:function(){var t={chartState:this.state,oldChartState:this.oldState,intermedState:this.intermedState,chartRenderer:this.renderer};this.components.forEach(function(e){return e.refresh(t)})}},{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){i(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:"updateCurrentDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return w(t,this.type,this.rawChartArgs)}}]),e}(),ct=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,s=void 0===a?"":a,r=e.make,o=e.argsKeys,l=e.animate;Y(this,t),this.layerClass=n,this.layerTransform=s,this.make=r,this.argsKeys=o,this.animate=l,this.layer=void 0,this.store=[]}return X(t,[{key:"refresh",value:function(t){this.chartState=t.chartState,this.oldChartState=t.oldChartState,this.intermedState=t.intermedState,this.chartRenderer=t.chartRenderer}},{key:"render",value:function(){var t=this,e=this.argsKeys.map(function(e){return t.chartState[e]});e.unshift(this.chartRenderer),this.store=this.make.apply(this,$(e)),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=d(this.parent,this.layerClass,this.layerTransform)}}]),t}(),ut=function(t){function e(t){Y(this,e);var i=V(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}return K(e,t),X(e,[{key:"refresh",value:function(t){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?a.slice(0,t.datasetLength):s(a,t.datasetLength-a.length,0):e,i.index=n}),t.noOfDatasets=t.datasets.length}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.label}),e.yUnitValues=e.datasets.map(function(t){return t.values}),e.yAxisLabels=W(this.getAllYValues(),"line"===this.type),this.calcYAxisPositions(),this.calcYUnitPositions(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{key:"calcXPositions",value:function(){var t=this.state;this.setUnitWidthAndXOffset(),t.xAxisPositions=t.xAxisLabels.map(function(e,i){return a(t.xOffset+i*t.unitWidth)}),t.xUnitPositions=new Array(t.noOfDatasets).fill(t.xAxisPositions)}},{key:"calcYAxisPositions",value:function(){var t=this.state,e=t.yAxisLabels;t.scaleMultiplier=this.height/N(e);var i=D(e)*t.scaleMultiplier;t.zeroLine=this.height-T(e)*i,t.yAxisPositions=e.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnitPositions",value:function(){var t=this.state;t.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return a(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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}(ht),_t=Math.PI/180,bt=function(i){function n(t){Y(this,n);var e=V(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 K(n,i),X(n,[{key:"setup_values",value:function(){var t=this;this.centerX=this.width/2,this.centerY=this.height/2,this.radius=this.height>this.width?this.centerX:this.centerY,this.slice_totals=[];var e=this.data.labels.map(function(e,i){var n=0;return t.data.datasets.map(function(t){n+=t.values[i]}),[n,e]}).filter(function(t){return t[0]>0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"makeArcPath",value:function(t,e){var i=this.centerX,n=this.centerY,a=this.radius,s=this.clockWise;return"M"+i+" "+n+" L"+(i+t.x)+" "+(n+t.y)+" A "+a+" "+a+" 0 0 "+(s?1:0)+" "+(i+e.x)+" "+(n+e.y)+" z"}},{key:"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),v=n.getPositionByAngle(p,i),g=t&&s[l],y=void 0,m=void 0;t?(y=g?g.startPosition:d,m=g?g.endPosition:d):(y=d,m=v);var _=e.makeArcPath(y,m),b=f(_,"pie-path","none",e.colors[l]);b.style.transition="transform .3s;",e.drawArea.appendChild(b),e.slices.push(b),e.slicesProperties.push({startPosition:d,endPosition:v,value:o,total:e.grand_total,startAngle:h,endAngle:p,angle:u}),t&&e.elements_to_animate.push([{unit:b,array:e.slices,index:e.slices.length-1},{d:e.makeArcPath(d,v)},650,"easein",null,{d:_}])}),t&&M(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){C(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=k(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 C(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*_t)*e,y:Math.cos(t*_t)*e}}}]),n}(ht),kt=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;Y(this,e);var g=V(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,arguments[0]));g.type="heatmap",g.domain=s,g.subdomain=o,g.data=h,g.discrete_domains=u,g.count_label=d;var y=new Date;return g.start=n||H(y,365),v=v.slice(0,5),g.legend_colors=g.validate_colors(v)?v:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"],g.distribution_size=5,g.translateX=0,g}return K(e,t),X(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){x(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()&&H(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&H(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=z(this.first_week_start+"",this.last_week_start+"")+1}},{key:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("data-groups","translate(0, 20)")}},{key:"setup_values",value:function(){var t=this;this.domain_label_group.textContent="",this.data_groups.textContent="";var e=Object.keys(this.data).map(function(e){return t.data[e]});this.distribution=j(e,this.distribution_size),this.month_names=["January","February","March","April","May","June","July","August","September","October","November","December"],this.render_all_weeks_and_store_x_values(this.no_of_cols)}},{key:"render_all_weeks_and_store_x_values",value:function(t){var e=new Date(this.first_week_start);this.week_col=0,this.current_month=e.getMonth(),this.months=[this.current_month+""],this.month_weeks={},this.month_start_points=[],this.month_weeks[this.current_month]=0,this.month_start_points.push(13);for(var i=0;ii)break;y.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=y}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("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}(ht),xt={line:gt,bar:vt,scatter:yt,percentage:mt,heatmap:kt,pie:bt},wt=function t(e){return Y(this,t),I(e.type,arguments[0])};return wt}(); +var Chart=function(){"use strict";function t(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function e(t){var e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}function i(t){var e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function n(t){var e=window.getComputedStyle(t),i=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.clientWidth-i}function a(t){return parseFloat(t.toFixed(2))}function s(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];i||(i=n?t[0]:t[t.length-1]);var a=new Array(Math.abs(e)).fill(i);return t=n?a.concat(t):t.concat(a)}function r(t,e,i){var n=void 0,a=void 0;return t<=e?(a=t,0===(n=e-t)&&(a-=n=i*G)):(a=e,0===(n=t-e)&&(n=i*G)),[n,a]}function o(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function l(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)o(a).appendChild(i);else if("around"===n){var s=o(a);s.parentNode.insertBefore(i,s),i.appendChild(s)}else"styles"===n?"object"===(void 0===a?"undefined":I(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 h(t,e){return l("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}function c(t,e,i,n){return l("stop",{inside:t,style:"stop-color: "+i,offset:e,"stop-opacity":n})}function u(t,e,i,n){return l("svg",{className:e,inside:t,width:i,height:n})}function p(t){return l("defs",{inside:t})}function d(t,e){return l("g",{className:e,inside:t,transform:arguments.length>2&&void 0!==arguments[2]?arguments[2]:""})}function f(t){return l("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 v(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n="path-fill-gradient-"+e,a=h(t,n),s=[1,.6,.2];return i&&(s=[.4,.2,0]),c(a,"0%",e,s[0]),c(a,"50%",e,s[1]),c(a,"100%",e,s[2]),n}function y(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"none",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r={className:t,x:e,y:i,width:n,height:n,fill:a};return Object.keys(s).map(function(t){r[t]=s[t]}),l("rect",r)}function g(t,e,i,n){return l("text",{className:t,x:e,y:i,dy:tt/2+"px","font-size":tt+"px",innerHTML:n})}function m(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=et);var s=l("line",{className:"line-vertical "+a.className,x1:0,x2:0,y1:i,y2:n,styles:{stroke:a.stroke}}),r=l("text",{x:0,y:i>n?i+Q:i-Q-tt,dy:tt+"px","font-size":tt+"px","text-anchor":"middle",innerHTML:e}),o=l("g",{transform:"translate("+t+", 0)"});return o.appendChild(s),o.appendChild(r),o}function _(t,e,i,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};a.stroke||(a.stroke=et),a.lineType||(a.lineType="");var s=l("line",{className:"line-horizontal "+a.className+("dashed"===a.lineType?"dashed":""),x1:i,x2:n,y1:0,y2:0,styles:{stroke:a.stroke}}),r=l("text",{x:i255?255:t<0?0:t}function k(t,e){var i=st(t),n=!1;"#"==i[0]&&(i=i.slice(1),n=!0);var a=parseInt(i,16),s=x((a>>16)+e),r=x((a>>8&255)+e),o=x((255&a)+e);return(n?"#":"")+(o|r<<8|s<<16).toString(16)}function b(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}function w(t,e,i){if(t!==e){rt.includes(t)||console.error("'"+t+"' is not a valid chart type."),ot[e].includes(t)||console.error("'"+e+"' chart cannot be converted to a '"+t+"' chart.");var n=lt[e].includes(t);return new wt({parent:i.parent,title:i.title,data:i.data,type:t,height:i.height,colors:n?i.colors:void 0})}}function A(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"linear",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{},r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){var h=void 0;h="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");var c=s[l]||t.getAttribute(l),u=e[l],p={attributeName:l,from:c,to:u,begin:"0s",dur:i/1e3+"s",values:c+";"+u,keySplines:pt[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 C(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function M(t,e){var i=[],n=[];e.map(function(t){var e=t[0],a=e.unit.parentNode,s=void 0,r=void 0;t[0]=e.unit;var o=A.apply(void 0,Z(t)),l=J(o,2);s=l[0],r=l[1],i.push(r),n.push([s,a]),a.replaceChild(s,e.unit),e.array?e.array[e.index]=r:e.object[e.key]=r});var a=t.cloneNode(!0);return n.map(function(t,n){t[1].replaceChild(i[n],t[0]),e[n][0]=i[n]}),a}function L(t,e,i){if(0!==i.length){var n=M(e,i);e.parentNode==t&&(t.removeChild(e),t.appendChild(n)),setTimeout(function(){n.parentNode==t&&(t.removeChild(n),t.appendChild(e))},ut)}}function O(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 P(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 W(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=O(t),n=J(i,2),a=n[0],s=n[1],r=e?e/Math.pow(10,s):0,o=P(a=a.toFixed(6),r);return o=o.map(function(t){return t*Math.pow(10,s)})}function N(t){function e(t,e){for(var i=W(t),n=i[1]-i[0],a=0,s=1;a1&&void 0!==arguments[1]&&arguments[1],n=Math.max.apply(Math,Z(t)),a=Math.min.apply(Math,Z(t)),s=[];if(n>=0&&a>=0)O(n)[1],s=i?W(n,a):W(n);else if(n>0&&a<0){var r=Math.abs(a);n>=r?(O(n)[1],s=e(n,r)):(O(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);O(o)[1],s=(s=i?W(o,l):W(o)).reverse().map(function(t){return-1*t})}return s}function S(t){var e=T(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 T(t){return t[1]-t[0]}function D(t){return t[t.length-1]-t[0]}function j(t,e){for(var i=Math.max.apply(Math,Z(t)),n=1/(e-1),a=[],s=0;s9?"":"0")+e,(i>9?"":"0")+i,t.getFullYear()].join("-")}function U(t,e){return Math.ceil(H(t,e)/7)}function H(t,e){return(E(e)-E(t))/864e5}function Y(t,e){t.setDate(t.getDate()+e)}function F(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"line",e=arguments[1];return bt[t]?new bt[t](e):new vt(e)}!function(t,e){if("undefined"==typeof document)return e;t=t||"";var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}('.chart-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.chart-container .multiaxis-chart .line-horizontal,.chart-container .multiaxis-chart .y-axis-guide{stroke-width:2px}.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,.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 I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X=(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")}),B=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}(),G=.01,Q=4,tt=10,et="#dadada",it=function(){function t(e){X(this,t),this.refreshState(e)}return B(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:"bar",value:function(t,e,i,n,a,s,o,h,c){var u=this.unitWidth-i.spaceWidth,p=u,d=t-u/2,f=r(e,this.zeroLine,this.totalHeight),v=J(f,2),y=v[0];return l("rect",{className:"bar mini",style:"fill: "+n,"data-point-index":a,x:d,y:v[1],width:p,height:y})}},{key:"dot",value:function(t,e,i,n,a){return l("circle",{style:"fill: "+n,"data-point-index":a,cx:t,cy:e,r:i.radius})}},{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=et),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),m(t,e,n,a,{stroke:i.stroke,className:i.className})}},{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=et),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,_(t,e,n,a,{stroke:i.stroke,className:i.className})}},{key:"xMarker",value:function(){}},{key:"yMarker",value:function(){}},{key:"xRegion",value:function(){}},{key:"yRegion",value:function(){}}]),t}(),nt={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"},at=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta"],st=function(t){return nt[t]||t},rt=["line","scatter","bar","percentage","heatmap","pie"],ot={bar:["line","scatter","percentage","pie"],line:["scatter","bar","percentage","pie"],pie:["line","scatter","percentage","bar"],scatter:["line","bar","percentage","pie"],percentage:["bar","line","scatter","pie"],heatmap:[]},lt={bar:["line","scatter"],line:["scatter","bar"],pie:["percentage"],scatter:["line","bar"],percentage:["pie"],heatmap:[]},ht=function(){function e(t){var i=t.height,n=void 0===i?240:i,a=t.title,s=void 0===a?"":a,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);X(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 B(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 $({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.makeChartArea(),this.setComponentParent(),this.makeComponentLayers(),this.renderLegend(),this.setupNavigation(t),this.renderComponents(),this.config.animate&&this.update(this.firstUpdateData)}},{key:"update",value:function(){this.refresh(),this.reRender()}},{key:"calcWidth",value:function(){this.baseWidth=n(this.parent)-0,this.width=this.baseWidth-(this.translateXLeft+this.translateXRight)}},{key:"refresh",value:function(){this.oldState=this.state?Object.assign({},this.state):{},this.intermedState={},this.prepareData(),this.reCalc(),this.refreshRenderer()}},{key:"makeChartArea",value:function(){this.svg=u(this.chartWrapper,"chart",this.baseWidth,this.baseHeight),this.svg_defs=p(this.svg),this.drawArea=d(this.svg,this.type+"-chart","translate("+this.translateXLeft+", "+this.translateY+")")}},{key:"prepareData",value:function(){}},{key:"reCalc",value:function(){}},{key:"refreshRenderer",value:function(){}},{key:"reRender",value:function(){var t=this;if(!(!(arguments.length>0&&void 0!==arguments[0])||arguments[0]))return void this.renderComponents();this.intermedState=this.calcIntermedState(),this.animateComponents(),setTimeout(function(){t.renderComponents()},400)}},{key:"calcIntermedState",value:function(){this.intermedState={}}},{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:"animateComponents",value:function(){this.components.forEach(function(t){return t.animate()})}},{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){i(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:"updateCurrentDataPoint",value:function(){}},{key:"getDifferentChart",value:function(t){return w(t,this.type,this.rawChartArgs)}}]),e}(),ct=function(){function t(e){var i=e.layerClass,n=void 0===i?"":i,a=e.layerTransform,s=void 0===a?"":a,r=e.make,o=e.animate;X(this,t),this.layerClass=n,this.layerTransform=s,this.make=r,this.animate=o,this.layer=void 0,this.store=[]}return B(t,[{key:"refresh",value:function(t){}},{key:"render",value:function(){var t=this;this.store=this.make(),this.layer.textContent="",this.store.forEach(function(e){t.layer.appendChild(e)})}},{key:"setupParent",value:function(t){this.parent=t}},{key:"makeLayer",value:function(){this.layer=d(this.parent,this.layerClass,this.layerTransform)}}]),t}(),ut=(function(t){function e(t){X(this,e);var i=K(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.stores=[],i}V(e,t),B(e,[{key:"refresh",value:function(t){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"refresh",this).call(this,t),this.totalIndices=this.chartState[this.argsKeys[0]].length}},{key:"makeLayer",value:function(){q(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"makeLayer",this).call(this),this.layers=[];for(var t=0;tt.datasetLength?a.slice(0,t.datasetLength):s(a,t.datasetLength-a.length,0):e,i.index=n}),t.noOfDatasets=t.datasets.length,this.prepareYAxis()}},{key:"prepareYAxis",value:function(){this.state.yAxis={labels:[],positions:[]}}},{key:"reCalc",value:function(){var t=this,e=this.state;e.xAxisLabels=this.data.labels,this.calcXPositions(),e.datasetsLabels=this.data.datasets.map(function(t){return t.name}),e.yUnitValues=e.datasets.map(function(t){return t.values}),this.setYAxis(),this.calcYUnits(),this.configUnits(),e.unitTypes=e.datasets.map(function(e){return e.unitArgs?e.unitArgs:t.state.unitArgs})}},{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 a(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=N(e,i);var n=t.labels;t.scaleMultiplier=this.height/D(n);var a=T(n)*t.scaleMultiplier;t.zeroLine=this.height-S(n)*a,t.positions=n.map(function(e){return t.zeroLine-e*t.scaleMultiplier})}},{key:"calcYUnits",value:function(){var t=this.state;t.yUnitPositions=t.yUnitValues.map(function(e){return e.map(function(e){return a(t.zeroLine-e*t.scaleMultiplier)})}),t.yUnitMinimums=new Array(t.datasetLength).fill(9999),t.datasets.map(function(e,i){t.yUnitPositions[i].map(function(e,i){e0}),i=e;if(e.length>this.max_slices){e.sort(function(t,e){return e[0]-t[0]}),i=e.slice(0,this.max_slices-1);var n=0;e.slice(this.max_slices-1).map(function(t){n+=t[0]}),i.push([n,"Rest"]),this.colors[this.max_slices-1]="grey"}this.labels=[],i.map(function(e){t.slice_totals.push(e[0]),t.labels.push(e[1])}),this.legend_totals=this.slice_totals.slice(0,this.max_legend_points)}},{key:"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}(ht),_t=Math.PI/180,xt=function(i){function n(t){X(this,n);var e=K(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 V(n,i),B(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),v=n.getPositionByAngle(p,i),y=t&&s[l],g=void 0,m=void 0;t?(g=y?y.startPosition:d,m=y?y.endPosition:d):(g=d,m=v);var _=e.makeArcPath(g,m),x=f(_,"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:v,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,v)},650,"easein",null,{d:_}])}),t&&L(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){C(t,this.calTranslateByAngle(this.slicesProperties[i])),t.style.fill=k(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 C(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*_t)*e,y:Math.cos(t*_t)*e}}}]),n}(ht),kt=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;X(this,e);var y=K(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||Y(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 V(e,t),B(e,[{key:"validate_colors",value:function(t){if(t.length<5)return 0;var e=1;return t.forEach(function(t){b(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()&&Y(this.first_week_start,-1*this.first_week_start.getDay()),7!==this.last_week_start.getDay()&&Y(this.last_week_start,-1*this.last_week_start.getDay()),this.no_of_cols=U(this.first_week_start+"",this.last_week_start+"")+1}},{key:"calcWidth",value:function(){this.baseWidth=12*(this.no_of_cols+3),this.discrete_domains&&(this.baseWidth+=144)}},{key:"setupLayers",value:function(){this.domain_label_group=this.makeLayer("domain-label-group chart-label"),this.data_groups=this.makeLayer("data-groups","translate(0, 20)")}},{key:"setup_values",value:function(){var t=this;this.domain_label_group.textContent="",this.data_groups.textContent="";var e=Object.keys(this.data).map(function(e){return t.data[e]});this.distribution=j(e,this.distribution_size),this.month_names=["January","February","March","April","May","June","July","August","September","October","November","December"],this.render_all_weeks_and_store_x_values(this.no_of_cols)}},{key:"render_all_weeks_and_store_x_values",value:function(t){var e=new Date(this.first_week_start);this.week_col=0,this.current_month=e.getMonth(),this.months=[this.current_month+""],this.month_weeks={},this.month_start_points=[],this.month_weeks[this.current_month]=0,this.month_start_points.push(13);for(var i=0;ii)break;g.getMonth()-t.getMonth()&&(n=1,this.discrete_domains&&(a=1),this.month_start_points.push(13+12*(e+a))),t=g}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=g("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}(ht),bt={line:vt,bar:ft,multiaxis:gt,scatter:yt,percentage:mt,heatmap:kt,pie:xt},wt=function t(e){return X(this,t),F(e.type,arguments[0])};return wt}(); diff --git a/docs/assets/js/index.js b/docs/assets/js/index.js index 80d5d20..24b0b75 100755 --- a/docs/assets/js/index.js +++ b/docs/assets/js/index.js @@ -8,7 +8,7 @@ let bar_composite_data = { "2013", "2014", "2015", "2016", "2017"], datasets: [{ - "label": "Events", + "name": "Events", "values": report_count_list, // "formatted": report_count_list.map(d => d + " reports") }] @@ -77,29 +77,31 @@ let type_data = { datasets: [ { - label: "Some Data", - values: [18, 40, 30, 35, 8, 52, 17, -4] + name: "Some Data", + values: [18, 40, 30, 35, 8, 52, 17, -4], + axisPosition: 'right' }, { - label: "Another Set", - values: [30, 50, -10, 15, 18, 32, 27, 14] + name: "Another Set", + values: [30, 50, -10, 15, 18, 32, 27, 14], + axisPosition: 'right' }, // { - // label: "Yet Another", + // name: "Yet Another", // values: [15, 20, -3, -15, 58, 12, -17, 37] // } // temp : Stacked // { - // label: "Some Data", + // name: "Some Data", // values:[25, 30, 50, 45, 18, 12, 27, 14] // }, // { - // label: "Another Set", + // name: "Another Set", // values: [18, 20, 30, 35, 8, 7, 17, 4] // }, // { - // label: "Another Set", + // name: "Another Set", // values: [11, 8, 19, 15, 3, 4, 10, 2] // }, ] @@ -109,7 +111,7 @@ let type_chart = new Chart({ parent: "#chart-types", // title: "My Awesome Chart", data: type_data, - type: 'bar', + type: 'multiaxis', height: 250, colors: ['purple', 'magenta'], is_series: 1, @@ -225,8 +227,8 @@ let update_data = { }], "specific_values": [ { - label: "Altitude", - // label: "A very long text", + name: "Altitude", + // name: "A very long text", line_type: "dashed", value: 38 }, diff --git a/src/js/chart.js b/src/js/chart.js index 5ff073e..5d247f4 100644 --- a/src/js/chart.js +++ b/src/js/chart.js @@ -3,6 +3,7 @@ import '../scss/charts.scss'; import BarChart from './charts/BarChart'; import LineChart from './charts/LineChart'; import ScatterChart from './charts/ScatterChart'; +import MultiAxisChart from './charts/MultiAxisChart'; import PercentageChart from './charts/PercentageChart'; import PieChart from './charts/PieChart'; import Heatmap from './charts/Heatmap'; @@ -18,6 +19,7 @@ import Heatmap from './charts/Heatmap'; const chartTypes = { line: LineChart, bar: BarChart, + multiaxis: MultiAxisChart, scatter: ScatterChart, percentage: PercentageChart, heatmap: Heatmap, diff --git a/src/js/charts/AxisChart.js b/src/js/charts/AxisChart.js index 080fc5e..3e032c5 100644 --- a/src/js/charts/AxisChart.js +++ b/src/js/charts/AxisChart.js @@ -1,5 +1,6 @@ import BaseChart from './BaseChart'; -import { ChartComponent, IndexedChartComponent } from '../objects/ChartComponent'; +import { Y_AXIS_MARGIN } from '../utils/margins'; +import { ChartComponent } from '../objects/ChartComponent'; import { getOffset, fire } from '../utils/dom'; import { AxisChartRenderer, makePath, makeGradient } from '../utils/draw'; import { equilizeNoOfElements } from '../utils/draw-utils'; @@ -14,9 +15,15 @@ export default class AxisChart extends BaseChart { this.is_series = args.is_series; this.format_tooltip_y = args.format_tooltip_y; this.format_tooltip_x = args.format_tooltip_x; + this.zeroLine = this.height; } + setHorizontalMargin() { + this.translateXLeft = Y_AXIS_MARGIN; + this.translateXRight = Y_AXIS_MARGIN; + } + checkData(data) { return true; } @@ -27,7 +34,10 @@ export default class AxisChart extends BaseChart { prepareData() { let s = this.state; + s.xAxisLabels = this.data.labels || []; + s.xAxisPositions = []; + s.datasetLength = s.xAxisLabels.length; let zeroArray = new Array(s.datasetLength).fill(0); @@ -60,6 +70,16 @@ export default class AxisChart extends BaseChart { }); s.noOfDatasets = s.datasets.length; + + // s.yAxis = []; + this.prepareYAxis(); + } + + prepareYAxis() { + this.state.yAxis = { + labels: [], + positions: [] + }; } reCalc() { @@ -70,15 +90,15 @@ export default class AxisChart extends BaseChart { this.calcXPositions(); // Y - s.datasetsLabels = this.data.datasets.map(d => d.label); + s.datasetsLabels = this.data.datasets.map(d => d.name); // s.yUnitValues = [[]]; indexed component // s.yUnitValues = [[[12, 34, 68], [10, 5, 46]], [[20, 20, 20]]]; // array of indexed components s.yUnitValues = s.datasets.map(d => d.values); // indexed component - s.yAxisLabels = calcIntervals(this.getAllYValues(), this.type === 'line'); - this.calcYAxisPositions(); - this.calcYUnitPositions(); + this.setYAxis(); + + this.calcYUnits(); // should be state this.configUnits(); @@ -87,6 +107,11 @@ export default class AxisChart extends BaseChart { s.unitTypes = s.datasets.map(d => d.unitArgs ? d.unitArgs : this.state.unitArgs); } + setYAxis() { + this.calcYAxisParameters(this.state.yAxis, this.getAllYValues(), this.type === 'line'); + this.state.zeroLine = this.state.yAxis.zeroLine; + } + calcXPositions() { let s = this.state; this.setUnitWidthAndXOffset(); @@ -96,18 +121,18 @@ export default class AxisChart extends BaseChart { s.xUnitPositions = new Array(s.noOfDatasets).fill(s.xAxisPositions); } - calcYAxisPositions() { - let s = this.state; - const yPts = s.yAxisLabels; + calcYAxisParameters(yAxis, dataValues, withMinimum = 'false') { + yAxis.labels = calcIntervals(dataValues, withMinimum); + const yPts = yAxis.labels; - s.scaleMultiplier = this.height / getValueRange(yPts); - const intervalHeight = getIntervalSize(yPts) * s.scaleMultiplier; - s.zeroLine = this.height - (getZeroIndex(yPts) * intervalHeight); + yAxis.scaleMultiplier = this.height / getValueRange(yPts); + const intervalHeight = getIntervalSize(yPts) * yAxis.scaleMultiplier; + yAxis.zeroLine = this.height - (getZeroIndex(yPts) * intervalHeight); - s.yAxisPositions = yPts.map(d => s.zeroLine - d * s.scaleMultiplier); + yAxis.positions = yPts.map(d => yAxis.zeroLine - d * yAxis.scaleMultiplier); } - calcYUnitPositions() { + calcYUnits() { let s = this.state; s.yUnitPositions = s.yUnitValues.map(values => values.map(val => floatTwo(s.zeroLine - val * s.scaleMultiplier)) @@ -143,6 +168,105 @@ export default class AxisChart extends BaseChart { // } + setupValues() {} + + setupComponents() { + // temp : will be an indexedchartcomponent + // this.yAxisAux = new ChartComponent({ + // layerClass: 'y axis aux', + // make: (renderer, positions, values) => { + // positions = [0, 70, 140, 270]; + // values = [300, 200, 100, 0]; + // return positions.map((position, i) => renderer.yLine(position, values[i], 'right')); + // }, + // animate: () => {} + // }); + + this.setupYAxesComponents(); + + this.xAxis = new ChartComponent({ + layerClass: 'x axis', + make: () => { + let s = this.state; + return s.xAxisPositions.map((position, i) => + this.renderer.xLine(position, s.xAxisLabels[i], {pos:'top'}) + ); + }, + // animate: (animator, lines, oldX, newX) => { + // lines.map((xLine, i) => { + // elements_to_animate.push(animator.verticalLine( + // xLine, newX[i], oldX[i] + // )); + // }); + // } + }); + + // this.dataUnits = new IndexedChartComponent({ + // layerClass: 'dataset-units', + // make: (renderer, xPosSet, yPosSet, color, unitType, + // yValueSet, datasetIndex, noOfDatasets) => {; + + // let unitSet = yPosSet.map((y, i) => { + // return renderer[unitType.type]( + // xPosSet[i], + // y, + // unitType.args, + // color, + // i, + // datasetIndex, + // noOfDatasets + // ); + // }); + + // if(this.type === 'line') { + // let pointsList = yPosSet.map((y, i) => (xPosSet[i] + ',' + y)); + // let pointsStr = pointsList.join("L"); + + // unitSet.unshift(makePath("M"+pointsStr, 'line-graph-path', color)); + // } + + // return unitSet; + // }, + // argsKeys: ['xUnitPositions', 'yUnitPositions', + // 'colors', 'unitTypes', 'yUnitValues'], + // animate: () => {} + // }); + + // TODO: rebind new units + // if(this.isNavigable) { + // this.bind_units(units_array); + // } + + this.yMarkerLines = {}; + this.xMarkerLines = {}; + + // Marker Regions + + this.components = [ + // temp + // this.yAxesAux, + ...this.yAxesComponents, + this.xAxis, + // this.yMarkerLines, + // this.xMarkerLines, + + // this.dataUnits, + ]; + } + + setupYAxesComponents() { + this.yAxesComponents = [ new ChartComponent({ + layerClass: 'y axis', + make: () => { + let s = this.state; + return s.yAxis.positions.map((position, i) => + this.renderer.yLine(position, s.yAxis.labels[i], {pos:'right'}) + ); + }, + animate: () => {} + })]; + } + refreshRenderer() { // These args are basically the current state of the chart, // with constant and alive params mixed @@ -163,93 +287,4 @@ export default class AxisChart extends BaseChart { } } - setupComponents() { - // temp : will be an indexedchartcomponent - // this.yAxisAux = new ChartComponent({ - // layerClass: 'y axis aux', - // make: (renderer, positions, values) => { - // positions = [0, 70, 140, 270]; - // values = [300, 200, 100, 0]; - // return positions.map((position, i) => renderer.yLine(position, values[i], 'right')); - // }, - // argsKeys: ['yAxisPositions', 'yAxisLabels'], - // animate: () => {} - // }); - - this.yAxis = new ChartComponent({ - layerClass: 'y axis', - make: (renderer, positions, values) => { - return positions.map((position, i) => renderer.yLine(position, values[i])); - }, - argsKeys: ['yAxisPositions', 'yAxisLabels'], - animate: () => {} - }); - - this.xAxis = new ChartComponent({ - layerClass: 'x axis', - make: (renderer, positions, values) => { - return positions.map((position, i) => renderer.xLine(position, values[i])); - }, - argsKeys: ['xAxisPositions', 'xAxisLabels'], - animate: (animator, lines, oldX, newX) => { - lines.map((xLine, i) => { - elements_to_animate.push(animator.verticalLine( - xLine, newX[i], oldX[i] - )); - }); - } - }); - - this.dataUnits = new IndexedChartComponent({ - layerClass: 'dataset-units', - make: (renderer, xPosSet, yPosSet, color, unitType, - yValueSet, datasetIndex, noOfDatasets) => {; - - let unitSet = yPosSet.map((y, i) => { - return renderer[unitType.type]( - xPosSet[i], - y, - unitType.args, - color, - i, - datasetIndex, - noOfDatasets - ); - }); - - if(this.type === 'line') { - let pointsList = yPosSet.map((y, i) => (xPosSet[i] + ',' + y)); - let pointsStr = pointsList.join("L"); - - unitSet.unshift(makePath("M"+pointsStr, 'line-graph-path', color)); - } - - return unitSet; - }, - argsKeys: ['xUnitPositions', 'yUnitPositions', - 'colors', 'unitTypes', 'yUnitValues'], - animate: () => {} - }); - - // TODO: rebind new units - // if(this.isNavigable) { - // this.bind_units(units_array); - // } - - this.yMarkerLines = {}; - this.xMarkerLines = {}; - - // Marker Regions - - this.components = [ - // temp - // this.yAxisAux, - this.yAxis, - this.xAxis, - // this.yMarkerLines, - // this.xMarkerLines, - this.dataUnits, - ]; - } - } diff --git a/src/js/charts/BaseChart.js b/src/js/charts/BaseChart.js index bb3dc70..14d820f 100644 --- a/src/js/charts/BaseChart.js +++ b/src/js/charts/BaseChart.js @@ -26,6 +26,7 @@ export default class BaseChart { this.parent = typeof parent === 'string' ? document.querySelector(parent) : parent; this.title = title; this.subtitle = subtitle; + this.argHeight = height; this.isNavigable = isNavigable; if(this.isNavigable) { @@ -40,7 +41,6 @@ export default class BaseChart { // showLegend, which then all functions will check this.setColors(); - this.setMargins(args); // constants this.config = { @@ -73,12 +73,19 @@ export default class BaseChart { this.colors = this.colors.map(color => getColor(color)); } - setMargins(args) { - let height = args.height; + setMargins() { + // TODO: think for all + let height = this.argHeight; this.baseHeight = height; - this.height = height - 40; - this.translateX = 60; - this.translateY = 10; + this.height = height - 40; // change + this.translateY = 20; + + this.setHorizontalMargin(); + } + + setHorizontalMargin() { + this.translateXLeft = 60; + this.translateXRight = 40; } validate(){ @@ -120,7 +127,10 @@ export default class BaseChart { _setup() { this.bindWindowEvents(); this.setupConstants(); + this.prepareData(); this.setupComponents(); + + this.setMargins(); this.makeContainer(); this.makeTooltip(); // without binding this.draw(true); @@ -204,15 +214,16 @@ export default class BaseChart { // } // }); this.baseWidth = getElementContentWidth(this.parent) - outerAnnotationsWidth; - this.width = this.baseWidth - this.translateX * 2; + this.width = this.baseWidth - (this.translateXLeft + this.translateXRight); } refresh() { //?? refresh? this.oldState = this.state ? Object.assign({}, this.state) : {}; + this.intermedState = {}; + this.prepareData(); this.reCalc(); this.refreshRenderer(); - this.refreshComponents(); } makeChartArea() { @@ -227,7 +238,7 @@ export default class BaseChart { this.drawArea = makeSVGGroup( this.svg, this.type + '-chart', - `translate(${this.translateX}, ${this.translateY})` + `translate(${this.translateXLeft}, ${this.translateY})` ); } @@ -245,7 +256,6 @@ export default class BaseChart { return; } this.intermedState = this.calcIntermedState(); - this.refreshComponents(); this.animateComponents(); setTimeout(() => { this.renderComponents(); @@ -254,22 +264,15 @@ export default class BaseChart { // (opt, should not redraw if still in animate?) } - calcIntermedState() {} + calcIntermedState() { + this.intermedState = {}; + } // 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()); } animateComponents() { this.components.forEach(c => c.animate()); } - refreshComponents() { - let args = { - chartState: this.state, - oldChartState: this.oldState, - intermedState: this.intermedState, - chartRenderer: this.renderer - }; - this.components.forEach(c => c.refresh(args)); - } renderLegend() {} diff --git a/src/js/charts/MultiAxisChart.js b/src/js/charts/MultiAxisChart.js new file mode 100644 index 0000000..a565b1e --- /dev/null +++ b/src/js/charts/MultiAxisChart.js @@ -0,0 +1,100 @@ +import AxisChart from './AxisChart'; +import { Y_AXIS_MARGIN } from '../utils/margins'; +import { ChartComponent } from '../objects/ChartComponent'; + +export default class MultiAxisChart extends AxisChart { + constructor(args) { + super(args); + this.type = 'multiaxis'; + this.unitType = args.unitType || 'line'; + this.setup(); + } + + setHorizontalMargin() { + let noOfLeftAxes = this.data.datasets.filter(d => d.axisPosition === 'left').length; + this.translateXLeft = (noOfLeftAxes) * Y_AXIS_MARGIN; + this.translateXRight = (this.data.datasets.length - noOfLeftAxes) * Y_AXIS_MARGIN || Y_AXIS_MARGIN; + } + + prepareYAxis() { + this.state.yAxes = []; + let sets = this.state.datasets; + // let axesLeft = sets.filter(d => d.axisPosition === 'left'); + // let axesRight = sets.filter(d => d.axisPosition === 'right'); + // let axesNone = sets.filter(d => !d.axisPosition || + // !['left', 'right'].includes(d.axisPosition)); + + let leftCount = 0, rightCount = 0; + + sets.forEach((d, i) => { + this.state.yAxes.push({ + position: d.axisPosition, + color: d.color, + dataValues: d.values, + index: d.axisPosition === 'left' ? leftCount++ : rightCount++ + }); + }); + } + + configure(args) { + super.configure(args); + this.config.xAxisMode = args.xAxisMode || 'tick'; + this.config.yAxisMode = args.yAxisMode || 'span'; + } + + // setUnitWidthAndXOffset() { + // this.state.unitWidth = this.width/(this.state.datasetLength); + // this.state.xOffset = this.state.unitWidth/2; + // } + + configUnits() { + this.state.unitArgs = { + type: 'bar', + args: { + spaceWidth: this.state.unitWidth/2, + } + }; + } + + setYAxis() { + this.state.yAxes.map(yAxis => { + // console.log(yAxis); + this.calcYAxisParameters(yAxis, yAxis.dataValues, this.unitType === 'line'); + // console.log(yAxis); + }); + } + + setupYAxesComponents() { + this.yAxesComponents = this.state.yAxes.map((e, i) => { + return new ChartComponent({ + layerClass: 'y axis y-axis-' + i, + make: () => { + let d = this.state.yAxes[i]; + this.renderer.setZeroline(d.zeroline); + let axis = d.positions.map((position, j) => + this.renderer.yLine(position, d.labels[j], { + pos: d.position, + mode: 'tick', + offset: d.index * Y_AXIS_MARGIN, + stroke: this.colors[i] + }) + ); + + let guidePos = d.position === 'left' + ? -1 * d.index * Y_AXIS_MARGIN + : this.width + d.index * Y_AXIS_MARGIN; + + axis.push(this.renderer.xLine(guidePos, '', { + pos:'top', + mode: 'span', + stroke: this.colors[i], + className: 'y-axis-guide' + })); + + return axis; + }, + animate: () => {} + }); + }); + } +} diff --git a/src/js/objects/ChartComponent.js b/src/js/objects/ChartComponent.js index 6e9f98d..c75ebdc 100644 --- a/src/js/objects/ChartComponent.js +++ b/src/js/objects/ChartComponent.js @@ -5,31 +5,21 @@ export class ChartComponent { layerClass = '', layerTransform = '', make, - argsKeys, animate }) { this.layerClass = layerClass; // 'y axis' this.layerTransform = layerTransform; this.make = make; - this.argsKeys = argsKeys;//['yAxisPositions', 'yAxisLabels']; this.animate = animate; this.layer = undefined; this.store = []; //[[]] depends on indexed } - refresh(args) { - this.chartState = args.chartState; - this.oldChartState = args.oldChartState; - this.intermedState = args.intermedState; - - this.chartRenderer = args.chartRenderer; - } + refresh(args) {} render() { - let args = this.argsKeys.map(key => this.chartState[key]); - args.unshift(this.chartRenderer); - this.store = this.make(...args); + this.store = this.make(); this.layer.textContent = ''; this.store.forEach(element => { @@ -79,7 +69,6 @@ export class IndexedChartComponent extends ChartComponent { // i.e.: [ [[0,0,0], [1,1,1]], ... ] for(var i = 0; i < this.totalIndices; i++) { let args = datasetArrays.map(datasetArray => datasetArray[i]); - args.unshift(this.chartRenderer); args.push(i); args.push(this.totalIndices); diff --git a/src/js/utils/draw.js b/src/js/utils/draw.js index f134a5e..75ff451 100644 --- a/src/js/utils/draw.js +++ b/src/js/utils/draw.js @@ -3,6 +3,7 @@ import { getBarHeightAndYAttr } from './draw-utils'; const AXIS_TICK_LENGTH = 6; const LABEL_MARGIN = 4; const FONT_SIZE = 10; +const BASE_LINE_COLOR = '#dadada'; function $(expr, con) { return typeof expr === "string"? (con || document).querySelector(expr) : expr || null; @@ -138,20 +139,22 @@ export function makeText(className, x, y, content) { }); } -export function makeVertXLine(x, label, totalHeight, mode, stroke='#dadada') { - let height = mode === 'span' ? -1 * AXIS_TICK_LENGTH : totalHeight; - +export function makeVertLine(x, label, y1, y2, options={}) { + if(!options.stroke) options.stroke = BASE_LINE_COLOR; let l = createSVG('line', { + className: 'line-vertical ' + options.className, x1: 0, x2: 0, - y1: totalHeight + AXIS_TICK_LENGTH, - y2: height, - stroke: stroke + y1: y1, + y2: y2, + styles: { + stroke: options.stroke + } }); let text = createSVG('text', { x: 0, - y: totalHeight + AXIS_TICK_LENGTH + LABEL_MARGIN, + y: y1 > y2 ? y1 + LABEL_MARGIN : y1 - LABEL_MARGIN - FONT_SIZE, dy: FONT_SIZE + 'px', 'font-size': FONT_SIZE + 'px', 'text-anchor': 'middle', @@ -168,50 +171,34 @@ export function makeVertXLine(x, label, totalHeight, mode, stroke='#dadada') { return line; } -export function makeHoriYLine(y, label, totalWidth, mode, pos='left') { - let lineType = ''; - let w2 = mode === 'span' ? totalWidth + AXIS_TICK_LENGTH : 0; - - // temp : works correctly - let x1, x2, textX, anchor; - if(mode === 'tick') { - if(pos === 'right') { - x1 = totalWidth; - x2 = totalWidth + AXIS_TICK_LENGTH; - textX = totalWidth + AXIS_TICK_LENGTH + LABEL_MARGIN; - anchor = 'start'; - } else { - x1 = -1 * AXIS_TICK_LENGTH; - x2 = w2; - textX = -1 * (LABEL_MARGIN + AXIS_TICK_LENGTH); - anchor = 'end'; - } - } else { - x1 = -1 * AXIS_TICK_LENGTH; - x2 = w2; - textX = -1 * (LABEL_MARGIN + AXIS_TICK_LENGTH); - anchor = 'end'; - } +export function makeHoriLine(y, label, x1, x2, options={}) { + if(!options.stroke) options.stroke = BASE_LINE_COLOR; + if(!options.lineType) options.lineType = ''; + let className = 'line-horizontal ' + options.className + + (options.lineType === "dashed" ? "dashed": ""); let l = createSVG('line', { - className: lineType === "dashed" ? "dashed": "", + className: className, x1: x1, x2: x2, y1: 0, - y2: 0 + y2: 0, + styles: { + stroke: options.stroke + } }); let text = createSVG('text', { - x: textX, + x: x1 < x2 ? x1 - LABEL_MARGIN : x1 + LABEL_MARGIN, y: 0, dy: (FONT_SIZE / 2 - 2) + 'px', 'font-size': FONT_SIZE + 'px', - 'text-anchor': anchor, + 'text-anchor': x1 < x2 ? 'end' : 'start', innerHTML: label+"" }); let line = createSVG('g', { - transform: `translate(0, ${y})`, + transform: `translate(0, ${ y })`, 'stroke-opacity': 1 }); @@ -239,6 +226,10 @@ export class AxisChartRenderer { this.yAxisMode = state.yAxisMode; } + setZeroline(zeroLine) { + this.zeroLine = zeroLine; + } + bar(x, yTop, args, color, index, datasetIndex, noOfDatasets, prevX, prevY) { let totalWidth = this.unitWidth - args.spaceWidth; @@ -275,14 +266,63 @@ export class AxisChartRenderer { }); } - // temp: stroke - xLine(x, label, pos='bottom', stroke='', mode=this.xAxisMode) { + 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.stroke) options.stroke = BASE_LINE_COLOR; + if(!options.className) options.className = ''; + // Draw X axis line in span/tick mode with optional label - return makeVertXLine(x, label, this.totalHeight, mode); + // y2(span) + // | + // | + // x line | + // | + // | + // ---------------------+-- y2(tick) + // | + // y1 + + let y1 = this.totalHeight + AXIS_TICK_LENGTH; + let y2 = options.mode === 'span' ? -1 * AXIS_TICK_LENGTH : this.totalHeight; + + if(options.mode === 'tick' && options.pos === 'top') { + // top axis ticks + y1 = -1 * AXIS_TICK_LENGTH; + y2 = 0; + } + + return makeVertLine(x, label, y1, y2, { + stroke: options.stroke, + className: options.className + }); } - yLine(y, label, pos='left', mode=this.yAxisMode) { - return makeHoriYLine(y, label, this.totalWidth, mode, pos); + 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; + } + + let offset = options.pos === 'left' ? -1 * options.offset : options.offset; + + x1 += options.offset; + x2 += options.offset; + + return makeHoriLine(y, label, x1, x2, { + stroke: options.stroke, + className: options.className + }); } xMarker() {} diff --git a/src/js/utils/margins.js b/src/js/utils/margins.js new file mode 100644 index 0000000..6664667 --- /dev/null +++ b/src/js/utils/margins.js @@ -0,0 +1 @@ +export const Y_AXIS_MARGIN = 60; \ No newline at end of file diff --git a/src/scss/charts.scss b/src/scss/charts.scss index 6ed247a..14c1d1d 100644 --- a/src/scss/charts.scss +++ b/src/scss/charts.scss @@ -4,6 +4,12 @@ "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + .multiaxis-chart { + .line-horizontal, .y-axis-guide { + stroke-width: 2px; + } + } + .graph-focus-margin { margin: 0px 5%; } @@ -53,9 +59,9 @@ .axis, .chart-label { fill: #555b51; // temp commented - // line { - // stroke: #dadada; - // } + line { + stroke: #dadada; + } } .percentage-graph { .progress {