if(window.PlotJax.PointGraph==null){registerNS("PlotJax.PointGraph");registerNS("PlotJax.LineGraph");registerNS("PlotJax.AreaGraph");PlotJax.PointGraph=function(a,b,c,d){if(arguments.length>0){this.plot=b;this.chartdesc=a;this.shapes=d;this.points=[];this.visible_points=[];this.zooms=[];this.undos=[];this.redos=[];this.balloon=b.getBalloon();this.gesture=b.getGesture();this.xType=b.getXType();this.yType=b.getYType();this.limits=c;this.myid=a.PlotID;this.helper=b.getHelper();this.chartstyles=(a.Style==null)?[]:(a.Style instanceof Array)?a.Style:[a.Style];var i;var e=this.chartstyles;for(i=0;i<e.length;i++){var f=e[i];if(f.Shape==null){f.Shape='circle'}else if(!d.isValidShape(f.Shape,f.Icon)){if(f.Shape=="icon"){alert("Unknown icon "+f.Icon)}else{alert("Unknown shape "+f.Shape)}return null}if(f.Color==null){f.Color="black"}}var g=a.Data;var j,x,y;if((g==null)||(g.length==0)){if((c[1]==null)||(c[0]==null)||(c[3]==null)||(c[2]==null)){alert("No data provided, and incomplete limits specified.");return null}}else{for(i=0;i<g.length;i++){var h=g[i];if(h[0]==null){alert("Missing domain value at element "+i);return null}x=this.xType.normalize(h[0]);if(((c[1]!=null)&&(x>c[1]))||((c[0]!=null)&&(x<c[0]))){continue}for(j=1;j<h.length;j++){if(h[j]==null){continue}y=this.yType.normalize(h[j]);if(((c[3]!=null)&&(y>c[3]))||((c[2]!=null)&&(y<c[2]))){continue}while(this.points.length<j){this.points.push([])}this.points[j-1].push([x,y])}}}for(i=0;i<this.points.length;i++){this.points[i]=this.points[i].sort(this.sortByDomain)}while(this.visible_points.length<this.points.length){this.visible_points.push([])}for(i=0;i<this.points.length;i++){for(j=0;j<this.points[i].length;j++){this.visible_points[i].push(j)}}if(this.gesture!=null){this.gesture.observe(this)}}};PlotJax.PointGraph.prototype={getChartID:function(){return this.myid},getElement:function(a){var b=a[0];var i=a[1];return(b<this.points.length)?[this.xType.display(this.points[b][i][0]),this.yType.display(this.points[b][i][1])]:null},getElements:function(a){return(a!=null)?((a>=this.points.length)?null:this.points[a]):this.points},layout:function(a,b){if((this.helper!=null)&&(this.helper.onlayout!=null)){this.helper.onlayout(this.plot,this)}var c=Number.MAX_VALUE;var d=Number.MIN_VALUE;var e=Number.MAX_VALUE;var f=Number.MIN_VALUE;var i,j,count=0;for(i=0;i<this.visible_points.length;i++){for(j=0;j<this.visible_points[i].length;j++){var g=this.points[i][this.visible_points[i][j]];d=Math.max(d,g[0]);c=Math.min(c,g[0]);f=Math.max(f,g[1]);e=Math.min(e,g[1])}count+=j}b[0]=(b[0]==null)?c:Math.min(c,b[0]);b[1]=(b[1]==null)?d:Math.max(d,b[1]);b[2]=(b[2]==null)?e:Math.min(e,b[2]);b[3]=(b[3]==null)?f:Math.max(f,b[3]);return count},sortVisibles:function(){var a;for(var i=0;(i<this.visible_points.length);i++){if(this.visible_points[i].length!=0){this.visible_points[i]=this.visible_points[i].sort(this.sortByIndex);a++}}return a},redraw:function(a){if((this.helper!=null)&&(this.helper.ondraw!=null)){this.helper.ondraw(this.plot,this)}if(this.sortVisibles()==0){return}var i,j,k,x,y;this.visible_coords=[];var b=this.plot.getLeftMargin();var c=this.plot.getVertEdge();var d,shape,icon;k=0;for(i=0;i<this.visible_points.length;i++){this.visible_coords.push([]);var e=this.chartstyles[k++];if(k==this.chartstyles.length){k=0}for(j=0;j<this.visible_points[i].length;j++){x=this.xType.pt2pxl(this.points[i][this.visible_points[i][j]][0],b);y=c-this.yType.pt2pxl(this.points[i][this.visible_points[i][j]][1],0);this.visible_coords[i].push(this.shapes.draw(x,y,e.Color,e.Shape,e.Icon))}}},sortByDomain:function(a,b){return((a==null)||(b==null))?0:a[0]-b[0]},sortByIndex:function(a,b){return a-b},redo:function(){var a=this.redos.pop();var b=[];var i,j,k;for(i=0;i<this.visible_points.length;i++){for(j=this.visible_points[i].length-1;(i>=0)&&(a.length>0);i--){var c=this.visible_points[i][j];for(k=0;(k<a.length)&&((a[k][0]!=i)||(a[k][1]!=c));k++){}if(k<a.length){this.visible_points[i].splice(j,1);b.push([i,c]);a.splice(k,1)}}}this.undos.push(b)},undo:function(){var a=this.undos.pop();for(var i=0;i<a.length;i++){this.visible_points[a[i][0]].push(a[i][1])}this.redos.push(a)},discardElement:function(a,b){if((a<this.points.length)&&(this.points[a].length<b)){this.points[a][b]=null}return this},getRangeByName:function(a){for(var i=0;(i<this.chartstyle.length);i++){if((this.chartstyle[i].Name!=null)&&(this.chartstyle[i].Name==a)){return i}}return null},getNameByRange:function(a){return(a<this.chartstyle.length)?this.chartstyle[a].Name:null},hideElements:function(a){var b;var c=[];var i,j,k;for(i=0;(a.length>0)&&(i<this.visible_points.length);i++){for(j=this.visible_points[i].length-1;(a.length>0)&&(j>=0);j--){b=this.visible_points[i][j];for(k=0;(k<a.length)&&((i!=a[k])||(b!=a[k+1]));k+=2){}if(k<a.length){this.visible_points[i].splice(j,1);c.push(i,b);a.splice(k,2)}}}if(c.length>0){this.undos.push(c)}return this},keepElements:function(a){var b;var c=[];var i,j,k;for(i=0;(a.length>0)&&(i<this.visible_points.length);i++){for(j=this.visible_points[i].length-1;(a.length>0)&&(j>=0)&&(a.length>0);j--){b=this.visible_points[i][j];for(k=0;(k<a.length)&&((i!=a[k])||(b!=a[k+1]));k+=2){}if(k==a.length){this.visible_points[i].splice(j,1);c.push(i,b)}else{a.splice(k,2)}}while(j>=0){this.undos.push(this.visible_points[i][j]);this.visible_points[i].splice(j,1);j--}}if(c.length>0){this.undos.push(c)}return this},getVisibleElements:function(){var a=[];for(var i=0;i<this.visible_points.length;i++){for(var j=0;j<this.visible_points[i].length;j++){a.push(i,j)}}return a},onclick:function(a,b,c,d){var e=[];var i,j,xdist,ydist;for(i=0;i<this.visible_points.length;i++){var f=this.visible_coords[i];for(j=0;j<this.visible_points[i].length;j++){xdist=(f[j][0]-a);ydist=(f[j][1]-b);if(Math.sqrt((xdist*xdist)+(ydist*ydist))<=f[j][2]){e.push(i,this.visible_points[i][j])}}}if(e.length>0){if(this.balloon!=null){var g=this.helper.getBalloonContent(this.plot,this,e[0]);if(g!=null){this.balloon.openBalloon(c,d,g)}}}return(e.length>0)},onhover:function(x,y){var a=[];var i,j,xdist,ydist;for(i=0;i<this.visible_points.length;i++){var b=this.visible_coords[i];for(j=0;j<this.visible_points[i].length;j++){xdist=(b[j][0]-x);ydist=(b[j][1]-y);if(Math.sqrt((xdist*xdist)+(ydist*ydist))<=b[j][2]){return this.helper.onhover(this.plot,this,[i,j])}}}return null},clear:function(){this.points=null;this.visible_points=null;this.visible_coords=null;this.plot=null;this.helper=null;this.balloon=null;this.gesture=null;this.zooms=null;this.redos=null;this.undos=null},observeZoom:function(a){var b=[];var i,j,k;for(i=0;i<this.visible_points.length;i++){var c=this.visible_coords[i];for(j=0;j<this.visible_points[i].length;j++){for(k=0;k<a.length;k++){if(a[k].contains(c[j][0],c[j][1])){b.push([i,j])}}}}return b},observeFlick:function(a){var b=[];var i,j;for(i=0;i<this.visible_points.length;i++){var c=this.visible_coords[i];for(j=0;j<this.visible_points[i].length;j++){if(a.intersects(c[j][0],c[j][1],3)){b.push([i,j])}}}return b}};PlotJax.LineGraph=function(a,b,c,d){if(arguments.length>0){var i;if(a.Style==null){a.Style=[{"Shape":"dot","LineWidth":1,"Pattern":"solid"}]}else{if(!(a.Style instanceof Array)){a.Style=[a.Style]}for(i=0;i<a.Style.length;i++){if(a.Style[i].Shape==null){a.Style[i].Shape="dot"}if(a.Style[i].LineWidth==null){a.Style[i].LineWidth=1}if(a.Style[i].Pattern==null){a.Style[i].Pattern="solid"}}}PlotJax.LineGraph.baseConstructor.call(this,a,b,c,d);this.canvas=b.getCanvas()}};JSPPTrustee.extend(PlotJax.LineGraph,PlotJax.PointGraph);PlotJax.LineGraph.prototype.redraw=function(a){if((this.helper!=null)&&(this.helper.ondraw!=null)){this.helper.ondraw(this.plot,this)}if(this.sortVisibles()==0){return}this.visible_coords=[];var i,j,k;var b=this.plot.getLeftMargin();var c=this.plot.getVertEdge();k=0;for(i=0;i<this.visible_points.length;i++){this.visible_coords.push([]);var d=this.chartstyles[k++];if(k==this.chartstyles.length){k=0}var e=[];for(j=0;j<this.visible_points[i].length;j++){var f=this.points[i][this.visible_points[i][j]];e.push(this.xType.pt2pxl(f[0],b),c-this.yType.pt2pxl(f[1],0))}this.plot.drawLine(e,d.Color,d.LineWidth,d.Pattern,false);for(j=0;j<e.length;j+=2){this.visible_coords[i].push(this.shapes.draw(e[j],e[j+1],d.Color,d.Shape,d.Icon))}}};PlotJax.AreaGraph=function(a,b,c,d){PlotJax.AreaGraph.baseConstructor.call(this,a,b,c,d)};JSPPTrustee.extend(PlotJax.AreaGraph,PlotJax.LineGraph);PlotJax.AreaGraph.prototype.redraw=function(a){if((this.helper!=null)&&(this.helper.ondraw!=null)){this.helper.ondraw(this.plot,this)}if(this.sortVisibles()==0){return}this.visible_coords=[];var i,j,k;var b=this.plot.getLeftMargin();var c=this.plot.getVertEdge();k=0;for(i=0;i<this.visible_points.length;i++){this.visible_coords.push([]);var d=this.chartstyles[k++];if(k==this.chartstyles.length){k=0}var e=[];for(j=0;j<this.visible_points[i].length;j++){var f=this.points[i][this.visible_points[i][j]];e.push(this.xType.pt2pxl(f[0],b),c-this.yType.pt2pxl(f[1],0))}this.plot.drawPolygon(e,d.Color,d.LineWidth,d.Pattern);for(j=0;j<e.length;j+=2){this.visible_coords[i].push(this.shapes.draw(e[j],e[j+1],d.Color,d.Shape,d.Icon))}}};PlotJax.LineFit=function(a,b,c,d){if(arguments.length>0){var i;if(a.Style==null){a.Style=[{"Shape":"dot","LineWidth":1,"Pattern":"solid"}]}else{if(!(a.Style instanceof Array)){a.Style=[a.Style]}for(i=0;i<a.Style.length;i++){if(a.Style[i].Shape==null){a.Style[i].Shape="dot"}if(a.Style[i].LineWidth==null){a.Style[i].LineWidth=1}if(a.Style[i].Pattern==null){a.Style[i].Pattern="solid"}}}PlotJax.LineFit.baseConstructor.call(this,a,b,c,d);this.canvas=b.getCanvas()}};JSPPTrustee.extend(PlotJax.LineFit,PlotJax.LineGraph);PlotJax.LineFit.prototype.calc=function(){var a=0,ys=0,x2s=0,y2s=0,xys=0;var b=this.chartdesc.Data;for(var i=0;i<b.length;i++){a+=b[i][0];ys+=b[i][1];x2s+=b[i][0]*b[i][0];y2s+=b[i][1]*b[i][1];xys+=b[i][0]*b[i][1]}var c=b.length;this.intercept=(ys*x2s-xys*a)/(c*x2s-a*a);this.slope=(c*xys-a*ys)/(c*x2s-a*a);this.correlation=(c*xys-a*ys)/Math.sqrt((c*x2s-a*a)*(c*y2s-ys*ys));this.correlation=this.correlation*this.correlation}}