UNPKG

apexcharts

Version:

A JavaScript Chart Library

6 lines (5 loc) 35.8 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).ApexLegend={})}(this,function(e){"use strict";var t=Object.defineProperty,s=Object.defineProperties,i=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,a=(e,s,i)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i,o=(e,t)=>{for(var s in t||(t={}))l.call(t,s)&&a(e,s,t[s]);if(n)for(var s of n(t))r.call(t,s)&&a(e,s,t[s]);return e},c=(e,t)=>s(e,i(t));const d=globalThis.ApexCharts,g=globalThis.ApexCharts.__internals.__apex_CoreUtils,h=globalThis.ApexCharts.__internals.__apex_dimensions_Dimensions,p=globalThis.ApexCharts.__internals.__apex_Graphics,u=globalThis.ApexCharts.__internals.__apex_Series,f=globalThis.ApexCharts.__internals.__apex_Utils,m=globalThis.ApexCharts.__internals.__apex_Environment_Environment;class x{constructor(e){this.w=e.w,this.lgCtx=e}getLegendStyles(){if(m.isSSR())return null;const e=document.createElement("style");e.setAttribute("type","text/css");const t=this.w.config.chart.nonce;t&&e.setAttribute("nonce",t);const s=document.createTextNode(".apexcharts-flip-y {\n transform: scaleY(-1) translateY(-100%);\n transform-origin: top;\n transform-box: fill-box;\n}\n.apexcharts-flip-x {\n transform: scaleX(-1);\n transform-origin: center;\n transform-box: fill-box;\n}\n.apexcharts-legend {\n display: flex;\n overflow: auto;\n padding: 0 10px;\n}\n.apexcharts-legend.apexcharts-legend-group-horizontal {\n flex-direction: column;\n}\n.apexcharts-legend-group {\n display: flex;\n}\n.apexcharts-legend-group-vertical {\n flex-direction: column-reverse;\n}\n.apexcharts-legend.apx-legend-position-bottom, .apexcharts-legend.apx-legend-position-top {\n flex-wrap: wrap\n}\n.apexcharts-legend.apx-legend-position-right, .apexcharts-legend.apx-legend-position-left {\n flex-direction: column;\n bottom: 0;\n}\n.apexcharts-legend.apx-legend-position-bottom.apexcharts-align-left, .apexcharts-legend.apx-legend-position-top.apexcharts-align-left, .apexcharts-legend.apx-legend-position-right, .apexcharts-legend.apx-legend-position-left {\n justify-content: flex-start;\n align-items: flex-start;\n}\n.apexcharts-legend.apx-legend-position-bottom.apexcharts-align-center, .apexcharts-legend.apx-legend-position-top.apexcharts-align-center {\n justify-content: center;\n align-items: center;\n}\n.apexcharts-legend.apx-legend-position-bottom.apexcharts-align-right, .apexcharts-legend.apx-legend-position-top.apexcharts-align-right {\n justify-content: flex-end;\n align-items: flex-end;\n}\n.apexcharts-legend-series {\n cursor: pointer;\n line-height: normal;\n display: flex;\n align-items: center;\n}\n.apexcharts-legend-text {\n position: relative;\n font-size: 14px;\n}\n.apexcharts-legend-text *, .apexcharts-legend-marker * {\n pointer-events: none;\n}\n.apexcharts-legend-marker {\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n margin-right: 1px;\n}\n\n.apexcharts-legend-series.apexcharts-no-click {\n cursor: auto;\n}\n.apexcharts-legend .apexcharts-hidden-zero-series, .apexcharts-legend .apexcharts-hidden-null-series {\n display: none !important;\n}\n.apexcharts-inactive-legend {\n opacity: 0.45;\n} ");return e.appendChild(s),e}getLegendDimensions(){const e=this.w.dom.baseEl.querySelector(".apexcharts-legend");if(!e)return{clwh:0,clww:0};const{width:t,height:s}=e.getBoundingClientRect();return{clwh:s,clww:t}}appendToForeignObject(){var e;const t=this.getLegendStyles();!1!==this.w.config.chart.injectStyleSheet&&t&&(null==(e=this.w.dom.elLegendForeign)||e.appendChild(t))}toggleDataSeries(e,t){var s,i,n;const l=this.w;if(l.globals.axisCharts||"radialBar"===l.config.chart.type){l.globals.resized=!0;let r=null,a=null;if(l.globals.risingSeries=[],l.globals.axisCharts){if(r=null!=(s=Array.prototype.find.call(l.dom.baseEl.querySelectorAll(".apexcharts-series"),t=>t.getAttribute("data:realIndex")===String(e)))?s:null,!r)return;a=parseInt(null!=(i=r.getAttribute("data:realIndex"))?i:"",10)}else{if(r=l.dom.baseEl.querySelector(`.apexcharts-series[rel='${e+1}']`),!r)return;a=parseInt(null!=(n=r.getAttribute("rel"))?n:"",10)-1}if(t){[{cs:l.globals.collapsedSeries,csi:l.globals.collapsedSeriesIndices},{cs:l.globals.ancillaryCollapsedSeries,csi:l.globals.ancillaryCollapsedSeriesIndices}].forEach(e=>{const t=e.cs,s=e.csi;this.riseCollapsedSeries(t,s,a)})}else this.hideSeries({seriesEl:r,realIndex:a});if(l.config.chart.accessibility.enabled){const t=l.dom.baseEl.querySelector(`.apexcharts-legend-series[rel="${e+1}"]`);if(t){const s=l.globals.collapsedSeriesIndices.includes(a)||l.globals.ancillaryCollapsedSeriesIndices.includes(a);t.setAttribute("aria-pressed",s?"true":"false");const i=t.querySelector(".apexcharts-legend-text"),n=i?i.textContent:l.seriesData.seriesNames[e],r=s?"hidden":"visible";t.setAttribute("aria-label",`${n}, ${r}. Press Enter or Space to toggle.`)}}}else{if(l.globals.resized=!0,l.globals.risingSeries=[],t)this.riseCollapsedSeries(l.globals.collapsedSeries,l.globals.collapsedSeriesIndices,e);else{const t=this.getSeriesAfterCollapsing({realIndex:e});this.lgCtx.updateSeries(t,l.config.chart.animations.dynamicAnimation.enabled)}if(l.config.chart.accessibility.enabled){const t=l.dom.baseEl.querySelector(`.apexcharts-legend-series[rel="${e+1}"]`);if(t){const s=l.globals.collapsedSeriesIndices.includes(e);t.setAttribute("aria-pressed",s?"true":"false");const i=t.querySelector(".apexcharts-legend-text"),n=i?i.textContent:l.seriesData.seriesNames[e],r=s?"hidden":"visible";t.setAttribute("aria-label",`${n}, ${r}. Press Enter or Space to toggle.`)}}}}_nonAxisSliceContainer(e){const t=this.w.config.chart.type;return("pie"===t||"donut"===t||"polarArea"===t||"sunburst"===t)&&1===e.length&&e[0]&&"object"==typeof e[0]&&Array.isArray(e[0].data)?e[0].data:e}_readSliceValue(e){return"unit"===this.w.config.chart.type&&e&&Array.isArray(e.data)?e.data:e&&"object"==typeof e?e.y:e}_writeSliceValue(e,t,s){const i=e[t];"unit"===this.w.config.chart.type&&i&&Array.isArray(i.data)?i.data=Array.isArray(s)?s:[]:i&&"object"==typeof i?i.y=s:e[t]=s}getSeriesAfterCollapsing({realIndex:e}){var t,s;const i=this.w,n=i.globals,l=f.clone(i.config.series);if(n.axisCharts){const t=i.config.yaxis[n.seriesYAxisReverseMap[e]],s={index:e,data:l[e].data.slice(),type:l[e].type||i.config.chart.type,name:(n.seriesNames||[])[e]};if(t&&t.show&&t.showAlways)n.ancillaryCollapsedSeriesIndices.indexOf(e)<0&&(n.ancillaryCollapsedSeries.push(s),n.ancillaryCollapsedSeriesIndices.push(e));else if(n.collapsedSeriesIndices.indexOf(e)<0){n.collapsedSeries.push(s),n.collapsedSeriesIndices.push(e);const t=n.risingSeries.indexOf(e);n.risingSeries.splice(t,1)}}else if(n.collapsedSeriesIndices.indexOf(e)<0){const r=this._nonAxisSliceContainer(l);n.collapsedSeries.push({index:e,data:this._readSliceValue(r[e]),type:null!=(s=null==(t=i.config.series[e])?void 0:t.type)?s:"line",name:(n.seriesNames||[])[e]}),n.collapsedSeriesIndices.push(e)}const r=n.axisCharts?i.config.series.length:this._nonAxisSliceContainer(l).length;return n.allSeriesCollapsed=n.collapsedSeries.length+n.ancillaryCollapsedSeries.length===r,this._getSeriesBasedOnCollapsedState(l)}hideSeries({seriesEl:e,realIndex:t}){const s=this.w,i=this.getSeriesAfterCollapsing({realIndex:t}),n=e.childNodes;for(let e=0;e<n.length;e++)n[e].classList.contains("apexcharts-series-markers-wrap")&&(n[e].classList.contains("apexcharts-hide")?n[e].classList.remove("apexcharts-hide"):n[e].classList.add("apexcharts-hide"));const l=s.config.chart.animations.dynamicAnimation.enabled;l&&(s.globals.collapsingSeriesIndices=[t]);const r=()=>{s.globals.collapsingSeriesIndices=[]},a=this.lgCtx.updateSeries(i,l);r(),a&&"function"==typeof a.then&&a.then(r,r)}riseCollapsedSeries(e,t,s){const i=this.w;let n=f.clone(i.config.series);if(e.length>0){for(let l=0;l<e.length;l++)if(e[l].index===s){if(i.globals.axisCharts)n[s].data=e[l].data.slice(),n[s].hidden=!1;else{const t=this._nonAxisSliceContainer(n);this._writeSliceValue(t,s,e[l].data)}e.splice(l,1),t.splice(l,1),i.globals.risingSeries.push(s),l--}n=this._getSeriesBasedOnCollapsedState(n),this.lgCtx.updateSeries(n,i.config.chart.animations.dynamicAnimation.enabled)}}_getSeriesBasedOnCollapsedState(e){const t=this.w;let s=0;if(t.globals.axisCharts)e.forEach((i,n)=>{t.globals.collapsedSeriesIndices.indexOf(n)<0&&t.globals.ancillaryCollapsedSeriesIndices.indexOf(n)<0||(e[n].data=[],s++)});else{const i=this._nonAxisSliceContainer(e);i.forEach((e,n)=>{t.globals.collapsedSeriesIndices.indexOf(n)<0||(this._writeSliceValue(i,n,0),s++)})}const i=t.globals.axisCharts?e.length:this._nonAxisSliceContainer(e).length;return t.globals.allSeriesCollapsed=s===i,e}}const b=globalThis.ApexCharts.__internals.__apex_BrowserAPIs_BrowserAPIs,y=["#cf4d3f","#8f9499","#26a75b"],v=(e,t,s)=>e+(t-e)*s;function S(e){return Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")}function w(e,t,s){const i=f.parseHex(A(e)),n=f.parseHex(A(t));return i&&n?"#"+S(v(i[0],n[0],s))+S(v(i[1],n[1],s))+S(v(i[2],n[2],s)):e}function A(e){if("string"!=typeof e)return"#000000";if(f.isColorHex(e))return e;return f.rgb2hex(e)||"#000000"}function _(e,t,s,i){var n,l,r;if(!t||"object"!=typeof t)return null;const a=null==(r=null==(l=null==(n=e.config.plotOptions)?void 0:n.treemap)?void 0:l.colorScale)?void 0:r.colorValue;let o;if(o="function"==typeof a?a(t,{seriesIndex:s,dataPointIndex:i,w:e}):"string"==typeof a?t[a]:t.colorValue,null==o)return null;const c=Number(o);return Number.isFinite(c)?c:null}function C(e){var t,s,i;const n=null==(i=null==(s=null==(t=e.config)?void 0:t.plotOptions)?void 0:s.treemap)?void 0:i.colorScale,l=n&&n.gradient;if(!l)return null;if(!1===l.enabled)return null;const r=e.config.series||[];let a=1/0,o=-1/0,c=!1;for(let t=0;t<r.length;t++){const s=r[t]&&r[t].data;if(Array.isArray(s))for(let i=0;i<s.length;i++){const n=_(e,s[i],t,i);null!=n&&(c=!0,n<a&&(a=n),n>o&&(o=n))}}if(!c&&!0!==l.enabled)return null;Number.isFinite(a)||(a=0,o=0);let d=Number.isFinite(Number(l.min))?Number(l.min):a,g=Number.isFinite(Number(l.max))?Number(l.max):o,h=null;if(null===l.midpoint?h=null:Number.isFinite(Number(l.midpoint))?h=Number(l.midpoint):d<0&&g>0&&(h=0),null!=h&&!1!==l.symmetric&&!Number.isFinite(Number(l.min))&&!Number.isFinite(Number(l.max))){const e=Math.max(Math.abs(d-h),Math.abs(g-h));d=h-e,g=h+e}g===d&&(d-=.5,g+=.5);const p=function(e,t,s,i){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:A(e.color)})).sort((e,t)=>e.value-t.value);const n=(Array.isArray(e.colors)&&e.colors.length>=2?e.colors:y).map(A),l=n.length;if(null!=i&&l>=3){const e=Math.floor((l-1)/2),r=[];for(let s=0;s<=e;s++)r.push({value:v(t,i,s/e),color:n[s]});for(let t=e+1;t<l;t++)r.push({value:v(i,s,(t-e)/(l-1-e)),color:n[t]});return r}return n.map((e,i)=>({value:v(t,s,i/(l-1)),color:e}))}(l,d,g,h);if(p.length<2)return null;const u=g-d,f=p.map(e=>({percent:0===u?0:(e.value-d)/u,color:e.color}));return{min:d,max:g,midpoint:h,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 s=p[t];if(e<=s.value){const i=p[t-1],n=s.value-i.value,l=0===n?0:(e-i.value)/n;return w(i.color,s.color,l)}}return t.color},legendStops:f}}const L="http://www.w3.org/2000/svg";class E{constructor(e,t){this.w=e,this.ctx=t,this.svgEl=null,this.arrowEl=null,this.hoverValueEl=null,this._min=0,this._max=0,this._geom=null,this._bandHitEls=[],this._activeBandIndex=-1,this._targetEl=null,this._onCellEnter=this._onCellEnter.bind(this),this._onCellLeave=this._onCellLeave.bind(this),this._onBandEnter=this._onBandEnter.bind(this),this._onBandLeave=this._onBandLeave.bind(this)}_getFormatter(){const e=this._cfg();return"function"==typeof e.formatter?e.formatter:e=>{if(!Number.isFinite(e))return String(e);const t=Math.abs(e);return t>=1e3?e.toFixed(0):t>=10?e.toFixed(1):e.toFixed(2)}}static colorScaleOf(e){var t,s,i,n,l;const r=null==(s=null==(t=null==e?void 0:e.config)?void 0:t.chart)?void 0:s.type;return r&&(null==(l=null==(n=null==(i=null==e?void 0:e.config)?void 0:i.plotOptions)?void 0:n[r])?void 0:l.colorScale)||null}static configFor(e){const t=E.colorScaleOf(e);return t&&t.gradientLegend||null}_cfg(){return E.configFor(this.w)||{}}static isEnabled(e){if(!E.supports(e))return!1;const t=E.configFor(e);return!(!t||!t.enabled)}static supports(e){var t,s;const i=null==(s=null==(t=null==e?void 0:e.config)?void 0:t.chart)?void 0:s.type;return"heatmap"===i||"treemap"===i}draw(e=null){var t,s,i,n,l,r,a,o;const c=this.w;this._targetEl=e;const d=e||c.dom.elLegendWrap;if(!d)return;const g=this._cfg(),h=c.config.legend.position,p="left"===h||"right"===h,u=null!=(s=null==(t=g.arrow)?void 0:t.size)?s:8,f=u+4,m=g.showLabels?28:4,x=g.showLabels?20:4,y=g.showLabels?44:0,v=this._resolveStripLength(p?g.height:g.width,p),S=g.thickness,w=p?Math.max(S+f+4,y):v+2*m,A=p?v+2*x:S+f+4,_=(w-(S+f))/2,C=p?"left"===h?_:_+f:m,E=p?x:"top"===h?f:4,k=b.createElementNS(L,"svg");k.setAttribute("class","apexcharts-heatmap-gradient-legend apexcharts-gradient-legend"),k.setAttribute("width",String(w)),k.setAttribute("height",String(A)),k.setAttribute("overflow","visible");const I=b.createElementNS(L,"defs"),F=`apexcharts-heatmap-gradient-${c.globals.cuid}`,H=b.createElementNS(L,"linearGradient");H.setAttribute("id",F),p?(H.setAttribute("x1","0"),H.setAttribute("y1","1"),H.setAttribute("x2","0"),H.setAttribute("y2","0")):(H.setAttribute("x1","0"),H.setAttribute("y1","0"),H.setAttribute("x2","1"),H.setAttribute("y2","0"));const{min:N,max:M,stops:B,bands:O}=this._computeStops();this._min=N,this._max=M,B.forEach(e=>{const t=b.createElementNS(L,"stop");t.setAttribute("offset",`${(100*e.percent).toFixed(2)}%`),t.setAttribute("stop-color",e.color),H.appendChild(t)}),I.appendChild(H),k.appendChild(I);const T=b.createElementNS(L,"rect");if(T.setAttribute("x",String(C)),T.setAttribute("y",String(E)),T.setAttribute("width",String(p?S:v)),T.setAttribute("height",String(p?v:S)),T.setAttribute("rx","2"),T.setAttribute("fill",`url(#${F})`),k.appendChild(T),g.showLabels){const e=(null==(i=g.labelStyle)?void 0:i.colors)||(Array.isArray(c.config.legend.labels.colors)?c.config.legend.labels.colors[0]:c.config.legend.labels.colors)||c.config.chart.foreColor,t=(null==(n=g.labelStyle)?void 0:n.fontSize)||"11px",s=(null==(l=g.labelStyle)?void 0:l.fontFamily)||c.config.chart.fontFamily,r=this._getFormatter(),a=(i,n,l,r)=>{const a=b.createElementNS(L,"text");return a.setAttribute("x",String(n)),a.setAttribute("y",String(l)),a.setAttribute("text-anchor",r),a.setAttribute("dominant-baseline","middle"),a.setAttribute("fill",e),a.setAttribute("font-size",t),s&&a.setAttribute("font-family",s),a.textContent=String(i),a};if(p){const e=C+S/2;k.appendChild(a(r(N),e,E+v+10,"middle")),k.appendChild(a(r(M),e,E-10,"middle"))}else{const e=E+S/2;k.appendChild(a(r(N),C-6,e,"end")),k.appendChild(a(r(M),C+v+6,e,"start"))}}const V=(null==(r=g.arrow)?void 0:r.color)||c.config.chart.foreColor,$=this._buildArrow(u,V,h);if(k.appendChild($),this.arrowEl=$,this._bandHitEls=[],c.config.legend.onItemHover.highlightDataSeries&&O.length>0&&O.forEach(e=>{const t=b.createElementNS(L,"rect");if(p){const s=E+v-e.p2*v,i=E+v-e.p1*v;t.setAttribute("x",String(C)),t.setAttribute("y",String(s)),t.setAttribute("width",String(S)),t.setAttribute("height",String(Math.max(0,i-s)))}else t.setAttribute("x",String(C+e.p1*v)),t.setAttribute("y",String(E)),t.setAttribute("width",String(Math.max(0,(e.p2-e.p1)*v))),t.setAttribute("height",String(S));t.setAttribute("fill","transparent"),t.setAttribute("class","apexcharts-heatmap-gradient-band"),t.setAttribute("data:range-index",String(e.index)),t.style.cursor="pointer",k.appendChild(t),this._bandHitEls.push(t)}),this._geom={isVertical:p,position:h,stripX:C,stripY:E,stripLength:v,stripThickness:S,arrowSize:u,svgWidth:w,svgHeight:A},g.showHoverValue){const e=b.createElement("div");e.classList.add("apexcharts-heatmap-gradient-legend-value"),e.style.position="absolute",e.style.fontSize=(null==(a=g.labelStyle)?void 0:a.fontSize)||"11px",e.style.fontFamily=(null==(o=g.labelStyle)?void 0:o.fontFamily)||c.config.chart.fontFamily||"",e.style.color=c.config.chart.foreColor,e.style.background="rgba(0,0,0,0.65)",e.style.color="#fff",e.style.padding="2px 6px",e.style.borderRadius="3px",e.style.pointerEvents="none",e.style.whiteSpace="nowrap",e.style.opacity="0",e.style.transition="opacity 120ms ease",this.hoverValueEl=e}d.classList.add("apexcharts-heatmap-gradient-legend-wrap"),d.classList.add("apx-legend-position-"+h),d.appendChild(k),this.hoverValueEl&&d.appendChild(this.hoverValueEl),this.svgEl=k,e?(d.style.width=w+"px",d.style.height=A+"px",d.style.position="relative",d.style.overflow="visible"):this._applyWrapAlignment(d,h,p,w,A),this._attachHoverListeners(),this._attachBandHoverListeners()}_resolveStripLength(e,t){const s=this.w,i=t?s.globals.svgHeight||s.config.chart.height||300:s.globals.svgWidth||s.config.chart.width||600;if("string"==typeof e){const t=e.trim();if(t.endsWith("%")){const e=parseFloat(t)||0;return Math.max(20,i*e/100)}const s=parseFloat(t);return Number.isFinite(s)?s:200}return"number"==typeof e&&Number.isFinite(e)?e:200}_applyWrapAlignment(e,t,s,i,n){const l=this.w,r=this._cfg().align||"center",a=12,o=l.globals.svgWidth||l.config.chart.width||600,c=l.globals.svgHeight||l.config.chart.height||300,d=l.config.legend.offsetX||0,g=l.config.legend.offsetY||0;if(e.style.position="absolute",e.style.display="block",e.style.overflow="visible",e.style.padding="0",e.style.width=i+"px",e.style.height=n+"px",e.style.right="auto",e.style.bottom="auto",s){const s=c-n-24;let l;l="start"===r?a:"end"===r?a+Math.max(0,s):a+Math.max(0,s)/2,e.style.top=l+g+"px",e.style.left="left"===t?a+d+"px":o-i-a+d+"px"}else{const s=o-i-24;let l;l="start"===r?a:"end"===r?a+Math.max(0,s):a+Math.max(0,s)/2,e.style.left=l+d+"px",e.style.top="top"===t?a+g+"px":c-n-a+g+"px"}}repositionToPlot(){var e,t;if(!m.isBrowser())return;if(this._targetEl)return;const s=this.w,i=s.globals,n=s.dom.elLegendWrap;if(!n||!this._geom)return;if(!Number.isFinite(i.gridWidth)||!Number.isFinite(i.gridHeight))return;const{isVertical:l,position:r,svgWidth:a,svgHeight:o,stripX:c,stripY:d,stripThickness:g}=this._geom,h=this._cfg().align||"center",p=s.config.legend.offsetX||0,u=s.config.legend.offsetY||0,f=null==(t=null==(e=this.ctx)?void 0:e.dimensions)?void 0:t.dimHelpers,x=f?f.getTitleSubtitleCoords("title").height+f.getTitleSubtitleCoords("subtitle").height:0,y=s.layout.xAxisHeight||0,v=(e,t)=>{const s=Math.max(0,e-t);return"start"===h?0:"end"===h?s:s/2};if(l){n.style.top=i.translateY+v(i.gridHeight,o)+u+"px";const e=(("left"===r?0:i.translateX+i.gridWidth)+("left"===r?i.translateX:i.svgWidth))/2;n.style.left=e-c-g/2+p+"px"}else{n.style.left=i.translateX+v(i.gridWidth,a)+p+"px";const e=(("top"===r?x:i.translateY+i.gridHeight+y)+("top"===r?i.translateY:i.svgHeight))/2;n.style.top=e-d-g/2+u+"px"}b.requestAnimationFrame(()=>this._enforceMinPlotGap())}_enforceMinPlotGap(){const e=this.w,t=e.dom.elLegendWrap,s=this.svgEl&&this.svgEl.querySelector("rect"),i=e.dom.baseEl.querySelector(".apexcharts-grid");if(!(t&&s&&i&&this._geom))return;const n=s.getBoundingClientRect(),l=i.getBoundingClientRect();if(!(n.width&&n.height&&l.width&&l.height))return;const{isVertical:r,position:a}=this._geom;if(r){const e="left"===a?l.left-n.right:n.left-l.right;if(e<16){const s=parseFloat(t.style.left)||0,i=16-e;t.style.left=s+("left"===a?-i:i)+"px"}}else{const e="top"===a?l.top-n.bottom:n.top-l.bottom;if(e<16){const s=parseFloat(t.style.top)||0,i=16-e;t.style.top=s+("top"===a?-i:i)+"px"}}}destroy(){var e,t,s,i,n,l,r;for(let s=0;s<this._bandHitEls.length;s++){const i=this._bandHitEls[s];null==(e=i.removeEventListener)||e.call(i,"mousemove",this._onBandEnter),null==(t=i.removeEventListener)||t.call(i,"mouseout",this._onBandLeave)}if(this._bandHitEls=[],this._activeBandIndex=-1,null==(s=this.ctx)?void 0:s.events)try{null==(n=(i=this.ctx.events).removeEventListener)||n.call(i,"dataPointMouseEnter",this._onCellEnter),null==(r=(l=this.ctx.events).removeEventListener)||r.call(l,"dataPointMouseLeave",this._onCellLeave)}catch(e){}}_attachBandHoverListeners(){if(m.isBrowser())for(let e=0;e<this._bandHitEls.length;e++){const t=this._bandHitEls[e];t.addEventListener("mousemove",this._onBandEnter),t.addEventListener("mouseout",this._onBandLeave)}}_onBandEnter(e){var t,s,i,n;const l=this.w,r=e.currentTarget,a=parseInt(null!=(t=r.getAttribute("data:range-index"))?t:"-1",10);a<0||a===this._activeBandIndex||(this._activeBandIndex=a,null==(n=null==(i=null==(s=this.ctx)?void 0:s.events)?void 0:i.fireEvent)||n.call(i,"legendHover",[this.ctx,a,l]),new u(l).highlightRangeInSeries(a,"highlight"))}_onBandLeave(){if(this._activeBandIndex<0)return;const e=this._activeBandIndex;this._activeBandIndex=-1,new u(this.w).highlightRangeInSeries(e,"reset")}_attachHoverListeners(){var e,t;m.isBrowser()&&(null==(t=null==(e=this.ctx)?void 0:e.events)?void 0:t.addEventListener)&&(this.ctx.events.addEventListener("dataPointMouseEnter",this._onCellEnter),this.ctx.events.addEventListener("dataPointMouseLeave",this._onCellLeave))}_onCellEnter(...e){var t,s,i;const n=this.w;if(!this.arrowEl)return;const l=e[e.length-1];if(!l||"object"!=typeof l)return;const r=l.seriesIndex,a=l.dataPointIndex;if("number"!=typeof r||"number"!=typeof a)return;if(!E.supports(n))return;let o;o=this._continuous?function(e,t,s){const i=e.config.series[t];return _(e,i&&Array.isArray(i.data)?i.data[s]:null,t,s)}(n,r,a):null==(i=null==(s=null==(t=n.seriesData)?void 0:t.series)?void 0:s[r])?void 0:i[a],null==o||Number.isNaN(o)||this._positionArrow(o)}_onCellLeave(){this.arrowEl&&(this.arrowEl.setAttribute("opacity","0"),this.hoverValueEl&&(this.hoverValueEl.style.opacity="0"))}_positionArrow(e){if(!this.arrowEl||!this._geom)return;const{isVertical:t,position:s,stripX:i,stripY:n,stripLength:l,stripThickness:r,arrowSize:a}=this._geom,o=this._min,c=this._max-o;let d;if(d=0===c?.5:(e-o)/c,d<0&&(d=0),d>1&&(d=1),t){const e=n+l-d*l;let t,o;"left"===s?(t=i+r,o=t+a):(t=i,o=t-a);const c=[`${t},${e}`,`${o},${e-a/2}`,`${o},${e+a/2}`].join(" ");this.arrowEl.setAttribute("points",c)}else{const e=i+d*l;let t,o;"top"===s?(t=n+r,o=t+a):(t=n,o=t-a);const c=[`${e},${t}`,`${e-a/2},${o}`,`${e+a/2},${o}`].join(" ");this.arrowEl.setAttribute("points",c)}if(this.arrowEl.setAttribute("opacity","1"),this.hoverValueEl){const o=this._getFormatter();if(this.hoverValueEl.textContent=o(e),t){const e=n+l-d*l;"left"===s?this.hoverValueEl.style.left=`${i+r+a+8}px`:(this.hoverValueEl.style.left=i-a-8+"px",this.hoverValueEl.style.transform="translateX(-100%)"),this.hoverValueEl.style.top=e-9+"px"}else{const e=i+d*l;this.hoverValueEl.style.left=`${e}px`,this.hoverValueEl.style.transform="translateX(-50%)",this.hoverValueEl.style.top="top"===s?`${n+r+a+8}px`:n-a-18+"px"}this.hoverValueEl.style.opacity="1"}}_buildArrow(e,t,s){const i=b.createElementNS(L,"polygon");return i.setAttribute("fill",t),i.setAttribute("opacity","0"),i.setAttribute("class","apexcharts-heatmap-gradient-arrow"),i.setAttribute("points","0,0 0,0 0,0"),i.setAttribute("pointer-events","none"),i}_computeStops(){var e,t;const s=this.w,i=E.colorScaleOf(s)||{},n=this._cfg(),l=C(s);if(l)return this._continuous=!0,{min:l.min,max:l.max,stops:l.legendStops,bands:[]};this._continuous=!1;let r=1/0,a=-1/0;const d=(null==(e=s.seriesData)?void 0:e.series)||[];for(let e=0;e<d.length;e++){const t=d[e];if(t)for(let e=0;e<t.length;e++){const s=t[e];null==s||Number.isNaN(s)||(s<r&&(r=s),s>a&&(a=s))}}Number.isFinite(r)||(r=0),Number.isFinite(a)||(a=0);let g=r,h=a;void 0!==i.min&&void 0!==i.max&&i.max>i.min?(g=i.min,h=i.max):(void 0!==i.min&&(g=i.min<r?i.min:r),void 0!==i.max&&(h=i.max>a?i.max:a));const p=[],u=[];if(i.ranges&&i.ranges.length>0){const e=i.ranges.map((e,t)=>c(o({},e),{_originalIndex:t})).sort((e,t)=>e.from-t.from),t=e[0].from,s=e[e.length-1].to;g=t,h=s;const n=s-t||1;e.forEach(e=>{const s=(e.from-t)/n,i=(e.to-t)/n;p.push({percent:(s+i)/2,color:e.color}),u.push({index:e._originalIndex,p1:s,p2:i})})}else{const e=s.globals.colors[0]||"#008FFB",i=new f,l=s.config.plotOptions[s.config.chart.type]||{},r=null!=(t=l.shadeIntensity)?t:.5,a=s.globals.hasNegs,o=Math.max(2,n.stops||16);for(let t=0;t<o;t++){const n=t/(o-1),c=g+n*(h-g),d=Math.abs(h)+Math.abs(g),u=0===d?0:100*c/d;let f;f=a?l.reverseNegativeShade?u<0?u/100*(1.25*r):1.25*r*(1-u/100):u<=0?1-(1+u/100)*r:(1-u/100)*r:1-u/100,f>1&&(f=1),f<-1&&(f=-1);const m=l.enableShades?i.shadeColor("dark"===s.config.theme.mode?-1*f:f,e):e;p.push({percent:n,color:m})}}return{min:g,max:h,stops:p,bands:u}}}const k=globalThis.ApexCharts.__internals.__apex_Markers;d.registerFeatures({legend:class{constructor(e,t){this.w=e,this.ctx=t,this.updateSeries=(...e)=>t.updateHelpers._updateSeries(...e),this.onLegendClick=this.onLegendClick.bind(this),this.onLegendHovered=this.onLegendHovered.bind(this),this.isBarsDistributed="bar"===this.w.config.chart.type&&this.w.config.plotOptions.bar.distributed&&1===this.w.config.series.length,this.legendHelpers=new x(this)}init(){const e=this.w,t=e.globals,s=e.config;this.isBarsDistributed="bar"===s.chart.type&&s.plotOptions.bar.distributed&&1===s.series.length;const i=s.legend.showForSingleSeries&&1===this.w.seriesData.series.length||this.isBarsDistributed||"heatmap"===s.chart.type||E.isEnabled(e)||this.w.seriesData.series.length>1;if(this.legendHelpers.appendToForeignObject(),(i||!t.axisCharts)&&s.legend.show){const t=e.dom.elLegendWrap;for(;t.firstChild;)t.removeChild(t.firstChild);this.heatmapGradientLegend&&(this.heatmapGradientLegend.destroy(),this.heatmapGradientLegend=null),E.isEnabled(e)?(this.heatmapGradientLegend=new E(e,this.ctx),this.heatmapGradientLegend.draw()):(this.drawLegends(),"bottom"===s.legend.position||"top"===s.legend.position?this.legendAlignHorizontal():"right"!==s.legend.position&&"left"!==s.legend.position||this.legendAlignVertical())}}createLegendMarker({i:e,fillcolor:t}){const s=this.w,i=b.createElement("span");i.classList.add("apexcharts-legend-marker");const n=s.config.legend.markers.shape||s.config.markers.shape;let l=n;Array.isArray(n)&&(l=n[e]);const r=Array.isArray(s.config.legend.markers.size)?parseFloat(s.config.legend.markers.size[e]):parseFloat(s.config.legend.markers.size),a=Array.isArray(s.config.legend.markers.offsetX)?parseFloat(s.config.legend.markers.offsetX[e]):parseFloat(s.config.legend.markers.offsetX),d=Array.isArray(s.config.legend.markers.offsetY)?parseFloat(s.config.legend.markers.offsetY[e]):parseFloat(s.config.legend.markers.offsetY),g=Array.isArray(s.config.legend.markers.strokeWidth)?parseFloat(s.config.legend.markers.strokeWidth[e]):parseFloat(s.config.legend.markers.strokeWidth),h=i.style;if(h.height=2*(r+g)+"px",h.width=2*(r+g)+"px",h.left=a+"px",h.top=d+"px",s.config.legend.markers.customHTML)h.background="transparent",h.color=t[e],Array.isArray(s.config.legend.markers.customHTML)?s.config.legend.markers.customHTML[e]&&(i.innerHTML=s.config.legend.markers.customHTML[e]()):i.innerHTML=s.config.legend.markers.customHTML();else{const n=new k(this.ctx.w,this.ctx).getMarkerConfig({cssClass:`apexcharts-legend-marker apexcharts-marker apexcharts-marker-${l}`,seriesIndex:e,strokeWidth:g,size:r}),a=(m.isBrowser()?window.SVG:global.SVG)().addTo(i).size("100%","100%"),d=new p(this.w).drawMarker(0,0,c(o({},n),{pointFillColor:Array.isArray(t)?t[e]:n.pointFillColor,shape:l}));s.dom.Paper.find(".apexcharts-legend-marker.apexcharts-marker").forEach(e=>{e.node.classList.contains("apexcharts-marker-triangle")?e.node.style.transform="translate(50%, 45%)":e.node.style.transform="translate(50%, 50%)"}),a.add(d)}return i}drawLegends(){var e;const t=this,s=this.w,i=s.dom.elLegendWrap,n=s.config.legend.fontFamily;let l=s.seriesData.seriesNames,r=s.config.legend.markers.fillColors?s.config.legend.markers.fillColors.slice():s.globals.colors.slice();if("heatmap"===s.config.chart.type){const e=s.config.plotOptions.heatmap.colorScale.ranges;l=e.map(e=>e.name?e.name:e.from+" - "+e.to),r=e.map(e=>e.color)}else this.isBarsDistributed&&(l=s.labelData.labels.slice());s.config.legend.customLegendItems.length&&(l=s.config.legend.customLegendItems);const a=s.formatters.legendFormatter,o=s.config.legend.inverseOrder,c=[];s.labelData.seriesGroups.length>1&&s.config.legend.clusterGroupedSeries&&s.labelData.seriesGroups.forEach((e,t)=>{c[t]=b.createElement("div"),c[t].classList.add("apexcharts-legend-group",`apexcharts-legend-group-${t}`),"horizontal"===s.config.legend.clusterGroupedSeriesOrientation?i.classList.add("apexcharts-legend-group-horizontal"):c[t].classList.add("apexcharts-legend-group-vertical")});for(let t=o?l.length-1:0;o?t>=0:t<=l.length-1;o?t--:t++){const o=a(l[t],{seriesIndex:t,w:s});let d=!1,h=!1;if(s.globals.collapsedSeries.length>0)for(let e=0;e<s.globals.collapsedSeries.length;e++)s.globals.collapsedSeries[e].index===t&&(d=!0);if(s.globals.ancillaryCollapsedSeriesIndices.length>0)for(let e=0;e<s.globals.ancillaryCollapsedSeriesIndices.length;e++)s.globals.ancillaryCollapsedSeriesIndices[e]===t&&(h=!0);const u=this.createLegendMarker({i:t,fillcolor:r});p.setAttrs(u,{rel:t+1,"data:collapsed":d||h}),(d||h)&&u.classList.add("apexcharts-inactive-legend");const m=b.createElement("div");if(s.config.chart.accessibility.enabled&&s.config.chart.accessibility.keyboard.enabled){m.setAttribute("role","button"),m.setAttribute("tabindex","0");const e=Array.isArray(o)?o.join(" "):o,t=d||h,s=t?"hidden":"visible";m.setAttribute("aria-label",`${e}, ${s}. Press Enter or Space to toggle.`),m.setAttribute("aria-pressed",t?"true":"false")}const x=b.createElement("span");x.classList.add("apexcharts-legend-text"),x.innerHTML=Array.isArray(o)?o.join(" "):o;let y=s.config.legend.labels.useSeriesColors?s.globals.colors[t]:Array.isArray(s.config.legend.labels.colors)?null==(e=s.config.legend.labels.colors)?void 0:e[t]:s.config.legend.labels.colors;y||(y=s.config.chart.foreColor),x.style.color=y,x.style.fontSize=s.config.legend.fontSize,x.style.fontWeight=s.config.legend.fontWeight,x.style.fontFamily=n||s.config.chart.fontFamily,p.setAttrs(x,{rel:t+1,i:t,"data:default-text":encodeURIComponent(o),"data:collapsed":d||h}),m.appendChild(u),m.appendChild(x);const v=new g(this.w);if(!s.config.legend.showForZeroSeries){0===v.getSeriesTotalByIndex(t)&&v.seriesHaveSameValues(t)&&!v.isSeriesNull(t)&&-1===s.globals.collapsedSeriesIndices.indexOf(t)&&-1===s.globals.ancillaryCollapsedSeriesIndices.indexOf(t)&&m.classList.add("apexcharts-hidden-zero-series")}s.config.legend.showForNullSeries||v.isSeriesNull(t)&&-1===s.globals.collapsedSeriesIndices.indexOf(t)&&-1===s.globals.ancillaryCollapsedSeriesIndices.indexOf(t)&&m.classList.add("apexcharts-hidden-null-series"),c.length?s.labelData.seriesGroups.forEach((e,n)=>{var l,r;e.includes(null!=(r=null==(l=s.config.series[t])?void 0:l.name)?r:"")&&(i.appendChild(c[n]),c[n].appendChild(m))}):i.appendChild(m),i.classList.add(`apexcharts-align-${s.config.legend.horizontalAlign}`),i.classList.add("apx-legend-position-"+s.config.legend.position),m.classList.add("apexcharts-legend-series"),m.style.margin=`${s.config.legend.itemMargin.vertical}px ${s.config.legend.itemMargin.horizontal}px`,i.style.width=s.config.legend.width?s.config.legend.width+"px":"",i.style.height=s.config.legend.height?s.config.legend.height+"px":"",p.setAttrs(m,{rel:t+1,seriesName:f.escapeString(l[t]),"data:collapsed":d||h}),(d||h)&&m.classList.add("apexcharts-inactive-legend"),s.config.legend.onItemClick.toggleDataSeries||m.classList.add("apexcharts-no-click")}s.dom.elWrap.addEventListener("click",t.onLegendClick,!0),s.config.legend.onItemHover.highlightDataSeries&&0===s.config.legend.customLegendItems.length&&(s.dom.elWrap.addEventListener("mousemove",t.onLegendHovered,!0),s.dom.elWrap.addEventListener("mouseout",t.onLegendHovered,!0)),s.config.chart.accessibility.enabled&&s.config.chart.accessibility.keyboard.enabled&&s.dom.elWrap.addEventListener("keydown",t.onLegendKeyDown.bind(t),!0)}setLegendWrapXY(e,t){const s=this.w,i=s.dom.elLegendWrap,n=i.clientHeight;let l=0,r=0;if("bottom"===s.config.legend.position)r=s.globals.svgHeight-Math.min(n,s.globals.svgHeight/2)-5;else if("top"===s.config.legend.position){const e=new h(this.w,this.ctx),t=e.dimHelpers.getTitleSubtitleCoords("title").height,s=e.dimHelpers.getTitleSubtitleCoords("subtitle").height;r=(t>0?t-10:0)+(s>0?s-10:0)}i.style.position="absolute",l=l+e+s.config.legend.offsetX,r=r+t+s.config.legend.offsetY,i.style.left=l+"px",i.style.top=r+"px","right"===s.config.legend.position&&(i.style.left="auto",i.style.right=25+s.config.legend.offsetX+"px");["width","height"].forEach(e=>{i&&i.style[e]&&(i.style[e]=parseInt(String(s.config.legend[e]),10)+"px")})}legendAlignHorizontal(){const e=this.w;e.dom.elLegendWrap.style.right="0";const t=new h(this.w,this.ctx),s=t.dimHelpers.getTitleSubtitleCoords("title"),i=t.dimHelpers.getTitleSubtitleCoords("subtitle");let n=0;"top"===e.config.legend.position&&(n=s.height+i.height+e.config.title.margin+e.config.subtitle.margin-10),this.setLegendWrapXY(20,n)}legendAlignVertical(){const e=this.w,t=this.legendHelpers.getLegendDimensions();let s=0;"left"===e.config.legend.position&&(s=20),"right"===e.config.legend.position&&(s=e.globals.svgWidth-t.clww-10),this.setLegendWrapXY(s,20)}onLegendHovered(e){var t;const s=this.w,i=e.target,n=i.classList.contains("apexcharts-legend-series")||i.classList.contains("apexcharts-legend-text")||i.classList.contains("apexcharts-legend-marker");if("heatmap"===s.config.chart.type||this.isBarsDistributed){if(n){const s=parseInt(null!=(t=i.getAttribute("rel"))?t:"0",10)-1;this.ctx.events.fireEvent("legendHover",[this.ctx,s,this.w]);const n=new u(this.ctx.w);"mousemove"===e.type?n.highlightRangeInSeries(s,"highlight"):"mouseout"===e.type&&n.highlightRangeInSeries(s,"reset")}}else if(!i.classList.contains("apexcharts-inactive-legend")&&n){new u(this.ctx.w).toggleSeriesOnHover(e,i)}}onLegendKeyDown(e){const t=this,s=this.w,i=e.target;if((i.classList.contains("apexcharts-legend-series")||i.classList.contains("apexcharts-legend-text")||i.classList.contains("apexcharts-legend-marker"))&&("Enter"===e.key||" "===e.key)){e.preventDefault();const n=i.getAttribute("rel");t.onLegendClick(e),null!==n&&s.config.legend.onItemClick.toggleDataSeries&&requestAnimationFrame(()=>{const e=s.dom.baseEl.querySelector(`.apexcharts-legend-series[rel="${n}"]`);e&&e.focus()})}}onLegendClick(e){var t;const s=this.w,i=e.target;if(!s.config.legend.customLegendItems.length&&(i.classList.contains("apexcharts-legend-series")||i.classList.contains("apexcharts-legend-text")||i.classList.contains("apexcharts-legend-marker"))){const e=parseInt(null!=(t=i.getAttribute("rel"))?t:"0",10)-1,n="true"===i.getAttribute("data:collapsed"),l=this.w.config.chart.events.legendClick;"function"==typeof l&&l(this.ctx,e,this.w),this.ctx.events.fireEvent("legendClick",[this.ctx,e,this.w]);const r=this.w.config.legend.markers.onClick;"function"==typeof r&&i.classList.contains("apexcharts-legend-marker")&&(r(this.ctx,e,this.w),this.ctx.events.fireEvent("legendMarkerClick",[this.ctx,e,this.w]));"treemap"!==s.config.chart.type&&"heatmap"!==s.config.chart.type&&!this.isBarsDistributed&&s.config.legend.onItemClick.toggleDataSeries&&this.legendHelpers.toggleDataSeries(e,n)}}}}),e.default=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});