@malinconico/nmcharts 2.3.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-categories.js +5597 -0
- package/nmcharts-categories.min.js +1 -0
- package/nmcharts-extras.js +320 -0
- package/nmcharts-extras.min.js +1 -0
- package/nmcharts.d.ts +369 -0
- package/nmcharts.esm.js +14 -0
- package/nmcharts.js +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t){"use strict";var e=t.NMCharts;if(!e)throw new Error("NMCharts-Categories: NMCharts must be loaded first.");var i=window.devicePixelRatio||1,s=600,o=400,a={top:50,right:24,bottom:60,left:60},r='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',l=["#6366f1","#10b981","#f59e0b","#ef4444","#8b5cf6","#06b6d4","#ec4899","#14b8a6"];function n(t,e){return getComputedStyle(t).getPropertyValue(e).trim()}function d(t){return{bg:n(t,"--mc-bg")||"#f5f7fa",card:n(t,"--mc-card")||"#fff",text:n(t,"--mc-text")||"#1e293b",text2:n(t,"--mc-text2")||"#475569",muted:n(t,"--mc-muted")||"#94a3b8",grid:n(t,"--mc-grid")||"#e2e8f0",border:n(t,"--mc-border")||"#e2e8f0",hover:n(t,"--mc-hover")||"rgba(0,0,0,.04)",ttBg:n(t,"--mc-tt-bg")||"#1e293b",ttFg:n(t,"--mc-tt-fg")||"#fff",btn:n(t,"--mc-btn")||"#6366f1",btnH:n(t,"--mc-btn-h")||"#4f46e5"}}function c(t,e,i){return Math.max(e,Math.min(i,t))}function _(t){if(t<=0)return 10;var e=Math.pow(10,Math.floor(Math.log10(t))),i=t/e;return i<=1?e:i<=2?2*e:i<=5?5*e:10*e}function p(t,e){var i=t/e,s=Math.pow(10,Math.floor(Math.log10(i))),o=i/s;return o<=1?s:o<=2?2*s:o<=5?5*s:10*s}function v(t){return Math.abs(t)>=1e6?(t/1e6).toFixed(1)+"M":Math.abs(t)>=1e3?(t/1e3).toFixed(1)+"k":t%1==0?String(t):t.toFixed(1)}function g(t){return 1-Math.pow(1-t,3)}function f(t){var e=1.70158;return 1+2.70158*Math.pow(t-1,3)+e*Math.pow(t-1,2)}function u(t,e,i){var s=document.createElement(t);return e&&(s.className=e),i&&i.appendChild(s),s}function b(t){var e=t.replace("#","");return 3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),[parseInt(e.substr(0,2),16),parseInt(e.substr(2,2),16),parseInt(e.substr(4,2),16)]}function m(t,e){var i=b(t);return"rgb("+Math.round(i[0]+(255-i[0])*e)+","+Math.round(i[1]+(255-i[1])*e)+","+Math.round(i[2]+(255-i[2])*e)+")"}function x(t,e,i){return null!=t[e]?t[e]:i}var y='<svg viewBox="0 0 24 24"><path d="M21 12.79A9 9 0 1 1 11.21 3a7 7 0 0 0 9.79 9.79z"/></svg>',M='<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>';function S(t,e,i){if(this.type=i,this.el="string"==typeof t?document.querySelector(t):t,!this.el)throw new Error("NMCharts-Categories: container not found");this.opts=e||{},this.categories=e.categories||[];var r=this.opts;this._height=x(r,"height",o),this._opacity=x(r,"opacity",x(r,"fillOpacity",.85)),this._hoverOpacity=x(r,"hoverOpacity",1),this._borderRadius=x(r,"borderRadius",4),this._showValues=x(r,"showValues",!0),this._valueSize=x(r,"valueSize",10),this._valueColor=x(r,"valueColor",null),this._gridLines=x(r,"gridLines",!0),this._gridColor=x(r,"gridColor",null),this._gridDashed=x(r,"gridDashed",!1),this._animDuration=x(r,"animDuration",s),this._toolbar=Object.assign({dark:!0,export:!0},r.toolbar||{}),this._padding=Object.assign({},a,r.padding||{}),this._legendPosition=x(r,"legendPosition","bottom"),this._legendHidden=x(r,"legendHidden",!1),this._userColors=r.colors||null,this._gradient=x(r,"gradient",!0),this._gradientOpacity=r.gradientOpacity||[.9,.4],this._tooltipEnabled=x(r,"tooltip",!0),this._responsive=x(r,"responsive",!0),this._barWidth=x(r,"barWidth",null),this._barGap=x(r,"barGap",4),this._groupPadding=x(r,"groupPadding",.25),this._stacked=x(r,"stacked",!1),this._borderWidth=x(r,"borderWidth",0),this._borderColor=x(r,"borderColor","transparent"),this._stackLabels=x(r,"stackLabels",!0),this._showTotal=x(r,"showTotal",!1),this.series=(e.series||[]).map(function(t,e){var i=r.colors||l;return{name:t.name||"Series "+(e+1),data:t.data||[],color:t.color||i[e%i.length],type:t.type||null,visible:!0}}),this._hoverCat=-1,this._hoverSeries=-1,this._animProgress=0,this._animStart=0,this._rafId=0,this._buildDOM(),this._initSize(),this._startAnimation(),this._bindEvents()}function C(t,e){S.call(this,t,e,"column")}function w(t,e){S.call(this,t,e,"bar")}function k(t,e){S.call(this,t,e,"barStacked")}function T(t,e){S.call(this,t,e,"lollipop")}function P(t,e){S.call(this,t,e,"combo")}function A(t,e){if(this.type="donut",this.el="string"==typeof t?document.querySelector(t):t,!this.el)throw new Error("NMCharts-Categories: container not found");this.opts=e||{},this._innerRadius=x(e,"innerRadius",.6),this._padAngle=x(e,"padAngle",.02),this._cornerRadius=x(e,"cornerRadius",0),this._centerLabel=x(e,"centerLabel",null),this._centerSubLabel=x(e,"centerSubLabel",null),this._hoverScale=x(e,"hoverScale",1.06),this._strokeWidth=x(e,"strokeWidth",2),this._strokeColor=x(e,"strokeColor","auto"),this._height=x(e,"height",o),this._opacity=x(e,"opacity",x(e,"fillOpacity",.88)),this._hoverOpacity=x(e,"hoverOpacity",1),this._animDuration=x(e,"animDuration",s),this._toolbar=Object.assign({dark:!0,export:!0},e.toolbar||{}),this._legendPosition=x(e,"legendPosition","bottom"),this._legendHidden=x(e,"legendHidden",!1),this._tooltipEnabled=x(e,"tooltip",!0),this._responsive=x(e,"responsive",!0),this._gradient=x(e,"gradient",!1),this._gradientOpacity=e.gradientOpacity||[.9,.4],this.segments=(e.segments||[]).map(function(t,i){var s=e.colors||l;return{label:t.label||"Segment "+(i+1),value:t.value||0,color:t.color||s[i%s.length],visible:!0}}),this._hoverIndex=-1,this._selectedIndex=-1,this._animProgress=0,this._animStart=0,this._rafId=0,this._buildDonutDOM(),this._initSize(),this._startAnimation(),this._bindDonutEvents()}function E(t,e){if(this.type="gauge",this.el="string"==typeof t?document.querySelector(t):t,!this.el)throw new Error("NMCharts-Categories: container not found");this.opts=e||{},this.value=e.value||0,this.min=null!=e.min?e.min:0,this.max=null!=e.max?e.max:100,this.zones=e.zones||[{from:0,to:40,color:"#10b981"},{from:40,to:70,color:"#f59e0b"},{from:70,to:100,color:"#ef4444"}],this._needleColor=x(e,"needleColor",null),this._needleWidth=x(e,"needleWidth",2.5),this._arcWidth=x(e,"arcWidth",.22),this._showTicks=x(e,"showTicks",!0),this._unit=x(e,"unit",e.unit||""),this._height=x(e,"height",o),this._animDuration=x(e,"animDuration",s),this._toolbar=Object.assign({dark:!0,export:!0},e.toolbar||{}),this._responsive=x(e,"responsive",!0),this._animProgress=0,this._animStart=0,this._rafId=0,this._buildGaugeDOM(),this._initSize(),this._startAnimation(),this._bindGaugeEvents()}function L(t,e){if(this.type="heatmap",this.el="string"==typeof t?document.querySelector(t):t,!this.el)throw new Error("NMCharts-Categories: container not found");this.opts=e||{},this.xLabels=e.xLabels||e.xCategories||[],this.yLabels=e.yLabels||e.yCategories||[],this.data=e.data||[];var i=e.colorRange;i&&i.min&&i.max?this.colorRange=[i.min,i.max]:this.colorRange=(Array.isArray(i)?i:null)||["#dbeafe","#1e40af"],this._cellRadius=x(e,"cellRadius",3),this._cellGap=x(e,"cellGap",2),this._showCellValues=x(e,"showCellValues",!0),this._cellFontSize=x(e,"cellFontSize",11),this._height=x(e,"height",o),this._animDuration=x(e,"animDuration",s),this._toolbar=Object.assign({dark:!0,export:!0},e.toolbar||{}),this._tooltipEnabled=x(e,"tooltip",!0),this._responsive=x(e,"responsive",!0),this._padding=Object.assign({},a,e.padding||{}),this._hoverCell=null,this._animProgress=0,this._animStart=0,this._rafId=0,this._buildHeatmapDOM(),this._initSize(),this._computeMinMax(),this._startAnimation(),this._bindHeatmapEvents()}function B(t,e){if(this.type="radar",this.el="string"==typeof t?document.querySelector(t):t,!this.el)throw new Error("NMCharts-Categories: container not found");if(this.opts=e||{},this.categories=e.categories||[],this._levels=x(e,"levels",5),this._fillOpacity=x(e,"fillOpacity",.2),this._lineWidth=x(e,"lineWidth",2),this._dotRadius=x(e,"dotRadius",4),this._showValues=x(e,"showValues",!1),this._gridStyle=x(e,"gridStyle","polygon"),this._axisLabels=x(e,"axisLabels",!0),this._max=x(e,"max",null),this._height=x(e,"height",o),this._animDuration=x(e,"animDuration",s),this._toolbar=Object.assign({dark:!0,export:!0},e.toolbar||{}),this._legendPosition=x(e,"legendPosition","bottom"),this._legendHidden=x(e,"legendHidden",!1),this._tooltipEnabled=x(e,"tooltip",!0),this._responsive=x(e,"responsive",!0),this.series=(e.series||[]).map(function(t,i){var s=e.colors||l;return{name:t.name||"Series "+(i+1),data:t.data||[],color:t.color||s[i%s.length],visible:!0}}),null==this._max){var i=0;this.series.forEach(function(t){t.data.forEach(function(t){t>i&&(i=t)})}),this._max=_(1.1*i)}this._hoverAxis=-1,this._animProgress=0,this._animStart=0,this._rafId=0,this._buildRadarDOM(),this._initSize(),this._startAnimation(),this._bindRadarEvents()}function H(t,e){this._barWidth=x(e,"barWidth",32),this._barOpacity=x(e,"barOpacity",.7),this._lineWidth=x(e,"lineWidth",2.5),this._lineTension=x(e,"lineTension",.4),this._dualAxis=x(e,"dualAxis",!1),S.call(this,t,e,"lineBar")}function W(t,e){this._showTotal=x(e,"showTotal",!0),this._showConnectors=x(e,"showConnectors",!0),this._positiveColor=x(e,"positiveColor","#10b981"),this._negativeColor=x(e,"negativeColor","#ef4444"),this._totalColor=x(e,"totalColor","#6366f1"),S.call(this,t,e,"waterfall")}function R(t,e){this._items=e.items||[],this._rangeColors=x(e,"rangeColors",["#94a3b8","#cbd5e1","#e2e8f0"]),this._markerColor=x(e,"markerColor","#1e293b"),this._barColor=x(e,"barColor","#1e293b"),this._barHeightRatio=x(e,"barHeight",.4),e.categories=this._items.map(function(t){return t.label}),e.series=[{name:"Actual",data:this._items.map(function(t){return t.actual}),color:"#1e293b"}],S.call(this,t,e,"bullet")}function D(t,e){this._segments=e.segments||[],this._barHeight=x(e,"height",60),this._showPercent=x(e,"showPercent",!0),this._showSegValues=x(e,"showValues",!0),this._rounded=x(e,"rounded",!0),this._segGap=x(e,"gap",2),e.height=Math.max(this._barHeight+120,180),e.series=[{name:"Timeline",data:this._segments.map(function(t){return t.value}),color:"#6366f1"}],e.categories=this._segments.map(function(t){return t.label}),e.legendHidden=!0,S.call(this,t,e,"timeline")}!function(){if(!document.getElementById("mc-cat-enhanced-styles")){var t=document.createElement("style");t.id="mc-cat-enhanced-styles",t.textContent=[".mc-root { box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.03); border-radius: 12px; overflow: hidden; }",".mc-tooltip { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: 10px; overflow: hidden; }",'.mc-tooltip::before { content: ""; display: block; height: 3px; background: var(--mc-tt-accent, #6366f1); }',".mc-legend-swatch { width: 10px !important; height: 10px !important; border-radius: 50% !important; transition: transform .15s ease; }",".mc-legend-item:hover .mc-legend-swatch { transform: scale(1.25); }",".mc-legend-item { transition: opacity .15s ease; }"].join("\n"),document.head.appendChild(t)}}(),S.prototype._buildDOM=function(){this._root=u("div","mc-root",this.el);var t=u("div","mc-header",this._root),e=u("div","mc-titles",t);this.opts.title&&(u("div","mc-title",e).textContent=this.opts.title);this.opts.subtitle&&(u("div","mc-subtitle",e).textContent=this.opts.subtitle);var i=u("div","mc-toolbar",t),s=this;if(this._toolbar.dark&&(this._darkBtn=u("button","",i),this._darkBtn.innerHTML=y,this._darkBtn.title="Toggle dark mode",this._darkBtn.addEventListener("click",function(){s.el.classList.toggle("mc-dark"),s._darkBtn.classList.toggle("active",s.el.classList.contains("mc-dark")),s.render()})),this._toolbar.export){var o=u("button","",i);o.innerHTML=M,o.title="Export PNG",o.addEventListener("click",function(){s.exportPNG()})}"top"!==this._legendPosition||this._legendHidden||(this._legendEl=u("div","mc-legend",this._root),this._buildLegend()),this._wrap=u("div","mc-wrap",this._root),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this._wrap.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this._tooltipEl=u("div","mc-tooltip",this._wrap),this.series.length>0&&this._tooltipEl.style.setProperty("--mc-tt-accent",this.series[0].color),"bottom"!==this._legendPosition||this._legendHidden||(this._legendEl=u("div","mc-legend",this._root),this._buildLegend()),this._legendEl||(this._legendEl=u("div","mc-legend",null),this._legendEl.style.display="none")},S.prototype._buildLegend=function(){this._legendEl.innerHTML="";var t=this;this.series.forEach(function(e,i){var s=u("div","mc-legend-item",t._legendEl);e.visible||s.classList.add("disabled"),u("div","mc-legend-swatch",s).style.background=e.color,u("span","",s).textContent=e.name,s.addEventListener("click",function(){e.visible=!e.visible,s.classList.toggle("disabled",!e.visible),t.render()})})},S.prototype._initSize=function(){var t=this._wrap.getBoundingClientRect().width,e=this._height;this.W=t,this.H=e,this.canvas.width=Math.round(t*i),this.canvas.height=Math.round(e*i),this.canvas.style.height=e+"px",this.ctx.setTransform(i,0,0,i,0,0)},S.prototype._startAnimation=function(){var t=this;this._animStart=performance.now(),this._animProgress=0;var e=this._animDuration||s;this._rafId=requestAnimationFrame(function i(s){var o=s-t._animStart;t._animProgress=c(o/e,0,1),t.render(),t._animProgress<1&&(t._rafId=requestAnimationFrame(i))})},S.prototype._bindEvents=function(){var t,e=this;this._responsive&&window.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(function(){e._initSize(),e.render()},80)});this.canvas.addEventListener("mousemove",function(t){var i=e.canvas.getBoundingClientRect(),s=t.clientX-i.left,o=t.clientY-i.top;e._onHover(s,o)}),this.canvas.addEventListener("mouseleave",function(){e._hoverCat=-1,e._hoverSeries=-1,e._hideTooltip(),e.render()})},S.prototype._showTooltip=function(t,e,i,s){if(this._tooltipEnabled){s.length>0&&this._tooltipEl.style.setProperty("--mc-tt-accent",s[0].color);var o='<div class="mc-tooltip-date">'+i+"</div>";s.forEach(function(t){o+='<div class="mc-tooltip-row"><div class="mc-tooltip-dot" style="background:'+t.color+'"></div><span>'+t.name+'</span><span class="mc-tooltip-val" style="margin-left:8px;font-weight:600">'+v(t.value)+"</span></div>"}),this._tooltipEl.innerHTML=o,this._tooltipEl.classList.add("visible");var a=this._tooltipEl.offsetWidth,r=this._tooltipEl.offsetHeight,l=t+16,h=e-r/2;l+a>this.W-8&&(l=t-a-16),h=c(h,4,this.H-r-4),this._tooltipEl.style.left=l+"px",this._tooltipEl.style.top=h+"px"}},S.prototype._hideTooltip=function(){this._tooltipEl.classList.remove("visible")},S.prototype.exportPNG=function(t){var e=document.createElement("a");e.download=t||"chart.png",e.href=this.canvas.toDataURL("image/png"),e.click()},S.prototype._computeScale=function(){var t=0,e=this;"barStacked"===this.type||"column"===this.type&&this._stacked?this.categories.forEach(function(i,s){var o=0;e.series.forEach(function(t){t.visible&&s<t.data.length&&(o+=Math.max(0,t.data[s]))}),o>t&&(t=o)}):this.series.forEach(function(e){e.visible&&e.data.forEach(function(e){e>t&&(t=e)})}),this._scaleMax=_(1.1*t),this._step=p(this._scaleMax,5),this._ticks=[];for(var i=0;i<=this._scaleMax;i+=this._step)this._ticks.push(i)},S.prototype._clearAndDrawBackground=function(){var t=d(this.el);this._vars=t;var e=this.ctx;e.clearRect(0,0,this.W,this.H),e.fillStyle=t.card,e.fillRect(0,0,this.W,this.H)},S.prototype._drawStripes=function(){var t=this.ctx,e=this._padding,i=e.left,s=e.top,o=this.W-e.left-e.right,a=this.H-e.top-e.bottom;if(!(this._ticks.length<2))for(var r=0;r<this._ticks.length-1;r++)if(r%2!=0){var l=s+a-this._ticks[r]/this._scaleMax*a,h=s+a-this._ticks[r+1]/this._scaleMax*a;t.fillStyle="rgba(0,0,0,0.015)",t.fillRect(i,h,o,l-h)}},S.prototype._drawVerticalAxes=function(){this._drawStripes();var t=this.ctx,e=this._vars,i=this._padding,s=i.left,o=i.top,a=this.W-i.left-i.right,l=this.H-i.top-i.bottom;t.textAlign="right",t.textBaseline="middle",t.font="500 12px "+r;for(var h=0;h<this._ticks.length;h++){var n=this._ticks[h],d=o+l-n/this._scaleMax*l;this._gridLines&&(t.strokeStyle=this._gridColor||"rgba(226,232,240,0.6)",t.lineWidth=1,this._gridDashed?t.setLineDash([4,4]):t.setLineDash([]),t.beginPath(),t.moveTo(s,d),t.lineTo(s+a,d),t.stroke(),t.setLineDash([])),t.fillStyle=e.muted,t.fillText(v(n),s-8,d)}t.textAlign="center",t.textBaseline="top",t.fillStyle=e.text2,t.font="500 12px "+r;for(var c=a/this.categories.length,_=0;_<this.categories.length;_++){var p=s+c*_+c/2;t.fillText(this.categories[_],p,o+l+8)}},S.prototype._drawHorizontalStripes=function(){var t=this.ctx,e=this._padding,i=e.left,s=e.top,o=this.W-e.left-e.right,a=this.H-e.top-e.bottom;if(!(this._ticks.length<2))for(var r=0;r<this._ticks.length-1;r++)if(r%2!=0){var l=i+this._ticks[r]/this._scaleMax*o,h=i+this._ticks[r+1]/this._scaleMax*o;t.fillStyle="rgba(0,0,0,0.015)",t.fillRect(l,s,h-l,a)}},S.prototype._drawHorizontalAxes=function(){this._drawHorizontalStripes();var t=this.ctx,e=this._vars,i=this._padding,s=i.left,o=i.top,a=this.W-i.left-i.right,l=this.H-i.top-i.bottom;t.textAlign="center",t.textBaseline="top",t.font="500 12px "+r;for(var h=0;h<this._ticks.length;h++){var n=this._ticks[h],d=s+n/this._scaleMax*a;this._gridLines&&(t.strokeStyle=this._gridColor||"rgba(226,232,240,0.6)",t.lineWidth=1,this._gridDashed?t.setLineDash([4,4]):t.setLineDash([]),t.beginPath(),t.moveTo(d,o),t.lineTo(d,o+l),t.stroke(),t.setLineDash([])),t.fillStyle=e.muted,t.fillText(v(n),d,o+l+8)}t.textAlign="right",t.textBaseline="middle",t.fillStyle=e.text2,t.font="500 12px "+r;for(var c=l/this.categories.length,_=0;_<this.categories.length;_++){var p=o+c*_+c/2;t.fillText(this.categories[_],s-8,p)}},S.prototype._getBarFill=function(t,e,i,s,o,a){return this._gradient?function(t,e,i,s,o,a,r,l){var h;h=l?t.createLinearGradient(i,s,i,s+a):t.createLinearGradient(i,s,i+o,s);var n=m(e,.25);return h.addColorStop(0,e),h.addColorStop(1,n),h}(this.ctx,t,e,i,s,o,this._gradientOpacity,a):t},S.prototype._drawBarShadow=function(t,e,i,s,o,a,r){t.save(),t.shadowColor=r,t.shadowBlur=8,t.shadowOffsetX=0,t.shadowOffsetY=3,t.fillStyle="rgba(0,0,0,0.01)",t.beginPath(),t.roundRect(e,i,s,o,a),t.fill(),t.restore()},S.prototype._drawBarHighlight=function(t,e,i,s,o,a){t.save(),t.globalAlpha=.25,t.strokeStyle="rgba(255,255,255,0.7)",t.lineWidth=1,t.beginPath(),a?(t.moveTo(e+o,i+1),t.lineTo(e+s-o,i+1)):(t.moveTo(e+s-1,i+o),t.lineTo(e+s-1,i+h-o)),t.stroke(),t.restore()},C.prototype=Object.create(S.prototype),C.prototype.constructor=C,C.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground(),this._drawVerticalAxes();var t=this.ctx,e=this._vars,i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);var o=this._padding,a=o.left,l=o.top,h=this.W-o.left-o.right,n=this.H-o.top-o.bottom,d=this.categories.length,_=this.series.filter(function(t){return t.visible}),p=_.length||1,g=this._borderRadius;if(this._stacked){for(var u=(A=h/d)*(1-this._groupPadding),b=(A-(E=this._barWidth||Math.min(u,60)))/2,m=0;m<d;m++){for(var x=0,y=this._hoverCat===m,M=0;M<_.length;M++){var S=_[M],C=(B=m<S.data.length?Math.max(0,S.data[m]):0)/this._scaleMax*n*s,w=a+A*m+b,k=l+n-x-C,T=[0,0,0,0];M===_.length-1&&(T=[g,g,0,0]),this._drawBarShadow(t,w,k,E,C,T,S.color),t.globalAlpha=y?this._hoverOpacity:this._opacity,t.fillStyle=this._getBarFill(S.color,w,k,E,C,!0),t.beginPath(),t.roundRect(w,k,E,C,T),t.fill(),M===_.length-1&&C>4&&this._drawBarHighlight(t,w,k,E,g,!0),this._borderWidth>0&&(t.strokeStyle=this._borderColor,t.lineWidth=this._borderWidth,t.stroke()),i>=1&&this._stackLabels&&this._showValues&&C>20&&(t.globalAlpha=1,t.font=this._valueSize+"px "+r,t.textAlign="center",t.textBaseline="middle",t.fillStyle=this._valueColor||"#fff",t.fillText(v(B),w+E/2,k+C/2)),x+=C}if(i>=1&&this._showTotal&&x>0){var P=0;_.forEach(function(t){m<t.data.length&&(P+=Math.max(0,t.data[m]))}),t.globalAlpha=1,t.font="bold "+this._valueSize+"px "+r,t.textAlign="center",t.textBaseline="bottom",t.fillStyle=e.text2,t.fillText(v(P),a+A*m+b+E/2,l+n-x-4)}}t.globalAlpha=1}else{u=(A=h/d)*(1-this._groupPadding);var A,E=this._barWidth||(u-this._barGap*(p-1))/p,L=(A-((E=Math.min(E,60))*p+this._barGap*(p-1)))/2;this._hitAreas=[];for(M=0;M<_.length;M++)for(S=_[M],m=0;m<d;m++){var B,H=(B=m<S.data.length?S.data[m]:0)/this._scaleMax*n*s;w=a+A*m+L+M*(E+this._barGap),k=l+n-H,y=this._hoverCat===m;this._drawBarShadow(t,w,k,E,H,[g,g,0,0],S.color),y&&(t.save(),t.shadowColor=S.color,t.shadowBlur=12,t.fillStyle="rgba(0,0,0,0.01)",t.beginPath(),t.roundRect(w,k,E,H,[g,g,0,0]),t.fill(),t.restore()),t.globalAlpha=y?this._hoverOpacity:this._opacity,t.fillStyle=this._getBarFill(S.color,w,k,E,H,!0),t.beginPath(),t.roundRect(w,k,E,H,[g,g,0,0]),t.fill(),H>4&&this._drawBarHighlight(t,w,k,E,g,!0),this._borderWidth>0&&(t.strokeStyle=this._borderColor,t.lineWidth=this._borderWidth,t.stroke()),this._hitAreas.push({ci:m,si:M,x:w,y:k,w:E,h:H,series:S}),i>=1&&this._showValues&&(t.globalAlpha=1,t.font=this._valueSize+"px "+r,t.textAlign="center",t.textBaseline=H>20?"top":"bottom",this._valueColor?t.fillStyle=this._valueColor:t.fillStyle=H>20?"#fff":e.text2,t.fillText(v(B),w+E/2,H>20?k+4:k-4))}t.globalAlpha=1}},C.prototype._onHover=function(t,e){var i=this._hoverCat;this._hoverCat=-1;var s=this._padding,o=s.left,a=this.W-s.left-s.right,r=a/this.categories.length;if(t>=o&&t<=o+a&&e>=s.top&&e<=this.H-s.bottom&&(this._hoverCat=Math.floor((t-o)/r),this._hoverCat=c(this._hoverCat,0,this.categories.length-1)),this._hoverCat!==i){if(this._hoverCat>=0){var l=[],h=this;this.series.forEach(function(t){t.visible&&h._hoverCat<t.data.length&&l.push({name:t.name,value:t.data[h._hoverCat],color:t.color})}),this._showTooltip(t,e,this.categories[this._hoverCat],l)}else this._hideTooltip();this.render()}},w.prototype=Object.create(S.prototype),w.prototype.constructor=w,w.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground(),this._drawHorizontalAxes();var t=this.ctx,e=this._vars,i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);for(var o=this._padding,a=o.left,l=o.top,h=this.W-o.left-o.right,n=this.H-o.top-o.bottom,d=this.categories.length,_=this.series.filter(function(t){return t.visible}),p=_.length||1,g=this._borderRadius,u=n/d,b=u*(1-this._groupPadding),m=this._barWidth||(b-this._barGap*(p-1))/p,x=(u-((m=Math.min(m,40))*p+this._barGap*(p-1)))/2,y=0;y<_.length;y++)for(var M=_[y],S=0;S<d;S++){var C=S<M.data.length?M.data[S]:0,w=C/this._scaleMax*h*s,k=l+u*S+x+y*(m+this._barGap),T=a,P=this._hoverCat===S;if(this._drawBarShadow(t,T,k,w,m,[0,g,g,0],M.color),P&&(t.save(),t.shadowColor=M.color,t.shadowBlur=12,t.fillStyle="rgba(0,0,0,0.01)",t.beginPath(),t.roundRect(T,k,w,m,[0,g,g,0]),t.fill(),t.restore()),t.globalAlpha=P?this._hoverOpacity:this._opacity,t.fillStyle=this._getBarFill(M.color,T,k,w,m,!1),t.beginPath(),t.roundRect(T,k,w,m,[0,g,g,0]),t.fill(),w>4&&(t.save(),t.globalAlpha=.25,t.strokeStyle="rgba(255,255,255,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(T+w-1,k+g),t.lineTo(T+w-1,k+m-g),t.stroke(),t.restore()),this._borderWidth>0&&(t.strokeStyle=this._borderColor,t.lineWidth=this._borderWidth,t.stroke()),i>=1&&this._showValues){t.globalAlpha=1,t.font=this._valueSize+"px "+r,t.textBaseline="middle";var A=k+m/2;w>40?(t.textAlign="right",t.fillStyle=this._valueColor||"#fff",t.fillText(v(C),T+w-6,A)):(t.textAlign="left",t.fillStyle=this._valueColor||e.text2,t.fillText(v(C),T+w+6,A))}}t.globalAlpha=1},w.prototype._onHover=function(t,e){var i=this._hoverCat;this._hoverCat=-1;var s=this._padding,o=this.H-s.top-s.bottom,a=o/this.categories.length;if(e>=s.top&&e<=s.top+o&&t>=s.left&&(this._hoverCat=Math.floor((e-s.top)/a),this._hoverCat=c(this._hoverCat,0,this.categories.length-1)),this._hoverCat!==i){if(this._hoverCat>=0){var r=[],l=this;this.series.forEach(function(t){t.visible&&l._hoverCat<t.data.length&&r.push({name:t.name,value:t.data[l._hoverCat],color:t.color})}),this._showTooltip(t,e,this.categories[this._hoverCat],r)}else this._hideTooltip();this.render()}},k.prototype=Object.create(S.prototype),k.prototype.constructor=k,k.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground(),this._drawHorizontalAxes();var t=this.ctx,e=this._vars,i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);for(var o=this._padding,a=o.left,l=o.top,h=this.W-o.left-o.right,n=this.H-o.top-o.bottom,d=this.categories.length,_=this._borderRadius,p=n/d,g=p*(1-this._groupPadding),u=(p-(g=Math.min(g,40)))/2,b=this.series.filter(function(t){return t.visible}),m=0;m<d;m++){for(var x=a,y=this._hoverCat===m,M=0;M<b.length;M++){var S=b[M],C=m<S.data.length?Math.max(0,S.data[m]):0,w=C/this._scaleMax*h*s,k=l+p*m+u,T=[0,0,0,0];M===b.length-1&&(T=[0,_,_,0]),0===M&&(T[0]=0,T[3]=0),this._drawBarShadow(t,x,k,w,g,T,S.color),t.globalAlpha=y?this._hoverOpacity:this._opacity,t.fillStyle=this._getBarFill(S.color,x,k,w,g,!1),t.beginPath(),t.roundRect(x,k,w,g,T),t.fill(),this._borderWidth>0&&(t.strokeStyle=this._borderColor,t.lineWidth=this._borderWidth,t.stroke()),i>=1&&this._stackLabels&&this._showValues&&w>30&&(t.globalAlpha=1,t.font=this._valueSize+"px "+r,t.textAlign="center",t.textBaseline="middle",t.fillStyle=this._valueColor||"#fff",t.fillText(v(C),x+w/2,k+g/2)),x+=w}if(i>=1&&this._showTotal){var P=0;b.forEach(function(t){m<t.data.length&&(P+=Math.max(0,t.data[m]))}),t.globalAlpha=1,t.font="bold "+this._valueSize+"px "+r,t.textAlign="left",t.textBaseline="middle",t.fillStyle=e.text2,t.fillText(v(P),x+6,l+p*m+u+g/2)}}t.globalAlpha=1},k.prototype._onHover=w.prototype._onHover,T.prototype=Object.create(S.prototype),T.prototype.constructor=T,T.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground(),this._drawVerticalAxes();var t=this.ctx,e=this._vars,i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);for(var o=this._padding,a=o.left,l=o.top,h=this.W-o.left-o.right,n=this.H-o.top-o.bottom,d=this.categories.length,_=this.series.filter(function(t){return t.visible}),p=_.length||1,g=h/d,u=Math.min(g/(p+1),28),y=u*(p-1),M=l+n,S=x(this.opts,"dotRadius",6),C=x(this.opts,"stemWidth",2),w=x(this.opts,"stemDashed",!1),k=x(this.opts,"dotBorder",!0),T=x(this.opts,"dotBorderWidth",2),P=0;P<_.length;P++)for(var A=_[P],E=0;E<d;E++){var L=E<A.data.length?A.data[E]:0,B=a+g*E+g/2-y/2+u*P,H=M-L/this._scaleMax*n*s,W=this._hoverCat===E;t.globalAlpha=W?this._hoverOpacity:.8;var R=t.createLinearGradient(B,M,B,H),D=b(A.color);R.addColorStop(0,"rgba("+D[0]+","+D[1]+","+D[2]+",0.3)"),R.addColorStop(1,"rgba("+D[0]+","+D[1]+","+D[2]+",0.8)"),t.strokeStyle=R,t.lineWidth=C,w?t.setLineDash([4,4]):t.setLineDash([]),t.beginPath(),t.moveTo(B,M),t.lineTo(B,H),t.stroke(),t.setLineDash([]),t.save(),t.shadowColor=A.color,t.shadowBlur=6,t.shadowOffsetY=2,t.fillStyle="rgba(0,0,0,0.01)",t.beginPath(),t.arc(B,H,S,0,2*Math.PI),t.fill(),t.restore();var I=t.createRadialGradient(B-.3*S,H-.3*S,0,B,H,S);I.addColorStop(0,m(A.color,.35)),I.addColorStop(1,A.color),t.fillStyle=I,t.beginPath(),t.arc(B,H,S,0,2*Math.PI),t.fill(),k&&(t.strokeStyle=e.card,t.lineWidth=T,t.stroke()),i>=1&&this._showValues&&(t.globalAlpha=1,t.font=this._valueSize+"px "+r,t.textAlign="center",t.textBaseline="bottom",t.fillStyle=this._valueColor||e.text2,t.fillText(v(L),B,H-S-3))}t.globalAlpha=1},T.prototype._onHover=C.prototype._onHover,P.prototype=Object.create(S.prototype),P.prototype.constructor=P,P.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground(),this._drawVerticalAxes();var t=this.ctx,e=this._vars,i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);var o=this._padding,a=o.left,l=o.top,h=this.W-o.left-o.right,n=this.H-o.top-o.bottom,d=this.categories.length,_=l+n,p=h/d,g=x(this.opts,"lineWidth",2.5),u=x(this.opts,"lineTension",.3),y=x(this.opts,"lineStyle","solid"),M=x(this.opts,"showArea",!1),S=x(this.opts,"areaOpacity",.15),C=[],w=[];this.series.forEach(function(t){t.visible&&("line"===t.type?w.push(t):C.push(t))});for(var k=C.length||1,T=Math.min(p/(k+1),28),P=T*(k-1),A=x(this.opts,"dotRadius",6),E=0;E<C.length;E++)for(var L=C[E],B=0;B<d;B++){var H=(B<L.data.length?L.data[B]:0)/this._scaleMax*n*s,W=a+p*B+p/2-P/2+T*E,R=_-H,D=this._hoverCat===B;t.globalAlpha=D?this._hoverOpacity:.8;var I=t.createLinearGradient(W,_,W,R),O=b(L.color);I.addColorStop(0,"rgba("+O[0]+","+O[1]+","+O[2]+",0.3)"),I.addColorStop(1,"rgba("+O[0]+","+O[1]+","+O[2]+",0.8)"),t.strokeStyle=I,t.lineWidth=2,t.beginPath(),t.moveTo(W,_),t.lineTo(W,R),t.stroke();var G=t.createRadialGradient(W-.3*A,R-.3*A,0,W,R,A);G.addColorStop(0,m(L.color,.35)),G.addColorStop(1,L.color),t.fillStyle=G,t.beginPath(),t.arc(W,R,A,0,2*Math.PI),t.fill()}for(var z=0;z<w.length;z++){var N=w[z];t.globalAlpha=1;for(var V=[],F=0;F<d;F++){var j=F<N.data.length?N.data[F]:0,q=a+p*F+p/2,Y=_-j/this._scaleMax*n*s;V.push({x:q,y:Y})}if("dashed"===y?t.setLineDash([8,4]):"dotted"===y?t.setLineDash([2,4]):t.setLineDash([]),M&&V.length>1){var X=t.createLinearGradient(0,l,0,_),J=b(N.color);if(X.addColorStop(0,"rgba("+J[0]+","+J[1]+","+J[2]+","+1.5*S+")"),X.addColorStop(.7,"rgba("+J[0]+","+J[1]+","+J[2]+","+.3*S+")"),X.addColorStop(1,"rgba("+J[0]+","+J[1]+","+J[2]+",0)"),t.globalAlpha=1,t.fillStyle=X,t.beginPath(),t.moveTo(V[0].x,_),u>0&&V.length>2){t.lineTo(V[0].x,V[0].y);for(var U=0;U<V.length-1;U++){var K=V[U],Q=V[U+1],Z=K.x+(Q.x-K.x)*u,$=Q.x-(Q.x-K.x)*u;t.bezierCurveTo(Z,K.y,$,Q.y,Q.x,Q.y)}}else for(var tt=0;tt<V.length;tt++)t.lineTo(V[tt].x,V[tt].y);t.lineTo(V[V.length-1].x,_),t.closePath(),t.fill(),t.globalAlpha=1}if(t.save(),t.shadowColor=N.color,t.shadowBlur=6,t.shadowOffsetY=2,t.strokeStyle=N.color,t.lineWidth=g,t.lineJoin="round",t.lineCap="round",t.beginPath(),u>0&&V.length>2){t.moveTo(V[0].x,V[0].y);for(var et=0;et<V.length-1;et++){var it=V[et],st=V[et+1],ot=it.x+(st.x-it.x)*u,at=st.x-(st.x-it.x)*u;t.bezierCurveTo(ot,it.y,at,st.y,st.x,st.y)}}else for(var rt=0;rt<V.length;rt++)0===rt?t.moveTo(V[rt].x,V[rt].y):t.lineTo(V[rt].x,V[rt].y);t.stroke(),t.restore(),t.setLineDash([]);for(var lt=0;lt<V.length;lt++)t.fillStyle=N.color,t.beginPath(),t.arc(V[lt].x,V[lt].y,4,0,2*Math.PI),t.fill(),t.fillStyle=e.card,t.beginPath(),t.arc(V[lt].x,V[lt].y,2,0,2*Math.PI),t.fill()}if(i>=1&&this._hoverCat>=0&&this._showValues){var ht=this._hoverCat;t.font=this._valueSize+"px "+r,t.textAlign="center",t.textBaseline="bottom",t.fillStyle=this._valueColor||e.text2,t.globalAlpha=1,this.series.forEach(function(e){if(e.visible&&!(ht>=e.data.length)){var i=e.data[ht],s=a+p*ht+p/2,o=_-i/this._scaleMax*n;t.fillText(v(i),s,o-10)}}.bind(this))}t.globalAlpha=1},P.prototype._onHover=C.prototype._onHover,A.prototype._buildDonutDOM=function(){this._root=u("div","mc-root",this.el);var t=u("div","mc-header",this._root),e=u("div","mc-titles",t);this.opts.title&&(u("div","mc-title",e).textContent=this.opts.title);this.opts.subtitle&&(u("div","mc-subtitle",e).textContent=this.opts.subtitle);var i=u("div","mc-toolbar",t),s=this;if(this._toolbar.dark&&(this._darkBtn=u("button","",i),this._darkBtn.innerHTML=y,this._darkBtn.title="Toggle dark mode",this._darkBtn.addEventListener("click",function(){s.el.classList.toggle("mc-dark"),s._darkBtn.classList.toggle("active",s.el.classList.contains("mc-dark")),s.render()})),this._toolbar.export){var o=u("button","",i);o.innerHTML=M,o.title="Export PNG",o.addEventListener("click",function(){s.exportPNG()})}"top"!==this._legendPosition||this._legendHidden||(this._legendEl=u("div","mc-legend",this._root),this._buildDonutLegend()),this._wrap=u("div","mc-wrap",this._root),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this._wrap.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this._tooltipEl=u("div","mc-tooltip",this._wrap),this.segments.length>0&&this._tooltipEl.style.setProperty("--mc-tt-accent",this.segments[0].color),"bottom"!==this._legendPosition||this._legendHidden||(this._legendEl=u("div","mc-legend",this._root),this._buildDonutLegend()),this._legendEl||(this._legendEl=u("div","mc-legend",null),this._legendEl.style.display="none")},A.prototype._buildDonutLegend=function(){this._legendEl.innerHTML="";var t=this;this.segments.forEach(function(e,i){var s=u("div","mc-legend-item",t._legendEl);e.visible||s.classList.add("disabled"),u("div","mc-legend-swatch",s).style.background=e.color,u("span","",s).textContent=e.label,s.addEventListener("click",function(){e.visible=!e.visible,s.classList.toggle("disabled",!e.visible),t.render()})})},A.prototype._initSize=function(){var t=this._wrap.getBoundingClientRect().width,e=Math.max(this._height,380);this.W=t,this.H=e,this.canvas.width=Math.round(t*i),this.canvas.height=Math.round(e*i),this.canvas.style.height=e+"px",this.ctx.setTransform(i,0,0,i,0,0)},A.prototype._startAnimation=S.prototype._startAnimation,A.prototype._bindDonutEvents=function(){var t,e=this;this._responsive&&window.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(function(){e._initSize(),e.render()},80)});this.canvas.addEventListener("mousemove",function(t){var i=e.canvas.getBoundingClientRect(),s=t.clientX-i.left,o=t.clientY-i.top;e._onDonutHover(s,o)}),this.canvas.addEventListener("mouseleave",function(){e._hoverIndex=-1,e._tooltipEl.classList.remove("visible"),e.render()}),this.canvas.addEventListener("click",function(t){var i=e.canvas.getBoundingClientRect(),s=t.clientX-i.left,o=t.clientY-i.top,a=e._hitTest(s,o);e._selectedIndex=e._selectedIndex===a?-1:a,e.render()})},A.prototype._getTotal=function(){var t=0;return this.segments.forEach(function(e){e.visible&&(t+=e.value)}),t},A.prototype._hitTest=function(t,e){var i=this.W/2,s=this.H/2,o=Math.min(i,s)-30,a=o*this._innerRadius,r=t-i,l=e-s,h=Math.sqrt(r*r+l*l);if(h<a||h>o+12)return-1;var n=Math.atan2(l,r);n<-Math.PI/2&&(n+=2*Math.PI);var d=this._getTotal();if(d<=0)return-1;for(var c=-Math.PI/2,_=0;_<this.segments.length;_++)if(this.segments[_].visible){var p=this.segments[_].value/d*Math.PI*2;if(n>=c&&n<c+p)return _;c+=p}return-1},A.prototype._onDonutHover=function(t,e){var i=this._hoverIndex;if(this._hoverIndex=this._hitTest(t,e),this._hoverIndex!==i){if(this._hoverIndex>=0&&this._tooltipEnabled){var s=this.segments[this._hoverIndex];this._tooltipEl.style.setProperty("--mc-tt-accent",s.color);var o=this._getTotal(),a=o>0?(s.value/o*100).toFixed(1):"0.0",r='<div class="mc-tooltip-date">'+s.label+'</div><div class="mc-tooltip-row"><div class="mc-tooltip-dot" style="background:'+s.color+'"></div><span>'+v(s.value)+'</span><span class="mc-tooltip-val" style="margin-left:8px;font-weight:600">'+a+"%</span></div>";this._tooltipEl.innerHTML=r,this._tooltipEl.classList.add("visible");var l=this._tooltipEl.offsetWidth,h=t+16;h+l>this.W-8&&(h=t-l-16),this._tooltipEl.style.left=h+"px",this._tooltipEl.style.top=e-20+"px"}else this._tooltipEl.classList.remove("visible");this.render()}},A.prototype.render=function(){var t=d(this.el),e=this.ctx;e.clearRect(0,0,this.W,this.H),e.fillStyle=t.card,e.fillRect(0,0,this.W,this.H);var i=g(this._animProgress),s=this._getTotal();if(!(s<=0)){for(var o=this.W/2,a=this.H/2,l=Math.min(o,a)-30,h=l*this._innerRadius,n=-Math.PI/2,c=2*Math.PI*i,_=this._padAngle,p=this._strokeWidth,f="auto"===this._strokeColor?t.card:this._strokeColor,u=0;u<this.segments.length;u++){var b=this.segments[u];if(b.visible){var x=b.value/s*Math.PI*2,y=Math.min(x-_,c-(n+Math.PI/2));if(y<=0)n+=x;else{var M=this._hoverIndex===u,S=this._selectedIndex===u,C=M||S?this._hoverScale:1,w=M||S?8:0,k=n+x/2,T=w*Math.cos(k),P=w*Math.sin(k),A=e.createLinearGradient(o+T+l*Math.cos(n),a+P+l*Math.sin(n),o+T+l*Math.cos(n+y),a+P+l*Math.sin(n+y));A.addColorStop(0,b.color),A.addColorStop(1,m(b.color,.15)),M&&(e.save(),e.shadowColor=b.color,e.shadowBlur=16,e.fillStyle="rgba(0,0,0,0.01)",e.beginPath(),e.arc(o+T,a+P,l*C,n+_/2,n+_/2+y),e.arc(o+T,a+P,h,n+_/2+y,n+_/2,!0),e.closePath(),e.fill(),e.restore()),e.fillStyle=A,e.globalAlpha=M?this._hoverOpacity:this._opacity,e.beginPath(),e.arc(o+T,a+P,l*(C>1?C:1),n+_/2,n+_/2+y),e.arc(o+T,a+P,h,n+_/2+y,n+_/2,!0),e.closePath(),e.fill(),p>0&&(e.strokeStyle=f,e.lineWidth=p,e.stroke()),n+=x}}}if(e.globalAlpha=1,this._innerRadius>0){var E=e.createRadialGradient(o,a,.8*h,o,a,h);E.addColorStop(0,"rgba(0,0,0,0)"),E.addColorStop(1,"rgba(0,0,0,0.06)"),e.fillStyle=E,e.beginPath(),e.arc(o,a,h,0,2*Math.PI),e.fill()}var L=this._centerLabel,B=this._centerSubLabel;if(null==L||null==B)if(this._selectedIndex>=0&&this.segments[this._selectedIndex].visible){var H=this.segments[this._selectedIndex];null==L&&(L=v(H.value)),null==B&&(B=H.label)}else null==L&&(L=v(s)),null==B&&(B="Total");e.textAlign="center",e.textBaseline="middle",e.fillStyle=t.text,e.font="bold 24px "+r,e.fillText(L,o,a-6),e.fillStyle=t.muted,e.font="12px "+r,e.fillText(B,o,a+16)}},A.prototype.exportPNG=S.prototype.exportPNG,E.prototype._buildGaugeDOM=function(){this._root=u("div","mc-root",this.el);var t=u("div","mc-header",this._root),e=u("div","mc-titles",t);this.opts.title&&(u("div","mc-title",e).textContent=this.opts.title);this.opts.subtitle&&(u("div","mc-subtitle",e).textContent=this.opts.subtitle);var i=u("div","mc-toolbar",t),s=this;this._toolbar.dark&&(this._darkBtn=u("button","",i),this._darkBtn.innerHTML=y,this._darkBtn.title="Toggle dark mode",this._darkBtn.addEventListener("click",function(){s.el.classList.toggle("mc-dark"),s._darkBtn.classList.toggle("active",s.el.classList.contains("mc-dark")),s.render()})),this._wrap=u("div","mc-wrap",this._root),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this._wrap.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d")},E.prototype._initSize=function(){var t=this._wrap.getBoundingClientRect().width,e=Math.min(t/2-30,180),s=e+e*this._arcWidth/2+70;s=Math.max(200,Math.min(s,320)),this.W=t,this.H=s,this.canvas.width=Math.round(t*i),this.canvas.height=Math.round(s*i),this.canvas.style.height=s+"px",this.ctx.setTransform(i,0,0,i,0,0)},E.prototype._startAnimation=S.prototype._startAnimation,E.prototype._bindGaugeEvents=function(){var t,e=this;this._responsive&&window.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(function(){e._initSize(),e.render()},80)})},E.prototype.render=function(){var t=d(this.el),e=this.ctx;e.clearRect(0,0,this.W,this.H),e.fillStyle=t.card,e.fillRect(0,0,this.W,this.H);var i=g(this._animProgress),s=this.W/2,o=this.H-40,a=Math.min(s-30,o-20,180),l=a*this._arcWidth,h=this.max-this.min,n=this;this.zones.forEach(function(t){var i=c((t.from-n.min)/h,0,1),r=c((t.to-n.min)/h,0,1),d=Math.PI+i*Math.PI,_=Math.PI+r*Math.PI;e.beginPath(),e.arc(s,o,a,d,_),e.lineWidth=l,e.strokeStyle=t.color,e.globalAlpha=.25,e.stroke()}),e.globalAlpha=1;var _=c((this.value-this.min)/h,0,1)*i,p=Math.PI+_*Math.PI;if(this.zones.forEach(function(t){var i=c((t.from-n.min)/h,0,1),r=c((t.to-n.min)/h,0,1),d=Math.PI+i*Math.PI,_=Math.PI+r*Math.PI,v=Math.min(_,p);if(!(v<=d)){var g=s+a*Math.cos(d),f=o+a*Math.sin(d),u=s+a*Math.cos(v),b=o+a*Math.sin(v),x=e.createLinearGradient(g,f,u,b);x.addColorStop(0,t.color),x.addColorStop(1,m(t.color,.2)),e.beginPath(),e.arc(s,o,a,d,v),e.lineWidth=l,e.strokeStyle=x,e.lineCap="butt",e.stroke()}}),e.save(),e.globalAlpha=.08,e.beginPath(),e.arc(s,o,a+.35*l,Math.PI,2*Math.PI),e.lineWidth=1.5,e.strokeStyle="#fff",e.stroke(),e.restore(),this._showTicks){e.strokeStyle=t.muted,e.lineWidth=1;for(var f=0;f<=10;f++){var u=f/10,b=Math.PI+u*Math.PI,x=a-l/2-4,y=a-l/2-10,M=s+x*Math.cos(b),S=o+x*Math.sin(b),C=s+y*Math.cos(b),w=o+y*Math.sin(b);e.beginPath(),e.moveTo(M,S),e.lineTo(C,w),e.stroke()}}var k=a-l/2-8,T=Math.PI+_*Math.PI,P=s+k*Math.cos(T),A=o+k*Math.sin(T);e.save(),e.shadowColor="rgba(0,0,0,0.3)",e.shadowBlur=6,e.shadowOffsetY=2,e.strokeStyle=this._needleColor||t.text,e.lineWidth=this._needleWidth,e.lineCap="round",e.beginPath(),e.moveTo(s,o),e.lineTo(P,A),e.stroke(),e.restore(),e.fillStyle=this._needleColor||t.text,e.beginPath(),e.arc(s,o,6,0,2*Math.PI),e.fill(),e.fillStyle=t.card,e.beginPath(),e.arc(s,o,3,0,2*Math.PI),e.fill(),e.textAlign="center",e.textBaseline="bottom",e.fillStyle=t.text,e.font="bold 28px "+r,e.fillText(v(this.value*i),s,o-16),this._unit&&(e.font="13px "+r,e.fillStyle=t.muted,e.fillText(this._unit,s,o-0)),e.font="500 12px "+r,e.fillStyle=t.muted,e.textAlign="center",e.textBaseline="top",e.fillText(v(this.min),s-a,o+6),e.fillText(v(this.max),s+a,o+6)},E.prototype.exportPNG=S.prototype.exportPNG,L.prototype._buildHeatmapDOM=function(){this._root=u("div","mc-root",this.el);var t=u("div","mc-header",this._root),e=u("div","mc-titles",t);this.opts.title&&(u("div","mc-title",e).textContent=this.opts.title);this.opts.subtitle&&(u("div","mc-subtitle",e).textContent=this.opts.subtitle);var i=u("div","mc-toolbar",t),s=this;if(this._toolbar.dark&&(this._darkBtn=u("button","",i),this._darkBtn.innerHTML=y,this._darkBtn.title="Toggle dark mode",this._darkBtn.addEventListener("click",function(){s.el.classList.toggle("mc-dark"),s._darkBtn.classList.toggle("active",s.el.classList.contains("mc-dark")),s.render()})),this._toolbar.export){var o=u("button","",i);o.innerHTML=M,o.title="Export PNG",o.addEventListener("click",function(){s.exportPNG()})}this._wrap=u("div","mc-wrap",this._root),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this._wrap.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this._tooltipEl=u("div","mc-tooltip",this._wrap)},L.prototype._initSize=function(){var t=this._wrap.getBoundingClientRect().width,e=this._padding,s=this.yLabels.length||1,o=Math.max(this._height,e.top+e.bottom+36*s);this.W=t,this.H=o,this.canvas.width=Math.round(t*i),this.canvas.height=Math.round(o*i),this.canvas.style.height=o+"px",this.ctx.setTransform(i,0,0,i,0,0)},L.prototype._startAnimation=S.prototype._startAnimation,L.prototype._computeMinMax=function(){this._dataMin=1/0,this._dataMax=-1/0;for(var t=0;t<this.data.length;t++){var e=this.data[t][2];e<this._dataMin&&(this._dataMin=e),e>this._dataMax&&(this._dataMax=e)}this._dataMin===1/0&&(this._dataMin=0,this._dataMax=1),this._grid={};for(var i=0;i<this.data.length;i++){var s=this.data[i];this._grid[s[0]+","+s[1]]=s[2]}},L.prototype._interpolateColor=function(t){var e=this.colorRange[0],i=this.colorRange[1],s=b(e),o=b(i);return"rgb("+Math.round(s[0]+(o[0]-s[0])*t)+","+Math.round(s[1]+(o[1]-s[1])*t)+","+Math.round(s[2]+(o[2]-s[2])*t)+")"},L.prototype._bindHeatmapEvents=function(){var t,e=this;this._responsive&&window.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(function(){e._initSize(),e.render()},80)});this.canvas.addEventListener("mousemove",function(t){var i=e.canvas.getBoundingClientRect(),s=t.clientX-i.left,o=t.clientY-i.top;e._onHeatmapHover(s,o)}),this.canvas.addEventListener("mouseleave",function(){e._hoverCell=null,e._tooltipEl.classList.remove("visible"),e.render()})},L.prototype._onHeatmapHover=function(t,e){var i=this._padding,s=i.left+20,o=i.top,a=this.W-s-i.right,r=this.H-i.top-i.bottom,l=a/this.xLabels.length,h=r/this.yLabels.length,n=Math.floor((t-s)/l),d=Math.floor((e-o)/h),c=this._hoverCell;if(n>=0&&n<this.xLabels.length&&d>=0&&d<this.yLabels.length){var _=n+","+d,p=this._grid[_];if(null!=p){if(this._hoverCell={xi:n,yi:d},!c||c.xi!==n||c.yi!==d){if(this._tooltipEnabled){var g='<div class="mc-tooltip-date">'+this.yLabels[d]+" / "+this.xLabels[n]+'</div><div class="mc-tooltip-row"><span style="font-weight:600">'+v(p)+"</span></div>";this._tooltipEl.innerHTML=g,this._tooltipEl.classList.add("visible");var f=this._tooltipEl.offsetWidth,u=t+16;u+f>this.W-8&&(u=t-f-16),this._tooltipEl.style.left=u+"px",this._tooltipEl.style.top=e-20+"px"}this.render()}return}}c&&(this._hoverCell=null,this._tooltipEl.classList.remove("visible"),this.render())},L.prototype.render=function(){var t=d(this.el),e=this.ctx;e.clearRect(0,0,this.W,this.H),e.fillStyle=t.card,e.fillRect(0,0,this.W,this.H);for(var i=g(this._animProgress),s=this._padding,o=s.left+20,a=s.top,l=this.W-o-s.right,h=this.H-s.top-s.bottom,n=this.xLabels.length,_=this.yLabels.length,p=l/n,f=h/_,u=this._cellGap,b=this._dataMax-this._dataMin||1,m=this._cellRadius,x=0;x<_;x++)for(var y=0;y<n;y++){var M=y+","+x,S=this._grid[M];if(null!=S){var C=c((S-this._dataMin)/b,0,1)*i,w=o+y*p+u/2,k=a+x*f+u/2,T=p-u,P=f-u,A=this._hoverCell&&this._hoverCell.xi===y&&this._hoverCell.yi===x;e.save(),e.shadowColor="rgba(0,0,0,0.08)",e.shadowBlur=2,e.shadowOffsetY=1,e.fillStyle=this._interpolateColor(C),e.globalAlpha=A?1:.9,e.beginPath(),e.roundRect(w,k,T,P,m),e.fill(),e.restore(),A&&(e.save(),e.shadowColor="rgba(255,255,255,0.8)",e.shadowBlur=8,e.strokeStyle="#fff",e.lineWidth=2,e.beginPath(),e.roundRect(w,k,T,P,m),e.stroke(),e.restore()),this._showCellValues&&i>=.8&&T>20&&P>16&&(e.globalAlpha=1,e.font=this._cellFontSize+"px "+r,e.textAlign="center",e.textBaseline="middle",e.fillStyle=C>.55?"#fff":t.text,e.fillText(v(S),w+T/2,k+P/2))}}e.globalAlpha=1,e.textAlign="center",e.textBaseline="bottom",e.font="500 12px "+r,e.fillStyle=t.text2;for(var E=0;E<n;E++)e.fillText(this.xLabels[E],o+E*p+p/2,a-6);e.textAlign="right",e.textBaseline="middle";for(var L=0;L<_;L++)e.fillText(this.yLabels[L],o-8,a+L*f+f/2)},L.prototype.exportPNG=S.prototype.exportPNG,B.prototype._buildRadarDOM=function(){this._root=u("div","mc-root",this.el);var t=u("div","mc-header",this._root),e=u("div","mc-titles",t);this.opts.title&&(u("div","mc-title",e).textContent=this.opts.title);this.opts.subtitle&&(u("div","mc-subtitle",e).textContent=this.opts.subtitle);var i=u("div","mc-toolbar",t),s=this;if(this._toolbar.dark&&(this._darkBtn=u("button","",i),this._darkBtn.innerHTML=y,this._darkBtn.title="Toggle dark mode",this._darkBtn.addEventListener("click",function(){s.el.classList.toggle("mc-dark"),s._darkBtn.classList.toggle("active",s.el.classList.contains("mc-dark")),s.render()})),this._toolbar.export){var o=u("button","",i);o.innerHTML=M,o.title="Export PNG",o.addEventListener("click",function(){s.exportPNG()})}"top"!==this._legendPosition||this._legendHidden||(this._legendEl=u("div","mc-legend",this._root),this._buildRadarLegend()),this._wrap=u("div","mc-wrap",this._root),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this._wrap.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this._tooltipEl=u("div","mc-tooltip",this._wrap),this.series.length>0&&this._tooltipEl.style.setProperty("--mc-tt-accent",this.series[0].color),"bottom"!==this._legendPosition||this._legendHidden||(this._legendEl=u("div","mc-legend",this._root),this._buildRadarLegend()),this._legendEl||(this._legendEl=u("div","mc-legend",null),this._legendEl.style.display="none")},B.prototype._buildRadarLegend=function(){this._legendEl.innerHTML="";var t=this;this.series.forEach(function(e,i){var s=u("div","mc-legend-item",t._legendEl);e.visible||s.classList.add("disabled"),u("div","mc-legend-swatch",s).style.background=e.color,u("span","",s).textContent=e.name,s.addEventListener("click",function(){e.visible=!e.visible,s.classList.toggle("disabled",!e.visible),t.render()})})},B.prototype._initSize=function(){var t=this._wrap.getBoundingClientRect().width,e=Math.max(this._height,380);this.W=t,this.H=e,this.canvas.width=Math.round(t*i),this.canvas.height=Math.round(e*i),this.canvas.style.height=e+"px",this.ctx.setTransform(i,0,0,i,0,0)},B.prototype._startAnimation=S.prototype._startAnimation,B.prototype._bindRadarEvents=function(){var t,e=this;this._responsive&&window.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(function(){e._initSize(),e.render()},80)});this.canvas.addEventListener("mousemove",function(t){var i=e.canvas.getBoundingClientRect(),s=t.clientX-i.left,o=t.clientY-i.top;e._onRadarHover(s,o)}),this.canvas.addEventListener("mouseleave",function(){e._hoverAxis=-1,e._tooltipEl.classList.remove("visible"),e.render()})},B.prototype._onRadarHover=function(t,e){var i=this.W/2,s=this.H/2,o=Math.min(i,s)-60,a=this.categories.length;if(0!==a){var r=t-i,l=e-s;if(Math.sqrt(r*r+l*l)>o+30)this._hoverAxis>=0&&(this._hoverAxis=-1,this._tooltipEl.classList.remove("visible"),this.render());else{for(var h=Math.atan2(l,r),n=-Math.PI/2,d=2*Math.PI/a,_=-1,p=1/0,g=0;g<a;g++){var f=n+d*g,u=Math.abs(Math.atan2(Math.sin(h-f),Math.cos(h-f)));u<p&&(p=u,_=g)}p>d/2&&(_=-1);var b=this._hoverAxis;if(this._hoverAxis=_,this._hoverAxis!==b){if(this._hoverAxis>=0&&this._tooltipEnabled){var m=[],x=this;if(this.series.forEach(function(t){t.visible&&x._hoverAxis<t.data.length&&m.push({name:t.name,value:t.data[x._hoverAxis],color:t.color})}),m.length>0){this._tooltipEl.style.setProperty("--mc-tt-accent",m[0].color);var y='<div class="mc-tooltip-date">'+this.categories[this._hoverAxis]+"</div>";m.forEach(function(t){y+='<div class="mc-tooltip-row"><div class="mc-tooltip-dot" style="background:'+t.color+'"></div><span>'+t.name+'</span><span class="mc-tooltip-val" style="margin-left:8px;font-weight:600">'+v(t.value)+"</span></div>"}),this._tooltipEl.innerHTML=y,this._tooltipEl.classList.add("visible");var M=this._tooltipEl.offsetWidth,S=t+16;S+M>this.W-8&&(S=t-M-16);var C=e-this._tooltipEl.offsetHeight/2;C=c(C,4,this.H-this._tooltipEl.offsetHeight-4),this._tooltipEl.style.left=S+"px",this._tooltipEl.style.top=C+"px"}}else this._tooltipEl.classList.remove("visible");this.render()}}}},B.prototype.render=function(){var t=d(this.el),e=this.ctx;e.clearRect(0,0,this.W,this.H),e.fillStyle=t.card,e.fillRect(0,0,this.W,this.H);var i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);var o=this.W/2,a=this.H/2,l=Math.min(o,a)-60,h=this.categories.length;if(0!==h){for(var n=-Math.PI/2,_=2*Math.PI/h,p=this._max,g=1;g<=this._levels;g++){var u=l/this._levels*g;if(e.strokeStyle="rgba(226,232,240,0.6)",e.lineWidth=1,e.beginPath(),"circle"===this._gridStyle)e.arc(o,a,u,0,2*Math.PI);else{for(var x=0;x<=h;x++){var y=n+_*(x%h),M=o+u*Math.cos(y),S=a+u*Math.sin(y);0===x?e.moveTo(M,S):e.lineTo(M,S)}e.closePath()}if(e.stroke(),g<this._levels||g===this._levels){var C=p/this._levels*g;e.font="10px "+r,e.fillStyle=t.muted,e.textAlign="left",e.textBaseline="bottom",e.fillText(v(C),o+4,a-u-2)}}for(x=0;x<h;x++){y=n+_*x;var w=o+l*Math.cos(y),k=a+l*Math.sin(y);e.strokeStyle="rgba(226,232,240,0.4)",e.lineWidth=1,e.beginPath(),e.moveTo(o,a),e.lineTo(w,k),e.stroke(),this._hoverAxis===x&&(e.strokeStyle="rgba(99,102,241,0.3)",e.lineWidth=2,e.beginPath(),e.moveTo(o,a),e.lineTo(w,k),e.stroke())}if(this._axisLabels){e.font="500 12px "+r,e.fillStyle=t.text2;for(x=0;x<h;x++){y=n+_*x;var T=l+18,P=o+T*Math.cos(y),A=a+T*Math.sin(y);Math.abs(Math.cos(y))<.1?e.textAlign="center":Math.cos(y)>0?e.textAlign="left":e.textAlign="right",Math.abs(Math.sin(y))<.1?e.textBaseline="middle":Math.sin(y)>0?e.textBaseline="top":e.textBaseline="bottom",this._hoverAxis===x?(e.fillStyle=t.text,e.font="600 12px "+r):(e.fillStyle=t.text2,e.font="500 12px "+r),e.fillText(this.categories[x],P,A)}}for(var E=this.series.filter(function(t){return t.visible}),L=0;L<E.length;L++){var B=E[L],H=[];for(x=0;x<h;x++){y=n+_*x;var W=(O=x<B.data.length?B.data[x]:0)/p*l*s;H.push({x:o+W*Math.cos(y),y:a+W*Math.sin(y)})}var R=b(B.color);e.globalAlpha=this._fillOpacity,e.fillStyle="rgba("+R[0]+","+R[1]+","+R[2]+","+this._fillOpacity+")",e.beginPath();for(x=0;x<=h;x++){var D=H[x%h];0===x?e.moveTo(D.x,D.y):e.lineTo(D.x,D.y)}e.closePath(),e.globalAlpha=1,e.fill(),e.save(),e.shadowColor=B.color,e.shadowBlur=4,e.strokeStyle=B.color,e.lineWidth=this._lineWidth,e.lineJoin="round",e.beginPath();for(x=0;x<=h;x++){D=H[x%h];0===x?e.moveTo(D.x,D.y):e.lineTo(D.x,D.y)}e.closePath(),e.stroke(),e.restore();for(x=0;x<h;x++){D=H[x];this._hoverAxis===x&&(e.save(),e.shadowColor=B.color,e.shadowBlur=8,e.fillStyle=B.color,e.beginPath(),e.arc(D.x,D.y,this._dotRadius+2,0,2*Math.PI),e.fill(),e.restore());var I=e.createRadialGradient(D.x-.3*this._dotRadius,D.y-.3*this._dotRadius,0,D.x,D.y,this._dotRadius);if(I.addColorStop(0,m(B.color,.3)),I.addColorStop(1,B.color),e.fillStyle=I,e.beginPath(),e.arc(D.x,D.y,this._dotRadius,0,2*Math.PI),e.fill(),e.strokeStyle=t.card,e.lineWidth=1.5,e.stroke(),this._showValues&&i>=1){var O=x<B.data.length?B.data[x]:0;e.font="10px "+r,e.fillStyle=t.text2,e.textAlign="center",e.textBaseline="bottom",e.fillText(v(O),D.x,D.y-this._dotRadius-3)}}}}},B.prototype.exportPNG=S.prototype.exportPNG,CanvasRenderingContext2D.prototype.roundRect||(CanvasRenderingContext2D.prototype.roundRect=function(t,e,i,s,o){Array.isArray(o)||(o=[o,o,o,o]);var a=o[0]||0,r=o[1]||0,l=o[2]||0,h=o[3]||0;return this.moveTo(t+a,e),this.lineTo(t+i-r,e),this.quadraticCurveTo(t+i,e,t+i,e+r),this.lineTo(t+i,e+s-l),this.quadraticCurveTo(t+i,e+s,t+i-l,e+s),this.lineTo(t+h,e+s),this.quadraticCurveTo(t,e+s,t,e+s-h),this.lineTo(t,e+a),this.quadraticCurveTo(t,e,t+a,e),this.closePath(),this}),H.prototype=Object.create(S.prototype),H.prototype.constructor=H,H.prototype._computeScale=function(){var t=0,e=0;this.series.forEach(function(i){i.visible&&i.data.forEach(function(s){null!=s&&("line"===i.type?s>e&&(e=s):s>t&&(t=s))})}),this._barScaleMax=_(1.15*t),this._barStep=p(this._barScaleMax,5),this._barTicks=[];for(var i=0;i<=this._barScaleMax;i+=this._barStep)this._barTicks.push(i);if(this._dualAxis){this._lineScaleMax=_(1.15*e),this._lineStep=p(this._lineScaleMax,5),this._lineTicks=[];for(var s=0;s<=this._lineScaleMax;s+=this._lineStep)this._lineTicks.push(s)}else{var o=Math.max(t,e);this._barScaleMax=_(1.15*o),this._barStep=p(this._barScaleMax,5),this._barTicks=[];for(var a=0;a<=this._barScaleMax;a+=this._barStep)this._barTicks.push(a);this._lineScaleMax=this._barScaleMax,this._lineTicks=this._barTicks}this._scaleMax=this._barScaleMax,this._ticks=this._barTicks},H.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground();var t=this.ctx,e=this._vars,i=f(c(this._animProgress,0,1));i=Math.max(0,i);var s=this._padding,o=s.left,a=s.top,l=this._dualAxis?60:s.right,h=this.W-s.left-l,n=this.H-s.top-s.bottom,d=this.categories.length,_=h/d,p=a+n,g=this._borderRadius;if(this._barTicks.length>=2)for(var u=0;u<this._barTicks.length-1;u++)if(u%2!=0){var b=a+n-this._barTicks[u]/this._barScaleMax*n,m=a+n-this._barTicks[u+1]/this._barScaleMax*n;t.fillStyle="rgba(0,0,0,0.015)",t.fillRect(o,m,h,b-m)}t.textAlign="right",t.textBaseline="middle",t.font="500 12px "+r;for(var x=0;x<this._barTicks.length;x++){var y=this._barTicks[x],M=a+n-y/this._barScaleMax*n;this._gridLines&&(t.strokeStyle=this._gridColor||"rgba(226,232,240,0.6)",t.lineWidth=1,t.setLineDash(this._gridDashed?[4,4]:[]),t.beginPath(),t.moveTo(o,M),t.lineTo(o+h,M),t.stroke(),t.setLineDash([])),t.fillStyle=e.muted,t.fillText(v(y),o-8,M)}if(this._dualAxis){t.textAlign="left";for(var S=0;S<this._lineTicks.length;S++){var C=this._lineTicks[S],w=a+n-C/this._lineScaleMax*n;t.fillStyle=e.muted,t.fillText(v(C),o+h+8,w)}}t.textAlign="center",t.textBaseline="top",t.fillStyle=e.text2,t.font="500 12px "+r;for(var k=0;k<d;k++)t.fillText(this.categories[k],o+_*k+_/2,p+8);var T=[],P=[];this.series.forEach(function(t){t.visible&&("line"===t.type?P.push(t):T.push(t))});var A=T.length||1,E=this._barWidth||Math.min(.6*_/A,60),L=(_-(E*A+this._barGap*(A-1)))/2;this._hitAreas=[];for(var B=0;B<T.length;B++)for(var H=T[B],W=0;W<d;W++){var R=W<H.data.length?H.data[W]:null;if(null!=R){var D=R/this._barScaleMax*n*i,I=o+_*W+L+B*(E+this._barGap),O=p-D,G=this._hoverCat===W;this._drawBarShadow(t,I,O,E,D,[g,g,0,0],H.color),t.globalAlpha=G?this._hoverOpacity:this._barOpacity,t.fillStyle=this._getBarFill(H.color,I,O,E,D,!0),t.beginPath(),t.roundRect(I,O,E,D,[g,g,0,0]),t.fill(),D>4&&this._drawBarHighlight(t,I,O,E,g,!0),this._hitAreas.push({ci:W,si:B,x:I,y:O,w:E,h:D,series:H})}}t.globalAlpha=1;for(var z=this._dualAxis?this._lineScaleMax:this._barScaleMax,N=0;N<P.length;N++){for(var V=P[N],F=[],j=0;j<d;j++){var q=j<V.data.length?V.data[j]:null;null!=q&&F.push({x:o+_*j+_/2,y:p-q/z*n*i})}if(!(F.length<2)){t.save(),t.shadowColor=V.color,t.shadowBlur=8,t.shadowOffsetY=2,t.strokeStyle=V.color,t.lineWidth=this._lineWidth,t.lineJoin="round",t.lineCap="round",t.beginPath();var Y=this._lineTension;if(Y>0&&F.length>2){t.moveTo(F[0].x,F[0].y);for(var X=0;X<F.length-1;X++){var J=F[X],U=F[X+1];t.bezierCurveTo(J.x+(U.x-J.x)*Y,J.y,U.x-(U.x-J.x)*Y,U.y,U.x,U.y)}}else{t.moveTo(F[0].x,F[0].y);for(var K=1;K<F.length;K++)t.lineTo(F[K].x,F[K].y)}t.stroke(),t.restore();for(var Q=0;Q<F.length;Q++)t.fillStyle=V.color,t.beginPath(),t.arc(F[Q].x,F[Q].y,5,0,2*Math.PI),t.fill(),t.fillStyle=e.card,t.beginPath(),t.arc(F[Q].x,F[Q].y,2.5,0,2*Math.PI),t.fill()}}t.globalAlpha=1},H.prototype._onHover=C.prototype._onHover,W.prototype=Object.create(S.prototype),W.prototype.constructor=W,W.prototype._computeScale=function(){for(var t=this.series.length>0?this.series[0].data:[],e=0,i=0,s=0,o=0;o<t.length;o++)(e+=t[o])>s&&(s=e),e<i&&(i=e);var a=e;this._showTotal&&a>s&&(s=a),this._showTotal&&a<i&&(i=a);var r=Math.max(Math.abs(i),Math.abs(s));this._scaleMax=_(1.15*r),this._scaleMin=i<0?-_(1.15*Math.abs(i)):0;var l=this._scaleMax-this._scaleMin;this._step=p(l,5),this._ticks=[];for(var h=this._scaleMin;h<=this._scaleMax;h+=this._step)this._ticks.push(Math.round(100*h)/100)},W.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground();var t=this.ctx,e=this._vars,i=this._animProgress,s=f(c(i,0,1));s=Math.max(0,s);for(var o=this._padding,a=o.left,l=o.top,h=this.W-o.left-o.right,n=this.H-o.top-o.bottom,d=this.series.length>0?this.series[0].data:[],_=this.categories.slice(),p=d.slice(),g=0,u=0;u<d.length;u++)g+=d[u];this._showTotal&&(_.push("Total"),p.push(g));var b=_.length,m=h/b,x=this._barWidth||Math.min(.6*m,60),y=this._scaleMax-this._scaleMin,M=this._borderRadius;function S(t){return l+n-(t-this._scaleMin)/y*n}var C=this;t.textAlign="right",t.textBaseline="middle",t.font="500 12px "+r;for(var w=0;w<this._ticks.length;w++){var k=this._ticks[w],T=S.call(C,k);this._gridLines&&(t.strokeStyle=this._gridColor||"rgba(226,232,240,0.6)",t.lineWidth=1,t.setLineDash(this._gridDashed?[4,4]:[]),t.beginPath(),t.moveTo(a,T),t.lineTo(a+h,T),t.stroke(),t.setLineDash([])),t.fillStyle=e.muted,t.fillText(v(k),a-8,T)}t.textAlign="center",t.textBaseline="top",t.fillStyle=e.text2,t.font="500 12px "+r;for(var P=0;P<b;P++)t.fillText(_[P],a+m*P+m/2,l+n+8);var A=0,E=S.call(C,0);this._hitAreas=[];for(var L=0;L<b;L++){var B,H,W,R,D=this._showTotal&&L===b-1;if(D)H=S.call(C,0),W=S.call(C,g*s),R=this._totalColor;else{var I=A;A+=B=d[L],H=S.call(C,I*s),W=S.call(C,A*s),R=B>=0?this._positiveColor:this._negativeColor}var O=a+m*L+(m-x)/2,G=Math.min(H,W),z=Math.max(H,W),N=z-G,V=this._hoverCat===L;if(this._showConnectors&&L>0&&!D&&(t.strokeStyle=e.muted,t.lineWidth=1,t.setLineDash([3,3]),t.beginPath(),t.moveTo(a+m*(L-1)+(m+x)/2,E),t.lineTo(O,E),t.stroke(),t.setLineDash([])),E=D?S.call(C,g*s):S.call(C,A*s),this._drawBarShadow(t,O,G,x,N,[M,M,M,M],R),t.globalAlpha=V?this._hoverOpacity:this._opacity,t.fillStyle=this._getBarFill(R,O,G,x,N,!0),t.beginPath(),t.roundRect(O,G,x,Math.max(N,1),[M,M,M,M]),t.fill(),N>4&&this._drawBarHighlight(t,O,G,x,M,!0),i>=1&&this._showValues){t.globalAlpha=1,t.font=this._valueSize+"px "+r,t.textAlign="center";var F=D?g:d[L];t.textBaseline=W<H?"bottom":"top",t.fillStyle=this._valueColor||e.text2;var j=W<H?G-4:z+4;t.fillText(v(F),O+x/2,j)}this._hitAreas.push({ci:L,si:0,x:O,y:G,w:x,h:N,series:this.series[0]||{}})}t.globalAlpha=1},W.prototype._onHover=function(t,e){var i=this._hoverCat;this._hoverCat=-1;var s=this._padding,o=s.left,a=this.W-s.left-s.right,r=this._showTotal?this.categories.length+1:this.categories.length,l=a/r;if(t>=o&&t<=o+a&&(this._hoverCat=Math.floor((t-o)/l),this._hoverCat>=r&&(this._hoverCat=r-1)),this._hoverCat!==i&&this.render(),this._hoverCat>=0){var h=this.series.length>0?this.series[0].data:[],n=this.categories.slice();this._showTotal&&n.push("Total");for(var d=0,c=0;c<=this._hoverCat&&c<h.length;c++)d+=h[c];var _=this._showTotal&&this._hoverCat===n.length-1,p=[{color:_?this._totalColor:h[this._hoverCat]>=0?this._positiveColor:this._negativeColor,name:_?"Total":h[this._hoverCat]>=0?"Increase":"Decrease",value:_?d:h[this._hoverCat]}];_||p.push({color:"#64748b",name:"Cumulative",value:d}),this._showTooltip(t,e,n[this._hoverCat],p)}else this._hideTooltip()},R.prototype=Object.create(S.prototype),R.prototype.constructor=R,R.prototype._computeScale=function(){var t=0;this._items.forEach(function(e){var i=e.ranges;if(i&&i.length>0){var s=i[i.length-1];s>t&&(t=s)}e.actual>t&&(t=e.actual),e.target>t&&(t=e.target)}),this._scaleMax=_(1.05*t),this._step=p(this._scaleMax,5),this._ticks=[];for(var e=0;e<=this._scaleMax;e+=this._step)this._ticks.push(e)},R.prototype.render=function(){this._computeScale(),this._clearAndDrawBackground();var t=this.ctx,e=this._vars,i=g(c(this._animProgress,0,1)),s=this._padding,o=s.left,a=s.top,l=this.W-s.left-s.right,h=this.H-s.top-s.bottom,n=this._items.length,d=h/n,_=this._rangeColors;t.textAlign="center",t.textBaseline="top",t.font="500 12px "+r;for(var p=0;p<this._ticks.length;p++){var f=this._ticks[p],u=o+f/this._scaleMax*l;this._gridLines&&(t.strokeStyle=this._gridColor||"rgba(226,232,240,0.4)",t.lineWidth=1,t.setLineDash(this._gridDashed?[4,4]:[]),t.beginPath(),t.moveTo(u,a),t.lineTo(u,a+h),t.stroke(),t.setLineDash([])),t.fillStyle=e.muted,t.fillText(v(f),u,a+h+8)}t.textAlign="right",t.textBaseline="middle",t.fillStyle=e.text2,t.font="500 12px "+r,this._hitAreas=[];for(var b=this._barHeightRatio,x=0;x<n;x++){var y=this._items[x],M=a+d*x+d/2,S=.65*d,C=d*b,w=this._hoverCat===x;t.fillStyle=e.text2,t.textAlign="right",t.textBaseline="middle",t.fillText(y.label,o-8,M);for(var k=y.ranges||[],T=k.length-1;T>=0;T--){var P=k[T]/this._scaleMax*l*i;t.fillStyle=_[T]||"#e2e8f0",t.beginPath(),t.roundRect(o,M-S/2,P,S,2),t.fill()}var A=y.actual/this._scaleMax*l*i,E=t.createLinearGradient(o,0,o+A,0);E.addColorStop(0,this._barColor),E.addColorStop(1,m(this._barColor,.3)),t.fillStyle=E,t.globalAlpha=w?1:.9,t.beginPath(),t.roundRect(o,M-C/2,A,C,2),t.fill(),t.globalAlpha=1;var L=o+y.target/this._scaleMax*l*i;t.strokeStyle=this._markerColor,t.lineWidth=2.5,t.beginPath(),t.moveTo(L,M-S/2-2),t.lineTo(L,M+S/2+2),t.stroke(),this._hitAreas.push({ci:x,si:0,x:o,y:M-S/2,w:l,h:S,series:this.series[0]||{}})}},R.prototype._onHover=function(t,e){var i=this._hoverCat;this._hoverCat=-1;var s=this._padding,o=s.top,a=this.H-s.top-s.bottom,r=this._items.length,l=a/r;if(e>=o&&e<=o+a&&(this._hoverCat=Math.floor((e-o)/l),this._hoverCat>=r&&(this._hoverCat=r-1)),this._hoverCat!==i&&this.render(),this._hoverCat>=0){var h=this._items[this._hoverCat];this._showTooltip(t,e,h.label,[{color:this._barColor,name:"Actual",value:h.actual},{color:this._markerColor,name:"Target",value:h.target}])}else this._hideTooltip()},D.prototype=Object.create(S.prototype),D.prototype.constructor=D,D.prototype.render=function(){this._clearAndDrawBackground();var t=this.ctx,e=this._vars,i=this._animProgress,s=g(c(i,0,1)),o=this._padding,a=o.left,l=o.top+10,h=this.W-o.left-o.right,n=this._barHeight,d=this._segGap,_=this._segments,p=0;_.forEach(function(t){p+=t.value});var f=l+20,u=a;this._segRects=[];for(var b=0;b<_.length;b++){var x=_[b],y=x.value/p,M=(h-d*(_.length-1))*y*s,S=u,C=[0,0,0,0];this._rounded&&(0===b&&(C=[6,0,0,6]),b===_.length-1&&(C=[0,6,6,0]),1===_.length&&(C=[6,6,6,6]));var w=t.createLinearGradient(S,f,S,f+n);w.addColorStop(0,x.color),w.addColorStop(1,m(x.color,.25));var k=this._hoverCat===b;t.globalAlpha=k?1:.88,t.fillStyle=w,t.beginPath(),t.roundRect(S,f,Math.max(M,0),n,C),t.fill(),M>4&&(t.save(),t.globalAlpha=.2,t.strokeStyle="rgba(255,255,255,0.5)",t.lineWidth=1,t.beginPath(),t.moveTo(S+(0===b?C[0]:0)+1,f+1),t.lineTo(S+M-(b===_.length-1?C[1]:0)-1,f+1),t.stroke(),t.restore()),t.globalAlpha=1;var T=(100*y).toFixed(1)+"%",P=M-8;if(P>30){t.font="bold 12px "+r,t.textAlign="center",t.textBaseline="middle",t.fillStyle="#fff";var A=x.label;t.measureText(A).width>P&&(A=A.substring(0,Math.floor(P/7))+".."),t.fillText(A,S+M/2,f+n/2-(this._showPercent?7:0)),this._showPercent&&(t.font="11px "+r,t.globalAlpha=.85,t.fillText(T,S+M/2,f+n/2+8),t.globalAlpha=1)}P<=30&&i>=1&&(t.font="10px "+r,t.textAlign="center",t.textBaseline="top",t.fillStyle=e.text2,t.save(),t.translate(S+M/2,f+n+8),t.rotate(Math.PI/6),t.fillText(x.label,0,0),t.restore()),this._showSegValues&&i>=1&&P>40&&(t.font="10px "+r,t.textAlign="center",t.textBaseline="top",t.fillStyle=e.muted,t.fillText(v(x.value),S+M/2,f+n+6)),this._segRects.push({x:S,y:f,w:M,h:n,idx:b}),u+=M+d}t.globalAlpha=1},D.prototype._onHover=function(t,e){var i=this._hoverCat;if(this._hoverCat=-1,this._segRects)for(var s=0;s<this._segRects.length;s++){var o=this._segRects[s];if(t>=o.x&&t<=o.x+o.w&&e>=o.y&&e<=o.y+o.h){this._hoverCat=s;break}}if(this._hoverCat!==i&&this.render(),this._hoverCat>=0){var a=this._segments[this._hoverCat],r=0;this._segments.forEach(function(t){r+=t.value});var l=(a.value/r*100).toFixed(1);this._showTooltip(t,e,a.label,[{color:a.color,name:"Value",value:a.value},{color:"#64748b",name:"Share",value:l+"%"}])}else this._hideTooltip()},D.prototype._computeScale=function(){this._scaleMax=1,this._ticks=[]},e.bar=function(t,e){return new w(t,e)},e.column=function(t,e){return new C(t,e)},e.barStacked=function(t,e){return new k(t,e)},e.lollipop=function(t,e){return new T(t,e)},e.combo=function(t,e){return new P(t,e)},e.donut=function(t,e){return new A(t,e)},e.gauge=function(t,e){return new E(t,e)},e.heatmap=function(t,e){return new L(t,e)},e.radar=function(t,e){return new B(t,e)},e.lineBar=function(t,e){return new H(t,e)},e.waterfall=function(t,e){return new W(t,e)},e.bullet=function(t,e){return new R(t,e)},e.timeline=function(t,e){return new D(t,e)},"object"==typeof module&&module.exports&&(module.exports=e)}("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:this);
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NMCharts Extras — Themes, SVG Export, ResizeObserver, Accessibility
|
|
3
|
+
* Load after nmcharts.js and nmcharts-categories.js
|
|
4
|
+
*/
|
|
5
|
+
(function (root) {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
var NM = root.NMCharts;
|
|
9
|
+
if (!NM) throw new Error('NMCharts-Extras: NMCharts must be loaded first.');
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// 1. PREDEFINED THEMES
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
NM.themes = {
|
|
16
|
+
corporate: ['#1e3a5f', '#2d6a9f', '#4a90d9', '#7cb5ec', '#a8d1f0', '#2f4858', '#547a96', '#8fb3c9'],
|
|
17
|
+
pastel: ['#a8d8ea', '#aa96da', '#fcbad3', '#ffffd2', '#b5ead7', '#c7ceea', '#ffdac1', '#e2f0cb'],
|
|
18
|
+
vibrant: ['#ff6b6b', '#feca57', '#48dbfb', '#ff9ff3', '#54a0ff', '#5f27cd', '#01a3a4', '#f368e0'],
|
|
19
|
+
monochrome: ['#1a1a2e', '#3d3d5c', '#5f5f8a', '#8282b8', '#a5a5d0', '#c8c8e6', '#e0e0f0', '#f0f0f8'],
|
|
20
|
+
colorblind: ['#0072B2', '#E69F00', '#009E73', '#D55E00', '#CC79A7', '#56B4E9', '#F0E442', '#999999']
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// 2. HELPERS
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
/** Debounce: returns a function that delays invoking fn until after wait ms. */
|
|
28
|
+
function debounce(fn, wait) {
|
|
29
|
+
var timer;
|
|
30
|
+
return function () {
|
|
31
|
+
var ctx = this, args = arguments;
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
timer = setTimeout(function () { fn.apply(ctx, args); }, wait);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Inject theme colors into opts.series entries that lack explicit colors,
|
|
39
|
+
* and into opts.colors if not already set.
|
|
40
|
+
* Mutates a shallow clone of opts to avoid modifying the caller's object.
|
|
41
|
+
*/
|
|
42
|
+
function applyTheme(opts) {
|
|
43
|
+
if (!opts || !opts.theme) return opts;
|
|
44
|
+
var palette = NM.themes[opts.theme];
|
|
45
|
+
if (!palette) return opts;
|
|
46
|
+
|
|
47
|
+
// Shallow clone
|
|
48
|
+
var o = Object.assign({}, opts);
|
|
49
|
+
|
|
50
|
+
// Apply colors array if not explicitly provided
|
|
51
|
+
if (!o.colors) {
|
|
52
|
+
o.colors = palette;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Apply per-series colors where missing
|
|
56
|
+
if (o.series) {
|
|
57
|
+
o.series = o.series.map(function (s, i) {
|
|
58
|
+
if (s.color) return s;
|
|
59
|
+
return Object.assign({}, s, { color: palette[i % palette.length] });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return o;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// 3. ACCESSIBILITY HELPERS
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
/** Inject ARIA attributes and a visually-hidden data table for screen readers. */
|
|
71
|
+
function injectA11y(instance, chartType) {
|
|
72
|
+
var root = instance._root;
|
|
73
|
+
if (!root) return;
|
|
74
|
+
|
|
75
|
+
var opts = instance.opts || {};
|
|
76
|
+
var title = opts.title || '';
|
|
77
|
+
var label = title ? (title + ' — ' + chartType + ' chart') : (chartType + ' chart');
|
|
78
|
+
|
|
79
|
+
root.setAttribute('role', 'img');
|
|
80
|
+
root.setAttribute('aria-label', label);
|
|
81
|
+
root.setAttribute('tabindex', '0');
|
|
82
|
+
|
|
83
|
+
// Build a visually-hidden table from series data when available
|
|
84
|
+
var series = instance.series;
|
|
85
|
+
var categories = instance.categories;
|
|
86
|
+
if (!series || !series.length) return;
|
|
87
|
+
|
|
88
|
+
// Only build if categories exist (category charts), or data arrays exist
|
|
89
|
+
var table = document.createElement('table');
|
|
90
|
+
table.style.cssText = [
|
|
91
|
+
'position:absolute',
|
|
92
|
+
'width:1px',
|
|
93
|
+
'height:1px',
|
|
94
|
+
'padding:0',
|
|
95
|
+
'margin:-1px',
|
|
96
|
+
'overflow:hidden',
|
|
97
|
+
'clip:rect(0,0,0,0)',
|
|
98
|
+
'white-space:nowrap',
|
|
99
|
+
'border:0'
|
|
100
|
+
].join(';');
|
|
101
|
+
|
|
102
|
+
// Caption
|
|
103
|
+
var caption = document.createElement('caption');
|
|
104
|
+
caption.textContent = label;
|
|
105
|
+
table.appendChild(caption);
|
|
106
|
+
|
|
107
|
+
if (categories && categories.length) {
|
|
108
|
+
// Header row: category labels
|
|
109
|
+
var thead = document.createElement('thead');
|
|
110
|
+
var headerRow = document.createElement('tr');
|
|
111
|
+
var thEmpty = document.createElement('th');
|
|
112
|
+
thEmpty.textContent = 'Series';
|
|
113
|
+
headerRow.appendChild(thEmpty);
|
|
114
|
+
categories.forEach(function (cat) {
|
|
115
|
+
var th = document.createElement('th');
|
|
116
|
+
th.setAttribute('scope', 'col');
|
|
117
|
+
th.textContent = String(cat);
|
|
118
|
+
headerRow.appendChild(th);
|
|
119
|
+
});
|
|
120
|
+
thead.appendChild(headerRow);
|
|
121
|
+
table.appendChild(thead);
|
|
122
|
+
|
|
123
|
+
// Body rows: one row per series
|
|
124
|
+
var tbody = document.createElement('tbody');
|
|
125
|
+
series.forEach(function (s) {
|
|
126
|
+
var tr = document.createElement('tr');
|
|
127
|
+
var th = document.createElement('th');
|
|
128
|
+
th.setAttribute('scope', 'row');
|
|
129
|
+
th.textContent = s.name || '';
|
|
130
|
+
tr.appendChild(th);
|
|
131
|
+
(s.data || []).forEach(function (v) {
|
|
132
|
+
var td = document.createElement('td');
|
|
133
|
+
td.textContent = v != null ? String(v) : '';
|
|
134
|
+
tr.appendChild(td);
|
|
135
|
+
});
|
|
136
|
+
tbody.appendChild(tr);
|
|
137
|
+
});
|
|
138
|
+
table.appendChild(tbody);
|
|
139
|
+
} else {
|
|
140
|
+
// Single-value series (gauge, donut-like): just list name + value
|
|
141
|
+
var tbody2 = document.createElement('tbody');
|
|
142
|
+
series.forEach(function (s) {
|
|
143
|
+
var tr = document.createElement('tr');
|
|
144
|
+
var tdName = document.createElement('td');
|
|
145
|
+
tdName.textContent = s.name || '';
|
|
146
|
+
var tdVal = document.createElement('td');
|
|
147
|
+
tdVal.textContent = s.value != null ? String(s.value) : (Array.isArray(s.data) ? s.data.join(', ') : '');
|
|
148
|
+
tr.appendChild(tdName);
|
|
149
|
+
tr.appendChild(tdVal);
|
|
150
|
+
tbody2.appendChild(tr);
|
|
151
|
+
});
|
|
152
|
+
table.appendChild(tbody2);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Append to root (positioned so it doesn't affect layout)
|
|
156
|
+
root.style.position = root.style.position || 'relative';
|
|
157
|
+
root.appendChild(table);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// 4. SVG EXPORT
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Export chart as SVG by wrapping the canvas data URL in an SVG <image> element.
|
|
166
|
+
* Works on any chart instance that has a .canvas property.
|
|
167
|
+
* @param {string} [filename] - Download filename (default: 'chart.svg')
|
|
168
|
+
*/
|
|
169
|
+
function exportSVG(filename) {
|
|
170
|
+
var canvas = this.canvas;
|
|
171
|
+
if (!canvas) {
|
|
172
|
+
console.warn('NMCharts exportSVG: no canvas found on instance');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
var w = canvas.width / (window.devicePixelRatio || 1);
|
|
177
|
+
var h = canvas.height / (window.devicePixelRatio || 1);
|
|
178
|
+
var dataURL = canvas.toDataURL('image/png');
|
|
179
|
+
|
|
180
|
+
var svg = [
|
|
181
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
182
|
+
'<svg xmlns="http://www.w3.org/2000/svg"',
|
|
183
|
+
' xmlns:xlink="http://www.w3.org/1999/xlink"',
|
|
184
|
+
' width="' + w + '" height="' + h + '"',
|
|
185
|
+
' viewBox="0 0 ' + w + ' ' + h + '">',
|
|
186
|
+
' <title>' + ((this.opts && this.opts.title) ? escapeXml(this.opts.title) : 'Chart') + '</title>',
|
|
187
|
+
' <image x="0" y="0" width="' + w + '" height="' + h + '"',
|
|
188
|
+
' xlink:href="' + dataURL + '"',
|
|
189
|
+
' href="' + dataURL + '"/>',
|
|
190
|
+
'</svg>'
|
|
191
|
+
].join('\n');
|
|
192
|
+
|
|
193
|
+
var blob = new Blob([svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
194
|
+
var url = URL.createObjectURL(blob);
|
|
195
|
+
var a = document.createElement('a');
|
|
196
|
+
a.download = filename || 'chart.svg';
|
|
197
|
+
a.href = url;
|
|
198
|
+
a.click();
|
|
199
|
+
setTimeout(function () { URL.revokeObjectURL(url); }, 1000);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function escapeXml(str) {
|
|
203
|
+
return String(str)
|
|
204
|
+
.replace(/&/g, '&')
|
|
205
|
+
.replace(/</g, '<')
|
|
206
|
+
.replace(/>/g, '>')
|
|
207
|
+
.replace(/"/g, '"')
|
|
208
|
+
.replace(/'/g, ''');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Attach exportSVG to the time-series prototype
|
|
212
|
+
NM.prototype.exportSVG = exportSVG;
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// 5. FACTORY METHOD WRAPPING
|
|
216
|
+
// Wraps each factory method to:
|
|
217
|
+
// a) apply theme colors from opts.theme
|
|
218
|
+
// b) attach ResizeObserver for re-render on container resize
|
|
219
|
+
// c) inject accessibility attributes
|
|
220
|
+
// d) expose exportSVG on the returned instance
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
var FACTORY_METHODS = [
|
|
224
|
+
'create',
|
|
225
|
+
'bar',
|
|
226
|
+
'column',
|
|
227
|
+
'barStacked',
|
|
228
|
+
'lollipop',
|
|
229
|
+
'combo',
|
|
230
|
+
'donut',
|
|
231
|
+
'gauge',
|
|
232
|
+
'heatmap',
|
|
233
|
+
'radar',
|
|
234
|
+
'lineBar',
|
|
235
|
+
'waterfall',
|
|
236
|
+
'bullet',
|
|
237
|
+
'timeline',
|
|
238
|
+
'treemap',
|
|
239
|
+
'funnel',
|
|
240
|
+
'polar',
|
|
241
|
+
'scatter',
|
|
242
|
+
'sankey',
|
|
243
|
+
'boxplot',
|
|
244
|
+
'sparkline'
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
var RESIZE_DEBOUNCE_MS = 150;
|
|
248
|
+
|
|
249
|
+
FACTORY_METHODS.forEach(function (method) {
|
|
250
|
+
var original = NM[method];
|
|
251
|
+
if (typeof original !== 'function') return;
|
|
252
|
+
|
|
253
|
+
NM[method] = function (selector, opts) {
|
|
254
|
+
// a) Apply theme if specified
|
|
255
|
+
var themedOpts = applyTheme(opts);
|
|
256
|
+
|
|
257
|
+
// b) Create chart via original factory
|
|
258
|
+
var instance = original.call(NM, selector, themedOpts);
|
|
259
|
+
if (!instance) return instance;
|
|
260
|
+
|
|
261
|
+
// c) Expose exportSVG if not already present
|
|
262
|
+
if (typeof instance.exportSVG !== 'function') {
|
|
263
|
+
instance.exportSVG = exportSVG.bind(instance);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// d) Accessibility
|
|
267
|
+
var chartType = method === 'create' ? 'line' : method;
|
|
268
|
+
injectA11y(instance, chartType);
|
|
269
|
+
|
|
270
|
+
// e) ResizeObserver
|
|
271
|
+
if (typeof ResizeObserver !== 'undefined' && instance._root) {
|
|
272
|
+
var debouncedRender = debounce(function () {
|
|
273
|
+
if (typeof instance._initSize === 'function') {
|
|
274
|
+
instance._initSize();
|
|
275
|
+
}
|
|
276
|
+
if (typeof instance.render === 'function') {
|
|
277
|
+
instance.render();
|
|
278
|
+
}
|
|
279
|
+
// Time-series also needs navigator re-render
|
|
280
|
+
if (typeof instance._renderNav === 'function') {
|
|
281
|
+
instance._renderNav();
|
|
282
|
+
}
|
|
283
|
+
}, RESIZE_DEBOUNCE_MS);
|
|
284
|
+
|
|
285
|
+
var observer = new ResizeObserver(function (entries) {
|
|
286
|
+
if (!entries || !entries.length) return;
|
|
287
|
+
debouncedRender();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Observe the root element (the mc-root div)
|
|
291
|
+
observer.observe(instance._root);
|
|
292
|
+
|
|
293
|
+
// Store on instance for cleanup
|
|
294
|
+
instance._resizeObserver = observer;
|
|
295
|
+
|
|
296
|
+
// Patch destroy to disconnect observer
|
|
297
|
+
var originalDestroy = instance.destroy;
|
|
298
|
+
instance.destroy = function () {
|
|
299
|
+
if (instance._resizeObserver) {
|
|
300
|
+
instance._resizeObserver.disconnect();
|
|
301
|
+
instance._resizeObserver = null;
|
|
302
|
+
}
|
|
303
|
+
if (typeof originalDestroy === 'function') {
|
|
304
|
+
originalDestroy.call(instance);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return instance;
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// ---------------------------------------------------------------------------
|
|
314
|
+
// UMD export (mirror pattern from nmcharts.js / nmcharts-categories.js)
|
|
315
|
+
// ---------------------------------------------------------------------------
|
|
316
|
+
if (typeof module === 'object' && module.exports) {
|
|
317
|
+
module.exports = NM;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
})(typeof window !== 'undefined' ? window : typeof globalThis !== 'undefined' ? globalThis : this);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){"use strict";var t=e.NMCharts;if(!t)throw new Error("NMCharts-Extras: NMCharts must be loaded first.");function n(e){var t=this.canvas;if(t){var n,r=t.width/(window.devicePixelRatio||1),a=t.height/(window.devicePixelRatio||1),o=t.toDataURL("image/png"),i=['<?xml version="1.0" encoding="UTF-8"?>','<svg xmlns="http://www.w3.org/2000/svg"',' xmlns:xlink="http://www.w3.org/1999/xlink"',' width="'+r+'" height="'+a+'"',' viewBox="0 0 '+r+" "+a+'">'," <title>"+(this.opts&&this.opts.title?(n=this.opts.title,String(n).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")):"Chart")+"</title>",' <image x="0" y="0" width="'+r+'" height="'+a+'"',' xlink:href="'+o+'"',' href="'+o+'"/>',"</svg>"].join("\n"),c=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),l=URL.createObjectURL(c),d=document.createElement("a");d.download=e||"chart.svg",d.href=l,d.click(),setTimeout(function(){URL.revokeObjectURL(l)},1e3)}else console.warn("NMCharts exportSVG: no canvas found on instance")}t.themes={corporate:["#1e3a5f","#2d6a9f","#4a90d9","#7cb5ec","#a8d1f0","#2f4858","#547a96","#8fb3c9"],pastel:["#a8d8ea","#aa96da","#fcbad3","#ffffd2","#b5ead7","#c7ceea","#ffdac1","#e2f0cb"],vibrant:["#ff6b6b","#feca57","#48dbfb","#ff9ff3","#54a0ff","#5f27cd","#01a3a4","#f368e0"],monochrome:["#1a1a2e","#3d3d5c","#5f5f8a","#8282b8","#a5a5d0","#c8c8e6","#e0e0f0","#f0f0f8"],colorblind:["#0072B2","#E69F00","#009E73","#D55E00","#CC79A7","#56B4E9","#F0E442","#999999"]},t.prototype.exportSVG=n;["create","bar","column","barStacked","lollipop","combo","donut","gauge","heatmap","radar","lineBar","waterfall","bullet","timeline"].forEach(function(e){var r=t[e];"function"==typeof r&&(t[e]=function(a,o){var i,c,l,d=function(e){if(!e||!e.theme)return e;var n=t.themes[e.theme];if(!n)return e;var r=Object.assign({},e);return r.colors||(r.colors=n),r.series&&(r.series=r.series.map(function(e,t){return e.color?e:Object.assign({},e,{color:n[t%n.length]})})),r}(o),s=r.call(t,a,d);if(!s)return s;if("function"!=typeof s.exportSVG&&(s.exportSVG=n.bind(s)),function(e,t){var n=e._root;if(n){var r=(e.opts||{}).title||"",a=r?r+" — "+t+" chart":t+" chart";n.setAttribute("role","img"),n.setAttribute("aria-label",a),n.setAttribute("tabindex","0");var o=e.series,i=e.categories;if(o&&o.length){var c=document.createElement("table");c.style.cssText=["position:absolute","width:1px","height:1px","padding:0","margin:-1px","overflow:hidden","clip:rect(0,0,0,0)","white-space:nowrap","border:0"].join(";");var l=document.createElement("caption");if(l.textContent=a,c.appendChild(l),i&&i.length){var d=document.createElement("thead"),s=document.createElement("tr"),f=document.createElement("th");f.textContent="Series",s.appendChild(f),i.forEach(function(e){var t=document.createElement("th");t.setAttribute("scope","col"),t.textContent=String(e),s.appendChild(t)}),d.appendChild(s),c.appendChild(d);var p=document.createElement("tbody");o.forEach(function(e){var t=document.createElement("tr"),n=document.createElement("th");n.setAttribute("scope","row"),n.textContent=e.name||"",t.appendChild(n),(e.data||[]).forEach(function(e){var n=document.createElement("td");n.textContent=null!=e?String(e):"",t.appendChild(n)}),p.appendChild(t)}),c.appendChild(p)}else{var u=document.createElement("tbody");o.forEach(function(e){var t=document.createElement("tr"),n=document.createElement("td");n.textContent=e.name||"";var r=document.createElement("td");r.textContent=null!=e.value?String(e.value):Array.isArray(e.data)?e.data.join(", "):"",t.appendChild(n),t.appendChild(r),u.appendChild(t)}),c.appendChild(u)}n.style.position=n.style.position||"relative",n.appendChild(c)}}}(s,"create"===e?"line":e),"undefined"!=typeof ResizeObserver&&s._root){var f=(i=function(){"function"==typeof s._initSize&&s._initSize(),"function"==typeof s.render&&s.render(),"function"==typeof s._renderNav&&s._renderNav()},c=150,function(){var e=this,t=arguments;clearTimeout(l),l=setTimeout(function(){i.apply(e,t)},c)}),p=new ResizeObserver(function(e){e&&e.length&&f()});p.observe(s._root),s._resizeObserver=p;var u=s.destroy;s.destroy=function(){s._resizeObserver&&(s._resizeObserver.disconnect(),s._resizeObserver=null),"function"==typeof u&&u.call(s)}}return s})}),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:this);
|