/*
    *
    * Wijmo Library 5.20181.462
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const wjcChart=require("wijmo/wijmo.chart"),wjcCore=require("wijmo/wijmo"),wjcSelfRef=require("wijmo/wijmo.chart.analytics");var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.chart=window.wijmo.chart||{},window.wijmo.chart.analytics=wjcSelf;class TrendLineBase extends wjcChart.SeriesBase{constructor(t){super(),this._chartType=wjcChart.ChartType.Line,this._sampleCount=100,this.initialize(t)}get sampleCount(){return this._sampleCount}set sampleCount(t){(t=wjcCore.asNumber(t,!1,!0))!=this._sampleCount&&(this._sampleCount=t,this._invalidate())}approximate(t){return 0}getValues(t){var e=this,r=e.binding,i=e.bindingX;return r!==e._bind&&(e._bind=r,e.binding=r),i!==e._bindX&&(e._bindX=i,e.bindingX=i),null==e._originYValues&&(e._originYValues=super.getValues(0)),null==e._originXValues&&(e._originXValues=super.getValues(1)),null==e._originXValues||null==e._originYValues?null:(super.getValues(t),null!=e._xValues&&null!=e._yValues||e._calculateValues(),0===t?e._yValues||null:1===t?e._xValues||null:void 0)}_calculateValues(){}_invalidate(){super._invalidate(),this._clearCalculatedValues()}_clearValues(){super._clearValues(),this._originXValues=null,this._originYValues=null,this._clearCalculatedValues()}_clearCalculatedValues(){this._xValues=null,this._yValues=null}}exports.TrendLineBase=TrendLineBase;class MathHelper{static round(t,e){if(!t)return 0;var r=Math.pow(10,e||2);return Math.round(t*r)/r}static avg(t){return MathHelper.sum(t)/t.length}static sum(t){return(t=wjcCore.asArray(t,!1)).reduce((t,e)=>t+e,0)}static sumOfPow(t,e){return t=wjcCore.asArray(t,!1),e=wjcCore.asNumber(e,!1),t.reduce((t,r)=>t+Math.pow(r,e),0)}static sumProduct(...t){t.length;var e,r,i=0,a=[];for((t=wjcCore.asArray(t,!1)).forEach((t,e)=>{t=wjcCore.asArray(t,!1),0===e?i=t.length:wjcCore.assert(t.length===i,"The length of the arrays must be equal")}),e=0;e<i;e++)r=1,t.some((t,i)=>{var a=t[e];if(!a||!wjcCore.isNumber(a))return r=0,!0;r*=a}),a.push(r);return MathHelper.sum(a)}static variance(t){t=wjcCore.asArray(t,!1);var e,r=MathHelper.avg(t);return e=t.map(t=>t-r),MathHelper.sumOfSquares(e)/(t.length-1)}static covariance(t,e){t=wjcCore.asArray(t,!1),e=wjcCore.asArray(e,!1),wjcCore.assert(t.length===e.length,"Length of arrays must be equal");var r,i=MathHelper.avg(t),a=MathHelper.avg(e),s=t.length,n=0;for(r=0;r<s;r++)n+=(t[r]-i)*(e[r]-a)/s;return n}}MathHelper.min=(t=>Math.min.apply(Math,wjcCore.asArray(t,!1))),MathHelper.max=(t=>Math.max.apply(Math,wjcCore.asArray(t,!1))),MathHelper.square=(t=>Math.pow(wjcCore.asNumber(t,!1),2)),MathHelper.sumOfSquares=(t=>MathHelper.sumOfPow(t,2)),MathHelper.stdDev=(t=>Math.sqrt(MathHelper.variance(t)));var TrendLineFitType;!function(t){t[t.Linear=0]="Linear",t[t.Exponential=1]="Exponential",t[t.Logarithmic=2]="Logarithmic",t[t.Power=3]="Power",t[t.Fourier=4]="Fourier",t[t.Polynomial=5]="Polynomial",t[t.MinX=6]="MinX",t[t.MinY=7]="MinY",t[t.MaxX=8]="MaxX",t[t.MaxY=9]="MaxY",t[t.AverageX=10]="AverageX",t[t.AverageY=11]="AverageY"}(TrendLineFitType=exports.TrendLineFitType||(exports.TrendLineFitType={}));class TrendLine extends TrendLineBase{constructor(t){super(),this._fitType=TrendLineFitType.Linear,this._order=2,this.initialize(t)}get fitType(){return this._fitType}set fitType(t){(t=wjcCore.asEnum(t,TrendLineFitType,!1))!=this._fitType&&(this._fitType=t,this._invalidate())}get order(){return this._order}set order(t){t!=this._order&&(this._order=wjcCore.asNumber(t,!1,!0),this._invalidate())}get coefficients(){return this._helper?this._helper.coefficients:null}approximate(t){return this._helper?this._helper.approximate(t):NaN}getEquation(t){return(this._helper?this._helper.getEquation(t):"").replace(/\S(\+|\-)\d/g,function(t){return t[0]+" "+t[1]+" "+t[2]})}_calculateValues(){var t=TrendLineFitType[this._fitType];if(TrendLineHelper[t]){var e=!1,r=this._originXValues;0==this._chart._xvals.length&&this._chart._xlabels.length>0&&(r=this._originXValues.map(t=>t+1),e=!0);var i=new TrendLineHelper[t](this._originYValues,r,this.sampleCount,this.order);i._isXString=e;var a=i.calculateValues();this._yValues=a[0],this._xValues=a[1],this._helper=i}}}exports.TrendLine=TrendLine;class Calculator{constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}get minX(){return null==this._minX&&(this._minX=MathHelper.min(this._x)),this._minX}get minY(){return null==this._minY&&(this._minY=MathHelper.min(this._y)),this._minY}get maxX(){return null==this._maxX&&(this._maxX=MathHelper.max(this._x)),this._maxX}get maxY(){return null==this._maxY&&(this._maxY=MathHelper.max(this._y)),this._maxY}get averageX(){return null==this._averageX&&(this._averageX=MathHelper.avg(this._x)),this._averageX}get averageY(){return null==this._averageY&&(this._averageY=MathHelper.avg(this._y)),this._averageY}get sumX(){return null==this._sumX&&(this._sumX=MathHelper.sum(this._x)),this._sumX}get sumY(){return null==this._sumY&&(this._sumY=MathHelper.sum(this._y)),this._sumY}get LogX(){return null==this._logX&&(this._logX=this._x.map(t=>Math.log(t))),this._logX}get LogY(){return null==this._logY&&(this._logY=this._y.map(t=>Math.log(t))),this._logY}get sumLogX(){return null==this._sumLogX&&(this._sumLogX=MathHelper.sum(this.LogX)),this._sumLogX}get sumLogY(){return null==this._sumLogY&&(this._sumLogY=MathHelper.sum(this.LogY)),this._sumLogY}get sumOfSquareX(){return null==this._sumOfSquareX&&(this._sumOfSquareX=MathHelper.sumOfSquares(this._x)),this._sumOfSquareX}get sumOfSquareY(){return null==this._sumOfSquareY&&(this._sumOfSquareY=MathHelper.sumOfSquares(this._y)),this._sumOfSquareY}get sumOfSquareLogX(){return null==this._sumOfSquareLogX&&(this._sumOfSquareLogX=MathHelper.sumOfSquares(this.LogX)),this._sumOfSquareLogX}get sumOfSquareLogY(){return null==this._sumOfSquareLogY&&(this._sumOfSquareLogY=MathHelper.sumOfSquares(this.LogY)),this._sumOfSquareLogY}sumProduct(t,e){return null==this._sumProduct&&(this._sumProduct=MathHelper.sumProduct(t,e)),this._sumProduct}}class TrendHelperBase{constructor(t,e,r){this._coefficients=[],this.y=wjcCore.asArray(t),this.x=wjcCore.asArray(e),wjcCore.assert(t.length===e.length,"Length of X and Y arrays are not equal"),this.count=r||t.length,this._calculator=new Calculator(e,t),this.xMin=this._calculator.minX,this.xMax=this._calculator.maxX}get calculator(){return this._calculator}get y(){return this._y}set y(t){t!==this.y&&(this._y=wjcCore.asArray(t,!1))}get x(){return this._x}set x(t){t!==this.x&&(this._x=wjcCore.asArray(t,!1))}get count(){return this._count}set count(t){t!==this.count&&(this._count=wjcCore.asInt(t,!1,!0))}get xMin(){return this._xMin}set xMin(t){t!==this.xMin&&(this._xMin=wjcCore.asNumber(t,!1))}get xMax(){return this._xMax}set xMax(t){t!==this.xMax&&(this._xMax=wjcCore.asNumber(t,!1))}get coefficients(){return this._coefficients}_calculateCoefficients(){var t=this.calcB(),e=this.calcA(t);this._coefficients.push(e,t)}calculateValues(){for(var t=(this.xMax-this.xMin)/(this.count-1),e=[[],[]],r=0;r<this.count;r++){var i=this.xMin+t*r,a=this.calcY(i);e[0].push(a),this._isXString?e[1].push(i-1):e[1].push(i)}return e}calcA(t){var e=this.y.length,r=this.calculator.sumX;return(this.calculator.sumY-(t=t||this.calcB())*r)/e}calcB(){var t=this.y.length,e=this.calculator,r=e.sumProduct(e.x,e.y),i=e.sumX;return(t*r-i*e.sumY)/(t*e.sumOfSquareX-MathHelper.square(i))}calcY(t){var e=this.coefficients;return e[0]+e[1]*t}approximate(t){return this.calcY(t)}getEquation(t){var t=t||this._defaultEquationFmt;return this._getEquation(t)}_getEquation(t){var e=[];return this.coefficients.forEach(r=>{e.push(t(r))}),this._concatEquation(e)}_concatEquation(t){return""}_defaultEquationFmt(t){var e,r=Math.abs(t),i=String(r),a=0;return r>=1e5?(e=String(Math.round(r)).length-1,Math.round(t/Number("1e"+e))+"e"+e):r<1e-4?(e=i.indexOf("e")>-1?Math.abs(+i.substring(i.indexOf("e")+1)):i.match(/\.0+/)[0].length,Math.round(t*Number("1e"+e))+"e-"+e):(a=t>0?6:7,r>=1e4&&a--,String(+String(t).substring(0,a)))}}class LinearHelper extends TrendHelperBase{get yOffset(){return this._yOffset}set yOffset(t){t!==this.yOffset&&(this._yOffset=wjcCore.asNumber(t,!0))}constructor(t,e,r,i){super(t,e,r),this._calculateCoefficients(),this.yOffset=i}calcA(t){return null!=this.yOffset?this.yOffset:super.calcA(t)}calcB(){return null!=this.yOffset?this._calculateBSimple():super.calcB()}_calculateBSimple(){var t=this.calculator,e=t.sumProduct(t.x,t.y),r=t.sumX,i=t.sumOfSquareX;return(e-this.yOffset*r)/i}_calculateCoefficients(){var t=this.calcB(),e=this.calcA(t);this.coefficients.push(t,e)}calcY(t){var e=this.coefficients;return e[0]*t+e[1]}_concatEquation(t){return"y = "+t[0]+"x"+(this.coefficients[1]>=0?"+":"")+t[1]}}class LogHelper extends TrendHelperBase{constructor(t,e,r){super(t,e,r),this._calculateCoefficients()}calcA(t){var e=this.y.length,r=this.calculator,i=r.sumY,a=r.sumLogX;return(i-(t=t||this.calcB())*a)/e}calcB(){var t=this.y.length,e=this.calculator,r=e.sumProduct(e.y,e.LogX),i=e.sumY,a=e.sumLogX;return(t*r-i*a)/(t*e.sumOfSquareLogX-MathHelper.square(a))}_calculateCoefficients(){var t=this.calcB(),e=this.calcA(t);this.coefficients.push(t,e)}calcY(t){var e=this.coefficients;return Math.log(t)*e[0]+e[1]}_concatEquation(t){return"y = "+t[0]+"ln(x)"+(this.coefficients[1]>=0?"+":"")+t[1]}}class ExpHelper extends TrendHelperBase{constructor(t,e,r){super(t,e,r),this._calculateCoefficients()}calcA(){var t=this.y.length,e=this.calculator,r=e.sumLogY,i=e.sumOfSquareX,a=e.sumX,s=e.sumProduct(e.x,e.LogY);return Math.exp((r*i-a*s)/(t*i-MathHelper.square(a)))}calcB(){var t=this.y.length,e=this.calculator,r=e.sumLogY,i=e.sumOfSquareX,a=e.sumX;return(t*e.sumProduct(e.x,e.LogY)-a*r)/(t*i-MathHelper.square(a))}calcY(t){var e=this.coefficients;return e[0]*Math.exp(e[1]*t)}_concatEquation(t){return"y = "+t[0]+"e<sup>"+t[1]+"x</sup>"}}class PowerHelper extends TrendHelperBase{constructor(t,e,r){super(t,e,r),this._calculateCoefficients()}calcA(t){var e=this.calculator,r=this.y.length,i=e.sumLogX,a=e.sumLogY,t=t||this.calcB();return Math.exp((a-t*i)/r)}calcB(){var t=this.y.length,e=this.calculator,r=e.sumProduct(e.LogX,e.LogY),i=e.sumLogX;return(t*r-i*e.sumLogY)/(t*e.sumOfSquareLogX-MathHelper.square(i))}calcY(t){var e=this.coefficients;return e[0]*Math.pow(t,e[1])}_concatEquation(t){return"y = "+t[0]+"x<sup>"+t[1]+"</sup>"}}class LeastSquaresHelper extends TrendHelperBase{constructor(t,e,r,i){super(t,e,r),this._order=null==i?2:i,this._basis=[],this._calculateCoefficients()}get basis(){return this._basis}get order(){return this._order}set order(t){this._order=wjcCore.asNumber(t,!0)}_calculateCoefficients(){this._coefficients.length=this.order,this._createBasis(),this._normalizeAndSolveGauss()}_createBasis(){var t=this.x.length,e=this.order;if(t<2)throw"Incompatible data: Less than 2 data points.";if(e<1)throw"Incompatible data: Less than 1 coefficient in the fit";if(e>t)throw"Incompatible data: Number of data points less than number of terms"}_normalizeAndSolveGauss(){var t=[];if(this._computeNormalEquations(t),this._genDefValForArray(t,0),!this._solveGauss(t))throw"Incompatible data: No solution."}_genDefValForArray(t,e){var r=t.length+1;t.forEach(t=>{for(var i=0;i<r;i++)null==t[i]&&(t[i]=e)})}_computeNormalEquations(t){var e,r,i,a,s=this.y,n=this.basis,l=this.order,h=s.length;for(e=0;e<l;e++)for(i=0,null==t[e]&&(t[e]=[]),s.forEach((t,r)=>{i+=t*n[r][e]}),t[e][l]=i,r=e;r<l;r++){for(i=0,a=0;a<h;a++)i+=n[a][r]*n[a][e];null==t[r]&&(t[r]=[]),t[r][e]=i,t[e][r]=i}}_solveGauss(t){var e,r,i=t.length,a=this._coefficients,s=!0;if(a.length<i||t[0].length<i+1)throw"Dimension of matrix is not correct.";if(t.some((e,a)=>{var n,l,h=a,o=Math.abs(e[a]);for(r=a+1;r<i;r++)o<(n=Math.abs(t[r][a]))&&(o=n,h=r);if(!(o>0))return s=!1,!0;for(r=a;r<=i;r++)l=t[a][r],t[a][r]=t[h][r],t[h][r]=l;for(h=a+1;h<i;h++)for(l=t[h][a]/e[a],t[h][a]=0,r=a+1;r<=i;r++)t[h][r]-=l*e[r]}),s)for(e=i-1;e>=0;e--){for(a[e]=t[e][i],r=e+1;r<i;r++)a[e]-=t[e][r]*a[r];a[e]=a[e]/t[e][e]}return s}}class PolyHelper extends LeastSquaresHelper{constructor(t,e,r,i){super(t,e,r,i)}get coefficients(){return this._coefficients.slice(0).reverse()}calcY(t){var e=0,r=1;return this._coefficients.forEach((i,a)=>{a>0&&(r*=t),e+=i*r}),e}_calculateCoefficients(){this._coefficients;this.order++,super._calculateCoefficients(),this.order--}_createBasis(){super._createBasis();var t=this.x,e=this.basis,r=this.order;t.forEach((t,i)=>{e[i]=[1];for(var a=1;a<=r;a++)e[i][a]=t*e[i][a-1]})}_concatEquation(t){var e="y = ",r=t.length,i=this.coefficients;return t.forEach(function(t,a){var s,n=r-1-a;0===n?e+=t:1===n?(s=i[a+1]>=0?"+":"",e+=t+"x"+s):(s=i[a+1]>=0?"+":"",e+=t+"x<sup>"+n+"</sup>"+s)}),e}}class FourierHelper extends LeastSquaresHelper{constructor(t,e,r,i){super(t,e,r,i=null==i?e.length:i)}_createBasis(){super._createBasis();var t=this.x,e=this.basis,r=this.order;t.forEach((t,i)=>{var a,s;for(e[i]=[1],a=1;a<r;a++)s=Math.floor((a+1)/2),a%2==1?e[i].push(Math.cos(s*t)):e[i].push(Math.sin(s*t))})}calcY(t){var e;return this._coefficients.forEach((r,i)=>{var a,s=Math.floor((i+1)/2);0===i?e=r:(a=s*t,e+=i%2==1?r*Math.cos(a):r*Math.sin(a))}),e}_concatEquation(t){var e="y = ",r=t.length,i=this.coefficients;return t.forEach(function(t,a){var s=a===r-1?"":i[a+1]>=0?"+":"",n="",l=Math.ceil(a/2);if(0===a)e+=t+s;else{n=a%2==1?"cos":"sin";n+="("+(1===l?"":String(l))+"x)",e+=t+n+s}}),e}}class SimpleTrendHelper extends TrendHelperBase{constructor(t,e,r){super(t,e,r),this._calculateCoefficients()}_setVal(t){this._val=t}calcY(t){return this._val}}class MinXHelper extends SimpleTrendHelper{constructor(t,e,r){super(t,e,r)}calculateValues(){var t,e,r=this.xMin,i=MathHelper.min(this.y),a=MathHelper.max(this.y);return this._isXString&&(r-=1),t=[r,r],e=[i,a],this._setVal(r),[e,t]}getEquation(t){var e=this.xMin;return this._isXString&&(e-=1),t&&(e=t(e)),"x = "+e}}class MinYHelper extends SimpleTrendHelper{constructor(t,e,r){super(t,e,r)}calculateValues(){var t,e,r=this.xMin,i=this.xMax,a=MathHelper.min(this.y);return this._isXString&&(r-=1,i-=1),t=[r,i],e=[a,a],this._setVal(a),[e,t]}getEquation(t){var e=MathHelper.min(this.y);return t&&(e=t(e)),"y = "+e}}class MaxXHelper extends SimpleTrendHelper{constructor(t,e,r){super(t,e,r)}calculateValues(){var t,e,r=this.xMax,i=MathHelper.min(this.y),a=MathHelper.max(this.y);return this._isXString&&(r-=1),t=[r,r],e=[i,a],this._setVal(r),[e,t]}getEquation(t){var e=this.xMax;return this._isXString&&(e-=1),t&&(e=t(e)),"x = "+e}}class MaxYHelper extends SimpleTrendHelper{constructor(t,e,r){super(t,e,r)}calculateValues(){var t,e,r=this.xMin,i=this.xMax,a=MathHelper.max(this.y);return this._isXString&&(r-=1,i-=1),t=[r,i],e=[a,a],this._setVal(a),[e,t]}getEquation(t){var e=MathHelper.max(this.y);return t&&(e=t(e)),"y = "+e}}class AverageXHelper extends SimpleTrendHelper{constructor(t,e,r){super(t,e,r)}calculateValues(){var t,e,r=MathHelper.avg(this.x),i=MathHelper.min(this.y),a=MathHelper.max(this.y);return this._isXString&&(r-=1),t=[r,r],e=[i,a],this._setVal(r),[e,t]}_getEquation(t){var e=MathHelper.avg(this.x);return this._isXString&&(e-=1),t&&(e=t(e))," x ="+e}_defaultEquationFmt(t){return Math.abs(t)<1e5?super._defaultEquationFmt(t):""+MathHelper.round(t,2)}}class AverageYHelper extends SimpleTrendHelper{constructor(t,e,r){super(t,e,r)}calculateValues(){var t,e,r=MathHelper.avg(this.y),i=this.xMin,a=this.xMax;return this._isXString&&(i-=1,a-=1),t=[i,a],e=[r,r],this._setVal(r),[e,t]}_getEquation(t){return"y = "+t(MathHelper.avg(this.y))}_defaultEquationFmt(t){return Math.abs(t)<1e5?super._defaultEquationFmt(t):""+MathHelper.round(t,2)}}var TrendLineHelper={TrendHelperBase:TrendHelperBase,Linear:LinearHelper,Exponential:ExpHelper,Logarithmic:LogHelper,Power:PowerHelper,Polynomial:PolyHelper,Fourier:FourierHelper,MinX:MinXHelper,MinY:MinYHelper,MaxX:MaxXHelper,MaxY:MaxYHelper,AverageX:AverageXHelper,AverageY:AverageYHelper};class FunctionSeries extends TrendLineBase{constructor(t){super(),this._min=0,this._max=1,this.initialize(t),null==this.itemsSource&&(this.itemsSource=[new wjcCore.Point(0,0)])}get min(){return this._min}set min(t){this._min!==t&&(this._min=wjcCore.asNumber(t,!1),this._invalidate())}get max(){return this._max}set max(t){this._max!==t&&(this._max=wjcCore.asNumber(t,!1),this._invalidate())}getValues(t){var e=this;return null!=e._xValues&&null!=e._yValues||e._calculateValues(),0===t?e._yValues||null:1===t?e._xValues||null:void 0}_calculateValues(){for(var t,e=this,r=e.sampleCount,i=[],a=[],s=(e.max-e.min)/(r-1),n=0;n<r;n++)t=n===r-1?this.max:this.min+s*n,i[n]=e._calculateX(t),a[n]=e._calculateY(t);e._yValues=a,e._xValues=i}_validateValue(t){return isFinite(t)?t:Number.NaN}_calculateValue(t,e){var r;try{r=t(e)}catch(t){r=Number.NaN}return this._validateValue(r)}_calculateX(t){return 0}_calculateY(t){return 0}}exports.FunctionSeries=FunctionSeries;class YFunctionSeries extends FunctionSeries{constructor(t){super(t)}get func(){return this._func}set func(t){t&&this._func!==t&&(this._func=wjcCore.asFunction(t,!1),this._invalidate())}_calculateX(t){return t}_calculateY(t){return this._calculateValue(this.func,t)}approximate(t){return this._calculateValue(this.func,t)}}exports.YFunctionSeries=YFunctionSeries;class ParametricFunctionSeries extends FunctionSeries{constructor(t){super(t)}get xFunc(){return this._xFunc}set xFunc(t){t&&this._xFunc!==t&&(this._xFunc=wjcCore.asFunction(t,!1),this._invalidate())}get yFunc(){return this._yFunc}set yFunc(t){t&&this._yFunc!==t&&(this._yFunc=wjcCore.asFunction(t,!1),this._invalidate())}_calculateX(t){return this._calculateValue(this.xFunc,t)}_calculateY(t){return this._calculateValue(this.yFunc,t)}approximate(t){var e=this._calculateValue(this.xFunc,t),r=this._calculateValue(this.yFunc,t);return new wjcCore.Point(e,r)}}exports.ParametricFunctionSeries=ParametricFunctionSeries;var MovingAverageType;!function(t){t[t.Simple=0]="Simple",t[t.Weighted=1]="Weighted",t[t.Exponential=2]="Exponential",t[t.Triangular=3]="Triangular"}(MovingAverageType=exports.MovingAverageType||(exports.MovingAverageType={}));class MovingAverage extends TrendLineBase{constructor(t){super(),this._chartType=wjcChart.ChartType.Line,this._type=MovingAverageType.Simple,this._period=2,this.initialize(t)}get type(){return this._type}set type(t){(t=wjcCore.asEnum(t,MovingAverageType,!1))!=this._type&&(this._type=t,this._invalidate())}get period(){return this._period}set period(t){(t=wjcCore.asNumber(t,!1,!0))!=this._period&&(this._period=wjcCore.asNumber(t,!1,!0),this._invalidate())}_checkPeriod(){var t=this.period,e=this._originXValues;t<=1&&wjcCore.assert(!1,"period must be greater than 1."),e&&e.length&&t>=e.length&&wjcCore.assert(!1,"period must be less than itemSource's length.")}_calculateValues(){this._type;var t="_calculate"+MovingAverageType[this._type],e=[],r=[];this._checkPeriod(),this[t]&&this[t].call(this,e,r),this._yValues=r,this._xValues=e}_calculateSimple(t,e,r=!1){for(var i=this._originXValues,a=this._originYValues,s=i.length,n=this._period,l=0,h=0;h<s;h++)l+=a[h]||0,h>=n&&(l-=a[h-n]||0),h>=n-1?(t.push(i[h]),e.push(l/n)):r&&(t.push(i[h]),e.push(l/(h+1)))}_calculateWeighted(t,e){for(var r=this._originXValues,i=this._originYValues,a=r.length,s=this._period,n=s*(s+1)/2,l=0,h=0,o=0;o<a;o++)o>0&&(l+=i[o-1]||0),o>s&&(l-=i[o-s-1]||0),o<s-1?h+=(i[o]||0)*(o+1):(h+=(i[o]||0)*s,o>s-1&&(h-=l),t.push(r[o]),e.push(h/n))}_calculateExponential(t,e){for(var r=this._originXValues,i=this._originYValues,a=r.length,s=this._period,n=0,l=0;l<a;l++)l<=s-2?(n+=i[l]||0,l===s-2&&(n/=s-1)):(n+=2/(s+1)*((i[l]||0)-n),t.push(r[l]),e.push(n))}_calculateTriangular(t,e){var r=this._period,i=[],a=[],s=0;this._calculateSimple(i,a,!0);for(var n=0,l=i.length;n<l;n++)s+=a[n]||0,n>=r&&(s-=a[n-r]||0),n>=r-1&&(t.push(i[n]),e.push(s/r))}}exports.MovingAverage=MovingAverage;class Waterfall extends wjcChart.SeriesBase{constructor(t){super(),this._startLabel="Start",this._relativeData=!0,this._connectorLines=!1,this._showTotal=!1,this._totalLabel="Total",this._getXValues=!1,this._showIntermediateTotal=!1,this._intermediateTotalPos=[],this._chartType=wjcChart.ChartType.Bar,this.rendering.addHandler(this._rendering,this),this.initialize(t)}get relativeData(){return this._relativeData}set relativeData(t){t!=this._relativeData&&(this._relativeData=wjcCore.asBoolean(t,!0),this._invalidate())}get start(){return this._start}set start(t){t!=this._start&&(this._start=wjcCore.asNumber(t,!0),this._invalidate())}get startLabel(){return this._startLabel}set startLabel(t){t!=this._startLabel&&(this._startLabel=wjcCore.asString(t,!1),this._invalidate())}get showTotal(){return this._showTotal}set showTotal(t){t!=this._showTotal&&(this._showTotal=wjcCore.asBoolean(t,!0),this._invalidate())}get totalLabel(){return this._totalLabel}set totalLabel(t){t!=this._totalLabel&&(this._totalLabel=wjcCore.asString(t,!1),this._invalidate())}get showIntermediateTotal(){return this._showIntermediateTotal}set showIntermediateTotal(t){t!=this._showIntermediateTotal&&(this._showIntermediateTotal=wjcCore.asBoolean(t,!1),this._invalidate())}get intermediateTotalPositions(){return this._intermediateTotalPositions}set intermediateTotalPositions(t){t!=this._intermediateTotalPositions&&(this._intermediateTotalPositions=wjcCore.asArray(t,!0),this._invalidate())}get intermediateTotalLabels(){return this._intermediateTotalLabels}set intermediateTotalLabels(t){t!=this._intermediateTotalLabels&&(wjcCore.assert(null==t||wjcCore.isArray(t)||wjcCore.isString(t),"Array or string expected."),this._intermediateTotalLabels=t,this._invalidate())}get connectorLines(){return this._connectorLines}set connectorLines(t){t!=this._connectorLines&&(this._connectorLines=wjcCore.asBoolean(t,!0),this._invalidate())}get styles(){return this._styles}set styles(t){t!=this._styles&&(this._styles=t,this._invalidate())}getValues(t){var e,r,i,a,s=[],n=0;if(e=super.getValues(t),0===t){if(!this._yValues){var s=[],l=0,h=0,o=e&&e.length||0;if(this.relativeData){for(;h<o;h++)l+=isNaN(e[h])?0:e[h],s.push(l);this._yValues=s}else{for(;h<o;h++)l=isNaN(e[h])?0:e[h],s.push(l);this._yValues=s}(r=this._yValues)&&r.length>0&&(this.showIntermediateTotal&&this.intermediateTotalPositions&&this.intermediateTotalPositions.length>0&&(this._intermediateTotalPos=r.slice(),this.intermediateTotalPositions.reduceRight((t,e)=>{var i=0===e?r[0]:r[e-1];return r.length>e?(r.splice(e,0,i),this._intermediateTotalPos.splice(e,0,!0)):r.length===e&&(r.push(i),this._intermediateTotalPos.push(!0)),0},0)),null!=this.start&&(r.splice(0,0,this.start),this._intermediateTotalPos.splice(0,0,!1)),this.showTotal&&r&&r.push(r[r.length-1]))}return this._yValues}if(!this._xValues&&this._getXValues&&(this._xValues=e&&e.slice(),this._getXValues=!1,this._xValues&&this._xValues.length>1&&(o=this._xValues.length,a=this._xValues[o-1],n=Math.abs(this._xValues[o-1]-this._xValues[o-2])),this.chart&&this.chart._xlabels&&this.chart._xlabels.length)){if(i=this.chart._xlabels,this.showIntermediateTotal&&this.intermediateTotalPositions&&this.intermediateTotalPositions.length>0){var u=this.intermediateTotalLabels;u&&this.intermediateTotalPositions.reduceRight((t,e,r)=>{var s="";return s=wjcCore.isString(u)?u:u[r]||"",i.length>e?i.splice(e,0,s):i.length===e&&i.push(s),n&&(a+=n,this._xValues.push(a)),0},0)}null!=this.start&&(i.splice(0,0,this.startLabel),n&&(a+=n,this._xValues.push(a))),this.showTotal&&(i.push(this.totalLabel),n&&(a+=n,this._xValues.push(a)))}return this._xValues}legendItemLength(){return this.showTotal?3:2}measureLegendItem(t,e){var r=this._getName(e);return r?this._measureLegendItem(t,r):new wjcCore.Size(0,0)}drawLegendItem(t,e,r){var i=this._getLegendStyles(r);this._getName(r)&&this._drawLegendItem(t,e,wjcChart.ChartType.Bar,this._getName(r),i,this.symbolStyle)}_clearValues(){super._clearValues(),this._xValues=null,this._yValues=null,this._wfstyle=null,this._getXValues=!0,this._intermediateTotalPos=[],this.chart&&this.chart._performBind()}_invalidate(){super._invalidate(),this._clearValues()}_rendering(t,e){e.cancel=!0,this._wfstyle=null;var r,i,a,s,n,l,h=this.chart,o=this._getAxisY(),u=this._getAxisX(),c=o.origin||0,_=e.engine;if(this._barPlotter=h._getPlotter(this),a=this._barPlotter.rotated,this._barPlotter._getSymbolOrigin||(this._barPlotter._getSymbolOrigin=((t,e,r)=>0===e?t:!0===this._intermediateTotalPos[e]?t:e===r-1&&this.showTotal?t:this._yValues[e-1])),this._barPlotter._getSymbolStyles||(this._barPlotter._getSymbolStyles=((t,e)=>{var r=this._getStyles();return 0===t&&null!=this.start?r.start:!0===this._intermediateTotalPos[t]?r.intermediateTotal:t===e-1&&this.showTotal?r.total:this._yValues[t]<this._yValues[t-1]?r.falling:r.rising})),this._barPlotter.plotSeries(_,u,o,t,h,0,1),this.connectorLines){for(_.startGroup(Waterfall.CSS_CONNECTOR_LINE_GROUP),s=this._barPlotter.hitTester._map[0],l=this._yValues[0]<c,n=s[0].rect,r=1,i=s.length;r<i;r++)!0===this._intermediateTotalPos[r]&&r!==i-1||(this._drawConnectorLine(_,a,n,s[r].rect,l),n=s[r].rect,l=this._yValues[r]<this._yValues[r-1]);_.endGroup()}}_getStyles(){if(this._wfstyle)return this._wfstyle;var t=this._chart.series.indexOf(this),e=this._getSymbolFill(t),r=this._getSymbolStroke(t),i=this.styles||{};return this._wfstyle={start:this._getStyleByKey(i,"start",e,r),intermediateTotal:this._getStyleByKey(i,"intermediateTotal",e,r),total:this._getStyleByKey(i,"total",e,r),falling:this._getStyleByKey(i,"falling","red","red"),rising:this._getStyleByKey(i,"rising","green","green")},this._wfstyle}_getStyleByKey(t,e,r,i){return{fill:t[e]&&t[e].fill?t[e].fill:r,stroke:t[e]&&t[e].stroke?t[e].stroke:i}}_drawConnectorLine(t,e,r,i,a){var s=new wjcCore.Point,n=new wjcCore.Point,l=this.chart.axisY.reversed,h=this.chart.axisX.reversed;l^=a,e?(l?(s.x=r.left,n.x=r.left):(s.x=r.left+r.width,n.x=r.left+r.width),h?(s.y=r.top,n.y=i.top+i.height):(s.y=r.top+r.height,n.y=i.top)):(l?(s.y=r.top+r.height,n.y=r.top+r.height):(s.y=r.top,n.y=r.top),h?(s.x=r.left+r.width,n.x=i.left):(s.x=r.left,n.x=i.left+i.width)),t.drawLine(s.x,s.y,n.x,n.y,Waterfall.CSS_CONNECTOR_LINE,this.styles&&this.styles.connectorLines||{stroke:"black"})}_getLegendStyles(t){if(t<0||null===this.styles)return null;var e=this._getStyles();return 0===t?e.rising:1===t?e.falling:e.total}_getName(t){var e=void 0;if(this.name)if(this.name.indexOf(",")){var r=this.name.split(",");r&&r.length-1>=t&&(e=r[t].trim())}else e=this.name;return e}}Waterfall.CSS_CONNECTOR_LINE_GROUP="water-fall-connector-lines",Waterfall.CSS_CONNECTOR_LINE="water-fall-connector-line",Waterfall.CSS_ENDLABEL="water-fall-end-label",exports.Waterfall=Waterfall;var QuartileCalculation;!function(t){t[t.InclusiveMedian=0]="InclusiveMedian",t[t.ExclusiveMedian=1]="ExclusiveMedian"}(QuartileCalculation=exports.QuartileCalculation||(exports.QuartileCalculation={}));class BoxWhisker extends wjcChart.SeriesBase{constructor(t){super(),this._groupWidth=.8,this._gapWidth=.1,this._showInnerPoints=!1,this._showOutliers=!1,this._quartileCalculation=QuartileCalculation.InclusiveMedian,this._chartType=wjcChart.ChartType.Bar,this.rendering.addHandler(this._rendering,this),this.initialize(t)}_initProperties(t){t&&wjcCore.copy(this,t)}_clearValues(){super._clearValues()}get quartileCalculation(){return this._quartileCalculation}set quartileCalculation(t){(t=wjcCore.asEnum(t,QuartileCalculation,!0))!=this._quartileCalculation&&(this._quartileCalculation=t,this._invalidate())}get groupWidth(){return this._groupWidth}set groupWidth(t){t!=this._groupWidth&&t>=0&&t<=1&&(this._groupWidth=wjcCore.asNumber(t,!0),this._invalidate())}get gapWidth(){return this._gapWidth}set gapWidth(t){t!=this._gapWidth&&t>=0&&t<=1&&(this._gapWidth=wjcCore.asNumber(t,!0),this._invalidate())}get showMeanLine(){return this._showMeanLine}set showMeanLine(t){t!=this._showMeanLine&&(this._showMeanLine=wjcCore.asBoolean(t,!0),this._invalidate())}get meanLineStyle(){return this._meanLineStyle}set meanLineStyle(t){t!=this._meanLineStyle&&(this._meanLineStyle=t,this._invalidate())}get showMeanMarker(){return this._showMeanMarker}set showMeanMarker(t){t!=this._showMeanMarker&&(this._showMeanMarker=wjcCore.asBoolean(t,!0),this._invalidate())}get meanMarkerStyle(){return this._meanMarkerStyle}set meanMarkerStyle(t){t!=this._meanMarkerStyle&&(this._meanMarkerStyle=t,this._invalidate())}get showInnerPoints(){return this._showInnerPoints}set showInnerPoints(t){t!=this._showInnerPoints&&(this._showInnerPoints=wjcCore.asBoolean(t,!0),this._invalidate())}get showOutliers(){return this._showOutliers}set showOutliers(t){t!=this._showOutliers&&(this._showOutliers=wjcCore.asBoolean(t,!0),this._invalidate())}_rendering(t,e){e.cancel=!0;var r,i,a=this,s=a.chart,n=(a.chart,a._getAxisX()),l=a._getAxisY(),h=e.index,o=e.count,u=e.engine,c=this._plotter,_=s.series.indexOf(a),m=wjcCore.asType(a,wjcChart.SeriesBase),d=this.quartileCalculation,g=this.showOutliers,p=this.groupWidth,f=(null==this.gapWidth?.2:this.gapWidth)/2;h=h||0;var x=p/(o=o||1),y=a.getValues(0),v=a.getValues(1);if(y){if(v||(v=c.dataInfo.getXVals()),v){var w=c.dataInfo.getDeltaX();w>0&&(p*=w,x*=w)}var M=m._getSymbolFill(_),S=m._getAltSymbolFill(_)||M,C=m._getSymbolStroke(_),V=m._getAltSymbolStroke(_)||C,L=y.length;null!=v&&(L=Math.min(L,v.length));var b,P,E=0,T=0;if(c.rotated){(E=n.origin||E)<n.actualMin?E=n.actualMin:E>n.actualMax&&(E=n.actualMax);n.convert(E);for(var B=l.actualMin,j=l.actualMax,X=0;X<L;X++){var H=v?v[X]:X,A=y[X];if(null==A||0===A.length)return;if(c._getSymbolOrigin&&l.convert(c._getSymbolOrigin(E,X)),c._getSymbolStyles){var q=c._getSymbolStyles(X);M=q&&q.fill?q.fill:M,S=q&&q.fill?q.fill:S,C=q&&q.stroke?q.fill:C,V=q&&q.stroke?q.fill:V}if(b=A[0]>0?M:S,P=A[0]>0?C:V,u.fill=b,u.stroke=P,wjcChart._DataInfo.isValid(H)&&wjcCore.isArray(A)&&A.length>0&&wjcChart._DataInfo.isValid(A[0])){var Y=H-.5*p+h*x,O=H-.5*p+(h+1)*x,F=(O-Y)*f;if(Y+=F,O-=F,Y<B&&O<B||Y>j&&O>j)continue;Y=l.convert(Y),O=l.convert(O);var N=new _BoxPlot(A,d,g),k={min:n.convert(N.min),max:n.convert(N.max),firstQuartile:n.convert(N.firstQuartile),median:n.convert(N.median),thirdQuartile:n.convert(N.thirdQuartile),mean:n.convert(N.mean),outlierPoints:this._convertPoints(N.outlierPoints,n),innerPoints:this._convertPoints(N.innerPoints,n)},I=new wjcCore.Rect(Math.min(k.min,k.max),Math.min(Y,O),Math.abs(k.max-k.min),Math.abs(O-Y)),Q=new wjcChart._RectArea(I),D={min:Math.min(Y,O),median:(Y+O)/2,max:Math.max(O,Y)};if(s.itemFormatter){u.startGroup();var W=new wjcChart.HitTestInfo(s,new wjcCore.Point((k.min+k.max)/2,D.median),wjcChart.ChartElement.SeriesSymbol);W._setData(a,X),s.itemFormatter(u,W,()=>{this._drawBoxWhisker(u,k,D,r,i,a),r=k,i=D}),u.endGroup()}else this._drawBoxWhisker(u,k,D,r,i,a),r=k,i=D;a._setPointIndex(X,T),T++;var R=new wjcChart._DataPoint(_,X,A,H);R.item=N,Q.tag=R,c.hitTester.add(Q,_)}}}else{(E=l.origin||E)<l.actualMin?E=l.actualMin:E>l.actualMax&&(E=l.actualMax);l.convert(E);for(var G=n.actualMin,z=n.actualMax,X=0;X<L;X++){H=v?v[X]:X;if(null==(A=y[X])||0===A.length)return;if(c._getSymbolOrigin&&l.convert(c._getSymbolOrigin(E,X,L)),c._getSymbolStyles&&(M=(q=c._getSymbolStyles(X,L))&&q.fill?q.fill:M,S=q&&q.fill?q.fill:S,C=q&&q.stroke?q.stroke:C,V=q&&q.stroke?q.stroke:V),b=A[0]>0?M:S,P=A[0]>0?C:V,u.fill=b,u.stroke=P,wjcChart._DataInfo.isValid(H)&&wjcCore.isArray(A)&&A.length>0&&wjcChart._DataInfo.isValid(A[0])){var K=H-.5*p+h*x,U=H-.5*p+(h+1)*x;if(K+=F=(U-K)*f,U-=F,K<G&&U<G||K>z&&U>z)continue;if(K=n.convert(K),U=n.convert(U),!wjcChart._DataInfo.isValid(K)||!wjcChart._DataInfo.isValid(U))continue;var N=new _BoxPlot(A,d,g),k={min:l.convert(N.min),max:l.convert(N.max),firstQuartile:l.convert(N.firstQuartile),median:l.convert(N.median),thirdQuartile:l.convert(N.thirdQuartile),mean:l.convert(N.mean),outlierPoints:this._convertPoints(N.outlierPoints,l),innerPoints:this._convertPoints(N.innerPoints,l)},I=new wjcCore.Rect(Math.min(K,U),Math.min(k.min,k.max),Math.abs(U-K),Math.abs(k.max-k.min)),Q=new wjcChart._RectArea(I),J={min:Math.min(K,U),median:(K+U)/2,max:Math.max(K,U)};s.itemFormatter?(u.startGroup(),(W=new wjcChart.HitTestInfo(s,new wjcCore.Point(J.median,(k.min+k.max)/2),wjcChart.ChartElement.SeriesSymbol))._setData(a,X),s.itemFormatter(u,W,()=>{this._drawBoxWhisker(u,J,k,r,i,a),r=J,i=k}),u.endGroup()):(this._drawBoxWhisker(u,J,k,r,i,a),r=J,i=k),a._setPointIndex(X,T),T++,(R=new wjcChart._DataPoint(_,X,H,A)).item=N,Q.tag=R,c.hitTester.add(Q,_)}}}}}_convertPoints(t,e){return t.map(t=>e.convert(t))}_drawBoxWhisker(t,e,r,i,a,s){var n=s.symbolStyle,l=this.showInnerPoints,h=this.showOutliers,o=this.showMeanLine,u=this.meanLineStyle,c=this.showMeanMarker,_=this.meanMarkerStyle,m=this._plotter;if(t.startGroup("box-plot"),m.rotated){if(t.drawLine(e.min,(r.min+r.median)/2,e.min,(r.max+r.median)/2,null,n),t.drawLine(e.min,r.median,e.firstQuartile,r.median,null,n),t.drawRect(Math.min(e.firstQuartile,e.thirdQuartile),Math.min(r.min,r.max),Math.abs(e.thirdQuartile-e.firstQuartile),Math.abs(r.max-r.min),null,n),t.drawLine(e.median,r.min,e.median,r.max,null,n),t.drawLine(e.max,r.median,e.thirdQuartile,r.median,null,n),t.drawLine(e.max,(r.min+r.median)/2,e.max,(r.max+r.median)/2,null,n),o&&i&&a&&t.drawLine(e.mean,r.median,i.mean,a.median,"box-whisker-mean-line",u||n),c){d=Math.abs(r.median-r.min)/2;t.drawLine(e.mean-d,r.median-d,e.mean+d,r.median+d,null,_||n),t.drawLine(e.mean+d,r.median-d,e.mean-d,r.median+d,null,_||n)}h&&e.outlierPoints.forEach(e=>{t.drawPieSegment(e,r.median,2,0,2*Math.PI,null,n)}),l&&e.innerPoints.forEach(e=>{t.drawPieSegment(e,r.median,2,0,2*Math.PI,null,n)})}else{if(t.drawLine((e.min+e.median)/2,r.min,(e.max+e.median)/2,r.min,null,n),t.drawLine(e.median,r.min,e.median,r.firstQuartile,null,n),t.drawRect(Math.min(e.min,e.max),Math.min(r.firstQuartile,r.thirdQuartile),Math.abs(e.max-e.min),Math.abs(r.thirdQuartile-r.firstQuartile),null,n),t.drawLine(e.min,r.median,e.max,r.median,null,n),t.drawLine(e.median,r.max,e.median,r.thirdQuartile,null,n),t.drawLine((e.min+e.median)/2,r.max,(e.max+e.median)/2,r.max,null,n),o&&i&&a&&t.drawLine(e.median,r.mean,i.median,a.mean,"box-whisker-mean-line",u||n),c){var d=Math.abs(e.median-e.min)/2;t.drawLine(e.median-d,r.mean-d,e.median+d,r.mean+d,null,_||n),t.drawLine(e.median-d,r.mean+d,e.median+d,r.mean-d,null,_||n)}h&&r.outlierPoints.forEach(r=>{t.drawPieSegment(e.median,r,2,0,2*Math.PI,null,n)}),l&&r.innerPoints.forEach(r=>{t.drawPieSegment(e.median,r,2,0,2*Math.PI,null,n)})}t.endGroup()}_renderLabels(t,e,r,i){var a=this,s=this._plotter,n=e.length,l=r.dataLabel,h=l.border,o=l.offset,u=l.connectingLine,c="dataY";s.rotated&&(c="dataX"),void 0===o&&(o=u?16:0),h&&(o-=2);for(var _=0;_<n;_++){var m=e[_],d=m.tag,g=wjcCore.asType(d,wjcChart._DataPoint,!0);if(g){var p=d.item,f=d.y;if(d[c]=p.min,d.yfmt=p.min,d.y=p.min,this._plotter._renderLabel(t,m,g,r,l,a,o,i),d[c]=p.firstQuartile,d.yfmt=p.firstQuartile,d.y=p.firstQuartile,this._plotter._renderLabel(t,m,g,r,l,a,o,i),d[c]=p.median,d.yfmt=p.median,d.y=p.median,this._plotter._renderLabel(t,m,g,r,l,a,o,i),d[c]=p.thirdQuartile,d.yfmt=p.thirdQuartile,d.y=p.thirdQuartile,this._plotter._renderLabel(t,m,g,r,l,a,o,i),d[c]=p.max,d.yfmt=p.max,d.y=p.max,this._plotter._renderLabel(t,m,g,r,l,a,o,i),this.showMeanMarker){let e=Number(p.mean.toFixed(2));d[c]=e,d.yfmt=e,d.y=e,this._plotter._renderLabel(t,m,g,r,l,a,o,i)}p.showOutliers&&p.outlierPoints&&p.outlierPoints.forEach(e=>{d[c]=e,d.yfmt=e,d.y=e,this._plotter._renderLabel(t,m,g,r,l,a,o,i)}),d.y=f}}}}exports.BoxWhisker=BoxWhisker;class _BoxPlot{constructor(t,e,r){this._outlierPoints=[],this._innerPoints=[],this._data=t,this._quartileCalculation=e,this._showOutliers=r,this._parse()}get showOutliers(){return this._showOutliers}get min(){return this._min}get max(){return this._max}get mean(){return this._mean}get firstQuartile(){return this._firstQuartile}get thirdQuartile(){return this._thirdQuartile}get median(){return this._median}get outlierPoints(){return this._outlierPoints}get innerPoints(){return this._innerPoints}_parse(){var t=this._data.length,e=this._data,r=0;this._outlierPoints=[],this._innerPoints=[],e.sort((t,e)=>t-e),e.some(t=>null!=t&&(this._min=t,!0)),this._max=null==e[t-1]?0:e[t-1],this._quartileCalculation===QuartileCalculation.InclusiveMedian?(this._firstQuartile=this._quartileInc(e,.25),this._median=this._quartileInc(e,.5),this._thirdQuartile=this._quartileInc(e,.75)):(this._firstQuartile=this._quartileExc(e,.25),this._median=this._quartileExc(e,.5),this._thirdQuartile=this._quartileExc(e,.75)),this._iqr=1.5*Math.abs(this._thirdQuartile-this._firstQuartile);var i=this._firstQuartile-this._iqr,a=this._thirdQuartile+this._iqr;if(this._showOutliers){var s=this._max;this._max=this._min,this._min=s,this._data.forEach(t=>{r+=t,t<i||t>a?this._outlierPoints.push(t):(t<this._min&&(this._min=t),t>this._max&&(this._max=t))})}else r=this._data.reduce((t,e)=>t+e,0);this._innerPoints=this._data.filter(t=>{if(t>this._min&&t<this._max)return!0}),this._mean=r/t}_quartileInc(t,e){var r,i,a,s,n=t.length;return 1===n?t[0]:(r=(n-1)*e+1,i=Math.floor(r),a=t[i-1],s=r-i,a+(t[i]-a)*s)}_quartileExc(t,e){var r,i,a,s,n=t.length;return 1===n?t[0]:2===n?t[Math.round(e)]:(n+1)%4==0?t[(n+1)*e]:(r=(n+1)*e,i=Math.floor(r),a=t[i-1],s=r-i,a+(t[i]-a)*s)}}exports._BoxPlot=_BoxPlot;var ErrorAmount;!function(t){t[t.FixedValue=0]="FixedValue",t[t.Percentage=1]="Percentage",t[t.StandardDeviation=2]="StandardDeviation",t[t.StandardError=3]="StandardError",t[t.Custom=4]="Custom"}(ErrorAmount=exports.ErrorAmount||(exports.ErrorAmount={}));var ErrorBarEndStyle;!function(t){t[t.Cap=0]="Cap",t[t.NoCap=1]="NoCap"}(ErrorBarEndStyle=exports.ErrorBarEndStyle||(exports.ErrorBarEndStyle={}));var ErrorBarDirection;!function(t){t[t.Both=0]="Both",t[t.Minus=1]="Minus",t[t.Plus=2]="Plus"}(ErrorBarDirection=exports.ErrorBarDirection||(exports.ErrorBarDirection={}));class ErrorBar extends wjcChart.Series{constructor(t){super(),this._errorAmount=ErrorAmount.FixedValue,this._endStyle=ErrorBarEndStyle.Cap,this._direction=ErrorBarDirection.Both,this.rendering.addHandler(this._rendering,this),this.initialize(t)}get value(){return this._value}set value(t){t!=this._value&&(this._value=t,this._invalidate())}get errorAmount(){return this._errorAmount}set errorAmount(t){(t=wjcCore.asEnum(t,ErrorAmount,!0))!=this._errorAmount&&(this._errorAmount=t,this._invalidate())}get errorBarStyle(){return this._errorBarStyle}set errorBarStyle(t){t!=this._errorBarStyle&&(this._errorBarStyle=t,this._invalidate())}get endStyle(){return this._endStyle}set endStyle(t){(t=wjcCore.asEnum(t,ErrorBarEndStyle,!0))!=this._endStyle&&(this._endStyle=t,this._invalidate())}get direction(){return this._direction}set direction(t){(t=wjcCore.asEnum(t,ErrorBarDirection,!0))!=this._direction&&(this._direction=t,this._invalidate())}getDataRect(t,e){if(!t)return null;this._chart;var r,i=this.errorAmount,a=0,s=0;this._paddings=[],this._calculateErrorValue();var n,l,h,o,u=this.getValues(0);if(!u)return t;for(h=0,r=u.length;h<r;h++){var c={plus:0,minus:0},_=this._value||0;switch(o=u[h],i){case ErrorAmount.Custom:c=this._getCustomValue(h),this._paddings.push(c);break;case ErrorAmount.FixedValue:this._paddings.push({plus:_,minus:_});break;case ErrorAmount.Percentage:this._paddings.push({plus:o*_,minus:o*_});break;case ErrorAmount.StandardDeviation:this._paddings.push({plus:this._errorValue*_,minus:this._errorValue*_});break;case ErrorAmount.StandardError:this._paddings.push({plus:this._errorValue,minus:this._errorValue})}(isNaN(n)||n>o-c.minus)&&(n=o-c.minus),(isNaN(l)||l<o+c.plus)&&(l=o+c.plus)}switch(i){case ErrorAmount.FixedValue:a=_,s=_;break;case ErrorAmount.Percentage:a=n*_,s=l*_;break;case ErrorAmount.StandardDeviation:a=this._errorValue*_,s=this._errorValue*_;break;case ErrorAmount.StandardError:a=this._errorValue,s=this._errorValue}return this._showPlus&&(l+=s),this._showMinus&&(n-=a),new wjcCore.Rect(t.left,n,t.width,l-n)}_getCustomValue(t){var e,r=this.value,i={minus:0,plus:0};return null!=this._minusBindingValues||null!=this._plusBindingValues?(i.minus=this._minusBindingValues&&this._minusBindingValues[t]||0,i.plus=this._plusBindingValues&&this._plusBindingValues[t]||0,i):null==r?i:(wjcCore.isArray(r)?((e=r[t])&&e.minus&&(i.minus=e.minus),e&&e.plus&&(i.plus=e.plus)):wjcCore.isNumber(r)?(i.minus=r,i.plus=r):(r.minus&&(i.minus=r.minus),r.plus&&(i.plus=r.plus)),i)}_calculateErrorValue(){var t=0,e=0,r=0;if(this._errorAmount===ErrorAmount.StandardDeviation||this._errorAmount===ErrorAmount.StandardError){var i=this.getValues(0);null!=i&&(i.forEach(r=>{t+=r,e++}),r=t/e,this._mean=r,t=0,i.forEach(e=>{t+=Math.pow(e-r,2)}),this._errorValue=Math.sqrt(t/(e-1))),this._errorAmount==ErrorAmount.StandardError&&(this._errorValue=this._errorValue/Math.sqrt(e))}}_clearValues(){this.__errorValue=null,this._mean=null,this._plusBindingValues=null,this._minusBindingValues=null,super._clearValues()}getValues(t){if(0==t&&this.errorAmount===ErrorAmount.Custom){var e=this._getBinding(1),r=this._getBinding(2);if((null==this._plusBindingValues||null==this._minusBindingValues)&&e&&r)if(null!=this._cv){if(e){i=this._bindValues(this._cv.items,e);this._plusBindingValues=i.values}if(r){a=this._bindValues(this._cv.items,r);this._minusBindingValues=a.values}}else if(null!=this.binding&&null!=this._chart&&null!=this._chart.collectionView){if(e){var i=this._bindValues(this._chart.collectionView.items,e);this._plusBindingValues=i.values}if(r){var a=this._bindValues(this._chart.collectionView.items,r);this._minusBindingValues=a.values}}}return super.getValues(t)}get _chart(){return this.__chart}set _chart(t){t!==this.__chart&&(this.__chart=t)}get _errorValue(){return this.__errorValue}set _errorValue(t){t!=this.__errorValue&&(this.__errorValue=t)}get _showPlus(){return this.direction===ErrorBarDirection.Both||this.direction===ErrorBarDirection.Plus}get _showMinus(){return this.direction===ErrorBarDirection.Both||this.direction===ErrorBarDirection.Minus}_rendering(t,e){e.cancel=!0;var r=this.chart,i=this._getAxisY(),a=this._getAxisX(),s=(i.origin,e.engine);this._plotter.plotSeries(s,a,i,this,r,e.index,e.count,t=>{var e,n,l,h=this._paddings,o=this._showPlus,u=this._showMinus,c=r._isRotated(),_=this.errorBarStyle&&this.errorBarStyle["stroke-width"]||2;l=(n=c?a:i).actualMax,e=n.convert(l);var m=s.stroke,d=s.strokeWidth;s.stroke="black",s.strokeWidth=1,t&&t.length&&t.forEach((t,r)=>{if(null!=t.x&&null!=t.y){var i=h[r],a=i&&i.minus||0,m=i&&i.plus||0,d=Math.abs(n.convert(l-a)-e),g=Math.abs(n.convert(l+m)-e),p=new wjcCore.Point(t.x,t.y),f=new wjcCore.Point(t.x,t.y);c?(this.errorAmount===ErrorAmount.StandardDeviation&&(t=new wjcCore.Point(n.convert(this._mean),t.y),p.x=t.x,f.x=t.x),u&&(p.x=p.x-d),o&&(f.x=f.x+g)):(this.errorAmount===ErrorAmount.StandardDeviation&&(t=new wjcCore.Point(t.x,n.convert(this._mean)),p.y=t.y,f.y=t.y),u&&(p.y=p.y+d),o&&(f.y=f.y-g)),s.drawLine(p.x,p.y,f.x,f.y,"error-bar",this.errorBarStyle),this.endStyle===ErrorBarEndStyle.Cap&&(o&&(c?s.drawLine(f.x,f.y-_,f.x,f.y+_,"error-bar",this.errorBarStyle):s.drawLine(f.x-_,f.y,f.x+_,f.y,"error-bar",this.errorBarStyle)),u&&(c?s.drawLine(p.x,p.y-_,p.x,p.y+_,"error-bar",this.errorBarStyle):s.drawLine(p.x-_,p.y,p.x+_,p.y,"error-bar",this.errorBarStyle)))}}),s.stroke=m,s.strokeWidth=d})}}exports.ErrorBar=ErrorBar;