6 lines
17 KiB
JavaScript
6 lines
17 KiB
JavaScript
"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[4013],{41928:(e,t,i)=>{i.d(t,{LineSourcePaneView:()=>S,anchorResizeCursorType:()=>_,createLineSourcePaneViewPoint:()=>g});var r=i(11284),o=i(85842),n=i(29968),s=i(83077),l=i(71367),a=i(8165),c=i(28031),d=i(61208);const h=r.colorsPalette["color-tv-blue-600"];var u,p;function _(e,t){const i=e.x-t.x,r=e.y-t.y;if(!Number.isFinite(i)||!Number.isFinite(r)||0===i&&0===r)return c.PaneCursorType.Default;let n=Math.atan2(r,i);return n<0&&(n+=2*Math.PI),n>=p.deg337_5||n<p.deg22_5||n>=p.deg157_5&&n<p.deg202_5?c.PaneCursorType.HorizontalResize:n>=p.deg22_5&&n<p.deg67_5||n>=p.deg202_5&&n<p.deg247_5?c.PaneCursorType.DiagonalNwSeResize:n>=p.deg67_5&&n<p.deg112_5||n>=p.deg247_5&&n<p.deg292_5?c.PaneCursorType.VerticalResize:n>=p.deg112_5&&n<p.deg157_5||n>=p.deg292_5&&n<p.deg337_5?c.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"}(p||(p={}));class S{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 r=null!==t?t.firstValue():null;return null===r?null:i.priceToCoordinate(e,r)}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 r=this._source.points(),o=i.map(((e,t)=>{const i=r[t],o=(0,a.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)),r=this._getOwnerSource();if(this.isLocked()){const o=this._getSelectionRenderer(t);return o.setData({bgColors:this._lineAnchorColors(i),points:e.points,visible:this.areAnchorsVisible(),
|
|
hittestResult:s.HitTarget.Regular,ownerSourceId:r?.id(),barSpacing:this._model.timeScale().barSpacing()}),o}const o=(0,n.lastMouseOrTouchEventInfo)().isTouch,l=this._getLineAnchorRenderer(t),a=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return l.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,ownerSourceId:r?.id()}),l}_getOwnerSource(){return this._ownerSource??this._source.ownerSource()}_anchorRadius(){return(0,n.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,d.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 l.SelectionRenderer);return this._selectionRenderers[e]}_getLineAnchorRenderer(e){for(;this._lineAnchorRenderers.length<=e;)this._lineAnchorRenderers.push(new a.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},19029:(e,t,i)=>{i.r(t),i.d(t,{LineToolPriceNote:()=>te});var r=i(85842),o=i(82014),n=i(11284),s=i(47097),l=i(95385),a=i(25432),c=i(33993),d=i(88483),h=i(93445),u=i(17567),p=i(86371);const _={intervalsVisibilities:{...d.intervalsVisibilitiesDefaults},horzLabelsAlign:l.HorizontalAlign.Center,vertLabelsAlign:l.VerticalAlign.Bottom,fontSize:14,bold:!1,italic:!1,priceLabelFontSize:12,priceLabelBold:!1,priceLabelItalic:!1},g=(0,n.getHexColorByName)("color-tv-blue-500"),S={lineColor:g,textColor:g,priceLabelBackgroundColor:g,priceLabelBorderColor:g,priceLabelTextColor:(0,n.getHexColorByName)("color-white")},P=new Map([[s.StdTheme.Light,S],[s.StdTheme.Dark,S]]),f=(0,h.extractThemedColors)((0,
|
|
r.ensureDefined)(P.get(s.StdTheme.Light)),(0,r.ensureDefined)(P.get(s.StdTheme.Dark))),b=(0,h.extractAllPropertiesKeys)((0,r.ensureDefined)(P.get(s.StdTheme.Light))),x=(0,h.extractAllPropertiesKeys)(_),m=[...new Set([...b,...x,...a.commonLineToolPropertiesStateKeys,"text"])],T=[...new Set([...b,...x,"text"])];class v extends p.LineDataSourceProperty{constructor(e){super(e),this.hasChild("text")||this.addProperty("text",""),this.addChild("linesColors",new c.LineToolColorsProperty([(0,r.ensureDefined)(this.child("lineColor"))])),this.addChild("backgroundsColors",new c.LineToolColorsProperty([(0,r.ensureDefined)(this.child("priceLabelBackgroundColor"))])),this.addChild("textsColors",new c.LineToolColorsProperty([(0,r.ensureDefined)(this.child("priceLabelTextColor"))]))}static create(e,t){return new this({defaultName:"linetoolpricenote",factoryDefaultsSupplier:()=>(0,u.factoryDefaultsForCurrentTheme)(_,P),nonThemedDefaultsKeys:x,themedDefaultsKeys:b,allStateKeys:m,themedColors:f,templateKeys:T,replaceThemedColorsOnThemeChange:!0,state:t,theme:e})}}var C,L,R=i(9840),w=i(57415),y=i(99680),M=i(61208),A=i(41928),I=i(8165),k=i(17086),D=i(80140),z=i(91903),B=i(14491),H=i(29968),W=i(83077),N=i(51946),V=i(72244),E=i(52612);!function(e){e[e.Label=1]="Label"}(C||(C={})),function(e){e[e.Tolerance=3]="Tolerance",e[e.TouchTolerance=20]="TouchTolerance",e[e.LineWidth=1]="LineWidth",e[e.CircleRadius=2]="CircleRadius",e[e.CircleStrokeWidth=1]="CircleStrokeWidth",e[e.BackgroundRoundRect=4]="BackgroundRoundRect",e[e.PriceLabelFontSize=12]="PriceLabelFontSize",e[e.LabelVertPadding=6]="LabelVertPadding",e[e.LabelHorzPadding=8]="LabelHorzPadding"}(L||(L={}));class F{constructor(){this._data=null,this._priceLabelRenderer=new M.TextRenderer(void 0,new W.HitTestResult(W.HitTarget.MovePoint,{areaName:W.AreaName.Style,activeItem:1})),this._hittest=new W.HitTestResult(W.HitTarget.MovePoint,{areaName:W.AreaName.Style})}setData(e){this._data=e;const t=e.points[0],i=e.points[1],r=Math.round(180*Math.atan2(i.y-t.y,i.x-t.x)/Math.PI);this._priceLabelRenderer.setData({...(0,E.alignByAngle)(r),points:[i],text:e.text,color:e.textColor,font:B.CHART_FONT_FAMILY,fontSize:e.fontSize,bold:e.bold,italic:e.italic,offsetX:0,offsetY:0,borderColor:e.borderColor,borderWidth:1,backgroundColor:e.backgroundColor,backgroundRoundRect:4,boxPaddingVert:6,boxPaddingHorz:8})}setHitTest(e){this._hittest=e}draw(e,t){const i=this._data;if(null===i||i.points.length<2)return;e.save();const{horizontalPixelRatio:r,verticalPixelRatio:o}=t,n=Math.round(i.points[0].x*r),s=Math.round(i.points[0].y*o),l=Math.round(i.points[1].x*r),a=Math.round(i.points[1].y*o);e.lineCap="round",(0,N.setLineStyle)(e,D.LINESTYLE_SOLID),e.strokeStyle=i.lineColor,e.fillStyle=i.lineColor,e.lineWidth=Math.round(1*r);const c=(0,V.fillScaledRadius)(2,r);(0,N.createCircle)(e,n,s,c),e.fill(),void 0!==i.excludeBoundaries&&(e.save(),(0,z.addExclusionArea)(e,t,i.excludeBoundaries)),(0,N.drawLine)(e,n,s,l,a),void 0!==i.excludeBoundaries&&e.restore(),this._priceLabelRenderer.draw(e,t);const d=1*r
|
|
;e.strokeStyle=i.circleBorderColor,e.lineWidth=d;const h=c+d/2;(0,N.createCircle)(e,n,s,h),e.stroke(),e.restore()}hitTest(e){const t=this._data;if(null===t)return null;const i=(0,H.lastMouseOrTouchEventInfo)().isTouch?20:3;return(0,k.distanceToSegment)(t.points[0],t.points[1],e).distance<=i?this._hittest:this._priceLabelRenderer.hitTest(e)}}class O extends A.LineSourcePaneView{constructor(){super(...arguments),this._renderer=new y.CompositeRenderer,this._priceNoteRenderer=new F,this._customLabelRenderer=new M.TextRenderer}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 i=this._points;if(i.length<2)return;const o=(0,r.ensureNotNull)(this._source.ownerSource()).firstValue();if(null===o)return;const s=this._source.properties().childs(),a=this._model.dark().value()?n.colorsPalette["color-cold-gray-900"]:n.colorsPalette["color-white"],c=this._source.points()[0].price,d={text:t.formatPrice(c,o),points:i,lineColor:s.lineColor.value(),circleBorderColor:a,backgroundColor:s.priceLabelBackgroundColor.value(),borderColor:s.priceLabelBorderColor.value(),textColor:s.priceLabelTextColor.value(),fontSize:s.priceLabelFontSize.value(),bold:s.priceLabelBold.value(),italic:s.priceLabelItalic.value()};{const t=i[0],r=i[1],o=t.x<r.x?t:r,n=o===t?r:t,a=s.vertLabelsAlign.value(),c=s.horzLabelsAlign.value();let h;h="left"===c?o.clone():"right"===c?n.clone():new w.Point((t.x+r.x)/2,(t.y+r.y)/2);const u=Math.atan((n.y-o.y)/(n.x-o.x)),p={points:[h],text:s.text.value(),color:s.textColor.value(),vertAlign:a,horzAlign:c,font:B.CHART_FONT_FAMILY,offsetX:0,offsetY:0,bold:s.bold.value(),italic:s.italic.value(),fontsize:s.fontSize.value(),forceTextAlign:!0,angle:u};if(this._customLabelRenderer.setData(p),this._renderer.append(this._customLabelRenderer),a===l.VerticalAlign.Middle){const{mediaSize:{width:t,height:i}}=e;d.excludeBoundaries=(0,M.getTextBoundaries)(this._customLabelRenderer,t,i)??void 0}}this._renderer.append(this._priceNoteRenderer),this._priceNoteRenderer.setData(d),this._renderer.append(this.createLineAnchor({points:i.map(I.mapLineSourcePaneViewPointToLineAnchorPoint)},0))}}var K=i(91599),Y=i(72769),q=i(2171),X=i(44907),$=i(73405),j=i(42897);const G=new Y.TranslatedString("change {title} line color",K.t(null,void 0,i(69406))),J=K.t(null,void 0,i(34834)),Q=K.t(null,void 0,i(83354)),U=K.t(null,void 0,i(76760)),Z=K.t(null,void 0,i(41198));class ee extends X.LineDataSourceDefinitionsViewModel{_stylePropertyDefinitions(){const e=this._source.properties().childs(),t=this._source.name(),i=(0,j.removeSpaces)(t),r=new Y.TranslatedString(t,this._source.translatedType()),o=(0,$.createColorPropertyDefinition)({color:(0,$.getColorDefinitionProperty)(this._propertyApplier,e.lineColor,null,G.format({title:r}))},{id:`${i}LineColor`,title:Q});return{definitions:[(0,q.createTextStyleDefinition)(this._propertyApplier,{textColor:e.priceLabelTextColor,fontSize:e.priceLabelFontSize,bold:e.priceLabelBold,
|
|
italic:e.priceLabelItalic,backgroundColor:e.priceLabelBackgroundColor,borderColor:e.priceLabelBorderColor},r,{isEditable:!1,isMultiLine:!1,customTitles:{text:J,borderTitle:U,backgroundTitle:Z}}),o]}}_textPropertyDefinitions(){const e=this._source.properties().childs();return{definitions:[(0,q.createTextStyleDefinition)(this._propertyApplier,{...e,textColor:e.textColor,fontSize:e.fontSize},new Y.TranslatedString(this._source.name(),this._source.translatedType()),{isEditable:!0,isMultiLine:!0})]}}}class te extends o.LineDataSource{constructor(e,t,i,r){super(e,t??te.createProperties(e.backgroundTheme().spawnOwnership()),i,r),this._labelMovingDelta=null,this._setPaneViews([new O(this,e)])}pointsCount(){return 2}name(){return"Price Note"}template(){return this._properties.template()}startMoving(e,t,i){if(1===t){if(this.isSourceHidden())return;const i=(0,r.ensureDefined)(e.logical),o=this.points()[1];this._labelMovingDelta={index:o.index-i.index,price:o.price-i.price},this.startChanging(t,i)}else this._labelMovingDelta=null,super.startMoving(e,t,i)}move(e,t,i){if(null!==this._labelMovingDelta){const t=(0,r.ensureDefined)(e.logical),o={index:t.index+this._labelMovingDelta.index,price:t.price+this._labelMovingDelta.price};this.setPoint(1,o,i),this.updateAllViews((0,R.sourceChangeEvent)(this.id()))}else super.move(e,t,i)}endMoving(e,t,i){return null!==this._labelMovingDelta?(this._labelMovingDelta=null,this.endChanging(!1,e)):super.endMoving(e,t,i)}snapTo45DegreesAvailable(){return!0}static createProperties(e,t){const i=v.create(e,t);return this._configureProperties(i),i}_normalizePoint(e,t){return 0===t?super._normalizePointWithoutOffset(e)??super._normalizePoint(e,t):super._normalizePoint(e,t)}async _getPropertyDefinitionsViewModelClass(){return ee}static _addCollectedProperties(e){}}},8165:(e,t,i)=>{i.d(t,{LineAnchorRenderer:()=>P,lineSourcePaneViewPointToLineAnchorPoint:()=>f,lineSourcePaneViewPointToLineAnchorPoint2:()=>b,mapLineSourcePaneViewPointToLineAnchorPoint:()=>x});var r=i(57415),o=i(91069),n=i(85842),s=i(51946),l=i(7321),a=i(83077),c=i(28031),d=i(72244),h=i(57507);function u(e,t,i,r){const{point:o}=t,n=i+r/2;(0,s.drawRoundRect)(e,o.x-n,o.y-n,2*n,2*n,(i+r)/2),e.closePath(),e.lineWidth=r}function p(e,t,i,r){e.globalAlpha=.2,u(e,t,i,r),e.stroke(),e.globalAlpha=1}function _(e,t,i,r){u(e,t,i-r,r),e.fill(),e.stroke()}function g(e,t,i,r){const{point:o}=t;e.globalAlpha=.2,e.beginPath(),e.arc(o.x,o.y,i+r/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=r,e.stroke(),e.globalAlpha=1}function S(e,t,i,r){const{point:o}=t;e.beginPath(),e.arc(o.x,o.y,i-r/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=r,e.fill(),e.stroke()}class P 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,r=t+(0,d.interactionTolerance)().anchor;for(const t of i){if(t.point.subtract(e).length()<=r)return new a.HitTestResult(t.hitTarget??a.HitTarget.ChangePoint,{areaName:a.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,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=[],r=[],o=[];for(let e=0;e<this._data.points.length;++e){const n=this._data.points[e],s=this._data.backgroundColors[e];n.square?(t.push(n),i.push(s)):(r.push(n),o.push(s))}t.length&&this._drawPoints(e,t,i,_,p),r.length&&this._drawPoints(e,r,o,S,g)}_drawPoints(e,t,i,o,s){const{context:a,horizontalPixelRatio:c,verticalPixelRatio:d}=e,h=(0,n.ensureNotNull)(this._data),u=h.radius;let p=Math.max(1,Math.floor((h.strokeWidth||2)*c));h.selected&&(p+=Math.max(1,Math.floor(c/2)));const _=Math.max(1,Math.floor(c));let g=Math.round(u*c*2);g%2!=_%2&&(g+=1);const S=_%2/2;a.strokeStyle=h.color;for(let e=0;e<t.length;++e){const n=t[e];if(!((0,l.isInteger)(n.pointIndex)&&h.linePointBeingEdited===n.pointIndex)){a.fillStyle=i[e];if(o(a,{...n,point:new r.Point(Math.round(n.point.x*c)+S,Math.round(n.point.y*d)+S)},g/2,p),!h.disableInteractions){if(null!==h.hoveredPointIndex&&n.pointIndex===h.hoveredPointIndex){const e=Math.max(1,Math.floor(h.selectedStrokeWidth*c));let t=Math.round(u*c*2);t%2!=_%2&&(t+=1);s(a,{...n,point:new r.Point(Math.round(n.point.x*c)+S,Math.round(n.point.y*d)+S)},t/2,e)}}}}}}function f(e,t=e.pointIndex,i,r,o,n,s,l,a,c){return{point:e,pointIndex:t,cursorType:i,square:r,hitTarget:o,snappingPrice:n,snappingIndex:s,nonDiscreteIndex:l,activeItem:a,possibleMovingDirections:c}}function b(e){return f(e.point,e.pointIndex,e.cursorType,e.square,e.hitTarget,e.snappingPrice,e.snappingIndex,e.nonDiscreteIndex,e.activeItem,e.possibleMovingDirections)}function x(e){return f(e)}}}]); |