"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[5456],{55456:(e,t,s)=>{s.r(t),s.d(t,{StudyCompare:()=>$});var i=s(50151),r=s(2072),l=s(91106),o=s(11485),n=s(95059),a=s(92211),u=s(43337),d=s(60911),h=s(37103),c=s(97902),m=s(36281),y=s(52945),b=s(52859);const _=h.enabled("force_exchange_as_title");class p extends m.PriceAxisView{constructor(e,t){super(),this._studyCompare=e,this._data=t}_updateRendererData(e,t,s){e.visible=!1,t.visible=!1;const r=this._studyCompare.priceScale(),l=this._studyCompare.lastValueData(this._data.plotIndex,!1);if(l.noData||null===r||r.isEmpty())return;const o=this._studyCompare.model(),n=o.timeScale().visibleBarsStrictRange(),a=o.mainSeries().bars().lastIndex();if(null===n||null===a)return;if(a<=n.lastBar())s.background=(0,b.resetTransparency)(l.color),s.textColor=this.generateTextColor(s.background),s.borderColor=void 0,e.borderVisible=!1,t.borderVisible=!1;else{const r=o.backgroundColorAtYPercentFromTop(l.coordinate/(0,i.ensureNotNull)(o.paneForSource(this._studyCompare)).height());s.background=r,s.textColor=(0,b.resetTransparency)(l.color),s.borderColor=s.textColor,e.borderVisible=!0,t.borderVisible=!0}s.coordinate=l.coordinate,s.floatCoordinate=l.floatCoordinate;const u=o.properties().childs().scalesProperties.childs();u.showSeriesLastValue.value()&&(e.text=(0,y.getCurrentModePriceText)(r,l),u.seriesLastValueMode.value()!==c.PriceAxisLastValueMode.LastPriceAndPercentageValue?e.secondLine="":e.secondLine=(0,y.getOppositeModePriceText)(r,l),e.visible=!0),t.text="",u.showSymbolLabels.value()&&(t.text=this._paneText(),t.visible=t.text.length>0)}_paneText(){let e="";const t=this._studyCompare.symbolInfo();return _?e=(0,n.displayedSymbolExchange)(t):this._studyCompare.model().properties().childs().scalesProperties.childs().showSymbolLabels.value()&&(e=(0,n.displayedSymbolName)(t)),e}}s(11542);var S=s(13212),g=s(71320),v=s(78861),C=s(49483),I=s(11946),P=s(87465),f=s(36313);const V=C.CheckMobile.any();class T extends g.StudyValuesProvider{constructor(e,t){super(e,t),this._emptyValues[0].title=e.guiPlotName(f.TitleDisplayTarget.StatusLine,"")}getValues(e){return(0,P.isNumber)(e)||(this._showLastPriceAndChangeOnly()?e=this._study.data().lastIndex():(e=this._model.crosshairSource().appliedIndex(),(0,P.isNumber)(e)||(e=this._study.data().lastIndex()))),super.getValues(e)}_hideValues(){return!1}_showLastPriceAndChangeOnly(){return V&&(null===this._model.crosshairSource().pane||(0,I.isLineToolName)(v.tool.value())||null!==this._model.lineBeingEdited())}}class w extends S.StudyDataWindowView{constructor(e,t){super(e,t),this._studyCompare=e}_hideValues(){return!1}_createValuesProvider(e,t){return new T(e,t)}}var x=s(40472);class L extends w{constructor(e,t){super(e,t),this._additional=null,this._showSeriesOHLC=t.properties().childs().paneProperties.childs().legendProperties.childs().showSeriesOHLC,this._showSeriesOHLC.subscribe(this,(()=>this.update((0,x.sourceChangeEvent)(e.id()))))}areValuesVisible(){return this._showSeriesOHLC.value()}destroy(){
this._showSeriesOHLC.unsubscribeAll(this)}additional(){return this._additional}_updateImpl(){super._updateImpl()}}var A=s(80671),R=s(35727),O=s(12965);class E extends O.StudyStatusProvider{getSplitTitle(){return this._source.titleInParts(f.TitleDisplayTarget.StatusLine,!0,void 0,!1,!1)}text(){return this._source.isActualInterval()?this._source.isFailed()?`${this._source.title(f.TitleDisplayTarget.StatusLine,!0,void 0,!1,!1)}: ${this.sourceStatusText()}`:`${this._source.title(f.TitleDisplayTarget.StatusLine,!0,void 0,!1,!1)} ${this.sourceStatusText()}`:this._source.title(f.TitleDisplayTarget.StatusLine,!0,void 0,!1,!1)}}var F=s(36597),k=s(77380),W=s(67455);const U=h.enabled("study_overlay_compare_legend_option"),D=h.enabled("force_exchange_as_title"),H=!h.enabled("hide_study_compare_legend_item"),N=h.enabled("hide_unresolved_symbols_in_legend"),B=h.enabled("symbol_info_price_source");var M;!function(e){e.SnapShotSymbolInfoKey="___snapshot"}(M||(M={}));class $ extends o.Study{constructor(e,t,s,i,l,o){super(e,function(e){return e.hasChild("currencyId")||e.addChild("currencyId",new u.Property(null)),e.hasChild("unitId")||e.addChild("unitId",new u.Property(null)),e.addExcludedKey("currencyId",1),e.addExcludedKey("unitId",1),e}(t),s,i,l,o),this._isActingAsSymbolSource=new r.WatchedValue(!0),this._realignToolsLastParams=null,this._lastResolvedSymbolSource="",this._symbolSourceWV=new r.WatchedValue(this),this.properties().childs().minTick.subscribe(null,(()=>this._recreatePriceFormattingDependencies())),this.properties().childs().minTick.subscribe(null,(()=>this._model.fullUpdate())),this.properties().childs().currencyId.subscribe(this,this._onCurrencyChanged),this.properties().childs().unitId.subscribe(this,this._onUnitChanged),this._symbolResolvingActive=new r.WatchedValue(!1),this._symbolHibernated=new r.WatchedValue(!1),e.mainSeries().onIntervalChanged().subscribe(this,(()=>e.realignLineTools(this))),this._symbolInfoWV=(0,W.createWVFromGetterAndSubscriptions)((()=>this.symbolInfo()),[this.symbolResolved(),this.onStatusChanged()])}destroy(){this._model.mainSeries().onIntervalChanged().unsubscribeAll(this),this._symbolInfoWV.destroy(),this._symbolSourceWV.destroy(),super.destroy()}properties(){return this._properties}isActingAsSymbolSource(){return this._isActingAsSymbolSource.readonly()}symbolParams(){return(0,F.symbolParams)(this)}compareSymbolParams(e){return(0,F.compareSymbolParams)(this,e,this._model.unitConversionEnabled())}async setSymbolParams(e){this._setSymbolCurrencyUnitInternal(e)}symbol(){return this.properties().childs().inputs.childs().symbol.value()}symbolOrAlias(){return this.symbol()}symbolChanged(){return this.properties().childs().inputs.childs().symbol}onSymbolIntervalChanged(){return this.symbolChanged()}setSymbol(e){this.setSymbolParams({symbol:e})}symbolInfo(){if(!this._resolvedSymbols)return null;const e=this.symbol();if(!e)return null;let t;return t=this._resolvedSymbols[this._getSymbolForResolve(e)]||null,t}symbolInfoWV(){return this._symbolInfoWV}aliasSymbolInfo(){return this.symbolInfo()}
symbolResolved(){return this.symbolsResolved()}symbolResolvingActive(){return this._symbolResolvingActive}symbolHibernated(){return this._symbolHibernated}isVisible(){const e=super.isVisible();return this._symbolHibernated.setValue(!e),e}symbolSameAsCurrent(e){return(0,F.symbolSameAsCurrent)(e,this.symbolInfo())}symbolSameAsResolved(e){return(0,k.symbolSameAsResolved)(e,this._lastResolvedSymbolSource,this.symbol())}currency(){return this.properties().childs().currencyId.value()||null}setCurrency(e){this.setSymbolParams({currency:e})}isConvertedToOtherCurrency(){return(0,n.isConvertedToOtherCurrency)(this.symbolInfo())}unit(){return this.properties().childs().unitId.value()||null}setUnit(e){this.setSymbolParams({unit:e})}isConvertedToOtherUnit(){return(0,n.isConvertedToOtherUnit)(this.symbolInfo(),this._model.unitConversionEnabled())}style(){return 2}setStyle(e){}interval(){return this._model.mainSeries().interval()}setInterval(e){}symbolSource(){return this}symbolSourceWV(){return this._symbolSourceWV}valueAt(e,t){return this.data().search(e)?.value[1]??null}state(e,t){const s=super.state(e,t);this._model.unitConversionEnabled()||delete s.state.unitId;const r=this.symbol();return s.state.inputs.symbol=(0,n.symbolToSaveInState)(this.symbolInfo()??this._model.chartApi().lastSymbolResolveInfo(r),r),e&&((0,i.ensureDefined)(s.data).symbols={___snapshot:this.symbolInfo()||void 0}),s}symbolTitle(e,t,s){return this.title(e,!0,{},!1,t)}titleInParts(e,t,s,i,r){const l=this._titleInParts(e,t,s,i,r);return[[l[0],...l[1]??[]].join(", ")]}tags(){const e=this.symbol();return e?[e]:[]}statusView(){return H?super.statusView():null}guiPlotName(e,t){return this.properties().childs().inputs.childs().symbol.value()}canOverrideMinTick(){return!0}canBeHiddenByGlobalFlag(){return!1}legendValuesProvider(){return new T(this,this.model())}statusProvider(e){return new E(this)}measureUnitId(){return(0,n.measureUnitId)(this.symbolInfo())}getSymbolString(e){return void 0===e&&(e=this._getSymbolForApi(this.symbol())),(0,d.encodeExtendedSymbolOrGetSimpleSymbolString)(this._getSymbolObject(e))}_createPriceAxisView(e){return new p(this,{plotIndex:"compare"})}_createViews(){this._legendView||(this._legendView=new L(this,this._model)),this._dataWindowView||(this._dataWindowView=new w(this,this._model)),this._statusView||(this._statusView=new A.StudyStatusView(this)),super._createViews()}_onUnitChanged(){"alwaysOff"!==(0,l.currencyUnitVisibilityProperty)().value()&&this._model.fullUpdate(),this._model.unitConversionEnabled()&&this.isStarted()&&this._tryChangeInputs(),this._unitChanged.fire()}_getSymbolObject(e){const t=super._getSymbolObject(e),s=this.currency();null!==s&&(t["currency-id"]=s);const i=this.unit();return this._model.unitConversionEnabled()&&null!==i&&(t["unit-id"]=i),t}_onSymbolResolvingStart(e,t){this._lastResolvedSymbolSource=t,super._onSymbolResolvingStart(e,t),this._symbolResolvingActive.setValue(!0)}_onSymbolError(){super._onSymbolError(),this._symbolResolvingActive.setValue(!1)}_onSymbolResolved(e,t,s){super._onSymbolResolved(e,t,s),
this._recreatePriceFormattingDependencies();const i=t===this.symbol()?(0,a.extractSymbolNameFromSymbolInfo)(s,this.symbol()):null,r=(0,n.symbolCurrency)(s),l=(0,n.symbolUnit)(s,this._model.unitConversionEnabled());this._setSymbolCurrencyUnitInternal({symbol:i??void 0,currency:r,unit:l},s),this._symbolResolvingActive.setValue(!1)}async _changeInputsImpl(e,t){await super._changeInputsImpl(e,t),this._realignLineToolsIfParamsChanged()}_createStudyOnServer(){const e=super._createStudyOnServer();return this._realignLineToolsIfParamsChanged(),e}_tryCreateFormatter(){const e=R.customFormatters?.priceFormatterFactory?.(this.symbolInfo(),this.properties().childs().minTick.value())??null;return null!==e?e:(0,n.createSeriesFormatter)(this.symbolInfo(),this.properties().childs().minTick.value())}_tryCreateDefaultFormatter(){return(0,n.createSeriesFormatter)(this.symbolInfo(),"default")}_titleInParts(e,t,s,i,r){const l=this.symbolInfo();return[this._getSymbolTitlePart(l),[this._getExchangeTitlePart(l,r),this._getPriceSourceTitlePart(l)].filter((e=>null!==e))]}_skipHistogramBaseOnAutoScale(){return!0}_getSymbolTitlePart(e){if(null===e)return N?"":this.properties().childs().inputs.childs().symbol.value();const t=(0,n.getSymbolListedExchange)(e);if(D&&void 0!==t)return t;if(U)switch(this._model.mainSeries().symbolTextSourceProxyProperty().value()){case"description":return e.description;case"ticker-and-description":return`${e.name}, ${e.description}`;case"long-description":return e.long_description??e.description}return e.name}_getExchangeTitlePart(e,t){return null===e||t?null:(0,n.getSymbolListedExchange)(e)}_getPriceSourceTitlePart(e){return B&&!1!==this._model.properties().childs().paneProperties.childs().legendProperties.childs().showPriceSource.value()&&void 0!==e?.price_source_id?this._model.availablePriceSources(this.getSymbolString(this._getSymbolForApi(this.symbol()))).name(e.price_source_id)??null:null}_setSymbolCurrencyUnitInternal(e,t){const{symbol:s,currency:i,unit:r}=e,l=this.properties().childs(),o=l.inputs.childs().symbol.value(),a=l.currencyId.value(),u=l.unitId.value();if(void 0!==s&&l.inputs.childs().symbol.setValueSilently(s),void 0!==i&&l.currencyId.setValueSilently(i),void 0!==r&&l.unitId.setValueSilently(r),t)this._resolvedSymbolsByInput[this.symbol()]=t,this._resolvedSymbols[this._getSymbolForResolve(this.symbol())]=t,this._realignToolsLastParams=null;else{const e=this.symbolInfo();null!==e&&(l.currencyId.setValueSilently((0,n.symbolCurrency)(e)),l.unitId.setValueSilently((0,n.symbolUnit)(e,this._model.unitConversionEnabled())))}l.inputs.childs().symbol.value()!==o&&l.inputs.childs().symbol.fireChanged(),l.currencyId.value()!==a&&l.currencyId.fireChanged(),l.unitId.value()!==u&&l.unitId.fireChanged(),this._realignLineToolsIfParamsChanged()}_realignLineToolsIfParamsChanged(){let e=null===this._realignToolsLastParams;if(null!==this._realignToolsLastParams){const t=this.compareSymbolParams(this._realignToolsLastParams);e=t.symbolChanged||t.intervalChanged||t.currencyChanged||t.unitChanged}
e&&(this._model.realignLineTools(this),this._realignToolsLastParams=this.symbolParams())}}}}]);