@barchart/chart-lib 2.356.1 → 2.356.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.
@@ -9,13 +9,13 @@ Bars %csame %c${i(t.lastTimestamp)} == ${i(t.newTimestamp)}`,"color:#0f0","color
9
9
  <td class="field-name">${e}</td>
10
10
  <td${n} class="field-value">${t}</td>
11
11
  </tr>
12
- `}function h$(e,t,i=null){return hU(e,t,i,"value-title")}function hG(e,t,i){let s="string"==typeof i?` style="color: ${i}"`:"",r=eF(e)?`<span class="field-name">${e}</span>`:"";return`${r}<span${s} class="field-value">${t}</span>`}function hz(e){return`<a class="delete-plot" data-plot-id="${e}" title="Delete plot">${hk("delete")}</a>`}function hY(e,t,i,s,r,n){let a=function(e,t){let i=e.data.aggregation,s=e.display.xAxis,r=s.isOrdinal,n=eH(r)&&r,a=n?s.ordinalName??"Value":"Date";return{date:n?hb(t):hD(i,t),time:i.isEndOfDay||n?null:hO(i,t,!1),isMultiSymbol:function(e){let t=e.mainPlot.symbol;return e.allPlots.some(e=>e.type===Z.Symbol&&e.symbol!==t)}(e),isMultiContract:i.isMultiContract,dateFieldName:a}}(e,t);return a.offset=i,a.lastBarRefresh=!!s,a.chartId=e.elementId,a.panes=e.panes.map(i=>({bounds:hj(i),id:i.id,plots:i.axes.map(e=>e.plots).flat().filter(t=>!r||t===e.mainPlot).map(i=>(function(e,t,i,{isMultiContract:s},r){let n=r.isStudy;if(!r.timeSeries.hasData)return null;let a=r.timeSeries.container;r.type,Z.Expression;let o=r.axis.comparison!==q.None,l=r.axis.comparison===q.Percent,u=(e,s)=>r.customPlotValues&&s!==ag.DateTime?[r.getValueAt(s,t,i),0]:hK(e,s,t,o),h=n?`${sV(r.model.study).meta.title} ${r.fullParams}`:r.metaData.name||"",c={isMain:r.main,type:r.type,typeName:Z[r.type],name:r.title,description:h,exchange:r.metaData.exchange||"",error:r.errorText,id:r.id,visible:r.visible};eF(r.yearOffset)&&0!=r.yearOffset&&(c.unalignedDate=hD(e.data.aggregation,function(e,t){return tt(2,arguments),tn(e,-te(t))}(t,r.yearOffset)));let d=r.curves[0];s&&r.type===Z.Symbol&&a.hasField(ag.Symbol)&&(t.valueOf()===tz.ZERO_DATE.valueOf()?c.name=r.timeSeries.container?.getLastDataPoint(ag.Symbol):c.name=u(d,ag.Symbol)[0]);let p={},f={range:r.axis.yScale.domain(),allDigits:!0};hq(r,e,f);let m=(e,t)=>{let i=(t===ag.Change||t===ag.PercentChange)&&e>0?"+":"";return l?i+hE(e):i+r.metaData.format(e,t,f)},g=hV(e),y=new Set;return c.values=r.curves.filter(e=>e.visible).map(e=>(!r.main&&r.isSymbol&&g?uf:e.fields).map(t=>{if(y.has(t))return null;y.add(t);let[i,s]=u(e,t),a=r.axis.yScale.priceToY(i);p[t.id]=!0;let o=r.customPlotValues?r.getColorOf(t):e.getColor(s,e.style!==$.HollowCandles,t),l=m(i,t).trim();if(eF(i)&&t===ag.Change){let[t]=u(e,ag.PercentChange);eF(t)&&(l+=` (${m(t,ag.PercentChange)})`)}return{abbreviation:hX(t),shortName:t.shortName,id:t.id,name:t.name,longName:`${t.shortName} ${n?r.params:""}`.trim(),color:iC(o),val:i,y:a,value:l}}).filter(e=>null!==e)).flat(),c.events=r.findEvents(u(d,ag.DateTime)).filter(e=>e.field!==ag.Custom),c})(e,t,n,a,i)).filter(e=>null!==e)})),a}function hj(e){let t=e.getBounds();if(!eF(t))return;let{x:i,y:s,width:r,height:n}=t,{leftOffset:a,rightOffset:o}=e.presenter.view;return{top:s,left:i+a,right:o,bottom:s+n,width:r,height:n}}function hK(e,t,i,s=!1){let r=e.plot,n=r.timeSeries.container,a=r.axis.pane.presenter.timeline,o=e_(a,+i,Number,hw),l=a.at(o-e.shift);if(null===l)return[null,0];let u=n.getTimeData(),h=e_(u,+l,Number);return[u[h]&&u[h].getTime()===l.getTime()?e.dataAt(t,h,!s):null,h]}function hq(e,t,i){eF(e.precision)?i.overridePrecision=e.precision:e.isStudy&&eF(t.mainPlot?.precision)&&!eF(sV(e.model.study).meta.decimals)&&(i.overridePrecision=t.mainPlot.precision)}function hX(e){return e.id===ag.Change.id?"Δ":e.id.substring(0,1)}class hZ{plot;id;fields=[];colors=[];style=$.Line;attributes=[];zones;_shift=0;lineWidth=1;lineMarker;lineSmoothing;dashStyle="Solid";varyColorPerBar=!1;visible=!0;_zoneColors;constructor(){this.id=e1(),this.plot=null}get shift(){return this._shift}set shift(e){this._shift=eF(e)?e:0}get isOhlc(){return(this.isOhlcStyle||this.isCandle||this.isHlcStyle||this.isElderImpulseSystemStyle||this.isRangeStyle)&&this.fields.includes(ag.Close)}get name(){return this.isOhlc?"":this.fields[0].name}get isHeikinAshiStyle(){return this.style===$.HeikinAshi}get isCandle(){return this.style===$.Candlestick||this.style===$.HollowCandles||this.style===$.HeikinAshi}get isHollowCandles(){return this.style===$.HollowCandles}get isElderImpulseSystemStyle(){return this.style===$.ElderImpulseSystem}get isPercentChangeStyle(){return this.style===$.PercentChange}get isOhlcStyle(){return this.style===$.OHLC}get isHlcStyle(){return this.style===$.HLC}get isRangeStyle(){return this.style===$.Range}get isRenko(){return this.style===$.Renko}get isKagi(){return this.style===$.Kagi}get isPointAndFigure(){return this.style===$.PointAndFigure}get isLineBreak(){return this.style===$.LineBreak}get isBaseline(){return this.style===$.Baseline}get isLineLike(){return[$.Line,$.Area,$.Baseline,$.PercentChange].includes(this.style)}get isColumn(){return this.style===$.Column}get isMultiColumn(){return this.style===$.MultiColumn}get isStackedColumn(){return this.style===$.StackedColumn}isFirstVisibleOfStyle(){return this.plot.curves.find(e=>e.visible&&e.style===this.style)===this}fromModel(e){e.attributes&&(this.attributes=e.attributes.map(e=>U[e])),this.colors=e.colors,this.fields=e.fields.map(e=>ag[e]),this.style=$[e.style],this.lineWidth=e.lineWidth,this.dashStyle=e.dashStyle,this.lineMarker=e.lineMarker,this.lineSmoothing=e.lineSmoothing,this.varyColorPerBar=e.varyColorPerBar,this.visible=e.visible??!0,e.zones&&(this.zones=e.zones),this.shift=e.shift}get axis(){return this.plot?.axis}get pane(){return this.axis?.pane}get timeSeries(){return this.plot?.timeSeries}get presenter(){return this.pane?.presenter}get view(){return this.presenter?.view}yToPrice(e){return this.yScale.yToPrice(e)}priceToY(e){return this.yScale.priceToY(e)}dataAt(e,t,i=!0){let s=!this.plot.isComparison(q.None),r=e===ag.PercentChange,n=e===ag.Change,a=r||(!i||s)&&n,o=this.timeSeries.container.hasField(ag.Last)?ag.Last:ag.Close,l=a?o:e,u=(e,t)=>{let i=this.timeSeries.container.getData(e)[t];return e.type!==Y.Number?i:this.plot.priceMapper(i,t,e)},h=u(l,t);if(!a)return h;if(t<=1)return 0;let c=u(l,t-1),d=h-c;return r?0===c?0:d/c:d}timeSeriesAt(e){let t=this.timeSeries.container.getTimeData(),i=t.length;return e<0||e>i-1?null:t[e]}timelineAt(e){return this.presenter.timeline.at(e)}get shiftedTimeDomain(){let e=this.view.xAxis.xScale;return eF(e.extent())?0!==this.shift?e.extent().map(t=>e.timeline.at(t-this.shift)):e.domain():null}get yScale(){return this.plot?.yScale??this.axis.yScale}getCore(){let e=this.timeSeries;if(!e.hasData||!this.visible)return null;let t=this.view.xAxis.xScale.extent();if(!eF(t))return null;let i=this.yScale.domain();return eF(i)?{ts:e,extent:t,domain:i,range:this.yScale.range()}:null}drawHover(e,t,i){if(!this.isLineLike||null===this.getCore())return;let[s,r]=hK(this,this.pickMainField(),t);if(eF(s))e.save(),iO(e,this.plot.axis.pane.getBoundsWithoutScales()),e.fillStyle=iC(this.getColor(r)),e.beginPath(),ci(e,i,this.priceToY(s),this.lineMarker??"Circle",1.3333),e.fill(),e.restore()}draw(e){let t=this.getCore();if(null===t)return;let{ts:i,extent:s,domain:r,range:n}=t;e.save(),e.setLineDash([]);let a=i.container.getTimeData(),o=this.shiftedTimeDomain[0],l={bar:this.view.xAxis.xScale.bar,domain:r,range:n,slice:s,start:e_(a,+o,Number)||0},u=eF(this.zones);this.isOhlc?ce.call(this,e,l):this.isRenko||this.isLineBreak?h4.call(this,e,l):this.style===$.Ribbon?this.varyColorPerBar?ch.call(this,e,l):cu.call(this,e,l,this.colors[0]):this.style===$.Area?u?h1.call(this,e,l,hQ,!0):hQ.call(this,e,l,this.colors,!0):this.isColumn||this.isMultiColumn?u?h1.call(this,e,l,h6,!0):h6.call(this,e,{...l,range:[null,null]}):this.isStackedColumn?h5.call(this,e,l):this.isBaseline?h3.call(this,e,l):this.style===$.Step?u?h1.call(this,e,l,h8):h8.call(this,e,l,this.colors[0]):this.isKagi?co.call(this,e,l):this.isPointAndFigure?cl.call(this,e,l):this.style===$.Dots?h7.call(this,e,l):this.style===$.Line||this.isPercentChangeStyle?u?h1.call(this,e,l,cs):this.varyColorPerBar?cn.call(this,e,l):cs.call(this,e,l):So(`Drawing of the curve style '${this.style}' is not implemented yet`,"error"),e.restore()}pickMainField(){return 1===this.fields.length?this.fields[0]:this.fields.includes(ag.Last)?ag.Last:this.fields.includes(ag.Close)?ag.Close:this.fields[0]}get zoneColors(){if(!eF(this._zoneColors)){let e=this.colors.slice();this._zoneColors=this.zones.map(t=>e.splice(0,t.colors))}return this._zoneColors}getColorsFromZone(e){let t=this.zones.findIndex(t=>e<t.value);return -1===t&&(t=this.zones.length-1),this.zoneColors[t]}pickAreaStroke(e){return e.length<2?iC(e[0]):e[1]}getComputedColor(e){if(!this.timeSeries.container.hasField(ag.BARCOLIX))return null;let t=this.dataAt(ag.BARCOLIX,e);return t>=0&&t<this.colors.length?this.colors[t]:null}getColor(e,t=!0,i=null){if(this.varyColorPerBar){let i,s={};if(this.isOhlc||this.isRenko||this.isLineBreak){let t=this.dataAt(ag.Open,e),i=this.dataAt(ag.High,e),r=this.dataAt(ag.Low,e),n=this.dataAt(ag.Close,e),a=this.dataAt(ag.Change,e);s.open=t,s.high=i,s.low=r,s.close=n,s.change=a}else if(this.plot.isStudy&&!["VOL","MAVOL"].includes(this.plot.model.study)){let t=this.pickMainField(),i=this.dataAt(t,e-1),r=this.dataAt(t,e),n=eF(i),a=eF(r);n?s.change=a?r-i:-1:s.change=+!!a}else{let t=this.plot.axis.pane.presenter.data.aggregation;t.isTick&&t.spec===z.None||(s.open=this.dataAt(ag.Open,e),s.close=this.dataAt(ag.Close,e)),s.change=this.dataAt(ag.Change,e)}let r=function(e,{open:t,close:i,change:s},r){let n=r.length>2&&e!==$.HLC,a=eF(t,i),o=a&&i>t,l=a&&i===t,u=s>0,h=0===s;return{useSame:n,isUp:o,isSame:l,isUpPrev:u,isSamePrev:h,isDown:!o&&!l,isDownPrev:!u&&!h}}(this.style,s,this.colors),n=this.getComputedColor(e);switch(this.style){case $.Candlestick:case $.Renko:case $.LineBreak:case $.Range:case $.HeikinAshi:case $.OHLC:case $.HLC:case $.Column:{if(eF(n)){i=n;break}let t=r.useSame?r.isUp:r.isUp||r.isSame,s=r.isSame,a=this.attributes||[],o=this.plot.isStudy&&!["HASMO","VOL","MAVOL"].includes(this.plot.model.study);(a.includes(U.ChangeBased)||o)&&(t=r.useSame?r.isUpPrev:r.isUpPrev||r.isSamePrev,s=r.isSamePrev),i=this.colors[+!!t],r.useSame&&s&&(i=this.colors[2]),(this.isRenko||this.isLineBreak||this.isRangeStyle)&&1===this.dataAt(ag.Projection,e)&&(i=iL(.5,!0)(i));break}case $.ElderImpulseSystem:i=this.colors[this.dataAt(ag.BREL,e)];break;case $.HollowCandles:{let e=this.colors[r.isUpPrev||r.isSamePrev?1:0];i=t&&(r.isUp||r.isSame)?tz.COLOR_TRANSPARENT:e;break}case $.Line:case $.PercentChange:case $.Ribbon:case $.Kagi:if(eF(n)){i=n;break}i=this.colors[0];break;case $.PointAndFigure:{let t=+!!uj(this.dataAt(ag.BARKIND,e));i=this.colors[t];break}default:throw Error(`Unexpected style ${$[this.style]} for a curve with varying colors`)}return eF(i)||(i=this.colors[0]),i}if(this.zones){let t=this.pickMainField(),i=this.dataAt(t,e),s=this.getColorsFromZone(i);return this.style===$.Area?this.pickAreaStroke(s):s.length>0?s[0]:this.colors[0]}if((this.isMultiColumn||this.isStackedColumn)&&eF(i)){var s;return this.colors[s=this.colors,Math.min(Math.max(this.fields.findIndex(e=>e===i),0),s.length-1)]}return this.colors[0]}}function hJ([e,t],i,s){let r=i,n=this.timeSeries.container.size;for(let i=e;i<=t;i++){for(;this.timeSeriesAt(r)<this.timelineAt(i-this.shift)&&r<n;)++r;if(r===n)break;let e=this.timeSeriesAt(r)>this.timelineAt(i-this.shift);s.call(this,r,e)}}function hQ(e,t,i,s=!1){cs.call(this,e,t,this.pickAreaStroke(i)),cc.call(this,e,t,i[0],s)}function h0(e,t){let i,s,r=eF(e),n=eF(t),a=this.pane.getBounds();if(r)if(n){let r=this.priceToY(e),n=this.priceToY(t);i=(r+n)/2,s=new iw(a.x,n,a.width,r-n)}else i=this.priceToY(e),s=new iw(a.x,a.y,a.width,i-a.y);else i=this.priceToY(t),s=new iw(a.x,i,a.width,a.y+a.height-i);return[i,s]}function h1(e,t,i,s=!1,r){let n;this.zones.forEach((a,o)=>{let l=a.value,[u,h]=h0.call(this,n,l);e.save(),iO(e,h),s&&(t.range=[null,u]);let c=this.zoneColors[o];if(a.gradient){let t=((e,t)=>{let i=iL(.6)(e),s=i_(.6)(e),r="linLighten"===t;return[r?s:i,e,r?i:s]})(c,a.gradient),i=e.createLinearGradient(0,h.y,0,h.y+h.height);i.addColorStop(0,t[0]),i.addColorStop(.5,t[1]),i.addColorStop(1,t[2]),c=i}else eF(r)&&(c=r(o,c));i.call(this,e,t,c),e.restore(),n=l})}function h2(e,t){let{x:i,width:s}=this.pane.getBoundsWithoutScales();e.save(),e.lineWidth=1,e.strokeStyle="#888",e.setLineDash(iP("dot")),ij(e,t,i,i+s),e.restore()}function h3(e,t){let[i,s]=t.range,{baseLevel:r}=function(e){let{BaseLevel:t}=eK(e);return{baseLevel:Number.isFinite(t)?e2(0,100,t):50}}(this.plot.inputs),n=(i-s)*r/100+s;this.zones[0].value=this.yToPrice(n),h2.call(this,e,n),h1.call(this,e,t,hQ,!0,(t,r)=>{let a=ib(r,0),o=e.createLinearGradient(0,1===t?i:s,0,n);return o.addColorStop(0,r),o.addColorStop(1,a),[o,ib(r,1)]})}function h4(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2;hJ.call(this,i,s,(i,s)=>{if(!s){let[s,n]=[ag.Open,ag.Close].map(e=>this.dataAt(e,i)).map(this.priceToY,this),a=Math.floor(t.totalWidth/2);e.fillStyle=this.getColor(i),e.beginPath(),e.rect(r-a,s,t.totalWidth,n-s),e.fill()}r+=t.totalWidth})}function h5(e,{bar:t,slice:i,start:s}){if(!this.isFirstVisibleOfStyle())return!1;let r=this.view.xAxis.xScale.range()[0]+t.offset,n=iZ();n.prolog(e);let a=this.plot.curves.filter(e=>e.isStackedColumn);hJ.call(this,i,s,(i,s)=>{if(!s){let s=this.priceToY(0),o=0;a.forEach(a=>{if(!a.visible)return;let l=a.fields[0];if(eF(o+=this.dataAt(l,i))){let u=this.priceToY(o);e.fillStyle=a.getColor(i,!1,l),e.beginPath(),e.rect(n.adjust(r),n.adjust(u),n.adjust(t.width),n.adjust(s-u)),e.fill(),s=u}})}r+=t.totalWidth}),n.epilog(e)}function h6(e,{bar:t,slice:i,start:s,range:[r,n]}){let a=this.view.xAxis.xScale.range()[0]+t.offset,o=this.isMultiColumn,l=o?this.fields:[this.pickMainField()],u=t.width/(o?l.length:1),h=iZ();h.prolog(e),hJ.call(this,i,s,(i,s)=>{s||l.forEach((t,s)=>{let r=this.dataAt(t,i);if(eF(r)){eF(n)||(n=this.priceToY(0));let o=this.priceToY(r);e.fillStyle=this.getColor(i,!1,t),e.beginPath(),e.rect(h.adjust(a+s*u),h.adjust(o),h.adjust(u),h.adjust(n-o)),e.fill()}}),a+=t.totalWidth}),h.epilog(e)}function h7(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2;e.fillStyle=this.getColor(0);let n=Math.max(1,this.lineWidth||tz.CURVE_STYLE_DOTS_RADIUS),a=2*Math.PI;e.beginPath(),hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eF(s)){let t=this.priceToY(s);e.moveTo(r+n,t),e.arc(r,t,n,0,a)}}r+=t.totalWidth}),e.fill()}function h8(e,{bar:t,slice:i,start:s},r){let n=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,a=iZ();a.prolog(e),e.strokeStyle=r,e.lineWidth=this.lineWidth,this.dashStyle&&e.setLineDash(iP(this.dashStyle)),e.beginPath();let o=!1,l=null;hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eF(s)){let r=this.priceToY(s);if(o)e.lineTo(n,l),e.lineTo(n,r);else{let s=this.dataAt(t,i-1);if(eF(s)){let t=this.priceToY(s);e.moveTo(-1,t),e.lineTo(n,t),e.lineTo(n,r)}else e.moveTo(n,r);o=!0}l=r}}n+=t.totalWidth}),e.stroke(),a.epilog(e)}let h9=[ag.Open,ag.High,ag.Low,ag.Close];function ce(e,{bar:t,slice:i,start:s}){let r=this.presenter.display.chart.showMinMaxArc,n=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,a=iZ();a.prolog(e);let o=null,l=null,u=null,h=null,c=t=>{this.isCandle?(this.isHollowCandles?t.outlineColor=this.getColor(t.ix,!1):(this.colors.length>3&&(t.outlineColor=this.colors[3]),this.colors.length>4&&(t.wickColor=this.colors[4])),function(e,{x:t,adjust:i,width:s,y:[r,n,a,o],color:l,outlineColor:u,wickColor:h,isMin:c,isMax:d},p){let f=s/2;e.lineWidth=p,e.fillStyle=l,e.strokeStyle=u||l,e.beginPath(),e.rect(i(t-f),r,s,i(o-r)),e.fill(),e.stroke(),e.strokeStyle=h||u||l,e.beginPath(),e.moveTo(t,Math.min(o,r)),e.lineTo(t,n),e.moveTo(t,Math.max(o,r)),e.lineTo(t,a),e.stroke(),e.strokeStyle=0===iM(l).a?u:l,ct(e,c,d,t,a,n,f)}(e,t,this.lineWidth)):(this.isOhlcStyle||this.isHlcStyle||this.isElderImpulseSystemStyle||this.isRangeStyle)&&function(e,{x:t,adjust:i,width:s,y:[r,n,a,o],color:l,isMin:u,isMax:h},c,d){let p=s/2;e.lineWidth=c,e.strokeStyle=l,e.beginPath(),e.moveTo(t,a),e.lineTo(t,n),d&&(e.moveTo(i(t-p),r),e.lineTo(t,r)),e.moveTo(i(t+p),o),e.lineTo(t,o),e.stroke(),ct(e,u,h,t,a,n,p)}(e,t,this.lineWidth,!this.isHlcStyle)};hJ.call(this,i,s,(e,i)=>{if(!i){let i=h9.map(t=>this.dataAt(t,e)),[s,r,d,p]=i;if(eF(s,r,d,p)){let f={x:a.adjust(n),adjust:a.adjust,width:t.width,y:[s,r,d,p].map(this.priceToY,this).map(a.adjust),isMin:!1,isMax:!1,ix:e,color:this.getColor(e)},m=Math.min(...i),g=Math.max(...i);(!eF(o)||m<o)&&(o=m,u=f),(!eF(l)||g>l)&&(l=g,h=f),c(f)}}n+=t.totalWidth}),r&&(eF(u)&&(u.isMin=!0,c(u)),eF(h)&&(h.isMax=!0,c(h))),a.epilog(e)}function ct(e,t,i,s,r,n,a,o=3){t&&iG(e,{x:s,y:r+o},a,0,Math.PI),i&&iG(e,{x:s,y:n-o},a,0,Math.PI,!0)}function ci(e,t,i,s,r=1){let n=tz.MARKER_SIZE*r,a=1.25*n;switch(s){case"Circle":e.moveTo(t+n,i),e.arc(t,i,n,0,2*Math.PI);break;case"Square":e.rect(t-n,i-n,2*n,2*n);break;case"TriangleUp":e.moveTo(t-a,i+a),e.lineTo(t+a,i+a),e.lineTo(t,i-a),e.lineTo(t-a,i+a);break;case"TriangleDown":e.moveTo(t-a,i-a),e.lineTo(t+a,i-a),e.lineTo(t,i+a),e.lineTo(t-a,i-a);break;case"Diamond":e.moveTo(t,i-a),e.lineTo(t+a,i),e.lineTo(t,i+a),e.lineTo(t-a,i),e.lineTo(t,i-a)}}function cs(e,{bar:t,slice:i,start:s},r=null){let n=r||this.getColor(0),a=eH(this.lineMarker);a&&(e.fillStyle=n,e.beginPath());let o=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,l=[],u=this.pickMainField();hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eF(t)){let i=this.priceToY(t);a&&ci(e,o,i,this.lineMarker),l.push({x:o,y:i})}}o+=t.totalWidth}),a&&e.fill(),e.lineWidth=this.lineWidth,this.dashStyle&&e.setLineDash(iP(this.dashStyle)),eH(this.lineSmoothing)?function(e,t,i,s){if(t.length<2)return;let r=function(e,t){let i=[];for(let s=0;s<e.length-1;s++){let r=e[s-1]||e[s],n=e[s],a=e[s+1],o=e[s+2]||a,l=n.x+(a.x-r.x)/t,u=n.y+(a.y-r.y)/t,h=a.x-(o.x-n.x)/t,c=a.y-(o.y-n.y)/t;i.push({cp1x:l,cp1y:u,cp2x:h,cp2y:c,x:a.x,y:a.y})}return i}(t,s);for(let s of(e.beginPath(),e.strokeStyle=i,e.moveTo(t[0].x,t[0].y),r))e.bezierCurveTo(s.cp1x,s.cp1y,s.cp2x,s.cp2y,s.x,s.y);e.stroke()}(e,l,n,this.lineSmoothing):cr(e,l,n)}function cr(e,t,i){if(t.length>1){e.beginPath(),e.strokeStyle=i;let s=t[0];e.moveTo(s.x,s.y);for(let i=1;i<t.length;i++){let s=t[i];e.lineTo(s.x,s.y)}e.stroke()}}function cn(e,{bar:t,slice:i,start:s}){e.lineWidth=this.lineWidth,e.lineCap="square",this.dashStyle&&e.setLineDash(iP(this.dashStyle));let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,n=null,a=null,o=[];hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eF(s)){let t=this.priceToY(s);a=this.getColor(i),n!==a&&(cr(e,o,n),o.length>0&&(o=[o.pop()]),n=a),o.push({x:r,y:t})}}r+=t.totalWidth}),cr(e,o,a)}let ca=[null,null,null,null];function co(e,{bar:t,slice:i,start:s}){e.lineWidth=Math.max(1,.5*t.width),e.lineJoin="miter",e.miterLimit=1.5;let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,n=iZ();n.prolog(e);let a=null,o=null,l=[];hJ.call(this,i,s,(i,s)=>{if(!s){let s=e=>h9.map(t=>this.dataAt(t,e)),[u,h,c,d]=s(i),[,p,f]=i<0?ca:s(i-1);if(eF(u,h,c,d)){let s=n.adjust(r),m=n.adjust(r-t.totalWidth),g=[u,h,c,d].map(this.priceToY,this).map(n.adjust),y=n.adjust(this.priceToY(h>p?p:f));o=this.getColor(i);let S=eF(a)&&a!==o,A=u===h?1:2,T=u===h?2:1;l.push({x:m,y:g[0]}),l.push({x:s,y:g[A]}),S&&(l.push({x:s,y:y}),cr(e,l,a),l=[]),S&&l.push({x:s,y:y}),l.push({x:s,y:g[T]}),a=o}}r+=t.totalWidth}),cr(e,l,o),n.epilog(e)}function cl(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0],n=t.totalWidth/2,a=r+t.offset+t.width/2,o=iZ();o.prolog(e);let l=this.plot.timeSeries.builder.boxSize,u=l/2;hJ.call(this,i,s,(i,s)=>{if(!s){let[t,s]=[ag.High,ag.Low].map(e=>this.dataAt(e,i)),r=this.colors[0],h=this.colors[1],c=this.dataAt(ag.BARKIND,i),d=uj(c),p=c===tz.BARKIND_XO,f=c===tz.BARKIND_OX;if(eF(t,s))for(let i=t;i>=s;i-=l){let l=o.adjust(a),[c,m]=[l-n,l+n],[g,y,S]=[i,i-u,i+u].map(e=>this.priceToY(e)),A=i===t&&p||i===s&&f?!d:d;e.beginPath(),A?(e.strokeStyle=h,e.moveTo(c,y),e.lineTo(m,S),e.moveTo(c,S),e.lineTo(m,y)):(e.strokeStyle=r,e.ellipse(l,g,n,y-g,0,0,2*Math.PI)),e.stroke()}}a+=t.totalWidth}),o.epilog(e)}function cu(e,{bar:t,slice:i,start:s},r){e.fillStyle=r;let[n,a]=this.fields,o=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,l=[];if(hJ.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(n,e),i=this.dataAt(a,e);eF(t,i)&&l.push({x:o,upY:this.priceToY(t),downY:this.priceToY(i)})}o+=t.totalWidth}),l.length>0){e.beginPath(),e.moveTo(l[0].x,l[0].upY);for(let t=1;t<l.length;++t)e.lineTo(l[t].x,l[t].upY);let t=l.length-1;e.lineTo(l[t].x,l[t].downY);for(let i=t-1;i>=0;--i)e.lineTo(l[i].x,l[i].downY);e.closePath(),e.fill()}}function ch(e,{bar:t,slice:i,start:s}){let[r,n]=this.fields,a=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,o=[],l=t=>{if(o.length>1){e.beginPath(),e.fillStyle=t,e.moveTo(o[0].x,o[0].upY);for(let t=1;t<o.length;++t)e.lineTo(o[t].x,o[t].upY);let i=o.length-1;e.lineTo(o[i].x,o[i].downY);for(let t=i-1;t>=0;--t)e.lineTo(o[t].x,o[t].downY);e.closePath(),e.fill()}},u=null,h=null;hJ.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(r,e),i=this.dataAt(n,e);if(eF(t,i)){let s=this.priceToY(t),r=this.priceToY(i);h=this.getColor(e),u!==h&&(l(u),o.length>0&&(o=[o.pop()]),u=h),o.push({x:a,upY:s,downY:r})}}a+=t.totalWidth}),l(h)}function cc(e,{bar:t,slice:i,start:s,range:[r,n]},a,o){if(o){let t=e.createLinearGradient(0,r,0,n);t.addColorStop(0,a),t.addColorStop(1,ib(a,0)),e.fillStyle=t}else e.fillStyle=a;e.beginPath();let l=null,u=this.pickMainField(),h=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,c=!1,d=null;hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eF(t)){let i=this.priceToY(t);c?e.lineTo(h,i):(e.moveTo(l=h,i),c=!0),d=h}}h+=t.totalWidth}),e.lineTo(d,n),e.lineTo(l,n),e.closePath(),e.fill()}class cd{symbol;aggregation;range;seriesKind;cacheMe;barsToFetch;offset;chartId;curveStyle;extendedHours;fields=[];alwaysUseBarsToFetch;inputs=[];splits;padded;constructor(e,t,i=J.Normal,s=[null,null]){this.symbol=e,this.aggregation=t,this.range=s,this.seriesKind=i,this.cacheMe=!1,this.barsToFetch=0,this.offset=0,this.chartId=null,this.curveStyle=null,this.alwaysUseBarsToFetch=!1,this.splits=!0,this.padded=!1}getBuilderKey(){if(!eF(this.curveStyle)||!tz.SPECIAL_BUILDER_REQUIRED.includes(this.curveStyle))return"Standard";switch(this.curveStyle){case $.Renko:{let{method:e,period:t,source:i,brickSize:s}=ui(this.inputs),r="ATR"===e?`ATR;${t}`:`${e};${s}`;return`Renko;${r};${i}`}case $.Kagi:{let{method:e,period:t,reversal:i}=uW(this.inputs),s="ATR"===e?`ATR;${t}`:`User;${i}`;return`Kagi;${s}`}case $.PointAndFigure:{let{method:e,period:t,reversal:i,boxSize:s,source:r,oneStepBack:n}=uK(this.inputs),a="ATR"===e?`ATR;${t}`:`User;${s}`;return`PointAndFigure;${a};${r};${i};${n}`}case $.LineBreak:{let{lineBreak:e}=u$(this.inputs);return`LineBreak;${e}`}default:return $[this.curveStyle]}}get needsExtraKey(){return[J.Options,J.BalanceSheet,J.IncomeStatement].includes(this.seriesKind)}getExtraKey(){return this.needsExtraKey&&this.fields.length>0?`${this.fields.map(e=>e.id).join(";")}`:""}getHashKey(){let e=this.aggregation.getHashKey(),t=this.getBuilderKey(),i=this.getExtraKey(),s=this.extendedHours??!1;return`${this.symbol}|${e}|${s}|${this.range}|${this.seriesKind}|${this.offset}|${t}|${this.splits}|${this.padded}|${i}`}duplicate(){let e=new cd(this.symbol,this.aggregation.duplicate(),this.seriesKind,this.range);return e.cacheMe=this.cacheMe,e.barsToFetch=this.barsToFetch,e.alwaysUseBarsToFetch=this.alwaysUseBarsToFetch,e.offset=this.offset,e.chartId=this.chartId,e.curveStyle=this.curveStyle,e.extendedHours=this.extendedHours,e.fields=ez(this.fields),e.splits=this.splits,e.padded=this.padded,e}}var cp=N("c15IW");function cf(e,t){let i=e.query?.duplicate();if(!eF(i)||i.symbol===tz.PLACEHOLDER_SYMBOL_NAME||"Standard"!==i.getBuilderKey())return new uJ;{0!==i.barsToFetch&&(i.barsToFetch=i.barsToFetch*tz.SERVER_COMPUTED_STUDY_BAR_MULTIPLIER);let e=t(i);return e.serverComputedSeries=!0,e}}function cm(e){return new ap(e,Y.Number,K.Study,e)}class cg{calcCtx;container;_source;target;inputs;outFields;studyFields={};innerSeries;calculable=!0;useNotifications=!1;initialNotification=!1;computedServerSide=!1;id;usedAsStyle=!1;recalcTriggers=new Set;basisChangedToken=null;_canLoadMoreData=!1;isLoading=!1;query;aggregation;sourceNeedsCompute=!1;allowEmptyValues=!1;constructor(e,...t){this.container=this._source=null,this.inputs=e.inputs,this.setOptions(e),this.innerSeries=t,this.id=e1(),this.addRecalcTrigger(...t)}refresh(){}get canLoadMoreData(){return this._canLoadMoreData}set canLoadMoreData(e){this._canLoadMoreData=e}loadMoreData(e){throw Error("Should not be called.")}addInner(...e){this.innerSeries.push(...e),this.addRecalcTrigger(...e)}isCalculable(e){return e.calculable??!1}addRecalcTrigger(...e){for(let t of e)this.isCalculable(t)?t.recalcTriggers.forEach(e=>this.recalcTriggers.add(e)):this.recalcTriggers.add(t)}setOptions(e){ej(this,e);let t=e.outFields??[e.target];this.studyFields=this.helpers.concat(t).reduce((e,t)=>(e[t.id]=t,e),{})}get helpers(){return tz.EMPTY_ARRAY}get hasData(){return null!==this.container}get source(){if(eF(this._source))return this._source;let e=eF(this.inputs)?this.inputs[tz.INPUT_SOURCE]:null;return eF(e)?ag[e]:null}set source(e){this._source=e}async ready(){return tU.call(this,async()=>{this.basisChangedToken=this.useNotifications?e(cp).subscribe(ay.TS_ALL,this.onBasisChanged.bind(this)):null;let t={tag:e1(),src:null},i=(await Promise.all(this.innerSeries.map(e=>e.ready()))).every(ep);return i&&this.calculate(t),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onBasisChanged(e,t){if(e===ay.TS_EVENTSCHANGED||e===ay.TS_LOADING||this.innerSeries.some(e=>!e.hasData)||!this.shouldTriggerOurRecalc(t.series)||null===this.base||this===t.series)return;let i={tag:e1(),src:t.series};switch(e){case ay.TS_MANYCHANGED:this.calculate(i);break;case ay.TS_DATAPOINTCHANGED:case ay.TS_DATAPOINTADDED:{let s=this.innerSeries[this.baseIndex].calculable?this.base.size-1:t.index;this.recalculateAt(i,s,e===ay.TS_DATAPOINTADDED);break}case ay.TS_TIMELINECORRECTION:case ay.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.useNotifications&&this.basisChangedToken&&e(cp).unsubscribe(this.basisChangedToken)}get baseIndex(){return 0}get base(){return this.innCont(this.baseIndex)}get period(){return this.inputs?.Period}calculateAt(e){return null}calculateDataPoint(e,t){let i=this.calculateAt(e);null!==i&&Object.keys(i).forEach(e=>{let s=i[e],r=this.studyFields[e];t?this.container.addDataPoint(r,s):this.container.setLastDataPoint(r,s)})}notify(e,t){eN(e,{series:this,index:t})}calculateCommon(e,t=null,i=-1,s=!0){let r=-1===i,n=r?t=>{(eF(e.src)||!eF(t.calcCtx))&&t.calculate(e)}:t=>t.recalculateAt(e,i,s);if(null===this.base||this.calcCtx&&this.calcCtx.tag===e.tag||this===e.src)return;this.calcCtx=e;let a=e=>this.isCalculable(e)&&!e.usedAsStyle;if(this.innerSeries.filter(a).forEach(e=>n(e)),r&&(this.container=this.makeContainer()),void 0!==this.calculateAt)if(r){let e=this.base.size;for(let t=0;t<e;++t)this.calculateDataPoint(t,!0)}else this.calculateDataPoint(i,s);t&&(eF(e.src)||this.initialNotification)&&this.notify(t,i)}calculate(e){this.calculateCommon(e,ay.TS_MANYCHANGED,-1,!0)}recalculateAt(e,t,i){this.computedServerSide||(!i&&eH(this.container)&&t>this.container.size-1&&(t=this.container.size-1),this.calculateCommon(e,i?ay.TS_DATAPOINTADDED:ay.TS_DATAPOINTCHANGED,t,i))}baseVal(e,t){return this.base.getData(e)[t]}innCont(e){return this.innerSeries[e].container}innVal(e,t,i){let s=this.innCont(e),r=s.size;return i<0||i>r-1?null:s.getData(t)[i]}innHasData(e){let t=this.innCont(e);return eF(t)&&t.size>0}wrap(...e){return e.reduce((e,t)=>(e[t.f.id]=t.g,e),{})}wrapBaseFields(...e){return e.map(this.wrapBaseField,this)}wrapInner(e,t){return{f:e,g:()=>this.innCont(t).getData(e)}}wrapBaseField(e){return this.wrapInner(e,this.baseIndex)}get defaultWrappers(){return this.wrapBaseFields(ag.DateTime,ag.Symbol)}makeContainer(){let e=this.defaultWrappers.concat(this.getWrappers());return new ue(Object.keys(this.studyFields).map(e=>this.studyFields[e],this),this.wrap(...e))}getWrappers(){return[]}atLeast(e,t){return e>=t-1}exactly(e,t){return e==t-1}past(e,t,i,s=this.base){return s.getData(i).slice(e-t+1,e+1)}getCacheableEntities(e){this.innerSeries.forEach(t=>{t.getCacheableEntities(e)})}}class cy extends cg{constructor(e,...t){super(e,...t),this.usedAsStyle=!0}get actual(){return this.innerSeries[0]}get canLoadMoreData(){return this.actual.canLoadMoreData}async loadMoreData(e=!0){return this.actual.loadMoreData(e)}get record(){return this.actual.record}}class cS extends cy{constructor(e,t){super(e,t),this.query=t.query,this.useNotifications=!0}calculateAt(e){let[t,i,s,r]=[ag.Open,ag.High,ag.Low,ag.Close].map(t=>this.baseVal(t,e),this),n=null,a=null,o=null,l=null,u=eg([t,i,s,r]);if(e<1)n=eg([t,r]),a=i,o=s,l=0;else{let[t,r]=[ag.Open,ag.Close].map(t=>this.container.getData(t)[e-1],this);a=Math.max(i,n=eg([t,r]),u),o=Math.min(s,n,u),l=u-r}return{[ag.Open.id]:n,[ag.High.id]:a,[ag.Low.id]:o,[ag.Close.id]:u,[ag.Change.id]:l}}getWrappers(){return this.wrapBaseFields(ag.Volume,ag.OpenInterest,ag.TradingDay)}}class cA extends cg{constructor(e,t){super(e,t),fj(this)}calculateAt(e){let t=null,i=this.period,[,s]=fK(this);if(this.atLeast(e,i)&&s.hasField(this.source)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=eg(r.filter(ef)):ey(r)&&(t=eg(r))}return{[this.target.id]:t}}getWrappers(){return this.source===ag.Volume?this.wrapBaseFields(ag.Volume,ag.TradeSize,ag.Change,ag.Open,ag.Close):[]}}class cT extends cg{multiplier;constructor(e,t,i){super(e,t),this.multiplier=i(this.period),fj(this)}calculateAt(e){let t=null,[i,s]=fK(this);if(this.atLeast(e,2)&&s.hasField(this.source)){let r=this.container.getData(this.target)[e-1];if(null!==r)t=(this.innVal(i,this.source,e)-r)*this.multiplier+r;else{let i=this.period;if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=eg(r.filter(ef)):ey(r)&&(t=eg(r))}}}return{[this.target.id]:t}}}class cv extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=ag.OpenInterest;return this.base.hasField(i)&&(t=this.baseVal(i,e)),{[i.id]:t}}}let cP={inField:ag.MA,outFields:[ag.ENVU,ag.ENVD],func:f_},cC={inField:ag.EMA,outFields:[ag.ENVEXPU,ag.ENVEXPD],func:fM},cb={inField:ag.SMA,outFields:[ag.ENVSMOU,ag.ENVSMOD],func:fx};class cE extends cg{kind;perc;constructor(e,t,i){super(e,i),this.kind=t,this.perc=this.inputs.Percent/100;let s=t.func(i,this.inputs.Period,e.source);this.addInner(s)}calculateAt(e){let t=null,i=null,s=this.innVal(1,this.kind.inField,e);if(null!==s){let e=s*this.perc;t=s+e,i=s-e}return{[this.kind.outFields[0].id]:t,[this.kind.outFields[1].id]:i}}}class cL extends cg{constructor(e,t){super(e,t);let i=f_(t,this.inputs.Period1,this.source),s=f_(t,this.inputs.Period2,this.source),r=fG(this.target,(e,t,i)=>t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(this.target,1)]}}let c_={fields:[ag.MACD,ag.MACDS,ag.MACDH],avgFunc:f_,mapFunc:fz,histogramVaryColor:!0},cM={fields:[ag.MACD,ag.MACDS,ag.MACDH],avgFunc:fM,mapFunc:fz,histogramVaryColor:!0},cx={fields:[ag.MACD,ag.CTLTM,ag.CTM],avgFunc:fM,mapFunc:fz,histogramVaryColor:!1},cI={fields:[ag.MACD,ag.CTLTMF,ag.CPMI],avgFunc:fM,mapFunc:fz,histogramVaryColor:!1},cD={fields:[ag.PPO,ag.PPOS,ag.PPOH],avgFunc:fM,mapFunc:fY,histogramVaryColor:!0},cO={fields:[ag.PVO,ag.PVOS,ag.PVOH],avgFunc:fM,mapFunc:fY,histogramVaryColor:!1};class cw extends cg{histogramVaryColor=!1;histogramField;get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=-1;if(this.histogramVaryColor&&e>0){let i=this.container.getData(this.histogramField)[e],s=this.container.getData(this.histogramField)[e-1];if(eF(i,s)){let r=i<=0;t=r?1:3,e>0&&(r&&i>s&&(t=0),!r&&i<s&&(t=2))}}return{[ag.BARCOLIX.id]:t}}}class cR extends cw{fields;constructor(e,t,i){super(e,i),this.fields=t.fields,this.histogramVaryColor=t.histogramVaryColor,this.histogramField=this.fields[2];let s=t.avgFunc(i,e.inputs.Period1,e.source,void 0),r=t.avgFunc(i,e.inputs.Period2,e.source,void 0),n=fG(this.fields[0],t.mapFunc,s,r),a=t.avgFunc(n,e.inputs.Period3,n.target,this.fields[1]),o=fG(this.fields[2],fz,n,a);this.addInner(n,a,o)}getWrappers(){return[this.wrapInner(this.fields[0],1),this.wrapInner(this.fields[1],2),this.wrapInner(this.fields[2],3)]}}let cN=cm("_AVG_GAIN"),cV=cm("_AVG_LOSS");class cH extends cg{constructor(e,t,i){super(e,i);let s=fB(i,this.inputs.Period,this.source,ag.RSI,t),r=fJ(e,"MA","Average")(s,this.inputs.PeriodAvg,ag.RSI,ag.RSIAVG);this.addInner(s,r)}getWrappers(){return[this.wrapInner(ag.RSI,1),this.wrapInner(ag.RSIAVG,2)]}}class cF extends cg{highest;index;constructor(e,t,i,s){super(e,s),this.highest=t,this.index=i}calculateAt(e){let t=null,i=this.inputs.Period;if(this.atLeast(e,i)){let s=this.past(e,i,this.source);ey(s)&&(t=this.highest?Math.max(...s):Math.min(...s),this.index&&(t=i-s.indexOf(t)-1))}return{[this.target.id]:t}}}class cB extends cg{toHighest;field;highField;lowField;constructor(e,t,i){super(e,i),this.toHighest=t;let s=eF(e.source),r=e.source,n=s?r:ag.Close;this.field=n;let a=s?r:ag.High;this.highField=a;let o=s?r:ag.Low;this.lowField=o;let l=fO(i,e.inputs.Period,this.highField,ag.HH,!0),u=fO(i,e.inputs.Period,this.lowField,ag.LL,!1);this.addInner(l,u)}calculateAt(e){let t=null,i=this.baseVal(this.field,e),s=this.innVal(1,ag.HH,e),r=this.innVal(2,ag.LL,e);if(ey([i,s,r])){let e=this.toHighest?s:r,n=s-r;0!==n&&(t=(i-e)/n*100)}return{[this.target.id]:t}}}let ck=cm("RawPercK");class cW extends cg{kField;constructor(e,t,i,s){super(e,s);let r=fw(s,this.inputs.Period1,t?ck:i,!1),n=fJ(e,"MA"),a=n(r,this.inputs.Period2,r.target,t?i:ag.PercD),o=t?n(a,this.inputs.Period3,a.target,ag.PercD):a;this.kField=i,t?this.addInner(a,o):this.addInner(r,a)}getWrappers(){return[this.wrapInner(this.kField,1),this.wrapInner(ag.PercD,2)]}}function cU(e,t,i,s,r){if(null===r)return null;let n=e*r,a=s+n,o=s-n;switch(t){case ag.BOLLBU:return a;case ag.BOLLBL:return o;case ag.BOLLBW:return(a-o)/s*100;default:return null}}class c$ extends cg{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=this.inputs.Period,r=this.source,n=f_(i,s,r,ag.BOLLBM),a="Modified"===t,o=fW(a?function(e,t,i=ag.PCTCHG){return fb("PCTCHG",{source:t,target:i,inputs:fR},e)}(i,r):i,s,a?ag.PCTCHG:r),l=this.inputs.Width,u=e=>ec(cU,l,e),h=fG(ag.BOLLBU,u(ag.BOLLBU),n,o),c=fG(ag.BOLLBL,u(ag.BOLLBL),n,o),d=fG(ag.BOLLBW,u(ag.BOLLBW),n,o),p=fJ(e,"MA","Average")(d,this.inputs.PeriodAvg,ag.BOLLBW,ag.BOLLBWA);this.addInner(n,o,h,c,d,p)}calculateAt(e){let t=this.innVal(3,ag.BOLLBU,e),i=this.innVal(4,ag.BOLLBL,e),s=this.innVal(1,ag.BOLLBM,e),r=this.innVal(5,ag.BOLLBW,e),n=this.innVal(6,ag.BOLLBWA,e),a=null;switch(eF(t,i)&&(a=(this.baseVal(ag.Close,e)-i)/(t-i)),this.kind){case"Regular":return{[ag.BOLLBU.id]:t,[ag.BOLLBL.id]:i,[ag.BOLLBM.id]:s};case"Width":return{[ag.BOLLW.id]:t-i};case"Percent":return{[ag.BOLLP.id]:a};case"BandWidth":return{[ag.BOLLBW.id]:r,[ag.BOLLBWA.id]:n};case"Modified":{let t=null,i=null,r=null,n=null,a=this.innVal(2,ag.MSD,e);if(eF(a)){let e=this.inputs.MultInside,o=this.inputs.MultOutside;t=s+e*a,r=s-e*a,i=s+o*a,n=s-o*a}return{[ag.MBBUI.id]:t,[ag.MBBLI.id]:r,[ag.MBBUO.id]:i,[ag.MBBLO.id]:n,[ag.MBBM.id]:s}}default:return null}}}let cG=cm("_ABS_CHG"),cz=cm("_MA_ABS_CHG"),cY=cm("_CHG"),cj=cm("_PDM"),cK=cm("_MDM"),cq=cm("_TRS"),cX=cm("_PDS"),cZ=cm("_MDS"),cJ=cm("_DX");class cQ extends cg{useEma;adxField;multiplier;constructor(e,t,i,s){super(e,s),this.useEma=t,this.adxField=i,this.multiplier=2/(this.inputs.AdxSmoothing+1);let r=fN(s,ag.TR);this.addInner(r)}get helpers(){return[cj,cK,cq,cX,cZ,cJ]}sum(e,t,i,s){let r=null;if(this.atLeast(e-1,s-1)){let n=this.past(e-1,s-1,t,this.container);n.push(i),ey(n)&&(r=n.reduce((e,t,i)=>e+t,0))}return r}smooth1(e,t,i,s){let r=this.inputs.DiLength,n=this.container.getData(i)[e-1];return null!==n?n-n/r+s:this.sum(e,t,s,r)}smooth2(e,t,i,s){let r=this.container.getData(i)[e-1],n=this.inputs.AdxSmoothing;if(null!==r)if(this.useEma)return(s-r)*this.multiplier+r;else return(r*(n-1)+s)/n;{let i=this.sum(e,t,s,n);if(null!==i)return i/n}return null}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=null,l=null,u=null;if(e>0){let h=this.past(e,2,ag.High),c=this.past(e,2,ag.Low),d=Math.max(h[1]-h[0],0),p=Math.max(c[0]-c[1],0);t=d>p?d:0,i=p>d?p:0;let f=this.container.getData(ag.TR)[e];r=this.smooth1(e,cj,cX,t),n=this.smooth1(e,cK,cZ,i),s=this.smooth1(e,ag.TR,cq,f),(r>0||n>0)&&0!==s&&(l=100*Math.abs((a=r/s*100)-(o=n/s*100))/(a+o),u=this.smooth2(e,cJ,this.adxField,l))}return{[cj.id]:t,[cK.id]:i,[cq.id]:s,[cX.id]:r,[cZ.id]:n,[ag.PDI.id]:a,[ag.MDI.id]:o,[cJ.id]:l,[this.adxField.id]:u}}getWrappers(){return[this.wrapInner(ag.TR,1)]}}class c0 extends cg{calculateAtFunc;constructor(e,t,...i){super(e,...i),this.calculateAtFunc=t}calculateAt(e){let t=this.innerSeries.map((t,i)=>{let s=t.target;return eF(s)||(s=t.container.hasField(ag.Close)?ag.Close:t.container.fields[0]),this.innVal(i,s,e)}),i=null;return ey(t)&&(i=this.calculateAtFunc(e,...t)),{[this.target.id]:i}}}function c1(e,t){let i=this.baseVal(ag.High,t),s=this.baseVal(ag.Low,t);return{[e.id]:(i+s)/2}}function c2(e,t){let i=this.baseVal(ag.High,t),s=this.baseVal(ag.Low,t);return{[e.id]:i-s}}class c3 extends cg{calculateAtFunc;constructor(e,t,i){super(e,i),this.calculateAtFunc=t}calculateAt(e){return this.calculateAtFunc.call(this,e)}}let c4=cm("_RANGE"),c5=cm("_MOV_RANGE"),c6={fields:[ag.KCUP,ag.KCLOW,ag.KCMID],midSeries:e=>fH(e,ag.TP),midTarget:ag.TP,rangeSeries:e=>f$(c4,eh(c2,c4),e),rangeTarget:c4,func:"MA",useMultiplier:!1},c7={fields:[ag.KBUP,ag.KBLOW,ag.KBMID],midSeries:e=>e,midTarget:ag.Close,rangeSeries:e=>fN(e,ag.TR),rangeTarget:ag.TR,func:"EMA",useMultiplier:!0};class c8 extends cg{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=t.midSeries(i),r=fJ(e,t.func,"Average"),n=r(s,this.inputs.Period,t.midTarget,t.fields[2]),a=r(t.rangeSeries(i),this.inputs.Period,t.rangeTarget,c5);this.addInner(n,a)}calculateAt(e){let t=this.innVal(1,this.kind.fields[2],e),i=this.innVal(2,c5,e),s=null!==t&&null!==i,r=this.kind.useMultiplier?this.inputs.Multiplier:1;return{[this.kind.fields[0].id]:s?t+i*r:null,[this.kind.fields[1].id]:s?t-i*r:null}}getWrappers(){return[this.wrapInner(this.kind.fields[2],1)]}}class c9 extends cg{isWidth;constructor(e,t,i){super(e,i),this.isWidth=t;let s=fO(i,this.inputs.Period,ag.High,ag.DONUP,!0),r=fO(i,this.inputs.Period,ag.Low,ag.DONLOW,!1);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,ag.DONUP,e),i=this.innVal(2,ag.DONLOW,e),s=null===t&&null===i;return this.isWidth?{[ag.DONW.id]:s?null:t-i}:{[ag.DONMID.id]:s?null:(t+i)/2}}getWrappers(){return[this.wrapInner(ag.DONUP,1),this.wrapInner(ag.DONLOW,2)]}}let de=cm("_HIND"),dt=cm("_LIND");class di extends cg{justWidth;constructor(e,t,i){super(e,i),this.justWidth=t,this.justWidth=t;let s=this.inputs.Period,r=fO(i,s,ag.High,de,!0,!0),n=fO(i,s,ag.Low,dt,!1,!0);this.addInner(r,n)}calculateAt(e){let t=null,i=null,s=null,r=this.innVal(1,de,e),n=this.innVal(2,dt,e);if(null!==r&&null!==n){let e=this.period;s=(t=(e-r)/e*100)-(i=(e-n)/e*100)}return this.justWidth?{[ag.ARNOSC.id]:s}:{[ag.ARNUP.id]:t,[ag.ARNLOW.id]:i}}}let ds=cm("_MIDPOINT"),dr=cm("_MIDPOINT");class dn extends cg{multiplyVol;constructor(e,t,i){super(e,i),this.multiplyVol=t}calculateAt(e){let[t,i,s,r]=[ag.High,ag.Low,ag.Close,ag.Volume].map(t=>this.baseVal(t,e)),n=t===i?0:(s-i-(t-s))/(t-i);return this.multiplyVol&&(n*=r),{[this.target.id]:n}}}let da=cm("_RANGE"),dl=cm("_MATP");class du extends cg{isBull;constructor(e,t,i){super(e,i),this.isBull=t;let s=fM(i,this.inputs.Period,this.source);this.addInner(s)}calculateAt(e){let t=null,i=this.innVal(1,ag.EMA,e);return null!==i&&(t=this.isBull?this.baseVal(ag.High,e)-i:this.baseVal(ag.Low,e)-i),{[this.isBull?ag.ERBLPOW.id:ag.ERBRPOW.id]:t}}}let dh=cm("_FORCE"),dc=cm("_RANGE"),dd=cm("_EMA1"),dp=cm("_EMA2"),df=cm("_RATIO"),dm={isNegative:!1,fields:[ag.PVI,ag.PVIEMA]},dg={isNegative:!0,fields:[ag.NVI,ag.NVIEMA]};class dy extends cg{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=f$(this.kind.fields[0],eh(function(e,t){let i=1e3;if(t>0){let s=[ag.Close,ag.Volume],[r,n]=s.map(e=>this.baseVal(e,t)),[a,o]=s.map(e=>this.baseVal(e,t-1)),l=this.container.getData(this.target)[t-1];i=(e?n<o:n>o)?l*((r-a)/a+1):l}return{[this.target.id]:i}},this.kind.isNegative),i),r=fM(s,this.inputs.Period,this.kind.fields[0],this.kind.fields[1]);this.addInner(s,r)}getWrappers(){return[this.wrapInner(this.kind.fields[0],1),this.wrapInner(this.kind.fields[1],2)]}}let dS=cm("_LOGPC"),dA=cm("_SWING_INDEX"),dT=cm("_MIN_CLOSE"),dv=cm("_MAX_CLOSE"),dP=cm("_EP"),dC=cm("_AF"),db=cm("_POS"),dE=cm("_IDY"),dL=[0,0,0,1,1,1,5,5,2,1,1,0,50,50,0,1,1,1,5,0,0],d_=e=>Array(e).fill(0);function dM(e,t,i){let s=e[i-1];return 0===t&&(s=e[i]),t<0&&(s=e[i+1]),s}function dx(e,t,i){let s=0,r=-1,n=0,a=1;for(let o=0;o<i;++o){if(t[o]=0,null==e[o]||(21==++s&&(a=2),31==s&&(a=3),n+=e[o]*a,s<40))continue;t[o]=n/70;let l=0,u=r+1;for(let t=u;t<i&&(null==e[t]||(1==++l&&(r=t),(1==l||21==l||31==l)&&(n-=e[t]),31!=l));++t);}}let dI={1:{param:"cot",func:"parseCotLineChart",fields:[ag.DateTime,ag.COTLCCMSP,ag.COTLCLGSP,ag.COTLCSMSP]},2:{param:"cotadv",func:"parseDisaggregated",fields:[ag.DateTime,ag.COTDAGPRO,ag.COTDAGSPD,ag.COTDAGMNM,ag.COTDAGOTH]},3:{param:"cotfin",func:"parseFinancialTradersReport",fields:[ag.DateTime,ag.COTFTRDLI,ag.COTFTRASM,ag.COTFTRLVF,ag.COTFTROTH]}};class dD extends cg{wrappers;constructor(e,t,i){super(e,cf(i,e=>new dO(t,e))),this.computedServerSide=!0,this.initialNotification=!0,this.wrappers=dI[t].fields.slice(1).map(e=>this.wrapInner(e,0))}getWrappers(){return this.wrappers}}class dO extends uZ{kind;constructor(e,t){super(t),this.kind=e}getRetriever(){return new dw(this.kind)}onStreamingUpdates(e){}}class dw extends uA{kind;constructor(e){super(),this.kind=e}addExtraParams(e){e[dI[this.kind].param]="y"}getParser(e){return new dR(e.symbol,e.aggregation,this.kind)}}class dR extends ug{kind;constructor(e,t,i){super(e,t,0),this.kind=i}makeContainer(){return new l8(dI[this.kind].fields)}getParseFunc(){return this.aggregation.isEndOfDay?this[dI[this.kind].func]:null}parseCotLineChart(e){this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.COTLCCMSP,parseInt(e[2])),this.container.addDataPoint(ag.COTLCLGSP,parseInt(e[3])),this.container.addDataPoint(ag.COTLCSMSP,parseInt(e[4]))}parseDisaggregated(e){this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.COTDAGPRO,parseInt(e[2])),this.container.addDataPoint(ag.COTDAGSPD,parseInt(e[3])),this.container.addDataPoint(ag.COTDAGMNM,parseInt(e[4])),this.container.addDataPoint(ag.COTDAGOTH,parseInt(e[5]))}parseFinancialTradersReport(e){this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.COTFTRDLI,parseInt(e[2])),this.container.addDataPoint(ag.COTFTRASM,parseInt(e[3])),this.container.addDataPoint(ag.COTFTRLVF,parseInt(e[4])),this.container.addDataPoint(ag.COTFTROTH,parseInt(e[5]))}}class dN extends dD{constructor(e,t){super(e,1,t)}}let dV={Day:[ag.PreviousHigh,ag.PreviousLow,ag.PreviousClose],Week:[ag.WeekPreviousHigh,ag.WeekPreviousLow,ag.WeekPreviousClose],Month:[ag.MonthPreviousHigh,ag.MonthPreviousLow,ag.MonthPreviousClose]};class dH extends cg{disabled;record;streamingSubscription;constructor(e,t,i){if(super(e,i),this.disabled=!eF(i.query)||!eF(i.query.symbol),!this.disabled){let e=i.query.symbol;e.endsWith(".BZ")&&(e=e.slice(0,-3)),this.record=Sp().getRecordSource().getRecord(e),this.record.addFields(...t),this.streamingSubscription=this.getStreamingSubscription()}this.initialNotification=!0}getStreamingSubscription(){return Sp().getRecordSource().subject.pipe(ub(e=>{let t=aR(ay.RT_QUOTE,this.record.symbol);return e.filter(t)}),ov(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}async ready(){return tU.call(this,async()=>eF(this.record)?await this.record.ready()&&await super.ready():await super.ready(),"asyncReadyWork2")}onStreamingUpdates(e){if(this.record){let e={tag:e1(),src:null};this.calculate(e)}}shutdown(){super.shutdown(),this.disabled||this.streamingSubscription.unsubscribe()}getValues(e){return dV[e].map(e=>this.record.getValue(e))}}class dF extends uZ{constructor(e){super(e)}getRetriever(){return tg(this.query.symbol)?new dU:new dB}onStreamingUpdates(e){}}class dB extends uA{addExtraParams(e){e.impl="y"}getParser(e){return new dW(e.symbol,e.aggregation)}}function dk(){return new l8([ag.DateTime,ag.IMPVOL])}class dW extends ug{constructor(e,t){super(e,t)}makeContainer(){return dk()}getParseFunc(){return this.parseImpVol}parseImpVol(e){this.aggregation.isEndOfDay&&!(e.length<9)&&(this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.IMPVOL,parseFloat(e[8])))}}class dU extends uT{emptyContainer(e,t){return dk()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(ag.DateTime,l2(e.date.substring(0,10)));let s=eH(e.impliedVolatility);i.addDataPoint(ag.IMPVOL,s?100*e.impliedVolatility:null)}}let d$=cm("_ABS_CHG"),dG=cm("_DS1_EMA1"),dz=cm("_DS1_EMA2"),dY=cm("_DS2_EMA1"),dj=cm("_DS2_EMA2"),dK=cm("_DIFF"),dq=cm("_SUM"),dX=cm("_ABS_CHG"),dZ=cm("_HH_LL"),dJ=cm("_MULMA"),dQ=cm("_DIFF");class d0 extends cy{constructor(e,t){super(e,t),this.query=t.query,this.useNotifications=!0}calculateAt(e){let t=[null,null,null,null,null];if(e>0){let i=(e,t)=>this.baseVal(e,t),s=[ag.Open,ag.High,ag.Low,ag.Close],r=s.map(t=>i(t,e));if(ey(r)){let n=s.map(t=>i(t,e-1));if(ey(n)){let[i,s]=eM(t=r.map((e,t)=>100*(e-n[t])/n[t]));if(t[1]=s,t[2]=i,e>1){let i=this.container.getData(ag.Close)[e-1];t[4]=t[3]-i}}}}return{[ag.Open.id]:t[0],[ag.High.id]:t[1],[ag.Low.id]:t[2],[ag.Close.id]:t[3],[ag.Change.id]:t[4]}}getWrappers(){return this.wrapBaseFields(ag.Volume,ag.OpenInterest,ag.TradingDay)}}let d1=cm("_DIST"),d2=cm("_EMA_DIST1"),d3=cm("_EMA_DIST2"),d4=cm("_DIFF"),d5=cm("_EMA_DIFF1"),d6=cm("_EMA_DIFF2"),d7=cm("_CHG"),d8=cm("_M1"),d9=cm("_M2");class pe extends cg{constructor(e,t){super(e,t);let i=f$(d7,function(e){let t=ag.Close,i=e>0?this.baseVal(t,e)-this.baseVal(t,e-1):0;return{[d7.id]:i}},t),s=fG(d8,(e,t)=>t>=0?t:0,i),r=fG(d9,(e,t)=>t>=0?0:-t,i);this.addInner(s,r)}perc(e,t){return 100*e/t}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i+1)){let s=this.past(e,i,d8,this.innCont(1)),r=this.past(e,i,d9,this.innCont(2));if(ey(s)&&ey(r)){let e=em(s),i=em(r);t=this.perc(e-i,e+i)}}return{[ag.CHDMOMOSC.id]:t}}}let pt=cm("_MAX"),pi=cm("_MIN"),ps=cm("_ISUPTREND"),pr=cm("_TRENDUP"),pn=cm("_TRENDDOWN"),pa=cm("_TREND"),po=cm("_CUM_PRICE"),pl=cm("_CUM_VOL"),pu=cm("_PER_CHG");class ph extends cg{constructor(e,t){super(e,t);let i=this.source,s=f$(i,eh(fq,i),t);this.addInner(s)}valueAt(e,t){return this.container.getData(e)[t]}dateAt(e){return this.container.getTimeData()[e]}}let pc=cm("_DIFF"),pd=[pc,ag.Buy,ag.Sell];function pp(e,t,i,s){let r=null,n=null,a=null;eF(i,s)&&(a=i-s);let o=t>0?e.getData(pc)[t-1]:null;return eF(a,o)&&(r=a>0&&o<=0?1:null,n=a<0&&o>=0?-1:null),{[pc.id]:a,[ag.Buy.id]:r,[ag.Sell.id]:n}}let pf=cm("_PVM"),pm=cm("_NVM");var cp=N("c15IW");function pg(e,t,i){return new py(e,t,i)}class py{exprModel;innerSeries;calculable;container;innerLookup;policy;exprSymbols;valueSymbols;onlyForTimeline;recalcTriggers;crashedComputationReported;isLoading;_sourceFields;_targetFields;basisChangedToken;quoteGroupToken;constructor(e,t,i){this.exprModel=e,this.innerSeries=t,this.calculable=!0,this.valueSymbols=[],this.crashedComputationReported=!1,this.isLoading=!1,this.basisChangedToken=null,this.quoteGroupToken=null,this.container=null,this.innerLookup=t.reduce((e,t)=>(e[i.mapper(t)]=t,e),{}),this.policy=i,this.exprSymbols=nJ(e),this.valueSymbols=this.exprSymbols.filter(e=>void 0===this.innerLookup[e]),this.onlyForTimeline=ev(this.symbols,this.exprSymbols),this.recalcTriggers=new Set(t)}refresh(){this.innerSeries.forEach(e=>e.refresh())}get canLoadMoreData(){return this.policy.loadMoreData&&this.innerSeries.some(e=>e.canLoadMoreData)}async loadMoreData(e=!0){if(this.isLoading)return Promise.resolve();this.isLoading=!0;let t=this.innerSeries.filter(e=>e.canLoadMoreData).map(t=>t.loadMoreData(e));await Promise.all(t),this.isLoading=!1}get isExprInError(){return!eF(this.exprModel)}get hasData(){return null!==this.container}get sourceFields(){return this._sourceFields||(this._sourceFields=Array.from(this.policy.fieldMap.keys())),this._sourceFields}get targetFields(){return this._targetFields||(this._targetFields=Array.from(this.policy.fieldMap.values())),this._targetFields}async ready(){return tU.call(this,async()=>{this.basisChangedToken=e(cp).subscribe(ay.TS_ALL,this.onBasisChanged.bind(this)),this.quoteGroupToken=e(cp).subscribe(ay.RT_QUOTEGROUP,this.onQuoteGroup.bind(this));let t=this.innerSeries.map(e=>e.ready());void 0!==this.policy.valueProvider&&t.push(this.policy.valueProvider.ready());let i=(await Promise.all(t)).every(ep);return i&&this.calculate(),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onQuoteGroup(e,t){t.source===this.policy.valueProvider&&this.innerSeries.every(e=>eF(e.container))&&this.calculateCommon(ay.TS_MANYCHANGED)}onBasisChanged(e,t){if(this.policy.recompute===B.Manual||e===ay.TS_EVENTSCHANGED||e===ay.TS_LOADING||!this.shouldTriggerOurRecalc(t.series)||this.innerSeries.some(e=>!eF(e.container)))return;let i=this.policy.mapper(t.series);if(!(e===ay.TS_DATAPOINTCHANGED&&this.onlyForTimeline?.includes(i)))switch(this.policy.recompute===B.Everything?ay.TS_MANYCHANGED:e){case ay.TS_MANYCHANGED:this.calculate();break;case ay.TS_DATAPOINTCHANGED:case ay.TS_DATAPOINTADDED:this.recalculate(e===ay.TS_DATAPOINTADDED);break;case ay.TS_TIMELINECORRECTION:case ay.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.basisChangedToken&&e(cp).unsubscribe(this.basisChangedToken),this.quoteGroupToken&&(e(cp).unsubscribe(this.quoteGroupToken),this.policy.valueProvider?.shutdown())}calculateAt(e){return e.isNull?null:this.sourceFields.map((t,i)=>t===ag.Volume?em(this.exprSymbols.map(t=>e.inn[t].values[i]??0)):nq(this.exprModel,t=>e.oneValue[t]??e.inn[t]?.values[i]??null))}pickMainField(){let e=null;for(let t of this.policy.fieldMap.values())if(null==e)e=t;else if(t===ag.Close){e=t;break}return e}calculateLastChange(){let e=this.container,t=e.size;if(t<=1)return;let i=this.pickMainField(),s=e.getData(i)[t-2],r=e.getData(i)[t-1];eF(s,r)&&e.setLastDataPoint(ag.Change,r-s)}calculateDataPoint(e,t){let i=this.calculateAt(e);if(null===i)return;e.atLeastOne=!0;let[s,r]=eM(i,0,3);i[1]=r,i[2]=s,this.targetFields.forEach((e,s)=>{let r=i[s];t?this.container.addDataPoint(e,r):this.container.setLastDataPoint(e,r)}),t&&(this.container.addDataPoint(ag.Change,null),this.container.addDataPoint(ag.DateTime,new Date(e.timeStamp))),this.calculateLastChange()}notify(e){eN(e,{series:this,index:this.container.size-1})}fieldValueAt(e,t,i){let s=this.innerLookup[e].container.getData(i);return t<0||t>=s.length?null:s[t]}timeStampAt(e,t){return this.fieldValueAt(e,t,ag.DateTime)}timeline(e){return e.container.getData(ag.DateTime)}getRangeHelper(){switch(this.policy.missing){case F.UseNext:case F.UseNone:return Math.min;case F.UsePrevious:return Math.max;default:throw Error("Unknow missing bar policy, likely forgot to implement it.")}}getRange(){let e=this.getRangeHelper();return{begin:new Date(e(...this.symbols.map(e=>eb(this.timeline(this.innerLookup[e]))))),end:new Date(e(...this.symbols.map(e=>eC(this.timeline(this.innerLookup[e])))))}}getFirstPos(){return this.getPos(this.getRange().begin)}getLastPos(){return this.getPos(this.getRange().end)}findIndex(e,t){let i=this.timeline(this.innerLookup[e]);switch(this.policy.missing){case F.UseNext:case F.UseNone:return i.findIndex(e=>e.valueOf()>=t.valueOf());case F.UsePrevious:return eE(i,e=>e.valueOf()<=t.valueOf());default:throw Error("Unknow missing bar policy, likely forgot to implement it.")}}checkPos(e){let t=Object.keys(e.inn).length;e.isNull=Object.values(e.inn).some(e=>!eF(e.timeStamp)&&(!this.policy.stretch(e.symbol)||1===t))}fillPosSymbolAt(e,t,i){e.index=t,e.timeStamp=this.timeStampAt(e.symbol,t);let s=(this.policy.missing===F.UseNone||this.policy.skipLeadingEmpty&&!i.atLeastOne)&&e.timeStamp&&e.timeStamp.valueOf()!==i.timeStamp.valueOf();return e.values=this.sourceFields.map(i=>s?null:this.fieldValueAt(e.symbol,t,i)),e}skippable(e){return!!this.innerLookup[e].container.isEmpty&&(this.policy.noDataApproach===k.IgnoreTimelineOnly&&this.onlyForTimeline.includes(e)||this.policy.noDataApproach===k.ModelTransformRequired)}get symbols(){let e=Object.keys(this.innerLookup);return eF(this.onlyForTimeline)?e.filter(e=>!this.skippable(e)):e}getPos(e){let t={isNull:!0,inn:{},timeStamp:e,atLeastOne:!1,oneValue:{}};return 0===this.symbols.length||(this.symbols.forEach(i=>{let s=this.findIndex(i,e),r={symbol:i,index:-1,timeStamp:new Date(0),values:[]};t.inn[i]=this.fillPosSymbolAt(r,s,t)}),this.valueSymbols.forEach(e=>{t.oneValue[e]=this.policy.valueProvider?.getValue(e)??null}),this.checkPos(t)),t}getInner(e){return Object.values(e.inn)}moveNext(e){!e.isNull&&(this.getInner(e).forEach(t=>{for(;eF(t.timeStamp)&&t.timeStamp.valueOf()<=e.timeStamp.valueOf();)this.fillPosSymbolAt(t,t.index+1,e)}),this.checkPos(e),e.isNull||(e.timeStamp=new Date(Math.min(...this.getInner(e).filter(e=>null!==e.timeStamp).map(e=>e.timeStamp.valueOf()))),this.policy.missing===F.UsePrevious?this.getInner(e).forEach(t=>{let i=eF(t.timeStamp);(i&&t.timeStamp.valueOf()>e.timeStamp.valueOf()||!i&&this.policy.stretch(t.symbol))&&this.fillPosSymbolAt(t,t.index-1,e)}):this.policy.missing===F.UseNone&&this.getInner(e).forEach(t=>this.fillPosSymbolAt(t,t.index,e))))}shouldAdd(e){return this.container.getLastDataPoint(ag.DateTime).valueOf()<e.timeStamp.valueOf()}calculateCommon(e=null,t=null,i=!0){try{if(t)this.calculateDataPoint(t,i);else if(this.container=this.makeContainer(),!this.isExprInError){let e=this.getFirstPos();for(;!e.isNull;)this.calculateDataPoint(e,!0),this.moveNext(e)}e&&this.notify(e)}catch(e){this.crashedComputationReported||(So(e,"error"),this.crashedComputationReported=!0)}}calculate(){let{yes:e,no:t}=eA(this.innerSeries,e=>!e.container.isEmpty);if(t.length>0&&this.policy.noDataApproach===k.ModelTransformRequired){let i=e=>e.map(this.policy.mapper),s=this.policy.modelTransform(i(e),i(t));null!==s&&(this.exprModel=s)}this.calculateCommon(ay.TS_MANYCHANGED)}recalculate(e){if(this.isExprInError)return;let t=this.getLastPos(),i=this.shouldAdd(t);this.calculateCommon(i?ay.TS_DATAPOINTADDED:ay.TS_DATAPOINTCHANGED,t,i)}recalculateAt(e,t,i){return this.recalculate(i)}makeContainer(){return new l8([ag.DateTime,ag.Change].concat(this.targetFields))}getCacheableEntities(e){this.innerSeries.forEach(t=>{t.getCacheableEntities(e)})}}let pS=cm("_AVG"),pA=cm("_HAO"),pT=cm("_HAH"),pv=cm("_HAL"),pP=cm("_HAC"),pC=cm("_DELTA"),pb=cm("_DIFF"),pE=cm("_RANK"),pL=cm("_CHG"),p_=cm("_AVG"),pM=cm("_HBRAKE_CHG"),px=cm("_HEIGHT_DELTA"),pI=cm("_ACTION"),pD=cm("_REVERSAL"),pO=e=>[e>0,e<0],pw=[null,null,null];function pR([e,t],i){let s=null;if(i>0){let t=this.baseVal(e,i-1);eF(t)&&(s=this.baseVal(e,i)-t)}return{[t.id]:s}}class pN extends cg{useHandbrake;constructor(e,t){super(e,t);let i=fJ(e,"MA","Average"),s=i(t,e2(1,999,this.inputs.FastPeriod),ag.Close),r=e2(0,999,this.inputs.SlowPeriod),n=r>0,a=n?i(t,r,ag.Close):t,o=fG(pb,n?(e,t,i)=>t-i:(e,t,i)=>i-t,s,a),l=f$(pL,eh(pR,[ag.Close,pL]),t),u=f$(pE,function(e){let t=Math.abs(this.baseVal(pb,e)),i=null,s=0,r=0;for(let i=e-1;i>=0&&s<200;--i){let e=Math.abs(this.baseVal(pb,i));s++,e<t&&r++}return s>0&&(i=Math.floor(r/s*10)),10===i&&i--,{[pE.id]:i}},o),h=e2(0,999,this.inputs.HandbrakePeriod);this.useHandbrake=h>0;let c=i(t,h,ag.Close,p_),d=f$(pM,eh(pR,[p_,pM]),c);this.addInner(l,o,u,d)}get helpers(){return[px,ag.BARCOLIX,pI,pD]}getStateAt(e){let t=this.innVal(2,pb,e);return eF(t)?pO(t):pw}findPreviousKnownState(e){for(let t=e-1;t>0;t--){let e=this.getStateAt(t);if(e===pw)break;let[i,s]=e;if(i||s)return e}return pw}getBuySell(e){let t=this.getStateAt(e);if(t===pw)return pw;let[i,s]=t,r=this.findPreviousKnownState(e),[n,a]=r;if(!i&&!s)return r===pw?pw:[n,a,!1];let o=i!==n||s!==a;return o?[n,a,o]:[i,s,o]}getPrev(e,t){return t>0?this.container.getData(e)[t-1]:null}calculateAt(e){let t=null,i=null,s=0,r=-1,n=0,[a,o,l]=this.getBuySell(e),[u,h]=[pD,pI].map(t=>this.getPrev(t,e)),[c,d]=[0,-1].map(t=>this.innVal(4,pM,e+t));if(r=l?10:this.innVal(3,pE,e),this.useHandbrake&&eF(c,d)){let t=a&&d>0||o&&d<0,i=!a&&c>0||!o&&c<0;l?(r=i?10:12,n=h):(!0===u||1===h)&&(t?(r=this.innVal(3,pE,e),n=2):(r=i?11:13,n=1))}if(eF(this.innVal(2,pb,e))){let t=this.innVal(1,pL,e),[i,r]=pO(t),n=Math.abs(t);(a&&i||o&&r)&&(s=n),(a&&r||o&&i)&&(s=-n)}return a?t=1:o&&(i=1),{[ag.JPIB.id]:t,[ag.JPIS.id]:i,[ag.BARCOLIX.id]:r,[px.id]:s,[pI.id]:n,[pD.id]:l}}}let pV={FastPeriod:8,SlowPeriod:21,HandbrakePeriod:13,Average:"EMA",Height:"Fixed"},pH=cm("_SMTH_ROC"),pF=cm("_TEN_SMTH_ROC");function pB(e,t,i,s,r){return new cT({source:s,target:r,outFields:[r],aggregation:i,inputs:fP(t)},e,e=>2/e)}let pk=cm("_VOL_AVG"),pW=131,pU=(()=>{let e=eB(.9865008210958766,6),t=ex(52,t=>Math.pow(e,t)),i=52/em(t);return t.map(e=>e*i)})(),p$=["Renko","Kagi","PointAndFigure","LineBreak"];function pG(e){return e===z.Continue||e===z.Nearest}class pz extends cg{additionalChunksCounter=1;noData=!1;isPeriodic=!1;constructor(e,t,i){super(e,i,cf(i,e=>{if(!sB(er[Sp()?.config.mode??"Unspecified"]))return i;let t=e.duplicate(),s=e.aggregation;if(s.hasSpec)if(pG(s.spec))return i;else return new uJ(t,!0);let r=s.unit===G.Intraday&&s.size<=5,n=function(e,t){switch(e){case G.Intraday:if(t>=240)return 3;if(t>=120)return 2;return 1;case G.Day:default:return 5;case G.Week:return 15;case G.Month:return 60;case G.Quarter:case G.Year:return 240}}(s.unit,s.size);return t.aggregation=r?new nw(G.Tick,s.size,z.PerSeconds):new nw(G.Intraday,n),t.barsToFetch=Math.min(tz.MAX_INTRADAY_BARS,(r?1:3)*e.barsToFetch),new uZ(t)})),this.isPeriodic=t,this.noData=this.innerSeries[1]instanceof uJ,this.computedServerSide=!0,this.initialNotification=!0}get canLoadMoreData(){return!1}loadMoreData(){let e=this.innerSeries[1];return!this.noData&&this.additionalChunksCounter<20&&e.canLoadMoreData&&!e.isLoading?(this.additionalChunksCounter+=1,e.loadMoreData()):Promise.resolve()}recalculateAt(e,t,i){if(e.src!==this.innerSeries[0])return;let s=i?ay.TS_DATAPOINTADDED:ay.TS_DATAPOINTCHANGED;this.notify(s,this.innerSeries[0].container.size-1)}getWrappers(){return[this.wrapInner(ag.Change,1),this.wrapInner(ag.Open,1),this.wrapInner(ag.Close,1)]}}let pY=cm("_EMA1"),pj=cm("_EMA2"),pK=cm("_MACD"),pq=cm("_PCTK"),pX=cm("_PCTD"),pZ=cm("_PCTK2"),pJ=cm("_EMA1"),pQ=cm("_EMA2"),p0=cm("_CORE");class p1 extends cg{isEmpty=!1;constructor(e,t){if(super(e,t),f2(t)&&e.aggregation?.isEndOfDay){let i=["$ADVT","$DECT"];switch(this.inputs.Source){case"TotalStocks":default:break;case"NYSEStocks":i=["$ADVN","$DECN"];break;case"NasdaqStocks":i=["$AVDQ","$DECQ"]}let s=this.getSeries(t.query,i[0]),r=this.getSeries(t.query,i[1]),n=this.getTargetSeries(e,s,r);this.addInner(s,r,n),this.canLoadMoreData=!0,this.initialNotification=!0}else{this.isEmpty=!0;let e=f$(ag.Close,(e,t)=>null,t),i=f$(ag.Close,(e,t)=>null,t),s=f$(this.target,(e,t)=>null,t);this.addInner(e,i,s),this.canLoadMoreData=!1}}get baseIndex(){return+!this.isEmpty}getSeries(e,t){let i=e.duplicate();return i.symbol=t,Sp().getTimeSeriesDataSource().getTimeSeries(i)}shouldTriggerOurRecalc(e){return!!super.shouldTriggerOurRecalc(e)||e!==this.innerSeries[0]&&(e===this.innerSeries[1]||e===this.innerSeries[2])&&this.innHasData(1)&&this.innHasData(2)}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[1].canLoadMoreData||!this.innerSeries[2].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),await this.innerSeries[2].loadMoreData(e),this.isLoading=!1}getWrappers(){return[this.wrapInner(this.target,3)]}}let p2=cm("_INN_HL_ACC_IX"),p3=new nw;class p4 extends cg{isWeekly=!1;constructor(e,t){if(super(e,t),t instanceof uJ)this.canLoadMoreData=!1;else{let s="PriceIndex"===this.inputs.Source?"$MADX":"$FADX",r=this.getSeries(t.query,s);if(this.addInner(r),this.isWeekly=e.aggregation.unit===G.Week,this.isWeekly){var i;let e=(i=this.getSeries(t.query,s,p3),new p4({aggregation:p3,source:null,target:p2,outFields:[p2],inputs:{...this.inputs}},i));this.addInner(e)}this.canLoadMoreData=!0,this.initialNotification=!0}}getSeries(e,t,i){let s=e.duplicate();return s.symbol=t,i&&(s.aggregation=i,s.barsToFetch=15*tz.US_TRADING_DAYS_PER_YEAR),Sp().getTimeSeriesDataSource().getTimeSeries(s)}get baseIndex(){return 1}calculateAt(e){if(this.isWeekly)return this.calculateAtWeekly(e);let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,ag.Close);ey(s)&&(t=em(s))}return{[this.target.id]:t}}calculateAtWeekly(e){let t=this.container?.size??-1,i=null,s=this.innCont(2);if(t>0&&e===t-1)i=s.getLastDataPoint(p2);else{let t=this.container.getTimeData()[e],r=s.getTimeData(),n=e_(r,t),a=r[n],o=null;for(;n<s.size&&nb(t,a);)o=n,n+=1,a=r[n];null!==o&&(i=s.getData(p2)[o])}return{[this.target.id]:i}}shouldTriggerOurRecalc(e){return!!super.shouldTriggerOurRecalc(e)||e!==this.innerSeries[0]&&e===this.innerSeries[1]&&this.innHasData(1)}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[1].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}}let p5=cm("_RSI1"),p6=cm("_RSI1_MOM"),p7=cm("_RSI2"),p8=cm("_RSI2_MA"),p9=cm("_MUL_ATR");class fe extends cg{constructor(e,t){super(e,cf(t,t=>{let i=Sp().getTimeSeriesDataSource();return t.seriesKind=J.Options,t.fields=e.outFields,i.getTimeSeries(t)})),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return this.outFields.map(e=>this.wrapInner(e,0))}}let ft=cm("_CORE");class fi extends uZ{constructor(e){super(e)}getRetriever(){return tg(this.query.symbol)?new fn:tP(this.query.symbol)?new fa:new fr}}function fs(){return new l8([ag.DateTime,ag.Delta,ag.Gamma,ag.Theta,ag.Vega])}class fr{supportsChunks;constructor(){this.supportsChunks=!1}async retrieve(e){return fs()}}class fn extends uT{emptyContainer(e,t){return fs()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(ag.DateTime,l2(e.date.substring(0,10))),i.addDataPoint(ag.Delta,e.delta),i.addDataPoint(ag.Gamma,e.gamma),i.addDataPoint(ag.Theta,e.theta),i.addDataPoint(ag.Vega,e.vega)}}class fa extends uT{emptyContainer(e,t){return fs()}addExtraParams(e){e.fields="delta,gamma,theta,vega"}get iterateForward(){return!0}getPageName(){return"getEquityOptionsHistory"}processRow(e,t,i){i.addDataPoint(ag.DateTime,l2(e.date)),i.addDataPoint(ag.Delta,e.delta),i.addDataPoint(ag.Gamma,e.gamma),i.addDataPoint(ag.Theta,e.theta),i.addDataPoint(ag.Vega,e.vega)}}let fo=cm("_RSI1"),fl=cm("_RSI2"),fu=cm("_ANCHR"),fh=cm("_HH_N"),fc=cm("_LL_N"),fd=cm("_HH_H1"),fp=cm("_LL_H1"),ff=cm("_HH_H2"),fm=cm("_LL_H2"),fg=cm("_MIDPOINT"),fy=cm("_VALUE");class fS extends cg{constructor(e,t){super(e,t),fj(this)}computeMidranks(e){let t=e.length,i=e.map((e,t)=>({v:e,i:t}));i.sort((e,t)=>e.v-t.v);let s=Array(t),r=0;for(;r<t;){let e=r,n=i[r].v;for(;e+1<t&&i[e+1].v===n;)e++;let a=(r+1+(e+1))/2;for(let t=r;t<=e;t++)s[i[t].i]=a;r=e+1}return s}pearsonCorrelation(e){let t=e.length;if(t<2)return null;let i=(t+1)/2,s=0;for(let i=0;i<t;i++)s+=e[i];let r=s/t,n=0,a=0,o=0;for(let s=0;s<t;s++){let t=s+1-i,l=e[s]-r;n+=t*l,a+=t*t,o+=l*l}let l=Math.sqrt(a*o);return 0===l?null:n/l}calculateAt(e){let t=null,i=this.period,[,s]=fK(this);if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);if(r.every(e=>null!==e)){let e=this.computeMidranks(r),i=this.pearsonCorrelation(e);null!==i&&(t=100*i)}}return{[ag.RCI.id]:t}}}let fA=cm("_ATR");var fT=((D=fT||{})[D.Uninitialized=0]="Uninitialized",D[D.UpLeg=1]="UpLeg",D[D.DownLeg=-1]="DownLeg",D);let fv={_TR:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=this.baseVal(ag.High,e),s=this.baseVal(ag.Low,e);if(e>0){let r=this.baseVal(ag.Close,e-1);t=Math.max(i-s,Math.abs(i-r),Math.abs(s-r))}else t=i-s;return{[this.target.id]:t}}},_RSI:class extends cg{isModified;constructor(e,t){super(e,t);let i=e.inputs.Modified;this.isModified=i}get helpers(){return[cN,cV]}gain(e,t){return t[e]>t[e-1]?t[e]-t[e-1]:0}loss(e,t){return t[e]<t[e-1]?t[e-1]-t[e]:0}calculateAt(e){let t=null,i=null,s=null,r=this.period;if(this.atLeast(e,r+1)){if(null===this.container.getData(this.target)[e-1]||this.isModified){let t=this.past(e,r+1,this.source);if(ey(t)){let e=eS(1,r),n=e.map(e=>this.gain(e,t)),a=e.map(e=>this.loss(e,t));i=eg(n),s=eg(a)}}else{let t=this.container.getData(cN)[e-1],n=this.container.getData(cV)[e-1],a=this.past(e,2,this.source),o=this.gain(1,a),l=this.loss(1,a);i=(t*(r-1)+o)/r,s=(n*(r-1)+l)/r}null!==i&&null!==s&&(t=100-100/(1+i/s))}return{[cN.id]:i,[cV.id]:s,[this.target.id]:t}}},MA:cA,MAEXP:class extends cT{constructor(e,t){super(e,t,e=>2/(e+1))}},MAHLC:class extends cg{constructor(e,t){super(e,t);let i=f_(t,this.inputs.Period1,ag.High,ag.MAHI),s=f_(t,this.inputs.Period2,ag.Low,ag.MALO);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.MAHI,1),this.wrapInner(ag.MALO,2)]}},VOL:class extends cv{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(ag.Volume,ag.TradeSize,ag.Change,ag.Open,ag.Close)}},MAENV:class extends cE{constructor(e,t){super(e,cP,t)}},MAENVEXP:class extends cE{constructor(e,t){super(e,cC,t)}},MAENVSMO:class extends cE{constructor(e,t){super(e,cb,t)}},MATRI:class extends cg{constructor(e,t){super(e,t);let i=f_(t,this.inputs.Period,this.source),s=f_(i,this.inputs.Period,ag.MA,ag.TMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.TMA,2)]}},MAWEI:class extends cg{triangle;constructor(e,t){super(e,t);let i=this.period;this.triangle=i*(i+1)/2,fj(this)}weightedAverage(e){let t=e.length;if(0===t)return null;let i=t===this.period?this.triangle:t*(t+1)/2;return e.reduce((e,t,i)=>e+t*(i+1),0)/i}calculateAt(e){let t=null,i=this.period,[,s]=fK(this);if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=this.weightedAverage(r.filter(ef)):ey(r)&&(t=this.weightedAverage(r))}return{[this.target.id]:t}}},MAVOL:cA,MASMO:class extends cT{constructor(e,t){super(e,t,e=>1/e)}},MACD:class extends cR{constructor(e,t){super(e,c_,t)}},MACDEXP:class extends cR{constructor(e,t){super(e,cM,t)}},MACDV:class extends cw{constructor(e,t){super(e,t),this.histogramVaryColor=!0,this.histogramField=ag.MACDVH;let i=fJ(e,"EMA","Average"),s=i(t,e.inputs.Period1,e.source,void 0),r=i(t,e.inputs.Period2,e.source,void 0),n=fV(t,e.inputs.Period2,e.inputs.Average),a=fG(ag.MACDV,(e,t,i,s)=>(t-i)/s*100,s,r,n),o=i(a,e.inputs.Period3,a.target,ag.MACDVS),l=fG(ag.MACDVH,fz,a,o);this.addInner(a,o,l)}getWrappers(){return[this.wrapInner(ag.MACDV,1),this.wrapInner(ag.MACDVS,2),this.wrapInner(ag.MACDVH,3)]}},GMMA:class extends cg{constructor(e,t){super(e,t);for(let r=1;r<=12;++r){var i,s;let n=(i=e.inputs,s=r,i[`Period${s}`]);this.addInner(fM(t,n,ag.Close,e.outFields[r-1]))}}getWrappers(){return eS(1,12).map(e=>this.wrapInner(this.outFields[e-1],e))}},OSCI:cL,OSCIVOL:cL,RSI:class extends cH{constructor(e,t){super(e,!1,t)}},RSIMOD:class extends cH{constructor(e,t){super(e,!0,t)}},RSISTO:class extends cg{constructor(e,t){super(e,t);let i=fB(t,this.inputs.Period,this.source),s=this.inputs.Range,r=f$(ag.STORSI,function(e){let t=null;if(this.atLeast(e,s)){let i=this.past(e,s,ag.RSI,this.base),r=eM(i),n=r[0],a=r[1];t=(eC(i)-n)/(a-n)}return{[ag.STORSI.id]:t}},i),n=fJ(e,"MA","Average")(r,this.inputs.PeriodAvg,ag.STORSI,ag.STORSIAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(ag.STORSI,1),this.wrapInner(ag.STORSIAVG,2)]}},RSA:class extends cg{constructor(e,t){super(e,t);let i=fB(t,this.inputs.Period1,this.source,fo),s=fB(t,this.inputs.Period2,this.source,fl),r=fG(ag.RSA,(e,t,i)=>(t+i)/2,i,s),n=fJ(e,"MA","Average")(r,this.inputs.PeriodAvg,ag.RSA,ag.RSAAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(ag.RSA,1),this.wrapInner(ag.RSAAVG,2)]}},WPERCR:class extends cB{constructor(e,t){super(e,!0,t)}},HHLL:class extends cg{constructor(e,t){super(e,t);let i=fO(t,this.inputs.Period1,ag.High,ag.HH,!0),s=fO(t,this.inputs.Period2,ag.Low,ag.LL,!1);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.HH,1),this.wrapInner(ag.LL,2)]}},WGCL:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,[i,s,r]=[ag.Close,ag.High,ag.Low].map(t=>this.baseVal(t,e));return t=(2*i+s+r)/4,{[this.target.id]:t}}},STOCHF:class extends cW{constructor(e,t){super(e,!1,ag.PercK,t)}},STOCHS:class extends cW{constructor(e,t){super(e,!0,ag.PercK,t)}},BBANDS:class extends c${constructor(e,t){super(e,"Regular",t)}},BWIDTH:class extends c${constructor(e,t){super(e,"Width",t)}},BPERC:class extends c${constructor(e,t){super(e,"Percent",t)}},OBVOL:class extends cg{constructor(e,t){super(e,t);let i=f$(ag.OBVOL,function(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Volume,e),r=this.baseVal(ag.Close,e-1),n=this.container.getData(this.target)[e-1];eF(n)||(n=0),t=i>r?n+s:i<r?n-s:n}return{[this.target.id]:t}},t),s=fJ(e,"MA","Average")(i,this.period,ag.OBVOL,ag.OBVOLAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.OBVOL,1),this.wrapInner(ag.OBVOLAVG,2)]}},ATR:class extends cg{constructor(e,t){super(e,t);let i=fN(t,ag.TR),s=fJ(e,"SMA")(i,this.inputs.Period,ag.TR,this.target),r=f_(s,this.inputs.Period2,ag.ATR,ag.ATRMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(this.target,1),this.wrapInner(ag.ATRMA,2)]}},ATRP:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period,e.inputs.Smoothing);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(1,ag.ATR,e),s=this.baseVal(ag.Close,e);return eF(i,s)&&s>0&&(t=i/s*100),{[ag.ATRP.id]:t}}},ADX:class extends cQ{constructor(e,t){super(e,!1,ag.ADX,t)}},ADXMOD:class extends cQ{constructor(e,t){super(e,!0,ag.ADXM,t)}},ADL:class extends cg{constructor(e,t){super(e,t);let i=fk(t);this.addInner(i)}calculateAt(e){let t=null;return t=(e>0?this.container.getData(this.target)[e-1]:0)+this.innVal(1,ag.MFMUL,e),{[this.target.id]:t}}},ADWM:class extends cg{constructor(e,t){super(e,t);let i=f$(ag.ADWM,function(e){let t=null,i=null;if(e>0){let s=this.baseVal(ag.Close,e-1),r=Math.max(s,this.baseVal(ag.High,e)),n=Math.min(s,this.baseVal(ag.Low,e)),a=this.baseVal(ag.Close,e);t=a>s?a-n:a<s?a-r:0,e>1&&(i=(e>2?this.container.getData(ag.ADWM)[e-1]:0)+t)}return{[ag.ADWM.id]:i}},t),s=f_(i,this.inputs.Period,ag.ADWM,ag.ADWMMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.ADWM,1),this.wrapInner(ag.ADWMMA,2)]}},CHAOSC:class extends cg{constructor(e,t){super(e,t);let i=ag.ADL,s=function(e,t=ag.ADL){return fb("ADL",fC(t),e)}(t,i),r=fM(s,3,i),n=fM(s,10,i),a=fG(e.target,(e,t,i)=>t-i,r,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},TP:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null;return t=eg([ag.Close,ag.High,ag.Low].map(t=>this.baseVal(t,e))),{[this.target.id]:t}}},KELCHN:class extends c8{constructor(e,t){super(e,c6,t)}},KELBND:class extends c8{constructor(e,t){super(e,c7,t)}},DONCHN:class extends c9{constructor(e,t){super(e,!1,t)}},DONWIDTH:class extends c9{constructor(e,t){super(e,!0,t)}},PVT:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Volume,e),r=this.baseVal(ag.Close,e-1),n=this.container.getData(this.target)[e-1];eF(n)||(n=0),t=n+(i-r)/r*s}return{[this.target.id]:t}}},ROC:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i+1)){let s=this.baseVal(this.source,e-i);null!==s&&0!==s&&(t=(this.baseVal(this.source,e)-s)/s*100)}return{[this.target.id]:t}}},TRIX:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,this.source),s=fM(i,this.inputs.Period,i.target),r=fM(s,this.inputs.Period,s.target),n=fF(r,1,r.target,this.target);this.addInner(n)}getWrappers(){return[this.wrapInner(this.target,1)]}},PPMOV:class extends cg{constructor(e,t){super(e,t);let i=fH(t,ag.PVPT);this.addInner(i)}calculateAt(e){let t=this.innVal(1,ag.PVPT,e),i=this.baseVal(ag.High,e),s=this.baseVal(ag.Low,e);return{[ag.PVPTR.id]:t+i-s,[ag.PVPTS.id]:t-i+s}}getWrappers(){return[this.wrapInner(ag.PVPT,1)]}},PIVPTS:class extends dH{constructor(e,t){super(e,dV[e.inputs.Previous],t)}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=null;if(!this.disabled){let e=this.getValues(this.inputs.Previous);if(ey(e)){let[l,u,h]=e,c=2*(t=(l+u+h)/3);i=c-u,s=c-l;let d=l-u;r=t+d,n=t-d,a=l+2*(t-u),o=u-2*(l-t)}}return{[ag.PPTPIV.id]:t,[ag.PPTR1.id]:i,[ag.PPTR2.id]:r,[ag.PPTR3.id]:a,[ag.PPTS1.id]:s,[ag.PPTS2.id]:n,[ag.PPTS3.id]:o}}},CPP:class extends dH{constructor(e,t){super(e,dV.Day,t)}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=null,l=null;if(!this.disabled){let e=this.getValues("Day");if(ey(e)){let[u,h,c]=e,d=u-h,[p,f,m,g]=[2,4,6,12].map(e=>1.1/e*d);o=c+p,n=c+f,s=c+m,t=c+g,i=c-g,r=c-m,a=c-f,l=c-p}}return{[ag.CPPH4.id]:o,[ag.CPPH3.id]:n,[ag.CPPH2.id]:s,[ag.CPPH1.id]:t,[ag.CPPL1.id]:i,[ag.CPPL2.id]:r,[ag.CPPL3.id]:a,[ag.CPPL4.id]:l}}},ARNUPDW:class extends di{constructor(e,t){super(e,!1,t)}},ARNOSC:class extends di{constructor(e,t){super(e,!0,t)}},TCHN:class extends cg{constructor(e,t){super(e,t);let i="Close"===e.inputs.Range,s=f1(t);if(!i&&s){let e=f$(ag.TCHNUP,(e,t)=>null,t),i=f$(ag.TCHNLOW,(e,t)=>null,t);this.addInner(e,i)}else{let s=fO(t,e.inputs.PeriodUpper,i?ag.Close:ag.High,ag.TCHNUP,!0),r=fO(t,e.inputs.PeriodLower,i?ag.Close:ag.Low,ag.TCHNLOW,!1);this.addInner(s,r)}}getWrappers(){return[this.wrapInner(ag.TCHNUP,1),this.wrapInner(ag.TCHNLOW,2)]}},TCHRE:class extends cg{constructor(e,t){super(e,t);let i=function(e,t,i){let s="TCHN",r=fE(s);return fb(s,{inputs:{PeriodUpper:t,PeriodLower:t,Range:i},outFields:r,source:null},e)}(t,e.inputs.Period,e.inputs.Range);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(1,ag.TCHNUP,e),s=this.innVal(1,ag.TCHNLOW,e),r=this.inputs.Adjustment,n=this.inputs.Retracement;return"Long"===n?t=eF(i)?i-r:null:"Short"===n&&(t=eF(s)?s+r:null),{[this.target.id]:t}}},ALLG:class extends cg{constructor(e,t){super(e,t);let i=f$(ds,eh(c1,ds),t),s=fx(i,e.inputs.Period1,ds,ag.ALJAW),r=fx(i,e.inputs.Period2,ds,ag.ALTEETH),n=fx(i,e.inputs.Period3,ds,ag.ALLIPS);this.addInner(s,r,n)}calculateAt(e){return{[ag.ALJAW.id]:this.innVal(1,ag.ALJAW,e),[ag.ALTEETH.id]:this.innVal(2,ag.ALTEETH,e),[ag.ALLIPS.id]:this.innVal(3,ag.ALLIPS,e)}}},PLTLN:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){return{[ag.PLTLN.id]:this.inputs.Position}}},AWEOSC:class extends cg{constructor(e,t){super(e,t);let i=f$(dr,eh(c1,dr),t),s=f_(i,this.inputs.Period1,dr),r=f_(i,this.inputs.Period2,dr),n=fG(ag.AWOS,(e,t,i)=>t-i,s,r),a=f_(n,this.inputs.Period3,n.target,ag.AWOSMA);this.addInner(n,a)}getWrappers(){return[this.wrapInner(ag.AWOS,1),this.wrapInner(ag.AWOSMA,2)]}},MFV:class extends dn{constructor(e,t){super(e,!0,t)}},CLV:class extends dn{constructor(e,t){super(e,!1,t)}},CHAMF:class extends cg{constructor(e,t){super(e,t);let i=fk(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,ag.Volume),r=this.past(e,i,ag.MFMUL,this.innCont(1));if(ey(s)&&ey(r)){let e=em(s);0!==e&&(t=em(r)/e)}}return{[this.target.id]:t}}},CHAVOL:class extends cg{constructor(e,t){super(e,t);let i=fF(fM(f$(da,eh(c2,da),t),this.inputs.Period1,da),this.inputs.Period2,ag.EMA,this.target);this.addInner(i)}getWrappers(){return[this.wrapInner(this.target,1)]}},DPO:class extends cg{shift;constructor(e,t){super(e,t);let i=this.inputs.Period;this.shift=Math.floor(i/2)+1;let s=f_(t,i,e.source);this.addInner(s)}calculateAt(e){let t=null,i=this.shift,s=this.innVal(1,ag.MA,e-i);return null!==s&&(t=this.baseVal(this.source,e)-s),{[this.target.id]:t}}},CCI:class extends cg{constructor(e,t){super(e,t);let i=fH(t),s=f_(i,this.inputs.Period,i.target,dl);this.addInner(i,s)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,ag.TP,this.innCont(1));if(ey(s)){let i=this.innVal(2,dl,e);if(null!==i){let r=s.reduce((e,t,s)=>e+Math.abs(i-t),0)/this.period;t=(this.innVal(1,ag.TP,e)-i)/(.015*r)}}}return{[this.target.id]:t}}},EMV:class extends cg{constructor(e,t){super(e,t);let i=f$(ag.EMV,function(e){let t=null;if(e>0){let[i,s,r]=[ag.High,ag.Low,ag.Volume].map(t=>this.baseVal(t,e)),[n,a]=[ag.High,ag.Low].map(t=>this.baseVal(t,e-1));t=((i+s)/2-(n+a)/2)/(r/1e6/(i-s))}return{[this.target.id]:t}},t),s=f_(i,this.inputs.Period,ag.EMV,ag.EMVMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.EMV,1),this.wrapInner(ag.EMVMA,2)]}},ERBRPOW:class extends du{constructor(e,t){super(e,!1,t)}},ERBLPOW:class extends du{constructor(e,t){super(e,!0,t)}},FI:class extends cg{constructor(e,t){super(e,t);let i=fM(f$(dh,function(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Volume,e);t=(i-this.baseVal(ag.Close,e-1))*s}return{[this.target.id]:t}},t),this.inputs.Period,dh,ag.FI);this.addInner(i)}getWrappers(){return[this.wrapInner(ag.FI,1)]}},MI:class extends cg{constructor(e,t){super(e,t);let i=fM(f$(dc,eh(c2,dc),t),9,dc,dd),s=fM(i,9,dd,dp),r=fG(df,(e,t,i)=>t/i,i,s);this.addInner(r)}calculateAt(e){let t=null;if(this.atLeast(e,25)){let i=this.past(e,25,df,this.innCont(1));ey(i)&&(t=em(i))}return{[this.target.id]:t}}},MOM:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=f$(ag.MOM,ec(fX,i,ag.Close),t),r=f_(s,this.inputs.Movement,ag.MOM,ag.MOMMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(ag.MOM,1),this.wrapInner(ag.MOMMA,2)]}},MFI:class extends cg{constructor(e,t){super(e,t);let i=fH(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period+1;if(this.atLeast(e,i)){let s=this.past(e,i,ag.TP,this.innCont(1)),r=this.past(e,i,ag.Volume).map(e=>null!=e?e:0);if(ey(s)&&ey(r)){let e=0,n=0;for(let t=1;t<i;++t){let i=s[t]*r[t];s[t]>s[t-1]?e+=i:n+=i}t=100-100/(1+e/n)}}return{[this.target.id]:t}}},MSD:class extends cg{constructor(e,t){super(e,t),fj(this);let i=f_(t,this.inputs.Period,this.source);this.addInner(i)}calculateAt(e){let t=null,[i,s]=fK(this),r=this.innVal(i+1,ag.MA,e);if(null!==r){let i=this.inputs.Period,n=this.past(e,i,this.source,s);t=Math.sqrt(eg(n=n.map(e=>(e-r)*(e-r))))}return{[this.target.id]:t}}getWrappers(){let[e]=fK(this);return[this.wrapInner(ag.MA,e+1)]}},NVI:class extends dy{constructor(e,t){super(e,dg,t)}},PVI:class extends dy{constructor(e,t){super(e,dm,t)}},PPO:class extends cR{constructor(e,t){super(e,cD,t)}},PVO:class extends cR{constructor(e,t){super(e,cO,t)}},HV:class extends cg{constructor(e,t){super(e,t);let i=Math.sqrt(f0(e.aggregation));if(0===i){let e=f$(this.target,(e,t)=>null,t);this.addInner(e)}else{let s=fW(f$(dS,eh(function(e,t){let i=null;if(t>0){let s=this.baseVal(e,t),r=this.baseVal(e,t-1);null!==s&&null!==r&&(i=Math.log(s/r))}return{[dS.id]:i}},ag.Close),t),e.inputs.Period,dS,ag.MSD),r=f$(ag.HV,eh(function(e,t){let i=null,s=this.baseVal(ag.MSD,t);return null!==s&&(i=100*s*e),{[ag.HV.id]:i}},i),s);this.addInner(r)}}getWrappers(){return[this.wrapInner(this.target,1)]}},PERF:class extends cg{noOp;constructor(e,t){super(e,t);let i="VisibleStart"===this.inputs.Anchor;this.noOp=i}calculateAt(e){let t=null,i=this.baseVal(this.source,0),s=this.baseVal(this.source,e);return this.noOp?t=s:null!==i&&null!==s&&(t=(s-i)/i*100),{[this.target.id]:t}}},WASI:class extends cg{constructor(e,t){super(e,t)}get helpers(){return[dA]}ohlcVals(e){return[ag.Open,ag.High,ag.Low,ag.Close].map(t=>this.baseVal(t,e))}obtainR(e,t,i,s){let r=Math.abs(e-s),n=Math.abs(t-s),a=Math.abs(e-t),o=Math.max(r,n,a),l=.25*Math.abs(s-i);return o===r?r-.5*n+l:o===n?n-.5*r+l:a+l}calculateAt(e){let t=null,i=null;if(e>0){let s=this.container.getData(dA)[e-1];eF(s)||(s=0);let[r,n,a,o]=this.ohlcVals(e),[l,u,h,c]=this.ohlcVals(e-1);if(ey([r,n,a,o,l,c])){let e=Math.max(Math.abs(n-c),Math.abs(a-c)),u=this.inputs.Limit,h=this.obtainR(n,a,l,c);i=s+(t=(o-c+.5*(o-r)+.25*(c-l))/h*50*(e/u))}}return{[dA.id]:t,[this.target.id]:i}}},WWVOL:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period);this.addInner(i)}get helpers(){return[dv,dT]}calculateAt(e){let t=null,i=null,s=null,r=null,n=this.innVal(1,ag.ATR,e);if(null!==n){let a=this.baseVal(ag.Close,e),o=this.baseVal(ag.Close,e-1),l=this.period;s=Math.max(...this.past(e,l,ag.Close)),r=Math.min(...this.past(e,l,ag.Close));let u=n*this.inputs.Constant;if(null===this.innVal(1,ag.ATR,e-1))a>o?t=s-u:i=r+u;else{let[n,o,l,h]=[ag.WWVSARU,ag.WWVSARD,dv,dT].map(t=>this.container.getData(t)[e-1]);s=l,r=h,null!==n?a<n?(r=a,i=a+u):t=(s=Math.max(a,s))-u:a>o?(s=a,t=a-u):i=(r=Math.min(a,r))+u}}return{[dv.id]:s,[dT.id]:r,[ag.WWVSARU.id]:t,[ag.WWVSARD.id]:i}}},PARTP:class extends cg{constructor(e,t){super(e,t)}get helpers(){return[dP,dC,db]}hlcVals(e){return[ag.High,ag.Low,ag.Close].map(t=>this.baseVal(t,e))}me(e,t){return this.container.getData(e)[t]}reciprocal(e){return 1/e}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null;if(e>0){let[o,l,u]=this.hlcVals(e),[h,c,d]=this.hlcVals(e-1),p=this.reciprocal(this.inputs.Acceleration),f=this.reciprocal(this.inputs.Limit);if(1===e){let e=1==(n=u>d?1:-1);a=e?c:h,s=e?Math.max(o,h):Math.min(l,c),r=p,e?t=a:i=a}else{let[u,d,m,g,y]=[db,ag.PARSARS,ag.PARSARL,dP,dC].map(t=>this.me(t,e-1)),S=1===u,A=S?m:d,T=y*Math.abs(g-A),v=u===(n=S?A+T>l?-1:1:A-T<o?1:-1);a=v?S?Math.min(A+T,c,this.baseVal(ag.Low,e-2)):Math.max(A-T,h,this.baseVal(ag.High,e-2)):g,s=v?S?Math.max(o,g):Math.min(l,g):1===n?o:l,r=y,v?(S?s>g:s<g)&&y<f&&(r=y+p):r=p,1===n?t=a:i=a}}return{[dP.id]:s,[dC.id]:r,[db.id]:n,[ag.PARSARS.id]:i,[ag.PARSARL.id]:t}}},MOVLR:class extends cg{xSum;xSum2;x2Sum;constructor(e,t){super(e,t);let i=this.period;this.xSum=i*(i+1)/2,this.xSum2=this.xSum*this.xSum,this.x2Sum=i*(i+1)*(2*i+1)/6}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,this.source);if(ey(s)){let e=em(s),r=(i*em(s.map((e,t)=>e*(t+1)))-this.xSum*e)/(i*this.x2Sum-this.xSum2);t=(e-r*this.xSum)/i+r*i}}return{[this.target.id]:t}}},TRSP:class extends cg{haveEnoughData=!1;firstUsefulIndex=0;s3;itr;constructor(e,t){super(e,t),this.s3=this.itr=[];let i=["VelocityUpTrend","VelocitySideTrend","VelocityDownTrend"].map(t=>e.inputs[t]||"3").map(Number);dL.splice(6,3,...i)}get helpers(){return[dE]}prepareComputation(){let e=this.base.getData(ag.Close),t=0,i=0,s=e.length;for(;i<72&&t<s;)null!=e[t]&&i++,t++;this.haveEnoughData=t<s,this.firstUsefulIndex=t,this.s3=d_(s),this.itr=d_(s),this.haveEnoughData&&dx(e,this.s3,s)}us(e,t){return this.container.getData(e)[t]}recalculateAt(e,t,i){let s=this.base.getData(ag.Close),r=s.length;this.haveEnoughData&&dx(s,this.s3,r),super.recalculateAt(e,t,i)}calculateAt(e){let t=null,i=null,s=null,r=t=>this.us(t,e-1);if(0===e)this.prepareComputation();else if(this.haveEnoughData&&e>=this.firstUsefulIndex&&null!==this.baseVal(ag.Close,e)){let n=r(ag.TRSP1),a=r(ag.TRSP2);s=r(dE),null===n&&null===a&&(n=a=this.baseVal(ag.Close,this.firstUsefulIndex)),null===s&&(s=1);let o=this.base.getData(ag.Close);s=function(e,t,i,s,r,n){let a=i;do a--;while(e[a]<=0)return t[i]=t[a],e[i]>r&&t[a]<=0&&(t[i]=t[a]+1),e[i]<s&&t[a]>=0&&(t[i]=t[a]-1),n++,t[i]!==t[a]&&(n=1),n}(o,this.itr,e,n,a,s);let l=function(e,t,i,s,r){let n=s,a=dM(r,i[s],7),o=0;do e[--n]>0&&o++;while(o<a&&n>0)return t[s]-t[n]}(o,this.s3,this.itr,e,dL),u=function(e,t,i,s,r){let n=r[18],a=s+1,o=0;for(let i=0;i<n;++i){let i=0,s=0;for(let r=1;r<6;++r){if(e[--a]<=0)continue;let n=e[a]-t[a];1==r&&(i=s=n),n>i&&(i=n),n<s&&(s=n)}o=o+i-s}return o/n*dM(r,i[s],4)}(o,this.s3,this.itr,e,dL);[n,a]=function(e,t,i,s,r,n,a,o,l,u){let h=dM(r,i[s],10),c=dM(r,i[s],13),d=dM(r,i[s],16),p=l+u+t[s]-e[s],f=100;r[20]>0&&(f=r[20]);let m=h*o/f;o>c&&(m=h*c/f);let g=2*u,y=e[s]+(p-g)-(p-g)*m,S=e[s]+(p-p*m),A=[n,a];return(1===o||1!==d||y>n)&&(A[0]=y),(1===o||1!==d||S<a)&&(A[1]=S),A}(o,this.s3,this.itr,e,dL,n,a,s,l,u),this.itr[e]>=0&&(t=n),this.itr[e]<=0&&(i=a)}return{[dE.id]:s,[ag.TRSP1.id]:t,[ag.TRSP2.id]:i}}},COTLC:dN,COTDAG:class extends dD{constructor(e,t){super(e,2,t)}},COTFTR:class extends dD{constructor(e,t){super(e,3,t)}},IMPVOL:class extends cg{constructor(e,t){super(e,cf(t,e=>new dF(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(ag.IMPVOL,0)]}},CTM:class extends cR{constructor(e,t){e.inputs={Period1:5,Period2:21,Period3:34},super(e,cx,t)}},CPMI:class extends cR{constructor(e,t){e.inputs={Period1:3,Period2:5,Period3:8},super(e,cI,t)}},DEMA:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,this.source),s=fM(i,this.inputs.Period,i.target),r=fG(ag.DEMA,(e,t,i)=>2*t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(ag.DEMA,1)]}},TEMA:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,this.source),s=fM(i,this.inputs.Period,i.target),r=fM(s,this.inputs.Period,s.target),n=fG(ag.TEMA,(e,t,i,s)=>3*(t-i)+s,i,s,r);this.addInner(n)}getWrappers(){return[this.wrapInner(ag.TEMA,1)]}},TSI:class extends cg{constructor(e,t){super(e,t);let i=(e,t,i,s,r,n)=>{let a=fM(e,t,i,s);return fM(a,r,s,n)},s=f$(d$,eh((e,t)=>({[e.id]:Math.abs(this.baseVal(ag.Change,t))}),d$),t),r=i(t,e.inputs.Period1,ag.Change,dG,e.inputs.Period2,dz),n=i(s,e.inputs.Period1,d$,dY,e.inputs.Period2,dj),a=fG(ag.TSI,(e,t,i)=>100*t/i,r,n),o=fM(a,e.inputs.Period3,ag.TSI,ag.TSISIG);this.addInner(a,o)}getWrappers(){return[this.wrapInner(ag.TSI,1),this.wrapInner(ag.TSISIG,2)]}},ADJATR:class extends cg{constructor(e,t){super(e,t);let i=(e,t)=>{let i=0;return t>0&&(i=this.baseVal(e,t)-this.baseVal(e,t-1)),{[cG.id]:Math.abs(i)}},s=f$(cG,eh(i,this.source),t),r=fJ(e,"MA")(s,this.inputs.Period,cG,cz),n=fG(ag.ADJATR,(e,t)=>2*t,r);this.addInner(n)}getWrappers(){return[this.wrapInner(ag.ADJATR,1)]}},COTR:class extends cg{constructor(e,t){super(e,t);let i=e=>{let t=0;return e>0&&(t=this.baseVal(ag.Close,e)-this.baseVal(ag.Close,e-1)),{[cY.id]:t}},s=f$(cY,i,t),r=fQ[e.inputs.TypeOfATR.toLowerCase()],n=r(t,this.inputs.Period,this.inputs.Smoothing),a=fG(this.target,(e,t,i)=>eF(t)&&eF(i)?t/i:null,s,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCGD:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,ag.Close);this.addInner(i)}calculateAt(e){let t=null,i=e>0?this.container.getData(this.target)[e-1]:null,s=this.innVal(1,ag.EMA,e);if(eH(i)){let r=this.baseVal(this.source,e),n=Math.pow(r/i,4);t=i+(r-i)/(.6*this.period*n);let a=e=>Math.log10(Math.abs(e-t))>1,o=a(i)||a(s);(!Number.isFinite(t)||o)&&(t=null)}else t=s;return{[this.target.id]:t}}},HMA:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=Math.floor(i/2),r=this.allowEmptyValues,n=fI(t,s,this.source,ag.WMA,r),a=fG(dK,(e,t,i)=>2*t-i,n,fI(t,i,this.source,ag.WMA,r)),o=fI(a,Math.floor(Math.sqrt(i)),dK,this.target,r);this.addInner(o)}getWrappers(){return[this.wrapInner(this.target,1)]}},COPP:class extends cg{constructor(e,t){super(e,t);let i=fF(t,this.inputs.PeriodRocLong),s=fI(fG(dq,(e,t,i)=>t+i,i,fF(t,this.inputs.PeriodRocShort)),this.inputs.PeriodWma,dq,this.target);this.addInner(s)}getWrappers(){return[this.wrapInner(this.target,1)]}},REATRS:class extends cg{constructor(e,t){super(e,t);let i="Close"===e.inputs.TurtleChnField,s="Long"===e.inputs.Direction,r=f1(t);if(!i&&r){let e=f$(this.target,(e,t)=>null,t);this.addInner(e)}else{let e=(e,t)=>({[dX.id]:t>0?e*Math.abs(this.baseVal(ag.Change,t)):null}),r=f_(f$(dX,eh(e,this.inputs.FactorATR),t),this.inputs.PeriodAdjATR,dX,ag.MA),n=s?ag.High:ag.Low,a=fO(t,this.inputs.PeriodTurtleChn,i?ag.Close:n,dZ,s),o=fG(dJ,(e,t)=>this.inputs.FactorAdjATR*t,r),l=s?-1:1,u=fG(this.target,(e,t,i)=>t+l*i,a,o);this.addInner(u)}}getWrappers(){return[this.wrapInner(this.target,1)]}},LINRCHN:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=f$(ag.LINRMID,eh(function(e,t){let i=null;if(t>=this.base.size-e){let s=e*(e+1)/2,r=0,n=0,a=1;for(let t=e-1;t>=0;--t){let e=this.baseVal(ag.Close,this.base.size-1-t);r+=e,n+=a*e,a+=1}let o=(e*n-s*r)/(e*(e+1)*(2*e+1)/6*e-s*s);i=r/e-o*s/e+o*(t-this.base.size+e+1)}return{[ag.LINRMID.id]:i}},i),t),r=fW(fG(dQ,(e,t,i)=>t-i,f$(this.source,function(e){return{[this.target.id]:this.baseVal(this.target,e)}},t),s),i,dQ);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,ag.LINRMID,e),i=eC(this.innCont(2).getData(ag.MSD)),s=null,r=null;if(eF(t,i)){let e=this.inputs.Width;s=t+e*i,r=t-e*i}return{[ag.LINRUP.id]:s,[ag.LINRLOW.id]:r}}getWrappers(){return[this.wrapInner(ag.LINRMID,1)]}},CSHO:class extends cg{computeDone;constructor(e,t){super(e,t,cf(t,e=>{var t,i;let s=ez(e);return s.symbol=ty(t=e.symbol)?`${ty(i=t)?td(i).root:null}Y00`:null,eF(s.symbol)?new uZ(s):new uJ(s,!0)})),this.computedServerSide=!0,this.initialNotification=!0,this.computeDone=!1}alignCashTimelineWithUnderlying(){let e=this.innCont(0);if(!eF(e)||0===e.size)return;let t=this.innCont(1),i=e.getTimeData(),s=t.getTimeData(),r=t.getData(ag.Close),n=Array(i.length).fill(null);if(!(this.innerSeries[1]instanceof uJ)){let a=0,o=e.size,l=t.size;for(let e=0;e<o;++e){for(;a<l&&s[a].getTime()<i[e].getTime();)a++;a<l&&s[a].getTime()===i[e].getTime()&&(n[e]=r[a])}}this.container.setData(this.target,n)}calculate(e){this.computeDone||(this.container=this.makeContainer(),this.alignCashTimelineWithUnderlying(),this.computeDone=!0,this.notify(ay.TS_MANYCHANGED,-1))}},CSHB:class extends cg{constructor(e,t){super(e,t,function(e,t=ag.CSHO){return fb("CSHO",fC(t),e)}(t))}shouldTriggerOurRecalc(e){return!!super.shouldTriggerOurRecalc(e)||e===this.innerSeries[1]&&this.innHasData(0)&&this.innHasData(1)}calculateAt(e){let t=(t,i)=>eF(this.innCont(t))?this.innVal(t,i,e):null,i=t(0,ag.Close),s=t(1,ag.CSHO);return{[this.target.id]:eF(s)&&eF(i)?s-i:null}}},CTPI:class extends cW{constructor(e,t){e.inputs={Period1:5,Period2:3,Period3:3},super(e,!0,ag.CTPI,t)}},PCTCHG:class extends cg{constructor(e,t){super(e,t),fj(this)}calculateAt(e){let t=null,[i]=fK(this);if(e>0){let s=this.innVal(i,this.source,e-1);null!==s&&(t=100*(this.innVal(i,this.source,e)-s)/s)}return{[this.target.id]:t}}},OPINT:class extends cv{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(ag.TradeSize,ag.Change)}},STOMOMIX:class extends cg{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period1,ag.High,ag.HH,!0),s=fO(t,e.inputs.Period1,ag.Low,ag.LL,!1),r=fM(fG(d1,(e,t,i)=>this.baseVal(ag.Close,e)-(t+i)/2,i,s),e.inputs.Period2,d1,d2),n=fM(r,e.inputs.Period2,d2,d3),a=fM(fG(d4,(e,t,i)=>t-i,i,s),e.inputs.Period2,d4,d5),o=fM(a,e.inputs.Period2,d5,d6),l=fG(ag.STOMOMIX,(e,t,i)=>100*t/i,n,o);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},CHDMOMOSC:class extends cg{constructor(e,t){super(e,t);let i=new pe(e,t),s=fJ(e,"MA","Average")(i,this.inputs.PeriodAvg,ag.CHDMOMOSC,ag.CHDMOMOSCAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.CHDMOMOSC,1),this.wrapInner(ag.CHDMOMOSCAVG,2)]}},VSTOP:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period);this.addInner(i)}get helpers(){return[pt,pi,ps]}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=1,l=this.baseVal(ag.Close,e),u=e=>eF(e)?e:0,h=(e,t)=>this.container.getData(e)[t];e>0&&(s=Math.max(u(h(pt,e-1)),l),n=Math.min(u(h(pi,e-1)),l),o=h(ps,e-1));let c=this.inputs.Multiplier,d=this.innVal(1,ag.ATR,e);if(eF(d)){let u=1===o,p=u?s-c*d:n+c*d,f=h(u?ag.VSTOPUP:ag.VSTOPLOW,e-1);eF(f)||(f=0);let m=u?Math.max(f,p):Math.min(f,p),g=(a=+(l-m>=0))!=o;i=g?l:s,r=g?l:n,t=g?1===a?i-c*d:r+c*d:m}return{[ag.VSTOPUP.id]:1===a?t:null,[ag.VSTOPLOW.id]:1===a?null:t,[pt.id]:i,[pi.id]:r,[ps.id]:a}}},SUPTR:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period);this.addInner(i)}get helpers(){return[pr,pn,pa,ag.BARCOLIX]}calculateAt(e){let t=0,i=0,s=0,r=null,n=0,a=this.innVal(1,ag.ATR,e);if(eF(a)){let[o,l,u]=[ag.Close,ag.High,ag.Low].map(t=>this.baseVal(t,e)),h=(l+u)/2,c=this.baseVal(ag.Close,e-1),d=this.inputs.Multiplier,p=h-d*a,f=h+d*a,[m,g,y]=[pr,pn,pa].map(t=>this.container.getData(t)[e-1]);t=c>m?Math.max(p,m):p,i=c<g?Math.min(f,g):f;let S=1===(s=o>g?1:o<m?-1:eF(y)?y:1);r=S?t:i,n=+!!S}return{[pr.id]:t,[pn.id]:i,[pa.id]:s,[ag.SUPTR.id]:r,[ag.BARCOLIX.id]:n}}},ICHCLD:class extends cg{constructor(e,t){super(e,t);let i=(e,t,i)=>fG(i,(e,t,i)=>(t+i)/2,e,t),s=(e,s)=>i(fO(t,e,ag.Low,ag.LL,!1),fO(t,e,ag.High,ag.HH,!0),s),r=s(e.inputs.PeriodConversionLine,ag.CONVLN),n=s(e.inputs.PeriodBaseLine,ag.BASELN),a=i(r,n,ag.LEADSP1),o=s(e.inputs.PeriodLaggingSpan2,ag.LEADSP2);this.addInner(r,n,a,o)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=+(this.innVal(3,ag.LEADSP1,e)>this.innVal(4,ag.LEADSP2,e));return{[ag.LAGGSP.id]:this.baseVal(ag.Close,e),[ag.BARCOLIX.id]:t}}getWrappers(){return[this.wrapInner(ag.CONVLN,1),this.wrapInner(ag.BASELN,2),this.wrapInner(ag.LEADSP1,3),this.wrapInner(ag.LEADSP2,4)]}},VWAP:class extends ph{constructor(e,t){super(e,t)}get helpers(){return[po,pl,pu]}isSame(e,t){switch(this.inputs.AnchorPeriod){case"Session":default:return nS(e,t);case"Week":return nb(e,t);case"Month":return nA(e,t);case"Quarter":return nv(e,t);case"Year":return nE(e,t);case"Decade":return l0(10,e)===l0(10,t);case"Century":return l0(100,e)===l0(10,t)}}findPrevPeriodChange(e){for(let t=e;t>0;t--)if(1===this.valueAt(pu,t))return t;return 0}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=e>0,o=a?this.dateAt(e-1):tz.ZERO_DATE,l=this.dateAt(e),u=a&&this.isSame(o,l),h=u?this.valueAt(po,e-1):0,c=u?this.valueAt(pl,e-1):0,d=this.innVal(0,ag.Volume,e),p=h+this.innVal(1,this.source,e)*d,f=c+d;if(t=p/f,u){let a=this.findPrevPeriodChange(e-1),o=this.container.getData(ag.VWAP).slice(a,e);o.push(t);let l=eg(o),u=Math.sqrt(eg(o.map(e=>(e-l)*(e-l)))),h=this.inputs.Stdev1stMultiplier*u;i=t+h,s=t-h;let c=this.inputs.Stdev2ndMultiplier*u;r=t+c,n=t-c}else i=t,s=t,r=t,n=t;return{[po.id]:p,[pl.id]:f,[pu.id]:+!u,[ag.VWAP.id]:t,[ag.VWAPSD1U.id]:i,[ag.VWAPSD1L.id]:s,[ag.VWAPSD2U.id]:r,[ag.VWAPSD2L.id]:n}}},MACROSS:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,ag.MAS),r=i(t,e.inputs.Period2,this.source,ag.MAL);this.addInner(s,r)}get helpers(){return pd}calculateAt(e){let t=this.innVal(1,ag.MAS,e),i=this.innVal(2,ag.MAL,e);return pp(this.container,e,t,i)}getWrappers(){return[this.wrapInner(ag.MAS,1),this.wrapInner(ag.MAL,2)]}},PACROSS:class extends cg{_maIndex;_maTarget;constructor(e,t){super(e,t),fj(this);let i=fJ(e,"MA","Average")(t,e.inputs.Period,this.source);this.addInner(i);let[s]=fK(this);this._maIndex=s+1,this._maTarget=i.target}get helpers(){return pd}calculateAt(e){let t=this.innVal(this._maIndex,this._maTarget,e),[,i]=fK(this),s=i.getData(this.source)[e],r=pp(this.container,e,s,t);return r[this.target.id]=t,r}},VOIN:class extends cg{constructor(e,t){super(e,t);let i=f$(pf,function(e){return{[pf.id]:e>0?Math.abs(this.baseVal(ag.High,e)-this.baseVal(ag.Low,e-1)):null}},t),s=f$(pm,function(e){return{[pm.id]:e>0?Math.abs(this.baseVal(ag.Low,e)-this.baseVal(ag.High,e-1)):null}},t),r=fN(t,ag.TR);this.addInner(i,s,r)}calculateAt(e){let t=null,i=null,s=this.period;if(this.atLeast(e,s)){let r=this.past(e,s,pf,this.innCont(1)),n=this.past(e,s,pm,this.innCont(2)),a=this.past(e,s,ag.TR,this.innCont(3));if(ey(r)&&ey(n)&&ey(a)){let e=em(r),s=em(n),o=em(a);t=e/o,i=s/o}}return{[ag.PLVI.id]:t,[ag.MNVI.id]:i}}},DIFA:class extends cg{isPercent;constructor(e,t){super(e,t);let i=fJ(e,"MA","Average")(t,this.period,this.source,pS);this.isPercent="Percentage"===e.inputs.Distance,this.addInner(i)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=null,i=null,s=this.innVal(1,pS,e),r=this.baseVal(this.source,e);if(null!=s&&0!==s){t=r-s,this.isPercent&&(t=100*t/s);let n=t<=0;if(i=n?1:3,e>0){let s=this.container.getData(this.target)[e-1];null!==s&&(n&&t>s&&(i=0),!n&&t<s&&(i=2))}}return{[this.target.id]:t,[ag.BARCOLIX.id]:i}}},DOSC:class extends cg{constructor(e,t){super(e,t);let i=fM(fB(t,this.inputs.PeriodRsi,this.source,ag.RSI),this.inputs.PeriodEma1,ag.RSI,ag.EMA),s=fM(i,this.inputs.PeriodEma2,ag.EMA,ag.EMA),r=f_(s,this.inputs.PeriodMa,ag.EMA,ag.MA),n=fG(ag.DOSCH,(e,t,i)=>t-i,s,r),a=f_(n,this.inputs.PeriodSig,ag.DOSCH,ag.DOSCS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(ag.DOSCH,1),this.wrapInner(ag.DOSCS,2)]}},BBANDW:class extends c${constructor(e,t){super(e,"BandWidth",t)}},MARIB:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=this.inputs.Increment,r=Math.min(Math.max(0,this.inputs.Count),10);for(let e=0;e<r;++e){let r=f_(t,i+e*s,this.source,this.outFields[e]);this.addInner(r)}}getWrappers(){let e=this.outFields,t=this.inputs.Count;return[this.wrapInner(e[0],1),this.wrapInner(e[1],2),this.wrapInner(e[2],3),this.wrapInner(e[3],4),this.wrapInner(e[4],5),this.wrapInner(e[5],6),this.wrapInner(e[6],7),this.wrapInner(e[7],8),this.wrapInner(e[8],9),this.wrapInner(e[9],10)].slice(0,t)}},HASMO:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"EMA","Smoothing1"),s=e.inputs.Period1,r=i(t,s,ag.Open),n=i(t,s,ag.High),a=i(t,s,ag.Low),o=i(t,s,ag.Close),l=fG(pP,(e,t,i,s,r)=>(t+i+s+r)/4,r,n,a,o),u=fG(pA,function(e,t,i,s){let r=null;if(e>0){let s=this.container.getData(pA)[e-1],n=this.innVal(2,pP,e-1);eF(s,n)?r=(s+n)/2:eF(t,i)&&(r=(t+i)/2)}return r},r,o,l),h=fG(pT,(e,t,i,s)=>eF(t,i,s)?Math.max(t,Math.max(i,s)):null,n,u,l),c=fG(pv,(e,t,i,s)=>eF(t,i,s)?Math.min(t,Math.min(i,s)):null,a,u,l),d=fJ(e,"EMA","Smoothing2"),p=e.inputs.Period2,f=d(u,p,pA,ag.Open),m=d(h,p,pT,ag.High),g=d(c,p,pv,ag.Low),y=d(l,p,pP,ag.Close),S=f$(ag.Change,function(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Close,e-1);eF(i,s)?t=i-s:eF(i)&&!eF(s)&&(t=0)}return{[ag.Change.id]:t}},y);this.addInner(f,m,g,y,S)}getWrappers(){return[this.wrapInner(ag.Open,1),this.wrapInner(ag.High,2),this.wrapInner(ag.Low,3),this.wrapInner(ag.Close,4),this.wrapInner(ag.Change,5)]}},TTMSQZ:class extends cg{constructor(e,t){super(e,t);let i=e.inputs,s=fM(t,i.PeriodEmaKeltner,ag.Close),r=fV(t,i.PeriodAtrKeltner);function n(e,t,i,s){return eF(i,s)?i+e*s:null}let a=i.MultiplierKeltner,o=fG(ag.KCUP,eh(n,a),s,r),l=fG(ag.KCLOW,eh(n,-a),s,r),u=function(e,t,i,s=ag.Close){let r="BBANDS",n=fE(r);return fb(r,{source:s,inputs:{[tz.INPUT_PERIOD]:t,[tz.INPUT_WIDTH]:i},outFields:n},e)}(t,i.PeriodBollinger,i.WidthBollinger),h=function(e,t){let i="DONCHN",s=fE(i);return fb(i,{inputs:fP(t),outFields:s,source:null},e)}(t,i.PeriodMomentum),c=f_(t,i.PeriodMomentum,ag.Close),d=fU(fG(pC,function(e,t,i,s){let r=null,n=this.innVal(1,ag.DONMID,e);return eF(n,s)&&(r=t-(n+s)/2),r},t,h,c),i.PeriodMomentum,pC,ag.TTMSQZOSC);this.addInner(o,l,u,d)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=null,i=null,s=-1,r=this.innVal(1,ag.KCUP,e),n=this.innVal(2,ag.KCLOW,e),[a,o]=[ag.BOLLBU,ag.BOLLBL].map(t=>this.innVal(3,t,e));a<r&&o>n?t=0:i=0;let l=this.innVal(4,ag.TTMSQZOSC,e),u=e>0?this.innVal(4,ag.TTMSQZOSC,e-1):null;if(eF(l))if(eF(u)){let e=l>=0,t=u<l;s=e?t?3:2:+!!t}else s=2;return{[ag.TTMSQZON.id]:t,[ag.TTMSQZOFF.id]:i,[ag.BARCOLIX.id]:s}}getWrappers(){return[this.wrapInner(ag.TTMSQZOSC,4)]}},CRS:class extends cg{constructor(e,t){if(super(e,t),f2(t)){let i=Sp().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.inputs.Symbol.toUpperCase();let r=i.getTimeSeries(s),n=e=>e.query?.symbol,{model:a}=nK(`{${n(t)}} / {${n(r)}}`,!1),o=new py(a,[t,r],(e=>{let t=e.unit===G.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:B.Manual,missing:t?F.UseNext:F.UsePrevious,stretch:e=>!1,fieldMap:new Map([[ag.Close,ag.CRS]]),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation)),l=fJ(e,"MA","Average")(o,this.period,ag.CRS,ag.CRSAVG);this.addInner(r,o,l),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=f$(ag.Close,(e,t)=>null,t),i=f$(ag.CRS,(e,t)=>null,t),s=f$(ag.CRSAVG,(e,t)=>null,t);this.addInner(e,i,s),this.canLoadMoreData=!1}}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[0].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}getWrappers(){return[this.wrapInner(ag.CRS,2),this.wrapInner(ag.CRSAVG,3)]}},JPI:pN,CTTP:class extends pN{constructor(e,t){e.inputs=eK(sR("JPI").defaults.inputs.filter(e=>"HandbrakePeriod"!==e.name)),super(e,t)}},CTTI:class extends pN{constructor(e,t){e.inputs=structuredClone(pV),super(e,t)}},DRS:class extends cg{get indexSymbol(){return this.inputs[tz.INPUT_SYMBOL]}constructor(e,t){if(super(e,t),f2(t)){let i=Sp().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.indexSymbol;let r=i.getTimeSeries(s),{model:n}=nK(`{${t.query.symbol}} / {${r.query.symbol}} * 100`,!1),a=new py(n,[t,r],(e=>{let t=e.unit===G.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:B.Manual,missing:t?F.UseNext:F.UsePrevious,stretch:e=>!1,fieldMap:new Map([[ag.Close,ag.DRS]]),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation));this.addInner(r,a),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=f$(ag.Close,(e,t)=>null,t),i=f$(ag.DRS,(e,t)=>null,t);this.addInner(e,i),this.canLoadMoreData=!1}}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[0].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}getWrappers(){return[this.wrapInner(ag.DRS,2)]}},MRS:class extends cg{get indexSymbol(){return this.inputs[tz.INPUT_SYMBOL]}constructor(e,t){super(e,t);let i=function(e,t,i,s=ag.DRS){return fb("DRS",{target:s,inputs:{[tz.INPUT_SYMBOL]:t},aggregation:i,source:null},e)}(t,this.indexSymbol,e.aggregation),s=f_(i,this.period,ag.DRS);this.addInner(i,s),this.canLoadMoreData=!0,this.initialNotification=!0}calculateAt(e){let t=this.innVal(1,ag.DRS,e),i=this.innVal(2,ag.MA,e),s=null;return eF(t,i)&&0!==i&&(s=(t/i-1)*100),{[ag.MRS.id]:s}}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[0].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}},PMO:class extends cg{constructor(e,t){super(e,t);let i=fF(t,1),s=e.aggregation,r=fG(pF,(e,t)=>10*t,pB(i,this.inputs.Period1,s,ag.ROC,pH)),n=pB(r,this.inputs.Period2,s,pF,ag.PMO),a=fM(n,this.inputs.Period3,ag.PMO,ag.PMOS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(ag.PMO,1),this.wrapInner(ag.PMOS,2)]}},RVOL:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"MA")(t,this.period,ag.Volume,pk,!0);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(0,ag.Volume,e),s=this.innVal(1,pk,e);return eF(i,s)&&0!==s&&(t=i/s),{[this.target.id]:t}}},WGALPH:class extends cg{isDaily;isFeasible=!0;constructor(e,t){super(e,t),this.isFeasible=!(t instanceof uJ)&&!p$.includes($[t.query.curveStyle]),this.isDaily=e.aggregation.unit===G.Day}acceptable(e,t,i,s){return this.isDaily?0===s||!nb(this.baseVal(ag.DateTime,t),this.baseVal(ag.DateTime,i)):e>0&&i-t>=5}pluckValues(e){let t=0,i=[],s=e+5;for(let r=0;t<53&&e-r>0;r++){let n=e-r,a=this.baseVal(this.source,n);this.acceptable(a,n,s,t)&&(i.push(a),s=n,t++)}return i}calculateAt(e){let t=null;if(this.isFeasible&&e>=pW){let i=1,s=this.pluckValues(e),r=s.length;if(r>=27)for(let e=0;e<r-1;e++){let t=s[e]/s[e+1]-1;t<0?t=Math.max(t,-.2):t>=0&&(t=Math.min(t,.2)),i*=t=t*pU[e]+1}t=100*(i-1)}return{[this.target.id]:t}}},VOLAP:class extends pz{constructor(e,t){super(e,!1,t)}},AVWAP:class extends ph{constructor(e,t){super(e,t)}get helpers(){return[po,pl]}isSameOhlcBar(e,t){let{unit:i,size:s}=this.aggregation;switch(i){case G.Tick:return e===t;case G.Intraday:return an(t,lz(e,s));case G.Day:return an(t,lk(e,s));case G.Week:return nb(e,t);case G.Month:return nA(e,t);case G.Quarter:return nv(e,t);case G.Year:return nE(e,t);default:throw Error(`Unexpected aggregation unit ${G[i]}`)}}calculateAt(e){let t=null,i=null,s=null,r=this.inputs.Anchor,n=this.dateAt(e);if(an(r,n)||this.isSameOhlcBar(n,r)){let r=e>0,n=r?this.valueAt(po,e-1):0,a=r?this.valueAt(pl,e-1):0,o=this.innVal(0,ag.Volume,e);t=(i=n+this.innVal(1,this.source,e)*o)/(s=a+o)}return{[po.id]:i,[pl.id]:s,[ag.AVWAP.id]:t}}},KST:class extends cg{constructor(e,t){super(e,t);let i=this.source,s=f$(i,eh(fq,i),t),r=fF(s,this.inputs.PeriodRoc1,i),n=fF(s,this.inputs.PeriodRoc2,i),a=fF(s,this.inputs.PeriodRoc3,i),o=fF(s,this.inputs.PeriodRoc4,i),l=f_(r,this.inputs.PeriodMa1,ag.ROC,ag.MA1),u=f_(n,this.inputs.PeriodMa2,ag.ROC,ag.MA2),h=f_(a,this.inputs.PeriodMa3,ag.ROC,ag.MA3),c=f_(o,this.inputs.PeriodMa4,ag.ROC,ag.MA4),d=fG(ag.KST,(e,t,i,s,r)=>t+2*i+3*s+4*r,l,u,h,c),p=f_(d,this.inputs.PeriodSig,ag.KST,ag.KSTSIG);this.addInner(d,p)}getWrappers(){return[this.wrapInner(ag.KST,1),this.wrapInner(ag.KSTSIG,2)]}},STC:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.PeriodShort,ag.Close,pY),s=fG(pK,(e,t,i)=>t-i,i,fM(t,this.inputs.PeriodLong,ag.Close,pj)),r=this.inputs.PeriodStoch1,n=this.inputs.PeriodStoch2,a=fJ(e,"EMA"),o=a(fw(s,r,pq,!1,pK),n,pq,pX),l=a(fw(o,r,pZ,!1,pX),n,pZ,this.target);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCCLO:class extends p1{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=(e,t,i)=>t-i,r=fG(p0,"Yes"===this.inputs.RatioAdjusted?(e,t,i)=>(t-i)/(t+i)*1e3:s,t,i),n=fM(r,this.inputs.Period1,p0,pJ),a=fM(r,this.inputs.Period2,p0,pQ);return fG(this.target,s,n,a)}},NHLAI:p4,CMBCI:class extends cg{constructor(e,t){super(e,t);let i=fB(t,this.inputs.Period1Rsi,ag.Close,p5),s=f$(p6,ec(fX,this.inputs.Period1Mom,p5),i),r=f_(fB(t,this.inputs.Period2Rsi,ag.Close,p7),this.inputs.Period2Ma,p7,p8),n=fG(ag.CMBCI,(e,t,i)=>t+i,s,r),a=f_(n,this.inputs.PeriodFastMa,ag.CMBCI,ag.CMBCIF),o=f_(n,this.inputs.PeriodSlowMa,ag.CMBCI,ag.CMBCIS);this.addInner(n,a,o)}getWrappers(){return[this.wrapInner(ag.CMBCI,1),this.wrapInner(ag.CMBCIF,2),this.wrapInner(ag.CMBCIS,3)]}},COTI:class extends cg{constructor(e,t){super(e,new dN({source:ag.Close,inputs:{},outFields:fE("COTLC")},t));let i=Number.parseInt(this.inputs.History),s=fw(this.innerSeries[0],6===i?26:52*i,ag.COTI,!1,ag.COTLCCMSP);this.initialNotification=!0,this.computedServerSide=!0,this.addInner(s)}getWrappers(){return[this.wrapInner(ag.COTI,1)]}},CHEXI:class extends cg{isLong;constructor(e,t){super(e,t),this.isLong="Long"===this.inputs.Direction;let i=this.period,s=fV(t,i),r=this.inputs.Multiplier,n=fG(p9,(e,t)=>null===t?null:r*t,s),a=fO(t,i,ag.High,ag.HH,!0),o=fO(t,i,ag.Low,ag.LL,!1);this.addInner(n,a,o)}calculateAt(e){let t=null,i=null,s=this.innVal(1,p9,e);return null!==s&&(this.isLong?t=this.innVal(2,ag.HH,e)-s:i=this.innVal(3,ag.LL,e)+s),{[ag.CHEXL.id]:t,[ag.CHEXS.id]:i}}},MBBANDS:class extends c${constructor(e,t){super(e,"Modified",t)}},OPTIV:class extends fe{},IVRANK:class extends fe{},IVPCTL:class extends fe{},OPTVOLPC:class extends fe{},OPTOIPC:class extends fe{},OPTVOL:class extends fe{},OPTOI:class extends fe{},CHOP:class extends cg{constructor(e,t){super(e,t);let i=fV(t,1),s=this.inputs.Period,r=fO(t,s,ag.High,ag.HH,!0),n=fO(t,s,ag.Low,ag.LL,!1);this.addInner(i,r,n)}calculateAt(e){let t=null,i=this.period;if(e>i){let s=this.past(e,i,ag.ATR,this.innCont(1));if(ey(s)){let r=em(s),n=this.innVal(2,ag.HH,e);t=100*Math.log10(r/(n-this.innVal(3,ag.LL,e)))/Math.log10(i)}}return{[this.target.id]:t}}},MACLD:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,ag.MACLD1),r=i(t,e.inputs.Period2,this.source,ag.MACLD2);this.addInner(s,r)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=this.innVal(1,ag.MACLD1,e),i=this.innVal(2,ag.MACLD2,e);return{[ag.BARCOLIX.id]:+(t>i)}}getWrappers(){return[this.wrapInner(ag.MACLD1,1),this.wrapInner(ag.MACLD2,2)]}},BTI:class extends p1{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=fG(ft,(e,t,i)=>t/(t+i),t,i);return fJ(e,"MA","Average")(s,this.inputs.Period,ft,this.target)}},FRAMA:class extends cg{constructor(e,t){super(e,t),fj(this);let i=e.inputs.Period,s=Math.floor(i/2),r=fO(t,i,ag.High,fh,!0),n=fO(t,i,ag.Low,fc,!1),a=fO(t,s,ag.High,fd,!0),o=fO(t,s,ag.Low,fp,!1),l=fO(t,s,ag.High,ff,!0),u=fO(t,s,ag.Low,fm,!1);this.addInner(r,n,a,o,l,u)}calculateAt(e){let t=this.period,i=Math.floor(t/2),[,s]=fK(this),r=s.getData(this.source)[e];if(!this.atLeast(e,t))return{[this.target.id]:r};let n=+!!this.sourceNeedsCompute,a=this.innVal(1+n,fh,e),o=this.innVal(2+n,fc,e),l=this.innVal(3+n,fd,e),u=this.innVal(4+n,fp,e),h=this.innVal(5+n,ff,e-i),c=this.innVal(6+n,fm,e-i);if(!eF(a,o,l,u,h,c))return{[this.target.id]:r};let d=(a-o)/t,p=(l-u)/i,f=(h-c)/i,m=0;p>0&&f>0&&d>0&&(m=(Math.log(p+f)-Math.log(d))/Math.log(2));let g=Math.exp(-4.6*(m-1));g=Math.max(.01,Math.min(1,g));let y=e>0?this.container.getData(this.target)[e-1]:r,S=null!==y?g*r+(1-g)*y:r;return{[this.target.id]:S}}},FISHER:class extends cg{constructor(e,t){super(e,t);let i=e.inputs.Period,s=f$(fg,eh(c1,fg),t),r=fO(s,i,fg,ag.HH,!0),n=fO(s,i,fg,ag.LL,!1);this.addInner(s,r,n)}get helpers(){return[fy]}calculateAt(e){let t=this.innVal(1,fg,e),i=this.innVal(2,ag.HH,e),s=this.innVal(3,ag.LL,e);if(!eF(i,s,t))return{[ag.FISHER.id]:null,[ag.FISHTRG.id]:null,[fy.id]:null};let r=i-s,n=t=>this.container.getData(t)[e-1],a=.66*((0!==r?(t-s)/r:.5)-.5)+.67*((e>0?n(fy):null)??0);a>.99?a=.999:a<-.99&&(a=-.999);let o=e>0?n(ag.FISHER):null,l=.5*Math.log((1+a)/(1-a))+.5*(o??0);return{[ag.FISHER.id]:l,[ag.FISHTRG.id]:o,[fy.id]:a}}},PC:class extends cg{stdDevs;periodForecast;unitsPerYear;constructor(e,t){super(e,t),this.unitsPerYear=f0(e.aggregation),this.stdDevs=this.toInt("StandardDeviations"),this.periodForecast=this.toInt("PeriodForecast");let i=this.getHistVolPeriod();if(null!==i){let s=function(e,t,i,s=ag.Close,r=ag.HV){return fb("HV",{source:s,target:r,aggregation:i,inputs:fP(t)},e)}(t,i,e.aggregation);this.addInner(s)}}getHistVolPeriod(){return this.isCustomVolatility?null:Number.parseInt(this.volatilityParam.substring(2))}toInt(e){return Number.parseInt(this.inputs[e])}get volatilityParam(){return this.inputs.Volatility}get isCustomVolatility(){return"Custom"===this.volatilityParam}get haveVolatility(){return this.isCustomVolatility||this.innHasData(1)}getVolatilityPercent(){return(this.isCustomVolatility?this.inputs.VolatilityPercent:this.innCont(1).getLastDataPoint(ag.HV))/100}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null;if(this.haveVolatility){let o=this.base.size-this.periodForecast;if(e>=o){let l=this.base.getLastDataPoint(ag.Close),u=l*this.getVolatilityPercent()*Math.sqrt((e-o+1)/this.unitsPerYear);if(t=l+u,i=l-u,this.stdDevs>1){let e=2*u;if(s=l+e,r=l-e,this.stdDevs>2){let e=3*u;n=l+e,a=l-e}}}}return{[ag.PCUP1.id]:t,[ag.PCDN1.id]:i,[ag.PCUP2.id]:s,[ag.PCDN2.id]:r,[ag.PCUP3.id]:n,[ag.PCDN3.id]:a}}recalculateAt(e,t,i){let s={tag:e1(),src:this.innerSeries[0]};i&&this.calculate(s)}},GREEKS:class extends cg{constructor(e,t){super(e,cf(t,e=>new fi(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(ag.Delta,0),this.wrapInner(ag.Gamma,0),this.wrapInner(ag.Theta,0),this.wrapInner(ag.Vega,0)]}},PVACP:class extends pz{constructor(e,t){super(e,!0,t)}},TDI:class extends cg{constructor(e,t){super(e,t),fj(this);let i=e.inputs.PeriodRSI,s=e.inputs.PeriodTradeSignal,r=e.inputs.PeriodMarketBase,n=e.inputs.PeriodBB,[a]=fK(this),o=fB(this.innerSeries[a],i,this.source,ag.TDIPRC),l=f_(o,s,ag.TDIPRC,ag.TDITSL),u=f_(o,r,ag.TDIPRC,ag.TDIMBL),h=fW(o,n,ag.TDIPRC,ag.MSD);this.addInner(o,l,u,h)}calculateAt(e){let t=this.inputs.MultiplierBB,i=+!!this.sourceNeedsCompute,s=this.innVal(1+i,ag.TDIPRC,e),r=this.innVal(2+i,ag.TDITSL,e),n=this.innVal(3+i,ag.TDIMBL,e),a=this.innVal(4+i,ag.MSD,e),o=null,l=null;if(eF(n,a)){let e=t*a;o=n+e,l=n-e}return{[ag.TDIPRC.id]:s,[ag.TDITSL.id]:r,[ag.TDIMBL.id]:n,[ag.TDIUPR.id]:o,[ag.TDILWR.id]:l}}},PPS:class extends cg{isLong;isPercent;constructor(e,t){super(e,t);let i=e.inputs.Period,s=e.inputs.Range,r=e.inputs.Direction;this.isLong="Long"===r,this.isPercent="Percent"===e.inputs.Type;let n=ag.Close;"Close"!==s&&(n=this.isLong?ag.High:ag.Low);let a=fO(t,i,n,fu,this.isLong);this.addInner(a)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=null,i=this.innVal(1,fu,e),s=this.inputs.StopValue;if(null!==i){let e=this.isPercent?i*s/100:.1*s;t=this.isLong?i-e:i+e}let r=+!!this.isLong;return{[ag.PPS.id]:t,[ag.BARCOLIX.id]:r}}},RCI:class extends cg{constructor(e,t){super(e,t);let i=new fS({source:this.source,target:ag.RCI,inputs:{Period:e.inputs.Period}},t),s=e.inputs.PeriodSignal,r=fJ(e,"MA","Smoothing")(i,s,ag.RCI,ag.RCISIG);this.addInner(i,r)}getWrappers(){return[this.wrapInner(ag.RCI,1),this.wrapInner(ag.RCISIG,2)]}},ZIGZAG:class extends cg{state;useHighLow;isAtrMode;atrMult;percent;constructor(e,t){if(super(e,t),this.useHighLow="High/Low"===e.inputs.Method,this.isAtrMode="ATR"===e.inputs.PercentMode,this.percent=e.inputs.Percent,this.atrMult=e.inputs.MultiplierAtr,this.useHighLow||fj(this),this.isAtrMode){let t=e.inputs.PeriodAtr,[i]=this.useHighLow?[0]:fK(this),s=fV(this.innerSeries[i],t,"SMA",fA);this.addInner(s)}this.resetState()}getHigh(e){if(this.useHighLow)return this.baseVal(ag.High,e);let[,t]=fK(this);return t.getData(this.source)[e]}getLow(e){if(this.useHighLow)return this.baseVal(ag.Low,e);let[,t]=fK(this);return t.getData(this.source)[e]}getAtrDenom(e){if(this.useHighLow)return this.baseVal(ag.Close,e);let[,t]=fK(this);return t.getData(this.source)[e]}setPivot(e,t){this.state.pivotPrice=e,this.state.pivotIndex=t}setCandidate(e,t){this.state.candPrice=e,this.state.candIndex=t}getDevPct(e){if(this.isAtrMode){let t=!this.useHighLow&&this.sourceNeedsCompute?1:0,i=this.innVal(1+t,fA,e),s=this.getAtrDenom(e);return null===i||null===s||0===s?0:this.atrMult*(i/s*100)}return this.percent}pct(e,t){return 0===e?0:(t-e)/e*100}resetState(){this.state={mode:0,pivotPrice:null,pivotIndex:null,candPrice:null,candIndex:null,confirmedPivots:new Map}}calculateAt(e){let t=this.getHigh(e),i=this.getLow(e),s=this.getDevPct(e);if(null===t||null===i)return{};if(0===e){this.resetState();let i=this.useHighLow?this.baseVal(ag.Close,e):t;return this.setPivot(i,e),this.setCandidate(i,e),{}}if(0===this.state.mode)this.pct(this.state.pivotPrice,t)>=s?(this.state.mode=1,this.setCandidate(t,e)):-this.pct(this.state.pivotPrice,i)>=s&&(this.state.mode=-1,this.setCandidate(i,e));else if(1===this.state.mode){let r=t>=this.state.candPrice;r&&this.setCandidate(t,e);let n=(this.state.candPrice-i)/this.state.candPrice*100;if(!r&&n>=s){let t=this.state.candIndex,s=this.state.candPrice;this.state.confirmedPivots.set(t,s),this.setPivot(s,t),this.setCandidate(i,e),this.state.mode=-1}}else if(-1===this.state.mode){let r=i<=this.state.candPrice;r&&this.setCandidate(i,e);let n=(t-this.state.candPrice)/this.state.candPrice*100;if(!r&&n>=s){let i=this.state.candIndex,s=this.state.candPrice;this.state.confirmedPivots.set(i,s),this.setPivot(s,i),this.setCandidate(t,e),this.state.mode=1}}return{}}getCurrentState(){return this.state}}};function fP(e){return{[tz.INPUT_PERIOD]:e}}function fC(e){return{target:e,source:null,inputs:fR}}function fb(e,t,i){if(e$(fv,e))return new fv[e](t,i);let s=Sp()?.config.extensions?.studyProvider;if(s){let r=s.factory(e,t,i);if(r)return r}throw Error(`Study ${e} has not been implemented yet.`)}function fE(e){return sR(e).defaults.curves.reduce((e,t)=>e.concat(t.fields.filter(t=>!e.includes(t))),[]).map(e=>ag[e])}function fL(e,t,i,s){return{source:t,target:i,inputs:fP(e),allowEmptyValues:s}}function f_(e,t,i,s=ag.MA,r=!1){return fb("MA",fL(t,i,s,r),e)}function fM(e,t,i,s=ag.EMA,r=!1){return fb("MAEXP",fL(t,i,s,r),e)}function fx(e,t,i,s=ag.SMA,r=!1){return fb("MASMO",fL(t,i,s,r),e)}function fI(e,t,i,s=ag.WMA,r=!1){return fb("MAWEI",fL(t,i,s,r),e)}function fD(e,t,i,s=ag.HMA,r=!1){return fb("HMA",fL(t,i,s,r),e)}function fO(e,t,i,s,r,n=!1){return new cF({source:i,target:s,inputs:fP(t)},r,n,e)}function fw(e,t,i,s,r=null){return new cB({source:r,target:i,inputs:fP(t)},s,e)}let fR={};function fN(e,t=ag.TR){return fb("_TR",fC(t),e)}function fV(e,t,i="SMA",s=ag.ATR){return fb("ATR",{target:s,inputs:{[tz.INPUT_PERIOD]:t,[tz.INPUT_SMOOTHING]:i},source:null},e)}function fH(e,t=ag.TP){return fb("TP",fC(t),e)}function fF(e,t,i=ag.Close,s=ag.ROC){return fb("ROC",{source:i,target:s,inputs:fP(t)},e)}function fB(e,t,i,s=ag.RSI,r=!1){return fb("_RSI",{source:i,target:s,inputs:{...fP(t),Modified:r}},e)}function fk(e,t=ag.MFMUL){return fb("MFV",fC(t),e)}function fW(e,t,i,s=ag.MSD){return fb("MSD",{source:i,target:s,inputs:fP(t)},e)}function fU(e,t,i,s=ag.MOVLR){return fb("MOVLR",{source:i,inputs:fP(t),target:s},e)}function f$(e,t,i){return new c3(fC(e),t,i)}function fG(e,t,...i){return new c0(fC(e),t,...i)}function fz(e,t,i){return t-i}function fY(e,t,i){return(t-i)/i*100}function fj(e){let t=e.source;if(e.sourceNeedsCompute=function(e){switch(e.id){case"HL/2":case"OC/2":case"HLC/3":case"OHLC/4":case"HLCC/4":return!0;default:return!1}}(t),e.sourceNeedsCompute){let i=f$(t,eh(fq,t),e.innerSeries[0]);e.addInner(i)}}function fK(e){let t=+!!e.sourceNeedsCompute;return[t,e.innCont(t)]}let fq=function(e,t){let[i,s,r,n]=[ag.Open,ag.High,ag.Low,ag.Close].map(e=>this.baseVal(e,t)),a=null,o=e.id;switch(o){case"Open":a=i;break;case"High":a=s;break;case"Low":a=r;break;case"Close":a=n;break;case"HL/2":a=(s+r)/2;break;case"OC/2":a=(i+n)/2;break;case"HLC/3":a=(s+r+n)/3;break;case"OHLC/4":a=(i+s+r+n)/4;break;case"HLCC/4":a=(s+r+n+n)/4}return{[o]:a}},fX=function(e,t,i){let s=null;if(this.atLeast(i,e+1)){let r=this.baseVal(t,i-e);null!==r&&(s=this.baseVal(t,i)-r)}return{[this.target.id]:s}},fZ={sma:fx,ma:f_,ema:fM,wma:fI,hma:fD};function fJ(e,t,i="Smoothing"){return fZ[(e.inputs[i]??t).toLowerCase()]}let fQ={atr:fV,adjatr:function(e,t,i="MA",s=ag.Close,r=ag.ADJATR){return fb("ADJATR",{source:s,target:r,inputs:{[tz.INPUT_PERIOD]:t,[tz.INPUT_SMOOTHING]:i}},e)}};function f0(e){switch(e.unit){case G.Day:return 252;case G.Week:return 52;case G.Month:return 12;default:return 0}}function f1(e){let t=[ag.High,ag.Low];return e instanceof py&&2!==eP(e.targetFields,t).length}function f2(e){return!(e instanceof uJ)&&e.query instanceof cd}class f3 extends cy{constructor(e,t){super(e,t,fM(t,13,ag.Close),function(e,t,i,s,r=ag.Close){return fb("MACDEXP",{source:r,inputs:{Period1:12,Period2:26,Period3:9},outFields:[ag.MACD,ag.MACDS,ag.MACDH]},e)}(t,0,0,0,ag.Close)),this.query=t.query,this.useNotifications=!0}calculateAt(e){let t=W.Same,i=this.innVal(1,ag.EMA,e),s=this.innVal(1,ag.EMA,e-1),r=this.innVal(2,ag.MACDH,e),n=this.innVal(2,ag.MACDH,e-1);return eF(i,s,r,n)&&(i>s&&r>n?t=W.Up:i<s&&r<n&&(t=W.Down)),{[ag.BREL.id]:t}}getWrappers(){return this.wrapBaseFields(ag.Open,ag.High,ag.Low,ag.Close,ag.Change,ag.Volume,ag.OpenInterest,ag.TradingDay)}}function f4(e,t){return eF(t)?(this[e]=t,null):this[e]}class f5{_domain;_range;_extent;_padding;constructor(){this._domain=this._range=this._extent=null,this._padding=[0,0]}domain(e){return f4.call(this,"_domain",e)}range(e){return f4.call(this,"_range",e)}padding(e){return f4.call(this,"_padding",e)}get ready(){return eF(this._domain,this._range)}}let f6=1/Math.log2(10);function f7(e,t){let i,s,r,n,a=(i=e[0],(s=e[1]-i)>0?e=>(e-i)/s:e=>ep(isNaN(s)?NaN:.5)),o=(r=t[0],n=t[1],e=>r*(1-e)+n*e);return e=>o(a(e))}function f8(e){return Math.sign(e)*Math.log10(1+Math.abs(e/f6))}function f9(e){return Math.sign(e)*f6*(-1+Math.pow(10,Math.abs(e)))}let me=[[0,1],[1,10],[10,100],[100,1e3],[1e3,1e4],[1e4,1e5]];class mt extends f5{scaleType;axis;constructor(e,t){super(),this.scaleType=e,this.axis=t}domain(e){return this.axis&&e&&!function(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;if(e===t)return!0;for(let i=0;i<e.length;++i)if(e[i]!==t[i])return!1;return!0}(e,this._domain)&&this.axis.pane.presenter.onScaleDomainChanged(this.axis),super.domain(e)}yToPrice(e){return this.mapValue(e)}rangeWithPadding(){return[this._range[0]+this._padding[0],this._range[1]-this._padding[1]]}mapValue(e,t=!0){if(!this.ready)return null;let i=ep,s=ep;switch(this.scaleType){case X.Linear:break;case X.Logarithmic:i=f8,s=f9;break;default:throw Error("Unexpected scale type (neither linear nor log)")}let r=this._domain.map(i),n=this.rangeWithPadding(),a=t?f7(n,r):f7(r,n),o=e=>n[1]-e+n[0],l=t?o:i;return(t?s:o)(a(l(e)))}priceToY(e){return this.mapValue(e,!1)}getTicks(e){if(!this.ready)return[];let[t,i]=this._range.map(e=>this.mapValue(e,!0));if(t===i&&e>0)return[t];let[s,r]=this._domain;if(this.scaleType===X.Linear||s<0||r>1e5)return mi(t,i,e);let n=this.findLogBand(s),a=this.findLogBand(r),o=2*e;return a-n==0?mi(t,i,o):this.getLogTicks(n,a,o,i<t)}findLogBand(e){return me.findIndex(([t,i])=>e>=t&&e<i)}getLogTicks(e,t,i,s){let r=[...this._domain],n=[];try{for(let a=e;a<=t;a++){let[o,l]=me[a];a===e?o=r[0]:a===t&&(l=r[1]),this.domain([o,l]);let[u,h]=this._range.map(e=>this.mapValue(e,!0)),c=mi(u,h,i);n=s?c.concat(n):n.concat(c)}}finally{this.domain(r)}return!function(e,t){let i=e.length;for(let s=1;s<i;++s){let i=e[s],r=s-1;for(;r>=0&&t(e[r],i);)e[r+1]=e[r],r-=1;e[r+1]=i}}(n,s?(e,t)=>e>t:(e,t)=>e<t),n}checkTicks(){return this.scaleType===X.Logarithmic}}function mi(e,t,i){let s,r=-1,n,a,o;if(i*=1,(e*=1)==(t*=1)&&i>0)return[e];if((s=t<e)&&(n=e,e=t,t=n),0===(o=function(e,t,i){let s=Math.sqrt(50),r=Math.sqrt(10),n=Math.sqrt(2),a=(t-e)/Math.max(0,i),o=Math.floor(Math.log(a)/Math.LN10),l=a/Math.pow(10,o);return o>=0?(l>=s?10:l>=r?5:l>=n?2:1)*Math.pow(10,o):-Math.pow(10,-o)/(l>=s?10:l>=r?5:l>=n?2:1)}(e,t,i))||!isFinite(o))return[];if(o>0)for(e=Math.ceil(e/o),a=Array(n=Math.ceil((t=Math.floor(t/o))-e+1));++r<n;)a[r]=(e+r)*o;else for(a=Array(n=Math.ceil((e=Math.floor(e*o))-(t=Math.ceil(t*o))+1));++r<n;)a[r]=(e-r)/o;return s&&a.reverse(),a}let ms={color:tz.COLOR_TRANSPARENT},mr={color:tz.COLOR_TRANSPARENT,width:0,dashStyle:"Solid"},mn=new Set([ag.Open,ag.High,ag.Low,ag.Close].map(e=>e.id)),ma=new iw(0,0,0,0);class mo{axis;id;record;metaData;timeSeries;notifyAboutPriceDomains=!1;customPlotValues=!1;_priceMapFirstIndex;priceMapper;_firstVisibleDate=null;_lastVisibleDate=null;main=!1;curves=[];type=Z.Symbol;isShutDown=!1;targetFields=[];detachedScale;yScale=null;levels;bands;annotations;visFromIndex;visToIndex;_eventsData;precision;visible=!0;constructor(){this.axis=null,this.id=e1(),this.record=new aP(""),this.metaData=new is,this.timeSeries=new uJ,this.priceMapper=this._priceMapper.bind(this),this._priceMapFirstIndex=new Map}get title(){return""}get showPrevious(){return!1}getPreviousValue(){return null}get mainCurve(){return this.curves[0]}get hasEvents(){return!1}findEvents([e,t]){return[]}get eventsSeries(){return null}get hasEventsData(){return this.hasEvents&&eF(this.eventsSeries)&&this.eventsSeries.hasData&&this.eventsSeries.container.size>0}getEventFor(e){return null}get isSymbol(){return this.is(Z.Symbol)}get isExpression(){return this.is(Z.Expression)}get isStudy(){return this.is(Z.Study)}get isForward(){return this.is(Z.Forward)}get isSeasonal(){return this.is(Z.Seasonal)}getValueAt(e,t,i){return null}wrapIfAdvancedStyle(e){let t=e,i=e=>({outFields:e,inputs:{},source:null});return this.mainCurve.isHeikinAshiStyle?t=new cS(i(uf.slice()),e):this.mainCurve.isElderImpulseSystemStyle?t=new f3(i(uf.slice().concat(ag.BREL)),e):this.mainCurve.isPercentChangeStyle&&(t=new d0(i(uf.slice()),e)),t}is(e){return this.type===e}getCacheableEntities(e){this.metaData.getCacheableEntities(e.metaData),this.timeSeries.getCacheableEntities(e.timeSeries)}fromModel(e){this.type=Z[e.type],this.main=e.main,e.levels&&(this.levels=e.levels),e.bands&&(this.bands=e.bands),eF(e.precision)&&(this.precision=e.precision),this.curves=e.curves.map(e=>{let t=new hZ;return t.plot=this,t.fromModel(e),t}),e.detachedScale&&(this.detachedScale=e.detachedScale,this.yScale=new mt(X.Linear,null)),this.visible=e.visible??!0}initialize(){}shutdown(){eF(this.timeSeries)&&eF(this.timeSeries.shutdown)&&!this.timeSeries.isCached&&this.timeSeries.shutdown(),this.isShutDown=!0}makeQuery(){let e=this.axis.pane.presenter,t=new cd(null,e.data.aggregation,J.Normal,[eq(eG(e.data,null,"range","from")),eq(eG(e.data,null,"range","to"))]);return t.barsToFetch=e.data.maxDataPoints||tz.DEFAULT_MAX_RECORDS,t.aggregation.backAdjust&&(t.barsToFetch=4*t.barsToFetch),t.chartId=e.elementId,t.curveStyle=this.curves[0].style,t.visibleRange=eG(e.display,null,"xAxis","visibleRange"),t.extendedHours=e.data.extendedHours,t}priceToY(e){return(this.hasDetachedScale?this.yScale:this.axis.yScale).priceToY(e)}get hasDetachedScale(){return eF(this.detachedScale,this.yScale)&&this.detachedScale}getDetachedScaleMargins(){return tz.DEFAULT_DETACHED_SCALE_MARGINS}setViewBox(e){if(!this.hasDetachedScale)return;let{y:t,height:i}=e,{top:s,bottom:r}=this.getDetachedScaleMargins();this.yScale.range([Math.floor(t+s*i),Math.floor(t+i-r*i)])}drawLevels(e){e.save();let t=tz.OUT_OF_SCREEN;for(let i of this.levels.filter(e=>e.visible)){let s=this.priceToY(i.value);i7(e,i8({line:i.line,fill:ms})),iz(e,{x:-1,y:s},{x:t,y:s})}e.restore()}drawBands(e){e.save();let t=tz.OUT_OF_SCREEN;for(let i of this.bands){let s=this.priceToY(i.range.to),r=this.priceToY(i.range.from);i7(e,i8({fill:i.fill,line:mr})),i$(e,new iw(-1,s,t,r-s),!1)}e.restore()}drawAnnotations(e){e.save(),this.annotations.forEach(t=>t.draw(e,!0)),e.restore()}getEventFields(){return this.hasEvents&&this.hasEventsData?this.eventsSeries.container.fields.filter(e=>e!==ag.DateTime):[]}getEventsAt(e){let t=this.eventsSeries.container,i=i=>t.getData(i)[e];return this.getEventFields().map(t=>{let s=i(t);if(!eF(s))return null;let r=this.getEventFor(t);if(!eF(r))return null;let n={field:t,value:s,date:i(ag.DateTime),text:r.title,color:r.color};if(t!==ag.Custom||s!==tz.FAKE_CUSTOM_EVENT)return n;{let t=e%2==0;return{...n,value:t?"___news":"___video",text:t?"N":"V"}}}).filter(e=>null!=e)}getRefEventField(e,t,i){return t?e.isOhlc?ag.High:i.isTick?ag.Last:ag.Close:e.fields[0]}getRefPlot(e){return this.axis.pane.isMain?e.mainPlot:this}drawEvents(e,t){let i=this.axis.pane.presenter,s=i.view.xAxis.xScale,r=s.domain();if(!eF(r)||!eF(r[0],r[1]))return;let n=(e,t=ag.DateTime)=>e.container.getData(t),a=n(this.eventsSeries),o=this.getRefPlot(i),l=o.timeSeries,u=n(l),h=i.data.aggregation,c=o===i.mainPlot,d=n(l,this.getRefEventField(o.mainCurve,c,h)),{chart:{fontFamily:p}}=this.axis.pane.presenter.display,f=a.map((e,n)=>e.valueOf()>=r[0].valueOf()&&e.valueOf()<=r[1].valueOf()?this.getEventsAt(n).map(e=>{let r=function(e,t){let{unit:i}=e;if(i===G.Year)return ta(t);if(i===G.Quarter)return nT(t);if(i===G.Month)return tc(t);if(i===G.Week)return nC(t);if(i===G.Day)return tl(t);return t}(h,e.date),n=e_(u,+r,Number),a=d[n];t.has(n)||t.set(n,-1);let o=t.get(n);t.set(n,++o);let l=s.timeToX(r),c=i.view.getEventRadius(),p=this.axis.yScale.priceToY(a)-o*(c+c+c);return{visible:!0,...e,x:l,y:p,r:c,rect:ma}}):[]).flat();e.save();let m=!0;f.forEach(t=>{t.rect=function(e,{x:t,y:i,r:s,color:r,text:n},a){e.fillStyle=r,e.beginPath();let o=s+s,l=new iw(t-s,i-s-o,o,o);e.fillRect(l.x,l.y,l.width,l.height);let u=(1.6*s).toFixed(0);return e.font=`700 ${u}px "${a}"`,e.fillStyle="#fff",e.textAlign="center",e.textBaseline="middle",e.beginPath(),e.fillText(n,t,i-.9*o),l}(e,t,p),this.customEventPopup?.visible&&t.date===this.customEventPopup.date&&(this.showCustomEventPopup(t),m=!1)}),e.restore(),this._eventsData=f,this.customEventPopup?.visible&&m&&this.hideCustomEventPopup()}get customEventPopup(){return this.axis.pane.presenter.view.customEventPopup}hideCustomEventPopup(){this.customEventPopup?.hide()}showCustomEventPopup(e){let{x:t,y:i,r:s,date:r,value:n}=e;this.customEventPopup?.show({x:t+2*s,y:i-2*s},r,n)}getCustomEventDataAt(e){if(!this._eventsData)return null;let t=this._eventsData.find(t=>t.rect.contains(e));return t?.field===ag.Custom?t:null}hitTestCustomEvent(e){return null!==this.getCustomEventDataAt(e)}tryHandleCustomEventClick(e){let t=this.getCustomEventDataAt(e);return!!eF(t)&&(this.showCustomEventPopup(t),!0)}isEmpty(){let e=this.timeSeries;return eF(e)&&e.hasData&&e.container.isEmpty}draw(e){if(this.visible)for(let t of(eF(this.levels)&&this.drawLevels(e),eF(this.bands)&&this.drawBands(e),this.curves))t.draw(e)}drawTopmost(e,t){this.hasEventsData&&this.drawEvents(e,t)}isComparison(e){return this.axis.comparison===e}invalidatePriceMappingCache(){this._firstVisibleDate=null}_priceMapper(e,t,i,s){if(!eF(e)||!this.timeSeries.hasData||!this.shouldPriceMap(i,s))return e;let[r,n]=this.axis.pane.presenter.view.xAxis.xScale.domain()||[];if(!eF(r)||!oC(r))return e;if(this._firstVisibleDate!==r){this._firstVisibleDate=r;let e=this.timeSeries.container.getTimeData(),t=t=>e_(e,+t,Number);this.visFromIndex=t(r),this.visToIndex=t(n),this._priceMapFirstIndex.clear()}return this._priceMapFirstIndex.has(i)||this.canPriceMap(t,i),this.priceMap(e,t,i,!1,s)}isOhlcMapping(e){return this.mainCurve.isOhlc&&mn.has(e.id)}getRefPriceMapField(e){return this.isOhlcMapping(e)||e===ag.PreviousClose?ag.Close:e}dataOf(e){return this.timeSeries.container.getData(e)}canPriceMap(e,t){let i=this.getRefPriceMapField(t),s=this.dataOf(i),r=null,n=this.visFromIndex;for(;null===r&&n<=this.visToIndex;)r=s[n++];this._priceMapFirstIndex.set(i,null!==r?n-1:NaN)}priceMap(e,t,i,s=!1,r=q.None){let n=this.getRefPriceMapField(i),a=this._priceMapFirstIndex.get(n);if(!Number.isFinite(a))return e;let o=this.dataOf(n)[a];return this.isComparison(q.Percent)||r===q.Percent?s?o+o*e/100:100*Math.abs(e-o)*(e>=o?1:-1)/Math.abs(o):s?o+e:e-o}shouldPriceMap(e,t){return eF(t)?t!==q.None:this.isComparison(q.Percent)||this.isComparison(q.Value)}onPriceDomainsUpdated(){}get presenter(){return this.axis?.pane?.presenter}}class ml extends mo{_symbol;_showPrevious;yearOffset;resolved=null;events;inputs=[];_eventsSeries;compare;get symbol(){return this._symbol}get title(){return this.symbol}get showPrevious(){return this._showPrevious}getPreviousValue(){if(!eF(this.timeSeries)||!eF(this.timeSeries.record))return null;let e=this.axis.pane.presenter.display.chart.previous.field;return this.timeSeries.record.getValue(ag[e])}getTimeSeries(){let e=Sp().getTimeSeriesDataSource(),t=this.makeQuery();switch(t.symbol=this.resolved,this.mainCurve.style){case $.Renko:case $.Kagi:case $.PointAndFigure:t.barsToFetch=10100,t.inputs=this.inputs;break;case $.Range:t.barsToFetch=4e3;break;case $.LineBreak:t.inputs=this.inputs}let i=this.axis.pane;if(eF(i.alignedToYear)){let e=tx(t.symbol);null!==e&&(this.yearOffset=i.alignedToYear-e.getFullYear(),t.offset=this.yearOffset)}let s=e.getTimeSeries(t);this.timeSeries=this.wrapIfAdvancedStyle(s),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:en.Unspecified};this.presenter?.notifyHost(ay.TS_MANYCHANGED,e),this.getEvents()}})}getMetaData(){let e=Sp().getMetaDataSource();this.metaData=e.getMetaData(this.resolved),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this})})}getEvents(){if(!this.hasEvents)return;let e=Sp().getTimeSeriesDataSource(),t={symbol:this.symbol,seriesKind:J.Events,getHashKey:function(){return Object.values(this).filter(e=>"function"!=typeof e).join("|")}};tz.EVENTS.forEach(e=>{t[e]=eG(this.events,!1,e,"show")}),this._eventsSeries=e.getTimeSeries(t),this._eventsSeries.ready().then(e=>{e&&this.presenter?.notifyHost(ay.TS_EVENTSCHANGED,{series:this.eventsSeries})})}get eventsSeries(){return this._eventsSeries??null}get hasEvents(){return!!eF(this.events)&&tz.EVENTS.some(e=>eG(this.events,!1,e,"show"))}findEvents(e){if(!this.hasEventsData||null===e[0]||null===e[1])return[];let t=e[0],i=e[1];if(i>0&&this.axis?.pane?.presenter?.data?.aggregation?.isIntraday){let e=this.timeSeries.container.getTimeData()[i-1];if(this.compare(e,t))return[]}return this.eventsSeries.container.getTimeData().map((e,i)=>this.compare(e,t)?this.getEventsAt(i):[]).flat()}fromModel(e){super.fromModel(e),this._showPrevious=e.showPrevious,this.events=e.events,this.inputs=e.inputs||[],this.compare=function(e){switch(e.unit){case G.Tick:return nO;case G.Intraday:case G.Day:return nM;case G.Week:return nx;case G.Month:return nI;case G.Quarter:return nD;case G.Year:return nE;default:return nO}}(this.axis.pane.presenter.data.aggregation),this._symbol=e.symbol}getEventFor(e){let t=this.events[e.id.toLowerCase()];return eF(t)&&t.show?t:null}async initialize(){return tU.call(this,async()=>(this.resolved=await tm(this.symbol),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class mu extends ml{seriesKind;fundamental;constructor(e){super(),this.seriesKind=e}get showPrevious(){return!1}get title(){return`${this.curves[0].fields[0].name}(${G[this.fundamental].substring(0,1)})`}fromModel(e){this.fundamental=G[e.fundamental],super.fromModel(e)}makeQuery(){let e=new cd(this.symbol,new nw(this.fundamental),this.seriesKind);return e.fields=this.curves[0].fields,e}}class mh{longPressTimeout;constructor(){this.longPressTimeout=null}getTouchCrosshairDelayMillis(){let e=Sp().config.touchCrosshairDelayMillis;return eF(e)&&Number.isFinite(e)?e:tz.LONG_PRESS_DELAY_MILLIS}startLongPress(e,t,i){eO()&&(this.longPressTimeout=setTimeout(()=>this.longPressTriggered(e,t,i),this.getTouchCrosshairDelayMillis()))}longPressTriggered(e,t,i){this.cancelLongPress(),this.performLongPress(e,t,i)}cancelLongPress(){eO()&&eF(this.longPressTimeout)&&(clearTimeout(this.longPressTimeout),this.longPressTimeout=null)}performLongPress(e,t,i){}}function mc(e){return e.locked||e.axis.pane.presenter.display.allAnnotationsLocked}class md extends mh{annotation;previous;cursorSet;moved;snapToSupported;constructor(e,t,i){super(),this.annotation=e,this.previous=t,this.cursorSet=!1,this.moved=!1,this.snapToSupported=!1,this.startLongPress(null,t,i)}performLongPress(e,t,i){m2(this.annotation,i)}onMouseMove(e){if(this.cancelLongPress(),this.annotation.axis.pane.presenter.enableTooltip(!1),mc(this.annotation))return;let{point:t,view:i,offset:s}=e;if(!eH(t)||t.axis!==this.annotation.axis)return;i.drawCrosshair({ap:t,offset:s}),this.cursorSet||(this.previous.axis.pane.presenter.view.setCursor(ee.Move),this.cursorSet=!0);let r=iS(t.point,this.previous.point);this.annotation.offset(r),this.annotation.wasModifiedByTool(),this.annotation.requestRedraw(),this.previous=t,this.moved=!0}onMouseUp(e){this.cancelLongPress(),gq(this.annotation,this.moved,el.Moved)}}class mp{annotation;pointIndex;snapToSupported;moved;alignPointsMode;constructor(e,t){this.annotation=e,this.snapToSupported=!0,this.moved=!1,this.alignPointsMode=!1,this.pointIndex=e.points.indexOf(t)}onMouseMove(e){if(this.alignPointsMode=e.getModifier(ei.Shift),this.annotation.axis.pane.presenter.enableTooltip(!1),mc(this.annotation))return;let{point:t,view:i,offset:s}=e;if(i.drawCrosshair({ap:t,offset:s}),eF(t)){let e=this.annotation.points[this.pointIndex],i=iS(t.point,e.point);switch(e.moveDirection){case es.Both:e.update(t.price,t.time);break;case es.Horizontal:e.update(e.price,t.time);break;case es.Vertical:e.update(t.price,e.time)}this.moved=e.moveDirection!==es.None,this.moved&&this.annotation.wasPointMovedByTool(e,i)}this.annotation.requestRedraw()}onMouseUp(e){gq(this.annotation,this.moved,el.PointMoved)}}class mf{anchor;isVertical;axis;constructor(e,t,i){this.anchor=e,this.isVertical=t,this.axis=i}hitTest(e){return!!eF(this.anchor)&&(this.isVertical?Math.abs(e.x-this.anchor.x)<=tz.HIT_TEST_TOLERANCE:Math.abs(e.y-this.anchor.y)<=tz.HIT_TEST_TOLERANCE)}draw(e){let t=tz.OUT_OF_SCREEN;this.isVertical?iY(e,this.anchor.x,-t,t):ij(e,this.anchor.y,-t,t)}}class mm{id;axis;_price;_time;passive=!1;moveDirection=es.Both;visible=!0;point;constructor(e,t,i){this.id=e1(),this.axis=e,void 0!==t&&void 0!==i&&(this.price=t,this.time=i,this.toPoint())}get price(){return this._price}set price(e){this._price=e}get time(){return this._time}set time(e){this._time=e}get movable(){return this.moveDirection!==es.None}get presenter(){return this.pane.presenter}get pane(){return this.axis.pane}toPoint(){let e=this.axis.toPoint(this);eF(e)&&ek(e.x)&&ek(e.y)&&(this.point=e)}update(e,t){this.price=e,this.time="number"==typeof t?new Date(t):t,this.toPoint()}updateFromPoint(e){let t=this.axis.toAnnotationPoint(e);this.price=t.price,this.time=t.time,this.point=e}hitTest(e){return!!this.visible&&this.distance(e)<=tz.HIT_TEST_TOLERANCE}distance(e){let t=e.x-this.point.x,i=e.y-this.point.y;return Math.abs(Math.sqrt(t*t+i*i)-tz.HALF_ANN_POINT_DIMENSION)}draw(e,t){if(eF(this.point)){let i=tz.HALF_ANN_POINT_DIMENSION;eF(t)&&t.locked&&(i*=.6),e.beginPath(),e.ellipse(this.point.x,this.point.y,i,i,0,0,2*Math.PI),e.stroke()}}}function mg(e){return 0===iM(e.fill.color).a?e.line.color:e.fill.color}function my(e,t){return{uid:e.uid,id:e.name,traits:{...e.extractTraits(!0),...e.extractTraits(!1)},extras:{},points:e.extractPoints(),visible:e.visible,locked:e.locked,isUndoRedo:!0,toolChange:t}}function mS(e){return{uid:e.uid,id:e.name,traits:e.extractTraits(!0),extras:e.extractTraits(!1),points:e.extractPoints(),visible:e.visible,locked:e.locked,chart:e.axis.pane.presenter.accessor}}class mA{points=[];isSelected=!1;drawn=!0;axis;name;uid;alignPointsSupported=!1;visible=!0;locked=!1;computed=!1;_traits;adjustFill;constructor(e,t){this.axis=e,this.name=t,this.uid=e1()}requestRedraw(){this.axis.pane.presenter.view?.redraw()}prepareDraw(e,t){return this.drawPoints(e,t),this.readyToDraw()}readyToDraw(){return this.activePoints.every(e=>void 0!==e.point)}getPriceScaleAdornments(){return tz.EMPTY_ARRAY}getTimeScaleAdornments(){return tz.EMPTY_ARRAY}extractTraits(e=!0){let t=ez(this.traits),i=sv(this.name);return Object.keys(t).forEach(s=>{let r=i.includes(s);(e&&!r||!e&&r)&&delete t[s]}),e||["line","fill","zIndex"].forEach(e=>delete t[e]),t}extractPoints(){return this.activePoints.map(e=>({price:e.price,time:eB(+e.time,4)}))}offset(e){this.points.filter(e=>e.movable).forEach(t=>{t.updateFromPoint(iA(t.point,e))})}get traits(){return this._traits||(this._traits=ez(this.defaultTraits)),this.adjustFill&&(this._traits.fill.color=mg(this._traits),this.adjustFill=!1),this._traits}set traits(e){void 0!==e&&eY(this.traits,e,!1)}get activePoints(){return this.points.filter(e=>!e.passive)}get style(){return i8(this.traits)}get defaultTraits(){return i6(this.axis.pane.presenter.display,this.name)}get defaultStyle(){return i8(this.defaultTraits)}get adornStyle(){let e=ez(this.defaultTraits);return e.fill.color=this.traits.line.color,e.line.width=0,e.line.color=tz.COLOR_TRANSPARENT,i8(e)}get pointsStyle(){let e=ez(this.defaultTraits);return e.line.dashStyle="Solid",i8(e)}get allowPricesChangeUI(){return this.traits?.allowPricesChangeUI}wasModifiedByTool(){}wasPointMovedByTool(e,t){}isPointDrawn(e){return void 0!==e.price}drawPoints(e,t){this.points.forEach(i=>{let s=this.isPointDrawn(i),r=eF(e);t&&(s||!r)&&i.toPoint(),r&&s&&(this.isSelected||this.drawn)&&(i7(e,this.pointsStyle),i.draw(e,this))})}addPoints(e){for(let t=0;t<e;t++)this.points.push(new mm(this.axis))}toModel(){let e=this.extractPoints();return{id:this.name,uid:this.uid,visible:this.visible,locked:this.locked,points:e,traits:ez(this.traits)}}canMove(e){return!0}updatePoints(e){}updateActivePoints(e){let t=this.activePoints;t.length===e.length&&t.forEach((t,i)=>{let s=e[i];t.update(s.price,s.time)})}updateFrom(e,t,i,s,r){"boolean"==typeof s&&(this.visible=s),"boolean"==typeof r&&(this.locked=r);let n=eF(e)?ez(e):{};eF(t)&&eY(n,t,!1),this.traits=n,eF(i)&&this.updatePoints(i)}priceMap(e){return this.axis.priceMap(e)}flip(e){let t=this.getFlipAnchorIndices();if(!eH(t))return;let i=this.points[t[0]],s=this.points[t[1]];if(e){let e=s.time;s.update(s.price,i.time),i.update(i.price,e)}else{let e=s.price;s.update(i.price,s.time),i.update(e,i.time)}this.wasModifiedByTool()}getFlipAnchorIndices(){return null}}function mT(e,t,i,s){return function(r,n=!0){let a=new t(r,e,i);return n?r.appendAnnotation(a):a.drawn=!1,eF(s)&&(a.traits=s),a}}class mv{axis;angle;extent;anchor1;anchor2;p1;p2;style;extended;_data;isTrend;constructor(e,t,i,s,r){this.axis=r,eF(e,t)&&(this.angle=iT(e,t),this.extent=this.getExtent(e,t),this.anchor1=e,this.anchor2=t,this.p1=i?this.extendPoint(t,-1):e,this.p2=s?this.extendPoint(e,1):t),this.extended=i||s}extendPoint(e,t){return{x:e.x+t*this.extent*Math.cos(this.angle),y:e.y+t*this.extent*Math.sin(this.angle)}}getExtent(e,t){let i=Math.max(Math.abs(e.x),Math.abs(t.x)),s=Math.max(Math.abs(e.y),Math.abs(t.y));return Math.sqrt(i*i+s*s)+tz.OUT_OF_SCREEN}hitTest(e){return!!eF(this.p1,this.p2)&&iv([this.p1,this.p2],e,tz.HIT_TEST_TOLERANCE)}draw(e){eF(this.p1,this.p2)&&(iz(e,this.p1,this.p2),this.extended)}getAdornOffset(e){var t,i;let s=ik(e),r=iF(e,1);return t=this.p1,i=this.p2,-(t.y-i.y)/(t.x-i.x)<0&&(s.y=r+5),s}}class mP{style;axis;rect;constructor(e,t,i,s){this.axis=s,this.rect=new iw(e.x,e.y,t,i)}hitTest(e){return this.rect.contains(e)}draw(e,t){i$(e,this.rect)}}class mC extends mA{countCache;constructor(e,t){super(e,t)}draw(e,t){if(this.prepareDraw(e,t)&&!this.drawn){let t=this.getElements();i7(e,this.style),t.forEach((t,i)=>{i7(e,this.getStyleForElement(t,i)),t.draw(e)}),i7(e,this.adornStyle),this.adornElements(t,e);let i=this.getMarkers();i7(e,this.style),i.forEach(t=>{t.draw(e)})}}getBarCount(e,t){if(void 0===this.countCache||this.countCache.time1!==e||this.countCache.time2!==t){let i=this.axis.pane.presenter.view,s=Math.abs(i.toIndex(e)-i.toIndex(t));this.countCache={time1:e,time2:t,barCount:s}}return this.countCache.barCount}getElements(){return[]}get presenter(){return this.axis.pane.presenter}get formatter(){return this.presenter.mainPlot.metaData}data(e){return this.presenter.mainPlot.timeSeries.container.getData(e)}getScreenPoints(){return this.points.map(e=>e.point)}getStyleForElement(e,t){return this.style}adornElements(e,t){}hitTestAdornments(e,t){return!1}getTextRef(){return null}hitTest(e){if(!this.drawn&&this.visible){let t=this.getElements(),i=this.getMarkers();return!!(t.some(t=>t.hitTest(e))||i.some(t=>t.hitTest(e)))||this.hitTestAdornments(t,e)}return!1}updatePointsFrom(e,t=0){e.forEach((e,i)=>this.points[t+i].update(e.price,e.time))}updatePoints(e){this.allowPricesChangeUI&&this.updatePointsFrom(e)}getMarkers(){return[]}get marker(){return this.traits?.marker}get showPrices(){return this.traits?.showPrices}get singleStyle(){var e;return e=this.traits?.singleStyle,!eF(e)||e}get showBackground(){var e;return e=this.traits?.showBackground,!!eF(e)&&e}get backgroundOpacity(){var e;return eF(e=this.traits?.backgroundOpacity)?e:0}fillOnlyStyle(e){return i8({line:{color:tz.COLOR_TRANSPARENT,dashStyle:"Solid",width:0},fill:this.traits[e]})}lineOnlyStyle(e){return i8({fill:{color:tz.COLOR_TRANSPARENT},line:this.traits[e]})}makeLine(e,t){return new mv(e,t,!1,!1,this.axis)}applyBackgroundOpacity(e){return ib(iC(e),this.backgroundOpacity)}getTraitsFor(e){let t={fill:{color:tz.COLOR_TRANSPARENT},line:{...e.line}};return this.showBackground&&(t.fill.color=this.applyBackgroundOpacity(t.line.color)),t}getFlipAnchorIndices(){return 2===this.points.length?[0,1]:null}}class mb extends mC{_factors;constructor(e,t){super(e,t)}get factorsPropName(){return tz.AT_FACTORS}get factors(){return i1(this._factors??this.traits[this.factorsPropName])}getStyleForElement(e,t){return e.style??super.getStyleForElement(e,t)}get showLevels(){return this.traits[tz.AT_SHOW_LEVELS]}get levelsKind(){return this.traits[tz.AT_LEVELS_KIND]}get labels(){return this.traits[tz.AT_LABELS]}get isExtended(){return 3===this.points.length}isBefore(e,t){return this.points[e].time<this.points[t].time}comparePoints(e,t,i){let s=this.isBefore(e,t);return i||(s=!s),this.points[s?e:t].point}getPoint(e){return this.isExtended?this.comparePoints(1,2,e):this.comparePoints(0,1,e)}get leftPoint(){return this.getPoint(!0)}get rightPoint(){return this.getPoint(!1)}get pricesOnScale(){return this.traits[tz.AT_PRICES_ON_SCALE]}formatLevelPrice(e,t){let i=this.levelsKind===tz.AT_LEVELS_PERCENTS,s="";if(this.showLevels&&(s=i?`${(100*e).toFixed(1)}%`:e.toString()),this.showPrices){let e=this.priceMap(this.axis.toPrice(t));s=(s+` (${h_(this.axis,e)})`).trim()}return s}getAdornPointAndAlign(e,t){let i=this.labels,s=e instanceof mv,r=(e,t,i)=>({pt:e,align:t,offset:i});switch(i){case tz.AT_LABELS_LEFT:return r(s?e.anchor1:e,Q.Right,-t);default:case tz.AT_LABELS_RIGHT:return r(s?e.anchor2:e,Q.Left,t);case tz.AT_LABELS_CENTER:return r(s?ig(e.anchor1,e.anchor2):e,Q.Center,0)}}getColoredElements(e){let t=this.singleStyle;return this.factors.map(i=>{let s=e(i);return null===s?null:(t||(s.style=i8(this.getTraitsFor(i))),s._data={factor:i.value},s)}).filter(e=>null!==e)}hitTestAdornments(e,t){let i=this.showLevels,s=this.getTextRef();if(!i||null===s)return!1;let r=this.axis.pane.presenter,n=r.view?.mainContext;if(!n)return!1;let a=null,o=!1;n.save();let{chart:{fontFamily:l},yAxis:{fontSize:u}}=r.display;for(let i of(n.font=`${u??12}px ${l}`,e)){if(!eF(i._data))continue;let{factor:e}=i._data,{ref:r,spacing:l,offsetY:u,text:h}=s(a,i,e),{pt:c,align:d,offset:p}=this.getAdornPointAndAlign(r,l),f=this.getAdornTextPoint(n,u,c,p);if(iW(n,h,f,d).contains(t)){o=!0;break}a=i}return n.restore(),o}adornElementsForColoredFactors(e,t,i,s){let r=this.singleStyle,n=this.showBackground,a=this.showLevels,o=this.applyBackgroundOpacity(this.traits.line.color),l=s.fillStyle,u=null;e.forEach(e=>{if(!eF(e._data))return;let{factor:h}=e._data;if(n){let i=t(u,e);s.fillStyle=r?o:e.style.fillStyle,s.fill(i)}if(a){let{ref:t,spacing:n,offsetY:a,text:o}=i(u,e,h),{pt:c,align:d,offset:p}=this.getAdornPointAndAlign(t,n),f=this.getAdornTextPoint(s,a,c,p);iU(s,o,f,d,r?l:e.style.strokeStyle)}u=e})}getAdornTextPoint(e,t,i,s){let r=iF(e,.75);return iA(i,{x:s,y:!0===t?r/2:t})}}class mE extends mC{lines;constructor(e,t){super(e,t),this.resetComputedState()}get rectStyle(){return this.fillOnlyStyle(tz.AT_FILL)}get rect(){let[e,t,,]=this.getScreenPoints(),i=new mP({x:e.x,y:Math.min(e.y,t.y)},t.x-e.x,Math.abs(e.y-t.y),this.axis);return i.style=this.rectStyle,i}get reverse(){return!1}getLinesDataAtLevels(e,t){let[i,s]=this.points;if(this.reverse&&([i,s]=[s,i]),null==this.lines){let r=(e,t=!1)=>i=>({level:i.value,domain:e(i.value),traits:this.getTraitsFor(i),isPrice:t}),n=s.price-i.price,a=r(e=>i.price+e*n,!0),o=e?.map(a)??[],l=this.axis.pane.presenter.timeline,u=e_(l,+i.time,Number,hw),h=e_(l,+s.time,Number,hw)-u,c=r(e=>+l.at(u+Math.floor(e*h))),d=t?.map(c)||[];this.lines={prices:o,times:d,barsDiff:h,priceDiff:n}}return this.lines}makeColoredLine(e,t,i){let s=this.makeLine(e,t);return this.singleStyle||(s.style=i8(i.traits)),s._data={level:i.level,isPrice:i.isPrice},s}getLineElements(e){let[t,i]=this.getScreenPoints();return{priceLines:e.prices.map(e=>{let s=this.axis.toY(e.domain);return this.makeColoredLine({x:t.x,y:s},{x:i.x,y:s},e)}),timeLines:e.times.map(e=>{let s=this.presenter.view.toX(e.domain);return this.makeColoredLine({x:s,y:t.y},{x:s,y:i.y},e)})}}getStyleForElement(e,t){return e.style||super.getStyleForElement(e,t)}resetComputedState(){}wasModifiedByTool(){this.resetComputedState()}wasPointMovedByTool(e,t){this.wasModifiedByTool()}updatePoints(e){super.updatePoints(e),this.wasModifiedByTool()}}class mL extends mm{priceRef;timeRef;constructor(e,t,i){super(e),this.priceRef=t,this.timeRef=i,this.passive=!0}get price(){return this.priceRef.price}get time(){return this.timeRef.time}set price(e){this.priceRef.price=e}set time(e){this.timeRef.time=e}}class m_{points;constructor(e){this.points=e}get left(){return Math.min(this.points[0].point.x,this.points[1].point.x)}get top(){return Math.min(this.points[0].point.y,this.points[1].point.y)}get width(){return Math.abs(this.points[1].point.x-this.points[0].point.x)}get height(){return Math.abs(this.points[1].point.y-this.points[0].point.y)}getRect(){return eF(this.points[0].point,this.points[1].point)?new iw(this.left,this.top,this.width,this.height):null}}function mM(e){let t=new mm(e),i=new mm(e),s=new mL(e,t,i),r=new mL(e,i,t);return[t,i,s,r]}class mx extends mA{helper;constructor(e,t){super(e,t),this.points=mM(e),this.helper=new m_(this.points)}get left(){return this.helper.left}get top(){return this.helper.top}get width(){return this.helper.width}get height(){return this.helper.height}getRect(){return this.helper.getRect()}draw(e,t){return!!this.prepareDraw(e,t)&&(i7(e,this.style),!0)}updatePoints(e){this.allowPricesChangeUI&&2===e.length&&e.forEach((e,t)=>this.points[t].update(e.price,e.time))}}class mI{points;lines;axis;helper;_actualWidth;_fontSizeForWidth;constructor(e,t,i){this.points=e,this.lines=t,this.axis=i,this._actualWidth=0,this._fontSizeForWidth=0,this.helper=new m_(this.points)}hitTest(e){let t=this.getRect();return!!eH(t)&&(t.width=this._actualWidth,t.contains(e))}getRect(){return this.helper.getRect()}get fontSize(){if(0===this.lines.length)return 0;let{height:e}=this.getRect();return Math.floor(e/this.lines.length)}computeActualWidth(e){(this._actualWidth<=0||this._fontSizeForWidth!==this.fontSize)&&(this._actualWidth=Math.max(...this.lines.map(t=>e.measureText(t).width)),this._fontSizeForWidth=this.fontSize)}draw(e){if(0===this.lines.length)return;e.save();let{x:t,y:i}=this.getRect(),{chart:{fontFamily:s}}=this.axis.pane.presenter.display,r=this.fontSize;e.textAlign="left",e.textBaseline="top",e.font=`${r}px ${s}`,this.lines.forEach((s,n)=>{let a=r*n;e.fillText(s,t,i+a)}),this.computeActualWidth(e),e.restore()}}class mD extends mC{textEditable;_textAnnElement;constructor(e,t){super(e,t),this.textEditable=!0,this.points=mM(e),this.adjustFill=!0}get textLines(){return this.traits[tz.AT_TEXT_LINES]}set textLines(e){this.traits[tz.AT_TEXT_LINES]=e,this._textAnnElement=void 0}get textElement(){return!eF(this._textAnnElement)&&this.visible&&(this._textAnnElement=new mI(this.points,this.textLines,this.axis)),this._textAnnElement}updateFrom(e,t,i,s,r){super.updateFrom(e,t,i,s,r),this._textAnnElement=void 0}getElements(){return this.visible?[this.textElement]:[]}}class mO extends mD{constructor(e,t){super(e,t),this.textEditable=!1}canMove(e){return!!this.visible&&this.textElement.hitTest(e)}get prices(){return this.traits.prices}get pricesPoints(){let e=this.points[0].time;return this.prices.map(t=>new mm(this.axis,t,e))}updateFrom(e,t,i,s,r){super.updateFrom(e,t,i,s,r),eF(e?.textLines)&&(this.textLines=e.textLines)}getElements(){let e=super.getElements(),t=this.pricesPoints.map(e=>new mf(e.point,!1,this.axis));return e.concat(t)}getPriceScaleAdornments(){if(!this.showPrices)return super.getPriceScaleAdornments();let e=this.traits.line;return this.prices.map(t=>({price:t,color:e.color}))}get defaultFont(){let{chart:{fontSize:e,fontFamily:t}}=this.axis.pane.presenter.display;return[e??13,t]}updateOtherPoints(e){let[t,i]=this.defaultFont;e.save(),e.font=`${t}px ${i}`;let s=Math.max(...this.textLines.map(t=>e.measureText(t).width)),{x:r,y:n}=this.points[0].point;this.points[1].updateFromPoint({x:r+s,y:n+this.textLines.length*t}),e.restore()}}class mw{annId;annotation;constructor(e){this.annId=e}onKeyDown(e){if(null==this.annId)return;let{key:t,code:i,presenter:s}=e;ew(t,i)&&(eF(this.annotation)&&(this.annotation.axis.deleteAnnotation(this.annotation,!1),s.view.redraw()),gK(s,{toolChange:el.Cancelled,annId:this.annId}))}}class mR extends mw{factory;thirdPoint;dragged;snapToSupported;isDrawingAnnotation;forceAlignPoints;indices;alignPointsMode;constructor(e,t=!1){super(e.annName),this.factory=e,this.thirdPoint=t,this.dragged=!1,this.snapToSupported=!0,this.isDrawingAnnotation=!0,this.forceAlignPoints=!1,this.alignPointsMode=!1,this.indices=t?[0,1,2]:[0,1]}signalChange(){this.annotation.wasModifiedByTool(),this.annotation.requestRedraw()}onMouseDown(e){let{point:t,button:i}=e;if(void 0===t)return;let s=eH(this.annotation);if(i===et.Left)if(s){let e=!this.thirdPoint||this.dragged?1:2;this.annotation.points[e].update(t.price,t.time),this.dragged=!1,this.signalChange(),this.thirdPoint&&2!==e||this.finish()}else this.dragged=!0,t.axis.pane.presenter.clearSelection(),this.annotation=this.factory(t.axis),this.annotation.drawn=!1,this.indices.forEach(e=>this.annotation.points[e].update(t.price,t.time)),this.signalChange();return!0}onMouseMove(e){let{point:t,view:i,offset:s}=e;return i.drawCrosshair({ap:t,offset:s}),eF(this.annotation,t)&&(this.alignPointsMode=this.forceAlignPoints||e.getModifier(ei.Shift),this.dragged?(this.annotation.points[1].update(t.price,t.time),this.signalChange()):this.thirdPoint&&!this.dragged&&(this.annotation.points[2].update(t.price,t.time),this.signalChange())),!0}finish(){gq(this.annotation,!0,el.Created)}isAccidentalMouseUp(e){let{point:t}=e,i=this.annotation.points[0].point;return iy(t.point,i)<tz.HIT_TEST_TOLERANCE}onMouseUp(e){if(void 0===this.annotation)return void gZ(e);if(this.isAccidentalMouseUp(e)){this.dragged=!0;return}this.dragged=!1,this.thirdPoint||this.finish()}}class mN extends mR{constructor(e,t=!1){super(e,t),this.forceAlignPoints=!0}}class mV extends mR{constructor(e){super(e,!1),this.snapToSupported=!1}onMouseMove(e){let{point:t,view:i,offset:s}=e;if(i.drawCrosshair({ap:t,offset:s}),eF(this.annotation)&&this.dragged){let[e,i]=this.annotation.points;i.update(t.price,t.time);let s=iS(i.point,e.point),r=e.point.y+s.x*Math.sign(s.y)*Math.sign(s.x),n=this.annotation.axis.toPrice(r);i.update(n,t.time),this.signalChange()}return!0}}class mH extends mw{factory;existing;isNew;anchor;clicks;snapToSupported;isDrawingAnnotation;textArea;constructor(e,t){super(e?e.annName:null),this.factory=e,this.existing=t,this.clicks=0,this.snapToSupported=!1,this.isNew=!eF(t),this.isNew||(this.anchor=this.existing.points[0]),this.isDrawingAnnotation=this.isNew}getChartParent(){return this.anchor.axis.pane.presenter.view.canvasContainer}styleProps(){if(this.isNew)return{height:100,fontSize:"100%",color:mg(i6(this.anchor.axis.pane.presenter.display,"Text"))};{let e=this.existing.textElement;return{height:1.05*e.getRect().height,fontSize:`${Math.round(e.fontSize)}px`,color:this.existing.traits[tz.AT_FILL].color}}}onMouseDown(e){let{point:t}=e;if(this.isNew)if(0===this.clicks){if(void 0===t)return void gZ(e);t.axis.pane.presenter.clearSelection(),this.anchor=t,this.clicks++,this.startEditing()}else this.onEndEditing();else this.onEndEditing()}startEditing(){this.textArea=document.createElement("textarea");let{x:e,y:t}=this.anchor.point,i=this.anchor.axis.pane.getBounds(),s=i.x+i.width-this.anchor.point.x,{height:r,fontSize:n,color:a}=this.styleProps();tN(this.textArea,{position:"absolute",top:`${t}px`,left:`${e}px`,border:"none",outline:"none",overflow:"hidden",height:`${r}px`,width:`${s}px`,resize:"none",backgroundColor:"rgba(255, 255, 255, 0.05)",zIndex:"5",fontSize:n,color:a}),this.getChartParent().appendChild(this.textArea),this.textArea.onblur=this.onEndEditing.bind(this),this.textArea.onkeydown=e=>e.stopImmediatePropagation(),this.isNew||(this.textArea.value=this.existing.textLines.join("\n"),this.existing.textLines=[""],this.existing.requestRedraw()),setTimeout(()=>this.textArea.focus(),100)}onEndEditing(){let e=this.anchor,t=this.isNew?this.factory(e.axis):this.existing,i=this.textArea.value.split("\n");if(this.isNew){let{actualWidth:s,actualHeight:r}=this.getTextDimensions(i);t.points[0].update(e.price,e.time);let{x:n,y:a}=t.points[0].point;t.points[1].updateFromPoint({x:n+s,y:a+r}),t.drawn=!1}t.textLines=i,this.textArea.onblur=null,this.getChartParent().removeChild(this.textArea),t.requestRedraw(),this.isNew||t.requestRedraw(),gq(t,!0,this.isNew?el.Created:el.TextChanged)}getTextDimensions(e){let t=globalThis.getComputedStyle(this.textArea).getPropertyValue("font-size"),i=parseFloat(t)*e.length,s=0,r=this.anchor.axis.pane.presenter,n=r.view.mainContext;n.save();let{chart:{fontFamily:a}}=r.display;n.font=`${t} ${a}`;for(let t=0;t<e.length;t++){let i=n.measureText(e[t]).width;i>s&&(s=i)}return n.restore(),{actualWidth:s,actualHeight:i}}}function mF(e){return Sp().config.tooltipMovement===e}function mB(){return mF("Draggable")}let mk=tz.TOOLTIP_STD_LEGACY_CLASS,mW=tz.TOOLTIP_STD_CLASS,mU=tz.TOOLTIP_BUBBLE_CLASS;class m${view;tooltipElem;leftSide;mode;isDrag;canDrag;isToggling;constructor(e){this.view=e,this.isDrag=!1,this.tooltipElem=tB(e.el,"div"),tV(this.tooltipElem,{id:`${e.presenter.elementId}-global-tooltip`,class:`${mW} ${mk}`}),this.leftSide=!0,tN(this.tooltipElem,{visibility:"hidden",position:"absolute",cursor:mB()?"move":"default",zIndex:20,top:`${tz.TOOLTIP_Y_OFFSET}px`,left:`${tz.TOOLTIP_X_OFFSET}px`}),this.setMode(e.presenter.display.tooltip.mode),this.handleMouseMove=this.handleMouseMove.bind(this),this.startDrag=this.startDrag.bind(this),this.stopDrag=this.stopDrag.bind(this),this.view.el.addEventListener("mousemove",this.handleMouseMove),this.view.el.addEventListener("mouseleave",this.stopDrag),this.tooltipElem.addEventListener("mousedown",this.startDrag),this.tooltipElem.addEventListener("mouseup",this.stopDrag)}startDrag(){this.isDrag=!0}stopDrag(){this.isDrag=!1}setMode(e){if(this.mode!==e){if(this.mode=e,e===tz.TOOLTIP_BUBBLE)this.canDrag=!1,this.tooltipElem.style.transition="none",this.tooltipElem.classList.remove(mW,mk),this.tooltipElem.classList.add(mU),tN(this.tooltipElem,{pointerEvents:"none"});else if(e===tz.TOOLTIP_STD){this.canDrag=mB(),this.tooltipElem.classList.remove(mU),this.tooltipElem.classList.add(mW,mk);let e=tz.TOOLTIP_TOGGLE_SIDE_ANIM_MS;tN(this.tooltipElem,{pointerEvents:"all",top:`${tz.TOOLTIP_Y_OFFSET}px`,left:`${tz.TOOLTIP_X_OFFSET}px`,transition:mF("Auto")?`left ${e}ms ease-out`:null})}}}show(e,t){let i=this.tooltipElem;if(t){let{width:e,height:s,leftOffset:r,rightOffset:n}=this.view,a=i.getBoundingClientRect(),o=a.width/2,l=i.style,u=s*tz.TOOLTIP_BUBBLE_OFFSET,h=t.yMin-a.height-u,c=t.x-o,d=t.yMax+u,p=d+a.height,f=c,m=e-n;f<r?f=r:f+a.width>m&&(f=m-a.width),l.top=`${h<0?p<s?d:0:h}px`,l.left=`${f}px`}"hidden"===i.style.visibility&&(i.style.visibility="visible"),tW(i,e)}hide(){this.tooltipElem.style.visibility="hidden"}remove(){this.view.el.removeEventListener("mousemove",this.handleMouseMove),this.view.el.removeEventListener("mouseleave",this.stopDrag),this.tooltipElem.removeEventListener("mousedown",this.startDrag),this.tooltipElem.removeEventListener("mouseup",this.stopDrag),this.tooltipElem.remove()}reposition(e,t){tN(this.tooltipElem,{left:`${e}px`,top:`${t}px`})}isAutoMove(){return this.mode===tz.TOOLTIP_STD&&mF("Auto")}handleMouseMove(e){if(this.isDrag&&this.canDrag){let{movementX:t,movementY:i}=e,{top:s,left:r}=this.tooltipElem.style,n=parseInt(s)+i,a=parseInt(r)+t;this.reposition(a,n)}else if(this.isAutoMove()){let t=this.tooltipElem.getBoundingClientRect(),i=this.view.el.getBoundingClientRect(),s=e.pageX,r=tz.TOOLTIP_TOGGLE_DISTANCE_TOLERANCE,n=i.width>2*t.width,a=s>t.x&&s<=t.right+r,o=s<t.x&&s>=t.x-r;n&&(a||o)&&this.toggleSide()}}repositionAuto(){if(this.isAutoMove()){let e=this.view.presenter.mainPane.getBoundsWithoutScales(),t=this.tooltipElem.offsetY,i=e.x+(this.leftSide?tz.TOOLTIP_X_OFFSET:e.width-this.tooltipElem.offsetWidth-tz.TOOLTIP_X_OFFSET);this.reposition(i,t)}}toggleSide(){this.isToggling||(this.isToggling=!0,setTimeout(()=>this.isToggling=!1,tz.TOOLTIP_TOGGLE_SIDE_ANIM_MS),this.leftSide=!this.leftSide,this.repositionAuto())}}function mG(e){e.showTooltip&&mz(e,{time:tz.ZERO_DATE,offset:tz.OFFSCREEN_OFFSET,price:0,lastBarRefresh:void 0,justMain:void 0})}function mz(e,{time:t,lastBarRefresh:i,justMain:s,offset:r,price:n}){let a=hY(e,t,r,i,s,n),{mode:o,showMainPlot:l,hideSymbols:u,revealingClose:h}=e.display.tooltip,{includeTimestamp:c,showMainPlot:d,showPlotActions:p}=Sp().config.tooltipHeaders||{},f=eF(d)?d:l,m=!!eF(c)&&c,g=!!eF(u)&&u,y=!!eF(h)&&h,S=!!eF(p)&&p,A=t.valueOf()===tz.ZERO_DATE.valueOf();switch(o){case tz.TOOLTIP_CARDS:s||mj(e,a,f,!A,m&&!A,!1,g,y,S,e.hasLegend?e.view?.legend?.getLegendElem().clientHeight:0);break;case tz.TOOLTIP_BUBBLE:if(!A){let t=a.panes.find(e=>{let{top:t,left:i,width:s,height:n}=e.bounds;return new iw(i,t,s,n).contains(r)}),i=t.plots.find(e=>e.isMain)||t.plots[0],s=i.values.find(e=>["Close","Last"].includes(e.id)),n=s?s.y:i.values[0].y,o=t.plots.map(e=>e.values.filter(e=>"Change"!==e.id&&e.y>0).map(e=>e.y)).flat(),l=hF({...a,hideSymbols:g,revealingClose:y,plots:t.plots}),u=`<div class="bubble-box">${l}</div>`;e.view.tooltip.show(u,{x:r.x,y:n,yMin:Math.min(...o),yMax:Math.max(...o)})}mj(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tz.TOOLTIP_STD:if(!A){let t=hF({...a,hideSymbols:g,revealingClose:y,plots:a.panes.map(e=>e.plots).flat()});e.view.tooltip.show(t)}mj(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tz.TOOLTIP_EXTERNAL:e.notifyHost(ay.CH_TOOLTIPCHANGED,a);break;default:console.warn(`Unknown tooltip mode requested: ${o}`)}}function mY(e,t,i,s,r,n){tN(e,{position:"absolute",display:"flex","flex-direction":t,"flex-wrap":"wrap",left:`${i+tz.CARDS_X_OFFSET}px`,top:`${r+tz.CARDS_Y_OFFSET}px`,maxWidth:`${n-s-2*tz.CARDS_X_OFFSET}px`})}function mj(e,t,i=!1,s=!1,r=!1,n=!1,a=!1,o=!1,l=!1,u=0){let h=e.view.el,c=function(e,{panes:t,date:i,time:s,isMultiSymbol:r},n=!1,a=!1,o=!1,l=!1,u=!1,h=!1){return t.map((c,d)=>{let p=n?c.plots:c.plots.filter(e=>!e.isMain),f=e.mainPlot.axis.pane.id===c.id,m=o&&f?`<span class="field-name" style="padding-right:5px">${i} ${s||""}</span>`:"",g=p.map(t=>(function(e,t,i,s,r,n,a,o){let{id:l,name:u,type:h,error:c,description:d,values:p,events:f,isMain:m}=e,g=o.display.tooltip,y=c||d,S=`value-title${m?" value-main":""}`,A=Z[h],T=!(["Study","BalanceSheet","IncomeStatement"].includes(A)||"Expression"===A&&!i)||o.hasLegend&&i?"":hz(l),v=function(e,t){let i=hk(t?"eye":"eyeSlash"),s=t?"Hide":"Show",r=`${s} plot`;return`<a class="show-hide-plot" data-plot-id="${e}" data-act="${s}" title="${r}">${i}</a>`}(l,e.visible),P=a?function(e){let t=hk("moreActions");return`<a class="more-actions" data-plot-id="${e}" data-act="Menu" title="Actions">${t}</a>`}(l):"",C=hV(o)&&e.type===Z.Symbol,b=(m||C)&&(!s||e.values.length>1),E=t?p.map(e=>hG(b?e.abbreviation:"Close"===e.id&&n?d+" ":null,e.value,e.color)).join(" ")+function(e){if(e&&e.length){let t=e.map(e=>hG(`${e.field.name} (${hD(hH,e.date)})`,e.value,e.color)).join(" ");return`Event ${t}`}return""}(f):"",L=!m&&"Expression"!==A,_=p.slice(0,L?p.length:1).map(e=>`<div class="box" style="background-color:${e.color}"></div>`).join(""),M="Name"===g.mainTitle?u:d,x=r?e.visible&&t?"":`${d}`:`${M}`,I=s&&C?`${d} (${x})`:x;g.showMainTitle||(I="");let D=e.isMain?(()=>{let e=o.data?.aggregation.toShortString(),t=o.data?.aggregation.describe();return`<span class="value-main" title="${t}">&centerdot;${e}&centerdot;</span>`})():"";return`
12
+ `}function h$(e,t,i=null){return hU(e,t,i,"value-title")}function hG(e,t,i){let s="string"==typeof i?` style="color: ${i}"`:"",r=eF(e)?`<span class="field-name">${e}</span>`:"";return`${r}<span${s} class="field-value">${t}</span>`}function hz(e){return`<a class="delete-plot" data-plot-id="${e}" title="Delete plot">${hk("delete")}</a>`}function hY(e,t,i,s,r,n){let a=function(e,t){let i=e.data.aggregation,s=e.display.xAxis,r=s.isOrdinal,n=eH(r)&&r,a=n?s.ordinalName??"Value":"Date";return{date:n?hb(t):hD(i,t),time:i.isEndOfDay||n?null:hO(i,t,!1),isMultiSymbol:function(e){let t=e.mainPlot.symbol;return e.allPlots.some(e=>e.type===Z.Symbol&&e.symbol!==t)}(e),isMultiContract:i.isMultiContract,dateFieldName:a}}(e,t);return a.offset=i,a.lastBarRefresh=!!s,a.chartId=e.elementId,a.panes=e.panes.map(i=>({bounds:hj(i),id:i.id,plots:i.axes.map(e=>e.plots).flat().filter(t=>!r||t===e.mainPlot).map(i=>(function(e,t,i,{isMultiContract:s},r){let n=r.isStudy;if(!r.timeSeries.hasData)return null;let a=r.timeSeries.container;r.type,Z.Expression;let o=r.axis.comparison!==q.None,l=r.axis.comparison===q.Percent,u=(e,s)=>r.customPlotValues&&s!==ag.DateTime?[r.getValueAt(s,t,i),0]:hK(e,s,t,o),h=n?`${sV(r.model.study).meta.title} ${r.fullParams}`:r.metaData.name||"",c={isMain:r.main,type:r.type,typeName:Z[r.type],name:r.title,description:h,exchange:r.metaData.exchange||"",error:r.errorText,id:r.id,visible:r.visible};eF(r.yearOffset)&&0!=r.yearOffset&&(c.unalignedDate=hD(e.data.aggregation,function(e,t){return tt(2,arguments),tn(e,-te(t))}(t,r.yearOffset)));let d=r.curves[0];s&&r.type===Z.Symbol&&a.hasField(ag.Symbol)&&(t.valueOf()===tz.ZERO_DATE.valueOf()?c.name=r.timeSeries.container?.getLastDataPoint(ag.Symbol):c.name=u(d,ag.Symbol)[0]);let p={},f={range:r.axis.yScale.domain(),allDigits:!0};hq(r,e,f);let m=(e,t)=>{let i=(t===ag.Change||t===ag.PercentChange)&&e>0?"+":"";return l?i+hE(e):i+r.metaData.format(e,t,f)},g=hV(e),y=new Set;return c.values=r.curves.filter(e=>e.visible).map(e=>(!r.main&&r.isSymbol&&g?uf:e.fields).map(t=>{if(y.has(t))return null;y.add(t);let[i,s]=u(e,t),a=r.axis.yScale.priceToY(i);p[t.id]=!0;let o=r.customPlotValues?r.getColorOf(t):e.getColor(s,e.style!==$.HollowCandles,t),l=m(i,t).trim();if(eF(i)&&t===ag.Change){let[t]=u(e,ag.PercentChange);eF(t)&&(l+=` (${m(t,ag.PercentChange)})`)}return{abbreviation:hX(t),shortName:t.shortName,id:t.id,name:t.name,longName:`${t.shortName} ${n?r.params:""}`.trim(),color:iC(o),val:i,y:a,value:l}}).filter(e=>null!==e)).flat(),c.events=r.findEvents(u(d,ag.DateTime)).filter(e=>e.field!==ag.Custom),c})(e,t,n,a,i)).filter(e=>null!==e)})),a}function hj(e){let t=e.getBounds();if(!eF(t))return;let{x:i,y:s,width:r,height:n}=t,{leftOffset:a,rightOffset:o}=e.presenter.view;return{top:s,left:i+a,right:o,bottom:s+n,width:r,height:n}}function hK(e,t,i,s=!1){let r=e.plot,n=r.timeSeries.container,a=r.axis.pane.presenter.timeline,o=e_(a,+i,Number,hw),l=a.at(o-e.shift);if(null===l)return[null,0];let u=n.getTimeData(),h=e_(u,+l,Number);return[u[h]&&u[h].getTime()===l.getTime()?e.dataAt(t,h,!s):null,h]}function hq(e,t,i){eF(e.precision)?i.overridePrecision=e.precision:e.isStudy&&eF(t.mainPlot?.precision)&&!eF(sV(e.model.study).meta.decimals)&&(i.overridePrecision=t.mainPlot.precision)}function hX(e){return e.id===ag.Change.id?"Δ":e.id.substring(0,1)}class hZ{plot;id;fields=[];colors=[];style=$.Line;attributes=[];zones;_shift=0;lineWidth=1;lineMarker;lineSmoothing;dashStyle="Solid";varyColorPerBar=!1;visible=!0;_zoneColors;constructor(){this.id=e1(),this.plot=null}get shift(){return this._shift}set shift(e){this._shift=eF(e)?e:0}get isOhlc(){return(this.isOhlcStyle||this.isCandle||this.isHlcStyle||this.isElderImpulseSystemStyle||this.isRangeStyle)&&this.fields.includes(ag.Close)}get name(){return this.isOhlc?"":this.fields[0].name}get isHeikinAshiStyle(){return this.style===$.HeikinAshi}get isCandle(){return this.style===$.Candlestick||this.style===$.HollowCandles||this.style===$.HeikinAshi}get isHollowCandles(){return this.style===$.HollowCandles}get isElderImpulseSystemStyle(){return this.style===$.ElderImpulseSystem}get isPercentChangeStyle(){return this.style===$.PercentChange}get isOhlcStyle(){return this.style===$.OHLC}get isHlcStyle(){return this.style===$.HLC}get isRangeStyle(){return this.style===$.Range}get isRenko(){return this.style===$.Renko}get isKagi(){return this.style===$.Kagi}get isPointAndFigure(){return this.style===$.PointAndFigure}get isLineBreak(){return this.style===$.LineBreak}get isBaseline(){return this.style===$.Baseline}get isLineLike(){return[$.Line,$.Area,$.Baseline,$.PercentChange].includes(this.style)}get isColumn(){return this.style===$.Column}get isMultiColumn(){return this.style===$.MultiColumn}get isStackedColumn(){return this.style===$.StackedColumn}isFirstVisibleOfStyle(){return this.plot.curves.find(e=>e.visible&&e.style===this.style)===this}fromModel(e){e.attributes&&(this.attributes=e.attributes.map(e=>U[e])),this.colors=e.colors,this.fields=e.fields.map(e=>ag[e]),this.style=$[e.style],this.lineWidth=e.lineWidth,this.dashStyle=e.dashStyle,this.lineMarker=e.lineMarker,this.lineSmoothing=e.lineSmoothing,this.varyColorPerBar=e.varyColorPerBar,this.visible=e.visible??!0,e.zones&&(this.zones=e.zones),this.shift=e.shift}get axis(){return this.plot?.axis}get pane(){return this.axis?.pane}get timeSeries(){return this.plot?.timeSeries}get presenter(){return this.pane?.presenter}get view(){return this.presenter?.view}yToPrice(e){return this.yScale.yToPrice(e)}priceToY(e){return this.yScale.priceToY(e)}dataAt(e,t,i=!0){let s=!this.plot.isComparison(q.None),r=e===ag.PercentChange,n=e===ag.Change,a=r||(!i||s)&&n,o=this.timeSeries.container.hasField(ag.Last)?ag.Last:ag.Close,l=a?o:e,u=(e,t)=>{let i=this.timeSeries.container.getData(e)[t];return e.type!==Y.Number?i:this.plot.priceMapper(i,t,e)},h=u(l,t);if(!a)return h;if(t<=1)return 0;let c=u(l,t-1),d=h-c;return r?0===c?0:d/c:d}timeSeriesAt(e){let t=this.timeSeries.container.getTimeData(),i=t.length;return e<0||e>i-1?null:t[e]}timelineAt(e){return this.presenter.timeline.at(e)}get shiftedTimeDomain(){let e=this.view.xAxis.xScale;return eF(e.extent())?0!==this.shift?e.extent().map(t=>e.timeline.at(t-this.shift)):e.domain():null}get yScale(){return this.plot?.yScale??this.axis.yScale}getCore(){let e=this.timeSeries;if(!e.hasData||!this.visible)return null;let t=this.view.xAxis.xScale.extent();if(!eF(t))return null;let i=this.yScale.domain();return eF(i)?{ts:e,extent:t,domain:i,range:this.yScale.range()}:null}drawHover(e,t,i){if(!this.isLineLike||null===this.getCore())return;let[s,r]=hK(this,this.pickMainField(),t);if(eF(s))e.save(),iO(e,this.plot.axis.pane.getBoundsWithoutScales()),e.fillStyle=iC(this.getColor(r)),e.beginPath(),ci(e,i,this.priceToY(s),this.lineMarker??"Circle",1.3333),e.fill(),e.restore()}draw(e){let t=this.getCore();if(null===t)return;let{ts:i,extent:s,domain:r,range:n}=t;e.save(),e.setLineDash([]);let a=i.container.getTimeData(),o=this.shiftedTimeDomain[0],l={bar:this.view.xAxis.xScale.bar,domain:r,range:n,slice:s,start:e_(a,+o,Number)||0},u=eF(this.zones);this.isOhlc?ce.call(this,e,l):this.isRenko||this.isLineBreak?h4.call(this,e,l):this.style===$.Ribbon?this.varyColorPerBar?ch.call(this,e,l):cu.call(this,e,l,this.colors[0]):this.style===$.Area?u?h1.call(this,e,l,hQ,!0):hQ.call(this,e,l,this.colors,!0):this.isColumn||this.isMultiColumn?u?h1.call(this,e,l,h6,!0):h6.call(this,e,{...l,range:[null,null]}):this.isStackedColumn?h5.call(this,e,l):this.isBaseline?h3.call(this,e,l):this.style===$.Step?u?h1.call(this,e,l,h8):h8.call(this,e,l,this.colors[0]):this.isKagi?co.call(this,e,l):this.isPointAndFigure?cl.call(this,e,l):this.style===$.Dots?h7.call(this,e,l):this.style===$.Line||this.isPercentChangeStyle?u?h1.call(this,e,l,cs):this.varyColorPerBar?cn.call(this,e,l):cs.call(this,e,l):So(`Drawing of the curve style '${this.style}' is not implemented yet`,"error"),e.restore()}pickMainField(){return 1===this.fields.length?this.fields[0]:this.fields.includes(ag.Last)?ag.Last:this.fields.includes(ag.Close)?ag.Close:this.fields[0]}get zoneColors(){if(!eF(this._zoneColors)){let e=this.colors.slice();this._zoneColors=this.zones.map(t=>e.splice(0,t.colors))}return this._zoneColors}getColorsFromZone(e){let t=this.zones.findIndex(t=>e<t.value);return -1===t&&(t=this.zones.length-1),this.zoneColors[t]}pickAreaStroke(e){return e.length<2?iC(e[0]):e[1]}getComputedColor(e){if(!this.timeSeries.container.hasField(ag.BARCOLIX))return null;let t=this.dataAt(ag.BARCOLIX,e);return t>=0&&t<this.colors.length?this.colors[t]:null}getColor(e,t=!0,i=null){if(this.varyColorPerBar){let i,s={};if(this.isOhlc||this.isRenko||this.isLineBreak){let t=this.dataAt(ag.Open,e),i=this.dataAt(ag.High,e),r=this.dataAt(ag.Low,e),n=this.dataAt(ag.Close,e),a=this.dataAt(ag.Change,e);s.open=t,s.high=i,s.low=r,s.close=n,s.change=a}else if(this.plot.isStudy&&!["VOL","MAVOL"].includes(this.plot.model.study)){let t=this.pickMainField(),i=this.dataAt(t,e-1),r=this.dataAt(t,e),n=eF(i),a=eF(r);n?s.change=a?r-i:-1:s.change=+!!a}else{let t=this.plot.axis.pane.presenter.data.aggregation;t.isTick&&t.spec===z.None||(s.open=this.dataAt(ag.Open,e),s.close=this.dataAt(ag.Close,e)),s.change=this.dataAt(ag.Change,e)}let r=function(e,{open:t,close:i,change:s},r){let n=r.length>2&&e!==$.HLC,a=eF(t,i),o=a&&i>t,l=a&&i===t,u=s>0,h=0===s;return{useSame:n,isUp:o,isSame:l,isUpPrev:u,isSamePrev:h,isDown:!o&&!l,isDownPrev:!u&&!h}}(this.style,s,this.colors),n=this.getComputedColor(e);switch(this.style){case $.Candlestick:case $.Renko:case $.LineBreak:case $.Range:case $.HeikinAshi:case $.OHLC:case $.HLC:case $.Column:{if(eF(n)){i=n;break}let t=r.useSame?r.isUp:r.isUp||r.isSame,s=r.isSame,a=this.attributes||[],o=this.plot.isStudy&&!["HASMO","VOL","MAVOL"].includes(this.plot.model.study);(a.includes(U.ChangeBased)||o)&&(t=r.useSame?r.isUpPrev:r.isUpPrev||r.isSamePrev,s=r.isSamePrev),i=this.colors[+!!t],r.useSame&&s&&(i=this.colors[2]),(this.isRenko||this.isLineBreak||this.isRangeStyle)&&1===this.dataAt(ag.Projection,e)&&(i=iL(.5,!0)(i));break}case $.ElderImpulseSystem:i=this.colors[this.dataAt(ag.BREL,e)];break;case $.HollowCandles:{let e=this.colors[r.isUpPrev||r.isSamePrev?1:0];i=t&&(r.isUp||r.isSame)?tz.COLOR_TRANSPARENT:e;break}case $.Line:case $.PercentChange:case $.Ribbon:case $.Kagi:if(eF(n)){i=n;break}i=this.colors[0];break;case $.PointAndFigure:{let t=+!!uj(this.dataAt(ag.BARKIND,e));i=this.colors[t];break}default:throw Error(`Unexpected style ${$[this.style]} for a curve with varying colors`)}return eF(i)||(i=this.colors[0]),i}if(this.zones){let t=this.pickMainField(),i=this.dataAt(t,e),s=this.getColorsFromZone(i);return this.style===$.Area?this.pickAreaStroke(s):s.length>0?s[0]:this.colors[0]}if((this.isMultiColumn||this.isStackedColumn)&&eF(i)){var s;return this.colors[s=this.colors,Math.min(Math.max(this.fields.findIndex(e=>e===i),0),s.length-1)]}return this.colors[0]}}function hJ([e,t],i,s){let r=i,n=this.timeSeries.container.size;for(let i=e;i<=t;i++){for(;this.timeSeriesAt(r)<this.timelineAt(i-this.shift)&&r<n;)++r;if(r===n)break;let e=this.timeSeriesAt(r)>this.timelineAt(i-this.shift);s.call(this,r,e)}}function hQ(e,t,i,s=!1){cs.call(this,e,t,this.pickAreaStroke(i)),cc.call(this,e,t,i[0],s)}function h0(e,t){let i,s,r=eF(e),n=eF(t),a=this.pane.getBounds();if(r)if(n){let r=this.priceToY(e),n=this.priceToY(t);i=(r+n)/2,s=new iw(a.x,n,a.width,r-n)}else i=this.priceToY(e),s=new iw(a.x,a.y,a.width,i-a.y);else i=this.priceToY(t),s=new iw(a.x,i,a.width,a.y+a.height-i);return[i,s]}function h1(e,t,i,s=!1,r){let n;this.zones.forEach((a,o)=>{let l=a.value,[u,h]=h0.call(this,n,l);e.save(),iO(e,h),s&&(t.range=[null,u]);let c=this.zoneColors[o];if(a.gradient){let t=((e,t)=>{let i=iL(.6)(e),s=i_(.6)(e),r="linLighten"===t;return[r?s:i,e,r?i:s]})(c,a.gradient),i=e.createLinearGradient(0,h.y,0,h.y+h.height);i.addColorStop(0,t[0]),i.addColorStop(.5,t[1]),i.addColorStop(1,t[2]),c=i}else eF(r)&&(c=r(o,c));i.call(this,e,t,c),e.restore(),n=l})}function h2(e,t){let{x:i,width:s}=this.pane.getBoundsWithoutScales();e.save(),e.lineWidth=1,e.strokeStyle="#888",e.setLineDash(iP("dot")),ij(e,t,i,i+s),e.restore()}function h3(e,t){let[i,s]=t.range,{baseLevel:r}=function(e){let{BaseLevel:t}=eK(e);return{baseLevel:Number.isFinite(t)?e2(0,100,t):50}}(this.plot.inputs),n=(i-s)*r/100+s;this.zones[0].value=this.yToPrice(n),h2.call(this,e,n),h1.call(this,e,t,hQ,!0,(t,r)=>{let a=ib(r,0),o=e.createLinearGradient(0,1===t?i:s,0,n);return o.addColorStop(0,r),o.addColorStop(1,a),[o,ib(r,1)]})}function h4(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2;hJ.call(this,i,s,(i,s)=>{if(!s){let[s,n]=[ag.Open,ag.Close].map(e=>this.dataAt(e,i)).map(this.priceToY,this),a=Math.floor(t.totalWidth/2);e.fillStyle=this.getColor(i),e.beginPath(),e.rect(r-a,s,t.totalWidth,n-s),e.fill()}r+=t.totalWidth})}function h5(e,{bar:t,slice:i,start:s}){if(!this.isFirstVisibleOfStyle())return!1;let r=this.view.xAxis.xScale.range()[0]+t.offset,n=iZ();n.prolog(e);let a=this.plot.curves.filter(e=>e.isStackedColumn);hJ.call(this,i,s,(i,s)=>{if(!s){let s=this.priceToY(0),o=0;a.forEach(a=>{if(!a.visible)return;let l=a.fields[0];if(eF(o+=this.dataAt(l,i))){let u=this.priceToY(o);e.fillStyle=a.getColor(i,!1,l),e.beginPath(),e.rect(n.adjust(r),n.adjust(u),n.adjust(t.width),n.adjust(s-u)),e.fill(),s=u}})}r+=t.totalWidth}),n.epilog(e)}function h6(e,{bar:t,slice:i,start:s,range:[r,n]}){let a=this.view.xAxis.xScale.range()[0]+t.offset,o=this.isMultiColumn,l=o?this.fields:[this.pickMainField()],u=t.width/(o?l.length:1),h=iZ();h.prolog(e),hJ.call(this,i,s,(i,s)=>{s||l.forEach((t,s)=>{let r=this.dataAt(t,i);if(eF(r)){eF(n)||(n=this.priceToY(0));let o=this.priceToY(r);e.fillStyle=this.getColor(i,!1,t),e.beginPath(),e.rect(h.adjust(a+s*u),h.adjust(o),h.adjust(u),h.adjust(n-o)),e.fill()}}),a+=t.totalWidth}),h.epilog(e)}function h7(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2;e.fillStyle=this.getColor(0);let n=Math.max(1,this.lineWidth||tz.CURVE_STYLE_DOTS_RADIUS),a=2*Math.PI;e.beginPath(),hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eF(s)){let t=this.priceToY(s);e.moveTo(r+n,t),e.arc(r,t,n,0,a)}}r+=t.totalWidth}),e.fill()}function h8(e,{bar:t,slice:i,start:s},r){let n=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,a=iZ();a.prolog(e),e.strokeStyle=r,e.lineWidth=this.lineWidth,this.dashStyle&&e.setLineDash(iP(this.dashStyle)),e.beginPath();let o=!1,l=null;hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eF(s)){let r=this.priceToY(s);if(o)e.lineTo(n,l),e.lineTo(n,r);else{let s=this.dataAt(t,i-1);if(eF(s)){let t=this.priceToY(s);e.moveTo(-1,t),e.lineTo(n,t),e.lineTo(n,r)}else e.moveTo(n,r);o=!0}l=r}}n+=t.totalWidth}),e.stroke(),a.epilog(e)}let h9=[ag.Open,ag.High,ag.Low,ag.Close];function ce(e,{bar:t,slice:i,start:s}){let r=this.presenter.display.chart.showMinMaxArc,n=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,a=iZ();a.prolog(e);let o=null,l=null,u=null,h=null,c=t=>{this.isCandle?(this.isHollowCandles?t.outlineColor=this.getColor(t.ix,!1):(this.colors.length>3&&(t.outlineColor=this.colors[3]),this.colors.length>4&&(t.wickColor=this.colors[4])),function(e,{x:t,adjust:i,width:s,y:[r,n,a,o],color:l,outlineColor:u,wickColor:h,isMin:c,isMax:d},p){let f=s/2;e.lineWidth=p,e.fillStyle=l,e.strokeStyle=u||l,e.beginPath(),e.rect(i(t-f),r,s,i(o-r)),e.fill(),e.stroke(),e.strokeStyle=h||u||l,e.beginPath(),e.moveTo(t,Math.min(o,r)),e.lineTo(t,n),e.moveTo(t,Math.max(o,r)),e.lineTo(t,a),e.stroke(),e.strokeStyle=0===iM(l).a?u:l,ct(e,c,d,t,a,n,f)}(e,t,this.lineWidth)):(this.isOhlcStyle||this.isHlcStyle||this.isElderImpulseSystemStyle||this.isRangeStyle)&&function(e,{x:t,adjust:i,width:s,y:[r,n,a,o],color:l,isMin:u,isMax:h},c,d){let p=s/2;e.lineWidth=c,e.strokeStyle=l,e.beginPath(),e.moveTo(t,a),e.lineTo(t,n),d&&(e.moveTo(i(t-p),r),e.lineTo(t,r)),e.moveTo(i(t+p),o),e.lineTo(t,o),e.stroke(),ct(e,u,h,t,a,n,p)}(e,t,this.lineWidth,!this.isHlcStyle)};hJ.call(this,i,s,(e,i)=>{if(!i){let i=h9.map(t=>this.dataAt(t,e)),[s,r,d,p]=i;if(eF(s,r,d,p)){let f={x:a.adjust(n),adjust:a.adjust,width:t.width,y:[s,r,d,p].map(this.priceToY,this).map(a.adjust),isMin:!1,isMax:!1,ix:e,color:this.getColor(e)},m=Math.min(...i),g=Math.max(...i);(!eF(o)||m<o)&&(o=m,u=f),(!eF(l)||g>l)&&(l=g,h=f),c(f)}}n+=t.totalWidth}),r&&(eF(u)&&(u.isMin=!0,c(u)),eF(h)&&(h.isMax=!0,c(h))),a.epilog(e)}function ct(e,t,i,s,r,n,a,o=3){t&&iG(e,{x:s,y:r+o},a,0,Math.PI),i&&iG(e,{x:s,y:n-o},a,0,Math.PI,!0)}function ci(e,t,i,s,r=1){let n=tz.MARKER_SIZE*r,a=1.25*n;switch(s){case"Circle":e.moveTo(t+n,i),e.arc(t,i,n,0,2*Math.PI);break;case"Square":e.rect(t-n,i-n,2*n,2*n);break;case"TriangleUp":e.moveTo(t-a,i+a),e.lineTo(t+a,i+a),e.lineTo(t,i-a),e.lineTo(t-a,i+a);break;case"TriangleDown":e.moveTo(t-a,i-a),e.lineTo(t+a,i-a),e.lineTo(t,i+a),e.lineTo(t-a,i-a);break;case"Diamond":e.moveTo(t,i-a),e.lineTo(t+a,i),e.lineTo(t,i+a),e.lineTo(t-a,i),e.lineTo(t,i-a)}}function cs(e,{bar:t,slice:i,start:s},r=null){let n=r||this.getColor(0),a=eH(this.lineMarker);a&&(e.fillStyle=n,e.beginPath());let o=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,l=[],u=this.pickMainField();hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eF(t)){let i=this.priceToY(t);a&&ci(e,o,i,this.lineMarker),l.push({x:o,y:i})}}o+=t.totalWidth}),a&&e.fill(),e.lineWidth=this.lineWidth,this.dashStyle&&e.setLineDash(iP(this.dashStyle)),eH(this.lineSmoothing)?function(e,t,i,s){if(t.length<2)return;let r=function(e,t){let i=[];for(let s=0;s<e.length-1;s++){let r=e[s-1]||e[s],n=e[s],a=e[s+1],o=e[s+2]||a,l=n.x+(a.x-r.x)/t,u=n.y+(a.y-r.y)/t,h=a.x-(o.x-n.x)/t,c=a.y-(o.y-n.y)/t;i.push({cp1x:l,cp1y:u,cp2x:h,cp2y:c,x:a.x,y:a.y})}return i}(t,s);for(let s of(e.beginPath(),e.strokeStyle=i,e.moveTo(t[0].x,t[0].y),r))e.bezierCurveTo(s.cp1x,s.cp1y,s.cp2x,s.cp2y,s.x,s.y);e.stroke()}(e,l,n,this.lineSmoothing):cr(e,l,n)}function cr(e,t,i){if(t.length>1){e.beginPath(),e.strokeStyle=i;let s=t[0];e.moveTo(s.x,s.y);for(let i=1;i<t.length;i++){let s=t[i];e.lineTo(s.x,s.y)}e.stroke()}}function cn(e,{bar:t,slice:i,start:s}){e.lineWidth=this.lineWidth,e.lineCap="square",this.dashStyle&&e.setLineDash(iP(this.dashStyle));let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,n=null,a=null,o=[];hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eF(s)){let t=this.priceToY(s);a=this.getColor(i),n!==a&&(cr(e,o,n),o.length>0&&(o=[o.pop()]),n=a),o.push({x:r,y:t})}}r+=t.totalWidth}),cr(e,o,a)}let ca=[null,null,null,null];function co(e,{bar:t,slice:i,start:s}){e.lineWidth=Math.max(1,.5*t.width),e.lineJoin="miter",e.miterLimit=1.5;let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,n=iZ();n.prolog(e);let a=null,o=null,l=[];hJ.call(this,i,s,(i,s)=>{if(!s){let s=e=>h9.map(t=>this.dataAt(t,e)),[u,h,c,d]=s(i),[,p,f]=i<0?ca:s(i-1);if(eF(u,h,c,d)){let s=n.adjust(r),m=n.adjust(r-t.totalWidth),g=[u,h,c,d].map(this.priceToY,this).map(n.adjust),y=n.adjust(this.priceToY(h>p?p:f));o=this.getColor(i);let S=eF(a)&&a!==o,A=u===h?1:2,T=u===h?2:1;l.push({x:m,y:g[0]}),l.push({x:s,y:g[A]}),S&&(l.push({x:s,y:y}),cr(e,l,a),l=[]),S&&l.push({x:s,y:y}),l.push({x:s,y:g[T]}),a=o}}r+=t.totalWidth}),cr(e,l,o),n.epilog(e)}function cl(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0],n=t.totalWidth/2,a=r+t.offset+t.width/2,o=iZ();o.prolog(e);let l=this.plot.timeSeries.builder.boxSize,u=l/2;hJ.call(this,i,s,(i,s)=>{if(!s){let[t,s]=[ag.High,ag.Low].map(e=>this.dataAt(e,i)),r=this.colors[0],h=this.colors[1],c=this.dataAt(ag.BARKIND,i),d=uj(c),p=c===tz.BARKIND_XO,f=c===tz.BARKIND_OX;if(eF(t,s))for(let i=t;i>=s;i-=l){let l=o.adjust(a),[c,m]=[l-n,l+n],[g,y,S]=[i,i-u,i+u].map(e=>this.priceToY(e)),A=i===t&&p||i===s&&f?!d:d;e.beginPath(),A?(e.strokeStyle=h,e.moveTo(c,y),e.lineTo(m,S),e.moveTo(c,S),e.lineTo(m,y)):(e.strokeStyle=r,e.ellipse(l,g,n,y-g,0,0,2*Math.PI)),e.stroke()}}a+=t.totalWidth}),o.epilog(e)}function cu(e,{bar:t,slice:i,start:s},r){e.fillStyle=r;let[n,a]=this.fields,o=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,l=[];if(hJ.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(n,e),i=this.dataAt(a,e);eF(t,i)&&l.push({x:o,upY:this.priceToY(t),downY:this.priceToY(i)})}o+=t.totalWidth}),l.length>0){e.beginPath(),e.moveTo(l[0].x,l[0].upY);for(let t=1;t<l.length;++t)e.lineTo(l[t].x,l[t].upY);let t=l.length-1;e.lineTo(l[t].x,l[t].downY);for(let i=t-1;i>=0;--i)e.lineTo(l[i].x,l[i].downY);e.closePath(),e.fill()}}function ch(e,{bar:t,slice:i,start:s}){let[r,n]=this.fields,a=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,o=[],l=t=>{if(o.length>1){e.beginPath(),e.fillStyle=t,e.moveTo(o[0].x,o[0].upY);for(let t=1;t<o.length;++t)e.lineTo(o[t].x,o[t].upY);let i=o.length-1;e.lineTo(o[i].x,o[i].downY);for(let t=i-1;t>=0;--t)e.lineTo(o[t].x,o[t].downY);e.closePath(),e.fill()}},u=null,h=null;hJ.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(r,e),i=this.dataAt(n,e);if(eF(t,i)){let s=this.priceToY(t),r=this.priceToY(i);h=this.getColor(e),u!==h&&(l(u),o.length>0&&(o=[o.pop()]),u=h),o.push({x:a,upY:s,downY:r})}}a+=t.totalWidth}),l(h)}function cc(e,{bar:t,slice:i,start:s,range:[r,n]},a,o){if(o){let t=e.createLinearGradient(0,r,0,n);t.addColorStop(0,a),t.addColorStop(1,ib(a,0)),e.fillStyle=t}else e.fillStyle=a;e.beginPath();let l=null,u=this.pickMainField(),h=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,c=!1,d=null;hJ.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eF(t)){let i=this.priceToY(t);c?e.lineTo(h,i):(e.moveTo(l=h,i),c=!0),d=h}}h+=t.totalWidth}),e.lineTo(d,n),e.lineTo(l,n),e.closePath(),e.fill()}class cd{symbol;aggregation;range;seriesKind;cacheMe;barsToFetch;offset;chartId;curveStyle;extendedHours;fields=[];alwaysUseBarsToFetch;inputs=[];splits;padded;constructor(e,t,i=J.Normal,s=[null,null]){this.symbol=e,this.aggregation=t,this.range=s,this.seriesKind=i,this.cacheMe=!1,this.barsToFetch=0,this.offset=0,this.chartId=null,this.curveStyle=null,this.alwaysUseBarsToFetch=!1,this.splits=!0,this.padded=!1}getBuilderKey(){if(!eF(this.curveStyle)||!tz.SPECIAL_BUILDER_REQUIRED.includes(this.curveStyle))return"Standard";switch(this.curveStyle){case $.Renko:{let{method:e,period:t,source:i,brickSize:s}=ui(this.inputs),r="ATR"===e?`ATR;${t}`:`${e};${s}`;return`Renko;${r};${i}`}case $.Kagi:{let{method:e,period:t,reversal:i}=uW(this.inputs),s="ATR"===e?`ATR;${t}`:`User;${i}`;return`Kagi;${s}`}case $.PointAndFigure:{let{method:e,period:t,reversal:i,boxSize:s,source:r,oneStepBack:n}=uK(this.inputs),a="ATR"===e?`ATR;${t}`:`User;${s}`;return`PointAndFigure;${a};${r};${i};${n}`}case $.LineBreak:{let{lineBreak:e}=u$(this.inputs);return`LineBreak;${e}`}default:return $[this.curveStyle]}}get needsExtraKey(){return[J.Options,J.BalanceSheet,J.IncomeStatement].includes(this.seriesKind)}getExtraKey(){return this.needsExtraKey&&this.fields.length>0?`${this.fields.map(e=>e.id).join(";")}`:""}getHashKey(){let e=this.aggregation.getHashKey(),t=this.getBuilderKey(),i=this.getExtraKey(),s=this.extendedHours??!1;return`${this.symbol}|${e}|${s}|${this.range}|${this.seriesKind}|${this.offset}|${t}|${this.splits}|${this.padded}|${i}`}duplicate(){let e=new cd(this.symbol,this.aggregation.duplicate(),this.seriesKind,this.range);return e.cacheMe=this.cacheMe,e.barsToFetch=this.barsToFetch,e.alwaysUseBarsToFetch=this.alwaysUseBarsToFetch,e.offset=this.offset,e.chartId=this.chartId,e.curveStyle=this.curveStyle,e.extendedHours=this.extendedHours,e.fields=ez(this.fields),e.splits=this.splits,e.padded=this.padded,e}}var cp=N("c15IW");function cf(e,t){let i=e.query?.duplicate();if(!eF(i)||i.symbol===tz.PLACEHOLDER_SYMBOL_NAME||"Standard"!==i.getBuilderKey())return new uJ;{0!==i.barsToFetch&&(i.barsToFetch=i.barsToFetch*tz.SERVER_COMPUTED_STUDY_BAR_MULTIPLIER);let e=t(i);return e.serverComputedSeries=!0,e}}function cm(e){return new ap(e,Y.Number,K.Study,e)}class cg{calcCtx;container;_source;target;inputs;outFields;studyFields={};innerSeries;calculable=!0;useNotifications=!1;initialNotification=!1;computedServerSide=!1;id;usedAsStyle=!1;recalcTriggers=new Set;basisChangedToken=null;_canLoadMoreData=!1;isLoading=!1;query;aggregation;sourceNeedsCompute=!1;allowEmptyValues=!1;constructor(e,...t){this.container=this._source=null,this.inputs=e.inputs,this.setOptions(e),this.innerSeries=t,this.id=e1(),this.addRecalcTrigger(...t)}refresh(){}get canLoadMoreData(){return this._canLoadMoreData}set canLoadMoreData(e){this._canLoadMoreData=e}loadMoreData(e){throw Error("Should not be called.")}addInner(...e){this.innerSeries.push(...e),this.addRecalcTrigger(...e)}isCalculable(e){return e.calculable??!1}addRecalcTrigger(...e){for(let t of e)this.isCalculable(t)?t.recalcTriggers.forEach(e=>this.recalcTriggers.add(e)):this.recalcTriggers.add(t)}setOptions(e){ej(this,e);let t=e.outFields??[e.target];this.studyFields=this.helpers.concat(t).reduce((e,t)=>(e[t.id]=t,e),{})}get helpers(){return tz.EMPTY_ARRAY}get hasData(){return null!==this.container}get source(){if(eF(this._source))return this._source;let e=eF(this.inputs)?this.inputs[tz.INPUT_SOURCE]:null;return eF(e)?ag[e]:null}set source(e){this._source=e}async ready(){return tU.call(this,async()=>{this.basisChangedToken=this.useNotifications?e(cp).subscribe(ay.TS_ALL,this.onBasisChanged.bind(this)):null;let t={tag:e1(),src:null},i=(await Promise.all(this.innerSeries.map(e=>e.ready()))).every(ep);return i&&this.calculate(t),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onBasisChanged(e,t){if(e===ay.TS_EVENTSCHANGED||e===ay.TS_LOADING||this.innerSeries.some(e=>!e.hasData)||!this.shouldTriggerOurRecalc(t.series)||null===this.base||this===t.series)return;let i={tag:e1(),src:t.series};switch(e){case ay.TS_MANYCHANGED:this.calculate(i);break;case ay.TS_DATAPOINTCHANGED:case ay.TS_DATAPOINTADDED:{let s=this.innerSeries[this.baseIndex].calculable?this.base.size-1:t.index;this.recalculateAt(i,s,e===ay.TS_DATAPOINTADDED);break}case ay.TS_TIMELINECORRECTION:case ay.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.useNotifications&&this.basisChangedToken&&e(cp).unsubscribe(this.basisChangedToken)}get baseIndex(){return 0}get base(){return this.innCont(this.baseIndex)}get period(){return this.inputs?.Period}calculateAt(e){return null}calculateDataPoint(e,t){let i=this.calculateAt(e);null!==i&&Object.keys(i).forEach(e=>{let s=i[e],r=this.studyFields[e];t?this.container.addDataPoint(r,s):this.container.setLastDataPoint(r,s)})}notify(e,t){eN(e,{series:this,index:t})}calculateCommon(e,t=null,i=-1,s=!0){let r=-1===i,n=r?t=>{(eF(e.src)||!eF(t.calcCtx))&&t.calculate(e)}:t=>t.recalculateAt(e,i,s);if(null===this.base||this.calcCtx&&this.calcCtx.tag===e.tag||this===e.src)return;this.calcCtx=e;let a=e=>this.isCalculable(e)&&!e.usedAsStyle;if(this.innerSeries.filter(a).forEach(e=>n(e)),r&&(this.container=this.makeContainer()),void 0!==this.calculateAt)if(r){let e=this.base.size;for(let t=0;t<e;++t)this.calculateDataPoint(t,!0)}else this.calculateDataPoint(i,s);t&&(eF(e.src)||this.initialNotification)&&this.notify(t,i)}calculate(e){this.calculateCommon(e,ay.TS_MANYCHANGED,-1,!0)}recalculateAt(e,t,i){this.computedServerSide||(!i&&eH(this.container)&&t>this.container.size-1&&(t=this.container.size-1),this.calculateCommon(e,i?ay.TS_DATAPOINTADDED:ay.TS_DATAPOINTCHANGED,t,i))}baseVal(e,t){return this.base.getData(e)[t]}innCont(e){return this.innerSeries[e].container}innVal(e,t,i){let s=this.innCont(e),r=s.size;return i<0||i>r-1?null:s.getData(t)[i]}innHasData(e){let t=this.innCont(e);return eF(t)&&t.size>0}wrap(...e){return e.reduce((e,t)=>(e[t.f.id]=t.g,e),{})}wrapBaseFields(...e){return e.map(this.wrapBaseField,this)}wrapInner(e,t){return{f:e,g:()=>this.innCont(t).getData(e)}}wrapBaseField(e){return this.wrapInner(e,this.baseIndex)}get defaultWrappers(){return this.wrapBaseFields(ag.DateTime,ag.Symbol)}makeContainer(){let e=this.defaultWrappers.concat(this.getWrappers());return new ue(Object.keys(this.studyFields).map(e=>this.studyFields[e],this),this.wrap(...e))}getWrappers(){return[]}atLeast(e,t){return e>=t-1}exactly(e,t){return e==t-1}past(e,t,i,s=this.base){return s.getData(i).slice(e-t+1,e+1)}getCacheableEntities(e){this.innerSeries.forEach(t=>{t.getCacheableEntities(e)})}}class cy extends cg{constructor(e,...t){super(e,...t),this.usedAsStyle=!0}get actual(){return this.innerSeries[0]}get canLoadMoreData(){return this.actual.canLoadMoreData}async loadMoreData(e=!0){return this.actual.loadMoreData(e)}get record(){return this.actual.record}}class cS extends cy{constructor(e,t){super(e,t),this.query=t.query,this.useNotifications=!0}calculateAt(e){let[t,i,s,r]=[ag.Open,ag.High,ag.Low,ag.Close].map(t=>this.baseVal(t,e),this),n=null,a=null,o=null,l=null,u=eg([t,i,s,r]);if(e<1)n=eg([t,r]),a=i,o=s,l=0;else{let[t,r]=[ag.Open,ag.Close].map(t=>this.container.getData(t)[e-1],this);a=Math.max(i,n=eg([t,r]),u),o=Math.min(s,n,u),l=u-r}return{[ag.Open.id]:n,[ag.High.id]:a,[ag.Low.id]:o,[ag.Close.id]:u,[ag.Change.id]:l}}getWrappers(){return this.wrapBaseFields(ag.Volume,ag.OpenInterest,ag.TradingDay)}}class cA extends cg{constructor(e,t){super(e,t),fj(this)}calculateAt(e){let t=null,i=this.period,[,s]=fK(this);if(this.atLeast(e,i)&&s.hasField(this.source)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=eg(r.filter(ef)):ey(r)&&(t=eg(r))}return{[this.target.id]:t}}getWrappers(){return this.source===ag.Volume?this.wrapBaseFields(ag.Volume,ag.TradeSize,ag.Change,ag.Open,ag.Close):[]}}class cT extends cg{multiplier;constructor(e,t,i){super(e,t),this.multiplier=i(this.period),fj(this)}calculateAt(e){let t=null,[i,s]=fK(this);if(this.atLeast(e,2)&&s.hasField(this.source)){let r=this.container.getData(this.target)[e-1];if(null!==r)t=(this.innVal(i,this.source,e)-r)*this.multiplier+r;else{let i=this.period;if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=eg(r.filter(ef)):ey(r)&&(t=eg(r))}}}return{[this.target.id]:t}}}class cv extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=ag.OpenInterest;return this.base.hasField(i)&&(t=this.baseVal(i,e)),{[i.id]:t}}}let cP={inField:ag.MA,outFields:[ag.ENVU,ag.ENVD],func:f_},cC={inField:ag.EMA,outFields:[ag.ENVEXPU,ag.ENVEXPD],func:fM},cb={inField:ag.SMA,outFields:[ag.ENVSMOU,ag.ENVSMOD],func:fx};class cE extends cg{kind;perc;constructor(e,t,i){super(e,i),this.kind=t,this.perc=this.inputs.Percent/100;let s=t.func(i,this.inputs.Period,e.source);this.addInner(s)}calculateAt(e){let t=null,i=null,s=this.innVal(1,this.kind.inField,e);if(null!==s){let e=s*this.perc;t=s+e,i=s-e}return{[this.kind.outFields[0].id]:t,[this.kind.outFields[1].id]:i}}}class cL extends cg{constructor(e,t){super(e,t);let i=f_(t,this.inputs.Period1,this.source),s=f_(t,this.inputs.Period2,this.source),r=fG(this.target,(e,t,i)=>t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(this.target,1)]}}let c_={fields:[ag.MACD,ag.MACDS,ag.MACDH],avgFunc:f_,mapFunc:fz,histogramVaryColor:!0},cM={fields:[ag.MACD,ag.MACDS,ag.MACDH],avgFunc:fM,mapFunc:fz,histogramVaryColor:!0},cx={fields:[ag.MACD,ag.CTLTM,ag.CTM],avgFunc:fM,mapFunc:fz,histogramVaryColor:!1},cI={fields:[ag.MACD,ag.CTLTMF,ag.CPMI],avgFunc:fM,mapFunc:fz,histogramVaryColor:!1},cD={fields:[ag.PPO,ag.PPOS,ag.PPOH],avgFunc:fM,mapFunc:fY,histogramVaryColor:!0},cO={fields:[ag.PVO,ag.PVOS,ag.PVOH],avgFunc:fM,mapFunc:fY,histogramVaryColor:!1};class cw extends cg{histogramVaryColor=!1;histogramField;get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=-1;if(this.histogramVaryColor&&e>0){let i=this.container.getData(this.histogramField)[e],s=this.container.getData(this.histogramField)[e-1];if(eF(i,s)){let r=i<=0;t=r?1:3,e>0&&(r&&i>s&&(t=0),!r&&i<s&&(t=2))}}return{[ag.BARCOLIX.id]:t}}}class cR extends cw{fields;constructor(e,t,i){super(e,i),this.fields=t.fields,this.histogramVaryColor=t.histogramVaryColor,this.histogramField=this.fields[2];let s=t.avgFunc(i,e.inputs.Period1,e.source,void 0),r=t.avgFunc(i,e.inputs.Period2,e.source,void 0),n=fG(this.fields[0],t.mapFunc,s,r),a=t.avgFunc(n,e.inputs.Period3,n.target,this.fields[1]),o=fG(this.fields[2],fz,n,a);this.addInner(n,a,o)}getWrappers(){return[this.wrapInner(this.fields[0],1),this.wrapInner(this.fields[1],2),this.wrapInner(this.fields[2],3)]}}let cN=cm("_AVG_GAIN"),cV=cm("_AVG_LOSS");class cH extends cg{constructor(e,t,i){super(e,i);let s=fB(i,this.inputs.Period,this.source,ag.RSI,t),r=fJ(e,"MA","Average")(s,this.inputs.PeriodAvg,ag.RSI,ag.RSIAVG);this.addInner(s,r)}getWrappers(){return[this.wrapInner(ag.RSI,1),this.wrapInner(ag.RSIAVG,2)]}}class cF extends cg{highest;index;constructor(e,t,i,s){super(e,s),this.highest=t,this.index=i}calculateAt(e){let t=null,i=this.inputs.Period;if(this.atLeast(e,i)){let s=this.past(e,i,this.source);ey(s)&&(t=this.highest?Math.max(...s):Math.min(...s),this.index&&(t=i-s.indexOf(t)-1))}return{[this.target.id]:t}}}class cB extends cg{toHighest;field;highField;lowField;constructor(e,t,i){super(e,i),this.toHighest=t;let s=eF(e.source),r=e.source,n=s?r:ag.Close;this.field=n;let a=s?r:ag.High;this.highField=a;let o=s?r:ag.Low;this.lowField=o;let l=fO(i,e.inputs.Period,this.highField,ag.HH,!0),u=fO(i,e.inputs.Period,this.lowField,ag.LL,!1);this.addInner(l,u)}calculateAt(e){let t=null,i=this.baseVal(this.field,e),s=this.innVal(1,ag.HH,e),r=this.innVal(2,ag.LL,e);if(ey([i,s,r])){let e=this.toHighest?s:r,n=s-r;0!==n&&(t=(i-e)/n*100)}return{[this.target.id]:t}}}let ck=cm("RawPercK");class cW extends cg{kField;constructor(e,t,i,s){super(e,s);let r=fw(s,this.inputs.Period1,t?ck:i,!1),n=fJ(e,"MA"),a=n(r,this.inputs.Period2,r.target,t?i:ag.PercD),o=t?n(a,this.inputs.Period3,a.target,ag.PercD):a;this.kField=i,t?this.addInner(a,o):this.addInner(r,a)}getWrappers(){return[this.wrapInner(this.kField,1),this.wrapInner(ag.PercD,2)]}}function cU(e,t,i,s,r){if(null===r)return null;let n=e*r,a=s+n,o=s-n;switch(t){case ag.BOLLBU:return a;case ag.BOLLBL:return o;case ag.BOLLBW:return(a-o)/s*100;default:return null}}class c$ extends cg{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=this.inputs.Period,r=this.source,n=f_(i,s,r,ag.BOLLBM),a="Modified"===t,o=fW(a?function(e,t,i=ag.PCTCHG){return fb("PCTCHG",{source:t,target:i,inputs:fR},e)}(i,r):i,s,a?ag.PCTCHG:r),l=this.inputs.Width,u=e=>ec(cU,l,e),h=fG(ag.BOLLBU,u(ag.BOLLBU),n,o),c=fG(ag.BOLLBL,u(ag.BOLLBL),n,o),d=fG(ag.BOLLBW,u(ag.BOLLBW),n,o),p=fJ(e,"MA","Average")(d,this.inputs.PeriodAvg,ag.BOLLBW,ag.BOLLBWA);this.addInner(n,o,h,c,d,p)}calculateAt(e){let t=this.innVal(3,ag.BOLLBU,e),i=this.innVal(4,ag.BOLLBL,e),s=this.innVal(1,ag.BOLLBM,e),r=this.innVal(5,ag.BOLLBW,e),n=this.innVal(6,ag.BOLLBWA,e),a=null;switch(eF(t,i)&&(a=(this.baseVal(ag.Close,e)-i)/(t-i)),this.kind){case"Regular":return{[ag.BOLLBU.id]:t,[ag.BOLLBL.id]:i,[ag.BOLLBM.id]:s};case"Width":return{[ag.BOLLW.id]:t-i};case"Percent":return{[ag.BOLLP.id]:a};case"BandWidth":return{[ag.BOLLBW.id]:r,[ag.BOLLBWA.id]:n};case"Modified":{let t=null,i=null,r=null,n=null,a=this.innVal(2,ag.MSD,e);if(eF(a)){let e=this.inputs.MultInside,o=this.inputs.MultOutside;t=s+e*a,r=s-e*a,i=s+o*a,n=s-o*a}return{[ag.MBBUI.id]:t,[ag.MBBLI.id]:r,[ag.MBBUO.id]:i,[ag.MBBLO.id]:n,[ag.MBBM.id]:s}}default:return null}}}let cG=cm("_ABS_CHG"),cz=cm("_MA_ABS_CHG"),cY=cm("_CHG"),cj=cm("_PDM"),cK=cm("_MDM"),cq=cm("_TRS"),cX=cm("_PDS"),cZ=cm("_MDS"),cJ=cm("_DX");class cQ extends cg{useEma;adxField;multiplier;constructor(e,t,i,s){super(e,s),this.useEma=t,this.adxField=i,this.multiplier=2/(this.inputs.AdxSmoothing+1);let r=fN(s,ag.TR);this.addInner(r)}get helpers(){return[cj,cK,cq,cX,cZ,cJ]}sum(e,t,i,s){let r=null;if(this.atLeast(e-1,s-1)){let n=this.past(e-1,s-1,t,this.container);n.push(i),ey(n)&&(r=n.reduce((e,t,i)=>e+t,0))}return r}smooth1(e,t,i,s){let r=this.inputs.DiLength,n=this.container.getData(i)[e-1];return null!==n?n-n/r+s:this.sum(e,t,s,r)}smooth2(e,t,i,s){let r=this.container.getData(i)[e-1],n=this.inputs.AdxSmoothing;if(null!==r)if(this.useEma)return(s-r)*this.multiplier+r;else return(r*(n-1)+s)/n;{let i=this.sum(e,t,s,n);if(null!==i)return i/n}return null}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=null,l=null,u=null;if(e>0){let h=this.past(e,2,ag.High),c=this.past(e,2,ag.Low),d=Math.max(h[1]-h[0],0),p=Math.max(c[0]-c[1],0);t=d>p?d:0,i=p>d?p:0;let f=this.container.getData(ag.TR)[e];r=this.smooth1(e,cj,cX,t),n=this.smooth1(e,cK,cZ,i),s=this.smooth1(e,ag.TR,cq,f),(r>0||n>0)&&0!==s&&(l=100*Math.abs((a=r/s*100)-(o=n/s*100))/(a+o),u=this.smooth2(e,cJ,this.adxField,l))}return{[cj.id]:t,[cK.id]:i,[cq.id]:s,[cX.id]:r,[cZ.id]:n,[ag.PDI.id]:a,[ag.MDI.id]:o,[cJ.id]:l,[this.adxField.id]:u}}getWrappers(){return[this.wrapInner(ag.TR,1)]}}class c0 extends cg{calculateAtFunc;constructor(e,t,...i){super(e,...i),this.calculateAtFunc=t}calculateAt(e){let t=this.innerSeries.map((t,i)=>{let s=t.target;return eF(s)||(s=t.container.hasField(ag.Close)?ag.Close:t.container.fields[0]),this.innVal(i,s,e)}),i=null;return ey(t)&&(i=this.calculateAtFunc(e,...t)),{[this.target.id]:i}}}function c1(e,t){let i=this.baseVal(ag.High,t),s=this.baseVal(ag.Low,t);return{[e.id]:(i+s)/2}}function c2(e,t){let i=this.baseVal(ag.High,t),s=this.baseVal(ag.Low,t);return{[e.id]:i-s}}class c3 extends cg{calculateAtFunc;constructor(e,t,i){super(e,i),this.calculateAtFunc=t}calculateAt(e){return this.calculateAtFunc.call(this,e)}}let c4=cm("_RANGE"),c5=cm("_MOV_RANGE"),c6={fields:[ag.KCUP,ag.KCLOW,ag.KCMID],midSeries:e=>fH(e,ag.TP),midTarget:ag.TP,rangeSeries:e=>f$(c4,eh(c2,c4),e),rangeTarget:c4,func:"MA",useMultiplier:!1},c7={fields:[ag.KBUP,ag.KBLOW,ag.KBMID],midSeries:e=>e,midTarget:ag.Close,rangeSeries:e=>fN(e,ag.TR),rangeTarget:ag.TR,func:"EMA",useMultiplier:!0};class c8 extends cg{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=t.midSeries(i),r=fJ(e,t.func,"Average"),n=r(s,this.inputs.Period,t.midTarget,t.fields[2]),a=r(t.rangeSeries(i),this.inputs.Period,t.rangeTarget,c5);this.addInner(n,a)}calculateAt(e){let t=this.innVal(1,this.kind.fields[2],e),i=this.innVal(2,c5,e),s=null!==t&&null!==i,r=this.kind.useMultiplier?this.inputs.Multiplier:1;return{[this.kind.fields[0].id]:s?t+i*r:null,[this.kind.fields[1].id]:s?t-i*r:null}}getWrappers(){return[this.wrapInner(this.kind.fields[2],1)]}}class c9 extends cg{isWidth;constructor(e,t,i){super(e,i),this.isWidth=t;let s=fO(i,this.inputs.Period,ag.High,ag.DONUP,!0),r=fO(i,this.inputs.Period,ag.Low,ag.DONLOW,!1);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,ag.DONUP,e),i=this.innVal(2,ag.DONLOW,e),s=null===t&&null===i;return this.isWidth?{[ag.DONW.id]:s?null:t-i}:{[ag.DONMID.id]:s?null:(t+i)/2}}getWrappers(){return[this.wrapInner(ag.DONUP,1),this.wrapInner(ag.DONLOW,2)]}}let de=cm("_HIND"),dt=cm("_LIND");class di extends cg{justWidth;constructor(e,t,i){super(e,i),this.justWidth=t,this.justWidth=t;let s=this.inputs.Period,r=fO(i,s,ag.High,de,!0,!0),n=fO(i,s,ag.Low,dt,!1,!0);this.addInner(r,n)}calculateAt(e){let t=null,i=null,s=null,r=this.innVal(1,de,e),n=this.innVal(2,dt,e);if(null!==r&&null!==n){let e=this.period;s=(t=(e-r)/e*100)-(i=(e-n)/e*100)}return this.justWidth?{[ag.ARNOSC.id]:s}:{[ag.ARNUP.id]:t,[ag.ARNLOW.id]:i}}}let ds=cm("_MIDPOINT"),dr=cm("_MIDPOINT");class dn extends cg{multiplyVol;constructor(e,t,i){super(e,i),this.multiplyVol=t}calculateAt(e){let[t,i,s,r]=[ag.High,ag.Low,ag.Close,ag.Volume].map(t=>this.baseVal(t,e)),n=t===i?0:(s-i-(t-s))/(t-i);return this.multiplyVol&&(n*=r),{[this.target.id]:n}}}let da=cm("_RANGE"),dl=cm("_MATP");class du extends cg{isBull;constructor(e,t,i){super(e,i),this.isBull=t;let s=fM(i,this.inputs.Period,this.source);this.addInner(s)}calculateAt(e){let t=null,i=this.innVal(1,ag.EMA,e);return null!==i&&(t=this.isBull?this.baseVal(ag.High,e)-i:this.baseVal(ag.Low,e)-i),{[this.isBull?ag.ERBLPOW.id:ag.ERBRPOW.id]:t}}}let dh=cm("_FORCE"),dc=cm("_RANGE"),dd=cm("_EMA1"),dp=cm("_EMA2"),df=cm("_RATIO"),dm={isNegative:!1,fields:[ag.PVI,ag.PVIEMA]},dg={isNegative:!0,fields:[ag.NVI,ag.NVIEMA]};class dy extends cg{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=f$(this.kind.fields[0],eh(function(e,t){let i=1e3;if(t>0){let s=[ag.Close,ag.Volume],[r,n]=s.map(e=>this.baseVal(e,t)),[a,o]=s.map(e=>this.baseVal(e,t-1)),l=this.container.getData(this.target)[t-1];i=(e?n<o:n>o)?l*((r-a)/a+1):l}return{[this.target.id]:i}},this.kind.isNegative),i),r=fM(s,this.inputs.Period,this.kind.fields[0],this.kind.fields[1]);this.addInner(s,r)}getWrappers(){return[this.wrapInner(this.kind.fields[0],1),this.wrapInner(this.kind.fields[1],2)]}}let dS=cm("_LOGPC"),dA=cm("_SWING_INDEX"),dT=cm("_MIN_CLOSE"),dv=cm("_MAX_CLOSE"),dP=cm("_EP"),dC=cm("_AF"),db=cm("_POS"),dE=cm("_IDY"),dL=[0,0,0,1,1,1,5,5,2,1,1,0,50,50,0,1,1,1,5,0,0],d_=e=>Array(e).fill(0);function dM(e,t,i){let s=e[i-1];return 0===t&&(s=e[i]),t<0&&(s=e[i+1]),s}function dx(e,t,i){let s=0,r=-1,n=0,a=1;for(let o=0;o<i;++o){if(t[o]=0,null==e[o]||(21==++s&&(a=2),31==s&&(a=3),n+=e[o]*a,s<40))continue;t[o]=n/70;let l=0,u=r+1;for(let t=u;t<i&&(null==e[t]||(1==++l&&(r=t),(1==l||21==l||31==l)&&(n-=e[t]),31!=l));++t);}}let dI={1:{param:"cot",func:"parseCotLineChart",fields:[ag.DateTime,ag.COTLCCMSP,ag.COTLCLGSP,ag.COTLCSMSP]},2:{param:"cotadv",func:"parseDisaggregated",fields:[ag.DateTime,ag.COTDAGPRO,ag.COTDAGSPD,ag.COTDAGMNM,ag.COTDAGOTH]},3:{param:"cotfin",func:"parseFinancialTradersReport",fields:[ag.DateTime,ag.COTFTRDLI,ag.COTFTRASM,ag.COTFTRLVF,ag.COTFTROTH]}};class dD extends cg{wrappers;constructor(e,t,i){super(e,cf(i,e=>new dO(t,e))),this.computedServerSide=!0,this.initialNotification=!0,this.wrappers=dI[t].fields.slice(1).map(e=>this.wrapInner(e,0))}getWrappers(){return this.wrappers}}class dO extends uZ{kind;constructor(e,t){super(t),this.kind=e}getRetriever(){return new dw(this.kind)}onStreamingUpdates(e){}}class dw extends uA{kind;constructor(e){super(),this.kind=e}addExtraParams(e){e[dI[this.kind].param]="y"}getParser(e){return new dR(e.symbol,e.aggregation,this.kind)}}class dR extends ug{kind;constructor(e,t,i){super(e,t,0),this.kind=i}makeContainer(){return new l8(dI[this.kind].fields)}getParseFunc(){return this.aggregation.isEndOfDay?this[dI[this.kind].func]:null}parseCotLineChart(e){this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.COTLCCMSP,parseInt(e[2])),this.container.addDataPoint(ag.COTLCLGSP,parseInt(e[3])),this.container.addDataPoint(ag.COTLCSMSP,parseInt(e[4]))}parseDisaggregated(e){this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.COTDAGPRO,parseInt(e[2])),this.container.addDataPoint(ag.COTDAGSPD,parseInt(e[3])),this.container.addDataPoint(ag.COTDAGMNM,parseInt(e[4])),this.container.addDataPoint(ag.COTDAGOTH,parseInt(e[5]))}parseFinancialTradersReport(e){this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.COTFTRDLI,parseInt(e[2])),this.container.addDataPoint(ag.COTFTRASM,parseInt(e[3])),this.container.addDataPoint(ag.COTFTRLVF,parseInt(e[4])),this.container.addDataPoint(ag.COTFTROTH,parseInt(e[5]))}}class dN extends dD{constructor(e,t){super(e,1,t)}}let dV={Day:[ag.PreviousHigh,ag.PreviousLow,ag.PreviousClose],Week:[ag.WeekPreviousHigh,ag.WeekPreviousLow,ag.WeekPreviousClose],Month:[ag.MonthPreviousHigh,ag.MonthPreviousLow,ag.MonthPreviousClose]};class dH extends cg{disabled;record;streamingSubscription;constructor(e,t,i){if(super(e,i),this.disabled=!eF(i.query)||!eF(i.query.symbol),!this.disabled){let e=i.query.symbol;e.endsWith(".BZ")&&(e=e.slice(0,-3)),this.record=Sp().getRecordSource().getRecord(e),this.record.addFields(...t),this.streamingSubscription=this.getStreamingSubscription()}this.initialNotification=!0}getStreamingSubscription(){return Sp().getRecordSource().subject.pipe(ub(e=>{let t=aR(ay.RT_QUOTE,this.record.symbol);return e.filter(t)}),ov(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}async ready(){return tU.call(this,async()=>eF(this.record)?await this.record.ready()&&await super.ready():await super.ready(),"asyncReadyWork2")}onStreamingUpdates(e){if(this.record){let e={tag:e1(),src:null};this.calculate(e)}}shutdown(){super.shutdown(),this.disabled||this.streamingSubscription.unsubscribe()}getValues(e){return dV[e].map(e=>this.record.getValue(e))}}class dF extends uZ{constructor(e){super(e)}getRetriever(){return tg(this.query.symbol)?new dU:new dB}onStreamingUpdates(e){}}class dB extends uA{addExtraParams(e){e.impl="y"}getParser(e){return new dW(e.symbol,e.aggregation)}}function dk(){return new l8([ag.DateTime,ag.IMPVOL])}class dW extends ug{constructor(e,t){super(e,t)}makeContainer(){return dk()}getParseFunc(){return this.parseImpVol}parseImpVol(e){this.aggregation.isEndOfDay&&!(e.length<9)&&(this.container.addDataPoint(ag.DateTime,this.parseDate(e[1])),this.container.addDataPoint(ag.IMPVOL,parseFloat(e[8])))}}class dU extends uT{emptyContainer(e,t){return dk()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(ag.DateTime,l2(e.date.substring(0,10)));let s=eH(e.impliedVolatility);i.addDataPoint(ag.IMPVOL,s?100*e.impliedVolatility:null)}}let d$=cm("_ABS_CHG"),dG=cm("_DS1_EMA1"),dz=cm("_DS1_EMA2"),dY=cm("_DS2_EMA1"),dj=cm("_DS2_EMA2"),dK=cm("_DIFF"),dq=cm("_SUM"),dX=cm("_ABS_CHG"),dZ=cm("_HH_LL"),dJ=cm("_MULMA"),dQ=cm("_DIFF");class d0 extends cy{constructor(e,t){super(e,t),this.query=t.query,this.useNotifications=!0}calculateAt(e){let t=[null,null,null,null,null];if(e>0){let i=(e,t)=>this.baseVal(e,t),s=[ag.Open,ag.High,ag.Low,ag.Close],r=s.map(t=>i(t,e));if(ey(r)){let n=s.map(t=>i(t,e-1));if(ey(n)){let[i,s]=eM(t=r.map((e,t)=>100*(e-n[t])/n[t]));if(t[1]=s,t[2]=i,e>1){let i=this.container.getData(ag.Close)[e-1];t[4]=t[3]-i}}}}return{[ag.Open.id]:t[0],[ag.High.id]:t[1],[ag.Low.id]:t[2],[ag.Close.id]:t[3],[ag.Change.id]:t[4]}}getWrappers(){return this.wrapBaseFields(ag.Volume,ag.OpenInterest,ag.TradingDay)}}let d1=cm("_DIST"),d2=cm("_EMA_DIST1"),d3=cm("_EMA_DIST2"),d4=cm("_DIFF"),d5=cm("_EMA_DIFF1"),d6=cm("_EMA_DIFF2"),d7=cm("_CHG"),d8=cm("_M1"),d9=cm("_M2");class pe extends cg{constructor(e,t){super(e,t);let i=f$(d7,function(e){let t=ag.Close,i=e>0?this.baseVal(t,e)-this.baseVal(t,e-1):0;return{[d7.id]:i}},t),s=fG(d8,(e,t)=>t>=0?t:0,i),r=fG(d9,(e,t)=>t>=0?0:-t,i);this.addInner(s,r)}perc(e,t){return 100*e/t}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i+1)){let s=this.past(e,i,d8,this.innCont(1)),r=this.past(e,i,d9,this.innCont(2));if(ey(s)&&ey(r)){let e=em(s),i=em(r);t=this.perc(e-i,e+i)}}return{[ag.CHDMOMOSC.id]:t}}}let pt=cm("_MAX"),pi=cm("_MIN"),ps=cm("_ISUPTREND"),pr=cm("_TRENDUP"),pn=cm("_TRENDDOWN"),pa=cm("_TREND"),po=cm("_CUM_PRICE"),pl=cm("_CUM_VOL"),pu=cm("_PER_CHG");class ph extends cg{constructor(e,t){super(e,t);let i=this.source,s=f$(i,eh(fq,i),t);this.addInner(s)}valueAt(e,t){return this.container.getData(e)[t]}dateAt(e){return this.container.getTimeData()[e]}}let pc=cm("_DIFF"),pd=[pc,ag.Buy,ag.Sell];function pp(e,t,i,s){let r=null,n=null,a=null;eF(i,s)&&(a=i-s);let o=t>0?e.getData(pc)[t-1]:null;return eF(a,o)&&(r=a>0&&o<=0?1:null,n=a<0&&o>=0?-1:null),{[pc.id]:a,[ag.Buy.id]:r,[ag.Sell.id]:n}}let pf=cm("_PVM"),pm=cm("_NVM");var cp=N("c15IW");function pg(e,t,i){return new py(e,t,i)}class py{exprModel;innerSeries;calculable;container;innerLookup;policy;exprSymbols;valueSymbols;onlyForTimeline;recalcTriggers;crashedComputationReported;isLoading;_sourceFields;_targetFields;basisChangedToken;quoteGroupToken;constructor(e,t,i){this.exprModel=e,this.innerSeries=t,this.calculable=!0,this.valueSymbols=[],this.crashedComputationReported=!1,this.isLoading=!1,this.basisChangedToken=null,this.quoteGroupToken=null,this.container=null,this.innerLookup=t.reduce((e,t)=>(e[i.mapper(t)]=t,e),{}),this.policy=i,this.exprSymbols=nJ(e),this.valueSymbols=this.exprSymbols.filter(e=>void 0===this.innerLookup[e]),this.onlyForTimeline=ev(this.symbols,this.exprSymbols),this.recalcTriggers=new Set(t)}refresh(){this.innerSeries.forEach(e=>e.refresh())}get canLoadMoreData(){return this.policy.loadMoreData&&this.innerSeries.some(e=>e.canLoadMoreData)}async loadMoreData(e=!0){if(this.isLoading)return Promise.resolve();this.isLoading=!0;let t=this.innerSeries.filter(e=>e.canLoadMoreData).map(t=>t.loadMoreData(e));await Promise.all(t),this.isLoading=!1}get isExprInError(){return!eF(this.exprModel)}get hasData(){return null!==this.container}get sourceFields(){return this._sourceFields||(this._sourceFields=Array.from(this.policy.fieldMap.keys())),this._sourceFields}get targetFields(){return this._targetFields||(this._targetFields=Array.from(this.policy.fieldMap.values())),this._targetFields}async ready(){return tU.call(this,async()=>{this.basisChangedToken=e(cp).subscribe(ay.TS_ALL,this.onBasisChanged.bind(this)),this.quoteGroupToken=e(cp).subscribe(ay.RT_QUOTEGROUP,this.onQuoteGroup.bind(this));let t=this.innerSeries.map(e=>e.ready());void 0!==this.policy.valueProvider&&t.push(this.policy.valueProvider.ready());let i=(await Promise.all(t)).every(ep);return i&&this.calculate(),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onQuoteGroup(e,t){t.source===this.policy.valueProvider&&this.innerSeries.every(e=>eF(e.container))&&this.calculateCommon(ay.TS_MANYCHANGED)}onBasisChanged(e,t){if(this.policy.recompute===B.Manual||e===ay.TS_EVENTSCHANGED||e===ay.TS_LOADING||!this.shouldTriggerOurRecalc(t.series)||this.innerSeries.some(e=>!eF(e.container)))return;let i=this.policy.mapper(t.series);if(!(e===ay.TS_DATAPOINTCHANGED&&this.onlyForTimeline?.includes(i)))switch(this.policy.recompute===B.Everything?ay.TS_MANYCHANGED:e){case ay.TS_MANYCHANGED:this.calculate();break;case ay.TS_DATAPOINTCHANGED:case ay.TS_DATAPOINTADDED:this.recalculate(e===ay.TS_DATAPOINTADDED);break;case ay.TS_TIMELINECORRECTION:case ay.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.basisChangedToken&&e(cp).unsubscribe(this.basisChangedToken),this.quoteGroupToken&&(e(cp).unsubscribe(this.quoteGroupToken),this.policy.valueProvider?.shutdown())}calculateAt(e){return e.isNull?null:this.sourceFields.map((t,i)=>t===ag.Volume?em(this.exprSymbols.map(t=>e.inn[t].values[i]??0)):nq(this.exprModel,t=>e.oneValue[t]??e.inn[t]?.values[i]??null))}pickMainField(){let e=null;for(let t of this.policy.fieldMap.values())if(null==e)e=t;else if(t===ag.Close){e=t;break}return e}calculateLastChange(){let e=this.container,t=e.size;if(t<=1)return;let i=this.pickMainField(),s=e.getData(i)[t-2],r=e.getData(i)[t-1];eF(s,r)&&e.setLastDataPoint(ag.Change,r-s)}calculateDataPoint(e,t){let i=this.calculateAt(e);if(null===i)return;e.atLeastOne=!0;let[s,r]=eM(i,0,3);i[1]=r,i[2]=s,this.targetFields.forEach((e,s)=>{let r=i[s];t?this.container.addDataPoint(e,r):this.container.setLastDataPoint(e,r)}),t&&(this.container.addDataPoint(ag.Change,null),this.container.addDataPoint(ag.DateTime,new Date(e.timeStamp))),this.calculateLastChange()}notify(e){eN(e,{series:this,index:this.container.size-1})}fieldValueAt(e,t,i){let s=this.innerLookup[e].container.getData(i);return t<0||t>=s.length?null:s[t]}timeStampAt(e,t){return this.fieldValueAt(e,t,ag.DateTime)}timeline(e){return e.container.getData(ag.DateTime)}getRangeHelper(){switch(this.policy.missing){case F.UseNext:case F.UseNone:return Math.min;case F.UsePrevious:return Math.max;default:throw Error("Unknow missing bar policy, likely forgot to implement it.")}}getRange(){let e=this.getRangeHelper();return{begin:new Date(e(...this.symbols.map(e=>eb(this.timeline(this.innerLookup[e]))))),end:new Date(e(...this.symbols.map(e=>eC(this.timeline(this.innerLookup[e])))))}}getFirstPos(){return this.getPos(this.getRange().begin)}getLastPos(){return this.getPos(this.getRange().end)}findIndex(e,t){let i=this.timeline(this.innerLookup[e]);switch(this.policy.missing){case F.UseNext:case F.UseNone:return i.findIndex(e=>e.valueOf()>=t.valueOf());case F.UsePrevious:return eE(i,e=>e.valueOf()<=t.valueOf());default:throw Error("Unknow missing bar policy, likely forgot to implement it.")}}checkPos(e){let t=Object.keys(e.inn).length;e.isNull=Object.values(e.inn).some(e=>!eF(e.timeStamp)&&(!this.policy.stretch(e.symbol)||1===t))}fillPosSymbolAt(e,t,i){e.index=t,e.timeStamp=this.timeStampAt(e.symbol,t);let s=(this.policy.missing===F.UseNone||this.policy.skipLeadingEmpty&&!i.atLeastOne)&&e.timeStamp&&e.timeStamp.valueOf()!==i.timeStamp.valueOf();return e.values=this.sourceFields.map(i=>s?null:this.fieldValueAt(e.symbol,t,i)),e}skippable(e){return!!this.innerLookup[e].container.isEmpty&&(this.policy.noDataApproach===k.IgnoreTimelineOnly&&this.onlyForTimeline.includes(e)||this.policy.noDataApproach===k.ModelTransformRequired)}get symbols(){let e=Object.keys(this.innerLookup);return eF(this.onlyForTimeline)?e.filter(e=>!this.skippable(e)):e}getPos(e){let t={isNull:!0,inn:{},timeStamp:e,atLeastOne:!1,oneValue:{}};return 0===this.symbols.length||(this.symbols.forEach(i=>{let s=this.findIndex(i,e),r={symbol:i,index:-1,timeStamp:new Date(0),values:[]};t.inn[i]=this.fillPosSymbolAt(r,s,t)}),this.valueSymbols.forEach(e=>{t.oneValue[e]=this.policy.valueProvider?.getValue(e)??null}),this.checkPos(t)),t}getInner(e){return Object.values(e.inn)}moveNext(e){!e.isNull&&(this.getInner(e).forEach(t=>{for(;eF(t.timeStamp)&&t.timeStamp.valueOf()<=e.timeStamp.valueOf();)this.fillPosSymbolAt(t,t.index+1,e)}),this.checkPos(e),e.isNull||(e.timeStamp=new Date(Math.min(...this.getInner(e).filter(e=>null!==e.timeStamp).map(e=>e.timeStamp.valueOf()))),this.policy.missing===F.UsePrevious?this.getInner(e).forEach(t=>{let i=eF(t.timeStamp);(i&&t.timeStamp.valueOf()>e.timeStamp.valueOf()||!i&&this.policy.stretch(t.symbol))&&this.fillPosSymbolAt(t,t.index-1,e)}):this.policy.missing===F.UseNone&&this.getInner(e).forEach(t=>this.fillPosSymbolAt(t,t.index,e))))}shouldAdd(e){return this.container.getLastDataPoint(ag.DateTime).valueOf()<e.timeStamp.valueOf()}calculateCommon(e=null,t=null,i=!0){try{if(t)this.calculateDataPoint(t,i);else if(this.container=this.makeContainer(),!this.isExprInError){let e=this.getFirstPos();for(;!e.isNull;)this.calculateDataPoint(e,!0),this.moveNext(e)}e&&this.notify(e)}catch(e){this.crashedComputationReported||(So(e,"error"),this.crashedComputationReported=!0)}}calculate(){let{yes:e,no:t}=eA(this.innerSeries,e=>!e.container.isEmpty);if(t.length>0&&this.policy.noDataApproach===k.ModelTransformRequired){let i=e=>e.map(this.policy.mapper),s=this.policy.modelTransform(i(e),i(t));null!==s&&(this.exprModel=s)}this.calculateCommon(ay.TS_MANYCHANGED)}recalculate(e){if(this.isExprInError)return;let t=this.getLastPos(),i=this.shouldAdd(t);this.calculateCommon(i?ay.TS_DATAPOINTADDED:ay.TS_DATAPOINTCHANGED,t,i)}recalculateAt(e,t,i){return this.recalculate(i)}makeContainer(){return new l8([ag.DateTime,ag.Change].concat(this.targetFields))}getCacheableEntities(e){this.innerSeries.forEach(t=>{t.getCacheableEntities(e)})}}let pS=cm("_AVG"),pA=cm("_HAO"),pT=cm("_HAH"),pv=cm("_HAL"),pP=cm("_HAC"),pC=cm("_DELTA"),pb=cm("_DIFF"),pE=cm("_RANK"),pL=cm("_CHG"),p_=cm("_AVG"),pM=cm("_HBRAKE_CHG"),px=cm("_HEIGHT_DELTA"),pI=cm("_ACTION"),pD=cm("_REVERSAL"),pO=e=>[e>0,e<0],pw=[null,null,null];function pR([e,t],i){let s=null;if(i>0){let t=this.baseVal(e,i-1);eF(t)&&(s=this.baseVal(e,i)-t)}return{[t.id]:s}}class pN extends cg{useHandbrake;constructor(e,t){super(e,t);let i=fJ(e,"MA","Average"),s=i(t,e2(1,999,this.inputs.FastPeriod),ag.Close),r=e2(0,999,this.inputs.SlowPeriod),n=r>0,a=n?i(t,r,ag.Close):t,o=fG(pb,n?(e,t,i)=>t-i:(e,t,i)=>i-t,s,a),l=f$(pL,eh(pR,[ag.Close,pL]),t),u=f$(pE,function(e){let t=Math.abs(this.baseVal(pb,e)),i=null,s=0,r=0;for(let i=e-1;i>=0&&s<200;--i){let e=Math.abs(this.baseVal(pb,i));s++,e<t&&r++}return s>0&&(i=Math.floor(r/s*10)),10===i&&i--,{[pE.id]:i}},o),h=e2(0,999,this.inputs.HandbrakePeriod);this.useHandbrake=h>0;let c=i(t,h,ag.Close,p_),d=f$(pM,eh(pR,[p_,pM]),c);this.addInner(l,o,u,d)}get helpers(){return[px,ag.BARCOLIX,pI,pD]}getStateAt(e){let t=this.innVal(2,pb,e);return eF(t)?pO(t):pw}findPreviousKnownState(e){for(let t=e-1;t>0;t--){let e=this.getStateAt(t);if(e===pw)break;let[i,s]=e;if(i||s)return e}return pw}getBuySell(e){let t=this.getStateAt(e);if(t===pw)return pw;let[i,s]=t,r=this.findPreviousKnownState(e),[n,a]=r;if(!i&&!s)return r===pw?pw:[n,a,!1];let o=i!==n||s!==a;return o?[n,a,o]:[i,s,o]}getPrev(e,t){return t>0?this.container.getData(e)[t-1]:null}calculateAt(e){let t=null,i=null,s=0,r=-1,n=0,[a,o,l]=this.getBuySell(e),[u,h]=[pD,pI].map(t=>this.getPrev(t,e)),[c,d]=[0,-1].map(t=>this.innVal(4,pM,e+t));if(r=l?10:this.innVal(3,pE,e),this.useHandbrake&&eF(c,d)){let t=a&&d>0||o&&d<0,i=!a&&c>0||!o&&c<0;l?(r=i?10:12,n=h):(!0===u||1===h)&&(t?(r=this.innVal(3,pE,e),n=2):(r=i?11:13,n=1))}if(eF(this.innVal(2,pb,e))){let t=this.innVal(1,pL,e),[i,r]=pO(t),n=Math.abs(t);(a&&i||o&&r)&&(s=n),(a&&r||o&&i)&&(s=-n)}return a?t=1:o&&(i=1),{[ag.JPIB.id]:t,[ag.JPIS.id]:i,[ag.BARCOLIX.id]:r,[px.id]:s,[pI.id]:n,[pD.id]:l}}}let pV={FastPeriod:8,SlowPeriod:21,HandbrakePeriod:13,Average:"EMA",Height:"Fixed"},pH=cm("_SMTH_ROC"),pF=cm("_TEN_SMTH_ROC");function pB(e,t,i,s,r){return new cT({source:s,target:r,outFields:[r],aggregation:i,inputs:fP(t)},e,e=>2/e)}let pk=cm("_VOL_AVG"),pW=131,pU=(()=>{let e=eB(.9865008210958766,6),t=ex(52,t=>Math.pow(e,t)),i=52/em(t);return t.map(e=>e*i)})(),p$=["Renko","Kagi","PointAndFigure","LineBreak"];function pG(e){return e===z.Continue||e===z.Nearest}class pz extends cg{additionalChunksCounter=1;noData=!1;isPeriodic=!1;constructor(e,t,i){super(e,i,cf(i,e=>{if(!sB(er[Sp()?.config.mode??"Unspecified"]))return i;let t=e.duplicate(),s=e.aggregation;if(s.hasSpec)if(pG(s.spec))return i;else return new uJ(t,!0);let r=s.unit===G.Intraday&&s.size<=5,n=function(e,t){switch(e){case G.Intraday:if(t>=240)return 3;if(t>=120)return 2;return 1;case G.Day:default:return 5;case G.Week:return 15;case G.Month:return 60;case G.Quarter:case G.Year:return 240}}(s.unit,s.size);return t.aggregation=r?new nw(G.Tick,s.size,z.PerSeconds):new nw(G.Intraday,n),t.barsToFetch=Math.min(tz.MAX_INTRADAY_BARS,(r?1:3)*e.barsToFetch),new uZ(t)})),this.isPeriodic=t,this.noData=this.innerSeries[1]instanceof uJ,this.computedServerSide=!0,this.initialNotification=!0}get canLoadMoreData(){return!1}loadMoreData(){let e=this.innerSeries[1];return!this.noData&&this.additionalChunksCounter<20&&e.canLoadMoreData&&!e.isLoading?(this.additionalChunksCounter+=1,e.loadMoreData()):Promise.resolve()}recalculateAt(e,t,i){if(e.src!==this.innerSeries[0])return;let s=i?ay.TS_DATAPOINTADDED:ay.TS_DATAPOINTCHANGED;this.notify(s,this.innerSeries[0].container.size-1)}getWrappers(){return[this.wrapInner(ag.Change,1),this.wrapInner(ag.Open,1),this.wrapInner(ag.Close,1)]}}let pY=cm("_EMA1"),pj=cm("_EMA2"),pK=cm("_MACD"),pq=cm("_PCTK"),pX=cm("_PCTD"),pZ=cm("_PCTK2"),pJ=cm("_EMA1"),pQ=cm("_EMA2"),p0=cm("_CORE");class p1 extends cg{isEmpty=!1;constructor(e,t){if(super(e,t),f2(t)&&e.aggregation?.isEndOfDay){let i=["$ADVT","$DECT"];switch(this.inputs.Source){case"TotalStocks":default:break;case"NYSEStocks":i=["$ADVN","$DECN"];break;case"NasdaqStocks":i=["$AVDQ","$DECQ"]}let s=this.getSeries(t.query,i[0]),r=this.getSeries(t.query,i[1]),n=this.getTargetSeries(e,s,r);this.addInner(s,r,n),this.canLoadMoreData=!0,this.initialNotification=!0}else{this.isEmpty=!0;let e=f$(ag.Close,(e,t)=>null,t),i=f$(ag.Close,(e,t)=>null,t),s=f$(this.target,(e,t)=>null,t);this.addInner(e,i,s),this.canLoadMoreData=!1}}get baseIndex(){return+!this.isEmpty}getSeries(e,t){let i=e.duplicate();return i.symbol=t,Sp().getTimeSeriesDataSource().getTimeSeries(i)}shouldTriggerOurRecalc(e){return!!super.shouldTriggerOurRecalc(e)||e!==this.innerSeries[0]&&(e===this.innerSeries[1]||e===this.innerSeries[2])&&this.innHasData(1)&&this.innHasData(2)}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[1].canLoadMoreData||!this.innerSeries[2].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),await this.innerSeries[2].loadMoreData(e),this.isLoading=!1}getWrappers(){return[this.wrapInner(this.target,3)]}}let p2=cm("_INN_HL_ACC_IX"),p3=new nw;class p4 extends cg{isWeekly=!1;constructor(e,t){if(super(e,t),t instanceof uJ)this.canLoadMoreData=!1;else{let s="PriceIndex"===this.inputs.Source?"$MADX":"$FADX",r=this.getSeries(t.query,s);if(this.addInner(r),this.isWeekly=e.aggregation.unit===G.Week,this.isWeekly){var i;let e=(i=this.getSeries(t.query,s,p3),new p4({aggregation:p3,source:null,target:p2,outFields:[p2],inputs:{...this.inputs}},i));this.addInner(e)}this.canLoadMoreData=!0,this.initialNotification=!0}}getSeries(e,t,i){let s=e.duplicate();return s.symbol=t,i&&(s.aggregation=i,s.barsToFetch=15*tz.US_TRADING_DAYS_PER_YEAR),Sp().getTimeSeriesDataSource().getTimeSeries(s)}get baseIndex(){return 1}calculateAt(e){if(this.isWeekly)return this.calculateAtWeekly(e);let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,ag.Close);ey(s)&&(t=em(s))}return{[this.target.id]:t}}calculateAtWeekly(e){let t=this.container?.size??-1,i=null,s=this.innCont(2);if(t>0&&e===t-1)i=s.getLastDataPoint(p2);else{let t=this.container.getTimeData()[e],r=s.getTimeData(),n=e_(r,t),a=r[n],o=null;for(;n<s.size&&nb(t,a);)o=n,n+=1,a=r[n];null!==o&&(i=s.getData(p2)[o])}return{[this.target.id]:i}}shouldTriggerOurRecalc(e){return!!super.shouldTriggerOurRecalc(e)||e!==this.innerSeries[0]&&e===this.innerSeries[1]&&this.innHasData(1)}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[1].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}}let p5=cm("_RSI1"),p6=cm("_RSI1_MOM"),p7=cm("_RSI2"),p8=cm("_RSI2_MA"),p9=cm("_MUL_ATR");class fe extends cg{constructor(e,t){super(e,cf(t,t=>{let i=Sp().getTimeSeriesDataSource();return t.seriesKind=J.Options,t.fields=e.outFields,i.getTimeSeries(t)})),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return this.outFields.map(e=>this.wrapInner(e,0))}}let ft=cm("_CORE");class fi extends uZ{constructor(e){super(e)}getRetriever(){return tg(this.query.symbol)?new fn:tP(this.query.symbol)?new fa:new fr}}function fs(){return new l8([ag.DateTime,ag.Delta,ag.Gamma,ag.Theta,ag.Vega])}class fr{supportsChunks;constructor(){this.supportsChunks=!1}async retrieve(e){return fs()}}class fn extends uT{emptyContainer(e,t){return fs()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(ag.DateTime,l2(e.date.substring(0,10))),i.addDataPoint(ag.Delta,e.delta),i.addDataPoint(ag.Gamma,e.gamma),i.addDataPoint(ag.Theta,e.theta),i.addDataPoint(ag.Vega,e.vega)}}class fa extends uT{emptyContainer(e,t){return fs()}addExtraParams(e){e.fields="delta,gamma,theta,vega"}get iterateForward(){return!0}getPageName(){return"getEquityOptionsHistory"}processRow(e,t,i){i.addDataPoint(ag.DateTime,l2(e.date)),i.addDataPoint(ag.Delta,e.delta),i.addDataPoint(ag.Gamma,e.gamma),i.addDataPoint(ag.Theta,e.theta),i.addDataPoint(ag.Vega,e.vega)}}let fo=cm("_RSI1"),fl=cm("_RSI2"),fu=cm("_ANCHR"),fh=cm("_HH_N"),fc=cm("_LL_N"),fd=cm("_HH_H1"),fp=cm("_LL_H1"),ff=cm("_HH_H2"),fm=cm("_LL_H2"),fg=cm("_MIDPOINT"),fy=cm("_VALUE");class fS extends cg{constructor(e,t){super(e,t),fj(this)}computeMidranks(e){let t=e.length,i=e.map((e,t)=>({v:e,i:t}));i.sort((e,t)=>e.v-t.v);let s=Array(t),r=0;for(;r<t;){let e=r,n=i[r].v;for(;e+1<t&&i[e+1].v===n;)e++;let a=(r+1+(e+1))/2;for(let t=r;t<=e;t++)s[i[t].i]=a;r=e+1}return s}pearsonCorrelation(e){let t=e.length;if(t<2)return null;let i=(t+1)/2,s=0;for(let i=0;i<t;i++)s+=e[i];let r=s/t,n=0,a=0,o=0;for(let s=0;s<t;s++){let t=s+1-i,l=e[s]-r;n+=t*l,a+=t*t,o+=l*l}let l=Math.sqrt(a*o);return 0===l?null:n/l}calculateAt(e){let t=null,i=this.period,[,s]=fK(this);if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);if(r.every(e=>null!==e)){let e=this.computeMidranks(r),i=this.pearsonCorrelation(e);null!==i&&(t=100*i)}}return{[ag.RCI.id]:t}}}let fA=cm("_ATR");var fT=((D=fT||{})[D.Uninitialized=0]="Uninitialized",D[D.UpLeg=1]="UpLeg",D[D.DownLeg=-1]="DownLeg",D);let fv={_TR:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=this.baseVal(ag.High,e),s=this.baseVal(ag.Low,e);if(e>0){let r=this.baseVal(ag.Close,e-1);t=Math.max(i-s,Math.abs(i-r),Math.abs(s-r))}else t=i-s;return{[this.target.id]:t}}},_RSI:class extends cg{isModified;constructor(e,t){super(e,t);let i=e.inputs.Modified;this.isModified=i}get helpers(){return[cN,cV]}gain(e,t){return t[e]>t[e-1]?t[e]-t[e-1]:0}loss(e,t){return t[e]<t[e-1]?t[e-1]-t[e]:0}calculateAt(e){let t=null,i=null,s=null,r=this.period;if(this.atLeast(e,r+1)){if(null===this.container.getData(this.target)[e-1]||this.isModified){let t=this.past(e,r+1,this.source);if(ey(t)){let e=eS(1,r),n=e.map(e=>this.gain(e,t)),a=e.map(e=>this.loss(e,t));i=eg(n),s=eg(a)}}else{let t=this.container.getData(cN)[e-1],n=this.container.getData(cV)[e-1],a=this.past(e,2,this.source),o=this.gain(1,a),l=this.loss(1,a);i=(t*(r-1)+o)/r,s=(n*(r-1)+l)/r}null!==i&&null!==s&&(t=100-100/(1+i/s))}return{[cN.id]:i,[cV.id]:s,[this.target.id]:t}}},MA:cA,MAEXP:class extends cT{constructor(e,t){super(e,t,e=>2/(e+1))}},MAHLC:class extends cg{constructor(e,t){super(e,t);let i=f_(t,this.inputs.Period1,ag.High,ag.MAHI),s=f_(t,this.inputs.Period2,ag.Low,ag.MALO);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.MAHI,1),this.wrapInner(ag.MALO,2)]}},VOL:class extends cv{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(ag.Volume,ag.TradeSize,ag.Change,ag.Open,ag.Close)}},MAENV:class extends cE{constructor(e,t){super(e,cP,t)}},MAENVEXP:class extends cE{constructor(e,t){super(e,cC,t)}},MAENVSMO:class extends cE{constructor(e,t){super(e,cb,t)}},MATRI:class extends cg{constructor(e,t){super(e,t);let i=f_(t,this.inputs.Period,this.source),s=f_(i,this.inputs.Period,ag.MA,ag.TMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.TMA,2)]}},MAWEI:class extends cg{triangle;constructor(e,t){super(e,t);let i=this.period;this.triangle=i*(i+1)/2,fj(this)}weightedAverage(e){let t=e.length;if(0===t)return null;let i=t===this.period?this.triangle:t*(t+1)/2;return e.reduce((e,t,i)=>e+t*(i+1),0)/i}calculateAt(e){let t=null,i=this.period,[,s]=fK(this);if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=this.weightedAverage(r.filter(ef)):ey(r)&&(t=this.weightedAverage(r))}return{[this.target.id]:t}}},MAVOL:cA,MASMO:class extends cT{constructor(e,t){super(e,t,e=>1/e)}},MACD:class extends cR{constructor(e,t){super(e,c_,t)}},MACDEXP:class extends cR{constructor(e,t){super(e,cM,t)}},MACDV:class extends cw{constructor(e,t){super(e,t),this.histogramVaryColor=!0,this.histogramField=ag.MACDVH;let i=fJ(e,"EMA","Average"),s=i(t,e.inputs.Period1,e.source,void 0),r=i(t,e.inputs.Period2,e.source,void 0),n=fV(t,e.inputs.Period2,e.inputs.Average),a=fG(ag.MACDV,(e,t,i,s)=>(t-i)/s*100,s,r,n),o=i(a,e.inputs.Period3,a.target,ag.MACDVS),l=fG(ag.MACDVH,fz,a,o);this.addInner(a,o,l)}getWrappers(){return[this.wrapInner(ag.MACDV,1),this.wrapInner(ag.MACDVS,2),this.wrapInner(ag.MACDVH,3)]}},GMMA:class extends cg{constructor(e,t){super(e,t);for(let r=1;r<=12;++r){var i,s;let n=(i=e.inputs,s=r,i[`Period${s}`]);this.addInner(fM(t,n,ag.Close,e.outFields[r-1]))}}getWrappers(){return eS(1,12).map(e=>this.wrapInner(this.outFields[e-1],e))}},OSCI:cL,OSCIVOL:cL,RSI:class extends cH{constructor(e,t){super(e,!1,t)}},RSIMOD:class extends cH{constructor(e,t){super(e,!0,t)}},RSISTO:class extends cg{constructor(e,t){super(e,t);let i=fB(t,this.inputs.Period,this.source),s=this.inputs.Range,r=f$(ag.STORSI,function(e){let t=null;if(this.atLeast(e,s)){let i=this.past(e,s,ag.RSI,this.base),r=eM(i),n=r[0],a=r[1];t=(eC(i)-n)/(a-n)}return{[ag.STORSI.id]:t}},i),n=fJ(e,"MA","Average")(r,this.inputs.PeriodAvg,ag.STORSI,ag.STORSIAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(ag.STORSI,1),this.wrapInner(ag.STORSIAVG,2)]}},RSA:class extends cg{constructor(e,t){super(e,t);let i=fB(t,this.inputs.Period1,this.source,fo),s=fB(t,this.inputs.Period2,this.source,fl),r=fG(ag.RSA,(e,t,i)=>(t+i)/2,i,s),n=fJ(e,"MA","Average")(r,this.inputs.PeriodAvg,ag.RSA,ag.RSAAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(ag.RSA,1),this.wrapInner(ag.RSAAVG,2)]}},WPERCR:class extends cB{constructor(e,t){super(e,!0,t)}},HHLL:class extends cg{constructor(e,t){super(e,t);let i=fO(t,this.inputs.Period1,ag.High,ag.HH,!0),s=fO(t,this.inputs.Period2,ag.Low,ag.LL,!1);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.HH,1),this.wrapInner(ag.LL,2)]}},WGCL:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,[i,s,r]=[ag.Close,ag.High,ag.Low].map(t=>this.baseVal(t,e));return t=(2*i+s+r)/4,{[this.target.id]:t}}},STOCHF:class extends cW{constructor(e,t){super(e,!1,ag.PercK,t)}},STOCHS:class extends cW{constructor(e,t){super(e,!0,ag.PercK,t)}},BBANDS:class extends c${constructor(e,t){super(e,"Regular",t)}},BWIDTH:class extends c${constructor(e,t){super(e,"Width",t)}},BPERC:class extends c${constructor(e,t){super(e,"Percent",t)}},OBVOL:class extends cg{constructor(e,t){super(e,t);let i=f$(ag.OBVOL,function(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Volume,e),r=this.baseVal(ag.Close,e-1),n=this.container.getData(this.target)[e-1];eF(n)||(n=0),t=i>r?n+s:i<r?n-s:n}return{[this.target.id]:t}},t),s=fJ(e,"MA","Average")(i,this.period,ag.OBVOL,ag.OBVOLAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.OBVOL,1),this.wrapInner(ag.OBVOLAVG,2)]}},ATR:class extends cg{constructor(e,t){super(e,t);let i=fN(t,ag.TR),s=fJ(e,"SMA")(i,this.inputs.Period,ag.TR,this.target),r=f_(s,this.inputs.Period2,ag.ATR,ag.ATRMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(this.target,1),this.wrapInner(ag.ATRMA,2)]}},ATRP:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period,e.inputs.Smoothing);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(1,ag.ATR,e),s=this.baseVal(ag.Close,e);return eF(i,s)&&s>0&&(t=i/s*100),{[ag.ATRP.id]:t}}},ADX:class extends cQ{constructor(e,t){super(e,!1,ag.ADX,t)}},ADXMOD:class extends cQ{constructor(e,t){super(e,!0,ag.ADXM,t)}},ADL:class extends cg{constructor(e,t){super(e,t);let i=fk(t);this.addInner(i)}calculateAt(e){let t=null;return t=(e>0?this.container.getData(this.target)[e-1]:0)+this.innVal(1,ag.MFMUL,e),{[this.target.id]:t}}},ADWM:class extends cg{constructor(e,t){super(e,t);let i=f$(ag.ADWM,function(e){let t=null,i=null;if(e>0){let s=this.baseVal(ag.Close,e-1),r=Math.max(s,this.baseVal(ag.High,e)),n=Math.min(s,this.baseVal(ag.Low,e)),a=this.baseVal(ag.Close,e);t=a>s?a-n:a<s?a-r:0,e>1&&(i=(e>2?this.container.getData(ag.ADWM)[e-1]:0)+t)}return{[ag.ADWM.id]:i}},t),s=f_(i,this.inputs.Period,ag.ADWM,ag.ADWMMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.ADWM,1),this.wrapInner(ag.ADWMMA,2)]}},CHAOSC:class extends cg{constructor(e,t){super(e,t);let i=ag.ADL,s=function(e,t=ag.ADL){return fb("ADL",fC(t),e)}(t,i),r=fM(s,3,i),n=fM(s,10,i),a=fG(e.target,(e,t,i)=>t-i,r,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},TP:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null;return t=eg([ag.Close,ag.High,ag.Low].map(t=>this.baseVal(t,e))),{[this.target.id]:t}}},KELCHN:class extends c8{constructor(e,t){super(e,c6,t)}},KELBND:class extends c8{constructor(e,t){super(e,c7,t)}},DONCHN:class extends c9{constructor(e,t){super(e,!1,t)}},DONWIDTH:class extends c9{constructor(e,t){super(e,!0,t)}},PVT:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Volume,e),r=this.baseVal(ag.Close,e-1),n=this.container.getData(this.target)[e-1];eF(n)||(n=0),t=n+(i-r)/r*s}return{[this.target.id]:t}}},ROC:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i+1)){let s=this.baseVal(this.source,e-i);null!==s&&0!==s&&(t=(this.baseVal(this.source,e)-s)/s*100)}return{[this.target.id]:t}}},TRIX:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,this.source),s=fM(i,this.inputs.Period,i.target),r=fM(s,this.inputs.Period,s.target),n=fF(r,1,r.target,this.target);this.addInner(n)}getWrappers(){return[this.wrapInner(this.target,1)]}},PPMOV:class extends cg{constructor(e,t){super(e,t);let i=fH(t,ag.PVPT);this.addInner(i)}calculateAt(e){let t=this.innVal(1,ag.PVPT,e),i=this.baseVal(ag.High,e),s=this.baseVal(ag.Low,e);return{[ag.PVPTR.id]:t+i-s,[ag.PVPTS.id]:t-i+s}}getWrappers(){return[this.wrapInner(ag.PVPT,1)]}},PIVPTS:class extends dH{constructor(e,t){super(e,dV[e.inputs.Previous],t)}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=null;if(!this.disabled){let e=this.getValues(this.inputs.Previous);if(ey(e)){let[l,u,h]=e,c=2*(t=(l+u+h)/3);i=c-u,s=c-l;let d=l-u;r=t+d,n=t-d,a=l+2*(t-u),o=u-2*(l-t)}}return{[ag.PPTPIV.id]:t,[ag.PPTR1.id]:i,[ag.PPTR2.id]:r,[ag.PPTR3.id]:a,[ag.PPTS1.id]:s,[ag.PPTS2.id]:n,[ag.PPTS3.id]:o}}},CPP:class extends dH{constructor(e,t){super(e,dV.Day,t)}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=null,l=null;if(!this.disabled){let e=this.getValues("Day");if(ey(e)){let[u,h,c]=e,d=u-h,[p,f,m,g]=[2,4,6,12].map(e=>1.1/e*d);o=c+p,n=c+f,s=c+m,t=c+g,i=c-g,r=c-m,a=c-f,l=c-p}}return{[ag.CPPH4.id]:o,[ag.CPPH3.id]:n,[ag.CPPH2.id]:s,[ag.CPPH1.id]:t,[ag.CPPL1.id]:i,[ag.CPPL2.id]:r,[ag.CPPL3.id]:a,[ag.CPPL4.id]:l}}},ARNUPDW:class extends di{constructor(e,t){super(e,!1,t)}},ARNOSC:class extends di{constructor(e,t){super(e,!0,t)}},TCHN:class extends cg{constructor(e,t){super(e,t);let i="Close"===e.inputs.Range,s=f1(t);if(!i&&s){let e=f$(ag.TCHNUP,(e,t)=>null,t),i=f$(ag.TCHNLOW,(e,t)=>null,t);this.addInner(e,i)}else{let s=fO(t,e.inputs.PeriodUpper,i?ag.Close:ag.High,ag.TCHNUP,!0),r=fO(t,e.inputs.PeriodLower,i?ag.Close:ag.Low,ag.TCHNLOW,!1);this.addInner(s,r)}}getWrappers(){return[this.wrapInner(ag.TCHNUP,1),this.wrapInner(ag.TCHNLOW,2)]}},TCHRE:class extends cg{constructor(e,t){super(e,t);let i=function(e,t,i){let s="TCHN",r=fE(s);return fb(s,{inputs:{PeriodUpper:t,PeriodLower:t,Range:i},outFields:r,source:null},e)}(t,e.inputs.Period,e.inputs.Range);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(1,ag.TCHNUP,e),s=this.innVal(1,ag.TCHNLOW,e),r=this.inputs.Adjustment,n=this.inputs.Retracement;return"Long"===n?t=eF(i)?i-r:null:"Short"===n&&(t=eF(s)?s+r:null),{[this.target.id]:t}}},ALLG:class extends cg{constructor(e,t){super(e,t);let i=f$(ds,eh(c1,ds),t),s=fx(i,e.inputs.Period1,ds,ag.ALJAW),r=fx(i,e.inputs.Period2,ds,ag.ALTEETH),n=fx(i,e.inputs.Period3,ds,ag.ALLIPS);this.addInner(s,r,n)}calculateAt(e){return{[ag.ALJAW.id]:this.innVal(1,ag.ALJAW,e),[ag.ALTEETH.id]:this.innVal(2,ag.ALTEETH,e),[ag.ALLIPS.id]:this.innVal(3,ag.ALLIPS,e)}}},PLTLN:class extends cg{constructor(e,t){super(e,t)}calculateAt(e){return{[ag.PLTLN.id]:this.inputs.Position}}},AWEOSC:class extends cg{constructor(e,t){super(e,t);let i=f$(dr,eh(c1,dr),t),s=f_(i,this.inputs.Period1,dr),r=f_(i,this.inputs.Period2,dr),n=fG(ag.AWOS,(e,t,i)=>t-i,s,r),a=f_(n,this.inputs.Period3,n.target,ag.AWOSMA);this.addInner(n,a)}getWrappers(){return[this.wrapInner(ag.AWOS,1),this.wrapInner(ag.AWOSMA,2)]}},MFV:class extends dn{constructor(e,t){super(e,!0,t)}},CLV:class extends dn{constructor(e,t){super(e,!1,t)}},CHAMF:class extends cg{constructor(e,t){super(e,t);let i=fk(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,ag.Volume),r=this.past(e,i,ag.MFMUL,this.innCont(1));if(ey(s)&&ey(r)){let e=em(s);0!==e&&(t=em(r)/e)}}return{[this.target.id]:t}}},CHAVOL:class extends cg{constructor(e,t){super(e,t);let i=fF(fM(f$(da,eh(c2,da),t),this.inputs.Period1,da),this.inputs.Period2,ag.EMA,this.target);this.addInner(i)}getWrappers(){return[this.wrapInner(this.target,1)]}},DPO:class extends cg{shift;constructor(e,t){super(e,t);let i=this.inputs.Period;this.shift=Math.floor(i/2)+1;let s=f_(t,i,e.source);this.addInner(s)}calculateAt(e){let t=null,i=this.shift,s=this.innVal(1,ag.MA,e-i);return null!==s&&(t=this.baseVal(this.source,e)-s),{[this.target.id]:t}}},CCI:class extends cg{constructor(e,t){super(e,t);let i=fH(t),s=f_(i,this.inputs.Period,i.target,dl);this.addInner(i,s)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,ag.TP,this.innCont(1));if(ey(s)){let i=this.innVal(2,dl,e);if(null!==i){let r=s.reduce((e,t,s)=>e+Math.abs(i-t),0)/this.period;t=(this.innVal(1,ag.TP,e)-i)/(.015*r)}}}return{[this.target.id]:t}}},EMV:class extends cg{constructor(e,t){super(e,t);let i=f$(ag.EMV,function(e){let t=null;if(e>0){let[i,s,r]=[ag.High,ag.Low,ag.Volume].map(t=>this.baseVal(t,e)),[n,a]=[ag.High,ag.Low].map(t=>this.baseVal(t,e-1));t=((i+s)/2-(n+a)/2)/(r/1e6/(i-s))}return{[this.target.id]:t}},t),s=f_(i,this.inputs.Period,ag.EMV,ag.EMVMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.EMV,1),this.wrapInner(ag.EMVMA,2)]}},ERBRPOW:class extends du{constructor(e,t){super(e,!1,t)}},ERBLPOW:class extends du{constructor(e,t){super(e,!0,t)}},FI:class extends cg{constructor(e,t){super(e,t);let i=fM(f$(dh,function(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Volume,e);t=(i-this.baseVal(ag.Close,e-1))*s}return{[this.target.id]:t}},t),this.inputs.Period,dh,ag.FI);this.addInner(i)}getWrappers(){return[this.wrapInner(ag.FI,1)]}},MI:class extends cg{constructor(e,t){super(e,t);let i=fM(f$(dc,eh(c2,dc),t),9,dc,dd),s=fM(i,9,dd,dp),r=fG(df,(e,t,i)=>t/i,i,s);this.addInner(r)}calculateAt(e){let t=null;if(this.atLeast(e,25)){let i=this.past(e,25,df,this.innCont(1));ey(i)&&(t=em(i))}return{[this.target.id]:t}}},MOM:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=f$(ag.MOM,ec(fX,i,ag.Close),t),r=f_(s,this.inputs.Movement,ag.MOM,ag.MOMMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(ag.MOM,1),this.wrapInner(ag.MOMMA,2)]}},MFI:class extends cg{constructor(e,t){super(e,t);let i=fH(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period+1;if(this.atLeast(e,i)){let s=this.past(e,i,ag.TP,this.innCont(1)),r=this.past(e,i,ag.Volume).map(e=>null!=e?e:0);if(ey(s)&&ey(r)){let e=0,n=0;for(let t=1;t<i;++t){let i=s[t]*r[t];s[t]>s[t-1]?e+=i:n+=i}t=100-100/(1+e/n)}}return{[this.target.id]:t}}},MSD:class extends cg{constructor(e,t){super(e,t),fj(this);let i=f_(t,this.inputs.Period,this.source);this.addInner(i)}calculateAt(e){let t=null,[i,s]=fK(this),r=this.innVal(i+1,ag.MA,e);if(null!==r){let i=this.inputs.Period,n=this.past(e,i,this.source,s);t=Math.sqrt(eg(n=n.map(e=>(e-r)*(e-r))))}return{[this.target.id]:t}}getWrappers(){let[e]=fK(this);return[this.wrapInner(ag.MA,e+1)]}},NVI:class extends dy{constructor(e,t){super(e,dg,t)}},PVI:class extends dy{constructor(e,t){super(e,dm,t)}},PPO:class extends cR{constructor(e,t){super(e,cD,t)}},PVO:class extends cR{constructor(e,t){super(e,cO,t)}},HV:class extends cg{constructor(e,t){super(e,t);let i=Math.sqrt(f0(e.aggregation));if(0===i){let e=f$(this.target,(e,t)=>null,t);this.addInner(e)}else{let s=fW(f$(dS,eh(function(e,t){let i=null;if(t>0){let s=this.baseVal(e,t),r=this.baseVal(e,t-1);null!==s&&null!==r&&(i=Math.log(s/r))}return{[dS.id]:i}},ag.Close),t),e.inputs.Period,dS,ag.MSD),r=f$(ag.HV,eh(function(e,t){let i=null,s=this.baseVal(ag.MSD,t);return null!==s&&(i=100*s*e),{[ag.HV.id]:i}},i),s);this.addInner(r)}}getWrappers(){return[this.wrapInner(this.target,1)]}},PERF:class extends cg{noOp;constructor(e,t){super(e,t);let i="VisibleStart"===this.inputs.Anchor;this.noOp=i}calculateAt(e){let t=null,i=this.baseVal(this.source,0),s=this.baseVal(this.source,e);return this.noOp?t=s:null!==i&&null!==s&&(t=(s-i)/i*100),{[this.target.id]:t}}},WASI:class extends cg{constructor(e,t){super(e,t)}get helpers(){return[dA]}ohlcVals(e){return[ag.Open,ag.High,ag.Low,ag.Close].map(t=>this.baseVal(t,e))}obtainR(e,t,i,s){let r=Math.abs(e-s),n=Math.abs(t-s),a=Math.abs(e-t),o=Math.max(r,n,a),l=.25*Math.abs(s-i);return o===r?r-.5*n+l:o===n?n-.5*r+l:a+l}calculateAt(e){let t=null,i=null;if(e>0){let s=this.container.getData(dA)[e-1];eF(s)||(s=0);let[r,n,a,o]=this.ohlcVals(e),[l,u,h,c]=this.ohlcVals(e-1);if(ey([r,n,a,o,l,c])){let e=Math.max(Math.abs(n-c),Math.abs(a-c)),u=this.inputs.Limit,h=this.obtainR(n,a,l,c);i=s+(t=(o-c+.5*(o-r)+.25*(c-l))/h*50*(e/u))}}return{[dA.id]:t,[this.target.id]:i}}},WWVOL:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period);this.addInner(i)}get helpers(){return[dv,dT]}calculateAt(e){let t=null,i=null,s=null,r=null,n=this.innVal(1,ag.ATR,e);if(null!==n){let a=this.baseVal(ag.Close,e),o=this.baseVal(ag.Close,e-1),l=this.period;s=Math.max(...this.past(e,l,ag.Close)),r=Math.min(...this.past(e,l,ag.Close));let u=n*this.inputs.Constant;if(null===this.innVal(1,ag.ATR,e-1))a>o?t=s-u:i=r+u;else{let[n,o,l,h]=[ag.WWVSARU,ag.WWVSARD,dv,dT].map(t=>this.container.getData(t)[e-1]);s=l,r=h,null!==n?a<n?(r=a,i=a+u):t=(s=Math.max(a,s))-u:a>o?(s=a,t=a-u):i=(r=Math.min(a,r))+u}}return{[dv.id]:s,[dT.id]:r,[ag.WWVSARU.id]:t,[ag.WWVSARD.id]:i}}},PARTP:class extends cg{constructor(e,t){super(e,t)}get helpers(){return[dP,dC,db]}hlcVals(e){return[ag.High,ag.Low,ag.Close].map(t=>this.baseVal(t,e))}me(e,t){return this.container.getData(e)[t]}reciprocal(e){return 1/e}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null;if(e>0){let[o,l,u]=this.hlcVals(e),[h,c,d]=this.hlcVals(e-1),p=this.reciprocal(this.inputs.Acceleration),f=this.reciprocal(this.inputs.Limit);if(1===e){let e=1==(n=u>d?1:-1);a=e?c:h,s=e?Math.max(o,h):Math.min(l,c),r=p,e?t=a:i=a}else{let[u,d,m,g,y]=[db,ag.PARSARS,ag.PARSARL,dP,dC].map(t=>this.me(t,e-1)),S=1===u,A=S?m:d,T=y*Math.abs(g-A),v=u===(n=S?A+T>l?-1:1:A-T<o?1:-1);a=v?S?Math.min(A+T,c,this.baseVal(ag.Low,e-2)):Math.max(A-T,h,this.baseVal(ag.High,e-2)):g,s=v?S?Math.max(o,g):Math.min(l,g):1===n?o:l,r=y,v?(S?s>g:s<g)&&y<f&&(r=y+p):r=p,1===n?t=a:i=a}}return{[dP.id]:s,[dC.id]:r,[db.id]:n,[ag.PARSARS.id]:i,[ag.PARSARL.id]:t}}},MOVLR:class extends cg{xSum;xSum2;x2Sum;constructor(e,t){super(e,t);let i=this.period;this.xSum=i*(i+1)/2,this.xSum2=this.xSum*this.xSum,this.x2Sum=i*(i+1)*(2*i+1)/6}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,this.source);if(ey(s)){let e=em(s),r=(i*em(s.map((e,t)=>e*(t+1)))-this.xSum*e)/(i*this.x2Sum-this.xSum2);t=(e-r*this.xSum)/i+r*i}}return{[this.target.id]:t}}},TRSP:class extends cg{haveEnoughData=!1;firstUsefulIndex=0;s3;itr;constructor(e,t){super(e,t),this.s3=this.itr=[];let i=["VelocityUpTrend","VelocitySideTrend","VelocityDownTrend"].map(t=>e.inputs[t]||"3").map(Number);dL.splice(6,3,...i)}get helpers(){return[dE]}prepareComputation(){let e=this.base.getData(ag.Close),t=0,i=0,s=e.length;for(;i<72&&t<s;)null!=e[t]&&i++,t++;this.haveEnoughData=t<s,this.firstUsefulIndex=t,this.s3=d_(s),this.itr=d_(s),this.haveEnoughData&&dx(e,this.s3,s)}us(e,t){return this.container.getData(e)[t]}recalculateAt(e,t,i){let s=this.base.getData(ag.Close),r=s.length;this.haveEnoughData&&dx(s,this.s3,r),super.recalculateAt(e,t,i)}calculateAt(e){let t=null,i=null,s=null,r=t=>this.us(t,e-1);if(0===e)this.prepareComputation();else if(this.haveEnoughData&&e>=this.firstUsefulIndex&&null!==this.baseVal(ag.Close,e)){let n=r(ag.TRSP1),a=r(ag.TRSP2);s=r(dE),null===n&&null===a&&(n=a=this.baseVal(ag.Close,this.firstUsefulIndex)),null===s&&(s=1);let o=this.base.getData(ag.Close);s=function(e,t,i,s,r,n){let a=i;do a--;while(e[a]<=0)return t[i]=t[a],e[i]>r&&t[a]<=0&&(t[i]=t[a]+1),e[i]<s&&t[a]>=0&&(t[i]=t[a]-1),n++,t[i]!==t[a]&&(n=1),n}(o,this.itr,e,n,a,s);let l=function(e,t,i,s,r){let n=s,a=dM(r,i[s],7),o=0;do e[--n]>0&&o++;while(o<a&&n>0)return t[s]-t[n]}(o,this.s3,this.itr,e,dL),u=function(e,t,i,s,r){let n=r[18],a=s+1,o=0;for(let i=0;i<n;++i){let i=0,s=0;for(let r=1;r<6;++r){if(e[--a]<=0)continue;let n=e[a]-t[a];1==r&&(i=s=n),n>i&&(i=n),n<s&&(s=n)}o=o+i-s}return o/n*dM(r,i[s],4)}(o,this.s3,this.itr,e,dL);[n,a]=function(e,t,i,s,r,n,a,o,l,u){let h=dM(r,i[s],10),c=dM(r,i[s],13),d=dM(r,i[s],16),p=l+u+t[s]-e[s],f=100;r[20]>0&&(f=r[20]);let m=h*o/f;o>c&&(m=h*c/f);let g=2*u,y=e[s]+(p-g)-(p-g)*m,S=e[s]+(p-p*m),A=[n,a];return(1===o||1!==d||y>n)&&(A[0]=y),(1===o||1!==d||S<a)&&(A[1]=S),A}(o,this.s3,this.itr,e,dL,n,a,s,l,u),this.itr[e]>=0&&(t=n),this.itr[e]<=0&&(i=a)}return{[dE.id]:s,[ag.TRSP1.id]:t,[ag.TRSP2.id]:i}}},COTLC:dN,COTDAG:class extends dD{constructor(e,t){super(e,2,t)}},COTFTR:class extends dD{constructor(e,t){super(e,3,t)}},IMPVOL:class extends cg{constructor(e,t){super(e,cf(t,e=>new dF(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(ag.IMPVOL,0)]}},CTM:class extends cR{constructor(e,t){e.inputs={Period1:5,Period2:21,Period3:34},super(e,cx,t)}},CPMI:class extends cR{constructor(e,t){e.inputs={Period1:3,Period2:5,Period3:8},super(e,cI,t)}},DEMA:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,this.source),s=fM(i,this.inputs.Period,i.target),r=fG(ag.DEMA,(e,t,i)=>2*t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(ag.DEMA,1)]}},TEMA:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,this.source),s=fM(i,this.inputs.Period,i.target),r=fM(s,this.inputs.Period,s.target),n=fG(ag.TEMA,(e,t,i,s)=>3*(t-i)+s,i,s,r);this.addInner(n)}getWrappers(){return[this.wrapInner(ag.TEMA,1)]}},TSI:class extends cg{constructor(e,t){super(e,t);let i=(e,t,i,s,r,n)=>{let a=fM(e,t,i,s);return fM(a,r,s,n)},s=f$(d$,eh((e,t)=>({[e.id]:Math.abs(this.baseVal(ag.Change,t))}),d$),t),r=i(t,e.inputs.Period1,ag.Change,dG,e.inputs.Period2,dz),n=i(s,e.inputs.Period1,d$,dY,e.inputs.Period2,dj),a=fG(ag.TSI,(e,t,i)=>100*t/i,r,n),o=fM(a,e.inputs.Period3,ag.TSI,ag.TSISIG);this.addInner(a,o)}getWrappers(){return[this.wrapInner(ag.TSI,1),this.wrapInner(ag.TSISIG,2)]}},ADJATR:class extends cg{constructor(e,t){super(e,t);let i=(e,t)=>{let i=0;return t>0&&(i=this.baseVal(e,t)-this.baseVal(e,t-1)),{[cG.id]:Math.abs(i)}},s=f$(cG,eh(i,this.source),t),r=fJ(e,"MA")(s,this.inputs.Period,cG,cz),n=fG(ag.ADJATR,(e,t)=>2*t,r);this.addInner(n)}getWrappers(){return[this.wrapInner(ag.ADJATR,1)]}},COTR:class extends cg{constructor(e,t){super(e,t);let i=e=>{let t=0;return e>0&&(t=this.baseVal(ag.Close,e)-this.baseVal(ag.Close,e-1)),{[cY.id]:t}},s=f$(cY,i,t),r=fQ[e.inputs.TypeOfATR.toLowerCase()],n=r(t,this.inputs.Period,this.inputs.Smoothing),a=fG(this.target,(e,t,i)=>eF(t)&&eF(i)?t/i:null,s,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCGD:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period,ag.Close);this.addInner(i)}calculateAt(e){let t=null,i=e>0?this.container.getData(this.target)[e-1]:null,s=this.innVal(1,ag.EMA,e);if(eH(i)){let r=this.baseVal(this.source,e),n=Math.pow(r/i,4);t=i+(r-i)/(.6*this.period*n);let a=e=>Math.log10(Math.abs(e-t))>1,o=a(i)||a(s);(!Number.isFinite(t)||o)&&(t=null)}else t=s;return{[this.target.id]:t}}},HMA:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=Math.floor(i/2),r=this.allowEmptyValues,n=fI(t,s,this.source,ag.WMA,r),a=fG(dK,(e,t,i)=>2*t-i,n,fI(t,i,this.source,ag.WMA,r)),o=fI(a,Math.floor(Math.sqrt(i)),dK,this.target,r);this.addInner(o)}getWrappers(){return[this.wrapInner(this.target,1)]}},COPP:class extends cg{constructor(e,t){super(e,t);let i=fF(t,this.inputs.PeriodRocLong),s=fI(fG(dq,(e,t,i)=>t+i,i,fF(t,this.inputs.PeriodRocShort)),this.inputs.PeriodWma,dq,this.target);this.addInner(s)}getWrappers(){return[this.wrapInner(this.target,1)]}},REATRS:class extends cg{constructor(e,t){super(e,t);let i="Close"===e.inputs.TurtleChnField,s="Long"===e.inputs.Direction,r=f1(t);if(!i&&r){let e=f$(this.target,(e,t)=>null,t);this.addInner(e)}else{let e=(e,t)=>({[dX.id]:t>0?e*Math.abs(this.baseVal(ag.Change,t)):null}),r=f_(f$(dX,eh(e,this.inputs.FactorATR),t),this.inputs.PeriodAdjATR,dX,ag.MA),n=s?ag.High:ag.Low,a=fO(t,this.inputs.PeriodTurtleChn,i?ag.Close:n,dZ,s),o=fG(dJ,(e,t)=>this.inputs.FactorAdjATR*t,r),l=s?-1:1,u=fG(this.target,(e,t,i)=>t+l*i,a,o);this.addInner(u)}}getWrappers(){return[this.wrapInner(this.target,1)]}},LINRCHN:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=f$(ag.LINRMID,eh(function(e,t){let i=null;if(t>=this.base.size-e){let s=e*(e+1)/2,r=0,n=0,a=1;for(let t=e-1;t>=0;--t){let e=this.baseVal(ag.Close,this.base.size-1-t);r+=e,n+=a*e,a+=1}let o=(e*n-s*r)/(e*(e+1)*(2*e+1)/6*e-s*s);i=r/e-o*s/e+o*(t-this.base.size+e+1)}return{[ag.LINRMID.id]:i}},i),t),r=fW(fG(dQ,(e,t,i)=>t-i,f$(this.source,function(e){return{[this.target.id]:this.baseVal(this.target,e)}},t),s),i,dQ);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,ag.LINRMID,e),i=eC(this.innCont(2).getData(ag.MSD)),s=null,r=null;if(eF(t,i)){let e=this.inputs.Width;s=t+e*i,r=t-e*i}return{[ag.LINRUP.id]:s,[ag.LINRLOW.id]:r}}getWrappers(){return[this.wrapInner(ag.LINRMID,1)]}},CSHO:class extends cg{computeDone;constructor(e,t){super(e,t,cf(t,e=>{var t,i;let s=ez(e);return s.symbol=ty(t=e.symbol)?`${ty(i=t)?td(i).root:null}Y00`:null,eF(s.symbol)?new uZ(s):new uJ(s,!0)})),this.computedServerSide=!0,this.initialNotification=!0,this.computeDone=!1}alignCashTimelineWithUnderlying(){let e=this.innCont(0);if(!eF(e)||0===e.size)return;let t=this.innCont(1),i=e.getTimeData(),s=t.getTimeData(),r=t.getData(ag.Close),n=Array(i.length).fill(null);if(!(this.innerSeries[1]instanceof uJ)){let a=0,o=e.size,l=t.size;for(let e=0;e<o;++e){for(;a<l&&s[a].getTime()<i[e].getTime();)a++;a<l&&s[a].getTime()===i[e].getTime()&&(n[e]=r[a])}}this.container.setData(this.target,n)}calculate(e){this.computeDone||(this.container=this.makeContainer(),this.alignCashTimelineWithUnderlying(),this.computeDone=!0,this.notify(ay.TS_MANYCHANGED,-1))}},CSHB:class extends cg{constructor(e,t){super(e,t,function(e,t=ag.CSHO){return fb("CSHO",fC(t),e)}(t))}shouldTriggerOurRecalc(e){return!!super.shouldTriggerOurRecalc(e)||e===this.innerSeries[1]&&this.innHasData(0)&&this.innHasData(1)}calculateAt(e){let t=(t,i)=>eF(this.innCont(t))?this.innVal(t,i,e):null,i=t(0,ag.Close),s=t(1,ag.CSHO);return{[this.target.id]:eF(s)&&eF(i)?s-i:null}}},CTPI:class extends cW{constructor(e,t){e.inputs={Period1:5,Period2:3,Period3:3},super(e,!0,ag.CTPI,t)}},PCTCHG:class extends cg{constructor(e,t){super(e,t),fj(this)}calculateAt(e){let t=null,[i]=fK(this);if(e>0){let s=this.innVal(i,this.source,e-1);null!==s&&(t=100*(this.innVal(i,this.source,e)-s)/s)}return{[this.target.id]:t}}},OPINT:class extends cv{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(ag.TradeSize,ag.Change)}},STOMOMIX:class extends cg{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period1,ag.High,ag.HH,!0),s=fO(t,e.inputs.Period1,ag.Low,ag.LL,!1),r=fM(fG(d1,(e,t,i)=>this.baseVal(ag.Close,e)-(t+i)/2,i,s),e.inputs.Period2,d1,d2),n=fM(r,e.inputs.Period2,d2,d3),a=fM(fG(d4,(e,t,i)=>t-i,i,s),e.inputs.Period2,d4,d5),o=fM(a,e.inputs.Period2,d5,d6),l=fG(ag.STOMOMIX,(e,t,i)=>100*t/i,n,o);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},CHDMOMOSC:class extends cg{constructor(e,t){super(e,t);let i=new pe(e,t),s=fJ(e,"MA","Average")(i,this.inputs.PeriodAvg,ag.CHDMOMOSC,ag.CHDMOMOSCAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(ag.CHDMOMOSC,1),this.wrapInner(ag.CHDMOMOSCAVG,2)]}},VSTOP:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period);this.addInner(i)}get helpers(){return[pt,pi,ps]}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=1,l=this.baseVal(ag.Close,e),u=e=>eF(e)?e:0,h=(e,t)=>this.container.getData(e)[t];e>0&&(s=Math.max(u(h(pt,e-1)),l),n=Math.min(u(h(pi,e-1)),l),o=h(ps,e-1));let c=this.inputs.Multiplier,d=this.innVal(1,ag.ATR,e);if(eF(d)){let u=1===o,p=u?s-c*d:n+c*d,f=h(u?ag.VSTOPUP:ag.VSTOPLOW,e-1);eF(f)||(f=0);let m=u?Math.max(f,p):Math.min(f,p),g=(a=+(l-m>=0))!=o;i=g?l:s,r=g?l:n,t=g?1===a?i-c*d:r+c*d:m}return{[ag.VSTOPUP.id]:1===a?t:null,[ag.VSTOPLOW.id]:1===a?null:t,[pt.id]:i,[pi.id]:r,[ps.id]:a}}},SUPTR:class extends cg{constructor(e,t){super(e,t);let i=fV(t,e.inputs.Period);this.addInner(i)}get helpers(){return[pr,pn,pa,ag.BARCOLIX]}calculateAt(e){let t=0,i=0,s=0,r=null,n=0,a=this.innVal(1,ag.ATR,e);if(eF(a)){let[o,l,u]=[ag.Close,ag.High,ag.Low].map(t=>this.baseVal(t,e)),h=(l+u)/2,c=this.baseVal(ag.Close,e-1),d=this.inputs.Multiplier,p=h-d*a,f=h+d*a,[m,g,y]=[pr,pn,pa].map(t=>this.container.getData(t)[e-1]);t=c>m?Math.max(p,m):p,i=c<g?Math.min(f,g):f;let S=1===(s=o>g?1:o<m?-1:eF(y)?y:1);r=S?t:i,n=+!!S}return{[pr.id]:t,[pn.id]:i,[pa.id]:s,[ag.SUPTR.id]:r,[ag.BARCOLIX.id]:n}}},ICHCLD:class extends cg{constructor(e,t){super(e,t);let i=(e,t,i)=>fG(i,(e,t,i)=>(t+i)/2,e,t),s=(e,s)=>i(fO(t,e,ag.Low,ag.LL,!1),fO(t,e,ag.High,ag.HH,!0),s),r=s(e.inputs.PeriodConversionLine,ag.CONVLN),n=s(e.inputs.PeriodBaseLine,ag.BASELN),a=i(r,n,ag.LEADSP1),o=s(e.inputs.PeriodLaggingSpan2,ag.LEADSP2);this.addInner(r,n,a,o)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=+(this.innVal(3,ag.LEADSP1,e)>this.innVal(4,ag.LEADSP2,e));return{[ag.LAGGSP.id]:this.baseVal(ag.Close,e),[ag.BARCOLIX.id]:t}}getWrappers(){return[this.wrapInner(ag.CONVLN,1),this.wrapInner(ag.BASELN,2),this.wrapInner(ag.LEADSP1,3),this.wrapInner(ag.LEADSP2,4)]}},VWAP:class extends ph{constructor(e,t){super(e,t)}get helpers(){return[po,pl,pu]}isSame(e,t){switch(this.inputs.AnchorPeriod){case"Session":default:return nS(e,t);case"Week":return nb(e,t);case"Month":return nA(e,t);case"Quarter":return nv(e,t);case"Year":return nE(e,t);case"Decade":return l0(10,e)===l0(10,t);case"Century":return l0(100,e)===l0(10,t)}}findPrevPeriodChange(e){for(let t=e;t>0;t--)if(1===this.valueAt(pu,t))return t;return 0}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=e>0,o=a?this.dateAt(e-1):tz.ZERO_DATE,l=this.dateAt(e),u=a&&this.isSame(o,l),h=u?this.valueAt(po,e-1):0,c=u?this.valueAt(pl,e-1):0,d=this.innVal(0,ag.Volume,e),p=h+this.innVal(1,this.source,e)*d,f=c+d;if(t=p/f,u){let a=this.findPrevPeriodChange(e-1),o=this.container.getData(ag.VWAP).slice(a,e);o.push(t);let l=eg(o),u=Math.sqrt(eg(o.map(e=>(e-l)*(e-l)))),h=this.inputs.Stdev1stMultiplier*u;i=t+h,s=t-h;let c=this.inputs.Stdev2ndMultiplier*u;r=t+c,n=t-c}else i=t,s=t,r=t,n=t;return{[po.id]:p,[pl.id]:f,[pu.id]:+!u,[ag.VWAP.id]:t,[ag.VWAPSD1U.id]:i,[ag.VWAPSD1L.id]:s,[ag.VWAPSD2U.id]:r,[ag.VWAPSD2L.id]:n}}},MACROSS:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,ag.MAS),r=i(t,e.inputs.Period2,this.source,ag.MAL);this.addInner(s,r)}get helpers(){return pd}calculateAt(e){let t=this.innVal(1,ag.MAS,e),i=this.innVal(2,ag.MAL,e);return pp(this.container,e,t,i)}getWrappers(){return[this.wrapInner(ag.MAS,1),this.wrapInner(ag.MAL,2)]}},PACROSS:class extends cg{_maIndex;_maTarget;constructor(e,t){super(e,t),fj(this);let i=fJ(e,"MA","Average")(t,e.inputs.Period,this.source);this.addInner(i);let[s]=fK(this);this._maIndex=s+1,this._maTarget=i.target}get helpers(){return pd}calculateAt(e){let t=this.innVal(this._maIndex,this._maTarget,e),[,i]=fK(this),s=i.getData(this.source)[e],r=pp(this.container,e,s,t);return r[this.target.id]=t,r}},VOIN:class extends cg{constructor(e,t){super(e,t);let i=f$(pf,function(e){return{[pf.id]:e>0?Math.abs(this.baseVal(ag.High,e)-this.baseVal(ag.Low,e-1)):null}},t),s=f$(pm,function(e){return{[pm.id]:e>0?Math.abs(this.baseVal(ag.Low,e)-this.baseVal(ag.High,e-1)):null}},t),r=fN(t,ag.TR);this.addInner(i,s,r)}calculateAt(e){let t=null,i=null,s=this.period;if(this.atLeast(e,s)){let r=this.past(e,s,pf,this.innCont(1)),n=this.past(e,s,pm,this.innCont(2)),a=this.past(e,s,ag.TR,this.innCont(3));if(ey(r)&&ey(n)&&ey(a)){let e=em(r),s=em(n),o=em(a);t=e/o,i=s/o}}return{[ag.PLVI.id]:t,[ag.MNVI.id]:i}}},DIFA:class extends cg{isPercent;constructor(e,t){super(e,t);let i=fJ(e,"MA","Average")(t,this.period,this.source,pS);this.isPercent="Percentage"===e.inputs.Distance,this.addInner(i)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=null,i=null,s=this.innVal(1,pS,e),r=this.baseVal(this.source,e);if(null!=s&&0!==s){t=r-s,this.isPercent&&(t=100*t/s);let n=t<=0;if(i=n?1:3,e>0){let s=this.container.getData(this.target)[e-1];null!==s&&(n&&t>s&&(i=0),!n&&t<s&&(i=2))}}return{[this.target.id]:t,[ag.BARCOLIX.id]:i}}},DOSC:class extends cg{constructor(e,t){super(e,t);let i=fM(fB(t,this.inputs.PeriodRsi,this.source,ag.RSI),this.inputs.PeriodEma1,ag.RSI,ag.EMA),s=fM(i,this.inputs.PeriodEma2,ag.EMA,ag.EMA),r=f_(s,this.inputs.PeriodMa,ag.EMA,ag.MA),n=fG(ag.DOSCH,(e,t,i)=>t-i,s,r),a=f_(n,this.inputs.PeriodSig,ag.DOSCH,ag.DOSCS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(ag.DOSCH,1),this.wrapInner(ag.DOSCS,2)]}},BBANDW:class extends c${constructor(e,t){super(e,"BandWidth",t)}},MARIB:class extends cg{constructor(e,t){super(e,t);let i=this.inputs.Period,s=this.inputs.Increment,r=Math.min(Math.max(0,this.inputs.Count),10);for(let e=0;e<r;++e){let r=f_(t,i+e*s,this.source,this.outFields[e]);this.addInner(r)}}getWrappers(){let e=this.outFields,t=this.inputs.Count;return[this.wrapInner(e[0],1),this.wrapInner(e[1],2),this.wrapInner(e[2],3),this.wrapInner(e[3],4),this.wrapInner(e[4],5),this.wrapInner(e[5],6),this.wrapInner(e[6],7),this.wrapInner(e[7],8),this.wrapInner(e[8],9),this.wrapInner(e[9],10)].slice(0,t)}},HASMO:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"EMA","Smoothing1"),s=e.inputs.Period1,r=i(t,s,ag.Open),n=i(t,s,ag.High),a=i(t,s,ag.Low),o=i(t,s,ag.Close),l=fG(pP,(e,t,i,s,r)=>(t+i+s+r)/4,r,n,a,o),u=fG(pA,function(e,t,i,s){let r=null;if(e>0){let s=this.container.getData(pA)[e-1],n=this.innVal(2,pP,e-1);eF(s,n)?r=(s+n)/2:eF(t,i)&&(r=(t+i)/2)}return r},r,o,l),h=fG(pT,(e,t,i,s)=>eF(t,i,s)?Math.max(t,Math.max(i,s)):null,n,u,l),c=fG(pv,(e,t,i,s)=>eF(t,i,s)?Math.min(t,Math.min(i,s)):null,a,u,l),d=fJ(e,"EMA","Smoothing2"),p=e.inputs.Period2,f=d(u,p,pA,ag.Open),m=d(h,p,pT,ag.High),g=d(c,p,pv,ag.Low),y=d(l,p,pP,ag.Close),S=f$(ag.Change,function(e){let t=null;if(e>0){let i=this.baseVal(ag.Close,e),s=this.baseVal(ag.Close,e-1);eF(i,s)?t=i-s:eF(i)&&!eF(s)&&(t=0)}return{[ag.Change.id]:t}},y);this.addInner(f,m,g,y,S)}getWrappers(){return[this.wrapInner(ag.Open,1),this.wrapInner(ag.High,2),this.wrapInner(ag.Low,3),this.wrapInner(ag.Close,4),this.wrapInner(ag.Change,5)]}},TTMSQZ:class extends cg{constructor(e,t){super(e,t);let i=e.inputs,s=fM(t,i.PeriodEmaKeltner,ag.Close),r=fV(t,i.PeriodAtrKeltner);function n(e,t,i,s){return eF(i,s)?i+e*s:null}let a=i.MultiplierKeltner,o=fG(ag.KCUP,eh(n,a),s,r),l=fG(ag.KCLOW,eh(n,-a),s,r),u=function(e,t,i,s=ag.Close){let r="BBANDS",n=fE(r);return fb(r,{source:s,inputs:{[tz.INPUT_PERIOD]:t,[tz.INPUT_WIDTH]:i},outFields:n},e)}(t,i.PeriodBollinger,i.WidthBollinger),h=function(e,t){let i="DONCHN",s=fE(i);return fb(i,{inputs:fP(t),outFields:s,source:null},e)}(t,i.PeriodMomentum),c=f_(t,i.PeriodMomentum,ag.Close),d=fU(fG(pC,function(e,t,i,s){let r=null,n=this.innVal(1,ag.DONMID,e);return eF(n,s)&&(r=t-(n+s)/2),r},t,h,c),i.PeriodMomentum,pC,ag.TTMSQZOSC);this.addInner(o,l,u,d)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=null,i=null,s=-1,r=this.innVal(1,ag.KCUP,e),n=this.innVal(2,ag.KCLOW,e),[a,o]=[ag.BOLLBU,ag.BOLLBL].map(t=>this.innVal(3,t,e));a<r&&o>n?t=0:i=0;let l=this.innVal(4,ag.TTMSQZOSC,e),u=e>0?this.innVal(4,ag.TTMSQZOSC,e-1):null;if(eF(l))if(eF(u)){let e=l>=0,t=u<l;s=e?t?3:2:+!!t}else s=2;return{[ag.TTMSQZON.id]:t,[ag.TTMSQZOFF.id]:i,[ag.BARCOLIX.id]:s}}getWrappers(){return[this.wrapInner(ag.TTMSQZOSC,4)]}},CRS:class extends cg{constructor(e,t){if(super(e,t),f2(t)){let i=Sp().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.inputs.Symbol.toUpperCase();let r=i.getTimeSeries(s),n=e=>e.query?.symbol,{model:a}=nK(`{${n(t)}} / {${n(r)}}`,!1),o=new py(a,[t,r],(e=>{let t=e.unit===G.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:B.Manual,missing:t?F.UseNext:F.UsePrevious,stretch:e=>!1,fieldMap:new Map([[ag.Close,ag.CRS]]),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation)),l=fJ(e,"MA","Average")(o,this.period,ag.CRS,ag.CRSAVG);this.addInner(r,o,l),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=f$(ag.Close,(e,t)=>null,t),i=f$(ag.CRS,(e,t)=>null,t),s=f$(ag.CRSAVG,(e,t)=>null,t);this.addInner(e,i,s),this.canLoadMoreData=!1}}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[0].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}getWrappers(){return[this.wrapInner(ag.CRS,2),this.wrapInner(ag.CRSAVG,3)]}},JPI:pN,CTTP:class extends pN{constructor(e,t){e.inputs=eK(sR("JPI").defaults.inputs.filter(e=>"HandbrakePeriod"!==e.name)),super(e,t)}},CTTI:class extends pN{constructor(e,t){e.inputs=structuredClone(pV),super(e,t)}},DRS:class extends cg{get indexSymbol(){return this.inputs[tz.INPUT_SYMBOL]}constructor(e,t){if(super(e,t),f2(t)){let i=Sp().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.indexSymbol;let r=i.getTimeSeries(s),{model:n}=nK(`{${t.query.symbol}} / {${r.query.symbol}} * 100`,!1),a=new py(n,[t,r],(e=>{let t=e.unit===G.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:B.Manual,missing:t?F.UseNext:F.UsePrevious,stretch:e=>!1,fieldMap:new Map([[ag.Close,ag.DRS]]),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation));this.addInner(r,a),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=f$(ag.Close,(e,t)=>null,t),i=f$(ag.DRS,(e,t)=>null,t);this.addInner(e,i),this.canLoadMoreData=!1}}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[0].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}getWrappers(){return[this.wrapInner(ag.DRS,2)]}},MRS:class extends cg{get indexSymbol(){return this.inputs[tz.INPUT_SYMBOL]}constructor(e,t){super(e,t);let i=function(e,t,i,s=ag.DRS){return fb("DRS",{target:s,inputs:{[tz.INPUT_SYMBOL]:t},aggregation:i,source:null},e)}(t,this.indexSymbol,e.aggregation),s=f_(i,this.period,ag.DRS);this.addInner(i,s),this.canLoadMoreData=!0,this.initialNotification=!0}calculateAt(e){let t=this.innVal(1,ag.DRS,e),i=this.innVal(2,ag.MA,e),s=null;return eF(t,i)&&0!==i&&(s=(t/i-1)*100),{[ag.MRS.id]:s}}async loadMoreData(e=!0){if(this.isLoading||!this.innerSeries[0].canLoadMoreData)return Promise.resolve();this.isLoading=!0,await this.innerSeries[1].loadMoreData(e),this.isLoading=!1}},PMO:class extends cg{constructor(e,t){super(e,t);let i=fF(t,1),s=e.aggregation,r=fG(pF,(e,t)=>10*t,pB(i,this.inputs.Period1,s,ag.ROC,pH)),n=pB(r,this.inputs.Period2,s,pF,ag.PMO),a=fM(n,this.inputs.Period3,ag.PMO,ag.PMOS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(ag.PMO,1),this.wrapInner(ag.PMOS,2)]}},RVOL:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"MA")(t,this.period,ag.Volume,pk,!0);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(0,ag.Volume,e),s=this.innVal(1,pk,e);return eF(i,s)&&0!==s&&(t=i/s),{[this.target.id]:t}}},WGALPH:class extends cg{isDaily;isFeasible=!0;constructor(e,t){super(e,t),this.isFeasible=!(t instanceof uJ)&&!p$.includes($[t.query.curveStyle]),this.isDaily=e.aggregation.unit===G.Day}acceptable(e,t,i,s){return this.isDaily?0===s||!nb(this.baseVal(ag.DateTime,t),this.baseVal(ag.DateTime,i)):e>0&&i-t>=5}pluckValues(e){let t=0,i=[],s=e+5;for(let r=0;t<53&&e-r>0;r++){let n=e-r,a=this.baseVal(this.source,n);this.acceptable(a,n,s,t)&&(i.push(a),s=n,t++)}return i}calculateAt(e){let t=null;if(this.isFeasible&&e>=pW){let i=1,s=this.pluckValues(e),r=s.length;if(r>=27)for(let e=0;e<r-1;e++){let t=s[e]/s[e+1]-1;t<0?t=Math.max(t,-.2):t>=0&&(t=Math.min(t,.2)),i*=t=t*pU[e]+1}t=100*(i-1)}return{[this.target.id]:t}}},VOLAP:class extends pz{constructor(e,t){super(e,!1,t)}},AVWAP:class extends ph{constructor(e,t){super(e,t)}get helpers(){return[po,pl]}isSameOhlcBar(e,t){let{unit:i,size:s}=this.aggregation;switch(i){case G.Tick:return e===t;case G.Intraday:return an(t,lz(e,s));case G.Day:return an(t,lk(e,s));case G.Week:return nb(e,t);case G.Month:return nA(e,t);case G.Quarter:return nv(e,t);case G.Year:return nE(e,t);default:throw Error(`Unexpected aggregation unit ${G[i]}`)}}calculateAt(e){let t=null,i=null,s=null,r=this.inputs.Anchor,n=this.dateAt(e);if(an(r,n)||this.isSameOhlcBar(n,r)){let r=e>0,n=r?this.valueAt(po,e-1):0,a=r?this.valueAt(pl,e-1):0,o=this.innVal(0,ag.Volume,e);t=(i=n+this.innVal(1,this.source,e)*o)/(s=a+o)}return{[po.id]:i,[pl.id]:s,[ag.AVWAP.id]:t}}},KST:class extends cg{constructor(e,t){super(e,t);let i=this.source,s=f$(i,eh(fq,i),t),r=fF(s,this.inputs.PeriodRoc1,i),n=fF(s,this.inputs.PeriodRoc2,i),a=fF(s,this.inputs.PeriodRoc3,i),o=fF(s,this.inputs.PeriodRoc4,i),l=f_(r,this.inputs.PeriodMa1,ag.ROC,ag.MA1),u=f_(n,this.inputs.PeriodMa2,ag.ROC,ag.MA2),h=f_(a,this.inputs.PeriodMa3,ag.ROC,ag.MA3),c=f_(o,this.inputs.PeriodMa4,ag.ROC,ag.MA4),d=fG(ag.KST,(e,t,i,s,r)=>t+2*i+3*s+4*r,l,u,h,c),p=f_(d,this.inputs.PeriodSig,ag.KST,ag.KSTSIG);this.addInner(d,p)}getWrappers(){return[this.wrapInner(ag.KST,1),this.wrapInner(ag.KSTSIG,2)]}},STC:class extends cg{constructor(e,t){super(e,t);let i=fM(t,this.inputs.PeriodShort,ag.Close,pY),s=fG(pK,(e,t,i)=>t-i,i,fM(t,this.inputs.PeriodLong,ag.Close,pj)),r=this.inputs.PeriodStoch1,n=this.inputs.PeriodStoch2,a=fJ(e,"EMA"),o=a(fw(s,r,pq,!1,pK),n,pq,pX),l=a(fw(o,r,pZ,!1,pX),n,pZ,this.target);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCCLO:class extends p1{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=(e,t,i)=>t-i,r=fG(p0,"Yes"===this.inputs.RatioAdjusted?(e,t,i)=>(t-i)/(t+i)*1e3:s,t,i),n=fM(r,this.inputs.Period1,p0,pJ),a=fM(r,this.inputs.Period2,p0,pQ);return fG(this.target,s,n,a)}},NHLAI:p4,CMBCI:class extends cg{constructor(e,t){super(e,t);let i=fB(t,this.inputs.Period1Rsi,ag.Close,p5),s=f$(p6,ec(fX,this.inputs.Period1Mom,p5),i),r=f_(fB(t,this.inputs.Period2Rsi,ag.Close,p7),this.inputs.Period2Ma,p7,p8),n=fG(ag.CMBCI,(e,t,i)=>t+i,s,r),a=f_(n,this.inputs.PeriodFastMa,ag.CMBCI,ag.CMBCIF),o=f_(n,this.inputs.PeriodSlowMa,ag.CMBCI,ag.CMBCIS);this.addInner(n,a,o)}getWrappers(){return[this.wrapInner(ag.CMBCI,1),this.wrapInner(ag.CMBCIF,2),this.wrapInner(ag.CMBCIS,3)]}},COTI:class extends cg{constructor(e,t){super(e,new dN({source:ag.Close,inputs:{},outFields:fE("COTLC")},t));let i=Number.parseInt(this.inputs.History),s=fw(this.innerSeries[0],6===i?26:52*i,ag.COTI,!1,ag.COTLCCMSP);this.initialNotification=!0,this.computedServerSide=!0,this.addInner(s)}getWrappers(){return[this.wrapInner(ag.COTI,1)]}},CHEXI:class extends cg{isLong;constructor(e,t){super(e,t),this.isLong="Long"===this.inputs.Direction;let i=this.period,s=fV(t,i),r=this.inputs.Multiplier,n=fG(p9,(e,t)=>null===t?null:r*t,s),a=fO(t,i,ag.High,ag.HH,!0),o=fO(t,i,ag.Low,ag.LL,!1);this.addInner(n,a,o)}calculateAt(e){let t=null,i=null,s=this.innVal(1,p9,e);return null!==s&&(this.isLong?t=this.innVal(2,ag.HH,e)-s:i=this.innVal(3,ag.LL,e)+s),{[ag.CHEXL.id]:t,[ag.CHEXS.id]:i}}},MBBANDS:class extends c${constructor(e,t){super(e,"Modified",t)}},OPTIV:class extends fe{},IVRANK:class extends fe{},IVPCTL:class extends fe{},OPTVOLPC:class extends fe{},OPTOIPC:class extends fe{},OPTVOL:class extends fe{},OPTOI:class extends fe{},CHOP:class extends cg{constructor(e,t){super(e,t);let i=fV(t,1),s=this.inputs.Period,r=fO(t,s,ag.High,ag.HH,!0),n=fO(t,s,ag.Low,ag.LL,!1);this.addInner(i,r,n)}calculateAt(e){let t=null,i=this.period;if(e>i){let s=this.past(e,i,ag.ATR,this.innCont(1));if(ey(s)){let r=em(s),n=this.innVal(2,ag.HH,e);t=100*Math.log10(r/(n-this.innVal(3,ag.LL,e)))/Math.log10(i)}}return{[this.target.id]:t}}},MACLD:class extends cg{constructor(e,t){super(e,t);let i=fJ(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,ag.MACLD1),r=i(t,e.inputs.Period2,this.source,ag.MACLD2);this.addInner(s,r)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=this.innVal(1,ag.MACLD1,e),i=this.innVal(2,ag.MACLD2,e);return{[ag.BARCOLIX.id]:+(t>i)}}getWrappers(){return[this.wrapInner(ag.MACLD1,1),this.wrapInner(ag.MACLD2,2)]}},BTI:class extends p1{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=fG(ft,(e,t,i)=>t/(t+i),t,i);return fJ(e,"MA","Average")(s,this.inputs.Period,ft,this.target)}},FRAMA:class extends cg{constructor(e,t){super(e,t),fj(this);let i=e.inputs.Period,s=Math.floor(i/2),r=fO(t,i,ag.High,fh,!0),n=fO(t,i,ag.Low,fc,!1),a=fO(t,s,ag.High,fd,!0),o=fO(t,s,ag.Low,fp,!1),l=fO(t,s,ag.High,ff,!0),u=fO(t,s,ag.Low,fm,!1);this.addInner(r,n,a,o,l,u)}calculateAt(e){let t=this.period,i=Math.floor(t/2),[,s]=fK(this),r=s.getData(this.source)[e];if(!this.atLeast(e,t))return{[this.target.id]:r};let n=+!!this.sourceNeedsCompute,a=this.innVal(1+n,fh,e),o=this.innVal(2+n,fc,e),l=this.innVal(3+n,fd,e),u=this.innVal(4+n,fp,e),h=this.innVal(5+n,ff,e-i),c=this.innVal(6+n,fm,e-i);if(!eF(a,o,l,u,h,c))return{[this.target.id]:r};let d=(a-o)/t,p=(l-u)/i,f=(h-c)/i,m=0;p>0&&f>0&&d>0&&(m=(Math.log(p+f)-Math.log(d))/Math.log(2));let g=Math.exp(-4.6*(m-1));g=Math.max(.01,Math.min(1,g));let y=e>0?this.container.getData(this.target)[e-1]:r,S=null!==y?g*r+(1-g)*y:r;return{[this.target.id]:S}}},FISHER:class extends cg{constructor(e,t){super(e,t);let i=e.inputs.Period,s=f$(fg,eh(c1,fg),t),r=fO(s,i,fg,ag.HH,!0),n=fO(s,i,fg,ag.LL,!1);this.addInner(s,r,n)}get helpers(){return[fy]}calculateAt(e){let t=this.innVal(1,fg,e),i=this.innVal(2,ag.HH,e),s=this.innVal(3,ag.LL,e);if(!eF(i,s,t))return{[ag.FISHER.id]:null,[ag.FISHTRG.id]:null,[fy.id]:null};let r=i-s,n=t=>this.container.getData(t)[e-1],a=.66*((0!==r?(t-s)/r:.5)-.5)+.67*((e>0?n(fy):null)??0);a>.99?a=.999:a<-.99&&(a=-.999);let o=e>0?n(ag.FISHER):null,l=.5*Math.log((1+a)/(1-a))+.5*(o??0);return{[ag.FISHER.id]:l,[ag.FISHTRG.id]:o,[fy.id]:a}}},PC:class extends cg{stdDevs;periodForecast;unitsPerYear;constructor(e,t){super(e,t),this.unitsPerYear=f0(e.aggregation),this.stdDevs=this.toInt("StandardDeviations"),this.periodForecast=this.toInt("PeriodForecast");let i=this.getHistVolPeriod();if(null!==i){let s=function(e,t,i,s=ag.Close,r=ag.HV){return fb("HV",{source:s,target:r,aggregation:i,inputs:fP(t)},e)}(t,i,e.aggregation);this.addInner(s)}}getHistVolPeriod(){return this.isCustomVolatility?null:Number.parseInt(this.volatilityParam.substring(2))}toInt(e){return Number.parseInt(this.inputs[e])}get volatilityParam(){return this.inputs.Volatility}get isCustomVolatility(){return"Custom"===this.volatilityParam}get haveVolatility(){return this.isCustomVolatility||this.innHasData(1)}getVolatilityPercent(){return(this.isCustomVolatility?this.inputs.VolatilityPercent:this.innCont(1).getLastDataPoint(ag.HV))/100}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null;if(this.haveVolatility){let o=this.base.size-this.periodForecast;if(e>=o){let l=this.base.getLastDataPoint(ag.Close),u=l*this.getVolatilityPercent()*Math.sqrt((e-o+1)/this.unitsPerYear);if(t=l+u,i=l-u,this.stdDevs>1){let e=2*u;if(s=l+e,r=l-e,this.stdDevs>2){let e=3*u;n=l+e,a=l-e}}}}return{[ag.PCUP1.id]:t,[ag.PCDN1.id]:i,[ag.PCUP2.id]:s,[ag.PCDN2.id]:r,[ag.PCUP3.id]:n,[ag.PCDN3.id]:a}}recalculateAt(e,t,i){let s={tag:e1(),src:this.innerSeries[0]};i&&this.calculate(s)}},GREEKS:class extends cg{constructor(e,t){super(e,cf(t,e=>new fi(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(ag.Delta,0),this.wrapInner(ag.Gamma,0),this.wrapInner(ag.Theta,0),this.wrapInner(ag.Vega,0)]}},PVACP:class extends pz{constructor(e,t){super(e,!0,t)}},TDI:class extends cg{constructor(e,t){super(e,t),fj(this);let i=e.inputs.PeriodRSI,s=e.inputs.PeriodTradeSignal,r=e.inputs.PeriodMarketBase,n=e.inputs.PeriodBB,[a]=fK(this),o=fB(this.innerSeries[a],i,this.source,ag.TDIPRC),l=f_(o,s,ag.TDIPRC,ag.TDITSL),u=f_(o,r,ag.TDIPRC,ag.TDIMBL),h=fW(o,n,ag.TDIPRC,ag.MSD);this.addInner(o,l,u,h)}calculateAt(e){let t=this.inputs.MultiplierBB,i=+!!this.sourceNeedsCompute,s=this.innVal(1+i,ag.TDIPRC,e),r=this.innVal(2+i,ag.TDITSL,e),n=this.innVal(3+i,ag.TDIMBL,e),a=this.innVal(4+i,ag.MSD,e),o=null,l=null;if(eF(n,a)){let e=t*a;o=n+e,l=n-e}return{[ag.TDIPRC.id]:s,[ag.TDITSL.id]:r,[ag.TDIMBL.id]:n,[ag.TDIUPR.id]:o,[ag.TDILWR.id]:l}}},PPS:class extends cg{isLong;isPercent;constructor(e,t){super(e,t);let i=e.inputs.Period,s=e.inputs.Range,r=e.inputs.Direction;this.isLong="Long"===r,this.isPercent="Percent"===e.inputs.Type;let n=ag.Close;"Close"!==s&&(n=this.isLong?ag.High:ag.Low);let a=fO(t,i,n,fu,this.isLong);this.addInner(a)}get helpers(){return[ag.BARCOLIX]}calculateAt(e){let t=null,i=this.innVal(1,fu,e),s=this.inputs.StopValue;if(null!==i){let e=this.isPercent?i*s/100:s;t=this.isLong?i-e:i+e}let r=+!!this.isLong;return{[ag.PPS.id]:t,[ag.BARCOLIX.id]:r}}},RCI:class extends cg{constructor(e,t){super(e,t);let i=new fS({source:this.source,target:ag.RCI,inputs:{Period:e.inputs.Period}},t),s=e.inputs.PeriodSignal,r=fJ(e,"MA","Smoothing")(i,s,ag.RCI,ag.RCISIG);this.addInner(i,r)}getWrappers(){return[this.wrapInner(ag.RCI,1),this.wrapInner(ag.RCISIG,2)]}},ZIGZAG:class extends cg{state;useHighLow;isAtrMode;atrMult;percent;constructor(e,t){if(super(e,t),this.useHighLow="High/Low"===e.inputs.Method,this.isAtrMode="ATR"===e.inputs.PercentMode,this.percent=e.inputs.Percent,this.atrMult=e.inputs.MultiplierAtr,this.useHighLow||fj(this),this.isAtrMode){let t=e.inputs.PeriodAtr,[i]=this.useHighLow?[0]:fK(this),s=fV(this.innerSeries[i],t,"SMA",fA);this.addInner(s)}this.resetState()}getHigh(e){if(this.useHighLow)return this.baseVal(ag.High,e);let[,t]=fK(this);return t.getData(this.source)[e]}getLow(e){if(this.useHighLow)return this.baseVal(ag.Low,e);let[,t]=fK(this);return t.getData(this.source)[e]}getAtrDenom(e){if(this.useHighLow)return this.baseVal(ag.Close,e);let[,t]=fK(this);return t.getData(this.source)[e]}setPivot(e,t){this.state.pivotPrice=e,this.state.pivotIndex=t}setCandidate(e,t){this.state.candPrice=e,this.state.candIndex=t}getDevPct(e){if(this.isAtrMode){let t=!this.useHighLow&&this.sourceNeedsCompute?1:0,i=this.innVal(1+t,fA,e),s=this.getAtrDenom(e);return null===i||null===s||0===s?0:this.atrMult*(i/s*100)}return this.percent}pct(e,t){return 0===e?0:(t-e)/e*100}resetState(){this.state={mode:0,pivotPrice:null,pivotIndex:null,candPrice:null,candIndex:null,confirmedPivots:new Map}}calculateAt(e){let t=this.getHigh(e),i=this.getLow(e),s=this.getDevPct(e);if(null===t||null===i)return{};if(0===e){this.resetState();let i=this.useHighLow?this.baseVal(ag.Close,e):t;return this.setPivot(i,e),this.setCandidate(i,e),{}}if(0===this.state.mode)this.pct(this.state.pivotPrice,t)>=s?(this.state.mode=1,this.setCandidate(t,e)):-this.pct(this.state.pivotPrice,i)>=s&&(this.state.mode=-1,this.setCandidate(i,e));else if(1===this.state.mode){let r=t>=this.state.candPrice;r&&this.setCandidate(t,e);let n=(this.state.candPrice-i)/this.state.candPrice*100;if(!r&&n>=s){let t=this.state.candIndex,s=this.state.candPrice;this.state.confirmedPivots.set(t,s),this.setPivot(s,t),this.setCandidate(i,e),this.state.mode=-1}}else if(-1===this.state.mode){let r=i<=this.state.candPrice;r&&this.setCandidate(i,e);let n=(t-this.state.candPrice)/this.state.candPrice*100;if(!r&&n>=s){let i=this.state.candIndex,s=this.state.candPrice;this.state.confirmedPivots.set(i,s),this.setPivot(s,i),this.setCandidate(t,e),this.state.mode=1}}return{}}getCurrentState(){return this.state}}};function fP(e){return{[tz.INPUT_PERIOD]:e}}function fC(e){return{target:e,source:null,inputs:fR}}function fb(e,t,i){if(e$(fv,e))return new fv[e](t,i);let s=Sp()?.config.extensions?.studyProvider;if(s){let r=s.factory(e,t,i);if(r)return r}throw Error(`Study ${e} has not been implemented yet.`)}function fE(e){return sR(e).defaults.curves.reduce((e,t)=>e.concat(t.fields.filter(t=>!e.includes(t))),[]).map(e=>ag[e])}function fL(e,t,i,s){return{source:t,target:i,inputs:fP(e),allowEmptyValues:s}}function f_(e,t,i,s=ag.MA,r=!1){return fb("MA",fL(t,i,s,r),e)}function fM(e,t,i,s=ag.EMA,r=!1){return fb("MAEXP",fL(t,i,s,r),e)}function fx(e,t,i,s=ag.SMA,r=!1){return fb("MASMO",fL(t,i,s,r),e)}function fI(e,t,i,s=ag.WMA,r=!1){return fb("MAWEI",fL(t,i,s,r),e)}function fD(e,t,i,s=ag.HMA,r=!1){return fb("HMA",fL(t,i,s,r),e)}function fO(e,t,i,s,r,n=!1){return new cF({source:i,target:s,inputs:fP(t)},r,n,e)}function fw(e,t,i,s,r=null){return new cB({source:r,target:i,inputs:fP(t)},s,e)}let fR={};function fN(e,t=ag.TR){return fb("_TR",fC(t),e)}function fV(e,t,i="SMA",s=ag.ATR){return fb("ATR",{target:s,inputs:{[tz.INPUT_PERIOD]:t,[tz.INPUT_SMOOTHING]:i},source:null},e)}function fH(e,t=ag.TP){return fb("TP",fC(t),e)}function fF(e,t,i=ag.Close,s=ag.ROC){return fb("ROC",{source:i,target:s,inputs:fP(t)},e)}function fB(e,t,i,s=ag.RSI,r=!1){return fb("_RSI",{source:i,target:s,inputs:{...fP(t),Modified:r}},e)}function fk(e,t=ag.MFMUL){return fb("MFV",fC(t),e)}function fW(e,t,i,s=ag.MSD){return fb("MSD",{source:i,target:s,inputs:fP(t)},e)}function fU(e,t,i,s=ag.MOVLR){return fb("MOVLR",{source:i,inputs:fP(t),target:s},e)}function f$(e,t,i){return new c3(fC(e),t,i)}function fG(e,t,...i){return new c0(fC(e),t,...i)}function fz(e,t,i){return t-i}function fY(e,t,i){return(t-i)/i*100}function fj(e){let t=e.source;if(e.sourceNeedsCompute=function(e){switch(e.id){case"HL/2":case"OC/2":case"HLC/3":case"OHLC/4":case"HLCC/4":return!0;default:return!1}}(t),e.sourceNeedsCompute){let i=f$(t,eh(fq,t),e.innerSeries[0]);e.addInner(i)}}function fK(e){let t=+!!e.sourceNeedsCompute;return[t,e.innCont(t)]}let fq=function(e,t){let[i,s,r,n]=[ag.Open,ag.High,ag.Low,ag.Close].map(e=>this.baseVal(e,t)),a=null,o=e.id;switch(o){case"Open":a=i;break;case"High":a=s;break;case"Low":a=r;break;case"Close":a=n;break;case"HL/2":a=(s+r)/2;break;case"OC/2":a=(i+n)/2;break;case"HLC/3":a=(s+r+n)/3;break;case"OHLC/4":a=(i+s+r+n)/4;break;case"HLCC/4":a=(s+r+n+n)/4}return{[o]:a}},fX=function(e,t,i){let s=null;if(this.atLeast(i,e+1)){let r=this.baseVal(t,i-e);null!==r&&(s=this.baseVal(t,i)-r)}return{[this.target.id]:s}},fZ={sma:fx,ma:f_,ema:fM,wma:fI,hma:fD};function fJ(e,t,i="Smoothing"){return fZ[(e.inputs[i]??t).toLowerCase()]}let fQ={atr:fV,adjatr:function(e,t,i="MA",s=ag.Close,r=ag.ADJATR){return fb("ADJATR",{source:s,target:r,inputs:{[tz.INPUT_PERIOD]:t,[tz.INPUT_SMOOTHING]:i}},e)}};function f0(e){switch(e.unit){case G.Day:return 252;case G.Week:return 52;case G.Month:return 12;default:return 0}}function f1(e){let t=[ag.High,ag.Low];return e instanceof py&&2!==eP(e.targetFields,t).length}function f2(e){return!(e instanceof uJ)&&e.query instanceof cd}class f3 extends cy{constructor(e,t){super(e,t,fM(t,13,ag.Close),function(e,t,i,s,r=ag.Close){return fb("MACDEXP",{source:r,inputs:{Period1:12,Period2:26,Period3:9},outFields:[ag.MACD,ag.MACDS,ag.MACDH]},e)}(t,0,0,0,ag.Close)),this.query=t.query,this.useNotifications=!0}calculateAt(e){let t=W.Same,i=this.innVal(1,ag.EMA,e),s=this.innVal(1,ag.EMA,e-1),r=this.innVal(2,ag.MACDH,e),n=this.innVal(2,ag.MACDH,e-1);return eF(i,s,r,n)&&(i>s&&r>n?t=W.Up:i<s&&r<n&&(t=W.Down)),{[ag.BREL.id]:t}}getWrappers(){return this.wrapBaseFields(ag.Open,ag.High,ag.Low,ag.Close,ag.Change,ag.Volume,ag.OpenInterest,ag.TradingDay)}}function f4(e,t){return eF(t)?(this[e]=t,null):this[e]}class f5{_domain;_range;_extent;_padding;constructor(){this._domain=this._range=this._extent=null,this._padding=[0,0]}domain(e){return f4.call(this,"_domain",e)}range(e){return f4.call(this,"_range",e)}padding(e){return f4.call(this,"_padding",e)}get ready(){return eF(this._domain,this._range)}}let f6=1/Math.log2(10);function f7(e,t){let i,s,r,n,a=(i=e[0],(s=e[1]-i)>0?e=>(e-i)/s:e=>ep(isNaN(s)?NaN:.5)),o=(r=t[0],n=t[1],e=>r*(1-e)+n*e);return e=>o(a(e))}function f8(e){return Math.sign(e)*Math.log10(1+Math.abs(e/f6))}function f9(e){return Math.sign(e)*f6*(-1+Math.pow(10,Math.abs(e)))}let me=[[0,1],[1,10],[10,100],[100,1e3],[1e3,1e4],[1e4,1e5]];class mt extends f5{scaleType;axis;constructor(e,t){super(),this.scaleType=e,this.axis=t}domain(e){return this.axis&&e&&!function(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;if(e===t)return!0;for(let i=0;i<e.length;++i)if(e[i]!==t[i])return!1;return!0}(e,this._domain)&&this.axis.pane.presenter.onScaleDomainChanged(this.axis),super.domain(e)}yToPrice(e){return this.mapValue(e)}rangeWithPadding(){return[this._range[0]+this._padding[0],this._range[1]-this._padding[1]]}mapValue(e,t=!0){if(!this.ready)return null;let i=ep,s=ep;switch(this.scaleType){case X.Linear:break;case X.Logarithmic:i=f8,s=f9;break;default:throw Error("Unexpected scale type (neither linear nor log)")}let r=this._domain.map(i),n=this.rangeWithPadding(),a=t?f7(n,r):f7(r,n),o=e=>n[1]-e+n[0],l=t?o:i;return(t?s:o)(a(l(e)))}priceToY(e){return this.mapValue(e,!1)}getTicks(e){if(!this.ready)return[];let[t,i]=this._range.map(e=>this.mapValue(e,!0));if(t===i&&e>0)return[t];let[s,r]=this._domain;if(this.scaleType===X.Linear||s<0||r>1e5)return mi(t,i,e);let n=this.findLogBand(s),a=this.findLogBand(r),o=2*e;return a-n==0?mi(t,i,o):this.getLogTicks(n,a,o,i<t)}findLogBand(e){return me.findIndex(([t,i])=>e>=t&&e<i)}getLogTicks(e,t,i,s){let r=[...this._domain],n=[];try{for(let a=e;a<=t;a++){let[o,l]=me[a];a===e?o=r[0]:a===t&&(l=r[1]),this.domain([o,l]);let[u,h]=this._range.map(e=>this.mapValue(e,!0)),c=mi(u,h,i);n=s?c.concat(n):n.concat(c)}}finally{this.domain(r)}return!function(e,t){let i=e.length;for(let s=1;s<i;++s){let i=e[s],r=s-1;for(;r>=0&&t(e[r],i);)e[r+1]=e[r],r-=1;e[r+1]=i}}(n,s?(e,t)=>e>t:(e,t)=>e<t),n}checkTicks(){return this.scaleType===X.Logarithmic}}function mi(e,t,i){let s,r=-1,n,a,o;if(i*=1,(e*=1)==(t*=1)&&i>0)return[e];if((s=t<e)&&(n=e,e=t,t=n),0===(o=function(e,t,i){let s=Math.sqrt(50),r=Math.sqrt(10),n=Math.sqrt(2),a=(t-e)/Math.max(0,i),o=Math.floor(Math.log(a)/Math.LN10),l=a/Math.pow(10,o);return o>=0?(l>=s?10:l>=r?5:l>=n?2:1)*Math.pow(10,o):-Math.pow(10,-o)/(l>=s?10:l>=r?5:l>=n?2:1)}(e,t,i))||!isFinite(o))return[];if(o>0)for(e=Math.ceil(e/o),a=Array(n=Math.ceil((t=Math.floor(t/o))-e+1));++r<n;)a[r]=(e+r)*o;else for(a=Array(n=Math.ceil((e=Math.floor(e*o))-(t=Math.ceil(t*o))+1));++r<n;)a[r]=(e-r)/o;return s&&a.reverse(),a}let ms={color:tz.COLOR_TRANSPARENT},mr={color:tz.COLOR_TRANSPARENT,width:0,dashStyle:"Solid"},mn=new Set([ag.Open,ag.High,ag.Low,ag.Close].map(e=>e.id)),ma=new iw(0,0,0,0);class mo{axis;id;record;metaData;timeSeries;notifyAboutPriceDomains=!1;customPlotValues=!1;_priceMapFirstIndex;priceMapper;_firstVisibleDate=null;_lastVisibleDate=null;main=!1;curves=[];type=Z.Symbol;isShutDown=!1;targetFields=[];detachedScale;yScale=null;levels;bands;annotations;visFromIndex;visToIndex;_eventsData;precision;visible=!0;constructor(){this.axis=null,this.id=e1(),this.record=new aP(""),this.metaData=new is,this.timeSeries=new uJ,this.priceMapper=this._priceMapper.bind(this),this._priceMapFirstIndex=new Map}get title(){return""}get showPrevious(){return!1}getPreviousValue(){return null}get mainCurve(){return this.curves[0]}get hasEvents(){return!1}findEvents([e,t]){return[]}get eventsSeries(){return null}get hasEventsData(){return this.hasEvents&&eF(this.eventsSeries)&&this.eventsSeries.hasData&&this.eventsSeries.container.size>0}getEventFor(e){return null}get isSymbol(){return this.is(Z.Symbol)}get isExpression(){return this.is(Z.Expression)}get isStudy(){return this.is(Z.Study)}get isForward(){return this.is(Z.Forward)}get isSeasonal(){return this.is(Z.Seasonal)}getValueAt(e,t,i){return null}wrapIfAdvancedStyle(e){let t=e,i=e=>({outFields:e,inputs:{},source:null});return this.mainCurve.isHeikinAshiStyle?t=new cS(i(uf.slice()),e):this.mainCurve.isElderImpulseSystemStyle?t=new f3(i(uf.slice().concat(ag.BREL)),e):this.mainCurve.isPercentChangeStyle&&(t=new d0(i(uf.slice()),e)),t}is(e){return this.type===e}getCacheableEntities(e){this.metaData.getCacheableEntities(e.metaData),this.timeSeries.getCacheableEntities(e.timeSeries)}fromModel(e){this.type=Z[e.type],this.main=e.main,e.levels&&(this.levels=e.levels),e.bands&&(this.bands=e.bands),eF(e.precision)&&(this.precision=e.precision),this.curves=e.curves.map(e=>{let t=new hZ;return t.plot=this,t.fromModel(e),t}),e.detachedScale&&(this.detachedScale=e.detachedScale,this.yScale=new mt(X.Linear,null)),this.visible=e.visible??!0}initialize(){}shutdown(){eF(this.timeSeries)&&eF(this.timeSeries.shutdown)&&!this.timeSeries.isCached&&this.timeSeries.shutdown(),this.isShutDown=!0}makeQuery(){let e=this.axis.pane.presenter,t=new cd(null,e.data.aggregation,J.Normal,[eq(eG(e.data,null,"range","from")),eq(eG(e.data,null,"range","to"))]);return t.barsToFetch=e.data.maxDataPoints||tz.DEFAULT_MAX_RECORDS,t.aggregation.backAdjust&&(t.barsToFetch=4*t.barsToFetch),t.chartId=e.elementId,t.curveStyle=this.curves[0].style,t.visibleRange=eG(e.display,null,"xAxis","visibleRange"),t.extendedHours=e.data.extendedHours,t}priceToY(e){return(this.hasDetachedScale?this.yScale:this.axis.yScale).priceToY(e)}get hasDetachedScale(){return eF(this.detachedScale,this.yScale)&&this.detachedScale}getDetachedScaleMargins(){return tz.DEFAULT_DETACHED_SCALE_MARGINS}setViewBox(e){if(!this.hasDetachedScale)return;let{y:t,height:i}=e,{top:s,bottom:r}=this.getDetachedScaleMargins();this.yScale.range([Math.floor(t+s*i),Math.floor(t+i-r*i)])}drawLevels(e){e.save();let t=tz.OUT_OF_SCREEN;for(let i of this.levels.filter(e=>e.visible)){let s=this.priceToY(i.value);i7(e,i8({line:i.line,fill:ms})),iz(e,{x:-1,y:s},{x:t,y:s})}e.restore()}drawBands(e){e.save();let t=tz.OUT_OF_SCREEN;for(let i of this.bands){let s=this.priceToY(i.range.to),r=this.priceToY(i.range.from);i7(e,i8({fill:i.fill,line:mr})),i$(e,new iw(-1,s,t,r-s),!1)}e.restore()}drawAnnotations(e){e.save(),this.annotations.forEach(t=>t.draw(e,!0)),e.restore()}getEventFields(){return this.hasEvents&&this.hasEventsData?this.eventsSeries.container.fields.filter(e=>e!==ag.DateTime):[]}getEventsAt(e){let t=this.eventsSeries.container,i=i=>t.getData(i)[e];return this.getEventFields().map(t=>{let s=i(t);if(!eF(s))return null;let r=this.getEventFor(t);if(!eF(r))return null;let n={field:t,value:s,date:i(ag.DateTime),text:r.title,color:r.color};if(t!==ag.Custom||s!==tz.FAKE_CUSTOM_EVENT)return n;{let t=e%2==0;return{...n,value:t?"___news":"___video",text:t?"N":"V"}}}).filter(e=>null!=e)}getRefEventField(e,t,i){return t?e.isOhlc?ag.High:i.isTick?ag.Last:ag.Close:e.fields[0]}getRefPlot(e){return this.axis.pane.isMain?e.mainPlot:this}drawEvents(e,t){let i=this.axis.pane.presenter,s=i.view.xAxis.xScale,r=s.domain();if(!eF(r)||!eF(r[0],r[1]))return;let n=(e,t=ag.DateTime)=>e.container.getData(t),a=n(this.eventsSeries),o=this.getRefPlot(i),l=o.timeSeries,u=n(l),h=i.data.aggregation,c=o===i.mainPlot,d=n(l,this.getRefEventField(o.mainCurve,c,h)),{chart:{fontFamily:p}}=this.axis.pane.presenter.display,f=a.map((e,n)=>e.valueOf()>=r[0].valueOf()&&e.valueOf()<=r[1].valueOf()?this.getEventsAt(n).map(e=>{let r=function(e,t){let{unit:i}=e;if(i===G.Year)return ta(t);if(i===G.Quarter)return nT(t);if(i===G.Month)return tc(t);if(i===G.Week)return nC(t);if(i===G.Day)return tl(t);return t}(h,e.date),n=e_(u,+r,Number),a=d[n];t.has(n)||t.set(n,-1);let o=t.get(n);t.set(n,++o);let l=s.timeToX(r),c=i.view.getEventRadius(),p=this.axis.yScale.priceToY(a)-o*(c+c+c);return{visible:!0,...e,x:l,y:p,r:c,rect:ma}}):[]).flat();e.save();let m=!0;f.forEach(t=>{t.rect=function(e,{x:t,y:i,r:s,color:r,text:n},a){e.fillStyle=r,e.beginPath();let o=s+s,l=new iw(t-s,i-s-o,o,o);e.fillRect(l.x,l.y,l.width,l.height);let u=(1.6*s).toFixed(0);return e.font=`700 ${u}px "${a}"`,e.fillStyle="#fff",e.textAlign="center",e.textBaseline="middle",e.beginPath(),e.fillText(n,t,i-.9*o),l}(e,t,p),this.customEventPopup?.visible&&t.date===this.customEventPopup.date&&(this.showCustomEventPopup(t),m=!1)}),e.restore(),this._eventsData=f,this.customEventPopup?.visible&&m&&this.hideCustomEventPopup()}get customEventPopup(){return this.axis.pane.presenter.view.customEventPopup}hideCustomEventPopup(){this.customEventPopup?.hide()}showCustomEventPopup(e){let{x:t,y:i,r:s,date:r,value:n}=e;this.customEventPopup?.show({x:t+2*s,y:i-2*s},r,n)}getCustomEventDataAt(e){if(!this._eventsData)return null;let t=this._eventsData.find(t=>t.rect.contains(e));return t?.field===ag.Custom?t:null}hitTestCustomEvent(e){return null!==this.getCustomEventDataAt(e)}tryHandleCustomEventClick(e){let t=this.getCustomEventDataAt(e);return!!eF(t)&&(this.showCustomEventPopup(t),!0)}isEmpty(){let e=this.timeSeries;return eF(e)&&e.hasData&&e.container.isEmpty}draw(e){if(this.visible)for(let t of(eF(this.levels)&&this.drawLevels(e),eF(this.bands)&&this.drawBands(e),this.curves))t.draw(e)}drawTopmost(e,t){this.hasEventsData&&this.drawEvents(e,t)}isComparison(e){return this.axis.comparison===e}invalidatePriceMappingCache(){this._firstVisibleDate=null}_priceMapper(e,t,i,s){if(!eF(e)||!this.timeSeries.hasData||!this.shouldPriceMap(i,s))return e;let[r,n]=this.axis.pane.presenter.view.xAxis.xScale.domain()||[];if(!eF(r)||!oC(r))return e;if(this._firstVisibleDate!==r){this._firstVisibleDate=r;let e=this.timeSeries.container.getTimeData(),t=t=>e_(e,+t,Number);this.visFromIndex=t(r),this.visToIndex=t(n),this._priceMapFirstIndex.clear()}return this._priceMapFirstIndex.has(i)||this.canPriceMap(t,i),this.priceMap(e,t,i,!1,s)}isOhlcMapping(e){return this.mainCurve.isOhlc&&mn.has(e.id)}getRefPriceMapField(e){return this.isOhlcMapping(e)||e===ag.PreviousClose?ag.Close:e}dataOf(e){return this.timeSeries.container.getData(e)}canPriceMap(e,t){let i=this.getRefPriceMapField(t),s=this.dataOf(i),r=null,n=this.visFromIndex;for(;null===r&&n<=this.visToIndex;)r=s[n++];this._priceMapFirstIndex.set(i,null!==r?n-1:NaN)}priceMap(e,t,i,s=!1,r=q.None){let n=this.getRefPriceMapField(i),a=this._priceMapFirstIndex.get(n);if(!Number.isFinite(a))return e;let o=this.dataOf(n)[a];return this.isComparison(q.Percent)||r===q.Percent?s?o+o*e/100:100*Math.abs(e-o)*(e>=o?1:-1)/Math.abs(o):s?o+e:e-o}shouldPriceMap(e,t){return eF(t)?t!==q.None:this.isComparison(q.Percent)||this.isComparison(q.Value)}onPriceDomainsUpdated(){}get presenter(){return this.axis?.pane?.presenter}}class ml extends mo{_symbol;_showPrevious;yearOffset;resolved=null;events;inputs=[];_eventsSeries;compare;get symbol(){return this._symbol}get title(){return this.symbol}get showPrevious(){return this._showPrevious}getPreviousValue(){if(!eF(this.timeSeries)||!eF(this.timeSeries.record))return null;let e=this.axis.pane.presenter.display.chart.previous.field;return this.timeSeries.record.getValue(ag[e])}getTimeSeries(){let e=Sp().getTimeSeriesDataSource(),t=this.makeQuery();switch(t.symbol=this.resolved,this.mainCurve.style){case $.Renko:case $.Kagi:case $.PointAndFigure:t.barsToFetch=10100,t.inputs=this.inputs;break;case $.Range:t.barsToFetch=4e3;break;case $.LineBreak:t.inputs=this.inputs}let i=this.axis.pane;if(eF(i.alignedToYear)){let e=tx(t.symbol);null!==e&&(this.yearOffset=i.alignedToYear-e.getFullYear(),t.offset=this.yearOffset)}let s=e.getTimeSeries(t);this.timeSeries=this.wrapIfAdvancedStyle(s),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:en.Unspecified};this.presenter?.notifyHost(ay.TS_MANYCHANGED,e),this.getEvents()}})}getMetaData(){let e=Sp().getMetaDataSource();this.metaData=e.getMetaData(this.resolved),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this})})}getEvents(){if(!this.hasEvents)return;let e=Sp().getTimeSeriesDataSource(),t={symbol:this.symbol,seriesKind:J.Events,getHashKey:function(){return Object.values(this).filter(e=>"function"!=typeof e).join("|")}};tz.EVENTS.forEach(e=>{t[e]=eG(this.events,!1,e,"show")}),this._eventsSeries=e.getTimeSeries(t),this._eventsSeries.ready().then(e=>{e&&this.presenter?.notifyHost(ay.TS_EVENTSCHANGED,{series:this.eventsSeries})})}get eventsSeries(){return this._eventsSeries??null}get hasEvents(){return!!eF(this.events)&&tz.EVENTS.some(e=>eG(this.events,!1,e,"show"))}findEvents(e){if(!this.hasEventsData||null===e[0]||null===e[1])return[];let t=e[0],i=e[1];if(i>0&&this.axis?.pane?.presenter?.data?.aggregation?.isIntraday){let e=this.timeSeries.container.getTimeData()[i-1];if(this.compare(e,t))return[]}return this.eventsSeries.container.getTimeData().map((e,i)=>this.compare(e,t)?this.getEventsAt(i):[]).flat()}fromModel(e){super.fromModel(e),this._showPrevious=e.showPrevious,this.events=e.events,this.inputs=e.inputs||[],this.compare=function(e){switch(e.unit){case G.Tick:return nO;case G.Intraday:case G.Day:return nM;case G.Week:return nx;case G.Month:return nI;case G.Quarter:return nD;case G.Year:return nE;default:return nO}}(this.axis.pane.presenter.data.aggregation),this._symbol=e.symbol}getEventFor(e){let t=this.events[e.id.toLowerCase()];return eF(t)&&t.show?t:null}async initialize(){return tU.call(this,async()=>(this.resolved=await tm(this.symbol),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class mu extends ml{seriesKind;fundamental;constructor(e){super(),this.seriesKind=e}get showPrevious(){return!1}get title(){return`${this.curves[0].fields[0].name}(${G[this.fundamental].substring(0,1)})`}fromModel(e){this.fundamental=G[e.fundamental],super.fromModel(e)}makeQuery(){let e=new cd(this.symbol,new nw(this.fundamental),this.seriesKind);return e.fields=this.curves[0].fields,e}}class mh{longPressTimeout;constructor(){this.longPressTimeout=null}getTouchCrosshairDelayMillis(){let e=Sp().config.touchCrosshairDelayMillis;return eF(e)&&Number.isFinite(e)?e:tz.LONG_PRESS_DELAY_MILLIS}startLongPress(e,t,i){eO()&&(this.longPressTimeout=setTimeout(()=>this.longPressTriggered(e,t,i),this.getTouchCrosshairDelayMillis()))}longPressTriggered(e,t,i){this.cancelLongPress(),this.performLongPress(e,t,i)}cancelLongPress(){eO()&&eF(this.longPressTimeout)&&(clearTimeout(this.longPressTimeout),this.longPressTimeout=null)}performLongPress(e,t,i){}}function mc(e){return e.locked||e.axis.pane.presenter.display.allAnnotationsLocked}class md extends mh{annotation;previous;cursorSet;moved;snapToSupported;constructor(e,t,i){super(),this.annotation=e,this.previous=t,this.cursorSet=!1,this.moved=!1,this.snapToSupported=!1,this.startLongPress(null,t,i)}performLongPress(e,t,i){m2(this.annotation,i)}onMouseMove(e){if(this.cancelLongPress(),this.annotation.axis.pane.presenter.enableTooltip(!1),mc(this.annotation))return;let{point:t,view:i,offset:s}=e;if(!eH(t)||t.axis!==this.annotation.axis)return;i.drawCrosshair({ap:t,offset:s}),this.cursorSet||(this.previous.axis.pane.presenter.view.setCursor(ee.Move),this.cursorSet=!0);let r=iS(t.point,this.previous.point);this.annotation.offset(r),this.annotation.wasModifiedByTool(),this.annotation.requestRedraw(),this.previous=t,this.moved=!0}onMouseUp(e){this.cancelLongPress(),gq(this.annotation,this.moved,el.Moved)}}class mp{annotation;pointIndex;snapToSupported;moved;alignPointsMode;constructor(e,t){this.annotation=e,this.snapToSupported=!0,this.moved=!1,this.alignPointsMode=!1,this.pointIndex=e.points.indexOf(t)}onMouseMove(e){if(this.alignPointsMode=e.getModifier(ei.Shift),this.annotation.axis.pane.presenter.enableTooltip(!1),mc(this.annotation))return;let{point:t,view:i,offset:s}=e;if(i.drawCrosshair({ap:t,offset:s}),eF(t)){let e=this.annotation.points[this.pointIndex],i=iS(t.point,e.point);switch(e.moveDirection){case es.Both:e.update(t.price,t.time);break;case es.Horizontal:e.update(e.price,t.time);break;case es.Vertical:e.update(t.price,e.time)}this.moved=e.moveDirection!==es.None,this.moved&&this.annotation.wasPointMovedByTool(e,i)}this.annotation.requestRedraw()}onMouseUp(e){gq(this.annotation,this.moved,el.PointMoved)}}class mf{anchor;isVertical;axis;constructor(e,t,i){this.anchor=e,this.isVertical=t,this.axis=i}hitTest(e){return!!eF(this.anchor)&&(this.isVertical?Math.abs(e.x-this.anchor.x)<=tz.HIT_TEST_TOLERANCE:Math.abs(e.y-this.anchor.y)<=tz.HIT_TEST_TOLERANCE)}draw(e){let t=tz.OUT_OF_SCREEN;this.isVertical?iY(e,this.anchor.x,-t,t):ij(e,this.anchor.y,-t,t)}}class mm{id;axis;_price;_time;passive=!1;moveDirection=es.Both;visible=!0;point;constructor(e,t,i){this.id=e1(),this.axis=e,void 0!==t&&void 0!==i&&(this.price=t,this.time=i,this.toPoint())}get price(){return this._price}set price(e){this._price=e}get time(){return this._time}set time(e){this._time=e}get movable(){return this.moveDirection!==es.None}get presenter(){return this.pane.presenter}get pane(){return this.axis.pane}toPoint(){let e=this.axis.toPoint(this);eF(e)&&ek(e.x)&&ek(e.y)&&(this.point=e)}update(e,t){this.price=e,this.time="number"==typeof t?new Date(t):t,this.toPoint()}updateFromPoint(e){let t=this.axis.toAnnotationPoint(e);this.price=t.price,this.time=t.time,this.point=e}hitTest(e){return!!this.visible&&this.distance(e)<=tz.HIT_TEST_TOLERANCE}distance(e){let t=e.x-this.point.x,i=e.y-this.point.y;return Math.abs(Math.sqrt(t*t+i*i)-tz.HALF_ANN_POINT_DIMENSION)}draw(e,t){if(eF(this.point)){let i=tz.HALF_ANN_POINT_DIMENSION;eF(t)&&t.locked&&(i*=.6),e.beginPath(),e.ellipse(this.point.x,this.point.y,i,i,0,0,2*Math.PI),e.stroke()}}}function mg(e){return 0===iM(e.fill.color).a?e.line.color:e.fill.color}function my(e,t){return{uid:e.uid,id:e.name,traits:{...e.extractTraits(!0),...e.extractTraits(!1)},extras:{},points:e.extractPoints(),visible:e.visible,locked:e.locked,isUndoRedo:!0,toolChange:t}}function mS(e){return{uid:e.uid,id:e.name,traits:e.extractTraits(!0),extras:e.extractTraits(!1),points:e.extractPoints(),visible:e.visible,locked:e.locked,chart:e.axis.pane.presenter.accessor}}class mA{points=[];isSelected=!1;drawn=!0;axis;name;uid;alignPointsSupported=!1;visible=!0;locked=!1;computed=!1;_traits;adjustFill;constructor(e,t){this.axis=e,this.name=t,this.uid=e1()}requestRedraw(){this.axis.pane.presenter.view?.redraw()}prepareDraw(e,t){return this.drawPoints(e,t),this.readyToDraw()}readyToDraw(){return this.activePoints.every(e=>void 0!==e.point)}getPriceScaleAdornments(){return tz.EMPTY_ARRAY}getTimeScaleAdornments(){return tz.EMPTY_ARRAY}extractTraits(e=!0){let t=ez(this.traits),i=sv(this.name);return Object.keys(t).forEach(s=>{let r=i.includes(s);(e&&!r||!e&&r)&&delete t[s]}),e||["line","fill","zIndex"].forEach(e=>delete t[e]),t}extractPoints(){return this.activePoints.map(e=>({price:e.price,time:eB(+e.time,4)}))}offset(e){this.points.filter(e=>e.movable).forEach(t=>{t.updateFromPoint(iA(t.point,e))})}get traits(){return this._traits||(this._traits=ez(this.defaultTraits)),this.adjustFill&&(this._traits.fill.color=mg(this._traits),this.adjustFill=!1),this._traits}set traits(e){void 0!==e&&eY(this.traits,e,!1)}get activePoints(){return this.points.filter(e=>!e.passive)}get style(){return i8(this.traits)}get defaultTraits(){return i6(this.axis.pane.presenter.display,this.name)}get defaultStyle(){return i8(this.defaultTraits)}get adornStyle(){let e=ez(this.defaultTraits);return e.fill.color=this.traits.line.color,e.line.width=0,e.line.color=tz.COLOR_TRANSPARENT,i8(e)}get pointsStyle(){let e=ez(this.defaultTraits);return e.line.dashStyle="Solid",i8(e)}get allowPricesChangeUI(){return this.traits?.allowPricesChangeUI}wasModifiedByTool(){}wasPointMovedByTool(e,t){}isPointDrawn(e){return void 0!==e.price}drawPoints(e,t){this.points.forEach(i=>{let s=this.isPointDrawn(i),r=eF(e);t&&(s||!r)&&i.toPoint(),r&&s&&(this.isSelected||this.drawn)&&(i7(e,this.pointsStyle),i.draw(e,this))})}addPoints(e){for(let t=0;t<e;t++)this.points.push(new mm(this.axis))}toModel(){let e=this.extractPoints();return{id:this.name,uid:this.uid,visible:this.visible,locked:this.locked,points:e,traits:ez(this.traits)}}canMove(e){return!0}updatePoints(e){}updateActivePoints(e){let t=this.activePoints;t.length===e.length&&t.forEach((t,i)=>{let s=e[i];t.update(s.price,s.time)})}updateFrom(e,t,i,s,r){"boolean"==typeof s&&(this.visible=s),"boolean"==typeof r&&(this.locked=r);let n=eF(e)?ez(e):{};eF(t)&&eY(n,t,!1),this.traits=n,eF(i)&&this.updatePoints(i)}priceMap(e){return this.axis.priceMap(e)}flip(e){let t=this.getFlipAnchorIndices();if(!eH(t))return;let i=this.points[t[0]],s=this.points[t[1]];if(e){let e=s.time;s.update(s.price,i.time),i.update(i.price,e)}else{let e=s.price;s.update(i.price,s.time),i.update(e,i.time)}this.wasModifiedByTool()}getFlipAnchorIndices(){return null}}function mT(e,t,i,s){return function(r,n=!0){let a=new t(r,e,i);return n?r.appendAnnotation(a):a.drawn=!1,eF(s)&&(a.traits=s),a}}class mv{axis;angle;extent;anchor1;anchor2;p1;p2;style;extended;_data;isTrend;constructor(e,t,i,s,r){this.axis=r,eF(e,t)&&(this.angle=iT(e,t),this.extent=this.getExtent(e,t),this.anchor1=e,this.anchor2=t,this.p1=i?this.extendPoint(t,-1):e,this.p2=s?this.extendPoint(e,1):t),this.extended=i||s}extendPoint(e,t){return{x:e.x+t*this.extent*Math.cos(this.angle),y:e.y+t*this.extent*Math.sin(this.angle)}}getExtent(e,t){let i=Math.max(Math.abs(e.x),Math.abs(t.x)),s=Math.max(Math.abs(e.y),Math.abs(t.y));return Math.sqrt(i*i+s*s)+tz.OUT_OF_SCREEN}hitTest(e){return!!eF(this.p1,this.p2)&&iv([this.p1,this.p2],e,tz.HIT_TEST_TOLERANCE)}draw(e){eF(this.p1,this.p2)&&(iz(e,this.p1,this.p2),this.extended)}getAdornOffset(e){var t,i;let s=ik(e),r=iF(e,1);return t=this.p1,i=this.p2,-(t.y-i.y)/(t.x-i.x)<0&&(s.y=r+5),s}}class mP{style;axis;rect;constructor(e,t,i,s){this.axis=s,this.rect=new iw(e.x,e.y,t,i)}hitTest(e){return this.rect.contains(e)}draw(e,t){i$(e,this.rect)}}class mC extends mA{countCache;constructor(e,t){super(e,t)}draw(e,t){if(this.prepareDraw(e,t)&&!this.drawn){let t=this.getElements();i7(e,this.style),t.forEach((t,i)=>{i7(e,this.getStyleForElement(t,i)),t.draw(e)}),i7(e,this.adornStyle),this.adornElements(t,e);let i=this.getMarkers();i7(e,this.style),i.forEach(t=>{t.draw(e)})}}getBarCount(e,t){if(void 0===this.countCache||this.countCache.time1!==e||this.countCache.time2!==t){let i=this.axis.pane.presenter.view,s=Math.abs(i.toIndex(e)-i.toIndex(t));this.countCache={time1:e,time2:t,barCount:s}}return this.countCache.barCount}getElements(){return[]}get presenter(){return this.axis.pane.presenter}get formatter(){return this.presenter.mainPlot.metaData}data(e){return this.presenter.mainPlot.timeSeries.container.getData(e)}getScreenPoints(){return this.points.map(e=>e.point)}getStyleForElement(e,t){return this.style}adornElements(e,t){}hitTestAdornments(e,t){return!1}getTextRef(){return null}hitTest(e){if(!this.drawn&&this.visible){let t=this.getElements(),i=this.getMarkers();return!!(t.some(t=>t.hitTest(e))||i.some(t=>t.hitTest(e)))||this.hitTestAdornments(t,e)}return!1}updatePointsFrom(e,t=0){e.forEach((e,i)=>this.points[t+i].update(e.price,e.time))}updatePoints(e){this.allowPricesChangeUI&&this.updatePointsFrom(e)}getMarkers(){return[]}get marker(){return this.traits?.marker}get showPrices(){return this.traits?.showPrices}get singleStyle(){var e;return e=this.traits?.singleStyle,!eF(e)||e}get showBackground(){var e;return e=this.traits?.showBackground,!!eF(e)&&e}get backgroundOpacity(){var e;return eF(e=this.traits?.backgroundOpacity)?e:0}fillOnlyStyle(e){return i8({line:{color:tz.COLOR_TRANSPARENT,dashStyle:"Solid",width:0},fill:this.traits[e]})}lineOnlyStyle(e){return i8({fill:{color:tz.COLOR_TRANSPARENT},line:this.traits[e]})}makeLine(e,t){return new mv(e,t,!1,!1,this.axis)}applyBackgroundOpacity(e){return ib(iC(e),this.backgroundOpacity)}getTraitsFor(e){let t={fill:{color:tz.COLOR_TRANSPARENT},line:{...e.line}};return this.showBackground&&(t.fill.color=this.applyBackgroundOpacity(t.line.color)),t}getFlipAnchorIndices(){return 2===this.points.length?[0,1]:null}}class mb extends mC{_factors;constructor(e,t){super(e,t)}get factorsPropName(){return tz.AT_FACTORS}get factors(){return i1(this._factors??this.traits[this.factorsPropName])}getStyleForElement(e,t){return e.style??super.getStyleForElement(e,t)}get showLevels(){return this.traits[tz.AT_SHOW_LEVELS]}get levelsKind(){return this.traits[tz.AT_LEVELS_KIND]}get labels(){return this.traits[tz.AT_LABELS]}get isExtended(){return 3===this.points.length}isBefore(e,t){return this.points[e].time<this.points[t].time}comparePoints(e,t,i){let s=this.isBefore(e,t);return i||(s=!s),this.points[s?e:t].point}getPoint(e){return this.isExtended?this.comparePoints(1,2,e):this.comparePoints(0,1,e)}get leftPoint(){return this.getPoint(!0)}get rightPoint(){return this.getPoint(!1)}get pricesOnScale(){return this.traits[tz.AT_PRICES_ON_SCALE]}formatLevelPrice(e,t){let i=this.levelsKind===tz.AT_LEVELS_PERCENTS,s="";if(this.showLevels&&(s=i?`${(100*e).toFixed(1)}%`:e.toString()),this.showPrices){let e=this.priceMap(this.axis.toPrice(t));s=(s+` (${h_(this.axis,e)})`).trim()}return s}getAdornPointAndAlign(e,t){let i=this.labels,s=e instanceof mv,r=(e,t,i)=>({pt:e,align:t,offset:i});switch(i){case tz.AT_LABELS_LEFT:return r(s?e.anchor1:e,Q.Right,-t);default:case tz.AT_LABELS_RIGHT:return r(s?e.anchor2:e,Q.Left,t);case tz.AT_LABELS_CENTER:return r(s?ig(e.anchor1,e.anchor2):e,Q.Center,0)}}getColoredElements(e){let t=this.singleStyle;return this.factors.map(i=>{let s=e(i);return null===s?null:(t||(s.style=i8(this.getTraitsFor(i))),s._data={factor:i.value},s)}).filter(e=>null!==e)}hitTestAdornments(e,t){let i=this.showLevels,s=this.getTextRef();if(!i||null===s)return!1;let r=this.axis.pane.presenter,n=r.view?.mainContext;if(!n)return!1;let a=null,o=!1;n.save();let{chart:{fontFamily:l},yAxis:{fontSize:u}}=r.display;for(let i of(n.font=`${u??12}px ${l}`,e)){if(!eF(i._data))continue;let{factor:e}=i._data,{ref:r,spacing:l,offsetY:u,text:h}=s(a,i,e),{pt:c,align:d,offset:p}=this.getAdornPointAndAlign(r,l),f=this.getAdornTextPoint(n,u,c,p);if(iW(n,h,f,d).contains(t)){o=!0;break}a=i}return n.restore(),o}adornElementsForColoredFactors(e,t,i,s){let r=this.singleStyle,n=this.showBackground,a=this.showLevels,o=this.applyBackgroundOpacity(this.traits.line.color),l=s.fillStyle,u=null;e.forEach(e=>{if(!eF(e._data))return;let{factor:h}=e._data;if(n){let i=t(u,e);s.fillStyle=r?o:e.style.fillStyle,s.fill(i)}if(a){let{ref:t,spacing:n,offsetY:a,text:o}=i(u,e,h),{pt:c,align:d,offset:p}=this.getAdornPointAndAlign(t,n),f=this.getAdornTextPoint(s,a,c,p);iU(s,o,f,d,r?l:e.style.strokeStyle)}u=e})}getAdornTextPoint(e,t,i,s){let r=iF(e,.75);return iA(i,{x:s,y:!0===t?r/2:t})}}class mE extends mC{lines;constructor(e,t){super(e,t),this.resetComputedState()}get rectStyle(){return this.fillOnlyStyle(tz.AT_FILL)}get rect(){let[e,t,,]=this.getScreenPoints(),i=new mP({x:e.x,y:Math.min(e.y,t.y)},t.x-e.x,Math.abs(e.y-t.y),this.axis);return i.style=this.rectStyle,i}get reverse(){return!1}getLinesDataAtLevels(e,t){let[i,s]=this.points;if(this.reverse&&([i,s]=[s,i]),null==this.lines){let r=(e,t=!1)=>i=>({level:i.value,domain:e(i.value),traits:this.getTraitsFor(i),isPrice:t}),n=s.price-i.price,a=r(e=>i.price+e*n,!0),o=e?.map(a)??[],l=this.axis.pane.presenter.timeline,u=e_(l,+i.time,Number,hw),h=e_(l,+s.time,Number,hw)-u,c=r(e=>+l.at(u+Math.floor(e*h))),d=t?.map(c)||[];this.lines={prices:o,times:d,barsDiff:h,priceDiff:n}}return this.lines}makeColoredLine(e,t,i){let s=this.makeLine(e,t);return this.singleStyle||(s.style=i8(i.traits)),s._data={level:i.level,isPrice:i.isPrice},s}getLineElements(e){let[t,i]=this.getScreenPoints();return{priceLines:e.prices.map(e=>{let s=this.axis.toY(e.domain);return this.makeColoredLine({x:t.x,y:s},{x:i.x,y:s},e)}),timeLines:e.times.map(e=>{let s=this.presenter.view.toX(e.domain);return this.makeColoredLine({x:s,y:t.y},{x:s,y:i.y},e)})}}getStyleForElement(e,t){return e.style||super.getStyleForElement(e,t)}resetComputedState(){}wasModifiedByTool(){this.resetComputedState()}wasPointMovedByTool(e,t){this.wasModifiedByTool()}updatePoints(e){super.updatePoints(e),this.wasModifiedByTool()}}class mL extends mm{priceRef;timeRef;constructor(e,t,i){super(e),this.priceRef=t,this.timeRef=i,this.passive=!0}get price(){return this.priceRef.price}get time(){return this.timeRef.time}set price(e){this.priceRef.price=e}set time(e){this.timeRef.time=e}}class m_{points;constructor(e){this.points=e}get left(){return Math.min(this.points[0].point.x,this.points[1].point.x)}get top(){return Math.min(this.points[0].point.y,this.points[1].point.y)}get width(){return Math.abs(this.points[1].point.x-this.points[0].point.x)}get height(){return Math.abs(this.points[1].point.y-this.points[0].point.y)}getRect(){return eF(this.points[0].point,this.points[1].point)?new iw(this.left,this.top,this.width,this.height):null}}function mM(e){let t=new mm(e),i=new mm(e),s=new mL(e,t,i),r=new mL(e,i,t);return[t,i,s,r]}class mx extends mA{helper;constructor(e,t){super(e,t),this.points=mM(e),this.helper=new m_(this.points)}get left(){return this.helper.left}get top(){return this.helper.top}get width(){return this.helper.width}get height(){return this.helper.height}getRect(){return this.helper.getRect()}draw(e,t){return!!this.prepareDraw(e,t)&&(i7(e,this.style),!0)}updatePoints(e){this.allowPricesChangeUI&&2===e.length&&e.forEach((e,t)=>this.points[t].update(e.price,e.time))}}class mI{points;lines;axis;helper;_actualWidth;_fontSizeForWidth;constructor(e,t,i){this.points=e,this.lines=t,this.axis=i,this._actualWidth=0,this._fontSizeForWidth=0,this.helper=new m_(this.points)}hitTest(e){let t=this.getRect();return!!eH(t)&&(t.width=this._actualWidth,t.contains(e))}getRect(){return this.helper.getRect()}get fontSize(){if(0===this.lines.length)return 0;let{height:e}=this.getRect();return Math.floor(e/this.lines.length)}computeActualWidth(e){(this._actualWidth<=0||this._fontSizeForWidth!==this.fontSize)&&(this._actualWidth=Math.max(...this.lines.map(t=>e.measureText(t).width)),this._fontSizeForWidth=this.fontSize)}draw(e){if(0===this.lines.length)return;e.save();let{x:t,y:i}=this.getRect(),{chart:{fontFamily:s}}=this.axis.pane.presenter.display,r=this.fontSize;e.textAlign="left",e.textBaseline="top",e.font=`${r}px ${s}`,this.lines.forEach((s,n)=>{let a=r*n;e.fillText(s,t,i+a)}),this.computeActualWidth(e),e.restore()}}class mD extends mC{textEditable;_textAnnElement;constructor(e,t){super(e,t),this.textEditable=!0,this.points=mM(e),this.adjustFill=!0}get textLines(){return this.traits[tz.AT_TEXT_LINES]}set textLines(e){this.traits[tz.AT_TEXT_LINES]=e,this._textAnnElement=void 0}get textElement(){return!eF(this._textAnnElement)&&this.visible&&(this._textAnnElement=new mI(this.points,this.textLines,this.axis)),this._textAnnElement}updateFrom(e,t,i,s,r){super.updateFrom(e,t,i,s,r),this._textAnnElement=void 0}getElements(){return this.visible?[this.textElement]:[]}}class mO extends mD{constructor(e,t){super(e,t),this.textEditable=!1}canMove(e){return!!this.visible&&this.textElement.hitTest(e)}get prices(){return this.traits.prices}get pricesPoints(){let e=this.points[0].time;return this.prices.map(t=>new mm(this.axis,t,e))}updateFrom(e,t,i,s,r){super.updateFrom(e,t,i,s,r),eF(e?.textLines)&&(this.textLines=e.textLines)}getElements(){let e=super.getElements(),t=this.pricesPoints.map(e=>new mf(e.point,!1,this.axis));return e.concat(t)}getPriceScaleAdornments(){if(!this.showPrices)return super.getPriceScaleAdornments();let e=this.traits.line;return this.prices.map(t=>({price:t,color:e.color}))}get defaultFont(){let{chart:{fontSize:e,fontFamily:t}}=this.axis.pane.presenter.display;return[e??13,t]}updateOtherPoints(e){let[t,i]=this.defaultFont;e.save(),e.font=`${t}px ${i}`;let s=Math.max(...this.textLines.map(t=>e.measureText(t).width)),{x:r,y:n}=this.points[0].point;this.points[1].updateFromPoint({x:r+s,y:n+this.textLines.length*t}),e.restore()}}class mw{annId;annotation;constructor(e){this.annId=e}onKeyDown(e){if(null==this.annId)return;let{key:t,code:i,presenter:s}=e;ew(t,i)&&(eF(this.annotation)&&(this.annotation.axis.deleteAnnotation(this.annotation,!1),s.view.redraw()),gK(s,{toolChange:el.Cancelled,annId:this.annId}))}}class mR extends mw{factory;thirdPoint;dragged;snapToSupported;isDrawingAnnotation;forceAlignPoints;indices;alignPointsMode;constructor(e,t=!1){super(e.annName),this.factory=e,this.thirdPoint=t,this.dragged=!1,this.snapToSupported=!0,this.isDrawingAnnotation=!0,this.forceAlignPoints=!1,this.alignPointsMode=!1,this.indices=t?[0,1,2]:[0,1]}signalChange(){this.annotation.wasModifiedByTool(),this.annotation.requestRedraw()}onMouseDown(e){let{point:t,button:i}=e;if(void 0===t)return;let s=eH(this.annotation);if(i===et.Left)if(s){let e=!this.thirdPoint||this.dragged?1:2;this.annotation.points[e].update(t.price,t.time),this.dragged=!1,this.signalChange(),this.thirdPoint&&2!==e||this.finish()}else this.dragged=!0,t.axis.pane.presenter.clearSelection(),this.annotation=this.factory(t.axis),this.annotation.drawn=!1,this.indices.forEach(e=>this.annotation.points[e].update(t.price,t.time)),this.signalChange();return!0}onMouseMove(e){let{point:t,view:i,offset:s}=e;return i.drawCrosshair({ap:t,offset:s}),eF(this.annotation,t)&&(this.alignPointsMode=this.forceAlignPoints||e.getModifier(ei.Shift),this.dragged?(this.annotation.points[1].update(t.price,t.time),this.signalChange()):this.thirdPoint&&!this.dragged&&(this.annotation.points[2].update(t.price,t.time),this.signalChange())),!0}finish(){gq(this.annotation,!0,el.Created)}isAccidentalMouseUp(e){let{point:t}=e,i=this.annotation.points[0].point;return iy(t.point,i)<tz.HIT_TEST_TOLERANCE}onMouseUp(e){if(void 0===this.annotation)return void gZ(e);if(this.isAccidentalMouseUp(e)){this.dragged=!0;return}this.dragged=!1,this.thirdPoint||this.finish()}}class mN extends mR{constructor(e,t=!1){super(e,t),this.forceAlignPoints=!0}}class mV extends mR{constructor(e){super(e,!1),this.snapToSupported=!1}onMouseMove(e){let{point:t,view:i,offset:s}=e;if(i.drawCrosshair({ap:t,offset:s}),eF(this.annotation)&&this.dragged){let[e,i]=this.annotation.points;i.update(t.price,t.time);let s=iS(i.point,e.point),r=e.point.y+s.x*Math.sign(s.y)*Math.sign(s.x),n=this.annotation.axis.toPrice(r);i.update(n,t.time),this.signalChange()}return!0}}class mH extends mw{factory;existing;isNew;anchor;clicks;snapToSupported;isDrawingAnnotation;textArea;constructor(e,t){super(e?e.annName:null),this.factory=e,this.existing=t,this.clicks=0,this.snapToSupported=!1,this.isNew=!eF(t),this.isNew||(this.anchor=this.existing.points[0]),this.isDrawingAnnotation=this.isNew}getChartParent(){return this.anchor.axis.pane.presenter.view.canvasContainer}styleProps(){if(this.isNew)return{height:100,fontSize:"100%",color:mg(i6(this.anchor.axis.pane.presenter.display,"Text"))};{let e=this.existing.textElement;return{height:1.05*e.getRect().height,fontSize:`${Math.round(e.fontSize)}px`,color:this.existing.traits[tz.AT_FILL].color}}}onMouseDown(e){let{point:t}=e;if(this.isNew)if(0===this.clicks){if(void 0===t)return void gZ(e);t.axis.pane.presenter.clearSelection(),this.anchor=t,this.clicks++,this.startEditing()}else this.onEndEditing();else this.onEndEditing()}startEditing(){this.textArea=document.createElement("textarea");let{x:e,y:t}=this.anchor.point,i=this.anchor.axis.pane.getBounds(),s=i.x+i.width-this.anchor.point.x,{height:r,fontSize:n,color:a}=this.styleProps();tN(this.textArea,{position:"absolute",top:`${t}px`,left:`${e}px`,border:"none",outline:"none",overflow:"hidden",height:`${r}px`,width:`${s}px`,resize:"none",backgroundColor:"rgba(255, 255, 255, 0.05)",zIndex:"5",fontSize:n,color:a}),this.getChartParent().appendChild(this.textArea),this.textArea.onblur=this.onEndEditing.bind(this),this.textArea.onkeydown=e=>e.stopImmediatePropagation(),this.isNew||(this.textArea.value=this.existing.textLines.join("\n"),this.existing.textLines=[""],this.existing.requestRedraw()),setTimeout(()=>this.textArea.focus(),100)}onEndEditing(){let e=this.anchor,t=this.isNew?this.factory(e.axis):this.existing,i=this.textArea.value.split("\n");if(this.isNew){let{actualWidth:s,actualHeight:r}=this.getTextDimensions(i);t.points[0].update(e.price,e.time);let{x:n,y:a}=t.points[0].point;t.points[1].updateFromPoint({x:n+s,y:a+r}),t.drawn=!1}t.textLines=i,this.textArea.onblur=null,this.getChartParent().removeChild(this.textArea),t.requestRedraw(),this.isNew||t.requestRedraw(),gq(t,!0,this.isNew?el.Created:el.TextChanged)}getTextDimensions(e){let t=globalThis.getComputedStyle(this.textArea).getPropertyValue("font-size"),i=parseFloat(t)*e.length,s=0,r=this.anchor.axis.pane.presenter,n=r.view.mainContext;n.save();let{chart:{fontFamily:a}}=r.display;n.font=`${t} ${a}`;for(let t=0;t<e.length;t++){let i=n.measureText(e[t]).width;i>s&&(s=i)}return n.restore(),{actualWidth:s,actualHeight:i}}}function mF(e){return Sp().config.tooltipMovement===e}function mB(){return mF("Draggable")}let mk=tz.TOOLTIP_STD_LEGACY_CLASS,mW=tz.TOOLTIP_STD_CLASS,mU=tz.TOOLTIP_BUBBLE_CLASS;class m${view;tooltipElem;leftSide;mode;isDrag;canDrag;isToggling;constructor(e){this.view=e,this.isDrag=!1,this.tooltipElem=tB(e.el,"div"),tV(this.tooltipElem,{id:`${e.presenter.elementId}-global-tooltip`,class:`${mW} ${mk}`}),this.leftSide=!0,tN(this.tooltipElem,{visibility:"hidden",position:"absolute",cursor:mB()?"move":"default",zIndex:20,top:`${tz.TOOLTIP_Y_OFFSET}px`,left:`${tz.TOOLTIP_X_OFFSET}px`}),this.setMode(e.presenter.display.tooltip.mode),this.handleMouseMove=this.handleMouseMove.bind(this),this.startDrag=this.startDrag.bind(this),this.stopDrag=this.stopDrag.bind(this),this.view.el.addEventListener("mousemove",this.handleMouseMove),this.view.el.addEventListener("mouseleave",this.stopDrag),this.tooltipElem.addEventListener("mousedown",this.startDrag),this.tooltipElem.addEventListener("mouseup",this.stopDrag)}startDrag(){this.isDrag=!0}stopDrag(){this.isDrag=!1}setMode(e){if(this.mode!==e){if(this.mode=e,e===tz.TOOLTIP_BUBBLE)this.canDrag=!1,this.tooltipElem.style.transition="none",this.tooltipElem.classList.remove(mW,mk),this.tooltipElem.classList.add(mU),tN(this.tooltipElem,{pointerEvents:"none"});else if(e===tz.TOOLTIP_STD){this.canDrag=mB(),this.tooltipElem.classList.remove(mU),this.tooltipElem.classList.add(mW,mk);let e=tz.TOOLTIP_TOGGLE_SIDE_ANIM_MS;tN(this.tooltipElem,{pointerEvents:"all",top:`${tz.TOOLTIP_Y_OFFSET}px`,left:`${tz.TOOLTIP_X_OFFSET}px`,transition:mF("Auto")?`left ${e}ms ease-out`:null})}}}show(e,t){let i=this.tooltipElem;if(t){let{width:e,height:s,leftOffset:r,rightOffset:n}=this.view,a=i.getBoundingClientRect(),o=a.width/2,l=i.style,u=s*tz.TOOLTIP_BUBBLE_OFFSET,h=t.yMin-a.height-u,c=t.x-o,d=t.yMax+u,p=d+a.height,f=c,m=e-n;f<r?f=r:f+a.width>m&&(f=m-a.width),l.top=`${h<0?p<s?d:0:h}px`,l.left=`${f}px`}"hidden"===i.style.visibility&&(i.style.visibility="visible"),tW(i,e)}hide(){this.tooltipElem.style.visibility="hidden"}remove(){this.view.el.removeEventListener("mousemove",this.handleMouseMove),this.view.el.removeEventListener("mouseleave",this.stopDrag),this.tooltipElem.removeEventListener("mousedown",this.startDrag),this.tooltipElem.removeEventListener("mouseup",this.stopDrag),this.tooltipElem.remove()}reposition(e,t){tN(this.tooltipElem,{left:`${e}px`,top:`${t}px`})}isAutoMove(){return this.mode===tz.TOOLTIP_STD&&mF("Auto")}handleMouseMove(e){if(this.isDrag&&this.canDrag){let{movementX:t,movementY:i}=e,{top:s,left:r}=this.tooltipElem.style,n=parseInt(s)+i,a=parseInt(r)+t;this.reposition(a,n)}else if(this.isAutoMove()){let t=this.tooltipElem.getBoundingClientRect(),i=this.view.el.getBoundingClientRect(),s=e.pageX,r=tz.TOOLTIP_TOGGLE_DISTANCE_TOLERANCE,n=i.width>2*t.width,a=s>t.x&&s<=t.right+r,o=s<t.x&&s>=t.x-r;n&&(a||o)&&this.toggleSide()}}repositionAuto(){if(this.isAutoMove()){let e=this.view.presenter.mainPane.getBoundsWithoutScales(),t=this.tooltipElem.offsetY,i=e.x+(this.leftSide?tz.TOOLTIP_X_OFFSET:e.width-this.tooltipElem.offsetWidth-tz.TOOLTIP_X_OFFSET);this.reposition(i,t)}}toggleSide(){this.isToggling||(this.isToggling=!0,setTimeout(()=>this.isToggling=!1,tz.TOOLTIP_TOGGLE_SIDE_ANIM_MS),this.leftSide=!this.leftSide,this.repositionAuto())}}function mG(e){e.showTooltip&&mz(e,{time:tz.ZERO_DATE,offset:tz.OFFSCREEN_OFFSET,price:0,lastBarRefresh:void 0,justMain:void 0})}function mz(e,{time:t,lastBarRefresh:i,justMain:s,offset:r,price:n}){let a=hY(e,t,r,i,s,n),{mode:o,showMainPlot:l,hideSymbols:u,revealingClose:h}=e.display.tooltip,{includeTimestamp:c,showMainPlot:d,showPlotActions:p}=Sp().config.tooltipHeaders||{},f=eF(d)?d:l,m=!!eF(c)&&c,g=!!eF(u)&&u,y=!!eF(h)&&h,S=!!eF(p)&&p,A=t.valueOf()===tz.ZERO_DATE.valueOf();switch(o){case tz.TOOLTIP_CARDS:s||mj(e,a,f,!A,m&&!A,!1,g,y,S,e.hasLegend?e.view?.legend?.getLegendElem().clientHeight:0);break;case tz.TOOLTIP_BUBBLE:if(!A){let t=a.panes.find(e=>{let{top:t,left:i,width:s,height:n}=e.bounds;return new iw(i,t,s,n).contains(r)}),i=t.plots.find(e=>e.isMain)||t.plots[0],s=i.values.find(e=>["Close","Last"].includes(e.id)),n=s?s.y:i.values[0].y,o=t.plots.map(e=>e.values.filter(e=>"Change"!==e.id&&e.y>0).map(e=>e.y)).flat(),l=hF({...a,hideSymbols:g,revealingClose:y,plots:t.plots}),u=`<div class="bubble-box">${l}</div>`;e.view.tooltip.show(u,{x:r.x,y:n,yMin:Math.min(...o),yMax:Math.max(...o)})}mj(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tz.TOOLTIP_STD:if(!A){let t=hF({...a,hideSymbols:g,revealingClose:y,plots:a.panes.map(e=>e.plots).flat()});e.view.tooltip.show(t)}mj(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tz.TOOLTIP_EXTERNAL:e.notifyHost(ay.CH_TOOLTIPCHANGED,a);break;default:console.warn(`Unknown tooltip mode requested: ${o}`)}}function mY(e,t,i,s,r,n){tN(e,{position:"absolute",display:"flex","flex-direction":t,"flex-wrap":"wrap",left:`${i+tz.CARDS_X_OFFSET}px`,top:`${r+tz.CARDS_Y_OFFSET}px`,maxWidth:`${n-s-2*tz.CARDS_X_OFFSET}px`})}function mj(e,t,i=!1,s=!1,r=!1,n=!1,a=!1,o=!1,l=!1,u=0){let h=e.view.el,c=function(e,{panes:t,date:i,time:s,isMultiSymbol:r},n=!1,a=!1,o=!1,l=!1,u=!1,h=!1){return t.map((c,d)=>{let p=n?c.plots:c.plots.filter(e=>!e.isMain),f=e.mainPlot.axis.pane.id===c.id,m=o&&f?`<span class="field-name" style="padding-right:5px">${i} ${s||""}</span>`:"",g=p.map(t=>(function(e,t,i,s,r,n,a,o){let{id:l,name:u,type:h,error:c,description:d,values:p,events:f,isMain:m}=e,g=o.display.tooltip,y=c||d,S=`value-title${m?" value-main":""}`,A=Z[h],T=!(["Study","BalanceSheet","IncomeStatement"].includes(A)||"Expression"===A&&!i)||o.hasLegend&&i?"":hz(l),v=function(e,t){let i=hk(t?"eye":"eyeSlash"),s=t?"Hide":"Show",r=`${s} plot`;return`<a class="show-hide-plot" data-plot-id="${e}" data-act="${s}" title="${r}">${i}</a>`}(l,e.visible),P=a?function(e){let t=hk("moreActions");return`<a class="more-actions" data-plot-id="${e}" data-act="Menu" title="Actions">${t}</a>`}(l):"",C=hV(o)&&e.type===Z.Symbol,b=(m||C)&&(!s||e.values.length>1),E=t?p.map(e=>hG(b?e.abbreviation:"Close"===e.id&&n?d+" ":null,e.value,e.color)).join(" ")+function(e){if(e&&e.length){let t=e.map(e=>hG(`${e.field.name} (${hD(hH,e.date)})`,e.value,e.color)).join(" ");return`Event ${t}`}return""}(f):"",L=!m&&"Expression"!==A,_=p.slice(0,L?p.length:1).map(e=>`<div class="box" style="background-color:${e.color}"></div>`).join(""),M="Name"===g.mainTitle?u:d,x=r?e.visible&&t?"":`${d}`:`${M}`,I=s&&C?`${d} (${x})`:x;g.showMainTitle||(I="");let D=e.isMain?(()=>{let e=o.data?.aggregation.toShortString(),t=o.data?.aggregation.describe();return`<span class="value-main" title="${t}">&centerdot;${e}&centerdot;</span>`})():"";return`
13
13
  <div class="plot">
14
14
  ${T} ${v} ${P} ${t?"":_}
15
15
  <a class="${S}" ${y?`title="${y}" `:""}data-plot-id="${l}">${I}</a>
16
16
  ${D} ${E}
17
17
  </div>
18
- `.trim()})(t,a,f,r,l,u,h,e)),y=`${m}${g.join("")}`,S=function(e,t){let i=e>0,s=e<t-1;return`${i?hW(!0,e):""} ${s?hW(!1,e):""}`.trim()}(d,t.length);return{id:`bc-tip-${c.id.substring(0,8)}`,isMainPane:f,content:y,moveContent:S,bounds:c.bounds}})}(e,t,i,s,r,a,o,l);c.some(e=>!eF(e.bounds))||c.forEach(({id:t,isMainPane:i,content:s,moveContent:r,bounds:{left:a,right:o,top:l,width:c}},d)=>{if(""!==s&&(!n||!i)){let r=tH(t,h,"div");mY(r,i&&hV(e)?"column":"row",a,o,l+u,c),tF(r,{"bcharts-card":!0,"bcharts-card-main":i,"bcharts-card-first":0===d}),r.innerHTML=s}let p=tR(`#right-${t}`,h);eF(p)||((p=document.createElement("div")).id=`right-${t}`,h.appendChild(p),tF(p,"bcharts-card bcharts-card-move")),tN(p,{position:"absolute",display:"block",right:`${o+tz.CARDS_X_OFFSET}px`,top:`${l+u+tz.CARDS_Y_OFFSET}px`}),p.innerHTML=r})}let mK=null;function mq(){return null===mK&&(mK=Sp().config.hostingModel===eo[eo.Application]),mK}class mX extends mh{ap;presenter;panY;snapToSupported;warmUp;preventDefault;lastOffset;lastPanningExtremes;constructor(e){super(),this.ap=e,this.snapToSupported=!1,this.warmUp=!0,this.preventDefault=!1,this.presenter=e.presenter,this.panY=e.axis.isCustomDomain}activated(){}deactivated(){this.cancelLongPress()}startPan(e){this.startLongPress(this.presenter,this.ap,e),this.lastOffset=e,this.lastPanningExtremes=this.ap.axis.yScale.domain();let t=this.ap.presenter;t.enableTooltip(!1),t.view.tooltip.hide(),t.view.drawCrosshair({ap:void 0})}onMouseMove(e){if(e.pinchZoom)return void this.presenter.resetActiveTool();let{point:t,view:i,offset:s}=e;if(t&&t.axis!==this.ap.axis)return;let{x:r,y:n}=s,a=r-this.lastOffset.x,o=Math.abs(a),l=this.lastOffset.y,u=Math.abs(n-l);o>=1&&this.cancelLongPress();let h=mq();if(eO()&&!h&&this.warmUp)return(o>7||u>7)&&(this.warmUp=!1,this.preventDefault=o>u),!1;if(this.preventDefault||!eO()||h){if(i.xAxis.pan(a),this.panY&&t&&t.axis){u>=1&&this.cancelLongPress();let e=function(e,t,i,s){let r=(i-t)/e.viewBox.height,[n,a]=s,o=r*(a-n);return[n+o,a+o]}(t.axis,l,n,this.lastPanningExtremes);this.lastPanningExtremes=e,t.axis.yScale.domain(e)}this.lastOffset=s,i.redraw(),t&&t.presenter.view.setCursor(ee.Grabbing)}return h||this.preventDefault}finished(){gK(this.presenter)}onMouseLeave(){this.finished()}onMouseUp(){this.finished()}onMouseDblClick({presenter:e,offset:t,originalEvent:i}){eO()&&m3(e,t,i)}performLongPress(e,t,i){e.enableTooltip(!0),e.resetActiveTool(),e.activeTool.startTouchCrosshairMode(e,t,i)}}let mZ=null;class mJ extends mx{constructor(e,t){super(e,t)}hitTest(e){if(!this.visible)return!1;let t=this.getRect();return null!==t&&t.contains(e)}draw(e,t){return!!super.draw(e,t)&&(i$(e,this.getRect()),!0)}}function mQ(e,t){return e<t?[e,t]:[t,e]}let m0={line:{width:1,color:"rgba(127, 127, 127, 0.3)",dashStyle:"LongDash"},fill:{color:"rgba(127, 127, 127, 0.1)"}};class m1 extends mR{snapToSupported=!1;preventDefault=!1;axis;presenter;constructor(){super(mT("Rectangle",mJ,null,m0),!1)}activated(){}deactivated(){eF(this.axis,this.annotation)&&this.axis.deleteAnnotation(this.annotation,!1)}onMouseDown(e){let t=super.onMouseDown(e);if(!0===t){let{point:t}=e;this.axis=t.axis,this.presenter=t.presenter}return t}finish(){if(eF(this.axis,this.presenter)){gK(this.presenter,{toolChange:el.Executed,annId:"ZoomIn"});let e=this.annotation.points,t=mQ(e[0].price,e[1].price),i=mQ(e[0].time,e[1].time),s=(e,t)=>Math.abs(t(e[0])-t(e[1])),r=s(i,e=>this.axis.toX(e)),n=s(t,e=>this.axis.toY(e)),a=this.presenter.view,o=tz.MINIMUM_ZOOM_DIMENSION;if(r>o&&n>o){let e=a.xAxis.xScale;this.axis.isCustomDomain=!0,this.axis.yScale.domain(t),e.wasZoomed=!0,e.scaleBarToFitRange(i,!1),e.domain(i)}a.redraw()}}}function m2(e,t){let i=mS(e);i.offset={x:t.x,y:t.y},i.canFlip=null!==e.getFlipAnchorIndices();let s=e.axis.pane.presenter;s.clearSelection(),s.notifyHost(ay.CH_ANNNEEDSCONTEXTMENU,i)}function m3(e,t,i){let s={offset:{x:t.x,y:t.y},chart:e.accessor,originalEvent:i};e.notifyHost(ay.CH_CHTNEEDSCONTEXTMENU,s)}class m4 extends mw{factory;maxClicks;clicks;snapToSupported;isDrawingAnnotation;constructor(e,t){super(e.annName),this.factory=e,this.maxClicks=t,this.clicks=0,this.snapToSupported=!0,this.isDrawingAnnotation=!0}onMouseMove(e){let{point:t,view:i,offset:s}=e;i.drawCrosshair({ap:t,offset:s})}onMouseDown(e){let{point:t,view:i}=e;if(0===this.clicks){if(void 0===t)return gZ(e),!1;t.axis.pane.presenter.clearSelection(),this.annotation=this.factory(t.axis)}this.applyToPoints(t),this.clicks++,this.clicks===this.maxClicks&&void 0!==this.annotation?(this.annotation.drawn=!1,this.annotation.requestRedraw(),"function"==typeof this.annotation.updateOtherPoints&&this.annotation.updateOtherPoints(i.mainContext),gq(this.annotation,!0,el.Created)):this.annotation.requestRedraw()}applyToPoints(e){this.annotation.points[this.clicks].update(e.price,e.time)}}class m5{snapToSupported=!1;constructor(e,t){setTimeout(()=>this.finalize(e,t),10)}finalize(e,t){let i=e(t);t.pane.presenter.clearSelection(),i.drawn=!1,i.requestRedraw(),gq(i,!0,el.None)}}let m6=tz.MARKER_ARROW_ANGLE*Math.PI/180/2;function m7(e,t,i=tz.MARKER_ARROW_LENGTH){return new m8(e,t,i)}class m8{vertex;arrowLen;p1;p2;constructor(e,t,i=tz.MARKER_ARROW_LENGTH){this.vertex=t,this.arrowLen=i,this.p1=e[0],this.p2=e[1]}hitTest(e){let{anchor:t,p1:i,p2:s}=this.getArrowPoints();return iv([t,i],e,tz.HIT_TEST_TOLERANCE)||iv([t,s],e,tz.HIT_TEST_TOLERANCE)}draw(e){let{anchor:t,p1:i,p2:s}=this.getArrowPoints();iz(e,t,i),iz(e,t,s)}getArrowPoints(){let e=iT(this.p1,this.p2),t="start"===this.vertex?0:Math.PI,i=e-m6+t,s=e+m6+t,r="start"===this.vertex?this.p1:this.p2,n=this.arrowLen*Math.cos(i)+r.x,a=this.arrowLen*Math.sin(i)+r.y,o=this.arrowLen*Math.cos(s)+r.x,l=this.arrowLen*Math.sin(s)+r.y;return{anchor:r,p1:{x:n,y:a},p2:{x:o,y:l}}}}class m9{hitTest(){return!1}draw(){}}class ge extends mC{constructor(e,t){super(e,t),this.addPoints(2),this.alignPointsSupported=!0}get extend1(){return this.traits[tz.AT_EXTEND_PT_1]}get extend2(){return this.traits[tz.AT_EXTEND_PT_2]}get showPercentDiff(){return this.traits[tz.AT_SHOW_PERCENTDIFF]}get showBarCount(){return this.traits[tz.AT_SHOW_BARCOUNT]}get showRatio(){return this.traits[tz.AT_RATIO]}getElements(){let e=this.points[0].point,t=this.points[1].point,i=new mv(e,t,this.extend1,this.extend2,this.axis),s=[];return this.extend1&&s.push(new mv(i.p1,e,!0,!1,this.axis)),s.push(new mv(e,t,!1,!1,this.axis)),this.extend2&&s.push(new mv(t,i.p2,!1,!0,this.axis)),s}formatRatio(e,t){return` (${eB(e/t,3)})`}formatPercDiff(e,t){let i=(t-e)/e*100,s=i>0?"+":"";return` (${s}${eB(i,2)}%)`}formatPrice(e){return h_(this.axis,this.priceMap(e))}adornElements(e,t){if(!this.showBarCount&&!this.showPrices&&!this.showPercentDiff&&!this.showRatio)return;let[i,s]=this.points,r=e[+!!this.extend1].getAdornOffset(t);if(this.showBarCount){let e=iA(ig(i.point,s.point),r);iU(t,this.getBarCount(i.time,s.time).toFixed(0),e,Q.Right)}let n=this.showRatio?this.formatRatio(i.price,s.price):"",a=this.showPrices?this.formatPrice(i.price):"",o=`${a}${n}`.trim();""!==o&&iU(t,o,iA(i.point,r),Q.Right);let l=this.showPercentDiff?this.formatPercDiff(i.price,s.price):"",u=this.showPrices?this.formatPrice(s.price):"",h=`${u}${l}`.trim();""!==h&&iU(t,h,iA(s.point,r),Q.Right)}getMarkers(){let e=this.marker;if(!e||"none"===e.vertex)return[];let{vertex:t,kind:i}=e;return("both"===t?["start","end"]:[t]).map(e=>{if("arrow"===i){var t;return t=this.points,m7(t.map(e=>e.point),e)}return console.warn(`There is no marker of ${i} kind`),new m9})}}class gt extends mC{constructor(e,t){super(e,t),this.addPoints(1)}get showTimestamps(){return this.traits[tz.AT_SHOW_TIMESTAMPS]}getElements(){return[new mf(this.points[0].point,!0,this.axis)]}getTimeScaleAdornments(){return this.showTimestamps?[{time:this.points[0].time,color:this.traits.line.color}]:super.getTimeScaleAdornments()}}class gi extends mC{constructor(e,t){super(e,t),this.addPoints(1)}getElements(){return[new mf(this.points[0].point,!1,this.axis)]}getPriceScaleAdornments(){return this.showPrices?[{price:this.points[0].price,color:this.traits.line.color}]:super.getPriceScaleAdornments()}}class gs extends mC{constructor(e,t,i){super(e,t),this.addPoints(2),eF(i)&&eF(i.points)&&i.points.forEach((e,t)=>this.points[t].update(e.price,e.time))}allPoints(){let[e,t]=this.points;return eF(e,e.point,t,t.point)?[e,this.axis.toAnnotationPoint(ig(e.point,t.point)),t]:tz.EMPTY_ARRAY}line2(){return this.traits[tz.AT_LINE_2]}use52WeekPrices(){return this.traits[tz.AT_USE_52WEEK_PRICES]}getElements(){let e=this.allPoints();return e===tz.EMPTY_ARRAY?tz.EMPTY_ARRAY:e.map(e=>new mv({x:-tz.OUT_OF_SCREEN,y:e.point.y},{x:tz.OUT_OF_SCREEN,y:e.point.y},!1,!1,this.axis))}wasPointMovedByTool(e,t){eF(this.use52WeekPrices())&&(this.traits[tz.AT_USE_52WEEK_PRICES]=!1)}getStyleForElement(e,t){let i=this.line2();if(1!==t||!eF(i))return super.getStyleForElement(e,t);let s=ez(this.traits);return s.line=i,i8(s)}getPriceScaleAdornments(){let e=this.allPoints();if(!this.showPrices||e===tz.EMPTY_ARRAY)return super.getPriceScaleAdornments();let t=this.traits.line,i=e.map(e=>({price:e.price,color:t.color})),s=this.line2();return eF(s)&&(i[1].color=s.color),i}getFlipAnchorIndices(){return null}}class gr extends mb{helper;constructor(e,t,i){super(e,t),this.addPoints(i),this.helper=new mm(e)}get showTrendLine(){return this.traits[tz.AT_SHOW_TRENDLINE]}get hasAllPoints(){return eF(...this.points.map(e=>e.point))}get line2(){return this.traits[tz.AT_LINE_2]}get extendLeft(){return this.traits[tz.AT_EXTEND_LEFT]}get extendRight(){return this.traits[tz.AT_EXTEND_RIGHT]}get reverse(){return this.traits[tz.AT_REVERSE]}get levelsRespectLogScale(){return this.traits[tz.AT_LEVELS_RESPECT_LOG_SCALE]}getStyleForElement(e,t){if(e.isTrend){let e=ez(this.traits);return e.line=this.line2,i8(e)}return super.getStyleForElement(e,t)}getKeyPoints(){let e=e=>e.map(e=>this.points[e]);return e(this.isExtended?this.reverse?[1,0,2]:[0,1,2]:this.reverse?[0,1,0]:[1,0,1])}getElements(){if(!this.hasAllPoints)return[];let[e,t,i]=this.getKeyPoints(),s=t.price-e.price,r=t.price/e.price,n=this.extendLeft,a=this.extendRight,o=this.leftPoint,l=this.rightPoint,u=(e,t,i=!1)=>{let s=new mv(e,t,!i&&n,!i&&a,this.axis);return s.isTrend=i,s},h=this.levelsRespectLogScale&&this.axis.scale===X.Logarithmic,c=({value:e})=>{let t=i.price+s*e,n=i.price*Math.pow(r,e);this.helper.update(h?n:t,i.time);let a=this.helper.point.y;return u({x:o.x,y:a},{x:l.x,y:a})},d=this.getColoredElements(c);return this.showTrendLine&&(d.push(u(e.point,t.point,!0)),this.isExtended&&d.push(u((this.reverse?e:t).point,i.point,!0))),d}getAdornPointAndAlign(e,t){let i=this.labels,s=(e,t,i)=>({pt:e,align:t,offset:i}),r=this.axis.pane.getBoundsWithoutScales();switch(i){case tz.AT_LABELS_LEFT:return this.extendLeft?s({x:r.x,y:e.anchor1.y},Q.Left,t):super.getAdornPointAndAlign(e,t);default:case tz.AT_LABELS_RIGHT:return this.extendRight?s({x:r.x+r.width,y:e.anchor2.y},Q.Right,-t):super.getAdornPointAndAlign(e,t);case tz.AT_LABELS_CENTER:return super.getAdornPointAndAlign(e,t)}}getTextRef(){return(e,t,i)=>{let s=this.formatLevelPrice(i,t.anchor1.y);return{ref:t,spacing:5,offsetY:-5,text:s}}}adornElements(e,t){this.adornElementsForColoredFactors(e,(e,t)=>{let i=new Path2D;return null===e||(iN(i,e.p1),i.lineTo(t.p2.x,e.p1.y),iV(i,t.p2),i.lineTo(e.p1.x,t.p2.y)),i},this.getTextRef(),t)}getPriceScaleAdornments(){if(!this.pricesOnScale)return super.getPriceScaleAdornments();let e=this.getElements();if(0===e.length)return super.getPriceScaleAdornments();let t=this.traits.line.color;return this.factors.map((i,s)=>{let r=e[s++].p1,n=this.singleStyle?t:i.line.color;return{price:this.axis.toPrice(r.y),color:n}})}}class gn extends gr{constructor(e,t){super(e,t,2)}}class ga extends gr{constructor(e,t){super(e,t,3)}}let go=(e,t)=>{let i=new Path2D;return null===e||(iN(i,e.p1),iV(i,e.p2),iV(i,t.p2)),i};class gl extends mb{constructor(e,t){super(e,t),this.addPoints(2)}get reverse(){return this.traits[tz.AT_REVERSE]}getElements(){let[e,t]=this.getScreenPoints(),i=t.y-e.y,s=({value:s})=>{let r=this.reverse?e.y+s*i:t.y-s*i;return new mv(e,{x:t.x,y:r},!1,!0,this.axis)};return this.getColoredElements(s)}getTextRef(){let[e,t]=this.getScreenPoints(),i=t.y-e.y,[s,r]=[this.leftPoint,this.rightPoint];return(n,a,o)=>{let l=this.reverse?e.y+o*i:t.y-o*i;return{ref:new mv({x:s.x,y:l},{x:r.x,y:l},!1,!1,this.axis),spacing:5,offsetY:!0,text:o.toString()}}}adornElements(e,t){this.adornElementsForColoredFactors(e,go,this.getTextRef(),t)}}class gu extends gl{constructor(e,t){super(e,t)}}class gh{center;rim;radius;startAngle;endAngle;antiClockwise;axis;left;right;scale;clip;style;constructor(e,t,i,s,r,n,a){this.center=e,this.rim=t,this.radius=i,this.startAngle=s,this.endAngle=r,this.antiClockwise=n,this.axis=a,this.left=null,this.right=null,this.scale=null,this.clip=null,null!==t&&(this.left={x:this.center.x-this.radius,y:this.center.y},this.right={x:this.center.x+this.radius,y:this.center.y})}get hasScale(){return null!==this.scale}get hasClip(){return null!==this.clip}get hasRim(){return null!==this.rim}applyScale(e){e.translate(this.center.x,this.center.y),e.scale(this.scale.x,this.scale.y),e.translate(-this.center.x,-this.center.y)}inverseScale(e){let t=new DOMPointReadOnly(e.x,e.y),i=this.axis.pane.presenter.view.mouseContext;i.save(),i.resetTransform(),this.applyScale(i);let s=i.getTransform().inverse();return i.restore(),s.transformPoint(t)}hitTest(e){let t=999;if(this.hasRim&&(this.center.y<this.rim.y&&e.y<=this.center.y||this.center.y>=this.rim.y&&e.y>=this.center.y))t=Math.min(iy(this.left,e),iy(this.right,e));else{let{x:i,y:s}=iS(this.hasScale?this.inverseScale(e):e,this.center);if(!this.hasRim){let{startAngle:e,endAngle:t,antiClockwise:r}=this,n=Math.PI/2;if(0===e&&t===n&&!r&&(i<0||s<0)||e===n&&t===Math.PI&&!r&&(i>0||s<0)||e===-n&&t===Math.PI&&r&&(i>0||s>0)||0===e&&t===-n&&r&&(i<0||s>0))return!1}t=Math.abs(Math.sqrt(i*i+s*s)-this.radius)}return t<=tz.HIT_TEST_TOLERANCE}get isAntiClockwise(){return this.hasRim?this.rim.y<=this.center.y:this.antiClockwise}draw(e){e.save(),this.hasClip&&e.clip(this.clip),this.hasScale&&this.applyScale(e),iG(e,this.center,this.radius,this.startAngle,this.endAngle,this.isAntiClockwise??!1),e.restore()}}let gc=(e,t)=>{let i=new Path2D,{center:s}=t;if(iN(i,s),i.arc(s.x,s.y,t.radius,t.startAngle,t.endAngle,t.isAntiClockwise??!1),null===e)return i;let r=new Path2D,{center:n}=e;return iN(r,n),r.arc(n.x,n.y,e.radius,e.endAngle,e.startAngle,!e.isAntiClockwise),i.addPath(r),i};class gd extends mb{constructor(e,t){super(e,t),this.addPoints(2)}getElements(){let[e,t]=this.getScreenPoints();if(!eF(e,t))return[];let i=iy(e,t),s=iS(t,e),r=s.y/i,n=s.x/i,a=({value:t})=>{let s=i*t,a={x:e.x+n*s,y:e.y+r*s};var o=this.axis;let l=iy(e,a);return new gh(e,a,l,0,Math.PI,null,o)},o=this.getColoredElements(a);if(this.showTrendLine){let i=new mv(e,t,!1,!1,this.axis);i.isTrend=!0,o.unshift(i)}return o}get showTrendLine(){return!0}getTextRef(){return(e,t,i)=>{let{center:s}=t,r=t.isAntiClockwise?-1:1;return{ref:{x:s.x,y:s.y+r*t.radius},spacing:0,offsetY:!0,text:i.toString()}}}adornElements(e,t){this.adornElementsForColoredFactors(e,gc,this.getTextRef(),t)}}class gp extends gd{constructor(e,t){super(e,t)}getStyleForElement(e,t){if(e.isTrend){let e=ez(this.traits);return e.line=this.line2,i8(e)}return super.getStyleForElement(e,t)}get showTrendLine(){return this.traits[tz.AT_SHOW_TRENDLINE]}get line2(){return this.traits[tz.AT_LINE_2]}}class gf extends mb{constructor(e,t){super(e,t),this.addPoints(2)}get factorsPropName(){return tz.AT_ANGLES}getElements(){let[e,t]=this.getScreenPoints(),{x:i,y:s}=iS(t,e),r=({value:r})=>{let n=(t,i)=>new mv(e,{x:t,y:i},!1,!0,this.axis),a="1"!==r.charAt(0),o=Number(a?r.charAt(0):r.charAt(2));return a?n(t.x,e.y+s/o):n(e.x+i/o,t.y)};return this.getColoredElements(r)}getTextRef(){return(e,t,i)=>({ref:t.anchor2,spacing:0,offsetY:!0,text:i.toString()})}adornElements(e,t){this.adornElementsForColoredFactors(e,go,this.getTextRef(),t)}}class gm extends gl{constructor(e,t){super(e,t),this._factors=[{shown:!0,value:1/3},{shown:!0,value:2/3}]}getElements(){let[e,t]=this.getScreenPoints();return[new mv(e,t,!1,!1,this.axis)].concat(super.getElements())}}class gg extends gd{constructor(e,t){super(e,t),this._factors=[{shown:!0,value:1/3},{shown:!0,value:2/3}]}}class gy extends mC{constructor(e,t){super(e,t),this.addPoints(3)}getElements(){let e=this.points[0].point,t=this.points[1].point,i=this.points[2].point,s=(t.x+i.x)/2-e.x,r=(t.y+i.y)/2-e.y,n=[];return n.push(new mv(t,{x:t.x+s,y:t.y+r},!1,!0,this.axis)),n.push(new mv(e,{x:e.x+s,y:e.y+r},!1,!0,this.axis)),n.push(new mv(i,{x:i.x+s,y:i.y+r},!1,!0,this.axis)),n.push(new mv(t,i,!1,!1,this.axis)),n}}class gS extends mx{constructor(e,t){super(e,t)}getEllipse(){let e=this.getRect();return null===e?null:new iR(e.centerX,e.centerY,e.width/2,e.height/2)}hitTest(e){if(!this.visible)return!1;let t=this.getEllipse();return null!==t&&t.contains(e)}draw(e,t){var i;return!!super.draw(e,t)&&(i=this.getEllipse(),e.beginPath(),e.ellipse(i.cx,i.cy,i.radiusX,i.radiusY,0,0,2*Math.PI),e.stroke(),e.fill(),!0)}}class gA extends mC{constructor(e,t){super(e,t),this.addPoints(3)}get extend1(){return this.traits[tz.AT_EXTEND_PT_1]}get extend2(){return this.traits[tz.AT_EXTEND_PT_2]}getLastPoint(){let[e,t,i]=this.points;var s=iy(e.point,t.point),r=iT(e.point,t.point);return{x:i.point.x+s*Math.cos(r),y:i.point.y+s*Math.sin(r)}}getElements(){let[e,t,i]=this.points;var s=[];if(s.push(new mv(e.point,t.point,this.extend1,this.extend2,this.axis)),eF(i?.price)){var r=this.getLastPoint();s.push(new mv(i.point,r,this.extend1,this.extend2,this.axis))}return s}}class gT extends mx{kind;constructor(e,t,i){super(e,t),this.kind=i,this.adjustFill=!0}hitTest(e){if(!this.visible)return!1;let t=this.getRect();return null!==t&&t.contains(e)}get dimension(){let e="fish_hook"===this.kind?2:1;return tz.DEFAULT_SYMBOL_WIDTH_HEIGHT*e}updateOtherPoints(){this.points[1].price||this.setBottomRight()}setBottomRight(){let e=this.dimension,t=this.axis.pane.presenter.timeline,{price:i,time:s}=this.points[0],r=e_(t,s,Number,hw);if(-1!==r){let s=this.axis.pane.presenter.view.xAxis.xScale.bar.totalWidth,n=1;for(;(2*n+1)*s<e;)n++;this.points[0].update(i,t.at(r-n)),this.points[1].update(i,t.at(r+n));let a=iA(this.points[0].point,{x:0,y:-e/2}),o=iA(this.points[1].point,{x:0,y:e/2});this.points[0].updateFromPoint(a),this.points[1].updateFromPoint(o)}}draw(e,t){if(!super.draw(e,t))return!1;let i=this.getRect();switch(0===i.width&&(i.width=this.dimension),this.kind){case"zero":iK(e,i,"0");break;case"one":iK(e,i,"1");break;case"two":iK(e,i,"2");break;case"three":iK(e,i,"3");break;case"four":iK(e,i,"4");break;case"five":iK(e,i,"5");break;case"six":iK(e,i,"6");break;case"seven":iK(e,i,"7");break;case"eight":iK(e,i,"8");break;case"nine":iK(e,i,"9");break;case"question":iK(e,i,"?");break;case"fish_hook":var s=e,r=i;s.save(),s.translate(r.x,r.y);let n=Math.min(r.width,r.height)/560;s.scale(n,n),s.lineCap="butt",s.lineJoin="miter",s.miterLimit=4,s.save(),s.save(),s.miterLimit=10,s.beginPath(),s.moveTo(377.8,354.8),s.bezierCurveTo(377.8,354.8,401.8,517.8,290.6,507),s.bezierCurveTo(173.2,495.5,171.5,50.39,171.5,50.39),s.bezierCurveTo(171.5,50.39,191.7,252.59,212.3,351),s.bezierCurveTo(212.3,351,230.9,472.8,286.7,488.7),s.bezierCurveTo(350.4,507,369.5,452.7,377.8,354.79),s.closePath(),s.fill(),s.restore(),s.save(),s.miterLimit=10,s.beginPath(),s.moveTo(378.3,351.1),s.lineTo(341.1,446.6),s.lineTo(371.2,436.7),s.lineTo(378.3,351.1),s.closePath(),s.fill(),s.restore(),s.restore(),s.restore();break;case"arrow_up":var a=e,o=i;a.save();let{cx:l,cy:u,left:h,right:c,top:d,bottom:p,halfBaseSize:f}=iq(o);a.beginPath(),a.moveTo(c,u),a.lineTo(l,d),a.lineTo(h,u),a.lineTo(Math.floor(l-f),u),a.lineTo(Math.floor(l-f),p),a.lineTo(Math.floor(l+f),p),a.lineTo(Math.floor(l+f),u),a.closePath(),a.fill(),a.restore();break;case"arrow_down":var m=e,g=i;m.save();let{cx:y,cy:S,left:A,right:T,top:v,bottom:P,halfBaseSize:C}=iq(g);m.beginPath(),m.moveTo(T,S),m.lineTo(y,P),m.lineTo(A,S),m.lineTo(Math.floor(y-C),S),m.lineTo(Math.floor(y-C),v),m.lineTo(Math.floor(y+C),v),m.lineTo(Math.floor(y+C),S),m.closePath(),m.fill(),m.restore();break;case"arrow_right":var b=e,E=i;b.save();let{cx:L,cy:_,left:M,right:x,top:I,bottom:D,halfBaseSize:O}=iq(E);b.beginPath(),b.moveTo(L,I),b.lineTo(x,_),b.lineTo(L,D),b.lineTo(L,Math.floor(_+O)),b.lineTo(M,Math.floor(_+O)),b.lineTo(M,Math.floor(_-O)),b.lineTo(L,Math.floor(_-O)),b.closePath(),b.fill(),b.restore();break;case"arrow_left":var w=e,R=i;w.save();let{cx:N,cy:V,left:H,right:F,top:B,bottom:k,halfBaseSize:W}=iq(R);w.beginPath(),w.moveTo(N,B),w.lineTo(H,V),w.lineTo(N,k),w.lineTo(N,Math.floor(V+W)),w.lineTo(F,Math.floor(V+W)),w.lineTo(F,Math.floor(V-W)),w.lineTo(N,Math.floor(V-W)),w.closePath(),w.fill(),w.restore();break;case"arrow_horizontal":var U=e,$=i;U.save();let{cx:G,cy:z,left:Y,right:j,top:K,bottom:q,halfBaseSize:X}=iq($,1.5),Z=Math.floor(G-(G-Y)/3),J=Math.floor(G+(G-Y)/3);U.beginPath(),U.moveTo(Z,K),U.lineTo(Y,z),U.lineTo(Z,q),U.lineTo(Z,Math.floor(z+X)),U.lineTo(J,Math.floor(z+X)),U.lineTo(J,q),U.lineTo(j,z),U.lineTo(J,K),U.lineTo(J,Math.floor(z-X)),U.lineTo(Z,Math.floor(z-X)),U.lineTo(Z,K),U.closePath(),U.fill(),U.restore();break;case"arrow_vertical":var Q=e,ee=i;Q.save();let{cx:et,cy:ei,left:es,right:er,top:en,bottom:ea,halfBaseSize:eo}=iq(ee,2/3),el=Math.floor(ei-(ei-en)/3),eu=Math.floor(ei+(ei-en)/3);Q.beginPath(),Q.moveTo(er,el),Q.lineTo(et,en),Q.lineTo(es,el),Q.lineTo(Math.floor(et-eo),el),Q.lineTo(Math.floor(et-eo),eu),Q.lineTo(es,eu),Q.lineTo(et,ea),Q.lineTo(er,eu),Q.lineTo(Math.floor(et+eo),eu),Q.lineTo(Math.floor(et+eo),el),Q.lineTo(er,el),Q.closePath(),Q.fill(),Q.restore();break;case"arc_down":!function(e,t){let{cx:i,cy:s,left:r,right:n,deflection:a,arcWidth:o}=iX(t);e.save(),e.beginPath(),e.moveTo(n,s);let l=i+a,u=s+a,h=i-a,c=s+a;e.bezierCurveTo(l,u,h,c,r,s),e.lineTo(r,s+o),e.bezierCurveTo(h,c+o,l,u+o,n,s+o),e.closePath(),e.fill(),e.restore()}(e,i);break;case"arc_up":!function(e,t){let{cx:i,cy:s,left:r,right:n,deflection:a,arcWidth:o}=iX(t);e.save(),e.beginPath(),e.moveTo(n,s);let l=i+a,u=s-a,h=i-a,c=s-a;e.bezierCurveTo(l,u,h,c,r,s),e.lineTo(r,s-o),e.bezierCurveTo(h,c-o,l,u-o,n,s-o),e.closePath(),e.fill(),e.restore()}(e,i);break;case"thumbs_up":var eh=e,ec=i;eh.save(),eh.translate(ec.x,ec.y),eh.lineWidth=.05;let ed=Math.min(ec.width,ec.height)/18;eh.scale(ed,ed),eh.lineCap="butt",eh.save(),eh.save(),eh.beginPath(),eh.moveTo(3.23,8.96),eh.lineTo(4.17,8.96),eh.bezierCurveTo(4.73,8.81,5.91,6.45,6.45,5.82),eh.bezierCurveTo(6.88,5.33,7.66,5.09,8.48,3.7),eh.bezierCurveTo(9.11,2.78,8.38,1.49,10.06,1.17),eh.bezierCurveTo(10.9,1.01,11.86,2.61,11.58,4.11),eh.bezierCurveTo(11.49,4.6,11.25,5.14,11.07,5.54),eh.bezierCurveTo(10.63,6.5,10.05,6.58,10.17,7.23),eh.bezierCurveTo(10.98,7.25,11.79,7.32,12.67,7.27),eh.bezierCurveTo(14.33,7.17,15.55,9.08,14.43,10.38),eh.bezierCurveTo(14.9,11.12,14.79,12.33,14.14,12.81),eh.bezierCurveTo(14.42,13.58,14.25,14.45,13.67,14.8),eh.bezierCurveTo(14.13,16.77,12.36,16.87,11.77,16.84),eh.lineTo(4.65,16.84),eh.bezierCurveTo(3.87,16.77,3.95,16.28,3.5,16.27),eh.bezierCurveTo(3.39,16.26,3.3,16.26,3.3,16.26),eh.bezierCurveTo(3.18,16.26,3.19,15.7,3.28,15.7),eh.bezierCurveTo(3.36,15.69,3.61,15.68,3.87,15.71),eh.bezierCurveTo(4.03,15.79,4.4,16.26,4.75,16.27),eh.lineTo(12.12,16.26),eh.bezierCurveTo(13.13,16.27,13.67,15.11,12.8,14.56),eh.bezierCurveTo(13.85,14.53,13.98,12.98,13.19,12.6),eh.bezierCurveTo(14.35,12.49,14.5,10.65,13.44,10.41),eh.bezierCurveTo(14.8,9.97,14.39,7.59,12.35,7.83),eh.bezierCurveTo(11.42,7.77,9.87,7.94,9.68,7.62),eh.bezierCurveTo(9.41,6.82,9.684,6.45,10.17,5.88),eh.bezierCurveTo(10.5,5.46,11.02,4.6,11.04,3.64),eh.bezierCurveTo(11.05,2.5,10.41,1.23,9.58,1.98),eh.bezierCurveTo(9.38,2.21,9.36,3.47,8.94,4.02),eh.bezierCurveTo(8.09,5.52,7.3,5.66,6.95,6.15),eh.bezierCurveTo(6.27,6.86,4.93,9.52,4.36,9.52),eh.bezierCurveTo(3.98,9.52,3.243,9.52,3.24,9.52),eh.bezierCurveTo(3.12,9.52,3.08,8.98,3.22,8.95),eh.closePath(),eh.fill(),eh.restore(),eh.restore(),eh.restore();break;case"thumbs_down":var ep=e,ef=i;ep.save(),ep.translate(ef.x,ef.y),ep.lineWidth=.05;let em=Math.min(ef.width,ef.height)/18;ep.scale(em,em),ep.lineCap="butt",ep.save(),ep.save(),ep.beginPath(),ep.moveTo(14.77,9.04),ep.lineTo(13.82,9.04),ep.bezierCurveTo(13.27,9.18,12.09,11.55,11.54,12.17),ep.bezierCurveTo(11.12,12.66,10.34,12.9,9.52,14.29),ep.bezierCurveTo(8.88,15.21,9.62,16.51,7.93,16.82),ep.bezierCurveTo(7.1,16.98,6.13,15.39,6.42,13.88),ep.bezierCurveTo(6.51,13.4,6.75,12.855,6.93,12.46),ep.bezierCurveTo(7.37,11.49,7.95,11.41,7.82,10.76),ep.bezierCurveTo(7.02,10.75,6.21,10.68,5.33,10.73),ep.bezierCurveTo(3.66,10.83,2.44,8.91,3.57,7.62),ep.bezierCurveTo(3.09,6.88,3.2,5.67,3.85,5.19),ep.bezierCurveTo(3.57,4.42,3.74,3.55,4.33,3.2),ep.bezierCurveTo(3.87,1.22,5.64,1.13,6.22,1.16),ep.lineTo(13.35,1.16),ep.bezierCurveTo(14.12,1.22,14.04,1.71,14.49,1.73),ep.bezierCurveTo(14.6,1.73,14.7,1.73,14.7,1.73),ep.bezierCurveTo(14.82,1.74,14.8,2.29,14.72,2.3),ep.bezierCurveTo(14.63,2.31,14.39,2.32,14.12,2.28),ep.bezierCurveTo(13.96,2.21,13.6,1.74,13.25,1.73),ep.lineTo(5.88,1.73),ep.bezierCurveTo(4.86,1.73,4.33,2.88,5.19,3.44),ep.bezierCurveTo(4.14,3.47,4.01,5.02,4.8,5.39),ep.bezierCurveTo(3.64,5.5,3.49,7.35,4.55,7.58),ep.bezierCurveTo(3.19,8.02,3.6,10.4,5.64,10.16),ep.bezierCurveTo(6.57,10.23,8.12,10.05,8.32,10.37),ep.bezierCurveTo(8.58,11.17,8.32,11.54,7.82,12.11),ep.bezierCurveTo(7.49,12.54,6.97,13.39,6.96,14.36),ep.bezierCurveTo(6.94,15.49,7.59,16.76,8.41,16.01),ep.bezierCurveTo(8.62,15.78,8.63,14.52,9.05,13.97),ep.bezierCurveTo(9.9,12.47,10.69,12.33,11.04,11.84),ep.bezierCurveTo(11.72,11.13,13.06,8.47,13.637,8.47),ep.bezierCurveTo(14.01,8.47,14.75,8.47,14.75,8.47),ep.bezierCurveTo(14.87,8.47,14.91,9.01,14.77,9.04),ep.closePath(),ep.fill(),ep.restore(),ep.restore(),ep.restore();break;case"buy":iK(e,i,"B");break;case"sell":iK(e,i,"S")}return!0}}class gv extends mb{helper;constructor(e,t){super(e,t),this.addPoints(2),this.helper=new mm(e)}getElements(){let e=this.axis.pane.presenter.timeline,{price:t,time:i}=this.points[0],s=e_(e,i,Number,hw),r=e_(e,this.points[1].time,Number,hw),n=r-s;if(-1===s||-1===r)return[];let a=({value:i})=>{let r=e.at(s+i*n);return null===r?null:(this.helper.update(t,r),new mf(this.helper.point,!0,this.axis))};return this.getColoredElements(a)}getTextRef(){return(e,t,i)=>({ref:t.anchor,spacing:3,offsetY:!0,text:i.toString()})}adornElements(e,t){let i=this.axis.pane.getBoundsWithoutScales();this.adornElementsForColoredFactors(e,(e,t)=>{let s=new Path2D;if(null===e)return s;let r=t.anchor.x-e.anchor.x;return s.rect(e.anchor.x,i.y,r,i.height),s},this.getTextRef(),t)}getTimeScaleAdornments(){let e=e=>({time:this.points[e].time,color:this.traits.line.color});return[e(0),e(1)]}}class gP{snapToSupported=!0;isDrawingAnnotation=!0;constructor(){}onMouseMove(e){let{point:t,view:i,offset:s}=e;i.drawCrosshair({ap:t,offset:s})}onMouseDown(e){if(eO()&&e.originalEvent instanceof TouchEvent)return;let{point:t}=e,i=t.axis.pane.presenter,s={chart:i.accessor,axis:t.axis,point:{time:t.time.getTime(),price:t.price}};i.notifyHost(ay.CH_ANNPOINTPICKED,s),gK(i,void 0)}}let gC="Closed";class gb extends mC{isLong;twoDecMeta;_dataWindow;_metaData;isHit;constructor(e,t,i){super(e,t),this.isLong=i,this.isHit=!1,this.addPoints(4);let s=(e,t)=>this.points[e].moveDirection=t;s(1,es.Vertical),s(2,es.Vertical),s(3,es.Horizontal),this.twoDecMeta=new ii(2)}data(e){return this.presenter.mainPlot.timeSeries.container.getData(e)}get presenter(){return this.axis.pane.presenter}getDataWindow(e,t,i=!0,s=!0){let r=this.data(ag.DateTime),n=e_(r,+e,Number),a=e_(r,+t,Number),o={refIndex:-1,highestIndex:-1,lowestIndex:-1,highest:null,lowest:null,data:[]},[l,u,h]=[ag.High,ag.Low,ag.Close].map(e=>this.data(e)),c=e=>e-n;for(let e=n;e<=a;e++)i&&-1===o.refIndex&&eF(this.entryPrice)&&this.entryPrice>=u[e]&&this.entryPrice<=l[e]&&(o.refIndex=c(e)),(!i||o.refIndex>=0&&c(e)>=o.refIndex)&&((!eF(o.highest)||l[e]>o.highest)&&(o.highest=l[e]),(!eF(o.lowest)||u[e]<o.lowest)&&(o.lowest=u[e])),i&&-1!==o.refIndex&&(-1===o.highestIndex&&l[e]>this.upperPrice&&(o.highestIndex=c(e)),-1===o.lowestIndex&&u[e]<this.lowerPrice&&(o.lowestIndex=c(e))),s&&o.data.push({high:l[e],low:u[e],close:h[e],time:r[e]});if(s&&o.data&&o.data.length>0){o.state=eF(o.highest,o.lowest)&&(this.upperPrice<o.highest||this.lowerPrice>o.lowest)?gC:"Open",o.special=-1===o.highestIndex&&-1===o.lowestIndex||o.highestIndex===o.lowestIndex;let e=eC(o.data);if(o.toPrice=e.close,o.toTime=e.time,o.state===gC)if(o.special){if(-1!==o.refIndex){let e=o.data[o.refIndex];o.toTime=e.time;let t=this.isLong?this.lowerPrice<o.lowest:this.upperPrice<o.highest;o.toPrice=t?this.upperPrice:this.lowerPrice}}else{let e=-1!==o.highestIndex&&-1!==o.lowestIndex;e&&o.highestIndex<o.lowestIndex||-1===o.lowestIndex?(o.toPrice=this.upperPrice,o.toTime=o.data[o.highestIndex].time):(e&&o.lowestIndex<o.highestIndex||-1===o.highestIndex)&&(o.toPrice=this.lowerPrice,o.toTime=o.data[o.lowestIndex].time)}let t=this.isLong?o.toPrice-this.entryPrice:this.entryPrice-o.toPrice;o.pAndL=eB(t,2)}return o}get dataWindow(){return eF(this._dataWindow)||(this._dataWindow=this.getDataWindow(this.entryAnchor.time,this.exitAnchor.time)),this._dataWindow}getVisiblePriceRange(){let e=this.axis.yScale.domain();return e[1]-e[0]}getFutureTimestamp(){let e=this.axis.pane.presenter.timeline,t=e_(e,+this.points[0].time,Number,hw),i=Math.min(e.length-1,t+50);return e.at(i).getTime()}get entryPrice(){return this.entryAnchor.price}get entryAnchor(){return this.points[0]}get upperPrice(){return this.upperAnchor.price}get upperAnchor(){return this.points[1]}get lowerPrice(){return this.lowerAnchor.price}get lowerAnchor(){return this.points[2]}get exitAnchor(){return this.points[3]}get accountSize(){return this.traits[tz.AT_ACCOUNT_SIZE]}get risk(){let e=this.traits[tz.AT_RISK_IS_PERCENT],t=this.traits[tz.AT_RISK];return eB(e?t/100*this.accountSize:t,2)}get pointValue(){return this._metaData||(this._metaData=this.presenter.mainPlot.metaData),this._metaData.pointValue}formatDollarValue(e){return Number.isFinite(e)?`${e<0?"-":""}$${this.twoDecMeta.format(Math.abs(e))}`:tz.NOT_APPLICABLE}get qty(){return Math.floor(this.risk/(this.isLong?this.entryPrice-this.lowerPrice:this.upperPrice-this.entryPrice))}get upperDiff(){return eB(this.upperPrice-this.entryPrice,2)}get amountMultiplier(){return this.isLong?1:-1}get upperAmount(){return eB(this.accountSize+this.amountMultiplier*this.qty*this.upperDiff,2)}get upperPandL(){return eB(this.amountMultiplier*this.upperDiff*this.pointValue,2)}get isCompact(){return this.traits[tz.AT_COMPACT]}get upper(){let e=h_(this.axis,this.priceMap(this.upperPrice)),t=`(${eB(this.upperDiff/this.entryPrice*100,2).toFixed(2)}%)`;return this.isCompact,`${e} ${t}`}get upperText(){let e=`${this.formatDollarValue(this.upperPandL)}`,t=`${this.formatDollarValue(this.upperAmount)}`,i=this.isLong?"Target":"Stop";return this.isCompact?`${this.upper} ${e}`:`${i}: ${this.upper}, P&L: ${e}, Amount: ${t}`}get lowerDiff(){return eB(this.entryPrice-this.lowerPrice,2)}get lowerAmount(){return eB(this.accountSize-this.amountMultiplier*this.qty*this.lowerDiff,2)}get lowerPandL(){return eB(-this.amountMultiplier*this.lowerDiff*this.pointValue,2)}get lower(){let e=h_(this.axis,this.priceMap(this.lowerPrice)),t=`(${eB(this.lowerDiff/this.entryPrice*100,2).toFixed(2)}%)`;return this.isCompact,`${e} ${t}`}get lowerText(){let e=`${this.formatDollarValue(this.lowerPandL)}`,t=`${this.formatDollarValue(this.lowerAmount)}`,i=this.isLong?"Stop":"Target";return this.isCompact?`${this.lower} ${e}`:`${i}: ${this.lower}, P&L: ${e}, Amount: ${t}`}get riskReward(){return eB(this.isLong?this.upperDiff/this.lowerDiff:this.lowerDiff/this.upperDiff,2)}get state(){return this.dataWindow.state}get pAndL(){return this.dataWindow.pAndL}get pAndLValue(){return this.pAndL*this.pointValue}positionPoints(){let e=this.getVisiblePriceRange()/5,t=this.getFutureTimestamp();this.upperAnchor.update(this.entryPrice+e,this.entryAnchor.time),this.lowerAnchor.update(this.entryPrice-e,this.entryAnchor.time),this.exitAnchor.update(this.entryPrice,t)}get lowerStyle(){return this.fillOnlyStyle(tz.AT_FILL2)}get upperStyle(){return this.fillOnlyStyle(tz.AT_FILL)}get textStyle(){return this.fillOnlyStyle(tz.AT_FILL_TEXT)}get secondaryLineStyle(){return i8({line:{color:this.traits.line.color,dashStyle:"ShortDash"},fill:{color:tz.COLOR_TRANSPARENT}})}wasModifiedByTool(){eF(this.points[2].price)||this.positionPoints(),this._dataWindow=void 0}wasPointMovedByTool(e,t){let i=this.getVisiblePriceRange()/5e3;if(3>this.points.indexOf(e)){let t=t=>e.update(t,e.time);this.entryAnchor.price>this.upperAnchor.price&&t(e===this.entryAnchor?this.upperAnchor.price-i:this.entryAnchor.price+i),this.entryAnchor.price<this.lowerAnchor.price&&t(e===this.entryAnchor?this.lowerAnchor.price+i:this.entryAnchor.price-i)}if(e===this.entryAnchor){let t=(t,i,s)=>t.update(i?e.price:t.price,s?e.time:t.time);t(this.exitAnchor,!0,!1),t(this.upperAnchor,!1,!0),t(this.lowerAnchor,!1,!0)}this.wasModifiedByTool()}get isUpperPerPAndL(){let e=this.dataWindow;return this.isLong?e.pAndL>0:e.pAndL<=0}getStyleForElement(e,t){return e.style||this.defaultStyle}getElements(){let e=new mv(this.entryAnchor.point,this.exitAnchor.point,!1,!1,this.axis),t=this.exitAnchor.point.x<this.entryAnchor.point.x,i=Math.abs(this.exitAnchor.point.x-this.entryAnchor.point.x),s=(e,t)=>({x:e.x+t,y:e.y}),r=new mP(s(this.upperAnchor.point,t?-i:0),i,Math.abs(this.upperAnchor.point.y-this.entryAnchor.point.y),this.axis);r.style=this.upperStyle;let n=new mP(s(this.entryAnchor.point,t?-i:0),i,Math.abs(this.entryAnchor.point.y-this.lowerAnchor.point.y),this.axis);n.style=this.lowerStyle;let a=[e,r,n],o=this.dataWindow;if(-1!==o.refIndex){let e=o.data[o.refIndex],t=new mm(this.axis,this.entryPrice,e.time),i=new mm(this.axis,o.toPrice,o.toTime),s=new mv(t.point,i.point,!1,!1,this.axis);if(s.style=this.secondaryLineStyle,a.push(s),t.time!==i.time){let e=this.entryPrice<o.toPrice,s=new mP({x:t.point.x,y:Math.min(t.point.y,i.point.y)},i.point.x-t.point.x,Math.abs(i.point.y-t.point.y),this.axis);s.style=e?this.upperStyle:this.lowerStyle,a.push(s)}}return a}hitTest(e){if(!this.visible)return!1;let t=this.isHit||!1;return this.isHit=super.hitTest(e),this.isHit!==t&&this.requestRedraw(),this.isHit}get showTextAdornments(){return this.isHit||this.isSelected}getPriceScaleAdornments(){let e=e=>iC(this.traits[e].color);return[{price:this.upperPrice,color:e(tz.AT_FILL)},{price:this.entryPrice,color:e(tz.AT_LINE)},{price:this.lowerPrice,color:e(tz.AT_FILL2)}]}adornElements(e,t){let[i,s,r]=e;if(this.showTextAdornments){let[e,n]=[!0,!1].map(e=>iB(t,e)),{x:a,y:o,width:l}=s.rect,u=this.textStyle.fillStyle;iU(t,this.upperText,{x:a+l/2,y:o+e},Q.Center,u,iC(this.upperStyle.fillStyle));let{x:h,y:c,width:d,height:p}=r.rect;iU(t,this.lowerText,{x:h+d/2,y:c+p+Math.abs(n)},Q.Center,u,iC(this.lowerStyle.fillStyle));let{p1:f,p2:m}=i,{x:g,y:y}=f,{x:S}=m,A=this.state||tz.NOT_APPLICABLE,T=this.isCompact?`${this.formatDollarValue(this.pAndLValue)}`:`${A} P&L: ${this.formatDollarValue(this.pAndLValue)}, Qty: ${this.qty}`,v=this.isCompact?`${this.riskReward.toFixed(2)}`:`Risk/Reward Ratio: ${this.riskReward.toFixed(2)}`,P=e=>t.measureText(e).width,C=Math.abs(S-g)<1.25*Math.max(P(T),P(v))?y+Math.abs(n)+5:y+e+10,b=iC(this.isUpperPerPAndL?this.upperStyle.fillStyle:this.lowerStyle.fillStyle);iU(t,[T,v],{x:g+(S-g)/2,y:C},Q.Center,u,b)}}updatePoints(e){super.updatePoints(e),this.wasModifiedByTool()}}var gE=["years","months","weeks","days","hours","minutes","seconds"];function gL(e,t){tt(2,arguments);var i=ts(e),s=ts(t),r=i.getTime()-s.getTime();return r<0?-1:r>0?1:r}function g_(e){return(g_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function gM(e,t){if(tt(2,arguments),!t||"object"!==g_(t))return new Date(NaN);var i=t.years?te(t.years):0,s=t.months?te(t.months):0,r=t.weeks?te(t.weeks):0,n=t.days?te(t.days):0,a=t.hours?te(t.hours):0,o=t.minutes?te(t.minutes):0,l=t.seconds?te(t.seconds):0,u=ts(e),h=s||i?tr(u,s+12*i):u;return new Date((n||r?lk(h,n+7*r):h).getTime()+1e3*(l+60*(o+60*a)))}function gx(e,t,i){tt(2,arguments);var s=uL(e,t)/6e4;return uM(null==i?void 0:i.roundingMethod)(s)}class gI extends mE{markers;display=null;constructor(e,t){super(e,t),this.points=mM(e),this.points[2].visible=!1,this.points[3].visible=!1,this.markers=[new m9]}isPointDrawn(e){return!!super.isPointDrawn(e)&&e.visible}makeLineArrow(e,t,i,s){let r=[ig(e,t),ig(i,s)];return[this.makeLine(r[0],r[1]),m7(r,"end",10)]}get rectColor(){return this.traits[tz.AT_FILL].color}get textColor(){return this.traits[tz.AT_FILL_TEXT].color}getMarkers(){return this.markers}formatDateDifference(e,t){return this.presenter.data.aggregation.isEndOfDay?`${lF(t,e)}d`:(function(e,t){if(arguments.length<1)throw TypeError("1 argument required, but only ".concat(arguments.length," present"));var i,s,r,n,a,o=null!=(i=null!=(s=null==t?void 0:t.locale)?s:nP.locale)?i:oZ,l=null!=(r=null==t?void 0:t.format)?r:gE,u=null!=(n=null==t?void 0:t.zero)&&n,h=null!=(a=null==t?void 0:t.delimiter)?a:" ";return o.formatDistance?l.reduce(function(t,i){var s="x".concat(i.replace(/(^.)/,function(e){return e.toUpperCase()})),r=e[i];return"number"==typeof r&&(u||e[i])?t.concat(o.formatDistance(s,r)):t},[]).join(h):""})(function(e){tt(1,arguments);var t=ts(e.start),i=ts(e.end);if(isNaN(t.getTime()))throw RangeError("Start Date is invalid");if(isNaN(i.getTime()))throw RangeError("End Date is invalid");var s={};s.years=Math.abs(function(e,t){tt(2,arguments);var i=ts(e),s=ts(t),r=gL(i,s),n=Math.abs(function(e,t){tt(2,arguments);var i=ts(e),s=ts(t);return i.getFullYear()-s.getFullYear()}(i,s));i.setFullYear(1584),s.setFullYear(1584);var a=gL(i,s)===-r,o=r*(n-Number(a));return 0===o?0:o}(i,t));var r=gL(i,t),n=gM(t,{years:r*s.years});s.months=Math.abs(function(e,t){tt(2,arguments);var i,s=ts(e),r=ts(t),n=gL(s,r),a=Math.abs(function(e,t){tt(2,arguments);var i=ts(e),s=ts(t);return 12*(i.getFullYear()-s.getFullYear())+(i.getMonth()-s.getMonth())}(s,r));if(a<1)i=0;else{1===s.getMonth()&&s.getDate()>27&&s.setDate(30),s.setMonth(s.getMonth()-n*a);var o=gL(s,r)===-n;(function(e){tt(1,arguments);var t=ts(e);return lB(t).getTime()===(function(e){tt(1,arguments);var t=ts(e),i=t.getMonth();return t.setFullYear(t.getFullYear(),i+1,0),t.setHours(23,59,59,999),t})(t).getTime()})(ts(e))&&1===a&&1===gL(e,r)&&(o=!1),i=n*(a-Number(o))}return 0===i?0:i}(i,n));var a=gM(n,{months:r*s.months});s.days=Math.abs(lF(i,a));var o=gM(a,{days:r*s.days});s.hours=Math.abs(function(e,t,i){tt(2,arguments);var s=uL(e,t)/36e5;return uM(null==i?void 0:i.roundingMethod)(s)}(i,o));var l=gM(o,{hours:r*s.hours});s.minutes=Math.abs(gx(i,l));var u=gM(l,{minutes:r*s.minutes});return s.seconds=Math.abs(ux(i,u)),s}({start:e,end:t}),{format:["days","hours","minutes","seconds"]}).replaceAll(/(days?)|(hours?)|(minutes?)|(seconds?)/g,e=>e[0])}computeState(){}get text(){return null===this.display&&this.computeState(),this.display}getTextCoord(e,t){let i=this.points[0].price<this.points[1].price,s=iB(t,i,this.text.length),{x:r,y:n,width:a,height:o}=e.rect;return{x:r+a/2,y:n+(i?0:o)+(i?s:Math.abs(s))}}adornElements(e,t){iU(t,this.text,this.getTextCoord(e[0],t),Q.Center,this.textColor,iC(this.rectColor))}getDateDifference(){let[e,t]=this.points.slice(0,2).map(e=>e.time),i=Math.min(+e,+t),s=Math.max(+e,+t),r=this.data(ag.DateTime),n=e_(r,+i,Number),a=e_(r,+s,Number),o=em(this.data(ag.Volume).slice(n,a+1)),l=this.formatter.format(o,ag.Volume),u=a-n,h=0===u?"":this.formatDateDifference(i,s),c=e<t?"":"-";return[`${c}${u} bars, ${c}${h}`,`Vol ${l}`]}getPriceDifference(){let[e,t]=this.points.slice(0,2).map(e=>e.price),i=t-e,s=this.formatter.format(i,ag.Close),r=this.formatter.format(i/e,ag.PercentChange);return[`${s} (${r})`]}resetComputedState(){this.display=null}getFlipAnchorIndices(){return[0,1]}}class gD extends gI{getElements(){this.points.slice(2).forEach(e=>e.toPoint());let[e,t,i,s]=this.getScreenPoints(),r=this.makeLine(e,s),n=this.makeLine(t,i),[a,o]=this.makeLineArrow(e,s,t,i);return this.markers[0]=o,[this.rect,r,n,a]}computeState(){this.display=this.getDateDifference()}}class gO extends gI{getElements(){this.points.slice(2).forEach(e=>e.toPoint());let[e,t,i,s]=this.getScreenPoints(),r=this.makeLine(e,i),n=this.makeLine(t,s),[a,o]=this.makeLineArrow(e,i,t,s);return this.markers[0]=o,[this.rect,r,n,a]}computeState(){this.display=this.getPriceDifference()}}class gw extends gI{get drawBorder(){return this.traits[tz.AT_DRAW_BORDER]}getBorderElements(){if(!this.drawBorder)return[];let[e,t,i,s]=this.getScreenPoints();return[this.makeLine(e,s),this.makeLine(t,i),this.makeLine(e,i),this.makeLine(t,s)]}getElements(){this.points.slice(2).forEach(e=>e.toPoint());let[e,t,i,s]=this.getScreenPoints(),[r,n]=this.makeLineArrow(e,s,t,i),[a,o]=this.makeLineArrow(e,i,t,s);this.markers=[n,o];let l=this.getBorderElements();return[this.rect,r,a].concat(l)}computeState(){this.display=this.getPriceDifference().concat(this.getDateDifference())}}class gR extends mE{constructor(e,t){super(e,t),this.points=mM(e)}get priceLevels(){return i1(this.traits[tz.AT_PRICE_LEVELS])}get timeLevels(){return i1(this.traits[tz.AT_TIME_LEVELS])}get showAngles(){return this.traits[tz.AT_SHOW_ANGLES]}get reverse(){return this.traits[tz.AT_REVERSE]}get showLeftLabels(){return this.traits[tz.AT_SHOW_LEFT_LABELS]}get showRightLabels(){return this.traits[tz.AT_SHOW_RIGHT_LABELS]}get showTopLabels(){return this.traits[tz.AT_SHOW_TOP_LABELS]}get showBottomLabels(){return this.traits[tz.AT_SHOW_BOTTOM_LABELS]}getAngles(e,t){let i=this.getScreenPoints(),s=this.lineOnlyStyle(tz.AT_LINE_2),r=[];e.concat(t).flatMap(e=>[e.p1,e.p2]).map(e=>{r.some(t=>e.x===t.x&&e.y===t.y)||r.push(e)});let n=i.map(e=>r.filter(t=>t.x!==e.x&&t.y!==e.y).map(t=>this.makeLine(e,t))).flat();return n.forEach(e=>e.style=s),n}getElements(){let e=this.getLinesDataAtLevels(this.priceLevels,this.timeLevels),{priceLines:t,timeLines:i}=this.getLineElements(e),s=this.showAngles?this.getAngles(t,i):[];return[...t,...i,...s]}adornElements(e,t){let i=this.singleStyle,s=this.showBackground,r=t.fillStyle,n=iF(t,1)/2,{x:a,y:o}=tz.DEFAULT_ADORN_OFFSET,l=(e,i,s,r,n)=>{let a=iA(e,i);iU(t,Number(s.toFixed(4)).toString(),a,r,n)},u=null;if(e.forEach(e=>{if(!e._data)return;let{level:h,isPrice:c}=e._data,d=i?r:e.style.strokeStyle,p=u&&s&&!i;c?(this.showLeftLabels&&l(e.p1,{x:a,y:n},h,Q.Right,d),this.showRightLabels&&l(e.p2,{x:-a,y:n},h,Q.Left,d)):(this.showTopLabels&&l(e.p1,{x:0,y:o},h,Q.Center,d),this.showBottomLabels&&l(e.p2,{x:0,y:-(2*o)},h,Q.Center,d)),p&&((e,i)=>{let s=new Path2D;iH(s,e.p1,i.p2),t.fillStyle=i.style.fillStyle,t.fill(s)})(u,e),u=e}),i&&s){let e=this.applyBackgroundOpacity(this.traits.line.color),i=new Path2D,[s,r]=this.getScreenPoints();iH(i,s,r),t.fillStyle=e,t.fill(i)}}resetComputedState(){this.lines=void 0}updateFrom(e,t,i,s,r){let n=e.reverse!==this.reverse;super.updateFrom(e,t,i,s,r),n&&this.resetComputedState()}getFlipAnchorIndices(){return[0,1]}}let gN=e=>e.map(e=>({...e,dimensions:e.value.split("x").map(Number)})),gV=(e,t)=>1e-7>Math.abs(e-t);class gH extends mE{_parsedFans=null;_parsedArcs=null;constructor(e,t){super(e,t),this.points=mM(e),this._parsedFans=this._parsedArcs=null}get levels(){return i1(this.traits[tz.AT_LEVELS])}setComputedAndTraits(e,t){let i={...e,computed:t,traits:this.getTraitsFor(e)};return delete i.line,i}get computedLevels(){return this.levels.map(e=>this.setComputedAndTraits(e,e.value/5))}get showRangesRatio(){return this.traits[tz.AT_SHOW_RANGES_RATIO]}get arcs(){return i1(this.traits[tz.AT_ARCS])}get fans(){return i1(this.traits[tz.AT_FANS])}get reverse(){return this.traits[tz.AT_REVERSE]}get parsedFans(){return null===this._parsedFans&&(this._parsedFans=gN(this.fans)),this._parsedFans}get computedFans(){let[,,e,t]=this.getReversedScreenPoints(),{dx:i,dy:s}=this.unit,{signX:r,signY:n}=this.getOrientation();return this.parsedFans.map(a=>{let[o,l]=a.dimensions;return this.setComputedAndTraits(a,o>=l?{x:e.x,y:e.y+l/o*n*5*s}:{x:t.x+o/l*5*r*i,y:t.y})})}get parsedArcs(){return null===this._parsedArcs&&(this._parsedArcs=gN(this.arcs)),this._parsedArcs}get computedArcs(){let{dx:e}=this.unit;return this.parsedArcs.map(t=>{let[i,s]=t.dimensions;return this.setComputedAndTraits(t,Math.sqrt(e**2*(i**2+s**2)))})}getReversedScreenPoints(){let[e,t,i,s]=this.getScreenPoints();return this.reverse?[t,e,s,i]:[e,t,i,s]}get unit(){let[e,t]=this.getReversedScreenPoints();return e.x!==t.x&&e.y!==t.y?{dx:Math.abs(t.x-e.x)/5,dy:Math.abs(t.y-e.y)/5}:null}get priceBarRatio(){return this.traits[tz.AT_PRICE_BAR_RATIO]}set priceBarRatio(e){this.traits[tz.AT_PRICE_BAR_RATIO]=e}makeStyledLine(e,t,i){let s=this.makeLine(e,t);return this.singleStyle||(s.style=i8(i)),s}getGridLines(e,t){let i=t.x-e.x,s=t.y-e.y;return this.computedLevels.map(({computed:r,traits:n})=>{let a=e.x+r*i,o=e.y+r*s;return[this.makeStyledLine({x:a,y:e.y},{x:a,y:t.y},n),this.makeStyledLine({x:e.x,y:o},{x:t.x,y:o},n)]}).flat()}getArcs(e){let{flipX:t,flipY:i,signY:s}=this.getOrientation(),{dx:r,dy:n}=this.unit,a=gV(r,n)?null:{x:1,y:n/r},o=this.getClipPath();return this.computedArcs.map(({computed:r,traits:n})=>{let l=new gh(e,null,r,t?s*Math.PI/2:0,t?Math.PI:s*Math.PI/2,i,this.axis);return null!==a&&(l.scale=a),l.clip=o,this.singleStyle||(l.style=i8(n)),l})}getFans(e){return this.computedFans.map(({computed:t,traits:i})=>this.makeStyledLine(e,t,i))}getElements(){if(null===this.unit)return[];let[e,t]=this.getReversedScreenPoints(),i=this.getGridLines(e,t);return[...i,...this.getArcs(e),...this.getFans(e)]}getOrientation(){let[e,t]=this.getReversedScreenPoints(),i=t.x<e.x,s=t.y<e.y;return{flipX:i,signX:i?-1:1,flipY:s,signY:s?-1:1}}getClipPath(){let[e,t]=this.getReversedScreenPoints(),i=new Path2D;return iH(i,e,t),i}adornElements(e,t){if(0===e.length)return;let i=(e,i,s)=>{t.fillStyle=s;let r=i.hasScale;r&&(t.save(),i.applyScale(t)),t.fill(e),r&&t.restore()};if(this.showBackground){let s=e.filter(e=>e.radius),r=this.getClipPath();if(t.save(),t.clip(r),this.singleStyle){let e=eC(s);i(gc(null,e),e,this.applyBackgroundOpacity(this.traits.line.color))}else{let e=null;s.forEach(t=>{let s=gc(e,t),r=t.style.fillStyle;i(s,t,r),e=t})}t.restore()}if(this.showRangesRatio&&null!==this.unit){let e=eC(this.computedLevels),i=(this.singleStyle?this:e).traits.line.color,[,s,r,n]=this.getReversedScreenPoints(),{x:a,y:o}=tz.DEFAULT_ADORN_OFFSET,{flipX:l,signX:u,signY:h}=this.getOrientation(),c=iA(r,{x:-a*u,y:o*h}),{priceDiff:d,barsDiff:p}=this.getLinesDataAtLevels(null,null),f=l?Q.Right:Q.Left;iU(t,p.toFixed(0),c,f,i);let m=iA(n,{x:2*a*u,y:-o*h}),g=l?Q.Left:Q.Right;iU(t,this.formatter.format(d,ag.Close),m,g,i);let y=iA(s,{x:-a*u,y:-o*h});iU(t,this.priceBarRatio.toFixed(6),y,f,i)}}resetComputedState(){if(this.lines=void 0,4===this.points.length&&null!==this.unit){let{priceDiff:e,barsDiff:t}=this.getLinesDataAtLevels(null,null);this.priceBarRatio=Math.abs(e/t)}}updateFrom(e,t,i,s,r){if(super.updateFrom(e,t,i,s,r),this._parsedFans=this._parsedArcs=null,!gV(e.priceBarRatio,this.priceBarRatio)){let[t,i,,]=this.points;this.reverse&&([t,i]=[i,t]);let{priceDiff:s,barsDiff:r}=this.getLinesDataAtLevels(null,null);i.update(t.price+Math.sign(s)*e.priceBarRatio*r,i.time),this.resetComputedState()}}getFlipAnchorIndices(){return[0,1]}}class gF extends mb{constructor(e,t){super(e,t),this.addPoints(3)}get extend1(){return this.traits[tz.AT_EXTEND_PT_1]}get extend2(){return this.traits[tz.AT_EXTEND_PT_2]}getElements(){let[e,t,i]=this.getScreenPoints(),{x:s,y:r}=iS(i,e),n=i=>{let[s,r]=[e,t].map(e=>iA(e,i));return new mv(s,r,this.extend1,this.extend2,this.axis)};return this.getColoredElements(({value:e})=>n({x:s*e,y:r*e}))}getTextRef(){return(e,t,i)=>{let s=this.formatLevelPrice(i,t.anchor1.y);return{ref:t,spacing:5,offsetY:!0,text:s}}}adornElements(e,t){this.adornElementsForColoredFactors(e,(e,t)=>{let i=new Path2D;return null===e||(iN(i,e.p1),iV(i,e.p2),iV(i,t.p2),iV(i,t.p1)),i},this.getTextRef(),t)}}class gB extends mC{levelSize=0;alignLeft=!0;totalVolume=!1;widthPercent=30;useChange=!1;studyPlotId;gotData;boxes=[];periodType="VisibleScreen";period=0;valueRangePercent=.7;levelMode="Count";usesFinerGrainedAgg=!0;constructor(e,t,i){super(e,t),this.computed=!0,this.studyPlotId=i,this.gotData=!1}setOptions(e){switch(this.levelMode=e.LevelMode,this.levelSize=e2(1,1e3,e.LevelSize),this.alignLeft="Left"===e.Position,this.totalVolume="Total"===e.Volume,this.widthPercent=e2(5,100,e.WidthPercent)/100,e.BarColoring){case"OpenToClose":this.useChange=!1;break;case"CloseToClose":this.useChange=!0;break;default:{let e=this.presenter.mainPlot?.mainCurve?.attributes;this.useChange=e?.includes(U.ChangeBased)??!1}}eH(e.PeriodType)&&(this.periodType=e.PeriodType),this.period=e.Period,this.valueRangePercent=e.ValueRangePercent/100;let t=er[Sp()?.config.mode??"Unspecified"];this.usesFinerGrainedAgg=sB(t)}get isCountMode(){return"Count"===this.levelMode}updateLastBox(){if(this.boxes.length>0){let e=this.boxes.pop(),t=this.getDataForRange(e.firstDate,e.lastDate);t&&this.boxes.push(t)}}invalidate(e){switch(this.periodType){case"VisibleScreen":this.gotData=!1,this.boxes=[];break;case"Bars":case"Days":switch(e){case"DataPointAdded":{let e=this.studySeries.innCont(0),t=e?.getTimeData();if(!eF(t))return;let i=t[t.length-1],s=this.boxes.length>0?this.boxes[this.boxes.length-1]:null;if(eH(s)&&i.valueOf()<s.lastDate.valueOf())this.updateLastBox();else{let e=this.getDataForRange(i,this.getBoxEndFromStart(i));e&&this.boxes.push(e)}break}case"DataPointChanged":this.updateLastBox();break;case"NewChunkArrived":this.gotData=!1}}}getBoxRect(e){switch(this.periodType){case"VisibleScreen":return this.axis.pane.getBoundsWithoutScales();case"Bars":case"Days":{let t=this.axis.pane.presenter.view.xAxis.xScale.bar,i=this.axis.toY(e.min),s=this.axis.toY(e.max),r=this.axis.pane.presenter.view.toX(e.firstDate)-t.width/2,n=0;if("Days"===this.periodType){let i=e.lastDate,s=this.axis.pane.presenter.view.xAxis.xScale.timeline,a=s.at(s.lastSeriesIndex),o=a.valueOf()<i.valueOf(),l=o?a:i,u=(o?1:-2)*t.width/2;n=this.axis.pane.presenter.view.toX(l)+u-r}else n=this.period*t.width+(this.period-1)*t.spacing;return new iw(r,s,n,i-s)}default:throw Error("Unexpected period type for Volume At Price annotation")}}getElementsForBox(e){let t=this.getBoxRect(e),i=[];if(this.isPeriodic){let e=new mP({x:t.x,y:t.y},t.width,t.height,this.axis);e.style=this.backgroundStyle,i.push(e)}let{x:s,width:r}=t,n=r*this.widthPercent,a=e.bars[e.maxVolumeIndex];return e.bars.forEach((t,o)=>{let{upVolume:l,downVolume:u,totalVolume:h,isValue:c}=t;if(0===l&&0===u)return null;let d=this.axis.toY(e.min+o*e.zone),p=this.axis.toY(e.min+(o+1)*e.zone),f=Math.abs(d-p),m=(e,t,i=0)=>{let n=new mP({x:this.alignLeft?s+i:s+r-e-i,y:p},e,f,this.axis);return n.style=t,n},g=(e,t,i)=>e/t.totalVolume*i,y=this.studyPlot.curves[2].visible,S=y&&c?this.upValueStyle:this.upStyle,A=y&&c?this.downValueStyle:this.downStyle,T=y&&c?this.totalValueStyle:this.totalStyle;if(this.totalVolume){let e=g(h,a,n);i.push(m(e,T))}else{let e=g(u,a,n),t=g(l,a,n);i.push(m(t,S),m(e,A,t))}if(this.studyPlot.curves[1].visible&&o===e.maxVolumeIndex){let e=i[i.length-1].rect,t=this.alignLeft?e.x+e.width:s,n=(p+d)/2,a=this.alignLeft?s+r:e.x;i.push(new mv({x:t,y:n},{x:a,y:n},!1,!1,this.axis))}}),i}get isVisible(){return this.studyPlot.visible&&this.studyPlot.mainCurve.visible}getElements(){if(this.gotData||this.getData(),!this.gotData||!this.isVisible||0===this.boxes.length)return[];switch(this.periodType){case"VisibleScreen":{let e=this.boxes[0];if(!e||0===e.bars.length)return[];return this.getElementsForBox(e)}case"Bars":case"Days":{let[e,t]=this.presenter.view.xAxis.xScale.domain()||[];if(!oC(e)||!oC(t))return[];let i=this.boxes.findIndex(t=>t.firstDate.getTime()<=e.getTime()&&t.lastDate.getTime()>=e.getTime());-1===i&&(i=0,this.studySeries.loadMoreData());let s=this.boxes.findIndex(e=>e.firstDate.getTime()<=t.getTime()&&e.lastDate.getTime()>=t.getTime());-1===s&&-1!==i&&(s=this.boxes.length-1);let r=[];for(let e=i;e<=s;e++)r.push(...this.getElementsForBox(this.boxes[e]));return r}default:throw Error("Unexpected period type for Volume At Price annotation")}}getStyleForElement(e,t){return e.style||super.getStyleForElement(e,t)}get presenter(){return this.axis.pane.presenter}get downStyle(){return this.fillOnlyStyle(tz.AT_FILL)}get upStyle(){return this.fillOnlyStyle(tz.AT_FILL2)}get totalStyle(){return this.fillOnlyStyle(tz.AT_FILL3)}get downValueStyle(){return this.fillOnlyStyle(tz.AT_FILL4)}get upValueStyle(){return this.fillOnlyStyle(tz.AT_FILL5)}get totalValueStyle(){return this.fillOnlyStyle(tz.AT_FILL6)}get backgroundStyle(){return this.fillOnlyStyle(tz.AT_FILL7)}get lineStyle(){return this.lineOnlyStyle(tz.AT_LINE)}getBoxEndFromStart(e){switch(this.periodType){case"VisibleScreen":default:return null;case"Days":return oE(lQ(G.Day,this.period)(e),1);case"Bars":{let t=this.axis.pane.presenter.data.aggregation;return oE(lQ(t.unit,t.size*this.period)(e),1)}}}getData(){let e=this.axis.pane.presenter.data.aggregation;if(e.isTick||e.hasSpec&&!pG(e.spec))return;let[t,i]=this.presenter.view.xAxis.xScale.domain()||[];if(!oC(t)||!oC(i))return;let s=lQ(e.unit,e.size);switch(this.periodType){case"VisibleScreen":{let e=this.boxes[0];if(e&&e.firstDate===t&&e.lastDate===i)this.gotData=!0;else{let e=this.getDataForRange(t,i);e&&(this.boxes[0]=e)}break}case"Bars":{let[e,t]=[0,1].map(e=>this.studySeries.innCont(e));if((e?.size??0)<1||(t?.size??0)<1)return;let i=e.getTimeData(),r=0;for(this.boxes=[];r<i.length;){let e=i[r],t=r+this.period,n=oE(t<i.length?i[t]:s(i[i.length-1]),1),a=this.getDataForRange(e,n);a&&this.boxes.push(a),r+=this.period}this.gotData=!0;break}case"Days":{if(e.isEndOfDay){this.boxes=[],this.gotData=!0;return}let[t,i]=[0,1].map(e=>this.studySeries.innCont(e));if((t?.size??0)<1||(i?.size??0)<1)return;let r=t.getTimeData(),n=t.getData(ag.TradingDay),a=e=>{let t=0,i=r[e],s=n[e];for(let a=e;a<r.length;a++)if(tu(r[a],i)>0&&n[a]!==s&&(t+=1,i=r[a],s=n[a],t===this.period))return a;return -1},o=0,l=r[0],u=a(o)-1;for(;(u<0||u===o)&&o<r.length;)o+=1,u=a(o)-1;for(this.boxes=[];o<r.length&&u<r.length&&o<u;){let e=oE(s(r[u]),1),t=this.getDataForRange(l,e);t&&this.boxes.push(t),l=r[o=u+1],u=a(o)-1}if(u<0&&o<r.length-1){let e=oE(s(r[r.length-1]),1),t=this.getDataForRange(r[o],e);t&&this.boxes.push(t)}this.gotData=!0}}}getBoxAt(e){if(0===this.boxes.length)return null;switch(this.periodType){case"VisibleScreen":{let t=this.boxes[0];if(t.firstDate>e||t.lastDate<e)return null;return t}case"Bars":case"Days":{let t=e.getTime(),i=this.boxes.find(e=>e.firstDate.getTime()<=t&&e.lastDate.getTime()>=t);if(!i)return null;return i}}}getValueAt(e,t,i){if(!this.isVisible)return null;let s=this.getBoxAt(t);if(!s)return null;let r=this.getBarIndex(s,i);if(r<0||r>=s.bars.length)return null;let n=s.bars[r];switch(e){case ag.UPVOL:return this.totalVolume?null:n.upVolume;case ag.DNVOL:return this.totalVolume?null:n.downVolume;case ag.TOTVOL:return this.totalVolume?n.totalVolume:null;case ag.POC:case ag.VAREA:case ag.BARBACK:return null;default:throw Error("Unexpected Volume At Price field")}}getBarIndex(e,t,i=!1){if(0===e.bars.length||0===e.zone)return -1;let s=Math.floor((t-e.min)/e.zone);return i?Math.min(e.bars.length-1,s):s}get studyPlot(){return this.presenter.allPlots.find(e=>e.id===this.studyPlotId)}get studySeries(){return this.studyPlot.timeSeries}makeBox(e,t){return{min:Number.MAX_VALUE,max:5e-324,zone:0,bars:[],maxVolumeIndex:-1,firstDate:e,lastDate:t}}findExtremes(e,t,i,s,r,n){let a=eH(r)&&eH(n);for(let o=t;o<=i;o++)if(a){let t=r[o];t>e.max&&(e.max=t);let i=n[o];i<e.min&&(e.min=i)}else{let t=s[o];t<e.min&&(e.min=t),t>e.max&&(e.max=t)}}findValueArea(e){if(-1===e.maxVolumeIndex||0===e.bars.length)return;e.bars[e.maxVolumeIndex].isValue=!0;let t=em(e.bars.map(e=>e.totalVolume))*this.valueRangePercent,i=e.bars[e.maxVolumeIndex].totalVolume,s=e.maxVolumeIndex,r=e.maxVolumeIndex;for(;i<t;){let n=[{dir:"lower",count:2,startIdx:s-2,endIdx:s-1},{dir:"lower",count:1,startIdx:s-1,endIdx:s-1},{dir:"upper",count:2,startIdx:r+1,endIdx:r+2},{dir:"upper",count:1,startIdx:r+1,endIdx:r+1}].filter(t=>t.startIdx>=0&&t.endIdx<e.bars.length).map(t=>{let s=em(e.bars.slice(t.startIdx,t.endIdx+1).map(e=>e.totalVolume));return{...t,volume:s,newTotal:i+s}});if(0===n.length)break;let a=(e,t)=>t.newTotal<e.newTotal?t:e,o=(e,t)=>t.volume>e.volume?t:e,l=n.filter(e=>e.newTotal>=t),u=l.length>0?l.reduce(a):n.reduce(o);for(let t=u.startIdx;t<=u.endIdx;t++)e.bars[t].isValue=!0;if("lower"===u.dir?s=u.startIdx:r=u.endIdx,(i=u.newTotal)>=t)break}}tallyVolume(e,t,i,s,r,n,a){let o=5e-324,l=!1;for(let u=t;u<=i;u++){let t=r[u],i=this.getBarIndex(e,t,!0);if(-1===i){l=!0;break}let h=a[u],c=this.useChange?n[u]>=0:s[u]<=r[u],d=e.bars[i];c?d.upVolume+=h:d.downVolume+=h,d.totalVolume=d.downVolume+d.upVolume,d.totalVolume>o&&(o=d.totalVolume,e.maxVolumeIndex=i)}l||this.findValueArea(e)}get isPeriodic(){return"Bars"===this.periodType||"Days"===this.periodType}get isVisibleScreen(){return"VisibleScreen"===this.periodType}getDataForRange(e,t){let i=this.makeBox(e,t),s=this.studySeries.innCont(1),r=s?.getTimeData();if(!eF(r))return null;let n=e=>e_(r,+e,Number),a=n(e),o=n(t);if(r[o].getTime()>t.getTime()&&(o-=1),a>o)return null;if(this.axis.pane.presenter.data.aggregation.unit===G.Day&&"Bars"===this.periodType){let e=s.getData(ag.TradingDay),t=e[a];for(;t===e[a]&&a>0;)a-=1;a+=1;let i=0;for(o=a;o<r.length&&i<this.period;)e[o]!==t&&(i+=1,t=e[o]),o+=1;o-=2}this.isVisibleScreen&&this.usesFinerGrainedAgg&&a<1e3&&this.studySeries.loadMoreData();let[l,u,h,c,d,p]=["Open","High","Low","Close","Change","Volume"].map(e=>{let t;return t=ag[e],s.getData(t)});this.findExtremes(i,a,o,c,u,h);let f=i.max-i.min,m=e=>({upVolume:0,downVolume:0,isValue:!1,totalVolume:0});if(this.isCountMode)i.zone=f/this.levelSize,i.bars=ex(this.levelSize,m);else{let e=Math.max(1,Math.ceil(f/((this.presenter.mainPlot?.metaData.minMovement??1)*this.levelSize)));i.zone=f/e,i.bars=ex(e,m)}return this.tallyVolume(i,a,o,l,c,d,p),this.gotData=!0,i}}class gk extends mC{studyPlotId;constructor(e,t,i){super(e,t),this.studyPlotId=i}get studyPlot(){return this.presenter.allPlots.find(e=>e.id===this.studyPlotId)}get studySeries(){return this.studyPlot.timeSeries}getElements(){if(!this.studyPlot.visible||!this.studyPlot.mainCurve.visible)return[];let e=this.studySeries.getCurrentState();if(!e)return[];let t=e.confirmedPivots,i=Array.from(t.keys()).sort((e,t)=>e-t);if(0===i.length)return[];let s=this.presenter.mainPlot?.timeSeries?.container;if(!s||s.size<2)return[];let r=s.getTimeData();if(!r)return[];let n=this.presenter.view,[a,o]=n.xAxis.xScale.domain()||[];if(!a||!o)return[];let l=a.getTime(),u=o.getTime(),h=-1,c=-1;for(let e=0;e<i.length;e++){let t=r[i[e]].getTime();if(-1===h&&t>=l&&(h=Math.max(0,e-1)),t<=u)c=e;else if(-1!==h)break}if(-1===h){if(i.length>0&&r[i[0]].getTime()>u)return[];h=i.length-1,c=i.length-1}else -1===c&&(c=h);c=Math.min(i.length-1,c+1);let d=[];for(let e=h;e<c;e++){let s=i[e],a=i[e+1],o=n.toX(r[s]),l=this.axis.toY(t.get(s)),u=n.toX(r[a]),h=this.axis.toY(t.get(a));d.push(this.makeLine({x:o,y:l},{x:u,y:h}))}if(eF(e.pivotPrice)&&eF(e.candPrice)){let t=r[e.pivotIndex].getTime();if(r[e.candIndex].getTime()>=l&&t<=u){let t=n.toX(r[e.pivotIndex]),i=this.axis.toY(e.pivotPrice),s=n.toX(r[e.candIndex]),a=this.axis.toY(e.candPrice);d.push(this.makeLine({x:t,y:i},{x:s,y:a}))}}return d}}function gW(e){let t=Math.abs(e)/Math.SQRT2,i=1/(1+.3275911*t);return .5*(1+(e<0?-1:1)*(1-((((1.061405429*i+-1.453152027)*i+1.421413741)*i+-.284496736)*i+.254829592)*i*Math.exp(-t*t)))}class gU extends mC{studyPlotId;periodTarget=0;targetPrice1=0;targetPrice2=0;pricesCount=0;targetDate;computed=!1;anchorPrice=0;sigmaAnnualized=0;unitsPerYear=0;probabilityAbove=0;probabilityBelow=0;probabilityBetween=0;styles=[];constructor(e,t,i){super(e,t),this.studyPlotId=i}makeStyles(){let e=this.lineOnlyStyle(tz.AT_LINE),t=this.lineOnlyStyle(tz.AT_LINE_2);this.styles=[e,t,t]}containerOf(e){return e?.timeSeries.container}get mainCont(){return this.containerOf(this.presenter.mainPlot)}get studyCont(){return this.containerOf(this.studyPlot)}get studyPlot(){return this.presenter.allPlots.find(e=>e.id===this.studyPlotId)}get targetPrice(){return 0!==this.targetPrice1?this.targetPrice1:this.targetPrice2}setOptions(e){if(this.periodTarget=e.PeriodTarget,this.targetPrice1=e.TargetPrice1,this.targetPrice2=e.TargetPrice2,this.pricesCount=+(0!==this.targetPrice1)+ +(0!==this.targetPrice2),this.pricesCount>1&&this.targetPrice1<this.targetPrice2){let e=this.targetPrice1;this.targetPrice1=this.targetPrice2,this.targetPrice2=e}}get haveInput(){return 0!==this.periodTarget&&(0!==this.targetPrice1||0!==this.targetPrice2)}get haveData(){return eH(this.mainCont)&&!this.mainCont.isEmpty&&this.studySeries.haveVolatility}get studySeries(){return this.studyPlot.timeSeries}getData(){let e=this.presenter.timeline;this.targetDate=e.at(e.lastSeriesIndex+this.periodTarget),this.points=[new mm(this.axis,this.targetPrice,this.targetDate)],this.pricesCount>1&&this.points.push(new mm(this.axis,this.targetPrice2,this.targetDate)),this.unitsPerYear=f0(this.presenter.data.aggregation),this.anchorPrice=this.mainCont.getLastDataPoint(ag.Close),this.sigmaAnnualized=this.studySeries.getVolatilityPercent()}computeProbabilities(){let e=this.sigmaAnnualized*Math.sqrt(this.periodTarget/this.unitsPerYear),t=t=>(t-this.anchorPrice)/(this.anchorPrice*e),i=gW(t(this.targetPrice));if(this.pricesCount>1){let e=gW(t(this.targetPrice2));this.probabilityAbove=1-i,this.probabilityBelow=e,this.probabilityBetween=i-e}else this.probabilityBelow=i,this.probabilityAbove=1-this.probabilityBelow;this.computed=!0}compute(){this.haveInput&&this.haveData&&(this.getData(),this.computeProbabilities())}getElements(){if(this.computed||this.compute(),!this.computed||!this.studyPlot.mainCurve.visible)return[];let e=[];return e.push(new mf(this.points[0].point,!0,this.axis)),e.push(new mf(this.points[0].point,!1,this.axis)),this.pricesCount>1&&e.push(new mf(this.points[1].point,!1,this.axis)),e}getStyleForElement(e,t){return this.styles.length||this.makeStyles(),this.styles[t]}get hasPoint(){return this.points.length>0}getTimeScaleAdornments(){return this.hasPoint?[{time:this.points[0].time,color:this.traits.line.color}]:[]}getPriceScaleAdornments(){if(!this.hasPoint)return[];let e=[];return e.push({price:this.points[0].price,color:this.traits.line2.color}),this.pricesCount>1&&e.push({price:this.points[1].price,color:this.traits.line2.color}),e}adornElements(e,t){if(this.computed){let[e,i]=[!0,!1].map(e=>Math.abs(iB(t,e))),s=this.pricesCount>1,r=this.points[0].point,n=s?this.points[1].point:r,a=this.traits.line2.color,o=iI(a),l=iF(t),u=["Above","Below","Between"],h=(e,t)=>`${eB(100*e,2).toFixed(2)}% Probability ${u[t]}`,c=(e,i)=>iU(t,e,i,Q.Right,o,a);if(c(h(this.probabilityAbove,0),{x:r.x-10,y:r.y-e}),s){let e=r.y+(n.y-r.y+l)/2;c(h(this.probabilityBetween,2),{x:r.x-10,y:e})}c(h(this.probabilityBelow,1),{x:n.x-10,y:n.y+i})}}}let g$=new class{resizingPanes=!1;snapToSupported=!1;touchCrosshairMode=!1;notifyZoomChanged;previousTouchTimestamp=null;resizingScale=!1;resizingScaleId=null;lastScaleResizingOffset=null;touchCrosshairTimeout=null;lastResizingOffset=null;splitter;prevZoomingOffset;prevPinchDistance=null;constructor(){this.stopResizingScale(),this.notifyZoomChanged=eV(ay.CH_ZOOMCHANGED,1e3)}startTouchCrosshairMode(e,t,i){this.touchCrosshairMode=!0,this.showCrosshairAndTooltips(e.view,t,i)}activated(){}deactivated(){}findHit(e){let t;if(!e.point)return[];if(e.axis.pane.axes.some(t=>t.plots.some(t=>t.hitTestCustomEvent(e.point))))return tz.EVENT_PIN_HIT;let i=e.presenter.selectedAnnotation;void 0!==i&&(t=i.points.find(t=>t.hitTest(e.point)));let s=eC(e.axis.annotations.filter(t=>t.computed?null:t.hitTest(e.point)));return void 0!==t&&null==s&&(s=i),[s,t]}stopResizingScale(){this.resizingScale=!1,this.resizingScaleId=null,this.lastScaleResizingOffset=null}resetVerticalAxis(e,t=!0){this.stopResizingScale(),e.isCustomDomain=!1,t&&e.setDomain()}resetHorizontalAxis(e,t=!0){e.view.xAxis.resetZoom(),t&&e.view.setPriceAxesDomains(),this.fireZoomChanged(e)}fireZoomChanged(e){this.notifyZoomChanged({chart:e.accessor})}onMouseDblClick({priceAxis:e,offset:t,presenter:i,view:s}){let r=s.xAxis.viewBox.contains(t),n=!1;if(eF(e))this.resetVerticalAxis(e),n=!0;else if(r)this.resetHorizontalAxis(i),n=!0;else if(eO()){let e=i.selectedAnnotation;null!=e?m2(e,t):m3(i,t)}n&&s.redraw()}onMouseEnter(){this.previousTouchTimestamp=null}computePreviousTouchStartDuration(){if(!eO())return null;let e=new Date().getTime(),t=eF(this.previousTouchTimestamp)?e-this.previousTouchTimestamp:null;return this.previousTouchTimestamp=e,t}onMouseDown(e){let{point:t,button:i,splitter:s,offset:r,priceAxis:n,presenter:a,originalEvent:o}=e,l=window.navigator.platform.toLowerCase().startsWith("mac"),u=l?ei.Meta:ei.Control,h=i===et.Right||l&&i===et.Left&&e.getModifier(ei.Control);this.touchCrosshairMode&&eF(this.touchCrosshairTimeout)&&(clearTimeout(this.touchCrosshairTimeout),this.touchCrosshairTimeout=null);let c=this.computePreviousTouchStartDuration();if(eF(c)&&c<tz.DOUBLE_CLICK_DURATION_MILLIS)return this.onMouseDblClick(e),!0;if(!h&&this.isLogoLink(r)&&a.notifyHost(ay.CH_LOGOCLICKED,{chart:a.accessor}),eF(t)&&a.allPlots.some(e=>e.tryHandleCustomEventClick(t.point)))return!0;if(eF(s))return this.resizingPanes=!0,this.lastResizingOffset=r,this.splitter=s,a.enableTooltip(!1),!0;if(eF(n))return eW(a.display.chart.zooming)[0]&&this.startAxisScaling(n,r),!0;if(null!=t){if(e.getModifier(u))return a.activeTool=new m1,a.activeTool.onMouseDown(e),!0;let[i,s]=this.findHit(t);if(a.clearSelection(),null!=i&&a.setSelection(i),null==i||i?.locked)return h?(null==i?m3(a,r,o):i?.locked&&m2(i,r),!0):!!this.touchCrosshairMode||(a.activeTool=new mX(t),a.activeTool.startPan(r),mq());let n=null!=s;return h?(m2(i,r),eO()):(!n||!!s.movable)&&(!!n||!!i.canMove(t.point))&&(a.activeTool=n&&-1!==i.points.indexOf(s)?new mp(i,s):new md(i,t,r),eO())}return this.prevZoomingOffset=r,!1}onContextMenu(e){return!0}isLogoLink(e){let t=eH(mZ)&&mZ.logoClickable?mZ.rect:null;return eF(t)&&t.contains(e)}onMouseMove(e){let{point:t,splitter:i,priceAxis:s,view:r,presenter:n,offset:a}=e;if(eF(e.pinchZoom)&&e.pinchZoom&&eF(e.pinchDistance))return eF(this.prevPinchDistance)&&(e.delta=this.prevPinchDistance-e.pinchDistance,this.onWheel(e)),this.prevPinchDistance=e.pinchDistance,eO();if(null!=i||this.resizingPanes)r.setCursor(ee.ResizeVertical),this.resizingPanes&&this.resizePanes(r,a);else if(eF(t)){let[e,i]=this.findHit(t);eF(i)?t.presenter.view.setCursor(ee.Crosshair):eF(e)?e.isSelected?t.presenter.view.setCursor(ee.Move):t.presenter.view.setCursor(ee.Hand):t.presenter.view.setCursor(ee.Arrow)}else if(eF(s))eW(n.display.chart.zooming)[0]&&(r.setCursor(ee.ResizeVertical),this.performAxisScaling(r,s,a));else{if(this.prevZoomingOffset){let{x:e}=this.prevZoomingOffset,{x:t}=a;this.applyZoom(r.presenter,-(e-t)),this.prevZoomingOffset=a}r.setCursor(ee.ResizeHorizontal)}return!t||this.resizingPanes?this.hideCrosshairAndTooltips(r):(this.isLogoLink(a)&&r.setCursor(ee.Hand),this.showCrosshairAndTooltips(r,t,a)),eO()}showCrosshairAndTooltips(e,t,i){t.time&&(!eO()||this.touchCrosshairMode)&&e.drawCrosshair({ap:t,offset:i})&&e.presenter.showTooltip&&mz(e.presenter,{time:t.time,offset:i,price:t.price,lastBarRefresh:void 0,justMain:void 0})}hideCrosshairAndTooltips(e,t=!1){e.drawCrosshair({ap:void 0}),e.tooltip.hide(),e.presenter.hideCards(t),t&&"cards"===e.tooltip.mode&&!e.presenter?.hasLegend&&mG(e.presenter)}onMouseLeave(e){let{view:t,offset:i}=e,s=t.presenter.accessor.getPaneBounds();s?.every(e=>!e.contains(i)||i.x===e.x||i.x===e.x+e.width||i.y===e.y||i.y===e.y+e.height)&&(this.hideCrosshairAndTooltips(t,!0),this.stopResizeZoom(t.presenter)),t.setCursor(ee.Arrow),this.touchCrosshairMode=!1}stopResizeZoom(e){this.resizingPanes&&(this.resizingPanes=!1,e.enableTooltip(!0),e.onPaneHeightsUpdated()),this.resizingScale&&this.stopResizingScale(),this.prevZoomingOffset&&delete this.prevZoomingOffset}onMouseUp({presenter:e}){if(this.stopResizeZoom(e),eO()){let t=function(){let e=Sp().config.touchCrosshairTimeoutMillis;return eF(e)&&Number.isFinite(e)?e:tz.LONG_PRESS_TIMEOUT_MILLIS}();this.touchCrosshairTimeout=window.setTimeout(()=>{this.hideCrosshairAndTooltips(e.view,!0),this.touchCrosshairMode=!1},t)}}applyZoom(e,t,i=!0){if(!eW(e.display.chart.zooming)[1])return;let s=Math.sign(t)*(eO()?2:10),r=e.view;r.xAxis.zoom(s)&&(r.setPriceAxesDomains(),r.redraw(),i&&this.fireZoomChanged(e))}onWheel({view:e,presenter:t,getModifier:i,delta:s}){let{scrollBehavior:r}=t.display;return!!(eO()?"none"!==r:"wheel"===r||"wheel+shift"===r&&i(ei.Shift))&&0!==s&&(e.drawCrosshair({ap:void 0}),e.tooltip.hide(),e.presenter.hideCards(),this.applyZoom(t,s),!0)}get useKeyboardShortcuts(){return Sp().config.hostingModel!==eo[eo.Application]}onKeyDown(e){let{key:t,code:i,presenter:s}=e;if(eF(s.selectedAnnotation)&&("Backspace"===t||"Delete"===t||8===i||46===i)){let e=s.selectedAnnotation;e.axis.deleteAnnotation(e),s.onAnnotationModifiedByTool(e,el.Deleted)}if(eF(s.selectedAnnotation)&&(ew(t,i)?s.clearSelection():("F2"===t||113===i)&&s.selectedAnnotation instanceof mD&&s.selectedAnnotation.textEditable&&(s.activeTool=new mH(null,s.selectedAnnotation),s.activeTool.startEditing())),eR(t,i)||"ArrowRight"===t||39===i){let e=eR(t,i)?1:-1,r=s.view;r.xAxis.pan(e*r.xAxis.xScale.bar.totalWidth),r.redraw()}let r=window.navigator.platform.toLowerCase().startsWith("mac")?ei.Meta:ei.Control;if(e.getModifier(r)&&this.useKeyboardShortcuts){let e="z"===t||90===i,r="y"===t||89===i;return e&&s.undoRedoManager.undo(),r&&s.undoRedoManager.redo(),e||r}("r"===t||82===i)&&e.getModifier(ei.Alt)&&this.resetView(s)}resetView(e){e.allAxes.forEach(e=>this.resetVerticalAxis(e,!1)),this.resetHorizontalAxis(e,!1),e.view.xAxis.goToLatest(!0)}resizePanes(e,t){let i=t.y-this.lastResizingOffset.y;if(0===i)return;let s=e.presenter.panes,[r,n]=this.splitter,a=s.map((e,t)=>{let s=e.getBounds().height;return t===r?s+i:t===n?s-i:s});if(a.some(e=>e<tz.MINIMUM_PANE_HEIGHT))return;let o=(e,t)=>e+t,l=a.reduce(o,0),u=s.map(e=>e.height).reduce(o,0);s.forEach((e,t)=>e.height=eB(a[t]/l*u,4)),this.lastResizingOffset=t,e.recalculateLayout(),e.redraw()}startAxisScaling(e,t){this.resizingScale=!0,this.resizingScaleId=e.id,this.lastScaleResizingOffset=t}performAxisScaling(e,t,i){if(this.resizingScale&&this.resizingScaleId===t.id){let s=eO()?4:5,r=function(e,t,i,s=1,r=-1){let n=(i.y-t.y)/10,a=e.yScale.rangeWithPadding().reverse();return[a[0]+n*s,a[1]+n*r].map(t=>e.yScale.yToPrice(t))}(t,this.lastScaleResizingOffset,i,s,-s);this.lastScaleResizingOffset=i,t.isCustomDomain=!0,t.yScale.domain(r),e.redraw()}}},gG=e=>gX(m4,gT,1,e),gz=e=>gX(m4,mO,1,e),gY={Default:()=>function(){return g$},Line:()=>gX(mR,ge,!1),DateRange:()=>gX(mR,gD,!1),PriceRange:()=>gX(mR,gO,!1),DatePriceRange:()=>gX(mR,gw,!1),GannBox:()=>gX(mR,gR,!1),GannSquare:()=>gX(mV,gH),Ray:()=>gX(mR,ge,!1),GannLine:()=>gX(mN,ge,!1),VerticalLine:()=>gX(m4,gt,1),HorizontalLine:()=>gX(m4,gi,1),LongPosition:()=>gX(m4,gb,1,!0),ShortPosition:()=>gX(m4,gb,1,!1),FiftyPercentLine:function(e,t){return eF(e)?gX(m5,gs,e.axis||t.mainAxis,e):gX(m4,gs,2)},FibonacciRetracement:()=>gX(mR,gn,!1),TrendBasedFibExtension:()=>gX(mR,ga,!0),FibonacciFan:()=>gX(mR,gu,!1),FibonacciArcs:()=>gX(mR,gp,!1),FibonacciChannel:()=>gX(mR,gF,!0),GannFan:()=>gX(mR,gf,!1),SpeedResistanceFan:()=>gX(mR,gm,!1),SpeedResistanceArcs:()=>gX(mR,gg,!1),AndrewsPitchfork:()=>gX(m4,gy,3),Rectangle:()=>gX(mR,mJ,!1),Ellipse:()=>gX(mR,gS,!1),TrendChannel:()=>gX(mR,gA,!0),SymbolArrowUp:()=>gG("arrow_up"),SymbolArrowDown:()=>gG("arrow_down"),SymbolArrowRight:()=>gG("arrow_right"),SymbolArrowLeft:()=>gG("arrow_left"),SymbolArrowHorizontal:()=>gG("arrow_horizontal"),SymbolArrowVertical:()=>gG("arrow_vertical"),SymbolArcDown:()=>gG("arc_down"),SymbolArcUp:()=>gG("arc_up"),SymbolThumbsUp:()=>gG("thumbs_up"),SymbolThumbsDown:()=>gG("thumbs_down"),SymbolZero:()=>gG("zero"),SymbolOne:()=>gG("one"),SymbolTwo:()=>gG("two"),SymbolThree:()=>gG("three"),SymbolFour:()=>gG("four"),SymbolFive:()=>gG("five"),SymbolSix:()=>gG("six"),SymbolSeven:()=>gG("seven"),SymbolEight:()=>gG("eight"),SymbolNine:()=>gG("nine"),SymbolQuestion:()=>gG("question"),SymbolFishHook:()=>gG("fish_hook"),SymbolBuy:()=>gG("buy"),SymbolSell:()=>gG("sell"),FibonacciTimeZones:()=>gX(mR,gv,!1),Text:()=>gX(mH,mD,null),PickPoint:()=>function(){return new gP},ZoomIn:()=>function(){return new m1},ProfitLoss:gz,RewardRisk:gz,VolumeAtPrice:function(e){return gX(m4,gB,2,e)},ZigZag:function(e){return gX(m5,gk,null,e)},ProbabilityCones:function(e){return gX(m4,gU,2,e)}};function gj(e,t=!1,i=null,s=null,r=null){let n=gY[e];return(n=n(s,r))(e,t,i)}function gK(e,t={}){e.enableTooltip(!0),e.resetActiveTool();let{axis:i,annotation:s,toolChange:r,annId:n}=t;eF(i)&&e.onAnnotationsUpdated(i),eF(s)&&e.onAnnotationModifiedByTool(s,r),[el.Cancelled,el.Executed,el.TextChanged].includes(r)&&e.onAnnotationDone(n,r)}function gq(e,t=!0,i=el.None){e.wasModifiedByTool();let s=e.axis;gK(s.pane.presenter,t?{axis:s,annotation:e,toolChange:i}:void 0)}function gX(e,t,i,s){return function(r,n,a){let o=mT(r,t,s,a);return(o.annName=r,n)?o:new e(o,i)}}function gZ(e){e.button===et.Right&&gK(e.presenter)}function gJ(e,t,i){let s={};s.source=ag[e.source],s.inputs=eK(e.inputs);let r=void 0!==e.target,n=eF(i)?i:e.curves;return s.outFields=function(e){let t=[];for(let i of e)t.includes(i)||t.push(i);return t}(r?[ag[e.target]]:n.map(e=>e.fields).flat()),s.target=r?ag[e.target]:s.outFields[0],s.aggregation=t,s}class gQ extends mo{model;basePlot;_hasEvents;_params;_shiftFmt;_title;range;shouldMaybePriceMap;annIndex;_canPriceMap;#e(e=3){let t=this.model.inputs||[],i=t.length;if(0===i)return"";let s="";i>e&&(t=t.slice(0,3),s=", ...");let r="AVWAP"===this.model.study;return 0===t.length?"":`(${t.map(e=>r&&"Anchor"===e.name?new Date(e.value).toLocaleString():e.value).join(", ")}${s})`}get params(){return eF(this._params)||(this._params=this.#e()),this._params}get fullParams(){return this.#e(Number.MAX_VALUE)}get shiftFmt(){if("PC"===this.model.study)return"";if(!eF(this._shiftFmt)){let e=this.curves.map(e=>Number(e.shift)).filter(e=>0!==e);this._shiftFmt=0===e.length?"":`[${e.join(", ")}]`}return this._shiftFmt}get title(){if(!eF(this._title)){let e=this.params,t=this.shiftFmt;this._title=`${this.model.study} ${e} ${t}`.trim()}return this._title}fromModel(e){this.model=e,super.fromModel(this.model)}getMetaData(){let e=sR(this.model.study),t=e.meta.decimals;this.metaData=void 0!==t?new ii(t):this.basePlot.metaData,eF(e.meta.range)&&(this.range=e.meta.range)}getDetachedScaleMargins(){return"VOL"===this.model?.study&&this.axis?.pane.isMain?tz.VOLUME_DETACHED_SCALE_MARGINS:super.getDetachedScaleMargins()}applySpecifics(e){let t=this.model.study;!0===sR(t).meta.shiftable&&this.curves.forEach(t=>{Number.isFinite(e.inputs.Offset)&&(t.shift=e.inputs.Offset)});let i=(e,t,i)=>this.curves[e].zones[t].value=this.model.levels[i].value;switch(t){case"ICHCLD":{let t=e.inputs.Displacement;this.curves[2].shift=-t,this.curves[3].shift=t,this.curves[4].shift=t,this.curves[5].shift=t;break}case"MARIB":{let t=Math.min(Math.max(0,e.inputs.Count),10);this.curves.forEach((e,i)=>e.visible=e.visible&&i<t);break}case"CRS":{let t="PercentChange"===e.inputs.Display;this.axis.comparison=t?q.Percent:q.None;break}case"PERF":{let t="VisibleStart"===e.inputs.Anchor;this.axis.comparison=t?q.Percent:q.None;break}case"JPI":case"CTTP":case"CTTI":{let t=ex(10,e=>(e+1)*.025),i=([e,i])=>[...t.map(t=>i_(t)(e)).reverse(),i,"#6a4a3a","#a000c8","#ffffff"];this.curves[0].colors=i(this.curves[0].colors),this.curves[1].colors=i(this.curves[1].colors);let s=this.curves[0].colors.length;this.curves[0].colors[s-1]=this.curves[1].colors[t.length],this.curves[1].colors[s-1]=this.curves[0].colors[t.length],this.shouldMaybePriceMap="Performance"===e.inputs.Height;break}case"RSI":case"RSIMOD":case"RSISTO":case"CCI":i(0,0,0),i(0,1,2);break;case"STC":i(0,0,0),i(0,1,1);break;case"RVOL":case"DPO":case"COPP":i(0,0,0);break;case"VOL":this.setCurveAttributes(0,e.inputs.BarColoring);break;case"MAVOL":this.setCurveAttributes(1,e.inputs.BarColoring);break;case"VOLAP":{this.notifyAboutPriceDomains=!0,this.customPlotValues=!0,eF(this.annotations)||(this.annotations=[]);let t=this.curves[1],i=this.curves[2],s=gj("VolumeAtPrice",!0,{[tz.AT_LINE]:{color:t.colors[0],width:t.lineWidth,dashStyle:t.dashStyle},[tz.AT_FILL]:{color:this.curves[0].colors[0]},[tz.AT_FILL2]:{color:this.curves[0].colors[1]},[tz.AT_FILL3]:{color:this.curves[0].colors[2]},[tz.AT_FILL4]:{color:i.colors[0]},[tz.AT_FILL5]:{color:i.colors[1]},[tz.AT_FILL6]:{color:i.colors[2]}},this.id)(this.axis,!1);s.setOptions(e.inputs),this.annIndex=this.annotations.push(s)-1;break}case"PVACP":{this.customPlotValues=!0,eF(this.annotations)||(this.annotations=[]);let t=this.curves[1],i=this.curves[2],s=this.curves[3],r=gj("VolumeAtPrice",!0,{[tz.AT_LINE]:{color:t.colors[0],width:t.lineWidth,dashStyle:t.dashStyle},[tz.AT_FILL]:{color:this.curves[0].colors[0]},[tz.AT_FILL2]:{color:this.curves[0].colors[1]},[tz.AT_FILL3]:{color:this.curves[0].colors[2]},[tz.AT_FILL4]:{color:i.colors[0]},[tz.AT_FILL5]:{color:i.colors[1]},[tz.AT_FILL6]:{color:i.colors[2]},[tz.AT_FILL7]:{color:s.colors[0]}},this.id)(this.axis,!1);r.setOptions(e.inputs),this.annIndex=this.annotations.push(r)-1;break}case"ZIGZAG":{this.customPlotValues=!0,eF(this.annotations)||(this.annotations=[]);let e=gj("ZigZag",!0,{[tz.AT_LINE]:{color:this.curves[0].colors[0],width:this.curves[0].lineWidth,dashStyle:this.curves[0].dashStyle}},this.id)(this.axis,!1);this.annIndex=this.annotations.push(e)-1;break}case"IVRANK":{let t=ag.ImplVolRank1Y;switch(e.inputs.TimeFrame){case"1-Year":default:break;case"5-Day":t=ag.ImplVolRank5D;break;case"1-Month":t=ag.ImplVolRank1M;break;case"3-Month":t=ag.ImplVolRank3M;break;case"6-Month":t=ag.ImplVolRank6M;break;case"YTD":t=ag.ImplVolRankYTD}this.curves[0].fields[0]=t,e.outFields[0]=t;break}case"IVPCTL":{let t=ag.ImplVolPerc1Y;switch(e.inputs.TimeFrame){case"1-Year":default:break;case"5-Day":t=ag.ImplVolPerc5D;break;case"1-Month":t=ag.ImplVolPerc1M;break;case"3-Month":t=ag.ImplVolPerc3M;break;case"6-Month":t=ag.ImplVolPerc6M;break;case"YTD":t=ag.ImplVolPercYTD}this.curves[0].fields[0]=t,e.outFields[0]=t;break}case"OPTIV":{let t=[ag.WeighImplVolHigh,ag.WeighImplVol,ag.WeighImplVolLow];switch(e.inputs.TimeFrame){case"1-Day":default:break;case"5-Day":t=[ag.WeighImplVolHigh5D,ag.WeighImplVol5D,ag.WeighImplVolLow5D];break;case"1-Month":t=[ag.WeighImplVolHigh1M,ag.WeighImplVol1M,ag.WeighImplVolLow1M];break;case"3-Month":t=[ag.WeighImplVolHigh3M,ag.WeighImplVol3M,ag.WeighImplVolLow3M];break;case"6-Month":t=[ag.WeighImplVolHigh6M,ag.WeighImplVol6M,ag.WeighImplVolLow6M];break;case"1-Year":t=[ag.WeighImplVolHigh1Y,ag.WeighImplVol1Y,ag.WeighImplVolLow1Y];break;case"YTD":t=[ag.WeighImplVolHighYTD,ag.WeighImplVolYTD,ag.WeighImplVolLowYTD]}this.curves[0].fields[0]=t[0],this.curves[1].fields[0]=t[1],this.curves[2].fields[0]=t[2],e.outFields=[...t];break}case"PC":{let t=e.inputs.PeriodForecast-1;this.curves.forEach(e=>e.shift=t),eF(this.annotations)||(this.annotations=[]);let i=this.curves[11],s=this.curves[12],r=gj("ProbabilityCones",!0,{[tz.AT_LINE]:{color:i.colors[0],width:i.lineWidth,dashStyle:i.dashStyle},[tz.AT_LINE_2]:{color:s.colors[0],width:s.lineWidth,dashStyle:s.dashStyle}},this.id)(this.axis,!1);r.setOptions(e.inputs),this.annIndex=this.annotations.push(r)-1}}}getValueAt(e,t,i){return this.isVolAP?this.annotations[this.annIndex].getValueAt(e,t,i):super.getValueAt(e,t,i)}getColorOf(e){if(!this.isVolAP&&!this.isZigZag)return null;let t=this.curves[0].colors;if(this.isZigZag)return t[0];switch(e){case ag.UPVOL:return t[1];case ag.DNVOL:return t[0];case ag.TOTVOL:return t[2];case ag.POC:case ag.VAREA:case ag.BARBACK:return tz.COLOR_TRANSPARENT;default:throw Error("Unexpected Volume At Price field")}}isEmpty(){return!this.isVolAP&&!this.isZigZag&&super.isEmpty()}setCurveAttributes(e,t){let i=t=>this.curves[e].attributes=[U[t]];switch(t){case"LikeMain":{let t=this.axis.pane.presenter.mainPlot.curves[0].attributes,s=Sp().config.defaultVolumeBarColoring;eF(t)?this.curves[e].attributes=[t[0]]:i(eF(s)?"OpenToClose"===s?"OpenVsClose":"ChangeBased":"OpenVsClose");break}case"OpenToClose":i("OpenVsClose");break;case"CloseToClose":i("ChangeBased");break;default:throw Error(`Unexpected bar coloring choice: ${t}`)}}get hasEvents(){return this._hasEvents}get eventsSeries(){return this.timeSeries}doesSeriesEmitEvents(){let e=this.timeSeries.helpers;return e.includes(ag.Buy)||e.includes(ag.Sell)}getEventFor(e){switch(e){case ag.Buy:return{show:!0,title:"B",color:"#03c03c"};case ag.Sell:return{show:!0,title:"S",color:"#c23b22"};default:return null}}getEventFields(){return this.hasEvents?[ag.Buy,ag.Sell]:[]}async initialize(){if(this.model.basis!==tz.BASIS_MAIN)throw Error("Studies can currently only be based on the main (symbol) plot");return tU.call(this,async()=>{this.basePlot=this.axis.pane.presenter.mainPlot,await this.basePlot.initialize(),this.getMetaData();let e=this.axis.pane.presenter.data.aggregation,t=gJ(this.model,e,this.curves);this.applySpecifics(t);let i=this.basePlot.timeSeries;i instanceof cS&&(i=i.actual),this.timeSeries=fb(this.model.study,t,i),this._hasEvents=this.doesSeriesEmitEvents(),this.timeSeries.useNotifications=!0;let s=this.title,r=this.basePlot.timeSeries instanceof uJ;return this.timeSeries.ready().then(e=>{e||r||this.timeSeries.computedServerSide||So(`Unable to calculate study values for ${s}`,"error")}),!0})}get isJpi(){return["JPI","CTTP","CTTI"].includes(this.model.study)}get isVolAP(){return"VOLAP"===this.model.study||"PVACP"===this.model.study}get isZigZag(){return"ZIGZAG"===this.model.study}invalidateAssociatedAnnotations(e){this.isVolAP&&this.annotations[this.annIndex].invalidate(e)}onPriceDomainsUpdated(){this.invalidateAssociatedAnnotations("PriceDomainsChanged")}shouldPriceMap(e){return this.isJpi?!!this.shouldMaybePriceMap&&(e.id===ag.JPIB.id||e.id===ag.JPIS.id):super.shouldPriceMap(e)}canPriceMap(e,t){if(!this.isJpi)return super.canPriceMap(e,t);this._canPriceMap=e>0}priceMap(e,t,i){if(!this.isJpi)return super.priceMap(e,t,i);if(t>this.visToIndex)return e;let s=(e,t)=>this.timeSeries.container.getData(e)[t],r=s(ag.JPIB,t),n=s(ag.JPIS,t);if(null===r&&i.id===ag.JPIB.id||null===n&&i.id===ag.JPIS.id)return null;let a=0,o=this.visFromIndex,l=this.timeSeries.helpers[0],u=this.timeSeries.helpers[2];for(;o<=t;)a+=1===s(u,o)?0:s(l,o),o++;return a}}let g0=[ag.Open,ag.High,ag.Low,ag.Close,ag.Volume];class g1 extends mo{_expression;exprModel=null;symbols=null;errorText;get title(){return this.expression}get expression(){return this._expression}async parseExpression(){let e=nK(this._expression);if(this.exprModel=null,this.symbols=null,nj(e))this.errorText=e.error;else{let{model:t,clean:i,symbols:s}=e;this.errorText=void 0,this.symbols=s,this.exprModel=t,this._expression=i}}get isValid(){return!eF(this.errorText)}#t(e){return{mapper:e=>e.query.symbol,loadMoreData:!0,recompute:B.Minimum,missing:F.UseNext,stretch:e=>!1,fieldMap:new Map(g0.map(e=>[e,e])),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:e}}getTimeSeries(){let e=this.getInnerSeries(),t=this.axis?.pane.presenter.data?.exprSkipLeadingEmpty??!1,i=new py(this.exprModel,e,this.#t(t));this.timeSeries=this.wrapIfAdvancedStyle(i);let s=this.title;this.timeSeries.ready().then(e=>{e||So(`Unable to calculate expression: ${s}`,"error")})}getInnerSeries(){let e=nJ(this.exprModel),t=Sp().getTimeSeriesDataSource();return e.map(e=>{let i=this.makeQuery();return i.symbol=e,t.getTimeSeries(i)})}getRecord(){if(eF(this.errorText))return;let e=this.metaData.inner.map(e=>[e.symbol,e.resolved]);this.record=new aw(e,ez(this.exprModel)),this.record.ready().then(e=>e)}getMetaData(){this.isValid&&(this.metaData=new ir(this.symbols),this.metaData.ready().then(e=>{e&&(this.getRecord(),this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this}))}))}fromModel(e){super.fromModel(e),this._expression=e.expression}async initialize(){return tU.call(this,async()=>(await this.parseExpression(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class g2 extends mo{suffix;_forward;offset;errorText;fwdModel=null;outField;roots=null;symbols=[];get title(){return`${this.forward}${this.suffix}`}get forward(){return this._forward}fromModel(e){super.fromModel(e),this.offset=e.offset,this._forward=e.forward}async parseForward(){let e=nK(this.forward),t=nj(e);if(t?(this.errorText=e.error,this.fwdModel=null,this._forward=e.text):(this.errorText=void 0,this.fwdModel=e.model,this._forward=e.clean),t)this.roots=null;else{this.offset>0?(this.suffix=` (${ed(uE(this.offset),l$(tz.FMT_US_DATE_ONLY))(new Date)})`,this.outField=new ap(`Close_${this.offset}`,Y.Number,K.Forward,`Close (${this.offset})`),this.curves[0].fields[0]=this.outField):(this.suffix="",this.outField=ag.Close);let{yes:t,no:i}=eA(e.symbols,e=>ty(`${e}*1`)),s=(await Promise.all(t.map(e=>tM(e)))).map(e=>e.map(e=>e.name));this.roots=t.reduce((e,t,i)=>(e[t]=s[i],e),{}),this.symbols=i}}get isValid(){return!eF(this.errorText)}getMetaData(){if(this.isValid){let e=Object.values(this.roots).flat();this.metaData=new ir(e),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this})})}}getForwardPolicy(e){return{mapper:e=>e.query.root,loadMoreData:!1,recompute:B.Everything,missing:F.UseNext,stretch:e=>!1,fieldMap:new Map([[ag.Close,this.outField]]),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1,valueProvider:e}}getTimeSeries(){let e=Sp().getTimeSeriesDataSource(),t=Object.keys(this.roots),i=0===this.offset?J.Forward:J.HistoricalForward,s=t.map(t=>{let s={seriesKind:i,root:t,offset:this.offset,symbols:this.roots[t],getHashKey:()=>`${i}|${t}|${this.offset}`};return e.getTimeSeries(s)}),r=this.symbols.length>0?new u4(this.symbols):void 0;this.timeSeries=new py(this.fwdModel,s,this.getForwardPolicy(r)),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:en.Unspecified};this.presenter?.notifyHost(ay.TS_MANYCHANGED,e)}})}async initialize(){return tU.call(this,async()=>(await this.parseForward(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}let g3=e=>e.substring(0,e.lastIndexOf("::"));class g4 extends mo{isAverage;hasComputation;offset;offsets;_seasonal;symbolToOffset;errorText;seaModel=null;isPlain=!1;isFutures=!1;suffix="";outField;symbols;coreModel;coreHasComputation;refSeasonal;get title(){if(this.isAverage){let e="YB ";return this.offset<-1&&(e=`${Math.abs(this.offset)}y `),`${e}Average`}return!this.hasComputation&&(this.symbols?.length??0)>0?this.outField.name:`${this.seasonal}${this.suffix}`}get seasonal(){return this._seasonal}fromModel(e){super.fromModel(e),this.offset=e.offset,this.offsets=e.offsets,this.isAverage=e.offset<0,this._seasonal=this.refSeasonal=e.seasonal}constructSeasonal(e,t){return nZ(n0(e,e=>this.applyOffset(e,t)))}constructAverage(e,t=null){let i=null===t?null:t.map(e=>this.symbolToOffset[e]),s=null===i,r=this.offsets.filter(e=>!!s||i.includes(e)).map(t=>`(${this.constructSeasonal(e,t)})`);return`(${r.join("+")})/${r.length}`}prepareFields(){let e=this.isPlain?`${this.yearFromOffset(this.offset)}`:`${this.offset}Y`,t=this.isAverage?"Avg":e;this.suffix=0===this.offset?"":` (${t})`,this.outField=new ap(`Close_${t}`,Y.Number,K.Seasonal,`Close${this.suffix}`),this.curves[0].fields[0]=this.outField}applyOffset(e,t){let i=this.isPlain?e:function(e,t){let i=ty(e),s=tv(e),r=tA(e);if(i)return tI(e,t);if(s){let i=tT.exec(e),s=Number.parseInt(i[2]),r=th(tn(new Date(s+(s>79?1900:2e3),0,1),t));return`${i[1]}${tC(r)}${i[3]}`}if(!r)return null;{let i=e.match(tS),s=tI(i[1],t),r=tI(i[2],t);return`_S_SP_${s}_${r}`}}(e,-t);return`${i}::${t}`}createSymbolToOffsetMapping(e){this.symbolToOffset={},e.forEach(e=>{this.offsets.forEach(t=>{this.symbolToOffset[this.applyOffset(e,t)]=t})})}async parseSeasonal(){let e=nK(this.seasonal,!0),t=nj(e),i=e=>(this.errorText=e,this.seaModel=null,null);if(t)return i(e.error);let{model:s,symbols:r}=e;this.prepareFields();let n=new Map;for(let e of r){let t=tb(await tm(e));n.set(e,t)}s=n0(s,e=>n.get(e));let a=(r=Array.from(n.values())).every(e=>ty(e)||tA(e)),o=r.every(e=>tv(e)),l=r.every(e=>!ty(e)&&!tv(e)&&!tA(e));if(!a&&!o&&!l)return i("Mixed types of symbols aren't supported yet");this.isPlain=l,this.isFutures=a,this.createSymbolToOffsetMapping(r),this.coreModel=this.isAverage?s:null,this.coreHasComputation=nQ(s);let{model:u,symbols:h}=nK(this.isAverage?this.constructAverage(s):this.constructSeasonal(s,this.offset),!0);this.seaModel=u,this.hasComputation=nQ(u),this._seasonal=nZ(n0(u,g3)),this.symbols=h,this.outField.name=this.outField.shortName=this.fixupFieldDescription()}get isValid(){return!eF(this.errorText)}getActualSymbols(){return[...new Set(this.symbols.map(g3))]}fixupFieldDescription(){if(!this.hasComputation&&!this.isAverage){let e=g3(this.symbols[0]);if(this.isPlain)return`${e} ${new Date().getFullYear()-this.offset}`;if(this.isFutures)return tb(e,!0)}return this.title}getMetaData(){if(this.isValid){let e=this.getActualSymbols(),t=1===e.length&&!this.hasComputation&&!this.isAverage,i=Sp().getMetaDataSource();this.metaData=t?i.getMetaData(e[0]):new ir(e),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this})})}}getNoDataApproach(){return this.isAverage&&!this.coreHasComputation?k.ModelTransformRequired:this.hasComputation?k.NoAction:k.IgnoreTimelineOnly}get seasonalPolicy(){return{mapper:e=>e.query.surrogate||e.query.symbol,loadMoreData:!1,recompute:B.Everything,missing:this.hasComputation?F.UsePrevious:F.UseNone,stretch:e=>this.shouldStretch(e),fieldMap:new Map([[ag.Close,this.outField]]),noDataApproach:this.getNoDataApproach(),modelTransform:(e,t)=>0===t.length?this.seaModel:nK(this.constructAverage(this.coreModel,e)).model,skipLeadingEmpty:!1}}shouldStretch(e){return 0===this.symbolToOffset[e]&&(this.isAverage&&this.symbols.length>1||this.offset>0)}shiftYears(e){return tn(new Date,-e)}yearFromOffset(e){return th(this.shiftYears(e))}getCmdtyRange(e){let t=this.shiftYears(e);return[ta(t),function(e){tt(1,arguments);var t=ts(e),i=t.getFullYear();return t.setFullYear(i+1,0,0),t.setHours(23,59,59,999),t}(t)]}getTimeSeries(){if(!this.isValid)return;let e=Sp().getTimeSeriesDataSource(),t=Object.keys(this.symbolToOffset).map(t=>{let i=this.makeQuery();return i.surrogate=t,i.symbol=g3(t),i.offset=this.symbolToOffset[t],i.cacheMe=!this.isPlain||0===i.offset,this.isPlain&&(i.range=this.getCmdtyRange(i.offset)),this.isFutures&&i.offset>0&&eF(...i.range)&&(i.range=i.range.map(e=>tn(e,-i.offset))),i.offset>0&&(i.disableStreamingUpdates=!0),e.getTimeSeries(i)});this.timeSeries=new py(this.seaModel,t,this.seasonalPolicy),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:en.Unspecified};this.presenter?.notifyHost(ay.TS_MANYCHANGED,e)}})}async initialize(){return tU.call(this,async()=>(await this.parseSeasonal(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}let g5=["bottom","right","left"],g6={bottom:"center",right:"start",left:"end"};class g7{lineWidth;arrowLength;position;textAlign;fontSize;fontFamily;padding;strokeColor;textColor;backgroundColor;constructor(e){this.lineWidth=1,this.arrowLength=7,this.position="bottom",this.textAlign="center",this.fontSize=12,this.fontFamily="Arial",this.padding=4,this.strokeColor="white",this.textColor="white",this.backgroundColor="black",e&&this.configure(e)}configure(e){Object.assign(this,e)}draw(e,t,i,s,r,n){let a=eF(r);if(n=n||this.fontSize+this.padding+this.padding+(a?this.padding:0),!g5.includes(this.position.toLowerCase()))return void console.error(`Can not draw indicator in position [${this.position}]`);e.font=`bold ${this.fontSize}px ${this.fontFamily}`,e.textAlign=g6[this.position],e.strokeStyle=this.strokeColor,e.fillStyle=iC(this.backgroundColor),e.lineWidth=this.lineWidth;let o=Math.round(Math.max(...[s,r??""].map(t=>e.measureText(t).width))+("bottom"!==this.position?this.arrowLength:0)+this.padding+this.padding),l=Math.round(o/2),u=Math.round(n/2);e.setLineDash([]),e.beginPath(),e.moveTo(t,i);let h=i+u,c=i+2*u,d=i-u;if("right"===this.position){e.lineTo(t,h);let i=t+o;a&&(e.lineTo(t,c),e.lineTo(i,c)),e.lineTo(i,h),e.lineTo(i,d),e.lineTo(t,d)}else if("left"===this.position){e.lineTo(t,h);let s=t-o;a&&(e.lineTo(t,c),e.lineTo(s,c)),e.lineTo(s,h),e.lineTo(s,d),e.lineTo(t,i-u)}else if("bottom"===this.position){let s=t-l,r=t+l;e.lineTo(t,i),e.lineTo(r,i),e.lineTo(r,i+n),e.lineTo(s,i+n),e.lineTo(s,i),e.lineTo(t,i)}if(e.closePath(),e.stroke(),e.fill(),e.fillStyle=this.textColor,e.textBaseline="middle","bottom"===this.position)e.fillText(s,t,i+iF(e,1));else if("right"===this.position){let n=t+this.arrowLength+this.padding;e.fillText(s,n,i),a&&e.fillText(r,n,i+this.padding+u)}else if("left"===this.position){let n=t-this.arrowLength-this.padding;e.fillText(s,n,i),a&&e.fillText(r,n,i+this.padding+u)}}}let g8=(e,t)=>e-1-t-4,g9=(e,t)=>e+1+t+4,ye=Array.from(Array(6),(e,t)=>++t).reverse();function yt(e){return e.curves.filter(t=>t.visible&&(e.type!==Z.Study||t.style!==$.Ribbon)).map(t=>{let i=t.pickMainField(),[s,r]=function(e,t){let i=e.timeSeries.container;if(null===i||i.size<1)return[null,-1];let s=i.getLastDataPoint(t),r=i.getData(t),n=r.length-1,a=e.type===Z.Study&&["JPI","CTTP","CTTI"].includes(e.model.study);return null!=s||a||(s=-1!==(n=eT(r,e=>null!==e))?r[n]:null),[s,n]}(e,i);return{value:s,color:function(e){let t=e.plot.timeSeries.container;return null===t||t.size<1?null:e.getColor(t.size-1)}(t),field:i,index:r}})}class yi{pane;annotations;id;isCustomDomain;primary;onTheRight;viewBox;plots;comparison;scale;yScale;label;crosshairIndicator;ticks;lastUsedOptions;config;_fullDomain;constructor(e){this.pane=e,this.annotations=[],this.isCustomDomain=!1,this.primary=!1,this.onTheRight=!0,this.plots=[],this.label="",this.id=e1(),this.ticks=null,this.lastUsedOptions=null;let{chart:{fontSize:t},yAxis:{fontSize:i}}=this.pane.presenter.display;this.config={innerTickSize:7,tickPadding:5,indicatorPadding:4,fontWeight:400,fontSize:i||t||12},this.crosshairIndicator=new g7({fontSize:this.config.fontSize,arrowLength:this.config.innerTickSize})}makePlot(e){let t=null;switch(Z[e.type]){case Z.Symbol:t=new ml;break;case Z.Expression:t=new g1;break;case Z.Study:t=new gQ;break;case Z.IncomeStatement:t=new mu(J.IncomeStatement);break;case Z.BalanceSheet:t=new mu(J.BalanceSheet);break;case Z.Forward:t=new g2;break;case Z.Seasonal:t=new g4;break;default:throw Error(`${e.type} isn't supported yet`)}return t.axis=this,t.fromModel(e),t}toPrice(e){let t=this.yScale.yToPrice(e);return this.comparison===q.None?t:this.pane.presenter.mainPlot.priceMap(t,void 0,ag.Close,!0)}toTime(e){return this.pane.presenter.view.toTime(e)}toAnnotationPoint(e){return new mm(this,this.toPrice(e.y),this.toTime(e.x)||void 0)}toX(e){return this.pane.presenter.view.toX(e)}priceMap(e){return this.comparison===q.None?e:this.pane.presenter.mainPlot.priceMap(e,void 0,ag.Close)}toY(e){let t=this.priceMap(e);return this.yScale.priceToY(t)}get plotAnnotations(){let e=[];return this.plots.forEach(t=>{t.annotations&&e.push(...t.annotations)}),e}annTimeToX(e){return this.pane.presenter.view.xAxis?.annTimeToX(e)}snapTo(e){let t={x:this.annTimeToX(e.time),y:this.toY(e.price)},i=this.pane.presenter,s=i.activeTool,r=s.annotation;return s.alignPointsMode&&r&&r.alignPointsSupported&&r.points.includes(e)?this.alignPoints(r,e,t):s.snapToSupported&&i.display.yAxis.snapAnnotationsToPrices&&!e.passive&&(e.moveDirection===es.Both||e.moveDirection===es.Vertical)&&this.snapToPrices(e,t),t}snapToPrices(e,t){let i=this.plots.find(e=>e.main);if(i&&i.timeSeries&&i.timeSeries.hasData){let s=i.timeSeries.container,r=e_(s.getTimeData(),+e.time,Number),n=[].concat(...i.curves.map(e=>e.fields)).filter(e=>s.hasField(e)).map(e=>{let i=s.getData(e)[r],n=this.toY(i),a=Math.abs(n-t.y);return{priceSnap:i,ySnap:n,dist:a}}).filter(e=>e.dist<=tz.SNAP_PROXIMITY_PIXELS).reduce((e,t)=>null===e||t.dist<e.dist?t:e,null);eF(n)&&(e.price=n.priceSnap,t.y=n.ySnap,e.time=s.getTimeData()[r],t.x=this.toX(e.time))}}alignPoints(e,t,i){let s=e.points.find(e=>e!==t);if(t!==s&&s&&s.point){let e=s.point,r=(360+-(180*iT(e,i))/Math.PI)%360;if(r>337.5||r<22.5||r>157.5&&r<202.5)i.y=e.y,t.price=this.toPrice(i.y);else if(r>67.5&&r<112.5||r>247.5&&r<292.5)i.x=e.x,t.time=this.toTime(i.x);else{let s=Math.abs(i.x-e.x),r=e.y>i.y?-1:1;i.y=e.y+s*r,t.price=this.toPrice(i.y)}}}toPoint(e){if(eF(this.pane.presenter.view))return this.snapTo(e)}makeAnnotation(e,t=!0){let i=gj(e.id,!0,e.traits)(this,!1);t&&e.uid&&(i.uid=e.uid);let s=i.activePoints,r=e.points.length-s.length;return r>0&&i.addPoints(r),i.activePoints.forEach((t,i)=>{let s=e.points[i];ek(s.price)&&ek(s.time)&&t.update(s.price,s.time)}),i.visible=e.visible,i.locked=e.locked,i}expand(e){let t=[];switch(e.type){case"Forward":{let i=e.curves,s=e.offsets;delete e.curves,delete e.offsets;for(let r=0;r<i.length;r++){let n=Object.assign({},e);n.curves=[i[r]],n.offset=s[r],t.push(n)}break}case"Seasonal":{let i=e.curves,s=e.offsets;delete e.curves,delete e.offsets;let r=s.filter(e=>e>=0);for(let n=0;n<i.length;n++){let a=Object.assign({},e);a.curves=[i[n]],a.offset=s[n];let o=a.offset<0;if(o){let e=-1===a.offset;a.offsets=e?r:ex(Math.abs(a.offset),e=>e+1)}else a.offsets=[a.offset];(!o||a.offsets.length>1)&&t.push(a)}break}default:t.push(e)}return t}fromModel(e){this.comparison=q[e.comparison??"None"],this.scale=X[e.scale??"Linear"],this.yScale=new mt(this.scale,this),this.label=e.label,this.plots=[].concat(...e.plots.map(e=>this.expand(e))).map(e=>this.makePlot(e));let t=e.annotations||[];this.annotations=t.map(e=>this.makeAnnotation(e));let{chart:{fontFamily:i,backgroundColor:s},yAxis:{textColor:r,crosshair:{color:n},primaryOnTheLeft:a}}=this.pane.presenter.display,o=a??!1;this.onTheRight=this.primary&&!o||!this.primary&&o,this.crosshairIndicator.configure({position:this.onTheRight?"right":"left",fontFamily:i,strokeColor:n,textColor:r,backgroundColor:i_(.15)(s)})}findIndex(e){return this.annotations.findIndex(t=>t.uid===e.uid)}addAnnotation(e){let t=this.makeAnnotation(e,!0);this.appendAnnotation(t),t.requestRedraw(),this.fireAnnotationsChanged()}appendAnnotation(e){-1===this.findIndex(e)&&this.annotations.push(e)}fireAnnotationsChanged(e=!1){this.pane.presenter.onAnnotationsUpdated(this,e)}deleteAnnotation(e,t=!0){e.isSelected&&this.pane.presenter.clearSelection();let i=this.findIndex(e);-1!==i&&this.annotations.splice(i,1),t&&this.fireAnnotationsChanged(!e.isSelected)}fliphorizontalAnnotation(e){e.flip(!0),this.fireAnnotationsChanged(!0)}flipverticalAnnotation(e){e.flip(!1),this.fireAnnotationsChanged(!0)}duplicateAnnotation(e){let t=e.axis,i=this.makeAnnotation(e.toModel(),!1);i.drawPoints(null,!0),i.offset({x:tz.ANN_DUPLICATE_OFFSET,y:tz.ANN_DUPLICATE_OFFSET}),t.appendAnnotation(i),i.requestRedraw(),this.fireAnnotationsChanged()}updateAnnotation(e,t){e.isSelected&&this.pane.presenter.clearSelection(),s8(e.name,t.traits),e.updateFrom(t.traits,t.extras,t.isUndoRedo?null:t.points,t.visible,t.locked),t.isUndoRedo&&eF(t.points)&&e.updateActivePoints(t.points),t.isUndoRedo||this.pane.presenter.undoRedoManager.done(my(e,el.Moved)),e.requestRedraw(),this.fireAnnotationsChanged()}setViewBox(e){this.viewBox=e;let{y:t,height:i}=this.viewBox;this.yScale.range([Math.floor(t),Math.floor(t+i)]),this.plots.forEach(t=>t.setViewBox(e))}get fullDomain(){return eF(this._fullDomain)||(this._fullDomain=this.getDataDomain().domain),this._fullDomain}updateFullDomain(e=null){if(null===e&&this.comparison!==q.None)return;let t=this.fullDomain;this._fullDomain=this.getDataDomain([e,e],t).domain}getPlotDataDomain(e,t,i){let s=e.timeSeries;if(!s.hasData)return{domain:null};let r=s.container,n=r.getTimeData(),a=e=>e_(n,+e,Number),o=eF(t),l=o?a(t):0,u=eF(i),h=u?a(i):n.length-1,c=e.curves.map(e=>e.fields).flat().filter(e=>e.id!==ag.Change.id),d=eF(e.targetFields);d&&c.push(...e.targetFields);let p={},f=t=>{let[i,s]=(t=>{let i=d?e.curves[0]:e.curves.find(e=>e.fields.includes(t));if(!eF(i)||0===i.shift)return[l,h];if(!eF(p[i.id])){let e=i.shiftedTimeDomain;if(!eF(e))return[l,h];p[i.id]=[a(e[0]),a(e[1])]}return p[i.id]})(t),n=r.getData(t),o=Math.max(i,0),u=Math.min(n.length-1,s);return n.slice(o,u+1).map((i,s)=>e.priceMapper(i,s,t))},m=[null,null],g=e=>e.id,y=new Set(eP(r.fields,c,g).map(g));e.curves.filter(e=>e.visible).map(e=>{let t=e.fields.filter(e=>y.has(e.id));e.isStackedColumn?eI(eM(t.map(e=>f(e)).reduce((e,t)=>t.map((t,i)=>(e[i]||0)+(t||0)),[])),m):t.map(e=>{eI(eM(f(e)),m)})});let S=eu.None,A=[$.Column,$.MultiColumn,$.StackedColumn];if(o&&u&&!e.main&&e.curves.some(e=>A.includes(e.style))){let e=m[0]>0,t=m[1]<0;e?(S=eu.Min,m[0]=0):t&&(S=eu.Max,m[1]=0)}return{domain:m,clamped:S}}getDataDomain([e,t]=[null,null],i=[null,null]){let s=ez(i),r=!1;for(let i of this.plots.filter(e=>!e.hasDetachedScale)){let{domain:n,clamped:a}=this.getPlotDataDomain(i,e,t);eF(n)&&(eI(n,s),r=r||a!==eu.None)}if(!eF(s))return{domain:null};let[n,a]=s;if(!eF(n,a))return{domain:null};let o=[Number(n),Number(a)];o[0]===o[1]&&(o[0]-=1,o[1]+=1);let l=eu.None;return r&&(0===o[0]?l=eu.Min:0===o[1]&&(l=eu.Max)),{domain:o,clamped:l}}setDomain(){let e=this.pane.presenter,t=e.view.xAxis.xScale.domain();if(!eF(t))return;for(let e of this.plots.filter(e=>e.hasDetachedScale)){let{domain:i}=this.getPlotDataDomain(e,t[0],t[1]);eF(i)&&e.yScale.domain(i)}if(this.isCustomDomain)return;let{domain:i,clamped:s}=this.getDataDomain(t);if(this===e.mainAxis&&e.mainPlot?.showPrevious){let t=e.mainPlot.getPreviousValue(),s=eG(e.display,!1,"chart","previous","forceVisible");eF(t,i)&&s&&(i[0]=Math.min(i[0],t),i[1]=Math.max(i[1],t))}if(this.yScale.domain(i),eF(i)){let e=this.getPadding(s);eF(e)&&this.yScale.padding(e)}}getInitialPadding(){let e=tO(this.pane.presenter.hostElement),t=tR(`#${tz.HEADER_SIZE_PLACEHOLDER_ID}`,e);if(!eF(t)){tN(t=tB(e,"div"),{display:"none"}),tV(t,{id:tz.HEADER_SIZE_PLACEHOLDER_ID,class:"bcharts-card bcharts-card-first"});let{lineHeight:i}=getComputedStyle(t);isNaN(Number.parseFloat(i))&&tN(t,{lineHeight:"120%"})}let{paddingTop:i,paddingBottom:s,marginTop:r,lineHeight:n}=getComputedStyle(t),a=this.pane.isMain?r:"0";return"cards"!==this.pane.presenter.display.tooltip.mode?Number.parseFloat(a):[i,s,a,n].map(Number.parseFloat).reduce((e,t)=>e+t,0)+tz.CARDS_Y_OFFSET}getPadding(e){let t=this.pane.presenter,i=t.display,s=eG(i,null,"yAxis","minPaddingPercent"),r=eG(i,null,"yAxis","maxPaddingPercent"),n=eF(s),a=eF(r),o=n||a?0:this.getInitialPadding(),l=n?s:tz.PANE_CAP_MIN_PADDING_PERCENT,u=a?r:tz.PANE_CAP_MAX_PADDING_PERCENT,h=l*this.viewBox.height,c=[a?u*this.viewBox.height:Math.max(h,Math.min(u*this.viewBox.height,o)),h];e===eu.Max?c[0]=tz.PANE_TINY_PADDING_PIXELS:e===eu.Min&&(c[1]=tz.PANE_TINY_PADDING_PIXELS);let d=t.mainPlot;return d&&d.hasEvents&&(c[0]+=3*t.view.getEventRadius()),c}clearTicks(){this.ticks=null}getTicks(e,t=0){let{height:i}=this.viewBox,s=iF(e,1.3),r={height:i,approxLineHeight:s,domain:this.yScale.domain()};if(eF(this.ticks)&&eF(r.domain)&&eF(this.lastUsedOptions)&&eF(this.lastUsedOptions.domain)&&r.height===this.lastUsedOptions.height&&r.approxLineHeight===this.lastUsedOptions.approxLineHeight&&r.domain[0]===this.lastUsedOptions.domain[0]&&r.domain[1]===this.lastUsedOptions.domain[1])return this.ticks;this.lastUsedOptions=r;let n=Math.floor((i+40)/(s+40)),a=this.yScale.getTicks(n),o=eG(Sp().config,null,"overrides","yAxis","tickProvider");if(eF(o)&&"function"==typeof o&&r.height>0&&eF(r.domain)){let e=ez(r);e.autoTicks=ez(a),a=o(e)}let{innerTickSize:l,tickPadding:u,fontSize:h}=this.config,c=null,d=this.yScale?.checkTicks(),p=d?30:40;return this.ticks=a.map(i=>{let s=Math.round(this.yScale.priceToY(i)),r=Math.abs(s-(c??s));if(d&&null!==c&&r<p)return null;c=s;let n=h_(this,i),a=e.measureText(n).width,o={x1:0,x2:0,y1:s,y2:s,dy:0,label:n,labelX:0,labelY:s+.32*h};return this.onTheRight?(o.x1=t,o.x2=o.x1+l,o.labelX=o.x2+a+u):(o.x1=t-l,o.x2=o.x1+l,o.labelX=o.x1-u),o}).filter(e=>null!==e),this.ticks}widthNeeded(e){if(!eF(this.fullDomain))return tz.DEFAULT_PRICE_AXIS_WIDTH;e.save();let{fontWeight:t,fontSize:i}=this.config,{chart:{fontFamily:s}}=this.pane.presenter.display;e.font=`${t} ${i}px ${s}`;let r=t=>e.measureText(h_(this,t,!0)).width,n=Math.max(...this.fullDomain.map(r)),{innerTickSize:a,tickPadding:o}=this.config,l=eF(this.label)?iF(e,1.6):0;return e.restore(),n+a+2*o+l}draw(e){let{chart:{fontFamily:t},yAxis:{gridLines:i,textColor:s,visible:r}}=this.pane.presenter.display;if(!r||!this.viewBox)return;e.save();let{x:n,y:a,width:o,height:l}=this.viewBox,{fontWeight:u,fontSize:h}=this.config;if(iO(e,this.viewBox),e.font=`${u} ${h}px ${t}`,e.lineWidth=2,e.strokeStyle=i.color,e.textAlign="end",eF(this.label)){e.save(),e.fillStyle=iL(.4)(s),e.translate(0,0);let t=this.onTheRight?1:-1;e.rotate(t*Math.PI/2),e.textAlign="center";let i=iF(e),r=t*(a+l/2);this.onTheRight?e.fillText(this.label,r,-(n+o-i)):e.fillText(this.label,r,n+i),e.restore()}let c=this.onTheRight?n:o;e.setLineDash([]),iY(e,c,a,a+l);let d=this.getTicks(e,c);this.drawTicks(e,d,s),this.drawPriceAdornments(e),e.restore()}drawTicks(e,t,i){t&&(e.fillStyle=i,t.forEach(t=>{e.fillText(t.label,t.labelX,t.labelY+t.dy)}))}drawCrosshairIndicator(e,t){if(0===this.plots.length||!this.pane.presenter.display.yAxis.crosshair.enabled)return;let i=this.onTheRight?this.viewBox.x:this.viewBox.width,s=h_(this,this.yScale.yToPrice(t));this.crosshairIndicator.draw(e,i,t,s)}get indicatorHeight(){return this.config.fontSize+this.config.indicatorPadding+this.config.indicatorPadding}drawPriceAdornments(e){var t;let i=this.pane.presenter,{chart:{fontFamily:s,previous:r},yAxis:{showLastValue:n,preventLabelOverlap:a,includePercentChangeWithLastValue:o}}=i.display,l=i.view,u=[],h=(e,t,i,s,r,n)=>{if(null!=t){let a,l=t;t=e.priceMapper(t,n,r);let h=e.is(Z.Symbol)||e.is(Z.Expression);if(o&&h){let t=e.axis.comparison===q.Percent?q.None:q.Percent;a=e.priceMapper(l,n,r,t)}let c=e.hasDetachedScale?e.metaData.format(t,r):void 0,d=eF(a)?1:2;u.push({y:e.priceToY(t),formattedValue:c,value:t,auxValue:a,color:i,halfHeight:Math.round(this.indicatorHeight/d),priority:s})}};this.plots.forEach(e=>{if(e.timeSeries&&e.timeSeries.hasData){if("All"===n||"Main"===n&&e.main){let t=e.main?1:3;yt(e).filter(e=>null!=e.value&&-1!==e.index).forEach(i=>h(e,i.value,i.color,t,i.field,i.index))}e.showPrevious&&h(e,e.getPreviousValue(),r.color,2,ag.PreviousClose,void 0)}}),this.annotations.concat(this.plotAnnotations).forEach(e=>{u.push(...e.getPriceScaleAdornments().map(e=>({y:this.toY(e.price),value:this.priceMap(e.price),color:e.color,halfHeight:Math.round(this.indicatorHeight/2),priority:4})))}),u.sort((e,t)=>e.y-t.y),a&&(t=this.viewBox,u.forEach((e,i,s)=>{if(0===i&&e.y-e.halfHeight<t.y)e.y=t.y+e.halfHeight+1;else if(i>0){let r=s[i-1],n=(({y:e,halfHeight:t})=>e-t)(e),a=(({y:e,halfHeight:t})=>e+t)(r);n<a&&(e.y=a+1+e.halfHeight),(({y:e,halfHeight:t})=>e+t)(e)>t.y+t.height&&(e.y=t.y+t.height-e.halfHeight-1)}}));let c=({y:t,value:i,formattedValue:r,color:n,auxValue:a})=>{let o,{leftOffset:u,rightOffset:h}=l,c=this.onTheRight?this.pane.viewBox.width-h:u,d=iI(n),p=new g7({position:this.onTheRight?"right":"left",fontSize:this.config.fontSize,padding:this.config.indicatorPadding,fontFamily:s,textColor:d,strokeColor:n,backgroundColor:n}),f=r||h_(this,i),m=this.comparison===q.Percent;eH(a)&&(o=m?hL(this,a):hE(a)),p.draw(e,c,t,f,o)};a?u.forEach(c):ye.forEach(e=>u.filter(t=>t.priority===e).forEach(c))}}let ys=Symbol.for("__dloacip__");class yr{presenter;id;axes;height;alignedToYear;viewBox;constructor(e){this.presenter=e,this.axes=[],this.height=0,this.alignedToYear=null,this.id=e1()}fromModel(e){this.height=e.height,!0===e.alignOnExpirations&&(this.alignedToYear=function(e){let t=e.map(e=>e.plots).flat().filter(e=>Z[e.type]==Z.Symbol).map(e=>e.symbol).map(e=>tx(e)).filter(e=>null!==e).map(e=>e.getFullYear());return 0!=t.length?Math.max(...t):null}(e.axes)),this.axes=e.axes.map((e,t)=>{let i=new yi(this);return i.primary=0===t,i.fromModel(e),i},this)}getBounds(){return this.viewBox}setViewBox(e){this.viewBox=e}drawBackground(e){eF(this.viewBox)&&(this.drawAxes(e),e.save(),this.clipToNoScales(e),this.drawGrid(e),e.restore())}draw(e){eF(this.viewBox)&&(e.save(),this.clipToNoScales(e),this.drawPrevious(e),this.drawPlots(e),this.drawAnnotations(e),this.drawLogo(e),e.restore())}drawLogo(e){this.isMain&&!1!==this.presenter[ys]&&function(e,{x:t,y:i,height:s,width:r}){if(!eH(mZ))return;let{path:n,width:a,height:o,rect:l}=mZ,u=Math.min(Math.max(50,r/8),a)/a;l.width=a*u,l.height=o*u,l.x=t+5,l.y=i+s-l.height-5,e.save();let h=getComputedStyle(e.canvas).getPropertyValue("--widget-logo-fill-color");e.fillStyle=0===h.length?"rgba(127, 127, 127, 0.6)":h,e.translate(l.x,l.y),e.scale(u,u),e.fill(n),e.restore()}(e,this.getBoundsWithoutScales())}drawAxes(e){for(let t of this.axes)t.draw(e)}drawPrevious(e){let t=this.presenter.mainPlot;if(t.showPrevious&&this.isMain){let i=t.getPreviousValue();if(null!=(i=t.priceMapper(i,void 0,ag.PreviousClose))){let{leftOffset:s,rightOffset:r}=this.presenter.view,n=this.viewBox.width-r,a=t.axis.yScale.priceToY(i),{color:o,dashStyle:l,lineWidth:u}=this.presenter.display.chart.previous,h=iP(l);e.save(),e.strokeStyle=o,e.lineWidth=u,e.setLineDash(h),ij(e,a,s,n),e.restore()}}}getBoundsWithoutScales(){let e=this.viewBox.duplicate(),t=this.presenter.view;return e.x=t.leftOffset,e.width-=t.leftOffset+t.rightOffset,e}clipToNoScales(e){iO(e,this.getBoundsWithoutScales())}drawAnnotations(e){e.save();let{chart:{fontFamily:t},yAxis:{fontSize:i}}=this.presenter.display;e.font=`${i??12}px ${t}`;let s=t=>t.draw(e,!0);this.axes.forEach(e=>{e.annotations.forEach(s),e.plotAnnotations.forEach(s)}),e.restore()}drawGrid(e){let{chart:{fontFamily:t},yAxis:{gridLines:i,visible:s,minorGridLines:r}}=this.presenter.display;if(!s||!i.visible)return;let{lineWidth:n,color:a,dashStyle:o}=i;e.save();let l=this.axes[0].plots?.length===0&&this.axes.length>1,u=this.axes[+!!l],{fontWeight:h,fontSize:c}=u.config;e.font=`${h} ${c}px ${t}`;let d=u.getTicks(e),{leftOffset:p,rightOffset:f}=this.presenter.view,m=this.viewBox.width-f,g=(t,i,s)=>{e.lineWidth=t,e.strokeStyle=i,e.setLineDash(iP(s)),e.beginPath()};if(g(n,a,o),d.forEach(t=>{e.moveTo(p,t.y1),e.lineTo(m,t.y2)}),e.stroke(),r&&r.visible&&d.length>=2){let{lineWidth:t,color:i,dashStyle:s}=r,n=(d[0].y1-d[1].y1)/5;g(t,i,s),d.forEach(t=>{for(let i=1;i<5;i++){let s=Math.ceil(t.y1+i*n);e.moveTo(p,s),e.lineTo(m,s)}}),e.stroke()}e.restore()}drawYCrosshair(e,t){let{yAxis:{crosshair:{enabled:i,showValue:s,color:r,dashStyle:n}}}=this.presenter.display;if(!i)return;let a=iP(n);e.strokeStyle=r,e.setLineDash(a);let o=this.presenter.view.leftOffset,l=this.viewBox.width-this.presenter.view.rightOffset,u=iZ();u.prolog(e),ij(e,u.adjust(t.y),u.adjust(o),u.adjust(l)),u.epilog(e),s&&this.axes.forEach(i=>{i.drawCrosshairIndicator(e,t.y)})}drawNoData(e){e.save(),e.font=`800 14px ${this.presenter.display.chart.fontFamily}`,e.fillStyle="#f00",iU(e,Sp().config.noDataText||tz.NO_DATA_TEXT,{x:this.viewBox.centerX,y:this.viewBox.centerY},Q.Center),e.restore()}get isMain(){let e=this.presenter.mainPlot;return this.axes.some(t=>t.plots.includes(e))}drawPlots(e){e.save();let t=this.presenter.mainPlot,i=this.presenter.display.chart.showNoDataText,s=!eF(i)||i,r=new Map,n=!0,a=i=>{for(let e of this.axes){for(let s of e.plots){let e=s.isEmpty();n=n&&s.main&&e,s===t||e||i(s)}e.plots.includes(t)&&!t.isEmpty()&&i(t)}s&&n&&this.drawNoData(e)};a(t=>t.draw(e)),a(t=>t.drawTopmost(e,r)),e.restore()}}function yn(e,t){return{width:e,spacing:t,get totalWidth(){return this.width+this.spacing},offset:0}}class ya extends f5{timeline;aggregation;marginBars;bar;resetBar;wasZoomed;fitAllData;constructor(e,t){super(),this.timeline=e,this.aggregation=t;let i=e.presenter.display;this.marginBars=i.xAxis.marginBars||0,this.bar=yn(eG(i,tz.DEFAULT_BAR_WIDTH,"chart","bar","width"),eG(i,tz.DEFAULT_BAR_SPACING,"chart","bar","spacing")),this._extent=null,this.wasZoomed=!1,this.fitAllData=!1}extent(e){return f4.call(this,"_extent",e)}get presenter(){return this.timeline.presenter}get display(){return this.presenter.display}scaleBarToFit(){if(this.wasZoomed)return;if(this.fitAllData)return this._domain=null,this.scaleBarToFitDensity(this.timeline.withoutPrologEpilogLength);let e=this.display.xAxis.visibleRange;if(eF(e))return this.scaleBarToFitRange([e.from,e.to]);let t=this.display.density;if(Number.isFinite(t))return this.scaleBarToFitDensity(t);let i=this.display.period;if(Number.isFinite(i))return this.scaleBarToFitPeriod(i)}deriveExtentsFromBarWidth(e){if(!eF(this._range)||0===this.timeline.length)return null;let t=this._range[1]-this._range[0],i=Math.ceil(t/e.totalWidth);e.offset=t-i*e.totalWidth;let s=this.timeline.lastSeriesIndex+this.marginBars,r=this._domain&&this._domain[1];return r&&(s=e_(this.timeline,+r,Number,hw)),[s-i+1,s]}adjustDomain(){if(!eF(this._range))return;this.scaleBarToFit();let e=this.deriveExtentsFromBarWidth(this.bar);eF(e)&&(this.extent(e),this.setDomainFromExtent())}xToTime(e){if(!this.ready)return null;let t=Math.floor((e-this._range[0]-this.bar.offset)/this.bar.totalWidth),i=this._extent[0]+t;return this.timeline.at(i)}timeToIndex(e){return this.ready?(e="number"==typeof e?e:+e,e_(this.timeline,e,Number,hw)):null}indexToX(e){let t=e-this._extent[0];return this.bar.width/2+this.range()[0]+this.bar.offset+t*this.bar.totalWidth}timeToX(e){if(!this.ready)return null;let t=this.timeToIndex(e);return this.indexToX(t)}zoom(e){let t=e*this.bar.width/100,i=this.bar.width-t,s=this.bar.spacing-e*this.bar.spacing/100;if(i>tz.MAXIMUM_BAR_WIDTH||i<tz.MINIMUM_BAR_WIDTH)return!1;let r=yn(i,s),n=this.deriveExtentsFromBarWidth(r);return!!this.isUsableExtent(n)&&(this.setBar(i,s),this.adjustDomain(),this.wasZoomed=!0,!0)}scaleBarToFitRange(e,t=!0){let i=(e,t,i,s)=>eF(e)?e_(this.timeline,e,Number,hw,i,s):t,{from:s,to:r}=this.presenter.data.range||{},n=+e[0]===s&&+e[1]===r,{firstSeriesIndex:a,lastSeriesIndex:o}=this.timeline,l=n?a:void 0,u=n?o:void 0,h=[i(e[0],a,l,u),i(e[1],o,l,u)];this.timeline.at(h[1])>e[1]&&(h[1]=Math.max(0,h[1]-1)),this.extent(h),this.scaleBarToFitDensity(h[1]-h[0]+1,t)}scaleBarToFitDensity(e,t=!0){let i=Math.max(tz.MINIMUM_BARS_VISIBLE,e),s=t&&this.display.xAxis.marginBars||0,r=(this._range[1]-this._range[0])/(i+s);this.setBar(2/3*r,1/3*r,!1)}scaleBarToFitPeriod(e){let t=this.timeline.lastSeriesIndex,i=this.timeline.at(t),s=i,r=t,n=this.presenter.data.aggregation;if(n.isEndOfDay||n.isIntraday&&e>=tz.INTRA_THRESHOLD)for(;r>0&&uL(i,s)<e;)r--,s=this.timeline.at(r);else if(!n.isTick){let t=Math.floor(e/tz.ONE_DAY_MILLIS),s=e=>gx(e,tl(e)),n=s(i),a=i;for(;r>0;){let e=this.timeline.at(r),i=nS(e,a);if(0===t){if(s(e)<=n||!i)break}else i||(t--,a=e);r--}}this.scaleBarToFitDensity(t-r+1)}setBar(e,t,i=!0){let[s,r]=e0(e,t,tz.MINIMUM_BAR_WIDTH,tz.MAXIMUM_BAR_WIDTH);this.bar.width=s,this.bar.spacing=r,this.wasZoomed||(this.resetBar={width:s,spacing:r}),i&&(this.presenter.model.display.chart.bar={width:e,spacing:t})}resetZoom(){eF(this.resetBar)?(this.bar.width=this.resetBar.width,this.bar.spacing=this.resetBar.spacing):(this.bar.width=tz.DEFAULT_BAR_WIDTH,this.bar.spacing=tz.DEFAULT_BAR_SPACING),delete this.presenter.model.display.chart.bar,this.adjustDomain()}isUsableExtent(e){return eF(e)&&eF(e[0],e[1])&&e[0]>=0&&e[1]<this.timeline.withPrologEpilogLength&&e[1]-e[0]>=tz.MINIMUM_BARS_VISIBLE}shiftBars(e,t=null){if(!this._extent)return;let i=this._extent.map(t=>t+e);this.isUsableExtent(i)&&(eF(t)&&(this.bar.offset=t),this.extent(i),this.setDomainFromExtent())}setDomainFromExtent(){this.domain(this.extent().map(e=>this.timeline.at(e)))}pan(e){if(!Number.isFinite(e)||0===e)return;let t=e%this.bar.totalWidth,i=this.bar.offset+t,s=Math.sign(e),r=-(e<0?Math.ceil:Math.floor)(e/this.bar.totalWidth);(i>this.bar.totalWidth||i<-this.bar.totalWidth)&&(r+=i>0?-1:1,i-=s*this.bar.totalWidth),this.shiftBars(r,i)}getSeriesThatCouldLoadMoreData(){let e=this.domain();if(!eF(e)||!eF(e[0]))return[];let t=e[0].getTime();return this.timeline.presenter.allPlots.map(e=>e.timeSeries).filter(e=>!!eF(e)&&!!e.hasData&&0!==e.container.size&&!0===e.canLoadMoreData&&t<=e.container.getTimeData()[0].getTime())}}function yo(e){return{date:e,priority:1,text:hb(e)}}class yl{view;xScale;ticks;lastUsedOptions;wasPanned;panningXAxisAllowed;config;isVisible;crosshairIndicator;viewBox;overrideTickGetter;overrideFormatter;constructor(e){this.view=e,this.xScale=new ya(e.presenter.timeline,e.presenter.data.aggregation),this.ticks=null,this.lastUsedOptions=null,this.wasPanned=!1,this.panningXAxisAllowed=eG(e.presenter.display,!0,"xAxis","panning"),this.updateConfigFromModel();let t=e.presenter.renderTo.id,i=eG(Sp().config,null,"overrides","xAxis","tickProvider");eF(i)&&"function"==typeof i&&(this.overrideTickGetter=eh(i,t));let s=eG(Sp().config,null,"overrides","xAxis","formatter");eF(s)&&"function"==typeof s&&(this.overrideFormatter=eh(s,t))}updateConfigFromModel(){let{chart:{fontFamily:e,backgroundColor:t,fontSize:i},xAxis:{textColor:s,visible:r,fontSize:n,crosshair:{color:a}}}=this.view.presenter.display;this.config={innerTickSize:5,tickPadding:5,indicatorPadding:5,fontWeight:400,fontSize:n||i||12},this.isVisible=r,this.crosshairIndicator=new g7({position:"bottom",fontSize:this.config.fontSize,fontFamily:e,padding:this.config.indicatorPadding,strokeColor:a,textColor:s,backgroundColor:i_(.15)(t),arrowLength:this.config.innerTickSize})}setDomain(){this.xScale.adjustDomain();let e=this.view.presenter.display.period===tz.FIFTY_YEARS_MILLIS;eF(this.xScale.extent())&&!e&&this.checkForMoreData()}zoom(e){let t=this.xScale.zoom(e);return this.checkForMoreData(),t}checkForMoreData(){this.xScale.getSeriesThatCouldLoadMoreData().forEach(e=>e.loadMoreData())}shouldScrollIntoView(e){let t=this.xScale.extent();return!!eF(t)&&e-this.xScale.timeline.lastSeriesIndex>=0&&e-t[1]<=1}pan(e){this.panningXAxisAllowed&&(this.xScale.pan(e),this.checkForMoreData(),this.view.setPriceAxesDomains(),this.wasPanned=!0)}get wasVisibleRangeChanged(){return this.wasPanned||this.xScale.wasZoomed}resetZoom(){this.xScale.resetZoom()}get barsToLast(){let e=this.xScale.timeline.lastSeriesIndex+this.getMaxCurveOffset(),t=this.xScale.extent(),i=t?t[1]:e;return e-i}canGoToLast(){return this.barsToLast>0}getMaxCurveOffset(){return Math.max(...this.view.presenter.allCurves.map(e=>e.shift))}goToLatest(e=!1){if(this.canGoToLast()||e){let e=0!==this.barsToLast?this.barsToLast+this.xScale.marginBars+1:0;this.xScale.shiftBars(e),this.view.setPriceAxesDomains(),this.view.redraw()}}setViewBox(e){this.viewBox=e;let{x:t,width:i}=this.viewBox;this.xScale.range([t,t+i])}heightNeeded(e){if(!this.isVisible)return 0;let t=this.view.presenter.display.chart.fontFamily,{fontWeight:i,fontSize:s}=this.config;e.save(),e.font=`${i} ${s}px ${t}`;let{innerTickSize:r,tickPadding:n,indicatorPadding:a}=this.config,o=iF(e,1)+r+n+a;return e.restore(),o}getTickGetter(e){if(this.overrideTickGetter)return this.overrideTickGetter;let t=this.view.presenter.display.xAxis.isOrdinal||!1,i=function(e){switch(e.agg.unit){case G.Tick:return new hS(e);case G.Intraday:return new hA(e,e.agg.size);case G.Day:return new hT(e);case G.Week:return new hv(e);case G.Month:case G.Quarter:return new hP(e);case G.Year:return new hC(e);default:throw Error(`Aggregation unit ${G[e.agg.unit]} not supported.`)}}(e);return t?yo:e=>i.getTick(e)}getTicks(e){let t,i;if(eF(this.lastUsedOptions)&&(t=e.agg,i=this.lastUsedOptions.agg,t.unit===i.unit&&t.size===i.size&&t.spec===i.spec)&&e.unitWidth===this.lastUsedOptions.unitWidth&&e.barWidth===this.lastUsedOptions.barWidth&&e.extent[0]===this.lastUsedOptions.extent[0]&&e.extent[1]===this.lastUsedOptions.extent[1]&&e.formatString===this.lastUsedOptions.formatString&&e.minTickInterval===this.lastUsedOptions.minTickInterval&&eF(this.ticks))return this.ticks;this.lastUsedOptions=e;let s=this.getTickGetter(e),r=Math.max(0,e.extent[0]),n=Math.min(this.xScale.timeline.withPrologEpilogLength-1,e.extent[1]+1);return this.ticks=this.view.presenter.timeline.slice(r,n).map((e,t)=>{if(!eF(e)||Number.isNaN(e.getTime()))return null;let i=s(e);return eF(i)&&(i.index=r+t),i}).filter(e=>eF(e)),this.ticks}normalizeDuration(e){let t=function(){let e=Object.keys(hh);return 1===hh.Day.Multipliers[0]&&e.forEach(e=>{let t=hh[e],i=eQ(t.Period);t.One=+i,t.Multipliers=t.Multipliers.map(e=>e*i)}),hh}(),i=t.Year,s=Object.keys(t);for(let r=0;r<s.length-1;++r){let n=t[s[r]].Multipliers,a=t[s[r+1]].Multipliers;if(e<=(eC(n)+eb(a))/2){i=t[s[r]];break}}let r=i.Multipliers,n=r.findIndex(t=>e<t),a=-1===n?eC(r):r[n];return"P1M"===i.Period?a*=.9:"P1W"===i.Period&&(a*=.84),a}draw(e){if(!this.isVisible)return;let{xAxis:{gridLines:t,textColor:i,minTickInterval:s,tickPixelInterval:r,format:n,forceTicksVisible:a},chart:{fontFamily:o}}=this.view.presenter.display,{fontWeight:l,fontSize:u,innerTickSize:h,tickPadding:c}=this.config,{x:d,y:p,width:f}=this.viewBox,{lineWidth:m,color:g,dashStyle:y}=t,S=iP(y);e.textAlign="center",e.font=`${l} ${u}px ${o}`,e.lineWidth=1,e.strokeStyle=g,e.fillStyle=i,e.setLineDash([]),ij(e,p,d,d+f);let A=this.xScale.extent(),T=e=>!eF(e)||!eF(e[0],e[1]);if(T(A))return;let v=t=>e.measureText(t).width,P=r>0?r:120,C=this.xScale.domain();if(T(C))return;let b=(C[1].getTime()-C[0].getTime())*P*.6/f,E=this.normalizeDuration(b),L=this.view.presenter.data.aggregation.isEndOfDay,_=d+f,M=({text:i,x:s,date:r,forced:n})=>{eF(r)&&(n||iY(e,s,p,p+h),e.fillText(i,s,p+h+c+.71*u),t.visible&&!n&&(e.save(),e.lineWidth=m,e.setLineDash(S),iY(e,s,0,p),e.restore()))},x={agg:this.view.presenter.data.aggregation,unitWidth:v("M"),barWidth:this.xScale.bar.width,extent:A,formatString:n,minTickInterval:s||0,duration:b},I=this.getTicks(x),D={date:tz.ZERO_DATE,priority:999,x:-999,text:"",index:-1,textWidth:0};I.forEach(e=>{e.x=this.xScale.indexToX(e.index),e.textWidth=v(e.text);let{x:t,textWidth:i}=e,r=t;if(a){let s=i/2;e.x=r=(r=t-s<d?d+s:t)+s>_?_-s:r,e.forced=t!==r}else e.forced=!1;((e,t)=>{let i,r;if(e.date.valueOf()===tz.ZERO_DATE.valueOf())return!0;if(i=e.date,r=t.date,(eF(i)?uL(r,i):tz.FIFTY_YEARS_MILLIS)<s)return!1;let n=t.x-e.x,a=t.date.getTime()-e.date.getTime();return!(e.x+e.textWidth/2>=t.x-t.textWidth/2)&&(n>P||!!L&&a>=E)})(D,e)?(M(D),D=e):e.priority<D.priority&&(D=e)}),M(D),this.drawTimeTransitions(e),this.drawTimeAdornments(e)}drawTransitionsFor(e,t,i,s){let r=this.xScale.domain(),n=this.view.presenter?.mainPlot?.timeSeries.container;if(!eH(n))return;let a=n.getTimeData(),o=null===t?a:n.getData(t);if(!eF(o))return;let l=e_(a,+r[0],Number),u=e_(a,+r[1],Number,eL,l);if(l<u){s.save();let t=iZ();t.prolog(s),s.strokeStyle=e.color,s.lineWidth=e.width,s.setLineDash(iP(e.dashStyle));let r=null;for(let e=l;e<u;++e){let t=o[e];if(i(t,r)){let i=a[e],n=this.xScale.timeToX(i);eF(n,r)&&iY(s,n,0,this.viewBox.y),r=t}}t.epilog(s),s.restore()}}drawTimeTransitions(e){let t=this.xScale.domain();if(!eH(t)||!eF(t[0],t[1]))return;let i=this.view.presenter,{xAxis:{contractTransition:s,cycleTransition:r}}=i.display,n=(e,t)=>e!==t;s.enabled&&i?.data?.aggregation.isMultiContract&&this.drawTransitionsFor(s,ag.Symbol,n,e),r.enabled&&(i?.data?.aggregation.isIntraday?this.drawTransitionsFor(r,ag.TradingDay,n,e):i?.data?.aggregation.unit===G.Day?this.drawTransitionsFor(r,null,(e,t)=>!nA(e,t),e):i?.data?.aggregation.unit===G.Week&&this.drawTransitionsFor(r,null,(e,t)=>!nE(e,t),e))}getAnnXScore(e,t){return[nS,nb,nA,nE].map((i,s)=>(4-s)*Number(i(e,t))).reduce((e,t)=>e+t,0)}annTimeToX(e){let t=this.xScale.timeToIndex(e);if(!eH(t))return null;let i=this.xScale.timeline.at(t),s=this.xScale.timeToX(e);if(!(t>0)||i.valueOf()===e.valueOf())return s;{let r=t-1,n=this.xScale.timeline.at(r),a=this.xScale.indexToX(r);if(!this.view.presenter.display?.xAxis?.isOrdinal){if(n.valueOf()>e.valueOf())return s;let t=this.getAnnXScore(n,e),r=this.getAnnXScore(i,e);return t>r?a:r>t?s:this.view.presenter?.data?.aggregation?.isIntraday?a:s}return a+(s-a)*((e.valueOf()-n.valueOf())/(i.valueOf()-n.valueOf()))}}drawTimeAdornments(e){e.save();let t=this.view.presenter,{chart:{fontFamily:i},xAxis:{preventLabelOverlap:s}}=t.display,r=[],n=t.mainPane?.getBoundsWithoutScales()??new iw(0,0,0,0);t.allAnnotations.concat(t.plotAnnotations).forEach(i=>{r.push(...i.getTimeScaleAdornments().map(i=>{let s=this.annTimeToX(i.time);if(s<n.x||s>n.x+n.width)return null;let r=hM(t,this.view.presenter?.display?.xAxis?.isOrdinal?i.time:this.xScale.xToTime(s)),a=e.measureText(r).width/2;return{x:s,value:r,color:i.color,halfWidth:a}}).filter(e=>null!=e))}),r.sort((e,t)=>e.x-t.x),s&&function(e,t){let i=e.length-1;e.forEach((e,s,r)=>{let n=0===s,a=n?null:r[s-1],o=(({x:e,halfWidth:t})=>e-t-4)(e),l=n?t.x:(({x:e,halfWidth:t})=>e+t+4)(a);if(e.x-e.halfWidth<t.x&&(e.x=g9(t.x,e.halfWidth)),o<l)e.x=g9(l,e.halfWidth+4);else{let t=(({x:e,halfWidth:t})=>e+t+4)(e),n=s<i?(({x:e,halfWidth:t})=>e-t-4)(r[s+1]):Number.MAX_SAFE_INTEGER;if(t>n){let i=g8(e.x,t-n),s=g8(e.x,e.halfWidth-2);e.x=Math.max(s,i,g9(l,a?.halfWidth??0))}}(({x:e,halfWidth:t})=>e+t+4)(e)>t.x+t.width&&(e.x=g8(t.x+t.width,e.halfWidth))})}(r,this.viewBox),r.forEach(t=>{let s=iI(t.color);new g7({position:"bottom",fontSize:this.config.fontSize,fontFamily:i,padding:this.config.indicatorPadding,strokeColor:tz.COLOR_TRANSPARENT,textColor:s,backgroundColor:t.color,arrowLength:this.config.innerTickSize}).draw(e,t.x,this.viewBox.y+1,t.value)}),e.restore()}drawCrosshair(e,{x:t}){let i=this.view.presenter,s=i.display.xAxis,{enabled:r,showValue:n,color:a,dashStyle:o,format:l}=s.crosshair,u=this.xScale.xToTime(t);if(!(eF(u)&&oC(u)))return!1;if(!r)return!0;t=this.xScale.timeToX(u);let h=iP(o);e.strokeStyle=a,e.setLineDash(h);let c=iZ();if(c.prolog(e),iY(e,c.adjust(t),0,c.adjust(this.viewBox.y)),c.epilog(e),!n||!s.visible)return!0;let d=hM(i,u,eF(s.format)?l:void 0);this.crosshairIndicator.draw(e,t,this.viewBox.y+1,d,void 0,this.viewBox.height-2);let{plotHover:p}=i.display.chart;return p&&i.allPlots.filter(e=>e.visible).forEach(i=>i.curves.forEach(i=>i.drawHover(e,u,t))),!0}}let yu={mousedown:"onMouseDown",mousemove:"onMouseMove",mouseup:"onMouseUp",dblclick:"onMouseDblClick",contextmenu:"onContextMenu",mouseover:"onMouseEnter",mouseout:"onMouseLeave",wheel:"onWheel",touchstart:"onMouseDown",touchmove:"onMouseMove",touchend:"onMouseUp",keydown:"onKeyDown"},yh={Shift:"shiftKey",Alt:"altKey",Control:"ctrlKey",Meta:"metaKey"};class yc{view;subscriptions;constructor(e){this.view=e,this.subscriptions=[]}init(e){let t=eO();Object.keys(yu).filter(e=>!e.startsWith("touch")||t).forEach(t=>{let i=e=>{let i=yu[t];!0===this.notifyActiveTool(i,e)&&e.preventDefault()};e.addEventListener(t,i),this.subscriptions.push(()=>{e.removeEventListener(t,i)})})}shutdown(){this.subscriptions.forEach(e=>e()),this.subscriptions=[]}notifyActiveTool(e,t){let i=this.view.presenter;if(void 0===i||null===i.activeTool)return!1;let s=this.getPayload(t,i),r=i.activeTool,n=!1;return"function"==typeof r[e]&&(n=r[e](s)||!1),n}getPayload(e,t){let i=e instanceof MouseEvent,s=eO()&&e instanceof TouchEvent;if(i||s){let r={x:0,y:0};if(s&&1===e.touches.length){let t=e.touches[0],{left:i,top:s}=e.target.getBoundingClientRect();r.x=t.clientX-i,r.y=t.clientY-s}else i&&(r.x=e.offsetX,r.y=e.offsetY);let n={button:i?e.which:et.Left,offset:r,view:t.view,presenter:t,originalEvent:e,getModifier:t=>e[yh[ei[t]]]};if(e instanceof WheelEvent&&(n.delta=e.shiftKey?e.deltaX:e.deltaY),s&&2===e.touches.length){let t=e.touches[0],i=e.touches[1];n.pinchZoom=!0;let s=t.clientX-i.clientX,r=t.clientY-i.clientY;n.pinchDistance=Math.sqrt(s*s+r*r)}return this.view.splitters.forEach((e,t)=>{e.contains(r)&&(n.splitter=[t,t+1])}),t.panes.forEach(e=>{let t=e.getBounds();if(eF(t)&&t.contains(r)){let t=e.axes.find(e=>e.viewBox?.contains(r));t?n.priceAxis=t:n.point=e.axes.find(e=>e.primary).toAnnotationPoint(r)}}),n}if(e instanceof KeyboardEvent)return{key:e.key??e.keyIdentifier,code:e.keyCode||e.charCode,repeat:e.repeat,presenter:t,getModifier:t=>e.getModifierState(ei[t])}}}let yd=uf.concat(ag.PercentChange);class yp{view;id;isOptionsChart;constructor(e){this.view=e,this.isOptionsChart=!1,this.id=`bc-legend-${e1()}`}getLegendElem(){let e=this.view.el;return tH(this.id,e,"div")}update(){let e=this.getLegendElem(),t=hj(this.presenter.mainPane);if(!eF(t))return;this.isOptionsChart=this.mainPlot.title.startsWith(tz.FAKE_SYMBOL_PREFIX);let{left:i,right:s,top:r,width:n}=t;mY(e,"row",i,s,r,n),tF(e,{"bcharts-card":!0,"bcharts-legend":!0});let a=this.mainPlot,o=a.isSeasonal||this.isOptionsChart?this.getFirstColorBadge(a):"",l=this.getPlotTitle(a),u=this.maybeGetQuote(),h=this.div(`${o} ${l} `)+this.div(`${u}`),c=this.maybeGetAdditionalPlots();e.innerHTML=`${h} ${c}`}remove(){this.getLegendElem().remove()}get presenter(){return this.view.presenter}get mainPlot(){return this.presenter.mainPlot}getAttributes(e){return Object.entries(e).map(([e,t])=>{if(null===t)return"";let i=Array.isArray(t)?t.join(" "):t;return`${e} = "${i}" `}).join(" ")}span(e,t={}){return`<span ${this.getAttributes(t)}>${e}</span>`}div(e){return`<div class="plot" style="flex: 0 0 auto">${e}</div>`}get meta(){return this.mainPlot.metaData}isSingleSymbolSeasonal(e){return e.isSeasonal&&!e.hasComputation}format(e,t,i){return(i??this.meta).format(e,t)}spanAsName(e){return this.span(e,{class:"field-name"})}spanAsValue(e,t=null,i=null){return this.span(e,{class:["field-value",t],style:i})}getQuoteFromRecord(e){let t=yd.map(t=>e.getValue(t));if(ey(t)){let e=t[4],i=`field-${e>0?"up":e<0?"down":"same"}-value`,s=t.slice(0,-1).map((e,t)=>{let s=yd[t],r=this.format(e,s),n=hX(s);return`${this.spanAsName(n)}${this.spanAsValue(r,i)}`}).join(" "),r=this.spanAsValue(`(${this.format(eC(t),eC(yd))})`,i);return`${s} ${r}`}return""}maybeGetQuote(){if(this.mainPlot.isSymbol&&this.mainPlot.timeSeries?.record?.isValid){let e=Sp().getRecordSource().getRecord(this.mainPlot.timeSeries.record.symbol);return this.getQuoteFromRecord(e)}if(this.mainPlot.isExpression&&this.mainPlot.record.isValid){let e=this.mainPlot.record;return e.evaluate(),this.getQuoteFromRecord(e)}return""}getTitle(e,t,i){let s=this.span(`${e.name} (${e.symbol})`,{"data-plot-id":i,class:["value-title",t?"value-main":null]}),r=t?` ${this.span(e.exchange,{class:"value-subtitle"})}`:"";return`${s}${r}`}getPlotTitle(e){if(e.isSymbol)return this.getTitle(e.metaData,e.main,e.id);if(!(this.isSingleSymbolSeasonal(e)&&0===e.offset&&(e.symbols?.length??0)>0))return this.span(e.title,{"data-plot-id":e.id,class:"value-title"});{let t=Sp().getMetaDataSource().getMetaData(e.getActualSymbols()[0]);return this.getTitle(t,!0,e.id)}}getFirstColorBadge(e){return hk("rectangle",e.mainCurve.colors[0])}getLastValues(e){return this.isOptionsChart?"":yt(e).filter(e=>eF(e.value)).map(t=>{let i=this.format(t.value,t.field,e.metaData);return this.spanAsValue(i,null,`color:${t.color}`)}).join(" ")}canBeDeleted(e){return e.isStudy||!e.main&&this.isOptionsChart}maybeGetAdditionalPlots(){let e=this.presenter.mainPane.axes.map(e=>e.plots).flat().filter((e,t)=>!e.main||e.isSeasonal&&t>0),t=this.presenter.display.yAxis.showLastValue;return e.length>0?e.map(e=>{let i=this.getFirstColorBadge(e),s=this.getPlotTitle(e),r=this.canBeDeleted(e)?hz(e.id):"",n="All"===t||e.isSeasonal?"":this.getLastValues(e);return this.div(`${r} ${i} ${s} ${n}`)}).join(" "):""}}class yf{presenter;splitters=[];canvasContainer=null;mouseCanvas=null;mainCanvas=null;mouseContext;mainContext;leftOffset=0;rightOffset=0;legend;notifyLayoutChanged;el=null;listeners=[];tooltip;width;height;customEventPopup=null;goToLatestButton=null;xAxis;eventCapture;resetZoomAndVisibleRange=!1;constructor(){this.legend=new yp(this),this.draw=this.draw.bind(this),this.notifyLayoutChanged=function(e,t=100){var i,s;let r;return i=t=>eN(e,t),s=t,r=!1,function(...e){r||(i.apply(this,e),r=!0,setTimeout(function(){r=!1},s))}}(ay.CH_CHTLAYOUTCHANGED,tz.LAYOUT_THROTTLE_DELAY)}get canShowLegend(){if(!this.presenter.hasLegend)return!1;let e=this.presenter.display.chart.showLegend;return"boolean"!=typeof e||!!e}updateLegend(){this.canShowLegend&&this.legend.update()}removeLegend(){this.legend.remove()}findSvgParentWithClass(e,t){return[e,e.parentElement,e.parentElement.parentElement].find(e=>eF(e)&&e.className===t)}onNonToolHandledMouseDown(e){let t=this.presenter,i=e.target;if("string"==typeof i.className&&i.className.split(" ").includes("value-title"))t.onCardClicked(i);else{let s=this.findSvgParentWithClass(i,"move-pane");if(eH(s))return void t.onMovePaneClicked(s);let r=this.findSvgParentWithClass(i,"delete-plot");if(eH(r))return void t.deletePlotClicked(r);let n=this.findSvgParentWithClass(i,"show-hide-plot");if(eH(n))return void t.showHidePlotClicked(n);let a=this.findSvgParentWithClass(i,"more-actions");if(eH(a))return void t.plotMoreActionsClicked(a,e)}}initialize(e){this.presenter=e,this.el=this.presenter.hostElement;let t=new ResizeObserver(e=>{for(let t of e){let{width:e,height:i}=t.contentRect;this.setSize(e,i),eF(this.tooltip)&&this.tooltip.repositionAuto()}});t.observe(this.el.parentElement),this.listeners.push(()=>t.unobserve(this.el.parentElement));let i=e=>this.onNonToolHandledMouseDown(e);this.el.addEventListener("mousedown",i),this.listeners.push(()=>this.el.removeEventListener("mousedown",i)),tN(this.el,{flex:1,display:"flex",position:"relative","flex-direction":"column","touch-action":"pan-x pan-y"}),this.tooltip=new m$(this);let s=Sp().config.getCustomEventPopup;this.customEventPopup=s?s(this):null;let{clientHeight:r,clientWidth:n}=this.el;this.width=n,this.height=r,this.canvasContainer=tB(this.el,"div"),tV(this.canvasContainer,{class:"chart-canvas-container"}),tN(this.canvasContainer,{flex:1,display:"flex","flex-direction":"column",position:"relative",height:"100%"}),this.mainCanvas=tB(this.canvasContainer,"canvas");let a={height:`${r}px`,width:`${n}px`,"z-index":2,position:"absolute",top:0,left:0};tN(this.mainCanvas,a),this.mouseCanvas=tB(this.canvasContainer,"canvas"),tV(this.mouseCanvas,{tabIndex:0}),a["z-index"]=3,a.outline="none",tN(this.mouseCanvas,a),this.goToLatestButton=tB(this.el,"button"),tW(this.goToLatestButton,`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
18
+ `.trim()})(t,a,f,r,l,u,h,e)),y=`${m}${g.join("")}`,S=function(e,t){let i=e>0,s=e<t-1;return`${i?hW(!0,e):""} ${s?hW(!1,e):""}`.trim()}(d,t.length);return{id:`bc-tip-${c.id.substring(0,8)}`,isMainPane:f,content:y,moveContent:S,bounds:c.bounds}})}(e,t,i,s,r,a,o,l);c.some(e=>!eF(e.bounds))||c.forEach(({id:t,isMainPane:i,content:s,moveContent:r,bounds:{left:a,right:o,top:l,width:c}},d)=>{if(""!==s&&(!n||!i)){let r=tH(t,h,"div");mY(r,i&&hV(e)?"column":"row",a,o,l+u,c),tF(r,{"bcharts-card":!0,"bcharts-card-main":i,"bcharts-card-first":0===d}),r.innerHTML=s}let p=tR(`#right-${t}`,h);eF(p)||((p=document.createElement("div")).id=`right-${t}`,h.appendChild(p),tF(p,"bcharts-card bcharts-card-move")),tN(p,{position:"absolute",display:"block",right:`${o+tz.CARDS_X_OFFSET}px`,top:`${l+u+tz.CARDS_Y_OFFSET}px`}),p.innerHTML=r})}let mK=null;function mq(){return null===mK&&(mK=Sp().config.hostingModel===eo[eo.Application]),mK}class mX extends mh{ap;presenter;panY;snapToSupported;warmUp;preventDefault;lastOffset;lastPanningExtremes;constructor(e){super(),this.ap=e,this.snapToSupported=!1,this.warmUp=!0,this.preventDefault=!1,this.presenter=e.presenter,this.panY=e.axis.isCustomDomain}activated(){}deactivated(){this.cancelLongPress()}startPan(e){this.startLongPress(this.presenter,this.ap,e),this.lastOffset=e,this.lastPanningExtremes=this.ap.axis.yScale.domain();let t=this.ap.presenter;t.enableTooltip(!1),t.view.tooltip.hide(),t.view.drawCrosshair({ap:void 0})}onMouseMove(e){if(e.pinchZoom)return void this.presenter.resetActiveTool();let{point:t,view:i,offset:s}=e;if(t&&t.axis!==this.ap.axis)return;let{x:r,y:n}=s,a=r-this.lastOffset.x,o=Math.abs(a),l=this.lastOffset.y,u=Math.abs(n-l);o>=1&&this.cancelLongPress();let h=mq();if(eO()&&!h&&this.warmUp)return(o>7||u>7)&&(this.warmUp=!1,this.preventDefault=o>u),!1;if(this.preventDefault||!eO()||h){if(i.xAxis.pan(a),this.panY&&t&&t.axis){u>=1&&this.cancelLongPress();let e=function(e,t,i,s){let r=(i-t)/e.viewBox.height,[n,a]=s,o=r*(a-n);return[n+o,a+o]}(t.axis,l,n,this.lastPanningExtremes);this.lastPanningExtremes=e,t.axis.yScale.domain(e)}this.lastOffset=s,i.redraw(),t&&t.presenter.view.setCursor(ee.Grabbing)}return h||this.preventDefault}finished(){gK(this.presenter)}onMouseLeave(){this.finished()}onMouseUp(){this.finished()}onMouseDblClick({presenter:e,offset:t,originalEvent:i}){eO()&&m3(e,t,i)}performLongPress(e,t,i){e.enableTooltip(!0),e.resetActiveTool(),e.activeTool.startTouchCrosshairMode(e,t,i)}}let mZ=null;class mJ extends mx{constructor(e,t){super(e,t)}hitTest(e){if(!this.visible)return!1;let t=this.getRect();return null!==t&&t.contains(e)}draw(e,t){return!!super.draw(e,t)&&(i$(e,this.getRect()),!0)}}function mQ(e,t){return e<t?[e,t]:[t,e]}let m0={line:{width:1,color:"rgba(127, 127, 127, 0.3)",dashStyle:"LongDash"},fill:{color:"rgba(127, 127, 127, 0.1)"}};class m1 extends mR{snapToSupported=!1;preventDefault=!1;axis;presenter;constructor(){super(mT("Rectangle",mJ,null,m0),!1)}activated(){}deactivated(){eF(this.axis,this.annotation)&&this.axis.deleteAnnotation(this.annotation,!1)}onMouseDown(e){let t=super.onMouseDown(e);if(!0===t){let{point:t}=e;this.axis=t.axis,this.presenter=t.presenter}return t}finish(){if(eF(this.axis,this.presenter)){gK(this.presenter,{toolChange:el.Executed,annId:"ZoomIn"});let e=this.annotation.points,t=mQ(e[0].price,e[1].price),i=mQ(e[0].time,e[1].time),s=(e,t)=>Math.abs(t(e[0])-t(e[1])),r=s(i,e=>this.axis.toX(e)),n=s(t,e=>this.axis.toY(e)),a=this.presenter.view,o=tz.MINIMUM_ZOOM_DIMENSION;if(r>o&&n>o){let e=a.xAxis.xScale;this.axis.isCustomDomain=!0,this.axis.yScale.domain(t),e.wasZoomed=!0,e.scaleBarToFitRange(i,!1),e.domain(i)}a.redraw()}}}function m2(e,t){let i=mS(e);i.offset={x:t.x,y:t.y},i.canFlip=null!==e.getFlipAnchorIndices();let s=e.axis.pane.presenter;s.clearSelection(),s.notifyHost(ay.CH_ANNNEEDSCONTEXTMENU,i)}function m3(e,t,i){let s={offset:{x:t.x,y:t.y},chart:e.accessor,originalEvent:i};e.notifyHost(ay.CH_CHTNEEDSCONTEXTMENU,s)}class m4 extends mw{factory;maxClicks;clicks;snapToSupported;isDrawingAnnotation;constructor(e,t){super(e.annName),this.factory=e,this.maxClicks=t,this.clicks=0,this.snapToSupported=!0,this.isDrawingAnnotation=!0}onMouseMove(e){let{point:t,view:i,offset:s}=e;i.drawCrosshair({ap:t,offset:s})}onMouseDown(e){let{point:t,view:i}=e;if(0===this.clicks){if(void 0===t)return gZ(e),!1;t.axis.pane.presenter.clearSelection(),this.annotation=this.factory(t.axis)}this.applyToPoints(t),this.clicks++,this.clicks===this.maxClicks&&void 0!==this.annotation?(this.annotation.drawn=!1,this.annotation.requestRedraw(),"function"==typeof this.annotation.updateOtherPoints&&this.annotation.updateOtherPoints(i.mainContext),gq(this.annotation,!0,el.Created)):this.annotation.requestRedraw()}applyToPoints(e){this.annotation.points[this.clicks].update(e.price,e.time)}}class m5{snapToSupported=!1;constructor(e,t){setTimeout(()=>this.finalize(e,t),10)}finalize(e,t){let i=e(t);t.pane.presenter.clearSelection(),i.drawn=!1,i.requestRedraw(),gq(i,!0,el.None)}}let m6=tz.MARKER_ARROW_ANGLE*Math.PI/180/2;function m7(e,t,i=tz.MARKER_ARROW_LENGTH){return new m8(e,t,i)}class m8{vertex;arrowLen;p1;p2;constructor(e,t,i=tz.MARKER_ARROW_LENGTH){this.vertex=t,this.arrowLen=i,this.p1=e[0],this.p2=e[1]}hitTest(e){let{anchor:t,p1:i,p2:s}=this.getArrowPoints();return iv([t,i],e,tz.HIT_TEST_TOLERANCE)||iv([t,s],e,tz.HIT_TEST_TOLERANCE)}draw(e){let{anchor:t,p1:i,p2:s}=this.getArrowPoints();iz(e,t,i),iz(e,t,s)}getArrowPoints(){let e=iT(this.p1,this.p2),t="start"===this.vertex?0:Math.PI,i=e-m6+t,s=e+m6+t,r="start"===this.vertex?this.p1:this.p2,n=this.arrowLen*Math.cos(i)+r.x,a=this.arrowLen*Math.sin(i)+r.y,o=this.arrowLen*Math.cos(s)+r.x,l=this.arrowLen*Math.sin(s)+r.y;return{anchor:r,p1:{x:n,y:a},p2:{x:o,y:l}}}}class m9{hitTest(){return!1}draw(){}}class ge extends mC{constructor(e,t){super(e,t),this.addPoints(2),this.alignPointsSupported=!0}get extend1(){return this.traits[tz.AT_EXTEND_PT_1]}get extend2(){return this.traits[tz.AT_EXTEND_PT_2]}get showPercentDiff(){return this.traits[tz.AT_SHOW_PERCENTDIFF]}get showBarCount(){return this.traits[tz.AT_SHOW_BARCOUNT]}get showRatio(){return this.traits[tz.AT_RATIO]}getElements(){let e=this.points[0].point,t=this.points[1].point,i=new mv(e,t,this.extend1,this.extend2,this.axis),s=[];return this.extend1&&s.push(new mv(i.p1,e,!0,!1,this.axis)),s.push(new mv(e,t,!1,!1,this.axis)),this.extend2&&s.push(new mv(t,i.p2,!1,!0,this.axis)),s}formatRatio(e,t){return` (${eB(e/t,3)})`}formatPercDiff(e,t){let i=(t-e)/e*100,s=i>0?"+":"";return` (${s}${eB(i,2)}%)`}formatPrice(e){return h_(this.axis,this.priceMap(e))}adornElements(e,t){if(!this.showBarCount&&!this.showPrices&&!this.showPercentDiff&&!this.showRatio)return;let[i,s]=this.points,r=e[+!!this.extend1].getAdornOffset(t);if(this.showBarCount){let e=iA(ig(i.point,s.point),r);iU(t,this.getBarCount(i.time,s.time).toFixed(0),e,Q.Right)}let n=this.showRatio?this.formatRatio(i.price,s.price):"",a=this.showPrices?this.formatPrice(i.price):"",o=`${a}${n}`.trim();""!==o&&iU(t,o,iA(i.point,r),Q.Right);let l=this.showPercentDiff?this.formatPercDiff(i.price,s.price):"",u=this.showPrices?this.formatPrice(s.price):"",h=`${u}${l}`.trim();""!==h&&iU(t,h,iA(s.point,r),Q.Right)}getMarkers(){let e=this.marker;if(!e||"none"===e.vertex)return[];let{vertex:t,kind:i}=e;return("both"===t?["start","end"]:[t]).map(e=>{if("arrow"===i){var t;return t=this.points,m7(t.map(e=>e.point),e)}return console.warn(`There is no marker of ${i} kind`),new m9})}}class gt extends mC{constructor(e,t){super(e,t),this.addPoints(1)}get showTimestamps(){return this.traits[tz.AT_SHOW_TIMESTAMPS]}getElements(){return[new mf(this.points[0].point,!0,this.axis)]}getTimeScaleAdornments(){return this.showTimestamps?[{time:this.points[0].time,color:this.traits.line.color}]:super.getTimeScaleAdornments()}}class gi extends mC{constructor(e,t){super(e,t),this.addPoints(1)}getElements(){return[new mf(this.points[0].point,!1,this.axis)]}getPriceScaleAdornments(){return this.showPrices?[{price:this.points[0].price,color:this.traits.line.color}]:super.getPriceScaleAdornments()}}class gs extends mC{constructor(e,t,i){super(e,t),this.addPoints(2),eF(i)&&eF(i.points)&&i.points.forEach((e,t)=>this.points[t].update(e.price,e.time))}allPoints(){let[e,t]=this.points;return eF(e,e.point,t,t.point)?[e,this.axis.toAnnotationPoint(ig(e.point,t.point)),t]:tz.EMPTY_ARRAY}line2(){return this.traits[tz.AT_LINE_2]}use52WeekPrices(){return this.traits[tz.AT_USE_52WEEK_PRICES]}getElements(){let e=this.allPoints();return e===tz.EMPTY_ARRAY?tz.EMPTY_ARRAY:e.map(e=>new mv({x:-tz.OUT_OF_SCREEN,y:e.point.y},{x:tz.OUT_OF_SCREEN,y:e.point.y},!1,!1,this.axis))}wasPointMovedByTool(e,t){eF(this.use52WeekPrices())&&(this.traits[tz.AT_USE_52WEEK_PRICES]=!1)}getStyleForElement(e,t){let i=this.line2();if(1!==t||!eF(i))return super.getStyleForElement(e,t);let s=ez(this.traits);return s.line=i,i8(s)}getPriceScaleAdornments(){let e=this.allPoints();if(!this.showPrices||e===tz.EMPTY_ARRAY)return super.getPriceScaleAdornments();let t=this.traits.line,i=e.map(e=>({price:e.price,color:t.color})),s=this.line2();return eF(s)&&(i[1].color=s.color),i}getFlipAnchorIndices(){return null}}class gr extends mb{helper;constructor(e,t,i){super(e,t),this.addPoints(i),this.helper=new mm(e)}get showTrendLine(){return this.traits[tz.AT_SHOW_TRENDLINE]}get hasAllPoints(){return eF(...this.points.map(e=>e.point))}get line2(){return this.traits[tz.AT_LINE_2]}get extendLeft(){return this.traits[tz.AT_EXTEND_LEFT]}get extendRight(){return this.traits[tz.AT_EXTEND_RIGHT]}get reverse(){return this.traits[tz.AT_REVERSE]}get levelsRespectLogScale(){return this.traits[tz.AT_LEVELS_RESPECT_LOG_SCALE]}getStyleForElement(e,t){if(e.isTrend){let e=ez(this.traits);return e.line=this.line2,i8(e)}return super.getStyleForElement(e,t)}getKeyPoints(){let e=e=>e.map(e=>this.points[e]);return e(this.isExtended?this.reverse?[1,0,2]:[0,1,2]:this.reverse?[0,1,0]:[1,0,1])}getElements(){if(!this.hasAllPoints)return[];let[e,t,i]=this.getKeyPoints(),s=t.price-e.price,r=t.price/e.price,n=this.extendLeft,a=this.extendRight,o=this.leftPoint,l=this.rightPoint,u=(e,t,i=!1)=>{let s=new mv(e,t,!i&&n,!i&&a,this.axis);return s.isTrend=i,s},h=this.levelsRespectLogScale&&this.axis.scale===X.Logarithmic,c=({value:e})=>{let t=i.price+s*e,n=i.price*Math.pow(r,e);this.helper.update(h?n:t,i.time);let a=this.helper.point.y;return u({x:o.x,y:a},{x:l.x,y:a})},d=this.getColoredElements(c);return this.showTrendLine&&(d.push(u(e.point,t.point,!0)),this.isExtended&&d.push(u((this.reverse?e:t).point,i.point,!0))),d}getAdornPointAndAlign(e,t){let i=this.labels,s=(e,t,i)=>({pt:e,align:t,offset:i}),r=this.axis.pane.getBoundsWithoutScales();switch(i){case tz.AT_LABELS_LEFT:return this.extendLeft?s({x:r.x,y:e.anchor1.y},Q.Left,t):super.getAdornPointAndAlign(e,t);default:case tz.AT_LABELS_RIGHT:return this.extendRight?s({x:r.x+r.width,y:e.anchor2.y},Q.Right,-t):super.getAdornPointAndAlign(e,t);case tz.AT_LABELS_CENTER:return super.getAdornPointAndAlign(e,t)}}getTextRef(){return(e,t,i)=>{let s=this.formatLevelPrice(i,t.anchor1.y);return{ref:t,spacing:5,offsetY:-5,text:s}}}adornElements(e,t){this.adornElementsForColoredFactors(e,(e,t)=>{let i=new Path2D;return null===e||(iN(i,e.p1),i.lineTo(t.p2.x,e.p1.y),iV(i,t.p2),i.lineTo(e.p1.x,t.p2.y)),i},this.getTextRef(),t)}getPriceScaleAdornments(){if(!this.pricesOnScale)return super.getPriceScaleAdornments();let e=this.getElements();if(0===e.length)return super.getPriceScaleAdornments();let t=this.traits.line.color;return this.factors.map((i,s)=>{let r=e[s++].p1,n=this.singleStyle?t:i.line.color;return{price:this.axis.toPrice(r.y),color:n}})}}class gn extends gr{constructor(e,t){super(e,t,2)}}class ga extends gr{constructor(e,t){super(e,t,3)}}let go=(e,t)=>{let i=new Path2D;return null===e||(iN(i,e.p1),iV(i,e.p2),iV(i,t.p2)),i};class gl extends mb{constructor(e,t){super(e,t),this.addPoints(2)}get reverse(){return this.traits[tz.AT_REVERSE]}getElements(){let[e,t]=this.getScreenPoints(),i=t.y-e.y,s=({value:s})=>{let r=this.reverse?e.y+s*i:t.y-s*i;return new mv(e,{x:t.x,y:r},!1,!0,this.axis)};return this.getColoredElements(s)}getTextRef(){let[e,t]=this.getScreenPoints(),i=t.y-e.y,[s,r]=[this.leftPoint,this.rightPoint];return(n,a,o)=>{let l=this.reverse?e.y+o*i:t.y-o*i;return{ref:new mv({x:s.x,y:l},{x:r.x,y:l},!1,!1,this.axis),spacing:5,offsetY:!0,text:o.toString()}}}adornElements(e,t){this.adornElementsForColoredFactors(e,go,this.getTextRef(),t)}}class gu extends gl{constructor(e,t){super(e,t)}}class gh{center;rim;radius;startAngle;endAngle;antiClockwise;axis;left;right;scale;clip;style;constructor(e,t,i,s,r,n,a){this.center=e,this.rim=t,this.radius=i,this.startAngle=s,this.endAngle=r,this.antiClockwise=n,this.axis=a,this.left=null,this.right=null,this.scale=null,this.clip=null,null!==t&&(this.left={x:this.center.x-this.radius,y:this.center.y},this.right={x:this.center.x+this.radius,y:this.center.y})}get hasScale(){return null!==this.scale}get hasClip(){return null!==this.clip}get hasRim(){return null!==this.rim}applyScale(e){e.translate(this.center.x,this.center.y),e.scale(this.scale.x,this.scale.y),e.translate(-this.center.x,-this.center.y)}inverseScale(e){let t=new DOMPointReadOnly(e.x,e.y),i=this.axis.pane.presenter.view.mouseContext;i.save(),i.resetTransform(),this.applyScale(i);let s=i.getTransform().inverse();return i.restore(),s.transformPoint(t)}hitTest(e){let t=999;if(this.hasRim&&(this.center.y<this.rim.y&&e.y<=this.center.y||this.center.y>=this.rim.y&&e.y>=this.center.y))t=Math.min(iy(this.left,e),iy(this.right,e));else{let{x:i,y:s}=iS(this.hasScale?this.inverseScale(e):e,this.center);if(!this.hasRim){let{startAngle:e,endAngle:t,antiClockwise:r}=this,n=Math.PI/2;if(0===e&&t===n&&!r&&(i<0||s<0)||e===n&&t===Math.PI&&!r&&(i>0||s<0)||e===-n&&t===Math.PI&&r&&(i>0||s>0)||0===e&&t===-n&&r&&(i<0||s>0))return!1}t=Math.abs(Math.sqrt(i*i+s*s)-this.radius)}return t<=tz.HIT_TEST_TOLERANCE}get isAntiClockwise(){return this.hasRim?this.rim.y<=this.center.y:this.antiClockwise}draw(e){e.save(),this.hasClip&&e.clip(this.clip),this.hasScale&&this.applyScale(e),iG(e,this.center,this.radius,this.startAngle,this.endAngle,this.isAntiClockwise??!1),e.restore()}}let gc=(e,t)=>{let i=new Path2D,{center:s}=t;if(iN(i,s),i.arc(s.x,s.y,t.radius,t.startAngle,t.endAngle,t.isAntiClockwise??!1),null===e)return i;let r=new Path2D,{center:n}=e;return iN(r,n),r.arc(n.x,n.y,e.radius,e.endAngle,e.startAngle,!e.isAntiClockwise),i.addPath(r),i};class gd extends mb{constructor(e,t){super(e,t),this.addPoints(2)}getElements(){let[e,t]=this.getScreenPoints();if(!eF(e,t))return[];let i=iy(e,t),s=iS(t,e),r=s.y/i,n=s.x/i,a=({value:t})=>{let s=i*t,a={x:e.x+n*s,y:e.y+r*s};var o=this.axis;let l=iy(e,a);return new gh(e,a,l,0,Math.PI,null,o)},o=this.getColoredElements(a);if(this.showTrendLine){let i=new mv(e,t,!1,!1,this.axis);i.isTrend=!0,o.unshift(i)}return o}get showTrendLine(){return!0}getTextRef(){return(e,t,i)=>{let{center:s}=t,r=t.isAntiClockwise?-1:1;return{ref:{x:s.x,y:s.y+r*t.radius},spacing:0,offsetY:!0,text:i.toString()}}}adornElements(e,t){this.adornElementsForColoredFactors(e,gc,this.getTextRef(),t)}}class gp extends gd{constructor(e,t){super(e,t)}getStyleForElement(e,t){if(e.isTrend){let e=ez(this.traits);return e.line=this.line2,i8(e)}return super.getStyleForElement(e,t)}get showTrendLine(){return this.traits[tz.AT_SHOW_TRENDLINE]}get line2(){return this.traits[tz.AT_LINE_2]}}class gf extends mb{constructor(e,t){super(e,t),this.addPoints(2)}get factorsPropName(){return tz.AT_ANGLES}getElements(){let[e,t]=this.getScreenPoints(),{x:i,y:s}=iS(t,e),r=({value:r})=>{let n=(t,i)=>new mv(e,{x:t,y:i},!1,!0,this.axis),a="1"!==r.charAt(0),o=Number(a?r.charAt(0):r.charAt(2));return a?n(t.x,e.y+s/o):n(e.x+i/o,t.y)};return this.getColoredElements(r)}getTextRef(){return(e,t,i)=>({ref:t.anchor2,spacing:0,offsetY:!0,text:i.toString()})}adornElements(e,t){this.adornElementsForColoredFactors(e,go,this.getTextRef(),t)}}class gm extends gl{constructor(e,t){super(e,t),this._factors=[{shown:!0,value:1/3},{shown:!0,value:2/3}]}getElements(){let[e,t]=this.getScreenPoints();return[new mv(e,t,!1,!1,this.axis)].concat(super.getElements())}}class gg extends gd{constructor(e,t){super(e,t),this._factors=[{shown:!0,value:1/3},{shown:!0,value:2/3}]}}class gy extends mC{constructor(e,t){super(e,t),this.addPoints(3)}getElements(){let e=this.points[0].point,t=this.points[1].point,i=this.points[2].point,s=(t.x+i.x)/2-e.x,r=(t.y+i.y)/2-e.y,n=[];return n.push(new mv(t,{x:t.x+s,y:t.y+r},!1,!0,this.axis)),n.push(new mv(e,{x:e.x+s,y:e.y+r},!1,!0,this.axis)),n.push(new mv(i,{x:i.x+s,y:i.y+r},!1,!0,this.axis)),n.push(new mv(t,i,!1,!1,this.axis)),n}}class gS extends mx{constructor(e,t){super(e,t)}getEllipse(){let e=this.getRect();return null===e?null:new iR(e.centerX,e.centerY,e.width/2,e.height/2)}hitTest(e){if(!this.visible)return!1;let t=this.getEllipse();return null!==t&&t.contains(e)}draw(e,t){var i;return!!super.draw(e,t)&&(i=this.getEllipse(),e.beginPath(),e.ellipse(i.cx,i.cy,i.radiusX,i.radiusY,0,0,2*Math.PI),e.stroke(),e.fill(),!0)}}class gA extends mC{constructor(e,t){super(e,t),this.addPoints(3)}get extend1(){return this.traits[tz.AT_EXTEND_PT_1]}get extend2(){return this.traits[tz.AT_EXTEND_PT_2]}getLastPoint(){let[e,t,i]=this.points;var s=iy(e.point,t.point),r=iT(e.point,t.point);return{x:i.point.x+s*Math.cos(r),y:i.point.y+s*Math.sin(r)}}getElements(){let[e,t,i]=this.points;var s=[];if(s.push(new mv(e.point,t.point,this.extend1,this.extend2,this.axis)),eF(i?.price)){var r=this.getLastPoint();s.push(new mv(i.point,r,this.extend1,this.extend2,this.axis))}return s}}class gT extends mx{kind;constructor(e,t,i){super(e,t),this.kind=i,this.adjustFill=!0}hitTest(e){if(!this.visible)return!1;let t=this.getRect();return null!==t&&t.contains(e)}get dimension(){let e="fish_hook"===this.kind?2:1;return tz.DEFAULT_SYMBOL_WIDTH_HEIGHT*e}updateOtherPoints(){this.points[1].price||this.setBottomRight()}setBottomRight(){let e=this.dimension,t=this.axis.pane.presenter.timeline,{price:i,time:s}=this.points[0],r=e_(t,s,Number,hw);if(-1!==r){let s=this.axis.pane.presenter.view.xAxis.xScale.bar.totalWidth,n=1;for(;(2*n+1)*s<e;)n++;this.points[0].update(i,t.at(r-n)),this.points[1].update(i,t.at(r+n));let a=iA(this.points[0].point,{x:0,y:-e/2}),o=iA(this.points[1].point,{x:0,y:e/2});this.points[0].updateFromPoint(a),this.points[1].updateFromPoint(o)}}draw(e,t){if(!super.draw(e,t))return!1;let i=this.getRect();switch(0===i.width&&(i.width=this.dimension),this.kind){case"zero":iK(e,i,"0");break;case"one":iK(e,i,"1");break;case"two":iK(e,i,"2");break;case"three":iK(e,i,"3");break;case"four":iK(e,i,"4");break;case"five":iK(e,i,"5");break;case"six":iK(e,i,"6");break;case"seven":iK(e,i,"7");break;case"eight":iK(e,i,"8");break;case"nine":iK(e,i,"9");break;case"question":iK(e,i,"?");break;case"fish_hook":var s=e,r=i;s.save(),s.translate(r.x,r.y);let n=Math.min(r.width,r.height)/560;s.scale(n,n),s.lineCap="butt",s.lineJoin="miter",s.miterLimit=4,s.save(),s.save(),s.miterLimit=10,s.beginPath(),s.moveTo(377.8,354.8),s.bezierCurveTo(377.8,354.8,401.8,517.8,290.6,507),s.bezierCurveTo(173.2,495.5,171.5,50.39,171.5,50.39),s.bezierCurveTo(171.5,50.39,191.7,252.59,212.3,351),s.bezierCurveTo(212.3,351,230.9,472.8,286.7,488.7),s.bezierCurveTo(350.4,507,369.5,452.7,377.8,354.79),s.closePath(),s.fill(),s.restore(),s.save(),s.miterLimit=10,s.beginPath(),s.moveTo(378.3,351.1),s.lineTo(341.1,446.6),s.lineTo(371.2,436.7),s.lineTo(378.3,351.1),s.closePath(),s.fill(),s.restore(),s.restore(),s.restore();break;case"arrow_up":var a=e,o=i;a.save();let{cx:l,cy:u,left:h,right:c,top:d,bottom:p,halfBaseSize:f}=iq(o);a.beginPath(),a.moveTo(c,u),a.lineTo(l,d),a.lineTo(h,u),a.lineTo(Math.floor(l-f),u),a.lineTo(Math.floor(l-f),p),a.lineTo(Math.floor(l+f),p),a.lineTo(Math.floor(l+f),u),a.closePath(),a.fill(),a.restore();break;case"arrow_down":var m=e,g=i;m.save();let{cx:y,cy:S,left:A,right:T,top:v,bottom:P,halfBaseSize:C}=iq(g);m.beginPath(),m.moveTo(T,S),m.lineTo(y,P),m.lineTo(A,S),m.lineTo(Math.floor(y-C),S),m.lineTo(Math.floor(y-C),v),m.lineTo(Math.floor(y+C),v),m.lineTo(Math.floor(y+C),S),m.closePath(),m.fill(),m.restore();break;case"arrow_right":var b=e,E=i;b.save();let{cx:L,cy:_,left:M,right:x,top:I,bottom:D,halfBaseSize:O}=iq(E);b.beginPath(),b.moveTo(L,I),b.lineTo(x,_),b.lineTo(L,D),b.lineTo(L,Math.floor(_+O)),b.lineTo(M,Math.floor(_+O)),b.lineTo(M,Math.floor(_-O)),b.lineTo(L,Math.floor(_-O)),b.closePath(),b.fill(),b.restore();break;case"arrow_left":var w=e,R=i;w.save();let{cx:N,cy:V,left:H,right:F,top:B,bottom:k,halfBaseSize:W}=iq(R);w.beginPath(),w.moveTo(N,B),w.lineTo(H,V),w.lineTo(N,k),w.lineTo(N,Math.floor(V+W)),w.lineTo(F,Math.floor(V+W)),w.lineTo(F,Math.floor(V-W)),w.lineTo(N,Math.floor(V-W)),w.closePath(),w.fill(),w.restore();break;case"arrow_horizontal":var U=e,$=i;U.save();let{cx:G,cy:z,left:Y,right:j,top:K,bottom:q,halfBaseSize:X}=iq($,1.5),Z=Math.floor(G-(G-Y)/3),J=Math.floor(G+(G-Y)/3);U.beginPath(),U.moveTo(Z,K),U.lineTo(Y,z),U.lineTo(Z,q),U.lineTo(Z,Math.floor(z+X)),U.lineTo(J,Math.floor(z+X)),U.lineTo(J,q),U.lineTo(j,z),U.lineTo(J,K),U.lineTo(J,Math.floor(z-X)),U.lineTo(Z,Math.floor(z-X)),U.lineTo(Z,K),U.closePath(),U.fill(),U.restore();break;case"arrow_vertical":var Q=e,ee=i;Q.save();let{cx:et,cy:ei,left:es,right:er,top:en,bottom:ea,halfBaseSize:eo}=iq(ee,2/3),el=Math.floor(ei-(ei-en)/3),eu=Math.floor(ei+(ei-en)/3);Q.beginPath(),Q.moveTo(er,el),Q.lineTo(et,en),Q.lineTo(es,el),Q.lineTo(Math.floor(et-eo),el),Q.lineTo(Math.floor(et-eo),eu),Q.lineTo(es,eu),Q.lineTo(et,ea),Q.lineTo(er,eu),Q.lineTo(Math.floor(et+eo),eu),Q.lineTo(Math.floor(et+eo),el),Q.lineTo(er,el),Q.closePath(),Q.fill(),Q.restore();break;case"arc_down":!function(e,t){let{cx:i,cy:s,left:r,right:n,deflection:a,arcWidth:o}=iX(t);e.save(),e.beginPath(),e.moveTo(n,s);let l=i+a,u=s+a,h=i-a,c=s+a;e.bezierCurveTo(l,u,h,c,r,s),e.lineTo(r,s+o),e.bezierCurveTo(h,c+o,l,u+o,n,s+o),e.closePath(),e.fill(),e.restore()}(e,i);break;case"arc_up":!function(e,t){let{cx:i,cy:s,left:r,right:n,deflection:a,arcWidth:o}=iX(t);e.save(),e.beginPath(),e.moveTo(n,s);let l=i+a,u=s-a,h=i-a,c=s-a;e.bezierCurveTo(l,u,h,c,r,s),e.lineTo(r,s-o),e.bezierCurveTo(h,c-o,l,u-o,n,s-o),e.closePath(),e.fill(),e.restore()}(e,i);break;case"thumbs_up":var eh=e,ec=i;eh.save(),eh.translate(ec.x,ec.y),eh.lineWidth=.05;let ed=Math.min(ec.width,ec.height)/18;eh.scale(ed,ed),eh.lineCap="butt",eh.save(),eh.save(),eh.beginPath(),eh.moveTo(3.23,8.96),eh.lineTo(4.17,8.96),eh.bezierCurveTo(4.73,8.81,5.91,6.45,6.45,5.82),eh.bezierCurveTo(6.88,5.33,7.66,5.09,8.48,3.7),eh.bezierCurveTo(9.11,2.78,8.38,1.49,10.06,1.17),eh.bezierCurveTo(10.9,1.01,11.86,2.61,11.58,4.11),eh.bezierCurveTo(11.49,4.6,11.25,5.14,11.07,5.54),eh.bezierCurveTo(10.63,6.5,10.05,6.58,10.17,7.23),eh.bezierCurveTo(10.98,7.25,11.79,7.32,12.67,7.27),eh.bezierCurveTo(14.33,7.17,15.55,9.08,14.43,10.38),eh.bezierCurveTo(14.9,11.12,14.79,12.33,14.14,12.81),eh.bezierCurveTo(14.42,13.58,14.25,14.45,13.67,14.8),eh.bezierCurveTo(14.13,16.77,12.36,16.87,11.77,16.84),eh.lineTo(4.65,16.84),eh.bezierCurveTo(3.87,16.77,3.95,16.28,3.5,16.27),eh.bezierCurveTo(3.39,16.26,3.3,16.26,3.3,16.26),eh.bezierCurveTo(3.18,16.26,3.19,15.7,3.28,15.7),eh.bezierCurveTo(3.36,15.69,3.61,15.68,3.87,15.71),eh.bezierCurveTo(4.03,15.79,4.4,16.26,4.75,16.27),eh.lineTo(12.12,16.26),eh.bezierCurveTo(13.13,16.27,13.67,15.11,12.8,14.56),eh.bezierCurveTo(13.85,14.53,13.98,12.98,13.19,12.6),eh.bezierCurveTo(14.35,12.49,14.5,10.65,13.44,10.41),eh.bezierCurveTo(14.8,9.97,14.39,7.59,12.35,7.83),eh.bezierCurveTo(11.42,7.77,9.87,7.94,9.68,7.62),eh.bezierCurveTo(9.41,6.82,9.684,6.45,10.17,5.88),eh.bezierCurveTo(10.5,5.46,11.02,4.6,11.04,3.64),eh.bezierCurveTo(11.05,2.5,10.41,1.23,9.58,1.98),eh.bezierCurveTo(9.38,2.21,9.36,3.47,8.94,4.02),eh.bezierCurveTo(8.09,5.52,7.3,5.66,6.95,6.15),eh.bezierCurveTo(6.27,6.86,4.93,9.52,4.36,9.52),eh.bezierCurveTo(3.98,9.52,3.243,9.52,3.24,9.52),eh.bezierCurveTo(3.12,9.52,3.08,8.98,3.22,8.95),eh.closePath(),eh.fill(),eh.restore(),eh.restore(),eh.restore();break;case"thumbs_down":var ep=e,ef=i;ep.save(),ep.translate(ef.x,ef.y),ep.lineWidth=.05;let em=Math.min(ef.width,ef.height)/18;ep.scale(em,em),ep.lineCap="butt",ep.save(),ep.save(),ep.beginPath(),ep.moveTo(14.77,9.04),ep.lineTo(13.82,9.04),ep.bezierCurveTo(13.27,9.18,12.09,11.55,11.54,12.17),ep.bezierCurveTo(11.12,12.66,10.34,12.9,9.52,14.29),ep.bezierCurveTo(8.88,15.21,9.62,16.51,7.93,16.82),ep.bezierCurveTo(7.1,16.98,6.13,15.39,6.42,13.88),ep.bezierCurveTo(6.51,13.4,6.75,12.855,6.93,12.46),ep.bezierCurveTo(7.37,11.49,7.95,11.41,7.82,10.76),ep.bezierCurveTo(7.02,10.75,6.21,10.68,5.33,10.73),ep.bezierCurveTo(3.66,10.83,2.44,8.91,3.57,7.62),ep.bezierCurveTo(3.09,6.88,3.2,5.67,3.85,5.19),ep.bezierCurveTo(3.57,4.42,3.74,3.55,4.33,3.2),ep.bezierCurveTo(3.87,1.22,5.64,1.13,6.22,1.16),ep.lineTo(13.35,1.16),ep.bezierCurveTo(14.12,1.22,14.04,1.71,14.49,1.73),ep.bezierCurveTo(14.6,1.73,14.7,1.73,14.7,1.73),ep.bezierCurveTo(14.82,1.74,14.8,2.29,14.72,2.3),ep.bezierCurveTo(14.63,2.31,14.39,2.32,14.12,2.28),ep.bezierCurveTo(13.96,2.21,13.6,1.74,13.25,1.73),ep.lineTo(5.88,1.73),ep.bezierCurveTo(4.86,1.73,4.33,2.88,5.19,3.44),ep.bezierCurveTo(4.14,3.47,4.01,5.02,4.8,5.39),ep.bezierCurveTo(3.64,5.5,3.49,7.35,4.55,7.58),ep.bezierCurveTo(3.19,8.02,3.6,10.4,5.64,10.16),ep.bezierCurveTo(6.57,10.23,8.12,10.05,8.32,10.37),ep.bezierCurveTo(8.58,11.17,8.32,11.54,7.82,12.11),ep.bezierCurveTo(7.49,12.54,6.97,13.39,6.96,14.36),ep.bezierCurveTo(6.94,15.49,7.59,16.76,8.41,16.01),ep.bezierCurveTo(8.62,15.78,8.63,14.52,9.05,13.97),ep.bezierCurveTo(9.9,12.47,10.69,12.33,11.04,11.84),ep.bezierCurveTo(11.72,11.13,13.06,8.47,13.637,8.47),ep.bezierCurveTo(14.01,8.47,14.75,8.47,14.75,8.47),ep.bezierCurveTo(14.87,8.47,14.91,9.01,14.77,9.04),ep.closePath(),ep.fill(),ep.restore(),ep.restore(),ep.restore();break;case"buy":iK(e,i,"B");break;case"sell":iK(e,i,"S")}return!0}}class gv extends mb{helper;constructor(e,t){super(e,t),this.addPoints(2),this.helper=new mm(e)}getElements(){let e=this.axis.pane.presenter.timeline,{price:t,time:i}=this.points[0],s=e_(e,i,Number,hw),r=e_(e,this.points[1].time,Number,hw),n=r-s;if(-1===s||-1===r)return[];let a=({value:i})=>{let r=e.at(s+i*n);return null===r?null:(this.helper.update(t,r),new mf(this.helper.point,!0,this.axis))};return this.getColoredElements(a)}getTextRef(){return(e,t,i)=>({ref:t.anchor,spacing:3,offsetY:!0,text:i.toString()})}adornElements(e,t){let i=this.axis.pane.getBoundsWithoutScales();this.adornElementsForColoredFactors(e,(e,t)=>{let s=new Path2D;if(null===e)return s;let r=t.anchor.x-e.anchor.x;return s.rect(e.anchor.x,i.y,r,i.height),s},this.getTextRef(),t)}getTimeScaleAdornments(){let e=e=>({time:this.points[e].time,color:this.traits.line.color});return[e(0),e(1)]}}class gP{snapToSupported=!0;isDrawingAnnotation=!0;constructor(){}onMouseMove(e){let{point:t,view:i,offset:s}=e;i.drawCrosshair({ap:t,offset:s})}onMouseDown(e){if(eO()&&e.originalEvent instanceof TouchEvent)return;let{point:t}=e,i=t.axis.pane.presenter,s={chart:i.accessor,axis:t.axis,point:{time:t.time.getTime(),price:t.price}};i.notifyHost(ay.CH_ANNPOINTPICKED,s),gK(i,void 0)}}let gC="Closed";class gb extends mC{isLong;twoDecMeta;_dataWindow;_metaData;isHit;constructor(e,t,i){super(e,t),this.isLong=i,this.isHit=!1,this.addPoints(4);let s=(e,t)=>this.points[e].moveDirection=t;s(1,es.Vertical),s(2,es.Vertical),s(3,es.Horizontal),this.twoDecMeta=new ii(2)}data(e){return this.presenter.mainPlot.timeSeries.container.getData(e)}get presenter(){return this.axis.pane.presenter}getDataWindow(e,t,i=!0,s=!0){let r=this.data(ag.DateTime),n=e_(r,+e,Number),a=e_(r,+t,Number),o={refIndex:-1,highestIndex:-1,lowestIndex:-1,highest:null,lowest:null,data:[]},[l,u,h]=[ag.High,ag.Low,ag.Close].map(e=>this.data(e)),c=e=>e-n;for(let e=n;e<=a;e++)i&&-1===o.refIndex&&eF(this.entryPrice)&&this.entryPrice>=u[e]&&this.entryPrice<=l[e]&&(o.refIndex=c(e)),(!i||o.refIndex>=0&&c(e)>=o.refIndex)&&((!eF(o.highest)||l[e]>o.highest)&&(o.highest=l[e]),(!eF(o.lowest)||u[e]<o.lowest)&&(o.lowest=u[e])),i&&-1!==o.refIndex&&(-1===o.highestIndex&&l[e]>this.upperPrice&&(o.highestIndex=c(e)),-1===o.lowestIndex&&u[e]<this.lowerPrice&&(o.lowestIndex=c(e))),s&&o.data.push({high:l[e],low:u[e],close:h[e],time:r[e]});if(s&&o.data&&o.data.length>0){o.state=eF(o.highest,o.lowest)&&(this.upperPrice<o.highest||this.lowerPrice>o.lowest)?gC:"Open",o.special=-1===o.highestIndex&&-1===o.lowestIndex||o.highestIndex===o.lowestIndex;let e=eC(o.data);if(o.toPrice=e.close,o.toTime=e.time,o.state===gC)if(o.special){if(-1!==o.refIndex){let e=o.data[o.refIndex];o.toTime=e.time;let t=this.isLong?this.lowerPrice<o.lowest:this.upperPrice<o.highest;o.toPrice=t?this.upperPrice:this.lowerPrice}}else{let e=-1!==o.highestIndex&&-1!==o.lowestIndex;e&&o.highestIndex<o.lowestIndex||-1===o.lowestIndex?(o.toPrice=this.upperPrice,o.toTime=o.data[o.highestIndex].time):(e&&o.lowestIndex<o.highestIndex||-1===o.highestIndex)&&(o.toPrice=this.lowerPrice,o.toTime=o.data[o.lowestIndex].time)}let t=this.isLong?o.toPrice-this.entryPrice:this.entryPrice-o.toPrice;o.pAndL=eB(t,2)}return o}get dataWindow(){return eF(this._dataWindow)||(this._dataWindow=this.getDataWindow(this.entryAnchor.time,this.exitAnchor.time)),this._dataWindow}getVisiblePriceRange(){let e=this.axis.yScale.domain();return e[1]-e[0]}getFutureTimestamp(){let e=this.axis.pane.presenter.timeline,t=e_(e,+this.points[0].time,Number,hw),i=Math.min(e.length-1,t+50);return e.at(i).getTime()}get entryPrice(){return this.entryAnchor.price}get entryAnchor(){return this.points[0]}get upperPrice(){return this.upperAnchor.price}get upperAnchor(){return this.points[1]}get lowerPrice(){return this.lowerAnchor.price}get lowerAnchor(){return this.points[2]}get exitAnchor(){return this.points[3]}get accountSize(){return this.traits[tz.AT_ACCOUNT_SIZE]}get risk(){let e=this.traits[tz.AT_RISK_IS_PERCENT],t=this.traits[tz.AT_RISK];return eB(e?t/100*this.accountSize:t,2)}get pointValue(){return this._metaData||(this._metaData=this.presenter.mainPlot.metaData),this._metaData.pointValue}formatDollarValue(e){return Number.isFinite(e)?`${e<0?"-":""}$${this.twoDecMeta.format(Math.abs(e))}`:tz.NOT_APPLICABLE}get qty(){return Math.floor(this.risk/(this.isLong?this.entryPrice-this.lowerPrice:this.upperPrice-this.entryPrice))}get upperDiff(){return eB(this.upperPrice-this.entryPrice,2)}get amountMultiplier(){return this.isLong?1:-1}get upperAmount(){return eB(this.accountSize+this.amountMultiplier*this.qty*this.upperDiff,2)}get upperPandL(){return eB(this.amountMultiplier*this.upperDiff*this.pointValue,2)}get isCompact(){return this.traits[tz.AT_COMPACT]}get upper(){let e=h_(this.axis,this.priceMap(this.upperPrice)),t=`(${eB(this.upperDiff/this.entryPrice*100,2).toFixed(2)}%)`;return this.isCompact,`${e} ${t}`}get upperText(){let e=`${this.formatDollarValue(this.upperPandL)}`,t=`${this.formatDollarValue(this.upperAmount)}`,i=this.isLong?"Target":"Stop";return this.isCompact?`${this.upper} ${e}`:`${i}: ${this.upper}, P&L: ${e}, Amount: ${t}`}get lowerDiff(){return eB(this.entryPrice-this.lowerPrice,2)}get lowerAmount(){return eB(this.accountSize-this.amountMultiplier*this.qty*this.lowerDiff,2)}get lowerPandL(){return eB(-this.amountMultiplier*this.lowerDiff*this.pointValue,2)}get lower(){let e=h_(this.axis,this.priceMap(this.lowerPrice)),t=`(${eB(this.lowerDiff/this.entryPrice*100,2).toFixed(2)}%)`;return this.isCompact,`${e} ${t}`}get lowerText(){let e=`${this.formatDollarValue(this.lowerPandL)}`,t=`${this.formatDollarValue(this.lowerAmount)}`,i=this.isLong?"Stop":"Target";return this.isCompact?`${this.lower} ${e}`:`${i}: ${this.lower}, P&L: ${e}, Amount: ${t}`}get riskReward(){return eB(this.isLong?this.upperDiff/this.lowerDiff:this.lowerDiff/this.upperDiff,2)}get state(){return this.dataWindow.state}get pAndL(){return this.dataWindow.pAndL}get pAndLValue(){return this.pAndL*this.pointValue}positionPoints(){let e=this.getVisiblePriceRange()/5,t=this.getFutureTimestamp();this.upperAnchor.update(this.entryPrice+e,this.entryAnchor.time),this.lowerAnchor.update(this.entryPrice-e,this.entryAnchor.time),this.exitAnchor.update(this.entryPrice,t)}get lowerStyle(){return this.fillOnlyStyle(tz.AT_FILL2)}get upperStyle(){return this.fillOnlyStyle(tz.AT_FILL)}get textStyle(){return this.fillOnlyStyle(tz.AT_FILL_TEXT)}get secondaryLineStyle(){return i8({line:{color:this.traits.line.color,dashStyle:"ShortDash"},fill:{color:tz.COLOR_TRANSPARENT}})}wasModifiedByTool(){eF(this.points[2].price)||this.positionPoints(),this._dataWindow=void 0}wasPointMovedByTool(e,t){let i=this.getVisiblePriceRange()/5e3;if(3>this.points.indexOf(e)){let t=t=>e.update(t,e.time);this.entryAnchor.price>this.upperAnchor.price&&t(e===this.entryAnchor?this.upperAnchor.price-i:this.entryAnchor.price+i),this.entryAnchor.price<this.lowerAnchor.price&&t(e===this.entryAnchor?this.lowerAnchor.price+i:this.entryAnchor.price-i)}if(e===this.entryAnchor){let t=(t,i,s)=>t.update(i?e.price:t.price,s?e.time:t.time);t(this.exitAnchor,!0,!1),t(this.upperAnchor,!1,!0),t(this.lowerAnchor,!1,!0)}this.wasModifiedByTool()}get isUpperPerPAndL(){let e=this.dataWindow;return this.isLong?e.pAndL>0:e.pAndL<=0}getStyleForElement(e,t){return e.style||this.defaultStyle}getElements(){let e=new mv(this.entryAnchor.point,this.exitAnchor.point,!1,!1,this.axis),t=this.exitAnchor.point.x<this.entryAnchor.point.x,i=Math.abs(this.exitAnchor.point.x-this.entryAnchor.point.x),s=(e,t)=>({x:e.x+t,y:e.y}),r=new mP(s(this.upperAnchor.point,t?-i:0),i,Math.abs(this.upperAnchor.point.y-this.entryAnchor.point.y),this.axis);r.style=this.upperStyle;let n=new mP(s(this.entryAnchor.point,t?-i:0),i,Math.abs(this.entryAnchor.point.y-this.lowerAnchor.point.y),this.axis);n.style=this.lowerStyle;let a=[e,r,n],o=this.dataWindow;if(-1!==o.refIndex){let e=o.data[o.refIndex],t=new mm(this.axis,this.entryPrice,e.time),i=new mm(this.axis,o.toPrice,o.toTime),s=new mv(t.point,i.point,!1,!1,this.axis);if(s.style=this.secondaryLineStyle,a.push(s),t.time!==i.time){let e=this.entryPrice<o.toPrice,s=new mP({x:t.point.x,y:Math.min(t.point.y,i.point.y)},i.point.x-t.point.x,Math.abs(i.point.y-t.point.y),this.axis);s.style=e?this.upperStyle:this.lowerStyle,a.push(s)}}return a}hitTest(e){if(!this.visible)return!1;let t=this.isHit||!1;return this.isHit=super.hitTest(e),this.isHit!==t&&this.requestRedraw(),this.isHit}get showTextAdornments(){return this.isHit||this.isSelected}getPriceScaleAdornments(){let e=e=>iC(this.traits[e].color);return[{price:this.upperPrice,color:e(tz.AT_FILL)},{price:this.entryPrice,color:e(tz.AT_LINE)},{price:this.lowerPrice,color:e(tz.AT_FILL2)}]}adornElements(e,t){let[i,s,r]=e;if(this.showTextAdornments){let[e,n]=[!0,!1].map(e=>iB(t,e)),{x:a,y:o,width:l}=s.rect,u=this.textStyle.fillStyle;iU(t,this.upperText,{x:a+l/2,y:o+e},Q.Center,u,iC(this.upperStyle.fillStyle));let{x:h,y:c,width:d,height:p}=r.rect;iU(t,this.lowerText,{x:h+d/2,y:c+p+Math.abs(n)},Q.Center,u,iC(this.lowerStyle.fillStyle));let{p1:f,p2:m}=i,{x:g,y:y}=f,{x:S}=m,A=this.state||tz.NOT_APPLICABLE,T=this.isCompact?`${this.formatDollarValue(this.pAndLValue)}`:`${A} P&L: ${this.formatDollarValue(this.pAndLValue)}, Qty: ${this.qty}`,v=this.isCompact?`${this.riskReward.toFixed(2)}`:`Risk/Reward Ratio: ${this.riskReward.toFixed(2)}`,P=e=>t.measureText(e).width,C=Math.abs(S-g)<1.25*Math.max(P(T),P(v))?y+Math.abs(n)+5:y+e+10,b=iC(this.isUpperPerPAndL?this.upperStyle.fillStyle:this.lowerStyle.fillStyle);iU(t,[T,v],{x:g+(S-g)/2,y:C},Q.Center,u,b)}}updatePoints(e){super.updatePoints(e),this.wasModifiedByTool()}}var gE=["years","months","weeks","days","hours","minutes","seconds"];function gL(e,t){tt(2,arguments);var i=ts(e),s=ts(t),r=i.getTime()-s.getTime();return r<0?-1:r>0?1:r}function g_(e){return(g_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function gM(e,t){if(tt(2,arguments),!t||"object"!==g_(t))return new Date(NaN);var i=t.years?te(t.years):0,s=t.months?te(t.months):0,r=t.weeks?te(t.weeks):0,n=t.days?te(t.days):0,a=t.hours?te(t.hours):0,o=t.minutes?te(t.minutes):0,l=t.seconds?te(t.seconds):0,u=ts(e),h=s||i?tr(u,s+12*i):u;return new Date((n||r?lk(h,n+7*r):h).getTime()+1e3*(l+60*(o+60*a)))}function gx(e,t,i){tt(2,arguments);var s=uL(e,t)/6e4;return uM(null==i?void 0:i.roundingMethod)(s)}class gI extends mE{markers;display=null;constructor(e,t){super(e,t),this.points=mM(e),this.points[2].visible=!1,this.points[3].visible=!1,this.markers=[new m9]}isPointDrawn(e){return!!super.isPointDrawn(e)&&e.visible}makeLineArrow(e,t,i,s){let r=[ig(e,t),ig(i,s)];return[this.makeLine(r[0],r[1]),m7(r,"end",10)]}get rectColor(){return this.traits[tz.AT_FILL].color}get textColor(){return this.traits[tz.AT_FILL_TEXT].color}getMarkers(){return this.markers}formatDateDifference(e,t){return this.presenter.data.aggregation.isEndOfDay?`${lF(t,e)}d`:(function(e,t){if(arguments.length<1)throw TypeError("1 argument required, but only ".concat(arguments.length," present"));var i,s,r,n,a,o=null!=(i=null!=(s=null==t?void 0:t.locale)?s:nP.locale)?i:oZ,l=null!=(r=null==t?void 0:t.format)?r:gE,u=null!=(n=null==t?void 0:t.zero)&&n,h=null!=(a=null==t?void 0:t.delimiter)?a:" ";return o.formatDistance?l.reduce(function(t,i){var s="x".concat(i.replace(/(^.)/,function(e){return e.toUpperCase()})),r=e[i];return"number"==typeof r&&(u||e[i])?t.concat(o.formatDistance(s,r)):t},[]).join(h):""})(function(e){tt(1,arguments);var t=ts(e.start),i=ts(e.end);if(isNaN(t.getTime()))throw RangeError("Start Date is invalid");if(isNaN(i.getTime()))throw RangeError("End Date is invalid");var s={};s.years=Math.abs(function(e,t){tt(2,arguments);var i=ts(e),s=ts(t),r=gL(i,s),n=Math.abs(function(e,t){tt(2,arguments);var i=ts(e),s=ts(t);return i.getFullYear()-s.getFullYear()}(i,s));i.setFullYear(1584),s.setFullYear(1584);var a=gL(i,s)===-r,o=r*(n-Number(a));return 0===o?0:o}(i,t));var r=gL(i,t),n=gM(t,{years:r*s.years});s.months=Math.abs(function(e,t){tt(2,arguments);var i,s=ts(e),r=ts(t),n=gL(s,r),a=Math.abs(function(e,t){tt(2,arguments);var i=ts(e),s=ts(t);return 12*(i.getFullYear()-s.getFullYear())+(i.getMonth()-s.getMonth())}(s,r));if(a<1)i=0;else{1===s.getMonth()&&s.getDate()>27&&s.setDate(30),s.setMonth(s.getMonth()-n*a);var o=gL(s,r)===-n;(function(e){tt(1,arguments);var t=ts(e);return lB(t).getTime()===(function(e){tt(1,arguments);var t=ts(e),i=t.getMonth();return t.setFullYear(t.getFullYear(),i+1,0),t.setHours(23,59,59,999),t})(t).getTime()})(ts(e))&&1===a&&1===gL(e,r)&&(o=!1),i=n*(a-Number(o))}return 0===i?0:i}(i,n));var a=gM(n,{months:r*s.months});s.days=Math.abs(lF(i,a));var o=gM(a,{days:r*s.days});s.hours=Math.abs(function(e,t,i){tt(2,arguments);var s=uL(e,t)/36e5;return uM(null==i?void 0:i.roundingMethod)(s)}(i,o));var l=gM(o,{hours:r*s.hours});s.minutes=Math.abs(gx(i,l));var u=gM(l,{minutes:r*s.minutes});return s.seconds=Math.abs(ux(i,u)),s}({start:e,end:t}),{format:["days","hours","minutes","seconds"]}).replaceAll(/(days?)|(hours?)|(minutes?)|(seconds?)/g,e=>e[0])}computeState(){}get text(){return null===this.display&&this.computeState(),this.display}getTextCoord(e,t){let i=this.points[0].price<this.points[1].price,s=iB(t,i,this.text.length),{x:r,y:n,width:a,height:o}=e.rect;return{x:r+a/2,y:n+(i?0:o)+(i?s:Math.abs(s))}}adornElements(e,t){iU(t,this.text,this.getTextCoord(e[0],t),Q.Center,this.textColor,iC(this.rectColor))}getDateDifference(){let[e,t]=this.points.slice(0,2).map(e=>e.time),i=Math.min(+e,+t),s=Math.max(+e,+t),r=this.data(ag.DateTime),n=e_(r,+i,Number),a=e_(r,+s,Number),o=em(this.data(ag.Volume).slice(n,a+1)),l=this.formatter.format(o,ag.Volume),u=a-n,h=0===u?"":this.formatDateDifference(i,s),c=e<t?"":"-";return[`${c}${u} bars, ${c}${h}`,`Vol ${l}`]}getPriceDifference(){let[e,t]=this.points.slice(0,2).map(e=>e.price),i=t-e,s=this.formatter.format(i,ag.Close),r=this.formatter.format(i/e,ag.PercentChange);return[`${s} (${r})`]}resetComputedState(){this.display=null}getFlipAnchorIndices(){return[0,1]}}class gD extends gI{getElements(){this.points.slice(2).forEach(e=>e.toPoint());let[e,t,i,s]=this.getScreenPoints(),r=this.makeLine(e,s),n=this.makeLine(t,i),[a,o]=this.makeLineArrow(e,s,t,i);return this.markers[0]=o,[this.rect,r,n,a]}computeState(){this.display=this.getDateDifference()}}class gO extends gI{getElements(){this.points.slice(2).forEach(e=>e.toPoint());let[e,t,i,s]=this.getScreenPoints(),r=this.makeLine(e,i),n=this.makeLine(t,s),[a,o]=this.makeLineArrow(e,i,t,s);return this.markers[0]=o,[this.rect,r,n,a]}computeState(){this.display=this.getPriceDifference()}}class gw extends gI{get drawBorder(){return this.traits[tz.AT_DRAW_BORDER]}getBorderElements(){if(!this.drawBorder)return[];let[e,t,i,s]=this.getScreenPoints();return[this.makeLine(e,s),this.makeLine(t,i),this.makeLine(e,i),this.makeLine(t,s)]}getElements(){this.points.slice(2).forEach(e=>e.toPoint());let[e,t,i,s]=this.getScreenPoints(),[r,n]=this.makeLineArrow(e,s,t,i),[a,o]=this.makeLineArrow(e,i,t,s);this.markers=[n,o];let l=this.getBorderElements();return[this.rect,r,a].concat(l)}computeState(){this.display=this.getPriceDifference().concat(this.getDateDifference())}}class gR extends mE{constructor(e,t){super(e,t),this.points=mM(e)}get priceLevels(){return i1(this.traits[tz.AT_PRICE_LEVELS])}get timeLevels(){return i1(this.traits[tz.AT_TIME_LEVELS])}get showAngles(){return this.traits[tz.AT_SHOW_ANGLES]}get reverse(){return this.traits[tz.AT_REVERSE]}get showLeftLabels(){return this.traits[tz.AT_SHOW_LEFT_LABELS]}get showRightLabels(){return this.traits[tz.AT_SHOW_RIGHT_LABELS]}get showTopLabels(){return this.traits[tz.AT_SHOW_TOP_LABELS]}get showBottomLabels(){return this.traits[tz.AT_SHOW_BOTTOM_LABELS]}getAngles(e,t){let i=this.getScreenPoints(),s=this.lineOnlyStyle(tz.AT_LINE_2),r=[];e.concat(t).flatMap(e=>[e.p1,e.p2]).map(e=>{r.some(t=>e.x===t.x&&e.y===t.y)||r.push(e)});let n=i.map(e=>r.filter(t=>t.x!==e.x&&t.y!==e.y).map(t=>this.makeLine(e,t))).flat();return n.forEach(e=>e.style=s),n}getElements(){let e=this.getLinesDataAtLevels(this.priceLevels,this.timeLevels),{priceLines:t,timeLines:i}=this.getLineElements(e),s=this.showAngles?this.getAngles(t,i):[];return[...t,...i,...s]}adornElements(e,t){let i=this.singleStyle,s=this.showBackground,r=t.fillStyle,n=iF(t,1)/2,{x:a,y:o}=tz.DEFAULT_ADORN_OFFSET,l=(e,i,s,r,n)=>{let a=iA(e,i);iU(t,Number(s.toFixed(4)).toString(),a,r,n)},u=null;if(e.forEach(e=>{if(!e._data)return;let{level:h,isPrice:c}=e._data,d=i?r:e.style.strokeStyle,p=u&&s&&!i;c?(this.showLeftLabels&&l(e.p1,{x:a,y:n},h,Q.Right,d),this.showRightLabels&&l(e.p2,{x:-a,y:n},h,Q.Left,d)):(this.showTopLabels&&l(e.p1,{x:0,y:o},h,Q.Center,d),this.showBottomLabels&&l(e.p2,{x:0,y:-(2*o)},h,Q.Center,d)),p&&((e,i)=>{let s=new Path2D;iH(s,e.p1,i.p2),t.fillStyle=i.style.fillStyle,t.fill(s)})(u,e),u=e}),i&&s){let e=this.applyBackgroundOpacity(this.traits.line.color),i=new Path2D,[s,r]=this.getScreenPoints();iH(i,s,r),t.fillStyle=e,t.fill(i)}}resetComputedState(){this.lines=void 0}updateFrom(e,t,i,s,r){let n=e.reverse!==this.reverse;super.updateFrom(e,t,i,s,r),n&&this.resetComputedState()}getFlipAnchorIndices(){return[0,1]}}let gN=e=>e.map(e=>({...e,dimensions:e.value.split("x").map(Number)})),gV=(e,t)=>1e-7>Math.abs(e-t);class gH extends mE{_parsedFans=null;_parsedArcs=null;constructor(e,t){super(e,t),this.points=mM(e),this._parsedFans=this._parsedArcs=null}get levels(){return i1(this.traits[tz.AT_LEVELS])}setComputedAndTraits(e,t){let i={...e,computed:t,traits:this.getTraitsFor(e)};return delete i.line,i}get computedLevels(){return this.levels.map(e=>this.setComputedAndTraits(e,e.value/5))}get showRangesRatio(){return this.traits[tz.AT_SHOW_RANGES_RATIO]}get arcs(){return i1(this.traits[tz.AT_ARCS])}get fans(){return i1(this.traits[tz.AT_FANS])}get reverse(){return this.traits[tz.AT_REVERSE]}get parsedFans(){return null===this._parsedFans&&(this._parsedFans=gN(this.fans)),this._parsedFans}get computedFans(){let[,,e,t]=this.getReversedScreenPoints(),{dx:i,dy:s}=this.unit,{signX:r,signY:n}=this.getOrientation();return this.parsedFans.map(a=>{let[o,l]=a.dimensions;return this.setComputedAndTraits(a,o>=l?{x:e.x,y:e.y+l/o*n*5*s}:{x:t.x+o/l*5*r*i,y:t.y})})}get parsedArcs(){return null===this._parsedArcs&&(this._parsedArcs=gN(this.arcs)),this._parsedArcs}get computedArcs(){let{dx:e}=this.unit;return this.parsedArcs.map(t=>{let[i,s]=t.dimensions;return this.setComputedAndTraits(t,Math.sqrt(e**2*(i**2+s**2)))})}getReversedScreenPoints(){let[e,t,i,s]=this.getScreenPoints();return this.reverse?[t,e,s,i]:[e,t,i,s]}get unit(){let[e,t]=this.getReversedScreenPoints();return e.x!==t.x&&e.y!==t.y?{dx:Math.abs(t.x-e.x)/5,dy:Math.abs(t.y-e.y)/5}:null}get priceBarRatio(){return this.traits[tz.AT_PRICE_BAR_RATIO]}set priceBarRatio(e){this.traits[tz.AT_PRICE_BAR_RATIO]=e}makeStyledLine(e,t,i){let s=this.makeLine(e,t);return this.singleStyle||(s.style=i8(i)),s}getGridLines(e,t){let i=t.x-e.x,s=t.y-e.y;return this.computedLevels.map(({computed:r,traits:n})=>{let a=e.x+r*i,o=e.y+r*s;return[this.makeStyledLine({x:a,y:e.y},{x:a,y:t.y},n),this.makeStyledLine({x:e.x,y:o},{x:t.x,y:o},n)]}).flat()}getArcs(e){let{flipX:t,flipY:i,signY:s}=this.getOrientation(),{dx:r,dy:n}=this.unit,a=gV(r,n)?null:{x:1,y:n/r},o=this.getClipPath();return this.computedArcs.map(({computed:r,traits:n})=>{let l=new gh(e,null,r,t?s*Math.PI/2:0,t?Math.PI:s*Math.PI/2,i,this.axis);return null!==a&&(l.scale=a),l.clip=o,this.singleStyle||(l.style=i8(n)),l})}getFans(e){return this.computedFans.map(({computed:t,traits:i})=>this.makeStyledLine(e,t,i))}getElements(){if(null===this.unit)return[];let[e,t]=this.getReversedScreenPoints(),i=this.getGridLines(e,t);return[...i,...this.getArcs(e),...this.getFans(e)]}getOrientation(){let[e,t]=this.getReversedScreenPoints(),i=t.x<e.x,s=t.y<e.y;return{flipX:i,signX:i?-1:1,flipY:s,signY:s?-1:1}}getClipPath(){let[e,t]=this.getReversedScreenPoints(),i=new Path2D;return iH(i,e,t),i}adornElements(e,t){if(0===e.length)return;let i=(e,i,s)=>{t.fillStyle=s;let r=i.hasScale;r&&(t.save(),i.applyScale(t)),t.fill(e),r&&t.restore()};if(this.showBackground){let s=e.filter(e=>e.radius),r=this.getClipPath();if(t.save(),t.clip(r),this.singleStyle){let e=eC(s);i(gc(null,e),e,this.applyBackgroundOpacity(this.traits.line.color))}else{let e=null;s.forEach(t=>{let s=gc(e,t),r=t.style.fillStyle;i(s,t,r),e=t})}t.restore()}if(this.showRangesRatio&&null!==this.unit){let e=eC(this.computedLevels),i=(this.singleStyle?this:e).traits.line.color,[,s,r,n]=this.getReversedScreenPoints(),{x:a,y:o}=tz.DEFAULT_ADORN_OFFSET,{flipX:l,signX:u,signY:h}=this.getOrientation(),c=iA(r,{x:-a*u,y:o*h}),{priceDiff:d,barsDiff:p}=this.getLinesDataAtLevels(null,null),f=l?Q.Right:Q.Left;iU(t,p.toFixed(0),c,f,i);let m=iA(n,{x:2*a*u,y:-o*h}),g=l?Q.Left:Q.Right;iU(t,this.formatter.format(d,ag.Close),m,g,i);let y=iA(s,{x:-a*u,y:-o*h});iU(t,this.priceBarRatio.toFixed(6),y,f,i)}}resetComputedState(){if(this.lines=void 0,4===this.points.length&&null!==this.unit){let{priceDiff:e,barsDiff:t}=this.getLinesDataAtLevels(null,null);this.priceBarRatio=Math.abs(e/t)}}updateFrom(e,t,i,s,r){if(super.updateFrom(e,t,i,s,r),this._parsedFans=this._parsedArcs=null,!gV(e.priceBarRatio,this.priceBarRatio)){let[t,i,,]=this.points;this.reverse&&([t,i]=[i,t]);let{priceDiff:s,barsDiff:r}=this.getLinesDataAtLevels(null,null);i.update(t.price+Math.sign(s)*e.priceBarRatio*r,i.time),this.resetComputedState()}}getFlipAnchorIndices(){return[0,1]}}class gF extends mb{constructor(e,t){super(e,t),this.addPoints(3)}get extend1(){return this.traits[tz.AT_EXTEND_PT_1]}get extend2(){return this.traits[tz.AT_EXTEND_PT_2]}getElements(){let[e,t,i]=this.getScreenPoints(),{x:s,y:r}=iS(i,e),n=i=>{let[s,r]=[e,t].map(e=>iA(e,i));return new mv(s,r,this.extend1,this.extend2,this.axis)};return this.getColoredElements(({value:e})=>n({x:s*e,y:r*e}))}getTextRef(){return(e,t,i)=>{let s=this.formatLevelPrice(i,t.anchor1.y);return{ref:t,spacing:5,offsetY:!0,text:s}}}adornElements(e,t){this.adornElementsForColoredFactors(e,(e,t)=>{let i=new Path2D;return null===e||(iN(i,e.p1),iV(i,e.p2),iV(i,t.p2),iV(i,t.p1)),i},this.getTextRef(),t)}}class gB extends mC{levelSize=0;alignLeft=!0;totalVolume=!1;widthPercent=30;useChange=!1;studyPlotId;gotData;boxes=[];periodType="VisibleScreen";period=0;valueRangePercent=.7;levelMode="Count";usesFinerGrainedAgg=!0;constructor(e,t,i){super(e,t),this.computed=!0,this.studyPlotId=i,this.gotData=!1}setOptions(e){switch(this.levelMode=e.LevelMode,this.levelSize=e2(1,1e3,e.LevelSize),this.alignLeft="Left"===e.Position,this.totalVolume="Total"===e.Volume,this.widthPercent=e2(5,100,e.WidthPercent)/100,e.BarColoring){case"OpenToClose":this.useChange=!1;break;case"CloseToClose":this.useChange=!0;break;default:{let e=this.presenter.mainPlot?.mainCurve?.attributes;this.useChange=e?.includes(U.ChangeBased)??!1}}eH(e.PeriodType)&&(this.periodType=e.PeriodType),this.period=e.Period,this.valueRangePercent=e.ValueRangePercent/100;let t=er[Sp()?.config.mode??"Unspecified"];this.usesFinerGrainedAgg=sB(t)}get isCountMode(){return"Count"===this.levelMode}updateLastBox(){if(this.boxes.length>0){let e=this.boxes.pop(),t=this.getDataForRange(e.firstDate,e.lastDate);t&&this.boxes.push(t)}}invalidate(e){switch(this.periodType){case"VisibleScreen":this.gotData=!1,this.boxes=[];break;case"Bars":case"Days":switch(e){case"DataPointAdded":{let e=this.studySeries.innCont(0),t=e?.getTimeData();if(!eF(t))return;let i=t[t.length-1],s=this.boxes.length>0?this.boxes[this.boxes.length-1]:null;if(eH(s)&&i.valueOf()<s.lastDate.valueOf())this.updateLastBox();else{let e=this.getDataForRange(i,this.getBoxEndFromStart(i));e&&this.boxes.push(e)}break}case"DataPointChanged":this.updateLastBox();break;case"NewChunkArrived":this.gotData=!1}}}getBoxRect(e){switch(this.periodType){case"VisibleScreen":return this.axis.pane.getBoundsWithoutScales();case"Bars":case"Days":{let t=this.axis.pane.presenter.view.xAxis.xScale.bar,i=this.axis.toY(e.min),s=this.axis.toY(e.max),r=this.axis.pane.presenter.view.toX(e.firstDate)-t.width/2,n=0;if("Days"===this.periodType){let i=e.lastDate,s=this.axis.pane.presenter.view.xAxis.xScale.timeline,a=s.at(s.lastSeriesIndex),o=a.valueOf()<i.valueOf(),l=o?a:i,u=(o?1:-2)*t.width/2;n=this.axis.pane.presenter.view.toX(l)+u-r}else n=this.period*t.width+(this.period-1)*t.spacing;return new iw(r,s,n,i-s)}default:throw Error("Unexpected period type for Volume At Price annotation")}}getElementsForBox(e){let t=this.getBoxRect(e),i=[];if(this.isPeriodic){let e=new mP({x:t.x,y:t.y},t.width,t.height,this.axis);e.style=this.backgroundStyle,i.push(e)}let{x:s,width:r}=t,n=r*this.widthPercent,a=e.bars[e.maxVolumeIndex];return e.bars.forEach((t,o)=>{let{upVolume:l,downVolume:u,totalVolume:h,isValue:c}=t;if(0===l&&0===u)return null;let d=this.axis.toY(e.min+o*e.zone),p=this.axis.toY(e.min+(o+1)*e.zone),f=Math.abs(d-p),m=(e,t,i=0)=>{let n=new mP({x:this.alignLeft?s+i:s+r-e-i,y:p},e,f,this.axis);return n.style=t,n},g=(e,t,i)=>e/t.totalVolume*i,y=this.studyPlot.curves[2].visible,S=y&&c?this.upValueStyle:this.upStyle,A=y&&c?this.downValueStyle:this.downStyle,T=y&&c?this.totalValueStyle:this.totalStyle;if(this.totalVolume){let e=g(h,a,n);i.push(m(e,T))}else{let e=g(u,a,n),t=g(l,a,n);i.push(m(t,S),m(e,A,t))}if(this.studyPlot.curves[1].visible&&o===e.maxVolumeIndex){let e=i[i.length-1].rect,t=this.alignLeft?e.x+e.width:s,n=(p+d)/2,a=this.alignLeft?s+r:e.x;i.push(new mv({x:t,y:n},{x:a,y:n},!1,!1,this.axis))}}),i}get isVisible(){return this.studyPlot.visible&&this.studyPlot.mainCurve.visible}getElements(){if(this.gotData||this.getData(),!this.gotData||!this.isVisible||0===this.boxes.length)return[];switch(this.periodType){case"VisibleScreen":{let e=this.boxes[0];if(!e||0===e.bars.length)return[];return this.getElementsForBox(e)}case"Bars":case"Days":{let[e,t]=this.presenter.view.xAxis.xScale.domain()||[];if(!oC(e)||!oC(t))return[];let i=this.boxes.findIndex(t=>t.firstDate.getTime()<=e.getTime()&&t.lastDate.getTime()>=e.getTime());-1===i&&(i=0,this.studySeries.loadMoreData());let s=this.boxes.findIndex(e=>e.firstDate.getTime()<=t.getTime()&&e.lastDate.getTime()>=t.getTime());-1===s&&-1!==i&&(s=this.boxes.length-1);let r=[];for(let e=i;e<=s;e++)r.push(...this.getElementsForBox(this.boxes[e]));return r}default:throw Error("Unexpected period type for Volume At Price annotation")}}getStyleForElement(e,t){return e.style||super.getStyleForElement(e,t)}get presenter(){return this.axis.pane.presenter}get downStyle(){return this.fillOnlyStyle(tz.AT_FILL)}get upStyle(){return this.fillOnlyStyle(tz.AT_FILL2)}get totalStyle(){return this.fillOnlyStyle(tz.AT_FILL3)}get downValueStyle(){return this.fillOnlyStyle(tz.AT_FILL4)}get upValueStyle(){return this.fillOnlyStyle(tz.AT_FILL5)}get totalValueStyle(){return this.fillOnlyStyle(tz.AT_FILL6)}get backgroundStyle(){return this.fillOnlyStyle(tz.AT_FILL7)}get lineStyle(){return this.lineOnlyStyle(tz.AT_LINE)}getBoxEndFromStart(e){switch(this.periodType){case"VisibleScreen":default:return null;case"Days":return oE(lQ(G.Day,this.period)(e),1);case"Bars":{let t=this.axis.pane.presenter.data.aggregation;return oE(lQ(t.unit,t.size*this.period)(e),1)}}}getData(){let e=this.axis.pane.presenter.data.aggregation;if(e.isTick||e.hasSpec&&!pG(e.spec))return;let[t,i]=this.presenter.view.xAxis.xScale.domain()||[];if(!oC(t)||!oC(i))return;let s=lQ(e.unit,e.size);switch(this.periodType){case"VisibleScreen":{let e=this.boxes[0];if(e&&e.firstDate===t&&e.lastDate===i)this.gotData=!0;else{let e=this.getDataForRange(t,i);e&&(this.boxes[0]=e)}break}case"Bars":{let[e,t]=[0,1].map(e=>this.studySeries.innCont(e));if((e?.size??0)<1||(t?.size??0)<1)return;let i=e.getTimeData(),r=0;for(this.boxes=[];r<i.length;){let e=i[r],t=r+this.period,n=oE(t<i.length?i[t]:s(i[i.length-1]),1),a=this.getDataForRange(e,n);a&&this.boxes.push(a),r+=this.period}this.gotData=!0;break}case"Days":{if(e.isEndOfDay){this.boxes=[],this.gotData=!0;return}let[t,i]=[0,1].map(e=>this.studySeries.innCont(e));if((t?.size??0)<1||(i?.size??0)<1)return;let r=t.getTimeData(),n=t.getData(ag.TradingDay),a=e=>{let t=0,i=r[e],s=n[e];for(let a=e;a<r.length;a++)if(tu(r[a],i)>0&&n[a]!==s&&(t+=1,i=r[a],s=n[a],t===this.period))return a;return -1},o=0,l=r[0],u=a(o)-1;for(;(u<0||u===o)&&o<r.length;)o+=1,u=a(o)-1;for(this.boxes=[];o<r.length&&u<r.length&&o<u;){let e=oE(s(r[u]),1),t=this.getDataForRange(l,e);t&&this.boxes.push(t),l=r[o=u+1],u=a(o)-1}if(u<0&&o<r.length-1){let e=oE(s(r[r.length-1]),1),t=this.getDataForRange(r[o],e);t&&this.boxes.push(t)}this.gotData=!0}}}getBoxAt(e){if(0===this.boxes.length)return null;switch(this.periodType){case"VisibleScreen":{let t=this.boxes[0];if(t.firstDate>e||t.lastDate<e)return null;return t}case"Bars":case"Days":{let t=e.getTime(),i=this.boxes.find(e=>e.firstDate.getTime()<=t&&e.lastDate.getTime()>=t);if(!i)return null;return i}}}getValueAt(e,t,i){if(!this.isVisible)return null;let s=this.getBoxAt(t);if(!s)return null;let r=this.getBarIndex(s,i);if(r<0||r>=s.bars.length)return null;let n=s.bars[r];switch(e){case ag.UPVOL:return this.totalVolume?null:n.upVolume;case ag.DNVOL:return this.totalVolume?null:n.downVolume;case ag.TOTVOL:return this.totalVolume?n.totalVolume:null;case ag.POC:case ag.VAREA:case ag.BARBACK:return null;default:throw Error("Unexpected Volume At Price field")}}getBarIndex(e,t,i=!1){if(0===e.bars.length||0===e.zone)return -1;let s=Math.floor((t-e.min)/e.zone);return i?Math.min(e.bars.length-1,s):s}get studyPlot(){return this.presenter.allPlots.find(e=>e.id===this.studyPlotId)}get studySeries(){return this.studyPlot.timeSeries}makeBox(e,t){return{min:Number.MAX_VALUE,max:5e-324,zone:0,bars:[],maxVolumeIndex:-1,firstDate:e,lastDate:t}}findExtremes(e,t,i,s,r,n){let a=eH(r)&&eH(n);for(let o=t;o<=i;o++)if(a){let t=r[o];t>e.max&&(e.max=t);let i=n[o];i<e.min&&(e.min=i)}else{let t=s[o];t<e.min&&(e.min=t),t>e.max&&(e.max=t)}}findValueArea(e){if(-1===e.maxVolumeIndex||0===e.bars.length)return;e.bars[e.maxVolumeIndex].isValue=!0;let t=em(e.bars.map(e=>e.totalVolume))*this.valueRangePercent,i=e.bars[e.maxVolumeIndex].totalVolume,s=e.maxVolumeIndex,r=e.maxVolumeIndex;for(;i<t;){let n=[{dir:"lower",count:2,startIdx:s-2,endIdx:s-1},{dir:"lower",count:1,startIdx:s-1,endIdx:s-1},{dir:"upper",count:2,startIdx:r+1,endIdx:r+2},{dir:"upper",count:1,startIdx:r+1,endIdx:r+1}].filter(t=>t.startIdx>=0&&t.endIdx<e.bars.length).map(t=>{let s=em(e.bars.slice(t.startIdx,t.endIdx+1).map(e=>e.totalVolume));return{...t,volume:s,newTotal:i+s}});if(0===n.length)break;let a=(e,t)=>t.newTotal<e.newTotal?t:e,o=(e,t)=>t.volume>e.volume?t:e,l=n.filter(e=>e.newTotal>=t),u=l.length>0?l.reduce(a):n.reduce(o);for(let t=u.startIdx;t<=u.endIdx;t++)e.bars[t].isValue=!0;if("lower"===u.dir?s=u.startIdx:r=u.endIdx,(i=u.newTotal)>=t)break}}tallyVolume(e,t,i,s,r,n,a){let o=5e-324,l=!1;for(let u=t;u<=i;u++){let t=r[u],i=this.getBarIndex(e,t,!0);if(-1===i){l=!0;break}let h=a[u],c=this.useChange?n[u]>=0:s[u]<=r[u],d=e.bars[i];c?d.upVolume+=h:d.downVolume+=h,d.totalVolume=d.downVolume+d.upVolume,d.totalVolume>o&&(o=d.totalVolume,e.maxVolumeIndex=i)}l||this.findValueArea(e)}get isPeriodic(){return"Bars"===this.periodType||"Days"===this.periodType}get isVisibleScreen(){return"VisibleScreen"===this.periodType}getDataForRange(e,t){let i=this.makeBox(e,t),s=this.studySeries.innCont(1),r=s?.getTimeData();if(!eF(r))return null;let n=e=>e_(r,+e,Number),a=n(e),o=n(t);if(r[o].getTime()>t.getTime()&&(o-=1),a>o)return null;if(this.axis.pane.presenter.data.aggregation.unit===G.Day&&"Bars"===this.periodType){let e=s.getData(ag.TradingDay),t=e[a];for(;t===e[a]&&a>0;)a-=1;a+=1;let i=0;for(o=a;o<r.length&&i<this.period;)e[o]!==t&&(i+=1,t=e[o]),o+=1;o-=2}this.isVisibleScreen&&this.usesFinerGrainedAgg&&a<1e3&&this.studySeries.loadMoreData();let[l,u,h,c,d,p]=["Open","High","Low","Close","Change","Volume"].map(e=>{let t;return t=ag[e],s.getData(t)});this.findExtremes(i,a,o,c,u,h);let f=i.max-i.min,m=e=>({upVolume:0,downVolume:0,isValue:!1,totalVolume:0});if(this.isCountMode)i.zone=f/this.levelSize,i.bars=ex(this.levelSize,m);else{let e=Math.max(1,Math.ceil(f/((this.presenter.mainPlot?.metaData.minMovement??1)*this.levelSize)));i.zone=f/e,i.bars=ex(e,m)}return this.tallyVolume(i,a,o,l,c,d,p),this.gotData=!0,i}}class gk extends mC{studyPlotId;constructor(e,t,i){super(e,t),this.studyPlotId=i}get studyPlot(){return this.presenter.allPlots.find(e=>e.id===this.studyPlotId)}get studySeries(){return this.studyPlot.timeSeries}getElements(){if(!this.studyPlot.visible||!this.studyPlot.mainCurve.visible)return[];let e=this.studySeries.getCurrentState();if(!e)return[];let t=e.confirmedPivots,i=Array.from(t.keys()).sort((e,t)=>e-t);if(0===i.length)return[];let s=this.presenter.mainPlot?.timeSeries?.container;if(!s||s.size<2)return[];let r=s.getTimeData();if(!r)return[];let n=this.presenter.view,[a,o]=n.xAxis.xScale.domain()||[];if(!a||!o)return[];let l=a.getTime(),u=o.getTime(),h=-1,c=-1;for(let e=0;e<i.length;e++){let t=r[i[e]].getTime();if(-1===h&&t>=l&&(h=Math.max(0,e-1)),t<=u)c=e;else if(-1!==h)break}if(-1===h){if(i.length>0&&r[i[0]].getTime()>u)return[];h=i.length-1,c=i.length-1}else -1===c&&(c=h);c=Math.min(i.length-1,c+1);let d=[];for(let e=h;e<c;e++){let s=i[e],a=i[e+1],o=n.toX(r[s]),l=this.axis.toY(t.get(s)),u=n.toX(r[a]),h=this.axis.toY(t.get(a));d.push(this.makeLine({x:o,y:l},{x:u,y:h}))}if(eF(e.pivotPrice)&&eF(e.candPrice)){let t=r[e.pivotIndex].getTime();if(r[e.candIndex].getTime()>=l&&t<=u){let t=n.toX(r[e.pivotIndex]),i=this.axis.toY(e.pivotPrice),s=n.toX(r[e.candIndex]),a=this.axis.toY(e.candPrice);d.push(this.makeLine({x:t,y:i},{x:s,y:a}))}}return d}}function gW(e){let t=Math.abs(e)/Math.SQRT2,i=1/(1+.3275911*t);return .5*(1+(e<0?-1:1)*(1-((((1.061405429*i+-1.453152027)*i+1.421413741)*i+-.284496736)*i+.254829592)*i*Math.exp(-t*t)))}class gU extends mC{studyPlotId;periodTarget=0;targetPrice1=0;targetPrice2=0;pricesCount=0;targetDate;computed=!1;anchorPrice=0;sigmaAnnualized=0;unitsPerYear=0;probabilityAbove=0;probabilityBelow=0;probabilityBetween=0;styles=[];constructor(e,t,i){super(e,t),this.studyPlotId=i}makeStyles(){let e=this.lineOnlyStyle(tz.AT_LINE),t=this.lineOnlyStyle(tz.AT_LINE_2);this.styles=[e,t,t]}containerOf(e){return e?.timeSeries.container}get mainCont(){return this.containerOf(this.presenter.mainPlot)}get studyCont(){return this.containerOf(this.studyPlot)}get studyPlot(){return this.presenter.allPlots.find(e=>e.id===this.studyPlotId)}get targetPrice(){return 0!==this.targetPrice1?this.targetPrice1:this.targetPrice2}setOptions(e){if(this.periodTarget=e.PeriodTarget,this.targetPrice1=e.TargetPrice1,this.targetPrice2=e.TargetPrice2,this.pricesCount=+(0!==this.targetPrice1)+ +(0!==this.targetPrice2),this.pricesCount>1&&this.targetPrice1<this.targetPrice2){let e=this.targetPrice1;this.targetPrice1=this.targetPrice2,this.targetPrice2=e}}get haveInput(){return 0!==this.periodTarget&&(0!==this.targetPrice1||0!==this.targetPrice2)}get haveData(){return eH(this.mainCont)&&!this.mainCont.isEmpty&&this.studySeries.haveVolatility}get studySeries(){return this.studyPlot.timeSeries}getData(){let e=this.presenter.timeline;this.targetDate=e.at(e.lastSeriesIndex+this.periodTarget),this.points=[new mm(this.axis,this.targetPrice,this.targetDate)],this.pricesCount>1&&this.points.push(new mm(this.axis,this.targetPrice2,this.targetDate)),this.unitsPerYear=f0(this.presenter.data.aggregation),this.anchorPrice=this.mainCont.getLastDataPoint(ag.Close),this.sigmaAnnualized=this.studySeries.getVolatilityPercent()}computeProbabilities(){let e=this.sigmaAnnualized*Math.sqrt(this.periodTarget/this.unitsPerYear),t=t=>(t-this.anchorPrice)/(this.anchorPrice*e),i=gW(t(this.targetPrice));if(this.pricesCount>1){let e=gW(t(this.targetPrice2));this.probabilityAbove=1-i,this.probabilityBelow=e,this.probabilityBetween=i-e}else this.probabilityBelow=i,this.probabilityAbove=1-this.probabilityBelow;this.computed=!0}compute(){this.haveInput&&this.haveData&&(this.getData(),this.computeProbabilities())}getElements(){if(this.computed||this.compute(),!this.computed||!this.studyPlot.mainCurve.visible)return[];let e=[];return e.push(new mf(this.points[0].point,!0,this.axis)),e.push(new mf(this.points[0].point,!1,this.axis)),this.pricesCount>1&&e.push(new mf(this.points[1].point,!1,this.axis)),e}getStyleForElement(e,t){return this.styles.length||this.makeStyles(),this.styles[t]}get hasPoint(){return this.points.length>0}getTimeScaleAdornments(){return this.hasPoint?[{time:this.points[0].time,color:this.traits.line.color}]:[]}getPriceScaleAdornments(){if(!this.hasPoint)return[];let e=[];return e.push({price:this.points[0].price,color:this.traits.line2.color}),this.pricesCount>1&&e.push({price:this.points[1].price,color:this.traits.line2.color}),e}adornElements(e,t){if(this.computed){let[e,i]=[!0,!1].map(e=>Math.abs(iB(t,e))),s=this.pricesCount>1,r=this.points[0].point,n=s?this.points[1].point:r,a=this.traits.line2.color,o=iI(a),l=iF(t),u=["Above","Below","Between"],h=(e,t)=>`${eB(100*e,2).toFixed(2)}% Probability ${u[t]}`,c=(e,i)=>iU(t,e,i,Q.Right,o,a);if(c(h(this.probabilityAbove,0),{x:r.x-10,y:r.y-e}),s){let e=r.y+(n.y-r.y+l)/2;c(h(this.probabilityBetween,2),{x:r.x-10,y:e})}c(h(this.probabilityBelow,1),{x:n.x-10,y:n.y+i})}}}let g$=new class{resizingPanes=!1;snapToSupported=!1;touchCrosshairMode=!1;notifyZoomChanged;previousTouchTimestamp=null;resizingScale=!1;resizingScaleId=null;lastScaleResizingOffset=null;touchCrosshairTimeout=null;lastResizingOffset=null;splitter;prevZoomingOffset;prevPinchDistance=null;constructor(){this.stopResizingScale(),this.notifyZoomChanged=eV(ay.CH_ZOOMCHANGED,1e3)}startTouchCrosshairMode(e,t,i){this.touchCrosshairMode=!0,this.showCrosshairAndTooltips(e.view,t,i)}activated(){}deactivated(){}findHit(e){let t;if(!e.point)return[];if(e.axis.pane.axes.some(t=>t.plots.some(t=>t.hitTestCustomEvent(e.point))))return tz.EVENT_PIN_HIT;let i=e.presenter.selectedAnnotation;void 0!==i&&(t=i.points.find(t=>t.hitTest(e.point)));let s=eC(e.axis.annotations.filter(t=>t.computed?null:t.hitTest(e.point)));return void 0!==t&&null==s&&(s=i),[s,t]}stopResizingScale(){this.resizingScale=!1,this.resizingScaleId=null,this.lastScaleResizingOffset=null}resetVerticalAxis(e,t=!0){this.stopResizingScale(),e.isCustomDomain=!1,t&&e.setDomain()}resetHorizontalAxis(e,t=!0){e.view.xAxis.resetZoom(),t&&e.view.setPriceAxesDomains(),this.fireZoomChanged(e)}fireZoomChanged(e){this.notifyZoomChanged({chart:e.accessor})}onMouseDblClick({priceAxis:e,offset:t,presenter:i,view:s}){let r=s.xAxis.viewBox.contains(t),n=!1;if(eF(e))this.resetVerticalAxis(e),n=!0;else if(r)this.resetHorizontalAxis(i),n=!0;else if(eO()){let e=i.selectedAnnotation;null!=e?m2(e,t):m3(i,t)}n&&s.redraw()}onMouseEnter(){this.previousTouchTimestamp=null}computePreviousTouchStartDuration(){if(!eO())return null;let e=new Date().getTime(),t=eF(this.previousTouchTimestamp)?e-this.previousTouchTimestamp:null;return this.previousTouchTimestamp=e,t}onMouseDown(e){let{point:t,button:i,splitter:s,offset:r,priceAxis:n,presenter:a,originalEvent:o}=e,l=window.navigator.platform.toLowerCase().startsWith("mac"),u=l?ei.Meta:ei.Control,h=i===et.Right||l&&i===et.Left&&e.getModifier(ei.Control);this.touchCrosshairMode&&eF(this.touchCrosshairTimeout)&&(clearTimeout(this.touchCrosshairTimeout),this.touchCrosshairTimeout=null);let c=this.computePreviousTouchStartDuration();if(eF(c)&&c<tz.DOUBLE_CLICK_DURATION_MILLIS)return this.onMouseDblClick(e),!0;if(!h&&this.isLogoLink(r)&&a.notifyHost(ay.CH_LOGOCLICKED,{chart:a.accessor}),eF(t)&&a.allPlots.some(e=>e.tryHandleCustomEventClick(t.point)))return!0;if(eF(s))return this.resizingPanes=!0,this.lastResizingOffset=r,this.splitter=s,a.enableTooltip(!1),!0;if(eF(n))return eW(a.display.chart.zooming)[0]&&this.startAxisScaling(n,r),!0;if(null!=t){if(e.getModifier(u))return a.activeTool=new m1,a.activeTool.onMouseDown(e),!0;let[i,s]=this.findHit(t);if(a.clearSelection(),null!=i&&a.setSelection(i),null==i||i?.locked)return h?(this.hideCrosshairAndTooltips(a.view),null==i?m3(a,r,o):i?.locked&&m2(i,r),!0):!!this.touchCrosshairMode||(a.activeTool=new mX(t),a.activeTool.startPan(r),mq());let n=null!=s;return h?(m2(i,r),eO()):(!n||!!s.movable)&&(!!n||!!i.canMove(t.point))&&(a.activeTool=n&&-1!==i.points.indexOf(s)?new mp(i,s):new md(i,t,r),eO())}return this.prevZoomingOffset=r,!1}onContextMenu(e){return!0}isLogoLink(e){let t=eH(mZ)&&mZ.logoClickable?mZ.rect:null;return eF(t)&&t.contains(e)}onMouseMove(e){let{point:t,splitter:i,priceAxis:s,view:r,presenter:n,offset:a}=e;if(eF(e.pinchZoom)&&e.pinchZoom&&eF(e.pinchDistance))return eF(this.prevPinchDistance)&&(e.delta=this.prevPinchDistance-e.pinchDistance,this.onWheel(e)),this.prevPinchDistance=e.pinchDistance,eO();if(null!=i||this.resizingPanes)r.setCursor(ee.ResizeVertical),this.resizingPanes&&this.resizePanes(r,a);else if(eF(t)){let[e,i]=this.findHit(t);eF(i)?t.presenter.view.setCursor(ee.Crosshair):eF(e)?e.isSelected?t.presenter.view.setCursor(ee.Move):t.presenter.view.setCursor(ee.Hand):t.presenter.view.setCursor(ee.Arrow)}else if(eF(s))eW(n.display.chart.zooming)[0]&&(r.setCursor(ee.ResizeVertical),this.performAxisScaling(r,s,a));else{if(this.prevZoomingOffset){let{x:e}=this.prevZoomingOffset,{x:t}=a;this.applyZoom(r.presenter,-(e-t)),this.prevZoomingOffset=a}r.setCursor(ee.ResizeHorizontal)}return!t||this.resizingPanes?this.hideCrosshairAndTooltips(r):(this.isLogoLink(a)&&r.setCursor(ee.Hand),this.showCrosshairAndTooltips(r,t,a)),eO()}showCrosshairAndTooltips(e,t,i){t.time&&(!eO()||this.touchCrosshairMode)&&e.drawCrosshair({ap:t,offset:i})&&e.presenter.showTooltip&&mz(e.presenter,{time:t.time,offset:i,price:t.price,lastBarRefresh:void 0,justMain:void 0})}hideCrosshairAndTooltips(e,t=!1){e.drawCrosshair({ap:void 0}),e.tooltip.hide(),e.presenter.hideCards(t),t&&"cards"===e.tooltip.mode&&!e.presenter?.hasLegend&&mG(e.presenter)}onMouseLeave(e){let{view:t,offset:i}=e,s=t.presenter.accessor.getPaneBounds();s?.every(e=>!e.contains(i)||i.x===e.x||i.x===e.x+e.width||i.y===e.y||i.y===e.y+e.height)&&(this.hideCrosshairAndTooltips(t,!0),this.stopResizeZoom(t.presenter)),t.setCursor(ee.Arrow),this.touchCrosshairMode=!1}stopResizeZoom(e){this.resizingPanes&&(this.resizingPanes=!1,e.enableTooltip(!0),e.onPaneHeightsUpdated()),this.resizingScale&&this.stopResizingScale(),this.prevZoomingOffset&&delete this.prevZoomingOffset}onMouseUp({presenter:e}){if(this.stopResizeZoom(e),eO()){let t=function(){let e=Sp().config.touchCrosshairTimeoutMillis;return eF(e)&&Number.isFinite(e)?e:tz.LONG_PRESS_TIMEOUT_MILLIS}();this.touchCrosshairTimeout=window.setTimeout(()=>{this.hideCrosshairAndTooltips(e.view,!0),this.touchCrosshairMode=!1},t)}}applyZoom(e,t,i=!0){if(!eW(e.display.chart.zooming)[1])return;let s=Math.sign(t)*(eO()?2:10),r=e.view;r.xAxis.zoom(s)&&(r.setPriceAxesDomains(),r.redraw(),i&&this.fireZoomChanged(e))}onWheel({view:e,presenter:t,getModifier:i,delta:s}){let{scrollBehavior:r}=t.display;return!!(eO()?"none"!==r:"wheel"===r||"wheel+shift"===r&&i(ei.Shift))&&0!==s&&(e.drawCrosshair({ap:void 0}),e.tooltip.hide(),e.presenter.hideCards(),this.applyZoom(t,s),!0)}get useKeyboardShortcuts(){return Sp().config.hostingModel!==eo[eo.Application]}onKeyDown(e){let{key:t,code:i,presenter:s}=e;if(eF(s.selectedAnnotation)&&("Backspace"===t||"Delete"===t||8===i||46===i)){let e=s.selectedAnnotation;e.axis.deleteAnnotation(e),s.onAnnotationModifiedByTool(e,el.Deleted)}if(eF(s.selectedAnnotation)&&(ew(t,i)?s.clearSelection():("F2"===t||113===i)&&s.selectedAnnotation instanceof mD&&s.selectedAnnotation.textEditable&&(s.activeTool=new mH(null,s.selectedAnnotation),s.activeTool.startEditing())),eR(t,i)||"ArrowRight"===t||39===i){let e=eR(t,i)?1:-1,r=s.view;r.xAxis.pan(e*r.xAxis.xScale.bar.totalWidth),this.hideCrosshairAndTooltips(r),r.redraw()}let r=window.navigator.platform.toLowerCase().startsWith("mac")?ei.Meta:ei.Control;if(e.getModifier(r)&&this.useKeyboardShortcuts){let e="z"===t||90===i,r="y"===t||89===i;return e&&s.undoRedoManager.undo(),r&&s.undoRedoManager.redo(),e||r}("r"===t||82===i)&&e.getModifier(ei.Alt)&&this.resetView(s)}resetView(e){e.allAxes.forEach(e=>this.resetVerticalAxis(e,!1)),this.resetHorizontalAxis(e,!1),e.view.xAxis.goToLatest(!0)}resizePanes(e,t){let i=t.y-this.lastResizingOffset.y;if(0===i)return;let s=e.presenter.panes,[r,n]=this.splitter,a=s.map((e,t)=>{let s=e.getBounds().height;return t===r?s+i:t===n?s-i:s});if(a.some(e=>e<tz.MINIMUM_PANE_HEIGHT))return;let o=(e,t)=>e+t,l=a.reduce(o,0),u=s.map(e=>e.height).reduce(o,0);s.forEach((e,t)=>e.height=eB(a[t]/l*u,4)),this.lastResizingOffset=t,e.recalculateLayout(),e.redraw()}startAxisScaling(e,t){this.resizingScale=!0,this.resizingScaleId=e.id,this.lastScaleResizingOffset=t}performAxisScaling(e,t,i){if(this.resizingScale&&this.resizingScaleId===t.id){let s=eO()?4:5,r=function(e,t,i,s=1,r=-1){let n=(i.y-t.y)/10,a=e.yScale.rangeWithPadding().reverse();return[a[0]+n*s,a[1]+n*r].map(t=>e.yScale.yToPrice(t))}(t,this.lastScaleResizingOffset,i,s,-s);this.lastScaleResizingOffset=i,t.isCustomDomain=!0,t.yScale.domain(r),e.redraw()}}},gG=e=>gX(m4,gT,1,e),gz=e=>gX(m4,mO,1,e),gY={Default:()=>function(){return g$},Line:()=>gX(mR,ge,!1),DateRange:()=>gX(mR,gD,!1),PriceRange:()=>gX(mR,gO,!1),DatePriceRange:()=>gX(mR,gw,!1),GannBox:()=>gX(mR,gR,!1),GannSquare:()=>gX(mV,gH),Ray:()=>gX(mR,ge,!1),GannLine:()=>gX(mN,ge,!1),VerticalLine:()=>gX(m4,gt,1),HorizontalLine:()=>gX(m4,gi,1),LongPosition:()=>gX(m4,gb,1,!0),ShortPosition:()=>gX(m4,gb,1,!1),FiftyPercentLine:function(e,t){return eF(e)?gX(m5,gs,e.axis||t.mainAxis,e):gX(m4,gs,2)},FibonacciRetracement:()=>gX(mR,gn,!1),TrendBasedFibExtension:()=>gX(mR,ga,!0),FibonacciFan:()=>gX(mR,gu,!1),FibonacciArcs:()=>gX(mR,gp,!1),FibonacciChannel:()=>gX(mR,gF,!0),GannFan:()=>gX(mR,gf,!1),SpeedResistanceFan:()=>gX(mR,gm,!1),SpeedResistanceArcs:()=>gX(mR,gg,!1),AndrewsPitchfork:()=>gX(m4,gy,3),Rectangle:()=>gX(mR,mJ,!1),Ellipse:()=>gX(mR,gS,!1),TrendChannel:()=>gX(mR,gA,!0),SymbolArrowUp:()=>gG("arrow_up"),SymbolArrowDown:()=>gG("arrow_down"),SymbolArrowRight:()=>gG("arrow_right"),SymbolArrowLeft:()=>gG("arrow_left"),SymbolArrowHorizontal:()=>gG("arrow_horizontal"),SymbolArrowVertical:()=>gG("arrow_vertical"),SymbolArcDown:()=>gG("arc_down"),SymbolArcUp:()=>gG("arc_up"),SymbolThumbsUp:()=>gG("thumbs_up"),SymbolThumbsDown:()=>gG("thumbs_down"),SymbolZero:()=>gG("zero"),SymbolOne:()=>gG("one"),SymbolTwo:()=>gG("two"),SymbolThree:()=>gG("three"),SymbolFour:()=>gG("four"),SymbolFive:()=>gG("five"),SymbolSix:()=>gG("six"),SymbolSeven:()=>gG("seven"),SymbolEight:()=>gG("eight"),SymbolNine:()=>gG("nine"),SymbolQuestion:()=>gG("question"),SymbolFishHook:()=>gG("fish_hook"),SymbolBuy:()=>gG("buy"),SymbolSell:()=>gG("sell"),FibonacciTimeZones:()=>gX(mR,gv,!1),Text:()=>gX(mH,mD,null),PickPoint:()=>function(){return new gP},ZoomIn:()=>function(){return new m1},ProfitLoss:gz,RewardRisk:gz,VolumeAtPrice:function(e){return gX(m4,gB,2,e)},ZigZag:function(e){return gX(m5,gk,null,e)},ProbabilityCones:function(e){return gX(m4,gU,2,e)}};function gj(e,t=!1,i=null,s=null,r=null){let n=gY[e];return(n=n(s,r))(e,t,i)}function gK(e,t={}){e.enableTooltip(!0),e.resetActiveTool();let{axis:i,annotation:s,toolChange:r,annId:n}=t;eF(i)&&e.onAnnotationsUpdated(i),eF(s)&&e.onAnnotationModifiedByTool(s,r),[el.Cancelled,el.Executed,el.TextChanged].includes(r)&&e.onAnnotationDone(n,r)}function gq(e,t=!0,i=el.None){e.wasModifiedByTool();let s=e.axis;gK(s.pane.presenter,t?{axis:s,annotation:e,toolChange:i}:void 0)}function gX(e,t,i,s){return function(r,n,a){let o=mT(r,t,s,a);return(o.annName=r,n)?o:new e(o,i)}}function gZ(e){e.button===et.Right&&gK(e.presenter)}function gJ(e,t,i){let s={};s.source=ag[e.source],s.inputs=eK(e.inputs);let r=void 0!==e.target,n=eF(i)?i:e.curves;return s.outFields=function(e){let t=[];for(let i of e)t.includes(i)||t.push(i);return t}(r?[ag[e.target]]:n.map(e=>e.fields).flat()),s.target=r?ag[e.target]:s.outFields[0],s.aggregation=t,s}class gQ extends mo{model;basePlot;_hasEvents;_params;_shiftFmt;_title;range;shouldMaybePriceMap;annIndex;_canPriceMap;#e(e=3){let t=this.model.inputs||[],i=t.length;if(0===i)return"";let s="";i>e&&(t=t.slice(0,3),s=", ...");let r="AVWAP"===this.model.study;return 0===t.length?"":`(${t.map(e=>r&&"Anchor"===e.name?new Date(e.value).toLocaleString():e.value).join(", ")}${s})`}get params(){return eF(this._params)||(this._params=this.#e()),this._params}get fullParams(){return this.#e(Number.MAX_VALUE)}get shiftFmt(){if("PC"===this.model.study)return"";if(!eF(this._shiftFmt)){let e=this.curves.map(e=>Number(e.shift)).filter(e=>0!==e);this._shiftFmt=0===e.length?"":`[${e.join(", ")}]`}return this._shiftFmt}get title(){if(!eF(this._title)){let e=this.params,t=this.shiftFmt;this._title=`${this.model.study} ${e} ${t}`.trim()}return this._title}fromModel(e){this.model=e,super.fromModel(this.model)}getMetaData(){let e=sR(this.model.study),t=e.meta.decimals;this.metaData=void 0!==t?new ii(t):this.basePlot.metaData,eF(e.meta.range)&&(this.range=e.meta.range)}getDetachedScaleMargins(){return"VOL"===this.model?.study&&this.axis?.pane.isMain?tz.VOLUME_DETACHED_SCALE_MARGINS:super.getDetachedScaleMargins()}applySpecifics(e){let t=this.model.study;!0===sR(t).meta.shiftable&&this.curves.forEach(t=>{Number.isFinite(e.inputs.Offset)&&(t.shift=e.inputs.Offset)});let i=(e,t,i)=>this.curves[e].zones[t].value=this.model.levels[i].value;switch(t){case"ICHCLD":{let t=e.inputs.Displacement;this.curves[2].shift=-t,this.curves[3].shift=t,this.curves[4].shift=t,this.curves[5].shift=t;break}case"MARIB":{let t=Math.min(Math.max(0,e.inputs.Count),10);this.curves.forEach((e,i)=>e.visible=e.visible&&i<t);break}case"CRS":{let t="PercentChange"===e.inputs.Display;this.axis.comparison=t?q.Percent:q.None;break}case"PERF":{let t="VisibleStart"===e.inputs.Anchor;this.axis.comparison=t?q.Percent:q.None;break}case"JPI":case"CTTP":case"CTTI":{let t=ex(10,e=>(e+1)*.025),i=([e,i])=>[...t.map(t=>i_(t)(e)).reverse(),i,"#6a4a3a","#a000c8","#ffffff"];this.curves[0].colors=i(this.curves[0].colors),this.curves[1].colors=i(this.curves[1].colors);let s=this.curves[0].colors.length;this.curves[0].colors[s-1]=this.curves[1].colors[t.length],this.curves[1].colors[s-1]=this.curves[0].colors[t.length],this.shouldMaybePriceMap="Performance"===e.inputs.Height;break}case"RSI":case"RSIMOD":case"RSISTO":case"CCI":i(0,0,0),i(0,1,2);break;case"STC":i(0,0,0),i(0,1,1);break;case"RVOL":case"DPO":case"COPP":i(0,0,0);break;case"VOL":this.setCurveAttributes(0,e.inputs.BarColoring);break;case"MAVOL":this.setCurveAttributes(1,e.inputs.BarColoring);break;case"VOLAP":{this.notifyAboutPriceDomains=!0,this.customPlotValues=!0,eF(this.annotations)||(this.annotations=[]);let t=this.curves[1],i=this.curves[2],s=gj("VolumeAtPrice",!0,{[tz.AT_LINE]:{color:t.colors[0],width:t.lineWidth,dashStyle:t.dashStyle},[tz.AT_FILL]:{color:this.curves[0].colors[0]},[tz.AT_FILL2]:{color:this.curves[0].colors[1]},[tz.AT_FILL3]:{color:this.curves[0].colors[2]},[tz.AT_FILL4]:{color:i.colors[0]},[tz.AT_FILL5]:{color:i.colors[1]},[tz.AT_FILL6]:{color:i.colors[2]}},this.id)(this.axis,!1);s.setOptions(e.inputs),this.annIndex=this.annotations.push(s)-1;break}case"PVACP":{this.customPlotValues=!0,eF(this.annotations)||(this.annotations=[]);let t=this.curves[1],i=this.curves[2],s=this.curves[3],r=gj("VolumeAtPrice",!0,{[tz.AT_LINE]:{color:t.colors[0],width:t.lineWidth,dashStyle:t.dashStyle},[tz.AT_FILL]:{color:this.curves[0].colors[0]},[tz.AT_FILL2]:{color:this.curves[0].colors[1]},[tz.AT_FILL3]:{color:this.curves[0].colors[2]},[tz.AT_FILL4]:{color:i.colors[0]},[tz.AT_FILL5]:{color:i.colors[1]},[tz.AT_FILL6]:{color:i.colors[2]},[tz.AT_FILL7]:{color:s.colors[0]}},this.id)(this.axis,!1);r.setOptions(e.inputs),this.annIndex=this.annotations.push(r)-1;break}case"ZIGZAG":{this.customPlotValues=!0,eF(this.annotations)||(this.annotations=[]);let e=gj("ZigZag",!0,{[tz.AT_LINE]:{color:this.curves[0].colors[0],width:this.curves[0].lineWidth,dashStyle:this.curves[0].dashStyle}},this.id)(this.axis,!1);this.annIndex=this.annotations.push(e)-1;break}case"IVRANK":{let t=ag.ImplVolRank1Y;switch(e.inputs.TimeFrame){case"1-Year":default:break;case"5-Day":t=ag.ImplVolRank5D;break;case"1-Month":t=ag.ImplVolRank1M;break;case"3-Month":t=ag.ImplVolRank3M;break;case"6-Month":t=ag.ImplVolRank6M;break;case"YTD":t=ag.ImplVolRankYTD}this.curves[0].fields[0]=t,e.outFields[0]=t;break}case"IVPCTL":{let t=ag.ImplVolPerc1Y;switch(e.inputs.TimeFrame){case"1-Year":default:break;case"5-Day":t=ag.ImplVolPerc5D;break;case"1-Month":t=ag.ImplVolPerc1M;break;case"3-Month":t=ag.ImplVolPerc3M;break;case"6-Month":t=ag.ImplVolPerc6M;break;case"YTD":t=ag.ImplVolPercYTD}this.curves[0].fields[0]=t,e.outFields[0]=t;break}case"OPTIV":{let t=[ag.WeighImplVolHigh,ag.WeighImplVol,ag.WeighImplVolLow];switch(e.inputs.TimeFrame){case"1-Day":default:break;case"5-Day":t=[ag.WeighImplVolHigh5D,ag.WeighImplVol5D,ag.WeighImplVolLow5D];break;case"1-Month":t=[ag.WeighImplVolHigh1M,ag.WeighImplVol1M,ag.WeighImplVolLow1M];break;case"3-Month":t=[ag.WeighImplVolHigh3M,ag.WeighImplVol3M,ag.WeighImplVolLow3M];break;case"6-Month":t=[ag.WeighImplVolHigh6M,ag.WeighImplVol6M,ag.WeighImplVolLow6M];break;case"1-Year":t=[ag.WeighImplVolHigh1Y,ag.WeighImplVol1Y,ag.WeighImplVolLow1Y];break;case"YTD":t=[ag.WeighImplVolHighYTD,ag.WeighImplVolYTD,ag.WeighImplVolLowYTD]}this.curves[0].fields[0]=t[0],this.curves[1].fields[0]=t[1],this.curves[2].fields[0]=t[2],e.outFields=[...t];break}case"PC":{let t=e.inputs.PeriodForecast-1;this.curves.forEach(e=>e.shift=t),eF(this.annotations)||(this.annotations=[]);let i=this.curves[11],s=this.curves[12],r=gj("ProbabilityCones",!0,{[tz.AT_LINE]:{color:i.colors[0],width:i.lineWidth,dashStyle:i.dashStyle},[tz.AT_LINE_2]:{color:s.colors[0],width:s.lineWidth,dashStyle:s.dashStyle}},this.id)(this.axis,!1);r.setOptions(e.inputs),this.annIndex=this.annotations.push(r)-1}}}getValueAt(e,t,i){return this.isVolAP?this.annotations[this.annIndex].getValueAt(e,t,i):super.getValueAt(e,t,i)}getColorOf(e){if(!this.isVolAP&&!this.isZigZag)return null;let t=this.curves[0].colors;if(this.isZigZag)return t[0];switch(e){case ag.UPVOL:return t[1];case ag.DNVOL:return t[0];case ag.TOTVOL:return t[2];case ag.POC:case ag.VAREA:case ag.BARBACK:return tz.COLOR_TRANSPARENT;default:throw Error("Unexpected Volume At Price field")}}isEmpty(){return!this.isVolAP&&!this.isZigZag&&super.isEmpty()}setCurveAttributes(e,t){let i=t=>this.curves[e].attributes=[U[t]];switch(t){case"LikeMain":{let t=this.axis.pane.presenter.mainPlot.curves[0].attributes,s=Sp().config.defaultVolumeBarColoring;eF(t)?this.curves[e].attributes=[t[0]]:i(eF(s)?"OpenToClose"===s?"OpenVsClose":"ChangeBased":"OpenVsClose");break}case"OpenToClose":i("OpenVsClose");break;case"CloseToClose":i("ChangeBased");break;default:throw Error(`Unexpected bar coloring choice: ${t}`)}}get hasEvents(){return this._hasEvents}get eventsSeries(){return this.timeSeries}doesSeriesEmitEvents(){let e=this.timeSeries.helpers;return e.includes(ag.Buy)||e.includes(ag.Sell)}getEventFor(e){switch(e){case ag.Buy:return{show:!0,title:"B",color:"#03c03c"};case ag.Sell:return{show:!0,title:"S",color:"#c23b22"};default:return null}}getEventFields(){return this.hasEvents?[ag.Buy,ag.Sell]:[]}async initialize(){if(this.model.basis!==tz.BASIS_MAIN)throw Error("Studies can currently only be based on the main (symbol) plot");return tU.call(this,async()=>{this.basePlot=this.axis.pane.presenter.mainPlot,await this.basePlot.initialize(),this.getMetaData();let e=this.axis.pane.presenter.data.aggregation,t=gJ(this.model,e,this.curves);this.applySpecifics(t);let i=this.basePlot.timeSeries;i instanceof cS&&(i=i.actual),this.timeSeries=fb(this.model.study,t,i),this._hasEvents=this.doesSeriesEmitEvents(),this.timeSeries.useNotifications=!0;let s=this.title,r=this.basePlot.timeSeries instanceof uJ;return this.timeSeries.ready().then(e=>{e||r||this.timeSeries.computedServerSide||So(`Unable to calculate study values for ${s}`,"error")}),!0})}get isJpi(){return["JPI","CTTP","CTTI"].includes(this.model.study)}get isVolAP(){return"VOLAP"===this.model.study||"PVACP"===this.model.study}get isZigZag(){return"ZIGZAG"===this.model.study}invalidateAssociatedAnnotations(e){this.isVolAP&&this.annotations[this.annIndex].invalidate(e)}onPriceDomainsUpdated(){this.invalidateAssociatedAnnotations("PriceDomainsChanged")}shouldPriceMap(e){return this.isJpi?!!this.shouldMaybePriceMap&&(e.id===ag.JPIB.id||e.id===ag.JPIS.id):super.shouldPriceMap(e)}canPriceMap(e,t){if(!this.isJpi)return super.canPriceMap(e,t);this._canPriceMap=e>0}priceMap(e,t,i){if(!this.isJpi)return super.priceMap(e,t,i);if(t>this.visToIndex)return e;let s=(e,t)=>this.timeSeries.container.getData(e)[t],r=s(ag.JPIB,t),n=s(ag.JPIS,t);if(null===r&&i.id===ag.JPIB.id||null===n&&i.id===ag.JPIS.id)return null;let a=0,o=this.visFromIndex,l=this.timeSeries.helpers[0],u=this.timeSeries.helpers[2];for(;o<=t;)a+=1===s(u,o)?0:s(l,o),o++;return a}}let g0=[ag.Open,ag.High,ag.Low,ag.Close,ag.Volume];class g1 extends mo{_expression;exprModel=null;symbols=null;errorText;get title(){return this.expression}get expression(){return this._expression}async parseExpression(){let e=nK(this._expression);if(this.exprModel=null,this.symbols=null,nj(e))this.errorText=e.error;else{let{model:t,clean:i,symbols:s}=e;this.errorText=void 0,this.symbols=s,this.exprModel=t,this._expression=i}}get isValid(){return!eF(this.errorText)}#t(e){return{mapper:e=>e.query.symbol,loadMoreData:!0,recompute:B.Minimum,missing:F.UseNext,stretch:e=>!1,fieldMap:new Map(g0.map(e=>[e,e])),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:e}}getTimeSeries(){let e=this.getInnerSeries(),t=this.axis?.pane.presenter.data?.exprSkipLeadingEmpty??!1,i=new py(this.exprModel,e,this.#t(t));this.timeSeries=this.wrapIfAdvancedStyle(i);let s=this.title;this.timeSeries.ready().then(e=>{e||So(`Unable to calculate expression: ${s}`,"error")})}getInnerSeries(){let e=nJ(this.exprModel),t=Sp().getTimeSeriesDataSource();return e.map(e=>{let i=this.makeQuery();return i.symbol=e,t.getTimeSeries(i)})}getRecord(){if(eF(this.errorText))return;let e=this.metaData.inner.map(e=>[e.symbol,e.resolved]);this.record=new aw(e,ez(this.exprModel)),this.record.ready().then(e=>e)}getMetaData(){this.isValid&&(this.metaData=new ir(this.symbols),this.metaData.ready().then(e=>{e&&(this.getRecord(),this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this}))}))}fromModel(e){super.fromModel(e),this._expression=e.expression}async initialize(){return tU.call(this,async()=>(await this.parseExpression(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class g2 extends mo{suffix;_forward;offset;errorText;fwdModel=null;outField;roots=null;symbols=[];get title(){return`${this.forward}${this.suffix}`}get forward(){return this._forward}fromModel(e){super.fromModel(e),this.offset=e.offset,this._forward=e.forward}async parseForward(){let e=nK(this.forward),t=nj(e);if(t?(this.errorText=e.error,this.fwdModel=null,this._forward=e.text):(this.errorText=void 0,this.fwdModel=e.model,this._forward=e.clean),t)this.roots=null;else{this.offset>0?(this.suffix=` (${ed(uE(this.offset),l$(tz.FMT_US_DATE_ONLY))(new Date)})`,this.outField=new ap(`Close_${this.offset}`,Y.Number,K.Forward,`Close (${this.offset})`),this.curves[0].fields[0]=this.outField):(this.suffix="",this.outField=ag.Close);let{yes:t,no:i}=eA(e.symbols,e=>ty(`${e}*1`)),s=(await Promise.all(t.map(e=>tM(e)))).map(e=>e.map(e=>e.name));this.roots=t.reduce((e,t,i)=>(e[t]=s[i],e),{}),this.symbols=i}}get isValid(){return!eF(this.errorText)}getMetaData(){if(this.isValid){let e=Object.values(this.roots).flat();this.metaData=new ir(e),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this})})}}getForwardPolicy(e){return{mapper:e=>e.query.root,loadMoreData:!1,recompute:B.Everything,missing:F.UseNext,stretch:e=>!1,fieldMap:new Map([[ag.Close,this.outField]]),noDataApproach:k.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1,valueProvider:e}}getTimeSeries(){let e=Sp().getTimeSeriesDataSource(),t=Object.keys(this.roots),i=0===this.offset?J.Forward:J.HistoricalForward,s=t.map(t=>{let s={seriesKind:i,root:t,offset:this.offset,symbols:this.roots[t],getHashKey:()=>`${i}|${t}|${this.offset}`};return e.getTimeSeries(s)}),r=this.symbols.length>0?new u4(this.symbols):void 0;this.timeSeries=new py(this.fwdModel,s,this.getForwardPolicy(r)),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:en.Unspecified};this.presenter?.notifyHost(ay.TS_MANYCHANGED,e)}})}async initialize(){return tU.call(this,async()=>(await this.parseForward(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}let g3=e=>e.substring(0,e.lastIndexOf("::"));class g4 extends mo{isAverage;hasComputation;offset;offsets;_seasonal;symbolToOffset;errorText;seaModel=null;isPlain=!1;isFutures=!1;suffix="";outField;symbols;coreModel;coreHasComputation;refSeasonal;get title(){if(this.isAverage){let e="YB ";return this.offset<-1&&(e=`${Math.abs(this.offset)}y `),`${e}Average`}return!this.hasComputation&&(this.symbols?.length??0)>0?this.outField.name:`${this.seasonal}${this.suffix}`}get seasonal(){return this._seasonal}fromModel(e){super.fromModel(e),this.offset=e.offset,this.offsets=e.offsets,this.isAverage=e.offset<0,this._seasonal=this.refSeasonal=e.seasonal}constructSeasonal(e,t){return nZ(n0(e,e=>this.applyOffset(e,t)))}constructAverage(e,t=null){let i=null===t?null:t.map(e=>this.symbolToOffset[e]),s=null===i,r=this.offsets.filter(e=>!!s||i.includes(e)).map(t=>`(${this.constructSeasonal(e,t)})`);return`(${r.join("+")})/${r.length}`}prepareFields(){let e=this.isPlain?`${this.yearFromOffset(this.offset)}`:`${this.offset}Y`,t=this.isAverage?"Avg":e;this.suffix=0===this.offset?"":` (${t})`,this.outField=new ap(`Close_${t}`,Y.Number,K.Seasonal,`Close${this.suffix}`),this.curves[0].fields[0]=this.outField}applyOffset(e,t){let i=this.isPlain?e:function(e,t){let i=ty(e),s=tv(e),r=tA(e);if(i)return tI(e,t);if(s){let i=tT.exec(e),s=Number.parseInt(i[2]),r=th(tn(new Date(s+(s>79?1900:2e3),0,1),t));return`${i[1]}${tC(r)}${i[3]}`}if(!r)return null;{let i=e.match(tS),s=tI(i[1],t),r=tI(i[2],t);return`_S_SP_${s}_${r}`}}(e,-t);return`${i}::${t}`}createSymbolToOffsetMapping(e){this.symbolToOffset={},e.forEach(e=>{this.offsets.forEach(t=>{this.symbolToOffset[this.applyOffset(e,t)]=t})})}async parseSeasonal(){let e=nK(this.seasonal,!0),t=nj(e),i=e=>(this.errorText=e,this.seaModel=null,null);if(t)return i(e.error);let{model:s,symbols:r}=e;this.prepareFields();let n=new Map;for(let e of r){let t=tb(await tm(e));n.set(e,t)}s=n0(s,e=>n.get(e));let a=(r=Array.from(n.values())).every(e=>ty(e)||tA(e)),o=r.every(e=>tv(e)),l=r.every(e=>!ty(e)&&!tv(e)&&!tA(e));if(!a&&!o&&!l)return i("Mixed types of symbols aren't supported yet");this.isPlain=l,this.isFutures=a,this.createSymbolToOffsetMapping(r),this.coreModel=this.isAverage?s:null,this.coreHasComputation=nQ(s);let{model:u,symbols:h}=nK(this.isAverage?this.constructAverage(s):this.constructSeasonal(s,this.offset),!0);this.seaModel=u,this.hasComputation=nQ(u),this._seasonal=nZ(n0(u,g3)),this.symbols=h,this.outField.name=this.outField.shortName=this.fixupFieldDescription()}get isValid(){return!eF(this.errorText)}getActualSymbols(){return[...new Set(this.symbols.map(g3))]}fixupFieldDescription(){if(!this.hasComputation&&!this.isAverage){let e=g3(this.symbols[0]);if(this.isPlain)return`${e} ${new Date().getFullYear()-this.offset}`;if(this.isFutures)return tb(e,!0)}return this.title}getMetaData(){if(this.isValid){let e=this.getActualSymbols(),t=1===e.length&&!this.hasComputation&&!this.isAverage,i=Sp().getMetaDataSource();this.metaData=t?i.getMetaData(e[0]):new ir(e),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(ay.MD_CHANGED,{plot:this})})}}getNoDataApproach(){return this.isAverage&&!this.coreHasComputation?k.ModelTransformRequired:this.hasComputation?k.NoAction:k.IgnoreTimelineOnly}get seasonalPolicy(){return{mapper:e=>e.query.surrogate||e.query.symbol,loadMoreData:!1,recompute:B.Everything,missing:this.hasComputation?F.UsePrevious:F.UseNone,stretch:e=>this.shouldStretch(e),fieldMap:new Map([[ag.Close,this.outField]]),noDataApproach:this.getNoDataApproach(),modelTransform:(e,t)=>0===t.length?this.seaModel:nK(this.constructAverage(this.coreModel,e)).model,skipLeadingEmpty:!1}}shouldStretch(e){return 0===this.symbolToOffset[e]&&(this.isAverage&&this.symbols.length>1||this.offset>0)}shiftYears(e){return tn(new Date,-e)}yearFromOffset(e){return th(this.shiftYears(e))}getCmdtyRange(e){let t=this.shiftYears(e);return[ta(t),function(e){tt(1,arguments);var t=ts(e),i=t.getFullYear();return t.setFullYear(i+1,0,0),t.setHours(23,59,59,999),t}(t)]}getTimeSeries(){if(!this.isValid)return;let e=Sp().getTimeSeriesDataSource(),t=Object.keys(this.symbolToOffset).map(t=>{let i=this.makeQuery();return i.surrogate=t,i.symbol=g3(t),i.offset=this.symbolToOffset[t],i.cacheMe=!this.isPlain||0===i.offset,this.isPlain&&(i.range=this.getCmdtyRange(i.offset)),this.isFutures&&i.offset>0&&eF(...i.range)&&(i.range=i.range.map(e=>tn(e,-i.offset))),i.offset>0&&(i.disableStreamingUpdates=!0),e.getTimeSeries(i)});this.timeSeries=new py(this.seaModel,t,this.seasonalPolicy),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:en.Unspecified};this.presenter?.notifyHost(ay.TS_MANYCHANGED,e)}})}async initialize(){return tU.call(this,async()=>(await this.parseSeasonal(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}let g5=["bottom","right","left"],g6={bottom:"center",right:"start",left:"end"};class g7{lineWidth;arrowLength;position;textAlign;fontSize;fontFamily;padding;strokeColor;textColor;backgroundColor;constructor(e){this.lineWidth=1,this.arrowLength=7,this.position="bottom",this.textAlign="center",this.fontSize=12,this.fontFamily="Arial",this.padding=4,this.strokeColor="white",this.textColor="white",this.backgroundColor="black",e&&this.configure(e)}configure(e){Object.assign(this,e)}draw(e,t,i,s,r,n){let a=eF(r);if(n=n||this.fontSize+this.padding+this.padding+(a?this.padding:0),!g5.includes(this.position.toLowerCase()))return void console.error(`Can not draw indicator in position [${this.position}]`);e.font=`bold ${this.fontSize}px ${this.fontFamily}`,e.textAlign=g6[this.position],e.strokeStyle=this.strokeColor,e.fillStyle=iC(this.backgroundColor),e.lineWidth=this.lineWidth;let o=Math.round(Math.max(...[s,r??""].map(t=>e.measureText(t).width))+("bottom"!==this.position?this.arrowLength:0)+this.padding+this.padding),l=Math.round(o/2),u=Math.round(n/2);e.setLineDash([]),e.beginPath(),e.moveTo(t,i);let h=i+u,c=i+2*u,d=i-u;if("right"===this.position){e.lineTo(t,h);let i=t+o;a&&(e.lineTo(t,c),e.lineTo(i,c)),e.lineTo(i,h),e.lineTo(i,d),e.lineTo(t,d)}else if("left"===this.position){e.lineTo(t,h);let s=t-o;a&&(e.lineTo(t,c),e.lineTo(s,c)),e.lineTo(s,h),e.lineTo(s,d),e.lineTo(t,i-u)}else if("bottom"===this.position){let s=t-l,r=t+l;e.lineTo(t,i),e.lineTo(r,i),e.lineTo(r,i+n),e.lineTo(s,i+n),e.lineTo(s,i),e.lineTo(t,i)}if(e.closePath(),e.stroke(),e.fill(),e.fillStyle=this.textColor,e.textBaseline="middle","bottom"===this.position)e.fillText(s,t,i+iF(e,1));else if("right"===this.position){let n=t+this.arrowLength+this.padding;e.fillText(s,n,i),a&&e.fillText(r,n,i+this.padding+u)}else if("left"===this.position){let n=t-this.arrowLength-this.padding;e.fillText(s,n,i),a&&e.fillText(r,n,i+this.padding+u)}}}let g8=(e,t)=>e-1-t-4,g9=(e,t)=>e+1+t+4,ye=Array.from(Array(6),(e,t)=>++t).reverse();function yt(e){return e.curves.filter(t=>t.visible&&(e.type!==Z.Study||t.style!==$.Ribbon)).map(t=>{let i=t.pickMainField(),[s,r]=function(e,t){let i=e.timeSeries.container;if(null===i||i.size<1)return[null,-1];let s=i.getLastDataPoint(t),r=i.getData(t),n=r.length-1,a=e.type===Z.Study&&["JPI","CTTP","CTTI"].includes(e.model.study);return null!=s||a||(s=-1!==(n=eT(r,e=>null!==e))?r[n]:null),[s,n]}(e,i);return{value:s,color:function(e){let t=e.plot.timeSeries.container;return null===t||t.size<1?null:e.getColor(t.size-1)}(t),field:i,index:r}})}class yi{pane;annotations;id;isCustomDomain;primary;onTheRight;viewBox;plots;comparison;scale;yScale;label;crosshairIndicator;ticks;lastUsedOptions;config;_fullDomain;constructor(e){this.pane=e,this.annotations=[],this.isCustomDomain=!1,this.primary=!1,this.onTheRight=!0,this.plots=[],this.label="",this.id=e1(),this.ticks=null,this.lastUsedOptions=null;let{chart:{fontSize:t},yAxis:{fontSize:i}}=this.pane.presenter.display;this.config={innerTickSize:7,tickPadding:5,indicatorPadding:4,fontWeight:400,fontSize:i||t||12},this.crosshairIndicator=new g7({fontSize:this.config.fontSize,arrowLength:this.config.innerTickSize})}makePlot(e){let t=null;switch(Z[e.type]){case Z.Symbol:t=new ml;break;case Z.Expression:t=new g1;break;case Z.Study:t=new gQ;break;case Z.IncomeStatement:t=new mu(J.IncomeStatement);break;case Z.BalanceSheet:t=new mu(J.BalanceSheet);break;case Z.Forward:t=new g2;break;case Z.Seasonal:t=new g4;break;default:throw Error(`${e.type} isn't supported yet`)}return t.axis=this,t.fromModel(e),t}toPrice(e){let t=this.yScale.yToPrice(e);return this.comparison===q.None?t:this.pane.presenter.mainPlot.priceMap(t,void 0,ag.Close,!0)}toTime(e){return this.pane.presenter.view.toTime(e)}toAnnotationPoint(e){return new mm(this,this.toPrice(e.y),this.toTime(e.x)||void 0)}toX(e){return this.pane.presenter.view.toX(e)}priceMap(e){return this.comparison===q.None?e:this.pane.presenter.mainPlot.priceMap(e,void 0,ag.Close)}toY(e){let t=this.priceMap(e);return this.yScale.priceToY(t)}get plotAnnotations(){let e=[];return this.plots.forEach(t=>{t.annotations&&e.push(...t.annotations)}),e}annTimeToX(e){return this.pane.presenter.view.xAxis?.annTimeToX(e)}snapTo(e){let t={x:this.annTimeToX(e.time),y:this.toY(e.price)},i=this.pane.presenter,s=i.activeTool,r=s.annotation;return s.alignPointsMode&&r&&r.alignPointsSupported&&r.points.includes(e)?this.alignPoints(r,e,t):s.snapToSupported&&i.display.yAxis.snapAnnotationsToPrices&&!e.passive&&(e.moveDirection===es.Both||e.moveDirection===es.Vertical)&&this.snapToPrices(e,t),t}snapToPrices(e,t){let i=this.plots.find(e=>e.main);if(i&&i.timeSeries&&i.timeSeries.hasData){let s=i.timeSeries.container,r=e_(s.getTimeData(),+e.time,Number),n=[].concat(...i.curves.map(e=>e.fields)).filter(e=>s.hasField(e)).map(e=>{let i=s.getData(e)[r],n=this.toY(i),a=Math.abs(n-t.y);return{priceSnap:i,ySnap:n,dist:a}}).filter(e=>e.dist<=tz.SNAP_PROXIMITY_PIXELS).reduce((e,t)=>null===e||t.dist<e.dist?t:e,null);eF(n)&&(e.price=n.priceSnap,t.y=n.ySnap,e.time=s.getTimeData()[r],t.x=this.toX(e.time))}}alignPoints(e,t,i){let s=e.points.find(e=>e!==t);if(t!==s&&s&&s.point){let e=s.point,r=(360+-(180*iT(e,i))/Math.PI)%360;if(r>337.5||r<22.5||r>157.5&&r<202.5)i.y=e.y,t.price=this.toPrice(i.y);else if(r>67.5&&r<112.5||r>247.5&&r<292.5)i.x=e.x,t.time=this.toTime(i.x);else{let s=Math.abs(i.x-e.x),r=e.y>i.y?-1:1;i.y=e.y+s*r,t.price=this.toPrice(i.y)}}}toPoint(e){if(eF(this.pane.presenter.view))return this.snapTo(e)}makeAnnotation(e,t=!0){let i=gj(e.id,!0,e.traits)(this,!1);t&&e.uid&&(i.uid=e.uid);let s=i.activePoints,r=e.points.length-s.length;return r>0&&i.addPoints(r),i.activePoints.forEach((t,i)=>{let s=e.points[i];ek(s.price)&&ek(s.time)&&t.update(s.price,s.time)}),i.visible=e.visible,i.locked=e.locked,i}expand(e){let t=[];switch(e.type){case"Forward":{let i=e.curves,s=e.offsets;delete e.curves,delete e.offsets;for(let r=0;r<i.length;r++){let n=Object.assign({},e);n.curves=[i[r]],n.offset=s[r],t.push(n)}break}case"Seasonal":{let i=e.curves,s=e.offsets;delete e.curves,delete e.offsets;let r=s.filter(e=>e>=0);for(let n=0;n<i.length;n++){let a=Object.assign({},e);a.curves=[i[n]],a.offset=s[n];let o=a.offset<0;if(o){let e=-1===a.offset;a.offsets=e?r:ex(Math.abs(a.offset),e=>e+1)}else a.offsets=[a.offset];(!o||a.offsets.length>1)&&t.push(a)}break}default:t.push(e)}return t}fromModel(e){this.comparison=q[e.comparison??"None"],this.scale=X[e.scale??"Linear"],this.yScale=new mt(this.scale,this),this.label=e.label,this.plots=[].concat(...e.plots.map(e=>this.expand(e))).map(e=>this.makePlot(e));let t=e.annotations||[];this.annotations=t.map(e=>this.makeAnnotation(e));let{chart:{fontFamily:i,backgroundColor:s},yAxis:{textColor:r,crosshair:{color:n},primaryOnTheLeft:a}}=this.pane.presenter.display,o=a??!1;this.onTheRight=this.primary&&!o||!this.primary&&o,this.crosshairIndicator.configure({position:this.onTheRight?"right":"left",fontFamily:i,strokeColor:n,textColor:r,backgroundColor:i_(.15)(s)})}findIndex(e){return this.annotations.findIndex(t=>t.uid===e.uid)}addAnnotation(e){let t=this.makeAnnotation(e,!0);this.appendAnnotation(t),t.requestRedraw(),this.fireAnnotationsChanged()}appendAnnotation(e){-1===this.findIndex(e)&&this.annotations.push(e)}fireAnnotationsChanged(e=!1){this.pane.presenter.onAnnotationsUpdated(this,e)}deleteAnnotation(e,t=!0){e.isSelected&&this.pane.presenter.clearSelection();let i=this.findIndex(e);-1!==i&&this.annotations.splice(i,1),t&&this.fireAnnotationsChanged(!e.isSelected)}fliphorizontalAnnotation(e){e.flip(!0),this.fireAnnotationsChanged(!0)}flipverticalAnnotation(e){e.flip(!1),this.fireAnnotationsChanged(!0)}duplicateAnnotation(e){let t=e.axis,i=this.makeAnnotation(e.toModel(),!1);i.drawPoints(null,!0),i.offset({x:tz.ANN_DUPLICATE_OFFSET,y:tz.ANN_DUPLICATE_OFFSET}),t.appendAnnotation(i),i.requestRedraw(),this.fireAnnotationsChanged()}updateAnnotation(e,t){e.isSelected&&this.pane.presenter.clearSelection(),s8(e.name,t.traits),e.updateFrom(t.traits,t.extras,t.isUndoRedo?null:t.points,t.visible,t.locked),t.isUndoRedo&&eF(t.points)&&e.updateActivePoints(t.points),t.isUndoRedo||this.pane.presenter.undoRedoManager.done(my(e,el.Moved)),e.requestRedraw(),this.fireAnnotationsChanged()}setViewBox(e){this.viewBox=e;let{y:t,height:i}=this.viewBox;this.yScale.range([Math.floor(t),Math.floor(t+i)]),this.plots.forEach(t=>t.setViewBox(e))}get fullDomain(){return eF(this._fullDomain)||(this._fullDomain=this.getDataDomain().domain),this._fullDomain}updateFullDomain(e=null){if(null===e&&this.comparison!==q.None)return;let t=this.fullDomain;this._fullDomain=this.getDataDomain([e,e],t).domain}getPlotDataDomain(e,t,i){let s=e.timeSeries;if(!s.hasData)return{domain:null};let r=s.container,n=r.getTimeData(),a=e=>e_(n,+e,Number),o=eF(t),l=o?a(t):0,u=eF(i),h=u?a(i):n.length-1,c=e.curves.map(e=>e.fields).flat().filter(e=>e.id!==ag.Change.id),d=eF(e.targetFields);d&&c.push(...e.targetFields);let p={},f=t=>{let[i,s]=(t=>{let i=d?e.curves[0]:e.curves.find(e=>e.fields.includes(t));if(!eF(i)||0===i.shift)return[l,h];if(!eF(p[i.id])){let e=i.shiftedTimeDomain;if(!eF(e))return[l,h];p[i.id]=[a(e[0]),a(e[1])]}return p[i.id]})(t),n=r.getData(t),o=Math.max(i,0),u=Math.min(n.length-1,s);return n.slice(o,u+1).map((i,s)=>e.priceMapper(i,s,t))},m=[null,null],g=e=>e.id,y=new Set(eP(r.fields,c,g).map(g));e.curves.filter(e=>e.visible).map(e=>{let t=e.fields.filter(e=>y.has(e.id));e.isStackedColumn?eI(eM(t.map(e=>f(e)).reduce((e,t)=>t.map((t,i)=>(e[i]||0)+(t||0)),[])),m):t.map(e=>{eI(eM(f(e)),m)})});let S=eu.None,A=[$.Column,$.MultiColumn,$.StackedColumn];if(o&&u&&!e.main&&e.curves.some(e=>A.includes(e.style))){let e=m[0]>0,t=m[1]<0;e?(S=eu.Min,m[0]=0):t&&(S=eu.Max,m[1]=0)}return{domain:m,clamped:S}}getDataDomain([e,t]=[null,null],i=[null,null]){let s=ez(i),r=!1;for(let i of this.plots.filter(e=>!e.hasDetachedScale)){let{domain:n,clamped:a}=this.getPlotDataDomain(i,e,t);eF(n)&&(eI(n,s),r=r||a!==eu.None)}if(!eF(s))return{domain:null};let[n,a]=s;if(!eF(n,a))return{domain:null};let o=[Number(n),Number(a)];o[0]===o[1]&&(o[0]-=1,o[1]+=1);let l=eu.None;return r&&(0===o[0]?l=eu.Min:0===o[1]&&(l=eu.Max)),{domain:o,clamped:l}}setDomain(){let e=this.pane.presenter,t=e.view.xAxis.xScale.domain();if(!eF(t))return;for(let e of this.plots.filter(e=>e.hasDetachedScale)){let{domain:i}=this.getPlotDataDomain(e,t[0],t[1]);eF(i)&&e.yScale.domain(i)}if(this.isCustomDomain)return;let{domain:i,clamped:s}=this.getDataDomain(t);if(this===e.mainAxis&&e.mainPlot?.showPrevious){let t=e.mainPlot.getPreviousValue(),s=eG(e.display,!1,"chart","previous","forceVisible");eF(t,i)&&s&&(i[0]=Math.min(i[0],t),i[1]=Math.max(i[1],t))}if(this.yScale.domain(i),eF(i)){let e=this.getPadding(s);eF(e)&&this.yScale.padding(e)}}getInitialPadding(){let e=tO(this.pane.presenter.hostElement),t=tR(`#${tz.HEADER_SIZE_PLACEHOLDER_ID}`,e);if(!eF(t)){tN(t=tB(e,"div"),{display:"none"}),tV(t,{id:tz.HEADER_SIZE_PLACEHOLDER_ID,class:"bcharts-card bcharts-card-first"});let{lineHeight:i}=getComputedStyle(t);isNaN(Number.parseFloat(i))&&tN(t,{lineHeight:"120%"})}let{paddingTop:i,paddingBottom:s,marginTop:r,lineHeight:n}=getComputedStyle(t),a=this.pane.isMain?r:"0";return"cards"!==this.pane.presenter.display.tooltip.mode?Number.parseFloat(a):[i,s,a,n].map(Number.parseFloat).reduce((e,t)=>e+t,0)+tz.CARDS_Y_OFFSET}getPadding(e){let t=this.pane.presenter,i=t.display,s=eG(i,null,"yAxis","minPaddingPercent"),r=eG(i,null,"yAxis","maxPaddingPercent"),n=eF(s),a=eF(r),o=n||a?0:this.getInitialPadding(),l=n?s:tz.PANE_CAP_MIN_PADDING_PERCENT,u=a?r:tz.PANE_CAP_MAX_PADDING_PERCENT,h=l*this.viewBox.height,c=[a?u*this.viewBox.height:Math.max(h,Math.min(u*this.viewBox.height,o)),h];e===eu.Max?c[0]=tz.PANE_TINY_PADDING_PIXELS:e===eu.Min&&(c[1]=tz.PANE_TINY_PADDING_PIXELS);let d=t.mainPlot;return d&&d.hasEvents&&(c[0]+=3*t.view.getEventRadius()),c}clearTicks(){this.ticks=null}getTicks(e,t=0){let{height:i}=this.viewBox,s=iF(e,1.3),r={height:i,approxLineHeight:s,domain:this.yScale.domain()};if(eF(this.ticks)&&eF(r.domain)&&eF(this.lastUsedOptions)&&eF(this.lastUsedOptions.domain)&&r.height===this.lastUsedOptions.height&&r.approxLineHeight===this.lastUsedOptions.approxLineHeight&&r.domain[0]===this.lastUsedOptions.domain[0]&&r.domain[1]===this.lastUsedOptions.domain[1])return this.ticks;this.lastUsedOptions=r;let n=Math.floor((i+40)/(s+40)),a=this.yScale.getTicks(n),o=eG(Sp().config,null,"overrides","yAxis","tickProvider");if(eF(o)&&"function"==typeof o&&r.height>0&&eF(r.domain)){let e=ez(r);e.autoTicks=ez(a),a=o(e)}let{innerTickSize:l,tickPadding:u,fontSize:h}=this.config,c=null,d=this.yScale?.checkTicks(),p=d?30:40;return this.ticks=a.map(i=>{let s=Math.round(this.yScale.priceToY(i)),r=Math.abs(s-(c??s));if(d&&null!==c&&r<p)return null;c=s;let n=h_(this,i),a=e.measureText(n).width,o={x1:0,x2:0,y1:s,y2:s,dy:0,label:n,labelX:0,labelY:s+.32*h};return this.onTheRight?(o.x1=t,o.x2=o.x1+l,o.labelX=o.x2+a+u):(o.x1=t-l,o.x2=o.x1+l,o.labelX=o.x1-u),o}).filter(e=>null!==e),this.ticks}widthNeeded(e){if(!eF(this.fullDomain))return tz.DEFAULT_PRICE_AXIS_WIDTH;e.save();let{fontWeight:t,fontSize:i}=this.config,{chart:{fontFamily:s}}=this.pane.presenter.display;e.font=`${t} ${i}px ${s}`;let r=t=>e.measureText(h_(this,t,!0)).width,n=Math.max(...this.fullDomain.map(r)),{innerTickSize:a,tickPadding:o}=this.config,l=eF(this.label)?iF(e,1.6):0;return e.restore(),n+a+2*o+l}draw(e){let{chart:{fontFamily:t},yAxis:{gridLines:i,textColor:s,visible:r}}=this.pane.presenter.display;if(!r||!this.viewBox)return;e.save();let{x:n,y:a,width:o,height:l}=this.viewBox,{fontWeight:u,fontSize:h}=this.config;if(iO(e,this.viewBox),e.font=`${u} ${h}px ${t}`,e.lineWidth=2,e.strokeStyle=i.color,e.textAlign="end",eF(this.label)){e.save(),e.fillStyle=iL(.4)(s),e.translate(0,0);let t=this.onTheRight?1:-1;e.rotate(t*Math.PI/2),e.textAlign="center";let i=iF(e),r=t*(a+l/2);this.onTheRight?e.fillText(this.label,r,-(n+o-i)):e.fillText(this.label,r,n+i),e.restore()}let c=this.onTheRight?n:o;e.setLineDash([]),iY(e,c,a,a+l);let d=this.getTicks(e,c);this.drawTicks(e,d,s),this.drawPriceAdornments(e),e.restore()}drawTicks(e,t,i){t&&(e.fillStyle=i,t.forEach(t=>{e.fillText(t.label,t.labelX,t.labelY+t.dy)}))}drawCrosshairIndicator(e,t){if(0===this.plots.length||!this.pane.presenter.display.yAxis.crosshair.enabled)return;let i=this.onTheRight?this.viewBox.x:this.viewBox.width,s=h_(this,this.yScale.yToPrice(t));this.crosshairIndicator.draw(e,i,t,s)}get indicatorHeight(){return this.config.fontSize+this.config.indicatorPadding+this.config.indicatorPadding}drawPriceAdornments(e){var t;let i=this.pane.presenter,{chart:{fontFamily:s,previous:r},yAxis:{showLastValue:n,preventLabelOverlap:a,includePercentChangeWithLastValue:o}}=i.display,l=i.view,u=[],h=(e,t,i,s,r,n)=>{if(null!=t){let a,l=t;t=e.priceMapper(t,n,r);let h=e.is(Z.Symbol)||e.is(Z.Expression);if(o&&h){let t=e.axis.comparison===q.Percent?q.None:q.Percent;a=e.priceMapper(l,n,r,t)}let c=e.hasDetachedScale?e.metaData.format(t,r):void 0,d=eF(a)?1:2;u.push({y:e.priceToY(t),formattedValue:c,value:t,auxValue:a,color:i,halfHeight:Math.round(this.indicatorHeight/d),priority:s})}};this.plots.forEach(e=>{if(e.timeSeries&&e.timeSeries.hasData){if("All"===n||"Main"===n&&e.main){let t=e.main?1:3;yt(e).filter(e=>null!=e.value&&-1!==e.index).forEach(i=>h(e,i.value,i.color,t,i.field,i.index))}e.showPrevious&&h(e,e.getPreviousValue(),r.color,2,ag.PreviousClose,void 0)}}),this.annotations.concat(this.plotAnnotations).forEach(e=>{u.push(...e.getPriceScaleAdornments().map(e=>({y:this.toY(e.price),value:this.priceMap(e.price),color:e.color,halfHeight:Math.round(this.indicatorHeight/2),priority:4})))}),u.sort((e,t)=>e.y-t.y),a&&(t=this.viewBox,u.forEach((e,i,s)=>{if(0===i&&e.y-e.halfHeight<t.y)e.y=t.y+e.halfHeight+1;else if(i>0){let r=s[i-1],n=(({y:e,halfHeight:t})=>e-t)(e),a=(({y:e,halfHeight:t})=>e+t)(r);n<a&&(e.y=a+1+e.halfHeight),(({y:e,halfHeight:t})=>e+t)(e)>t.y+t.height&&(e.y=t.y+t.height-e.halfHeight-1)}}));let c=({y:t,value:i,formattedValue:r,color:n,auxValue:a})=>{let o,{leftOffset:u,rightOffset:h}=l,c=this.onTheRight?this.pane.viewBox.width-h:u,d=iI(n),p=new g7({position:this.onTheRight?"right":"left",fontSize:this.config.fontSize,padding:this.config.indicatorPadding,fontFamily:s,textColor:d,strokeColor:n,backgroundColor:n}),f=r||h_(this,i),m=this.comparison===q.Percent;eH(a)&&(o=m?hL(this,a):hE(a)),p.draw(e,c,t,f,o)};a?u.forEach(c):ye.forEach(e=>u.filter(t=>t.priority===e).forEach(c))}}let ys=Symbol.for("__dloacip__");class yr{presenter;id;axes;height;alignedToYear;viewBox;constructor(e){this.presenter=e,this.axes=[],this.height=0,this.alignedToYear=null,this.id=e1()}fromModel(e){this.height=e.height,!0===e.alignOnExpirations&&(this.alignedToYear=function(e){let t=e.map(e=>e.plots).flat().filter(e=>Z[e.type]==Z.Symbol).map(e=>e.symbol).map(e=>tx(e)).filter(e=>null!==e).map(e=>e.getFullYear());return 0!=t.length?Math.max(...t):null}(e.axes)),this.axes=e.axes.map((e,t)=>{let i=new yi(this);return i.primary=0===t,i.fromModel(e),i},this)}getBounds(){return this.viewBox}setViewBox(e){this.viewBox=e}drawBackground(e){eF(this.viewBox)&&(this.drawAxes(e),e.save(),this.clipToNoScales(e),this.drawGrid(e),e.restore())}draw(e){eF(this.viewBox)&&(e.save(),this.clipToNoScales(e),this.drawPrevious(e),this.drawPlots(e),this.drawAnnotations(e),this.drawLogo(e),e.restore())}drawLogo(e){this.isMain&&!1!==this.presenter[ys]&&function(e,{x:t,y:i,height:s,width:r}){if(!eH(mZ))return;let{path:n,width:a,height:o,rect:l}=mZ,u=Math.min(Math.max(50,r/8),a)/a;l.width=a*u,l.height=o*u,l.x=t+5,l.y=i+s-l.height-5,e.save();let h=getComputedStyle(e.canvas).getPropertyValue("--widget-logo-fill-color");e.fillStyle=0===h.length?"rgba(127, 127, 127, 0.6)":h,e.translate(l.x,l.y),e.scale(u,u),e.fill(n),e.restore()}(e,this.getBoundsWithoutScales())}drawAxes(e){for(let t of this.axes)t.draw(e)}drawPrevious(e){let t=this.presenter.mainPlot;if(t.showPrevious&&this.isMain){let i=t.getPreviousValue();if(null!=(i=t.priceMapper(i,void 0,ag.PreviousClose))){let{leftOffset:s,rightOffset:r}=this.presenter.view,n=this.viewBox.width-r,a=t.axis.yScale.priceToY(i),{color:o,dashStyle:l,lineWidth:u}=this.presenter.display.chart.previous,h=iP(l);e.save(),e.strokeStyle=o,e.lineWidth=u,e.setLineDash(h),ij(e,a,s,n),e.restore()}}}getBoundsWithoutScales(){let e=this.viewBox.duplicate(),t=this.presenter.view;return e.x=t.leftOffset,e.width-=t.leftOffset+t.rightOffset,e}clipToNoScales(e){iO(e,this.getBoundsWithoutScales())}drawAnnotations(e){e.save();let{chart:{fontFamily:t},yAxis:{fontSize:i}}=this.presenter.display;e.font=`${i??12}px ${t}`;let s=t=>t.draw(e,!0);this.axes.forEach(e=>{e.annotations.forEach(s),e.plotAnnotations.forEach(s)}),e.restore()}drawGrid(e){let{chart:{fontFamily:t},yAxis:{gridLines:i,visible:s,minorGridLines:r}}=this.presenter.display;if(!s||!i.visible)return;let{lineWidth:n,color:a,dashStyle:o}=i;e.save();let l=this.axes[0].plots?.length===0&&this.axes.length>1,u=this.axes[+!!l],{fontWeight:h,fontSize:c}=u.config;e.font=`${h} ${c}px ${t}`;let d=u.getTicks(e),{leftOffset:p,rightOffset:f}=this.presenter.view,m=this.viewBox.width-f,g=(t,i,s)=>{e.lineWidth=t,e.strokeStyle=i,e.setLineDash(iP(s)),e.beginPath()};if(g(n,a,o),d.forEach(t=>{e.moveTo(p,t.y1),e.lineTo(m,t.y2)}),e.stroke(),r&&r.visible&&d.length>=2){let{lineWidth:t,color:i,dashStyle:s}=r,n=(d[0].y1-d[1].y1)/5;g(t,i,s),d.forEach(t=>{for(let i=1;i<5;i++){let s=Math.ceil(t.y1+i*n);e.moveTo(p,s),e.lineTo(m,s)}}),e.stroke()}e.restore()}drawYCrosshair(e,t){let{yAxis:{crosshair:{enabled:i,showValue:s,color:r,dashStyle:n}}}=this.presenter.display;if(!i)return;let a=iP(n);e.strokeStyle=r,e.setLineDash(a);let o=this.presenter.view.leftOffset,l=this.viewBox.width-this.presenter.view.rightOffset,u=iZ();u.prolog(e),ij(e,u.adjust(t.y),u.adjust(o),u.adjust(l)),u.epilog(e),s&&this.axes.forEach(i=>{i.drawCrosshairIndicator(e,t.y)})}drawNoData(e){e.save(),e.font=`800 14px ${this.presenter.display.chart.fontFamily}`,e.fillStyle="#f00",iU(e,Sp().config.noDataText||tz.NO_DATA_TEXT,{x:this.viewBox.centerX,y:this.viewBox.centerY},Q.Center),e.restore()}get isMain(){let e=this.presenter.mainPlot;return this.axes.some(t=>t.plots.includes(e))}drawPlots(e){e.save();let t=this.presenter.mainPlot,i=this.presenter.display.chart.showNoDataText,s=!eF(i)||i,r=new Map,n=!0,a=i=>{for(let e of this.axes){for(let s of e.plots){let e=s.isEmpty();n=n&&s.main&&e,s===t||e||i(s)}e.plots.includes(t)&&!t.isEmpty()&&i(t)}s&&n&&this.drawNoData(e)};a(t=>t.draw(e)),a(t=>t.drawTopmost(e,r)),e.restore()}}function yn(e,t){return{width:e,spacing:t,get totalWidth(){return this.width+this.spacing},offset:0}}class ya extends f5{timeline;aggregation;marginBars;bar;resetBar;wasZoomed;fitAllData;constructor(e,t){super(),this.timeline=e,this.aggregation=t;let i=e.presenter.display;this.marginBars=i.xAxis.marginBars||0,this.bar=yn(eG(i,tz.DEFAULT_BAR_WIDTH,"chart","bar","width"),eG(i,tz.DEFAULT_BAR_SPACING,"chart","bar","spacing")),this._extent=null,this.wasZoomed=!1,this.fitAllData=!1}extent(e){return f4.call(this,"_extent",e)}get presenter(){return this.timeline.presenter}get display(){return this.presenter.display}scaleBarToFit(){if(this.wasZoomed)return;if(this.fitAllData)return this._domain=null,this.scaleBarToFitDensity(this.timeline.withoutPrologEpilogLength);let e=this.display.xAxis.visibleRange;if(eF(e))return this.scaleBarToFitRange([e.from,e.to]);let t=this.display.density;if(Number.isFinite(t))return this.scaleBarToFitDensity(t);let i=this.display.period;if(Number.isFinite(i))return this.scaleBarToFitPeriod(i)}deriveExtentsFromBarWidth(e){if(!eF(this._range)||0===this.timeline.length)return null;let t=this._range[1]-this._range[0],i=Math.ceil(t/e.totalWidth);e.offset=t-i*e.totalWidth;let s=this.timeline.lastSeriesIndex+this.marginBars,r=this._domain&&this._domain[1];return r&&(s=e_(this.timeline,+r,Number,hw)),[s-i+1,s]}adjustDomain(){if(!eF(this._range))return;this.scaleBarToFit();let e=this.deriveExtentsFromBarWidth(this.bar);eF(e)&&(this.extent(e),this.setDomainFromExtent())}xToTime(e){if(!this.ready)return null;let t=Math.floor((e-this._range[0]-this.bar.offset)/this.bar.totalWidth),i=this._extent[0]+t;return this.timeline.at(i)}timeToIndex(e){return this.ready?(e="number"==typeof e?e:+e,e_(this.timeline,e,Number,hw)):null}indexToX(e){let t=e-this._extent[0];return this.bar.width/2+this.range()[0]+this.bar.offset+t*this.bar.totalWidth}timeToX(e){if(!this.ready)return null;let t=this.timeToIndex(e);return this.indexToX(t)}zoom(e){let t=e*this.bar.width/100,i=this.bar.width-t,s=this.bar.spacing-e*this.bar.spacing/100;if(i>tz.MAXIMUM_BAR_WIDTH||i<tz.MINIMUM_BAR_WIDTH)return!1;let r=yn(i,s),n=this.deriveExtentsFromBarWidth(r);return!!this.isUsableExtent(n)&&(this.setBar(i,s),this.adjustDomain(),this.wasZoomed=!0,!0)}scaleBarToFitRange(e,t=!0){let i=(e,t,i,s)=>eF(e)?e_(this.timeline,e,Number,hw,i,s):t,{from:s,to:r}=this.presenter.data.range||{},n=+e[0]===s&&+e[1]===r,{firstSeriesIndex:a,lastSeriesIndex:o}=this.timeline,l=n?a:void 0,u=n?o:void 0,h=[i(e[0],a,l,u),i(e[1],o,l,u)];this.timeline.at(h[1])>e[1]&&(h[1]=Math.max(0,h[1]-1)),this.extent(h),this.scaleBarToFitDensity(h[1]-h[0]+1,t)}scaleBarToFitDensity(e,t=!0){let i=Math.max(tz.MINIMUM_BARS_VISIBLE,e),s=t&&this.display.xAxis.marginBars||0,r=(this._range[1]-this._range[0])/(i+s);this.setBar(2/3*r,1/3*r,!1)}scaleBarToFitPeriod(e){let t=this.timeline.lastSeriesIndex,i=this.timeline.at(t),s=i,r=t,n=this.presenter.data.aggregation;if(n.isEndOfDay||n.isIntraday&&e>=tz.INTRA_THRESHOLD)for(;r>0&&uL(i,s)<e;)r--,s=this.timeline.at(r);else if(!n.isTick){let t=Math.floor(e/tz.ONE_DAY_MILLIS),s=e=>gx(e,tl(e)),n=s(i),a=i;for(;r>0;){let e=this.timeline.at(r),i=nS(e,a);if(0===t){if(s(e)<=n||!i)break}else i||(t--,a=e);r--}}this.scaleBarToFitDensity(t-r+1)}setBar(e,t,i=!0){let[s,r]=e0(e,t,tz.MINIMUM_BAR_WIDTH,tz.MAXIMUM_BAR_WIDTH);this.bar.width=s,this.bar.spacing=r,this.wasZoomed||(this.resetBar={width:s,spacing:r}),i&&(this.presenter.model.display.chart.bar={width:e,spacing:t})}resetZoom(){eF(this.resetBar)?(this.bar.width=this.resetBar.width,this.bar.spacing=this.resetBar.spacing):(this.bar.width=tz.DEFAULT_BAR_WIDTH,this.bar.spacing=tz.DEFAULT_BAR_SPACING),delete this.presenter.model.display.chart.bar,this.adjustDomain()}isUsableExtent(e){return eF(e)&&eF(e[0],e[1])&&e[0]>=0&&e[1]<this.timeline.withPrologEpilogLength&&e[1]-e[0]>=tz.MINIMUM_BARS_VISIBLE}shiftBars(e,t=null){if(!this._extent)return;let i=this._extent.map(t=>t+e);this.isUsableExtent(i)&&(eF(t)&&(this.bar.offset=t),this.extent(i),this.setDomainFromExtent())}setDomainFromExtent(){this.domain(this.extent().map(e=>this.timeline.at(e)))}pan(e){if(!Number.isFinite(e)||0===e)return;let t=e%this.bar.totalWidth,i=this.bar.offset+t,s=Math.sign(e),r=-(e<0?Math.ceil:Math.floor)(e/this.bar.totalWidth);(i>this.bar.totalWidth||i<-this.bar.totalWidth)&&(r+=i>0?-1:1,i-=s*this.bar.totalWidth),this.shiftBars(r,i)}getSeriesThatCouldLoadMoreData(){let e=this.domain();if(!eF(e)||!eF(e[0]))return[];let t=e[0].getTime();return this.timeline.presenter.allPlots.map(e=>e.timeSeries).filter(e=>!!eF(e)&&!!e.hasData&&0!==e.container.size&&!0===e.canLoadMoreData&&t<=e.container.getTimeData()[0].getTime())}}function yo(e){return{date:e,priority:1,text:hb(e)}}class yl{view;xScale;ticks;lastUsedOptions;wasPanned;panningXAxisAllowed;config;isVisible;crosshairIndicator;viewBox;overrideTickGetter;overrideFormatter;constructor(e){this.view=e,this.xScale=new ya(e.presenter.timeline,e.presenter.data.aggregation),this.ticks=null,this.lastUsedOptions=null,this.wasPanned=!1,this.panningXAxisAllowed=eG(e.presenter.display,!0,"xAxis","panning"),this.updateConfigFromModel();let t=e.presenter.renderTo.id,i=eG(Sp().config,null,"overrides","xAxis","tickProvider");eF(i)&&"function"==typeof i&&(this.overrideTickGetter=eh(i,t));let s=eG(Sp().config,null,"overrides","xAxis","formatter");eF(s)&&"function"==typeof s&&(this.overrideFormatter=eh(s,t))}updateConfigFromModel(){let{chart:{fontFamily:e,backgroundColor:t,fontSize:i},xAxis:{textColor:s,visible:r,fontSize:n,crosshair:{color:a}}}=this.view.presenter.display;this.config={innerTickSize:5,tickPadding:5,indicatorPadding:5,fontWeight:400,fontSize:n||i||12},this.isVisible=r,this.crosshairIndicator=new g7({position:"bottom",fontSize:this.config.fontSize,fontFamily:e,padding:this.config.indicatorPadding,strokeColor:a,textColor:s,backgroundColor:i_(.15)(t),arrowLength:this.config.innerTickSize})}setDomain(){this.xScale.adjustDomain();let e=this.view.presenter.display.period===tz.FIFTY_YEARS_MILLIS;eF(this.xScale.extent())&&!e&&this.checkForMoreData()}zoom(e){let t=this.xScale.zoom(e);return this.checkForMoreData(),t}checkForMoreData(){this.xScale.getSeriesThatCouldLoadMoreData().forEach(e=>e.loadMoreData())}shouldScrollIntoView(e){let t=this.xScale.extent();return!!eF(t)&&e-this.xScale.timeline.lastSeriesIndex>=0&&e-t[1]<=1}pan(e){this.panningXAxisAllowed&&(this.xScale.pan(e),this.checkForMoreData(),this.view.setPriceAxesDomains(),this.wasPanned=!0)}get wasVisibleRangeChanged(){return this.wasPanned||this.xScale.wasZoomed}resetZoom(){this.xScale.resetZoom()}get barsToLast(){let e=this.xScale.timeline.lastSeriesIndex+this.getMaxCurveOffset(),t=this.xScale.extent(),i=t?t[1]:e;return e-i}canGoToLast(){return this.barsToLast>0}getMaxCurveOffset(){return Math.max(...this.view.presenter.allCurves.map(e=>e.shift))}goToLatest(e=!1){if(this.canGoToLast()||e){let e=0!==this.barsToLast?this.barsToLast+this.xScale.marginBars+1:0;this.xScale.shiftBars(e),this.view.setPriceAxesDomains(),this.view.redraw()}}setViewBox(e){this.viewBox=e;let{x:t,width:i}=this.viewBox;this.xScale.range([t,t+i])}heightNeeded(e){if(!this.isVisible)return 0;let t=this.view.presenter.display.chart.fontFamily,{fontWeight:i,fontSize:s}=this.config;e.save(),e.font=`${i} ${s}px ${t}`;let{innerTickSize:r,tickPadding:n,indicatorPadding:a}=this.config,o=iF(e,1)+r+n+a;return e.restore(),o}getTickGetter(e){if(this.overrideTickGetter)return this.overrideTickGetter;let t=this.view.presenter.display.xAxis.isOrdinal||!1,i=function(e){switch(e.agg.unit){case G.Tick:return new hS(e);case G.Intraday:return new hA(e,e.agg.size);case G.Day:return new hT(e);case G.Week:return new hv(e);case G.Month:case G.Quarter:return new hP(e);case G.Year:return new hC(e);default:throw Error(`Aggregation unit ${G[e.agg.unit]} not supported.`)}}(e);return t?yo:e=>i.getTick(e)}getTicks(e){let t,i;if(eF(this.lastUsedOptions)&&(t=e.agg,i=this.lastUsedOptions.agg,t.unit===i.unit&&t.size===i.size&&t.spec===i.spec)&&e.unitWidth===this.lastUsedOptions.unitWidth&&e.barWidth===this.lastUsedOptions.barWidth&&e.extent[0]===this.lastUsedOptions.extent[0]&&e.extent[1]===this.lastUsedOptions.extent[1]&&e.formatString===this.lastUsedOptions.formatString&&e.minTickInterval===this.lastUsedOptions.minTickInterval&&eF(this.ticks))return this.ticks;this.lastUsedOptions=e;let s=this.getTickGetter(e),r=Math.max(0,e.extent[0]),n=Math.min(this.xScale.timeline.withPrologEpilogLength-1,e.extent[1]+1);return this.ticks=this.view.presenter.timeline.slice(r,n).map((e,t)=>{if(!eF(e)||Number.isNaN(e.getTime()))return null;let i=s(e);return eF(i)&&(i.index=r+t),i}).filter(e=>eF(e)),this.ticks}normalizeDuration(e){let t=function(){let e=Object.keys(hh);return 1===hh.Day.Multipliers[0]&&e.forEach(e=>{let t=hh[e],i=eQ(t.Period);t.One=+i,t.Multipliers=t.Multipliers.map(e=>e*i)}),hh}(),i=t.Year,s=Object.keys(t);for(let r=0;r<s.length-1;++r){let n=t[s[r]].Multipliers,a=t[s[r+1]].Multipliers;if(e<=(eC(n)+eb(a))/2){i=t[s[r]];break}}let r=i.Multipliers,n=r.findIndex(t=>e<t),a=-1===n?eC(r):r[n];return"P1M"===i.Period?a*=.9:"P1W"===i.Period&&(a*=.84),a}draw(e){if(!this.isVisible)return;let{xAxis:{gridLines:t,textColor:i,minTickInterval:s,tickPixelInterval:r,format:n,forceTicksVisible:a},chart:{fontFamily:o}}=this.view.presenter.display,{fontWeight:l,fontSize:u,innerTickSize:h,tickPadding:c}=this.config,{x:d,y:p,width:f}=this.viewBox,{lineWidth:m,color:g,dashStyle:y}=t,S=iP(y);e.textAlign="center",e.font=`${l} ${u}px ${o}`,e.lineWidth=1,e.strokeStyle=g,e.fillStyle=i,e.setLineDash([]),ij(e,p,d,d+f);let A=this.xScale.extent(),T=e=>!eF(e)||!eF(e[0],e[1]);if(T(A))return;let v=t=>e.measureText(t).width,P=r>0?r:120,C=this.xScale.domain();if(T(C))return;let b=(C[1].getTime()-C[0].getTime())*P*.6/f,E=this.normalizeDuration(b),L=this.view.presenter.data.aggregation.isEndOfDay,_=d+f,M=({text:i,x:s,date:r,forced:n})=>{eF(r)&&(n||iY(e,s,p,p+h),e.fillText(i,s,p+h+c+.71*u),t.visible&&!n&&(e.save(),e.lineWidth=m,e.setLineDash(S),iY(e,s,0,p),e.restore()))},x={agg:this.view.presenter.data.aggregation,unitWidth:v("M"),barWidth:this.xScale.bar.width,extent:A,formatString:n,minTickInterval:s||0,duration:b},I=this.getTicks(x),D={date:tz.ZERO_DATE,priority:999,x:-999,text:"",index:-1,textWidth:0};I.forEach(e=>{e.x=this.xScale.indexToX(e.index),e.textWidth=v(e.text);let{x:t,textWidth:i}=e,r=t;if(a){let s=i/2;e.x=r=(r=t-s<d?d+s:t)+s>_?_-s:r,e.forced=t!==r}else e.forced=!1;((e,t)=>{let i,r;if(e.date.valueOf()===tz.ZERO_DATE.valueOf())return!0;if(i=e.date,r=t.date,(eF(i)?uL(r,i):tz.FIFTY_YEARS_MILLIS)<s)return!1;let n=t.x-e.x,a=t.date.getTime()-e.date.getTime();return!(e.x+e.textWidth/2>=t.x-t.textWidth/2)&&(n>P||!!L&&a>=E)})(D,e)?(M(D),D=e):e.priority<D.priority&&(D=e)}),M(D),this.drawTimeTransitions(e),this.drawTimeAdornments(e)}drawTransitionsFor(e,t,i,s){let r=this.xScale.domain(),n=this.view.presenter?.mainPlot?.timeSeries.container;if(!eH(n))return;let a=n.getTimeData(),o=null===t?a:n.getData(t);if(!eF(o))return;let l=e_(a,+r[0],Number),u=e_(a,+r[1],Number,eL,l);if(l<u){s.save();let t=iZ();t.prolog(s),s.strokeStyle=e.color,s.lineWidth=e.width,s.setLineDash(iP(e.dashStyle));let r=null;for(let e=l;e<u;++e){let t=o[e];if(i(t,r)){let i=a[e],n=this.xScale.timeToX(i);eF(n,r)&&iY(s,n,0,this.viewBox.y),r=t}}t.epilog(s),s.restore()}}drawTimeTransitions(e){let t=this.xScale.domain();if(!eH(t)||!eF(t[0],t[1]))return;let i=this.view.presenter,{xAxis:{contractTransition:s,cycleTransition:r}}=i.display,n=(e,t)=>e!==t;s.enabled&&i?.data?.aggregation.isMultiContract&&this.drawTransitionsFor(s,ag.Symbol,n,e),r.enabled&&(i?.data?.aggregation.isIntraday?this.drawTransitionsFor(r,ag.TradingDay,n,e):i?.data?.aggregation.unit===G.Day?this.drawTransitionsFor(r,null,(e,t)=>!nA(e,t),e):i?.data?.aggregation.unit===G.Week&&this.drawTransitionsFor(r,null,(e,t)=>!nE(e,t),e))}getAnnXScore(e,t){return[nS,nb,nA,nE].map((i,s)=>(4-s)*Number(i(e,t))).reduce((e,t)=>e+t,0)}annTimeToX(e){let t=this.xScale.timeToIndex(e);if(!eH(t))return null;let i=this.xScale.timeline.at(t),s=this.xScale.timeToX(e);if(!(t>0)||i.valueOf()===e.valueOf())return s;{let r=t-1,n=this.xScale.timeline.at(r),a=this.xScale.indexToX(r);if(!this.view.presenter.display?.xAxis?.isOrdinal){if(n.valueOf()>e.valueOf())return s;let t=this.getAnnXScore(n,e),r=this.getAnnXScore(i,e);return t>r?a:r>t?s:this.view.presenter?.data?.aggregation?.isIntraday?a:s}return a+(s-a)*((e.valueOf()-n.valueOf())/(i.valueOf()-n.valueOf()))}}drawTimeAdornments(e){e.save();let t=this.view.presenter,{chart:{fontFamily:i},xAxis:{preventLabelOverlap:s}}=t.display,r=[],n=t.mainPane?.getBoundsWithoutScales()??new iw(0,0,0,0);t.allAnnotations.concat(t.plotAnnotations).forEach(i=>{r.push(...i.getTimeScaleAdornments().map(i=>{let s=this.annTimeToX(i.time);if(s<n.x||s>n.x+n.width)return null;let r=hM(t,this.view.presenter?.display?.xAxis?.isOrdinal?i.time:this.xScale.xToTime(s)),a=e.measureText(r).width/2;return{x:s,value:r,color:i.color,halfWidth:a}}).filter(e=>null!=e))}),r.sort((e,t)=>e.x-t.x),s&&function(e,t){let i=e.length-1;e.forEach((e,s,r)=>{let n=0===s,a=n?null:r[s-1],o=(({x:e,halfWidth:t})=>e-t-4)(e),l=n?t.x:(({x:e,halfWidth:t})=>e+t+4)(a);if(e.x-e.halfWidth<t.x&&(e.x=g9(t.x,e.halfWidth)),o<l)e.x=g9(l,e.halfWidth+4);else{let t=(({x:e,halfWidth:t})=>e+t+4)(e),n=s<i?(({x:e,halfWidth:t})=>e-t-4)(r[s+1]):Number.MAX_SAFE_INTEGER;if(t>n){let i=g8(e.x,t-n),s=g8(e.x,e.halfWidth-2);e.x=Math.max(s,i,g9(l,a?.halfWidth??0))}}(({x:e,halfWidth:t})=>e+t+4)(e)>t.x+t.width&&(e.x=g8(t.x+t.width,e.halfWidth))})}(r,this.viewBox),r.forEach(t=>{let s=iI(t.color);new g7({position:"bottom",fontSize:this.config.fontSize,fontFamily:i,padding:this.config.indicatorPadding,strokeColor:tz.COLOR_TRANSPARENT,textColor:s,backgroundColor:t.color,arrowLength:this.config.innerTickSize}).draw(e,t.x,this.viewBox.y+1,t.value)}),e.restore()}drawCrosshair(e,{x:t}){let i=this.view.presenter,s=i.display.xAxis,{enabled:r,showValue:n,color:a,dashStyle:o,format:l}=s.crosshair,u=this.xScale.xToTime(t);if(!(eF(u)&&oC(u)))return!1;if(!r)return!0;t=this.xScale.timeToX(u);let h=iP(o);e.strokeStyle=a,e.setLineDash(h);let c=iZ();if(c.prolog(e),iY(e,c.adjust(t),0,c.adjust(this.viewBox.y)),c.epilog(e),!n||!s.visible)return!0;let d=hM(i,u,eF(s.format)?l:void 0);this.crosshairIndicator.draw(e,t,this.viewBox.y+1,d,void 0,this.viewBox.height-2);let{plotHover:p}=i.display.chart;return p&&i.allPlots.filter(e=>e.visible).forEach(i=>i.curves.forEach(i=>i.drawHover(e,u,t))),!0}}let yu={mousedown:"onMouseDown",mousemove:"onMouseMove",mouseup:"onMouseUp",dblclick:"onMouseDblClick",contextmenu:"onContextMenu",mouseover:"onMouseEnter",mouseout:"onMouseLeave",wheel:"onWheel",touchstart:"onMouseDown",touchmove:"onMouseMove",touchend:"onMouseUp",keydown:"onKeyDown"},yh={Shift:"shiftKey",Alt:"altKey",Control:"ctrlKey",Meta:"metaKey"};class yc{view;subscriptions;constructor(e){this.view=e,this.subscriptions=[]}init(e){let t=eO();Object.keys(yu).filter(e=>!e.startsWith("touch")||t).forEach(t=>{let i=e=>{let i=yu[t];!0===this.notifyActiveTool(i,e)&&e.preventDefault()};e.addEventListener(t,i),this.subscriptions.push(()=>{e.removeEventListener(t,i)})})}shutdown(){this.subscriptions.forEach(e=>e()),this.subscriptions=[]}notifyActiveTool(e,t){let i=this.view.presenter;if(void 0===i||null===i.activeTool)return!1;let s=this.getPayload(t,i),r=i.activeTool,n=!1;return"function"==typeof r[e]&&(n=r[e](s)||!1),n}getPayload(e,t){let i=e instanceof MouseEvent,s=eO()&&e instanceof TouchEvent;if(i||s){let r={x:0,y:0};if(s&&1===e.touches.length){let t=e.touches[0],{left:i,top:s}=e.target.getBoundingClientRect();r.x=t.clientX-i,r.y=t.clientY-s}else i&&(r.x=e.offsetX,r.y=e.offsetY);let n={button:i?e.which:et.Left,offset:r,view:t.view,presenter:t,originalEvent:e,getModifier:t=>e[yh[ei[t]]]};if(e instanceof WheelEvent&&(n.delta=e.shiftKey?e.deltaX:e.deltaY),s&&2===e.touches.length){let t=e.touches[0],i=e.touches[1];n.pinchZoom=!0;let s=t.clientX-i.clientX,r=t.clientY-i.clientY;n.pinchDistance=Math.sqrt(s*s+r*r)}return this.view.splitters.forEach((e,t)=>{e.contains(r)&&(n.splitter=[t,t+1])}),t.panes.forEach(e=>{let t=e.getBounds();if(eF(t)&&t.contains(r)){let t=e.axes.find(e=>e.viewBox?.contains(r));t?n.priceAxis=t:n.point=e.axes.find(e=>e.primary).toAnnotationPoint(r)}}),n}if(e instanceof KeyboardEvent)return{key:e.key??e.keyIdentifier,code:e.keyCode||e.charCode,repeat:e.repeat,presenter:t,getModifier:t=>e.getModifierState(ei[t])}}}let yd=uf.concat(ag.PercentChange);class yp{view;id;isOptionsChart;constructor(e){this.view=e,this.isOptionsChart=!1,this.id=`bc-legend-${e1()}`}getLegendElem(){let e=this.view.el;return tH(this.id,e,"div")}update(){let e=this.getLegendElem(),t=hj(this.presenter.mainPane);if(!eF(t))return;this.isOptionsChart=this.mainPlot.title.startsWith(tz.FAKE_SYMBOL_PREFIX);let{left:i,right:s,top:r,width:n}=t;mY(e,"row",i,s,r,n),tF(e,{"bcharts-card":!0,"bcharts-legend":!0});let a=this.mainPlot,o=a.isSeasonal||this.isOptionsChart?this.getFirstColorBadge(a):"",l=this.getPlotTitle(a),u=this.maybeGetQuote(),h=this.div(`${o} ${l} `)+this.div(`${u}`),c=this.maybeGetAdditionalPlots();e.innerHTML=`${h} ${c}`}remove(){this.getLegendElem().remove()}get presenter(){return this.view.presenter}get mainPlot(){return this.presenter.mainPlot}getAttributes(e){return Object.entries(e).map(([e,t])=>{if(null===t)return"";let i=Array.isArray(t)?t.join(" "):t;return`${e} = "${i}" `}).join(" ")}span(e,t={}){return`<span ${this.getAttributes(t)}>${e}</span>`}div(e){return`<div class="plot" style="flex: 0 0 auto">${e}</div>`}get meta(){return this.mainPlot.metaData}isSingleSymbolSeasonal(e){return e.isSeasonal&&!e.hasComputation}format(e,t,i){return(i??this.meta).format(e,t)}spanAsName(e){return this.span(e,{class:"field-name"})}spanAsValue(e,t=null,i=null){return this.span(e,{class:["field-value",t],style:i})}getQuoteFromRecord(e){let t=yd.map(t=>e.getValue(t));if(ey(t)){let e=t[4],i=`field-${e>0?"up":e<0?"down":"same"}-value`,s=t.slice(0,-1).map((e,t)=>{let s=yd[t],r=this.format(e,s),n=hX(s);return`${this.spanAsName(n)}${this.spanAsValue(r,i)}`}).join(" "),r=this.spanAsValue(`(${this.format(eC(t),eC(yd))})`,i);return`${s} ${r}`}return""}maybeGetQuote(){if(this.mainPlot.isSymbol&&this.mainPlot.timeSeries?.record?.isValid){let e=Sp().getRecordSource().getRecord(this.mainPlot.timeSeries.record.symbol);return this.getQuoteFromRecord(e)}if(this.mainPlot.isExpression&&this.mainPlot.record.isValid){let e=this.mainPlot.record;return e.evaluate(),this.getQuoteFromRecord(e)}return""}getTitle(e,t,i){let s=this.span(`${e.name} (${e.symbol})`,{"data-plot-id":i,class:["value-title",t?"value-main":null]}),r=t?` ${this.span(e.exchange,{class:"value-subtitle"})}`:"";return`${s}${r}`}getPlotTitle(e){if(e.isSymbol)return this.getTitle(e.metaData,e.main,e.id);if(!(this.isSingleSymbolSeasonal(e)&&0===e.offset&&(e.symbols?.length??0)>0))return this.span(e.title,{"data-plot-id":e.id,class:"value-title"});{let t=Sp().getMetaDataSource().getMetaData(e.getActualSymbols()[0]);return this.getTitle(t,!0,e.id)}}getFirstColorBadge(e){return hk("rectangle",e.mainCurve.colors[0])}getLastValues(e){return this.isOptionsChart?"":yt(e).filter(e=>eF(e.value)).map(t=>{let i=this.format(t.value,t.field,e.metaData);return this.spanAsValue(i,null,`color:${t.color}`)}).join(" ")}canBeDeleted(e){return e.isStudy||!e.main&&this.isOptionsChart}maybeGetAdditionalPlots(){let e=this.presenter.mainPane.axes.map(e=>e.plots).flat().filter((e,t)=>!e.main||e.isSeasonal&&t>0),t=this.presenter.display.yAxis.showLastValue;return e.length>0?e.map(e=>{let i=this.getFirstColorBadge(e),s=this.getPlotTitle(e),r=this.canBeDeleted(e)?hz(e.id):"",n="All"===t||e.isSeasonal?"":this.getLastValues(e);return this.div(`${r} ${i} ${s} ${n}`)}).join(" "):""}}class yf{presenter;splitters=[];canvasContainer=null;mouseCanvas=null;mainCanvas=null;mouseContext;mainContext;leftOffset=0;rightOffset=0;legend;notifyLayoutChanged;el=null;listeners=[];tooltip;width;height;customEventPopup=null;goToLatestButton=null;xAxis;eventCapture;resetZoomAndVisibleRange=!1;constructor(){this.legend=new yp(this),this.draw=this.draw.bind(this),this.notifyLayoutChanged=function(e,t=100){var i,s;let r;return i=t=>eN(e,t),s=t,r=!1,function(...e){r||(i.apply(this,e),r=!0,setTimeout(function(){r=!1},s))}}(ay.CH_CHTLAYOUTCHANGED,tz.LAYOUT_THROTTLE_DELAY)}get canShowLegend(){if(!this.presenter.hasLegend)return!1;let e=this.presenter.display.chart.showLegend;return"boolean"!=typeof e||!!e}updateLegend(){this.canShowLegend&&this.legend.update()}removeLegend(){this.legend.remove()}findSvgParentWithClass(e,t){return[e,e.parentElement,e.parentElement.parentElement].find(e=>eF(e)&&e.className===t)}onNonToolHandledMouseDown(e){let t=this.presenter,i=e.target;if("string"==typeof i.className&&i.className.split(" ").includes("value-title"))t.onCardClicked(i);else{let s=this.findSvgParentWithClass(i,"move-pane");if(eH(s))return void t.onMovePaneClicked(s);let r=this.findSvgParentWithClass(i,"delete-plot");if(eH(r))return void t.deletePlotClicked(r);let n=this.findSvgParentWithClass(i,"show-hide-plot");if(eH(n))return void t.showHidePlotClicked(n);let a=this.findSvgParentWithClass(i,"more-actions");if(eH(a))return void t.plotMoreActionsClicked(a,e)}}initialize(e){this.presenter=e,this.el=this.presenter.hostElement;let t=new ResizeObserver(e=>{for(let t of e){let{width:e,height:i}=t.contentRect;this.setSize(e,i),eF(this.tooltip)&&this.tooltip.repositionAuto()}});t.observe(this.el.parentElement),this.listeners.push(()=>t.unobserve(this.el.parentElement));let i=e=>this.onNonToolHandledMouseDown(e);this.el.addEventListener("mousedown",i),this.listeners.push(()=>this.el.removeEventListener("mousedown",i)),tN(this.el,{flex:1,display:"flex",position:"relative","flex-direction":"column","touch-action":"pan-x pan-y"}),this.tooltip=new m$(this);let s=Sp().config.getCustomEventPopup;this.customEventPopup=s?s(this):null;let{clientHeight:r,clientWidth:n}=this.el;this.width=n,this.height=r,this.canvasContainer=tB(this.el,"div"),tV(this.canvasContainer,{class:"chart-canvas-container"}),tN(this.canvasContainer,{flex:1,display:"flex","flex-direction":"column",position:"relative",height:"100%"}),this.mainCanvas=tB(this.canvasContainer,"canvas");let a={height:`${r}px`,width:`${n}px`,"z-index":2,position:"absolute",top:0,left:0};tN(this.mainCanvas,a),this.mouseCanvas=tB(this.canvasContainer,"canvas"),tV(this.mouseCanvas,{tabIndex:0}),a["z-index"]=3,a.outline="none",tN(this.mouseCanvas,a),this.goToLatestButton=tB(this.el,"button"),tW(this.goToLatestButton,`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
19
19
  <path d="M13.707 17.707l5-5c0.391-0.391 0.391-1.024 0-1.414l-5-5c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414l4.293 4.293-4.293 4.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0zM6.707 17.707l5-5c0.391-0.391 0.391-1.024 0-1.414l-5-5c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414l4.293 4.293-4.293 4.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0z"></path>
20
- </svg>`),tN(this.goToLatestButton,{position:"absolute",right:0,bottom:0,"z-index":3}),tV(this.goToLatestButton,{class:"go-to-latest"}),this.goToLatestButton.onclick=()=>{this.xAxis.goToLatest()},this.listeners.push(()=>{this.goToLatestButton.onclick=null}),this.mainContext=this.mainCanvas.getContext("2d"),this.mouseContext=this.mouseCanvas.getContext("2d"),this.splitters=[],this.xAxis=new yl(this),this.eventCapture=new yc(this),this.eventCapture.init(this.mouseCanvas),this.setChartSize(n,r);let o=tO(this.el);eF(tR(`.${tz.SVG_ICONS_DOM_NODE}`,o))||function(e){let t=tB(e,"div");tV(t,{class:tz.SVG_ICONS_DOM_NODE});let i=Object.keys(hN).map(e=>`<symbol id="${hB(e)}" viewBox="0 0 1024 1024">${hN[e]}</symbol>`).join("");t.innerHTML=`<svg style="display:none" xmlns="http://www.w3.org/2000/svg" version="1.1"><defs>${i}</defs></svg>`}(o)}reinitialize(){this.el&&tk(".bcharts-card",this.el).forEach(e=>e.remove()),this.customEventPopup?.hide(),this.tooltip.hide(),this.tooltip.setMode(this.presenter.display.tooltip.mode),this.resetZoomAndVisibleRange?this.xAxis=new yl(this):this.xAxis?.updateConfigFromModel(),this.recalculateLayout(),this.redraw()}setSize(e,t,i=!1){this.setChartSize(e,t),this.redraw(i)}setChartSize(e,t){let i={width:`${e}px`,height:`${t}px`};tN(this.el,i),this.width=e,this.height=t;let s=globalThis.devicePixelRatio||1,r={height:this.height*s,width:this.width*s};[this.mainCanvas,this.mouseCanvas].forEach(e=>{tV(e,r),tN(e,i)}),this.mainContext.scale(s,s),this.mouseContext.scale(s,s),this.recalculateLayout(),this.presenter&&mG(this.presenter)}widthNeeded(e,t){let i=this.presenter.allAxes.filter(e=>e.onTheRight===t);return 0===i.length?0:Math.max(...i.map(t=>t.widthNeeded(e)))}recalculateLayout(){if(!this.isHostElementVisible)return;this.leftOffset=0,this.rightOffset=0,this.presenter.allAxes.forEach(e=>e.clearTicks()),this.splitters.length=0;let e=this.xAxis.heightNeeded(this.mainContext),t=this.widthNeeded(this.mainContext,!0),i=this.widthNeeded(this.mainContext,!1),s=this.height-e,r=this.presenter.panes,n=em(r.map(e=>e.height)),a=0,o=tz.PANE_SPLITTER_PERCENT_HEIGHT/100,l=Math.floor(o*s);n*=1+(r.length-1)*o;let u=this.presenter.display?.yAxis?.primaryOnTheLeft??!1;this.presenter.display.yAxis.visible&&(r.some(e=>e.axes.length>1)?(this.leftOffset=i,this.rightOffset=t):u?this.leftOffset=i:this.rightOffset=t),r.forEach((e,i,r)=>{let o=i===r.length-1,u=Math.floor(s*e.height/n),h=new iw(0,a,this.width,u);e.setViewBox(h);let c=new iw(this.width-this.rightOffset,a,t,u),d=new iw(0,a,this.leftOffset,u),p=e=>e.setViewBox(e.onTheRight?c:d);if(p(e.axes[0]),e.axes[1]&&p(e.axes[1]),a+=u,!o){let e=new iw(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,l);this.splitters.push(e),a+=l}});let h=new iw(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,e);this.xAxis.setViewBox(h),tN(this.goToLatestButton,{right:`${t+5}px`,bottom:`${e+5}px`}),this.updateLegend(),this.xAxis.setDomain(),this.setPriceAxesDomains(),this.notifyLayoutChanged({chart:this.presenter.accessor})}setPriceAxesDomains(){this.presenter.allAxes.forEach(e=>{e.setDomain(),e.updateFullDomain()}),this.presenter.priceDomainsUpdated()}draw(){for(let e of(this.mainContext.save(),this.mainContext.miterLimit=1,this.drawBackground(this.mainContext),this.presenter.panes))e.drawBackground(this.mainContext);for(let e of(this.xAxis.draw(this.mainContext),this.presenter.panes))e.draw(this.mainContext);this.drawSplitters(this.mainContext),this.presenter.title.draw(this.mainContext);let e=Sp().config.showGoToLatest,{showGoToLatest:t}=this.presenter.display.chart,i=eF(e)?e:t;this.goToLatestButton.style.display=i&&this.xAxis.canGoToLast()?"block":"none",this.mainContext.restore()}get isHostElementVisible(){return eF(this.el)&&eF(this.el.offsetParent)}redraw(e=!1){this.isHostElementVisible&&(e?this.draw():Sp().redraw(this.presenter.hostElement))}drawBackground(e){let t=this.presenter.display.chart.backgroundColor;e.clearRect(0,0,this.width,this.height),e.fillStyle=t,e.fillRect(0,0,this.width,this.height)}drawCrosshair({ap:e,offset:t}){let i=this.mouseContext;return i.clearRect(0,0,this.width,this.height),!!e&&!!this.xAxis.drawCrosshair(i,t)&&(this.presenter.display.yAxis.visible&&e.axis.pane.drawYCrosshair(i,t),!0)}drawSplitters(e){e.strokeStyle=(e=>{let t=iM(e);return iD(iE(function({r:e,g:t,b:i,a:s}){return{r:255-e,g:255-t,b:255-i,a:s}}(t),t,.7))})(this.presenter.display.chart.backgroundColor),e.lineWidth=2,this.splitters.forEach(t=>{let{x:i,y:s,width:r,height:n}=t,a=s+n/2;e.beginPath(),e.moveTo(i,a),e.lineTo(i+r,a),e.stroke()})}toTime(e){return this.xAxis.xScale.xToTime(e)}toIndex(e){return this.xAxis.xScale.timeToIndex(e)}toX(e){return this.xAxis.xScale.timeToX(e)}setCursor(e){let t=function(e){switch(e){case ee.Arrow:default:return"default";case ee.Crosshair:return"crosshair";case ee.Hand:return"pointer";case ee.Move:return"move";case ee.ResizeVertical:return"ns-resize";case ee.Grabbing:return"grabbing";case ee.ResizeHorizontal:return"ew-resize"}}(e);tN(this.el,{cursor:t})}shutdown(){this.listeners.forEach(e=>e()),this.eventCapture&&this.eventCapture.shutdown(),this.tooltip&&this.tooltip.remove(),this.el&&tk(".bcharts-card",this.el).forEach(e=>e.remove()),this.canvasContainer.remove()}getEventRadius(){return Math.max(this.xAxis.xScale.bar.width/2,tz.MIN_EVENT_RADIUS)}}class ym{view;popupElement;date;value;visible;_initialized;constructor(e){this.view=e,this.date=null,this.value=null,this.visible=!1,this._initialized=!1}initialize(){this.popupElement=tB(this.view.el,"div"),tV(this.popupElement,{id:`${this.view.presenter.elementId}-custom-event-host`}),tN(this.popupElement,{visibility:"hidden",position:"absolute","z-index":30,top:"0px",left:"0px",padding:"5px 10px 10px 10px",display:"flex","flex-direction":"column",background:"var(--chartPopupElemBg, #999)","box-shadow":"0px 2px 10px rgba(0,0,0,.3)","border-radius":"4px",border:"1px solid var(--chartPopupElemBorderColor, #888)","max-height":"400px",overflow:"auto"});let e=tB(this.popupElement,"a");tV(e,{class:"custom-event-close-button"}),tN(e,{position:"absolute",right:"10px",top:"5px",fill:"var(--text-color,#888)",cursor:"pointer"}),e.innerHTML='<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="12px" height="12px"><use xlink:href="#bchart-icon-delete"></use></svg>',e.addEventListener("click",e=>this.hide()),this._initialized=!0}showValue(){}show(e,t,i){this._initialized||this.initialize(),this.date=t,this.value!==i&&(this.value=i,this.showValue()),tN(this.popupElement,{visibility:"visible",top:`${e.y}px`,left:`${e.x}px`,width:"310px"}),this.visible=!0}hideValue(){}hide(){this.visible&&(this.hideValue(),tN(this.popupElement,{visibility:"hidden"}),this.visible=!1)}}function yg(e,t){if(!(e.annotations&&e.annotations.length>0))return;let i=t.annotations||[];t.annotations=i.concat(e.annotations)}let yy='..axes{..plots{.type==="Study"}}';var cp=N("c15IW");let yS={ok:!1,change:void 0,toApply:void 0};class yA{presenter;paused;undoStack;redoStack;initial;isPaused;constructor(e){this.presenter=e,this.paused=null,this.undoStack=[],this.redoStack=[],this.initial=new Map,this.isPaused=!1,this.clear()}clear(e=!1){this.undoStack=[],this.redoStack=[],this.initial=new Map,e&&this.presenter.allAnnotations.forEach(e=>this.initial.set(e.uid,my(e,el.Moved)))}done(e){if(this.isPaused){this.paused=e;return}this.undoStack.push(e),this.redoStack.length=0}undo(){this.undoRedo(this.undoStack,this.redoStack,!0)}pause(){this.isPaused=!0}resume(e){this.isPaused=!1,e&&eH(this.paused)&&this.done(this.paused),this.paused=null}redo(){this.undoRedo(this.redoStack,this.undoStack,!1)}delete(e){let t={...e,id:"Delete"};this.presenter.handleAnnotationChange(t)}add(e){this.presenter.handleAnnotationChange({annotation:e,id:"Add"})}apply(e,t,i){if(!eF(e))return!1;switch(t){case el.None:case el.Undo:case el.Redo:So(`Unexpected tool change ${el[t]} for undo/redo`,"warn");break;case el.Created:i?this.delete(e):this.add(e);break;case el.Deleted:i?this.add(e):this.delete(e);break;default:{let t={...e,id:"Update"};this.presenter.handleAnnotationChange(t)}}let s=this.presenter.allAnnotations.find(t=>t.uid===e.uid),r=i?el.Undo:el.Redo;return eF(s)&&this.presenter.onAnnotationModifiedByTool(s,r),!0}can(e){let t=e?this.undoStack:this.redoStack;if(t.length<1)return yS;let i=eC(t),s=i.toolChange;if(!(e&&s!==el.Deleted&&s!==el.Created))return{ok:!0,change:s,toApply:i};let r=eE(t,e=>e.uid===i.uid,t.length-2),n=-1!==r?t[r]:null,a=null===n;return a&&!this.initial.has(i.uid)?yS:{ok:!0,change:s,toApply:a?this.initial.get(i.uid):n}}get canUndo(){return this.can(!0).ok}get canRedo(){return this.can(!1).ok}undoRedo(e,t,i){let{ok:s,change:r,toApply:n}=this.can(i);if(!s)return;let a=e.pop();this.apply(n,r,i),t.push(a)}}class yT{presenter;text;align;verticalAlign;x;y;style;constructor(e){this.presenter=e,this.text=null,this.align="center",this.verticalAlign="top",this.x=0,this.y=0,this.style={color:"#333",fontSize:18}}update({style:e,...t}){Object.assign(this,t),Object.assign(this.style,e)}draw(e){if(!this.text)return;let{fontFamily:t}=this.presenter.display.chart,{fontSize:i,color:s,fontWeight:r}=this.style,{x:n,y:a,width:o,height:l}=this.presenter.mainPlot.axis.pane.getBounds(),u=n+this.presenter.view.leftOffset,h=n+o-this.presenter.view.rightOffset,c=u;c="center"===this.align?o/2:"right"===this.align?h:u;let d=a+i;"middle"===this.verticalAlign?d=a+i+l/2:"bottom"===this.verticalAlign&&(d=a+l),c+=this.x,d+=this.y,e.save(),e.font=`${r||"normal"} ${i}px ${t}`,e.textAlign=this.align,e.textBaseline="bottom",e.fillStyle=s,e.fillText(this.text,c,d),e.restore()}}function yv(e={}){let t=this.allPlots;if(!t.every(e=>eF(e.timeSeries)&&e.timeSeries.hasData))return"No data to export";let i=e.excludeHeader??!1,s=e.numDecimals??null,r=e.excludeFields??[],n=e=>{let t=new Map;return e.main&&(t.set(ag.DateTime,0),this.data.aggregation.isMultiContract&&!e.isExpression&&t.set(ag.Symbol,0)),e.curves.forEach(e=>{e.fields.forEach(i=>{r.includes(i.id)||t.set(i,e.shift)})}),Array.from(t)},a=this.data.aggregation.isEndOfDay?tz.FMT_ISO_DATE_ONLY:tz.FMT_EXPORT_ALL_BUT_MILLIS,o=(e,t)=>e===ag.DateTime?o3(t,a):(eF(s,t)?eB(t,s):t)?.toString()??"",l={},u=this.timeline.lastSeriesIndex,h=eb(this.mainPlot.timeSeries.container.getTimeData()),c=e_(this.timeline,+h,Number,hw),d=(e,t)=>{let i=this.timeline.at(e),s=t.timeSeries.container,r=s.getTimeData(),u=e_(r,+i,Number,eL,l[t.id]||0),h=+i==+r[u];return h&&(l[t.id]=u),n(t).map(([t,n])=>{if(0===n)if(h)return o(t,s.getData(t)[u]);else if(t===ag.DateTime)return o3(i,a);else return"";{let i=this.timeline.at(e-n),a=e_(r,+i,Number,eL,0);return+i==+r[a]?o(t,s.getData(t)[a]):""}})},p=e=>{let i=t.map(e).flat();return i.slice(1).every(e=>0===e.length)?null:i.join(",")},f=[];i||(f.push(p(e=>{let t=Array(n(e).length).fill("");return t[0]=`"${Z[e.type]}: ${e.title}"`,t})),f.push(p(e=>n(e).map(([e,t])=>`"${e.name}"`))));let m=[0,0];this.allCurves.forEach(e=>{!e.fields.every(e=>r.includes(e.id))&&(e.shift<0&&(m[0]=Math.min(m[0],e.shift)),e.shift>0&&(m[1]=Math.max(m[1],e.shift)))});for(let e=c+m[0];e<=u+m[1];e++){let t=p(eh(d,e));null!==t&&f.push(t)}return f.join("\n")}function yP(e={}){let t=this.view.mainCanvas,{width:i,height:s}=t,{width:r,height:n,title:a}=e,o=(e,t)=>{let i=document.createElement("canvas");return i.width=e,i.height=t,i.getContext("2d")},l=o(i,s),u=globalThis.devicePixelRatio;if(l.drawImage(t,0,0),l.scale(u,u),eH(a)){let e=new yT(this);e.update(a),e.draw(l)}let h=this.mainPlot?.timeSeries.container?.getLastDataPoint(ag.DateTime);if(eH(h)){let{fontFamily:e}=this.display.chart,{fontWeight:i,fontSize:s}=this.mainAxis.config;l.font=`${i} ${1.2*s}px ${e}`,l.textBaseline="top";let r=1.5*s,n=getComputedStyle(t),a=n.getPropertyValue("--app-hc-color"),o=n.getPropertyValue("--app-color-pl"),u={x:tz.CARDS_X_OFFSET,y:tz.CARDS_Y_OFFSET},c=hY(this,h,u,void 0,!1,0),d=`${c.date} ${c.time??""}`.trim(),[p,f]=[1,5],m=(e,t)=>l.measureText(e).width+t,g=(e,t,i,s,r)=>(l.fillStyle=s,l.fillText(e,t,i),m(e,r)),y=(e,t)=>e.type===Z[t];c.panes.forEach(e=>{let{top:t,left:i,width:s,right:n}=e.bounds,l=i+s-n-f,h=i+u.x,c=t+u.y;e.plots.some(e=>e.isMain)&&(h+=g(d,h,c,a,f)),e.plots.forEach((e,t)=>{let s,n=(s=e.name,e.isMain&&y(e,"Symbol")?s=`${e.description} (${e.name}) [${e.exchange}]`:y(e,"Study")&&(s=`${e.description} ${e.name.substring(e.name.indexOf(" "))}`),s),d=!y(e,"Study")&&e.values.length>1;if(!e.isMain&&t>0){let t=h+m(n,f);e.values.forEach(e=>{d&&(t+=m(e.abbreviation,p)),t+=m(e.value,f)}),t>=l&&(h=i+u.x,c+=r)}h+=g(n,h,c,a,f),e.values.forEach(e=>{d&&(h+=g(e.abbreviation,h,c,o,p)),h+=g(e.value,h,c,e.color,f)})})})}let c=e=>({width:r??i,height:n??s,data:e.toDataURL("image/png")});if(!(eH(r)&&eH(n)))return c(l.canvas);{let e=o(r,n);return e.drawImage(l.canvas,0,0,r,n),c(e.canvas)}}let yC=Symbol.for("__ias__");class yb{accessor;view;defaultTool;_activeTool;tooltipEnabled;timeline;sentInitialLoadNotification;_hostElement;undoRedoManager;title;display;model;data;panes;_hasLegend;renderTo;seriesChangedToken;metaChangedToken;streamingSubscription;_previousMask;_ohlcMask;selectedAnnotation;forceResetVisibleRange;_maxOffset;_isShutdown;notifySelectionChanged;notifyRecreated;notifyDefinitionChanged;constructor(e){this.accessor=e,this.tooltipEnabled=!0,this.sentInitialLoadNotification=!1,this._hostElement=null,this.panes=[],this.seriesChangedToken="",this.metaChangedToken="",this.streamingSubscription=null,this._previousMask=0,this.forceResetVisibleRange=!1,this._maxOffset=0,this._isShutdown=!1,this.defaultTool=gj("Default"),this._activeTool=this.defaultTool,this.timeline=new hR(this),this.undoRedoManager=new yA(this),this.title=new yT(this),this.notifySelectionChanged=eV(ay.CH_ANNSELECTIONCHANGED),this.notifyRecreated=eV(ay.CH_RECREATED),this.notifyDefinitionChanged=eV(ay.CH_DEFINITION_CHANGED)}getModel(){return this.model}get isEmpty(){return!eF(this.model)}notifyHost(e,t){eN(e,t)}async fromModel(e,t){if(this._isShutdown)return;eF(this.model)&&this.allPlots.forEach(e=>e.shutdown()),this.sentInitialLoadNotification=!1,this.clearSelection(),this.model=e;let i=ez(e);this.data=i.data,this.data.aggregation=n_(i.data.aggregation),this.display=i.display,eF(this.display.period)&&(this.display.period=eQ(this.display.period)),this.panes=i.panes.map(e=>{let t=new yr(this);return t.fromModel(e),t},this);let s=this.allPlots.map(e=>e.initialize());await Promise.all(s),this._isShutdown||(this.timeline.invalidate(),this.checkZoomAndVisibleRange(e,t),eF(e,t)&&this.notifyDefinitionChanged({chart:this.accessor}),this.reinitializeView())}checkZoomAndVisibleRange(e,t){if(this.view)if(this.forceResetVisibleRange)this.forceResetVisibleRange=!1,this.view.resetZoomAndVisibleRange=!0,this._maxOffset=0;else{let i=!t||function(e,t,i){let s={id:"Aggregation",context:{id:"Get"}};if(y_(nL(y5(s,t,i)),nL(y5(s,e,i)))||!yE(e.display?.xAxis?.visibleRange,t.display?.xAxis?.visibleRange)||e.display?.xAxis?.marginBars!==t.display?.xAxis?.marginBars||!yE(e.data?.range,t.data?.range)||e.data?.extendedHours!==t.data?.extendedHours||e.display?.period!==t.display?.period||e.display?.density!==t.display?.density)return!0;let r=n3(t),n=n3(e);if(function(e,t){let i=e=>e.curves[0],s=i(e),r=i(t),n=yL.includes(s.style),a=yL.includes(r.style);if(n!==a)return!0;if(!a)return!1;if(s.style!==r.style)return!0;if(t.inputs&&y_(eK(e.inputs),eK(t.inputs)))return!0;return!1}(r,n))return!0;let a=e=>{let t=e.toLowerCase();return n.type===e&&r.type===e&&r[t]!==n[t]},o=r.type!==n.type,l=a("Forward"),u=a("Expression"),h=a("Symbol");return o||l||u||h}(e,t,this);this.view.resetZoomAndVisibleRange=i,i&&(this._maxOffset=0)}}closeView(){eF(this.view)&&(this.view.shutdown(),this.view=void 0)}reinitializeView(){this._isShutdown||(eF(this.view)?this.view.reinitialize():(this.view=new yf,this.view.initialize(this)),this.notifyRecreated({elementId:this.elementId}))}getCacheableEntities(e){this.isEmpty||this.allPlots.map(t=>t.getCacheableEntities(e))}get activeTool(){return this._activeTool}set activeTool(e){eF(this._activeTool.deactivated)&&this._activeTool.deactivated(this),this._activeTool=e,eF(this._activeTool.activated)&&this._activeTool.activated(this),this.notifyHost(ay.TL_CHANGED,{chart:this.accessor})}get mainPlot(){return this.allPlots.find(e=>e.main)}get mainAxis(){return this.mainPlot?.axis}get mainPane(){return this.mainAxis?.pane}get allAxes(){let e=[];return this.panes.forEach(t=>{t.axes.forEach(t=>{e.push(t)})}),e}get plotAnnotations(){let e=[];return this.allPlots.forEach(t=>{t.annotations?.forEach(t=>{e.push(t)})}),e}get allAnnotations(){let e=[];return this.allAxes.forEach(t=>{t.annotations.forEach(t=>{e.push(t)})}),e}get allPlots(){let e=[];return this.allAxes.forEach(t=>{t.plots.forEach(t=>{e.push(t)})}),e}findAxis(e){return this.allAxes.find(t=>t.id===e)}findPlot(e){return this.allPlots.find(t=>t.id===e)}get allCurves(){let e=[];return this.allPlots.forEach(t=>{t.curves.forEach(t=>{e.push(t)})}),e}findCurve(e){return this.allCurves.find(t=>t.id===e)}fixupDensityForForwards(){let e=this.allPlots.filter(e=>e.isForward).map(e=>e.timeSeries.container?.size??0);e.some(e=>e>0)&&(this.display.density=Math.max(...e))}onSeriesChanged(e,t){if(!this.view||!this.allPlots)return;let i=t.series,s=e=>e.timeSeries===i||e.eventsSeries===i,r=this.allPlots.find(s);if(!eF(r))return;let n=eF(r)&&r.main,a=!1,o=!1;if(e===ay.TS_TIMELINECORRECTION){if(!this.timeline.tryToCorrectLastBar(t.from,t.to))return;a=!0}let l=eF(t.index)?i.container.getTimeData()[t.index]:null,u=e===ay.TS_EVENTSCHANGED,h=this.view.xAxis,c=h.xScale;if(e===ay.TS_MANYCHANGED||u){if(n&&this.data.checkRange)if(eF(this.display.xAxis.visibleRange)){let e={id:"Period",context:{range:this.display.xAxis.visibleRange}};e[yC]=!0,this.accessor.change(e);return}else delete this.data.checkRange;r.isForward&&this.fixupDensityForForwards();let e=this.view.xAxis?.getMaxCurveOffset()??0;if(r.isStudy&&(e!==this._maxOffset&&(this._maxOffset=e,h.goToLatest(!0)),r.invalidateAssociatedAnnotations("NewChunkArrived")),(r.isSeasonal&&!h.wasVisibleRangeChanged||this.display?.xAxis?.isOrdinal)&&h.goToLatest(!0),t.part===en.Tail){let e=e_(this.timeline,l,Number,hw);h.shouldScrollIntoView(e)&&c.shiftBars(t.count)}this.timeline.invalidate(),this.allPlots.forEach(e=>e.invalidatePriceMappingCache()),a=!0}else if(e===ay.TS_DATAPOINTADDED){let e=this.timeline.mergeDateIntoTimeline(l);-1!=e&&h.shouldScrollIntoView(e)?(c.shiftBars(1),a=!0):o=!0,r.isStudy&&r.invalidateAssociatedAnnotations("DataPointAdded")}else e===ay.TS_DATAPOINTCHANGED&&(o=!0,r.isStudy&&r.invalidateAssociatedAnnotations("DataPointChanged"));if(!u&&s(this.mainPlot)&&i.hasData&&0===i.container.size&&this.notifyHost(ay.CH_NODATAFORMAINSYMBOL,{chart:this.accessor}),a&&this.view.recalculateLayout(),o&&(a&&So("Performance : redundant call to recompute price domains (layout recalculation took care of this)","warn"),this.allAxes.filter(e=>e.plots.includes(r)).forEach(e=>{e.setDomain(),eF(l)&&e.updateFullDomain(l)})),!this.sentInitialLoadNotification&&e===ay.TS_MANYCHANGED&&this.allPlots.every(e=>e.timeSeries&&e.timeSeries.hasData)){this.sentInitialLoadNotification=!0,this.notifyHost(ay.CH_ALL_DATA_PROJECTED,{chart:this.accessor}),mG(this);let e=this.display.period===tz.FIFTY_YEARS_MILLIS;this.mainPlot&&e&&(c.fitAllData=!0,c.adjustDomain())}this.view.redraw()}onMetaChanged(e,t){e===ay.MD_CHANGED&&this.view&&this.allPlots&&this.allPlots.find(e=>e.id===t.plot.id)&&(this.view.recalculateLayout(),this.view.redraw())}priceDomainsUpdated(){this.allPlots.forEach(e=>{e.notifyAboutPriceDomains&&e.onPriceDomainsUpdated()})}onScaleDomainChanged(e){let t=this.panes.indexOf(e.pane),i=e.pane.axes.indexOf(e),s={chart:this.accessor,paneIndex:t,axisIndex:i};this.notifyHost(ay.CH_AXISSCALECHANGED,s)}get previousMask(){return eF(this._previousMask)||(this._previousMask=aA(ag.PreviousClose)),this._previousMask}hasMatch(e,t){return e.some(e=>e.updated&&t)}get hasLegend(){return eF(this._hasLegend)||(this._hasLegend=Sp().config.mode===er[er.cmdtyView]),this._hasLegend}onStreamingUpdates(e){eF(this.view)&&(this.mainPlot.showPrevious&&this.hasMatch(e,this.previousMask)&&this.view.redraw(),this.hasLegend&&this.hasMatch(e,this.ohlcMask)&&this.view.updateLegend())}get ohlcMask(){return eF(this._ohlcMask)||(this._ohlcMask=aA(ag.Open,ag.High,ag.Low,ag.Close,ag.PreviousClose)),this._ohlcMask}updateMatches(e,t){if((e&this.ohlcMask)==0)return!1;let i=(e,t)=>eH(e)&&e.isValid&&e.hasSymbol(t);return this.mainPlot.isSymbol?i(this.mainPlot.timeSeries.record,t):!!this.mainPlot.isExpression&&i(this.mainPlot.record,t)}getStreamingSubscription(){return Sp().getRecordSource().subject.pipe(ub(e=>e.filter(e=>this.updateMatches(e.updated,e.data.symbol))),ov(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}get hostElement(){return this._hostElement}get elementId(){return eF(this._hostElement)?this._hostElement.id:null}initialize(t){if(this._hostElement=t instanceof HTMLElement?t:tR(`#${t}`),!this._hostElement)throw Error(`There is no element ${t} in the DOM`);this.renderTo=t,this.seriesChangedToken=e(cp).subscribe(ay.TS_ALL,this.onSeriesChanged.bind(this)),this.metaChangedToken=e(cp).subscribe(ay.MD_ALL,this.onMetaChanged.bind(this)),this.streamingSubscription=this.getStreamingSubscription()}shutdown(){return e(cp).unsubscribe(this.seriesChangedToken),e(cp).unsubscribe(this.metaChangedToken),eF(this.streamingSubscription)&&this.streamingSubscription.unsubscribe(),this.allPlots.forEach(e=>e.shutdown()),this.model=void 0,this.closeView(),this.notifyHost(ay.CH_SHUTDOWN,{elementId:this.elementId}),this._isShutdown=!0,!0}setSelection(e){this.selectedAnnotation=e,this.selectedAnnotation.isSelected=!0,this.selectedAnnotation.requestRedraw(),this.notifySelectionChanged({chart:this.accessor})}clearSelection(){eF(this.selectedAnnotation)&&(this.selectedAnnotation.isSelected=!1,this.selectedAnnotation.requestRedraw(),this.selectedAnnotation=void 0),this.notifySelectionChanged({chart:this.accessor})}resetActiveTool(){this.activeTool=this.defaultTool,this.view.setCursor(ee.Arrow)}print(e={}){let t=tB(document.body,"iframe");t.src="",t.style.display="none",t.onload=()=>{let{title:i}=e,s=yP.call(this,{title:i}),r=new Image;r.src=s.data,r.style.width="100%",t.contentDocument.body.appendChild(r),new Promise(e=>{let t=()=>{r&&void 0!==r.naturalWidth&&0!==r.naturalWidth&&r.complete?e():setTimeout(t,150)};t()}).then(()=>{let e=t.contentWindow;t.focus(),e.print(),t.remove()})}}setTitle(e,t=!1){this.title.update(e),eF(this.view)&&this.view.redraw(t)}enableTooltip(e){this.tooltipEnabled=e;let t=this.display.tooltip.mode===tz.TOOLTIP_CARDS;!e&&t&&this.hideCards()}get showTooltip(){return this.display.tooltip.visible&&this.tooltipEnabled}hideCards(e=!1){let t=this.display.tooltip,i=eO();!e&&t.visible&&t.mode===tz.TOOLTIP_CARDS&&tk(".bcharts-card",this.hostElement).forEach(e=>{let t=e.classList.contains("bcharts-card-move");i&&t||e.classList.contains("bcharts-legend")||(e.style.display="none")})}handleAnnotationChange(e){let t=(e,t=!0)=>({id:t?e.name:e.id,uid:e.uid,visible:e.visible});if("List"===e.id)return this.allAnnotations.map(t);if("Cache"===e.id)return sz(this.model,"..annCache{.annotations}").map(e=>({symbol:e.symbol,annotations:e.annotations.map(e=>t(e,!1))}));if("Add"===e.id)return this.mainAxis.addAnnotation(e.annotation);let i=this.allAnnotations.find(t=>t.uid===e.uid);if(void 0!==i){let t=i.axis,s=t[`${e.id.toLowerCase()}Annotation`];if("function"==typeof s){s.call(t,i,e),"Delete"!==e.id||e.isUndoRedo||this.onAnnotationModifiedByTool(i,el.Deleted);return}}throw Error(`Unknown sub-action ${e.id} for action ${tz.ANN_ACTION_ID}`)}getPlotInfoFromDomId(e){let t=e.attributes.getNamedItem("data-plot-id").value,i=this.allPlots,s=i.findIndex(e=>e.id===t);return{type:Z[i[s].type],index:s}}getSimplePlot(e,t){return this.accessor.change({id:"Plot",context:{id:tz.ACTION_GET,type:e,index:t}})[0]}onCardClicked(e){let t=this.getPlotInfoFromDomId(e),i=this.getSimplePlot(t.type,t.index),s={chart:this.accessor,plot:i};this.notifyHost(ay.CH_CARDPLOTCLICKED,s)}deletePlotClicked(e){let t=this.getPlotInfoFromDomId(e),i=this.getSimplePlot(t.type,t.index);this.accessor.change({id:"Plot",context:{id:"Delete",type:t.type,index:t.index}});let s={chart:this.accessor,plot:i};this.notifyHost(ay.CH_CARDPLOTREMOVED,s)}showHidePlotClicked(e){this.defaultTool.hideCrosshairAndTooltips(this.view,!0);let t=this.getPlotInfoFromDomId(e),i="Show"===e.attributes.getNamedItem("data-act").value;this.accessor.change({id:"Plot",context:{id:"Update",type:t.type,index:t.index,visible:i}});let s=this.getSimplePlot(t.type,t.index),r={chart:this.accessor,plot:s,visible:i};this.notifyHost(ay.CH_CARDPLOTVISIBILITYCHANGED,r)}plotMoreActionsClicked(e,t){let i=this.getPlotInfoFromDomId(e),s=this.getSimplePlot(i.type,i.index),r={x:t.clientX,y:t.clientY},n={chart:this.accessor,plot:s,offset:r,originalEvent:t};this.notifyHost(ay.CH_PLOTNEEDSCONTEXTMENU,n)}onMovePaneClicked(e){let t=parseInt(e.attributes.getNamedItem("data-pane").value),i="Down"===e.attributes.getNamedItem("data-dir").value,s=t+ +!!i,r=t-!i;setTimeout(()=>{this.accessor.change({id:"MovePane",context:{from:s,to:r}}),this.notifyHost(ay.CH_PANESREORDERED,{chart:this.accessor})})}onAnnotationsUpdated(e,t=!1){var i,s;let r=this.allAxes.indexOf(e),n=e.annotations.map(e=>e.toModel()),a=(i=this.model,s={axisIndex:r,annotations:n},sY(i,`..axes[${s.axisIndex}]`,e=>(e.annotations=s.annotations,e)));try{this.model=ah(a,tz.CHART_SCHEMA)}catch(e){So(`Cannot update annotation (corrupts definition), error is: ${e.message}`,"error")}t&&this.view.draw(),this.notifyHost(ay.CH_ANNOTATIONCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}onAnnotationModifiedByTool(e,t,i=!0){if(t!==el.None){if(i&&t!==el.Undo&&t!==el.Redo){let i=my(e,t);this.undoRedoManager.done(i)}let s=mS(e);s.toolChange=el[t],this.notifyHost(ay.CH_ANNMODIFIEDBYTOOL,s)}}onAnnotationDone(e,t){let i={id:e,chart:this.accessor,toolChange:el[t]};this.notifyHost(ay.CH_ANNMODIFIEDBYTOOL,i)}onPaneHeightsUpdated(){var e,t;let i,s=this.panes.map((e,t)=>({index:t,relativeHeight:e.height}));this.model=(e=this.model,t={paneHeights:s},i=e,t.paneHeights.forEach(e=>{let t;i=sY(i,(t=e.index,`..panes[${t}]`),t=>(t.height=e.relativeHeight,t))}),i),this.notifyHost(ay.CH_PANEHEIGHTSCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}getDataStats(){let e=this.mainPlot.timeSeries.container;if(!eF(e)||0===e.size)return null;let t=e.getTimeData();return{dataRange:{from:eb(t).getTime(),to:eC(t).getTime()},barCount:e.size}}}function yE(e,t){return e?.from===t?.from&&e?.to===t?.to}let yL=["Renko","Range","LineBreak","Kagi","PointAndFigure"];function y_(e,t){for(let i of Object.keys(e))if(e[i]!==t[i])return!0}let yM="MARKED_FOR_DELETION";function yx(e,t){if(0===t.plots.length)return e;let i=e;return t.plots.forEach(e=>{let t=yO(e.index),s=yw(i,t);eF(s)&&s.type===e.type&&(i=sY(i,t,e=>(e[yM]=!0,e)))}),ac(i=sY(i,`..plots{.${yM} === true}`,e=>tz.NULL_OBJECT))}function yI(e,{main:t,type:i,index:s},r){let n="..plots{.main === true}",a=sz(e,"..panes").map((e,t)=>{let i=1===sz(e,n).length;return sz(e,"..axes").map((e,s)=>{let a=1===sz(e,n).length;return sz(e,"..plots").map(e=>{let n=function(e,t,i,s){let r=Z[e.type],n={curves:ez(e.curves),type:e.type};n.precision=e.precision,n.visible=e.visible;let a=(e,t)=>{eF(e[t])?n[t]=e[t].map(e=>ez(e)):n[t]=[]},o=(e,t,i=!1)=>{!0===t.main&&(e.main=!0,e.showPrevious=t.showPrevious,i&&null!=t.events&&(e.events=ez(t.events)))},l=(e,t=e=>!0)=>{eF(s)&&(e.subtitles=s.allPlots.filter(e=>e.type===r).filter(t).map(e=>e.title))};switch(r){case Z.Symbol:{n.title=e.symbol;let t=n.curves[0].style,i=t=>{a(e,"inputs"),0===n.inputs.length&&(n.inputs=ez(t))};switch(t){case"Renko":i(tz.DEFAULT_RENKO_INPUTS);break;case"Kagi":i(tz.DEFAULT_KAGI_INPUTS);break;case"PointAndFigure":i(tz.DEFAULT_PNF_INPUTS);break;case"LineBreak":i(tz.DEFAULT_LINEBREAK_INPUTS);break;case"Baseline":i(tz.DEFAULT_BASELINE_INPUTS)}o(n,e,!0);break}case Z.Study:{a(e,"inputs");let s=sR(e.study),r=n.inputs,o="AVWAP"===e.study,l=0===r.length?"":` (${r.map(e=>o&&"Anchor"===e.name?new Date(e.value).toLocaleString():e.value).join(", ")})`,u=n.curves.map(e=>Number(e.shift)).filter(e=>e>0),h=0===u.length?"":` [${u.join(", ")}]`;n.title=`${s.id}${l}${h}`,n.studyId=s.id,a(e,"levels"),a(e,"bands"),n.placement=t?i?"overlay":"withMain":"standalone",n.detachedScale=e.detachedScale;break}case Z.BalanceSheet:case Z.IncomeStatement:{let t=ag[e.curves[0].fields[0]];n.title=`${t.name} (${e.fundamental.substring(0,1)})`,n.fundamentalId=t.id,n.frequency=e.fundamental;break}case Z.Expression:n.title=e.expression,o(n,e);break;case Z.Forward:n.title=e.forward,a(e,"offsets"),l(n),o(n,e);break;case Z.Seasonal:n.title=e.seasonal,l(n,e=>e.refSeasonal===n.title),a(e,"offsets"),o(n,e);break;default:throw Error("Unexpected plot type")}return n}(e,i,a,r);return n.paneIndex=t,n.axisIndex=s,n})})}).flat(2).map((e,t)=>(e.index=t,e));if(t)return a.filter(e=>e.main);if(!eF(i))return a;{let e=a.filter(e=>e.type===i);return eF(s)?e.filter(e=>e.index===s):e}}function yD(e,t){"Study"===e.type&&t.curves?.forEach(e=>delete e.varyColorPerBar),function(e){let t=Z[e.type];return t===Z.Forward||t===Z.Seasonal}(e)?eF(t.curves)&&(e.curves=t.curves):function(e,t){if(void 0!==t&&t.length===e.length)for(let i=0;i<e.length;++i){let s=t[i],r=e[i];for(let e of(eY(r,s),["shift","dashStyle","lineSmoothing","lineMarker"])){let t=s[e];eF(t)&&(r[e]=t)}}}(e.curves,t.curves);let i=Z[t.type];eF(t.precision)?e.precision=t.precision:delete e.precision,i===Z.Symbol?e.symbol=t.symbol:i===Z.Study?(function(e,t,i){let s=eK(e),r=eK(t);eY(s,r);let n=Object.keys(r).map(e=>({name:e,value:r[e]}));n.length>0&&(i.inputs=n)}(e.inputs,t.inputs,e),["bands","levels","detachedScale"].forEach(i=>{t[i]&&(e[i]=t[i])})):(i===Z.BalanceSheet||i===Z.IncomeStatement)&&t.frequency?e.fundamental=t.frequency:i===Z.Expression?eF(t.expression)&&(e.expression=t.expression):i===Z.Forward?(eF(t.offsets)&&(e.offsets=t.offsets),eF(t.forward)&&(e.forward=t.forward)):i===Z.Seasonal&&(eF(t.offsets)&&(e.offsets=t.offsets),eF(t.seasonal)&&(e.seasonal=t.seasonal),eF(t.usesInAverage)&&(e.usesInAverage=t.usesInAverage),rs(e))}let yO=e=>`..plots[${e}]`;function yw(e,t){let i=sz(e,t);return 1!==i.length?null:i[0]}let yR=["withMain","overlay","standalone","clone"];function yN(){return{plots:[]}}function yV(e){let t=e.display.chart.newPaneHeight??1;return{axes:[yN()],height:t}}function yH(e){let t=yV(e);return e.panes.push(t),t}function yF(e,t){let i=eH(t.paneIndex)&&t.paneIndex<e.panes.length?e.panes[t.paneIndex]:yH(e),s=i.axes[0];return t.oppositeScale?yK(i,s):s}function yB(e,t,i){let s=null,{mainPane:r,mainAxis:n}=n4(e);switch(t){case"withMain":s=yK(r,n);break;case"overlay":s=n;break;case"standalone":s=yH(e).axes[0];break;case"clone":if("number"==typeof i){let t={main:!1,index:i,type:Z[Z.Study]},r=yI(e,t).find(e=>e.index===t.index);s=sz(e,`..panes[${r.paneIndex}]..axes[${r.axisIndex}]`)[0]}}return s}let yk=[{fields:[ag.Close.id],colors:["#888"],style:"Line",lineWidth:2,varyColorPerBar:!1,visible:!0}];function yW(e){return"Symbol"===e.type}let yU={attributes:["OpenVsClose"],colors:["#b63400","#007f3e","#1664db"],fields:["Open","High","Low","Close","Change"],style:"Candlestick",varyColorPerBar:!0,lineWidth:1},y$=0,yG=["#0d223a","#8abc21","#910000","#2f7ed8","#42ccdc","#bf95df","#860262","#e5daa3","#4682e8","#aaa9c1","#fcccdc","#f66b00","#d875be","#e84b46"],yz="Symbol";function yY(e,t){let i={curves:[{attributes:[],colors:yG.slice(y$,y$+1),fields:e?[ag.Last.id]:[ag.Close.id],style:"Line",dashStyle:"Solid",varyColorPerBar:!1,lineWidth:2,lineMarker:void 0,lineSmoothing:void 0}]};return delete t.oppositeScale,ej(i,t),eF(t.curves)&&eY(i.curves,t.curves),y$=(y$+1)%yG.length,i}let yj='..plots{(.type === "Symbol" || .type === "Expression") && .main !== true}';function yK(e,t){let i=e.axes.find(e=>e!==t);return eF(i)||(i=yN(),e.axes.push(i)),i}let yq=()=>tz.NULL_OBJECT;function yX(e){return sY(e,"..axes.annotations",yq)}function yZ(e){return ac(sY(e,'..plots{.type === "Symbol" && .main !== true}',yq))}let yJ=".display.chart.previous";function yQ(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==Z[t.type])return s;let n=i.panes.indexOf(r.axis.pane),a=n===i.panes.length-1,o=1===i.panes[n].axes.reduce((e,t)=>e+t.plots.length,0);return 0!==n&&s.push("ExistingAbove"),o||s.push("NewAbove"),a||s.push("ExistingBelow"),o||s.push("NewBelow"),s}function y0(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==Z[t.type])return s;let n=r.axis.pane,a=r.axis===n.axes[0],o=n.axes.some(e=>e.plots.some(e=>r!==e&&!e.hasDetachedScale)),l=r.hasDetachedScale;return(a||l)&&s.push("SecondaryAxis"),(!a||l)&&s.push("PrimaryAxis"),o&&s.push("NoAxis"),s}function y1(e,t){let i=e.panes[t],s=i.axes.map(e=>e.plots.reduce((e,t)=>e+ +!!t.detachedScale,0)),r=i.axes.length;return i.axes.forEach((e,t)=>{let n=s[t],a=e.plots.length;if(0!==n&&!(n<a)&&n===a)if(r>1&&1===n){let n=(t+1)%r;if(s[n]<i.axes[n].plots.length){let t=e.plots.find(e=>e.detachedScale);t&&(i.axes[n].plots.push(t),e.plots=e.plots.filter(e=>!e.detachedScale),s[n]++)}}else{let t=e.plots.find(e=>e.detachedScale);t&&(t.detachedScale=!1)}}),e}function y2(e,t){let i=e.allPlots[t],s=e.panes.indexOf(i.axis.pane),r=e.panes[s].axes.indexOf(i.axis),n=e.panes[s].axes[r].plots.findIndex(e=>e===i);return{pane:s,axis:r,plot:n}}let y3={MainPlot:at,Aggregation:{Update:ar,Get:function(e,t,i){return ez(e.data.aggregation)}},Period:{Update:function(e,t,i){let s=eF(t.period),r=eF(t.range),n=eF(t.density);if(+!!s+ +!!r+ +!!n>1)throw Error("Cannot set more than one of: period, range, density.");if(s&&(e.display.period=t.period,nN(e),nH(e)),r)if((!eF(e.display.period)||ao(e.display.period))&&(e.display.xAxis.visibleRange=t.range),nV(e),nH(e),eF(i)){let s=function(e){let t=e.getDataStats();return null===t?null:t.dataRange}(i),r=n_(e.data.aggregation),n=i.data.aggregation,a=r.unit!==n.unit||r.size!==n.size||r.spec!==n.spec||!eF(s)||e.data.checkRange,o=a;if(!a){let{from:e,to:i}=s,{from:r,to:n}=t.range;o=r<e||r>i||n<e||n>i}o&&(e.data.range=t.range),delete e.data.checkRange}else e.data.checkRange=!0;return n&&(e.display.density=t.density,nN(e),nV(e)),(s||r||n)&&(nR(e),i&&(i.forceResetVisibleRange=!0)),e},Delete:function(e,t,i){return eF(t.period)&&t.period&&(delete e.display.period,ai(e),i&&(i.forceResetVisibleRange=!0)),e}},Crosshair:{Update:function(e,t){let[i,s]=eW(t.crosshair),{color:r,dashStyle:n}=t.horizontal||{},{color:a,dashStyle:o}=t.vertical||{},l=(e,t,i)=>{t&&(e.color=t),i&&(e.dashStyle=i)},u=sY(e,".display.xAxis.crosshair",e=>(e.enabled=i,l(e,a,o),e));return u=sY(u,".display.yAxis.crosshair",e=>(e.enabled=s,l(e,r,n),e)),eF(t.haloTracking)&&"boolean"==typeof t.haloTracking&&(u=sY(u,".display.chart",e=>(e.plotHover=t.haloTracking,e))),u},Get:function(e,t,i){let s=t=>sz(e,t)[0],r=s(".display.chart"),n=s(".display.xAxis.crosshair"),a=s(".display.yAxis.crosshair"),o="none";return n.enabled&&a.enabled?o="both":n.enabled?o="vertical":a.enabled&&(o="horizontal"),{crosshair:o,horizontal:{color:a.color,dashStyle:a.dashStyle},vertical:{color:n.color,dashStyle:n.dashStyle},haloTracking:r.plotHover}}},Tooltip:{Update:function(e,t){return sY(e,".display.tooltip",e=>(null!=t.visible&&(e.visible=t.visible),t.mode&&(e.mode=t.mode),null!=t.showMainTitle&&(e.showMainTitle=t.showMainTitle),t.mainTitle&&(e.mainTitle=t.mainTitle),e))},Get:function(e,t,i){let s=sz(e,".display.tooltip")[0];return{visible:s.visible,mode:s.mode,showMainTitle:s.showMainTitle,mainTitle:s.mainTitle}}},Events:function(e,t){let i=ez(t);return Object.keys(t).forEach(e=>{tz.EVENTS.includes(e)||delete i[e];let s=t[e];"boolean"==typeof s?s={show:t[e]}:Object.keys(s).forEach(e=>{tz.EVENT_PROPERTIES.includes(e)||delete s[e]}),i[e]=s}),sY(e,n2,e=>("Symbol"===e.type&&(e.events=e.events||{},Object.keys(i).forEach(t=>{e.events[t]=e.events[t]||{},eY(e.events[t],i[t],!1)})),e))},Scale:{Update:function(e,t){let i=sY(e,"..panes[0]..axes",e=>(eH(t.scale)&&(e.scale=t.scale),e));return i=sY(i,".display.xAxis",e=>(eH(t.marginBars)&&(e.marginBars=t.marginBars),eH(t.nonEodLabelWithDate)&&(e.nonEodLabelWithDate=t.nonEodLabelWithDate),eH(t.ordinalName)&&(e.ordinalName=t.ordinalName),eH(t.preventHorizontalLabelOverlap)&&(e.preventLabelOverlap=t.preventHorizontalLabelOverlap),e)),i=sY(i,".display.yAxis",e=>{(eF(t.minPadding)||eF(t.maxPadding))&&So("The 'minPadding' and 'maxPadding' are deprecated (ignored)","warn");let i=eH(t.preventLabelOverlap)&&!eH(t.preventVerticalLabelOverlap);i&&So("The 'preventLabelOverlap' is deprecated, please use 'preventVerticalLabelOverlap'","warn");let s=i?t.preventLabelOverlap:t.preventVerticalLabelOverlap;return eH(s)&&(e.preventLabelOverlap=s),eF(t.includePercentChangeWithLastValue)&&(e.includePercentChangeWithLastValue=t.includePercentChangeWithLastValue),eF(t.snapAnnotationsToPrices)&&(e.snapAnnotationsToPrices=t.snapAnnotationsToPrices),e}),eF(t.labels)&&Array.isArray(t.labels)&&t.labels.forEach(e=>{let{axis:t,text:s,index:r,paneIndex:n}=e;eF(t,s,r)&&"vertical"===t&&Number.isInteger(r)&&(i=sY(i,`..panes[${n??0}]..axes[${r}]`,e=>eF(e)?(e.label=s,e):tz.NULL_OBJECT))}),eH(t.contractTransition)&&(i=sY(i,".display.xAxis",e=>(eY(e.contractTransition,t.contractTransition),e))),eH(t.cycleTransition)&&(i=sY(i,".display.xAxis",e=>(eY(e.cycleTransition,t.cycleTransition),e))),i},Get:function(e,t,i){let{mainAxis:s}=n4(e),r=sz(e,".display.xAxis")[0],n=sz(e,".display.yAxis")[0];return{scale:s.scale,marginBars:r.marginBars??0,preventLabelOverlap:n.preventLabelOverlap,preventVerticalLabelOverlap:n.preventLabelOverlap,preventHorizontalLabelOverlap:r.preventLabelOverlap,snapAnnotationsToPrices:n.snapAnnotationsToPrices,nonEodLabelWithDate:r.nonEodLabelWithDate??!1,includePercentChangeWithLastValue:n.includePercentChangeWithLastValue??!1,ordinalName:r.ordinalName??"",contractTransition:r.contractTransition,cycleTransition:r.cycleTransition}}},Other:{Update:function(e,t,i){let s=e;if(eF(t.comparisonMode)&&"string"==typeof t.comparisonMode&&e$(q,t.comparisonMode)&&(s=sY(s,`..panes{${n2}}.axes`,e=>(e.comparison=t.comparisonMode,e))),eF(t.gridLines)){let[e,i]=eW(t.gridLines);s=sY(s,".display.xAxis.gridLines",t=>(t.visible=e,t)),s=sY(s,".display.yAxis.gridLines",e=>(e.visible=i,e))}if(eF(t.minorGridLines)){let[,e]=eW(t.minorGridLines);s=sY(s,".display.yAxis.minorGridLines",t=>(t.visible=e,t))}eF(t.newPaneHeight)&&"number"==typeof t.newPaneHeight&&(s=sY(s,".display.chart{.newPaneHeight > 0}",e=>(e.newPaneHeight=t.newPaneHeight,e))),eF(t.showNavigator)&&"boolean"==typeof t.showNavigator&&(s=sY(s,".display.scrollbar",e=>(e.visible=t.showNavigator,e))),eF(t.plotHover)&&"boolean"==typeof t.plotHover&&(s=sY(s,".display.chart",e=>(e.plotHover=t.plotHover,e))),eF(t.showLastValue)&&"string"==typeof t.showLastValue&&(s=sY(s,".display.yAxis",e=>(e.showLastValue=t.showLastValue,e))),eF(t.showMinMaxArc)&&"boolean"==typeof t.showMinMaxArc&&(s=sY(s,".display.chart",e=>(e.showMinMaxArc=t.showMinMaxArc,e))),eF(t.showGoToLatest)&&"boolean"==typeof t.showGoToLatest&&(s=sY(s,".display.chart",e=>(e.showGoToLatest=t.showGoToLatest,e))),eF(t.showLegend)&&"boolean"==typeof t.showLegend&&(s=sY(s,".display.chart",e=>(e.showLegend=t.showLegend,e)),t.showLegend||i.view.removeLegend()),eF(t.allAnnotationsLocked)&&"boolean"==typeof t.allAnnotationsLocked&&(s=sY(s,".display",e=>(e.allAnnotationsLocked=t.allAnnotationsLocked,e))),eF(t.exprSkipLeadingEmpty)&&"boolean"==typeof t.exprSkipLeadingEmpty&&(s=sY(s,".data",e=>(e.exprSkipLeadingEmpty=t.exprSkipLeadingEmpty,e)));let r=[];if(eF(t.extendedHours)&&"boolean"==typeof t.extendedHours&&(s=sY(s,".data",e=>(e.extendedHours=t.extendedHours,e))),eF(t.realTimeCboeBzx)&&"boolean"==typeof t.realTimeCboeBzx&&(s=sY(s,".data",e=>(e.realTimeCboeBzx!==t.realTimeCboeBzx&&r.push("realTimeCboeBzx"),e.realTimeCboeBzx=t.realTimeCboeBzx,e))),eF(t.buildContinuation)&&"boolean"==typeof t.buildContinuation&&(s=sY(s,".data",e=>(e.buildContinuation=t.buildContinuation,e))),r.length>0){let e={chart:i.accessor,hostPropsChanged:r};i.notifyHost(ay.CH_HOST_PROPS_CHANGED,e)}return s},Get:function(e,t,i){let s=sz(e,`..panes{${n2}}.axes.comparison`)[0],r=e.display,n=(e,t)=>eG(e,!1,t,"visible"),a=e=>(function(e,t){let i=e=>eF(e)&&"boolean"==typeof e&&e,s=i(e),r=i(t);return s&&r?"both":s?"vertical":r?"horizontal":"none"})(n(r.xAxis,e),n(r.yAxis,e)),o=eG(r.chart,!0,"showLegend");return{comparison:s,gridLines:a("gridLines"),minorGridLines:a("minorGridLines"),newPaneHeight:r.chart.newPaneHeight,showLastValue:r.yAxis.showLastValue,showLegend:o,showMinMaxArc:r.chart.showMinMaxArc,allAnnotationsLocked:r.allAnnotationsLocked,exprSkipLeadingEmpty:e.data?.exprSkipLeadingEmpty??!1,extendedHours:e.data?.extendedHours??!1,realTimeCboeBzx:e.data?.realTimeCboeBzx??!1,buildContinuation:e.data?.buildContinuation??!1}}},Plot:{Add:function(e,t){switch(t.type){case"Study":return function(e,t){let i=sR(t.studyId);if(!eH(i))return So(`Unknown or unavailable study with the id '${t.studyId}'`,"error"),e;let s=n3(e),r=sF(i);if(s.type===Z[Z.Expression]&&r)return So(`Cannot add study "${i.meta.title}" because it cannot be based on an expression (current main plot); study needs more than "OHLCV" fields to be calculated.`,"error"),e;let n=t.placement||(i.meta.overlay?"overlay":"standalone"),a={type:"Study",study:t.studyId,visible:!0};"overlay"===n&&"VOL"===t.studyId&&(a.detachedScale=!0),void 0!==t.curves&&(a.curves=i.defaults.curves),yD(a,t);let o=yB(e,n,t.cloneIndex);eF(o)&&o.plots.push(a);let l=e.data.aggregation;return as(e,"Tick"===l.unit&&"None"===l.spec)}(e,t);case"IncomeStatement":case"BalanceSheet":return function(e,t){let i=n3(e);if(i.type!==Z[Z.Symbol])throw Error("Cannot add fundamental to the chart whose main plot is not a Symbol plot.");let s=i.symbol,r={curves:[{fields:[t.fundamentalId],lineWidth:2,style:"Line",varyColorPerBar:!1,visible:!0,colors:["#888"]}],fundamental:"Quarter",symbol:s,type:K[ag[t.fundamentalId].category],visible:!0};return yD(r,t),e.panes.push({axes:[{plots:[r]}]}),e}(e,t);case"Expression":let i=n3(e),s={curves:ez(yW(i)?i.curves:yk),expression:"",type:"Expression",visible:!0};return yD(s,t),yF(e,t).plots.push(s),e;case"Symbol":return function(e,t){let i=n3(e),s=Sp().getDefaultMultiFieldCurve(),r=eF(s)?s:yU,n=i.curves?.length,a={curves:n===t.curves.length&&1===n?ez(yW(i)?i.curves:[r]):t.curves,symbol:"",type:"Symbol",visible:!0};return yD(a,t),yF(e,t).plots.push(a),e}(e,t);case"Seasonal":let r={curves:ez(yk),offsets:[0],seasonal:"",type:"Seasonal",visible:!0,main:!1};return yD(r,t),t.paneIndex=t.paneIndex??0,yF(e,t).plots.push(r),e;default:throw Error("Unexpected plot type '${type}', not supported currently")}},Get:yI,Delete:yx,Update:function(e,t,i){if(eF(t.placement)&&!yR.includes(t.placement))throw Error(`Unknown placement: ${t.placement}`);let s=t.main?n2:yO(t.index),r=yw(e,s);if(!eH(r)||eH(t.type)&&r.type!==t.type)return e;if(eH(t.visible))return r.visible=t.visible,e;if(r.main&&function(e){let t=Z[e.type];return t===Z.Symbol||t===Z.Expression}(r)){if(t.curves){let i=e=>e.curves[0].style===$[$.Range],[s,n]=[i(r),i(t)];s&&!n?e=ar(e,{unit:"Day",size:1,spec:"None"}):!s&&n&&(e=ar(e,{unit:"Intraday",size:100,spec:"PerRange"}))}return t.type||(t.type=r.type),eF(t.precision)?r.precision=t.precision:delete r.precision,eF(t.showPrevious)&&(e=sY(e,n2,e=>(e.showPrevious=t.showPrevious,e))),t.curves?nW(e,t):e}{let r=sY(e,s,e=>(yD(e,t),e)),n=yI(r,t,i).find(e=>e.index===t.index);if(!eF(n))return e;if(!(t.type===Z[Z.Study]&&eF(t.placement)&&t.placement!==n.placement))return r;let a=yw(r,s),o=yB(r=yx(r,{id:"Delete",plots:[{index:t.index,type:t.type}]}),t.placement);return null!==o&&o.plots.push(a),r}}},Compare:{Update:function(e,t){let{yes:i,no:s}=eA((eF(t.symbols)&&(So("Use of 'symbols' for Compare API is deprecated. Please see docs for the latest version which supports more plot types","warn"),t.plots=t.symbols.map(e=>(e.type=yz,e))),t.plots?.some(e=>eF(e.leftScale)))?(So("Use of 'leftScale' for Compare API is deprecated. Please use 'oppositeScale'","warn"),t.plots.map(e=>{let t=e.leftScale;return delete e.leftScale,{...e,oppositeScale:t}})):t.plots,e=>e.oppositeScale??!1),{mainPane:r,mainAxis:n}=n4(e);r.alignOnExpirations=t.alignOnExpirations||!1;let a=yK(r,n),o=e=>![yz,"Expression"].includes(e.type);a.plots=a.plots.filter(o);let l=n.plots.filter(e=>e.main||o(e)),u="Tick"===e.data.aggregation.unit;y$=0;let h=eh(yY,u);return n.plots=l.concat(s.map(h)),i.length>0&&(a.plots.push(...i.map(h)),a.comparison=n.comparison,a.scale=n.scale),ac(e)},Get:function(e,t){let i=sz(e,yj),{mainPane:s,mainAxis:r}=n4(e),n=[];for(let e of i){let t=r.plots.includes(e),i=e.type.toLowerCase(),s={curves:ez(e.curves),type:e.type,[i]:e[i],leftScale:!t};n.push(s)}return{plots:n,alignOnExpirations:s.alignOnExpirations}}},Annotation:{Get:function(e,t,i){let s=sz(e,"..panes").map((e,t)=>sz(e,"..axes").map((e,i)=>sz(e,".annotations").map(e=>({...e,paneIndex:t,axisIndex:i})))).flat(2).map((e,t)=>({...e,index:t}));return eF(t.index)&&Number.isFinite(t.index)?t.index<s.length?[s[t.index]]:tz.EMPTY_ARRAY:s}},MovePane:function(e,t){let i=e.panes;return i.splice(t.to,0,i.splice(t.from,1)[0]),e},Template:function(e,t){let i=ez(e);if(t.strip.main){let e=n3(i),t=e.type.toLowerCase();e[t]=tz.PLACEHOLDER_SYMBOL_NAME}return t.strip.annotations&&(i=yX(i)),t.strip.compare&&(i=yZ(i)),i=sY(i,".data",e=>(e.range&&(delete e.range,e.checkRange=!0),e))},Outline:function(e,t,i){let s=yI(e,{main:!0},i)[0],r=s.title===tz.PLACEHOLDER_SYMBOL_NAME,n="Symbol"===s.type,a="Expression"===s.type,o=nK(s.title),l=[];return a&&!nj(o)?l=o.symbols:r||(l=[s.title]),{isTemplate:r,isDefinition:!r,main:{isSymbol:n,isExpression:a,symbols:l,title:r?null:s.title},compare:sz(e,yj).map(e=>e.symbol),annotations:sz(e,"..annotations").map(e=>e.id),studies:yI(e,{type:"Study"},i).map(e=>e.title)}},Theme:{Update:function(e,t){let i=e,{backgroundColor:s,axis:{gridLinesColor:r,textColor:n,crosshairColor:a,gridLinesStyle:o},fontSize:l}=t,{chart:u,xAxis:h,yAxis:c}=l||{};if((s||u)&&(i=sY(e,".display.chart",e=>(s&&(e.backgroundColor=s),u&&(e.fontSize=u),e))),r){let e=e=>(e.color=r,e);i=sY(i,".display.xAxis.gridLines",e),i=sY(i,".display.yAxis.gridLines",e),i=sY(i,".display.yAxis.minorGridLines",e)}if(o){let e=e=>(e.dashStyle=o,e);i=sY(i,".display.xAxis.gridLines",e),i=sY(i,".display.yAxis.gridLines",e),i=sY(i,".display.yAxis.minorGridLines",e)}if(n){let e=e=>(e.textColor=n,e);i=sY(i,".display.xAxis",e),i=sY(i,".display.yAxis",e)}if(a){let e=e=>(e.color=a,e);i=sY(i,".display.xAxis.crosshair",e),i=sY(i,".display.yAxis.crosshair",e)}if(h||c){let e=e=>t=>(t.fontSize=e,t);h&&(i=sY(i,".display.xAxis",e(h))),c&&(i=sY(i,".display.yAxis",e(c)))}return i},Get:function(e,t,i){let{chart:s,xAxis:r,yAxis:n}=e.display||{},{fontSize:a,backgroundColor:o}=s||{},{fontSize:l,gridLines:u,textColor:h,crosshair:c}=r||{},{color:d,dashStyle:p}=u||{},{fontSize:f}=n||{},{color:m}=c||{};return{backgroundColor:o,axis:{gridLinesColor:d,textColor:h,crosshairColor:m,gridLinesStyle:p},fontSize:{chart:a,xAxis:l,yAxis:f}}}},Clear:function(e,t,i){let{paneIndex:s,annotations:r,studies:n}=t||{},a=Number.isInteger(s)?`[${s}]`:"",o=`..panes${a}`,l=e,u=e=>tz.NULL_OBJECT;return!0===r&&(i.allAnnotations.forEach(e=>i.onAnnotationModifiedByTool(e,el.Deleted,!1)),l=sY(l,`${o}..annotations`,u)),!0===n&&(l=sY(l,`${o}..plots{.type=="Study"}`,u)),l=ac(l)},Previous:{Update:function(e,t,i){return sY(e,yJ,e=>(eY(e,t),e))},Get:function(e,t,i){return sz(e,yJ)[0]}},MovePlot:{Update:function(e,t,i){if(!yQ(e,t,i).includes(t.targetPane))return e;let s=y2(i,t.index),r=yw(e,yO(t.index));e.panes[s.pane].axes[s.axis].plots.splice(s.plot,1);let n=s.pane,a=!0;switch(t.targetPane){case"ExistingAbove":n--;break;case"NewAbove":e.panes.splice(n,0,yV(e)),a=!1;break;case"ExistingBelow":n++;break;case"NewBelow":n++,a=!1,e.panes.splice(n,0,yV(e))}a&&i.panes[n].isMain&&r?.type==="Study"&&"VOL"===r.study&&(r.detachedScale=!0);let o=e.panes[n];o.axes.length<2&&o.axes[0].plots.length>0&&o.axes.push(yN());let l=o.axes.findIndex(e=>0===e.plots.length),u=-1===l?o.axes.length-1:l;o.axes[u].plots.push(r);let h=y1(e,s.pane);return ac(h=y1(h,n))},Get:yQ},PinPlot:{Update:function(e,t,i){if(!y0(e,t,i).includes(t.targetAxis))return e;let s=y2(i,t.index),r=e.panes[s.pane],n=yw(e,yO(t.index)),a=-1;switch(t.targetAxis){case"PrimaryAxis":a=0;break;case"SecondaryAxis":a=1;break;case"NoAxis":n.detachedScale=!0}if(-1!==a)if(a!==s.axis)delete n.detachedScale,r.axes.length<2&&a>0&&r.axes.push(yN()),r.axes[a].plots.push(n),r.axes[+(0===a)].plots.splice(s.plot,1);else{let e=r.axes[s.axis].plots[s.plot];delete e.detachedScale}return ac(y1(e,s.pane))},Get:y0}};function y4(e){return"function"==typeof e}function y5(e,t,i){return(function(e,t){let i=y3[e];if(y4(i))return i;{let e=void 0!==t?i[t]:void 0;if(!y4(e)&&!y4(e=i[tz.DEFAULT_ACCESSOR_SUBACTION]))throw Error("Invalid accesor id and/or sub id");return e}})(e.id,e.context.id)(t,e.context,i)}function y6(e){return{id:"MainPlot",context:e}}let y7={keepOldAnnotations:!1,keepNewAnnotations:!0,keepOldCompare:!1,keepNewCompare:!0,keepOldAggregation:!1,keepNewBarWidth:!1},y8=Symbol.for("__ias__");class y9{headless;presenter;_model;constructor(e=!1){this.headless=e,this.presenter=e?null:new yb(this)}get elementId(){return this.headless?null:this.presenter?.elementId??null}get hostElement(){return this.headless?null:this.presenter?.hostElement??null}initialize(e,t=null){if(this.headless)return void console.error("You cannot initialize a headless chart.");if(this.presenter.initialize(e),eH(t)){let e="string"==typeof t;e?So("Initializing the chart with symbol name is deprecated. Please use object form instead (see docs for details). This API will be removed in the future.","warn"):(t.template&&this.load(t.template),delete t.template);let i=e?{symbol:t}:t;this.change(y6(i))}}shutdown(){if(!this.headless){let e=this.presenter?.shutdown();return this.presenter=null,e}return!1}annotate(e,t=null,i=null){if(!this.headless)if(eF(e)){s9(e,t),s8(e,t);let s=gj(e,!1,t,i,this.presenter);s.isDrawingAnnotation&&this.presenter.view.setCursor(ee.Crosshair),this.presenter.activeTool=s,eO()||this.presenter.view.mouseCanvas.focus({preventScroll:!0})}else this.presenter.resetActiveTool()}cancelAnnotation(){this.headless||this.presenter.resetActiveTool()}zoom(e){this.headless||"boolean"!=typeof e||(e?this.annotate("ZoomIn"):this.presenter.defaultTool.resetView(this.presenter))}getDefaultTemplate(){return Sf()}get model(){return(this.headless?this._model:this.presenter.getModel())||Sf()}asTemplate(e={main:!0,annotations:!1,compare:!1}){return this.change({id:tz.ACTION_TEMPLATE,context:{strip:e}})}change(...e){let t={chart:this,actions:e.filter(e=>!e[y8])};t.actions.length>0&&this.presenter?.notifyHost(ay.CH_API_ACTIONS_RECEIVED,t);let i=Sp().config.validateInput,s=e.map(e=>i?ah(e,tz.ACCESSOR_SCHEMA):e);if(1===s.length){let e=s[0];if(e.id===tz.ACTION_TEMPLATE||e.context.id===tz.ACTION_GET)return y5(e,this.model,this.presenter);if(!this.headless&&e.id===tz.ANN_ACTION_ID)return this.presenter.handleAnnotationChange(e.context)}let{yes:r,no:n}=eA(s,e=>e.id===tz.ACTION_PLOT&&eF(e.context)&&e.context.id===tz.ACTION_DELETE),a=ez(this.model),o=ez(this.model);r.length>0&&n.push({id:tz.ACTION_PLOT,context:{id:tz.ACTION_DELETE,plots:r.map(e=>e.context)}}),n.forEach(e=>{if(!eF(o=y5(e,o,this.presenter)))throw Error("Forgot to return model from accessor")}),this.fromModel(o,a)}async fromModel(e,t){let i=ah(e,tz.CHART_SCHEMA);this.headless?this._model=i:await this.presenter?.fromModel(i,t)}async load(e,t){let i={...y7,...t},s=ah(JSON.parse(e),tz.CHART_SCHEMA),r=this.model,n=ez(r);if(eF(r)){if(s=function(e,t,i){let s=n3(t),r=s.type.toLowerCase();if(s[r]===tz.PLACEHOLDER_SYMBOL_NAME){let s=n3(e),{mainAxis:r}=n4(t),n=r.annotations,a=at(t,s);if(i){let{mainAxis:e}=n4(a);e.annotations=n}return a}return t}(r,s,i.keepNewAnnotations),i.keepNewAnnotations||(s=yX(s)),i.keepOldAnnotations&&(s=function(e,t){let{mainAxis:i}=n4(e),{mainAxis:s}=n4(t);yg(i,s);let r=e=>sz(e,'..plots{.type==="Study"}.study')[0],n=sz(e,yy).filter(e=>e!==i),a=sz(t,yy).filter(e=>e!==s);return n.forEach(e=>{let t=r(e),i=a.find(e=>t===r(e));eF(i)&&yg(e,i)}),t}(r,s)),i.keepNewCompare||(s=yZ(s)),i.keepOldCompare&&(s=function(e,t){let i=sz(e,yj),s=sz(t,yj),r=Math.max(0,4-s.length);if(0===r)return t;let n=i.filter(e=>!s.find(t=>e.symbol===t.symbol)).slice(0,r);if(0===n.length)return t;let{mainPane:a,mainAxis:o}=n4(t),{mainAxis:l}=n4(e);return n.forEach(e=>{l.plots.includes(e)?o.plots.push(e):yK(a,o).plots.push(e)}),t}(r,s)),i.keepOldAggregation){let e={id:tz.ACTION_AGGREGATION,context:r.data.aggregation},t=s.display.density;s=y5(e,s,this.presenter),i.keepNewBarWidth&&eF(t)&&(s.display.density=t)}await this.fromModel(s,n),this.clearUndoRedo()}}save(){return JSON.stringify(this.model)}clearUndoRedo(){this.headless||this.presenter.undoRedoManager.clear(!0)}reset(e=!0){let t=Sf();if(this.headless)this._model=t;else if(this.presenter.getModel()){let i=this.presenter.mainPlot,s=null;if(i.isSymbol?s={symbol:i.symbol}:i.isExpression?s={expression:i.expression}:i.isForward?s={forward:i.forward}:i.isSeasonal&&(s={seasonal:i.seasonal}),eF(s)){let i=y5({id:"Theme",context:{id:"Get"}},this.model,this.presenter),r=y5(y6(s),t,this.presenter);e&&(r=y5({id:"Theme",context:i},r,this.presenter)),this.presenter?.fromModel(r)}}this.clearUndoRedo(),this.presenter?.notifyHost(ay.CH_RESET,{elementId:this.elementId})}print(e={}){this.headless||this.presenter.print(e)}getSVGForExport(){So("Obsolete: please use 'exportImage' method instead.","warn")}setTitle(e){this.headless||this.presenter.setTitle(e)}getPaneBounds(e=!0){if(!this.headless)return this.presenter.panes.map(t=>e?t.getBounds():t.getBoundsWithoutScales())}exportData(e={}){return this.headless?null:yv.call(this.presenter,e)}exportImage(e={}){return this.headless?null:yP.call(this.presenter,e)}getDataStats(){return this.presenter.getDataStats()}get canUndo(){return!this.headless&&this.presenter.undoRedoManager.canUndo}get canRedo(){return!this.headless&&this.presenter.undoRedoManager.canRedo}undo(){this.canUndo&&this.presenter.undoRedoManager.undo()}redo(){this.canRedo&&this.presenter.undoRedoManager.redo()}pauseUndoRedo(){this.headless||this.presenter.undoRedoManager.pause()}resumeUndoRedo(e){this.headless||this.presenter.undoRedoManager.resume(e)}priceToY(e,t=0,i=0){let s=this.presenter;if(this.headless||t<0||i<0||t>s.panes.length)return null;let r=s.panes[t];return i>r.axes.length?null:r.axes[i].toY(e)}yToPrices(e){let t=this.presenter;if(this.headless)return null;for(let[i,s]of t.panes.entries()){let t=s.getBounds();if(eF(t)&&e>=t.y&&e<=t.y+t.height)return{pane:i,prices:s.axes.map(t=>t.toPrice(e))}}return{pane:-1,prices:[]}}activate(){this.presenter?.notifyHost(ay.CH_DIDBECOMEACTIVE,{chart:this})}}var cp=N("c15IW");function Se(e,t,i,s,r){void 0===s&&(s=0),void 0===r&&(r=!1);var n=t.schedule(function(){i(),r?e.add(this.schedule(null,s)):this.unsubscribe()},s);if(e.add(n),!r)return n}function St(e,t){return e+Math.random()*(t-e)}let Si=Function(atob("Y29uc29sZS5sb2coIlBsZWFzZSBjb250YWN0IEJhcmNoYXJ0IGluIG9yZGVyIHRvIG9idGFpbiB0aGUgbGljZW5zZSBmb3IgdGhlIGNoYXJ0IGNvbXBvbmVudC4iKTsg")),Ss=Function("f",atob("Zi5yZW1vdmVBbGxDaGFydHMoKTsg")),Sr=Function("m",atob("cmV0dXJuIG0gPT09ICJJbnRlcm5hbEZlZWQiIHx8IG0gPT09ICJXaWRnZXQiIHx8IG0gPT09ICJGcmVlV2lkZ2V0IiB8fCBtID09PSAiRGVtb1NpdGUiOw=="));async function Sn(e,t){if(t&&!Sr(e.mode))return;let i=!1,s=0,r=25;for(;!i&&s<5;){let t=function(){let e=globalThis.parent?.location?.hostname||"";return["","localhost","127.0.0.1"].includes(e)||function(e){let t=e.split(".");if(!t||4!==t.length)return!1;let i=t.map(Number);if(!i.every(e=>Number.isFinite(e)&&e>=0&&e<=255))return!1;let[s,r]=i;return 10===s||172===s&&r>=16&&r<=31||192===s&&168===r}(e)}()||"FreeWidget"===e.mode,n=t?e.apiKey:"";try{let r=t?"":function(){let e=document.domain,t=e.split("."),i="__tld"+new Date().getTime(),s=0;for(;s<t.length-1&&-1===document.cookie.indexOf(`${i}=${i}`);)e=t.slice(-1-++s).join("."),document.cookie=`${i}=${i};domain=${e};`;return document.cookie=`${i}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=${e};`,e}(),a=function(e,t=""){return function(e,t){Object.keys(t).forEach(e=>!eF(t[e])&&delete t[e]);let i=new URLSearchParams(t);return`${e}/?${i.toString()}`}(atob("aHR0cHM6Ly9iYXJjaGFydHdpZGdldHMud2Vic29sLmJhcmNoYXJ0LmNvbQ=="),{module:atob("YXV0aGVudGljYXRlQ2hhcnRSZWZlcmVy"),secret:t,referer:e})}(r,n),o=await fetch(a);if(o.ok){let t=await o.json(),s=t[atob("YXV0aG9yaXplZA==")];e.knownSite=s,s?(e.dataEndpoint=(t[atob("ZGF0YS1lbmRwb2ludA==")]||"").replace(/\/$/g,""),e.allowCredentials=t[atob("YWxsb3dDcmVkZW50aWFscw==")]):(e.dataEndpoint="",e.allowCredentials=!1),i=!0;break}s++}catch{}s++,r*=2,await new Promise(e=>setTimeout(e,r))}i&&e.knownSite||(setTimeout(Si,St(2e3,3e3)),setTimeout(()=>Ss(Sp()),St(4e3,5e3)))}var Sa={};function So(e,t="info",i=""){let s=globalThis.console,r=void 0!==s[t];s[r?t:"log"](e,i)}Sa=JSON.parse('{"major":2,"minor":356,"patch":1,"prerelease":false}');let Sl={environment:"Browser",validateInput:!1,throttleMillis:0,isAlt64:!0,defaultTemplate:`/${tz.CHART_DEFINITION}`,cachedAnnotationsCount:0,showResizeHandles:!1,scrollBehavior:"wheel+shift",bypassSmoothing:!1,showGoToLatest:void 0,tooltipMovement:"Auto",tooltipHeaders:void 0,touchCrosshairTimeoutMillis:void 0,touchCrosshairDelayMillis:void 0,mode:"Unspecified",hostingModel:"Page",overrides:void 0,logo:void 0,logoClickable:void 0,noDataText:void 0,useAllFieldsForComparison:void 0,colorfulAnnotations:!1,baseUrl:{instruments:"/proxies/instruments",futures:"/proxies/futures",timeseries:"/proxies/timeseries",timeseriesNew:"/proxies/new-timeseries",ondemand:"/proxies/ondemand",options:"/proxies/core-api"},credentials:void 0,apiKey:void 0,extensions:void 0,defaultVolumeBarColoring:void 0,defaultMainPlotBarColoring:void 0,async fetch(e,t){let i=this.baseUrl[e],s=`${i}${t}`;if(Sr(this.mode)&&this.knownSite){let{username:r,password:n}=this.credentials||{},a=eF(r,n),o=("timeseries"===e||"timeseriesNew"===e)&&a&&this.allowCredentials?`&username=${r}&password=${n}`:"";s=`https://${this.dataEndpoint}${i}${t}${o}`}let r=await fetch(s);return await r.text()},getCustomEventPopup:e=>null};async function Su(e,t){let i=Sp()?.config;if(!i||!i.fetch)throw Error("You should call initFeed first");let s=t;return"timeseries"===e?s=`/historical${t}`:"options"===e&&(s=`/options-historical${t}`),await i.fetch.call(i,e,s)}let Sh=!1,Sc=null;function Sd(t,i={}){if(Sh)throw Error("You should only call initFeed once during page's lifetime");Sh=!0;let s=Object.assign(Sl);return eY(s,i),eH(s.logo)&&function(e,t){let i=new DOMParser().parseFromString(e,"image/svg+xml"),s=i.querySelector("svg")?.getAttribute("viewBox"),r=i.querySelector("path")?.getAttribute("d");if(eH(s)&&eH(r)){let e=s.split(" ").map(Number);4===e.length&&e.every(Number.isFinite)&&(mZ={path:new Path2D(r),width:e[2],height:e[3],rect:new iw(0,0,0,0),logoClickable:t})}}(s.logo,s.logoClickable??!1),!function(e){var t;let i=e.extensions?.studyProvider;if(!eF(i))return;let s=i.getFields(),r=i.getStudies(),n=ez(s_(tz.CHART_SCHEMA)),a=n.definitions,o=a.studyField.enum,l=a.study.enum;for(let e of s)if(o.includes(e.id))throw Error(`Field with id ${e.id} already exists`);for(let e of r)if(l.includes(e.id))throw Error(`Study with id ${e.id} already exists`);o.push(...s.map(e=>e.id)),l.push(...r.map(e=>e.id)),t=tz.CHART_SCHEMA,au.addSchema(t,n),am(s),sD(r)}(s),(Sc=new t(s)).version=function(){let t=e(Sa),i=t.prerelease?`-${t.prerelease.identifier}.${t.prerelease.ordinal}`:"";return`${t.major}.${t.minor}.${t.patch}${i}`}(),So(`%cBarchart Chart version ${Sc.version}`,"info","font-size: larger"),Sc.cachesData&&(Sc.subject?.subscribe(Sc.onPerformInternalGc.bind(Sc)),e(cp).subscribe(ay.CH_ALL,Sc.onChartChanged.bind(Sc))),Sc}function Sp(){return Sc}function Sf(){return ez(Sp()?.template)}function Sm(){eH(Sc)&&(Sc.shutdown(),Sh=!1,Sc=null)}function Sg(e){let t=new y9(!0);return t.load(e),t.change({id:"Outline",context:{id:"Get"}})}function Sy(e,t,i,s=null){return new Proxy(e,{get:function(e,r,n){return r===t?function(t){let n=s?t[s]:t;return(i.handlesRequestsFor(n)?i:e)[r](t)}:Reflect.get(e,r,n)}})}class SS{config;version;cachesData;timeSeriesSource;metaDataSource;recordSource;charts;pendingRedraw;template;ongoingAnimationCallbackId;_altDataSource;_subject;knowDefaultCurve;defaultOhlcCurve;knowDefaultAggregation;defaultAggregation;knowDefaultPeriod;defaultPeriod;knowDefaultDensity;defaultDensity;id;_mainFeed;constructor(e){this.config=e,this._mainFeed=null,this.timeSeriesSource=this.metaDataSource=this.recordSource=null,this.charts=new Map,this.pendingRedraw=new Set,this.ongoingAnimationCallbackId=null,this.drawCharts=this.drawCharts.bind(this),this.template=null,this.cachesData=!1,this._altDataSource=null,this._subject=null,this.id=e1()}get subject(){return this.isAuxiliary||eH(this._subject)||(this._subject=new of().pipe(function(e){for(var t,i,s=[],r=1;r<arguments.length;r++)s[r-1]=arguments[r];var n=null!=(t=oc(s[s.length-1])?s.pop():void 0)?t:a1,a=null!=(i=s[0])?i:null,o=s[1]||1/0;return og(function(t,i){var s=[],r=!1,l=function(e){var t=e.buffer;e.subs.unsubscribe(),az(s,e),i.next(t),r&&u()},u=function(){if(s){var t=new aY;i.add(t);var r={buffer:[],subs:t};s.push(r),Se(t,n,function(){return l(r)},e)}};null!==a&&a>=0?Se(i,n,u,a,!0):r=!0,u();var h=oy(i,function(e){var t,i,r=s.slice();try{for(var n=aF(r),a=n.next();!a.done;a=n.next()){var u=a.value,h=u.buffer;h.push(e),o<=h.length&&l(u)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}},function(){for(;null==s?void 0:s.length;)i.next(s.shift().buffer);null==h||h.unsubscribe(),i.complete(),i.unsubscribe()},void 0,function(){return s=null});t.subscribe(h)})}(tz.INTERNAL_GC_MILLIS),ov(e=>e.length>0))),this._subject}get isAuxiliary(){return null!==window.opener}setAltDataSource(e){this._altDataSource=e,this.timeSeriesSource=Sy(this.timeSeriesSource,"getTimeSeries",e,"symbol"),this.metaDataSource=Sy(this.metaDataSource,"getMetaData",e),this.recordSource=Sy(this.recordSource,"getRecord",e)}replaceDataSources(e){this._altDataSource=e._altDataSource,this.timeSeriesSource=e.timeSeriesSource,this.metaDataSource=e.metaDataSource,this.recordSource=e.recordSource}getAltDataSource(){return this._altDataSource}getTimeSeriesDataSource(){if(!eH(this.timeSeriesSource))throw Error("No time series source defined");return this.timeSeriesSource}getMetaDataSource(){if(!eH(this.metaDataSource))throw Error("No metadata source defined");return this.metaDataSource}getRecordSource(){if(!eH(this.recordSource))throw Error("No record source defined");return this.recordSource}async ready(){return tU.call(this,async()=>{await Sn(this.config,this instanceof SC||this instanceof SA||this instanceof SL);let e=this.config.defaultTemplate;if(!e)throw Error("Must provide a default template");if("string"==typeof e){let t=await fetch(e);e=await t.json()}return this.template=ah(e,tz.CHART_SCHEMA),!0})}getHeadlessChart(){return new y9(!0)}fixupRenderTo(e){if(!eH(e))return null;if(e instanceof HTMLElement)return e;let t=tR(`#${e}`);if(eH(t))return t;let i=[...this.charts.keys()].find(t=>t.id===e);return eH(i)?i:null}checkChart(e,t){let i=this.fixupRenderTo(e),s=eH(i)&&this.charts.has(i);return eH(t)&&t!==s&&So(`There is ${t?"no":"already a"} chart inside the element ${e}`,"error"),i}addChart(e,t=null){let i=this.checkChart(e,!1),s=new y9;return this.charts.set(i,s),s.initialize(e,t),s}removeChart(e){let t=this.checkChart(e,!0);eH(t)&&(this.charts.get(t).shutdown(),this.charts.delete(t))}removeAllCharts(){for(let e of this.charts.keys())this.removeChart(e)}getChart(e){let t=this.checkChart(e);return eH(t)?this.charts.get(t):null}redraw(e){let t=this.checkChart(e,!0);eH(this.ongoingAnimationCallbackId)||(this.ongoingAnimationCallbackId=requestAnimationFrame(this.drawCharts)),eH(t)&&this.pendingRedraw.add(t)}drawCharts(){this.ongoingAnimationCallbackId=null,this.pendingRedraw.forEach(e=>{let t=this.getChart(e);if(!eH(t?.presenter?.view))return;let i=t.presenter.view;i.isHostElementVisible&&i.draw()}),this.pendingRedraw.clear()}get emptyEntities(){return{metaData:new Set,records:new Set,timeSeries:new Set}}getAllCacheableEntities(e){for(let t of this.charts.values())t.presenter.getCacheableEntities(e)}getCacheableEntities(){let e=this.emptyEntities;return this.getAllCacheableEntities(e),e.timeSeries.forEach(t=>{eH(t)&&(eH(t.record)?e.records.add(t.record):eF(t.records)&&Object.values(t.records).forEach(t=>e.records.add(t)))}),e}clearCaches(){this.evictUnused(this.emptyEntities)}refreshCaches(){this.getTimeSeriesDataSource().refresh(),eN(ay.DF_STREAMRECONNECTED,{})}evictUnused(e){this.getMetaDataSource().evictUnused(e.metaData),this.getRecordSource().evictUnused(e.records),this.getTimeSeriesDataSource().evictUnused(e.timeSeries)}onPerformInternalGc(){let e=this.getCacheableEntities();this.evictUnused(e)}triggerGc(){this.subject?.next()}onChartChanged(e,t){(e===ay.CH_RECREATED||e===ay.CH_SHUTDOWN)&&(this.isAuxiliary?this._mainFeed?.triggerGc():this.triggerGc())}getDefaultMultiFieldCurve(){if(!eH(this.template))return null;if(!this.knowDefaultCurve){let e=n3(this.template);1===e.curves.length&&function(e){switch($[e]){case $.OHLC:case $.HLC:case $.Candlestick:case $.HollowCandles:case $.HeikinAshi:case $.ElderImpulseSystem:case $.Range:case $.MultiColumn:return!0;default:return!1}}(e.curves[0].style)?this.defaultOhlcCurve=ez(e.curves[0]):this.defaultOhlcCurve=null,this.knowDefaultCurve=!0}return this.defaultOhlcCurve}getDefaultAggregation(){return!this.knowDefaultAggregation&&this.template&&(this.defaultAggregation=ez(this.template.data.aggregation),this.knowDefaultAggregation=!0),this.defaultAggregation}getDefaultPeriod(){return!this.knowDefaultPeriod&&this.template&&(this.defaultPeriod=this.template.display?.period,this.knowDefaultPeriod=!0),this.defaultPeriod}getDefaultDensity(){return!this.knowDefaultDensity&&this.template&&(this.defaultDensity=this.template.display?.density,this.knowDefaultDensity=!0),this.defaultDensity}shutdown(){this.isAuxiliary||this.clearCaches(),this.removeAllCharts()}}class SA extends SS{constructor(e){super(e),this.timeSeriesSource=new u8(!1),this.metaDataSource=new io,this.recordSource=new lw}}class ST extends SS{constructor(e){super(e),this.timeSeriesSource=new u8(!0),this.metaDataSource=new io,this.recordSource=new lR}}class Sv extends SS{constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u8(!0),this.metaDataSource=new io,this.recordSource=new lw}}let SP=["drazen.dotlic@barchart.com","princec","b.hebert24@barchart.com"];class SC extends SS{lastStreamingTimestamp=null;_isActivelyStreaming=null;needToResubscribe=!1;_connection;constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u8(!0),this.metaDataSource=new il,this.recordSource=new lN,this.onEvents=this.onEvents.bind(this),this.onTimestamp=this.onTimestamp.bind(this),this.resetStreamingState()}resetStreamingState(){this.lastStreamingTimestamp=null,this._isActivelyStreaming=null,this.needToResubscribe=!1}get connection(){return this._connection}set connection(e){this._connection=e,eH(e)&&this.initializeStreaming()}addChart(e,t=null){return this.needToResubscribe&&this.initializeStreaming(),super.addChart(e,t)}set isActivelyStreaming(e){eH(this._isActivelyStreaming)&&!this._isActivelyStreaming&&e&&(this.debug("need to refresh caches"),this.refreshCaches()),this._isActivelyStreaming=e}get isActivelyStreaming(){return this._isActivelyStreaming}initializeStreaming(){this.resetStreamingState(),this.connection.on("events",this.onEvents),this.connection.on("timestamp",this.onTimestamp)}onTimestamp(e){this.isActivelyStreaming&&(this.lastStreamingTimestamp=e)}debug(e){this.connection&&SP.includes(this.connection._username)&&So(`[chart] Connection ${e}, last timestamp ${this.lastStreamingTimestamp}`)}onEvents({event:e}){e===tz.BC_EVENT_DISCONNECTED||e===tz.BC_EVENT_FEED_PAUSED?(this.debug(e),this.isActivelyStreaming=!1):(e===tz.BC_EVENT_LOGGED_IN||e===tz.BC_EVENT_FEED_RESUMED)&&(this.debug(e),this.isActivelyStreaming=!0)}shutdown(){super.shutdown(),eH(this._connection)&&(this.connection.off("timestamp",this.onTimestamp),this.connection.off("events",this.onEvents),this.resetStreamingState(),this.connection.disconnect(),this.connection=null)}}function Sb(e,t){return new SE(e,t)}class SE{_client;_subscriptions=new Map;_listeners=new Set;constructor(e,t){this._client=e;let i=e=>e.find(e=>this._subscriptions.has(e))??null;t.onConnected=()=>{this._listeners.forEach(e=>e?.onConnected())},t.onMessageWithMetadata=(e,t)=>{let s=e.marketSnapshot;if(eH(s)){let e=i(t);null!==e&&this._listeners.forEach(t=>t.onSnapshot?.(s,e))}let r=e.marketUpdate;if(eH(r)){let e=i(t);null!==e&&this._listeners.forEach(t=>t.onUpdate?.(r,e))}},t.onDisconnected=()=>{this._listeners.forEach(e=>e?.onDisconnected())},t.onHeartBeat=e=>{this._listeners.forEach(t=>t.onHeartBeat?.(e))}}addListener(e){this._listeners.add(e)}removeListener(e){this._listeners.delete(e)}async ready(){return eH(await this._client.connection)}shutdown(){eH(this._client)&&(this._client.dispose(),this._subscriptions.clear(),this._listeners.clear())}subscribeToRealTime(e){if(this._subscriptions.has(e)||!eH(this._client))return;let t=this._client.subscribe(1,5,0,[e],null,null,null);this._subscriptions.set(e,t)}unsubscribeFromRealTime(e){if(!this._subscriptions.has(e)||!eH(this._client))return;let t=this._subscriptions.get(e);this._client.unsubscribe(t),this._subscriptions.delete(e)}async getInstrument(e){let t=await this._client.connection;return await t?.getInstrument(e)??[]}}class SL extends SS{_adapter=null;_auxFeeds=[];constructor(t){super(t),this.cachesData=!0,this.isAuxiliary||(this.timeSeriesSource=new u8(!0),this.metaDataSource=new iu,this.recordSource=new lV,e(cp).subscribe(ay.TS_ALL,this.onTimeSeriesMessage.bind(this)))}onTimeSeriesMessage(e,t){if(!this.isAuxiliary)for(let i of this._auxFeeds)i.notifySeriesMessage(e,t)}notifySeriesMessage(e,t){this.isAuxiliary&&eN(e,t)}getAdapter(){return this.isAuxiliary?this._mainFeed?._adapter:this._adapter}setAdapter(e){if(this.isAuxiliary)throw Error("Cannot set adapter on auxiliary feed");this._adapter=e,this._adapter.addListener(this)}async ready(){if(this.isAuxiliary){let e=await this._mainFeed?.ready()??!1;return e&&(this.template=this._mainFeed.template),e}return await super.ready(),await this._adapter?.ready()??!1}subscribe(e){this.getAdapter()?.subscribeToRealTime(e)}unsubscribe(e){this.getAdapter()?.unsubscribeFromRealTime(e)}shutdown(){super.shutdown(),this.isAuxiliary?(this._mainFeed?.removeAuxFeed(this),this._mainFeed=null):this._adapter?.shutdown()}onConnected(){this.refreshCaches()}onDisconnected(){}onHeartBeat(){}onUpdate(e,t){this.ofRecordSource.onUpdate(e,t)}onSnapshot(e,t){this.ofRecordSource.onSnapshot(e,t)}get ofRecordSource(){return this.recordSource}replaceDataSources(e){super.replaceDataSources(e),this._mainFeed=e}addAuxFeed(e){e.replaceDataSources(this),this._auxFeeds.push(e),this._adapter?.addListener(e)}removeAuxFeed(e){let t=this._auxFeeds.findIndex(t=>t.id==e.id);-1!==t&&(this._auxFeeds.splice(t,1),this._adapter?.removeListener(e),this.triggerGc())}getAllCacheableEntities(e){if(super.getAllCacheableEntities(e),!this.isAuxiliary)for(let t of this._auxFeeds)t.getAllCacheableEntities(e)}}var cp=N("c15IW");let S_=e(cp);export{S_ as PubSub,Sd as initFeed,Sp as getFeed,Sm as shutdownFeed,Sg as getChartOutline,SS as BaseDataFeed,SA as BarchartSiteDataFeed,Sv as MiniWidgetDataFeed,SC as MarketDataFeed,SL as OpenFeed,ST as SnapshotDataFeed,Sb as adaptOpenFeedClient,l6 as OHLCDataPointBuilder,nK as parseExpression,nq as evaluateExpression,nZ as formatExpression,nJ as getExpressionSymbols,n0 as replaceExpressionSymbols,py as ExpressionSeries,pg as makeExpression,uQ as ContainerWrapperTimeSeries,t4 as formatPriceWithDecimals,t5 as getCombinedMetaData,lO as BaseRecordSource,aC as EmptyRecord,ap as Field,ag as Fields,l8 as TimeSeriesContainer,cd as TimeSeriesQuery,nw as Aggregation,tU as asyncReady,tL as hasOpenInterest,l1 as optionValueToDate,e1 as generateUid,s$ as getTaxonomies,sH as doesStudyExist,sN as getAnnotationTraits,gJ as getStudyOptions,cg as StudySeries,cm as makeHelperField,fb as makeStudy,f$ as convertSeries,fG as mapSeries,f_ as movAvg,fM as movExp,fx as movSmo,fI as movWei,fD as movHul,fU as linReg,fN as trueRange,fH as typical,fF as roc,fW as stdDev,ay as Topics,ix as getLightness,en as ChunkPart,J as SeriesKind,z as AggregationSpec,G as AggregationUnit,B as ExpressionRecompute,k as ExpressionNoDataApproach,F as ExpressionMissingBar,Y as FieldValueType,K as FieldCategory,j as FieldFormat,ym as CustomEventPopup,tB as appendDOMElement,tN as styleDOMElement,tV as setAttributesDOMElement};
20
+ </svg>`),tN(this.goToLatestButton,{position:"absolute",right:0,bottom:0,"z-index":3}),tV(this.goToLatestButton,{class:"go-to-latest"}),this.goToLatestButton.onclick=()=>{this.xAxis.goToLatest()},this.listeners.push(()=>{this.goToLatestButton.onclick=null}),this.mainContext=this.mainCanvas.getContext("2d"),this.mouseContext=this.mouseCanvas.getContext("2d"),this.splitters=[],this.xAxis=new yl(this),this.eventCapture=new yc(this),this.eventCapture.init(this.mouseCanvas),this.setChartSize(n,r);let o=tO(this.el);eF(tR(`.${tz.SVG_ICONS_DOM_NODE}`,o))||function(e){let t=tB(e,"div");tV(t,{class:tz.SVG_ICONS_DOM_NODE});let i=Object.keys(hN).map(e=>`<symbol id="${hB(e)}" viewBox="0 0 1024 1024">${hN[e]}</symbol>`).join("");t.innerHTML=`<svg style="display:none" xmlns="http://www.w3.org/2000/svg" version="1.1"><defs>${i}</defs></svg>`}(o)}reinitialize(){this.el&&tk(".bcharts-card",this.el).forEach(e=>e.remove()),this.customEventPopup?.hide(),this.drawCrosshair({ap:void 0}),this.tooltip.hide(),this.tooltip.setMode(this.presenter.display.tooltip.mode),this.resetZoomAndVisibleRange?this.xAxis=new yl(this):this.xAxis?.updateConfigFromModel(),this.recalculateLayout(),this.redraw()}setSize(e,t,i=!1){this.setChartSize(e,t),this.redraw(i)}setChartSize(e,t){let i={width:`${e}px`,height:`${t}px`};tN(this.el,i),this.width=e,this.height=t;let s=globalThis.devicePixelRatio||1,r={height:this.height*s,width:this.width*s};[this.mainCanvas,this.mouseCanvas].forEach(e=>{tV(e,r),tN(e,i)}),this.mainContext.scale(s,s),this.mouseContext.scale(s,s),this.recalculateLayout(),this.presenter&&mG(this.presenter)}widthNeeded(e,t){let i=this.presenter.allAxes.filter(e=>e.onTheRight===t);return 0===i.length?0:Math.max(...i.map(t=>t.widthNeeded(e)))}recalculateLayout(){if(!this.isHostElementVisible)return;this.leftOffset=0,this.rightOffset=0,this.presenter.allAxes.forEach(e=>e.clearTicks()),this.splitters.length=0;let e=this.xAxis.heightNeeded(this.mainContext),t=this.widthNeeded(this.mainContext,!0),i=this.widthNeeded(this.mainContext,!1),s=this.height-e,r=this.presenter.panes,n=em(r.map(e=>e.height)),a=0,o=tz.PANE_SPLITTER_PERCENT_HEIGHT/100,l=Math.floor(o*s);n*=1+(r.length-1)*o;let u=this.presenter.display?.yAxis?.primaryOnTheLeft??!1;this.presenter.display.yAxis.visible&&(r.some(e=>e.axes.length>1)?(this.leftOffset=i,this.rightOffset=t):u?this.leftOffset=i:this.rightOffset=t),r.forEach((e,i,r)=>{let o=i===r.length-1,u=Math.floor(s*e.height/n),h=new iw(0,a,this.width,u);e.setViewBox(h);let c=new iw(this.width-this.rightOffset,a,t,u),d=new iw(0,a,this.leftOffset,u),p=e=>e.setViewBox(e.onTheRight?c:d);if(p(e.axes[0]),e.axes[1]&&p(e.axes[1]),a+=u,!o){let e=new iw(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,l);this.splitters.push(e),a+=l}});let h=new iw(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,e);this.xAxis.setViewBox(h),tN(this.goToLatestButton,{right:`${t+5}px`,bottom:`${e+5}px`}),this.updateLegend(),this.xAxis.setDomain(),this.setPriceAxesDomains(),this.notifyLayoutChanged({chart:this.presenter.accessor})}setPriceAxesDomains(){this.presenter.allAxes.forEach(e=>{e.setDomain(),e.updateFullDomain()}),this.presenter.priceDomainsUpdated()}draw(){for(let e of(this.mainContext.save(),this.mainContext.miterLimit=1,this.drawBackground(this.mainContext),this.presenter.panes))e.drawBackground(this.mainContext);for(let e of(this.xAxis.draw(this.mainContext),this.presenter.panes))e.draw(this.mainContext);this.drawSplitters(this.mainContext),this.presenter.title.draw(this.mainContext);let e=Sp().config.showGoToLatest,{showGoToLatest:t}=this.presenter.display.chart,i=eF(e)?e:t;this.goToLatestButton.style.display=i&&this.xAxis.canGoToLast()?"block":"none",this.mainContext.restore()}get isHostElementVisible(){return eF(this.el)&&eF(this.el.offsetParent)}redraw(e=!1){this.isHostElementVisible&&(e?this.draw():Sp().redraw(this.presenter.hostElement))}drawBackground(e){let t=this.presenter.display.chart.backgroundColor;e.clearRect(0,0,this.width,this.height),e.fillStyle=t,e.fillRect(0,0,this.width,this.height)}drawCrosshair({ap:e,offset:t}){let i=this.mouseContext;return i.clearRect(0,0,this.width,this.height),!!e&&!!this.xAxis.drawCrosshair(i,t)&&(this.presenter.display.yAxis.visible&&e.axis.pane.drawYCrosshair(i,t),!0)}drawSplitters(e){e.strokeStyle=(e=>{let t=iM(e);return iD(iE(function({r:e,g:t,b:i,a:s}){return{r:255-e,g:255-t,b:255-i,a:s}}(t),t,.7))})(this.presenter.display.chart.backgroundColor),e.lineWidth=2,this.splitters.forEach(t=>{let{x:i,y:s,width:r,height:n}=t,a=s+n/2;e.beginPath(),e.moveTo(i,a),e.lineTo(i+r,a),e.stroke()})}toTime(e){return this.xAxis.xScale.xToTime(e)}toIndex(e){return this.xAxis.xScale.timeToIndex(e)}toX(e){return this.xAxis.xScale.timeToX(e)}setCursor(e){let t=function(e){switch(e){case ee.Arrow:default:return"default";case ee.Crosshair:return"crosshair";case ee.Hand:return"pointer";case ee.Move:return"move";case ee.ResizeVertical:return"ns-resize";case ee.Grabbing:return"grabbing";case ee.ResizeHorizontal:return"ew-resize"}}(e);tN(this.el,{cursor:t})}shutdown(){this.listeners.forEach(e=>e()),this.eventCapture&&this.eventCapture.shutdown(),this.tooltip&&this.tooltip.remove(),this.el&&tk(".bcharts-card",this.el).forEach(e=>e.remove()),this.canvasContainer.remove()}getEventRadius(){return Math.max(this.xAxis.xScale.bar.width/2,tz.MIN_EVENT_RADIUS)}}class ym{view;popupElement;date;value;visible;_initialized;constructor(e){this.view=e,this.date=null,this.value=null,this.visible=!1,this._initialized=!1}initialize(){this.popupElement=tB(this.view.el,"div"),tV(this.popupElement,{id:`${this.view.presenter.elementId}-custom-event-host`}),tN(this.popupElement,{visibility:"hidden",position:"absolute","z-index":30,top:"0px",left:"0px",padding:"5px 10px 10px 10px",display:"flex","flex-direction":"column",background:"var(--chartPopupElemBg, #999)","box-shadow":"0px 2px 10px rgba(0,0,0,.3)","border-radius":"4px",border:"1px solid var(--chartPopupElemBorderColor, #888)","max-height":"400px",overflow:"auto"});let e=tB(this.popupElement,"a");tV(e,{class:"custom-event-close-button"}),tN(e,{position:"absolute",right:"10px",top:"5px",fill:"var(--text-color,#888)",cursor:"pointer"}),e.innerHTML='<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="12px" height="12px"><use xlink:href="#bchart-icon-delete"></use></svg>',e.addEventListener("click",e=>this.hide()),this._initialized=!0}showValue(){}show(e,t,i){this._initialized||this.initialize(),this.date=t,this.value!==i&&(this.value=i,this.showValue()),tN(this.popupElement,{visibility:"visible",top:`${e.y}px`,left:`${e.x}px`,width:"310px"}),this.visible=!0}hideValue(){}hide(){this.visible&&(this.hideValue(),tN(this.popupElement,{visibility:"hidden"}),this.visible=!1)}}function yg(e,t){if(!(e.annotations&&e.annotations.length>0))return;let i=t.annotations||[];t.annotations=i.concat(e.annotations)}let yy='..axes{..plots{.type==="Study"}}';var cp=N("c15IW");let yS={ok:!1,change:void 0,toApply:void 0};class yA{presenter;paused;undoStack;redoStack;initial;isPaused;constructor(e){this.presenter=e,this.paused=null,this.undoStack=[],this.redoStack=[],this.initial=new Map,this.isPaused=!1,this.clear()}clear(e=!1){this.undoStack=[],this.redoStack=[],this.initial=new Map,e&&this.presenter.allAnnotations.forEach(e=>this.initial.set(e.uid,my(e,el.Moved)))}done(e){if(this.isPaused){this.paused=e;return}this.undoStack.push(e),this.redoStack.length=0}undo(){this.undoRedo(this.undoStack,this.redoStack,!0)}pause(){this.isPaused=!0}resume(e){this.isPaused=!1,e&&eH(this.paused)&&this.done(this.paused),this.paused=null}redo(){this.undoRedo(this.redoStack,this.undoStack,!1)}delete(e){let t={...e,id:"Delete"};this.presenter.handleAnnotationChange(t)}add(e){this.presenter.handleAnnotationChange({annotation:e,id:"Add"})}apply(e,t,i){if(!eF(e))return!1;switch(t){case el.None:case el.Undo:case el.Redo:So(`Unexpected tool change ${el[t]} for undo/redo`,"warn");break;case el.Created:i?this.delete(e):this.add(e);break;case el.Deleted:i?this.add(e):this.delete(e);break;default:{let t={...e,id:"Update"};this.presenter.handleAnnotationChange(t)}}let s=this.presenter.allAnnotations.find(t=>t.uid===e.uid),r=i?el.Undo:el.Redo;return eF(s)&&this.presenter.onAnnotationModifiedByTool(s,r),!0}can(e){let t=e?this.undoStack:this.redoStack;if(t.length<1)return yS;let i=eC(t),s=i.toolChange;if(!(e&&s!==el.Deleted&&s!==el.Created))return{ok:!0,change:s,toApply:i};let r=eE(t,e=>e.uid===i.uid,t.length-2),n=-1!==r?t[r]:null,a=null===n;return a&&!this.initial.has(i.uid)?yS:{ok:!0,change:s,toApply:a?this.initial.get(i.uid):n}}get canUndo(){return this.can(!0).ok}get canRedo(){return this.can(!1).ok}undoRedo(e,t,i){let{ok:s,change:r,toApply:n}=this.can(i);if(!s)return;let a=e.pop();this.apply(n,r,i),t.push(a)}}class yT{presenter;text;align;verticalAlign;x;y;style;constructor(e){this.presenter=e,this.text=null,this.align="center",this.verticalAlign="top",this.x=0,this.y=0,this.style={color:"#333",fontSize:18}}update({style:e,...t}){Object.assign(this,t),Object.assign(this.style,e)}draw(e){if(!this.text)return;let{fontFamily:t}=this.presenter.display.chart,{fontSize:i,color:s,fontWeight:r}=this.style,{x:n,y:a,width:o,height:l}=this.presenter.mainPlot.axis.pane.getBounds(),u=n+this.presenter.view.leftOffset,h=n+o-this.presenter.view.rightOffset,c=u;c="center"===this.align?o/2:"right"===this.align?h:u;let d=a+i;"middle"===this.verticalAlign?d=a+i+l/2:"bottom"===this.verticalAlign&&(d=a+l),c+=this.x,d+=this.y,e.save(),e.font=`${r||"normal"} ${i}px ${t}`,e.textAlign=this.align,e.textBaseline="bottom",e.fillStyle=s,e.fillText(this.text,c,d),e.restore()}}function yv(e={}){let t=this.allPlots;if(!t.every(e=>eF(e.timeSeries)&&e.timeSeries.hasData))return"No data to export";let i=e.excludeHeader??!1,s=e.numDecimals??null,r=e.excludeFields??[],n=e=>{let t=new Map;return e.main&&(t.set(ag.DateTime,0),this.data.aggregation.isMultiContract&&!e.isExpression&&t.set(ag.Symbol,0)),e.curves.forEach(e=>{e.fields.forEach(i=>{r.includes(i.id)||t.set(i,e.shift)})}),Array.from(t)},a=this.data.aggregation.isEndOfDay?tz.FMT_ISO_DATE_ONLY:tz.FMT_EXPORT_ALL_BUT_MILLIS,o=(e,t)=>e===ag.DateTime?o3(t,a):(eF(s,t)?eB(t,s):t)?.toString()??"",l={},u=this.timeline.lastSeriesIndex,h=eb(this.mainPlot.timeSeries.container.getTimeData()),c=e_(this.timeline,+h,Number,hw),d=(e,t)=>{let i=this.timeline.at(e),s=t.timeSeries.container,r=s.getTimeData(),u=e_(r,+i,Number,eL,l[t.id]||0),h=+i==+r[u];return h&&(l[t.id]=u),n(t).map(([t,n])=>{if(0===n)if(h)return o(t,s.getData(t)[u]);else if(t===ag.DateTime)return o3(i,a);else return"";{let i=this.timeline.at(e-n),a=e_(r,+i,Number,eL,0);return+i==+r[a]?o(t,s.getData(t)[a]):""}})},p=e=>{let i=t.map(e).flat();return i.slice(1).every(e=>0===e.length)?null:i.join(",")},f=[];i||(f.push(p(e=>{let t=Array(n(e).length).fill("");return t[0]=`"${Z[e.type]}: ${e.title}"`,t})),f.push(p(e=>n(e).map(([e,t])=>`"${e.name}"`))));let m=[0,0];this.allCurves.forEach(e=>{!e.fields.every(e=>r.includes(e.id))&&(e.shift<0&&(m[0]=Math.min(m[0],e.shift)),e.shift>0&&(m[1]=Math.max(m[1],e.shift)))});for(let e=c+m[0];e<=u+m[1];e++){let t=p(eh(d,e));null!==t&&f.push(t)}return f.join("\n")}function yP(e={}){let t=this.view.mainCanvas,{width:i,height:s}=t,{width:r,height:n,title:a}=e,o=(e,t)=>{let i=document.createElement("canvas");return i.width=e,i.height=t,i.getContext("2d")},l=o(i,s),u=globalThis.devicePixelRatio;if(l.drawImage(t,0,0),l.scale(u,u),eH(a)){let e=new yT(this);e.update(a),e.draw(l)}let h=this.mainPlot?.timeSeries.container?.getLastDataPoint(ag.DateTime);if(eH(h)){let{fontFamily:e}=this.display.chart,{fontWeight:i,fontSize:s}=this.mainAxis.config;l.font=`${i} ${1.2*s}px ${e}`,l.textBaseline="top";let r=1.5*s,n=getComputedStyle(t),a=n.getPropertyValue("--app-hc-color"),o=n.getPropertyValue("--app-color-pl"),u={x:tz.CARDS_X_OFFSET,y:tz.CARDS_Y_OFFSET},c=hY(this,h,u,void 0,!1,0),d=`${c.date} ${c.time??""}`.trim(),[p,f]=[1,5],m=(e,t)=>l.measureText(e).width+t,g=(e,t,i,s,r)=>(l.fillStyle=s,l.fillText(e,t,i),m(e,r)),y=(e,t)=>e.type===Z[t];c.panes.forEach(e=>{let{top:t,left:i,width:s,right:n}=e.bounds,l=i+s-n-f,h=i+u.x,c=t+u.y;e.plots.some(e=>e.isMain)&&(h+=g(d,h,c,a,f)),e.plots.forEach((e,t)=>{let s,n=(s=e.name,e.isMain&&y(e,"Symbol")?s=`${e.description} (${e.name}) [${e.exchange}]`:y(e,"Study")&&(s=`${e.description} ${e.name.substring(e.name.indexOf(" "))}`),s),d=!y(e,"Study")&&e.values.length>1;if(!e.isMain&&t>0){let t=h+m(n,f);e.values.forEach(e=>{d&&(t+=m(e.abbreviation,p)),t+=m(e.value,f)}),t>=l&&(h=i+u.x,c+=r)}h+=g(n,h,c,a,f),e.values.forEach(e=>{d&&(h+=g(e.abbreviation,h,c,o,p)),h+=g(e.value,h,c,e.color,f)})})})}let c=e=>({width:r??i,height:n??s,data:e.toDataURL("image/png")});if(!(eH(r)&&eH(n)))return c(l.canvas);{let e=o(r,n);return e.drawImage(l.canvas,0,0,r,n),c(e.canvas)}}let yC=Symbol.for("__ias__");class yb{accessor;view;defaultTool;_activeTool;tooltipEnabled;timeline;sentInitialLoadNotification;_hostElement;undoRedoManager;title;display;model;data;panes;_hasLegend;renderTo;seriesChangedToken;metaChangedToken;streamingSubscription;_previousMask;_ohlcMask;selectedAnnotation;forceResetVisibleRange;_maxOffset;_isShutdown;notifySelectionChanged;notifyRecreated;notifyDefinitionChanged;constructor(e){this.accessor=e,this.tooltipEnabled=!0,this.sentInitialLoadNotification=!1,this._hostElement=null,this.panes=[],this.seriesChangedToken="",this.metaChangedToken="",this.streamingSubscription=null,this._previousMask=0,this.forceResetVisibleRange=!1,this._maxOffset=0,this._isShutdown=!1,this.defaultTool=gj("Default"),this._activeTool=this.defaultTool,this.timeline=new hR(this),this.undoRedoManager=new yA(this),this.title=new yT(this),this.notifySelectionChanged=eV(ay.CH_ANNSELECTIONCHANGED),this.notifyRecreated=eV(ay.CH_RECREATED),this.notifyDefinitionChanged=eV(ay.CH_DEFINITION_CHANGED)}getModel(){return this.model}get isEmpty(){return!eF(this.model)}notifyHost(e,t){eN(e,t)}async fromModel(e,t){if(this._isShutdown)return;eF(this.model)&&this.allPlots.forEach(e=>e.shutdown()),this.sentInitialLoadNotification=!1,this.clearSelection(),this.model=e;let i=ez(e);this.data=i.data,this.data.aggregation=n_(i.data.aggregation),this.display=i.display,eF(this.display.period)&&(this.display.period=eQ(this.display.period)),this.panes=i.panes.map(e=>{let t=new yr(this);return t.fromModel(e),t},this);let s=this.allPlots.map(e=>e.initialize());await Promise.all(s),this._isShutdown||(this.timeline.invalidate(),this.checkZoomAndVisibleRange(e,t),eF(e,t)&&this.notifyDefinitionChanged({chart:this.accessor}),this.reinitializeView())}checkZoomAndVisibleRange(e,t){if(this.view)if(this.forceResetVisibleRange)this.forceResetVisibleRange=!1,this.view.resetZoomAndVisibleRange=!0,this._maxOffset=0;else{let i=!t||function(e,t,i){let s={id:"Aggregation",context:{id:"Get"}};if(y_(nL(y5(s,t,i)),nL(y5(s,e,i)))||!yE(e.display?.xAxis?.visibleRange,t.display?.xAxis?.visibleRange)||e.display?.xAxis?.marginBars!==t.display?.xAxis?.marginBars||!yE(e.data?.range,t.data?.range)||e.data?.extendedHours!==t.data?.extendedHours||e.display?.period!==t.display?.period||e.display?.density!==t.display?.density)return!0;let r=n3(t),n=n3(e);if(function(e,t){let i=e=>e.curves[0],s=i(e),r=i(t),n=yL.includes(s.style),a=yL.includes(r.style);if(n!==a)return!0;if(!a)return!1;if(s.style!==r.style)return!0;if(t.inputs&&y_(eK(e.inputs),eK(t.inputs)))return!0;return!1}(r,n))return!0;let a=e=>{let t=e.toLowerCase();return n.type===e&&r.type===e&&r[t]!==n[t]},o=r.type!==n.type,l=a("Forward"),u=a("Expression"),h=a("Symbol");return o||l||u||h}(e,t,this);this.view.resetZoomAndVisibleRange=i,i&&(this._maxOffset=0)}}closeView(){eF(this.view)&&(this.view.shutdown(),this.view=void 0)}reinitializeView(){this._isShutdown||(eF(this.view)?this.view.reinitialize():(this.view=new yf,this.view.initialize(this)),this.notifyRecreated({elementId:this.elementId}))}getCacheableEntities(e){this.isEmpty||this.allPlots.map(t=>t.getCacheableEntities(e))}get activeTool(){return this._activeTool}set activeTool(e){eF(this._activeTool.deactivated)&&this._activeTool.deactivated(this),this._activeTool=e,eF(this._activeTool.activated)&&this._activeTool.activated(this),this.notifyHost(ay.TL_CHANGED,{chart:this.accessor})}get mainPlot(){return this.allPlots.find(e=>e.main)}get mainAxis(){return this.mainPlot?.axis}get mainPane(){return this.mainAxis?.pane}get allAxes(){let e=[];return this.panes.forEach(t=>{t.axes.forEach(t=>{e.push(t)})}),e}get plotAnnotations(){let e=[];return this.allPlots.forEach(t=>{t.annotations?.forEach(t=>{e.push(t)})}),e}get allAnnotations(){let e=[];return this.allAxes.forEach(t=>{t.annotations.forEach(t=>{e.push(t)})}),e}get allPlots(){let e=[];return this.allAxes.forEach(t=>{t.plots.forEach(t=>{e.push(t)})}),e}findAxis(e){return this.allAxes.find(t=>t.id===e)}findPlot(e){return this.allPlots.find(t=>t.id===e)}get allCurves(){let e=[];return this.allPlots.forEach(t=>{t.curves.forEach(t=>{e.push(t)})}),e}findCurve(e){return this.allCurves.find(t=>t.id===e)}fixupDensityForForwards(){let e=this.allPlots.filter(e=>e.isForward).map(e=>e.timeSeries.container?.size??0);e.some(e=>e>0)&&(this.display.density=Math.max(...e))}onSeriesChanged(e,t){if(!this.view||!this.allPlots)return;let i=t.series,s=e=>e.timeSeries===i||e.eventsSeries===i,r=this.allPlots.find(s);if(!eF(r))return;let n=eF(r)&&r.main,a=!1,o=!1;if(e===ay.TS_TIMELINECORRECTION){if(!this.timeline.tryToCorrectLastBar(t.from,t.to))return;a=!0}let l=eF(t.index)?i.container.getTimeData()[t.index]:null,u=e===ay.TS_EVENTSCHANGED,h=this.view.xAxis,c=h.xScale;if(e===ay.TS_MANYCHANGED||u){if(n&&this.data.checkRange)if(eF(this.display.xAxis.visibleRange)){let e={id:"Period",context:{range:this.display.xAxis.visibleRange}};e[yC]=!0,this.accessor.change(e);return}else delete this.data.checkRange;r.isForward&&this.fixupDensityForForwards();let e=this.view.xAxis?.getMaxCurveOffset()??0;if(r.isStudy&&(e!==this._maxOffset&&(this._maxOffset=e,h.goToLatest(!0)),r.invalidateAssociatedAnnotations("NewChunkArrived")),(r.isSeasonal&&!h.wasVisibleRangeChanged||this.display?.xAxis?.isOrdinal)&&h.goToLatest(!0),t.part===en.Tail){let e=e_(this.timeline,l,Number,hw);h.shouldScrollIntoView(e)&&c.shiftBars(t.count)}this.timeline.invalidate(),this.allPlots.forEach(e=>e.invalidatePriceMappingCache()),a=!0}else if(e===ay.TS_DATAPOINTADDED){let e=this.timeline.mergeDateIntoTimeline(l);-1!=e&&h.shouldScrollIntoView(e)?(c.shiftBars(1),a=!0):o=!0,r.isStudy&&r.invalidateAssociatedAnnotations("DataPointAdded")}else e===ay.TS_DATAPOINTCHANGED&&(o=!0,r.isStudy&&r.invalidateAssociatedAnnotations("DataPointChanged"));if(!u&&s(this.mainPlot)&&i.hasData&&0===i.container.size&&this.notifyHost(ay.CH_NODATAFORMAINSYMBOL,{chart:this.accessor}),a&&this.view.recalculateLayout(),o&&(a&&So("Performance : redundant call to recompute price domains (layout recalculation took care of this)","warn"),this.allAxes.filter(e=>e.plots.includes(r)).forEach(e=>{e.setDomain(),eF(l)&&e.updateFullDomain(l)})),!this.sentInitialLoadNotification&&e===ay.TS_MANYCHANGED&&this.allPlots.every(e=>e.timeSeries&&e.timeSeries.hasData)){this.sentInitialLoadNotification=!0,this.notifyHost(ay.CH_ALL_DATA_PROJECTED,{chart:this.accessor}),mG(this);let e=this.display.period===tz.FIFTY_YEARS_MILLIS;this.mainPlot&&e&&(c.fitAllData=!0,c.adjustDomain())}this.view.redraw()}onMetaChanged(e,t){e===ay.MD_CHANGED&&this.view&&this.allPlots&&this.allPlots.find(e=>e.id===t.plot.id)&&(this.view.recalculateLayout(),this.view.redraw())}priceDomainsUpdated(){this.allPlots.forEach(e=>{e.notifyAboutPriceDomains&&e.onPriceDomainsUpdated()})}onScaleDomainChanged(e){let t=this.panes.indexOf(e.pane),i=e.pane.axes.indexOf(e),s={chart:this.accessor,paneIndex:t,axisIndex:i};this.notifyHost(ay.CH_AXISSCALECHANGED,s)}get previousMask(){return eF(this._previousMask)||(this._previousMask=aA(ag.PreviousClose)),this._previousMask}hasMatch(e,t){return e.some(e=>e.updated&&t)}get hasLegend(){return eF(this._hasLegend)||(this._hasLegend=Sp().config.mode===er[er.cmdtyView]),this._hasLegend}onStreamingUpdates(e){eF(this.view)&&(this.mainPlot.showPrevious&&this.hasMatch(e,this.previousMask)&&this.view.redraw(),this.hasLegend&&this.hasMatch(e,this.ohlcMask)&&this.view.updateLegend())}get ohlcMask(){return eF(this._ohlcMask)||(this._ohlcMask=aA(ag.Open,ag.High,ag.Low,ag.Close,ag.PreviousClose)),this._ohlcMask}updateMatches(e,t){if((e&this.ohlcMask)==0)return!1;let i=(e,t)=>eH(e)&&e.isValid&&e.hasSymbol(t);return this.mainPlot.isSymbol?i(this.mainPlot.timeSeries.record,t):!!this.mainPlot.isExpression&&i(this.mainPlot.record,t)}getStreamingSubscription(){return Sp().getRecordSource().subject.pipe(ub(e=>e.filter(e=>this.updateMatches(e.updated,e.data.symbol))),ov(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}get hostElement(){return this._hostElement}get elementId(){return eF(this._hostElement)?this._hostElement.id:null}initialize(t){if(this._hostElement=t instanceof HTMLElement?t:tR(`#${t}`),!this._hostElement)throw Error(`There is no element ${t} in the DOM`);this.renderTo=t,this.seriesChangedToken=e(cp).subscribe(ay.TS_ALL,this.onSeriesChanged.bind(this)),this.metaChangedToken=e(cp).subscribe(ay.MD_ALL,this.onMetaChanged.bind(this)),this.streamingSubscription=this.getStreamingSubscription()}shutdown(){return e(cp).unsubscribe(this.seriesChangedToken),e(cp).unsubscribe(this.metaChangedToken),eF(this.streamingSubscription)&&this.streamingSubscription.unsubscribe(),this.allPlots.forEach(e=>e.shutdown()),this.model=void 0,this.closeView(),this.notifyHost(ay.CH_SHUTDOWN,{elementId:this.elementId}),this._isShutdown=!0,!0}setSelection(e){this.selectedAnnotation=e,this.selectedAnnotation.isSelected=!0,this.selectedAnnotation.requestRedraw(),this.notifySelectionChanged({chart:this.accessor})}clearSelection(){eF(this.selectedAnnotation)&&(this.selectedAnnotation.isSelected=!1,this.selectedAnnotation.requestRedraw(),this.selectedAnnotation=void 0),this.notifySelectionChanged({chart:this.accessor})}resetActiveTool(){this.activeTool=this.defaultTool,this.view.setCursor(ee.Arrow)}print(e={}){let t=tB(document.body,"iframe");t.src="",t.style.display="none",t.onload=()=>{let{title:i}=e,s=yP.call(this,{title:i}),r=new Image;r.src=s.data,r.style.width="100%",t.contentDocument.body.appendChild(r),new Promise(e=>{let t=()=>{r&&void 0!==r.naturalWidth&&0!==r.naturalWidth&&r.complete?e():setTimeout(t,150)};t()}).then(()=>{let e=t.contentWindow;t.focus(),e.print(),t.remove()})}}setTitle(e,t=!1){this.title.update(e),eF(this.view)&&this.view.redraw(t)}enableTooltip(e){this.tooltipEnabled=e;let t=this.display.tooltip.mode===tz.TOOLTIP_CARDS;!e&&t&&this.hideCards()}get showTooltip(){return this.display.tooltip.visible&&this.tooltipEnabled}hideCards(e=!1){let t=this.display.tooltip,i=eO();!e&&t.visible&&t.mode===tz.TOOLTIP_CARDS&&tk(".bcharts-card",this.hostElement).forEach(e=>{let t=e.classList.contains("bcharts-card-move");i&&t||e.classList.contains("bcharts-legend")||(e.style.display="none")})}handleAnnotationChange(e){let t=(e,t=!0)=>({id:t?e.name:e.id,uid:e.uid,visible:e.visible});if("List"===e.id)return this.allAnnotations.map(t);if("Cache"===e.id)return sz(this.model,"..annCache{.annotations}").map(e=>({symbol:e.symbol,annotations:e.annotations.map(e=>t(e,!1))}));if("Add"===e.id)return this.mainAxis.addAnnotation(e.annotation);let i=this.allAnnotations.find(t=>t.uid===e.uid);if(void 0!==i){let t=i.axis,s=t[`${e.id.toLowerCase()}Annotation`];if("function"==typeof s){s.call(t,i,e),"Delete"!==e.id||e.isUndoRedo||this.onAnnotationModifiedByTool(i,el.Deleted);return}}throw Error(`Unknown sub-action ${e.id} for action ${tz.ANN_ACTION_ID}`)}getPlotInfoFromDomId(e){let t=e.attributes.getNamedItem("data-plot-id").value,i=this.allPlots,s=i.findIndex(e=>e.id===t);return{type:Z[i[s].type],index:s}}getSimplePlot(e,t){return this.accessor.change({id:"Plot",context:{id:tz.ACTION_GET,type:e,index:t}})[0]}onCardClicked(e){let t=this.getPlotInfoFromDomId(e),i=this.getSimplePlot(t.type,t.index),s={chart:this.accessor,plot:i};this.notifyHost(ay.CH_CARDPLOTCLICKED,s)}deletePlotClicked(e){let t=this.getPlotInfoFromDomId(e),i=this.getSimplePlot(t.type,t.index);this.accessor.change({id:"Plot",context:{id:"Delete",type:t.type,index:t.index}});let s={chart:this.accessor,plot:i};this.notifyHost(ay.CH_CARDPLOTREMOVED,s)}showHidePlotClicked(e){this.defaultTool.hideCrosshairAndTooltips(this.view,!0);let t=this.getPlotInfoFromDomId(e),i="Show"===e.attributes.getNamedItem("data-act").value;this.accessor.change({id:"Plot",context:{id:"Update",type:t.type,index:t.index,visible:i}});let s=this.getSimplePlot(t.type,t.index),r={chart:this.accessor,plot:s,visible:i};this.notifyHost(ay.CH_CARDPLOTVISIBILITYCHANGED,r)}plotMoreActionsClicked(e,t){let i=this.getPlotInfoFromDomId(e),s=this.getSimplePlot(i.type,i.index),r={x:t.clientX,y:t.clientY},n={chart:this.accessor,plot:s,offset:r,originalEvent:t};this.notifyHost(ay.CH_PLOTNEEDSCONTEXTMENU,n)}onMovePaneClicked(e){let t=parseInt(e.attributes.getNamedItem("data-pane").value),i="Down"===e.attributes.getNamedItem("data-dir").value,s=t+ +!!i,r=t-!i;setTimeout(()=>{this.accessor.change({id:"MovePane",context:{from:s,to:r}}),this.notifyHost(ay.CH_PANESREORDERED,{chart:this.accessor})})}onAnnotationsUpdated(e,t=!1){var i,s;let r=this.allAxes.indexOf(e),n=e.annotations.map(e=>e.toModel()),a=(i=this.model,s={axisIndex:r,annotations:n},sY(i,`..axes[${s.axisIndex}]`,e=>(e.annotations=s.annotations,e)));try{this.model=ah(a,tz.CHART_SCHEMA)}catch(e){So(`Cannot update annotation (corrupts definition), error is: ${e.message}`,"error")}t&&this.view.draw(),this.notifyHost(ay.CH_ANNOTATIONCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}onAnnotationModifiedByTool(e,t,i=!0){if(t!==el.None){if(i&&t!==el.Undo&&t!==el.Redo){let i=my(e,t);this.undoRedoManager.done(i)}let s=mS(e);s.toolChange=el[t],this.notifyHost(ay.CH_ANNMODIFIEDBYTOOL,s)}}onAnnotationDone(e,t){let i={id:e,chart:this.accessor,toolChange:el[t]};this.notifyHost(ay.CH_ANNMODIFIEDBYTOOL,i)}onPaneHeightsUpdated(){var e,t;let i,s=this.panes.map((e,t)=>({index:t,relativeHeight:e.height}));this.model=(e=this.model,t={paneHeights:s},i=e,t.paneHeights.forEach(e=>{let t;i=sY(i,(t=e.index,`..panes[${t}]`),t=>(t.height=e.relativeHeight,t))}),i),this.notifyHost(ay.CH_PANEHEIGHTSCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}getDataStats(){let e=this.mainPlot.timeSeries.container;if(!eF(e)||0===e.size)return null;let t=e.getTimeData();return{dataRange:{from:eb(t).getTime(),to:eC(t).getTime()},barCount:e.size}}}function yE(e,t){return e?.from===t?.from&&e?.to===t?.to}let yL=["Renko","Range","LineBreak","Kagi","PointAndFigure"];function y_(e,t){for(let i of Object.keys(e))if(e[i]!==t[i])return!0}let yM="MARKED_FOR_DELETION";function yx(e,t){if(0===t.plots.length)return e;let i=e;return t.plots.forEach(e=>{let t=yO(e.index),s=yw(i,t);eF(s)&&s.type===e.type&&(i=sY(i,t,e=>(e[yM]=!0,e)))}),ac(i=sY(i,`..plots{.${yM} === true}`,e=>tz.NULL_OBJECT))}function yI(e,{main:t,type:i,index:s},r){let n="..plots{.main === true}",a=sz(e,"..panes").map((e,t)=>{let i=1===sz(e,n).length;return sz(e,"..axes").map((e,s)=>{let a=1===sz(e,n).length;return sz(e,"..plots").map(e=>{let n=function(e,t,i,s){let r=Z[e.type],n={curves:ez(e.curves),type:e.type};n.precision=e.precision,n.visible=e.visible;let a=(e,t)=>{eF(e[t])?n[t]=e[t].map(e=>ez(e)):n[t]=[]},o=(e,t,i=!1)=>{!0===t.main&&(e.main=!0,e.showPrevious=t.showPrevious,i&&null!=t.events&&(e.events=ez(t.events)))},l=(e,t=e=>!0)=>{eF(s)&&(e.subtitles=s.allPlots.filter(e=>e.type===r).filter(t).map(e=>e.title))};switch(r){case Z.Symbol:{n.title=e.symbol;let t=n.curves[0].style,i=t=>{a(e,"inputs"),0===n.inputs.length&&(n.inputs=ez(t))};switch(t){case"Renko":i(tz.DEFAULT_RENKO_INPUTS);break;case"Kagi":i(tz.DEFAULT_KAGI_INPUTS);break;case"PointAndFigure":i(tz.DEFAULT_PNF_INPUTS);break;case"LineBreak":i(tz.DEFAULT_LINEBREAK_INPUTS);break;case"Baseline":i(tz.DEFAULT_BASELINE_INPUTS)}o(n,e,!0);break}case Z.Study:{a(e,"inputs");let s=sR(e.study),r=n.inputs,o="AVWAP"===e.study,l=0===r.length?"":` (${r.map(e=>o&&"Anchor"===e.name?new Date(e.value).toLocaleString():e.value).join(", ")})`,u=n.curves.map(e=>Number(e.shift)).filter(e=>e>0),h=0===u.length?"":` [${u.join(", ")}]`;n.title=`${s.id}${l}${h}`,n.studyId=s.id,a(e,"levels"),a(e,"bands"),n.placement=t?i?"overlay":"withMain":"standalone",n.detachedScale=e.detachedScale;break}case Z.BalanceSheet:case Z.IncomeStatement:{let t=ag[e.curves[0].fields[0]];n.title=`${t.name} (${e.fundamental.substring(0,1)})`,n.fundamentalId=t.id,n.frequency=e.fundamental;break}case Z.Expression:n.title=e.expression,o(n,e);break;case Z.Forward:n.title=e.forward,a(e,"offsets"),l(n),o(n,e);break;case Z.Seasonal:n.title=e.seasonal,l(n,e=>e.refSeasonal===n.title),a(e,"offsets"),o(n,e);break;default:throw Error("Unexpected plot type")}return n}(e,i,a,r);return n.paneIndex=t,n.axisIndex=s,n})})}).flat(2).map((e,t)=>(e.index=t,e));if(t)return a.filter(e=>e.main);if(!eF(i))return a;{let e=a.filter(e=>e.type===i);return eF(s)?e.filter(e=>e.index===s):e}}function yD(e,t){"Study"===e.type&&t.curves?.forEach(e=>delete e.varyColorPerBar),function(e){let t=Z[e.type];return t===Z.Forward||t===Z.Seasonal}(e)?eF(t.curves)&&(e.curves=t.curves):function(e,t){if(void 0!==t&&t.length===e.length)for(let i=0;i<e.length;++i){let s=t[i],r=e[i];for(let e of(eY(r,s),["shift","dashStyle","lineSmoothing","lineMarker"])){let t=s[e];eF(t)&&(r[e]=t)}}}(e.curves,t.curves);let i=Z[t.type];eF(t.precision)?e.precision=t.precision:delete e.precision,i===Z.Symbol?e.symbol=t.symbol:i===Z.Study?(function(e,t,i){let s=eK(e),r=eK(t);eY(s,r);let n=Object.keys(r).map(e=>({name:e,value:r[e]}));n.length>0&&(i.inputs=n)}(e.inputs,t.inputs,e),["bands","levels","detachedScale"].forEach(i=>{t[i]&&(e[i]=t[i])})):(i===Z.BalanceSheet||i===Z.IncomeStatement)&&t.frequency?e.fundamental=t.frequency:i===Z.Expression?eF(t.expression)&&(e.expression=t.expression):i===Z.Forward?(eF(t.offsets)&&(e.offsets=t.offsets),eF(t.forward)&&(e.forward=t.forward)):i===Z.Seasonal&&(eF(t.offsets)&&(e.offsets=t.offsets),eF(t.seasonal)&&(e.seasonal=t.seasonal),eF(t.usesInAverage)&&(e.usesInAverage=t.usesInAverage),rs(e))}let yO=e=>`..plots[${e}]`;function yw(e,t){let i=sz(e,t);return 1!==i.length?null:i[0]}let yR=["withMain","overlay","standalone","clone"];function yN(){return{plots:[]}}function yV(e){let t=e.display.chart.newPaneHeight??1;return{axes:[yN()],height:t}}function yH(e){let t=yV(e);return e.panes.push(t),t}function yF(e,t){let i=eH(t.paneIndex)&&t.paneIndex<e.panes.length?e.panes[t.paneIndex]:yH(e),s=i.axes[0];return t.oppositeScale?yK(i,s):s}function yB(e,t,i){let s=null,{mainPane:r,mainAxis:n}=n4(e);switch(t){case"withMain":s=yK(r,n);break;case"overlay":s=n;break;case"standalone":s=yH(e).axes[0];break;case"clone":if("number"==typeof i){let t={main:!1,index:i,type:Z[Z.Study]},r=yI(e,t).find(e=>e.index===t.index);s=sz(e,`..panes[${r.paneIndex}]..axes[${r.axisIndex}]`)[0]}}return s}let yk=[{fields:[ag.Close.id],colors:["#888"],style:"Line",lineWidth:2,varyColorPerBar:!1,visible:!0}];function yW(e){return"Symbol"===e.type}let yU={attributes:["OpenVsClose"],colors:["#b63400","#007f3e","#1664db"],fields:["Open","High","Low","Close","Change"],style:"Candlestick",varyColorPerBar:!0,lineWidth:1},y$=0,yG=["#0d223a","#8abc21","#910000","#2f7ed8","#42ccdc","#bf95df","#860262","#e5daa3","#4682e8","#aaa9c1","#fcccdc","#f66b00","#d875be","#e84b46"],yz="Symbol";function yY(e,t){let i={curves:[{attributes:[],colors:yG.slice(y$,y$+1),fields:e?[ag.Last.id]:[ag.Close.id],style:"Line",dashStyle:"Solid",varyColorPerBar:!1,lineWidth:2,lineMarker:void 0,lineSmoothing:void 0}]};return delete t.oppositeScale,ej(i,t),eF(t.curves)&&eY(i.curves,t.curves),y$=(y$+1)%yG.length,i}let yj='..plots{(.type === "Symbol" || .type === "Expression") && .main !== true}';function yK(e,t){let i=e.axes.find(e=>e!==t);return eF(i)||(i=yN(),e.axes.push(i)),i}let yq=()=>tz.NULL_OBJECT;function yX(e){return sY(e,"..axes.annotations",yq)}function yZ(e){return ac(sY(e,'..plots{.type === "Symbol" && .main !== true}',yq))}let yJ=".display.chart.previous";function yQ(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==Z[t.type])return s;let n=i.panes.indexOf(r.axis.pane),a=n===i.panes.length-1,o=1===i.panes[n].axes.reduce((e,t)=>e+t.plots.length,0);return 0!==n&&s.push("ExistingAbove"),o||s.push("NewAbove"),a||s.push("ExistingBelow"),o||s.push("NewBelow"),s}function y0(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==Z[t.type])return s;let n=r.axis.pane,a=r.axis===n.axes[0],o=n.axes.some(e=>e.plots.some(e=>r!==e&&!e.hasDetachedScale)),l=r.hasDetachedScale;return(a||l)&&s.push("SecondaryAxis"),(!a||l)&&s.push("PrimaryAxis"),o&&s.push("NoAxis"),s}function y1(e,t){let i=e.panes[t],s=i.axes.map(e=>e.plots.reduce((e,t)=>e+ +!!t.detachedScale,0)),r=i.axes.length;return i.axes.forEach((e,t)=>{let n=s[t],a=e.plots.length;if(0!==n&&!(n<a)&&n===a)if(r>1&&1===n){let n=(t+1)%r;if(s[n]<i.axes[n].plots.length){let t=e.plots.find(e=>e.detachedScale);t&&(i.axes[n].plots.push(t),e.plots=e.plots.filter(e=>!e.detachedScale),s[n]++)}}else{let t=e.plots.find(e=>e.detachedScale);t&&(t.detachedScale=!1)}}),e}function y2(e,t){let i=e.allPlots[t],s=e.panes.indexOf(i.axis.pane),r=e.panes[s].axes.indexOf(i.axis),n=e.panes[s].axes[r].plots.findIndex(e=>e===i);return{pane:s,axis:r,plot:n}}let y3={MainPlot:at,Aggregation:{Update:ar,Get:function(e,t,i){return ez(e.data.aggregation)}},Period:{Update:function(e,t,i){let s=eF(t.period),r=eF(t.range),n=eF(t.density);if(+!!s+ +!!r+ +!!n>1)throw Error("Cannot set more than one of: period, range, density.");if(s&&(e.display.period=t.period,nN(e),nH(e)),r)if((!eF(e.display.period)||ao(e.display.period))&&(e.display.xAxis.visibleRange=t.range),nV(e),nH(e),eF(i)){let s=function(e){let t=e.getDataStats();return null===t?null:t.dataRange}(i),r=n_(e.data.aggregation),n=i.data.aggregation,a=r.unit!==n.unit||r.size!==n.size||r.spec!==n.spec||!eF(s)||e.data.checkRange,o=a;if(!a){let{from:e,to:i}=s,{from:r,to:n}=t.range;o=r<e||r>i||n<e||n>i}o&&(e.data.range=t.range),delete e.data.checkRange}else e.data.checkRange=!0;return n&&(e.display.density=t.density,nN(e),nV(e)),(s||r||n)&&(nR(e),i&&(i.forceResetVisibleRange=!0)),e},Delete:function(e,t,i){return eF(t.period)&&t.period&&(delete e.display.period,ai(e),i&&(i.forceResetVisibleRange=!0)),e}},Crosshair:{Update:function(e,t){let[i,s]=eW(t.crosshair),{color:r,dashStyle:n}=t.horizontal||{},{color:a,dashStyle:o}=t.vertical||{},l=(e,t,i)=>{t&&(e.color=t),i&&(e.dashStyle=i)},u=sY(e,".display.xAxis.crosshair",e=>(e.enabled=i,l(e,a,o),e));return u=sY(u,".display.yAxis.crosshair",e=>(e.enabled=s,l(e,r,n),e)),eF(t.haloTracking)&&"boolean"==typeof t.haloTracking&&(u=sY(u,".display.chart",e=>(e.plotHover=t.haloTracking,e))),u},Get:function(e,t,i){let s=t=>sz(e,t)[0],r=s(".display.chart"),n=s(".display.xAxis.crosshair"),a=s(".display.yAxis.crosshair"),o="none";return n.enabled&&a.enabled?o="both":n.enabled?o="vertical":a.enabled&&(o="horizontal"),{crosshair:o,horizontal:{color:a.color,dashStyle:a.dashStyle},vertical:{color:n.color,dashStyle:n.dashStyle},haloTracking:r.plotHover}}},Tooltip:{Update:function(e,t){return sY(e,".display.tooltip",e=>(null!=t.visible&&(e.visible=t.visible),t.mode&&(e.mode=t.mode),null!=t.showMainTitle&&(e.showMainTitle=t.showMainTitle),t.mainTitle&&(e.mainTitle=t.mainTitle),e))},Get:function(e,t,i){let s=sz(e,".display.tooltip")[0];return{visible:s.visible,mode:s.mode,showMainTitle:s.showMainTitle,mainTitle:s.mainTitle}}},Events:function(e,t){let i=ez(t);return Object.keys(t).forEach(e=>{tz.EVENTS.includes(e)||delete i[e];let s=t[e];"boolean"==typeof s?s={show:t[e]}:Object.keys(s).forEach(e=>{tz.EVENT_PROPERTIES.includes(e)||delete s[e]}),i[e]=s}),sY(e,n2,e=>("Symbol"===e.type&&(e.events=e.events||{},Object.keys(i).forEach(t=>{e.events[t]=e.events[t]||{},eY(e.events[t],i[t],!1)})),e))},Scale:{Update:function(e,t){let i=sY(e,"..panes[0]..axes",e=>(eH(t.scale)&&(e.scale=t.scale),e));return i=sY(i,".display.xAxis",e=>(eH(t.marginBars)&&(e.marginBars=t.marginBars),eH(t.nonEodLabelWithDate)&&(e.nonEodLabelWithDate=t.nonEodLabelWithDate),eH(t.ordinalName)&&(e.ordinalName=t.ordinalName),eH(t.preventHorizontalLabelOverlap)&&(e.preventLabelOverlap=t.preventHorizontalLabelOverlap),e)),i=sY(i,".display.yAxis",e=>{(eF(t.minPadding)||eF(t.maxPadding))&&So("The 'minPadding' and 'maxPadding' are deprecated (ignored)","warn");let i=eH(t.preventLabelOverlap)&&!eH(t.preventVerticalLabelOverlap);i&&So("The 'preventLabelOverlap' is deprecated, please use 'preventVerticalLabelOverlap'","warn");let s=i?t.preventLabelOverlap:t.preventVerticalLabelOverlap;return eH(s)&&(e.preventLabelOverlap=s),eF(t.includePercentChangeWithLastValue)&&(e.includePercentChangeWithLastValue=t.includePercentChangeWithLastValue),eF(t.snapAnnotationsToPrices)&&(e.snapAnnotationsToPrices=t.snapAnnotationsToPrices),e}),eF(t.labels)&&Array.isArray(t.labels)&&t.labels.forEach(e=>{let{axis:t,text:s,index:r,paneIndex:n}=e;eF(t,s,r)&&"vertical"===t&&Number.isInteger(r)&&(i=sY(i,`..panes[${n??0}]..axes[${r}]`,e=>eF(e)?(e.label=s,e):tz.NULL_OBJECT))}),eH(t.contractTransition)&&(i=sY(i,".display.xAxis",e=>(eY(e.contractTransition,t.contractTransition),e))),eH(t.cycleTransition)&&(i=sY(i,".display.xAxis",e=>(eY(e.cycleTransition,t.cycleTransition),e))),i},Get:function(e,t,i){let{mainAxis:s}=n4(e),r=sz(e,".display.xAxis")[0],n=sz(e,".display.yAxis")[0];return{scale:s.scale,marginBars:r.marginBars??0,preventLabelOverlap:n.preventLabelOverlap,preventVerticalLabelOverlap:n.preventLabelOverlap,preventHorizontalLabelOverlap:r.preventLabelOverlap,snapAnnotationsToPrices:n.snapAnnotationsToPrices,nonEodLabelWithDate:r.nonEodLabelWithDate??!1,includePercentChangeWithLastValue:n.includePercentChangeWithLastValue??!1,ordinalName:r.ordinalName??"",contractTransition:r.contractTransition,cycleTransition:r.cycleTransition}}},Other:{Update:function(e,t,i){let s=e;if(eF(t.comparisonMode)&&"string"==typeof t.comparisonMode&&e$(q,t.comparisonMode)&&(s=sY(s,`..panes{${n2}}.axes`,e=>(e.comparison=t.comparisonMode,e))),eF(t.gridLines)){let[e,i]=eW(t.gridLines);s=sY(s,".display.xAxis.gridLines",t=>(t.visible=e,t)),s=sY(s,".display.yAxis.gridLines",e=>(e.visible=i,e))}if(eF(t.minorGridLines)){let[,e]=eW(t.minorGridLines);s=sY(s,".display.yAxis.minorGridLines",t=>(t.visible=e,t))}eF(t.newPaneHeight)&&"number"==typeof t.newPaneHeight&&(s=sY(s,".display.chart{.newPaneHeight > 0}",e=>(e.newPaneHeight=t.newPaneHeight,e))),eF(t.showNavigator)&&"boolean"==typeof t.showNavigator&&(s=sY(s,".display.scrollbar",e=>(e.visible=t.showNavigator,e))),eF(t.plotHover)&&"boolean"==typeof t.plotHover&&(s=sY(s,".display.chart",e=>(e.plotHover=t.plotHover,e))),eF(t.showLastValue)&&"string"==typeof t.showLastValue&&(s=sY(s,".display.yAxis",e=>(e.showLastValue=t.showLastValue,e))),eF(t.showMinMaxArc)&&"boolean"==typeof t.showMinMaxArc&&(s=sY(s,".display.chart",e=>(e.showMinMaxArc=t.showMinMaxArc,e))),eF(t.showGoToLatest)&&"boolean"==typeof t.showGoToLatest&&(s=sY(s,".display.chart",e=>(e.showGoToLatest=t.showGoToLatest,e))),eF(t.showLegend)&&"boolean"==typeof t.showLegend&&(s=sY(s,".display.chart",e=>(e.showLegend=t.showLegend,e)),t.showLegend||i.view.removeLegend()),eF(t.allAnnotationsLocked)&&"boolean"==typeof t.allAnnotationsLocked&&(s=sY(s,".display",e=>(e.allAnnotationsLocked=t.allAnnotationsLocked,e))),eF(t.exprSkipLeadingEmpty)&&"boolean"==typeof t.exprSkipLeadingEmpty&&(s=sY(s,".data",e=>(e.exprSkipLeadingEmpty=t.exprSkipLeadingEmpty,e)));let r=[];if(eF(t.extendedHours)&&"boolean"==typeof t.extendedHours&&(s=sY(s,".data",e=>(e.extendedHours=t.extendedHours,e))),eF(t.realTimeCboeBzx)&&"boolean"==typeof t.realTimeCboeBzx&&(s=sY(s,".data",e=>(e.realTimeCboeBzx!==t.realTimeCboeBzx&&r.push("realTimeCboeBzx"),e.realTimeCboeBzx=t.realTimeCboeBzx,e))),eF(t.buildContinuation)&&"boolean"==typeof t.buildContinuation&&(s=sY(s,".data",e=>(e.buildContinuation=t.buildContinuation,e))),r.length>0){let e={chart:i.accessor,hostPropsChanged:r};i.notifyHost(ay.CH_HOST_PROPS_CHANGED,e)}return s},Get:function(e,t,i){let s=sz(e,`..panes{${n2}}.axes.comparison`)[0],r=e.display,n=(e,t)=>eG(e,!1,t,"visible"),a=e=>(function(e,t){let i=e=>eF(e)&&"boolean"==typeof e&&e,s=i(e),r=i(t);return s&&r?"both":s?"vertical":r?"horizontal":"none"})(n(r.xAxis,e),n(r.yAxis,e)),o=eG(r.chart,!0,"showLegend");return{comparison:s,gridLines:a("gridLines"),minorGridLines:a("minorGridLines"),newPaneHeight:r.chart.newPaneHeight,showLastValue:r.yAxis.showLastValue,showLegend:o,showMinMaxArc:r.chart.showMinMaxArc,allAnnotationsLocked:r.allAnnotationsLocked,exprSkipLeadingEmpty:e.data?.exprSkipLeadingEmpty??!1,extendedHours:e.data?.extendedHours??!1,realTimeCboeBzx:e.data?.realTimeCboeBzx??!1,buildContinuation:e.data?.buildContinuation??!1}}},Plot:{Add:function(e,t){switch(t.type){case"Study":return function(e,t){let i=sR(t.studyId);if(!eH(i))return So(`Unknown or unavailable study with the id '${t.studyId}'`,"error"),e;let s=n3(e),r=sF(i);if(s.type===Z[Z.Expression]&&r)return So(`Cannot add study "${i.meta.title}" because it cannot be based on an expression (current main plot); study needs more than "OHLCV" fields to be calculated.`,"error"),e;let n=t.placement||(i.meta.overlay?"overlay":"standalone"),a={type:"Study",study:t.studyId,visible:!0};"overlay"===n&&"VOL"===t.studyId&&(a.detachedScale=!0),void 0!==t.curves&&(a.curves=i.defaults.curves),yD(a,t);let o=yB(e,n,t.cloneIndex);eF(o)&&o.plots.push(a);let l=e.data.aggregation;return as(e,"Tick"===l.unit&&"None"===l.spec)}(e,t);case"IncomeStatement":case"BalanceSheet":return function(e,t){let i=n3(e);if(i.type!==Z[Z.Symbol])throw Error("Cannot add fundamental to the chart whose main plot is not a Symbol plot.");let s=i.symbol,r={curves:[{fields:[t.fundamentalId],lineWidth:2,style:"Line",varyColorPerBar:!1,visible:!0,colors:["#888"]}],fundamental:"Quarter",symbol:s,type:K[ag[t.fundamentalId].category],visible:!0};return yD(r,t),e.panes.push({axes:[{plots:[r]}]}),e}(e,t);case"Expression":let i=n3(e),s={curves:ez(yW(i)?i.curves:yk),expression:"",type:"Expression",visible:!0};return yD(s,t),yF(e,t).plots.push(s),e;case"Symbol":return function(e,t){let i=n3(e),s=Sp().getDefaultMultiFieldCurve(),r=eF(s)?s:yU,n=i.curves?.length,a={curves:n===t.curves.length&&1===n?ez(yW(i)?i.curves:[r]):t.curves,symbol:"",type:"Symbol",visible:!0};return yD(a,t),yF(e,t).plots.push(a),e}(e,t);case"Seasonal":let r={curves:ez(yk),offsets:[0],seasonal:"",type:"Seasonal",visible:!0,main:!1};return yD(r,t),t.paneIndex=t.paneIndex??0,yF(e,t).plots.push(r),e;default:throw Error("Unexpected plot type '${type}', not supported currently")}},Get:yI,Delete:yx,Update:function(e,t,i){if(eF(t.placement)&&!yR.includes(t.placement))throw Error(`Unknown placement: ${t.placement}`);let s=t.main?n2:yO(t.index),r=yw(e,s);if(!eH(r)||eH(t.type)&&r.type!==t.type)return e;if(eH(t.visible))return r.visible=t.visible,e;if(r.main&&function(e){let t=Z[e.type];return t===Z.Symbol||t===Z.Expression}(r)){if(t.curves){let i=e=>e.curves[0].style===$[$.Range],[s,n]=[i(r),i(t)];s&&!n?e=ar(e,{unit:"Day",size:1,spec:"None"}):!s&&n&&(e=ar(e,{unit:"Intraday",size:100,spec:"PerRange"}))}return t.type||(t.type=r.type),eF(t.precision)?r.precision=t.precision:delete r.precision,eF(t.showPrevious)&&(e=sY(e,n2,e=>(e.showPrevious=t.showPrevious,e))),t.curves?nW(e,t):e}{let r=sY(e,s,e=>(yD(e,t),e)),n=yI(r,t,i).find(e=>e.index===t.index);if(!eF(n))return e;if(!(t.type===Z[Z.Study]&&eF(t.placement)&&t.placement!==n.placement))return r;let a=yw(r,s),o=yB(r=yx(r,{id:"Delete",plots:[{index:t.index,type:t.type}]}),t.placement);return null!==o&&o.plots.push(a),r}}},Compare:{Update:function(e,t){let{yes:i,no:s}=eA((eF(t.symbols)&&(So("Use of 'symbols' for Compare API is deprecated. Please see docs for the latest version which supports more plot types","warn"),t.plots=t.symbols.map(e=>(e.type=yz,e))),t.plots?.some(e=>eF(e.leftScale)))?(So("Use of 'leftScale' for Compare API is deprecated. Please use 'oppositeScale'","warn"),t.plots.map(e=>{let t=e.leftScale;return delete e.leftScale,{...e,oppositeScale:t}})):t.plots,e=>e.oppositeScale??!1),{mainPane:r,mainAxis:n}=n4(e);r.alignOnExpirations=t.alignOnExpirations||!1;let a=yK(r,n),o=e=>![yz,"Expression"].includes(e.type);a.plots=a.plots.filter(o);let l=n.plots.filter(e=>e.main||o(e)),u="Tick"===e.data.aggregation.unit;y$=0;let h=eh(yY,u);return n.plots=l.concat(s.map(h)),i.length>0&&(a.plots.push(...i.map(h)),a.comparison=n.comparison,a.scale=n.scale),ac(e)},Get:function(e,t){let i=sz(e,yj),{mainPane:s,mainAxis:r}=n4(e),n=[];for(let e of i){let t=r.plots.includes(e),i=e.type.toLowerCase(),s={curves:ez(e.curves),type:e.type,[i]:e[i],leftScale:!t};n.push(s)}return{plots:n,alignOnExpirations:s.alignOnExpirations}}},Annotation:{Get:function(e,t,i){let s=sz(e,"..panes").map((e,t)=>sz(e,"..axes").map((e,i)=>sz(e,".annotations").map(e=>({...e,paneIndex:t,axisIndex:i})))).flat(2).map((e,t)=>({...e,index:t}));return eF(t.index)&&Number.isFinite(t.index)?t.index<s.length?[s[t.index]]:tz.EMPTY_ARRAY:s}},MovePane:function(e,t){let i=e.panes;return i.splice(t.to,0,i.splice(t.from,1)[0]),e},Template:function(e,t){let i=ez(e);if(t.strip.main){let e=n3(i),t=e.type.toLowerCase();e[t]=tz.PLACEHOLDER_SYMBOL_NAME}return t.strip.annotations&&(i=yX(i)),t.strip.compare&&(i=yZ(i)),i=sY(i,".data",e=>(e.range&&(delete e.range,e.checkRange=!0),e))},Outline:function(e,t,i){let s=yI(e,{main:!0},i)[0],r=s.title===tz.PLACEHOLDER_SYMBOL_NAME,n="Symbol"===s.type,a="Expression"===s.type,o=nK(s.title),l=[];return a&&!nj(o)?l=o.symbols:r||(l=[s.title]),{isTemplate:r,isDefinition:!r,main:{isSymbol:n,isExpression:a,symbols:l,title:r?null:s.title},compare:sz(e,yj).map(e=>e.symbol),annotations:sz(e,"..annotations").map(e=>e.id),studies:yI(e,{type:"Study"},i).map(e=>e.title)}},Theme:{Update:function(e,t){let i=e,{backgroundColor:s,axis:{gridLinesColor:r,textColor:n,crosshairColor:a,gridLinesStyle:o},fontSize:l}=t,{chart:u,xAxis:h,yAxis:c}=l||{};if((s||u)&&(i=sY(e,".display.chart",e=>(s&&(e.backgroundColor=s),u&&(e.fontSize=u),e))),r){let e=e=>(e.color=r,e);i=sY(i,".display.xAxis.gridLines",e),i=sY(i,".display.yAxis.gridLines",e),i=sY(i,".display.yAxis.minorGridLines",e)}if(o){let e=e=>(e.dashStyle=o,e);i=sY(i,".display.xAxis.gridLines",e),i=sY(i,".display.yAxis.gridLines",e),i=sY(i,".display.yAxis.minorGridLines",e)}if(n){let e=e=>(e.textColor=n,e);i=sY(i,".display.xAxis",e),i=sY(i,".display.yAxis",e)}if(a){let e=e=>(e.color=a,e);i=sY(i,".display.xAxis.crosshair",e),i=sY(i,".display.yAxis.crosshair",e)}if(h||c){let e=e=>t=>(t.fontSize=e,t);h&&(i=sY(i,".display.xAxis",e(h))),c&&(i=sY(i,".display.yAxis",e(c)))}return i},Get:function(e,t,i){let{chart:s,xAxis:r,yAxis:n}=e.display||{},{fontSize:a,backgroundColor:o}=s||{},{fontSize:l,gridLines:u,textColor:h,crosshair:c}=r||{},{color:d,dashStyle:p}=u||{},{fontSize:f}=n||{},{color:m}=c||{};return{backgroundColor:o,axis:{gridLinesColor:d,textColor:h,crosshairColor:m,gridLinesStyle:p},fontSize:{chart:a,xAxis:l,yAxis:f}}}},Clear:function(e,t,i){let{paneIndex:s,annotations:r,studies:n}=t||{},a=Number.isInteger(s)?`[${s}]`:"",o=`..panes${a}`,l=e,u=e=>tz.NULL_OBJECT;return!0===r&&(i.allAnnotations.forEach(e=>i.onAnnotationModifiedByTool(e,el.Deleted,!1)),l=sY(l,`${o}..annotations`,u)),!0===n&&(l=sY(l,`${o}..plots{.type=="Study"}`,u)),l=ac(l)},Previous:{Update:function(e,t,i){return sY(e,yJ,e=>(eY(e,t),e))},Get:function(e,t,i){return sz(e,yJ)[0]}},MovePlot:{Update:function(e,t,i){if(!yQ(e,t,i).includes(t.targetPane))return e;let s=y2(i,t.index),r=yw(e,yO(t.index));e.panes[s.pane].axes[s.axis].plots.splice(s.plot,1);let n=s.pane,a=!0;switch(t.targetPane){case"ExistingAbove":n--;break;case"NewAbove":e.panes.splice(n,0,yV(e)),a=!1;break;case"ExistingBelow":n++;break;case"NewBelow":n++,a=!1,e.panes.splice(n,0,yV(e))}a&&i.panes[n].isMain&&r?.type==="Study"&&"VOL"===r.study&&(r.detachedScale=!0);let o=e.panes[n];o.axes.length<2&&o.axes[0].plots.length>0&&o.axes.push(yN());let l=o.axes.findIndex(e=>0===e.plots.length),u=-1===l?o.axes.length-1:l;o.axes[u].plots.push(r);let h=y1(e,s.pane);return ac(h=y1(h,n))},Get:yQ},PinPlot:{Update:function(e,t,i){if(!y0(e,t,i).includes(t.targetAxis))return e;let s=y2(i,t.index),r=e.panes[s.pane],n=yw(e,yO(t.index)),a=-1;switch(t.targetAxis){case"PrimaryAxis":a=0;break;case"SecondaryAxis":a=1;break;case"NoAxis":n.detachedScale=!0}if(-1!==a)if(a!==s.axis)delete n.detachedScale,r.axes.length<2&&a>0&&r.axes.push(yN()),r.axes[a].plots.push(n),r.axes[+(0===a)].plots.splice(s.plot,1);else{let e=r.axes[s.axis].plots[s.plot];delete e.detachedScale}return ac(y1(e,s.pane))},Get:y0}};function y4(e){return"function"==typeof e}function y5(e,t,i){return(function(e,t){let i=y3[e];if(y4(i))return i;{let e=void 0!==t?i[t]:void 0;if(!y4(e)&&!y4(e=i[tz.DEFAULT_ACCESSOR_SUBACTION]))throw Error("Invalid accesor id and/or sub id");return e}})(e.id,e.context.id)(t,e.context,i)}function y6(e){return{id:"MainPlot",context:e}}let y7={keepOldAnnotations:!1,keepNewAnnotations:!0,keepOldCompare:!1,keepNewCompare:!0,keepOldAggregation:!1,keepNewBarWidth:!1},y8=Symbol.for("__ias__");class y9{headless;presenter;_model;constructor(e=!1){this.headless=e,this.presenter=e?null:new yb(this)}get elementId(){return this.headless?null:this.presenter?.elementId??null}get hostElement(){return this.headless?null:this.presenter?.hostElement??null}initialize(e,t=null){if(this.headless)return void console.error("You cannot initialize a headless chart.");if(this.presenter.initialize(e),eH(t)){let e="string"==typeof t;e?So("Initializing the chart with symbol name is deprecated. Please use object form instead (see docs for details). This API will be removed in the future.","warn"):(t.template&&this.load(t.template),delete t.template);let i=e?{symbol:t}:t;this.change(y6(i))}}shutdown(){if(!this.headless){let e=this.presenter?.shutdown();return this.presenter=null,e}return!1}annotate(e,t=null,i=null){if(!this.headless)if(eF(e)){s9(e,t),s8(e,t);let s=gj(e,!1,t,i,this.presenter);s.isDrawingAnnotation&&this.presenter.view.setCursor(ee.Crosshair),this.presenter.activeTool=s,eO()||this.presenter.view.mouseCanvas.focus({preventScroll:!0})}else this.presenter.resetActiveTool()}cancelAnnotation(){this.headless||this.presenter.resetActiveTool()}zoom(e){this.headless||"boolean"!=typeof e||(e?this.annotate("ZoomIn"):this.presenter.defaultTool.resetView(this.presenter))}getDefaultTemplate(){return Sf()}get model(){return(this.headless?this._model:this.presenter.getModel())||Sf()}asTemplate(e={main:!0,annotations:!1,compare:!1}){return this.change({id:tz.ACTION_TEMPLATE,context:{strip:e}})}change(...e){let t={chart:this,actions:e.filter(e=>!e[y8])};t.actions.length>0&&this.presenter?.notifyHost(ay.CH_API_ACTIONS_RECEIVED,t);let i=Sp().config.validateInput,s=e.map(e=>i?ah(e,tz.ACCESSOR_SCHEMA):e);if(1===s.length){let e=s[0];if(e.id===tz.ACTION_TEMPLATE||e.context.id===tz.ACTION_GET)return y5(e,this.model,this.presenter);if(!this.headless&&e.id===tz.ANN_ACTION_ID)return this.presenter.handleAnnotationChange(e.context)}let{yes:r,no:n}=eA(s,e=>e.id===tz.ACTION_PLOT&&eF(e.context)&&e.context.id===tz.ACTION_DELETE),a=ez(this.model),o=ez(this.model);r.length>0&&n.push({id:tz.ACTION_PLOT,context:{id:tz.ACTION_DELETE,plots:r.map(e=>e.context)}}),n.forEach(e=>{if(!eF(o=y5(e,o,this.presenter)))throw Error("Forgot to return model from accessor")}),this.fromModel(o,a)}async fromModel(e,t){let i=ah(e,tz.CHART_SCHEMA);this.headless?this._model=i:await this.presenter?.fromModel(i,t)}async load(e,t){let i={...y7,...t},s=ah(JSON.parse(e),tz.CHART_SCHEMA),r=this.model,n=ez(r);if(eF(r)){if(s=function(e,t,i){let s=n3(t),r=s.type.toLowerCase();if(s[r]===tz.PLACEHOLDER_SYMBOL_NAME){let s=n3(e),{mainAxis:r}=n4(t),n=r.annotations,a=at(t,s);if(i){let{mainAxis:e}=n4(a);e.annotations=n}return a}return t}(r,s,i.keepNewAnnotations),i.keepNewAnnotations||(s=yX(s)),i.keepOldAnnotations&&(s=function(e,t){let{mainAxis:i}=n4(e),{mainAxis:s}=n4(t);yg(i,s);let r=e=>sz(e,'..plots{.type==="Study"}.study')[0],n=sz(e,yy).filter(e=>e!==i),a=sz(t,yy).filter(e=>e!==s);return n.forEach(e=>{let t=r(e),i=a.find(e=>t===r(e));eF(i)&&yg(e,i)}),t}(r,s)),i.keepNewCompare||(s=yZ(s)),i.keepOldCompare&&(s=function(e,t){let i=sz(e,yj),s=sz(t,yj),r=Math.max(0,4-s.length);if(0===r)return t;let n=i.filter(e=>!s.find(t=>e.symbol===t.symbol)).slice(0,r);if(0===n.length)return t;let{mainPane:a,mainAxis:o}=n4(t),{mainAxis:l}=n4(e);return n.forEach(e=>{l.plots.includes(e)?o.plots.push(e):yK(a,o).plots.push(e)}),t}(r,s)),i.keepOldAggregation){let e={id:tz.ACTION_AGGREGATION,context:r.data.aggregation},t=s.display.density;s=y5(e,s,this.presenter),i.keepNewBarWidth&&eF(t)&&(s.display.density=t)}await this.fromModel(s,n),this.clearUndoRedo()}}save(){return JSON.stringify(this.model)}clearUndoRedo(){this.headless||this.presenter.undoRedoManager.clear(!0)}reset(e=!0){let t=Sf();if(this.headless)this._model=t;else if(this.presenter.getModel()){let i=this.presenter.mainPlot,s=null;if(i.isSymbol?s={symbol:i.symbol}:i.isExpression?s={expression:i.expression}:i.isForward?s={forward:i.forward}:i.isSeasonal&&(s={seasonal:i.seasonal}),eF(s)){let i=y5({id:"Theme",context:{id:"Get"}},this.model,this.presenter),r=y5(y6(s),t,this.presenter);e&&(r=y5({id:"Theme",context:i},r,this.presenter)),this.presenter?.fromModel(r)}}this.clearUndoRedo(),this.presenter?.notifyHost(ay.CH_RESET,{elementId:this.elementId})}print(e={}){this.headless||this.presenter.print(e)}getSVGForExport(){So("Obsolete: please use 'exportImage' method instead.","warn")}setTitle(e){this.headless||this.presenter.setTitle(e)}getPaneBounds(e=!0){if(!this.headless)return this.presenter.panes.map(t=>e?t.getBounds():t.getBoundsWithoutScales())}exportData(e={}){return this.headless?null:yv.call(this.presenter,e)}exportImage(e={}){return this.headless?null:yP.call(this.presenter,e)}getDataStats(){return this.presenter.getDataStats()}get canUndo(){return!this.headless&&this.presenter.undoRedoManager.canUndo}get canRedo(){return!this.headless&&this.presenter.undoRedoManager.canRedo}undo(){this.canUndo&&this.presenter.undoRedoManager.undo()}redo(){this.canRedo&&this.presenter.undoRedoManager.redo()}pauseUndoRedo(){this.headless||this.presenter.undoRedoManager.pause()}resumeUndoRedo(e){this.headless||this.presenter.undoRedoManager.resume(e)}priceToY(e,t=0,i=0){let s=this.presenter;if(this.headless||t<0||i<0||t>s.panes.length)return null;let r=s.panes[t];return i>r.axes.length?null:r.axes[i].toY(e)}yToPrices(e){let t=this.presenter;if(this.headless)return null;for(let[i,s]of t.panes.entries()){let t=s.getBounds();if(eF(t)&&e>=t.y&&e<=t.y+t.height)return{pane:i,prices:s.axes.map(t=>t.toPrice(e))}}return{pane:-1,prices:[]}}activate(){this.presenter?.notifyHost(ay.CH_DIDBECOMEACTIVE,{chart:this})}}var cp=N("c15IW");function Se(e,t,i,s,r){void 0===s&&(s=0),void 0===r&&(r=!1);var n=t.schedule(function(){i(),r?e.add(this.schedule(null,s)):this.unsubscribe()},s);if(e.add(n),!r)return n}function St(e,t){return e+Math.random()*(t-e)}let Si=Function(atob("Y29uc29sZS5sb2coIlBsZWFzZSBjb250YWN0IEJhcmNoYXJ0IGluIG9yZGVyIHRvIG9idGFpbiB0aGUgbGljZW5zZSBmb3IgdGhlIGNoYXJ0IGNvbXBvbmVudC4iKTsg")),Ss=Function("f",atob("Zi5yZW1vdmVBbGxDaGFydHMoKTsg")),Sr=Function("m",atob("cmV0dXJuIG0gPT09ICJJbnRlcm5hbEZlZWQiIHx8IG0gPT09ICJXaWRnZXQiIHx8IG0gPT09ICJGcmVlV2lkZ2V0IiB8fCBtID09PSAiRGVtb1NpdGUiOw=="));async function Sn(e,t){if(t&&!Sr(e.mode))return;let i=!1,s=0,r=25;for(;!i&&s<5;){let t=function(){let e=globalThis.parent?.location?.hostname||"";return["","localhost","127.0.0.1"].includes(e)||function(e){let t=e.split(".");if(!t||4!==t.length)return!1;let i=t.map(Number);if(!i.every(e=>Number.isFinite(e)&&e>=0&&e<=255))return!1;let[s,r]=i;return 10===s||172===s&&r>=16&&r<=31||192===s&&168===r}(e)}()||"FreeWidget"===e.mode,n=t?e.apiKey:"";try{let r=t?"":function(){let e=document.domain,t=e.split("."),i="__tld"+new Date().getTime(),s=0;for(;s<t.length-1&&-1===document.cookie.indexOf(`${i}=${i}`);)e=t.slice(-1-++s).join("."),document.cookie=`${i}=${i};domain=${e};`;return document.cookie=`${i}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=${e};`,e}(),a=function(e,t=""){return function(e,t){Object.keys(t).forEach(e=>!eF(t[e])&&delete t[e]);let i=new URLSearchParams(t);return`${e}/?${i.toString()}`}(atob("aHR0cHM6Ly9iYXJjaGFydHdpZGdldHMud2Vic29sLmJhcmNoYXJ0LmNvbQ=="),{module:atob("YXV0aGVudGljYXRlQ2hhcnRSZWZlcmVy"),secret:t,referer:e})}(r,n),o=await fetch(a);if(o.ok){let t=await o.json(),s=t[atob("YXV0aG9yaXplZA==")];e.knownSite=s,s?(e.dataEndpoint=(t[atob("ZGF0YS1lbmRwb2ludA==")]||"").replace(/\/$/g,""),e.allowCredentials=t[atob("YWxsb3dDcmVkZW50aWFscw==")]):(e.dataEndpoint="",e.allowCredentials=!1),i=!0;break}s++}catch{}s++,r*=2,await new Promise(e=>setTimeout(e,r))}i&&e.knownSite||(setTimeout(Si,St(2e3,3e3)),setTimeout(()=>Ss(Sp()),St(4e3,5e3)))}var Sa={};function So(e,t="info",i=""){let s=globalThis.console,r=void 0!==s[t];s[r?t:"log"](e,i)}Sa=JSON.parse('{"major":2,"minor":356,"patch":3,"prerelease":false}');let Sl={environment:"Browser",validateInput:!1,throttleMillis:0,isAlt64:!0,defaultTemplate:`/${tz.CHART_DEFINITION}`,cachedAnnotationsCount:0,showResizeHandles:!1,scrollBehavior:"wheel+shift",bypassSmoothing:!1,showGoToLatest:void 0,tooltipMovement:"Auto",tooltipHeaders:void 0,touchCrosshairTimeoutMillis:void 0,touchCrosshairDelayMillis:void 0,mode:"Unspecified",hostingModel:"Page",overrides:void 0,logo:void 0,logoClickable:void 0,noDataText:void 0,useAllFieldsForComparison:void 0,colorfulAnnotations:!1,baseUrl:{instruments:"/proxies/instruments",futures:"/proxies/futures",timeseries:"/proxies/timeseries",timeseriesNew:"/proxies/new-timeseries",ondemand:"/proxies/ondemand",options:"/proxies/core-api"},credentials:void 0,apiKey:void 0,extensions:void 0,defaultVolumeBarColoring:void 0,defaultMainPlotBarColoring:void 0,async fetch(e,t){let i=this.baseUrl[e],s=`${i}${t}`;if(Sr(this.mode)&&this.knownSite){let{username:r,password:n}=this.credentials||{},a=eF(r,n),o=("timeseries"===e||"timeseriesNew"===e)&&a&&this.allowCredentials?`&username=${r}&password=${n}`:"";s=`https://${this.dataEndpoint}${i}${t}${o}`}let r=await fetch(s);return await r.text()},getCustomEventPopup:e=>null};async function Su(e,t){let i=Sp()?.config;if(!i||!i.fetch)throw Error("You should call initFeed first");let s=t;return"timeseries"===e?s=`/historical${t}`:"options"===e&&(s=`/options-historical${t}`),await i.fetch.call(i,e,s)}let Sh=!1,Sc=null;function Sd(t,i={}){if(Sh)throw Error("You should only call initFeed once during page's lifetime");Sh=!0;let s=Object.assign(Sl);return eY(s,i),eH(s.logo)&&function(e,t){let i=new DOMParser().parseFromString(e,"image/svg+xml"),s=i.querySelector("svg")?.getAttribute("viewBox"),r=i.querySelector("path")?.getAttribute("d");if(eH(s)&&eH(r)){let e=s.split(" ").map(Number);4===e.length&&e.every(Number.isFinite)&&(mZ={path:new Path2D(r),width:e[2],height:e[3],rect:new iw(0,0,0,0),logoClickable:t})}}(s.logo,s.logoClickable??!1),!function(e){var t;let i=e.extensions?.studyProvider;if(!eF(i))return;let s=i.getFields(),r=i.getStudies(),n=ez(s_(tz.CHART_SCHEMA)),a=n.definitions,o=a.studyField.enum,l=a.study.enum;for(let e of s)if(o.includes(e.id))throw Error(`Field with id ${e.id} already exists`);for(let e of r)if(l.includes(e.id))throw Error(`Study with id ${e.id} already exists`);o.push(...s.map(e=>e.id)),l.push(...r.map(e=>e.id)),t=tz.CHART_SCHEMA,au.addSchema(t,n),am(s),sD(r)}(s),(Sc=new t(s)).version=function(){let t=e(Sa),i=t.prerelease?`-${t.prerelease.identifier}.${t.prerelease.ordinal}`:"";return`${t.major}.${t.minor}.${t.patch}${i}`}(),So(`%cBarchart Chart version ${Sc.version}`,"info","font-size: larger"),Sc.cachesData&&(Sc.subject?.subscribe(Sc.onPerformInternalGc.bind(Sc)),e(cp).subscribe(ay.CH_ALL,Sc.onChartChanged.bind(Sc))),Sc}function Sp(){return Sc}function Sf(){return ez(Sp()?.template)}function Sm(){eH(Sc)&&(Sc.shutdown(),Sh=!1,Sc=null)}function Sg(e){let t=new y9(!0);return t.load(e),t.change({id:"Outline",context:{id:"Get"}})}function Sy(e,t,i,s=null){return new Proxy(e,{get:function(e,r,n){return r===t?function(t){let n=s?t[s]:t;return(i.handlesRequestsFor(n)?i:e)[r](t)}:Reflect.get(e,r,n)}})}class SS{config;version;cachesData;timeSeriesSource;metaDataSource;recordSource;charts;pendingRedraw;template;ongoingAnimationCallbackId;_altDataSource;_subject;knowDefaultCurve;defaultOhlcCurve;knowDefaultAggregation;defaultAggregation;knowDefaultPeriod;defaultPeriod;knowDefaultDensity;defaultDensity;id;_mainFeed;constructor(e){this.config=e,this._mainFeed=null,this.timeSeriesSource=this.metaDataSource=this.recordSource=null,this.charts=new Map,this.pendingRedraw=new Set,this.ongoingAnimationCallbackId=null,this.drawCharts=this.drawCharts.bind(this),this.template=null,this.cachesData=!1,this._altDataSource=null,this._subject=null,this.id=e1()}get subject(){return this.isAuxiliary||eH(this._subject)||(this._subject=new of().pipe(function(e){for(var t,i,s=[],r=1;r<arguments.length;r++)s[r-1]=arguments[r];var n=null!=(t=oc(s[s.length-1])?s.pop():void 0)?t:a1,a=null!=(i=s[0])?i:null,o=s[1]||1/0;return og(function(t,i){var s=[],r=!1,l=function(e){var t=e.buffer;e.subs.unsubscribe(),az(s,e),i.next(t),r&&u()},u=function(){if(s){var t=new aY;i.add(t);var r={buffer:[],subs:t};s.push(r),Se(t,n,function(){return l(r)},e)}};null!==a&&a>=0?Se(i,n,u,a,!0):r=!0,u();var h=oy(i,function(e){var t,i,r=s.slice();try{for(var n=aF(r),a=n.next();!a.done;a=n.next()){var u=a.value,h=u.buffer;h.push(e),o<=h.length&&l(u)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}},function(){for(;null==s?void 0:s.length;)i.next(s.shift().buffer);null==h||h.unsubscribe(),i.complete(),i.unsubscribe()},void 0,function(){return s=null});t.subscribe(h)})}(tz.INTERNAL_GC_MILLIS),ov(e=>e.length>0))),this._subject}get isAuxiliary(){return null!==window.opener}setAltDataSource(e){this._altDataSource=e,this.timeSeriesSource=Sy(this.timeSeriesSource,"getTimeSeries",e,"symbol"),this.metaDataSource=Sy(this.metaDataSource,"getMetaData",e),this.recordSource=Sy(this.recordSource,"getRecord",e)}replaceDataSources(e){this._altDataSource=e._altDataSource,this.timeSeriesSource=e.timeSeriesSource,this.metaDataSource=e.metaDataSource,this.recordSource=e.recordSource}getAltDataSource(){return this._altDataSource}getTimeSeriesDataSource(){if(!eH(this.timeSeriesSource))throw Error("No time series source defined");return this.timeSeriesSource}getMetaDataSource(){if(!eH(this.metaDataSource))throw Error("No metadata source defined");return this.metaDataSource}getRecordSource(){if(!eH(this.recordSource))throw Error("No record source defined");return this.recordSource}async ready(){return tU.call(this,async()=>{await Sn(this.config,this instanceof SC||this instanceof SA||this instanceof SL);let e=this.config.defaultTemplate;if(!e)throw Error("Must provide a default template");if("string"==typeof e){let t=await fetch(e);e=await t.json()}return this.template=ah(e,tz.CHART_SCHEMA),!0})}getHeadlessChart(){return new y9(!0)}fixupRenderTo(e){if(!eH(e))return null;if(e instanceof HTMLElement)return e;let t=tR(`#${e}`);if(eH(t))return t;let i=[...this.charts.keys()].find(t=>t.id===e);return eH(i)?i:null}checkChart(e,t){let i=this.fixupRenderTo(e),s=eH(i)&&this.charts.has(i);return eH(t)&&t!==s&&So(`There is ${t?"no":"already a"} chart inside the element ${e}`,"error"),i}addChart(e,t=null){let i=this.checkChart(e,!1),s=new y9;return this.charts.set(i,s),s.initialize(e,t),s}removeChart(e){let t=this.checkChart(e,!0);eH(t)&&(this.charts.get(t).shutdown(),this.charts.delete(t))}removeAllCharts(){for(let e of this.charts.keys())this.removeChart(e)}getChart(e){let t=this.checkChart(e);return eH(t)?this.charts.get(t):null}redraw(e){let t=this.checkChart(e,!0);eH(this.ongoingAnimationCallbackId)||(this.ongoingAnimationCallbackId=requestAnimationFrame(this.drawCharts)),eH(t)&&this.pendingRedraw.add(t)}drawCharts(){this.ongoingAnimationCallbackId=null,this.pendingRedraw.forEach(e=>{let t=this.getChart(e);if(!eH(t?.presenter?.view))return;let i=t.presenter.view;i.isHostElementVisible&&i.draw()}),this.pendingRedraw.clear()}get emptyEntities(){return{metaData:new Set,records:new Set,timeSeries:new Set}}getAllCacheableEntities(e){for(let t of this.charts.values())t.presenter.getCacheableEntities(e)}getCacheableEntities(){let e=this.emptyEntities;return this.getAllCacheableEntities(e),e.timeSeries.forEach(t=>{eH(t)&&(eH(t.record)?e.records.add(t.record):eF(t.records)&&Object.values(t.records).forEach(t=>e.records.add(t)))}),e}clearCaches(){this.evictUnused(this.emptyEntities)}refreshCaches(){this.getTimeSeriesDataSource().refresh(),eN(ay.DF_STREAMRECONNECTED,{})}evictUnused(e){this.getMetaDataSource().evictUnused(e.metaData),this.getRecordSource().evictUnused(e.records),this.getTimeSeriesDataSource().evictUnused(e.timeSeries)}onPerformInternalGc(){let e=this.getCacheableEntities();this.evictUnused(e)}triggerGc(){this.subject?.next()}onChartChanged(e,t){(e===ay.CH_RECREATED||e===ay.CH_SHUTDOWN)&&(this.isAuxiliary?this._mainFeed?.triggerGc():this.triggerGc())}getDefaultMultiFieldCurve(){if(!eH(this.template))return null;if(!this.knowDefaultCurve){let e=n3(this.template);1===e.curves.length&&function(e){switch($[e]){case $.OHLC:case $.HLC:case $.Candlestick:case $.HollowCandles:case $.HeikinAshi:case $.ElderImpulseSystem:case $.Range:case $.MultiColumn:return!0;default:return!1}}(e.curves[0].style)?this.defaultOhlcCurve=ez(e.curves[0]):this.defaultOhlcCurve=null,this.knowDefaultCurve=!0}return this.defaultOhlcCurve}getDefaultAggregation(){return!this.knowDefaultAggregation&&this.template&&(this.defaultAggregation=ez(this.template.data.aggregation),this.knowDefaultAggregation=!0),this.defaultAggregation}getDefaultPeriod(){return!this.knowDefaultPeriod&&this.template&&(this.defaultPeriod=this.template.display?.period,this.knowDefaultPeriod=!0),this.defaultPeriod}getDefaultDensity(){return!this.knowDefaultDensity&&this.template&&(this.defaultDensity=this.template.display?.density,this.knowDefaultDensity=!0),this.defaultDensity}shutdown(){this.isAuxiliary||this.clearCaches(),this.removeAllCharts()}}class SA extends SS{constructor(e){super(e),this.timeSeriesSource=new u8(!1),this.metaDataSource=new io,this.recordSource=new lw}}class ST extends SS{constructor(e){super(e),this.timeSeriesSource=new u8(!0),this.metaDataSource=new io,this.recordSource=new lR}}class Sv extends SS{constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u8(!0),this.metaDataSource=new io,this.recordSource=new lw}}let SP=["drazen.dotlic@barchart.com","princec","b.hebert24@barchart.com"];class SC extends SS{lastStreamingTimestamp=null;_isActivelyStreaming=null;needToResubscribe=!1;_connection;constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u8(!0),this.metaDataSource=new il,this.recordSource=new lN,this.onEvents=this.onEvents.bind(this),this.onTimestamp=this.onTimestamp.bind(this),this.resetStreamingState()}resetStreamingState(){this.lastStreamingTimestamp=null,this._isActivelyStreaming=null,this.needToResubscribe=!1}get connection(){return this._connection}set connection(e){this._connection=e,eH(e)&&this.initializeStreaming()}addChart(e,t=null){return this.needToResubscribe&&this.initializeStreaming(),super.addChart(e,t)}set isActivelyStreaming(e){eH(this._isActivelyStreaming)&&!this._isActivelyStreaming&&e&&(this.debug("need to refresh caches"),this.refreshCaches()),this._isActivelyStreaming=e}get isActivelyStreaming(){return this._isActivelyStreaming}initializeStreaming(){this.resetStreamingState(),this.connection.on("events",this.onEvents),this.connection.on("timestamp",this.onTimestamp)}onTimestamp(e){this.isActivelyStreaming&&(this.lastStreamingTimestamp=e)}debug(e){this.connection&&SP.includes(this.connection._username)&&So(`[chart] Connection ${e}, last timestamp ${this.lastStreamingTimestamp}`)}onEvents({event:e}){e===tz.BC_EVENT_DISCONNECTED||e===tz.BC_EVENT_FEED_PAUSED?(this.debug(e),this.isActivelyStreaming=!1):(e===tz.BC_EVENT_LOGGED_IN||e===tz.BC_EVENT_FEED_RESUMED)&&(this.debug(e),this.isActivelyStreaming=!0)}shutdown(){super.shutdown(),eH(this._connection)&&(this.connection.off("timestamp",this.onTimestamp),this.connection.off("events",this.onEvents),this.resetStreamingState(),this.connection.disconnect(),this.connection=null)}}function Sb(e,t){return new SE(e,t)}class SE{_client;_subscriptions=new Map;_listeners=new Set;constructor(e,t){this._client=e;let i=e=>e.find(e=>this._subscriptions.has(e))??null;t.onConnected=()=>{this._listeners.forEach(e=>e?.onConnected())},t.onMessageWithMetadata=(e,t)=>{let s=e.marketSnapshot;if(eH(s)){let e=i(t);null!==e&&this._listeners.forEach(t=>t.onSnapshot?.(s,e))}let r=e.marketUpdate;if(eH(r)){let e=i(t);null!==e&&this._listeners.forEach(t=>t.onUpdate?.(r,e))}},t.onDisconnected=()=>{this._listeners.forEach(e=>e?.onDisconnected())},t.onHeartBeat=e=>{this._listeners.forEach(t=>t.onHeartBeat?.(e))}}addListener(e){this._listeners.add(e)}removeListener(e){this._listeners.delete(e)}async ready(){return eH(await this._client.connection)}shutdown(){eH(this._client)&&(this._client.dispose(),this._subscriptions.clear(),this._listeners.clear())}subscribeToRealTime(e){if(this._subscriptions.has(e)||!eH(this._client))return;let t=this._client.subscribe(1,5,0,[e],null,null,null);this._subscriptions.set(e,t)}unsubscribeFromRealTime(e){if(!this._subscriptions.has(e)||!eH(this._client))return;let t=this._subscriptions.get(e);this._client.unsubscribe(t),this._subscriptions.delete(e)}async getInstrument(e){let t=await this._client.connection;return await t?.getInstrument(e)??[]}}class SL extends SS{_adapter=null;_auxFeeds=[];constructor(t){super(t),this.cachesData=!0,this.isAuxiliary||(this.timeSeriesSource=new u8(!0),this.metaDataSource=new iu,this.recordSource=new lV,e(cp).subscribe(ay.TS_ALL,this.onTimeSeriesMessage.bind(this)))}onTimeSeriesMessage(e,t){if(!this.isAuxiliary)for(let i of this._auxFeeds)i.notifySeriesMessage(e,t)}notifySeriesMessage(e,t){this.isAuxiliary&&eN(e,t)}getAdapter(){return this.isAuxiliary?this._mainFeed?._adapter:this._adapter}setAdapter(e){if(this.isAuxiliary)throw Error("Cannot set adapter on auxiliary feed");this._adapter=e,this._adapter.addListener(this)}async ready(){if(this.isAuxiliary){let e=await this._mainFeed?.ready()??!1;return e&&(this.template=this._mainFeed.template),e}return await super.ready(),await this._adapter?.ready()??!1}subscribe(e){this.getAdapter()?.subscribeToRealTime(e)}unsubscribe(e){this.getAdapter()?.unsubscribeFromRealTime(e)}shutdown(){super.shutdown(),this.isAuxiliary?(this._mainFeed?.removeAuxFeed(this),this._mainFeed=null):this._adapter?.shutdown()}onConnected(){this.refreshCaches()}onDisconnected(){}onHeartBeat(){}onUpdate(e,t){this.ofRecordSource.onUpdate(e,t)}onSnapshot(e,t){this.ofRecordSource.onSnapshot(e,t)}get ofRecordSource(){return this.recordSource}replaceDataSources(e){super.replaceDataSources(e),this._mainFeed=e}addAuxFeed(e){e.replaceDataSources(this),this._auxFeeds.push(e),this._adapter?.addListener(e)}removeAuxFeed(e){let t=this._auxFeeds.findIndex(t=>t.id==e.id);-1!==t&&(this._auxFeeds.splice(t,1),this._adapter?.removeListener(e),this.triggerGc())}getAllCacheableEntities(e){if(super.getAllCacheableEntities(e),!this.isAuxiliary)for(let t of this._auxFeeds)t.getAllCacheableEntities(e)}}var cp=N("c15IW");let S_=e(cp);export{S_ as PubSub,Sd as initFeed,Sp as getFeed,Sm as shutdownFeed,Sg as getChartOutline,SS as BaseDataFeed,SA as BarchartSiteDataFeed,Sv as MiniWidgetDataFeed,SC as MarketDataFeed,SL as OpenFeed,ST as SnapshotDataFeed,Sb as adaptOpenFeedClient,l6 as OHLCDataPointBuilder,nK as parseExpression,nq as evaluateExpression,nZ as formatExpression,nJ as getExpressionSymbols,n0 as replaceExpressionSymbols,py as ExpressionSeries,pg as makeExpression,uQ as ContainerWrapperTimeSeries,t4 as formatPriceWithDecimals,t5 as getCombinedMetaData,lO as BaseRecordSource,aC as EmptyRecord,ap as Field,ag as Fields,l8 as TimeSeriesContainer,cd as TimeSeriesQuery,nw as Aggregation,tU as asyncReady,tL as hasOpenInterest,l1 as optionValueToDate,e1 as generateUid,s$ as getTaxonomies,sH as doesStudyExist,sN as getAnnotationTraits,gJ as getStudyOptions,cg as StudySeries,cm as makeHelperField,fb as makeStudy,f$ as convertSeries,fG as mapSeries,f_ as movAvg,fM as movExp,fx as movSmo,fI as movWei,fD as movHul,fU as linReg,fN as trueRange,fH as typical,fF as roc,fW as stdDev,ay as Topics,ix as getLightness,en as ChunkPart,J as SeriesKind,z as AggregationSpec,G as AggregationUnit,B as ExpressionRecompute,k as ExpressionNoDataApproach,F as ExpressionMissingBar,Y as FieldValueType,K as FieldCategory,j as FieldFormat,ym as CustomEventPopup,tB as appendDOMElement,tN as styleDOMElement,tV as setAttributesDOMElement};
21
21
  //# sourceMappingURL=barchart.chart.js.map