UNPKG

apexcharts

Version:

A JavaScript Chart Library

6 lines (5 loc) 10.2 kB
/*! * ApexCharts v7.0.0 * (c) 2018-2026 ApexCharts */ "use strict";var t=Object.defineProperty,r=Object.defineProperties,e=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,s=(r,e,n)=>e in r?t(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,a=(t,r)=>{for(var e in r||(r={}))i.call(r,e)&&s(t,e,r[e]);if(n)for(var e of n(r))o.call(r,e)&&s(t,e,r[e]);return t},l=(t,n)=>r(t,e(n));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function u(t){if(t&&t.__esModule)return t;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const e in t)if("default"!==e){const n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,n.get?n:{enumerable:!0,get:()=>t[e]})}return r.default=t,Object.freeze(r)}const c=u(require("apexcharts/core")),f=c.__apex_Utils,h="__apexcharts_series_transforms__";function d(t,r){t&&"string"==typeof t&&"function"==typeof r&&(globalThis[h][t]=r)}globalThis[h]||(globalThis[h]={});const g="__apexcharts_row_sources__";function y(t,r){t&&"string"==typeof t&&"function"==typeof r&&(globalThis[g][t]=r)}globalThis[g]||(globalThis[g]={});function p(t,r){const e=t.length;if(0===e)return NaN;if(1===e)return t[0];const n=(e-1)*r,i=Math.floor(n),o=Math.ceil(n);return i===o?t[i]:t[i]+(t[o]-t[i])*(n-i)}function b(t){const r=t.length;if(r<2)return 0;let e=0;for(let n=0;n<r;n++)e+=t[n];const n=e/r;let i=0;for(let e=0;e<r;e++){const r=t[e]-n;i+=r*r}return Math.sqrt(i/r)}function m(t,r={}){if(!Array.isArray(t)||0===t.length)return null;const e=t.slice().sort((t,r)=>t-r);let n=e[0],i=e[e.length-1];const o=r.range;if(Array.isArray(o)&&2===o.length){const t=Number(o[0]),r=Number(o[1]);isFinite(t)&&isFinite(r)&&r>t&&(n=t,i=r)}if(!(i>n)){const t=Math.abs(n)>0?.05*Math.abs(n):.5;return{edges:[n-t,n+t],binWidth:2*t,rule:"single",capped:!1}}const s=i-n;let a,l;if("number"==typeof r.binWidth&&r.binWidth>0)a=r.binWidth,l="binWidth";else if("number"==typeof r.bins&&r.bins>=1)a=s/Math.floor(r.bins),l="count";else{const t=function(t,r,e){const n=t.length,i=t=>r/Math.max(1,Math.ceil(t));switch(e){case"sqrt":return{width:i(Math.sqrt(n)),rule:"sqrt"};case"rice":return{width:i(2*Math.cbrt(n)),rule:"rice"};case"scott":{const r=b(t);return r>0?{width:3.49*r*Math.pow(n,-1/3),rule:"scott"}:{width:i(Math.log2(n)+1),rule:"sturges"}}case"fd":{const r=p(t,.75)-p(t,.25);return r>0?{width:2*r*Math.pow(n,-1/3),rule:"fd"}:{width:i(Math.log2(n)+1),rule:"sturges"}}case"auto":{const r=i(Math.log2(n)+1),e=p(t,.75)-p(t,.25);if(e<=0)return{width:r,rule:"sturges"};const o=2*e*Math.pow(n,-1/3);return o<r?{width:o,rule:"fd"}:{width:r,rule:"sturges"}}default:return{width:i(Math.log2(n)+1),rule:"sturges"}}}(e,s,"string"==typeof r.bins?r.bins:"auto");a=t.width,l=t.rule}(!isFinite(a)||a<=0)&&(a=s);let u=Math.ceil(s/a);(!isFinite(u)||u<1)&&(u=1);let c=!1;u>1e3&&(u=1e3,a=s/u,c=!0),a=s/u;const f=new Array(u+1);for(let t=0;t<=u;t++)f[t]=n+t*a;return f[u]=Math.max(f[u],i),{edges:f,binWidth:a,rule:l,capped:c}}function A(t,r){const e=r.length-1;if(!(t>=r[0])||t>r[e])return-1;if(t===r[e])return e-1;const n=(r[e]-r[0])/e;if(n>0){let i=Math.floor((t-r[0])/n);return i<0&&(i=0),i>e-1&&(i=e-1),t<r[i]?i--:t>=r[i+1]&&i++,i<0||i>e-1?-1:i}let i=0,o=e-1;for(;i<=o;){const e=i+o>>1;if(t<r[e])o=e-1;else{if(!(t>=r[e+1]))return e;i=e+1}}return-1}function v(t){const r=[];if(!Array.isArray(t))return r;for(let e=0;e<t.length;e++){const n=t[e];let i=n;Array.isArray(n)?i=1===n.length?n[0]:n[1]:n&&"object"==typeof n&&(i=void 0!==n.y?n.y:n.x);const o=f.parseNumber(i);null!==o&&isFinite(o)&&r.push(o)}return r}function w(t,r){var e;const n=r.config,i=r.globals;if(!Array.isArray(t))return t;i.histogramRawSeries||(i.histogramRawSeries=t.map(t=>l(a({},t),{data:Array.isArray(null==t?void 0:t.data)?t.data.slice():null==t?void 0:t.data})));const o=i.histogramRawSeries,s=(null==(e=n.plotOptions)?void 0:e.histogram)||{},u=o.map(t=>v(null==t?void 0:t.data));let c=[];if(1===u.length)c=u[0];else for(const t of u)c=c.concat(t);const f=m(c,{bins:s.bins,binWidth:s.binWidth,range:s.range});if(!f)return r.histogramData={edges:[],binWidth:0,counts:[],rule:"",capped:!1},o;const{edges:h,binWidth:d}=f,g=u.map(t=>function(t,r){const e=new Array(Math.max(0,r.length-1)).fill(0);for(let n=0;n<t.length;n++){const i=A(t[n],r);i>=0&&e[i]++}return e}(t,h));r.histogramData={edges:h,binWidth:d,counts:g,rule:f.rule,capped:f.capped};const y=i.collapsedSeriesIndices||[];return o.map((t,r)=>{if(-1!==y.indexOf(r))return l(a({},t),{data:[]});const e=function(t,r={}){let e=t.slice();if(r.cumulative){let t=0;e=e.map(r=>t+=r)}const n=t.reduce((t,r)=>t+r,0);if(n<=0)return e;if("relative"===r.normalize)return e.map(t=>t/n*100);if("density"===r.normalize){const t=r.binWidth;if("number"==typeof t&&t>0)return e.map(r=>r/(n*t))}return e}(g[r],{normalize:s.normalize,cumulative:s.cumulative,binWidth:d}),n=[];for(let t=0;t<e.length;t++)n.push({x:(h[t]+h[t+1])/2,y:e[t]});return l(a({},t),{data:n})})}const M=new WeakSet;function x(t,r){var e;if(!t||"object"!=typeof t||Array.isArray(t))return null;let n=null;if(Array.isArray(t.points)?n=t.points:Array.isArray(null==(e=t.y)?void 0:e.points)?n=t.y.points:r&&Array.isArray(t.y)&&"number"==typeof t.y[0]&&(n=t.y),!n)return null;const i=[];for(let t=0;t<n.length;t++){const r=f.parseNumber(n[t]);null!==r&&isFinite(r)&&i.push(r)}return i.length?i:null}function O(t,r){var e,n;if(!Array.isArray(t))return t;const i=(null==(n=null==(e=r.config.plotOptions)?void 0:e.boxPlot)?void 0:n.whiskers)||"minmax";return t.map(t=>{if(!Array.isArray(null==t?void 0:t.data))return t;let r=!1;const e=t.data.map(t=>{if(Array.isArray(null==t?void 0:t.y)&&5===t.y.length&&!M.has(t))return t;const e=x(t,!1);if(!e)return t;const n=function(t,r={}){if(!Array.isArray(t)||0===t.length)return null;const e=t.slice().sort((t,r)=>t-r),n=p(e,.25),i=p(e,.5),o=p(e,.75),s=o-n;let a=e[0],l=e[e.length-1],u=[];if("tukey"===r.whiskers&&s>0){const t=n-1.5*s,r=o+1.5*s;let i=0;for(;i<e.length&&e[i]<t;)i++;let c=e.length-1;for(;c>=0&&e[c]>r;)c--;i<=c&&(a=e[i],l=e[c],u=e.slice(0,i).concat(e.slice(c+1)))}return{summary:[a,n,i,o,l],outliers:u,iqr:s}}(e,{whiskers:i});if(!n)return t;r=!0;const o=l(a({},t),{y:n.summary,points:e});return M.add(o),o});return r?l(a({},t),{data:e}):t})}function _(t,r){var e,n;if(!Array.isArray(t))return t;const i=(null==(n=null==(e=r.config.plotOptions)?void 0:e.violin)?void 0:n.kde)||{};return t.map(t=>{if(!Array.isArray(null==t?void 0:t.data))return t;let r=!1;const e=t.data.map(t=>{var e;if(Array.isArray(null==(e=null==t?void 0:t.y)?void 0:e.density)&&t.y.density.length&&!M.has(t))return t;const n=x(t,!0);if(!n)return t;const o=function(t,r={}){if(!Array.isArray(t)||0===t.length)return null;const e=t.slice().sort((t,r)=>t-r),n=e.length;let i=r.bandwidth;if(!("number"==typeof i&&i>0)){const t=b(e),r=p(e,.75)-p(e,.25);i=.9*(r>0?Math.min(t,r/1.349):t)*Math.pow(n,-.2)}if(!isFinite(i)||i<=0){const t=e[0],r=Math.abs(t)>0?.001*Math.abs(t):.001;return{density:[[t-r,0],[t,1],[t+r,0]],bandwidth:r}}const o=Math.max(8,Math.floor(r.resolution||64)),s=e[0]-2*i,a=(e[n-1]+2*i-s)/(o-1),l=1/(n*i*Math.sqrt(2*Math.PI)),u=[];for(let t=0;t<o;t++){const r=s+t*a;let o=0;for(let t=0;t<n;t++){const n=(r-e[t])/i;o+=Math.exp(-.5*n*n)}u.push([r,o*l])}return{density:u,bandwidth:i}}(n,{bandwidth:i.bandwidth,resolution:i.resolution});if(!o)return t;r=!0;const s=l(a({},t),{y:{density:o.density,points:n}});return M.add(s),s});return r?l(a({},t),{data:e}):t})}function P(t,r,e){const n=e&&null!=e.maxRows?e.maxRows:3e3,i=function(t,r){let e=0,n=0;for(const r of t)e+=r.length,r.length>n&&(n=r.length);if(e<=r)return{clusters:t,stride:1,total:e,kept:e};const i=r=>{let e=0;for(const n of t)e+=Math.ceil(n.length/r);return e};let o=Math.max(2,Math.ceil(e/r));for(;o<n&&i(o)>r;)o++;let s=0;return{clusters:t.map(t=>{const r=[];for(let e=0;e<t.length;e+=o)r.push(t[e]);return s+=r.length,r}),stride:o,total:e,kept:s}}(r.map(t=>t.rows),n);i.stride;const o=t.globals&&t.globals.colors||[];return r.map((t,r)=>{const e=o[t.realIndex]||o[0];return{name:t.name,data:i.clusters[r].map((n,i)=>a({id:`${t.realIndex}:${r}:${i}`,x:t.name,y:n},e?{fillColor:e}:{}))}})}function S(t,r){const e=t.globals,n=t.histogramData,i=e&&e.histogramRawSeries;if(!n||!Array.isArray(n.edges)||n.edges.length<2)return null;if(!Array.isArray(i)||!i.length)return null;const o=e&&e.collapsedSeriesIndices||[],s=n.edges,a=[];return i.forEach((r,e)=>{var n;if(-1!==o.indexOf(e))return;const l=function(t,r){const e=Math.max(0,r.length-1),n=new Array(e);for(let t=0;t<e;t++)n[t]=[];for(let e=0;e<t.length;e++){const i=A(t[e],r);i>=0&&n[i].push(t[e])}return n}(v(r&&r.data),s),u=t.seriesData&&(null==(n=t.seriesData.seriesNames)?void 0:n[e])||(null==r?void 0:r.name);l.forEach((t,r)=>{const n=`${j(s[r])}-${j(s[r+1])}`;a.push({name:i.length>1&&u?`${u} ${n}`:n,realIndex:e,rows:t})})}),a.length?P(t,a,r):null}function j(t){if(!isFinite(t))return String(t);const r=Math.round(t);return Math.abs(t-r)<1e-6?String(r):String(Number(t.toFixed(2)))}function W(t){return(r,e)=>{var n;const i=t(r);if(!Array.isArray(i)||!i.length)return null;const o=r.globals&&r.globals.collapsedSeriesIndices||[],s=r.globals&&((null==(n=r.globals.categoryLabels)?void 0:n.length)?r.globals.categoryLabels:r.globals.labels)||[],a=[];return i.forEach((t,e)=>{var n;if(-1!==o.indexOf(e))return;if(!Array.isArray(t))return;const l=r.seriesData&&(null==(n=r.seriesData.seriesNames)?void 0:n[e]);t.forEach((t,r)=>{const n=null!=s[r]?String(s[r]):`#${r+1}`;a.push({name:i.length>1&&l?`${l} ${n}`:n,realIndex:e,rows:Array.isArray(t)?t.slice():[]})})}),a.length?P(r,a,e):null}}const D=W(t=>{var r;return null==(r=t.candleData)?void 0:r.seriesBoxPoints}),T=W(t=>{var r;return null==(r=t.violinData)?void 0:r.seriesViolinPoints});d("histogram",w),d("boxPlot",O),d("violin",_),y("histogram",S),y("boxPlot",D),y("violin",T),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>c.default}),exports.boxPlotRows=D,exports.boxPlotTransform=O,exports.histogramRows=S,exports.histogramTransform=w,exports.violinRows=T,exports.violinTransform=_;