"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[5500],{55157:(e,t,s)=>{s.r(t),s.d(t,{LineToolAnchoredVWAP:()=>L});var i=s(50151),r=s(19844),n=s(87465),a=s(43337),l=s(23502),o=s(24062),d=s(65045),u=s(63670);class h extends u.StudyPriceAxisView{_showPaneLabel(){return!1}_showAxisLabel(){const e=this._model.properties().childs().scalesProperties.childs();return this._visible()&&"VWAP"===this._data.plotIndex&&e.showStudyLastValue.value()}_visible(){const e=this._source.properties().childs().styles.childs()[this._data.plotIndex].childs().display.value();return this._source.properties().childs().axisLabelVisible.value()&&Boolean(4&e)}}var c=s(96025);class p extends c.StudyPlotPaneView{constructor(e,t,s,i){super(e,t,s,i),this._line=e}_makeSureRendererIsValid(){(this._dataInvalidated||this._viewportInvalidated)&&this._updateImplFull(this._viewportInvalidated)&&(this._dataInvalidated=null),this._viewportInvalidated=!1}_updateRenderer(e,t){super._updateRenderer(e,t),this._addAlertsRenderer()}_addAlertsRenderer(){return!1}}var y=s(9343),_=s(78176),f=s(5605),P=(s(89323),s(40472)),w=s(69708),b=s(35107),S=s(5471);class A extends b.StudyLineDataSource{lastValueData(e,t,s){const r={noData:!0},n=this.priceScale();if(this._model.timeScale().isEmpty()||null===this.priceScale()||null===n||n.isEmpty()||this.plots().isEmpty())return r;const a=this._model.timeScale().visibleBarsStrictRange();if(null===a)return r;const l=this._studyProps();if(!l.childs().visible.value())return r;const o=this.plots().search(a.lastBar(),S.PlotRowSearchMode.NearestLeft,1);if(null===o)return r;const d=a.contains(o.index),u=!t&&d?o:(0,i.ensureNotNull)(this.plots().last()),h=this.metaInfo().plots.findIndex((t=>t.id===e));if(h<0||!u||!(0,w.default)(u.value[h+1]))return r;const c=u.value[h+1];if(null==c)return r;const p=(0,i.ensureDefined)(l.childs().styles.child(e)),y=(0,i.ensureNotNull)(this.firstValue()),_=n.priceToCoordinate(c,y);return{...n.getFormattedValues(c,y),noData:!1,price:c,color:p.childs().color.value(),coordinate:_,floatCoordinate:_,index:u.index}}priceLabelText(e){const t=(0,i.ensureDefined)(this._metaInfo.styles);return(0,i.ensureDefined)(t[e]).title}offset(e){return 0}getMinFirstBarIndexForPlot(){return-1/0}isPlotVisibleAt(e,t){return(this._studyProps().childs().styles.childs()[e].childs().display.value()&t)===t}_studyProps(){return this.properties()}}var g=s(69555),m=s(72972),V=s(91111);const I=(0,y.getLogger)("Chart.AnchoredVWAP"),v=(0,i.ensureDefined)(V.lineToolsStudyIds.LineToolAnchoredVWAP),C=!0;function R(e,t,s,r){return"calculate_stDev"in(0,i.ensureDefined)(e.inputs)||void 0===r.inputs.find((e=>"calculate_stDev"===e.id))||((0,i.ensureDefined)(t.inputs).calculate_stDev=!1),t.styles&&(x(t.styles.VWAP,r.defaults.styles?.VWAP?.display),x(t.styles.UpperBand,r.defaults.styles?.UpperBand?.display),x(t.styles.LowerBand,r.defaults.styles?.LowerBand?.display),x(t.styles.UpperBand_2,r.defaults.styles?.UpperBand_2?.display),x(t.styles.LowerBand_2,r.defaults.styles?.LowerBand_2?.display),
x(t.styles.UpperBand_3,r.defaults.styles?.UpperBand_3?.display),x(t.styles.LowerBand_3,r.defaults.styles?.LowerBand_3?.display)),t}function x(e,t){if(void 0!==e&&void 0!==e.visible){if(void 0!==e.display&&e.display!==t)return;e.display=e.visible?15:0,delete e.visible}}class L extends A{constructor(e,t,s,r,n){s=s||(0,i.ensureNotNull)((0,m.studyMetaInfoRepository)().findByIdSync({type:"java",studyId:v}));const a=t??L.createProperties(e.backgroundTheme().spawnOwnership());super(e,s,"anchoredvwap",a,r,n),this._onVisibleBarsStrictRangeChanged=e=>{const t=this._getPointsetPoints()?.[0].index??null;null!==t&&null!==e&&e.contains(t)&&this._onStudyInputsMayChange()};const[l,o,d,u,y,_,P]=this.metaInfo().plots,w=e.mainSeries(),b=[new p(this,w,e,l.id)];o&&d&&(b.push(new c.StudyPlotPaneView(this,w,e,o.id)),b.push(new c.StudyPlotPaneView(this,w,e,d.id))),u&&y&&_&&P&&(b.push(new c.StudyPlotPaneView(this,w,e,u.id)),b.push(new c.StudyPlotPaneView(this,w,e,y.id)),b.push(new c.StudyPlotPaneView(this,w,e,_.id)),b.push(new c.StudyPlotPaneView(this,w,e,P.id))),this._properties.childs().areaBackground&&b.splice(0,0,new f.AreaBackgroundPaneView(this,e)),this._priceAxisViews=this.metaInfo().plots.map((e=>new h(this,{plotIndex:e.id}))),b.push(...this._priceAxisViews.map((e=>new g.PanePriceAxisView(e,this,this._model)))),this._anchorPriceCalculated=!1,this._onInputsReadyCallbacks=[],this._setPaneViews(b),e.properties().childs().scalesProperties.childs().showStudyLastValue.subscribe(this,this._onShowStudyLastValueChanged),a.onRestoreFactoryDefaults().subscribe(this,this._onRestoreFactoryDefaults),this._hasAlert.subscribe(this.processHibernate.bind(this),{callWithLast:!0}),this._model.timeScale().visibleBarsStrictRangeChanged().subscribe(this,this._onVisibleBarsStrictRangeChanged)}destroy(){this.properties().onRestoreFactoryDefaults().unsubscribeAll(this),this.model().properties().childs().scalesProperties.childs().showStudyLastValue.unsubscribeAll(this),this._model.timeScale().visibleBarsStrictRangeChanged().unsubscribeAll(this),this._onInputsReadyCallbacks=[],super.destroy()}cloneable(){return!1}canHasAlert(){return!0}pointsCount(){return 1}updateAllViews(e){super.updateAllViews(e),this._priceAxisViews.forEach((t=>t.update(e)))}firstValue(){return this._model.mainSeries().firstValue()}priceRange(e,t,s){if(!this._isReady()||this.isSourceHidden()||s.targetPriceScale!==this.priceScale())return null;const r=this.plots().minMaxOnRangeCached(e,t,[{name:this.metaInfo().plots[0].id,offset:0}]);if(null===r)return null;const n=(0,i.ensureNotNull)(this.priceScale());return n.isLog()?new o.PriceRange(n.priceToLogical(r.min),n.priceToLogical(r.max)):new o.PriceRange(r.min,r.max)}isIncludedInAutoScale(){return!0}restoreData(e){super.restoreData(e),void 0!==e.data&&(this._anchorPriceCalculated=!0)}properties(){return super.properties()}sourceId(){return this._studyId()}hasStateForAlert(){return!1}stateForAlert(){throw new Error("Not implemented")}inputsForAlertState(){
return null===this._inputs&&I.logWarn("Could not get inputsForAlertState if VWAP has no inputs"),{...this.inputs()}}inputs(){return(0,i.ensureNotNull)(this._inputs)}idForAlert(){return super.idForAlert()}defaultPlotIdForAlert(){return this.metaInfo().plots[0].id}canBeHibernated(){return super.canBeHibernated()&&!this._hasAlert.value()}static createProperties(e,t){const s=r.StudyMetaInfo.getStudyPropertyRootNameById(v),a=(0,i.ensureNotNull)((0,m.studyMetaInfoRepository)().findByIdSync({type:"java",studyId:v})),l=(0,_.createDefaultsState)(!0,s,[],(0,m.studyMetaInfoRepository)().studyVersioning());return this.createPropertiesFromStudyMetaInfoAndState(a,a,(0,n.merge)((0,n.clone)(l),t??{}),(0,m.studyMetaInfoRepository)().studyVersioning(),e)}static studyId(){return v}static createPropertiesFromStudyMetaInfoAndState(e,t,s,i,r){const n=(0,l.prepareStudyPropertiesForLoadChart)(e,t,s,i,R,r);return this._configureProperties(n),n}_onPointsetUpdated(e){super._onPointsetUpdated(e),this._onStudyInputsMayChange()}_studyInputs(e){(0,i.assert)(1===e.length,"all the line tool points should be defined");const t=e[0],s=this._getPointTime(t,!1);return null===s?(this._subscribeApplyInputsOnSeriesCompleted(),null):{...this.properties().childs().inputs.state(["start_time"]),start_time:1e3*s}}_isReady(){return super._isReady()&&(null!==this._inputs||this._anchorPriceCalculated)&&this.model().lineBeingEdited()!==this}_onDataCleared(){super._onDataCleared(),this._anchorPriceCalculated=!1}_onInputsChanged(){if(super._onInputsChanged(),this._updateAlertCreationAvailable(),null!==this._inputs){for(const e of this._onInputsReadyCallbacks)try{e(this._inputs)}catch(e){I.logError(e.stack||e.message)}this._onInputsReadyCallbacks=[]}}_clearAllDataExceptPointsetPoints(){super._clearAllDataExceptPointsetPoints(),this._updateAlertCreationAvailable()}async _getPropertyDefinitionsViewModelClass(){return(await Promise.all([s.e(3198),s.e(5410),s.e(2745),s.e(8823),s.e(8537)]).then(s.bind(s,7750))).AnchoredVWAPDefinitionsViewModel}_updateAnchorsPrice(e){if(!e&&(this._anchorPriceCalculated||!this.isActualSymbol()))return;const t=this.firstValue(),s=this.points();if(null===t||0===s.length)return;const i=s[0].index,r=this.plots().valueAt(i);if(null===r)return;const n=r[1];null!=n&&(this._points[0].price=n,this._timePoint[0].price=n,this._anchorPriceCalculated=!0)}async _synchronizeAlert(e){this._onInputsReady((()=>super._synchronizeAlert(e)))}static _configureProperties(e){super._configureProperties(e),e.hasChild("axisLabelVisible")||e.addChild("axisLabelVisible",new a.Property(C));const t=e.childs().styles.childs().VWAP.childs().linewidth,s=e.childs().styles.childs().VWAP.childs().color;e.addChild("linesWidths",new d.LineToolWidthsProperty([t])),e.addChild("linesColors",new d.LineToolColorsProperty([s]))}_onInputsReady(e){null!==this._inputs?e(this._inputs):this._onInputsReadyCallbacks.push(e)}_onShowStudyLastValueChanged(){this._priceAxisViews.forEach((e=>e.update((0,P.sourceChangeEvent)(this.id())))),this.model().updateSource(this)}_onRestoreFactoryDefaults(){
this.properties().childs().axisLabelVisible.setValue(C)}}}}]);