Release v23.043 (from 3fdcc43e)
This commit is contained in:
@@ -414,7 +414,7 @@ return this._appliedTimeFrame.appliedTimeFrame()}barsMarksSources(){return this.
|
||||
;return a.invalidatePriceScale(r,n,o,t),a}_removeCustomSource(e){const t=this._customSourcesMap.get(e);if(void 0===t)return void Ai.logWarn(`Attempt to remove custom source which does not exist in the model - "${e}"`);Ai.logNormal(`Removing custom source "${e}"`),this.selectionMacro(e=>{e.removeSourceFromSelection(t)}),this._hoveredSource===t&&this.setHoveredSource(null),this._customSourceBeingMoved===t&&this.setMovingCustomSource(null,null);const i=Ei(this._bgCustomSources,t),s=Ei(this._fgCustomSources,t),n=Ei(this._topmostCustomSources,t),o=Ei(this._allCustomSources,t);(0,r.assert)(i||s||n,"Source should be presented in one of the layers"),(0,r.assert)(o,"Source should be presented in the array"),this._customSourcesMap.delete(e),t.destroy()}_updateShowLegendProperty(){const e=this._properties.childs().paneProperties.childs().legendProperties.childs().showLegend,t=this._showLegendProperty;if(e.value())t.setValue(!0);else{for(const e of this._panes){let i=0;for(const s of e.priceDataSources())if(s!==this.mainSeries()&&null!==s.statusView()&&(i++,i>1))return void t.setValue(!1)}t.setValue(!0)}}_pointToPercentPosition(e,t){return{x:e.x/this._timeScale.width(),y:e.y/(0,r.ensureNotNull)((0,r.ensureNotNull)(t.mainDataSource()).priceScale()).height()}}_percentPositionToPoint(e,t){const i=e.x*this._timeScale.width(),s=e.y*(0,r.ensureNotNull)((0,r.ensureNotNull)(t.mainDataSource()).priceScale()).height();return new n.Point(i,s)}_recalcVisibleRangeStudiesImpl(e){var t,i,s;if(e.timerId=null,this.timeScale().isEmpty())return;const r=this.timeScale().visibleBarsStrictRange();if(null===r)return;const n=this.mainSeries().bars(),o=n.search(r.firstBar(),ft.PlotRowSearchMode.NearestRight),a=n.search(r.lastBar(),ft.PlotRowSearchMode.NearestLeft),l=n.lastIndex(),c=o?o.index:void 0,h=a?a.index:void 0,d=c===e.oldStartVisibleIndex,u=h===e.oldEndVisibleIndex;if(d&&u&&!e.force)return;e.force=!1,e.oldStartVisibleIndex=void 0!==c?c:NaN,e.oldEndVisibleIndex=void 0!==h?h:NaN;const p={first_visible_bar_time:1e3*(null!==(t=null==o?void 0:o.value[0])&&void 0!==t?t:0),last_visible_bar_time:1e3*(null!==(i=null==a?void 0:a.value[0])&&void 0!==i?i:0),subscribeRealtime:(null==a?void 0:a.index)===l},_=null!==(s=e.studies)&&void 0!==s?s:this.priceDataSources();e.studies=void 0;for(const e of _)if((0,H.isStudy)(e)){const t=e.metaInfo().inputs,i=[];for(const e of t)p.hasOwnProperty(e.id)&&i.push(e.id);const s=e.properties().inputs;for(const e of i)s[e].setValueSilently(p[e]);i.length>0&&s.listeners().fire(s)}}_recalcColorStudiesImpl(e){var t;e.timerId=null;const i=this.backgroundColorAtYPercentFromTop(.5),s=this.isDark()?a.colorsPalette["color-cold-gray-200"]:a.colorsPalette["color-cold-gray-900"],r=i===e.oldBgColor,n=s===e.oldFgColor;if(r&&n&&!e.force)return;e.force=!1,e.oldBgColor=i,e.oldFgColor=s;const o={__chart_bgcolor:i,__chart_fgcolor:s},l=null!==(t=e.studies)&&void 0!==t?t:this.priceDataSources();e.studies=void 0;for(const e of l)if((0,H.isStudy)(e)){const t=e.metaInfo().inputs,i=[];for(const e of t)o.hasOwnProperty(e.id)&&i.push(e.id)
|
||||
;const s=e.properties().inputs;for(const e of i)s[e].setValueSilently(o[e]);i.length>0&&s.listeners().fire(s)}}_getAllSources(e){const t=[];for(const i of this._panes){const s=i.sourcesByGroup().all();for(const i of s)e(i)&&t.push(i)}return t}_invalidateBarColorerCaches(){this.mainSeries().invalidateBarColorerCache()}_updateTimeScale(e){var t,i;const{index:s,zoffset:r,values:n,indexDiffs:o,baseIndex:a,marks:l,clearFlag:c}=e;if(c){this._timeScale.reset();for(const e of this.dataSources())null===(t=e.clearData)||void 0===t||t.call(e)}if(o.length>0)for(const e of this.dataSources())null===(i=e.moveData)||void 0===i||i.call(e,o);const h=this._timeScale.indexToTimePoint(this._timeScale.baseIndex()),d=this._timeScale.canNormalize();this._timeScale.update(s,r,n,l);let u="ChartModel.prototype._updateTimeScale("+s+","+r+","+n.length+","+o.length+","+l.length+","+c+")";if(u+="TimeScale: {first:"+this._timeScale.points().firstIndex()+",last:"+this._timeScale.points().lastIndex()+"}",null===a){this._timeScale.resetBaseIndex();const e=this._timeScale.rightOffset();e<0?this._timeScale.setRightOffset(this.studyAwareDefaultRightOffset()):this._timeScale.setRightOffset(Math.max(e,this._cachedStudiesMaxOffset))}else if(void 0!==a){const e=this._timeScale.indexToTimePoint(a),t=null!==h&&null!==e&&e>h;this._updateBaseIndex(a,t)}if(Ai.logDebug(u),!d&&d!==this._timeScale.canNormalize())for(const e of this.dataSources())!(0,f.isLineTool)(e)||e.isFixed()||e.isSourceHidden()||e.processHibernate();this.recalculateAllPanes((0,O.globalChangeEvent)()),this.lightUpdate()}_getAvailableCurrencies(){return!this.currencyConversionEnabled()||this.isSnapshot()?[]:(0,_e.isArray)(this._availableCurrenciesList)?this._availableCurrenciesList:(null!==this._availableCurrenciesList||(this._availableCurrenciesList=this.chartApi().availableCurrencies(),this._availableCurrenciesList.then(e=>{this._destroyed||(this._availableCurrenciesList=e,this.fullUpdate())}).catch(e=>{Ai.logWarn("An error occurred while getting currencies config: "+e)})),[])}_getAvailableUnits(){return!this.unitConversionEnabled()||this.isSnapshot()?{}:this._availableUnitsObject instanceof Promise||null===this._availableUnitsObject?(null!==this._availableUnitsObject||(this._availableUnitsObject=this.chartApi().availableUnits(),this._availableUnitsObject.then(e=>{this._destroyed||(this._availableUnitsObject=e,this.fullUpdate())}).catch(e=>{Ai.logWarn("An error occurred while getting units config: "+e)})),{}):this._availableUnitsObject}_getBackgroundColor(e){const t=this._properties.childs().paneProperties.childs();if(t.backgroundType.value()===dt.ColorType.Gradient){const i=t.backgroundGradientStartColor.value(),s=t.backgroundGradientEndColor.value();return e?i:s}return t.background.value()}_updateBackgroundColor(){this._backgroundColor.setValue(this._getBackgroundColor()),this._backgroundTopColor.setValue(this._getBackgroundColor(!0))}_syncCrosshair(e){if(!this._isSettingsExternalPosition){
|
||||
const t=this._undoModel.chartWidget(),i=this._undoModel.mainSeries(),s=i.syncModel(),r=this._undoModel.crossHairSource(),n=r.pane;if(null!==s&&null!==n){const o={timeStamp:this._timeScale.points().roughTime(r.index,s.projectTime.bind(s)),syncSourceTarget:s.syncSourceTarget()};n.mainDataSource()===i&&(o.price=r.price,o.symbol=i.symbol());let a=this._lineBeingCreated||null!==this._linePointBeingEdited||Boolean(this._sourcesBeingMoved.length);a=a&&(0,lt.drawOnAllCharts)().value(),t.chartWidgetCollection().syncCrosshair(o,t.id(),a,e)}this._phantomSourceContainer.onCursorPositionUpdated()}}_gotoTimeImpl(e,t){const i=this.timeScale(),s=this.mainSeries();let n;if(void 0!==e){if(this._scrollingState&&this._scrollingState.deferred.reject(),n=(0,d.createDeferredPromise)(),!s.isDWM()){const t=s.symbolInfo();if(null!==t){let i=this.properties().childs().timezone.value();"exchange"===i&&(i=t.timezone);const r=(0,it.cal_to_utc)((0,it.get_timezone)(i),new Date(e)),n=(0,wt.createTimeToBarTimeAligner)(s.interval(),t)(r);e=(0,it.utc_to_cal)((0,it.get_timezone)(i),n).getTime()}}this._scrollingState={targetDate:e,deferred:n,centerIfVisible:t.centerIfVisible}}else{if(!this._scrollingState)return Ai.logError("scrollTo called without an argument"),Promise.reject();e=this._scrollingState.targetDate,n=this._scrollingState.deferred}if(void 0===i.tickMarks().minIndex)return n.resolve(void 0),n.promise;let o=((e,t)=>{if((e=>(0,r.ensureNotNull)(i.tickMarks().indexToTime((0,r.ensureDefined)(i.tickMarks().minIndex))).valueOf()-e)(t)<0){let n=i.tickMarks().nearestIndex(t);const o=s.bars().lastIndex();if(null===o)return null;n=Math.min(n,o);let a=(0,r.ensureNotNull)(i.tickMarks().indexToTime(n)).valueOf();for(;a<t&&n<o;)n++,a=(0,r.ensureNotNull)(i.tickMarks().indexToTime(n)).valueOf();const l=(0,r.ensureNotNull)(i.visibleBarsStrictRange()),c=l.lastBar()-l.firstBar();return!e&&l.contains(n)||i.zoomToBarsRange(n-c/2,n+c/2),{timestamp:(0,r.ensureNotNull)(i.indexToTimePoint(n))}}return null})(this._scrollingState.centerIfVisible,this._scrollingState.targetDate);if(!o){const t=(0,r.ensureDefined)(i.tickMarks().minIndex),n=(0,r.ensureNotNull)(i.visibleBarsStrictRange()),a=n.lastBar()-n.firstBar();if(s.requestMoreDataAvailable()){const t=i.tickMarks().estimateLeft(e);i.requestMoreHistoryPoints(Math.ceil(t+a/2))}else i.zoomToBarsRange(t-a/2,t+a/2),o={timestamp:(0,r.ensureNotNull)(i.indexToTimePoint(t)),eod:!0}}return o&&(this.fullUpdate(),this._scrollingState=null,n.resolve(o)),n.promise}_setCorrectedPositionToCrosshair(e,t,i,s){const n=this.crossHairSource();n.setPosition(e,t,s);const o=this._timeScale.indexToCoordinate(e),a=s.defaultPriceScale().priceToCoordinate(t,(0,r.ensureNotNull)(i));n.saveOriginCoords(o,a)}_onSymbolSourceCollectionChanged(e){this._recalcAdjustForDividendsAvailibility(),this._symbolSourceCollectionChanged.fire(e)}_getExceedingChildStudies(e){let t=[];for(let i=0;i<e.length;++i)t=t.concat(e[i].sources||[]);let i=0;const s=[],r={};let n=0,o=1e6;for(;t.length&&--o;){const e=t[n]
|
||||
;(e.ownerSource&&r[e.ownerSource]||!e.ownerSource)&&(r[e.id]=e,t.splice(t.indexOf(e),1),e.ownerSource&&(0,he.isStudyState)(e)&&e.state&&e.state.isChildStudy&&++i>1&&s.push(e)),n=(n+1)%t.length}return s}}},15943:(e,t,i)=>{"use strict";i.d(t,{japaneseChartStyles:()=>r,commonChartStyles:()=>n,allChartStyles:()=>o});var s=i(67337);function r(){return s.enabled("japanese_chart_styles"),[8]}function n(){const e=[0,1,9,13,2,3,10];return s.enabled("chart_style_hilo")&&e.push(12),e}function o(){return n().concat(r())}},97205:(e,t,i)=>{"use strict";i.d(t,{ChartUndoModelBase:()=>Wi});var s=i(85459),r=i.n(s),n=i(16230),o=i(88537),a=i(86441),l=i(28353),c=i(24980),h=i(68587),d=i(65645),u=i(67072),p=i.n(u),_=i(98125);const m=new c.TranslatedString("move all scales to left",(0,l.t)("move all scales to left")),g=new c.TranslatedString("move all scales to right",(0,l.t)("move all scales to right")),f=(0,_.getLogger)("Chart.MergeAllScales");var v=i(44556),S=i(35762);class y extends S.UndoCommand{constructor(e,t,i,s,r,n){super(n),this._model=e,this._paneIndex=e.panes().indexOf(t),this._targetPosition=s,this._targetIndex=r,this._scaleId=i.id(),this._sourcePosition=t.priceScalePosition(i),"overlay"!==this._sourcePosition&&(this._sourceIndex=t.priceScaleIndex(i,this._sourcePosition))}redo(){const e=this._model.panes()[this._paneIndex],t=(0,o.ensureNotNull)(e.getPriceScaleById(this._scaleId));e.movePriceScale(t,this._targetPosition,this._targetIndex),this._model.fullUpdate()}undo(){const e=this._model.panes()[this._paneIndex],t=(0,o.ensureNotNull)(e.getPriceScaleById(this._scaleId));e.movePriceScale(t,this._sourcePosition,this._sourceIndex),this._model.fullUpdate()}}var b=i(14291);class w extends S.UndoCommand{constructor(e,t,i,s){super(s),this._createdIds=[],this._model=e,this._withoutShift=i,this._origStates=t.map(e=>e.state(!0));const r=e.lineToolsGroupModel();this._origGroups=t.map(e=>{const t=r.groupForLineTool(e);return t&&t.id})}redo(){const e=this._model.lineToolsGroupModel(),t=this._origStates.map((t,i)=>{const s=(0,o.ensureNotNull)(this._model.dataSourceForId(t.id)),r=0===this._createdIds.length?void 0:(0,o.ensureDefined)(this._createdIds[i]),n=(0,b.cloneLineTool)(this._model,s,!this._withoutShift,r),a=(0,o.ensureNotNull)(s.priceScale());(0,o.ensureNotNull)(this._model.paneForSource(s)).addDataSource(n,a,!1);const l=this._origGroups[i];if(null!==l){const t=e.groupForId(l);t&&t.addLineTools([n])}return this._model.updateSource(n),n});0===this._createdIds.length&&(this._createdIds=t.map(e=>e.id())),this._model.selectionMacro(e=>{e.clearSelection(),t.forEach(t=>{e.addSourceToSelection(t)})}),this._model.setShouldBeSavedEvenIfHidden(!0)}undo(){const e=this._model.lineToolsGroupModel();this._createdIds.forEach(t=>{const i=(0,o.ensureNotNull)(this._model.dataSourceForId(t)),s=e.groupForLineTool(i);null!==s&&s.excludeLineTool(i),this._model.removeSource(i)})}newIds(){return this._createdIds}}var C=i(65284),P=i(79495),T=i(80643),x=i(81851);class I extends S.UndoCommand{constructor(e,t,i,s=!0){super(i,s),this._newStates=[],this._model=e,
|
||||
;(e.ownerSource&&r[e.ownerSource]||!e.ownerSource)&&(r[e.id]=e,t.splice(t.indexOf(e),1),e.ownerSource&&(0,he.isStudyState)(e)&&e.state&&e.state.isChildStudy&&++i>1&&s.push(e)),n=(n+1)%t.length}return s}}},15943:(e,t,i)=>{"use strict";i.d(t,{japaneseChartStyles:()=>r,commonChartStyles:()=>n,allChartStyles:()=>o});var s=i(67337);function r(){return s.enabled("japanese_chart_styles"),[8]}function n(){const e=[0,1,9,13,2,3,10];return s.enabled("chart_style_hilo")&&e.push(12),e}function o(){return n().concat(r())}},97205:(e,t,i)=>{"use strict";i.d(t,{ChartUndoModelBase:()=>Hi});var s=i(85459),r=i.n(s),n=i(16230),o=i(88537),a=i(86441),l=i(28353),c=i(24980),h=i(68587),d=i(65645),u=i(67072),p=i.n(u),_=i(98125);const m=new c.TranslatedString("move all scales to left",(0,l.t)("move all scales to left")),g=new c.TranslatedString("move all scales to right",(0,l.t)("move all scales to right")),f=(0,_.getLogger)("Chart.MergeAllScales");var v=i(44556),S=i(35762);class y extends S.UndoCommand{constructor(e,t,i,s,r,n){super(n),this._model=e,this._paneIndex=e.panes().indexOf(t),this._targetPosition=s,this._targetIndex=r,this._scaleId=i.id(),this._sourcePosition=t.priceScalePosition(i),"overlay"!==this._sourcePosition&&(this._sourceIndex=t.priceScaleIndex(i,this._sourcePosition))}redo(){const e=this._model.panes()[this._paneIndex],t=(0,o.ensureNotNull)(e.getPriceScaleById(this._scaleId));e.movePriceScale(t,this._targetPosition,this._targetIndex),this._model.fullUpdate()}undo(){const e=this._model.panes()[this._paneIndex],t=(0,o.ensureNotNull)(e.getPriceScaleById(this._scaleId));e.movePriceScale(t,this._sourcePosition,this._sourceIndex),this._model.fullUpdate()}}var b=i(14291);class w extends S.UndoCommand{constructor(e,t,i,s){super(s),this._createdIds=[],this._model=e,this._withoutShift=i,this._origStates=t.map(e=>e.state(!0));const r=e.lineToolsGroupModel();this._origGroups=t.map(e=>{const t=r.groupForLineTool(e);return t&&t.id})}redo(){const e=this._model.lineToolsGroupModel(),t=this._origStates.map((t,i)=>{const s=(0,o.ensureNotNull)(this._model.dataSourceForId(t.id)),r=0===this._createdIds.length?void 0:(0,o.ensureDefined)(this._createdIds[i]),n=(0,b.cloneLineTool)(this._model,s,!this._withoutShift,r),a=(0,o.ensureNotNull)(s.priceScale());(0,o.ensureNotNull)(this._model.paneForSource(s)).addDataSource(n,a,!1);const l=this._origGroups[i];if(null!==l){const t=e.groupForId(l);t&&t.addLineTools([n])}return this._model.updateSource(n),n});0===this._createdIds.length&&(this._createdIds=t.map(e=>e.id())),this._model.selectionMacro(e=>{e.clearSelection(),t.forEach(t=>{e.addSourceToSelection(t)})}),this._model.setShouldBeSavedEvenIfHidden(!0)}undo(){const e=this._model.lineToolsGroupModel();this._createdIds.forEach(t=>{const i=(0,o.ensureNotNull)(this._model.dataSourceForId(t)),s=e.groupForLineTool(i);null!==s&&s.excludeLineTool(i),this._model.removeSource(i)})}newIds(){return this._createdIds}}var C=i(65284),P=i(79495),T=i(80643),x=i(81851);class I extends S.UndoCommand{constructor(e,t,i,s=!0){super(i,s),this._newStates=[],this._model=e,
|
||||
this._savedStates=t.map(e=>e.state(!1))}redo(){this._applyState(this._newStates)}undo(){0===this._newStates.length&&this.saveNewState(),this._applyState(this._savedStates)}saveNewState(){const e=this._savedStates.filter(T.notNull).map(e=>(0,o.ensureNotNull)(this._model.dataSourceForId(e.id)));this._newStates=e.map(e=>e.state(!1))}_applyState(e){for(const t of e)if(null!==t){const e=this._model.dataSourceForId(t.id);if(null!==e)if((0,x.isStudy)(e)){const i=t.state.inputs,s=e.properties().inputs;for(const e in i)s[e]&&s[e].setValue(i[e])}else this._model.restoreLineToolState(e,t,!0)}}}var M=i(36551),L=i(8597),A=i(59555),E=i(60870);const k=new c.TranslatedString("create {tool}",(0,l.t)("create {tool}"));class D extends S.UndoCommand{constructor(e,t,i,s,r=0,n){super(k.format({tool:new c.TranslatedString(i,E.lineToolsLocalizedNames[i])}),!1),this._lineId=null,this._lineState=null,this._model=e,this._paneIndex=e.panes().indexOf(t),this._lineTool=i,this._ownerSourceId=s.id(),this._lineId=null!=n?n:null,this._drawOnAllChartsMode=r}startCreatingLine(e,t,i){var s;const r=this._model.panes()[this._paneIndex],n=this._model.dataSourceForId(this._ownerSourceId),o=this._model.createLineTool(r,e,this._lineTool,t,i,n,null!==(s=this._lineId)&&void 0!==s?s:void 0);return this._lineId=o.id(),!this._model.lineBeingCreated()}continueCreatingLine(e,t,i,s){const r=this._model.continueCreatingLine(e,t,i,s);return r&&this._model.setShouldBeSavedEvenIfHidden(!0),r}line(){return null===this._lineId?null:this._model.dataSourceForId(this._lineId)}undo(){const e=this.line();null!==e&&(this._lineState=e.state(!1),this._model.removeSource(e),this._lineId=null)}redo(){if(null===this._lineState)return;const e=this._model.restoreSource(!1,this._paneIndex,null,(0,o.ensureNotNull)(this._lineState),null);null!==e&&(this._lineId=e.id(),this._lineState=null,e.share(this._drawOnAllChartsMode))}drawOnAllCharts(){return 0!==this._drawOnAllChartsMode}}var V=i(94578);const B=new c.TranslatedString("bring {title} to front",(0,l.t)("bring {title} to front")),N=new c.TranslatedString("send {title} to back",(0,l.t)("send {title} to back")),R=new c.TranslatedString("insert {title} after {targetTitle}",(0,l.t)("insert {title} after {targetTitle}")),O=new c.TranslatedString("insert {title} before {targetTitle}",(0,l.t)("insert {title} before {targetTitle}")),F=new c.TranslatedString("send {title} backward",(0,l.t)("send {title} backward")),W=new c.TranslatedString("bring {title} forward",(0,l.t)("bring {title} forward")),H=new c.TranslatedString("send group {title} backward",(0,l.t)("send group {title} backward")),z=new c.TranslatedString("bring group {title} forward",(0,l.t)("bring group {title} forward"));function U(e){return new c.TranslatedString(e.name(),e.title())}class j extends S.UndoCommand{constructor(e,t,i){super(i),this._sourcesByPanes=new Map,this._originalState=new Map,this._model=e,t.forEach(t=>{const i=(0,o.ensureNotNull)(e.paneForSource(t)),s=e.panes().indexOf(i),r=this._sourcesByPanes.get(s)||[];r.push(t.id()),this._sourcesByPanes.set(s,r)}),
|
||||
Array.from(this._sourcesByPanes.keys()).forEach(t=>{const i=e.panes()[t],s=new Map;i.sourcesByGroup().allIncludingHidden().forEach(e=>{s.set(e.id(),e.zorder())}),this._originalState.set(t,s)})}undo(){this._originalState.forEach((e,t)=>{const i=this._model.panes()[t],s=new Map;e.forEach((e,t)=>{const r=(0,o.ensureNotNull)(i.dataSourceForId(t));s.set(r,e)}),i.setZOrders(s)})}redo(){this._sourcesByPanes.forEach((e,t)=>{const i=this._model.panes()[t],s=e.map(e=>(0,o.ensureNotNull)(i.dataSourceForId(e)));this._paneOperation(i,s)})}}class G extends j{constructor(e,t){super(e,t,B.format({title:U(t[0])}))}_paneOperation(e,t){e.bringToFront(t)}}class q extends j{constructor(e,t){super(e,t,N.format({title:U(t[0])}))}_paneOperation(e,t){e.sendToBack(t)}}class Y extends j{constructor(e,t,i,s){super(e,t,s),this._targetSource=i}_paneOperation(e,t){e.insertAfter(t,this._targetSource)}}class K extends Y{constructor(e,t,i){super(e,t,i,R.format({title:U(t[0]),targetTitle:U(i)}))}}class $ extends j{constructor(e,t,i,s){super(e,t,s),this._targetSource=i}_paneOperation(e,t){e.insertBefore(t,this._targetSource)}}class X extends ${constructor(e,t,i){super(e,t,i,O.format({title:U(t[0]),targetTitle:U(i)}))}}function Z(e,t){const i=t[0],s=e.sourcesByGroup().all().filter(e=>e.zorder()<i.zorder());if(0===s.length)throw new Error("Cannot move backward source that alreadt on back");let r=s[s.length-1];if((0,b.isLineTool)(r)){const t=e.model().lineToolsGroupModel().groupForLineTool(r);null!==t&&(r=t.lineTools()[0])}return r}class J extends ${constructor(e,t,i){super(e,i,Z(t,i),F.format({title:U(i[0])}))}}function Q(e,t){const i=t[t.length-1],s=e.sourcesByGroup().allExceptSpecialSources().filter(e=>e.zorder()>i.zorder());if(0===s.length)throw new Error("Cannot bring forward source that alreadt on back");let r=s[0];if((0,b.isLineTool)(r)){const t=e.model().lineToolsGroupModel().groupForLineTool(r);if(null!==t){const e=t.lineTools();r=e[e.length-1]}}return r}class ee extends Y{constructor(e,t,i){super(e,i,Q(t,i),W.format({title:U(i[0])}))}}function te(e,t){return(0,o.ensureNotNull)(e.paneForSource(t.lineTools()[0]))}class ie extends ${constructor(e,t){super(e,t.lineTools(),Z(te(e,t),t.lineTools()),H.format({title:t.name()}))}}class se extends Y{constructor(e,t){super(e,t.lineTools(),Q(te(e,t),t.lineTools()),z.format({title:t.name()}))}}const re=new c.TranslatedString("rearrange panes",(0,l.t)("rearrange panes"));class ne extends S.UndoCommand{constructor(e,t,i){super(re),this._chartModel=e,this._index=t,(0,T.isNumber)(i)?this._dstIndex=i:this._dstIndex="up"===i?t-1:t+1}redo(){this._checkIndices()&&this._chartModel.movePane(this._index,this._dstIndex)}undo(){this._checkIndices()&&this._chartModel.movePane(this._dstIndex,this._index)}_checkIndices(){const e=this._chartModel.panes().length;return this._index>=0&&this._index<e&&this._dstIndex>=0&&this._dstIndex<e}}var oe=i(13339),ae=i(23075),le=i(88564),ce=i(37667),he=i(82992),de=i(9315),ue=i(33291);class pe extends S.UndoCommand{constructor(e,t,i,s,r,n){super(s),this._prevPriceAxisProps={},
|
||||
this._property=e,this._mainSeries=i,this._value=t,this._model=r,this._chartWidget=n}redo(){const e=this._mainSeries,t=e.properties().childs();t.style===this._property&&e.isNeedRestart(this._value)&&this._chartWidget.screen.show(),this._prevResolution=t.interval.value(),this._prevValue=this._property.value(),this._storePriceAxisProps(),(0,le.saveDefaultProperties)(!0);const i=t.interval.value(),s=this._model.defaultResolutions(),r=(0,de.getResolutionByChartStyle)(this._value,i,s);he.linking.interval.setValue(r),e.setChartStyleWithIntervalIfNeeded(this._value,r),(0,ce.setLastUsedStyle)(this._value,e.symbolInfo()),(0,ce.preparePriceAxisProperties)(t),(0,le.saveDefaultProperties)(!1),this._invalidateModel()}undo(){const e=this._mainSeries;e.properties().childs().style===this._property&&e.isNeedRestart(this._value)&&this._chartWidget.screen.show(),(0,le.saveDefaultProperties)(!0),e.setChartStyleWithIntervalIfNeeded(this._prevValue,this._prevResolution),this._restorePriceAxisProps(),he.linking.interval.setValue(this._prevResolution),(0,le.saveDefaultProperties)(!1),this._invalidateModel()}_storePriceAxisProps(){const e=this._mainSeries.priceScale();this._prevPriceAxisProps=e.mode()}_restorePriceAxisProps(){this._mainSeries.priceScale().setMode(this._prevPriceAxisProps)}_invalidateModel(){this._model&&(this._model.recalculateAllPanes((0,ue.dataSourceChangeEvent)(this._model.mainSeries().id())),this._model.lightUpdate())}}var _e=i(64237),me=i(29823);const ge=new c.TranslatedString("change date range",(0,l.t)("change date range"));class fe extends S.UndoCommand{constructor(e,t){super(ge),this._modelsData=[],this._rangeOptions=t,this._modelsData.push({model:e,prevResolution:e.mainSeries().properties().childs().interval.value(),barSpacing:e.timeScale().barSpacing(),rightOffset:e.timeScale().rightOffset(),rangeOptions:e.appliedTimeFrame().value()})}redo(){const e=[];for(const t of this._modelsData){const i=t.model.mainSeries(),s=i.properties().childs().interval;me.Interval.isEqual(this._rangeOptions.res,s.value())?i.loadDataTo(this._rangeOptions.val):(e.push(s),i.setDefaultTimeframe(this._rangeOptions.val),s.setValueSilently(this._rangeOptions.res))}for(const t of e)t.listeners().fire(t)}undo(){const e=[];for(const t of this._modelsData){const i=t.model.mainSeries(),s=i.properties().childs().interval;t.prevResolution!==s.value()?(e.push(s),null!==t.rangeOptions&&i.setDefaultTimeframe(t.rangeOptions.val),s.setValueSilently(t.prevResolution)):null!==t.rangeOptions&&i.loadDataTo(t.rangeOptions.val);const r=t.model.timeScale();r.setBarSpacing(t.barSpacing),r.setRightOffset(t.rightOffset)}for(const t of e)t.listeners().fire(t)}canMerge(e){return e instanceof fe&&(0,_e.rangesAreEqual)(e._rangeOptions,this._rangeOptions)}merge(e){if(!(e instanceof fe))throw new Error("Invalid command to merge");this._modelsData=this._modelsData.concat(e._modelsData)}}var ve=i(59199),Se=i(81822);i(94419);class ye extends S.UndoCommand{constructor(e,t,i){super(i),this._model=e,this._groupId=t.id,this._groupName=t.name(),
|
||||
@@ -427,17 +427,17 @@ null!==a.mainDataSource()||i.removePane(a)}return i.syncESD(),s.priceScale().set
|
||||
this._move((0,o.ensureNotNull)(this._endEvent))}_move(e){const t=(0,o.ensureNotNull)(this._model.dataSourceForId(this._sourceId));(0,o.assert)(void 0!==t.moveItem,'The method "moveItem" is not defined'),t.moveItem&&t.moveItem(new a.Point(e.localX,e.localY),this._itemIndex,new at.EnvironmentState(e))}}class ht extends S.UndoCommand{constructor(e,t,i,s,r,n,o,a,l,c,h,d){super(d),this._studyId=null,this._paneState=null,this._chartModel=e,this._studyMetaInfo=t,this._props=s,this._addAsOverlay=r,this._parentId=null==n?null:n.id(),this._inputs=i,this._targetZOrder=h,this._preferredPriceScale=o,this._allowChangeCurrency=a,this._allowChangeUnit=l,this._paneSize=c}redo(){const e=null===this._parentId?void 0:this._chartModel.dataSourceForId(this._parentId),t=this._chartModel.insertStudyWithParams(this._studyMetaInfo,this._inputs,this._targetZOrder,this._props,this._addAsOverlay,e,this._preferredPriceScale,this._allowChangeCurrency,this._allowChangeUnit,this._paneSize,null===this._studyId?void 0:this._studyId);if(this._studyId=t.id(),t.childStudyByRebind().subscribe(null,()=>(0,tt.trackEvent)("SOS","Apply SOS","Rebind SOS")),this._chartModel.setShouldBeSavedEvenIfHidden(!0),null!==this._paneState){(0,o.ensureNotNull)(this._chartModel.paneForSource(t)).restoreState(this._paneState,!1,this._chartModel.version()),this._paneState=null}}undo(){const e=(0,o.ensureNotNull)(this._chartModel.dataSourceForId((0,o.ensureNotNull)(this._studyId))),t=(0,o.ensureNotNull)(this._chartModel.paneForSource(e)).state();this._chartModel.removeSource(e)&&(this._paneState=t)}insertedStudy(){return this._chartModel.dataSourceForId((0,o.ensureNotNull)(this._studyId))}}var dt=i(59836),ut=i(88735),pt=i.n(ut),_t=i(79222),mt=i(69746),gt=i(67337);const ft=new c.TranslatedString("zoom",(0,l.t)("zoom"));class vt extends S.UndoCommand{constructor(e,t,i,s,r,n){super(ft),this._barSpacing=null,this._rightBarsOffset=null,this._leftBarsOffset=null,this._priceMode=null,this._model=e,this._startBar=t,this._endBar=i,this._startPrice=s,this._endPrice=r,this._pane=n}redo(){const e=(0,o.ensureNotNull)(this._model.timeScale().visibleBarsStrictRange());this._leftBarsOffset=e.firstBar()-this._startBar,this._rightBarsOffset=e.lastBar()-this._endBar,this._barSpacing=this._model.timeScale().barSpacing(),this._priceMode=this._pane.defaultPriceScale().mode(),this._model.zoomToViewport(this._startBar,this._endBar,this._startPrice,this._endPrice,this._pane)}undo(){const e=this._model.timeScale(),t=this._pane.defaultPriceScale(),i=(0,o.ensureNotNull)(e.visibleBarsStrictRange());e.setBarSpacing((0,o.ensureNotNull)(this._barSpacing)),e.zoomToBarsRange(i.firstBar()+(0,o.ensureNotNull)(this._leftBarsOffset),i.lastBar()+(0,o.ensureNotNull)(this._rightBarsOffset)),t.setMode((0,o.ensureNotNull)(this._priceMode)),t.recalculatePriceRange((0,o.ensureNotNull)(e.visibleBarsStrictRange())),this._model.recalculateAllPanes((0,ue.viewportChangeEvent)()),this._model.lightUpdate()}}const St=(0,_.getLogger)("Chart.ChartUndoModel"),yt=new c.TranslatedString("zoom",(0,l.t)("zoom"))
|
||||
;class bt extends S.UndoCommand{constructor(e,t,i){super(yt),this._baseCmd=e,this._zoomStack=t,this._inOut=i}undo(){if(this._inOut){if(this._baseCmd!==this._zoomStack.head())return void St.logDebug("zoom stack inconsistency");this._baseCmd.undo(),this._zoomStack.pop()}else this._baseCmd.redo(),this._zoomStack.push(this._baseCmd)}redo(){if(this._inOut)this._baseCmd.redo(),this._zoomStack.push(this._baseCmd);else{if(this._baseCmd!==this._zoomStack.head())return void St.logDebug("zoom stack inconsistency");this._baseCmd.undo(),this._zoomStack.pop()}}}const wt=new c.TranslatedString("stop syncing drawing",(0,l.t)("stop syncing drawing"));class Ct extends S.UndoCommand{constructor(e,t){super(wt),this._model=e,this._sourceId=t.id(),this._linkKey=t.linkKey().value()}redo(){(0,o.ensureNotNull)(this._model.dataSourceForId(this._sourceId)).linkKey().setValue(null)}undo(){(0,o.ensureNotNull)(this._model.dataSourceForId(this._sourceId)).linkKey().setValue(this._linkKey)}}const Pt=new c.TranslatedString("restore defaults",(0,l.t)("restore defaults"));class Tt extends S.UndoCommand{constructor(e,t,i=Pt){super(i),this._chartModel=e,this._defaultProperty=t,this._state=t.state()}redo(){this._chartModel.restoreFactoryDefaults(this._defaultProperty)}undo(){this._defaultProperty.mergeAndFire(this._state),this._chartModel.mainSeries().onChartStyleChanged()}}var xt=i(52418);class It extends Tt{redo(){this._defaultProperty.hasChild("intervalsVisibilities")&&this._defaultProperty.childs().intervalsVisibilities.mergeAndFire(xt.intervalsVisibilitiesDefaults),super.redo()}}class Mt extends It{redo(){super.redo(),this._chartModel.recalcColorStudies(!0)}undo(){super.undo(),this._chartModel.recalcColorStudies(!0)}}var Lt=i(36759),At=i(15840),Et=i(59803);function kt(e){const{visible:t,...i}=e;return i}function Dt(e){const{visible:t,...i}=e;return i}function Vt(e){const{drawWick:t,drawBorder:i,drawBody:s,barColorsOnPrevClose:r,...n}=e;return n}function Bt(e){const{drawWick:t,drawBorder:i,drawBody:s,...r}=e;return r}function Nt(e){const{drawWick:t,drawBorder:i,drawBody:s,showRealLastPrice:r,inputs:n,...o}=e;return o}function Rt(e){const{barColorsOnPrevClose:t,dontDrawOpen:i,thinBars:s,...r}=e;return r}function Ot(e){const{showBorders:t,showLabels:i,fontSize:s,drawBody:r,...n}=e;return n}function Ft(e){const{linestyle:t,linewidth:i,styleType:s,priceSource:r,...n}=e;return n}function Wt(e){const{linestyle:t,linewidth:i,priceSource:s,...r}=e;return r}function Ht(e){const{inputs:t,...i}=e;return i}function zt(e){const{inputs:t,...i}=e;return i}function Ut(e){const{inputs:t,...i}=e;return i}function jt(e){const{inputs:t,...i}=e;return i}function Gt(e){const{topLineWidth:t,bottomLineWidth:i,baseLevelPercentage:s,priceSource:r,...n}=e;return n}function qt(e){const{thinBars:t,inputs:i,...s}=e;return s}function Yt(e){
|
||||
const{visible:t,style:i,symbol:s,interval:r,sessionId:n,highLowAvgPrice:o,showCountdown:a,bidAsk:l,prePostMarket:c,priceAxisProperties:h,candleStyle:d,hollowCandleStyle:u,haStyle:p,barStyle:_,hiloStyle:m,lineStyle:g,areaStyle:f,renkoStyle:v,pbStyle:S,kagiStyle:y,pnfStyle:b,baselineStyle:w,rangeStyle:C,...P}=e;return{bidAsk:kt(l),prePostMarket:Dt(c),candleStyle:Vt(d),hollowCandleStyle:Bt(u),haStyle:Nt(p),barStyle:Rt(_),hiloStyle:Ot(m),lineStyle:Ft(g),areaStyle:Wt(f),renkoStyle:Ht(v),pbStyle:zt(S),kagiStyle:Ut(y),pnfStyle:jt(b),baselineStyle:Gt(w),rangeStyle:qt(C),...P}}function Kt(e){const{scaleSeriesOnly:t,showSeriesLastValue:i,showStudyLastValue:s,showSymbolLabels:r,showBidAskLabels:n,showPrePostMarketPriceLabel:o,showStudyPlotLabels:a,showFundamentalNameLabel:l,showFundamentalLastValue:c,seriesLastValueMode:h,...d}=e;return d}function $t(e){const{topMargin:t,bottomMargin:i,...s}=e;return s}const Xt=new c.TranslatedString("apply chart theme",(0,l.t)("apply chart theme"));class Zt extends S.UndoCommand{constructor(e,t,i){var s,r,n;super(Xt),this._model=e,this._newSessionProps=t.sessions||(0,Et.factoryDefaults)("sessions"),["candleStyle","hollowCandleStyle","haStyle"].forEach(e=>{t.mainSourceProperties[e].wickUpColor=t.mainSourceProperties[e].wickUpColor||t.mainSourceProperties[e].wickColor,t.mainSourceProperties[e].wickDownColor=t.mainSourceProperties[e].wickDownColor||t.mainSourceProperties[e].wickColor}),t.chartProperties=null!==(s=t.chartProperties)&&void 0!==s?s:{paneProperties:void 0,scalesProperties:void 0},t.chartProperties.paneProperties.vertGridProperties=null!==(r=t.chartProperties.paneProperties.vertGridProperties)&&void 0!==r?r:t.chartProperties.paneProperties.gridProperties,t.chartProperties.paneProperties.horzGridProperties=null!==(n=t.chartProperties.paneProperties.horzGridProperties)&&void 0!==n?n:t.chartProperties.paneProperties.gridProperties;const o=this._model.properties().state().paneProperties.legendProperties;delete o.backgroundTransparency,t.chartProperties.paneProperties.legendProperties={...t.chartProperties.paneProperties.legendProperties,...o};const a=(0,Et.factoryDefaults)("chartproperties"),l=(0,At.deepExtend)({},a,t.chartProperties);this._newChartProps={paneProperties:$t(l.paneProperties),scalesProperties:Kt(l.scalesProperties)},e.timeScale().preserveBarSpacing()&&delete this._newChartProps.scalesProperties.barSpacing;const c=(0,Et.factoryDefaults)("chartproperties.mainSeriesProperties"),h=(0,At.deepExtend)({},c,t.mainSourceProperties);this._newSeriesProps=i?h:Yt(h);const d=e.properties().state();this._oldChartProps={paneProperties:$t(d.paneProperties),scalesProperties:Kt(d.scalesProperties)};const u=e.mainSeries().properties().state();this._oldSeriesProps=i?u:Yt(u),this._oldSessionProps=this._model.sessions().properties().state()}undo(){this._merge(this._oldChartProps,this._oldSeriesProps,this._oldSessionProps),this._model.mainSeries().onChartStyleChanged(),this._model.updateScales(),this._model.chartThemeLoaded()}redo(){
|
||||
this._merge(this._newChartProps,this._newSeriesProps,this._newSessionProps),this._model.mainSeries().onChartStyleChanged(),this._model.updateScales(),this._model.chartThemeLoaded()}_merge(e,t,i){var s,r,n,o;const a=this._model;(0,le.saveDefaultProperties)(!0),e&&(a.properties().childs().paneProperties.mergeAndFire(e.paneProperties),a.properties().childs().scalesProperties.mergeAndFire(e.scalesProperties)),"priceAxisProperties"in t&&a.mainSeries().priceScale().setMode({autoScale:null===(s=t.priceAxisProperties)||void 0===s?void 0:s.autoScale,percentage:null===(r=t.priceAxisProperties)||void 0===r?void 0:r.percentage,log:null===(n=t.priceAxisProperties)||void 0===n?void 0:n.log,lockScale:null===(o=t.priceAxisProperties)||void 0===o?void 0:o.lockScale}),a.mainSeries().properties().mergeAndFire(t),a.mainSeries().properties().saveDefaults(),a.mainSeries().createPaneView(),a.mainSeries().invalidateBarStylesCache(),a.recalculateAllPanes((0,ue.globalChangeEvent)()),a.fullUpdate(),a.properties().saveDefaults(),a.sessions().restoreState({properties:i},!1),(0,le.saveDefaultProperties)(!1)}}const Jt=new c.TranslatedString("change resolution",(0,l.t)("change resolution"));class Qt extends S.UndoCommand{constructor(e,t,i){let s;super(Jt),this._sourceId=e.id();const r=(0,ce.isRangeStyle)(e.style()),n=me.Interval.isRange(t);!r&&n?s=11:r&&!n&&(s=(0,ce.getLastUsedStyle)()),this._newSymbolParams={interval:t,style:s},this._prevSymbolParams={symbol:e.symbol(),currency:e.currency(),unit:e.unit(),interval:e.interval(),style:e.style()},this._chartWidget=i}redo(){this._chartWidget.screen.show();this._symbolSource().setSymbolParams(this._newSymbolParams)}undo(){this._chartWidget.screen.show();this._symbolSource().setSymbolParams(this._prevSymbolParams)}_symbolSource(){return(0,o.ensureNotNull)(this._chartWidget.model().model().dataSourceForId(this._sourceId))}}const ei=new c.TranslatedString("send {title} backward",(0,l.t)("send {title} backward")),ti=new c.TranslatedString("bring {title} forward",(0,l.t)("bring {title} forward")),ii=new c.TranslatedString("insert {title} after {target}",(0,l.t)("insert {title} after {target}")),si=new c.TranslatedString("insert {title} before {target}",(0,l.t)("insert {title} before {target}")),ri=new c.TranslatedString("cut {title}",(0,l.t)("cut {title}")),ni=new c.TranslatedString("cut sources",(0,l.t)("cut sources")),oi=new c.TranslatedString("remove {title}",(0,l.t)("remove {title}")),ai=new c.TranslatedString("remove drawings group",(0,l.t)("remove drawings group")),li=new c.TranslatedString("move scale",(0,l.t)("move scale")),ci=new c.TranslatedString("stop syncing line tool(s)",(0,l.t)("stop syncing line tool(s)")),hi=new c.TranslatedString("zoom out",(0,l.t)("zoom out")),di=new c.TranslatedString("zoom in",(0,l.t)("zoom in")),ui=new c.TranslatedString("move drawing(s)",(0,l.t)("move drawing(s)")),pi=new c.TranslatedString("load default drawing template",(0,l.t)("load default drawing template")),_i=new c.TranslatedString("change currency",(0,
|
||||
l.t)("change currency")),mi=new c.TranslatedString("change unit",(0,l.t)("change unit")),gi=new c.TranslatedString("clone line tools",(0,l.t)("clone line tools")),fi=new c.TranslatedString("merge up",(0,l.t)("merge up")),vi=new c.TranslatedString("merge down",(0,l.t)("merge down")),Si=new c.TranslatedString("merge to pane",(0,l.t)("merge to pane")),yi=new c.TranslatedString("unmerge up",(0,l.t)("unmerge up")),bi=new c.TranslatedString("unmerge down",(0,l.t)("unmerge down")),wi=new c.TranslatedString("unmerge to new bottom pane",(0,l.t)("unmerge to new bottom pane")),Ci=new c.TranslatedString("move {title} to new right scale",(0,l.t)("move {title} to new right scale")),Pi=new c.TranslatedString("move {title} to new left scale",(0,l.t)("move {title} to new left scale")),Ti=new c.TranslatedString("make {title} no scale (Full screen)",(0,l.t)("make {title} no scale (Full screen)")),xi=new c.TranslatedString("scroll time",(0,l.t)("scroll time")),Ii=new c.TranslatedString("scale time",(0,l.t)("scale time")),Mi=new c.TranslatedString("reset time scale",(0,l.t)("reset time scale")),Li=new c.TranslatedString("reset scales",(0,l.t)("reset scales")),Ai=new c.TranslatedString("create {tool}",(0,l.t)("create {tool}")),Ei=new c.TranslatedString("change {pointIndex} point",(0,l.t)("change {pointIndex} point")),ki=new c.TranslatedString("paste {title}",(0,l.t)("paste {title}")),Di=new c.TranslatedString("insert {title}",(0,l.t)("insert {title}")),Vi=new c.TranslatedString("remove all studies",(0,l.t)("remove all studies")),Bi=new c.TranslatedString("remove drawings",(0,l.t)("remove drawings")),Ni=new c.TranslatedString("remove all studies and drawing tools",(0,l.t)("remove all studies and drawing tools"));new c.TranslatedString("turn line tools sharing off",(0,l.t)("turn line tools sharing off")),new c.TranslatedString("share line tools in layout",(0,l.t)("share line tools in layout")),new c.TranslatedString("share line tools globally",(0,l.t)("share line tools globally"));function Ri(e,t){return{bringForwardEnabled:e.bringForwardEnabled||t.bringForwardEnabled,bringToFrontEnabled:e.bringToFrontEnabled||t.bringToFrontEnabled,sendBackwardEnabled:e.sendBackwardEnabled||t.sendBackwardEnabled,sendToBackEnabled:e.sendToBackEnabled||t.sendToBackEnabled}}function Oi(e){return new c.TranslatedString(e.name(),e.title())}function Fi(){return(0,Me.drawOnAllCharts)().value()?1:0}class Wi extends(r()){constructor(e,t,i,s,r,n,o,a,l,c,h){super(),this._createLineCommand=null,this._initialTimeScrollState=null,this._initialTimeScrollPos=null,this._scalePriceInfo=null,this._currentSourceMoveCommand=null,this._currentLineChangeCommand=null,this._currentCustomMoveCommand=null,this._zoomStack=new v.UndoStack,this._lineToolsDoNotAffectChartInvalidation=new Te.FeatureToggleWatchedValue("do_not_invalidate_chart_on_changing_line_tools",!1),this._chartWidget=n,this.m_model=new(pt())(e,t,i,s,r,this,a,l,c,h),this._undoHistory=o,this._lineToolsGroupController=new Re({model:this._model.bind(this),pushUndoCommand:this._pushUndoCommand.bind(this),
|
||||
beginUndoMacro:(e,t)=>{this._undoHistory.beginUndoMacro(e).setCustomFlag("doesnt_affect_save",!!t)},endUndoMacro:this._undoHistory.endUndoMacro.bind(this._undoHistory),emitEvent:this.emitEvent.bind(this)})}undoHistory(){return this._undoHistory}setWatchedValue(e,t,i){this._undoHistory.setWatchedValue(e,t,i)}lineToolsGroupController(){return this._lineToolsGroupController}mergeAllScales(e){!function(e,t){e.beginUndoMacro("left"===t?m:g),e.model().panes().forEach(i=>{const s="left"===t?i.rightPriceScales():i.leftPriceScales(),r=("left"===t?i.leftPriceScales():i.rightPriceScales()).concat(s),n="overlay"===i.priceScalePosition(i.defaultPriceScale())?r[0]:i.defaultPriceScale();e.movePriceScale(i,n,t,0),r.forEach(t=>{if(t===n)return;let s=t.mainSource();for(;null!==s;){e.moveToScale(s,i,n,null,!0);const r=t.mainSource();if(r===s){f.logError("Loop detected while trying to merge scales");break}s=r}})}),e.endUndoMacro(),e.model().fullUpdate()}(this,e)}movePriceScale(e,t,i,s){const r=new y(this._model(),e,t,i,s,li);this._pushUndoCommand(r)}createLineTool({pane:e,point:t,linetool:i,properties:s,linkKey:r,ownerSource:n,disableSynchronization:a,sharingMode:l=Fi(),id:h}){if(("LineToolRegressionTrend"===i||"LineToolAnchoredVWAP"===i)&&!this.canCreateStudy())return(0,d.showTooManyStudiesNotice)(),null;const u=Ai.format({tool:new c.TranslatedString(i,E.lineToolsLocalizedNames[i])});this.beginUndoMacro(u,this._lineToolsDoNotAffectChartInvalidation.value());const p=!a;this._createLineCommand=new D(this._model(),e,i,n||(0,o.ensureNotNull)(e.mainDataSource()),l,h);const _=this._createLineCommand.startCreatingLine(t,s,r||null),m=(0,o.ensureNotNull)(this._createLineCommand.line());let g=null;if(_&&(p&&this.finishLineTool(m),this._pushUndoCommand(this._createLineCommand),this._createLineCommand=null,g={points:m.normalizedPoints(),interval:this.mainSeries().interval()}),p&&void 0===r&&(0,Me.drawOnAllCharts)().value()&&m.isSynchronizable()){const e=(0,o.ensureNotNull)(this.model().externalTimeStamp(t.index)),s={point:{price:t.price,timeStamp:e},linetool:i,properties:m.properties(),symbol:this.mainSeries().symbol(),model:this.model(),linkKey:(0,o.ensureNotNull)(m.linkKey().value()),finalState:g,id:m.id()};m.isFixed()&&(s.pointPositionPercents=m.calcPositionPercents()[0]),(0,Me.createLineTool)(s)}return this.endUndoMacro(),m}continueCreatingLine(e,t,i,s){const r=(0,o.ensureNotNull)(this._createLineCommand);this.beginUndoMacro(r.text(),this._lineToolsDoNotAffectChartInvalidation.value());const n=(0,o.ensureNotNull)(this._model().lineBeingCreated()),a=r.continueCreatingLine(e,t,i,s);let l=null;if(a&&(this.finishLineTool(n),this._pushUndoCommand(r),this._createLineCommand=null,l={points:n.normalizedPoints(),interval:this.mainSeries().interval()}),r.drawOnAllCharts()&&n.isSynchronizable()){const i=(0,o.ensureNotNull)(this._model().externalTimeStamp(e.index));(0,Me.continueLineTool)({point:{price:e.price,timeStamp:i},envState:t,finalState:l,model:this._model()})}return this.endUndoMacro(),a}continueExternalLine(e,t,i){const s=(0,
|
||||
o.ensureNotNull)(this._createLineCommand),r=s.continueCreatingLine(e,t,i);return r&&(this._pushUndoCommand(s),this._createLineCommand=null),r}finishLineTool(e){this._model().finishLineTool(e)}pasteImageAsLineTool(e,t,i,s){return null}loadRange(e){this._pushUndoCommand(new fe(this._model(),e))}unlinkLines(e){const t=this.model();this.beginUndoMacro(ci,this._lineToolsDoNotAffectChartInvalidation.value());for(const i of e)null!==i.linkKey().value()&&(0,Me.removeLineTool)({withUndo:!0,model:this.model(),symbol:i.symbol(),linkKey:(0,o.ensureNotNull)(i.linkKey().value()),sourceTitle:Oi(i),lineToolState:i.state(!1),unlink:!0}),this._pushUndoCommand(new Ct(t,i));this.endUndoMacro()}zoomFromViewport(){const e=new bt((0,o.ensureDefined)(this._zoomStack.head()),this._zoomStack,!1);this._pushUndoCommand(e)}zoomToViewport(e,t,i,s,r){const n=new vt(this.m_model,e,t,i,s,r),o=new bt(n,this._zoomStack,!0);this._pushUndoCommand(o)}zoomStack(){return this._zoomStack}hoveredSource(){return this.m_model.hoveredSource()}setProperty(e,t,i,s){if(e&&e.value()!==t){const r=new xe(e,t,i,this.m_model,s);this._pushUndoCommand(r),this.emitEvent("setProperty")}}withMacro(e,t,i){const s=this.beginUndoMacro(e,i);try{t()}finally{this.endUndoMacro()}return s}barsMarksSources(){return this.m_model.barsMarksSources()}barMarksSourceForId(e){return this.m_model.barMarksSourceForId(e)}removeAllDrawingTools(){this.beginUndoMacro(Bi,!0),this._removeAllDrawingToolsImpl(),this.endUndoMacro()}removeAllStudiesAndDrawingTools(){this.beginUndoMacro(Ni),this._removeAllDrawingToolsImpl(),this._removeAllStudiesImpl(),this.endUndoMacro()}removeAllStudies(){this.beginUndoMacro(Vi),this._removeAllStudiesImpl(),this.endUndoMacro()}canZoomIn(){return this.model().canZoomIn()}canZoomOut(){return this.model().canZoomOut()}zoomOut(){const e=this.timeScale().width();if(this.canZoomOut()){try{this.beginUndoMacro(hi)}catch(e){return}(0,ve.doAnimate)({to:e/5,onStep:e=>{this.startScaleTime(0),this.scaleTimeTo(e),this.endScaleTime()},onComplete:()=>this.endUndoMacro()})}}zoomIn(){const e=this.timeScale().width();if(this.canZoomIn()){try{this.beginUndoMacro(di)}catch(e){return}(0,ve.doAnimate)({to:e/5,onStep:e=>{this.startScaleTime(e),this.scaleTimeTo(0),this.endScaleTime()},onComplete:()=>this.endUndoMacro()})}}startMovingSources(e,t,i,s){e.filter(e=>e.doesMovingAffectsUndo()).length&&(this._currentSourceMoveCommand=new I(this.model(),e,ui,!1),e.every(b.isLineTool)&&this._currentSourceMoveCommand.setCustomFlag("doesnt_affect_save",this._lineToolsDoNotAffectChartInvalidation.value())),this.model().startMovingSources(e,t,i,new Map,s)}moveSources(e,t){this.model().moveSources(e,new Map,t)}endMovingSource(e,t){this.model().endMovingSources(e,void 0,t),null!==this._currentSourceMoveCommand&&(this._currentSourceMoveCommand.saveNewState(),this._pushUndoCommand(this._currentSourceMoveCommand)),this._currentSourceMoveCommand=null}startChangingLinetool(e,t,i,s,r){this._currentLineChangeCommand=new I(this.model(),[e],Ei.format({pointIndex:i}),!1),
|
||||
this._currentLineChangeCommand.setCustomFlag("doesnt_affect_save",this._lineToolsDoNotAffectChartInvalidation.value()),this.model().startChangingLinetool(e,t,i,s,r)}changeLinePoint(e,t){this.model().changeLinePoint(e,t)}endChangingLinetool(e){this.model().endChangingLinetool(e),null!==this._currentLineChangeCommand&&(this._currentLineChangeCommand.saveNewState(),this._pushUndoCommand(this._currentLineChangeCommand)),this._currentLineChangeCommand=null}setChartStyleProperty(e,t,i){if(e.value()!==t){const s=new pe(e,t,this.mainSeries(),i,this.model(),this.chartWidget());this._pushUndoCommand(s),this.emitEvent("setChartStyleProperty"),(0,ae.trackChartStyleChanged)(e.value())}}restorePropertiesForSource(e){(0,b.isLineTool)(e)?this._restoreLineToolFactoryDefaults(e):this._restoreStudyFactoryDefaults(e)}restoreState(e,t,i){return this.m_model.restoreState(e,t,i)}async clipboardCopy(e,t=this.selection().dataSources()){if(!(0,gt.enabled)("datasource_copypaste"))return;const i=t.filter(e=>e.copiable());if(0===i.length)return;for(const e of i)if((0,x.isStudy)(e)&&e.isChildStudy())throw new Error("Can not copy child study");const s=(0,V.clipboardDataForSources)(this._model().id(),i);return null!==s?e.write({app:JSON.stringify(s),text:s.title}):void 0}async clipboardCut(e,t=this.selection().dataSources()){if(!(0,gt.enabled)("datasource_copypaste"))return;const i=t.filter(e=>e.copiable());if(0===i.length)return;await this.clipboardCopy(e,i);const s=i.filter(e=>e.isUserDeletable());if(0===s.length)return;const r=(1===s.length?ri:ni).format({title:Oi(s[0])});this.beginUndoMacro(r),this.m_model.selectionMacro(()=>{this.removeSources(s,!1,r)}),this.endUndoMacro()}async clipboardPaste(e,t){let i=null;if((0,gt.enabled)("datasource_copypaste")&&(i=i||await e.read(),i.app)){const e=JSON.parse(i.app);if(null!==this.pasteSourceFromClip(t,e))return}await this._processSpecialLineToolsContents(e,i,t)}applyStudyTemplate(e,t){const i=new je(this._model(),e,t);this._pushUndoCommand(i)}startCustomMoving(e,t,i){this._currentCustomMoveCommand=new ct(this.model(),e,t,i)}customMoveBeingProcessed(){return null!==this._currentCustomMoveCommand}processCustomMove(e){(0,o.ensureNotNull)(this._currentCustomMoveCommand).move(e)}endCustomMoving(){null!==this._currentCustomMoveCommand&&this._currentCustomMoveCommand.hasChanges()&&(this._pushUndoCommand(this._currentCustomMoveCommand),this._currentCustomMoveCommand=null)}cloneLineTools(e,t){for(let t=0;t<Math.min(5,e.length);++t)(0,ae.trackDrawingCloned)(e[t]);this.beginUndoMacro(gi,this._lineToolsDoNotAffectChartInvalidation.value());const i=new w(this._model(),e,t,gi);if(this._pushUndoCommand(i),(0,Me.drawOnAllCharts)().value()){const e=i.newIds().map(e=>(0,o.ensureNotNull)(this.model().dataSourceForId(e)));this.copyToOtherCharts(e)}return this.endUndoMacro(),this.emitEvent("cloneLineTools"),i.newIds()}removeSource(e,t,i){this.lineBeingCreated()!==e?this.removeSources([e],t,oi.format({title:Oi(e)}),i):this.cancelCreatingLine()}removeSelectedSources(){const e=this._model().selection().dataSources()
|
||||
;if(!e.length)return;const t=(e.length>1?ai:oi).format({title:Oi(e[0])});this.removeSources(e,!1,t)}removeSources(e,t,i,s){s||(e=e.filter(e=>e.isUserDeletable()));const r=this._model(),n=r.lineToolsGroupModel(),a=e.every(b.isLineTool)&&this._lineToolsDoNotAffectChartInvalidation.value();this.beginUndoMacro(i,a),r.selectionMacro(s=>{const a=new Map;e.forEach(e=>{if((0,b.isLineTool)(e)){const t=n.groupForLineTool(e);if(null!==t){const i=a.get(t)||[];i.push(e),a.set(t,i)}null!==e.linkKey().value()&&(0,Me.removeLineTool)({withUndo:!0,model:this.model(),linkKey:(0,o.ensureNotNull)(e.linkKey().value()),symbol:this.model().mainSeries().symbol(),lineToolState:e.state(!1),sourceTitle:Oi(e)})}}),a.forEach((e,t)=>{const i=new P.ExcludeLineToolsFromGroupUndoCommand(r,t,e);this._pushUndoCommand(i)});const l=new C.RemoveSourcesCommand(r,e,i),c=l.removedIds();this._pushUndoCommand(l),!t&&c.length>0&&(1===c.length?this.emitEvent("removeSource",[c[0]]):this.emitEvent("removeSources",[c]))}),this.endUndoMacro()}removeUnloadedLineTool({lineToolsSynchronizer:e,sourceTitle:t,linkKey:i,symbol:s,state:r,withUndo:n,unlink:o}){}async scrollToLineTool(e){const t=this.timeScale().logicalRange();if(null===t)return;const i=this.timeScale().barSpacing();let s=t.left();const r=e.points().map(e=>e.index);let n=this.timeScale().points().firstIndex();const a=this.timeScale().points().lastIndex();if(null===n||null===a)return;const l=t.length()/2;if(0===r.length||r.some(e=>t.contains(e)))return;const c=()=>{const t=e.points().map(e=>e.index),i=t.filter(e=>e<=a).reduce((e,t)=>null===e?t:Math.max(e,t),null);return null!==i?i:t.reduce((e,t)=>Math.min(e,t))};let d,u=c();if(n-l>u){const t=e.points().map(e=>e.time).filter(T.notUndefined).map(e=>e.valueOf()/1e3);if(0===t.length)return;const i=t.reduce((e,t)=>Math.min(e,t),t[0]);await this.model().gotoTime(i),u=c();s=(0,o.ensureNotNull)(this.timeScale().logicalRange()).left(),n=(0,o.ensureNotNull)(this.timeScale().points().firstIndex())}n-l>u?(d=(s-n+l)*i,this.mainSeries().setGotoDateResult({timestamp:(0,o.ensureNotNull)(this.timeScale().points().valueAt(n)),eod:!0})):d=(s-u+1+l)*i,this.startScrollTime(0),(0,ve.doAnimate)({onStep:(e,t)=>this.scrollTimeTo(t),from:0,to:Math.round(d),easing:h.easingFunc.easeInOutCubic,duration:h.dur,onComplete:()=>this.endScrollTime()})}mergeSourceUp(e){const t=new L.MergeUpUndoCommand(this._model(),e,fi);this._mergeUnmergeSource(e,t)}mergeSourceDown(e){const t=new L.MergeDownUndoCommand(this._model(),e,vi);this._mergeUnmergeSource(e,t)}mergeToPane(e,t){const i=this._model().panes().indexOf(t),s=new L.MergeToTargetPane(this._model(),e,i,Si);this._mergeUnmergeSource(e,s)}unmergeSourceUp(e){const t=new M.UnmergeUpUndoCommand(this._model(),e,yi);this._mergeUnmergeSource(e,t)}unmergeSourceDown(e){const t=new M.UnmergeDownUndoCommand(this._model(),e,bi);this._mergeUnmergeSource(e,t)}unmergeToNewBottomPane(e){const t=new M.UnmergeToNewBottomPane(this._model(),e,wi);this._mergeUnmergeSource(e,t)}availableZOrderOperations(e){
|
||||
const t=this._model().lineToolsGroupModel(),i=e.filter(b.isLineTool),s=i.map(e=>t.groupForLineTool(e));(0,o.assert)(new Set(s).size<=1,"Cannot move line tools from different group");const r=0===s.length?null:s[0];let n={bringForwardEnabled:!1,bringToFrontEnabled:!1,sendBackwardEnabled:!1,sendToBackEnabled:!1};const a=new Set(i);for(const t of(0,A.sortSources)(e)){if((0,b.isLineTool)(t)&&null!==r){const e=(0,A.sortSources)(r.lineTools().filter(e=>!a.has(e)||e===t));n=Ri(n,{bringForwardEnabled:t!==e[e.length-1],bringToFrontEnabled:t!==e[e.length-1],sendBackwardEnabled:t!==e[0],sendToBackEnabled:t!==e[0]});continue}const e=(0,o.ensureNotNull)(this._model().paneForSource(t)).sourcesByGroup().allExceptSpecialSources();if(0===e.length)continue;const i=t.zorder(),s=e[0].zorder(),l=e[e.length-1].zorder();n=Ri(n,{bringForwardEnabled:i!==l,bringToFrontEnabled:i!==l,sendBackwardEnabled:i!==s,sendToBackEnabled:i!==s})}return n}sendToBack(e){if(!this.availableZOrderOperations(e).sendToBackEnabled)throw new Error("Send to back operation is unavailable");let t=null;const i=e[0];if((0,b.isLineTool)(i)){const s=this._model().lineToolsGroupModel().groupForLineTool(i);if(null!==s){const i=s.lineTools();t=new X(this.model(),(0,A.sortSources)(e),i[0])}}null===t&&(t=new q(this.model(),(0,A.sortSources)(e))),this._pushUndoCommand(t),this.emitEvent("changeZOrder",[e])}bringToFront(e){if(!this.availableZOrderOperations(e).bringToFrontEnabled)throw new Error("Bring to front operation is unavailable");let t=null;const i=e[0];if((0,b.isLineTool)(i)){const s=this._model().lineToolsGroupModel().groupForLineTool(i);if(null!==s){const i=s.lineTools();t=new K(this.model(),(0,A.sortSources)(e),i[i.length-1])}}null===t&&(t=new G(this.model(),(0,A.sortSources)(e))),this._pushUndoCommand(t),this.emitEvent("changeZOrder",[e])}sendBackward(e){if(!this.availableZOrderOperations(e).sendBackwardEnabled)throw new Error("Send backward operation is unavailable");const t=ei.format({title:Oi(e[0])});this._sendBackOrBringForward(t,(0,A.sortSources)(e),(e,t)=>new J(this.model(),e,t))}bringForward(e){if(!this.availableZOrderOperations(e).bringForwardEnabled)throw new Error("Bring forward operation is unavailable");const t=ti.format({title:Oi(e[0])});this._sendBackOrBringForward(t,(0,A.sortSources)(e),(e,t)=>new ee(this.model(),e,t))}insertAfter(e,t){e=(0,A.sortSources)(e);const i=ii.format({title:Oi(e[0]),target:Oi(t)});this._insertAfterOrBefore(i,e,t,()=>new K(this.model(),e,t))}insertBefore(e,t){e=(0,A.sortSources)(e);const i=si.format({title:Oi(e[0]),target:Oi(t)});this._insertAfterOrBefore(i,e,t,()=>new X(this.model(),e,t))}detachToRight(e,t){(0,tt.trackEvent)("Chart","Move to new right scale");const i=Ci.format({title:Oi(e)}),s=new Je.MoveToNewPriceScaleUndoCommand(this.model(),e,t,"right",i);this._pushUndoCommand(s),this.emitEvent("moveSource",[e])}detachToLeft(e,t){(0,tt.trackEvent)("Chart","Move to new left scale");const i=Pi.format({title:Oi(e)}),s=new Je.MoveToNewPriceScaleUndoCommand(this.model(),e,t,"left",i);this._pushUndoCommand(s),
|
||||
this.emitEvent("moveSource",[e])}detachNoScale(e,t){(0,tt.trackEvent)("Chart","Make source no scale");const i=Ti.format({title:Oi(e)}),s=new Je.MoveToNewPriceScaleUndoCommand(this.model(),e,t,"overlay",i);this._pushUndoCommand(s),this.emitEvent("moveSource",[e])}moveToScale(e,t,i,s,r){(0,tt.trackEvent)("Chart","Move source to target scale"),this.beginUndoMacro(s);const n=new Je.MoveToExistingPriceScaleUndoCommand(this.model(),e,t,i,s),o=r?null:(0,it.sourceNewCurrencyOnPinningToPriceScale)(e,i,this._model()),a=r?null:(0,_t.sourceNewUnitOnPinningToPriceScale)(e,i,this._model());this._pushUndoCommand(n),null!==o&&this.setPriceScaleCurrency(i,o),null!==a&&this.setPriceScaleUnit(i,a),this.endUndoMacro(),this.emitEvent("moveSource",[e])}startScrollTime(e){const t=this.timeScale();this._initialTimeScrollState={rightOffset:t.rightOffset(),barSpacing:t.barSpacing()},this._initialTimeScrollPos=e,this.model().startScrollTime(e)}scrollTimeTo(e){let t=!1;return null!==this._initialTimeScrollPos&&null!==this._initialTimeScrollState&&Math.abs(e-this._initialTimeScrollPos)>20&&(this._pushUndoCommand(new oe.TimeScaleChangeUndoCommand(this.model(),this._initialTimeScrollState,xi)),this._initialTimeScrollPos=null,this._initialTimeScrollState=null,t=!0),this.model().scrollTimeTo(e),t}endScrollTime(){this.model().endScrollTime(),this._initialTimeScrollPos=null,this._initialTimeScrollState=null}startScaleTime(e){const t=this.timeScale(),i={rightOffset:t.rightOffset(),barSpacing:t.barSpacing()};this._pushUndoCommand(new oe.TimeScaleChangeUndoCommand(this.model(),i,Ii)),this.model().startScaleTime(e)}scaleTimeTo(e){this.model().scaleTimeTo(e)}endScaleTime(){this.model().endScaleTime()}resetTimeScale(){const e=this.timeScale(),t={rightOffset:e.rightOffset(),barSpacing:e.barSpacing()};this._pushUndoCommand(new oe.TimeScaleChangeUndoCommand(this.model(),t,Mi)),this.model().resetTimeScale()}startScalePrice(e,t,i,s){this._scalePriceInfo={priceScaleState:t.state(),tryMergeConsecutiveScales:s},this.model().startScalePrice(e,t,i)}scalePriceTo(e,t,i){this.model().scalePriceTo(e,t,i)}endScalePrice(e,t){this.model().endScalePrice(e,t);const i=(0,o.ensureNotNull)(this._scalePriceInfo);(0,n.default)(i.priceScaleState,t.state())||this._pushUndoCommand(new mt.PriceScaleChangeUndoCommand(this.model(),e,t,i.priceScaleState,i.tryMergeConsecutiveScales)),this._scalePriceInfo=null}startTwoPointsScalePrice(e,t,i,s,r){this._scalePriceInfo={priceScaleState:t.state(),tryMergeConsecutiveScales:r},this.model().startTwoPointsScalePrice(e,t,i,s)}twoPointsScalePriceTo(e,t,i,s){this.model().twoPointsScalePriceTo(e,t,i,s)}endTwoPointsScalePrice(e,t){this.model().endTwoPointsScalePrice(e,t);const i=(0,o.ensureNotNull)(this._scalePriceInfo);(0,n.default)(i.priceScaleState,t.state())||this._pushUndoCommand(new mt.PriceScaleChangeUndoCommand(this.model(),e,t,i.priceScaleState,i.tryMergeConsecutiveScales)),this._scalePriceInfo=null}resetPriceScale(e,t){const i=t.state();this.model().resetPriceScale(e,t),(0,
|
||||
n.default)(i,t.state())||this._pushUndoCommand(new mt.PriceScaleChangeUndoCommand(this.m_model,e,t,i))}rearrangePanes(e,t){const i=new ne(this._model(),e,t);this._pushUndoCommand(i)}movePane(e,t){const i=new ne(this._model(),e,t);this._pushUndoCommand(i)}pasteSourceFromClip(e,t,i){const s=t;if(!s||0===s.sources.length)return null;const r=e||(0,o.ensureNotNull)(this.model().paneForSource(this.mainSeries()));if(!s.sources.some(e=>"drawing"!==e.type||null!==r.clipboardLineToolOwnerSource(e.source.id)))return null;this.beginUndoMacro(ki.format({title:s.title}));let n=0;const a=[],l=[];for(const t of s.sources)if("drawing"===t.type&&null!==r.clipboardLineToolOwnerSource(t.source.id)){const e=this.pasteLineTool(r,t);n<5&&((0,ae.trackDrawingPasted)(e),n+=1),l.push(e),a.push(e)}else"study"===t.type&&t.source&&t.source.metaInfo&&this.checkIfFeatureAvailable(new(p())(t.source.metaInfo))&&a.push(this.pasteStudy(t,i?e:void 0));return l.length&&this.selectionMacro(e=>{e.clearSelection(),l.forEach(t=>{e.addSourceToSelection(t,null)})}),this.endUndoMacro(),a}pasteLineTool(e,t,i,s){t.source.state.intervalsVisibilities=(0,Lt.mergeIntervalVisibilitiesDefaults)(t.source.state.intervalsVisibilities),(0,Lt.makeIntervalsVisibilitiesVisibleAtInterval)(t.source.state.intervalsVisibilities,me.Interval.parse(this.model().mainSeries().interval()));const r=new $e(this.model(),t,e,i,s);this._pushUndoCommand(r);const n=r.source();return r.needCopyToOtherCharts()&&this.copyToOtherCharts([n]),this.selectionMacro(e=>{e.clearSelection(),e.addSourceToSelection(n,null)}),n}pasteStudy(e,t){const i=new nt(this.model(),e,null==t?void 0:t.id());this._pushUndoCommand(i);const s=(0,o.ensureNotNull)(i.state()).id;return(0,o.ensureNotNull)(this._model().dataSourceForId(s))}setPriceScaleCurrency(e,t){const i=new Xe.SetPriceScaleCurrencyUndoCommand(e,t,this.chartWidget(),_i);this._pushUndoCommand(i)}setPriceScaleUnit(e,t){const i=new Ze.SetPriceScaleUnitUndoCommand(e,t,this.chartWidget(),mi);this._pushUndoCommand(i)}setSymbol(e,t){e.symbol()!==t&&this._pushUndoCommand(new et(e,t,this.chartWidget()))}setResolution(e,t){me.Interval.isEqual(e.interval(),t)||this._pushUndoCommand(new Qt(e,t,this.chartWidget()))}chartLoadTheme(e,t,i){const s=new Zt(this.model(),e,t);i?s.redo():this._pushUndoCommand(s)}isJustClonedChart(){return this._chartWidget.isJustClonedChart()}copyToOtherCharts(e){const t=this.mainSeries(),i=t.syncModel(),s=this.timeScale();if(i)for(const r of e){if(!r.isSynchronizable())continue;const e=r.linkKey().value()||(0,Ge.randomHash)();r.linkKey().setValue(e);const n=r.state(!1),a=r.normalizedPoints(),l=r.properties().interval.value(),c=t.interval();let h;if(me.Interval.isEqual(l,c))h=a.map(e=>{const t=(0,o.ensureNotNull)(s.timePointToIndex(e.time_t))+e.offset;return{price:e.price,timeStamp:(0,o.ensureNotNull)(this.model().externalTimeStamp(t))}});else{const e=i.createNewModelWithResolution(l);h=a.map(t=>({price:t.price,timeStamp:0===t.offset?t.time_t:e.projectTime(t.time_t,t.offset)}))}const d={...n,id:r.id(),linkKey:e,points:h,linetool:r.toolname,
|
||||
model:this.model(),symbol:t.symbol(),finalState:{points:a,interval:l},pointPositionPercents:r.isFixed()?r.calcPositionPercents():void 0,sharingMode:r.sharingMode().value()};(0,Me.copyLineTool)(d)}}addPaneStretchFactorUndoCommand(e,t,i,s){const r=new ot(this.model(),e,t,i,s);this._pushUndoCommand(r)}paneForSource(e){return this.m_model.paneForSource(e)}destroy(){this._lineToolsDoNotAffectChartInvalidation.destroy(),this.m_model.destroy()}moveSelectedToolsLeft(){return this._moveSelectedTools(2)}moveSelectedToolsUp(){return this._moveSelectedTools(0)}moveSelectedToolsRight(){return this._moveSelectedTools(3)}moveSelectedToolsDown(){return this._moveSelectedTools(1)}insertStudyWithoutCheck(e,t){return this._insertStudy(e,t,{},!1,void 0,void 0,void 0,void 0,void 0,null,void 0)}saveLineToolState(e,t){this._pushUndoCommand(new I(this.m_model,[e],t))}resetScales(){this.beginUndoMacro(Li),this.resetTimeScale();for(const e of this.m_model.panes()){for(const t of e.leftPriceScales())this.resetPriceScale(e,t);for(const t of e.rightPriceScales())this.resetPriceScale(e,t)}this.endUndoMacro(),this.m_model.recalculateAllPanes((0,ue.viewportChangeEvent)())}shareLineTools(e,t){}_mergeUnmergeSource(e,t){this.beginUndoMacro(t.text());const i=(0,o.ensureNotNull)(this._model().paneForSource(e)),s=new Set(i.sourcesByGroup().lineSources().filter(t=>t.ownerSource()===e));this._model().lineToolsGroupModel().groups().filter(e=>{const t=e.lineTools().some(e=>s.has(e)),i=e.lineTools().some(e=>!s.has(e));return t&&i}).forEach(e=>{this._pushUndoCommand(new P.ExcludeLineToolsFromGroupUndoCommand(this._model(),e,e.lineTools()))}),this._pushUndoCommand(t),this.endUndoMacro()}_insertStudy(e,t,i,s,r,n,a,l,c,h,d){const u=Di.format({title:e.description});this.beginUndoMacro(u);const p=new ht(this.model(),e,t,i,s,r,n,a,l,c,h||null,u);this._pushUndoCommand(p);const _=p.insertedStudy();if(void 0!==d){const e=new dt.SetPriceScaleModeCommand(d,(0,o.ensureNotNull)(_.priceScale()),null,this.model());this._pushUndoCommand(e)}return this.endUndoMacro(),_}async _processSpecialLineToolsContents(e,t,i){0}_insertAfterOrBefore(e,t,i,s){const r=(0,o.ensureNotNull)(this._model().paneForSource(i));if(t.some(e=>(0,b.isLineTool)(e)&&this._model().paneForSource(e)!==r))throw new Error("Cannot insert line tool after target on another pane");this.beginUndoMacro(e),t.forEach(e=>{(0,o.ensureNotNull)(this.model().paneForSource(e))!==r&&this.mergeToPane(e,r)});const n=s();this._pushUndoCommand(n),this.emitEvent("changeZOrder",[t]),this.endUndoMacro()}_sendBackOrBringForward(e,t,i){const s=new Map;t.forEach(e=>{const t=(0,o.ensureNotNull)(this._model().paneForSource(e)),i=s.get(t)||[];i.push(e),s.set(t,i)}),this.beginUndoMacro(e),s.forEach((e,t)=>{this._pushUndoCommand(i(t,e))}),this.endUndoMacro(),this.emitEvent("changeZOrder",[t])}_moveSelectedTools(e){const t=this.model().selection().lineDataSources();if(0===t.length)return!1;if((0,Me.lockDrawings)().value())return!0;const i=this.timeScale().visibleBarsStrictRange();if(null===i)return!1;const s=function(e){const t=new Map
|
||||
;for(const i of e){const e=i.ownerSource();if(null===e)continue;let s=t.get(e);if(void 0===s){const r=e.priceScale(),n=e.priceStep(),o=e.firstValue();if(null===r||null===n||null===o)continue;if(null===r.priceRange())continue;s={sources:[],priceScale:r,priceStep:n,startPrice:i.points()[0].price,firstValue:o},t.set(e,s)}s.sources.push(i)}return t}(t);if(0===s.size)return!1;this.beginUndoMacro(ui,this._lineToolsDoNotAffectChartInvalidation.value());const r=i.firstBar(),n=this.timeScale().indexToCoordinate(r),o=r+(3===e?1:2===e?-1:0),l=this.timeScale().indexToCoordinate(o);return Me.isDirectionalMovementActive.setValue(!0),s.forEach(t=>{const{startPrice:i,priceStep:s,priceScale:c,firstValue:h}=t,d=i+(0===e?s:1===e?-s:0),u=c.priceToCoordinate(i,h),p=c.priceToCoordinate(d,h),_={logical:{index:r,price:i},screen:new a.Point(n,u)},m={logical:{index:o,price:d},screen:new a.Point(l,p)};this.startMovingSources(t.sources,_,null),this.moveSources(m),this.endMovingSource(!1,!0)}),Me.isDirectionalMovementActive.setValue(!1),this.endUndoMacro(),!0}_restoreStudyFactoryDefaults(e){const t=new Mt(this.m_model,e.properties());this._pushUndoCommand(t)}_restoreLineToolFactoryDefaults(e){this.beginUndoMacro(pi,this._lineToolsDoNotAffectChartInvalidation.value()),this.saveLineToolState(e,pi);const t=new It(this.m_model,e.properties(),pi);this._pushUndoCommand(t),this.saveLineToolState(e,pi),this.endUndoMacro(),this.model().updateSource(e)}_removeAllDrawingToolsImpl(e){this.selectionMacro(()=>{this.lineBeingCreated()&&this.cancelCreatingLine();this.dataSources().filter(b.isLineTool).filter(e=>e.isActualSymbol()&&e.isUserDeletable()).filter(t=>!e||e===t.toolname).forEach(e=>this.removeSource(e,!1))})}_removeAllStudiesImpl(){const e=this.dataSources(),t=e.filter(x.isStudy).filter(e=>!e.isChildStudy()&&e.removeByRemoveAllStudies()),i=e.filter(x.isStudyStub);t.concat(i).forEach(e=>this.removeSource(e,!1))}}},88735:(e,t,i)=>{"use strict";var s=i(2872),r=i(88537).ensureNotNull,n=i(56840),o=i(88537).assert,a=i(36244).ChartModelBase,l=i(14291),c=l.isLineTool,h=l.isStudyLineTool,d=i(39094).Watermark,u=i(49483).CheckMobile,p=i(23653).InvalidationMask,_=i(23653).InvalidationLevel;const{globalChangeEvent:m,dataSourceChangeEvent:g}=i(33291);var f=i(66101),v=f.Study,S=i(13672).NonSeriesStudy,y=i(81851),b=y.createStudy,w=y.isStudy,C=y.isFundamentalStudy,P=f.prepareStudyProperties,T=i(85733),x=i(88564).saveDefaultProperties,I=i(32050).MainSeriesScaleRatioProperty,M=i(22423).scaleRatio,L=i(90998).StudyInserter,A=i(21761).dateFormatProperty,E=i(79680).isActingAsSymbolSource,k=i(13795).sourceNewCurrencyOnPinningToPriceScale,D=i(79222).sourceNewUnitOnPinningToPriceScale,V=i(76422),B=i(56606).StudyColorRotatorFactory,N=i(67337),R=i(44419).AppliedTimeFrame,O=N.enabled("auto_enable_symbol_labels");N.enabled("fix_left_edge");class F extends a{constructor(e,t,i,r,n,o,a,l,c,h){super(e,t,i,r,n,o,a,l,c,h);var u=this,p=this.m_mainSeries.properties(),_=this._panes[0];_.setStretchFactor(2*_.stretchFactor()),
|
||||
this._merge(this._newChartProps,this._newSeriesProps,this._newSessionProps),this._model.mainSeries().onChartStyleChanged(),this._model.updateScales(),this._model.chartThemeLoaded()}_merge(e,t,i){var s,r,n,o;const a=this._model;(0,le.saveDefaultProperties)(!0),e&&(a.properties().childs().paneProperties.mergeAndFire(e.paneProperties),a.properties().childs().scalesProperties.mergeAndFire(e.scalesProperties)),"priceAxisProperties"in t&&a.mainSeries().priceScale().setMode({autoScale:null===(s=t.priceAxisProperties)||void 0===s?void 0:s.autoScale,percentage:null===(r=t.priceAxisProperties)||void 0===r?void 0:r.percentage,log:null===(n=t.priceAxisProperties)||void 0===n?void 0:n.log,lockScale:null===(o=t.priceAxisProperties)||void 0===o?void 0:o.lockScale}),a.mainSeries().properties().mergeAndFire(t),a.mainSeries().properties().saveDefaults(),a.mainSeries().createPaneView(),a.mainSeries().invalidateBarStylesCache(),a.recalculateAllPanes((0,ue.globalChangeEvent)()),a.fullUpdate(),a.properties().saveDefaults(),a.sessions().restoreState({properties:i},!1),(0,le.saveDefaultProperties)(!1)}}const Jt=new c.TranslatedString("change resolution",(0,l.t)("change resolution"));class Qt extends S.UndoCommand{constructor(e,t,i){let s;super(Jt),this._sourceId=e.id();const r=(0,ce.isRangeStyle)(e.style()),n=me.Interval.isRange(t);!r&&n?s=11:r&&!n&&(s=(0,ce.getLastUsedStyle)()),this._newSymbolParams={interval:t,style:s},this._prevSymbolParams={symbol:e.symbol(),currency:e.currency(),unit:e.unit(),interval:e.interval(),style:e.style()},this._chartWidget=i}redo(){this._chartWidget.screen.show();this._symbolSource().setSymbolParams(this._newSymbolParams)}undo(){this._chartWidget.screen.show();this._symbolSource().setSymbolParams(this._prevSymbolParams)}_symbolSource(){return(0,o.ensureNotNull)(this._chartWidget.model().model().dataSourceForId(this._sourceId))}}var ei=i(76422);const ti=new c.TranslatedString("send {title} backward",(0,l.t)("send {title} backward")),ii=new c.TranslatedString("bring {title} forward",(0,l.t)("bring {title} forward")),si=new c.TranslatedString("insert {title} after {target}",(0,l.t)("insert {title} after {target}")),ri=new c.TranslatedString("insert {title} before {target}",(0,l.t)("insert {title} before {target}")),ni=new c.TranslatedString("cut {title}",(0,l.t)("cut {title}")),oi=new c.TranslatedString("cut sources",(0,l.t)("cut sources")),ai=new c.TranslatedString("remove {title}",(0,l.t)("remove {title}")),li=new c.TranslatedString("remove drawings group",(0,l.t)("remove drawings group")),ci=new c.TranslatedString("move scale",(0,l.t)("move scale")),hi=new c.TranslatedString("stop syncing line tool(s)",(0,l.t)("stop syncing line tool(s)")),di=new c.TranslatedString("zoom out",(0,l.t)("zoom out")),ui=new c.TranslatedString("zoom in",(0,l.t)("zoom in")),pi=new c.TranslatedString("move drawing(s)",(0,l.t)("move drawing(s)")),_i=new c.TranslatedString("load default drawing template",(0,l.t)("load default drawing template")),mi=new c.TranslatedString("change currency",(0,
|
||||
l.t)("change currency")),gi=new c.TranslatedString("change unit",(0,l.t)("change unit")),fi=new c.TranslatedString("clone line tools",(0,l.t)("clone line tools")),vi=new c.TranslatedString("merge up",(0,l.t)("merge up")),Si=new c.TranslatedString("merge down",(0,l.t)("merge down")),yi=new c.TranslatedString("merge to pane",(0,l.t)("merge to pane")),bi=new c.TranslatedString("unmerge up",(0,l.t)("unmerge up")),wi=new c.TranslatedString("unmerge down",(0,l.t)("unmerge down")),Ci=new c.TranslatedString("unmerge to new bottom pane",(0,l.t)("unmerge to new bottom pane")),Pi=new c.TranslatedString("move {title} to new right scale",(0,l.t)("move {title} to new right scale")),Ti=new c.TranslatedString("move {title} to new left scale",(0,l.t)("move {title} to new left scale")),xi=new c.TranslatedString("make {title} no scale (Full screen)",(0,l.t)("make {title} no scale (Full screen)")),Ii=new c.TranslatedString("scroll time",(0,l.t)("scroll time")),Mi=new c.TranslatedString("scale time",(0,l.t)("scale time")),Li=new c.TranslatedString("reset time scale",(0,l.t)("reset time scale")),Ai=new c.TranslatedString("reset scales",(0,l.t)("reset scales")),Ei=new c.TranslatedString("create {tool}",(0,l.t)("create {tool}")),ki=new c.TranslatedString("change {pointIndex} point",(0,l.t)("change {pointIndex} point")),Di=new c.TranslatedString("paste {title}",(0,l.t)("paste {title}")),Vi=new c.TranslatedString("insert {title}",(0,l.t)("insert {title}")),Bi=new c.TranslatedString("remove all studies",(0,l.t)("remove all studies")),Ni=new c.TranslatedString("remove drawings",(0,l.t)("remove drawings")),Ri=new c.TranslatedString("remove all studies and drawing tools",(0,l.t)("remove all studies and drawing tools"));new c.TranslatedString("turn line tools sharing off",(0,l.t)("turn line tools sharing off")),new c.TranslatedString("share line tools in layout",(0,l.t)("share line tools in layout")),new c.TranslatedString("share line tools globally",(0,l.t)("share line tools globally"));function Oi(e,t){return{bringForwardEnabled:e.bringForwardEnabled||t.bringForwardEnabled,bringToFrontEnabled:e.bringToFrontEnabled||t.bringToFrontEnabled,sendBackwardEnabled:e.sendBackwardEnabled||t.sendBackwardEnabled,sendToBackEnabled:e.sendToBackEnabled||t.sendToBackEnabled}}function Fi(e){return new c.TranslatedString(e.name(),e.title())}function Wi(){return(0,Me.drawOnAllCharts)().value()?1:0}class Hi extends(r()){constructor(e,t,i,s,r,n,o,a,l,c,h){super(),this._createLineCommand=null,this._initialTimeScrollState=null,this._initialTimeScrollPos=null,this._scalePriceInfo=null,this._currentSourceMoveCommand=null,this._currentLineChangeCommand=null,this._currentCustomMoveCommand=null,this._zoomStack=new v.UndoStack,this._lineToolsDoNotAffectChartInvalidation=new Te.FeatureToggleWatchedValue("do_not_invalidate_chart_on_changing_line_tools",!1),this._chartWidget=n,this.m_model=new(pt())(e,t,i,s,r,this,a,l,c,h),this._undoHistory=o,this._lineToolsGroupController=new Re({model:this._model.bind(this),pushUndoCommand:this._pushUndoCommand.bind(this),
|
||||
beginUndoMacro:(e,t)=>{this._undoHistory.beginUndoMacro(e).setCustomFlag("doesnt_affect_save",!!t)},endUndoMacro:this._undoHistory.endUndoMacro.bind(this._undoHistory),emitEvent:this.emitEvent.bind(this)})}undoHistory(){return this._undoHistory}setWatchedValue(e,t,i){this._undoHistory.setWatchedValue(e,t,i)}lineToolsGroupController(){return this._lineToolsGroupController}mergeAllScales(e){!function(e,t){e.beginUndoMacro("left"===t?m:g),e.model().panes().forEach(i=>{const s="left"===t?i.rightPriceScales():i.leftPriceScales(),r=("left"===t?i.leftPriceScales():i.rightPriceScales()).concat(s),n="overlay"===i.priceScalePosition(i.defaultPriceScale())?r[0]:i.defaultPriceScale();e.movePriceScale(i,n,t,0),r.forEach(t=>{if(t===n)return;let s=t.mainSource();for(;null!==s;){e.moveToScale(s,i,n,null,!0);const r=t.mainSource();if(r===s){f.logError("Loop detected while trying to merge scales");break}s=r}})}),e.endUndoMacro(),e.model().fullUpdate()}(this,e)}movePriceScale(e,t,i,s){const r=new y(this._model(),e,t,i,s,ci);this._pushUndoCommand(r)}createLineTool({pane:e,point:t,linetool:i,properties:s,linkKey:r,ownerSource:n,disableSynchronization:a,sharingMode:l=Wi(),id:h}){if(("LineToolRegressionTrend"===i||"LineToolAnchoredVWAP"===i)&&!this.canCreateStudy())return(0,d.showTooManyStudiesNotice)(),null;const u=Ei.format({tool:new c.TranslatedString(i,E.lineToolsLocalizedNames[i])});this.beginUndoMacro(u,this._lineToolsDoNotAffectChartInvalidation.value());const p=!a;this._createLineCommand=new D(this._model(),e,i,n||(0,o.ensureNotNull)(e.mainDataSource()),l,h);const _=this._createLineCommand.startCreatingLine(t,s,r||null),m=(0,o.ensureNotNull)(this._createLineCommand.line());let g=null;if(_&&(p&&this.finishLineTool(m),this._pushUndoCommand(this._createLineCommand),this._createLineCommand=null,g={points:m.normalizedPoints(),interval:this.mainSeries().interval()}),p&&void 0===r&&(0,Me.drawOnAllCharts)().value()&&m.isSynchronizable()){const e=(0,o.ensureNotNull)(this.model().externalTimeStamp(t.index)),s={point:{price:t.price,timeStamp:e},linetool:i,properties:m.properties(),symbol:this.mainSeries().symbol(),model:this.model(),linkKey:(0,o.ensureNotNull)(m.linkKey().value()),finalState:g,id:m.id()};m.isFixed()&&(s.pointPositionPercents=m.calcPositionPercents()[0]),(0,Me.createLineTool)(s)}return this.endUndoMacro(),m}continueCreatingLine(e,t,i,s){const r=(0,o.ensureNotNull)(this._createLineCommand);this.beginUndoMacro(r.text(),this._lineToolsDoNotAffectChartInvalidation.value());const n=(0,o.ensureNotNull)(this._model().lineBeingCreated()),a=r.continueCreatingLine(e,t,i,s);let l=null;if(a&&(this.finishLineTool(n),this._pushUndoCommand(r),this._createLineCommand=null,l={points:n.normalizedPoints(),interval:this.mainSeries().interval()}),r.drawOnAllCharts()&&n.isSynchronizable()){const i=(0,o.ensureNotNull)(this._model().externalTimeStamp(e.index));(0,Me.continueLineTool)({point:{price:e.price,timeStamp:i},envState:t,finalState:l,model:this._model()})}return this.endUndoMacro(),a}continueExternalLine(e,t,i){const s=(0,
|
||||
o.ensureNotNull)(this._createLineCommand),r=s.continueCreatingLine(e,t,i);return r&&(this._pushUndoCommand(s),this._createLineCommand=null),r}finishLineTool(e){this._model().finishLineTool(e)}pasteImageAsLineTool(e,t,i,s){return null}loadRange(e){this._pushUndoCommand(new fe(this._model(),e))}unlinkLines(e){const t=this.model();this.beginUndoMacro(hi,this._lineToolsDoNotAffectChartInvalidation.value());for(const i of e)null!==i.linkKey().value()&&(0,Me.removeLineTool)({withUndo:!0,model:this.model(),symbol:i.symbol(),linkKey:(0,o.ensureNotNull)(i.linkKey().value()),sourceTitle:Fi(i),lineToolState:i.state(!1),unlink:!0}),this._pushUndoCommand(new Ct(t,i));this.endUndoMacro()}zoomFromViewport(){const e=new bt((0,o.ensureDefined)(this._zoomStack.head()),this._zoomStack,!1);this._pushUndoCommand(e)}zoomToViewport(e,t,i,s,r){const n=new vt(this.m_model,e,t,i,s,r),o=new bt(n,this._zoomStack,!0);this._pushUndoCommand(o)}zoomStack(){return this._zoomStack}hoveredSource(){return this.m_model.hoveredSource()}setProperty(e,t,i,s){if(e&&e.value()!==t){const r=new xe(e,t,i,this.m_model,s);this._pushUndoCommand(r),this.emitEvent("setProperty")}}withMacro(e,t,i){const s=this.beginUndoMacro(e,i);try{t()}finally{this.endUndoMacro()}return s}barsMarksSources(){return this.m_model.barsMarksSources()}barMarksSourceForId(e){return this.m_model.barMarksSourceForId(e)}removeAllDrawingTools(){this.beginUndoMacro(Ni,!0),this._removeAllDrawingToolsImpl(),this.endUndoMacro()}removeAllStudiesAndDrawingTools(){this.beginUndoMacro(Ri),this._removeAllDrawingToolsImpl(),this._removeAllStudiesImpl(),this.endUndoMacro()}removeAllStudies(){this.beginUndoMacro(Bi),this._removeAllStudiesImpl(),this.endUndoMacro()}canZoomIn(){return this.model().canZoomIn()}canZoomOut(){return this.model().canZoomOut()}zoomOut(){const e=this.timeScale().width();if(this.canZoomOut()){try{this.beginUndoMacro(di)}catch(e){return}(0,ve.doAnimate)({to:e/5,onStep:e=>{this.startScaleTime(0),this.scaleTimeTo(e),this.endScaleTime()},onComplete:()=>this.endUndoMacro()})}}zoomIn(){const e=this.timeScale().width();if(this.canZoomIn()){try{this.beginUndoMacro(ui)}catch(e){return}(0,ve.doAnimate)({to:e/5,onStep:e=>{this.startScaleTime(e),this.scaleTimeTo(0),this.endScaleTime()},onComplete:()=>this.endUndoMacro()})}}startMovingSources(e,t,i,s){e.filter(e=>e.doesMovingAffectsUndo()).length&&(this._currentSourceMoveCommand=new I(this.model(),e,pi,!1),e.every(b.isLineTool)&&this._currentSourceMoveCommand.setCustomFlag("doesnt_affect_save",this._lineToolsDoNotAffectChartInvalidation.value())),this.model().startMovingSources(e,t,i,new Map,s)}moveSources(e,t){this.model().moveSources(e,new Map,t)}endMovingSource(e,t){this.model().endMovingSources(e,void 0,t),null!==this._currentSourceMoveCommand&&(this._currentSourceMoveCommand.saveNewState(),this._pushUndoCommand(this._currentSourceMoveCommand)),this._currentSourceMoveCommand=null}startChangingLinetool(e,t,i,s,r){this._currentLineChangeCommand=new I(this.model(),[e],ki.format({pointIndex:i}),!1),
|
||||
this._currentLineChangeCommand.setCustomFlag("doesnt_affect_save",this._lineToolsDoNotAffectChartInvalidation.value()),this.model().startChangingLinetool(e,t,i,s,r)}changeLinePoint(e,t){this.model().changeLinePoint(e,t)}endChangingLinetool(e){this.model().endChangingLinetool(e),null!==this._currentLineChangeCommand&&(this._currentLineChangeCommand.saveNewState(),this._pushUndoCommand(this._currentLineChangeCommand)),this._currentLineChangeCommand=null}setChartStyleProperty(e,t,i){if(e.value()!==t){const s=new pe(e,t,this.mainSeries(),i,this.model(),this.chartWidget());this._pushUndoCommand(s),this.emitEvent("setChartStyleProperty"),(0,ae.trackChartStyleChanged)(e.value())}}restorePropertiesForSource(e){(0,b.isLineTool)(e)?this._restoreLineToolFactoryDefaults(e):this._restoreStudyFactoryDefaults(e)}restoreState(e,t,i){return this.m_model.restoreState(e,t,i)}async clipboardCopy(e,t=this.selection().dataSources()){if(!(0,gt.enabled)("datasource_copypaste"))return;const i=t.filter(e=>e.copiable());if(0===i.length)return;for(const e of i)if((0,x.isStudy)(e)&&e.isChildStudy())throw new Error("Can not copy child study");const s=(0,V.clipboardDataForSources)(this._model().id(),i);return null!==s?e.write({app:JSON.stringify(s),text:s.title}):void 0}async clipboardCut(e,t=this.selection().dataSources()){if(!(0,gt.enabled)("datasource_copypaste"))return;const i=t.filter(e=>e.copiable());if(0===i.length)return;await this.clipboardCopy(e,i);const s=i.filter(e=>e.isUserDeletable());if(0===s.length)return;const r=(1===s.length?ni:oi).format({title:Fi(s[0])});this.beginUndoMacro(r),this.m_model.selectionMacro(()=>{this.removeSources(s,!1,r)}),this.endUndoMacro()}async clipboardPaste(e,t){let i=null;if((0,gt.enabled)("datasource_copypaste")&&(i=i||await e.read(),i.app)){const e=JSON.parse(i.app);if(null!==this.pasteSourceFromClip(t,e))return}await this._processSpecialLineToolsContents(e,i,t)}applyStudyTemplate(e,t){const i=new je(this._model(),e,t);this._pushUndoCommand(i)}startCustomMoving(e,t,i){this._currentCustomMoveCommand=new ct(this.model(),e,t,i)}customMoveBeingProcessed(){return null!==this._currentCustomMoveCommand}processCustomMove(e){(0,o.ensureNotNull)(this._currentCustomMoveCommand).move(e)}endCustomMoving(){null!==this._currentCustomMoveCommand&&this._currentCustomMoveCommand.hasChanges()&&(this._pushUndoCommand(this._currentCustomMoveCommand),this._currentCustomMoveCommand=null)}cloneLineTools(e,t){for(let t=0;t<Math.min(5,e.length);++t)(0,ae.trackDrawingCloned)(e[t]);this.beginUndoMacro(fi,this._lineToolsDoNotAffectChartInvalidation.value());const i=new w(this._model(),e,t,fi);if(this._pushUndoCommand(i),(0,Me.drawOnAllCharts)().value()){const e=i.newIds().map(e=>(0,o.ensureNotNull)(this.model().dataSourceForId(e)));this.copyToOtherCharts(e)}return this.endUndoMacro(),this.emitEvent("cloneLineTools"),i.newIds()}removeSource(e,t,i){this.lineBeingCreated()!==e?this.removeSources([e],t,ai.format({title:Fi(e)}),i):this.cancelCreatingLine()}removeSelectedSources(){const e=this._model().selection().dataSources()
|
||||
;if(!e.length)return;const t=(e.length>1?li:ai).format({title:Fi(e[0])});this.removeSources(e,!1,t)}removeSources(e,t,i,s){s||(e=e.filter(e=>e.isUserDeletable()));const r=this._model(),n=r.lineToolsGroupModel(),a=e.every(b.isLineTool)&&this._lineToolsDoNotAffectChartInvalidation.value();this.beginUndoMacro(i,a),r.selectionMacro(s=>{const a=new Map;e.forEach(e=>{if((0,b.isLineTool)(e)){const t=n.groupForLineTool(e);if(null!==t){const i=a.get(t)||[];i.push(e),a.set(t,i)}null!==e.linkKey().value()&&(0,Me.removeLineTool)({withUndo:!0,model:this.model(),linkKey:(0,o.ensureNotNull)(e.linkKey().value()),symbol:this.model().mainSeries().symbol(),lineToolState:e.state(!1),sourceTitle:Fi(e)})}}),a.forEach((e,t)=>{const i=new P.ExcludeLineToolsFromGroupUndoCommand(r,t,e);this._pushUndoCommand(i)});const l=new C.RemoveSourcesCommand(r,e,i),c=l.removedIds();this._pushUndoCommand(l),!t&&c.length>0&&(1===c.length?this.emitEvent("removeSource",[c[0]]):this.emitEvent("removeSources",[c]))}),this.endUndoMacro()}removeUnloadedLineTool({lineToolsSynchronizer:e,sourceTitle:t,linkKey:i,symbol:s,state:r,withUndo:n,unlink:o}){}async scrollToLineTool(e){const t=this.timeScale().logicalRange();if(null===t)return;const i=this.timeScale().barSpacing();let s=t.left();const r=e.points().map(e=>e.index);let n=this.timeScale().points().firstIndex();const a=this.timeScale().points().lastIndex();if(null===n||null===a)return;const l=t.length()/2;if(0===r.length||r.some(e=>t.contains(e)))return;const c=()=>{const t=e.points().map(e=>e.index),i=t.filter(e=>e<=a).reduce((e,t)=>null===e?t:Math.max(e,t),null);return null!==i?i:t.reduce((e,t)=>Math.min(e,t))};let d,u=c();if(n-l>u){const t=e.points().map(e=>e.time).filter(T.notUndefined).map(e=>e.valueOf()/1e3);if(0===t.length)return;const i=t.reduce((e,t)=>Math.min(e,t),t[0]);await this.model().gotoTime(i),u=c();s=(0,o.ensureNotNull)(this.timeScale().logicalRange()).left(),n=(0,o.ensureNotNull)(this.timeScale().points().firstIndex())}n-l>u?(d=(s-n+l)*i,this.mainSeries().setGotoDateResult({timestamp:(0,o.ensureNotNull)(this.timeScale().points().valueAt(n)),eod:!0})):d=(s-u+1+l)*i,this.startScrollTime(0),(0,ve.doAnimate)({onStep:(e,t)=>this.scrollTimeTo(t),from:0,to:Math.round(d),easing:h.easingFunc.easeInOutCubic,duration:h.dur,onComplete:()=>this.endScrollTime()})}mergeSourceUp(e){const t=new L.MergeUpUndoCommand(this._model(),e,vi);this._mergeUnmergeSource(e,t)}mergeSourceDown(e){const t=new L.MergeDownUndoCommand(this._model(),e,Si);this._mergeUnmergeSource(e,t)}mergeToPane(e,t){const i=this._model().panes().indexOf(t),s=new L.MergeToTargetPane(this._model(),e,i,yi);this._mergeUnmergeSource(e,s)}unmergeSourceUp(e){const t=new M.UnmergeUpUndoCommand(this._model(),e,bi);this._mergeUnmergeSource(e,t)}unmergeSourceDown(e){const t=new M.UnmergeDownUndoCommand(this._model(),e,wi);this._mergeUnmergeSource(e,t)}unmergeToNewBottomPane(e){const t=new M.UnmergeToNewBottomPane(this._model(),e,Ci);this._mergeUnmergeSource(e,t)}availableZOrderOperations(e){
|
||||
const t=this._model().lineToolsGroupModel(),i=e.filter(b.isLineTool),s=i.map(e=>t.groupForLineTool(e));(0,o.assert)(new Set(s).size<=1,"Cannot move line tools from different group");const r=0===s.length?null:s[0];let n={bringForwardEnabled:!1,bringToFrontEnabled:!1,sendBackwardEnabled:!1,sendToBackEnabled:!1};const a=new Set(i);for(const t of(0,A.sortSources)(e)){if((0,b.isLineTool)(t)&&null!==r){const e=(0,A.sortSources)(r.lineTools().filter(e=>!a.has(e)||e===t));n=Oi(n,{bringForwardEnabled:t!==e[e.length-1],bringToFrontEnabled:t!==e[e.length-1],sendBackwardEnabled:t!==e[0],sendToBackEnabled:t!==e[0]});continue}const e=(0,o.ensureNotNull)(this._model().paneForSource(t)).sourcesByGroup().allExceptSpecialSources();if(0===e.length)continue;const i=t.zorder(),s=e[0].zorder(),l=e[e.length-1].zorder();n=Oi(n,{bringForwardEnabled:i!==l,bringToFrontEnabled:i!==l,sendBackwardEnabled:i!==s,sendToBackEnabled:i!==s})}return n}sendToBack(e){if(!this.availableZOrderOperations(e).sendToBackEnabled)throw new Error("Send to back operation is unavailable");let t=null;const i=e[0];if((0,b.isLineTool)(i)){const s=this._model().lineToolsGroupModel().groupForLineTool(i);if(null!==s){const i=s.lineTools();t=new X(this.model(),(0,A.sortSources)(e),i[0])}}null===t&&(t=new q(this.model(),(0,A.sortSources)(e))),this._pushUndoCommand(t),this.emitEvent("changeZOrder",[e])}bringToFront(e){if(!this.availableZOrderOperations(e).bringToFrontEnabled)throw new Error("Bring to front operation is unavailable");let t=null;const i=e[0];if((0,b.isLineTool)(i)){const s=this._model().lineToolsGroupModel().groupForLineTool(i);if(null!==s){const i=s.lineTools();t=new K(this.model(),(0,A.sortSources)(e),i[i.length-1])}}null===t&&(t=new G(this.model(),(0,A.sortSources)(e))),this._pushUndoCommand(t),this.emitEvent("changeZOrder",[e])}sendBackward(e){if(!this.availableZOrderOperations(e).sendBackwardEnabled)throw new Error("Send backward operation is unavailable");const t=ti.format({title:Fi(e[0])});this._sendBackOrBringForward(t,(0,A.sortSources)(e),(e,t)=>new J(this.model(),e,t))}bringForward(e){if(!this.availableZOrderOperations(e).bringForwardEnabled)throw new Error("Bring forward operation is unavailable");const t=ii.format({title:Fi(e[0])});this._sendBackOrBringForward(t,(0,A.sortSources)(e),(e,t)=>new ee(this.model(),e,t))}insertAfter(e,t){e=(0,A.sortSources)(e);const i=si.format({title:Fi(e[0]),target:Fi(t)});this._insertAfterOrBefore(i,e,t,()=>new K(this.model(),e,t))}insertBefore(e,t){e=(0,A.sortSources)(e);const i=ri.format({title:Fi(e[0]),target:Fi(t)});this._insertAfterOrBefore(i,e,t,()=>new X(this.model(),e,t))}detachToRight(e,t){(0,tt.trackEvent)("Chart","Move to new right scale");const i=Pi.format({title:Fi(e)}),s=new Je.MoveToNewPriceScaleUndoCommand(this.model(),e,t,"right",i);this._pushUndoCommand(s),this.emitEvent("moveSource",[e])}detachToLeft(e,t){(0,tt.trackEvent)("Chart","Move to new left scale");const i=Ti.format({title:Fi(e)}),s=new Je.MoveToNewPriceScaleUndoCommand(this.model(),e,t,"left",i);this._pushUndoCommand(s),
|
||||
this.emitEvent("moveSource",[e])}detachNoScale(e,t){(0,tt.trackEvent)("Chart","Make source no scale");const i=xi.format({title:Fi(e)}),s=new Je.MoveToNewPriceScaleUndoCommand(this.model(),e,t,"overlay",i);this._pushUndoCommand(s),this.emitEvent("moveSource",[e])}moveToScale(e,t,i,s,r){(0,tt.trackEvent)("Chart","Move source to target scale"),this.beginUndoMacro(s);const n=new Je.MoveToExistingPriceScaleUndoCommand(this.model(),e,t,i,s),o=r?null:(0,it.sourceNewCurrencyOnPinningToPriceScale)(e,i,this._model()),a=r?null:(0,_t.sourceNewUnitOnPinningToPriceScale)(e,i,this._model());this._pushUndoCommand(n),null!==o&&this.setPriceScaleCurrency(i,o),null!==a&&this.setPriceScaleUnit(i,a),this.endUndoMacro(),this.emitEvent("moveSource",[e])}startScrollTime(e){const t=this.timeScale();this._initialTimeScrollState={rightOffset:t.rightOffset(),barSpacing:t.barSpacing()},this._initialTimeScrollPos=e,this.model().startScrollTime(e)}scrollTimeTo(e){let t=!1;return null!==this._initialTimeScrollPos&&null!==this._initialTimeScrollState&&Math.abs(e-this._initialTimeScrollPos)>20&&(this._pushUndoCommand(new oe.TimeScaleChangeUndoCommand(this.model(),this._initialTimeScrollState,Ii)),this._initialTimeScrollPos=null,this._initialTimeScrollState=null,t=!0),this.model().scrollTimeTo(e),t}endScrollTime(){this.model().endScrollTime(),this._initialTimeScrollPos=null,this._initialTimeScrollState=null}startScaleTime(e){const t=this.timeScale(),i={rightOffset:t.rightOffset(),barSpacing:t.barSpacing()};this._pushUndoCommand(new oe.TimeScaleChangeUndoCommand(this.model(),i,Mi)),this.model().startScaleTime(e)}scaleTimeTo(e){this.model().scaleTimeTo(e)}endScaleTime(){this.model().endScaleTime()}resetTimeScale(){const e=this.timeScale(),t={rightOffset:e.rightOffset(),barSpacing:e.barSpacing()};this._pushUndoCommand(new oe.TimeScaleChangeUndoCommand(this.model(),t,Li)),this.model().resetTimeScale()}startScalePrice(e,t,i,s){this._scalePriceInfo={priceScaleState:t.state(),tryMergeConsecutiveScales:s},this.model().startScalePrice(e,t,i)}scalePriceTo(e,t,i){this.model().scalePriceTo(e,t,i)}endScalePrice(e,t){this.model().endScalePrice(e,t);const i=(0,o.ensureNotNull)(this._scalePriceInfo);(0,n.default)(i.priceScaleState,t.state())||this._pushUndoCommand(new mt.PriceScaleChangeUndoCommand(this.model(),e,t,i.priceScaleState,i.tryMergeConsecutiveScales)),this._scalePriceInfo=null}startTwoPointsScalePrice(e,t,i,s,r){this._scalePriceInfo={priceScaleState:t.state(),tryMergeConsecutiveScales:r},this.model().startTwoPointsScalePrice(e,t,i,s)}twoPointsScalePriceTo(e,t,i,s){this.model().twoPointsScalePriceTo(e,t,i,s)}endTwoPointsScalePrice(e,t){this.model().endTwoPointsScalePrice(e,t);const i=(0,o.ensureNotNull)(this._scalePriceInfo);(0,n.default)(i.priceScaleState,t.state())||this._pushUndoCommand(new mt.PriceScaleChangeUndoCommand(this.model(),e,t,i.priceScaleState,i.tryMergeConsecutiveScales)),this._scalePriceInfo=null}resetPriceScale(e,t){const i=t.state();this.model().resetPriceScale(e,t),(0,
|
||||
n.default)(i,t.state())||this._pushUndoCommand(new mt.PriceScaleChangeUndoCommand(this.m_model,e,t,i))}rearrangePanes(e,t){const i=new ne(this._model(),e,t);this._pushUndoCommand(i)}movePane(e,t){const i=new ne(this._model(),e,t);this._pushUndoCommand(i)}pasteSourceFromClip(e,t,i){const s=t;if(!s||0===s.sources.length)return null;const r=e||(0,o.ensureNotNull)(this.model().paneForSource(this.mainSeries()));if(!s.sources.some(e=>"drawing"!==e.type||null!==r.clipboardLineToolOwnerSource(e.source.id)))return null;this.beginUndoMacro(Di.format({title:s.title}));let n=0;const a=[],l=[];for(const t of s.sources)if("drawing"===t.type&&null!==r.clipboardLineToolOwnerSource(t.source.id)){const e=this.pasteLineTool(r,t);n<5&&((0,ae.trackDrawingPasted)(e),n+=1),l.push(e),a.push(e)}else"study"===t.type&&t.source&&t.source.metaInfo&&this.checkIfFeatureAvailable(new(p())(t.source.metaInfo))&&a.push(this.pasteStudy(t,i?e:void 0));return l.length&&this.selectionMacro(e=>{e.clearSelection(),l.forEach(t=>{e.addSourceToSelection(t,null)})}),this.endUndoMacro(),a}pasteLineTool(e,t,i,s){t.source.state.intervalsVisibilities=(0,Lt.mergeIntervalVisibilitiesDefaults)(t.source.state.intervalsVisibilities),(0,Lt.makeIntervalsVisibilitiesVisibleAtInterval)(t.source.state.intervalsVisibilities,me.Interval.parse(this.model().mainSeries().interval()));const r=new $e(this.model(),t,e,i,s);this._pushUndoCommand(r);const n=r.source();return r.needCopyToOtherCharts()&&this.copyToOtherCharts([n]),this.selectionMacro(e=>{e.clearSelection(),e.addSourceToSelection(n,null)}),n}pasteStudy(e,t){const i=new nt(this.model(),e,null==t?void 0:t.id());this._pushUndoCommand(i);const s=(0,o.ensureNotNull)(i.state()).id;return(0,ei.emit)("study_event",s,"paste_study"),(0,o.ensureNotNull)(this._model().dataSourceForId(s))}setPriceScaleCurrency(e,t){const i=new Xe.SetPriceScaleCurrencyUndoCommand(e,t,this.chartWidget(),mi);this._pushUndoCommand(i)}setPriceScaleUnit(e,t){const i=new Ze.SetPriceScaleUnitUndoCommand(e,t,this.chartWidget(),gi);this._pushUndoCommand(i)}setSymbol(e,t){e.symbol()!==t&&this._pushUndoCommand(new et(e,t,this.chartWidget()))}setResolution(e,t){me.Interval.isEqual(e.interval(),t)||this._pushUndoCommand(new Qt(e,t,this.chartWidget()))}chartLoadTheme(e,t,i){const s=new Zt(this.model(),e,t);i?s.redo():this._pushUndoCommand(s)}isJustClonedChart(){return this._chartWidget.isJustClonedChart()}copyToOtherCharts(e){const t=this.mainSeries(),i=t.syncModel(),s=this.timeScale();if(i)for(const r of e){if(!r.isSynchronizable())continue;const e=r.linkKey().value()||(0,Ge.randomHash)();r.linkKey().setValue(e);const n=r.state(!1),a=r.normalizedPoints(),l=r.properties().interval.value(),c=t.interval();let h;if(me.Interval.isEqual(l,c))h=a.map(e=>{const t=(0,o.ensureNotNull)(s.timePointToIndex(e.time_t))+e.offset;return{price:e.price,timeStamp:(0,o.ensureNotNull)(this.model().externalTimeStamp(t))}});else{const e=i.createNewModelWithResolution(l);h=a.map(t=>({price:t.price,timeStamp:0===t.offset?t.time_t:e.projectTime(t.time_t,t.offset)}))}const d={...n,id:r.id(),
|
||||
linkKey:e,points:h,linetool:r.toolname,model:this.model(),symbol:t.symbol(),finalState:{points:a,interval:l},pointPositionPercents:r.isFixed()?r.calcPositionPercents():void 0,sharingMode:r.sharingMode().value()};(0,Me.copyLineTool)(d)}}addPaneStretchFactorUndoCommand(e,t,i,s){const r=new ot(this.model(),e,t,i,s);this._pushUndoCommand(r)}paneForSource(e){return this.m_model.paneForSource(e)}destroy(){this._lineToolsDoNotAffectChartInvalidation.destroy(),this.m_model.destroy()}moveSelectedToolsLeft(){return this._moveSelectedTools(2)}moveSelectedToolsUp(){return this._moveSelectedTools(0)}moveSelectedToolsRight(){return this._moveSelectedTools(3)}moveSelectedToolsDown(){return this._moveSelectedTools(1)}insertStudyWithoutCheck(e,t){return this._insertStudy(e,t,{},!1,void 0,void 0,void 0,void 0,void 0,null,void 0)}saveLineToolState(e,t){this._pushUndoCommand(new I(this.m_model,[e],t))}resetScales(){this.beginUndoMacro(Ai),this.resetTimeScale();for(const e of this.m_model.panes()){for(const t of e.leftPriceScales())this.resetPriceScale(e,t);for(const t of e.rightPriceScales())this.resetPriceScale(e,t)}this.endUndoMacro(),this.m_model.recalculateAllPanes((0,ue.viewportChangeEvent)())}shareLineTools(e,t){}_mergeUnmergeSource(e,t){this.beginUndoMacro(t.text());const i=(0,o.ensureNotNull)(this._model().paneForSource(e)),s=new Set(i.sourcesByGroup().lineSources().filter(t=>t.ownerSource()===e));this._model().lineToolsGroupModel().groups().filter(e=>{const t=e.lineTools().some(e=>s.has(e)),i=e.lineTools().some(e=>!s.has(e));return t&&i}).forEach(e=>{this._pushUndoCommand(new P.ExcludeLineToolsFromGroupUndoCommand(this._model(),e,e.lineTools()))}),this._pushUndoCommand(t),this.endUndoMacro()}_insertStudy(e,t,i,s,r,n,a,l,c,h,d){const u=Vi.format({title:e.description});this.beginUndoMacro(u);const p=new ht(this.model(),e,t,i,s,r,n,a,l,c,h||null,u);this._pushUndoCommand(p);const _=p.insertedStudy();if(void 0!==d){const e=new dt.SetPriceScaleModeCommand(d,(0,o.ensureNotNull)(_.priceScale()),null,this.model());this._pushUndoCommand(e)}return this.endUndoMacro(),_}async _processSpecialLineToolsContents(e,t,i){0}_insertAfterOrBefore(e,t,i,s){const r=(0,o.ensureNotNull)(this._model().paneForSource(i));if(t.some(e=>(0,b.isLineTool)(e)&&this._model().paneForSource(e)!==r))throw new Error("Cannot insert line tool after target on another pane");this.beginUndoMacro(e),t.forEach(e=>{(0,o.ensureNotNull)(this.model().paneForSource(e))!==r&&this.mergeToPane(e,r)});const n=s();this._pushUndoCommand(n),this.emitEvent("changeZOrder",[t]),this.endUndoMacro()}_sendBackOrBringForward(e,t,i){const s=new Map;t.forEach(e=>{const t=(0,o.ensureNotNull)(this._model().paneForSource(e)),i=s.get(t)||[];i.push(e),s.set(t,i)}),this.beginUndoMacro(e),s.forEach((e,t)=>{this._pushUndoCommand(i(t,e))}),this.endUndoMacro(),this.emitEvent("changeZOrder",[t])}_moveSelectedTools(e){const t=this.model().selection().lineDataSources();if(0===t.length)return!1;if((0,Me.lockDrawings)().value())return!0;const i=this.timeScale().visibleBarsStrictRange();if(null===i)return!1
|
||||
;const s=function(e){const t=new Map;for(const i of e){const e=i.ownerSource();if(null===e)continue;let s=t.get(e);if(void 0===s){const r=e.priceScale(),n=e.priceStep(),o=e.firstValue();if(null===r||null===n||null===o)continue;if(null===r.priceRange())continue;s={sources:[],priceScale:r,priceStep:n,startPrice:i.points()[0].price,firstValue:o},t.set(e,s)}s.sources.push(i)}return t}(t);if(0===s.size)return!1;this.beginUndoMacro(pi,this._lineToolsDoNotAffectChartInvalidation.value());const r=i.firstBar(),n=this.timeScale().indexToCoordinate(r),o=r+(3===e?1:2===e?-1:0),l=this.timeScale().indexToCoordinate(o);return Me.isDirectionalMovementActive.setValue(!0),s.forEach(t=>{const{startPrice:i,priceStep:s,priceScale:c,firstValue:h}=t,d=i+(0===e?s:1===e?-s:0),u=c.priceToCoordinate(i,h),p=c.priceToCoordinate(d,h),_={logical:{index:r,price:i},screen:new a.Point(n,u)},m={logical:{index:o,price:d},screen:new a.Point(l,p)};this.startMovingSources(t.sources,_,null),this.moveSources(m),this.endMovingSource(!1,!0)}),Me.isDirectionalMovementActive.setValue(!1),this.endUndoMacro(),!0}_restoreStudyFactoryDefaults(e){const t=new Mt(this.m_model,e.properties());this._pushUndoCommand(t)}_restoreLineToolFactoryDefaults(e){this.beginUndoMacro(_i,this._lineToolsDoNotAffectChartInvalidation.value()),this.saveLineToolState(e,_i);const t=new It(this.m_model,e.properties(),_i);this._pushUndoCommand(t),this.saveLineToolState(e,_i),this.endUndoMacro(),this.model().updateSource(e)}_removeAllDrawingToolsImpl(e){this.selectionMacro(()=>{this.lineBeingCreated()&&this.cancelCreatingLine();this.dataSources().filter(b.isLineTool).filter(e=>e.isActualSymbol()&&e.isUserDeletable()).filter(t=>!e||e===t.toolname).forEach(e=>this.removeSource(e,!1))})}_removeAllStudiesImpl(){const e=this.dataSources(),t=e.filter(x.isStudy).filter(e=>!e.isChildStudy()&&e.removeByRemoveAllStudies()),i=e.filter(x.isStudyStub);t.concat(i).forEach(e=>this.removeSource(e,!1))}}},88735:(e,t,i)=>{"use strict";var s=i(2872),r=i(88537).ensureNotNull,n=i(56840),o=i(88537).assert,a=i(36244).ChartModelBase,l=i(14291),c=l.isLineTool,h=l.isStudyLineTool,d=i(39094).Watermark,u=i(49483).CheckMobile,p=i(23653).InvalidationMask,_=i(23653).InvalidationLevel;const{globalChangeEvent:m,dataSourceChangeEvent:g}=i(33291);var f=i(66101),v=f.Study,S=i(13672).NonSeriesStudy,y=i(81851),b=y.createStudy,w=y.isStudy,C=y.isFundamentalStudy,P=f.prepareStudyProperties,T=i(85733),x=i(88564).saveDefaultProperties,I=i(32050).MainSeriesScaleRatioProperty,M=i(22423).scaleRatio,L=i(90998).StudyInserter,A=i(21761).dateFormatProperty,E=i(79680).isActingAsSymbolSource,k=i(13795).sourceNewCurrencyOnPinningToPriceScale,D=i(79222).sourceNewUnitOnPinningToPriceScale,V=i(76422),B=i(56606).StudyColorRotatorFactory,N=i(67337),R=i(44419).AppliedTimeFrame,O=N.enabled("auto_enable_symbol_labels");N.enabled("fix_left_edge");class F extends a{constructor(e,t,i,r,n,o,a,l,c,h){super(e,t,i,r,n,o,a,l,c,h);var u=this,p=this.m_mainSeries.properties(),_=this._panes[0];_.setStretchFactor(2*_.stretchFactor()),
|
||||
this._properties.listeners().subscribe(this,F.prototype.propertyChangeHandler),this._properties.timezone.listeners().subscribe(null,(function(){u._chartApi&&u._chartApi.isConnected().value()&&u._chartApi.switchTimezone(u.timezone())})),_.addDataSource(this.m_mainSeries,this._panes[0].findSuitableScale(this.m_mainSeries)),this._mainSeriesScaleRatioProperty=new I(this),this.m_mainSeries.dataEvents().completed().subscribe(this,function(){this._scrollingState&&this.gotoTime()}.bind(this)),this.m_mainSeries.onIntervalChanged().subscribe(this,(function(){this._recalcVRStudiesParams.oldStartVisibleIndex=NaN,this._recalcVRStudiesParams.oldEndVisibleIndex=NaN})),this._readOnly||(p.addChild("priceAxisProperties",this.m_mainSeries.m_priceScale.properties()),this._properties.paneProperties.legendProperties.showStudyTitles.listeners().subscribe(this,(function(e){e.value()||u._properties.paneProperties.legendProperties.showStudyArguments.setValue(!1)}))),this._barsMarksSources=a(this);for(var m=0;m<this._barsMarksSources.length;m++)this._barsMarksSources[m].setOwnerSource(this.m_mainSeries);this._watermarkSource=this._options.watermarkEnabled?new d(this,this.m_mainSeries):null,T.hideAllDrawings().subscribe(this,this._onDrawingsVisibilityChanged),T.hideAllIndicators().subscribe(this,this._onIndicatorsVisibilityChanged),this._properties.scalesProperties.listeners().subscribe(this,F.prototype.fullUpdate),this._studyInserted=new s,this._studyShiftColorStartOffset=void 0,this._linePointBeingEdited=null,this._lineBeingEdited=null,A.subscribe(this,this._updateDateTimeFormatter),this.mainSeries().properties().interval.subscribe(this,this._updateDateTimeFormatter),this._updateDateTimeFormatter(),this._studyColorRotatorFactory=new B(this),this._dataSourceCollectionChanged.subscribe(this,this._updateShowLegendProperty.bind(this)),this._properties.paneProperties.legendProperties.showLegend.subscribe(this,this._updateShowLegendProperty),this._appliedTimeFrame=new R(this),this.mainSeries().onTimeFrameApplied().subscribe(this,(function(e){var t=null!==e?{res:this.mainSeries().interval(),val:e}:null;this.appliedTimeFrame().setValue(t)}))}applyPreferences(e){for(var t in e)void 0!==this._properties[t]&&"m_mainSeries"!==this._properties[t]&&this._properties[t].mergeAndFire(e[t]);void 0!==e.timeScale&&this._timeScale.defaultRightOffset().setValue(e.timeScale.defaultRightOffset),this._properties.saveDefaults(),this.m_mainSeries.applyPreferences(e.mainSeries),this.sessions().applyPreferences(e.sessions),this.recalculateAllPanes(m()),this.fullUpdate()}timezone(){return this._properties.timezone.value()}initConnection(){this._chartApi.switchTimezone(this.timezone())}updatePane(e){var t=this._paneInvalidationMask(e);this.invalidate(t)}fullUpdate(){this.invalidate(p.full())}lightUpdate(){this.invalidate(p.light())}studiesMetaData(){return this._studiesMetaData}studyVersioning(){return this._studyVersioning}startNotStartedStudies(){if(!this.m_mainSeries.isStarted())throw new Error("Cannot start studies: main series is not started")
|
||||
;for(var e=this.dataSources(),t=0;t<e.length;t++)w(e[t])&&!e[t].isStarted()&&e[t].restart&&e[t]!==this.m_mainSeries&&e[t].restart()}readOnly(){return this._readOnly}chartApi(){return this._chartApi}propertyChangeHandler(){this.lightUpdate()}_onDrawingsVisibilityChanged(e){for(var t=!1===e.value(),i=this.dataSources(),s=0;s<i.length;s++){var r=i[s],n=c(r)&&r.properties().visible.value();t&&n?V.emit("drawing_event",r.id(),"show"):!t&&n&&V.emit("drawing_event",r.id(),"hide")}this.selectionMacro((function(e){e.clearSelection()}))}_onIndicatorsVisibilityChanged(){var e=this.allStudies().filter((function(e){return e.properties().visible.value()&&e.canBeHiddenByGlobalFlag()}));if(0!==e.length){for(var t=!1,i=0;i<e.length;i++)if(this.selection().isSelected(e[i])){t=!0;break}t?this.selectionMacro((function(e){e.clearSelection()})):this.lightUpdate()}}mainSeries(){return this.m_mainSeries}timeScale(){return this._timeScale}watermarkSource(){return this._watermarkSource}crossHairSource(){return this.m_crossHairSource}publishedChartsTimelineSource(){return null}priceScaleSlotsCount(){var e=0,t=0;this._panes.forEach((function(i){e=Math.max(i.leftPriceScales().length,e),t=Math.max(i.rightPriceScales().length,t)}));var i=e+t;if(u.any()){var s=this.paneForSource(this.mainSeries()),r=s.priceScalePosition(this.mainSeries().priceScale()),n="right"===r;return"overlay"===r&&(n=s.rightPriceScales().length>0),n?{left:0,right:1,totallySlots:i}:{left:1,right:0,totallySlots:i}}return{left:e,right:t,totallySlots:e+t}}setPriceAutoScale(e,t,i){e.setPriceAutoScale(t,i),this.invalidate(this._paneInvalidationMask(e,_.Light))}updateScales(e,t){this._undoModel._chartWidget._updateScalesActions()}mainSeriesScaleRatioProperty(){return this._mainSeriesScaleRatioProperty}mainSeriesScaleRatioPropertyOnChanged(){this._mainSeriesScaleRatioProperty.listeners().fire(this._mainSeriesScaleRatioProperty)}mainSeriesScaleRatio(){return M(this._timeScale,this.m_mainSeries.priceScale())}setMainSeriesScaleRatio(e){this.paneForSource(this.m_mainSeries).applyPriceScaleRatio(this.m_mainSeries.priceScale(),e)}recalcStudyBasedLineTools(){this.dataSources().forEach((function(e){h(e)&&e.recalcStudyIfNeeded&&e.recalcStudyIfNeeded()}))}restoreFactoryDefaults(e){e.restoreFactoryDefaults(),this.recalcVisibleRangeStudies(!0)}orderedDataSources(e){var t=[];t.push(this.m_crossHairSource);for(var i=0;i<this._panes.length;i++){var s=this._panes[i].sourcesByGroup().all().slice();e&&s.reverse(),t=t.concat(s)}return t}dataSourceForId(e){for(var t,i=0;i<this._panes.length;++i)if(t=this._panes[i].dataSourceForId(e))return t;return null}children(e,t){return this.dataSources().filter((function(i){return(!0!==t||!w(i)||!i.isChildStudy())&&i.ownerSource()===e}))}onSyncScrollNeeded(e){var t=this._undoModel._chartWidget;if(t._chartWidgetCollection){var i=this.mainSeries().syncModel();if(i){var s=1e3*this._timeScale.points().roughTime(e,i.projectTime.bind(i));t._chartWidgetCollection.syncScroll(s,this)}}}updateTimeScaleBaseIndex(e){var t=this.mainSeries().bars()
|
||||
;t.isEmpty()||this._updateBaseIndex(r(t.lastIndex()),e&&e.index>0)}createStudyInserter(e){return new L(e,this._studiesMetaInfoRepository,{createStudy:this.insertStudyWithParams.bind(this)})}insertStudyWithParams(e,t,i,s,r,o,a,l,c,h,d){null==o&&(o=this.mainSeries());var u=null;if(!r&&void 0!==e.groupingKey){var p=this.findNonOverlayStudyWithGroupingKey(e.groupingKey);null!==p&&(u=p.pane)}null===u&&(r||e.is_price_study?u=this.paneForSource(o):(u=this.createPane(),void 0!==h&&u.setPaneSize(h))),"Compare@tv-basicstudies"===e.id&&this.m_mainSeries.priceScale().setMode({log:!1,percentage:!0});var _=Object.assign({},s,{inputs:t}),m=P(e,_,u,this.studyVersioning(),o),f=b(this,m,o,e,d);this._recalcVisibleRangeStudiesImpl({studies:[f],oldEndVisibleIndex:-1,oldStartVisibleIndex:-1,force:!0,timerId:null});var v=u.findSuitableScale(f,o,a);if(v===this.mainSeries().priceScale()&&E(f)){var S=l?k(f,v,this,!0):null,y=c?D(f,v,this,!0):null;null===S&&null===y||f.setSymbolParams({currency:S||void 0,unit:y||void 0})}return E(f)&&u.hasDataSource(this.mainSeries())&&O&&!n.getBool("enable_symbol_labels_on_inserting_compare_once",!1)&&(x(!0),this.properties().scalesProperties.showSymbolLabels.setValue(!0),x(!1),n.setValue("enable_symbol_labels_on_inserting_compare_once",!0)),f.start(),null!==i&&u.id()===i.paneId?u.insertDataSource(f,v,i.zorder):u.addDataSource(f,v),f.properties().linkedToSeries&&f.properties().linkedToSeries.value()&&f.setOwnerSource(this.mainSeries()),this.recalculatePane(u,g(f.id())),this.fullUpdate(),this._invalidateBarColorerCaches(),this._recalcVisibleRangeStudiesImpl({studies:[f],force:!0}),this._recalcColorStudiesImpl({studies:[f],force:!0}),this._studyInserted.fire(f),f.maxOffset().subscribe(this._boundUpdateStudiesMaxOffset,{callWithLast:!0}),f}studyInserted(){return this._studyInserted}_unmergeAvailable(e){return e===this.m_mainSeries||TradingView.isInherited(e.constructor,v)&&!e.isLinkedToSeries()&&!TradingView.isInherited(e.constructor,S)&&e.showInObjectTree()}isMergeUpAvailableForSource(e){return!!this._unmergeAvailable(e)&&this.paneForSource(e)!==this.panes()[0]}isMergeDownAvailableForSource(e){if(!this._unmergeAvailable(e))return!1;var t=this.paneForSource(e),i=this.panes();return t!==i[i.length-1]}isUnmergeAvailableForSource(e){return!!this._unmergeAvailable(e)&&this.paneForSource(e).dataSources().filter(this._unmergeAvailable,this).length>1}lineBeingEdited(){return this._lineBeingEdited}linePointBeingEdited(){return this._linePointBeingEdited}calculateDefaultTags(){for(var e=[],t=this.dataSources(),i=0;i<t.length;i++){var s=t[i];s.tags&&(e=e.concat(s.tags()))}return e}_sendTo(e,t){var i={},s=this;for(var r in e.forEach((function(e){var t=s.paneForSource(e),r=s._panes.indexOf(t);i[r]||(i[r]=[]),i[r].push(e)})),i){t(s._panes[r],i[r])}this.fullUpdate()}sendToBack(e){this._sendTo(e,(function(e,t){e.sendToBack(t)}))}bringToFront(e){this._sendTo(e,(function(e,t){e.bringToFront(t)}))}allLineTools(){return this._getAllSources(c)}getStudyById(e){var t=this.dataSourceForId(e);return null!==t&&w(t)?t:null}
|
||||
Reference in New Issue
Block a user