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