lit-litelements 2.2.6 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component/chart.lit.js +10 -3
- package/dist/main.js +1 -1
- package/package.json +1 -1
|
@@ -361,11 +361,18 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
361
361
|
color: (ctx) => {
|
|
362
362
|
const label = ctx.tick.label;
|
|
363
363
|
if (typeof label === "string") {
|
|
364
|
-
|
|
364
|
+
// Replace space with T to make it ISO-compliant
|
|
365
|
+
const safeLabel = label.includes(" ") ? label.replace(" ", "T") : label;
|
|
366
|
+
const labelDate = new Date(safeLabel);
|
|
367
|
+
// If the date is invalid, return default color
|
|
368
|
+
if (isNaN(labelDate.getTime()))
|
|
369
|
+
return "black";
|
|
370
|
+
// Compare date part only
|
|
365
371
|
const todayStr = new Date().toISOString().split("T")[0];
|
|
366
|
-
|
|
372
|
+
const labelStr = labelDate.toISOString().split("T")[0];
|
|
373
|
+
return labelStr === todayStr ? "Salmon" : "black";
|
|
367
374
|
}
|
|
368
|
-
return "black"; //
|
|
375
|
+
return "black"; // fallback for non-string labels
|
|
369
376
|
},
|
|
370
377
|
},
|
|
371
378
|
},
|
package/dist/main.js
CHANGED
|
@@ -538,7 +538,7 @@ const lt=t=>(e,i)=>{void 0!==i?i.addInitializer((()=>{customElements.define(t,e)
|
|
|
538
538
|
* (c) 2016-2024 chartjs-plugin-zoom Contributors
|
|
539
539
|
* Released under the MIT License
|
|
540
540
|
*/
|
|
541
|
-
const il=t=>t&&t.enabled&&t.modifierKey,nl=(t,e)=>t&&e[t+"Key"],sl=(t,e)=>t&&!e[t+"Key"];function ol(t,e,i){return void 0===t||("string"==typeof t?-1!==t.indexOf(e):"function"==typeof t&&-1!==t({chart:i}).indexOf(e))}function rl(t,e){return"function"==typeof t&&(t=t({chart:e})),"string"==typeof t?{x:-1!==t.indexOf("x"),y:-1!==t.indexOf("y")}:{x:!1,y:!1}}function al(t,e,i){const{mode:n="xy",scaleMode:s,overScaleMode:o}=t||{},r=function(t,e){let{x:i,y:n}=t;const s=e.scales,o=Object.keys(s);for(let t=0;t<o.length;t++){const e=s[o[t]];if(n>=e.top&&n<=e.bottom&&i>=e.left&&i<=e.right)return e}return null}(e,i),a=rl(n,i),l=rl(s,i);if(o){const t=rl(o,i);for(const e of["x","y"])t[e]&&(l[e]=a[e],a[e]=!1)}if(r&&l[r.axis])return[r];const h=[];return oe(i.scales,(function(t){a[t.axis]&&h.push(t)})),h}const ll=new WeakMap;function hl(t){let e=ll.get(t);return e||(e={originalScaleLimits:{},updatedScaleLimits:{},handlers:{},panDelta:{},dragging:!1,panning:!1},ll.set(t,e)),e}function cl(t,e,i,n){const s=Math.max(0,Math.min(1,(t-e)/i||0));return{min:n*s,max:n*(1-s)}}function dl(t,e){const i=t.isHorizontal()?e.x:e.y;return t.getValueForPixel(i)}function ul(t,e,i){const n=t.max-t.min,s=n*(e-1);return cl(dl(t,i),t.min,n,s)}function pl(t,e,i,n,s){let o=i[n];if("original"===o){const i=t.originalScaleLimits[e.id][n];o=ie(i.options,i.scale)}return ie(o,s)}function fl(t,e,i){let{min:n,max:s}=e,o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=hl(t.chart),{options:a}=t,l=function(t,e){return e&&(e[t.id]||e[t.axis])||{}}(t,i),{minRange:h=0}=l,c=pl(r,t,l,"min",-1/0),d=pl(r,t,l,"max",1/0);if("pan"===o&&(n<c||s>d))return!0;const u=t.max-t.min,p=o?Math.max(s-n,h):u;if(o&&p===h&&u<=h)return!0;const f=function(t,e,i){let{min:n,max:s,minLimit:o,maxLimit:r}=e;const a=(t-s+n)/2;n-=a,s+=a;const l=i.min.options??i.min.scale,h=i.max.options??i.max.scale,c=t/1e6;return De(n,l,c)&&(n=l),De(s,h,c)&&(s=h),n<o?(n=o,s=Math.min(o+t,r)):s>r&&(s=r,n=Math.max(r-t,o)),{min:n,max:s}}(p,{min:n,max:s,minLimit:c,maxLimit:d},r.originalScaleLimits[t.id]);return a.min=f.min,a.max=f.max,r.updatedScaleLimits[t.id]=f,t.parse(f.min)!==t.min||t.parse(f.max)!==t.max}const gl=t=>0===t||isNaN(t)?0:t<0?Math.min(Math.round(t),-1):Math.max(Math.round(t),1);const ml={second:500,minute:3e4,hour:18e5,day:432e5,week:3024e5,month:1296e6,quarter:5184e6,year:157248e5};function bl(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const{min:s,max:o,options:r}=t,a=r.time&&r.time.round,l=ml[a]||0,h=t.getValueForPixel(t.getPixelForValue(s+l)-e),c=t.getValueForPixel(t.getPixelForValue(o+l)-e);return!(!isNaN(h)&&!isNaN(c))||fl(t,{min:h,max:c},i,!!n&&"pan")}function xl(t,e,i){return bl(t,e,i,!0)}const yl={category:function(t,e,i,n){const s=ul(t,e,i);return t.min===t.max&&e<1&&function(t){const e=t.getLabels().length-1;t.min>0&&(t.min-=1),t.max<e&&(t.max+=1)}(t),fl(t,{min:t.min+gl(s.min),max:t.max-gl(s.max)},n,!0)},default:function(t,e,i,n){const s=ul(t,e,i);return fl(t,{min:t.min+s.min,max:t.max-s.max},n,!0)},logarithmic:function(t,e,i,n){const s=function(t,e,i){const n=dl(t,i);if(void 0===n)return{min:t.min,max:t.max};const s=Math.log10(t.min),o=Math.log10(t.max),r=o-s,a=cl(Math.log10(n),s,r,r*(e-1));return{min:Math.pow(10,s+a.min),max:Math.pow(10,o-a.max)}}(t,e,i);return fl(t,s,n,!0)}},vl={default:function(t,e,i,n){fl(t,function(t,e,i){const n=t.getValueForPixel(e),s=t.getValueForPixel(i);return{min:Math.min(n,s),max:Math.max(n,s)}}(t,e,i),n,!0)}},_l={category:function(t,e,i){const n=t.getLabels().length-1;let{min:s,max:o}=t;const r=Math.max(o-s,1),a=Math.round(function(t){return t.isHorizontal()?t.width:t.height}(t)/Math.max(r,10)),l=Math.round(Math.abs(e/a));let h;return e<-a?(o=Math.min(o+l,n),s=1===r?o:o-r,h=o===n):e>a&&(s=Math.max(0,s-l),o=1===r?s:s+r,h=0===s),fl(t,{min:s,max:o},i)||h},default:bl,logarithmic:xl,timeseries:xl};function wl(t,e){oe(t,((i,n)=>{e[n]||delete t[n]}))}function Ml(t,e){const{scales:i}=t,{originalScaleLimits:n,updatedScaleLimits:s}=e;return oe(i,(function(t){(function(t,e,i){const{id:n,options:{min:s,max:o}}=t;if(!e[n]||!i[n])return!0;const r=i[n];return r.min!==s||r.max!==o})(t,n,s)&&(n[t.id]={min:{scale:t.min,options:t.options.min},max:{scale:t.max,options:t.options.max}})})),wl(n,i),wl(s,i),n}function kl(t,e,i,n){se(yl[t.type]||yl.default,[t,e,i,n])}function Sl(t,e,i,n){se(vl[t.type]||vl.default,[t,e,i,n])}function Al(t){const e=t.chartArea;return{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}}function Pl(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"api";const{x:s=1,y:o=1,focalPoint:r=Al(t)}="number"==typeof e?{x:e,y:e}:e,a=hl(t),{options:{limits:l,zoom:h}}=a;Ml(t,a);const c=1!==s,d=1!==o;oe(al(h,r,t)||t.scales,(function(t){t.isHorizontal()&&c?kl(t,s,r,l):!t.isHorizontal()&&d&&kl(t,o,r,l)})),t.update(i),se(h.onZoom,[{chart:t,trigger:n}])}function Cl(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none",s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"api";const o=hl(t),{options:{limits:r,zoom:a}}=o,{mode:l="xy"}=a;Ml(t,o);const h=ol(l,"x",t),c=ol(l,"y",t);oe(t.scales,(function(t){t.isHorizontal()&&h?Sl(t,e.x,i.x,r):!t.isHorizontal()&&c&&Sl(t,e.y,i.y,r)})),t.update(n),se(a.onZoom,[{chart:t,trigger:s}])}function Dl(t){const e=hl(t);let i=1,n=1;return oe(t.scales,(function(t){const s=function(t,e){const i=t.originalScaleLimits[e];if(!i)return;const{min:n,max:s}=i;return ie(s.options,s.scale)-ie(n.options,n.scale)}(e,t.id);if(s){const e=Math.round(s/(t.max-t.min)*100)/100;i=Math.min(i,e),n=Math.max(n,e)}})),i<1?i:n}function Tl(t,e,i,n){const{panDelta:s}=n,o=s[t.id]||0;Ce(o)===Ce(e)&&(e+=o);se(_l[t.type]||_l.default,[t,e,i])?s[t.id]=0:s[t.id]=e}function El(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none";const{x:s=0,y:o=0}="number"==typeof e?{x:e,y:e}:e,r=hl(t),{options:{pan:a,limits:l}}=r,{onPan:h}=a||{};Ml(t,r);const c=0!==s,d=0!==o;oe(i||t.scales,(function(t){t.isHorizontal()&&c?Tl(t,s,l,r):!t.isHorizontal()&&d&&Tl(t,o,l,r)})),t.update(n),se(h,[{chart:t}])}function Ol(t){const e=hl(t);Ml(t,e);const i={};for(const n of Object.keys(t.scales)){const{min:t,max:s}=e.originalScaleLimits[n]||{min:{},max:{}};i[n]={min:t.scale,max:s.scale}}return i}function Rl(t){const e=hl(t);return e.panning||e.dragging}const Ll=(t,e,i)=>Math.min(i,Math.max(e,t));function zl(t,e){const{handlers:i}=hl(t),n=i[e];n&&n.target&&(n.target.removeEventListener(e,n),delete i[e])}function Il(t,e,i,n){const{handlers:s,options:o}=hl(t),r=s[i];if(r&&r.target===e)return;zl(t,i),s[i]=e=>n(t,e,o),s[i].target=e;const a="wheel"!==i&&void 0;e.addEventListener(i,s[i],{passive:a})}function $l(t,e){const i=hl(t);i.dragStart&&(i.dragging=!0,i.dragEnd=e,t.update("none"))}function Fl(t,e){const i=hl(t);i.dragStart&&"Escape"===e.key&&(zl(t,"keydown"),i.dragging=!1,i.dragStart=i.dragEnd=null,t.update("none"))}function Vl(t,e){if(t.target!==e.canvas){const i=e.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}return _n(t,e)}function Nl(t,e,i){const{onZoomStart:n,onZoomRejected:s}=i;if(n){if(!1===se(n,[{chart:t,event:e,point:Vl(e,t)}]))return se(s,[{chart:t,event:e}]),!1}}function Hl(t,e){if(t.legend){if(Ai(_n(e,t),t.legend))return}const i=hl(t),{pan:n,zoom:s={}}=i.options;if(0!==e.button||nl(il(n),e)||sl(il(s.drag),e))return se(s.onZoomRejected,[{chart:t,event:e}]);!1!==Nl(t,e,s)&&(i.dragStart=e,Il(t,t.canvas.ownerDocument,"mousemove",$l),Il(t,window.document,"keydown",Fl))}function Wl(t,e,i,n){let{min:s,max:o,prop:r}=n;t[s]=Ll(Math.min(i.begin[r],i.end[r]),e[s],e[o]),t[o]=Ll(Math.max(i.begin[r],i.end[r]),e[s],e[o])}function Bl(t,e,i){const n={begin:Vl(e.dragStart,t),end:Vl(e.dragEnd,t)};if(i){!function(t,e){let{begin:i,end:n}=t,s=n.x-i.x,o=n.y-i.y;const r=Math.abs(s/o);r>e?s=Math.sign(s)*Math.abs(o*e):r<e&&(o=Math.sign(o)*Math.abs(s/e)),n.x=i.x+s,n.y=i.y+o}(n,t.chartArea.width/t.chartArea.height)}return n}function jl(t,e,i,n){const s=ol(e,"x",t),o=ol(e,"y",t),{top:r,left:a,right:l,bottom:h,width:c,height:d}=t.chartArea,u={top:r,left:a,right:l,bottom:h},p=Bl(t,i,n&&s&&o);s&&Wl(u,t.chartArea,p,{min:"left",max:"right",prop:"x"}),o&&Wl(u,t.chartArea,p,{min:"top",max:"bottom",prop:"y"});const f=u.right-u.left,g=u.bottom-u.top;return{...u,width:f,height:g,zoomX:s&&f?1+(c-f)/c:1,zoomY:o&&g?1+(d-g)/d:1}}function Ul(t,e){const i=hl(t);if(!i.dragStart)return;zl(t,"mousemove");const{mode:n,onZoomComplete:s,drag:{threshold:o=0,maintainAspectRatio:r}}=i.options.zoom,a=jl(t,n,{dragStart:i.dragStart,dragEnd:e},r),l=ol(n,"x",t)?a.width:0,h=ol(n,"y",t)?a.height:0,c=Math.sqrt(l*l+h*h);if(i.dragStart=i.dragEnd=null,c<=o)return i.dragging=!1,void t.update("none");Cl(t,{x:a.left,y:a.top},{x:a.right,y:a.bottom},"zoom","drag"),i.dragging=!1,i.filterNextClick=!0,se(s,[{chart:t}])}function Yl(t,e){const{handlers:{onZoomComplete:i},options:{zoom:n}}=hl(t);if(!function(t,e,i){if(sl(il(i.wheel),e))se(i.onZoomRejected,[{chart:t,event:e}]);else if(!1!==Nl(t,e,i)&&(e.cancelable&&e.preventDefault(),void 0!==e.deltaY))return!0}(t,e,n))return;const s=e.target.getBoundingClientRect(),o=n.wheel.speed,r=e.deltaY>=0?2-1/(1-o):1+o;Pl(t,{x:r,y:r,focalPoint:{x:e.clientX-s.left,y:e.clientY-s.top}},"zoom","wheel"),se(i,[{chart:t}])}function Xl(t,e,i,n){i&&(hl(t).handlers[e]=function(t,e){let i;return function(){return clearTimeout(i),i=setTimeout(t,e),e}}((()=>se(i,[{chart:t}])),n))}function Zl(t,e){return function(i,n){const{pan:s,zoom:o={}}=e.options;if(!s||!s.enabled)return!1;const r=n&&n.srcEvent;return!r||(!(!e.panning&&"mouse"===n.pointerType&&(sl(il(s),r)||nl(il(o.drag),r)))||(se(s.onPanRejected,[{chart:t,event:n}]),!1))}}function ql(t,e,i){if(e.scale){const{center:n,pointers:s}=i,o=1/e.scale*i.scale,r=i.target.getBoundingClientRect(),a=function(t,e){const i=Math.abs(t.clientX-e.clientX),n=Math.abs(t.clientY-e.clientY),s=i/n;let o,r;return s>.3&&s<1.7?o=r=!0:i>n?o=!0:r=!0,{x:o,y:r}}(s[0],s[1]),l=e.options.zoom.mode;Pl(t,{x:a.x&&ol(l,"x",t)?o:1,y:a.y&&ol(l,"y",t)?o:1,focalPoint:{x:n.x-r.left,y:n.y-r.top}},"zoom","pinch"),e.scale=i.scale}}function Kl(t,e,i){const n=e.delta;n&&(e.panning=!0,El(t,{x:i.deltaX-n.x,y:i.deltaY-n.y},e.panScales),e.delta={x:i.deltaX,y:i.deltaY})}const Gl=new WeakMap;function Jl(t,e){const i=hl(t),n=t.canvas,{pan:s,zoom:o}=e,r=new el.Manager(n);o&&o.pinch.enabled&&(r.add(new el.Pinch),r.on("pinchstart",(e=>function(t,e,i){if(e.options.zoom.pinch.enabled){const n=_n(i,t);!1===se(e.options.zoom.onZoomStart,[{chart:t,event:i,point:n}])?(e.scale=null,se(e.options.zoom.onZoomRejected,[{chart:t,event:i}])):e.scale=1}}(t,i,e))),r.on("pinch",(e=>ql(t,i,e))),r.on("pinchend",(e=>function(t,e,i){e.scale&&(ql(t,e,i),e.scale=null,se(e.options.zoom.onZoomComplete,[{chart:t}]))}(t,i,e)))),s&&s.enabled&&(r.add(new el.Pan({threshold:s.threshold,enable:Zl(t,i)})),r.on("panstart",(e=>function(t,e,i){const{enabled:n,onPanStart:s,onPanRejected:o}=e.options.pan;if(!n)return;const r=i.target.getBoundingClientRect(),a={x:i.center.x-r.left,y:i.center.y-r.top};if(!1===se(s,[{chart:t,event:i,point:a}]))return se(o,[{chart:t,event:i}]);e.panScales=al(e.options.pan,a,t),e.delta={x:0,y:0},Kl(t,e,i)}(t,i,e))),r.on("panmove",(e=>Kl(t,i,e))),r.on("panend",(()=>function(t,e){e.delta=null,e.panning&&(e.panning=!1,e.filterNextClick=!0,se(e.options.pan.onPanComplete,[{chart:t}]))}(t,i)))),Gl.set(t,r)}function Ql(t){const e=Gl.get(t);e&&(e.remove("pinchstart"),e.remove("pinch"),e.remove("pinchend"),e.remove("panstart"),e.remove("pan"),e.remove("panend"),e.destroy(),Gl.delete(t))}function th(t,e,i){const n=i.zoom.drag,{dragStart:s,dragEnd:o}=hl(t);if(n.drawTime!==e||!o)return;const{left:r,top:a,width:l,height:h}=jl(t,i.zoom.mode,{dragStart:s,dragEnd:o},n.maintainAspectRatio),c=t.ctx;c.save(),c.beginPath(),c.fillStyle=n.backgroundColor||"rgba(225,225,225,0.3)",c.fillRect(r,a,l,h),n.borderWidth>0&&(c.lineWidth=n.borderWidth,c.strokeStyle=n.borderColor||"rgba(225,225,225)",c.strokeRect(r,a,l,h)),c.restore()}var eh={id:"zoom",version:"2.2.0",defaults:{pan:{enabled:!1,mode:"xy",threshold:10,modifierKey:null},zoom:{wheel:{enabled:!1,speed:.1,modifierKey:null},drag:{enabled:!1,drawTime:"beforeDatasetsDraw",modifierKey:null},pinch:{enabled:!1},mode:"xy"}},start:function(t,e,i){hl(t).options=i,Object.prototype.hasOwnProperty.call(i.zoom,"enabled")&&console.warn("The option `zoom.enabled` is no longer supported. Please use `zoom.wheel.enabled`, `zoom.drag.enabled`, or `zoom.pinch.enabled`."),(Object.prototype.hasOwnProperty.call(i.zoom,"overScaleMode")||Object.prototype.hasOwnProperty.call(i.pan,"overScaleMode"))&&console.warn("The option `overScaleMode` is deprecated. Please use `scaleMode` instead (and update `mode` as desired)."),el&&Jl(t,i),t.pan=(e,i,n)=>El(t,e,i,n),t.zoom=(e,i)=>Pl(t,e,i),t.zoomRect=(e,i,n)=>Cl(t,e,i,n),t.zoomScale=(e,i,n)=>function(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none",s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"api";const o=hl(t);Ml(t,o),fl(t.scales[e],i,void 0,!0),t.update(n),se(o.options.zoom?.onZoom,[{chart:t,trigger:s}])}(t,e,i,n),t.resetZoom=e=>function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";const i=hl(t),n=Ml(t,i);oe(t.scales,(function(t){const e=t.options;n[t.id]?(e.min=n[t.id].min.options,e.max=n[t.id].max.options):(delete e.min,delete e.max),delete i.updatedScaleLimits[t.id]})),t.update(e),se(i.options.zoom.onZoomComplete,[{chart:t}])}(t,e),t.getZoomLevel=()=>Dl(t),t.getInitialScaleBounds=()=>Ol(t),t.getZoomedScaleBounds=()=>function(t){const e=hl(t),i={};for(const n of Object.keys(t.scales))i[n]=e.updatedScaleLimits[n];return i}(t),t.isZoomedOrPanned=()=>function(t){const e=Ol(t);for(const i of Object.keys(t.scales)){const{min:n,max:s}=e[i];if(void 0!==n&&t.scales[i].min!==n)return!0;if(void 0!==s&&t.scales[i].max!==s)return!0}return!1}(t),t.isZoomingOrPanning=()=>Rl(t)},beforeEvent(t,e){let{event:i}=e;if(Rl(t))return!1;if("click"===i.type||"mouseup"===i.type){const e=hl(t);if(e.filterNextClick)return e.filterNextClick=!1,!1}},beforeUpdate:function(t,e,i){const n=hl(t),s=n.options;n.options=i,function(t,e){const{pan:i,zoom:n}=t,{pan:s,zoom:o}=e;return n?.zoom?.pinch?.enabled!==o?.zoom?.pinch?.enabled||i?.enabled!==s?.enabled||i?.threshold!==s?.threshold}(s,i)&&(Ql(t),Jl(t,i)),function(t,e){const i=t.canvas,{wheel:n,drag:s,onZoomComplete:o}=e.zoom;n.enabled?(Il(t,i,"wheel",Yl),Xl(t,"onZoomComplete",o,250)):zl(t,"wheel"),s.enabled?(Il(t,i,"mousedown",Hl),Il(t,i.ownerDocument,"mouseup",Ul)):(zl(t,"mousedown"),zl(t,"mousemove"),zl(t,"mouseup"),zl(t,"keydown"))}(t,i)},beforeDatasetsDraw(t,e,i){th(t,"beforeDatasetsDraw",i)},afterDatasetsDraw(t,e,i){th(t,"afterDatasetsDraw",i)},beforeDraw(t,e,i){th(t,"beforeDraw",i)},afterDraw(t,e,i){th(t,"afterDraw",i)},stop:function(t){!function(t){zl(t,"mousedown"),zl(t,"mousemove"),zl(t,"mouseup"),zl(t,"wheel"),zl(t,"click"),zl(t,"keydown")}(t),el&&Ql(t),function(t){ll.delete(t)}(t)},panFunctions:_l,zoomFunctions:yl,zoomRectFunctions:vl};let ih=class extends rt{constructor(){super(),this.stockData=[],this.zoomEnabled=!1,this.chart=null,this.customLinePlugin={id:"customLinePlugin",afterDraw:t=>{const e=t.ctx,{chartArea:i,scales:n,data:s}=t,o=t.data.datasets.find((t=>"RSI"===t.label)),r=s.datasets.find((t=>"Close Price"===t.label)),a=s.datasets.find((t=>"MA200"===t.label));if(!o||!r||!a)return;const l=o.data,h=r.data,c=a.data;for(let t=1;t<h.length;t++){const i=l[t];if(null!==i&&i<30){const s=n.x.getPixelForValue(t),o=n.yRSI.getPixelForValue(i);e.beginPath(),e.arc(s,o,4,0,2*Math.PI),e.fillStyle="green",e.fill(),e.fillStyle="green",e.font="bold 12px sans-serif",e.fillText("Buy",s+6,o-6)}else if(null!==i&&i>70){const s=n.x.getPixelForValue(t),o=n.yRSI.getPixelForValue(i);e.beginPath(),e.arc(s,o,4,0,2*Math.PI),e.fillStyle="red",e.fill(),e.fillStyle="red",e.font="bold 12px sans-serif",e.fillText("Sell",s+6,o-6)}const s=h[t-1],o=c[t-1],r=h[t],a=c[t];if(null==s||null==o||null==r||null==a)continue;const d=n.x.getPixelForValue(t),u=n.yPrice.getPixelForValue(r);if(r>a&&s<o){e.beginPath(),e.arc(d,u,4,0,2*Math.PI),e.fillStyle="green",e.fill(),e.fillStyle="green",e.font="bold 12px sans-serif",e.fillText("Bull",d+6,u-6);const t=.99*r,i=r+2*(r-t),s=n.yPrice.getPixelForValue(t),o=n.yPrice.getPixelForValue(i);e.fillStyle="red",e.fillRect(d,s,100,1),e.font="bold 12px sans-serif",e.fillText("SL "+t.toFixed(2),d+12,s-4),e.fillStyle="green",e.fillRect(d,o,100,1),e.fillText("TP "+i.toFixed(2),d+12,o-4)}else r<a&&s>o&&(e.beginPath(),e.arc(d,u,4,0,2*Math.PI),e.fillStyle="purple",e.fill(),e.fillStyle="purple",e.font="bold 12px sans-serif",e.fillText("Bear",d+6,u-6));e.setLineDash([])}}},this.stockData=[]}firstUpdated(){this._createChart()}_resetZoom(){var t;null===(t=this.chart)||void 0===t||t.resetZoom()}_Zoomenalbe(){var t,e,i,n;if(null===(e=null===(t=this.chart)||void 0===t?void 0:t.options.plugins)||void 0===e?void 0:e.zoom){const t=this.chart.options.plugins.zoom,e=!this.zoomEnabled;(null===(i=t.zoom)||void 0===i?void 0:i.wheel)&&(t.zoom.wheel.enabled=e),(null===(n=t.zoom)||void 0===n?void 0:n.pinch)&&(t.zoom.pinch.enabled=e),t.pan&&(t.pan.enabled=e),this.zoomEnabled=e,this.chart.update()}}willUpdate(t){return i(this,void 0,void 0,(function*(){t.has("stockData")&&(this.chart?this._updateChart():this._createChart())}))}_getChartData(){return{dates:this.stockData.map((t=>t.date)),closePrices:this.stockData.map((t=>t.close)),ma5:this.stockData.map((t=>{var e;return null!==(e=t.MA5)&&void 0!==e?e:null})),ma10:this.stockData.map((t=>{var e;return null!==(e=t.MA10)&&void 0!==e?e:null})),ma20:this.stockData.map((t=>{var e;return null!==(e=t.MA20)&&void 0!==e?e:null})),ma50:this.stockData.map((t=>{var e;return null!==(e=t.MA50)&&void 0!==e?e:null})),ma100:this.stockData.map((t=>{var e;return null!==(e=t.MA100)&&void 0!==e?e:null})),ma200:this.stockData.map((t=>{var e;return null!==(e=t.MA200)&&void 0!==e?e:null})),RSI:this.stockData.map((t=>{var e;return null!==(e=t.RSI)&&void 0!==e?e:null})),MACDLine:this.stockData.map((t=>{var e;return null!==(e=t.MACDLine)&&void 0!==e?e:null})),SignalLine:this.stockData.map((t=>{var e;return null!==(e=t.SignalLine)&&void 0!==e?e:null})),MACDHistogram:this.stockData.map((t=>{var e;return null!==(e=t.MACDHistogram)&&void 0!==e?e:null})),volumes:this.stockData.map((t=>{var e;return null!==(e=t.volume)&&void 0!==e?e:0}))}}_updateChart(){if(this.chart){const{dates:t,closePrices:e,ma5:i,ma10:n,ma20:s,ma50:o,ma100:r,ma200:a,RSI:l,MACDLine:h,SignalLine:c,MACDHistogram:d,volumes:u}=this._getChartData();this.chart.data.labels=t,this.chart.data.datasets[0].data=l,this.chart.data.datasets[1].data=d,this.chart.data.datasets[2].data=c,this.chart.data.datasets[3].data=h,this.chart.data.datasets[4].data=e,this.chart.data.datasets[5].data=s,this.chart.data.datasets[6].data=o,this.chart.data.datasets[7].data=r,this.chart.data.datasets[8].data=a,this.chart.data.datasets[9].data=u,this.chart.data.datasets[10].data=n,this.chart.data.datasets[11].data=i,this.chart.update()}}_createChart(){var t;const{dates:e,closePrices:i,ma5:n,ma10:s,ma20:o,ma50:r,ma100:a,ma200:l,RSI:h,MACDLine:c,SignalLine:d,MACDHistogram:u,volumes:p}=this._getChartData(),f=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("stockChart");if(!f)return;const g=f.getContext("2d");g&&(this.chart&&this.chart.destroy(),Ga.register(this.customLinePlugin),Ga.register(eh),this.chart=new Ga(g,{type:"line",data:{labels:e,datasets:[{label:"RSI",data:h,borderColor:"rgba(15, 92, 92, 1)",backgroundColor:"rgba(15, 92, 92, 0.2)",fill:!1,borderWidth:2,yAxisID:"yRSI",pointRadius:1,pointHoverRadius:3,hidden:!0},{label:"MACDHistogram",data:u,borderColor:"rgba(175, 92, 92, 1)",backgroundColor:"rgba(175, 92, 92, 0.2)",fill:!1,borderWidth:2,yAxisID:"yMACD",hidden:!0,pointRadius:1,pointHoverRadius:3},{label:"SignalLine",data:d,borderColor:"rgba(75, 92, 192, 1)",backgroundColor:"rgba(75, 92, 192, 0.2)",fill:!1,borderWidth:1,yAxisID:"yMACD",hidden:!0,pointRadius:1,pointHoverRadius:3},{label:"MACDLine",data:c,borderColor:"rgba(175, 192, 192, 1)",backgroundColor:"rgba(175, 192, 192, 0.2)",fill:!1,borderWidth:1,yAxisID:"yMACD",hidden:!0,pointRadius:1,pointHoverRadius:3},{label:"Close Price",data:i,borderColor:"rgba(75, 192, 192, 1)",backgroundColor:"rgba(75, 192, 192, 0.2)",fill:!0,borderWidth:1,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA20",data:o,borderColor:"rgba(255, 99, 132, 1)",backgroundColor:"rgba(255, 99, 132, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA50",data:r,borderColor:"rgba(255, 206, 86, 1)",backgroundColor:"rgba(255, 206, 86, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA100",data:a,borderColor:"rgba(153, 102, 25, 1)",backgroundColor:"rgba(153, 102, 25, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA200",data:l,borderColor:"rgba(153, 102, 255, 1)",backgroundColor:"rgba(153, 102, 255, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"Volume",data:p,yAxisID:"yVolume",fill:!0,backgroundColor:"rgba(252, 3, 57, 0.5)",borderWidth:1,pointRadius:1,pointHoverRadius:3},{label:"MA10",data:s,borderColor:"rgba(153, 12, 25, 1)",backgroundColor:"rgba(153, 12, 25, 0.2)",fill:!1,borderWidth:1,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA5",data:n,borderColor:"rgba(13, 12, 25, 1)",backgroundColor:"rgba(13, 12, 25, 0.2)",fill:!1,borderWidth:1,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3}]},options:{responsive:!0,scales:{x:{ticks:{color:t=>{const e=t.tick.label;if("string"==typeof e){return new Date(e).toISOString().split("T")[0]===(new Date).toISOString().split("T")[0]?"Salmon":"black"}return"black"}}},yPrice:{type:"linear",position:"left",beginAtZero:!1,title:{display:!0,text:"Price"}},yRSI:{type:"linear",position:"right",beginAtZero:!0,title:{display:!0,text:"RSI"},grid:{drawOnChartArea:!1}},yMACD:{type:"linear",position:"right",beginAtZero:!0,title:{display:!0,text:"MACD"},grid:{drawOnChartArea:!1}},yVolume:{type:"linear",position:"left",beginAtZero:!0,title:{display:!0,text:"Volume"},grid:{drawOnChartArea:!1}}},interaction:{mode:"index",intersect:!1},plugins:{tooltip:{mode:"index",axis:"x"},zoom:{pan:{enabled:!1,mode:"xy",modifierKey:void 0},zoom:{wheel:{enabled:!1},pinch:{enabled:!1},mode:"x"},limits:{x:{minRange:10}}}}}}))}render(){return B`
|
|
541
|
+
const il=t=>t&&t.enabled&&t.modifierKey,nl=(t,e)=>t&&e[t+"Key"],sl=(t,e)=>t&&!e[t+"Key"];function ol(t,e,i){return void 0===t||("string"==typeof t?-1!==t.indexOf(e):"function"==typeof t&&-1!==t({chart:i}).indexOf(e))}function rl(t,e){return"function"==typeof t&&(t=t({chart:e})),"string"==typeof t?{x:-1!==t.indexOf("x"),y:-1!==t.indexOf("y")}:{x:!1,y:!1}}function al(t,e,i){const{mode:n="xy",scaleMode:s,overScaleMode:o}=t||{},r=function(t,e){let{x:i,y:n}=t;const s=e.scales,o=Object.keys(s);for(let t=0;t<o.length;t++){const e=s[o[t]];if(n>=e.top&&n<=e.bottom&&i>=e.left&&i<=e.right)return e}return null}(e,i),a=rl(n,i),l=rl(s,i);if(o){const t=rl(o,i);for(const e of["x","y"])t[e]&&(l[e]=a[e],a[e]=!1)}if(r&&l[r.axis])return[r];const h=[];return oe(i.scales,(function(t){a[t.axis]&&h.push(t)})),h}const ll=new WeakMap;function hl(t){let e=ll.get(t);return e||(e={originalScaleLimits:{},updatedScaleLimits:{},handlers:{},panDelta:{},dragging:!1,panning:!1},ll.set(t,e)),e}function cl(t,e,i,n){const s=Math.max(0,Math.min(1,(t-e)/i||0));return{min:n*s,max:n*(1-s)}}function dl(t,e){const i=t.isHorizontal()?e.x:e.y;return t.getValueForPixel(i)}function ul(t,e,i){const n=t.max-t.min,s=n*(e-1);return cl(dl(t,i),t.min,n,s)}function pl(t,e,i,n,s){let o=i[n];if("original"===o){const i=t.originalScaleLimits[e.id][n];o=ie(i.options,i.scale)}return ie(o,s)}function fl(t,e,i){let{min:n,max:s}=e,o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=hl(t.chart),{options:a}=t,l=function(t,e){return e&&(e[t.id]||e[t.axis])||{}}(t,i),{minRange:h=0}=l,c=pl(r,t,l,"min",-1/0),d=pl(r,t,l,"max",1/0);if("pan"===o&&(n<c||s>d))return!0;const u=t.max-t.min,p=o?Math.max(s-n,h):u;if(o&&p===h&&u<=h)return!0;const f=function(t,e,i){let{min:n,max:s,minLimit:o,maxLimit:r}=e;const a=(t-s+n)/2;n-=a,s+=a;const l=i.min.options??i.min.scale,h=i.max.options??i.max.scale,c=t/1e6;return De(n,l,c)&&(n=l),De(s,h,c)&&(s=h),n<o?(n=o,s=Math.min(o+t,r)):s>r&&(s=r,n=Math.max(r-t,o)),{min:n,max:s}}(p,{min:n,max:s,minLimit:c,maxLimit:d},r.originalScaleLimits[t.id]);return a.min=f.min,a.max=f.max,r.updatedScaleLimits[t.id]=f,t.parse(f.min)!==t.min||t.parse(f.max)!==t.max}const gl=t=>0===t||isNaN(t)?0:t<0?Math.min(Math.round(t),-1):Math.max(Math.round(t),1);const ml={second:500,minute:3e4,hour:18e5,day:432e5,week:3024e5,month:1296e6,quarter:5184e6,year:157248e5};function bl(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const{min:s,max:o,options:r}=t,a=r.time&&r.time.round,l=ml[a]||0,h=t.getValueForPixel(t.getPixelForValue(s+l)-e),c=t.getValueForPixel(t.getPixelForValue(o+l)-e);return!(!isNaN(h)&&!isNaN(c))||fl(t,{min:h,max:c},i,!!n&&"pan")}function xl(t,e,i){return bl(t,e,i,!0)}const yl={category:function(t,e,i,n){const s=ul(t,e,i);return t.min===t.max&&e<1&&function(t){const e=t.getLabels().length-1;t.min>0&&(t.min-=1),t.max<e&&(t.max+=1)}(t),fl(t,{min:t.min+gl(s.min),max:t.max-gl(s.max)},n,!0)},default:function(t,e,i,n){const s=ul(t,e,i);return fl(t,{min:t.min+s.min,max:t.max-s.max},n,!0)},logarithmic:function(t,e,i,n){const s=function(t,e,i){const n=dl(t,i);if(void 0===n)return{min:t.min,max:t.max};const s=Math.log10(t.min),o=Math.log10(t.max),r=o-s,a=cl(Math.log10(n),s,r,r*(e-1));return{min:Math.pow(10,s+a.min),max:Math.pow(10,o-a.max)}}(t,e,i);return fl(t,s,n,!0)}},vl={default:function(t,e,i,n){fl(t,function(t,e,i){const n=t.getValueForPixel(e),s=t.getValueForPixel(i);return{min:Math.min(n,s),max:Math.max(n,s)}}(t,e,i),n,!0)}},_l={category:function(t,e,i){const n=t.getLabels().length-1;let{min:s,max:o}=t;const r=Math.max(o-s,1),a=Math.round(function(t){return t.isHorizontal()?t.width:t.height}(t)/Math.max(r,10)),l=Math.round(Math.abs(e/a));let h;return e<-a?(o=Math.min(o+l,n),s=1===r?o:o-r,h=o===n):e>a&&(s=Math.max(0,s-l),o=1===r?s:s+r,h=0===s),fl(t,{min:s,max:o},i)||h},default:bl,logarithmic:xl,timeseries:xl};function wl(t,e){oe(t,((i,n)=>{e[n]||delete t[n]}))}function Ml(t,e){const{scales:i}=t,{originalScaleLimits:n,updatedScaleLimits:s}=e;return oe(i,(function(t){(function(t,e,i){const{id:n,options:{min:s,max:o}}=t;if(!e[n]||!i[n])return!0;const r=i[n];return r.min!==s||r.max!==o})(t,n,s)&&(n[t.id]={min:{scale:t.min,options:t.options.min},max:{scale:t.max,options:t.options.max}})})),wl(n,i),wl(s,i),n}function kl(t,e,i,n){se(yl[t.type]||yl.default,[t,e,i,n])}function Sl(t,e,i,n){se(vl[t.type]||vl.default,[t,e,i,n])}function Al(t){const e=t.chartArea;return{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}}function Pl(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"none",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"api";const{x:s=1,y:o=1,focalPoint:r=Al(t)}="number"==typeof e?{x:e,y:e}:e,a=hl(t),{options:{limits:l,zoom:h}}=a;Ml(t,a);const c=1!==s,d=1!==o;oe(al(h,r,t)||t.scales,(function(t){t.isHorizontal()&&c?kl(t,s,r,l):!t.isHorizontal()&&d&&kl(t,o,r,l)})),t.update(i),se(h.onZoom,[{chart:t,trigger:n}])}function Cl(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none",s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"api";const o=hl(t),{options:{limits:r,zoom:a}}=o,{mode:l="xy"}=a;Ml(t,o);const h=ol(l,"x",t),c=ol(l,"y",t);oe(t.scales,(function(t){t.isHorizontal()&&h?Sl(t,e.x,i.x,r):!t.isHorizontal()&&c&&Sl(t,e.y,i.y,r)})),t.update(n),se(a.onZoom,[{chart:t,trigger:s}])}function Dl(t){const e=hl(t);let i=1,n=1;return oe(t.scales,(function(t){const s=function(t,e){const i=t.originalScaleLimits[e];if(!i)return;const{min:n,max:s}=i;return ie(s.options,s.scale)-ie(n.options,n.scale)}(e,t.id);if(s){const e=Math.round(s/(t.max-t.min)*100)/100;i=Math.min(i,e),n=Math.max(n,e)}})),i<1?i:n}function Tl(t,e,i,n){const{panDelta:s}=n,o=s[t.id]||0;Ce(o)===Ce(e)&&(e+=o);se(_l[t.type]||_l.default,[t,e,i])?s[t.id]=0:s[t.id]=e}function El(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none";const{x:s=0,y:o=0}="number"==typeof e?{x:e,y:e}:e,r=hl(t),{options:{pan:a,limits:l}}=r,{onPan:h}=a||{};Ml(t,r);const c=0!==s,d=0!==o;oe(i||t.scales,(function(t){t.isHorizontal()&&c?Tl(t,s,l,r):!t.isHorizontal()&&d&&Tl(t,o,l,r)})),t.update(n),se(h,[{chart:t}])}function Ol(t){const e=hl(t);Ml(t,e);const i={};for(const n of Object.keys(t.scales)){const{min:t,max:s}=e.originalScaleLimits[n]||{min:{},max:{}};i[n]={min:t.scale,max:s.scale}}return i}function Rl(t){const e=hl(t);return e.panning||e.dragging}const Ll=(t,e,i)=>Math.min(i,Math.max(e,t));function zl(t,e){const{handlers:i}=hl(t),n=i[e];n&&n.target&&(n.target.removeEventListener(e,n),delete i[e])}function Il(t,e,i,n){const{handlers:s,options:o}=hl(t),r=s[i];if(r&&r.target===e)return;zl(t,i),s[i]=e=>n(t,e,o),s[i].target=e;const a="wheel"!==i&&void 0;e.addEventListener(i,s[i],{passive:a})}function $l(t,e){const i=hl(t);i.dragStart&&(i.dragging=!0,i.dragEnd=e,t.update("none"))}function Fl(t,e){const i=hl(t);i.dragStart&&"Escape"===e.key&&(zl(t,"keydown"),i.dragging=!1,i.dragStart=i.dragEnd=null,t.update("none"))}function Vl(t,e){if(t.target!==e.canvas){const i=e.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}return _n(t,e)}function Nl(t,e,i){const{onZoomStart:n,onZoomRejected:s}=i;if(n){if(!1===se(n,[{chart:t,event:e,point:Vl(e,t)}]))return se(s,[{chart:t,event:e}]),!1}}function Hl(t,e){if(t.legend){if(Ai(_n(e,t),t.legend))return}const i=hl(t),{pan:n,zoom:s={}}=i.options;if(0!==e.button||nl(il(n),e)||sl(il(s.drag),e))return se(s.onZoomRejected,[{chart:t,event:e}]);!1!==Nl(t,e,s)&&(i.dragStart=e,Il(t,t.canvas.ownerDocument,"mousemove",$l),Il(t,window.document,"keydown",Fl))}function Wl(t,e,i,n){let{min:s,max:o,prop:r}=n;t[s]=Ll(Math.min(i.begin[r],i.end[r]),e[s],e[o]),t[o]=Ll(Math.max(i.begin[r],i.end[r]),e[s],e[o])}function Bl(t,e,i){const n={begin:Vl(e.dragStart,t),end:Vl(e.dragEnd,t)};if(i){!function(t,e){let{begin:i,end:n}=t,s=n.x-i.x,o=n.y-i.y;const r=Math.abs(s/o);r>e?s=Math.sign(s)*Math.abs(o*e):r<e&&(o=Math.sign(o)*Math.abs(s/e)),n.x=i.x+s,n.y=i.y+o}(n,t.chartArea.width/t.chartArea.height)}return n}function jl(t,e,i,n){const s=ol(e,"x",t),o=ol(e,"y",t),{top:r,left:a,right:l,bottom:h,width:c,height:d}=t.chartArea,u={top:r,left:a,right:l,bottom:h},p=Bl(t,i,n&&s&&o);s&&Wl(u,t.chartArea,p,{min:"left",max:"right",prop:"x"}),o&&Wl(u,t.chartArea,p,{min:"top",max:"bottom",prop:"y"});const f=u.right-u.left,g=u.bottom-u.top;return{...u,width:f,height:g,zoomX:s&&f?1+(c-f)/c:1,zoomY:o&&g?1+(d-g)/d:1}}function Ul(t,e){const i=hl(t);if(!i.dragStart)return;zl(t,"mousemove");const{mode:n,onZoomComplete:s,drag:{threshold:o=0,maintainAspectRatio:r}}=i.options.zoom,a=jl(t,n,{dragStart:i.dragStart,dragEnd:e},r),l=ol(n,"x",t)?a.width:0,h=ol(n,"y",t)?a.height:0,c=Math.sqrt(l*l+h*h);if(i.dragStart=i.dragEnd=null,c<=o)return i.dragging=!1,void t.update("none");Cl(t,{x:a.left,y:a.top},{x:a.right,y:a.bottom},"zoom","drag"),i.dragging=!1,i.filterNextClick=!0,se(s,[{chart:t}])}function Yl(t,e){const{handlers:{onZoomComplete:i},options:{zoom:n}}=hl(t);if(!function(t,e,i){if(sl(il(i.wheel),e))se(i.onZoomRejected,[{chart:t,event:e}]);else if(!1!==Nl(t,e,i)&&(e.cancelable&&e.preventDefault(),void 0!==e.deltaY))return!0}(t,e,n))return;const s=e.target.getBoundingClientRect(),o=n.wheel.speed,r=e.deltaY>=0?2-1/(1-o):1+o;Pl(t,{x:r,y:r,focalPoint:{x:e.clientX-s.left,y:e.clientY-s.top}},"zoom","wheel"),se(i,[{chart:t}])}function Xl(t,e,i,n){i&&(hl(t).handlers[e]=function(t,e){let i;return function(){return clearTimeout(i),i=setTimeout(t,e),e}}((()=>se(i,[{chart:t}])),n))}function Zl(t,e){return function(i,n){const{pan:s,zoom:o={}}=e.options;if(!s||!s.enabled)return!1;const r=n&&n.srcEvent;return!r||(!(!e.panning&&"mouse"===n.pointerType&&(sl(il(s),r)||nl(il(o.drag),r)))||(se(s.onPanRejected,[{chart:t,event:n}]),!1))}}function ql(t,e,i){if(e.scale){const{center:n,pointers:s}=i,o=1/e.scale*i.scale,r=i.target.getBoundingClientRect(),a=function(t,e){const i=Math.abs(t.clientX-e.clientX),n=Math.abs(t.clientY-e.clientY),s=i/n;let o,r;return s>.3&&s<1.7?o=r=!0:i>n?o=!0:r=!0,{x:o,y:r}}(s[0],s[1]),l=e.options.zoom.mode;Pl(t,{x:a.x&&ol(l,"x",t)?o:1,y:a.y&&ol(l,"y",t)?o:1,focalPoint:{x:n.x-r.left,y:n.y-r.top}},"zoom","pinch"),e.scale=i.scale}}function Kl(t,e,i){const n=e.delta;n&&(e.panning=!0,El(t,{x:i.deltaX-n.x,y:i.deltaY-n.y},e.panScales),e.delta={x:i.deltaX,y:i.deltaY})}const Gl=new WeakMap;function Jl(t,e){const i=hl(t),n=t.canvas,{pan:s,zoom:o}=e,r=new el.Manager(n);o&&o.pinch.enabled&&(r.add(new el.Pinch),r.on("pinchstart",(e=>function(t,e,i){if(e.options.zoom.pinch.enabled){const n=_n(i,t);!1===se(e.options.zoom.onZoomStart,[{chart:t,event:i,point:n}])?(e.scale=null,se(e.options.zoom.onZoomRejected,[{chart:t,event:i}])):e.scale=1}}(t,i,e))),r.on("pinch",(e=>ql(t,i,e))),r.on("pinchend",(e=>function(t,e,i){e.scale&&(ql(t,e,i),e.scale=null,se(e.options.zoom.onZoomComplete,[{chart:t}]))}(t,i,e)))),s&&s.enabled&&(r.add(new el.Pan({threshold:s.threshold,enable:Zl(t,i)})),r.on("panstart",(e=>function(t,e,i){const{enabled:n,onPanStart:s,onPanRejected:o}=e.options.pan;if(!n)return;const r=i.target.getBoundingClientRect(),a={x:i.center.x-r.left,y:i.center.y-r.top};if(!1===se(s,[{chart:t,event:i,point:a}]))return se(o,[{chart:t,event:i}]);e.panScales=al(e.options.pan,a,t),e.delta={x:0,y:0},Kl(t,e,i)}(t,i,e))),r.on("panmove",(e=>Kl(t,i,e))),r.on("panend",(()=>function(t,e){e.delta=null,e.panning&&(e.panning=!1,e.filterNextClick=!0,se(e.options.pan.onPanComplete,[{chart:t}]))}(t,i)))),Gl.set(t,r)}function Ql(t){const e=Gl.get(t);e&&(e.remove("pinchstart"),e.remove("pinch"),e.remove("pinchend"),e.remove("panstart"),e.remove("pan"),e.remove("panend"),e.destroy(),Gl.delete(t))}function th(t,e,i){const n=i.zoom.drag,{dragStart:s,dragEnd:o}=hl(t);if(n.drawTime!==e||!o)return;const{left:r,top:a,width:l,height:h}=jl(t,i.zoom.mode,{dragStart:s,dragEnd:o},n.maintainAspectRatio),c=t.ctx;c.save(),c.beginPath(),c.fillStyle=n.backgroundColor||"rgba(225,225,225,0.3)",c.fillRect(r,a,l,h),n.borderWidth>0&&(c.lineWidth=n.borderWidth,c.strokeStyle=n.borderColor||"rgba(225,225,225)",c.strokeRect(r,a,l,h)),c.restore()}var eh={id:"zoom",version:"2.2.0",defaults:{pan:{enabled:!1,mode:"xy",threshold:10,modifierKey:null},zoom:{wheel:{enabled:!1,speed:.1,modifierKey:null},drag:{enabled:!1,drawTime:"beforeDatasetsDraw",modifierKey:null},pinch:{enabled:!1},mode:"xy"}},start:function(t,e,i){hl(t).options=i,Object.prototype.hasOwnProperty.call(i.zoom,"enabled")&&console.warn("The option `zoom.enabled` is no longer supported. Please use `zoom.wheel.enabled`, `zoom.drag.enabled`, or `zoom.pinch.enabled`."),(Object.prototype.hasOwnProperty.call(i.zoom,"overScaleMode")||Object.prototype.hasOwnProperty.call(i.pan,"overScaleMode"))&&console.warn("The option `overScaleMode` is deprecated. Please use `scaleMode` instead (and update `mode` as desired)."),el&&Jl(t,i),t.pan=(e,i,n)=>El(t,e,i,n),t.zoom=(e,i)=>Pl(t,e,i),t.zoomRect=(e,i,n)=>Cl(t,e,i,n),t.zoomScale=(e,i,n)=>function(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"none",s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"api";const o=hl(t);Ml(t,o),fl(t.scales[e],i,void 0,!0),t.update(n),se(o.options.zoom?.onZoom,[{chart:t,trigger:s}])}(t,e,i,n),t.resetZoom=e=>function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";const i=hl(t),n=Ml(t,i);oe(t.scales,(function(t){const e=t.options;n[t.id]?(e.min=n[t.id].min.options,e.max=n[t.id].max.options):(delete e.min,delete e.max),delete i.updatedScaleLimits[t.id]})),t.update(e),se(i.options.zoom.onZoomComplete,[{chart:t}])}(t,e),t.getZoomLevel=()=>Dl(t),t.getInitialScaleBounds=()=>Ol(t),t.getZoomedScaleBounds=()=>function(t){const e=hl(t),i={};for(const n of Object.keys(t.scales))i[n]=e.updatedScaleLimits[n];return i}(t),t.isZoomedOrPanned=()=>function(t){const e=Ol(t);for(const i of Object.keys(t.scales)){const{min:n,max:s}=e[i];if(void 0!==n&&t.scales[i].min!==n)return!0;if(void 0!==s&&t.scales[i].max!==s)return!0}return!1}(t),t.isZoomingOrPanning=()=>Rl(t)},beforeEvent(t,e){let{event:i}=e;if(Rl(t))return!1;if("click"===i.type||"mouseup"===i.type){const e=hl(t);if(e.filterNextClick)return e.filterNextClick=!1,!1}},beforeUpdate:function(t,e,i){const n=hl(t),s=n.options;n.options=i,function(t,e){const{pan:i,zoom:n}=t,{pan:s,zoom:o}=e;return n?.zoom?.pinch?.enabled!==o?.zoom?.pinch?.enabled||i?.enabled!==s?.enabled||i?.threshold!==s?.threshold}(s,i)&&(Ql(t),Jl(t,i)),function(t,e){const i=t.canvas,{wheel:n,drag:s,onZoomComplete:o}=e.zoom;n.enabled?(Il(t,i,"wheel",Yl),Xl(t,"onZoomComplete",o,250)):zl(t,"wheel"),s.enabled?(Il(t,i,"mousedown",Hl),Il(t,i.ownerDocument,"mouseup",Ul)):(zl(t,"mousedown"),zl(t,"mousemove"),zl(t,"mouseup"),zl(t,"keydown"))}(t,i)},beforeDatasetsDraw(t,e,i){th(t,"beforeDatasetsDraw",i)},afterDatasetsDraw(t,e,i){th(t,"afterDatasetsDraw",i)},beforeDraw(t,e,i){th(t,"beforeDraw",i)},afterDraw(t,e,i){th(t,"afterDraw",i)},stop:function(t){!function(t){zl(t,"mousedown"),zl(t,"mousemove"),zl(t,"mouseup"),zl(t,"wheel"),zl(t,"click"),zl(t,"keydown")}(t),el&&Ql(t),function(t){ll.delete(t)}(t)},panFunctions:_l,zoomFunctions:yl,zoomRectFunctions:vl};let ih=class extends rt{constructor(){super(),this.stockData=[],this.zoomEnabled=!1,this.chart=null,this.customLinePlugin={id:"customLinePlugin",afterDraw:t=>{const e=t.ctx,{chartArea:i,scales:n,data:s}=t,o=t.data.datasets.find((t=>"RSI"===t.label)),r=s.datasets.find((t=>"Close Price"===t.label)),a=s.datasets.find((t=>"MA200"===t.label));if(!o||!r||!a)return;const l=o.data,h=r.data,c=a.data;for(let t=1;t<h.length;t++){const i=l[t];if(null!==i&&i<30){const s=n.x.getPixelForValue(t),o=n.yRSI.getPixelForValue(i);e.beginPath(),e.arc(s,o,4,0,2*Math.PI),e.fillStyle="green",e.fill(),e.fillStyle="green",e.font="bold 12px sans-serif",e.fillText("Buy",s+6,o-6)}else if(null!==i&&i>70){const s=n.x.getPixelForValue(t),o=n.yRSI.getPixelForValue(i);e.beginPath(),e.arc(s,o,4,0,2*Math.PI),e.fillStyle="red",e.fill(),e.fillStyle="red",e.font="bold 12px sans-serif",e.fillText("Sell",s+6,o-6)}const s=h[t-1],o=c[t-1],r=h[t],a=c[t];if(null==s||null==o||null==r||null==a)continue;const d=n.x.getPixelForValue(t),u=n.yPrice.getPixelForValue(r);if(r>a&&s<o){e.beginPath(),e.arc(d,u,4,0,2*Math.PI),e.fillStyle="green",e.fill(),e.fillStyle="green",e.font="bold 12px sans-serif",e.fillText("Bull",d+6,u-6);const t=.99*r,i=r+2*(r-t),s=n.yPrice.getPixelForValue(t),o=n.yPrice.getPixelForValue(i);e.fillStyle="red",e.fillRect(d,s,100,1),e.font="bold 12px sans-serif",e.fillText("SL "+t.toFixed(2),d+12,s-4),e.fillStyle="green",e.fillRect(d,o,100,1),e.fillText("TP "+i.toFixed(2),d+12,o-4)}else r<a&&s>o&&(e.beginPath(),e.arc(d,u,4,0,2*Math.PI),e.fillStyle="purple",e.fill(),e.fillStyle="purple",e.font="bold 12px sans-serif",e.fillText("Bear",d+6,u-6));e.setLineDash([])}}},this.stockData=[]}firstUpdated(){this._createChart()}_resetZoom(){var t;null===(t=this.chart)||void 0===t||t.resetZoom()}_Zoomenalbe(){var t,e,i,n;if(null===(e=null===(t=this.chart)||void 0===t?void 0:t.options.plugins)||void 0===e?void 0:e.zoom){const t=this.chart.options.plugins.zoom,e=!this.zoomEnabled;(null===(i=t.zoom)||void 0===i?void 0:i.wheel)&&(t.zoom.wheel.enabled=e),(null===(n=t.zoom)||void 0===n?void 0:n.pinch)&&(t.zoom.pinch.enabled=e),t.pan&&(t.pan.enabled=e),this.zoomEnabled=e,this.chart.update()}}willUpdate(t){return i(this,void 0,void 0,(function*(){t.has("stockData")&&(this.chart?this._updateChart():this._createChart())}))}_getChartData(){return{dates:this.stockData.map((t=>t.date)),closePrices:this.stockData.map((t=>t.close)),ma5:this.stockData.map((t=>{var e;return null!==(e=t.MA5)&&void 0!==e?e:null})),ma10:this.stockData.map((t=>{var e;return null!==(e=t.MA10)&&void 0!==e?e:null})),ma20:this.stockData.map((t=>{var e;return null!==(e=t.MA20)&&void 0!==e?e:null})),ma50:this.stockData.map((t=>{var e;return null!==(e=t.MA50)&&void 0!==e?e:null})),ma100:this.stockData.map((t=>{var e;return null!==(e=t.MA100)&&void 0!==e?e:null})),ma200:this.stockData.map((t=>{var e;return null!==(e=t.MA200)&&void 0!==e?e:null})),RSI:this.stockData.map((t=>{var e;return null!==(e=t.RSI)&&void 0!==e?e:null})),MACDLine:this.stockData.map((t=>{var e;return null!==(e=t.MACDLine)&&void 0!==e?e:null})),SignalLine:this.stockData.map((t=>{var e;return null!==(e=t.SignalLine)&&void 0!==e?e:null})),MACDHistogram:this.stockData.map((t=>{var e;return null!==(e=t.MACDHistogram)&&void 0!==e?e:null})),volumes:this.stockData.map((t=>{var e;return null!==(e=t.volume)&&void 0!==e?e:0}))}}_updateChart(){if(this.chart){const{dates:t,closePrices:e,ma5:i,ma10:n,ma20:s,ma50:o,ma100:r,ma200:a,RSI:l,MACDLine:h,SignalLine:c,MACDHistogram:d,volumes:u}=this._getChartData();this.chart.data.labels=t,this.chart.data.datasets[0].data=l,this.chart.data.datasets[1].data=d,this.chart.data.datasets[2].data=c,this.chart.data.datasets[3].data=h,this.chart.data.datasets[4].data=e,this.chart.data.datasets[5].data=s,this.chart.data.datasets[6].data=o,this.chart.data.datasets[7].data=r,this.chart.data.datasets[8].data=a,this.chart.data.datasets[9].data=u,this.chart.data.datasets[10].data=n,this.chart.data.datasets[11].data=i,this.chart.update()}}_createChart(){var t;const{dates:e,closePrices:i,ma5:n,ma10:s,ma20:o,ma50:r,ma100:a,ma200:l,RSI:h,MACDLine:c,SignalLine:d,MACDHistogram:u,volumes:p}=this._getChartData(),f=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("stockChart");if(!f)return;const g=f.getContext("2d");g&&(this.chart&&this.chart.destroy(),Ga.register(this.customLinePlugin),Ga.register(eh),this.chart=new Ga(g,{type:"line",data:{labels:e,datasets:[{label:"RSI",data:h,borderColor:"rgba(15, 92, 92, 1)",backgroundColor:"rgba(15, 92, 92, 0.2)",fill:!1,borderWidth:2,yAxisID:"yRSI",pointRadius:1,pointHoverRadius:3,hidden:!0},{label:"MACDHistogram",data:u,borderColor:"rgba(175, 92, 92, 1)",backgroundColor:"rgba(175, 92, 92, 0.2)",fill:!1,borderWidth:2,yAxisID:"yMACD",hidden:!0,pointRadius:1,pointHoverRadius:3},{label:"SignalLine",data:d,borderColor:"rgba(75, 92, 192, 1)",backgroundColor:"rgba(75, 92, 192, 0.2)",fill:!1,borderWidth:1,yAxisID:"yMACD",hidden:!0,pointRadius:1,pointHoverRadius:3},{label:"MACDLine",data:c,borderColor:"rgba(175, 192, 192, 1)",backgroundColor:"rgba(175, 192, 192, 0.2)",fill:!1,borderWidth:1,yAxisID:"yMACD",hidden:!0,pointRadius:1,pointHoverRadius:3},{label:"Close Price",data:i,borderColor:"rgba(75, 192, 192, 1)",backgroundColor:"rgba(75, 192, 192, 0.2)",fill:!0,borderWidth:1,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA20",data:o,borderColor:"rgba(255, 99, 132, 1)",backgroundColor:"rgba(255, 99, 132, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA50",data:r,borderColor:"rgba(255, 206, 86, 1)",backgroundColor:"rgba(255, 206, 86, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA100",data:a,borderColor:"rgba(153, 102, 25, 1)",backgroundColor:"rgba(153, 102, 25, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA200",data:l,borderColor:"rgba(153, 102, 255, 1)",backgroundColor:"rgba(153, 102, 255, 0.2)",fill:!1,borderWidth:2,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"Volume",data:p,yAxisID:"yVolume",fill:!0,backgroundColor:"rgba(252, 3, 57, 0.5)",borderWidth:1,pointRadius:1,pointHoverRadius:3},{label:"MA10",data:s,borderColor:"rgba(153, 12, 25, 1)",backgroundColor:"rgba(153, 12, 25, 0.2)",fill:!1,borderWidth:1,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3},{label:"MA5",data:n,borderColor:"rgba(13, 12, 25, 1)",backgroundColor:"rgba(13, 12, 25, 0.2)",fill:!1,borderWidth:1,yAxisID:"yPrice",pointRadius:1,pointHoverRadius:3}]},options:{responsive:!0,scales:{x:{ticks:{color:t=>{const e=t.tick.label;if("string"==typeof e){const t=e.includes(" ")?e.replace(" ","T"):e,i=new Date(t);if(isNaN(i.getTime()))return"black";const n=(new Date).toISOString().split("T")[0];return i.toISOString().split("T")[0]===n?"Salmon":"black"}return"black"}}},yPrice:{type:"linear",position:"left",beginAtZero:!1,title:{display:!0,text:"Price"}},yRSI:{type:"linear",position:"right",beginAtZero:!0,title:{display:!0,text:"RSI"},grid:{drawOnChartArea:!1}},yMACD:{type:"linear",position:"right",beginAtZero:!0,title:{display:!0,text:"MACD"},grid:{drawOnChartArea:!1}},yVolume:{type:"linear",position:"left",beginAtZero:!0,title:{display:!0,text:"Volume"},grid:{drawOnChartArea:!1}}},interaction:{mode:"index",intersect:!1},plugins:{tooltip:{mode:"index",axis:"x"},zoom:{pan:{enabled:!1,mode:"xy",modifierKey:void 0},zoom:{wheel:{enabled:!1},pinch:{enabled:!1},mode:"x"},limits:{x:{minRange:10}}}}}}))}render(){return B`
|
|
542
542
|
<button @click="${this._Zoomenalbe}">
|
|
543
543
|
${this.zoomEnabled?"Disable Zoom":"Enable Zoom"}
|
|
544
544
|
</button>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lit-litelements",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
4
4
|
"description": "My LitElement component build for loading spinner with 10 types, and chart-display fix error hover hidden: true for some line async update",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"module": "dist/main.js",
|