5 lines
14 KiB
JavaScript
5 lines
14 KiB
JavaScript
"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[1313],{54707:(e,t,n)=>{n.d(t,{LineSourcePaneView:()=>P,anchorResizeCursorType:()=>_,createLineSourcePaneViewPoint:()=>g});var i=n(58978),o=n(50151),r=n(39612),s=n(2383),l=n(45801),d=n(73914),a=n(43838),c=n(4753);const h=i.colorsPalette["color-tv-blue-600"];var u,p;function _(e,t){const n=e.x-t.x,i=e.y-t.y;if(!Number.isFinite(n)||!Number.isFinite(i)||0===n&&0===i)return a.PaneCursorType.Default;let r=Math.atan2(i,n);return r<0&&(r+=2*Math.PI),r>=p.deg337_5||r<p.deg22_5||r>=p.deg157_5&&r<p.deg202_5?a.PaneCursorType.HorizontalResize:r>=p.deg22_5&&r<p.deg67_5||r>=p.deg202_5&&r<p.deg247_5?a.PaneCursorType.DiagonalNwSeResize:r>=p.deg67_5&&r<p.deg112_5||r>=p.deg247_5&&r<p.deg292_5?a.PaneCursorType.VerticalResize:r>=p.deg112_5&&r<p.deg157_5||r>=p.deg292_5&&r<p.deg337_5?a.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 P{constructor(e,t,n){this._invalidated=!0,this._points=[],this._middlePoint=null,this._selectionRenderers=[],this._lineAnchorRenderers=[],this._source=e,this._model=t,this._ownerSource=n??null}priceToCoordinate(e){const t=this._getOwnerSource(),n=t?.priceScale();if(null==n)return null;const i=null!==t?t.firstValue():null;return null===i?null:n.priceToCoordinate(e,i)}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 n=this._getPoints();this._model.lineBeingCreated()===this._source&&(n=n.slice(0,-1));const i=this._source.points(),o=n.map(((e,t)=>{const n=i[t],o=(0,d.lineSourcePaneViewPointToLineAnchorPoint)(e);return n&&(o.snappingPrice=n.price,o.snappingIndex=n.index),o}));e.append(this.createLineAnchor({...t,points:o},0))}createLineAnchor(e,t){const n=e.points.map((e=>e.point)),i=this._getOwnerSource();if(this.isLocked()){const o=this._getSelectionRenderer(t);return o.setData({bgColors:this._lineAnchorColors(n),points:e.points,visible:this.areAnchorsVisible(),
|
|
hittestResult:s.HitTarget.Regular,ownerSourceId:i?.id(),barSpacing:this._model.timeScale().barSpacing()}),o}const o=(0,r.lastMouseOrTouchEventInfo)().isTouch,l=this._getLineAnchorRenderer(t),d=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return l.setData({...e,color:this.anchorColor(),backgroundColors:this._lineAnchorColors(n),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:i?.id()}),l}_getOwnerSource(){return this._ownerSource??this._source.ownerSource()}_anchorRadius(){return(0,r.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 n=this._source.pointToScreenPoint(e,this._ownerSource??void 0);n&&this._points.push(g(n,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 n=this._source.properties().childs();return"middle"===(t??n.vertLabelsAlign.value())&&(0,c.needTextExclusionPath)(e)}_addAlertRenderer(e,t,n=this._source.properties().linecolor.value()){}_getAlertRenderer(e,t=this._source.properties().linecolor.value(),n){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 d.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},23712:(e,t,n)=>{n.r(t),n.d(t,{LineToolPitchfan:()=>w});var i=n(50151),o=n(11542),r=n(40226),s=n(95804),l=n(13896),d=n(41414),a=n(65045),c=n(87997),h=n(2383),u=n(39723),p=n(94602),_=n(73914),g=n(25672),P=n(80819),f=n(54707);class v extends f.LineSourcePaneView{constructor(){super(...arguments),this._medianRenderer=new P.TrendLineRenderer,this._sideRenderer=new P.TrendLineRenderer,this._renderer=null,this._medianPoint=null}renderer(e){return this._invalidated&&this._updateImpl(e),this._renderer}_updateImpl(e){super._updateImpl(e),this._renderer=null;const t=this._points.length;if(0===t)return;const[n]=this._points;if(this._medianPoint=(0,
|
|
_.lineSourcePaneViewPointToLineAnchorPoint)(3===t?this._points[1].add(this._points[2]).scaled(.5):2===t?this._points[1]:n,3),t<2)return;if(!this._medianPoint)return;const i=new p.CompositeRenderer,o=this._source.properties().childs(),r=o.median.childs(),s={points:[n,this._medianPoint.point],color:r.color.value(),linewidth:r.linewidth.value(),linestyle:r.linestyle.value(),extendleft:!1,extendright:!0,leftend:g.LineEnd.Normal,rightend:g.LineEnd.Normal};if(this._medianRenderer.setData(s),i.append(this._medianRenderer),t<3)return this.addAnchors(i),void(this._renderer=i);const l={points:[this._points[1],this._points[2]],color:r.color.value(),linewidth:r.linewidth.value(),linestyle:r.linestyle.value(),extendleft:!1,extendright:!1,leftend:g.LineEnd.Normal,rightend:g.LineEnd.Normal};this._sideRenderer.setData(l),i.append(this._sideRenderer);let d=0;const a=this._points[2].subtract(this._points[1]).scaled(.5),c=o.fillBackground.value(),f=o.transparency.value();for(let e=0;e<=8;e++){const t="level"+e,o=this._source.properties().child(t);if(o?.childs().visible.value()){const t=this._medianPoint.point.addScaled(a,o.childs().coeff.value()),r=this._medianPoint.point.addScaled(a,-o.childs().coeff.value());if(c){{const e={p1:n,p2:t,p3:n,p4:this._medianPoint.point.addScaled(a,d),color:o.childs().color.value(),transparency:f,hittestOnBackground:!0,extendLeft:!1},r=new u.ChannelRenderer;r.setData(e),i.append(r)}{const e={p1:n,p2:r,p3:n,p4:this._medianPoint.point.addScaled(a,-d),color:o.childs().color.value(),transparency:f,hittestOnBackground:!0,extendLeft:!1},t=new u.ChannelRenderer;t.setData(e),i.append(t)}}d=o.childs().coeff.value();{const r={points:[n,t],color:o.childs().color.value(),linewidth:o.childs().linewidth.value(),linestyle:o.childs().linestyle.value(),extendleft:!1,extendright:!0,leftend:g.LineEnd.Normal,rightend:g.LineEnd.Normal},s=new P.TrendLineRenderer;s.setData(r),s.setHitTest(new h.HitTestResult(h.HitTarget.MovePoint,void 0,e)),i.append(s)}{const t={points:[n,r],color:o.childs().color.value(),linewidth:o.childs().linewidth.value(),linestyle:o.childs().linestyle.value(),extendleft:!1,extendright:!0,leftend:g.LineEnd.Normal,rightend:g.LineEnd.Normal},s=new P.TrendLineRenderer;s.setData(t),s.setHitTest(new h.HitTestResult(h.HitTarget.MovePoint,void 0,e)),i.append(s)}}}this.addAnchors(i),this._renderer=i}}const S=new s.TranslatedString("erase level line",o.t(null,void 0,n(77114)));var m;!function(e){e[e.LevelsCount=8]="LevelsCount"}(m||(m={}));class w extends d.LineDataSource{constructor(e,t,n,i){super(e,t??w.createProperties(e.backgroundTheme().spawnOwnership()),n,i),this._setPaneViews([new v(this,this._model)])}levelsCount(){return 8}pointsCount(){return 3}name(){return"Pitchfan"}processErase(e,t){const n="level"+t,o=(0,i.ensureDefined)(this.properties().child(n)).childs().visible;e.setProperty(o,!1,S,l.lineToolsDoNotAffectChartInvalidation)}static createProperties(e,t){const n=new r.LevelsProperty({defaultName:"linetoolpitchfan",state:t,map:{range:[0,8]},theme:e});return this._configureProperties(n),n}
|
|
async _getPropertyDefinitionsViewModelClass(){return c.PitchBaseDefinitionsViewModel}static _configureProperties(e){super._configureProperties(e);const t=[e.childs().median.childs().linewidth],n=[e.childs().median.childs().color];for(let o=0;o<=8;o++){const r=(0,i.ensureDefined)(e.child("level"+o));t.push((0,i.ensureDefined)(r.child("linewidth"))),n.push((0,i.ensureDefined)(r.child("color")))}e.addChild("linesColors",new a.LineToolColorsProperty(n)),e.addChild("linesWidths",new a.LineToolWidthsProperty(t))}}},39723:(e,t,n)=>{n.d(t,{ChannelRenderer:()=>h});var i=n(50151),o=n(10555),r=n(6453),s=n(2624),l=n(2383),d=n(58221),a=n(52859),c=n(20820);class h extends c.MediaCoordinatesPaneRenderer{constructor(){super(...arguments),this._data=null}setData(e){this._data=e}hitTest(e,t){if(null===this._data||!this._data.hittestOnBackground)return null;const n=this._visiblePolygon(t.mediaSize);return null!==n&&(0,r.pointInPolygon)(e,n)?new l.HitTestResult(l.HitTarget.MovePointBackground):null}_drawImpl(e){if(null===this._data)return;const t=e.context,n=this._visiblePolygon(e.mediaSize);if(null!==n){t.beginPath(),t.moveTo(n[0].x,n[0].y);for(let e=1;e<n.length;e++)t.lineTo(n[e].x,n[e].y);t.fillStyle=(0,a.generateColor)(this._data.color,this._data.transparency,!0),t.fill()}}_visiblePolygon(e){const t=(0,i.ensureNotNull)(this._data),n=t.p1,r=t.p2,l=t.p3,a=t.p4;if((0,o.equalPoints)(n,r)||(0,o.equalPoints)(l,a)||(0,s.distanceToLine)(n,r,l).distance<1e-6&&(0,s.distanceToLine)(n,r,a).distance<1e-6)return null;if(e.width<=0||e.height<=0)return null;let c=[new o.Point(0,0),new o.Point(e.width,0),new o.Point(e.width,e.height),new o.Point(0,e.height)];return c=(0,d.clipPolygonByEdge)(c,n,r,[a,l]),c=(0,d.clipPolygonByEdge)(c,a,l,[n,r]),(0,o.equalPoints)(l,n)||t.extendLeft||(c=(0,d.clipPolygonByEdge)(c,l,n,[r,a])),c}}},73914:(e,t,n)=>{n.d(t,{LineAnchorRenderer:()=>f,lineSourcePaneViewPointToLineAnchorPoint:()=>v,lineSourcePaneViewPointToLineAnchorPoint2:()=>S,mapLineSourcePaneViewPointToLineAnchorPoint:()=>m});var i=n(10555),o=n(6453),r=n(50151),s=n(58221),l=n(87465),d=n(2383),a=n(43838),c=n(4539),h=n(10307);function u(e,t,n,i){const{point:o}=t,r=n+i/2;(0,s.drawRoundRect)(e,o.x-r,o.y-r,2*r,2*r,(n+i)/2),e.closePath(),e.lineWidth=i}function p(e,t,n,i){e.globalAlpha=.2,u(e,t,n,i),e.stroke(),e.globalAlpha=1}function _(e,t,n,i){u(e,t,n-i,i),e.fill(),e.stroke()}function g(e,t,n,i){const{point:o}=t;e.globalAlpha=.2,e.beginPath(),e.arc(o.x,o.y,n+i/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=i,e.stroke(),e.globalAlpha=1}function P(e,t,n,i){const{point:o}=t;e.beginPath(),e.arc(o.x,o.y,n-i/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=i,e.fill(),e.stroke()}class f 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:n}=this._data,i=t+(0,c.interactionTolerance)().anchor;for(const t of n){if(t.point.subtract(e).length()<=i)return new d.HitTestResult(t.hitTarget??d.HitTarget.ChangePoint,{
|
|
areaName:d.AreaName.AnchorPoint,pointIndex:t.pointIndex,cursorType:t.cursorType??a.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=[],n=[],i=[],o=[];for(let e=0;e<this._data.points.length;++e){const r=this._data.points[e],s=this._data.backgroundColors[e];r.square?(t.push(r),n.push(s)):(i.push(r),o.push(s))}t.length&&this._drawPoints(e,t,n,_,p),i.length&&this._drawPoints(e,i,o,P,g)}_drawPoints(e,t,n,o,s){const{context:d,horizontalPixelRatio:a,verticalPixelRatio:c}=e,h=(0,r.ensureNotNull)(this._data),u=h.radius;let p=Math.max(1,Math.floor((h.strokeWidth||2)*a));h.selected&&(p+=Math.max(1,Math.floor(a/2)));const _=Math.max(1,Math.floor(a));let g=Math.round(u*a*2);g%2!=_%2&&(g+=1);const P=_%2/2;d.strokeStyle=h.color;for(let e=0;e<t.length;++e){const r=t[e];if(!((0,l.isInteger)(r.pointIndex)&&h.linePointBeingEdited===r.pointIndex)){d.fillStyle=n[e];if(o(d,{...r,point:new i.Point(Math.round(r.point.x*a)+P,Math.round(r.point.y*c)+P)},g/2,p),!h.disableInteractions){if(null!==h.hoveredPointIndex&&r.pointIndex===h.hoveredPointIndex){const e=Math.max(1,Math.floor(h.selectedStrokeWidth*a));let t=Math.round(u*a*2);t%2!=_%2&&(t+=1);s(d,{...r,point:new i.Point(Math.round(r.point.x*a)+P,Math.round(r.point.y*c)+P)},t/2,e)}}}}}}function v(e,t=e.pointIndex,n,i,o,r,s,l,d,a){return{point:e,pointIndex:t,cursorType:n,square:i,hitTarget:o,snappingPrice:r,snappingIndex:s,nonDiscreteIndex:l,activeItem:d,possibleMovingDirections:a}}function S(e){return v(e.point,e.pointIndex,e.cursorType,e.square,e.hitTarget,e.snappingPrice,e.snappingIndex,e.nonDiscreteIndex,e.activeItem,e.possibleMovingDirections)}function m(e){return v(e)}}}]); |