let Trend=function(a){return{linear:function(t,e){if(e.data.length<2)return null;let l,n,r,s,i,u;l=n=r=s=i=u=0;for(let a=0;a<e.data.length;a++){let t=e.data[a][0]-e.data[0][0],x=e.data[a][1];null!==t&&null!==x&&(l+=t,n+=x,r+=t*t,s+=x*x,i+=t*x,u++)}let x=u*i-l*n,d=u*r-l*l,o=d?x/d:0,h=(n-o*l)/u;d=Math.sqrt(Math.abs((u*r-l*l)*(u*s-n*n)));let M=d?x/d:1,m=M*M,f=a.extend(!0,{},e,{label:e.label+" trend",lines:{show:!1,fill:!1},points:{show:!0,radius:1},trend:{type:"L"}});f.data=[];let p=null,g=0,y=null,c=t.yaxis.max?t.yaxis.max:t.yaxis.autoscaleMax?t.yaxis.autoscaleMax:Number.MAX_VALUE;for(let a=t.xaxis.min;a<=t.xaxis.max;a+=t.xaxis.step){let t=MMONIT.math.round(h+o*(a-e.data[0][0]),2);t>=0&&t<=c&&(f.data.push([a,t]),(null===p||t<p)&&(p=t),(null===y||t>y)&&(y=t),g+=t)}return f.data.length&&(g/=f.data.length),{series:f,r2:m,min:p,avg:g,max:y}},exponential:function(t,e){if(e.data.length<2)return null;let l,n,r,s,i,u;l=n=r=s=i=u=0;for(let a=0;a<e.data.length;a++)if(e.data[a][0]>0&&e.data[a][1]>0){let t=e.data[a][0]-e.data[0][0],x=Math.log(e.data[a][1]);l+=t,n+=x,r+=t*t,s+=x*x,i+=t*x,u++}let x=u*i-l*n,d=u*r-l*l,o=d?x/d:0,h=(n-o*l)/u;d=Math.sqrt(Math.abs((u*r-l*l)*(u*s-n*n)));let M=d?x/d:1,m=M*M,f=Math.exp(o),p=Math.exp(h),g=a.extend(!0,{},e,{label:e.label+" trend",lines:{show:!1,fill:!1},points:{show:!0,radius:1},trend:{type:"E"}});g.data=[];let y=null,c=0,b=null,w=t.yaxis.max?t.yaxis.max:t.yaxis.autoscaleMax?t.yaxis.autoscaleMax:Number.MAX_VALUE;for(let a=t.xaxis.min;a<=t.xaxis.max;a+=t.xaxis.step){let t=MMONIT.math.round(p*Math.pow(f,a-e.data[0][0]),2);t>=0&&t<=w&&(g.data.push([a,t]),(null===y||t<y)&&(y=t),(null===b||t>b)&&(b=t),c+=t)}return g.data.length&&(c/=g.data.length),{series:g,r2:m,min:y,avg:c,max:b}},auto:function(a,t){let e=[Trend.linear(a,t),Trend.exponential(a,t)];return e.sort((function(a,t){return a&&t?t.r2-a.r2:0})),e[0]}}}(jQuery);