@barchart/chart-lib 2.354.3 → 2.354.4

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,7 +9,7 @@ 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 hW(e,t,i=null){return hk(e,t,i,"value-title")}function hU(e,t,i){let s="string"==typeof i?` style="color: ${i}"`:"",r=eH(e)?`<span class="field-name">${e}</span>`:"";return`${r}<span${s} class="field-value">${t}</span>`}function h$(e){return`<a class="delete-plot" data-plot-id="${e}" title="Delete plot">${hF("delete")}</a>`}function hG(e,t,i,s,r,n){let a=function(e,t){let i=e.data.aggregation,s=e.display.xAxis,r=s.isOrdinal,n=eV(r)&&r,a=n?s.ordinalName??"Value":"Date";return{date:n?hb(t):hx(i,t),time:i.isEndOfDay||n?null:hI(i,t,!1),isMultiSymbol:function(e){let t=e.mainPlot.symbol;return e.allPlots.some(e=>e.type===X.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:hz(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,X.Expression;let o=r.axis.comparison!==K.None,l=r.axis.comparison===K.Percent,u=(e,s)=>r.customPlotValues&&s!==af.DateTime?[r.getValueAt(s,t,i),0]:hY(e,s,t,o),h=n?`${sN(r.model.study).meta.title} ${r.fullParams}`:r.metaData.name||"",c={isMain:r.main,type:r.type,typeName:X[r.type],name:r.title,description:h,exchange:r.metaData.exchange||"",error:r.errorText,id:r.id,visible:r.visible};eH(r.yearOffset)&&0!=r.yearOffset&&(c.unalignedDate=hx(e.data.aggregation,function(e,t){return te(2,arguments),tr(e,-e9(t))}(t,r.yearOffset)));let d=r.curves[0];s&&r.type===X.Symbol&&a.hasField(af.Symbol)&&(t.valueOf()===tG.ZERO_DATE.valueOf()?c.name=r.timeSeries.container?.getLastDataPoint(af.Symbol):c.name=u(d,af.Symbol)[0]);let p={},f={range:r.axis.yScale.domain(),allDigits:!0};hj(r,e,f);let m=(e,t)=>{let i=(t===af.Change||t===af.PercentChange)&&e>0?"+":"";return l?i+hP(e):i+r.metaData.format(e,t,f)},g=hR(e),y=new Set;return c.values=r.curves.filter(e=>e.visible).map(e=>(!r.main&&r.isSymbol&&g?ud: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!==U.HollowCandles,t),l=m(i,t).trim();if(eH(i)&&t===af.Change){let[t]=u(e,af.PercentChange);eH(t)&&(l+=` (${m(t,af.PercentChange)})`)}return{abbreviation:hK(t),shortName:t.shortName,id:t.id,name:t.name,longName:`${t.shortName} ${n?r.params:""}`.trim(),color:ib(o),val:i,y:a,value:l}}).filter(e=>null!==e)).flat(),c.events=r.findEvents(u(d,af.DateTime)).filter(e=>e.field!==af.Custom),c})(e,t,n,a,i)).filter(e=>null!==e)})),a}function hz(e){let t=e.getBounds();if(!eH(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 hY(e,t,i,s=!1){let r=e.plot,n=r.timeSeries.container,a=r.axis.pane.presenter.timeline,o=e_(a,+i,Number,hD),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 hj(e,t,i){eH(e.precision)?i.overridePrecision=e.precision:e.isStudy&&eH(t.mainPlot?.precision)&&!eH(sN(e.model.study).meta.decimals)&&(i.overridePrecision=t.mainPlot.precision)}function hK(e){return e.id===af.Change.id?"Δ":e.id.substring(0,1)}class hq{plot;id;fields=[];colors=[];style=U.Line;attributes=[];zones;_shift=0;lineWidth=1;lineMarker;lineSmoothing;dashStyle="Solid";varyColorPerBar=!1;visible=!0;_zoneColors;constructor(){this.id=e0(),this.plot=null}get shift(){return this._shift}set shift(e){this._shift=eH(e)?e:0}get isOhlc(){return(this.isOhlcStyle||this.isCandle||this.isHlcStyle||this.isElderImpulseSystemStyle||this.isRangeStyle)&&this.fields.includes(af.Close)}get name(){return this.isOhlc?"":this.fields[0].name}get isHeikinAshiStyle(){return this.style===U.HeikinAshi}get isCandle(){return this.style===U.Candlestick||this.style===U.HollowCandles||this.style===U.HeikinAshi}get isHollowCandles(){return this.style===U.HollowCandles}get isElderImpulseSystemStyle(){return this.style===U.ElderImpulseSystem}get isPercentChangeStyle(){return this.style===U.PercentChange}get isOhlcStyle(){return this.style===U.OHLC}get isHlcStyle(){return this.style===U.HLC}get isRangeStyle(){return this.style===U.Range}get isRenko(){return this.style===U.Renko}get isKagi(){return this.style===U.Kagi}get isPointAndFigure(){return this.style===U.PointAndFigure}get isLineBreak(){return this.style===U.LineBreak}get isBaseline(){return this.style===U.Baseline}get isLineLike(){return[U.Line,U.Area,U.Baseline,U.PercentChange].includes(this.style)}get isColumn(){return this.style===U.Column}get isMultiColumn(){return this.style===U.MultiColumn}get isStackedColumn(){return this.style===U.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=>W[e])),this.colors=e.colors,this.fields=e.fields.map(e=>af[e]),this.style=U[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(K.None),r=e===af.PercentChange,n=e===af.Change,a=r||(!i||s)&&n,o=this.timeSeries.container.hasField(af.Last)?af.Last:af.Close,l=a?o:e,u=(e,t)=>{let i=this.timeSeries.container.getData(e)[t];return e.type!==z.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 eH(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(!eH(t))return null;let i=this.yScale.domain();return eH(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]=hY(this,this.pickMainField(),t);if(eH(s))e.save(),iD(e,this.plot.axis.pane.getBoundsWithoutScales()),e.fillStyle=ib(this.getColor(r)),e.beginPath(),ce(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=eH(this.zones);this.isOhlc?h8.call(this,e,l):this.isRenko||this.isLineBreak?h2.call(this,e,l):this.style===U.Ribbon?this.varyColorPerBar?cl.call(this,e,l):co.call(this,e,l,this.colors[0]):this.style===U.Area?u?hQ.call(this,e,l,hZ,!0):hZ.call(this,e,l,this.colors,!0):this.isColumn||this.isMultiColumn?u?hQ.call(this,e,l,h4,!0):h4.call(this,e,{...l,range:[null,null]}):this.isStackedColumn?h3.call(this,e,l):this.isBaseline?h1.call(this,e,l):this.style===U.Step?u?hQ.call(this,e,l,h6):h6.call(this,e,l,this.colors[0]):this.isKagi?cn.call(this,e,l):this.isPointAndFigure?ca.call(this,e,l):this.style===U.Dots?h5.call(this,e,l):this.style===U.Line||this.isPercentChangeStyle?u?hQ.call(this,e,l,ct):this.varyColorPerBar?cs.call(this,e,l):ct.call(this,e,l):Si(`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(af.Last)?af.Last:this.fields.includes(af.Close)?af.Close:this.fields[0]}get zoneColors(){if(!eH(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?ib(e[0]):e[1]}getComputedColor(e){if(!this.timeSeries.container.hasField(af.BARCOLIX))return null;let t=this.dataAt(af.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(af.Open,e),i=this.dataAt(af.High,e),r=this.dataAt(af.Low,e),n=this.dataAt(af.Close,e),a=this.dataAt(af.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=eH(i),a=eH(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===G.None||(s.open=this.dataAt(af.Open,e),s.close=this.dataAt(af.Close,e)),s.change=this.dataAt(af.Change,e)}let r=function(e,{open:t,close:i,change:s},r){let n=r.length>2&&e!==U.HLC,a=eH(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 U.Candlestick:case U.Renko:case U.LineBreak:case U.Range:case U.HeikinAshi:case U.OHLC:case U.HLC:case U.Column:{if(eH(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(W.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(af.Projection,e)&&(i=iE(.5,!0)(i));break}case U.ElderImpulseSystem:i=this.colors[this.dataAt(af.BREL,e)];break;case U.HollowCandles:{let e=this.colors[r.isUpPrev||r.isSamePrev?1:0];i=t&&(r.isUp||r.isSame)?tG.COLOR_TRANSPARENT:e;break}case U.Line:case U.PercentChange:case U.Ribbon:case U.Kagi:if(eH(n)){i=n;break}i=this.colors[0];break;case U.PointAndFigure:{let t=+!!uz(this.dataAt(af.BARKIND,e));i=this.colors[t];break}default:throw Error(`Unexpected style ${U[this.style]} for a curve with varying colors`)}return eH(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===U.Area?this.pickAreaStroke(s):s.length>0?s[0]:this.colors[0]}if((this.isMultiColumn||this.isStackedColumn)&&eH(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 hX([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 hZ(e,t,i,s=!1){ct.call(this,e,t,this.pickAreaStroke(i)),cu.call(this,e,t,i[0],s)}function hJ(e,t){let i,s,r=eH(e),n=eH(t),a=this.pane.getBounds();if(r)if(n){let r=this.priceToY(e),n=this.priceToY(t);i=(r+n)/2,s=new iO(a.x,n,a.width,r-n)}else i=this.priceToY(e),s=new iO(a.x,a.y,a.width,i-a.y);else i=this.priceToY(t),s=new iO(a.x,i,a.width,a.y+a.height-i);return[i,s]}function hQ(e,t,i,s=!1,r){let n;this.zones.forEach((a,o)=>{let l=a.value,[u,h]=hJ.call(this,n,l);e.save(),iD(e,h),s&&(t.range=[null,u]);let c=this.zoneColors[o];if(a.gradient){let t=((e,t)=>{let i=iE(.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 eH(r)&&(c=r(o,c));i.call(this,e,t,c),e.restore(),n=l})}function h0(e,t){let{x:i,width:s}=this.pane.getBoundsWithoutScales();e.save(),e.lineWidth=1,e.strokeStyle="#888",e.setLineDash(iv("dot")),iY(e,t,i,i+s),e.restore()}function h1(e,t){let[i,s]=t.range,{baseLevel:r}=function(e){let{BaseLevel:t}=ej(e);return{baseLevel:Number.isFinite(t)?e1(0,100,t):50}}(this.plot.inputs),n=(i-s)*r/100+s;this.zones[0].value=this.yToPrice(n),h0.call(this,e,n),hQ.call(this,e,t,hZ,!0,(t,r)=>{let a=iP(r,0),o=e.createLinearGradient(0,1===t?i:s,0,n);return o.addColorStop(0,r),o.addColorStop(1,a),[o,iP(r,1)]})}function h2(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2;hX.call(this,i,s,(i,s)=>{if(!s){let[s,n]=[af.Open,af.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 h3(e,{bar:t,slice:i,start:s}){if(!this.isFirstVisibleOfStyle())return!1;let r=this.view.xAxis.xScale.range()[0]+t.offset,n=iX();n.prolog(e);let a=this.plot.curves.filter(e=>e.isStackedColumn);hX.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(eH(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 h4(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=iX();h.prolog(e),hX.call(this,i,s,(i,s)=>{s||l.forEach((t,s)=>{let r=this.dataAt(t,i);if(eH(r)){eH(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 h5(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||tG.CURVE_STYLE_DOTS_RADIUS),a=2*Math.PI;e.beginPath(),hX.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eH(s)){let t=this.priceToY(s);e.moveTo(r+n,t),e.arc(r,t,n,0,a)}}r+=t.totalWidth}),e.fill()}function h6(e,{bar:t,slice:i,start:s},r){let n=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,a=iX();a.prolog(e),e.strokeStyle=r,e.lineWidth=this.lineWidth,this.dashStyle&&e.setLineDash(iv(this.dashStyle)),e.beginPath();let o=!1,l=null;hX.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eH(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(eH(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 h7=[af.Open,af.High,af.Low,af.Close];function h8(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=iX();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===iL(l).a?u:l,h9(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(),h9(e,u,h,t,a,n,p)}(e,t,this.lineWidth,!this.isHlcStyle)};hX.call(this,i,s,(e,i)=>{if(!i){let i=h7.map(t=>this.dataAt(t,e)),[s,r,d,p]=i;if(eH(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);(!eH(o)||m<o)&&(o=m,u=f),(!eH(l)||g>l)&&(l=g,h=f),c(f)}}n+=t.totalWidth}),r&&(eH(u)&&(u.isMin=!0,c(u)),eH(h)&&(h.isMax=!0,c(h))),a.epilog(e)}function h9(e,t,i,s,r,n,a,o=3){t&&i$(e,{x:s,y:r+o},a,0,Math.PI),i&&i$(e,{x:s,y:n-o},a,0,Math.PI,!0)}function ce(e,t,i,s,r=1){let n=tG.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 ct(e,{bar:t,slice:i,start:s},r=null){let n=r||this.getColor(0),a=eV(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();hX.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eH(t)){let i=this.priceToY(t);a&&ce(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(iv(this.dashStyle)),eV(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):ci(e,l,n)}function ci(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 cs(e,{bar:t,slice:i,start:s}){e.lineWidth=this.lineWidth,e.lineCap="square",this.dashStyle&&e.setLineDash(iv(this.dashStyle));let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,n=null,a=null,o=[];hX.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eH(s)){let t=this.priceToY(s);a=this.getColor(i),n!==a&&(ci(e,o,n),o.length>0&&(o=[o.pop()]),n=a),o.push({x:r,y:t})}}r+=t.totalWidth}),ci(e,o,a)}let cr=[null,null,null,null];function cn(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=iX();n.prolog(e);let a=null,o=null,l=[];hX.call(this,i,s,(i,s)=>{if(!s){let s=e=>h7.map(t=>this.dataAt(t,e)),[u,h,c,d]=s(i),[,p,f]=i<0?cr:s(i-1);if(eH(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=eH(a)&&a!==o,T=u===h?1:2,A=u===h?2:1;l.push({x:m,y:g[0]}),l.push({x:s,y:g[T]}),S&&(l.push({x:s,y:y}),ci(e,l,a),l=[]),S&&l.push({x:s,y:y}),l.push({x:s,y:g[A]}),a=o}}r+=t.totalWidth}),ci(e,l,o),n.epilog(e)}function ca(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=iX();o.prolog(e);let l=this.plot.timeSeries.builder.boxSize,u=l/2;hX.call(this,i,s,(i,s)=>{if(!s){let[t,s]=[af.High,af.Low].map(e=>this.dataAt(e,i)),r=this.colors[0],h=this.colors[1],c=this.dataAt(af.BARKIND,i),d=uz(c),p=c===tG.BARKIND_XO,f=c===tG.BARKIND_OX;if(eH(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)),T=i===t&&p||i===s&&f?!d:d;e.beginPath(),T?(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 co(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(hX.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(n,e),i=this.dataAt(a,e);eH(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 cl(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;hX.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(r,e),i=this.dataAt(n,e);if(eH(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 cu(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,iP(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;hX.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eH(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 ch{symbol;aggregation;range;seriesKind;cacheMe;barsToFetch;offset;chartId;curveStyle;extendedHours;fields=[];alwaysUseBarsToFetch;inputs=[];splits;padded;constructor(e,t,i=Z.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(!eH(this.curveStyle)||!tG.SPECIAL_BUILDER_REQUIRED.includes(this.curveStyle))return"Standard";switch(this.curveStyle){case U.Renko:{let{method:e,period:t,source:i,brickSize:s}=ue(this.inputs),r="ATR"===e?`ATR;${t}`:`${e};${s}`;return`Renko;${r};${i}`}case U.Kagi:{let{method:e,period:t,reversal:i}=uB(this.inputs),s="ATR"===e?`ATR;${t}`:`User;${i}`;return`Kagi;${s}`}case U.PointAndFigure:{let{method:e,period:t,reversal:i,boxSize:s,source:r,oneStepBack:n}=uY(this.inputs),a="ATR"===e?`ATR;${t}`:`User;${s}`;return`PointAndFigure;${a};${r};${i};${n}`}case U.LineBreak:{let{lineBreak:e}=uW(this.inputs);return`LineBreak;${e}`}default:return U[this.curveStyle]}}get needsExtraKey(){return[Z.Options,Z.BalanceSheet,Z.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 ch(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=eG(this.fields),e.splits=this.splits,e.padded=this.padded,e}}var cc=R("c15IW");function cd(e,t){let i=e.query?.duplicate();if(!eH(i)||i.symbol===tG.PLACEHOLDER_SYMBOL_NAME||"Standard"!==i.getBuilderKey())return new uX;{0!==i.barsToFetch&&(i.barsToFetch=i.barsToFetch*tG.SERVER_COMPUTED_STUDY_BAR_MULTIPLIER);let e=t(i);return e.serverComputedSeries=!0,e}}function cp(e){return new ac(e,z.Number,j.Study,e)}class cf{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=e0(),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){eY(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 tG.EMPTY_ARRAY}get hasData(){return null!==this.container}get source(){if(eH(this._source))return this._source;let e=eH(this.inputs)?this.inputs[tG.INPUT_SOURCE]:null;return eH(e)?af[e]:null}set source(e){this._source=e}async ready(){return tW.call(this,async()=>{this.basisChangedToken=this.useNotifications?e(cc).subscribe(am.TS_ALL,this.onBasisChanged.bind(this)):null;let t={tag:e0(),src:null},i=(await Promise.all(this.innerSeries.map(e=>e.ready()))).every(ed);return i&&this.calculate(t),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onBasisChanged(e,t){if(e===am.TS_EVENTSCHANGED||e===am.TS_LOADING||this.innerSeries.some(e=>!e.hasData)||!this.shouldTriggerOurRecalc(t.series)||null===this.base||this===t.series)return;let i={tag:e0(),src:t.series};switch(e){case am.TS_MANYCHANGED:this.calculate(i);break;case am.TS_DATAPOINTCHANGED:case am.TS_DATAPOINTADDED:{let s=this.innerSeries[this.baseIndex].calculable?this.base.size-1:t.index;this.recalculateAt(i,s,e===am.TS_DATAPOINTADDED);break}case am.TS_TIMELINECORRECTION:case am.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.useNotifications&&this.basisChangedToken&&e(cc).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){eR(e,{series:this,index:t})}calculateCommon(e,t=null,i=-1,s=!0){let r=-1===i,n=r?t=>{(eH(e.src)||!eH(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&&(eH(e.src)||this.initialNotification)&&this.notify(t,i)}calculate(e){this.calculateCommon(e,am.TS_MANYCHANGED,-1,!0)}recalculateAt(e,t,i){this.computedServerSide||(!i&&eV(this.container)&&t>this.container.size-1&&(t=this.container.size-1),this.calculateCommon(e,i?am.TS_DATAPOINTADDED:am.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 eH(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(af.DateTime,af.Symbol)}makeContainer(){let e=this.defaultWrappers.concat(this.getWrappers());return new l8(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 cm extends cf{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 cg extends cm{constructor(e,t){super(e,t),this.query=t.query,this.useNotifications=!0}calculateAt(e){let[t,i,s,r]=[af.Open,af.High,af.Low,af.Close].map(t=>this.baseVal(t,e),this),n=null,a=null,o=null,l=null,u=em([t,i,s,r]);if(e<1)n=em([t,r]),a=i,o=s,l=0;else{let[t,r]=[af.Open,af.Close].map(t=>this.container.getData(t)[e-1],this);a=Math.max(i,n=em([t,r]),u),o=Math.min(s,n,u),l=u-r}return{[af.Open.id]:n,[af.High.id]:a,[af.Low.id]:o,[af.Close.id]:u,[af.Change.id]:l}}getWrappers(){return this.wrapBaseFields(af.Volume,af.OpenInterest,af.TradingDay)}}class cy extends cf{constructor(e,t){super(e,t),f$(this)}calculateAt(e){let t=null,i=this.period,[,s]=fG(this);if(this.atLeast(e,i)&&s.hasField(this.source)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=em(r.filter(ep)):eg(r)&&(t=em(r))}return{[this.target.id]:t}}getWrappers(){return this.source===af.Volume?this.wrapBaseFields(af.Volume,af.TradeSize,af.Change,af.Open,af.Close):[]}}class cS extends cf{multiplier;constructor(e,t,i){super(e,t),this.multiplier=i(this.period),f$(this)}calculateAt(e){let t=null,[i,s]=fG(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=em(r.filter(ep)):eg(r)&&(t=em(r))}}}return{[this.target.id]:t}}}class cT extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=af.OpenInterest;return this.base.hasField(i)&&(t=this.baseVal(i,e)),{[i.id]:t}}}let cA={inField:af.MA,outFields:[af.ENVU,af.ENVD],func:fP},cv={inField:af.EMA,outFields:[af.ENVEXPU,af.ENVEXPD],func:fC},cb={inField:af.SMA,outFields:[af.ENVSMOU,af.ENVSMOD],func:fE};class cP extends cf{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 cC extends cf{constructor(e,t){super(e,t);let i=fP(t,this.inputs.Period1,this.source),s=fP(t,this.inputs.Period2,this.source),r=fk(this.target,(e,t,i)=>t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(this.target,1)]}}let cE={fields:[af.MACD,af.MACDS,af.MACDH],avgFunc:fP,mapFunc:fW,histogramVaryColor:!0},c_={fields:[af.MACD,af.MACDS,af.MACDH],avgFunc:fC,mapFunc:fW,histogramVaryColor:!0},cL={fields:[af.MACD,af.CTLTM,af.CTM],avgFunc:fC,mapFunc:fW,histogramVaryColor:!1},cM={fields:[af.MACD,af.CTLTMF,af.CPMI],avgFunc:fC,mapFunc:fW,histogramVaryColor:!1},cx={fields:[af.PPO,af.PPOS,af.PPOH],avgFunc:fC,mapFunc:fU,histogramVaryColor:!0},cI={fields:[af.PVO,af.PVOS,af.PVOH],avgFunc:fC,mapFunc:fU,histogramVaryColor:!1};class cD extends cf{histogramVaryColor=!1;histogramField;get helpers(){return[af.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(eH(i,s)){let r=i<=0;t=r?1:3,e>0&&(r&&i>s&&(t=0),!r&&i<s&&(t=2))}}return{[af.BARCOLIX.id]:t}}}class cO extends cD{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=fk(this.fields[0],t.mapFunc,s,r),a=t.avgFunc(n,e.inputs.Period3,n.target,this.fields[1]),o=fk(this.fields[2],fW,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 cw=cp("_AVG_GAIN"),cR=cp("_AVG_LOSS");class cN extends cf{constructor(e,t,i){super(e,i);let s=fN(i,this.inputs.Period,this.source,af.RSI,t),r=fK(e,"MA","Average")(s,this.inputs.PeriodAvg,af.RSI,af.RSIAVG);this.addInner(s,r)}getWrappers(){return[this.wrapInner(af.RSI,1),this.wrapInner(af.RSIAVG,2)]}}class cV extends cf{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);eg(s)&&(t=this.highest?Math.max(...s):Math.min(...s),this.index&&(t=i-s.indexOf(t)-1))}return{[this.target.id]:t}}}class cH extends cf{toHighest;field;highField;lowField;constructor(e,t,i){super(e,i),this.toHighest=t;let s=eH(e.source),r=e.source,n=s?r:af.Close;this.field=n;let a=s?r:af.High;this.highField=a;let o=s?r:af.Low;this.lowField=o;let l=fM(i,e.inputs.Period,this.highField,af.HH,!0),u=fM(i,e.inputs.Period,this.lowField,af.LL,!1);this.addInner(l,u)}calculateAt(e){let t=null,i=this.baseVal(this.field,e),s=this.innVal(1,af.HH,e),r=this.innVal(2,af.LL,e);if(eg([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 cF=cp("RawPercK");class cB extends cf{kField;constructor(e,t,i,s){super(e,s);let r=fx(s,this.inputs.Period1,t?cF:i,!1),n=fK(e,"MA"),a=n(r,this.inputs.Period2,r.target,t?i:af.PercD),o=t?n(a,this.inputs.Period3,a.target,af.PercD):a;this.kField=i,t?this.addInner(a,o):this.addInner(r,a)}getWrappers(){return[this.wrapInner(this.kField,1),this.wrapInner(af.PercD,2)]}}function ck(e,t,i,s,r){if(null===r)return null;let n=e*r,a=s+n,o=s-n;switch(t){case af.BOLLBU:return a;case af.BOLLBL:return o;case af.BOLLBW:return(a-o)/s*100;default:return null}}class cW extends cf{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=this.inputs.Period,r=this.source,n=fP(i,s,r,af.BOLLBM),a="Modified"===t,o=fH(a?function(e,t,i=af.PCTCHG){return fA("PCTCHG",{source:t,target:i,inputs:fI},e)}(i,r):i,s,a?af.PCTCHG:r),l=this.inputs.Width,u=e=>eh(ck,l,e),h=fk(af.BOLLBU,u(af.BOLLBU),n,o),c=fk(af.BOLLBL,u(af.BOLLBL),n,o),d=fk(af.BOLLBW,u(af.BOLLBW),n,o),p=fK(e,"MA","Average")(d,this.inputs.PeriodAvg,af.BOLLBW,af.BOLLBWA);this.addInner(n,o,h,c,d,p)}calculateAt(e){let t=this.innVal(3,af.BOLLBU,e),i=this.innVal(4,af.BOLLBL,e),s=this.innVal(1,af.BOLLBM,e),r=this.innVal(5,af.BOLLBW,e),n=this.innVal(6,af.BOLLBWA,e),a=null;switch(eH(t,i)&&(a=(this.baseVal(af.Close,e)-i)/(t-i)),this.kind){case"Regular":return{[af.BOLLBU.id]:t,[af.BOLLBL.id]:i,[af.BOLLBM.id]:s};case"Width":return{[af.BOLLW.id]:t-i};case"Percent":return{[af.BOLLP.id]:a};case"BandWidth":return{[af.BOLLBW.id]:r,[af.BOLLBWA.id]:n};case"Modified":{let t=null,i=null,r=null,n=null,a=this.innVal(2,af.MSD,e);if(eH(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{[af.MBBUI.id]:t,[af.MBBLI.id]:r,[af.MBBUO.id]:i,[af.MBBLO.id]:n,[af.MBBM.id]:s}}default:return null}}}let cU=cp("_ABS_CHG"),c$=cp("_MA_ABS_CHG"),cG=cp("_CHG"),cz=cp("_PDM"),cY=cp("_MDM"),cj=cp("_TRS"),cK=cp("_PDS"),cq=cp("_MDS"),cX=cp("_DX");class cZ extends cf{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=fD(s,af.TR);this.addInner(r)}get helpers(){return[cz,cY,cj,cK,cq,cX]}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),eg(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,af.High),c=this.past(e,2,af.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(af.TR)[e];r=this.smooth1(e,cz,cK,t),n=this.smooth1(e,cY,cq,i),s=this.smooth1(e,af.TR,cj,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,cX,this.adxField,l))}return{[cz.id]:t,[cY.id]:i,[cj.id]:s,[cK.id]:r,[cq.id]:n,[af.PDI.id]:a,[af.MDI.id]:o,[cX.id]:l,[this.adxField.id]:u}}getWrappers(){return[this.wrapInner(af.TR,1)]}}class cJ extends cf{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 eH(s)||(s=t.container.hasField(af.Close)?af.Close:t.container.fields[0]),this.innVal(i,s,e)}),i=null;return eg(t)&&(i=this.calculateAtFunc(e,...t)),{[this.target.id]:i}}}function cQ(e,t){let i=this.baseVal(af.High,t),s=this.baseVal(af.Low,t);return{[e.id]:(i+s)/2}}function c0(e,t){let i=this.baseVal(af.High,t),s=this.baseVal(af.Low,t);return{[e.id]:i-s}}class c1 extends cf{calculateAtFunc;constructor(e,t,i){super(e,i),this.calculateAtFunc=t}calculateAt(e){return this.calculateAtFunc.call(this,e)}}let c2=cp("_RANGE"),c3=cp("_MOV_RANGE"),c4={fields:[af.KCUP,af.KCLOW,af.KCMID],midSeries:e=>fw(e,af.TP),midTarget:af.TP,rangeSeries:e=>fB(c2,eu(c0,c2),e),rangeTarget:c2,func:"MA",useMultiplier:!1},c5={fields:[af.KBUP,af.KBLOW,af.KBMID],midSeries:e=>e,midTarget:af.Close,rangeSeries:e=>fD(e,af.TR),rangeTarget:af.TR,func:"EMA",useMultiplier:!0};class c6 extends cf{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=t.midSeries(i),r=fK(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,c3);this.addInner(n,a)}calculateAt(e){let t=this.innVal(1,this.kind.fields[2],e),i=this.innVal(2,c3,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 c7 extends cf{isWidth;constructor(e,t,i){super(e,i),this.isWidth=t;let s=fM(i,this.inputs.Period,af.High,af.DONUP,!0),r=fM(i,this.inputs.Period,af.Low,af.DONLOW,!1);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,af.DONUP,e),i=this.innVal(2,af.DONLOW,e),s=null===t&&null===i;return this.isWidth?{[af.DONW.id]:s?null:t-i}:{[af.DONMID.id]:s?null:(t+i)/2}}getWrappers(){return[this.wrapInner(af.DONUP,1),this.wrapInner(af.DONLOW,2)]}}let c8=cp("_HIND"),c9=cp("_LIND");class de extends cf{justWidth;constructor(e,t,i){super(e,i),this.justWidth=t,this.justWidth=t;let s=this.inputs.Period,r=fM(i,s,af.High,c8,!0,!0),n=fM(i,s,af.Low,c9,!1,!0);this.addInner(r,n)}calculateAt(e){let t=null,i=null,s=null,r=this.innVal(1,c8,e),n=this.innVal(2,c9,e);if(null!==r&&null!==n){let e=this.period;s=(t=(e-r)/e*100)-(i=(e-n)/e*100)}return this.justWidth?{[af.ARNOSC.id]:s}:{[af.ARNUP.id]:t,[af.ARNLOW.id]:i}}}let dt=cp("_MIDPOINT"),di=cp("_MIDPOINT");class ds extends cf{multiplyVol;constructor(e,t,i){super(e,i),this.multiplyVol=t}calculateAt(e){let[t,i,s,r]=[af.High,af.Low,af.Close,af.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 dr=cp("_RANGE"),dn=cp("_MATP");class da extends cf{isBull;constructor(e,t,i){super(e,i),this.isBull=t;let s=fC(i,this.inputs.Period,this.source);this.addInner(s)}calculateAt(e){let t=null,i=this.innVal(1,af.EMA,e);return null!==i&&(t=this.isBull?this.baseVal(af.High,e)-i:this.baseVal(af.Low,e)-i),{[this.isBull?af.ERBLPOW.id:af.ERBRPOW.id]:t}}}let dl=cp("_FORCE"),du=cp("_RANGE"),dh=cp("_EMA1"),dc=cp("_EMA2"),dd=cp("_RATIO"),dp={isNegative:!1,fields:[af.PVI,af.PVIEMA]},df={isNegative:!0,fields:[af.NVI,af.NVIEMA]};class dm extends cf{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=fB(this.kind.fields[0],eu(function(e,t){let i=1e3;if(t>0){let s=[af.Close,af.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=fC(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 dg=cp("_LOGPC"),dy=cp("_SWING_INDEX"),dS=cp("_MIN_CLOSE"),dT=cp("_MAX_CLOSE"),dA=cp("_EP"),dv=cp("_AF"),db=cp("_POS"),dP=cp("_IDY"),dC=[0,0,0,1,1,1,5,5,2,1,1,0,50,50,0,1,1,1,5,0,0],dE=e=>Array(e).fill(0);function d_(e,t,i){let s=e[i-1];return 0===t&&(s=e[i]),t<0&&(s=e[i+1]),s}function dL(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 dM={1:{param:"cot",func:"parseCotLineChart",fields:[af.DateTime,af.COTLCCMSP,af.COTLCLGSP,af.COTLCSMSP]},2:{param:"cotadv",func:"parseDisaggregated",fields:[af.DateTime,af.COTDAGPRO,af.COTDAGSPD,af.COTDAGMNM,af.COTDAGOTH]},3:{param:"cotfin",func:"parseFinancialTradersReport",fields:[af.DateTime,af.COTFTRDLI,af.COTFTRASM,af.COTFTRLVF,af.COTFTROTH]}};class dx extends cf{wrappers;constructor(e,t,i){super(e,cd(i,e=>new dI(t,e))),this.computedServerSide=!0,this.initialNotification=!0,this.wrappers=dM[t].fields.slice(1).map(e=>this.wrapInner(e,0))}getWrappers(){return this.wrappers}}class dI extends uq{kind;constructor(e,t){super(t),this.kind=e}getRetriever(){return new dD(this.kind)}onStreamingUpdates(e){}}class dD extends uy{kind;constructor(e){super(),this.kind=e}addExtraParams(e){e[dM[this.kind].param]="y"}getParser(e){return new dO(e.symbol,e.aggregation,this.kind)}}class dO extends uf{kind;constructor(e,t,i){super(e,t,0),this.kind=i}makeContainer(){return new l6(dM[this.kind].fields)}getParseFunc(){return this.aggregation.isEndOfDay?this[dM[this.kind].func]:null}parseCotLineChart(e){this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.COTLCCMSP,parseInt(e[2])),this.container.addDataPoint(af.COTLCLGSP,parseInt(e[3])),this.container.addDataPoint(af.COTLCSMSP,parseInt(e[4]))}parseDisaggregated(e){this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.COTDAGPRO,parseInt(e[2])),this.container.addDataPoint(af.COTDAGSPD,parseInt(e[3])),this.container.addDataPoint(af.COTDAGMNM,parseInt(e[4])),this.container.addDataPoint(af.COTDAGOTH,parseInt(e[5]))}parseFinancialTradersReport(e){this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.COTFTRDLI,parseInt(e[2])),this.container.addDataPoint(af.COTFTRASM,parseInt(e[3])),this.container.addDataPoint(af.COTFTRLVF,parseInt(e[4])),this.container.addDataPoint(af.COTFTROTH,parseInt(e[5]))}}class dw extends dx{constructor(e,t){super(e,1,t)}}let dR={Day:[af.PreviousHigh,af.PreviousLow,af.PreviousClose],Week:[af.WeekPreviousHigh,af.WeekPreviousLow,af.WeekPreviousClose],Month:[af.MonthPreviousHigh,af.MonthPreviousLow,af.MonthPreviousClose]};class dN extends cf{disabled;record;streamingSubscription;constructor(e,t,i){if(super(e,i),this.disabled=!eH(i.query)||!eH(i.query.symbol),!this.disabled){let e=i.query.symbol;e.endsWith(".BZ")&&(e=e.slice(0,-3)),this.record=Sl().getRecordSource().getRecord(e),this.record.addFields(...t),this.streamingSubscription=this.getStreamingSubscription()}this.initialNotification=!0}getStreamingSubscription(){return Sl().getRecordSource().subject.pipe(ub(e=>{let t=aO(am.RT_QUOTE,this.record.symbol);return e.filter(t)}),oT(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}async ready(){return tW.call(this,async()=>eH(this.record)?await this.record.ready()&&await super.ready():await super.ready(),"asyncReadyWork2")}onStreamingUpdates(e){if(this.record){let e={tag:e0(),src:null};this.calculate(e)}}shutdown(){super.shutdown(),this.disabled||this.streamingSubscription.unsubscribe()}getValues(e){return dR[e].map(e=>this.record.getValue(e))}}class dV extends uq{constructor(e){super(e)}getRetriever(){return tm(this.query.symbol)?new dk:new dH}onStreamingUpdates(e){}}class dH extends uy{addExtraParams(e){e.impl="y"}getParser(e){return new dB(e.symbol,e.aggregation)}}function dF(){return new l6([af.DateTime,af.IMPVOL])}class dB extends uf{constructor(e,t){super(e,t)}makeContainer(){return dF()}getParseFunc(){return this.parseImpVol}parseImpVol(e){this.aggregation.isEndOfDay&&!(e.length<9)&&(this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.IMPVOL,parseFloat(e[8])))}}class dk extends uS{emptyContainer(e,t){return dF()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(af.DateTime,l0(e.date.substring(0,10)));let s=eV(e.impliedVolatility);i.addDataPoint(af.IMPVOL,s?100*e.impliedVolatility:null)}}let dW=cp("_ABS_CHG"),dU=cp("_DS1_EMA1"),d$=cp("_DS1_EMA2"),dG=cp("_DS2_EMA1"),dz=cp("_DS2_EMA2"),dY=cp("_DIFF"),dj=cp("_SUM"),dK=cp("_ABS_CHG"),dq=cp("_HH_LL"),dX=cp("_MULMA"),dZ=cp("_DIFF");class dJ extends cm{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=[af.Open,af.High,af.Low,af.Close],r=s.map(t=>i(t,e));if(eg(r)){let n=s.map(t=>i(t,e-1));if(eg(n)){let[i,s]=eL(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(af.Close)[e-1];t[4]=t[3]-i}}}}return{[af.Open.id]:t[0],[af.High.id]:t[1],[af.Low.id]:t[2],[af.Close.id]:t[3],[af.Change.id]:t[4]}}getWrappers(){return this.wrapBaseFields(af.Volume,af.OpenInterest,af.TradingDay)}}let dQ=cp("_DIST"),d0=cp("_EMA_DIST1"),d1=cp("_EMA_DIST2"),d2=cp("_DIFF"),d3=cp("_EMA_DIFF1"),d4=cp("_EMA_DIFF2"),d5=cp("_CHG"),d6=cp("_M1"),d7=cp("_M2");class d8 extends cf{constructor(e,t){super(e,t);let i=fB(d5,function(e){let t=af.Close,i=e>0?this.baseVal(t,e)-this.baseVal(t,e-1):0;return{[d5.id]:i}},t),s=fk(d6,(e,t)=>t>=0?t:0,i),r=fk(d7,(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,d6,this.innCont(1)),r=this.past(e,i,d7,this.innCont(2));if(eg(s)&&eg(r)){let e=ef(s),i=ef(r);t=this.perc(e-i,e+i)}}return{[af.CHDMOMOSC.id]:t}}}let d9=cp("_MAX"),pe=cp("_MIN"),pt=cp("_ISUPTREND"),pi=cp("_TRENDUP"),ps=cp("_TRENDDOWN"),pr=cp("_TREND"),pn=cp("_CUM_PRICE"),pa=cp("_CUM_VOL"),po=cp("_PER_CHG");class pl extends cf{constructor(e,t){super(e,t);let i=this.source,s=fB(i,eu(fz,i),t);this.addInner(s)}valueAt(e,t){return this.container.getData(e)[t]}dateAt(e){return this.container.getTimeData()[e]}}let pu=cp("_DIFF"),ph=[pu,af.Buy,af.Sell];function pc(e,t,i,s){let r=null,n=null,a=null;eH(i,s)&&(a=i-s);let o=t>0?e.getData(pu)[t-1]:null;return eH(a,o)&&(r=a>0&&o<=0?1:null,n=a<0&&o>=0?-1:null),{[pu.id]:a,[af.Buy.id]:r,[af.Sell.id]:n}}let pd=cp("_PVM"),pp=cp("_NVM");var cc=R("c15IW");function pf(e,t,i){return new pm(e,t,i)}class pm{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=nX(e),this.valueSymbols=this.exprSymbols.filter(e=>void 0===this.innerLookup[e]),this.onlyForTimeline=eA(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!eH(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 tW.call(this,async()=>{this.basisChangedToken=e(cc).subscribe(am.TS_ALL,this.onBasisChanged.bind(this)),this.quoteGroupToken=e(cc).subscribe(am.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(ed);return i&&this.calculate(),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onQuoteGroup(e,t){t.source===this.policy.valueProvider&&this.innerSeries.every(e=>eH(e.container))&&this.calculateCommon(am.TS_MANYCHANGED)}onBasisChanged(e,t){if(this.policy.recompute===F.Manual||e===am.TS_EVENTSCHANGED||e===am.TS_LOADING||!this.shouldTriggerOurRecalc(t.series)||this.innerSeries.some(e=>!eH(e.container)))return;let i=this.policy.mapper(t.series);if(!(e===am.TS_DATAPOINTCHANGED&&this.onlyForTimeline?.includes(i)))switch(this.policy.recompute===F.Everything?am.TS_MANYCHANGED:e){case am.TS_MANYCHANGED:this.calculate();break;case am.TS_DATAPOINTCHANGED:case am.TS_DATAPOINTADDED:this.recalculate(e===am.TS_DATAPOINTADDED);break;case am.TS_TIMELINECORRECTION:case am.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.basisChangedToken&&e(cc).unsubscribe(this.basisChangedToken),this.quoteGroupToken&&(e(cc).unsubscribe(this.quoteGroupToken),this.policy.valueProvider?.shutdown())}calculateAt(e){return e.isNull?null:this.sourceFields.map((t,i)=>t===af.Volume?ef(this.exprSymbols.map(t=>e.inn[t].values[i]??0)):nj(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===af.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];eH(s,r)&&e.setLastDataPoint(af.Change,r-s)}calculateDataPoint(e,t){let i=this.calculateAt(e);if(null===i)return;e.atLeastOne=!0;let[s,r]=eL(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(af.Change,null),this.container.addDataPoint(af.DateTime,new Date(e.timeStamp))),this.calculateLastChange()}notify(e){eR(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,af.DateTime)}timeline(e){return e.container.getData(af.DateTime)}getRangeHelper(){switch(this.policy.missing){case H.UseNext:case H.UseNone:return Math.min;case H.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=>eP(this.timeline(this.innerLookup[e]))))),end:new Date(e(...this.symbols.map(e=>eb(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 H.UseNext:case H.UseNone:return i.findIndex(e=>e.valueOf()>=t.valueOf());case H.UsePrevious:return eC(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=>!eH(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===H.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===B.IgnoreTimelineOnly&&this.onlyForTimeline.includes(e)||this.policy.noDataApproach===B.ModelTransformRequired)}get symbols(){let e=Object.keys(this.innerLookup);return eH(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(;eH(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===H.UsePrevious?this.getInner(e).forEach(t=>{let i=eH(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===H.UseNone&&this.getInner(e).forEach(t=>this.fillPosSymbolAt(t,t.index,e))))}shouldAdd(e){return this.container.getLastDataPoint(af.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||(Si(e,"error"),this.crashedComputationReported=!0)}}calculate(){let{yes:e,no:t}=eS(this.innerSeries,e=>!e.container.isEmpty);if(t.length>0&&this.policy.noDataApproach===B.ModelTransformRequired){let i=e=>e.map(this.policy.mapper),s=this.policy.modelTransform(i(e),i(t));null!==s&&(this.exprModel=s)}this.calculateCommon(am.TS_MANYCHANGED)}recalculate(e){if(this.isExprInError)return;let t=this.getLastPos(),i=this.shouldAdd(t);this.calculateCommon(i?am.TS_DATAPOINTADDED:am.TS_DATAPOINTCHANGED,t,i)}recalculateAt(e,t,i){return this.recalculate(i)}makeContainer(){return new l6([af.DateTime,af.Change].concat(this.targetFields))}getCacheableEntities(e){this.innerSeries.forEach(t=>{t.getCacheableEntities(e)})}}let pg=cp("_AVG"),py=cp("_HAO"),pS=cp("_HAH"),pT=cp("_HAL"),pA=cp("_HAC"),pv=cp("_DELTA"),pb=cp("_DIFF"),pP=cp("_RANK"),pC=cp("_CHG"),pE=cp("_AVG"),p_=cp("_HBRAKE_CHG"),pL=cp("_HEIGHT_DELTA"),pM=cp("_ACTION"),px=cp("_REVERSAL"),pI=e=>[e>0,e<0],pD=[null,null,null];function pO([e,t],i){let s=null;if(i>0){let t=this.baseVal(e,i-1);eH(t)&&(s=this.baseVal(e,i)-t)}return{[t.id]:s}}class pw extends cf{useHandbrake;constructor(e,t){super(e,t);let i=fK(e,"MA","Average"),s=i(t,e1(1,999,this.inputs.FastPeriod),af.Close),r=e1(0,999,this.inputs.SlowPeriod),n=r>0,a=n?i(t,r,af.Close):t,o=fk(pb,n?(e,t,i)=>t-i:(e,t,i)=>i-t,s,a),l=fB(pC,eu(pO,[af.Close,pC]),t),u=fB(pP,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--,{[pP.id]:i}},o),h=e1(0,999,this.inputs.HandbrakePeriod);this.useHandbrake=h>0;let c=i(t,h,af.Close,pE),d=fB(p_,eu(pO,[pE,p_]),c);this.addInner(l,o,u,d)}get helpers(){return[pL,af.BARCOLIX,pM,px]}getStateAt(e){let t=this.innVal(2,pb,e);return eH(t)?pI(t):pD}findPreviousKnownState(e){for(let t=e-1;t>0;t--){let e=this.getStateAt(t);if(e===pD)break;let[i,s]=e;if(i||s)return e}return pD}getBuySell(e){let t=this.getStateAt(e);if(t===pD)return pD;let[i,s]=t,r=this.findPreviousKnownState(e),[n,a]=r;if(!i&&!s)return r===pD?pD:[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]=[px,pM].map(t=>this.getPrev(t,e)),[c,d]=[0,-1].map(t=>this.innVal(4,p_,e+t));if(r=l?10:this.innVal(3,pP,e),this.useHandbrake&&eH(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,pP,e),n=2):(r=i?11:13,n=1))}if(eH(this.innVal(2,pb,e))){let t=this.innVal(1,pC,e),[i,r]=pI(t),n=Math.abs(t);(a&&i||o&&r)&&(s=n),(a&&r||o&&i)&&(s=-n)}return a?t=1:o&&(i=1),{[af.JPIB.id]:t,[af.JPIS.id]:i,[af.BARCOLIX.id]:r,[pL.id]:s,[pM.id]:n,[px.id]:l}}}let pR={FastPeriod:8,SlowPeriod:21,HandbrakePeriod:13,Average:"EMA",Height:"Fixed"},pN=cp("_SMTH_ROC"),pV=cp("_TEN_SMTH_ROC");function pH(e,t,i,s,r){return new cS({source:s,target:r,outFields:[r],aggregation:i,inputs:fS(t)},e,e=>2/e)}let pF=cp("_VOL_AVG"),pB=131,pk=(()=>{let e=eF(.9865008210958766,6),t=eM(52,t=>Math.pow(e,t)),i=52/ef(t);return t.map(e=>e*i)})(),pW=["Renko","Kagi","PointAndFigure","LineBreak"];function pU(e){return e===G.Continue||e===G.Nearest}class p$ extends cf{additionalChunksCounter=1;noData=!1;isPeriodic=!1;constructor(e,t,i){super(e,i,cd(i,e=>{if(!sF(es[Sl()?.config.mode??"Unspecified"]))return i;let t=e.duplicate(),s=e.aggregation;if(s.hasSpec)if(pU(s.spec))return i;else return new uX(t,!0);let r=s.unit===$.Intraday&&s.size<=5,n=function(e,t){switch(e){case $.Intraday:if(t>=240)return 3;if(t>=120)return 2;return 1;case $.Day:default:return 5;case $.Week:return 15;case $.Month:return 60;case $.Quarter:case $.Year:return 240}}(s.unit,s.size);return t.aggregation=r?new nD($.Tick,s.size,G.PerSeconds):new nD($.Intraday,n),t.barsToFetch=Math.min(tG.MAX_INTRADAY_BARS,(r?1:3)*e.barsToFetch),new uq(t)})),this.isPeriodic=t,this.noData=this.innerSeries[1]instanceof uX,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?am.TS_DATAPOINTADDED:am.TS_DATAPOINTCHANGED;this.notify(s,this.innerSeries[0].container.size-1)}getWrappers(){return[this.wrapInner(af.Change,1),this.wrapInner(af.Open,1),this.wrapInner(af.Close,1)]}}let pG=cp("_EMA1"),pz=cp("_EMA2"),pY=cp("_MACD"),pj=cp("_PCTK"),pK=cp("_PCTD"),pq=cp("_PCTK2"),pX=cp("_EMA1"),pZ=cp("_EMA2"),pJ=cp("_CORE");class pQ extends cf{isEmpty=!1;constructor(e,t){if(super(e,t),fJ(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=fB(af.Close,(e,t)=>null,t),i=fB(af.Close,(e,t)=>null,t),s=fB(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,Sl().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 p0=cp("_INN_HL_ACC_IX"),p1=new nD;class p2 extends cf{isWeekly=!1;constructor(e,t){if(super(e,t),t instanceof uX)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===$.Week,this.isWeekly){var i;let e=(i=this.getSeries(t.query,s,p1),new p2({aggregation:p1,source:null,target:p0,outFields:[p0],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*tG.US_TRADING_DAYS_PER_YEAR),Sl().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,af.Close);eg(s)&&(t=ef(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(p0);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(p0)[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 p3=cp("_RSI1"),p4=cp("_RSI1_MOM"),p5=cp("_RSI2"),p6=cp("_RSI2_MA"),p7=cp("_MUL_ATR");class p8 extends cf{constructor(e,t){super(e,cd(t,t=>{let i=Sl().getTimeSeriesDataSource();return t.seriesKind=Z.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 p9=cp("_CORE");class fe extends uq{constructor(e){super(e)}getRetriever(){return tm(this.query.symbol)?new fs:tv(this.query.symbol)?new fr:new fi}}function ft(){return new l6([af.DateTime,af.Delta,af.Gamma,af.Theta,af.Vega])}class fi{supportsChunks;constructor(){this.supportsChunks=!1}async retrieve(e){return ft()}}class fs extends uS{emptyContainer(e,t){return ft()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(af.DateTime,l0(e.date.substring(0,10))),i.addDataPoint(af.Delta,e.delta),i.addDataPoint(af.Gamma,e.gamma),i.addDataPoint(af.Theta,e.theta),i.addDataPoint(af.Vega,e.vega)}}class fr extends uS{emptyContainer(e,t){return ft()}addExtraParams(e){e.fields="delta,gamma,theta,vega"}get iterateForward(){return!0}getPageName(){return"getEquityOptionsHistory"}processRow(e,t,i){i.addDataPoint(af.DateTime,l0(e.date)),i.addDataPoint(af.Delta,e.delta),i.addDataPoint(af.Gamma,e.gamma),i.addDataPoint(af.Theta,e.theta),i.addDataPoint(af.Vega,e.vega)}}let fn=cp("_RSI1"),fa=cp("_RSI2"),fo=cp("_ANCHR"),fl=cp("_HH_N"),fu=cp("_LL_N"),fh=cp("_HH_H1"),fc=cp("_LL_H1"),fd=cp("_HH_H2"),fp=cp("_LL_H2"),ff=cp("_MIDPOINT"),fm=cp("_VALUE");class fg extends cf{constructor(e,t){super(e,t),f$(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]=fG(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{[af.RCI.id]:t}}}let fy={_TR:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=this.baseVal(af.High,e),s=this.baseVal(af.Low,e);if(e>0){let r=this.baseVal(af.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 cf{isModified;constructor(e,t){super(e,t);let i=e.inputs.Modified;this.isModified=i}get helpers(){return[cw,cR]}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(eg(t)){let e=ey(1,r),n=e.map(e=>this.gain(e,t)),a=e.map(e=>this.loss(e,t));i=em(n),s=em(a)}}else{let t=this.container.getData(cw)[e-1],n=this.container.getData(cR)[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{[cw.id]:i,[cR.id]:s,[this.target.id]:t}}},MA:cy,MAEXP:class extends cS{constructor(e,t){super(e,t,e=>2/(e+1))}},MAHLC:class extends cf{constructor(e,t){super(e,t);let i=fP(t,this.inputs.Period1,af.High,af.MAHI),s=fP(t,this.inputs.Period2,af.Low,af.MALO);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.MAHI,1),this.wrapInner(af.MALO,2)]}},VOL:class extends cT{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(af.Volume,af.TradeSize,af.Change,af.Open,af.Close)}},MAENV:class extends cP{constructor(e,t){super(e,cA,t)}},MAENVEXP:class extends cP{constructor(e,t){super(e,cv,t)}},MAENVSMO:class extends cP{constructor(e,t){super(e,cb,t)}},MATRI:class extends cf{constructor(e,t){super(e,t);let i=fP(t,this.inputs.Period,this.source),s=fP(i,this.inputs.Period,af.MA,af.TMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.TMA,2)]}},MAWEI:class extends cf{triangle;constructor(e,t){super(e,t);let i=this.period;this.triangle=i*(i+1)/2,f$(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]=fG(this);if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=this.weightedAverage(r.filter(ep)):eg(r)&&(t=this.weightedAverage(r))}return{[this.target.id]:t}}},MAVOL:cy,MASMO:class extends cS{constructor(e,t){super(e,t,e=>1/e)}},MACD:class extends cO{constructor(e,t){super(e,cE,t)}},MACDEXP:class extends cO{constructor(e,t){super(e,c_,t)}},MACDV:class extends cD{constructor(e,t){super(e,t),this.histogramVaryColor=!0,this.histogramField=af.MACDVH;let i=fK(e,"EMA","Average"),s=i(t,e.inputs.Period1,e.source,void 0),r=i(t,e.inputs.Period2,e.source,void 0),n=fO(t,e.inputs.Period2,e.inputs.Average),a=fk(af.MACDV,(e,t,i,s)=>(t-i)/s*100,s,r,n),o=i(a,e.inputs.Period3,a.target,af.MACDVS),l=fk(af.MACDVH,fW,a,o);this.addInner(a,o,l)}getWrappers(){return[this.wrapInner(af.MACDV,1),this.wrapInner(af.MACDVS,2),this.wrapInner(af.MACDVH,3)]}},GMMA:class extends cf{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(fC(t,n,af.Close,e.outFields[r-1]))}}getWrappers(){return ey(1,12).map(e=>this.wrapInner(this.outFields[e-1],e))}},OSCI:cC,OSCIVOL:cC,RSI:class extends cN{constructor(e,t){super(e,!1,t)}},RSIMOD:class extends cN{constructor(e,t){super(e,!0,t)}},RSISTO:class extends cf{constructor(e,t){super(e,t);let i=fN(t,this.inputs.Period,this.source),s=this.inputs.Range,r=fB(af.STORSI,function(e){let t=null;if(this.atLeast(e,s)){let i=this.past(e,s,af.RSI,this.base),r=eL(i),n=r[0],a=r[1];t=(eb(i)-n)/(a-n)}return{[af.STORSI.id]:t}},i),n=fK(e,"MA","Average")(r,this.inputs.PeriodAvg,af.STORSI,af.STORSIAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(af.STORSI,1),this.wrapInner(af.STORSIAVG,2)]}},RSA:class extends cf{constructor(e,t){super(e,t);let i=fN(t,this.inputs.Period1,this.source,fn),s=fN(t,this.inputs.Period2,this.source,fa),r=fk(af.RSA,(e,t,i)=>(t+i)/2,i,s),n=fK(e,"MA","Average")(r,this.inputs.PeriodAvg,af.RSA,af.RSAAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(af.RSA,1),this.wrapInner(af.RSAAVG,2)]}},WPERCR:class extends cH{constructor(e,t){super(e,!0,t)}},HHLL:class extends cf{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period1,af.High,af.HH,!0),s=fM(t,this.inputs.Period2,af.Low,af.LL,!1);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.HH,1),this.wrapInner(af.LL,2)]}},WGCL:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null,[i,s,r]=[af.Close,af.High,af.Low].map(t=>this.baseVal(t,e));return t=(2*i+s+r)/4,{[this.target.id]:t}}},STOCHF:class extends cB{constructor(e,t){super(e,!1,af.PercK,t)}},STOCHS:class extends cB{constructor(e,t){super(e,!0,af.PercK,t)}},BBANDS:class extends cW{constructor(e,t){super(e,"Regular",t)}},BWIDTH:class extends cW{constructor(e,t){super(e,"Width",t)}},BPERC:class extends cW{constructor(e,t){super(e,"Percent",t)}},OBVOL:class extends cf{constructor(e,t){super(e,t);let i=fB(af.OBVOL,function(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Volume,e),r=this.baseVal(af.Close,e-1),n=this.container.getData(this.target)[e-1];eH(n)||(n=0),t=i>r?n+s:i<r?n-s:n}return{[this.target.id]:t}},t),s=fK(e,"MA","Average")(i,this.period,af.OBVOL,af.OBVOLAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.OBVOL,1),this.wrapInner(af.OBVOLAVG,2)]}},ATR:class extends cf{constructor(e,t){super(e,t);let i=fD(t,af.TR),s=fK(e,"SMA")(i,this.inputs.Period,af.TR,this.target),r=fP(s,this.inputs.Period2,af.ATR,af.ATRMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(this.target,1),this.wrapInner(af.ATRMA,2)]}},ATRP:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period,e.inputs.Smoothing);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(1,af.ATR,e),s=this.baseVal(af.Close,e);return eH(i,s)&&s>0&&(t=i/s*100),{[af.ATRP.id]:t}}},ADX:class extends cZ{constructor(e,t){super(e,!1,af.ADX,t)}},ADXMOD:class extends cZ{constructor(e,t){super(e,!0,af.ADXM,t)}},ADL:class extends cf{constructor(e,t){super(e,t);let i=fV(t);this.addInner(i)}calculateAt(e){let t=null;return t=(e>0?this.container.getData(this.target)[e-1]:0)+this.innVal(1,af.MFMUL,e),{[this.target.id]:t}}},ADWM:class extends cf{constructor(e,t){super(e,t);let i=fB(af.ADWM,function(e){let t=null,i=null;if(e>0){let s=this.baseVal(af.Close,e-1),r=Math.max(s,this.baseVal(af.High,e)),n=Math.min(s,this.baseVal(af.Low,e)),a=this.baseVal(af.Close,e);t=a>s?a-n:a<s?a-r:0,e>1&&(i=(e>2?this.container.getData(af.ADWM)[e-1]:0)+t)}return{[af.ADWM.id]:i}},t),s=fP(i,this.inputs.Period,af.ADWM,af.ADWMMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.ADWM,1),this.wrapInner(af.ADWMMA,2)]}},CHAOSC:class extends cf{constructor(e,t){super(e,t);let i=af.ADL,s=function(e,t=af.ADL){return fA("ADL",fT(t),e)}(t,i),r=fC(s,3,i),n=fC(s,10,i),a=fk(e.target,(e,t,i)=>t-i,r,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},TP:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null;return t=em([af.Close,af.High,af.Low].map(t=>this.baseVal(t,e))),{[this.target.id]:t}}},KELCHN:class extends c6{constructor(e,t){super(e,c4,t)}},KELBND:class extends c6{constructor(e,t){super(e,c5,t)}},DONCHN:class extends c7{constructor(e,t){super(e,!1,t)}},DONWIDTH:class extends c7{constructor(e,t){super(e,!0,t)}},PVT:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Volume,e),r=this.baseVal(af.Close,e-1),n=this.container.getData(this.target)[e-1];eH(n)||(n=0),t=n+(i-r)/r*s}return{[this.target.id]:t}}},ROC:class extends cf{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 cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,this.source),s=fC(i,this.inputs.Period,i.target),r=fC(s,this.inputs.Period,s.target),n=fR(r,1,r.target,this.target);this.addInner(n)}getWrappers(){return[this.wrapInner(this.target,1)]}},PPMOV:class extends cf{constructor(e,t){super(e,t);let i=fw(t,af.PVPT);this.addInner(i)}calculateAt(e){let t=this.innVal(1,af.PVPT,e),i=this.baseVal(af.High,e),s=this.baseVal(af.Low,e);return{[af.PVPTR.id]:t+i-s,[af.PVPTS.id]:t-i+s}}getWrappers(){return[this.wrapInner(af.PVPT,1)]}},PIVPTS:class extends dN{constructor(e,t){super(e,dR[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(eg(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{[af.PPTPIV.id]:t,[af.PPTR1.id]:i,[af.PPTR2.id]:r,[af.PPTR3.id]:a,[af.PPTS1.id]:s,[af.PPTS2.id]:n,[af.PPTS3.id]:o}}},CPP:class extends dN{constructor(e,t){super(e,dR.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(eg(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{[af.CPPH4.id]:o,[af.CPPH3.id]:n,[af.CPPH2.id]:s,[af.CPPH1.id]:t,[af.CPPL1.id]:i,[af.CPPL2.id]:r,[af.CPPL3.id]:a,[af.CPPL4.id]:l}}},ARNUPDW:class extends de{constructor(e,t){super(e,!1,t)}},ARNOSC:class extends de{constructor(e,t){super(e,!0,t)}},TCHN:class extends cf{constructor(e,t){super(e,t);let i="Close"===e.inputs.Range,s=fZ(t);if(!i&&s){let e=fB(af.TCHNUP,(e,t)=>null,t),i=fB(af.TCHNLOW,(e,t)=>null,t);this.addInner(e,i)}else{let s=fM(t,e.inputs.PeriodUpper,i?af.Close:af.High,af.TCHNUP,!0),r=fM(t,e.inputs.PeriodLower,i?af.Close:af.Low,af.TCHNLOW,!1);this.addInner(s,r)}}getWrappers(){return[this.wrapInner(af.TCHNUP,1),this.wrapInner(af.TCHNLOW,2)]}},TCHRE:class extends cf{constructor(e,t){super(e,t);let i=function(e,t,i){let s="TCHN",r=fv(s);return fA(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,af.TCHNUP,e),s=this.innVal(1,af.TCHNLOW,e),r=this.inputs.Adjustment,n=this.inputs.Retracement;return"Long"===n?t=eH(i)?i-r:null:"Short"===n&&(t=eH(s)?s+r:null),{[this.target.id]:t}}},ALLG:class extends cf{constructor(e,t){super(e,t);let i=fB(dt,eu(cQ,dt),t),s=fE(i,e.inputs.Period1,dt,af.ALJAW),r=fE(i,e.inputs.Period2,dt,af.ALTEETH),n=fE(i,e.inputs.Period3,dt,af.ALLIPS);this.addInner(s,r,n)}calculateAt(e){return{[af.ALJAW.id]:this.innVal(1,af.ALJAW,e),[af.ALTEETH.id]:this.innVal(2,af.ALTEETH,e),[af.ALLIPS.id]:this.innVal(3,af.ALLIPS,e)}}},PLTLN:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){return{[af.PLTLN.id]:this.inputs.Position}}},AWEOSC:class extends cf{constructor(e,t){super(e,t);let i=fB(di,eu(cQ,di),t),s=fP(i,this.inputs.Period1,di),r=fP(i,this.inputs.Period2,di),n=fk(af.AWOS,(e,t,i)=>t-i,s,r),a=fP(n,this.inputs.Period3,n.target,af.AWOSMA);this.addInner(n,a)}getWrappers(){return[this.wrapInner(af.AWOS,1),this.wrapInner(af.AWOSMA,2)]}},MFV:class extends ds{constructor(e,t){super(e,!0,t)}},CLV:class extends ds{constructor(e,t){super(e,!1,t)}},CHAMF:class extends cf{constructor(e,t){super(e,t);let i=fV(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,af.Volume),r=this.past(e,i,af.MFMUL,this.innCont(1));if(eg(s)&&eg(r)){let e=ef(s);0!==e&&(t=ef(r)/e)}}return{[this.target.id]:t}}},CHAVOL:class extends cf{constructor(e,t){super(e,t);let i=fR(fC(fB(dr,eu(c0,dr),t),this.inputs.Period1,dr),this.inputs.Period2,af.EMA,this.target);this.addInner(i)}getWrappers(){return[this.wrapInner(this.target,1)]}},DPO:class extends cf{shift;constructor(e,t){super(e,t);let i=this.inputs.Period;this.shift=Math.floor(i/2)+1;let s=fP(t,i,e.source);this.addInner(s)}calculateAt(e){let t=null,i=this.shift,s=this.innVal(1,af.MA,e-i);return null!==s&&(t=this.baseVal(this.source,e)-s),{[this.target.id]:t}}},CCI:class extends cf{constructor(e,t){super(e,t);let i=fw(t),s=fP(i,this.inputs.Period,i.target,dn);this.addInner(i,s)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,af.TP,this.innCont(1));if(eg(s)){let i=this.innVal(2,dn,e);if(null!==i){let r=s.reduce((e,t,s)=>e+Math.abs(i-t),0)/this.period;t=(this.innVal(1,af.TP,e)-i)/(.015*r)}}}return{[this.target.id]:t}}},EMV:class extends cf{constructor(e,t){super(e,t);let i=fB(af.EMV,function(e){let t=null;if(e>0){let[i,s,r]=[af.High,af.Low,af.Volume].map(t=>this.baseVal(t,e)),[n,a]=[af.High,af.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=fP(i,this.inputs.Period,af.EMV,af.EMVMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.EMV,1),this.wrapInner(af.EMVMA,2)]}},ERBRPOW:class extends da{constructor(e,t){super(e,!1,t)}},ERBLPOW:class extends da{constructor(e,t){super(e,!0,t)}},FI:class extends cf{constructor(e,t){super(e,t);let i=fC(fB(dl,function(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Volume,e);t=(i-this.baseVal(af.Close,e-1))*s}return{[this.target.id]:t}},t),this.inputs.Period,dl,af.FI);this.addInner(i)}getWrappers(){return[this.wrapInner(af.FI,1)]}},MI:class extends cf{constructor(e,t){super(e,t);let i=fC(fB(du,eu(c0,du),t),9,du,dh),s=fC(i,9,dh,dc),r=fk(dd,(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,dd,this.innCont(1));eg(i)&&(t=ef(i))}return{[this.target.id]:t}}},MOM:class extends cf{constructor(e,t){super(e,t);let i=this.inputs.Period,s=fB(af.MOM,eh(fY,i,af.Close),t),r=fP(s,this.inputs.Movement,af.MOM,af.MOMMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(af.MOM,1),this.wrapInner(af.MOMMA,2)]}},MFI:class extends cf{constructor(e,t){super(e,t);let i=fw(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period+1;if(this.atLeast(e,i)){let s=this.past(e,i,af.TP,this.innCont(1)),r=this.past(e,i,af.Volume).map(e=>null!=e?e:0);if(eg(s)&&eg(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 cf{constructor(e,t){super(e,t),f$(this);let i=fP(t,this.inputs.Period,this.source);this.addInner(i)}calculateAt(e){let t=null,[i,s]=fG(this),r=this.innVal(i+1,af.MA,e);if(null!==r){let i=this.inputs.Period,n=this.past(e,i,this.source,s);t=Math.sqrt(em(n=n.map(e=>(e-r)*(e-r))))}return{[this.target.id]:t}}getWrappers(){let[e]=fG(this);return[this.wrapInner(af.MA,e+1)]}},NVI:class extends dm{constructor(e,t){super(e,df,t)}},PVI:class extends dm{constructor(e,t){super(e,dp,t)}},PPO:class extends cO{constructor(e,t){super(e,cx,t)}},PVO:class extends cO{constructor(e,t){super(e,cI,t)}},HV:class extends cf{constructor(e,t){super(e,t);let i=Math.sqrt(fX(e.aggregation));if(0===i){let e=fB(this.target,(e,t)=>null,t);this.addInner(e)}else{let s=fH(fB(dg,eu(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{[dg.id]:i}},af.Close),t),e.inputs.Period,dg,af.MSD),r=fB(af.HV,eu(function(e,t){let i=null,s=this.baseVal(af.MSD,t);return null!==s&&(i=100*s*e),{[af.HV.id]:i}},i),s);this.addInner(r)}}getWrappers(){return[this.wrapInner(this.target,1)]}},PERF:class extends cf{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 cf{constructor(e,t){super(e,t)}get helpers(){return[dy]}ohlcVals(e){return[af.Open,af.High,af.Low,af.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(dy)[e-1];eH(s)||(s=0);let[r,n,a,o]=this.ohlcVals(e),[l,u,h,c]=this.ohlcVals(e-1);if(eg([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{[dy.id]:t,[this.target.id]:i}}},WWVOL:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period);this.addInner(i)}get helpers(){return[dT,dS]}calculateAt(e){let t=null,i=null,s=null,r=null,n=this.innVal(1,af.ATR,e);if(null!==n){let a=this.baseVal(af.Close,e),o=this.baseVal(af.Close,e-1),l=this.period;s=Math.max(...this.past(e,l,af.Close)),r=Math.min(...this.past(e,l,af.Close));let u=n*this.inputs.Constant;if(null===this.innVal(1,af.ATR,e-1))a>o?t=s-u:i=r+u;else{let[n,o,l,h]=[af.WWVSARU,af.WWVSARD,dT,dS].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{[dT.id]:s,[dS.id]:r,[af.WWVSARU.id]:t,[af.WWVSARD.id]:i}}},PARTP:class extends cf{constructor(e,t){super(e,t)}get helpers(){return[dA,dv,db]}hlcVals(e){return[af.High,af.Low,af.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,af.PARSARS,af.PARSARL,dA,dv].map(t=>this.me(t,e-1)),S=1===u,T=S?m:d,A=y*Math.abs(g-T),v=u===(n=S?T+A>l?-1:1:T-A<o?1:-1);a=v?S?Math.min(T+A,c,this.baseVal(af.Low,e-2)):Math.max(T-A,h,this.baseVal(af.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{[dA.id]:s,[dv.id]:r,[db.id]:n,[af.PARSARS.id]:i,[af.PARSARL.id]:t}}},MOVLR:class extends cf{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(eg(s)){let e=ef(s),r=(i*ef(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 cf{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);dC.splice(6,3,...i)}get helpers(){return[dP]}prepareComputation(){let e=this.base.getData(af.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=dE(s),this.itr=dE(s),this.haveEnoughData&&dL(e,this.s3,s)}us(e,t){return this.container.getData(e)[t]}recalculateAt(e,t,i){let s=this.base.getData(af.Close),r=s.length;this.haveEnoughData&&dL(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(af.Close,e)){let n=r(af.TRSP1),a=r(af.TRSP2);s=r(dP),null===n&&null===a&&(n=a=this.baseVal(af.Close,this.firstUsefulIndex)),null===s&&(s=1);let o=this.base.getData(af.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=d_(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,dC),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*d_(r,i[s],4)}(o,this.s3,this.itr,e,dC);[n,a]=function(e,t,i,s,r,n,a,o,l,u){let h=d_(r,i[s],10),c=d_(r,i[s],13),d=d_(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),T=[n,a];return(1===o||1!==d||y>n)&&(T[0]=y),(1===o||1!==d||S<a)&&(T[1]=S),T}(o,this.s3,this.itr,e,dC,n,a,s,l,u),this.itr[e]>=0&&(t=n),this.itr[e]<=0&&(i=a)}return{[dP.id]:s,[af.TRSP1.id]:t,[af.TRSP2.id]:i}}},COTLC:dw,COTDAG:class extends dx{constructor(e,t){super(e,2,t)}},COTFTR:class extends dx{constructor(e,t){super(e,3,t)}},IMPVOL:class extends cf{constructor(e,t){super(e,cd(t,e=>new dV(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(af.IMPVOL,0)]}},CTM:class extends cO{constructor(e,t){e.inputs={Period1:5,Period2:21,Period3:34},super(e,cL,t)}},CPMI:class extends cO{constructor(e,t){e.inputs={Period1:3,Period2:5,Period3:8},super(e,cM,t)}},DEMA:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,this.source),s=fC(i,this.inputs.Period,i.target),r=fk(af.DEMA,(e,t,i)=>2*t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(af.DEMA,1)]}},TEMA:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,this.source),s=fC(i,this.inputs.Period,i.target),r=fC(s,this.inputs.Period,s.target),n=fk(af.TEMA,(e,t,i,s)=>3*(t-i)+s,i,s,r);this.addInner(n)}getWrappers(){return[this.wrapInner(af.TEMA,1)]}},TSI:class extends cf{constructor(e,t){super(e,t);let i=(e,t,i,s,r,n)=>{let a=fC(e,t,i,s);return fC(a,r,s,n)},s=fB(dW,eu((e,t)=>({[e.id]:Math.abs(this.baseVal(af.Change,t))}),dW),t),r=i(t,e.inputs.Period1,af.Change,dU,e.inputs.Period2,d$),n=i(s,e.inputs.Period1,dW,dG,e.inputs.Period2,dz),a=fk(af.TSI,(e,t,i)=>100*t/i,r,n),o=fC(a,e.inputs.Period3,af.TSI,af.TSISIG);this.addInner(a,o)}getWrappers(){return[this.wrapInner(af.TSI,1),this.wrapInner(af.TSISIG,2)]}},ADJATR:class extends cf{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)),{[cU.id]:Math.abs(i)}},s=fB(cU,eu(i,this.source),t),r=fK(e,"MA")(s,this.inputs.Period,cU,c$),n=fk(af.ADJATR,(e,t)=>2*t,r);this.addInner(n)}getWrappers(){return[this.wrapInner(af.ADJATR,1)]}},COTR:class extends cf{constructor(e,t){super(e,t);let i=e=>{let t=0;return e>0&&(t=this.baseVal(af.Close,e)-this.baseVal(af.Close,e-1)),{[cG.id]:t}},s=fB(cG,i,t),r=fq[e.inputs.TypeOfATR.toLowerCase()],n=r(t,this.inputs.Period,this.inputs.Smoothing),a=fk(this.target,(e,t,i)=>eH(t)&&eH(i)?t/i:null,s,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCGD:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,af.Close);this.addInner(i)}calculateAt(e){let t=null,i=e>0?this.container.getData(this.target)[e-1]:null,s=this.innVal(1,af.EMA,e);if(eV(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 cf{constructor(e,t){super(e,t);let i=this.inputs.Period,s=Math.floor(i/2),r=this.allowEmptyValues,n=f_(t,s,this.source,af.WMA,r),a=fk(dY,(e,t,i)=>2*t-i,n,f_(t,i,this.source,af.WMA,r)),o=f_(a,Math.floor(Math.sqrt(i)),dY,this.target,r);this.addInner(o)}getWrappers(){return[this.wrapInner(this.target,1)]}},COPP:class extends cf{constructor(e,t){super(e,t);let i=fR(t,this.inputs.PeriodRocLong),s=f_(fk(dj,(e,t,i)=>t+i,i,fR(t,this.inputs.PeriodRocShort)),this.inputs.PeriodWma,dj,this.target);this.addInner(s)}getWrappers(){return[this.wrapInner(this.target,1)]}},REATRS:class extends cf{constructor(e,t){super(e,t);let i="Close"===e.inputs.TurtleChnField,s="Long"===e.inputs.Direction,r=fZ(t);if(!i&&r){let e=fB(this.target,(e,t)=>null,t);this.addInner(e)}else{let e=(e,t)=>({[dK.id]:t>0?e*Math.abs(this.baseVal(af.Change,t)):null}),r=fP(fB(dK,eu(e,this.inputs.FactorATR),t),this.inputs.PeriodAdjATR,dK,af.MA),n=s?af.High:af.Low,a=fM(t,this.inputs.PeriodTurtleChn,i?af.Close:n,dq,s),o=fk(dX,(e,t)=>this.inputs.FactorAdjATR*t,r),l=s?-1:1,u=fk(this.target,(e,t,i)=>t+l*i,a,o);this.addInner(u)}}getWrappers(){return[this.wrapInner(this.target,1)]}},LINRCHN:class extends cf{constructor(e,t){super(e,t);let i=this.inputs.Period,s=fB(af.LINRMID,eu(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(af.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{[af.LINRMID.id]:i}},i),t),r=fH(fk(dZ,(e,t,i)=>t-i,fB(this.source,function(e){return{[this.target.id]:this.baseVal(this.target,e)}},t),s),i,dZ);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,af.LINRMID,e),i=eb(this.innCont(2).getData(af.MSD)),s=null,r=null;if(eH(t,i)){let e=this.inputs.Width;s=t+e*i,r=t-e*i}return{[af.LINRUP.id]:s,[af.LINRLOW.id]:r}}getWrappers(){return[this.wrapInner(af.LINRMID,1)]}},CSHO:class extends cf{computeDone;constructor(e,t){super(e,t,cd(t,e=>{var t,i;let s=eG(e);return s.symbol=tg(t=e.symbol)?`${tg(i=t)?tc(i).root:null}Y00`:null,eH(s.symbol)?new uq(s):new uX(s,!0)})),this.computedServerSide=!0,this.initialNotification=!0,this.computeDone=!1}alignCashTimelineWithUnderlying(){let e=this.innCont(0);if(!eH(e)||0===e.size)return;let t=this.innCont(1),i=e.getTimeData(),s=t.getTimeData(),r=t.getData(af.Close),n=Array(i.length).fill(null);if(!(this.innerSeries[1]instanceof uX)){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(am.TS_MANYCHANGED,-1))}},CSHB:class extends cf{constructor(e,t){super(e,t,function(e,t=af.CSHO){return fA("CSHO",fT(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)=>eH(this.innCont(t))?this.innVal(t,i,e):null,i=t(0,af.Close),s=t(1,af.CSHO);return{[this.target.id]:eH(s)&&eH(i)?s-i:null}}},CTPI:class extends cB{constructor(e,t){e.inputs={Period1:5,Period2:3,Period3:3},super(e,!0,af.CTPI,t)}},PCTCHG:class extends cf{constructor(e,t){super(e,t),f$(this)}calculateAt(e){let t=null,[i]=fG(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 cT{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(af.TradeSize,af.Change)}},STOMOMIX:class extends cf{constructor(e,t){super(e,t);let i=fM(t,e.inputs.Period1,af.High,af.HH,!0),s=fM(t,e.inputs.Period1,af.Low,af.LL,!1),r=fC(fk(dQ,(e,t,i)=>this.baseVal(af.Close,e)-(t+i)/2,i,s),e.inputs.Period2,dQ,d0),n=fC(r,e.inputs.Period2,d0,d1),a=fC(fk(d2,(e,t,i)=>t-i,i,s),e.inputs.Period2,d2,d3),o=fC(a,e.inputs.Period2,d3,d4),l=fk(af.STOMOMIX,(e,t,i)=>100*t/i,n,o);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},CHDMOMOSC:class extends cf{constructor(e,t){super(e,t);let i=new d8(e,t),s=fK(e,"MA","Average")(i,this.inputs.PeriodAvg,af.CHDMOMOSC,af.CHDMOMOSCAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.CHDMOMOSC,1),this.wrapInner(af.CHDMOMOSCAVG,2)]}},VSTOP:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period);this.addInner(i)}get helpers(){return[d9,pe,pt]}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=1,l=this.baseVal(af.Close,e),u=e=>eH(e)?e:0,h=(e,t)=>this.container.getData(e)[t];e>0&&(s=Math.max(u(h(d9,e-1)),l),n=Math.min(u(h(pe,e-1)),l),o=h(pt,e-1));let c=this.inputs.Multiplier,d=this.innVal(1,af.ATR,e);if(eH(d)){let u=1===o,p=u?s-c*d:n+c*d,f=h(u?af.VSTOPUP:af.VSTOPLOW,e-1);eH(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{[af.VSTOPUP.id]:1===a?t:null,[af.VSTOPLOW.id]:1===a?null:t,[d9.id]:i,[pe.id]:r,[pt.id]:a}}},SUPTR:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period);this.addInner(i)}get helpers(){return[pi,ps,pr,af.BARCOLIX]}calculateAt(e){let t=0,i=0,s=0,r=null,n=0,a=this.innVal(1,af.ATR,e);if(eH(a)){let[o,l,u]=[af.Close,af.High,af.Low].map(t=>this.baseVal(t,e)),h=(l+u)/2,c=this.baseVal(af.Close,e-1),d=this.inputs.Multiplier,p=h-d*a,f=h+d*a,[m,g,y]=[pi,ps,pr].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:eH(y)?y:1);r=S?t:i,n=+!!S}return{[pi.id]:t,[ps.id]:i,[pr.id]:s,[af.SUPTR.id]:r,[af.BARCOLIX.id]:n}}},ICHCLD:class extends cf{constructor(e,t){super(e,t);let i=(e,t,i)=>fk(i,(e,t,i)=>(t+i)/2,e,t),s=(e,s)=>i(fM(t,e,af.Low,af.LL,!1),fM(t,e,af.High,af.HH,!0),s),r=s(e.inputs.PeriodConversionLine,af.CONVLN),n=s(e.inputs.PeriodBaseLine,af.BASELN),a=i(r,n,af.LEADSP1),o=s(e.inputs.PeriodLaggingSpan2,af.LEADSP2);this.addInner(r,n,a,o)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=+(this.innVal(3,af.LEADSP1,e)>this.innVal(4,af.LEADSP2,e));return{[af.LAGGSP.id]:this.baseVal(af.Close,e),[af.BARCOLIX.id]:t}}getWrappers(){return[this.wrapInner(af.CONVLN,1),this.wrapInner(af.BASELN,2),this.wrapInner(af.LEADSP1,3),this.wrapInner(af.LEADSP2,4)]}},VWAP:class extends pl{constructor(e,t){super(e,t)}get helpers(){return[pn,pa,po]}isSame(e,t){switch(this.inputs.AnchorPeriod){case"Session":default:return ng(e,t);case"Week":return nb(e,t);case"Month":return ny(e,t);case"Quarter":return nT(e,t);case"Year":return nP(e,t);case"Decade":return lJ(10,e)===lJ(10,t);case"Century":return lJ(100,e)===lJ(10,t)}}findPrevPeriodChange(e){for(let t=e;t>0;t--)if(1===this.valueAt(po,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):tG.ZERO_DATE,l=this.dateAt(e),u=a&&this.isSame(o,l),h=u?this.valueAt(pn,e-1):0,c=u?this.valueAt(pa,e-1):0,d=this.innVal(0,af.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(af.VWAP).slice(a,e);o.push(t);let l=em(o),u=Math.sqrt(em(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{[pn.id]:p,[pa.id]:f,[po.id]:+!u,[af.VWAP.id]:t,[af.VWAPSD1U.id]:i,[af.VWAPSD1L.id]:s,[af.VWAPSD2U.id]:r,[af.VWAPSD2L.id]:n}}},MACROSS:class extends cf{constructor(e,t){super(e,t);let i=fK(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,af.MAS),r=i(t,e.inputs.Period2,this.source,af.MAL);this.addInner(s,r)}get helpers(){return ph}calculateAt(e){let t=this.innVal(1,af.MAS,e),i=this.innVal(2,af.MAL,e);return pc(this.container,e,t,i)}getWrappers(){return[this.wrapInner(af.MAS,1),this.wrapInner(af.MAL,2)]}},PACROSS:class extends cf{_maIndex;_maTarget;constructor(e,t){super(e,t),f$(this);let i=fK(e,"MA","Average")(t,e.inputs.Period,this.source);this.addInner(i);let[s]=fG(this);this._maIndex=s+1,this._maTarget=i.target}get helpers(){return ph}calculateAt(e){let t=this.innVal(this._maIndex,this._maTarget,e),[,i]=fG(this),s=i.getData(this.source)[e],r=pc(this.container,e,s,t);return r[this.target.id]=t,r}},VOIN:class extends cf{constructor(e,t){super(e,t);let i=fB(pd,function(e){return{[pd.id]:e>0?Math.abs(this.baseVal(af.High,e)-this.baseVal(af.Low,e-1)):null}},t),s=fB(pp,function(e){return{[pp.id]:e>0?Math.abs(this.baseVal(af.Low,e)-this.baseVal(af.High,e-1)):null}},t),r=fD(t,af.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,pd,this.innCont(1)),n=this.past(e,s,pp,this.innCont(2)),a=this.past(e,s,af.TR,this.innCont(3));if(eg(r)&&eg(n)&&eg(a)){let e=ef(r),s=ef(n),o=ef(a);t=e/o,i=s/o}}return{[af.PLVI.id]:t,[af.MNVI.id]:i}}},DIFA:class extends cf{isPercent;constructor(e,t){super(e,t);let i=fK(e,"MA","Average")(t,this.period,this.source,pg);this.isPercent="Percentage"===e.inputs.Distance,this.addInner(i)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=null,i=null,s=this.innVal(1,pg,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,[af.BARCOLIX.id]:i}}},DOSC:class extends cf{constructor(e,t){super(e,t);let i=fC(fN(t,this.inputs.PeriodRsi,this.source,af.RSI),this.inputs.PeriodEma1,af.RSI,af.EMA),s=fC(i,this.inputs.PeriodEma2,af.EMA,af.EMA),r=fP(s,this.inputs.PeriodMa,af.EMA,af.MA),n=fk(af.DOSCH,(e,t,i)=>t-i,s,r),a=fP(n,this.inputs.PeriodSig,af.DOSCH,af.DOSCS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(af.DOSCH,1),this.wrapInner(af.DOSCS,2)]}},BBANDW:class extends cW{constructor(e,t){super(e,"BandWidth",t)}},MARIB:class extends cf{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=fP(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 cf{constructor(e,t){super(e,t);let i=fK(e,"EMA","Smoothing1"),s=e.inputs.Period1,r=i(t,s,af.Open),n=i(t,s,af.High),a=i(t,s,af.Low),o=i(t,s,af.Close),l=fk(pA,(e,t,i,s,r)=>(t+i+s+r)/4,r,n,a,o),u=fk(py,function(e,t,i,s){let r=null;if(e>0){let s=this.container.getData(py)[e-1],n=this.innVal(2,pA,e-1);eH(s,n)?r=(s+n)/2:eH(t,i)&&(r=(t+i)/2)}return r},r,o,l),h=fk(pS,(e,t,i,s)=>eH(t,i,s)?Math.max(t,Math.max(i,s)):null,n,u,l),c=fk(pT,(e,t,i,s)=>eH(t,i,s)?Math.min(t,Math.min(i,s)):null,a,u,l),d=fK(e,"EMA","Smoothing2"),p=e.inputs.Period2,f=d(u,p,py,af.Open),m=d(h,p,pS,af.High),g=d(c,p,pT,af.Low),y=d(l,p,pA,af.Close),S=fB(af.Change,function(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Close,e-1);eH(i,s)?t=i-s:eH(i)&&!eH(s)&&(t=0)}return{[af.Change.id]:t}},y);this.addInner(f,m,g,y,S)}getWrappers(){return[this.wrapInner(af.Open,1),this.wrapInner(af.High,2),this.wrapInner(af.Low,3),this.wrapInner(af.Close,4),this.wrapInner(af.Change,5)]}},TTMSQZ:class extends cf{constructor(e,t){super(e,t);let i=e.inputs,s=fC(t,i.PeriodEmaKeltner,af.Close),r=fO(t,i.PeriodAtrKeltner);function n(e,t,i,s){return eH(i,s)?i+e*s:null}let a=i.MultiplierKeltner,o=fk(af.KCUP,eu(n,a),s,r),l=fk(af.KCLOW,eu(n,-a),s,r),u=function(e,t,i,s=af.Close){let r="BBANDS",n=fv(r);return fA(r,{source:s,inputs:{[tG.INPUT_PERIOD]:t,[tG.INPUT_WIDTH]:i},outFields:n},e)}(t,i.PeriodBollinger,i.WidthBollinger),h=function(e,t){let i="DONCHN",s=fv(i);return fA(i,{inputs:fS(t),outFields:s,source:null},e)}(t,i.PeriodMomentum),c=fP(t,i.PeriodMomentum,af.Close),d=fF(fk(pv,function(e,t,i,s){let r=null,n=this.innVal(1,af.DONMID,e);return eH(n,s)&&(r=t-(n+s)/2),r},t,h,c),i.PeriodMomentum,pv,af.TTMSQZOSC);this.addInner(o,l,u,d)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=null,i=null,s=-1,r=this.innVal(1,af.KCUP,e),n=this.innVal(2,af.KCLOW,e),[a,o]=[af.BOLLBU,af.BOLLBL].map(t=>this.innVal(3,t,e));a<r&&o>n?t=0:i=0;let l=this.innVal(4,af.TTMSQZOSC,e),u=e>0?this.innVal(4,af.TTMSQZOSC,e-1):null;if(eH(l))if(eH(u)){let e=l>=0,t=u<l;s=e?t?3:2:+!!t}else s=2;return{[af.TTMSQZON.id]:t,[af.TTMSQZOFF.id]:i,[af.BARCOLIX.id]:s}}getWrappers(){return[this.wrapInner(af.TTMSQZOSC,4)]}},CRS:class extends cf{constructor(e,t){if(super(e,t),fJ(t)){let i=Sl().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.inputs.Symbol.toUpperCase();let r=i.getTimeSeries(s),n=e=>e.query?.symbol,{model:a}=nY(`{${n(t)}} / {${n(r)}}`,!1),o=new pm(a,[t,r],(e=>{let t=e.unit===$.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:F.Manual,missing:t?H.UseNext:H.UsePrevious,stretch:e=>!1,fieldMap:new Map([[af.Close,af.CRS]]),noDataApproach:B.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation)),l=fK(e,"MA","Average")(o,this.period,af.CRS,af.CRSAVG);this.addInner(r,o,l),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=fB(af.Close,(e,t)=>null,t),i=fB(af.CRS,(e,t)=>null,t),s=fB(af.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(af.CRS,2),this.wrapInner(af.CRSAVG,3)]}},JPI:pw,CTTP:class extends pw{constructor(e,t){e.inputs=ej(sw("JPI").defaults.inputs.filter(e=>"HandbrakePeriod"!==e.name)),super(e,t)}},CTTI:class extends pw{constructor(e,t){e.inputs=structuredClone(pR),super(e,t)}},DRS:class extends cf{get indexSymbol(){return this.inputs[tG.INPUT_SYMBOL]}constructor(e,t){if(super(e,t),fJ(t)){let i=Sl().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.indexSymbol;let r=i.getTimeSeries(s),{model:n}=nY(`{${t.query.symbol}} / {${r.query.symbol}} * 100`,!1),a=new pm(n,[t,r],(e=>{let t=e.unit===$.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:F.Manual,missing:t?H.UseNext:H.UsePrevious,stretch:e=>!1,fieldMap:new Map([[af.Close,af.DRS]]),noDataApproach:B.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation));this.addInner(r,a),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=fB(af.Close,(e,t)=>null,t),i=fB(af.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(af.DRS,2)]}},MRS:class extends cf{get indexSymbol(){return this.inputs[tG.INPUT_SYMBOL]}constructor(e,t){super(e,t);let i=function(e,t,i,s=af.DRS){return fA("DRS",{target:s,inputs:{[tG.INPUT_SYMBOL]:t},aggregation:i,source:null},e)}(t,this.indexSymbol,e.aggregation),s=fP(i,this.period,af.DRS);this.addInner(i,s),this.canLoadMoreData=!0,this.initialNotification=!0}calculateAt(e){let t=this.innVal(1,af.DRS,e),i=this.innVal(2,af.MA,e),s=null;return eH(t,i)&&0!==i&&(s=(t/i-1)*100),{[af.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 cf{constructor(e,t){super(e,t);let i=fR(t,1),s=e.aggregation,r=fk(pV,(e,t)=>10*t,pH(i,this.inputs.Period1,s,af.ROC,pN)),n=pH(r,this.inputs.Period2,s,pV,af.PMO),a=fC(n,this.inputs.Period3,af.PMO,af.PMOS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(af.PMO,1),this.wrapInner(af.PMOS,2)]}},RVOL:class extends cf{constructor(e,t){super(e,t);let i=fK(e,"MA")(t,this.period,af.Volume,pF,!0);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(0,af.Volume,e),s=this.innVal(1,pF,e);return eH(i,s)&&0!==s&&(t=i/s),{[this.target.id]:t}}},WGALPH:class extends cf{isDaily;isFeasible=!0;constructor(e,t){super(e,t),this.isFeasible=!(t instanceof uX)&&!pW.includes(U[t.query.curveStyle]),this.isDaily=e.aggregation.unit===$.Day}acceptable(e,t,i,s){return this.isDaily?0===s||!nb(this.baseVal(af.DateTime,t),this.baseVal(af.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>=pB){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*pk[e]+1}t=100*(i-1)}return{[this.target.id]:t}}},VOLAP:class extends p${constructor(e,t){super(e,!1,t)}},AVWAP:class extends pl{constructor(e,t){super(e,t)}get helpers(){return[pn,pa]}isSameOhlcBar(e,t){let{unit:i,size:s}=this.aggregation;switch(i){case $.Tick:return e===t;case $.Intraday:return as(t,l$(e,s));case $.Day:return as(t,lF(e,s));case $.Week:return nb(e,t);case $.Month:return ny(e,t);case $.Quarter:return nT(e,t);case $.Year:return nP(e,t);default:throw Error(`Unexpected aggregation unit ${$[i]}`)}}calculateAt(e){let t=null,i=null,s=null,r=this.inputs.Anchor,n=this.dateAt(e);if(as(r,n)||this.isSameOhlcBar(n,r)){let r=e>0,n=r?this.valueAt(pn,e-1):0,a=r?this.valueAt(pa,e-1):0,o=this.innVal(0,af.Volume,e);t=(i=n+this.innVal(1,this.source,e)*o)/(s=a+o)}return{[pn.id]:i,[pa.id]:s,[af.AVWAP.id]:t}}},KST:class extends cf{constructor(e,t){super(e,t);let i=this.source,s=fB(i,eu(fz,i),t),r=fR(s,this.inputs.PeriodRoc1,i),n=fR(s,this.inputs.PeriodRoc2,i),a=fR(s,this.inputs.PeriodRoc3,i),o=fR(s,this.inputs.PeriodRoc4,i),l=fP(r,this.inputs.PeriodMa1,af.ROC,af.MA1),u=fP(n,this.inputs.PeriodMa2,af.ROC,af.MA2),h=fP(a,this.inputs.PeriodMa3,af.ROC,af.MA3),c=fP(o,this.inputs.PeriodMa4,af.ROC,af.MA4),d=fk(af.KST,(e,t,i,s,r)=>t+2*i+3*s+4*r,l,u,h,c),p=fP(d,this.inputs.PeriodSig,af.KST,af.KSTSIG);this.addInner(d,p)}getWrappers(){return[this.wrapInner(af.KST,1),this.wrapInner(af.KSTSIG,2)]}},STC:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.PeriodShort,af.Close,pG),s=fk(pY,(e,t,i)=>t-i,i,fC(t,this.inputs.PeriodLong,af.Close,pz)),r=this.inputs.PeriodStoch1,n=this.inputs.PeriodStoch2,a=fK(e,"EMA"),o=a(fx(s,r,pj,!1,pY),n,pj,pK),l=a(fx(o,r,pq,!1,pK),n,pq,this.target);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCCLO:class extends pQ{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=(e,t,i)=>t-i,r=fk(pJ,"Yes"===this.inputs.RatioAdjusted?(e,t,i)=>(t-i)/(t+i)*1e3:s,t,i),n=fC(r,this.inputs.Period1,pJ,pX),a=fC(r,this.inputs.Period2,pJ,pZ);return fk(this.target,s,n,a)}},NHLAI:p2,CMBCI:class extends cf{constructor(e,t){super(e,t);let i=fN(t,this.inputs.Period1Rsi,af.Close,p3),s=fB(p4,eh(fY,this.inputs.Period1Mom,p3),i),r=fP(fN(t,this.inputs.Period2Rsi,af.Close,p5),this.inputs.Period2Ma,p5,p6),n=fk(af.CMBCI,(e,t,i)=>t+i,s,r),a=fP(n,this.inputs.PeriodFastMa,af.CMBCI,af.CMBCIF),o=fP(n,this.inputs.PeriodSlowMa,af.CMBCI,af.CMBCIS);this.addInner(n,a,o)}getWrappers(){return[this.wrapInner(af.CMBCI,1),this.wrapInner(af.CMBCIF,2),this.wrapInner(af.CMBCIS,3)]}},COTI:class extends cf{constructor(e,t){super(e,new dw({source:af.Close,inputs:{},outFields:fv("COTLC")},t));let i=Number.parseInt(this.inputs.History),s=fx(this.innerSeries[0],6===i?26:52*i,af.COTI,!1,af.COTLCCMSP);this.initialNotification=!0,this.computedServerSide=!0,this.addInner(s)}getWrappers(){return[this.wrapInner(af.COTI,1)]}},CHEXI:class extends cf{isLong;constructor(e,t){super(e,t),this.isLong="Long"===this.inputs.Direction;let i=this.period,s=fO(t,i),r=this.inputs.Multiplier,n=fk(p7,(e,t)=>null===t?null:r*t,s),a=fM(t,i,af.High,af.HH,!0),o=fM(t,i,af.Low,af.LL,!1);this.addInner(n,a,o)}calculateAt(e){let t=null,i=null,s=this.innVal(1,p7,e);return null!==s&&(this.isLong?t=this.innVal(2,af.HH,e)-s:i=this.innVal(3,af.LL,e)+s),{[af.CHEXL.id]:t,[af.CHEXS.id]:i}}},MBBANDS:class extends cW{constructor(e,t){super(e,"Modified",t)}},OPTIV:class extends p8{},IVRANK:class extends p8{},IVPCTL:class extends p8{},OPTVOLPC:class extends p8{},OPTOIPC:class extends p8{},OPTVOL:class extends p8{},OPTOI:class extends p8{},CHOP:class extends cf{constructor(e,t){super(e,t);let i=fO(t,1),s=this.inputs.Period,r=fM(t,s,af.High,af.HH,!0),n=fM(t,s,af.Low,af.LL,!1);this.addInner(i,r,n)}calculateAt(e){let t=null,i=this.period;if(e>i){let s=this.past(e,i,af.ATR,this.innCont(1));if(eg(s)){let r=ef(s),n=this.innVal(2,af.HH,e);t=100*Math.log10(r/(n-this.innVal(3,af.LL,e)))/Math.log10(i)}}return{[this.target.id]:t}}},MACLD:class extends cf{constructor(e,t){super(e,t);let i=fK(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,af.MACLD1),r=i(t,e.inputs.Period2,this.source,af.MACLD2);this.addInner(s,r)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=this.innVal(1,af.MACLD1,e),i=this.innVal(2,af.MACLD2,e);return{[af.BARCOLIX.id]:+(t>i)}}getWrappers(){return[this.wrapInner(af.MACLD1,1),this.wrapInner(af.MACLD2,2)]}},BTI:class extends pQ{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=fk(p9,(e,t,i)=>t/(t+i),t,i);return fK(e,"MA","Average")(s,this.inputs.Period,p9,this.target)}},FRAMA:class extends cf{constructor(e,t){super(e,t),f$(this);let i=e.inputs.Period,s=Math.floor(i/2),r=fM(t,i,af.High,fl,!0),n=fM(t,i,af.Low,fu,!1),a=fM(t,s,af.High,fh,!0),o=fM(t,s,af.Low,fc,!1),l=fM(t,s,af.High,fd,!0),u=fM(t,s,af.Low,fp,!1);this.addInner(r,n,a,o,l,u)}calculateAt(e){let t=this.period,i=Math.floor(t/2),[,s]=fG(this),r=s.getData(this.source)[e];if(!this.atLeast(e,t))return{[this.target.id]:r};let n=this.innVal(2,fl,e),a=this.innVal(3,fu,e),o=this.innVal(4,fh,e),l=this.innVal(5,fc,e),u=this.innVal(6,fd,e-i),h=this.innVal(7,fp,e-i);if(!eH(n,a,o,l,u,h))return{[this.target.id]:r};let c=(n-a)/t,d=(o-l)/i,p=(u-h)/i,f=0;d>0&&p>0&&c>0&&(f=(Math.log(d+p)-Math.log(c))/Math.log(2));let m=Math.exp(-4.6*(f-1));m=Math.max(.01,Math.min(1,m));let g=e>0?this.container.getData(this.target)[e-1]:r,y=null!==g?m*r+(1-m)*g:r;return{[this.target.id]:y}}},FISHER:class extends cf{constructor(e,t){super(e,t);let i=e.inputs.Period,s=fB(ff,eu(cQ,ff),t),r=fM(s,i,ff,af.HH,!0),n=fM(s,i,ff,af.LL,!1);this.addInner(s,r,n)}get helpers(){return[fm]}calculateAt(e){let t=this.innVal(1,ff,e),i=this.innVal(2,af.HH,e),s=this.innVal(3,af.LL,e);if(!eH(i,s,t))return{[af.FISHER.id]:null,[af.FISHTRG.id]:null,[fm.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(fm):null)??0);a>.99?a=.999:a<-.99&&(a=-.999);let o=e>0?n(af.FISHER):null,l=.5*Math.log((1+a)/(1-a))+.5*(o??0);return{[af.FISHER.id]:l,[af.FISHTRG.id]:o,[fm.id]:a}}},PC:class extends cf{stdDevs;periodForecast;unitsPerYear;constructor(e,t){super(e,t),this.unitsPerYear=fX(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=af.Close,r=af.HV){return fA("HV",{source:s,target:r,aggregation:i,inputs:fS(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(af.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(af.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{[af.PCUP1.id]:t,[af.PCDN1.id]:i,[af.PCUP2.id]:s,[af.PCDN2.id]:r,[af.PCUP3.id]:n,[af.PCDN3.id]:a}}recalculateAt(e,t,i){let s={tag:e0(),src:this.innerSeries[0]};i&&this.calculate(s)}},GREEKS:class extends cf{constructor(e,t){super(e,cd(t,e=>new fe(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(af.Delta,0),this.wrapInner(af.Gamma,0),this.wrapInner(af.Theta,0),this.wrapInner(af.Vega,0)]}},PVACP:class extends p${constructor(e,t){super(e,!0,t)}},TDI:class extends cf{constructor(e,t){super(e,t),f$(this);let i=e.inputs.PeriodRSI,s=e.inputs.PeriodTradeSignal,r=e.inputs.PeriodMarketBase,n=e.inputs.PeriodBB,[a]=fG(this),o=fN(this.innerSeries[a],i,this.source,af.TDIPRC),l=fP(o,s,af.TDIPRC,af.TDITSL),u=fP(o,r,af.TDIPRC,af.TDIMBL),h=fH(o,n,af.TDIPRC,af.MSD);this.addInner(o,l,u,h)}calculateAt(e){let t=this.inputs.MultiplierBB,i=+!!this.sourceNeedsCompute,s=this.innVal(1+i,af.TDIPRC,e),r=this.innVal(2+i,af.TDITSL,e),n=this.innVal(3+i,af.TDIMBL,e),a=this.innVal(4+i,af.MSD,e),o=null,l=null;if(eH(n,a)){let e=t*a;o=n+e,l=n-e}return{[af.TDIPRC.id]:s,[af.TDITSL.id]:r,[af.TDIMBL.id]:n,[af.TDIUPR.id]:o,[af.TDILWR.id]:l}}},PPS:class extends cf{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=af.Close;"Close"!==s&&(n=this.isLong?af.High:af.Low);let a=fM(t,i,n,fo,this.isLong);this.addInner(a)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=null,i=this.innVal(1,fo,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{[af.PPS.id]:t,[af.BARCOLIX.id]:r}}},RCI:class extends cf{constructor(e,t){super(e,t);let i=new fg({source:this.source,target:af.RCI,inputs:{Period:e.inputs.Period}},t),s=e.inputs.PeriodSignal,r=fK(e,"MA","Smoothing")(i,s,af.RCI,af.RCISIG);this.addInner(i,r)}getWrappers(){return[this.wrapInner(af.RCI,1),this.wrapInner(af.RCISIG,2)]}}};function fS(e){return{[tG.INPUT_PERIOD]:e}}function fT(e){return{target:e,source:null,inputs:fI}}function fA(e,t,i){if(eU(fy,e))return new fy[e](t,i);let s=Sl()?.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 fv(e){return sw(e).defaults.curves.reduce((e,t)=>e.concat(t.fields.filter(t=>!e.includes(t))),[]).map(e=>af[e])}function fb(e,t,i,s){return{source:t,target:i,inputs:fS(e),allowEmptyValues:s}}function fP(e,t,i,s=af.MA,r=!1){return fA("MA",fb(t,i,s,r),e)}function fC(e,t,i,s=af.EMA,r=!1){return fA("MAEXP",fb(t,i,s,r),e)}function fE(e,t,i,s=af.SMA,r=!1){return fA("MASMO",fb(t,i,s,r),e)}function f_(e,t,i,s=af.WMA,r=!1){return fA("MAWEI",fb(t,i,s,r),e)}function fL(e,t,i,s=af.HMA,r=!1){return fA("HMA",fb(t,i,s,r),e)}function fM(e,t,i,s,r,n=!1){return new cV({source:i,target:s,inputs:fS(t)},r,n,e)}function fx(e,t,i,s,r=null){return new cH({source:r,target:i,inputs:fS(t)},s,e)}let fI={};function fD(e,t=af.TR){return fA("_TR",fT(t),e)}function fO(e,t,i="SMA",s=af.ATR){return fA("ATR",{target:s,inputs:{[tG.INPUT_PERIOD]:t,[tG.INPUT_SMOOTHING]:i},source:null},e)}function fw(e,t=af.TP){return fA("TP",fT(t),e)}function fR(e,t,i=af.Close,s=af.ROC){return fA("ROC",{source:i,target:s,inputs:fS(t)},e)}function fN(e,t,i,s=af.RSI,r=!1){return fA("_RSI",{source:i,target:s,inputs:{...fS(t),Modified:r}},e)}function fV(e,t=af.MFMUL){return fA("MFV",fT(t),e)}function fH(e,t,i,s=af.MSD){return fA("MSD",{source:i,target:s,inputs:fS(t)},e)}function fF(e,t,i,s=af.MOVLR){return fA("MOVLR",{source:i,inputs:fS(t),target:s},e)}function fB(e,t,i){return new c1(fT(e),t,i)}function fk(e,t,...i){return new cJ(fT(e),t,...i)}function fW(e,t,i){return t-i}function fU(e,t,i){return(t-i)/i*100}function f$(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=fB(t,eu(fz,t),e.innerSeries[0]);e.addInner(i)}}function fG(e){let t=+!!e.sourceNeedsCompute;return[t,e.innCont(t)]}let fz=function(e,t){let[i,s,r,n]=[af.Open,af.High,af.Low,af.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}},fY=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}},fj={sma:fE,ma:fP,ema:fC,wma:f_,hma:fL};function fK(e,t,i="Smoothing"){return fj[(e.inputs[i]??t).toLowerCase()]}let fq={atr:fO,adjatr:function(e,t,i="MA",s=af.Close,r=af.ADJATR){return fA("ADJATR",{source:s,target:r,inputs:{[tG.INPUT_PERIOD]:t,[tG.INPUT_SMOOTHING]:i}},e)}};function fX(e){switch(e.unit){case $.Day:return 252;case $.Week:return 52;case $.Month:return 12;default:return 0}}function fZ(e){let t=[af.High,af.Low];return e instanceof pm&&2!==ev(e.targetFields,t).length}function fJ(e){return!(e instanceof uX)&&e.query instanceof ch}class fQ extends cm{constructor(e,t){super(e,t,fC(t,13,af.Close),function(e,t,i,s,r=af.Close){return fA("MACDEXP",{source:r,inputs:{Period1:12,Period2:26,Period3:9},outFields:[af.MACD,af.MACDS,af.MACDH]},e)}(t,0,0,0,af.Close)),this.query=t.query,this.useNotifications=!0}calculateAt(e){let t=k.Same,i=this.innVal(1,af.EMA,e),s=this.innVal(1,af.EMA,e-1),r=this.innVal(2,af.MACDH,e),n=this.innVal(2,af.MACDH,e-1);return eH(i,s,r,n)&&(i>s&&r>n?t=k.Up:i<s&&r<n&&(t=k.Down)),{[af.BREL.id]:t}}getWrappers(){return this.wrapBaseFields(af.Open,af.High,af.Low,af.Close,af.Change,af.Volume,af.OpenInterest,af.TradingDay)}}function f0(e,t){return eH(t)?(this[e]=t,null):this[e]}class f1{_domain;_range;_extent;_padding;constructor(){this._domain=this._range=this._extent=null,this._padding=[0,0]}domain(e){return f0.call(this,"_domain",e)}range(e){return f0.call(this,"_range",e)}padding(e){return f0.call(this,"_padding",e)}get ready(){return eH(this._domain,this._range)}}let f2=1/Math.log2(10);function f3(e,t){let i,s,r,n,a=(i=e[0],(s=e[1]-i)>0?e=>(e-i)/s:e=>ed(isNaN(s)?NaN:.5)),o=(r=t[0],n=t[1],e=>r*(1-e)+n*e);return e=>o(a(e))}function f4(e){return Math.sign(e)*Math.log10(1+Math.abs(e/f2))}function f5(e){return Math.sign(e)*f2*(-1+Math.pow(10,Math.abs(e)))}let f6=[[0,1],[1,10],[10,100],[100,1e3],[1e3,1e4],[1e4,1e5]];class f7 extends f1{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=ed,s=ed;switch(this.scaleType){case q.Linear:break;case q.Logarithmic:i=f4,s=f5;break;default:throw Error("Unexpected scale type (neither linear nor log)")}let r=this._domain.map(i),n=this.rangeWithPadding(),a=t?f3(n,r):f3(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===q.Linear||s<0||r>1e5)return f8(t,i,e);let n=this.findLogBand(s),a=this.findLogBand(r),o=2*e;return a-n==0?f8(t,i,o):this.getLogTicks(n,a,o,i<t)}findLogBand(e){return f6.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]=f6[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=f8(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===q.Logarithmic}}function f8(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 f9={color:tG.COLOR_TRANSPARENT},me={color:tG.COLOR_TRANSPARENT,width:0,dashStyle:"Solid"},mt=new Set([af.Open,af.High,af.Low,af.Close].map(e=>e.id)),mi=new iO(0,0,0,0);class ms{axis;id;record;metaData;timeSeries;notifyAboutPriceDomains=!1;customPlotValues=!1;_priceMapFirstIndex;priceMapper;_firstVisibleDate=null;_lastVisibleDate=null;main=!1;curves=[];type=X.Symbol;isShutDown=!1;targetFields=[];detachedScale;yScale=null;levels;bands;annotations;visFromIndex;visToIndex;_eventsData;precision;visible=!0;constructor(){this.axis=null,this.id=e0(),this.record=new aA(""),this.metaData=new ii,this.timeSeries=new uX,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&&eH(this.eventsSeries)&&this.eventsSeries.hasData&&this.eventsSeries.container.size>0}getEventFor(e){return null}get isSymbol(){return this.is(X.Symbol)}get isExpression(){return this.is(X.Expression)}get isStudy(){return this.is(X.Study)}get isForward(){return this.is(X.Forward)}get isSeasonal(){return this.is(X.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 cg(i(ud.slice()),e):this.mainCurve.isElderImpulseSystemStyle?t=new fQ(i(ud.slice().concat(af.BREL)),e):this.mainCurve.isPercentChangeStyle&&(t=new dJ(i(ud.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=X[e.type],this.main=e.main,e.levels&&(this.levels=e.levels),e.bands&&(this.bands=e.bands),eH(e.precision)&&(this.precision=e.precision),this.curves=e.curves.map(e=>{let t=new hq;return t.plot=this,t.fromModel(e),t}),e.detachedScale&&(this.detachedScale=e.detachedScale,this.yScale=new f7(q.Linear,null)),this.visible=e.visible??!0}initialize(){}shutdown(){eH(this.timeSeries)&&eH(this.timeSeries.shutdown)&&!this.timeSeries.isCached&&this.timeSeries.shutdown(),this.isShutDown=!0}makeQuery(){let e=this.axis.pane.presenter,t=new ch(null,e.data.aggregation,Z.Normal,[eK(e$(e.data,null,"range","from")),eK(e$(e.data,null,"range","to"))]);return t.barsToFetch=e.data.maxDataPoints||tG.DEFAULT_MAX_RECORDS,t.aggregation.backAdjust&&(t.barsToFetch=4*t.barsToFetch),t.chartId=e.elementId,t.curveStyle=this.curves[0].style,t.visibleRange=e$(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 eH(this.detachedScale,this.yScale)&&this.detachedScale}getDetachedScaleMargins(){return tG.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=tG.OUT_OF_SCREEN;for(let i of this.levels.filter(e=>e.visible)){let s=this.priceToY(i.value);i6(e,i7({line:i.line,fill:f9})),iG(e,{x:-1,y:s},{x:t,y:s})}e.restore()}drawBands(e){e.save();let t=tG.OUT_OF_SCREEN;for(let i of this.bands){let s=this.priceToY(i.range.to),r=this.priceToY(i.range.from);i6(e,i7({fill:i.fill,line:me})),iU(e,new iO(-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!==af.DateTime):[]}getEventsAt(e){let t=this.eventsSeries.container,i=i=>t.getData(i)[e];return this.getEventFields().map(t=>{let s=i(t);if(!eH(s))return null;let r=this.getEventFor(t);if(!eH(r))return null;let n={field:t,value:s,date:i(af.DateTime),text:r.title,color:r.color};if(t!==af.Custom||s!==tG.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?af.High:i.isTick?af.Last:af.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(!eH(r)||!eH(r[0],r[1]))return;let n=(e,t=af.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===$.Year)return tn(t);if(i===$.Quarter)return nS(t);if(i===$.Month)return th(t);if(i===$.Week)return nv(t);if(i===$.Day)return to(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:mi}}):[]).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 iO(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===af.Custom?t:null}hitTestCustomEvent(e){return null!==this.getCustomEventDataAt(e)}tryHandleCustomEventClick(e){let t=this.getCustomEventDataAt(e);return!!eH(t)&&(this.showCustomEventPopup(t),!0)}isEmpty(){let e=this.timeSeries;return eH(e)&&e.hasData&&e.container.isEmpty}draw(e){if(this.visible)for(let t of(eH(this.levels)&&this.drawLevels(e),eH(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(!eH(e)||!this.timeSeries.hasData||!this.shouldPriceMap(i,s))return e;let[r,n]=this.axis.pane.presenter.view.xAxis.xScale.domain()||[];if(!eH(r)||!ov(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&&mt.has(e.id)}getRefPriceMapField(e){return this.isOhlcMapping(e)||e===af.PreviousClose?af.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=K.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(K.Percent)||r===K.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 eH(t)?t!==K.None:this.isComparison(K.Percent)||this.isComparison(K.Value)}onPriceDomainsUpdated(){}get presenter(){return this.axis?.pane?.presenter}}class mr extends ms{_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(!eH(this.timeSeries)||!eH(this.timeSeries.record))return null;let e=this.axis.pane.presenter.display.chart.previous.field;return this.timeSeries.record.getValue(af[e])}getTimeSeries(){let e=Sl().getTimeSeriesDataSource(),t=this.makeQuery();switch(t.symbol=this.resolved,this.mainCurve.style){case U.Renko:case U.Kagi:case U.PointAndFigure:t.barsToFetch=10100,t.inputs=this.inputs;break;case U.Range:t.barsToFetch=4e3;break;case U.LineBreak:t.inputs=this.inputs}let i=this.axis.pane;if(eH(i.alignedToYear)){let e=tM(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:er.Unspecified};this.presenter?.notifyHost(am.TS_MANYCHANGED,e),this.getEvents()}})}getMetaData(){let e=Sl().getMetaDataSource();this.metaData=e.getMetaData(this.resolved),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(am.MD_CHANGED,{plot:this})})}getEvents(){if(!this.hasEvents)return;let e=Sl().getTimeSeriesDataSource(),t={symbol:this.symbol,seriesKind:Z.Events,getHashKey:function(){return Object.values(this).filter(e=>"function"!=typeof e).join("|")}};tG.EVENTS.forEach(e=>{t[e]=e$(this.events,!1,e,"show")}),this._eventsSeries=e.getTimeSeries(t),this._eventsSeries.ready().then(e=>{e&&this.presenter?.notifyHost(am.TS_EVENTSCHANGED,{series:this.eventsSeries})})}get eventsSeries(){return this._eventsSeries??null}get hasEvents(){return!!eH(this.events)&&tG.EVENTS.some(e=>e$(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 $.Tick:return nI;case $.Intraday:case $.Day:return n_;case $.Week:return nL;case $.Month:return nM;case $.Quarter:return nx;case $.Year:return nP;default:return nI}}(this.axis.pane.presenter.data.aggregation),this._symbol=e.symbol}getEventFor(e){let t=this.events[e.id.toLowerCase()];return eH(t)&&t.show?t:null}async initialize(){return tW.call(this,async()=>(this.resolved=await tf(this.symbol),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class mn extends mr{seriesKind;fundamental;constructor(e){super(),this.seriesKind=e}get showPrevious(){return!1}get title(){return`${this.curves[0].fields[0].name}(${$[this.fundamental].substring(0,1)})`}fromModel(e){this.fundamental=$[e.fundamental],super.fromModel(e)}makeQuery(){let e=new ch(this.symbol,new nD(this.fundamental),this.seriesKind);return e.fields=this.curves[0].fields,e}}class ma{longPressTimeout;constructor(){this.longPressTimeout=null}getTouchCrosshairDelayMillis(){let e=Sl().config.touchCrosshairDelayMillis;return eH(e)&&Number.isFinite(e)?e:tG.LONG_PRESS_DELAY_MILLIS}startLongPress(e,t,i){eD()&&(this.longPressTimeout=setTimeout(()=>this.longPressTriggered(e,t,i),this.getTouchCrosshairDelayMillis()))}longPressTriggered(e,t,i){this.cancelLongPress(),this.performLongPress(e,t,i)}cancelLongPress(){eD()&&eH(this.longPressTimeout)&&(clearTimeout(this.longPressTimeout),this.longPressTimeout=null)}performLongPress(e,t,i){}}function mo(e){return e.locked||e.axis.pane.presenter.display.allAnnotationsLocked}class ml extends ma{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){mJ(this.annotation,i)}onMouseMove(e){if(this.cancelLongPress(),this.annotation.axis.pane.presenter.enableTooltip(!1),mo(this.annotation))return;let{point:t,view:i,offset:s}=e;if(!eV(t)||t.axis!==this.annotation.axis)return;i.drawCrosshair({ap:t,offset:s}),this.cursorSet||(this.previous.axis.pane.presenter.view.setCursor(Q.Move),this.cursorSet=!0);let r=iy(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(),gG(this.annotation,this.moved,eo.Moved)}}class mu{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(et.Shift),this.annotation.axis.pane.presenter.enableTooltip(!1),mo(this.annotation))return;let{point:t,view:i,offset:s}=e;if(i.drawCrosshair({ap:t,offset:s}),eH(t)){let e=this.annotation.points[this.pointIndex],i=iy(t.point,e.point);switch(e.moveDirection){case ei.Both:e.update(t.price,t.time);break;case ei.Horizontal:e.update(e.price,t.time);break;case ei.Vertical:e.update(t.price,e.time)}this.moved=e.moveDirection!==ei.None,this.moved&&this.annotation.wasPointMovedByTool(e,i)}this.annotation.requestRedraw()}onMouseUp(e){gG(this.annotation,this.moved,eo.PointMoved)}}class mh{anchor;isVertical;axis;constructor(e,t,i){this.anchor=e,this.isVertical=t,this.axis=i}hitTest(e){return!!eH(this.anchor)&&(this.isVertical?Math.abs(e.x-this.anchor.x)<=tG.HIT_TEST_TOLERANCE:Math.abs(e.y-this.anchor.y)<=tG.HIT_TEST_TOLERANCE)}draw(e){let t=tG.OUT_OF_SCREEN;this.isVertical?iz(e,this.anchor.x,-t,t):iY(e,this.anchor.y,-t,t)}}class mc{id;axis;_price;_time;passive=!1;moveDirection=ei.Both;visible=!0;point;constructor(e,t,i){this.id=e0(),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!==ei.None}get presenter(){return this.pane.presenter}get pane(){return this.axis.pane}toPoint(){let e=this.axis.toPoint(this);eH(e)&&eB(e.x)&&eB(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)<=tG.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)-tG.HALF_ANN_POINT_DIMENSION)}draw(e,t){if(eH(this.point)){let i=tG.HALF_ANN_POINT_DIMENSION;eH(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 md(e){return 0===iL(e.fill.color).a?e.line.color:e.fill.color}function mp(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 mf(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 mm{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=e0()}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 tG.EMPTY_ARRAY}getTimeScaleAdornments(){return tG.EMPTY_ARRAY}extractTraits(e=!0){let t=eG(this.traits),i=sA(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:eF(+e.time,4)}))}offset(e){this.points.filter(e=>e.movable).forEach(t=>{t.updateFromPoint(iS(t.point,e))})}get traits(){return this._traits||(this._traits=eG(this.defaultTraits)),this.adjustFill&&(this._traits.fill.color=md(this._traits),this.adjustFill=!1),this._traits}set traits(e){void 0!==e&&ez(this.traits,e,!1)}get activePoints(){return this.points.filter(e=>!e.passive)}get style(){return i7(this.traits)}get defaultTraits(){return i5(this.axis.pane.presenter.display,this.name)}get defaultStyle(){return i7(this.defaultTraits)}get adornStyle(){let e=eG(this.defaultTraits);return e.fill.color=this.traits.line.color,e.line.width=0,e.line.color=tG.COLOR_TRANSPARENT,i7(e)}get pointsStyle(){let e=eG(this.defaultTraits);return e.line.dashStyle="Solid",i7(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=eH(e);t&&(s||!r)&&i.toPoint(),r&&s&&(this.isSelected||this.drawn)&&(i6(e,this.pointsStyle),i.draw(e,this))})}addPoints(e){for(let t=0;t<e;t++)this.points.push(new mc(this.axis))}toModel(){let e=this.extractPoints();return{id:this.name,uid:this.uid,visible:this.visible,locked:this.locked,points:e,traits:eG(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=eH(e)?eG(e):{};eH(t)&&ez(n,t,!1),this.traits=n,eH(i)&&this.updatePoints(i)}priceMap(e){return this.axis.priceMap(e)}flip(e){let t=this.getFlipAnchorIndices();if(!eV(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 mg(e,t,i,s){return function(r,n=!0){let a=new t(r,e,i);return n?r.appendAnnotation(a):a.drawn=!1,eH(s)&&(a.traits=s),a}}class my{axis;angle;extent;anchor1;anchor2;p1;p2;style;extended;_data;isTrend;constructor(e,t,i,s,r){this.axis=r,eH(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)+tG.OUT_OF_SCREEN}hitTest(e){return!!eH(this.p1,this.p2)&&iA([this.p1,this.p2],e,tG.HIT_TEST_TOLERANCE)}draw(e){eH(this.p1,this.p2)&&(iG(e,this.p1,this.p2),this.extended)}getAdornOffset(e){var t,i;let s=iB(e),r=iH(e,1);return t=this.p1,i=this.p2,-(t.y-i.y)/(t.x-i.x)<0&&(s.y=r+5),s}}class mS{style;axis;rect;constructor(e,t,i,s){this.axis=s,this.rect=new iO(e.x,e.y,t,i)}hitTest(e){return this.rect.contains(e)}draw(e,t){iU(e,this.rect)}}class mT extends mm{countCache;constructor(e,t){super(e,t)}draw(e,t){if(this.prepareDraw(e,t)&&!this.drawn){let t=this.getElements();i6(e,this.style),t.forEach((t,i)=>{i6(e,this.getStyleForElement(t,i)),t.draw(e)}),i6(e,this.adornStyle),this.adornElements(t,e);let i=this.getMarkers();i6(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,!eH(e)||e}get showBackground(){var e;return e=this.traits?.showBackground,!!eH(e)&&e}get backgroundOpacity(){var e;return eH(e=this.traits?.backgroundOpacity)?e:0}fillOnlyStyle(e){return i7({line:{color:tG.COLOR_TRANSPARENT,dashStyle:"Solid",width:0},fill:this.traits[e]})}lineOnlyStyle(e){return i7({fill:{color:tG.COLOR_TRANSPARENT},line:this.traits[e]})}makeLine(e,t){return new my(e,t,!1,!1,this.axis)}applyBackgroundOpacity(e){return iP(ib(e),this.backgroundOpacity)}getTraitsFor(e){let t={fill:{color:tG.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 mA extends mT{_factors;constructor(e,t){super(e,t)}get factorsPropName(){return tG.AT_FACTORS}get factors(){return i0(this._factors??this.traits[this.factorsPropName])}getStyleForElement(e,t){return e.style??super.getStyleForElement(e,t)}get showLevels(){return this.traits[tG.AT_SHOW_LEVELS]}get levelsKind(){return this.traits[tG.AT_LEVELS_KIND]}get labels(){return this.traits[tG.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[tG.AT_PRICES_ON_SCALE]}formatLevelPrice(e,t){let i=this.levelsKind===tG.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+` (${hE(this.axis,e)})`).trim()}return s}getAdornPointAndAlign(e,t){let i=this.labels,s=e instanceof my,r=(e,t,i)=>({pt:e,align:t,offset:i});switch(i){case tG.AT_LABELS_LEFT:return r(s?e.anchor1:e,J.Right,-t);default:case tG.AT_LABELS_RIGHT:return r(s?e.anchor2:e,J.Left,t);case tG.AT_LABELS_CENTER:return r(s?im(e.anchor1,e.anchor2):e,J.Center,0)}}getColoredElements(e){let t=this.singleStyle;return this.factors.map(i=>{let s=e(i);return null===s?null:(t||(s.style=i7(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(!eH(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(ik(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(!eH(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);iW(s,o,f,d,r?l:e.style.strokeStyle)}u=e})}getAdornTextPoint(e,t,i,s){let r=iH(e,.75);return iS(i,{x:s,y:!0===t?r/2:t})}}class mv extends mT{lines;constructor(e,t){super(e,t),this.resetComputedState()}get rectStyle(){return this.fillOnlyStyle(tG.AT_FILL)}get rect(){let[e,t,,]=this.getScreenPoints(),i=new mS({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,hD),h=e_(l,+s.time,Number,hD)-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=i7(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 mb extends mc{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 mP{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 eH(this.points[0].point,this.points[1].point)?new iO(this.left,this.top,this.width,this.height):null}}function mC(e){let t=new mc(e),i=new mc(e),s=new mb(e,t,i),r=new mb(e,i,t);return[t,i,s,r]}class mE extends mm{helper;constructor(e,t){super(e,t),this.points=mC(e),this.helper=new mP(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)&&(i6(e,this.style),!0)}updatePoints(e){this.allowPricesChangeUI&&2===e.length&&e.forEach((e,t)=>this.points[t].update(e.price,e.time))}}class m_{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 mP(this.points)}hitTest(e){let t=this.getRect();return!!eV(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 mL extends mT{textEditable;_textAnnElement;constructor(e,t){super(e,t),this.textEditable=!0,this.points=mC(e),this.adjustFill=!0}get textLines(){return this.traits[tG.AT_TEXT_LINES]}set textLines(e){this.traits[tG.AT_TEXT_LINES]=e,this._textAnnElement=void 0}get textElement(){return!eH(this._textAnnElement)&&this.visible&&(this._textAnnElement=new m_(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 mM extends mL{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 mc(this.axis,t,e))}updateFrom(e,t,i,s,r){super.updateFrom(e,t,i,s,r),eH(e?.textLines)&&(this.textLines=e.textLines)}getElements(){let e=super.getElements(),t=this.pricesPoints.map(e=>new mh(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 mx{annId;annotation;constructor(e){this.annId=e}onKeyDown(e){if(null==this.annId)return;let{key:t,code:i,presenter:s}=e;eO(t,i)&&(eH(this.annotation)&&(this.annotation.axis.deleteAnnotation(this.annotation,!1),s.view.redraw()),g$(s,{toolChange:eo.Cancelled,annId:this.annId}))}}class mI extends mx{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=eV(this.annotation);if(i===ee.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}),eH(this.annotation,t)&&(this.alignPointsMode=this.forceAlignPoints||e.getModifier(et.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(){gG(this.annotation,!0,eo.Created)}isAccidentalMouseUp(e){let{point:t}=e,i=this.annotation.points[0].point;return ig(t.point,i)<tG.HIT_TEST_TOLERANCE}onMouseUp(e){if(void 0===this.annotation)return void gY(e);if(this.isAccidentalMouseUp(e)){this.dragged=!0;return}this.dragged=!1,this.thirdPoint||this.finish()}}class mD extends mI{constructor(e,t=!1){super(e,t),this.forceAlignPoints=!0}}class mO extends mI{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}),eH(this.annotation)&&this.dragged){let[e,i]=this.annotation.points;i.update(t.price,t.time);let s=iy(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 mw extends mx{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=!eH(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:md(i5(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[tG.AT_FILL].color}}}onMouseDown(e){let{point:t}=e;if(this.isNew)if(0===this.clicks){if(void 0===t)return void gY(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();tR(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(),gG(t,!0,this.isNew?eo.Created:eo.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 mR(e){return Sl().config.tooltipMovement===e}function mN(){return mR("Draggable")}let mV=tG.TOOLTIP_STD_LEGACY_CLASS,mH=tG.TOOLTIP_STD_CLASS,mF=tG.TOOLTIP_BUBBLE_CLASS;class mB{view;tooltipElem;leftSide;mode;isDrag;canDrag;isToggling;constructor(e){this.view=e,this.isDrag=!1,this.tooltipElem=tF(e.el,"div"),tN(this.tooltipElem,{id:`${e.presenter.elementId}-global-tooltip`,class:`${mH} ${mV}`}),this.leftSide=!0,tR(this.tooltipElem,{visibility:"hidden",position:"absolute",cursor:mN()?"move":"default",zIndex:20,top:`${tG.TOOLTIP_Y_OFFSET}px`,left:`${tG.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===tG.TOOLTIP_BUBBLE)this.canDrag=!1,this.tooltipElem.style.transition="none",this.tooltipElem.classList.remove(mH,mV),this.tooltipElem.classList.add(mF),tR(this.tooltipElem,{pointerEvents:"none"});else if(e===tG.TOOLTIP_STD){this.canDrag=mN(),this.tooltipElem.classList.remove(mF),this.tooltipElem.classList.add(mH,mV);let e=tG.TOOLTIP_TOGGLE_SIDE_ANIM_MS;tR(this.tooltipElem,{pointerEvents:"all",top:`${tG.TOOLTIP_Y_OFFSET}px`,left:`${tG.TOOLTIP_X_OFFSET}px`,transition:mR("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*tG.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"),tk(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){tR(this.tooltipElem,{left:`${e}px`,top:`${t}px`})}isAutoMove(){return this.mode===tG.TOOLTIP_STD&&mR("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=tG.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?tG.TOOLTIP_X_OFFSET:e.width-this.tooltipElem.offsetWidth-tG.TOOLTIP_X_OFFSET);this.reposition(i,t)}}toggleSide(){this.isToggling||(this.isToggling=!0,setTimeout(()=>this.isToggling=!1,tG.TOOLTIP_TOGGLE_SIDE_ANIM_MS),this.leftSide=!this.leftSide,this.repositionAuto())}}function mk(e){e.showTooltip&&mW(e,{time:tG.ZERO_DATE,offset:tG.OFFSCREEN_OFFSET,price:0,lastBarRefresh:void 0,justMain:void 0})}function mW(e,{time:t,lastBarRefresh:i,justMain:s,offset:r,price:n}){let a=hG(e,t,r,i,s,n),{mode:o,showMainPlot:l,hideSymbols:u,revealingClose:h}=e.display.tooltip,{includeTimestamp:c,showMainPlot:d,showPlotActions:p}=Sl().config.tooltipHeaders||{},f=eH(d)?d:l,m=!!eH(c)&&c,g=!!eH(u)&&u,y=!!eH(h)&&h,S=!!eH(p)&&p,T=t.valueOf()===tG.ZERO_DATE.valueOf();switch(o){case tG.TOOLTIP_CARDS:s||m$(e,a,f,!T,m&&!T,!1,g,y,S,e.hasLegend?e.view?.legend?.getLegendElem().clientHeight:0);break;case tG.TOOLTIP_BUBBLE:if(!T){let t=a.panes.find(e=>{let{top:t,left:i,width:s,height:n}=e.bounds;return new iO(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=hV({...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)})}m$(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tG.TOOLTIP_STD:if(!T){let t=hV({...a,hideSymbols:g,revealingClose:y,plots:a.panes.map(e=>e.plots).flat()});e.view.tooltip.show(t)}m$(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tG.TOOLTIP_EXTERNAL:e.notifyHost(am.CH_TOOLTIPCHANGED,a);break;default:console.warn(`Unknown tooltip mode requested: ${o}`)}}function mU(e,t,i,s,r,n){tR(e,{position:"absolute",display:"flex","flex-direction":t,"flex-wrap":"wrap",left:`${i+tG.CARDS_X_OFFSET}px`,top:`${r+tG.CARDS_Y_OFFSET}px`,maxWidth:`${n-s-2*tG.CARDS_X_OFFSET}px`})}function m$(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":""}`,T=X[h],A=!(["Study","BalanceSheet","IncomeStatement"].includes(T)||"Expression"===T&&!i)||o.hasLegend&&i?"":h$(l),v=function(e,t){let i=hF(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),b=a?function(e){let t=hF("moreActions");return`<a class="more-actions" data-plot-id="${e}" data-act="Menu" title="Actions">${t}</a>`}(l):"",P=hR(o)&&e.type===X.Symbol,C=(m||P)&&(!s||e.values.length>1),E=t?p.map(e=>hU(C?e.abbreviation:"Close"===e.id&&n?d+" ":null,e.value,e.color)).join(" ")+function(e){if(e&&e.length){let t=e.map(e=>hU(`${e.field.name} (${hx(hN,e.date)})`,e.value,e.color)).join(" ");return`Event ${t}`}return""}(f):"",_=!m&&"Expression"!==T,L=p.slice(0,_?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&&P?`${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 hW(e,t,i=null){return hk(e,t,i,"value-title")}function hU(e,t,i){let s="string"==typeof i?` style="color: ${i}"`:"",r=eH(e)?`<span class="field-name">${e}</span>`:"";return`${r}<span${s} class="field-value">${t}</span>`}function h$(e){return`<a class="delete-plot" data-plot-id="${e}" title="Delete plot">${hF("delete")}</a>`}function hG(e,t,i,s,r,n){let a=function(e,t){let i=e.data.aggregation,s=e.display.xAxis,r=s.isOrdinal,n=eV(r)&&r,a=n?s.ordinalName??"Value":"Date";return{date:n?hb(t):hx(i,t),time:i.isEndOfDay||n?null:hI(i,t,!1),isMultiSymbol:function(e){let t=e.mainPlot.symbol;return e.allPlots.some(e=>e.type===X.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:hz(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,X.Expression;let o=r.axis.comparison!==K.None,l=r.axis.comparison===K.Percent,u=(e,s)=>r.customPlotValues&&s!==af.DateTime?[r.getValueAt(s,t,i),0]:hY(e,s,t,o),h=n?`${sN(r.model.study).meta.title} ${r.fullParams}`:r.metaData.name||"",c={isMain:r.main,type:r.type,typeName:X[r.type],name:r.title,description:h,exchange:r.metaData.exchange||"",error:r.errorText,id:r.id,visible:r.visible};eH(r.yearOffset)&&0!=r.yearOffset&&(c.unalignedDate=hx(e.data.aggregation,function(e,t){return te(2,arguments),tr(e,-e9(t))}(t,r.yearOffset)));let d=r.curves[0];s&&r.type===X.Symbol&&a.hasField(af.Symbol)&&(t.valueOf()===tG.ZERO_DATE.valueOf()?c.name=r.timeSeries.container?.getLastDataPoint(af.Symbol):c.name=u(d,af.Symbol)[0]);let p={},f={range:r.axis.yScale.domain(),allDigits:!0};hj(r,e,f);let m=(e,t)=>{let i=(t===af.Change||t===af.PercentChange)&&e>0?"+":"";return l?i+hP(e):i+r.metaData.format(e,t,f)},g=hR(e),y=new Set;return c.values=r.curves.filter(e=>e.visible).map(e=>(!r.main&&r.isSymbol&&g?ud: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!==U.HollowCandles,t),l=m(i,t).trim();if(eH(i)&&t===af.Change){let[t]=u(e,af.PercentChange);eH(t)&&(l+=` (${m(t,af.PercentChange)})`)}return{abbreviation:hK(t),shortName:t.shortName,id:t.id,name:t.name,longName:`${t.shortName} ${n?r.params:""}`.trim(),color:ib(o),val:i,y:a,value:l}}).filter(e=>null!==e)).flat(),c.events=r.findEvents(u(d,af.DateTime)).filter(e=>e.field!==af.Custom),c})(e,t,n,a,i)).filter(e=>null!==e)})),a}function hz(e){let t=e.getBounds();if(!eH(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 hY(e,t,i,s=!1){let r=e.plot,n=r.timeSeries.container,a=r.axis.pane.presenter.timeline,o=e_(a,+i,Number,hD),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 hj(e,t,i){eH(e.precision)?i.overridePrecision=e.precision:e.isStudy&&eH(t.mainPlot?.precision)&&!eH(sN(e.model.study).meta.decimals)&&(i.overridePrecision=t.mainPlot.precision)}function hK(e){return e.id===af.Change.id?"Δ":e.id.substring(0,1)}class hq{plot;id;fields=[];colors=[];style=U.Line;attributes=[];zones;_shift=0;lineWidth=1;lineMarker;lineSmoothing;dashStyle="Solid";varyColorPerBar=!1;visible=!0;_zoneColors;constructor(){this.id=e0(),this.plot=null}get shift(){return this._shift}set shift(e){this._shift=eH(e)?e:0}get isOhlc(){return(this.isOhlcStyle||this.isCandle||this.isHlcStyle||this.isElderImpulseSystemStyle||this.isRangeStyle)&&this.fields.includes(af.Close)}get name(){return this.isOhlc?"":this.fields[0].name}get isHeikinAshiStyle(){return this.style===U.HeikinAshi}get isCandle(){return this.style===U.Candlestick||this.style===U.HollowCandles||this.style===U.HeikinAshi}get isHollowCandles(){return this.style===U.HollowCandles}get isElderImpulseSystemStyle(){return this.style===U.ElderImpulseSystem}get isPercentChangeStyle(){return this.style===U.PercentChange}get isOhlcStyle(){return this.style===U.OHLC}get isHlcStyle(){return this.style===U.HLC}get isRangeStyle(){return this.style===U.Range}get isRenko(){return this.style===U.Renko}get isKagi(){return this.style===U.Kagi}get isPointAndFigure(){return this.style===U.PointAndFigure}get isLineBreak(){return this.style===U.LineBreak}get isBaseline(){return this.style===U.Baseline}get isLineLike(){return[U.Line,U.Area,U.Baseline,U.PercentChange].includes(this.style)}get isColumn(){return this.style===U.Column}get isMultiColumn(){return this.style===U.MultiColumn}get isStackedColumn(){return this.style===U.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=>W[e])),this.colors=e.colors,this.fields=e.fields.map(e=>af[e]),this.style=U[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(K.None),r=e===af.PercentChange,n=e===af.Change,a=r||(!i||s)&&n,o=this.timeSeries.container.hasField(af.Last)?af.Last:af.Close,l=a?o:e,u=(e,t)=>{let i=this.timeSeries.container.getData(e)[t];return e.type!==z.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 eH(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(!eH(t))return null;let i=this.yScale.domain();return eH(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]=hY(this,this.pickMainField(),t);if(eH(s))e.save(),iD(e,this.plot.axis.pane.getBoundsWithoutScales()),e.fillStyle=ib(this.getColor(r)),e.beginPath(),ce(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=eH(this.zones);this.isOhlc?h8.call(this,e,l):this.isRenko||this.isLineBreak?h2.call(this,e,l):this.style===U.Ribbon?this.varyColorPerBar?cl.call(this,e,l):co.call(this,e,l,this.colors[0]):this.style===U.Area?u?hQ.call(this,e,l,hZ,!0):hZ.call(this,e,l,this.colors,!0):this.isColumn||this.isMultiColumn?u?hQ.call(this,e,l,h4,!0):h4.call(this,e,{...l,range:[null,null]}):this.isStackedColumn?h3.call(this,e,l):this.isBaseline?h1.call(this,e,l):this.style===U.Step?u?hQ.call(this,e,l,h6):h6.call(this,e,l,this.colors[0]):this.isKagi?cn.call(this,e,l):this.isPointAndFigure?ca.call(this,e,l):this.style===U.Dots?h5.call(this,e,l):this.style===U.Line||this.isPercentChangeStyle?u?hQ.call(this,e,l,ct):this.varyColorPerBar?cs.call(this,e,l):ct.call(this,e,l):Si(`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(af.Last)?af.Last:this.fields.includes(af.Close)?af.Close:this.fields[0]}get zoneColors(){if(!eH(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?ib(e[0]):e[1]}getComputedColor(e){if(!this.timeSeries.container.hasField(af.BARCOLIX))return null;let t=this.dataAt(af.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(af.Open,e),i=this.dataAt(af.High,e),r=this.dataAt(af.Low,e),n=this.dataAt(af.Close,e),a=this.dataAt(af.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=eH(i),a=eH(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===G.None||(s.open=this.dataAt(af.Open,e),s.close=this.dataAt(af.Close,e)),s.change=this.dataAt(af.Change,e)}let r=function(e,{open:t,close:i,change:s},r){let n=r.length>2&&e!==U.HLC,a=eH(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 U.Candlestick:case U.Renko:case U.LineBreak:case U.Range:case U.HeikinAshi:case U.OHLC:case U.HLC:case U.Column:{if(eH(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(W.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(af.Projection,e)&&(i=iE(.5,!0)(i));break}case U.ElderImpulseSystem:i=this.colors[this.dataAt(af.BREL,e)];break;case U.HollowCandles:{let e=this.colors[r.isUpPrev||r.isSamePrev?1:0];i=t&&(r.isUp||r.isSame)?tG.COLOR_TRANSPARENT:e;break}case U.Line:case U.PercentChange:case U.Ribbon:case U.Kagi:if(eH(n)){i=n;break}i=this.colors[0];break;case U.PointAndFigure:{let t=+!!uz(this.dataAt(af.BARKIND,e));i=this.colors[t];break}default:throw Error(`Unexpected style ${U[this.style]} for a curve with varying colors`)}return eH(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===U.Area?this.pickAreaStroke(s):s.length>0?s[0]:this.colors[0]}if((this.isMultiColumn||this.isStackedColumn)&&eH(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 hX([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 hZ(e,t,i,s=!1){ct.call(this,e,t,this.pickAreaStroke(i)),cu.call(this,e,t,i[0],s)}function hJ(e,t){let i,s,r=eH(e),n=eH(t),a=this.pane.getBounds();if(r)if(n){let r=this.priceToY(e),n=this.priceToY(t);i=(r+n)/2,s=new iO(a.x,n,a.width,r-n)}else i=this.priceToY(e),s=new iO(a.x,a.y,a.width,i-a.y);else i=this.priceToY(t),s=new iO(a.x,i,a.width,a.y+a.height-i);return[i,s]}function hQ(e,t,i,s=!1,r){let n;this.zones.forEach((a,o)=>{let l=a.value,[u,h]=hJ.call(this,n,l);e.save(),iD(e,h),s&&(t.range=[null,u]);let c=this.zoneColors[o];if(a.gradient){let t=((e,t)=>{let i=iE(.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 eH(r)&&(c=r(o,c));i.call(this,e,t,c),e.restore(),n=l})}function h0(e,t){let{x:i,width:s}=this.pane.getBoundsWithoutScales();e.save(),e.lineWidth=1,e.strokeStyle="#888",e.setLineDash(iv("dot")),iY(e,t,i,i+s),e.restore()}function h1(e,t){let[i,s]=t.range,{baseLevel:r}=function(e){let{BaseLevel:t}=ej(e);return{baseLevel:Number.isFinite(t)?e1(0,100,t):50}}(this.plot.inputs),n=(i-s)*r/100+s;this.zones[0].value=this.yToPrice(n),h0.call(this,e,n),hQ.call(this,e,t,hZ,!0,(t,r)=>{let a=iP(r,0),o=e.createLinearGradient(0,1===t?i:s,0,n);return o.addColorStop(0,r),o.addColorStop(1,a),[o,iP(r,1)]})}function h2(e,{bar:t,slice:i,start:s}){let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2;hX.call(this,i,s,(i,s)=>{if(!s){let[s,n]=[af.Open,af.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 h3(e,{bar:t,slice:i,start:s}){if(!this.isFirstVisibleOfStyle())return!1;let r=this.view.xAxis.xScale.range()[0]+t.offset,n=iX();n.prolog(e);let a=this.plot.curves.filter(e=>e.isStackedColumn);hX.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(eH(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 h4(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=iX();h.prolog(e),hX.call(this,i,s,(i,s)=>{s||l.forEach((t,s)=>{let r=this.dataAt(t,i);if(eH(r)){eH(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 h5(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||tG.CURVE_STYLE_DOTS_RADIUS),a=2*Math.PI;e.beginPath(),hX.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eH(s)){let t=this.priceToY(s);e.moveTo(r+n,t),e.arc(r,t,n,0,a)}}r+=t.totalWidth}),e.fill()}function h6(e,{bar:t,slice:i,start:s},r){let n=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,a=iX();a.prolog(e),e.strokeStyle=r,e.lineWidth=this.lineWidth,this.dashStyle&&e.setLineDash(iv(this.dashStyle)),e.beginPath();let o=!1,l=null;hX.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eH(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(eH(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 h7=[af.Open,af.High,af.Low,af.Close];function h8(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=iX();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===iL(l).a?u:l,h9(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(),h9(e,u,h,t,a,n,p)}(e,t,this.lineWidth,!this.isHlcStyle)};hX.call(this,i,s,(e,i)=>{if(!i){let i=h7.map(t=>this.dataAt(t,e)),[s,r,d,p]=i;if(eH(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);(!eH(o)||m<o)&&(o=m,u=f),(!eH(l)||g>l)&&(l=g,h=f),c(f)}}n+=t.totalWidth}),r&&(eH(u)&&(u.isMin=!0,c(u)),eH(h)&&(h.isMax=!0,c(h))),a.epilog(e)}function h9(e,t,i,s,r,n,a,o=3){t&&i$(e,{x:s,y:r+o},a,0,Math.PI),i&&i$(e,{x:s,y:n-o},a,0,Math.PI,!0)}function ce(e,t,i,s,r=1){let n=tG.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 ct(e,{bar:t,slice:i,start:s},r=null){let n=r||this.getColor(0),a=eV(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();hX.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eH(t)){let i=this.priceToY(t);a&&ce(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(iv(this.dashStyle)),eV(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):ci(e,l,n)}function ci(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 cs(e,{bar:t,slice:i,start:s}){e.lineWidth=this.lineWidth,e.lineCap="square",this.dashStyle&&e.setLineDash(iv(this.dashStyle));let r=this.view.xAxis.xScale.range()[0]+t.offset+t.width/2,n=null,a=null,o=[];hX.call(this,i,s,(i,s)=>{if(!s){let t=this.pickMainField(),s=this.dataAt(t,i);if(eH(s)){let t=this.priceToY(s);a=this.getColor(i),n!==a&&(ci(e,o,n),o.length>0&&(o=[o.pop()]),n=a),o.push({x:r,y:t})}}r+=t.totalWidth}),ci(e,o,a)}let cr=[null,null,null,null];function cn(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=iX();n.prolog(e);let a=null,o=null,l=[];hX.call(this,i,s,(i,s)=>{if(!s){let s=e=>h7.map(t=>this.dataAt(t,e)),[u,h,c,d]=s(i),[,p,f]=i<0?cr:s(i-1);if(eH(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=eH(a)&&a!==o,T=u===h?1:2,A=u===h?2:1;l.push({x:m,y:g[0]}),l.push({x:s,y:g[T]}),S&&(l.push({x:s,y:y}),ci(e,l,a),l=[]),S&&l.push({x:s,y:y}),l.push({x:s,y:g[A]}),a=o}}r+=t.totalWidth}),ci(e,l,o),n.epilog(e)}function ca(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=iX();o.prolog(e);let l=this.plot.timeSeries.builder.boxSize,u=l/2;hX.call(this,i,s,(i,s)=>{if(!s){let[t,s]=[af.High,af.Low].map(e=>this.dataAt(e,i)),r=this.colors[0],h=this.colors[1],c=this.dataAt(af.BARKIND,i),d=uz(c),p=c===tG.BARKIND_XO,f=c===tG.BARKIND_OX;if(eH(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)),T=i===t&&p||i===s&&f?!d:d;e.beginPath(),T?(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 co(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(hX.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(n,e),i=this.dataAt(a,e);eH(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 cl(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;hX.call(this,i,s,(e,i)=>{if(!i){let t=this.dataAt(r,e),i=this.dataAt(n,e);if(eH(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 cu(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,iP(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;hX.call(this,i,s,(i,s)=>{if(!s){let t=this.dataAt(u,i);if(eH(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 ch{symbol;aggregation;range;seriesKind;cacheMe;barsToFetch;offset;chartId;curveStyle;extendedHours;fields=[];alwaysUseBarsToFetch;inputs=[];splits;padded;constructor(e,t,i=Z.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(!eH(this.curveStyle)||!tG.SPECIAL_BUILDER_REQUIRED.includes(this.curveStyle))return"Standard";switch(this.curveStyle){case U.Renko:{let{method:e,period:t,source:i,brickSize:s}=ue(this.inputs),r="ATR"===e?`ATR;${t}`:`${e};${s}`;return`Renko;${r};${i}`}case U.Kagi:{let{method:e,period:t,reversal:i}=uB(this.inputs),s="ATR"===e?`ATR;${t}`:`User;${i}`;return`Kagi;${s}`}case U.PointAndFigure:{let{method:e,period:t,reversal:i,boxSize:s,source:r,oneStepBack:n}=uY(this.inputs),a="ATR"===e?`ATR;${t}`:`User;${s}`;return`PointAndFigure;${a};${r};${i};${n}`}case U.LineBreak:{let{lineBreak:e}=uW(this.inputs);return`LineBreak;${e}`}default:return U[this.curveStyle]}}get needsExtraKey(){return[Z.Options,Z.BalanceSheet,Z.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 ch(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=eG(this.fields),e.splits=this.splits,e.padded=this.padded,e}}var cc=R("c15IW");function cd(e,t){let i=e.query?.duplicate();if(!eH(i)||i.symbol===tG.PLACEHOLDER_SYMBOL_NAME||"Standard"!==i.getBuilderKey())return new uX;{0!==i.barsToFetch&&(i.barsToFetch=i.barsToFetch*tG.SERVER_COMPUTED_STUDY_BAR_MULTIPLIER);let e=t(i);return e.serverComputedSeries=!0,e}}function cp(e){return new ac(e,z.Number,j.Study,e)}class cf{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=e0(),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){eY(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 tG.EMPTY_ARRAY}get hasData(){return null!==this.container}get source(){if(eH(this._source))return this._source;let e=eH(this.inputs)?this.inputs[tG.INPUT_SOURCE]:null;return eH(e)?af[e]:null}set source(e){this._source=e}async ready(){return tW.call(this,async()=>{this.basisChangedToken=this.useNotifications?e(cc).subscribe(am.TS_ALL,this.onBasisChanged.bind(this)):null;let t={tag:e0(),src:null},i=(await Promise.all(this.innerSeries.map(e=>e.ready()))).every(ed);return i&&this.calculate(t),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onBasisChanged(e,t){if(e===am.TS_EVENTSCHANGED||e===am.TS_LOADING||this.innerSeries.some(e=>!e.hasData)||!this.shouldTriggerOurRecalc(t.series)||null===this.base||this===t.series)return;let i={tag:e0(),src:t.series};switch(e){case am.TS_MANYCHANGED:this.calculate(i);break;case am.TS_DATAPOINTCHANGED:case am.TS_DATAPOINTADDED:{let s=this.innerSeries[this.baseIndex].calculable?this.base.size-1:t.index;this.recalculateAt(i,s,e===am.TS_DATAPOINTADDED);break}case am.TS_TIMELINECORRECTION:case am.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.useNotifications&&this.basisChangedToken&&e(cc).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){eR(e,{series:this,index:t})}calculateCommon(e,t=null,i=-1,s=!0){let r=-1===i,n=r?t=>{(eH(e.src)||!eH(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&&(eH(e.src)||this.initialNotification)&&this.notify(t,i)}calculate(e){this.calculateCommon(e,am.TS_MANYCHANGED,-1,!0)}recalculateAt(e,t,i){this.computedServerSide||(!i&&eV(this.container)&&t>this.container.size-1&&(t=this.container.size-1),this.calculateCommon(e,i?am.TS_DATAPOINTADDED:am.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 eH(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(af.DateTime,af.Symbol)}makeContainer(){let e=this.defaultWrappers.concat(this.getWrappers());return new l8(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 cm extends cf{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 cg extends cm{constructor(e,t){super(e,t),this.query=t.query,this.useNotifications=!0}calculateAt(e){let[t,i,s,r]=[af.Open,af.High,af.Low,af.Close].map(t=>this.baseVal(t,e),this),n=null,a=null,o=null,l=null,u=em([t,i,s,r]);if(e<1)n=em([t,r]),a=i,o=s,l=0;else{let[t,r]=[af.Open,af.Close].map(t=>this.container.getData(t)[e-1],this);a=Math.max(i,n=em([t,r]),u),o=Math.min(s,n,u),l=u-r}return{[af.Open.id]:n,[af.High.id]:a,[af.Low.id]:o,[af.Close.id]:u,[af.Change.id]:l}}getWrappers(){return this.wrapBaseFields(af.Volume,af.OpenInterest,af.TradingDay)}}class cy extends cf{constructor(e,t){super(e,t),f$(this)}calculateAt(e){let t=null,i=this.period,[,s]=fG(this);if(this.atLeast(e,i)&&s.hasField(this.source)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=em(r.filter(ep)):eg(r)&&(t=em(r))}return{[this.target.id]:t}}getWrappers(){return this.source===af.Volume?this.wrapBaseFields(af.Volume,af.TradeSize,af.Change,af.Open,af.Close):[]}}class cS extends cf{multiplier;constructor(e,t,i){super(e,t),this.multiplier=i(this.period),f$(this)}calculateAt(e){let t=null,[i,s]=fG(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=em(r.filter(ep)):eg(r)&&(t=em(r))}}}return{[this.target.id]:t}}}class cT extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=af.OpenInterest;return this.base.hasField(i)&&(t=this.baseVal(i,e)),{[i.id]:t}}}let cA={inField:af.MA,outFields:[af.ENVU,af.ENVD],func:fP},cv={inField:af.EMA,outFields:[af.ENVEXPU,af.ENVEXPD],func:fC},cb={inField:af.SMA,outFields:[af.ENVSMOU,af.ENVSMOD],func:fE};class cP extends cf{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 cC extends cf{constructor(e,t){super(e,t);let i=fP(t,this.inputs.Period1,this.source),s=fP(t,this.inputs.Period2,this.source),r=fk(this.target,(e,t,i)=>t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(this.target,1)]}}let cE={fields:[af.MACD,af.MACDS,af.MACDH],avgFunc:fP,mapFunc:fW,histogramVaryColor:!0},c_={fields:[af.MACD,af.MACDS,af.MACDH],avgFunc:fC,mapFunc:fW,histogramVaryColor:!0},cL={fields:[af.MACD,af.CTLTM,af.CTM],avgFunc:fC,mapFunc:fW,histogramVaryColor:!1},cM={fields:[af.MACD,af.CTLTMF,af.CPMI],avgFunc:fC,mapFunc:fW,histogramVaryColor:!1},cx={fields:[af.PPO,af.PPOS,af.PPOH],avgFunc:fC,mapFunc:fU,histogramVaryColor:!0},cI={fields:[af.PVO,af.PVOS,af.PVOH],avgFunc:fC,mapFunc:fU,histogramVaryColor:!1};class cD extends cf{histogramVaryColor=!1;histogramField;get helpers(){return[af.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(eH(i,s)){let r=i<=0;t=r?1:3,e>0&&(r&&i>s&&(t=0),!r&&i<s&&(t=2))}}return{[af.BARCOLIX.id]:t}}}class cO extends cD{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=fk(this.fields[0],t.mapFunc,s,r),a=t.avgFunc(n,e.inputs.Period3,n.target,this.fields[1]),o=fk(this.fields[2],fW,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 cw=cp("_AVG_GAIN"),cR=cp("_AVG_LOSS");class cN extends cf{constructor(e,t,i){super(e,i);let s=fN(i,this.inputs.Period,this.source,af.RSI,t),r=fK(e,"MA","Average")(s,this.inputs.PeriodAvg,af.RSI,af.RSIAVG);this.addInner(s,r)}getWrappers(){return[this.wrapInner(af.RSI,1),this.wrapInner(af.RSIAVG,2)]}}class cV extends cf{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);eg(s)&&(t=this.highest?Math.max(...s):Math.min(...s),this.index&&(t=i-s.indexOf(t)-1))}return{[this.target.id]:t}}}class cH extends cf{toHighest;field;highField;lowField;constructor(e,t,i){super(e,i),this.toHighest=t;let s=eH(e.source),r=e.source,n=s?r:af.Close;this.field=n;let a=s?r:af.High;this.highField=a;let o=s?r:af.Low;this.lowField=o;let l=fM(i,e.inputs.Period,this.highField,af.HH,!0),u=fM(i,e.inputs.Period,this.lowField,af.LL,!1);this.addInner(l,u)}calculateAt(e){let t=null,i=this.baseVal(this.field,e),s=this.innVal(1,af.HH,e),r=this.innVal(2,af.LL,e);if(eg([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 cF=cp("RawPercK");class cB extends cf{kField;constructor(e,t,i,s){super(e,s);let r=fx(s,this.inputs.Period1,t?cF:i,!1),n=fK(e,"MA"),a=n(r,this.inputs.Period2,r.target,t?i:af.PercD),o=t?n(a,this.inputs.Period3,a.target,af.PercD):a;this.kField=i,t?this.addInner(a,o):this.addInner(r,a)}getWrappers(){return[this.wrapInner(this.kField,1),this.wrapInner(af.PercD,2)]}}function ck(e,t,i,s,r){if(null===r)return null;let n=e*r,a=s+n,o=s-n;switch(t){case af.BOLLBU:return a;case af.BOLLBL:return o;case af.BOLLBW:return(a-o)/s*100;default:return null}}class cW extends cf{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=this.inputs.Period,r=this.source,n=fP(i,s,r,af.BOLLBM),a="Modified"===t,o=fH(a?function(e,t,i=af.PCTCHG){return fA("PCTCHG",{source:t,target:i,inputs:fI},e)}(i,r):i,s,a?af.PCTCHG:r),l=this.inputs.Width,u=e=>eh(ck,l,e),h=fk(af.BOLLBU,u(af.BOLLBU),n,o),c=fk(af.BOLLBL,u(af.BOLLBL),n,o),d=fk(af.BOLLBW,u(af.BOLLBW),n,o),p=fK(e,"MA","Average")(d,this.inputs.PeriodAvg,af.BOLLBW,af.BOLLBWA);this.addInner(n,o,h,c,d,p)}calculateAt(e){let t=this.innVal(3,af.BOLLBU,e),i=this.innVal(4,af.BOLLBL,e),s=this.innVal(1,af.BOLLBM,e),r=this.innVal(5,af.BOLLBW,e),n=this.innVal(6,af.BOLLBWA,e),a=null;switch(eH(t,i)&&(a=(this.baseVal(af.Close,e)-i)/(t-i)),this.kind){case"Regular":return{[af.BOLLBU.id]:t,[af.BOLLBL.id]:i,[af.BOLLBM.id]:s};case"Width":return{[af.BOLLW.id]:t-i};case"Percent":return{[af.BOLLP.id]:a};case"BandWidth":return{[af.BOLLBW.id]:r,[af.BOLLBWA.id]:n};case"Modified":{let t=null,i=null,r=null,n=null,a=this.innVal(2,af.MSD,e);if(eH(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{[af.MBBUI.id]:t,[af.MBBLI.id]:r,[af.MBBUO.id]:i,[af.MBBLO.id]:n,[af.MBBM.id]:s}}default:return null}}}let cU=cp("_ABS_CHG"),c$=cp("_MA_ABS_CHG"),cG=cp("_CHG"),cz=cp("_PDM"),cY=cp("_MDM"),cj=cp("_TRS"),cK=cp("_PDS"),cq=cp("_MDS"),cX=cp("_DX");class cZ extends cf{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=fD(s,af.TR);this.addInner(r)}get helpers(){return[cz,cY,cj,cK,cq,cX]}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),eg(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,af.High),c=this.past(e,2,af.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(af.TR)[e];r=this.smooth1(e,cz,cK,t),n=this.smooth1(e,cY,cq,i),s=this.smooth1(e,af.TR,cj,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,cX,this.adxField,l))}return{[cz.id]:t,[cY.id]:i,[cj.id]:s,[cK.id]:r,[cq.id]:n,[af.PDI.id]:a,[af.MDI.id]:o,[cX.id]:l,[this.adxField.id]:u}}getWrappers(){return[this.wrapInner(af.TR,1)]}}class cJ extends cf{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 eH(s)||(s=t.container.hasField(af.Close)?af.Close:t.container.fields[0]),this.innVal(i,s,e)}),i=null;return eg(t)&&(i=this.calculateAtFunc(e,...t)),{[this.target.id]:i}}}function cQ(e,t){let i=this.baseVal(af.High,t),s=this.baseVal(af.Low,t);return{[e.id]:(i+s)/2}}function c0(e,t){let i=this.baseVal(af.High,t),s=this.baseVal(af.Low,t);return{[e.id]:i-s}}class c1 extends cf{calculateAtFunc;constructor(e,t,i){super(e,i),this.calculateAtFunc=t}calculateAt(e){return this.calculateAtFunc.call(this,e)}}let c2=cp("_RANGE"),c3=cp("_MOV_RANGE"),c4={fields:[af.KCUP,af.KCLOW,af.KCMID],midSeries:e=>fw(e,af.TP),midTarget:af.TP,rangeSeries:e=>fB(c2,eu(c0,c2),e),rangeTarget:c2,func:"MA",useMultiplier:!1},c5={fields:[af.KBUP,af.KBLOW,af.KBMID],midSeries:e=>e,midTarget:af.Close,rangeSeries:e=>fD(e,af.TR),rangeTarget:af.TR,func:"EMA",useMultiplier:!0};class c6 extends cf{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=t.midSeries(i),r=fK(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,c3);this.addInner(n,a)}calculateAt(e){let t=this.innVal(1,this.kind.fields[2],e),i=this.innVal(2,c3,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 c7 extends cf{isWidth;constructor(e,t,i){super(e,i),this.isWidth=t;let s=fM(i,this.inputs.Period,af.High,af.DONUP,!0),r=fM(i,this.inputs.Period,af.Low,af.DONLOW,!1);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,af.DONUP,e),i=this.innVal(2,af.DONLOW,e),s=null===t&&null===i;return this.isWidth?{[af.DONW.id]:s?null:t-i}:{[af.DONMID.id]:s?null:(t+i)/2}}getWrappers(){return[this.wrapInner(af.DONUP,1),this.wrapInner(af.DONLOW,2)]}}let c8=cp("_HIND"),c9=cp("_LIND");class de extends cf{justWidth;constructor(e,t,i){super(e,i),this.justWidth=t,this.justWidth=t;let s=this.inputs.Period,r=fM(i,s,af.High,c8,!0,!0),n=fM(i,s,af.Low,c9,!1,!0);this.addInner(r,n)}calculateAt(e){let t=null,i=null,s=null,r=this.innVal(1,c8,e),n=this.innVal(2,c9,e);if(null!==r&&null!==n){let e=this.period;s=(t=(e-r)/e*100)-(i=(e-n)/e*100)}return this.justWidth?{[af.ARNOSC.id]:s}:{[af.ARNUP.id]:t,[af.ARNLOW.id]:i}}}let dt=cp("_MIDPOINT"),di=cp("_MIDPOINT");class ds extends cf{multiplyVol;constructor(e,t,i){super(e,i),this.multiplyVol=t}calculateAt(e){let[t,i,s,r]=[af.High,af.Low,af.Close,af.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 dr=cp("_RANGE"),dn=cp("_MATP");class da extends cf{isBull;constructor(e,t,i){super(e,i),this.isBull=t;let s=fC(i,this.inputs.Period,this.source);this.addInner(s)}calculateAt(e){let t=null,i=this.innVal(1,af.EMA,e);return null!==i&&(t=this.isBull?this.baseVal(af.High,e)-i:this.baseVal(af.Low,e)-i),{[this.isBull?af.ERBLPOW.id:af.ERBRPOW.id]:t}}}let dl=cp("_FORCE"),du=cp("_RANGE"),dh=cp("_EMA1"),dc=cp("_EMA2"),dd=cp("_RATIO"),dp={isNegative:!1,fields:[af.PVI,af.PVIEMA]},df={isNegative:!0,fields:[af.NVI,af.NVIEMA]};class dm extends cf{kind;constructor(e,t,i){super(e,i),this.kind=t;let s=fB(this.kind.fields[0],eu(function(e,t){let i=1e3;if(t>0){let s=[af.Close,af.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=fC(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 dg=cp("_LOGPC"),dy=cp("_SWING_INDEX"),dS=cp("_MIN_CLOSE"),dT=cp("_MAX_CLOSE"),dA=cp("_EP"),dv=cp("_AF"),db=cp("_POS"),dP=cp("_IDY"),dC=[0,0,0,1,1,1,5,5,2,1,1,0,50,50,0,1,1,1,5,0,0],dE=e=>Array(e).fill(0);function d_(e,t,i){let s=e[i-1];return 0===t&&(s=e[i]),t<0&&(s=e[i+1]),s}function dL(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 dM={1:{param:"cot",func:"parseCotLineChart",fields:[af.DateTime,af.COTLCCMSP,af.COTLCLGSP,af.COTLCSMSP]},2:{param:"cotadv",func:"parseDisaggregated",fields:[af.DateTime,af.COTDAGPRO,af.COTDAGSPD,af.COTDAGMNM,af.COTDAGOTH]},3:{param:"cotfin",func:"parseFinancialTradersReport",fields:[af.DateTime,af.COTFTRDLI,af.COTFTRASM,af.COTFTRLVF,af.COTFTROTH]}};class dx extends cf{wrappers;constructor(e,t,i){super(e,cd(i,e=>new dI(t,e))),this.computedServerSide=!0,this.initialNotification=!0,this.wrappers=dM[t].fields.slice(1).map(e=>this.wrapInner(e,0))}getWrappers(){return this.wrappers}}class dI extends uq{kind;constructor(e,t){super(t),this.kind=e}getRetriever(){return new dD(this.kind)}onStreamingUpdates(e){}}class dD extends uy{kind;constructor(e){super(),this.kind=e}addExtraParams(e){e[dM[this.kind].param]="y"}getParser(e){return new dO(e.symbol,e.aggregation,this.kind)}}class dO extends uf{kind;constructor(e,t,i){super(e,t,0),this.kind=i}makeContainer(){return new l6(dM[this.kind].fields)}getParseFunc(){return this.aggregation.isEndOfDay?this[dM[this.kind].func]:null}parseCotLineChart(e){this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.COTLCCMSP,parseInt(e[2])),this.container.addDataPoint(af.COTLCLGSP,parseInt(e[3])),this.container.addDataPoint(af.COTLCSMSP,parseInt(e[4]))}parseDisaggregated(e){this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.COTDAGPRO,parseInt(e[2])),this.container.addDataPoint(af.COTDAGSPD,parseInt(e[3])),this.container.addDataPoint(af.COTDAGMNM,parseInt(e[4])),this.container.addDataPoint(af.COTDAGOTH,parseInt(e[5]))}parseFinancialTradersReport(e){this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.COTFTRDLI,parseInt(e[2])),this.container.addDataPoint(af.COTFTRASM,parseInt(e[3])),this.container.addDataPoint(af.COTFTRLVF,parseInt(e[4])),this.container.addDataPoint(af.COTFTROTH,parseInt(e[5]))}}class dw extends dx{constructor(e,t){super(e,1,t)}}let dR={Day:[af.PreviousHigh,af.PreviousLow,af.PreviousClose],Week:[af.WeekPreviousHigh,af.WeekPreviousLow,af.WeekPreviousClose],Month:[af.MonthPreviousHigh,af.MonthPreviousLow,af.MonthPreviousClose]};class dN extends cf{disabled;record;streamingSubscription;constructor(e,t,i){if(super(e,i),this.disabled=!eH(i.query)||!eH(i.query.symbol),!this.disabled){let e=i.query.symbol;e.endsWith(".BZ")&&(e=e.slice(0,-3)),this.record=Sl().getRecordSource().getRecord(e),this.record.addFields(...t),this.streamingSubscription=this.getStreamingSubscription()}this.initialNotification=!0}getStreamingSubscription(){return Sl().getRecordSource().subject.pipe(ub(e=>{let t=aO(am.RT_QUOTE,this.record.symbol);return e.filter(t)}),oT(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}async ready(){return tW.call(this,async()=>eH(this.record)?await this.record.ready()&&await super.ready():await super.ready(),"asyncReadyWork2")}onStreamingUpdates(e){if(this.record){let e={tag:e0(),src:null};this.calculate(e)}}shutdown(){super.shutdown(),this.disabled||this.streamingSubscription.unsubscribe()}getValues(e){return dR[e].map(e=>this.record.getValue(e))}}class dV extends uq{constructor(e){super(e)}getRetriever(){return tm(this.query.symbol)?new dk:new dH}onStreamingUpdates(e){}}class dH extends uy{addExtraParams(e){e.impl="y"}getParser(e){return new dB(e.symbol,e.aggregation)}}function dF(){return new l6([af.DateTime,af.IMPVOL])}class dB extends uf{constructor(e,t){super(e,t)}makeContainer(){return dF()}getParseFunc(){return this.parseImpVol}parseImpVol(e){this.aggregation.isEndOfDay&&!(e.length<9)&&(this.container.addDataPoint(af.DateTime,this.parseDate(e[1])),this.container.addDataPoint(af.IMPVOL,parseFloat(e[8])))}}class dk extends uS{emptyContainer(e,t){return dF()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(af.DateTime,l0(e.date.substring(0,10)));let s=eV(e.impliedVolatility);i.addDataPoint(af.IMPVOL,s?100*e.impliedVolatility:null)}}let dW=cp("_ABS_CHG"),dU=cp("_DS1_EMA1"),d$=cp("_DS1_EMA2"),dG=cp("_DS2_EMA1"),dz=cp("_DS2_EMA2"),dY=cp("_DIFF"),dj=cp("_SUM"),dK=cp("_ABS_CHG"),dq=cp("_HH_LL"),dX=cp("_MULMA"),dZ=cp("_DIFF");class dJ extends cm{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=[af.Open,af.High,af.Low,af.Close],r=s.map(t=>i(t,e));if(eg(r)){let n=s.map(t=>i(t,e-1));if(eg(n)){let[i,s]=eL(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(af.Close)[e-1];t[4]=t[3]-i}}}}return{[af.Open.id]:t[0],[af.High.id]:t[1],[af.Low.id]:t[2],[af.Close.id]:t[3],[af.Change.id]:t[4]}}getWrappers(){return this.wrapBaseFields(af.Volume,af.OpenInterest,af.TradingDay)}}let dQ=cp("_DIST"),d0=cp("_EMA_DIST1"),d1=cp("_EMA_DIST2"),d2=cp("_DIFF"),d3=cp("_EMA_DIFF1"),d4=cp("_EMA_DIFF2"),d5=cp("_CHG"),d6=cp("_M1"),d7=cp("_M2");class d8 extends cf{constructor(e,t){super(e,t);let i=fB(d5,function(e){let t=af.Close,i=e>0?this.baseVal(t,e)-this.baseVal(t,e-1):0;return{[d5.id]:i}},t),s=fk(d6,(e,t)=>t>=0?t:0,i),r=fk(d7,(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,d6,this.innCont(1)),r=this.past(e,i,d7,this.innCont(2));if(eg(s)&&eg(r)){let e=ef(s),i=ef(r);t=this.perc(e-i,e+i)}}return{[af.CHDMOMOSC.id]:t}}}let d9=cp("_MAX"),pe=cp("_MIN"),pt=cp("_ISUPTREND"),pi=cp("_TRENDUP"),ps=cp("_TRENDDOWN"),pr=cp("_TREND"),pn=cp("_CUM_PRICE"),pa=cp("_CUM_VOL"),po=cp("_PER_CHG");class pl extends cf{constructor(e,t){super(e,t);let i=this.source,s=fB(i,eu(fz,i),t);this.addInner(s)}valueAt(e,t){return this.container.getData(e)[t]}dateAt(e){return this.container.getTimeData()[e]}}let pu=cp("_DIFF"),ph=[pu,af.Buy,af.Sell];function pc(e,t,i,s){let r=null,n=null,a=null;eH(i,s)&&(a=i-s);let o=t>0?e.getData(pu)[t-1]:null;return eH(a,o)&&(r=a>0&&o<=0?1:null,n=a<0&&o>=0?-1:null),{[pu.id]:a,[af.Buy.id]:r,[af.Sell.id]:n}}let pd=cp("_PVM"),pp=cp("_NVM");var cc=R("c15IW");function pf(e,t,i){return new pm(e,t,i)}class pm{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=nX(e),this.valueSymbols=this.exprSymbols.filter(e=>void 0===this.innerLookup[e]),this.onlyForTimeline=eA(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!eH(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 tW.call(this,async()=>{this.basisChangedToken=e(cc).subscribe(am.TS_ALL,this.onBasisChanged.bind(this)),this.quoteGroupToken=e(cc).subscribe(am.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(ed);return i&&this.calculate(),i})}shouldTriggerOurRecalc(e){return this.recalcTriggers.has(e)}onQuoteGroup(e,t){t.source===this.policy.valueProvider&&this.innerSeries.every(e=>eH(e.container))&&this.calculateCommon(am.TS_MANYCHANGED)}onBasisChanged(e,t){if(this.policy.recompute===F.Manual||e===am.TS_EVENTSCHANGED||e===am.TS_LOADING||!this.shouldTriggerOurRecalc(t.series)||this.innerSeries.some(e=>!eH(e.container)))return;let i=this.policy.mapper(t.series);if(!(e===am.TS_DATAPOINTCHANGED&&this.onlyForTimeline?.includes(i)))switch(this.policy.recompute===F.Everything?am.TS_MANYCHANGED:e){case am.TS_MANYCHANGED:this.calculate();break;case am.TS_DATAPOINTCHANGED:case am.TS_DATAPOINTADDED:this.recalculate(e===am.TS_DATAPOINTADDED);break;case am.TS_TIMELINECORRECTION:case am.TS_QUOTEMARKER:break;default:throw Error("Unknown time series message, likely forgot to handle it")}}shutdown(){this.basisChangedToken&&e(cc).unsubscribe(this.basisChangedToken),this.quoteGroupToken&&(e(cc).unsubscribe(this.quoteGroupToken),this.policy.valueProvider?.shutdown())}calculateAt(e){return e.isNull?null:this.sourceFields.map((t,i)=>t===af.Volume?ef(this.exprSymbols.map(t=>e.inn[t].values[i]??0)):nj(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===af.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];eH(s,r)&&e.setLastDataPoint(af.Change,r-s)}calculateDataPoint(e,t){let i=this.calculateAt(e);if(null===i)return;e.atLeastOne=!0;let[s,r]=eL(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(af.Change,null),this.container.addDataPoint(af.DateTime,new Date(e.timeStamp))),this.calculateLastChange()}notify(e){eR(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,af.DateTime)}timeline(e){return e.container.getData(af.DateTime)}getRangeHelper(){switch(this.policy.missing){case H.UseNext:case H.UseNone:return Math.min;case H.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=>eP(this.timeline(this.innerLookup[e]))))),end:new Date(e(...this.symbols.map(e=>eb(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 H.UseNext:case H.UseNone:return i.findIndex(e=>e.valueOf()>=t.valueOf());case H.UsePrevious:return eC(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=>!eH(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===H.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===B.IgnoreTimelineOnly&&this.onlyForTimeline.includes(e)||this.policy.noDataApproach===B.ModelTransformRequired)}get symbols(){let e=Object.keys(this.innerLookup);return eH(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(;eH(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===H.UsePrevious?this.getInner(e).forEach(t=>{let i=eH(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===H.UseNone&&this.getInner(e).forEach(t=>this.fillPosSymbolAt(t,t.index,e))))}shouldAdd(e){return this.container.getLastDataPoint(af.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||(Si(e,"error"),this.crashedComputationReported=!0)}}calculate(){let{yes:e,no:t}=eS(this.innerSeries,e=>!e.container.isEmpty);if(t.length>0&&this.policy.noDataApproach===B.ModelTransformRequired){let i=e=>e.map(this.policy.mapper),s=this.policy.modelTransform(i(e),i(t));null!==s&&(this.exprModel=s)}this.calculateCommon(am.TS_MANYCHANGED)}recalculate(e){if(this.isExprInError)return;let t=this.getLastPos(),i=this.shouldAdd(t);this.calculateCommon(i?am.TS_DATAPOINTADDED:am.TS_DATAPOINTCHANGED,t,i)}recalculateAt(e,t,i){return this.recalculate(i)}makeContainer(){return new l6([af.DateTime,af.Change].concat(this.targetFields))}getCacheableEntities(e){this.innerSeries.forEach(t=>{t.getCacheableEntities(e)})}}let pg=cp("_AVG"),py=cp("_HAO"),pS=cp("_HAH"),pT=cp("_HAL"),pA=cp("_HAC"),pv=cp("_DELTA"),pb=cp("_DIFF"),pP=cp("_RANK"),pC=cp("_CHG"),pE=cp("_AVG"),p_=cp("_HBRAKE_CHG"),pL=cp("_HEIGHT_DELTA"),pM=cp("_ACTION"),px=cp("_REVERSAL"),pI=e=>[e>0,e<0],pD=[null,null,null];function pO([e,t],i){let s=null;if(i>0){let t=this.baseVal(e,i-1);eH(t)&&(s=this.baseVal(e,i)-t)}return{[t.id]:s}}class pw extends cf{useHandbrake;constructor(e,t){super(e,t);let i=fK(e,"MA","Average"),s=i(t,e1(1,999,this.inputs.FastPeriod),af.Close),r=e1(0,999,this.inputs.SlowPeriod),n=r>0,a=n?i(t,r,af.Close):t,o=fk(pb,n?(e,t,i)=>t-i:(e,t,i)=>i-t,s,a),l=fB(pC,eu(pO,[af.Close,pC]),t),u=fB(pP,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--,{[pP.id]:i}},o),h=e1(0,999,this.inputs.HandbrakePeriod);this.useHandbrake=h>0;let c=i(t,h,af.Close,pE),d=fB(p_,eu(pO,[pE,p_]),c);this.addInner(l,o,u,d)}get helpers(){return[pL,af.BARCOLIX,pM,px]}getStateAt(e){let t=this.innVal(2,pb,e);return eH(t)?pI(t):pD}findPreviousKnownState(e){for(let t=e-1;t>0;t--){let e=this.getStateAt(t);if(e===pD)break;let[i,s]=e;if(i||s)return e}return pD}getBuySell(e){let t=this.getStateAt(e);if(t===pD)return pD;let[i,s]=t,r=this.findPreviousKnownState(e),[n,a]=r;if(!i&&!s)return r===pD?pD:[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]=[px,pM].map(t=>this.getPrev(t,e)),[c,d]=[0,-1].map(t=>this.innVal(4,p_,e+t));if(r=l?10:this.innVal(3,pP,e),this.useHandbrake&&eH(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,pP,e),n=2):(r=i?11:13,n=1))}if(eH(this.innVal(2,pb,e))){let t=this.innVal(1,pC,e),[i,r]=pI(t),n=Math.abs(t);(a&&i||o&&r)&&(s=n),(a&&r||o&&i)&&(s=-n)}return a?t=1:o&&(i=1),{[af.JPIB.id]:t,[af.JPIS.id]:i,[af.BARCOLIX.id]:r,[pL.id]:s,[pM.id]:n,[px.id]:l}}}let pR={FastPeriod:8,SlowPeriod:21,HandbrakePeriod:13,Average:"EMA",Height:"Fixed"},pN=cp("_SMTH_ROC"),pV=cp("_TEN_SMTH_ROC");function pH(e,t,i,s,r){return new cS({source:s,target:r,outFields:[r],aggregation:i,inputs:fS(t)},e,e=>2/e)}let pF=cp("_VOL_AVG"),pB=131,pk=(()=>{let e=eF(.9865008210958766,6),t=eM(52,t=>Math.pow(e,t)),i=52/ef(t);return t.map(e=>e*i)})(),pW=["Renko","Kagi","PointAndFigure","LineBreak"];function pU(e){return e===G.Continue||e===G.Nearest}class p$ extends cf{additionalChunksCounter=1;noData=!1;isPeriodic=!1;constructor(e,t,i){super(e,i,cd(i,e=>{if(!sF(es[Sl()?.config.mode??"Unspecified"]))return i;let t=e.duplicate(),s=e.aggregation;if(s.hasSpec)if(pU(s.spec))return i;else return new uX(t,!0);let r=s.unit===$.Intraday&&s.size<=5,n=function(e,t){switch(e){case $.Intraday:if(t>=240)return 3;if(t>=120)return 2;return 1;case $.Day:default:return 5;case $.Week:return 15;case $.Month:return 60;case $.Quarter:case $.Year:return 240}}(s.unit,s.size);return t.aggregation=r?new nD($.Tick,s.size,G.PerSeconds):new nD($.Intraday,n),t.barsToFetch=Math.min(tG.MAX_INTRADAY_BARS,(r?1:3)*e.barsToFetch),new uq(t)})),this.isPeriodic=t,this.noData=this.innerSeries[1]instanceof uX,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?am.TS_DATAPOINTADDED:am.TS_DATAPOINTCHANGED;this.notify(s,this.innerSeries[0].container.size-1)}getWrappers(){return[this.wrapInner(af.Change,1),this.wrapInner(af.Open,1),this.wrapInner(af.Close,1)]}}let pG=cp("_EMA1"),pz=cp("_EMA2"),pY=cp("_MACD"),pj=cp("_PCTK"),pK=cp("_PCTD"),pq=cp("_PCTK2"),pX=cp("_EMA1"),pZ=cp("_EMA2"),pJ=cp("_CORE");class pQ extends cf{isEmpty=!1;constructor(e,t){if(super(e,t),fJ(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=fB(af.Close,(e,t)=>null,t),i=fB(af.Close,(e,t)=>null,t),s=fB(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,Sl().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 p0=cp("_INN_HL_ACC_IX"),p1=new nD;class p2 extends cf{isWeekly=!1;constructor(e,t){if(super(e,t),t instanceof uX)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===$.Week,this.isWeekly){var i;let e=(i=this.getSeries(t.query,s,p1),new p2({aggregation:p1,source:null,target:p0,outFields:[p0],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*tG.US_TRADING_DAYS_PER_YEAR),Sl().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,af.Close);eg(s)&&(t=ef(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(p0);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(p0)[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 p3=cp("_RSI1"),p4=cp("_RSI1_MOM"),p5=cp("_RSI2"),p6=cp("_RSI2_MA"),p7=cp("_MUL_ATR");class p8 extends cf{constructor(e,t){super(e,cd(t,t=>{let i=Sl().getTimeSeriesDataSource();return t.seriesKind=Z.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 p9=cp("_CORE");class fe extends uq{constructor(e){super(e)}getRetriever(){return tm(this.query.symbol)?new fs:tv(this.query.symbol)?new fr:new fi}}function ft(){return new l6([af.DateTime,af.Delta,af.Gamma,af.Theta,af.Vega])}class fi{supportsChunks;constructor(){this.supportsChunks=!1}async retrieve(e){return ft()}}class fs extends uS{emptyContainer(e,t){return ft()}get iterateForward(){return!1}getPageName(){return"getFuturesOptionsHistory"}processRow(e,t,i){i.addDataPoint(af.DateTime,l0(e.date.substring(0,10))),i.addDataPoint(af.Delta,e.delta),i.addDataPoint(af.Gamma,e.gamma),i.addDataPoint(af.Theta,e.theta),i.addDataPoint(af.Vega,e.vega)}}class fr extends uS{emptyContainer(e,t){return ft()}addExtraParams(e){e.fields="delta,gamma,theta,vega"}get iterateForward(){return!0}getPageName(){return"getEquityOptionsHistory"}processRow(e,t,i){i.addDataPoint(af.DateTime,l0(e.date)),i.addDataPoint(af.Delta,e.delta),i.addDataPoint(af.Gamma,e.gamma),i.addDataPoint(af.Theta,e.theta),i.addDataPoint(af.Vega,e.vega)}}let fn=cp("_RSI1"),fa=cp("_RSI2"),fo=cp("_ANCHR"),fl=cp("_HH_N"),fu=cp("_LL_N"),fh=cp("_HH_H1"),fc=cp("_LL_H1"),fd=cp("_HH_H2"),fp=cp("_LL_H2"),ff=cp("_MIDPOINT"),fm=cp("_VALUE");class fg extends cf{constructor(e,t){super(e,t),f$(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]=fG(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{[af.RCI.id]:t}}}let fy={_TR:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null,i=this.baseVal(af.High,e),s=this.baseVal(af.Low,e);if(e>0){let r=this.baseVal(af.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 cf{isModified;constructor(e,t){super(e,t);let i=e.inputs.Modified;this.isModified=i}get helpers(){return[cw,cR]}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(eg(t)){let e=ey(1,r),n=e.map(e=>this.gain(e,t)),a=e.map(e=>this.loss(e,t));i=em(n),s=em(a)}}else{let t=this.container.getData(cw)[e-1],n=this.container.getData(cR)[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{[cw.id]:i,[cR.id]:s,[this.target.id]:t}}},MA:cy,MAEXP:class extends cS{constructor(e,t){super(e,t,e=>2/(e+1))}},MAHLC:class extends cf{constructor(e,t){super(e,t);let i=fP(t,this.inputs.Period1,af.High,af.MAHI),s=fP(t,this.inputs.Period2,af.Low,af.MALO);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.MAHI,1),this.wrapInner(af.MALO,2)]}},VOL:class extends cT{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(af.Volume,af.TradeSize,af.Change,af.Open,af.Close)}},MAENV:class extends cP{constructor(e,t){super(e,cA,t)}},MAENVEXP:class extends cP{constructor(e,t){super(e,cv,t)}},MAENVSMO:class extends cP{constructor(e,t){super(e,cb,t)}},MATRI:class extends cf{constructor(e,t){super(e,t);let i=fP(t,this.inputs.Period,this.source),s=fP(i,this.inputs.Period,af.MA,af.TMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.TMA,2)]}},MAWEI:class extends cf{triangle;constructor(e,t){super(e,t);let i=this.period;this.triangle=i*(i+1)/2,f$(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]=fG(this);if(this.atLeast(e,i)){let r=this.past(e,i,this.source,s);this.allowEmptyValues?t=this.weightedAverage(r.filter(ep)):eg(r)&&(t=this.weightedAverage(r))}return{[this.target.id]:t}}},MAVOL:cy,MASMO:class extends cS{constructor(e,t){super(e,t,e=>1/e)}},MACD:class extends cO{constructor(e,t){super(e,cE,t)}},MACDEXP:class extends cO{constructor(e,t){super(e,c_,t)}},MACDV:class extends cD{constructor(e,t){super(e,t),this.histogramVaryColor=!0,this.histogramField=af.MACDVH;let i=fK(e,"EMA","Average"),s=i(t,e.inputs.Period1,e.source,void 0),r=i(t,e.inputs.Period2,e.source,void 0),n=fO(t,e.inputs.Period2,e.inputs.Average),a=fk(af.MACDV,(e,t,i,s)=>(t-i)/s*100,s,r,n),o=i(a,e.inputs.Period3,a.target,af.MACDVS),l=fk(af.MACDVH,fW,a,o);this.addInner(a,o,l)}getWrappers(){return[this.wrapInner(af.MACDV,1),this.wrapInner(af.MACDVS,2),this.wrapInner(af.MACDVH,3)]}},GMMA:class extends cf{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(fC(t,n,af.Close,e.outFields[r-1]))}}getWrappers(){return ey(1,12).map(e=>this.wrapInner(this.outFields[e-1],e))}},OSCI:cC,OSCIVOL:cC,RSI:class extends cN{constructor(e,t){super(e,!1,t)}},RSIMOD:class extends cN{constructor(e,t){super(e,!0,t)}},RSISTO:class extends cf{constructor(e,t){super(e,t);let i=fN(t,this.inputs.Period,this.source),s=this.inputs.Range,r=fB(af.STORSI,function(e){let t=null;if(this.atLeast(e,s)){let i=this.past(e,s,af.RSI,this.base),r=eL(i),n=r[0],a=r[1];t=(eb(i)-n)/(a-n)}return{[af.STORSI.id]:t}},i),n=fK(e,"MA","Average")(r,this.inputs.PeriodAvg,af.STORSI,af.STORSIAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(af.STORSI,1),this.wrapInner(af.STORSIAVG,2)]}},RSA:class extends cf{constructor(e,t){super(e,t);let i=fN(t,this.inputs.Period1,this.source,fn),s=fN(t,this.inputs.Period2,this.source,fa),r=fk(af.RSA,(e,t,i)=>(t+i)/2,i,s),n=fK(e,"MA","Average")(r,this.inputs.PeriodAvg,af.RSA,af.RSAAVG);this.addInner(r,n)}getWrappers(){return[this.wrapInner(af.RSA,1),this.wrapInner(af.RSAAVG,2)]}},WPERCR:class extends cH{constructor(e,t){super(e,!0,t)}},HHLL:class extends cf{constructor(e,t){super(e,t);let i=fM(t,this.inputs.Period1,af.High,af.HH,!0),s=fM(t,this.inputs.Period2,af.Low,af.LL,!1);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.HH,1),this.wrapInner(af.LL,2)]}},WGCL:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null,[i,s,r]=[af.Close,af.High,af.Low].map(t=>this.baseVal(t,e));return t=(2*i+s+r)/4,{[this.target.id]:t}}},STOCHF:class extends cB{constructor(e,t){super(e,!1,af.PercK,t)}},STOCHS:class extends cB{constructor(e,t){super(e,!0,af.PercK,t)}},BBANDS:class extends cW{constructor(e,t){super(e,"Regular",t)}},BWIDTH:class extends cW{constructor(e,t){super(e,"Width",t)}},BPERC:class extends cW{constructor(e,t){super(e,"Percent",t)}},OBVOL:class extends cf{constructor(e,t){super(e,t);let i=fB(af.OBVOL,function(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Volume,e),r=this.baseVal(af.Close,e-1),n=this.container.getData(this.target)[e-1];eH(n)||(n=0),t=i>r?n+s:i<r?n-s:n}return{[this.target.id]:t}},t),s=fK(e,"MA","Average")(i,this.period,af.OBVOL,af.OBVOLAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.OBVOL,1),this.wrapInner(af.OBVOLAVG,2)]}},ATR:class extends cf{constructor(e,t){super(e,t);let i=fD(t,af.TR),s=fK(e,"SMA")(i,this.inputs.Period,af.TR,this.target),r=fP(s,this.inputs.Period2,af.ATR,af.ATRMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(this.target,1),this.wrapInner(af.ATRMA,2)]}},ATRP:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period,e.inputs.Smoothing);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(1,af.ATR,e),s=this.baseVal(af.Close,e);return eH(i,s)&&s>0&&(t=i/s*100),{[af.ATRP.id]:t}}},ADX:class extends cZ{constructor(e,t){super(e,!1,af.ADX,t)}},ADXMOD:class extends cZ{constructor(e,t){super(e,!0,af.ADXM,t)}},ADL:class extends cf{constructor(e,t){super(e,t);let i=fV(t);this.addInner(i)}calculateAt(e){let t=null;return t=(e>0?this.container.getData(this.target)[e-1]:0)+this.innVal(1,af.MFMUL,e),{[this.target.id]:t}}},ADWM:class extends cf{constructor(e,t){super(e,t);let i=fB(af.ADWM,function(e){let t=null,i=null;if(e>0){let s=this.baseVal(af.Close,e-1),r=Math.max(s,this.baseVal(af.High,e)),n=Math.min(s,this.baseVal(af.Low,e)),a=this.baseVal(af.Close,e);t=a>s?a-n:a<s?a-r:0,e>1&&(i=(e>2?this.container.getData(af.ADWM)[e-1]:0)+t)}return{[af.ADWM.id]:i}},t),s=fP(i,this.inputs.Period,af.ADWM,af.ADWMMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.ADWM,1),this.wrapInner(af.ADWMMA,2)]}},CHAOSC:class extends cf{constructor(e,t){super(e,t);let i=af.ADL,s=function(e,t=af.ADL){return fA("ADL",fT(t),e)}(t,i),r=fC(s,3,i),n=fC(s,10,i),a=fk(e.target,(e,t,i)=>t-i,r,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},TP:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null;return t=em([af.Close,af.High,af.Low].map(t=>this.baseVal(t,e))),{[this.target.id]:t}}},KELCHN:class extends c6{constructor(e,t){super(e,c4,t)}},KELBND:class extends c6{constructor(e,t){super(e,c5,t)}},DONCHN:class extends c7{constructor(e,t){super(e,!1,t)}},DONWIDTH:class extends c7{constructor(e,t){super(e,!0,t)}},PVT:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Volume,e),r=this.baseVal(af.Close,e-1),n=this.container.getData(this.target)[e-1];eH(n)||(n=0),t=n+(i-r)/r*s}return{[this.target.id]:t}}},ROC:class extends cf{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 cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,this.source),s=fC(i,this.inputs.Period,i.target),r=fC(s,this.inputs.Period,s.target),n=fR(r,1,r.target,this.target);this.addInner(n)}getWrappers(){return[this.wrapInner(this.target,1)]}},PPMOV:class extends cf{constructor(e,t){super(e,t);let i=fw(t,af.PVPT);this.addInner(i)}calculateAt(e){let t=this.innVal(1,af.PVPT,e),i=this.baseVal(af.High,e),s=this.baseVal(af.Low,e);return{[af.PVPTR.id]:t+i-s,[af.PVPTS.id]:t-i+s}}getWrappers(){return[this.wrapInner(af.PVPT,1)]}},PIVPTS:class extends dN{constructor(e,t){super(e,dR[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(eg(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{[af.PPTPIV.id]:t,[af.PPTR1.id]:i,[af.PPTR2.id]:r,[af.PPTR3.id]:a,[af.PPTS1.id]:s,[af.PPTS2.id]:n,[af.PPTS3.id]:o}}},CPP:class extends dN{constructor(e,t){super(e,dR.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(eg(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{[af.CPPH4.id]:o,[af.CPPH3.id]:n,[af.CPPH2.id]:s,[af.CPPH1.id]:t,[af.CPPL1.id]:i,[af.CPPL2.id]:r,[af.CPPL3.id]:a,[af.CPPL4.id]:l}}},ARNUPDW:class extends de{constructor(e,t){super(e,!1,t)}},ARNOSC:class extends de{constructor(e,t){super(e,!0,t)}},TCHN:class extends cf{constructor(e,t){super(e,t);let i="Close"===e.inputs.Range,s=fZ(t);if(!i&&s){let e=fB(af.TCHNUP,(e,t)=>null,t),i=fB(af.TCHNLOW,(e,t)=>null,t);this.addInner(e,i)}else{let s=fM(t,e.inputs.PeriodUpper,i?af.Close:af.High,af.TCHNUP,!0),r=fM(t,e.inputs.PeriodLower,i?af.Close:af.Low,af.TCHNLOW,!1);this.addInner(s,r)}}getWrappers(){return[this.wrapInner(af.TCHNUP,1),this.wrapInner(af.TCHNLOW,2)]}},TCHRE:class extends cf{constructor(e,t){super(e,t);let i=function(e,t,i){let s="TCHN",r=fv(s);return fA(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,af.TCHNUP,e),s=this.innVal(1,af.TCHNLOW,e),r=this.inputs.Adjustment,n=this.inputs.Retracement;return"Long"===n?t=eH(i)?i-r:null:"Short"===n&&(t=eH(s)?s+r:null),{[this.target.id]:t}}},ALLG:class extends cf{constructor(e,t){super(e,t);let i=fB(dt,eu(cQ,dt),t),s=fE(i,e.inputs.Period1,dt,af.ALJAW),r=fE(i,e.inputs.Period2,dt,af.ALTEETH),n=fE(i,e.inputs.Period3,dt,af.ALLIPS);this.addInner(s,r,n)}calculateAt(e){return{[af.ALJAW.id]:this.innVal(1,af.ALJAW,e),[af.ALTEETH.id]:this.innVal(2,af.ALTEETH,e),[af.ALLIPS.id]:this.innVal(3,af.ALLIPS,e)}}},PLTLN:class extends cf{constructor(e,t){super(e,t)}calculateAt(e){return{[af.PLTLN.id]:this.inputs.Position}}},AWEOSC:class extends cf{constructor(e,t){super(e,t);let i=fB(di,eu(cQ,di),t),s=fP(i,this.inputs.Period1,di),r=fP(i,this.inputs.Period2,di),n=fk(af.AWOS,(e,t,i)=>t-i,s,r),a=fP(n,this.inputs.Period3,n.target,af.AWOSMA);this.addInner(n,a)}getWrappers(){return[this.wrapInner(af.AWOS,1),this.wrapInner(af.AWOSMA,2)]}},MFV:class extends ds{constructor(e,t){super(e,!0,t)}},CLV:class extends ds{constructor(e,t){super(e,!1,t)}},CHAMF:class extends cf{constructor(e,t){super(e,t);let i=fV(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,af.Volume),r=this.past(e,i,af.MFMUL,this.innCont(1));if(eg(s)&&eg(r)){let e=ef(s);0!==e&&(t=ef(r)/e)}}return{[this.target.id]:t}}},CHAVOL:class extends cf{constructor(e,t){super(e,t);let i=fR(fC(fB(dr,eu(c0,dr),t),this.inputs.Period1,dr),this.inputs.Period2,af.EMA,this.target);this.addInner(i)}getWrappers(){return[this.wrapInner(this.target,1)]}},DPO:class extends cf{shift;constructor(e,t){super(e,t);let i=this.inputs.Period;this.shift=Math.floor(i/2)+1;let s=fP(t,i,e.source);this.addInner(s)}calculateAt(e){let t=null,i=this.shift,s=this.innVal(1,af.MA,e-i);return null!==s&&(t=this.baseVal(this.source,e)-s),{[this.target.id]:t}}},CCI:class extends cf{constructor(e,t){super(e,t);let i=fw(t),s=fP(i,this.inputs.Period,i.target,dn);this.addInner(i,s)}calculateAt(e){let t=null,i=this.period;if(this.atLeast(e,i)){let s=this.past(e,i,af.TP,this.innCont(1));if(eg(s)){let i=this.innVal(2,dn,e);if(null!==i){let r=s.reduce((e,t,s)=>e+Math.abs(i-t),0)/this.period;t=(this.innVal(1,af.TP,e)-i)/(.015*r)}}}return{[this.target.id]:t}}},EMV:class extends cf{constructor(e,t){super(e,t);let i=fB(af.EMV,function(e){let t=null;if(e>0){let[i,s,r]=[af.High,af.Low,af.Volume].map(t=>this.baseVal(t,e)),[n,a]=[af.High,af.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=fP(i,this.inputs.Period,af.EMV,af.EMVMA);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.EMV,1),this.wrapInner(af.EMVMA,2)]}},ERBRPOW:class extends da{constructor(e,t){super(e,!1,t)}},ERBLPOW:class extends da{constructor(e,t){super(e,!0,t)}},FI:class extends cf{constructor(e,t){super(e,t);let i=fC(fB(dl,function(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Volume,e);t=(i-this.baseVal(af.Close,e-1))*s}return{[this.target.id]:t}},t),this.inputs.Period,dl,af.FI);this.addInner(i)}getWrappers(){return[this.wrapInner(af.FI,1)]}},MI:class extends cf{constructor(e,t){super(e,t);let i=fC(fB(du,eu(c0,du),t),9,du,dh),s=fC(i,9,dh,dc),r=fk(dd,(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,dd,this.innCont(1));eg(i)&&(t=ef(i))}return{[this.target.id]:t}}},MOM:class extends cf{constructor(e,t){super(e,t);let i=this.inputs.Period,s=fB(af.MOM,eh(fY,i,af.Close),t),r=fP(s,this.inputs.Movement,af.MOM,af.MOMMA);this.addInner(s,r)}getWrappers(){return[this.wrapInner(af.MOM,1),this.wrapInner(af.MOMMA,2)]}},MFI:class extends cf{constructor(e,t){super(e,t);let i=fw(t);this.addInner(i)}calculateAt(e){let t=null,i=this.period+1;if(this.atLeast(e,i)){let s=this.past(e,i,af.TP,this.innCont(1)),r=this.past(e,i,af.Volume).map(e=>null!=e?e:0);if(eg(s)&&eg(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 cf{constructor(e,t){super(e,t),f$(this);let i=fP(t,this.inputs.Period,this.source);this.addInner(i)}calculateAt(e){let t=null,[i,s]=fG(this),r=this.innVal(i+1,af.MA,e);if(null!==r){let i=this.inputs.Period,n=this.past(e,i,this.source,s);t=Math.sqrt(em(n=n.map(e=>(e-r)*(e-r))))}return{[this.target.id]:t}}getWrappers(){let[e]=fG(this);return[this.wrapInner(af.MA,e+1)]}},NVI:class extends dm{constructor(e,t){super(e,df,t)}},PVI:class extends dm{constructor(e,t){super(e,dp,t)}},PPO:class extends cO{constructor(e,t){super(e,cx,t)}},PVO:class extends cO{constructor(e,t){super(e,cI,t)}},HV:class extends cf{constructor(e,t){super(e,t);let i=Math.sqrt(fX(e.aggregation));if(0===i){let e=fB(this.target,(e,t)=>null,t);this.addInner(e)}else{let s=fH(fB(dg,eu(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{[dg.id]:i}},af.Close),t),e.inputs.Period,dg,af.MSD),r=fB(af.HV,eu(function(e,t){let i=null,s=this.baseVal(af.MSD,t);return null!==s&&(i=100*s*e),{[af.HV.id]:i}},i),s);this.addInner(r)}}getWrappers(){return[this.wrapInner(this.target,1)]}},PERF:class extends cf{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 cf{constructor(e,t){super(e,t)}get helpers(){return[dy]}ohlcVals(e){return[af.Open,af.High,af.Low,af.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(dy)[e-1];eH(s)||(s=0);let[r,n,a,o]=this.ohlcVals(e),[l,u,h,c]=this.ohlcVals(e-1);if(eg([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{[dy.id]:t,[this.target.id]:i}}},WWVOL:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period);this.addInner(i)}get helpers(){return[dT,dS]}calculateAt(e){let t=null,i=null,s=null,r=null,n=this.innVal(1,af.ATR,e);if(null!==n){let a=this.baseVal(af.Close,e),o=this.baseVal(af.Close,e-1),l=this.period;s=Math.max(...this.past(e,l,af.Close)),r=Math.min(...this.past(e,l,af.Close));let u=n*this.inputs.Constant;if(null===this.innVal(1,af.ATR,e-1))a>o?t=s-u:i=r+u;else{let[n,o,l,h]=[af.WWVSARU,af.WWVSARD,dT,dS].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{[dT.id]:s,[dS.id]:r,[af.WWVSARU.id]:t,[af.WWVSARD.id]:i}}},PARTP:class extends cf{constructor(e,t){super(e,t)}get helpers(){return[dA,dv,db]}hlcVals(e){return[af.High,af.Low,af.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,af.PARSARS,af.PARSARL,dA,dv].map(t=>this.me(t,e-1)),S=1===u,T=S?m:d,A=y*Math.abs(g-T),v=u===(n=S?T+A>l?-1:1:T-A<o?1:-1);a=v?S?Math.min(T+A,c,this.baseVal(af.Low,e-2)):Math.max(T-A,h,this.baseVal(af.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{[dA.id]:s,[dv.id]:r,[db.id]:n,[af.PARSARS.id]:i,[af.PARSARL.id]:t}}},MOVLR:class extends cf{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(eg(s)){let e=ef(s),r=(i*ef(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 cf{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);dC.splice(6,3,...i)}get helpers(){return[dP]}prepareComputation(){let e=this.base.getData(af.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=dE(s),this.itr=dE(s),this.haveEnoughData&&dL(e,this.s3,s)}us(e,t){return this.container.getData(e)[t]}recalculateAt(e,t,i){let s=this.base.getData(af.Close),r=s.length;this.haveEnoughData&&dL(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(af.Close,e)){let n=r(af.TRSP1),a=r(af.TRSP2);s=r(dP),null===n&&null===a&&(n=a=this.baseVal(af.Close,this.firstUsefulIndex)),null===s&&(s=1);let o=this.base.getData(af.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=d_(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,dC),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*d_(r,i[s],4)}(o,this.s3,this.itr,e,dC);[n,a]=function(e,t,i,s,r,n,a,o,l,u){let h=d_(r,i[s],10),c=d_(r,i[s],13),d=d_(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),T=[n,a];return(1===o||1!==d||y>n)&&(T[0]=y),(1===o||1!==d||S<a)&&(T[1]=S),T}(o,this.s3,this.itr,e,dC,n,a,s,l,u),this.itr[e]>=0&&(t=n),this.itr[e]<=0&&(i=a)}return{[dP.id]:s,[af.TRSP1.id]:t,[af.TRSP2.id]:i}}},COTLC:dw,COTDAG:class extends dx{constructor(e,t){super(e,2,t)}},COTFTR:class extends dx{constructor(e,t){super(e,3,t)}},IMPVOL:class extends cf{constructor(e,t){super(e,cd(t,e=>new dV(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(af.IMPVOL,0)]}},CTM:class extends cO{constructor(e,t){e.inputs={Period1:5,Period2:21,Period3:34},super(e,cL,t)}},CPMI:class extends cO{constructor(e,t){e.inputs={Period1:3,Period2:5,Period3:8},super(e,cM,t)}},DEMA:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,this.source),s=fC(i,this.inputs.Period,i.target),r=fk(af.DEMA,(e,t,i)=>2*t-i,i,s);this.addInner(r)}getWrappers(){return[this.wrapInner(af.DEMA,1)]}},TEMA:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,this.source),s=fC(i,this.inputs.Period,i.target),r=fC(s,this.inputs.Period,s.target),n=fk(af.TEMA,(e,t,i,s)=>3*(t-i)+s,i,s,r);this.addInner(n)}getWrappers(){return[this.wrapInner(af.TEMA,1)]}},TSI:class extends cf{constructor(e,t){super(e,t);let i=(e,t,i,s,r,n)=>{let a=fC(e,t,i,s);return fC(a,r,s,n)},s=fB(dW,eu((e,t)=>({[e.id]:Math.abs(this.baseVal(af.Change,t))}),dW),t),r=i(t,e.inputs.Period1,af.Change,dU,e.inputs.Period2,d$),n=i(s,e.inputs.Period1,dW,dG,e.inputs.Period2,dz),a=fk(af.TSI,(e,t,i)=>100*t/i,r,n),o=fC(a,e.inputs.Period3,af.TSI,af.TSISIG);this.addInner(a,o)}getWrappers(){return[this.wrapInner(af.TSI,1),this.wrapInner(af.TSISIG,2)]}},ADJATR:class extends cf{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)),{[cU.id]:Math.abs(i)}},s=fB(cU,eu(i,this.source),t),r=fK(e,"MA")(s,this.inputs.Period,cU,c$),n=fk(af.ADJATR,(e,t)=>2*t,r);this.addInner(n)}getWrappers(){return[this.wrapInner(af.ADJATR,1)]}},COTR:class extends cf{constructor(e,t){super(e,t);let i=e=>{let t=0;return e>0&&(t=this.baseVal(af.Close,e)-this.baseVal(af.Close,e-1)),{[cG.id]:t}},s=fB(cG,i,t),r=fq[e.inputs.TypeOfATR.toLowerCase()],n=r(t,this.inputs.Period,this.inputs.Smoothing),a=fk(this.target,(e,t,i)=>eH(t)&&eH(i)?t/i:null,s,n);this.addInner(a)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCGD:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.Period,af.Close);this.addInner(i)}calculateAt(e){let t=null,i=e>0?this.container.getData(this.target)[e-1]:null,s=this.innVal(1,af.EMA,e);if(eV(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 cf{constructor(e,t){super(e,t);let i=this.inputs.Period,s=Math.floor(i/2),r=this.allowEmptyValues,n=f_(t,s,this.source,af.WMA,r),a=fk(dY,(e,t,i)=>2*t-i,n,f_(t,i,this.source,af.WMA,r)),o=f_(a,Math.floor(Math.sqrt(i)),dY,this.target,r);this.addInner(o)}getWrappers(){return[this.wrapInner(this.target,1)]}},COPP:class extends cf{constructor(e,t){super(e,t);let i=fR(t,this.inputs.PeriodRocLong),s=f_(fk(dj,(e,t,i)=>t+i,i,fR(t,this.inputs.PeriodRocShort)),this.inputs.PeriodWma,dj,this.target);this.addInner(s)}getWrappers(){return[this.wrapInner(this.target,1)]}},REATRS:class extends cf{constructor(e,t){super(e,t);let i="Close"===e.inputs.TurtleChnField,s="Long"===e.inputs.Direction,r=fZ(t);if(!i&&r){let e=fB(this.target,(e,t)=>null,t);this.addInner(e)}else{let e=(e,t)=>({[dK.id]:t>0?e*Math.abs(this.baseVal(af.Change,t)):null}),r=fP(fB(dK,eu(e,this.inputs.FactorATR),t),this.inputs.PeriodAdjATR,dK,af.MA),n=s?af.High:af.Low,a=fM(t,this.inputs.PeriodTurtleChn,i?af.Close:n,dq,s),o=fk(dX,(e,t)=>this.inputs.FactorAdjATR*t,r),l=s?-1:1,u=fk(this.target,(e,t,i)=>t+l*i,a,o);this.addInner(u)}}getWrappers(){return[this.wrapInner(this.target,1)]}},LINRCHN:class extends cf{constructor(e,t){super(e,t);let i=this.inputs.Period,s=fB(af.LINRMID,eu(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(af.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{[af.LINRMID.id]:i}},i),t),r=fH(fk(dZ,(e,t,i)=>t-i,fB(this.source,function(e){return{[this.target.id]:this.baseVal(this.target,e)}},t),s),i,dZ);this.addInner(s,r)}calculateAt(e){let t=this.innVal(1,af.LINRMID,e),i=eb(this.innCont(2).getData(af.MSD)),s=null,r=null;if(eH(t,i)){let e=this.inputs.Width;s=t+e*i,r=t-e*i}return{[af.LINRUP.id]:s,[af.LINRLOW.id]:r}}getWrappers(){return[this.wrapInner(af.LINRMID,1)]}},CSHO:class extends cf{computeDone;constructor(e,t){super(e,t,cd(t,e=>{var t,i;let s=eG(e);return s.symbol=tg(t=e.symbol)?`${tg(i=t)?tc(i).root:null}Y00`:null,eH(s.symbol)?new uq(s):new uX(s,!0)})),this.computedServerSide=!0,this.initialNotification=!0,this.computeDone=!1}alignCashTimelineWithUnderlying(){let e=this.innCont(0);if(!eH(e)||0===e.size)return;let t=this.innCont(1),i=e.getTimeData(),s=t.getTimeData(),r=t.getData(af.Close),n=Array(i.length).fill(null);if(!(this.innerSeries[1]instanceof uX)){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(am.TS_MANYCHANGED,-1))}},CSHB:class extends cf{constructor(e,t){super(e,t,function(e,t=af.CSHO){return fA("CSHO",fT(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)=>eH(this.innCont(t))?this.innVal(t,i,e):null,i=t(0,af.Close),s=t(1,af.CSHO);return{[this.target.id]:eH(s)&&eH(i)?s-i:null}}},CTPI:class extends cB{constructor(e,t){e.inputs={Period1:5,Period2:3,Period3:3},super(e,!0,af.CTPI,t)}},PCTCHG:class extends cf{constructor(e,t){super(e,t),f$(this)}calculateAt(e){let t=null,[i]=fG(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 cT{constructor(e,t){super(e,t)}getWrappers(){return this.wrapBaseFields(af.TradeSize,af.Change)}},STOMOMIX:class extends cf{constructor(e,t){super(e,t);let i=fM(t,e.inputs.Period1,af.High,af.HH,!0),s=fM(t,e.inputs.Period1,af.Low,af.LL,!1),r=fC(fk(dQ,(e,t,i)=>this.baseVal(af.Close,e)-(t+i)/2,i,s),e.inputs.Period2,dQ,d0),n=fC(r,e.inputs.Period2,d0,d1),a=fC(fk(d2,(e,t,i)=>t-i,i,s),e.inputs.Period2,d2,d3),o=fC(a,e.inputs.Period2,d3,d4),l=fk(af.STOMOMIX,(e,t,i)=>100*t/i,n,o);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},CHDMOMOSC:class extends cf{constructor(e,t){super(e,t);let i=new d8(e,t),s=fK(e,"MA","Average")(i,this.inputs.PeriodAvg,af.CHDMOMOSC,af.CHDMOMOSCAVG);this.addInner(i,s)}getWrappers(){return[this.wrapInner(af.CHDMOMOSC,1),this.wrapInner(af.CHDMOMOSCAVG,2)]}},VSTOP:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period);this.addInner(i)}get helpers(){return[d9,pe,pt]}calculateAt(e){let t=null,i=null,s=null,r=null,n=null,a=null,o=1,l=this.baseVal(af.Close,e),u=e=>eH(e)?e:0,h=(e,t)=>this.container.getData(e)[t];e>0&&(s=Math.max(u(h(d9,e-1)),l),n=Math.min(u(h(pe,e-1)),l),o=h(pt,e-1));let c=this.inputs.Multiplier,d=this.innVal(1,af.ATR,e);if(eH(d)){let u=1===o,p=u?s-c*d:n+c*d,f=h(u?af.VSTOPUP:af.VSTOPLOW,e-1);eH(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{[af.VSTOPUP.id]:1===a?t:null,[af.VSTOPLOW.id]:1===a?null:t,[d9.id]:i,[pe.id]:r,[pt.id]:a}}},SUPTR:class extends cf{constructor(e,t){super(e,t);let i=fO(t,e.inputs.Period);this.addInner(i)}get helpers(){return[pi,ps,pr,af.BARCOLIX]}calculateAt(e){let t=0,i=0,s=0,r=null,n=0,a=this.innVal(1,af.ATR,e);if(eH(a)){let[o,l,u]=[af.Close,af.High,af.Low].map(t=>this.baseVal(t,e)),h=(l+u)/2,c=this.baseVal(af.Close,e-1),d=this.inputs.Multiplier,p=h-d*a,f=h+d*a,[m,g,y]=[pi,ps,pr].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:eH(y)?y:1);r=S?t:i,n=+!!S}return{[pi.id]:t,[ps.id]:i,[pr.id]:s,[af.SUPTR.id]:r,[af.BARCOLIX.id]:n}}},ICHCLD:class extends cf{constructor(e,t){super(e,t);let i=(e,t,i)=>fk(i,(e,t,i)=>(t+i)/2,e,t),s=(e,s)=>i(fM(t,e,af.Low,af.LL,!1),fM(t,e,af.High,af.HH,!0),s),r=s(e.inputs.PeriodConversionLine,af.CONVLN),n=s(e.inputs.PeriodBaseLine,af.BASELN),a=i(r,n,af.LEADSP1),o=s(e.inputs.PeriodLaggingSpan2,af.LEADSP2);this.addInner(r,n,a,o)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=+(this.innVal(3,af.LEADSP1,e)>this.innVal(4,af.LEADSP2,e));return{[af.LAGGSP.id]:this.baseVal(af.Close,e),[af.BARCOLIX.id]:t}}getWrappers(){return[this.wrapInner(af.CONVLN,1),this.wrapInner(af.BASELN,2),this.wrapInner(af.LEADSP1,3),this.wrapInner(af.LEADSP2,4)]}},VWAP:class extends pl{constructor(e,t){super(e,t)}get helpers(){return[pn,pa,po]}isSame(e,t){switch(this.inputs.AnchorPeriod){case"Session":default:return ng(e,t);case"Week":return nb(e,t);case"Month":return ny(e,t);case"Quarter":return nT(e,t);case"Year":return nP(e,t);case"Decade":return lJ(10,e)===lJ(10,t);case"Century":return lJ(100,e)===lJ(10,t)}}findPrevPeriodChange(e){for(let t=e;t>0;t--)if(1===this.valueAt(po,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):tG.ZERO_DATE,l=this.dateAt(e),u=a&&this.isSame(o,l),h=u?this.valueAt(pn,e-1):0,c=u?this.valueAt(pa,e-1):0,d=this.innVal(0,af.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(af.VWAP).slice(a,e);o.push(t);let l=em(o),u=Math.sqrt(em(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{[pn.id]:p,[pa.id]:f,[po.id]:+!u,[af.VWAP.id]:t,[af.VWAPSD1U.id]:i,[af.VWAPSD1L.id]:s,[af.VWAPSD2U.id]:r,[af.VWAPSD2L.id]:n}}},MACROSS:class extends cf{constructor(e,t){super(e,t);let i=fK(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,af.MAS),r=i(t,e.inputs.Period2,this.source,af.MAL);this.addInner(s,r)}get helpers(){return ph}calculateAt(e){let t=this.innVal(1,af.MAS,e),i=this.innVal(2,af.MAL,e);return pc(this.container,e,t,i)}getWrappers(){return[this.wrapInner(af.MAS,1),this.wrapInner(af.MAL,2)]}},PACROSS:class extends cf{_maIndex;_maTarget;constructor(e,t){super(e,t),f$(this);let i=fK(e,"MA","Average")(t,e.inputs.Period,this.source);this.addInner(i);let[s]=fG(this);this._maIndex=s+1,this._maTarget=i.target}get helpers(){return ph}calculateAt(e){let t=this.innVal(this._maIndex,this._maTarget,e),[,i]=fG(this),s=i.getData(this.source)[e],r=pc(this.container,e,s,t);return r[this.target.id]=t,r}},VOIN:class extends cf{constructor(e,t){super(e,t);let i=fB(pd,function(e){return{[pd.id]:e>0?Math.abs(this.baseVal(af.High,e)-this.baseVal(af.Low,e-1)):null}},t),s=fB(pp,function(e){return{[pp.id]:e>0?Math.abs(this.baseVal(af.Low,e)-this.baseVal(af.High,e-1)):null}},t),r=fD(t,af.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,pd,this.innCont(1)),n=this.past(e,s,pp,this.innCont(2)),a=this.past(e,s,af.TR,this.innCont(3));if(eg(r)&&eg(n)&&eg(a)){let e=ef(r),s=ef(n),o=ef(a);t=e/o,i=s/o}}return{[af.PLVI.id]:t,[af.MNVI.id]:i}}},DIFA:class extends cf{isPercent;constructor(e,t){super(e,t);let i=fK(e,"MA","Average")(t,this.period,this.source,pg);this.isPercent="Percentage"===e.inputs.Distance,this.addInner(i)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=null,i=null,s=this.innVal(1,pg,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,[af.BARCOLIX.id]:i}}},DOSC:class extends cf{constructor(e,t){super(e,t);let i=fC(fN(t,this.inputs.PeriodRsi,this.source,af.RSI),this.inputs.PeriodEma1,af.RSI,af.EMA),s=fC(i,this.inputs.PeriodEma2,af.EMA,af.EMA),r=fP(s,this.inputs.PeriodMa,af.EMA,af.MA),n=fk(af.DOSCH,(e,t,i)=>t-i,s,r),a=fP(n,this.inputs.PeriodSig,af.DOSCH,af.DOSCS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(af.DOSCH,1),this.wrapInner(af.DOSCS,2)]}},BBANDW:class extends cW{constructor(e,t){super(e,"BandWidth",t)}},MARIB:class extends cf{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=fP(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 cf{constructor(e,t){super(e,t);let i=fK(e,"EMA","Smoothing1"),s=e.inputs.Period1,r=i(t,s,af.Open),n=i(t,s,af.High),a=i(t,s,af.Low),o=i(t,s,af.Close),l=fk(pA,(e,t,i,s,r)=>(t+i+s+r)/4,r,n,a,o),u=fk(py,function(e,t,i,s){let r=null;if(e>0){let s=this.container.getData(py)[e-1],n=this.innVal(2,pA,e-1);eH(s,n)?r=(s+n)/2:eH(t,i)&&(r=(t+i)/2)}return r},r,o,l),h=fk(pS,(e,t,i,s)=>eH(t,i,s)?Math.max(t,Math.max(i,s)):null,n,u,l),c=fk(pT,(e,t,i,s)=>eH(t,i,s)?Math.min(t,Math.min(i,s)):null,a,u,l),d=fK(e,"EMA","Smoothing2"),p=e.inputs.Period2,f=d(u,p,py,af.Open),m=d(h,p,pS,af.High),g=d(c,p,pT,af.Low),y=d(l,p,pA,af.Close),S=fB(af.Change,function(e){let t=null;if(e>0){let i=this.baseVal(af.Close,e),s=this.baseVal(af.Close,e-1);eH(i,s)?t=i-s:eH(i)&&!eH(s)&&(t=0)}return{[af.Change.id]:t}},y);this.addInner(f,m,g,y,S)}getWrappers(){return[this.wrapInner(af.Open,1),this.wrapInner(af.High,2),this.wrapInner(af.Low,3),this.wrapInner(af.Close,4),this.wrapInner(af.Change,5)]}},TTMSQZ:class extends cf{constructor(e,t){super(e,t);let i=e.inputs,s=fC(t,i.PeriodEmaKeltner,af.Close),r=fO(t,i.PeriodAtrKeltner);function n(e,t,i,s){return eH(i,s)?i+e*s:null}let a=i.MultiplierKeltner,o=fk(af.KCUP,eu(n,a),s,r),l=fk(af.KCLOW,eu(n,-a),s,r),u=function(e,t,i,s=af.Close){let r="BBANDS",n=fv(r);return fA(r,{source:s,inputs:{[tG.INPUT_PERIOD]:t,[tG.INPUT_WIDTH]:i},outFields:n},e)}(t,i.PeriodBollinger,i.WidthBollinger),h=function(e,t){let i="DONCHN",s=fv(i);return fA(i,{inputs:fS(t),outFields:s,source:null},e)}(t,i.PeriodMomentum),c=fP(t,i.PeriodMomentum,af.Close),d=fF(fk(pv,function(e,t,i,s){let r=null,n=this.innVal(1,af.DONMID,e);return eH(n,s)&&(r=t-(n+s)/2),r},t,h,c),i.PeriodMomentum,pv,af.TTMSQZOSC);this.addInner(o,l,u,d)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=null,i=null,s=-1,r=this.innVal(1,af.KCUP,e),n=this.innVal(2,af.KCLOW,e),[a,o]=[af.BOLLBU,af.BOLLBL].map(t=>this.innVal(3,t,e));a<r&&o>n?t=0:i=0;let l=this.innVal(4,af.TTMSQZOSC,e),u=e>0?this.innVal(4,af.TTMSQZOSC,e-1):null;if(eH(l))if(eH(u)){let e=l>=0,t=u<l;s=e?t?3:2:+!!t}else s=2;return{[af.TTMSQZON.id]:t,[af.TTMSQZOFF.id]:i,[af.BARCOLIX.id]:s}}getWrappers(){return[this.wrapInner(af.TTMSQZOSC,4)]}},CRS:class extends cf{constructor(e,t){if(super(e,t),fJ(t)){let i=Sl().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.inputs.Symbol.toUpperCase();let r=i.getTimeSeries(s),n=e=>e.query?.symbol,{model:a}=nY(`{${n(t)}} / {${n(r)}}`,!1),o=new pm(a,[t,r],(e=>{let t=e.unit===$.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:F.Manual,missing:t?H.UseNext:H.UsePrevious,stretch:e=>!1,fieldMap:new Map([[af.Close,af.CRS]]),noDataApproach:B.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation)),l=fK(e,"MA","Average")(o,this.period,af.CRS,af.CRSAVG);this.addInner(r,o,l),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=fB(af.Close,(e,t)=>null,t),i=fB(af.CRS,(e,t)=>null,t),s=fB(af.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(af.CRS,2),this.wrapInner(af.CRSAVG,3)]}},JPI:pw,CTTP:class extends pw{constructor(e,t){e.inputs=ej(sw("JPI").defaults.inputs.filter(e=>"HandbrakePeriod"!==e.name)),super(e,t)}},CTTI:class extends pw{constructor(e,t){e.inputs=structuredClone(pR),super(e,t)}},DRS:class extends cf{get indexSymbol(){return this.inputs[tG.INPUT_SYMBOL]}constructor(e,t){if(super(e,t),fJ(t)){let i=Sl().getTimeSeriesDataSource(),s=t.query.duplicate();s.symbol=this.indexSymbol;let r=i.getTimeSeries(s),{model:n}=nY(`{${t.query.symbol}} / {${r.query.symbol}} * 100`,!1),a=new pm(n,[t,r],(e=>{let t=e.unit===$.Month;return{mapper:e=>e.query.symbol,loadMoreData:!1,recompute:F.Manual,missing:t?H.UseNext:H.UsePrevious,stretch:e=>!1,fieldMap:new Map([[af.Close,af.DRS]]),noDataApproach:B.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1}})(e.aggregation));this.addInner(r,a),this.canLoadMoreData=!0,this.initialNotification=!0}else{let e=fB(af.Close,(e,t)=>null,t),i=fB(af.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(af.DRS,2)]}},MRS:class extends cf{get indexSymbol(){return this.inputs[tG.INPUT_SYMBOL]}constructor(e,t){super(e,t);let i=function(e,t,i,s=af.DRS){return fA("DRS",{target:s,inputs:{[tG.INPUT_SYMBOL]:t},aggregation:i,source:null},e)}(t,this.indexSymbol,e.aggregation),s=fP(i,this.period,af.DRS);this.addInner(i,s),this.canLoadMoreData=!0,this.initialNotification=!0}calculateAt(e){let t=this.innVal(1,af.DRS,e),i=this.innVal(2,af.MA,e),s=null;return eH(t,i)&&0!==i&&(s=(t/i-1)*100),{[af.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 cf{constructor(e,t){super(e,t);let i=fR(t,1),s=e.aggregation,r=fk(pV,(e,t)=>10*t,pH(i,this.inputs.Period1,s,af.ROC,pN)),n=pH(r,this.inputs.Period2,s,pV,af.PMO),a=fC(n,this.inputs.Period3,af.PMO,af.PMOS);this.addInner(n,a)}getWrappers(){return[this.wrapInner(af.PMO,1),this.wrapInner(af.PMOS,2)]}},RVOL:class extends cf{constructor(e,t){super(e,t);let i=fK(e,"MA")(t,this.period,af.Volume,pF,!0);this.addInner(i)}calculateAt(e){let t=null,i=this.innVal(0,af.Volume,e),s=this.innVal(1,pF,e);return eH(i,s)&&0!==s&&(t=i/s),{[this.target.id]:t}}},WGALPH:class extends cf{isDaily;isFeasible=!0;constructor(e,t){super(e,t),this.isFeasible=!(t instanceof uX)&&!pW.includes(U[t.query.curveStyle]),this.isDaily=e.aggregation.unit===$.Day}acceptable(e,t,i,s){return this.isDaily?0===s||!nb(this.baseVal(af.DateTime,t),this.baseVal(af.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>=pB){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*pk[e]+1}t=100*(i-1)}return{[this.target.id]:t}}},VOLAP:class extends p${constructor(e,t){super(e,!1,t)}},AVWAP:class extends pl{constructor(e,t){super(e,t)}get helpers(){return[pn,pa]}isSameOhlcBar(e,t){let{unit:i,size:s}=this.aggregation;switch(i){case $.Tick:return e===t;case $.Intraday:return as(t,l$(e,s));case $.Day:return as(t,lF(e,s));case $.Week:return nb(e,t);case $.Month:return ny(e,t);case $.Quarter:return nT(e,t);case $.Year:return nP(e,t);default:throw Error(`Unexpected aggregation unit ${$[i]}`)}}calculateAt(e){let t=null,i=null,s=null,r=this.inputs.Anchor,n=this.dateAt(e);if(as(r,n)||this.isSameOhlcBar(n,r)){let r=e>0,n=r?this.valueAt(pn,e-1):0,a=r?this.valueAt(pa,e-1):0,o=this.innVal(0,af.Volume,e);t=(i=n+this.innVal(1,this.source,e)*o)/(s=a+o)}return{[pn.id]:i,[pa.id]:s,[af.AVWAP.id]:t}}},KST:class extends cf{constructor(e,t){super(e,t);let i=this.source,s=fB(i,eu(fz,i),t),r=fR(s,this.inputs.PeriodRoc1,i),n=fR(s,this.inputs.PeriodRoc2,i),a=fR(s,this.inputs.PeriodRoc3,i),o=fR(s,this.inputs.PeriodRoc4,i),l=fP(r,this.inputs.PeriodMa1,af.ROC,af.MA1),u=fP(n,this.inputs.PeriodMa2,af.ROC,af.MA2),h=fP(a,this.inputs.PeriodMa3,af.ROC,af.MA3),c=fP(o,this.inputs.PeriodMa4,af.ROC,af.MA4),d=fk(af.KST,(e,t,i,s,r)=>t+2*i+3*s+4*r,l,u,h,c),p=fP(d,this.inputs.PeriodSig,af.KST,af.KSTSIG);this.addInner(d,p)}getWrappers(){return[this.wrapInner(af.KST,1),this.wrapInner(af.KSTSIG,2)]}},STC:class extends cf{constructor(e,t){super(e,t);let i=fC(t,this.inputs.PeriodShort,af.Close,pG),s=fk(pY,(e,t,i)=>t-i,i,fC(t,this.inputs.PeriodLong,af.Close,pz)),r=this.inputs.PeriodStoch1,n=this.inputs.PeriodStoch2,a=fK(e,"EMA"),o=a(fx(s,r,pj,!1,pY),n,pj,pK),l=a(fx(o,r,pq,!1,pK),n,pq,this.target);this.addInner(l)}getWrappers(){return[this.wrapInner(this.target,1)]}},MCCLO:class extends pQ{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=(e,t,i)=>t-i,r=fk(pJ,"Yes"===this.inputs.RatioAdjusted?(e,t,i)=>(t-i)/(t+i)*1e3:s,t,i),n=fC(r,this.inputs.Period1,pJ,pX),a=fC(r,this.inputs.Period2,pJ,pZ);return fk(this.target,s,n,a)}},NHLAI:p2,CMBCI:class extends cf{constructor(e,t){super(e,t);let i=fN(t,this.inputs.Period1Rsi,af.Close,p3),s=fB(p4,eh(fY,this.inputs.Period1Mom,p3),i),r=fP(fN(t,this.inputs.Period2Rsi,af.Close,p5),this.inputs.Period2Ma,p5,p6),n=fk(af.CMBCI,(e,t,i)=>t+i,s,r),a=fP(n,this.inputs.PeriodFastMa,af.CMBCI,af.CMBCIF),o=fP(n,this.inputs.PeriodSlowMa,af.CMBCI,af.CMBCIS);this.addInner(n,a,o)}getWrappers(){return[this.wrapInner(af.CMBCI,1),this.wrapInner(af.CMBCIF,2),this.wrapInner(af.CMBCIS,3)]}},COTI:class extends cf{constructor(e,t){super(e,new dw({source:af.Close,inputs:{},outFields:fv("COTLC")},t));let i=Number.parseInt(this.inputs.History),s=fx(this.innerSeries[0],6===i?26:52*i,af.COTI,!1,af.COTLCCMSP);this.initialNotification=!0,this.computedServerSide=!0,this.addInner(s)}getWrappers(){return[this.wrapInner(af.COTI,1)]}},CHEXI:class extends cf{isLong;constructor(e,t){super(e,t),this.isLong="Long"===this.inputs.Direction;let i=this.period,s=fO(t,i),r=this.inputs.Multiplier,n=fk(p7,(e,t)=>null===t?null:r*t,s),a=fM(t,i,af.High,af.HH,!0),o=fM(t,i,af.Low,af.LL,!1);this.addInner(n,a,o)}calculateAt(e){let t=null,i=null,s=this.innVal(1,p7,e);return null!==s&&(this.isLong?t=this.innVal(2,af.HH,e)-s:i=this.innVal(3,af.LL,e)+s),{[af.CHEXL.id]:t,[af.CHEXS.id]:i}}},MBBANDS:class extends cW{constructor(e,t){super(e,"Modified",t)}},OPTIV:class extends p8{},IVRANK:class extends p8{},IVPCTL:class extends p8{},OPTVOLPC:class extends p8{},OPTOIPC:class extends p8{},OPTVOL:class extends p8{},OPTOI:class extends p8{},CHOP:class extends cf{constructor(e,t){super(e,t);let i=fO(t,1),s=this.inputs.Period,r=fM(t,s,af.High,af.HH,!0),n=fM(t,s,af.Low,af.LL,!1);this.addInner(i,r,n)}calculateAt(e){let t=null,i=this.period;if(e>i){let s=this.past(e,i,af.ATR,this.innCont(1));if(eg(s)){let r=ef(s),n=this.innVal(2,af.HH,e);t=100*Math.log10(r/(n-this.innVal(3,af.LL,e)))/Math.log10(i)}}return{[this.target.id]:t}}},MACLD:class extends cf{constructor(e,t){super(e,t);let i=fK(e,"MA","Average"),s=i(t,e.inputs.Period1,this.source,af.MACLD1),r=i(t,e.inputs.Period2,this.source,af.MACLD2);this.addInner(s,r)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=this.innVal(1,af.MACLD1,e),i=this.innVal(2,af.MACLD2,e);return{[af.BARCOLIX.id]:+(t>i)}}getWrappers(){return[this.wrapInner(af.MACLD1,1),this.wrapInner(af.MACLD2,2)]}},BTI:class extends pQ{constructor(e,t){super(e,t)}getTargetSeries(e,t,i){let s=fk(p9,(e,t,i)=>t/(t+i),t,i);return fK(e,"MA","Average")(s,this.inputs.Period,p9,this.target)}},FRAMA:class extends cf{constructor(e,t){super(e,t),f$(this);let i=e.inputs.Period,s=Math.floor(i/2),r=fM(t,i,af.High,fl,!0),n=fM(t,i,af.Low,fu,!1),a=fM(t,s,af.High,fh,!0),o=fM(t,s,af.Low,fc,!1),l=fM(t,s,af.High,fd,!0),u=fM(t,s,af.Low,fp,!1);this.addInner(r,n,a,o,l,u)}calculateAt(e){let t=this.period,i=Math.floor(t/2),[,s]=fG(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,fl,e),o=this.innVal(2+n,fu,e),l=this.innVal(3+n,fh,e),u=this.innVal(4+n,fc,e),h=this.innVal(5+n,fd,e-i),c=this.innVal(6+n,fp,e-i);if(!eH(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 cf{constructor(e,t){super(e,t);let i=e.inputs.Period,s=fB(ff,eu(cQ,ff),t),r=fM(s,i,ff,af.HH,!0),n=fM(s,i,ff,af.LL,!1);this.addInner(s,r,n)}get helpers(){return[fm]}calculateAt(e){let t=this.innVal(1,ff,e),i=this.innVal(2,af.HH,e),s=this.innVal(3,af.LL,e);if(!eH(i,s,t))return{[af.FISHER.id]:null,[af.FISHTRG.id]:null,[fm.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(fm):null)??0);a>.99?a=.999:a<-.99&&(a=-.999);let o=e>0?n(af.FISHER):null,l=.5*Math.log((1+a)/(1-a))+.5*(o??0);return{[af.FISHER.id]:l,[af.FISHTRG.id]:o,[fm.id]:a}}},PC:class extends cf{stdDevs;periodForecast;unitsPerYear;constructor(e,t){super(e,t),this.unitsPerYear=fX(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=af.Close,r=af.HV){return fA("HV",{source:s,target:r,aggregation:i,inputs:fS(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(af.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(af.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{[af.PCUP1.id]:t,[af.PCDN1.id]:i,[af.PCUP2.id]:s,[af.PCDN2.id]:r,[af.PCUP3.id]:n,[af.PCDN3.id]:a}}recalculateAt(e,t,i){let s={tag:e0(),src:this.innerSeries[0]};i&&this.calculate(s)}},GREEKS:class extends cf{constructor(e,t){super(e,cd(t,e=>new fe(e))),this.computedServerSide=!0,this.initialNotification=!0}getWrappers(){return[this.wrapInner(af.Delta,0),this.wrapInner(af.Gamma,0),this.wrapInner(af.Theta,0),this.wrapInner(af.Vega,0)]}},PVACP:class extends p${constructor(e,t){super(e,!0,t)}},TDI:class extends cf{constructor(e,t){super(e,t),f$(this);let i=e.inputs.PeriodRSI,s=e.inputs.PeriodTradeSignal,r=e.inputs.PeriodMarketBase,n=e.inputs.PeriodBB,[a]=fG(this),o=fN(this.innerSeries[a],i,this.source,af.TDIPRC),l=fP(o,s,af.TDIPRC,af.TDITSL),u=fP(o,r,af.TDIPRC,af.TDIMBL),h=fH(o,n,af.TDIPRC,af.MSD);this.addInner(o,l,u,h)}calculateAt(e){let t=this.inputs.MultiplierBB,i=+!!this.sourceNeedsCompute,s=this.innVal(1+i,af.TDIPRC,e),r=this.innVal(2+i,af.TDITSL,e),n=this.innVal(3+i,af.TDIMBL,e),a=this.innVal(4+i,af.MSD,e),o=null,l=null;if(eH(n,a)){let e=t*a;o=n+e,l=n-e}return{[af.TDIPRC.id]:s,[af.TDITSL.id]:r,[af.TDIMBL.id]:n,[af.TDIUPR.id]:o,[af.TDILWR.id]:l}}},PPS:class extends cf{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=af.Close;"Close"!==s&&(n=this.isLong?af.High:af.Low);let a=fM(t,i,n,fo,this.isLong);this.addInner(a)}get helpers(){return[af.BARCOLIX]}calculateAt(e){let t=null,i=this.innVal(1,fo,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{[af.PPS.id]:t,[af.BARCOLIX.id]:r}}},RCI:class extends cf{constructor(e,t){super(e,t);let i=new fg({source:this.source,target:af.RCI,inputs:{Period:e.inputs.Period}},t),s=e.inputs.PeriodSignal,r=fK(e,"MA","Smoothing")(i,s,af.RCI,af.RCISIG);this.addInner(i,r)}getWrappers(){return[this.wrapInner(af.RCI,1),this.wrapInner(af.RCISIG,2)]}}};function fS(e){return{[tG.INPUT_PERIOD]:e}}function fT(e){return{target:e,source:null,inputs:fI}}function fA(e,t,i){if(eU(fy,e))return new fy[e](t,i);let s=Sl()?.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 fv(e){return sw(e).defaults.curves.reduce((e,t)=>e.concat(t.fields.filter(t=>!e.includes(t))),[]).map(e=>af[e])}function fb(e,t,i,s){return{source:t,target:i,inputs:fS(e),allowEmptyValues:s}}function fP(e,t,i,s=af.MA,r=!1){return fA("MA",fb(t,i,s,r),e)}function fC(e,t,i,s=af.EMA,r=!1){return fA("MAEXP",fb(t,i,s,r),e)}function fE(e,t,i,s=af.SMA,r=!1){return fA("MASMO",fb(t,i,s,r),e)}function f_(e,t,i,s=af.WMA,r=!1){return fA("MAWEI",fb(t,i,s,r),e)}function fL(e,t,i,s=af.HMA,r=!1){return fA("HMA",fb(t,i,s,r),e)}function fM(e,t,i,s,r,n=!1){return new cV({source:i,target:s,inputs:fS(t)},r,n,e)}function fx(e,t,i,s,r=null){return new cH({source:r,target:i,inputs:fS(t)},s,e)}let fI={};function fD(e,t=af.TR){return fA("_TR",fT(t),e)}function fO(e,t,i="SMA",s=af.ATR){return fA("ATR",{target:s,inputs:{[tG.INPUT_PERIOD]:t,[tG.INPUT_SMOOTHING]:i},source:null},e)}function fw(e,t=af.TP){return fA("TP",fT(t),e)}function fR(e,t,i=af.Close,s=af.ROC){return fA("ROC",{source:i,target:s,inputs:fS(t)},e)}function fN(e,t,i,s=af.RSI,r=!1){return fA("_RSI",{source:i,target:s,inputs:{...fS(t),Modified:r}},e)}function fV(e,t=af.MFMUL){return fA("MFV",fT(t),e)}function fH(e,t,i,s=af.MSD){return fA("MSD",{source:i,target:s,inputs:fS(t)},e)}function fF(e,t,i,s=af.MOVLR){return fA("MOVLR",{source:i,inputs:fS(t),target:s},e)}function fB(e,t,i){return new c1(fT(e),t,i)}function fk(e,t,...i){return new cJ(fT(e),t,...i)}function fW(e,t,i){return t-i}function fU(e,t,i){return(t-i)/i*100}function f$(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=fB(t,eu(fz,t),e.innerSeries[0]);e.addInner(i)}}function fG(e){let t=+!!e.sourceNeedsCompute;return[t,e.innCont(t)]}let fz=function(e,t){let[i,s,r,n]=[af.Open,af.High,af.Low,af.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}},fY=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}},fj={sma:fE,ma:fP,ema:fC,wma:f_,hma:fL};function fK(e,t,i="Smoothing"){return fj[(e.inputs[i]??t).toLowerCase()]}let fq={atr:fO,adjatr:function(e,t,i="MA",s=af.Close,r=af.ADJATR){return fA("ADJATR",{source:s,target:r,inputs:{[tG.INPUT_PERIOD]:t,[tG.INPUT_SMOOTHING]:i}},e)}};function fX(e){switch(e.unit){case $.Day:return 252;case $.Week:return 52;case $.Month:return 12;default:return 0}}function fZ(e){let t=[af.High,af.Low];return e instanceof pm&&2!==ev(e.targetFields,t).length}function fJ(e){return!(e instanceof uX)&&e.query instanceof ch}class fQ extends cm{constructor(e,t){super(e,t,fC(t,13,af.Close),function(e,t,i,s,r=af.Close){return fA("MACDEXP",{source:r,inputs:{Period1:12,Period2:26,Period3:9},outFields:[af.MACD,af.MACDS,af.MACDH]},e)}(t,0,0,0,af.Close)),this.query=t.query,this.useNotifications=!0}calculateAt(e){let t=k.Same,i=this.innVal(1,af.EMA,e),s=this.innVal(1,af.EMA,e-1),r=this.innVal(2,af.MACDH,e),n=this.innVal(2,af.MACDH,e-1);return eH(i,s,r,n)&&(i>s&&r>n?t=k.Up:i<s&&r<n&&(t=k.Down)),{[af.BREL.id]:t}}getWrappers(){return this.wrapBaseFields(af.Open,af.High,af.Low,af.Close,af.Change,af.Volume,af.OpenInterest,af.TradingDay)}}function f0(e,t){return eH(t)?(this[e]=t,null):this[e]}class f1{_domain;_range;_extent;_padding;constructor(){this._domain=this._range=this._extent=null,this._padding=[0,0]}domain(e){return f0.call(this,"_domain",e)}range(e){return f0.call(this,"_range",e)}padding(e){return f0.call(this,"_padding",e)}get ready(){return eH(this._domain,this._range)}}let f2=1/Math.log2(10);function f3(e,t){let i,s,r,n,a=(i=e[0],(s=e[1]-i)>0?e=>(e-i)/s:e=>ed(isNaN(s)?NaN:.5)),o=(r=t[0],n=t[1],e=>r*(1-e)+n*e);return e=>o(a(e))}function f4(e){return Math.sign(e)*Math.log10(1+Math.abs(e/f2))}function f5(e){return Math.sign(e)*f2*(-1+Math.pow(10,Math.abs(e)))}let f6=[[0,1],[1,10],[10,100],[100,1e3],[1e3,1e4],[1e4,1e5]];class f7 extends f1{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=ed,s=ed;switch(this.scaleType){case q.Linear:break;case q.Logarithmic:i=f4,s=f5;break;default:throw Error("Unexpected scale type (neither linear nor log)")}let r=this._domain.map(i),n=this.rangeWithPadding(),a=t?f3(n,r):f3(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===q.Linear||s<0||r>1e5)return f8(t,i,e);let n=this.findLogBand(s),a=this.findLogBand(r),o=2*e;return a-n==0?f8(t,i,o):this.getLogTicks(n,a,o,i<t)}findLogBand(e){return f6.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]=f6[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=f8(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===q.Logarithmic}}function f8(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 f9={color:tG.COLOR_TRANSPARENT},me={color:tG.COLOR_TRANSPARENT,width:0,dashStyle:"Solid"},mt=new Set([af.Open,af.High,af.Low,af.Close].map(e=>e.id)),mi=new iO(0,0,0,0);class ms{axis;id;record;metaData;timeSeries;notifyAboutPriceDomains=!1;customPlotValues=!1;_priceMapFirstIndex;priceMapper;_firstVisibleDate=null;_lastVisibleDate=null;main=!1;curves=[];type=X.Symbol;isShutDown=!1;targetFields=[];detachedScale;yScale=null;levels;bands;annotations;visFromIndex;visToIndex;_eventsData;precision;visible=!0;constructor(){this.axis=null,this.id=e0(),this.record=new aA(""),this.metaData=new ii,this.timeSeries=new uX,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&&eH(this.eventsSeries)&&this.eventsSeries.hasData&&this.eventsSeries.container.size>0}getEventFor(e){return null}get isSymbol(){return this.is(X.Symbol)}get isExpression(){return this.is(X.Expression)}get isStudy(){return this.is(X.Study)}get isForward(){return this.is(X.Forward)}get isSeasonal(){return this.is(X.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 cg(i(ud.slice()),e):this.mainCurve.isElderImpulseSystemStyle?t=new fQ(i(ud.slice().concat(af.BREL)),e):this.mainCurve.isPercentChangeStyle&&(t=new dJ(i(ud.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=X[e.type],this.main=e.main,e.levels&&(this.levels=e.levels),e.bands&&(this.bands=e.bands),eH(e.precision)&&(this.precision=e.precision),this.curves=e.curves.map(e=>{let t=new hq;return t.plot=this,t.fromModel(e),t}),e.detachedScale&&(this.detachedScale=e.detachedScale,this.yScale=new f7(q.Linear,null)),this.visible=e.visible??!0}initialize(){}shutdown(){eH(this.timeSeries)&&eH(this.timeSeries.shutdown)&&!this.timeSeries.isCached&&this.timeSeries.shutdown(),this.isShutDown=!0}makeQuery(){let e=this.axis.pane.presenter,t=new ch(null,e.data.aggregation,Z.Normal,[eK(e$(e.data,null,"range","from")),eK(e$(e.data,null,"range","to"))]);return t.barsToFetch=e.data.maxDataPoints||tG.DEFAULT_MAX_RECORDS,t.aggregation.backAdjust&&(t.barsToFetch=4*t.barsToFetch),t.chartId=e.elementId,t.curveStyle=this.curves[0].style,t.visibleRange=e$(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 eH(this.detachedScale,this.yScale)&&this.detachedScale}getDetachedScaleMargins(){return tG.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=tG.OUT_OF_SCREEN;for(let i of this.levels.filter(e=>e.visible)){let s=this.priceToY(i.value);i6(e,i7({line:i.line,fill:f9})),iG(e,{x:-1,y:s},{x:t,y:s})}e.restore()}drawBands(e){e.save();let t=tG.OUT_OF_SCREEN;for(let i of this.bands){let s=this.priceToY(i.range.to),r=this.priceToY(i.range.from);i6(e,i7({fill:i.fill,line:me})),iU(e,new iO(-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!==af.DateTime):[]}getEventsAt(e){let t=this.eventsSeries.container,i=i=>t.getData(i)[e];return this.getEventFields().map(t=>{let s=i(t);if(!eH(s))return null;let r=this.getEventFor(t);if(!eH(r))return null;let n={field:t,value:s,date:i(af.DateTime),text:r.title,color:r.color};if(t!==af.Custom||s!==tG.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?af.High:i.isTick?af.Last:af.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(!eH(r)||!eH(r[0],r[1]))return;let n=(e,t=af.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===$.Year)return tn(t);if(i===$.Quarter)return nS(t);if(i===$.Month)return th(t);if(i===$.Week)return nv(t);if(i===$.Day)return to(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:mi}}):[]).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 iO(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===af.Custom?t:null}hitTestCustomEvent(e){return null!==this.getCustomEventDataAt(e)}tryHandleCustomEventClick(e){let t=this.getCustomEventDataAt(e);return!!eH(t)&&(this.showCustomEventPopup(t),!0)}isEmpty(){let e=this.timeSeries;return eH(e)&&e.hasData&&e.container.isEmpty}draw(e){if(this.visible)for(let t of(eH(this.levels)&&this.drawLevels(e),eH(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(!eH(e)||!this.timeSeries.hasData||!this.shouldPriceMap(i,s))return e;let[r,n]=this.axis.pane.presenter.view.xAxis.xScale.domain()||[];if(!eH(r)||!ov(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&&mt.has(e.id)}getRefPriceMapField(e){return this.isOhlcMapping(e)||e===af.PreviousClose?af.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=K.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(K.Percent)||r===K.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 eH(t)?t!==K.None:this.isComparison(K.Percent)||this.isComparison(K.Value)}onPriceDomainsUpdated(){}get presenter(){return this.axis?.pane?.presenter}}class mr extends ms{_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(!eH(this.timeSeries)||!eH(this.timeSeries.record))return null;let e=this.axis.pane.presenter.display.chart.previous.field;return this.timeSeries.record.getValue(af[e])}getTimeSeries(){let e=Sl().getTimeSeriesDataSource(),t=this.makeQuery();switch(t.symbol=this.resolved,this.mainCurve.style){case U.Renko:case U.Kagi:case U.PointAndFigure:t.barsToFetch=10100,t.inputs=this.inputs;break;case U.Range:t.barsToFetch=4e3;break;case U.LineBreak:t.inputs=this.inputs}let i=this.axis.pane;if(eH(i.alignedToYear)){let e=tM(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:er.Unspecified};this.presenter?.notifyHost(am.TS_MANYCHANGED,e),this.getEvents()}})}getMetaData(){let e=Sl().getMetaDataSource();this.metaData=e.getMetaData(this.resolved),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(am.MD_CHANGED,{plot:this})})}getEvents(){if(!this.hasEvents)return;let e=Sl().getTimeSeriesDataSource(),t={symbol:this.symbol,seriesKind:Z.Events,getHashKey:function(){return Object.values(this).filter(e=>"function"!=typeof e).join("|")}};tG.EVENTS.forEach(e=>{t[e]=e$(this.events,!1,e,"show")}),this._eventsSeries=e.getTimeSeries(t),this._eventsSeries.ready().then(e=>{e&&this.presenter?.notifyHost(am.TS_EVENTSCHANGED,{series:this.eventsSeries})})}get eventsSeries(){return this._eventsSeries??null}get hasEvents(){return!!eH(this.events)&&tG.EVENTS.some(e=>e$(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 $.Tick:return nI;case $.Intraday:case $.Day:return n_;case $.Week:return nL;case $.Month:return nM;case $.Quarter:return nx;case $.Year:return nP;default:return nI}}(this.axis.pane.presenter.data.aggregation),this._symbol=e.symbol}getEventFor(e){let t=this.events[e.id.toLowerCase()];return eH(t)&&t.show?t:null}async initialize(){return tW.call(this,async()=>(this.resolved=await tf(this.symbol),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class mn extends mr{seriesKind;fundamental;constructor(e){super(),this.seriesKind=e}get showPrevious(){return!1}get title(){return`${this.curves[0].fields[0].name}(${$[this.fundamental].substring(0,1)})`}fromModel(e){this.fundamental=$[e.fundamental],super.fromModel(e)}makeQuery(){let e=new ch(this.symbol,new nD(this.fundamental),this.seriesKind);return e.fields=this.curves[0].fields,e}}class ma{longPressTimeout;constructor(){this.longPressTimeout=null}getTouchCrosshairDelayMillis(){let e=Sl().config.touchCrosshairDelayMillis;return eH(e)&&Number.isFinite(e)?e:tG.LONG_PRESS_DELAY_MILLIS}startLongPress(e,t,i){eD()&&(this.longPressTimeout=setTimeout(()=>this.longPressTriggered(e,t,i),this.getTouchCrosshairDelayMillis()))}longPressTriggered(e,t,i){this.cancelLongPress(),this.performLongPress(e,t,i)}cancelLongPress(){eD()&&eH(this.longPressTimeout)&&(clearTimeout(this.longPressTimeout),this.longPressTimeout=null)}performLongPress(e,t,i){}}function mo(e){return e.locked||e.axis.pane.presenter.display.allAnnotationsLocked}class ml extends ma{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){mJ(this.annotation,i)}onMouseMove(e){if(this.cancelLongPress(),this.annotation.axis.pane.presenter.enableTooltip(!1),mo(this.annotation))return;let{point:t,view:i,offset:s}=e;if(!eV(t)||t.axis!==this.annotation.axis)return;i.drawCrosshair({ap:t,offset:s}),this.cursorSet||(this.previous.axis.pane.presenter.view.setCursor(Q.Move),this.cursorSet=!0);let r=iy(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(),gG(this.annotation,this.moved,eo.Moved)}}class mu{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(et.Shift),this.annotation.axis.pane.presenter.enableTooltip(!1),mo(this.annotation))return;let{point:t,view:i,offset:s}=e;if(i.drawCrosshair({ap:t,offset:s}),eH(t)){let e=this.annotation.points[this.pointIndex],i=iy(t.point,e.point);switch(e.moveDirection){case ei.Both:e.update(t.price,t.time);break;case ei.Horizontal:e.update(e.price,t.time);break;case ei.Vertical:e.update(t.price,e.time)}this.moved=e.moveDirection!==ei.None,this.moved&&this.annotation.wasPointMovedByTool(e,i)}this.annotation.requestRedraw()}onMouseUp(e){gG(this.annotation,this.moved,eo.PointMoved)}}class mh{anchor;isVertical;axis;constructor(e,t,i){this.anchor=e,this.isVertical=t,this.axis=i}hitTest(e){return!!eH(this.anchor)&&(this.isVertical?Math.abs(e.x-this.anchor.x)<=tG.HIT_TEST_TOLERANCE:Math.abs(e.y-this.anchor.y)<=tG.HIT_TEST_TOLERANCE)}draw(e){let t=tG.OUT_OF_SCREEN;this.isVertical?iz(e,this.anchor.x,-t,t):iY(e,this.anchor.y,-t,t)}}class mc{id;axis;_price;_time;passive=!1;moveDirection=ei.Both;visible=!0;point;constructor(e,t,i){this.id=e0(),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!==ei.None}get presenter(){return this.pane.presenter}get pane(){return this.axis.pane}toPoint(){let e=this.axis.toPoint(this);eH(e)&&eB(e.x)&&eB(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)<=tG.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)-tG.HALF_ANN_POINT_DIMENSION)}draw(e,t){if(eH(this.point)){let i=tG.HALF_ANN_POINT_DIMENSION;eH(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 md(e){return 0===iL(e.fill.color).a?e.line.color:e.fill.color}function mp(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 mf(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 mm{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=e0()}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 tG.EMPTY_ARRAY}getTimeScaleAdornments(){return tG.EMPTY_ARRAY}extractTraits(e=!0){let t=eG(this.traits),i=sA(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:eF(+e.time,4)}))}offset(e){this.points.filter(e=>e.movable).forEach(t=>{t.updateFromPoint(iS(t.point,e))})}get traits(){return this._traits||(this._traits=eG(this.defaultTraits)),this.adjustFill&&(this._traits.fill.color=md(this._traits),this.adjustFill=!1),this._traits}set traits(e){void 0!==e&&ez(this.traits,e,!1)}get activePoints(){return this.points.filter(e=>!e.passive)}get style(){return i7(this.traits)}get defaultTraits(){return i5(this.axis.pane.presenter.display,this.name)}get defaultStyle(){return i7(this.defaultTraits)}get adornStyle(){let e=eG(this.defaultTraits);return e.fill.color=this.traits.line.color,e.line.width=0,e.line.color=tG.COLOR_TRANSPARENT,i7(e)}get pointsStyle(){let e=eG(this.defaultTraits);return e.line.dashStyle="Solid",i7(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=eH(e);t&&(s||!r)&&i.toPoint(),r&&s&&(this.isSelected||this.drawn)&&(i6(e,this.pointsStyle),i.draw(e,this))})}addPoints(e){for(let t=0;t<e;t++)this.points.push(new mc(this.axis))}toModel(){let e=this.extractPoints();return{id:this.name,uid:this.uid,visible:this.visible,locked:this.locked,points:e,traits:eG(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=eH(e)?eG(e):{};eH(t)&&ez(n,t,!1),this.traits=n,eH(i)&&this.updatePoints(i)}priceMap(e){return this.axis.priceMap(e)}flip(e){let t=this.getFlipAnchorIndices();if(!eV(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 mg(e,t,i,s){return function(r,n=!0){let a=new t(r,e,i);return n?r.appendAnnotation(a):a.drawn=!1,eH(s)&&(a.traits=s),a}}class my{axis;angle;extent;anchor1;anchor2;p1;p2;style;extended;_data;isTrend;constructor(e,t,i,s,r){this.axis=r,eH(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)+tG.OUT_OF_SCREEN}hitTest(e){return!!eH(this.p1,this.p2)&&iA([this.p1,this.p2],e,tG.HIT_TEST_TOLERANCE)}draw(e){eH(this.p1,this.p2)&&(iG(e,this.p1,this.p2),this.extended)}getAdornOffset(e){var t,i;let s=iB(e),r=iH(e,1);return t=this.p1,i=this.p2,-(t.y-i.y)/(t.x-i.x)<0&&(s.y=r+5),s}}class mS{style;axis;rect;constructor(e,t,i,s){this.axis=s,this.rect=new iO(e.x,e.y,t,i)}hitTest(e){return this.rect.contains(e)}draw(e,t){iU(e,this.rect)}}class mT extends mm{countCache;constructor(e,t){super(e,t)}draw(e,t){if(this.prepareDraw(e,t)&&!this.drawn){let t=this.getElements();i6(e,this.style),t.forEach((t,i)=>{i6(e,this.getStyleForElement(t,i)),t.draw(e)}),i6(e,this.adornStyle),this.adornElements(t,e);let i=this.getMarkers();i6(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,!eH(e)||e}get showBackground(){var e;return e=this.traits?.showBackground,!!eH(e)&&e}get backgroundOpacity(){var e;return eH(e=this.traits?.backgroundOpacity)?e:0}fillOnlyStyle(e){return i7({line:{color:tG.COLOR_TRANSPARENT,dashStyle:"Solid",width:0},fill:this.traits[e]})}lineOnlyStyle(e){return i7({fill:{color:tG.COLOR_TRANSPARENT},line:this.traits[e]})}makeLine(e,t){return new my(e,t,!1,!1,this.axis)}applyBackgroundOpacity(e){return iP(ib(e),this.backgroundOpacity)}getTraitsFor(e){let t={fill:{color:tG.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 mA extends mT{_factors;constructor(e,t){super(e,t)}get factorsPropName(){return tG.AT_FACTORS}get factors(){return i0(this._factors??this.traits[this.factorsPropName])}getStyleForElement(e,t){return e.style??super.getStyleForElement(e,t)}get showLevels(){return this.traits[tG.AT_SHOW_LEVELS]}get levelsKind(){return this.traits[tG.AT_LEVELS_KIND]}get labels(){return this.traits[tG.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[tG.AT_PRICES_ON_SCALE]}formatLevelPrice(e,t){let i=this.levelsKind===tG.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+` (${hE(this.axis,e)})`).trim()}return s}getAdornPointAndAlign(e,t){let i=this.labels,s=e instanceof my,r=(e,t,i)=>({pt:e,align:t,offset:i});switch(i){case tG.AT_LABELS_LEFT:return r(s?e.anchor1:e,J.Right,-t);default:case tG.AT_LABELS_RIGHT:return r(s?e.anchor2:e,J.Left,t);case tG.AT_LABELS_CENTER:return r(s?im(e.anchor1,e.anchor2):e,J.Center,0)}}getColoredElements(e){let t=this.singleStyle;return this.factors.map(i=>{let s=e(i);return null===s?null:(t||(s.style=i7(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(!eH(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(ik(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(!eH(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);iW(s,o,f,d,r?l:e.style.strokeStyle)}u=e})}getAdornTextPoint(e,t,i,s){let r=iH(e,.75);return iS(i,{x:s,y:!0===t?r/2:t})}}class mv extends mT{lines;constructor(e,t){super(e,t),this.resetComputedState()}get rectStyle(){return this.fillOnlyStyle(tG.AT_FILL)}get rect(){let[e,t,,]=this.getScreenPoints(),i=new mS({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,hD),h=e_(l,+s.time,Number,hD)-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=i7(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 mb extends mc{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 mP{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 eH(this.points[0].point,this.points[1].point)?new iO(this.left,this.top,this.width,this.height):null}}function mC(e){let t=new mc(e),i=new mc(e),s=new mb(e,t,i),r=new mb(e,i,t);return[t,i,s,r]}class mE extends mm{helper;constructor(e,t){super(e,t),this.points=mC(e),this.helper=new mP(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)&&(i6(e,this.style),!0)}updatePoints(e){this.allowPricesChangeUI&&2===e.length&&e.forEach((e,t)=>this.points[t].update(e.price,e.time))}}class m_{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 mP(this.points)}hitTest(e){let t=this.getRect();return!!eV(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 mL extends mT{textEditable;_textAnnElement;constructor(e,t){super(e,t),this.textEditable=!0,this.points=mC(e),this.adjustFill=!0}get textLines(){return this.traits[tG.AT_TEXT_LINES]}set textLines(e){this.traits[tG.AT_TEXT_LINES]=e,this._textAnnElement=void 0}get textElement(){return!eH(this._textAnnElement)&&this.visible&&(this._textAnnElement=new m_(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 mM extends mL{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 mc(this.axis,t,e))}updateFrom(e,t,i,s,r){super.updateFrom(e,t,i,s,r),eH(e?.textLines)&&(this.textLines=e.textLines)}getElements(){let e=super.getElements(),t=this.pricesPoints.map(e=>new mh(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 mx{annId;annotation;constructor(e){this.annId=e}onKeyDown(e){if(null==this.annId)return;let{key:t,code:i,presenter:s}=e;eO(t,i)&&(eH(this.annotation)&&(this.annotation.axis.deleteAnnotation(this.annotation,!1),s.view.redraw()),g$(s,{toolChange:eo.Cancelled,annId:this.annId}))}}class mI extends mx{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=eV(this.annotation);if(i===ee.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}),eH(this.annotation,t)&&(this.alignPointsMode=this.forceAlignPoints||e.getModifier(et.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(){gG(this.annotation,!0,eo.Created)}isAccidentalMouseUp(e){let{point:t}=e,i=this.annotation.points[0].point;return ig(t.point,i)<tG.HIT_TEST_TOLERANCE}onMouseUp(e){if(void 0===this.annotation)return void gY(e);if(this.isAccidentalMouseUp(e)){this.dragged=!0;return}this.dragged=!1,this.thirdPoint||this.finish()}}class mD extends mI{constructor(e,t=!1){super(e,t),this.forceAlignPoints=!0}}class mO extends mI{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}),eH(this.annotation)&&this.dragged){let[e,i]=this.annotation.points;i.update(t.price,t.time);let s=iy(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 mw extends mx{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=!eH(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:md(i5(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[tG.AT_FILL].color}}}onMouseDown(e){let{point:t}=e;if(this.isNew)if(0===this.clicks){if(void 0===t)return void gY(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();tR(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(),gG(t,!0,this.isNew?eo.Created:eo.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 mR(e){return Sl().config.tooltipMovement===e}function mN(){return mR("Draggable")}let mV=tG.TOOLTIP_STD_LEGACY_CLASS,mH=tG.TOOLTIP_STD_CLASS,mF=tG.TOOLTIP_BUBBLE_CLASS;class mB{view;tooltipElem;leftSide;mode;isDrag;canDrag;isToggling;constructor(e){this.view=e,this.isDrag=!1,this.tooltipElem=tF(e.el,"div"),tN(this.tooltipElem,{id:`${e.presenter.elementId}-global-tooltip`,class:`${mH} ${mV}`}),this.leftSide=!0,tR(this.tooltipElem,{visibility:"hidden",position:"absolute",cursor:mN()?"move":"default",zIndex:20,top:`${tG.TOOLTIP_Y_OFFSET}px`,left:`${tG.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===tG.TOOLTIP_BUBBLE)this.canDrag=!1,this.tooltipElem.style.transition="none",this.tooltipElem.classList.remove(mH,mV),this.tooltipElem.classList.add(mF),tR(this.tooltipElem,{pointerEvents:"none"});else if(e===tG.TOOLTIP_STD){this.canDrag=mN(),this.tooltipElem.classList.remove(mF),this.tooltipElem.classList.add(mH,mV);let e=tG.TOOLTIP_TOGGLE_SIDE_ANIM_MS;tR(this.tooltipElem,{pointerEvents:"all",top:`${tG.TOOLTIP_Y_OFFSET}px`,left:`${tG.TOOLTIP_X_OFFSET}px`,transition:mR("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*tG.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"),tk(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){tR(this.tooltipElem,{left:`${e}px`,top:`${t}px`})}isAutoMove(){return this.mode===tG.TOOLTIP_STD&&mR("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=tG.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?tG.TOOLTIP_X_OFFSET:e.width-this.tooltipElem.offsetWidth-tG.TOOLTIP_X_OFFSET);this.reposition(i,t)}}toggleSide(){this.isToggling||(this.isToggling=!0,setTimeout(()=>this.isToggling=!1,tG.TOOLTIP_TOGGLE_SIDE_ANIM_MS),this.leftSide=!this.leftSide,this.repositionAuto())}}function mk(e){e.showTooltip&&mW(e,{time:tG.ZERO_DATE,offset:tG.OFFSCREEN_OFFSET,price:0,lastBarRefresh:void 0,justMain:void 0})}function mW(e,{time:t,lastBarRefresh:i,justMain:s,offset:r,price:n}){let a=hG(e,t,r,i,s,n),{mode:o,showMainPlot:l,hideSymbols:u,revealingClose:h}=e.display.tooltip,{includeTimestamp:c,showMainPlot:d,showPlotActions:p}=Sl().config.tooltipHeaders||{},f=eH(d)?d:l,m=!!eH(c)&&c,g=!!eH(u)&&u,y=!!eH(h)&&h,S=!!eH(p)&&p,T=t.valueOf()===tG.ZERO_DATE.valueOf();switch(o){case tG.TOOLTIP_CARDS:s||m$(e,a,f,!T,m&&!T,!1,g,y,S,e.hasLegend?e.view?.legend?.getLegendElem().clientHeight:0);break;case tG.TOOLTIP_BUBBLE:if(!T){let t=a.panes.find(e=>{let{top:t,left:i,width:s,height:n}=e.bounds;return new iO(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=hV({...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)})}m$(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tG.TOOLTIP_STD:if(!T){let t=hV({...a,hideSymbols:g,revealingClose:y,plots:a.panes.map(e=>e.plots).flat()});e.view.tooltip.show(t)}m$(e,a,f,!1,!1,e.hasLegend,g,y,S);break;case tG.TOOLTIP_EXTERNAL:e.notifyHost(am.CH_TOOLTIPCHANGED,a);break;default:console.warn(`Unknown tooltip mode requested: ${o}`)}}function mU(e,t,i,s,r,n){tR(e,{position:"absolute",display:"flex","flex-direction":t,"flex-wrap":"wrap",left:`${i+tG.CARDS_X_OFFSET}px`,top:`${r+tG.CARDS_Y_OFFSET}px`,maxWidth:`${n-s-2*tG.CARDS_X_OFFSET}px`})}function m$(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":""}`,T=X[h],A=!(["Study","BalanceSheet","IncomeStatement"].includes(T)||"Expression"===T&&!i)||o.hasLegend&&i?"":h$(l),v=function(e,t){let i=hF(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),b=a?function(e){let t=hF("moreActions");return`<a class="more-actions" data-plot-id="${e}" data-act="Menu" title="Actions">${t}</a>`}(l):"",P=hR(o)&&e.type===X.Symbol,C=(m||P)&&(!s||e.values.length>1),E=t?p.map(e=>hU(C?e.abbreviation:"Close"===e.id&&n?d+" ":null,e.value,e.color)).join(" ")+function(e){if(e&&e.length){let t=e.map(e=>hU(`${e.field.name} (${hx(hN,e.date)})`,e.value,e.color)).join(" ");return`Event ${t}`}return""}(f):"",_=!m&&"Expression"!==T,L=p.slice(0,_?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&&P?`${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
  ${A} ${v} ${b} ${t?"":L}
15
15
  <a class="${S}" ${y?`title="${y}" `:""}data-plot-id="${l}">${I}</a>
@@ -17,5 +17,5 @@ Bars %csame %c${i(t.lastTimestamp)} == ${i(t.newTimestamp)}`,"color:#0f0","color
17
17
  </div>
18
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?hB(!0,e):""} ${s?hB(!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=>!eH(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=tV(t,h,"div");mU(r,i&&hR(e)?"column":"row",a,o,l+u,c),tH(r,{"bcharts-card":!0,"bcharts-card-main":i,"bcharts-card-first":0===d}),r.innerHTML=s}let p=tw(`#right-${t}`,h);eH(p)||((p=document.createElement("div")).id=`right-${t}`,h.appendChild(p),tH(p,"bcharts-card bcharts-card-move")),tR(p,{position:"absolute",display:"block",right:`${o+tG.CARDS_X_OFFSET}px`,top:`${l+u+tG.CARDS_Y_OFFSET}px`}),p.innerHTML=r})}let mG=null;function mz(){return null===mG&&(mG=Sl().config.hostingModel===ea[ea.Application]),mG}class mY extends ma{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=mz();if(eD()&&!h&&this.warmUp)return(o>7||u>7)&&(this.warmUp=!1,this.preventDefault=o>u),!1;if(this.preventDefault||!eD()||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(Q.Grabbing)}return h||this.preventDefault}finished(){g$(this.presenter)}onMouseLeave(){this.finished()}onMouseUp(){this.finished()}onMouseDblClick({presenter:e,offset:t,originalEvent:i}){eD()&&mQ(e,t,i)}performLongPress(e,t,i){e.enableTooltip(!0),e.resetActiveTool(),e.activeTool.startTouchCrosshairMode(e,t,i)}}let mj=null;class mK extends mE{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)&&(iU(e,this.getRect()),!0)}}function mq(e,t){return e<t?[e,t]:[t,e]}let mX={line:{width:1,color:"rgba(127, 127, 127, 0.3)",dashStyle:"LongDash"},fill:{color:"rgba(127, 127, 127, 0.1)"}};class mZ extends mI{snapToSupported=!1;preventDefault=!1;axis;presenter;constructor(){super(mg("Rectangle",mK,null,mX),!1)}activated(){}deactivated(){eH(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(eH(this.axis,this.presenter)){g$(this.presenter,{toolChange:eo.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=tG.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 mJ(e,t){let i=mf(e);i.offset={x:t.x,y:t.y},i.canFlip=null!==e.getFlipAnchorIndices();let s=e.axis.pane.presenter;s.clearSelection(),s.notifyHost(am.CH_ANNNEEDSCONTEXTMENU,i)}function mQ(e,t,i){let s={offset:{x:t.x,y:t.y},chart:e.accessor,originalEvent:i};e.notifyHost(am.CH_CHTNEEDSCONTEXTMENU,s)}class m0 extends mx{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 gY(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),gG(this.annotation,!0,eo.Created)):this.annotation.requestRedraw()}applyToPoints(e){this.annotation.points[this.clicks].update(e.price,e.time)}}class m1{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(),gG(i,!0,eo.None)}}let m2=tG.MARKER_ARROW_ANGLE*Math.PI/180/2;function m3(e,t,i=tG.MARKER_ARROW_LENGTH){return new m4(e,t,i)}class m4{vertex;arrowLen;p1;p2;constructor(e,t,i=tG.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 iA([t,i],e,tG.HIT_TEST_TOLERANCE)||iA([t,s],e,tG.HIT_TEST_TOLERANCE)}draw(e){let{anchor:t,p1:i,p2:s}=this.getArrowPoints();iG(e,t,i),iG(e,t,s)}getArrowPoints(){let e=iT(this.p1,this.p2),t="start"===this.vertex?0:Math.PI,i=e-m2+t,s=e+m2+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 m5{hitTest(){return!1}draw(){}}class m6 extends mT{constructor(e,t){super(e,t),this.addPoints(2),this.alignPointsSupported=!0}get extend1(){return this.traits[tG.AT_EXTEND_PT_1]}get extend2(){return this.traits[tG.AT_EXTEND_PT_2]}get showPercentDiff(){return this.traits[tG.AT_SHOW_PERCENTDIFF]}get showBarCount(){return this.traits[tG.AT_SHOW_BARCOUNT]}get showRatio(){return this.traits[tG.AT_RATIO]}getElements(){let e=this.points[0].point,t=this.points[1].point,i=new my(e,t,this.extend1,this.extend2,this.axis),s=[];return this.extend1&&s.push(new my(i.p1,e,!0,!1,this.axis)),s.push(new my(e,t,!1,!1,this.axis)),this.extend2&&s.push(new my(t,i.p2,!1,!0,this.axis)),s}formatRatio(e,t){return` (${eF(e/t,3)})`}formatPercDiff(e,t){let i=(t-e)/e*100,s=i>0?"+":"";return` (${s}${eF(i,2)}%)`}formatPrice(e){return hE(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=iS(im(i.point,s.point),r);iW(t,this.getBarCount(i.time,s.time).toFixed(0),e,J.Right)}let n=this.showRatio?this.formatRatio(i.price,s.price):"",a=this.showPrices?this.formatPrice(i.price):"",o=`${a}${n}`.trim();""!==o&&iW(t,o,iS(i.point,r),J.Right);let l=this.showPercentDiff?this.formatPercDiff(i.price,s.price):"",u=this.showPrices?this.formatPrice(s.price):"",h=`${u}${l}`.trim();""!==h&&iW(t,h,iS(s.point,r),J.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,m3(t.map(e=>e.point),e)}return console.warn(`There is no marker of ${i} kind`),new m5})}}class m7 extends mT{constructor(e,t){super(e,t),this.addPoints(1)}get showTimestamps(){return this.traits[tG.AT_SHOW_TIMESTAMPS]}getElements(){return[new mh(this.points[0].point,!0,this.axis)]}getTimeScaleAdornments(){return this.showTimestamps?[{time:this.points[0].time,color:this.traits.line.color}]:super.getTimeScaleAdornments()}}class m8 extends mT{constructor(e,t){super(e,t),this.addPoints(1)}getElements(){return[new mh(this.points[0].point,!1,this.axis)]}getPriceScaleAdornments(){return this.showPrices?[{price:this.points[0].price,color:this.traits.line.color}]:super.getPriceScaleAdornments()}}class m9 extends mT{constructor(e,t,i){super(e,t),this.addPoints(2),eH(i)&&eH(i.points)&&i.points.forEach((e,t)=>this.points[t].update(e.price,e.time))}allPoints(){let[e,t]=this.points;return eH(e,e.point,t,t.point)?[e,this.axis.toAnnotationPoint(im(e.point,t.point)),t]:tG.EMPTY_ARRAY}line2(){return this.traits[tG.AT_LINE_2]}use52WeekPrices(){return this.traits[tG.AT_USE_52WEEK_PRICES]}getElements(){let e=this.allPoints();return e===tG.EMPTY_ARRAY?tG.EMPTY_ARRAY:e.map(e=>new my({x:-tG.OUT_OF_SCREEN,y:e.point.y},{x:tG.OUT_OF_SCREEN,y:e.point.y},!1,!1,this.axis))}wasPointMovedByTool(e,t){eH(this.use52WeekPrices())&&(this.traits[tG.AT_USE_52WEEK_PRICES]=!1)}getStyleForElement(e,t){let i=this.line2();if(1!==t||!eH(i))return super.getStyleForElement(e,t);let s=eG(this.traits);return s.line=i,i7(s)}getPriceScaleAdornments(){let e=this.allPoints();if(!this.showPrices||e===tG.EMPTY_ARRAY)return super.getPriceScaleAdornments();let t=this.traits.line,i=e.map(e=>({price:e.price,color:t.color})),s=this.line2();return eH(s)&&(i[1].color=s.color),i}getFlipAnchorIndices(){return null}}class ge extends mA{helper;constructor(e,t,i){super(e,t),this.addPoints(i),this.helper=new mc(e)}get showTrendLine(){return this.traits[tG.AT_SHOW_TRENDLINE]}get hasAllPoints(){return eH(...this.points.map(e=>e.point))}get line2(){return this.traits[tG.AT_LINE_2]}get extendLeft(){return this.traits[tG.AT_EXTEND_LEFT]}get extendRight(){return this.traits[tG.AT_EXTEND_RIGHT]}get reverse(){return this.traits[tG.AT_REVERSE]}get levelsRespectLogScale(){return this.traits[tG.AT_LEVELS_RESPECT_LOG_SCALE]}getStyleForElement(e,t){if(e.isTrend){let e=eG(this.traits);return e.line=this.line2,i7(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 my(e,t,!i&&n,!i&&a,this.axis);return s.isTrend=i,s},h=this.levelsRespectLogScale&&this.axis.scale===q.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 tG.AT_LABELS_LEFT:return this.extendLeft?s({x:r.x,y:e.anchor1.y},J.Left,t):super.getAdornPointAndAlign(e,t);default:case tG.AT_LABELS_RIGHT:return this.extendRight?s({x:r.x+r.width,y:e.anchor2.y},J.Right,-t):super.getAdornPointAndAlign(e,t);case tG.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||(iR(i,e.p1),i.lineTo(t.p2.x,e.p1.y),iN(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 gt extends ge{constructor(e,t){super(e,t,2)}}class gi extends ge{constructor(e,t){super(e,t,3)}}let gs=(e,t)=>{let i=new Path2D;return null===e||(iR(i,e.p1),iN(i,e.p2),iN(i,t.p2)),i};class gr extends mA{constructor(e,t){super(e,t),this.addPoints(2)}get reverse(){return this.traits[tG.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 my(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 my({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,gs,this.getTextRef(),t)}}class gn extends gr{constructor(e,t){super(e,t)}}class ga{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(ig(this.left,e),ig(this.right,e));else{let{x:i,y:s}=iy(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<=tG.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),i$(e,this.center,this.radius,this.startAngle,this.endAngle,this.isAntiClockwise??!1),e.restore()}}let go=(e,t)=>{let i=new Path2D,{center:s}=t;if(iR(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 iR(r,n),r.arc(n.x,n.y,e.radius,e.endAngle,e.startAngle,!e.isAntiClockwise),i.addPath(r),i};class gl extends mA{constructor(e,t){super(e,t),this.addPoints(2)}getElements(){let[e,t]=this.getScreenPoints();if(!eH(e,t))return[];let i=ig(e,t),s=iy(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=ig(e,a);return new ga(e,a,l,0,Math.PI,null,o)},o=this.getColoredElements(a);if(this.showTrendLine){let i=new my(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,go,this.getTextRef(),t)}}class gu extends gl{constructor(e,t){super(e,t)}getStyleForElement(e,t){if(e.isTrend){let e=eG(this.traits);return e.line=this.line2,i7(e)}return super.getStyleForElement(e,t)}get showTrendLine(){return this.traits[tG.AT_SHOW_TRENDLINE]}get line2(){return this.traits[tG.AT_LINE_2]}}class gh extends mA{constructor(e,t){super(e,t),this.addPoints(2)}get factorsPropName(){return tG.AT_ANGLES}getElements(){let[e,t]=this.getScreenPoints(),{x:i,y:s}=iy(t,e),r=({value:r})=>{let n=(t,i)=>new my(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,gs,this.getTextRef(),t)}}class gc extends gr{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 my(e,t,!1,!1,this.axis)].concat(super.getElements())}}class gd extends gl{constructor(e,t){super(e,t),this._factors=[{shown:!0,value:1/3},{shown:!0,value:2/3}]}}class gp extends mT{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 my(t,{x:t.x+s,y:t.y+r},!1,!0,this.axis)),n.push(new my(e,{x:e.x+s,y:e.y+r},!1,!0,this.axis)),n.push(new my(i,{x:i.x+s,y:i.y+r},!1,!0,this.axis)),n.push(new my(t,i,!1,!1,this.axis)),n}}class gf extends mE{constructor(e,t){super(e,t)}getEllipse(){let e=this.getRect();return null===e?null:new iw(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 gm extends mT{constructor(e,t){super(e,t),this.addPoints(3)}get extend1(){return this.traits[tG.AT_EXTEND_PT_1]}get extend2(){return this.traits[tG.AT_EXTEND_PT_2]}getLastPoint(){let[e,t,i]=this.points;var s=ig(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 my(e.point,t.point,this.extend1,this.extend2,this.axis)),eH(i?.price)){var r=this.getLastPoint();s.push(new my(i.point,r,this.extend1,this.extend2,this.axis))}return s}}class gg extends mE{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 tG.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,hD);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=iS(this.points[0].point,{x:0,y:-e/2}),o=iS(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":ij(e,i,"0");break;case"one":ij(e,i,"1");break;case"two":ij(e,i,"2");break;case"three":ij(e,i,"3");break;case"four":ij(e,i,"4");break;case"five":ij(e,i,"5");break;case"six":ij(e,i,"6");break;case"seven":ij(e,i,"7");break;case"eight":ij(e,i,"8");break;case"nine":ij(e,i,"9");break;case"question":ij(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}=iK(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:T,right:A,top:v,bottom:b,halfBaseSize:P}=iK(g);m.beginPath(),m.moveTo(A,S),m.lineTo(y,b),m.lineTo(T,S),m.lineTo(Math.floor(y-P),S),m.lineTo(Math.floor(y-P),v),m.lineTo(Math.floor(y+P),v),m.lineTo(Math.floor(y+P),S),m.closePath(),m.fill(),m.restore();break;case"arrow_right":var C=e,E=i;C.save();let{cx:_,cy:L,left:M,right:x,top:I,bottom:D,halfBaseSize:O}=iK(E);C.beginPath(),C.moveTo(_,I),C.lineTo(x,L),C.lineTo(_,D),C.lineTo(_,Math.floor(L+O)),C.lineTo(M,Math.floor(L+O)),C.lineTo(M,Math.floor(L-O)),C.lineTo(_,Math.floor(L-O)),C.closePath(),C.fill(),C.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}=iK(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}=iK($,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}=iK(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}=iq(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}=iq(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":ij(e,i,"B");break;case"sell":ij(e,i,"S")}return!0}}class gy extends mA{helper;constructor(e,t){super(e,t),this.addPoints(2),this.helper=new mc(e)}getElements(){let e=this.axis.pane.presenter.timeline,{price:t,time:i}=this.points[0],s=e_(e,i,Number,hD),r=e_(e,this.points[1].time,Number,hD),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 mh(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 gS{snapToSupported=!0;isDrawingAnnotation=!0;constructor(){}onMouseMove(e){let{point:t,view:i,offset:s}=e;i.drawCrosshair({ap:t,offset:s})}onMouseDown(e){if(eD()&&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(am.CH_ANNPOINTPICKED,s),g$(i,void 0)}}let gT="Closed";class gA extends mT{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,ei.Vertical),s(2,ei.Vertical),s(3,ei.Horizontal),this.twoDecMeta=new it(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(af.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]=[af.High,af.Low,af.Close].map(e=>this.data(e)),c=e=>e-n;for(let e=n;e<=a;e++)i&&-1===o.refIndex&&eH(this.entryPrice)&&this.entryPrice>=u[e]&&this.entryPrice<=l[e]&&(o.refIndex=c(e)),(!i||o.refIndex>=0&&c(e)>=o.refIndex)&&((!eH(o.highest)||l[e]>o.highest)&&(o.highest=l[e]),(!eH(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=eH(o.highest,o.lowest)&&(this.upperPrice<o.highest||this.lowerPrice>o.lowest)?gT:"Open",o.special=-1===o.highestIndex&&-1===o.lowestIndex||o.highestIndex===o.lowestIndex;let e=eb(o.data);if(o.toPrice=e.close,o.toTime=e.time,o.state===gT)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=eF(t,2)}return o}get dataWindow(){return eH(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,hD),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[tG.AT_ACCOUNT_SIZE]}get risk(){let e=this.traits[tG.AT_RISK_IS_PERCENT],t=this.traits[tG.AT_RISK];return eF(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))}`:tG.NOT_APPLICABLE}get qty(){return Math.floor(this.risk/(this.isLong?this.entryPrice-this.lowerPrice:this.upperPrice-this.entryPrice))}get upperDiff(){return eF(this.upperPrice-this.entryPrice,2)}get amountMultiplier(){return this.isLong?1:-1}get upperAmount(){return eF(this.accountSize+this.amountMultiplier*this.qty*this.upperDiff,2)}get upperPandL(){return eF(this.amountMultiplier*this.upperDiff*this.pointValue,2)}get isCompact(){return this.traits[tG.AT_COMPACT]}get upper(){let e=hE(this.axis,this.priceMap(this.upperPrice)),t=`(${eF(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 eF(this.entryPrice-this.lowerPrice,2)}get lowerAmount(){return eF(this.accountSize-this.amountMultiplier*this.qty*this.lowerDiff,2)}get lowerPandL(){return eF(-this.amountMultiplier*this.lowerDiff*this.pointValue,2)}get lower(){let e=hE(this.axis,this.priceMap(this.lowerPrice)),t=`(${eF(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 eF(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(tG.AT_FILL2)}get upperStyle(){return this.fillOnlyStyle(tG.AT_FILL)}get textStyle(){return this.fillOnlyStyle(tG.AT_FILL_TEXT)}get secondaryLineStyle(){return i7({line:{color:this.traits.line.color,dashStyle:"ShortDash"},fill:{color:tG.COLOR_TRANSPARENT}})}wasModifiedByTool(){eH(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 my(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 mS(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 mS(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 mc(this.axis,this.entryPrice,e.time),i=new mc(this.axis,o.toPrice,o.toTime),s=new my(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 mS({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=>ib(this.traits[e].color);return[{price:this.upperPrice,color:e(tG.AT_FILL)},{price:this.entryPrice,color:e(tG.AT_LINE)},{price:this.lowerPrice,color:e(tG.AT_FILL2)}]}adornElements(e,t){let[i,s,r]=e;if(this.showTextAdornments){let[e,n]=[!0,!1].map(e=>iF(t,e)),{x:a,y:o,width:l}=s.rect,u=this.textStyle.fillStyle;iW(t,this.upperText,{x:a+l/2,y:o+e},J.Center,u,ib(this.upperStyle.fillStyle));let{x:h,y:c,width:d,height:p}=r.rect;iW(t,this.lowerText,{x:h+d/2,y:c+p+Math.abs(n)},J.Center,u,ib(this.lowerStyle.fillStyle));let{p1:f,p2:m}=i,{x:g,y:y}=f,{x:S}=m,T=this.state||tG.NOT_APPLICABLE,A=this.isCompact?`${this.formatDollarValue(this.pAndLValue)}`:`${T} P&L: ${this.formatDollarValue(this.pAndLValue)}, Qty: ${this.qty}`,v=this.isCompact?`${this.riskReward.toFixed(2)}`:`Risk/Reward Ratio: ${this.riskReward.toFixed(2)}`,b=e=>t.measureText(e).width,P=Math.abs(S-g)<1.25*Math.max(b(A),b(v))?y+Math.abs(n)+5:y+e+10,C=ib(this.isUpperPerPAndL?this.upperStyle.fillStyle:this.lowerStyle.fillStyle);iW(t,[A,v],{x:g+(S-g)/2,y:P},J.Center,u,C)}}updatePoints(e){super.updatePoints(e),this.wasModifiedByTool()}}var gv=["years","months","weeks","days","hours","minutes","seconds"];function gb(e,t){te(2,arguments);var i=ti(e),s=ti(t),r=i.getTime()-s.getTime();return r<0?-1:r>0?1:r}function gP(e){return(gP="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 gC(e,t){if(te(2,arguments),!t||"object"!==gP(t))return new Date(NaN);var i=t.years?e9(t.years):0,s=t.months?e9(t.months):0,r=t.weeks?e9(t.weeks):0,n=t.days?e9(t.days):0,a=t.hours?e9(t.hours):0,o=t.minutes?e9(t.minutes):0,l=t.seconds?e9(t.seconds):0,u=ti(e),h=s||i?ts(u,s+12*i):u;return new Date((n||r?lF(h,n+7*r):h).getTime()+1e3*(l+60*(o+60*a)))}function gE(e,t,i){te(2,arguments);var s=uC(e,t)/6e4;return u_(null==i?void 0:i.roundingMethod)(s)}class g_ extends mv{markers;display=null;constructor(e,t){super(e,t),this.points=mC(e),this.points[2].visible=!1,this.points[3].visible=!1,this.markers=[new m5]}isPointDrawn(e){return!!super.isPointDrawn(e)&&e.visible}makeLineArrow(e,t,i,s){let r=[im(e,t),im(i,s)];return[this.makeLine(r[0],r[1]),m3(r,"end",10)]}get rectColor(){return this.traits[tG.AT_FILL].color}get textColor(){return this.traits[tG.AT_FILL_TEXT].color}getMarkers(){return this.markers}formatDateDifference(e,t){return this.presenter.data.aggregation.isEndOfDay?`${lV(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:nA.locale)?i:oq,l=null!=(r=null==t?void 0:t.format)?r:gv,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){te(1,arguments);var t=ti(e.start),i=ti(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){te(2,arguments);var i=ti(e),s=ti(t),r=gb(i,s),n=Math.abs(function(e,t){te(2,arguments);var i=ti(e),s=ti(t);return i.getFullYear()-s.getFullYear()}(i,s));i.setFullYear(1584),s.setFullYear(1584);var a=gb(i,s)===-r,o=r*(n-Number(a));return 0===o?0:o}(i,t));var r=gb(i,t),n=gC(t,{years:r*s.years});s.months=Math.abs(function(e,t){te(2,arguments);var i,s=ti(e),r=ti(t),n=gb(s,r),a=Math.abs(function(e,t){te(2,arguments);var i=ti(e),s=ti(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=gb(s,r)===-n;(function(e){te(1,arguments);var t=ti(e);return lH(t).getTime()===(function(e){te(1,arguments);var t=ti(e),i=t.getMonth();return t.setFullYear(t.getFullYear(),i+1,0),t.setHours(23,59,59,999),t})(t).getTime()})(ti(e))&&1===a&&1===gb(e,r)&&(o=!1),i=n*(a-Number(o))}return 0===i?0:i}(i,n));var a=gC(n,{months:r*s.months});s.days=Math.abs(lV(i,a));var o=gC(a,{days:r*s.days});s.hours=Math.abs(function(e,t,i){te(2,arguments);var s=uC(e,t)/36e5;return u_(null==i?void 0:i.roundingMethod)(s)}(i,o));var l=gC(o,{hours:r*s.hours});s.minutes=Math.abs(gE(i,l));var u=gC(l,{minutes:r*s.minutes});return s.seconds=Math.abs(uL(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=iF(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){iW(t,this.text,this.getTextCoord(e[0],t),J.Center,this.textColor,ib(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(af.DateTime),n=e_(r,+i,Number),a=e_(r,+s,Number),o=ef(this.data(af.Volume).slice(n,a+1)),l=this.formatter.format(o,af.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,af.Close),r=this.formatter.format(i/e,af.PercentChange);return[`${s} (${r})`]}resetComputedState(){this.display=null}getFlipAnchorIndices(){return[0,1]}}class gL extends g_{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 gM extends g_{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 gx extends g_{get drawBorder(){return this.traits[tG.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 gI extends mv{constructor(e,t){super(e,t),this.points=mC(e)}get priceLevels(){return i0(this.traits[tG.AT_PRICE_LEVELS])}get timeLevels(){return i0(this.traits[tG.AT_TIME_LEVELS])}get showAngles(){return this.traits[tG.AT_SHOW_ANGLES]}get reverse(){return this.traits[tG.AT_REVERSE]}get showLeftLabels(){return this.traits[tG.AT_SHOW_LEFT_LABELS]}get showRightLabels(){return this.traits[tG.AT_SHOW_RIGHT_LABELS]}get showTopLabels(){return this.traits[tG.AT_SHOW_TOP_LABELS]}get showBottomLabels(){return this.traits[tG.AT_SHOW_BOTTOM_LABELS]}getAngles(e,t){let i=this.getScreenPoints(),s=this.lineOnlyStyle(tG.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=iH(t,1)/2,{x:a,y:o}=tG.DEFAULT_ADORN_OFFSET,l=(e,i,s,r,n)=>{let a=iS(e,i);iW(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,J.Right,d),this.showRightLabels&&l(e.p2,{x:-a,y:n},h,J.Left,d)):(this.showTopLabels&&l(e.p1,{x:0,y:o},h,J.Center,d),this.showBottomLabels&&l(e.p2,{x:0,y:-(2*o)},h,J.Center,d)),p&&((e,i)=>{let s=new Path2D;iV(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();iV(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 gD=e=>e.map(e=>({...e,dimensions:e.value.split("x").map(Number)})),gO=(e,t)=>1e-7>Math.abs(e-t);class gw extends mv{_parsedFans=null;_parsedArcs=null;constructor(e,t){super(e,t),this.points=mC(e),this._parsedFans=this._parsedArcs=null}get levels(){return i0(this.traits[tG.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[tG.AT_SHOW_RANGES_RATIO]}get arcs(){return i0(this.traits[tG.AT_ARCS])}get fans(){return i0(this.traits[tG.AT_FANS])}get reverse(){return this.traits[tG.AT_REVERSE]}get parsedFans(){return null===this._parsedFans&&(this._parsedFans=gD(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=gD(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[tG.AT_PRICE_BAR_RATIO]}set priceBarRatio(e){this.traits[tG.AT_PRICE_BAR_RATIO]=e}makeStyledLine(e,t,i){let s=this.makeLine(e,t);return this.singleStyle||(s.style=i7(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=gO(r,n)?null:{x:1,y:n/r},o=this.getClipPath();return this.computedArcs.map(({computed:r,traits:n})=>{let l=new ga(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=i7(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 iV(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=eb(s);i(go(null,e),e,this.applyBackgroundOpacity(this.traits.line.color))}else{let e=null;s.forEach(t=>{let s=go(e,t),r=t.style.fillStyle;i(s,t,r),e=t})}t.restore()}if(this.showRangesRatio&&null!==this.unit){let e=eb(this.computedLevels),i=(this.singleStyle?this:e).traits.line.color,[,s,r,n]=this.getReversedScreenPoints(),{x:a,y:o}=tG.DEFAULT_ADORN_OFFSET,{flipX:l,signX:u,signY:h}=this.getOrientation(),c=iS(r,{x:-a*u,y:o*h}),{priceDiff:d,barsDiff:p}=this.getLinesDataAtLevels(null,null),f=l?J.Right:J.Left;iW(t,p.toFixed(0),c,f,i);let m=iS(n,{x:2*a*u,y:-o*h}),g=l?J.Left:J.Right;iW(t,this.formatter.format(d,af.Close),m,g,i);let y=iS(s,{x:-a*u,y:-o*h});iW(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,!gO(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 gR extends mA{constructor(e,t){super(e,t),this.addPoints(3)}get extend1(){return this.traits[tG.AT_EXTEND_PT_1]}get extend2(){return this.traits[tG.AT_EXTEND_PT_2]}getElements(){let[e,t,i]=this.getScreenPoints(),{x:s,y:r}=iy(i,e),n=i=>{let[s,r]=[e,t].map(e=>iS(e,i));return new my(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||(iR(i,e.p1),iN(i,e.p2),iN(i,t.p2),iN(i,t.p1)),i},this.getTextRef(),t)}}class gN extends mT{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=e1(1,1e3,e.LevelSize),this.alignLeft="Left"===e.Position,this.totalVolume="Total"===e.Volume,this.widthPercent=e1(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(W.ChangeBased)??!1}}eV(e.PeriodType)&&(this.periodType=e.PeriodType),this.period=e.Period,this.valueRangePercent=e.ValueRangePercent/100;let t=es[Sl()?.config.mode??"Unspecified"];this.usesFinerGrainedAgg=sF(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(!eH(t))return;let i=t[t.length-1],s=this.boxes.length>0?this.boxes[this.boxes.length-1]:null;if(eV(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 iO(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 mS({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 mS({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,T=y&&c?this.downValueStyle:this.downStyle,A=y&&c?this.totalValueStyle:this.totalStyle;if(this.totalVolume){let e=g(h,a,n);i.push(m(e,A))}else{let e=g(u,a,n),t=g(l,a,n);i.push(m(t,S),m(e,T,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 my({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(!ov(e)||!ov(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(tG.AT_FILL)}get upStyle(){return this.fillOnlyStyle(tG.AT_FILL2)}get totalStyle(){return this.fillOnlyStyle(tG.AT_FILL3)}get downValueStyle(){return this.fillOnlyStyle(tG.AT_FILL4)}get upValueStyle(){return this.fillOnlyStyle(tG.AT_FILL5)}get totalValueStyle(){return this.fillOnlyStyle(tG.AT_FILL6)}get backgroundStyle(){return this.fillOnlyStyle(tG.AT_FILL7)}get lineStyle(){return this.lineOnlyStyle(tG.AT_LINE)}getBoxEndFromStart(e){switch(this.periodType){case"VisibleScreen":default:return null;case"Days":return oP(lZ($.Day,this.period)(e),1);case"Bars":{let t=this.axis.pane.presenter.data.aggregation;return oP(lZ(t.unit,t.size*this.period)(e),1)}}}getData(){let e=this.axis.pane.presenter.data.aggregation;if(e.isTick||e.hasSpec&&!pU(e.spec))return;let[t,i]=this.presenter.view.xAxis.xScale.domain()||[];if(!ov(t)||!ov(i))return;let s=lZ(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=oP(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(af.TradingDay),a=e=>{let t=0,i=r[e],s=n[e];for(let a=e;a<r.length;a++)if(tl(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=oP(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=oP(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 af.UPVOL:return this.totalVolume?null:n.upVolume;case af.DNVOL:return this.totalVolume?null:n.downVolume;case af.TOTVOL:return this.totalVolume?n.totalVolume:null;case af.POC:case af.VAREA:case af.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=eV(r)&&eV(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=ef(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=ef(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(!eH(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===$.Day&&"Bars"===this.periodType){let e=s.getData(af.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=af[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=eM(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=eM(e,m)}return this.tallyVolume(i,a,o,l,c,d,p),this.gotData=!0,i}}function gV(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 gH extends mT{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(tG.AT_LINE),t=this.lineOnlyStyle(tG.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 eV(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 mc(this.axis,this.targetPrice,this.targetDate)],this.pricesCount>1&&this.points.push(new mc(this.axis,this.targetPrice2,this.targetDate)),this.unitsPerYear=fX(this.presenter.data.aggregation),this.anchorPrice=this.mainCont.getLastDataPoint(af.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=gV(t(this.targetPrice));if(this.pricesCount>1){let e=gV(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 mh(this.points[0].point,!0,this.axis)),e.push(new mh(this.points[0].point,!1,this.axis)),this.pricesCount>1&&e.push(new mh(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(iF(t,e))),s=this.pricesCount>1,r=this.points[0].point,n=s?this.points[1].point:r,a=this.traits.line2.color,o=ix(a),l=iH(t),u=["Above","Below","Between"],h=(e,t)=>`${eF(100*e,2).toFixed(2)}% Probability ${u[t]}`,c=(e,i)=>iW(t,e,i,J.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 gF=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=eN(am.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 tG.EVENT_PIN_HIT;let i=e.presenter.selectedAnnotation;void 0!==i&&(t=i.points.find(t=>t.hitTest(e.point)));let s=eb(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(eH(e))this.resetVerticalAxis(e),n=!0;else if(r)this.resetHorizontalAxis(i),n=!0;else if(eD()){let e=i.selectedAnnotation;null!=e?mJ(e,t):mQ(i,t)}n&&s.redraw()}onMouseEnter(){this.previousTouchTimestamp=null}computePreviousTouchStartDuration(){if(!eD())return null;let e=new Date().getTime(),t=eH(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?et.Meta:et.Control,h=i===ee.Right||l&&i===ee.Left&&e.getModifier(et.Control);this.touchCrosshairMode&&eH(this.touchCrosshairTimeout)&&(clearTimeout(this.touchCrosshairTimeout),this.touchCrosshairTimeout=null);let c=this.computePreviousTouchStartDuration();if(eH(c)&&c<tG.DOUBLE_CLICK_DURATION_MILLIS)return this.onMouseDblClick(e),!0;if(!h&&this.isLogoLink(r)&&a.notifyHost(am.CH_LOGOCLICKED,{chart:a.accessor}),eH(t)&&a.allPlots.some(e=>e.tryHandleCustomEventClick(t.point)))return!0;if(eH(s))return this.resizingPanes=!0,this.lastResizingOffset=r,this.splitter=s,a.enableTooltip(!1),!0;if(eH(n))return ek(a.display.chart.zooming)[0]&&this.startAxisScaling(n,r),!0;if(null!=t){if(e.getModifier(u))return a.activeTool=new mZ,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?mQ(a,r,o):i?.locked&&mJ(i,r),!0):!!this.touchCrosshairMode||(a.activeTool=new mY(t),a.activeTool.startPan(r),mz());let n=null!=s;return h?(mJ(i,r),eD()):(!n||!!s.movable)&&(!!n||!!i.canMove(t.point))&&(a.activeTool=n&&-1!==i.points.indexOf(s)?new mu(i,s):new ml(i,t,r),eD())}return this.prevZoomingOffset=r,!1}onContextMenu(e){return!0}isLogoLink(e){let t=eV(mj)&&mj.logoClickable?mj.rect:null;return eH(t)&&t.contains(e)}onMouseMove(e){let{point:t,splitter:i,priceAxis:s,view:r,presenter:n,offset:a}=e;if(eH(e.pinchZoom)&&e.pinchZoom&&eH(e.pinchDistance))return eH(this.prevPinchDistance)&&(e.delta=this.prevPinchDistance-e.pinchDistance,this.onWheel(e)),this.prevPinchDistance=e.pinchDistance,eD();if(null!=i||this.resizingPanes)r.setCursor(Q.ResizeVertical),this.resizingPanes&&this.resizePanes(r,a);else if(eH(t)){let[e,i]=this.findHit(t);eH(i)?t.presenter.view.setCursor(Q.Crosshair):eH(e)?e.isSelected?t.presenter.view.setCursor(Q.Move):t.presenter.view.setCursor(Q.Hand):t.presenter.view.setCursor(Q.Arrow)}else if(eH(s))ek(n.display.chart.zooming)[0]&&(r.setCursor(Q.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(Q.ResizeHorizontal)}return!t||this.resizingPanes?this.hideCrosshairAndTooltips(r):(this.isLogoLink(a)&&r.setCursor(Q.Hand),this.showCrosshairAndTooltips(r,t,a)),eD()}showCrosshairAndTooltips(e,t,i){t.time&&(!eD()||this.touchCrosshairMode)&&e.drawCrosshair({ap:t,offset:i})&&e.presenter.showTooltip&&mW(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&&mk(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(Q.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),eD()){let t=function(){let e=Sl().config.touchCrosshairTimeoutMillis;return eH(e)&&Number.isFinite(e)?e:tG.LONG_PRESS_TIMEOUT_MILLIS}();this.touchCrosshairTimeout=window.setTimeout(()=>{this.hideCrosshairAndTooltips(e.view,!0),this.touchCrosshairMode=!1},t)}}applyZoom(e,t,i=!0){if(!ek(e.display.chart.zooming)[1])return;let s=Math.sign(t)*(eD()?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!!(eD()?"none"!==r:"wheel"===r||"wheel+shift"===r&&i(et.Shift))&&0!==s&&(e.drawCrosshair({ap:void 0}),e.tooltip.hide(),e.presenter.hideCards(),this.applyZoom(t,s),!0)}get useKeyboardShortcuts(){return Sl().config.hostingModel!==ea[ea.Application]}onKeyDown(e){let{key:t,code:i,presenter:s}=e;if(eH(s.selectedAnnotation)&&("Backspace"===t||"Delete"===t||8===i||46===i)){let e=s.selectedAnnotation;e.axis.deleteAnnotation(e),s.onAnnotationModifiedByTool(e,eo.Deleted)}if(eH(s.selectedAnnotation)&&(eO(t,i)?s.clearSelection():("F2"===t||113===i)&&s.selectedAnnotation instanceof mL&&s.selectedAnnotation.textEditable&&(s.activeTool=new mw(null,s.selectedAnnotation),s.activeTool.startEditing())),ew(t,i)||"ArrowRight"===t||39===i){let e=ew(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")?et.Meta:et.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(et.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<tG.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=eF(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=eD()?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()}}},gB=e=>gz(m0,gg,1,e),gk=e=>gz(m0,mM,1,e),gW={Default:()=>function(){return gF},Line:()=>gz(mI,m6,!1),DateRange:()=>gz(mI,gL,!1),PriceRange:()=>gz(mI,gM,!1),DatePriceRange:()=>gz(mI,gx,!1),GannBox:()=>gz(mI,gI,!1),GannSquare:()=>gz(mO,gw),Ray:()=>gz(mI,m6,!1),GannLine:()=>gz(mD,m6,!1),VerticalLine:()=>gz(m0,m7,1),HorizontalLine:()=>gz(m0,m8,1),LongPosition:()=>gz(m0,gA,1,!0),ShortPosition:()=>gz(m0,gA,1,!1),FiftyPercentLine:function(e,t){return eH(e)?gz(m1,m9,e.axis||t.mainAxis,e):gz(m0,m9,2)},FibonacciRetracement:()=>gz(mI,gt,!1),TrendBasedFibExtension:()=>gz(mI,gi,!0),FibonacciFan:()=>gz(mI,gn,!1),FibonacciArcs:()=>gz(mI,gu,!1),FibonacciChannel:()=>gz(mI,gR,!0),GannFan:()=>gz(mI,gh,!1),SpeedResistanceFan:()=>gz(mI,gc,!1),SpeedResistanceArcs:()=>gz(mI,gd,!1),AndrewsPitchfork:()=>gz(m0,gp,3),Rectangle:()=>gz(mI,mK,!1),Ellipse:()=>gz(mI,gf,!1),TrendChannel:()=>gz(mI,gm,!0),SymbolArrowUp:()=>gB("arrow_up"),SymbolArrowDown:()=>gB("arrow_down"),SymbolArrowRight:()=>gB("arrow_right"),SymbolArrowLeft:()=>gB("arrow_left"),SymbolArrowHorizontal:()=>gB("arrow_horizontal"),SymbolArrowVertical:()=>gB("arrow_vertical"),SymbolArcDown:()=>gB("arc_down"),SymbolArcUp:()=>gB("arc_up"),SymbolThumbsUp:()=>gB("thumbs_up"),SymbolThumbsDown:()=>gB("thumbs_down"),SymbolZero:()=>gB("zero"),SymbolOne:()=>gB("one"),SymbolTwo:()=>gB("two"),SymbolThree:()=>gB("three"),SymbolFour:()=>gB("four"),SymbolFive:()=>gB("five"),SymbolSix:()=>gB("six"),SymbolSeven:()=>gB("seven"),SymbolEight:()=>gB("eight"),SymbolNine:()=>gB("nine"),SymbolQuestion:()=>gB("question"),SymbolFishHook:()=>gB("fish_hook"),SymbolBuy:()=>gB("buy"),SymbolSell:()=>gB("sell"),FibonacciTimeZones:()=>gz(mI,gy,!1),Text:()=>gz(mw,mL,null),PickPoint:()=>function(){return new gS},ZoomIn:()=>function(){return new mZ},ProfitLoss:gk,RewardRisk:gk,VolumeAtPrice:function(e){return gz(m0,gN,2,e)},ProbabilityCones:function(e){return gz(m0,gH,2,e)}};function gU(e,t=!1,i=null,s=null,r=null){let n=gW[e];return(n=n(s,r))(e,t,i)}function g$(e,t={}){e.enableTooltip(!0),e.resetActiveTool();let{axis:i,annotation:s,toolChange:r,annId:n}=t;eH(i)&&e.onAnnotationsUpdated(i),eH(s)&&e.onAnnotationModifiedByTool(s,r),[eo.Cancelled,eo.Executed,eo.TextChanged].includes(r)&&e.onAnnotationDone(n,r)}function gG(e,t=!0,i=eo.None){e.wasModifiedByTool();let s=e.axis;g$(s.pane.presenter,t?{axis:s,annotation:e,toolChange:i}:void 0)}function gz(e,t,i,s){return function(r,n,a){let o=mg(r,t,s,a);return(o.annName=r,n)?o:new e(o,i)}}function gY(e){e.button===ee.Right&&g$(e.presenter)}function gj(e,t,i){let s={};s.source=af[e.source],s.inputs=ej(e.inputs);let r=void 0!==e.target,n=eH(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?[af[e.target]]:n.map(e=>e.fields).flat()),s.target=r?af[e.target]:s.outFields[0],s.aggregation=t,s}class gK extends ms{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 eH(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(!eH(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(!eH(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=sw(this.model.study),t=e.meta.decimals;this.metaData=void 0!==t?new it(t):this.basePlot.metaData,eH(e.meta.range)&&(this.range=e.meta.range)}getDetachedScaleMargins(){return"VOL"===this.model?.study&&this.axis?.pane.isMain?tG.VOLUME_DETACHED_SCALE_MARGINS:super.getDetachedScaleMargins()}applySpecifics(e){let t=this.model.study;!0===sw(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?K.Percent:K.None;break}case"PERF":{let t="VisibleStart"===e.inputs.Anchor;this.axis.comparison=t?K.Percent:K.None;break}case"JPI":case"CTTP":case"CTTI":{let t=eM(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,eH(this.annotations)||(this.annotations=[]);let t=this.curves[1],i=this.curves[2],s=gU("VolumeAtPrice",!0,{[tG.AT_LINE]:{color:t.colors[0],width:t.lineWidth,dashStyle:t.dashStyle},[tG.AT_FILL]:{color:this.curves[0].colors[0]},[tG.AT_FILL2]:{color:this.curves[0].colors[1]},[tG.AT_FILL3]:{color:this.curves[0].colors[2]},[tG.AT_FILL4]:{color:i.colors[0]},[tG.AT_FILL5]:{color:i.colors[1]},[tG.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,eH(this.annotations)||(this.annotations=[]);let t=this.curves[1],i=this.curves[2],s=this.curves[3],r=gU("VolumeAtPrice",!0,{[tG.AT_LINE]:{color:t.colors[0],width:t.lineWidth,dashStyle:t.dashStyle},[tG.AT_FILL]:{color:this.curves[0].colors[0]},[tG.AT_FILL2]:{color:this.curves[0].colors[1]},[tG.AT_FILL3]:{color:this.curves[0].colors[2]},[tG.AT_FILL4]:{color:i.colors[0]},[tG.AT_FILL5]:{color:i.colors[1]},[tG.AT_FILL6]:{color:i.colors[2]},[tG.AT_FILL7]:{color:s.colors[0]}},this.id)(this.axis,!1);r.setOptions(e.inputs),this.annIndex=this.annotations.push(r)-1;break}case"IVRANK":{let t=af.ImplVolRank1Y;switch(e.inputs.TimeFrame){case"1-Year":default:break;case"5-Day":t=af.ImplVolRank5D;break;case"1-Month":t=af.ImplVolRank1M;break;case"3-Month":t=af.ImplVolRank3M;break;case"6-Month":t=af.ImplVolRank6M;break;case"YTD":t=af.ImplVolRankYTD}this.curves[0].fields[0]=t,e.outFields[0]=t;break}case"IVPCTL":{let t=af.ImplVolPerc1Y;switch(e.inputs.TimeFrame){case"1-Year":default:break;case"5-Day":t=af.ImplVolPerc5D;break;case"1-Month":t=af.ImplVolPerc1M;break;case"3-Month":t=af.ImplVolPerc3M;break;case"6-Month":t=af.ImplVolPerc6M;break;case"YTD":t=af.ImplVolPercYTD}this.curves[0].fields[0]=t,e.outFields[0]=t;break}case"OPTIV":{let t=[af.WeighImplVolHigh,af.WeighImplVol,af.WeighImplVolLow];switch(e.inputs.TimeFrame){case"1-Day":default:break;case"5-Day":t=[af.WeighImplVolHigh5D,af.WeighImplVol5D,af.WeighImplVolLow5D];break;case"1-Month":t=[af.WeighImplVolHigh1M,af.WeighImplVol1M,af.WeighImplVolLow1M];break;case"3-Month":t=[af.WeighImplVolHigh3M,af.WeighImplVol3M,af.WeighImplVolLow3M];break;case"6-Month":t=[af.WeighImplVolHigh6M,af.WeighImplVol6M,af.WeighImplVolLow6M];break;case"1-Year":t=[af.WeighImplVolHigh1Y,af.WeighImplVol1Y,af.WeighImplVolLow1Y];break;case"YTD":t=[af.WeighImplVolHighYTD,af.WeighImplVolYTD,af.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),eH(this.annotations)||(this.annotations=[]);let i=this.curves[11],s=this.curves[12],r=gU("ProbabilityCones",!0,{[tG.AT_LINE]:{color:i.colors[0],width:i.lineWidth,dashStyle:i.dashStyle},[tG.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)return null;let t=this.curves[0].colors;switch(e){case af.UPVOL:return t[1];case af.DNVOL:return t[0];case af.TOTVOL:return t[2];case af.POC:case af.VAREA:case af.BARBACK:return tG.COLOR_TRANSPARENT;default:throw Error("Unexpected Volume At Price field")}}isEmpty(){return!this.isVolAP&&super.isEmpty()}setCurveAttributes(e,t){let i=t=>this.curves[e].attributes=[W[t]];switch(t){case"LikeMain":{let t=this.axis.pane.presenter.mainPlot.curves[0].attributes,s=Sl().config.defaultVolumeBarColoring;eH(t)?this.curves[e].attributes=[t[0]]:i(eH(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(af.Buy)||e.includes(af.Sell)}getEventFor(e){switch(e){case af.Buy:return{show:!0,title:"B",color:"#03c03c"};case af.Sell:return{show:!0,title:"S",color:"#c23b22"};default:return null}}getEventFields(){return this.hasEvents?[af.Buy,af.Sell]:[]}async initialize(){if(this.model.basis!==tG.BASIS_MAIN)throw Error("Studies can currently only be based on the main (symbol) plot");return tW.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 cg&&(i=i.actual),this.timeSeries=fA(this.model.study,t,i),this._hasEvents=this.doesSeriesEmitEvents(),this.timeSeries.useNotifications=!0;let s=this.title,r=this.basePlot.timeSeries instanceof uX;return this.timeSeries.ready().then(e=>{e||r||this.timeSeries.computedServerSide||Si(`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}invalidateAssociatedAnnotations(e){this.isVolAP&&this.annotations[this.annIndex].invalidate(e)}onPriceDomainsUpdated(){this.invalidateAssociatedAnnotations("PriceDomainsChanged")}shouldPriceMap(e){return this.isJpi?!!this.shouldMaybePriceMap&&(e.id===af.JPIB.id||e.id===af.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(af.JPIB,t),n=s(af.JPIS,t);if(null===r&&i.id===af.JPIB.id||null===n&&i.id===af.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 gq=[af.Open,af.High,af.Low,af.Close,af.Volume];class gX extends ms{_expression;exprModel=null;symbols=null;errorText;get title(){return this.expression}get expression(){return this._expression}async parseExpression(){let e=nY(this._expression);if(this.exprModel=null,this.symbols=null,nz(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!eH(this.errorText)}#t(e){return{mapper:e=>e.query.symbol,loadMoreData:!0,recompute:F.Minimum,missing:H.UseNext,stretch:e=>!1,fieldMap:new Map(gq.map(e=>[e,e])),noDataApproach:B.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:e}}getTimeSeries(){let e=this.getInnerSeries(),t=this.axis?.pane.presenter.data?.exprSkipLeadingEmpty??!1,i=new pm(this.exprModel,e,this.#t(t));this.timeSeries=this.wrapIfAdvancedStyle(i);let s=this.title;this.timeSeries.ready().then(e=>{e||Si(`Unable to calculate expression: ${s}`,"error")})}getInnerSeries(){let e=nX(this.exprModel),t=Sl().getTimeSeriesDataSource();return e.map(e=>{let i=this.makeQuery();return i.symbol=e,t.getTimeSeries(i)})}getRecord(){if(eH(this.errorText))return;let e=this.metaData.inner.map(e=>[e.symbol,e.resolved]);this.record=new aD(e,eG(this.exprModel)),this.record.ready().then(e=>e)}getMetaData(){this.isValid&&(this.metaData=new is(this.symbols),this.metaData.ready().then(e=>{e&&(this.getRecord(),this.presenter?.notifyHost(am.MD_CHANGED,{plot:this}))}))}fromModel(e){super.fromModel(e),this._expression=e.expression}async initialize(){return tW.call(this,async()=>(await this.parseExpression(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}class gZ extends ms{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=nY(this.forward),t=nz(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=` (${ec(uP(this.offset),lW(tG.FMT_US_DATE_ONLY))(new Date)})`,this.outField=new ac(`Close_${this.offset}`,z.Number,j.Forward,`Close (${this.offset})`),this.curves[0].fields[0]=this.outField):(this.suffix="",this.outField=af.Close);let{yes:t,no:i}=eS(e.symbols,e=>tg(`${e}*1`)),s=(await Promise.all(t.map(e=>tL(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!eH(this.errorText)}getMetaData(){if(this.isValid){let e=Object.values(this.roots).flat();this.metaData=new is(e),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(am.MD_CHANGED,{plot:this})})}}getForwardPolicy(e){return{mapper:e=>e.query.root,loadMoreData:!1,recompute:F.Everything,missing:H.UseNext,stretch:e=>!1,fieldMap:new Map([[af.Close,this.outField]]),noDataApproach:B.NoAction,modelTransform:(e,t)=>null,skipLeadingEmpty:!1,valueProvider:e}}getTimeSeries(){let e=Sl().getTimeSeriesDataSource(),t=Object.keys(this.roots),i=0===this.offset?Z.Forward:Z.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 u2(this.symbols):void 0;this.timeSeries=new pm(this.fwdModel,s,this.getForwardPolicy(r)),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:er.Unspecified};this.presenter?.notifyHost(am.TS_MANYCHANGED,e)}})}async initialize(){return tW.call(this,async()=>(await this.parseForward(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}let gJ=e=>e.substring(0,e.lastIndexOf("::"));class gQ extends ms{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 nq(nJ(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 ac(`Close_${t}`,z.Number,j.Seasonal,`Close${this.suffix}`),this.curves[0].fields[0]=this.outField}applyOffset(e,t){let i=this.isPlain?e:function(e,t){let i=tg(e),s=tA(e),r=tS(e);if(i)return tx(e,t);if(s){let i=tT.exec(e),s=Number.parseInt(i[2]),r=tu(tr(new Date(s+(s>79?1900:2e3),0,1),t));return`${i[1]}${tb(r)}${i[3]}`}if(!r)return null;{let i=e.match(ty),s=tx(i[1],t),r=tx(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=nY(this.seasonal,!0),t=nz(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=tP(await tf(e));n.set(e,t)}s=nJ(s,e=>n.get(e));let a=(r=Array.from(n.values())).every(e=>tg(e)||tS(e)),o=r.every(e=>tA(e)),l=r.every(e=>!tg(e)&&!tA(e)&&!tS(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=nZ(s);let{model:u,symbols:h}=nY(this.isAverage?this.constructAverage(s):this.constructSeasonal(s,this.offset),!0);this.seaModel=u,this.hasComputation=nZ(u),this._seasonal=nq(nJ(u,gJ)),this.symbols=h,this.outField.name=this.outField.shortName=this.fixupFieldDescription()}get isValid(){return!eH(this.errorText)}getActualSymbols(){return[...new Set(this.symbols.map(gJ))]}fixupFieldDescription(){if(!this.hasComputation&&!this.isAverage){let e=gJ(this.symbols[0]);if(this.isPlain)return`${e} ${new Date().getFullYear()-this.offset}`;if(this.isFutures)return tP(e,!0)}return this.title}getMetaData(){if(this.isValid){let e=this.getActualSymbols(),t=1===e.length&&!this.hasComputation&&!this.isAverage,i=Sl().getMetaDataSource();this.metaData=t?i.getMetaData(e[0]):new is(e),this.metaData.ready().then(e=>{e&&this.presenter?.notifyHost(am.MD_CHANGED,{plot:this})})}}getNoDataApproach(){return this.isAverage&&!this.coreHasComputation?B.ModelTransformRequired:this.hasComputation?B.NoAction:B.IgnoreTimelineOnly}get seasonalPolicy(){return{mapper:e=>e.query.surrogate||e.query.symbol,loadMoreData:!1,recompute:F.Everything,missing:this.hasComputation?H.UsePrevious:H.UseNone,stretch:e=>this.shouldStretch(e),fieldMap:new Map([[af.Close,this.outField]]),noDataApproach:this.getNoDataApproach(),modelTransform:(e,t)=>0===t.length?this.seaModel:nY(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 tr(new Date,-e)}yearFromOffset(e){return tu(this.shiftYears(e))}getCmdtyRange(e){let t=this.shiftYears(e);return[tn(t),function(e){te(1,arguments);var t=ti(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=Sl().getTimeSeriesDataSource(),t=Object.keys(this.symbolToOffset).map(t=>{let i=this.makeQuery();return i.surrogate=t,i.symbol=gJ(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&&eH(...i.range)&&(i.range=i.range.map(e=>tr(e,-i.offset))),i.offset>0&&(i.disableStreamingUpdates=!0),e.getTimeSeries(i)});this.timeSeries=new pm(this.seaModel,t,this.seasonalPolicy),this.timeSeries.ready().then(e=>{if(e){let e={series:this.timeSeries,part:er.Unspecified};this.presenter?.notifyHost(am.TS_MANYCHANGED,e)}})}async initialize(){return tW.call(this,async()=>(await this.parseSeasonal(),!this.isShutDown&&(this.getMetaData(),this.getTimeSeries(),!0)))}}let g0=["bottom","right","left"],g1={bottom:"center",right:"start",left:"end"};class g2{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=eH(r);if(n=n||this.fontSize+this.padding+this.padding+(a?this.padding:0),!g0.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=g1[this.position],e.strokeStyle=this.strokeColor,e.fillStyle=ib(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+iH(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 g3=(e,t)=>e-1-t-4,g4=(e,t)=>e+1+t+4,g5=Array.from(Array(6),(e,t)=>++t).reverse();function g6(e){return e.curves.filter(t=>t.visible&&(e.type!==X.Study||t.style!==U.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===X.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 g7{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=e0(),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 g2({fontSize:this.config.fontSize,arrowLength:this.config.innerTickSize})}makePlot(e){let t=null;switch(X[e.type]){case X.Symbol:t=new mr;break;case X.Expression:t=new gX;break;case X.Study:t=new gK;break;case X.IncomeStatement:t=new mn(Z.IncomeStatement);break;case X.BalanceSheet:t=new mn(Z.BalanceSheet);break;case X.Forward:t=new gZ;break;case X.Seasonal:t=new gQ;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===K.None?t:this.pane.presenter.mainPlot.priceMap(t,void 0,af.Close,!0)}toTime(e){return this.pane.presenter.view.toTime(e)}toAnnotationPoint(e){return new mc(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===K.None?e:this.pane.presenter.mainPlot.priceMap(e,void 0,af.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===ei.Both||e.moveDirection===ei.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<=tG.SNAP_PROXIMITY_PIXELS).reduce((e,t)=>null===e||t.dist<e.dist?t:e,null);eH(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(eH(this.pane.presenter.view))return this.snapTo(e)}makeAnnotation(e,t=!0){let i=gU(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];eB(s.price)&&eB(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:eM(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=K[e.comparison??"None"],this.scale=q[e.scale??"Linear"],this.yScale=new f7(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:tG.ANN_DUPLICATE_OFFSET,y:tG.ANN_DUPLICATE_OFFSET}),t.appendAnnotation(i),i.requestRedraw(),this.fireAnnotationsChanged()}updateAnnotation(e,t){e.isSelected&&this.pane.presenter.clearSelection(),s7(e.name,t.traits),e.updateFrom(t.traits,t.extras,t.isUndoRedo?null:t.points,t.visible,t.locked),t.isUndoRedo&&eH(t.points)&&e.updateActivePoints(t.points),t.isUndoRedo||this.pane.presenter.undoRedoManager.done(mp(e,eo.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 eH(this._fullDomain)||(this._fullDomain=this.getDataDomain().domain),this._fullDomain}updateFullDomain(e=null){if(null===e&&this.comparison!==K.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=eH(t),l=o?a(t):0,u=eH(i),h=u?a(i):n.length-1,c=e.curves.map(e=>e.fields).flat().filter(e=>e.id!==af.Change.id),d=eH(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(!eH(i)||0===i.shift)return[l,h];if(!eH(p[i.id])){let e=i.shiftedTimeDomain;if(!eH(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(ev(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?ex(eL(t.map(e=>f(e)).reduce((e,t)=>t.map((t,i)=>(e[i]||0)+(t||0)),[])),m):t.map(e=>{ex(eL(f(e)),m)})});let S=el.None,T=[U.Column,U.MultiColumn,U.StackedColumn];if(o&&u&&!e.main&&e.curves.some(e=>T.includes(e.style))){let e=m[0]>0,t=m[1]<0;e?(S=el.Min,m[0]=0):t&&(S=el.Max,m[1]=0)}return{domain:m,clamped:S}}getDataDomain([e,t]=[null,null],i=[null,null]){let s=eG(i),r=!1;for(let i of this.plots.filter(e=>!e.hasDetachedScale)){let{domain:n,clamped:a}=this.getPlotDataDomain(i,e,t);eH(n)&&(ex(n,s),r=r||a!==el.None)}if(!eH(s))return{domain:null};let[n,a]=s;if(!eH(n,a))return{domain:null};let o=[Number(n),Number(a)];o[0]===o[1]&&(o[0]-=1,o[1]+=1);let l=el.None;return r&&(0===o[0]?l=el.Min:0===o[1]&&(l=el.Max)),{domain:o,clamped:l}}setDomain(){let e=this.pane.presenter,t=e.view.xAxis.xScale.domain();if(!eH(t))return;for(let e of this.plots.filter(e=>e.hasDetachedScale)){let{domain:i}=this.getPlotDataDomain(e,t[0],t[1]);eH(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=e$(e.display,!1,"chart","previous","forceVisible");eH(t,i)&&s&&(i[0]=Math.min(i[0],t),i[1]=Math.max(i[1],t))}if(this.yScale.domain(i),eH(i)){let e=this.getPadding(s);eH(e)&&this.yScale.padding(e)}}getInitialPadding(){let e=tD(this.pane.presenter.hostElement),t=tw(`#${tG.HEADER_SIZE_PLACEHOLDER_ID}`,e);if(!eH(t)){tR(t=tF(e,"div"),{display:"none"}),tN(t,{id:tG.HEADER_SIZE_PLACEHOLDER_ID,class:"bcharts-card bcharts-card-first"});let{lineHeight:i}=getComputedStyle(t);isNaN(Number.parseFloat(i))&&tR(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)+tG.CARDS_Y_OFFSET}getPadding(e){let t=this.pane.presenter,i=t.display,s=e$(i,null,"yAxis","minPaddingPercent"),r=e$(i,null,"yAxis","maxPaddingPercent"),n=eH(s),a=eH(r),o=n||a?0:this.getInitialPadding(),l=n?s:tG.PANE_CAP_MIN_PADDING_PERCENT,u=a?r:tG.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===el.Max?c[0]=tG.PANE_TINY_PADDING_PIXELS:e===el.Min&&(c[1]=tG.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=iH(e,1.3),r={height:i,approxLineHeight:s,domain:this.yScale.domain()};if(eH(this.ticks)&&eH(r.domain)&&eH(this.lastUsedOptions)&&eH(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=e$(Sl().config,null,"overrides","yAxis","tickProvider");if(eH(o)&&"function"==typeof o&&r.height>0&&eH(r.domain)){let e=eG(r);e.autoTicks=eG(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=hE(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(!eH(this.fullDomain))return tG.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(hE(this,t,!0)).width,n=Math.max(...this.fullDomain.map(r)),{innerTickSize:a,tickPadding:o}=this.config,l=eH(this.label)?iH(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(iD(e,this.viewBox),e.font=`${u} ${h}px ${t}`,e.lineWidth=2,e.strokeStyle=i.color,e.textAlign="end",eH(this.label)){e.save(),e.fillStyle=iE(.4)(s),e.translate(0,0);let t=this.onTheRight?1:-1;e.rotate(t*Math.PI/2),e.textAlign="center";let i=iH(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([]),iz(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=hE(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(X.Symbol)||e.is(X.Expression);if(o&&h){let t=e.axis.comparison===K.Percent?K.None:K.Percent;a=e.priceMapper(l,n,r,t)}let c=e.hasDetachedScale?e.metaData.format(t,r):void 0,d=eH(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;g6(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,af.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=ix(n),p=new g2({position:this.onTheRight?"right":"left",fontSize:this.config.fontSize,padding:this.config.indicatorPadding,fontFamily:s,textColor:d,strokeColor:n,backgroundColor:n}),f=r||hE(this,i),m=this.comparison===K.Percent;eV(a)&&(o=m?hC(this,a):hP(a)),p.draw(e,c,t,f,o)};a?u.forEach(c):g5.forEach(e=>u.filter(t=>t.priority===e).forEach(c))}}let g8=Symbol.for("__dloacip__");class g9{presenter;id;axes;height;alignedToYear;viewBox;constructor(e){this.presenter=e,this.axes=[],this.height=0,this.alignedToYear=null,this.id=e0()}fromModel(e){this.height=e.height,!0===e.alignOnExpirations&&(this.alignedToYear=function(e){let t=e.map(e=>e.plots).flat().filter(e=>X[e.type]==X.Symbol).map(e=>e.symbol).map(e=>tM(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 g7(this);return i.primary=0===t,i.fromModel(e),i},this)}getBounds(){return this.viewBox}setViewBox(e){this.viewBox=e}drawBackground(e){eH(this.viewBox)&&(this.drawAxes(e),e.save(),this.clipToNoScales(e),this.drawGrid(e),e.restore())}draw(e){eH(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[g8]&&function(e,{x:t,y:i,height:s,width:r}){if(!eV(mj))return;let{path:n,width:a,height:o,rect:l}=mj,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,af.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=iv(l);e.save(),e.strokeStyle=o,e.lineWidth=u,e.setLineDash(h),iY(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){iD(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(iv(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=iv(n);e.strokeStyle=r,e.setLineDash(a);let o=this.presenter.view.leftOffset,l=this.viewBox.width-this.presenter.view.rightOffset,u=iX();u.prolog(e),iY(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",iW(e,Sl().config.noDataText||tG.NO_DATA_TEXT,{x:this.viewBox.centerX,y:this.viewBox.centerY},J.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=!eH(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 ye(e,t){return{width:e,spacing:t,get totalWidth(){return this.width+this.spacing},offset:0}}class yt extends f1{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=ye(e$(i,tG.DEFAULT_BAR_WIDTH,"chart","bar","width"),e$(i,tG.DEFAULT_BAR_SPACING,"chart","bar","spacing")),this._extent=null,this.wasZoomed=!1,this.fitAllData=!1}extent(e){return f0.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(eH(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(!eH(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,hD)),[s-i+1,s]}adjustDomain(){if(!eH(this._range))return;this.scaleBarToFit();let e=this.deriveExtentsFromBarWidth(this.bar);eH(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,hD)):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>tG.MAXIMUM_BAR_WIDTH||i<tG.MINIMUM_BAR_WIDTH)return!1;let r=ye(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)=>eH(e)?e_(this.timeline,e,Number,hD,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(tG.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>=tG.INTRA_THRESHOLD)for(;r>0&&uC(i,s)<e;)r--,s=this.timeline.at(r);else if(!n.isTick){let t=Math.floor(e/tG.ONE_DAY_MILLIS),s=e=>gE(e,to(e)),n=s(i),a=i;for(;r>0;){let e=this.timeline.at(r),i=ng(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]=eQ(e,t,tG.MINIMUM_BAR_WIDTH,tG.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(){eH(this.resetBar)?(this.bar.width=this.resetBar.width,this.bar.spacing=this.resetBar.spacing):(this.bar.width=tG.DEFAULT_BAR_WIDTH,this.bar.spacing=tG.DEFAULT_BAR_SPACING),delete this.presenter.model.display.chart.bar,this.adjustDomain()}isUsableExtent(e){return eH(e)&&eH(e[0],e[1])&&e[0]>=0&&e[1]<this.timeline.withPrologEpilogLength&&e[1]-e[0]>=tG.MINIMUM_BARS_VISIBLE}shiftBars(e,t=null){if(!this._extent)return;let i=this._extent.map(t=>t+e);this.isUsableExtent(i)&&(eH(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(!eH(e)||!eH(e[0]))return[];let t=e[0].getTime();return this.timeline.presenter.allPlots.map(e=>e.timeSeries).filter(e=>!!eH(e)&&!!e.hasData&&0!==e.container.size&&!0===e.canLoadMoreData&&t<=e.container.getTimeData()[0].getTime())}}function yi(e){return{date:e,priority:1,text:hb(e)}}class ys{view;xScale;ticks;lastUsedOptions;wasPanned;panningXAxisAllowed;config;isVisible;crosshairIndicator;viewBox;overrideTickGetter;overrideFormatter;constructor(e){this.view=e,this.xScale=new yt(e.presenter.timeline,e.presenter.data.aggregation),this.ticks=null,this.lastUsedOptions=null,this.wasPanned=!1,this.panningXAxisAllowed=e$(e.presenter.display,!0,"xAxis","panning"),this.updateConfigFromModel();let t=e.presenter.renderTo.id,i=e$(Sl().config,null,"overrides","xAxis","tickProvider");eH(i)&&"function"==typeof i&&(this.overrideTickGetter=eu(i,t));let s=e$(Sl().config,null,"overrides","xAxis","formatter");eH(s)&&"function"==typeof s&&(this.overrideFormatter=eu(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 g2({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===tG.FIFTY_YEARS_MILLIS;eH(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!!eH(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=iH(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 $.Tick:return new hg(e);case $.Intraday:return new hy(e,e.agg.size);case $.Day:return new hS(e);case $.Week:return new hT(e);case $.Month:case $.Quarter:return new hA(e);case $.Year:return new hv(e);default:throw Error(`Aggregation unit ${$[e.agg.unit]} not supported.`)}}(e);return t?yi:e=>i.getTick(e)}getTicks(e){let t,i;if(eH(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&&eH(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(!eH(e)||Number.isNaN(e.getTime()))return null;let i=s(e);return eH(i)&&(i.index=r+t),i}).filter(e=>eH(e)),this.ticks}normalizeDuration(e){let t=function(){let e=Object.keys(hl);return 1===hl.Day.Multipliers[0]&&e.forEach(e=>{let t=hl[e],i=eJ(t.Period);t.One=+i,t.Multipliers=t.Multipliers.map(e=>e*i)}),hl}(),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<=(eb(n)+eP(a))/2){i=t[s[r]];break}}let r=i.Multipliers,n=r.findIndex(t=>e<t),a=-1===n?eb(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=iv(y);e.textAlign="center",e.font=`${l} ${u}px ${o}`,e.lineWidth=1,e.strokeStyle=g,e.fillStyle=i,e.setLineDash([]),iY(e,p,d,d+f);let T=this.xScale.extent(),A=e=>!eH(e)||!eH(e[0],e[1]);if(A(T))return;let v=t=>e.measureText(t).width,b=r>0?r:120,P=this.xScale.domain();if(A(P))return;let C=(P[1].getTime()-P[0].getTime())*b*.6/f,E=this.normalizeDuration(C),_=this.view.presenter.data.aggregation.isEndOfDay,L=d+f,M=({text:i,x:s,date:r,forced:n})=>{eH(r)&&(n||iz(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),iz(e,s,0,p),e.restore()))},x={agg:this.view.presenter.data.aggregation,unitWidth:v("M"),barWidth:this.xScale.bar.width,extent:T,formatString:n,minTickInterval:s||0,duration:C},I=this.getTicks(x),D={date:tG.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>L?L-s:r,e.forced=t!==r}else e.forced=!1;((e,t)=>{let i,r;if(e.date.valueOf()===tG.ZERO_DATE.valueOf())return!0;if(i=e.date,r=t.date,(eH(i)?uC(r,i):tG.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>b||!!_&&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(!eV(n))return;let a=n.getTimeData(),o=null===t?a:n.getData(t);if(!eH(o))return;let l=e_(a,+r[0],Number),u=e_(a,+r[1],Number,eE,l);if(l<u){s.save();let t=iX();t.prolog(s),s.strokeStyle=e.color,s.lineWidth=e.width,s.setLineDash(iv(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);eH(n,r)&&iz(s,n,0,this.viewBox.y),r=t}}t.epilog(s),s.restore()}}drawTimeTransitions(e){let t=this.xScale.domain();if(!eV(t)||!eH(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,af.Symbol,n,e),r.enabled&&(i?.data?.aggregation.isIntraday?this.drawTransitionsFor(r,af.TradingDay,n,e):i?.data?.aggregation.unit===$.Day?this.drawTransitionsFor(r,null,(e,t)=>!ny(e,t),e):i?.data?.aggregation.unit===$.Week&&this.drawTransitionsFor(r,null,(e,t)=>!nP(e,t),e))}getAnnXScore(e,t){return[ng,nb,ny,nP].map((i,s)=>(4-s)*Number(i(e,t))).reduce((e,t)=>e+t,0)}annTimeToX(e){let t=this.xScale.timeToIndex(e);if(!eV(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 iO(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=h_(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=g4(t.x,e.halfWidth)),o<l)e.x=g4(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=g3(e.x,t-n),s=g3(e.x,e.halfWidth-2);e.x=Math.max(s,i,g4(l,a?.halfWidth??0))}}(({x:e,halfWidth:t})=>e+t+4)(e)>t.x+t.width&&(e.x=g3(t.x+t.width,e.halfWidth))})}(r,this.viewBox),r.forEach(t=>{let s=ix(t.color);new g2({position:"bottom",fontSize:this.config.fontSize,fontFamily:i,padding:this.config.indicatorPadding,strokeColor:tG.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(!(eH(u)&&ov(u)))return!1;if(!r)return!0;t=this.xScale.timeToX(u);let h=iv(o);e.strokeStyle=a,e.setLineDash(h);let c=iX();if(c.prolog(e),iz(e,c.adjust(t),0,c.adjust(this.viewBox.y)),c.epilog(e),!n||!s.visible)return!0;let d=h_(i,u,eH(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 yr={mousedown:"onMouseDown",mousemove:"onMouseMove",mouseup:"onMouseUp",dblclick:"onMouseDblClick",contextmenu:"onContextMenu",mouseover:"onMouseEnter",mouseout:"onMouseLeave",wheel:"onWheel",touchstart:"onMouseDown",touchmove:"onMouseMove",touchend:"onMouseUp",keydown:"onKeyDown"},yn={Shift:"shiftKey",Alt:"altKey",Control:"ctrlKey",Meta:"metaKey"};class ya{view;subscriptions;constructor(e){this.view=e,this.subscriptions=[]}init(e){let t=eD();Object.keys(yr).filter(e=>!e.startsWith("touch")||t).forEach(t=>{let i=e=>{let i=yr[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=eD()&&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:ee.Left,offset:r,view:t.view,presenter:t,originalEvent:e,getModifier:t=>e[yn[et[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(eH(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(et[t])}}}let yo=ud.concat(af.PercentChange);class yl{view;id;isOptionsChart;constructor(e){this.view=e,this.isOptionsChart=!1,this.id=`bc-legend-${e0()}`}getLegendElem(){let e=this.view.el;return tV(this.id,e,"div")}update(){let e=this.getLegendElem(),t=hz(this.presenter.mainPane);if(!eH(t))return;this.isOptionsChart=this.mainPlot.title.startsWith(tG.FAKE_SYMBOL_PREFIX);let{left:i,right:s,top:r,width:n}=t;mU(e,"row",i,s,r,n),tH(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=yo.map(t=>e.getValue(t));if(eg(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=yo[t],r=this.format(e,s),n=hK(s);return`${this.spanAsName(n)}${this.spanAsValue(r,i)}`}).join(" "),r=this.spanAsValue(`(${this.format(eb(t),eb(yo))})`,i);return`${s} ${r}`}return""}maybeGetQuote(){if(this.mainPlot.isSymbol&&this.mainPlot.timeSeries?.record?.isValid){let e=Sl().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=Sl().getMetaDataSource().getMetaData(e.getActualSymbols()[0]);return this.getTitle(t,!0,e.id)}}getFirstColorBadge(e){return hF("rectangle",e.mainCurve.colors[0])}getLastValues(e){return this.isOptionsChart?"":g6(e).filter(e=>eH(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)?h$(e.id):"",n="All"===t||e.isSeasonal?"":this.getLastValues(e);return this.div(`${r} ${i} ${s} ${n}`)}).join(" "):""}}class yu{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 yl(this),this.draw=this.draw.bind(this),this.notifyLayoutChanged=function(e,t=100){var i,s;let r;return i=t=>eR(e,t),s=t,r=!1,function(...e){r||(i.apply(this,e),r=!0,setTimeout(function(){r=!1},s))}}(am.CH_CHTLAYOUTCHANGED,tG.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=>eH(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(eV(s))return void t.onMovePaneClicked(s);let r=this.findSvgParentWithClass(i,"delete-plot");if(eV(r))return void t.deletePlotClicked(r);let n=this.findSvgParentWithClass(i,"show-hide-plot");if(eV(n))return void t.showHidePlotClicked(n);let a=this.findSvgParentWithClass(i,"more-actions");if(eV(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),eH(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)),tR(this.el,{flex:1,display:"flex",position:"relative","flex-direction":"column","touch-action":"pan-x pan-y"}),this.tooltip=new mB(this);let s=Sl().config.getCustomEventPopup;this.customEventPopup=s?s(this):null;let{clientHeight:r,clientWidth:n}=this.el;this.width=n,this.height=r,this.canvasContainer=tF(this.el,"div"),tN(this.canvasContainer,{class:"chart-canvas-container"}),tR(this.canvasContainer,{flex:1,display:"flex","flex-direction":"column",position:"relative",height:"100%"}),this.mainCanvas=tF(this.canvasContainer,"canvas");let a={height:`${r}px`,width:`${n}px`,"z-index":2,position:"absolute",top:0,left:0};tR(this.mainCanvas,a),this.mouseCanvas=tF(this.canvasContainer,"canvas"),tN(this.mouseCanvas,{tabIndex:0}),a["z-index"]=3,a.outline="none",tR(this.mouseCanvas,a),this.goToLatestButton=tF(this.el,"button"),tk(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>`),tR(this.goToLatestButton,{position:"absolute",right:0,bottom:0,"z-index":3}),tN(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 ys(this),this.eventCapture=new ya(this),this.eventCapture.init(this.mouseCanvas),this.setChartSize(n,r);let o=tD(this.el);eH(tw(`.${tG.SVG_ICONS_DOM_NODE}`,o))||function(e){let t=tF(e,"div");tN(t,{class:tG.SVG_ICONS_DOM_NODE});let i=Object.keys(hw).map(e=>`<symbol id="${hH(e)}" viewBox="0 0 1024 1024">${hw[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&&tB(".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 ys(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`};tR(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=>{tN(e,r),tR(e,i)}),this.mainContext.scale(s,s),this.mouseContext.scale(s,s),this.recalculateLayout(),this.presenter&&mk(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=ef(r.map(e=>e.height)),a=0,o=tG.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 iO(0,a,this.width,u);e.setViewBox(h);let c=new iO(this.width-this.rightOffset,a,t,u),d=new iO(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 iO(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,l);this.splitters.push(e),a+=l}});let h=new iO(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,e);this.xAxis.setViewBox(h),tR(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=Sl().config.showGoToLatest,{showGoToLatest:t}=this.presenter.display.chart,i=eH(e)?e:t;this.goToLatestButton.style.display=i&&this.xAxis.canGoToLast()?"block":"none",this.mainContext.restore()}get isHostElementVisible(){return eH(this.el)&&eH(this.el.offsetParent)}redraw(e=!1){this.isHostElementVisible&&(e?this.draw():Sl().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=iL(e);return iI(iC(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 Q.Arrow:default:return"default";case Q.Crosshair:return"crosshair";case Q.Hand:return"pointer";case Q.Move:return"move";case Q.ResizeVertical:return"ns-resize";case Q.Grabbing:return"grabbing";case Q.ResizeHorizontal:return"ew-resize"}}(e);tR(this.el,{cursor:t})}shutdown(){this.listeners.forEach(e=>e()),this.eventCapture&&this.eventCapture.shutdown(),this.tooltip&&this.tooltip.remove(),this.el&&tB(".bcharts-card",this.el).forEach(e=>e.remove()),this.canvasContainer.remove()}getEventRadius(){return Math.max(this.xAxis.xScale.bar.width/2,tG.MIN_EVENT_RADIUS)}}class yh{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=tF(this.view.el,"div"),tN(this.popupElement,{id:`${this.view.presenter.elementId}-custom-event-host`}),tR(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=tF(this.popupElement,"a");tN(e,{class:"custom-event-close-button"}),tR(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()),tR(this.popupElement,{visibility:"visible",top:`${e.y}px`,left:`${e.x}px`,width:"310px"}),this.visible=!0}hideValue(){}hide(){this.visible&&(this.hideValue(),tR(this.popupElement,{visibility:"hidden"}),this.visible=!1)}}function yc(e,t){if(!(e.annotations&&e.annotations.length>0))return;let i=t.annotations||[];t.annotations=i.concat(e.annotations)}let yd='..axes{..plots{.type==="Study"}}';var cc=R("c15IW");let yp={ok:!1,change:void 0,toApply:void 0};class yf{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,mp(e,eo.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&&eV(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(!eH(e))return!1;switch(t){case eo.None:case eo.Undo:case eo.Redo:Si(`Unexpected tool change ${eo[t]} for undo/redo`,"warn");break;case eo.Created:i?this.delete(e):this.add(e);break;case eo.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?eo.Undo:eo.Redo;return eH(s)&&this.presenter.onAnnotationModifiedByTool(s,r),!0}can(e){let t=e?this.undoStack:this.redoStack;if(t.length<1)return yp;let i=eb(t),s=i.toolChange;if(!(e&&s!==eo.Deleted&&s!==eo.Created))return{ok:!0,change:s,toApply:i};let r=eC(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)?yp:{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 ym{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 yg(e={}){let t=this.allPlots;if(!t.every(e=>eH(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(af.DateTime,0),this.data.aggregation.isMultiContract&&!e.isExpression&&t.set(af.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?tG.FMT_ISO_DATE_ONLY:tG.FMT_EXPORT_ALL_BUT_MILLIS,o=(e,t)=>e===af.DateTime?o1(t,a):(eH(s,t)?eF(t,s):t)?.toString()??"",l={},u=this.timeline.lastSeriesIndex,h=eP(this.mainPlot.timeSeries.container.getTimeData()),c=e_(this.timeline,+h,Number,hD),d=(e,t)=>{let i=this.timeline.at(e),s=t.timeSeries.container,r=s.getTimeData(),u=e_(r,+i,Number,eE,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===af.DateTime)return o1(i,a);else return"";{let i=this.timeline.at(e-n),a=e_(r,+i,Number,eE,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]=`"${X[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(eu(d,e));null!==t&&f.push(t)}return f.join("\n")}function yy(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),eV(a)){let e=new ym(this);e.update(a),e.draw(l)}let h=this.mainPlot?.timeSeries.container?.getLastDataPoint(af.DateTime);if(eV(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:tG.CARDS_X_OFFSET,y:tG.CARDS_Y_OFFSET},c=hG(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===X[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(!(eV(r)&&eV(n)))return c(l.canvas);{let e=o(r,n);return e.drawImage(l.canvas,0,0,r,n),c(e.canvas)}}let yS=Symbol.for("__ias__");class yT{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=gU("Default"),this._activeTool=this.defaultTool,this.timeline=new hO(this),this.undoRedoManager=new yf(this),this.title=new ym(this),this.notifySelectionChanged=eN(am.CH_ANNSELECTIONCHANGED),this.notifyRecreated=eN(am.CH_RECREATED),this.notifyDefinitionChanged=eN(am.CH_DEFINITION_CHANGED)}getModel(){return this.model}get isEmpty(){return!eH(this.model)}notifyHost(e,t){eR(e,t)}async fromModel(e,t){if(this._isShutdown)return;eH(this.model)&&this.allPlots.forEach(e=>e.shutdown()),this.sentInitialLoadNotification=!1,this.clearSelection(),this.model=e;let i=eG(e);this.data=i.data,this.data.aggregation=nE(i.data.aggregation),this.display=i.display,eH(this.display.period)&&(this.display.period=eJ(this.display.period)),this.panes=i.panes.map(e=>{let t=new g9(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),eH(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(yb(nC(y0(s,t,i)),nC(y0(s,e,i)))||!yA(e.display?.xAxis?.visibleRange,t.display?.xAxis?.visibleRange)||e.display?.xAxis?.marginBars!==t.display?.xAxis?.marginBars||!yA(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=n1(t),n=n1(e);if(function(e,t){let i=e=>e.curves[0],s=i(e),r=i(t),n=yv.includes(s.style),a=yv.includes(r.style);if(n!==a)return!0;if(!a)return!1;if(s.style!==r.style)return!0;if(t.inputs&&yb(ej(e.inputs),ej(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(){eH(this.view)&&(this.view.shutdown(),this.view=void 0)}reinitializeView(){this._isShutdown||(eH(this.view)?this.view.reinitialize():(this.view=new yu,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){eH(this._activeTool.deactivated)&&this._activeTool.deactivated(this),this._activeTool=e,eH(this._activeTool.activated)&&this._activeTool.activated(this),this.notifyHost(am.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(!eH(r))return;let n=eH(r)&&r.main,a=!1,o=!1;if(e===am.TS_TIMELINECORRECTION){if(!this.timeline.tryToCorrectLastBar(t.from,t.to))return;a=!0}let l=eH(t.index)?i.container.getTimeData()[t.index]:null,u=e===am.TS_EVENTSCHANGED,h=this.view.xAxis,c=h.xScale;if(e===am.TS_MANYCHANGED||u){if(n&&this.data.checkRange)if(eH(this.display.xAxis.visibleRange)){let e={id:"Period",context:{range:this.display.xAxis.visibleRange}};e[yS]=!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===er.Tail){let e=e_(this.timeline,l,Number,hD);h.shouldScrollIntoView(e)&&c.shiftBars(t.count)}this.timeline.invalidate(),this.allPlots.forEach(e=>e.invalidatePriceMappingCache()),a=!0}else if(e===am.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===am.TS_DATAPOINTCHANGED&&(o=!0,r.isStudy&&r.invalidateAssociatedAnnotations("DataPointChanged"));if(!u&&s(this.mainPlot)&&i.hasData&&0===i.container.size&&this.notifyHost(am.CH_NODATAFORMAINSYMBOL,{chart:this.accessor}),a&&this.view.recalculateLayout(),o&&(a&&Si("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(),eH(l)&&e.updateFullDomain(l)})),!this.sentInitialLoadNotification&&e===am.TS_MANYCHANGED&&this.allPlots.every(e=>e.timeSeries&&e.timeSeries.hasData)){this.sentInitialLoadNotification=!0,this.notifyHost(am.CH_ALL_DATA_PROJECTED,{chart:this.accessor}),mk(this);let e=this.display.period===tG.FIFTY_YEARS_MILLIS;this.mainPlot&&e&&(c.fitAllData=!0,c.adjustDomain())}this.view.redraw()}onMetaChanged(e,t){e===am.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(am.CH_AXISSCALECHANGED,s)}get previousMask(){return eH(this._previousMask)||(this._previousMask=ay(af.PreviousClose)),this._previousMask}hasMatch(e,t){return e.some(e=>e.updated&&t)}get hasLegend(){return eH(this._hasLegend)||(this._hasLegend=Sl().config.mode===es[es.cmdtyView]),this._hasLegend}onStreamingUpdates(e){eH(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 eH(this._ohlcMask)||(this._ohlcMask=ay(af.Open,af.High,af.Low,af.Close,af.PreviousClose)),this._ohlcMask}updateMatches(e,t){if((e&this.ohlcMask)==0)return!1;let i=(e,t)=>eV(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 Sl().getRecordSource().subject.pipe(ub(e=>e.filter(e=>this.updateMatches(e.updated,e.data.symbol))),oT(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}get hostElement(){return this._hostElement}get elementId(){return eH(this._hostElement)?this._hostElement.id:null}initialize(t){if(this._hostElement=t instanceof HTMLElement?t:tw(`#${t}`),!this._hostElement)throw Error(`There is no element ${t} in the DOM`);this.renderTo=t,this.seriesChangedToken=e(cc).subscribe(am.TS_ALL,this.onSeriesChanged.bind(this)),this.metaChangedToken=e(cc).subscribe(am.MD_ALL,this.onMetaChanged.bind(this)),this.streamingSubscription=this.getStreamingSubscription()}shutdown(){return e(cc).unsubscribe(this.seriesChangedToken),e(cc).unsubscribe(this.metaChangedToken),eH(this.streamingSubscription)&&this.streamingSubscription.unsubscribe(),this.allPlots.forEach(e=>e.shutdown()),this.model=void 0,this.closeView(),this.notifyHost(am.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(){eH(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(Q.Arrow)}print(e={}){let t=tF(document.body,"iframe");t.src="",t.style.display="none",t.onload=()=>{let{title:i}=e,s=yy.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),eH(this.view)&&this.view.redraw(t)}enableTooltip(e){this.tooltipEnabled=e;let t=this.display.tooltip.mode===tG.TOOLTIP_CARDS;!e&&t&&this.hideCards()}get showTooltip(){return this.display.tooltip.visible&&this.tooltipEnabled}hideCards(e=!1){let t=this.display.tooltip,i=eD();!e&&t.visible&&t.mode===tG.TOOLTIP_CARDS&&tB(".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 sG(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,eo.Deleted);return}}throw Error(`Unknown sub-action ${e.id} for action ${tG.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:X[i[s].type],index:s}}getSimplePlot(e,t){return this.accessor.change({id:"Plot",context:{id:tG.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(am.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(am.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(am.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(am.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(am.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},sz(i,`..axes[${s.axisIndex}]`,e=>(e.annotations=s.annotations,e)));try{this.model=al(a,tG.CHART_SCHEMA)}catch(e){Si(`Cannot update annotation (corrupts definition), error is: ${e.message}`,"error")}t&&this.view.draw(),this.notifyHost(am.CH_ANNOTATIONCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}onAnnotationModifiedByTool(e,t,i=!0){if(t!==eo.None){if(i&&t!==eo.Undo&&t!==eo.Redo){let i=mp(e,t);this.undoRedoManager.done(i)}let s=mf(e);s.toolChange=eo[t],this.notifyHost(am.CH_ANNMODIFIEDBYTOOL,s)}}onAnnotationDone(e,t){let i={id:e,chart:this.accessor,toolChange:eo[t]};this.notifyHost(am.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=sz(i,(t=e.index,`..panes[${t}]`),t=>(t.height=e.relativeHeight,t))}),i),this.notifyHost(am.CH_PANEHEIGHTSCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}getDataStats(){let e=this.mainPlot.timeSeries.container;if(!eH(e)||0===e.size)return null;let t=e.getTimeData();return{dataRange:{from:eP(t).getTime(),to:eb(t).getTime()},barCount:e.size}}}function yA(e,t){return e?.from===t?.from&&e?.to===t?.to}let yv=["Renko","Range","LineBreak","Kagi","PointAndFigure"];function yb(e,t){for(let i of Object.keys(e))if(e[i]!==t[i])return!0}let yP="MARKED_FOR_DELETION";function yC(e,t){if(0===t.plots.length)return e;let i=e;return t.plots.forEach(e=>{let t=yL(e.index),s=yM(i,t);eH(s)&&s.type===e.type&&(i=sz(i,t,e=>(e[yP]=!0,e)))}),au(i=sz(i,`..plots{.${yP} === true}`,e=>tG.NULL_OBJECT))}function yE(e,{main:t,type:i,index:s},r){let n="..plots{.main === true}",a=sG(e,"..panes").map((e,t)=>{let i=1===sG(e,n).length;return sG(e,"..axes").map((e,s)=>{let a=1===sG(e,n).length;return sG(e,"..plots").map(e=>{let n=function(e,t,i,s){let r=X[e.type],n={curves:eG(e.curves),type:e.type};n.precision=e.precision,n.visible=e.visible;let a=(e,t)=>{eH(e[t])?n[t]=e[t].map(e=>eG(e)):n[t]=[]},o=(e,t,i=!1)=>{!0===t.main&&(e.main=!0,e.showPrevious=t.showPrevious,i&&null!=t.events&&(e.events=eG(t.events)))},l=(e,t=e=>!0)=>{eH(s)&&(e.subtitles=s.allPlots.filter(e=>e.type===r).filter(t).map(e=>e.title))};switch(r){case X.Symbol:{n.title=e.symbol;let t=n.curves[0].style,i=t=>{a(e,"inputs"),0===n.inputs.length&&(n.inputs=eG(t))};switch(t){case"Renko":i(tG.DEFAULT_RENKO_INPUTS);break;case"Kagi":i(tG.DEFAULT_KAGI_INPUTS);break;case"PointAndFigure":i(tG.DEFAULT_PNF_INPUTS);break;case"LineBreak":i(tG.DEFAULT_LINEBREAK_INPUTS);break;case"Baseline":i(tG.DEFAULT_BASELINE_INPUTS)}o(n,e,!0);break}case X.Study:{a(e,"inputs");let s=sw(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 X.BalanceSheet:case X.IncomeStatement:{let t=af[e.curves[0].fields[0]];n.title=`${t.name} (${e.fundamental.substring(0,1)})`,n.fundamentalId=t.id,n.frequency=e.fundamental;break}case X.Expression:n.title=e.expression,o(n,e);break;case X.Forward:n.title=e.forward,a(e,"offsets"),l(n),o(n,e);break;case X.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(!eH(i))return a;{let e=a.filter(e=>e.type===i);return eH(s)?e.filter(e=>e.index===s):e}}function y_(e,t){"Study"===e.type&&t.curves?.forEach(e=>delete e.varyColorPerBar),function(e){let t=X[e.type];return t===X.Forward||t===X.Seasonal}(e)?eH(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(ez(r,s),["shift","dashStyle","lineSmoothing","lineMarker"])){let t=s[e];eH(t)&&(r[e]=t)}}}(e.curves,t.curves);let i=X[t.type];eH(t.precision)?e.precision=t.precision:delete e.precision,i===X.Symbol?e.symbol=t.symbol:i===X.Study?(function(e,t,i){let s=ej(e),r=ej(t);ez(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===X.BalanceSheet||i===X.IncomeStatement)&&t.frequency?e.fundamental=t.frequency:i===X.Expression?eH(t.expression)&&(e.expression=t.expression):i===X.Forward?(eH(t.offsets)&&(e.offsets=t.offsets),eH(t.forward)&&(e.forward=t.forward)):i===X.Seasonal&&(eH(t.offsets)&&(e.offsets=t.offsets),eH(t.seasonal)&&(e.seasonal=t.seasonal),eH(t.usesInAverage)&&(e.usesInAverage=t.usesInAverage),ri(e))}let yL=e=>`..plots[${e}]`;function yM(e,t){let i=sG(e,t);return 1!==i.length?null:i[0]}let yx=["withMain","overlay","standalone","clone"];function yI(){return{plots:[]}}function yD(e){let t=e.display.chart.newPaneHeight??1;return{axes:[yI()],height:t}}function yO(e){let t=yD(e);return e.panes.push(t),t}function yw(e,t){let i=eV(t.paneIndex)&&t.paneIndex<e.panes.length?e.panes[t.paneIndex]:yO(e),s=i.axes[0];return t.oppositeScale?y$(i,s):s}function yR(e,t,i){let s=null,{mainPane:r,mainAxis:n}=n2(e);switch(t){case"withMain":s=y$(r,n);break;case"overlay":s=n;break;case"standalone":s=yO(e).axes[0];break;case"clone":if("number"==typeof i){let t={main:!1,index:i,type:X[X.Study]},r=yE(e,t).find(e=>e.index===t.index);s=sG(e,`..panes[${r.paneIndex}]..axes[${r.axisIndex}]`)[0]}}return s}let yN=[{fields:[af.Close.id],colors:["#888"],style:"Line",lineWidth:2,varyColorPerBar:!1,visible:!0}];function yV(e){return"Symbol"===e.type}let yH={attributes:["OpenVsClose"],colors:["#b63400","#007f3e","#1664db"],fields:["Open","High","Low","Close","Change"],style:"Candlestick",varyColorPerBar:!0,lineWidth:1},yF=0,yB=["#0d223a","#8abc21","#910000","#2f7ed8","#42ccdc","#bf95df","#860262","#e5daa3","#4682e8","#aaa9c1","#fcccdc","#f66b00","#d875be","#e84b46"],yk="Symbol";function yW(e,t){let i={curves:[{attributes:[],colors:yB.slice(yF,yF+1),fields:e?[af.Last.id]:[af.Close.id],style:"Line",dashStyle:"Solid",varyColorPerBar:!1,lineWidth:2,lineMarker:void 0,lineSmoothing:void 0}]};return delete t.oppositeScale,eY(i,t),eH(t.curves)&&ez(i.curves,t.curves),yF=(yF+1)%yB.length,i}let yU='..plots{(.type === "Symbol" || .type === "Expression") && .main !== true}';function y$(e,t){let i=e.axes.find(e=>e!==t);return eH(i)||(i=yI(),e.axes.push(i)),i}let yG=()=>tG.NULL_OBJECT;function yz(e){return sz(e,"..axes.annotations",yG)}function yY(e){return au(sz(e,'..plots{.type === "Symbol" && .main !== true}',yG))}let yj=".display.chart.previous";function yK(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==X[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 yq(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==X[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 yX(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 yZ(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 yJ={MainPlot:n9,Aggregation:{Update:ai,Get:function(e,t,i){return eG(e.data.aggregation)}},Period:{Update:function(e,t,i){let s=eH(t.period),r=eH(t.range),n=eH(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,nw(e),nN(e)),r)if((!eH(e.display.period)||an(e.display.period))&&(e.display.xAxis.visibleRange=t.range),nR(e),nN(e),eH(i)){let s=function(e){let t=e.getDataStats();return null===t?null:t.dataRange}(i),r=nE(e.data.aggregation),n=i.data.aggregation,a=r.unit!==n.unit||r.size!==n.size||r.spec!==n.spec||!eH(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,nw(e),nR(e)),(s||r||n)&&(nO(e),i&&(i.forceResetVisibleRange=!0)),e},Delete:function(e,t,i){return eH(t.period)&&t.period&&(delete e.display.period,ae(e),i&&(i.forceResetVisibleRange=!0)),e}},Crosshair:{Update:function(e,t){let[i,s]=ek(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=sz(e,".display.xAxis.crosshair",e=>(e.enabled=i,l(e,a,o),e));return u=sz(u,".display.yAxis.crosshair",e=>(e.enabled=s,l(e,r,n),e)),eH(t.haloTracking)&&"boolean"==typeof t.haloTracking&&(u=sz(u,".display.chart",e=>(e.plotHover=t.haloTracking,e))),u},Get:function(e,t,i){let s=t=>sG(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 sz(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=sG(e,".display.tooltip")[0];return{visible:s.visible,mode:s.mode,showMainTitle:s.showMainTitle,mainTitle:s.mainTitle}}},Events:function(e,t){let i=eG(t);return Object.keys(t).forEach(e=>{tG.EVENTS.includes(e)||delete i[e];let s=t[e];"boolean"==typeof s?s={show:t[e]}:Object.keys(s).forEach(e=>{tG.EVENT_PROPERTIES.includes(e)||delete s[e]}),i[e]=s}),sz(e,n0,e=>("Symbol"===e.type&&(e.events=e.events||{},Object.keys(i).forEach(t=>{e.events[t]=e.events[t]||{},ez(e.events[t],i[t],!1)})),e))},Scale:{Update:function(e,t){let i=sz(e,"..panes[0]..axes",e=>(eV(t.scale)&&(e.scale=t.scale),e));return i=sz(i,".display.xAxis",e=>(eV(t.marginBars)&&(e.marginBars=t.marginBars),eV(t.nonEodLabelWithDate)&&(e.nonEodLabelWithDate=t.nonEodLabelWithDate),eV(t.ordinalName)&&(e.ordinalName=t.ordinalName),eV(t.preventHorizontalLabelOverlap)&&(e.preventLabelOverlap=t.preventHorizontalLabelOverlap),e)),i=sz(i,".display.yAxis",e=>{(eH(t.minPadding)||eH(t.maxPadding))&&Si("The 'minPadding' and 'maxPadding' are deprecated (ignored)","warn");let i=eV(t.preventLabelOverlap)&&!eV(t.preventVerticalLabelOverlap);i&&Si("The 'preventLabelOverlap' is deprecated, please use 'preventVerticalLabelOverlap'","warn");let s=i?t.preventLabelOverlap:t.preventVerticalLabelOverlap;return eV(s)&&(e.preventLabelOverlap=s),eH(t.includePercentChangeWithLastValue)&&(e.includePercentChangeWithLastValue=t.includePercentChangeWithLastValue),eH(t.snapAnnotationsToPrices)&&(e.snapAnnotationsToPrices=t.snapAnnotationsToPrices),e}),eH(t.labels)&&Array.isArray(t.labels)&&t.labels.forEach(e=>{let{axis:t,text:s,index:r,paneIndex:n}=e;eH(t,s,r)&&"vertical"===t&&Number.isInteger(r)&&(i=sz(i,`..panes[${n??0}]..axes[${r}]`,e=>eH(e)?(e.label=s,e):tG.NULL_OBJECT))}),eV(t.contractTransition)&&(i=sz(i,".display.xAxis",e=>(ez(e.contractTransition,t.contractTransition),e))),eV(t.cycleTransition)&&(i=sz(i,".display.xAxis",e=>(ez(e.cycleTransition,t.cycleTransition),e))),i},Get:function(e,t,i){let{mainAxis:s}=n2(e),r=sG(e,".display.xAxis")[0],n=sG(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(eH(t.comparisonMode)&&"string"==typeof t.comparisonMode&&eU(K,t.comparisonMode)&&(s=sz(s,`..panes{${n0}}.axes`,e=>(e.comparison=t.comparisonMode,e))),eH(t.gridLines)){let[e,i]=ek(t.gridLines);s=sz(s,".display.xAxis.gridLines",t=>(t.visible=e,t)),s=sz(s,".display.yAxis.gridLines",e=>(e.visible=i,e))}if(eH(t.minorGridLines)){let[,e]=ek(t.minorGridLines);s=sz(s,".display.yAxis.minorGridLines",t=>(t.visible=e,t))}eH(t.newPaneHeight)&&"number"==typeof t.newPaneHeight&&(s=sz(s,".display.chart{.newPaneHeight > 0}",e=>(e.newPaneHeight=t.newPaneHeight,e))),eH(t.showNavigator)&&"boolean"==typeof t.showNavigator&&(s=sz(s,".display.scrollbar",e=>(e.visible=t.showNavigator,e))),eH(t.plotHover)&&"boolean"==typeof t.plotHover&&(s=sz(s,".display.chart",e=>(e.plotHover=t.plotHover,e))),eH(t.showLastValue)&&"string"==typeof t.showLastValue&&(s=sz(s,".display.yAxis",e=>(e.showLastValue=t.showLastValue,e))),eH(t.showMinMaxArc)&&"boolean"==typeof t.showMinMaxArc&&(s=sz(s,".display.chart",e=>(e.showMinMaxArc=t.showMinMaxArc,e))),eH(t.showGoToLatest)&&"boolean"==typeof t.showGoToLatest&&(s=sz(s,".display.chart",e=>(e.showGoToLatest=t.showGoToLatest,e))),eH(t.showLegend)&&"boolean"==typeof t.showLegend&&(s=sz(s,".display.chart",e=>(e.showLegend=t.showLegend,e)),t.showLegend||i.view.removeLegend()),eH(t.allAnnotationsLocked)&&"boolean"==typeof t.allAnnotationsLocked&&(s=sz(s,".display",e=>(e.allAnnotationsLocked=t.allAnnotationsLocked,e))),eH(t.exprSkipLeadingEmpty)&&"boolean"==typeof t.exprSkipLeadingEmpty&&(s=sz(s,".data",e=>(e.exprSkipLeadingEmpty=t.exprSkipLeadingEmpty,e)));let r=[];if(eH(t.extendedHours)&&"boolean"==typeof t.extendedHours&&(s=sz(s,".data",e=>(e.extendedHours=t.extendedHours,e))),eH(t.realTimeCboeBzx)&&"boolean"==typeof t.realTimeCboeBzx&&(s=sz(s,".data",e=>(e.realTimeCboeBzx!==t.realTimeCboeBzx&&r.push("realTimeCboeBzx"),e.realTimeCboeBzx=t.realTimeCboeBzx,e))),eH(t.buildContinuation)&&"boolean"==typeof t.buildContinuation&&(s=sz(s,".data",e=>(e.buildContinuation=t.buildContinuation,e))),r.length>0){let e={chart:i.accessor,hostPropsChanged:r};i.notifyHost(am.CH_HOST_PROPS_CHANGED,e)}return s},Get:function(e,t,i){let s=sG(e,`..panes{${n0}}.axes.comparison`)[0],r=e.display,n=(e,t)=>e$(e,!1,t,"visible"),a=e=>(function(e,t){let i=e=>eH(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=e$(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=sw(t.studyId);if(!eV(i))return Si(`Unknown or unavailable study with the id '${t.studyId}'`,"error"),e;let s=n1(e),r=sH(i);if(s.type===X[X.Expression]&&r)return Si(`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),y_(a,t);let o=yR(e,n,t.cloneIndex);eH(o)&&o.plots.push(a);let l=e.data.aggregation;return at(e,"Tick"===l.unit&&"None"===l.spec)}(e,t);case"IncomeStatement":case"BalanceSheet":return function(e,t){let i=n1(e);if(i.type!==X[X.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:j[af[t.fundamentalId].category],visible:!0};return y_(r,t),e.panes.push({axes:[{plots:[r]}]}),e}(e,t);case"Expression":let i=n1(e),s={curves:eG(yV(i)?i.curves:yN),expression:"",type:"Expression",visible:!0};return y_(s,t),yw(e,t).plots.push(s),e;case"Symbol":return function(e,t){let i=n1(e),s=Sl().getDefaultMultiFieldCurve(),r=eH(s)?s:yH,n=i.curves?.length,a={curves:n===t.curves.length&&1===n?eG(yV(i)?i.curves:[r]):t.curves,symbol:"",type:"Symbol",visible:!0};return y_(a,t),yw(e,t).plots.push(a),e}(e,t);case"Seasonal":let r={curves:eG(yN),offsets:[0],seasonal:"",type:"Seasonal",visible:!0,main:!1};return y_(r,t),t.paneIndex=t.paneIndex??0,yw(e,t).plots.push(r),e;default:throw Error("Unexpected plot type '${type}', not supported currently")}},Get:yE,Delete:yC,Update:function(e,t,i){if(eH(t.placement)&&!yx.includes(t.placement))throw Error(`Unknown placement: ${t.placement}`);let s=t.main?n0:yL(t.index),r=yM(e,s);if(!eV(r)||eV(t.type)&&r.type!==t.type)return e;if(eV(t.visible))return r.visible=t.visible,e;if(r.main&&function(e){let t=X[e.type];return t===X.Symbol||t===X.Expression}(r)){if(t.curves){let i=e=>e.curves[0].style===U[U.Range],[s,n]=[i(r),i(t)];s&&!n?e=ai(e,{unit:"Day",size:1,spec:"None"}):!s&&n&&(e=ai(e,{unit:"Intraday",size:100,spec:"PerRange"}))}return t.type||(t.type=r.type),eH(t.precision)?r.precision=t.precision:delete r.precision,eH(t.showPrevious)&&(e=sz(e,n0,e=>(e.showPrevious=t.showPrevious,e))),t.curves?nB(e,t):e}{let r=sz(e,s,e=>(y_(e,t),e)),n=yE(r,t,i).find(e=>e.index===t.index);if(!eH(n))return e;if(!(t.type===X[X.Study]&&eH(t.placement)&&t.placement!==n.placement))return r;let a=yM(r,s),o=yR(r=yC(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}=eS((eH(t.symbols)&&(Si("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=yk,e))),t.plots?.some(e=>eH(e.leftScale)))?(Si("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}=n2(e);r.alignOnExpirations=t.alignOnExpirations||!1;let a=y$(r,n),o=e=>![yk,"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;yF=0;let h=eu(yW,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),au(e)},Get:function(e,t){let i=sG(e,yU),{mainPane:s,mainAxis:r}=n2(e),n=[];for(let e of i){let t=r.plots.includes(e),i=e.type.toLowerCase(),s={curves:eG(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=sG(e,"..panes").map((e,t)=>sG(e,"..axes").map((e,i)=>sG(e,".annotations").map(e=>({...e,paneIndex:t,axisIndex:i})))).flat(2).map((e,t)=>({...e,index:t}));return eH(t.index)&&Number.isFinite(t.index)?t.index<s.length?[s[t.index]]:tG.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=eG(e);if(t.strip.main){let e=n1(i),t=e.type.toLowerCase();e[t]=tG.PLACEHOLDER_SYMBOL_NAME}return t.strip.annotations&&(i=yz(i)),t.strip.compare&&(i=yY(i)),i=sz(i,".data",e=>(e.range&&(delete e.range,e.checkRange=!0),e))},Outline:function(e,t,i){let s=yE(e,{main:!0},i)[0],r=s.title===tG.PLACEHOLDER_SYMBOL_NAME,n="Symbol"===s.type,a="Expression"===s.type,o=nY(s.title),l=[];return a&&!nz(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:sG(e,yU).map(e=>e.symbol),annotations:sG(e,"..annotations").map(e=>e.id),studies:yE(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=sz(e,".display.chart",e=>(s&&(e.backgroundColor=s),u&&(e.fontSize=u),e))),r){let e=e=>(e.color=r,e);i=sz(i,".display.xAxis.gridLines",e),i=sz(i,".display.yAxis.gridLines",e),i=sz(i,".display.yAxis.minorGridLines",e)}if(o){let e=e=>(e.dashStyle=o,e);i=sz(i,".display.xAxis.gridLines",e),i=sz(i,".display.yAxis.gridLines",e),i=sz(i,".display.yAxis.minorGridLines",e)}if(n){let e=e=>(e.textColor=n,e);i=sz(i,".display.xAxis",e),i=sz(i,".display.yAxis",e)}if(a){let e=e=>(e.color=a,e);i=sz(i,".display.xAxis.crosshair",e),i=sz(i,".display.yAxis.crosshair",e)}if(h||c){let e=e=>t=>(t.fontSize=e,t);h&&(i=sz(i,".display.xAxis",e(h))),c&&(i=sz(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=>tG.NULL_OBJECT;return!0===r&&(i.allAnnotations.forEach(e=>i.onAnnotationModifiedByTool(e,eo.Deleted,!1)),l=sz(l,`${o}..annotations`,u)),!0===n&&(l=sz(l,`${o}..plots{.type=="Study"}`,u)),l=au(l)},Previous:{Update:function(e,t,i){return sz(e,yj,e=>(ez(e,t),e))},Get:function(e,t,i){return sG(e,yj)[0]}},MovePlot:{Update:function(e,t,i){if(!yK(e,t,i).includes(t.targetPane))return e;let s=yZ(i,t.index),r=yM(e,yL(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,yD(e)),a=!1;break;case"ExistingBelow":n++;break;case"NewBelow":n++,a=!1,e.panes.splice(n,0,yD(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(yI());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=yX(e,s.pane);return au(h=yX(h,n))},Get:yK},PinPlot:{Update:function(e,t,i){if(!yq(e,t,i).includes(t.targetAxis))return e;let s=yZ(i,t.index),r=e.panes[s.pane],n=yM(e,yL(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(yI()),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 au(yX(e,s.pane))},Get:yq}};function yQ(e){return"function"==typeof e}function y0(e,t,i){return(function(e,t){let i=yJ[e];if(yQ(i))return i;{let e=void 0!==t?i[t]:void 0;if(!yQ(e)&&!yQ(e=i[tG.DEFAULT_ACCESSOR_SUBACTION]))throw Error("Invalid accesor id and/or sub id");return e}})(e.id,e.context.id)(t,e.context,i)}function y1(e){return{id:"MainPlot",context:e}}let y2={keepOldAnnotations:!1,keepNewAnnotations:!0,keepOldCompare:!1,keepNewCompare:!0,keepOldAggregation:!1,keepNewBarWidth:!1},y3=Symbol.for("__ias__");class y4{headless;presenter;_model;constructor(e=!1){this.headless=e,this.presenter=e?null:new yT(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),eV(t)){let e="string"==typeof t;e?Si("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(y1(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(eH(e)){s8(e,t),s7(e,t);let s=gU(e,!1,t,i,this.presenter);s.isDrawingAnnotation&&this.presenter.view.setCursor(Q.Crosshair),this.presenter.activeTool=s,eD()||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 Su()}get model(){return(this.headless?this._model:this.presenter.getModel())||Su()}asTemplate(e={main:!0,annotations:!1,compare:!1}){return this.change({id:tG.ACTION_TEMPLATE,context:{strip:e}})}change(...e){let t={chart:this,actions:e.filter(e=>!e[y3])};t.actions.length>0&&this.presenter?.notifyHost(am.CH_API_ACTIONS_RECEIVED,t);let i=Sl().config.validateInput,s=e.map(e=>i?al(e,tG.ACCESSOR_SCHEMA):e);if(1===s.length){let e=s[0];if(e.id===tG.ACTION_TEMPLATE||e.context.id===tG.ACTION_GET)return y0(e,this.model,this.presenter);if(!this.headless&&e.id===tG.ANN_ACTION_ID)return this.presenter.handleAnnotationChange(e.context)}let{yes:r,no:n}=eS(s,e=>e.id===tG.ACTION_PLOT&&eH(e.context)&&e.context.id===tG.ACTION_DELETE),a=eG(this.model),o=eG(this.model);r.length>0&&n.push({id:tG.ACTION_PLOT,context:{id:tG.ACTION_DELETE,plots:r.map(e=>e.context)}}),n.forEach(e=>{if(!eH(o=y0(e,o,this.presenter)))throw Error("Forgot to return model from accessor")}),this.fromModel(o,a)}async fromModel(e,t){let i=al(e,tG.CHART_SCHEMA);this.headless?this._model=i:await this.presenter?.fromModel(i,t)}async load(e,t){let i={...y2,...t},s=al(JSON.parse(e),tG.CHART_SCHEMA),r=this.model,n=eG(r);if(eH(r)){if(s=function(e,t,i){let s=n1(t),r=s.type.toLowerCase();if(s[r]===tG.PLACEHOLDER_SYMBOL_NAME){let s=n1(e),{mainAxis:r}=n2(t),n=r.annotations,a=n9(t,s);if(i){let{mainAxis:e}=n2(a);e.annotations=n}return a}return t}(r,s,i.keepNewAnnotations),i.keepNewAnnotations||(s=yz(s)),i.keepOldAnnotations&&(s=function(e,t){let{mainAxis:i}=n2(e),{mainAxis:s}=n2(t);yc(i,s);let r=e=>sG(e,'..plots{.type==="Study"}.study')[0],n=sG(e,yd).filter(e=>e!==i),a=sG(t,yd).filter(e=>e!==s);return n.forEach(e=>{let t=r(e),i=a.find(e=>t===r(e));eH(i)&&yc(e,i)}),t}(r,s)),i.keepNewCompare||(s=yY(s)),i.keepOldCompare&&(s=function(e,t){let i=sG(e,yU),s=sG(t,yU),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}=n2(t),{mainAxis:l}=n2(e);return n.forEach(e=>{l.plots.includes(e)?o.plots.push(e):y$(a,o).plots.push(e)}),t}(r,s)),i.keepOldAggregation){let e={id:tG.ACTION_AGGREGATION,context:r.data.aggregation},t=s.display.density;s=y0(e,s,this.presenter),i.keepNewBarWidth&&eH(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=Su();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}),eH(s)){let i=y0({id:"Theme",context:{id:"Get"}},this.model,this.presenter),r=y0(y1(s),t,this.presenter);e&&(r=y0({id:"Theme",context:i},r,this.presenter)),this.presenter?.fromModel(r)}}this.clearUndoRedo(),this.presenter?.notifyHost(am.CH_RESET,{elementId:this.elementId})}print(e={}){this.headless||this.presenter.print(e)}getSVGForExport(){Si("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:yg.call(this.presenter,e)}exportImage(e={}){return this.headless?null:yy.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(eH(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(am.CH_DIDBECOMEACTIVE,{chart:this})}}var cc=R("c15IW");function y5(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 y6(e,t){return e+Math.random()*(t-e)}let y7=Function(atob("Y29uc29sZS5sb2coIlBsZWFzZSBjb250YWN0IEJhcmNoYXJ0IGluIG9yZGVyIHRvIG9idGFpbiB0aGUgbGljZW5zZSBmb3IgdGhlIGNoYXJ0IGNvbXBvbmVudC4iKTsg")),y8=Function("f",atob("Zi5yZW1vdmVBbGxDaGFydHMoKTsg")),y9=Function("m",atob("cmV0dXJuIG0gPT09ICJJbnRlcm5hbEZlZWQiIHx8IG0gPT09ICJXaWRnZXQiIHx8IG0gPT09ICJGcmVlV2lkZ2V0IiB8fCBtID09PSAiRGVtb1NpdGUiOw=="));async function Se(e,t){if(t&&!y9(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=>!eH(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(y7,y6(2e3,3e3)),setTimeout(()=>y8(Sl()),y6(4e3,5e3)))}var St={};function Si(e,t="info",i=""){let s=globalThis.console,r=void 0!==s[t];s[r?t:"log"](e,i)}St=JSON.parse('{"major":2,"minor":354,"patch":3,"prerelease":false}');let Ss={environment:"Browser",validateInput:!1,throttleMillis:0,isAlt64:!0,defaultTemplate:`/${tG.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(y9(this.mode)&&this.knownSite){let{username:r,password:n}=this.credentials||{},a=eH(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 Sr(e,t){let i=Sl()?.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 Sn=!1,Sa=null;function So(t,i={}){if(Sn)throw Error("You should only call initFeed once during page's lifetime");Sn=!0;let s=Object.assign(Ss);return ez(s,i),eV(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(eV(s)&&eV(r)){let e=s.split(" ").map(Number);4===e.length&&e.every(Number.isFinite)&&(mj={path:new Path2D(r),width:e[2],height:e[3],rect:new iO(0,0,0,0),logoClickable:t})}}(s.logo,s.logoClickable??!1),!function(e){var t;let i=e.extensions?.studyProvider;if(!eH(i))return;let s=i.getFields(),r=i.getStudies(),n=eG(s_(tG.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=tG.CHART_SCHEMA,ao.addSchema(t,n),ap(s),sI(r)}(s),(Sa=new t(s)).version=function(){let t=e(St),i=t.prerelease?`-${t.prerelease.identifier}.${t.prerelease.ordinal}`:"";return`${t.major}.${t.minor}.${t.patch}${i}`}(),Si(`%cBarchart Chart version ${Sa.version}`,"info","font-size: larger"),Sa.cachesData&&(Sa.subject?.subscribe(Sa.onPerformInternalGc.bind(Sa)),e(cc).subscribe(am.CH_ALL,Sa.onChartChanged.bind(Sa))),Sa}function Sl(){return Sa}function Su(){return eG(Sl()?.template)}function Sh(){eV(Sa)&&(Sa.shutdown(),Sn=!1,Sa=null)}function Sc(e){let t=new y4(!0);return t.load(e),t.change({id:"Outline",context:{id:"Get"}})}function Sd(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 Sp{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=e0()}get subject(){return this.isAuxiliary||eV(this._subject)||(this._subject=new od().pipe(function(e){for(var t,i,s=[],r=1;r<arguments.length;r++)s[r-1]=arguments[r];var n=null!=(t=ou(s[s.length-1])?s.pop():void 0)?t:aQ,a=null!=(i=s[0])?i:null,o=s[1]||1/0;return of(function(t,i){var s=[],r=!1,l=function(e){var t=e.buffer;e.subs.unsubscribe(),a$(s,e),i.next(t),r&&u()},u=function(){if(s){var t=new aG;i.add(t);var r={buffer:[],subs:t};s.push(r),y5(t,n,function(){return l(r)},e)}};null!==a&&a>=0?y5(i,n,u,a,!0):r=!0,u();var h=om(i,function(e){var t,i,r=s.slice();try{for(var n=aV(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)})}(tG.INTERNAL_GC_MILLIS),oT(e=>e.length>0))),this._subject}get isAuxiliary(){return null!==window.opener}setAltDataSource(e){this._altDataSource=e,this.timeSeriesSource=Sd(this.timeSeriesSource,"getTimeSeries",e,"symbol"),this.metaDataSource=Sd(this.metaDataSource,"getMetaData",e),this.recordSource=Sd(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(!eV(this.timeSeriesSource))throw Error("No time series source defined");return this.timeSeriesSource}getMetaDataSource(){if(!eV(this.metaDataSource))throw Error("No metadata source defined");return this.metaDataSource}getRecordSource(){if(!eV(this.recordSource))throw Error("No record source defined");return this.recordSource}async ready(){return tW.call(this,async()=>{await Se(this.config,this instanceof SS||this instanceof Sf||this instanceof Sb);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=al(e,tG.CHART_SCHEMA),!0})}getHeadlessChart(){return new y4(!0)}fixupRenderTo(e){if(!eV(e))return null;if(e instanceof HTMLElement)return e;let t=tw(`#${e}`);if(eV(t))return t;let i=[...this.charts.keys()].find(t=>t.id===e);return eV(i)?i:null}checkChart(e,t){let i=this.fixupRenderTo(e),s=eV(i)&&this.charts.has(i);return eV(t)&&t!==s&&Si(`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 y4;return this.charts.set(i,s),s.initialize(e,t),s}removeChart(e){let t=this.checkChart(e,!0);eV(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 eV(t)?this.charts.get(t):null}redraw(e){let t=this.checkChart(e,!0);eV(this.ongoingAnimationCallbackId)||(this.ongoingAnimationCallbackId=requestAnimationFrame(this.drawCharts)),eV(t)&&this.pendingRedraw.add(t)}drawCharts(){this.ongoingAnimationCallbackId=null,this.pendingRedraw.forEach(e=>{let t=this.getChart(e);if(!eV(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=>{eV(t)&&(eV(t.record)?e.records.add(t.record):eH(t.records)&&Object.values(t.records).forEach(t=>e.records.add(t)))}),e}clearCaches(){this.evictUnused(this.emptyEntities)}refreshCaches(){this.getTimeSeriesDataSource().refresh(),eR(am.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===am.CH_RECREATED||e===am.CH_SHUTDOWN)&&(this.isAuxiliary?this._mainFeed?.triggerGc():this.triggerGc())}getDefaultMultiFieldCurve(){if(!eV(this.template))return null;if(!this.knowDefaultCurve){let e=n1(this.template);1===e.curves.length&&function(e){switch(U[e]){case U.OHLC:case U.HLC:case U.Candlestick:case U.HollowCandles:case U.HeikinAshi:case U.ElderImpulseSystem:case U.Range:case U.MultiColumn:return!0;default:return!1}}(e.curves[0].style)?this.defaultOhlcCurve=eG(e.curves[0]):this.defaultOhlcCurve=null,this.knowDefaultCurve=!0}return this.defaultOhlcCurve}getDefaultAggregation(){return!this.knowDefaultAggregation&&this.template&&(this.defaultAggregation=eG(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 Sf extends Sp{constructor(e){super(e),this.timeSeriesSource=new u6(!1),this.metaDataSource=new ia,this.recordSource=new lD}}class Sm extends Sp{constructor(e){super(e),this.timeSeriesSource=new u6(!0),this.metaDataSource=new ia,this.recordSource=new lO}}class Sg extends Sp{constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u6(!0),this.metaDataSource=new ia,this.recordSource=new lD}}let Sy=["drazen.dotlic@barchart.com","princec","b.hebert24@barchart.com"];class SS extends Sp{lastStreamingTimestamp=null;_isActivelyStreaming=null;needToResubscribe=!1;_connection;constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u6(!0),this.metaDataSource=new io,this.recordSource=new lw,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,eV(e)&&this.initializeStreaming()}addChart(e,t=null){return this.needToResubscribe&&this.initializeStreaming(),super.addChart(e,t)}set isActivelyStreaming(e){eV(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&&Sy.includes(this.connection._username)&&Si(`[chart] Connection ${e}, last timestamp ${this.lastStreamingTimestamp}`)}onEvents({event:e}){e===tG.BC_EVENT_DISCONNECTED||e===tG.BC_EVENT_FEED_PAUSED?(this.debug(e),this.isActivelyStreaming=!1):(e===tG.BC_EVENT_LOGGED_IN||e===tG.BC_EVENT_FEED_RESUMED)&&(this.debug(e),this.isActivelyStreaming=!0)}shutdown(){super.shutdown(),eV(this._connection)&&(this.connection.off("timestamp",this.onTimestamp),this.connection.off("events",this.onEvents),this.resetStreamingState(),this.connection.disconnect(),this.connection=null)}}class ST{_listeners=new Set;onConnected;onDisconnected;onMessage;onHeartBeat;constructor(){this.onConnected=e=>{this._listeners.forEach(t=>t.onConnected?.(e))},this.onMessage=e=>{this._listeners.forEach(t=>t.onMessage?.(e))},this.onDisconnected=()=>{this._listeners.forEach(e=>e.onDisconnected?.())},this.onHeartBeat=e=>{this._listeners.forEach(t=>t.onHeartBeat?.(e))}}addListener(e){this._listeners.add(e)}removeListener(e){this._listeners.delete(e)}clear(){this._listeners.clear()}}function SA(e,t){return new Sv(e,t)}class Sv{_client=null;_subscriptions=new Map;_marketIdToSymbol=new Map;_symbolToMarketId=new Map;constructor(e,t){this._client=e,t.onMessage=this.onMessage.bind(this)}associateSymbolAndMarketId(e,t){this._symbolToMarketId.set(e,t),this._marketIdToSymbol.set(t,e)}disassociateSymbolAndMarketId(e){let t=this._symbolToMarketId.get(e),i=eV(t);return i&&(this._symbolToMarketId.delete(e),this._marketIdToSymbol.delete(t)),i}onMessage(e){let t=e.subscriptionResponse;t&&this.isSubscribedToRealTimeTrades(t.symbol)&&this.associateSymbolAndMarketId(t.symbol,t.marketId.toNumber())}async ready(){return eV(await this._client?.connection)}shutdown(){eV(this._client)&&(this._client.dispose(),this._client=null)}findSymbolByMarketId(e){let t=e?.marketId.toNumber();return eV(t)&&this._marketIdToSymbol.has(t)?this._marketIdToSymbol.get(t):null}subscribeToRealTimeTrades(e){if(this._subscriptions.has(e)||!eV(this._client))return;let t=this._client.subscribe(1,5,0,[e],null,null,null);this._subscriptions.set(e,t)}unsubscribeFromRealTimeTrades(e){if(!this._subscriptions.has(e)||!eV(this._client))return;let t=this._subscriptions.get(e);this._client.unsubscribe(t),this._subscriptions.delete(e),this.disassociateSymbolAndMarketId(e)}async getInstrument(e){let t=await this._client?.connection;return await t?.getInstrument(e)??[]}isSubscribedToRealTimeTrades(e){return this._subscriptions.has(e)}}class Sb extends Sp{multiplexer=new ST;_adapter=null;_auxFeeds=[];constructor(t){super(t),this.cachesData=!0,this.isAuxiliary||(this.timeSeriesSource=new u6(!0),this.metaDataSource=new il,this.recordSource=new lR,e(cc).subscribe(am.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&&eR(e,t)}set listener(e){eV(e)&&(e.onConnected=this.onConnected.bind(this),e.onMessage=this.onMessage.bind(this))}get adapter(){return this._adapter}set adapter(e){eV(e)&&(this._adapter=e)}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._adapter?.subscribeToRealTimeTrades(e)}unsubscribe(e){this._adapter?.unsubscribeFromRealTimeTrades(e)}shutdown(){super.shutdown(),this.isAuxiliary?(this._mainFeed?.removeAuxFeed(this),this._mainFeed=null):(this._adapter?.shutdown(),this.multiplexer.clear())}onConnected(e){this.refreshCaches()}get ofRecordSource(){return this.recordSource}onMessage(e){let t=e.marketSnapshot,i=this._adapter?.findSymbolByMarketId(t)??null;eV(t)&&null!==i&&this.ofRecordSource.onSnapshot(t,i);let s=e.marketUpdate;i=this._adapter?.findSymbolByMarketId(s)??null,eV(s)&&null!==i&&this.ofRecordSource.onUpdate(s,i)}replaceDataSources(e){super.replaceDataSources(e),this._mainFeed=e,this.adapter=e.adapter}addAuxFeed(e){e.replaceDataSources(this),this._auxFeeds.push(e)}removeAuxFeed(e){let t=this._auxFeeds.findIndex(t=>t.id==e.id);-1!==t&&(this._auxFeeds.splice(t,1),this.triggerGc())}getAllCacheableEntities(e){if(super.getAllCacheableEntities(e),!this.isAuxiliary)for(let t of this._auxFeeds)t.getAllCacheableEntities(e)}}var cc=R("c15IW");let SP=e(cc);export{SP as PubSub,So as initFeed,Sl as getFeed,Sh as shutdownFeed,Sc as getChartOutline,Sp as BaseDataFeed,Sf as BarchartSiteDataFeed,Sg as MiniWidgetDataFeed,SS as MarketDataFeed,Sb as OpenFeed,Sm as SnapshotDataFeed,SA as adaptOpenFeedClient,l4 as OHLCDataPointBuilder,nY as parseExpression,nj as evaluateExpression,nq as formatExpression,nX as getExpressionSymbols,nJ as replaceExpressionSymbols,pm as ExpressionSeries,pf as makeExpression,uZ as ContainerWrapperTimeSeries,t3 as formatPriceWithDecimals,t4 as getCombinedMetaData,lI as BaseRecordSource,av as EmptyRecord,ac as Field,af as Fields,l6 as TimeSeriesContainer,ch as TimeSeriesQuery,nD as Aggregation,tW as asyncReady,tE as hasOpenInterest,lQ as optionValueToDate,e0 as generateUid,sU as getTaxonomies,sV as doesStudyExist,sR as getAnnotationTraits,gj as getStudyOptions,cf as StudySeries,cp as makeHelperField,fA as makeStudy,fB as convertSeries,fk as mapSeries,fP as movAvg,fC as movExp,fE as movSmo,f_ as movWei,fL as movHul,fF as linReg,fD as trueRange,fw as typical,fR as roc,fH as stdDev,am as Topics,iM as getLightness,er as ChunkPart,Z as SeriesKind,G as AggregationSpec,$ as AggregationUnit,F as ExpressionRecompute,B as ExpressionNoDataApproach,H as ExpressionMissingBar,z as FieldValueType,j as FieldCategory,Y as FieldFormat,yh as CustomEventPopup,tF as appendDOMElement,tR as styleDOMElement,tN as setAttributesDOMElement};
20
+ </svg>`),tR(this.goToLatestButton,{position:"absolute",right:0,bottom:0,"z-index":3}),tN(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 ys(this),this.eventCapture=new ya(this),this.eventCapture.init(this.mouseCanvas),this.setChartSize(n,r);let o=tD(this.el);eH(tw(`.${tG.SVG_ICONS_DOM_NODE}`,o))||function(e){let t=tF(e,"div");tN(t,{class:tG.SVG_ICONS_DOM_NODE});let i=Object.keys(hw).map(e=>`<symbol id="${hH(e)}" viewBox="0 0 1024 1024">${hw[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&&tB(".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 ys(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`};tR(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=>{tN(e,r),tR(e,i)}),this.mainContext.scale(s,s),this.mouseContext.scale(s,s),this.recalculateLayout(),this.presenter&&mk(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=ef(r.map(e=>e.height)),a=0,o=tG.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 iO(0,a,this.width,u);e.setViewBox(h);let c=new iO(this.width-this.rightOffset,a,t,u),d=new iO(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 iO(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,l);this.splitters.push(e),a+=l}});let h=new iO(this.leftOffset,a,this.width-this.rightOffset-this.leftOffset,e);this.xAxis.setViewBox(h),tR(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=Sl().config.showGoToLatest,{showGoToLatest:t}=this.presenter.display.chart,i=eH(e)?e:t;this.goToLatestButton.style.display=i&&this.xAxis.canGoToLast()?"block":"none",this.mainContext.restore()}get isHostElementVisible(){return eH(this.el)&&eH(this.el.offsetParent)}redraw(e=!1){this.isHostElementVisible&&(e?this.draw():Sl().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=iL(e);return iI(iC(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 Q.Arrow:default:return"default";case Q.Crosshair:return"crosshair";case Q.Hand:return"pointer";case Q.Move:return"move";case Q.ResizeVertical:return"ns-resize";case Q.Grabbing:return"grabbing";case Q.ResizeHorizontal:return"ew-resize"}}(e);tR(this.el,{cursor:t})}shutdown(){this.listeners.forEach(e=>e()),this.eventCapture&&this.eventCapture.shutdown(),this.tooltip&&this.tooltip.remove(),this.el&&tB(".bcharts-card",this.el).forEach(e=>e.remove()),this.canvasContainer.remove()}getEventRadius(){return Math.max(this.xAxis.xScale.bar.width/2,tG.MIN_EVENT_RADIUS)}}class yh{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=tF(this.view.el,"div"),tN(this.popupElement,{id:`${this.view.presenter.elementId}-custom-event-host`}),tR(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=tF(this.popupElement,"a");tN(e,{class:"custom-event-close-button"}),tR(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()),tR(this.popupElement,{visibility:"visible",top:`${e.y}px`,left:`${e.x}px`,width:"310px"}),this.visible=!0}hideValue(){}hide(){this.visible&&(this.hideValue(),tR(this.popupElement,{visibility:"hidden"}),this.visible=!1)}}function yc(e,t){if(!(e.annotations&&e.annotations.length>0))return;let i=t.annotations||[];t.annotations=i.concat(e.annotations)}let yd='..axes{..plots{.type==="Study"}}';var cc=R("c15IW");let yp={ok:!1,change:void 0,toApply:void 0};class yf{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,mp(e,eo.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&&eV(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(!eH(e))return!1;switch(t){case eo.None:case eo.Undo:case eo.Redo:Si(`Unexpected tool change ${eo[t]} for undo/redo`,"warn");break;case eo.Created:i?this.delete(e):this.add(e);break;case eo.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?eo.Undo:eo.Redo;return eH(s)&&this.presenter.onAnnotationModifiedByTool(s,r),!0}can(e){let t=e?this.undoStack:this.redoStack;if(t.length<1)return yp;let i=eb(t),s=i.toolChange;if(!(e&&s!==eo.Deleted&&s!==eo.Created))return{ok:!0,change:s,toApply:i};let r=eC(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)?yp:{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 ym{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 yg(e={}){let t=this.allPlots;if(!t.every(e=>eH(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(af.DateTime,0),this.data.aggregation.isMultiContract&&!e.isExpression&&t.set(af.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?tG.FMT_ISO_DATE_ONLY:tG.FMT_EXPORT_ALL_BUT_MILLIS,o=(e,t)=>e===af.DateTime?o1(t,a):(eH(s,t)?eF(t,s):t)?.toString()??"",l={},u=this.timeline.lastSeriesIndex,h=eP(this.mainPlot.timeSeries.container.getTimeData()),c=e_(this.timeline,+h,Number,hD),d=(e,t)=>{let i=this.timeline.at(e),s=t.timeSeries.container,r=s.getTimeData(),u=e_(r,+i,Number,eE,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===af.DateTime)return o1(i,a);else return"";{let i=this.timeline.at(e-n),a=e_(r,+i,Number,eE,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]=`"${X[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(eu(d,e));null!==t&&f.push(t)}return f.join("\n")}function yy(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),eV(a)){let e=new ym(this);e.update(a),e.draw(l)}let h=this.mainPlot?.timeSeries.container?.getLastDataPoint(af.DateTime);if(eV(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:tG.CARDS_X_OFFSET,y:tG.CARDS_Y_OFFSET},c=hG(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===X[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(!(eV(r)&&eV(n)))return c(l.canvas);{let e=o(r,n);return e.drawImage(l.canvas,0,0,r,n),c(e.canvas)}}let yS=Symbol.for("__ias__");class yT{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=gU("Default"),this._activeTool=this.defaultTool,this.timeline=new hO(this),this.undoRedoManager=new yf(this),this.title=new ym(this),this.notifySelectionChanged=eN(am.CH_ANNSELECTIONCHANGED),this.notifyRecreated=eN(am.CH_RECREATED),this.notifyDefinitionChanged=eN(am.CH_DEFINITION_CHANGED)}getModel(){return this.model}get isEmpty(){return!eH(this.model)}notifyHost(e,t){eR(e,t)}async fromModel(e,t){if(this._isShutdown)return;eH(this.model)&&this.allPlots.forEach(e=>e.shutdown()),this.sentInitialLoadNotification=!1,this.clearSelection(),this.model=e;let i=eG(e);this.data=i.data,this.data.aggregation=nE(i.data.aggregation),this.display=i.display,eH(this.display.period)&&(this.display.period=eJ(this.display.period)),this.panes=i.panes.map(e=>{let t=new g9(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),eH(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(yb(nC(y0(s,t,i)),nC(y0(s,e,i)))||!yA(e.display?.xAxis?.visibleRange,t.display?.xAxis?.visibleRange)||e.display?.xAxis?.marginBars!==t.display?.xAxis?.marginBars||!yA(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=n1(t),n=n1(e);if(function(e,t){let i=e=>e.curves[0],s=i(e),r=i(t),n=yv.includes(s.style),a=yv.includes(r.style);if(n!==a)return!0;if(!a)return!1;if(s.style!==r.style)return!0;if(t.inputs&&yb(ej(e.inputs),ej(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(){eH(this.view)&&(this.view.shutdown(),this.view=void 0)}reinitializeView(){this._isShutdown||(eH(this.view)?this.view.reinitialize():(this.view=new yu,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){eH(this._activeTool.deactivated)&&this._activeTool.deactivated(this),this._activeTool=e,eH(this._activeTool.activated)&&this._activeTool.activated(this),this.notifyHost(am.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(!eH(r))return;let n=eH(r)&&r.main,a=!1,o=!1;if(e===am.TS_TIMELINECORRECTION){if(!this.timeline.tryToCorrectLastBar(t.from,t.to))return;a=!0}let l=eH(t.index)?i.container.getTimeData()[t.index]:null,u=e===am.TS_EVENTSCHANGED,h=this.view.xAxis,c=h.xScale;if(e===am.TS_MANYCHANGED||u){if(n&&this.data.checkRange)if(eH(this.display.xAxis.visibleRange)){let e={id:"Period",context:{range:this.display.xAxis.visibleRange}};e[yS]=!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===er.Tail){let e=e_(this.timeline,l,Number,hD);h.shouldScrollIntoView(e)&&c.shiftBars(t.count)}this.timeline.invalidate(),this.allPlots.forEach(e=>e.invalidatePriceMappingCache()),a=!0}else if(e===am.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===am.TS_DATAPOINTCHANGED&&(o=!0,r.isStudy&&r.invalidateAssociatedAnnotations("DataPointChanged"));if(!u&&s(this.mainPlot)&&i.hasData&&0===i.container.size&&this.notifyHost(am.CH_NODATAFORMAINSYMBOL,{chart:this.accessor}),a&&this.view.recalculateLayout(),o&&(a&&Si("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(),eH(l)&&e.updateFullDomain(l)})),!this.sentInitialLoadNotification&&e===am.TS_MANYCHANGED&&this.allPlots.every(e=>e.timeSeries&&e.timeSeries.hasData)){this.sentInitialLoadNotification=!0,this.notifyHost(am.CH_ALL_DATA_PROJECTED,{chart:this.accessor}),mk(this);let e=this.display.period===tG.FIFTY_YEARS_MILLIS;this.mainPlot&&e&&(c.fitAllData=!0,c.adjustDomain())}this.view.redraw()}onMetaChanged(e,t){e===am.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(am.CH_AXISSCALECHANGED,s)}get previousMask(){return eH(this._previousMask)||(this._previousMask=ay(af.PreviousClose)),this._previousMask}hasMatch(e,t){return e.some(e=>e.updated&&t)}get hasLegend(){return eH(this._hasLegend)||(this._hasLegend=Sl().config.mode===es[es.cmdtyView]),this._hasLegend}onStreamingUpdates(e){eH(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 eH(this._ohlcMask)||(this._ohlcMask=ay(af.Open,af.High,af.Low,af.Close,af.PreviousClose)),this._ohlcMask}updateMatches(e,t){if((e&this.ohlcMask)==0)return!1;let i=(e,t)=>eV(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 Sl().getRecordSource().subject.pipe(ub(e=>e.filter(e=>this.updateMatches(e.updated,e.data.symbol))),oT(e=>e.length>0)).subscribe(this.onStreamingUpdates.bind(this))}get hostElement(){return this._hostElement}get elementId(){return eH(this._hostElement)?this._hostElement.id:null}initialize(t){if(this._hostElement=t instanceof HTMLElement?t:tw(`#${t}`),!this._hostElement)throw Error(`There is no element ${t} in the DOM`);this.renderTo=t,this.seriesChangedToken=e(cc).subscribe(am.TS_ALL,this.onSeriesChanged.bind(this)),this.metaChangedToken=e(cc).subscribe(am.MD_ALL,this.onMetaChanged.bind(this)),this.streamingSubscription=this.getStreamingSubscription()}shutdown(){return e(cc).unsubscribe(this.seriesChangedToken),e(cc).unsubscribe(this.metaChangedToken),eH(this.streamingSubscription)&&this.streamingSubscription.unsubscribe(),this.allPlots.forEach(e=>e.shutdown()),this.model=void 0,this.closeView(),this.notifyHost(am.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(){eH(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(Q.Arrow)}print(e={}){let t=tF(document.body,"iframe");t.src="",t.style.display="none",t.onload=()=>{let{title:i}=e,s=yy.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),eH(this.view)&&this.view.redraw(t)}enableTooltip(e){this.tooltipEnabled=e;let t=this.display.tooltip.mode===tG.TOOLTIP_CARDS;!e&&t&&this.hideCards()}get showTooltip(){return this.display.tooltip.visible&&this.tooltipEnabled}hideCards(e=!1){let t=this.display.tooltip,i=eD();!e&&t.visible&&t.mode===tG.TOOLTIP_CARDS&&tB(".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 sG(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,eo.Deleted);return}}throw Error(`Unknown sub-action ${e.id} for action ${tG.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:X[i[s].type],index:s}}getSimplePlot(e,t){return this.accessor.change({id:"Plot",context:{id:tG.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(am.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(am.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(am.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(am.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(am.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},sz(i,`..axes[${s.axisIndex}]`,e=>(e.annotations=s.annotations,e)));try{this.model=al(a,tG.CHART_SCHEMA)}catch(e){Si(`Cannot update annotation (corrupts definition), error is: ${e.message}`,"error")}t&&this.view.draw(),this.notifyHost(am.CH_ANNOTATIONCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}onAnnotationModifiedByTool(e,t,i=!0){if(t!==eo.None){if(i&&t!==eo.Undo&&t!==eo.Redo){let i=mp(e,t);this.undoRedoManager.done(i)}let s=mf(e);s.toolChange=eo[t],this.notifyHost(am.CH_ANNMODIFIEDBYTOOL,s)}}onAnnotationDone(e,t){let i={id:e,chart:this.accessor,toolChange:eo[t]};this.notifyHost(am.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=sz(i,(t=e.index,`..panes[${t}]`),t=>(t.height=e.relativeHeight,t))}),i),this.notifyHost(am.CH_PANEHEIGHTSCHANGED,{chart:this.accessor}),this.notifyDefinitionChanged({chart:this.accessor})}getDataStats(){let e=this.mainPlot.timeSeries.container;if(!eH(e)||0===e.size)return null;let t=e.getTimeData();return{dataRange:{from:eP(t).getTime(),to:eb(t).getTime()},barCount:e.size}}}function yA(e,t){return e?.from===t?.from&&e?.to===t?.to}let yv=["Renko","Range","LineBreak","Kagi","PointAndFigure"];function yb(e,t){for(let i of Object.keys(e))if(e[i]!==t[i])return!0}let yP="MARKED_FOR_DELETION";function yC(e,t){if(0===t.plots.length)return e;let i=e;return t.plots.forEach(e=>{let t=yL(e.index),s=yM(i,t);eH(s)&&s.type===e.type&&(i=sz(i,t,e=>(e[yP]=!0,e)))}),au(i=sz(i,`..plots{.${yP} === true}`,e=>tG.NULL_OBJECT))}function yE(e,{main:t,type:i,index:s},r){let n="..plots{.main === true}",a=sG(e,"..panes").map((e,t)=>{let i=1===sG(e,n).length;return sG(e,"..axes").map((e,s)=>{let a=1===sG(e,n).length;return sG(e,"..plots").map(e=>{let n=function(e,t,i,s){let r=X[e.type],n={curves:eG(e.curves),type:e.type};n.precision=e.precision,n.visible=e.visible;let a=(e,t)=>{eH(e[t])?n[t]=e[t].map(e=>eG(e)):n[t]=[]},o=(e,t,i=!1)=>{!0===t.main&&(e.main=!0,e.showPrevious=t.showPrevious,i&&null!=t.events&&(e.events=eG(t.events)))},l=(e,t=e=>!0)=>{eH(s)&&(e.subtitles=s.allPlots.filter(e=>e.type===r).filter(t).map(e=>e.title))};switch(r){case X.Symbol:{n.title=e.symbol;let t=n.curves[0].style,i=t=>{a(e,"inputs"),0===n.inputs.length&&(n.inputs=eG(t))};switch(t){case"Renko":i(tG.DEFAULT_RENKO_INPUTS);break;case"Kagi":i(tG.DEFAULT_KAGI_INPUTS);break;case"PointAndFigure":i(tG.DEFAULT_PNF_INPUTS);break;case"LineBreak":i(tG.DEFAULT_LINEBREAK_INPUTS);break;case"Baseline":i(tG.DEFAULT_BASELINE_INPUTS)}o(n,e,!0);break}case X.Study:{a(e,"inputs");let s=sw(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 X.BalanceSheet:case X.IncomeStatement:{let t=af[e.curves[0].fields[0]];n.title=`${t.name} (${e.fundamental.substring(0,1)})`,n.fundamentalId=t.id,n.frequency=e.fundamental;break}case X.Expression:n.title=e.expression,o(n,e);break;case X.Forward:n.title=e.forward,a(e,"offsets"),l(n),o(n,e);break;case X.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(!eH(i))return a;{let e=a.filter(e=>e.type===i);return eH(s)?e.filter(e=>e.index===s):e}}function y_(e,t){"Study"===e.type&&t.curves?.forEach(e=>delete e.varyColorPerBar),function(e){let t=X[e.type];return t===X.Forward||t===X.Seasonal}(e)?eH(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(ez(r,s),["shift","dashStyle","lineSmoothing","lineMarker"])){let t=s[e];eH(t)&&(r[e]=t)}}}(e.curves,t.curves);let i=X[t.type];eH(t.precision)?e.precision=t.precision:delete e.precision,i===X.Symbol?e.symbol=t.symbol:i===X.Study?(function(e,t,i){let s=ej(e),r=ej(t);ez(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===X.BalanceSheet||i===X.IncomeStatement)&&t.frequency?e.fundamental=t.frequency:i===X.Expression?eH(t.expression)&&(e.expression=t.expression):i===X.Forward?(eH(t.offsets)&&(e.offsets=t.offsets),eH(t.forward)&&(e.forward=t.forward)):i===X.Seasonal&&(eH(t.offsets)&&(e.offsets=t.offsets),eH(t.seasonal)&&(e.seasonal=t.seasonal),eH(t.usesInAverage)&&(e.usesInAverage=t.usesInAverage),ri(e))}let yL=e=>`..plots[${e}]`;function yM(e,t){let i=sG(e,t);return 1!==i.length?null:i[0]}let yx=["withMain","overlay","standalone","clone"];function yI(){return{plots:[]}}function yD(e){let t=e.display.chart.newPaneHeight??1;return{axes:[yI()],height:t}}function yO(e){let t=yD(e);return e.panes.push(t),t}function yw(e,t){let i=eV(t.paneIndex)&&t.paneIndex<e.panes.length?e.panes[t.paneIndex]:yO(e),s=i.axes[0];return t.oppositeScale?y$(i,s):s}function yR(e,t,i){let s=null,{mainPane:r,mainAxis:n}=n2(e);switch(t){case"withMain":s=y$(r,n);break;case"overlay":s=n;break;case"standalone":s=yO(e).axes[0];break;case"clone":if("number"==typeof i){let t={main:!1,index:i,type:X[X.Study]},r=yE(e,t).find(e=>e.index===t.index);s=sG(e,`..panes[${r.paneIndex}]..axes[${r.axisIndex}]`)[0]}}return s}let yN=[{fields:[af.Close.id],colors:["#888"],style:"Line",lineWidth:2,varyColorPerBar:!1,visible:!0}];function yV(e){return"Symbol"===e.type}let yH={attributes:["OpenVsClose"],colors:["#b63400","#007f3e","#1664db"],fields:["Open","High","Low","Close","Change"],style:"Candlestick",varyColorPerBar:!0,lineWidth:1},yF=0,yB=["#0d223a","#8abc21","#910000","#2f7ed8","#42ccdc","#bf95df","#860262","#e5daa3","#4682e8","#aaa9c1","#fcccdc","#f66b00","#d875be","#e84b46"],yk="Symbol";function yW(e,t){let i={curves:[{attributes:[],colors:yB.slice(yF,yF+1),fields:e?[af.Last.id]:[af.Close.id],style:"Line",dashStyle:"Solid",varyColorPerBar:!1,lineWidth:2,lineMarker:void 0,lineSmoothing:void 0}]};return delete t.oppositeScale,eY(i,t),eH(t.curves)&&ez(i.curves,t.curves),yF=(yF+1)%yB.length,i}let yU='..plots{(.type === "Symbol" || .type === "Expression") && .main !== true}';function y$(e,t){let i=e.axes.find(e=>e!==t);return eH(i)||(i=yI(),e.axes.push(i)),i}let yG=()=>tG.NULL_OBJECT;function yz(e){return sz(e,"..axes.annotations",yG)}function yY(e){return au(sz(e,'..plots{.type === "Symbol" && .main !== true}',yG))}let yj=".display.chart.previous";function yK(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==X[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 yq(e,t,i){let s=[],r=i.allPlots[t.index];if(r?.type!==X[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 yX(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 yZ(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 yJ={MainPlot:n9,Aggregation:{Update:ai,Get:function(e,t,i){return eG(e.data.aggregation)}},Period:{Update:function(e,t,i){let s=eH(t.period),r=eH(t.range),n=eH(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,nw(e),nN(e)),r)if((!eH(e.display.period)||an(e.display.period))&&(e.display.xAxis.visibleRange=t.range),nR(e),nN(e),eH(i)){let s=function(e){let t=e.getDataStats();return null===t?null:t.dataRange}(i),r=nE(e.data.aggregation),n=i.data.aggregation,a=r.unit!==n.unit||r.size!==n.size||r.spec!==n.spec||!eH(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,nw(e),nR(e)),(s||r||n)&&(nO(e),i&&(i.forceResetVisibleRange=!0)),e},Delete:function(e,t,i){return eH(t.period)&&t.period&&(delete e.display.period,ae(e),i&&(i.forceResetVisibleRange=!0)),e}},Crosshair:{Update:function(e,t){let[i,s]=ek(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=sz(e,".display.xAxis.crosshair",e=>(e.enabled=i,l(e,a,o),e));return u=sz(u,".display.yAxis.crosshair",e=>(e.enabled=s,l(e,r,n),e)),eH(t.haloTracking)&&"boolean"==typeof t.haloTracking&&(u=sz(u,".display.chart",e=>(e.plotHover=t.haloTracking,e))),u},Get:function(e,t,i){let s=t=>sG(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 sz(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=sG(e,".display.tooltip")[0];return{visible:s.visible,mode:s.mode,showMainTitle:s.showMainTitle,mainTitle:s.mainTitle}}},Events:function(e,t){let i=eG(t);return Object.keys(t).forEach(e=>{tG.EVENTS.includes(e)||delete i[e];let s=t[e];"boolean"==typeof s?s={show:t[e]}:Object.keys(s).forEach(e=>{tG.EVENT_PROPERTIES.includes(e)||delete s[e]}),i[e]=s}),sz(e,n0,e=>("Symbol"===e.type&&(e.events=e.events||{},Object.keys(i).forEach(t=>{e.events[t]=e.events[t]||{},ez(e.events[t],i[t],!1)})),e))},Scale:{Update:function(e,t){let i=sz(e,"..panes[0]..axes",e=>(eV(t.scale)&&(e.scale=t.scale),e));return i=sz(i,".display.xAxis",e=>(eV(t.marginBars)&&(e.marginBars=t.marginBars),eV(t.nonEodLabelWithDate)&&(e.nonEodLabelWithDate=t.nonEodLabelWithDate),eV(t.ordinalName)&&(e.ordinalName=t.ordinalName),eV(t.preventHorizontalLabelOverlap)&&(e.preventLabelOverlap=t.preventHorizontalLabelOverlap),e)),i=sz(i,".display.yAxis",e=>{(eH(t.minPadding)||eH(t.maxPadding))&&Si("The 'minPadding' and 'maxPadding' are deprecated (ignored)","warn");let i=eV(t.preventLabelOverlap)&&!eV(t.preventVerticalLabelOverlap);i&&Si("The 'preventLabelOverlap' is deprecated, please use 'preventVerticalLabelOverlap'","warn");let s=i?t.preventLabelOverlap:t.preventVerticalLabelOverlap;return eV(s)&&(e.preventLabelOverlap=s),eH(t.includePercentChangeWithLastValue)&&(e.includePercentChangeWithLastValue=t.includePercentChangeWithLastValue),eH(t.snapAnnotationsToPrices)&&(e.snapAnnotationsToPrices=t.snapAnnotationsToPrices),e}),eH(t.labels)&&Array.isArray(t.labels)&&t.labels.forEach(e=>{let{axis:t,text:s,index:r,paneIndex:n}=e;eH(t,s,r)&&"vertical"===t&&Number.isInteger(r)&&(i=sz(i,`..panes[${n??0}]..axes[${r}]`,e=>eH(e)?(e.label=s,e):tG.NULL_OBJECT))}),eV(t.contractTransition)&&(i=sz(i,".display.xAxis",e=>(ez(e.contractTransition,t.contractTransition),e))),eV(t.cycleTransition)&&(i=sz(i,".display.xAxis",e=>(ez(e.cycleTransition,t.cycleTransition),e))),i},Get:function(e,t,i){let{mainAxis:s}=n2(e),r=sG(e,".display.xAxis")[0],n=sG(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(eH(t.comparisonMode)&&"string"==typeof t.comparisonMode&&eU(K,t.comparisonMode)&&(s=sz(s,`..panes{${n0}}.axes`,e=>(e.comparison=t.comparisonMode,e))),eH(t.gridLines)){let[e,i]=ek(t.gridLines);s=sz(s,".display.xAxis.gridLines",t=>(t.visible=e,t)),s=sz(s,".display.yAxis.gridLines",e=>(e.visible=i,e))}if(eH(t.minorGridLines)){let[,e]=ek(t.minorGridLines);s=sz(s,".display.yAxis.minorGridLines",t=>(t.visible=e,t))}eH(t.newPaneHeight)&&"number"==typeof t.newPaneHeight&&(s=sz(s,".display.chart{.newPaneHeight > 0}",e=>(e.newPaneHeight=t.newPaneHeight,e))),eH(t.showNavigator)&&"boolean"==typeof t.showNavigator&&(s=sz(s,".display.scrollbar",e=>(e.visible=t.showNavigator,e))),eH(t.plotHover)&&"boolean"==typeof t.plotHover&&(s=sz(s,".display.chart",e=>(e.plotHover=t.plotHover,e))),eH(t.showLastValue)&&"string"==typeof t.showLastValue&&(s=sz(s,".display.yAxis",e=>(e.showLastValue=t.showLastValue,e))),eH(t.showMinMaxArc)&&"boolean"==typeof t.showMinMaxArc&&(s=sz(s,".display.chart",e=>(e.showMinMaxArc=t.showMinMaxArc,e))),eH(t.showGoToLatest)&&"boolean"==typeof t.showGoToLatest&&(s=sz(s,".display.chart",e=>(e.showGoToLatest=t.showGoToLatest,e))),eH(t.showLegend)&&"boolean"==typeof t.showLegend&&(s=sz(s,".display.chart",e=>(e.showLegend=t.showLegend,e)),t.showLegend||i.view.removeLegend()),eH(t.allAnnotationsLocked)&&"boolean"==typeof t.allAnnotationsLocked&&(s=sz(s,".display",e=>(e.allAnnotationsLocked=t.allAnnotationsLocked,e))),eH(t.exprSkipLeadingEmpty)&&"boolean"==typeof t.exprSkipLeadingEmpty&&(s=sz(s,".data",e=>(e.exprSkipLeadingEmpty=t.exprSkipLeadingEmpty,e)));let r=[];if(eH(t.extendedHours)&&"boolean"==typeof t.extendedHours&&(s=sz(s,".data",e=>(e.extendedHours=t.extendedHours,e))),eH(t.realTimeCboeBzx)&&"boolean"==typeof t.realTimeCboeBzx&&(s=sz(s,".data",e=>(e.realTimeCboeBzx!==t.realTimeCboeBzx&&r.push("realTimeCboeBzx"),e.realTimeCboeBzx=t.realTimeCboeBzx,e))),eH(t.buildContinuation)&&"boolean"==typeof t.buildContinuation&&(s=sz(s,".data",e=>(e.buildContinuation=t.buildContinuation,e))),r.length>0){let e={chart:i.accessor,hostPropsChanged:r};i.notifyHost(am.CH_HOST_PROPS_CHANGED,e)}return s},Get:function(e,t,i){let s=sG(e,`..panes{${n0}}.axes.comparison`)[0],r=e.display,n=(e,t)=>e$(e,!1,t,"visible"),a=e=>(function(e,t){let i=e=>eH(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=e$(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=sw(t.studyId);if(!eV(i))return Si(`Unknown or unavailable study with the id '${t.studyId}'`,"error"),e;let s=n1(e),r=sH(i);if(s.type===X[X.Expression]&&r)return Si(`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),y_(a,t);let o=yR(e,n,t.cloneIndex);eH(o)&&o.plots.push(a);let l=e.data.aggregation;return at(e,"Tick"===l.unit&&"None"===l.spec)}(e,t);case"IncomeStatement":case"BalanceSheet":return function(e,t){let i=n1(e);if(i.type!==X[X.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:j[af[t.fundamentalId].category],visible:!0};return y_(r,t),e.panes.push({axes:[{plots:[r]}]}),e}(e,t);case"Expression":let i=n1(e),s={curves:eG(yV(i)?i.curves:yN),expression:"",type:"Expression",visible:!0};return y_(s,t),yw(e,t).plots.push(s),e;case"Symbol":return function(e,t){let i=n1(e),s=Sl().getDefaultMultiFieldCurve(),r=eH(s)?s:yH,n=i.curves?.length,a={curves:n===t.curves.length&&1===n?eG(yV(i)?i.curves:[r]):t.curves,symbol:"",type:"Symbol",visible:!0};return y_(a,t),yw(e,t).plots.push(a),e}(e,t);case"Seasonal":let r={curves:eG(yN),offsets:[0],seasonal:"",type:"Seasonal",visible:!0,main:!1};return y_(r,t),t.paneIndex=t.paneIndex??0,yw(e,t).plots.push(r),e;default:throw Error("Unexpected plot type '${type}', not supported currently")}},Get:yE,Delete:yC,Update:function(e,t,i){if(eH(t.placement)&&!yx.includes(t.placement))throw Error(`Unknown placement: ${t.placement}`);let s=t.main?n0:yL(t.index),r=yM(e,s);if(!eV(r)||eV(t.type)&&r.type!==t.type)return e;if(eV(t.visible))return r.visible=t.visible,e;if(r.main&&function(e){let t=X[e.type];return t===X.Symbol||t===X.Expression}(r)){if(t.curves){let i=e=>e.curves[0].style===U[U.Range],[s,n]=[i(r),i(t)];s&&!n?e=ai(e,{unit:"Day",size:1,spec:"None"}):!s&&n&&(e=ai(e,{unit:"Intraday",size:100,spec:"PerRange"}))}return t.type||(t.type=r.type),eH(t.precision)?r.precision=t.precision:delete r.precision,eH(t.showPrevious)&&(e=sz(e,n0,e=>(e.showPrevious=t.showPrevious,e))),t.curves?nB(e,t):e}{let r=sz(e,s,e=>(y_(e,t),e)),n=yE(r,t,i).find(e=>e.index===t.index);if(!eH(n))return e;if(!(t.type===X[X.Study]&&eH(t.placement)&&t.placement!==n.placement))return r;let a=yM(r,s),o=yR(r=yC(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}=eS((eH(t.symbols)&&(Si("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=yk,e))),t.plots?.some(e=>eH(e.leftScale)))?(Si("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}=n2(e);r.alignOnExpirations=t.alignOnExpirations||!1;let a=y$(r,n),o=e=>![yk,"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;yF=0;let h=eu(yW,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),au(e)},Get:function(e,t){let i=sG(e,yU),{mainPane:s,mainAxis:r}=n2(e),n=[];for(let e of i){let t=r.plots.includes(e),i=e.type.toLowerCase(),s={curves:eG(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=sG(e,"..panes").map((e,t)=>sG(e,"..axes").map((e,i)=>sG(e,".annotations").map(e=>({...e,paneIndex:t,axisIndex:i})))).flat(2).map((e,t)=>({...e,index:t}));return eH(t.index)&&Number.isFinite(t.index)?t.index<s.length?[s[t.index]]:tG.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=eG(e);if(t.strip.main){let e=n1(i),t=e.type.toLowerCase();e[t]=tG.PLACEHOLDER_SYMBOL_NAME}return t.strip.annotations&&(i=yz(i)),t.strip.compare&&(i=yY(i)),i=sz(i,".data",e=>(e.range&&(delete e.range,e.checkRange=!0),e))},Outline:function(e,t,i){let s=yE(e,{main:!0},i)[0],r=s.title===tG.PLACEHOLDER_SYMBOL_NAME,n="Symbol"===s.type,a="Expression"===s.type,o=nY(s.title),l=[];return a&&!nz(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:sG(e,yU).map(e=>e.symbol),annotations:sG(e,"..annotations").map(e=>e.id),studies:yE(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=sz(e,".display.chart",e=>(s&&(e.backgroundColor=s),u&&(e.fontSize=u),e))),r){let e=e=>(e.color=r,e);i=sz(i,".display.xAxis.gridLines",e),i=sz(i,".display.yAxis.gridLines",e),i=sz(i,".display.yAxis.minorGridLines",e)}if(o){let e=e=>(e.dashStyle=o,e);i=sz(i,".display.xAxis.gridLines",e),i=sz(i,".display.yAxis.gridLines",e),i=sz(i,".display.yAxis.minorGridLines",e)}if(n){let e=e=>(e.textColor=n,e);i=sz(i,".display.xAxis",e),i=sz(i,".display.yAxis",e)}if(a){let e=e=>(e.color=a,e);i=sz(i,".display.xAxis.crosshair",e),i=sz(i,".display.yAxis.crosshair",e)}if(h||c){let e=e=>t=>(t.fontSize=e,t);h&&(i=sz(i,".display.xAxis",e(h))),c&&(i=sz(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=>tG.NULL_OBJECT;return!0===r&&(i.allAnnotations.forEach(e=>i.onAnnotationModifiedByTool(e,eo.Deleted,!1)),l=sz(l,`${o}..annotations`,u)),!0===n&&(l=sz(l,`${o}..plots{.type=="Study"}`,u)),l=au(l)},Previous:{Update:function(e,t,i){return sz(e,yj,e=>(ez(e,t),e))},Get:function(e,t,i){return sG(e,yj)[0]}},MovePlot:{Update:function(e,t,i){if(!yK(e,t,i).includes(t.targetPane))return e;let s=yZ(i,t.index),r=yM(e,yL(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,yD(e)),a=!1;break;case"ExistingBelow":n++;break;case"NewBelow":n++,a=!1,e.panes.splice(n,0,yD(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(yI());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=yX(e,s.pane);return au(h=yX(h,n))},Get:yK},PinPlot:{Update:function(e,t,i){if(!yq(e,t,i).includes(t.targetAxis))return e;let s=yZ(i,t.index),r=e.panes[s.pane],n=yM(e,yL(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(yI()),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 au(yX(e,s.pane))},Get:yq}};function yQ(e){return"function"==typeof e}function y0(e,t,i){return(function(e,t){let i=yJ[e];if(yQ(i))return i;{let e=void 0!==t?i[t]:void 0;if(!yQ(e)&&!yQ(e=i[tG.DEFAULT_ACCESSOR_SUBACTION]))throw Error("Invalid accesor id and/or sub id");return e}})(e.id,e.context.id)(t,e.context,i)}function y1(e){return{id:"MainPlot",context:e}}let y2={keepOldAnnotations:!1,keepNewAnnotations:!0,keepOldCompare:!1,keepNewCompare:!0,keepOldAggregation:!1,keepNewBarWidth:!1},y3=Symbol.for("__ias__");class y4{headless;presenter;_model;constructor(e=!1){this.headless=e,this.presenter=e?null:new yT(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),eV(t)){let e="string"==typeof t;e?Si("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(y1(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(eH(e)){s8(e,t),s7(e,t);let s=gU(e,!1,t,i,this.presenter);s.isDrawingAnnotation&&this.presenter.view.setCursor(Q.Crosshair),this.presenter.activeTool=s,eD()||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 Su()}get model(){return(this.headless?this._model:this.presenter.getModel())||Su()}asTemplate(e={main:!0,annotations:!1,compare:!1}){return this.change({id:tG.ACTION_TEMPLATE,context:{strip:e}})}change(...e){let t={chart:this,actions:e.filter(e=>!e[y3])};t.actions.length>0&&this.presenter?.notifyHost(am.CH_API_ACTIONS_RECEIVED,t);let i=Sl().config.validateInput,s=e.map(e=>i?al(e,tG.ACCESSOR_SCHEMA):e);if(1===s.length){let e=s[0];if(e.id===tG.ACTION_TEMPLATE||e.context.id===tG.ACTION_GET)return y0(e,this.model,this.presenter);if(!this.headless&&e.id===tG.ANN_ACTION_ID)return this.presenter.handleAnnotationChange(e.context)}let{yes:r,no:n}=eS(s,e=>e.id===tG.ACTION_PLOT&&eH(e.context)&&e.context.id===tG.ACTION_DELETE),a=eG(this.model),o=eG(this.model);r.length>0&&n.push({id:tG.ACTION_PLOT,context:{id:tG.ACTION_DELETE,plots:r.map(e=>e.context)}}),n.forEach(e=>{if(!eH(o=y0(e,o,this.presenter)))throw Error("Forgot to return model from accessor")}),this.fromModel(o,a)}async fromModel(e,t){let i=al(e,tG.CHART_SCHEMA);this.headless?this._model=i:await this.presenter?.fromModel(i,t)}async load(e,t){let i={...y2,...t},s=al(JSON.parse(e),tG.CHART_SCHEMA),r=this.model,n=eG(r);if(eH(r)){if(s=function(e,t,i){let s=n1(t),r=s.type.toLowerCase();if(s[r]===tG.PLACEHOLDER_SYMBOL_NAME){let s=n1(e),{mainAxis:r}=n2(t),n=r.annotations,a=n9(t,s);if(i){let{mainAxis:e}=n2(a);e.annotations=n}return a}return t}(r,s,i.keepNewAnnotations),i.keepNewAnnotations||(s=yz(s)),i.keepOldAnnotations&&(s=function(e,t){let{mainAxis:i}=n2(e),{mainAxis:s}=n2(t);yc(i,s);let r=e=>sG(e,'..plots{.type==="Study"}.study')[0],n=sG(e,yd).filter(e=>e!==i),a=sG(t,yd).filter(e=>e!==s);return n.forEach(e=>{let t=r(e),i=a.find(e=>t===r(e));eH(i)&&yc(e,i)}),t}(r,s)),i.keepNewCompare||(s=yY(s)),i.keepOldCompare&&(s=function(e,t){let i=sG(e,yU),s=sG(t,yU),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}=n2(t),{mainAxis:l}=n2(e);return n.forEach(e=>{l.plots.includes(e)?o.plots.push(e):y$(a,o).plots.push(e)}),t}(r,s)),i.keepOldAggregation){let e={id:tG.ACTION_AGGREGATION,context:r.data.aggregation},t=s.display.density;s=y0(e,s,this.presenter),i.keepNewBarWidth&&eH(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=Su();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}),eH(s)){let i=y0({id:"Theme",context:{id:"Get"}},this.model,this.presenter),r=y0(y1(s),t,this.presenter);e&&(r=y0({id:"Theme",context:i},r,this.presenter)),this.presenter?.fromModel(r)}}this.clearUndoRedo(),this.presenter?.notifyHost(am.CH_RESET,{elementId:this.elementId})}print(e={}){this.headless||this.presenter.print(e)}getSVGForExport(){Si("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:yg.call(this.presenter,e)}exportImage(e={}){return this.headless?null:yy.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(eH(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(am.CH_DIDBECOMEACTIVE,{chart:this})}}var cc=R("c15IW");function y5(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 y6(e,t){return e+Math.random()*(t-e)}let y7=Function(atob("Y29uc29sZS5sb2coIlBsZWFzZSBjb250YWN0IEJhcmNoYXJ0IGluIG9yZGVyIHRvIG9idGFpbiB0aGUgbGljZW5zZSBmb3IgdGhlIGNoYXJ0IGNvbXBvbmVudC4iKTsg")),y8=Function("f",atob("Zi5yZW1vdmVBbGxDaGFydHMoKTsg")),y9=Function("m",atob("cmV0dXJuIG0gPT09ICJJbnRlcm5hbEZlZWQiIHx8IG0gPT09ICJXaWRnZXQiIHx8IG0gPT09ICJGcmVlV2lkZ2V0IiB8fCBtID09PSAiRGVtb1NpdGUiOw=="));async function Se(e,t){if(t&&!y9(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=>!eH(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(y7,y6(2e3,3e3)),setTimeout(()=>y8(Sl()),y6(4e3,5e3)))}var St={};function Si(e,t="info",i=""){let s=globalThis.console,r=void 0!==s[t];s[r?t:"log"](e,i)}St=JSON.parse('{"major":2,"minor":354,"patch":4,"prerelease":false}');let Ss={environment:"Browser",validateInput:!1,throttleMillis:0,isAlt64:!0,defaultTemplate:`/${tG.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(y9(this.mode)&&this.knownSite){let{username:r,password:n}=this.credentials||{},a=eH(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 Sr(e,t){let i=Sl()?.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 Sn=!1,Sa=null;function So(t,i={}){if(Sn)throw Error("You should only call initFeed once during page's lifetime");Sn=!0;let s=Object.assign(Ss);return ez(s,i),eV(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(eV(s)&&eV(r)){let e=s.split(" ").map(Number);4===e.length&&e.every(Number.isFinite)&&(mj={path:new Path2D(r),width:e[2],height:e[3],rect:new iO(0,0,0,0),logoClickable:t})}}(s.logo,s.logoClickable??!1),!function(e){var t;let i=e.extensions?.studyProvider;if(!eH(i))return;let s=i.getFields(),r=i.getStudies(),n=eG(s_(tG.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=tG.CHART_SCHEMA,ao.addSchema(t,n),ap(s),sI(r)}(s),(Sa=new t(s)).version=function(){let t=e(St),i=t.prerelease?`-${t.prerelease.identifier}.${t.prerelease.ordinal}`:"";return`${t.major}.${t.minor}.${t.patch}${i}`}(),Si(`%cBarchart Chart version ${Sa.version}`,"info","font-size: larger"),Sa.cachesData&&(Sa.subject?.subscribe(Sa.onPerformInternalGc.bind(Sa)),e(cc).subscribe(am.CH_ALL,Sa.onChartChanged.bind(Sa))),Sa}function Sl(){return Sa}function Su(){return eG(Sl()?.template)}function Sh(){eV(Sa)&&(Sa.shutdown(),Sn=!1,Sa=null)}function Sc(e){let t=new y4(!0);return t.load(e),t.change({id:"Outline",context:{id:"Get"}})}function Sd(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 Sp{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=e0()}get subject(){return this.isAuxiliary||eV(this._subject)||(this._subject=new od().pipe(function(e){for(var t,i,s=[],r=1;r<arguments.length;r++)s[r-1]=arguments[r];var n=null!=(t=ou(s[s.length-1])?s.pop():void 0)?t:aQ,a=null!=(i=s[0])?i:null,o=s[1]||1/0;return of(function(t,i){var s=[],r=!1,l=function(e){var t=e.buffer;e.subs.unsubscribe(),a$(s,e),i.next(t),r&&u()},u=function(){if(s){var t=new aG;i.add(t);var r={buffer:[],subs:t};s.push(r),y5(t,n,function(){return l(r)},e)}};null!==a&&a>=0?y5(i,n,u,a,!0):r=!0,u();var h=om(i,function(e){var t,i,r=s.slice();try{for(var n=aV(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)})}(tG.INTERNAL_GC_MILLIS),oT(e=>e.length>0))),this._subject}get isAuxiliary(){return null!==window.opener}setAltDataSource(e){this._altDataSource=e,this.timeSeriesSource=Sd(this.timeSeriesSource,"getTimeSeries",e,"symbol"),this.metaDataSource=Sd(this.metaDataSource,"getMetaData",e),this.recordSource=Sd(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(!eV(this.timeSeriesSource))throw Error("No time series source defined");return this.timeSeriesSource}getMetaDataSource(){if(!eV(this.metaDataSource))throw Error("No metadata source defined");return this.metaDataSource}getRecordSource(){if(!eV(this.recordSource))throw Error("No record source defined");return this.recordSource}async ready(){return tW.call(this,async()=>{await Se(this.config,this instanceof SS||this instanceof Sf||this instanceof Sb);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=al(e,tG.CHART_SCHEMA),!0})}getHeadlessChart(){return new y4(!0)}fixupRenderTo(e){if(!eV(e))return null;if(e instanceof HTMLElement)return e;let t=tw(`#${e}`);if(eV(t))return t;let i=[...this.charts.keys()].find(t=>t.id===e);return eV(i)?i:null}checkChart(e,t){let i=this.fixupRenderTo(e),s=eV(i)&&this.charts.has(i);return eV(t)&&t!==s&&Si(`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 y4;return this.charts.set(i,s),s.initialize(e,t),s}removeChart(e){let t=this.checkChart(e,!0);eV(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 eV(t)?this.charts.get(t):null}redraw(e){let t=this.checkChart(e,!0);eV(this.ongoingAnimationCallbackId)||(this.ongoingAnimationCallbackId=requestAnimationFrame(this.drawCharts)),eV(t)&&this.pendingRedraw.add(t)}drawCharts(){this.ongoingAnimationCallbackId=null,this.pendingRedraw.forEach(e=>{let t=this.getChart(e);if(!eV(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=>{eV(t)&&(eV(t.record)?e.records.add(t.record):eH(t.records)&&Object.values(t.records).forEach(t=>e.records.add(t)))}),e}clearCaches(){this.evictUnused(this.emptyEntities)}refreshCaches(){this.getTimeSeriesDataSource().refresh(),eR(am.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===am.CH_RECREATED||e===am.CH_SHUTDOWN)&&(this.isAuxiliary?this._mainFeed?.triggerGc():this.triggerGc())}getDefaultMultiFieldCurve(){if(!eV(this.template))return null;if(!this.knowDefaultCurve){let e=n1(this.template);1===e.curves.length&&function(e){switch(U[e]){case U.OHLC:case U.HLC:case U.Candlestick:case U.HollowCandles:case U.HeikinAshi:case U.ElderImpulseSystem:case U.Range:case U.MultiColumn:return!0;default:return!1}}(e.curves[0].style)?this.defaultOhlcCurve=eG(e.curves[0]):this.defaultOhlcCurve=null,this.knowDefaultCurve=!0}return this.defaultOhlcCurve}getDefaultAggregation(){return!this.knowDefaultAggregation&&this.template&&(this.defaultAggregation=eG(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 Sf extends Sp{constructor(e){super(e),this.timeSeriesSource=new u6(!1),this.metaDataSource=new ia,this.recordSource=new lD}}class Sm extends Sp{constructor(e){super(e),this.timeSeriesSource=new u6(!0),this.metaDataSource=new ia,this.recordSource=new lO}}class Sg extends Sp{constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u6(!0),this.metaDataSource=new ia,this.recordSource=new lD}}let Sy=["drazen.dotlic@barchart.com","princec","b.hebert24@barchart.com"];class SS extends Sp{lastStreamingTimestamp=null;_isActivelyStreaming=null;needToResubscribe=!1;_connection;constructor(e){super(e),this.cachesData=!0,this.timeSeriesSource=new u6(!0),this.metaDataSource=new io,this.recordSource=new lw,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,eV(e)&&this.initializeStreaming()}addChart(e,t=null){return this.needToResubscribe&&this.initializeStreaming(),super.addChart(e,t)}set isActivelyStreaming(e){eV(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&&Sy.includes(this.connection._username)&&Si(`[chart] Connection ${e}, last timestamp ${this.lastStreamingTimestamp}`)}onEvents({event:e}){e===tG.BC_EVENT_DISCONNECTED||e===tG.BC_EVENT_FEED_PAUSED?(this.debug(e),this.isActivelyStreaming=!1):(e===tG.BC_EVENT_LOGGED_IN||e===tG.BC_EVENT_FEED_RESUMED)&&(this.debug(e),this.isActivelyStreaming=!0)}shutdown(){super.shutdown(),eV(this._connection)&&(this.connection.off("timestamp",this.onTimestamp),this.connection.off("events",this.onEvents),this.resetStreamingState(),this.connection.disconnect(),this.connection=null)}}class ST{_listeners=new Set;onConnected;onDisconnected;onMessage;onHeartBeat;constructor(){this.onConnected=e=>{this._listeners.forEach(t=>t.onConnected?.(e))},this.onMessage=e=>{this._listeners.forEach(t=>t.onMessage?.(e))},this.onDisconnected=()=>{this._listeners.forEach(e=>e.onDisconnected?.())},this.onHeartBeat=e=>{this._listeners.forEach(t=>t.onHeartBeat?.(e))}}addListener(e){this._listeners.add(e)}removeListener(e){this._listeners.delete(e)}clear(){this._listeners.clear()}}function SA(e,t){return new Sv(e,t)}class Sv{_client=null;_subscriptions=new Map;_marketIdToSymbol=new Map;_symbolToMarketId=new Map;constructor(e,t){this._client=e,t.onMessage=this.onMessage.bind(this)}associateSymbolAndMarketId(e,t){this._symbolToMarketId.set(e,t),this._marketIdToSymbol.set(t,e)}disassociateSymbolAndMarketId(e){let t=this._symbolToMarketId.get(e),i=eV(t);return i&&(this._symbolToMarketId.delete(e),this._marketIdToSymbol.delete(t)),i}onMessage(e){let t=e.subscriptionResponse;t&&this.isSubscribedToRealTimeTrades(t.symbol)&&this.associateSymbolAndMarketId(t.symbol,t.marketId.toNumber())}async ready(){return eV(await this._client?.connection)}shutdown(){eV(this._client)&&(this._client.dispose(),this._client=null)}findSymbolByMarketId(e){let t=e?.marketId.toNumber();return eV(t)&&this._marketIdToSymbol.has(t)?this._marketIdToSymbol.get(t):null}subscribeToRealTimeTrades(e){if(this._subscriptions.has(e)||!eV(this._client))return;let t=this._client.subscribe(1,5,0,[e],null,null,null);this._subscriptions.set(e,t)}unsubscribeFromRealTimeTrades(e){if(!this._subscriptions.has(e)||!eV(this._client))return;let t=this._subscriptions.get(e);this._client.unsubscribe(t),this._subscriptions.delete(e),this.disassociateSymbolAndMarketId(e)}async getInstrument(e){let t=await this._client?.connection;return await t?.getInstrument(e)??[]}isSubscribedToRealTimeTrades(e){return this._subscriptions.has(e)}}class Sb extends Sp{multiplexer=new ST;_adapter=null;_auxFeeds=[];constructor(t){super(t),this.cachesData=!0,this.isAuxiliary||(this.timeSeriesSource=new u6(!0),this.metaDataSource=new il,this.recordSource=new lR,e(cc).subscribe(am.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&&eR(e,t)}set listener(e){eV(e)&&(e.onConnected=this.onConnected.bind(this),e.onMessage=this.onMessage.bind(this))}get adapter(){return this._adapter}set adapter(e){eV(e)&&(this._adapter=e)}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._adapter?.subscribeToRealTimeTrades(e)}unsubscribe(e){this._adapter?.unsubscribeFromRealTimeTrades(e)}shutdown(){super.shutdown(),this.isAuxiliary?(this._mainFeed?.removeAuxFeed(this),this._mainFeed=null):(this._adapter?.shutdown(),this.multiplexer.clear())}onConnected(e){this.refreshCaches()}get ofRecordSource(){return this.recordSource}onMessage(e){let t=e.marketSnapshot,i=this._adapter?.findSymbolByMarketId(t)??null;eV(t)&&null!==i&&this.ofRecordSource.onSnapshot(t,i);let s=e.marketUpdate;i=this._adapter?.findSymbolByMarketId(s)??null,eV(s)&&null!==i&&this.ofRecordSource.onUpdate(s,i)}replaceDataSources(e){super.replaceDataSources(e),this._mainFeed=e,this.adapter=e.adapter}addAuxFeed(e){e.replaceDataSources(this),this._auxFeeds.push(e)}removeAuxFeed(e){let t=this._auxFeeds.findIndex(t=>t.id==e.id);-1!==t&&(this._auxFeeds.splice(t,1),this.triggerGc())}getAllCacheableEntities(e){if(super.getAllCacheableEntities(e),!this.isAuxiliary)for(let t of this._auxFeeds)t.getAllCacheableEntities(e)}}var cc=R("c15IW");let SP=e(cc);export{SP as PubSub,So as initFeed,Sl as getFeed,Sh as shutdownFeed,Sc as getChartOutline,Sp as BaseDataFeed,Sf as BarchartSiteDataFeed,Sg as MiniWidgetDataFeed,SS as MarketDataFeed,Sb as OpenFeed,Sm as SnapshotDataFeed,SA as adaptOpenFeedClient,l4 as OHLCDataPointBuilder,nY as parseExpression,nj as evaluateExpression,nq as formatExpression,nX as getExpressionSymbols,nJ as replaceExpressionSymbols,pm as ExpressionSeries,pf as makeExpression,uZ as ContainerWrapperTimeSeries,t3 as formatPriceWithDecimals,t4 as getCombinedMetaData,lI as BaseRecordSource,av as EmptyRecord,ac as Field,af as Fields,l6 as TimeSeriesContainer,ch as TimeSeriesQuery,nD as Aggregation,tW as asyncReady,tE as hasOpenInterest,lQ as optionValueToDate,e0 as generateUid,sU as getTaxonomies,sV as doesStudyExist,sR as getAnnotationTraits,gj as getStudyOptions,cf as StudySeries,cp as makeHelperField,fA as makeStudy,fB as convertSeries,fk as mapSeries,fP as movAvg,fC as movExp,fE as movSmo,f_ as movWei,fL as movHul,fF as linReg,fD as trueRange,fw as typical,fR as roc,fH as stdDev,am as Topics,iM as getLightness,er as ChunkPart,Z as SeriesKind,G as AggregationSpec,$ as AggregationUnit,F as ExpressionRecompute,B as ExpressionNoDataApproach,H as ExpressionMissingBar,z as FieldValueType,j as FieldCategory,Y as FieldFormat,yh as CustomEventPopup,tF as appendDOMElement,tR as styleDOMElement,tN as setAttributesDOMElement};
21
21
  //# sourceMappingURL=barchart.chart.js.map