/*
    *
    * Wijmo Library 5.20182.500
    * 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";function _trunc(e){return wjcCore.asNumber(e,!0,!1),e>0?Math.floor(e):Math.ceil(e)}function _sum(e){return arguments.length>1&&(e=Array.prototype.slice.call(arguments)),wjcCore.asArray(e,!1),e.reduce((e,t)=>e+wjcCore.asNumber(t),0)}function _average(e){return arguments.length>1&&(e=Array.prototype.slice.call(arguments)),wjcCore.asArray(e,!1),_sum(e)/e.length}function _minimum(e){return arguments.length>1&&(e=Array.prototype.slice.call(arguments)),wjcCore.asArray(e,!1),Math.min.apply(null,e)}function _maximum(e){return arguments.length>1&&(e=Array.prototype.slice.call(arguments)),wjcCore.asArray(e,!1),Math.max.apply(null,e)}function _variance(e){arguments.length>1&&(e=Array.prototype.slice.call(arguments)),wjcCore.asArray(e,!1);var t=_average(e);return _average(e.map(e=>Math.pow(e-t,2)))}function _stdDeviation(e){return arguments.length>1&&(e=Array.prototype.slice.call(arguments)),wjcCore.asArray(e,!1),Math.sqrt(_variance(e))}function _avgTrueRng(e,t,a,i=14){wjcCore.asArray(e,!1),wjcCore.asArray(t,!1),wjcCore.asArray(a,!1),wjcCore.asInt(i,!1,!0);var s=_trueRng(e,t,a,i),r=Math.min(e.length,t.length,a.length,s.length),n=[];wjcCore.assert(r>i&&i>1,"Average True Range period must be an integer less than the length of the data and greater than one.");for(var l=0;l<r;l++)wjcCore.asNumber(e[l],!1),wjcCore.asNumber(t[l],!1),wjcCore.asNumber(a[l],!1),wjcCore.asNumber(s[l],!1),l+1===i?n.push(_average(s.slice(0,i))):l+1>i&&n.push(((i-1)*n[n.length-1]+s[l])/i);return n}function _trueRng(e,t,a,i=14){wjcCore.asArray(e,!1),wjcCore.asArray(t,!1),wjcCore.asArray(a,!1),wjcCore.asInt(i,!1,!0);var s=Math.min(e.length,t.length,a.length),r=[];wjcCore.assert(s>i&&i>1,"True Range period must be an integer less than the length of the data and greater than one.");for(var n=0;n<s;n++)wjcCore.asNumber(e[n],!1),wjcCore.asNumber(t[n],!1),wjcCore.asNumber(a[n],!1),0===n?r.push(e[n]-t[n]):r.push(Math.max(e[n]-t[n],Math.abs(e[n]-a[n-1]),Math.abs(t[n]-a[n-1])));return r}function _sma(e,t){wjcCore.asArray(e,!1),wjcCore.asNumber(t,!1,!0),wjcCore.assert(e.length>t&&t>1,"Simple Moving Average period must be an integer less than the length of the data and greater than one.");for(var a=[],i=t;i<=e.length;i++)a.push(_average(e.slice(i-t,i)));return a}function _ema(e,t){wjcCore.asArray(e,!1),wjcCore.asNumber(t,!1,!0),wjcCore.assert(e.length>t&&t>1,"Exponential Moving Average period must be an integer less than the length of the data and greater than one.");var a=[],i=2/(t+1),s=_sma(e,t);e=e.slice(t-1);for(var r=0;r<e.length;r++)0===r?a.push(s[0]):a.push((e[r]-a[r-1])*i+a[r-1]);return a}function _range(e,t,a=1){wjcCore.asNumber(e,!1),wjcCore.asNumber(t,!1),wjcCore.asNumber(a,!1),wjcCore.assert(e<t,"begin argument must be less than end argument.");for(var i=[],s=e;s<=t;s+=a)i.push(s);return i}Object.defineProperty(exports,"__esModule",{value:!0});const wjcCore=require("wijmo/wijmo"),wjcChart=require("wijmo/wijmo.chart"),wjcSelfRef=require("wijmo/wijmo.chart.finance");var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.chart=window.wijmo.chart||{},window.wijmo.chart.finance=wjcSelf,exports._trunc=_trunc,exports._sum=_sum,exports._average=_average,exports._minimum=_minimum,exports._maximum=_maximum,exports._variance=_variance,exports._stdDeviation=_stdDeviation,exports._avgTrueRng=_avgTrueRng,exports._trueRng=_trueRng,exports._sma=_sma,exports._ema=_ema,exports._range=_range;var FinancialChartType;!function(e){e[e.Column=0]="Column",e[e.Scatter=1]="Scatter",e[e.Line=2]="Line",e[e.LineSymbols=3]="LineSymbols",e[e.Area=4]="Area",e[e.Candlestick=5]="Candlestick",e[e.HighLowOpenClose=6]="HighLowOpenClose",e[e.HeikinAshi=7]="HeikinAshi",e[e.LineBreak=8]="LineBreak",e[e.Renko=9]="Renko",e[e.Kagi=10]="Kagi",e[e.ColumnVolume=11]="ColumnVolume",e[e.EquiVolume=12]="EquiVolume",e[e.CandleVolume=13]="CandleVolume",e[e.ArmsCandleVolume=14]="ArmsCandleVolume",e[e.PointAndFigure=15]="PointAndFigure"}(FinancialChartType=exports.FinancialChartType||(exports.FinancialChartType={}));class FinancialChart extends wjcChart.FlexChartCore{constructor(e,t){super(e,null),this._chartType=FinancialChartType.Line,this.__heikinAshiPlotter=null,this.__lineBreakPlotter=null,this.__renkoPlotter=null,this.__kagiPlotter=null,this.__pfPlotter=null,this.initialize(t)}_getProductInfo(){return"A78U,FinancialChart"}get chartType(){return this._chartType}set chartType(e){(e=wjcCore.asEnum(e,FinancialChartType))!=this._chartType&&(this._chartType=e,this.invalidate())}get options(){return this._options}set options(e){e!=this._options&&(this._options=e,this.invalidate())}get _heikinAshiPlotter(){return null===this.__heikinAshiPlotter&&(this.__heikinAshiPlotter=new _HeikinAshiPlotter,this._initPlotter(this.__heikinAshiPlotter)),this.__heikinAshiPlotter}get _lineBreakPlotter(){return null===this.__lineBreakPlotter&&(this.__lineBreakPlotter=new _LineBreakPlotter,this._initPlotter(this.__lineBreakPlotter)),this.__lineBreakPlotter}get _renkoPlotter(){return null===this.__renkoPlotter&&(this.__renkoPlotter=new _RenkoPlotter,this._initPlotter(this.__renkoPlotter)),this.__renkoPlotter}get _kagiPlotter(){return null===this.__kagiPlotter&&(this.__kagiPlotter=new _KagiPlotter,this._initPlotter(this.__kagiPlotter)),this.__kagiPlotter}get _pfPlotter(){return null===this.__pfPlotter&&(this.__pfPlotter=new _PointAndFigurePlotter,this._initPlotter(this.__pfPlotter)),this.__pfPlotter}_getChartType(){var e=null;switch(this.chartType){case FinancialChartType.Area:e=wjcChart.ChartType.Area;break;case FinancialChartType.Line:case FinancialChartType.Kagi:case FinancialChartType.PointAndFigure:e=wjcChart.ChartType.Line;break;case FinancialChartType.Column:case FinancialChartType.ColumnVolume:e=wjcChart.ChartType.Column;break;case FinancialChartType.LineSymbols:e=wjcChart.ChartType.LineSymbols;break;case FinancialChartType.Scatter:e=wjcChart.ChartType.Scatter;break;case FinancialChartType.Candlestick:case FinancialChartType.Renko:case FinancialChartType.HeikinAshi:case FinancialChartType.LineBreak:case FinancialChartType.EquiVolume:case FinancialChartType.CandleVolume:case FinancialChartType.ArmsCandleVolume:e=wjcChart.ChartType.Candlestick;break;case FinancialChartType.HighLowOpenClose:e=wjcChart.ChartType.HighLowOpenClose}return e}_getPlotter(e){var t=this.chartType,a=null;if(e){var i=e.chartType;i&&!wjcCore.isUndefined(i)&&i!=t&&(t=i,!0)}switch(t){case FinancialChartType.HeikinAshi:a=this._heikinAshiPlotter;break;case FinancialChartType.LineBreak:a=this._lineBreakPlotter;break;case FinancialChartType.Renko:a=this._renkoPlotter;break;case FinancialChartType.Kagi:a=this._kagiPlotter;break;case FinancialChartType.ColumnVolume:(a=super._getPlotter(e)).isVolume=!0,a.width=1;break;case FinancialChartType.EquiVolume:(a=super._getPlotter(e)).isEqui=!0,a.isCandle=!1,a.isArms=!1,a.isVolume=!0,a.symbolWidth="100%";break;case FinancialChartType.CandleVolume:(a=super._getPlotter(e)).isEqui=!1,a.isCandle=!0,a.isArms=!1,a.isVolume=!0,a.symbolWidth="100%";break;case FinancialChartType.ArmsCandleVolume:(a=super._getPlotter(e)).isEqui=!1,a.isCandle=!1,a.isArms=!0,a.isVolume=!0,a.symbolWidth="100%";break;case FinancialChartType.PointAndFigure:a=this._pfPlotter;break;default:a=super._getPlotter(e)}return a}_createSeries(){return new FinancialSeries}}exports.FinancialChart=FinancialChart;class FinancialSeries extends wjcChart.SeriesBase{get chartType(){return this._finChartType}set chartType(e){(e=wjcCore.asEnum(e,FinancialChartType,!0))!=this._finChartType&&(this._finChartType=e,this._invalidate())}_getChartType(){var e=null;switch(this.chartType){case FinancialChartType.Area:e=wjcChart.ChartType.Area;break;case FinancialChartType.Line:case FinancialChartType.Kagi:case FinancialChartType.PointAndFigure:e=wjcChart.ChartType.Line;break;case FinancialChartType.Column:case FinancialChartType.ColumnVolume:e=wjcChart.ChartType.Column;break;case FinancialChartType.LineSymbols:e=wjcChart.ChartType.LineSymbols;break;case FinancialChartType.Scatter:e=wjcChart.ChartType.Scatter;break;case FinancialChartType.Candlestick:case FinancialChartType.Renko:case FinancialChartType.HeikinAshi:case FinancialChartType.LineBreak:case FinancialChartType.EquiVolume:case FinancialChartType.CandleVolume:case FinancialChartType.ArmsCandleVolume:e=wjcChart.ChartType.Candlestick;break;case FinancialChartType.HighLowOpenClose:e=wjcChart.ChartType.HighLowOpenClose}return e}getDataRect(e,t){if(t)return t;var a=this.getValues(0),i=this.getValues(1)||(this.chart._xvals&&this.chart._xvals.length?this.chart._xvals:null),s=this._getBinding(0),r=this._getBinding(1),n=this._getBinding(2),l=this._getBinding(3);this._plotter;let h=this._getChartType()||this.chart._getChartType();if(h!==wjcChart.ChartType.HighLowOpenClose&&h!==wjcChart.ChartType.Candlestick||s===r)return null;if(a){for(var o=NaN,c=NaN,u=NaN,_=NaN,g=a.length,d=0;d<g;d++){var p=this._getItem(d),C=a[d];if(isFinite(C)&&[C,r?p[r]:null,n?p[n]:null,l?p[l]:null].forEach(e=>{wjcChart._DataInfo.isValid(e)&&null!==e&&((isNaN(c)||e<c)&&(c=e),(isNaN(_)||e>_)&&(_=e))}),i){var w=i[d];isFinite(w)&&(isNaN(o)?o=u=w:w<o?o=w:C>_&&(u=w))}}if(i||(o=0,u=g-1),!isNaN(c))return new wjcCore.Rect(o,c,u-o,_-c)}return null}}exports.FinancialSeries=FinancialSeries;class _BaseCalculator{constructor(e,t,a,i){this.highs=e,this.lows=t,this.opens=a,this.closes=i}calculate(){}}exports._BaseCalculator=_BaseCalculator;class _HeikinAshiCalculator extends _BaseCalculator{constructor(e,t,a,i){super(e,t,a,i)}calculate(){var e,t,a,i,s=Math.min(this.highs.length,this.lows.length,this.opens.length,this.closes.length),r=[];if(s<=0)return r;for(var n=0;n<s;n++)i=_average(this.highs[n],this.lows[n],this.opens[n],this.closes[n]),0===n?(a=_average(this.opens[n],this.closes[n]),e=this.highs[n],t=this.lows[n]):(a=_average(r[n-1].open,r[n-1].close),e=Math.max(this.highs[n],a,i),t=Math.min(this.lows[n],a,i)),r.push({high:e,low:t,close:i,open:a,pointIndex:n,x:null});return r}}exports._HeikinAshiCalculator=_HeikinAshiCalculator;class _BaseRangeCalculator extends _BaseCalculator{constructor(e,t,a,i,s,r,n,l){super(e,t,a,i),this.xs=s,this.size=r,this.unit=n,this.fields=l}_getValues(){var e,t=[],a=Math.min(this.highs.length,this.lows.length,this.opens.length,this.closes.length);switch(this.fields){case DataFields.High:t=this.highs;break;case DataFields.Low:t=this.lows;break;case DataFields.Open:t=this.opens;break;case DataFields.HL2:for(e=0;e<a;e++)t.push(_average(this.highs[e],this.lows[e]));break;case DataFields.HLC3:for(e=0;e<a;e++)t.push(_average(this.highs[e],this.lows[e],this.closes[e]));break;case DataFields.HLOC4:for(e=0;e<a;e++)t.push(_average(this.highs[e],this.lows[e],this.opens[e],this.closes[e]));break;case DataFields.Close:default:t=this.closes}return t}_getSize(){var e=this.unit===RangeMode.ATR?_avgTrueRng(this.highs,this.lows,this.closes,this.size):null;return this.unit===RangeMode.ATR?e[e.length-1]:this.size}}exports._BaseRangeCalculator=_BaseRangeCalculator;class _LineBreakCalculator extends _BaseRangeCalculator{constructor(e,t,a,i,s,r){super(e,t,a,i,s,r)}calculate(){var e=null!==this.xs&&this.xs.length>0,t=this.closes.length,a=[],i=[[],[]];if(t<=0)return a;for(var s,r,n,l,h,o,c,u=[],_=1;_<t;_++){if(l=a.length,h=l-1,r=e?this.xs[_]:_,n=this.closes[_],-1===h){if((s=this.closes[0])===n)continue}else if(u=this._trendExists(i)||1===this.size?i[0].slice(-this.size).concat(i[1].slice(-this.size)):i[0].slice(1-this.size).concat(i[1].slice(1-this.size)),o=Math.max.apply(null,u),c=Math.min.apply(null,u),n>o)s=Math.max(i[0][h],i[1][h]);else{if(!(n<c))continue;s=Math.min(i[0][h],i[1][h])}i[0].push(s),i[1].push(n),a.push({high:Math.max(s,n),low:Math.min(s,n),open:s,close:n,x:r,pointIndex:_})}return a}_trendExists(e){if(e[1].length<this.size)return!1;var t,a=!1,i=e[1].slice(-this.size);for(t=1;t<this.size&&(a=i[t]>i[t-1]);t++);if(!a)for(t=1;t<this.size&&(a=i[t]<i[t-1]);t++);return a}}exports._LineBreakCalculator=_LineBreakCalculator;class _KagiCalculator extends _BaseRangeCalculator{constructor(e,t,a,i,s,r,n,l){super(e,t,a,i,s,r,n,l)}calculate(){var e=this._getSize(),t=Math.min(this.highs.length,this.lows.length,this.opens.length,this.closes.length),a=this._getValues(),i=null!==this.xs&&this.xs.length>0,s=[],r=[[],[]];if(t<=0)return s;for(var n,l,h,o,c,u,_,g,d,p,C=1;C<t;C++){if(o=s.length,c=o-1,l=i?this.xs[C]:C,p=C,d=!1,this.fields===DataFields.HighLow)if(-1===c)if(this.highs[C]>this.highs[0])h=this.highs[C];else{if(!(this.lows[C]<this.lows[0]))continue;h=this.lows[C]}else if((g=r[1][c]-r[0][c])>0)if(this.highs[C]>r[1][c])h=this.highs[C];else{if(!(this.lows[C]<r[1][c]))continue;h=this.lows[C]}else if(this.lows[C]<r[1][c])h=this.lows[C];else{if(!(this.highs[C]>r[1][c]))continue;h=this.highs[C]}else h=a[C];if(this.unit===RangeMode.Percentage&&(e=h*this.size),-1===c){if(l=i?this.xs[0]:0,p=0,n=this.fields===DataFields.HighLow?null==this.highs[0]?this.highs[this.highs.length-1]:this.highs[0]:null==a[0]?a[a.length-1]:a[0],(g=Math.abs(n-h)||0)<e)continue}else if(g=r[1][c]-r[0][c],_=Math.max(r[0][c],r[1][c]),u=Math.min(r[0][c],r[1][c]),g>0)if(h>_)d=!0;else{if(!((g=_-h)>=e))continue;n=_}else if(h<u)d=!0;else{if(!((g=h-u)>=e))continue;n=u}d?(r[1][c]=h,s[c].close=h,s[c].high=Math.max(s[c].open,s[c].close),s[c].low=Math.min(s[c].open,s[c].close)):(r[0].push(n),r[1].push(h),s.push({high:Math.max(n,h),low:Math.min(n,h),open:n,close:h,x:l,pointIndex:p}))}return s}}exports._KagiCalculator=_KagiCalculator;class _RenkoCalculator extends _BaseRangeCalculator{constructor(e,t,a,i,s,r,n,l,h=!1){super(e,t,a,i,s,r,n,l),this.rounding=h}calculate(){var e=this._getSize(),t=Math.min(this.highs.length,this.lows.length,this.opens.length,this.closes.length),a=null!==this.xs&&this.xs.length>0,i=this._getValues(),s=[],r=[[],[]];if(t<=0)return s;for(var n,l,h,o,c,u,_,g,d=1;d<t;d++){if(o=s.length,c=o-1,l=a?this.xs[d]:d,this.fields===DataFields.HighLow)if(-1===c)if(this.highs[d]-this.highs[0]>e)n=this.highs[0],h=this.highs[d];else{if(!(this.lows[0]-this.lows[d]>e))continue;n=this.lows[0],h=this.lows[d]}else if(u=Math.min(r[0][c],r[1][c]),_=Math.max(r[0][c],r[1][c]),this.highs[d]-_>e)n=_,h=this.highs[d];else{if(!(u-this.lows[d]>e))continue;n=u,h=this.lows[d]}else if(h=i[d],-1===c)n=i[0];else if(u=Math.min(r[0][c],r[1][c]),_=Math.max(r[0][c],r[1][c]),h>_)n=_;else{if(!(h<u))continue;n=u}if(g=h-n,!(Math.abs(g)<e)){g=_trunc(g/e);for(var p=0;p<Math.abs(g);p++){var C={};this.rounding&&(n=this._round(n,e)),r[0].push(n),C.open=n,n=g>0?n+e:n-e,r[1].push(n),C.close=n,C.x=l,C.pointIndex=d,C.high=Math.max(C.open,C.close),C.low=Math.min(C.open,C.close),s.push(C)}}}return s}_round(e,t){return Math.round(e/t)*t}}exports._RenkoCalculator=_RenkoCalculator;class _HeikinAshiPlotter extends wjcChart._FinancePlotter{constructor(){super(),this._symFactor=.7,this.clear()}clear(){super.clear(),this._haValues=null,this._calculator=null}plotSeries(e,t,a,i,s,r,n){this._calculate(i);var l=wjcCore.asType(i,wjcChart.SeriesBase),h=this.chart.series.indexOf(i),o=i.getValues(1),c=this._symFactor,u=this._haValues.length,_=!0;if(o){var g=this.dataInfo.getDeltaX();g>0&&(c*=g)}else o=this.dataInfo.getXVals();o?u=Math.min(u,o.length):(_=!1,o=new Array(u));var d=this._DEFAULT_WIDTH,p=l._getSymbolFill(h),C=l._getAltSymbolFill(h)||"transparent",w=l._getSymbolStroke(h),m=l._getAltSymbolStroke(h)||w,f=c,x=i.getDataType(1)||i.chart._xDataType;e.strokeWidth=d;for(var v,y,j,k,F,b,P,T,V=t.actualMin,A=t.actualMax,L=0,M=0;M<u;M++)if(j=_?o[M]:M,wjcChart._DataInfo.isValid(j)&&V<=j&&j<=A){if(F=this._haValues[M].high,b=this._haValues[M].low,P=this._haValues[M].open,T=this._haValues[M].close,v=P<T?C:p,y=P<T?m:w,e.fill=v,e.stroke=y,e.startGroup(),k=this._getDataPoint(h,M,j,i),this.chart.itemFormatter){var S=new wjcChart.HitTestInfo(this.chart,new wjcCore.Point(t.convert(j),a.convert(F)),wjcChart.ChartElement.SeriesSymbol);S._setData(l,M),S._setDataPoint(k),this.chart.itemFormatter(e,S,()=>{this._drawSymbol(e,t,a,h,M,v,f,j,F,b,P,T,k,x)})}else this._drawSymbol(e,t,a,h,M,v,f,j,F,b,P,T,k,x);e.endGroup(),i._setPointIndex(M,L),L++}}_drawSymbol(e,t,a,i,s,r,n,l,h,o,c,u,_,g){var d,p=null,C=null,w=null,m=null,f=g===wjcCore.DataType.Date?432e5:.5;if(w=t.convert(l-f*n),m=t.convert(l+f*n),w>m){var x=w;w=m,m=x}l=t.convert(l),wjcChart._DataInfo.isValid(c)&&wjcChart._DataInfo.isValid(u)&&(c=a.convert(c),u=a.convert(u),C=(p=Math.min(c,u))+Math.abs(c-u),e.drawRect(w,p,m-w,C-p),(d=new wjcChart._RectArea(new wjcCore.Rect(w,p,m-w,C-p))).tag=_,this.hitTester.add(d,i)),wjcChart._DataInfo.isValid(h)&&(h=a.convert(h),null!==p&&e.drawLine(l,p,l,h)),wjcChart._DataInfo.isValid(o)&&(o=a.convert(o),null!==C&&e.drawLine(l,C,l,o))}_getDataPoint(e,t,a,i){var s=new wjcChart._DataPoint(e,t,a,this._haValues[t].high),r=i._getItem(t),n=i._getBinding(0),l=i._getBinding(1),h=i._getBinding(2),o=i._getBinding(3),c=i._getAxisY();return null!=r&&(s.item=wjcChart._BasePlotter.cloneStyle(r,[]),s.item[n]=this._haValues[t].high,s.item[l]=this._haValues[t].low,s.item[h]=this._haValues[t].open,s.item[o]=this._haValues[t].close),s.y=this._haValues[t].high,s.yfmt=c._formatValue(this._haValues[t].high),s}_calculate(e){var t=e._getBindingValues(0),a=e._getBindingValues(1),i=e._getBindingValues(2),s=e._getBindingValues(3);this._calculator=new _HeikinAshiCalculator(t,a,i,s),this._haValues=this._calculator.calculate(),(null===this._haValues||wjcCore.isUndefined(this._haValues))&&this._init()}_init(){this._haValues=[]}}exports._HeikinAshiPlotter=_HeikinAshiPlotter;class _BaseRangePlotter extends wjcChart._BasePlotter{constructor(){super(),this._symFactor=.7,this.clear()}clear(){super.clear(),this._rangeValues=null,this._rangeXLabels=null,this._calculator=null}unload(){super.unload();for(var e,t,a=0;a<this.chart.series.length;a++)(e=this.chart.series[a])&&(t=e._getAxisX())&&t.itemsSource&&(t.itemsSource=null)}adjustLimits(e,t){var a,i,s,r=0,n=0,l=0,h=0,o=this.chart._xDataType===wjcCore.DataType.Date?.5:0;wjcCore.assert(this.chart.series.length<=1,"Current FinancialChartType only supports a single series");for(var c=0;c<this.chart.series.length;c++)a=this.chart.series[c],this._calculate(a),this._rangeValues.length<=0||this._rangeXLabels.length<=0||((i=this._rangeValues.map(e=>e.open)).push.apply(i,this._rangeValues.map(e=>e.close)),s=this._rangeXLabels.map(e=>e.value),l=Math.min.apply(null,i),h=Math.max.apply(null,i),r=Math.min.apply(null,s),n=Math.max.apply(null,s),a._getAxisX().itemsSource=this._rangeXLabels);return r-=o,new wjcCore.Rect(r,l,n-r+o,h-l)}plotSeries(e,t,a,i,s,r,n){this._calculate(i);var l=this.chart.series.indexOf(i),h=this._rangeValues.length,o=t.actualMin,c=t.actualMax,u=this._DEFAULT_WIDTH,_=this._symFactor,g=i._getSymbolFill(l),d=i._getAltSymbolFill(l)||"transparent",p=i._getSymbolStroke(l),C=i._getAltSymbolStroke(l)||p;e.strokeWidth=u;for(var w,m,f,x,v=0,y=0;y<h;y++)if(w=y,wjcChart._DataInfo.isValid(w)&&o<=w&&w<=c){if(m=this._rangeValues[y].open,f=this._rangeValues[y].close,e.fill=m>f?g:d,e.stroke=m>f?p:C,x=this._getDataPoint(l,y,i,Math.max(m,f)),e.startGroup(),this.chart.itemFormatter){var j=new wjcChart.HitTestInfo(this.chart,new wjcCore.Point(t.convert(w),a.convert(f)),wjcChart.ChartElement.SeriesSymbol);j._setData(i,y),j._setDataPoint(x),this.chart.itemFormatter(e,j,()=>{this._drawSymbol(e,t,a,l,v,_,w,m,f,x)})}else this._drawSymbol(e,t,a,l,v,_,w,m,f,x);e.endGroup(),i._setPointIndex(y,v),v++}}_drawSymbol(e,t,a,i,s,r,n,l,h,o){var c,u,_,g,d;if(_=t.convert(n-.5*r),g=t.convert(n+.5*r),_>g){var p=_;_=g,g=p}wjcChart._DataInfo.isValid(l)&&wjcChart._DataInfo.isValid(h)&&(l=a.convert(l),h=a.convert(h),u=(c=Math.min(l,h))+Math.abs(l-h),e.drawRect(_,c,g-_,u-c),(d=new wjcChart._RectArea(new wjcCore.Rect(_,c,g-_,u-c))).tag=o,this.hitTester.add(d,i))}_getDataPoint(e,t,a,i){var s=t,r=new wjcChart._DataPoint(e,t,s,i),n=a._getItem(this._rangeValues[t].pointIndex),l=a.bindingX||this.chart.bindingX,h=a._getBinding(0),o=a._getBinding(1),c=a._getBinding(2),u=a._getBinding(3),_=a._getAxisY();return r.item=wjcChart._BasePlotter.cloneStyle(n,[]),r.item[h]=this._rangeValues[t].high,r.item[o]=this._rangeValues[t].low,r.item[c]=this._rangeValues[t].open,r.item[u]=this._rangeValues[t].close,r.y=this._rangeValues[t].close,r.yfmt=_._formatValue(this._rangeValues[t].close),r.x=r.item[l],r.xfmt=this._rangeXLabels[t]._text,r}_init(){this._rangeValues=[],this._rangeXLabels=[]}_calculate(e){}_generateXLabels(e){var t,a=e._getAxisX(),i=e.getDataType(1)||this.chart._xDataType;this._rangeValues.forEach((e,s)=>{var r=e.x;t=i===wjcCore.DataType.Date?wjcCore.Globalize.format(wjcChart.FlexChart._fromOADate(r),a.format||"d"):i===wjcCore.DataType.Number?a._formatValue(r):null!==i&&i!==wjcCore.DataType.String||!this.chart._xlabels?r.toString():this.chart._xlabels[r],this._rangeXLabels.push({value:s,text:t,_text:t})},this)}}exports._BaseRangePlotter=_BaseRangePlotter;var DataFields;!function(e){e[e.Close=0]="Close",e[e.High=1]="High",e[e.Low=2]="Low",e[e.Open=3]="Open",e[e.HighLow=4]="HighLow",e[e.HL2=5]="HL2",e[e.HLC3=6]="HLC3",e[e.HLOC4=7]="HLOC4"}(DataFields=exports.DataFields||(exports.DataFields={}));var RangeMode;!function(e){e[e.Fixed=0]="Fixed",e[e.ATR=1]="ATR",e[e.Percentage=2]="Percentage"}(RangeMode=exports.RangeMode||(exports.RangeMode={}));class _LineBreakPlotter extends _BaseRangePlotter{constructor(){super()}clear(){super.clear(),this._newLineBreaks=null}_calculate(e){this._init();var t=e._getBindingValues(3),a=e.getValues(1)||this.chart._xvals;this._calculator=new _LineBreakCalculator(null,null,null,t,a,this._newLineBreaks),this._rangeValues=this._calculator.calculate(),(null===this._rangeValues||wjcCore.isUndefined(this._rangeValues))&&(this._rangeValues=[]),this._generateXLabels(e)}_init(){super._init(),this._newLineBreaks=wjcCore.asInt(this.getNumOption("newLineBreaks","lineBreak"),!0,!0)||3,wjcCore.assert(this._newLineBreaks>=1,"Value must be greater than 1")}}exports._LineBreakPlotter=_LineBreakPlotter;class _RenkoPlotter extends _BaseRangePlotter{constructor(){super()}clear(){super.clear(),this._boxSize=null,this._rangeMode=null}_calculate(e){this._init();var t=e._getBindingValues(0),a=e._getBindingValues(1),i=e._getBindingValues(2),s=e._getBindingValues(3),r=e.getValues(1)||this.chart._xvals;this._calculator=new _RenkoCalculator(t,a,i,s,r,this._boxSize,this._rangeMode,this._fields,this._rounding),this._rangeValues=this._calculator.calculate(),(null===this._rangeValues||wjcCore.isUndefined(this._rangeValues))&&(this._rangeValues=[]),this._generateXLabels(e)}_init(){super._init(),this._boxSize=this.getNumOption("boxSize","renko")||14,this._rangeMode=this.getOption("rangeMode","renko")||RangeMode.Fixed,this._rangeMode=wjcCore.asEnum(this._rangeMode,RangeMode,!0),wjcCore.assert(this._rangeMode!==RangeMode.Percentage,"RangeMode.Percentage is not supported"),this._fields=this.getOption("fields","renko")||DataFields.Close,this._fields=wjcCore.asEnum(this._fields,DataFields,!0),wjcCore.assert(this._fields!==DataFields.HighLow,"DataFields.HighLow is not supported"),this._rounding=wjcCore.asBoolean(this.getOption("rounding","renko"),!0)}_generateXLabels(e){super._generateXLabels(e),this._rangeXLabels.forEach((e,t)=>{t>0&&this._rangeXLabels[t-1]._text===e.text&&(e.text="")},this)}}exports._RenkoPlotter=_RenkoPlotter;class _KagiPlotter extends _BaseRangePlotter{constructor(){super()}_calculate(e){this._init();var t=e._getBindingValues(0),a=e._getBindingValues(1),i=e._getBindingValues(2),s=e._getBindingValues(3),r=e.getValues(1)||this.chart._xvals;this._calculator=new _KagiCalculator(t,a,i,s,r,this._reversalAmount,this._rangeMode,this._fields),this._rangeValues=this._calculator.calculate(),(null===this._rangeValues||wjcCore.isUndefined(this._rangeValues))&&(this._rangeValues=[]),this._generateXLabels(e)}plotSeries(e,t,a,i,s,r,n){this._calculate(i);var l=this.chart.series.indexOf(i),h=this._rangeValues.length,o=t.actualMin,c=t.actualMax,u=this._DEFAULT_WIDTH,_=i._getSymbolStroke(l),g=i._getAltSymbolStroke(l)||_,d=[],p=[];e.stroke=_,e.strokeWidth=u;var C,w,m,f,x,v,y,j=0;e.startGroup();for(var k=0;k<h;k++)C=k,wjcChart._DataInfo.isValid(C)&&o<=C&&C<=c&&(w=this._rangeValues[k].open,m=this._rangeValues[k].close,0===k?(f=Math.min(w,m),x=Math.max(w,m),e.strokeWidth=w>m?u:2*u,e.stroke=w>m?_:g,e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(m)),e.drawLine(t.convert(C-1)-e.strokeWidth/2,a.convert(w),t.convert(C)+e.strokeWidth/2,a.convert(w))):e.strokeWidth===u?m>w?(m>x?(e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(x)),e.strokeWidth=2*u,e.stroke=g,e.drawLine(t.convert(C),a.convert(x),t.convert(C),a.convert(m)),f=w):e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(m)),x=m):e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(m)):e.strokeWidth/2===u&&(m<w?(m<f?(e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(f)),e.strokeWidth=u,e.stroke=_,e.drawLine(t.convert(C),a.convert(f),t.convert(C),a.convert(m)),x=w):e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(m)),f=m):e.drawLine(t.convert(C),a.convert(w),t.convert(C),a.convert(m))),k<h-1&&e.drawLine(t.convert(C)-e.strokeWidth/2,a.convert(m),t.convert(C+1)+e.strokeWidth/2,a.convert(m)),y=this._getDataPoint(l,k,i,m),(v=new wjcChart._CircleArea(new wjcCore.Point(t.convert(C),a.convert(m)),.5*e.strokeWidth)).tag=y,this.hitTester.add(v,l),i._setPointIndex(k,j),j++,d.push(t.convert(C)),p.push(a.convert(w)),d.push(t.convert(C)),p.push(a.convert(m)));e.endGroup(),this.hitTester.add(new wjcChart._LinesArea(d,p),l)}_init(){super._init(),this._reversalAmount=this.getNumOption("reversalAmount","kagi")||14,this._rangeMode=this.getOption("rangeMode","kagi")||RangeMode.Fixed,this._rangeMode=wjcCore.asEnum(this._rangeMode,RangeMode,!0),this._fields=this.getOption("fields","kagi")||DataFields.Close,this._fields=wjcCore.asEnum(this._fields,DataFields,!0)}clear(){super.clear(),this._reversalAmount=null,this._rangeMode=null}}exports._KagiPlotter=_KagiPlotter;var PointAndFigureScaling;!function(e){e[e.Traditional=0]="Traditional",e[e.Fixed=1]="Fixed",e[e.Dynamic=2]="Dynamic"}(PointAndFigureScaling=exports.PointAndFigureScaling||(exports.PointAndFigureScaling={}));class _PointAndFigurePlotter extends wjcChart._BasePlotter{constructor(){super()}clear(){super.clear(),this._boxSize=null,this._fields=null,this._reversal=null,this._scaling=null}unload(){super.unload(),this.chart.axisX.itemsSource=this._xlbls}_init(){this._boxSize=this.getNumOption("boxSize","pointAndFigure")||1,this._reversal=this.getNumOption("reversal","pointAndFigure")||3,this._period=this.getNumOption("period","pointAndFigure")||20,this._fields=this.getOption("fields","pointAndFigure")||DataFields.Close,this._fields=wjcCore.asEnum(this._fields,DataFields,!0),wjcCore.assert(this._fields==DataFields.Close||this._fields==DataFields.HighLow,"Only DataFields.Close and DataFields.HighLow are supported"),this._scaling=this.getOption("scaling","pointAndFigure")||PointAndFigureScaling.Traditional,this._scaling=wjcCore.asEnum(this._scaling,PointAndFigureScaling,!0),this._xlbls=[]}adjustLimits(e,t){this._init(),this.hitTester.clear();let a=new wjcCore.Rect(0,0,0,0),i=this.chart.series.length;if(wjcCore.assert(i<=1,"Current FinancialChartType only supports a single series"),i>0){let e=this.chart.series[0],t=this._reversal,i=e.collectionView?e.collectionView:this.chart.collectionView,o=i?i.items:null;if(o&&o.length>0){let i=e._getBinding(0),c=e._getBinding(1),u=e._getBinding(2),_=e._getBinding(3);this._fields==DataFields.Close&&(_?i=_:u&&(i=u),c=i);let g=e.bindingX?e.bindingX:this.chart.bindingX,d=this._actualBoxSize=this.calcBoxSize(o,i,c);if(this._pfdata=this.calcPFHiLo2(o,i,c,g,d,t),this._pfdata&&this._pfdata.length>0){var s=this._pfdata.reduce(function(e,t){return Math.max(e,t.max)},this._pfdata[0].max),r=this._pfdata.reduce(function(e,t){return Math.min(e,t.min)},this._pfdata[0].min);a=new wjcCore.Rect(-.5,r-.5*d,this._pfdata.length,s-r+d);for(var n=1;n<this._pfdata.length;n++){var l=this._pfdata[n-1],h=this._pfdata[n];wjcCore.isDate(h.date)&&wjcCore.isDate(l.date)&&h.date.getYear()!=l.date.getYear()&&this._xlbls.push({value:n,text:wjcCore.Globalize.formatNumber(h.date.getFullYear()%100,"d2")})}}}}return 0==this._xlbls.length&&this._xlbls.push({value:0}),this.chart.axisY.majorGrid=!1,this.chart.axisX.itemsSource=this._xlbls,a}plotSeries(e,t,a,i,s,r,n){if(this._pfdata&&this._pfdata.length>0){var l=this._actualBoxSize;this.renderGrid(e,this._pfdata,l),this.renderData(this.chart,e,this._pfdata,l)}}calcBoxSize(e,t,a){var i=e.reduce(function(e,a){return Math.max(e,a[t])},e[0][t]),s=e.reduce(function(e,t){return Math.min(e,t[a])},e[0][a]),r=this._boxSize,n=i-s;switch(this._scaling){case PointAndFigureScaling.Traditional:n<.25?r=.0625:n>=.25&&n<1?r=.125:n>=1&&n<5?r=.25:n>=5&&n<20?r=.5:n>=20&&n<100?r=1:n>=100&&n<200?r=2:n>=200&&n<500?r=4:n>=500&&n<1e3?r=5:n>=1e3&&n<25e3?r=50:n>-25e3&&(r=500);break;case PointAndFigureScaling.Dynamic:let e=this.chart.series[0],t=e._getBindingValues(0),a=e._getBindingValues(1);e._getBindingValues(2);var l=_avgTrueRng(t,a,e._getBindingValues(3),this._period);r=l[l.length-1];break;case PointAndFigureScaling.Fixed:}return r}calcPFHiLo2(e,t,a,i,s,r){let n=[];for(let c=0;c<e.length;c++){let u=e[c][t],_=e[c][a];wjcCore.assert(u>=_,"'High' value must be larger than 'low' value.");let g=e[c][i];if(0==n.length)n.push({min:this.roundDown(_,s),max:this.roundDown(u,s),rise:!1,date:g});else{var l=n[n.length-1];if(l.rise){var h=l.max+s,o=l.max-r*s;this.roundUp(u,s)>=h?l.max=this.roundUp(u,s):_<=o&&n.push({min:this.roundDown(_,s),max:l.max-s,rise:!1,date:g})}else{var h=l.min-s,o=l.min+r*s;this.roundDown(_,s)<=h?l.min=this.roundDown(_,s):u>=o&&n.push({min:l.min+s,max:this.roundUp(u,s),rise:!0,date:g})}}}if(n.length>0){var c=n[0];c.min==c.max&&n.splice(0,1)}return n}roundUp(e,t){return Math.ceil(e/t-.999999)*t}roundDown(e,t){return Math.floor(e/t+.999999)*t}renderGrid(e,t,a){if(this._pfdata){for(var i=this._pfdata.reduce(function(e,t){return Math.max(e,t.max)},this._pfdata[0].max),s=this._pfdata.reduce(function(e,t){return Math.min(e,t.min)},this._pfdata[0].min),r=this.chart,n=this._pfdata.length,l=s-.5*a;l<=i+a;l+=a){o=new wjcCore.Point(-.5,l);o=r.dataToPoint(o);c=new wjcCore.Point(n,l);c=r.dataToPoint(c),e.stroke=wjcChart.FlexChart._FG,e.strokeWidth=1,e.drawLine(o.x,o.y,c.x,c.y,wjcChart.FlexChart._CSS_GRIDLINE)}for(var h=-.5;h<=n;h+=1){var o=new wjcCore.Point(h,this.chart.axisY.actualMin);o=r.dataToPoint(o);var c=new wjcCore.Point(h,this.chart.axisY.actualMax);c=r.dataToPoint(c),e.stroke=wjcChart.FlexChart._FG,e.strokeWidth=1,e.drawLine(o.x,o.y,c.x,c.y,wjcChart.FlexChart._CSS_GRIDLINE)}}}renderData(e,t,a,i){let s=e.series[0],r=s._getSymbolStroke(0),n=s._getAltSymbolStroke(0)||r;for(let s=0;s<a.length;s++){let h=a[s],o=(a[s].max-a[s].min)/i;if(0==o)continue;let c=new wjcCore.Point(s-.5,h.min);c=e.dataToPoint(c);let u=new wjcCore.Point(s+.5,h.max);u=e.dataToPoint(u),t.fill="transparent";let _=(u.y-c.y)/o;for(var l=0;l<o+1;l++)if(t.strokeWidth=1.5,h.rise?(t.stroke=r,t.drawLine(c.x,c.y+(l-.5)*_,u.x,c.y+(l+.5)*_),t.drawLine(u.x,c.y+(l-.5)*_,c.x,c.y+(l+.5)*_)):(t.stroke=n,t.drawEllipse(.5*(c.x+u.x),c.y+l*_,.5*Math.abs(c.x-u.x),.5*Math.abs(_))),this.hitTester){let e=h.min+l*i,t=new wjcChart._DataPoint(0,s,h.date,e);t.y=e,t.yfmt=this.chart.axisY._formatValue(e),wjcCore.isDate(h.date)&&(t.x=h.date,t.xfmt=wjcCore.Globalize.formatDate(h.date,"d"));let a=new wjcCore.Rect(Math.min(c.x,u.x),c.y+l*_-.5*_,Math.abs(u.x-c.x),_);a.height<0&&(a.top+=_,a.height=-a.height);let r=new wjcChart._RectArea(a);r.tag=t,this.hitTester.add(r,0)}}}}exports._PointAndFigurePlotter=_PointAndFigurePlotter;