apexcharts
Version:
A JavaScript Chart Library
6 lines (5 loc) • 10.5 kB
JavaScript
/*!
* ApexCharts v7.0.0
* (c) 2018-2026 ApexCharts
*/
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ApexStats={})}(this,function(t){"use strict";var r=Object.defineProperty,e=Object.defineProperties,n=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,a=(t,e,n)=>e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,l=(t,r)=>{for(var e in r||(r={}))i.call(r,e)&&a(t,e,r[e]);if(s)for(var e of s(r))o.call(r,e)&&a(t,e,r[e]);return t},u=(t,r)=>e(t,n(r));const c=globalThis.ApexCharts,f=globalThis.ApexCharts.__internals.__apex_Utils,h="__apexcharts_series_transforms__";function d(t,r){t&&"string"==typeof t?"function"==typeof r?globalThis[h][t]=r:console.warn(`ApexCharts: registerSeriesTransform("${t}") expects a function (series, w) => series.`):console.warn("ApexCharts: registerSeriesTransform requires a non-empty name.")}globalThis[h]||(globalThis[h]={});const g="__apexcharts_row_sources__";function p(t,r){t&&"string"==typeof t?"function"==typeof r?globalThis[g][t]=r:console.warn(`ApexCharts: registerRowSource("${t}") expects a function (w, opts) => series.`):console.warn("ApexCharts: registerRowSource requires a non-empty name.")}globalThis[g]||(globalThis[g]={});function y(t,r){const e=t.length;if(0===e)return NaN;if(1===e)return t[0];const n=(e-1)*r,s=Math.floor(n),i=Math.ceil(n);return s===i?t[s]:t[s]+(t[i]-t[s])*(n-s)}function m(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 s=0;for(let e=0;e<r;e++){const r=t[e]-n;s+=r*r}return Math.sqrt(s/r)}function b(t,r={}){if(!Array.isArray(t)||0===t.length)return null;const e=t.slice().sort((t,r)=>t-r);let n=e[0],s=e[e.length-1];const i=r.range;if(Array.isArray(i)&&2===i.length){const t=Number(i[0]),r=Number(i[1]);isFinite(t)&&isFinite(r)&&r>t&&(n=t,s=r)}if(!(s>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 o=s-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=o/Math.floor(r.bins),l="count";else{const t=function(t,r,e){const n=t.length,s=t=>r/Math.max(1,Math.ceil(t));switch(e){case"sqrt":return{width:s(Math.sqrt(n)),rule:"sqrt"};case"rice":return{width:s(2*Math.cbrt(n)),rule:"rice"};case"scott":{const r=m(t);return r>0?{width:3.49*r*Math.pow(n,-1/3),rule:"scott"}:{width:s(Math.log2(n)+1),rule:"sturges"}}case"fd":{const r=y(t,.75)-y(t,.25);return r>0?{width:2*r*Math.pow(n,-1/3),rule:"fd"}:{width:s(Math.log2(n)+1),rule:"sturges"}}case"auto":{const r=s(Math.log2(n)+1),e=y(t,.75)-y(t,.25);if(e<=0)return{width:r,rule:"sturges"};const i=2*e*Math.pow(n,-1/3);return i<r?{width:i,rule:"fd"}:{width:r,rule:"sturges"}}default:return{width:s(Math.log2(n)+1),rule:"sturges"}}}(e,o,"string"==typeof r.bins?r.bins:"auto");a=t.width,l=t.rule}(!isFinite(a)||a<=0)&&(a=o);let u=Math.ceil(o/a);(!isFinite(u)||u<1)&&(u=1);let c=!1;u>1e3&&(u=1e3,a=o/u,c=!0),a=o/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],s),{edges:f,binWidth:a,rule:l,capped:c}}function w(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 s=Math.floor((t-r[0])/n);return s<0&&(s=0),s>e-1&&(s=e-1),t<r[s]?s--:t>=r[s+1]&&s++,s<0||s>e-1?-1:s}let s=0,i=e-1;for(;s<=i;){const e=s+i>>1;if(t<r[e])i=e-1;else{if(!(t>=r[e+1]))return e;s=e+1}}return-1}function A(t){const r=[];if(!Array.isArray(t))return r;for(let e=0;e<t.length;e++){const n=t[e];let s=n;Array.isArray(n)?s=1===n.length?n[0]:n[1]:n&&"object"==typeof n&&(s=void 0!==n.y?n.y:n.x);const i=f.parseNumber(s);null!==i&&isFinite(i)&&r.push(i)}return r}function v(t,r){var e;const n=r.config,s=r.globals;if(!Array.isArray(t))return t;s.histogramRawSeries||(s.histogramRawSeries=t.map(t=>u(l({},t),{data:Array.isArray(null==t?void 0:t.data)?t.data.slice():null==t?void 0:t.data})));const i=s.histogramRawSeries,o=(null==(e=n.plotOptions)?void 0:e.histogram)||{},a=i.map(t=>A(null==t?void 0:t.data));let c=[];if(1===a.length)c=a[0];else for(const t of a)c=c.concat(t);const f=b(c,{bins:o.bins,binWidth:o.binWidth,range:o.range});if(!f)return r.histogramData={edges:[],binWidth:0,counts:[],rule:"",capped:!1},i;const{edges:h,binWidth:d}=f,g=a.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 s=w(t[n],r);s>=0&&e[s]++}return e}(t,h));r.histogramData={edges:h,binWidth:d,counts:g,rule:f.rule,capped:f.capped};const p=s.collapsedSeriesIndices||[];return i.map((t,r)=>{if(-1!==p.indexOf(r))return u(l({},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:o.normalize,cumulative:o.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 u(l({},t),{data:n})})}const x=new WeakSet;function M(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 s=[];for(let t=0;t<n.length;t++){const r=f.parseNumber(n[t]);null!==r&&isFinite(r)&&s.push(r)}return s.length?s:null}function S(t,r){var e,n;if(!Array.isArray(t))return t;const s=(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&&!x.has(t))return t;const e=M(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=y(e,.25),s=y(e,.5),i=y(e,.75),o=i-n;let a=e[0],l=e[e.length-1],u=[];if("tukey"===r.whiskers&&o>0){const t=n-1.5*o,r=i+1.5*o;let s=0;for(;s<e.length&&e[s]<t;)s++;let c=e.length-1;for(;c>=0&&e[c]>r;)c--;s<=c&&(a=e[s],l=e[c],u=e.slice(0,s).concat(e.slice(c+1)))}return{summary:[a,n,s,i,l],outliers:u,iqr:o}}(e,{whiskers:s});if(!n)return t;r=!0;const i=u(l({},t),{y:n.summary,points:e});return x.add(i),i});return r?u(l({},t),{data:e}):t})}function _(t,r){var e,n;if(!Array.isArray(t))return t;const s=(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&&!x.has(t))return t;const n=M(t,!0);if(!n)return t;const i=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 s=r.bandwidth;if(!("number"==typeof s&&s>0)){const t=m(e),r=y(e,.75)-y(e,.25);s=.9*(r>0?Math.min(t,r/1.349):t)*Math.pow(n,-.2)}if(!isFinite(s)||s<=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 i=Math.max(8,Math.floor(r.resolution||64)),o=e[0]-2*s,a=(e[n-1]+2*s-o)/(i-1),l=1/(n*s*Math.sqrt(2*Math.PI)),u=[];for(let t=0;t<i;t++){const r=o+t*a;let i=0;for(let t=0;t<n;t++){const n=(r-e[t])/s;i+=Math.exp(-.5*n*n)}u.push([r,i*l])}return{density:u,bandwidth:s}}(n,{bandwidth:s.bandwidth,resolution:s.resolution});if(!i)return t;r=!0;const o=u(l({},t),{y:{density:i.density,points:n}});return x.add(o),o});return r?u(l({},t),{data:e}):t})}function $(t,r,e){const n=e&&null!=e.maxRows?e.maxRows:3e3,s=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 s=r=>{let e=0;for(const n of t)e+=Math.ceil(n.length/r);return e};let i=Math.max(2,Math.ceil(e/r));for(;i<n&&s(i)>r;)i++;let o=0;return{clusters:t.map(t=>{const r=[];for(let e=0;e<t.length;e+=i)r.push(t[e]);return o+=r.length,r}),stride:i,total:e,kept:o}}(r.map(t=>t.rows),n);s.stride>1&&console.warn(`ApexCharts: rowSeries() thinned ${s.total} rows to ${s.kept} (every ${s.stride}${2===s.stride?"nd":3===s.stride?"rd":"th"} row) to stay under maxRows=${n}. Raise maxRows to draw more.`);const i=t.globals&&t.globals.colors||[];return r.map((t,r)=>{const e=i[t.realIndex]||i[0];return{name:t.name,data:s.clusters[r].map((n,s)=>l({id:`${t.realIndex}:${r}:${s}`,x:t.name,y:n},e?{fillColor:e}:{}))}})}function O(t,r){const e=t.globals,n=t.histogramData,s=e&&e.histogramRawSeries;if(!n||!Array.isArray(n.edges)||n.edges.length<2)return null;if(!Array.isArray(s)||!s.length)return null;const i=e&&e.collapsedSeriesIndices||[],o=n.edges,a=[];return s.forEach((r,e)=>{var n;if(-1!==i.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 s=w(t[e],r);s>=0&&n[s].push(t[e])}return n}(A(r&&r.data),o),u=t.seriesData&&(null==(n=t.seriesData.seriesNames)?void 0:n[e])||(null==r?void 0:r.name);l.forEach((t,r)=>{const n=`${T(o[r])}-${T(o[r+1])}`;a.push({name:s.length>1&&u?`${u} ${n}`:n,realIndex:e,rows:t})})}),a.length?$(t,a,r):null}function T(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 P(t){return(r,e)=>{var n;const s=t(r);if(!Array.isArray(s)||!s.length)return null;const i=r.globals&&r.globals.collapsedSeriesIndices||[],o=r.globals&&((null==(n=r.globals.categoryLabels)?void 0:n.length)?r.globals.categoryLabels:r.globals.labels)||[],a=[];return s.forEach((t,e)=>{var n;if(-1!==i.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!=o[r]?String(o[r]):`#${r+1}`;a.push({name:s.length>1&&l?`${l} ${n}`:n,realIndex:e,rows:Array.isArray(t)?t.slice():[]})})}),a.length?$(r,a,e):null}}const R=P(t=>{var r;return null==(r=t.candleData)?void 0:r.seriesBoxPoints}),W=P(t=>{var r;return null==(r=t.violinData)?void 0:r.seriesViolinPoints});d("histogram",v),d("boxPlot",S),d("violin",_),p("histogram",O),p("boxPlot",R),p("violin",W),t.boxPlotRows=R,t.boxPlotTransform=S,t.default=c,t.histogramRows=O,t.histogramTransform=v,t.violinRows=W,t.violinTransform=_,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});