Files
ai/charting_library/bundles/line-tool-fib-spiral.7f2a02e712b2f4cc826e.js

6 lines
16 KiB
JavaScript

"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[8090],{73174:(e,t,i)=>{i.r(t),i.d(t,{getCoordinateXMetaInfo:()=>S,getCoordinateYMetaInfo:()=>P,getCoordinatesPropertiesDefinitions:()=>w,getSelectionCoordinatesPropertyDefinition:()=>x});var n=i(50151),o=i(11542),r=i(45126),s=i(44672),l=i(60265);class a extends l.UndoCommand{constructor({lineToolId:e,chartModel:t,newPositionPoints:i}){super(null),this._pointState=null,this._lineToolId=e,this._model=t,this._newPositionPoints=i}redo(){const e=(0,n.ensureNotNull)(this._model.dataSourceForId(this._lineToolId));this._pointState=[e.normalizedPoints(),e.points()],e.startChanging(),e.moveLineTool(this._newPositionPoints),this._model.updateSource(e),e.updateAllViews((0,s.sourceChangeEvent)(e.id())),e.syncMultichartState(e.endChanging(!0,!1))}undo(){if(this._pointState){const e=(0,n.ensureNotNull)(this._model.dataSourceForId(this._lineToolId));e.startChanging(),e.restorePoints(...this._pointState),this._model.updateSource(e),e.updateAllViews((0,s.sourceChangeEvent)(e.id())),e.syncMultichartState(e.endChanging(!0,!1))}}}var c=i(32097),d=i(64147),h=i(12988),u=i(91682);const p=-5e4,_=15e3,g=new r.TranslatedString("change price Y coordinate",o.t(null,void 0,i(11737))),f=new r.TranslatedString("change bar X coordinate",o.t(null,void 0,i(2066))),m=new r.TranslatedString("move drawings",o.t(null,void 0,i(76261)));function P(e,t,i){return{property:(0,c.convertToDefinitionProperty)(e,t.price,g),info:{typeY:1,stepY:i}}}function S(e,t){return{property:(0,c.convertToDefinitionProperty)(e,t.bar,f),info:{typeX:0,minX:new d.WatchedValue(p),maxX:new d.WatchedValue(_),stepX:new d.WatchedValue(1)}}}function w(e,t,i,n,o,r){const s=S(e,t),l=P(e,t,n);return(0,c.createCoordinatesPropertyDefinition)({x:s.property,y:l.property},{id:(0,u.removeSpaces)(`${r}Coordinates${o}`),title:o,...s.info,...l.info})}const y=/^([+*\-\/]?)((?:\d*)|(?:\d+\.\d*))$/;function T(e,t,i){const o=new h.Property(""),r=(0,c.makeProxyDefinitionProperty)(o.weakReference());return r.setValue=r=>{try{const o=r.match(y);if(!o)return;const[,s,l]=o;if(!l.length)return;const c=i(parseFloat(l));if("/"===s&&(0===c.price||0===c.index))return;t.withMacro(m,(()=>{e.filter((e=>!e.isSourceHidden())).forEach((e=>{const i=e.points();let o;switch(s){case"":{const e=(0,n.ensureDefined)(i[0]);let{index:t=e.index,price:r=e.price}=c;r-=e.price,t-=e.index,o=i.map((e=>({...e,index:e.index+t,price:e.price+r})));break}case"-":case"+":{let{index:e=0,price:t=0}=c;"-"===s&&(e*=-1,t*=-1),o=i.map((i=>({...i,index:i.index+e,price:i.price+t})));break}case"*":{const{index:e=1,price:t=1}=c;o=i.map((i=>({...i,index:i.index*e,price:i.price*t})));break}case"/":{const{index:e=1,price:t=1}=c;o=i.map((i=>({...i,index:i.index/e,price:i.price/t})));break}}t.undoHistory().pushUndoCommand(new a({lineToolId:e.id(),chartModel:t.model(),newPositionPoints:o}))}))}))}finally{o.setValue("",!0)}},r}function x(e,t){const n=T(e,t,(e=>({index:e}))),r=T(e,t,(e=>({price:e})));return(0,c.createSelectionCoordinatesPropertyDefinition)({x:n,y:r},{
id:"SourcesCoordinates",title:o.t(null,void 0,i(44272)),mathOperationsX:"+",mathOperationsY:"+/*",modeX:"integer",modeY:"float"})}},22717:(e,t,i)=>{i.r(t),i.d(t,{LineToolFibSpiral:()=>K});var n=i(29875),o=i(19625),r=i(50151),s=i(24633),l=i(51056),a=i(31229),c=i(6590),d=i(32679),h=i(11402),u=i(38039),p=i(73305);const _={intervalsVisibilities:{...a.intervalsVisibilitiesDefaults},counterclockwise:!1,linewidth:2,linestyle:l.LINESTYLE_SOLID},g={linecolor:(0,o.getHexColorByName)("color-sky-blue-500")},f=new Map([[s.StdTheme.Light,g],[s.StdTheme.Dark,g]]),m=(0,d.extractThemedColors)((0,r.ensureDefined)(f.get(s.StdTheme.Light)),(0,r.ensureDefined)(f.get(s.StdTheme.Dark))),P=(0,d.extractAllPropertiesKeys)((0,r.ensureDefined)(f.get(s.StdTheme.Light))),S=(0,d.extractAllPropertiesKeys)(_),w=[...new Set([...P,...S,...c.commonLineToolPropertiesStateKeys])];class y extends u.LineDataSourceProperty{constructor(e){super(e),this.addChild("linesColors",new p.LineToolColorsProperty([(0,r.ensureDefined)(this.child("linecolor"))])),this.addChild("linesWidths",new p.LineToolWidthsProperty([(0,r.ensureDefined)(this.child("linewidth"))]))}static create(e,t){return new this({defaultName:"linetoolfibspiral",factoryDefaultsSupplier:()=>(0,h.factoryDefaultsForCurrentTheme)(_,f),nonThemedDefaultsKeys:S,themedDefaultsKeys:P,allStateKeys:w,themedColors:m,replaceThemedColorsOnThemeChange:!0,state:t,theme:e})}}var T=i(95201),x=i(49857),v=i(91046),k=i(27916),C=i(56468),M=i(37743),R=i(61993),I=i(75919);const b=[0,1,2,3,5,8,13,21,34,55,89];class D extends I.MediaCoordinatesPaneRenderer{constructor(){super(...arguments),this._data=null}setData(e){this._data=e}hitTest(e){if(null===this._data||this._data.points.length<2)return null;const t=this._data.points[0],i=this._data.points[1].subtract(t),n=e.subtract(t),o=i.normalized(),r=o.transposed(),s=n.normalized();let l=Math.acos(o.dotProduct(s));Math.asin(r.dotProduct(s))<0&&(l=2*Math.PI-l);const a=this._data.counterclockwise?-1:1,c=n.length(),d=(0,R.interactionTolerance)().curve;for(let e=0;e<4;e++){const t=a*l/(.5*Math.PI);let n=this._continiusFib(t+4*e);if(null!==n&&(n=n*i.length()/5,Math.abs(n-c)<d))return new C.HitTestResult(C.HitTarget.MovePoint)}return null}_drawImpl(e){if(null===this._data||this._data.points.length<2)return;const t=e.context;t.lineCap="round",t.strokeStyle=this._data.color;const i=this._data.points[0],n=this._data.points[1];t.translate(i.x,i.y);let o=n.subtract(i);const r=o.length();o=o.normalized();let s=Math.acos(o.x);Math.asin(o.y)<0&&(s=2*Math.PI-s),t.rotate(s),t.scale(r/5,r/5),t.lineWidth=this._data.linewidth,(0,M.setLineStyle)(t,this._data.linestyle);const l=Math.PI/100;t.moveTo(0,0);const a=this._data.counterclockwise?-1:1;for(let e=0;e<50*(b.length-1);e++){const i=a*e*l,n=this._continiusFib(e/50);if(null===n)break;const o=Math.cos(i)*n,r=Math.sin(i)*n;t.lineTo(o,r)}t.scale(5/r,5/r),t.rotate(-s),t.stroke()}_continiusFib(e){const t=Math.floor(e),i=Math.ceil(e);if(i>=b.length)return null;let n=e-t;n=Math.pow(n,1.15);return b[t]+(b[i]-b[t])*n}}class A extends k.LineSourcePaneView{
constructor(){super(...arguments),this._trendLineRenderer=new v.TrendLineRenderer,this._spiralRenderer=new D,this._renderer=null}renderer(e){return this._invalidated&&this._updateImpl(e),this._renderer}_updateImpl(e){if(super._updateImpl(e),this._renderer=null,this._points.length<2)return;const t=new T.CompositeRenderer,i=this._source.properties().childs();{const e={points:[this._points[0],this._points[1]],color:i.linecolor.value(),linewidth:i.linewidth.value(),linestyle:i.linestyle.value(),extendleft:!1,extendright:!0,leftend:x.LineEnd.Normal,rightend:x.LineEnd.Normal};this._trendLineRenderer.setData(e),t.append(this._trendLineRenderer)}{const e={points:this._points,color:i.linecolor.value(),linewidth:i.linewidth.value(),linestyle:i.linestyle.value(),counterclockwise:i.counterclockwise.value()};this._spiralRenderer.setData(e),t.append(this._spiralRenderer)}this.addAnchors(t),this._renderer=t}}var L=i(11542),W=i(45126),V=i(32097),E=i(18009),H=i(91682);const N=new W.TranslatedString("change {title} line color",L.t(null,void 0,i(7455))),B=new W.TranslatedString("change {title} line width",L.t(null,void 0,i(46040))),F=new W.TranslatedString("change {title} line style",L.t(null,void 0,i(30843))),z=new W.TranslatedString("change {title} counterclockwise",L.t(null,void 0,i(60003))),X=L.t(null,void 0,i(3554)),Y=L.t(null,void 0,i(33004));class O extends E.LineDataSourceDefinitionsViewModel{_stylePropertyDefinitions(){const e=this._source.properties().childs(),t=this._source.name(),i=(0,H.removeSpaces)(t),n=new W.TranslatedString(t,this._source.translatedType());return{definitions:[(0,V.createLinePropertyDefinition)({color:(0,V.getColorDefinitionProperty)(this._propertyApplier,e.linecolor,null,N.format({title:n})),width:(0,V.convertToDefinitionProperty)(this._propertyApplier,e.linewidth,B.format({title:n})),style:(0,V.convertToDefinitionProperty)(this._propertyApplier,e.linestyle,F.format({title:n}))},{id:`${i}Line`,title:X}),(0,V.createCheckablePropertyDefinition)({checked:(0,V.convertToDefinitionProperty)(this._propertyApplier,e.counterclockwise,z.format({title:n}))},{id:`${i}Counterclockwise`,title:Y})]}}}class K extends n.LineDataSource{constructor(e,t,i,n){super(e,t??K.createProperties(e.backgroundTheme().spawnOwnership()),i,n),this._setPaneViews([new A(this,e)])}pointsCount(){return 2}name(){return"Fib Spiral"}template(){return this._properties.template()}static createProperties(e,t){const i=y.create(e,t);return this._configureProperties(i),i}async _getPropertyDefinitionsViewModelClass(){return O}static _addCollectedProperties(e){}}},27916:(e,t,i)=>{i.d(t,{LineSourcePaneView:()=>g,createLineSourcePaneViewPoint:()=>_,thirdPointCursorType:()=>p});var n=i(19625),o=i(50151),r=i(69186),s=i(56468),l=i(11064),a=i(36036),c=i(72791),d=i(17330);const h=n.colorsPalette["color-tv-blue-600"];var u;function p(e,t){const i=t.x-e.x,n=t.y-e.y,o=Math.abs(Math.atan2(i,n));return o>Math.PI/4&&o<3*Math.PI/4?c.PaneCursorType.VerticalResize:c.PaneCursorType.HorizontalResize}function _(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 g{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(),n=null!==i?i.firstValue():null;return null===n?null:t.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,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));if(this.isLocked()){const n=this._getSelectionRenderer(t);return n.setData({bgColors:this._lineAnchorColors(i),points:e.points,visible:this.areAnchorsVisible(),hittestResult:s.HitTarget.Regular,barSpacing:this._model.timeScale().barSpacing()}),n}const n=(0,r.lastMouseOrTouchEventInfo)().isTouch,o=this._getLineAnchorRenderer(t),l=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return o.setData({...e,color:this.anchorColor(),backgroundColors:this._lineAnchorColors(i),hoveredPointIndex:l,linePointBeingEdited:this.isBeingEdited()?this._model.linePointBeingEdited():null,radius:this._anchorRadius(),strokeWidth:n?u.TouchStrokeWidth:u.RegularStrokeWidth,selected:this.isSelectedSource(),selectedStrokeWidth:n?u.TouchSelectedStrokeWidth:u.RegularSelectedStrokeWidth,visible:this.areAnchorsVisible(),clickHandler:e.clickHandler}),o}_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 i=this._source.pointToScreenPoint(e);i&&this._points.push(_(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,d.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 l.SelectionRenderer);return this._selectionRenderers[e]}_getLineAnchorRenderer(e){for(;this._lineAnchorRenderers.length<=e;)this._lineAnchorRenderers.push(new a.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},36036:(e,t,i)=>{i.d(t,{LineAnchorRenderer:()=>m,lineSourcePaneViewPointToLineAnchorPoint:()=>P,mapLineSourcePaneViewPointToLineAnchorPoint:()=>S});var n=i(86441),o=i(34026),r=i(50151),s=i(37743),l=i(37265),a=i(56468),c=i(72791),d=i(61993),h=i(30125);function u(e,t,i,n){const{point:o}=t,r=i+n/2;(0,s.drawRoundRect)(e,o.x-r,o.y-r,2*r,2*r,(i+n)/2),e.closePath(),e.lineWidth=n}function p(e,t,i,n){e.globalAlpha=.2,u(e,t,i,n),e.stroke(),e.globalAlpha=1}function _(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 f(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 m 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,d.interactionTolerance)().anchor;for(const t of i){if(t.point.subtract(e).length()<=n)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})}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 r=this._data.points[e],s=this._data.backgroundColors[e];r.square?(t.push(r),i.push(s)):(n.push(r),o.push(s))}t.length&&this._drawPoints(e,t,i,_,p),n.length&&this._drawPoints(e,n,o,f,g)}_drawPoints(e,t,i,o,s){const{context:a,horizontalPixelRatio:c,verticalPixelRatio:d}=e,h=(0,r.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 f=_%2/2;a.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)){a.fillStyle=i[e];if(o(a,{...r,point:new n.Point(Math.round(r.point.x*c)+f,Math.round(r.point.y*d)+f)},g/2,p),!h.disableInteractions){if(null!==h.hoveredPointIndex&&r.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,{...r,point:new n.Point(Math.round(r.point.x*c)+f,Math.round(r.point.y*d)+f)},t/2,e)}}}}}}function P(e,t=e.pointIndex,i,n,o,r,s,l,a,c){return{point:e,pointIndex:t,cursorType:i,square:n,hitTarget:o,snappingPrice:r,snappingIndex:s,nonDiscreteIndex:l,activeItem:a,possibleMovingDirections:c}}function S(e){return P(e)}}}]);