ag-charts-core
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
2 lines (1 loc) • 17.5 kB
JavaScript
var Ne=Object.defineProperty,ne=(e,t)=>{for(var n in t)Ne(e,n,{get:t[n],enumerable:!0})},re={};ne(re,{error:()=>ie,errorOnce:()=>Be,log:()=>Te,logGroup:()=>ze,reset:()=>Re,table:()=>Ve,warn:()=>oe,warnOnce:()=>Ge});var P=new Set;function Te(...e){console.log(...e)}function oe(e,...t){console.warn(`AG Charts - ${e}`,...t)}function ie(e,...t){typeof e=="object"?console.error("AG Charts error",e,...t):console.error(`AG Charts - ${e}`,...t)}function Ve(...e){console.table(...e)}function Ge(e,...t){const n=`Logger.warn: ${e}`;P.has(n)||(oe(e,...t),P.add(n))}function Be(e,...t){const n=`Logger.error: ${e}`;P.has(n)||(ie(e,...t),P.add(n))}function Re(){P.clear()}function ze(e,t){console.groupCollapsed(e);try{return t()}finally{console.groupEnd()}}var se={};ne(se,{detectChartDefinition:()=>He,getAxisModule:()=>Je,getSeriesModule:()=>Ze,hasModule:()=>_e,listModulesByType:()=>Ke,register:()=>ue,registerMany:()=>Ue,reset:()=>We});var ae=(e=>(e.Axis="axis",e.Chart="chart",e.Preset="preset",e.Plugin="plugin",e.Series="series",e))(ae||{}),S=new Map;function ue(e){const t=S.get(e.name);if(t&&(t.enterprise||!e.enterprise))throw new Error(`AG Charts - Module '${e.name}' already registered`);S.set(e.name,e)}function Ue(e){for(const t of e)ue(t)}function We(){S.clear()}function _e(e){return S.has(e)}function*Ke(e){for(const t of S.values())t.type===e&&(yield t)}function He(e){for(const t of S.values())if(Le(t)&&t.detect(e))return t;throw new Error("AG Charts - Unknown chart type; Check options are correctly structured and series types are specified")}function Ze(e){const t=S.get(e);if(Ye(t))return t}function Je(e){const t=S.get(e);if(Xe(t))return t}function Le(e){return e?.type==="chart"}function Xe(e){return e?.type==="axis"}function Ye(e){return e?.type==="series"}var Qe=class{constructor(){this.events=new Map}on(e,t){return this.events.has(e)||this.events.set(e,new Set),this.events.get(e)?.add(t),()=>this.off(e,t)}off(e,t){const n=this.events.get(e);n&&(n.delete(t),n.size===0&&this.events.delete(e))}emit(e,t){this.events.get(e)?.forEach(n=>n(t))}clear(e){e?this.events.delete(e):this.events.clear()}};function le(e,t="and",n=String,r=1/0){if(e.length===1)return n(e[0]);e=e.map(n);const o=e.pop();if(e.length>=r){const i=e.length-(r-1);return`${e.slice(0,r-1).join(", ")}, and ${i} more ${t} ${o}`}return`${e.join(", ")} ${t} ${o}`}function ce(e,t=1/0){if(typeof e=="number"){if(isNaN(e))return"NaN";if(e===1/0)return"Infinity";if(e===-1/0)return"-Infinity"}const n=JSON.stringify(e)??typeof e;return n.length>t?`${n.slice(0,t)}... (+${n.length-t} characters)`:n}function et(e){let t=1;for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t++;return t}function fe(e,t){if(e===t)return 0;const[n,r]=e.length<t.length?[e,t]:[t,e],o=n.length,i=r.length;let s=new Array(o+1).fill(0).map((l,u)=>u),a=new Array(o+1);for(let l=1;l<=i;l++){a[0]=l;for(let u=1;u<=o;u++){const d=r[l-1]===n[u-1]?0:1;a[u]=Math.min(s[u]+1,a[u-1]+1,s[u-1]+d)}[s,a]=[a,s]}return s[o]}var m={};typeof window<"u"?m.window=window:typeof global<"u"&&(m.window=global.window),typeof document<"u"?m.document=document:typeof global<"u"&&(m.document=global.document);function N(e){return e?m.document?.[e]:m.document}function de(e){return e?m.window?.[e]:m.window}function tt(e){m.document=e}function nt(e){m.window=e}function pe(e,t,n){const r=N().createElement(e);if(typeof t=="object"&&(n=t,t=void 0),t)for(const o of t.split(" "))r.classList.add(o);return n&&Object.assign(r.style,n),r}function rt(e){return N().createElementNS("http://www.w3.org/2000/svg",e)}function ot(e,t){const n=N("body"),r=pe("a",{display:"none"});r.href=e,r.download=t,n.appendChild(r),r.click(),setTimeout(()=>n.removeChild(r))}function he(e){const t=de("Option"),{style:n}=new t;return n.color=e,n.color||null}function ge(e){return e!=null}function O(e){return Array.isArray(e)}function ye(e){return typeof e=="boolean"}function J(e){return e instanceof Date}function L(e){return J(e)&&!isNaN(Number(e))}function it(e){return e instanceof RegExp}function q(e){return typeof e=="function"}function T(e){return typeof e=="object"&&e!==null&&!O(e)}function st(e){return O(e)||be(e)}function be(e){return typeof e=="object"&&e!==null&&e.constructor?.name==="Object"}function j(e){return typeof e=="string"}function at(e){return typeof e=="number"}function E(e){return Number.isFinite(e)}function ut(e){return typeof window<"u"&&e instanceof HTMLElement}function lt(e,t){return j(t)&&Object.keys(e).includes(t)}function ct(e,t){return Object.values(e).includes(t)}function ft(e){return typeof e=="symbol"}function we(e){return j(e)&&he(e)!=null}var C=Symbol("description"),me=Symbol("required"),V=class{constructor(e,t,n,r){this.message=e,this.path=t,this.required=n,this.unknown=r}toString(){return this.message}};function F(e,t,n=""){if(!T(e)){const l=$e(n,e,"an object",!0);return{valid:null,errors:[new V(l,n,!0)]}}const r=[],o=new Set(Object.keys(e)),i=[],s={};function a(l){return O(t)?`${n}[${l}]`:n?`${n}.${l}`:l}for(const l of Object.keys(t)){const u=t[l],d=e[l],w=u[me];if(o.delete(l),typeof d>"u"&&(r.push(l),!w))continue;const v=a(l);if(q(u)){const h={options:e,path:v};if(u(d,h))s[l]=h.result?.valid??d;else if(!h.result){const x=$e(v,d,u,w);i.push(new V(x,n,w))}h.result&&i.push(...h.result.errors)}else{const h=F(d,u,v);h.valid!=null&&(s[l]=h.valid),i.push(...h.errors)}}for(const l of o){if(typeof e[l]>"u")continue;const d=dt(l,a(l),r);i.push(new V(d,n,void 0,!0))}return{valid:s,errors:i}}function $e(e,t,n,r){const o=j(n)?n:n[C],i=o?`; expecting ${o}`:"",s=e?`Option \`${e}\``:"Value";return r&&t==null?`${s} is required and has not been provided${i}, ignoring.`:`${s} cannot be set to \`${ce(t,50)}\`${i}, ignoring.`}function dt(e,t,n){const r=pt(e,n),o=r?`; Did you mean \`${r}\`? Ignoring.`:", ignoring.";return`Unknown option \`${t}\`${o}`}function pt(e,t,n=2){let r=1/0;const o=e.toLowerCase();return t.reduce((i,s)=>{const a=fe(o,s.toLowerCase());return r>a&&a<=n?(r=a,s):i},null)}function c(e,t){return Object.assign(q(e)?(n,r)=>e(n,r):{...e},{[C]:t})}function f(e){return Object.assign(q(e)?(t,n)=>e(t,n):A(e),{[me]:!0,[C]:e[C]})}var A=(e,t="an object")=>c((n,r)=>(r.result=F(n,e,r.path),!r.result.errors.some(o=>o.required&&o.path===r.path)),t),ve=(e,t="an object")=>c((n,r)=>(r.result=F(n,e,r.path),r.result.errors=r.result.errors.filter(o=>!o.unknown),!r.result.errors.some(o=>o.required&&o.path===r.path)),t),G=(...e)=>c((t,n)=>e.every(r=>{const o=r(t,n);return n.result&&!o&&delete n.result,o}),e.map(t=>t[C]).filter(Boolean).join(" and ")),B=(...e)=>c((t,n)=>e.some(r=>{const o=r(t,n);return n.result&&!o&&delete n.result,o}),e.map(t=>t[C]).filter(Boolean).join(" or ")),R=e=>E(e)||L(e),ht=e=>J(e)||(E(e)||j(e))&&L(new Date(e)),gt=c(O,"an array"),z=c(ye,"a boolean"),yt=c(q,"a function"),b=c(we,"a color string"),bt=c(ht,"a date"),wt=c(ge,"a defined value"),k=c(E,"a number"),mt=c(T,"an object"),Me=c(j,"a string"),X=(e,t=1/0)=>{let n;return t===1/0?n=`an array of at least ${e} items`:e===t?n=`an array of exactly ${e} items`:e===0?n=`an array of no more than ${t} items`:n=`an array of at least ${e} and no more than ${t} items`,c(r=>O(r)&&r.length>=e&&r.length<=t,n)},Y=(e,t=!0)=>c(n=>E(n)&&(n>e||t&&n===e),`a number greater than ${t?"or equal to ":""}${e}`),Se=(e,t)=>c(n=>E(n)&&n>=e&&n<=t,`a number between ${e} and ${t} inclusive`),g=Y(0),$t=Y(0,!1),M=Se(0,1),vt=e=>c((t,{options:n})=>!R(t)||!R(n[e])||t<n[e],`the value to be less than \`${e}\``),Mt=e=>c((t,{options:n})=>!R(t)||!R(n[e])||t>n[e],`the value to be greater than \`${e}\``);function $(...e){T(e[0])&&(e=Object.values(e[0]));const t=le(e,"or",n=>`'${n}'`);return c(n=>e.includes(n),`a keyword such as ${t}`)}var U=e=>c(t=>e===t,`the value ${JSON.stringify(e)}`),St=(e,t)=>c(n=>n instanceof e,t??`an instance of ${e.name}`),W=(e,t)=>c((n,r)=>O(n)&&n.every(o=>{const i=e(o,r);return delete r.result,i}),t??`${e[C]} array`),Ot=(e,t="an object array")=>c((n,r)=>{if(!O(n))return!1;const o=[],i=[];for(let s=0;s<n.length;s++){const a=`${r.path}[${s}]`,l=F(n[s],e,a);i.push(...l.errors),l.errors.some(u=>u.required&&u.path===a)||o.push(l.valid)}return r.result={valid:o,errors:i},!0},t),Q=(e,t="an object")=>{const n=ve({type:f($(...Object.keys(e)))});return c((r,o)=>{if(n(r,o)){const i=r.type,s={type:f(U(i)),...e[i]},a=A(s)(r,o);if(o.result)for(const l of o.result.errors)l.message+=` (type="${i}")`;return a}return!1},t)},jt=A({color:b,stop:M},""),Ct=c(e=>{let t=-1/0;for(const n of e)if(n?.stop!=null){if(n.stop<t)return!1;t=n.stop}return!0},"color stops to be defined in ascending order"),_=G(X(2),G(W(jt),Ct)),ee=$("axis","item","series"),kt=Q({gradient:{gradient:$("linear","radial","conic"),bounds:ee,colorStops:f(_),rotation:k,reverse:z}},"a gradient object with color stops"),Oe={stroke:b,strokeWidth:g,strokeOpacity:M},je=A({type:f(U("gradient")),gradient:f($("linear","radial","conic")),bounds:f(ee),colorStops:f(B(_,G(X(2),W(b)))),rotation:f(k),reverse:f(z)}),Ce=A({type:f(U("pattern")),pattern:f($("vertical-lines","horizontal-lines","forward-slanted-lines","backward-slanted-lines","circles","squares","triangles","diamonds","stars","hearts","crosses")),width:f(g),height:f(g),fill:f(b),fillOpacity:f(M),backgroundFill:f(b),backgroundFillOpacity:f(M),padding:f(g),rotation:f(k),stroke:f(b),strokeWidth:f(g),strokeOpacity:f(M)}),xt={gradient:$("linear","radial","conic"),bounds:ee,reverse:z},Et={rotation:k,padding:g},At=Q({gradient:{...xt,colorStops:_,rotation:k},pattern:{...Et,pattern:$("vertical-lines","horizontal-lines","forward-slanted-lines","backward-slanted-lines","circles","squares","triangles","diamonds","stars","hearts","crosses"),width:g,height:g,fill:b,fillOpacity:M,backgroundFill:b,backgroundFillOpacity:M,...Oe}},"a color object"),ke=B(b,At),te={fill:ke,fillOpacity:M};te.fillGradientDefaults=je,te.fillPatternDefaults=Ce;var It={lineDash:W(g),lineDashOffset:k},Dt={color:b,fontFamily:Me,fontSize:g,fontStyle:$("normal","italic","oblique"),fontWeight:B(g,$("normal","bold","bolder","lighter"))};function Pt(e){return typeof e>"u"?[]:Array.isArray(e)?e:[e]}function qt(e){return Array.from(new Set(e))}function Ft(e,t){return e.reduce((n,r)=>{const o=t(r);return n[o]??(n[o]=[]),n[o].push(r),n},{})}function xe(e,t){if(e==null||t==null||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(Array.isArray(e[n])&&Array.isArray(t[n])){if(!xe(e[n],t[n]))return!1}else if(e[n]!==t[n])return!1;return!0}function Nt(e,t,n=0){if(e.length===0)return[];const r=[];for(let o=0;o<t;o++)r.push(e.at((o+n)%e.length));return r}function Tt(e,t){const n=new Map;return t.forEach((r,o)=>{n.set(r,o)}),e.sort((r,o)=>{const i=n.get(r)??1/0,s=n.get(o)??1/0;return i-s})}function Vt(e,t,n){if(e>t)return;let r;for(;t>=e;){const o=Math.floor((t+e)/2);n(o)?(r=o,e=o+1):t=o-1}return r}function Gt(e,t,n){if(e>t)return;let r;for(;t>=e;){const o=Math.floor((t+e)/2);n(o)?(r=o,t=o-1):e=o+1}return r}function Bt(e,t,n){if(e>t)return;let r;for(;t>=e;){const o=Math.floor((t+e)/2),i=n(o);i==null?t=o-1:(r=i,e=o+1)}return r}function Rt(e,t,n){if(e>t)return;let r;for(;t>=e;){const o=Math.floor((t+e)/2),i=n(o);i==null?e=o+1:(r=i,t=o-1)}return r}function zt(e,t){const n=Math.max(e.length,t.length),r=new Set,o=new Set;for(let i=0;i<n;i++){const s=e[i],a=t[i];s!==a&&(o.has(a)?o.delete(a):a&&r.add(a),r.has(s)?r.delete(s):s&&o.add(s))}return{changed:r.size>0||o.size>0,added:r,removed:o}}function Ut(e,t=0,n){const{leading:r=!1,trailing:o=!0,maxWait:i=1/0}=n??{};let s,a;if(i<t)throw new Error("Value of maxWait cannot be lower than waitMs.");function l(...u){if(r&&!a){a=Date.now(),s=setTimeout(()=>a=null,t),e(...u);return}let d=t;if(i!==1/0&&a){const w=Date.now()-a;t>i-w&&(d=i-w)}clearTimeout(s),a??(a=Date.now()),s=setTimeout(()=>{a=null,o&&e(...u)},d)}return Object.assign(l,{cancel(){clearTimeout(s),a=null}})}function Wt(e,t,n){const{leading:r=!0,trailing:o=!0}=n??{};let i,s,a=!1;function l(){o&&s?(i=setTimeout(l,t),e(...s)):a=!1,s=null}function u(...d){a?s=d:(a=!0,i=setTimeout(l,t),r?e(...d):s=d)}return Object.assign(u,{cancel(){clearTimeout(i),a=!1,s=null}})}function*_t(...e){for(const t of e)yield*t}function Kt(e){return e!=null&&typeof e=="object"&&Symbol.iterator in e?e:[e]}function Ht(e){for(const t of e)return t;throw new Error("AG Charts - no first() value found")}function*Zt(e){const t=[void 0,void 0];for(const n of Object.keys(e))t[0]=n,t[1]=e[n],yield t}function Ee(e,t,n){return Math.min(n,Math.max(e,t))}function Jt(e,t,n=1e-10){return e>=t[0]-n&&e<=t[1]+n}function Lt(e,t,n=1e-10){return e===t||Math.abs(e-t)<n}function Xt(e){return Math.sign(e)===-1||Object.is(e,-0)}function Yt(e){return e%1===0}function Qt(e,t=2){const n=10**t;return Math.round(e*n)/n}function en(e,t){return Math.floor(e%t+(e<0?Math.abs(t):0))}function tn(e){if(Math.floor(e)===e)return 0;let t=String(e),n=0;if(e<1e-6||e>=1e21){let o;[t,o]=t.split("e"),o!=null&&(n=Number(o))}const r=t.split(".")[1]?.length??0;return Math.max(r-n,0)}var Ae=/^(?:(.)?([<>=^]))?([+\-( ])?([$€£¥₣₹#])?(0)?(\d+)?(,)?(?:\.(\d+))?(~)?([%a-z])?$/i,Ie=/^((?:[^#]|#[^{])*)#{([^}]+)}(.*)$/;function nn(e){if(!j(e))return!1;const t=Ie.exec(e);return Ae.test(t?t[2]:e)}function De(e){let t,n;const r=Ie.exec(e);r&&([,t,e,n]=r);const o=Ae.exec(e);if(!o)throw new Error(`The number formatter is invalid: ${e}`);const[,i,s,a,l,u,d,w,v,h,x]=o;return{fill:i,align:s,sign:a,symbol:l,zero:u,width:parseInt(d),comma:w,precision:parseInt(v),trim:!!h,type:x,prefix:t,suffix:n}}function rn(e){const t=typeof e=="string"?De(e):e,{fill:n,align:r,sign:o="-",symbol:i,zero:s,width:a,comma:l,type:u,prefix:d="",suffix:w="",precision:v}=t;let{trim:h}=t;const x=v==null||isNaN(v);let D;if(!u)D=y.g,h=!0;else if(u in y&&u in I)D=x?I[u]:y[u];else if(u in y)D=y[u];else if(u in I)D=I[u];else throw new Error(`The number formatter type is invalid: ${u}`);let H;return x?H=u?6:12:H=v,Z=>{let p=D(Z,H);return h&&(p=an(p)),l&&(p=un(p,l)),p=cn(Z,p,o),i&&i!=="#"&&(p=`${i}${p}`),i==="#"&&u==="x"&&(p=`0x${p}`),u==="s"&&(p=`${p}${ln(Z)}`),(u==="%"||u==="p")&&(p=`${p}%`),a!=null&&!isNaN(a)&&(p=fn(p,a,n??s,r)),p=`${d}${p}${w}`,p}}var I={b:e=>K(e).toString(2),c:e=>String.fromCharCode(e),d:e=>Math.round(Math.abs(e)).toFixed(0),o:e=>K(e).toString(8),x:e=>K(e).toString(16),X:e=>I.x(e).toUpperCase(),n:e=>I.d(e),"%":e=>`${K(e*100).toFixed(0)}`},y={e:(e,t)=>Math.abs(e).toExponential(t),E:(e,t)=>y.e(e,t).toUpperCase(),f:(e,t)=>Math.abs(e).toFixed(t),F:(e,t)=>y.f(e,t).toUpperCase(),g:(e,t)=>{if(e===0)return"0";const n=Math.abs(e),r=Math.floor(Math.log10(n));return r>=-4&&r<t?n.toFixed(t-1-r):n.toExponential(t-1)},G:(e,t)=>y.g(e,t).toUpperCase(),n:(e,t)=>y.g(e,t),p:(e,t)=>y.r(e*100,t),r:(e,t)=>{if(e===0)return"0";const n=Math.abs(e),o=Math.floor(Math.log10(n))-(t-1);if(o<=0)return n.toFixed(-o);const i=10**o;return(Math.round(n/i)*i).toFixed()},s:(e,t)=>{const n=Fe(e);return y.r(e/10**n,t)},"%":(e,t)=>y.f(e*100,t)},Pe=-24,qe=24,on={[Pe]:"y",[-21]:"z",[-18]:"a",[-15]:"f",[-12]:"p",[-9]:"n",[-6]:"\xB5",[-3]:"m",0:"",3:"k",6:"M",9:"G",12:"T",15:"P",18:"E",21:"Z",[qe]:"Y"},sn="\u2212";function K(e){return Math.floor(Math.abs(e))}function an(e){return e.replace(/\.0+$/,"").replace(/(\.[1-9])0+$/,"$1")}function un(e,t){let n=e.indexOf(".");n<0&&(n=e.length);const r=e.substring(0,n).split(""),o=e.substring(n);for(let i=r.length-3;i>0;i-=3)r.splice(i,0,t);return`${r.join("")}${o}`}function ln(e){return on[Fe(e)]}function Fe(e){return Ee(Pe,e?Math.floor(Math.log10(Math.abs(e))/3)*3:0,qe)}function cn(e,t,n=""){if(n==="(")return e>=0?t:`(${t})`;const r=n==="+"?"+":"";return`${e>=0?r:sn}${t}`}function fn(e,t,n=" ",r=">"){let o=e;if(r===">"||!r)o=o.padStart(t,n);else if(r==="<")o=o.padEnd(t,n);else if(r==="^"){const i=Math.max(0,t-o.length),s=Math.ceil(i/2),a=Math.floor(i/2);o=o.padStart(s+o.length,n),o=o.padEnd(a+o.length,n)}return o}export{Qe as EventEmitter,re as Logger,se as ModuleRegistry,ae as ModuleType,V as ValidationError,G as and,gt as array,X as arrayLength,W as arrayOf,Ot as arrayOfDefs,xe as arraysEqual,c as attachDescription,z as boolean,yt as callback,Nt as circularSliceArray,Ee as clamp,b as color,ke as colorUnion,U as constant,tn as countFractionDigits,et as countLines,pe as createElement,rn as createNumberFormatter,rt as createSvgElement,bt as date,Ut as debounce,wt as defined,zt as diffArrays,ot as downloadUrl,Zt as entries,je as fillGradientDefaults,te as fillOptionsDef,Ce as fillPatternDefaults,Vt as findMaxIndex,Bt as findMaxValue,Gt as findMinIndex,Rt as findMinValue,Ht as first,Dt as fontOptionsDef,N as getDocument,de as getWindow,_ as gradientColorStops,kt as gradientStrict,Mt as greaterThan,Ft as groupBy,Jt as inRange,St as instanceOf,O as isArray,ye as isBoolean,we as isColor,J as isDate,ge as isDefined,lt as isEnumKey,ct as isEnumValue,E as isFiniteNumber,q as isFunction,ut as isHtmlElement,Yt as isInteger,Xt as isNegative,at as isNumber,Lt as isNumberEqual,T as isObject,st as isObjectLike,be as isPlainObject,it as isRegExp,j as isString,ft as isSymbol,L as isValidDate,nn as isValidNumberFormat,_t as iterate,le as joinFormatted,vt as lessThan,fe as levenshteinDistance,It as lineDashOptionsDef,en as modulus,k as number,Y as numberMin,Se as numberRange,mt as object,A as optionsDefs,B as or,he as parseColor,De as parseNumberFormat,ve as partialDefs,g as positiveNumber,$t as positiveNumberNonZero,M as ratio,f as required,Qt as roundTo,tt as setDocument,nt as setWindow,Tt as sortBasedOnArray,Me as string,ce as stringifyValue,Oe as strokeOptionsDef,Wt as throttle,Pt as toArray,Kt as toIterable,Q as typeUnion,$ as union,qt as unique,F as validate};