4 lines
10 KiB
JavaScript
4 lines
10 KiB
JavaScript
"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[2211],{32211:(e,t,i)=>{i.d(t,{InplaceTextLineSourcePaneView:()=>_,inplaceEditHandlers:()=>u});var o=i(50151),n=i(11542),s=i(19063),r=i(91676),a=i(27916),l=i(56468),c=i(69186),h=i(72791);const d=n.t(null,void 0,i(6060));function u(e){const t=(t,i)=>{i.sourceWasSelected&&e(t)};return{areaName:l.AreaName.Text,executeDefaultAction:{doubleClickHandler:!0,doubleTapHandler:!0},clickHandler:t,tapHandler:t}}class _ extends a.LineSourcePaneView{constructor(e,t,i,o,n){super(e,t),this._textInfo=new r.WatchedObject({}),this._isTextEditModeActivated=!1,this._textWasEdited=!1,this._showTextEditor=i,this._hideTextEditor=o,this._onSelectionChangeCb=n,this._editableTextSpawn=this._source.editableText().spawn(),this._editableTextSpawn.subscribe((()=>this._updateTextWasEditable()))}destroy(){this._editableTextSpawn.destroy()}setSelectionRange(e){this._selectionRange=e}closeTextEditor(){this._textWasEdited=!1,this._isTextEditModeActivated=!1,this._hideTextEditor?.()}_placeHolderMode(e){return!this._isTextEditMode()&&this._model.hoveredSource()===this._source&&0===this._model.hoveredSourceOrigin()&&(!e||this._model.lastHittestData()?.areaName!==l.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)?h.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,o.ensureNotNull)(t.target instanceof HTMLElement?t.target.closest(".chart-gui-wrapper"):null);this._activateEditMode(i)}_isTextEditMode(){return this._isTextEditModeActivated}_textData(){return this._text()||(this._textWasEdited?"":d)}_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?.(e,this._textInfo,d,this.closeTextEditor.bind(this),(e=>this._onSelectionChangeCb?.(e))),this._isTextEditModeActivated=!0}_text(){return this._isTextEditMode()?this._source.editableText().value():this._source.editableTextProperties().text.value()}}},27916:(e,t,i)=>{i.d(t,{LineSourcePaneView:()=>x,createLineSourcePaneViewPoint:()=>p,thirdPointCursorType:()=>_});var o=i(19625),n=i(50151),s=i(69186),r=i(56468),a=i(11064),l=i(36036),c=i(72791),h=i(17330);const d=o.colorsPalette["color-tv-blue-600"];var u;function _(e,t){const i=t.x-e.x,o=t.y-e.y,n=Math.abs(Math.atan2(i,o))
|
||
;return n>Math.PI/4&&n<3*Math.PI/4?c.PaneCursorType.VerticalResize:c.PaneCursorType.HorizontalResize}function p(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={}));class x{constructor(e,t){this._invalidated=!0,this._points=[],this._middlePoint=null,this._selectionRenderers=[],this._lineAnchorRenderers=[],this._source=e,this._model=t}priceToCoordinate(e){const t=this._source.priceScale();if(null===t)return null;const i=this._source.ownerSource(),o=null!==i?i.firstValue():null;return null===o?null:t.priceToCoordinate(e,o)}anchorColor(){return d}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 o=this._source.points(),n=i.map(((e,t)=>{const i=o[t],n=(0,l.lineSourcePaneViewPointToLineAnchorPoint)(e);return i&&(n.snappingPrice=i.price,n.snappingIndex=i.index),n}));e.append(this.createLineAnchor({...t,points:n},0))}createLineAnchor(e,t){const i=e.points.map((e=>e.point));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,barSpacing:this._model.timeScale().barSpacing()}),o}const o=(0,s.lastMouseOrTouchEventInfo)().isTouch,n=this._getLineAnchorRenderer(t),a=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return n.setData({...e,color:this.anchorColor(),backgroundColors:this._lineAnchorColors(i),hoveredPointIndex:a,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}),n}_anchorRadius(){return(0,s.lastMouseOrTouchEventInfo)().isTouch?u.TouchAnchorRadius:u.RegularAnchorRadius}_lineAnchorColors(e){const t=(0,n.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);i&&this._points.push(p(i,t))})),
|
||
2===this._points.length&&(this._middlePoint=this._source.calcMiddlePoint(this._points[0],this._points[1])),this._invalidated=!1)}_validatePriceScale(){const e=this._source.priceScale();return null!==e&&!e.isEmpty()}_getSource(){return this._source}_getPoints(){return this._points}_getModel(){return this._model}_height(){const e=this._source.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,h.needTextExclusionPath)(e)}_addAlertRenderer(e,t,i=this._source.properties().linecolor.value()){}_getAlertRenderer(e,t=this._source.properties().linecolor.value(),i){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 l.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},36036:(e,t,i)=>{i.d(t,{LineAnchorRenderer:()=>S,lineSourcePaneViewPointToLineAnchorPoint:()=>T,mapLineSourcePaneViewPointToLineAnchorPoint:()=>P});var o=i(86441),n=i(34026),s=i(50151),r=i(37743),a=i(37265),l=i(56468),c=i(72791),h=i(61993),d=i(30125);function u(e,t,i,o){const{point:n}=t,s=i+o/2;(0,r.drawRoundRect)(e,n.x-s,n.y-s,2*s,2*s,(i+o)/2),e.closePath(),e.lineWidth=o}function _(e,t,i,o){e.globalAlpha=.2,u(e,t,i,o),e.stroke(),e.globalAlpha=1}function p(e,t,i,o){u(e,t,i-o,o),e.fill(),e.stroke()}function x(e,t,i,o){const{point:n}=t;e.globalAlpha=.2,e.beginPath(),e.arc(n.x,n.y,i+o/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=o,e.stroke(),e.globalAlpha=1}function g(e,t,i,o){const{point:n}=t;e.beginPath(),e.arc(n.x,n.y,i-o/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=o,e.fill(),e.stroke()}class S extends d.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,o=t+(0,h.interactionTolerance)().anchor;for(const t of i){if(t.point.subtract(e).length()<=o)return new l.HitTestResult(t.hitTarget??l.HitTarget.ChangePoint,{areaName:l.AreaName.AnchorPoint,pointIndex:t.pointIndex,cursorType:t.cursorType??c.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})}return null}doesIntersectWithBox(e){return null!==this._data&&this._data.points.some((t=>(0,n.pointInBox)(t.point,e)))}_drawImpl(e){if(null===this._data||!this._data.visible)return;const t=[],i=[],o=[],n=[];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)):(o.push(s),n.push(r))}t.length&&this._drawPoints(e,t,i,p,_),o.length&&this._drawPoints(e,o,n,g,x)}_drawPoints(e,t,i,n,r){
|
||
const{context:l,horizontalPixelRatio:c,verticalPixelRatio:h}=e,d=(0,s.ensureNotNull)(this._data),u=d.radius;let _=Math.max(1,Math.floor((d.strokeWidth||2)*c));d.selected&&(_+=Math.max(1,Math.floor(c/2)));const p=Math.max(1,Math.floor(c));let x=Math.round(u*c*2);x%2!=p%2&&(x+=1);const g=p%2/2;l.strokeStyle=d.color;for(let e=0;e<t.length;++e){const s=t[e];if(!((0,a.isInteger)(s.pointIndex)&&d.linePointBeingEdited===s.pointIndex)){l.fillStyle=i[e];if(n(l,{...s,point:new o.Point(Math.round(s.point.x*c)+g,Math.round(s.point.y*h)+g)},x/2,_),!d.disableInteractions){if(null!==d.hoveredPointIndex&&s.pointIndex===d.hoveredPointIndex){const e=Math.max(1,Math.floor(d.selectedStrokeWidth*c));let t=Math.round(u*c*2);t%2!=p%2&&(t+=1);r(l,{...s,point:new o.Point(Math.round(s.point.x*c)+g,Math.round(s.point.y*h)+g)},t/2,e)}}}}}}function T(e,t=e.pointIndex,i,o,n,s,r,a,l,c){return{point:e,pointIndex:t,cursorType:i,square:o,hitTarget:n,snappingPrice:s,snappingIndex:r,nonDiscreteIndex:a,activeItem:l,possibleMovingDirections:c}}function P(e){return T(e)}}}]); |