3 lines
6.9 KiB
JavaScript
3 lines
6.9 KiB
JavaScript
"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[7692],{75071:(e,t,i)=>{i.r(t),i.d(t,{LineToolImage:()=>W,OriginPoints:()=>T});var n=i(85842),r=i(57415),s=i(73775),o=i(89659),a=i(93445),l=i(22384),u=i(82014),h=i(9840),c=i(82287),d=i(64906),g=i(66863),p=i(43312),m=i(91599),_=i(45958),b=i(23351),f=i(16905);const P=m.t(null,void 0,i(25488));var v=i(98059),w=i(54951);async function S(e,t){return async function(e){const[t]=await Promise.all([Promise.all([i.e(6759),i.e(3159),i.e(4219),i.e(7356),i.e(7039),i.e(2593),i.e(6651),i.e(4551),i.e(7839),i.e(6266),i.e(9224),i.e(1709),i.e(9365),i.e(7557),i.e(5088),i.e(7877)]).then(i.bind(i,97193))]);return t.renderImageDialog(e)}({onConfirm:e,onClose:t})}let C=null;function U(e){if("LineToolImage"!==e)return C?.then((e=>e())),void(C=null);(0,p.runOrSigninWithFeature)((()=>{const e="LineToolImage";w.tool.setValue(e),(0,g.trackDrawingToolSelected)(e,"Left panel"),C=S(I,(()=>{C?.then((e=>e())),C=null,w.tool.value()===e&&(0,w.resetToCursor)(!0)})),(0,d.trackEvent)("Image","Open image dialog")}),{feature:"drawings",source:"Change drawing tool state"})}function I(e){const t=(0,v.chartWidgetCollectionService)();if(null===t)return;const r=!Boolean(c.getBool("hint.pasteImage")),s=t.activeChartWidget.value();var o,a;s.model().pasteImageAsLineTool(e.url,e.blobUrl,(0,n.ensureNotNull)(s.model().model().paneForSource(s.model().mainSeries())),e.transparency),r&&(o=t.getContainer(),a="hint.pasteImage",(0,f.isFeaturesetEnabled)("popup_hints")&&!_.CheckMobile.any()&&Promise.all([i.e(6498),i.e(7201),i.e(9365),i.e(7588)]).then(i.bind(i,41688)).then((e=>{const t=new e.ChartEventHintRenderer(o),i=P.format({shortcut:(0,b.humanReadableHash)(b.Modifiers.Mod+86)});let n=null;t.show(i,(()=>{null!==n&&(clearTimeout(n),n=null,c.setValue(a,!0,{forceFlush:!0}))})),n=setTimeout((()=>{n=null,t.hide()}),5e3)})))}const y=(0,s.getLogger)("Chart.LineToolImage");var T;function L(e){return e.toLowerCase().startsWith("blob:")}function N(e){return e.toLowerCase().startsWith("data:")}!function(e){e[e.LeftTopAnchor=0]="LeftTopAnchor",e[e.RightTopAnchor=1]="RightTopAnchor",e[e.LeftBottomAnchor=2]="LeftBottomAnchor",e[e.RightBottomAnchor=3]="RightBottomAnchor",e[e.Center=4]="Center"}(T||(T={}));const x=window.AWS_BBS3_DOMAIN;function O(e){return L(e)||N(e)?e:null}function V(e){const t=new URL(e,x),i=new URL(t.pathname,x);return"/"!==i.pathname&&t.toString()===i.toString()}function M(e){return N(e)?e:new URL(e).pathname}class W extends u.LineDataSource{constructor(e,t,n,r){super(e,t||W.createProperties(e.backgroundTheme().spawnOwnership()),n,r),this._hasEditableCoordinates=new o.WatchedValue(!1),this._image=null,this._originPoint=4,this._absoluteUserImageUrl=new l.Property(""),this._bindAbsoluteUserImageUrlPropertyToUrlProperty(),this._loadImage(),Promise.all([i.e(8263),i.e(144),i.e(4073),i.e(1912),i.e(1495)]).then(i.bind(i,60428)).then((({ImagePaneView:t})=>{this._setPaneViews([new t(this,e)])}))}absoluteUserImageUrl(){return this._absoluteUserImageUrl}cssWidth(){
|
|
return this.properties().childs().cssWidth.value()}cssHeight(){return this.properties().childs().cssHeight.value()}angle(){return this.properties().childs().angle.value()}originPoint(){return this._originPoint}dOffsetX(){return this._dOffsetX||0}pointsCount(){return 1}name(){return"Image"}image(){return this._image}setBlobImageUrl(e){this._image}getChangePointForSync(e){return null}pointToScreenPoint({index:e,price:t},i,s){const o=this._model.timeScale(),a=(0,n.ensureNotNull)(i?i.priceScale():this.priceScale()),l=(0,n.ensure)((i??this.ownerSource())?.firstValue()),u=o.indexToCoordinate(e)+(s??0),h=a.priceToCoordinate(t,l);return new r.Point(u,h)}setPoint(e,t,i){if(null===this._image)return;const{width:r,height:s}=this._image,o=(0,n.ensureNotNull)(this.pointToScreenPoint(t)),a=(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[0],void 0,this.dOffsetX())),l=Math.max(Math.abs(a.x-o.x)/r,Math.abs(a.y-o.y)/s),u=Math.round(r*l),h=Math.round(s*l),c=this.properties().childs();c.cssWidth.setValue(u),c.cssHeight.setValue(h),this.propertiesChanged()}startChanging(e,t){super.startChanging(e,t),this._changeOriginPoint(W._oppositePoints[e])}endChanging(e,t){return this._changeOriginPoint(4),super.endChanging(e,t)}getPoint(){return null}syncLineStyleState(){const e=super.syncLineStyleState();return!e.url&&this._blobUrl&&(e.blobUrl=this._blobUrl),e}restoreExternalState(e){const{blobUrl:t,...i}=e;t&&this.setBlobImageUrl(t),super.restoreExternalState(i)}isSavedInChart(){return super.isSavedInChart()&&""!==this.absoluteUserImageUrl().value()}static createProperties(e,t){const i=new a.DefaultProperty({defaultName:"linetoolimage",state:t,theme:e});return this._configureProperties(i),i}async _getPropertyDefinitionsViewModelClass(){return(await Promise.all([i.e(1982),i.e(7686),i.e(2428),i.e(3920),i.e(9328)]).then(i.bind(i,22251))).ImageDefinitionsViewModel}static _configureProperties(e){super._configureProperties(e),e.hasChild("url")||e.addChild("url",new l.Property("")),e.addExcludedKey("url",1),e.addExcludedKey("cssWidth",1),e.addExcludedKey("cssHeight",1),e.addExcludedKey("angle",1)}_loadImage(){const e=this.properties(),t=(0,n.ensureDefined)(e.child("url")).value();if(t){const e=O(t);e&&V(e)?this._createImage(e):y.logWarn(`Invalid image URL: ${t}`)}}_changeOriginPoint(e){const t=this.originPoint(),i=4===t?W._correctOriginDirections[e]:W._correctOriginDirections[W._oppositePoints[t]],s=this.properties().childs().cssWidth.value()/2,o=this.properties().childs().cssHeight.value()/2,[a]=this._points,l=(0,n.ensureNotNull)(this.pointToScreenPoint(a)),u=new r.Point(l.x+s*i[0],l.y+o*i[1]),h=(0,n.ensureNotNull)(this.screenPointToPoint(u));this._dOffsetX=4===t?u.x-(0,n.ensureNotNull)(this.pointToScreenPoint(h)).x:void 0,a.index=h.index,a.price=h.price,this._originPoint=e}_createImage(e){const t=document.createElement("img");t.crossOrigin="anonymous",t.src=e,t.addEventListener("load",(()=>{this._image=t;const i=this.properties().childs();if(!L(e)){const t=M(e);i.url.setValue(t),this._blobUrl=void 0}
|
|
if(i.cssWidth.value()&&i.cssHeight.value())return void this._model.updateSource(this);const r=this._model.timeScale().width()/4,s=(0,n.ensureNotNull)(this.priceScale()).height()/4,o=t.naturalWidth,a=t.naturalHeight,l=Math.min(1,r/o),u=Math.min(1,s/a),c=Math.min(l,u),d=Math.round(c*o),g=Math.round(c*a);i.cssWidth.setValue(d),i.cssHeight.setValue(g),this.updateAllViews((0,h.sourceChangeEvent)(this.id())),this._model.updateSource(this)})),t.addEventListener("error",(()=>{this.model().removeSource(this)}))}_bindAbsoluteUserImageUrlPropertyToUrlProperty(){const e=this.properties().childs().url;e.subscribe(this,(()=>{const t=O(e.value());null!==t&&this._absoluteUserImageUrl.setValue(t)}));{const t=O(e.value());t&&V(t)&&this._absoluteUserImageUrl.setValue(t)}this._absoluteUserImageUrl.subscribe(this,(t=>{const i=t.value();if(L(i))return;const n=O(i);null!==n&&e.setValue(M(n))}))}}W._correctOriginDirections=[[-1,-1],[1,-1],[-1,1],[1,1],[0,0]],W._oppositePoints=[3,2,1,0,4],(0,w.runOnDrawingStateReady)((()=>{w.tool.subscribe(U)}))}}]); |