@malinconico/nmcharts 2.3.0 → 2.4.0

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/nmcharts.js CHANGED
@@ -1 +1,1163 @@
1
- !function(t){"use strict";var e=!1,i=[":root{","--mc-bg:#f5f7fa;--mc-card:#fff;--mc-text:#1e293b;--mc-text2:#475569;--mc-muted:#94a3b8;","--mc-grid:#e2e8f0;--mc-border:#e2e8f0;--mc-hover:rgba(0,0,0,.04);","--mc-tt-bg:#1e293b;--mc-tt-fg:#fff;","--mc-sel:rgba(79,70,229,.1);--mc-sel-b:rgba(79,70,229,.3);","--mc-btn:#4f46e5;--mc-btn-h:#4338ca;--mc-mask:rgba(148,163,184,.18);","}",".mc-dark{","--mc-bg:#0f172a;--mc-card:#1e293b;--mc-text:#f1f5f9;--mc-text2:#cbd5e1;--mc-muted:#64748b;","--mc-grid:#334155;--mc-border:#334155;--mc-hover:rgba(255,255,255,.05);","--mc-tt-bg:#0f172a;--mc-tt-fg:#f1f5f9;","--mc-sel:rgba(129,120,255,.15);--mc-sel-b:rgba(129,120,255,.35);","--mc-btn:#6366f1;--mc-btn-h:#818cf8;--mc-mask:rgba(100,116,139,.3);","}",'.mc-root{position:relative;background:var(--mc-card);border-radius:12px;box-shadow:0 2px 16px rgba(0,0,0,.08);padding:20px 20px 14px;user-select:none;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;color:var(--mc-text);transition:background .3s,box-shadow .3s}',".mc-dark .mc-root{box-shadow:0 2px 24px rgba(0,0,0,.3)}",".mc-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}",".mc-titles{text-align:center;flex:1}",".mc-title{font-size:18px;font-weight:600}",".mc-subtitle{font-size:12px;color:var(--mc-muted);margin-top:2px}",".mc-toolbar{display:flex;gap:4px;flex-shrink:0}",".mc-toolbar button{width:32px;height:32px;border:1px solid var(--mc-border);border-radius:6px;background:transparent;color:var(--mc-text2);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s,border-color .15s}",".mc-toolbar button:hover{background:var(--mc-hover)}",".mc-toolbar button.active{background:var(--mc-btn);color:#fff;border-color:var(--mc-btn)}",".mc-toolbar button svg{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}",".mc-wrap{position:relative;width:100%}",".mc-wrap canvas{display:block;width:100%}",".mc-legend{display:flex;justify-content:center;gap:20px;margin-top:8px;flex-wrap:wrap}",".mc-legend-item{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--mc-text2);cursor:pointer;padding:2px 6px;border-radius:4px;transition:background .15s}",".mc-legend-item:hover{background:var(--mc-hover)}",".mc-legend-swatch{width:14px;height:3px;border-radius:2px}",".mc-legend-item.disabled .mc-legend-swatch{opacity:.25}",".mc-legend-item.disabled span:last-child{text-decoration:line-through;opacity:.4}",".mc-tooltip{position:absolute;pointer-events:none;opacity:0;background:var(--mc-tt-bg);color:var(--mc-tt-fg);border-radius:8px;padding:10px 14px;font-size:12px;line-height:1.6;white-space:nowrap;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:opacity .1s;z-index:10}",".mc-tooltip.visible{opacity:1}",".mc-tooltip-date{font-weight:600;margin-bottom:2px}",".mc-tooltip-row{display:flex;align-items:center;gap:6px}",".mc-tooltip-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}",".mc-tooltip-val{margin-left:auto;padding-left:12px;font-weight:600}",".mc-selection{position:absolute;top:0;height:100%;background:var(--mc-sel);border-left:1px solid var(--mc-sel-b);border-right:1px solid var(--mc-sel-b);pointer-events:none;display:none}",".mc-reset{position:absolute;top:8px;right:8px;background:var(--mc-btn);color:#fff;border:none;border-radius:6px;padding:4px 10px;font-size:11px;font-weight:500;cursor:pointer;opacity:0;pointer-events:none;transition:opacity .2s}",".mc-reset.visible{opacity:1;pointer-events:auto}",".mc-reset:hover{background:var(--mc-btn-h)}",".mc-nav{position:relative;width:100%;height:48px;margin-top:6px;border-top:1px solid var(--mc-border)}",".mc-nav canvas{display:block;width:100%;height:48px}",".mc-nav-mask{position:absolute;top:0;height:100%;background:var(--mc-mask);pointer-events:none}",".mc-nav-mask.left{left:0}",".mc-nav-mask.right{right:0}",".mc-nav-win{position:absolute;top:0;height:100%;border-left:2px solid var(--mc-btn);border-right:2px solid var(--mc-btn);cursor:grab;z-index:2}",".mc-nav-h{position:absolute;top:50%;transform:translateY(-50%);width:6px;height:20px;background:var(--mc-btn);border-radius:3px;cursor:ew-resize;z-index:3}",".mc-nav-h.l{left:-4px}",".mc-nav-h.r{right:-4px}",".mc-root:fullscreen,.mc-root:-webkit-full-screen{display:flex;flex-direction:column;justify-content:center;max-width:100%;width:100%;border-radius:0}"].join("\n"),n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function o(t,e,i){return t+(e-t)*i}function r(t,e,i){return Math.max(e,Math.min(i,t))}function s(t,e){var i=Math.floor(Math.log10(t)),n=t/Math.pow(10,i);return(e?n<1.5?1:n<3?2:n<7?5:10:n<=1?1:n<=2?2:n<=5?5:10)*Math.pow(10,i)}function l(t){return Math.abs(t)>=1e3?t.toLocaleString("en-US",{maximumFractionDigits:1}):t===Math.floor(t)?t.toString():t.toFixed(1)}function c(t,e,i,_t){var T=typeof _t==="number"?_t:1;var n=e.length;if(!(n<2))if(i||t.moveTo(e[0][0],e[0][1]),2!==n){if(T<=0){for(var j=1;j<n;j++)t.lineTo(e[j][0],e[j][1]);return}for(var a=[],o=[],r=[],s=0;s<n-1;s++)a[s]=e[s+1][0]-e[s][0],o[s]=e[s+1][1]-e[s][1],r[s]=0===a[s]?0:o[s]/a[s];var l=[r[0]];for(s=1;s<n-1;s++)l[s]=r[s-1]*r[s]<=0?0:(r[s-1]+r[s])/2;for(l[n-1]=r[n-2],s=0;s<n-1;s++)if(Math.abs(r[s])<1e-10)l[s]=0,l[s+1]=0;else{var c=l[s]/r[s],d=l[s+1]/r[s],h=c*c+d*d;if(h>9){var p=3/Math.sqrt(h);l[s]=p*c*r[s],l[s+1]=p*d*r[s]}}for(s=0;s<n-1;s++){var v=a[s]*T/3;t.bezierCurveTo(e[s][0]+v,e[s][1]+l[s]*v,e[s+1][0]-v,e[s+1][1]-l[s+1]*v,e[s+1][0],e[s+1][1])}}else t.lineTo(e[1][0],e[1][1])}function d(t,e){return"rgba("+parseInt(t.slice(1,3),16)+","+parseInt(t.slice(3,5),16)+","+parseInt(t.slice(5,7),16)+","+e+")"}function h(t){return getComputedStyle(document.documentElement).getPropertyValue("--mc-"+t).trim()}function p(t,e,i){var n=document.createElement(t);return e&&(n.className=e),i&&i.appendChild(n),n}function v(t,n){if(function(){if(!e){e=!0;var t=document.createElement("style");t.textContent=i,document.head.appendChild(t)}}(),n=n||{},this.el="string"==typeof t?document.querySelector(t):t,!this.el)throw new Error("NMCharts: container not found");this.opts=n,this.bands=n.bands||[],this.forecastFrom=n.forecastFrom||null;var a=n.toolbar||{};this.series=(n.series||[]).map(function(t){return{name:t.name,data:t.data.slice().sort(function(t,e){return t[0]-e[0]}),color:t.color,type:t.type||"area",dashStyle:t.dashStyle||null,lineWidth:t.lineWidth||2.5,tension:typeof t.tension==="number"?t.tension:1,visible:!0}}),this._buildDOM(n,a),this._computeFullBounds(),this.viewXMin=this.fullXMin,this.viewXMax=this.fullXMax,this._dragStart=null,this._dragging=!1,this._panning=!1,this._panAnchorX=0,this._panViewStart=0,this._panViewEnd=0,this._hoverIdx=-1,this._zoomed=!1,this._entryProgress=0,this._entryStart=performance.now(),this._initSize(),this._buildLegend(),this._bindEvents(),this._bindNavigator(),this._startEntryAnim()}v.prototype._buildDOM=function(t,e){var i=p("div","mc-root",this.el);this._root=i;var n=p("div","mc-header",i);p("div","",n).style.width="120px";var a=p("div","mc-titles",n);p("div","mc-title",a).textContent=t.title||"",p("div","mc-subtitle",a).innerHTML=t.subtitle||"Drag to zoom &middot; Shift+drag to pan &middot; Scroll to zoom &middot; Double-click to reset";var o=p("div","mc-toolbar",n),r=this;if(!1!==e.dark){var s=p("button","",o);s.title="Dark mode",s.innerHTML='<svg viewBox="0 0 24 24"><path d="M21 12.79A9 9 0 0 1 11.21 3a7 7 0 1 0 9.79 9.79z"/></svg>',s.addEventListener("click",function(){r.el.classList.toggle("mc-dark"),s.classList.toggle("active"),r.render(),r._renderNav()})}if(!1!==e.export){var l=p("button","",o);l.title="Export PNG",l.innerHTML='<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',l.addEventListener("click",function(){r.exportPNG()})}if(!1!==e.fullscreen){var c=p("button","",o);c.title="Fullscreen",c.innerHTML='<svg viewBox="0 0 24 24"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',c.addEventListener("click",function(){document.fullscreenElement?(document.exitFullscreen||document.webkitExitFullscreen).call(document):(i.requestFullscreen||i.webkitRequestFullscreen).call(i)}),["fullscreenchange","webkitfullscreenchange"].forEach(function(t){document.addEventListener(t,function(){setTimeout(function(){r._initSize(),r.render(),r._renderNav()},100)})})}var d=p("div","mc-wrap",i);this._wrap=d,this.canvas=p("canvas","",d),this.ctx=this.canvas.getContext("2d"),this._tooltipEl=p("div","mc-tooltip",d),this._selEl=p("div","mc-selection",d),this._resetBtn=p("button","mc-reset",d),this._resetBtn.textContent="Reset zoom";var h=p("div","mc-nav",i);this._navWrap=h,this._navCanvas=p("canvas","",h),this._navCtx=this._navCanvas.getContext("2d"),this._navMaskL=p("div","mc-nav-mask left",h),this._navMaskR=p("div","mc-nav-mask right",h);var v=p("div","mc-nav-win",h);this._navWin=v,this._navHL=p("div","mc-nav-h l",v),this._navHR=p("div","mc-nav-h r",v),this._legendEl=p("div","mc-legend",i)},v.prototype._computeFullBounds=function(){for(var t=1/0,e=-1/0,i=0;i<this.series.length;i++){var n=this.series[i].data;n.length&&(t=Math.min(t,n[0][0]),e=Math.max(e,n[n.length-1][0]))}this.fullXMin=t,this.fullXMax=e},v.prototype._initSize=function(){var t=window.devicePixelRatio||1,e=this._wrap.getBoundingClientRect().width,i=Math.round(.42*e);this.canvas.width=e*t,this.canvas.height=i*t,this.canvas.style.height=i+"px",this.ctx.setTransform(t,0,0,t,0,0),this.W=e,this.H=i,this.pX=58,this.pY=24,this.pW=e-58-24,this.pH=i-24-44;var n=this._navWrap.getBoundingClientRect().width;this._navCanvas.width=n*t,this._navCanvas.height=48*t,this._navCtx.setTransform(t,0,0,t,0,0),this._nW=n,this._nH=48},v.prototype._buildLegend=function(){var t=this;this._legendEl.innerHTML="",this.series.forEach(function(e){var i=p("div","mc-legend-item"+(e.visible?"":" disabled"),t._legendEl),n="line"===e.type?"background:transparent;border-top:2.5px "+("dashed"===e.dashStyle?"dashed":"dotted"===e.dashStyle?"dotted":"solid")+" "+e.color+";height:0;margin-top:1px":"background:"+e.color;i.innerHTML='<div class="mc-legend-swatch" style="'+n+'"></div><span>'+e.name+"</span>",i.addEventListener("click",function(){e.visible=!e.visible,i.classList.toggle("disabled",!e.visible),t.render(),t._renderNav()})})},v.prototype._x2px=function(t){return this.pX+(t-this.viewXMin)/(this.viewXMax-this.viewXMin)*this.pW},v.prototype._y2px=function(t,e){return this.pY+this.pH-(t-e.min)/(e.max-e.min)*this.pH},v.prototype._px2x=function(t){return this.viewXMin+(t-this.pX)/this.pW*(this.viewXMax-this.viewXMin)},v.prototype._yScale=function(){for(var t=1/0,e=-1/0,i=0;i<this.series.length;i++)if(this.series[i].visible)for(var n=this.series[i].data,a=0;a<n.length;a++)n[a][0]>=this.viewXMin&&n[a][0]<=this.viewXMax&&(t=Math.min(t,n[a][1]),e=Math.max(e,n[a][1]));return t===1/0&&(t=0,e=100),function(t,e){t===e&&(t-=1,e+=1);for(var i=s(e-t,!1),n=s(i/5,!0),a=Math.floor(t/n)*n,o=Math.ceil(e/n)*n,r=[],l=a;l<=o+.5*n;l+=n)r.push(Math.round(1e10*l)/1e10);return{min:a,max:o,step:n,ticks:r}}(t=Math.min(0,t),e)},v.prototype._startEntryAnim=function(){var t=this,e=performance.now();!function i(n){var a=r((n-e)/800,0,1);t._entryProgress=1-Math.pow(1-a,3),t.render(),t._renderNav(),a<1&&requestAnimationFrame(i)}(e)},v.prototype.render=function(){var t=this.ctx,e=this._yScale(),i=this,a=h("grid"),o=h("muted"),s='11px -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif';t.clearRect(0,0,this.W,this.H),this.bands.forEach(function(n){var a=i._y2px(Math.min(n.to,e.max),e),o=i._y2px(Math.max(n.from,e.min),e);o<=i.pY||a>=i.pY+i.pH||(a=r(a,i.pY,i.pY+i.pH),o=r(o,i.pY,i.pY+i.pH),t.fillStyle=n.color,t.fillRect(i.pX,a,i.pW,o-a),n.label&&(t.save(),t.font="9px "+s,t.fillStyle=n.labelColor||n.color,t.textAlign="right",t.textBaseline="top",t.globalAlpha=.7,t.fillText(n.label,i.pX+i.pW-4,a+2),t.restore()))}),t.save(),t.font=s,t.textAlign="right",t.textBaseline="middle",e.ticks.forEach(function(n){var r=i._y2px(n,e);t.strokeStyle=a,t.lineWidth=1,t.beginPath(),t.moveTo(i.pX,Math.round(r)+.5),t.lineTo(i.pX+i.pW,Math.round(r)+.5),t.stroke(),t.fillStyle=o,t.fillText(l(n),i.pX-8,r)}),t.restore();var p=function(t,e,i){for(var n=e-t,a=864e5,o=[a,2*a,5*a,7*a,14*a,30*a,60*a,90*a,180*a,365*a],r=a,s=0;s<o.length;s++)if(n/o[s]<=i){r=o[s];break}for(var l=[],c=Math.ceil(t/r)*r;c<=e;c+=r)l.push(c);return l}(this.viewXMin,this.viewXMax,Math.floor(this.pW/80));t.save(),t.font=s,t.textAlign="center",t.textBaseline="top",t.fillStyle=o,p.forEach(function(e){var o=i._x2px(e);o>=i.pX&&o<=i.pX+i.pW&&(t.strokeStyle=a,t.beginPath(),t.moveTo(Math.round(o)+.5,i.pY+i.pH),t.lineTo(Math.round(o)+.5,i.pY+i.pH+5),t.stroke(),t.fillText(function(t){var e=new Date(t);return e.getUTCDate()+" "+n[e.getUTCMonth()]}(e),o,i.pY+i.pH+8))}),t.restore(),t.strokeStyle=a,t.lineWidth=1,t.beginPath(),t.moveTo(this.pX,this.pY),t.lineTo(this.pX,this.pY+this.pH),t.lineTo(this.pX+this.pW,this.pY+this.pH),t.stroke(),t.save(),t.beginPath(),t.rect(this.pX,this.pY,this.pW,this.pH),t.clip();var v=this.pW*this._entryProgress;if(this.series.forEach(function(n){if(n.visible){for(var a=[],o=.05*(i.viewXMax-i.viewXMin),r=0;r<n.data.length;r++){var s=n.data[r][0],l=n.data[r][1];s<i.viewXMin-o||s>i.viewXMax+o||a.push([i._x2px(s),i._y2px(l,e),s])}if(!(a.length<2)){var h=i._y2px(e.min,e);t.save(),t.beginPath(),t.rect(i.pX,i.pY,v,i.pH),t.clip();var p=a,u=null;if(i.forecastFrom){p=[],u=[];for(var f=0;f<a.length;f++)a[f][2]<i.forecastFrom?p.push(a[f]):u.push(a[f]);p.length&&u.length&&u.unshift(p[p.length-1])}var m="line"===n.type,g="dashed"===n.dashStyle?[6,4]:"dotted"===n.dashStyle?[2,3]:null;x(p,!1),u&&u.length>=2&&x(u,!0),t.restore()}}function x(e,a){if(!(e.length<2)){if(!m){var o=t.createLinearGradient(0,i.pY,0,h);o.addColorStop(0,d(n.color,.22)),o.addColorStop(1,d(n.color,.02)),t.beginPath(),t.moveTo(e[0][0],h),t.lineTo(e[0][0],e[0][1]),c(t,e,!0,n.tension),t.lineTo(e[e.length-1][0],h),t.closePath(),t.fillStyle=o,t.fill()}var r=a?[6,4]:g;r&&t.setLineDash(r),t.beginPath(),c(t,e,!1,n.tension),t.strokeStyle=n.color,t.lineWidth=n.lineWidth,t.lineJoin="round",t.lineCap="round",t.stroke(),r&&t.setLineDash([])}}}),this._hoverIdx>=0&&this._entryProgress>=1){var u=null;this.series.forEach(function(n){if(n.visible&&!(i._hoverIdx>=n.data.length)){var a=n.data[i._hoverIdx],o=i._x2px(a[0]),r=i._y2px(a[1],e);u=o,t.beginPath(),t.arc(o,r,5,0,2*Math.PI),t.fillStyle=h("card"),t.fill(),t.strokeStyle=n.color,t.lineWidth=2.5,t.stroke()}}),null!==u&&(t.strokeStyle=d(o,.4),t.lineWidth=1,t.setLineDash([4,3]),t.beginPath(),t.moveTo(Math.round(u)+.5,i.pY),t.lineTo(Math.round(u)+.5,i.pY+i.pH),t.stroke(),t.setLineDash([]))}t.restore()},v.prototype._renderNav=function(){var t=this._navCtx,e=this._nW,i=this._nH,n=this,a=e-2-2,o=i-4-4;t.clearRect(0,0,e,i);var r=1/0,s=-1/0;this.series.forEach(function(t){t.visible&&t.data.forEach(function(t){r=Math.min(r,t[1]),s=Math.max(s,t[1])})}),r===1/0&&(r=0,s=100),r=Math.min(0,r);var l=4+o;this.series.forEach(function(e){if(e.visible){var i=e.data.map(function(t){return[2+(t[0]-n.fullXMin)/(n.fullXMax-n.fullXMin)*a,4+o-(t[1]-r)/(s-r)*o]});if(!(i.length<2)){if("line"!==e.type){var h=t.createLinearGradient(0,4,0,l);h.addColorStop(0,d(e.color,.18)),h.addColorStop(1,d(e.color,.02)),t.beginPath(),t.moveTo(i[0][0],l),t.lineTo(i[0][0],i[0][1]),c(t,i,!0,e.tension),t.lineTo(i[i.length-1][0],l),t.closePath(),t.fillStyle=h,t.fill()}var p="dashed"===e.dashStyle?[4,3]:"dotted"===e.dashStyle?[2,2]:null;p&&t.setLineDash(p),t.beginPath(),c(t,i,!1,e.tension),t.strokeStyle=d(e.color,.6),t.lineWidth=1.2,t.stroke(),p&&t.setLineDash([])}}});var h=(this.viewXMin-this.fullXMin)/(this.fullXMax-this.fullXMin)*100,p=(this.fullXMax-this.viewXMax)/(this.fullXMax-this.fullXMin)*100;this._navWin.style.left=h+"%",this._navWin.style.right=p+"%",this._navMaskL.style.width=h+"%",this._navMaskR.style.width=p+"%"},v.prototype._bindNavigator=function(){var t,e,i,n=this,a=null;function o(o,r){o.preventDefault(),o.stopPropagation(),a=r,t=o.clientX,e=n.viewXMin,i=n.viewXMax,document.addEventListener("mousemove",s),document.addEventListener("mouseup",l)}function s(o){var s=n._navWrap.getBoundingClientRect(),l=(o.clientX-t)/s.width*(n.fullXMax-n.fullXMin),c=1728e5;if("move"===a){var d=e+l,h=i+l;d<n.fullXMin&&(h+=n.fullXMin-d,d=n.fullXMin),h>n.fullXMax&&(d-=h-n.fullXMax,h=n.fullXMax),n.viewXMin=d,n.viewXMax=h}else"left"===a?n.viewXMin=r(e+l,n.fullXMin,n.viewXMax-c):n.viewXMax=r(i+l,n.viewXMin+c,n.fullXMax);n._zoomed=n.viewXMin>n.fullXMin||n.viewXMax<n.fullXMax,n._resetBtn.classList.toggle("visible",n._zoomed),n.render(),n._renderNav()}function l(){a=null,document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",l)}this._navWin.addEventListener("mousedown",function(t){o(t,"move")}),this._navHL.addEventListener("mousedown",function(t){o(t,"left")}),this._navHR.addEventListener("mousedown",function(t){o(t,"right")}),this._navWrap.addEventListener("mousedown",function(t){if(t.target===n._navCanvas){var e=n._navWrap.getBoundingClientRect(),i=n.fullXMin+(t.clientX-e.left)/e.width*(n.fullXMax-n.fullXMin),a=n.viewXMax-n.viewXMin,o=i-a/2,r=i+a/2;o<n.fullXMin&&(r+=n.fullXMin-o,o=n.fullXMin),r>n.fullXMax&&(o-=r-n.fullXMax,r=n.fullXMax),n._zoomed=!0,n._resetBtn.classList.add("visible"),n._animateTo(o,r)}})},v.prototype._animateTo=function(t,e){var i={a:this.viewXMin,b:this.viewXMax},n=this,a=performance.now();!function s(l){var c=r((l-a)/400,0,1),d=1-Math.pow(1-c,3);n.viewXMin=o(i.a,t,d),n.viewXMax=o(i.b,e,d),n.render(),n._renderNav(),c<1&&requestAnimationFrame(s)}(a)},v.prototype._bindEvents=function(){var t,e=this,i=this.canvas;function n(t){var e=i.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}function a(t){return t.x>=e.pX&&t.x<=e.pX+e.pW&&t.y>=e.pY&&t.y<=e.pY+e.pH}window.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(function(){e._initSize(),e.render(),e._renderNav()},80)}),i.addEventListener("mousedown",function(t){var o=n(t);a(o)&&(t.shiftKey&&e._zoomed?(e._panning=!0,e._panAnchorX=o.x,e._panViewStart=e.viewXMin,e._panViewEnd=e.viewXMax,i.style.cursor="grabbing"):(e._dragStart=o.x,e._dragging=!0,e._selEl.style.display="block",e._selEl.style.left=o.x+"px",e._selEl.style.width="0px"))}),i.addEventListener("mousemove",function(t){var o=n(t);if(e._panning){var s=o.x-e._panAnchorX,l=e._panViewEnd-e._panViewStart,c=-s/e.pW*l,d=e._panViewStart+c,h=e._panViewEnd+c;return d<e.fullXMin&&(h+=e.fullXMin-d,d=e.fullXMin),h>e.fullXMax&&(d-=h-e.fullXMax,h=e.fullXMax),e.viewXMin=d,e.viewXMax=h,e.render(),void e._renderNav()}if(e._dragging){var p=Math.min(e._dragStart,o.x),v=Math.abs(o.x-e._dragStart);p=r(p,e.pX,e.pX+e.pW);var u=r(p+v,e.pX,e.pX+e.pW);return e._selEl.style.left=p+"px",void(e._selEl.style.width=u-p+"px")}if(a(o)){i.style.cursor=t.shiftKey&&e._zoomed?"grab":"crosshair";var f=function(t){for(var i=e._px2x(t),n=null,a=0;a<e.series.length;a++)if(e.series[a].visible){n=e.series[a].data;break}if(!n||!n.length)return-1;for(var o=0,r=1/0,s=0;s<n.length;s++){var l=Math.abs(n[s][0]-i);l<r&&(r=l,o=s)}return o}(o.x);f!==e._hoverIdx&&(e._hoverIdx=f,e.render()),e._showTooltip(o,f)}else e._hideTooltip()}),window.addEventListener("mouseup",function(){if(e._panning)return e._panning=!1,void(i.style.cursor="crosshair");if(e._dragging){e._dragging=!1,e._selEl.style.display="none";var t=parseFloat(e._selEl.style.width);if(t<10)e._dragStart=null;else{var n=parseFloat(e._selEl.style.left);e._zoomed=!0,e._resetBtn.classList.add("visible"),e._animateTo(e._px2x(n),e._px2x(n+t)),e._dragStart=null}}}),i.addEventListener("mouseleave",function(){e._hideTooltip()}),i.addEventListener("dblclick",function(t){t.preventDefault(),e._zoomed&&(e._zoomed=!1,e._resetBtn.classList.remove("visible"),e._animateTo(e.fullXMin,e.fullXMax))}),i.addEventListener("wheel",function(t){var i=n(t);if(a(i)){t.preventDefault();var o=t.deltaY>0?1.15:1/1.15,r=e._px2x(i.x),s=e.viewXMax-e.viewXMin,l=s*o;if(!(l<1728e5)){var c=(r-e.viewXMin)/s,d=Math.max(r-c*l,e.fullXMin),h=Math.min(r+(1-c)*l,e.fullXMax);e.viewXMin=d,e.viewXMax=h,e._zoomed=d>e.fullXMin||h<e.fullXMax,e._resetBtn.classList.toggle("visible",e._zoomed),e.render(),e._renderNav()}}},{passive:!1}),this._resetBtn.addEventListener("click",function(){e._zoomed=!1,e._resetBtn.classList.remove("visible"),e._animateTo(e.fullXMin,e.fullXMax)}),document.addEventListener("keydown",function(t){if("INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName){var i=e.viewXMax-e.viewXMin,n=.15*i;if("ArrowLeft"===t.key){var a=Math.max(e.viewXMin-n,e.fullXMin);e._animateTo(a,a+i)}else if("ArrowRight"===t.key){var o=Math.min(e.viewXMax+n,e.fullXMax);e._animateTo(o-i,o)}else if("+"===t.key||"="===t.key){var r=.7*i,s=(e.viewXMin+e.viewXMax)/2;e._zoomed=!0,e._resetBtn.classList.add("visible"),e._animateTo(s-r/2,s+r/2)}else if("-"===t.key){var l=Math.min(1.4*i,e.fullXMax-e.fullXMin),c=(e.viewXMin+e.viewXMax)/2,d=Math.max(c-l/2,e.fullXMin),h=Math.min(c+l/2,e.fullXMax);e._zoomed=d>e.fullXMin||h<e.fullXMax,e._resetBtn.classList.toggle("visible",e._zoomed),e._animateTo(d,h)}else"Escape"===t.key&&e._zoomed&&(e._zoomed=!1,e._resetBtn.classList.remove("visible"),e._animateTo(e.fullXMin,e.fullXMax))}});var o=null;i.addEventListener("touchstart",function(t){1===t.touches.length?(e._panning=!0,e._panAnchorX=t.touches[0].clientX-i.getBoundingClientRect().left,e._panViewStart=e.viewXMin,e._panViewEnd=e.viewXMax):2===t.touches.length&&(e._panning=!1,o=Math.abs(t.touches[1].clientX-t.touches[0].clientX)),t.preventDefault()},{passive:!1}),i.addEventListener("touchmove",function(t){if(1===t.touches.length&&e._panning){var n=t.touches[0].clientX-i.getBoundingClientRect().left-e._panAnchorX,a=e._panViewEnd-e._panViewStart,r=-n/e.pW*a,s=e._panViewStart+r,l=e._panViewEnd+r;s<e.fullXMin&&(l+=e.fullXMin-s,s=e.fullXMin),l>e.fullXMax&&(s-=l-e.fullXMax,l=e.fullXMax),e.viewXMin=s,e.viewXMax=l,e.render(),e._renderNav()}else if(2===t.touches.length&&o){var c=Math.abs(t.touches[1].clientX-t.touches[0].clientX),d=o/c,h=(t.touches[0].clientX+t.touches[1].clientX)/2-i.getBoundingClientRect().left,p=e._px2x(h),v=e.viewXMax-e.viewXMin,u=v*d;if(u<1728e5)return void t.preventDefault();var f=(p-e.viewXMin)/v;e.viewXMin=Math.max(p-f*u,e.fullXMin),e.viewXMax=Math.min(p+(1-f)*u,e.fullXMax),e._zoomed=!0,e._resetBtn.classList.add("visible"),o=c,e.render(),e._renderNav()}t.preventDefault()},{passive:!1}),i.addEventListener("touchend",function(){e._panning=!1,o=null})},v.prototype._showTooltip=function(t,e){if(e<0)this._hideTooltip();else{var i="",o=null;if(this.series.forEach(function(t){!t.visible||e>=t.data.length||(o||(o=t.data[e][0]),i+='<div class="mc-tooltip-row"><div class="mc-tooltip-dot" style="background:'+t.color+'"></div><span>'+t.name+'</span><span class="mc-tooltip-val">'+l(t.data[e][1])+"</span></div>")}),o){i='<div class="mc-tooltip-date">'+function(t){var e=new Date(t);return a[e.getUTCDay()]+", "+n[e.getUTCMonth()]+" "+e.getUTCDate()+", "+e.getUTCFullYear()}(o)+"</div>"+i,this._tooltipEl.innerHTML=i,this._tooltipEl.classList.add("visible");var s=this._tooltipEl.offsetWidth,c=this._tooltipEl.offsetHeight,d=t.x+16,h=t.y-c/2;d+s>this.W-8&&(d=t.x-s-16),h=r(h,4,this.H-c-4),this._tooltipEl.style.left=d+"px",this._tooltipEl.style.top=h+"px"}else this._hideTooltip()}},v.prototype._hideTooltip=function(){this._tooltipEl.classList.remove("visible"),this._hoverIdx>=0&&(this._hoverIdx=-1,this.render())},v.prototype.exportPNG=function(t){var e=document.createElement("a");e.download=t||"chart.png",e.href=this.canvas.toDataURL("image/png"),e.click()},v.prototype.setDarkMode=function(t){this.el.classList.toggle("mc-dark",t),this.render(),this._renderNav()},v.prototype.updateSeries=function(t){this.series=t.map(function(t){return{name:t.name,data:t.data.slice().sort(function(t,e){return t[0]-e[0]}),color:t.color,type:t.type||"area",dashStyle:t.dashStyle||null,lineWidth:t.lineWidth||2.5,tension:typeof t.tension==="number"?t.tension:1,visible:!0}}),this._computeFullBounds(),this.viewXMin=this.fullXMin,this.viewXMax=this.fullXMax,this._zoomed=!1,this._resetBtn.classList.remove("visible"),this._buildLegend(),this.render(),this._renderNav()},v.prototype.destroy=function(){this._root.remove()},v.create=function(t,e){return new v(t,e)};"object"==typeof module&&module.exports?module.exports=v:"function"==typeof define&&define.amd?define(function(){return v}):t.NMCharts=v}("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:this);
1
+ !(function (t) {
2
+ "use strict";
3
+ var e = !1,
4
+ _styleEl = null,
5
+ _instanceCount = 0,
6
+ i = [
7
+ ":root{",
8
+ "--mc-bg:#f5f7fa;--mc-card:#fff;--mc-text:#1e293b;--mc-text2:#475569;--mc-muted:#94a3b8;",
9
+ "--mc-grid:#e2e8f0;--mc-border:#e2e8f0;--mc-hover:rgba(0,0,0,.04);",
10
+ "--mc-tt-bg:#1e293b;--mc-tt-fg:#fff;",
11
+ "--mc-sel:rgba(79,70,229,.1);--mc-sel-b:rgba(79,70,229,.3);",
12
+ "--mc-btn:#4f46e5;--mc-btn-h:#4338ca;--mc-mask:rgba(148,163,184,.18);",
13
+ "}",
14
+ ".mc-dark{",
15
+ "--mc-bg:#0f172a;--mc-card:#1e293b;--mc-text:#f1f5f9;--mc-text2:#cbd5e1;--mc-muted:#64748b;",
16
+ "--mc-grid:#334155;--mc-border:#334155;--mc-hover:rgba(255,255,255,.05);",
17
+ "--mc-tt-bg:#0f172a;--mc-tt-fg:#f1f5f9;",
18
+ "--mc-sel:rgba(129,120,255,.15);--mc-sel-b:rgba(129,120,255,.35);",
19
+ "--mc-btn:#6366f1;--mc-btn-h:#818cf8;--mc-mask:rgba(100,116,139,.3);",
20
+ "}",
21
+ '.mc-root{position:relative;background:var(--mc-card);border-radius:12px;box-shadow:0 2px 16px rgba(0,0,0,.08);padding:20px 20px 14px;user-select:none;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;color:var(--mc-text);transition:background .3s,box-shadow .3s}',
22
+ ".mc-dark .mc-root{box-shadow:0 2px 24px rgba(0,0,0,.3)}",
23
+ ".mc-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}",
24
+ ".mc-titles{text-align:center;flex:1}",
25
+ ".mc-title{font-size:18px;font-weight:600}",
26
+ ".mc-subtitle{font-size:12px;color:var(--mc-muted);margin-top:2px}",
27
+ ".mc-toolbar{display:flex;gap:4px;flex-shrink:0}",
28
+ ".mc-toolbar button{width:32px;height:32px;border:1px solid var(--mc-border);border-radius:6px;background:transparent;color:var(--mc-text2);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s,border-color .15s}",
29
+ ".mc-toolbar button:hover{background:var(--mc-hover)}",
30
+ ".mc-toolbar button.active{background:var(--mc-btn);color:#fff;border-color:var(--mc-btn)}",
31
+ ".mc-toolbar button svg{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}",
32
+ ".mc-wrap{position:relative;width:100%}",
33
+ ".mc-wrap canvas{display:block;width:100%}",
34
+ ".mc-legend{display:flex;justify-content:center;gap:20px;margin-top:8px;flex-wrap:wrap}",
35
+ ".mc-legend-item{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--mc-text2);cursor:pointer;padding:2px 6px;border-radius:4px;transition:background .15s}",
36
+ ".mc-legend-item:hover{background:var(--mc-hover)}",
37
+ ".mc-legend-swatch{width:14px;height:3px;border-radius:2px}",
38
+ ".mc-legend-item.disabled .mc-legend-swatch{opacity:.25}",
39
+ ".mc-legend-item.disabled span:last-child{text-decoration:line-through;opacity:.4}",
40
+ ".mc-tooltip{position:absolute;pointer-events:none;opacity:0;background:var(--mc-tt-bg);color:var(--mc-tt-fg);border-radius:8px;padding:10px 14px;font-size:12px;line-height:1.6;white-space:nowrap;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:opacity .1s;z-index:10}",
41
+ ".mc-tooltip.visible{opacity:1}",
42
+ ".mc-tooltip-date{font-weight:600;margin-bottom:2px}",
43
+ ".mc-tooltip-row{display:flex;align-items:center;gap:6px}",
44
+ ".mc-tooltip-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}",
45
+ ".mc-tooltip-val{margin-left:auto;padding-left:12px;font-weight:600}",
46
+ ".mc-selection{position:absolute;top:0;height:100%;background:var(--mc-sel);border-left:1px solid var(--mc-sel-b);border-right:1px solid var(--mc-sel-b);pointer-events:none;display:none}",
47
+ ".mc-reset{position:absolute;top:8px;right:8px;background:var(--mc-btn);color:#fff;border:none;border-radius:6px;padding:4px 10px;font-size:11px;font-weight:500;cursor:pointer;opacity:0;pointer-events:none;transition:opacity .2s}",
48
+ ".mc-reset.visible{opacity:1;pointer-events:auto}",
49
+ ".mc-reset:hover{background:var(--mc-btn-h)}",
50
+ ".mc-nav{position:relative;width:100%;height:48px;margin-top:6px;border-top:1px solid var(--mc-border)}",
51
+ ".mc-nav canvas{display:block;width:100%;height:48px}",
52
+ ".mc-nav-mask{position:absolute;top:0;height:100%;background:var(--mc-mask);pointer-events:none}",
53
+ ".mc-nav-mask.left{left:0}",
54
+ ".mc-nav-mask.right{right:0}",
55
+ ".mc-nav-win{position:absolute;top:0;height:100%;border-left:2px solid var(--mc-btn);border-right:2px solid var(--mc-btn);cursor:grab;z-index:2}",
56
+ ".mc-nav-h{position:absolute;top:50%;transform:translateY(-50%);width:6px;height:20px;background:var(--mc-btn);border-radius:3px;cursor:ew-resize;z-index:3}",
57
+ ".mc-nav-h.l{left:-4px}",
58
+ ".mc-nav-h.r{right:-4px}",
59
+ ".mc-root:fullscreen,.mc-root:-webkit-full-screen{display:flex;flex-direction:column;justify-content:center;max-width:100%;width:100%;border-radius:0}",
60
+ ].join("\n"),
61
+ n = [
62
+ "Jan",
63
+ "Feb",
64
+ "Mar",
65
+ "Apr",
66
+ "May",
67
+ "Jun",
68
+ "Jul",
69
+ "Aug",
70
+ "Sep",
71
+ "Oct",
72
+ "Nov",
73
+ "Dec",
74
+ ],
75
+ a = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
76
+ function o(t, e, i) {
77
+ return t + (e - t) * i;
78
+ }
79
+ function r(t, e, i) {
80
+ return Math.max(e, Math.min(i, t));
81
+ }
82
+ function s(t, e) {
83
+ var i = Math.floor(Math.log10(t)),
84
+ n = t / Math.pow(10, i);
85
+ return (
86
+ (e
87
+ ? n < 1.5
88
+ ? 1
89
+ : n < 3
90
+ ? 2
91
+ : n < 7
92
+ ? 5
93
+ : 10
94
+ : n <= 1
95
+ ? 1
96
+ : n <= 2
97
+ ? 2
98
+ : n <= 5
99
+ ? 5
100
+ : 10) * Math.pow(10, i)
101
+ );
102
+ }
103
+ function l(t) {
104
+ return Math.abs(t) >= 1e3
105
+ ? t.toLocaleString("en-US", { maximumFractionDigits: 1 })
106
+ : t === Math.floor(t)
107
+ ? t.toString()
108
+ : t.toFixed(1);
109
+ }
110
+ function c(t, e, i, _t) {
111
+ var T = typeof _t === "number" ? _t : 1;
112
+ var n = e.length;
113
+ if (!(n < 2))
114
+ if ((i || t.moveTo(e[0][0], e[0][1]), 2 !== n)) {
115
+ if (T <= 0) {
116
+ for (var j = 1; j < n; j++) t.lineTo(e[j][0], e[j][1]);
117
+ return;
118
+ }
119
+ for (var a = [], o = [], r = [], s = 0; s < n - 1; s++)
120
+ ((a[s] = e[s + 1][0] - e[s][0]),
121
+ (o[s] = e[s + 1][1] - e[s][1]),
122
+ (r[s] = 0 === a[s] ? 0 : o[s] / a[s]));
123
+ var l = [r[0]];
124
+ for (s = 1; s < n - 1; s++)
125
+ l[s] = r[s - 1] * r[s] <= 0 ? 0 : (r[s - 1] + r[s]) / 2;
126
+ for (l[n - 1] = r[n - 2], s = 0; s < n - 1; s++)
127
+ if (Math.abs(r[s]) < 1e-10) ((l[s] = 0), (l[s + 1] = 0));
128
+ else {
129
+ var c = l[s] / r[s],
130
+ d = l[s + 1] / r[s],
131
+ h = c * c + d * d;
132
+ if (h > 9) {
133
+ var p = 3 / Math.sqrt(h);
134
+ ((l[s] = p * c * r[s]), (l[s + 1] = p * d * r[s]));
135
+ }
136
+ }
137
+ for (s = 0; s < n - 1; s++) {
138
+ var v = (a[s] * T) / 3;
139
+ t.bezierCurveTo(
140
+ e[s][0] + v,
141
+ e[s][1] + l[s] * v,
142
+ e[s + 1][0] - v,
143
+ e[s + 1][1] - l[s + 1] * v,
144
+ e[s + 1][0],
145
+ e[s + 1][1],
146
+ );
147
+ }
148
+ } else t.lineTo(e[1][0], e[1][1]);
149
+ }
150
+ function d(t, e) {
151
+ return (
152
+ "rgba(" +
153
+ parseInt(t.slice(1, 3), 16) +
154
+ "," +
155
+ parseInt(t.slice(3, 5), 16) +
156
+ "," +
157
+ parseInt(t.slice(5, 7), 16) +
158
+ "," +
159
+ e +
160
+ ")"
161
+ );
162
+ }
163
+ function h(t, root) {
164
+ var el = root || document.documentElement;
165
+ return getComputedStyle(el)
166
+ .getPropertyValue("--mc-" + t)
167
+ .trim();
168
+ }
169
+ function p(t, e, i) {
170
+ var n = document.createElement(t);
171
+ return (e && (n.className = e), i && i.appendChild(n), n);
172
+ }
173
+ function v(t, n) {
174
+ if (
175
+ ((function () {
176
+ if (!e) {
177
+ e = !0;
178
+ _styleEl = document.createElement("style");
179
+ _styleEl.setAttribute("data-nmcharts", "");
180
+ ((_styleEl.textContent = i), document.head.appendChild(_styleEl));
181
+ }
182
+ _instanceCount++;
183
+ })(),
184
+ (n = n || {}),
185
+ (this.el = "string" == typeof t ? document.querySelector(t) : t),
186
+ !this.el)
187
+ )
188
+ throw new Error("NMCharts: container not found");
189
+ ((this.opts = n),
190
+ (this.bands = n.bands || []),
191
+ (this.forecastFrom = n.forecastFrom || null));
192
+ var a = n.toolbar || {};
193
+ ((this.series = (n.series || []).map(function (t) {
194
+ return {
195
+ name: t.name,
196
+ data: t.data.slice().sort(function (t, e) {
197
+ return t[0] - e[0];
198
+ }),
199
+ color: t.color,
200
+ type: t.type || "area",
201
+ dashStyle: t.dashStyle || null,
202
+ lineWidth: t.lineWidth || 2.5,
203
+ tension: typeof t.tension === "number" ? t.tension : 1,
204
+ visible: !0,
205
+ };
206
+ })),
207
+ this._buildDOM(n, a),
208
+ this._computeFullBounds(),
209
+ (this.viewXMin = this.fullXMin),
210
+ (this.viewXMax = this.fullXMax),
211
+ (this._dragStart = null),
212
+ (this._dragging = !1),
213
+ (this._panning = !1),
214
+ (this._panAnchorX = 0),
215
+ (this._panViewStart = 0),
216
+ (this._panViewEnd = 0),
217
+ (this._hoverIdx = -1),
218
+ (this._zoomed = !1),
219
+ (this._entryProgress = 0),
220
+ (this._entryStart = performance.now()),
221
+ (this._rafId = null),
222
+ (this._resizeTimer = null),
223
+ (this._externalListeners = []),
224
+ (this._destroyed = !1),
225
+ this._initSize(),
226
+ this._buildLegend(),
227
+ this._bindEvents(),
228
+ this._bindNavigator(),
229
+ this._startEntryAnim());
230
+ }
231
+ ((v.prototype._buildDOM = function (t, e) {
232
+ var i = p("div", "mc-root", this.el);
233
+ this._root = i;
234
+ var n = p("div", "mc-header", i);
235
+ p("div", "", n).style.width = "120px";
236
+ var a = p("div", "mc-titles", n);
237
+ ((p("div", "mc-title", a).textContent = t.title || ""),
238
+ (p("div", "mc-subtitle", a).innerHTML =
239
+ t.subtitle ||
240
+ "Drag to zoom &middot; Shift+drag to pan &middot; Scroll to zoom &middot; Double-click to reset"));
241
+ var o = p("div", "mc-toolbar", n),
242
+ r = this;
243
+ if (!1 !== e.dark) {
244
+ var s = p("button", "", o);
245
+ ((s.title = "Dark mode"),
246
+ (s.innerHTML =
247
+ '<svg viewBox="0 0 24 24"><path d="M21 12.79A9 9 0 0 1 11.21 3a7 7 0 1 0 9.79 9.79z"/></svg>'),
248
+ s.addEventListener("click", function () {
249
+ (r.el.classList.toggle("mc-dark"),
250
+ s.classList.toggle("active"),
251
+ r.render(),
252
+ r._renderNav());
253
+ }));
254
+ }
255
+ if (!1 !== e.export) {
256
+ var l = p("button", "", o);
257
+ ((l.title = "Export PNG"),
258
+ (l.innerHTML =
259
+ '<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>'),
260
+ l.addEventListener("click", function () {
261
+ r.exportPNG();
262
+ }));
263
+ }
264
+ if (!1 !== e.fullscreen) {
265
+ var c = p("button", "", o);
266
+ ((c.title = "Fullscreen"),
267
+ (c.innerHTML =
268
+ '<svg viewBox="0 0 24 24"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>'),
269
+ c.addEventListener("click", function () {
270
+ document.fullscreenElement
271
+ ? (document.exitFullscreen || document.webkitExitFullscreen).call(
272
+ document,
273
+ )
274
+ : (i.requestFullscreen || i.webkitRequestFullscreen).call(i);
275
+ }),
276
+ ["fullscreenchange", "webkitfullscreenchange"].forEach(function (t) {
277
+ var fn = function () {
278
+ if (r._destroyed) return;
279
+ setTimeout(function () {
280
+ if (r._destroyed) return;
281
+ (r._initSize(), r.render(), r._renderNav());
282
+ }, 100);
283
+ };
284
+ document.addEventListener(t, fn);
285
+ r._externalListeners.push({ target: document, type: t, fn: fn });
286
+ }));
287
+ }
288
+ var d = p("div", "mc-wrap", i);
289
+ ((this._wrap = d),
290
+ (this.canvas = p("canvas", "", d)),
291
+ (this.ctx = this.canvas.getContext("2d")),
292
+ (this._tooltipEl = p("div", "mc-tooltip", d)),
293
+ (this._selEl = p("div", "mc-selection", d)),
294
+ (this._resetBtn = p("button", "mc-reset", d)),
295
+ (this._resetBtn.textContent = "Reset zoom"));
296
+ var h = p("div", "mc-nav", i);
297
+ ((this._navWrap = h),
298
+ (this._navCanvas = p("canvas", "", h)),
299
+ (this._navCtx = this._navCanvas.getContext("2d")),
300
+ (this._navMaskL = p("div", "mc-nav-mask left", h)),
301
+ (this._navMaskR = p("div", "mc-nav-mask right", h)));
302
+ var v = p("div", "mc-nav-win", h);
303
+ ((this._navWin = v),
304
+ (this._navHL = p("div", "mc-nav-h l", v)),
305
+ (this._navHR = p("div", "mc-nav-h r", v)),
306
+ (this._legendEl = p("div", "mc-legend", i)));
307
+ }),
308
+ (v.prototype._computeFullBounds = function () {
309
+ for (var t = 1 / 0, e = -1 / 0, i = 0; i < this.series.length; i++) {
310
+ var n = this.series[i].data;
311
+ n.length &&
312
+ ((t = Math.min(t, n[0][0])), (e = Math.max(e, n[n.length - 1][0])));
313
+ }
314
+ ((this.fullXMin = t), (this.fullXMax = e));
315
+ }),
316
+ (v.prototype._initSize = function () {
317
+ var t = window.devicePixelRatio || 1,
318
+ e = this._wrap.getBoundingClientRect().width,
319
+ i = Math.round(0.42 * e);
320
+ ((this.canvas.width = e * t),
321
+ (this.canvas.height = i * t),
322
+ (this.canvas.style.height = i + "px"),
323
+ this.ctx.setTransform(t, 0, 0, t, 0, 0),
324
+ (this.W = e),
325
+ (this.H = i),
326
+ (this.pX = 58),
327
+ (this.pY = 24),
328
+ (this.pW = e - 58 - 24),
329
+ (this.pH = i - 24 - 44));
330
+ var n = this._navWrap.getBoundingClientRect().width;
331
+ ((this._navCanvas.width = n * t),
332
+ (this._navCanvas.height = 48 * t),
333
+ this._navCtx.setTransform(t, 0, 0, t, 0, 0),
334
+ (this._nW = n),
335
+ (this._nH = 48));
336
+ }),
337
+ (v.prototype._buildLegend = function () {
338
+ var t = this;
339
+ ((this._legendEl.innerHTML = ""),
340
+ this.series.forEach(function (e) {
341
+ var i = p(
342
+ "div",
343
+ "mc-legend-item" + (e.visible ? "" : " disabled"),
344
+ t._legendEl,
345
+ ),
346
+ n =
347
+ "line" === e.type
348
+ ? "background:transparent;border-top:2.5px " +
349
+ ("dashed" === e.dashStyle
350
+ ? "dashed"
351
+ : "dotted" === e.dashStyle
352
+ ? "dotted"
353
+ : "solid") +
354
+ " " +
355
+ e.color +
356
+ ";height:0;margin-top:1px"
357
+ : "background:" + e.color;
358
+ ((i.innerHTML =
359
+ '<div class="mc-legend-swatch" style="' +
360
+ n +
361
+ '"></div><span>' +
362
+ e.name +
363
+ "</span>"),
364
+ i.addEventListener("click", function () {
365
+ ((e.visible = !e.visible),
366
+ i.classList.toggle("disabled", !e.visible),
367
+ t.render(),
368
+ t._renderNav());
369
+ }));
370
+ }));
371
+ }),
372
+ (v.prototype._x2px = function (t) {
373
+ return (
374
+ this.pX +
375
+ ((t - this.viewXMin) / (this.viewXMax - this.viewXMin)) * this.pW
376
+ );
377
+ }),
378
+ (v.prototype._y2px = function (t, e) {
379
+ return this.pY + this.pH - ((t - e.min) / (e.max - e.min)) * this.pH;
380
+ }),
381
+ (v.prototype._px2x = function (t) {
382
+ return (
383
+ this.viewXMin +
384
+ ((t - this.pX) / this.pW) * (this.viewXMax - this.viewXMin)
385
+ );
386
+ }),
387
+ (v.prototype._yScale = function () {
388
+ for (var t = 1 / 0, e = -1 / 0, i = 0; i < this.series.length; i++)
389
+ if (this.series[i].visible)
390
+ for (var n = this.series[i].data, a = 0; a < n.length; a++)
391
+ n[a][0] >= this.viewXMin &&
392
+ n[a][0] <= this.viewXMax &&
393
+ ((t = Math.min(t, n[a][1])), (e = Math.max(e, n[a][1])));
394
+ return (
395
+ t === 1 / 0 && ((t = 0), (e = 100)),
396
+ (function (t, e) {
397
+ t === e && ((t -= 1), (e += 1));
398
+ for (
399
+ var i = s(e - t, !1),
400
+ n = s(i / 5, !0),
401
+ a = Math.floor(t / n) * n,
402
+ o = Math.ceil(e / n) * n,
403
+ r = [],
404
+ l = a;
405
+ l <= o + 0.5 * n;
406
+ l += n
407
+ )
408
+ r.push(Math.round(1e10 * l) / 1e10);
409
+ return { min: a, max: o, step: n, ticks: r };
410
+ })((t = Math.min(0, t)), e)
411
+ );
412
+ }),
413
+ (v.prototype._startEntryAnim = function () {
414
+ var t = this,
415
+ e = performance.now();
416
+ !(function i(n) {
417
+ if (t._destroyed) return;
418
+ var a = r((n - e) / 800, 0, 1);
419
+ ((t._entryProgress = 1 - Math.pow(1 - a, 3)),
420
+ t.render(),
421
+ t._renderNav(),
422
+ a < 1 && (t._rafId = requestAnimationFrame(i)));
423
+ })(e);
424
+ }),
425
+ (v.prototype.render = function () {
426
+ var t = this.ctx,
427
+ e = this._yScale(),
428
+ i = this,
429
+ a = h("grid", i._root),
430
+ o = h("muted", i._root),
431
+ s =
432
+ '11px -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif';
433
+ (t.clearRect(0, 0, this.W, this.H),
434
+ this.bands.forEach(function (n) {
435
+ var a = i._y2px(Math.min(n.to, e.max), e),
436
+ o = i._y2px(Math.max(n.from, e.min), e);
437
+ o <= i.pY ||
438
+ a >= i.pY + i.pH ||
439
+ ((a = r(a, i.pY, i.pY + i.pH)),
440
+ (o = r(o, i.pY, i.pY + i.pH)),
441
+ (t.fillStyle = n.color),
442
+ t.fillRect(i.pX, a, i.pW, o - a),
443
+ n.label &&
444
+ (t.save(),
445
+ (t.font = "9px " + s),
446
+ (t.fillStyle = n.labelColor || n.color),
447
+ (t.textAlign = "right"),
448
+ (t.textBaseline = "top"),
449
+ (t.globalAlpha = 0.7),
450
+ t.fillText(n.label, i.pX + i.pW - 4, a + 2),
451
+ t.restore()));
452
+ }),
453
+ t.save(),
454
+ (t.font = s),
455
+ (t.textAlign = "right"),
456
+ (t.textBaseline = "middle"),
457
+ e.ticks.forEach(function (n) {
458
+ var r = i._y2px(n, e);
459
+ ((t.strokeStyle = a),
460
+ (t.lineWidth = 1),
461
+ t.beginPath(),
462
+ t.moveTo(i.pX, Math.round(r) + 0.5),
463
+ t.lineTo(i.pX + i.pW, Math.round(r) + 0.5),
464
+ t.stroke(),
465
+ (t.fillStyle = o),
466
+ t.fillText(l(n), i.pX - 8, r));
467
+ }),
468
+ t.restore());
469
+ var p = (function (t, e, i) {
470
+ for (
471
+ var n = e - t,
472
+ a = 864e5,
473
+ o = [
474
+ a,
475
+ 2 * a,
476
+ 5 * a,
477
+ 7 * a,
478
+ 14 * a,
479
+ 30 * a,
480
+ 60 * a,
481
+ 90 * a,
482
+ 180 * a,
483
+ 365 * a,
484
+ ],
485
+ r = a,
486
+ s = 0;
487
+ s < o.length;
488
+ s++
489
+ )
490
+ if (n / o[s] <= i) {
491
+ r = o[s];
492
+ break;
493
+ }
494
+ for (var l = [], c = Math.ceil(t / r) * r; c <= e; c += r) l.push(c);
495
+ return l;
496
+ })(this.viewXMin, this.viewXMax, Math.floor(this.pW / 80));
497
+ (t.save(),
498
+ (t.font = s),
499
+ (t.textAlign = "center"),
500
+ (t.textBaseline = "top"),
501
+ (t.fillStyle = o),
502
+ p.forEach(function (e) {
503
+ var o = i._x2px(e);
504
+ o >= i.pX &&
505
+ o <= i.pX + i.pW &&
506
+ ((t.strokeStyle = a),
507
+ t.beginPath(),
508
+ t.moveTo(Math.round(o) + 0.5, i.pY + i.pH),
509
+ t.lineTo(Math.round(o) + 0.5, i.pY + i.pH + 5),
510
+ t.stroke(),
511
+ t.fillText(
512
+ (function (t) {
513
+ var e = new Date(t);
514
+ return e.getUTCDate() + " " + n[e.getUTCMonth()];
515
+ })(e),
516
+ o,
517
+ i.pY + i.pH + 8,
518
+ ));
519
+ }),
520
+ t.restore(),
521
+ (t.strokeStyle = a),
522
+ (t.lineWidth = 1),
523
+ t.beginPath(),
524
+ t.moveTo(this.pX, this.pY),
525
+ t.lineTo(this.pX, this.pY + this.pH),
526
+ t.lineTo(this.pX + this.pW, this.pY + this.pH),
527
+ t.stroke(),
528
+ t.save(),
529
+ t.beginPath(),
530
+ t.rect(this.pX, this.pY, this.pW, this.pH),
531
+ t.clip());
532
+ var v = this.pW * this._entryProgress;
533
+ if (
534
+ (this.series.forEach(function (n) {
535
+ if (n.visible) {
536
+ for (
537
+ var a = [], o = 0.05 * (i.viewXMax - i.viewXMin), r = 0;
538
+ r < n.data.length;
539
+ r++
540
+ ) {
541
+ var s = n.data[r][0],
542
+ l = n.data[r][1];
543
+ s < i.viewXMin - o ||
544
+ s > i.viewXMax + o ||
545
+ a.push([i._x2px(s), i._y2px(l, e), s]);
546
+ }
547
+ if (!(a.length < 2)) {
548
+ var h = i._y2px(e.min, e);
549
+ (t.save(), t.beginPath(), t.rect(i.pX, i.pY, v, i.pH), t.clip());
550
+ var p = a,
551
+ u = null;
552
+ if (i.forecastFrom) {
553
+ ((p = []), (u = []));
554
+ for (var f = 0; f < a.length; f++)
555
+ a[f][2] < i.forecastFrom ? p.push(a[f]) : u.push(a[f]);
556
+ p.length && u.length && u.unshift(p[p.length - 1]);
557
+ }
558
+ var m = "line" === n.type,
559
+ g =
560
+ "dashed" === n.dashStyle
561
+ ? [6, 4]
562
+ : "dotted" === n.dashStyle
563
+ ? [2, 3]
564
+ : null;
565
+ (x(p, !1), u && u.length >= 2 && x(u, !0), t.restore());
566
+ }
567
+ }
568
+ function x(e, a) {
569
+ if (!(e.length < 2)) {
570
+ if (!m) {
571
+ var o = t.createLinearGradient(0, i.pY, 0, h);
572
+ (o.addColorStop(0, d(n.color, 0.22)),
573
+ o.addColorStop(1, d(n.color, 0.02)),
574
+ t.beginPath(),
575
+ t.moveTo(e[0][0], h),
576
+ t.lineTo(e[0][0], e[0][1]),
577
+ c(t, e, !0, n.tension),
578
+ t.lineTo(e[e.length - 1][0], h),
579
+ t.closePath(),
580
+ (t.fillStyle = o),
581
+ t.fill());
582
+ }
583
+ var r = a ? [6, 4] : g;
584
+ (r && t.setLineDash(r),
585
+ t.beginPath(),
586
+ c(t, e, !1, n.tension),
587
+ (t.strokeStyle = n.color),
588
+ (t.lineWidth = n.lineWidth),
589
+ (t.lineJoin = "round"),
590
+ (t.lineCap = "round"),
591
+ t.stroke(),
592
+ r && t.setLineDash([]));
593
+ }
594
+ }
595
+ }),
596
+ this._hoverIdx >= 0 && this._entryProgress >= 1)
597
+ ) {
598
+ var u = null;
599
+ (this.series.forEach(function (n) {
600
+ if (n.visible && !(i._hoverIdx >= n.data.length)) {
601
+ var a = n.data[i._hoverIdx],
602
+ o = i._x2px(a[0]),
603
+ r = i._y2px(a[1], e);
604
+ ((u = o),
605
+ t.beginPath(),
606
+ t.arc(o, r, 5, 0, 2 * Math.PI),
607
+ (t.fillStyle = h("card", i._root)),
608
+ t.fill(),
609
+ (t.strokeStyle = n.color),
610
+ (t.lineWidth = 2.5),
611
+ t.stroke());
612
+ }
613
+ }),
614
+ null !== u &&
615
+ ((t.strokeStyle = d(o, 0.4)),
616
+ (t.lineWidth = 1),
617
+ t.setLineDash([4, 3]),
618
+ t.beginPath(),
619
+ t.moveTo(Math.round(u) + 0.5, i.pY),
620
+ t.lineTo(Math.round(u) + 0.5, i.pY + i.pH),
621
+ t.stroke(),
622
+ t.setLineDash([])));
623
+ }
624
+ t.restore();
625
+ }),
626
+ (v.prototype._renderNav = function () {
627
+ var t = this._navCtx,
628
+ e = this._nW,
629
+ i = this._nH,
630
+ n = this,
631
+ a = e - 2 - 2,
632
+ o = i - 4 - 4;
633
+ t.clearRect(0, 0, e, i);
634
+ var r = 1 / 0,
635
+ s = -1 / 0;
636
+ (this.series.forEach(function (t) {
637
+ t.visible &&
638
+ t.data.forEach(function (t) {
639
+ ((r = Math.min(r, t[1])), (s = Math.max(s, t[1])));
640
+ });
641
+ }),
642
+ r === 1 / 0 && ((r = 0), (s = 100)),
643
+ (r = Math.min(0, r)));
644
+ var l = 4 + o;
645
+ this.series.forEach(function (e) {
646
+ if (e.visible) {
647
+ var i = e.data.map(function (t) {
648
+ return [
649
+ 2 + ((t[0] - n.fullXMin) / (n.fullXMax - n.fullXMin)) * a,
650
+ 4 + o - ((t[1] - r) / (s - r)) * o,
651
+ ];
652
+ });
653
+ if (!(i.length < 2)) {
654
+ if ("line" !== e.type) {
655
+ var h = t.createLinearGradient(0, 4, 0, l);
656
+ (h.addColorStop(0, d(e.color, 0.18)),
657
+ h.addColorStop(1, d(e.color, 0.02)),
658
+ t.beginPath(),
659
+ t.moveTo(i[0][0], l),
660
+ t.lineTo(i[0][0], i[0][1]),
661
+ c(t, i, !0, e.tension),
662
+ t.lineTo(i[i.length - 1][0], l),
663
+ t.closePath(),
664
+ (t.fillStyle = h),
665
+ t.fill());
666
+ }
667
+ var p =
668
+ "dashed" === e.dashStyle
669
+ ? [4, 3]
670
+ : "dotted" === e.dashStyle
671
+ ? [2, 2]
672
+ : null;
673
+ (p && t.setLineDash(p),
674
+ t.beginPath(),
675
+ c(t, i, !1, e.tension),
676
+ (t.strokeStyle = d(e.color, 0.6)),
677
+ (t.lineWidth = 1.2),
678
+ t.stroke(),
679
+ p && t.setLineDash([]));
680
+ }
681
+ }
682
+ });
683
+ var h =
684
+ ((this.viewXMin - this.fullXMin) / (this.fullXMax - this.fullXMin)) *
685
+ 100,
686
+ p =
687
+ ((this.fullXMax - this.viewXMax) / (this.fullXMax - this.fullXMin)) *
688
+ 100;
689
+ ((this._navWin.style.left = h + "%"),
690
+ (this._navWin.style.right = p + "%"),
691
+ (this._navMaskL.style.width = h + "%"),
692
+ (this._navMaskR.style.width = p + "%"));
693
+ }),
694
+ (v.prototype._bindNavigator = function () {
695
+ var t,
696
+ e,
697
+ i,
698
+ n = this,
699
+ a = null;
700
+ function o(o, r) {
701
+ (o.preventDefault(),
702
+ o.stopPropagation(),
703
+ (a = r),
704
+ (t = o.clientX),
705
+ (e = n.viewXMin),
706
+ (i = n.viewXMax),
707
+ document.addEventListener("mousemove", s),
708
+ document.addEventListener("mouseup", l));
709
+ }
710
+ function s(o) {
711
+ var s = n._navWrap.getBoundingClientRect(),
712
+ l = ((o.clientX - t) / s.width) * (n.fullXMax - n.fullXMin),
713
+ c = 1728e5;
714
+ if ("move" === a) {
715
+ var d = e + l,
716
+ h = i + l;
717
+ (d < n.fullXMin && ((h += n.fullXMin - d), (d = n.fullXMin)),
718
+ h > n.fullXMax && ((d -= h - n.fullXMax), (h = n.fullXMax)),
719
+ (n.viewXMin = d),
720
+ (n.viewXMax = h));
721
+ } else
722
+ "left" === a
723
+ ? (n.viewXMin = r(e + l, n.fullXMin, n.viewXMax - c))
724
+ : (n.viewXMax = r(i + l, n.viewXMin + c, n.fullXMax));
725
+ ((n._zoomed = n.viewXMin > n.fullXMin || n.viewXMax < n.fullXMax),
726
+ n._resetBtn.classList.toggle("visible", n._zoomed),
727
+ n.render(),
728
+ n._renderNav());
729
+ }
730
+ function l() {
731
+ ((a = null),
732
+ document.removeEventListener("mousemove", s),
733
+ document.removeEventListener("mouseup", l));
734
+ }
735
+ (this._navWin.addEventListener("mousedown", function (t) {
736
+ o(t, "move");
737
+ }),
738
+ this._navHL.addEventListener("mousedown", function (t) {
739
+ o(t, "left");
740
+ }),
741
+ this._navHR.addEventListener("mousedown", function (t) {
742
+ o(t, "right");
743
+ }),
744
+ this._navWrap.addEventListener("mousedown", function (t) {
745
+ if (t.target === n._navCanvas) {
746
+ var e = n._navWrap.getBoundingClientRect(),
747
+ i =
748
+ n.fullXMin +
749
+ ((t.clientX - e.left) / e.width) * (n.fullXMax - n.fullXMin),
750
+ a = n.viewXMax - n.viewXMin,
751
+ o = i - a / 2,
752
+ r = i + a / 2;
753
+ (o < n.fullXMin && ((r += n.fullXMin - o), (o = n.fullXMin)),
754
+ r > n.fullXMax && ((o -= r - n.fullXMax), (r = n.fullXMax)),
755
+ (n._zoomed = !0),
756
+ n._resetBtn.classList.add("visible"),
757
+ n._animateTo(o, r));
758
+ }
759
+ }));
760
+ }),
761
+ (v.prototype._animateTo = function (t, e) {
762
+ var i = { a: this.viewXMin, b: this.viewXMax },
763
+ n = this,
764
+ a = performance.now();
765
+ !(function s(l) {
766
+ if (n._destroyed) return;
767
+ var c = r((l - a) / 400, 0, 1),
768
+ d = 1 - Math.pow(1 - c, 3);
769
+ ((n.viewXMin = o(i.a, t, d)),
770
+ (n.viewXMax = o(i.b, e, d)),
771
+ n.render(),
772
+ n._renderNav(),
773
+ c < 1 && (n._rafId = requestAnimationFrame(s)));
774
+ })(a);
775
+ }),
776
+ (v.prototype._bindEvents = function () {
777
+ var t,
778
+ e = this,
779
+ i = this.canvas;
780
+ function n(t) {
781
+ var e = i.getBoundingClientRect();
782
+ return { x: t.clientX - e.left, y: t.clientY - e.top };
783
+ }
784
+ function a(t) {
785
+ return (
786
+ t.x >= e.pX && t.x <= e.pX + e.pW && t.y >= e.pY && t.y <= e.pY + e.pH
787
+ );
788
+ }
789
+ (function () {
790
+ var resizeFn = function () {
791
+ (clearTimeout(e._resizeTimer),
792
+ (e._resizeTimer = setTimeout(function () {
793
+ if (e._destroyed) return;
794
+ (e._initSize(), e.render(), e._renderNav());
795
+ }, 80)));
796
+ };
797
+ window.addEventListener("resize", resizeFn);
798
+ e._externalListeners.push({ target: window, type: "resize", fn: resizeFn });
799
+ })(),
800
+ i.addEventListener("mousedown", function (t) {
801
+ var o = n(t);
802
+ a(o) &&
803
+ (t.shiftKey && e._zoomed
804
+ ? ((e._panning = !0),
805
+ (e._panAnchorX = o.x),
806
+ (e._panViewStart = e.viewXMin),
807
+ (e._panViewEnd = e.viewXMax),
808
+ (i.style.cursor = "grabbing"))
809
+ : ((e._dragStart = o.x),
810
+ (e._dragging = !0),
811
+ (e._selEl.style.display = "block"),
812
+ (e._selEl.style.left = o.x + "px"),
813
+ (e._selEl.style.width = "0px")));
814
+ }),
815
+ i.addEventListener("mousemove", function (t) {
816
+ var o = n(t);
817
+ if (e._panning) {
818
+ var s = o.x - e._panAnchorX,
819
+ l = e._panViewEnd - e._panViewStart,
820
+ c = (-s / e.pW) * l,
821
+ d = e._panViewStart + c,
822
+ h = e._panViewEnd + c;
823
+ return (
824
+ d < e.fullXMin && ((h += e.fullXMin - d), (d = e.fullXMin)),
825
+ h > e.fullXMax && ((d -= h - e.fullXMax), (h = e.fullXMax)),
826
+ (e.viewXMin = d),
827
+ (e.viewXMax = h),
828
+ e.render(),
829
+ void e._renderNav()
830
+ );
831
+ }
832
+ if (e._dragging) {
833
+ var p = Math.min(e._dragStart, o.x),
834
+ v = Math.abs(o.x - e._dragStart);
835
+ p = r(p, e.pX, e.pX + e.pW);
836
+ var u = r(p + v, e.pX, e.pX + e.pW);
837
+ return (
838
+ (e._selEl.style.left = p + "px"),
839
+ void (e._selEl.style.width = u - p + "px")
840
+ );
841
+ }
842
+ if (a(o)) {
843
+ i.style.cursor = t.shiftKey && e._zoomed ? "grab" : "crosshair";
844
+ var f = (function (t) {
845
+ for (
846
+ var i = e._px2x(t), n = null, a = 0;
847
+ a < e.series.length;
848
+ a++
849
+ )
850
+ if (e.series[a].visible) {
851
+ n = e.series[a].data;
852
+ break;
853
+ }
854
+ if (!n || !n.length) return -1;
855
+ for (var o = 0, r = 1 / 0, s = 0; s < n.length; s++) {
856
+ var l = Math.abs(n[s][0] - i);
857
+ l < r && ((r = l), (o = s));
858
+ }
859
+ return o;
860
+ })(o.x);
861
+ (f !== e._hoverIdx && ((e._hoverIdx = f), e.render()),
862
+ e._showTooltip(o, f));
863
+ } else e._hideTooltip();
864
+ }),
865
+ (function () {
866
+ var mouseupFn = function () {
867
+ if (e._panning)
868
+ return ((e._panning = !1), void (i.style.cursor = "crosshair"));
869
+ if (e._dragging) {
870
+ ((e._dragging = !1), (e._selEl.style.display = "none"));
871
+ var t = parseFloat(e._selEl.style.width);
872
+ if (t < 10) e._dragStart = null;
873
+ else {
874
+ var n = parseFloat(e._selEl.style.left);
875
+ ((e._zoomed = !0),
876
+ e._resetBtn.classList.add("visible"),
877
+ e._animateTo(e._px2x(n), e._px2x(n + t)),
878
+ (e._dragStart = null));
879
+ }
880
+ }
881
+ };
882
+ window.addEventListener("mouseup", mouseupFn);
883
+ e._externalListeners.push({ target: window, type: "mouseup", fn: mouseupFn });
884
+ })(),
885
+ i.addEventListener("mouseleave", function () {
886
+ e._hideTooltip();
887
+ }),
888
+ i.addEventListener("dblclick", function (t) {
889
+ (t.preventDefault(),
890
+ e._zoomed &&
891
+ ((e._zoomed = !1),
892
+ e._resetBtn.classList.remove("visible"),
893
+ e._animateTo(e.fullXMin, e.fullXMax)));
894
+ }),
895
+ i.addEventListener(
896
+ "wheel",
897
+ function (t) {
898
+ var i = n(t);
899
+ if (a(i)) {
900
+ t.preventDefault();
901
+ var o = t.deltaY > 0 ? 1.15 : 1 / 1.15,
902
+ r = e._px2x(i.x),
903
+ s = e.viewXMax - e.viewXMin,
904
+ l = s * o;
905
+ if (!(l < 1728e5)) {
906
+ var c = (r - e.viewXMin) / s,
907
+ d = Math.max(r - c * l, e.fullXMin),
908
+ h = Math.min(r + (1 - c) * l, e.fullXMax);
909
+ ((e.viewXMin = d),
910
+ (e.viewXMax = h),
911
+ (e._zoomed = d > e.fullXMin || h < e.fullXMax),
912
+ e._resetBtn.classList.toggle("visible", e._zoomed),
913
+ e.render(),
914
+ e._renderNav());
915
+ }
916
+ }
917
+ },
918
+ { passive: !1 },
919
+ ),
920
+ this._resetBtn.addEventListener("click", function () {
921
+ ((e._zoomed = !1),
922
+ e._resetBtn.classList.remove("visible"),
923
+ e._animateTo(e.fullXMin, e.fullXMax));
924
+ }),
925
+ (function () {
926
+ var keydownFn = function (t) {
927
+ if (e._destroyed) return;
928
+ if ("INPUT" !== t.target.tagName && "TEXTAREA" !== t.target.tagName) {
929
+ var i = e.viewXMax - e.viewXMin,
930
+ n = 0.15 * i;
931
+ if ("ArrowLeft" === t.key) {
932
+ var a = Math.max(e.viewXMin - n, e.fullXMin);
933
+ e._animateTo(a, a + i);
934
+ } else if ("ArrowRight" === t.key) {
935
+ var o = Math.min(e.viewXMax + n, e.fullXMax);
936
+ e._animateTo(o - i, o);
937
+ } else if ("+" === t.key || "=" === t.key) {
938
+ var r = 0.7 * i,
939
+ s = (e.viewXMin + e.viewXMax) / 2;
940
+ ((e._zoomed = !0),
941
+ e._resetBtn.classList.add("visible"),
942
+ e._animateTo(s - r / 2, s + r / 2));
943
+ } else if ("-" === t.key) {
944
+ var l = Math.min(1.4 * i, e.fullXMax - e.fullXMin),
945
+ c = (e.viewXMin + e.viewXMax) / 2,
946
+ d = Math.max(c - l / 2, e.fullXMin),
947
+ h = Math.min(c + l / 2, e.fullXMax);
948
+ ((e._zoomed = d > e.fullXMin || h < e.fullXMax),
949
+ e._resetBtn.classList.toggle("visible", e._zoomed),
950
+ e._animateTo(d, h));
951
+ } else
952
+ "Escape" === t.key &&
953
+ e._zoomed &&
954
+ ((e._zoomed = !1),
955
+ e._resetBtn.classList.remove("visible"),
956
+ e._animateTo(e.fullXMin, e.fullXMax));
957
+ }
958
+ };
959
+ document.addEventListener("keydown", keydownFn);
960
+ e._externalListeners.push({ target: document, type: "keydown", fn: keydownFn });
961
+ })();
962
+ var o = null;
963
+ (i.addEventListener(
964
+ "touchstart",
965
+ function (t) {
966
+ (1 === t.touches.length
967
+ ? ((e._panning = !0),
968
+ (e._panAnchorX =
969
+ t.touches[0].clientX - i.getBoundingClientRect().left),
970
+ (e._panViewStart = e.viewXMin),
971
+ (e._panViewEnd = e.viewXMax))
972
+ : 2 === t.touches.length &&
973
+ ((e._panning = !1),
974
+ (o = Math.abs(t.touches[1].clientX - t.touches[0].clientX))),
975
+ t.preventDefault());
976
+ },
977
+ { passive: !1 },
978
+ ),
979
+ i.addEventListener(
980
+ "touchmove",
981
+ function (t) {
982
+ if (1 === t.touches.length && e._panning) {
983
+ var n =
984
+ t.touches[0].clientX -
985
+ i.getBoundingClientRect().left -
986
+ e._panAnchorX,
987
+ a = e._panViewEnd - e._panViewStart,
988
+ r = (-n / e.pW) * a,
989
+ s = e._panViewStart + r,
990
+ l = e._panViewEnd + r;
991
+ (s < e.fullXMin && ((l += e.fullXMin - s), (s = e.fullXMin)),
992
+ l > e.fullXMax && ((s -= l - e.fullXMax), (l = e.fullXMax)),
993
+ (e.viewXMin = s),
994
+ (e.viewXMax = l),
995
+ e.render(),
996
+ e._renderNav());
997
+ } else if (2 === t.touches.length && o) {
998
+ var c = Math.abs(t.touches[1].clientX - t.touches[0].clientX),
999
+ d = o / c,
1000
+ h =
1001
+ (t.touches[0].clientX + t.touches[1].clientX) / 2 -
1002
+ i.getBoundingClientRect().left,
1003
+ p = e._px2x(h),
1004
+ v = e.viewXMax - e.viewXMin,
1005
+ u = v * d;
1006
+ if (u < 1728e5) return void t.preventDefault();
1007
+ var f = (p - e.viewXMin) / v;
1008
+ ((e.viewXMin = Math.max(p - f * u, e.fullXMin)),
1009
+ (e.viewXMax = Math.min(p + (1 - f) * u, e.fullXMax)),
1010
+ (e._zoomed = !0),
1011
+ e._resetBtn.classList.add("visible"),
1012
+ (o = c),
1013
+ e.render(),
1014
+ e._renderNav());
1015
+ }
1016
+ t.preventDefault();
1017
+ },
1018
+ { passive: !1 },
1019
+ ),
1020
+ i.addEventListener("touchend", function () {
1021
+ ((e._panning = !1), (o = null));
1022
+ }));
1023
+ }),
1024
+ (v.prototype._showTooltip = function (t, e) {
1025
+ if (e < 0) this._hideTooltip();
1026
+ else {
1027
+ var i = "",
1028
+ o = null;
1029
+ if (
1030
+ (this.series.forEach(function (t) {
1031
+ !t.visible ||
1032
+ e >= t.data.length ||
1033
+ (o || (o = t.data[e][0]),
1034
+ (i +=
1035
+ '<div class="mc-tooltip-row"><div class="mc-tooltip-dot" style="background:' +
1036
+ t.color +
1037
+ '"></div><span>' +
1038
+ t.name +
1039
+ '</span><span class="mc-tooltip-val">' +
1040
+ l(t.data[e][1]) +
1041
+ "</span></div>"));
1042
+ }),
1043
+ o)
1044
+ ) {
1045
+ ((i =
1046
+ '<div class="mc-tooltip-date">' +
1047
+ (function (t) {
1048
+ var e = new Date(t);
1049
+ return (
1050
+ a[e.getUTCDay()] +
1051
+ ", " +
1052
+ n[e.getUTCMonth()] +
1053
+ " " +
1054
+ e.getUTCDate() +
1055
+ ", " +
1056
+ e.getUTCFullYear()
1057
+ );
1058
+ })(o) +
1059
+ "</div>" +
1060
+ i),
1061
+ (this._tooltipEl.innerHTML = i),
1062
+ this._tooltipEl.classList.add("visible"));
1063
+ var s = this._tooltipEl.offsetWidth,
1064
+ c = this._tooltipEl.offsetHeight,
1065
+ d = t.x + 16,
1066
+ h = t.y - c / 2;
1067
+ (d + s > this.W - 8 && (d = t.x - s - 16),
1068
+ (h = r(h, 4, this.H - c - 4)),
1069
+ (this._tooltipEl.style.left = d + "px"),
1070
+ (this._tooltipEl.style.top = h + "px"));
1071
+ } else this._hideTooltip();
1072
+ }
1073
+ }),
1074
+ (v.prototype._hideTooltip = function () {
1075
+ (this._tooltipEl.classList.remove("visible"),
1076
+ this._hoverIdx >= 0 && ((this._hoverIdx = -1), this.render()));
1077
+ }),
1078
+ (v.prototype.exportPNG = function (t) {
1079
+ var e = document.createElement("a");
1080
+ ((e.download = t || "chart.png"),
1081
+ (e.href = this.canvas.toDataURL("image/png")),
1082
+ e.click());
1083
+ }),
1084
+ (v.prototype.setDarkMode = function (t) {
1085
+ (this.el.classList.toggle("mc-dark", t),
1086
+ this.render(),
1087
+ this._renderNav());
1088
+ }),
1089
+ (v.prototype.updateSeries = function (t) {
1090
+ ((this.series = t.map(function (t) {
1091
+ return {
1092
+ name: t.name,
1093
+ data: t.data.slice().sort(function (t, e) {
1094
+ return t[0] - e[0];
1095
+ }),
1096
+ color: t.color,
1097
+ type: t.type || "area",
1098
+ dashStyle: t.dashStyle || null,
1099
+ lineWidth: t.lineWidth || 2.5,
1100
+ tension: typeof t.tension === "number" ? t.tension : 1,
1101
+ visible: !0,
1102
+ };
1103
+ })),
1104
+ this._computeFullBounds(),
1105
+ (this.viewXMin = this.fullXMin),
1106
+ (this.viewXMax = this.fullXMax),
1107
+ (this._zoomed = !1),
1108
+ this._resetBtn.classList.remove("visible"),
1109
+ this._buildLegend(),
1110
+ this.render(),
1111
+ this._renderNav());
1112
+ }),
1113
+ (v.prototype.destroy = function () {
1114
+ this._destroyed = !0;
1115
+ // Cancel pending animations
1116
+ if (this._rafId) { cancelAnimationFrame(this._rafId); this._rafId = null; }
1117
+ // Clear resize debounce timer
1118
+ if (this._resizeTimer) { clearTimeout(this._resizeTimer); this._resizeTimer = null; }
1119
+ // Remove all external listeners (window/document)
1120
+ if (this._externalListeners) {
1121
+ for (var i = 0; i < this._externalListeners.length; i++) {
1122
+ var l = this._externalListeners[i];
1123
+ l.target.removeEventListener(l.type, l.fn);
1124
+ }
1125
+ this._externalListeners = [];
1126
+ }
1127
+ // Remove DOM
1128
+ if (this._root && this._root.parentNode) {
1129
+ this._root.parentNode.removeChild(this._root);
1130
+ }
1131
+ // Decrement instance count; remove global CSS when last instance is destroyed
1132
+ _instanceCount--;
1133
+ if (_instanceCount <= 0 && _styleEl && _styleEl.parentNode) {
1134
+ _styleEl.parentNode.removeChild(_styleEl);
1135
+ _styleEl = null;
1136
+ e = !1;
1137
+ _instanceCount = 0;
1138
+ }
1139
+ // Null out references to aid GC
1140
+ this.canvas = null;
1141
+ this.ctx = null;
1142
+ this._navCanvas = null;
1143
+ this._navCtx = null;
1144
+ this._tooltipEl = null;
1145
+ this.el = null;
1146
+ }),
1147
+ (v.create = function (t, e) {
1148
+ return new v(t, e);
1149
+ }));
1150
+ "object" == typeof module && module.exports
1151
+ ? (module.exports = v)
1152
+ : "function" == typeof define && define.amd
1153
+ ? define(function () {
1154
+ return v;
1155
+ })
1156
+ : (t.NMCharts = v);
1157
+ })(
1158
+ "undefined" != typeof window
1159
+ ? window
1160
+ : "undefined" != typeof globalThis
1161
+ ? globalThis
1162
+ : this,
1163
+ );