UNPKG

apexcharts

Version:

A JavaScript Chart Library

6 lines (5 loc) 31.7 kB
/*! * ApexCharts v7.0.0 * (c) 2018-2026 ApexCharts */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ApexTreemap={})}(this,function(e){"use strict";var t=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,l=(e,t)=>{for(var r in t||(t={}))a.call(t,r)&&s(e,r,t[r]);if(n)for(var r of n(t))i.call(t,r)&&s(e,r,t[r]);return e},h=(e,t)=>r(e,o(t));const c=globalThis.ApexCharts;function d(e,t){let r=0;for(let t=0;t<e.length;t++)r+=e[t];const o=t/r,n=new Array(e.length);for(let t=0;t<e.length;t++)n[t]=e[t]*o;return n}function u(e,t,r,o){const n=o*o,a=r*r;return Math.max(n*t/a,a/(n*e))}function p(e,t,r,o,n,a){if(0===e)return!0;return u(t,r,o,a)>=u(Math.min(t,n),Math.max(r,n),o+n,a)}function f(e,t,r,o,n,a,i,s){if(i>=s){const i=o/s;let l=a;for(let o=0;o<r;o++){const r=t[o]/i;e.push([n,l,n+i,l+r]),l+=r}}else{const s=o/i;let l=n;for(let o=0;o<r;o++){const r=t[o]/s;e.push([l,a,l+r,a+s]),l+=r}}}function g(e,t,r,o,n){const a=[],i=e.length;if(0===i)return a;const s=new Array(i);let l=0,h=0,c=1/0,d=-1/0,u=0;for(;u<i;){const i=Math.min(o,n),g=e[u];if(p(l,c,d,h,g,i))s[l]=g,l++,h+=g,g<c&&(c=g),g>d&&(d=g),u++;else{if(f(a,s,l,h,t,r,o,n),o>=n){const e=h/n;t+=e,o-=e}else{const e=h/o;r+=e,n-=e}l=0,h=0,c=1/0,d=-1/0}}return l>0&&f(a,s,l,h,t,r,o,n),a}function m(e){const t=e.children;if(t&&t.length){let r=0;for(let e=0;e<t.length;e++)r+=m(t[e]);return e._area=r,r}const r=Number(e.value),o=isNaN(r)?0:Math.abs(r);return e._area=o,o}function b(e,t,r,o,n,a,i,s){const l=e.length;if(0===l||o<=0||n<=0)return;const h=new Array(l);let c=0;for(let t=0;t<l;t++)h[t]=e[t]._area,c+=h[t];if(c<=0)return;const u=g(d(h,o*n),t,r,o,n);for(let t=0;t<l;t++){const r=e[t],o=u[t];if(!o)continue;r.rect=o,r.depth=a;const n=r.children;if(!n||!n.length)continue;const l=o[2]-o[0],h=o[3]-o[1];let c=Math.max(0,i(r,a,l,h)||0);(2*c>=l||2*c>=h)&&(c=0);let d=Math.max(0,s(r,a,l,h)||0);d>0&&h-2*c-d<d&&(d=0),r.headerHeight=d,b(n,o[0]+c,o[1]+d+c,l-2*c,h-d-2*c,a+1,i,s)}}const _={generate:function(e,t,r){const o=e.length,n=new Array(o);for(let t=0;t<o;t++){let r=0;const o=e[t];for(let e=0;e<o.length;e++)r+=o[e];n[t]=r}const a=g(d(n,t*r),0,0,t,r),i=new Array(o);for(let t=0;t<o;t++){const r=a[t],o=r[0],n=r[1],s=r[2]-o,l=r[3]-n;i[t]=g(d(e[t],s*l),o,n,s,l)}return i},generateNested:function(e,t,r,o={}){if(!Array.isArray(e)||0===e.length)return e||[];const n=o.padding||(()=>0),a=o.header||(()=>0);for(let t=0;t<e.length;t++)m(e[t]);return b(e,0,0,t,r,0,n,a),e}},x=globalThis.ApexCharts.__internals.__apex_Graphics,y=globalThis.ApexCharts.__internals,v=y.__apex_Animations;y.__apex_Animations_computeStagger,y.__apex_Animations_applyAnimationPolicy,y.__apex_Animations_prefersReducedMotion,y.__apex_Animations_applyProgressiveReveal;const w=globalThis.ApexCharts.__internals.__apex_Fill,A=globalThis.ApexCharts.__internals.__apex_Utils,C=globalThis.ApexCharts.__internals.__apex_DataLabels,S=(e,t,r,o)=>{if("function"!=typeof e)return e;const n=e({series:t.seriesData.series,seriesIndex:r,dataPointIndex:o,w:t});return Number.isFinite(n)?n:0};class M{constructor(e,t){this.ctx=t,this.w=e}checkColorRange(){const e=this.w;let t=!1;const r=e.config.plotOptions[e.config.chart.type];return r.colorScale.ranges.length>0&&r.colorScale.ranges.map(e=>{e.from<=0&&(t=!0)}),t}getShadeColor(e,t,r,o){const n=this.w;let a=1;const i=n.config.plotOptions[e].shadeIntensity,s=this.determineColor(e,t,r);n.globals.hasNegs||o?a=n.config.plotOptions[e].reverseNegativeShade?s.percent<0?s.percent/100*(1.25*i):(1-s.percent/100)*(1.25*i):s.percent<=0?1-(1+s.percent/100)*i:(1-s.percent/100)*i:(a=1-s.percent/100,"treemap"===e&&(a=(1-s.percent/100)*(1.25*i)));let l=s.color;const h=new A;if(n.config.plotOptions[e].enableShades)if("dark"===this.w.config.theme.mode){const e=h.shadeColor(-1*a,s.color);l=A.hexToRgba(A.isColorHex(e)?e:A.rgb2hex(e),n.config.fill.opacity)}else{const e=h.shadeColor(a,s.color);l=A.hexToRgba(A.isColorHex(e)?e:A.rgb2hex(e),n.config.fill.opacity)}return{color:l,colorProps:s}}determineColor(e,t,r){const o=this.w,n=o.seriesData.series[t][r],a=o.config.plotOptions[e];let i=a.colorScale.inverse?r:t;a.distributed&&"treemap"===o.config.chart.type&&(i=r);let s,l,h=o.globals.colors[i],c=null;if(a.distributed||"heatmap"!==e){const e=o.seriesData.series[t];s=e.length?e[0]:0,l=s;for(let t=1;t<e.length;t++)e[t]<s&&(s=e[t]),e[t]>l&&(l=e[t])}else s=o.globals.minY,l=o.globals.maxY;const d=a.colorScale.min,u=a.colorScale.max;void 0!==d&&void 0!==u&&u>d?(s=d,l=u):void 0!==d&&(s=d<o.globals.minY?d:o.globals.minY,l=u>o.globals.maxY?u:o.globals.maxY);const p=Math.abs(l)+Math.abs(s),f=Math.min(Math.max(n,s),l);let g=0===p?0:100*f/p;if(a.colorScale.ranges.length>0){a.colorScale.ranges.map(e=>{if(n>=e.from&&n<=e.to){h=e.color,c=e.foreColor?e.foreColor:null,s=e.from,l=e.to;const t=Math.abs(l)+Math.abs(s);g=0===t?0:100*n/t}})}return{color:h,foreColor:c,percent:g}}calculateDataLabels({text:e,x:t,y:r,i:o,j:n,colorProps:a,fontSize:i}){const s=this.w,l=s.config.dataLabels,h=new x(this.w),c=new C(this.w,this.ctx);let d=null;if(l.enabled){d=h.group({class:"apexcharts-data-labels"});const u=S(l.offsetX,s,o,n),p=S(l.offsetY,s,o,n),f=t+u,g=r+parseFloat(l.style.fontSize)/3+p;c.plotDataLabelsText({x:f,y:g,text:e,i:o,j:n,color:a.foreColor,parent:d,fontSize:i,dataLabelsConfig:l})}return d}}const L=globalThis.ApexCharts.__internals.__apex_Filters,N=globalThis.ApexCharts.__internals.__apex_Environment_Environment;function P(e,t,r,o,n,a=null,i={}){var s,l,h;const c=t&&"object"==typeof t,d=c&&null!=(l=null!=(s=t.x)?s:t.name)?l:"",u=Number(c?null!=(h=t.y)?h:t.value:t),p={name:String(d),value:isNaN(u)?null:u,color:c&&t.color?t.color:void 0,_key:`${n}/${r}:${d}`};if(o&&!p.color&&(p.color=o[r%o.length]),i.keepDatum&&(p._datum=t),c&&Array.isArray(t.children)&&t.children.length)p.children=t.children.map((t,r)=>P(e,t,r,null,p._key,a,i));else if(c&&null!=t.drilldown&&!1!==i.expandDrilldown){const r=a||new Set;if(!r.has(t.drilldown)){const o=function(e,t){const r=e.config.drilldown;return(r&&Array.isArray(r.series)?r.series:[]).find(e=>e&&e.id===t)}(e,t.drilldown);if(o&&Array.isArray(o.data)&&o.data.length){const n=new Set(r);n.add(t.drilldown);const a=Array.isArray(o.colors)?o.colors:null;p.children=o.data.map((t,r)=>P(e,t,r,a,p._key,n,i))}}}return p}function k(e){e.children&&e.children.length&&(e.children.forEach(e=>k(e)),(null==e.value||isNaN(e.value))&&(e.value=e.children.reduce((e,t)=>e+Math.max(0,t.value||0),0))),(null==e.value||isNaN(e.value))&&(e.value=0)}function E(e){if("string"!=typeof e)return"";const t=e.indexOf("/");return-1===t?"":e.slice(t)}function T(e){const t=e.globals.treemapRoots;if(t&&t.length)return{roots:t,maxDepth:e.globals.treemapMaxDepth||1,nested:!0};const r=function(e,t,r={}){const o=t||e.config.series;return Array.isArray(o)?o.map((t,o)=>{var n,a;const i=t&&Array.isArray(t.data)?t.data:[],s=`${o}:${null!=(n=null==t?void 0:t.name)?n:""}`;return{name:String(null!=(a=null==t?void 0:t.name)?a:""),value:null,color:(null==t?void 0:t.color)||void 0,_key:s,_seriesIndex:o,children:i.map((t,o)=>P(e,t,o,null,s,null,r))}}):[]}(e,e.config.series,{keepDatum:!0,expandDrilldown:!1});r.forEach(k);const{maxDepth:o}=function(e){const t=[];let r=0;return e.forEach((e,o)=>{const n=[],a=(e,t,i)=>{e._parent=i,e._depth=t,e._si=o,e._leaf=!(e.children&&e.children.length),t>r&&(r=t),e._leaf?(e._di=n.length,n.push(e)):(e._di=-1,e.children.forEach(r=>a(r,t+1,e)))};a(e,0,null),t.push(n)}),{leaves:t,maxDepth:r}}(r);return{roots:r,maxDepth:o,nested:!1}}const F=["#cf4d3f","#8f9499","#26a75b"],O=(e,t,r)=>e+(t-e)*r;function $(e){return Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")}function z(e,t,r){const o=A.parseHex(W(e)),n=A.parseHex(W(t));return o&&n?"#"+$(O(o[0],n[0],r))+$(O(o[1],n[1],r))+$(O(o[2],n[2],r)):e}function W(e){if("string"!=typeof e)return"#000000";if(A.isColorHex(e))return e;return A.rgb2hex(e)||"#000000"}function R(e,t,r,o){var n,a,i;if(!t||"object"!=typeof t)return null;const s=null==(i=null==(a=null==(n=e.config.plotOptions)?void 0:n.treemap)?void 0:a.colorScale)?void 0:i.colorValue;let l;if(l="function"==typeof s?s(t,{seriesIndex:r,dataPointIndex:o,w:e}):"string"==typeof s?t[s]:t.colorValue,null==l)return null;const h=Number(l);return Number.isFinite(h)?h:null}function B(e){var t,r,o;const n=null==(o=null==(r=null==(t=e.config)?void 0:t.plotOptions)?void 0:r.treemap)?void 0:o.colorScale,a=n&&n.gradient;if(!a)return null;if(!1===a.enabled)return null;const i=e.config.series||[];let s=1/0,l=-1/0,h=!1;for(let t=0;t<i.length;t++){const r=i[t]&&i[t].data;if(Array.isArray(r))for(let o=0;o<r.length;o++){const n=R(e,r[o],t,o);null!=n&&(h=!0,n<s&&(s=n),n>l&&(l=n))}}if(!h&&!0!==a.enabled)return null;Number.isFinite(s)||(s=0,l=0);let c=Number.isFinite(Number(a.min))?Number(a.min):s,d=Number.isFinite(Number(a.max))?Number(a.max):l,u=null;if(null===a.midpoint?u=null:Number.isFinite(Number(a.midpoint))?u=Number(a.midpoint):c<0&&d>0&&(u=0),null!=u&&!1!==a.symmetric&&!Number.isFinite(Number(a.min))&&!Number.isFinite(Number(a.max))){const e=Math.max(Math.abs(c-u),Math.abs(d-u));c=u-e,d=u+e}d===c&&(c-=.5,d+=.5);const p=function(e,t,r,o){if(Array.isArray(e.stops)&&e.stops.length>=2)return e.stops.filter(e=>e&&Number.isFinite(Number(e.value))).map(e=>({value:Number(e.value),color:W(e.color)})).sort((e,t)=>e.value-t.value);const n=(Array.isArray(e.colors)&&e.colors.length>=2?e.colors:F).map(W),a=n.length;if(null!=o&&a>=3){const e=Math.floor((a-1)/2),i=[];for(let r=0;r<=e;r++)i.push({value:O(t,o,r/e),color:n[r]});for(let t=e+1;t<a;t++)i.push({value:O(o,r,(t-e)/(a-1-e)),color:n[t]});return i}return n.map((e,o)=>({value:O(t,r,o/(a-1)),color:e}))}(a,c,d,u);if(p.length<2)return null;const f=d-c,g=p.map(e=>({percent:0===f?0:(e.value-c)/f,color:e.color}));return{min:c,max:d,midpoint:u,stops:p,at:e=>{if(!Number.isFinite(e))return p[Math.floor(p.length/2)].color;if(e<=p[0].value)return p[0].color;const t=p[p.length-1];if(e>=t.value)return t.color;for(let t=1;t<p.length;t++){const r=p[t];if(e<=r.value){const o=p[t-1],n=r.value-o.value,a=0===n?0:(e-o.value)/n;return z(o.color,r.color,a)}}return t.color},legendStops:g}}function I(e){const t=W(e);return A.getContrastRatio(t,"#ffffff")>=A.getContrastRatio(t,"#000000")?"#ffffff":"#000000"}const D=globalThis.ApexCharts.__internals.__apex_BrowserAPIs_BrowserAPIs,j="http://www.w3.org/1999/xhtml";function Y(e,t){const r=e.config.drilldown&&e.config.drilldown.breadcrumb||{};return l(l({show:!0,position:"top-left",separator:" / ",rootLabel:"All",offsetX:0,offsetY:0,formatter:void 0},r),t||{})}function H(e){const t=e.dom.elWrap;if(!t)return;const r=t.querySelector(".apexcharts-breadcrumb");r&&r.parentNode&&r.parentNode.removeChild(r)}c.use({treemap:class{constructor(e,t){this.ctx=t,this.w=e,this.strokeWidth=this.w.config.stroke.width,this.helpers=new M(e,t),this.dynamicAnim=this.w.config.chart.animations.dynamicAnimation,this.labels=[],this.roots=[],this.drawn=[],this.nested=!1,this.showParents=!1,this.scale=null,this._levelCache=null,this._total=null,this._avgLabelSize=null,this._tooltipEl=null,this._tipOwned=!1,this._morphLeafIndex=0}draw(e){var t;const r=this.w,o=new x(this.w,this.ctx),n=new w(this.w),a=o.group({class:"apexcharts-treemap"});if(r.globals.noData)return a;e.forEach(e=>{e.map(e=>Math.abs(e))}),this.negRange=this.helpers.checkColorRange(),r.config.series.forEach((e,t)=>{e.data.forEach(e=>{Array.isArray(this.labels[t])||(this.labels[t]=[]),this.labels[t].push(e.x)})});const i=T(r);this.nested=i.nested,this.roots=i.roots,this.scale=B(r);const s=1===i.roots.length?i.roots[0].children||[]:i.roots;this.drawn=s;const l=r.config.plotOptions.treemap.parents;this.showParents=!0===l.show||!1!==l.show&&this.nested;const h=this._resolveFocus(s),c=h?[h]:s;_.generateNested(c,r.layout.gridWidth,r.layout.gridHeight,{padding:(e,t,r,o)=>this.showParents?this._levelPadding(t,r,o):0,header:(e,t,r,o)=>this.showParents?this._levelHeader(e,t,r,o):0});const d=null==(t=this.ctx)?void 0:t.morphTypeChange,u=!!d&&"function"==typeof d.isActive&&d.isActive()&&"function"==typeof d.getInitialPathAt;this._morphLeafIndex=0;const p=this._leavesBySeries(c,r.config.series.length),f=this.showParents?this._parentsBySeries(c,r.config.series.length):[];return p.forEach((t,i)=>{var s;const l=o.group({class:"apexcharts-series apexcharts-treemap-series",seriesName:A.escapeString(r.seriesData.seriesNames[i]),rel:i+1,"data:realIndex":i});if(o.setupEventDelegation(l,".apexcharts-treemap-rect"),r.config.chart.dropShadow.enabled){const e=r.config.chart.dropShadow;new L(this.w).dropShadow(a,e,i)}const h=o.group({class:"apexcharts-data-labels"}),c={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0};this.showParents&&(f[i]||[]).forEach(e=>{this._drawParent(l,e,i)});const d=r.config.chart.animations,p=d.animateGradually,g=p&&!1!==p.enabled,m=new Array(t.length).fill(0);if(g){const e=t.length||1,r=Math.min(p.delay||0,.5*d.speed/e);t.map((e,t)=>{return{j:t,area:e.rect?(r=e.rect,(r[2]-r[0])*(r[3]-r[1])):0};var r}).sort((e,t)=>t.area-e.area).forEach((e,t)=>{m[e.j]=t*r})}t.forEach((t,a)=>{const s=t.rect;if(!s)return;const h=t._di,d=s[0],p=s[1],f=s[2],g=s[3];c.xMin=Math.min(c.xMin,d),c.yMin=Math.min(c.yMin,p),c.xMax=Math.max(c.xMax,f),c.yMax=Math.max(c.yMax,g);const b=this._leafColor(i,h),_=b.color,x=n.fillPath({color:_,seriesNumber:i,dataPointIndex:h}),y=u?this._morphSourceForLeaf(t):null,v=y?o.drawPath({d:this._tilePath(d,p,f,g),fill:"#fff",stroke:r.config.plotOptions.treemap.useFillColorAsStroke?_:r.globals.stroke.colors[i],strokeWidth:this.strokeWidth,fillOpacity:1}):o.drawRect(d,p,f-d,g-p,r.config.plotOptions.treemap.borderRadius,"#fff",1,this.strokeWidth,r.config.plotOptions.treemap.useFillColorAsStroke?_:r.globals.stroke.colors[i]);v.attr({cx:d,cy:p,index:i,i:i,j:h,width:f-d,height:g-p,fill:x}),v.node.classList.add("apexcharts-treemap-rect"),v.node.setAttribute("data:key",E(t._key));let w={x:d+(f-d)/2,y:p+(g-p)/2,width:0,height:0};const A={x:d,y:p,width:f-d,height:g-p};if(y)this._morphTile(v,y,this._tilePath(d,p,f,g),this.ctx.morphTypeChange.getSpeed(),i,h);else if(r.config.chart.animations.enabled&&!r.globals.dataChanged){let e=1;r.globals.resized||(e=r.config.chart.animations.speed),this.animateTreemap(v,w,A,e,m[a]||0)}if(r.globals.dataChanged){let e=1;this.dynamicAnim.enabled&&r.globals.shouldAnimate&&(e=this.dynamicAnim.speed,r.globals.previousPaths[i]&&r.globals.previousPaths[i][h]&&r.globals.previousPaths[i][h].rect&&(w=r.globals.previousPaths[i][h].rect),this.animateTreemap(v,w,A,e))}let C=this.getFontSize(s);"truncate"===r.config.plotOptions.treemap.dataLabels.format&&(C=parseInt(String(r.config.dataLabels.style.fontSize),10));let S=null;if(r.config.dataLabels.enabled&&this._labelCanShow(C,f-d,g-p)){let t=r.config.dataLabels.formatter(this.labels[i][h],{value:r.seriesData.series[i][h],seriesIndex:i,dataPointIndex:h,w:r});"truncate"===r.config.plotOptions.treemap.dataLabels.format&&(t=this.truncateLabels(String(t),C,d,p,f,g)),r.seriesData.series[i][h]&&(S=this.helpers.calculateDataLabels({text:t,x:(d+f)/2,y:(p+g)/2+this.strokeWidth/2+C/3,i:i,j:h,colorProps:b,fontSize:C,series:e})),r.config.dataLabels.enabled&&S&&this.rotateToFitLabel(S,C,t,d,p,f,g)}l.add(v),null!==S&&l.add(S)});const b=r.config.plotOptions.treemap.seriesTitle;if(!this.showParents&&r.config.series.length>1&&b&&b.show){const e=r.config.series[i].name||"";if(e&&c.xMin<1/0&&c.yMin<1/0){const{offsetX:t,offsetY:n,borderColor:a,borderWidth:i,borderRadius:h,style:d}=b,u=d.color||r.config.chart.foreColor,p={left:d.padding.left,right:d.padding.right,top:d.padding.top,bottom:d.padding.bottom},f=o.getTextRects(e,d.fontSize,d.fontFamily),g=f.width+p.left+p.right,m=f.height+p.top+p.bottom,_=c.xMin+(t||0),x=c.yMin+(n||0),y=o.drawRect(_,x,g,m,h,d.background,1,i,a),v=o.drawText({x:_+p.left,y:x+p.top+.75*(null!=(s=null==f?void 0:f.height)?s:0),text:e,fontSize:d.fontSize,fontFamily:d.fontFamily,fontWeight:d.fontWeight,foreColor:u,cssClass:d.cssClass||""});l.add(y),l.add(v)}}l.add(h),a.add(l)}),this._renderBreadcrumb(),a}_levelCfg(e){if(this._levelCache||(this._levelCache=[]),this._levelCache[e])return this._levelCache[e];const t=this.w.config.plotOptions.treemap,r=t.parents||{},o=(t.levels||[])[e]||{},n=h(l(l({},r),o),{header:h(l(l({},r.header||{}),o.header||{}),{style:l(l({},(r.header||{}).style||{}),(o.header||{}).style||{})}),hover:l(l({},r.hover||{}),o.hover||{})});return this._levelCache[e]=n,n}_levelPadding(e,t,r){const o=this._levelCfg(e);return Number(o.padding)||0}_levelHeader(e,t,r,o){const n=this._levelCfg(t).header||{};if(!1===n.show)return 0;const a=Number(n.height);if(!Number.isFinite(a)||a<=0)return 0;return r<(Number(n.minWidth)||40)||o<2*a?0:a}_leavesBySeries(e,t){const r=new Array(Math.max(1,t));for(let e=0;e<r.length;e++)r[e]=[];const o=e=>{if(e.children&&e.children.length)e.children.forEach(o);else{const t=e._si||0;r[t]&&r[t].push(e)}};return e.forEach(o),r}_parentsBySeries(e,t){const r=new Array(Math.max(1,t));for(let e=0;e<r.length;e++)r[e]=[];const o=e=>{if(!e.children||!e.children.length)return;const t=e._si||0;r[t]&&r[t].push(e),e.children.forEach(o)};return e.forEach(o),r.forEach(e=>e.sort((e,t)=>(e.depth||0)-(t.depth||0))),r}_leafColor(e,t){const r=this.w;if(this.scale){const o=function(e,t,r){const o=e.config.series[t];return R(e,o&&Array.isArray(o.data)?o.data[r]:null,t,r)}(r,e,t);if(null!=o){const e=this.scale.at(o);return{color:e,foreColor:I(e),colorProps:{color:e,foreColor:I(e),percent:0}}}}return this.helpers.getShadeColor(r.config.chart.type,e,t,this.negRange)}_parentChrome(e){const t=this.w,r=this._levelCfg(e),o="dark"===t.config.theme.mode,n=(r.header||{}).style||{},a=Math.min(e,3),i=o?255:0,s=`${i},${i},${i}`;return{fill:r.fill||`rgba(${s},${(o?.04:.03)+.02*a})`,fillOpacity:null==r.fillOpacity?1:r.fillOpacity,borderColor:r.borderColor||`rgba(${s},${o?.18:.14})`,borderWidth:null==r.borderWidth?1:r.borderWidth,borderRadius:null==r.borderRadius?t.config.plotOptions.treemap.borderRadius:r.borderRadius,headerBg:n.background||`rgba(${s},${o?.1:.07})`,headerColor:n.color||(o?"#e8e8e8":t.config.chart.foreColor),headerFontSize:n.fontSize||"12px",headerFontFamily:n.fontFamily||t.config.chart.fontFamily,headerFontWeight:null==n.fontWeight?600:n.fontWeight,hoverColor:r.hover&&r.hover.color||(o?"rgba(255,255,255,0.85)":"rgba(0,0,0,0.7)"),hoverWidth:r.hover&&r.hover.width||2,hoverShow:!(r.hover&&!1===r.hover.show)}}_drawParent(e,t,r){var o;const n=t.rect;if(!n)return;const a=this.w,i=new x(this.w,this.ctx),s=t.depth||0,l=this._levelCfg(s),h=this._parentChrome(s),c=n[0],d=n[1],u=n[2]-n[0],p=n[3]-n[1];if(u<=0||p<=0)return;const f=i.group({class:"apexcharts-treemap-parent","data:depth":s,"data:name":A.escapeString(t.name)}),g=E(t._key),m=this._morphKeyed()?this.ctx.morphTypeChange.getInitialPathForKey(g):null,b=m?i.drawPath({d:this._tilePath(c,d,c+u,d+p),fill:h.fill,stroke:h.borderColor,strokeWidth:h.borderWidth,fillOpacity:h.fillOpacity}):i.drawRect(c,d,u,p,h.borderRadius,h.fill,h.fillOpacity,h.borderWidth,h.borderColor);b.node.classList.add("apexcharts-treemap-parent-rect"),b.node.setAttribute("data:key",g),b.node.setAttribute("data:depth",String(s)),m&&this._morphTile(b,m,this._tilePath(c,d,c+u,d+p),this.ctx.morphTypeChange.getSpeed(),r,s),f.add(b);const _=t.headerHeight||0;let y="";if(_>0){const e=l.header||{},n=i.drawRect(c,d,u,_,0,h.headerBg,1,0,"transparent");n.node.classList.add("apexcharts-treemap-parent-header"),f.add(n);let p=String(null!=(o=t.name)?o:"");"function"==typeof e.formatter?p=String(e.formatter(t.name,{value:t.value,depth:s,seriesIndex:r,node:t,w:a})):e.showValue&&(p=`${p} ${this._formatValue(t.value)}`),y=p;const g=Number(e.offsetX)||0,m=e.align||"left",x=6,v=Math.max(0,u-2*x-Math.abs(g)),w=parseFloat(String(h.headerFontSize))||12,A=i.getTextBasedOnMaxWidth({text:p,maxWidth:v,fontSize:w});if(A){let t=c+x+g,r="start";"center"===m?(t=c+u/2+g,r="middle"):"right"===m&&(t=c+u-x+g,r="end");const o=i.drawText({x:t,y:d+_/2+w/3+(Number(e.offsetY)||0),text:A,textAnchor:r,fontSize:h.headerFontSize,fontFamily:h.headerFontFamily,fontWeight:h.headerFontWeight,foreColor:h.headerColor,cssClass:`apexcharts-treemap-parent-label ${e.style&&e.style.cssClass||""}`});o.node.setAttribute("pointer-events","none"),f.add(o)}this._attachParentEvents(n.node,t,h,b),this._makeParentAccessible(n.node,t,h,b,y)}this._attachParentEvents(b.node,t,h,b),f.node.setAttribute("role","group"),f.node.setAttribute("aria-label",this._parentLabel(t,y)),e.add(f)}_parentLabel(e,t){const r=this._drawnTotal(),o=r>0?(e._area/r*100).toFixed(1):"0",n=this._countLeaves(e);return`${t&&String(t).trim()?String(t).replace(/\s+/g," ").trim():`${e.name}, ${this._formatValue(e._area)}`}, ${n} ${1===n?"item":"items"}, ${o}% of total`}_makeParentAccessible(e,t,r,o,n){e&&e.setAttribute&&this._zoomEnabled()&&(e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.setAttribute("aria-label",`${this._parentLabel(t,n)}. Zoom in`),e.setAttribute("aria-expanded","false"),N.isBrowser()&&e.addEventListener&&(e.addEventListener("focus",()=>{o.node.setAttribute("stroke",r.hoverColor),o.node.setAttribute("stroke-width",String(r.hoverWidth+1))}),e.addEventListener("blur",()=>{o.node.setAttribute("stroke",r.borderColor),o.node.setAttribute("stroke-width",String(r.borderWidth))}),e.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key&&"Spacebar"!==e.key||(e.preventDefault(),this._zoomTo(t,!0))})))}_attachParentEvents(e,t,r,o){if(!N.isBrowser()||!e||!e.addEventListener)return;const n=this.w;r.hoverShow&&(e.addEventListener("mouseenter",()=>{o.node.setAttribute("stroke",r.hoverColor),o.node.setAttribute("stroke-width",String(r.hoverWidth))}),e.addEventListener("mouseleave",()=>{o.node.setAttribute("stroke",r.borderColor),o.node.setAttribute("stroke-width",String(r.borderWidth))})),n.config.tooltip.enabled&&(e.addEventListener("mouseenter",e=>this._showParentTooltip(e,t)),e.addEventListener("mousemove",e=>this._positionTooltip(e)),e.addEventListener("mouseleave",()=>this._hideParentTooltip())),this._zoomEnabled()&&(e.style.cursor="pointer",e.addEventListener("click",()=>this._zoomTo(t)))}_zoomEnabled(){const e=this.w,t=e.config.plotOptions.treemap.zoom;if(!t||!t.enabled||!this.showParents)return!1;const r=e.config.drilldown;return!(r&&r.enabled&&Array.isArray(r.series)&&r.series.length)||(this._warnedZoomConflict||(this._warnedZoomConflict=!0,console.warn("ApexCharts treemap: `plotOptions.treemap.zoom` and the drilldown feature both navigate the hierarchy, so zoom is ignored here. Drop `drilldown.series` to zoom a nested treemap instead.")),!1)}_resolveFocus(e){const t=this.w.globals.treemapFocusKey;if(!t||!this._zoomEnabled())return null;let r=null;const o=e=>{r||(e._key!==t?e.children&&e.children.forEach(o):r=e)};return e.forEach(o),r&&r.children&&r.children.length?r:null}_zoomTo(e,t=!1){const r=this.w;if(!e||!e.children||!e.children.length)return;const o=r.globals.treemapFocusKey===e._key?null:e._key;r.globals.treemapFocusKey=o,this._hideParentTooltip();const n=this.ctx.update();t&&n&&"function"==typeof n.then&&n.then(()=>{if(!N.isBrowser())return;const e=r.dom.baseEl.querySelector(".apexcharts-breadcrumb .apexcharts-breadcrumb-item");if(e&&e.focus)return void e.focus();const t=r.dom.baseEl.querySelector(".apexcharts-treemap-parent-header[tabindex]");t&&t.focus&&t.focus()})}_focusChain(){const e=[],t=new Set(this.drawn||[]);let r=this._resolveFocus(this.drawn||[]);for(;r&&(e.unshift(r),!t.has(r));)r=r._parent;return e}_breadcrumbCfg(){const e=this.w.config.plotOptions.treemap.zoom;return Y(this.w,e&&e.breadcrumb)}_renderBreadcrumb(){if(!N.isBrowser())return;const e=this.w;if(!e.dom.elWrap)return;if(H(e),!this._zoomEnabled())return;const t=this._focusChain();if(!t.length)return;const r=function(e,t){if(!N.isBrowser())return null;const r=e.dom.elWrap;if(!r)return null;H(e);const o=t.config||Y(e);if(!1===o.show)return null;const n=t.crumbs||[];if(n.length<2)return null;const a=D.createElementNS(j,"nav");a.setAttribute("class","apexcharts-breadcrumb"),a.setAttribute("aria-label",t.ariaLabel||"Breadcrumb"),function(e,t){const r=t.offsetX||0,o=t.offsetY||0;e.style.position="absolute",e.style.top=o+"px","top-right"===t.position?e.style.right=3-r+"px":e.style.left=r+"px"}(a,o),t.compact&&(a.style.fontSize="11px",a.style.padding="0 2px");const i=null!=o.separator?o.separator:" / ";return n.forEach((e,r)=>{var s;if(r>0){const e=D.createElementNS(j,"span");e.setAttribute("class","apexcharts-breadcrumb-separator"),e.setAttribute("aria-hidden","true"),e.textContent=i,a.appendChild(e)}let l=0===r?null!=(s=o.rootLabel)?s:"All":e.label;if("function"==typeof o.formatter&&(l=o.formatter(l,{index:r,depth:n.length-1,data:e.data})),r===n.length-1){const e=D.createElementNS(j,"span");return e.setAttribute("class","apexcharts-breadcrumb-item apexcharts-breadcrumb-current"),e.setAttribute("aria-current","page"),e.textContent=String(l),void a.appendChild(e)}const h=D.createElementNS(j,"button");if(h.setAttribute("type","button"),h.setAttribute("class","apexcharts-breadcrumb-item"),0===r){const e=D.createElementNS(j,"span");e.setAttribute("class","apexcharts-breadcrumb-arrow"),e.setAttribute("aria-hidden","true"),e.textContent="\u2190",h.appendChild(e)}const c=D.createElementNS(j,"span");c.setAttribute("class","apexcharts-breadcrumb-label"),c.textContent=String(l),h.appendChild(c),h.addEventListener("click",()=>t.onNavigate(r,e)),a.appendChild(h)}),r.appendChild(a),a}(e,{ariaLabel:"Treemap breadcrumb",config:this._breadcrumbCfg(),compact:!0,crumbs:[{label:"All",data:null}].concat(t.map(e=>({label:e.name,data:e}))),onNavigate:(t,r)=>{e.globals.treemapFocusKey=r.data?r.data._key:null,this._hideParentTooltip(),this.ctx.update()}});r&&(this._placeBreadcrumb(r),function(e,t){const r=[".apexcharts-title-text",".apexcharts-subtitle-text"].map(t=>e.dom.baseEl.querySelector(t)).filter(e=>null!==e);if(!r.length)return;const o=e.dom.elWrap.getBoundingClientRect().top;for(let e=0;e<r.length+1;e++){const e=t.getBoundingClientRect(),n=r.find(t=>{const r=t.getBoundingClientRect();return e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top});if(!n)break;t.style.top=n.getBoundingClientRect().bottom-o+4+"px"}}(e,r))}_placeBreadcrumb(e){var t,r;const o=this.w,n=o.layout.translateY||0,a=null==(r=null==(t=this.ctx)?void 0:t.dimensions)?void 0:r.dimHelpers,i=a?a.getTitleSubtitleCoords("title").height+a.getTitleSubtitleCoords("subtitle").height:0,s=e.getBoundingClientRect().height||18;if(n-i>=s+1)return void(e.style.top=n-s-1+"px");e.style.top=`${i}px`;const l="dark"===o.config.theme.mode;e.style.background=l?"rgba(20,24,30,0.82)":"rgba(255,255,255,0.86)",e.style.borderRadius="4px"}_showParentTooltip(e,t){const r=this.w,o=this._tip();if(!o)return;const n=this._drawnTotal(),a=t._parent?t._parent._area:n,i=n>0?(t._area/n*100).toFixed(1):"0.0",s=a>0?(t._area/a*100).toFixed(1):i,l=this.w.config.plotOptions.treemap.parents,h=l&&l.tooltip&&l.tooltip.formatter,c=this._countLeaves(t);let d;if("function"==typeof h)d=h({name:t.name,value:t._area,depth:t.depth||0,leafCount:c,percentOfParent:Number(s),percentOfTotal:Number(i),node:t,w:r});else{const e=this._parentChrome(t.depth||0).headerBg;d=`<div class="apexcharts-tooltip-series-group apexcharts-active" style="display:flex;${r.config.tooltip.fillSeriesColor?`background-color:${e};`:""}"><div class="apexcharts-tooltip-text"><div class="apexcharts-tooltip-y-group"><span class="apexcharts-tooltip-text-y-label">${A.escapeString(t.name)}: </span><span class="apexcharts-tooltip-text-y-value">${this._formatValue(t._area)}</span></div><div class="apexcharts-tooltip-y-group"><span class="apexcharts-tooltip-text-y-label">${c} items, </span><span class="apexcharts-tooltip-text-y-value">${s}% of parent, ${i}% of total</span></div></div></div>`}o.innerHTML=d,o.classList.add("apexcharts-active"),o.style.opacity="1",this._tipOwned=!0,this._positionTooltip(e)}_tip(){return this._tooltipEl||(this._tooltipEl=this.w.dom.baseEl.querySelector(".apexcharts-tooltip")),this._tooltipEl}_positionTooltip(e){const t=this._tip();if(!t||!this._tipOwned)return;const r=this.w.dom.elWrap.getBoundingClientRect(),o=t.offsetWidth,n=t.offsetHeight;let a=e.clientX-r.left+12;a+o>r.width&&(a=e.clientX-r.left-o-12),a=Math.max(0,Math.min(a,r.width-o));let i=e.clientY-r.top+12;i+n>r.height&&(i=e.clientY-r.top-n-12),i=Math.max(0,Math.min(i,r.height-n)),t.style.left=a+"px",t.style.top=i+"px"}_hideParentTooltip(){const e=this._tip();e&&this._tipOwned&&(this._tipOwned=!1,e.classList.remove("apexcharts-active"),e.style.opacity="0")}_drawnTotal(){return null==this._total&&(this._total=(this.drawn||[]).reduce((e,t)=>e+this._subtreeArea(t),0)),this._total||0}_subtreeArea(e){if(null!=e._area)return e._area;const t=e.children;if(t&&t.length){let e=0;for(let r=0;r<t.length;r++)e+=this._subtreeArea(t[r]);return e}const r=Number(e.value);return isNaN(r)?0:Math.abs(r)}_countLeaves(e){return e.children&&e.children.length?e.children.reduce((e,t)=>e+this._countLeaves(t),0):1}_formatValue(e){var t,r,o,n,a;const i=this.w,s=(null==(r=null==(t=i.config.tooltip)?void 0:t.y)?void 0:r.formatter)||(null==(a=null==(n=null==(o=i.config.yaxis)?void 0:o[0])?void 0:n.labels)?void 0:a.formatter);if("function"==typeof s)try{return String(s(e,{seriesIndex:0,dataPointIndex:0,w:i}))}catch(e){}return String(e)}_labelCanShow(e,t,r){if(!Number.isFinite(e)||e<=0)return!1;const o=this.w.config.plotOptions.treemap.dataLabels;return!(e<(o&&null!=o.minFontSize?Number(o.minFontSize):0))&&Math.max(t,r)>=e}_averageLabelSize(){if(null!=this._avgLabelSize)return this._avgLabelSize;return this._avgLabelSize=function e(t){let r,o=0;if(Array.isArray(t[0]))for(r=0;r<t.length;r++)o+=e(t[r]);else for(r=0;r<t.length;r++)o+=t[r].length;return o}(this.labels)/function e(t){let r,o=0;if(Array.isArray(t[0]))for(r=0;r<t.length;r++)o+=e(t[r]);else for(r=0;r<t.length;r++)o+=1;return o}(this.labels),this._avgLabelSize}getFontSize(e){const t=this.w,r=this._averageLabelSize();return function(e,o){const n=e*o,a=Math.pow(n,.5);return Math.min(a/r,parseInt(t.config.dataLabels.style.fontSize,10))}(e[2]-e[0],e[3]-e[1])}rotateToFitLabel(e,t,r,o,n,a,i){const s=new x(this.w),l=s.getTextRects(r,String(t));if(l.width+this.w.config.stroke.width+5>a-o&&l.width<=i-n){const t=s.rotateAroundCenter(e.node);e.node.setAttribute("transform",`rotate(-90 ${t.x} ${t.y}) translate(${l.height/3})`)}}truncateLabels(e,t,r,o,n,a){const i=new x(this.w),s=i.getTextRects(e,String(t)).width+this.w.config.stroke.width+5>n-r&&a-o>n-r?a-o:n-r,l=i.getTextBasedOnMaxWidth({text:e,maxWidth:s,fontSize:t});return e.length!==l.length&&s/t<5?"":l}_morphKeyed(){var e;const t=null==(e=this.ctx)?void 0:e.morphTypeChange;return!(!t||"function"!=typeof t.hasKeyedMarks||!t.hasKeyedMarks()||"function"!=typeof t.getInitialPathForKey)}_morphSourceForLeaf(e){var t;const r=null==(t=this.ctx)?void 0:t.morphTypeChange;if(!r||"function"!=typeof r.getInitialPathAt)return null;if(this._morphKeyed()){const t=r.getInitialPathForKey(E(e._key));if(t)return t}return r.getInitialPathAt(this._morphLeafIndex++)}_tilePath(e,t,r,o){return`M ${e} ${t} L ${r} ${t} L ${r} ${o} L ${e} ${o} Z`}_morphTile(e,t,r,o,n,a){new v(this.w,this.ctx).morphSVG(e,n,a,"none",t,r,o,0)}animateTreemap(e,t,r,o,n=0){const a=new v(this.w);a.animateRect(e,t,r,o,()=>{a.animationCompleted(e)},n)}}}),e.default=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});