apexcharts
Version:
A JavaScript Chart Library
6 lines (5 loc) • 9.41 kB
JavaScript
/*!
* ApexCharts v6.6.1
* (c) 2018-2026 ApexCharts
*/
"use strict";var t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("apexcharts/core");function s(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const i in t)if("default"!==i){const n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:()=>t[i]})}return e.default=t,Object.freeze(e)}const o=s(n),r=o.__apex_Utils,a=o.__apex_Environment_Environment;function l(t,e){const i=null!=t,n=null!=e;return i||n?{min:i?t:null,max:n?e:null}:null}function c(t){return Array.isArray(t)?t.map(t=>Array.isArray(t)?t.slice():t):[]}function h(t,e){return"function"==typeof t&&e?t===e.addXaxisAnnotation?"xaxis":t===e.addYaxisAnnotation?"yaxis":t===e.addPointAnnotation?"point":null:null}function d(t,e){const i=t.config.annotations?r.clone(t.config.annotations):null,n=[],s=t.globals.memory&&t.globals.memory.methodsToExec||[];for(const t of s){if(!t||"addAnnotation"!==t.label)continue;const i=h(t.method,e);i&&n.push({kind:i,params:r.clone(t.params)})}return{static:i,dynamic:n}}function u(t){const e=t&&t.measure;if(!e||"function"!=typeof e.getPins)return null;const i=e.getPins();return Array.isArray(i)&&i.length?{pins:i}:null}function _(t,e){if(!t||!e)return;const i=t.w;i.interact.zoomed=!!e.zoomed,function(t,e,i){const n=t.w;if(null==e&&null==i)return;const s=n.globals.seriesNames||[],o=new Set([...e||[],...i||[]]),r=new Set([...n.globals.collapsedSeriesIndices||[],...n.globals.ancillaryCollapsedSeriesIndices||[]]);for(let e=0;e<s.length;e++){const i=s[e];if(null==i)continue;const n=o.has(e),a=r.has(e);n&&!a?t.hideSeries(i):!n&&a&&t.showSeries(i)}}(t,e.collapsed,e.ancillaryCollapsed),e.annotations&&Array.isArray(e.annotations.dynamic)&&e.annotations.dynamic.forEach(e=>{const i=function(t){switch(t){case"xaxis":return"addXaxisAnnotation";case"yaxis":return"addYaxisAnnotation";case"point":return"addPointAnnotation";default:return null}}(e.kind);i&&"function"==typeof t[i]&&t[i](e.params,!0)}),function(t,e){Array.isArray(e)&&(t.w.interact.selectedDataPoints=c(e))}(t,e.selectedDataPoints),e.locale&&e.locale!==i.config.chart.defaultLocale&&t.setLocale(e.locale),t.measure&&"function"==typeof t.measure.setPins&&t.measure.setPins(e.measure&&e.measure.pins||[])}n.registerFeatures({history:class{constructor(t,e){this.w=t,this.ctx=e,this.stack=[],this.pointer=-1,this.applying=!1,this._batching=!1,this._counter=0,this._coalesceTimer=null,this._settleTimer=null,this._pendingLabel=void 0,this._keydownTarget=null,this._pointerTarget=null,this._engaged=!1,this._wired=!1,this._readConfig(),this._onMounted=this._onMounted.bind(this),this._onUpdated=this._onUpdated.bind(this),this._onSelection=this._onSelection.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onPointerDown=this._onPointerDown.bind(this),this.init()}_readConfig(){const t=this.w,e=t.config.chart&&t.config.chart.history||{};this.enabled=!!e.enabled,this.maxDepth=e.maxDepth>0?e.maxDepth:100,this.coalesceMs=null!=e.coalesceMs?e.coalesceMs:250,this.keyboard=!1!==e.keyboard}_syncConfig(){this._readConfig(),this.enabled&&this.keyboard?this._wireKeyboard():this._unwireKeyboard()}init(){this._wired||(this._wired=!0,this.ctx.addEventListener("mounted",this._onMounted),this.ctx.addEventListener("updated",this._onUpdated),this.ctx.addEventListener("scrolled",this._onUpdated),this.ctx.addEventListener("dataPointSelection",this._onSelection),this.enabled&&this.keyboard&&this._wireKeyboard())}_wireKeyboard(){if(this._keydownTarget)return;const t=this.ctx.el,e=t&&t.ownerDocument;a.isBrowser()&&e&&(e.addEventListener("keydown",this._onKeyDown),e.addEventListener("pointerdown",this._onPointerDown,!0),e.addEventListener("mousedown",this._onPointerDown,!0),this._keydownTarget=e,this._pointerTarget=e)}_unwireKeyboard(){this._keydownTarget&&(this._keydownTarget.removeEventListener("keydown",this._onKeyDown),this._keydownTarget=null),this._pointerTarget&&(this._pointerTarget.removeEventListener("pointerdown",this._onPointerDown,!0),this._pointerTarget.removeEventListener("mousedown",this._onPointerDown,!0),this._pointerTarget=null),this._engaged=!1}_onMounted(){this._syncConfig(),this.enabled&&0===this.stack.length&&this._commit("initial",!0)}_onUpdated(){this._syncConfig(),this.enabled&&(this.applying?this._refreshSettle():this._schedule("update"))}_onSelection(){this.enabled&&!this.applying&&this._schedule("selection")}_onPointerDown(t){const e=this.ctx.el;this._engaged=!!(e&&t.target&&e.contains(t.target))}_onKeyDown(t){if(!t.metaKey&&!t.ctrlKey)return;const e=(t.key||"").toLowerCase();if("z"!==e&&"y"!==e)return;const i=this.ctx.el;if(!i)return;const n=i.ownerDocument,s=n&&n.activeElement;if(function(t){if(!t)return!1;const e=t.tagName;return"INPUT"===e||"TEXTAREA"===e||"SELECT"===e||!0===t.isContentEditable}(s))return;if(!i.contains(s)&&!this._engaged)return;const o="y"===e||t.shiftKey;t.preventDefault(),o?this.redo():this.undo()}_schedule(t){this.applying||this._batching||!this.enabled||(this._pendingLabel=t,this.coalesceMs>0&&a.isBrowser()?(clearTimeout(this._coalesceTimer),this._coalesceTimer=setTimeout(()=>this._commit(this._pendingLabel),this.coalesceMs)):this._commit(t))}_commit(t,e){if(clearTimeout(this._coalesceTimer),this._coalesceTimer=null,!e&&(this.applying||this._batching))return;const i=this._capture(t),n=this.stack[this.pointer];if(!n||n.sig!==i.sig){for(this.pointer<this.stack.length-1&&this.stack.splice(this.pointer+1),this.stack.push(i),this.pointer=this.stack.length-1;this.stack.length>this.maxDepth;)this.stack.shift(),this.pointer--;this._emitChange()}}_capture(t){const e=function(t,e){var i,n;const s=t.config.xaxis||{},o=(Array.isArray(t.config.yaxis)?t.config.yaxis:t.config.yaxis?[t.config.yaxis]:[]).map(t=>l(t&&t.min,t&&t.max)),r=o.some(t=>null!==t),a=t.config.theme,h=e&&e.drilldown;return{v:1,window:{xaxis:l(s.min,s.max),yaxis:r?o:null},zoomed:!!t.interact.zoomed,collapsed:(t.globals.collapsedSeriesIndices||[]).slice(),ancillaryCollapsed:(t.globals.ancillaryCollapsedSeriesIndices||[]).slice(),selectedDataPoints:c(t.interact.selectedDataPoints),theme:a?{mode:null!=(i=a.mode)?i:null,palette:null!=(n=a.palette)?n:null}:null,locale:t.config.chart&&t.config.chart.defaultLocale||null,annotations:d(t,e),drill:h&&h.depth>0?{path:h.path.slice()}:null,measure:u(e)}}(this.w,this.ctx),{config:i,seriesSig:n}=this._cloneConfigCOW();return{id:"hist-"+ ++this._counter,view:e,config:i,seriesSig:n,label:t||"change",at:a.isBrowser()?Date.now():0,origin:"local",sig:this._signature(e,i)}}_cloneConfigCOW(){const n=this.w,s=this.stack[this.pointer];let o,a=null;try{a=JSON.stringify(n.config.series)}catch(t){a=null}if(s&&null!==a&&s.seriesSig===a){const a=n.config,{series:l}=a,c=((n,s)=>{var o={};for(var r in n)e.call(n,r)&&s.indexOf(r)<0&&(o[r]=n[r]);if(null!=n&&t)for(var r of t(n))s.indexOf(r)<0&&i.call(n,r)&&(o[r]=n[r]);return o})(a,["series"]);o=r.clone(c),o.series=s.config.series}else o=r.clone(n.config);return{config:o,seriesSig:a}}_signature(t,e){try{return JSON.stringify(t)+"|"+JSON.stringify(e)}catch(t){return`nosig-${this._counter}`}}_restore(t,e){if(!t)return;let i;this.applying=!0;try{this.ctx.clearAnnotations(),i=this.ctx.updateOptions(r.clone(t.config),!1,e,!1,!1)}catch(t){throw this.applying=!1,t}Promise.resolve(i).then(()=>{_(this.ctx,t.view),this._refreshSettle(),this._emitChange()}).catch(()=>{this.applying=!1})}_refreshSettle(){a.isBrowser()?(clearTimeout(this._settleTimer),this._settleTimer=setTimeout(()=>{this.applying=!1},0)):this.applying=!1}snapshot(t){this.enabled&&!this.applying&&this._commit(t||"change")}undo(t=!0){this.canUndo()&&(this.pointer--,this._restore(this.stack[this.pointer],t))}redo(t=!0){this.canRedo()&&(this.pointer++,this._restore(this.stack[this.pointer],t))}canUndo(){return this.pointer>0}canRedo(){return this.pointer>-1&&this.pointer<this.stack.length-1}jump(t,e=!0){const i=this.stack.findIndex(e=>e.id===t);-1!==i&&i!==this.pointer&&(this.pointer=i,this._restore(this.stack[i],e))}clear(){clearTimeout(this._coalesceTimer),this._coalesceTimer=null;const t=this.stack[this.pointer];this.stack=t?[t]:[],this.pointer=this.stack.length-1,this._emitChange()}transaction(t,e={}){if("function"!=typeof t)return Promise.resolve();const i=this._batching;return this._batching=!0,Promise.resolve().then(()=>t()).finally(()=>{this._batching=i,i||this._commit(e.label||"transaction",!0)})}entries(){return this.stack.map(t=>({id:t.id,label:t.label,at:t.at}))}state(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),index:this.pointer,length:this.stack.length}}_emitChange(){this.ctx.events.fireEvent("historyChange",[this.ctx,this.state()])}teardown(){var t,e,i,n,s,o,r,a;clearTimeout(this._coalesceTimer),clearTimeout(this._settleTimer),this._coalesceTimer=null,this._settleTimer=null,this._unwireKeyboard(),this._wired&&(null==(e=(t=this.ctx).removeEventListener)||e.call(t,"mounted",this._onMounted),null==(n=(i=this.ctx).removeEventListener)||n.call(i,"updated",this._onUpdated),null==(o=(s=this.ctx).removeEventListener)||o.call(s,"scrolled",this._onUpdated),null==(a=(r=this.ctx).removeEventListener)||a.call(r,"dataPointSelection",this._onSelection)),this.stack=[],this.pointer=-1,this._wired=!1}}}),exports.default=n;