UNPKG

apexcharts

Version:

A JavaScript Chart Library

6 lines (5 loc) 15.9 kB
/*! * ApexCharts v7.0.0 * (c) 2018-2026 ApexCharts */ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function t(t){if(t&&t.__esModule)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const s in t)if("default"!==s){const i=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:()=>t[s]})}return e.default=t,Object.freeze(e)}const e=t(require("apexcharts/core")),s=e.__apex_Graphics,i=e.__apex_BrowserAPIs_BrowserAPIs,r=e.__apex_Environment_Environment,a=Math.PI/180,o=180/Math.PI;function n(t,e,s,i){return{x:t+s*Math.cos((i-90)*a),y:e+s*Math.sin((i-90)*a)}}const l=t=>`${t.x} ${t.y}`;const c=e.__apex_Animations;function h(t,e,s,i,r,a=null,o={}){var n,l,c;const u=e&&"object"==typeof e,d=u&&null!=(l=null!=(n=e.x)?n:e.name)?l:"",_=Number(u?null!=(c=e.y)?c:e.value:e),p={name:String(d),value:isNaN(_)?null:_,color:u&&e.color?e.color:void 0,_key:`${r}/${s}:${d}`};if(i&&!p.color&&(p.color=i[s%i.length]),o.keepDatum&&(p._datum=e),u&&Array.isArray(e.children)&&e.children.length)p.children=e.children.map((e,s)=>h(t,e,s,null,p._key,a,o));else if(u&&null!=e.drilldown&&!1!==o.expandDrilldown){const s=a||new Set;if(!s.has(e.drilldown)){const i=function(t,e){const s=t.config.drilldown;return(s&&Array.isArray(s.series)?s.series:[]).find(t=>t&&t.id===e)}(t,e.drilldown);if(i&&Array.isArray(i.data)&&i.data.length){const r=new Set(s);r.add(e.drilldown);const a=Array.isArray(i.colors)?i.colors:null;p.children=i.data.map((e,s)=>h(t,e,s,a,p._key,r,o))}}}return p}function u(t){t.children&&t.children.length&&(t.children.forEach(t=>u(t)),(null==t.value||isNaN(t.value))&&(t.value=t.children.reduce((t,e)=>t+Math.max(0,e.value||0),0))),(null==t.value||isNaN(t.value))&&(t.value=0)}function d(t){if("string"!=typeof t)return"";const e=t.indexOf("/");return-1===e?"":t.slice(e)}const _=Math.PI/180,p=180/Math.PI,f="http://www.w3.org/2000/svg",m="http://www.w3.org/1999/xhtml",g=(t,e,s)=>t+(e-t)*s;e.default.use({sunburst:class{constructor(t,e){this.ctx=e,this.w=t;const s=t.config;this.cfg=s.plotOptions.sunburst,this.strokeWidth=s.stroke.show?s.stroke.width:0,this.strokeColor=Array.isArray(s.stroke.colors)?s.stroke.colors[0]:s.stroke.colors||"#fff",this.startAngle=this.cfg.startAngle,this.endAngle=this.cfg.endAngle,this.maxDepth=0,this.centerX=0,this.centerY=0,this.maxRadius=0,this.total=1,this._focusMaxDepth=0,this._focus=null,this._zoomGen=0,this._roots=[],this._nodesAll=[],this._innerR=()=>0,this._outerR=()=>0,this._tooltipEl=null,this._lblSeq=0,this._morphLeafIndex=0,this._graphics=null,this._ringsG=null,this._labelsG=null}draw(t){const e=this.w,i=new s(this.w);this._graphics=i;const r=i.group({class:"apexcharts-sunburst"});if(e.globals.noData||!t||!t.length)return r;const a=e.layout.gridWidth,o=e.layout.gridHeight;if(this.centerX=a/2+(this.cfg.offsetX||0),this.centerY=o/2+(this.cfg.offsetY||0),this.maxRadius=Math.min(a,o)/2.05-this.strokeWidth-(e.config.chart.sparkline.enabled?0:e.config.chart.dropShadow.blur),this.maxRadius<5)return r;if(this._roots=this._buildHierarchy(),!this._roots.length)return r;this._roots.forEach(t=>this._fillValues(t)),this._validateStrict(),this._nodesAll=[];const n=e.globals.colors||[];this._roots.forEach((t,e)=>{this._colorPass(t,t.color||n[e%n.length]||"#008FFB")}),this.total=this._roots.reduce((t,e)=>t+Math.max(0,e.value),0)||1,this._ringsG=i.group({class:"apexcharts-sunburst-rings"}),this._labelsG=i.group({class:"apexcharts-sunburst-labels"}),r.add(this._ringsG),r.add(this._labelsG),this._focus=null,this._relayout(this._focus);const l=e.config.chart.animations;let c="none";return l.enabled&&(e.globals.dataChanged?l.dynamicAnimation.enabled&&(c="update"):e.globals.resized||(c="intro")),this._applyLayout(c),this._renderBreadcrumb(),r}_buildHierarchy(){return function(t,e={}){const s=t.config.series,i=s&&s[0],r=i&&Array.isArray(i.data)?i.data:s;return Array.isArray(r)?r.map((s,i)=>h(t,s,i,null,"",null,e)):[]}(this.w)}_fillValues(t){u(t)}_validateStrict(){if("strict"!==this.cfg.partition)return;let t=!1;const e=s=>{if(s.children&&s.children.length){const i=s.children.reduce((t,e)=>t+Math.max(0,e.value||0),0);!t&&null!=s.value&&Math.abs(i-s.value)>.5&&(t=!0),s.children.forEach(e)}};this._roots.forEach(e)}_colorPass(t,e){t._color=t.color||e,this._nodesAll.push(t),t.children&&t.children.forEach(e=>this._colorPass(e,e.color||this._lighten(t._color,this.cfg.tint)))}_relayout(t){if(this._nodesAll.forEach(t=>{t._show=!1}),this._focusMaxDepth=0,t)this._placeVis(t,0,this.startAngle,this.endAngle,t._parent);else{const t=this._roots.reduce((t,e)=>t+Math.max(0,e.value),0)||1;let e=this.startAngle;this._roots.forEach(s=>{const i=(this.endAngle-this.startAngle)*Math.max(0,s.value)/t;this._placeVis(s,0,e,e+i,null),e+=i})}const e=this._parseSize(this.cfg.innerSize,this.maxRadius),s=this._focusMaxDepth+1,i=(this.maxRadius-e)/s,r=s>1?1:0;this._innerR=t=>e+t*i+(t>0?r/2:0),this._outerR=t=>e+(t+1)*i-r/2,this._nodesAll.forEach(t=>{t._show&&(t._iR=this._innerR(t._vDepth),t._oR=t._leaf&&"extend"===this.cfg.leaf&&t._vDepth<this._focusMaxDepth?this.maxRadius:this._outerR(t._vDepth))})}_placeVis(t,e,s,i,r){if(t._show=!0,t._vDepth=e,t._a0=s,t._a1=i,t._parent=r,t._leaf=!(t.children&&t.children.length),e>this._focusMaxDepth&&(this._focusMaxDepth=e),!t._leaf){const r=t.children.reduce((t,e)=>t+Math.max(0,e.value),0)||1;let a=s;t.children.forEach(o=>{const n=(i-s)*Math.max(0,o.value)/r;this._placeVis(o,e+1,a,a+n,t),a+=n})}}_applyLayout(t){var e;const s=this.w.config.chart.animations,i=s.enabled?"none"===t?0:"update"===t?s.dynamicAnimation.speed||350:s.speed||500:0,r=++this._zoomGen,a=null==(e=this.ctx)?void 0:e.morphTypeChange,o=!!a&&"function"==typeof a.isActive&&a.isActive()&&"function"==typeof a.getInitialPathAt,n=o?a.getSpeed():0;this._morphLeafIndex=0;const l="update"===t?this.ctx._sunburstPrevGeoms:null;this._nodesAll.forEach(e=>{if(e._show){const s={a0:e._a0,a1:e._a1,iR:e._iR,oR:e._oR};e._el||(e._el=this._createArcEl(e));const a=o?this._morphSourceFor(e):null;if(a&&n>0)this._morphArcFrom(e,a,s,n,r);else if(("intro"===t||o)&&i>0)this._sweepArc(e,s,o?n:i,r);else{let t,a=!1;if(e._cur)t=e._cur;else if(l&&l.get(e._key))t=l.get(e._key);else{const e=(s.a0+s.a1)/2;t={a0:e,a1:e,iR:s.iR,oR:s.iR},a=!0}this._animateArc(e,t,s,i,!1,a,r)}}else if(e._el&&e._cur){const t=(e._cur.a0+e._cur.a1)/2,s={a0:t,a1:t,iR:e._cur.iR,oR:e._cur.iR};this._animateArc(e,e._cur,s,i,!0,!1,r)}});const c=new Map;this._nodesAll.forEach(t=>{t._show&&c.set(t._key,{a0:t._a0,a1:t._a1,iR:t._iR,oR:t._oR})}),this.ctx._sunburstPrevGeoms=c,this._renderLabels(i)}_morphSourceFor(t){const e=this.ctx,s=e&&e.morphTypeChange;return s?"function"==typeof s.hasKeyedMarks&&s.hasKeyedMarks()&&"function"==typeof s.getInitialPathForKey?s.getInitialPathForKey(d(t._key)):t.children&&t.children.length?null:s.getInitialPathAt(this._morphLeafIndex++):null}_morphArcFrom(t,e,s,i,r){const a=t._el,o=this._arcPath(s.iR,s.oR,s.a0,s.a1,this.cfg.borderRadius);a.node.style.display="",a.attr({d:e,opacity:1}),t._cur=s,this._zoomGen===r&&new c(this.w,this.ctx).morphSVG(a,0,null,t._color,e,o,i,0)}_sweepArc(t,e,s,i){const r=t._el,a=this.cfg.borderRadius,o=this.startAngle,n=this.endAngle;r.node.style.display="",r.attr({d:"",opacity:1}),r.animate(s).during(s=>{if(this._zoomGen!==i)return;const l=o+(n-o)*s;if(l<=e.a0+.01)return void r.attr({d:""});const c=Math.min(e.a1,l);r.attr({d:this._arcPath(e.iR,e.oR,e.a0,c,a)}),t._cur={a0:e.a0,a1:c,iR:e.iR,oR:e.oR}}).after(()=>{this._zoomGen===i&&(t._cur=e)})}_createArcEl(t){const e=this._graphics.drawPath({d:"",fill:t._color,stroke:this.strokeColor,strokeWidth:this.strokeWidth,fillOpacity:1,classes:"apexcharts-sunburst-arc"}),s=e.node;return s.setAttribute("data:name",t.name),s.setAttribute("data:value",String(t.value)),s.setAttribute("data:key",d(t._key)),s.setAttribute("data:leaf",String(!(t.children&&t.children.length))),this._attachTooltip(s,t),r.isBrowser()&&(s.addEventListener("click",()=>this._zoomTo(t)),s.style.cursor="pointer"),this._ringsG.add(e),e}_animateArc(t,e,s,i,r,a,o){const n=t._el,l=this.cfg.borderRadius;if(n.attr({fill:t._color}),0===i)return n.attr({d:this._arcPath(s.iR,s.oR,s.a0,s.a1,l),opacity:r?0:1}),n.node.style.display=r?"none":"",void(t._cur=r?null:s);n.node.style.display="";const c=r?Number(n.attr("opacity"))||1:a?0:1,h=r?0:1;n.attr({opacity:c}),n.animate(i).during(i=>{if(this._zoomGen!==o)return;const r=g(e.a0,s.a0,i),a=g(e.a1,s.a1,i),u=g(e.iR,s.iR,i),d=g(e.oR,s.oR,i);n.attr({d:this._arcPath(u,d,r,a,l),opacity:g(c,h,i)}),t._cur={a0:r,a1:a,iR:u,oR:d}}).after(()=>{this._zoomGen===o&&(r?(n.node.style.display="none",t._cur=null):t._cur=s)})}_renderLabels(t){const e=this._labelsG;for(;e.node.firstChild;)e.node.removeChild(e.node.firstChild);this.cfg.dataLabels.show&&(this._nodesAll.forEach(t=>{t._show&&(t._a1-t._a0<this.cfg.dataLabels.minAngleToShow||this._renderCurvedLabel(t))}),t>0?(e.attr({opacity:0}),e.animate(250,t).attr({opacity:1})):e.attr({opacity:1}))}_renderCurvedLabel(t){if(!r.isBrowser())return;const e=this.cfg.dataLabels.style,s=this.w,a=(t._iR+t._oR)/2,o=(t._a0+t._a1)/2,n=o>90&&o<270,l=Math.min(a>0?4/a*p:0,(t._a1-t._a0)/2),c=n?t._a1-l:t._a0+l,h=n?t._a0+l:t._a1-l,u=this._ptAt(a,c),d=this._ptAt(a,h),_=Math.abs(h-c)>180?1:0,m=n?0:1,g=`apx-sb-lbl-${s.globals.cuid}-${this._lblSeq++}`,b=i.createElementNS(f,"path");b.setAttribute("id",g),b.setAttribute("d",`M ${u.x} ${u.y} A ${a} ${a} 0 ${_} ${m} ${d.x} ${d.y}`),b.setAttribute("fill","none"),b.setAttribute("stroke","none");const y=e.colors,x=(Array.isArray(y)?y[0]:y)||"#fff",A=i.createElementNS(f,"text");A.setAttribute("font-size",e.fontSize||"12px"),e.fontFamily&&A.setAttribute("font-family",e.fontFamily),A.setAttribute("font-weight",String(e.fontWeight||400)),A.setAttribute("fill",x),A.setAttribute("dominant-baseline","central"),A.style.pointerEvents="none";const v=i.createElementNS(f,"textPath");v.setAttribute("href","#"+g),v.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","#"+g),v.setAttribute("startOffset","50%"),v.setAttribute("text-anchor","middle"),v.textContent=this._truncate(t.name,a,t._a1-t._a0,e.fontSize),A.appendChild(v),this._labelsG.node.appendChild(b),this._labelsG.node.appendChild(A)}_truncate(t,e,s,i){const r=e*s*_-8,a=.58*(parseFloat(i)||12),o=Math.floor(r/a);return o>=t.length?t:o<=1?"":t.slice(0,Math.max(1,o-1))+"\u2026"}_zoomTo(t){if(!1===this.cfg.zoomOnClick)return;const e=t===this._focus?t._parent||null:t;e!==this._focus&&(this._focus=!e||e.children&&e.children.length?e:e._parent||null,this._relayout(this._focus),this._applyLayout("zoom"),this._renderBreadcrumb())}_focusChain(){const t=[];let e=this._focus;for(;e;)t.unshift(e),e=e._parent;return t}_renderBreadcrumb(){if(!r.isBrowser())return;const t=this.w.dom.elWrap;if(!t)return;const e=t.querySelector(".apexcharts-breadcrumb");if(e&&e.parentNode&&e.parentNode.removeChild(e),!this._focus)return;const s=i.createElementNS(m,"nav");s.setAttribute("class","apexcharts-breadcrumb"),s.setAttribute("aria-label","Sunburst breadcrumb"),s.style.position="absolute",s.style.top="0px",s.style.left="0px";const a=[{name:"All",node:null}].concat(this._focusChain().map(t=>({name:t.name,node:t})));a.forEach((t,e)=>{if(e>0){const t=i.createElementNS(m,"span");t.setAttribute("class","apexcharts-breadcrumb-separator"),t.textContent=" / ",s.appendChild(t)}if(e===a.length-1){const e=i.createElementNS(m,"span");e.setAttribute("class","apexcharts-breadcrumb-item apexcharts-breadcrumb-current"),e.textContent=t.name,s.appendChild(e)}else{const r=i.createElementNS(m,"button");if(r.setAttribute("type","button"),r.setAttribute("class","apexcharts-breadcrumb-item"),0===e){const t=i.createElementNS(m,"span");t.setAttribute("class","apexcharts-breadcrumb-arrow"),t.textContent="\u2190",r.appendChild(t)}const a=i.createElementNS(m,"span");a.setAttribute("class","apexcharts-breadcrumb-label"),a.textContent=t.name,r.appendChild(a),r.addEventListener("click",()=>{this._focus=t.node,this._relayout(this._focus),this._applyLayout("zoom"),this._renderBreadcrumb()}),s.appendChild(r)}}),t.appendChild(s),this._avoidChromeOverlap(s)}_avoidChromeOverlap(t){!function(t,e){const s=[".apexcharts-title-text",".apexcharts-subtitle-text"].map(e=>t.dom.baseEl.querySelector(e)).filter(t=>null!==t);if(!s.length)return;const i=t.dom.elWrap.getBoundingClientRect().top;for(let t=0;t<s.length+1;t++){const t=e.getBoundingClientRect(),r=s.find(e=>{const s=e.getBoundingClientRect();return t.left<s.right&&t.right>s.left&&t.top<s.bottom&&t.bottom>s.top});if(!r)break;e.style.top=r.getBoundingClientRect().bottom-i+4+"px"}}(this.w,t)}_ptAt(t,e){return{x:this.centerX+t*Math.cos((e-90)*_),y:this.centerY+t*Math.sin((e-90)*_)}}_arcPath(t,e,s,i,r){if(e<=t+.01)return"";let a=i-s;const c=this.cfg.spacing;if(c>0&&a>0&&e>0){const t=c/e*p,r=Math.min(t/2,Math.max(0,a/2-.25));a=(i-=r)-(s+=r)}if(a<=0)return"";const h=a*_,u=this.centerX,d=this.centerY;let f=r;return f=Math.min(f,h*t/2,h*e/2,(e-t)/2),f>.5?function({cx:t,cy:e,rIn:s,rOut:i,a0:r,a1:a,r:c,spanDeg:h}){const u=(s,i)=>n(t,e,s,i),d=c/i*o,_=c/s*o,p=u(i,r+d),f=u(i,a-d),m=h-2*d>180?1:0,g=u(i,a),b=u(i-c,a),y=u(i,r),x=u(i-c,r),A=u(s,a-_),v=u(s,r+_),w=h-2*_>180?1:0,R=u(s,a),M=u(s+c,a),S=u(s,r),E=u(s+c,r);return["M",l(p),"A",i,i,0,m,1,l(f),"Q",l(g),l(b),"L",l(M),"Q",l(R),l(A),"A",s,s,0,w,0,l(v),"Q",l(S),l(E),"L",l(x),"Q",l(y),l(p),"Z"].join(" ")}({cx:u,cy:d,rIn:t,rOut:e,a0:s,a1:i,r:f,spanDeg:a}):function({cx:t,cy:e,rIn:s,rOut:i,a0:r,a1:a,spanDeg:o}){const c=(s,i)=>n(t,e,s,i),h=o>180?1:0,u=c(i,r),d=c(i,a),_=c(s,a),p=c(s,r);return["M",l(u),"A",i,i,0,h,1,l(d),"L",l(_),"A",s,s,0,h,0,l(p),"Z"].join(" ")}({cx:u,cy:d,rIn:t,rOut:e,a0:s,a1:i,spanDeg:a})}_tip(){return this._tooltipEl||(this._tooltipEl=this.w.dom.baseEl.querySelector(".apexcharts-tooltip")),this._tooltipEl}_attachTooltip(t,e){this.w.config.tooltip.enabled&&r.isBrowser()&&(t.addEventListener("mouseenter",t=>this._showTooltip(t,e)),t.addEventListener("mousemove",t=>this._positionTooltip(t)),t.addEventListener("mouseleave",()=>this._hideTooltip()))}_showTooltip(t,e){const s=this._tip();if(!s)return;const i=this.w,r=(e.value/this.total*100).toFixed(1),a=e._parent?e._parent.value:this.total,o=a>0?(e.value/a*100).toFixed(1):r,n=i.config.tooltip.fillSeriesColor?`background-color:${e._color};`:"";s.innerHTML=`<div class="apexcharts-tooltip-series-group apexcharts-active" style="display:flex;${n}"><span class="apexcharts-tooltip-marker" style="background-color:${e._color}"></span><div class="apexcharts-tooltip-text"><div class="apexcharts-tooltip-y-group"><span class="apexcharts-tooltip-text-y-label">${e.name}: </span><span class="apexcharts-tooltip-text-y-value">${e.value} (${o}% of parent, ${r}% of total)</span></div></div></div>`,s.classList.add("apexcharts-active"),s.style.opacity="1",this._positionTooltip(t)}_positionTooltip(t){const e=this._tip();if(!e)return;const s=this.w.dom.elWrap.getBoundingClientRect(),i=e.offsetWidth,r=e.offsetHeight;let a=t.clientX-s.left+12;a+i>s.width&&(a=t.clientX-s.left-i-12),a=Math.max(0,Math.min(a,s.width-i));let o=t.clientY-s.top+12;o+r>s.height&&(o=t.clientY-s.top-r-12),o=Math.max(0,Math.min(o,s.height-r)),e.style.left=a+"px",e.style.top=o+"px"}_hideTooltip(){const t=this._tip();t&&(t.classList.remove("apexcharts-active"),t.style.opacity="0")}_parseSize(t,e){if("number"==typeof t)return t;const s=String(t).trim();if(s.endsWith("%"))return parseFloat(s)/100*e;const i=parseFloat(s);return isNaN(i)?.15*e:i}_lighten(t,e){if("string"!=typeof t||"#"!==t[0])return t;let s=t.slice(1);if(3===s.length&&(s=s.split("").map(t=>t+t).join("")),6!==s.length)return t;const i=parseInt(s,16);if(isNaN(i))return t;let r=i>>16&255,a=i>>8&255,o=255&i;return r=Math.round(r+(255-r)*e),a=Math.round(a+(255-a)*e),o=Math.round(o+(255-o)*e),"#"+((1<<24)+(r<<16)+(a<<8)+o).toString(16).slice(1)}}}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>e.default});