UNPKG

@highcharts/dashboards

Version:
10 lines 15.3 kB
!/** * Highcharts Dashboards Math 4.2.1 (2026-08-06) * @module dashboards/modules/math-modifier * @requires dashboards * * (c) 2009-2026 Highsoft AS * * A commercial license may be required depending on use, * see www.highcharts.com/license */function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(e._Dashboards,e._Dashboards.DataModifier):"function"==typeof define&&define.amd?define("dashboards/modules/math-modifier",["dashboards/dashboards"],function(e){return t(e,e.DataModifier)}):"object"==typeof exports?exports["dashboards/modules/math-modifier"]=t(e._Dashboards,e._Dashboards.DataModifier):e.Dashboards=t(e.Dashboards,e.Dashboards.DataModifier)}("u"<typeof window?this:window,(e,t)=>(()=>{"use strict";var r={784(e){e.exports=t},668(t){t.exports=e}};let n={};function o(e){let t=n[e];if(void 0!==t)return t.exports;let s=n[e]={exports:{}};return r[e](s,s.exports,o),s.exports}o.n=e=>{let t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{if(Array.isArray(t))for(var r=0;r<t.length;){var n=t[r++],s=t[r++];o.o(e,n)?0===s&&r++:0===s?Object.defineProperty(e,n,{enumerable:!0,value:t[r++]}):Object.defineProperty(e,n,{enumerable:!0,get:s})}else for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let s={};o.d(s,{default:()=>em});var i=o(668),u=o.n(i);let a=/^(?:FALSE|TRUE)/,l=/^[+\-]?\d+(?:\.\d+)?(?:e[+\-]\d+)?/,c=/^[+\-]?\d+(?:,\d+)?(?:e[+\-]\d+)?/,f=/^([A-Z][A-Z\d\.]*)\(/,g=/^(?:[+\-*\/^<=>]|<=|=>)/,p=/^(\$?[A-Z]+)(\$?\d+)\:(\$?[A-Z]+)(\$?\d+)/,h=/^R(\d*|\[\d+\])C(\d*|\[\d+\])\:R(\d*|\[\d+\])C(\d*|\[\d+\])/,m=/^(\$?[A-Z]+)(\$?\d+)(?![\:C])/,b=/^R(\d*|\[\d+\])C(\d*|\[\d+\])(?!\:)/;function d(e){let t=0;for(let r=0,n=e.length,o,s=1;r<n;++r){if("("===(o=e[r])){t||(s=r+1),++t;continue}if(")"===o&&!--t)return e.substring(s,r)}if(t>0){let e=Error("Incomplete parentheses.");throw e.name="FormulaParseError",e}return""}function y(e){let t=-1;for(let r=0,n=e.length,o,s=!1;r<n;++r){if("\\"===(o=e[r])){s=!s;continue}if(s){s=!1;continue}if('"'===o)if(!(t<0))return e.substring(t+1,r);else t=r}let r=Error("Incomplete string.");throw r.name="FormulaParseError",r}function N(e,t){let r;if(r=e.match(h)){let e=""===r[2]||"["===r[2][0],t=""===r[1]||"["===r[1][0],n=""===r[4]||"["===r[4][0],o=""===r[3]||"["===r[3][0],s={type:"range",beginColumn:e?parseInt(r[2].substring(1,-1)||"0",10):parseInt(r[2],10)-1,beginRow:t?parseInt(r[1].substring(1,-1)||"0",10):parseInt(r[1],10)-1,endColumn:n?parseInt(r[4].substring(1,-1)||"0",10):parseInt(r[4],10)-1,endRow:o?parseInt(r[3].substring(1,-1)||"0",10):parseInt(r[3],10)-1};return e&&(s.beginColumnRelative=!0),t&&(s.beginRowRelative=!0),n&&(s.endColumnRelative=!0),o&&(s.endRowRelative=!0),s}if(r=e.match(p)){let e="$"!==r[1][0],t="$"!==r[2][0],n="$"!==r[3][0],o="$"!==r[4][0],s={type:"range",beginColumn:F(e?r[1]:r[1].substring(1))-1,beginRow:parseInt(t?r[2]:r[2].substring(1),10)-1,endColumn:F(n?r[3]:r[3].substring(1))-1,endRow:parseInt(o?r[4]:r[4].substring(1),10)-1};return e&&(s.beginColumnRelative=!0),t&&(s.beginRowRelative=!0),n&&(s.endColumnRelative=!0),o&&(s.endRowRelative=!0),s}let n=A(e,t);return 1===n.length&&"string"!=typeof n[0]?n[0]:n}function w(e){let t=e.length,r=e[t-2];return"-"===e[t-1]&&(0,i.isString)(r)&&!!r.match(/\*|\/|\^/)}function A(e,t){let r=t?c:l,n=[],o,s=("="===e[0]?e.substring(1):e).trim();for(;s;){if(o=s.match(b)){let e=""===o[2]||"["===o[2][0],t=""===o[1]||"["===o[1][0],r={type:"reference",column:e?parseInt(o[2].substring(1,-1)||"0",10):parseInt(o[2],10)-1,row:t?parseInt(o[1].substring(1,-1)||"0",10):parseInt(o[1],10)-1};e&&(r.columnRelative=!0),t&&(r.rowRelative=!0),w(n)&&(n.pop(),r.isNegative=!0),n.push(r),s=s.substring(o[0].length).trim();continue}if(o=s.match(m)){let e="$"!==o[1][0],t="$"!==o[2][0],r={type:"reference",column:F(e?o[1]:o[1].substring(1))-1,row:parseInt(t?o[2]:o[2].substring(1),10)-1};e&&(r.columnRelative=!0),t&&(r.rowRelative=!0),w(n)&&(n.pop(),r.isNegative=!0),n.push(r),s=s.substring(o[0].length).trim();continue}if(o=s.match(g)){n.push(o[0]),s=s.substring(o[0].length).trim();continue}if(o=s.match(a)){n.push("TRUE"===o[0]),s=s.substring(o[0].length).trim();continue}if(o=s.match(r)){let e=parseFloat(o[0]);w(n)&&(n.pop(),e=-e),n.push(e),s=s.substring(o[0].length).trim();continue}if('"'===s[0]){let e=y(s);n.push(e.substring(1,-1)),s=s.substring(e.length+2).trim();continue}if(o=s.match(f)){let e=d(s=s.substring(o[1].length).trim());n.push({type:"function",name:o[1],args:function(e,t){let r=[],n=t?";":",",o=0,s="";for(let i=0,u=e.length,a;i<u;++i)if((a=e[i])===n&&!o&&s)r.push(N(s,t)),s="";else if('"'!==a||o||s)" "!==a&&(s+=a,"("===a?++o:")"===a&&--o);else{let t=y(e.substring(i));r.push(t),i+=t.length+1}return!o&&s&&r.push(N(s,t)),r}(e,t)}),s=s.substring(e.length+2).trim();continue}if("("===s[0]){let e=d(s);if(e){n.push(A(e,t)),s=s.substring(e.length+2).trim();continue}}let i=e.length-s.length,u=Error("Unexpected character `"+e.substring(i,i+1)+"` at position "+(i+1)+". (`..."+e.substring(i-5,i+6)+"...`)");throw u.name="FormulaParseError",u}return n}function F(e){let t=0;for(let r=0,n=e.length,o,s=e.length-1;r<n;++r)(o=e.charCodeAt(r))>=65&&o<=90&&(t+=(o-64)*Math.pow(26,s)),--s;return t}let R={parseFormula:A},C=["+","-","*","/","^","=","<","<=",">",">="],v={isFormula:function(e){return Array.isArray(e)},isFunction:function(e){return"object"==typeof e&&!Array.isArray(e)&&"function"===e.type},isOperator:function(e){return"string"==typeof e&&C.indexOf(e)>=0},isRange:function(e){return"object"==typeof e&&!Array.isArray(e)&&"range"===e.type},isReference:function(e){return"object"==typeof e&&!Array.isArray(e)&&"reference"===e.type},isValue:function(e){return"boolean"==typeof e||"number"==typeof e||"string"==typeof e}},{isFormula:M,isFunction:P,isOperator:j,isRange:V,isReference:I,isValue:E}=v,O=/ */,D=Number.MAX_VALUE/1.000000000001,k=Number.MAX_VALUE/1.000000000002,x=Number.MAX_VALUE,$={"^":3,"*":2,"/":2,"+":1,"-":1,"=":0,"<":0,"<=":0,">":0,">=":0},U={},S=/^[A-Z][A-Z\.]*$/;function T(e){switch(typeof e){case"boolean":return e?x:D;case"string":return k;case"number":return e;default:return NaN}}function _(e){return"string"==typeof e?e.toLowerCase().replace(O,"\0"):e}function L(e){switch(typeof e){case"boolean":return+!!e;case"string":return parseFloat(e.replace(",","."));case"number":return e;default:return NaN}}function Z(e,t){return E(e)?e:V(e)?t&&X(e,t)||[]:P(e)?z(e,t):q(M(e)?e:[e],t)}function X(e,t){let r=t.getColumnIds().slice(e.beginColumn,e.endColumn+1),n=[];for(let o=0,s=r.length,i;o<s;++o){let s=t.getColumn(r[o],!0)||[];for(let u=e.beginRow,a=e.endRow+1;u<a;++u)"string"==typeof(i=s[u])&&"="===i[0]&&t!==t.getModified()&&(i=t.getModified().getCell(r[o],u)),n.push(E(i)?i:NaN)}return n}function G(e,t){let r=t.getColumnIds()[e.column];if(r){let n=t.getCell(r,e.row);if("string"==typeof n&&"="===n[0]&&t!==t.getModified()){let n=t.getModified().getCell(r,e.row);return E(n)?n:NaN}if(E(n))return e.isNegative?-n:n}return NaN}function B(e,t){(e.length<2||t.length<1)&&e.push(NaN);let r=e.pop(),n=e.pop(),o=t.pop();(0,i.defined)(r)&&(0,i.defined)(n)&&(0,i.defined)(o)?e.push(function(e,t,r){let n;switch(e){case"=":return _(t)===_(r);case"<":if(typeof t==typeof r)return _(t)<_(r);return T(t)<T(r);case"<=":if(typeof t==typeof r)return _(t)<=_(r);return T(t)<=T(r);case">":if(typeof t==typeof r)return _(t)>_(r);return T(t)>T(r);case">=":if(typeof t==typeof r)return _(t)>=_(r);return T(t)>=T(r)}switch(t=L(t),r=L(r),e){case"+":n=t+r;break;case"-":n=t-r;break;case"*":n=t*r;break;case"/":n=t/r;break;case"^":n=Math.pow(t,r);break;default:return NaN}return n%1?Math.round(1e9*n)/1e9:n}(o,n,r)):e.push(NaN)}function q(e,t){let r=[],n=[],o=!0;for(let s=0,i=e.length;s<i;++s){let i,u=e[s];if(j(u)){if(o&&"-"===u)r.push(0),n.push("-"),o=!0;else{for(;n.length&&$[n[n.length-1]]>=$[u];)B(r,n);n.push(u),o=!0}continue}if(E(u))i=u;else if(I(u))i=t?G(u,t):NaN;else if(P(u)){let e=z(u,t);i=E(e)?e:NaN}else M(u)&&(i=q(u,t));if(void 0===i)return NaN;r.push(i),o=!1}for(;n.length;)B(r,n);return 1!==r.length?NaN:r[0]}function z(e,t,r){let n=U[e.name];if(n)try{return n(e.args,t)}catch{return NaN}let o=Error(`Function "${e.name}" not found.`);throw o.name="FormulaProcessError",o}let H={asNumber:L,getArgumentValue:Z,getArgumentsValues:function(e,t){let r=[];for(let n=0,o=e.length;n<o;++n)r.push(Z(e[n],t));return r},getRangeValues:X,getReferenceValue:G,processFormula:q,processorFunctions:U,registerProcessorFunction:function(e,t){return S.test(e)&&!U[e]&&!!(U[e]=t)},translateReferences:function e(t,r=0,n=0){for(let o=0,s=t.length,i;o<s;++o)Array.isArray(i=t[o])?e(i,r,n):P(i)?e(i.args,r,n):V(i)?(i.beginColumnRelative&&(i.beginColumn+=r),i.beginRowRelative&&(i.beginRow+=n),i.endColumnRelative&&(i.endColumn+=r),i.endRowRelative&&(i.endRow+=n)):I(i)&&(i.columnRelative&&(i.column+=r),i.rowRelative&&(i.row+=n));return t}},{getArgumentValue:J}=H;H.registerProcessorFunction("ABS",function(e,t){let r=J(e[0],t);switch(typeof r){case"number":return Math.abs(r);case"object":{let e=[];for(let t=0,n=r.length,o;t<n;++t){if("number"!=typeof(o=r[t]))return NaN;e.push(Math.abs(o))}return e}default:return NaN}});let{getArgumentValue:K}=H;H.registerProcessorFunction("AND",function e(t,r){for(let n=0,o=t.length,s;n<o;++n)if(!(s=K(t[n],r))||"object"==typeof s&&!e(s,r))return!1;return!0});let{getArgumentsValues:Q}=H;H.registerProcessorFunction("AVERAGE",function(e,t){let r=Q(e,t),n=0,o=0;for(let e=0,t=r.length,s;e<t;++e)switch(typeof(s=r[e])){case"number":isNaN(s)||(++n,o+=s);break;case"object":for(let e=0,t=s.length,r;e<t;++e)"number"!=typeof(r=s[e])||isNaN(r)||(++n,o+=r)}return n?o/n:0});let{getArgumentValue:W}=H;H.registerProcessorFunction("AVERAGEA",function(e,t){let r=0,n=0;for(let o=0,s=e.length,i;o<s;++o)switch(typeof(i=W(e[o],t))){case"boolean":++r,n+=+!!i;continue;case"number":isNaN(i)||(++r,n+=i);continue;case"string":++r;continue;default:for(let e=0,t=i.length,o;e<t;++e)switch(typeof(o=i[e])){case"boolean":++r,n+=+!!o;continue;case"number":isNaN(o)||(++r,n+=o);continue;case"string":++r;continue}continue}return r?n/r:0}),H.registerProcessorFunction("COUNT",function e(t,r){let n=H.getArgumentsValues(t,r),o=0;for(let t=0,s=n.length,i;t<s;++t)switch(typeof(i=n[t])){case"number":!isNaN(i)&&++o;break;case"object":o+=e(i,r)}return o}),H.registerProcessorFunction("COUNTA",function e(t,r){let n=H.getArgumentsValues(t,r),o=0;for(let t=0,s=n.length,i;t<s;++t){switch(typeof(i=n[t])){case"number":if(isNaN(i))continue;break;case"object":o+=e(i,r);continue;case"string":if(!i)continue}++o}return o});let{getArgumentValue:Y}=H;H.registerProcessorFunction("IF",function(e,t){return Y(e[0],t)?Y(e[1],t):Y(e[2],t)});let{getArgumentValue:ee}=H;H.registerProcessorFunction("ISNA",function(e,t){let r=ee(e[0],t);return"number"!=typeof r||isNaN(r)});let{getArgumentsValues:et}=H;H.registerProcessorFunction("MAX",function e(t,r){let n=et(t,r),o=-1/0;for(let t=0,r=n.length,s;t<r;++t)switch(typeof(s=n[t])){case"number":s>o&&(o=s);break;case"object":(s=e(s))>o&&(o=s)}return isFinite(o)?o:0}),H.registerProcessorFunction("MEDIAN",function(e,t){let r=[],n=H.getArgumentsValues(e,t);for(let e=0,t=n.length,o;e<t;++e)switch(typeof(o=n[e])){case"number":isNaN(o)||r.push(o);break;case"object":for(let e=0,t=o.length,n;e<t;++e)"number"!=typeof(n=o[e])||isNaN(n)||r.push(n)}let o=r.length;if(!o)return NaN;let s=Math.floor(o/2);return o%2?r[s]:(r[s-1]+r[s])/2});let{getArgumentsValues:er}=H;H.registerProcessorFunction("MIN",function e(t,r){let n=er(t,r),o=1/0;for(let t=0,r=n.length,s;t<r;++t)switch(typeof(s=n[t])){case"number":s<o&&(o=s);break;case"object":(s=e(s))<o&&(o=s)}return isFinite(o)?o:0});let{getArgumentValue:en}=H;function eo(e,t){let r={},n=H.getArgumentsValues(e,t);for(let e=0,t=n.length,o;e<t;++e)switch(typeof(o=n[e])){case"number":isNaN(o)||(r[o]=(r[o]||0)+1);break;case"object":for(let e=0,t=o.length,n;e<t;++e)"number"!=typeof(n=o[e])||isNaN(n)||(r[n]=(r[n]||0)+1)}return r}function es(e,t){let r=eo(e,t),n=Object.keys(r);if(!n.length)return NaN;let o=parseFloat(n[0]),s=r[n[0]];for(let e=1,t=n.length,i,u,a;e<t;++e)s<(a=r[i=n[e]])?(o=parseFloat(i),s=a):s===a&&o>(u=parseFloat(i))&&(o=u,s=a);return s>1?o:NaN}H.registerProcessorFunction("MOD",function(e,t){let r=en(e[0],t),n=en(e[1],t);return("object"==typeof r&&(r=r[0]),"object"==typeof n&&(n=n[0]),"number"!=typeof r||"number"!=typeof n||0===n)?NaN:r%n}),H.registerProcessorFunction("MODE",es),H.registerProcessorFunction("MODE.MULT",function(e,t){let r=eo(e,t),n=Object.keys(r);if(!n.length)return NaN;let o=[parseFloat(n[0])],s=r[n[0]];for(let e=1,t=n.length,i,u;e<t;++e)s<(u=r[i=n[e]])?(o=[parseFloat(i)],s=u):s===u&&o.push(parseFloat(i));return s>1?o:NaN}),H.registerProcessorFunction("MODE.SNGL",es);let{getArgumentValue:ei}=H;H.registerProcessorFunction("NOT",function(e,t){let r=ei(e[0],t);switch("object"==typeof r&&(r=r[0]),typeof r){case"boolean":case"number":return!r}return NaN});let{getArgumentValue:eu}=H;H.registerProcessorFunction("OR",function e(t,r){for(let n=0,o=t.length,s;n<o;++n)if("object"==typeof(s=eu(t[n],r))){if(e(s,r))return!0}else if(s)return!0;return!1});let{getArgumentsValues:ea}=H;H.registerProcessorFunction("PRODUCT",function e(t,r){let n=ea(t,r),o=1,s=!1;for(let t=0,i=n.length,u;t<i;++t)switch(typeof(u=n[t])){case"number":isNaN(u)||(s=!0,o*=u);break;case"object":s=!0,o*=e(u,r)}return s?o:0}),H.registerProcessorFunction("SUM",function e(t,r){let n=H.getArgumentsValues(t,r),o=0;for(let t=0,s=n.length,i;t<s;++t)switch(typeof(i=n[t])){case"number":isNaN(i)||(o+=i);break;case"object":o+=e(i,r)}return o});let{getArgumentValue:el}=H;H.registerProcessorFunction("XOR",function(e,t){for(let r=0,n=e.length,o,s;r<n;++r)switch(typeof(s=el(e[r],t))){case"boolean":case"number":if(void 0===o)o=!!s;else if(!!s!==o)return!0;break;case"object":for(let e=0,t=s.length,r;e<t;++e)switch(typeof(r=s[e])){case"boolean":case"number":if(void 0===o)o=!!r;else if(!!r!==o)return!0}}return!1});let ec={...R,...H,...v};var ef=o(784),eg=o.n(ef);class ep extends eg(){constructor(e){super(),this.options={...ep.defaultOptions,...e}}modifyTable(e,t){this.emit({type:"modify",detail:t,table:e});let r=this.options.alternativeSeparators,n=this.options.formulaColumns||e.getColumnIds(),o=e.getModified();for(let t=0,r=n.length,s;t<r;++t)s=n[t],n.indexOf(s)>=0&&o.setColumn(s,this.processColumn(e,s));let s=this.options.columnFormulas||[];for(let t=0,n=s.length,i,u;t<n;++t)i=s[t],u=R.parseFormula(i.formula,r),o.setColumn(i.column,this.processColumnFormula(u,e,i.rowStart,i.rowEnd));return this.emit({type:"afterModify",detail:t,table:e}),e}processColumn(e,t,r=0){let n=this.options.alternativeSeparators,o=(e.getColumn(t,!0)||[]).slice(r>0?r:0);for(let t=0,r=o.length,s=[],i;t<r;++t)if("string"==typeof(i=o[t])&&"="===i[0])try{s=""===i?s:R.parseFormula(i.substring(1),n),o[t]=H.processFormula(s,e)}catch{o[t]=NaN}return o}processColumnFormula(e,t,r=0,n=t.getRowCount()){r=r>=0?r:0,n=n>=0?n:t.getRowCount()+n;let o=[],s=t.getModified();for(let t=0,i=n-r;t<i;++t)try{o[t]=H.processFormula(e,s)}catch{o[t]=NaN}finally{e=H.translateReferences(e,0,1)}return o}}ep.defaultOptions={type:"Math",alternativeSeparators:!1},eg().registerType("Math",ep);let eh=u();eh.Formula=ec;let em=eh;return s.default})());