apexcharts
Version:
A JavaScript Chart Library
6 lines (5 loc) • 18.1 kB
JavaScript
/*!
* ApexCharts v5.10.6
* (c) 2018-2026 ApexCharts
*/
"use strict";var e=Object.defineProperty,t=Object.defineProperties,s=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,l=(t,s,n)=>s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("apexcharts/core");function o(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const s in e)if("default"!==s){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}return t.default=e,Object.freeze(t)}const c=o(r),d=c.__apex_CoreUtils,g=c.__apex_dimensions_Dimensions,p=c.__apex_Graphics,h=c.__apex_Series,f=c.__apex_Utils,x=c.__apex_Environment_Environment;class u{constructor(e){this.w=e.w,this.lgCtx=e}getLegendStyles(){if(x.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,n;const i=this.w;if(i.globals.axisCharts||"radialBar"===i.config.chart.type){i.globals.resized=!0;let a=null,l=null;if(i.globals.risingSeries=[],i.globals.axisCharts){if(a=i.dom.baseEl.querySelector(`.apexcharts-series[data\\:realIndex='${e}']`),!a)return;l=parseInt(null!=(s=a.getAttribute("data:realIndex"))?s:"",10)}else{if(a=i.dom.baseEl.querySelector(`.apexcharts-series[rel='${e+1}']`),!a)return;l=parseInt(null!=(n=a.getAttribute("rel"))?n:"",10)-1}if(t){[{cs:i.globals.collapsedSeries,csi:i.globals.collapsedSeriesIndices},{cs:i.globals.ancillaryCollapsedSeries,csi:i.globals.ancillaryCollapsedSeriesIndices}].forEach(e=>{const t=e.cs,s=e.csi;this.riseCollapsedSeries(t,s,l)})}else this.hideSeries({seriesEl:a,realIndex:l});if(i.config.chart.accessibility.enabled){const t=i.dom.baseEl.querySelector(`.apexcharts-legend-series[rel="${e+1}"]`);if(t){const s=i.globals.collapsedSeriesIndices.includes(l)||i.globals.ancillaryCollapsedSeriesIndices.includes(l);t.setAttribute("aria-pressed",s?"true":"false");const n=t.querySelector(".apexcharts-legend-text"),a=n?n.textContent:i.seriesData.seriesNames[e],r=s?"hidden":"visible";t.setAttribute("aria-label",`${a}, ${r}. Press Enter or Space to toggle.`)}}}else{const t=i.dom.Paper.findOne(` .apexcharts-series[rel='${e+1}'] path`),s=i.config.chart.type;if("pie"===s||"polarArea"===s||"donut"===s){const e=i.config.plotOptions.pie.donut.labels;new p(this.w).pathMouseDown(t,null),this.lgCtx.printDataLabelsInner(t.node,e)}if(i.config.chart.accessibility.enabled){const t=i.dom.baseEl.querySelector(`.apexcharts-legend-series[rel="${e+1}"]`);if(t){const s=i.globals.collapsedSeriesIndices.includes(e);t.setAttribute("aria-pressed",s?"true":"false");const n=t.querySelector(".apexcharts-legend-text"),a=n?n.textContent:i.seriesData.seriesNames[e],l=s?"hidden":"visible";t.setAttribute("aria-label",`${a}, ${l}. Press Enter or Space to toggle.`)}}}}getSeriesAfterCollapsing({realIndex:e}){var t;const s=this.w,n=s.globals,i=f.clone(s.config.series);if(n.axisCharts){const t=s.config.yaxis[n.seriesYAxisReverseMap[e]],a={index:e,data:i[e].data.slice(),type:i[e].type||s.config.chart.type};if(t&&t.show&&t.showAlways)n.ancillaryCollapsedSeriesIndices.indexOf(e)<0&&(n.ancillaryCollapsedSeries.push(a),n.ancillaryCollapsedSeriesIndices.push(e));else if(n.collapsedSeriesIndices.indexOf(e)<0){n.collapsedSeries.push(a),n.collapsedSeriesIndices.push(e);const t=n.risingSeries.indexOf(e);n.risingSeries.splice(t,1)}}else n.collapsedSeries.push({index:e,data:i[e],type:null!=(t=s.config.series[e].type)?t:"line"}),n.collapsedSeriesIndices.push(e);return n.allSeriesCollapsed=n.collapsedSeries.length+n.ancillaryCollapsedSeries.length===s.config.series.length,this._getSeriesBasedOnCollapsedState(i)}hideSeries({seriesEl:e,realIndex:t}){const s=this.w,n=this.getSeriesAfterCollapsing({realIndex:t}),i=e.childNodes;for(let e=0;e<i.length;e++)i[e].classList.contains("apexcharts-series-markers-wrap")&&(i[e].classList.contains("apexcharts-hide")?i[e].classList.remove("apexcharts-hide"):i[e].classList.add("apexcharts-hide"));this.lgCtx.updateSeries(n,s.config.chart.animations.dynamicAnimation.enabled)}riseCollapsedSeries(e,t,s){const n=this.w;let i=f.clone(n.config.series);if(e.length>0){for(let a=0;a<e.length;a++)e[a].index===s&&(n.globals.axisCharts?i[s].data=e[a].data.slice():i[s]=e[a].data,"number"!=typeof i[s]&&(i[s].hidden=!1),e.splice(a,1),t.splice(a,1),n.globals.risingSeries.push(s),a--);i=this._getSeriesBasedOnCollapsedState(i),this.lgCtx.updateSeries(i,n.config.chart.animations.dynamicAnimation.enabled)}}_getSeriesBasedOnCollapsedState(e){const t=this.w;let s=0;return t.globals.axisCharts?e.forEach((n,i)=>{t.globals.collapsedSeriesIndices.indexOf(i)<0&&t.globals.ancillaryCollapsedSeriesIndices.indexOf(i)<0||(e[i].data=[],s++)}):e.forEach((n,i)=>{t.globals.collapsedSeriesIndices.indexOf(i)<0||(e[i]=0,s++)}),t.globals.allSeriesCollapsed=s===e.length,e}}const m=c.__apex_Markers,b=c.__apex_BrowserAPIs_BrowserAPIs;r.registerFeatures({legend:class{constructor(e,t){this.w=e,this.ctx=t,this.printDataLabelsInner=(...e)=>{var s;return null==(s=t.pie)?void 0:s.printDataLabelsInner(...e)},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 u(this)}init(){const e=this.w,t=e.globals,s=e.config,n=s.legend.showForSingleSeries&&1===this.w.seriesData.series.length||this.isBarsDistributed||this.w.seriesData.series.length>1;if(this.legendHelpers.appendToForeignObject(),(n||!t.axisCharts)&&s.legend.show){const t=e.dom.elLegendWrap;for(;t.firstChild;)t.removeChild(t.firstChild);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:r}){const o=this.w,c=b.createElement("span");c.classList.add("apexcharts-legend-marker");const d=o.config.legend.markers.shape||o.config.markers.shape;let g=d;Array.isArray(d)&&(g=d[e]);const h=Array.isArray(o.config.legend.markers.size)?parseFloat(o.config.legend.markers.size[e]):parseFloat(o.config.legend.markers.size),f=Array.isArray(o.config.legend.markers.offsetX)?parseFloat(o.config.legend.markers.offsetX[e]):parseFloat(o.config.legend.markers.offsetX),u=Array.isArray(o.config.legend.markers.offsetY)?parseFloat(o.config.legend.markers.offsetY[e]):parseFloat(o.config.legend.markers.offsetY),y=Array.isArray(o.config.legend.markers.strokeWidth)?parseFloat(o.config.legend.markers.strokeWidth[e]):parseFloat(o.config.legend.markers.strokeWidth),S=c.style;if(S.height=2*(h+y)+"px",S.width=2*(h+y)+"px",S.left=f+"px",S.top=u+"px",o.config.legend.markers.customHTML)S.background="transparent",S.color=r[e],Array.isArray(o.config.legend.markers.customHTML)?o.config.legend.markers.customHTML[e]&&(c.innerHTML=o.config.legend.markers.customHTML[e]()):c.innerHTML=o.config.legend.markers.customHTML();else{const d=new m(this.ctx.w,this.ctx).getMarkerConfig({cssClass:`apexcharts-legend-marker apexcharts-marker apexcharts-marker-${g}`,seriesIndex:e,strokeWidth:y,size:h}),f=(x.isBrowser()?window.SVG:global.SVG)().addTo(c).size("100%","100%"),u=new p(this.w).drawMarker(0,0,(w=((e,t)=>{for(var s in t||(t={}))i.call(t,s)&&l(e,s,t[s]);if(n)for(var s of n(t))a.call(t,s)&&l(e,s,t[s]);return e})({},d),L={pointFillColor:Array.isArray(r)?r[e]:d.pointFillColor,shape:g},t(w,s(L))));o.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%)"}),f.add(u)}var w,L;return c}drawLegends(){var e;const t=this,s=this.w,n=s.dom.elLegendWrap,i=s.config.legend.fontFamily;let a=s.seriesData.seriesNames,l=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;a=e.map(e=>e.name?e.name:e.from+" - "+e.to),l=e.map(e=>e.color)}else this.isBarsDistributed&&(a=s.labelData.labels.slice());s.config.legend.customLegendItems.length&&(a=s.config.legend.customLegendItems);const r=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?n.classList.add("apexcharts-legend-group-horizontal"):c[t].classList.add("apexcharts-legend-group-vertical")});for(let t=o?a.length-1:0;o?t>=0:t<=a.length-1;o?t--:t++){const o=r(a[t],{seriesIndex:t,w:s});let g=!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&&(g=!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 x=this.createLegendMarker({i:t,fillcolor:l});p.setAttrs(x,{rel:t+1,"data:collapsed":g||h}),(g||h)&&x.classList.add("apexcharts-inactive-legend");const u=b.createElement("div");if(s.config.chart.accessibility.enabled&&s.config.chart.accessibility.keyboard.enabled){u.setAttribute("role","button"),u.setAttribute("tabindex","0");const e=Array.isArray(o)?o.join(" "):o,t=g||h,s=t?"hidden":"visible";u.setAttribute("aria-label",`${e}, ${s}. Press Enter or Space to toggle.`),u.setAttribute("aria-pressed",t?"true":"false")}const m=b.createElement("span");m.classList.add("apexcharts-legend-text"),m.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),m.style.color=y,m.style.fontSize=s.config.legend.fontSize,m.style.fontWeight=s.config.legend.fontWeight,m.style.fontFamily=i||s.config.chart.fontFamily,p.setAttrs(m,{rel:t+1,i:t,"data:default-text":encodeURIComponent(o),"data:collapsed":g||h}),u.appendChild(x),u.appendChild(m);const S=new d(this.w);if(!s.config.legend.showForZeroSeries){0===S.getSeriesTotalByIndex(t)&&S.seriesHaveSameValues(t)&&!S.isSeriesNull(t)&&-1===s.globals.collapsedSeriesIndices.indexOf(t)&&-1===s.globals.ancillaryCollapsedSeriesIndices.indexOf(t)&&u.classList.add("apexcharts-hidden-zero-series")}s.config.legend.showForNullSeries||S.isSeriesNull(t)&&-1===s.globals.collapsedSeriesIndices.indexOf(t)&&-1===s.globals.ancillaryCollapsedSeriesIndices.indexOf(t)&&u.classList.add("apexcharts-hidden-null-series"),c.length?s.labelData.seriesGroups.forEach((e,i)=>{var a,l;e.includes(null!=(l=null==(a=s.config.series[t])?void 0:a.name)?l:"")&&(n.appendChild(c[i]),c[i].appendChild(u))}):n.appendChild(u),n.classList.add(`apexcharts-align-${s.config.legend.horizontalAlign}`),n.classList.add("apx-legend-position-"+s.config.legend.position),u.classList.add("apexcharts-legend-series"),u.style.margin=`${s.config.legend.itemMargin.vertical}px ${s.config.legend.itemMargin.horizontal}px`,n.style.width=s.config.legend.width?s.config.legend.width+"px":"",n.style.height=s.config.legend.height?s.config.legend.height+"px":"",p.setAttrs(u,{rel:t+1,seriesName:f.escapeString(a[t]),"data:collapsed":g||h}),(g||h)&&u.classList.add("apexcharts-inactive-legend"),s.config.legend.onItemClick.toggleDataSeries||u.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,n=s.dom.elLegendWrap,i=n.clientHeight;let a=0,l=0;if("bottom"===s.config.legend.position)l=s.globals.svgHeight-Math.min(i,s.globals.svgHeight/2)-5;else if("top"===s.config.legend.position){const e=new g(this.w,this.ctx),t=e.dimHelpers.getTitleSubtitleCoords("title").height,s=e.dimHelpers.getTitleSubtitleCoords("subtitle").height;l=(t>0?t-10:0)+(s>0?s-10:0)}n.style.position="absolute",a=a+e+s.config.legend.offsetX,l=l+t+s.config.legend.offsetY,n.style.left=a+"px",n.style.top=l+"px","right"===s.config.legend.position&&(n.style.left="auto",n.style.right=25+s.config.legend.offsetX+"px");["width","height"].forEach(e=>{n&&n.style[e]&&(n.style[e]=parseInt(String(s.config.legend[e]),10)+"px")})}legendAlignHorizontal(){const e=this.w;e.dom.elLegendWrap.style.right="0";const t=new g(this.w,this.ctx),s=t.dimHelpers.getTitleSubtitleCoords("title"),n=t.dimHelpers.getTitleSubtitleCoords("subtitle");let i=0;"top"===e.config.legend.position&&(i=s.height+n.height+e.config.title.margin+e.config.subtitle.margin-10),this.setLegendWrapXY(20,i)}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,n=e.target,i=n.classList.contains("apexcharts-legend-series")||n.classList.contains("apexcharts-legend-text")||n.classList.contains("apexcharts-legend-marker");if("heatmap"===s.config.chart.type||this.isBarsDistributed){if(i){const s=parseInt(null!=(t=n.getAttribute("rel"))?t:"0",10)-1;this.ctx.events.fireEvent("legendHover",[this.ctx,s,this.w]);new h(this.ctx.w).highlightRangeInSeries(e,n)}}else if(!n.classList.contains("apexcharts-inactive-legend")&&i){new h(this.ctx.w).toggleSeriesOnHover(e,n)}}onLegendKeyDown(e){const t=this,s=this.w,n=e.target;if((n.classList.contains("apexcharts-legend-series")||n.classList.contains("apexcharts-legend-text")||n.classList.contains("apexcharts-legend-marker"))&&("Enter"===e.key||" "===e.key)){e.preventDefault();const i=n.getAttribute("rel");t.onLegendClick(e),null!==i&&s.config.legend.onItemClick.toggleDataSeries&&requestAnimationFrame(()=>{const e=s.dom.baseEl.querySelector(`.apexcharts-legend-series[rel="${i}"]`);e&&e.focus()})}}onLegendClick(e){var t;const s=this.w,n=e.target;if(!s.config.legend.customLegendItems.length&&(n.classList.contains("apexcharts-legend-series")||n.classList.contains("apexcharts-legend-text")||n.classList.contains("apexcharts-legend-marker"))){const e=parseInt(null!=(t=n.getAttribute("rel"))?t:"0",10)-1,i="true"===n.getAttribute("data:collapsed"),a=this.w.config.chart.events.legendClick;"function"==typeof a&&a(this.ctx,e,this.w),this.ctx.events.fireEvent("legendClick",[this.ctx,e,this.w]);const l=this.w.config.legend.markers.onClick;"function"==typeof l&&n.classList.contains("apexcharts-legend-marker")&&(l(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,i)}}}}),exports.default=r;