@devexperts/dxcharts-lite 2.4.2 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,9 +52,9 @@ export class YAxisScaleHandler extends ChartBaseElement {
52
52
  const delta = (newYHeight - this.lastYHeight) / 2;
53
53
  const newYStart = this.lastYStart - delta;
54
54
  const newYEnd = this.lastYEnd + delta;
55
- this.autoScaleCallback(false);
56
55
  if (this.lastYStart !== newYStart || this.lastYEnd !== newYEnd) {
57
56
  this.scale.setYScale(newYStart, newYEnd);
57
+ this.autoScaleCallback(false);
58
58
  this.bus.fireDraw();
59
59
  }
60
60
  };
@@ -287,7 +287,7 @@ export class ViewportModel extends ChartBaseElement {
287
287
  * @returns {boolean} - Returns true if the viewport is valid, false otherwise.
288
288
  */
289
289
  isViewportValid() {
290
- return this.xStart !== this.xEnd && this.yStart !== this.yEnd && isFinite(this.yStart) && isFinite(this.yEnd);
290
+ return this.xStart !== this.xEnd && this.yStart !== this.yEnd && isFinite(this.yStart) && isFinite(this.yEnd) && this.zoomX > 0 && this.zoomY > 0;
291
291
  }
292
292
  }
293
293
  export const compareStates = (a, b) => !keys(a).some(k => a[k] !== b[k]);
@@ -20,4 +20,4 @@ ${s?` <p style="position: absolute; visibility: hidden;">If you have any sugge
20
20
  `:""} </div>
21
21
  </div>
22
22
  </div>
