/*
    *
    * 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.annotation");var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.chart=window.wijmo.chart||{},window.wijmo.chart.annotation=wjcSelf;var AnnotationAttachment;!function(t){t[t.DataIndex=0]="DataIndex",t[t.DataCoordinate=1]="DataCoordinate",t[t.Relative=2]="Relative",t[t.Absolute=3]="Absolute"}(AnnotationAttachment=exports.AnnotationAttachment||(exports.AnnotationAttachment={}));var AnnotationPosition;!function(t){t[t.Center=0]="Center",t[t.Top=1]="Top",t[t.Bottom=2]="Bottom",t[t.Left=4]="Left",t[t.Right=8]="Right"}(AnnotationPosition=exports.AnnotationPosition||(exports.AnnotationPosition={}));class AnnotationBase{constructor(t){this._resetDefaultValue(),t&&this._copy(this,t)}get attachment(){return this._attachment}set attachment(t){(t=wjcCore.asEnum(t,AnnotationAttachment))!=this._attachment&&(this._attachment=t,this._repaint())}get point(){return this._point}set point(t){null!=t.x&&null!=t.y&&(t.x===this._point.x&&t.y===this._point.y||(this._point=t,this._repaint()))}get seriesIndex(){return this._seriesIndex}set seriesIndex(t){(t=wjcCore.asNumber(t,!1,!0))!=this._seriesIndex&&(this._seriesIndex=t,this._repaint())}get pointIndex(){return this._pointIndex}set pointIndex(t){t!==this._pointIndex&&(this._pointIndex=wjcCore.asNumber(t,!1,!0),this._repaint())}get position(){return this._position}set position(t){t!=this._position&&(this._position=t,this._repaint())}get offset(){return this._offset}set offset(t){null!=t.x&&null!=t.y&&(t.x===this._offset.x&&t.y===this._offset.y||(this._offset=t,this._repaint()))}get style(){return null==this._style&&(this._style={}),this._style}set style(t){t!=this._style&&(this._style=t,this._repaint())}get isVisible(){return this._isVisible}set isVisible(t){(t=wjcCore.asBoolean(t,!1))!=this._isVisible&&(this._isVisible=t,this._toggleVisibility(t))}get tooltip(){return this._tooltip}set tooltip(t){this._tooltip=t}get name(){return this._name}set name(t){this._name=t}render(t){var e,n=this;n._element=t.startGroup(n._getCSSClass()),t.fill="#88bde6",t.strokeWidth=1,t.stroke="#000000",n._render(t),t.endGroup(),n._element[AnnotationBase._DATA_KEY]=this,n._isVisible?n._attachment===AnnotationAttachment.DataIndex&&(!(e=n._layer._chart.series[n._seriesIndex])||e.visibility!==wjcChart.SeriesVisibility.Legend&&e.visibility!==wjcChart.SeriesVisibility.Hidden||n._toggleVisibility(!1)):n._toggleVisibility(!1)}destroy(){}_copy(t,e){for(var n in e)n in t&&this._processOptions(n,t,e)}_processOptions(t,e,n){e[t]=n[t]}_resetDefaultValue(){var t=this;t._attachment=AnnotationAttachment.Absolute,t._point=new wjcChart.DataPoint(0,0),t._seriesIndex=0,t._pointIndex=0,t._position=AnnotationPosition.Center,t._offset=new wjcCore.Point(0,0),t._isVisible=!0,t._tooltip=""}_toggleVisibility(t){var e=t?"visible":"hidden";this._element&&this._element.setAttribute("visibility",e)}_getCSSClass(){return AnnotationBase._CSS_ANNOTATION}_render(t){this._element=null}_repaint(){this._layer&&this._layer._renderAnnotation(this)}_convertPoint(t){var e,n,i,s,r,o,a,_=this,h=_._attachment,l=new wjcCore.Point;switch(_._layer&&_._layer._chart&&(n=(e=_._layer._chart)._plotRect),h){case AnnotationAttachment.DataIndex:if(!e.series||e.series.length<=_.seriesIndex)break;if(r=e.series[_.seriesIndex],!(o=r._getItem(_.pointIndex)))break;i=r.axisX||e.axisX,s=r.axisY||e.axisY,"string"==typeof(a=o[r.bindingX]||o.x)&&(a=_.pointIndex),l.x=_._convertDataToLen(n.width,i,a),l.y=_._convertDataToLen(n.height,s,o[r._getBinding(0)]||s.actualMin+.25,!0);break;case AnnotationAttachment.DataCoordinate:i=e.axisX,s=e.axisY,l.x=_._convertDataToLen(n.width,i,t.x),l.y=_._convertDataToLen(n.height,s,t.y,!0);break;case AnnotationAttachment.Relative:l.x=n.width*t.x,l.y=n.height*t.y;break;case AnnotationAttachment.Absolute:default:l.x=t.x,l.y=t.y}return l}_convertDataToLen(t,e,n,i=!1){var s=null==e.min?e.actualMin:e.min,r=null==e.max?e.actualMax:e.max;if(e._getLogBase()){if(n<=0)return NaN;let e=Math.log(r/s);return i?t*(1-Math.log(n/s)/e):t*Math.log(n/s)/e}return i?t*(1-(n-s)/(r-s)):t*(n-s)/(r-s)}_renderCenteredText(t,e,n,i,s,r){var o,a;this._isValidPoint(n)&&(s?e.drawStringRotated(t,n,n,s,i,r):e.drawString(t,n,i,r),(o=this._element.querySelector("text"))&&(a=o.getBBox(),o.setAttribute("x",(n.x-a.width/2).toFixed(1)),o.setAttribute("y",(n.y+a.height/6).toFixed(1))))}_adjustOffset(t,e){t.x=t.x+e.x,t.y=t.y+e.y}_getOffset(t){var e=this._getPositionOffset(t);return new wjcCore.Point(this._offset.x+e.x,this._offset.y+e.y)}_getPositionOffset(t){var e=new wjcCore.Point(0,0),n=this.position,i=this._getSize(t);return(n&AnnotationPosition.Top)===AnnotationPosition.Top?e.y-=i.height/2:(n&AnnotationPosition.Bottom)===AnnotationPosition.Bottom&&(e.y+=i.height/2),(n&AnnotationPosition.Left)===AnnotationPosition.Left?e.x-=i.width/2:(n&AnnotationPosition.Right)===AnnotationPosition.Right&&(e.x+=i.width/2),e}_getSize(t){return new wjcCore.Size}_isValidPoint(t){return isFinite(t.x)&&isFinite(t.y)}_measureString(t,e,n){var i,s=t;return s._textGroup&&null==s._textGroup.parentNode?(s._svg.appendChild(s._textGroup),i=s.measureString(e,n,null,this.style),s.endRender()):i=s.measureString(e,n,null,this.style),i}}AnnotationBase._DATA_KEY="wj-chart-annotation",AnnotationBase._CSS_ANNOTATION="wjchart-annotation",AnnotationBase._CSS_ANNO_TEXT="anno-text",AnnotationBase._CSS_ANNO_SHAPE="anno-shape",exports.AnnotationBase=AnnotationBase;class Text extends AnnotationBase{constructor(t){super(t)}_resetDefaultValue(){super._resetDefaultValue(),this._text="",this.position=AnnotationPosition.Top}_getCSSClass(){return super._getCSSClass()+" "+Text._CSS_TEXT}get text(){return this._text}set text(t){var e=this;t!==e._text&&(e._text=t,e._repaint())}_render(t){var e,n=this,i=n._convertPoint(n.point);e=n._getOffset(t),n._adjustOffset(i,e),n._renderCenteredText(n._text,t,i,AnnotationBase._CSS_ANNO_TEXT,null,n.style)}_getSize(t){return t?this._measureString(t,this._text,AnnotationBase._CSS_ANNO_TEXT):new wjcCore.Size}}Text._CSS_TEXT="wjchart-anno-text",exports.Text=Text;class Shape extends AnnotationBase{constructor(t){super(t)}_resetDefaultValue(){super._resetDefaultValue(),this._content=""}_getCSSClass(){return super._getCSSClass()+" "+Shape._CSS_SHAPE}get content(){return this._content}set content(t){var e=this;t!==e._content&&(e._content=t,e._repaint())}_render(t){var e=this;e._shapeContainer=t.startGroup(),t.stroke="#000",e._renderShape(t),t.stroke=null,t.endGroup(),e._content&&e._renderText(t)}_getContentCenter(){return this.point}_renderShape(t){}_renderText(t){var e,n,i=this;e=i._convertPoint(i._getContentCenter()),i._isValidPoint(e)&&(n=i._getOffset(),i._adjustOffset(e,n),i._renderCenteredText(i._content,t,e,AnnotationBase._CSS_ANNO_TEXT))}}Shape._CSS_SHAPE="wjchart-anno-shape",exports.Shape=Shape;class Ellipse extends Shape{constructor(t){super(t)}get width(){return this._width}set width(t){t!==this._width&&(this._width=wjcCore.asNumber(t,!1,!0),this._repaint())}get height(){return this._height}set height(t){t!==this._height&&(this._height=wjcCore.asNumber(t,!1,!0),this._repaint())}_resetDefaultValue(){super._resetDefaultValue(),this._width=100,this._height=80}_getCSSClass(){return super._getCSSClass()+" "+Ellipse._CSS_ELLIPSE}_renderShape(t){super._renderShape(t);var e=this,n=e._convertPoint(e.point),i=e._width,s=e._height,r=e._getOffset();e._adjustOffset(n,r),e._isValidPoint(n)&&t.drawEllipse(n.x,n.y,i/2,s/2,AnnotationBase._CSS_ANNO_SHAPE,e.style)}_getSize(){return new wjcCore.Size(this.width,this.height)}}Ellipse._CSS_ELLIPSE="wjchart-anno-ellipse",exports.Ellipse=Ellipse;class Rectangle extends Shape{constructor(t){super(t)}get width(){return this._width}set width(t){t!==this._width&&(this._width=wjcCore.asNumber(t,!1,!0),this._repaint())}get height(){return this._height}set height(t){t!==this._height&&(this._height=wjcCore.asNumber(t,!1,!0),this._repaint())}_resetDefaultValue(){super._resetDefaultValue(),this._width=100,this._height=80}_getCSSClass(){return super._getCSSClass()+" "+Rectangle._CSS_RECTANGLE}_renderShape(t){super._renderShape(t);var e=this,n=e._convertPoint(e.point),i=e._width,s=e._height,r=e._getOffset();e._adjustOffset(n,r),e._isValidPoint(n)&&t.drawRect(n.x-i/2,n.y-s/2,e._width,e._height,AnnotationBase._CSS_ANNO_SHAPE,e.style)}_getSize(){return new wjcCore.Size(this.width,this.height)}}Rectangle._CSS_RECTANGLE="wjchart-anno-rectangle",exports.Rectangle=Rectangle;class Line extends Shape{constructor(t){super(t)}get start(){return this._start}set start(t){var e=this;null!=t.x&&null!=t.y&&(t.x===e._start.x&&t.y===e._start.y||(e._start=t,e._repaint()))}get end(){return this._end}set end(t){var e=this;null!=t.x&&null!=t.y&&(t.x===e._end.x&&t.y===e._end.y||(e._end=t,e._repaint()))}_resetDefaultValue(){super._resetDefaultValue(),this._start=new wjcChart.DataPoint(0,0),this._end=new wjcChart.DataPoint(0,0),this.position=AnnotationPosition.Top}_getCSSClass(){return super._getCSSClass()+" "+Line._CSS_LINE}_getContentCenter(){var t=this.start,e=this.end;return wjcCore.isDate(t.x)&&wjcCore.isDate(e.x)?new wjcChart.DataPoint(new Date(t.x.getTime()+(e.x-t.x)/2),(t.y+e.y)/2):new wjcChart.DataPoint((t.x+e.x)/2,(t.y+e.y)/2)}_renderShape(t){super._renderShape(t);var e,n=this,i=n._convertPoint(n._start),s=n._convertPoint(n._end);n._cS=i,n._cE=s,e=n._getOffset(),n._adjustOffset(i,e),n._adjustOffset(s,e),n._isValidPoint(i)&&n._isValidPoint(s)&&t.drawLine(i.x,i.y,s.x,s.y,AnnotationBase._CSS_ANNO_SHAPE,n.style)}_getSize(){var t=this._cS,e=this._cE;return new wjcCore.Size(Math.abs(t.x-e.x),Math.abs(t.y-e.y))}_renderText(t){var e,n,i,s=this,r=s._cS,o=s._cE;e=s._convertPoint(s._getContentCenter()),n=s._getOffset(),s._adjustOffset(e,n),s._isValidPoint(e)&&(i=(i=180*Math.atan2(o.y-r.y,o.x-r.x)/Math.PI)<-90?i+180:i>90?i-180:i,s._renderCenteredText(s.content,t,e,AnnotationBase._CSS_ANNO_TEXT,i))}_renderCenteredText(t,e,n,i,s,r){if(null!=s){var o,a,_,h;_=this._measureString(e,t,i).height/2,h=s*Math.PI/180,o=_*Math.sin(h),a=_*Math.cos(h),n.x=n.x+o,n.y=n.y-a}super._renderCenteredText(t,e,n,i,s,r)}}Line._CSS_LINE="wjchart-anno-line",exports.Line=Line;class Polygon extends Shape{constructor(t){super(t)}_processOptions(t,e,n){if("points"===t){var i=n[t];wjcCore.isArray(i)&&i.forEach(t=>{this.points.push(t)})}else super._processOptions(t,e,n)}get points(){return this._points}_resetDefaultValue(){var t=this;super._resetDefaultValue(),t._points=new wjcCore.ObservableArray,t._points.collectionChanged.addHandler(function(){t._element&&t._repaint()})}_getCSSClass(){return super._getCSSClass()+" "+Polygon._CSS_POLYGON}_getContentCenter(){var t,e=this.points,n=e.length,i=0,s=0;for(t=0;t<n;t++)i+=e[t].x,s+=e[t].y;return new wjcChart.DataPoint(i/n,s/n)}_renderShape(t){super._renderShape(t);var e,n,i=this,s=[],r=[],o=i._points,a=o.length,_=i._getOffset();for(e=0;e<a;e++){if(n=i._convertPoint(o[e]),!i._isValidPoint(n))return;i._adjustOffset(n,_),s.push(n.x),r.push(n.y)}t.drawPolygon(s,r,AnnotationBase._CSS_ANNO_SHAPE,i.style)}_getSize(){var t,e,n,i,s,r,o,a=this,_=a._points.length;for(o=[].map.call(a._points,function(t){return a._convertPoint(t)}),s=0;s<_;s++)r=o[s],0!==s?(r.x<t?t=r.x:r.x>e&&(e=r.x),r.y<n?n=r.y:r.y>i&&(i=r.y)):(t=e=r.x,n=i=r.y);return new wjcCore.Size(e-t,i-n)}}Polygon._CSS_POLYGON="wjchart-anno-polygon",exports.Polygon=Polygon;class Circle extends Shape{constructor(t){super(t)}get radius(){return this._radius}set radius(t){t!==this._radius&&(this._radius=wjcCore.asNumber(t,!1,!0),this._repaint())}_resetDefaultValue(){super._resetDefaultValue(),this._radius=100}_getCSSClass(){return super._getCSSClass()+" "+Circle._CSS_CIRCLE}_renderShape(t){super._renderShape(t);var e=this,n=e._convertPoint(e.point),i=e._getOffset();e._adjustOffset(n,i),e._isValidPoint(n)&&t.drawPieSegment(n.x,n.y,e.radius,0,360,AnnotationBase._CSS_ANNO_SHAPE,e.style)}_getSize(){var t=2*this.radius;return new wjcCore.Size(t,t)}}Circle._CSS_CIRCLE="wjchart-anno-circle",exports.Circle=Circle;class Square extends Shape{constructor(t){super(t)}get length(){return this._length}set length(t){t!==this._length&&(this._length=wjcCore.asNumber(t,!1,!0),this._repaint())}_resetDefaultValue(){super._resetDefaultValue(),this._length=100}_getCSSClass(){return super._getCSSClass()+" "+Square._CSS_SQUARE}_renderShape(t){super._renderShape(t);var e=this,n=e._convertPoint(e.point),i=e.length,s=e._getOffset();e._adjustOffset(n,s),e._isValidPoint(n)&&t.drawRect(n.x-i/2,n.y-i/2,i,i,AnnotationBase._CSS_ANNO_SHAPE,e.style)}_getSize(){return new wjcCore.Size(this.length,this.length)}}Square._CSS_SQUARE="wjchart-anno-square",exports.Square=Square;class Image extends Shape{constructor(t){super(t)}get width(){return this._width}set width(t){t!==this._width&&(this._width=wjcCore.asNumber(t,!1,!0),this._repaint())}get height(){return this._height}set height(t){t!==this._height&&(this._height=wjcCore.asNumber(t,!1,!0),this._repaint())}get href(){return this._href}set href(t){t!==this._href&&(this._href=t,this._repaint())}_resetDefaultValue(){super._resetDefaultValue(),this._width=100,this._height=100,this._href=""}_getCSSClass(){return super._getCSSClass()+" "+Image._CSS_IMAGE}_renderShape(t){super._renderShape(t);var e=this,n=e._convertPoint(e.point),i=e._href,s=e.width,r=e.height,o=e._getOffset();i.length>0&&e._isValidPoint(n)&&(e._adjustOffset(n,o),t.drawImage(i,n.x-s/2,n.y-r/2,s,r)),e._applyStyle(e._element,e.style)}_getSize(){return new wjcCore.Size(this.width,this.height)}_applyStyle(t,e){if(e)for(var n in e)t.setAttribute(this._deCase(n),e[n])}_deCase(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})}}Image._CSS_IMAGE="wjchart-anno-image",exports.Image=Image;class AnnotationLayer{constructor(t,e){var n=this;n._init(t),n._renderGroup(),n._bindTooltip(),e&&wjcCore.isArray(e)&&e.forEach(t=>{var e,i=t.type||"Circle";wjcSelf[i]&&(e=new wjcSelf[i](t),n._items.push(e))})}_init(t){var e=this;e._items=new wjcCore.ObservableArray,e._items.collectionChanged.addHandler(e._itemsChanged,e),e._chart=t,e._forceTTShowing=!1,e._annoTTShowing=!1,e._engine=t._currentRenderEngine,t.rendered.addHandler(e._renderAnnotations,e),t.lostFocus.addHandler(e._lostFocus,e)}_lostFocus(t){this._toggleTooltip(this._tooltip,t,this._chart.hostElement)}get items(){return this._items}getItem(t){var e=this.getItems(t);return e.length>0?e[0]:null}getItems(t){var e=[];if(0===this._items.length||!t||""===t)return e;for(var n=0;n<this._items.length;n++)t===this._items[n].name&&e.push(this._items[n]);return e}_bindTooltip(){var t,e=this,n=e._chart.hostElement,i=e._tooltip;i||(i=e._tooltip=new wjcChart.ChartTooltip,t=wjcCore.Tooltip.prototype.hide,wjcCore.Tooltip.prototype.hide=function(){e._forceTTShowing||t.call(i)}),n&&(n.addEventListener("click",function(t){e._toggleTooltip(i,t,n)}),n.addEventListener("mousemove",function(t){e._showTooltip()&&e._toggleTooltip(i,t,n)}))}_showTooltip(){return!this._chart.isTouching}_toggleTooltip(t,e,n){var i=this,s=i._getAnnotation(e.target,n);if(s&&s.tooltip)i._forceTTShowing=!0,i._annoTTShowing=!0,t.show(i._layerEle,s.tooltip,new wjcCore.Rect(e.clientX,e.clientY,5,5));else{if(!i._annoTTShowing)return;i._annoTTShowing=!1,i._forceTTShowing=!1,t.hide()}}_getAnnotation(t,e){var n=this._getAnnotationElement(t,e);return null==n?null:n[AnnotationBase._DATA_KEY]}_getAnnotationElement(t,e){if(!t||!e)return null;var n=t.parentNode;return wjcCore.hasClass(t,AnnotationBase._CSS_ANNOTATION)?t:null==n||n===document.body||n===document||n===e?null:this._getAnnotationElement(n,e)}_itemsChanged(t,e){var n=e.action,i=e.item;switch(n){case wjcCore.NotifyCollectionChangedAction.Add:case wjcCore.NotifyCollectionChangedAction.Change:i._layer=this,this._renderAnnotation(i);break;case wjcCore.NotifyCollectionChangedAction.Remove:this._destroyAnnotation(i)}}_renderAnnotations(){var t,e=this.items,n=e.length;for(this._renderGroup(),t=0;t<n;t++)this._renderAnnotation(e[t])}_renderGroup(){var t=this,e=t._engine,n=t._chart._plotRect;n&&(t._layerEle&&null!=t._layerEle.parentNode||(t._plotrectId="plotRect"+(1e6*Math.random()).toFixed(),e.addClipRect({left:0,top:0,width:n.width,height:n.height},t._plotrectId),t._layerEle=e.startGroup(AnnotationLayer._CSS_Layer,t._plotrectId),t._layerEle.setAttribute("transform","translate("+n.left+", "+n.top+")"),e.endGroup()))}_renderAnnotation(t){this._layerEle&&null!=this._layerEle.parentNode&&(t._element&&t._element.parentNode==this._layerEle&&this._layerEle.removeChild(t._element),t.render(this._engine),this._layerEle.appendChild(t._element))}_destroyAnnotations(){var t,e=this.items,n=e.length;for(t=0;t<n;t++)this._destroyAnnotation(e[t])}_destroyAnnotation(t){this._layerEle&&this._layerEle.removeChild(t._element),t.destroy()}}AnnotationLayer._CSS_Layer="wj-chart-annotationlayer",exports.AnnotationLayer=AnnotationLayer;