@datagrok/curves 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +4 -3
- package/src/fit/fit-grid-cell-handler.ts +1 -1
- package/src/fit/fit-renderer.ts +5 -0
- package/src/fit/multi-curve-viewer.ts +6 -0
- package/src/package.g.ts +21 -0
- package/src/package.ts +6 -20
- package/src/tests/curves-cell-renderer-tests.ts +3 -3
- package/tsconfig.json +2 -2
- package/webpack.config.js +4 -0
package/dist/package.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var curves;(()=>{var e={111:(e,t,n)=>{"use strict";function r(e){e.sort();const t=e[Math.trunc(e.length/4)],n=e.length%2==0?(e[Math.trunc(e.length/2)]+e[Math.trunc(e.length/2)-1])/2:e[Math.trunc(e.length/2)],r=e[Math.trunc(3*e.length/4)],i=1.5*(r-t);let a=o(e,r+i);a<0&&(a=~a);let l=e[Math.max(0,a-1)];l<r&&(l=r);let s=o(e,t-i);s<0&&(s=~s);let u=e[s];return u>t&&(u=t),{q1:t,q2:n,q3:r,lowerAdjacentValue:u,upperAdjacentValue:l}}function o(e,t,n=0,r){if(0===e.length)return-1;if(void 0===r&&(r=e.length-1),t<e[n])return-1;if(t>e[r])return-(r+1);for(;r-n>1;){const o=Math.trunc((r+n)/2);if(t===e[o])return o;t<e[o]?r=o:n=o}return e[n]===t?n:0===e[r]?r:t<e[n]?-(n+1):-(r+1)}n.d(t,{G:()=>r})},102:(e,t,n)=>{"use strict";n.d(t,{yB:()=>T,cY:()=>d,js:()=>f,kW:()=>v,iC:()=>y,K0:()=>_,ue:()=>A,hR:()=>x,ZY:()=>I,aC:()=>C,sw:()=>g});var r,o=n(976),i=n(162);class a extends Error{constructor(e){super(e)}}function l(e,t,n,r){for(let o=0;o<t;o++){let i=0;for(let e=0;e<t+1;e++)e!==n&&(i+=r[e][o]);e[o]=i/t}}function s(e,t,n,r,o,i,a,l){for(let s=0;s<i;s++)t[s]=e[s],t[s]+=o*(e[s]-r[n][s]),t[s]<a[s]?t[s]=a[s]:t[s]>l[s]&&(t[s]=l[s])}!function(e){e[e.TOLERANCE=.01]="TOLERANCE",e[e.MAX_ITER=20]="MAX_ITER",e[e.NON_ZERO_PARAM=1e-4]="NON_ZERO_PARAM",e[e.INITIAL_SCALE=.02]="INITIAL_SCALE",e[e.SCALE_REFLECTION=1]="SCALE_REFLECTION",e[e.SCALE_EXPANSION=2]="SCALE_EXPANSION",e[e.SCALE_CONTRACTION=-.5]="SCALE_CONTRACTION"}(r||(r={})),new Map([["tolerance","Tolerance"],["maxIter","Max iterations"],["nonZeroParam","Non-zero param"],["initialScale","Initial scale"],["scaleReflection","Scale reflection"],["scaleExpansion","Scale expansion"],["scaleContraction","Scale contraction"]]);const u=function(e,t,n,r,o){const i=n.tolerance,a=n.maxIter,u=n.scaleReflection,c=n.scaleExpansion,f=n.scaleContraction,d=t.length+1,m=t.length,[h,p]=function(e,t,n,r,o){const i=n.length+1,a=n.length,l=t.nonZeroParam,s=t.initialScale,u=new Array(i),c=new Array(i);for(let t=0;t<i;t++){u[t]=new Float32Array(a);for(let e=0;e<a;e++)u[t][e]=n[e],0!==t&&t-1===e&&(0===n[e]?u[t][e]=l:u[t][e]+=s*n[t-1],u[t][e]<r[e]?u[t][e]=r[e]:u[t][e]>o[e]&&(u[t][e]=o[e]));c[t]=e(u[t])}return[u,c]}(e,n,t,r,o),g=new Array(d);for(let e=0;e<d;e++)g[e]=e;const v=g.length-1;let _=0,T=0,w=0,E=0;const I=new Float32Array(m),y=new Float32Array(m),x=new Float32Array(m),A=new Float32Array(m),C=new Array(a);if(d>1){for(;g.sort(((e,t)=>p[e]-p[t])),!(_>a);){if(0===_&&(T=p[0],w=2*p[g[0]]),C[_]=T,++_,T=p[g[0]],w-T>i)E=0;else if(++E,E>2*d)break;w=T,l(I,m,g[v],h),s(I,y,g[v],h,u,m,r,o);const t=e(y);if(t<p[g[v]]){s(I,x,g[v],h,c,m,r,o);const n=e(x);if(n<t){p[g[v]]=n;for(let e=0;e<m;e++)h[g[v]][e]=x[e];continue}p[g[v]]=t;for(let e=0;e<m;e++)h[g[v]][e]=y[e];continue}s(I,A,g[v],h,f,m,r,o);const n=e(A);if(!(n<p[g[v]]))break;p[g[v]]=n;for(let e=0;e<m;e++)h[g[v]][e]=A[e]}for(let e=_;e<a;e++)C[e]=p[g[0]]}return{point:h[g[0]],cost:p[g[0]],iterCosts:C,iterCount:_-1}};function c(e,t,n){const r=t-n,o=new Array(e);for(let t=0;t<e;t++){const e=Math.random();o[t]=n+e*r}return o}const f={CONSTANT:"constant",PROPORTIONAL:"proportional",COMBINED:"combined"};class d{constructor(){this.chartOptions={},this.seriesOptions={},this.series=[]}}class m{}class h extends m{constructor(e,t,n,r){super(),this._name=e,this._parameterNames=r,this.y=t,this.getInitialParameters=n}get name(){return this._name}get parameterNames(){return this._parameterNames}y(e,t){throw new Error("Not implemented")}getInitialParameters(e,t){throw new Error("Not implemented")}}const p={linear:new class extends m{get name(){return w}get parameterNames(){return["Slope","Intercept"]}y(e,t){return function(e,t){return e[0]*t+e[1]}(e,t)}getInitialParameters(e,t){let n=0,r=0;for(let t=1;t<e.length;t++)e[t]<e[n]&&(n=t),e[t]>e[r]&&(r=t);const o=e[r]-e[n],i=(t[r]-t[n])/o,a=t[r]-i*e[r],l=new Float32Array(2);return l.set([i,a]),l}},sigmoid:new class extends m{get name(){return T}get parameterNames(){return["Top","Bottom","Slope","IC50"]}y(e,t){return function(e,t){const n=e[0],r=e[1],o=e[2],i=e[3];return i+(n-i)/(1+Math.pow(10,(t-o)*r))}(e,t)}getInitialParameters(e,t){const n=o.Rect.fromXYArrays(e,t),r=(n.bottom-n.top)/2+n.top;let i=n.bottom-n.top,a=0;for(let n=0;n<e.length;n++){const e=Math.abs(t[n]-r);e<i&&(i=e,a=n)}const l=e[a],s=t[0]>t[t.length-1]?1:-1,u=new Float32Array(4);return u.set([n.bottom,s,l,n.top]),u}},"log-linear":new class extends m{get name(){return E}get parameterNames(){return["Slope","Intercept"]}y(e,t){return function(e,t){const n=e[0],r=e[1];return n*Math.log(t+1)+r}(e,t)}getInitialParameters(e,t){const n=new Float32Array(2);return n.set([-5,100]),n}}},g=[o.Property.js("rSquared",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("auc",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("interceptY",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("interceptX",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("slope",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("top",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("bottom",o.TYPE.FLOAT,{userEditable:!1})],v=[o.Property.js("minX",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("minY",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("maxX",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("maxY",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("title",o.TYPE.STRING,{nullable:!0}),o.Property.js("xAxisName",o.TYPE.STRING,{description:"Label to show on the X axis. If not specified, corresponding data column name is used",nullable:!0}),o.Property.js("yAxisName",o.TYPE.STRING,{description:"Label to show on the Y axis. If not specified, corresponding data column name is used",nullable:!0}),o.Property.js("logX",o.TYPE.BOOL,{description:"Whether the X axis should be logarithmic",defaultValue:!1}),o.Property.js("logY",o.TYPE.BOOL,{description:"Whether the Y axis should be logarithmic",defaultValue:!1}),o.Property.js("allowXZeroes",o.TYPE.BOOL,{description:"Whether x zeroes allowed for logarithmic data or not",defaultValue:!0}),o.Property.js("mergeSeries",o.TYPE.BOOL,{description:"Merges all series within one cell into one series",defaultValue:!1}),o.Property.js("showColumnLabel",o.TYPE.BOOL,{description:"Whether to show the column label in the legend or not",defaultValue:!1}),o.Property.js("showStatistics",o.TYPE.STRING_LIST,{description:"Whether specific statistics should be rendered",choices:g.map((e=>e.name)),inputType:"MultiChoice",friendlyName:"Statistics"})],_=[o.Property.js("fitFunction",o.TYPE.STRING,{category:"Fitting",choices:Object.keys(p),defaultValue:"sigmoid"}),o.Property.js("pointColor",o.TYPE.STRING,{category:"Rendering",nullable:!0,inputType:"Color"}),o.Property.js("fitLineColor",o.TYPE.STRING,{category:"Rendering",nullable:!0,inputType:"Color"}),o.Property.js("outlierColor",o.TYPE.STRING,{category:"Rendering",nullable:!0,inputType:"Color"}),o.Property.js("errorModel",o.TYPE.STRING,{category:"Fitting",defaultValue:"constant",choices:["constant","proportional","combined"],nullable:!1}),o.Property.js("connectDots",o.TYPE.BOOL,{category:"Fitting",defaultValue:!1}),o.Property.js("clickToToggle",o.TYPE.BOOL,{category:"Fitting",description:"Click on a point to mark it as outlier and refit",nullable:!0,defaultValue:!1}),o.Property.js("showFitLine",o.TYPE.BOOL,{category:"Fitting",defaultValue:!0}),o.Property.js("showPoints",o.TYPE.STRING,{category:"Fitting",description:"Whether points/candlesticks/none should be rendered",defaultValue:"points",choices:["points","candlesticks","both"]}),o.Property.js("showCurveConfidenceInterval",o.TYPE.BOOL,{category:"Fitting",description:"Whether confidence intervals should be rendered",defaultValue:!1,friendlyName:"Confidence Interval"}),o.Property.js("markerType",o.TYPE.STRING,{category:"Rendering",defaultValue:"circle",choices:["asterisk","circle","cross border","diamond","square","star","triangle bottom","triangle left","triangle right","triangle top"],nullable:!1,friendlyName:"Marker"}),o.Property.js("outlierMarkerType",o.TYPE.STRING,{category:"Rendering",defaultValue:"outlier",choices:["asterisk","circle","cross border","diamond","outlier","square","star","triangle bottom","triangle left","triangle right","triangle top"],nullable:!1,friendlyName:"Outlier Marker"}),o.Property.js("lineStyle",o.TYPE.STRING,{category:"Rendering",defaultValue:"solid",choices:["solid","dotted","dashed","dashdotted"],nullable:!1}),o.Property.js("droplines",o.TYPE.STRING_LIST,{description:"Whether specific droplines should be rendered",choices:["IC50"],inputType:"MultiChoice"}),o.Property.js("columnName",o.TYPE.STRING,{description:"Column name where the series is stored",defaultValue:""})],T="sigmoid",w="linear",E="log-linear";function I(e){if("string"==typeof e)return p[e];if(!p[e.name]){const t=e.name,n=e.parameterNames,r=e.function.split("=>").map((e=>e.trim())),o=e.getInitialParameters.split("=>").map((e=>e.trim())),i=new Function(r[0].slice(1,r[0].length-1),`${r[1].includes(";")?"":"return "}${r[1]}`),a=new Function(o[0].slice(1,o[0].length-1),`return ${o[1]}`),l=new h(t,i,a,n);p[t]=l}return p[e.name]}function y(e,t,n,i){const l=t.y;let s=t.getInitialParameters(e.x,e.y);const d=function(e,t,n){return r=>{let o=0,i=0,a=0;const l=t.y,s=t.x.map((t=>e(r,t))),u=l.map(((e,t)=>e-s[t])).map((e=>Math.pow(e,2)));for(let e=0;e<u.length;e++)[f.CONSTANT,f.COMBINED].includes(n)?i+=u[e]:n===f.PROPORTIONAL&&(a+=u[e]/(s[e]*s[e]));i=Math.sqrt(i/u.length),a=Math.sqrt(a/u.length),n===f.COMBINED&&({sigmaA:i,sigmaB:a}=O(i,a,u,s));const c=[];for(let e=0;e<u.length;e++)c[e]=Math.pow(i+a*s[e],2),o+=u[e]/c[e]+Math.log(2*Math.PI*c[e]);return o}}(l,e,n);let m=new Float32Array(t.parameterNames.length),h=new Float32Array(t.parameterNames.length);for(let e=0;e<t.parameterNames.length;e++)m[e]=0===s[e]?-1:s[e]-Math.abs(.5*s[e]),h[e]=0===s[e]?1:s[e]+Math.abs(.5*s[e]);return i&&0!==i.length&&(m=new Float32Array(i.length),m.set(i.map((e=>e.min))),h=new Float32Array(i.length),h.set(i.map((e=>e.max)))),s=function(e,t,n,r,i=1,l=null,s=!0){const f=function(e,t,n){const r=t.length,o=new Array(e);for(let t=0;t<e;t++)o[t]=new Float32Array(r);for(let i=0;i<r;i++)if(t[i]===n[i])for(let n=0;n<e;n++)o[n][i]=t[i];else{const r=c(e,t[i],n[i]);for(let t=0;t<e;t++)o[t][i]=r[t]}return o}(i,n,t);null!==l&&(f[0]=l);const d=[],m=[],h=[];let p,g=0,v=null;for(p=0;p<i;++p)try{if(0===p&&s){const t=new Float32Array(l.length).map((e=>-1/0)),n=new Float32Array(l.length).map((e=>1/0));d.push(u(e,f[p],r,t,n))}else d.push(u(e,f[p],r,t,n))}catch(e){if(e instanceof a)throw new Error(`Inconsistent dataframes: ${e.message}`);++g,m.push(e instanceof Error?e.message:"Platform issue"),h.push(f[p])}if(g>0){const e=n.length,t=new Array(e);for(let n=0;n<e;++n)t[n]=new Float32Array(g);h.forEach(((e,n)=>e.forEach(((e,r)=>t[r][n]=e)))),v=o.DataFrame.fromColumns(t.map(((e,t)=>o.Column.fromFloat32Array(`arg${t}`,e)))),v.columns.add(o.Column.fromStrings("Issue",m))}return{extremums:d,fails:v}}(d,m,h,{tolerance:r.TOLERANCE,maxIter:r.MAX_ITER,nonZeroParam:r.NON_ZERO_PARAM,initialScale:r.INITIAL_SCALE,scaleReflection:r.SCALE_REFLECTION,scaleExpansion:r.SCALE_EXPANSION,scaleContraction:r.SCALE_CONTRACTION},1,s).extremums[0].point,{fittedCurve:x(l,s),parameters:s}}function x(e,t){return n=>e(t,n)}function A(e,t,n,r=.05,o){const a=function(e,t,n,r){let o=0,i=0;const a=t.y,l=t.x.map((t=>e(r,t))),s=a.map(((e,t)=>e-l[t])),u=s.map((e=>Math.pow(e,2)));for(let e=0;e<u.length;e++)[f.CONSTANT,f.COMBINED].includes(n)?o+=u[e]:n===f.PROPORTIONAL&&(i+=Math.pow(s[e]/Math.abs(l[e]),2));return o=Math.sqrt(o/u.length),i=Math.sqrt(i/u.length),n===f.COMBINED&&({sigmaA:o,sigmaB:i}=O(o,i,u,l)),{sigmaA:o,sigmaB:i}}(n,e,o,t),l=i.normal.inv(1-r/2,0,1);return{confidenceTop:e=>{const r=n(t,e);return r+l*(a.sigmaA+Math.abs(r)*a.sigmaB)},confidenceBottom:e=>{const r=n(t,e);return r-l*(a.sigmaA+Math.abs(r)*a.sigmaB)}}}function C(e,t,n,r=!0){const o=x(n,t);return{rSquared:r?S(o,e):void 0,auc:r?N(o,e):void 0,interceptX:t[2],interceptY:o(t[2]),slope:t[1],top:t[0],bottom:t[3]}}function N(e,t){let n=0;const r=Math.min(...t.x),o=Math.max(...t.x),i=(o-r)/1e3;for(let t=r;t<o;t+=i)n+=i*e(t);return n}function S(e,t){let n=0,r=0;const o=i.mean(t.y);for(let i=0;i<t.x.length;i++)n+=Math.pow(t.y[i]-e(t.x[i]),2),r+=Math.pow(t.y[i]-o,2);return 1-n/r}function O(e,t,n,r){let o=Number.MAX_VALUE,i=0;for(let t=0;t<=10;t++){let a=0;const l=t/10,s=e*l,u=e*(1-l),c=[];for(let e=0;e<n.length;e++)c[e]=Math.pow(s+u*r[e],2),a+=n[e]/c[e]+Math.log(2*Math.PI*c[e]);a<o&&(o=a,i=l)}return t=e*(1-i),{sigmaA:e*=i,sigmaB:t}}},416:(e,t,n)=>{"use strict";n.d(t,{LC:()=>m,PK:()=>d,TL:()=>a,Y6:()=>c,dU:()=>u,kG:()=>f,tq:()=>h});var r=n(976),o=n(102);function i(e){const t={};for(const n of e)null!==n.defaultValue&&(t[n.name]=n.defaultValue);return t}function a(){return{chartOptions:i(o.kW),seriesOptions:i(o.K0)}}function l(e){const t=[],n=[];for(let r=0;r<e.length;r++)t[r]=e[r].x,n[r]=e[r].y;return{xs:t,ys:n}}function s(e){const t=Math.floor(e.y.length/2),n=e.y.sort(((e,t)=>e-t));return n.length%2==0?(n[t-1]+n[t])/2:n[t]}function u(e){var t;const n=e.chartOptions;if((null===(t=e.series)||void 0===t?void 0:t.length)&&0!==e.series.length){const{xs:t,ys:o}=l(e.series[0].points);let i=r.Rect.fromXYArrays(t,o);for(let t=1;t<e.series.length;t++){const{xs:n,ys:o}=l(e.series[t].points);n.some((e=>void 0===e))||o.some((e=>void 0===e))||(i=i.union(r.Rect.fromXYArrays(n,o)))}return n?function(e,t){let n=e.x,o=e.y,i=e.width,a=e.height;return void 0!==t.minX&&null!==t.minX&&(!t.logX||t.logX&&t.minX>0)&&(i+=n-t.minX,n=t.minX),void 0!==t.maxX&&null!==t.maxX&&(!t.logX||t.logX&&t.maxX>0)&&(i+=t.maxX-(n+i)),void 0!==t.minY&&null!==t.minY&&(!t.logY||t.logY&&t.minY>0)&&(a+=o-t.minY,o=t.minY),void 0!==t.maxY&&null!==t.maxY&&(!t.logY||t.logY&&t.maxY>0)&&(a+=t.maxY-(o+a)),new r.Rect(n,o,i,a)}(i,n):i}return new r.Rect(0,0,1,1)}function c(e){return(0,o.ZY)(e.fitFunction)}function f(e,t){var n;const r=new Float32Array(null===(n=e.parameters)||void 0===n?void 0:n.length);return r.set(e.parameters),(0,o.hR)(t.y,r)}function d(e,t,n){var r;const i={x:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logX)?Math.log10(e.x):e.x)),y:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logY)?Math.log10(e.y):e.y))};var a;return e.parameterBounds&&(null==n?void 0:n.logX)&&(e.parameterBounds[2]=((a=e.parameterBounds[2])&&(void 0!==a.max&&(a.max=Math.log10(a.max)),void 0!==a.min&&(a.min=0===a.min?-Number.MAX_VALUE:Math.log10(a.min))),a)),(0,o.iC)(function(e){const t={x:[],y:[]},n={x:[e.x[0]],y:[e.y[0]]};for(let r=1;r<e.x.length;r++){if(e.x[r]===n.x[0]){n.x[n.x.length]=e.x[r],n.y[n.y.length]=e.y[r];continue}const o=s(n);t.x[t.x.length]=n.x[0],t.y[t.y.length]=o,n.x=[e.x[r]],n.y=[e.y[r]]}const r=s(n);return t.x[t.x.length]=n.x[0],t.y[t.y.length]=r,t}(i),t,null!==(r=e.errorModel)&&void 0!==r?r:o.js.CONSTANT,e.parameterBounds)}function m(e,t,n,r){var i,a;const l=n?{x:e.points.map((e=>(null==r?void 0:r.logX)?Math.log10(e.x):e.x)),y:e.points.map((e=>(null==r?void 0:r.logY)?Math.log10(e.y):e.y))}:{x:e.points.filter((e=>!e.outlier)).map((e=>(null==r?void 0:r.logX)?Math.log10(e.x):e.x)),y:e.points.filter((e=>!e.outlier)).map((e=>(null==r?void 0:r.logY)?Math.log10(e.y):e.y))};if(!e.parameters){const n=d(e,t).parameters;e.parameters=[...n]}const s=new Float32Array(null===(i=e.parameters)||void 0===i?void 0:i.length);return s.set(e.parameters),(0,o.ue)(l,s,t.y,.05,null!==(a=e.errorModel)&&void 0!==a?a:o.js.CONSTANT)}function h(e,t,n){var r;const i={x:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logX)?Math.log10(e.x):e.x)),y:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logY)?Math.log10(e.y):e.y))};if(!e.parameters){const n=d(e,t).parameters;e.parameters=[...n]}const a=new Float32Array(null===(r=e.parameters)||void 0===r?void 0:r.length);return a.set(e.parameters),(0,o.aC)(i,a,t.y,!0)}},766:(e,t,n)=>{"use strict";n.d(t,{l:()=>l});var r=n(976);const o=1e-30,i=new class{screenToWorld(e,t,n,r,o){return n+(o?1-e/t:e/t)*(r-n)}worldToScreen(e,t,n,r,o){return o?(1-(e-n)/(r-n))*t:(e-n)/(r-n)*t}},a=new class{screenToWorld(e,t,n,r,i){n=n<o?o:n;const a=Math.log(r),l=Math.log(n);return Math.exp(l+(a-l)*(i?t-e:e)/t)}worldToScreen(e,t,n,r,i){if(e<=0)return NaN;if(Math.abs(e-n)<o)return i?t:0;if(Math.abs(e-r)<o)return i?0:t;n=n<o?o:n,e=e<o?o:e;const a=t*Math.log(e/n)/Math.log(r/n);return i?t-a:a}};class l{get xt(){return this.logX?a:i}get yt(){return this.logY?a:i}constructor(e,t,n=!1,r=!1){this.logX=!1,this.logY=!1,this.inverseX=!1,this.inverseY=!1,this.world=e,this.screen=t,this.logX=n,this.logY=r}xToScreen(e){return this.screen.left+this.xt.worldToScreen(e,this.screen.width,this.world.minX,this.world.maxX,this.inverseX)}yToScreen(e){return this.screen.top+this.yt.worldToScreen(e,this.screen.height,this.world.minY,this.world.maxY,!this.inverseY)}xToWorld(e){return this.xt.screenToWorld(e-this.screen.left,this.screen.width,this.world.minX,this.world.maxX,this.inverseX)}yToWorld(e){return this.yt.screenToWorld(e-this.screen.top,this.screen.height,this.world.minY,this.world.maxY,!this.inverseY)}toScreen(e){return new r.Point(this.xToScreen(e.x),this.yToScreen(e.y))}toWorld(e){return new r.Point(this.xToWorld(e.x),this.yToWorld(e.y))}drawCoordinateGrid(e,t,n){t&&r.Paint.horzAxis(e,this.world.minX,this.world.maxX,t.x,t.y,t.width,t.height,this.logX,this.inverseX),n&&r.Paint.vertAxis(e,this.world.minY,this.world.maxY,n.x,n.y,n.width,n.height,this.logY,this.inverseY)}}},162:function(e){var t;e.exports=(t=function(e,t){var n=Array.prototype.concat,r=Array.prototype.slice,o=Object.prototype.toString;function i(t,n){var r=t>n?t:n;return e.pow(10,17-~~(e.log(r>0?r:-r)*e.LOG10E))}var a=Array.isArray||function(e){return"[object Array]"===o.call(e)};function l(e){return"[object Function]"===o.call(e)}function s(e){return"number"==typeof e&&e-e==0}function u(){return new u._init(arguments)}function c(){return 0}function f(){return 1}function d(e,t){return e===t?1:0}u.fn=u.prototype,u._init=function(e){if(a(e[0]))if(a(e[0][0])){l(e[1])&&(e[0]=u.map(e[0],e[1]));for(var t=0;t<e[0].length;t++)this[t]=e[0][t];this.length=e[0].length}else this[0]=l(e[1])?u.map(e[0],e[1]):e[0],this.length=1;else if(s(e[0]))this[0]=u.seq.apply(null,e),this.length=1;else{if(e[0]instanceof u)return u(e[0].toArray());this[0]=[],this.length=1}return this},u._init.prototype=u.prototype,u._init.constructor=u,u.utils={calcRdx:i,isArray:a,isFunction:l,isNumber:s,toVector:function(e){return n.apply([],e)}},u._random_fn=e.random,u.setRandom=function(e){if("function"!=typeof e)throw new TypeError("fn is not a function");u._random_fn=e},u.extend=function(e){var t,n;if(1===arguments.length){for(n in e)u[n]=e[n];return this}for(t=1;t<arguments.length;t++)for(n in arguments[t])e[n]=arguments[t][n];return e},u.rows=function(e){return e.length||1},u.cols=function(e){return e[0].length||1},u.dimensions=function(e){return{rows:u.rows(e),cols:u.cols(e)}},u.row=function(e,t){return a(t)?t.map((function(t){return u.row(e,t)})):e[t]},u.rowa=function(e,t){return u.row(e,t)},u.col=function(e,t){if(a(t)){var n=u.arange(e.length).map((function(){return new Array(t.length)}));return t.forEach((function(t,r){u.arange(e.length).forEach((function(o){n[o][r]=e[o][t]}))})),n}for(var r=new Array(e.length),o=0;o<e.length;o++)r[o]=[e[o][t]];return r},u.cola=function(e,t){return u.col(e,t).map((function(e){return e[0]}))},u.diag=function(e){for(var t=u.rows(e),n=new Array(t),r=0;r<t;r++)n[r]=[e[r][r]];return n},u.antidiag=function(e){for(var t=u.rows(e)-1,n=new Array(t),r=0;t>=0;t--,r++)n[r]=[e[r][t]];return n},u.transpose=function(e){var t,n,r,o,i,l=[];for(a(e[0])||(e=[e]),n=e.length,r=e[0].length,i=0;i<r;i++){for(t=new Array(n),o=0;o<n;o++)t[o]=e[o][i];l.push(t)}return 1===l.length?l[0]:l},u.map=function(e,t,n){var r,o,i,l,s;for(a(e[0])||(e=[e]),o=e.length,i=e[0].length,l=n?e:new Array(o),r=0;r<o;r++)for(l[r]||(l[r]=new Array(i)),s=0;s<i;s++)l[r][s]=t(e[r][s],r,s);return 1===l.length?l[0]:l},u.cumreduce=function(e,t,n){var r,o,i,l,s;for(a(e[0])||(e=[e]),o=e.length,i=e[0].length,l=n?e:new Array(o),r=0;r<o;r++)for(l[r]||(l[r]=new Array(i)),i>0&&(l[r][0]=e[r][0]),s=1;s<i;s++)l[r][s]=t(l[r][s-1],e[r][s]);return 1===l.length?l[0]:l},u.alter=function(e,t){return u.map(e,t,!0)},u.create=function(e,t,n){var r,o,i=new Array(e);for(l(t)&&(n=t,t=e),r=0;r<e;r++)for(i[r]=new Array(t),o=0;o<t;o++)i[r][o]=n(r,o);return i},u.zeros=function(e,t){return s(t)||(t=e),u.create(e,t,c)},u.ones=function(e,t){return s(t)||(t=e),u.create(e,t,f)},u.rand=function(e,t){return s(t)||(t=e),u.create(e,t,u._random_fn)},u.identity=function(e,t){return s(t)||(t=e),u.create(e,t,d)},u.symmetric=function(e){var t,n,r=e.length;if(e.length!==e[0].length)return!1;for(t=0;t<r;t++)for(n=0;n<r;n++)if(e[n][t]!==e[t][n])return!1;return!0},u.clear=function(e){return u.alter(e,c)},u.seq=function(e,t,n,r){l(r)||(r=!1);var o,a=[],s=i(e,t),u=(t*s-e*s)/((n-1)*s),c=e;for(o=0;c<=t&&o<n;c=(e*s+u*s*++o)/s)a.push(r?r(c,o):c);return a},u.arange=function(e,n,r){var o,i=[];if(r=r||1,n===t&&(n=e,e=0),e===n||0===r)return[];if(e<n&&r<0)return[];if(e>n&&r>0)return[];if(r>0)for(o=e;o<n;o+=r)i.push(o);else for(o=e;o>n;o+=r)i.push(o);return i},u.slice=function(){function e(e,n,r,o){var i,a=[],l=e.length;if(n===t&&r===t&&o===t)return u.copy(e);if(o=o||1,(n=(n=n||0)>=0?n:l+n)===(r=(r=r||e.length)>=0?r:l+r)||0===o)return[];if(n<r&&o<0)return[];if(n>r&&o>0)return[];if(o>0)for(i=n;i<r;i+=o)a.push(e[i]);else for(i=n;i>r;i+=o)a.push(e[i]);return a}return function(t,n){var r,o;return s((n=n||{}).row)?s(n.col)?t[n.row][n.col]:e(u.rowa(t,n.row),(r=n.col||{}).start,r.end,r.step):s(n.col)?e(u.cola(t,n.col),(o=n.row||{}).start,o.end,o.step):(o=n.row||{},r=n.col||{},e(t,o.start,o.end,o.step).map((function(t){return e(t,r.start,r.end,r.step)})))}}(),u.sliceAssign=function(n,r,o){var i,a;if(s(r.row)){if(s(r.col))return n[r.row][r.col]=o;r.col=r.col||{},r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,i=u.arange(r.col.start,e.min(n.length,r.col.end),r.col.step);var l=r.row;return i.forEach((function(e,t){n[l][e]=o[t]})),n}if(s(r.col)){r.row=r.row||{},r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,a=u.arange(r.row.start,e.min(n[0].length,r.row.end),r.row.step);var c=r.col;return a.forEach((function(e,t){n[e][c]=o[t]})),n}return o[0].length===t&&(o=[o]),r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,a=u.arange(r.row.start,e.min(n.length,r.row.end),r.row.step),i=u.arange(r.col.start,e.min(n[0].length,r.col.end),r.col.step),a.forEach((function(e,t){i.forEach((function(r,i){n[e][r]=o[t][i]}))})),n},u.diagonal=function(e){var t=u.zeros(e.length,e.length);return e.forEach((function(e,n){t[n][n]=e})),t},u.copy=function(e){return e.map((function(e){return s(e)?e:e.map((function(e){return e}))}))};var m=u.prototype;return m.length=0,m.push=Array.prototype.push,m.sort=Array.prototype.sort,m.splice=Array.prototype.splice,m.slice=Array.prototype.slice,m.toArray=function(){return this.length>1?r.call(this):r.call(this)[0]},m.map=function(e,t){return u(u.map(this,e,t))},m.cumreduce=function(e,t){return u(u.cumreduce(this,e,t))},m.alter=function(e){return u.alter(this,e),this},function(e){for(var t=0;t<e.length;t++)!function(e){m[e]=function(t){var n,r=this;return t?(setTimeout((function(){t.call(r,m[e].call(r))})),this):(n=u[e](this),a(n)?u(n):n)}}(e[t])}("transpose clear symmetric rows cols dimensions diag antidiag".split(" ")),function(e){for(var t=0;t<e.length;t++)!function(e){m[e]=function(t,n){var r=this;return n?(setTimeout((function(){n.call(r,m[e].call(r,t))})),this):u(u[e](this,t))}}(e[t])}("row col".split(" ")),function(e){for(var t=0;t<e.length;t++)!function(e){m[e]=function(){return u(u[e].apply(null,arguments))}}(e[t])}("create zeros ones rand identity".split(" ")),u}(Math),function(e,t){var n=e.utils.isFunction;function r(e,t){return e-t}function o(e,n,r){return t.max(n,t.min(e,r))}e.sum=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n];return t},e.sumsqrd=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n]*e[n];return t},e.sumsqerr=function(t){for(var n,r=e.mean(t),o=0,i=t.length;--i>=0;)o+=(n=t[i]-r)*n;return o},e.sumrow=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n];return t},e.product=function(e){for(var t=1,n=e.length;--n>=0;)t*=e[n];return t},e.min=function(e){for(var t=e[0],n=0;++n<e.length;)e[n]<t&&(t=e[n]);return t},e.max=function(e){for(var t=e[0],n=0;++n<e.length;)e[n]>t&&(t=e[n]);return t},e.unique=function(e){for(var t={},n=[],r=0;r<e.length;r++)t[e[r]]||(t[e[r]]=!0,n.push(e[r]));return n},e.mean=function(t){return e.sum(t)/t.length},e.meansqerr=function(t){return e.sumsqerr(t)/t.length},e.geomean=function(n){var r=n.map(t.log),o=e.mean(r);return t.exp(o)},e.median=function(e){var t=e.length,n=e.slice().sort(r);return 1&t?n[t/2|0]:(n[t/2-1]+n[t/2])/2},e.cumsum=function(t){return e.cumreduce(t,(function(e,t){return e+t}))},e.cumprod=function(t){return e.cumreduce(t,(function(e,t){return e*t}))},e.diff=function(e){var t,n=[],r=e.length;for(t=1;t<r;t++)n.push(e[t]-e[t-1]);return n},e.rank=function(e){var t,n=[],o={};for(t=0;t<e.length;t++)o[s=e[t]]?o[s]++:(o[s]=1,n.push(s));var i=n.sort(r),a={},l=1;for(t=0;t<i.length;t++){var s,u=o[s=i[t]],c=(l+(l+u-1))/2;a[s]=c,l+=u}return e.map((function(e){return a[e]}))},e.mode=function(e){var t,n=e.length,o=e.slice().sort(r),i=1,a=0,l=0,s=[];for(t=0;t<n;t++)o[t]===o[t+1]?i++:(i>a?(s=[o[t]],a=i,l=0):i===a&&(s.push(o[t]),l++),i=1);return 0===l?s[0]:s},e.range=function(t){return e.max(t)-e.min(t)},e.variance=function(t,n){return e.sumsqerr(t)/(t.length-(n?1:0))},e.pooledvariance=function(t){return t.reduce((function(t,n){return t+e.sumsqerr(n)}),0)/(t.reduce((function(e,t){return e+t.length}),0)-t.length)},e.deviation=function(t){for(var n=e.mean(t),r=t.length,o=new Array(r),i=0;i<r;i++)o[i]=t[i]-n;return o},e.stdev=function(n,r){return t.sqrt(e.variance(n,r))},e.pooledstdev=function(n){return t.sqrt(e.pooledvariance(n))},e.meandev=function(n){for(var r=e.mean(n),o=[],i=n.length-1;i>=0;i--)o.push(t.abs(n[i]-r));return e.mean(o)},e.meddev=function(n){for(var r=e.median(n),o=[],i=n.length-1;i>=0;i--)o.push(t.abs(n[i]-r));return e.median(o)},e.coeffvar=function(t){return e.stdev(t)/e.mean(t)},e.quartiles=function(e){var n=e.length,o=e.slice().sort(r);return[o[t.round(n/4)-1],o[t.round(n/2)-1],o[t.round(3*n/4)-1]]},e.quantiles=function(e,n,i,a){var l,s,u,c,f,d=e.slice().sort(r),m=[n.length],h=e.length;for(void 0===i&&(i=3/8),void 0===a&&(a=3/8),l=0;l<n.length;l++)u=h*(s=n[l])+(i+s*(1-i-a)),c=t.floor(o(u,1,h-1)),f=o(u-c,0,1),m[l]=(1-f)*d[c-1]+f*d[c];return m},e.percentile=function(e,t,n){var o=e.slice().sort(r),i=t*(o.length+(n?1:-1))+(n?0:1),a=parseInt(i),l=i-a;return a+1<o.length?o[a-1]+l*(o[a]-o[a-1]):o[a-1]},e.percentileOfScore=function(e,t,n){var r,o,i=0,a=e.length,l=!1;for("strict"===n&&(l=!0),o=0;o<a;o++)r=e[o],(l&&r<t||!l&&r<=t)&&i++;return i/a},e.histogram=function(n,r){r=r||4;var o,i=e.min(n),a=(e.max(n)-i)/r,l=n.length,s=[];for(o=0;o<r;o++)s[o]=0;for(o=0;o<l;o++)s[t.min(t.floor((n[o]-i)/a),r-1)]+=1;return s},e.covariance=function(t,n){var r,o=e.mean(t),i=e.mean(n),a=t.length,l=new Array(a);for(r=0;r<a;r++)l[r]=(t[r]-o)*(n[r]-i);return e.sum(l)/(a-1)},e.corrcoeff=function(t,n){return e.covariance(t,n)/e.stdev(t,1)/e.stdev(n,1)},e.spearmancoeff=function(t,n){return t=e.rank(t),n=e.rank(n),e.corrcoeff(t,n)},e.stanMoment=function(n,r){for(var o=e.mean(n),i=e.stdev(n),a=n.length,l=0,s=0;s<a;s++)l+=t.pow((n[s]-o)/i,r);return l/n.length},e.skewness=function(t){return e.stanMoment(t,3)},e.kurtosis=function(t){return e.stanMoment(t,4)-3};var i=e.prototype;!function(t){for(var r=0;r<t.length;r++)!function(t){i[t]=function(r,o){var a=[],l=0,s=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(s,i[t].call(s,r))})),this;if(this.length>1){for(s=!0===r?this:this.transpose();l<s.length;l++)a[l]=e[t](s[l]);return a}return e[t](this[0],r)}}(t[r])}("cumsum cumprod".split(" ")),function(t){for(var r=0;r<t.length;r++)!function(t){i[t]=function(r,o){var a=[],l=0,s=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(s,i[t].call(s,r))})),this;if(this.length>1){for("sumrow"!==t&&(s=!0===r?this:this.transpose());l<s.length;l++)a[l]=e[t](s[l]);return!0===r?e[t](e.utils.toVector(a)):a}return e[t](this[0],r)}}(t[r])}("sum sumsqrd sumsqerr sumrow product min max unique mean meansqerr geomean median diff rank mode range variance deviation stdev meandev meddev coeffvar quartiles histogram skewness kurtosis".split(" ")),function(t){for(var r=0;r<t.length;r++)!function(t){i[t]=function(){var r,o=[],a=0,l=this,s=Array.prototype.slice.call(arguments);if(n(s[s.length-1])){r=s[s.length-1];var u=s.slice(0,s.length-1);return setTimeout((function(){r.call(l,i[t].apply(l,u))})),this}r=void 0;var c=function(n){return e[t].apply(l,[n].concat(s))};if(this.length>1){for(l=l.transpose();a<l.length;a++)o[a]=c(l[a]);return o}return c(this[0])}}(t[r])}("quantiles percentileOfScore".split(" "))}(t,Math),function(e,t){e.gammaln=function(e){var n,r,o,i=0,a=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],l=1.000000000190015;for(o=(r=n=e)+5.5,o-=(n+.5)*t.log(o);i<6;i++)l+=a[i]/++r;return t.log(2.5066282746310007*l/n)-o},e.loggam=function(e){var n,r,o,i,a,l,s,u=[.08333333333333333,-.002777777777777778,.0007936507936507937,-.0005952380952380952,.0008417508417508418,-.001917526917526918,.00641025641025641,-.02955065359477124,.1796443723688307,-1.3924322169059];if(n=e,s=0,1==e||2==e)return 0;for(e<=7&&(n=e+(s=t.floor(7-e))),r=1/(n*n),o=2*t.PI,a=u[9],l=8;l>=0;l--)a*=r,a+=u[l];if(i=a/n+.5*t.log(o)+(n-.5)*t.log(n)-n,e<=7)for(l=1;l<=s;l++)i-=t.log(n-1),n-=1;return i},e.gammafn=function(e){var n,r,o,i,a=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],l=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],s=!1,u=0,c=0,f=0,d=e;if(e>171.6243769536076)return 1/0;if(d<=0){if(!(i=d%1+36e-17))return 1/0;s=(1&d?-1:1)*t.PI/t.sin(t.PI*i),d=1-d}for(o=d,r=d<1?d++:(d-=u=(0|d)-1)-1,n=0;n<8;++n)f=(f+a[n])*r,c=c*r+l[n];if(i=f/c+1,o<d)i/=o;else if(o>d)for(n=0;n<u;++n)i*=d,d++;return s&&(i=s/i),i},e.gammap=function(t,n){return e.lowRegGamma(t,n)*e.gammafn(t)},e.lowRegGamma=function(n,r){var o,i=e.gammaln(n),a=n,l=1/n,s=l,u=r+1-n,c=1/1e-30,f=1/u,d=f,m=1,h=-~(8.5*t.log(n>=1?n:1/n)+.4*n+17);if(r<0||n<=0)return NaN;if(r<n+1){for(;m<=h;m++)l+=s*=r/++a;return l*t.exp(-r+n*t.log(r)-i)}for(;m<=h;m++)d*=(f=1/(f=(o=-m*(m-n))*f+(u+=2)))*(c=u+o/c);return 1-d*t.exp(-r+n*t.log(r)-i)},e.factorialln=function(t){return t<0?NaN:e.gammaln(t+1)},e.factorial=function(t){return t<0?NaN:e.gammafn(t+1)},e.combination=function(n,r){return n>170||r>170?t.exp(e.combinationln(n,r)):e.factorial(n)/e.factorial(r)/e.factorial(n-r)},e.combinationln=function(t,n){return e.factorialln(t)-e.factorialln(n)-e.factorialln(t-n)},e.permutation=function(t,n){return e.factorial(t)/e.factorial(t-n)},e.betafn=function(n,r){if(!(n<=0||r<=0))return n+r>170?t.exp(e.betaln(n,r)):e.gammafn(n)*e.gammafn(r)/e.gammafn(n+r)},e.betaln=function(t,n){return e.gammaln(t)+e.gammaln(n)-e.gammaln(t+n)},e.betacf=function(e,n,r){var o,i,a,l,s=1e-30,u=1,c=n+r,f=n+1,d=n-1,m=1,h=1-c*e/f;for(t.abs(h)<s&&(h=s),l=h=1/h;u<=100&&(h=1+(i=u*(r-u)*e/((d+(o=2*u))*(n+o)))*h,t.abs(h)<s&&(h=s),m=1+i/m,t.abs(m)<s&&(m=s),l*=(h=1/h)*m,h=1+(i=-(n+u)*(c+u)*e/((n+o)*(f+o)))*h,t.abs(h)<s&&(h=s),m=1+i/m,t.abs(m)<s&&(m=s),l*=a=(h=1/h)*m,!(t.abs(a-1)<3e-7));u++);return l},e.gammapinv=function(n,r){var o,i,a,l,s,u,c=0,f=r-1,d=e.gammaln(r);if(n>=1)return t.max(100,r+100*t.sqrt(r));if(n<=0)return 0;for(r>1?(s=t.log(f),u=t.exp(f*(s-1)-d),l=n<.5?n:1-n,o=(2.30753+.27061*(i=t.sqrt(-2*t.log(l))))/(1+i*(.99229+.04481*i))-i,n<.5&&(o=-o),o=t.max(.001,r*t.pow(1-1/(9*r)-o/(3*t.sqrt(r)),3))):o=n<(i=1-r*(.253+.12*r))?t.pow(n/i,1/r):1-t.log(1-(n-i)/(1-i));c<12;c++){if(o<=0)return 0;if((o-=i=(a=(e.lowRegGamma(r,o)-n)/(i=r>1?u*t.exp(-(o-f)+f*(t.log(o)-s)):t.exp(-o+f*t.log(o)-d)))/(1-.5*t.min(1,a*((r-1)/o-1))))<=0&&(o=.5*(o+i)),t.abs(i)<1e-8*o)break}return o},e.erf=function(e){var n,r,o,i,a=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],l=a.length-1,s=!1,u=0,c=0;for(e<0&&(e=-e,s=!0),r=4*(n=2/(2+e))-2;l>0;l--)o=u,u=r*u-c+a[l],c=o;return i=n*t.exp(-e*e+.5*(a[0]+r*u)-c),s?i-1:1-i},e.erfc=function(t){return 1-e.erf(t)},e.erfcinv=function(n){var r,o,i,a,l=0;if(n>=2)return-100;if(n<=0)return 100;for(a=n<1?n:2-n,r=-.70711*((2.30753+.27061*(i=t.sqrt(-2*t.log(a/2))))/(1+i*(.99229+.04481*i))-i);l<2;l++)r+=(o=e.erfc(r)-a)/(1.1283791670955126*t.exp(-r*r)-r*o);return n<1?r:-r},e.ibetainv=function(n,r,o){var i,a,l,s,u,c,f,d,m,h,p=r-1,g=o-1,v=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&o>=1?(l=n<.5?n:1-n,c=(2.30753+.27061*(s=t.sqrt(-2*t.log(l))))/(1+s*(.99229+.04481*s))-s,n<.5&&(c=-c),f=(c*c-3)/6,d=2/(1/(2*r-1)+1/(2*o-1)),m=c*t.sqrt(f+d)/d-(1/(2*o-1)-1/(2*r-1))*(f+5/6-2/(3*d)),c=r/(r+o*t.exp(2*m))):(i=t.log(r/(r+o)),a=t.log(o/(r+o)),c=n<(s=t.exp(r*i)/r)/(m=s+(u=t.exp(o*a)/o))?t.pow(r*m*n,1/r):1-t.pow(o*m*(1-n),1/o)),h=-e.gammaln(r)-e.gammaln(o)+e.gammaln(r+o);v<10;v++){if(0===c||1===c)return c;if((c-=s=(u=(e.ibeta(c,r,o)-n)/(s=t.exp(p*t.log(c)+g*t.log(1-c)+h)))/(1-.5*t.min(1,u*(p/c-g/(1-c)))))<=0&&(c=.5*(c+s)),c>=1&&(c=.5*(c+s+1)),t.abs(s)<1e-8*c&&v>0)break}return c},e.ibeta=function(n,r,o){var i=0===n||1===n?0:t.exp(e.gammaln(r+o)-e.gammaln(r)-e.gammaln(o)+r*t.log(n)+o*t.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+o+2)?i*e.betacf(n,r,o)/r:1-i*e.betacf(1-n,o,r)/o)},e.randn=function(n,r){var o,i,a,l,s;if(r||(r=n),n)return e.create(n,r,(function(){return e.randn()}));do{o=e._random_fn(),i=1.7156*(e._random_fn()-.5),s=(a=o-.449871)*a+(l=t.abs(i)+.386595)*(.196*l-.25472*a)}while(s>.27597&&(s>.27846||i*i>-4*t.log(o)*o*o));return i/o},e.randg=function(n,r,o){var i,a,l,s,u,c,f=n;if(o||(o=r),n||(n=1),r)return(c=e.zeros(r,o)).alter((function(){return e.randg(n)})),c;n<1&&(n+=1),i=n-1/3,a=1/t.sqrt(9*i);do{do{s=1+a*(u=e.randn())}while(s<=0);s*=s*s,l=e._random_fn()}while(l>1-.331*t.pow(u,4)&&t.log(l)>.5*u*u+i*(1-s+t.log(s)));if(n==f)return i*s;do{l=e._random_fn()}while(0===l);return t.pow(l,1/f)*i*s},function(t){for(var n=0;n<t.length;n++)!function(t){e.fn[t]=function(){return e(e.map(this,(function(n){return e[t](n)})))}}(t[n])}("gammaln gammafn factorial factorialln".split(" ")),function(t){for(var n=0;n<t.length;n++)!function(t){e.fn[t]=function(){return e(e[t].apply(null,arguments))}}(t[n])}("randn".split(" "))}(t,Math),function(e,t){function n(e,n,r,o){for(var i,a=0,l=1,s=1,u=1,c=0,f=0;t.abs((s-f)/s)>o;)f=s,l=u+(i=-(n+c)*(n+r+c)*e/(n+2*c)/(n+2*c+1))*l,s=(a=s+i*a)+(i=(c+=1)*(r-c)*e/(n+2*c-1)/(n+2*c))*s,a/=u=l+i*u,l/=u,s/=u,u=1;return s/n}function r(n,r,o){var i=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],a=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],l=.5*n;if(l>=8)return 1;var s,u=2*e.normal.cdf(l,0,1,1,0)-1;u=u>=t.exp(-50/o)?t.pow(u,o):0;for(var c=l,f=(8-l)/(s=n>3?2:3),d=c+f,m=0,h=o-1,p=1;p<=s;p++){for(var g=0,v=.5*(d+c),_=.5*(d-c),T=1;T<=12;T++){var w,E=v+_*(6<T?i[(w=12-T+1)-1]:-i[(w=T)-1]),I=E*E;if(I>60)break;var y=2*e.normal.cdf(E,0,1,1,0)*.5-2*e.normal.cdf(E,n,1,1,0)*.5;y>=t.exp(-30/h)&&(g+=y=a[w-1]*t.exp(-.5*I)*t.pow(y,h))}m+=g*=2*_*o/t.sqrt(2*t.PI),c=d,d+=f}return(u+=m)<=t.exp(-30/r)?0:(u=t.pow(u,r))>=1?1:u}!function(t){for(var n=0;n<t.length;n++)!function(t){e[t]=function e(t,n,r){return this instanceof e?(this._a=t,this._b=n,this._c=r,this):new e(t,n,r)},e.fn[t]=function(n,r,o){var i=e[t](n,r,o);return i.data=this,i},e[t].prototype.sample=function(n){var r=this._a,o=this._b,i=this._c;return n?e.alter(n,(function(){return e[t].sample(r,o,i)})):e[t].sample(r,o,i)},function(n){for(var r=0;r<n.length;r++)!function(n){e[t].prototype[n]=function(r){var o=this._a,i=this._b,a=this._c;return r||0===r||(r=this.data),"number"!=typeof r?e.fn.map.call(r,(function(r){return e[t][n](r,o,i,a)})):e[t][n](r,o,i,a)}}(n[r])}("pdf cdf inv".split(" ")),function(n){for(var r=0;r<n.length;r++)!function(n){e[t].prototype[n]=function(){return e[t][n](this._a,this._b,this._c)}}(n[r])}("mean median mode variance".split(" "))}(t[n])}("beta centralF cauchy chisquare exponential gamma invgamma kumaraswamy laplace lognormal noncentralt normal pareto studentt weibull uniform binomial negbin hypgeom poisson triangular tukey arcsine".split(" ")),e.extend(e.beta,{pdf:function(n,r,o){return n>1||n<0?0:1==r&&1==o?1:r<512&&o<512?t.pow(n,r-1)*t.pow(1-n,o-1)/e.betafn(r,o):t.exp((r-1)*t.log(n)+(o-1)*t.log(1-n)-e.betaln(r,o))},cdf:function(t,n,r){return t>1||t<0?1*(t>1):e.ibeta(t,n,r)},inv:function(t,n,r){return e.ibetainv(t,n,r)},mean:function(e,t){return e/(e+t)},median:function(t,n){return e.ibetainv(.5,t,n)},mode:function(e,t){return(e-1)/(e+t-2)},sample:function(t,n){var r=e.randg(t);return r/(r+e.randg(n))},variance:function(e,n){return e*n/(t.pow(e+n,2)*(e+n+1))}}),e.extend(e.centralF,{pdf:function(n,r,o){var i;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/e.betafn(r/2,o/2)*t.pow(r/o,r/2)*t.pow(n,r/2-1)*t.pow(1+r/o*n,-(r+o)/2):(i=r*n/(o+n*r),r*(o/(o+n*r))/2*e.binomial.pdf((r-2)/2,(r+o-2)/2,i))},cdf:function(t,n,r){return t<0?0:e.ibeta(n*t/(n*t+r),n/2,r/2)},inv:function(t,n,r){return r/(n*(1/e.ibetainv(t,n/2,r/2)-1))},mean:function(e,t){return t>2?t/(t-2):void 0},mode:function(e,t){return e>2?t*(e-2)/(e*(t+2)):void 0},sample:function(t,n){return 2*e.randg(t/2)/t/(2*e.randg(n/2)/n)},variance:function(e,t){if(!(t<=4))return 2*t*t*(e+t-2)/(e*(t-2)*(t-2)*(t-4))}}),e.extend(e.cauchy,{pdf:function(e,n,r){return r<0?0:r/(t.pow(e-n,2)+t.pow(r,2))/t.PI},cdf:function(e,n,r){return t.atan((e-n)/r)/t.PI+.5},inv:function(e,n,r){return n+r*t.tan(t.PI*(e-.5))},median:function(e){return e},mode:function(e){return e},sample:function(n,r){return e.randn()*t.sqrt(1/(2*e.randg(.5)))*r+n}}),e.extend(e.chisquare,{pdf:function(n,r){return n<0?0:0===n&&2===r?.5:t.exp((r/2-1)*t.log(n)-n/2-r/2*t.log(2)-e.gammaln(r/2))},cdf:function(t,n){return t<0?0:e.lowRegGamma(n/2,t/2)},inv:function(t,n){return 2*e.gammapinv(t,.5*n)},mean:function(e){return e},median:function(e){return e*t.pow(1-2/(9*e),3)},mode:function(e){return e-2>0?e-2:0},sample:function(t){return 2*e.randg(t/2)},variance:function(e){return 2*e}}),e.extend(e.exponential,{pdf:function(e,n){return e<0?0:n*t.exp(-n*e)},cdf:function(e,n){return e<0?0:1-t.exp(-n*e)},inv:function(e,n){return-t.log(1-e)/n},mean:function(e){return 1/e},median:function(e){return 1/e*t.log(2)},mode:function(){return 0},sample:function(n){return-1/n*t.log(e._random_fn())},variance:function(e){return t.pow(e,-2)}}),e.extend(e.gamma,{pdf:function(n,r,o){return n<0?0:0===n&&1===r?1/o:t.exp((r-1)*t.log(n)-n/o-e.gammaln(r)-r*t.log(o))},cdf:function(t,n,r){return t<0?0:e.lowRegGamma(n,t/r)},inv:function(t,n,r){return e.gammapinv(t,n)*r},mean:function(e,t){return e*t},mode:function(e,t){if(e>1)return(e-1)*t},sample:function(t,n){return e.randg(t)*n},variance:function(e,t){return e*t*t}}),e.extend(e.invgamma,{pdf:function(n,r,o){return n<=0?0:t.exp(-(r+1)*t.log(n)-o/n-e.gammaln(r)+r*t.log(o))},cdf:function(t,n,r){return t<=0?0:1-e.lowRegGamma(n,r/t)},inv:function(t,n,r){return r/e.gammapinv(1-t,n)},mean:function(e,t){return e>1?t/(e-1):void 0},mode:function(e,t){return t/(e+1)},sample:function(t,n){return n/e.randg(t)},variance:function(e,t){if(!(e<=2))return t*t/((e-1)*(e-1)*(e-2))}}),e.extend(e.kumaraswamy,{pdf:function(e,n,r){return 0===e&&1===n?r:1===e&&1===r?n:t.exp(t.log(n)+t.log(r)+(n-1)*t.log(e)+(r-1)*t.log(1-t.pow(e,n)))},cdf:function(e,n,r){return e<0?0:e>1?1:1-t.pow(1-t.pow(e,n),r)},inv:function(e,n,r){return t.pow(1-t.pow(1-e,1/r),1/n)},mean:function(t,n){return n*e.gammafn(1+1/t)*e.gammafn(n)/e.gammafn(1+1/t+n)},median:function(e,n){return t.pow(1-t.pow(2,-1/n),1/e)},mode:function(e,n){if(e>=1&&n>=1&&1!==e&&1!==n)return t.pow((e-1)/(e*n-1),1/e)},variance:function(){throw new Error("variance not yet implemented")}}),e.extend(e.lognormal,{pdf:function(e,n,r){return e<=0?0:t.exp(-t.log(e)-.5*t.log(2*t.PI)-t.log(r)-t.pow(t.log(e)-n,2)/(2*r*r))},cdf:function(n,r,o){return n<0?0:.5+.5*e.erf((t.log(n)-r)/t.sqrt(2*o*o))},inv:function(n,r,o){return t.exp(-1.4142135623730951*o*e.erfcinv(2*n)+r)},mean:function(e,n){return t.exp(e+n*n/2)},median:function(e){return t.exp(e)},mode:function(e,n){return t.exp(e-n*n)},sample:function(n,r){return t.exp(e.randn()*r+n)},variance:function(e,n){return(t.exp(n*n)-1)*t.exp(2*e+n*n)}}),e.extend(e.noncentralt,{pdf:function(n,r,o){return t.abs(o)<1e-14?e.studentt.pdf(n,r):t.abs(n)<1e-14?t.exp(e.gammaln((r+1)/2)-o*o/2-.5*t.log(t.PI*r)-e.gammaln(r/2)):r/n*(e.noncentralt.cdf(n*t.sqrt(1+2/r),r+2,o)-e.noncentralt.cdf(n,r,o))},cdf:function(n,r,o){var i=1e-14;if(t.abs(o)<i)return e.studentt.cdf(n,r);var a=!1;n<0&&(a=!0,o=-o);for(var l=e.normal.cdf(-o,0,1),s=i+1,u=s,c=n*n/(n*n+r),f=0,d=t.exp(-o*o/2),m=t.exp(-o*o/2-.5*t.log(2)-e.gammaln(1.5))*o;f<200||u>i||s>i;)u=s,f>0&&(d*=o*o/(2*f),m*=o*o/(2*(f+.5))),l+=.5*(s=d*e.beta.cdf(c,f+.5,r/2)+m*e.beta.cdf(c,f+1,r/2)),f++;return a?1-l:l}}),e.extend(e.normal,{pdf:function(e,n,r){return t.exp(-.5*t.log(2*t.PI)-t.log(r)-t.pow(e-n,2)/(2*r*r))},cdf:function(n,r,o){return.5*(1+e.erf((n-r)/t.sqrt(2*o*o)))},inv:function(t,n,r){return-1.4142135623730951*r*e.erfcinv(2*t)+n},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},sample:function(t,n){return e.randn()*n+t},variance:function(e,t){return t*t}}),e.extend(e.pareto,{pdf:function(e,n,r){return e<n?0:r*t.pow(n,r)/t.pow(e,r+1)},cdf:function(e,n,r){return e<n?0:1-t.pow(n/e,r)},inv:function(e,n,r){return n/t.pow(1-e,1/r)},mean:function(e,n){if(!(n<=1))return n*t.pow(e,n)/(n-1)},median:function(e,n){return e*(n*t.SQRT2)},mode:function(e){return e},variance:function(e,n){if(!(n<=2))return e*e*n/(t.pow(n-1,2)*(n-2))}}),e.extend(e.studentt,{pdf:function(n,r){return r=r>1e100?1e100:r,1/(t.sqrt(r)*e.betafn(.5,r/2))*t.pow(1+n*n/r,-(r+1)/2)},cdf:function(n,r){var o=r/2;return e.ibeta((n+t.sqrt(n*n+r))/(2*t.sqrt(n*n+r)),o,o)},inv:function(n,r){var o=e.ibetainv(2*t.min(n,1-n),.5*r,.5);return o=t.sqrt(r*(1-o)/o),n>.5?o:-o},mean:function(e){return e>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(n){return e.randn()*t.sqrt(n/(2*e.randg(n/2)))},variance:function(e){return e>2?e/(e-2):e>1?1/0:void 0}}),e.extend(e.weibull,{pdf:function(e,n,r){return e<0||n<0||r<0?0:r/n*t.pow(e/n,r-1)*t.exp(-t.pow(e/n,r))},cdf:function(e,n,r){return e<0?0:1-t.exp(-t.pow(e/n,r))},inv:function(e,n,r){return n*t.pow(-t.log(1-e),1/r)},mean:function(t,n){return t*e.gammafn(1+1/n)},median:function(e,n){return e*t.pow(t.log(2),1/n)},mode:function(e,n){return n<=1?0:e*t.pow((n-1)/n,1/n)},sample:function(n,r){return n*t.pow(-t.log(e._random_fn()),1/r)},variance:function(n,r){return n*n*e.gammafn(1+2/r)-t.pow(e.weibull.mean(n,r),2)}}),e.extend(e.uniform,{pdf:function(e,t,n){return e<t||e>n?0:1/(n-t)},cdf:function(e,t,n){return e<t?0:e<n?(e-t)/(n-t):1},inv:function(e,t,n){return t+e*(n-t)},mean:function(e,t){return.5*(e+t)},median:function(t,n){return e.mean(t,n)},mode:function(){throw new Error("mode is not yet implemented")},sample:function(t,n){return t/2+n/2+(n/2-t/2)*(2*e._random_fn()-1)},variance:function(e,n){return t.pow(n-e,2)/12}}),e.extend(e.binomial,{pdf:function(n,r,o){return 0===o||1===o?r*o===n?1:0:e.combination(r,n)*t.pow(o,n)*t.pow(1-o,r-n)},cdf:function(r,o,i){var a,l=1e-10;if(r<0)return 0;if(r>=o)return 1;if(i<0||i>1||o<=0)return NaN;var s=i,u=(r=t.floor(r))+1,c=o-r,f=u+c,d=t.exp(e.gammaln(f)-e.gammaln(c)-e.gammaln(u)+u*t.log(s)+c*t.log(1-s));return a=s<(u+1)/(f+2)?d*n(s,u,c,l):1-d*n(1-s,c,u,l),t.round(1/l*(1-a))/(1/l)}}),e.extend(e.negbin,{pdf:function(n,r,o){return n===n>>>0&&(n<0?0:e.combination(n+r-1,r-1)*t.pow(1-o,n)*t.pow(o,r))},cdf:function(t,n,r){var o=0,i=0;if(t<0)return 0;for(;i<=t;i++)o+=e.negbin.pdf(i,n,r);return o}}),e.extend(e.hypgeom,{pdf:function(n,r,o,i){if(n!=n|0)return!1;if(n<0||n<o-(r-i))return 0;if(n>i||n>o)return 0;if(2*o>r)return 2*i>r?e.hypgeom.pdf(r-o-i+n,r,r-o,r-i):e.hypgeom.pdf(i-n,r,r-o,i);if(2*i>r)return e.hypgeom.pdf(o-n,r,o,r-i);if(o<i)return e.hypgeom.pdf(n,r,i,o);for(var a=1,l=0,s=0;s<n;s++){for(;a>1&&l<i;)a*=1-o/(r-l),l++;a*=(i-s)*(o-s)/((s+1)*(r-o-i+s+1))}for(;l<i;l++)a*=1-o/(r-l);return t.min(1,t.max(0,a))},cdf:function(n,r,o,i){if(n<0||n<o-(r-i))return 0;if(n>=i||n>=o)return 1;if(2*o>r)return 2*i>r?e.hypgeom.cdf(r-o-i+n,r,r-o,r-i):1-e.hypgeom.cdf(i-n-1,r,r-o,i);if(2*i>r)return 1-e.hypgeom.cdf(o-n-1,r,o,r-i);if(o<i)return e.hypgeom.cdf(n,r,i,o);for(var a=1,l=1,s=0,u=0;u<n;u++){for(;a>1&&s<i;){var c=1-o/(r-s);l*=c,a*=c,s++}a+=l*=(i-u)*(o-u)/((u+1)*(r-o-i+u+1))}for(;s<i;s++)a*=1-o/(r-s);return t.min(1,t.max(0,a))}}),e.extend(e.poisson,{pdf:function(n,r){return r<0||n%1!=0||n<0?0:t.pow(r,n)*t.exp(-r)/e.factorial(n)},cdf:function(t,n){var r=[],o=0;if(t<0)return 0;for(;o<=t;o++)r.push(e.poisson.pdf(o,n));return e.sum(r)},mean:function(e){return e},variance:function(e){return e},sampleSmall:function(n){var r=1,o=0,i=t.exp(-n);do{o++,r*=e._random_fn()}while(r>i);return o-1},sampleLarge:function(n){var r,o,i,a,l,s,u,c,f,d,m=n;for(a=t.sqrt(m),l=t.log(m),s=.02483*(u=.931+2.53*a)-.059,c=1.1239+1.1328/(u-3.4),f=.9277-3.6224/(u-2);;){if(o=t.random()-.5,i=t.random(),d=.5-t.abs(o),r=t.floor((2*s/d+u)*o+m+.43),d>=.07&&i<=f)return r;if(!(r<0||d<.013&&i>d)&&t.log(i)+t.log(c)-t.log(s/(d*d)+u)<=r*l-m-e.loggam(r+1))return r}},sample:function(e){return e<10?this.sampleSmall(e):this.sampleLarge(e)}}),e.extend(e.triangular,{pdf:function(e,t,n,r){return n<=t||r<t||r>n?NaN:e<t||e>n?0:e<r?2*(e-t)/((n-t)*(r-t)):e===r?2/(n-t):2*(n-e)/((n-t)*(n-r))},cdf:function(e,n,r,o){return r<=n||o<n||o>r?NaN:e<=n?0:e>=r?1:e<=o?t.pow(e-n,2)/((r-n)*(o-n)):1-t.pow(r-e,2)/((r-n)*(r-o))},inv:function(e,n,r,o){return r<=n||o<n||o>r?NaN:e<=(o-n)/(r-n)?n+(r-n)*t.sqrt(e*((o-n)/(r-n))):n+(r-n)*(1-t.sqrt((1-e)*(1-(o-n)/(r-n))))},mean:function(e,t,n){return(e+t+n)/3},median:function(e,n,r){return r<=(e+n)/2?n-t.sqrt((n-e)*(n-r))/t.sqrt(2):r>(e+n)/2?e+t.sqrt((n-e)*(r-e))/t.sqrt(2):void 0},mode:function(e,t,n){return n},sample:function(n,r,o){var i=e._random_fn();return i<(o-n)/(r-n)?n+t.sqrt(i*(r-n)*(o-n)):r-t.sqrt((1-i)*(r-n)*(r-o))},variance:function(e,t,n){return(e*e+t*t+n*n-e*t-e*n-t*n)/18}}),e.extend(e.arcsine,{pdf:function(e,n,r){return r<=n?NaN:e<=n||e>=r?0:2/t.PI*t.pow(t.pow(r-n,2)-t.pow(2*e-n-r,2),-.5)},cdf:function(e,n,r){return e<n?0:e<r?2/t.PI*t.asin(t.sqrt((e-n)/(r-n))):1},inv:function(e,n,r){return n+(.5-.5*t.cos(t.PI*e))*(r-n)},mean:function(e,t){return t<=e?NaN:(e+t)/2},median:function(e,t){return t<=e?NaN:(e+t)/2},mode:function(){throw new Error("mode is not yet implemented")},sample:function(n,r){return(n+r)/2+(r-n)/2*t.sin(2*t.PI*e.uniform.sample(0,1))},variance:function(e,n){return n<=e?NaN:t.pow(n-e,2)/8}}),e.extend(e.laplace,{pdf:function(e,n,r){return r<=0?0:t.exp(-t.abs(e-n)/r)/(2*r)},cdf:function(e,n,r){return r<=0?0:e<n?.5*t.exp((e-n)/r):1-.5*t.exp(-(e-n)/r)},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},variance:function(e,t){return 2*t*t},sample:function(n,r){var o,i=e._random_fn()-.5;return n-r*((o=i)/t.abs(o))*t.log(1-2*t.abs(i))}}),e.extend(e.tukey,{cdf:function(n,o,i){var a=o,l=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],s=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(i<2||a<2)return NaN;if(!Number.isFinite(n))return 1;if(i>25e3)return r(n,1,a);var u,c=.5*i,f=c*t.log(i)-i*t.log(2)-e.gammaln(c),d=c-1,m=.25*i;u=i<=100?1:i<=800?.5:i<=5e3?.25:.125,f+=t.log(u);for(var h=0,p=1;p<=50;p++){for(var g=0,v=(2*p-1)*u,_=1;_<=16;_++){var T,w;8<_?(T=_-8-1,w=f+d*t.log(v+l[T]*u)-(l[T]*u+v)*m):(T=_-1,w=f+d*t.log(v-l[T]*u)+(l[T]*u-v)*m),w>=-30&&(g+=r(8<_?n*t.sqrt(.5*(l[T]*u+v)):n*t.sqrt(.5*(-l[T]*u+v)),1,a)*s[T]*t.exp(w))}if(p*u>=1&&g<=1e-14)break;h+=g}if(g>1e-14)throw new Error("tukey.cdf failed to converge");return h>1&&(h=1),h},inv:function(n,r,o){if(o<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var i,a=function(e,n,r){var o=.5-.5*e,i=t.sqrt(t.log(1/(o*o))),a=i+((((-453642210148e-16*i-.204231210125)*i-.342242088547)*i-1)*i+.322232421088)/((((.0038560700634*i+.10353775285)*i+.531103462366)*i+.588581570495)*i+.099348462606);r<120&&(a+=(a*a*a+a)/r/4);var l=.8832-.2368*a;return r<120&&(l+=-1.214/r+1.208*a/r),a*(l*t.log(n-1)+1.4142)}(n,r,o),l=e.tukey.cdf(a,r,o)-n;i=l>0?t.max(0,a-1):a+1;for(var s,u=e.tukey.cdf(i,r,o)-n,c=1;c<50;c++)if(s=i-u*(i-a)/(u-l),l=u,a=i,s<0&&(s=0,u=-n),u=e.tukey.cdf(s,r,o)-n,i=s,t.abs(i-a)<1e-4)return s;throw new Error("tukey.inv failed to converge")}})}(t,Math),function(e,t){var n,r,o=Array.prototype.push,i=e.utils.isArray;function a(t){return i(t)||t instanceof e}e.extend({add:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.map(t,(function(e,t,r){return e+n[t][r]}))):e.map(t,(function(e){return e+n}))},subtract:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.map(t,(function(e,t,r){return e-n[t][r]||0}))):e.map(t,(function(e){return e-n}))},divide:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.multiply(t,e.inv(n))):e.map(t,(function(e){return e/n}))},multiply:function(t,n){var r,o,i,l,s,u,c,f;if(void 0===t.length&&void 0===n.length)return t*n;if(s=t.length,u=t[0].length,c=e.zeros(s,i=a(n)?n[0].length:u),f=0,a(n)){for(;f<i;f++)for(r=0;r<s;r++){for(l=0,o=0;o<u;o++)l+=t[r][o]*n[o][f];c[r][f]=l}return 1===s&&1===f?c[0][0]:c}return e.map(t,(function(e){return e*n}))},outer:function(t,n){return e.multiply(t.map((function(e){return[e]})),[n])},dot:function(t,n){a(t[0])||(t=[t]),a(n[0])||(n=[n]);for(var r,o,i=1===t[0].length&&1!==t.length?e.transpose(t):t,l=1===n[0].length&&1!==n.length?e.transpose(n):n,s=[],u=0,c=i.length,f=i[0].length;u<c;u++){for(s[u]=[],r=0,o=0;o<f;o++)r+=i[u][o]*l[u][o];s[u]=r}return 1===s.length?s[0]:s},pow:function(n,r){return e.map(n,(function(e){return t.pow(e,r)}))},exp:function(n){return e.map(n,(function(e){return t.exp(e)}))},log:function(n){return e.map(n,(function(e){return t.log(e)}))},abs:function(n){return e.map(n,(function(e){return t.abs(e)}))},norm:function(e,n){var r=0,o=0;for(isNaN(n)&&(n=2),a(e[0])&&(e=e[0]);o<e.length;o++)r+=t.pow(t.abs(e[o]),n);return t.pow(r,1/n)},angle:function(n,r){return t.acos(e.dot(n,r)/(e.norm(n)*e.norm(r)))},aug:function(e,t){var n,r=[];for(n=0;n<e.length;n++)r.push(e[n].slice());for(n=0;n<r.length;n++)o.apply(r[n],t[n]);return r},inv:function(t){for(var n,r=t.length,o=t[0].length,i=e.identity(r,o),a=e.gauss_jordan(t,i),l=[],s=0;s<r;s++)for(l[s]=[],n=o;n<a[0].length;n++)l[s][n-o]=a[s][n];return l},det:function e(t){if(2===t.length)return t[0][0]*t[1][1]-t[0][1]*t[1][0];for(var n=0,r=0;r<t.length;r++){for(var o=[],i=1;i<t.length;i++){o[i-1]=[];for(var a=0;a<t.length;a++)a<r?o[i-1][a]=t[i][a]:a>r&&(o[i-1][a-1]=t[i][a])}var l=r%2?-1:1;n+=e(o)*t[0][r]*l}return n},gauss_elimination:function(n,r){var o,i,a,l,s=0,u=0,c=n.length,f=n[0].length,d=1,m=0,h=[];for(o=(n=e.aug(n,r))[0].length,s=0;s<c;s++){for(i=n[s][s],u=s,l=s+1;l<f;l++)i<t.abs(n[l][s])&&(i=n[l][s],u=l);if(u!=s)for(l=0;l<o;l++)a=n[s][l],n[s][l]=n[u][l],n[u][l]=a;for(u=s+1;u<c;u++)for(d=n[u][s]/n[s][s],l=s;l<o;l++)n[u][l]=n[u][l]-d*n[s][l]}for(s=c-1;s>=0;s--){for(m=0,u=s+1;u<=c-1;u++)m+=h[u]*n[s][u];h[s]=(n[s][o-1]-m)/n[s][s]}return h},gauss_jordan:function(n,r){var o,i,a,l=e.aug(n,r),s=l.length,u=l[0].length,c=0;for(i=0;i<s;i++){var f=i;for(a=i+1;a<s;a++)t.abs(l[a][i])>t.abs(l[f][i])&&(f=a);var d=l[i];for(l[i]=l[f],l[f]=d,a=i+1;a<s;a++)for(c=l[a][i]/l[i][i],o=i;o<u;o++)l[a][o]-=l[i][o]*c}for(i=s-1;i>=0;i--){for(c=l[i][i],a=0;a<i;a++)for(o=u-1;o>i-1;o--)l[a][o]-=l[i][o]*l[a][i]/c;for(l[i][i]/=c,o=s;o<u;o++)l[i][o]/=c}return l},triaUpSolve:function(t,n){var r,o=t[0].length,i=e.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(e){return e[0]})),a=!0),e.arange(o-1,-1,-1).forEach((function(a){r=e.arange(a+1,o).map((function(e){return i[e]*t[a][e]})),i[a]=(n[a]-e.sum(r))/t[a][a]})),a?i.map((function(e){return[e]})):i},triaLowSolve:function(t,n){var r,o=t[0].length,i=e.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(e){return e[0]})),a=!0),e.arange(o).forEach((function(o){r=e.arange(o).map((function(e){return t[o][e]*i[e]})),i[o]=(n[o]-e.sum(r))/t[o][o]})),a?i.map((function(e){return[e]})):i},lu:function(t){var n,r=t.length,o=e.identity(r),i=e.zeros(t.length,t[0].length);return e.arange(r).forEach((function(e){i[0][e]=t[0][e]})),e.arange(1,r).forEach((function(a){e.arange(a).forEach((function(r){n=e.arange(r).map((function(e){return o[a][e]*i[e][r]})),o[a][r]=(t[a][r]-e.sum(n))/i[r][r]})),e.arange(a,r).forEach((function(r){n=e.arange(a).map((function(e){return o[a][e]*i[e][r]})),i[a][r]=t[n.length][r]-e.sum(n)}))})),[o,i]},cholesky:function(n){var r,o=n.length,i=e.zeros(n.length,n[0].length);return e.arange(o).forEach((function(a){r=e.arange(a).map((function(e){return t.pow(i[a][e],2)})),i[a][a]=t.sqrt(n[a][a]-e.sum(r)),e.arange(a+1,o).forEach((function(t){r=e.arange(a).map((function(e){return i[a][e]*i[t][e]})),i[t][a]=(n[a][t]-e.sum(r))/i[a][a]}))})),i},gauss_jacobi:function(n,r,o,i){for(var a,l,s,u,c=0,f=0,d=n.length,m=[],h=[],p=[];c<d;c++)for(m[c]=[],h[c]=[],p[c]=[],f=0;f<d;f++)c>f?(m[c][f]=n[c][f],h[c][f]=p[c][f]=0):c<f?(h[c][f]=n[c][f],m[c][f]=p[c][f]=0):(p[c][f]=n[c][f],m[c][f]=h[c][f]=0);for(s=e.multiply(e.multiply(e.inv(p),e.add(m,h)),-1),l=e.multiply(e.inv(p),r),a=o,u=e.add(e.multiply(s,o),l),c=2;t.abs(e.norm(e.subtract(u,a)))>i;)a=u,u=e.add(e.multiply(s,a),l),c++;return u},gauss_seidel:function(n,r,o,i){for(var a,l,s,u,c,f=0,d=n.length,m=[],h=[],p=[];f<d;f++)for(m[f]=[],h[f]=[],p[f]=[],a=0;a<d;a++)f>a?(m[f][a]=n[f][a],h[f][a]=p[f][a]=0):f<a?(h[f][a]=n[f][a],m[f][a]=p[f][a]=0):(p[f][a]=n[f][a],m[f][a]=h[f][a]=0);for(u=e.multiply(e.multiply(e.inv(e.add(p,m)),h),-1),s=e.multiply(e.inv(e.add(p,m)),r),l=o,c=e.add(e.multiply(u,o),s),f=2;t.abs(e.norm(e.subtract(c,l)))>i;)l=c,c=e.add(e.multiply(u,l),s),f+=1;return c},SOR:function(n,r,o,i,a){for(var l,s,u,c,f,d=0,m=n.length,h=[],p=[],g=[];d<m;d++)for(h[d]=[],p[d]=[],g[d]=[],l=0;l<m;l++)d>l?(h[d][l]=n[d][l],p[d][l]=g[d][l]=0):d<l?(p[d][l]=n[d][l],h[d][l]=g[d][l]=0):(g[d][l]=n[d][l],h[d][l]=p[d][l]=0);for(c=e.multiply(e.inv(e.add(g,e.multiply(h,a))),e.subtract(e.multiply(g,1-a),e.multiply(p,a))),u=e.multiply(e.multiply(e.inv(e.add(g,e.multiply(h,a))),r),a),s=o,f=e.add(e.multiply(c,o),u),d=2;t.abs(e.norm(e.subtract(f,s)))>i;)s=f,f=e.add(e.multiply(c,s),u),d++;return f},householder:function(n){for(var r,o,i,a,l=n.length,s=n[0].length,u=0,c=[],f=[];u<l-1;u++){for(r=0,a=u+1;a<s;a++)r+=n[a][u]*n[a][u];for(r=(n[u+1][u]>0?-1:1)*t.sqrt(r),o=t.sqrt((r*r-n[u+1][u]*r)/2),(c=e.zeros(l,1))[u+1][0]=(n[u+1][u]-r)/(2*o),i=u+2;i<l;i++)c[i][0]=n[i][u]/(2*o);f=e.subtract(e.identity(l,s),e.multiply(e.multiply(c,e.transpose(c)),2)),n=e.multiply(f,e.multiply(n,f))}return n},QR:(n=e.sum,r=e.arange,function(o){var i,a,l,s=o.length,u=o[0].length,c=e.zeros(u,u);for(o=e.copy(o),a=0;a<u;a++){for(c[a][a]=t.sqrt(n(r(s).map((function(e){return o[e][a]*o[e][a]})))),i=0;i<s;i++)o[i][a]=o[i][a]/c[a][a];for(l=a+1;l<u;l++)for(c[a][l]=n(r(s).map((function(e){return o[e][a]*o[e][l]}))),i=0;i<s;i++)o[i][l]=o[i][l]-o[i][a]*c[a][l]}return[o,c]}),lstsq:function(t,n){var r=!1;void 0===n[0].length&&(n=n.map((function(e){return[e]})),r=!0);var o=e.QR(t),i=o[0],a=o[1],l=t[0].length,s=e.slice(i,{col:{end:l}}),u=function(t){var n=(t=e.copy(t)).length,r=e.identity(n);return e.arange(n-1,-1,-1).forEach((function(n){e.sliceAssign(r,{row:n},e.divide(e.slice(r,{row:n}),t[n][n])),e.sliceAssign(t,{row:n},e.divide(e.slice(t,{row:n}),t[n][n])),e.arange(n).forEach((function(o){var i=e.multiply(t[o][n],-1),a=e.slice(t,{row:o}),l=e.multiply(e.slice(t,{row:n}),i);e.sliceAssign(t,{row:o},e.add(a,l));var s=e.slice(r,{row:o}),u=e.multiply(e.slice(r,{row:n}),i);e.sliceAssign(r,{row:o},e.add(s,u))}))})),r}(e.slice(a,{row:{end:l}})),c=e.transpose(s);void 0===c[0].length&&(c=[c]);var f=e.multiply(e.multiply(u,c),n);return void 0===f.length&&(f=[[f]]),r?f.map((function(e){return e[0]})):f},jacobi:function(n){for(var r,o,i,a,l,s,u,c=1,f=n.length,d=e.identity(f,f),m=[];1===c;){for(l=n[0][1],i=0,a=1,r=0;r<f;r++)for(o=0;o<f;o++)r!=o&&l<t.abs(n[r][o])&&(l=t.abs(n[r][o]),i=r,a=o);for(s=n[i][i]===n[a][a]?n[i][a]>0?t.PI/4:-t.PI/4:t.atan(2*n[i][a]/(n[i][i]-n[a][a]))/2,(u=e.identity(f,f))[i][i]=t.cos(s),u[i][a]=-t.sin(s),u[a][i]=t.sin(s),u[a][a]=t.cos(s),d=e.multiply(d,u),n=e.multiply(e.multiply(e.inv(u),n),u),c=0,r=1;r<f;r++)for(o=1;o<f;o++)r!=o&&t.abs(n[r][o])>.001&&(c=1)}for(r=0;r<f;r++)m.push(n[r][r]);return[d,m]},rungekutta:function(e,t,n,r,o,i){var a,l,s;if(2===i)for(;r<=n;)o+=((a=t*e(r,o))+(l=t*e(r+t,o+a)))/2,r+=t;if(4===i)for(;r<=n;)o+=((a=t*e(r,o))+2*(l=t*e(r+t/2,o+a/2))+2*(s=t*e(r+t/2,o+l/2))+t*e(r+t,o+s))/6,r+=t;return o},romberg:function(e,n,r,o){for(var i,a,l,s,u,c=0,f=(r-n)/2,d=[],m=[],h=[];c<o/2;){for(u=e(n),l=n,s=0;l<=r;l+=f,s++)d[s]=l;for(i=d.length,l=1;l<i-1;l++)u+=(l%2!=0?4:2)*e(d[l]);u=f/3*(u+e(r)),h[c]=u,f/=2,c++}for(a=h.length,i=1;1!==a;){for(l=0;l<a-1;l++)m[l]=(t.pow(4,i)*h[l+1]-h[l])/(t.pow(4,i)-1);a=m.length,h=m,m=[],i++}return h},richardson:function(e,n,r,o){function i(e,t){for(var n,r=0,o=e.length;r<o;r++)e[r]===t&&(n=r);return n}for(var a,l,s,u,c,f=t.abs(r-e[i(e,r)+1]),d=0,m=[],h=[];o>=f;)a=i(e,r+o),l=i(e,r),m[d]=(n[a]-2*n[l]+n[2*l-a])/(o*o),o/=2,d++;for(u=m.length,s=1;1!=u;){for(c=0;c<u-1;c++)h[c]=(t.pow(4,s)*m[c+1]-m[c])/(t.pow(4,s)-1);u=h.length,m=h,h=[],s++}return m},simpson:function(e,t,n,r){for(var o,i=(n-t)/r,a=e(t),l=[],s=t,u=0,c=1;s<=n;s+=i,u++)l[u]=s;for(o=l.length;c<o-1;c++)a+=(c%2!=0?4:2)*e(l[c]);return i/3*(a+e(n))},hermite:function(e,t,n,r){for(var o,i=e.length,a=0,l=0,s=[],u=[],c=[],f=[];l<i;l++){for(s[l]=1,o=0;o<i;o++)l!=o&&(s[l]*=(r-e[o])/(e[l]-e[o]));for(u[l]=0,o=0;o<i;o++)l!=o&&(u[l]+=1/(e[l]-e[o]));c[l]=(1-2*(r-e[l])*u[l])*(s[l]*s[l]),f[l]=(r-e[l])*(s[l]*s[l]),a+=c[l]*t[l]+f[l]*n[l]}return a},lagrange:function(e,t,n){for(var r,o,i=0,a=0,l=e.length;a<l;a++){for(o=t[a],r=0;r<l;r++)a!=r&&(o*=(n-e[r])/(e[a]-e[r]));i+=o}return i},cubic_spline:function(t,n,r){for(var o,i,a=t.length,l=0,s=[],u=[],c=[],f=[],d=[],m=[];l<a-1;l++)f[l]=t[l+1]-t[l];for(c[0]=0,l=1;l<a-1;l++)c[l]=3/f[l]*(n[l+1]-n[l])-3/f[l-1]*(n[l]-n[l-1]);for(l=1;l<a-1;l++)s[l]=[],u[l]=[],s[l][l-1]=f[l-1],s[l][l]=2*(f[l-1]+f[l]),s[l][l+1]=f[l],u[l][0]=c[l];for(i=e.multiply(e.inv(s),u),o=0;o<a-1;o++)d[o]=(n[o+1]-n[o])/f[o]-f[o]*(i[o+1][0]+2*i[o][0])/3,m[o]=(i[o+1][0]-i[o][0])/(3*f[o]);for(o=0;o<a&&!(t[o]>r);o++);return n[o-=1]+(r-t[o])*d[o]+e.sq(r-t[o])*i[o]+(r-t[o])*e.sq(r-t[o])*m[o]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(t){var n,r,o,i,a,l=t.length,s=t[0].length,u=0,c=[],f=[],d=[],m=[],h=[],p=[],g=[];for(u=0;u<l;u++)c[u]=e.sum(t[u])/s;for(u=0;u<s;u++)for(h[u]=[],n=0;n<l;n++)h[u][n]=t[n][u]-c[n];for(h=e.transpose(h),u=0;u<l;u++)for(p[u]=[],n=0;n<l;n++)p[u][n]=e.dot([h[u]],[h[n]])/(s-1);for(a=(o=e.jacobi(p))[0],f=o[1],g=e.transpose(a),u=0;u<f.length;u++)for(n=u;n<f.length;n++)f[u]<f[n]&&(r=f[u],f[u]=f[n],f[n]=r,d=g[u],g[u]=g[n],g[n]=d);for(i=e.transpose(h),u=0;u<l;u++)for(m[u]=[],n=0;n<i.length;n++)m[u][n]=e.dot([g[u]],[i[n]]);return[t,f,g,m]}}),function(t){for(var n=0;n<t.length;n++)!function(t){e.fn[t]=function(n,r){var o=this;return r?(setTimeout((function(){r.call(o,e.fn[t].call(o,n))}),15),this):"number"==typeof e[t](this,n)?e[t](this,n):e(e[t](this,n))}}(t[n])}("add divide multiply subtract dot pow exp log abs norm angle".split(" "))}(t,Math),function(e,t){var n=[].slice,r=e.utils.isNumber,o=e.utils.isArray;function i(e,n,r,o){if(e>1||r>1||e<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var i=(e*n+r*o)/(n+o);return(e-r)/t.sqrt(i*(1-i)*(1/n+1/o))}e.extend({zscore:function(){var t=n.call(arguments);return r(t[1])?(t[0]-t[1])/t[2]:(t[0]-e.mean(t[1]))/e.stdev(t[1],t[2])},ztest:function(){var r,i=n.call(arguments);return o(i[1])?(r=e.zscore(i[0],i[1],i[3]),1===i[2]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1)):i.length>2?(r=e.zscore(i[0],i[1],i[2]),1===i[3]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1)):(r=i[0],1===i[1]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1))}}),e.extend(e.fn,{zscore:function(e,t){return(e-this.mean())/this.stdev(t)},ztest:function(n,r,o){var i=t.abs(this.zscore(n,o));return 1===r?e.normal.cdf(-i,0,1):2*e.normal.cdf(-i,0,1)}}),e.extend({tscore:function(){var r=n.call(arguments);return 4===r.length?(r[0]-r[1])/(r[2]/t.sqrt(r[3])):(r[0]-e.mean(r[1]))/(e.stdev(r[1],!0)/t.sqrt(r[1].length))},ttest:function(){var o,i=n.call(arguments);return 5===i.length?(o=t.abs(e.tscore(i[0],i[1],i[2],i[3])),1===i[4]?e.studentt.cdf(-o,i[3]-1):2*e.studentt.cdf(-o,i[3]-1)):r(i[1])?(o=t.abs(i[0]),1==i[2]?e.studentt.cdf(-o,i[1]-1):2*e.studentt.cdf(-o,i[1]-1)):(o=t.abs(e.tscore(i[0],i[1])),1==i[2]?e.studentt.cdf(-o,i[1].length-1):2*e.studentt.cdf(-o,i[1].length-1))}}),e.extend(e.fn,{tscore:function(e){return(e-this.mean())/(this.stdev(!0)/t.sqrt(this.cols()))},ttest:function(n,r){return 1===r?1-e.studentt.cdf(t.abs(this.tscore(n)),this.cols()-1):2*e.studentt.cdf(-t.abs(this.tscore(n)),this.cols()-1)}}),e.extend({anovafscore:function(){var r,o,i,a,l,s,u,c,f=n.call(arguments);if(1===f.length){for(l=new Array(f[0].length),u=0;u<f[0].length;u++)l[u]=f[0][u];f=l}for(o=new Array,u=0;u<f.length;u++)o=o.concat(f[u]);for(i=e.mean(o),r=0,u=0;u<f.length;u++)r+=f[u].length*t.pow(e.mean(f[u])-i,2);for(r/=f.length-1,s=0,u=0;u<f.length;u++)for(a=e.mean(f[u]),c=0;c<f[u].length;c++)s+=t.pow(f[u][c]-a,2);return r/(s/(o.length-f.length))},anovaftest:function(){var t,o,i,a,l=n.call(arguments);if(r(l[0]))return 1-e.centralF.cdf(l[0],l[1],l[2]);var s=e.anovafscore(l);for(t=l.length-1,i=0,a=0;a<l.length;a++)i+=l[a].length;return o=i-t-1,1-e.centralF.cdf(s,t,o)},ftest:function(t,n,r){return 1-e.centralF.cdf(t,n,r)}}),e.extend(e.fn,{anovafscore:function(){return e.anovafscore(this.toArray())},anovaftes:function(){var t,n=0;for(t=0;t<this.length;t++)n+=this[t].length;return e.ftest(this.anovafscore(),this.length-1,n-this.length)}}),e.extend({qscore:function(){var o,i,a,l,s,u=n.call(arguments);return r(u[0])?(o=u[0],i=u[1],a=u[2],l=u[3],s=u[4]):(o=e.mean(u[0]),i=e.mean(u[1]),a=u[0].length,l=u[1].length,s=u[2]),t.abs(o-i)/(s*t.sqrt((1/a+1/l)/2))},qtest:function(){var t,r=n.call(arguments);3===r.length?(t=r[0],r=r.slice(1)):7===r.length?(t=e.qscore(r[0],r[1],r[2],r[3],r[4]),r=r.slice(5)):(t=e.qscore(r[0],r[1],r[2]),r=r.slice(3));var o=r[0],i=r[1];return 1-e.tukey.cdf(t,i,o-i)},tukeyhsd:function(t){for(var n=e.pooledstdev(t),r=t.map((function(t){return e.mean(t)})),o=t.reduce((function(e,t){return e+t.length}),0),i=[],a=0;a<t.length;++a)for(var l=a+1;l<t.length;++l){var s=e.qtest(r[a],r[l],t[a].length,t[l].length,n,o,t.length);i.push([[a,l],s])}return i}}),e.extend({normalci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?t.abs(e.normal.inv(o[1]/2,0,1)*o[2]/t.sqrt(o[3])):t.abs(e.normal.inv(o[1]/2,0,1)*e.stdev(o[2])/t.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},tci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?t.abs(e.studentt.inv(o[1]/2,o[3]-1)*o[2]/t.sqrt(o[3])):t.abs(e.studentt.inv(o[1]/2,o[2].length-1)*e.stdev(o[2],!0)/t.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},significant:function(e,t){return e<t}}),e.extend(e.fn,{normalci:function(t,n){return e.normalci(t,n,this.toArray())},tci:function(t,n){return e.tci(t,n,this.toArray())}}),e.extend(e.fn,{oneSidedDifferenceOfProportions:function(t,n,r,o){var a=i(t,n,r,o);return e.ztest(a,1)},twoSidedDifferenceOfProportions:function(t,n,r,o){var a=i(t,n,r,o);return e.ztest(a,2)}})}(t,Math),t.models=function(){function e(e,n){var r=e.length,o=n[0].length-1,i=r-o-1,a=t.lstsq(n,e),l=t.multiply(n,a.map((function(e){return[e]}))).map((function(e){return e[0]})),s=t.subtract(e,l),u=t.mean(e),c=t.sum(l.map((function(e){return Math.pow(e-u,2)}))),f=t.sum(e.map((function(e,t){return Math.pow(e-l[t],2)}))),d=c+f;return{exog:n,endog:e,nobs:r,df_model:o,df_resid:i,coef:a,predict:l,resid:s,ybar:u,SST:d,SSE:c,SSR:f,R2:c/d}}function n(n){var r,o,i=(r=n.exog,o=r[0].length,t.arange(o).map((function(n){var i=t.arange(o).filter((function(e){return e!==n}));return e(t.col(r,n).map((function(e){return e[0]})),t.col(r,i))}))),a=Math.sqrt(n.SSR/n.df_resid),l=i.map((function(e){var t=e.SST,n=e.R2;return a/Math.sqrt(t*(1-n))})),s=n.coef.map((function(e,t){return(e-0)/l[t]})),u=s.map((function(e){var r=t.studentt.cdf(e,n.df_resid);return 2*(r>.5?1-r:r)})),c=t.studentt.inv(.975,n.df_resid),f=n.coef.map((function(e,t){var n=c*l[t];return[e-n,e+n]}));return{se:l,t:s,p:u,sigmaHat:a,interval95:f}}return{ols:function(r,o){var i=e(r,o),a=n(i),l=function(e){var n,r,o,i=e.R2/e.df_model/((1-e.R2)/e.df_resid);return{F_statistic:i,pvalue:1-(n=i,r=e.df_model,o=e.df_resid,t.beta.cdf(n/(o/r+n),r/2,o/2))}}(i),s=1-(1-i.R2)*((i.nobs-1)/i.df_resid);return i.t=a,i.f=l,i.adjust_R2=s,i}}}(),t.extend({buildxmatrix:function(){for(var e=new Array(arguments.length),n=0;n<arguments.length;n++)e[n]=[1].concat(arguments[n]);return t(e)},builddxmatrix:function(){for(var e=new Array(arguments[0].length),n=0;n<arguments[0].length;n++)e[n]=[1].concat(arguments[0][n]);return t(e)},buildjxmatrix:function(e){for(var n=new Array(e.length),r=0;r<e.length;r++)n[r]=e[r];return t.builddxmatrix(n)},buildymatrix:function(e){return t(e).transpose()},buildjymatrix:function(e){return e.transpose()},matrixmult:function(e,n){var r,o,i,a,l;if(e.cols()==n.rows()){if(n.rows()>1){for(a=[],r=0;r<e.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(l=0,i=0;i<e.cols();i++)l+=e.toArray()[r][i]*n.toArray()[i][o];a[r][o]=l}return t(a)}for(a=[],r=0;r<e.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(l=0,i=0;i<e.cols();i++)l+=e.toArray()[r][i]*n.toArray()[o];a[r][o]=l}return t(a)}},regress:function(e,n){var r=t.xtranspxinv(e),o=e.transpose(),i=t.matrixmult(t(r),o);return t.matrixmult(i,n)},regresst:function(e,n,r){var o=t.regress(e,n),i={anova:{}},a=t.jMatYBar(e,o);i.yBar=a;var l=n.mean();i.anova.residuals=t.residuals(n,a),i.anova.ssr=t.ssr(a,l),i.anova.msr=i.anova.ssr/(e[0].length-1),i.anova.sse=t.sse(n,a),i.anova.mse=i.anova.sse/(n.length-(e[0].length-1)-1),i.anova.sst=t.sst(n,l),i.anova.mst=i.anova.sst/(n.length-1),i.anova.r2=1-i.anova.sse/i.anova.sst,i.anova.r2<0&&(i.anova.r2=0),i.anova.fratio=i.anova.msr/i.anova.mse,i.anova.pvalue=t.anovaftest(i.anova.fratio,e[0].length-1,n.length-(e[0].length-1)-1),i.anova.rmse=Math.sqrt(i.anova.mse),i.anova.r2adj=1-i.anova.mse/i.anova.mst,i.anova.r2adj<0&&(i.anova.r2adj=0),i.stats=new Array(e[0].length);for(var s,u,c,f=t.xtranspxinv(e),d=0;d<o.length;d++)s=Math.sqrt(i.anova.mse*Math.abs(f[d][d])),u=Math.abs(o[d]/s),c=t.ttest(u,n.length-e[0].length-1,r),i.stats[d]=[o[d],s,u,c];return i.regress=o,i},xtranspx:function(e){return t.matrixmult(e.transpose(),e)},xtranspxinv:function(e){var n=t.matrixmult(e.transpose(),e);return t.inv(n)},jMatYBar:function(e,n){var r=t.matrixmult(e,n);return new t(r)},residuals:function(e,n){return t.matrixsubtract(e,n)},ssr:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t,2);return n},sse:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t[r],2);return n},sst:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t,2);return n},matrixsubtract:function(e,n){for(var r=new Array(e.length),o=0;o<e.length;o++){r[o]=new Array(e[o].length);for(var i=0;i<e[o].length;i++)r[o][i]=e[o][i]-n[o][i]}return t(r)}}),t.jStat=t,t)},184:(e,t,n)=>{"use strict";n.d(t,{$:()=>a});var r=n(976),o=n(870),i=n(874);class a extends r.JsViewer{constructor(e){super(),this.canvas=o.canvas(),this.gridCellStyle=r.GridCellStyle.create(),this.renderer=e,this.root.append(this.canvas),this.canvas.style.width="100%",this.canvas.style.height="100%",o.tools.handleResize(this.canvas,((e,t)=>{this.canvas.width=e,this.canvas.height=t,this.render()}));const t=e=>t=>{this.gridCell&&e(this.gridCell,t)};this.canvas.onmousemove=t(this.renderer.onMouseMove),this.canvas.onmouseenter=t(this.renderer.onMouseEnter),this.canvas.onmouseleave=t(this.renderer.onMouseLeave)}static fromGridCell(e){const t=new a(new i.cv);return t.gridCell=e,t.render(),t}render(){if(!this.gridCell)return;const e=this.canvas.getContext("2d");e.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderer.renderInternal(e,0,0,this.canvas.width,this.canvas.height,this.gridCell.dart,this.gridCellStyle)}}},638:(e,t,n)=>{"use strict";n.d(t,{d:()=>r});class r{}r.TAG_FIT_CHART_FORMAT=".fitChartFormat",r.TAG_FIT_CHART_FORMAT_3DX="3dx",r.FIT_SEM_TYPE="fit",r.FIT_CELL_TYPE="fit",r.TAG_FIT=".fit",r.CELL_DEFAULT_WIDTH=230,r.CELL_DEFAULT_HEIGHT=160,r.MIN_CELL_RENDERER_PX_WIDTH=20,r.MIN_CELL_RENDERER_PX_HEIGHT=10,r.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH=70,r.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT=45,r.MIN_AXES_CELL_PX_WIDTH=100,r.MIN_AXES_CELL_PX_HEIGHT=55,r.MIN_TITLE_PX_WIDTH=275,r.MIN_TITLE_PX_HEIGHT=225,r.MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH=180,r.MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT=140,r.MIN_LEGEND_PX_WIDTH=325,r.MIN_LEGEND_PX_HEIGHT=275,r.MIN_DROPLINES_VISIBILITY_PX_WIDTH=120,r.MIN_DROPLINES_VISIBILITY_PX_HEIGHT=110,r.AXES_LEFT_PX_MARGIN=38,r.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS=45,r.AXES_TOP_PX_MARGIN=5,r.AXES_TOP_PX_MARGIN_WITH_TITLE=25,r.AXES_RIGHT_PX_MARGIN=18,r.AXES_BOTTOM_PX_MARGIN=15,r.AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS=30,r.X_AXIS_LABEL_BOTTOM_PX_MARGIN=4,r.LEGEND_TOP_PX_MARGIN=10,r.OUTLIER_PX_SIZE=12,r.POINT_PX_SIZE=4,r.OUTLIER_HITBOX_RADIUS=2,r.CANDLESTICK_BORDER_PX_SIZE=4,r.CANDLESTICK_MEDIAN_PX_SIZE=3.5,r.CANDLESTICK_OUTLIER_PX_SIZE=6,r.INFLATE_SIZE=-6,r.LEGEND_RECORD_PX_HEIGHT=18,r.LEGEND_RECORD_LINE_PX_WIDTH=20,r.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN=5,r.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN=4,r.LINE_STYLES={solid:[],dotted:[1,1],dashed:[5,5],dashdotted:[5,5,2,5]},r.CURVE_CONFIDENCE_INTERVAL_BOUNDS={TOP:"top",BOTTOM:"bottom"},r.CONFIDENCE_INTERVAL_STROKE_COLOR="rgba(255,191,63,0.4)",r.CONFIDENCE_INTERVAL_FILL_COLOR="rgba(255,238,204,0.3)",r.CONDITION_MAP={"No series to show":e=>void 0===e||0===(null==e?void 0:e.length),"There were series with no points":e=>e.some((e=>{var t;return 0===(null===(t=e.points)||void 0===t?void 0:t.length)})),"There were series with all x zeroes":e=>e.some((e=>{var t;return null===(t=e.points)||void 0===t?void 0:t.every((e=>0===e.x))})),"There were series with all y zeroes":e=>e.some((e=>{var t;return null===(t=e.points)||void 0===t?void 0:t.every((e=>0===e.y))}))}},840:(e,t,n)=>{"use strict";n.d(t,{DI:()=>a}),n(976);var r=n(469),o=n(363),i=(n(102),n(414),n(638),function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((r=r.apply(e,t||[])).next())}))});function a(){return i(this,void 0,void 0,(function*(){r.shell.windows.showContextPanel=!0;const e=yield r.data.loadTable(`${o._package.webRoot}files/curves-demo.csv`);r.shell.addTableView(e)}))}},188:(e,t,n)=>{"use strict";n.d(t,{No:()=>v,Z:()=>w,hS:()=>g});var r=n(976),o=n(870),i=n(416),a=n(102),l=n(874),s=n(184),u=n(711),c=n(638),f=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((r=r.apply(e,t||[])).next())}))};const d="chartOptions",m="seriesOptions";var h;!function(e){e.DATAFRAME="Dataframe",e.COLUMN="Column",e.CELL="Cell"}(h||(h={}));const p={count:"totalCount",nulls:"missingValueCount",unique:"uniqueCount",values:"valueCount",min:"min",max:"max",sum:"sum",avg:"avg",stdev:"stdev",variance:"variance",skew:"skew",kurt:"kurt",med:"med",q1:"q1",q2:"q2",q3:"q3"};function g(e,t){const n=(0,i.Y6)(e);if(e.parameters)t.logX&&e.parameters[2]>0&&(e.parameters[2]=Math.log10(e.parameters[2]));else{const r=(0,i.PK)(e,n,t).parameters;e.parameters=[...r]}return(0,i.tq)(e,n,t)}function v(e,t){var n,o,i;const a={logX:null===(n=e.chartOptions)||void 0===n?void 0:n.logX,logY:null===(o=e.chartOptions)||void 0===o?void 0:o.logY},l=[],s=[],u=[],c=[],f=[],d=[],m=[];for(let t=0,n=0;t<(null===(i=e.series)||void 0===i?void 0:i.length);t++){if(e.series[t].points.every((e=>e.outlier)))continue;const r=g(e.series[t],a);l[n]=r.rSquared,s[n]=r.auc,u[n]=r.interceptX,c[n]=r.interceptY,f[n]=r.slope,d[n]=r.top,m[n]=r.bottom,n++}return{rSquared:l.some((e=>null==e))?void 0:r.Stats.fromValues(l)[p[t]],auc:s.some((e=>null==e))?void 0:r.Stats.fromValues(s)[p[t]],interceptX:u.some((e=>null==e))?void 0:r.Stats.fromValues(u)[p[t]],interceptY:c.some((e=>null==e))?void 0:r.Stats.fromValues(c)[p[t]],slope:f.some((e=>null==e))?void 0:r.Stats.fromValues(f)[p[t]],top:d.some((e=>null==e))?void 0:r.Stats.fromValues(d)[p[t]],bottom:m.some((e=>null==e))?void 0:r.Stats.fromValues(m)[p[t]]}}function _(e){for(let t=0;t<e.length;t++){const n=e.get(t);if(""===n)continue;const r=(0,u.f)(n);e.set(t,JSON.stringify(r))}e.setTag(c.d.TAG_FIT_CHART_FORMAT,"")}function T(e,t,n,r){var o;void 0===e.cell.column.temp[`${d}-custom-title`]&&function(e){var t,n;const r=e.columns.bySemTypeAll(c.d.FIT_SEM_TYPE);for(let e=0;e<r.length;e++){a.kW.map((t=>{r[e].temp[`${d}-custom-${t.name}`]=!1})),a.K0.map((t=>{r[e].temp[`${m}-custom-${t.name}`]=!1})),r[e].getTag(c.d.TAG_FIT_CHART_FORMAT)===c.d.TAG_FIT_CHART_FORMAT_3DX&&_(r[e]);for(let o=0;o<r[e].length;o++){if(""===r[e].get(o))continue;const i=null!==(n=JSON.parse(null!==(t=r[e].get(o))&&void 0!==t?t:"{}"))&&void 0!==n?n:{};a.kW.map((t=>{i.chartOptions&&void 0!==i.chartOptions[t.name]&&(r[e].temp[`${d}-custom-${t.name}`]=!0)})),a.K0.map((t=>{if(i.series)for(const n of i.series)void 0!==n[t.name]&&(r[e].temp[`${m}-custom-${t.name}`]=!0)}))}}}(e.cell.dataFrame);const i=t.property.name,s=r===h.DATAFRAME?(0,l.jG)(e.cell.dataFrame):(0,l.hq)(e.cell.column);if(n===d?s.chartOptions[i]=t.value:n===m&&(s.seriesOptions[i]=t.value),r===h.CELL){const r=e.cell.value;if(""===r)return;const i=null!==(o=JSON.parse(null!=r?r:"{}"))&&void 0!==o?o:{};!function(e,t,n){const r=t.property.name;if(n===d){if(void 0===e.chartOptions)return;e.chartOptions[r]=t.value}else if(n===m){if(void 0===e.series)return;for(let n=0;n<e.series.length;n++)e.series[n][r]=t.value}}(i,t,n),e.cell.value=JSON.stringify(i)}else{let t;r===h.DATAFRAME?(e.cell.dataFrame.tags[c.d.TAG_FIT]=JSON.stringify(s),t=e.cell.dataFrame.columns.bySemTypeAll(c.d.FIT_SEM_TYPE)):(e.cell.column.tags[c.d.TAG_FIT]=JSON.stringify(s),t=[e.cell.column]);for(let e=0;e<t.length;e++){if(r===h.DATAFRAME){const r=(0,l.hq)(t[e]);n===d?delete r.chartOptions[i]:delete r.seriesOptions[i],t[e].tags[c.d.TAG_FIT]=JSON.stringify(r)}!1!==t[e].temp[`${n}-custom-${i}`]&&(t[e].init((r=>{var o,a;const l=t[e].get(r);if(""===l)return l;const s=null!==(a=JSON.parse(null!==(o=t[e].get(r))&&void 0!==o?o:"{}"))&&void 0!==a?a:{};if(n===d){if(void 0===s.chartOptions)return l;if(void 0===s.chartOptions[i])return l;delete s.chartOptions[i]}else{if(void 0===s.series)return l;let e=!1;for(const t of s.series)void 0!==t[i]&&(delete t[i],e=!0);if(s.seriesOptions&&delete s.seriesOptions[i],!e)return l}return JSON.stringify(s)})),t[e].temp[`${n}-custom-${i}`]=!1)}}e.grid.invalidate()}class w extends r.ObjectHandler{get type(){return"GridCell"}isApplicable(e){return e instanceof r.GridCell&&e.cellType===c.d.FIT_CELL_TYPE}renderProperties(e,t=null){var n,u,c,h,p,_,w,E,I,y,x;const A=o.accordion("Curves property panel"),C=r.Property.js("level",r.TYPE.STRING,{description:"Controls the level at which properties will be switched",defaultValue:"Column",choices:["Dataframe","Column","Cell"],nullable:!1}),N=o.input.forProperty(C);o.tooltip.bind(N.captionLabel,"Controls the level at which properties will be switched");const S=(0,l.W$)(e),O=(0,l.hq)(e.cell.column),L=(0,l.jG)(e.cell.dataFrame),P={onValueChanged:t=>T(e,t,m,N.value)},b={onValueChanged:t=>T(e,t,d,N.value)};(0,l.fi)(null===(n=L.seriesOptions)||void 0===n?void 0:n.pointColor)||(0,l.fi)(null===(u=O.seriesOptions)||void 0===u?void 0:u.pointColor)||(S.seriesOptions?(0,l.fi)(S.seriesOptions.pointColor)||(S.seriesOptions.pointColor=r.Color.toHtml(r.Color.getCategoricalColor(0))):(0,l.fi)(S.series?S.series[0].pointColor:"")||(S.series[0].pointColor=r.Color.toHtml(r.Color.getCategoricalColor(0)))),(0,l.fi)(null===(c=L.seriesOptions)||void 0===c?void 0:c.fitLineColor)||(0,l.fi)(null===(h=O.seriesOptions)||void 0===h?void 0:h.fitLineColor)||(S.seriesOptions?(0,l.fi)(S.seriesOptions.fitLineColor)||(S.seriesOptions.fitLineColor=r.Color.toHtml(r.Color.getCategoricalColor(0))):(0,l.fi)(S.series?S.series[0].fitLineColor:"")||(S.series[0].fitLineColor=r.Color.toHtml(r.Color.getCategoricalColor(0)))),(0,l.fi)(null===(p=L.seriesOptions)||void 0===p?void 0:p.outlierColor)||(0,l.fi)(null===(_=O.seriesOptions)||void 0===_?void 0:_.outlierColor)||(S.seriesOptions?(0,l.fi)(S.seriesOptions.outlierColor)||(S.seriesOptions.outlierColor=r.Color.toHtml(r.Color.red)):(0,l.fi)(S.series?S.series[0].outlierColor:"")||(S.series[0].outlierColor=r.Color.toHtml(r.Color.red))),(0,l.BI)(a.K0,O.seriesOptions,S.seriesOptions?S.seriesOptions:S.series&&null!==(w=S.series[0])&&void 0!==w?w:{}),(0,l.BI)(a.K0,L.seriesOptions,S.seriesOptions?S.seriesOptions:S.series&&null!==(E=S.series[0])&&void 0!==E?E:{}),(0,l.BI)(a.kW,O.chartOptions,S.chartOptions?S.chartOptions:{}),(0,l.BI)(a.kW,L.chartOptions,S.chartOptions?S.chartOptions:{}),(null===(I=S.chartOptions)||void 0===I?void 0:I.allowXZeroes)&&(null===(y=S.chartOptions)||void 0===y?void 0:y.logX)&&(null===(x=S.series)||void 0===x?void 0:x.some((e=>e.points.some((e=>0===e.x)))))&&(0,l.kb)(S);const R=o.form([N]),X=a.K0.map((e=>o.input.forProperty(e,S.seriesOptions?S.seriesOptions:S.series[0],P)));o.forms.addGroup(R,"Series options",X),o.forms.addGroup(R,"Chart options",a.kW.map((e=>o.input.forProperty(e,S.chartOptions,b)))),A.addPane("Options",(()=>R));const M=r.Property.js("series",r.TYPE.STRING,{description:"Controls whether to show series statistics or aggregated statistics",defaultValue:"All",choices:["all","aggregated"],nullable:!1}),F=o.input.forProperty(M,null,{onValueChanged(e){A.getPane("Fit").root.lastElementChild.replaceChildren(Y())}}),G=r.Property.js("aggregation type",r.TYPE.STRING,{description:"Controls which aggregation to use on the series statistics",defaultValue:"med",choices:Object.values(r.STATS),nullable:!1}),D=o.input.forProperty(G,null,{onValueChanged(e){A.getPane("Fit").root.lastElementChild.replaceChildren(Y())}});function Y(){var t,n,l;const s=o.divV("aggregated"===F.stringValue?[F.root,D.root]:[F.root]),u=(0,i.dU)(S);if(u.x<=0&&S.chartOptions&&(S.chartOptions.logX=!1),u.y<=0&&S.chartOptions&&(S.chartOptions.logY=!1),"all"===F.stringValue){const i={logX:null===(t=S.chartOptions)||void 0===t?void 0:t.logX,logY:null===(n=S.chartOptions)||void 0===n?void 0:n.logY};for(let t=0;t<S.series.length;t++){const n=S.series[t],u=g(n,i),c=n.fitLineColor&&r.Color.fromHtml(n.fitLineColor)?n.fitLineColor:r.Color.toHtml(r.Color.getCategoricalColor(t));s.appendChild(o.panel([o.h1(null!==(l=n.name)&&void 0!==l?l:"series "+t,{style:{color:c}}),o.input.form(u,a.sw,{onCreated:i=>i.root.appendChild(o.iconFA("plus",(()=>f(this,void 0,void 0,(function*(){const o={df:e.cell.dataFrame,colName:e.gridColumn.name,propName:i.property.name,seriesName:n.name,seriesNumber:t};yield r.Func.find({name:"addStatisticsColumn"})[0].prepare(o).call(void 0,void 0,{processed:!1})}))),`Calculate ${i.property.name} for the whole column`))})]))}}else{const t=v(S,D.stringValue);s.appendChild(o.panel([o.h1(`series ${D.stringValue}`),o.input.form(t,a.sw,{onCreated:t=>t.root.appendChild(o.iconFA("plus",(()=>f(this,void 0,void 0,(function*(){const n={df:e.cell.dataFrame,colName:e.gridColumn.name,propName:t.property.name,aggrType:D.stringValue};yield r.Func.find({name:"addAggrStatisticsColumn"})[0].prepare(n).call(void 0,void 0,{processed:!1})}))),`Calculate ${t.property.name} ${D.stringValue} for the whole column`))})]))}return s}return A.addPane("Fit",(()=>Y())),A.addPane("Chart",(()=>s.$.fromGridCell(e).root)),A.root}}},711:(e,t,n)=>{"use strict";n.d(t,{f:()=>u});var r=n(976),o=n(102);const i={x:"xAxis",y:"yAxis"},a={min:"min",max:"max"};function l(e){var t,n,i;const a=null===(n=null===(t=e.getElementsByTagName("params")[0])||void 0===t?void 0:t.childNodes[0].nodeValue)||void 0===n?void 0:n.split(",").map(Number);let l=null===(i=e.getElementsByTagName("function")[0])||void 0===i?void 0:i.getAttribute("type");l=l&&"sigif"!==l?l:o.yB;const s=e.getElementsByTagName("settings")[0].getAttribute("markerColor"),u=e.getElementsByTagName("settings")[0].getAttribute("color"),c=!!e.getElementsByTagName("settings")[0].getAttribute("drawLine"),f={name:e.getAttribute("name"),fitFunction:l,markerType:r.MARKER_TYPE.CIRCLE,pointColor:s,fitLineColor:u,showFitLine:c,showPoints:"points",showCurveConfidenceInterval:!1,clickToToggle:!1};return a&&(f.parameters=[a[2],a[1],a[0],a[3]]),f}function s(e){const t=function(e){var t,n,r;const o=null===(t=e.getElementsByTagName("x")[0].childNodes[0].nodeValue)||void 0===t?void 0:t.split(","),i=null===(n=e.getElementsByTagName("y")[0].childNodes[0].nodeValue)||void 0===n?void 0:n.split(","),a=null===(r=e.getElementsByTagName("mask")[0].childNodes[0].nodeValue)||void 0===r?void 0:r.split(""),l=[];for(let e=0;e<o.length;e++)l[e]={x:+o[e],y:+i[e],outlier:!Boolean(a[e])};return l}(e),n=l(e),r={points:t};return Object.assign(r,n),r}function u(e){const t=(new DOMParser).parseFromString(e,"text/xml"),n=t.getElementsByTagName("grid")[0],r=(u=t.getElementsByTagName("settings")[0],{minX:+(o=n).getElementsByTagName(i.x)[0].getAttribute(a.min),minY:+o.getElementsByTagName(i.y)[0].getAttribute(a.min),maxX:+o.getElementsByTagName(i.x)[0].getAttribute(a.max),maxY:+o.getElementsByTagName(i.y)[0].getAttribute(a.max),xAxisName:u.getAttribute("xLabel"),yAxisName:u.getAttribute("yLabel"),logX:!!u.getAttribute("logX")});var o,u;const c=t.getElementsByTagName("seriesCollection")[0],f=l(c.getElementsByTagName("series")[0]),d=function(e){const t=[],n=e.getElementsByTagName("series").length;for(let r=0;r<n;r++){const n=e.getElementsByTagName("series")[r];t[r]=s(n)}return t}(c);return{chartOptions:r,seriesOptions:f,series:d}}},874:(e,t,n)=>{"use strict";n.d(t,{cv:()=>B,W$:()=>X,hq:()=>F,jG:()=>M,fi:()=>D,l$:()=>b,BI:()=>P,Qp:()=>R,kb:()=>Y});var r=n(976),o=n(469),i=n(870),a=n(102),l=n(766),s=n(416),u=n(711),c=n(184),f=n(188),d=n(638),m=n(111);const h=window,p=new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:2});class g{static getUniqueName(e,t,n){return h.grok_Utils_GetUniqueName(e,t,null==n?void 0:n.auto,null==n?void 0:n.idx,null==n?void 0:n.render,null==n?void 0:n.choices)}static isEmpty(e){return null==e||""==e}static formatNumber(e){return p.format(e)}}function v(e,t){const n=e.pointColor&&r.Color.fromHtml(e.pointColor)?e.pointColor:r.Color.toHtml(r.Color.getCategoricalColor(t)),o=e.outlierColor&&r.Color.fromHtml(e.outlierColor)?e.outlierColor:r.Color.toHtml(r.Color.red),i=e.fitLineColor&&r.Color.fromHtml(e.fitLineColor)?e.fitLineColor:r.Color.toHtml(r.Color.getCategoricalColor(t));e.pointColor=n,e.outlierColor=o,e.fitLineColor=i}function _(e,t,n){var r;if(null!==(r=t.connectDots)&&void 0!==r&&r){e.strokeStyle=t.pointColor,e.lineWidth=2*n.ratio,e.beginPath();for(let r=0;r<t.points.length;r++){const o=t.points[r].x,i=t.points[r].y,a=n.viewport.xToScreen(o),l=n.viewport.yToScreen(i);0===r?e.moveTo(a,l):e.lineTo(a,l)}e.stroke()}}function T(e,t,n){var o;(null===(o=t.showPoints)||void 0===o||o)&&(e.strokeStyle=t.pointColor,t.connectDots&&""!==t.showPoints||"points"===t.showPoints?function(e,t,n){for(let o=0;o<t.points.length;o++){const i=t.points[o],a=t.connectDots?t.pointColor:i.outlier?i.outlierColor&&r.Color.fromHtml(i.outlierColor)?i.outlierColor:t.outlierColor:i.color&&r.Color.fromHtml(i.color)?i.color:t.pointColor,l=i.marker?i.marker:t.markerType,s=i.outlierMarker?i.outlierMarker:t.outlierMarkerType,u=t.connectDots?d.d.POINT_PX_SIZE*n.ratio:i.outlier?d.d.OUTLIER_PX_SIZE*n.ratio:i.size?i.size:d.d.POINT_PX_SIZE*n.ratio;r.Paint.marker(e,t.connectDots?l:i.outlier?s:l,n.viewport.xToScreen(i.x),n.viewport.yToScreen(i.y),a,u),i.stdev&&!i.outlier&&(e.strokeStyle=a,e.beginPath(),e.moveTo(n.viewport.xToScreen(i.x),n.viewport.yToScreen(i.y+i.stdev)),e.lineTo(n.viewport.xToScreen(i.x),n.viewport.yToScreen(i.y-i.stdev)),e.stroke())}}(e,t,n):["candlesticks","both"].includes(t.showPoints)&&function(e,t,n){for(let o=0,i=null;o<t.points.length;o++){const a=t.points[o];if(a.outlier)continue;const l=o+1<t.points.length&&t.points[o+1].x===a.x;if(!i&&l)i=o;else if(null!==i&&!l){const l=[];for(let e=i,n=0;e<=o;e++,n++)l[n]=t.points[e].y;const s=(0,m.G)(l);if(e.beginPath(),w(e,{viewport:n.viewport,ratio:n.ratio,x:a.x,boxPlotStats:s,color:t.pointColor}),e.stroke(),"both"===t.showPoints)for(let o=0;o<l.length;o++)(l[o]<s.lowerAdjacentValue||l[o]>s.upperAdjacentValue)&&r.Paint.marker(e,r.MARKER_TYPE.OUTLIER,n.viewport.xToScreen(a.x),n.viewport.yToScreen(l[o]),t.pointColor,d.d.CANDLESTICK_OUTLIER_PX_SIZE*n.ratio);i=null}}}(e,t,n))}function w(e,t){E(e,t.x,t.boxPlotStats.lowerAdjacentValue,t.viewport),e.moveTo(t.viewport.xToScreen(t.x),t.viewport.yToScreen(t.boxPlotStats.lowerAdjacentValue)),e.lineTo(t.viewport.xToScreen(t.x),t.viewport.yToScreen(t.boxPlotStats.upperAdjacentValue)),E(e,t.x,t.boxPlotStats.upperAdjacentValue,t.viewport),r.Paint.marker(e,r.MARKER_TYPE.CIRCLE,t.viewport.xToScreen(t.x),t.viewport.yToScreen(t.boxPlotStats.q2),t.color,d.d.CANDLESTICK_MEDIAN_PX_SIZE*t.ratio)}function E(e,t,n,r){e.moveTo(r.xToScreen(t)-d.d.CANDLESTICK_BORDER_PX_SIZE/2,r.yToScreen(n)),e.lineTo(r.xToScreen(t)+d.d.CANDLESTICK_BORDER_PX_SIZE/2,r.yToScreen(n))}function I(e,t,n){var r;if(null===(r=t.showFitLine)||void 0===r||r){e.save(),e.strokeStyle=t.fitLineColor,e.lineWidth=2*n.ratio,e.beginPath(),t.lineStyle&&e.setLineDash(d.d.LINE_STYLES[t.lineStyle]);const r=n.showAxes?n.showAxesLabels?d.d.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:d.d.AXES_LEFT_PX_MARGIN:0,o=n.showAxes?d.d.AXES_RIGHT_PX_MARGIN:0;for(let t=r;t<=n.screenBounds.width-o;t++){const o=n.screenBounds.x+t,i=n.logOptions.logX?Math.log10(n.viewport.xToWorld(o)):n.viewport.xToWorld(o),a=n.logOptions.logY?n.viewport.yToScreen(Math.pow(10,n.curveFunc(i))):n.viewport.yToScreen(n.curveFunc(i));t===r?e.moveTo(o,a):e.lineTo(o,a)}e.stroke(),e.restore()}}function y(e,t,n){var r,o,i,a;if((null===(r=t.showFitLine)||void 0===r||r)&&null!==(o=t.showCurveConfidenceInterval)&&void 0!==o&&o){e.strokeStyle=null!==(i=t.confidenceIntervalColor)&&void 0!==i?i:d.d.CONFIDENCE_INTERVAL_STROKE_COLOR,e.fillStyle=null!==(a=t.confidenceIntervalColor)&&void 0!==a?a:d.d.CONFIDENCE_INTERVAL_FILL_COLOR;const r=(0,s.LC)(t,n.fitFunc,n.userParamsFlag,n.logOptions);x(e,{viewport:n.viewport,logOptions:n.logOptions,showAxes:n.showAxes,showAxesLabels:n.showAxesLabels,screenBounds:n.screenBounds,confidenceIntervals:r,confidenceType:d.d.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP}),x(e,{viewport:n.viewport,logOptions:n.logOptions,showAxes:n.showAxes,showAxesLabels:n.showAxesLabels,screenBounds:n.screenBounds,confidenceIntervals:r,confidenceType:d.d.CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM}),function(e,t){e.beginPath();const n=t.showAxes?t.showAxesLabels?d.d.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:d.d.AXES_LEFT_PX_MARGIN:0,r=t.showAxes?d.d.AXES_RIGHT_PX_MARGIN:0;for(let o=n;o<=t.screenBounds.width-r;o++){const r=t.screenBounds.x+o,i=t.logOptions.logX?Math.log10(t.viewport.xToWorld(r)):t.viewport.xToWorld(r),a=t.logOptions.logY?t.viewport.yToScreen(Math.pow(10,t.confidenceIntervals.confidenceTop(i))):t.viewport.yToScreen(t.confidenceIntervals.confidenceTop(i));o===n?e.moveTo(r,a):e.lineTo(r,a)}for(let o=t.screenBounds.width-r;o>=n;o--){const n=t.screenBounds.x+o,r=t.logOptions.logX?Math.log10(t.viewport.xToWorld(n)):t.viewport.xToWorld(n),i=t.logOptions.logY?t.viewport.yToScreen(Math.pow(10,t.confidenceIntervals.confidenceBottom(r))):t.viewport.yToScreen(t.confidenceIntervals.confidenceBottom(r));e.lineTo(n,i)}e.closePath(),e.fill()}(e,{viewport:n.viewport,logOptions:n.logOptions,showAxes:n.showAxes,showAxesLabels:n.showAxesLabels,screenBounds:n.screenBounds,confidenceIntervals:r})}}function x(e,t){e.beginPath();const n=t.showAxes?t.showAxesLabels?d.d.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:d.d.AXES_LEFT_PX_MARGIN:0,r=t.showAxes?d.d.AXES_RIGHT_PX_MARGIN:0,o=t.confidenceType===d.d.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP?t.confidenceIntervals.confidenceTop:t.confidenceIntervals.confidenceBottom;for(let i=n;i<=t.screenBounds.width-r;i++){const r=t.screenBounds.x+i,a=t.logOptions.logX?Math.log10(t.viewport.xToWorld(r)):t.viewport.xToWorld(r),l=t.logOptions.logY?t.viewport.yToScreen(Math.pow(10,o(a))):t.viewport.yToScreen(o(a));i===n?e.moveTo(r,l):e.lineTo(r,l)}e.stroke()}function A(e,t,n){var r;if((null===(r=t.showFitLine)||void 0===r||r)&&t.droplines&&n.showDroplines){e.save(),e.strokeStyle="blue",e.lineWidth=n.ratio,e.beginPath(),e.setLineDash([5,5]);for(let r=0;r<t.droplines.length;r++)"IC50"===t.droplines[r]&&C(e,{viewport:n.viewport,xValue:t.parameters[2],dataBounds:n.dataBounds,curveFunc:n.curveFunc,logOptions:n.logOptions});e.stroke(),e.restore()}}function C(e,t){t.logOptions.logX&&(t.xValue=Math.pow(10,t.xValue));const n=t.logOptions.logX?Math.log10(t.xValue):t.xValue,r=t.logOptions.logY?Math.pow(10,t.curveFunc(n)):t.curveFunc(n);e.moveTo(t.viewport.xToScreen(t.dataBounds.minX),t.viewport.yToScreen(r)),e.lineTo(t.viewport.xToScreen(t.xValue),t.viewport.yToScreen(r)),e.lineTo(t.viewport.xToScreen(t.xValue),t.viewport.yToScreen(t.dataBounds.minY))}function N(e,t,n){var r;if((null===(r=t.showFitLine)||void 0===r||r)&&n.statistics){const r=(0,s.tq)(t,n.fitFunc,n.logOptions);for(let o=0;o<n.statistics.length;o++){const i=n.statistics[o],l=a.sw.find((e=>e.name===i));if(l){const i=g.formatNumber(l.get(r));e.fillStyle=t.fitLineColor,e.textAlign="left",e.fillText(l.name+": "+i,n.dataBox.x+5,n.dataBox.y+20+20*o)}}}}function S(e,t,n){e.beginPath(),e.fillStyle="black";const r=e.measureText(t).width;e.fillText(t,n.dataBox.maxX-r,n.dataBox.y+d.d.LEGEND_TOP_PX_MARGIN+(n.columnIdx*d.d.LEGEND_RECORD_PX_HEIGHT+d.d.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend))}function O(e,t,n){e.beginPath(),e.strokeStyle=t.fitLineColor,e.lineWidth=2*n.ratio;const o=e.measureText(t.name).width;e.moveTo(n.dataBox.maxX-o-d.d.LEGEND_RECORD_LINE_PX_WIDTH-d.d.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,n.dataBox.y+d.d.LEGEND_TOP_PX_MARGIN-d.d.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN+(n.showColumnLabel?d.d.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+d.d.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend),e.lineTo(n.dataBox.maxX-o-d.d.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,n.dataBox.y+d.d.LEGEND_TOP_PX_MARGIN-d.d.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN+(n.showColumnLabel?d.d.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+d.d.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend);const i=t.markerType?t.markerType:r.MARKER_TYPE.CIRCLE;r.Paint.marker(e,i,n.dataBox.maxX-o-d.d.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN-d.d.LEGEND_RECORD_LINE_PX_WIDTH/2,n.dataBox.y+d.d.LEGEND_TOP_PX_MARGIN-d.d.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN+(n.showColumnLabel?d.d.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+d.d.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend,t.pointColor,d.d.POINT_PX_SIZE*n.ratio),e.fillStyle=t.fitLineColor,e.fillText(t.name,n.dataBox.maxX-o,n.dataBox.y+d.d.LEGEND_TOP_PX_MARGIN+(n.showColumnLabel?d.d.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+d.d.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend),e.stroke()}function L(e,t){var n;r.Paint.marker(e,r.MARKER_TYPE.OUTLIER,t.midX,t.midY,r.Color.red,(n=.8*Math.min(t.width,t.height),0,30,Math.min(Math.max(n,0),30)))}function P(e,t,n){if(t&&n)for(const r of e)!(r.name in n)&&r.name in t&&(n[r.name]=t[r.name])}function b(e){if(0===e.length)return{};let t,n,r,o=Number.MAX_VALUE,i=Number.MAX_VALUE,a=Number.MIN_VALUE,l=Number.MIN_VALUE,s=!1,u=!1,c=!1;for(const f of e)null!==f.minX&&void 0!==f.minX&&(o=Math.min(o,f.minX)),null!==f.minY&&void 0!==f.minY&&(i=Math.min(i,f.minY)),null!==f.maxX&&void 0!==f.maxX&&(a=Math.max(a,f.maxX)),null!==f.maxY&&void 0!==f.maxY&&(l=Math.max(l,f.maxY)),null!==f.title&&void 0!==f.title&&(null!=r||(r=f.title)),null!==f.xAxisName&&void 0!==f.xAxisName&&(null!=t||(t=f.xAxisName)),null!==f.yAxisName&&void 0!==f.yAxisName&&(null!=n||(n=f.yAxisName)),null!==f.logX&&void 0!==f.logX&&f.logX&&(s=!0),null!==f.logY&&void 0!==f.logY&&f.logY&&(u=!0),null!==f.allowXZeroes&&void 0!==f.allowXZeroes&&f.allowXZeroes&&(c=!0);return{minX:o===Number.MAX_VALUE?void 0:o,minY:i===Number.MAX_VALUE?void 0:i,maxX:a===Number.MIN_VALUE?void 0:a,maxY:l===Number.MIN_VALUE?void 0:l,title:r,xAxisName:t,yAxisName:n,logX:s,logY:u,allowXZeroes:c}}function R(e){if(0===e.length)return null;const t={points:[],name:e[0].name,fitFunction:e[0].fitFunction,markerType:e[0].markerType,lineStyle:e[0].lineStyle,pointColor:e[0].pointColor,fitLineColor:e[0].fitLineColor,confidenceIntervalColor:e[0].confidenceIntervalColor,outlierColor:e[0].outlierColor,connectDots:e[0].connectDots,showFitLine:e[0].showFitLine,showPoints:e[0].showPoints,showCurveConfidenceInterval:e[0].showCurveConfidenceInterval,errorModel:e[0].errorModel,clickToToggle:e[0].clickToToggle,labels:e[0].labels,droplines:e[0].droplines,columnName:e[0].columnName};for(const n of e)t.points=[...t.points,...n.points];return t}function X(e){var t,n,o,i,l;let c=e.cell.value;c.includes("|")&&(c=c.replaceAll("|",""));const f=(null===(n=null===(t=e.cell)||void 0===t?void 0:t.column)||void 0===n?void 0:n.type)===r.TYPE.STRING?e.cell.column.getTag(d.d.TAG_FIT_CHART_FORMAT)===d.d.TAG_FIT_CHART_FORMAT_3DX?(0,u.f)(c):null!==(o=JSON.parse(null!=c?c:"{}"))&&void 0!==o?o:{}:(0,s.TL)(),m=e.cell.column?F(e.cell.column):{},h=e.cell.column?M(e.cell.dataFrame):{};null!==(i=f.series)&&void 0!==i||(f.series=[]),null!==(l=f.chartOptions)&&void 0!==l||(f.chartOptions=m.chartOptions),P(a.kW,m.chartOptions,f.chartOptions),P(a.kW,h.chartOptions,f.chartOptions);for(const e of f.series)P(a.K0,f.seriesOptions,e),P(a.K0,m.seriesOptions,e),P(a.K0,h.seriesOptions,e);return f}function M(e){var t,n,r;return JSON.parse(null!==(t=(n=e.tags)[r=d.d.TAG_FIT])&&void 0!==t?t:n[r]=JSON.stringify((0,s.TL)()))}function F(e){var t,n,r;return JSON.parse(null!==(t=(n=e.tags)[r=d.d.TAG_FIT])&&void 0!==t?t:n[r]=JSON.stringify((0,s.TL)()))}function G(e,t,n){if(e.width<d.d.MIN_AXES_CELL_PX_WIDTH||e.height<d.d.MIN_AXES_CELL_PX_HEIGHT)return[e,void 0,void 0];const r=t?d.d.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:d.d.AXES_LEFT_PX_MARGIN,o=t?d.d.AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS:d.d.AXES_BOTTOM_PX_MARGIN,i=n?d.d.AXES_TOP_PX_MARGIN_WITH_TITLE:d.d.AXES_TOP_PX_MARGIN;return[e.cutLeft(r).cutBottom(o).cutTop(i).cutRight(d.d.AXES_RIGHT_PX_MARGIN),e.getBottom(o).getTop(i).cutLeft(r).cutRight(d.d.AXES_RIGHT_PX_MARGIN),e.getLeft(r).getRight(d.d.AXES_RIGHT_PX_MARGIN).cutBottom(o).cutTop(i)]}function D(e){return null!=e&&""!==e&&void 0!==r.Color.fromHtml(e)}function Y(e){var t;for(let n=0;n<(null===(t=e.series)||void 0===t?void 0:t.length);n++){const t=e.series[n];if(t.points.every((e=>0!==e.x)))continue;let r=Number.MAX_VALUE,o=0,i=0;const a=[];for(let e=0;e<t.points.length;e++)t.points[e].x<r&&0!==t.points[e].x&&(r=t.points[e].x),t.points[e].x>o&&0!==t.points[e].x&&(o=t.points[e].x),a.includes(t.points[e].x)||(a[a.length]=t.points[e].x,i++);const l=Math.pow(10,Math.log10(r)-(Math.log10(o)-Math.log10(r)/(i-1)));for(let e=0;e<t.points.length;e++)0===t.points[e].x&&(t.points[e].x=l)}}class B extends r.GridCellRenderer{get name(){return d.d.FIT_CELL_TYPE}get cellType(){return d.d.FIT_CELL_TYPE}getDefaultSize(e){return{width:d.d.CELL_DEFAULT_WIDTH,height:d.d.CELL_DEFAULT_HEIGHT}}onClick(e,t){var n,r,a,c,m,h,p;if(!e.cell.value)return;const g=e.cell.column.getTag(d.d.TAG_FIT_CHART_FORMAT)===d.d.TAG_FIT_CHART_FORMAT_3DX?(0,u.f)(e.cell.value):X(e);for(const[e,t]of Object.entries(d.d.CONDITION_MAP))if(t(g.series))return void(o.shell.o=i.divText(e,{style:{color:"red"}}));o.shell.o=e;const v=e.bounds.inflate(d.d.INFLATE_SIZE,d.d.INFLATE_SIZE),_=G(v,this.areAxesLabelsShown(v,g),this.isTitleShown(v,g))[0],T=(0,s.dU)(g),w=new l.l(T,_,null!==(r=null===(n=g.chartOptions)||void 0===n?void 0:n.logX)&&void 0!==r&&r,null!==(c=null===(a=g.chartOptions)||void 0===a?void 0:a.logY)&&void 0!==c&&c);for(let n=0;n<(null===(m=g.series)||void 0===m?void 0:m.length);n++)if(!(g.series[n].connectDots||!g.series[n].clickToToggle||"points"!==g.series[n].showPoints||v.width<d.d.MIN_AXES_CELL_PX_WIDTH||v.height<d.d.MIN_AXES_CELL_PX_HEIGHT))for(let r=0;r<g.series[n].points.length;r++){const o=g.series[n].points[r];if(this.hitTest(t,o,w)){o.outlier=!o.outlier;const t=e.grid.dataFrame.columns.byTags({".sourceColumn":e.cell.column.name});if(t)for(const r of t){const t={logX:null===(h=g.chartOptions)||void 0===h?void 0:h.logX,logY:null===(p=g.chartOptions)||void 0===p?void 0:p.logY},o=null!==r.tags[".seriesAggregation"]?(0,f.No)(g,r.tags[".seriesAggregation"]):r.tags[".seriesNumber"]===n?(0,f.hS)(g.series[n],t):null;null!==o&&r.set(e.cell.rowIndex,o[r.tags[".statistics"]])}if(e.cell.column.getTag(d.d.TAG_FIT_CHART_FORMAT)!==d.d.TAG_FIT_CHART_FORMAT_3DX){const t=JSON.parse(e.cell.value);t.series[n].points[r].outlier=o.outlier,e.cell.value=JSON.stringify(t)}return}}}onDoubleClick(e,t){if(!e.cell.value)return;const n=c.$.fromGridCell(e),r=i.dialog({title:"Edit chart"}).add(n.root).show({resizable:!0}).root.getElementsByClassName("d4-dialog-contents dlg-edit-chart")[0].firstChild;n.canvas.width=r.clientWidth,n.canvas.height=r.clientHeight,n.render(),r.style.width="100%",r.style.height="100%",i.tools.handleResize(r,((e,t)=>{n.canvas.width=e,n.canvas.height=t,n.render()}))}areAxesShown(e){return e.width>=d.d.MIN_AXES_CELL_PX_WIDTH&&e.height>=d.d.MIN_AXES_CELL_PX_HEIGHT}areAxesLabelsShown(e,t){var n;return e.width>=d.d.MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH&&e.height>=d.d.MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT&&!!(null===(n=t.chartOptions)||void 0===n?void 0:n.xAxisName)&&!!t.chartOptions.yAxisName}isTitleShown(e,t){var n;return e.width>=d.d.MIN_TITLE_PX_WIDTH&&e.height>=d.d.MIN_TITLE_PX_HEIGHT&&!!(null===(n=t.chartOptions)||void 0===n?void 0:n.title)}isLegendShown(e){return e.width>=d.d.MIN_LEGEND_PX_WIDTH&&e.height>=d.d.MIN_LEGEND_PX_HEIGHT}areDroplinesShown(e){return e.width>=d.d.MIN_DROPLINES_VISIBILITY_PX_WIDTH&&e.height>=d.d.MIN_DROPLINES_VISIBILITY_PX_HEIGHT}renderCurves(e,t,n){var r,o,i,a,u,c,f,m,h,p,g,w,E,x,C;e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),(null===(r=n.chartOptions)||void 0===r?void 0:r.allowXZeroes)&&(null===(o=n.chartOptions)||void 0===o?void 0:o.logX)&&(null===(i=n.series)||void 0===i?void 0:i.some((e=>e.points.some((e=>0===e.x)))))&&Y(n);const[L,P,b]=G(t,this.areAxesLabelsShown(t,n),this.isTitleShown(t,n)),R=(0,s.dU)(n);(R.x<0&&n.chartOptions||0===R.x&&n.chartOptions&&!n.chartOptions.allowXZeroes)&&(n.chartOptions.logX=!1),R.y<=0&&n.chartOptions&&(n.chartOptions.logY=!1);const X=new l.l(R,L,null!==(u=null===(a=n.chartOptions)||void 0===a?void 0:a.logX)&&void 0!==u&&u,null!==(f=null===(c=n.chartOptions)||void 0===c?void 0:c.logY)&&void 0!==f&&f),M=Math.min(L.width,L.height),F=M>100?1:.2+M/100*.8,D={logX:null===(m=n.chartOptions)||void 0===m?void 0:m.logX,logY:null===(h=n.chartOptions)||void 0===h?void 0:h.logY};e.save(),e.font='11px Roboto, "Roboto Local"',X.drawCoordinateGrid(e,P,b),e.restore();for(let r=0;r<(null===(p=n.series)||void 0===p?void 0:p.length);r++){const o=n.series[r];if(o.points.some((e=>void 0===e.x||void 0===e.y)))continue;(t.width<d.d.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH||t.height<d.d.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT)&&(o.showPoints="",n.chartOptions&&(n.chartOptions.showStatistics=[])),o.points.sort(((e,t)=>e.x-t.x));let i=!0;const a=(0,s.Y6)(o);let l=null;if(!o.connectDots||o.showFitLine)if(o.parameters)(null===(g=n.chartOptions)||void 0===g?void 0:g.logX)&&o.parameters[2]>0&&(o.parameters[2]=Math.log10(o.parameters[2])),l=(0,s.kG)(o,a);else{const e=(0,s.PK)(o,a,D);l=e.fittedCurve;const t=[...e.parameters];o.parameters=t,i=!1}v(o,r),_(e,o,{viewport:X,ratio:F}),T(e,o,{viewport:X,ratio:F}),I(e,o,{viewport:X,ratio:F,logOptions:D,showAxes:this.areAxesShown(t),showAxesLabels:this.areAxesLabelsShown(t,n),screenBounds:t,curveFunc:l}),y(e,o,{viewport:X,logOptions:D,showAxes:this.areAxesShown(t),showAxesLabels:this.areAxesLabelsShown(t,n),screenBounds:t,fitFunc:a,userParamsFlag:i}),o.parameters&&A(e,o,{viewport:X,ratio:F,showDroplines:this.areDroplinesShown(t),xValue:o.parameters[2],dataBounds:R,curveFunc:l,logOptions:D}),N(e,o,{statistics:null===(w=n.chartOptions)||void 0===w?void 0:w.showStatistics,fitFunc:a,logOptions:D,dataBox:L})}!function(e,t){t.showTitle&&(e.font='12px Roboto, "Roboto Local"',e.textAlign="center",e.fillStyle="black",e.fillText(t.title,t.dataBox.midX-5,t.screenBounds.y+15))}(e,{showTitle:this.isTitleShown(t,n),title:null===(E=n.chartOptions)||void 0===E?void 0:E.title,dataBox:L,screenBounds:t}),function(e,t){if(t.showAxesLabels){e.font='11px Roboto, "Roboto Local"',e.textAlign="center",e.fillStyle="black",e.fillText(t.xAxisName,t.dataBox.midX-5,t.screenBounds.maxY-d.d.X_AXIS_LABEL_BOTTOM_PX_MARGIN),e.translate(t.screenBounds.x,t.screenBounds.y),e.rotate(-Math.PI/2);const n=t.showTitle?d.d.AXES_TOP_PX_MARGIN_WITH_TITLE:d.d.AXES_TOP_PX_MARGIN;e.fillText(t.yAxisName,-(t.dataBox.height/2+n+15),15),e.restore()}}(e,{showTitle:this.isTitleShown(t,n),dataBox:L,screenBounds:t,showAxesLabels:this.areAxesLabelsShown(t,n),xAxisName:null===(x=n.chartOptions)||void 0===x?void 0:x.xAxisName,yAxisName:null===(C=n.chartOptions)||void 0===C?void 0:C.yAxisName}),function(e,t,n){var r,o,i,a;if(n.showLegend){e.font='11px Roboto, "Roboto Local"';const l=[...new Set(null===(r=t.series)||void 0===r?void 0:r.map((e=>e.columnName)))].filter((e=>null!=e));let s=0;for(let r=0;r<l.length;r++){const u=l[r];(null===(o=t.chartOptions)||void 0===o?void 0:o.showColumnLabel)&&S(e,u,{dataBox:n.dataBox,columnIdx:r,drawnCurvesInLegend:s});const c=null===(i=t.series)||void 0===i?void 0:i.filter((e=>e.columnName===u));for(let o=0;o<(null==c?void 0:c.length);o++){const i=c[o];""!==i.name&&null!==i.name&&void 0!==i.name&&(O(e,i,{dataBox:n.dataBox,ratio:n.ratio,columnIdx:r,drawnCurvesInLegend:s,showColumnLabel:null===(a=t.chartOptions)||void 0===a?void 0:a.showColumnLabel}),s++)}}e.restore()}}(e,n,{showLegend:this.isLegendShown(t),dataBox:L,ratio:F}),e.restore()}render(e,t,n,o,i,a,l){var s,c,f;if(!a.cell.value)return;if(o<d.d.MIN_CELL_RENDERER_PX_WIDTH||i<d.d.MIN_CELL_RENDERER_PX_HEIGHT)return;const m=(null===(s=a.cell.column)||void 0===s?void 0:s.getTag(d.d.TAG_FIT_CHART_FORMAT))===d.d.TAG_FIT_CHART_FORMAT_3DX?(0,u.f)(a.cell.value):X(a),h=new r.Rect(t,n,o,i).inflate(d.d.INFLATE_SIZE,d.d.INFLATE_SIZE);for(const[t,n]of Object.entries(d.d.CONDITION_MAP))if(n(m.series))return void L(e,h);null===(c=m.series)||void 0===c||c.forEach((e=>e.columnName=a.cell.column.name)),(null===(f=m.chartOptions)||void 0===f?void 0:f.mergeSeries)&&(m.series=[R(m.series)]),this.renderCurves(e,h,m)}hitTest(e,t,n){const o=n.xToScreen(t.x),i=n.yToScreen(t.y),a=(t.outlier?d.d.OUTLIER_PX_SIZE:d.d.POINT_PX_SIZE)/2+d.d.OUTLIER_HITBOX_RADIUS;return new r.Rect(o-a,i-a,2*a,2*a).containsPoint(new r.Point(e.offsetX,e.offsetY))}onMouseMove(e,t){var n,o,a,c,f;if(!e.cell.value)return;const m=e.bounds.inflate(d.d.INFLATE_SIZE,d.d.INFLATE_SIZE);if(m.width<d.d.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH||m.height<d.d.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT){const n=i.canvas(300,200);this.render(n.getContext("2d"),0,0,300,200,e,null);const r=i.divV([n]);i.tooltip.show(r,t.x,t.y)}const h=e.cell.column.getTag(d.d.TAG_FIT_CHART_FORMAT)===d.d.TAG_FIT_CHART_FORMAT_3DX?(0,u.f)(e.cell.value):X(e);if(m.width>=d.d.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH&&m.height>=d.d.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT){const e=G(m,this.areAxesLabelsShown(m,h),this.isTitleShown(m,h))[0],u=(0,s.dU)(h),p=new l.l(u,e,null!==(o=null===(n=h.chartOptions)||void 0===n?void 0:n.logX)&&void 0!==o&&o,null!==(c=null===(a=h.chartOptions)||void 0===a?void 0:a.logY)&&void 0!==c&&c);for(let e=0;e<(null===(f=h.series)||void 0===f?void 0:f.length);e++)if("points"===h.series[e].showPoints)for(let n=0;n<h.series[e].points.length;n++){const o=h.series[e].points[n];if(this.hitTest(t,o,p))return i.tooltip.show(i.divV([i.divText(`x: ${r.format(o.x,"#0.000")}`),i.divText(`y: ${r.format(o.y,"#0.000")}`)]),t.x+16,t.y+16),void(!h.series[e].connectDots&&h.series[e].clickToToggle&&m.width>=d.d.MIN_AXES_CELL_PX_WIDTH&&m.height>=d.d.MIN_AXES_CELL_PX_HEIGHT&&(document.body.style.cursor="pointer"))}i.tooltip.hide()}document.body.style.cursor="default"}}},363:(e,t,n)=>{"use strict";n.r(t),n.d(t,{_FitViewer:()=>I,_initCurves:()=>x,_package:()=>g,addAggrStatisticsColumn:()=>C,addStatisticsColumn:()=>A,curveFitDemo:()=>y,fitCellRenderer:()=>E});var r=n(976),o=n(188),i=n(874),a=n(870),l=n(184),s=n(102);const u=rxjs.operators,c=rxjs;var f=n(638);class d extends l.${constructor(){super(new i.cv),this.curvesColumnNames=[],this.showSelectedRowsCurves=!1,this.showCurrentRowCurve=!0,this.showMouseOverRowCurve=!0,this.mergeColumnSeries=!1,this.rows=[],this.data=new s.cY,this.curvesColumnNames=this.addProperty("curvesColumnNames",r.TYPE.COLUMN_LIST,[],{semType:f.d.FIT_SEM_TYPE}),this.showSelectedRowsCurves=this.bool("showSelectedRowsCurves",!1,{description:"Adds curves from the selected rows"}),this.showCurrentRowCurve=this.bool("showCurrentRowCurve",!0),this.showMouseOverRowCurve=this.bool("showMouseOverRowCurve",!0),this.mergeColumnSeries=this.bool("mergeColumnSeries",!1);for(const e of s.kW)this.addProperty("mergeSeries"===e.name?"mergeCellSeries":e.name,e.propertyType,e.defaultValue,e.options)}static fromChartData(e){let t=new d;return t.data=e,t.render(),t}applyViewerProperties(){(0,i.BI)(s.kW,this,this.data.chartOptions)}mergeViewerChartOptions(){for(const e of s.kW)if(["logX","logY","allowXZeroes","mergeCellSeries","showColumnLabel"].includes("mergeSeries"===e.name?"mergeCellSeries":e.name)?void 0!==this["mergeSeries"===e.name?"mergeCellSeries":e.name]:void 0!==this.props.get(e.name)&&this.props.get(e.name)!==e.defaultValue){if(["title","xAxisName","yAxisName"].includes(e.name)&&""===this.props.get(e.name))continue;["logX","logY","allowXZeroes","mergeCellSeries","showColumnLabel"].includes("mergeSeries"===e.name?"mergeCellSeries":e.name)?this.data.chartOptions[e.name]=this[e.name]:this.data.chartOptions[e.name]=this.props.get(e.name)}}createChartData(){var e,t,n,o,a,l;if(0===(null===(e=this.curvesColumnNames)||void 0===e?void 0:e.length))return;this.rows.length=0;let u=-1;this.showCurrentRowCurve&&-1!==this.dataFrame.currentRowIdx&&this.rows.push(this.dataFrame.currentRowIdx),this.showMouseOverRowCurve&&-1!==this.dataFrame.mouseOverRowIdx&&this.rows.push(this.dataFrame.mouseOverRowIdx),this.showSelectedRowsCurves&&-1!==this.dataFrame.mouseOverRowIdx&&(u=this.rows.length,this.rows.push(...this.dataFrame.selection.getSelectedIndexes())),this.data=new s.cY;const c=null===(t=this.tableView)||void 0===t?void 0:t.grid,f=this.props.get("mergeCellSeries"),d=[];for(const e of this.curvesColumnNames){const t=[];for(const r of new Set(this.rows)){const o=c.cell(e,c.tableRowToGrid(r));if(""===o.cell.value)continue;const a=(0,i.W$)(o);null===(n=a.series)||void 0===n||n.forEach((e=>e.columnName=o.cell.column.name));const l=a.chartOptions;if(null!=l&&(d[d.length]=l),f){const e=(0,i.Qp)(a.series);void 0!==(null==l?void 0:l.title)&&""!==(null==l?void 0:l.title)&&(e.name=null==l?void 0:l.title),a.series=[e]}t.push(...a.series)}this.mergeColumnSeries?null===(o=this.data.series)||void 0===o||o.push((0,i.Qp)(t)):null===(a=this.data.series)||void 0===a||a.push(...t)}this.data.chartOptions=(0,i.l$)(d),this.mergeViewerChartOptions(),null===(l=this.data.series)||void 0===l||l.forEach(((e,t)=>{var n,o,i,a,l;if(e.pointColor=r.Color.toHtml(r.Color.getCategoricalColor((null===(n=this.data.series)||void 0===n?void 0:n.length)>20?0:t)),e.fitLineColor=r.Color.toHtml(r.Color.getCategoricalColor((null===(o=this.data.series)||void 0===o?void 0:o.length)>20?0:t)),e.showCurveConfidenceInterval=!1,e.droplines=[],(null===(i=this.data.series)||void 0===i?void 0:i.length)>20&&(e.showPoints="",e.lineStyle="solid"),(null===(a=this.data.series)||void 0===a?void 0:a.length)>10&&(null===(l=this.data.series)||void 0===l?void 0:l.length)<100&&t>=u){const t=r.Color.fromHtml(e.fitLineColor);e.fitLineColor=`rgba(${r.Color.r(t)}, ${r.Color.g(t)}, ${r.Color.b(t)}, 0.2)`}}))}onPropertyChanged(e){var t,n,r,o,i;"curvesColumnNames"===(null==e?void 0:e.name)&&(this.props.set("showColumnLabel",(null===(t=this.curvesColumnNames)||void 0===t?void 0:t.length)>1),this.showColumnLabel=(null===(n=this.curvesColumnNames)||void 0===n?void 0:n.length)>1),["logX","logY","allowXZeroes","mergeCellSeries","showColumnLabel"].includes("mergeSeries"===(null==e?void 0:e.name)?"mergeCellSeries":null!==(r=null==e?void 0:e.name)&&void 0!==r?r:"")&&(this["mergeSeries"===(null==e?void 0:e.name)?"mergeCellSeries":null!==(o=null==e?void 0:e.name)&&void 0!==o?o:""]=this[null!==(i=null==e?void 0:e.name)&&void 0!==i?i:""]),this.applyViewerProperties(),this.createChartData(),this.render()}onTableAttached(){var e;const t=null===(e=this.tableView)||void 0===e?void 0:e.grid,n=this.dataFrame.columns.bySemType(f.d.FIT_SEM_TYPE);null!==n&&(this.curvesColumnNames=[n.name]),(0,c.merge)(this.dataFrame.onCurrentCellChanged,t.onCellMouseEnter,this.dataFrame.onSelectionChanged).pipe((0,u.debounce)((e=>(0,c.interval)(50)))).subscribe((e=>{this.createChartData(),this.render()}))}_showErrorMessage(e){this.root.appendChild(a.divText(e,"d4-viewer-error"))}_removeErrorMessage(){const e=this.root.getElementsByClassName("d4-viewer-error")[0];e&&this.root.removeChild(e)}render(){var e;const t=this.canvas.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),0!==(null===(e=this.curvesColumnNames)||void 0===e?void 0:e.length)?(this._removeErrorMessage(),this.renderer.renderCurves(t,new r.Rect(0,0,this.canvas.width,this.canvas.height).inflate(f.d.INFLATE_SIZE,f.d.INFLATE_SIZE),this.data)):this._showErrorMessage("The MultiCurveViewer viewer requires a minimum of 1 curves column.")}}var m=n(840),h=n(711),p=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((r=r.apply(e,t||[])).next())}))};const g=new r.Package,v=".sourceColumn",_=".seriesNumber",T=".seriesAggregation",w=".statistics";function E(){return new i.cv}function I(){return new d}function y(){return p(this,void 0,void 0,(function*(){yield(0,m.DI)()}))}function x(){r.ObjectHandler.register(new o.Z)}function A(e,t,n,a,l){var s;const u=r.Viewer.grid(e),c=u.col(t),d=r.Column.float(`${t}_${a}_${n}`,null===(s=c.column)||void 0===s?void 0:s.length);d.tags[v]=t,d.tags[_]=l,d.tags[w]=n,d.init((e=>{var a,s,c,d,m;const p=r.GridCell.fromColumnRow(u,t,u.tableRowToGrid(e));if(""===p.cell.value)return null;const g=p.cell.column.getTag(f.d.TAG_FIT_CHART_FORMAT)===f.d.TAG_FIT_CHART_FORMAT_3DX?(0,h.f)(p.cell.value):(0,i.W$)(p);if(void 0===g.series[l]||g.series[l].points.every((e=>e.outlier)))return null;(null===(a=g.chartOptions)||void 0===a?void 0:a.allowXZeroes)&&(null===(s=g.chartOptions)||void 0===s?void 0:s.logX)&&(null===(c=g.series)||void 0===c?void 0:c.some((e=>e.points.some((e=>0===e.x)))))&&(0,i.kb)(g);const v={logX:null===(d=g.chartOptions)||void 0===d?void 0:d.logX,logY:null===(m=g.chartOptions)||void 0===m?void 0:m.logY};return(0,o.hS)(g.series[l],v)[n]})),e.columns.insert(d,c.idx)}function C(e,t,n,a){var l;const s=r.Viewer.grid(e),u=s.col(t),c=r.Column.float(`${t}_${a}_${n}`,null===(l=u.column)||void 0===l?void 0:l.length);c.tags[v]=t,c.tags[T]=a,c.tags[w]=n,c.init((e=>{var l,u,c,d;const m=r.GridCell.fromColumnRow(s,t,s.tableRowToGrid(e));if(""===m.cell.value)return null;const p=m.cell.column.getTag(f.d.TAG_FIT_CHART_FORMAT)===f.d.TAG_FIT_CHART_FORMAT_3DX?(0,h.f)(m.cell.value):(0,i.W$)(m);return(null===(l=p.series)||void 0===l?void 0:l.every((e=>e.points.every((e=>e.outlier)))))?null:((null===(u=p.chartOptions)||void 0===u?void 0:u.allowXZeroes)&&(null===(c=p.chartOptions)||void 0===c?void 0:c.logX)&&(null===(d=p.series)||void 0===d?void 0:d.some((e=>e.points.some((e=>0===e.x)))))&&(0,i.kb)(p),(0,o.No)(p,a)[n])})),e.columns.insert(c,u.idx)}},976:e=>{"use strict";e.exports=DG},469:e=>{"use strict";e.exports=grok},870:e=>{"use strict";e.exports=ui},414:e=>{"use strict";e.exports=wu}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r=n(363);curves=r})();
|
|
1
|
+
var curves;(()=>{var e={368:(e,t,n)=>{"use strict";function r(e){e.sort();const t=e[Math.trunc(e.length/4)],n=e.length%2==0?(e[Math.trunc(e.length/2)]+e[Math.trunc(e.length/2)-1])/2:e[Math.trunc(e.length/2)],r=e[Math.trunc(3*e.length/4)],i=1.5*(r-t);let a=o(e,r+i);a<0&&(a=~a);let l=e[Math.max(0,a-1)];l<r&&(l=r);let s=o(e,t-i);s<0&&(s=~s);let u=e[s];return u>t&&(u=t),{q1:t,q2:n,q3:r,lowerAdjacentValue:u,upperAdjacentValue:l}}function o(e,t,n=0,r){if(0===e.length)return-1;if(void 0===r&&(r=e.length-1),t<e[n])return-1;if(t>e[r])return-(r+1);for(;r-n>1;){const o=Math.trunc((r+n)/2);if(t===e[o])return o;t<e[o]?r=o:n=o}return e[n]===t?n:0===e[r]?r:t<e[n]?-(n+1):-(r+1)}n.d(t,{k:()=>r})},71:(e,t,n)=>{"use strict";n.d(t,{G7:()=>T,oH:()=>h,dZ:()=>f,xs:()=>v,W6:()=>y,IL:()=>_,O8:()=>A,ah:()=>x,TV:()=>I,mW:()=>C,nK:()=>g});var r,o=n(82),i=n(572);class a extends Error{constructor(e){super(e)}}function l(e,t,n,r){for(let o=0;o<t;o++){let i=0;for(let e=0;e<t+1;e++)e!==n&&(i+=r[e][o]);e[o]=i/t}}function s(e,t,n,r,o,i,a,l){for(let s=0;s<i;s++)t[s]=e[s],t[s]+=o*(e[s]-r[n][s]),t[s]<a[s]?t[s]=a[s]:t[s]>l[s]&&(t[s]=l[s])}!function(e){e[e.TOLERANCE=.01]="TOLERANCE",e[e.MAX_ITER=20]="MAX_ITER",e[e.NON_ZERO_PARAM=1e-4]="NON_ZERO_PARAM",e[e.INITIAL_SCALE=.02]="INITIAL_SCALE",e[e.SCALE_REFLECTION=1]="SCALE_REFLECTION",e[e.SCALE_EXPANSION=2]="SCALE_EXPANSION",e[e.SCALE_CONTRACTION=-.5]="SCALE_CONTRACTION"}(r||(r={})),new Map([["tolerance","Tolerance"],["maxIter","Max iterations"],["nonZeroParam","Non-zero param"],["initialScale","Initial scale"],["scaleReflection","Scale reflection"],["scaleExpansion","Scale expansion"],["scaleContraction","Scale contraction"]]);const u=function(e,t,n,r,o){const i=n.tolerance,a=n.maxIter,u=n.scaleReflection,c=n.scaleExpansion,f=n.scaleContraction,h=t.length+1,d=t.length,[m,p]=function(e,t,n,r,o){const i=n.length+1,a=n.length,l=t.nonZeroParam,s=t.initialScale,u=new Array(i),c=new Array(i);for(let t=0;t<i;t++){u[t]=new Float32Array(a);for(let e=0;e<a;e++)u[t][e]=n[e],0!==t&&t-1===e&&(0===n[e]?u[t][e]=l:u[t][e]+=s*n[t-1],u[t][e]<r[e]?u[t][e]=r[e]:u[t][e]>o[e]&&(u[t][e]=o[e]));c[t]=e(u[t])}return[u,c]}(e,n,t,r,o),g=new Array(h);for(let e=0;e<h;e++)g[e]=e;const v=g.length-1;let _=0,T=0,w=0,E=0;const I=new Float32Array(d),y=new Float32Array(d),x=new Float32Array(d),A=new Float32Array(d),C=new Array(a);if(h>1){for(;g.sort(((e,t)=>p[e]-p[t])),!(_>a);){if(0===_&&(T=p[0],w=2*p[g[0]]),C[_]=T,++_,T=p[g[0]],w-T>i)E=0;else if(++E,E>2*h)break;w=T,l(I,d,g[v],m),s(I,y,g[v],m,u,d,r,o);const t=e(y);if(t<p[g[v]]){s(I,x,g[v],m,c,d,r,o);const n=e(x);if(n<t){p[g[v]]=n;for(let e=0;e<d;e++)m[g[v]][e]=x[e];continue}p[g[v]]=t;for(let e=0;e<d;e++)m[g[v]][e]=y[e];continue}s(I,A,g[v],m,f,d,r,o);const n=e(A);if(!(n<p[g[v]]))break;p[g[v]]=n;for(let e=0;e<d;e++)m[g[v]][e]=A[e]}for(let e=_;e<a;e++)C[e]=p[g[0]]}return{point:m[g[0]],cost:p[g[0]],iterCosts:C,iterCount:_-1}};function c(e,t,n){const r=t-n,o=new Array(e);for(let t=0;t<e;t++){const e=Math.random();o[t]=n+e*r}return o}const f={CONSTANT:"constant",PROPORTIONAL:"proportional",COMBINED:"combined"};class h{constructor(){this.chartOptions={},this.seriesOptions={},this.series=[]}}class d{}class m extends d{constructor(e,t,n,r){super(),this._name=e,this._parameterNames=r,this.y=t,this.getInitialParameters=n}get name(){return this._name}get parameterNames(){return this._parameterNames}y(e,t){throw new Error("Not implemented")}getInitialParameters(e,t){throw new Error("Not implemented")}}const p={linear:new class extends d{get name(){return w}get parameterNames(){return["Slope","Intercept"]}y(e,t){return function(e,t){return e[0]*t+e[1]}(e,t)}getInitialParameters(e,t){let n=0,r=0;for(let t=1;t<e.length;t++)e[t]<e[n]&&(n=t),e[t]>e[r]&&(r=t);const o=e[r]-e[n],i=(t[r]-t[n])/o,a=t[r]-i*e[r],l=new Float32Array(2);return l.set([i,a]),l}},sigmoid:new class extends d{get name(){return T}get parameterNames(){return["Top","Bottom","Slope","IC50"]}y(e,t){return function(e,t){const n=e[0],r=e[1],o=e[2],i=e[3];return i+(n-i)/(1+Math.pow(10,(t-o)*r))}(e,t)}getInitialParameters(e,t){const n=o.Rect.fromXYArrays(e,t),r=(n.bottom-n.top)/2+n.top;let i=n.bottom-n.top,a=0;for(let n=0;n<e.length;n++){const e=Math.abs(t[n]-r);e<i&&(i=e,a=n)}const l=e[a],s=t[0]>t[t.length-1]?1:-1,u=new Float32Array(4);return u.set([n.bottom,s,l,n.top]),u}},"log-linear":new class extends d{get name(){return E}get parameterNames(){return["Slope","Intercept"]}y(e,t){return function(e,t){const n=e[0],r=e[1];return n*Math.log(t+1)+r}(e,t)}getInitialParameters(e,t){const n=new Float32Array(2);return n.set([-5,100]),n}}},g=[o.Property.js("rSquared",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("auc",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("interceptY",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("interceptX",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("slope",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("top",o.TYPE.FLOAT,{userEditable:!1}),o.Property.js("bottom",o.TYPE.FLOAT,{userEditable:!1})],v=[o.Property.js("minX",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("minY",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("maxX",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("maxY",o.TYPE.FLOAT,{nullable:!0}),o.Property.js("title",o.TYPE.STRING,{nullable:!0}),o.Property.js("xAxisName",o.TYPE.STRING,{description:"Label to show on the X axis. If not specified, corresponding data column name is used",nullable:!0}),o.Property.js("yAxisName",o.TYPE.STRING,{description:"Label to show on the Y axis. If not specified, corresponding data column name is used",nullable:!0}),o.Property.js("logX",o.TYPE.BOOL,{description:"Whether the X axis should be logarithmic",defaultValue:!1}),o.Property.js("logY",o.TYPE.BOOL,{description:"Whether the Y axis should be logarithmic",defaultValue:!1}),o.Property.js("allowXZeroes",o.TYPE.BOOL,{description:"Whether x zeroes allowed for logarithmic data or not",defaultValue:!0}),o.Property.js("mergeSeries",o.TYPE.BOOL,{description:"Merges all series within one cell into one series",defaultValue:!1}),o.Property.js("showColumnLabel",o.TYPE.BOOL,{description:"Whether to show the column label in the legend or not",defaultValue:!1}),o.Property.js("showStatistics",o.TYPE.STRING_LIST,{description:"Whether specific statistics should be rendered",choices:g.map((e=>e.name)),inputType:"MultiChoice",friendlyName:"Statistics"})],_=[o.Property.js("fitFunction",o.TYPE.STRING,{category:"Fitting",choices:Object.keys(p),defaultValue:"sigmoid"}),o.Property.js("pointColor",o.TYPE.STRING,{category:"Rendering",nullable:!0,inputType:"Color"}),o.Property.js("fitLineColor",o.TYPE.STRING,{category:"Rendering",nullable:!0,inputType:"Color"}),o.Property.js("outlierColor",o.TYPE.STRING,{category:"Rendering",nullable:!0,inputType:"Color"}),o.Property.js("errorModel",o.TYPE.STRING,{category:"Fitting",defaultValue:"constant",choices:["constant","proportional","combined"],nullable:!1}),o.Property.js("connectDots",o.TYPE.BOOL,{category:"Fitting",defaultValue:!1}),o.Property.js("clickToToggle",o.TYPE.BOOL,{category:"Fitting",description:"Click on a point to mark it as outlier and refit",nullable:!0,defaultValue:!1}),o.Property.js("showFitLine",o.TYPE.BOOL,{category:"Fitting",defaultValue:!0}),o.Property.js("showPoints",o.TYPE.STRING,{category:"Fitting",description:"Whether points/candlesticks/none should be rendered",defaultValue:"points",choices:["points","candlesticks","both"]}),o.Property.js("showCurveConfidenceInterval",o.TYPE.BOOL,{category:"Fitting",description:"Whether confidence intervals should be rendered",defaultValue:!1,friendlyName:"Confidence Interval"}),o.Property.js("markerType",o.TYPE.STRING,{category:"Rendering",defaultValue:"circle",choices:["asterisk","circle","cross border","diamond","square","star","triangle bottom","triangle left","triangle right","triangle top"],nullable:!1,friendlyName:"Marker"}),o.Property.js("outlierMarkerType",o.TYPE.STRING,{category:"Rendering",defaultValue:"outlier",choices:["asterisk","circle","cross border","diamond","outlier","square","star","triangle bottom","triangle left","triangle right","triangle top"],nullable:!1,friendlyName:"Outlier Marker"}),o.Property.js("lineStyle",o.TYPE.STRING,{category:"Rendering",defaultValue:"solid",choices:["solid","dotted","dashed","dashdotted"],nullable:!1}),o.Property.js("droplines",o.TYPE.STRING_LIST,{description:"Whether specific droplines should be rendered",choices:["IC50"],inputType:"MultiChoice"}),o.Property.js("columnName",o.TYPE.STRING,{description:"Column name where the series is stored",defaultValue:""})],T="sigmoid",w="linear",E="log-linear";function I(e){if("string"==typeof e)return p[e];if(!p[e.name]){const t=e.name,n=e.parameterNames,r=e.function.split("=>").map((e=>e.trim())),o=e.getInitialParameters.split("=>").map((e=>e.trim())),i=new Function(r[0].slice(1,r[0].length-1),`${r[1].includes(";")?"":"return "}${r[1]}`),a=new Function(o[0].slice(1,o[0].length-1),`return ${o[1]}`),l=new m(t,i,a,n);p[t]=l}return p[e.name]}function y(e,t,n,i){const l=t.y;let s=t.getInitialParameters(e.x,e.y);const h=function(e,t,n){return r=>{let o=0,i=0,a=0;const l=t.y,s=t.x.map((t=>e(r,t))),u=l.map(((e,t)=>e-s[t])).map((e=>Math.pow(e,2)));for(let e=0;e<u.length;e++)[f.CONSTANT,f.COMBINED].includes(n)?i+=u[e]:n===f.PROPORTIONAL&&(a+=u[e]/(s[e]*s[e]));i=Math.sqrt(i/u.length),a=Math.sqrt(a/u.length),n===f.COMBINED&&({sigmaA:i,sigmaB:a}=S(i,a,u,s));const c=[];for(let e=0;e<u.length;e++)c[e]=Math.pow(i+a*s[e],2),o+=u[e]/c[e]+Math.log(2*Math.PI*c[e]);return o}}(l,e,n);let d=new Float32Array(t.parameterNames.length),m=new Float32Array(t.parameterNames.length);for(let e=0;e<t.parameterNames.length;e++)d[e]=0===s[e]?-1:s[e]-Math.abs(.5*s[e]),m[e]=0===s[e]?1:s[e]+Math.abs(.5*s[e]);return i&&0!==i.length&&(d=new Float32Array(i.length),d.set(i.map((e=>e.min))),m=new Float32Array(i.length),m.set(i.map((e=>e.max)))),s=function(e,t,n,r,i=1,l=null,s=!0){const f=function(e,t,n){const r=t.length,o=new Array(e);for(let t=0;t<e;t++)o[t]=new Float32Array(r);for(let i=0;i<r;i++)if(t[i]===n[i])for(let n=0;n<e;n++)o[n][i]=t[i];else{const r=c(e,t[i],n[i]);for(let t=0;t<e;t++)o[t][i]=r[t]}return o}(i,n,t);null!==l&&(f[0]=l);const h=[],d=[],m=[];let p,g=0,v=null;for(p=0;p<i;++p)try{if(0===p&&s){const t=new Float32Array(l.length).map((e=>-1/0)),n=new Float32Array(l.length).map((e=>1/0));h.push(u(e,f[p],r,t,n))}else h.push(u(e,f[p],r,t,n))}catch(e){if(e instanceof a)throw new Error(`Inconsistent dataframes: ${e.message}`);++g,d.push(e instanceof Error?e.message:"Platform issue"),m.push(f[p])}if(g>0){const e=n.length,t=new Array(e);for(let n=0;n<e;++n)t[n]=new Float32Array(g);m.forEach(((e,n)=>e.forEach(((e,r)=>t[r][n]=e)))),v=o.DataFrame.fromColumns(t.map(((e,t)=>o.Column.fromFloat32Array(`arg${t}`,e)))),v.columns.add(o.Column.fromStrings("Issue",d))}return{extremums:h,fails:v}}(h,d,m,{tolerance:r.TOLERANCE,maxIter:r.MAX_ITER,nonZeroParam:r.NON_ZERO_PARAM,initialScale:r.INITIAL_SCALE,scaleReflection:r.SCALE_REFLECTION,scaleExpansion:r.SCALE_EXPANSION,scaleContraction:r.SCALE_CONTRACTION},1,s).extremums[0].point,{fittedCurve:x(l,s),parameters:s}}function x(e,t){return n=>e(t,n)}function A(e,t,n,r=.05,o){const a=function(e,t,n,r){let o=0,i=0;const a=t.y,l=t.x.map((t=>e(r,t))),s=a.map(((e,t)=>e-l[t])),u=s.map((e=>Math.pow(e,2)));for(let e=0;e<u.length;e++)[f.CONSTANT,f.COMBINED].includes(n)?o+=u[e]:n===f.PROPORTIONAL&&(i+=Math.pow(s[e]/Math.abs(l[e]),2));return o=Math.sqrt(o/u.length),i=Math.sqrt(i/u.length),n===f.COMBINED&&({sigmaA:o,sigmaB:i}=S(o,i,u,l)),{sigmaA:o,sigmaB:i}}(n,e,o,t),l=i.normal.inv(1-r/2,0,1);return{confidenceTop:e=>{const r=n(t,e);return r+l*(a.sigmaA+Math.abs(r)*a.sigmaB)},confidenceBottom:e=>{const r=n(t,e);return r-l*(a.sigmaA+Math.abs(r)*a.sigmaB)}}}function C(e,t,n,r=!0){const o=x(n,t);return{rSquared:r?O(o,e):void 0,auc:r?N(o,e):void 0,interceptX:t[2],interceptY:o(t[2]),slope:t[1],top:t[0],bottom:t[3]}}function N(e,t){let n=0;const r=Math.min(...t.x),o=Math.max(...t.x),i=(o-r)/1e3;for(let t=r;t<o;t+=i)n+=i*e(t);return n}function O(e,t){let n=0,r=0;const o=i.mean(t.y);for(let i=0;i<t.x.length;i++)n+=Math.pow(t.y[i]-e(t.x[i]),2),r+=Math.pow(t.y[i]-o,2);return 1-n/r}function S(e,t,n,r){let o=Number.MAX_VALUE,i=0;for(let t=0;t<=10;t++){let a=0;const l=t/10,s=e*l,u=e*(1-l),c=[];for(let e=0;e<n.length;e++)c[e]=Math.pow(s+u*r[e],2),a+=n[e]/c[e]+Math.log(2*Math.PI*c[e]);a<o&&(o=a,i=l)}return t=e*(1-i),{sigmaA:e*=i,sigmaB:t}}},999:(e,t,n)=>{"use strict";n.d(t,{Kh:()=>a,VA:()=>m,_T:()=>f,fY:()=>d,nT:()=>h,s$:()=>u,zB:()=>c});var r=n(82),o=n(71);function i(e){const t={};for(const n of e)null!==n.defaultValue&&(t[n.name]=n.defaultValue);return t}function a(){return{chartOptions:i(o.xs),seriesOptions:i(o.IL)}}function l(e){const t=[],n=[];for(let r=0;r<e.length;r++)t[r]=e[r].x,n[r]=e[r].y;return{xs:t,ys:n}}function s(e){const t=Math.floor(e.y.length/2),n=e.y.sort(((e,t)=>e-t));return n.length%2==0?(n[t-1]+n[t])/2:n[t]}function u(e){var t;const n=e.chartOptions;if((null===(t=e.series)||void 0===t?void 0:t.length)&&0!==e.series.length){const{xs:t,ys:o}=l(e.series[0].points);let i=r.Rect.fromXYArrays(t,o);for(let t=1;t<e.series.length;t++){const{xs:n,ys:o}=l(e.series[t].points);n.some((e=>void 0===e))||o.some((e=>void 0===e))||(i=i.union(r.Rect.fromXYArrays(n,o)))}return n?function(e,t){let n=e.x,o=e.y,i=e.width,a=e.height;return void 0!==t.minX&&null!==t.minX&&(!t.logX||t.logX&&t.minX>0)&&(i+=n-t.minX,n=t.minX),void 0!==t.maxX&&null!==t.maxX&&(!t.logX||t.logX&&t.maxX>0)&&(i+=t.maxX-(n+i)),void 0!==t.minY&&null!==t.minY&&(!t.logY||t.logY&&t.minY>0)&&(a+=o-t.minY,o=t.minY),void 0!==t.maxY&&null!==t.maxY&&(!t.logY||t.logY&&t.maxY>0)&&(a+=t.maxY-(o+a)),new r.Rect(n,o,i,a)}(i,n):i}return new r.Rect(0,0,1,1)}function c(e){return(0,o.TV)(e.fitFunction)}function f(e,t){var n;const r=new Float32Array(null===(n=e.parameters)||void 0===n?void 0:n.length);return r.set(e.parameters),(0,o.ah)(t.y,r)}function h(e,t,n){var r;const i={x:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logX)?Math.log10(e.x):e.x)),y:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logY)?Math.log10(e.y):e.y))};var a;return e.parameterBounds&&(null==n?void 0:n.logX)&&(e.parameterBounds[2]=((a=e.parameterBounds[2])&&(void 0!==a.max&&(a.max=Math.log10(a.max)),void 0!==a.min&&(a.min=0===a.min?-Number.MAX_VALUE:Math.log10(a.min))),a)),(0,o.W6)(function(e){const t={x:[],y:[]},n={x:[e.x[0]],y:[e.y[0]]};for(let r=1;r<e.x.length;r++){if(e.x[r]===n.x[0]){n.x[n.x.length]=e.x[r],n.y[n.y.length]=e.y[r];continue}const o=s(n);t.x[t.x.length]=n.x[0],t.y[t.y.length]=o,n.x=[e.x[r]],n.y=[e.y[r]]}const r=s(n);return t.x[t.x.length]=n.x[0],t.y[t.y.length]=r,t}(i),t,null!==(r=e.errorModel)&&void 0!==r?r:o.dZ.CONSTANT,e.parameterBounds)}function d(e,t,n,r){var i,a;const l=n?{x:e.points.map((e=>(null==r?void 0:r.logX)?Math.log10(e.x):e.x)),y:e.points.map((e=>(null==r?void 0:r.logY)?Math.log10(e.y):e.y))}:{x:e.points.filter((e=>!e.outlier)).map((e=>(null==r?void 0:r.logX)?Math.log10(e.x):e.x)),y:e.points.filter((e=>!e.outlier)).map((e=>(null==r?void 0:r.logY)?Math.log10(e.y):e.y))};if(!e.parameters){const n=h(e,t).parameters;e.parameters=[...n]}const s=new Float32Array(null===(i=e.parameters)||void 0===i?void 0:i.length);return s.set(e.parameters),(0,o.O8)(l,s,t.y,.05,null!==(a=e.errorModel)&&void 0!==a?a:o.dZ.CONSTANT)}function m(e,t,n){var r;const i={x:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logX)?Math.log10(e.x):e.x)),y:e.points.filter((e=>!e.outlier)).map((e=>(null==n?void 0:n.logY)?Math.log10(e.y):e.y))};if(!e.parameters){const n=h(e,t).parameters;e.parameters=[...n]}const a=new Float32Array(null===(r=e.parameters)||void 0===r?void 0:r.length);return a.set(e.parameters),(0,o.mW)(i,a,t.y,!0)}},293:(e,t,n)=>{"use strict";n.d(t,{L:()=>l});var r=n(82);const o=1e-30,i=new class{screenToWorld(e,t,n,r,o){return n+(o?1-e/t:e/t)*(r-n)}worldToScreen(e,t,n,r,o){return o?(1-(e-n)/(r-n))*t:(e-n)/(r-n)*t}},a=new class{screenToWorld(e,t,n,r,i){n=n<o?o:n;const a=Math.log(r),l=Math.log(n);return Math.exp(l+(a-l)*(i?t-e:e)/t)}worldToScreen(e,t,n,r,i){if(e<=0)return NaN;if(Math.abs(e-n)<o)return i?t:0;if(Math.abs(e-r)<o)return i?0:t;n=n<o?o:n,e=e<o?o:e;const a=t*Math.log(e/n)/Math.log(r/n);return i?t-a:a}};class l{get xt(){return this.logX?a:i}get yt(){return this.logY?a:i}constructor(e,t,n=!1,r=!1){this.logX=!1,this.logY=!1,this.inverseX=!1,this.inverseY=!1,this.world=e,this.screen=t,this.logX=n,this.logY=r}xToScreen(e){return this.screen.left+this.xt.worldToScreen(e,this.screen.width,this.world.minX,this.world.maxX,this.inverseX)}yToScreen(e){return this.screen.top+this.yt.worldToScreen(e,this.screen.height,this.world.minY,this.world.maxY,!this.inverseY)}xToWorld(e){return this.xt.screenToWorld(e-this.screen.left,this.screen.width,this.world.minX,this.world.maxX,this.inverseX)}yToWorld(e){return this.yt.screenToWorld(e-this.screen.top,this.screen.height,this.world.minY,this.world.maxY,!this.inverseY)}toScreen(e){return new r.Point(this.xToScreen(e.x),this.yToScreen(e.y))}toWorld(e){return new r.Point(this.xToWorld(e.x),this.yToWorld(e.y))}drawCoordinateGrid(e,t,n){t&&r.Paint.horzAxis(e,this.world.minX,this.world.maxX,t.x,t.y,t.width,t.height,this.logX,this.inverseX),n&&r.Paint.vertAxis(e,this.world.minY,this.world.maxY,n.x,n.y,n.width,n.height,this.logY,this.inverseY)}}},572:function(e){var t;e.exports=(t=function(e,t){var n=Array.prototype.concat,r=Array.prototype.slice,o=Object.prototype.toString;function i(t,n){var r=t>n?t:n;return e.pow(10,17-~~(e.log(r>0?r:-r)*e.LOG10E))}var a=Array.isArray||function(e){return"[object Array]"===o.call(e)};function l(e){return"[object Function]"===o.call(e)}function s(e){return"number"==typeof e&&e-e==0}function u(){return new u._init(arguments)}function c(){return 0}function f(){return 1}function h(e,t){return e===t?1:0}u.fn=u.prototype,u._init=function(e){if(a(e[0]))if(a(e[0][0])){l(e[1])&&(e[0]=u.map(e[0],e[1]));for(var t=0;t<e[0].length;t++)this[t]=e[0][t];this.length=e[0].length}else this[0]=l(e[1])?u.map(e[0],e[1]):e[0],this.length=1;else if(s(e[0]))this[0]=u.seq.apply(null,e),this.length=1;else{if(e[0]instanceof u)return u(e[0].toArray());this[0]=[],this.length=1}return this},u._init.prototype=u.prototype,u._init.constructor=u,u.utils={calcRdx:i,isArray:a,isFunction:l,isNumber:s,toVector:function(e){return n.apply([],e)}},u._random_fn=e.random,u.setRandom=function(e){if("function"!=typeof e)throw new TypeError("fn is not a function");u._random_fn=e},u.extend=function(e){var t,n;if(1===arguments.length){for(n in e)u[n]=e[n];return this}for(t=1;t<arguments.length;t++)for(n in arguments[t])e[n]=arguments[t][n];return e},u.rows=function(e){return e.length||1},u.cols=function(e){return e[0].length||1},u.dimensions=function(e){return{rows:u.rows(e),cols:u.cols(e)}},u.row=function(e,t){return a(t)?t.map((function(t){return u.row(e,t)})):e[t]},u.rowa=function(e,t){return u.row(e,t)},u.col=function(e,t){if(a(t)){var n=u.arange(e.length).map((function(){return new Array(t.length)}));return t.forEach((function(t,r){u.arange(e.length).forEach((function(o){n[o][r]=e[o][t]}))})),n}for(var r=new Array(e.length),o=0;o<e.length;o++)r[o]=[e[o][t]];return r},u.cola=function(e,t){return u.col(e,t).map((function(e){return e[0]}))},u.diag=function(e){for(var t=u.rows(e),n=new Array(t),r=0;r<t;r++)n[r]=[e[r][r]];return n},u.antidiag=function(e){for(var t=u.rows(e)-1,n=new Array(t),r=0;t>=0;t--,r++)n[r]=[e[r][t]];return n},u.transpose=function(e){var t,n,r,o,i,l=[];for(a(e[0])||(e=[e]),n=e.length,r=e[0].length,i=0;i<r;i++){for(t=new Array(n),o=0;o<n;o++)t[o]=e[o][i];l.push(t)}return 1===l.length?l[0]:l},u.map=function(e,t,n){var r,o,i,l,s;for(a(e[0])||(e=[e]),o=e.length,i=e[0].length,l=n?e:new Array(o),r=0;r<o;r++)for(l[r]||(l[r]=new Array(i)),s=0;s<i;s++)l[r][s]=t(e[r][s],r,s);return 1===l.length?l[0]:l},u.cumreduce=function(e,t,n){var r,o,i,l,s;for(a(e[0])||(e=[e]),o=e.length,i=e[0].length,l=n?e:new Array(o),r=0;r<o;r++)for(l[r]||(l[r]=new Array(i)),i>0&&(l[r][0]=e[r][0]),s=1;s<i;s++)l[r][s]=t(l[r][s-1],e[r][s]);return 1===l.length?l[0]:l},u.alter=function(e,t){return u.map(e,t,!0)},u.create=function(e,t,n){var r,o,i=new Array(e);for(l(t)&&(n=t,t=e),r=0;r<e;r++)for(i[r]=new Array(t),o=0;o<t;o++)i[r][o]=n(r,o);return i},u.zeros=function(e,t){return s(t)||(t=e),u.create(e,t,c)},u.ones=function(e,t){return s(t)||(t=e),u.create(e,t,f)},u.rand=function(e,t){return s(t)||(t=e),u.create(e,t,u._random_fn)},u.identity=function(e,t){return s(t)||(t=e),u.create(e,t,h)},u.symmetric=function(e){var t,n,r=e.length;if(e.length!==e[0].length)return!1;for(t=0;t<r;t++)for(n=0;n<r;n++)if(e[n][t]!==e[t][n])return!1;return!0},u.clear=function(e){return u.alter(e,c)},u.seq=function(e,t,n,r){l(r)||(r=!1);var o,a=[],s=i(e,t),u=(t*s-e*s)/((n-1)*s),c=e;for(o=0;c<=t&&o<n;c=(e*s+u*s*++o)/s)a.push(r?r(c,o):c);return a},u.arange=function(e,n,r){var o,i=[];if(r=r||1,n===t&&(n=e,e=0),e===n||0===r)return[];if(e<n&&r<0)return[];if(e>n&&r>0)return[];if(r>0)for(o=e;o<n;o+=r)i.push(o);else for(o=e;o>n;o+=r)i.push(o);return i},u.slice=function(){function e(e,n,r,o){var i,a=[],l=e.length;if(n===t&&r===t&&o===t)return u.copy(e);if(o=o||1,(n=(n=n||0)>=0?n:l+n)===(r=(r=r||e.length)>=0?r:l+r)||0===o)return[];if(n<r&&o<0)return[];if(n>r&&o>0)return[];if(o>0)for(i=n;i<r;i+=o)a.push(e[i]);else for(i=n;i>r;i+=o)a.push(e[i]);return a}return function(t,n){var r,o;return s((n=n||{}).row)?s(n.col)?t[n.row][n.col]:e(u.rowa(t,n.row),(r=n.col||{}).start,r.end,r.step):s(n.col)?e(u.cola(t,n.col),(o=n.row||{}).start,o.end,o.step):(o=n.row||{},r=n.col||{},e(t,o.start,o.end,o.step).map((function(t){return e(t,r.start,r.end,r.step)})))}}(),u.sliceAssign=function(n,r,o){var i,a;if(s(r.row)){if(s(r.col))return n[r.row][r.col]=o;r.col=r.col||{},r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,i=u.arange(r.col.start,e.min(n.length,r.col.end),r.col.step);var l=r.row;return i.forEach((function(e,t){n[l][e]=o[t]})),n}if(s(r.col)){r.row=r.row||{},r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,a=u.arange(r.row.start,e.min(n[0].length,r.row.end),r.row.step);var c=r.col;return a.forEach((function(e,t){n[e][c]=o[t]})),n}return o[0].length===t&&(o=[o]),r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,a=u.arange(r.row.start,e.min(n.length,r.row.end),r.row.step),i=u.arange(r.col.start,e.min(n[0].length,r.col.end),r.col.step),a.forEach((function(e,t){i.forEach((function(r,i){n[e][r]=o[t][i]}))})),n},u.diagonal=function(e){var t=u.zeros(e.length,e.length);return e.forEach((function(e,n){t[n][n]=e})),t},u.copy=function(e){return e.map((function(e){return s(e)?e:e.map((function(e){return e}))}))};var d=u.prototype;return d.length=0,d.push=Array.prototype.push,d.sort=Array.prototype.sort,d.splice=Array.prototype.splice,d.slice=Array.prototype.slice,d.toArray=function(){return this.length>1?r.call(this):r.call(this)[0]},d.map=function(e,t){return u(u.map(this,e,t))},d.cumreduce=function(e,t){return u(u.cumreduce(this,e,t))},d.alter=function(e){return u.alter(this,e),this},function(e){for(var t=0;t<e.length;t++)!function(e){d[e]=function(t){var n,r=this;return t?(setTimeout((function(){t.call(r,d[e].call(r))})),this):(n=u[e](this),a(n)?u(n):n)}}(e[t])}("transpose clear symmetric rows cols dimensions diag antidiag".split(" ")),function(e){for(var t=0;t<e.length;t++)!function(e){d[e]=function(t,n){var r=this;return n?(setTimeout((function(){n.call(r,d[e].call(r,t))})),this):u(u[e](this,t))}}(e[t])}("row col".split(" ")),function(e){for(var t=0;t<e.length;t++)!function(e){d[e]=function(){return u(u[e].apply(null,arguments))}}(e[t])}("create zeros ones rand identity".split(" ")),u}(Math),function(e,t){var n=e.utils.isFunction;function r(e,t){return e-t}function o(e,n,r){return t.max(n,t.min(e,r))}e.sum=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n];return t},e.sumsqrd=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n]*e[n];return t},e.sumsqerr=function(t){for(var n,r=e.mean(t),o=0,i=t.length;--i>=0;)o+=(n=t[i]-r)*n;return o},e.sumrow=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n];return t},e.product=function(e){for(var t=1,n=e.length;--n>=0;)t*=e[n];return t},e.min=function(e){for(var t=e[0],n=0;++n<e.length;)e[n]<t&&(t=e[n]);return t},e.max=function(e){for(var t=e[0],n=0;++n<e.length;)e[n]>t&&(t=e[n]);return t},e.unique=function(e){for(var t={},n=[],r=0;r<e.length;r++)t[e[r]]||(t[e[r]]=!0,n.push(e[r]));return n},e.mean=function(t){return e.sum(t)/t.length},e.meansqerr=function(t){return e.sumsqerr(t)/t.length},e.geomean=function(n){var r=n.map(t.log),o=e.mean(r);return t.exp(o)},e.median=function(e){var t=e.length,n=e.slice().sort(r);return 1&t?n[t/2|0]:(n[t/2-1]+n[t/2])/2},e.cumsum=function(t){return e.cumreduce(t,(function(e,t){return e+t}))},e.cumprod=function(t){return e.cumreduce(t,(function(e,t){return e*t}))},e.diff=function(e){var t,n=[],r=e.length;for(t=1;t<r;t++)n.push(e[t]-e[t-1]);return n},e.rank=function(e){var t,n=[],o={};for(t=0;t<e.length;t++)o[s=e[t]]?o[s]++:(o[s]=1,n.push(s));var i=n.sort(r),a={},l=1;for(t=0;t<i.length;t++){var s,u=o[s=i[t]],c=(l+(l+u-1))/2;a[s]=c,l+=u}return e.map((function(e){return a[e]}))},e.mode=function(e){var t,n=e.length,o=e.slice().sort(r),i=1,a=0,l=0,s=[];for(t=0;t<n;t++)o[t]===o[t+1]?i++:(i>a?(s=[o[t]],a=i,l=0):i===a&&(s.push(o[t]),l++),i=1);return 0===l?s[0]:s},e.range=function(t){return e.max(t)-e.min(t)},e.variance=function(t,n){return e.sumsqerr(t)/(t.length-(n?1:0))},e.pooledvariance=function(t){return t.reduce((function(t,n){return t+e.sumsqerr(n)}),0)/(t.reduce((function(e,t){return e+t.length}),0)-t.length)},e.deviation=function(t){for(var n=e.mean(t),r=t.length,o=new Array(r),i=0;i<r;i++)o[i]=t[i]-n;return o},e.stdev=function(n,r){return t.sqrt(e.variance(n,r))},e.pooledstdev=function(n){return t.sqrt(e.pooledvariance(n))},e.meandev=function(n){for(var r=e.mean(n),o=[],i=n.length-1;i>=0;i--)o.push(t.abs(n[i]-r));return e.mean(o)},e.meddev=function(n){for(var r=e.median(n),o=[],i=n.length-1;i>=0;i--)o.push(t.abs(n[i]-r));return e.median(o)},e.coeffvar=function(t){return e.stdev(t)/e.mean(t)},e.quartiles=function(e){var n=e.length,o=e.slice().sort(r);return[o[t.round(n/4)-1],o[t.round(n/2)-1],o[t.round(3*n/4)-1]]},e.quantiles=function(e,n,i,a){var l,s,u,c,f,h=e.slice().sort(r),d=[n.length],m=e.length;for(void 0===i&&(i=3/8),void 0===a&&(a=3/8),l=0;l<n.length;l++)u=m*(s=n[l])+(i+s*(1-i-a)),c=t.floor(o(u,1,m-1)),f=o(u-c,0,1),d[l]=(1-f)*h[c-1]+f*h[c];return d},e.percentile=function(e,t,n){var o=e.slice().sort(r),i=t*(o.length+(n?1:-1))+(n?0:1),a=parseInt(i),l=i-a;return a+1<o.length?o[a-1]+l*(o[a]-o[a-1]):o[a-1]},e.percentileOfScore=function(e,t,n){var r,o,i=0,a=e.length,l=!1;for("strict"===n&&(l=!0),o=0;o<a;o++)r=e[o],(l&&r<t||!l&&r<=t)&&i++;return i/a},e.histogram=function(n,r){r=r||4;var o,i=e.min(n),a=(e.max(n)-i)/r,l=n.length,s=[];for(o=0;o<r;o++)s[o]=0;for(o=0;o<l;o++)s[t.min(t.floor((n[o]-i)/a),r-1)]+=1;return s},e.covariance=function(t,n){var r,o=e.mean(t),i=e.mean(n),a=t.length,l=new Array(a);for(r=0;r<a;r++)l[r]=(t[r]-o)*(n[r]-i);return e.sum(l)/(a-1)},e.corrcoeff=function(t,n){return e.covariance(t,n)/e.stdev(t,1)/e.stdev(n,1)},e.spearmancoeff=function(t,n){return t=e.rank(t),n=e.rank(n),e.corrcoeff(t,n)},e.stanMoment=function(n,r){for(var o=e.mean(n),i=e.stdev(n),a=n.length,l=0,s=0;s<a;s++)l+=t.pow((n[s]-o)/i,r);return l/n.length},e.skewness=function(t){return e.stanMoment(t,3)},e.kurtosis=function(t){return e.stanMoment(t,4)-3};var i=e.prototype;!function(t){for(var r=0;r<t.length;r++)!function(t){i[t]=function(r,o){var a=[],l=0,s=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(s,i[t].call(s,r))})),this;if(this.length>1){for(s=!0===r?this:this.transpose();l<s.length;l++)a[l]=e[t](s[l]);return a}return e[t](this[0],r)}}(t[r])}("cumsum cumprod".split(" ")),function(t){for(var r=0;r<t.length;r++)!function(t){i[t]=function(r,o){var a=[],l=0,s=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(s,i[t].call(s,r))})),this;if(this.length>1){for("sumrow"!==t&&(s=!0===r?this:this.transpose());l<s.length;l++)a[l]=e[t](s[l]);return!0===r?e[t](e.utils.toVector(a)):a}return e[t](this[0],r)}}(t[r])}("sum sumsqrd sumsqerr sumrow product min max unique mean meansqerr geomean median diff rank mode range variance deviation stdev meandev meddev coeffvar quartiles histogram skewness kurtosis".split(" ")),function(t){for(var r=0;r<t.length;r++)!function(t){i[t]=function(){var r,o=[],a=0,l=this,s=Array.prototype.slice.call(arguments);if(n(s[s.length-1])){r=s[s.length-1];var u=s.slice(0,s.length-1);return setTimeout((function(){r.call(l,i[t].apply(l,u))})),this}r=void 0;var c=function(n){return e[t].apply(l,[n].concat(s))};if(this.length>1){for(l=l.transpose();a<l.length;a++)o[a]=c(l[a]);return o}return c(this[0])}}(t[r])}("quantiles percentileOfScore".split(" "))}(t,Math),function(e,t){e.gammaln=function(e){var n,r,o,i=0,a=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],l=1.000000000190015;for(o=(r=n=e)+5.5,o-=(n+.5)*t.log(o);i<6;i++)l+=a[i]/++r;return t.log(2.5066282746310007*l/n)-o},e.loggam=function(e){var n,r,o,i,a,l,s,u=[.08333333333333333,-.002777777777777778,.0007936507936507937,-.0005952380952380952,.0008417508417508418,-.001917526917526918,.00641025641025641,-.02955065359477124,.1796443723688307,-1.3924322169059];if(n=e,s=0,1==e||2==e)return 0;for(e<=7&&(n=e+(s=t.floor(7-e))),r=1/(n*n),o=2*t.PI,a=u[9],l=8;l>=0;l--)a*=r,a+=u[l];if(i=a/n+.5*t.log(o)+(n-.5)*t.log(n)-n,e<=7)for(l=1;l<=s;l++)i-=t.log(n-1),n-=1;return i},e.gammafn=function(e){var n,r,o,i,a=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],l=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],s=!1,u=0,c=0,f=0,h=e;if(e>171.6243769536076)return 1/0;if(h<=0){if(!(i=h%1+36e-17))return 1/0;s=(1&h?-1:1)*t.PI/t.sin(t.PI*i),h=1-h}for(o=h,r=h<1?h++:(h-=u=(0|h)-1)-1,n=0;n<8;++n)f=(f+a[n])*r,c=c*r+l[n];if(i=f/c+1,o<h)i/=o;else if(o>h)for(n=0;n<u;++n)i*=h,h++;return s&&(i=s/i),i},e.gammap=function(t,n){return e.lowRegGamma(t,n)*e.gammafn(t)},e.lowRegGamma=function(n,r){var o,i=e.gammaln(n),a=n,l=1/n,s=l,u=r+1-n,c=1/1e-30,f=1/u,h=f,d=1,m=-~(8.5*t.log(n>=1?n:1/n)+.4*n+17);if(r<0||n<=0)return NaN;if(r<n+1){for(;d<=m;d++)l+=s*=r/++a;return l*t.exp(-r+n*t.log(r)-i)}for(;d<=m;d++)h*=(f=1/(f=(o=-d*(d-n))*f+(u+=2)))*(c=u+o/c);return 1-h*t.exp(-r+n*t.log(r)-i)},e.factorialln=function(t){return t<0?NaN:e.gammaln(t+1)},e.factorial=function(t){return t<0?NaN:e.gammafn(t+1)},e.combination=function(n,r){return n>170||r>170?t.exp(e.combinationln(n,r)):e.factorial(n)/e.factorial(r)/e.factorial(n-r)},e.combinationln=function(t,n){return e.factorialln(t)-e.factorialln(n)-e.factorialln(t-n)},e.permutation=function(t,n){return e.factorial(t)/e.factorial(t-n)},e.betafn=function(n,r){if(!(n<=0||r<=0))return n+r>170?t.exp(e.betaln(n,r)):e.gammafn(n)*e.gammafn(r)/e.gammafn(n+r)},e.betaln=function(t,n){return e.gammaln(t)+e.gammaln(n)-e.gammaln(t+n)},e.betacf=function(e,n,r){var o,i,a,l,s=1e-30,u=1,c=n+r,f=n+1,h=n-1,d=1,m=1-c*e/f;for(t.abs(m)<s&&(m=s),l=m=1/m;u<=100&&(m=1+(i=u*(r-u)*e/((h+(o=2*u))*(n+o)))*m,t.abs(m)<s&&(m=s),d=1+i/d,t.abs(d)<s&&(d=s),l*=(m=1/m)*d,m=1+(i=-(n+u)*(c+u)*e/((n+o)*(f+o)))*m,t.abs(m)<s&&(m=s),d=1+i/d,t.abs(d)<s&&(d=s),l*=a=(m=1/m)*d,!(t.abs(a-1)<3e-7));u++);return l},e.gammapinv=function(n,r){var o,i,a,l,s,u,c=0,f=r-1,h=e.gammaln(r);if(n>=1)return t.max(100,r+100*t.sqrt(r));if(n<=0)return 0;for(r>1?(s=t.log(f),u=t.exp(f*(s-1)-h),l=n<.5?n:1-n,o=(2.30753+.27061*(i=t.sqrt(-2*t.log(l))))/(1+i*(.99229+.04481*i))-i,n<.5&&(o=-o),o=t.max(.001,r*t.pow(1-1/(9*r)-o/(3*t.sqrt(r)),3))):o=n<(i=1-r*(.253+.12*r))?t.pow(n/i,1/r):1-t.log(1-(n-i)/(1-i));c<12;c++){if(o<=0)return 0;if((o-=i=(a=(e.lowRegGamma(r,o)-n)/(i=r>1?u*t.exp(-(o-f)+f*(t.log(o)-s)):t.exp(-o+f*t.log(o)-h)))/(1-.5*t.min(1,a*((r-1)/o-1))))<=0&&(o=.5*(o+i)),t.abs(i)<1e-8*o)break}return o},e.erf=function(e){var n,r,o,i,a=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],l=a.length-1,s=!1,u=0,c=0;for(e<0&&(e=-e,s=!0),r=4*(n=2/(2+e))-2;l>0;l--)o=u,u=r*u-c+a[l],c=o;return i=n*t.exp(-e*e+.5*(a[0]+r*u)-c),s?i-1:1-i},e.erfc=function(t){return 1-e.erf(t)},e.erfcinv=function(n){var r,o,i,a,l=0;if(n>=2)return-100;if(n<=0)return 100;for(a=n<1?n:2-n,r=-.70711*((2.30753+.27061*(i=t.sqrt(-2*t.log(a/2))))/(1+i*(.99229+.04481*i))-i);l<2;l++)r+=(o=e.erfc(r)-a)/(1.1283791670955126*t.exp(-r*r)-r*o);return n<1?r:-r},e.ibetainv=function(n,r,o){var i,a,l,s,u,c,f,h,d,m,p=r-1,g=o-1,v=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&o>=1?(l=n<.5?n:1-n,c=(2.30753+.27061*(s=t.sqrt(-2*t.log(l))))/(1+s*(.99229+.04481*s))-s,n<.5&&(c=-c),f=(c*c-3)/6,h=2/(1/(2*r-1)+1/(2*o-1)),d=c*t.sqrt(f+h)/h-(1/(2*o-1)-1/(2*r-1))*(f+5/6-2/(3*h)),c=r/(r+o*t.exp(2*d))):(i=t.log(r/(r+o)),a=t.log(o/(r+o)),c=n<(s=t.exp(r*i)/r)/(d=s+(u=t.exp(o*a)/o))?t.pow(r*d*n,1/r):1-t.pow(o*d*(1-n),1/o)),m=-e.gammaln(r)-e.gammaln(o)+e.gammaln(r+o);v<10;v++){if(0===c||1===c)return c;if((c-=s=(u=(e.ibeta(c,r,o)-n)/(s=t.exp(p*t.log(c)+g*t.log(1-c)+m)))/(1-.5*t.min(1,u*(p/c-g/(1-c)))))<=0&&(c=.5*(c+s)),c>=1&&(c=.5*(c+s+1)),t.abs(s)<1e-8*c&&v>0)break}return c},e.ibeta=function(n,r,o){var i=0===n||1===n?0:t.exp(e.gammaln(r+o)-e.gammaln(r)-e.gammaln(o)+r*t.log(n)+o*t.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+o+2)?i*e.betacf(n,r,o)/r:1-i*e.betacf(1-n,o,r)/o)},e.randn=function(n,r){var o,i,a,l,s;if(r||(r=n),n)return e.create(n,r,(function(){return e.randn()}));do{o=e._random_fn(),i=1.7156*(e._random_fn()-.5),s=(a=o-.449871)*a+(l=t.abs(i)+.386595)*(.196*l-.25472*a)}while(s>.27597&&(s>.27846||i*i>-4*t.log(o)*o*o));return i/o},e.randg=function(n,r,o){var i,a,l,s,u,c,f=n;if(o||(o=r),n||(n=1),r)return(c=e.zeros(r,o)).alter((function(){return e.randg(n)})),c;n<1&&(n+=1),i=n-1/3,a=1/t.sqrt(9*i);do{do{s=1+a*(u=e.randn())}while(s<=0);s*=s*s,l=e._random_fn()}while(l>1-.331*t.pow(u,4)&&t.log(l)>.5*u*u+i*(1-s+t.log(s)));if(n==f)return i*s;do{l=e._random_fn()}while(0===l);return t.pow(l,1/f)*i*s},function(t){for(var n=0;n<t.length;n++)!function(t){e.fn[t]=function(){return e(e.map(this,(function(n){return e[t](n)})))}}(t[n])}("gammaln gammafn factorial factorialln".split(" ")),function(t){for(var n=0;n<t.length;n++)!function(t){e.fn[t]=function(){return e(e[t].apply(null,arguments))}}(t[n])}("randn".split(" "))}(t,Math),function(e,t){function n(e,n,r,o){for(var i,a=0,l=1,s=1,u=1,c=0,f=0;t.abs((s-f)/s)>o;)f=s,l=u+(i=-(n+c)*(n+r+c)*e/(n+2*c)/(n+2*c+1))*l,s=(a=s+i*a)+(i=(c+=1)*(r-c)*e/(n+2*c-1)/(n+2*c))*s,a/=u=l+i*u,l/=u,s/=u,u=1;return s/n}function r(n,r,o){var i=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],a=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],l=.5*n;if(l>=8)return 1;var s,u=2*e.normal.cdf(l,0,1,1,0)-1;u=u>=t.exp(-50/o)?t.pow(u,o):0;for(var c=l,f=(8-l)/(s=n>3?2:3),h=c+f,d=0,m=o-1,p=1;p<=s;p++){for(var g=0,v=.5*(h+c),_=.5*(h-c),T=1;T<=12;T++){var w,E=v+_*(6<T?i[(w=12-T+1)-1]:-i[(w=T)-1]),I=E*E;if(I>60)break;var y=2*e.normal.cdf(E,0,1,1,0)*.5-2*e.normal.cdf(E,n,1,1,0)*.5;y>=t.exp(-30/m)&&(g+=y=a[w-1]*t.exp(-.5*I)*t.pow(y,m))}d+=g*=2*_*o/t.sqrt(2*t.PI),c=h,h+=f}return(u+=d)<=t.exp(-30/r)?0:(u=t.pow(u,r))>=1?1:u}!function(t){for(var n=0;n<t.length;n++)!function(t){e[t]=function e(t,n,r){return this instanceof e?(this._a=t,this._b=n,this._c=r,this):new e(t,n,r)},e.fn[t]=function(n,r,o){var i=e[t](n,r,o);return i.data=this,i},e[t].prototype.sample=function(n){var r=this._a,o=this._b,i=this._c;return n?e.alter(n,(function(){return e[t].sample(r,o,i)})):e[t].sample(r,o,i)},function(n){for(var r=0;r<n.length;r++)!function(n){e[t].prototype[n]=function(r){var o=this._a,i=this._b,a=this._c;return r||0===r||(r=this.data),"number"!=typeof r?e.fn.map.call(r,(function(r){return e[t][n](r,o,i,a)})):e[t][n](r,o,i,a)}}(n[r])}("pdf cdf inv".split(" ")),function(n){for(var r=0;r<n.length;r++)!function(n){e[t].prototype[n]=function(){return e[t][n](this._a,this._b,this._c)}}(n[r])}("mean median mode variance".split(" "))}(t[n])}("beta centralF cauchy chisquare exponential gamma invgamma kumaraswamy laplace lognormal noncentralt normal pareto studentt weibull uniform binomial negbin hypgeom poisson triangular tukey arcsine".split(" ")),e.extend(e.beta,{pdf:function(n,r,o){return n>1||n<0?0:1==r&&1==o?1:r<512&&o<512?t.pow(n,r-1)*t.pow(1-n,o-1)/e.betafn(r,o):t.exp((r-1)*t.log(n)+(o-1)*t.log(1-n)-e.betaln(r,o))},cdf:function(t,n,r){return t>1||t<0?1*(t>1):e.ibeta(t,n,r)},inv:function(t,n,r){return e.ibetainv(t,n,r)},mean:function(e,t){return e/(e+t)},median:function(t,n){return e.ibetainv(.5,t,n)},mode:function(e,t){return(e-1)/(e+t-2)},sample:function(t,n){var r=e.randg(t);return r/(r+e.randg(n))},variance:function(e,n){return e*n/(t.pow(e+n,2)*(e+n+1))}}),e.extend(e.centralF,{pdf:function(n,r,o){var i;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/e.betafn(r/2,o/2)*t.pow(r/o,r/2)*t.pow(n,r/2-1)*t.pow(1+r/o*n,-(r+o)/2):(i=r*n/(o+n*r),r*(o/(o+n*r))/2*e.binomial.pdf((r-2)/2,(r+o-2)/2,i))},cdf:function(t,n,r){return t<0?0:e.ibeta(n*t/(n*t+r),n/2,r/2)},inv:function(t,n,r){return r/(n*(1/e.ibetainv(t,n/2,r/2)-1))},mean:function(e,t){return t>2?t/(t-2):void 0},mode:function(e,t){return e>2?t*(e-2)/(e*(t+2)):void 0},sample:function(t,n){return 2*e.randg(t/2)/t/(2*e.randg(n/2)/n)},variance:function(e,t){if(!(t<=4))return 2*t*t*(e+t-2)/(e*(t-2)*(t-2)*(t-4))}}),e.extend(e.cauchy,{pdf:function(e,n,r){return r<0?0:r/(t.pow(e-n,2)+t.pow(r,2))/t.PI},cdf:function(e,n,r){return t.atan((e-n)/r)/t.PI+.5},inv:function(e,n,r){return n+r*t.tan(t.PI*(e-.5))},median:function(e){return e},mode:function(e){return e},sample:function(n,r){return e.randn()*t.sqrt(1/(2*e.randg(.5)))*r+n}}),e.extend(e.chisquare,{pdf:function(n,r){return n<0?0:0===n&&2===r?.5:t.exp((r/2-1)*t.log(n)-n/2-r/2*t.log(2)-e.gammaln(r/2))},cdf:function(t,n){return t<0?0:e.lowRegGamma(n/2,t/2)},inv:function(t,n){return 2*e.gammapinv(t,.5*n)},mean:function(e){return e},median:function(e){return e*t.pow(1-2/(9*e),3)},mode:function(e){return e-2>0?e-2:0},sample:function(t){return 2*e.randg(t/2)},variance:function(e){return 2*e}}),e.extend(e.exponential,{pdf:function(e,n){return e<0?0:n*t.exp(-n*e)},cdf:function(e,n){return e<0?0:1-t.exp(-n*e)},inv:function(e,n){return-t.log(1-e)/n},mean:function(e){return 1/e},median:function(e){return 1/e*t.log(2)},mode:function(){return 0},sample:function(n){return-1/n*t.log(e._random_fn())},variance:function(e){return t.pow(e,-2)}}),e.extend(e.gamma,{pdf:function(n,r,o){return n<0?0:0===n&&1===r?1/o:t.exp((r-1)*t.log(n)-n/o-e.gammaln(r)-r*t.log(o))},cdf:function(t,n,r){return t<0?0:e.lowRegGamma(n,t/r)},inv:function(t,n,r){return e.gammapinv(t,n)*r},mean:function(e,t){return e*t},mode:function(e,t){if(e>1)return(e-1)*t},sample:function(t,n){return e.randg(t)*n},variance:function(e,t){return e*t*t}}),e.extend(e.invgamma,{pdf:function(n,r,o){return n<=0?0:t.exp(-(r+1)*t.log(n)-o/n-e.gammaln(r)+r*t.log(o))},cdf:function(t,n,r){return t<=0?0:1-e.lowRegGamma(n,r/t)},inv:function(t,n,r){return r/e.gammapinv(1-t,n)},mean:function(e,t){return e>1?t/(e-1):void 0},mode:function(e,t){return t/(e+1)},sample:function(t,n){return n/e.randg(t)},variance:function(e,t){if(!(e<=2))return t*t/((e-1)*(e-1)*(e-2))}}),e.extend(e.kumaraswamy,{pdf:function(e,n,r){return 0===e&&1===n?r:1===e&&1===r?n:t.exp(t.log(n)+t.log(r)+(n-1)*t.log(e)+(r-1)*t.log(1-t.pow(e,n)))},cdf:function(e,n,r){return e<0?0:e>1?1:1-t.pow(1-t.pow(e,n),r)},inv:function(e,n,r){return t.pow(1-t.pow(1-e,1/r),1/n)},mean:function(t,n){return n*e.gammafn(1+1/t)*e.gammafn(n)/e.gammafn(1+1/t+n)},median:function(e,n){return t.pow(1-t.pow(2,-1/n),1/e)},mode:function(e,n){if(e>=1&&n>=1&&1!==e&&1!==n)return t.pow((e-1)/(e*n-1),1/e)},variance:function(){throw new Error("variance not yet implemented")}}),e.extend(e.lognormal,{pdf:function(e,n,r){return e<=0?0:t.exp(-t.log(e)-.5*t.log(2*t.PI)-t.log(r)-t.pow(t.log(e)-n,2)/(2*r*r))},cdf:function(n,r,o){return n<0?0:.5+.5*e.erf((t.log(n)-r)/t.sqrt(2*o*o))},inv:function(n,r,o){return t.exp(-1.4142135623730951*o*e.erfcinv(2*n)+r)},mean:function(e,n){return t.exp(e+n*n/2)},median:function(e){return t.exp(e)},mode:function(e,n){return t.exp(e-n*n)},sample:function(n,r){return t.exp(e.randn()*r+n)},variance:function(e,n){return(t.exp(n*n)-1)*t.exp(2*e+n*n)}}),e.extend(e.noncentralt,{pdf:function(n,r,o){return t.abs(o)<1e-14?e.studentt.pdf(n,r):t.abs(n)<1e-14?t.exp(e.gammaln((r+1)/2)-o*o/2-.5*t.log(t.PI*r)-e.gammaln(r/2)):r/n*(e.noncentralt.cdf(n*t.sqrt(1+2/r),r+2,o)-e.noncentralt.cdf(n,r,o))},cdf:function(n,r,o){var i=1e-14;if(t.abs(o)<i)return e.studentt.cdf(n,r);var a=!1;n<0&&(a=!0,o=-o);for(var l=e.normal.cdf(-o,0,1),s=i+1,u=s,c=n*n/(n*n+r),f=0,h=t.exp(-o*o/2),d=t.exp(-o*o/2-.5*t.log(2)-e.gammaln(1.5))*o;f<200||u>i||s>i;)u=s,f>0&&(h*=o*o/(2*f),d*=o*o/(2*(f+.5))),l+=.5*(s=h*e.beta.cdf(c,f+.5,r/2)+d*e.beta.cdf(c,f+1,r/2)),f++;return a?1-l:l}}),e.extend(e.normal,{pdf:function(e,n,r){return t.exp(-.5*t.log(2*t.PI)-t.log(r)-t.pow(e-n,2)/(2*r*r))},cdf:function(n,r,o){return.5*(1+e.erf((n-r)/t.sqrt(2*o*o)))},inv:function(t,n,r){return-1.4142135623730951*r*e.erfcinv(2*t)+n},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},sample:function(t,n){return e.randn()*n+t},variance:function(e,t){return t*t}}),e.extend(e.pareto,{pdf:function(e,n,r){return e<n?0:r*t.pow(n,r)/t.pow(e,r+1)},cdf:function(e,n,r){return e<n?0:1-t.pow(n/e,r)},inv:function(e,n,r){return n/t.pow(1-e,1/r)},mean:function(e,n){if(!(n<=1))return n*t.pow(e,n)/(n-1)},median:function(e,n){return e*(n*t.SQRT2)},mode:function(e){return e},variance:function(e,n){if(!(n<=2))return e*e*n/(t.pow(n-1,2)*(n-2))}}),e.extend(e.studentt,{pdf:function(n,r){return r=r>1e100?1e100:r,1/(t.sqrt(r)*e.betafn(.5,r/2))*t.pow(1+n*n/r,-(r+1)/2)},cdf:function(n,r){var o=r/2;return e.ibeta((n+t.sqrt(n*n+r))/(2*t.sqrt(n*n+r)),o,o)},inv:function(n,r){var o=e.ibetainv(2*t.min(n,1-n),.5*r,.5);return o=t.sqrt(r*(1-o)/o),n>.5?o:-o},mean:function(e){return e>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(n){return e.randn()*t.sqrt(n/(2*e.randg(n/2)))},variance:function(e){return e>2?e/(e-2):e>1?1/0:void 0}}),e.extend(e.weibull,{pdf:function(e,n,r){return e<0||n<0||r<0?0:r/n*t.pow(e/n,r-1)*t.exp(-t.pow(e/n,r))},cdf:function(e,n,r){return e<0?0:1-t.exp(-t.pow(e/n,r))},inv:function(e,n,r){return n*t.pow(-t.log(1-e),1/r)},mean:function(t,n){return t*e.gammafn(1+1/n)},median:function(e,n){return e*t.pow(t.log(2),1/n)},mode:function(e,n){return n<=1?0:e*t.pow((n-1)/n,1/n)},sample:function(n,r){return n*t.pow(-t.log(e._random_fn()),1/r)},variance:function(n,r){return n*n*e.gammafn(1+2/r)-t.pow(e.weibull.mean(n,r),2)}}),e.extend(e.uniform,{pdf:function(e,t,n){return e<t||e>n?0:1/(n-t)},cdf:function(e,t,n){return e<t?0:e<n?(e-t)/(n-t):1},inv:function(e,t,n){return t+e*(n-t)},mean:function(e,t){return.5*(e+t)},median:function(t,n){return e.mean(t,n)},mode:function(){throw new Error("mode is not yet implemented")},sample:function(t,n){return t/2+n/2+(n/2-t/2)*(2*e._random_fn()-1)},variance:function(e,n){return t.pow(n-e,2)/12}}),e.extend(e.binomial,{pdf:function(n,r,o){return 0===o||1===o?r*o===n?1:0:e.combination(r,n)*t.pow(o,n)*t.pow(1-o,r-n)},cdf:function(r,o,i){var a,l=1e-10;if(r<0)return 0;if(r>=o)return 1;if(i<0||i>1||o<=0)return NaN;var s=i,u=(r=t.floor(r))+1,c=o-r,f=u+c,h=t.exp(e.gammaln(f)-e.gammaln(c)-e.gammaln(u)+u*t.log(s)+c*t.log(1-s));return a=s<(u+1)/(f+2)?h*n(s,u,c,l):1-h*n(1-s,c,u,l),t.round(1/l*(1-a))/(1/l)}}),e.extend(e.negbin,{pdf:function(n,r,o){return n===n>>>0&&(n<0?0:e.combination(n+r-1,r-1)*t.pow(1-o,n)*t.pow(o,r))},cdf:function(t,n,r){var o=0,i=0;if(t<0)return 0;for(;i<=t;i++)o+=e.negbin.pdf(i,n,r);return o}}),e.extend(e.hypgeom,{pdf:function(n,r,o,i){if(n!=n|0)return!1;if(n<0||n<o-(r-i))return 0;if(n>i||n>o)return 0;if(2*o>r)return 2*i>r?e.hypgeom.pdf(r-o-i+n,r,r-o,r-i):e.hypgeom.pdf(i-n,r,r-o,i);if(2*i>r)return e.hypgeom.pdf(o-n,r,o,r-i);if(o<i)return e.hypgeom.pdf(n,r,i,o);for(var a=1,l=0,s=0;s<n;s++){for(;a>1&&l<i;)a*=1-o/(r-l),l++;a*=(i-s)*(o-s)/((s+1)*(r-o-i+s+1))}for(;l<i;l++)a*=1-o/(r-l);return t.min(1,t.max(0,a))},cdf:function(n,r,o,i){if(n<0||n<o-(r-i))return 0;if(n>=i||n>=o)return 1;if(2*o>r)return 2*i>r?e.hypgeom.cdf(r-o-i+n,r,r-o,r-i):1-e.hypgeom.cdf(i-n-1,r,r-o,i);if(2*i>r)return 1-e.hypgeom.cdf(o-n-1,r,o,r-i);if(o<i)return e.hypgeom.cdf(n,r,i,o);for(var a=1,l=1,s=0,u=0;u<n;u++){for(;a>1&&s<i;){var c=1-o/(r-s);l*=c,a*=c,s++}a+=l*=(i-u)*(o-u)/((u+1)*(r-o-i+u+1))}for(;s<i;s++)a*=1-o/(r-s);return t.min(1,t.max(0,a))}}),e.extend(e.poisson,{pdf:function(n,r){return r<0||n%1!=0||n<0?0:t.pow(r,n)*t.exp(-r)/e.factorial(n)},cdf:function(t,n){var r=[],o=0;if(t<0)return 0;for(;o<=t;o++)r.push(e.poisson.pdf(o,n));return e.sum(r)},mean:function(e){return e},variance:function(e){return e},sampleSmall:function(n){var r=1,o=0,i=t.exp(-n);do{o++,r*=e._random_fn()}while(r>i);return o-1},sampleLarge:function(n){var r,o,i,a,l,s,u,c,f,h,d=n;for(a=t.sqrt(d),l=t.log(d),s=.02483*(u=.931+2.53*a)-.059,c=1.1239+1.1328/(u-3.4),f=.9277-3.6224/(u-2);;){if(o=t.random()-.5,i=t.random(),h=.5-t.abs(o),r=t.floor((2*s/h+u)*o+d+.43),h>=.07&&i<=f)return r;if(!(r<0||h<.013&&i>h)&&t.log(i)+t.log(c)-t.log(s/(h*h)+u)<=r*l-d-e.loggam(r+1))return r}},sample:function(e){return e<10?this.sampleSmall(e):this.sampleLarge(e)}}),e.extend(e.triangular,{pdf:function(e,t,n,r){return n<=t||r<t||r>n?NaN:e<t||e>n?0:e<r?2*(e-t)/((n-t)*(r-t)):e===r?2/(n-t):2*(n-e)/((n-t)*(n-r))},cdf:function(e,n,r,o){return r<=n||o<n||o>r?NaN:e<=n?0:e>=r?1:e<=o?t.pow(e-n,2)/((r-n)*(o-n)):1-t.pow(r-e,2)/((r-n)*(r-o))},inv:function(e,n,r,o){return r<=n||o<n||o>r?NaN:e<=(o-n)/(r-n)?n+(r-n)*t.sqrt(e*((o-n)/(r-n))):n+(r-n)*(1-t.sqrt((1-e)*(1-(o-n)/(r-n))))},mean:function(e,t,n){return(e+t+n)/3},median:function(e,n,r){return r<=(e+n)/2?n-t.sqrt((n-e)*(n-r))/t.sqrt(2):r>(e+n)/2?e+t.sqrt((n-e)*(r-e))/t.sqrt(2):void 0},mode:function(e,t,n){return n},sample:function(n,r,o){var i=e._random_fn();return i<(o-n)/(r-n)?n+t.sqrt(i*(r-n)*(o-n)):r-t.sqrt((1-i)*(r-n)*(r-o))},variance:function(e,t,n){return(e*e+t*t+n*n-e*t-e*n-t*n)/18}}),e.extend(e.arcsine,{pdf:function(e,n,r){return r<=n?NaN:e<=n||e>=r?0:2/t.PI*t.pow(t.pow(r-n,2)-t.pow(2*e-n-r,2),-.5)},cdf:function(e,n,r){return e<n?0:e<r?2/t.PI*t.asin(t.sqrt((e-n)/(r-n))):1},inv:function(e,n,r){return n+(.5-.5*t.cos(t.PI*e))*(r-n)},mean:function(e,t){return t<=e?NaN:(e+t)/2},median:function(e,t){return t<=e?NaN:(e+t)/2},mode:function(){throw new Error("mode is not yet implemented")},sample:function(n,r){return(n+r)/2+(r-n)/2*t.sin(2*t.PI*e.uniform.sample(0,1))},variance:function(e,n){return n<=e?NaN:t.pow(n-e,2)/8}}),e.extend(e.laplace,{pdf:function(e,n,r){return r<=0?0:t.exp(-t.abs(e-n)/r)/(2*r)},cdf:function(e,n,r){return r<=0?0:e<n?.5*t.exp((e-n)/r):1-.5*t.exp(-(e-n)/r)},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},variance:function(e,t){return 2*t*t},sample:function(n,r){var o,i=e._random_fn()-.5;return n-r*((o=i)/t.abs(o))*t.log(1-2*t.abs(i))}}),e.extend(e.tukey,{cdf:function(n,o,i){var a=o,l=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],s=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(i<2||a<2)return NaN;if(!Number.isFinite(n))return 1;if(i>25e3)return r(n,1,a);var u,c=.5*i,f=c*t.log(i)-i*t.log(2)-e.gammaln(c),h=c-1,d=.25*i;u=i<=100?1:i<=800?.5:i<=5e3?.25:.125,f+=t.log(u);for(var m=0,p=1;p<=50;p++){for(var g=0,v=(2*p-1)*u,_=1;_<=16;_++){var T,w;8<_?(T=_-8-1,w=f+h*t.log(v+l[T]*u)-(l[T]*u+v)*d):(T=_-1,w=f+h*t.log(v-l[T]*u)+(l[T]*u-v)*d),w>=-30&&(g+=r(8<_?n*t.sqrt(.5*(l[T]*u+v)):n*t.sqrt(.5*(-l[T]*u+v)),1,a)*s[T]*t.exp(w))}if(p*u>=1&&g<=1e-14)break;m+=g}if(g>1e-14)throw new Error("tukey.cdf failed to converge");return m>1&&(m=1),m},inv:function(n,r,o){if(o<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var i,a=function(e,n,r){var o=.5-.5*e,i=t.sqrt(t.log(1/(o*o))),a=i+((((-453642210148e-16*i-.204231210125)*i-.342242088547)*i-1)*i+.322232421088)/((((.0038560700634*i+.10353775285)*i+.531103462366)*i+.588581570495)*i+.099348462606);r<120&&(a+=(a*a*a+a)/r/4);var l=.8832-.2368*a;return r<120&&(l+=-1.214/r+1.208*a/r),a*(l*t.log(n-1)+1.4142)}(n,r,o),l=e.tukey.cdf(a,r,o)-n;i=l>0?t.max(0,a-1):a+1;for(var s,u=e.tukey.cdf(i,r,o)-n,c=1;c<50;c++)if(s=i-u*(i-a)/(u-l),l=u,a=i,s<0&&(s=0,u=-n),u=e.tukey.cdf(s,r,o)-n,i=s,t.abs(i-a)<1e-4)return s;throw new Error("tukey.inv failed to converge")}})}(t,Math),function(e,t){var n,r,o=Array.prototype.push,i=e.utils.isArray;function a(t){return i(t)||t instanceof e}e.extend({add:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.map(t,(function(e,t,r){return e+n[t][r]}))):e.map(t,(function(e){return e+n}))},subtract:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.map(t,(function(e,t,r){return e-n[t][r]||0}))):e.map(t,(function(e){return e-n}))},divide:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.multiply(t,e.inv(n))):e.map(t,(function(e){return e/n}))},multiply:function(t,n){var r,o,i,l,s,u,c,f;if(void 0===t.length&&void 0===n.length)return t*n;if(s=t.length,u=t[0].length,c=e.zeros(s,i=a(n)?n[0].length:u),f=0,a(n)){for(;f<i;f++)for(r=0;r<s;r++){for(l=0,o=0;o<u;o++)l+=t[r][o]*n[o][f];c[r][f]=l}return 1===s&&1===f?c[0][0]:c}return e.map(t,(function(e){return e*n}))},outer:function(t,n){return e.multiply(t.map((function(e){return[e]})),[n])},dot:function(t,n){a(t[0])||(t=[t]),a(n[0])||(n=[n]);for(var r,o,i=1===t[0].length&&1!==t.length?e.transpose(t):t,l=1===n[0].length&&1!==n.length?e.transpose(n):n,s=[],u=0,c=i.length,f=i[0].length;u<c;u++){for(s[u]=[],r=0,o=0;o<f;o++)r+=i[u][o]*l[u][o];s[u]=r}return 1===s.length?s[0]:s},pow:function(n,r){return e.map(n,(function(e){return t.pow(e,r)}))},exp:function(n){return e.map(n,(function(e){return t.exp(e)}))},log:function(n){return e.map(n,(function(e){return t.log(e)}))},abs:function(n){return e.map(n,(function(e){return t.abs(e)}))},norm:function(e,n){var r=0,o=0;for(isNaN(n)&&(n=2),a(e[0])&&(e=e[0]);o<e.length;o++)r+=t.pow(t.abs(e[o]),n);return t.pow(r,1/n)},angle:function(n,r){return t.acos(e.dot(n,r)/(e.norm(n)*e.norm(r)))},aug:function(e,t){var n,r=[];for(n=0;n<e.length;n++)r.push(e[n].slice());for(n=0;n<r.length;n++)o.apply(r[n],t[n]);return r},inv:function(t){for(var n,r=t.length,o=t[0].length,i=e.identity(r,o),a=e.gauss_jordan(t,i),l=[],s=0;s<r;s++)for(l[s]=[],n=o;n<a[0].length;n++)l[s][n-o]=a[s][n];return l},det:function e(t){if(2===t.length)return t[0][0]*t[1][1]-t[0][1]*t[1][0];for(var n=0,r=0;r<t.length;r++){for(var o=[],i=1;i<t.length;i++){o[i-1]=[];for(var a=0;a<t.length;a++)a<r?o[i-1][a]=t[i][a]:a>r&&(o[i-1][a-1]=t[i][a])}var l=r%2?-1:1;n+=e(o)*t[0][r]*l}return n},gauss_elimination:function(n,r){var o,i,a,l,s=0,u=0,c=n.length,f=n[0].length,h=1,d=0,m=[];for(o=(n=e.aug(n,r))[0].length,s=0;s<c;s++){for(i=n[s][s],u=s,l=s+1;l<f;l++)i<t.abs(n[l][s])&&(i=n[l][s],u=l);if(u!=s)for(l=0;l<o;l++)a=n[s][l],n[s][l]=n[u][l],n[u][l]=a;for(u=s+1;u<c;u++)for(h=n[u][s]/n[s][s],l=s;l<o;l++)n[u][l]=n[u][l]-h*n[s][l]}for(s=c-1;s>=0;s--){for(d=0,u=s+1;u<=c-1;u++)d+=m[u]*n[s][u];m[s]=(n[s][o-1]-d)/n[s][s]}return m},gauss_jordan:function(n,r){var o,i,a,l=e.aug(n,r),s=l.length,u=l[0].length,c=0;for(i=0;i<s;i++){var f=i;for(a=i+1;a<s;a++)t.abs(l[a][i])>t.abs(l[f][i])&&(f=a);var h=l[i];for(l[i]=l[f],l[f]=h,a=i+1;a<s;a++)for(c=l[a][i]/l[i][i],o=i;o<u;o++)l[a][o]-=l[i][o]*c}for(i=s-1;i>=0;i--){for(c=l[i][i],a=0;a<i;a++)for(o=u-1;o>i-1;o--)l[a][o]-=l[i][o]*l[a][i]/c;for(l[i][i]/=c,o=s;o<u;o++)l[i][o]/=c}return l},triaUpSolve:function(t,n){var r,o=t[0].length,i=e.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(e){return e[0]})),a=!0),e.arange(o-1,-1,-1).forEach((function(a){r=e.arange(a+1,o).map((function(e){return i[e]*t[a][e]})),i[a]=(n[a]-e.sum(r))/t[a][a]})),a?i.map((function(e){return[e]})):i},triaLowSolve:function(t,n){var r,o=t[0].length,i=e.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(e){return e[0]})),a=!0),e.arange(o).forEach((function(o){r=e.arange(o).map((function(e){return t[o][e]*i[e]})),i[o]=(n[o]-e.sum(r))/t[o][o]})),a?i.map((function(e){return[e]})):i},lu:function(t){var n,r=t.length,o=e.identity(r),i=e.zeros(t.length,t[0].length);return e.arange(r).forEach((function(e){i[0][e]=t[0][e]})),e.arange(1,r).forEach((function(a){e.arange(a).forEach((function(r){n=e.arange(r).map((function(e){return o[a][e]*i[e][r]})),o[a][r]=(t[a][r]-e.sum(n))/i[r][r]})),e.arange(a,r).forEach((function(r){n=e.arange(a).map((function(e){return o[a][e]*i[e][r]})),i[a][r]=t[n.length][r]-e.sum(n)}))})),[o,i]},cholesky:function(n){var r,o=n.length,i=e.zeros(n.length,n[0].length);return e.arange(o).forEach((function(a){r=e.arange(a).map((function(e){return t.pow(i[a][e],2)})),i[a][a]=t.sqrt(n[a][a]-e.sum(r)),e.arange(a+1,o).forEach((function(t){r=e.arange(a).map((function(e){return i[a][e]*i[t][e]})),i[t][a]=(n[a][t]-e.sum(r))/i[a][a]}))})),i},gauss_jacobi:function(n,r,o,i){for(var a,l,s,u,c=0,f=0,h=n.length,d=[],m=[],p=[];c<h;c++)for(d[c]=[],m[c]=[],p[c]=[],f=0;f<h;f++)c>f?(d[c][f]=n[c][f],m[c][f]=p[c][f]=0):c<f?(m[c][f]=n[c][f],d[c][f]=p[c][f]=0):(p[c][f]=n[c][f],d[c][f]=m[c][f]=0);for(s=e.multiply(e.multiply(e.inv(p),e.add(d,m)),-1),l=e.multiply(e.inv(p),r),a=o,u=e.add(e.multiply(s,o),l),c=2;t.abs(e.norm(e.subtract(u,a)))>i;)a=u,u=e.add(e.multiply(s,a),l),c++;return u},gauss_seidel:function(n,r,o,i){for(var a,l,s,u,c,f=0,h=n.length,d=[],m=[],p=[];f<h;f++)for(d[f]=[],m[f]=[],p[f]=[],a=0;a<h;a++)f>a?(d[f][a]=n[f][a],m[f][a]=p[f][a]=0):f<a?(m[f][a]=n[f][a],d[f][a]=p[f][a]=0):(p[f][a]=n[f][a],d[f][a]=m[f][a]=0);for(u=e.multiply(e.multiply(e.inv(e.add(p,d)),m),-1),s=e.multiply(e.inv(e.add(p,d)),r),l=o,c=e.add(e.multiply(u,o),s),f=2;t.abs(e.norm(e.subtract(c,l)))>i;)l=c,c=e.add(e.multiply(u,l),s),f+=1;return c},SOR:function(n,r,o,i,a){for(var l,s,u,c,f,h=0,d=n.length,m=[],p=[],g=[];h<d;h++)for(m[h]=[],p[h]=[],g[h]=[],l=0;l<d;l++)h>l?(m[h][l]=n[h][l],p[h][l]=g[h][l]=0):h<l?(p[h][l]=n[h][l],m[h][l]=g[h][l]=0):(g[h][l]=n[h][l],m[h][l]=p[h][l]=0);for(c=e.multiply(e.inv(e.add(g,e.multiply(m,a))),e.subtract(e.multiply(g,1-a),e.multiply(p,a))),u=e.multiply(e.multiply(e.inv(e.add(g,e.multiply(m,a))),r),a),s=o,f=e.add(e.multiply(c,o),u),h=2;t.abs(e.norm(e.subtract(f,s)))>i;)s=f,f=e.add(e.multiply(c,s),u),h++;return f},householder:function(n){for(var r,o,i,a,l=n.length,s=n[0].length,u=0,c=[],f=[];u<l-1;u++){for(r=0,a=u+1;a<s;a++)r+=n[a][u]*n[a][u];for(r=(n[u+1][u]>0?-1:1)*t.sqrt(r),o=t.sqrt((r*r-n[u+1][u]*r)/2),(c=e.zeros(l,1))[u+1][0]=(n[u+1][u]-r)/(2*o),i=u+2;i<l;i++)c[i][0]=n[i][u]/(2*o);f=e.subtract(e.identity(l,s),e.multiply(e.multiply(c,e.transpose(c)),2)),n=e.multiply(f,e.multiply(n,f))}return n},QR:(n=e.sum,r=e.arange,function(o){var i,a,l,s=o.length,u=o[0].length,c=e.zeros(u,u);for(o=e.copy(o),a=0;a<u;a++){for(c[a][a]=t.sqrt(n(r(s).map((function(e){return o[e][a]*o[e][a]})))),i=0;i<s;i++)o[i][a]=o[i][a]/c[a][a];for(l=a+1;l<u;l++)for(c[a][l]=n(r(s).map((function(e){return o[e][a]*o[e][l]}))),i=0;i<s;i++)o[i][l]=o[i][l]-o[i][a]*c[a][l]}return[o,c]}),lstsq:function(t,n){var r=!1;void 0===n[0].length&&(n=n.map((function(e){return[e]})),r=!0);var o=e.QR(t),i=o[0],a=o[1],l=t[0].length,s=e.slice(i,{col:{end:l}}),u=function(t){var n=(t=e.copy(t)).length,r=e.identity(n);return e.arange(n-1,-1,-1).forEach((function(n){e.sliceAssign(r,{row:n},e.divide(e.slice(r,{row:n}),t[n][n])),e.sliceAssign(t,{row:n},e.divide(e.slice(t,{row:n}),t[n][n])),e.arange(n).forEach((function(o){var i=e.multiply(t[o][n],-1),a=e.slice(t,{row:o}),l=e.multiply(e.slice(t,{row:n}),i);e.sliceAssign(t,{row:o},e.add(a,l));var s=e.slice(r,{row:o}),u=e.multiply(e.slice(r,{row:n}),i);e.sliceAssign(r,{row:o},e.add(s,u))}))})),r}(e.slice(a,{row:{end:l}})),c=e.transpose(s);void 0===c[0].length&&(c=[c]);var f=e.multiply(e.multiply(u,c),n);return void 0===f.length&&(f=[[f]]),r?f.map((function(e){return e[0]})):f},jacobi:function(n){for(var r,o,i,a,l,s,u,c=1,f=n.length,h=e.identity(f,f),d=[];1===c;){for(l=n[0][1],i=0,a=1,r=0;r<f;r++)for(o=0;o<f;o++)r!=o&&l<t.abs(n[r][o])&&(l=t.abs(n[r][o]),i=r,a=o);for(s=n[i][i]===n[a][a]?n[i][a]>0?t.PI/4:-t.PI/4:t.atan(2*n[i][a]/(n[i][i]-n[a][a]))/2,(u=e.identity(f,f))[i][i]=t.cos(s),u[i][a]=-t.sin(s),u[a][i]=t.sin(s),u[a][a]=t.cos(s),h=e.multiply(h,u),n=e.multiply(e.multiply(e.inv(u),n),u),c=0,r=1;r<f;r++)for(o=1;o<f;o++)r!=o&&t.abs(n[r][o])>.001&&(c=1)}for(r=0;r<f;r++)d.push(n[r][r]);return[h,d]},rungekutta:function(e,t,n,r,o,i){var a,l,s;if(2===i)for(;r<=n;)o+=((a=t*e(r,o))+(l=t*e(r+t,o+a)))/2,r+=t;if(4===i)for(;r<=n;)o+=((a=t*e(r,o))+2*(l=t*e(r+t/2,o+a/2))+2*(s=t*e(r+t/2,o+l/2))+t*e(r+t,o+s))/6,r+=t;return o},romberg:function(e,n,r,o){for(var i,a,l,s,u,c=0,f=(r-n)/2,h=[],d=[],m=[];c<o/2;){for(u=e(n),l=n,s=0;l<=r;l+=f,s++)h[s]=l;for(i=h.length,l=1;l<i-1;l++)u+=(l%2!=0?4:2)*e(h[l]);u=f/3*(u+e(r)),m[c]=u,f/=2,c++}for(a=m.length,i=1;1!==a;){for(l=0;l<a-1;l++)d[l]=(t.pow(4,i)*m[l+1]-m[l])/(t.pow(4,i)-1);a=d.length,m=d,d=[],i++}return m},richardson:function(e,n,r,o){function i(e,t){for(var n,r=0,o=e.length;r<o;r++)e[r]===t&&(n=r);return n}for(var a,l,s,u,c,f=t.abs(r-e[i(e,r)+1]),h=0,d=[],m=[];o>=f;)a=i(e,r+o),l=i(e,r),d[h]=(n[a]-2*n[l]+n[2*l-a])/(o*o),o/=2,h++;for(u=d.length,s=1;1!=u;){for(c=0;c<u-1;c++)m[c]=(t.pow(4,s)*d[c+1]-d[c])/(t.pow(4,s)-1);u=m.length,d=m,m=[],s++}return d},simpson:function(e,t,n,r){for(var o,i=(n-t)/r,a=e(t),l=[],s=t,u=0,c=1;s<=n;s+=i,u++)l[u]=s;for(o=l.length;c<o-1;c++)a+=(c%2!=0?4:2)*e(l[c]);return i/3*(a+e(n))},hermite:function(e,t,n,r){for(var o,i=e.length,a=0,l=0,s=[],u=[],c=[],f=[];l<i;l++){for(s[l]=1,o=0;o<i;o++)l!=o&&(s[l]*=(r-e[o])/(e[l]-e[o]));for(u[l]=0,o=0;o<i;o++)l!=o&&(u[l]+=1/(e[l]-e[o]));c[l]=(1-2*(r-e[l])*u[l])*(s[l]*s[l]),f[l]=(r-e[l])*(s[l]*s[l]),a+=c[l]*t[l]+f[l]*n[l]}return a},lagrange:function(e,t,n){for(var r,o,i=0,a=0,l=e.length;a<l;a++){for(o=t[a],r=0;r<l;r++)a!=r&&(o*=(n-e[r])/(e[a]-e[r]));i+=o}return i},cubic_spline:function(t,n,r){for(var o,i,a=t.length,l=0,s=[],u=[],c=[],f=[],h=[],d=[];l<a-1;l++)f[l]=t[l+1]-t[l];for(c[0]=0,l=1;l<a-1;l++)c[l]=3/f[l]*(n[l+1]-n[l])-3/f[l-1]*(n[l]-n[l-1]);for(l=1;l<a-1;l++)s[l]=[],u[l]=[],s[l][l-1]=f[l-1],s[l][l]=2*(f[l-1]+f[l]),s[l][l+1]=f[l],u[l][0]=c[l];for(i=e.multiply(e.inv(s),u),o=0;o<a-1;o++)h[o]=(n[o+1]-n[o])/f[o]-f[o]*(i[o+1][0]+2*i[o][0])/3,d[o]=(i[o+1][0]-i[o][0])/(3*f[o]);for(o=0;o<a&&!(t[o]>r);o++);return n[o-=1]+(r-t[o])*h[o]+e.sq(r-t[o])*i[o]+(r-t[o])*e.sq(r-t[o])*d[o]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(t){var n,r,o,i,a,l=t.length,s=t[0].length,u=0,c=[],f=[],h=[],d=[],m=[],p=[],g=[];for(u=0;u<l;u++)c[u]=e.sum(t[u])/s;for(u=0;u<s;u++)for(m[u]=[],n=0;n<l;n++)m[u][n]=t[n][u]-c[n];for(m=e.transpose(m),u=0;u<l;u++)for(p[u]=[],n=0;n<l;n++)p[u][n]=e.dot([m[u]],[m[n]])/(s-1);for(a=(o=e.jacobi(p))[0],f=o[1],g=e.transpose(a),u=0;u<f.length;u++)for(n=u;n<f.length;n++)f[u]<f[n]&&(r=f[u],f[u]=f[n],f[n]=r,h=g[u],g[u]=g[n],g[n]=h);for(i=e.transpose(m),u=0;u<l;u++)for(d[u]=[],n=0;n<i.length;n++)d[u][n]=e.dot([g[u]],[i[n]]);return[t,f,g,d]}}),function(t){for(var n=0;n<t.length;n++)!function(t){e.fn[t]=function(n,r){var o=this;return r?(setTimeout((function(){r.call(o,e.fn[t].call(o,n))}),15),this):"number"==typeof e[t](this,n)?e[t](this,n):e(e[t](this,n))}}(t[n])}("add divide multiply subtract dot pow exp log abs norm angle".split(" "))}(t,Math),function(e,t){var n=[].slice,r=e.utils.isNumber,o=e.utils.isArray;function i(e,n,r,o){if(e>1||r>1||e<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var i=(e*n+r*o)/(n+o);return(e-r)/t.sqrt(i*(1-i)*(1/n+1/o))}e.extend({zscore:function(){var t=n.call(arguments);return r(t[1])?(t[0]-t[1])/t[2]:(t[0]-e.mean(t[1]))/e.stdev(t[1],t[2])},ztest:function(){var r,i=n.call(arguments);return o(i[1])?(r=e.zscore(i[0],i[1],i[3]),1===i[2]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1)):i.length>2?(r=e.zscore(i[0],i[1],i[2]),1===i[3]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1)):(r=i[0],1===i[1]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1))}}),e.extend(e.fn,{zscore:function(e,t){return(e-this.mean())/this.stdev(t)},ztest:function(n,r,o){var i=t.abs(this.zscore(n,o));return 1===r?e.normal.cdf(-i,0,1):2*e.normal.cdf(-i,0,1)}}),e.extend({tscore:function(){var r=n.call(arguments);return 4===r.length?(r[0]-r[1])/(r[2]/t.sqrt(r[3])):(r[0]-e.mean(r[1]))/(e.stdev(r[1],!0)/t.sqrt(r[1].length))},ttest:function(){var o,i=n.call(arguments);return 5===i.length?(o=t.abs(e.tscore(i[0],i[1],i[2],i[3])),1===i[4]?e.studentt.cdf(-o,i[3]-1):2*e.studentt.cdf(-o,i[3]-1)):r(i[1])?(o=t.abs(i[0]),1==i[2]?e.studentt.cdf(-o,i[1]-1):2*e.studentt.cdf(-o,i[1]-1)):(o=t.abs(e.tscore(i[0],i[1])),1==i[2]?e.studentt.cdf(-o,i[1].length-1):2*e.studentt.cdf(-o,i[1].length-1))}}),e.extend(e.fn,{tscore:function(e){return(e-this.mean())/(this.stdev(!0)/t.sqrt(this.cols()))},ttest:function(n,r){return 1===r?1-e.studentt.cdf(t.abs(this.tscore(n)),this.cols()-1):2*e.studentt.cdf(-t.abs(this.tscore(n)),this.cols()-1)}}),e.extend({anovafscore:function(){var r,o,i,a,l,s,u,c,f=n.call(arguments);if(1===f.length){for(l=new Array(f[0].length),u=0;u<f[0].length;u++)l[u]=f[0][u];f=l}for(o=new Array,u=0;u<f.length;u++)o=o.concat(f[u]);for(i=e.mean(o),r=0,u=0;u<f.length;u++)r+=f[u].length*t.pow(e.mean(f[u])-i,2);for(r/=f.length-1,s=0,u=0;u<f.length;u++)for(a=e.mean(f[u]),c=0;c<f[u].length;c++)s+=t.pow(f[u][c]-a,2);return r/(s/(o.length-f.length))},anovaftest:function(){var t,o,i,a,l=n.call(arguments);if(r(l[0]))return 1-e.centralF.cdf(l[0],l[1],l[2]);var s=e.anovafscore(l);for(t=l.length-1,i=0,a=0;a<l.length;a++)i+=l[a].length;return o=i-t-1,1-e.centralF.cdf(s,t,o)},ftest:function(t,n,r){return 1-e.centralF.cdf(t,n,r)}}),e.extend(e.fn,{anovafscore:function(){return e.anovafscore(this.toArray())},anovaftes:function(){var t,n=0;for(t=0;t<this.length;t++)n+=this[t].length;return e.ftest(this.anovafscore(),this.length-1,n-this.length)}}),e.extend({qscore:function(){var o,i,a,l,s,u=n.call(arguments);return r(u[0])?(o=u[0],i=u[1],a=u[2],l=u[3],s=u[4]):(o=e.mean(u[0]),i=e.mean(u[1]),a=u[0].length,l=u[1].length,s=u[2]),t.abs(o-i)/(s*t.sqrt((1/a+1/l)/2))},qtest:function(){var t,r=n.call(arguments);3===r.length?(t=r[0],r=r.slice(1)):7===r.length?(t=e.qscore(r[0],r[1],r[2],r[3],r[4]),r=r.slice(5)):(t=e.qscore(r[0],r[1],r[2]),r=r.slice(3));var o=r[0],i=r[1];return 1-e.tukey.cdf(t,i,o-i)},tukeyhsd:function(t){for(var n=e.pooledstdev(t),r=t.map((function(t){return e.mean(t)})),o=t.reduce((function(e,t){return e+t.length}),0),i=[],a=0;a<t.length;++a)for(var l=a+1;l<t.length;++l){var s=e.qtest(r[a],r[l],t[a].length,t[l].length,n,o,t.length);i.push([[a,l],s])}return i}}),e.extend({normalci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?t.abs(e.normal.inv(o[1]/2,0,1)*o[2]/t.sqrt(o[3])):t.abs(e.normal.inv(o[1]/2,0,1)*e.stdev(o[2])/t.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},tci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?t.abs(e.studentt.inv(o[1]/2,o[3]-1)*o[2]/t.sqrt(o[3])):t.abs(e.studentt.inv(o[1]/2,o[2].length-1)*e.stdev(o[2],!0)/t.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},significant:function(e,t){return e<t}}),e.extend(e.fn,{normalci:function(t,n){return e.normalci(t,n,this.toArray())},tci:function(t,n){return e.tci(t,n,this.toArray())}}),e.extend(e.fn,{oneSidedDifferenceOfProportions:function(t,n,r,o){var a=i(t,n,r,o);return e.ztest(a,1)},twoSidedDifferenceOfProportions:function(t,n,r,o){var a=i(t,n,r,o);return e.ztest(a,2)}})}(t,Math),t.models=function(){function e(e,n){var r=e.length,o=n[0].length-1,i=r-o-1,a=t.lstsq(n,e),l=t.multiply(n,a.map((function(e){return[e]}))).map((function(e){return e[0]})),s=t.subtract(e,l),u=t.mean(e),c=t.sum(l.map((function(e){return Math.pow(e-u,2)}))),f=t.sum(e.map((function(e,t){return Math.pow(e-l[t],2)}))),h=c+f;return{exog:n,endog:e,nobs:r,df_model:o,df_resid:i,coef:a,predict:l,resid:s,ybar:u,SST:h,SSE:c,SSR:f,R2:c/h}}function n(n){var r,o,i=(r=n.exog,o=r[0].length,t.arange(o).map((function(n){var i=t.arange(o).filter((function(e){return e!==n}));return e(t.col(r,n).map((function(e){return e[0]})),t.col(r,i))}))),a=Math.sqrt(n.SSR/n.df_resid),l=i.map((function(e){var t=e.SST,n=e.R2;return a/Math.sqrt(t*(1-n))})),s=n.coef.map((function(e,t){return(e-0)/l[t]})),u=s.map((function(e){var r=t.studentt.cdf(e,n.df_resid);return 2*(r>.5?1-r:r)})),c=t.studentt.inv(.975,n.df_resid),f=n.coef.map((function(e,t){var n=c*l[t];return[e-n,e+n]}));return{se:l,t:s,p:u,sigmaHat:a,interval95:f}}return{ols:function(r,o){var i=e(r,o),a=n(i),l=function(e){var n,r,o,i=e.R2/e.df_model/((1-e.R2)/e.df_resid);return{F_statistic:i,pvalue:1-(n=i,r=e.df_model,o=e.df_resid,t.beta.cdf(n/(o/r+n),r/2,o/2))}}(i),s=1-(1-i.R2)*((i.nobs-1)/i.df_resid);return i.t=a,i.f=l,i.adjust_R2=s,i}}}(),t.extend({buildxmatrix:function(){for(var e=new Array(arguments.length),n=0;n<arguments.length;n++)e[n]=[1].concat(arguments[n]);return t(e)},builddxmatrix:function(){for(var e=new Array(arguments[0].length),n=0;n<arguments[0].length;n++)e[n]=[1].concat(arguments[0][n]);return t(e)},buildjxmatrix:function(e){for(var n=new Array(e.length),r=0;r<e.length;r++)n[r]=e[r];return t.builddxmatrix(n)},buildymatrix:function(e){return t(e).transpose()},buildjymatrix:function(e){return e.transpose()},matrixmult:function(e,n){var r,o,i,a,l;if(e.cols()==n.rows()){if(n.rows()>1){for(a=[],r=0;r<e.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(l=0,i=0;i<e.cols();i++)l+=e.toArray()[r][i]*n.toArray()[i][o];a[r][o]=l}return t(a)}for(a=[],r=0;r<e.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(l=0,i=0;i<e.cols();i++)l+=e.toArray()[r][i]*n.toArray()[o];a[r][o]=l}return t(a)}},regress:function(e,n){var r=t.xtranspxinv(e),o=e.transpose(),i=t.matrixmult(t(r),o);return t.matrixmult(i,n)},regresst:function(e,n,r){var o=t.regress(e,n),i={anova:{}},a=t.jMatYBar(e,o);i.yBar=a;var l=n.mean();i.anova.residuals=t.residuals(n,a),i.anova.ssr=t.ssr(a,l),i.anova.msr=i.anova.ssr/(e[0].length-1),i.anova.sse=t.sse(n,a),i.anova.mse=i.anova.sse/(n.length-(e[0].length-1)-1),i.anova.sst=t.sst(n,l),i.anova.mst=i.anova.sst/(n.length-1),i.anova.r2=1-i.anova.sse/i.anova.sst,i.anova.r2<0&&(i.anova.r2=0),i.anova.fratio=i.anova.msr/i.anova.mse,i.anova.pvalue=t.anovaftest(i.anova.fratio,e[0].length-1,n.length-(e[0].length-1)-1),i.anova.rmse=Math.sqrt(i.anova.mse),i.anova.r2adj=1-i.anova.mse/i.anova.mst,i.anova.r2adj<0&&(i.anova.r2adj=0),i.stats=new Array(e[0].length);for(var s,u,c,f=t.xtranspxinv(e),h=0;h<o.length;h++)s=Math.sqrt(i.anova.mse*Math.abs(f[h][h])),u=Math.abs(o[h]/s),c=t.ttest(u,n.length-e[0].length-1,r),i.stats[h]=[o[h],s,u,c];return i.regress=o,i},xtranspx:function(e){return t.matrixmult(e.transpose(),e)},xtranspxinv:function(e){var n=t.matrixmult(e.transpose(),e);return t.inv(n)},jMatYBar:function(e,n){var r=t.matrixmult(e,n);return new t(r)},residuals:function(e,n){return t.matrixsubtract(e,n)},ssr:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t,2);return n},sse:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t[r],2);return n},sst:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t,2);return n},matrixsubtract:function(e,n){for(var r=new Array(e.length),o=0;o<e.length;o++){r[o]=new Array(e[o].length);for(var i=0;i<e[o].length;i++)r[o][i]=e[o][i]-n[o][i]}return t(r)}}),t.jStat=t,t)},326:(e,t,n)=>{"use strict";n.d(t,{D:()=>a});var r=n(82),o=n(389),i=n(755);class a extends r.JsViewer{constructor(e){super(),this.canvas=o.canvas(),this.gridCellStyle=r.GridCellStyle.create(),this.renderer=e,this.root.append(this.canvas),this.canvas.style.width="100%",this.canvas.style.height="100%",o.tools.handleResize(this.canvas,((e,t)=>{this.canvas.width=e,this.canvas.height=t,this.render()}));const t=e=>t=>{this.gridCell&&e(this.gridCell,t)};this.canvas.onmousemove=t(this.renderer.onMouseMove),this.canvas.onmouseenter=t(this.renderer.onMouseEnter),this.canvas.onmouseleave=t(this.renderer.onMouseLeave)}static fromGridCell(e){const t=new a(new i.lR);return t.gridCell=e,t.render(),t}render(){if(!this.gridCell)return;const e=this.canvas.getContext("2d");e.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderer.renderInternal(e,0,0,this.canvas.width,this.canvas.height,this.gridCell.dart,this.gridCellStyle)}}},95:(e,t,n)=>{"use strict";n.d(t,{h:()=>r});class r{}r.TAG_FIT_CHART_FORMAT=".fitChartFormat",r.TAG_FIT_CHART_FORMAT_3DX="3dx",r.FIT_SEM_TYPE="fit",r.FIT_CELL_TYPE="fit",r.TAG_FIT=".fit",r.CELL_DEFAULT_WIDTH=230,r.CELL_DEFAULT_HEIGHT=160,r.MIN_CELL_RENDERER_PX_WIDTH=20,r.MIN_CELL_RENDERER_PX_HEIGHT=10,r.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH=70,r.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT=45,r.MIN_AXES_CELL_PX_WIDTH=100,r.MIN_AXES_CELL_PX_HEIGHT=55,r.MIN_TITLE_PX_WIDTH=275,r.MIN_TITLE_PX_HEIGHT=225,r.MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH=180,r.MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT=140,r.MIN_LEGEND_PX_WIDTH=325,r.MIN_LEGEND_PX_HEIGHT=275,r.MIN_DROPLINES_VISIBILITY_PX_WIDTH=120,r.MIN_DROPLINES_VISIBILITY_PX_HEIGHT=110,r.AXES_LEFT_PX_MARGIN=38,r.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS=45,r.AXES_TOP_PX_MARGIN=5,r.AXES_TOP_PX_MARGIN_WITH_TITLE=25,r.AXES_RIGHT_PX_MARGIN=18,r.AXES_BOTTOM_PX_MARGIN=15,r.AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS=30,r.X_AXIS_LABEL_BOTTOM_PX_MARGIN=4,r.LEGEND_TOP_PX_MARGIN=10,r.OUTLIER_PX_SIZE=12,r.POINT_PX_SIZE=4,r.OUTLIER_HITBOX_RADIUS=2,r.CANDLESTICK_BORDER_PX_SIZE=4,r.CANDLESTICK_MEDIAN_PX_SIZE=3.5,r.CANDLESTICK_OUTLIER_PX_SIZE=6,r.INFLATE_SIZE=-6,r.LEGEND_RECORD_PX_HEIGHT=18,r.LEGEND_RECORD_LINE_PX_WIDTH=20,r.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN=5,r.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN=4,r.LINE_STYLES={solid:[],dotted:[1,1],dashed:[5,5],dashdotted:[5,5,2,5]},r.CURVE_CONFIDENCE_INTERVAL_BOUNDS={TOP:"top",BOTTOM:"bottom"},r.CONFIDENCE_INTERVAL_STROKE_COLOR="rgba(255,191,63,0.4)",r.CONFIDENCE_INTERVAL_FILL_COLOR="rgba(255,238,204,0.3)",r.CONDITION_MAP={"No series to show":e=>void 0===e||0===(null==e?void 0:e.length),"There were series with no points":e=>e.some((e=>{var t;return 0===(null===(t=e.points)||void 0===t?void 0:t.length)})),"There were series with all x zeroes":e=>e.some((e=>{var t;return null===(t=e.points)||void 0===t?void 0:t.every((e=>0===e.x))})),"There were series with all y zeroes":e=>e.some((e=>{var t;return null===(t=e.points)||void 0===t?void 0:t.every((e=>0===e.y))}))}},471:(e,t,n)=>{"use strict";n.d(t,{Z1:()=>a}),n(82);var r=n(328),o=n(860),i=(n(71),n(991),n(95),function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((r=r.apply(e,t||[])).next())}))});function a(){return i(this,void 0,void 0,(function*(){r.shell.windows.showContextPanel=!0;const e=yield r.data.loadTable(`${o._package.webRoot}files/curves-demo.csv`);r.shell.addTableView(e)}))}},48:(e,t,n)=>{"use strict";n.d(t,{JR:()=>v,VK:()=>g,e4:()=>w});var r=n(82),o=n(389),i=n(999),a=n(71),l=n(755),s=n(326),u=n(283),c=n(95),f=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((r=r.apply(e,t||[])).next())}))};const h="chartOptions",d="seriesOptions";var m;!function(e){e.DATAFRAME="Dataframe",e.COLUMN="Column",e.CELL="Cell"}(m||(m={}));const p={count:"totalCount",nulls:"missingValueCount",unique:"uniqueCount",values:"valueCount",min:"min",max:"max",sum:"sum",avg:"avg",stdev:"stdev",variance:"variance",skew:"skew",kurt:"kurt",med:"med",q1:"q1",q2:"q2",q3:"q3"};function g(e,t){const n=(0,i.zB)(e);if(e.parameters)t.logX&&e.parameters[2]>0&&(e.parameters[2]=Math.log10(e.parameters[2]));else{const r=(0,i.nT)(e,n,t).parameters;e.parameters=[...r]}return(0,i.VA)(e,n,t)}function v(e,t){var n,o,i;const a={logX:null===(n=e.chartOptions)||void 0===n?void 0:n.logX,logY:null===(o=e.chartOptions)||void 0===o?void 0:o.logY},l=[],s=[],u=[],c=[],f=[],h=[],d=[];for(let t=0,n=0;t<(null===(i=e.series)||void 0===i?void 0:i.length);t++){if(e.series[t].points.every((e=>e.outlier)))continue;const r=g(e.series[t],a);l[n]=r.rSquared,s[n]=r.auc,u[n]=r.interceptX,c[n]=r.interceptY,f[n]=r.slope,h[n]=r.top,d[n]=r.bottom,n++}return{rSquared:l.some((e=>null==e))?void 0:r.Stats.fromValues(l)[p[t]],auc:s.some((e=>null==e))?void 0:r.Stats.fromValues(s)[p[t]],interceptX:u.some((e=>null==e))?void 0:r.Stats.fromValues(u)[p[t]],interceptY:c.some((e=>null==e))?void 0:r.Stats.fromValues(c)[p[t]],slope:f.some((e=>null==e))?void 0:r.Stats.fromValues(f)[p[t]],top:h.some((e=>null==e))?void 0:r.Stats.fromValues(h)[p[t]],bottom:d.some((e=>null==e))?void 0:r.Stats.fromValues(d)[p[t]]}}function _(e){for(let t=0;t<e.length;t++){const n=e.get(t);if(""===n)continue;const r=(0,u.K)(n);e.set(t,JSON.stringify(r))}e.setTag(c.h.TAG_FIT_CHART_FORMAT,"")}function T(e,t,n,r){var o;void 0===e.cell.column.temp[`${h}-custom-title`]&&function(e){var t,n;const r=e.columns.bySemTypeAll(c.h.FIT_SEM_TYPE);for(let e=0;e<r.length;e++){a.xs.map((t=>{r[e].temp[`${h}-custom-${t.name}`]=!1})),a.IL.map((t=>{r[e].temp[`${d}-custom-${t.name}`]=!1})),r[e].getTag(c.h.TAG_FIT_CHART_FORMAT)===c.h.TAG_FIT_CHART_FORMAT_3DX&&_(r[e]);for(let o=0;o<r[e].length;o++){if(""===r[e].get(o))continue;const i=null!==(n=JSON.parse(null!==(t=r[e].get(o))&&void 0!==t?t:"{}"))&&void 0!==n?n:{};a.xs.map((t=>{i.chartOptions&&void 0!==i.chartOptions[t.name]&&(r[e].temp[`${h}-custom-${t.name}`]=!0)})),a.IL.map((t=>{if(i.series)for(const n of i.series)void 0!==n[t.name]&&(r[e].temp[`${d}-custom-${t.name}`]=!0)}))}}}(e.cell.dataFrame);const i=t.property.name,s=r===m.DATAFRAME?(0,l.Ig)(e.cell.dataFrame):(0,l.bc)(e.cell.column);if(n===h?s.chartOptions[i]=t.value:n===d&&(s.seriesOptions[i]=t.value),r===m.CELL){const r=e.cell.value;if(""===r)return;const i=null!==(o=JSON.parse(null!=r?r:"{}"))&&void 0!==o?o:{};!function(e,t,n){const r=t.property.name;if(n===h){if(void 0===e.chartOptions)return;e.chartOptions[r]=t.value}else if(n===d){if(void 0===e.series)return;for(let n=0;n<e.series.length;n++)e.series[n][r]=t.value}}(i,t,n),e.cell.value=JSON.stringify(i)}else{let t;r===m.DATAFRAME?(e.cell.dataFrame.tags[c.h.TAG_FIT]=JSON.stringify(s),t=e.cell.dataFrame.columns.bySemTypeAll(c.h.FIT_SEM_TYPE)):(e.cell.column.tags[c.h.TAG_FIT]=JSON.stringify(s),t=[e.cell.column]);for(let e=0;e<t.length;e++){if(r===m.DATAFRAME){const r=(0,l.bc)(t[e]);n===h?delete r.chartOptions[i]:delete r.seriesOptions[i],t[e].tags[c.h.TAG_FIT]=JSON.stringify(r)}!1!==t[e].temp[`${n}-custom-${i}`]&&(t[e].init((r=>{var o,a;const l=t[e].get(r);if(""===l)return l;const s=null!==(a=JSON.parse(null!==(o=t[e].get(r))&&void 0!==o?o:"{}"))&&void 0!==a?a:{};if(n===h){if(void 0===s.chartOptions)return l;if(void 0===s.chartOptions[i])return l;delete s.chartOptions[i]}else{if(void 0===s.series)return l;let e=!1;for(const t of s.series)void 0!==t[i]&&(delete t[i],e=!0);if(s.seriesOptions&&delete s.seriesOptions[i],!e)return l}return JSON.stringify(s)})),t[e].temp[`${n}-custom-${i}`]=!1)}}e.grid.invalidate()}class w extends r.ObjectHandler{get type(){return"GridCell"}isApplicable(e){return e instanceof r.GridCell&&e.cellType===c.h.FIT_CELL_TYPE}renderProperties(e,t=null){var n,u,c,m,p,_,w,E,I,y,x;const A=o.accordion("Curves property panel"),C=r.Property.js("level",r.TYPE.STRING,{description:"Controls the level at which properties will be switched",defaultValue:"Column",choices:["Dataframe","Column","Cell"],nullable:!1}),N=o.input.forProperty(C);o.tooltip.bind(N.captionLabel,"Controls the level at which properties will be switched");const O=(0,l.j$)(e),S=(0,l.bc)(e.cell.column),L=(0,l.Ig)(e.cell.dataFrame),P={onValueChanged:t=>T(e,t,d,N.value)},b={onValueChanged:t=>T(e,t,h,N.value)};(0,l.Yc)(null===(n=L.seriesOptions)||void 0===n?void 0:n.pointColor)||(0,l.Yc)(null===(u=S.seriesOptions)||void 0===u?void 0:u.pointColor)||(O.seriesOptions?(0,l.Yc)(O.seriesOptions.pointColor)||(O.seriesOptions.pointColor=r.Color.toHtml(r.Color.getCategoricalColor(0))):(0,l.Yc)(O.series?O.series[0].pointColor:"")||(O.series[0].pointColor=r.Color.toHtml(r.Color.getCategoricalColor(0)))),(0,l.Yc)(null===(c=L.seriesOptions)||void 0===c?void 0:c.fitLineColor)||(0,l.Yc)(null===(m=S.seriesOptions)||void 0===m?void 0:m.fitLineColor)||(O.seriesOptions?(0,l.Yc)(O.seriesOptions.fitLineColor)||(O.seriesOptions.fitLineColor=r.Color.toHtml(r.Color.getCategoricalColor(0))):(0,l.Yc)(O.series?O.series[0].fitLineColor:"")||(O.series[0].fitLineColor=r.Color.toHtml(r.Color.getCategoricalColor(0)))),(0,l.Yc)(null===(p=L.seriesOptions)||void 0===p?void 0:p.outlierColor)||(0,l.Yc)(null===(_=S.seriesOptions)||void 0===_?void 0:_.outlierColor)||(O.seriesOptions?(0,l.Yc)(O.seriesOptions.outlierColor)||(O.seriesOptions.outlierColor=r.Color.toHtml(r.Color.red)):(0,l.Yc)(O.series?O.series[0].outlierColor:"")||(O.series[0].outlierColor=r.Color.toHtml(r.Color.red))),(0,l.g2)(a.IL,S.seriesOptions,O.seriesOptions?O.seriesOptions:O.series&&null!==(w=O.series[0])&&void 0!==w?w:{}),(0,l.g2)(a.IL,L.seriesOptions,O.seriesOptions?O.seriesOptions:O.series&&null!==(E=O.series[0])&&void 0!==E?E:{}),(0,l.g2)(a.xs,S.chartOptions,O.chartOptions?O.chartOptions:{}),(0,l.g2)(a.xs,L.chartOptions,O.chartOptions?O.chartOptions:{}),(null===(I=O.chartOptions)||void 0===I?void 0:I.allowXZeroes)&&(null===(y=O.chartOptions)||void 0===y?void 0:y.logX)&&(null===(x=O.series)||void 0===x?void 0:x.some((e=>e.points.some((e=>0===e.x)))))&&(0,l.B3)(O);const R=o.form([N]),X=a.IL.map((e=>o.input.forProperty(e,O.seriesOptions?O.seriesOptions:O.series[0],P)));o.forms.addGroup(R,"Series options",X),o.forms.addGroup(R,"Chart options",a.xs.map((e=>o.input.forProperty(e,O.chartOptions,b)))),A.addPane("Options",(()=>R));const M=r.Property.js("series",r.TYPE.STRING,{description:"Controls whether to show series statistics or aggregated statistics",defaultValue:"All",choices:["all","aggregated"],nullable:!1}),F=o.input.forProperty(M,null,{onValueChanged(e){A.getPane("Fit").root.lastElementChild.replaceChildren(Y())}}),G=r.Property.js("aggregation type",r.TYPE.STRING,{description:"Controls which aggregation to use on the series statistics",defaultValue:"med",choices:Object.values(r.STATS),nullable:!1}),D=o.input.forProperty(G,null,{onValueChanged(e){A.getPane("Fit").root.lastElementChild.replaceChildren(Y())}});function Y(){var t,n,l;const s=o.divV("aggregated"===F.stringValue?[F.root,D.root]:[F.root]),u=(0,i.s$)(O);if(u.x<=0&&O.chartOptions&&(O.chartOptions.logX=!1),u.y<=0&&O.chartOptions&&(O.chartOptions.logY=!1),"all"===F.stringValue){const i={logX:null===(t=O.chartOptions)||void 0===t?void 0:t.logX,logY:null===(n=O.chartOptions)||void 0===n?void 0:n.logY};for(let t=0;t<O.series.length;t++){const n=O.series[t],u=g(n,i),c=n.fitLineColor&&r.Color.fromHtml(n.fitLineColor)?n.fitLineColor:r.Color.toHtml(r.Color.getCategoricalColor(t));s.appendChild(o.panel([o.h1(null!==(l=n.name)&&void 0!==l?l:"series "+t,{style:{color:c}}),o.input.form(u,a.nK,{onCreated:i=>i.root.appendChild(o.iconFA("plus",(()=>f(this,void 0,void 0,(function*(){const o={df:e.cell.dataFrame,colName:e.gridColumn.name,propName:i.property.name,seriesName:n.name,seriesNumber:t};yield r.Func.find({name:"addStatisticsColumn"})[0].prepare(o).call(void 0,void 0,{processed:!1})}))),`Calculate ${i.property.name} for the whole column`))})]))}}else{const t=v(O,D.stringValue);s.appendChild(o.panel([o.h1(`series ${D.stringValue}`),o.input.form(t,a.nK,{onCreated:t=>t.root.appendChild(o.iconFA("plus",(()=>f(this,void 0,void 0,(function*(){const n={df:e.cell.dataFrame,colName:e.gridColumn.name,propName:t.property.name,aggrType:D.stringValue};yield r.Func.find({name:"addAggrStatisticsColumn"})[0].prepare(n).call(void 0,void 0,{processed:!1})}))),`Calculate ${t.property.name} ${D.stringValue} for the whole column`))})]))}return s}return A.addPane("Fit",(()=>Y())),A.addPane("Chart",(()=>s.D.fromGridCell(e).root)),A.root}}},283:(e,t,n)=>{"use strict";n.d(t,{K:()=>u});var r=n(82),o=n(71);const i={x:"xAxis",y:"yAxis"},a={min:"min",max:"max"};function l(e){var t,n,i;const a=null===(n=null===(t=e.getElementsByTagName("params")[0])||void 0===t?void 0:t.childNodes[0].nodeValue)||void 0===n?void 0:n.split(",").map(Number);let l=null===(i=e.getElementsByTagName("function")[0])||void 0===i?void 0:i.getAttribute("type");l=l&&"sigif"!==l?l:o.G7;const s=e.getElementsByTagName("settings")[0].getAttribute("markerColor"),u=e.getElementsByTagName("settings")[0].getAttribute("color"),c=!!e.getElementsByTagName("settings")[0].getAttribute("drawLine"),f={name:e.getAttribute("name"),fitFunction:l,markerType:r.MARKER_TYPE.CIRCLE,pointColor:s,fitLineColor:u,showFitLine:c,showPoints:"points",showCurveConfidenceInterval:!1,clickToToggle:!1};return a&&(f.parameters=[a[2],a[1],a[0],a[3]]),f}function s(e){const t=function(e){var t,n,r;const o=null===(t=e.getElementsByTagName("x")[0].childNodes[0].nodeValue)||void 0===t?void 0:t.split(","),i=null===(n=e.getElementsByTagName("y")[0].childNodes[0].nodeValue)||void 0===n?void 0:n.split(","),a=null===(r=e.getElementsByTagName("mask")[0].childNodes[0].nodeValue)||void 0===r?void 0:r.split(""),l=[];for(let e=0;e<o.length;e++)l[e]={x:+o[e],y:+i[e],outlier:!Boolean(a[e])};return l}(e),n=l(e),r={points:t};return Object.assign(r,n),r}function u(e){const t=(new DOMParser).parseFromString(e,"text/xml"),n=t.getElementsByTagName("grid")[0],r=(u=t.getElementsByTagName("settings")[0],{minX:+(o=n).getElementsByTagName(i.x)[0].getAttribute(a.min),minY:+o.getElementsByTagName(i.y)[0].getAttribute(a.min),maxX:+o.getElementsByTagName(i.x)[0].getAttribute(a.max),maxY:+o.getElementsByTagName(i.y)[0].getAttribute(a.max),xAxisName:u.getAttribute("xLabel"),yAxisName:u.getAttribute("yLabel"),logX:!!u.getAttribute("logX")});var o,u;const c=t.getElementsByTagName("seriesCollection")[0],f=l(c.getElementsByTagName("series")[0]),h=function(e){const t=[],n=e.getElementsByTagName("series").length;for(let r=0;r<n;r++){const n=e.getElementsByTagName("series")[r];t[r]=s(n)}return t}(c);return{chartOptions:r,seriesOptions:f,series:h}}},755:(e,t,n)=>{"use strict";n.d(t,{lR:()=>B,j$:()=>X,bc:()=>F,Ig:()=>M,Yc:()=>D,LX:()=>b,g2:()=>P,wU:()=>R,B3:()=>Y});var r=n(82),o=n(328),i=n(389),a=n(71),l=n(293),s=n(999),u=n(283),c=n(326),f=n(48),h=n(95),d=n(368);const m=window,p=new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:2});class g{static getUniqueName(e,t,n){return m.grok_Utils_GetUniqueName(e,t,null==n?void 0:n.auto,null==n?void 0:n.idx,null==n?void 0:n.render,null==n?void 0:n.choices)}static isEmpty(e){return null==e||""==e}static formatNumber(e){return p.format(e)}}function v(e,t){const n=e.pointColor&&r.Color.fromHtml(e.pointColor)?e.pointColor:r.Color.toHtml(r.Color.getCategoricalColor(t)),o=e.outlierColor&&r.Color.fromHtml(e.outlierColor)?e.outlierColor:r.Color.toHtml(r.Color.red),i=e.fitLineColor&&r.Color.fromHtml(e.fitLineColor)?e.fitLineColor:r.Color.toHtml(r.Color.getCategoricalColor(t));e.pointColor=n,e.outlierColor=o,e.fitLineColor=i}function _(e,t,n){var r;if(null!==(r=t.connectDots)&&void 0!==r&&r){e.strokeStyle=t.pointColor,e.lineWidth=2*n.ratio,e.beginPath();for(let r=0;r<t.points.length;r++){const o=t.points[r].x,i=t.points[r].y,a=n.viewport.xToScreen(o),l=n.viewport.yToScreen(i);0===r?e.moveTo(a,l):e.lineTo(a,l)}e.stroke()}}function T(e,t,n){var o;(null===(o=t.showPoints)||void 0===o||o)&&(e.strokeStyle=t.pointColor,t.connectDots&&""!==t.showPoints||"points"===t.showPoints?function(e,t,n){for(let o=0;o<t.points.length;o++){const i=t.points[o],a=t.connectDots?t.pointColor:i.outlier?i.outlierColor&&r.Color.fromHtml(i.outlierColor)?i.outlierColor:t.outlierColor:i.color&&r.Color.fromHtml(i.color)?i.color:t.pointColor,l=i.marker?i.marker:t.markerType,s=i.outlierMarker?i.outlierMarker:t.outlierMarkerType,u=t.connectDots?h.h.POINT_PX_SIZE*n.ratio:i.outlier?h.h.OUTLIER_PX_SIZE*n.ratio:i.size?i.size:h.h.POINT_PX_SIZE*n.ratio;r.Paint.marker(e,t.connectDots?l:i.outlier?s:l,n.viewport.xToScreen(i.x),n.viewport.yToScreen(i.y),a,u),i.stdev&&!i.outlier&&(e.strokeStyle=a,e.beginPath(),e.moveTo(n.viewport.xToScreen(i.x),n.viewport.yToScreen(i.y+i.stdev)),e.lineTo(n.viewport.xToScreen(i.x),n.viewport.yToScreen(i.y-i.stdev)),e.stroke())}}(e,t,n):["candlesticks","both"].includes(t.showPoints)&&function(e,t,n){for(let o=0,i=null;o<t.points.length;o++){const a=t.points[o];if(a.outlier)continue;const l=o+1<t.points.length&&t.points[o+1].x===a.x;if(!i&&l)i=o;else if(null!==i&&!l){const l=[];for(let e=i,n=0;e<=o;e++,n++)l[n]=t.points[e].y;const s=(0,d.k)(l);if(e.beginPath(),w(e,{viewport:n.viewport,ratio:n.ratio,x:a.x,boxPlotStats:s,color:t.pointColor}),e.stroke(),"both"===t.showPoints)for(let o=0;o<l.length;o++)(l[o]<s.lowerAdjacentValue||l[o]>s.upperAdjacentValue)&&r.Paint.marker(e,r.MARKER_TYPE.OUTLIER,n.viewport.xToScreen(a.x),n.viewport.yToScreen(l[o]),t.pointColor,h.h.CANDLESTICK_OUTLIER_PX_SIZE*n.ratio);i=null}}}(e,t,n))}function w(e,t){E(e,t.x,t.boxPlotStats.lowerAdjacentValue,t.viewport),e.moveTo(t.viewport.xToScreen(t.x),t.viewport.yToScreen(t.boxPlotStats.lowerAdjacentValue)),e.lineTo(t.viewport.xToScreen(t.x),t.viewport.yToScreen(t.boxPlotStats.upperAdjacentValue)),E(e,t.x,t.boxPlotStats.upperAdjacentValue,t.viewport),r.Paint.marker(e,r.MARKER_TYPE.CIRCLE,t.viewport.xToScreen(t.x),t.viewport.yToScreen(t.boxPlotStats.q2),t.color,h.h.CANDLESTICK_MEDIAN_PX_SIZE*t.ratio)}function E(e,t,n,r){e.moveTo(r.xToScreen(t)-h.h.CANDLESTICK_BORDER_PX_SIZE/2,r.yToScreen(n)),e.lineTo(r.xToScreen(t)+h.h.CANDLESTICK_BORDER_PX_SIZE/2,r.yToScreen(n))}function I(e,t,n){var r;if(null===(r=t.showFitLine)||void 0===r||r){e.save(),e.strokeStyle=t.fitLineColor,e.lineWidth=2*n.ratio,e.beginPath(),t.lineStyle&&e.setLineDash(h.h.LINE_STYLES[t.lineStyle]);const r=n.showAxes?n.showAxesLabels?h.h.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:h.h.AXES_LEFT_PX_MARGIN:0,o=n.showAxes?h.h.AXES_RIGHT_PX_MARGIN:0;for(let t=r;t<=n.screenBounds.width-o;t++){const o=n.screenBounds.x+t,i=n.logOptions.logX?Math.log10(n.viewport.xToWorld(o)):n.viewport.xToWorld(o),a=n.logOptions.logY?n.viewport.yToScreen(Math.pow(10,n.curveFunc(i))):n.viewport.yToScreen(n.curveFunc(i));t===r?e.moveTo(o,a):e.lineTo(o,a)}e.stroke(),e.restore()}}function y(e,t,n){var r,o,i,a;if((null===(r=t.showFitLine)||void 0===r||r)&&null!==(o=t.showCurveConfidenceInterval)&&void 0!==o&&o){e.strokeStyle=null!==(i=t.confidenceIntervalColor)&&void 0!==i?i:h.h.CONFIDENCE_INTERVAL_STROKE_COLOR,e.fillStyle=null!==(a=t.confidenceIntervalColor)&&void 0!==a?a:h.h.CONFIDENCE_INTERVAL_FILL_COLOR;const r=(0,s.fY)(t,n.fitFunc,n.userParamsFlag,n.logOptions);x(e,{viewport:n.viewport,logOptions:n.logOptions,showAxes:n.showAxes,showAxesLabels:n.showAxesLabels,screenBounds:n.screenBounds,confidenceIntervals:r,confidenceType:h.h.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP}),x(e,{viewport:n.viewport,logOptions:n.logOptions,showAxes:n.showAxes,showAxesLabels:n.showAxesLabels,screenBounds:n.screenBounds,confidenceIntervals:r,confidenceType:h.h.CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM}),function(e,t){e.beginPath();const n=t.showAxes?t.showAxesLabels?h.h.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:h.h.AXES_LEFT_PX_MARGIN:0,r=t.showAxes?h.h.AXES_RIGHT_PX_MARGIN:0;for(let o=n;o<=t.screenBounds.width-r;o++){const r=t.screenBounds.x+o,i=t.logOptions.logX?Math.log10(t.viewport.xToWorld(r)):t.viewport.xToWorld(r),a=t.logOptions.logY?t.viewport.yToScreen(Math.pow(10,t.confidenceIntervals.confidenceTop(i))):t.viewport.yToScreen(t.confidenceIntervals.confidenceTop(i));o===n?e.moveTo(r,a):e.lineTo(r,a)}for(let o=t.screenBounds.width-r;o>=n;o--){const n=t.screenBounds.x+o,r=t.logOptions.logX?Math.log10(t.viewport.xToWorld(n)):t.viewport.xToWorld(n),i=t.logOptions.logY?t.viewport.yToScreen(Math.pow(10,t.confidenceIntervals.confidenceBottom(r))):t.viewport.yToScreen(t.confidenceIntervals.confidenceBottom(r));e.lineTo(n,i)}e.closePath(),e.fill()}(e,{viewport:n.viewport,logOptions:n.logOptions,showAxes:n.showAxes,showAxesLabels:n.showAxesLabels,screenBounds:n.screenBounds,confidenceIntervals:r})}}function x(e,t){e.beginPath();const n=t.showAxes?t.showAxesLabels?h.h.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:h.h.AXES_LEFT_PX_MARGIN:0,r=t.showAxes?h.h.AXES_RIGHT_PX_MARGIN:0,o=t.confidenceType===h.h.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP?t.confidenceIntervals.confidenceTop:t.confidenceIntervals.confidenceBottom;for(let i=n;i<=t.screenBounds.width-r;i++){const r=t.screenBounds.x+i,a=t.logOptions.logX?Math.log10(t.viewport.xToWorld(r)):t.viewport.xToWorld(r),l=t.logOptions.logY?t.viewport.yToScreen(Math.pow(10,o(a))):t.viewport.yToScreen(o(a));i===n?e.moveTo(r,l):e.lineTo(r,l)}e.stroke()}function A(e,t,n){var r;if((null===(r=t.showFitLine)||void 0===r||r)&&t.droplines&&n.showDroplines){e.save(),e.strokeStyle="blue",e.lineWidth=n.ratio,e.beginPath(),e.setLineDash([5,5]);for(let r=0;r<t.droplines.length;r++)"IC50"===t.droplines[r]&&C(e,{viewport:n.viewport,xValue:t.parameters[2],dataBounds:n.dataBounds,curveFunc:n.curveFunc,logOptions:n.logOptions});e.stroke(),e.restore()}}function C(e,t){t.logOptions.logX&&(t.xValue=Math.pow(10,t.xValue));const n=t.logOptions.logX?Math.log10(t.xValue):t.xValue,r=t.logOptions.logY?Math.pow(10,t.curveFunc(n)):t.curveFunc(n);e.moveTo(t.viewport.xToScreen(t.dataBounds.minX),t.viewport.yToScreen(r)),e.lineTo(t.viewport.xToScreen(t.xValue),t.viewport.yToScreen(r)),e.lineTo(t.viewport.xToScreen(t.xValue),t.viewport.yToScreen(t.dataBounds.minY))}function N(e,t,n){var r;if((null===(r=t.showFitLine)||void 0===r||r)&&n.statistics){const r=(0,s.VA)(t,n.fitFunc,n.logOptions);for(let o=0;o<n.statistics.length;o++){const i=n.statistics[o],l=a.nK.find((e=>e.name===i));if(l){const i=g.formatNumber(l.get(r));e.fillStyle=t.fitLineColor,e.textAlign="left",e.fillText(l.name+": "+i,n.dataBox.x+5,n.dataBox.y+20+20*o)}}}}function O(e,t,n){e.beginPath(),e.fillStyle="black";const r=e.measureText(t).width;e.fillText(t,n.dataBox.maxX-r,n.dataBox.y+h.h.LEGEND_TOP_PX_MARGIN+(n.columnIdx*h.h.LEGEND_RECORD_PX_HEIGHT+h.h.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend))}function S(e,t,n){e.beginPath(),e.strokeStyle=t.fitLineColor,e.lineWidth=2*n.ratio;const o=e.measureText(t.name).width;e.moveTo(n.dataBox.maxX-o-h.h.LEGEND_RECORD_LINE_PX_WIDTH-h.h.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,n.dataBox.y+h.h.LEGEND_TOP_PX_MARGIN-h.h.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN+(n.showColumnLabel?h.h.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+h.h.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend),e.lineTo(n.dataBox.maxX-o-h.h.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,n.dataBox.y+h.h.LEGEND_TOP_PX_MARGIN-h.h.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN+(n.showColumnLabel?h.h.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+h.h.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend);const i=t.markerType?t.markerType:r.MARKER_TYPE.CIRCLE;r.Paint.marker(e,i,n.dataBox.maxX-o-h.h.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN-h.h.LEGEND_RECORD_LINE_PX_WIDTH/2,n.dataBox.y+h.h.LEGEND_TOP_PX_MARGIN-h.h.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN+(n.showColumnLabel?h.h.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+h.h.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend,t.pointColor,h.h.POINT_PX_SIZE*n.ratio),e.fillStyle=t.fitLineColor,e.fillText(t.name,n.dataBox.maxX-o,n.dataBox.y+h.h.LEGEND_TOP_PX_MARGIN+(n.showColumnLabel?h.h.LEGEND_RECORD_PX_HEIGHT*(n.columnIdx+1):0)+h.h.LEGEND_RECORD_PX_HEIGHT*n.drawnCurvesInLegend),e.stroke()}function L(e,t){var n;r.Paint.marker(e,r.MARKER_TYPE.OUTLIER,t.midX,t.midY,r.Color.red,(n=.8*Math.min(t.width,t.height),Math.min(Math.max(n,0),30)))}function P(e,t,n){if(t&&n)for(const r of e)!(r.name in n)&&r.name in t&&(n[r.name]=t[r.name])}function b(e){if(0===e.length)return{};let t,n,r,o=Number.MAX_VALUE,i=Number.MAX_VALUE,a=Number.MIN_VALUE,l=Number.MIN_VALUE,s=!1,u=!1,c=!1;for(const f of e)null!==f.minX&&void 0!==f.minX&&(o=Math.min(o,f.minX)),null!==f.minY&&void 0!==f.minY&&(i=Math.min(i,f.minY)),null!==f.maxX&&void 0!==f.maxX&&(a=Math.max(a,f.maxX)),null!==f.maxY&&void 0!==f.maxY&&(l=Math.max(l,f.maxY)),null!==f.title&&void 0!==f.title&&(null!=r||(r=f.title)),null!==f.xAxisName&&void 0!==f.xAxisName&&(null!=t||(t=f.xAxisName)),null!==f.yAxisName&&void 0!==f.yAxisName&&(null!=n||(n=f.yAxisName)),null!==f.logX&&void 0!==f.logX&&f.logX&&(s=!0),null!==f.logY&&void 0!==f.logY&&f.logY&&(u=!0),null!==f.allowXZeroes&&void 0!==f.allowXZeroes&&f.allowXZeroes&&(c=!0);return{minX:o===Number.MAX_VALUE?void 0:o,minY:i===Number.MAX_VALUE?void 0:i,maxX:a===Number.MIN_VALUE?void 0:a,maxY:l===Number.MIN_VALUE?void 0:l,title:r,xAxisName:t,yAxisName:n,logX:s,logY:u,allowXZeroes:c}}function R(e){if(0===e.length)return null;const t={points:[],name:e[0].name,fitFunction:e[0].fitFunction,markerType:e[0].markerType,lineStyle:e[0].lineStyle,pointColor:e[0].pointColor,fitLineColor:e[0].fitLineColor,confidenceIntervalColor:e[0].confidenceIntervalColor,outlierColor:e[0].outlierColor,connectDots:e[0].connectDots,showFitLine:e[0].showFitLine,showPoints:e[0].showPoints,showCurveConfidenceInterval:e[0].showCurveConfidenceInterval,errorModel:e[0].errorModel,clickToToggle:e[0].clickToToggle,labels:e[0].labels,droplines:e[0].droplines,columnName:e[0].columnName};for(const n of e)t.points=[...t.points,...n.points];return t}function X(e){var t,n,o,i,l;let c=e.cell.value;c.includes("|")&&(c=c.replaceAll("|",""));const f=(null===(n=null===(t=e.cell)||void 0===t?void 0:t.column)||void 0===n?void 0:n.type)===r.TYPE.STRING?e.cell.column.getTag(h.h.TAG_FIT_CHART_FORMAT)===h.h.TAG_FIT_CHART_FORMAT_3DX?(0,u.K)(c):null!==(o=JSON.parse(null!=c?c:"{}"))&&void 0!==o?o:{}:(0,s.Kh)(),d=e.cell.column?F(e.cell.column):{},m=e.cell.column?M(e.cell.dataFrame):{};null!==(i=f.series)&&void 0!==i||(f.series=[]),null!==(l=f.chartOptions)&&void 0!==l||(f.chartOptions=d.chartOptions),P(a.xs,d.chartOptions,f.chartOptions),P(a.xs,m.chartOptions,f.chartOptions);for(const e of f.series)P(a.IL,f.seriesOptions,e),P(a.IL,d.seriesOptions,e),P(a.IL,m.seriesOptions,e);return f}function M(e){var t,n,r;return JSON.parse(null!==(t=(n=e.tags)[r=h.h.TAG_FIT])&&void 0!==t?t:n[r]=JSON.stringify((0,s.Kh)()))}function F(e){var t,n,r;return JSON.parse(null!==(t=(n=e.tags)[r=h.h.TAG_FIT])&&void 0!==t?t:n[r]=JSON.stringify((0,s.Kh)()))}function G(e,t,n){if(e.width<h.h.MIN_AXES_CELL_PX_WIDTH||e.height<h.h.MIN_AXES_CELL_PX_HEIGHT)return[e,void 0,void 0];const r=t?h.h.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS:h.h.AXES_LEFT_PX_MARGIN,o=t?h.h.AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS:h.h.AXES_BOTTOM_PX_MARGIN,i=n?h.h.AXES_TOP_PX_MARGIN_WITH_TITLE:h.h.AXES_TOP_PX_MARGIN;return[e.cutLeft(r).cutBottom(o).cutTop(i).cutRight(h.h.AXES_RIGHT_PX_MARGIN),e.getBottom(o).getTop(i).cutLeft(r).cutRight(h.h.AXES_RIGHT_PX_MARGIN),e.getLeft(r).getRight(h.h.AXES_RIGHT_PX_MARGIN).cutBottom(o).cutTop(i)]}function D(e){return null!=e&&""!==e&&void 0!==r.Color.fromHtml(e)}function Y(e){var t;for(let n=0;n<(null===(t=e.series)||void 0===t?void 0:t.length);n++){const t=e.series[n];if(t.points.every((e=>0!==e.x)))continue;let r=Number.MAX_VALUE,o=0,i=0;const a=[];for(let e=0;e<t.points.length;e++)t.points[e].x<r&&0!==t.points[e].x&&(r=t.points[e].x),t.points[e].x>o&&0!==t.points[e].x&&(o=t.points[e].x),a.includes(t.points[e].x)||(a[a.length]=t.points[e].x,i++);const l=Math.pow(10,Math.log10(r)-(Math.log10(o)-Math.log10(r)/(i-1)));for(let e=0;e<t.points.length;e++)0===t.points[e].x&&(t.points[e].x=l)}}let B=class extends r.GridCellRenderer{get name(){return h.h.FIT_CELL_TYPE}get cellType(){return h.h.FIT_CELL_TYPE}getDefaultSize(e){return{width:h.h.CELL_DEFAULT_WIDTH,height:h.h.CELL_DEFAULT_HEIGHT}}onClick(e,t){var n,r,a,c,d,m,p;if(!e.cell.value)return;const g=e.cell.column.getTag(h.h.TAG_FIT_CHART_FORMAT)===h.h.TAG_FIT_CHART_FORMAT_3DX?(0,u.K)(e.cell.value):X(e);for(const[e,t]of Object.entries(h.h.CONDITION_MAP))if(t(g.series))return void(o.shell.o=i.divText(e,{style:{color:"red"}}));o.shell.o=e;const v=e.bounds.inflate(h.h.INFLATE_SIZE,h.h.INFLATE_SIZE),_=G(v,this.areAxesLabelsShown(v,g),this.isTitleShown(v,g))[0],T=(0,s.s$)(g),w=new l.L(T,_,null!==(r=null===(n=g.chartOptions)||void 0===n?void 0:n.logX)&&void 0!==r&&r,null!==(c=null===(a=g.chartOptions)||void 0===a?void 0:a.logY)&&void 0!==c&&c);for(let n=0;n<(null===(d=g.series)||void 0===d?void 0:d.length);n++)if(!(g.series[n].connectDots||!g.series[n].clickToToggle||"points"!==g.series[n].showPoints||v.width<h.h.MIN_AXES_CELL_PX_WIDTH||v.height<h.h.MIN_AXES_CELL_PX_HEIGHT))for(let r=0;r<g.series[n].points.length;r++){const o=g.series[n].points[r];if(this.hitTest(t,o,w)){o.outlier=!o.outlier;const t=e.grid.dataFrame.columns.byTags({".sourceColumn":e.cell.column.name});if(t)for(const r of t){const t={logX:null===(m=g.chartOptions)||void 0===m?void 0:m.logX,logY:null===(p=g.chartOptions)||void 0===p?void 0:p.logY},o=null!==r.tags[".seriesAggregation"]?(0,f.JR)(g,r.tags[".seriesAggregation"]):r.tags[".seriesNumber"]===n?(0,f.VK)(g.series[n],t):null;null!==o&&r.set(e.cell.rowIndex,o[r.tags[".statistics"]])}if(e.cell.column.getTag(h.h.TAG_FIT_CHART_FORMAT)!==h.h.TAG_FIT_CHART_FORMAT_3DX){const t=JSON.parse(e.cell.value);t.series[n].points[r].outlier=o.outlier,e.cell.value=JSON.stringify(t)}return}}}onDoubleClick(e,t){if(!e.cell.value)return;const n=c.D.fromGridCell(e),r=i.dialog({title:"Edit chart"}).add(n.root).show({resizable:!0}).root.getElementsByClassName("d4-dialog-contents dlg-edit-chart")[0].firstChild;n.canvas.width=r.clientWidth,n.canvas.height=r.clientHeight,n.render(),r.style.width="100%",r.style.height="100%",i.tools.handleResize(r,((e,t)=>{n.canvas.width=e,n.canvas.height=t,n.render()}))}areAxesShown(e){return e.width>=h.h.MIN_AXES_CELL_PX_WIDTH&&e.height>=h.h.MIN_AXES_CELL_PX_HEIGHT}areAxesLabelsShown(e,t){var n;return e.width>=h.h.MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH&&e.height>=h.h.MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT&&!!(null===(n=t.chartOptions)||void 0===n?void 0:n.xAxisName)&&!!t.chartOptions.yAxisName}isTitleShown(e,t){var n;return e.width>=h.h.MIN_TITLE_PX_WIDTH&&e.height>=h.h.MIN_TITLE_PX_HEIGHT&&!!(null===(n=t.chartOptions)||void 0===n?void 0:n.title)}isLegendShown(e){return e.width>=h.h.MIN_LEGEND_PX_WIDTH&&e.height>=h.h.MIN_LEGEND_PX_HEIGHT}areDroplinesShown(e){return e.width>=h.h.MIN_DROPLINES_VISIBILITY_PX_WIDTH&&e.height>=h.h.MIN_DROPLINES_VISIBILITY_PX_HEIGHT}renderCurves(e,t,n){var r,o,i,a,u,c,f,d,m,p,g,w,E,x,C;e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),(null===(r=n.chartOptions)||void 0===r?void 0:r.allowXZeroes)&&(null===(o=n.chartOptions)||void 0===o?void 0:o.logX)&&(null===(i=n.series)||void 0===i?void 0:i.some((e=>e.points.some((e=>0===e.x)))))&&Y(n);const[L,P,b]=G(t,this.areAxesLabelsShown(t,n),this.isTitleShown(t,n)),R=(0,s.s$)(n);(R.x<0&&n.chartOptions||0===R.x&&n.chartOptions&&!n.chartOptions.allowXZeroes)&&(n.chartOptions.logX=!1),R.y<=0&&n.chartOptions&&(n.chartOptions.logY=!1);const X=new l.L(R,L,null!==(u=null===(a=n.chartOptions)||void 0===a?void 0:a.logX)&&void 0!==u&&u,null!==(f=null===(c=n.chartOptions)||void 0===c?void 0:c.logY)&&void 0!==f&&f),M=Math.min(L.width,L.height),F=M>100?1:.2+M/100*.8,D={logX:null===(d=n.chartOptions)||void 0===d?void 0:d.logX,logY:null===(m=n.chartOptions)||void 0===m?void 0:m.logY};e.save(),e.font='11px Roboto, "Roboto Local"',X.drawCoordinateGrid(e,P,b),e.restore();for(let r=0;r<(null===(p=n.series)||void 0===p?void 0:p.length);r++){const o=n.series[r];if(o.points.some((e=>void 0===e.x||void 0===e.y)))continue;(t.width<h.h.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH||t.height<h.h.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT)&&(o.showPoints="",n.chartOptions&&(n.chartOptions.showStatistics=[])),o.points.sort(((e,t)=>e.x-t.x));let i=!0;const a=(0,s.zB)(o);let l=null;if(!o.connectDots||o.showFitLine)if(o.parameters)(null===(g=n.chartOptions)||void 0===g?void 0:g.logX)&&o.parameters[2]>0&&(o.parameters[2]=Math.log10(o.parameters[2])),l=(0,s._T)(o,a);else{const e=(0,s.nT)(o,a,D);l=e.fittedCurve;const t=[...e.parameters];o.parameters=t,i=!1}v(o,r),_(e,o,{viewport:X,ratio:F}),T(e,o,{viewport:X,ratio:F}),I(e,o,{viewport:X,ratio:F,logOptions:D,showAxes:this.areAxesShown(t),showAxesLabels:this.areAxesLabelsShown(t,n),screenBounds:t,curveFunc:l}),y(e,o,{viewport:X,logOptions:D,showAxes:this.areAxesShown(t),showAxesLabels:this.areAxesLabelsShown(t,n),screenBounds:t,fitFunc:a,userParamsFlag:i}),o.parameters&&A(e,o,{viewport:X,ratio:F,showDroplines:this.areDroplinesShown(t),xValue:o.parameters[2],dataBounds:R,curveFunc:l,logOptions:D}),N(e,o,{statistics:null===(w=n.chartOptions)||void 0===w?void 0:w.showStatistics,fitFunc:a,logOptions:D,dataBox:L})}!function(e,t){t.showTitle&&(e.font='12px Roboto, "Roboto Local"',e.textAlign="center",e.fillStyle="black",e.fillText(t.title,t.dataBox.midX-5,t.screenBounds.y+15))}(e,{showTitle:this.isTitleShown(t,n),title:null===(E=n.chartOptions)||void 0===E?void 0:E.title,dataBox:L,screenBounds:t}),function(e,t){if(t.showAxesLabels){e.font='11px Roboto, "Roboto Local"',e.textAlign="center",e.fillStyle="black",e.fillText(t.xAxisName,t.dataBox.midX-5,t.screenBounds.maxY-h.h.X_AXIS_LABEL_BOTTOM_PX_MARGIN),e.translate(t.screenBounds.x,t.screenBounds.y),e.rotate(-Math.PI/2);const n=t.showTitle?h.h.AXES_TOP_PX_MARGIN_WITH_TITLE:h.h.AXES_TOP_PX_MARGIN;e.fillText(t.yAxisName,-(t.dataBox.height/2+n+15),15),e.restore()}}(e,{showTitle:this.isTitleShown(t,n),dataBox:L,screenBounds:t,showAxesLabels:this.areAxesLabelsShown(t,n),xAxisName:null===(x=n.chartOptions)||void 0===x?void 0:x.xAxisName,yAxisName:null===(C=n.chartOptions)||void 0===C?void 0:C.yAxisName}),function(e,t,n){var r,o,i,a;if(n.showLegend){e.font='11px Roboto, "Roboto Local"';const l=[...new Set(null===(r=t.series)||void 0===r?void 0:r.map((e=>e.columnName)))].filter((e=>null!=e));let s=0;for(let r=0;r<l.length;r++){const u=l[r];(null===(o=t.chartOptions)||void 0===o?void 0:o.showColumnLabel)&&O(e,u,{dataBox:n.dataBox,columnIdx:r,drawnCurvesInLegend:s});const c=null===(i=t.series)||void 0===i?void 0:i.filter((e=>e.columnName===u));for(let o=0;o<(null==c?void 0:c.length);o++){const i=c[o];""!==i.name&&null!==i.name&&void 0!==i.name&&(S(e,i,{dataBox:n.dataBox,ratio:n.ratio,columnIdx:r,drawnCurvesInLegend:s,showColumnLabel:null===(a=t.chartOptions)||void 0===a?void 0:a.showColumnLabel}),s++)}}e.restore()}}(e,n,{showLegend:this.isLegendShown(t),dataBox:L,ratio:F}),e.restore()}render(e,t,n,o,i,a,l){var s,c,f;if(!a.cell.value)return;if(o<h.h.MIN_CELL_RENDERER_PX_WIDTH||i<h.h.MIN_CELL_RENDERER_PX_HEIGHT)return;const d=(null===(s=a.cell.column)||void 0===s?void 0:s.getTag(h.h.TAG_FIT_CHART_FORMAT))===h.h.TAG_FIT_CHART_FORMAT_3DX?(0,u.K)(a.cell.value):X(a),m=new r.Rect(t,n,o,i).inflate(h.h.INFLATE_SIZE,h.h.INFLATE_SIZE);for(const[t,n]of Object.entries(h.h.CONDITION_MAP))if(n(d.series))return void L(e,m);null===(c=d.series)||void 0===c||c.forEach((e=>e.columnName=a.cell.column.name)),(null===(f=d.chartOptions)||void 0===f?void 0:f.mergeSeries)&&(d.series=[R(d.series)]),this.renderCurves(e,m,d)}hitTest(e,t,n){const o=n.xToScreen(t.x),i=n.yToScreen(t.y),a=(t.outlier?h.h.OUTLIER_PX_SIZE:h.h.POINT_PX_SIZE)/2+h.h.OUTLIER_HITBOX_RADIUS;return new r.Rect(o-a,i-a,2*a,2*a).containsPoint(new r.Point(e.offsetX,e.offsetY))}onMouseMove(e,t){var n,o,a,c,f;if(!e.cell.value)return;const d=e.bounds.inflate(h.h.INFLATE_SIZE,h.h.INFLATE_SIZE);if(d.width<h.h.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH||d.height<h.h.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT){const n=i.canvas(300,200);this.render(n.getContext("2d"),0,0,300,200,e,null);const r=i.divV([n]);i.tooltip.show(r,t.x,t.y)}const m=e.cell.column.getTag(h.h.TAG_FIT_CHART_FORMAT)===h.h.TAG_FIT_CHART_FORMAT_3DX?(0,u.K)(e.cell.value):X(e);if(d.width>=h.h.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH&&d.height>=h.h.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT){const e=G(d,this.areAxesLabelsShown(d,m),this.isTitleShown(d,m))[0],u=(0,s.s$)(m),p=new l.L(u,e,null!==(o=null===(n=m.chartOptions)||void 0===n?void 0:n.logX)&&void 0!==o&&o,null!==(c=null===(a=m.chartOptions)||void 0===a?void 0:a.logY)&&void 0!==c&&c);for(let e=0;e<(null===(f=m.series)||void 0===f?void 0:f.length);e++)if("points"===m.series[e].showPoints)for(let n=0;n<m.series[e].points.length;n++){const o=m.series[e].points[n];if(this.hitTest(t,o,p))return i.tooltip.show(i.divV([i.divText(`x: ${r.format(o.x,"#0.000")}`),i.divText(`y: ${r.format(o.y,"#0.000")}`)]),t.x+16,t.y+16),void(!m.series[e].connectDots&&m.series[e].clickToToggle&&d.width>=h.h.MIN_AXES_CELL_PX_WIDTH&&d.height>=h.h.MIN_AXES_CELL_PX_HEIGHT&&(document.body.style.cursor="pointer"))}i.tooltip.hide()}document.body.style.cursor="default"}};B=function(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}([o.decorators.cellRenderer({name:"Fit",cellType:"fit",virtual:!0})],B)},860:(e,t,n)=>{"use strict";n.r(t),n.d(t,{_FitChartCellRenderer:()=>m,_MultiCurveViewer:()=>p,_initCurves:()=>C,_package:()=>w,addAggrStatisticsColumn:()=>O,addStatisticsColumn:()=>N,curveFitDemo:()=>A});var r=n(755),o=n(82),i=n(389),a=n(328),l=n(326),s=n(71);const u=rxjs.operators,c=rxjs;var f,h=n(95);let d=f=class extends l.D{constructor(){super(new r.lR),this.curvesColumnNames=[],this.showSelectedRowsCurves=!1,this.showCurrentRowCurve=!0,this.showMouseOverRowCurve=!0,this.mergeColumnSeries=!1,this.rows=[],this.data=new s.oH,this.curvesColumnNames=this.addProperty("curvesColumnNames",o.TYPE.COLUMN_LIST,[],{semType:h.h.FIT_SEM_TYPE}),this.showSelectedRowsCurves=this.bool("showSelectedRowsCurves",!1,{description:"Adds curves from the selected rows"}),this.showCurrentRowCurve=this.bool("showCurrentRowCurve",!0),this.showMouseOverRowCurve=this.bool("showMouseOverRowCurve",!0),this.mergeColumnSeries=this.bool("mergeColumnSeries",!1);for(const e of s.xs)this.addProperty("mergeSeries"===e.name?"mergeCellSeries":e.name,e.propertyType,e.defaultValue,e.options)}static fromChartData(e){let t=new f;return t.data=e,t.render(),t}applyViewerProperties(){(0,r.g2)(s.xs,this,this.data.chartOptions)}mergeViewerChartOptions(){for(const e of s.xs)if(["logX","logY","allowXZeroes","mergeCellSeries","showColumnLabel"].includes("mergeSeries"===e.name?"mergeCellSeries":e.name)?void 0!==this["mergeSeries"===e.name?"mergeCellSeries":e.name]:void 0!==this.props.get(e.name)&&this.props.get(e.name)!==e.defaultValue){if(["title","xAxisName","yAxisName"].includes(e.name)&&""===this.props.get(e.name))continue;["logX","logY","allowXZeroes","mergeCellSeries","showColumnLabel"].includes("mergeSeries"===e.name?"mergeCellSeries":e.name)?this.data.chartOptions[e.name]=this[e.name]:this.data.chartOptions[e.name]=this.props.get(e.name)}}createChartData(){var e,t,n,i,a,l;if(0===(null===(e=this.curvesColumnNames)||void 0===e?void 0:e.length))return;this.rows.length=0;let u=-1;this.showCurrentRowCurve&&-1!==this.dataFrame.currentRowIdx&&this.rows.push(this.dataFrame.currentRowIdx),this.showMouseOverRowCurve&&-1!==this.dataFrame.mouseOverRowIdx&&this.rows.push(this.dataFrame.mouseOverRowIdx),this.showSelectedRowsCurves&&-1!==this.dataFrame.mouseOverRowIdx&&(u=this.rows.length,this.rows.push(...this.dataFrame.selection.getSelectedIndexes())),this.data=new s.oH;const c=null===(t=this.tableView)||void 0===t?void 0:t.grid,f=this.props.get("mergeCellSeries"),h=[];for(const e of this.curvesColumnNames){const t=[];for(const o of new Set(this.rows)){const i=c.cell(e,c.tableRowToGrid(o));if(""===i.cell.value)continue;const a=(0,r.j$)(i);null===(n=a.series)||void 0===n||n.forEach((e=>e.columnName=i.cell.column.name));const l=a.chartOptions;if(null!=l&&(h[h.length]=l),f){const e=(0,r.wU)(a.series);void 0!==(null==l?void 0:l.title)&&""!==(null==l?void 0:l.title)&&(e.name=null==l?void 0:l.title),a.series=[e]}t.push(...a.series)}this.mergeColumnSeries?null===(i=this.data.series)||void 0===i||i.push((0,r.wU)(t)):null===(a=this.data.series)||void 0===a||a.push(...t)}this.data.chartOptions=(0,r.LX)(h),this.mergeViewerChartOptions(),null===(l=this.data.series)||void 0===l||l.forEach(((e,t)=>{var n,r,i,a,l;if(e.pointColor=o.Color.toHtml(o.Color.getCategoricalColor((null===(n=this.data.series)||void 0===n?void 0:n.length)>20?0:t)),e.fitLineColor=o.Color.toHtml(o.Color.getCategoricalColor((null===(r=this.data.series)||void 0===r?void 0:r.length)>20?0:t)),e.showCurveConfidenceInterval=!1,e.droplines=[],(null===(i=this.data.series)||void 0===i?void 0:i.length)>20&&(e.showPoints="",e.lineStyle="solid"),(null===(a=this.data.series)||void 0===a?void 0:a.length)>10&&(null===(l=this.data.series)||void 0===l?void 0:l.length)<100&&t>=u){const t=o.Color.fromHtml(e.fitLineColor);e.fitLineColor=`rgba(${o.Color.r(t)}, ${o.Color.g(t)}, ${o.Color.b(t)}, 0.2)`}}))}onPropertyChanged(e){var t,n,r,o,i;"curvesColumnNames"===(null==e?void 0:e.name)&&(this.props.set("showColumnLabel",(null===(t=this.curvesColumnNames)||void 0===t?void 0:t.length)>1),this.showColumnLabel=(null===(n=this.curvesColumnNames)||void 0===n?void 0:n.length)>1),["logX","logY","allowXZeroes","mergeCellSeries","showColumnLabel"].includes("mergeSeries"===(null==e?void 0:e.name)?"mergeCellSeries":null!==(r=null==e?void 0:e.name)&&void 0!==r?r:"")&&(this["mergeSeries"===(null==e?void 0:e.name)?"mergeCellSeries":null!==(o=null==e?void 0:e.name)&&void 0!==o?o:""]=this[null!==(i=null==e?void 0:e.name)&&void 0!==i?i:""]),this.applyViewerProperties(),this.createChartData(),this.render()}onTableAttached(){var e;const t=null===(e=this.tableView)||void 0===e?void 0:e.grid,n=this.dataFrame.columns.bySemType(h.h.FIT_SEM_TYPE);null!==n&&(this.curvesColumnNames=[n.name]),(0,c.merge)(this.dataFrame.onCurrentCellChanged,t.onCellMouseEnter,this.dataFrame.onSelectionChanged).pipe((0,u.debounce)((e=>(0,c.interval)(50)))).subscribe((e=>{this.createChartData(),this.render()}))}_showErrorMessage(e){this.root.appendChild(i.divText(e,"d4-viewer-error"))}_removeErrorMessage(){const e=this.root.getElementsByClassName("d4-viewer-error")[0];e&&this.root.removeChild(e)}render(){var e;const t=this.canvas.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),0!==(null===(e=this.curvesColumnNames)||void 0===e?void 0:e.length)?(this._removeErrorMessage(),this.renderer.renderCurves(t,new o.Rect(0,0,this.canvas.width,this.canvas.height).inflate(h.h.INFLATE_SIZE,h.h.INFLATE_SIZE),this.data)):this._showErrorMessage("The MultiCurveViewer viewer requires a minimum of 1 curves column.")}};function m(){return new r.lR}function p(){return new d}d=f=function(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}([a.decorators.viewer({name:"MultiCurveViewer",description:"A viewer that superimposes multiple in-cell curves on one chart",icon:"icons/multi-curve-viewer.png"}),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[])],d);var g=n(48),v=n(471),_=n(283),T=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((r=r.apply(e,t||[])).next())}))};const w=new o.Package,E=".sourceColumn",I=".seriesNumber",y=".seriesAggregation",x=".statistics";function A(){return T(this,void 0,void 0,(function*(){yield(0,v.Z1)()}))}function C(){o.ObjectHandler.register(new g.e4)}function N(e,t,n,i,a){var l;const s=o.Viewer.grid(e),u=s.col(t),c=o.Column.float(`${t}_${i}_${n}`,null===(l=u.column)||void 0===l?void 0:l.length);c.tags[E]=t,c.tags[I]=a,c.tags[x]=n,c.init((e=>{var i,l,u,c,f;const d=o.GridCell.fromColumnRow(s,t,s.tableRowToGrid(e));if(""===d.cell.value)return null;const m=d.cell.column.getTag(h.h.TAG_FIT_CHART_FORMAT)===h.h.TAG_FIT_CHART_FORMAT_3DX?(0,_.K)(d.cell.value):(0,r.j$)(d);if(void 0===m.series[a]||m.series[a].points.every((e=>e.outlier)))return null;(null===(i=m.chartOptions)||void 0===i?void 0:i.allowXZeroes)&&(null===(l=m.chartOptions)||void 0===l?void 0:l.logX)&&(null===(u=m.series)||void 0===u?void 0:u.some((e=>e.points.some((e=>0===e.x)))))&&(0,r.B3)(m);const p={logX:null===(c=m.chartOptions)||void 0===c?void 0:c.logX,logY:null===(f=m.chartOptions)||void 0===f?void 0:f.logY};return(0,g.VK)(m.series[a],p)[n]})),e.columns.insert(c,u.idx)}function O(e,t,n,i){var a;const l=o.Viewer.grid(e),s=l.col(t),u=o.Column.float(`${t}_${i}_${n}`,null===(a=s.column)||void 0===a?void 0:a.length);u.tags[E]=t,u.tags[y]=i,u.tags[x]=n,u.init((e=>{var a,s,u,c;const f=o.GridCell.fromColumnRow(l,t,l.tableRowToGrid(e));if(""===f.cell.value)return null;const d=f.cell.column.getTag(h.h.TAG_FIT_CHART_FORMAT)===h.h.TAG_FIT_CHART_FORMAT_3DX?(0,_.K)(f.cell.value):(0,r.j$)(f);return(null===(a=d.series)||void 0===a?void 0:a.every((e=>e.points.every((e=>e.outlier)))))?null:((null===(s=d.chartOptions)||void 0===s?void 0:s.allowXZeroes)&&(null===(u=d.chartOptions)||void 0===u?void 0:u.logX)&&(null===(c=d.series)||void 0===c?void 0:c.some((e=>e.points.some((e=>0===e.x)))))&&(0,r.B3)(d),(0,g.JR)(d,i)[n])})),e.columns.insert(u,s.idx)}},82:e=>{"use strict";e.exports=DG},328:e=>{"use strict";e.exports=grok},389:e=>{"use strict";e.exports=ui},991:e=>{"use strict";e.exports=wu}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r=n(860);curves=r})();
|
|
2
2
|
//# sourceMappingURL=package.js.map
|