UNPKG

apexcharts

Version:

A JavaScript Chart Library

6 lines (5 loc) 6.78 kB
/*! * ApexCharts v6.6.1 * (c) 2018-2026 ApexCharts */ "use strict";var e=Object.defineProperty,t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,i=(t,r,s)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s,a=(e,a)=>{for(var n in a||(a={}))r.call(a,n)&&i(e,n,a[n]);if(t)for(var n of t(a))s.call(a,n)&&i(e,n,a[n]);return e};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("apexcharts/core"),o="__apexcharts_plugins__";function l(e){return function(){const e=globalThis;return e[o]||(e[o]={}),e[o]}()[e]||null}const c=["updateOptions","updateSeries","appendData","appendSeries","toggleSeries","showSeries","hideSeries","highlightSeries","isSeriesHidden","zoomX","addXaxisAnnotation","addYaxisAnnotation","addPointAnnotation","clearAnnotations","removeAnnotation","dataURI","exportToCSV"];function d(e){const t={};return c.forEach(r=>{"function"==typeof e[r]&&(t[r]=e[r].bind(e))}),Object.freeze(t)}n.registerFeatures({weave:class{constructor(e,t){this.w=e,this.ctx=t,this.active=[],this._layers=new Map,this._currentScales=null,this._lastPluginsRef=null,this._lastData=null,this._updatedWired=!1,this._onUpdated=this._onUpdated.bind(this),this._init()}_init(){(this.w.config.plugins||[]).map((e,t)=>({entry:e,order:null!=e.order?e.order:t})).sort((e,t)=>e.order-t.order).forEach(e=>this._activate(e.entry)),this._lastPluginsRef=this.w.config.plugins,this._wireUpdated()}_wireUpdated(){this._updatedWired||(this.ctx.addEventListener("updated",this._onUpdated),this._updatedWired=!0)}_onUpdated(){this.dispatch("afterUpdate",{pass:"update"})}_activate(e){const t=l(e.name);if(!t)return;const r=null!=t.apiVersion?t.apiVersion:1;if(1!==Math.trunc(r))return;const s={def:t,options:Object.freeze(a({},e.options||{})),handlers:new Map,disabled:!1,failures:0,api:null};s.api=function(e,t){const r=e.ctx,s=e.w,i={name:t.def.name,version:1,get options(){return t.options},on(e,r){const s=t.handlers;return s.has(e)||s.set(e,[]),s.get(e).push(r),i},off(e,r){const s=t.handlers.get(e);if(s){const e=s.indexOf(r);e>-1&&s.splice(e,1)}return i},store:{},layer:r=>e._layer(t.def.name,r||{}),get scales(){return e._currentScales},get data(){return e._lastData||(e._lastData=e._dataSnapshot())},theme:Object.freeze({get mode(){return s.config.theme.mode},get foreColor(){return s.config.chart.foreColor},seriesColor:e=>s.globals.colors[e],token:t=>e._token(t)}),chart:d(r),emit(e,s){r.events.fireEvent(`plugin:${t.def.name}:${e}`,[r,s])},get el(){return s.dom.baseEl}};return Object.freeze(i)}(this,s),this.active.push(s),this._guard(s,"setup",()=>t.setup(s.api))}dispatch(e,t){if("draw"===e&&(this._reconcile(),this._resetLayers()),this._lastData=null,!this.active.length)return;"afterParse"===e?this._currentScales=null:t&&"xyRatios"in t&&this._setScales(t.xyRatios);const r=t&&t.pass||"full";let s=null;for(const t of this.active){if(t.disabled)continue;const i=t.handlers.get(e);if(!i||!i.length)continue;null===s&&(s=this._dataSnapshot(),this._lastData=s);const a={api:t.api,scales:this._currentScales,data:s,pass:r,hook:e};for(const r of i.slice())this._guard(t,e,()=>r(a))}}_guard(e,t,r){if(!e.disabled)try{r()}catch(t){e.failures=(e.failures||0)+1,e.failures>=3&&(e.disabled=!0)}}_setScales(e){const t=this.w,r=t.globals,s=t.layout;if(!e||!r.axisCharts)return void(this._currentScales=null);const i=e.xRatio,a=e.yRatio||[],n=e=>null!=r.maxYArr[e]?r.maxYArr[e]:r.maxY,o=e=>null!=r.minYArr[e]?r.minYArr[e]:r.minY;this._currentScales={x:e=>s.translateX+(e-r.minX)/i,y:(e,t=0)=>s.translateY+(n(t)-e)/(e=>null!=a[e]?a[e]:a[0])(t),domainX:[r.minX,r.maxX],domainY:(e=0)=>[o(e),n(e)],gridWidth:s.gridWidth,gridHeight:s.gridHeight,ratios:e}}_dataSnapshot(){const e=this.w,t=e.globals,r=e.seriesData.series||[],s=e.seriesData.seriesX||[];return r.map((e,r)=>{const i=s[r]||[],a=(e||[]).map((e,t)=>({x:null!=i[t]?i[t]:t,y:e}));return{name:t.seriesNames?t.seriesNames[r]:void 0,hidden:(t.collapsedSeriesIndices||[]).includes(r),color:t.colors?t.colors[r]:void 0,points:a}})}_token(e){const t=this.w,r=t.globals;switch(e){case"foreColor":return t.config.chart.foreColor;case"background":return t.config.chart.background;case"accent":case"primary":return r.colors?r.colors[0]:void 0;default:return/^series-\d+$/.test(e)&&r.colors?r.colors[Number(e.split("-")[1])]:void 0}}_layer(e,{z:t="front",className:r=""}={}){let s=this._layers.get(e);if(!s){s=this.ctx.graphics.group({class:`apexcharts-plugin-${e} ${r}`.trim()});const i=this.w.dom.elGraphical.node;"behind"===t?i.insertBefore(s.node,i.firstChild):i.appendChild(s.node),s.node.setAttribute("aria-hidden","true"),this._layers.set(e,s)}return function(e,t){const r=t=>(t&&e.add(t),t),s={get node(){return e.node},path(e={}){const{d:s="",stroke:i="#000",width:a=1,fill:n="none",opacity:o=1,dash:l=0,className:c=""}=e;return r(t.drawPath({d:s,stroke:i,strokeWidth:a,fill:n,fillOpacity:"none"===n?0:o,strokeOpacity:o,strokeDashArray:l,classes:c}))},line(e={}){const{x1:s,y1:i,x2:a,y2:n,stroke:o="#000",width:l=1,dash:c=0}=e;return r(t.drawLine(s,i,a,n,o,c,l))},rect(e={}){const{x:s=0,y:i=0,w:a=0,h:n=0,r:o=0,fill:l="#000",stroke:c=null,opacity:d=1}=e;return r(t.drawRect(s,i,a,n,o,l,d,null!=c?1:null,c))},circle(e={}){const{cx:s=0,cy:i=0,r:a=0,fill:n="#000",stroke:o=null}=e;return r(t.drawCircle(a,{cx:s,cy:i,fill:n,stroke:o||"none"}))},text(e={}){const{x:s=0,y:i=0,text:a="",color:n,size:o,anchor:l="start",weight:c}=e;return r(t.drawText({x:s,y:i,text:a,textAnchor:l,fontSize:o,foreColor:n,fontWeight:c}))},clear(){const t=e.node;for(;t.firstChild;)t.removeChild(t.firstChild);return s}};return s}(s,this.ctx.graphics)}_resetLayers(){const e=this.w.dom.elGraphical,t=e&&e.node;if(t){const e=t.querySelectorAll('g[class*="apexcharts-plugin-"]');Array.prototype.forEach.call(e,e=>e.remove())}this._layers.clear()}_reconcile(){const e=this.w.config.plugins||[];if(e===this._lastPluginsRef)return;this._lastPluginsRef=e;const t=new Map(e.map((e,t)=>[e.name,{entry:e,order:null!=e.order?e.order:t}]));for(let e=this.active.length-1;e>=0;e--){const r=this.active[e],s=t.get(r.def.name);s?r.options=Object.freeze(a({},s.entry.options||{})):(this._guard(r,"destroy",()=>r.def.destroy&&r.def.destroy(r.api)),this.active.splice(e,1))}const r=new Set(this.active.map(e=>e.def.name)),s=[];t.forEach((e,t)=>{r.has(t)||s.push(e)}),s.sort((e,t)=>e.order-t.order).forEach(e=>this._activate(e.entry))}teardown(e){if(!e){this.dispatch("destroy");for(const e of this.active)this._guard(e,"destroy",()=>e.def.destroy&&e.def.destroy(e.api));this.active=[],this._updatedWired&&(this.ctx.removeEventListener&&this.ctx.removeEventListener("updated",this._onUpdated),this._updatedWired=!1)}this._layers.clear()}}}),exports.default=n;