23
- `;function bl(s){const t=document.createElement("template");return t.innerHTML=vl(s.devexpertsPromoLink),t}function Cl(s){const t={},e=Array.from(s.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(n=>{var i;t[(i=n.getAttribute("data-element"))!=null?i:""]=n}),ml(t))return t;throw new Error("Some chart elements are missing")}function wl(s){if(s.length>1){const t=s.reduce((i,r,o)=>{if(o!==s.length-1){const a=s[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,n;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,n=r)}if(n)return n}}const be=(s,t,e,n=1e3)=>{var i,r,o,a;const l=(r=(i=fe(e))==null?void 0:i.timestamp)!=null?r:0,c=(a=(o=wt(e))==null?void 0:o.timestamp)!=null?a:0;return s>c?t?{index:e.length-1+Math.ceil((s-c)/n),exact:!0}:{index:e.length-1,exact:!0}:s<l?t?{index:it((s-l)/n),exact:!0}:{index:-1,exact:!0}:zt(e,s,h=>h.timestamp)},Ls=1;function Xe(s,t){return t===s?"none":t>s?"up":"down"}function yl(s,t){return t>s?"up":"down"}function Sl(s,t,e=!1){const{expansion:n,impVolatility:i,vwap:r,volume:o,timestamp:a}=s;let l=s.hi,c=s.lo,h=s.open;const d=s.close;e&&(l=d,c=d,h=d);let u=s.idx;return t!==void 0&&(u=t),{hi:l,lo:c,open:h,close:d,timestamp:a,volume:o,expansion:n,idx:u,impVolatility:i,vwap:r}}const pi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2},mi={paintConfig:[pi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var xl=Object.defineProperty,vi=Object.getOwnPropertySymbols,_l=Object.prototype.hasOwnProperty,Pl=Object.prototype.propertyIsEnumerable,bi=(s,t,e)=>t in s?xl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Tl=(s,t)=>{for(var e in t||(t={}))_l.call(t,e)&&bi(s,e,t[e]);if(vi)for(var e of vi(t))Pl.call(t,e)&&bi(s,e,t[e]);return s};class Ml{constructor(t,e,n,i){this.series=t,this.config=e,this.yAxisBoundsProvider=n,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,n=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[Tl({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:n}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:pi).color;return{textColor:qt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}let Dt=window.devicePixelRatio,ze=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Ds=()=>{ze.removeEventListener("change",Ds),Dt=window.devicePixelRatio,ze=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),ze.addEventListener("change",Ds)};ze.addEventListener("change",Ds);const Al=()=>Dt,El=s=>Kt(Dt*s)/Dt,V=s=>it(Dt*s)/Dt,Ci=s=>pa(Dt*s)/Dt,Ce=s=>JSON.parse(JSON.stringify(s));function Is(s){return Object.entries(s)}const wi=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function yi(s){return Object.keys(s)}function Si(s,t){if(Object.is(s,t))return!0;if(typeof s!="object"||s===null||typeof t!="object"||t===null)return!1;const e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!Si(s[e[i]],t[e[i]]))return!1;return!0}function xi(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new B}:t,n=s.resetOnError,i=n===void 0?!0:n,r=s.resetOnComplete,o=r===void 0?!0:r,a=s.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,g=0,C=!1,S=!1,_=function(){d==null||d.unsubscribe(),d=void 0},M=function(){_(),h=u=void 0,C=S=!1},I=function(){var F=h;M(),F==null||F.unsubscribe()};return N(function(F,j){g++,!S&&!C&&_();var R=u=u!=null?u:e();j.add(function(){g--,g===0&&!S&&!C&&(d=Bs(I,l))}),R.subscribe(j),!h&&g>0&&(h=new de({next:function(H){return R.next(H)},error:function(H){S=!0,_(),d=Bs(M,i,H),R.error(H)},complete:function(){C=!0,_(),d=Bs(M,o),R.complete()}}),Rt(F).subscribe(h))})(c)}}function Bs(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];if(t===!0){s();return}if(t!==!1){var i=new de({next:function(){i.unsubscribe(),s()}});return Rt(t.apply(void 0,L([],p(e)))).subscribe(i)}}const We=(s,t)=>s/t,dt=(s,t)=>s/t,Yt=(s,t)=>s*t,_i=(s,t)=>(s-t)*100/t,Pi=(s,t)=>s*t/100+t,Ti=s=>Math.log2(s),Os=s=>Math.pow(2,s);class Ll extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new B,this.xChanged=this.changed.pipe(ct(()=>({start:this.xStart,end:this.xEnd})),Et((t,e)=>t.start===e.start&&t.end===e.end),xi()),this.yChanged=this.changed.pipe(ct(()=>({start:this.yStart,end:this.yEnd})),Et((t,e)=>t.start===e.start&&t.end===e.end),xi())}doActivate(){super.doActivate()}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+dt(t-this.xStart,this.zoomX)}xPixels(t){return dt(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+dt(t-this.yStart,this.zoomY):e.y+e.height-dt(t-this.yStart,this.zoomY)}yPixels(t){return dt(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Yt(e+dt(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?Yt(n+dt(this.yStart,this.zoomY),this.zoomY):Yt(e.height-n+dt(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return We(e-t,this.getBounds().width)}calculateZoomY(t,e){return We(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,n=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),n&&this.fireChanged()}setYScale(t,e,n=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),n&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(){return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)}}const Dl=(s,t)=>!yi(s).some(e=>s[e]!==t[e]);class Il{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let n;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(zt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(zt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class Mi{constructor(t,e,n,i){this.dataSeries=t,this.scale=e,this.getAxisType=n,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new Il(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return _i(t,n);case"logarithmic":return Ti(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return Pi(t,this.getBaseline());case"logarithmic":return Os(t);case"regular":return t}}}var Bl=Object.defineProperty,Ol=Object.defineProperties,Rl=Object.getOwnPropertyDescriptors,Ai=Object.getOwnPropertySymbols,Fl=Object.prototype.hasOwnProperty,Hl=Object.prototype.propertyIsEnumerable,Ei=(s,t,e)=>t in s?Bl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,kl=(s,t)=>{for(var e in t||(t={}))Fl.call(t,e)&&Ei(s,e,t[e]);if(Ai)for(var e of Ai(t))Hl.call(t,e)&&Ei(s,e,t[e]);return s},Yl=(s,t)=>Ol(s,Rl(t));class we{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return V(t.toY(this.close))}x(t){return V(t.toX(this.centerUnit))}clone(){return new we(this.centerUnit,this.close)}}class Li extends X{constructor(t,e,n,i=Ce(mi)){var r;super(),this.extentComponent=t,this.id=e,this.htId=n,this.name="",this.hovered=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=o=>{var a;return(a=this.config.paintConfig[o])!=null?a:this.config.paintConfig[0]},this.getBaseline=(o=this.dataIdxStart)=>{var a,l;return(l=(a=this.visualPoints[o])==null?void 0:a.close)!=null?l:1},this.getTextForPoint=o=>`${o.close}`,this.getLastVisualSeriesPoint=()=>{const o=this.visualPoints,a=zt(o,this.scale.xEnd,l=>l.centerUnit).index;return o[a]},this.getLastDataSeriesPoint=()=>{const o=this.visualPoints;return wt(o)},this.config=Lt(i,mi),this.scale=t.scale,this.view=new Mi(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Ml(this,this.config,t.getYAxisBounds,(r=t.yAxis)==null?void 0:r.state),this.highLowProvider=Nl(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=zn(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=zn(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new Mi(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state,this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,n)=>({centerUnit:n,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const n=zt(this.visualPoints,t,r=>r.centerUnit).index,i=zt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return Di(t)}getSeriesInViewport(t,e){let n=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);n=r.dataIdxStart,i=r.dataIdxEnd}return Ia(this.visualPoints2D,n,i)}}const jl=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.close>t.high&&(t.high=n.close,t.highIdx=e),n.close<t.low&&(t.low=n.close,t.lowIdx=e)}return t},Nl=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=jl(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return Yl(kl({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),Di=s=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(s);return ht.makeDecimal(s,i)};class Ue extends we{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.width=e,this.open=n,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return V(Math.abs(t.toY(this.open)-t.toY(this.close)))}candleHeight(t){return V(Math.abs(t.toY(this.high)-t.toY(this.low)))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=V(t.toY(this.high)),n=V(t.toY(this.low)),i=V(t.toY(this.open)),r=V(t.toY(this.close)),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return V(Math.max(t.toY(this.high),t.toY(this.low)))}yLineStart(t){return V(Math.min(t.toY(this.high),t.toY(this.low)))}yBodyStart(t){return V(Math.min(t.toY(this.open),t.toY(this.close)))}yBodyEnd(t){return V(Math.max(t.toY(this.open),t.toY(this.close)))}xCenter(t){return this.x(t)}xStart(t){return El(t.toX(this.startUnit))}}const oe=60,Ii=(s,t,e,n,i=oe)=>{const r=ye(s,n,i);r.volume=e;let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Ue(o,e,r.open,r.close,r.lo,r.hi,Xe(r.open,r.close),r)},Xl=(s,t,e,n,i=oe)=>{const r=zl(s,n,i);let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new we(o,r.close)},ye=(s,t,e=oe)=>({hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:Bi(s,t,e),volume:NaN,expansion:!0,idx:t}),zl=(s,t,e=oe)=>({close:NaN,timestamp:Bi(s,t,e)});function Bi(s,t,e=oe){var n,i;const r=Kt(t);if(s.length===0)return 0;const o=wt(s);if(r>=s.length&&o)return Oi(o,s.length-1,r,e);const a=fe(s);return r<0&&a?Oi(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const Oi=(s,t,e,n=oe)=>s.timestamp+(e-(t!=null?t:0))*n;class Wl{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new B,this.dataSetSubject=new B,this.dataRemovedSubject=new B,this.dataPrependSubject=new B,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e=!0,n=this.mainDataPoints){const i=be(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=wl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Ii(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):Xl(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var Ul=Object.defineProperty,Ri=Object.getOwnPropertySymbols,Vl=Object.prototype.hasOwnProperty,Gl=Object.prototype.propertyIsEnumerable,Fi=(s,t,e)=>t in s?Ul(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zl=(s,t)=>{for(var e in t||(t={}))Vl.call(t,e)&&Fi(s,e,t[e]);if(Ri)for(var e of Ri(t))Gl.call(t,e)&&Fi(s,e,t[e]);return s};class $l{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.backgroundDrawPredicate=n,this.prevState={}}draw(){if(this.backgroundDrawPredicate()||!Si(this.config.colors.chartAreaTheme,this.prevState)){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=Zl({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const Kl=(s,t,e,n,i,r,o)=>{const a=Al(),l=[e*a,n*a,i*a,r*a];let c=s.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=it(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?it(u*o):it(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Hi=(s,{x:t,width:e,activeCandle:n})=>new Ue(t,e,s.open,s.close,s.hi,s.lo,Xe(s.open,s.close),s,!0,Rs(s,n)),ql=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ue(t,e,s.open,s.close,s.hi,s.lo,yl((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},ki=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ue(t,e,s.open,s.close,s.hi,s.lo,Xe((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},Jl=ki,Rs=(s,t)=>{const e=t&&t.idx===s.idx;return e!=null?e:!1},Yi=()=>Ls,Qt=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>it(Math.log10((n^n>>31)-(n>>31)))+1;let e=t(s);return e===1&&s<1&&(e=t(s*1e9)-9),e}static getPriceIncrement(s,t=[]){if(!this.validatePriceIncrementsOrPrecisions(t))return this.DEFAULT_INCREMENT;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;const n=1e-6;for(;e<t.length&&s>t[e]+Math.min(t[e-1],t[e+1])*n;)e+=2;return e>=t.length||s<t[e]-Math.min(t[e-1],t[e+1])*n?t[e-1]:Math.min(t[e-1],t[e+1])}static getPricePrecision(s,t){if(!this.validatePriceIncrementsOrPrecisions(t))return 0;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;for(;e<t.length&&s>t[e];)e+=2;return Math.round(t[e-1])}static roundPriceToIncrement(s,t,e){const n=Qt.getPriceIncrement(e||s,t);return ht.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=Qt.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*Qt.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<Qt.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*Qt.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return Qt.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let It=Qt;It.DEFAULT_INCREMENT=.01,It.DEFAULT_PRECISION=2,It.RELATIVE_EPS=1e-8,It.MAXIMUM_PRECISION=10;const Ql=(s,t)=>{var e;const n=(e=wt(t))!=null?e:1;return Math.pow(10,-n)};var tc=Object.defineProperty,ec=Object.defineProperties,sc=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,nc=Object.prototype.hasOwnProperty,ic=Object.prototype.propertyIsEnumerable,Ni=(s,t,e)=>t in s?tc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,rc=(s,t)=>{for(var e in t||(t={}))nc.call(t,e)&&Ni(s,e,t[e]);if(ji)for(var e of ji(t))ic.call(t,e)&&Ni(s,e,t[e]);return s},oc=(s,t)=>ec(s,sc(t));const ac=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:s.scale.xStart,n=t?t.xEnd:s.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=s.calculateDataViewportIndexes(e,n),o=s.visualPoints.slice(i,r+1),a=Xi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return oc(rc({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Xi=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.high>t.high&&(t.high=n.high,t.highIdx=e),n.low<t.low&&(t.low=n.low,t.lowIdx=e)}return t},lc=30,zi=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:lc,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY});t.currentAnimation=n};class cc{constructor(t,e){this.delegate=t,this.highLowPostProcessor={},this.highLowProviders=e!=null?e:{}}setHighLowProvider(t,e){this.highLowProviders[t]=e}deleteHighLowProvider(t){delete this.highLowProviders[t]}setHighLowPostProcessor(t,e){this.highLowPostProcessor[t]=e}doAutoYScale(t){hc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const hc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=Wi(i),o=n.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=s.calculateZoomY(t.yStart,t.yEnd)};function Wi(s){if(s.length===0)return dc();let t=s[0].high,e=s[0].low;return s.forEach(n=>{isFinite(n.high)&&n.high>=t&&(t=n.high),isFinite(n.low)&&n.low<=e&&(e=n.low)}),{low:e,high:t}}const dc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER});var uc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,gc=Object.prototype.hasOwnProperty,fc=Object.prototype.propertyIsEnumerable,Vi=(s,t,e)=>t in s?uc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gi=(s,t)=>{for(var e in t||(t={}))gc.call(t,e)&&Vi(s,e,t[e]);if(Ui)for(var e of Ui(t))fc.call(t,e)&&Vi(s,e,t[e]);return s};const pc=(s,t,e,n)=>{var i,r,o,a;const l=Gi({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Ba(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=s.xStart,u=s.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Yt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},mc=(s,t,e,n)=>{const i=Gi({},t),r=n(),o=i.xEnd-i.xStart,a=o<e.minCandles,l=r.width/e.minWidth,c=o>l;if(r.width>0){if(c)return i.xStart=i.xEnd-l,i.zoomX=We(i.xEnd-i.xStart,r.width),i;if(a)return i.xStart=i.xEnd-e.minCandles,i.zoomX=We(i.xEnd-i.xStart,r.width),i}return i},vc=(s,t)=>s/t,bc=(s,t)=>s/t,Cc=(s,t)=>s*t,Zi=(s,t)=>{const e=s.zoomY;s.zoomY=bc(s.zoomX,t);const n=s.zoomY/e,i=s.yEnd-s.yStart,o=i*n-i;s.yEnd=s.yEnd+o/2,s.yStart=s.yStart-o/2},wc=(s,t)=>{const e=s.zoomX;s.zoomX=Cc(s.zoomY,t);const n=s.zoomX/e,i=s.xEnd-s.xStart,o=i*n-i;s.xStart=s.xStart-o},yc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},Sc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},$i=(s,t,e,n,i)=>{const r=(t.xEnd-t.xStart)*n,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=s.calculateZoomX(t.xStart,t.xEnd),t},xc=(s,t,e,n)=>$i(s,t,1,e,n);var _c=Object.defineProperty,Pc=Object.defineProperties,Tc=Object.getOwnPropertyDescriptors,Ki=Object.getOwnPropertySymbols,Mc=Object.prototype.hasOwnProperty,Ac=Object.prototype.propertyIsEnumerable,qi=(s,t,e)=>t in s?_c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Se=(s,t)=>{for(var e in t||(t={}))Mc.call(t,e)&&qi(s,e,t[e]);if(Ki)for(var e of Ki(t))Ac.call(t,e)&&qi(s,e,t[e]);return s},Ec=(s,t)=>Pc(s,Tc(t));const Lc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class Ji extends Ll{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new B,this.beforeStartAnimationSubject=new B,this.history=[],this.zoomXYRatio=0,this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=Ce(t.scale),this.autoScaleModel=new cc(this),this.offsets=this.config.components.offsets,this.addXConstraint((i,r)=>mc(i,r,this.config.components.chart,this.getBounds))}doActivate(){super.doActivate(),this.scaleInversedSubject=new B,this.beforeStartAnimationSubject=new B,this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=Se(Se({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,n=!1,i){const r=this.config.scale.disableAnimations||n;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();$i(this,o,t,i,e),this.zoomXTo(o,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const n=this.export();xc(this,n,e,t),this.zoomXTo(n,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.doAutoScale())}zoomXTo(t,e){const n=Se({},t),i=this.scalePostProcessor(n,t);this.state.lockPriceToBarRatio&&Zi(i,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(i),e?this.apply(i):zi(this.canvasAnimation,this,i)}setXScale(t,e,n=!0){const i=this.export(),r=this.calculateZoomX(t,e),o=Ec(Se({},i),{zoomX:r,xStart:t,xEnd:e}),a=this.scalePostProcessor(i,o);this.state.lockPriceToBarRatio&&Zi(a,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(a),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(a)):zi(this.canvasAnimation,this,a)}setYScale(t,e,n=!1){const i=this.export();super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);if(this.state.lockPriceToBarRatio){wc(o,this.zoomXYRatio),this.setXScale(o.xStart,o.xEnd);return}else this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}moveXStart(t){const e=this.export(),n=Se({},e);this.haltAnimation(),yc(e,t);const i=this.scalePostProcessor(n,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Sc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Dl(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}t&&this.recalculateZoomXYRatio(),this.state.lockPriceToBarRatio=t}recalculateZoomXYRatio(){this.zoomXYRatio=vc(this.zoomX,this.zoomY)}}class Dc extends Ji{constructor(t,e,n,i){super(e,n,i),this.delegate=t,this.config=e,this.getBounds=n}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Ic=Ye().colors;class Wt extends Li{constructor(t,e,n,i,r,o,a,l,c=Ic){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Lc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new B,this.meanCandleWidth=Ls,this._instrument=o,this.instrument=o,this.highLowProvider=ac(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=It.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){super.recalculateDataViewportIndexes(t,e),this.recalculateZippedHighLow(),this.eventBus.fireDraw()}applyPriceMovement(){const t=wt(this.dataPoints);t&&(this.lastPriceMovement=Xe(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Xi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Lt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Yi;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),g=a+u/2,C=(i=this.candlesTransformersByChartType[r])!=null?i:Hi;o.push(C(h,{x:g,width:u,prevCandle:d,activeCandle:this.activeCandle})),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,n)=>e+n.width,0)/t.length:this.meanCandleWidth=Ls}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Wf(s){switch(s){case"line":case"area":return!0;default:return!1}}class Bc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);if(r.length===0)return;i.singleColor?t.strokeStyle=i.singleColor:t.strokeStyle=n.colors.areaTheme.lineColor,n.hovered?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const o=n.extentComponent.getBounds(),a=r[0],l=n.view.toX(a.centerUnit);for(let c=0;c<r.length;c++){const h=r[c-1],d=r[c+1],u=r[c],g=n.view.toX(u.centerUnit),C=n.view.toY(u.close),S=o.y+o.height;if(h===void 0)t.beginPath(),t.lineTo(it(g),S),t.moveTo(it(g),C);else if(d===void 0){t.lineTo(it(g),C),t.stroke(),t.lineTo(it(g),S),t.lineTo(it(l),S),t.closePath();let _;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(_=t.createLinearGradient(0,0,0,o.height),_.addColorStop(0,n.colors.areaTheme.startColor),_.addColorStop(1,n.colors.areaTheme.stopColor),_):"",t.fill()}else t.lineTo(it(g),C)}}}}function Qi(s,t,e,n,i,r=4,o=!0,a=!1){s.save(),s.beginPath(),s.moveTo(t+r,e),s.lineTo(t+n-r,e),s.quadraticCurveTo(t+n,e,t+n,e+r),s.lineTo(t+n,e+i-r),s.quadraticCurveTo(t+n,e+i,t+n-r,e+i),s.lineTo(t+r,e+i),s.quadraticCurveTo(t,e+i,t,e+i-r),s.lineTo(t,e+r),s.quadraticCurveTo(t,e,t+r,e),s.closePath(),o&&s.fill(),a&&s.stroke(),s.restore()}function Oc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const g=c==="right"?a:-a,C=c==="right"?h:-h,S=h;s.save(),s.beginPath(),l?s.moveTo(r+C,o):s.moveTo(r,o),l?(s.lineTo(r+g-C,o),s.quadraticCurveTo(r+g,o,r+g,o-S),s.lineTo(r+g,e+S),s.quadraticCurveTo(r+g,e,r+g-C,e),s.lineTo(t+C,e)):(s.lineTo(r+g,o),s.lineTo(r+g,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-C/3,e+S/3),s.lineTo(n+C/3,i-S/3),s.quadraticCurveTo(n,i,n+C/3,i+S/3),s.lineTo(r-C/3,o-S/3),s.quadraticCurveTo(r,o,r+C/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function Rc(s,t,e,n,i,r=1){s.save(),s.lineWidth=r,s.beginPath(),s.moveTo(t,e),s.lineTo(n,i),s.stroke(),s.closePath(),s.restore()}function te(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function tr(s,t,e){const n=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);s.fillRect(n,i,r,o)}const Ut=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Uf=s=>Array.isArray(s[0])?s:[s];class Fc{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,n){const i=t.ctx,r=n&&this.paneManager.panes[n];e&&(i.save(),r&&Ut(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);r&&r.length>=1&&i.draw(t,r,e,{})}else console.error(`Data series drawer with type ${n} isn't registered!`)}}}const ae=(s,t,e,n,i=t)=>{n.forceBold?s.lineWidth=n.forceBold:e.hovered?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class Hc{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.singleColor)t.strokeStyle=e.singleColor;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);ae(t,this.config.barLineWidth,n,i),te(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=V(n.view.toX(o.centerUnit)),l=V(n.view.toX(o.startUnit)),[c,h,d,u]=o.yBodyKeyPoints(n.view),g=V(n.view.xPixels(o.width)/2),C=V(n.view.toY(o.close)),S=V(n.view.toY(o.open));this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,C),t.lineTo(a+g,C),t.moveTo(l,S),t.lineTo(a,S),t.stroke()}})}}}class kc{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Wt){const r=pt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(x.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],g=r[h+1],C=n.view.toX(c.centerUnit),S=n.view.toX(d.centerUnit),_=n.view.toY(d.close),M=u?n.view.toY(u.close)<l:!1,I=_<l;if(u!==void 0&&M!==I){er(t,n,i,M);const F=n.view.toX(u.centerUnit),j=n.view.toY(u.close),R=S-F,H=_-j,Y=R/H,Z=_-l,K=Y*Z,W=F+(R-K);t.lineTo(W,l),t.stroke(),t.lineTo(C,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(W,l)}u===void 0?(t.beginPath(),t.moveTo(S,_)):g===void 0?(er(t,n,i,I),t.lineTo(S,_),t.stroke(),t.lineTo(S,l),t.lineTo(C,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(C,l),t.lineTo(S,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(S,_)}}}}const er=(s,t,e,n)=>{e.singleColor?(s.fillStyle=e.singleColor,s.strokeStyle=e.singleColor):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Yc{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);ae(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),te(t,()=>{this.pixelLength=1/Dt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=n.colors;a&&l&&this.drawCandle(t,i,n,o)}})}}drawCandle(t,e,n,i){const{candleTheme:r,activeCandleTheme:o}=n.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.singleColor?t.fillStyle=e.singleColor:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=V(n.view.toX(i.startUnit)),d=V(n.view.xPixels(i.width)),u=i.bodyHeight(n.view),[g,C,S,_]=i.yBodyKeyPoints(n.view),M=C===S?C+1:S,I=g===_?g+1:_,F=l[`${a}Color`],j=a==="none"?F:l[`${a}WickColor`];t.fillStyle=F,e.singleColor?t.strokeStyle=e.singleColor:t.strokeStyle=j;const R=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),H=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,H?g:C),t.lineTo(h,H?I:M),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,H?g:C),t.lineTo(h,H?I:M),t.moveTo(h+1,C),t.lineTo(h+1,M),t.stroke();else if(d===3){const Y=d/Dt;this.drawCandlesWicks(t,h+Y,g,I,C,M),c||(t.beginPath(),t.moveTo(h+Y,C),t.lineTo(h+Y,M),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,C+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,g,I,C,M-1);const Z=this.config.candlePaddingPercent,K=Math.max(V(d*Z/2),this.pixelLength),W=h+K,U=d-K*2;c||(e.singleColor&&(t.fillStyle=e.singleColor),t.fillRect(W,C,U,u)),R&&this.drawCandleBorder(t,e,l,i,W+this.halfLineWidthCU,C+this.halfLineWidthCU,U-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,n,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,n),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,n,i,r,o,a,l){if(e.singleColor)t.strokeStyle=e.singleColor;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class jc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=e.flat(),o=n.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=n.colors.histogram;if(d===void 0)return;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),g=V(n.view.toY(l.close)),C=V(n.view.xPixels(l.width));t.fillRect(u,g,C,h);const S=t.createLinearGradient(0,g+h,0,a);i.singleColor?t.fillStyle=i.singleColor:(S.addColorStop(0,d[`${c}Cap`]),S.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=S),C===0?(t.beginPath(),t.strokeStyle=S,t.moveTo(u,g+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,g+h,C,a-g-h)}}}}class Nc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);ae(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.singleColor&&(t.strokeStyle=i.singleColor);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.singleColor||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),g=n.view.toX(c.centerUnit),C=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(g,C),t.stroke()}}}}const Xc=1.5;class zc{constructor(t){this.config=t}draw(t,e,n,i){var r;t.fillStyle=(r=i.singleColor)!=null?r:this.config.mainColor;for(const o of pt(e)){t.beginPath();const a=V(n.view.toX(o.centerUnit)),l=V(n.view.toY(o.close));t.arc(a,l,Xc,0,Math.PI*2,!0),t.fill()}}}const Wc=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Uc{constructor(t,e,n){this.drawer=t,this.config=e,this.chartBounds=n}draw(t,e,n,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,n,i),this.afterDraw(t,n))}beforeDraw(t){t.restore(),t.save(),Ut(t,this.chartBounds())}isChartTypeAllowed(){return Wc.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Ut(t,e.scale.getBounds())}}class Vc{constructor(t){this.chartModel=t}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(Kt(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,g=V(dt(h.width,u)),C=V(h.bodyHeight(this.chartModel.scale)),S=h.xCenter(this.chartModel.scale)-g/2,_=h.yBodyStart(this.chartModel.scale),M=this.chartModel.config.components.chart.candlePaddingPercent,I=V(g*M/2),F=S+I,j=g-I*2;t.fillRect(F,_,j,C)}})})}}const sr=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{const{centerUnit:r,close:o}=n,a=e.toX(r),l=e.toY(o);i===0?t.moveTo(a,l):t.lineTo(a,l)})},Gc=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Zc=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i;function $c(s){const t=Gc.exec(s)||Zc.exec(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const nr={};function Kc(s,t){let e=nr[s+t];if(!e){const n=$c(s);e=n&&"rgba("+n.join(",")+","+t+")",nr[s+t]=e}return e}class qc{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ae(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.singleColor)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(rr(r.config.type)&&rr(n.config.type)&&r.config.visible){const a=[],l=n,c=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1),h=r.getSeriesInViewport(r.scale.xStart-1,r.scale.xEnd+1);c.forEach((d,u)=>{const g=Math.min(d.length,h[u].length);for(let _=0;_<g;_++){const M=[d[_].clone(),h[u][_].clone()];a.push({diffPoints:M})}const C=l.getPaintConfig(u).color,S=r.getPaintConfig(o).color;this.drawDifference(t,C,S,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),sr(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[g,C]=u.diffPoints;l.push(g),c.push(C)});const h=ir(l,r.view),d=ir(c,o.view);this.fillCloud(t,n,h,d,a),this.fillCloud(t,e,d,h,a)}fillCloud(t,e,n,i,r){var o,a,l,c;t.save(),t.beginPath();const h=(a=(o=fe(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=wt(n))==null?void 0:l.x)!=null?c:0;t.lineTo(h,0),n.forEach(u=>{t.lineTo(u.x,u.y)}),t.lineTo(d,0),t.closePath(),t.clip(),t.beginPath(),n.forEach((u,g)=>{g===0?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y)}),i.slice().reverse().forEach(u=>{t.lineTo(u.x,u.y)}),t.closePath(),t.fillStyle=r.singleColor?r.singleColor:Kc(e||"#383838",.3),t.fill(),t.restore()}}const ir=(s,t)=>s.map(e=>{const{centerUnit:n,close:i}=e,r=t.toX(n),o=t.toY(i);return{x:r,y:o}}),rr=s=>s==="DIFFERENCE";class Jc{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);ae(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.singleColor)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,it(r)),t.lineTo(d,it(u))}),t.stroke()})}}class Qc{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ae(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.singleColor)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),sr(e,t,n),t.stroke()}}class th{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=l.lineWidth;t.fillStyle=(a=i.singleColor)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class eh{constructor(t){this.config=t}draw(t,e,n,i){t.save(),e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=n.getTextForPoint(h),u=yt(d,t,c),g=Ht(c,t),C=n.view.toX(h.centerUnit)-u/2,S=n.view.toY(h.close)+g;t.fillText(d,C,S)})}),t.restore()}}class sh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=n.view.toX(c.centerUnit),d=n.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,n,i){t.beginPath(),t.moveTo(e-i/2,n),t.lineTo(e,n-i),t.lineTo(e+i/2,n),t.fill()}}const Fs="resized_local",Ve="draw",Vf="draw_last_candle",le={width:20,height:20};class or{constructor(t,e,n,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=n,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=Hs;var a;i.push(this),this.parent=rh(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:n}=t,i=window.devicePixelRatio;this.canvas.style.height=n+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=n*i,this.width=e,this.height=n,this.ctx.scale(i,i)}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const n=e.height;n!==this.height&&(t.style.height=n+"px",this.height=n,t.height=n,this.prevHeight=n)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>le.width&&this.height>le.height}}const Hs={name:"candle"},nh={candle:Hs,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function ih(s,t,e,n,i,r,o){var a;const l=ce(s,t,i,r,o,e);return l.type=(a=nh[n])!=null?a:Hs,l}function ce(s,t,e,n,i,r,o){const a=new or(s,t,n,i,r,o);return ar(a,e),a}function ar(s,t){const e=s.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",s.width=t.fixedSize.width,s.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function rh(s){let t=s;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}let ks=!1,Ys=0;const Ge=new Map,js=new Map,lr=()=>{ks||(ks=!0,Ys=requestAnimationFrame(()=>{js.forEach((s,t)=>{s(),js.delete(t)}),Ge.forEach((s,t)=>{s(),Ge.delete(t)}),ks=!1}))},cr=(s,t)=>{Ge.set(s,t),lr()},Kf=s=>{Ge.delete(s)},Ns=(s,t)=>{js.set(s,t),lr()},Ze="HIT_TEST_",qf=null;class oh{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${Ct()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf(Ze)!==-1&&this.drawersMap[n].draw()})},t.on(Ve,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),cr(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(Ze)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(Ze)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}Ea(t,n.getCanvasIds()).length&&n.draw()}})}isDrawable(){var t,e,n,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>le.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>le.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=Ct()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(n);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(n);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const n=this.drawingOrder.indexOf(e);n!==-1&&this.drawingOrder.splice(n,1)}})}reorderDrawers(t){this.drawingOrder=Nn(this.drawingOrder,t)}}class hr{static paneResizer(t){return`PANE_RESIZER_${t}`}}class ah{constructor(t,e,n){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=n}draw(){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Ut(t,e.getBounds()),e.dataSeries.forEach(n=>this.drawSeries(t,n)),t.restore()})}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r={singleColor:this.canvasModel.idToColor(e.htId),forceBold:7};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const dr={disableChartPanning:!0};class ur extends X{constructor(t,e,n,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=n,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o),this.dragComponentOptions.disableChartPanning&&this.chartPanComponent.deactivatePanHandlers()},this.onDragTick=o=>{this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels),this.dragComponentOptions.disableChartPanning&&this.chartPanComponent.activateChartPanHandlers())}}doActivate(){super.doActivate()}doDeactivate(){super.doDeactivate()}}class $e extends ur{constructor(t,e,n,i,r=dr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}doDeactivate(){super.doDeactivate()}}const lh="BASELINE_RESIZER";class ch extends X{constructor(t,e,n,i,r,o,a){super(),this.chartModel=t,this.canvasModel=n,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.baselineYPercents=50,this.ht=As.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&al(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new $e(this.ht,{onDragTick:this.dragTickCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(x.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(x.CHART),e=this.canvasBoundContainer.getBounds(x.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const n=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=n,this.canvasBoundContainer.bounds[lh]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(x.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const Ke=s=>{var t;const e=ue(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=ue(s.hi,Math.max(s.open,s.close),e),i=ue(s.lo,Math.min(s.open,s.close),e),r=ue(s.open,s.lo,e),o=ue(s.close,s.hi,e);return{hi:n,lo:i,open:r,close:o,timestamp:s.timestamp,volume:(t=s.volume)!=null?t:0,expansion:s.expansion,idx:s.idx,impVolatility:s.impVolatility}},Xs=s=>{for(let t=0;t<s.length;++t)s[t].idx=t},gr=s=>{s.forEach(t=>{t.idx=void 0})};class hh{constructor(){}draw(t,e,n){const i=n.view.toY(0),r=pt(e),o=[[],[]];r.forEach((a,l,c)=>{o[a.close<this.previousValue(c,l)?1:0].push(a)}),o.forEach((a,l)=>{const c=n.getPaintConfig(l);t.strokeStyle=l===0?c.color:c.aditionalColor||"#FF00FF",t.lineWidth=c.lineWidth,t.beginPath(),a.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,it(i)),t.lineTo(d,it(u))}),t.stroke()})}previousValue(t,e){do e--;while(e>=0&&!isFinite(t[e]&&t[e].close));return t[e]?t[e].close:Number.NaN}}var dh=Object.defineProperty,fr=Object.getOwnPropertySymbols,uh=Object.prototype.hasOwnProperty,gh=Object.prototype.propertyIsEnumerable,pr=(s,t,e)=>t in s?dh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,fh=(s,t)=>{for(var e in t||(t={}))uh.call(t,e)&&pr(s,e,t[e]);if(fr)for(var e of fr(t))gh.call(t,e)&&pr(s,e,t[e]);return s};class ph{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class mh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,C){super(),this.chartModel=t,this.canvasModel=e,this.config=n,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=g,this.chartResizeHandler=C,this._dataSeriesDrawers={},this.backgroundDrawPredicateSubj=new _t(!0),this.strToBarType=_=>{var M;return(M=this.barTypeValues.find(I=>I===_))!=null?M:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new ch(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const S=new ah(this._dataSeriesDrawers,this.hitTestCanvasModel,d);this.drawingManager.addDrawerBefore(S,Ze+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new $l(c,this.config,()=>this.backgroundDrawPredicateSubj.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(q),n.components.chart.cursor),this.dataSeriesDrawer=new Fc(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(()=>{this.backgroundDrawPredicateSubj.next(!1)})),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawPredicateSubj.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Hi),this.registerCandlesTransformer("trend",ki),this.registerCandlesTransformer("hollow",ql),this.registerCandlesTransformer("line",Jl)}get barTypeValues(){return yi(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new Yc(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Hc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new Nc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new zc(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Bc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new kc(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new jc(this.config.components.chart.histogram));const e=x.PANE_UUID(q),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new Qc),this.registerDataSeriesTypeDrawer("HISTOGRAM",new Jc),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new hh),this.registerDataSeriesTypeDrawer("POINTS",new th),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Uc(new Vc(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new eh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new sh),this.registerDataSeriesTypeDrawer("DIFFERENCE",new qc)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(fh({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,n=!0){return this.chartModel.setTimestampRange(t,e,n)}setXScale(t,e,n=!0){return this.scale.setXScale(t,e,n)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setMainSeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=n,this.chartModel.setAllSeries({candles:t.candles,instrument:n},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return gr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(n)}setSecondarySeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,n);if(this.updatePriceIncrementsIfNeeded(n),i)return i}setAllSeries(t,e=[]){var n;const i=(n=t.instrument)!=null?n:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!It.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[It.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}class mr extends Wt{constructor(t,e,n,i,r,o,a,l,c,h){super(e,n,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}const vh=s=>t=>{if(t.length!==0){const e=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),n=e[0],i=e[e.length-1];s.setXScale(n.startUnit,i.startUnit+i.width+s.offsets.right),s.doAutoScale(!0),s.recalculateZoomXYRatio(),s.fireChanged()}},bh=(s,t)=>(e,n=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=n===null?0:t.mainCandleSeries.meanCandleWidth*2,c=n?o-l:o+l,h=n?a+l:a-l;s.setXScale(c,h)};var Ch=Object.defineProperty,wh=Object.defineProperties,yh=Object.getOwnPropertyDescriptors,vr=Object.getOwnPropertySymbols,Sh=Object.prototype.hasOwnProperty,xh=Object.prototype.propertyIsEnumerable,br=(s,t,e)=>t in s?Ch(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,xe=(s,t)=>{for(var e in t||(t={}))Sh.call(t,e)&&br(s,e,t[e]);if(vr)for(var e of vr(t))xh.call(t,e)&&br(s,e,t[e]);return s},zs=(s,t)=>wh(s,yh(t));class _h{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,n)=>zs(xe({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=zs(xe({},Ce(this.config.colors)),{lineTheme:xe({},n.lineTheme),areaTheme:xe({},n.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,n="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,n=i);return this.usedChartColors[n]=this.usedChartColors[n]+1,this.symbolsToColorKeys[t]=n,this.secondaryChartColorsPool[n]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var n,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=zs(xe({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Ph=Object.defineProperty,Cr=Object.getOwnPropertySymbols,Th=Object.prototype.hasOwnProperty,Mh=Object.prototype.propertyIsEnumerable,wr=(s,t,e)=>t in s?Ph(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,qe=(s,t)=>{for(var e in t||(t={}))Th.call(t,e)&&wr(s,e,t[e]);if(Cr)for(var e of Cr(t))Mh.call(t,e)&&wr(s,e,t[e]);return s};class Ah extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=n,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.nextCandleTimeStampSubject=new B,this.chartTypeChanged=new B,this.mainInstrumentChangedSubject=new B,this.offsetsChanged=new B,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new _h(this.config);const d=new mr(this.chartBaseModel,this.paneManager.panes[q].mainExtent,Ct(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new ph,this.candlesTransformersByChartType,this.candleWidthByChartType,qe({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),o.addXConstraint((u,g)=>pc(g,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=vh(o),this.timeFrameViewportTransformer=bh(o,this),this.pane=this.paneManager.panes[q]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(q)).pipe(Et(hi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>le.width&&t.height>le.height){const e=this.getEffectiveChartWidth(),n=this.getEffectiveYAxisWidth();if(this.prevChartWidth===0){this.scale.isViewportValid()?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Yt(n-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=n,this.prevChartWidth=e;return}const i=Yt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=n,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(n=>{const i=n.dataPoints;return gr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=Je(t.map(Ke)),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,n&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var n;this.mainCandleSeries.instrument=(n=t.instrument)!=null?n:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=Je(t.candles.map(Ke));this.mainCandleSeries.clearData(),Xs(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=qe({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const n=[t,...e];if(!this.candleSeries.every(l=>n.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=Je(t.candles.map(Ke)),r=Sr(this.mainCandleSeries.dataPoints,i),o=r.candles;Xs(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const g=Je(l.candles.map(Ke)),C=Sr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],g).candles;return this.setSecondaryCandleSeries(C,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),l.recalculateDataViewportIndexes()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(n=>{const i=zt(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}createSecondaryCandleSeriesModel(t){const e=qe(qe({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Wt(this.paneManager.panes[q].mainExtent,Ct(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return n.config.type="line",this.candleSeries.push(n),n}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[q].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{var r;const o=(r=i.idx)!=null?r:0,a=e[o];if(a)n.push(a);else{let l=yr(e,o,-1);if(l||(l=yr(e,o,1)),l){const c=Sl(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=Lt(t,Ye().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=n,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}getEffectiveYAxisWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(q)).width}getEffectiveChartWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)).width}getEffectiveChartHeight(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)).height}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),n=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=n.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,n=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,n)}candleFromUnit(t,e=!1,n=this.mainCandleSeries){var i,r;const o=zt(n.visualPoints,t,d=>d.startUnit),a=n.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Kt((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?ye(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:ye(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e=!0,n=this.mainCandleSeries){const i=n.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,n,i;const r=t-((i=(n=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:n.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,n=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,n)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return wt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return wt(t)}getMaxCandlesFitLength(){return it(this.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((n,i)=>{const r=i.timestamp,o=be(r,!1,t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,n[o.index]=i),n},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const n=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=be(h.timestamp,!0,o,this.getPeriod()),g=Math.min(u.index,o.length);a=a||g===o.length,o[g]=h,h.idx=g,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(g);const C=g>=o.length-1,S=c&&h.timestamp<c.timestamp;if(C&&!S&&(c=h),a&&c&&n&&l){const _=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Yi;this.scale.moveXStart(this.scale.xStart+_(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return ft(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=0,e){let n=this.getCandles().slice();const i=this.getCandlesCount(),r=e!=null?e:i+this.FAKE_CANDLES_DEFAULT;n=n.slice(Math.max(0,t),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(ye(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(ye(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...n,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const n=t.slice(),i=[];return e.forEach(r=>{const a=be(r.timestamp,!1,t).index;a<0?i.push(r):t[a].timestamp===r.timestamp?n[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...n]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){const n=this.findSeriesBySymbol(e);if(n.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}n.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Xs(i.dataPoints),i.recalculateVisualPoints()}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Je=s=>s.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),yr=(s,t,e)=>{if(t>=s.length)return s[s.length-1];for(let n=t;n<s.length&&n>=0;n+=e){const i=s[n];if(i)return i}},Sr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=be(r.timestamp,!0,s).index;a<0?n.push(r):a>=s.length?i.push(r):s[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:n,appended:i,candles:[...n,...e,...i]}};class _e{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ws{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const n=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(n,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=wi(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=wi(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=pt(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class Eh{constructor(t,e,n){this.model=t,this.crossToolCanvasModel=e,this.crossToolTypeDrawers=n}draw(){const t=this.crossToolTypeDrawers[this.model.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.model.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}class Lh extends X{constructor(t,e,n,i){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.currentHoverSubject=new _t(null),this.type="cross-and-labels",this.type=t.type}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?this.updateHover(t):this.currentHover=null,this.fireDraw()}))}fireDraw(){this.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateHover(t,e=this.config.magnetTarget){if(this.currentHover===null?this.currentHover={x:t.x,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=t.x,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===q)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}}const Pt=4;function Dh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,C;const S=r.align,_=(l=i.textFont)!=null?l:Jt(r),M=i.bgColor,I=(c=i.textColor)!=null?c:qt(M,o.labelTextColor,o.labelInvertedTextColor),F=(h=i.paddingTop)!=null?h:Pt,j=(d=i.paddingBottom)!=null?d:Pt,R=(u=i.paddingEnd)!=null?u:Pt,H=Kt(Ht(_,s)/2),Y=n-H-F,K=n+H+j-Y;if(a&&!Qe(n,t,K))return;s.save(),s.fillStyle=M,s.strokeStyle=M;const W=Kt(t.width/6),U=S==="right"?t.x:t.x+t.width,tt=S==="right"?U+W:U-W,J=r.labelBoxMargin.end,Q=J-R,et=t.width-W-Q;Oc(s,tt,Y,U,Y+Kt(K/2),tt,Y+K,et,(C=(g=r.typeConfig.badge)==null?void 0:g.rounded)!=null?C:!1,S),s.fillStyle=I,s.font=_;const st=S==="right"?t.x+t.width-yt(e,s,_)-J:t.x+J;s.fillText(e,st,n+H-1),s.restore()}function Ih(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,C,S,_,M,I;const F=r.align,j=(l=i.textFont)!=null?l:Jt(r),R=i.bgColor,H=(c=i.textColor)!=null?c:qt(R,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,Z=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Pt,K=(C=(g=i.paddingBottom)!=null?g:Y==null?void 0:Y.bottom)!=null?C:Pt,W=(_=(S=i.paddingEnd)!=null?S:Y==null?void 0:Y.end)!=null?_:Pt,U=i.paddingStart,tt=Ht(j,s),J=n-tt/2-Z,et=n+tt/2+K-J,st=(I=i.rounded)!=null?I:(M=r.typeConfig.rectangle)==null?void 0:M.rounded;if(a&&!Qe(n,t,et))return;s.save(),s.fillStyle=R,s.strokeStyle=R;const ot=r.labelBoxMargin.end;s.font=j;const Tt=yt(e,s,j),St=ot-W,Bt=U!==void 0?Tt+U+W:t.width-St,se=F==="right"?t.x+t.width-St-Bt:t.x+St,Ae=F==="right"?t.x+t.width-Tt-ot:ot;st?Qi(s,se,J,Bt,et,4,!0):s.fillRect(se,J,Bt,et),s.fillStyle=H,s.fillText(e,Ae,n+tt/2-1),s.restore()}function Bh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,C,S,_;const M=r.align,I=(l=i.textFont)!=null?l:Jt(r),F=o.backgroundColor,j=(c=i.textColor)!=null?c:qt(F,o.labelTextColor,o.labelInvertedTextColor),R=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,H=(u=(d=i.paddingTop)!=null?d:R==null?void 0:R.top)!=null?u:Pt,Y=(C=(g=i.paddingBottom)!=null?g:R==null?void 0:R.bottom)!=null?C:Pt,Z=(_=(S=i.paddingEnd)!=null?S:R==null?void 0:R.end)!=null?_:Pt,K=i.paddingStart,W=Ht(I,s),U=n-W/2-H,J=n+W/2+Y-U;if(a&&!Qe(n,t,J))return;s.save(),s.fillStyle=F,s.strokeStyle=F;const Q=r.labelBoxMargin.end;s.font=I;const et=yt(e,s,I),st=Q-Z,ot=K!==void 0?et+K+Z:t.width-st,Tt=M==="right"?t.x+t.width-st-ot:t.x+st,St=M==="right"?t.x+t.width-et-Q:Q;s.fillStyle=F,s.strokeStyle=F,s.fillRect(Tt,U,ot,J),s.fillStyle=j,s.fillText(e,St,n+W/2-1),s.restore()}function Oh(s,t,e=Pt){return Ht(s,t)/2+e}function Qe(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const Rh="badge",xr=4,_r={badge:Dh,rectangle:Ih,plain:Bh};function Pr(s,t,e,n,i,r,o,a){var l,c,h,d,u;const g=i.y,C=i.labelText,S=(l=i.mode)!=null?l:"label",_=(c=i.labelType)!=null?c:Rh,M=i.description,I=(h=i.textFont)!=null?h:Jt(o),F=i.bgColor,j=(d=i.lineColor)!=null?d:F,R=yt(M!=null?M:"",s,I)+8,H=it(i.y),Y=Ht(I,s),Z=g-Y/2,W=g+Y/2-Z;s.save(),s.fillStyle=F,s.strokeStyle=j;const U=r.getBounds(x.PANE_UUID(q)),tt=_r[_],J=o.labels.descriptions,Q=Fh(e,H,W),et=()=>J&&Hh(t,s,e,n,i,o);let st,ot;const Tt=2;o.align==="right"?(st=U.x,ot=J?U.x+U.width-R:U.x+U.width+Tt):(st=J?U.x+R:U.x-Tt,ot=U.x+U.width);const St=(u=i.lineY)!=null?u:i.y,Bt=()=>Q&&te(s,()=>Rc(s,st,St,ot,St,1)),se=()=>tt(s,e,C,g,i,o,a.yAxis,!1),wf={line:()=>{Bt(),et()},"line-label":()=>{Bt(),se(),et()},label:()=>{et(),se()}};S!=="none"&&Qe(g,e,W)&&wf[S](),s.restore()}const Fh=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function Hh(s,t,e,n,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=Jt(r),g=yt(h,t,u),C=Ht(u,t),S=(o=i.paddingTop)!=null?o:xr,_=(a=i.paddingBottom)!=null?a:xr,M=d-C/2-S,F=d+C/2+_-M;t.save();const j=g+5,R=4,H=g+R*2,Y=n.x+n.width,Z=c==="right"?Y-H:n.x+R;Kl(s,t,Z,M,j,F,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const K=c==="right"?Y-g-R*2:n.x+R*2;t.fillText(h,K,d+C/2-1),t.restore()}class Tr{constructor(t,e,n,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=n,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&te(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var n,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(x.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES,{extensionY:1e-4}),h=(n=this.config.components.xAxis.padding.top)!=null?n:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,g=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const C={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},S={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},_=g==null?void 0:g(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),_&&(t.moveTo(...C.start),t.lineTo(...C.end)),t.moveTo(...S.start),t.lineTo(...S.end),t.stroke()),_&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var n,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,g=t.measureText(u).width,C=this.config.components.xAxis.fontSize,S=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const _=(n=l==null?void 0:l.left)!=null?n:0,M=(i=l==null?void 0:l.right)!=null?i:0,I=(r=l==null?void 0:l.top)!=null?r:0,F=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,R=g+_+M,H=C+I+F,Y=Math.max(d-R/2,0),Z=S.y+j;Qi(t,Y,Z,R,H),t.fillStyle=h.labelTextColor;const K=Math.max(d-g/2,_),W=S.y+j+C+I-1;t.fillText(u,K,W),t.restore()}}drawYLabel(t,e){const n=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=_r[a],g=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:g,bgColor:i.labelBoxColor,paddingBottom:n==null?void 0:n.bottom,paddingEnd:n==null?void 0:n.end,paddingTop:n==null?void 0:n.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class kh{draw(){}}class Yh extends X{constructor(t,e,n,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossToolTypeDrawers={},this.model=new Lh(t.components.crossTool,this.crossToolCanvasModel,o,a),this.addChildEntity(this.model);const l=new _e(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const c=new Eh(this.model,this.crossToolCanvasModel,this.crossToolTypeDrawers),h=new Ws;h.addDrawer(l,"CLEAR_CANVAS"),h.addDrawer(c,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(h,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Tr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Tr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new kh)}setVisible(t){this.model.setType(t?"cross-and-labels":"none")}setType(t){this.model.setType(t)}observeCrossToolChanged(){return this.model.currentHoverSubject}setMagnetTarget(t){this.config.components.crossTool.magnetTarget=t}registerCrossToolTypeDrawer(t,e){this.crossToolTypeDrawers[t]=e}}class jh{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,n])=>{for(const i of n){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class jt{constructor(t){this.data=t,this.next=null}}class Nh{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new jt(t);if(this.head===null)this._head=e;else{let n=this.head;for(;n.next;)n=n.next;n.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const n=new jt(e);if(t===0)n.next=this.head,this._head=n;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;n.next=i,r.next=n,t===this.length-1&&(this._tail=n)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,n=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,n=e,e=e.next;n.next=e.next,t===this.length-1&&(this._tail=n)}this.length--}getNodePosition(t){let e=0,n=this.head;for(;n;){if(n.data===t.data)return e;n=n.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class Xh extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._objects=new _t({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const n=e.paneId,r=this.objects[n];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[n,i]=e,r=new jt(n);return i.getNodePosition(r)}addObject(t){var e;const n=t.paneId,i=this.objects,r=(e=i[n])!=null?e:new Nh;Object.keys(i).find(o=>o===n)||(i[n]=r),r.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.setDynamicObjects(i)}removeObject(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);i.removeAt(o),this.modelIdToObjectMap.delete(t),i.size()===0&&delete this.objects[n.paneId],this.setDynamicObjects(this.objects)}moveToPosition(t,e){const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new jt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(n),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,n),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,n),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,n),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class zh extends X{constructor(t,e){super();const n=new Xh(t);this.model=n,this.addChildEntity(n);const i=new jh(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Wh=()=>s=>s.toString(),Uh=(s,t)=>{var e;const n="date.get"+(t((e=s.timezone)!=null?e:"")?"":"UTC"),i={YYYY:o("FullYear"),YY:o("FullYear")+" % 100",MMM:a("shortMonths","Month"),MMMM:l(a("shortMonths","Month")),M:"1+"+o("Month"),d:o("Date"),H:o("Hours"),m:o("Minutes"),s:o("Seconds"),sss:o("Milliseconds"),EEE:a("shortDays","Day"),SSS:"this.addTwoZeros("+o("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(h){i[h+h]="this.addZero("+i[h]+")"});const r=new RegExp(Object.keys(i).sort().reverse().join("|"),"g");function o(h){return n+h+"()"}function a(h,d){return"this."+h+"["+o(d)+"]"}function l(h){return h+".toUpperCase()"}function c(h){return"' + ("+i[h]+") + '"}return function(h){var d;const u={shortDays:Vh(s),shortMonths:Gh(s),addZero(g){return g<10?"0"+g:g},addTwoZeros(g){return(g<100?"0":"")+(g<10?"0":"")+g},tzDate:t((d=s.timezone)!=null?d:"")||function(g){return g instanceof Date?g:new Date(+g)}};return new Function("date","date=this.tzDate(date); return '"+h.replace(r,c)+"'").bind(u)}};function Vh(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Gh(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const Mr=(s,t,e)=>{if(s){if(typeof s=="string")return e(s);if(Array.isArray(s)){const n=s.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(n.length>0){const i=n[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Wh()},Zh={"rhombus-small":4,rhombus:6,"rhombus-large":8},Pe=(s,t)=>`${s}_${t}`;class $h{constructor(t,e,n,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&(this.createCustomIcon("earnings",a.earnings),this.createCustomIcon("dividends",a.dividends),this.createCustomIcon("splits",a.splits),this.createCustomIcon("conference-calls",a.conferenceCalls))}createCustomIcon(t,e){if(e){const n=this.createIconImage(e.normal),i=this.createIconImage(e.hover);this.customIcons[Pe(t,"normal")]=n,this.customIcons[Pe(t,"hover")]=i}}createIconImage(t){var e;const i=new DOMParser().parseFromString(t,"text/html").querySelector("svg");let r=0;i&&(r=parseInt((e=i.getAttribute("height"))!=null?e:"",10));const l="data:image/svg+xml;base64,"+btoa(t),c=new Image;return c.src=l,{img:c,svgHeight:r}}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(x.EVENTS),e=this.canvasBoundsContainer.getBounds(x.ALL_PANES),n=this.canvasModel.ctx;n.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{const r=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(r>e.x&&r<e.x+e.width){const o=this.config.colors.events[i.type].color;n.strokeStyle=o,this.customIcons[Pe(i.type,"hover")]!==void 0?this.drawCustomSvgEvent(n,r,t,i):this.drawDefaultEvent(n,r,t,i,o),this.model.hoveredEvent.getValue()===i&&(n.beginPath(),n.moveTo(r,e.y),n.lineTo(r,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(r,i))}}),n.restore()}drawCustomSvgEvent(t,e,n,i){const r=n.y+n.height/2,o=this.customIcons[Pe(i.type,"normal")],a=this.customIcons[Pe(i.type,"hover")];this.model.hoveredEvent.getValue()===i?t.drawImage(a.img,e-a.svgHeight/2,r-a.svgHeight/2):t.drawImage(o.img,e-o.svgHeight/2,r-o.svgHeight/2)}drawDefaultEvent(t,e,n,i,r){const o=n.y+n.height/2;t.fillStyle=r,t.lineWidth=1.5;const a=Us(i);t.beginPath(),t.moveTo(e-a,o),t.lineTo(e,o-a),t.lineTo(e+a,o),t.lineTo(e,o+a),t.closePath(),this.model.hoveredEvent.getValue()===i?t.fill():t.stroke()}drawLabel(t,e){var n;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(x.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(n=this.config.components.xAxis.padding.top)!=null?n:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function Us(s){return Zh[s.style]}const ts=5;class Kh{constructor(t,e,n,i,r){this.hitTestCanvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r}draw(){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(x.EVENTS);t.save(),this.model.events.forEach((n,i)=>{const r=this.model.events[i-1],o=r&&this.chartModel.candleFromTimestamp(r.timestamp).xCenter(this.chartModel.scale),a=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(a>e.x&&a<e.x+e.width){const l=this.config.colors.events[n.type].color;t.strokeStyle=l,t.fillStyle=l;const c=Us(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const h=(c+ts)*2;if(o!==void 0){const d=Us(r);if(o+d>a-h/2){const g=c*2+ts;t.fillRect(o+d,e.y,g,e.height)}else t.fillRect(a-c-ts,e.y,h,e.height)}else t.fillRect(a-c-ts,e.y,h,e.height)}}),t.restore()}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var qh=Object.defineProperty,Ar=Object.getOwnPropertySymbols,Jh=Object.prototype.hasOwnProperty,Qh=Object.prototype.propertyIsEnumerable,Er=(s,t,e)=>t in s?qh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,td=(s,t)=>{for(var e in t||(t={}))Jh.call(t,e)&&Er(s,e,t[e]);if(Ar)for(var e of Ar(t))Qh.call(t,e)&&Er(s,e,t[e]);return s};const Lr=317,Vs={DRAWINGS:[1,199],NEWS:[200,299],DATA_SERIES:[300,2999],EVENTS:[3e3,4e3],EXECUTED_ORDERS:[4001,5e3]};class ed extends or{constructor(t,e,n,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=n,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new B,this.touchStartSubject=new B,this.dblClickSubject=new B,this.rightClickSubject=new B,this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,ar(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(ve(100,me,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=ft(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=ft(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ct(()=>td({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,n,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*Lr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Lr}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const n=window.devicePixelRatio;return this.prevAnimationFrameId!==Ys&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ys),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),n=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(n),[r]=Gs(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(n)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const n=this.getPixel(t.x,t.y),i=this.colorToId(n[0]*65536+n[1]*256+n[2]),r=Number(i),[o]=Gs(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var n,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[g,C]=Gs(this.hitTestSubscribers,u),S=g==null?void 0:g.lookup(d),_={point:t,model:S};switch(e){case"mousedown":S&&((n=g==null?void 0:g.onMouseDown)==null||n.call(g,S,t)),C.forEach(M=>M.onMouseDown&&M.onMouseDown(null,t));break;case"mouseup":S&&((i=g==null?void 0:g.onMouseUp)==null||i.call(g,S,t)),C.forEach(M=>M.onMouseUp&&M.onMouseUp(null,t));break;case"hover":S&&((r=g==null?void 0:g.onHover)==null||r.call(g,S,t)),C.forEach(M=>M.onHover&&M.onHover(null,t)),this.hoverSubject.next(_);break;case"touchstart":S&&((o=g==null?void 0:g.onTouchStart)==null||o.call(g,S,t)),C.forEach(M=>M.onTouchStart&&M.onTouchStart(null,t)),this.touchStartSubject.next(_);break;case"dblclick":S&&((a=g==null?void 0:g.onDblClick)==null||a.call(g,S,t)),this.dblClickSubject.next(_);break;case"contextmenu":S&&((l=g==null?void 0:g.onRightClick)==null||l.call(g,S,t)),this.rightClickSubject.next(_);break;case"zoom":S&&((c=g==null?void 0:g.onZoom)==null||c.call(g,S,t)),C.forEach(M=>M.onZoom&&M.onZoom(null,t));break;default:break}}}const Gs=(s,t)=>{let e;const n=[];return s.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:n.push(i)}),[e,n]};var sd=Object.defineProperty,nd=Object.defineProperties,id=Object.getOwnPropertyDescriptors,Dr=Object.getOwnPropertySymbols,rd=Object.prototype.hasOwnProperty,od=Object.prototype.propertyIsEnumerable,Ir=(s,t,e)=>t in s?sd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ad=(s,t)=>{for(var e in t||(t={}))rd.call(t,e)&&Ir(s,e,t[e]);if(Dr)for(var e of Dr(t))od.call(t,e)&&Ir(s,e,t[e]);return s},ld=(s,t)=>nd(s,id(t));class cd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new _t(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>ld(ad({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Vs.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class hd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>Mr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new cd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new $h(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Kh(n,i,t,r,c);this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(x.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){Lt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class dd{constructor(t,e,n,i,r,o,a,l,c=()=>!0,h){this.canvasModel=t,this.viewportModel=e,this.config=n,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.getBaseline=h}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;te(t,()=>this.drawVertical(t)),te(t,()=>this.drawHorizontal(t)),te(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const n=this.xBoundsProvider(),i=it(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(n.x,i),t.lineTo(n.x+n.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.xBoundsProvider(),i=n.x+n.width;for(const r of e){const o=V(this.viewportModel.toX(r.value));o>n.x&&o<i&&(t.beginPath(),t.moveTo(o,n.y),t.lineTo(o,n.y+n.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length&&this.config.components.grid.horizontal){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.yBoundsProvider();for(const i of e){const r=it(this.viewportModel.toY(i.value)),o=Oh(i.text,t,Pt);r>n.y+o&&r<n.y+n.height-o&&(t.beginPath(),t.moveTo(n.x,r),t.lineTo(n.x+n.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Br extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new dd(t,e,n,i,a,l,c,h,u,d)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class ud{constructor(t,e,n,i){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:n,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+n,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low");const c=this.canvasBoundsContainer.getBounds("PANE_CHART");l.restore(),Ut(l,c)}}drawMarkerLabel(t,e,n,i){const r=this.getMarkerY(t,n,i==="low"),o=ke(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(n,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?"H:":"L:"} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=ke(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(x.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,n){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(x.CHART),o=4,a=t.measureText(n).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class gd extends X{constructor(t,e,n,i,r){super();const o=new ud(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const fd=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],pd=24*60*60*1e3;class md extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new B}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+pd;Ha(this.highlights,t,e,vd).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,n)=>e.to-n.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const vd=s=>s.to,Vt=[20,10];class bd{constructor(t,e,n,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,n,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(x.ALL_PANES);o.save(),Ut(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(n=this.config.components.highlights.fontSize)!=null?n:11,g=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",C=`${u}px ${g}, monospace`;o.font=C,o.lineWidth=h,o.setLineDash(d),fd.forEach(S=>{var _,M;const I=a[S];if(I){const F=this.config.colors.highlights[S],j=(_=F==null?void 0:F.border)!=null?_:"#ffffff",R=(M=F==null?void 0:F.background)!=null?M:"#ffffff";o.save(),o.beginPath(),o.fillStyle=R,o.strokeStyle=j,I.forEach(H=>{var Y,Z,K;const W=this.chartModel.candleFromTimestamp(H.from),U=dt(W.width,this.chartModel.scale.zoomX),tt=W.xStart(this.chartModel.scale),J=this.chartModel.candleFromTimestamp(H.to),Q=dt(J.width,this.chartModel.scale.zoomX),et=J.xStart(this.chartModel.scale)+Q;if(H.border&&this.drawBorders(H.border,o,tt+U,et-Q,c),o.fillRect(tt,c.y,et-tt,c.y+c.height),H.label){const st=(Y=H.label.text)!=null?Y:"",ot=this.config.colors.highlights[H.type];o.save(),o.fillStyle=(Z=ot==null?void 0:ot.label)!=null?Z:"#ffffff";const Tt=yt(st,o,C),[St,Bt]=this.resolveHighlightLabelPosition((K=H.label.placement)!=null?K:"left-left",c,[tt,et],Tt);o.fillText(st,St,Bt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Vt[1]-i,e.y+Vt[0]];case"left-left":return[r-Vt[1]-i,e.y+Vt[0]];case"right-right":return[o+Vt[1],e.y+Vt[0]];case"left-right":default:return[r+Vt[1],e.y+Vt[0]]}}drawBorders(t,e,n,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(n,r.y),e.lineTo(n,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const Cd="HIGHLIGHTS_PLUGIN";class wd extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new md(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new bd(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,Cd)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function yd(){return N(function(s,t){var e,n=!1;s.subscribe(xt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function $(s,t){return N(function(e,n){var i=0;e.subscribe(xt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var Sd=Object.defineProperty,xd=Object.defineProperties,_d=Object.getOwnPropertyDescriptors,Or=Object.getOwnPropertySymbols,Pd=Object.prototype.hasOwnProperty,Td=Object.prototype.propertyIsEnumerable,Rr=(s,t,e)=>t in s?Sd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Fr=(s,t)=>{for(var e in t||(t={}))Pd.call(t,e)&&Rr(s,e,t[e]);if(Or)for(var e of Or(t))Td.call(t,e)&&Rr(s,e,t[e]);return s},Hr=(s,t)=>xd(s,_d(t));const Nt=4;class Md{constructor(t,e,n,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(x.N_MAP),n=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(x.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),n.width!==0&&this.drawLeftArrowButton(c,n,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,n,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,n,i){t.x<=n.x+n.width&&(t.x=n.x+n.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,n,i,r){this.blockDrawSliderOnLeftArrow(e,n,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,n,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Nt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+Nt,r+Nt),t.lineTo(i+Nt,r-Nt),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Nt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-Nt),t.lineTo(i,r+Nt),t.lineTo(i+Nt,r),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,n,i){const r=n.components.navigationMap.knots.border;t.fillStyle=n.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=n.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=n.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=n.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=pt(this.chartModel.mainCandleSeries.getSeriesInViewport()),n=this.config.components.navigationMap.timeLabels,i=n.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:n.fontFamily,textSize:`${n.fontSize}px`},d={dateFormat:n.dateFormat,padding:n.padding,textProperties:Hr(Fr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:Hr(Fr({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,n,i){const r=i.padding,o=Gn(n,i.dateFormat,this.formatterFactory);Wn(t,i.textProperties);const a=ke(t),l=Vn(o);Ya(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Te extends ur{constructor(t,e,n,i,r=dr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}doDeactivate(){super.doDeactivate()}}const kr=4;class Ad extends X{constructor(t,e,n,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=n,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=g=>{const C=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=g.x-C.x-kr},this.leftKnotDragTick=g=>{const{delta:C}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.leftKnotDragStartXRelative+C)/_;this.canvasBoundsContainer.leftRatio=M,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=g=>{const C=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=g.x-C.x+kr},this.rightKnotDragTick=g=>{const{delta:C}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.rightKnotDragStartXRelative+C)/_;this.canvasBoundsContainer.rightRatio=M,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=g=>{const{delta:C}=g,S=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),_=this.chartModel.mainCandleSeries.meanCandleWidth/(S.width/this.chartModel.mainCandleSeries.dataPoints.length),M=(this.lastMousePosition-C)*_;this.scale.moveXStart(this.scale.xStart-M),this.lastMousePosition=C};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Te(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Te(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_SLIDER_WINDOW),u=new Te(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const n=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=n.dataIdxStart/(n.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=n.dataIdxEnd/(n.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class Ed extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=n,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new Md(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new Ad(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(x.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(x.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(x.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(x.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(x.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(x.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(yd(),$(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const n=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-n,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),h=c.width,d=[];let u=0,g,C;for(g=0;g<h;g++)C=it(g*o/h)-r,C in e?(d[g]=e[C].close,u=(t=d[g])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[g]=0;return a-=l,d.map((S,_)=>[_+c.x,(a+l-S)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(Fs),this.canvasModel.fireDraw())}}class Ld extends X{constructor(t,e,n){super(),this.scale=t,this.canvasInputListeners=e,this.mainCanvasParent=n,this.touchedCandleIndexes=[0,0]}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(t=>this.handleTouchMoveEvent(t)))}handleTouchStartEvent(t){t.touches.length===2&&(this.touchedCandleIndexes=this.getXPositions(t).map(e=>this.scale.fromX(e)))}handleTouchMoveEvent(t){t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),n=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];n[r]=a.pageX-e.left-i}return n}pinchHandler(t,e){const n=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=n+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;this.scale.setXScale(n,i)}}const Yr=()=>{const s=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(n=>navigator.userAgent.match(n));return s?"apple":e?"mobile":"other"},Jf=(s,t)=>s==="apple"||s==="mobile"?3:t,Dd=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Id=!!window.chrome,jr=typeof InstallTrigger!="undefined",Bd=navigator.platform.indexOf("Win")>-1,Nr=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(Dd)i=e===s.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(s.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(s.deltaY)*3);else if(Id){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,Bd){const r=Math.round(s.deltaY)===e||Math.abs(Math.round(s.deltaY)+Math.sign(s.deltaY))===Math.abs(e)||Math.abs(Math.round(s.deltaY)-Math.sign(s.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(s.deltaY)||r}}else jr?Math.abs(s.deltaY)>Math.abs(s.deltaX)?i=!1:i=n===s.deltaX*-3:i=e===s.deltaY*-3;i&&(t=!0)}else s.deltaMode===0&&(t=!0);return jr&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},Xr=(s,t)=>s==="percent"?t/4:t;var Zs=Math.pow;class Od extends X{constructor(t,e,n,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=n,this.mainCanvasParent=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.canvasAnimation=a,this.chartPanComponent=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelTrottleTime=15,this.zoomXHandler=(d,u)=>{const g=d.deltaY<0;if(this.config.scale.zoomToCursor){const S=this.canvasBoundsContainer.getBounds(x.CANVAS).width,M=d.offsetX/S;this.scale.zoomXToPercent(M,g,!1,u)}else this.scale.zoomXToEnd(g,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(bs),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const g=Yt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-g),this.bus.fireDraw()},this.touchHandler=new Ld(this.scale,this.canvasInputListener,this.mainCanvasParent);const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Te(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(ft(this.canvasInputListener.observeWheel(t),this.canvasInputListener.observePinch(t)).pipe(ve(this.wheelTrottleTime,me,{trailing:!0,leading:!0})).subscribe(e=>{const i=Nr(e)?Xr(this.config.components.yAxis.type,this.config.scale.zoomSensitivity.pinch):this.config.scale.zoomSensitivity.wheel;this.zoomXHandler(e,i)})),this.addRxSubscription(this.canvasInputListener.observeScrollGesture().pipe(ve(this.wheelTrottleTime,me,{trailing:!0,leading:!0})).subscribe(e=>{let n=-1;const i=Yr();(i==="apple"||i==="mobile")&&(n=1);let r=0,o=0;if(r+=e.deltaX*n,o+=e.deltaY*-n,r!==0&&Math.abs(r)>Math.abs(o)){const a=Yt(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a)}else if(o!==0&&Math.abs(o)>Math.abs(r)){const a=Xr(this.config.components.yAxis.type,this.config.scale.zoomSensitivity.glide);this.zoomXHandler(e,a)}this.bus.fireDraw()})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e})),this.touchHandler.activate(),this.addSubscription(this.touchHandler.deactivate.bind(this.touchHandler))}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(bs),this.currentPoint={x:0,y:0},n=t.yStart},r=a=>{const{delta:l}=a;if(this.currentPoint.y=l,t.state.auto)Rd(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const c=Yt(t.state.inverse?-l:l,t.zoomY);t.moveYStart(n+c)}},o=new $e(e,{onDragTick:r,onDragStart:i},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});return this.addChildEntity(o),o}}const Rd=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Zs(Zs(Math.abs(s.x),2)+Zs(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle};class Fd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=n,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.chartPanComponents=[],this.chartAreaPanHandler=new Od(this.eventBus,this.config,this.mainScale,this.mainCanvasParent,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this),this.chartPanComponents.push(this.chartAreaPanHandler)}doActivate(){this.activateChartPanHandlers()}doDeactivate(){this.deactivatePanHandlers()}activateChartPanHandlers(){this.chartPanComponents.forEach(t=>t.activate())}deactivatePanHandlers(){this.chartPanComponents.forEach(t=>t.deactivate())}}const zr=s=>t=>{const{top:e,bottom:n}=s(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*n/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},Wr=(s,t)=>{const e=zr(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function Hd(){return En(1)}function Ur(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return Hd()(Re(s,Oe(s)))}function kd(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Oe(s);return N(function(n,i){(e?Ur(s,n,e):Ur(s,n)).subscribe(i)})}function Yd(s){return $(function(t,e){return s<=e})}class jd{constructor(t,e,n,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=n,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),n=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(n.fillStyle=i.getColor(0),n.fillRect(e.x,e.y-r,e.width,e.height+2*r)),n.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?n.fillRect(e.x,e.y,e.width,e.height):n.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Nd extends X{constructor(t,e,n,i,r,o,a,l,c,h,d){super(),this.id=t,this.boundsProvider=e,this.hitTest=n,this.dragTickCb=i,this.chartPanComponent=r,this.canvasModel=o,this.drawingManager=a,this.canvasInputListener=l,this.canvasAnimation=c,this.config=h,this.canvasBoundsContainer=d,this.initialY=0,this.resizeEvent$=new B,this.onYDragStart=()=>{this.config.components.crossTool.type="none",this.initialY=this.boundsProvider().y},this.onYDragEnd=()=>{this.config.components.crossTool.type="cross-and-labels",this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio)},this.onYDragTick=u=>{const{delta:g,draggedPixels:C}=u;Math.abs(this.initialY-this.boundsProvider().y+C)>=0&&(this.dragTickCb(g),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new $e(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent);this.addChildEntity(n),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(kd(!1),Et(),Yd(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new jd(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,hr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(hr.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const Xd=s=>t=>{let e;if(typeof t=="number")e=t;else if(typeof t=="string")e=Number(t);else return"\u2014";const[n]=s.dataSeries;if(n!==void 0){const i=It.getPricePrecision(e,n.pricePrecisions);return e.toFixed(i)}return`${e}`},zd=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=_i(t,r.getBaseline()));const o=i.toFixed(It.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Wd=s=>({percent:zd(s),regular:Xd(s)});class Ud extends X{constructor(t,e,n,i,r,o,a,l,c,h,d=new Set,u={regular:Di}){super(),this.paneUUID=t,this.idx=e,this.paneComponent=n,this.chartBaseModel=i,this.canvasBoundsContainer=r,this.hitTestController=o,this.dynamicObjectsCanvasModel=a,this.scale=l,this.dragNDrop=h,this.dataSeries=d,this.formatters=u,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(C=>new we(this.chartBaseModel.dataFromTimestamp(C.timestamp).centerUnit,C.close)),this.toY=g=>{var C,S;return(S=(C=this.mainDataSeries)==null?void 0:C.view.toY(g))!=null?S:1},this.valueFormatter=(g,C)=>{var S;return((S=this.formatters[this.yAxis.getAxisType()])!=null?S:this.formatters.regular)(g,C)},this.addChildEntity(l),this.setValueFormatters(Wd(this)),this.yAxis=c(this.valueFormatter.bind(this),()=>this.mainDataSeries),this.addChildEntity(this.yAxis)}doDeactivate(){super.doDeactivate(),this.dataSeries.forEach(t=>{this.paneComponent.seriesRemovedSubject.next(t),t.deactivate()})}getBounds(){return this.scale.getBounds()}getBaseline(){var t,e;return(e=(t=this.mainDataSeries)==null?void 0:t.getBaseline())!=null?e:1}createDataSeries(){const t=new Li(this,Ct(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){this.dataSeries.add(t),this.dataSeries.size===1&&(this.mainDataSeries=t),this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,n;return(n=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?n:this.scale.fromY(t)}}const Vr=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return Wi(e)}});class Vd{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Vs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Vs.DATA_SERIES}get allDataSeries(){return ge(ge(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(n=>n.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.hovered=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(n=>n.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Xt="#FF00FF";function Qf(s,t,e,n){const i=s.yAxis.backgroundColor,r=s.chartAreaTheme.backgroundColor,o=s.chartAreaTheme.backgroundGradientTopColor,a=s.chartAreaTheme.backgroundGradientBottomColor,l=n.align==="left"?o:a,c=s.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const Gd=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Zd=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:Xt},$d=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:Xt},Kd=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:Xt},qd=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Xt},Jd=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Xt},Qd=(s,t)=>{const e=t.histogram[`${s}Cap`];return e!=null?e:Xt},tu=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Xt},Gr=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:Xt},eu=()=>(console.warn("Fallback for label default color"),Xt);function su(s,t){if(s.filter(a=>a!==null).length<=1)return s.map(a=>a.y);const e=t-2,n=s.map((a,l)=>nu(a,l,e)).filter(jn).sort(iu),i=new Array(n.length),r=n.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=n.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=n[a],c=n[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<n.length;a++){const l=n[a],c=n[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const nu=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,iu=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var ru=Object.defineProperty,ou=Object.defineProperties,au=Object.getOwnPropertyDescriptors,Zr=Object.getOwnPropertySymbols,lu=Object.prototype.hasOwnProperty,cu=Object.prototype.propertyIsEnumerable,$r=(s,t,e)=>t in s?ru(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Kr=(s,t)=>{for(var e in t||(t={}))lu.call(t,e)&&$r(s,e,t[e]);if(Zr)for(var e of Zr(t))cu.call(t,e)&&$r(s,e,t[e]);return s},qr=(s,t)=>ou(s,au(t));const $s={MAIN:"MAIN"};class hu extends X{constructor(t,e,n,i,r,o,a){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.orderedLabels=[],this.customLabels={},this.labelsProviders={},this.labelsPositionRecalculatedSubject=new B,this.animFrameId=`anim_cache_${Ct()}`,this.initModel()}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),Ns(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const n=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=pt(Object.values(i).map(l=>l.getUnorderedLabels())),o=pt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=su(o,n);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,n){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][n]=t))}updateLabelsCoordinates(t,e){return qr(Kr({},t),{labels:t.labels.map((n,i)=>qr(Kr({},n),{lineY:n.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,n){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[n]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var n;const i=(n=this.labelsProviders[t])!=null?n:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}const Jr=10;class du extends X{constructor(t,e,n,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.autoScaleCallback=l,this.yAxisDragEndSubject=new B,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=this.bounds.getBounds(x.Y_AXIS).height},this.onYDragTick=c=>{const{delta:h}=c;let d;h<0?d=1/(1+-h/this.lastYPxHeight*(Jr-1)):d=1+h/this.lastYPxHeight*(Jr-1);const g=(this.lastYHeight*d-this.lastYHeight)/2,C=this.lastYStart-g,S=this.lastYEnd+g;this.autoScaleCallback(!1),(this.lastYStart!==C||this.lastYEnd!==S)&&(this.scale.setYScale(C,S),this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next()},e.customScale){const c=()=>e.type!=="percent"&&e.visible,h=new $e(a,{onDragTick:Ks(this.onYDragTick,c),onDragStart:Ks(this.onYDragStart,c),onDragEnd:Ks(this.onYDragEnd,c)},r,n,{disableChartPanning:!1});this.addChildEntity(h)}}doActivate(){this.config.customScaleDblClick&&this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.autoScaleCallback(!0),this.bus.fireDraw()}))}}const Ks=(s,t)=>(...e)=>t()&&s(...e);class uu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${Ct()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),cr(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const gu=0,fu=.01;class qs{constructor(t,e,n,i,r=!1,o,a,l=Cs,c=23){this.increment=t,this.startEndProvider=e,this.lengthProvider=n,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new B,this.newGeneratedLabelsSubject=new B,this.lastStart=0,this.lastEnd=0,this.labelsCache=new uu(()=>this.labelFilter(this.doGenerateLabels()))}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=ht.roundToNearest(t,n);for(;r<e;){const o=ht.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=ht.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=ht.roundToNearest(t,n);for(;o<e;){const a=ht.roundToNearest(o,n),l=Pi(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=ht.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=ht.roundToNearest(t,n);for(;r<e;){const o=Os(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=ht.roundDecimal(r+n)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[n,i]=this.calculateMinMax(),r=this.getAxisStep(n,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(n,i,r):a==="percent"?o=this.generatePercentLabels(n,i,r):o=this.generateRegularLabels(n,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),n=this.lengthProvider(),i=qs.getLabelBounds(t,e,n);return[i[0],i[1]]}getAxisStep(t,e,n){const i=e-t,r=n/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){if(this.increment)return this.increment;if(!isNaN(t)){const e=It.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(e)}return this.adjustIncrementOnAxisType(fu)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Os(e)+t;return Ti(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,n){const i=Math.abs((e-t)*(gu/n));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let n=e,i=e,r=0;for(;n<t&&n>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),n=i*this.gridDistanceMultipliers[r++];return n}}class pu extends qs{constructor(t,e,n,i,r=()=>"regular",o=23){super(t,()=>[n.yStart,n.yEnd],()=>n.getBounds().height,i,!1,r,()=>{var a,l;return(l=(a=e())==null?void 0:a.getBaseline())!=null?l:1},void 0,o),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,n)=>n.text.length>e.length?n.text:e,"")}calculateIncrement(t){var e;const n=this.dataSeriesProvider();if(n){const i=wt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=Ql(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function Qr(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?N(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(xt(r,function(l){var c;(c=n.next)===null||c===void 0||c.call(n,l),r.next(l)},function(){var l;a=!1,(l=n.complete)===null||l===void 0||l.call(n),r.complete()},function(l){var c;a=!1,(c=n.error)===null||c===void 0||c.call(n,l),r.error(l)},function(){var l,c;a&&((l=n.unsubscribe)===null||l===void 0||l.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):ie}class mu extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=n,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${Ct()}`}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ct(t=>t.height),$(t=>ga(t,this.prevYAxisHeight,1.5)),Qr(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),Ns(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class vu extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new pu(null,l,o,a,()=>this.state.type,n.labelHeight),this.baseLabelsModel=new mu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new hu(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths()),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(n=>n.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(n=>n.labels).map(n=>n.labelText)).reduce((n,i)=>i.length>n.length?i:n,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class bu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasBoundsContainer=o,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new B,this.state=Ce(e.components.yAxis),this.yAxisScaleHandler=new du(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),g=>i.autoScale(g)),this.addChildEntity(this.yAxisScaleHandler),this.model=new vu(this.paneUUID,t,this.state,o,n,i,c,h,u),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Kd),this.registerLabelColorResolver("bar",Zd),this.registerLabelColorResolver("line",$d),this.registerLabelColorResolver("area",qd),this.registerLabelColorResolver("scatterPlot",Jd),this.registerLabelColorResolver("histogram",Qd),this.registerLabelColorResolver("baseline",tu),this.registerLabelColorResolver("trend",Gr),this.registerLabelColorResolver("hollow",Gr)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:eu}registerYAxisLabelsProvider(t,e=$s.MAIN,n=Ct()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,n),n}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=$s.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.enable():this.disable(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t){this.scale.state.inverse=t,this.scale.inverseY=t,this.scale.scaleInversedSubject.next(t)}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Cu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,C,S,_,M,I){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=n,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=g,this.canvasBoundsContainer=C,this.uuid=S,this.seriesAddedSubject=_,this.seriesRemovedSubject=M,this._paneOrder=0,this.yExtentComponents=[],this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(j,R)=>this.mainExtent.valueFormatter(j,R);const F=this.createExtentComponent(I);this.mainExtent=F,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(S),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return ge(this.yExtentComponents,t=>Array.from(t.dataSeries))}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.uuid)).pipe(Et(hi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,n;return(n=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?n:this.scale.toY(t)}createGridComponent(t,e,n,i){const r=x.PANE_UUID(t);return new Br(this.mainCanvasModel,e,this.config,i,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(r),()=>this.canvasBoundsContainer.getBounds(r),()=>[],()=>n.generateNumericLabels())}createYPanHandler(t,e){const n=x.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(n));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const n=x.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(n,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(n)}createExtentComponent(t){var e,n;const i=this.yExtentComponents.length,r=x.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new Dc(this.mainScale,this.config,o,this.canvasAnimation),[l,c]=this.createYPanHandler(this.uuid,a),h=(C,S)=>new bu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,C,S,this.uuid,i),d=new Ud(this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,h,c);d.addSubscription(l),d.addSubscription(this.addCursors(i,d.yAxis)),t!=null&&t.paneFormatters&&d.setValueFormatters(t.paneFormatters),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",Wr(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),Vr(d)));const g=this.createGridComponent(this.uuid,a,d.yAxis.model.labelsGenerator,d.yAxis.state);return d.addChildEntity(g),d.activate(),this.yExtentComponents.push(d),this.canvasBoundsContainer.updateYAxisWidths(),d}removeExtentComponent(t){t.disable(),this.yExtentComponents.splice(t.idx,1),this.yExtentComponents.forEach((e,n)=>e.idx=n),this.canvasBoundsContainer.updateYAxisWidths()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(n=>n.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}hide(){this._paneOrder=this.canvasBoundsContainer.panesOrder.indexOf(this.uuid),this.canvasBoundsContainer.removedPaneBounds(this.uuid),this.eventBus.fireDraw()}show(){this.canvasBoundsContainer.addPaneBounds(this.uuid,this._paneOrder),this.eventBus.fireDraw()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=fe(this.canvasBoundsContainer.panesOrder);return this.uuid!==t}canMoveDown(){const t=wt(this.canvasBoundsContainer.panesOrder);return this.uuid!==t}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}class wu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,C,S){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=n,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=g,this.mainCanvasModel=C,this.yAxisLabelsCanvasModel=S,this.panes={},this.paneRemovedSubject=new B,this.paneAddedSubject=new B,this.dataSeriesAddedSubject=new B,this.dataSeriesRemovedSubject=new B,this.hitTestController=new Vd(this.panes,this.dynamicObjectsCanvasModel);const _=this.createPane(q,{useDefaultHighLow:!1,scale:this.mainScale});_.mainExtent.scale.autoScaleModel.setHighLowProvider("series",Vr(_.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",zr(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removedPaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone}),n=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},i=x.PANE_UUID_RESIZER(t),r=new Nd(i,()=>this.canvasBoundsContainer.getBounds(i),e,n,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer);return this.userInputListenerComponents.push(r),r}get yExtents(){return ge(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(n=>this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(n.uuid))(t.x,t.y))}createPane(t=Ct(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new Cu(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,e);return this.config.components.paneResizer.visible&&n.addChildEntity(this.addResizer(t)),n.addSubscription(this.addBounds(t,e==null?void 0:e.order)),n.addSubscription(this.addCursors(t)),n.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,n.ht)),this.panes[t]=n,n.activate(),this.recalculateState(),n.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),n}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(n=>n.disable()),delete this.panes[t],this.recalculateState())}addCursors(t,e=this.config.components.chart.cursor){const n=x.PANE_UUID(t),i=x.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(n,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone),()=>{this.cursorHandler.removeCursorForCanvasEl(n),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class yu extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,n=this.canvasModel.ctx;if(n){n.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return n.drawImage(this.elements.backgroundCanvas,0,0,i,r),n.drawImage(this.elements.mainCanvas,0,0,i,r),n.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),n.drawImage(this.elements.crossToolCanvas,0,0,i,r),n.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(n),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const Su=(s,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function n(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return n(s)},es=class extends X{constructor(s,t,e,n,i){super(),this.chartComponent=s,this.drawingManager=t,this.config=e,this.volumesModel=n,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var s,t;return!((s=this.pane)!=null&&s.scale.isViewportValid())&&((t=this.pane)==null?void 0:t.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var s;return(s=this.pane)==null?void 0:s.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[es.UUID]===void 0){const t=this.paneManager.createPane(es.UUID,{paneFormatters:{regular:i=>Su(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=Wr(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);e.autoScaleModel.setHighLowProvider("volumes",n),e.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(es.UUID),delete this.pane,this.drawingManager.removeDrawerByName("UNDERLAY_VOLUMES_AREA")}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let to=es;to.UUID="volumes";const ss=.3,xu=(s,t)=>{const e=t.barTheme[`${s}Color`];return At()(e).alpha(ss).toString()},_u=(s,t)=>{const e=t.volume[`${s}BarColor`];return At()(e).alpha(ss).toString()},Pu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return At()(e).alpha(ss).toString()},Js=(s,t)=>{const e=t.candleTheme[`${s}Color`];return At()(e).alpha(ss).toString()},Tu=3;class Mu{constructor(t,e,n,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=n,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const n=(e=this.volumesColorByChartTypeMap[t])!=null?e:_u;this.volumeBarColors.down=n("down",this.config.colors),this.volumeBarColors.up=n("up",this.config.colors),this.volumeBarColors.none=n("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const n=this.getViewportModel().getBounds();Ut(e,n),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const n=pt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();n.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=n[o+1]!==void 0?V(i.toX(n[o+1].startUnit)):void 0,h=V(i.toX(r.startUnit)),d=c!==void 0?c-h:V(dt(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=V(i.toY(r.candle.volume)),g=V(i.toY(0))-u;this.drawVolume(t,r,h,u,d,g)}else{const u=e/(l/Tu),g=Math.max(dt(r.candle.volume,u),2),C=V(a.y+l-g);this.drawVolume(t,r,h,C,d,g)}}})}drawVolume(t,e,n,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(n,l),a.lineTo(n,Ci(c)),a.stroke()):a.fillRect(n,i,r,Ci(o))}}const Au=Fa(s=>s.candle.volume),eo="volumes";class Eu extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=eo,this.volumeMax=new _t(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;this.volumeMax.next((t=fe(Au(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class Lu extends X{constructor(t,e,n,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new _t(!1),this.volumeIsSeparateModeChangedSubject=new _t(!1);const c=new Eu(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new to(e,r,o,c,a),this.volumesDrawer=new Mu(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:n},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.addVolumesToDynamicObjects(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",Js),this.registerVolumeColorResolver("trend",Js),this.registerVolumeColorResolver("hollow",Js),this.registerVolumeColorResolver("line",Pu),this.registerVolumeColorResolver("bar",xu)}setShowVolumesSeparatly(t){this.config.components.volumes.showSeparately!==t&&(this.config.components.volumes.showSeparately=t,t?this.separateVolumes.activateSeparateVolumes():this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(t))}doDeactivate(){super.doDeactivate(),this.setVisible(!1)}registerVolumeColorResolver(t,e){this.volumesColorByChartTypeMap[t]=e}setVisible(t=!0){this.config.components.volumes.visible=t,this.volumeVisibilityChangedSubject.next(t),t?this.addVolumesToDynamicObjects():this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.canvasModel.fireDraw()}addVolumesToDynamicObjects(){this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1&&this.dynamicObjectsComponent.model.addObject({id:this.volumesModel.id,paneId:this.config.components.volumes.showSeparately?eo:q,drawer:this.volumesDrawer,model:this.volumesModel})}}class Du{constructor(t,e,n,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=n,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,g=this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)),{position:C,offsetY:S,offsetX:_}=this.config.components.waterMark;let M;switch(d?M=d:(u.font=ns(this.config,l),M=u.measureText(a).width,g.width-10<M&&(u.font=Iu(this.config,this.canvasBoundsContainer,l,M),M=u.measureText(a).width)),C){case"left-top":return{x:_+g.x,y:S+o+g.y,font:u.font,text:a,color:c};case"left-bottom":return{x:_+g.x,y:g.height-h-S+o+g.y,font:u.font,text:a,color:c};case"center":return{x:g.width/2-M/2+g.x,y:(g.height-h)/2+o+g.y,font:u.font,text:a,color:c}}}}draw(){var t,e,n,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,g=this.canvasModel.ctx;let C=0,S=0,_=0,M=0,I=0;if(g.save(),d.firstRowFontSize&&l){g.font=ns(this.config,d.firstRowFontSize);const H=g.measureText(l);C=H.actualBoundingBoxAscent+H.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){g.font=ns(this.config,d.secondRowFontSize);const H=g.measureText(c);S=H.actualBoundingBoxAscent+H.actualBoundingBoxDescent,_=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){g.font=ns(this.config,d.thirdRowFontSize);const H=g.measureText(h);M=H.actualBoundingBoxAscent+H.actualBoundingBoxDescent,I=(n=d.secondRowBottomPadding)!=null?n:0}const F=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,R=C+S+_+M+I+F+j;if(l&&this.drawWaterMark(this.getConfig(C,l,d.firstRowFontSize,u.firstRowColor,R)),c&&this.drawWaterMark(this.getConfig(C+_+S,c,d.secondRowFontSize,u.secondRowColor,R)),h&&this.drawWaterMark(this.getConfig(C+_+S+I+M,h,d.thirdRowFontSize,u.thirdRowColor,R)),this.logoImage){const H=this.getConfig(C+_+S+I+M+F,"",d.thirdRowFontSize,u.thirdRowColor,R,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,H.x,H.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}g.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const n=this.canvasModel.ctx;n.font=t.font,n.fillStyle=t.color;const i=t.x,r=t.y;n.fillText(e,i,r)}reset(){}}const Iu=(s,t,e,n)=>{const r=((a,l)=>t.getBounds(x.CHART).width/l*a)(e,n);let o;return s.components&&s.components.waterMark&&(o=s.components.waterMark.fontFamily),r+"px "+o},ns=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Bu=Object.defineProperty,so=Object.getOwnPropertySymbols,Ou=Object.prototype.hasOwnProperty,Ru=Object.prototype.propertyIsEnumerable,no=(s,t,e)=>t in s?Bu(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,io=(s,t)=>{for(var e in t||(t={}))Ou.call(t,e)&&no(s,e,t[e]);if(so)for(var e of so(t))Ru.call(t,e)&&no(s,e,t[e]);return s};class Fu extends X{constructor(t,e,n,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=n,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new Du(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Lt(r.observeBoundsChanged(x.PANE_UUID(q)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Lt(e,t),Lt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return io(io({},this.config.components.waterMark),h)}}const ro={x:4,y:4};function Hu(s,t,e,n){var i,r;const o=(i=n.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(x.X_AXIS);s.save(),s.font=`bold ${a}px ${l}`;const C=s.measureText(n.text).width+ro.x*2;let S=0;const _=n.x;switch(o){case"start":S=_-C;break;case"end":S=_;break;case"middle":default:S=_-C/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(S,u.y,C,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(_,u.y),s.lineTo(_,u.y+u.height),s.stroke()),s.fillStyle=n.color;const M=S+ro.x,I=u.y+d+a;s.fillText(n.text,M,I),s.restore()}class ku{constructor(t,e,n,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=n,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Hu(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},n=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(n).forEach(i=>{const r=n[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.fillStyle=At().rgb(r[0].color).alpha(.1).toString(),tr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const tp="week-weekday",Yu=["second","minute","hour","day","month","year"],ju=["lessThanSecond"],Nu=s=>Yu.some(t=>t===s),Xu=s=>s==="week-weekday",zu=s=>ju.some(t=>t===s),oo=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},Qs=s=>parseInt(s,10),ao=s=>{const[t,...e]=s.split("_");if(Nu(t)){const[n]=e,i=oo(n),r=Qs(n);return{key:t,value:r,exact:i["!"]}}else if(Xu(t)){const[n,i]=e,r=oo(n),o=Qs(n),a=Qs(i);return{key:t,week:r.$?"$":o,weekday:a}}else return zu(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats https://webdev.prosp.devexperts.com:8095/docs/chart/x-axis`),null)};class is{constructor(t,e,n,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=n,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,n=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=is.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a),e.restore()}}drawLabels(t,e,n,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-yt(c.text,t,l)/2,d=n.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const tn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},lo=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return tn[s.key]+s.value;case"lessThanSecond":return tn[s.key];case"week-weekday":return tn[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},co=s=>{const t={};for(const e of s){const n=t[e.weight];n===void 0?t[e.weight]=[e]:n.push(e)}return t},Wu=(s,t)=>{const e=Object.keys(s).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let n=[];for(const i of e){const r=s[i];if(!r)continue;const o=[...n];n=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const g=r[u],C=g.idx;for(;c<a;){const S=o[c],_=S.idx;if(C>_)c++,n.push(S),d=_,h=1/0;else{h=_;break}}h-C>=t&&C-d>=t&&(n.push(g),d=C)}for(;c<a;)n.push(o[c]),c++}return n},Uu=(s,t,e,n,i,r)=>{const o=is.getFontFromConfig(t),a=yt(e.text,s,o),l=yt(n.text,s,o),c=i.toX(e.value)+a/2;return i.toX(n.value)-l/2-c<r};function en(s){"@babel/helpers - typeof";return en=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},en(s)}function mt(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function vt(s){mt(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||en(s)==="object"&&t==="[object Date]"?new Date(s.getTime()):typeof s=="number"||t==="[object Number]"?new Date(s):((typeof s=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Vu(s){return mt(1,arguments),vt(s).getDay()===1}function Gu(s){return mt(1,arguments),vt(s).getDay()===2}function Zu(s){return mt(1,arguments),vt(s).getDay()===3}function $u(s){return mt(1,arguments),vt(s).getDay()===4}function Ku(s){return mt(1,arguments),vt(s).getDay()===5}function qu(s){return mt(1,arguments),vt(s).getDay()===6}function Ju(s){return mt(1,arguments),vt(s).getDay()===0}function Qu(s,t){var e;mt(1,arguments);var n=s||{},i=vt(n.start),r=vt(n.end),o=r.getTime();if(!(i.getTime()<=o))throw new RangeError("Invalid interval");var a=[],l=i;l.setHours(0,0,0,0);var c=Number((e=t==null?void 0:t.step)!==null&&e!==void 0?e:1);if(c<1||isNaN(c))throw new RangeError("`options.step` must be a number greater than 1");for(;l.getTime()<=o;)a.push(vt(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function tg(s){mt(1,arguments);var t=vt(s);return t.setDate(1),t.setHours(0,0,0,0),t}function eg(s){mt(1,arguments);var t=vt(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function ho(s){mt(1,arguments);var t=vt(s);return t.setHours(0,0,0,0),t}function uo(s,t){mt(2,arguments);var e=ho(s),n=ho(t);return e.getTime()===n.getTime()}const sg=s=>{switch(s.key){case"lessThanSecond":return og(s);case"month":return ag(s);case"second":case"minute":case"hour":case"day":case"year":return lg(s);case"week-weekday":return cg(s);default:return()=>!1}},Gt=(s,t)=>{switch(t){case"lessThanSecond":return s.getMilliseconds();case"month":return s.getMonth();case"second":return s.getSeconds();case"minute":return s.getMinutes();case"hour":return s.getHours();case"day":return s.getDate();case"year":return s.getFullYear();case"week-weekday":return s.getDate()}},sn=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n!==i},ng=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n>=i},ig={1:Vu,2:Gu,3:Zu,4:$u,5:Ku,6:qu,7:Ju},rg=(s,t,e)=>{var n;const i=Qu({start:tg(s),end:eg(s)}),r=(n=ig[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return uo(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return uo(s,a);o++}}return!1},go=(s,t)=>t===1?s===1:s/t===1,fo=(s,t)=>t===1?!0:s%t===0,og=s=>(t,e)=>ng(s.key)(t,e),ag=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?go(Gt(t,s.key)+1,s.value):fo(Gt(t,s.key)+1,s.value);return n&&i},lg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?go(Gt(t,s.key),s.value):fo(Gt(t,s.key),s.value);return n&&i},cg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=rg(t,s.week,s.weekday);return n&&i},hg=s=>{switch(s.key){case"second":case"minute":return dg(s.value);case"hour":return ug(s.value);case"day":return gg(s.value);case"month":return mg(s.value);case"year":return vg(s.value);case"week-weekday":const t=pg(s.week),e=fg(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},dg=s=>s>0&&s<=60,ug=s=>s>0&&s<=24,gg=s=>s>0&&s<=31,fg=s=>po(s)?s>=1&&s<=7:!1,pg=s=>s==="$"?!0:po(s)?s>=1&&s<=6:!1,mg=s=>s>0&&s<=12,vg=s=>s>0,po=s=>!isNaN(s)&&isFinite(s),bg=(s,t,e)=>{var n,i;for(const[r,o]of e)if(o(s,t))return r;return(i=(n=e[e.length-1])==null?void 0:n[0])!=null?i:0};function nn(s,t,e){const n=new Array(s.length);let i=e(0);for(let r=0;r<s.length;r++){const o=s[r],a=e(o.candle.timestamp),l={weight:bg(a,i,t)};n[r]=l,i=a}return n}const mo=s=>{const t={},e={};return Is(s).forEach(([n,i])=>{const r=ao(n),o=r===null?!1:hg(r);if(r&&o){const a=lo(r);t[a]=i,e[a]=sg(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class vo{constructor(t,e,n,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=n,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?dt(d,h.animationConfig.targetZoomX):dt(d,this.scale.zoomX);if(!isFinite(u))return-1;const g=this.config.components.xAxis.fontSize,C=Object.values(this.formatsByWeightMap).reduce((_,M)=>Math.max(M.length,_),1),S=g*C;return Math.round(S/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=mo(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(x.X_AXIS),n=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||n.push(i)}return n}getLabelsFromChartType(){var t,e;const n=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(n):n}getAllCandlesWithFake(){const t=this.chartModel.mainCandleSeries.visualPoints;if(t.length===0)return[];const n=Array.from({length:750}).map((i,r)=>Ii(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,t.length+r,this.chartModel.getPeriod()));return[...t,...n]}mapWeightedPointsToLabels(t,e){var n;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(n=a.candle.idx)!=null?n:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:n}=mo(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(n).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateWeightedLabels()}generateWeightedLabels(){const t=this.getAllCandlesWithFake(),e=nn(t,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),n=this.mapWeightedPointsToLabels(e,t);this.labelsGroupedByWeight=co(n),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=nn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(g=>g.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),n=nn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=co(i),o=Ce(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),g=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&g.shift(),g){const C=g.map(S=>(S.idx=S.idx+t.length,S.value=a.startUnit+a.width+S.value,S));r[u]?c[h]=d.concat(C):c[h]=C}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(){this.generateWeightedLabels()}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const n=Wu(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=n,this.weightedCache={labels:n,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,n;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Uu(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((n=a.weight)!=null?n:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const n=Is(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=ao(o);if(l){const c=lo(l);i[c]=a}}return i},{});return Is(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class Cg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(Ve,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}class wg extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.lastXStart=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const a=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=a.width-this.canvasInputListener.currentPoint.x},this.onXDragTick=a=>{const{delta:l}=a,c=this.lastXPxWidth-l;if(c<0)return;const h=this.lastXPxWidth/c,d=this.lastXWidth*h,u=this.lastXStart+(this.lastXWidth-d);this.scale.setXScale(u,this.scale.xEnd)};const o=new Te(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS),{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});this.addChildEntity(o)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS)).subscribe(()=>this.chartModel.doBasicScale())),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class yg extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h;const g=new vo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=g,this.xAxisLabelsModel=new Cg(t,[]);const C=new Ws;c.addDrawer(C,"X_AXIS"),this.xAxisDrawer=new is(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),C.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new ku(e,n,o,this.xAxisLabelsModel),C.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new wg(r,a,o,d,this.chartComponent.chartModel),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe($(({prependedCandles:t})=>t.length!==0),ct(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;Za.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(ft(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(ve(50,me,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ct(()=>wt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),Et((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.timestamp)===((i=e==null?void 0:e.candle)==null?void 0:i.timestamp)}),$(jn)).subscribe(t=>{var e,n;return(n=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:n.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof vo?this.xAxisLabelsGenerator.setFormatsForLabelsConfig(t):console.error("Format config for x-axis is not available")}isVisible(){var t,e;return(e=(t=this.config.components)==null?void 0:t.xAxis.visible)!=null?e:!1}}var Sg=Object.defineProperty,bo=Object.getOwnPropertySymbols,xg=Object.prototype.hasOwnProperty,_g=Object.prototype.propertyIsEnumerable,Co=(s,t,e)=>t in s?Sg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,rs=(s,t)=>{for(var e in t||(t={}))xg.call(t,e)&&Co(s,e,t[e]);if(bo)for(var e of bo(t))_g.call(t,e)&&Co(s,e,t[e]);return s};class Pg{constructor(t,e,n,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=n,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const n=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=n&&rs(rs({},n),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&rs(rs({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=wt(t.dataPoints);if(e){const n=t.view.toY(e.close);if(isFinite(n)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:n,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const n=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:qt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const c=Gd(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,c,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,r,o),rounded:!0}}}class Tg{constructor(t,e,n,i,r){this.yAxisLabelsCanvasModel=t,this.backgroundCanvasModel=e,this.canvasBoundsContainer=n,this.fullConfig=i,this.paneManager=r}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx;this.paneManager.yExtents.forEach(n=>{if(n.yAxis.state.visible){const i=n.getYAxisBounds(),r=this.canvasBoundsContainer.getBounds(x.ALL_PANES),o=n.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(o),o.forEach(a=>{var l;const c=(l=a.bounds)!=null?l:i;a.labels.forEach(h=>Pr(t,e,c,r,h,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}),Object.values(n.yAxis.model.fancyLabelsModel.customLabels).forEach(a=>Pr(t,e,i,r,a,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,n={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=n[r.subGroupId])!=null?o:[];if(n[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(q));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];tr(e,{x:h.x,y:ci(d,h)},{x:h.x+h.width-6,y:ci(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class Mg{constructor(t,e,n){this.fullConfig=t,this.canvasModel=e,this.paneManager=n}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const n=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height);const o=Jt(e.state),a=Ht(o,r),l=this.getLabelTextColor();r.save(),Ut(r,i),this.drawLabels(r,n,i,a,o,l,e),r.restore()}})}drawLabels(t,e,n,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=n.y+c,d=n.y+n.height-c;e.forEach(u=>{const g=a.scale.toY(u.value);g>h&&g<d&&Ag(t,n,u.text,g,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const Ag=(s,t,e,n,i,r,o,a)=>{const l=a==="right"?t.x+t.width-yt(e,s,r)-o:t.x+o;s.fillText(e,l,n+i/2-1)};class Eg{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Oa.call(n,e)},this.add=(t,e,n)=>(e in this.handlers?t.call(this.handlers[e],n):this.handlers[e]=[n],this.unsub.bind(this,e,n)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new B,n=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,n),e.unsubscribe=()=>{this.unsub(t,n),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var n;if(!this.muted){const i=(n=this.handlers[t])!=null?n:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(Ve,t)}}class Lg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ct(r=>i.components.chart.highlightActiveCandle?r:void 0),Et()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,n){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=n.candleFromX(r);o&&n.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const n=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-n.left-i}}class Dg{constructor(t,e,n,i,r){this.frameElement=t,this.resizerElement=e,this.bus=n,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${Ct()}`,this.canvasResized=new B,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){Ns(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.canvasModels.forEach(n=>this.previousBCR&&n.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(Fs,e),this.bus.fire(Ve))}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.previousBCR!==void 0}}var Ig=Array.isArray,Bg=Object.getPrototypeOf,Og=Object.prototype,Rg=Object.keys;function Fg(s){if(s.length===1){var t=s[0];if(Ig(t))return{args:t,keys:null};if(Hg(t)){var e=Rg(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function Hg(s){return s&&typeof s=="object"&&Bg(s)===Og}var kg=Array.isArray;function Yg(s,t){return kg(t)?s.apply(void 0,L([],p(t))):s(t)}function jg(s){return ct(function(t){return Yg(s,t)})}function Ng(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Xg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Oe(s),n=ea(s),i=Fg(s),r=i.args,o=i.keys;if(r.length===0)return Re([],e);var a=new gt(zg(r,e,o?function(l){return Ng(o,l)}:ie));return n?a.pipe(jg(n)):a}function zg(s,t,e){return e===void 0&&(e=ie),function(n){wo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){wo(t,function(){var d=Re(s[h],t),u=!1;d.subscribe(xt(n,function(g){r[h]=g,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function wo(s,t,e){s?Ft(e,s,t):t()}class Wg extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new _t(null)}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,n){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,n)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const n=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Xg([n,i]).pipe($(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}else this.crossSubject.next(null),r=!0});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}class Ug{constructor(t,e,n,i){this.visualCandle=t,this.price=e,this.priceFormatter=n,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class Vg{constructor(t){this.chartModel=t}getData(t){const{x:e,y:n}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(n);return o&&new Ug(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Gg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof mr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Zg=Object.defineProperty,$g=Object.defineProperties,Kg=Object.getOwnPropertyDescriptors,yo=Object.getOwnPropertySymbols,qg=Object.prototype.hasOwnProperty,Jg=Object.prototype.propertyIsEnumerable,So=(s,t,e)=>t in s?Zg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Me=(s,t)=>{for(var e in t||(t={}))qg.call(t,e)&&So(s,e,t[e]);if(yo)for(var e of yo(t))Jg.call(t,e)&&So(s,e,t[e]);return s},rn=(s,t)=>$g(s,Kg(t));class Qg extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.crossEventProducer=t,this.scale=e,this.config=n,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.formatterFactory=c,this.hoverSubject=new _t(null),this.longTouchActivatedSubject=new _t(!1),this.xFormatter=()=>"";const h=new Vg(this.chartModel),d=new Gg(this.chartModel);this.hoverProducerParts={candleHover:h,compareSeriesHover:d}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp===this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{const n=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,i=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.chartModel.candleFromX(n,!0)&&this.createAndFireHover([n,i,""])}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{this.paneManager.chartPanComponent.deactivatePanHandlers(),this.longTouchActivatedSubject.next(!0);const n=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,i=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.createAndFireHover([n,i,""]),this.crossEventProducer.crossSubject.next([n,i,""])})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(()=>{this.paneManager.chartPanComponent.activateChartPanHandlers(),this.longTouchActivatedSubject.getValue()&&(this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose())})),this.addRxSubscription(ft(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter()))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=Mr(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),n=this.scale.toY(t.close);return this.createHover(e,n,q)}createHover(t,e,n){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:n},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>rn(Me({},l),{[c[0]]:c[1].getData(o)}),{});return Me(Me({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const n=rn(Me({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(n)}}createAndFireHover([t,e,n]){const i=this.createHover(t,e,n);this.fireHover(i)}fireHover(t){var e;if(t){if(xs()&&this.config.components.crossTool.type!=="none"){const n=(e=t.candleHover)==null?void 0:e.visualCandle.candle;n&&this.chartModel.mainCandleSeries.setActiveCandle(n)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=rn(Me({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const xo={left:0,middle:1,right:2};function ut(s,t,e,n){return s.addEventListener(e,t,n),function(){s.removeEventListener(e,t,n)}}function he(s){return t=>{t.button===xo.left&&s(t)}}var tf=Object.defineProperty,_o=Object.getOwnPropertySymbols,ef=Object.prototype.hasOwnProperty,sf=Object.prototype.propertyIsEnumerable,Po=(s,t,e)=>t in s?tf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,nf=(s,t)=>{for(var e in t||(t={}))ef.call(t,e)&&Po(s,e,t[e]);if(_o)for(var e of _o(t))sf.call(t,e)&&Po(s,e,t[e]);return s};const ee=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new B,this.xDragSubject=new B,this.xDragTickSubject=new B,this.xDragEndSubject=new B,this.yDragStartSubject=new B,this.yDragSubject=new B,this.yDragTickSubject=new B,this.yDragEndSubject=new B,this.mouseMoveSubject=new B,this.mouseMoveDocumentSubject=new B,this.clickSubject=new B,this.clickDocumentSubject=new B,this.dbClickSubject=new B,this.dbTapSubject=new B,this.mouseDownSubject=new B,this.mouseUpSubject=new B,this.mouseUpDocumentSubject=new B,this.wheelSubject=new B,this.touchStartSubject=new B,this.touchStartTimestamp=0,this.touchMoveSubject=new B,this.touchEndSubject=new B,this.touchCancelSubject=new B,this.longTouchStartSubject=new B,this.longTouchEndSubject=new B,this.contextMenuSubject=new B,this.pinchSubject=new B,this.scrollGestureSubject=new B,this.fastTouchScroll=new B,this.mouseLeavesCanvasSubject=new B,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=e=>{this.isDraggable(e)&&(this.updateCurrentPoints(e),this.dragging=!0,this.dragStartEvent=e,this.documentDragListeners.forEach(n=>n()),this.dragStartPoint=ee.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=nf({},this.dragStartPoint),ee.DRAG_EVENTS.forEach(n=>{document.addEventListener(n,this.dragProcessListener,!0);const i=document.removeEventListener.bind(document,n,this.dragProcessListener,!0);this.documentDragListeners.push(i),this.addSubscription(i)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.documentDragListeners.forEach(e=>e()),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=e=>{this.updateCurrentDocumentPoint(e),this.updateCurrentMousePoint(e)}}isDraggable(s){return s instanceof MouseEvent?s.button===xo.left:s instanceof TouchEvent}startDragging(s){this.updateCurrentPoints(s),this.dragStartListener(s)}movePointer(s){this.updateCurrentPoints(s),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const s=t=>(t.preventDefault(),!1);this.element.addEventListener("selectstart",s,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",s,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],ee.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),ee.DRAG_EVENTS.forEach(e=>{document.addEventListener(e,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragListener)),this.element.addEventListener(e,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,e,this.updateElementOffsetListener))}),ee.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(ut(this.element,he(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(ut(document,he(e=>this.clickDocumentSubject.next(e)),"click"));const s=Yr();if(s==="apple"||s==="mobile"){let e=null;const n=o=>{o.preventDefault(),e?(this.dbTapSubject.next(this.currentPoint),clearTimeout(e),e=null):e=window.setTimeout(()=>{e=null},250)};this.addSubscription(ut(this.element,n,"touchend"));const i=(o,a=700,l=3)=>{o.preventDefault();const c={x:o.touches[0].clientX,y:o.touches[0].clientY};let h={x:0,y:0},d=!1,u=null;u=setTimeout(()=>{d=!0,this.longTouchStartSubject.next(o)},a);const g=S=>{S.preventDefault(),h={x:S.touches[0].clientX,y:S.touches[0].clientY},(Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2))>l||S.touches.length>1)&&u&&clearTimeout(u)},C=S=>{S.preventDefault(),u&&clearTimeout(u),d&&(d=!1,this.longTouchEndSubject.next(S)),this.element.removeEventListener("touchend",C),this.element.removeEventListener("touchmove",g)};this.element.addEventListener("touchmove",g),this.element.addEventListener("touchend",C)};this.addSubscription(ut(this.element,o=>i(o),"touchstart"));const r=o=>{if(o.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const c=this.touchStartTimestamp,d=Date.now()-c,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,C=d<=250;g&&C&&this.fastTouchScroll.next(o)}};this.addSubscription(ut(this.element,r,"touchend"))}this.addSubscription(ut(this.element,he(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(ut(this.element,e=>{this.touchStartSubject.next(e),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(ut(this.element,e=>this.touchMoveSubject.next(e),"touchmove",!0)),this.addSubscription(ut(this.element,e=>this.touchEndSubject.next(e),"touchend")),this.addSubscription(ut(this.element,e=>this.touchCancelSubject.next(e),"touchcancel")),this.addSubscription(ut(this.element,e=>{e.ctrlKey?this.pinchSubject.next(e):Nr(e)?this.scrollGestureSubject.next(e):this.wheelSubject.next(e),e.preventDefault()},"wheel")),this.addSubscription(ut(this.element,e=>this.contextMenuSubject.next(e),"contextmenu")),this.addSubscription(ut(this.element,he(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(ut(this.element,he(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(ut(document,he(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(Fs).subscribe(()=>{const e=this.element.getBoundingClientRect();this.canvasBounds.x=e.left,this.canvasBounds.y=e.top,this.canvasBounds.width=e.width,this.canvasBounds.height=e.height}));const t=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",t,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){ee.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(s,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(s){"pageX"in s?this.currentPointDocument.x=s.pageX:s.touches!==void 0&&(this.currentPointDocument.x=s.touches[0].pageX),"pageY"in s?this.currentPointDocument.y=s.pageY:s.touches!==void 0&&(this.currentPointDocument.y=s.touches[0].pageY)}updateCurrentMousePoint(s){const t=this.element.getBoundingClientRect();"clientX"in s?this.currentPoint.x=s.clientX-t.left:s.touches!==void 0&&(this.currentPoint.x=s.touches[0].clientX-t.left),"clientY"in s?this.currentPoint.y=s.clientY-t.top:s.touches!==void 0&&(this.currentPoint.y=s.touches[0].clientY-t.top)}static copyPoint(s){return{x:s.x,y:s.y}}observeMouseMove(s=()=>!0){return this.mouseMoveSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe($(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe($(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ct(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe($(()=>!(t&&this.dragging)),ct(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ct(()=>!1));return ft(e,n).pipe(Et())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observePinch(s=()=>!0){return this.pinchSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeScrollGesture(){return this.scrollGestureSubject.asObservable()}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(s=()=>!0){return this.mouseDownSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)),Qr(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let os=ee;os.DRAG_START_EVENTS=["mousedown","touchstart"],os.DRAG_EVENTS=["mousemove","touchmove"],os.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var rf=function(s){z(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Es);var r=s.call(this)||this;return r._bufferSize=e,r._windowTime=n,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=n===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,n),r}return t.prototype.next=function(e){var n=this,i=n.isStopped,r=n._buffer,o=n._infiniteTimeWindow,a=n._timestampProvider,l=n._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),s.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),n},t.prototype._trimBuffer=function(){var e=this,n=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*n;if(n<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t}(B);const on={};function of(s){return on[s]||(on[s]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:s,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),on[s]}const To=(s,t=Date.now())=>{const n=of(s).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+)/.exec(n);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],0);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},Mo=60*1e3;class af{constructor(t){this.config=t,this.timeZoneChangedSubject=new rf,this.currentTzOffset=e=>To(this.config.timezone,e)+new Date(e).getTimezoneOffset()*Mo,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const n=t.createFormatterFunction;e=i=>n(i).bind(t)}else e=Uh(this.config,this.tzOffset);return e}getFormatterFactory(){return this.dateTimeFormatterFactory}getDateTimeFormatter(t){return this.formatterCache[t]===void 0&&(this.formatterCache[t]=this.dateTimeFormatterFactory(t)),this.formatterCache[t]}tzOffset(t){return t?e=>new Date(e+To(t,e)+new Date(e).getTimezoneOffset()*Mo):e=>new Date(e)}}class an{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;$a(r),this.config=r;const o=bl(r);t.innerHTML="",t.appendChild(o.content),this.id=(n=t.getAttribute("data-id"))!=null?n:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new af(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Cl(t);this.elements=c;const h=new Eg;this.bus=h;const d=new Dg(t,(i=c.chartResizer)!=null?i:t,h,this.canvasModels,r);this.chartResizeHandler=d,d.subscribeResize(),this.components.push(d.unsubscribeAnimationUpdate.bind(d));const u=new oh(h,d);this.drawingManager=u;const g=ih(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=g,this.dynamicObjectsCanvasModel=ce(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const C=new _e(this.dynamicObjectsCanvasModel);u.addDrawer(C,"SERIES_CLEAR");const S=ce(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),_=new As(r,h,g,l,d);this.canvasBoundsContainer=_;const M=c.mainCanvas.parentElement;if(M===null)throw new Error("Couldn't get main canvas parent");const I=new os(h,M);this.canvasInputListener=I,this.chartComponents.push(this.canvasInputListener);const F=new ed(h,c.hitTestCanvas,I,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=F;const j=new _e(F);u.addDrawer(j,"HIT_TEST_CLEAR");const R=new Pa(h);this.canvasAnimation=R;const H=x.PANE_UUID(q),Y=new Ji(r,()=>_.getBounds(H),R);this.scaleModel=Y;const Z=ce(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=Z,this.cursorHandler=new pl(c.canvasArea,I,_,F),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Wg(I,_),this.chartComponents.push(this.crossEventProducer);const K=new Wl("candle");this.chartBaseModel=K;const W=new Fd(h,Y,_,r,R,I,M,K);this.chartPanComponent=W,this.chartComponents.push(W),this.userInputListenerComponents.push(W.chartAreaPanHandler);const U=new wu(K,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,Y,_,r,R,I,u,this.cursorHandler,this.crossEventProducer,W,g,S);this.paneManager=U;const tt=this.paneManager.panes[q];this.mainPane=tt,this.chartComponents.push(U),this.dynamicObjects=new zh(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Ah(K,U,h,this.dynamicObjectsCanvasModel,r,Y,l,M,_,d);const J=new mh(this.chartModel,this.dynamicObjectsCanvasModel,r,Y,_,u,F,I,Z,W,U,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(J),this.chartComponent=J;const Q=this.chartComponent.chartModel;this.chartModel=Q,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),F.addSubscriber(U.hitTestController),this.xAxisComponent=new yg(h,r,g,J,Y,_,I,d,this.drawingManager,a,W,this.cursorHandler),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const et=new _e(g);u.addDrawer(et,"MAIN_CLEAR");const st=new Lg(M,Q,I,r);this.chartComponents.push(st),this.watermarkComponent=new Fu(U,Q,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ot=ce(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new wd(h,r,Q,g,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(Q)),this.navigationMapComponent=new Ed(h,Q,g,r,I,_,u,l,W,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const Tt=new gd(r,this.dynamicObjectsCanvasModel,Q,_,u);this.chartComponents.push(Tt),this.initYAxisDrawer(S),this.yAxisComponent=tt.mainExtent.yAxis;const St=new Pg(this.chartModel,this.config,tt.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(St,$s.MAIN),this.volumesComponent=new Lu(this.dynamicObjectsCanvasModel,J,Y,_,u,r,U,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const Bt=new Br(g,Y,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(H),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>this.yAxisComponent.model.baseLabelsModel.labels,()=>tt.mainExtent.toY(tt.mainExtent.getBaseline()),()=>r.components.grid.visible);this.chartComponents.push(Bt),this.hoverProducer=new Qg(this.crossEventProducer,Y,r,Q,I,this.canvasBoundsContainer,this.paneManager,a,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new Yh(r,ot,_,u,U,this.crossEventProducer,this.hoverProducer),this.chartComponents.push(this.crossToolComponent);const se=ce(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),Ae=new yu(this.elements,se);this.snapshotComponent=Ae,this.chartComponents.push(Ae);const ln=new hd(r,this.dynamicObjectsCanvasModel,F,Q,_,u,l,this.cursorHandler);this.eventsComponent=ln,this.chartComponents.push(ln),this.chartComponents.forEach(Io=>Io.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Aa(this.components)}initYAxisDrawer(t){const e=new Ws,n=new _e(t);e.addDrawer(n,"YAXIS_CLEAR"),this.drawingManager.addDrawer(e,"Y_AXIS");const i=new Mg(this.config,t,this.paneManager);e.addDrawer(i);const r=new Tg(t,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);e.addDrawer(r)}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&an.mergeConfig(t[n],e[n]):t[n]=e[n];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,n,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(n=t.dash)!=null?n:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){Lt(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(n).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,n=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,n).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(n).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=ft(this.canvasInputListener.observeYDrag(n),this.canvasInputListener.observeXDrag(n)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const n=t(this);this.components.push(n),e&&e(n),n.activate()}}class Ao extends an{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var n;(n=this.paneManager.panes[t])==null||n.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.setAllSeries(e,n)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.updateAllSeries(e,n)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.chartComponent.setChartType(t)}createPane(){return this.paneManager.createPane()}}var lf=Object.defineProperty,cf=Object.defineProperties,hf=Object.getOwnPropertyDescriptors,Eo=Object.getOwnPropertySymbols,df=Object.prototype.hasOwnProperty,uf=Object.prototype.propertyIsEnumerable,Lo=(s,t,e)=>t in s?lf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,gf=(s,t)=>{for(var e in t||(t={}))df.call(t,e)&&Lo(s,e,t[e]);if(Eo)for(var e of Eo(t))uf.call(t,e)&&Lo(s,e,t[e]);return s},ff=(s,t)=>cf(s,hf(t));function Do(s){s=s||{},s.quantity=s.quantity||200,s.startY=s.startY||50,s.avgCandleSize=s.avgCandleSize||2,s.avgTrendLength=s.avgTrendLength||{},s.avgTrendLength.sw=s.avgTrendLength.sw||10,s.avgTrendLength.down=s.avgTrendLength.down||10,s.avgTrendLength.up=s.avgTrendLength.up||10,s.withVolume=s.withVolume===!0||!1,s.period=s.period||3600;var t=[],e=s.quantity||200,n=10,i=10,r=10;s.avgTrendLength&&(n=s.avgTrendLength.sw||10,i=s.avgTrendLength.down||10,r=s.avgTrendLength.up||10);var o=s.startY||50,a=s.avgCandleSize||2,l=o-a,c=o+a,h=as(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(vf(t[t.length-1],a,n)):d>3?t=t.concat(pf(t[t.length-1],a,r)):t=t.concat(mf(t[t.length-1],a,i))}t=t.slice(0,s.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*s.period;for(let g=0;g<t.length;g++){const C=t[g];Object.assign(C,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(C.volume=Math.ceil(Math.random()*1e3+200))}return t}function as(s,t,e,n){var i=Math.random()*(t-s)+s,r;if(n&&n==="bull"||!n&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>s?a:s}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function pf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.lo,o=s.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=as(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),n.push(c)}return n}function mf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.hi-t*1.2,o=s.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=as(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),n.push(c)}return n}function vf(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var g,C;return Math.random()>.5?(g=u.lo-t*.2,C=u.hi+t*1.2):(g=u.lo-t*1.2,C=u.hi+t*.2),{from:g,to:C}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=as(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),n.push(d)}return n}window.DXChart=ff(gf({},window.DXChart),{generateCandlesData:Do});function bf(s){return Do(s)}const Cf=(s,t={})=>new Ao(s,t)})(),window.DXChart=ls})();})();
23
+ `;function bl(s){const t=document.createElement("template");return t.innerHTML=vl(s.devexpertsPromoLink),t}function Cl(s){const t={},e=Array.from(s.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(n=>{var i;t[(i=n.getAttribute("data-element"))!=null?i:""]=n}),ml(t))return t;throw new Error("Some chart elements are missing")}function wl(s){if(s.length>1){const t=s.reduce((i,r,o)=>{if(o!==s.length-1){const a=s[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,n;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,n=r)}if(n)return n}}const be=(s,t,e,n=1e3)=>{var i,r,o,a;const l=(r=(i=fe(e))==null?void 0:i.timestamp)!=null?r:0,c=(a=(o=wt(e))==null?void 0:o.timestamp)!=null?a:0;return s>c?t?{index:e.length-1+Math.ceil((s-c)/n),exact:!0}:{index:e.length-1,exact:!0}:s<l?t?{index:it((s-l)/n),exact:!0}:{index:-1,exact:!0}:zt(e,s,h=>h.timestamp)},Ls=1;function Xe(s,t){return t===s?"none":t>s?"up":"down"}function yl(s,t){return t>s?"up":"down"}function Sl(s,t,e=!1){const{expansion:n,impVolatility:i,vwap:r,volume:o,timestamp:a}=s;let l=s.hi,c=s.lo,h=s.open;const d=s.close;e&&(l=d,c=d,h=d);let u=s.idx;return t!==void 0&&(u=t),{hi:l,lo:c,open:h,close:d,timestamp:a,volume:o,expansion:n,idx:u,impVolatility:i,vwap:r}}const pi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2},mi={paintConfig:[pi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var xl=Object.defineProperty,vi=Object.getOwnPropertySymbols,_l=Object.prototype.hasOwnProperty,Pl=Object.prototype.propertyIsEnumerable,bi=(s,t,e)=>t in s?xl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Tl=(s,t)=>{for(var e in t||(t={}))_l.call(t,e)&&bi(s,e,t[e]);if(vi)for(var e of vi(t))Pl.call(t,e)&&bi(s,e,t[e]);return s};class Ml{constructor(t,e,n,i){this.series=t,this.config=e,this.yAxisBoundsProvider=n,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,n=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[Tl({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:n}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:pi).color;return{textColor:qt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}let Dt=window.devicePixelRatio,ze=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Ds=()=>{ze.removeEventListener("change",Ds),Dt=window.devicePixelRatio,ze=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),ze.addEventListener("change",Ds)};ze.addEventListener("change",Ds);const Al=()=>Dt,El=s=>Kt(Dt*s)/Dt,V=s=>it(Dt*s)/Dt,Ci=s=>pa(Dt*s)/Dt,Ce=s=>JSON.parse(JSON.stringify(s));function Is(s){return Object.entries(s)}const wi=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function yi(s){return Object.keys(s)}function Si(s,t){if(Object.is(s,t))return!0;if(typeof s!="object"||s===null||typeof t!="object"||t===null)return!1;const e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!Si(s[e[i]],t[e[i]]))return!1;return!0}function xi(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new B}:t,n=s.resetOnError,i=n===void 0?!0:n,r=s.resetOnComplete,o=r===void 0?!0:r,a=s.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,g=0,C=!1,S=!1,_=function(){d==null||d.unsubscribe(),d=void 0},M=function(){_(),h=u=void 0,C=S=!1},I=function(){var F=h;M(),F==null||F.unsubscribe()};return N(function(F,j){g++,!S&&!C&&_();var R=u=u!=null?u:e();j.add(function(){g--,g===0&&!S&&!C&&(d=Bs(I,l))}),R.subscribe(j),!h&&g>0&&(h=new de({next:function(H){return R.next(H)},error:function(H){S=!0,_(),d=Bs(M,i,H),R.error(H)},complete:function(){C=!0,_(),d=Bs(M,o),R.complete()}}),Rt(F).subscribe(h))})(c)}}function Bs(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];if(t===!0){s();return}if(t!==!1){var i=new de({next:function(){i.unsubscribe(),s()}});return Rt(t.apply(void 0,L([],p(e)))).subscribe(i)}}const We=(s,t)=>s/t,dt=(s,t)=>s/t,Yt=(s,t)=>s*t,_i=(s,t)=>(s-t)*100/t,Pi=(s,t)=>s*t/100+t,Ti=s=>Math.log2(s),Os=s=>Math.pow(2,s);class Ll extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new B,this.xChanged=this.changed.pipe(ct(()=>({start:this.xStart,end:this.xEnd})),Et((t,e)=>t.start===e.start&&t.end===e.end),xi()),this.yChanged=this.changed.pipe(ct(()=>({start:this.yStart,end:this.yEnd})),Et((t,e)=>t.start===e.start&&t.end===e.end),xi())}doActivate(){super.doActivate()}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+dt(t-this.xStart,this.zoomX)}xPixels(t){return dt(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+dt(t-this.yStart,this.zoomY):e.y+e.height-dt(t-this.yStart,this.zoomY)}yPixels(t){return dt(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Yt(e+dt(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?Yt(n+dt(this.yStart,this.zoomY),this.zoomY):Yt(e.height-n+dt(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return We(e-t,this.getBounds().width)}calculateZoomY(t,e){return We(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,n=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),n&&this.fireChanged()}setYScale(t,e,n=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),n&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(){return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&this.zoomX>0&&this.zoomY>0}}const Dl=(s,t)=>!yi(s).some(e=>s[e]!==t[e]);class Il{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let n;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(zt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(zt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class Mi{constructor(t,e,n,i){this.dataSeries=t,this.scale=e,this.getAxisType=n,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new Il(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return _i(t,n);case"logarithmic":return Ti(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return Pi(t,this.getBaseline());case"logarithmic":return Os(t);case"regular":return t}}}var Bl=Object.defineProperty,Ol=Object.defineProperties,Rl=Object.getOwnPropertyDescriptors,Ai=Object.getOwnPropertySymbols,Fl=Object.prototype.hasOwnProperty,Hl=Object.prototype.propertyIsEnumerable,Ei=(s,t,e)=>t in s?Bl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,kl=(s,t)=>{for(var e in t||(t={}))Fl.call(t,e)&&Ei(s,e,t[e]);if(Ai)for(var e of Ai(t))Hl.call(t,e)&&Ei(s,e,t[e]);return s},Yl=(s,t)=>Ol(s,Rl(t));class we{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return V(t.toY(this.close))}x(t){return V(t.toX(this.centerUnit))}clone(){return new we(this.centerUnit,this.close)}}class Li extends X{constructor(t,e,n,i=Ce(mi)){var r;super(),this.extentComponent=t,this.id=e,this.htId=n,this.name="",this.hovered=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=o=>{var a;return(a=this.config.paintConfig[o])!=null?a:this.config.paintConfig[0]},this.getBaseline=(o=this.dataIdxStart)=>{var a,l;return(l=(a=this.visualPoints[o])==null?void 0:a.close)!=null?l:1},this.getTextForPoint=o=>`${o.close}`,this.getLastVisualSeriesPoint=()=>{const o=this.visualPoints,a=zt(o,this.scale.xEnd,l=>l.centerUnit).index;return o[a]},this.getLastDataSeriesPoint=()=>{const o=this.visualPoints;return wt(o)},this.config=Lt(i,mi),this.scale=t.scale,this.view=new Mi(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Ml(this,this.config,t.getYAxisBounds,(r=t.yAxis)==null?void 0:r.state),this.highLowProvider=Nl(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=zn(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=zn(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new Mi(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state,this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,n)=>({centerUnit:n,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const n=zt(this.visualPoints,t,r=>r.centerUnit).index,i=zt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return Di(t)}getSeriesInViewport(t,e){let n=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);n=r.dataIdxStart,i=r.dataIdxEnd}return Ia(this.visualPoints2D,n,i)}}const jl=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.close>t.high&&(t.high=n.close,t.highIdx=e),n.close<t.low&&(t.low=n.close,t.lowIdx=e)}return t},Nl=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=jl(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return Yl(kl({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),Di=s=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(s);return ht.makeDecimal(s,i)};class Ue extends we{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.width=e,this.open=n,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return V(Math.abs(t.toY(this.open)-t.toY(this.close)))}candleHeight(t){return V(Math.abs(t.toY(this.high)-t.toY(this.low)))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=V(t.toY(this.high)),n=V(t.toY(this.low)),i=V(t.toY(this.open)),r=V(t.toY(this.close)),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return V(Math.max(t.toY(this.high),t.toY(this.low)))}yLineStart(t){return V(Math.min(t.toY(this.high),t.toY(this.low)))}yBodyStart(t){return V(Math.min(t.toY(this.open),t.toY(this.close)))}yBodyEnd(t){return V(Math.max(t.toY(this.open),t.toY(this.close)))}xCenter(t){return this.x(t)}xStart(t){return El(t.toX(this.startUnit))}}const oe=60,Ii=(s,t,e,n,i=oe)=>{const r=ye(s,n,i);r.volume=e;let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Ue(o,e,r.open,r.close,r.lo,r.hi,Xe(r.open,r.close),r)},Xl=(s,t,e,n,i=oe)=>{const r=zl(s,n,i);let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new we(o,r.close)},ye=(s,t,e=oe)=>({hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:Bi(s,t,e),volume:NaN,expansion:!0,idx:t}),zl=(s,t,e=oe)=>({close:NaN,timestamp:Bi(s,t,e)});function Bi(s,t,e=oe){var n,i;const r=Kt(t);if(s.length===0)return 0;const o=wt(s);if(r>=s.length&&o)return Oi(o,s.length-1,r,e);const a=fe(s);return r<0&&a?Oi(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const Oi=(s,t,e,n=oe)=>s.timestamp+(e-(t!=null?t:0))*n;class Wl{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new B,this.dataSetSubject=new B,this.dataRemovedSubject=new B,this.dataPrependSubject=new B,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e=!0,n=this.mainDataPoints){const i=be(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=wl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Ii(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):Xl(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var Ul=Object.defineProperty,Ri=Object.getOwnPropertySymbols,Vl=Object.prototype.hasOwnProperty,Gl=Object.prototype.propertyIsEnumerable,Fi=(s,t,e)=>t in s?Ul(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zl=(s,t)=>{for(var e in t||(t={}))Vl.call(t,e)&&Fi(s,e,t[e]);if(Ri)for(var e of Ri(t))Gl.call(t,e)&&Fi(s,e,t[e]);return s};class $l{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.backgroundDrawPredicate=n,this.prevState={}}draw(){if(this.backgroundDrawPredicate()||!Si(this.config.colors.chartAreaTheme,this.prevState)){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=Zl({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const Kl=(s,t,e,n,i,r,o)=>{const a=Al(),l=[e*a,n*a,i*a,r*a];let c=s.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=it(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?it(u*o):it(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Hi=(s,{x:t,width:e,activeCandle:n})=>new Ue(t,e,s.open,s.close,s.hi,s.lo,Xe(s.open,s.close),s,!0,Rs(s,n)),ql=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ue(t,e,s.open,s.close,s.hi,s.lo,yl((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},ki=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ue(t,e,s.open,s.close,s.hi,s.lo,Xe((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},Jl=ki,Rs=(s,t)=>{const e=t&&t.idx===s.idx;return e!=null?e:!1},Yi=()=>Ls,Qt=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>it(Math.log10((n^n>>31)-(n>>31)))+1;let e=t(s);return e===1&&s<1&&(e=t(s*1e9)-9),e}static getPriceIncrement(s,t=[]){if(!this.validatePriceIncrementsOrPrecisions(t))return this.DEFAULT_INCREMENT;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;const n=1e-6;for(;e<t.length&&s>t[e]+Math.min(t[e-1],t[e+1])*n;)e+=2;return e>=t.length||s<t[e]-Math.min(t[e-1],t[e+1])*n?t[e-1]:Math.min(t[e-1],t[e+1])}static getPricePrecision(s,t){if(!this.validatePriceIncrementsOrPrecisions(t))return 0;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;for(;e<t.length&&s>t[e];)e+=2;return Math.round(t[e-1])}static roundPriceToIncrement(s,t,e){const n=Qt.getPriceIncrement(e||s,t);return ht.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=Qt.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*Qt.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<Qt.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*Qt.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return Qt.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let It=Qt;It.DEFAULT_INCREMENT=.01,It.DEFAULT_PRECISION=2,It.RELATIVE_EPS=1e-8,It.MAXIMUM_PRECISION=10;const Ql=(s,t)=>{var e;const n=(e=wt(t))!=null?e:1;return Math.pow(10,-n)};var tc=Object.defineProperty,ec=Object.defineProperties,sc=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,nc=Object.prototype.hasOwnProperty,ic=Object.prototype.propertyIsEnumerable,Ni=(s,t,e)=>t in s?tc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,rc=(s,t)=>{for(var e in t||(t={}))nc.call(t,e)&&Ni(s,e,t[e]);if(ji)for(var e of ji(t))ic.call(t,e)&&Ni(s,e,t[e]);return s},oc=(s,t)=>ec(s,sc(t));const ac=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:s.scale.xStart,n=t?t.xEnd:s.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=s.calculateDataViewportIndexes(e,n),o=s.visualPoints.slice(i,r+1),a=Xi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return oc(rc({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Xi=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.high>t.high&&(t.high=n.high,t.highIdx=e),n.low<t.low&&(t.low=n.low,t.lowIdx=e)}return t},lc=30,zi=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:lc,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY});t.currentAnimation=n};class cc{constructor(t,e){this.delegate=t,this.highLowPostProcessor={},this.highLowProviders=e!=null?e:{}}setHighLowProvider(t,e){this.highLowProviders[t]=e}deleteHighLowProvider(t){delete this.highLowProviders[t]}setHighLowPostProcessor(t,e){this.highLowPostProcessor[t]=e}doAutoYScale(t){hc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const hc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=Wi(i),o=n.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=s.calculateZoomY(t.yStart,t.yEnd)};function Wi(s){if(s.length===0)return dc();let t=s[0].high,e=s[0].low;return s.forEach(n=>{isFinite(n.high)&&n.high>=t&&(t=n.high),isFinite(n.low)&&n.low<=e&&(e=n.low)}),{low:e,high:t}}const dc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER});var uc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,gc=Object.prototype.hasOwnProperty,fc=Object.prototype.propertyIsEnumerable,Vi=(s,t,e)=>t in s?uc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gi=(s,t)=>{for(var e in t||(t={}))gc.call(t,e)&&Vi(s,e,t[e]);if(Ui)for(var e of Ui(t))fc.call(t,e)&&Vi(s,e,t[e]);return s};const pc=(s,t,e,n)=>{var i,r,o,a;const l=Gi({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Ba(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=s.xStart,u=s.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Yt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},mc=(s,t,e,n)=>{const i=Gi({},t),r=n(),o=i.xEnd-i.xStart,a=o<e.minCandles,l=r.width/e.minWidth,c=o>l;if(r.width>0){if(c)return i.xStart=i.xEnd-l,i.zoomX=We(i.xEnd-i.xStart,r.width),i;if(a)return i.xStart=i.xEnd-e.minCandles,i.zoomX=We(i.xEnd-i.xStart,r.width),i}return i},vc=(s,t)=>s/t,bc=(s,t)=>s/t,Cc=(s,t)=>s*t,Zi=(s,t)=>{const e=s.zoomY;s.zoomY=bc(s.zoomX,t);const n=s.zoomY/e,i=s.yEnd-s.yStart,o=i*n-i;s.yEnd=s.yEnd+o/2,s.yStart=s.yStart-o/2},wc=(s,t)=>{const e=s.zoomX;s.zoomX=Cc(s.zoomY,t);const n=s.zoomX/e,i=s.xEnd-s.xStart,o=i*n-i;s.xStart=s.xStart-o},yc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},Sc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},$i=(s,t,e,n,i)=>{const r=(t.xEnd-t.xStart)*n,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=s.calculateZoomX(t.xStart,t.xEnd),t},xc=(s,t,e,n)=>$i(s,t,1,e,n);var _c=Object.defineProperty,Pc=Object.defineProperties,Tc=Object.getOwnPropertyDescriptors,Ki=Object.getOwnPropertySymbols,Mc=Object.prototype.hasOwnProperty,Ac=Object.prototype.propertyIsEnumerable,qi=(s,t,e)=>t in s?_c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Se=(s,t)=>{for(var e in t||(t={}))Mc.call(t,e)&&qi(s,e,t[e]);if(Ki)for(var e of Ki(t))Ac.call(t,e)&&qi(s,e,t[e]);return s},Ec=(s,t)=>Pc(s,Tc(t));const Lc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class Ji extends Ll{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new B,this.beforeStartAnimationSubject=new B,this.history=[],this.zoomXYRatio=0,this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=Ce(t.scale),this.autoScaleModel=new cc(this),this.offsets=this.config.components.offsets,this.addXConstraint((i,r)=>mc(i,r,this.config.components.chart,this.getBounds))}doActivate(){super.doActivate(),this.scaleInversedSubject=new B,this.beforeStartAnimationSubject=new B,this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=Se(Se({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,n=!1,i){const r=this.config.scale.disableAnimations||n;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();$i(this,o,t,i,e),this.zoomXTo(o,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const n=this.export();xc(this,n,e,t),this.zoomXTo(n,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.doAutoScale())}zoomXTo(t,e){const n=Se({},t),i=this.scalePostProcessor(n,t);this.state.lockPriceToBarRatio&&Zi(i,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(i),e?this.apply(i):zi(this.canvasAnimation,this,i)}setXScale(t,e,n=!0){const i=this.export(),r=this.calculateZoomX(t,e),o=Ec(Se({},i),{zoomX:r,xStart:t,xEnd:e}),a=this.scalePostProcessor(i,o);this.state.lockPriceToBarRatio&&Zi(a,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(a),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(a)):zi(this.canvasAnimation,this,a)}setYScale(t,e,n=!1){const i=this.export();super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);if(this.state.lockPriceToBarRatio){wc(o,this.zoomXYRatio),this.setXScale(o.xStart,o.xEnd);return}else this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}moveXStart(t){const e=this.export(),n=Se({},e);this.haltAnimation(),yc(e,t);const i=this.scalePostProcessor(n,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Sc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Dl(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}t&&this.recalculateZoomXYRatio(),this.state.lockPriceToBarRatio=t}recalculateZoomXYRatio(){this.zoomXYRatio=vc(this.zoomX,this.zoomY)}}class Dc extends Ji{constructor(t,e,n,i){super(e,n,i),this.delegate=t,this.config=e,this.getBounds=n}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Ic=Ye().colors;class Wt extends Li{constructor(t,e,n,i,r,o,a,l,c=Ic){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Lc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new B,this.meanCandleWidth=Ls,this._instrument=o,this.instrument=o,this.highLowProvider=ac(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=It.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){super.recalculateDataViewportIndexes(t,e),this.recalculateZippedHighLow(),this.eventBus.fireDraw()}applyPriceMovement(){const t=wt(this.dataPoints);t&&(this.lastPriceMovement=Xe(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Xi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Lt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Yi;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),g=a+u/2,C=(i=this.candlesTransformersByChartType[r])!=null?i:Hi;o.push(C(h,{x:g,width:u,prevCandle:d,activeCandle:this.activeCandle})),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,n)=>e+n.width,0)/t.length:this.meanCandleWidth=Ls}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Wf(s){switch(s){case"line":case"area":return!0;default:return!1}}class Bc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);if(r.length===0)return;i.singleColor?t.strokeStyle=i.singleColor:t.strokeStyle=n.colors.areaTheme.lineColor,n.hovered?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const o=n.extentComponent.getBounds(),a=r[0],l=n.view.toX(a.centerUnit);for(let c=0;c<r.length;c++){const h=r[c-1],d=r[c+1],u=r[c],g=n.view.toX(u.centerUnit),C=n.view.toY(u.close),S=o.y+o.height;if(h===void 0)t.beginPath(),t.lineTo(it(g),S),t.moveTo(it(g),C);else if(d===void 0){t.lineTo(it(g),C),t.stroke(),t.lineTo(it(g),S),t.lineTo(it(l),S),t.closePath();let _;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(_=t.createLinearGradient(0,0,0,o.height),_.addColorStop(0,n.colors.areaTheme.startColor),_.addColorStop(1,n.colors.areaTheme.stopColor),_):"",t.fill()}else t.lineTo(it(g),C)}}}}function Qi(s,t,e,n,i,r=4,o=!0,a=!1){s.save(),s.beginPath(),s.moveTo(t+r,e),s.lineTo(t+n-r,e),s.quadraticCurveTo(t+n,e,t+n,e+r),s.lineTo(t+n,e+i-r),s.quadraticCurveTo(t+n,e+i,t+n-r,e+i),s.lineTo(t+r,e+i),s.quadraticCurveTo(t,e+i,t,e+i-r),s.lineTo(t,e+r),s.quadraticCurveTo(t,e,t+r,e),s.closePath(),o&&s.fill(),a&&s.stroke(),s.restore()}function Oc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const g=c==="right"?a:-a,C=c==="right"?h:-h,S=h;s.save(),s.beginPath(),l?s.moveTo(r+C,o):s.moveTo(r,o),l?(s.lineTo(r+g-C,o),s.quadraticCurveTo(r+g,o,r+g,o-S),s.lineTo(r+g,e+S),s.quadraticCurveTo(r+g,e,r+g-C,e),s.lineTo(t+C,e)):(s.lineTo(r+g,o),s.lineTo(r+g,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-C/3,e+S/3),s.lineTo(n+C/3,i-S/3),s.quadraticCurveTo(n,i,n+C/3,i+S/3),s.lineTo(r-C/3,o-S/3),s.quadraticCurveTo(r,o,r+C/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function Rc(s,t,e,n,i,r=1){s.save(),s.lineWidth=r,s.beginPath(),s.moveTo(t,e),s.lineTo(n,i),s.stroke(),s.closePath(),s.restore()}function te(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function tr(s,t,e){const n=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);s.fillRect(n,i,r,o)}const Ut=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Uf=s=>Array.isArray(s[0])?s:[s];class Fc{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,n){const i=t.ctx,r=n&&this.paneManager.panes[n];e&&(i.save(),r&&Ut(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);r&&r.length>=1&&i.draw(t,r,e,{})}else console.error(`Data series drawer with type ${n} isn't registered!`)}}}const ae=(s,t,e,n,i=t)=>{n.forceBold?s.lineWidth=n.forceBold:e.hovered?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class Hc{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.singleColor)t.strokeStyle=e.singleColor;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);ae(t,this.config.barLineWidth,n,i),te(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=V(n.view.toX(o.centerUnit)),l=V(n.view.toX(o.startUnit)),[c,h,d,u]=o.yBodyKeyPoints(n.view),g=V(n.view.xPixels(o.width)/2),C=V(n.view.toY(o.close)),S=V(n.view.toY(o.open));this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,C),t.lineTo(a+g,C),t.moveTo(l,S),t.lineTo(a,S),t.stroke()}})}}}class kc{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Wt){const r=pt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(x.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],g=r[h+1],C=n.view.toX(c.centerUnit),S=n.view.toX(d.centerUnit),_=n.view.toY(d.close),M=u?n.view.toY(u.close)<l:!1,I=_<l;if(u!==void 0&&M!==I){er(t,n,i,M);const F=n.view.toX(u.centerUnit),j=n.view.toY(u.close),R=S-F,H=_-j,Y=R/H,Z=_-l,K=Y*Z,W=F+(R-K);t.lineTo(W,l),t.stroke(),t.lineTo(C,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(W,l)}u===void 0?(t.beginPath(),t.moveTo(S,_)):g===void 0?(er(t,n,i,I),t.lineTo(S,_),t.stroke(),t.lineTo(S,l),t.lineTo(C,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(C,l),t.lineTo(S,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(S,_)}}}}const er=(s,t,e,n)=>{e.singleColor?(s.fillStyle=e.singleColor,s.strokeStyle=e.singleColor):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Yc{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);ae(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),te(t,()=>{this.pixelLength=1/Dt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=n.colors;a&&l&&this.drawCandle(t,i,n,o)}})}}drawCandle(t,e,n,i){const{candleTheme:r,activeCandleTheme:o}=n.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.singleColor?t.fillStyle=e.singleColor:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=V(n.view.toX(i.startUnit)),d=V(n.view.xPixels(i.width)),u=i.bodyHeight(n.view),[g,C,S,_]=i.yBodyKeyPoints(n.view),M=C===S?C+1:S,I=g===_?g+1:_,F=l[`${a}Color`],j=a==="none"?F:l[`${a}WickColor`];t.fillStyle=F,e.singleColor?t.strokeStyle=e.singleColor:t.strokeStyle=j;const R=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),H=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,H?g:C),t.lineTo(h,H?I:M),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,H?g:C),t.lineTo(h,H?I:M),t.moveTo(h+1,C),t.lineTo(h+1,M),t.stroke();else if(d===3){const Y=d/Dt;this.drawCandlesWicks(t,h+Y,g,I,C,M),c||(t.beginPath(),t.moveTo(h+Y,C),t.lineTo(h+Y,M),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,C+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,g,I,C,M-1);const Z=this.config.candlePaddingPercent,K=Math.max(V(d*Z/2),this.pixelLength),W=h+K,U=d-K*2;c||(e.singleColor&&(t.fillStyle=e.singleColor),t.fillRect(W,C,U,u)),R&&this.drawCandleBorder(t,e,l,i,W+this.halfLineWidthCU,C+this.halfLineWidthCU,U-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,n,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,n),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,n,i,r,o,a,l){if(e.singleColor)t.strokeStyle=e.singleColor;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class jc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=e.flat(),o=n.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=n.colors.histogram;if(d===void 0)return;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),g=V(n.view.toY(l.close)),C=V(n.view.xPixels(l.width));t.fillRect(u,g,C,h);const S=t.createLinearGradient(0,g+h,0,a);i.singleColor?t.fillStyle=i.singleColor:(S.addColorStop(0,d[`${c}Cap`]),S.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=S),C===0?(t.beginPath(),t.strokeStyle=S,t.moveTo(u,g+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,g+h,C,a-g-h)}}}}class Nc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=pt(e);ae(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.singleColor&&(t.strokeStyle=i.singleColor);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.singleColor||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),g=n.view.toX(c.centerUnit),C=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(g,C),t.stroke()}}}}const Xc=1.5;class zc{constructor(t){this.config=t}draw(t,e,n,i){var r;t.fillStyle=(r=i.singleColor)!=null?r:this.config.mainColor;for(const o of pt(e)){t.beginPath();const a=V(n.view.toX(o.centerUnit)),l=V(n.view.toY(o.close));t.arc(a,l,Xc,0,Math.PI*2,!0),t.fill()}}}const Wc=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Uc{constructor(t,e,n){this.drawer=t,this.config=e,this.chartBounds=n}draw(t,e,n,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,n,i),this.afterDraw(t,n))}beforeDraw(t){t.restore(),t.save(),Ut(t,this.chartBounds())}isChartTypeAllowed(){return Wc.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Ut(t,e.scale.getBounds())}}class Vc{constructor(t){this.chartModel=t}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(Kt(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,g=V(dt(h.width,u)),C=V(h.bodyHeight(this.chartModel.scale)),S=h.xCenter(this.chartModel.scale)-g/2,_=h.yBodyStart(this.chartModel.scale),M=this.chartModel.config.components.chart.candlePaddingPercent,I=V(g*M/2),F=S+I,j=g-I*2;t.fillRect(F,_,j,C)}})})}}const sr=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{const{centerUnit:r,close:o}=n,a=e.toX(r),l=e.toY(o);i===0?t.moveTo(a,l):t.lineTo(a,l)})},Gc=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Zc=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i;function $c(s){const t=Gc.exec(s)||Zc.exec(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const nr={};function Kc(s,t){let e=nr[s+t];if(!e){const n=$c(s);e=n&&"rgba("+n.join(",")+","+t+")",nr[s+t]=e}return e}class qc{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ae(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.singleColor)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(rr(r.config.type)&&rr(n.config.type)&&r.config.visible){const a=[],l=n,c=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1),h=r.getSeriesInViewport(r.scale.xStart-1,r.scale.xEnd+1);c.forEach((d,u)=>{const g=Math.min(d.length,h[u].length);for(let _=0;_<g;_++){const M=[d[_].clone(),h[u][_].clone()];a.push({diffPoints:M})}const C=l.getPaintConfig(u).color,S=r.getPaintConfig(o).color;this.drawDifference(t,C,S,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),sr(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[g,C]=u.diffPoints;l.push(g),c.push(C)});const h=ir(l,r.view),d=ir(c,o.view);this.fillCloud(t,n,h,d,a),this.fillCloud(t,e,d,h,a)}fillCloud(t,e,n,i,r){var o,a,l,c;t.save(),t.beginPath();const h=(a=(o=fe(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=wt(n))==null?void 0:l.x)!=null?c:0;t.lineTo(h,0),n.forEach(u=>{t.lineTo(u.x,u.y)}),t.lineTo(d,0),t.closePath(),t.clip(),t.beginPath(),n.forEach((u,g)=>{g===0?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y)}),i.slice().reverse().forEach(u=>{t.lineTo(u.x,u.y)}),t.closePath(),t.fillStyle=r.singleColor?r.singleColor:Kc(e||"#383838",.3),t.fill(),t.restore()}}const ir=(s,t)=>s.map(e=>{const{centerUnit:n,close:i}=e,r=t.toX(n),o=t.toY(i);return{x:r,y:o}}),rr=s=>s==="DIFFERENCE";class Jc{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);ae(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.singleColor)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,it(r)),t.lineTo(d,it(u))}),t.stroke()})}}class Qc{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ae(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.singleColor)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),sr(e,t,n),t.stroke()}}class th{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=l.lineWidth;t.fillStyle=(a=i.singleColor)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class eh{constructor(t){this.config=t}draw(t,e,n,i){t.save(),e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=n.getTextForPoint(h),u=yt(d,t,c),g=Ht(c,t),C=n.view.toX(h.centerUnit)-u/2,S=n.view.toY(h.close)+g;t.fillText(d,C,S)})}),t.restore()}}class sh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=n.view.toX(c.centerUnit),d=n.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,n,i){t.beginPath(),t.moveTo(e-i/2,n),t.lineTo(e,n-i),t.lineTo(e+i/2,n),t.fill()}}const Fs="resized_local",Ve="draw",Vf="draw_last_candle",le={width:20,height:20};class or{constructor(t,e,n,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=n,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=Hs;var a;i.push(this),this.parent=rh(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:n}=t,i=window.devicePixelRatio;this.canvas.style.height=n+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=n*i,this.width=e,this.height=n,this.ctx.scale(i,i)}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const n=e.height;n!==this.height&&(t.style.height=n+"px",this.height=n,t.height=n,this.prevHeight=n)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>le.width&&this.height>le.height}}const Hs={name:"candle"},nh={candle:Hs,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function ih(s,t,e,n,i,r,o){var a;const l=ce(s,t,i,r,o,e);return l.type=(a=nh[n])!=null?a:Hs,l}function ce(s,t,e,n,i,r,o){const a=new or(s,t,n,i,r,o);return ar(a,e),a}function ar(s,t){const e=s.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",s.width=t.fixedSize.width,s.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function rh(s){let t=s;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}let ks=!1,Ys=0;const Ge=new Map,js=new Map,lr=()=>{ks||(ks=!0,Ys=requestAnimationFrame(()=>{js.forEach((s,t)=>{s(),js.delete(t)}),Ge.forEach((s,t)=>{s(),Ge.delete(t)}),ks=!1}))},cr=(s,t)=>{Ge.set(s,t),lr()},Kf=s=>{Ge.delete(s)},Ns=(s,t)=>{js.set(s,t),lr()},Ze="HIT_TEST_",qf=null;class oh{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${Ct()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf(Ze)!==-1&&this.drawersMap[n].draw()})},t.on(Ve,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),cr(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(Ze)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(Ze)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}Ea(t,n.getCanvasIds()).length&&n.draw()}})}isDrawable(){var t,e,n,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>le.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>le.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=Ct()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(n);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(n);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const n=this.drawingOrder.indexOf(e);n!==-1&&this.drawingOrder.splice(n,1)}})}reorderDrawers(t){this.drawingOrder=Nn(this.drawingOrder,t)}}class hr{static paneResizer(t){return`PANE_RESIZER_${t}`}}class ah{constructor(t,e,n){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=n}draw(){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Ut(t,e.getBounds()),e.dataSeries.forEach(n=>this.drawSeries(t,n)),t.restore()})}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r={singleColor:this.canvasModel.idToColor(e.htId),forceBold:7};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const dr={disableChartPanning:!0};class ur extends X{constructor(t,e,n,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=n,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o),this.dragComponentOptions.disableChartPanning&&this.chartPanComponent.deactivatePanHandlers()},this.onDragTick=o=>{this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels),this.dragComponentOptions.disableChartPanning&&this.chartPanComponent.activateChartPanHandlers())}}doActivate(){super.doActivate()}doDeactivate(){super.doDeactivate()}}class $e extends ur{constructor(t,e,n,i,r=dr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}doDeactivate(){super.doDeactivate()}}const lh="BASELINE_RESIZER";class ch extends X{constructor(t,e,n,i,r,o,a){super(),this.chartModel=t,this.canvasModel=n,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.baselineYPercents=50,this.ht=As.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&al(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new $e(this.ht,{onDragTick:this.dragTickCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(x.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(x.CHART),e=this.canvasBoundContainer.getBounds(x.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const n=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=n,this.canvasBoundContainer.bounds[lh]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(x.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const Ke=s=>{var t;const e=ue(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=ue(s.hi,Math.max(s.open,s.close),e),i=ue(s.lo,Math.min(s.open,s.close),e),r=ue(s.open,s.lo,e),o=ue(s.close,s.hi,e);return{hi:n,lo:i,open:r,close:o,timestamp:s.timestamp,volume:(t=s.volume)!=null?t:0,expansion:s.expansion,idx:s.idx,impVolatility:s.impVolatility}},Xs=s=>{for(let t=0;t<s.length;++t)s[t].idx=t},gr=s=>{s.forEach(t=>{t.idx=void 0})};class hh{constructor(){}draw(t,e,n){const i=n.view.toY(0),r=pt(e),o=[[],[]];r.forEach((a,l,c)=>{o[a.close<this.previousValue(c,l)?1:0].push(a)}),o.forEach((a,l)=>{const c=n.getPaintConfig(l);t.strokeStyle=l===0?c.color:c.aditionalColor||"#FF00FF",t.lineWidth=c.lineWidth,t.beginPath(),a.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,it(i)),t.lineTo(d,it(u))}),t.stroke()})}previousValue(t,e){do e--;while(e>=0&&!isFinite(t[e]&&t[e].close));return t[e]?t[e].close:Number.NaN}}var dh=Object.defineProperty,fr=Object.getOwnPropertySymbols,uh=Object.prototype.hasOwnProperty,gh=Object.prototype.propertyIsEnumerable,pr=(s,t,e)=>t in s?dh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,fh=(s,t)=>{for(var e in t||(t={}))uh.call(t,e)&&pr(s,e,t[e]);if(fr)for(var e of fr(t))gh.call(t,e)&&pr(s,e,t[e]);return s};class ph{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class mh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,C){super(),this.chartModel=t,this.canvasModel=e,this.config=n,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=g,this.chartResizeHandler=C,this._dataSeriesDrawers={},this.backgroundDrawPredicateSubj=new _t(!0),this.strToBarType=_=>{var M;return(M=this.barTypeValues.find(I=>I===_))!=null?M:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new ch(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const S=new ah(this._dataSeriesDrawers,this.hitTestCanvasModel,d);this.drawingManager.addDrawerBefore(S,Ze+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new $l(c,this.config,()=>this.backgroundDrawPredicateSubj.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(q),n.components.chart.cursor),this.dataSeriesDrawer=new Fc(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(()=>{this.backgroundDrawPredicateSubj.next(!1)})),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawPredicateSubj.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Hi),this.registerCandlesTransformer("trend",ki),this.registerCandlesTransformer("hollow",ql),this.registerCandlesTransformer("line",Jl)}get barTypeValues(){return yi(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new Yc(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Hc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new Nc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new zc(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Bc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new kc(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new jc(this.config.components.chart.histogram));const e=x.PANE_UUID(q),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new Qc),this.registerDataSeriesTypeDrawer("HISTOGRAM",new Jc),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new hh),this.registerDataSeriesTypeDrawer("POINTS",new th),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Uc(new Vc(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new eh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new sh),this.registerDataSeriesTypeDrawer("DIFFERENCE",new qc)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(fh({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,n=!0){return this.chartModel.setTimestampRange(t,e,n)}setXScale(t,e,n=!0){return this.scale.setXScale(t,e,n)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setMainSeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=n,this.chartModel.setAllSeries({candles:t.candles,instrument:n},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return gr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(n)}setSecondarySeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,n);if(this.updatePriceIncrementsIfNeeded(n),i)return i}setAllSeries(t,e=[]){var n;const i=(n=t.instrument)!=null?n:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!It.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[It.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}class mr extends Wt{constructor(t,e,n,i,r,o,a,l,c,h){super(e,n,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}const vh=s=>t=>{if(t.length!==0){const e=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),n=e[0],i=e[e.length-1];s.setXScale(n.startUnit,i.startUnit+i.width+s.offsets.right),s.doAutoScale(!0),s.recalculateZoomXYRatio(),s.fireChanged()}},bh=(s,t)=>(e,n=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=n===null?0:t.mainCandleSeries.meanCandleWidth*2,c=n?o-l:o+l,h=n?a+l:a-l;s.setXScale(c,h)};var Ch=Object.defineProperty,wh=Object.defineProperties,yh=Object.getOwnPropertyDescriptors,vr=Object.getOwnPropertySymbols,Sh=Object.prototype.hasOwnProperty,xh=Object.prototype.propertyIsEnumerable,br=(s,t,e)=>t in s?Ch(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,xe=(s,t)=>{for(var e in t||(t={}))Sh.call(t,e)&&br(s,e,t[e]);if(vr)for(var e of vr(t))xh.call(t,e)&&br(s,e,t[e]);return s},zs=(s,t)=>wh(s,yh(t));class _h{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,n)=>zs(xe({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=zs(xe({},Ce(this.config.colors)),{lineTheme:xe({},n.lineTheme),areaTheme:xe({},n.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,n="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,n=i);return this.usedChartColors[n]=this.usedChartColors[n]+1,this.symbolsToColorKeys[t]=n,this.secondaryChartColorsPool[n]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var n,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=zs(xe({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Ph=Object.defineProperty,Cr=Object.getOwnPropertySymbols,Th=Object.prototype.hasOwnProperty,Mh=Object.prototype.propertyIsEnumerable,wr=(s,t,e)=>t in s?Ph(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,qe=(s,t)=>{for(var e in t||(t={}))Th.call(t,e)&&wr(s,e,t[e]);if(Cr)for(var e of Cr(t))Mh.call(t,e)&&wr(s,e,t[e]);return s};class Ah extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=n,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.nextCandleTimeStampSubject=new B,this.chartTypeChanged=new B,this.mainInstrumentChangedSubject=new B,this.offsetsChanged=new B,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new _h(this.config);const d=new mr(this.chartBaseModel,this.paneManager.panes[q].mainExtent,Ct(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new ph,this.candlesTransformersByChartType,this.candleWidthByChartType,qe({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),o.addXConstraint((u,g)=>pc(g,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=vh(o),this.timeFrameViewportTransformer=bh(o,this),this.pane=this.paneManager.panes[q]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(q)).pipe(Et(hi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>le.width&&t.height>le.height){const e=this.getEffectiveChartWidth(),n=this.getEffectiveYAxisWidth();if(this.prevChartWidth===0){this.scale.isViewportValid()?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Yt(n-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=n,this.prevChartWidth=e;return}const i=Yt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=n,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(n=>{const i=n.dataPoints;return gr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=Je(t.map(Ke)),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,n&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var n;this.mainCandleSeries.instrument=(n=t.instrument)!=null?n:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=Je(t.candles.map(Ke));this.mainCandleSeries.clearData(),Xs(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=qe({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const n=[t,...e];if(!this.candleSeries.every(l=>n.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=Je(t.candles.map(Ke)),r=Sr(this.mainCandleSeries.dataPoints,i),o=r.candles;Xs(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const g=Je(l.candles.map(Ke)),C=Sr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],g).candles;return this.setSecondaryCandleSeries(C,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),l.recalculateDataViewportIndexes()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(n=>{const i=zt(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}createSecondaryCandleSeriesModel(t){const e=qe(qe({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Wt(this.paneManager.panes[q].mainExtent,Ct(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return n.config.type="line",this.candleSeries.push(n),n}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[q].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{var r;const o=(r=i.idx)!=null?r:0,a=e[o];if(a)n.push(a);else{let l=yr(e,o,-1);if(l||(l=yr(e,o,1)),l){const c=Sl(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=Lt(t,Ye().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=n,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}getEffectiveYAxisWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(q)).width}getEffectiveChartWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)).width}getEffectiveChartHeight(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)).height}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),n=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=n.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,n=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,n)}candleFromUnit(t,e=!1,n=this.mainCandleSeries){var i,r;const o=zt(n.visualPoints,t,d=>d.startUnit),a=n.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Kt((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?ye(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:ye(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e=!0,n=this.mainCandleSeries){const i=n.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,n,i;const r=t-((i=(n=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:n.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,n=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,n)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return wt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return wt(t)}getMaxCandlesFitLength(){return it(this.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((n,i)=>{const r=i.timestamp,o=be(r,!1,t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,n[o.index]=i),n},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const n=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=be(h.timestamp,!0,o,this.getPeriod()),g=Math.min(u.index,o.length);a=a||g===o.length,o[g]=h,h.idx=g,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(g);const C=g>=o.length-1,S=c&&h.timestamp<c.timestamp;if(C&&!S&&(c=h),a&&c&&n&&l){const _=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Yi;this.scale.moveXStart(this.scale.xStart+_(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return ft(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=0,e){let n=this.getCandles().slice();const i=this.getCandlesCount(),r=e!=null?e:i+this.FAKE_CANDLES_DEFAULT;n=n.slice(Math.max(0,t),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(ye(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(ye(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...n,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const n=t.slice(),i=[];return e.forEach(r=>{const a=be(r.timestamp,!1,t).index;a<0?i.push(r):t[a].timestamp===r.timestamp?n[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...n]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){const n=this.findSeriesBySymbol(e);if(n.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}n.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Xs(i.dataPoints),i.recalculateVisualPoints()}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Je=s=>s.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),yr=(s,t,e)=>{if(t>=s.length)return s[s.length-1];for(let n=t;n<s.length&&n>=0;n+=e){const i=s[n];if(i)return i}},Sr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=be(r.timestamp,!0,s).index;a<0?n.push(r):a>=s.length?i.push(r):s[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:n,appended:i,candles:[...n,...e,...i]}};class _e{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ws{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const n=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(n,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=wi(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=wi(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=pt(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class Eh{constructor(t,e,n){this.model=t,this.crossToolCanvasModel=e,this.crossToolTypeDrawers=n}draw(){const t=this.crossToolTypeDrawers[this.model.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.model.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}class Lh extends X{constructor(t,e,n,i){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.currentHoverSubject=new _t(null),this.type="cross-and-labels",this.type=t.type}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?this.updateHover(t):this.currentHover=null,this.fireDraw()}))}fireDraw(){this.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateHover(t,e=this.config.magnetTarget){if(this.currentHover===null?this.currentHover={x:t.x,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=t.x,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===q)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}}const Pt=4;function Dh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,C;const S=r.align,_=(l=i.textFont)!=null?l:Jt(r),M=i.bgColor,I=(c=i.textColor)!=null?c:qt(M,o.labelTextColor,o.labelInvertedTextColor),F=(h=i.paddingTop)!=null?h:Pt,j=(d=i.paddingBottom)!=null?d:Pt,R=(u=i.paddingEnd)!=null?u:Pt,H=Kt(Ht(_,s)/2),Y=n-H-F,K=n+H+j-Y;if(a&&!Qe(n,t,K))return;s.save(),s.fillStyle=M,s.strokeStyle=M;const W=Kt(t.width/6),U=S==="right"?t.x:t.x+t.width,tt=S==="right"?U+W:U-W,J=r.labelBoxMargin.end,Q=J-R,et=t.width-W-Q;Oc(s,tt,Y,U,Y+Kt(K/2),tt,Y+K,et,(C=(g=r.typeConfig.badge)==null?void 0:g.rounded)!=null?C:!1,S),s.fillStyle=I,s.font=_;const st=S==="right"?t.x+t.width-yt(e,s,_)-J:t.x+J;s.fillText(e,st,n+H-1),s.restore()}function Ih(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,C,S,_,M,I;const F=r.align,j=(l=i.textFont)!=null?l:Jt(r),R=i.bgColor,H=(c=i.textColor)!=null?c:qt(R,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,Z=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Pt,K=(C=(g=i.paddingBottom)!=null?g:Y==null?void 0:Y.bottom)!=null?C:Pt,W=(_=(S=i.paddingEnd)!=null?S:Y==null?void 0:Y.end)!=null?_:Pt,U=i.paddingStart,tt=Ht(j,s),J=n-tt/2-Z,et=n+tt/2+K-J,st=(I=i.rounded)!=null?I:(M=r.typeConfig.rectangle)==null?void 0:M.rounded;if(a&&!Qe(n,t,et))return;s.save(),s.fillStyle=R,s.strokeStyle=R;const ot=r.labelBoxMargin.end;s.font=j;const Tt=yt(e,s,j),St=ot-W,Bt=U!==void 0?Tt+U+W:t.width-St,se=F==="right"?t.x+t.width-St-Bt:t.x+St,Ae=F==="right"?t.x+t.width-Tt-ot:ot;st?Qi(s,se,J,Bt,et,4,!0):s.fillRect(se,J,Bt,et),s.fillStyle=H,s.fillText(e,Ae,n+tt/2-1),s.restore()}function Bh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,C,S,_;const M=r.align,I=(l=i.textFont)!=null?l:Jt(r),F=o.backgroundColor,j=(c=i.textColor)!=null?c:qt(F,o.labelTextColor,o.labelInvertedTextColor),R=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,H=(u=(d=i.paddingTop)!=null?d:R==null?void 0:R.top)!=null?u:Pt,Y=(C=(g=i.paddingBottom)!=null?g:R==null?void 0:R.bottom)!=null?C:Pt,Z=(_=(S=i.paddingEnd)!=null?S:R==null?void 0:R.end)!=null?_:Pt,K=i.paddingStart,W=Ht(I,s),U=n-W/2-H,J=n+W/2+Y-U;if(a&&!Qe(n,t,J))return;s.save(),s.fillStyle=F,s.strokeStyle=F;const Q=r.labelBoxMargin.end;s.font=I;const et=yt(e,s,I),st=Q-Z,ot=K!==void 0?et+K+Z:t.width-st,Tt=M==="right"?t.x+t.width-st-ot:t.x+st,St=M==="right"?t.x+t.width-et-Q:Q;s.fillStyle=F,s.strokeStyle=F,s.fillRect(Tt,U,ot,J),s.fillStyle=j,s.fillText(e,St,n+W/2-1),s.restore()}function Oh(s,t,e=Pt){return Ht(s,t)/2+e}function Qe(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const Rh="badge",xr=4,_r={badge:Dh,rectangle:Ih,plain:Bh};function Pr(s,t,e,n,i,r,o,a){var l,c,h,d,u;const g=i.y,C=i.labelText,S=(l=i.mode)!=null?l:"label",_=(c=i.labelType)!=null?c:Rh,M=i.description,I=(h=i.textFont)!=null?h:Jt(o),F=i.bgColor,j=(d=i.lineColor)!=null?d:F,R=yt(M!=null?M:"",s,I)+8,H=it(i.y),Y=Ht(I,s),Z=g-Y/2,W=g+Y/2-Z;s.save(),s.fillStyle=F,s.strokeStyle=j;const U=r.getBounds(x.PANE_UUID(q)),tt=_r[_],J=o.labels.descriptions,Q=Fh(e,H,W),et=()=>J&&Hh(t,s,e,n,i,o);let st,ot;const Tt=2;o.align==="right"?(st=U.x,ot=J?U.x+U.width-R:U.x+U.width+Tt):(st=J?U.x+R:U.x-Tt,ot=U.x+U.width);const St=(u=i.lineY)!=null?u:i.y,Bt=()=>Q&&te(s,()=>Rc(s,st,St,ot,St,1)),se=()=>tt(s,e,C,g,i,o,a.yAxis,!1),wf={line:()=>{Bt(),et()},"line-label":()=>{Bt(),se(),et()},label:()=>{et(),se()}};S!=="none"&&Qe(g,e,W)&&wf[S](),s.restore()}const Fh=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function Hh(s,t,e,n,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=Jt(r),g=yt(h,t,u),C=Ht(u,t),S=(o=i.paddingTop)!=null?o:xr,_=(a=i.paddingBottom)!=null?a:xr,M=d-C/2-S,F=d+C/2+_-M;t.save();const j=g+5,R=4,H=g+R*2,Y=n.x+n.width,Z=c==="right"?Y-H:n.x+R;Kl(s,t,Z,M,j,F,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const K=c==="right"?Y-g-R*2:n.x+R*2;t.fillText(h,K,d+C/2-1),t.restore()}class Tr{constructor(t,e,n,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=n,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&te(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var n,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(x.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES,{extensionY:1e-4}),h=(n=this.config.components.xAxis.padding.top)!=null?n:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,g=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const C={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},S={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},_=g==null?void 0:g(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),_&&(t.moveTo(...C.start),t.lineTo(...C.end)),t.moveTo(...S.start),t.lineTo(...S.end),t.stroke()),_&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var n,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,g=t.measureText(u).width,C=this.config.components.xAxis.fontSize,S=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const _=(n=l==null?void 0:l.left)!=null?n:0,M=(i=l==null?void 0:l.right)!=null?i:0,I=(r=l==null?void 0:l.top)!=null?r:0,F=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,R=g+_+M,H=C+I+F,Y=Math.max(d-R/2,0),Z=S.y+j;Qi(t,Y,Z,R,H),t.fillStyle=h.labelTextColor;const K=Math.max(d-g/2,_),W=S.y+j+C+I-1;t.fillText(u,K,W),t.restore()}}drawYLabel(t,e){const n=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=_r[a],g=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:g,bgColor:i.labelBoxColor,paddingBottom:n==null?void 0:n.bottom,paddingEnd:n==null?void 0:n.end,paddingTop:n==null?void 0:n.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class kh{draw(){}}class Yh extends X{constructor(t,e,n,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossToolTypeDrawers={},this.model=new Lh(t.components.crossTool,this.crossToolCanvasModel,o,a),this.addChildEntity(this.model);const l=new _e(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const c=new Eh(this.model,this.crossToolCanvasModel,this.crossToolTypeDrawers),h=new Ws;h.addDrawer(l,"CLEAR_CANVAS"),h.addDrawer(c,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(h,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Tr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Tr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new kh)}setVisible(t){this.model.setType(t?"cross-and-labels":"none")}setType(t){this.model.setType(t)}observeCrossToolChanged(){return this.model.currentHoverSubject}setMagnetTarget(t){this.config.components.crossTool.magnetTarget=t}registerCrossToolTypeDrawer(t,e){this.crossToolTypeDrawers[t]=e}}class jh{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,n])=>{for(const i of n){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class jt{constructor(t){this.data=t,this.next=null}}class Nh{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new jt(t);if(this.head===null)this._head=e;else{let n=this.head;for(;n.next;)n=n.next;n.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const n=new jt(e);if(t===0)n.next=this.head,this._head=n;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;n.next=i,r.next=n,t===this.length-1&&(this._tail=n)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,n=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,n=e,e=e.next;n.next=e.next,t===this.length-1&&(this._tail=n)}this.length--}getNodePosition(t){let e=0,n=this.head;for(;n;){if(n.data===t.data)return e;n=n.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class Xh extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._objects=new _t({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const n=e.paneId,r=this.objects[n];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[n,i]=e,r=new jt(n);return i.getNodePosition(r)}addObject(t){var e;const n=t.paneId,i=this.objects,r=(e=i[n])!=null?e:new Nh;Object.keys(i).find(o=>o===n)||(i[n]=r),r.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.setDynamicObjects(i)}removeObject(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);i.removeAt(o),this.modelIdToObjectMap.delete(t),i.size()===0&&delete this.objects[n.paneId],this.setDynamicObjects(this.objects)}moveToPosition(t,e){const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new jt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(n),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,n),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,n),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new jt(n),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,n),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class zh extends X{constructor(t,e){super();const n=new Xh(t);this.model=n,this.addChildEntity(n);const i=new jh(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Wh=()=>s=>s.toString(),Uh=(s,t)=>{var e;const n="date.get"+(t((e=s.timezone)!=null?e:"")?"":"UTC"),i={YYYY:o("FullYear"),YY:o("FullYear")+" % 100",MMM:a("shortMonths","Month"),MMMM:l(a("shortMonths","Month")),M:"1+"+o("Month"),d:o("Date"),H:o("Hours"),m:o("Minutes"),s:o("Seconds"),sss:o("Milliseconds"),EEE:a("shortDays","Day"),SSS:"this.addTwoZeros("+o("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(h){i[h+h]="this.addZero("+i[h]+")"});const r=new RegExp(Object.keys(i).sort().reverse().join("|"),"g");function o(h){return n+h+"()"}function a(h,d){return"this."+h+"["+o(d)+"]"}function l(h){return h+".toUpperCase()"}function c(h){return"' + ("+i[h]+") + '"}return function(h){var d;const u={shortDays:Vh(s),shortMonths:Gh(s),addZero(g){return g<10?"0"+g:g},addTwoZeros(g){return(g<100?"0":"")+(g<10?"0":"")+g},tzDate:t((d=s.timezone)!=null?d:"")||function(g){return g instanceof Date?g:new Date(+g)}};return new Function("date","date=this.tzDate(date); return '"+h.replace(r,c)+"'").bind(u)}};function Vh(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Gh(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const Mr=(s,t,e)=>{if(s){if(typeof s=="string")return e(s);if(Array.isArray(s)){const n=s.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(n.length>0){const i=n[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Wh()},Zh={"rhombus-small":4,rhombus:6,"rhombus-large":8},Pe=(s,t)=>`${s}_${t}`;class $h{constructor(t,e,n,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&(this.createCustomIcon("earnings",a.earnings),this.createCustomIcon("dividends",a.dividends),this.createCustomIcon("splits",a.splits),this.createCustomIcon("conference-calls",a.conferenceCalls))}createCustomIcon(t,e){if(e){const n=this.createIconImage(e.normal),i=this.createIconImage(e.hover);this.customIcons[Pe(t,"normal")]=n,this.customIcons[Pe(t,"hover")]=i}}createIconImage(t){var e;const i=new DOMParser().parseFromString(t,"text/html").querySelector("svg");let r=0;i&&(r=parseInt((e=i.getAttribute("height"))!=null?e:"",10));const l="data:image/svg+xml;base64,"+btoa(t),c=new Image;return c.src=l,{img:c,svgHeight:r}}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(x.EVENTS),e=this.canvasBoundsContainer.getBounds(x.ALL_PANES),n=this.canvasModel.ctx;n.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{const r=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(r>e.x&&r<e.x+e.width){const o=this.config.colors.events[i.type].color;n.strokeStyle=o,this.customIcons[Pe(i.type,"hover")]!==void 0?this.drawCustomSvgEvent(n,r,t,i):this.drawDefaultEvent(n,r,t,i,o),this.model.hoveredEvent.getValue()===i&&(n.beginPath(),n.moveTo(r,e.y),n.lineTo(r,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(r,i))}}),n.restore()}drawCustomSvgEvent(t,e,n,i){const r=n.y+n.height/2,o=this.customIcons[Pe(i.type,"normal")],a=this.customIcons[Pe(i.type,"hover")];this.model.hoveredEvent.getValue()===i?t.drawImage(a.img,e-a.svgHeight/2,r-a.svgHeight/2):t.drawImage(o.img,e-o.svgHeight/2,r-o.svgHeight/2)}drawDefaultEvent(t,e,n,i,r){const o=n.y+n.height/2;t.fillStyle=r,t.lineWidth=1.5;const a=Us(i);t.beginPath(),t.moveTo(e-a,o),t.lineTo(e,o-a),t.lineTo(e+a,o),t.lineTo(e,o+a),t.closePath(),this.model.hoveredEvent.getValue()===i?t.fill():t.stroke()}drawLabel(t,e){var n;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(x.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(n=this.config.components.xAxis.padding.top)!=null?n:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function Us(s){return Zh[s.style]}const ts=5;class Kh{constructor(t,e,n,i,r){this.hitTestCanvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r}draw(){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(x.EVENTS);t.save(),this.model.events.forEach((n,i)=>{const r=this.model.events[i-1],o=r&&this.chartModel.candleFromTimestamp(r.timestamp).xCenter(this.chartModel.scale),a=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(a>e.x&&a<e.x+e.width){const l=this.config.colors.events[n.type].color;t.strokeStyle=l,t.fillStyle=l;const c=Us(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const h=(c+ts)*2;if(o!==void 0){const d=Us(r);if(o+d>a-h/2){const g=c*2+ts;t.fillRect(o+d,e.y,g,e.height)}else t.fillRect(a-c-ts,e.y,h,e.height)}else t.fillRect(a-c-ts,e.y,h,e.height)}}),t.restore()}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var qh=Object.defineProperty,Ar=Object.getOwnPropertySymbols,Jh=Object.prototype.hasOwnProperty,Qh=Object.prototype.propertyIsEnumerable,Er=(s,t,e)=>t in s?qh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,td=(s,t)=>{for(var e in t||(t={}))Jh.call(t,e)&&Er(s,e,t[e]);if(Ar)for(var e of Ar(t))Qh.call(t,e)&&Er(s,e,t[e]);return s};const Lr=317,Vs={DRAWINGS:[1,199],NEWS:[200,299],DATA_SERIES:[300,2999],EVENTS:[3e3,4e3],EXECUTED_ORDERS:[4001,5e3]};class ed extends or{constructor(t,e,n,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=n,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new B,this.touchStartSubject=new B,this.dblClickSubject=new B,this.rightClickSubject=new B,this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,ar(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(ve(100,me,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=ft(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=ft(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ct(()=>td({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,n,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*Lr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Lr}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const n=window.devicePixelRatio;return this.prevAnimationFrameId!==Ys&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ys),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),n=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(n),[r]=Gs(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(n)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const n=this.getPixel(t.x,t.y),i=this.colorToId(n[0]*65536+n[1]*256+n[2]),r=Number(i),[o]=Gs(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var n,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[g,C]=Gs(this.hitTestSubscribers,u),S=g==null?void 0:g.lookup(d),_={point:t,model:S};switch(e){case"mousedown":S&&((n=g==null?void 0:g.onMouseDown)==null||n.call(g,S,t)),C.forEach(M=>M.onMouseDown&&M.onMouseDown(null,t));break;case"mouseup":S&&((i=g==null?void 0:g.onMouseUp)==null||i.call(g,S,t)),C.forEach(M=>M.onMouseUp&&M.onMouseUp(null,t));break;case"hover":S&&((r=g==null?void 0:g.onHover)==null||r.call(g,S,t)),C.forEach(M=>M.onHover&&M.onHover(null,t)),this.hoverSubject.next(_);break;case"touchstart":S&&((o=g==null?void 0:g.onTouchStart)==null||o.call(g,S,t)),C.forEach(M=>M.onTouchStart&&M.onTouchStart(null,t)),this.touchStartSubject.next(_);break;case"dblclick":S&&((a=g==null?void 0:g.onDblClick)==null||a.call(g,S,t)),this.dblClickSubject.next(_);break;case"contextmenu":S&&((l=g==null?void 0:g.onRightClick)==null||l.call(g,S,t)),this.rightClickSubject.next(_);break;case"zoom":S&&((c=g==null?void 0:g.onZoom)==null||c.call(g,S,t)),C.forEach(M=>M.onZoom&&M.onZoom(null,t));break;default:break}}}const Gs=(s,t)=>{let e;const n=[];return s.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:n.push(i)}),[e,n]};var sd=Object.defineProperty,nd=Object.defineProperties,id=Object.getOwnPropertyDescriptors,Dr=Object.getOwnPropertySymbols,rd=Object.prototype.hasOwnProperty,od=Object.prototype.propertyIsEnumerable,Ir=(s,t,e)=>t in s?sd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ad=(s,t)=>{for(var e in t||(t={}))rd.call(t,e)&&Ir(s,e,t[e]);if(Dr)for(var e of Dr(t))od.call(t,e)&&Ir(s,e,t[e]);return s},ld=(s,t)=>nd(s,id(t));class cd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new _t(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>ld(ad({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Vs.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class hd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>Mr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new cd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new $h(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Kh(n,i,t,r,c);this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(x.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){Lt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class dd{constructor(t,e,n,i,r,o,a,l,c=()=>!0,h){this.canvasModel=t,this.viewportModel=e,this.config=n,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.getBaseline=h}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;te(t,()=>this.drawVertical(t)),te(t,()=>this.drawHorizontal(t)),te(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const n=this.xBoundsProvider(),i=it(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(n.x,i),t.lineTo(n.x+n.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.xBoundsProvider(),i=n.x+n.width;for(const r of e){const o=V(this.viewportModel.toX(r.value));o>n.x&&o<i&&(t.beginPath(),t.moveTo(o,n.y),t.lineTo(o,n.y+n.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length&&this.config.components.grid.horizontal){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.yBoundsProvider();for(const i of e){const r=it(this.viewportModel.toY(i.value)),o=Oh(i.text,t,Pt);r>n.y+o&&r<n.y+n.height-o&&(t.beginPath(),t.moveTo(n.x,r),t.lineTo(n.x+n.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Br extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new dd(t,e,n,i,a,l,c,h,u,d)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class ud{constructor(t,e,n,i){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:n,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+n,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low");const c=this.canvasBoundsContainer.getBounds("PANE_CHART");l.restore(),Ut(l,c)}}drawMarkerLabel(t,e,n,i){const r=this.getMarkerY(t,n,i==="low"),o=ke(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(n,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?"H:":"L:"} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=ke(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(x.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,n){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(x.CHART),o=4,a=t.measureText(n).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class gd extends X{constructor(t,e,n,i,r){super();const o=new ud(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const fd=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],pd=24*60*60*1e3;class md extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new B}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+pd;Ha(this.highlights,t,e,vd).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,n)=>e.to-n.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const vd=s=>s.to,Vt=[20,10];class bd{constructor(t,e,n,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,n,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(x.ALL_PANES);o.save(),Ut(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(n=this.config.components.highlights.fontSize)!=null?n:11,g=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",C=`${u}px ${g}, monospace`;o.font=C,o.lineWidth=h,o.setLineDash(d),fd.forEach(S=>{var _,M;const I=a[S];if(I){const F=this.config.colors.highlights[S],j=(_=F==null?void 0:F.border)!=null?_:"#ffffff",R=(M=F==null?void 0:F.background)!=null?M:"#ffffff";o.save(),o.beginPath(),o.fillStyle=R,o.strokeStyle=j,I.forEach(H=>{var Y,Z,K;const W=this.chartModel.candleFromTimestamp(H.from),U=dt(W.width,this.chartModel.scale.zoomX),tt=W.xStart(this.chartModel.scale),J=this.chartModel.candleFromTimestamp(H.to),Q=dt(J.width,this.chartModel.scale.zoomX),et=J.xStart(this.chartModel.scale)+Q;if(H.border&&this.drawBorders(H.border,o,tt+U,et-Q,c),o.fillRect(tt,c.y,et-tt,c.y+c.height),H.label){const st=(Y=H.label.text)!=null?Y:"",ot=this.config.colors.highlights[H.type];o.save(),o.fillStyle=(Z=ot==null?void 0:ot.label)!=null?Z:"#ffffff";const Tt=yt(st,o,C),[St,Bt]=this.resolveHighlightLabelPosition((K=H.label.placement)!=null?K:"left-left",c,[tt,et],Tt);o.fillText(st,St,Bt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Vt[1]-i,e.y+Vt[0]];case"left-left":return[r-Vt[1]-i,e.y+Vt[0]];case"right-right":return[o+Vt[1],e.y+Vt[0]];case"left-right":default:return[r+Vt[1],e.y+Vt[0]]}}drawBorders(t,e,n,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(n,r.y),e.lineTo(n,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const Cd="HIGHLIGHTS_PLUGIN";class wd extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new md(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new bd(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,Cd)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function yd(){return N(function(s,t){var e,n=!1;s.subscribe(xt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function $(s,t){return N(function(e,n){var i=0;e.subscribe(xt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var Sd=Object.defineProperty,xd=Object.defineProperties,_d=Object.getOwnPropertyDescriptors,Or=Object.getOwnPropertySymbols,Pd=Object.prototype.hasOwnProperty,Td=Object.prototype.propertyIsEnumerable,Rr=(s,t,e)=>t in s?Sd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Fr=(s,t)=>{for(var e in t||(t={}))Pd.call(t,e)&&Rr(s,e,t[e]);if(Or)for(var e of Or(t))Td.call(t,e)&&Rr(s,e,t[e]);return s},Hr=(s,t)=>xd(s,_d(t));const Nt=4;class Md{constructor(t,e,n,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(x.N_MAP),n=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(x.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),n.width!==0&&this.drawLeftArrowButton(c,n,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,n,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,n,i){t.x<=n.x+n.width&&(t.x=n.x+n.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,n,i,r){this.blockDrawSliderOnLeftArrow(e,n,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,n,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Nt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+Nt,r+Nt),t.lineTo(i+Nt,r-Nt),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Nt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-Nt),t.lineTo(i,r+Nt),t.lineTo(i+Nt,r),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,n,i){const r=n.components.navigationMap.knots.border;t.fillStyle=n.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=n.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=n.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=n.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=pt(this.chartModel.mainCandleSeries.getSeriesInViewport()),n=this.config.components.navigationMap.timeLabels,i=n.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:n.fontFamily,textSize:`${n.fontSize}px`},d={dateFormat:n.dateFormat,padding:n.padding,textProperties:Hr(Fr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:Hr(Fr({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,n,i){const r=i.padding,o=Gn(n,i.dateFormat,this.formatterFactory);Wn(t,i.textProperties);const a=ke(t),l=Vn(o);Ya(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Te extends ur{constructor(t,e,n,i,r=dr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}doDeactivate(){super.doDeactivate()}}const kr=4;class Ad extends X{constructor(t,e,n,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=n,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=g=>{const C=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=g.x-C.x-kr},this.leftKnotDragTick=g=>{const{delta:C}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.leftKnotDragStartXRelative+C)/_;this.canvasBoundsContainer.leftRatio=M,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=g=>{const C=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=g.x-C.x+kr},this.rightKnotDragTick=g=>{const{delta:C}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.rightKnotDragStartXRelative+C)/_;this.canvasBoundsContainer.rightRatio=M,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=g=>{const{delta:C}=g,S=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),_=this.chartModel.mainCandleSeries.meanCandleWidth/(S.width/this.chartModel.mainCandleSeries.dataPoints.length),M=(this.lastMousePosition-C)*_;this.scale.moveXStart(this.scale.xStart-M),this.lastMousePosition=C};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Te(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Te(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_SLIDER_WINDOW),u=new Te(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const n=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=n.dataIdxStart/(n.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=n.dataIdxEnd/(n.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class Ed extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=n,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new Md(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new Ad(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(x.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(x.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(x.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(x.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(x.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(x.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(yd(),$(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const n=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-n,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),h=c.width,d=[];let u=0,g,C;for(g=0;g<h;g++)C=it(g*o/h)-r,C in e?(d[g]=e[C].close,u=(t=d[g])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[g]=0;return a-=l,d.map((S,_)=>[_+c.x,(a+l-S)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(Fs),this.canvasModel.fireDraw())}}class Ld extends X{constructor(t,e,n){super(),this.scale=t,this.canvasInputListeners=e,this.mainCanvasParent=n,this.touchedCandleIndexes=[0,0]}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(t=>this.handleTouchMoveEvent(t)))}handleTouchStartEvent(t){t.touches.length===2&&(this.touchedCandleIndexes=this.getXPositions(t).map(e=>this.scale.fromX(e)))}handleTouchMoveEvent(t){t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),n=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];n[r]=a.pageX-e.left-i}return n}pinchHandler(t,e){const n=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=n+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;this.scale.setXScale(n,i)}}const Yr=()=>{const s=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(n=>navigator.userAgent.match(n));return s?"apple":e?"mobile":"other"},Jf=(s,t)=>s==="apple"||s==="mobile"?3:t,Dd=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Id=!!window.chrome,jr=typeof InstallTrigger!="undefined",Bd=navigator.platform.indexOf("Win")>-1,Nr=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(Dd)i=e===s.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(s.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(s.deltaY)*3);else if(Id){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,Bd){const r=Math.round(s.deltaY)===e||Math.abs(Math.round(s.deltaY)+Math.sign(s.deltaY))===Math.abs(e)||Math.abs(Math.round(s.deltaY)-Math.sign(s.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(s.deltaY)||r}}else jr?Math.abs(s.deltaY)>Math.abs(s.deltaX)?i=!1:i=n===s.deltaX*-3:i=e===s.deltaY*-3;i&&(t=!0)}else s.deltaMode===0&&(t=!0);return jr&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},Xr=(s,t)=>s==="percent"?t/4:t;var Zs=Math.pow;class Od extends X{constructor(t,e,n,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=n,this.mainCanvasParent=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.canvasAnimation=a,this.chartPanComponent=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelTrottleTime=15,this.zoomXHandler=(d,u)=>{const g=d.deltaY<0;if(this.config.scale.zoomToCursor){const S=this.canvasBoundsContainer.getBounds(x.CANVAS).width,M=d.offsetX/S;this.scale.zoomXToPercent(M,g,!1,u)}else this.scale.zoomXToEnd(g,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(bs),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const g=Yt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-g),this.bus.fireDraw()},this.touchHandler=new Ld(this.scale,this.canvasInputListener,this.mainCanvasParent);const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Te(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(ft(this.canvasInputListener.observeWheel(t),this.canvasInputListener.observePinch(t)).pipe(ve(this.wheelTrottleTime,me,{trailing:!0,leading:!0})).subscribe(e=>{const i=Nr(e)?Xr(this.config.components.yAxis.type,this.config.scale.zoomSensitivity.pinch):this.config.scale.zoomSensitivity.wheel;this.zoomXHandler(e,i)})),this.addRxSubscription(this.canvasInputListener.observeScrollGesture().pipe(ve(this.wheelTrottleTime,me,{trailing:!0,leading:!0})).subscribe(e=>{let n=-1;const i=Yr();(i==="apple"||i==="mobile")&&(n=1);let r=0,o=0;if(r+=e.deltaX*n,o+=e.deltaY*-n,r!==0&&Math.abs(r)>Math.abs(o)){const a=Yt(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a)}else if(o!==0&&Math.abs(o)>Math.abs(r)){const a=Xr(this.config.components.yAxis.type,this.config.scale.zoomSensitivity.glide);this.zoomXHandler(e,a)}this.bus.fireDraw()})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e})),this.touchHandler.activate(),this.addSubscription(this.touchHandler.deactivate.bind(this.touchHandler))}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(bs),this.currentPoint={x:0,y:0},n=t.yStart},r=a=>{const{delta:l}=a;if(this.currentPoint.y=l,t.state.auto)Rd(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const c=Yt(t.state.inverse?-l:l,t.zoomY);t.moveYStart(n+c)}},o=new $e(e,{onDragTick:r,onDragStart:i},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});return this.addChildEntity(o),o}}const Rd=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Zs(Zs(Math.abs(s.x),2)+Zs(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle};class Fd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=n,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.chartPanComponents=[],this.chartAreaPanHandler=new Od(this.eventBus,this.config,this.mainScale,this.mainCanvasParent,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this),this.chartPanComponents.push(this.chartAreaPanHandler)}doActivate(){this.activateChartPanHandlers()}doDeactivate(){this.deactivatePanHandlers()}activateChartPanHandlers(){this.chartPanComponents.forEach(t=>t.activate())}deactivatePanHandlers(){this.chartPanComponents.forEach(t=>t.deactivate())}}const zr=s=>t=>{const{top:e,bottom:n}=s(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*n/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},Wr=(s,t)=>{const e=zr(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function Hd(){return En(1)}function Ur(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return Hd()(Re(s,Oe(s)))}function kd(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Oe(s);return N(function(n,i){(e?Ur(s,n,e):Ur(s,n)).subscribe(i)})}function Yd(s){return $(function(t,e){return s<=e})}class jd{constructor(t,e,n,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=n,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),n=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(n.fillStyle=i.getColor(0),n.fillRect(e.x,e.y-r,e.width,e.height+2*r)),n.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?n.fillRect(e.x,e.y,e.width,e.height):n.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Nd extends X{constructor(t,e,n,i,r,o,a,l,c,h,d){super(),this.id=t,this.boundsProvider=e,this.hitTest=n,this.dragTickCb=i,this.chartPanComponent=r,this.canvasModel=o,this.drawingManager=a,this.canvasInputListener=l,this.canvasAnimation=c,this.config=h,this.canvasBoundsContainer=d,this.initialY=0,this.resizeEvent$=new B,this.onYDragStart=()=>{this.config.components.crossTool.type="none",this.initialY=this.boundsProvider().y},this.onYDragEnd=()=>{this.config.components.crossTool.type="cross-and-labels",this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio)},this.onYDragTick=u=>{const{delta:g,draggedPixels:C}=u;Math.abs(this.initialY-this.boundsProvider().y+C)>=0&&(this.dragTickCb(g),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new $e(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent);this.addChildEntity(n),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(kd(!1),Et(),Yd(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new jd(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,hr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(hr.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const Xd=s=>t=>{let e;if(typeof t=="number")e=t;else if(typeof t=="string")e=Number(t);else return"\u2014";const[n]=s.dataSeries;if(n!==void 0){const i=It.getPricePrecision(e,n.pricePrecisions);return e.toFixed(i)}return`${e}`},zd=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=_i(t,r.getBaseline()));const o=i.toFixed(It.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Wd=s=>({percent:zd(s),regular:Xd(s)});class Ud extends X{constructor(t,e,n,i,r,o,a,l,c,h,d=new Set,u={regular:Di}){super(),this.paneUUID=t,this.idx=e,this.paneComponent=n,this.chartBaseModel=i,this.canvasBoundsContainer=r,this.hitTestController=o,this.dynamicObjectsCanvasModel=a,this.scale=l,this.dragNDrop=h,this.dataSeries=d,this.formatters=u,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(C=>new we(this.chartBaseModel.dataFromTimestamp(C.timestamp).centerUnit,C.close)),this.toY=g=>{var C,S;return(S=(C=this.mainDataSeries)==null?void 0:C.view.toY(g))!=null?S:1},this.valueFormatter=(g,C)=>{var S;return((S=this.formatters[this.yAxis.getAxisType()])!=null?S:this.formatters.regular)(g,C)},this.addChildEntity(l),this.setValueFormatters(Wd(this)),this.yAxis=c(this.valueFormatter.bind(this),()=>this.mainDataSeries),this.addChildEntity(this.yAxis)}doDeactivate(){super.doDeactivate(),this.dataSeries.forEach(t=>{this.paneComponent.seriesRemovedSubject.next(t),t.deactivate()})}getBounds(){return this.scale.getBounds()}getBaseline(){var t,e;return(e=(t=this.mainDataSeries)==null?void 0:t.getBaseline())!=null?e:1}createDataSeries(){const t=new Li(this,Ct(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){this.dataSeries.add(t),this.dataSeries.size===1&&(this.mainDataSeries=t),this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,n;return(n=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?n:this.scale.fromY(t)}}const Vr=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return Wi(e)}});class Vd{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Vs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Vs.DATA_SERIES}get allDataSeries(){return ge(ge(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(n=>n.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.hovered=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(n=>n.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Xt="#FF00FF";function Qf(s,t,e,n){const i=s.yAxis.backgroundColor,r=s.chartAreaTheme.backgroundColor,o=s.chartAreaTheme.backgroundGradientTopColor,a=s.chartAreaTheme.backgroundGradientBottomColor,l=n.align==="left"?o:a,c=s.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const Gd=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Zd=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:Xt},$d=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:Xt},Kd=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:Xt},qd=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Xt},Jd=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Xt},Qd=(s,t)=>{const e=t.histogram[`${s}Cap`];return e!=null?e:Xt},tu=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Xt},Gr=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:Xt},eu=()=>(console.warn("Fallback for label default color"),Xt);function su(s,t){if(s.filter(a=>a!==null).length<=1)return s.map(a=>a.y);const e=t-2,n=s.map((a,l)=>nu(a,l,e)).filter(jn).sort(iu),i=new Array(n.length),r=n.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=n.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=n[a],c=n[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<n.length;a++){const l=n[a],c=n[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const nu=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,iu=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var ru=Object.defineProperty,ou=Object.defineProperties,au=Object.getOwnPropertyDescriptors,Zr=Object.getOwnPropertySymbols,lu=Object.prototype.hasOwnProperty,cu=Object.prototype.propertyIsEnumerable,$r=(s,t,e)=>t in s?ru(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Kr=(s,t)=>{for(var e in t||(t={}))lu.call(t,e)&&$r(s,e,t[e]);if(Zr)for(var e of Zr(t))cu.call(t,e)&&$r(s,e,t[e]);return s},qr=(s,t)=>ou(s,au(t));const $s={MAIN:"MAIN"};class hu extends X{constructor(t,e,n,i,r,o,a){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.orderedLabels=[],this.customLabels={},this.labelsProviders={},this.labelsPositionRecalculatedSubject=new B,this.animFrameId=`anim_cache_${Ct()}`,this.initModel()}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),Ns(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const n=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=pt(Object.values(i).map(l=>l.getUnorderedLabels())),o=pt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=su(o,n);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,n){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][n]=t))}updateLabelsCoordinates(t,e){return qr(Kr({},t),{labels:t.labels.map((n,i)=>qr(Kr({},n),{lineY:n.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,n){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[n]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var n;const i=(n=this.labelsProviders[t])!=null?n:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}const Jr=10;class du extends X{constructor(t,e,n,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.autoScaleCallback=l,this.yAxisDragEndSubject=new B,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=this.bounds.getBounds(x.Y_AXIS).height},this.onYDragTick=c=>{const{delta:h}=c;let d;h<0?d=1/(1+-h/this.lastYPxHeight*(Jr-1)):d=1+h/this.lastYPxHeight*(Jr-1);const g=(this.lastYHeight*d-this.lastYHeight)/2,C=this.lastYStart-g,S=this.lastYEnd+g;(this.lastYStart!==C||this.lastYEnd!==S)&&(this.scale.setYScale(C,S),this.autoScaleCallback(!1),this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next()},e.customScale){const c=()=>e.type!=="percent"&&e.visible,h=new $e(a,{onDragTick:Ks(this.onYDragTick,c),onDragStart:Ks(this.onYDragStart,c),onDragEnd:Ks(this.onYDragEnd,c)},r,n,{disableChartPanning:!1});this.addChildEntity(h)}}doActivate(){this.config.customScaleDblClick&&this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.autoScaleCallback(!0),this.bus.fireDraw()}))}}const Ks=(s,t)=>(...e)=>t()&&s(...e);class uu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${Ct()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),cr(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const gu=0,fu=.01;class qs{constructor(t,e,n,i,r=!1,o,a,l=Cs,c=23){this.increment=t,this.startEndProvider=e,this.lengthProvider=n,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new B,this.newGeneratedLabelsSubject=new B,this.lastStart=0,this.lastEnd=0,this.labelsCache=new uu(()=>this.labelFilter(this.doGenerateLabels()))}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=ht.roundToNearest(t,n);for(;r<e;){const o=ht.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=ht.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=ht.roundToNearest(t,n);for(;o<e;){const a=ht.roundToNearest(o,n),l=Pi(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=ht.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=ht.roundToNearest(t,n);for(;r<e;){const o=Os(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=ht.roundDecimal(r+n)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[n,i]=this.calculateMinMax(),r=this.getAxisStep(n,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(n,i,r):a==="percent"?o=this.generatePercentLabels(n,i,r):o=this.generateRegularLabels(n,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),n=this.lengthProvider(),i=qs.getLabelBounds(t,e,n);return[i[0],i[1]]}getAxisStep(t,e,n){const i=e-t,r=n/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){if(this.increment)return this.increment;if(!isNaN(t)){const e=It.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(e)}return this.adjustIncrementOnAxisType(fu)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Os(e)+t;return Ti(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,n){const i=Math.abs((e-t)*(gu/n));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let n=e,i=e,r=0;for(;n<t&&n>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),n=i*this.gridDistanceMultipliers[r++];return n}}class pu extends qs{constructor(t,e,n,i,r=()=>"regular",o=23){super(t,()=>[n.yStart,n.yEnd],()=>n.getBounds().height,i,!1,r,()=>{var a,l;return(l=(a=e())==null?void 0:a.getBaseline())!=null?l:1},void 0,o),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,n)=>n.text.length>e.length?n.text:e,"")}calculateIncrement(t){var e;const n=this.dataSeriesProvider();if(n){const i=wt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=Ql(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function Qr(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?N(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(xt(r,function(l){var c;(c=n.next)===null||c===void 0||c.call(n,l),r.next(l)},function(){var l;a=!1,(l=n.complete)===null||l===void 0||l.call(n),r.complete()},function(l){var c;a=!1,(c=n.error)===null||c===void 0||c.call(n,l),r.error(l)},function(){var l,c;a&&((l=n.unsubscribe)===null||l===void 0||l.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):ie}class mu extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=n,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${Ct()}`}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ct(t=>t.height),$(t=>ga(t,this.prevYAxisHeight,1.5)),Qr(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),Ns(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class vu extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new pu(null,l,o,a,()=>this.state.type,n.labelHeight),this.baseLabelsModel=new mu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new hu(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths()),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(n=>n.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(n=>n.labels).map(n=>n.labelText)).reduce((n,i)=>i.length>n.length?i:n,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class bu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasBoundsContainer=o,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new B,this.state=Ce(e.components.yAxis),this.yAxisScaleHandler=new du(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),g=>i.autoScale(g)),this.addChildEntity(this.yAxisScaleHandler),this.model=new vu(this.paneUUID,t,this.state,o,n,i,c,h,u),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Kd),this.registerLabelColorResolver("bar",Zd),this.registerLabelColorResolver("line",$d),this.registerLabelColorResolver("area",qd),this.registerLabelColorResolver("scatterPlot",Jd),this.registerLabelColorResolver("histogram",Qd),this.registerLabelColorResolver("baseline",tu),this.registerLabelColorResolver("trend",Gr),this.registerLabelColorResolver("hollow",Gr)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:eu}registerYAxisLabelsProvider(t,e=$s.MAIN,n=Ct()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,n),n}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=$s.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.enable():this.disable(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t){this.scale.state.inverse=t,this.scale.inverseY=t,this.scale.scaleInversedSubject.next(t)}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Cu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,C,S,_,M,I){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=n,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=g,this.canvasBoundsContainer=C,this.uuid=S,this.seriesAddedSubject=_,this.seriesRemovedSubject=M,this._paneOrder=0,this.yExtentComponents=[],this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(j,R)=>this.mainExtent.valueFormatter(j,R);const F=this.createExtentComponent(I);this.mainExtent=F,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(S),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return ge(this.yExtentComponents,t=>Array.from(t.dataSeries))}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.uuid)).pipe(Et(hi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,n;return(n=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?n:this.scale.toY(t)}createGridComponent(t,e,n,i){const r=x.PANE_UUID(t);return new Br(this.mainCanvasModel,e,this.config,i,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(r),()=>this.canvasBoundsContainer.getBounds(r),()=>[],()=>n.generateNumericLabels())}createYPanHandler(t,e){const n=x.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(n));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const n=x.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(n,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(n)}createExtentComponent(t){var e,n;const i=this.yExtentComponents.length,r=x.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new Dc(this.mainScale,this.config,o,this.canvasAnimation),[l,c]=this.createYPanHandler(this.uuid,a),h=(C,S)=>new bu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,C,S,this.uuid,i),d=new Ud(this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,h,c);d.addSubscription(l),d.addSubscription(this.addCursors(i,d.yAxis)),t!=null&&t.paneFormatters&&d.setValueFormatters(t.paneFormatters),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",Wr(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),Vr(d)));const g=this.createGridComponent(this.uuid,a,d.yAxis.model.labelsGenerator,d.yAxis.state);return d.addChildEntity(g),d.activate(),this.yExtentComponents.push(d),this.canvasBoundsContainer.updateYAxisWidths(),d}removeExtentComponent(t){t.disable(),this.yExtentComponents.splice(t.idx,1),this.yExtentComponents.forEach((e,n)=>e.idx=n),this.canvasBoundsContainer.updateYAxisWidths()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(n=>n.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}hide(){this._paneOrder=this.canvasBoundsContainer.panesOrder.indexOf(this.uuid),this.canvasBoundsContainer.removedPaneBounds(this.uuid),this.eventBus.fireDraw()}show(){this.canvasBoundsContainer.addPaneBounds(this.uuid,this._paneOrder),this.eventBus.fireDraw()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=fe(this.canvasBoundsContainer.panesOrder);return this.uuid!==t}canMoveDown(){const t=wt(this.canvasBoundsContainer.panesOrder);return this.uuid!==t}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}class wu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,C,S){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=n,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=g,this.mainCanvasModel=C,this.yAxisLabelsCanvasModel=S,this.panes={},this.paneRemovedSubject=new B,this.paneAddedSubject=new B,this.dataSeriesAddedSubject=new B,this.dataSeriesRemovedSubject=new B,this.hitTestController=new Vd(this.panes,this.dynamicObjectsCanvasModel);const _=this.createPane(q,{useDefaultHighLow:!1,scale:this.mainScale});_.mainExtent.scale.autoScaleModel.setHighLowProvider("series",Vr(_.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",zr(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removedPaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone}),n=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},i=x.PANE_UUID_RESIZER(t),r=new Nd(i,()=>this.canvasBoundsContainer.getBounds(i),e,n,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer);return this.userInputListenerComponents.push(r),r}get yExtents(){return ge(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(n=>this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(n.uuid))(t.x,t.y))}createPane(t=Ct(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new Cu(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,e);return this.config.components.paneResizer.visible&&n.addChildEntity(this.addResizer(t)),n.addSubscription(this.addBounds(t,e==null?void 0:e.order)),n.addSubscription(this.addCursors(t)),n.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,n.ht)),this.panes[t]=n,n.activate(),this.recalculateState(),n.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),n}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(n=>n.disable()),delete this.panes[t],this.recalculateState())}addCursors(t,e=this.config.components.chart.cursor){const n=x.PANE_UUID(t),i=x.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(n,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone),()=>{this.cursorHandler.removeCursorForCanvasEl(n),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class yu extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,n=this.canvasModel.ctx;if(n){n.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return n.drawImage(this.elements.backgroundCanvas,0,0,i,r),n.drawImage(this.elements.mainCanvas,0,0,i,r),n.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),n.drawImage(this.elements.crossToolCanvas,0,0,i,r),n.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(n),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const Su=(s,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function n(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return n(s)},es=class extends X{constructor(s,t,e,n,i){super(),this.chartComponent=s,this.drawingManager=t,this.config=e,this.volumesModel=n,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var s,t;return!((s=this.pane)!=null&&s.scale.isViewportValid())&&((t=this.pane)==null?void 0:t.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var s;return(s=this.pane)==null?void 0:s.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[es.UUID]===void 0){const t=this.paneManager.createPane(es.UUID,{paneFormatters:{regular:i=>Su(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=Wr(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);e.autoScaleModel.setHighLowProvider("volumes",n),e.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(es.UUID),delete this.pane,this.drawingManager.removeDrawerByName("UNDERLAY_VOLUMES_AREA")}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let to=es;to.UUID="volumes";const ss=.3,xu=(s,t)=>{const e=t.barTheme[`${s}Color`];return At()(e).alpha(ss).toString()},_u=(s,t)=>{const e=t.volume[`${s}BarColor`];return At()(e).alpha(ss).toString()},Pu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return At()(e).alpha(ss).toString()},Js=(s,t)=>{const e=t.candleTheme[`${s}Color`];return At()(e).alpha(ss).toString()},Tu=3;class Mu{constructor(t,e,n,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=n,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const n=(e=this.volumesColorByChartTypeMap[t])!=null?e:_u;this.volumeBarColors.down=n("down",this.config.colors),this.volumeBarColors.up=n("up",this.config.colors),this.volumeBarColors.none=n("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const n=this.getViewportModel().getBounds();Ut(e,n),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const n=pt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();n.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=n[o+1]!==void 0?V(i.toX(n[o+1].startUnit)):void 0,h=V(i.toX(r.startUnit)),d=c!==void 0?c-h:V(dt(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=V(i.toY(r.candle.volume)),g=V(i.toY(0))-u;this.drawVolume(t,r,h,u,d,g)}else{const u=e/(l/Tu),g=Math.max(dt(r.candle.volume,u),2),C=V(a.y+l-g);this.drawVolume(t,r,h,C,d,g)}}})}drawVolume(t,e,n,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(n,l),a.lineTo(n,Ci(c)),a.stroke()):a.fillRect(n,i,r,Ci(o))}}const Au=Fa(s=>s.candle.volume),eo="volumes";class Eu extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=eo,this.volumeMax=new _t(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;this.volumeMax.next((t=fe(Au(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class Lu extends X{constructor(t,e,n,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new _t(!1),this.volumeIsSeparateModeChangedSubject=new _t(!1);const c=new Eu(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new to(e,r,o,c,a),this.volumesDrawer=new Mu(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:n},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.addVolumesToDynamicObjects(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",Js),this.registerVolumeColorResolver("trend",Js),this.registerVolumeColorResolver("hollow",Js),this.registerVolumeColorResolver("line",Pu),this.registerVolumeColorResolver("bar",xu)}setShowVolumesSeparatly(t){this.config.components.volumes.showSeparately!==t&&(this.config.components.volumes.showSeparately=t,t?this.separateVolumes.activateSeparateVolumes():this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(t))}doDeactivate(){super.doDeactivate(),this.setVisible(!1)}registerVolumeColorResolver(t,e){this.volumesColorByChartTypeMap[t]=e}setVisible(t=!0){this.config.components.volumes.visible=t,this.volumeVisibilityChangedSubject.next(t),t?this.addVolumesToDynamicObjects():this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.canvasModel.fireDraw()}addVolumesToDynamicObjects(){this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1&&this.dynamicObjectsComponent.model.addObject({id:this.volumesModel.id,paneId:this.config.components.volumes.showSeparately?eo:q,drawer:this.volumesDrawer,model:this.volumesModel})}}class Du{constructor(t,e,n,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=n,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,g=this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)),{position:C,offsetY:S,offsetX:_}=this.config.components.waterMark;let M;switch(d?M=d:(u.font=ns(this.config,l),M=u.measureText(a).width,g.width-10<M&&(u.font=Iu(this.config,this.canvasBoundsContainer,l,M),M=u.measureText(a).width)),C){case"left-top":return{x:_+g.x,y:S+o+g.y,font:u.font,text:a,color:c};case"left-bottom":return{x:_+g.x,y:g.height-h-S+o+g.y,font:u.font,text:a,color:c};case"center":return{x:g.width/2-M/2+g.x,y:(g.height-h)/2+o+g.y,font:u.font,text:a,color:c}}}}draw(){var t,e,n,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,g=this.canvasModel.ctx;let C=0,S=0,_=0,M=0,I=0;if(g.save(),d.firstRowFontSize&&l){g.font=ns(this.config,d.firstRowFontSize);const H=g.measureText(l);C=H.actualBoundingBoxAscent+H.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){g.font=ns(this.config,d.secondRowFontSize);const H=g.measureText(c);S=H.actualBoundingBoxAscent+H.actualBoundingBoxDescent,_=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){g.font=ns(this.config,d.thirdRowFontSize);const H=g.measureText(h);M=H.actualBoundingBoxAscent+H.actualBoundingBoxDescent,I=(n=d.secondRowBottomPadding)!=null?n:0}const F=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,R=C+S+_+M+I+F+j;if(l&&this.drawWaterMark(this.getConfig(C,l,d.firstRowFontSize,u.firstRowColor,R)),c&&this.drawWaterMark(this.getConfig(C+_+S,c,d.secondRowFontSize,u.secondRowColor,R)),h&&this.drawWaterMark(this.getConfig(C+_+S+I+M,h,d.thirdRowFontSize,u.thirdRowColor,R)),this.logoImage){const H=this.getConfig(C+_+S+I+M+F,"",d.thirdRowFontSize,u.thirdRowColor,R,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,H.x,H.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}g.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const n=this.canvasModel.ctx;n.font=t.font,n.fillStyle=t.color;const i=t.x,r=t.y;n.fillText(e,i,r)}reset(){}}const Iu=(s,t,e,n)=>{const r=((a,l)=>t.getBounds(x.CHART).width/l*a)(e,n);let o;return s.components&&s.components.waterMark&&(o=s.components.waterMark.fontFamily),r+"px "+o},ns=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Bu=Object.defineProperty,so=Object.getOwnPropertySymbols,Ou=Object.prototype.hasOwnProperty,Ru=Object.prototype.propertyIsEnumerable,no=(s,t,e)=>t in s?Bu(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,io=(s,t)=>{for(var e in t||(t={}))Ou.call(t,e)&&no(s,e,t[e]);if(so)for(var e of so(t))Ru.call(t,e)&&no(s,e,t[e]);return s};class Fu extends X{constructor(t,e,n,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=n,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new Du(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Lt(r.observeBoundsChanged(x.PANE_UUID(q)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Lt(e,t),Lt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return io(io({},this.config.components.waterMark),h)}}const ro={x:4,y:4};function Hu(s,t,e,n){var i,r;const o=(i=n.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(x.X_AXIS);s.save(),s.font=`bold ${a}px ${l}`;const C=s.measureText(n.text).width+ro.x*2;let S=0;const _=n.x;switch(o){case"start":S=_-C;break;case"end":S=_;break;case"middle":default:S=_-C/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(S,u.y,C,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(_,u.y),s.lineTo(_,u.y+u.height),s.stroke()),s.fillStyle=n.color;const M=S+ro.x,I=u.y+d+a;s.fillText(n.text,M,I),s.restore()}class ku{constructor(t,e,n,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=n,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Hu(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},n=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(n).forEach(i=>{const r=n[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.fillStyle=At().rgb(r[0].color).alpha(.1).toString(),tr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const tp="week-weekday",Yu=["second","minute","hour","day","month","year"],ju=["lessThanSecond"],Nu=s=>Yu.some(t=>t===s),Xu=s=>s==="week-weekday",zu=s=>ju.some(t=>t===s),oo=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},Qs=s=>parseInt(s,10),ao=s=>{const[t,...e]=s.split("_");if(Nu(t)){const[n]=e,i=oo(n),r=Qs(n);return{key:t,value:r,exact:i["!"]}}else if(Xu(t)){const[n,i]=e,r=oo(n),o=Qs(n),a=Qs(i);return{key:t,week:r.$?"$":o,weekday:a}}else return zu(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats https://webdev.prosp.devexperts.com:8095/docs/chart/x-axis`),null)};class is{constructor(t,e,n,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=n,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,n=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=is.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a),e.restore()}}drawLabels(t,e,n,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-yt(c.text,t,l)/2,d=n.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const tn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},lo=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return tn[s.key]+s.value;case"lessThanSecond":return tn[s.key];case"week-weekday":return tn[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},co=s=>{const t={};for(const e of s){const n=t[e.weight];n===void 0?t[e.weight]=[e]:n.push(e)}return t},Wu=(s,t)=>{const e=Object.keys(s).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let n=[];for(const i of e){const r=s[i];if(!r)continue;const o=[...n];n=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const g=r[u],C=g.idx;for(;c<a;){const S=o[c],_=S.idx;if(C>_)c++,n.push(S),d=_,h=1/0;else{h=_;break}}h-C>=t&&C-d>=t&&(n.push(g),d=C)}for(;c<a;)n.push(o[c]),c++}return n},Uu=(s,t,e,n,i,r)=>{const o=is.getFontFromConfig(t),a=yt(e.text,s,o),l=yt(n.text,s,o),c=i.toX(e.value)+a/2;return i.toX(n.value)-l/2-c<r};function en(s){"@babel/helpers - typeof";return en=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},en(s)}function mt(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function vt(s){mt(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||en(s)==="object"&&t==="[object Date]"?new Date(s.getTime()):typeof s=="number"||t==="[object Number]"?new Date(s):((typeof s=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Vu(s){return mt(1,arguments),vt(s).getDay()===1}function Gu(s){return mt(1,arguments),vt(s).getDay()===2}function Zu(s){return mt(1,arguments),vt(s).getDay()===3}function $u(s){return mt(1,arguments),vt(s).getDay()===4}function Ku(s){return mt(1,arguments),vt(s).getDay()===5}function qu(s){return mt(1,arguments),vt(s).getDay()===6}function Ju(s){return mt(1,arguments),vt(s).getDay()===0}function Qu(s,t){var e;mt(1,arguments);var n=s||{},i=vt(n.start),r=vt(n.end),o=r.getTime();if(!(i.getTime()<=o))throw new RangeError("Invalid interval");var a=[],l=i;l.setHours(0,0,0,0);var c=Number((e=t==null?void 0:t.step)!==null&&e!==void 0?e:1);if(c<1||isNaN(c))throw new RangeError("`options.step` must be a number greater than 1");for(;l.getTime()<=o;)a.push(vt(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function tg(s){mt(1,arguments);var t=vt(s);return t.setDate(1),t.setHours(0,0,0,0),t}function eg(s){mt(1,arguments);var t=vt(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function ho(s){mt(1,arguments);var t=vt(s);return t.setHours(0,0,0,0),t}function uo(s,t){mt(2,arguments);var e=ho(s),n=ho(t);return e.getTime()===n.getTime()}const sg=s=>{switch(s.key){case"lessThanSecond":return og(s);case"month":return ag(s);case"second":case"minute":case"hour":case"day":case"year":return lg(s);case"week-weekday":return cg(s);default:return()=>!1}},Gt=(s,t)=>{switch(t){case"lessThanSecond":return s.getMilliseconds();case"month":return s.getMonth();case"second":return s.getSeconds();case"minute":return s.getMinutes();case"hour":return s.getHours();case"day":return s.getDate();case"year":return s.getFullYear();case"week-weekday":return s.getDate()}},sn=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n!==i},ng=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n>=i},ig={1:Vu,2:Gu,3:Zu,4:$u,5:Ku,6:qu,7:Ju},rg=(s,t,e)=>{var n;const i=Qu({start:tg(s),end:eg(s)}),r=(n=ig[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return uo(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return uo(s,a);o++}}return!1},go=(s,t)=>t===1?s===1:s/t===1,fo=(s,t)=>t===1?!0:s%t===0,og=s=>(t,e)=>ng(s.key)(t,e),ag=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?go(Gt(t,s.key)+1,s.value):fo(Gt(t,s.key)+1,s.value);return n&&i},lg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?go(Gt(t,s.key),s.value):fo(Gt(t,s.key),s.value);return n&&i},cg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=rg(t,s.week,s.weekday);return n&&i},hg=s=>{switch(s.key){case"second":case"minute":return dg(s.value);case"hour":return ug(s.value);case"day":return gg(s.value);case"month":return mg(s.value);case"year":return vg(s.value);case"week-weekday":const t=pg(s.week),e=fg(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},dg=s=>s>0&&s<=60,ug=s=>s>0&&s<=24,gg=s=>s>0&&s<=31,fg=s=>po(s)?s>=1&&s<=7:!1,pg=s=>s==="$"?!0:po(s)?s>=1&&s<=6:!1,mg=s=>s>0&&s<=12,vg=s=>s>0,po=s=>!isNaN(s)&&isFinite(s),bg=(s,t,e)=>{var n,i;for(const[r,o]of e)if(o(s,t))return r;return(i=(n=e[e.length-1])==null?void 0:n[0])!=null?i:0};function nn(s,t,e){const n=new Array(s.length);let i=e(0);for(let r=0;r<s.length;r++){const o=s[r],a=e(o.candle.timestamp),l={weight:bg(a,i,t)};n[r]=l,i=a}return n}const mo=s=>{const t={},e={};return Is(s).forEach(([n,i])=>{const r=ao(n),o=r===null?!1:hg(r);if(r&&o){const a=lo(r);t[a]=i,e[a]=sg(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class vo{constructor(t,e,n,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=n,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?dt(d,h.animationConfig.targetZoomX):dt(d,this.scale.zoomX);if(!isFinite(u))return-1;const g=this.config.components.xAxis.fontSize,C=Object.values(this.formatsByWeightMap).reduce((_,M)=>Math.max(M.length,_),1),S=g*C;return Math.round(S/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=mo(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(x.X_AXIS),n=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||n.push(i)}return n}getLabelsFromChartType(){var t,e;const n=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(n):n}getAllCandlesWithFake(){const t=this.chartModel.mainCandleSeries.visualPoints;if(t.length===0)return[];const n=Array.from({length:750}).map((i,r)=>Ii(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,t.length+r,this.chartModel.getPeriod()));return[...t,...n]}mapWeightedPointsToLabels(t,e){var n;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(n=a.candle.idx)!=null?n:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:n}=mo(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(n).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateWeightedLabels()}generateWeightedLabels(){const t=this.getAllCandlesWithFake(),e=nn(t,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),n=this.mapWeightedPointsToLabels(e,t);this.labelsGroupedByWeight=co(n),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=nn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(g=>g.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),n=nn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=co(i),o=Ce(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),g=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&g.shift(),g){const C=g.map(S=>(S.idx=S.idx+t.length,S.value=a.startUnit+a.width+S.value,S));r[u]?c[h]=d.concat(C):c[h]=C}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(){this.generateWeightedLabels()}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const n=Wu(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=n,this.weightedCache={labels:n,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,n;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Uu(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((n=a.weight)!=null?n:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const n=Is(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=ao(o);if(l){const c=lo(l);i[c]=a}}return i},{});return Is(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class Cg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(Ve,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}class wg extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.lastXStart=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const a=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=a.width-this.canvasInputListener.currentPoint.x},this.onXDragTick=a=>{const{delta:l}=a,c=this.lastXPxWidth-l;if(c<0)return;const h=this.lastXPxWidth/c,d=this.lastXWidth*h,u=this.lastXStart+(this.lastXWidth-d);this.scale.setXScale(u,this.scale.xEnd)};const o=new Te(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS),{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});this.addChildEntity(o)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS)).subscribe(()=>this.chartModel.doBasicScale())),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class yg extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h;const g=new vo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=g,this.xAxisLabelsModel=new Cg(t,[]);const C=new Ws;c.addDrawer(C,"X_AXIS"),this.xAxisDrawer=new is(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),C.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new ku(e,n,o,this.xAxisLabelsModel),C.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new wg(r,a,o,d,this.chartComponent.chartModel),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(ft(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe($(({prependedCandles:t})=>t.length!==0),ct(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;Za.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(ft(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(ve(50,me,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ct(()=>wt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),Et((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.timestamp)===((i=e==null?void 0:e.candle)==null?void 0:i.timestamp)}),$(jn)).subscribe(t=>{var e,n;return(n=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:n.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof vo?this.xAxisLabelsGenerator.setFormatsForLabelsConfig(t):console.error("Format config for x-axis is not available")}isVisible(){var t,e;return(e=(t=this.config.components)==null?void 0:t.xAxis.visible)!=null?e:!1}}var Sg=Object.defineProperty,bo=Object.getOwnPropertySymbols,xg=Object.prototype.hasOwnProperty,_g=Object.prototype.propertyIsEnumerable,Co=(s,t,e)=>t in s?Sg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,rs=(s,t)=>{for(var e in t||(t={}))xg.call(t,e)&&Co(s,e,t[e]);if(bo)for(var e of bo(t))_g.call(t,e)&&Co(s,e,t[e]);return s};class Pg{constructor(t,e,n,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=n,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const n=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=n&&rs(rs({},n),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&rs(rs({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=wt(t.dataPoints);if(e){const n=t.view.toY(e.close);if(isFinite(n)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:n,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const n=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:qt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const c=Gd(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,c,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,r,o),rounded:!0}}}class Tg{constructor(t,e,n,i,r){this.yAxisLabelsCanvasModel=t,this.backgroundCanvasModel=e,this.canvasBoundsContainer=n,this.fullConfig=i,this.paneManager=r}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx;this.paneManager.yExtents.forEach(n=>{if(n.yAxis.state.visible){const i=n.getYAxisBounds(),r=this.canvasBoundsContainer.getBounds(x.ALL_PANES),o=n.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(o),o.forEach(a=>{var l;const c=(l=a.bounds)!=null?l:i;a.labels.forEach(h=>Pr(t,e,c,r,h,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}),Object.values(n.yAxis.model.fancyLabelsModel.customLabels).forEach(a=>Pr(t,e,i,r,a,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,n={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=n[r.subGroupId])!=null?o:[];if(n[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(q));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];tr(e,{x:h.x,y:ci(d,h)},{x:h.x+h.width-6,y:ci(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class Mg{constructor(t,e,n){this.fullConfig=t,this.canvasModel=e,this.paneManager=n}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const n=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height);const o=Jt(e.state),a=Ht(o,r),l=this.getLabelTextColor();r.save(),Ut(r,i),this.drawLabels(r,n,i,a,o,l,e),r.restore()}})}drawLabels(t,e,n,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=n.y+c,d=n.y+n.height-c;e.forEach(u=>{const g=a.scale.toY(u.value);g>h&&g<d&&Ag(t,n,u.text,g,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const Ag=(s,t,e,n,i,r,o,a)=>{const l=a==="right"?t.x+t.width-yt(e,s,r)-o:t.x+o;s.fillText(e,l,n+i/2-1)};class Eg{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Oa.call(n,e)},this.add=(t,e,n)=>(e in this.handlers?t.call(this.handlers[e],n):this.handlers[e]=[n],this.unsub.bind(this,e,n)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new B,n=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,n),e.unsubscribe=()=>{this.unsub(t,n),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var n;if(!this.muted){const i=(n=this.handlers[t])!=null?n:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(Ve,t)}}class Lg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ct(r=>i.components.chart.highlightActiveCandle?r:void 0),Et()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,n){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=n.candleFromX(r);o&&n.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const n=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-n.left-i}}class Dg{constructor(t,e,n,i,r){this.frameElement=t,this.resizerElement=e,this.bus=n,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${Ct()}`,this.canvasResized=new B,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){Ns(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.canvasModels.forEach(n=>this.previousBCR&&n.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(Fs,e),this.bus.fire(Ve))}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.previousBCR!==void 0}}var Ig=Array.isArray,Bg=Object.getPrototypeOf,Og=Object.prototype,Rg=Object.keys;function Fg(s){if(s.length===1){var t=s[0];if(Ig(t))return{args:t,keys:null};if(Hg(t)){var e=Rg(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function Hg(s){return s&&typeof s=="object"&&Bg(s)===Og}var kg=Array.isArray;function Yg(s,t){return kg(t)?s.apply(void 0,L([],p(t))):s(t)}function jg(s){return ct(function(t){return Yg(s,t)})}function Ng(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Xg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Oe(s),n=ea(s),i=Fg(s),r=i.args,o=i.keys;if(r.length===0)return Re([],e);var a=new gt(zg(r,e,o?function(l){return Ng(o,l)}:ie));return n?a.pipe(jg(n)):a}function zg(s,t,e){return e===void 0&&(e=ie),function(n){wo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){wo(t,function(){var d=Re(s[h],t),u=!1;d.subscribe(xt(n,function(g){r[h]=g,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function wo(s,t,e){s?Ft(e,s,t):t()}class Wg extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new _t(null)}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,n){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,n)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const n=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Xg([n,i]).pipe($(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}else this.crossSubject.next(null),r=!0});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}class Ug{constructor(t,e,n,i){this.visualCandle=t,this.price=e,this.priceFormatter=n,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class Vg{constructor(t){this.chartModel=t}getData(t){const{x:e,y:n}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(n);return o&&new Ug(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Gg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof mr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Zg=Object.defineProperty,$g=Object.defineProperties,Kg=Object.getOwnPropertyDescriptors,yo=Object.getOwnPropertySymbols,qg=Object.prototype.hasOwnProperty,Jg=Object.prototype.propertyIsEnumerable,So=(s,t,e)=>t in s?Zg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Me=(s,t)=>{for(var e in t||(t={}))qg.call(t,e)&&So(s,e,t[e]);if(yo)for(var e of yo(t))Jg.call(t,e)&&So(s,e,t[e]);return s},rn=(s,t)=>$g(s,Kg(t));class Qg extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.crossEventProducer=t,this.scale=e,this.config=n,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.formatterFactory=c,this.hoverSubject=new _t(null),this.longTouchActivatedSubject=new _t(!1),this.xFormatter=()=>"";const h=new Vg(this.chartModel),d=new Gg(this.chartModel);this.hoverProducerParts={candleHover:h,compareSeriesHover:d}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp===this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{const n=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,i=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.chartModel.candleFromX(n,!0)&&this.createAndFireHover([n,i,""])}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{this.paneManager.chartPanComponent.deactivatePanHandlers(),this.longTouchActivatedSubject.next(!0);const n=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,i=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.createAndFireHover([n,i,""]),this.crossEventProducer.crossSubject.next([n,i,""])})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(()=>{this.paneManager.chartPanComponent.activateChartPanHandlers(),this.longTouchActivatedSubject.getValue()&&(this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose())})),this.addRxSubscription(ft(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter()))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=Mr(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),n=this.scale.toY(t.close);return this.createHover(e,n,q)}createHover(t,e,n){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:n},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>rn(Me({},l),{[c[0]]:c[1].getData(o)}),{});return Me(Me({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const n=rn(Me({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(n)}}createAndFireHover([t,e,n]){const i=this.createHover(t,e,n);this.fireHover(i)}fireHover(t){var e;if(t){if(xs()&&this.config.components.crossTool.type!=="none"){const n=(e=t.candleHover)==null?void 0:e.visualCandle.candle;n&&this.chartModel.mainCandleSeries.setActiveCandle(n)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=rn(Me({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const xo={left:0,middle:1,right:2};function ut(s,t,e,n){return s.addEventListener(e,t,n),function(){s.removeEventListener(e,t,n)}}function he(s){return t=>{t.button===xo.left&&s(t)}}var tf=Object.defineProperty,_o=Object.getOwnPropertySymbols,ef=Object.prototype.hasOwnProperty,sf=Object.prototype.propertyIsEnumerable,Po=(s,t,e)=>t in s?tf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,nf=(s,t)=>{for(var e in t||(t={}))ef.call(t,e)&&Po(s,e,t[e]);if(_o)for(var e of _o(t))sf.call(t,e)&&Po(s,e,t[e]);return s};const ee=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new B,this.xDragSubject=new B,this.xDragTickSubject=new B,this.xDragEndSubject=new B,this.yDragStartSubject=new B,this.yDragSubject=new B,this.yDragTickSubject=new B,this.yDragEndSubject=new B,this.mouseMoveSubject=new B,this.mouseMoveDocumentSubject=new B,this.clickSubject=new B,this.clickDocumentSubject=new B,this.dbClickSubject=new B,this.dbTapSubject=new B,this.mouseDownSubject=new B,this.mouseUpSubject=new B,this.mouseUpDocumentSubject=new B,this.wheelSubject=new B,this.touchStartSubject=new B,this.touchStartTimestamp=0,this.touchMoveSubject=new B,this.touchEndSubject=new B,this.touchCancelSubject=new B,this.longTouchStartSubject=new B,this.longTouchEndSubject=new B,this.contextMenuSubject=new B,this.pinchSubject=new B,this.scrollGestureSubject=new B,this.fastTouchScroll=new B,this.mouseLeavesCanvasSubject=new B,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=e=>{this.isDraggable(e)&&(this.updateCurrentPoints(e),this.dragging=!0,this.dragStartEvent=e,this.documentDragListeners.forEach(n=>n()),this.dragStartPoint=ee.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=nf({},this.dragStartPoint),ee.DRAG_EVENTS.forEach(n=>{document.addEventListener(n,this.dragProcessListener,!0);const i=document.removeEventListener.bind(document,n,this.dragProcessListener,!0);this.documentDragListeners.push(i),this.addSubscription(i)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.documentDragListeners.forEach(e=>e()),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=e=>{this.updateCurrentDocumentPoint(e),this.updateCurrentMousePoint(e)}}isDraggable(s){return s instanceof MouseEvent?s.button===xo.left:s instanceof TouchEvent}startDragging(s){this.updateCurrentPoints(s),this.dragStartListener(s)}movePointer(s){this.updateCurrentPoints(s),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const s=t=>(t.preventDefault(),!1);this.element.addEventListener("selectstart",s,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",s,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],ee.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),ee.DRAG_EVENTS.forEach(e=>{document.addEventListener(e,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragListener)),this.element.addEventListener(e,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,e,this.updateElementOffsetListener))}),ee.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(ut(this.element,he(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(ut(document,he(e=>this.clickDocumentSubject.next(e)),"click"));const s=Yr();if(s==="apple"||s==="mobile"){let e=null;const n=o=>{o.preventDefault(),e?(this.dbTapSubject.next(this.currentPoint),clearTimeout(e),e=null):e=window.setTimeout(()=>{e=null},250)};this.addSubscription(ut(this.element,n,"touchend"));const i=(o,a=700,l=3)=>{o.preventDefault();const c={x:o.touches[0].clientX,y:o.touches[0].clientY};let h={x:0,y:0},d=!1,u=null;u=setTimeout(()=>{d=!0,this.longTouchStartSubject.next(o)},a);const g=S=>{S.preventDefault(),h={x:S.touches[0].clientX,y:S.touches[0].clientY},(Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2))>l||S.touches.length>1)&&u&&clearTimeout(u)},C=S=>{S.preventDefault(),u&&clearTimeout(u),d&&(d=!1,this.longTouchEndSubject.next(S)),this.element.removeEventListener("touchend",C),this.element.removeEventListener("touchmove",g)};this.element.addEventListener("touchmove",g),this.element.addEventListener("touchend",C)};this.addSubscription(ut(this.element,o=>i(o),"touchstart"));const r=o=>{if(o.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const c=this.touchStartTimestamp,d=Date.now()-c,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,C=d<=250;g&&C&&this.fastTouchScroll.next(o)}};this.addSubscription(ut(this.element,r,"touchend"))}this.addSubscription(ut(this.element,he(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(ut(this.element,e=>{this.touchStartSubject.next(e),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(ut(this.element,e=>this.touchMoveSubject.next(e),"touchmove",!0)),this.addSubscription(ut(this.element,e=>this.touchEndSubject.next(e),"touchend")),this.addSubscription(ut(this.element,e=>this.touchCancelSubject.next(e),"touchcancel")),this.addSubscription(ut(this.element,e=>{e.ctrlKey?this.pinchSubject.next(e):Nr(e)?this.scrollGestureSubject.next(e):this.wheelSubject.next(e),e.preventDefault()},"wheel")),this.addSubscription(ut(this.element,e=>this.contextMenuSubject.next(e),"contextmenu")),this.addSubscription(ut(this.element,he(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(ut(this.element,he(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(ut(document,he(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(Fs).subscribe(()=>{const e=this.element.getBoundingClientRect();this.canvasBounds.x=e.left,this.canvasBounds.y=e.top,this.canvasBounds.width=e.width,this.canvasBounds.height=e.height}));const t=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",t,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){ee.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(s,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(s){"pageX"in s?this.currentPointDocument.x=s.pageX:s.touches!==void 0&&(this.currentPointDocument.x=s.touches[0].pageX),"pageY"in s?this.currentPointDocument.y=s.pageY:s.touches!==void 0&&(this.currentPointDocument.y=s.touches[0].pageY)}updateCurrentMousePoint(s){const t=this.element.getBoundingClientRect();"clientX"in s?this.currentPoint.x=s.clientX-t.left:s.touches!==void 0&&(this.currentPoint.x=s.touches[0].clientX-t.left),"clientY"in s?this.currentPoint.y=s.clientY-t.top:s.touches!==void 0&&(this.currentPoint.y=s.touches[0].clientY-t.top)}static copyPoint(s){return{x:s.x,y:s.y}}observeMouseMove(s=()=>!0){return this.mouseMoveSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe($(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe($(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ct(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe($(()=>!(t&&this.dragging)),ct(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ct(()=>!1));return ft(e,n).pipe(Et())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observePinch(s=()=>!0){return this.pinchSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeScrollGesture(){return this.scrollGestureSubject.asObservable()}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(s=()=>!0){return this.mouseDownSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)),Qr(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe($(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let os=ee;os.DRAG_START_EVENTS=["mousedown","touchstart"],os.DRAG_EVENTS=["mousemove","touchmove"],os.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var rf=function(s){z(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Es);var r=s.call(this)||this;return r._bufferSize=e,r._windowTime=n,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=n===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,n),r}return t.prototype.next=function(e){var n=this,i=n.isStopped,r=n._buffer,o=n._infiniteTimeWindow,a=n._timestampProvider,l=n._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),s.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),n},t.prototype._trimBuffer=function(){var e=this,n=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*n;if(n<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t}(B);const on={};function of(s){return on[s]||(on[s]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:s,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),on[s]}const To=(s,t=Date.now())=>{const n=of(s).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+)/.exec(n);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],0);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},Mo=60*1e3;class af{constructor(t){this.config=t,this.timeZoneChangedSubject=new rf,this.currentTzOffset=e=>To(this.config.timezone,e)+new Date(e).getTimezoneOffset()*Mo,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const n=t.createFormatterFunction;e=i=>n(i).bind(t)}else e=Uh(this.config,this.tzOffset);return e}getFormatterFactory(){return this.dateTimeFormatterFactory}getDateTimeFormatter(t){return this.formatterCache[t]===void 0&&(this.formatterCache[t]=this.dateTimeFormatterFactory(t)),this.formatterCache[t]}tzOffset(t){return t?e=>new Date(e+To(t,e)+new Date(e).getTimezoneOffset()*Mo):e=>new Date(e)}}class an{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;$a(r),this.config=r;const o=bl(r);t.innerHTML="",t.appendChild(o.content),this.id=(n=t.getAttribute("data-id"))!=null?n:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new af(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Cl(t);this.elements=c;const h=new Eg;this.bus=h;const d=new Dg(t,(i=c.chartResizer)!=null?i:t,h,this.canvasModels,r);this.chartResizeHandler=d,d.subscribeResize(),this.components.push(d.unsubscribeAnimationUpdate.bind(d));const u=new oh(h,d);this.drawingManager=u;const g=ih(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=g,this.dynamicObjectsCanvasModel=ce(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const C=new _e(this.dynamicObjectsCanvasModel);u.addDrawer(C,"SERIES_CLEAR");const S=ce(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),_=new As(r,h,g,l,d);this.canvasBoundsContainer=_;const M=c.mainCanvas.parentElement;if(M===null)throw new Error("Couldn't get main canvas parent");const I=new os(h,M);this.canvasInputListener=I,this.chartComponents.push(this.canvasInputListener);const F=new ed(h,c.hitTestCanvas,I,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=F;const j=new _e(F);u.addDrawer(j,"HIT_TEST_CLEAR");const R=new Pa(h);this.canvasAnimation=R;const H=x.PANE_UUID(q),Y=new Ji(r,()=>_.getBounds(H),R);this.scaleModel=Y;const Z=ce(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=Z,this.cursorHandler=new pl(c.canvasArea,I,_,F),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Wg(I,_),this.chartComponents.push(this.crossEventProducer);const K=new Wl("candle");this.chartBaseModel=K;const W=new Fd(h,Y,_,r,R,I,M,K);this.chartPanComponent=W,this.chartComponents.push(W),this.userInputListenerComponents.push(W.chartAreaPanHandler);const U=new wu(K,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,Y,_,r,R,I,u,this.cursorHandler,this.crossEventProducer,W,g,S);this.paneManager=U;const tt=this.paneManager.panes[q];this.mainPane=tt,this.chartComponents.push(U),this.dynamicObjects=new zh(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Ah(K,U,h,this.dynamicObjectsCanvasModel,r,Y,l,M,_,d);const J=new mh(this.chartModel,this.dynamicObjectsCanvasModel,r,Y,_,u,F,I,Z,W,U,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(J),this.chartComponent=J;const Q=this.chartComponent.chartModel;this.chartModel=Q,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),F.addSubscriber(U.hitTestController),this.xAxisComponent=new yg(h,r,g,J,Y,_,I,d,this.drawingManager,a,W,this.cursorHandler),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const et=new _e(g);u.addDrawer(et,"MAIN_CLEAR");const st=new Lg(M,Q,I,r);this.chartComponents.push(st),this.watermarkComponent=new Fu(U,Q,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ot=ce(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new wd(h,r,Q,g,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(Q)),this.navigationMapComponent=new Ed(h,Q,g,r,I,_,u,l,W,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const Tt=new gd(r,this.dynamicObjectsCanvasModel,Q,_,u);this.chartComponents.push(Tt),this.initYAxisDrawer(S),this.yAxisComponent=tt.mainExtent.yAxis;const St=new Pg(this.chartModel,this.config,tt.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(St,$s.MAIN),this.volumesComponent=new Lu(this.dynamicObjectsCanvasModel,J,Y,_,u,r,U,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const Bt=new Br(g,Y,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(H),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>this.yAxisComponent.model.baseLabelsModel.labels,()=>tt.mainExtent.toY(tt.mainExtent.getBaseline()),()=>r.components.grid.visible);this.chartComponents.push(Bt),this.hoverProducer=new Qg(this.crossEventProducer,Y,r,Q,I,this.canvasBoundsContainer,this.paneManager,a,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new Yh(r,ot,_,u,U,this.crossEventProducer,this.hoverProducer),this.chartComponents.push(this.crossToolComponent);const se=ce(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),Ae=new yu(this.elements,se);this.snapshotComponent=Ae,this.chartComponents.push(Ae);const ln=new hd(r,this.dynamicObjectsCanvasModel,F,Q,_,u,l,this.cursorHandler);this.eventsComponent=ln,this.chartComponents.push(ln),this.chartComponents.forEach(Io=>Io.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Aa(this.components)}initYAxisDrawer(t){const e=new Ws,n=new _e(t);e.addDrawer(n,"YAXIS_CLEAR"),this.drawingManager.addDrawer(e,"Y_AXIS");const i=new Mg(this.config,t,this.paneManager);e.addDrawer(i);const r=new Tg(t,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);e.addDrawer(r)}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&an.mergeConfig(t[n],e[n]):t[n]=e[n];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,n,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(n=t.dash)!=null?n:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){Lt(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(n).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,n=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,n).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(n).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=ft(this.canvasInputListener.observeYDrag(n),this.canvasInputListener.observeXDrag(n)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const n=t(this);this.components.push(n),e&&e(n),n.activate()}}class Ao extends an{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var n;(n=this.paneManager.panes[t])==null||n.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.setAllSeries(e,n)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.updateAllSeries(e,n)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.chartComponent.setChartType(t)}createPane(){return this.paneManager.createPane()}}var lf=Object.defineProperty,cf=Object.defineProperties,hf=Object.getOwnPropertyDescriptors,Eo=Object.getOwnPropertySymbols,df=Object.prototype.hasOwnProperty,uf=Object.prototype.propertyIsEnumerable,Lo=(s,t,e)=>t in s?lf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,gf=(s,t)=>{for(var e in t||(t={}))df.call(t,e)&&Lo(s,e,t[e]);if(Eo)for(var e of Eo(t))uf.call(t,e)&&Lo(s,e,t[e]);return s},ff=(s,t)=>cf(s,hf(t));function Do(s){s=s||{},s.quantity=s.quantity||200,s.startY=s.startY||50,s.avgCandleSize=s.avgCandleSize||2,s.avgTrendLength=s.avgTrendLength||{},s.avgTrendLength.sw=s.avgTrendLength.sw||10,s.avgTrendLength.down=s.avgTrendLength.down||10,s.avgTrendLength.up=s.avgTrendLength.up||10,s.withVolume=s.withVolume===!0||!1,s.period=s.period||3600;var t=[],e=s.quantity||200,n=10,i=10,r=10;s.avgTrendLength&&(n=s.avgTrendLength.sw||10,i=s.avgTrendLength.down||10,r=s.avgTrendLength.up||10);var o=s.startY||50,a=s.avgCandleSize||2,l=o-a,c=o+a,h=as(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(vf(t[t.length-1],a,n)):d>3?t=t.concat(pf(t[t.length-1],a,r)):t=t.concat(mf(t[t.length-1],a,i))}t=t.slice(0,s.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*s.period;for(let g=0;g<t.length;g++){const C=t[g];Object.assign(C,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(C.volume=Math.ceil(Math.random()*1e3+200))}return t}function as(s,t,e,n){var i=Math.random()*(t-s)+s,r;if(n&&n==="bull"||!n&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>s?a:s}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function pf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.lo,o=s.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=as(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),n.push(c)}return n}function mf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.hi-t*1.2,o=s.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=as(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),n.push(c)}return n}function vf(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var g,C;return Math.random()>.5?(g=u.lo-t*.2,C=u.hi+t*1.2):(g=u.lo-t*1.2,C=u.hi+t*.2),{from:g,to:C}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=as(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),n.push(d)}return n}window.DXChart=ff(gf({},window.DXChart),{generateCandlesData:Do});function bf(s){return Do(s)}const Cf=(s,t={})=>new Ao(s,t)})(),window.DXChart=ls})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devexperts/dxcharts-lite",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "DXCharts Lite",
5
5
  "author": "Devexperts Solutions IE Limited",
6
6
  "license": "MPL 2.0",