/*
    *
    * 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/
    *
    */
import*as wjcCore from"wijmo/wijmo";import*as wjcChart from"wijmo/wijmo.chart";import*as wjcSelfRef from"wijmo/wijmo.chart.interaction";var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.chart=window.wijmo.chart||{},window.wijmo.chart.interaction=wjcSelf;export class _RangeSlider{constructor(t,e,i,s){this._isVisible=!0,this._buttonsVisible=!0,this._minScale=0,this._maxScale=1,this._seamless=!1,this._rsContainer=null,this._rsEle=null,this._decBtn=null,this._incBtn=null,this._rsContent=null,this._minHandler=null,this._rangeHandler=null,this._maxHandler=null,this._wrapperSliderMousedown=null,this._wrapperDocMouseMove=null,this._wrapperDocMouseup=null,this._wrapperBtnMousedown=null,this._wrapperRangeSpaceMousedown=null,this._wrapperRangeMouseleave=null,this._isTouch=!1,this._slidingInterval=null,this._rangeSliderRect=null,this._isHorizontal=!0,this._isBtnMousedown=!1,this._needSpaceClick=!1,this._hasButtons=!0,this._movingEle=null,this._movingOffset=null,this._range=null,this._startPt=null,this._minPos=0,this._maxPos=1,this.rangeChanged=new wjcCore.Event,this.rangeChanging=new wjcCore.Event,t||wjcCore.assert(!1,"The container cannot be null."),this._isTouch="ontouchstart"in window,this._needSpaceClick=e,this._hasButtons=i,wjcCore.copy(this,s),this._createSlider(t)}get buttonsVisible(){return this._buttonsVisible}set buttonsVisible(t){if(t!=this._buttonsVisible){if(this._buttonsVisible=wjcCore.asBoolean(t),!this._rsContainer||!this._hasButtons)return;this._refresh()}}get isHorizontal(){return this._isHorizontal}set isHorizontal(t){if(t!=this._isHorizontal){if(this._isHorizontal=wjcCore.asBoolean(t),!this._rsContainer)return;this._invalidate()}}get isVisible(){return this._isVisible}set isVisible(t){if(t!=this._isVisible){if(this._isVisible=wjcCore.asBoolean(t),!this._rsContainer)return;this._rsContainer.style.visibility=this._isVisible?"visible":"hidden"}}get minScale(){return this._minScale}set minScale(t){t>=0&&t!=this._minScale&&(this._minScale=wjcCore.asNumber(t))}get maxScale(){return this._maxScale}set maxScale(t){t>=0&&t!=this._maxScale&&(this._maxScale=wjcCore.asNumber(t))}get seamless(){return this._seamless}set seamless(t){t!=this._seamless&&(this._seamless=wjcCore.asBoolean(t))}onRangeChanged(t){this.rangeChanged.raise(this,t)}onRangeChanging(t){this.rangeChanging.raise(this,t)}get _isSliding(){return null!==this._startPt}get _handleWidth(){return this._minHandler.offsetWidth}_createSlider(t){var e=this._isHorizontal?_RangeSlider._HRANGESLIDER:_RangeSlider._VRANGESLIDER,i=this._isHorizontal?"wj-glyph-left":"wj-glyph-down",s=this._isHorizontal?"wj-glyph-right":"wj-glyph-up";this._rsContainer=t,this._rsContainer.style.visibility=this._isVisible?"visible":"hidden",this._rsEle=wjcCore.createElement('<div class="wj-chart-rangeslider '+e+'"></div>'),this._rsContainer.appendChild(this._rsEle),this._hasButtons&&(this._decBtn=wjcCore.createElement('<button class="wj-rangeslider-decbtn wj-btn wj-btn-default" type="button" tabindex="-1"><span class="'+i+" "+_RangeSlider._RANGESLIDER_DECBTN+'"></span></button>'),this._rsEle.appendChild(this._decBtn),this._incBtn=wjcCore.createElement('<button class="wj-rangeslider-incbtn wj-btn wj-btn-default" type="button" tabindex="-1"><span class="'+s+" "+_RangeSlider._RANGESLIDER_INCBTN+'"></span></button>'),this._rsEle.appendChild(this._incBtn)),this._rsContent=wjcCore.createElement('<div class="wj-rangeslider-content"><div class="wj-rangeslider-rangehandle"></div><div class="wj-rangeslider-minhandle"></div><div class="wj-rangeslider-maxhandle"></div>'),this._rsEle.appendChild(this._rsContent),this._minHandler=this._rsContent.querySelector("."+_RangeSlider._RANGESLIDER_MINHANDLE),this._rangeHandler=this._rsContent.querySelector("."+_RangeSlider._RANGESLIDER_RANGEHANDLE),this._maxHandler=this._rsContent.querySelector("."+_RangeSlider._RANGESLIDER_MAXHANDLE),this._wrapperSliderMousedown=this._onSliderMousedown.bind(this),this._wrapperDocMouseMove=this._onDocMouseMove.bind(this),this._wrapperDocMouseup=this._onDocMouseup.bind(this),this._wrapperRangeSpaceMousedown=this._onRangeSpaceMousedown.bind(this),this._wrapperRangeMouseleave=this._onRangeMouseleave.bind(this),this._wrapperBtnMousedown=this._onBtnMousedown.bind(this),this._switchEvent(!0)}_switchEvent(t){var e=t?"addEventListener":"removeEventListener";this._rsContainer&&(this._needSpaceClick&&this._rsEle[e]("mousedown",this._wrapperRangeSpaceMousedown),this._rsEle[e]("mouseleave",this._wrapperRangeMouseleave),this._rsContent[e]("mousedown",this._wrapperSliderMousedown),this._hasButtons&&(this._decBtn[e]("mousedown",this._wrapperBtnMousedown),this._incBtn[e]("mousedown",this._wrapperBtnMousedown)),document[e]("mousemove",this._wrapperDocMouseMove),document[e]("mouseup",this._wrapperDocMouseup),"ontouchstart"in window&&(this._needSpaceClick&&this._rsEle[e]("touchstart",this._wrapperRangeSpaceMousedown),this._rsContent[e]("touchstart",this._wrapperSliderMousedown),this._hasButtons&&(this._decBtn[e]("touchstart",this._wrapperBtnMousedown),this._incBtn[e]("touchstart",this._wrapperBtnMousedown)),document[e]("touchmove",this._wrapperDocMouseMove),document[e]("touchend",this._wrapperDocMouseup)))}_onSliderMousedown(t){this._isVisible&&(this._movingEle=t.srcElement||t.target,this._startPt=t instanceof MouseEvent?new wjcCore.Point(t.pageX,t.pageY):new wjcCore.Point(t.changedTouches[0].pageX,t.changedTouches[0].pageY),wjcCore.removeClass(this._minHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE),wjcCore.removeClass(this._maxHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE),this._movingOffset=wjcCore.getElementRect(this._movingEle),this._movingEle!=this._rangeHandler?(this._isHorizontal?this._movingOffset.left+=.5*this._movingEle.offsetWidth:this._movingOffset.top+=.5*this._movingEle.offsetHeight,wjcCore.addClass(this._movingEle,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE)):this._range=this._maxPos-this._minPos,t.preventDefault())}_onDocMouseMove(t){if(this._isVisible&&this._startPt){var e=t instanceof MouseEvent?new wjcCore.Point(t.pageX,t.pageY):new wjcCore.Point(t.changedTouches[0].pageX,t.changedTouches[0].pageY);this._onMove(e)}}_onMove(t){var e,i=this,s=this._startPt,a=this._movingOffset,n=this._plotBox,h=this._range,r=this._movingEle,o=this._minHandler,_=this._rangeHandler,l=this._maxHandler;s&&a&&((e=this._isHorizontal?(a.left+t.x-s.x-n.x)/n.width:1-(a.top+t.y-s.y-n.y)/n.height)<0?e=0:e>1&&(e=1),r===o?this._seamless&&0===this._minScale&&e>=this._maxPos?(i._minPos=i._maxPos,i._movingEle=l,wjcCore.removeClass(this._minHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE),wjcCore.addClass(this._maxHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE)):(e>this._maxPos-this._minScale&&(e=this._maxPos-this._minScale),e<this._maxPos-this._maxScale&&(e=this._maxPos-this._maxScale),this._minPos=e):r===l?this._seamless&&0===this._minScale&&e<=this._minPos?(i._maxPos=i._minPos,i._movingEle=o,wjcCore.removeClass(this._maxHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE),wjcCore.addClass(this._minHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE)):(e<this._minPos+this._minScale&&(e=this._minPos+this._minScale),e>this._minPos+this._maxScale&&(e=this._minPos+this._maxScale),this._maxPos=e):r===_&&(this._isHorizontal?(this._minPos=e,this._maxPos=this._minPos+h,this._maxPos>=1&&(this._maxPos=1,this._minPos=this._maxPos-h)):(this._maxPos=e,this._minPos=this._maxPos-h,this._minPos<=0&&(this._minPos=0,this._maxPos=this._minPos+h))),this._updateElesPosition(),this.onRangeChanging())}_onDocMouseup(t){this._isVisible&&(this._clearInterval(),this._isBtnMousedown=!1,this._startPt&&(this.onRangeChanged(),this._startPt=null,this._movingOffset=null),wjcCore.removeClass(this._minHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE),wjcCore.removeClass(this._maxHandler,_RangeSlider._RANGESLIDER_HANDLE_ACTIVE))}_onRangeSpaceMousedown(t){var e=t instanceof MouseEvent?new wjcCore.Point(t.pageX,t.pageY):new wjcCore.Point(t.changedTouches[0].pageX,t.changedTouches[0].pageY),i=wjcCore.getElementRect(this._rsContent),s=wjcCore.getElementRect(this._rangeHandler),a=t.srcElement||t.target,n=0;t.stopPropagation(),t.preventDefault(),a!==this._rsContent&&a!==this._rsEle||(this._isHorizontal?(n=s.width/i.width,e.x<s.left?n*=-1:e.x>s.left+s.width&&(n*=1)):(n=s.height/i.height,e.y<s.top?n*=1:e.y>s.top+s.height&&(n*=-1)),0!==n&&this._doSliding(n,e))}_onRangeMouseleave(t){t.stopPropagation(),t.preventDefault(),this._isBtnMousedown&&(this._clearInterval(),this.onRangeChanged())}_onBtnMousedown(t){var e=t.srcElement||t.target,i=0;if(t.stopPropagation(),t.preventDefault(),wjcCore.hasClass(e,_RangeSlider._RANGESLIDER_DECBTN)){if(0===this._minPos)return;i=-.05}else if(wjcCore.hasClass(e,_RangeSlider._RANGESLIDER_INCBTN)){if(1===this._maxPos)return;i=.05}this._isBtnMousedown=!0,0!==i&&this._doSliding(i)}_refresh(t){var e,i,s=0,a=wjcCore.getElementRect(this._rsContainer);t&&(this._rangeSliderRect=t),this._rangeSliderRect&&(this._hasButtons&&this._buttonsVisible?(this._decBtn.style.display="block",this._incBtn.style.display="block",s=this._isHorizontal?this._decBtn.offsetWidth+this._minHandler.offsetWidth/2:this._decBtn.offsetHeight+this._minHandler.offsetHeight/2):(this._hasButtons&&(this._decBtn.style.display="none",this._incBtn.style.display="none"),s=this._isHorizontal?this._minHandler.offsetWidth/2:this._minHandler.offsetHeight/2),e=this._getRsRect(),this._isHorizontal?(e.left-=this._minHandler.offsetWidth/2,e.width+=this._minHandler.offsetWidth,i={left:s,width:e.width-2*s}):(e.top-=this._minHandler.offsetHeight/2,e.height+=this._minHandler.offsetHeight,i={top:s,height:e.height-2*s}),wjcCore.setCss(this._rsEle,e),wjcCore.setCss(this._rsContent,i),a=wjcCore.getElementRect(this._rsContent),this._plotBox={x:a.left,y:a.top,width:a.width,height:a.height},this._updateElesPosition())}_updateElesPosition(){var t,e,i,s=this._minHandler,a=(this._rangeHandler,this._maxHandler),n=this._plotBox,h=this._isHorizontal;n&&(t=h?{left:this._minPos*n.width-.5*s.offsetWidth}:{top:(1-this._minPos)*n.height-.5*a.offsetHeight},e=h?{left:this._minPos*n.width,width:(this._maxPos-this._minPos)*n.width}:{top:(1-this._maxPos)*n.height,height:(this._maxPos-this._minPos)*n.height},i=h?{left:this._maxPos*n.width-.5*a.offsetWidth}:{top:(1-this._maxPos)*n.height-.5*s.offsetHeight},this._refreshSlider(t,e,i))}_refreshSlider(t,e,i){wjcCore.setCss(this._minHandler,t),wjcCore.setCss(this._rangeHandler,e),wjcCore.setCss(this._maxHandler,i)}_invalidate(){var t,e;this._rsContainer&&(t=this._isHorizontal?_RangeSlider._HRANGESLIDER:_RangeSlider._VRANGESLIDER,e=this._isHorizontal?_RangeSlider._VRANGESLIDER:_RangeSlider._HRANGESLIDER,wjcCore.removeClass(this._rsEle,e),wjcCore.addClass(this._rsEle,t),[this._rsEle,this._rsContent,this._minHandler,this._maxHandler,this._rangeHandler].forEach(t=>{t.removeAttribute("style")}),this._refresh())}_changeRange(t){var e=this._maxPos-this._minPos;t<0&&0===this._minPos||t>0&&1===this._maxPos||(t<0?(this._minPos+=t,this._minPos=this._minPos<0?0:this._minPos,this._maxPos=this._minPos+e):(this._maxPos+=t,this._maxPos=this._maxPos>1?1:this._maxPos,this._minPos=this._maxPos-e),this._updateElesPosition())}_doSliding(t,e){wjcCore.getElementRect(this._rsContent),wjcCore.getElementRect(this._rangeHandler);this._clearInterval(),this._startPt=new wjcCore.Point,this._changeRange(t),this.onRangeChanged(),this._setSlidingInterval(t,e)}_setSlidingInterval(t,e){var i,s,a=this;this._slidingInterval=window.setInterval(function(){if(e)if(i=wjcCore.getElementRect(a._rsContent),s=wjcCore.getElementRect(a._rangeHandler),a._isHorizontal){if(e.x>=s.left&&e.x<=s.left+s.width)return void a._clearInterval()}else if(e.y>=s.top&&e.y<=s.top+s.height)return void a._clearInterval();a._changeRange(t),a.onRangeChanged()},200)}_clearInterval(){this._slidingInterval&&window.clearInterval(this._slidingInterval)}_getRsRect(){var t=this._rangeSliderRect,e={};if(t)return["left","top","width","height"].forEach(function(i){t[i]&&(e[i]=t[i])}),e}};_RangeSlider._HRANGESLIDER="wj-chart-hrangeslider",_RangeSlider._VRANGESLIDER="wj-chart-vrangeslider",_RangeSlider._RANGESLIDER_DECBTN="wj-rangeslider-decbtn",_RangeSlider._RANGESLIDER_INCBTN="wj-rangeslider-incbtn",_RangeSlider._RANGESLIDER_RANGEHANDLE="wj-rangeslider-rangehandle",_RangeSlider._RANGESLIDER_MINHANDLE="wj-rangeslider-minhandle",_RangeSlider._RANGESLIDER_MAXHANDLE="wj-rangeslider-maxhandle",_RangeSlider._RANGESLIDER_HANDLE_ACTIVE="wj-rangeslider-handle-active";export var Orientation;!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(Orientation||(Orientation={}));export class RangeSelector{constructor(t,e){this._isVisible=!0,this._orientation=Orientation.X,this._seamless=!1,this._minScale=0,this._maxScale=1,this.rangeChanged=new wjcCore.Event,this._chart=wjcCore.asType(t,wjcChart.FlexChartCore,!1),this._createRangeSelector(),wjcCore.copy(this,e)}get isVisible(){return this._isVisible}set isVisible(t){t!=this._isVisible&&(this._isVisible=wjcCore.asBoolean(t),this._rangeSlider&&(this._rangeSlider.isVisible=t))}get min(){return this._min}set min(t){if((t=wjcCore.asNumber(t,!0,!1))!=this._min){var e=!1;null==t||void 0===t||isNaN(t)||null==this._max?(this._min=t,e=!0):t<=this._max&&(this._min=t,e=!0),this._rangeSlider&&e&&this._changeRange()}}get max(){return this._max}set max(t){if((t=wjcCore.asNumber(t,!0,!1))!=this._max){var e=!1;null==t||isNaN(t)?(this._max=t,e=!0):t>=this._min&&(this._max=t,e=!0),this._rangeSlider&&e&&this._changeRange()}}get orientation(){return this._orientation}set orientation(t){(t=wjcCore.asEnum(t,Orientation))!==this._orientation&&(this._orientation=t,this._rangeSlider&&(this._rangeSlider.isHorizontal=t==Orientation.X))}get seamless(){return this._seamless}set seamless(t){(t=wjcCore.asBoolean(t,!0))!=this._seamless&&(this._seamless=t,this._rangeSlider&&(this._rangeSlider.seamless=t))}get minScale(){return this._minScale}set minScale(t){(t=wjcCore.asNumber(t))<=1&&t>=0&&t!=this._minScale&&t<this._maxScale&&(this._minScale=t,this._rangeSlider&&(this._rangeSlider.minScale=wjcCore.asNumber(t),this._updateMinAndMaxWithScale(!0)))}get maxScale(){return this._maxScale}set maxScale(t){(t=wjcCore.asNumber(t))<=1&&t>=0&&t!=this._maxScale&&t>this._minScale&&(this._maxScale=t,this._rangeSlider&&(this._rangeSlider.maxScale=wjcCore.asNumber(t),this._updateMinAndMaxWithScale(!0)))}remove(){this._rangeSelectorEle&&(this._chart.hostElement.removeChild(this._rangeSelectorEle),this._switchEvent(!1),this._rangeSelectorEle=null,this._rangeSlider=null)}onRangeChanged(t){this.rangeChanged.raise(this,t)}_createRangeSelector(){var t=this._chart.hostElement,e=this._orientation===Orientation.X;this._rangeSelectorEle=wjcCore.createElement('<div class="wj-chart-rangeselector-container"></div>'),this._rangeSlider=new _RangeSlider(this._rangeSelectorEle,!1,!1,{isHorizontal:e,isVisible:this._isVisible,seamless:this._seamless}),t.appendChild(this._rangeSelectorEle),this._switchEvent(!0)}_switchEvent(t){var e=t?"addHandler":"removeHandler";this._chart.hostElement&&(this._rangeSlider.rangeChanged[e](this._updateRange,this),this._chart.rendered[e](this._refresh,this))}_refresh(){var t,e,i,s=this._chart.hostElement,a=wjcCore.getElementRect(this._rangeSelectorEle);t=s.querySelector("."+wjcChart.FlexChart._CSS_PLOT_AREA),e=wjcCore.getElementRect(t),(i=t.getBBox())&&i.width&&i.height&&(this._adjustMinAndMax(),this._rangeSlider._refresh({left:i.x,top:e.top-a.top,width:i.width,height:i.height}))}_adjustMinAndMax(){var t=this,e=t._chart,i=t._rangeSlider,s=t._min,a=t._max,n=t._orientation===Orientation.X?e.axisX:e.axisY,h=wjcCore.isDate(n.actualMin)?n.actualMin.valueOf():n.actualMin,r=wjcCore.isDate(n.actualMax)?n.actualMax.valueOf():n.actualMax;t._min=null===s||isNaN(s)||void 0===s||s<h||s>r?h:s,t._max=null===a||isNaN(a)||void 0===a||a<h||a>r?r:a;var o=this._chart._plotRect;if(o){let e,s;this._orientation===Orientation.X?(e=(n.convert(t._min)-o.left)/o.width,s=(n.convert(t._max)-o.left)/o.width):(e=(o.top-n.convert(t._min))/o.height+1,s=(o.top-n.convert(t._max))/o.height+1),i._minPos=isNaN(e)?0:e,i._maxPos=isNaN(s)?1:s,this._updateMinAndMaxWithScale(!1)}}_updateMinAndMaxWithScale(t){var e,i=this._rangeSlider,s=!1;if(0!==this._minScale&&i._minPos+this._minScale>i._maxPos&&((e=i._minPos+this._minScale)>1?(i._maxPos=1,i._minPos=1-this._minScale):i._maxPos=e,s=!0),1!==this._maxScale&&i._minPos+this._maxScale<i._maxPos&&((e=i._minPos+this._maxScale)>1?(i._maxPos=1,i._minPos=1-this._maxScale):i._maxPos=e,s=!0),s){var a=this._getMinAndMax();this._min=a.min,this._max=a.max,t&&this._rangeSelectorEle&&(this._rangeSlider._refresh(),this.onRangeChanged())}}_changeRange(){this._adjustMinAndMax(),this._rangeSelectorEle&&(this._rangeSlider._refresh(),this.onRangeChanged())}_updateRange(){var t;this._rangeSlider;t=this._chart,this._orientation===Orientation.X?t.axisX:t.axisY;var e=this._getMinAndMax();this._min=e.min,this._max=e.max,this.onRangeChanged()}_getMinAndMax(){var t=this._rangeSlider,e=this._chart,i=e._plotRect,s=null,a=null;return i&&(this._orientation===Orientation.X?(s=e.axisX.convertBack(i.left+t._minPos*i.width),a=e.axisX.convertBack(i.left+t._maxPos*i.width)):(s=e.axisY.convertBack(i.top+(1-t._minPos)*i.height),a=e.axisY.convertBack(i.top+(1-t._maxPos)*i.height))),{min:s,max:a}}};export var MouseAction;!function(t){t[t.Zoom=0]="Zoom",t[t.Pan=1]="Pan"}(MouseAction||(MouseAction={}));export var InteractiveAxes;!function(t){t[t.X=0]="X",t[t.Y=1]="Y",t[t.XY=2]="XY"}(InteractiveAxes||(InteractiveAxes={}));export class ChartGestures{constructor(t,e){this._chart=null,this._zoomEle=null,this._overlayEle=null,this._wrapperMousedown=null,this._wrapperMouseMove=null,this._wrapperMouseup=null,this._wrapperPointerdown=null,this._wrapperPointerMove=null,this._wrapperPointerup=null,this._wrapperTouchStart=null,this._wrapperTouchMove=null,this._wrapperTouchEnd=null,this._wrapperMouseWheel=null,this._startFirstPt=null,this._minX=null,this._maxX=null,this._minY=null,this._maxY=null,this._threadHold=20,this._clip={},this._selection={},this._startPointers=[],this._mvPointers=[],this._pinchStartEvents=[],this._minXRange=null,this._minYRange=null,this._innerUpdating=!1,this._lastMinX=null,this._lastMaxX=null,this._lastMinY=null,this._lastMaxY=null,this._mouseAction=MouseAction.Zoom,this._interactiveAxes=InteractiveAxes.X,this._enable=!0,this._scaleX=1,this._scaleY=1,this._posX=0,this._posY=0,t||wjcCore.assert(!1,"The FlexChart cannot be null."),this._chart=t,wjcCore.copy(this,e),this._initialize()}get mouseAction(){return this._mouseAction}set mouseAction(t){this._mouseAction=wjcCore.asEnum(t,MouseAction)}get interactiveAxes(){return this._interactiveAxes}set interactiveAxes(t){t!==this._interactiveAxes&&(this._interactiveAxes=wjcCore.asEnum(t,InteractiveAxes))}get enable(){return this._enable}set enable(t){t!==this._enable&&(this._enable=wjcCore.asBoolean(t,!0))}get scaleX(){return this._scaleX}set scaleX(t){t!==this._scaleX&&(this._scaleX=t<0?0:t>1?1:wjcCore.asNumber(t),this._seriesGroup&&this._initAxisRangeWithPosAndScale(!0))}get scaleY(){return this._scaleY}set scaleY(t){t!==this._scaleY&&(this._scaleY=t<0?0:t>1?1:wjcCore.asNumber(t),this._seriesGroup&&this._initAxisRangeWithPosAndScale(!1))}get posX(){return this._posX}set posX(t){t!==this._posX&&(this._posX=t<0?0:t>1?1:wjcCore.asNumber(t),this._seriesGroup&&this._initAxisRangeWithPosAndScale(!0))}get posY(){return this._posY}set posY(t){t!==this._posY&&(this._posY=t<0?0:t>1?1:wjcCore.asNumber(t),this._seriesGroup&&this._initAxisRangeWithPosAndScale(!1))}remove(){this._zoomEle&&(this._chart.hostElement.removeChild(this._zoomEle),this._zoomEle=null),wjcCore.removeClass(this._chart.hostElement,ChartGestures._CSS_TOUCH_DISABLED),this._switchEvent(!1),this._wrapperMousedown=null,this._wrapperMouseMove=null,this._wrapperMouseup=null,this._wrapperPointerdown=null,this._wrapperPointerMove=null,this._wrapperPointerup=null,this._wrapperTouchStart=null,this._wrapperTouchMove=null,this._wrapperTouchEnd=null,this._wrapperMouseWheel=null}reset(){var t=this._chart,e=t.axisX,i=t.axisY;this._maxX&&(e.max=this._maxX),this._minX&&(e.min=this._minX),this._maxY&&(i.max=this._maxY),this._minY&&(i.min=this._minY),this._initAxisRangeWithPosAndScale(!0),this._initAxisRangeWithPosAndScale(!1)}_refreshChart(){var t=this._chart,e=t.axisX,i=t.axisY;this._minX=this._getAxisMin(e),this._maxX=this._getAxisMax(e),this._minY=this._getAxisMin(i),this._maxY=this._getAxisMax(i),this._minXRange=.005*(this._maxX-this._minX),this._minYRange=.005*(this._maxY-this._minY),this._initAxisRangeWithPosAndScale(!0),this._initAxisRangeWithPosAndScale(!1)}_initialize(){var t=this._chart.hostElement;this._zoomEle=wjcCore.createElement('<div class="'+ChartGestures._CSS_ZOOM+'"><div class="'+ChartGestures._CSS_ZOOM_OVERLAY+'"></div>'),this._zoomEle.style.visibility="visible",t.appendChild(this._zoomEle),wjcCore.addClass(t,ChartGestures._CSS_TOUCH_DISABLED),this._overlayEle=this._zoomEle.querySelector("."+ChartGestures._CSS_ZOOM_OVERLAY),this._wrapperMousedown=this._onMousedown.bind(this),this._wrapperMouseMove=this._onMouseMove.bind(this),this._wrapperMouseup=this._onMouseup.bind(this),this._wrapperPointerdown=this._onPointerdown.bind(this),this._wrapperPointerMove=this._onPointerMove.bind(this),this._wrapperPointerup=this._onPointerup.bind(this),this._wrapperMouseWheel=this._onMouseWheel.bind(this),this._wrapperTouchStart=this._onTouchStart.bind(this),this._wrapperTouchMove=this._onTouchMove.bind(this),this._wrapperTouchEnd=this._onTouchEnd.bind(this),this._switchEvent(!0)}_switchEvent(t){var e=this._chart.hostElement,i=t?"addEventListener":"removeEventListener",s=t?"addHandler":"removeHandler";e&&(e[i]("mousedown",this._wrapperMousedown),e[i]("mousemove",this._wrapperMouseMove),document[i]("mouseup",this._wrapperMouseup),"onpointerdown"in window&&(e[i]("pointerdown",this._wrapperPointerdown),e[i]("pointermove",this._wrapperPointerMove),document[i]("pointerup",this._wrapperPointerup)),e[i]("wheel",this._wrapperMouseWheel),"ontouchstart"in window&&(e[i]("touchstart",this._wrapperTouchStart),e[i]("touchmove",this._wrapperTouchMove),document[i]("touchend",this._wrapperTouchEnd)),this._chart.rendered[s](this._refresh,this))}_refresh(){var t,e,i,s=this._chart,a=s.axisX,n=s.axisY,h=s.hostElement;this._seriesGroup=h.querySelector(".wj-series-group"),t=h.querySelector("."+wjcChart.FlexChart._CSS_PLOT_AREA),this._plotOffset=wjcCore.getElementRect(t),this._plotBox=t.getBBox(),this._zoomEleOffset=wjcCore.getElementRect(this._zoomEle),this._overlayEle&&this._overlayEle.removeAttribute("style"),this._innerUpdating?this._innerUpdating=!1:(e=!1,i=!1,(null===this._minX||isNaN(this._minX)||0===this._minX||-1===this._minX||this._lastMinX!==this._getAxisMin(a))&&(this._minX=this._getAxisMin(a),null===this._minX||isNaN(this._minX)||0===this._minX||-1===this._minX||(e=!0)),(null===this._maxX||isNaN(this._maxX)||0===this._maxX||-1===this._maxX||this._lastMaxX!==this._getAxisMax(a))&&(this._maxX=this._getAxisMax(a),null===this._maxX||isNaN(this._maxX)||0===this._maxX||-1===this._maxX||(e=!0)),(null===this._minY||isNaN(this._minY)||this._lastMinY!==this._getAxisMin(n))&&(this._minY=this._getAxisMin(n),isNaN(this._minY)||(i=!0)),(null===this._maxY||isNaN(this._maxY)||this._lastMaxY!==this._getAxisMax(n))&&(this._maxY=this._getAxisMax(n),isNaN(this._maxY)||(i=!0)),this._minXRange=.005*(this._maxX-this._minX),this._minYRange=.005*(this._maxY-this._minY),e&&null!==this._scaleX&&void 0!==this._scaleX&&1!==this._scaleX&&null!==this._posX&&void 0!==this._posX&&0!==this._posX&&this._initAxisRangeWithPosAndScale(!0),i&&null!==this._scaleY&&void 0!==this._scaleY&&1!==this._scaleY&&null!==this._posY&&void 0!==this._posY&&0!==this._posY&&this._initAxisRangeWithPosAndScale(!1))}_onMousedown(t){this._enable&&(this._disabledOthersInteraction(!0),this._mouseDown(t),t.preventDefault())}_onMouseMove(t){this._enable&&(this._mouseMove(t),t.preventDefault())}_onMouseup(t){this._enable&&(this._mouseup(t),this._disabledOthersInteraction(!1))}_onMouseWheel(t){var e=-t.deltaY>0?.05:-.05;this._enable&&(this._scaling=!0,this._interactiveAxes!==InteractiveAxes.X&&this._interactiveAxes!==InteractiveAxes.XY||this._updateAxisByChg(!0,e,-e),this._interactiveAxes!==InteractiveAxes.Y&&this._interactiveAxes!==InteractiveAxes.XY||this._updateAxisByChg(!1,e,-e),this._scaling=!1,t.preventDefault())}_mouseDown(t){this._startFirstPt=this._getPoint(t),this._updatePoint(this._startFirstPt),this._mouseAction===MouseAction.Zoom?this._initOverlay():(this._seriesGroup.setAttribute("clip-path","url(#"+this._chart._plotrectId+")"),wjcCore.toggleClass(this._chart.hostElement,ChartGestures._CSS_PANABLE,this._mouseAction===MouseAction.Pan))}_mouseMove(t){var e;this._startFirstPt&&(e=this._getPoint(t),this._updatePoint(e),this._endPoint=new wjcCore.Point(e.x,e.y),this._mouseAction===MouseAction.Zoom?this._updateOverLay(e):(this._panning=!0,this._panningChart(e.x-this._startFirstPt.x,e.y-this._startFirstPt.y)))}_mouseup(t){var e=this._endPoint;this._chart.axisX;if(!this._startFirstPt||!e)return wjcCore.removeClass(this._chart.hostElement,ChartGestures._CSS_PANABLE),void this._reset();this._mouseAction===MouseAction.Zoom?(this._zoomedChart(e),this._reset()):(this._pannedChart(e.x-this._startFirstPt.x,e.y-this._startFirstPt.y),this._reset()),wjcCore.removeClass(this._chart.hostElement,ChartGestures._CSS_PANABLE)}_onPointerdown(t){if(this._enable){switch(this._disabledOthersInteraction(!0),t.pointerType){case"touch":this._pointerDown(t);break;case"mouse":this._mouseDown(t)}t.preventDefault()}}_onPointerMove(t){if(this._enable){switch(t.pointerType){case"touch":this._pointerMove(t);break;case"mouse":this._mouseMove(t)}t.preventDefault()}}_onPointerup(t){if(this._enable){switch(t.pointerType){case"touch":this._pointerUp(t);break;case"mouse":this._mouseup(t)}this._disabledOthersInteraction(!1),t.preventDefault()}}_pointerDown(t){t.preventManipulation&&t.preventManipulation(),this._seriesGroup.setAttribute("clip-path","url(#"+this._chart._plotrectId+")"),this._startPointers.push({id:t.pointerId,x:t.pageX,y:t.pageY}),1===this._startPointers.length?(this._scaling=!1,this._panning=!0):2===this._startPointers.length&&(this._panning=!1,this._scaling=!0,this._startDistance={x:this._startPointers[0].x-this._startPointers[1].x,y:this._startPointers[0].y-this._startPointers[1].y})}_pointerMove(t){var e,i,s,a,n=new wjcCore.Point(t.pageX,t.pageY),h={},r={};if(t.preventManipulation&&t.preventManipulation(),this._panning){if(!this._pointInPlotArea(n))return;this._endPoint=new wjcCore.Point(t.pageX,t.pageY),this._panningChart(this._endPoint.x-this._startPointers[0].x,this._endPoint.y-this._startPointers[0].y)}else this._scaling&&(e=this._startPointers[0].id+"",i=this._startPointers[1].id+"",this._mvPointers[t.pointerId+""]={x:t.pageX,y:t.pageY},this._mvPointers[e]&&this._mvPointers[i]&&(Math.abs(this._startDistance.x)>this._threadHold&&this._interactiveAxes!==InteractiveAxes.Y&&(s=this._mvPointers[e].x-this._plotOffset.left,a=this._startPointers[0].x-this._plotOffset.left,r.x=Math.abs((this._mvPointers[e].x-this._mvPointers[i].x)/this._startDistance.x),h.x=s-r.x*a,this._clip.x=(this._plotBox.x-s)/r.x+a,this._selection.w=this._plotBox.width/r.x),Math.abs(this._startDistance.y)>this._threadHold&&this._interactiveAxes!==InteractiveAxes.X&&(s=this._mvPointers[e].y-this._plotOffset.top,a=this._startPointers[0].y-this._plotOffset.top,r.y=Math.abs((this._mvPointers[e].y-this._mvPointers[i].y)/this._startDistance.y),h.y=s-r.y*a,this._clip.y=(this._plotBox.y-s)/r.y+a,this._selection.h=this._plotBox.height/r.y),this._scalingChart(r,h)))}_pointerUp(t){t.preventManipulation&&t.preventManipulation(),this._panning?(this._endPoint&&this._pannedChart(this._endPoint.x-this._startPointers[0].x,this._endPoint.y-this._startPointers[0].y),this._reset()):this._scaling&&(this._scaledChart(t),this._reset())}_onTouchStart(t){if(this._enable)return this._disabledOthersInteraction(!0),1==t.touches.length?(this._scaling=!1,this._panning=!0,this._startFirstPt=this._getPoint(t)):2==t.touches.length&&(this._pinchStartEvents=this._getTouchPair(t),this._startDistance=this._touchDistance(t),this._panning=!1,this._scaling=!0),this._seriesGroup&&this._seriesGroup.setAttribute("clip-path","url(#"+this._chart._plotrectId+")"),this._chart._hideToolTip(),!0}_onTouchMove(t){if(this._enable){var e,i,s,a,n,h={},r={},o=t.touches[0],_=new wjcCore.Point(o.pageX,o.pageY);if(t.preventDefault(),this._panning){if(this._startFirstPt){if(!this._pointInPlotArea(_))return;this._endPoint=new wjcCore.Point(o.pageX,o.pageY),this._panningChart(this._endPoint.x-this._startFirstPt.x,this._endPoint.y-this._startFirstPt.y)}}else this._scaling&&(s=this._touchDistance(t),a=this._getTouchPair(t)[0],n=this._pinchStartEvents[0],Math.abs(this._startDistance.x)>this._threadHold&&this._interactiveAxes!==InteractiveAxes.Y&&(e=a.pageX-this._plotOffset.left,i=n.pageX-this._plotOffset.left,h.x=Math.abs(s.x/this._startDistance.x),r.x=e-h.x*i,this._clip.x=(this._plotBox.x-e)/h.x+i,this._selection.w=this._plotBox.width/h.x),Math.abs(this._startDistance.y)>this._threadHold&&this._interactiveAxes!==InteractiveAxes.X&&(e=a.pageY-this._plotOffset.top,i=n.pageY-this._plotOffset.top,h.y=Math.abs(s.y/this._startDistance.y),r.y=e-h.y*i,this._clip.y=(this._plotBox.y-e)/h.y+i,this._selection.h=this._plotBox.height/h.y),this._scalingChart(h,r));return!0}}_onTouchEnd(t){if(this._enable){var e=this._endPoint;if(this._panning){if(!this._startFirstPt||!e)return void this._reset();this._pannedChart(e.x-this._startFirstPt.x,e.y-this._startFirstPt.y)}else this._scaling&&this._scaledChart(t);return this._reset(),this._disabledOthersInteraction(!1),!0}}_initOverlay(){switch(this._zoomEle.style.visibility="visible",this._interactiveAxes){case InteractiveAxes.X:this._overlayEle.style.left=this._startFirstPt.x-this._zoomEleOffset.left+"px",this._overlayEle.style.top=this._plotOffset.top-this._zoomEleOffset.top+"px";break;case InteractiveAxes.Y:this._overlayEle.style.left=this._plotBox.x+"px",this._overlayEle.style.top=this._startFirstPt.y-this._zoomEleOffset.top+"px";break;case InteractiveAxes.XY:this._overlayEle.style.left=this._startFirstPt.x-this._zoomEleOffset.left+"px",this._overlayEle.style.top=this._startFirstPt.y-this._zoomEleOffset.top+"px"}}_updateOverLay(t){var e=this._startFirstPt.x-t.x,i=this._startFirstPt.y-t.y,s={};switch(this._interactiveAxes){case InteractiveAxes.X:if(Math.abs(e)<this._threadHold)return;s=e<=0?{width:Math.abs(e)+"px",height:this._plotBox.height+"px"}:{left:t.x-this._zoomEleOffset.left+"px",width:e+"px",height:this._plotBox.height+"px"};break;case InteractiveAxes.Y:if(Math.abs(i)<this._threadHold)return;s=i<=0?{height:Math.abs(i)+"px",width:this._plotBox.width+"px"}:{top:t.y-this._zoomEleOffset.top+"px",height:i+"px",width:this._plotBox.width+"px"};break;case InteractiveAxes.XY:Math.abs(e)>=this._threadHold&&(s.width=Math.abs(e)+"px",e>0&&(s.left=t.x-this._zoomEleOffset.left+"px")),Math.abs(i)>=this._threadHold&&(s.height=Math.abs(i)+"px",i>0&&(s.top=t.y-this._zoomEleOffset.top+"px"))}wjcCore.setCss(this._overlayEle,s)}_updatePoint(t){var e=this._plotOffset;t.x<e.left&&(t.x=e.left),t.x>e.left+e.width&&(t.x=e.left+e.width),t.y<e.top&&(t.y=e.top),t.y>e.top+e.height&&(t.y=e.top+e.height)}_pointInPlotArea(t){var e=this._plotOffset;return t.x>=e.left&&t.x<=e.left+e.width&&t.y>=e.top&&t.y<=e.top+e.height}_zoomedChart(t){t&&(this._interactiveAxes!==InteractiveAxes.X&&this._interactiveAxes!==InteractiveAxes.XY||this._zoomedAxis(t,!0),this._interactiveAxes!==InteractiveAxes.Y&&this._interactiveAxes!==InteractiveAxes.XY||this._zoomedAxis(t,!1),this._startFirstPt=null)}_zoomedAxis(t,e){var i,s,a=e?this._chart.axisX:this._chart.axisY,n=e?"x":"y",h=e?"left":"top";t&&Math.abs(this._startFirstPt[n]-t[n])>this._threadHold&&(i=a.convertBack(this._startFirstPt[n]-this._plotOffset[h]+this._plotBox[n]),(s=a.convertBack(t[n]-this._plotOffset[h]+this._plotBox[n]))-i!=0&&this._updateAxisRange(a,Math.min(i,s),Math.max(i,s)))}_panningChart(t,e){var i=this._chart.axisX,s=this._chart.axisY,a=this._getTransFormGroups();t=Math.abs(t)<this._threadHold?0:t,e=Math.abs(e)<this._threadHold?0:e,this._interactiveAxes===InteractiveAxes.X&&(e=0),this._interactiveAxes===InteractiveAxes.Y&&(t=0),t>0&&i.actualMin.valueOf()===this._minX&&(t=0),t<0&&i.actualMax.valueOf()===this._maxX&&(t=0),e>0&&s.actualMax.valueOf()===this._maxY&&(e=0),e<0&&s.actualMin.valueOf()===this._minY&&(e=0);for(var n=0;n<a.length;n++)a[n].setAttribute("transform","translate("+t+","+e+")")}_pannedChart(t,e){this._interactiveAxes!==InteractiveAxes.X&&this._interactiveAxes!==InteractiveAxes.XY||this._updateAxisByDistance(!0,t),this._interactiveAxes!==InteractiveAxes.Y&&this._interactiveAxes!==InteractiveAxes.XY||this._updateAxisByDistance(!1,-e)}_scalingChart(t,e){var i,s,a,n=this._chart.axisX,h=this._chart.axisY,r=void 0!==e.x?e.x:0,o=void 0!==e.y?e.y:0;if(t){i=this._getTransFormGroups(),void 0!==t.x&&t.x<1&&n.actualMin.valueOf()===this._minX&&n.actualMax.valueOf()===this._maxX&&(t.x=1,r=0),void 0!==t.y&&t.y<1&&h.actualMin.valueOf()===this._minY&&h.actualMax.valueOf()===this._maxY&&(t.y=1,o=0),s=void 0!==t.x?t.x:1,a=void 0!==t.y?t.y:1;for(var _=0;_<i.length;_++)i[_].setAttribute("transform","translate("+r+", "+o+") scale("+s+", "+a+")")}}_scaledChart(t){var e,i,s=this._chart,a=s.axisX,n=s.axisY;this._clip&&(this._interactiveAxes!==InteractiveAxes.Y&&void 0!==this._clip.x&&(e=Math.max(this._minX,a.convertBack(this._clip.x)))-(i=Math.min(this._maxX,a.convertBack(this._clip.x+this._selection.w)))!=0&&this._updateAxisRange(a,e,i),this._interactiveAxes!==InteractiveAxes.X&&void 0!==this._clip.y&&(i=Math.min(this._maxY,n.convertBack(this._clip.y)),(e=Math.max(this._minY,n.convertBack(this._clip.y+this._selection.h)))-i!=0&&this._updateAxisRange(n,e,i)))}_updateAxisByDistance(t,e){var i,s=t?this._chart.axisX:this._chart.axisY,a=t?this._minX:this._minY,n=t?this._maxX:this._maxY,h=s.actualMin.valueOf(),r=s.actualMax.valueOf();if(0!==e){if(e>0&&a===h||e<0&&n===r)return this._innerUpdating=!0,void this._chart.invalidate();i=e/(t?this._plotBox.width:this._plotBox.height),this._updateAxisByChg(t,-i,-i)}}_updateAxisByChg(t,e,i){var s,a,n=t?this._chart.axisX:this._chart.axisY,h=t?this._minX:this._minY,r=t?this._maxX:this._maxY,o=n.actualMin.valueOf(),_=(n.actualMax.valueOf(),this._chart._plotRect),l=t?_.left:_.top,c=t?_.width:_.height,d=t?this._minXRange:this._minYRange;isNaN(e)||isNaN(i)||(this._panning?e<0?(s=t?n.convertBack(l+e*c):n.convertBack(l+c-e*c))<h?(s=h,a=t?n.convertBack(n.convert(s)+c):n.convertBack(n.convert(s)-c)):a=t?n.convertBack(l+c+i*c):n.convertBack(l-i*c):(a=t?n.convertBack(l+c+i*c):n.convertBack(l-i*c))>r?(a=r,s=t?n.convertBack(n.convert(a)-c):n.convertBack(n.convert(a)+c)):s=t?n.convertBack(l+e*c):n.convertBack(l+c-e*c):this._scaling&&(s=t?n.convertBack(l+e*c):n.convertBack(l+c-e*c),a=t?n.convertBack(l+c+i*c):n.convertBack(l-i*c),s<h&&(s=h),a>r&&(a=r),a-s<d&&(s=a-d)),this._updateAxisRange(n,s,a))}_initAxisRangeWithPosAndScale(t){var e,i,s,a;t?(i=(e=this._maxX-this._minX)*this._scaleX,a=(s=this._minX+this._posX*(e-i))+i,this._innerUpdating=!0,this._chart.axisX.min=s,this._chart.axisX.max=a,this._lastMinX=s,this._lastMaxX=a):(i=(e=this._maxY-this._minY)*this._scaleY,a=(s=this._minY+this._posY*(e-i))+i,this._innerUpdating=!0,this._chart.axisY.min=s,this._chart.axisY.max=a,this._lastMinY=s,this._lastMaxY=a)}_updateAxisRange(t,e,i){this._chart.beginUpdate(),t.min=e,t.max=i,t===this._chart.axisX?(this._lastMinX=e,this._lastMaxX=i):(this._lastMinY=e,this._lastMaxY=i),this._innerUpdating=!0,this._chart.endUpdate()}_reset(){this._scaling=!1,this._panning=!1,this._startDistance=0,this._startFirstPt=null,this._pinchStartEvents=[],this._startPointers=[],this._mvPointers=[],this._endPoint=null,this._clip={},this._selection={}}_getAxisMin(t){return wjcCore.isDate(t.actualMin)?t.actualMin.valueOf():t.actualMin}_getAxisMax(t){return wjcCore.isDate(t.actualMax)?t.actualMax.valueOf():t.actualMax}_getTransFormGroups(){var t=this._seriesGroup.querySelectorAll("g[clip-path]");return 0===t.length&&(t=this._seriesGroup.querySelectorAll("g")),t}_disabledOthersInteraction(t){var e=this._chart.hostElement;if(null!==e&&void 0!==e)for(var i=e.querySelectorAll(".wj-chart-linemarker-container"),s=0;s<i.length;s++)t?wjcCore.addClass(i[s],ChartGestures._CSS_BLOCK_INTERACTION):wjcCore.removeClass(i[s],ChartGestures._CSS_BLOCK_INTERACTION)}_getPoint(t){return t instanceof MouseEvent?new wjcCore.Point(t.pageX,t.pageY):new wjcCore.Point(t.changedTouches[0].pageX,t.changedTouches[0].pageY)}_getTouchPair(t){var e=[];return wjcCore.isArray(t)?(e[0]=t[0],e[1]=t[1]):"touchend"===t.type?1===t.touches.length?(e[0]=t.touches[0],e[1]=t.changedTouches[0]):0===t.touches.length&&(e[0]=t.changedTouches[0],e[1]=t.changedTouches[1]):(e[0]=t.touches[0],e[1]=t.touches[1]),e}_touchDistance(t){var e=this._getTouchPair(t),i=0,s=0;return e[0]&&void 0!==e[0].pageX&&e[1]&&void 0!==e[1].pageX&&(i=e[0].pageX-e[1].pageX),e[0]&&void 0!==e[0].pageY&&e[1]&&void 0!==e[1].pageY&&(s=e[0].pageY-e[1].pageY),{x:i,y:s}}};ChartGestures._CSS_ZOOM="wj-zoom",ChartGestures._CSS_ZOOM_OVERLAY="wj-zoom-overlay",ChartGestures._CSS_PANABLE="wj-panable",ChartGestures._CSS_TOUCH_DISABLED="wj-flexchart-touch-disabled",ChartGestures._CSS_BLOCK_INTERACTION="wj-block-other-interaction";