Files
ai/charting_library/bundles/144.4a7e7ba1d7853630aeaf.js

6 lines
18 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[144,9974],{7955:(e,t,i)=>{i.d(t,{inplaceEditHandlers:()=>o});var n=i(83077);function o(e){const t=(t,i)=>{i.sourceWasSelected&&e(t)};return{areaName:n.AreaName.Text,executeDefaultAction:{doubleClickHandler:!0,doubleTapHandler:!0},clickHandler:t,tapHandler:t}}},7919:(e,t,i)=>{i.d(t,{InplaceTextLineSourcePaneView:()=>u});var n=i(85842),o=i(91599),s=i(82347),r=i(89772),a=i(41928),d=i(83077),l=i(28031),c=i(29968);const h=o.t(null,void 0,i(3443));class u extends a.LineSourcePaneView{constructor(e,t,i,n,o){super(e,t,o),this._textInfo=new r.WatchedObject({}),this._isTextEditModeActivated=!1,this._textWasEdited=!1,this._showTextEditor=i,this._hideTextEditor=n,this._editableTextSpawn=this._source.editableText().spawn(),this._editableTextSpawn.subscribe((()=>this._updateTextWasEditable()))}destroy(){this._editableTextSpawn.destroy()}setSelectionRange(e){this._selectionRange=e}closeTextEditor(){this._closeTextEditorImpl()}_closeTextEditorImpl(e){this._textWasEdited=!1,this._isTextEditModeActivated=!1,this._hideTextEditor?.(e)}_placeHolderMode(e){return!this._isTextEditMode()&&this._model.hoveredSource()===this._source&&0===this._model.hoveredSourceOrigin()&&(!e||this._model.lastHittestData()?.areaName!==d.AreaName.AnchorPoint)&&!(0,c.lastMouseOrTouchEventInfo)().isTouch&&!this._source.editableTextProperties().text.value()&&this._model.selection().isSelected(this._source)}_updateTextWasEditable(){this._textWasEdited=!0}_textCursorType(){return this._model.selection().isSelected(this._source)&&!this._model.sourcesBeingMoved().includes(this._source)?l.PaneCursorType.Text:void 0}_updateInplaceText(e){this._textInfo.setValue(e),this._model.selection().isSelected(this._source)||this.closeTextEditor();const t=this._source.textEditingEl();t&&this._activateEditMode(t)}_tryActivateEditMode(e,t){const i=(0,n.ensureNotNull)(t.target instanceof HTMLElement?t.target.closest(".chart-gui-wrapper"):null);this._activateEditMode(i)}_isTextEditMode(){return this._isTextEditModeActivated}_isTextBeingEdited(){return this._textWasEdited}_textData(){return this._text()||(this._textWasEdited?"":h)}_textColor(){const e=this._source.editableTextProperties().textColor.value();return this._text()?e:(0,s.generateColor)(e,50,!0)}_inplaceTextHighlight(){const e=this._source.editableTextStyle();return this._selectionRange?{selectionHighlight:{start:this._selectionRange[0],end:this._selectionRange[1],color:(0,s.generateColor)(e.selectionColor,80,!0)}}:{}}_activateEditMode(e){this._showTextEditor?.((0,n.ensureNotNull)(this._getOwnerSource()),e,this._textInfo,h,this._closeTextEditorImpl.bind(this)),this._isTextEditModeActivated=!0}_text(){return this._isTextEditMode()?this._source.editableText().value():this._source.editableTextProperties().text.value()}}},63212:(e,t,i)=>{i.d(t,{InplaceTextLineDataSource:()=>S,InplaceTextUndoCommand:()=>m})
;var n=i(83991),o=i(85842),s=i(57415),r=i(11284),a=i(55482),d=i(91599),l=i(72769),c=i(68657),h=i(89659),u=i(1479),_=i(82014),p=i(9840),g=i(34773);const x={selectionColor:(0,r.getHexColorByName)("color-tv-blue-500"),cursorColor:(0,r.getHexColorByName)("color-black")},T={selectionColor:(0,r.getHexColorByName)("color-white"),cursorColor:(0,r.getHexColorByName)("color-white")};var P;!function(e){e[e.TextEditingJustFinishedTime=100]="TextEditingJustFinishedTime"}(P||(P={}));class m extends u.UndoCommand{constructor(e,t,n,o){super(new l.TranslatedString("change {title} text",d.t(null,void 0,i(58899))).format({title:new l.TranslatedString(t.name(),t.translatedType())}),!0,!g.lineToolsDoNotAffectChartInvalidation),this._sourceId=t.id(),this._model=e,this._oldValue=n,this._newValue=o}redo(){const e=this._source();this._textProperty(e).setValue(this._newValue)}undo(){const e=this._source();this._textProperty(e).setValue(this._oldValue)}_textProperty(e){return e.editableTextProperties().text}_source(){return(0,o.ensureNotNull)(this._model.dataSourceForId(this._sourceId))}}class S extends _.LineDataSource{constructor(e,t,n,o){super(e,t,n,o),this._container=null,this._activeEditingOwnerSource=null,this._editableText=new h.WatchedValue(""),this._activateTextEditingEl=null,this._paneView=null,this._selectionData={},this._cursorPaneView=null,this._cursorPosition=null,this._editingOnCreation=!1,this._editingActivationTime=null,this._editingDeactivationTime=0,this._editableText.subscribe((()=>{this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))})),this._isDarkBackground=(0,c.combine)(((e,t)=>{if(null===t)return this._model.dark().value();const i=(0,a.blendRgba)((0,a.parseRgba)(e),(0,a.parseRgba)(t));return"black"===(0,a.rgbToBlackWhiteString)([i[0],i[1],i[2]],150)}),this._model.backgroundColor().spawnOwnership(),this._createDataSourceBackgroundColorWV()),Promise.all([i.e(8263),i.e(144),i.e(4073),i.e(1912),i.e(1495)]).then(i.bind(i,16630)).then((t=>{this._cursorPaneView=new t.InplaceTextCursorPaneView(this,e),this._additionalCursorDataGetters&&(this._cursorPaneView.setAdditionalCursorData(...this._additionalCursorDataGetters),null!==this._cursorPosition&&(this._cursorPaneView.setCursorPosition(this._cursorPosition),e.updateSource(this)))}))}destroy(){this._isDarkBackground.destroy(),this._editableText.unsubscribe(),this._closeTextEditor(),super.destroy()}editableTextStyle(){return{...this._isDarkBackground.value()?T:x}}removeIfEditableTextIsEmpty(){return!1}activateEditingOnCreation(){return!1}topPaneViews(e){return this._activeEditingOwnerSource&&e.hasDataSource(this._activeEditingOwnerSource)&&!window.TradingView.printing&&this._cursorPaneView?(this._cursorPaneView.update((0,p.sourceChangeEvent)(this.id())),[this._cursorPaneView]):null}dataAndViewsReady(){return super.dataAndViewsReady()&&null!==this._cursorPaneView}editableText(){return this._editableText}textEditingEl(){return this._activateTextEditingEl}activateTextEditingOn(e,t){this._activateTextEditingEl=e,this._editingOnCreation=!!t,
this._editingActivationTime=performance.now(),this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))}deactivateTextEditing(){this._closeTextEditor()}textEditingActivationTime(){return this._editingActivationTime}textEditingJustFinished(){return performance.now()-this._editingDeactivationTime<100}setAdditionalCursorData(e,t){this._cursorPaneView?this._cursorPaneView.setAdditionalCursorData(e,t):this._additionalCursorDataGetters=[e,t]}_updateAllPaneViews(e){super._updateAllPaneViews(e),this._cursorPaneView?.update(e)}async _openTextEditor(e,t,n,r,a){if(null!==this._container)return;null===this._editingActivationTime&&(this._editingActivationTime=performance.now()),this._activateTextEditingEl=null,this._cursorPosition=null,this._container=document.createElement("div"),this._container.style.position="absolute",this._container.style.top="0",this._container.style.bottom="0",this._container.style.left="0",this._container.style.right="0",this._container.style.overflow="hidden",this._container.style.pointerEvents="none",t.appendChild(this._container);const{updateChartEditorText:d,closeChartEditorText:l}=await Promise.all([i.e(7922),i.e(9365),i.e(269)]).then(i.bind(i,5443));if(null===this._container||this._isDestroyed)return;this._activeEditingOwnerSource=e,this._closeChartEditorText=l;const{text:c,textColor:h,wordWrap:u}=this.editableTextProperties(),{forbidLineBreaks:_,maxLength:g}=this.editableTextStyle();this._editableText.setValue(c.value());const x=this.isFixed()?(0,o.ensureDefined)(this.fixedPoint(e)):(0,o.ensureNotNull)(this.pointToScreenPoint(this._points[0],e)),T={position:(0,s.point)(x.x,x.y),textInfo:n,placeholder:r,text:this._editableText,textColor:h,wordWrap:u,forbidLineBreaks:_,maxLength:g,onClose:a,onSelectionChange:this._onSelectionChange.bind(this),onContextMenu:this.onContextMenu?this.onContextMenu.bind(this):void 0};d(this._container,T),this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))}_closeTextEditor(e){null===this._container||this._isDestroyed||(this._editingActivationTime=null,this._editingDeactivationTime=performance.now(),this._saveEditedText(),this._editingOnCreation=!1,this._onSelectionChange(),this._closeChartEditorText?.(this._container),this._closeChartEditorText=void 0,this._container.remove(),this._container=null,this._activeEditingOwnerSource=null,this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id())))}_saveEditedText(){const e=this.editableTextProperties().text.value(),t=this._editableText.value();e!==t&&(this._editingOnCreation&&this.editableTextProperties().text.setValue(t),this._model.undoModel().undoHistory().pushUndoCommand(this._changeEditableTextUndoCommand(e,t)))}_changeEditableTextUndoCommand(e,t){return new m(this._model,this,e,t)}_createDataSourceBackgroundColorWV(){return new h.WatchedValue(null).readonly().ownership()}_onSelectionChange(e){if(null===this._container)return;const t={};if(void 0!==e){const{start:i,end:n}=e;i===n?t.cursorPosition=i:t.selectionRange=[Math.min(i,n),Math.max(i,n)]}(0,
n.default)(t,this._selectionData)||(this._selectionData=t,this._paneViews.forEach((e=>{e.forEach((e=>{"setSelectionRange"in e&&e.setSelectionRange(t.selectionRange)}))})),this._cursorPaneView?this._cursorPaneView.setCursorPosition(t.cursorPosition):this._cursorPosition=t.cursorPosition??null,this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id())))}}},41928:(e,t,i)=>{i.d(t,{LineSourcePaneView:()=>x,anchorResizeCursorType:()=>p,createLineSourcePaneViewPoint:()=>g});var n=i(11284),o=i(85842),s=i(29968),r=i(83077),a=i(71367),d=i(8165),l=i(28031),c=i(61208);const h=n.colorsPalette["color-tv-blue-600"];var u,_;function p(e,t){const i=e.x-t.x,n=e.y-t.y;if(!Number.isFinite(i)||!Number.isFinite(n)||0===i&&0===n)return l.PaneCursorType.Default;let s=Math.atan2(n,i);return s<0&&(s+=2*Math.PI),s>=_.deg337_5||s<_.deg22_5||s>=_.deg157_5&&s<_.deg202_5?l.PaneCursorType.HorizontalResize:s>=_.deg22_5&&s<_.deg67_5||s>=_.deg202_5&&s<_.deg247_5?l.PaneCursorType.DiagonalNwSeResize:s>=_.deg67_5&&s<_.deg112_5||s>=_.deg247_5&&s<_.deg292_5?l.PaneCursorType.VerticalResize:s>=_.deg112_5&&s<_.deg157_5||s>=_.deg292_5&&s<_.deg337_5?l.PaneCursorType.DiagonalNeSwResize:void(0,o.assert)(!1,"unexpected angle")}function g(e,t){return e.pointIndex=t,e}!function(e){e[e.RegularAnchorRadius=6]="RegularAnchorRadius",e[e.TouchAnchorRadius=13]="TouchAnchorRadius",e[e.RegularStrokeWidth=1]="RegularStrokeWidth",e[e.TouchStrokeWidth=3]="TouchStrokeWidth",e[e.RegularSelectedStrokeWidth=3]="RegularSelectedStrokeWidth",e[e.TouchSelectedStrokeWidth=0]="TouchSelectedStrokeWidth"}(u||(u={})),function(e){e[e.deg22_5=Math.PI/8]="deg22_5",e[e.deg67_5=3*Math.PI/8]="deg67_5",e[e.deg112_5=5*Math.PI/8]="deg112_5",e[e.deg157_5=7*Math.PI/8]="deg157_5",e[e.deg202_5=9*Math.PI/8]="deg202_5",e[e.deg247_5=11*Math.PI/8]="deg247_5",e[e.deg292_5=13*Math.PI/8]="deg292_5",e[e.deg337_5=15*Math.PI/8]="deg337_5"}(_||(_={}));class x{constructor(e,t,i){this._invalidated=!0,this._points=[],this._middlePoint=null,this._selectionRenderers=[],this._lineAnchorRenderers=[],this._source=e,this._model=t,this._ownerSource=i??null}priceToCoordinate(e){const t=this._getOwnerSource(),i=t?.priceScale();if(null==i)return null;const n=null!==t?t.firstValue():null;return null===n?null:i.priceToCoordinate(e,n)}anchorColor(){return h}isHoveredSource(){return this._source===this._model.hoveredSource()}isSelectedSource(){return this._model.selection().isSelected(this._source)}isBeingEdited(){return this._model.lineBeingEdited()===this._source}isEditMode(){return!this._model.isSnapshot()}areAnchorsVisible(){return(this.isHoveredSource()&&!this.isLocked()||this.isSelectedSource())&&this.isEditMode()}update(){this._invalidated=!0}isLocked(){return Boolean(this._source.isLocked&&this._source.isLocked())}addAnchors(e,t={}){let i=this._getPoints();this._model.lineBeingCreated()===this._source&&(i=i.slice(0,-1));const n=this._source.points(),o=i.map(((e,t)=>{const i=n[t],o=(0,d.lineSourcePaneViewPointToLineAnchorPoint)(e);return i&&(o.snappingPrice=i.price,o.snappingIndex=i.index),o}))
;e.append(this.createLineAnchor({...t,points:o},0))}createLineAnchor(e,t){const i=e.points.map((e=>e.point)),n=this._getOwnerSource();if(this.isLocked()){const o=this._getSelectionRenderer(t);return o.setData({bgColors:this._lineAnchorColors(i),points:e.points,visible:this.areAnchorsVisible(),hittestResult:r.HitTarget.Regular,ownerSourceId:n?.id(),barSpacing:this._model.timeScale().barSpacing()}),o}const o=(0,s.lastMouseOrTouchEventInfo)().isTouch,a=this._getLineAnchorRenderer(t),d=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return a.setData({...e,color:this.anchorColor(),backgroundColors:this._lineAnchorColors(i),hoveredPointIndex:d,linePointBeingEdited:this.isBeingEdited()?this._model.linePointBeingEdited():null,radius:this._anchorRadius(),strokeWidth:o?u.TouchStrokeWidth:u.RegularStrokeWidth,selected:this.isSelectedSource(),selectedStrokeWidth:o?u.TouchSelectedStrokeWidth:u.RegularSelectedStrokeWidth,visible:this.areAnchorsVisible(),clickHandler:e.clickHandler,ownerSourceId:n?.id()}),a}_getOwnerSource(){return this._ownerSource??this._source.ownerSource()}_anchorRadius(){return(0,s.lastMouseOrTouchEventInfo)().isTouch?u.TouchAnchorRadius:u.RegularAnchorRadius}_lineAnchorColors(e){const t=(0,o.ensureNotNull)(this._model.paneForSource(this._source)).height();return e.map((e=>this._model.backgroundColorAtYPercentFromTop(e.y/t)))}_updateImpl(e){this._points=[];this._model.timeScale().isEmpty()||this._validatePriceScale()&&(this._source.points().forEach(((e,t)=>{const i=this._source.pointToScreenPoint(e,this._ownerSource??void 0);i&&this._points.push(g(i,t))})),2===this._points.length&&(this._middlePoint=this._source.calcMiddlePoint(this._points[0],this._points[1])),this._invalidated=!1)}_validatePriceScale(){const e=this._getOwnerSource()?.priceScale();return null!=e&&!e.isEmpty()}_getSource(){return this._source}_getPoints(){return this._points}_getModel(){return this._model}_height(){const e=this._getOwnerSource()?.priceScale();return null!=e?e.height():0}_width(){return this._model.timeScale().width()}_needLabelExclusionPath(e,t){const i=this._source.properties().childs();return"middle"===(t??i.vertLabelsAlign.value())&&(0,c.needTextExclusionPath)(e)}_addAlertRenderer(e,t,i=this._source.properties().linecolor.value()){}_getAlertRenderer(e){return null}_getSelectionRenderer(e){for(;this._selectionRenderers.length<=e;)this._selectionRenderers.push(new a.SelectionRenderer);return this._selectionRenderers[e]}_getLineAnchorRenderer(e){for(;this._lineAnchorRenderers.length<=e;)this._lineAnchorRenderers.push(new d.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},8165:(e,t,i)=>{i.d(t,{LineAnchorRenderer:()=>T,lineSourcePaneViewPointToLineAnchorPoint:()=>P,lineSourcePaneViewPointToLineAnchorPoint2:()=>m,mapLineSourcePaneViewPointToLineAnchorPoint:()=>S});var n=i(57415),o=i(91069),s=i(85842),r=i(51946),a=i(7321),d=i(83077),l=i(28031),c=i(72244),h=i(57507);function u(e,t,i,n){const{point:o}=t,s=i+n/2;(0,r.drawRoundRect)(e,o.x-s,o.y-s,2*s,2*s,(i+n)/2),e.closePath(),e.lineWidth=n}
function _(e,t,i,n){e.globalAlpha=.2,u(e,t,i,n),e.stroke(),e.globalAlpha=1}function p(e,t,i,n){u(e,t,i-n,n),e.fill(),e.stroke()}function g(e,t,i,n){const{point:o}=t;e.globalAlpha=.2,e.beginPath(),e.arc(o.x,o.y,i+n/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=n,e.stroke(),e.globalAlpha=1}function x(e,t,i,n){const{point:o}=t;e.beginPath(),e.arc(o.x,o.y,i-n/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=n,e.fill(),e.stroke()}class T extends h.BitmapCoordinatesPaneRenderer{constructor(e){super(),this._data=e??null}setData(e){this._data=e}hitTest(e){if(null===this._data||this._data.disableInteractions)return null;const{radius:t,points:i}=this._data,n=t+(0,c.interactionTolerance)().anchor;for(const t of i){if(t.point.subtract(e).length()<=n)return new d.HitTestResult(t.hitTarget??d.HitTarget.ChangePoint,{areaName:d.AreaName.AnchorPoint,pointIndex:t.pointIndex,cursorType:t.cursorType??l.PaneCursorType.Default,activeItem:t.activeItem,snappingPrice:t.snappingPrice,snappingIndex:t.snappingIndex,nonDiscreteIndex:t.nonDiscreteIndex,possibleMovingDirections:t.possibleMovingDirections,clickHandler:this._data.clickHandler,tapHandler:this._data.clickHandler,ownerSourceId:this._data.ownerSourceId})}return null}doesIntersectWithBox(e){return null!==this._data&&this._data.points.some((t=>(0,o.pointInBox)(t.point,e)))}_drawImpl(e){if(null===this._data||!this._data.visible)return;const t=[],i=[],n=[],o=[];for(let e=0;e<this._data.points.length;++e){const s=this._data.points[e],r=this._data.backgroundColors[e];s.square?(t.push(s),i.push(r)):(n.push(s),o.push(r))}t.length&&this._drawPoints(e,t,i,p,_),n.length&&this._drawPoints(e,n,o,x,g)}_drawPoints(e,t,i,o,r){const{context:d,horizontalPixelRatio:l,verticalPixelRatio:c}=e,h=(0,s.ensureNotNull)(this._data),u=h.radius;let _=Math.max(1,Math.floor((h.strokeWidth||2)*l));h.selected&&(_+=Math.max(1,Math.floor(l/2)));const p=Math.max(1,Math.floor(l));let g=Math.round(u*l*2);g%2!=p%2&&(g+=1);const x=p%2/2;d.strokeStyle=h.color;for(let e=0;e<t.length;++e){const s=t[e];if(!((0,a.isInteger)(s.pointIndex)&&h.linePointBeingEdited===s.pointIndex)){d.fillStyle=i[e];if(o(d,{...s,point:new n.Point(Math.round(s.point.x*l)+x,Math.round(s.point.y*c)+x)},g/2,_),!h.disableInteractions){if(null!==h.hoveredPointIndex&&s.pointIndex===h.hoveredPointIndex){const e=Math.max(1,Math.floor(h.selectedStrokeWidth*l));let t=Math.round(u*l*2);t%2!=p%2&&(t+=1);r(d,{...s,point:new n.Point(Math.round(s.point.x*l)+x,Math.round(s.point.y*c)+x)},t/2,e)}}}}}}function P(e,t=e.pointIndex,i,n,o,s,r,a,d,l){return{point:e,pointIndex:t,cursorType:i,square:n,hitTarget:o,snappingPrice:s,snappingIndex:r,nonDiscreteIndex:a,activeItem:d,possibleMovingDirections:l}}function m(e){return P(e.point,e.pointIndex,e.cursorType,e.square,e.hitTarget,e.snappingPrice,e.snappingIndex,e.nonDiscreteIndex,e.activeItem,e.possibleMovingDirections)}function S(e){return P(e)}}}]);