@malinconico/nmcharts 2.3.0 → 2.5.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,1170 @@
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
+ var _nonce = (t.NMCharts && t.NMCharts._cspNonce) || "";
181
+ if (_nonce) _styleEl.setAttribute("nonce", _nonce);
182
+ _styleEl.textContent = i;
183
+ try { document.head.appendChild(_styleEl); } catch(ex) { console.warn("[NMCharts] CSP blocked style injection:", ex.message); }
184
+ }
185
+ _instanceCount++;
186
+ })(),
187
+ (n = n || {}),
188
+ (this.el = "string" == typeof t ? document.querySelector(t) : t),
189
+ !this.el)
190
+ )
191
+ throw new Error("NMCharts: container not found");
192
+ if (t.NMCharts && t.NMCharts.debug) console.log("[NMCharts:create] Creating time-series chart", { container: this.el.id || this.el.tagName, width: this.el.getBoundingClientRect().width, series: (n.series||[]).length, title: n.title || '' });
193
+ ((this.opts = n),
194
+ (this.bands = n.bands || []),
195
+ (this.forecastFrom = n.forecastFrom || null),
196
+ (this._externalListeners = []),
197
+ (this._destroyed = !1));
198
+ var a = n.toolbar || {};
199
+ ((this.series = (n.series || []).map(function (t) {
200
+ return {
201
+ name: t.name,
202
+ data: t.data.slice().sort(function (t, e) {
203
+ return t[0] - e[0];
204
+ }),
205
+ color: t.color,
206
+ type: t.type || "area",
207
+ dashStyle: t.dashStyle || null,
208
+ lineWidth: t.lineWidth || 2.5,
209
+ tension: typeof t.tension === "number" ? t.tension : 1,
210
+ visible: !0,
211
+ };
212
+ })),
213
+ this._buildDOM(n, a),
214
+ this._computeFullBounds(),
215
+ (this.viewXMin = this.fullXMin),
216
+ (this.viewXMax = this.fullXMax),
217
+ (this._dragStart = null),
218
+ (this._dragging = !1),
219
+ (this._panning = !1),
220
+ (this._panAnchorX = 0),
221
+ (this._panViewStart = 0),
222
+ (this._panViewEnd = 0),
223
+ (this._hoverIdx = -1),
224
+ (this._zoomed = !1),
225
+ (this._entryProgress = 0),
226
+ (this._entryStart = performance.now()),
227
+ (this._rafId = null),
228
+ (this._resizeTimer = null),
229
+ (this._externalListeners = []),
230
+ (this._destroyed = !1),
231
+ this._initSize(),
232
+ this._buildLegend(),
233
+ this._bindEvents(),
234
+ this._bindNavigator(),
235
+ this._startEntryAnim());
236
+ }
237
+ ((v.prototype._buildDOM = function (t, e) {
238
+ var i = p("div", "mc-root", this.el);
239
+ i.style.maxWidth = "100%"; i.style.overflow = "hidden"; i.style.boxSizing = "border-box";
240
+ this._root = i;
241
+ var n = p("div", "mc-header", i);
242
+ p("div", "", n).style.width = "120px";
243
+ var a = p("div", "mc-titles", n);
244
+ ((p("div", "mc-title", a).textContent = t.title || ""),
245
+ (p("div", "mc-subtitle", a).textContent =
246
+ t.subtitle ||
247
+ "Drag to zoom \u00B7 Shift+drag to pan \u00B7 Scroll to zoom \u00B7 Double-click to reset"));
248
+ var o = p("div", "mc-toolbar", n),
249
+ r = this;
250
+ if (!1 !== e.dark) {
251
+ var s = p("button", "", o);
252
+ ((s.title = "Dark mode"),
253
+ (s.innerHTML =
254
+ '<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>'),
255
+ s.addEventListener("click", function () {
256
+ (r.el.classList.toggle("mc-dark"),
257
+ s.classList.toggle("active"),
258
+ r.render(),
259
+ r._renderNav());
260
+ }));
261
+ }
262
+ if (!1 !== e.export) {
263
+ var l = p("button", "", o);
264
+ ((l.title = "Export PNG"),
265
+ (l.innerHTML =
266
+ '<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>'),
267
+ l.addEventListener("click", function () {
268
+ r.exportPNG();
269
+ }));
270
+ }
271
+ if (!1 !== e.fullscreen) {
272
+ var c = p("button", "", o);
273
+ ((c.title = "Fullscreen"),
274
+ (c.innerHTML =
275
+ '<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>'),
276
+ c.addEventListener("click", function () {
277
+ document.fullscreenElement
278
+ ? (document.exitFullscreen || document.webkitExitFullscreen).call(
279
+ document,
280
+ )
281
+ : (i.requestFullscreen || i.webkitRequestFullscreen).call(i);
282
+ }),
283
+ ["fullscreenchange", "webkitfullscreenchange"].forEach(function (t) {
284
+ var fn = function () {
285
+ if (r._destroyed) return;
286
+ setTimeout(function () {
287
+ if (r._destroyed) return;
288
+ (r._initSize(), r.render(), r._renderNav());
289
+ }, 100);
290
+ };
291
+ document.addEventListener(t, fn);
292
+ r._externalListeners.push({ target: document, type: t, fn: fn });
293
+ }));
294
+ }
295
+ var d = p("div", "mc-wrap", i);
296
+ ((this._wrap = d),
297
+ (this.canvas = p("canvas", "", d)),
298
+ (this.ctx = this.canvas.getContext("2d")),
299
+ (this._tooltipEl = p("div", "mc-tooltip", d)),
300
+ (this._selEl = p("div", "mc-selection", d)),
301
+ (this._resetBtn = p("button", "mc-reset", d)),
302
+ (this._resetBtn.textContent = "Reset zoom"));
303
+ var h = p("div", "mc-nav", i);
304
+ ((this._navWrap = h),
305
+ (this._navCanvas = p("canvas", "", h)),
306
+ (this._navCtx = this._navCanvas.getContext("2d")),
307
+ (this._navMaskL = p("div", "mc-nav-mask left", h)),
308
+ (this._navMaskR = p("div", "mc-nav-mask right", h)));
309
+ var v = p("div", "mc-nav-win", h);
310
+ ((this._navWin = v),
311
+ (this._navHL = p("div", "mc-nav-h l", v)),
312
+ (this._navHR = p("div", "mc-nav-h r", v)),
313
+ (this._legendEl = p("div", "mc-legend", i)));
314
+ }),
315
+ (v.prototype._computeFullBounds = function () {
316
+ for (var t = 1 / 0, e = -1 / 0, i = 0; i < this.series.length; i++) {
317
+ var n = this.series[i].data;
318
+ n.length &&
319
+ ((t = Math.min(t, n[0][0])), (e = Math.max(e, n[n.length - 1][0])));
320
+ }
321
+ ((this.fullXMin = t), (this.fullXMax = e));
322
+ }),
323
+ (v.prototype._initSize = function () {
324
+ var t = window.devicePixelRatio || 1,
325
+ e = this._wrap.getBoundingClientRect().width,
326
+ i = Math.round(0.42 * e);
327
+ if (e <= 0) {
328
+ var self = this;
329
+ if (!this._sizeRetry) this._sizeRetry = 0;
330
+ if (this._sizeRetry < 20) {
331
+ this._sizeRetry++;
332
+ if (window.NMCharts && window.NMCharts.debug) console.log("[NMCharts:create] Width=0, retrying (" + this._sizeRetry + "/20)");
333
+ this._sizeTimer = setTimeout(function () { self._initSize(); if (self.W > 0) { if (window.NMCharts && window.NMCharts.debug) console.log("[NMCharts:create] Container now visible, width=" + self.W); self._entryProgress = 0; self._startEntryAnim(); } }, 66);
334
+ } else {
335
+ if (window.NMCharts && window.NMCharts.debug) console.warn("[NMCharts:create] WARNING: Container still 0px after 20 retries", { el: this.el.id || this.el.tagName, display: getComputedStyle(this.el).display });
336
+ }
337
+ return;
338
+ }
339
+ this._sizeRetry = 0;
340
+ if (window.NMCharts && window.NMCharts.debug && !this._sizeLogged) { this._sizeLogged = true; console.log("[NMCharts:create] Size OK", { width: e, height: i, dpr: t }); }
341
+ ((this.canvas.width = e * t),
342
+ (this.canvas.height = i * t),
343
+ (this.canvas.style.height = i + "px"),
344
+ this.ctx.setTransform(t, 0, 0, t, 0, 0),
345
+ (this.W = e),
346
+ (this.H = i),
347
+ (this.pX = 58),
348
+ (this.pY = 24),
349
+ (this.pW = e - 58 - 24),
350
+ (this.pH = i - 24 - 44));
351
+ var n = this._navWrap.getBoundingClientRect().width;
352
+ ((this._navCanvas.width = n * t),
353
+ (this._navCanvas.height = 48 * t),
354
+ this._navCtx.setTransform(t, 0, 0, t, 0, 0),
355
+ (this._nW = n),
356
+ (this._nH = 48));
357
+ }),
358
+ (v.prototype._buildLegend = function () {
359
+ var t = this;
360
+ ((this._legendEl.textContent = ""),
361
+ this.series.forEach(function (e) {
362
+ var i = p(
363
+ "div",
364
+ "mc-legend-item" + (e.visible ? "" : " disabled"),
365
+ t._legendEl,
366
+ ),
367
+ n =
368
+ "line" === e.type
369
+ ? "background:transparent;border-top:2.5px " +
370
+ ("dashed" === e.dashStyle
371
+ ? "dashed"
372
+ : "dotted" === e.dashStyle
373
+ ? "dotted"
374
+ : "solid") +
375
+ " " +
376
+ e.color +
377
+ ";height:0;margin-top:1px"
378
+ : "background:" + e.color;
379
+ (i.textContent = "",
380
+ (function() {
381
+ var sw = document.createElement("div"); sw.className = "mc-legend-swatch"; sw.style.cssText = n;
382
+ var sp = document.createElement("span"); sp.textContent = e.name;
383
+ i.appendChild(sw); i.appendChild(sp);
384
+ })(),
385
+ i.addEventListener("click", function () {
386
+ ((e.visible = !e.visible),
387
+ i.classList.toggle("disabled", !e.visible),
388
+ t.render(),
389
+ t._renderNav());
390
+ }));
391
+ }));
392
+ }),
393
+ (v.prototype._x2px = function (t) {
394
+ return (
395
+ this.pX +
396
+ ((t - this.viewXMin) / (this.viewXMax - this.viewXMin)) * this.pW
397
+ );
398
+ }),
399
+ (v.prototype._y2px = function (t, e) {
400
+ return this.pY + this.pH - ((t - e.min) / (e.max - e.min)) * this.pH;
401
+ }),
402
+ (v.prototype._px2x = function (t) {
403
+ return (
404
+ this.viewXMin +
405
+ ((t - this.pX) / this.pW) * (this.viewXMax - this.viewXMin)
406
+ );
407
+ }),
408
+ (v.prototype._yScale = function () {
409
+ for (var t = 1 / 0, e = -1 / 0, i = 0; i < this.series.length; i++)
410
+ if (this.series[i].visible)
411
+ for (var n = this.series[i].data, a = 0; a < n.length; a++)
412
+ n[a][0] >= this.viewXMin &&
413
+ n[a][0] <= this.viewXMax &&
414
+ ((t = Math.min(t, n[a][1])), (e = Math.max(e, n[a][1])));
415
+ return (
416
+ t === 1 / 0 && ((t = 0), (e = 100)),
417
+ (function (t, e) {
418
+ t === e && ((t -= 1), (e += 1));
419
+ for (
420
+ var i = s(e - t, !1),
421
+ n = s(i / 5, !0),
422
+ a = Math.floor(t / n) * n,
423
+ o = Math.ceil(e / n) * n,
424
+ r = [],
425
+ l = a;
426
+ l <= o + 0.5 * n;
427
+ l += n
428
+ )
429
+ r.push(Math.round(1e10 * l) / 1e10);
430
+ return { min: a, max: o, step: n, ticks: r };
431
+ })((t = Math.min(0, t)), e)
432
+ );
433
+ }),
434
+ (v.prototype._startEntryAnim = function () {
435
+ var t = this,
436
+ e = performance.now();
437
+ !(function i(n) {
438
+ if (t._destroyed) return;
439
+ var a = r((n - e) / 800, 0, 1);
440
+ ((t._entryProgress = 1 - Math.pow(1 - a, 3)),
441
+ t.render(),
442
+ t._renderNav(),
443
+ a < 1 && (t._rafId = requestAnimationFrame(i)));
444
+ })(e);
445
+ }),
446
+ (v.prototype.render = function () {
447
+ var t = this.ctx,
448
+ e = this._yScale(),
449
+ i = this,
450
+ a = h("grid", i._root),
451
+ o = h("muted", i._root),
452
+ s =
453
+ '11px -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif';
454
+ (t.clearRect(0, 0, this.W, this.H),
455
+ this.bands.forEach(function (n) {
456
+ var a = i._y2px(Math.min(n.to, e.max), e),
457
+ o = i._y2px(Math.max(n.from, e.min), e);
458
+ o <= i.pY ||
459
+ a >= i.pY + i.pH ||
460
+ ((a = r(a, i.pY, i.pY + i.pH)),
461
+ (o = r(o, i.pY, i.pY + i.pH)),
462
+ (t.fillStyle = n.color),
463
+ t.fillRect(i.pX, a, i.pW, o - a),
464
+ n.label &&
465
+ (t.save(),
466
+ (t.font = "9px " + s),
467
+ (t.fillStyle = n.labelColor || n.color),
468
+ (t.textAlign = "right"),
469
+ (t.textBaseline = "top"),
470
+ (t.globalAlpha = 0.7),
471
+ t.fillText(n.label, i.pX + i.pW - 4, a + 2),
472
+ t.restore()));
473
+ }),
474
+ t.save(),
475
+ (t.font = s),
476
+ (t.textAlign = "right"),
477
+ (t.textBaseline = "middle"),
478
+ e.ticks.forEach(function (n) {
479
+ var r = i._y2px(n, e);
480
+ ((t.strokeStyle = a),
481
+ (t.lineWidth = 1),
482
+ t.beginPath(),
483
+ t.moveTo(i.pX, Math.round(r) + 0.5),
484
+ t.lineTo(i.pX + i.pW, Math.round(r) + 0.5),
485
+ t.stroke(),
486
+ (t.fillStyle = o),
487
+ t.fillText(l(n), i.pX - 8, r));
488
+ }),
489
+ t.restore());
490
+ var p = (function (t, e, i) {
491
+ for (
492
+ var n = e - t,
493
+ a = 864e5,
494
+ o = [
495
+ a,
496
+ 2 * a,
497
+ 5 * a,
498
+ 7 * a,
499
+ 14 * a,
500
+ 30 * a,
501
+ 60 * a,
502
+ 90 * a,
503
+ 180 * a,
504
+ 365 * a,
505
+ ],
506
+ r = a,
507
+ s = 0;
508
+ s < o.length;
509
+ s++
510
+ )
511
+ if (n / o[s] <= i) {
512
+ r = o[s];
513
+ break;
514
+ }
515
+ for (var l = [], c = Math.ceil(t / r) * r; c <= e; c += r) l.push(c);
516
+ return l;
517
+ })(this.viewXMin, this.viewXMax, Math.floor(this.pW / 80));
518
+ (t.save(),
519
+ (t.font = s),
520
+ (t.textAlign = "center"),
521
+ (t.textBaseline = "top"),
522
+ (t.fillStyle = o),
523
+ p.forEach(function (e) {
524
+ var o = i._x2px(e);
525
+ o >= i.pX &&
526
+ o <= i.pX + i.pW &&
527
+ ((t.strokeStyle = a),
528
+ t.beginPath(),
529
+ t.moveTo(Math.round(o) + 0.5, i.pY + i.pH),
530
+ t.lineTo(Math.round(o) + 0.5, i.pY + i.pH + 5),
531
+ t.stroke(),
532
+ t.fillText(
533
+ (function (t) {
534
+ var e = new Date(t);
535
+ return e.getUTCDate() + " " + n[e.getUTCMonth()];
536
+ })(e),
537
+ o,
538
+ i.pY + i.pH + 8,
539
+ ));
540
+ }),
541
+ t.restore(),
542
+ (t.strokeStyle = a),
543
+ (t.lineWidth = 1),
544
+ t.beginPath(),
545
+ t.moveTo(this.pX, this.pY),
546
+ t.lineTo(this.pX, this.pY + this.pH),
547
+ t.lineTo(this.pX + this.pW, this.pY + this.pH),
548
+ t.stroke(),
549
+ t.save(),
550
+ t.beginPath(),
551
+ t.rect(this.pX, this.pY, this.pW, this.pH),
552
+ t.clip());
553
+ var v = this.pW * this._entryProgress;
554
+ if (
555
+ (this.series.forEach(function (n) {
556
+ if (n.visible) {
557
+ for (
558
+ var a = [], o = 0.05 * (i.viewXMax - i.viewXMin), r = 0;
559
+ r < n.data.length;
560
+ r++
561
+ ) {
562
+ var s = n.data[r][0],
563
+ l = n.data[r][1];
564
+ s < i.viewXMin - o ||
565
+ s > i.viewXMax + o ||
566
+ a.push([i._x2px(s), i._y2px(l, e), s]);
567
+ }
568
+ if (!(a.length < 2)) {
569
+ var h = i._y2px(e.min, e);
570
+ (t.save(), t.beginPath(), t.rect(i.pX, i.pY, v, i.pH), t.clip());
571
+ var p = a,
572
+ u = null;
573
+ if (i.forecastFrom) {
574
+ ((p = []), (u = []));
575
+ for (var f = 0; f < a.length; f++)
576
+ a[f][2] < i.forecastFrom ? p.push(a[f]) : u.push(a[f]);
577
+ p.length && u.length && u.unshift(p[p.length - 1]);
578
+ }
579
+ var m = "line" === n.type,
580
+ g =
581
+ "dashed" === n.dashStyle
582
+ ? [6, 4]
583
+ : "dotted" === n.dashStyle
584
+ ? [2, 3]
585
+ : null;
586
+ (x(p, !1), u && u.length >= 2 && x(u, !0), t.restore());
587
+ }
588
+ }
589
+ function x(e, a) {
590
+ if (!(e.length < 2)) {
591
+ if (!m) {
592
+ var o = t.createLinearGradient(0, i.pY, 0, h);
593
+ (o.addColorStop(0, d(n.color, 0.22)),
594
+ o.addColorStop(1, d(n.color, 0.02)),
595
+ t.beginPath(),
596
+ t.moveTo(e[0][0], h),
597
+ t.lineTo(e[0][0], e[0][1]),
598
+ c(t, e, !0, n.tension),
599
+ t.lineTo(e[e.length - 1][0], h),
600
+ t.closePath(),
601
+ (t.fillStyle = o),
602
+ t.fill());
603
+ }
604
+ var r = a ? [6, 4] : g;
605
+ (r && t.setLineDash(r),
606
+ t.beginPath(),
607
+ c(t, e, !1, n.tension),
608
+ (t.strokeStyle = n.color),
609
+ (t.lineWidth = n.lineWidth),
610
+ (t.lineJoin = "round"),
611
+ (t.lineCap = "round"),
612
+ t.stroke(),
613
+ r && t.setLineDash([]));
614
+ }
615
+ }
616
+ }),
617
+ this._hoverIdx >= 0 && this._entryProgress >= 1)
618
+ ) {
619
+ var u = null;
620
+ (this.series.forEach(function (n) {
621
+ if (n.visible && !(i._hoverIdx >= n.data.length)) {
622
+ var a = n.data[i._hoverIdx],
623
+ o = i._x2px(a[0]),
624
+ r = i._y2px(a[1], e);
625
+ ((u = o),
626
+ t.beginPath(),
627
+ t.arc(o, r, 5, 0, 2 * Math.PI),
628
+ (t.fillStyle = h("card", i._root)),
629
+ t.fill(),
630
+ (t.strokeStyle = n.color),
631
+ (t.lineWidth = 2.5),
632
+ t.stroke());
633
+ }
634
+ }),
635
+ null !== u &&
636
+ ((t.strokeStyle = d(o, 0.4)),
637
+ (t.lineWidth = 1),
638
+ t.setLineDash([4, 3]),
639
+ t.beginPath(),
640
+ t.moveTo(Math.round(u) + 0.5, i.pY),
641
+ t.lineTo(Math.round(u) + 0.5, i.pY + i.pH),
642
+ t.stroke(),
643
+ t.setLineDash([])));
644
+ }
645
+ t.restore();
646
+ }),
647
+ (v.prototype._renderNav = function () {
648
+ var t = this._navCtx,
649
+ e = this._nW,
650
+ i = this._nH,
651
+ n = this,
652
+ a = e - 2 - 2,
653
+ o = i - 4 - 4;
654
+ t.clearRect(0, 0, e, i);
655
+ var r = 1 / 0,
656
+ s = -1 / 0;
657
+ (this.series.forEach(function (t) {
658
+ t.visible &&
659
+ t.data.forEach(function (t) {
660
+ ((r = Math.min(r, t[1])), (s = Math.max(s, t[1])));
661
+ });
662
+ }),
663
+ r === 1 / 0 && ((r = 0), (s = 100)),
664
+ (r = Math.min(0, r)));
665
+ var l = 4 + o;
666
+ this.series.forEach(function (e) {
667
+ if (e.visible) {
668
+ var i = e.data.map(function (t) {
669
+ return [
670
+ 2 + ((t[0] - n.fullXMin) / (n.fullXMax - n.fullXMin)) * a,
671
+ 4 + o - ((t[1] - r) / (s - r)) * o,
672
+ ];
673
+ });
674
+ if (!(i.length < 2)) {
675
+ if ("line" !== e.type) {
676
+ var h = t.createLinearGradient(0, 4, 0, l);
677
+ (h.addColorStop(0, d(e.color, 0.18)),
678
+ h.addColorStop(1, d(e.color, 0.02)),
679
+ t.beginPath(),
680
+ t.moveTo(i[0][0], l),
681
+ t.lineTo(i[0][0], i[0][1]),
682
+ c(t, i, !0, e.tension),
683
+ t.lineTo(i[i.length - 1][0], l),
684
+ t.closePath(),
685
+ (t.fillStyle = h),
686
+ t.fill());
687
+ }
688
+ var p =
689
+ "dashed" === e.dashStyle
690
+ ? [4, 3]
691
+ : "dotted" === e.dashStyle
692
+ ? [2, 2]
693
+ : null;
694
+ (p && t.setLineDash(p),
695
+ t.beginPath(),
696
+ c(t, i, !1, e.tension),
697
+ (t.strokeStyle = d(e.color, 0.6)),
698
+ (t.lineWidth = 1.2),
699
+ t.stroke(),
700
+ p && t.setLineDash([]));
701
+ }
702
+ }
703
+ });
704
+ var h =
705
+ ((this.viewXMin - this.fullXMin) / (this.fullXMax - this.fullXMin)) *
706
+ 100,
707
+ p =
708
+ ((this.fullXMax - this.viewXMax) / (this.fullXMax - this.fullXMin)) *
709
+ 100;
710
+ ((this._navWin.style.left = h + "%"),
711
+ (this._navWin.style.right = p + "%"),
712
+ (this._navMaskL.style.width = h + "%"),
713
+ (this._navMaskR.style.width = p + "%"));
714
+ }),
715
+ (v.prototype._bindNavigator = function () {
716
+ var t,
717
+ e,
718
+ i,
719
+ n = this,
720
+ a = null;
721
+ function o(o, r) {
722
+ (o.preventDefault(),
723
+ o.stopPropagation(),
724
+ (a = r),
725
+ (t = o.clientX),
726
+ (e = n.viewXMin),
727
+ (i = n.viewXMax),
728
+ document.addEventListener("mousemove", s),
729
+ document.addEventListener("mouseup", l));
730
+ }
731
+ function s(o) {
732
+ var s = n._navWrap.getBoundingClientRect(),
733
+ l = ((o.clientX - t) / s.width) * (n.fullXMax - n.fullXMin),
734
+ c = 1728e5;
735
+ if ("move" === a) {
736
+ var d = e + l,
737
+ h = i + l;
738
+ (d < n.fullXMin && ((h += n.fullXMin - d), (d = n.fullXMin)),
739
+ h > n.fullXMax && ((d -= h - n.fullXMax), (h = n.fullXMax)),
740
+ (n.viewXMin = d),
741
+ (n.viewXMax = h));
742
+ } else
743
+ "left" === a
744
+ ? (n.viewXMin = r(e + l, n.fullXMin, n.viewXMax - c))
745
+ : (n.viewXMax = r(i + l, n.viewXMin + c, n.fullXMax));
746
+ ((n._zoomed = n.viewXMin > n.fullXMin || n.viewXMax < n.fullXMax),
747
+ n._resetBtn.classList.toggle("visible", n._zoomed),
748
+ n.render(),
749
+ n._renderNav());
750
+ }
751
+ function l() {
752
+ ((a = null),
753
+ document.removeEventListener("mousemove", s),
754
+ document.removeEventListener("mouseup", l));
755
+ }
756
+ (this._navWin.addEventListener("mousedown", function (t) {
757
+ o(t, "move");
758
+ }),
759
+ this._navHL.addEventListener("mousedown", function (t) {
760
+ o(t, "left");
761
+ }),
762
+ this._navHR.addEventListener("mousedown", function (t) {
763
+ o(t, "right");
764
+ }),
765
+ this._navWrap.addEventListener("mousedown", function (t) {
766
+ if (t.target === n._navCanvas) {
767
+ var e = n._navWrap.getBoundingClientRect(),
768
+ i =
769
+ n.fullXMin +
770
+ ((t.clientX - e.left) / e.width) * (n.fullXMax - n.fullXMin),
771
+ a = n.viewXMax - n.viewXMin,
772
+ o = i - a / 2,
773
+ r = i + a / 2;
774
+ (o < n.fullXMin && ((r += n.fullXMin - o), (o = n.fullXMin)),
775
+ r > n.fullXMax && ((o -= r - n.fullXMax), (r = n.fullXMax)),
776
+ (n._zoomed = !0),
777
+ n._resetBtn.classList.add("visible"),
778
+ n._animateTo(o, r));
779
+ }
780
+ }));
781
+ }),
782
+ (v.prototype._animateTo = function (t, e) {
783
+ var i = { a: this.viewXMin, b: this.viewXMax },
784
+ n = this,
785
+ a = performance.now();
786
+ !(function s(l) {
787
+ if (n._destroyed) return;
788
+ var c = r((l - a) / 400, 0, 1),
789
+ d = 1 - Math.pow(1 - c, 3);
790
+ ((n.viewXMin = o(i.a, t, d)),
791
+ (n.viewXMax = o(i.b, e, d)),
792
+ n.render(),
793
+ n._renderNav(),
794
+ c < 1 && (n._rafId = requestAnimationFrame(s)));
795
+ })(a);
796
+ }),
797
+ (v.prototype._bindEvents = function () {
798
+ var t,
799
+ e = this,
800
+ i = this.canvas;
801
+ function n(t) {
802
+ var e = i.getBoundingClientRect();
803
+ return { x: t.clientX - e.left, y: t.clientY - e.top };
804
+ }
805
+ function a(t) {
806
+ return (
807
+ t.x >= e.pX && t.x <= e.pX + e.pW && t.y >= e.pY && t.y <= e.pY + e.pH
808
+ );
809
+ }
810
+ (function () {
811
+ var resizeFn = function () {
812
+ (clearTimeout(e._resizeTimer),
813
+ (e._resizeTimer = setTimeout(function () {
814
+ if (e._destroyed) return;
815
+ (e._initSize(), e.render(), e._renderNav());
816
+ }, 80)));
817
+ };
818
+ window.addEventListener("resize", resizeFn);
819
+ e._externalListeners.push({ target: window, type: "resize", fn: resizeFn });
820
+ })(),
821
+ i.addEventListener("mousedown", function (t) {
822
+ var o = n(t);
823
+ a(o) &&
824
+ (t.shiftKey && e._zoomed
825
+ ? ((e._panning = !0),
826
+ (e._panAnchorX = o.x),
827
+ (e._panViewStart = e.viewXMin),
828
+ (e._panViewEnd = e.viewXMax),
829
+ (i.style.cursor = "grabbing"))
830
+ : ((e._dragStart = o.x),
831
+ (e._dragging = !0),
832
+ (e._selEl.style.display = "block"),
833
+ (e._selEl.style.left = o.x + "px"),
834
+ (e._selEl.style.width = "0px")));
835
+ }),
836
+ i.addEventListener("mousemove", function (t) {
837
+ var o = n(t);
838
+ if (e._panning) {
839
+ var s = o.x - e._panAnchorX,
840
+ l = e._panViewEnd - e._panViewStart,
841
+ c = (-s / e.pW) * l,
842
+ d = e._panViewStart + c,
843
+ h = e._panViewEnd + c;
844
+ return (
845
+ d < e.fullXMin && ((h += e.fullXMin - d), (d = e.fullXMin)),
846
+ h > e.fullXMax && ((d -= h - e.fullXMax), (h = e.fullXMax)),
847
+ (e.viewXMin = d),
848
+ (e.viewXMax = h),
849
+ e.render(),
850
+ void e._renderNav()
851
+ );
852
+ }
853
+ if (e._dragging) {
854
+ var p = Math.min(e._dragStart, o.x),
855
+ v = Math.abs(o.x - e._dragStart);
856
+ p = r(p, e.pX, e.pX + e.pW);
857
+ var u = r(p + v, e.pX, e.pX + e.pW);
858
+ return (
859
+ (e._selEl.style.left = p + "px"),
860
+ void (e._selEl.style.width = u - p + "px")
861
+ );
862
+ }
863
+ if (a(o)) {
864
+ i.style.cursor = t.shiftKey && e._zoomed ? "grab" : "crosshair";
865
+ var f = (function (t) {
866
+ for (
867
+ var i = e._px2x(t), n = null, a = 0;
868
+ a < e.series.length;
869
+ a++
870
+ )
871
+ if (e.series[a].visible) {
872
+ n = e.series[a].data;
873
+ break;
874
+ }
875
+ if (!n || !n.length) return -1;
876
+ for (var o = 0, r = 1 / 0, s = 0; s < n.length; s++) {
877
+ var l = Math.abs(n[s][0] - i);
878
+ l < r && ((r = l), (o = s));
879
+ }
880
+ return o;
881
+ })(o.x);
882
+ (f !== e._hoverIdx && ((e._hoverIdx = f), e.render()),
883
+ e._showTooltip(o, f));
884
+ } else e._hideTooltip();
885
+ }),
886
+ (function () {
887
+ var mouseupFn = function () {
888
+ if (e._panning)
889
+ return ((e._panning = !1), void (i.style.cursor = "crosshair"));
890
+ if (e._dragging) {
891
+ ((e._dragging = !1), (e._selEl.style.display = "none"));
892
+ var t = parseFloat(e._selEl.style.width);
893
+ if (t < 10) e._dragStart = null;
894
+ else {
895
+ var n = parseFloat(e._selEl.style.left);
896
+ ((e._zoomed = !0),
897
+ e._resetBtn.classList.add("visible"),
898
+ e._animateTo(e._px2x(n), e._px2x(n + t)),
899
+ (e._dragStart = null));
900
+ }
901
+ }
902
+ };
903
+ window.addEventListener("mouseup", mouseupFn);
904
+ e._externalListeners.push({ target: window, type: "mouseup", fn: mouseupFn });
905
+ })(),
906
+ i.addEventListener("mouseleave", function () {
907
+ e._hideTooltip();
908
+ }),
909
+ i.addEventListener("dblclick", function (t) {
910
+ (t.preventDefault(),
911
+ e._zoomed &&
912
+ ((e._zoomed = !1),
913
+ e._resetBtn.classList.remove("visible"),
914
+ e._animateTo(e.fullXMin, e.fullXMax)));
915
+ }),
916
+ i.addEventListener(
917
+ "wheel",
918
+ function (t) {
919
+ var i = n(t);
920
+ if (a(i)) {
921
+ t.preventDefault();
922
+ var o = t.deltaY > 0 ? 1.15 : 1 / 1.15,
923
+ r = e._px2x(i.x),
924
+ s = e.viewXMax - e.viewXMin,
925
+ l = s * o;
926
+ if (!(l < 1728e5)) {
927
+ var c = (r - e.viewXMin) / s,
928
+ d = Math.max(r - c * l, e.fullXMin),
929
+ h = Math.min(r + (1 - c) * l, e.fullXMax);
930
+ ((e.viewXMin = d),
931
+ (e.viewXMax = h),
932
+ (e._zoomed = d > e.fullXMin || h < e.fullXMax),
933
+ e._resetBtn.classList.toggle("visible", e._zoomed),
934
+ e.render(),
935
+ e._renderNav());
936
+ }
937
+ }
938
+ },
939
+ { passive: !1 },
940
+ ),
941
+ this._resetBtn.addEventListener("click", function () {
942
+ ((e._zoomed = !1),
943
+ e._resetBtn.classList.remove("visible"),
944
+ e._animateTo(e.fullXMin, e.fullXMax));
945
+ }),
946
+ (function () {
947
+ var keydownFn = function (t) {
948
+ if (e._destroyed) return;
949
+ if ("INPUT" !== t.target.tagName && "TEXTAREA" !== t.target.tagName) {
950
+ var i = e.viewXMax - e.viewXMin,
951
+ n = 0.15 * i;
952
+ if ("ArrowLeft" === t.key) {
953
+ var a = Math.max(e.viewXMin - n, e.fullXMin);
954
+ e._animateTo(a, a + i);
955
+ } else if ("ArrowRight" === t.key) {
956
+ var o = Math.min(e.viewXMax + n, e.fullXMax);
957
+ e._animateTo(o - i, o);
958
+ } else if ("+" === t.key || "=" === t.key) {
959
+ var r = 0.7 * i,
960
+ s = (e.viewXMin + e.viewXMax) / 2;
961
+ ((e._zoomed = !0),
962
+ e._resetBtn.classList.add("visible"),
963
+ e._animateTo(s - r / 2, s + r / 2));
964
+ } else if ("-" === t.key) {
965
+ var l = Math.min(1.4 * i, e.fullXMax - e.fullXMin),
966
+ c = (e.viewXMin + e.viewXMax) / 2,
967
+ d = Math.max(c - l / 2, e.fullXMin),
968
+ h = Math.min(c + l / 2, e.fullXMax);
969
+ ((e._zoomed = d > e.fullXMin || h < e.fullXMax),
970
+ e._resetBtn.classList.toggle("visible", e._zoomed),
971
+ e._animateTo(d, h));
972
+ } else
973
+ "Escape" === t.key &&
974
+ e._zoomed &&
975
+ ((e._zoomed = !1),
976
+ e._resetBtn.classList.remove("visible"),
977
+ e._animateTo(e.fullXMin, e.fullXMax));
978
+ }
979
+ };
980
+ document.addEventListener("keydown", keydownFn);
981
+ e._externalListeners.push({ target: document, type: "keydown", fn: keydownFn });
982
+ })();
983
+ var o = null;
984
+ (i.addEventListener(
985
+ "touchstart",
986
+ function (t) {
987
+ (1 === t.touches.length
988
+ ? ((e._panning = !0),
989
+ (e._panAnchorX =
990
+ t.touches[0].clientX - i.getBoundingClientRect().left),
991
+ (e._panViewStart = e.viewXMin),
992
+ (e._panViewEnd = e.viewXMax))
993
+ : 2 === t.touches.length &&
994
+ ((e._panning = !1),
995
+ (o = Math.abs(t.touches[1].clientX - t.touches[0].clientX))),
996
+ t.preventDefault());
997
+ },
998
+ { passive: !1 },
999
+ ),
1000
+ i.addEventListener(
1001
+ "touchmove",
1002
+ function (t) {
1003
+ if (1 === t.touches.length && e._panning) {
1004
+ var n =
1005
+ t.touches[0].clientX -
1006
+ i.getBoundingClientRect().left -
1007
+ e._panAnchorX,
1008
+ a = e._panViewEnd - e._panViewStart,
1009
+ r = (-n / e.pW) * a,
1010
+ s = e._panViewStart + r,
1011
+ l = e._panViewEnd + r;
1012
+ (s < e.fullXMin && ((l += e.fullXMin - s), (s = e.fullXMin)),
1013
+ l > e.fullXMax && ((s -= l - e.fullXMax), (l = e.fullXMax)),
1014
+ (e.viewXMin = s),
1015
+ (e.viewXMax = l),
1016
+ e.render(),
1017
+ e._renderNav());
1018
+ } else if (2 === t.touches.length && o) {
1019
+ var c = Math.abs(t.touches[1].clientX - t.touches[0].clientX),
1020
+ d = o / c,
1021
+ h =
1022
+ (t.touches[0].clientX + t.touches[1].clientX) / 2 -
1023
+ i.getBoundingClientRect().left,
1024
+ p = e._px2x(h),
1025
+ v = e.viewXMax - e.viewXMin,
1026
+ u = v * d;
1027
+ if (u < 1728e5) return void t.preventDefault();
1028
+ var f = (p - e.viewXMin) / v;
1029
+ ((e.viewXMin = Math.max(p - f * u, e.fullXMin)),
1030
+ (e.viewXMax = Math.min(p + (1 - f) * u, e.fullXMax)),
1031
+ (e._zoomed = !0),
1032
+ e._resetBtn.classList.add("visible"),
1033
+ (o = c),
1034
+ e.render(),
1035
+ e._renderNav());
1036
+ }
1037
+ t.preventDefault();
1038
+ },
1039
+ { passive: !1 },
1040
+ ),
1041
+ i.addEventListener("touchend", function () {
1042
+ ((e._panning = !1), (o = null));
1043
+ }));
1044
+ }),
1045
+ (v.prototype._showTooltip = function (t, e) {
1046
+ if (e < 0) this._hideTooltip();
1047
+ else {
1048
+ var o = null;
1049
+ var entries = [];
1050
+ this.series.forEach(function (t) {
1051
+ if (!t.visible || e >= t.data.length) return;
1052
+ if (!o) o = t.data[e][0];
1053
+ entries.push({ color: t.color, name: t.name, value: l(t.data[e][1]) });
1054
+ });
1055
+ if (o) {
1056
+ // Build tooltip with safe DOM methods (no innerHTML)
1057
+ this._tooltipEl.textContent = "";
1058
+ var dateDiv = document.createElement("div"); dateDiv.className = "mc-tooltip-date";
1059
+ dateDiv.textContent = (function (t) {
1060
+ var e = new Date(t);
1061
+ return a[e.getUTCDay()] + ", " + n[e.getUTCMonth()] + " " + e.getUTCDate() + ", " + e.getUTCFullYear();
1062
+ })(o);
1063
+ this._tooltipEl.appendChild(dateDiv);
1064
+ entries.forEach(function (entry) {
1065
+ var row = document.createElement("div"); row.className = "mc-tooltip-row";
1066
+ var dot = document.createElement("div"); dot.className = "mc-tooltip-dot"; dot.style.background = entry.color;
1067
+ var nm = document.createElement("span"); nm.textContent = entry.name;
1068
+ var val = document.createElement("span"); val.className = "mc-tooltip-val"; val.textContent = entry.value;
1069
+ row.appendChild(dot); row.appendChild(nm); row.appendChild(val);
1070
+ this._tooltipEl.appendChild(row);
1071
+ }.bind(this));
1072
+ this._tooltipEl.classList.add("visible");
1073
+ var s = this._tooltipEl.offsetWidth,
1074
+ c = this._tooltipEl.offsetHeight,
1075
+ d = t.x + 16,
1076
+ h = t.y - c / 2;
1077
+ (d + s > this.W - 8 && (d = t.x - s - 16),
1078
+ (h = r(h, 4, this.H - c - 4)),
1079
+ (this._tooltipEl.style.left = d + "px"),
1080
+ (this._tooltipEl.style.top = h + "px"));
1081
+ } else this._hideTooltip();
1082
+ }
1083
+ }),
1084
+ (v.prototype._hideTooltip = function () {
1085
+ (this._tooltipEl.classList.remove("visible"),
1086
+ this._hoverIdx >= 0 && ((this._hoverIdx = -1), this.render()));
1087
+ }),
1088
+ (v.prototype.exportPNG = function (t) {
1089
+ var e = document.createElement("a");
1090
+ ((e.download = t || "chart.png"),
1091
+ (e.href = this.canvas.toDataURL("image/png")),
1092
+ e.click());
1093
+ }),
1094
+ (v.prototype.setDarkMode = function (t) {
1095
+ (this.el.classList.toggle("mc-dark", t),
1096
+ this.render(),
1097
+ this._renderNav());
1098
+ }),
1099
+ (v.prototype.updateSeries = function (t) {
1100
+ ((this.series = t.map(function (t) {
1101
+ return {
1102
+ name: t.name,
1103
+ data: t.data.slice().sort(function (t, e) {
1104
+ return t[0] - e[0];
1105
+ }),
1106
+ color: t.color,
1107
+ type: t.type || "area",
1108
+ dashStyle: t.dashStyle || null,
1109
+ lineWidth: t.lineWidth || 2.5,
1110
+ tension: typeof t.tension === "number" ? t.tension : 1,
1111
+ visible: !0,
1112
+ };
1113
+ })),
1114
+ this._computeFullBounds(),
1115
+ (this.viewXMin = this.fullXMin),
1116
+ (this.viewXMax = this.fullXMax),
1117
+ (this._zoomed = !1),
1118
+ this._resetBtn.classList.remove("visible"),
1119
+ this._buildLegend(),
1120
+ this.render(),
1121
+ this._renderNav());
1122
+ }),
1123
+ (v.prototype.destroy = function () {
1124
+ this._destroyed = !0;
1125
+ // Cancel pending animations
1126
+ if (this._rafId) { cancelAnimationFrame(this._rafId); this._rafId = null; }
1127
+ // Clear resize debounce timer
1128
+ if (this._resizeTimer) { clearTimeout(this._resizeTimer); this._resizeTimer = null; }
1129
+ if (this._sizeTimer) { clearTimeout(this._sizeTimer); this._sizeTimer = null; }
1130
+ // Remove all external listeners (window/document)
1131
+ if (this._externalListeners) {
1132
+ for (var i = 0; i < this._externalListeners.length; i++) {
1133
+ var l = this._externalListeners[i];
1134
+ l.target.removeEventListener(l.type, l.fn);
1135
+ }
1136
+ this._externalListeners = [];
1137
+ }
1138
+ // Remove DOM
1139
+ if (this._root && this._root.parentNode) {
1140
+ this._root.parentNode.removeChild(this._root);
1141
+ }
1142
+ // Decrement instance count (keep styles — category charts may depend on them)
1143
+ _instanceCount--;
1144
+ if (_instanceCount < 0) _instanceCount = 0;
1145
+ }
1146
+ // Null out references to aid GC
1147
+ this.canvas = null;
1148
+ this.ctx = null;
1149
+ this._navCanvas = null;
1150
+ this._navCtx = null;
1151
+ this._tooltipEl = null;
1152
+ this.el = null;
1153
+ }),
1154
+ (v.create = function (t, e) {
1155
+ return new v(t, e);
1156
+ }));
1157
+ "object" == typeof module && module.exports
1158
+ ? (module.exports = v)
1159
+ : "function" == typeof define && define.amd
1160
+ ? define(function () {
1161
+ return v;
1162
+ })
1163
+ : (t.NMCharts = v);
1164
+ })(
1165
+ "undefined" != typeof window
1166
+ ? window
1167
+ : "undefined" != typeof globalThis
1168
+ ? globalThis
1169
+ : this,
1170
+ );