5 lines
13 KiB
JavaScript
5 lines
13 KiB
JavaScript
"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[5917],{34896:(e,t,o)=>{o.r(t),o.d(t,{LineToolTextNote:()=>pe});var i=o(11624),r=o(85842),n=o(47097),l=o(86684),a=o(88483),s=o(25432),d=o(93445),h=o(17567),c=o(86371),u=o(33993);const g={intervalsVisibilities:{...a.intervalsVisibilitiesDefaults},drawBackground:!0,drawBorder:!1,fontSize:14,bold:!1,italic:!1},p=new Map([[n.StdTheme.Light,{lineColor:l.colors.colorColdGray900,backgroundColor:l.colors.colorWhite,borderColor:l.colors.colorColdGray150,textColor:l.colors.colorColdGray900}],[n.StdTheme.Dark,{lineColor:l.colors.colorColdGray200,backgroundColor:l.colors.colorColdGray800,borderColor:l.colors.colorColdGray700,textColor:l.colors.colorColdGray200}]]),x=(0,d.extractThemedColors)((0,r.ensureDefined)(p.get(n.StdTheme.Light)),(0,r.ensureDefined)(p.get(n.StdTheme.Dark))),_=(0,d.extractAllPropertiesKeys)((0,r.ensureDefined)(p.get(n.StdTheme.Light))),f=(0,d.extractAllPropertiesKeys)(g),C=[...new Set([..._,...f,...s.commonLineToolPropertiesStateKeys,"text"])],b=[...new Set([..._,...f,"text"])];class T extends c.LineDataSourceProperty{constructor(e){super(e),this.hasChild("text")||this.addProperty("text",""),this.addChild("linesColors",new u.LineToolColorsProperty([(0,r.ensureDefined)(this.child("lineColor"))])),this.addChild("backgroundsColors",new u.LineToolColorsProperty([(0,r.ensureDefined)(this.child("backgroundColor"))])),this.addChild("textsColors",new u.LineToolColorsProperty([(0,r.ensureDefined)(this.child("textColor"))]))}static create(e,t){return new this({defaultName:"linetooltextnote",factoryDefaultsSupplier:()=>(0,h.factoryDefaultsForCurrentTheme)(g,p),nonThemedDefaultsKeys:f,themedDefaultsKeys:_,allStateKeys:C,themedColors:x,templateKeys:b,replaceThemedColorsOnThemeChange:!0,state:t,theme:e})}}var v=o(63212),y=o(11284),m=o(31048),D=o(14491),w=o(99680),P=o(8165),R=o(7919),S=o(7955),L=o(57415),A=o(91069),M=o(17086),k=o(81458),H=o(57507),B=o(83077),z=o(51946),I=o(72244),V=o(61208),N=o(95385),E=o(60525),W=o(16905);var O,F,G=o(52612);function K(e){return(0,W.isFeaturesetEnabled)("text-note-align-anchor-to-corner")?function(e){let t,o;return e>=-180&&e<-90?(t=N.HorizontalAlign.Right,o=N.VerticalAlign.Bottom):e>=-90&&e<=0?(t=N.HorizontalAlign.Left,o=N.VerticalAlign.Bottom):e>0&&e<=90?(t=N.HorizontalAlign.Left,o=N.VerticalAlign.Top):(t=N.HorizontalAlign.Right,o=N.VerticalAlign.Top),{horzAlign:t,vertAlign:o}}(e):(0,G.alignByAngle)(e)}!function(e){e[e.Label=1]="Label"}(O||(O={})),function(e){e[e.CircleRadius=2]="CircleRadius",e[e.RoundRectRadius=4]="RoundRectRadius",e[e.LabelVertPadding=6]="LabelVertPadding",e[e.LabelHorzPadding=8]="LabelHorzPadding",e[e.TextMargins=2]="TextMargins",e[e.Blur=4]="Blur",e[e.ShadowOffsetY=2]="ShadowOffsetY"}(F||(F={}));class Y extends H.BitmapCoordinatesPaneRenderer{constructor(e){super(),this._data=null,this._textLabelRenderer=new V.TextRenderer,this._textInfoCache=null,this._lineHitTest=new B.HitTestResult(B.HitTarget.MovePoint),this._textHitTest=e||new B.HitTestResult(B.HitTarget.MovePoint,{
|
|
areaName:B.AreaName.Text}),this._textHitTest.mergeData({activeItem:O.Label})}setData(e){null===this._data||this._data.textData.text===e.textData.text&&this._data.textData.fontSize===e.textData.fontSize||(this._textInfoCache=null),this._data=e;const t=e.points[1];this._textLabelRenderer.setData({horzAlign:N.HorizontalAlign.Left,vertAlign:N.VerticalAlign.Middle,points:[t],text:e.textData.text||" ",color:e.textData.color,font:D.CHART_FONT_FAMILY,fontSize:e.textData.fontSize,bold:e.textData.bold,italic:e.textData.italic,offsetX:0,offsetY:0,borderColor:e.drawBorder?e.borderColor:void 0,borderWidth:1,backgroundColor:e.drawBackground?e.backgroundColor:void 0,backgroundRoundRect:F.RoundRectRadius,boxPaddingVert:F.LabelVertPadding,boxPaddingHorz:F.LabelHorzPadding,boxShadow:e.drawBorder||e.drawBackground?{shadowColor:e.shadowColor,shadowBlur:F.Blur,shadowOffsetY:F.ShadowOffsetY}:void 0,selectionHighlight:e.textData.selectionHighlight});const o=this._textLabelRenderer.rect(),i=e.points[0],r=e.points[1],n=K(Math.round(180*Math.atan2(r.y-i.y,r.x-i.x)/Math.PI));let l=e.points[1];switch(n.horzAlign){case N.HorizontalAlign.Center:l=l.add((0,L.point)(.5*-o.width,0));break;case N.HorizontalAlign.Right:l=l.add((0,L.point)(-o.width,0))}switch(n.vertAlign){case N.VerticalAlign.Top:l=l.add((0,L.point)(0,.5*o.height));break;case N.VerticalAlign.Bottom:l=l.add((0,L.point)(0,.5*-o.height))}this._textLabelRenderer.setPoint(l)}setCursorType(e){this._textHitTest.mergeData({cursorType:e})}hitTest(e){const t=this._data;if(null===t||t.points.length<2)return null;const o=(0,I.interactionTolerance)().line+.5,i=t.points[0],r=t.points[1];if((0,M.distanceToSegment)(i,r,e).distance<=o)return this._lineHitTest;const n=this._textLabelRenderer.rect(),l=(0,L.box)((0,L.point)(n.x,n.y),(0,L.point)(n.x+n.width,n.y+n.height));return(0,A.pointInBox)(e,l)?this._textHitTest:null}getTextInfo(){const e=(0,r.ensureNotNull)(this._data),t=(0,k.isRtl)()?"right":"left",o=F.RoundRectRadius,i=F.TextMargins,n=(0,r.ensureNotNull)(this._calcTextSize()),l=this._textLabelRenderer.rect(),a=(0,r.ensureDefined)(this._textLabelRenderer.data()?.points?.[0]).add((0,L.point)(0,.5*-l.height)),{totalWidth:s,totalHeight:d}=n,h=o+i;return{font:e.textData.font,fontSize:e.textData.fontSize,lineHeight:Math.ceil(e.textData.fontSize),lineSpacing:0,textTop:a.y+h,textBottom:a.y+d-h,textLeft:a.x+h,textRight:a.x+s-h,textAlign:t}}positionToCoordinate(e,t){const o=(0,r.ensureNotNull)(this._data),i=this.getTextInfo(),n=this._textLabelRenderer.getLinesInfo(),{x:l,y:a,lineNumber:s}=(0,E.getSymbolCoordinatesInfo)({symbolPosition:t,textWidth:i.textRight-i.textLeft,textByLines:n.linesIncludingHidden,lineHeight:o.textData.fontSize,font:i.font,textAlign:i.textAlign});return{x:l+i.textLeft,y:a+i.textTop,lineNumber:s}}_drawImpl(e){const t=this._data;if(null===t||t.points.length<2)return;const{context:o}=e,i=t.points[0];let r=t.points[1];if((0,W.isFeaturesetEnabled)("text-note-align-anchor-to-corner")){const e=Math.atan2(r.y-i.y,r.x-i.x);r=r.add(new L.Point(2*Math.cos(e),2*Math.sin(e)))}
|
|
o.strokeStyle=t.lineColor,o.lineWidth=Math.max(1,Math.floor(e.horizontalPixelRatio)),o.beginPath();const[n,l]=(0,z.addPixelPerfectLineToPath)(o,i.x,i.y,r.x,r.y,e);o.stroke();const a=Math.round(F.CircleRadius*e.horizontalPixelRatio);o.fillStyle=t.lineColor,o.beginPath(),o.arc(n,l,a,0,2*Math.PI,!1),o.fill(),o.beginPath(),o.strokeStyle=t.circleBorderColor,o.lineWidth=1;const s=Math.round(F.CircleRadius*e.horizontalPixelRatio+.5*e.horizontalPixelRatio);o.arc(n,l,s,0,2*Math.PI,!1),o.stroke(),this._textLabelRenderer.draw(o,e)}_calcTextSize(){if(null===this._data||this._data.points.length<2)return null;if(null===this._textInfoCache){const e=this._textLabelRenderer.getLinesInfo(),t=this._data.textData.fontSize*e.lines.length,o=e.linesMaxWidth,i=F.RoundRectRadius,r=2*F.TextMargins+2*i;this._textInfoCache={textWidth:o,textHeight:t,totalWidth:o+r,totalHeight:t+r}}return this._textInfoCache}}var $=o(82347);const X=(0,$.generateColor)((0,y.getHexColorByName)("color-black"),80),j=(0,$.generateColor)((0,y.getHexColorByName)("color-black"),60);class q extends R.InplaceTextLineSourcePaneView{constructor(e,t,o,i){super(e,t,o,i),this._renderer=new w.CompositeRenderer,this._noteRenderer=new Y(new B.HitTestResult(B.HitTarget.MovePoint,(0,S.inplaceEditHandlers)(this._tryActivateEditMode.bind(this,null)))),this._source.setAdditionalCursorData((()=>({color:this._source.editableTextStyle().cursorColor,...this._noteRenderer.getTextInfo()})),this._noteRenderer.positionToCoordinate.bind(this._noteRenderer,!0))}renderer(e){return this._invalidated&&this._updateImpl(e),this._renderer}_updateImpl(e){super._updateImpl(e),this._renderer.clear();const t=this._source.priceScale();if(!t||t.isEmpty())return;const o=this._points;if(o.length<2)return;if(null===(0,r.ensureNotNull)(this._source.ownerSource()).firstValue())return;const i=this._source.properties().childs(),n=this._model.dark().value()?l.colors.colorColdGray850:l.colors.colorWhite,a=this._model.dark().value()?j:X,s=i.fontSize.value(),d=i.bold.value(),h=i.italic.value(),c={textData:{font:(0,m.makeFont)(s,D.CHART_FONT_FAMILY,h?"italic":"",d?"bold":""),fontSize:s,text:this._textData(),color:this._textColor(),bold:d,italic:h,selectionHighlight:this._inplaceTextHighlight().selectionHighlight},shadowColor:a,points:o,lineColor:i.lineColor.value(),drawBackground:i.drawBackground.value(),drawBorder:i.drawBorder.value(),backgroundColor:i.backgroundColor.value(),borderColor:i.borderColor.value(),circleBorderColor:n};this._renderer.append(this._noteRenderer),this._noteRenderer.setData(c),this._noteRenderer.setCursorType(this._textCursorType()),this._renderer.append(this.createLineAnchor({points:o.map(P.mapLineSourcePaneViewPointToLineAnchorPoint)},0)),this._updateInplaceText(this._noteRenderer.getTextInfo())}}var J=o(91599),Q=o(72769),U=o(2171),Z=o(44907),ee=o(73405),te=o(42897)
|
|
;const oe=new Q.TranslatedString("change {title} line color",J.t(null,void 0,o(69406))),ie=new Q.TranslatedString("change {title} background visibility",J.t(null,void 0,o(19514))),re=new Q.TranslatedString("change {title} background color",J.t(null,void 0,o(77582))),ne=new Q.TranslatedString("change {title} border visibility",J.t(null,void 0,o(15585))),le=new Q.TranslatedString("change {title} border color",J.t(null,void 0,o(5970))),ae=J.t(null,void 0,o(79115)),se=J.t(null,void 0,o(83354)),de=J.t(null,void 0,o(76760)),he=J.t(null,void 0,o(41198));class ce extends Z.LineDataSourceDefinitionsViewModel{_stylePropertyDefinitions(){const e=this._source.properties().childs(),t=this._source.name(),o=(0,te.removeSpaces)(t),i=new Q.TranslatedString(t,this._source.translatedType());return{definitions:[(0,ee.createColorPropertyDefinition)({checked:(0,ee.convertToDefinitionProperty)(this._propertyApplier,e.drawBackground,ie.format({title:i})),color:(0,ee.getColorDefinitionProperty)(this._propertyApplier,e.backgroundColor,null,re.format({title:i}))},{id:(0,te.removeSpaces)(`${t}BackgroundColor`),title:he}),(0,ee.createColorPropertyDefinition)({checked:(0,ee.convertToDefinitionProperty)(this._propertyApplier,e.drawBorder,ne.format({title:i})),color:(0,ee.getColorDefinitionProperty)(this._propertyApplier,e.borderColor,null,le.format({title:i}))},{id:(0,te.removeSpaces)(`${t}BorderColor`),title:de}),(0,ee.createColorPropertyDefinition)({color:(0,ee.getColorDefinitionProperty)(this._propertyApplier,e.lineColor,null,oe.format({title:i}))},{id:`${o}LineColor`,title:se})]}}_textPropertyDefinitions(){const{backgroundColor:e,borderColor:t,...o}=this._source.properties().childs();return{definitions:[(0,U.createTextStyleDefinition)(this._propertyApplier,{...o,textColor:o.textColor,fontSize:o.fontSize},new Q.TranslatedString(this._source.name(),this._source.translatedType()),{isEditable:!0,isMultiLine:!0,customTitles:{text:ae}})]}}}var ue=o(9840);class ge{constructor(e,t){this._labelMovingDelta=null,this._line=e,this._itemIndex=t}startMoving(e,t,o){if(t===this._itemIndex){if(this._line.isSourceHidden())return!0;const o=(0,r.ensureDefined)(e.logical),i=this._line.points()[1];return this._labelMovingDelta={index:i.index-o.index,price:i.price-o.price},this._line.startChanging(t,o),!0}return this._labelMovingDelta=null,!1}move(e,t,o){if(null!==this._labelMovingDelta){const t=(0,r.ensureDefined)(e.logical),i={index:t.index+this._labelMovingDelta.index,price:t.price+this._labelMovingDelta.price};return this._line.setPoint(1,i,o),this._line.updateAllViews((0,ue.sourceChangeEvent)(this._line.id())),!0}return!1}endMoving(e,t,o){return null!==this._labelMovingDelta?(this._labelMovingDelta=null,this._line.endChanging(!1,e)):null}}class pe extends v.InplaceTextLineDataSource{constructor(e,t,o,i){super(e,t??pe.createProperties(e.backgroundTheme().spawnOwnership()),o,i),this._moveAsChangeBehavior=new ge(this,O.Label),this._setPaneViews([new q(this,e,this._openTextEditor.bind(this),this._closeTextEditor.bind(this))])}pointsCount(){return 2}name(){
|
|
return"Note"}removeIfEditableTextIsEmpty(){return!0}activateEditingOnCreation(){return!0}shouldBeRemovedOnDeselect(){const e=this._properties.childs().text.value().trim();return this._points.length===this.pointsCount()&&""===e}editableTextProperties(){const e=this.properties().childs();return{text:e.text,textColor:e.textColor}}template(){return this._properties.template()}startMoving(e,t,o){this._moveAsChangeBehavior.startMoving(e,t,o)||super.startMoving(e,t,o)}move(e,t,o){this._moveAsChangeBehavior.move(e,t,o)||super.move(e,t,o)}endMoving(e,t,o){return this._moveAsChangeBehavior.endMoving(e,t,o)??super.endMoving(e,t,o)}snapTo45DegreesAvailable(){return!0}static createProperties(e,t){const o=T.create(e,t);return this._configureProperties(o),o}async _getPropertyDefinitionsViewModelClass(){return ce}_createDataSourceBackgroundColorWV(){return(0,i.convertPropertyToWatchedValue)(this.properties().childs().backgroundColor).ownership()}}}}]); |