/*
    *
    * 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/
    *
    */
import*as wjcChart from"wijmo/wijmo.chart";import*as wjcCore from"wijmo/wijmo";import*as wjcSelfRef from"wijmo/wijmo.chart.radar";var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.chart=window.wijmo.chart||{},window.wijmo.chart.radar=wjcSelf;export var RadarChartType;!function(t){t[t.Column=0]="Column",t[t.Scatter=1]="Scatter",t[t.Line=2]="Line",t[t.LineSymbols=3]="LineSymbols",t[t.Area=4]="Area"}(RadarChartType||(RadarChartType={}));export class FlexRadar extends wjcChart.FlexChartCore{constructor(t,e){super(t,e),this._chartType=RadarChartType.Line,this._startAngle=0,this._totalAngle=360,this._reversed=!1,this._areas=[]}get _radarLinePlotter(){return null==this.__radarLinePlotter&&(this.__radarLinePlotter=new _RadarLinePlotter,this._initPlotter(this.__radarLinePlotter)),this.__radarLinePlotter}get _radarColumnPlotter(){return null==this.__radarColumnPlotter&&(this.__radarColumnPlotter=new _RadarBarPlotter,this._initPlotter(this.__radarColumnPlotter)),this.__radarColumnPlotter}_initAxes(){super._initAxes(),this.axes.pop(),this.axes.pop(),this.axisX=new FlexRadarAxis(wjcChart.Position.Bottom),this.axisX.majorGrid=!0,this.axisY=new FlexRadarAxis(wjcChart.Position.Left),this.axisY.majorTickMarks=wjcChart.TickMark.Outside,this.axes.push(this.axisX),this.axes.push(this.axisY)}_layout(t,e,a){super._layout(t,e,a);var r=this.axisX._height;this._plotRect.top+=r/2;var i=this._plotRect;this._radius=Math.min(i.width,i.height)/2,this._center=new wjcCore.Point(i.left+i.width/2,i.top+i.height/2)}get chartType(){return this._chartType}set chartType(t){(t=wjcCore.asEnum(t,RadarChartType))!=this._chartType&&(this._chartType=t,this.invalidate())}get startAngle(){return this._startAngle}set startAngle(t){t!=this._startAngle&&(this._startAngle=wjcCore.asNumber(t,!0),this.invalidate())}get totalAngle(){return this._totalAngle}set totalAngle(t){t!=this._totalAngle&&t>=0&&(this._totalAngle=wjcCore.asNumber(t,!0),this._totalAngle<=0&&(wjcCore.assert(!1,"totalAngle must be greater than 0."),this._totalAngle=0),this._totalAngle>360&&(wjcCore.assert(!1,"totalAngle must be less than or equal to 360."),this._totalAngle=360),this.invalidate())}get reversed(){return this._reversed}set reversed(t){t!=this._reversed&&(this._reversed=wjcCore.asBoolean(t,!0),this.invalidate())}get stacking(){return this._stacking}set stacking(t){(t=wjcCore.asEnum(t,wjcChart.Stacking))!=this._stacking&&(this._stacking=t,this.invalidate())}_getChartType(){var t=wjcChart.ChartType.Line;switch(this.chartType){case RadarChartType.Area:t=wjcChart.ChartType.Area;break;case RadarChartType.Line:t=wjcChart.ChartType.Line;break;case RadarChartType.Column:t=wjcChart.ChartType.Column;break;case RadarChartType.LineSymbols:t=wjcChart.ChartType.LineSymbols;break;case RadarChartType.Scatter:t=wjcChart.ChartType.Scatter}return t}_getPlotter(t){var e=this.chartType,a=null;if(t){var r=t.chartType;null!=r&&r!=e&&(e=r,!0)}switch(e){case RadarChartType.Line:this._radarLinePlotter.hasSymbols=!1,this._radarLinePlotter.hasLines=!0,this._radarLinePlotter.isArea=!1,a=this._radarLinePlotter;break;case RadarChartType.LineSymbols:this._radarLinePlotter.hasSymbols=!0,this._radarLinePlotter.hasLines=!0,this._radarLinePlotter.isArea=!1,a=this._radarLinePlotter;break;case RadarChartType.Area:this._radarLinePlotter.hasSymbols=!1,this._radarLinePlotter.hasLines=!0,this._radarLinePlotter.isArea=!0,a=this._radarLinePlotter;break;case RadarChartType.Scatter:this._radarLinePlotter.hasSymbols=!0,this._radarLinePlotter.hasLines=!1,this._radarLinePlotter.isArea=!1,a=this._radarLinePlotter;break;case RadarChartType.Column:this._radarColumnPlotter.isVolume=!1,this._radarColumnPlotter.width=.8,a=this._radarColumnPlotter;break;default:a=super._getPlotter(t)}return a}_convertPoint(t,e){var a=new wjcCore.Point,r=this._center;return a.x=r.x+t*Math.sin(e),a.y=r.y-t*Math.cos(e),a}_createSeries(){return new FlexRadarSeries}_clearCachedValues(){super._clearCachedValues(),this._isPolar=!1,this._areas=[]}_performBind(){super._performBind(),this._xDataType===wjcCore.DataType.Number&&(this._isPolar=!0)}_prepareRender(){super._prepareRender(),this._areas=[]}};export class FlexRadarSeries extends wjcChart.SeriesBase{get chartType(){return this._finChartType}set chartType(t){(t=wjcCore.asEnum(t,RadarChartType,!0))!=this._finChartType&&(this._finChartType=t,this._invalidate())}_getChartType(){var t;switch(this.chartType){case RadarChartType.Area:t=wjcChart.ChartType.Area;break;case RadarChartType.Line:t=wjcChart.ChartType.Line;break;case RadarChartType.Column:t=wjcChart.ChartType.Column;break;case RadarChartType.LineSymbols:t=wjcChart.ChartType.LineSymbols;break;case RadarChartType.Scatter:t=wjcChart.ChartType.Scatter}return t}};export class FlexRadarAxis extends wjcChart.Axis{constructor(){super(...arguments),this._points=[],this._axisLabels=[]}_render(t){if(this._hasVisibileSeries()){super._render(t);var e=this._axisLabels;if(e.length){var a=()=>{var r=this.axisType==wjcChart.AxisType.X?"wj-axis-x-labels "+wjcChart.FlexChart._CSS_AXIS_X:"wj-axis-y-labels "+wjcChart.FlexChart._CSS_AXIS_Y;t.startGroup(r),e.forEach(e=>{var a=e.labelAngle;a>0?wjcChart.FlexChart._renderRotatedText(t,e.text,e.pos,e.align,e.vAlign,e.pos,a,e.class):a<0?wjcChart.FlexChart._renderRotatedText(t,e.text,e.pos,e.align,e.vAlign,e.pos,a,e.class):this._renderLabel(t,e.val,e.text,e.pos,e.align,e.vAlign,e.class)}),t.endGroup(),this._axisLabels=[],this._chart.rendered.removeHandler(a)};this._chart.rendered.addHandler(a,this)}}}_getHeight(t,e){var a=super._getHeight(t,e);return this._axisType==wjcChart.AxisType.Y&&(a=4),this._height=2*a,2*a}_updateActualLimits(t,e,a,r=null,i=null){super._updateActualLimits(t,e,a,r,i);var s,h=this._chart,n=this._lbls,l=this.actualMin.valueOf?this.actualMin.valueOf():this.actualMin,o=this.actualMax.valueOf?this.actualMax.valueOf():this.actualMax;this._lbls&&this===h.axisX&&(h._angles=[],this._isTimeAxis&&0===this._lbls.length&&this._values.forEach(t=>{n.push(this._formatValue(t))}),s=n.length,h.totalAngle<360&&(s-=1),n.forEach((t,e)=>{var a=l+e/s*(o-l),r=h.startAngle+e/s*h.totalAngle;isNaN(r)||isNaN(a)||h._angles.push({value:this.convert(a),angle:r})}))}_updateActualLimitsByChartType(t,e,a){var r=this._chart;if(r._getChartType()!=wjcChart.ChartType.Column&&360===r.totalAngle&&this.axisType===wjcChart.AxisType.X)if(this._isTimeAxis){var i=(r._xlabels.length||r._xvals.length)-1;a+=(a-e)/(i=i<1?1:i)}else r._isPolar||(a+=1);return{min:e,max:a}}convert(t,e,a){var r=null==e?this.actualMax:e,i=null==a?this.actualMin:a,s=this._chart;if(!s)return NaN;if(r==i)return 0;if(this.axisType===wjcChart.AxisType.X)return s.reversed?(s.startAngle-(t-i)/(r-i)*s.totalAngle)*Math.PI/180:(s.startAngle+(t-i)/(r-i)*s.totalAngle)*Math.PI/180;if(this._getLogBase()){if(t<=0)return NaN;var h=Math.log(r/i);return Math.log(t/i)/h*s._radius}return(t-i)/(r-i)*s._radius}_renderLineAndTitle(t){var e=this._chart,a=wjcChart.FlexChart._CSS_LINE,r=(e.startAngle-90)*Math.PI/180,i=e.totalAngle*Math.PI/180,s=e._radius;this.axisType===wjcChart.AxisType.X&&this.axisLine&&(t.stroke=wjcChart.FlexChart._FG,e._isPolar?(r=e.reversed?r-i:r,t.drawPieSegment(e._center.x,e._center.y,s,r,i,a)):this._renderPolygon(t,s,a))}_renderPolygon(t,e,a){var r=this._chart,i=r._angles,s=i.length,h=r.axisX.minorGrid,n=[],l=[];if(i.forEach((t,a)=>{if(h&&a>0){var s=r._convertPoint(e,t.value-(t.value-i[a-1].value)/2);n.push(s.x),l.push(s.y)}var o=r._convertPoint(e,t.value);n.push(o.x),l.push(o.y)}),r.totalAngle<360)n.push(r._center.x),l.push(r._center.y);else if(h&&s>=2){var o=r._convertPoint(e,i[s-1].value-(i[s-2].value-i[s-1].value)/2);n.push(o.x),l.push(o.y)}t.drawPolygon(n,l,a)}_renderMinors(t,e,a,r){var i,s=this._chart,h=wjcChart.FlexChart._CSS_GRIDLINE_MINOR,n=this.minorGrid,l=s._angles,o=l.length,c=s.axisX.minorGrid,_=wjcChart.FlexChart._FG,d=this._GRIDLINE_WIDTH,u=(s.startAngle,Math.PI,s.totalAngle,Math.PI,this._TICK_OVERLAP),g=this.minorTickMarks,C=!0;this._vals.minor=e,g==wjcChart.TickMark.Outside?u=1:g==wjcChart.TickMark.Inside?u=-1:g==wjcChart.TickMark.Cross?u=0:C=!1,this.axisType==wjcChart.AxisType.Y?(t.stroke=_,t.strokeWidth=d,e.forEach(e=>{var a=this.convert(e);if(n&&this._renderYGridLine(t,s,a,h),C&&(l.forEach((e,r)=>{if(c&&r>0){i=e.value-(e.value-l[r-1].value)/2;var h=s._convertPoint(a,i);this._drawMinorTickLength(t,u,i,h)}i=e.value;var n=s._convertPoint(a,i);this._drawMinorTickLength(t,u,i,n)}),c&&o>=2)){i=l[o-1].value-(l[o-2].value-l[o-1].value)/2;var r=s._convertPoint(a,i);this._drawMinorTickLength(t,u,i,r)}})):(t.stroke=_,t.strokeWidth=d,e.forEach(e=>{var a=this.convert(e);n&&(this._renderXGridLine(t,s,a,h),C&&this._drawMinorTickLength(t,u,a-Math.PI/2,s._convertPoint(s._radius,a)))}))}_drawMinorTickLength(t,e,a,r){var i=this._TICK_HEIGHT,s=wjcChart.FlexChart._CSS_TICK_MINOR,h=.5*(e-1)*i*Math.cos(a),n=.5*(1+e)*i*Math.cos(a),l=.5*(e-1)*i*Math.sin(a),o=.5*(1+e)*i*Math.sin(a);t.drawLine(r.x+h,r.y+l,r.x+n,r.y+o,s)}_renderLabelsAndTicks(t,e,a,r,i,s,h,n,l){this._points=[],i=this.labelAngle||0;var o,c=this._chart,_=this.labelPadding||2,d=wjcChart.FlexChart._CSS_LABEL,u=wjcChart.FlexChart._CSS_GRIDLINE,g=wjcChart.FlexChart._CSS_TICK,C=wjcChart.FlexChart._FG,p=this._TICK_WIDTH,w=this.majorGrid,v=wjcChart.FlexChart._FG,y=this._GRIDLINE_WIDTH,x=c.startAngle*Math.PI/180,A=(c.totalAngle,Math.PI,1);if(this.axisType==wjcChart.AxisType.Y){w=a!=this.actualMin&&w&&a!=this.actualMax;var T=this.convert(a),m=c._convertPoint(T,x);if(w&&(t.stroke=v,t.strokeWidth=y,this._renderYGridLine(t,c,T,u)),t.stroke=C,t.strokeWidth=p,h){(o=(c.startAngle%360+360)%360)<=90&&o>=75||o>=270&&o<=285?A=2:(o>90&&o<=105||o<270&&o>=255)&&(A=0);S=new wjcCore.Point(m.x-_-Math.abs(n-l),m.y);this._axisLabels.push({val:a,text:r,pos:S,align:2,vAlign:A,labelAngle:i,class:d})}s!=wjcChart.TickMark.None&&t.drawLine(m.x-l*Math.cos(x),m.y-l*Math.sin(x),m.x-n*Math.cos(x),m.y-n*Math.sin(x),g)}else{var j=this.convert(a);if(w&&(t.stroke=v,t.strokeWidth=y,this._renderXGridLine(t,c,j,u)),t.stroke=C,t.strokeWidth=p,h){var P,L,f,S=c._convertPoint(c._radius+_,j);P=c._angles&&c._angles.length?c._angles[e].angle:c.startAngle+(a-this.actualMin)*c.totalAngle/(this.actualMax-this.actualMin),P=(P%=360)>=0?P:P+360,L=this._getXLabelVAlign(P),f=this._getXLabelAlign(P),c._isPolar&&(r=this._formatValue(P)),i>0?wjcChart.FlexChart._renderRotatedText(t,r,S,f,L,S,i,d):i<0?wjcChart.FlexChart._renderRotatedText(t,r,S,f,L,S,i,d):this._renderLabel(t,a,r,S,f,L,d)}s!=wjcChart.TickMark.None&&this._renderXTick(t,c,j,g,n,l)}return!0}_renderXGridLine(t,e,a,r){var i=e._center,s=e._convertPoint(e._radius,a);t.drawLine(i.x,i.y,s.x,s.y,r)}_renderXTick(t,e,a,r,i,s){var h,n;e._center;h=e._convertPoint(e._radius+i,a),n=e._convertPoint(e._radius+s,a),t.drawLine(h.x,h.y,n.x,n.y,r)}_renderYGridLine(t,e,a,r){e._angles;var i=e._center,s=e.startAngle*Math.PI/180,h=e.totalAngle*Math.PI/180;e._isPolar?(s=(e.startAngle-90)*Math.PI/180,s=e.reversed?s-h:s,t.drawPieSegment(i.x,i.y,a,s,h,r)):this._renderPolygon(t,a,r)}_getXLabelVAlign(t){var e=1,a=this._chart,r=a.startAngle;return a.reversed&&(t=(360+r+(r%360-t%360))%360),0===t?e=2:180===t&&(e=0),e}_getXLabelAlign(t){var e=0,a=this._chart,r=a.startAngle;return a.reversed&&(t=(360+r+(r%360-t%360))%360),t>0&&t<180?e=-1:t>180&&t<360&&(e=1),e+1}_createTimeLabels(t,e,a,r){if(this._axisType==wjcChart.AxisType.Y)super._createTimeLabels(t,e,a,r);else{var i=this._values;this.format;if(!i||0===i.length)return;i.forEach(t=>{a.push(t),r.push(this._formatValue(t))})}}_niceNumber(t,e,a){var r=this._chart,i=this.actualMax-this.actualMin,s=r.totalAngle;return s>360&&(s%=360),r._isPolar?s%8==0?i/8:s%6==0?i/6:s%4==0?i/4:s%3==0?i/3:s%2==0?i/2:super._niceNumber(t,e,a):super._niceNumber(t,e,a)}};export class _RadarLinePlotter extends wjcChart._LinePlotter{constructor(){super(...arguments),this.isArea=!1}_getLabelPoint(t,e){var a=t._getAxisX(),r=t._getAxisY(),i=a.convert(e.dataX),s=r.convert(e.dataY);return this.chart._convertPoint(s,i)}plotSeries(t,e,a,r,i,s,h){var n=wjcCore.asType(r,wjcChart.SeriesBase),l=this.chart,o=n._getChartType()||l._getChartType(),c=l.series.indexOf(r),_=r.getValues(0),d=r.getValues(1);if(_){d||(d=this.dataInfo.getXVals());var u=wjcChart._BasePlotter.cloneStyle(r.style,["fill"]),g=_.length,C=!0;d?g=Math.min(g,d.length):(C=!1,d=new Array(g));var p=this._DEFAULT_WIDTH,w=n._getSymbolFill(c),v=n._getAltSymbolFill(c)||w,y=n._getSymbolStroke(c),x=n._getAltSymbolStroke(c)||y,A=n._getSymbolSize();t.stroke=y,t.strokeWidth=p,t.fill=w;var T=new Array,m=new Array,j=this.stacking!=wjcChart.Stacking.None&&!n._isCustomAxisY(),P=this.stacking==wjcChart.Stacking.Stacked100pc&&!n._isCustomAxisY();void 0!==n._getChartType()&&(j=P=!1);for(var L=this.chart.interpolateNulls,f=!1,S=0;S<g;S++){var k=C?d[S]:S,b=_[S];if(wjcChart._DataInfo.isValid(k)&&wjcChart._DataInfo.isValid(b)){if(j)if(P&&(b/=this.dataInfo.getStackedAbsSum(k)),b>=0){M=isNaN(this.stackPos[k])?0:this.stackPos[k];b=this.stackPos[k]=M+b}else{var M=isNaN(this.stackNeg[k])?0:this.stackNeg[k];b=this.stackNeg[k]=M+b}var I;I=new wjcChart._DataPoint(c,S,k,b);var R=e.convert(k),N=a.convert(b),F=this.chart._convertPoint(N,R);if(k=F.x,b=F.y,isNaN(k)||isNaN(b))f=!0,!0!==L&&(T.push(void 0),m.push(void 0));else{T.push(k),m.push(b);var X=new wjcChart._CircleArea(new wjcCore.Point(k,b),.5*A);X.tag=I,this.hitTester.add(X,c)}}else f=!0,!0!==L&&(T.push(void 0),m.push(void 0))}var D=0;if(this.hasLines)if(this.isArea?t.fill=w||i._getColorLight(c):t.fill="none",f&&!0!==L){for(var V=[],G=[],S=0;S<g;S++)void 0===T[S]?(V.push(void 0),G.push(0)):(V.push(T[S]),G.push(m[S]));V.length>1&&(l._isPolar&&o!==wjcChart.ChartType.Area?this._drawLines(t,V,G,null,u,this.chart._plotrectId):(l.totalAngle<360&&(V.push(l._center.x),G.push(l._center.y)),t.drawPolygon(V,G,null,u,this.chart._plotrectId)),this.hitTester.add(new wjcChart._LinesArea(V,G),c),D++)}else l._isPolar&&o!==wjcChart.ChartType.Area?this._drawLines(t,T,m,null,u,this.chart._plotrectId):(l.totalAngle<360&&(T.push(l._center.x),m.push(l._center.y)),t.drawPolygon(T,m,null,u,this.chart._plotrectId)),this.hitTester.add(new wjcChart._LinesArea(T,m),c),D++;t.fill=w;for(S=0;S<g;S++){var k=T[S],b=m[S];!1===this.hasLines&&(t.fill=_[S]>0?w:v,t.stroke=_[S]>0?y:x),this.isValid(k,b,e,a)&&((this.hasSymbols||this.chart.itemFormatter)&&A>0&&this._drawSymbol(t,k,b,A,n,S),r._setPointIndex(S,D),D++)}}}};export class _RadarBarPlotter extends wjcChart._BarPlotter{adjustLimits(t,e){this.dataInfo=t;var a=t.getMinX(),r=t.getMinY(),i=t.getMaxX(),s=t.getMaxY(),h=t.getDeltaX();return h<=0&&(h=1),this.chart.totalAngle<360&&(h=0),this.unload(),this.chart.axisY._getLogBase()||(this.origin>s?s=this.origin:this.origin<r&&(r=this.origin)),new wjcCore.Rect(a,r,i-a+h,s-r)}_getLabelPoint(t,e){var a=t._getAxisX(),r=t._getAxisY(),i=a.convert(e.dataX),s=r.convert(e.dataY);return this.chart._convertPoint(s,i)}plotSeries(t,e,a,r,i,s,h){var n=this.chart.series.indexOf(r),l=wjcCore.asType(r,wjcChart.SeriesBase),o=(this.chart.options,this.width),c=this.chart,_=-90*Math.PI/180;s=s||0;var d,u=l._getAxisY()._uniqueId,g=(this.stackNegMap[u],this.stackPosMap[u]),C=this.stacking!=wjcChart.Stacking.None,p=this.stacking==wjcChart.Stacking.Stacked100pc,w=r.getValues(0),v=r.getValues(1);if(w){v||(v=this.dataInfo.getXVals());var y;(y=v?c.totalAngle/v.length:c.totalAngle/(e.actualMax-e.actualMin))>0&&(o=C?y*o*Math.PI/180:y*Math.pow(o,s+1)*Math.PI/180);var x=l._getSymbolFill(n),A=l._getAltSymbolFill(n)||x,T=l._getSymbolStroke(n),m=l._getAltSymbolStroke(n)||T,j=w.length;null!=v&&(j=Math.min(j,v.length));var P,L,f=this.origin,S=0;void 0!==l._getChartType()&&(C=p=!1),f<a.actualMin?f=a.actualMin:f>a.actualMax&&(f=a.actualMax);a.convert(f);var k=e.actualMin,b=e.actualMax;l._isCustomAxisY()&&(C=p=!1),c._areas[n]||(c._areas[n]=[]);for(var M=0;M<j;M++){var I=v?v[M]:M,R=w[M];if(this._getSymbolOrigin&&a.convert(this._getSymbolOrigin(f,M,j)),this._getSymbolStyles){var N=this._getSymbolStyles(M,j);x=N&&N.fill?N.fill:x,A=N&&N.fill?N.fill:A,T=N&&N.stroke?N.stroke:T,m=N&&N.stroke?N.stroke:m}if(P=R>0?x:A,L=R>0?T:m,t.fill=P,t.stroke=L,wjcChart._DataInfo.isValid(I)&&wjcChart._DataInfo.isValid(R)){if(C){var F=I-.5*o,X=I+.5*o;if(F<k&&X<k||F>b&&X>b)continue;if(F=e.convert(F),X=e.convert(X),!wjcChart._DataInfo.isValid(F)||!wjcChart._DataInfo.isValid(X))continue;var D,V;p&&(R/=this.dataInfo.getStackedAbsSum(I));var G=isNaN(g[I])?0:g[I];D=G,V=G+R,g[I]=G+R;var Y=e.convert(I),E=a.convert(D),B=a.convert(V);Y-=o/2,t.drawDonutSegment(c._center.x,c._center.y,B,E,Y+_,o,null,l.symbolStyle),(d=new wjcChart._DonutSegment(new wjcCore.Point(c._center.x,c._center.y),B,E,Y+_,o,c.startAngle||0)).tag=new wjcChart._DataPoint(n,M,I,G+R),this.hitTester.add(d,n)}else{var Y=e.convert(I),O=a.convert(R);c._convertPoint(O,Y);Y-=o/2,t.drawPieSegment(c._center.x,c._center.y,O,Y+_,o,null,l.symbolStyle),(d=new wjcChart._PieSegment(new wjcCore.Point(c._center.x,c._center.y),O,Y+_,o,c.startAngle)).tag=new wjcChart._DataPoint(n,M,I,R),this.hitTester.add(d,n)}c._areas[n].push(d),r._setPointIndex(M,S),S++}}}}};