function diagnose(a){alert(a)}if(window.PlotJax.BubbleChart==null){registerNS("PlotJax.BubbleChart");registerNS("PlotJax.Bubble");registerNS("PlotJax.RoundBubble");registerNS("PlotJax.SquareBubble");PlotJax.Bubble=function(a,b,c,d,e,f,g){if(arguments.length>0){this.plot=a;this.parent=b;this.myid=c;this.x_value=d[0];this.y_value=d[1];this.size_value=d[2];this.intensity_value=d[3];this.x_normal=d[4];this.y_normal=d[5];this.size_normal=d[6];this.intensity_normal=d[7];this.color="";this.centerx=0;this.centery=0;this.ctx=e;this.balloon=f;this.helper=g}};PlotJax.Bubble.MAX_FACTOR=0.035;PlotJax.Bubble.MIN_DIAM=10;PlotJax.Bubble.SHADOW=4;PlotJax.Bubble.prototype.getBubbleID=function(){return this.myid};PlotJax.Bubble.prototype.getCenterX=function(){return this.centerx};PlotJax.Bubble.prototype.getCenterY=function(){return this.centery};PlotJax.Bubble.prototype.getRadius=function(){return this.radius};PlotJax.Bubble.prototype.getNormalized=function(){return[this.x_normal,this.y_normal,this.size_normal,this.intensity_normal]};PlotJax.Bubble.prototype.getSize=function(){return this.size_normal};PlotJax.Bubble.prototype.getIntensity=function(){return this.intensity_normal};PlotJax.Bubble.prototype.getValues=function(){return[this.x_value,this.y_value,this.size_value,this.intensity_value]};PlotJax.Bubble.prototype.openBalloon=function(x,y){var a=this.helper.getBalloonContent(this.plot,this.parent,this.myid);if(a!=null){this.balloon.openBalloon(x,y,a)}return true};PlotJax.Bubble.prototype.dump=function(){return[this.x_value,this.y_value,this.size_value,this.intensity_value,this.x_normal,this.y_normal,this.size_normal,this.intensity_normal].join(',')};PlotJax.Bubble.prototype.clear=function(){this.plot=null;this.parent=null;this.balloon=null;this.helper=null;this.ctx=null};PlotJax.SquareBubble=function(a,b,c,d,e,f,g){PlotJax.SquareBubble.baseConstructor.call(this,a,b,c,d,e,f,g);this.left=0;this.top=0;this.right=0;this.bottom=0;this.height=0;this.width=0;this.radius=0};JSPPTrustee.extend(PlotJax.SquareBubble,PlotJax.Bubble);PlotJax.SquareBubble.prototype.draw=function(a,b,c,d,e,f,g,h){this.centerx=a.pt2pxl(this.x_normal,g);this.centery=h-b.pt2pxl(this.y_normal,0);this.height=this.width=Math.round(Math.sqrt((this.size_normal*c)+d));this.color=e;this.left=this.centerx-(this.width>>1);this.top=this.centery-(this.height>>1);this.right=this.centerx+(this.width>>1);this.bottom=this.centery+(this.height>>1);this.radius=(this.right-this.left);if(f){this.ctx.fillStyle=PlotJax.SHADOW;this.ctx.beginPath();this.ctx.fillRect(this.left+PlotJax.Bubble.SHADOW,this.top+PlotJax.Bubble.SHADOW,this.width,this.width);this.ctx.closePath()}this.ctx.fillStyle=this.color;this.ctx.fillRect(this.left,this.top,this.width,this.width);this.ctx.strokeStyle="black";this.ctx.linewidth=1;this.ctx.beginPath();this.ctx.strokeRect(this.left,this.top,this.width,this.width);this.ctx.closePath()};PlotJax.SquareBubble.prototype.contains=function(x,y){return((this.left<x)&&(this.right>x)&&(this.top<y)&&(this.bottom>y))};PlotJax.SquareBubble.prototype.getArea=function(){return(this.height*this.width)};PlotJax.RoundBubble=function(a,b,c,d,e,f,g){PlotJax.RoundBubble.baseConstructor.call(this,a,b,c,d,e,f,g);this.radius=0};JSPPTrustee.extend(PlotJax.RoundBubble,PlotJax.Bubble);PlotJax.RoundBubble.prototype.draw=function(a,b,c,d,e,f,g,h){this.centerx=a.pt2pxl(this.x_normal,g);this.centery=h-b.pt2pxl(this.y_normal,0);this.radius=Math.round(Math.sqrt(((this.size_normal*c)+d)/Math.PI));this.color=e;if(f){this.ctx.fillStyle=PlotJax.SHADOW;this.ctx.beginPath();this.ctx.arc(this.centerx+PlotJax.Bubble.SHADOW,this.centery+PlotJax.Bubble.SHADOW,this.radius,0,2*Math.PI,true);this.ctx.closePath();this.ctx.fill()}this.ctx.fillStyle=this.color;this.ctx.beginPath();this.ctx.arc(this.centerx,this.centery,this.radius,0,2*Math.PI,true);this.ctx.closePath();this.ctx.fill();this.ctx.strokeStyle="black";this.ctx.linewidth=1;this.ctx.beginPath();this.ctx.arc(this.centerx,this.centery,this.radius,0,2*Math.PI,true);this.ctx.closePath();this.ctx.stroke()};PlotJax.RoundBubble.prototype.contains=function(x,y){var a=Math.abs(x-this.centerx);var b=Math.abs(y-this.centery);var r=Math.sqrt((a*a)+(b*b));return(r<this.radius)};PlotJax.RoundBubble.prototype.getArea=function(){return Math.PI*this.radius*this.radius};PlotJax.BubbleChart=function(a,b,c,d){this.plot=b;this.chartdesc=a;this.shapes=d;this.bubbles=[];this.visible_bubbles=[];this.zooms=[];this.undos=[];this.redos=[];this.sizeSlope=this.sizeIntercept=null;this.balloon=b.getBalloon();this.gesture=b.getGesture();this.xType=b.getXType();this.yType=b.getYType();this.limits=c;this.myid=a.PlotID;this.bubbleid=0;this.helper=b.getHelper();this.chartstyle=a.Style[0];if(this.chartstyle.Shape==null){this.chartstyle.Shape='circle'}else if((this.chartstyle.Shape!='square')&&(this.chartstyle.Shape!='circle')&&(this.chartstyle.Shape!='round')){alert("Unknown shape "+this.chartstyle.Shape);return null}if(a.Size!=null){this.sizeType=b.getType(a.Size);if(this.sizeType==null){return}if((this.sizeType.Mapping==null)||((this.sizeType.Mapping!='normal')&&(this.sizeType.Mapping!='reverse'))){this.sizeType.Mapping='normal'}}if(a.Intensity!=null){this.intensityType=b.getType(a.Intensity);if(this.intensityType==null){return}if((this.intensityType.Mapping==null)||((this.intensityType.Mapping!='normal')&&(this.intensityType.Mapping!='reverse'))){this.intensityType.Mapping='normal'}}if(!(this.chartstyle.Color instanceof Array)){this.chartstyle.Color=[this.chartstyle.Color]}this.colors=this.chartstyle.Color.slice(0);if(this.colors==null){this.colors=["#D2D2D2","#000000"]}else if(this.colors.length==1){this.colors[1]=this.colors[0]}var i;for(i=0;i<this.colors.length;i++){this.colors[i]=b.parseColor(this.colors[i]);if(this.colors[i]==null){alert("Invalid color specification.");return null}}var e=a.Data;if((e==null)||(e.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{e=a.Data;var f=b.getCanvas();for(i=0;i<e.length;i++){var g=e[i].slice(0);var x=this.xType.normalize(g[0]);var y=this.yType.normalize(g[1]);if(x==null){alert("Missing domain value at element "+i);return null}if(y==null){alert("Missing range value at element "+i);return null}if(((c[1]!=null)&&(x>c[1]))||((c[0]!=null)&&(x<c[0]))||((c[3]!=null)&&(y>c[3]))||((c[2]!=null)&&(y<c[2]))){continue}if(g.length<3){if(this.sizeType!=null){alert("Missing size value at element "+i);return null}g.push(1)}var h=(this.sizeType!=null)?this.sizeType.normalize(g[2]):1;if(h==null){alert("Missing size value at element "+i);return null}if(g.length<4){if(this.intensityType!=null){alert("Missing intensity value at element "+i);return null}g.push(1)}var j=(this.intensityType!=null)?this.intensityType.normalize(g[3]):1;if(j==null){alert("Missing intensity value at element "+i);return null}g.push(x,y,h,j);var k=(this.chartstyle.Shape=='square')?new PlotJax.SquareBubble(this.plot,this,this.bubbleid++,g,f,this.balloon,this.helper):new PlotJax.RoundBubble(this.plot,this,this.bubbleid++,g,f,this.balloon,this.helper);if(k==null){return null}this.bubbles.push(k)}this.visible_bubbles=this.bubbles.slice(0)}if(this.gesture!=null){this.gesture.observe(this)}};PlotJax.BubbleChart.prototype.getChartID=function(){return this.myid};PlotJax.BubbleChart.prototype.addBubble=function(a){var c=this.plot;var b=(this.chartstyle.shape=='square')?new PlotJax.SquareBubble(c,this,this.bubbleid++,a,c.getCanvas(),c.getAreamap(),this.balloon,this.helper):new PlotJax.RoundBubble(c,this,this.bubbleid++,a,c.getCanvas(),c.getAreamap(),this.balloon,this.helper);if(b!=null){this.bubbles.push(b);return true}return false};PlotJax.BubbleChart.prototype.computeIntensity=function(a){var b=a*this.intensityFactor;var c=Math.floor(b);b-=c;var d=[];if(c<this.colors.length-1){}for(var i=0;i<3;i++){d[i]=(c==this.colors.length-1)?this.colors[c][i]:Math.round(this.colors[c][i]+(b*(this.colors[c+1][i]-this.colors[c][i])))}return"rgba("+d.join(",")+", 0.3)"};PlotJax.BubbleChart.prototype.getElement=function(i){var a=this.bubbles[i].getNormalized();return[this.xType.display(a[0]),this.yType.display(a[1]),(this.sizeType!=null)?this.sizeType.display(a[2]):null,(this.intensityType!=null)?this.intensityType.display(a[3]):null]};PlotJax.BubbleChart.prototype.getElements=function(){return this.bubbles};PlotJax.BubbleChart.prototype.layout=function(a,b){if((this.helper!=null)&&(this.helper.onlayout!=null)){this.helper.onlayout(this.plot,this)}this.visible_bubbles=this.visible_bubbles.sort(this.sortBySize).reverse();var c=Number.MAX_VALUE;var d=Number.MIN_VALUE;var e=Number.MAX_VALUE;var f=Number.MIN_VALUE;var i;for(i=0;i<this.visible_bubbles.length;i++){var g=this.visible_bubbles[i].getNormalized();d=Math.max(d,g[0]);c=Math.min(c,g[0]);f=Math.max(f,g[1]);e=Math.min(e,g[1])}b[0]=Math.min(c,b[0]);b[1]=Math.max(d,b[1]);b[2]=Math.min(e,b[2]);b[3]=Math.max(f,b[3]);return i};PlotJax.BubbleChart.prototype.redraw=function(a){if((this.helper!=null)&&(this.helper.ondraw!=null)){this.helper.ondraw(this.plot,this)}if(this.visible_bubbles.length==0){return}var b=PlotJax.Bubble.MAX_FACTOR*(this.plot.getChartWidth()*this.plot.getChartHeight());var c=PlotJax.Bubble.MIN_DIAM*PlotJax.Bubble.MIN_DIAM;var d=Number.MIN_VALUE;var e=Number.MAX_VALUE;var f=Number.MIN_VALUE;var g=Number.MAX_VALUE;var h=0;var j=0;var i;for(i=0;i<this.visible_bubbles.length;i++){h=this.visible_bubbles[i].getSize();j=this.visible_bubbles[i].getIntensity();d=Math.max(d,h);e=Math.min(e,h);if(j!=null){f=Math.max(f,j);g=Math.min(g,j)}}if((this.sizeType!=null)&&(d-e>0.00000001)){this.sizeSlope=(this.chartdesc.Mapping=='normal')?(b-c)/(d-e):(b-c)/(e-d);this.sizeIntercept=(this.chartdesc.Mapping=='normal')?b-(this.sizeSlope*d):b-(this.sizeSlope*e)}else{this.sizeSlope=0;this.sizeIntercept=b>>1}this.intensityFactor=((this.intensityType!=null)&&(f-g>0.00000001))?(this.colors.length-1)/(f-g):0;var k=false;var l=this.plot.getLeftMargin();var m=this.plot.getVertEdge();for(i=0;i<this.visible_bubbles.length;i++){this.visible_bubbles[i].draw(this.xType,this.yType,this.sizeSlope,this.sizeIntercept,(this.intensityFactor!=0)?this.computeIntensity(this.visible_bubbles[i].getIntensity()-g):"rgba("+this.colors[0].join(",")+", 0.3)",k,l,m)}};PlotJax.BubbleChart.prototype.sortBySize=function(a,b){return a.getSize()-b.getSize()};PlotJax.BubbleChart.prototype.redo=function(){var a=this.redos.pop();var b=[];for(var i=this.visible_bubbles.length-1;(i>=0)&&(a.length>0);i--){var c=this.visible_bubbles[i].getBubbleID();for(var j=0;(j<a.length)&&(a[j]!=c);j++){}if(j<a.length){this.visible_bubbles.splice(i,1);b.push(c);a.splice(j,1)}}this.undos.push(b)};PlotJax.BubbleChart.prototype.undo=function(){var a=this.undos.pop();for(var i=0;i<a.length;i++){this.visible_bubbles.push(this.bubbles[a[i]])}this.redos.push(a)};PlotJax.BubbleChart.prototype.discardElement=function(a){if((this.bubbles.length<a)&&(this.bubbles[a]!=null)){this.bubbles[a].clear();this.bubbles[a]=null}return this};PlotJax.BubbleChart.prototype.hideElements=function(a){var b;var c=[];var i,j;for(i=this.visible_bubbles.length-1;i>=0;i--){b=this.visible_bubbles[i].getBubbleID();for(j=0;(j<a.length)&&(b!=a[j]);j++){}if(j<a.length){this.visible_bubbles.splice(i,1);c.push(b);a.splice(j,1)}}if(c.length>0){this.undos.push(c)}return this};PlotJax.BubbleChart.prototype.keepElements=function(a){var b;var c=[];var i,j;for(i=this.visible_bubbles.length-1;(i>=0)&&(a.length>0);i--){b=this.visible_bubbles[i].getBubbleID();for(j=0;(j<a.length)&&(b!=a[j]);j++){}if(j==a.length){this.visible_bubbles.splice(i,1);c.push(b)}else{a.splice(j,1)}}while(i>=0){c.push(this.visible_bubbles[i].getBubbleID());this.visible_bubbles.splice(i,1);i--}if(c.length>0){this.undos.push(c)}return this};PlotJax.BubbleChart.prototype.getVisibleElements=function(){return this.visible_bubbles.slice(0)};PlotJax.BubbleChart.prototype.onclick=function(a,b,c,d){var e=[];for(var i=0;i<this.visible_bubbles.length;i++){if(this.visible_bubbles[i].contains(a,b)){e.push(this.visible_bubbles[i])}}if((this.balloon!=null)&&(e.length>0)){e[0].openBalloon(c,d)}return(e.length>0)};PlotJax.BubbleChart.prototype.onhover=function(x,y){var a=[];for(var i=0;i<this.visible_bubbles.length;i++){if(this.visible_bubbles[i].contains(x,y)){return this.helper.onhover(this.plot,this,this.visible_bubbles[i].getBubbleID())}}return null};PlotJax.BubbleChart.prototype.clear=function(){for(var i=0;i<this.bubbles.length;i++){if(this.bubbles[i]!=null){this.bubbles[i].clear();this.bubbles[i]=null}}this.bubbles=null;this.visible_bubbles=null;this.plot=null;this.helper=null;this.balloon=null;this.gesture=null;this.zooms=null;this.redos=null;this.undos=null;this.chartstyle=null;this.colors=null};PlotJax.BubbleChart.prototype.observeZoom=function(a){var b=[];for(var i=0;i<this.visible_bubbles.length;i++){for(var j=0;j<a.length;j++){if(a[j].contains(this.visible_bubbles[i].getCenterX(),this.visible_bubbles[i].getCenterY())){b.push(this.visible_bubbles[i].getBubbleID())}}}return b};PlotJax.BubbleChart.prototype.observeFlick=function(a){var b=[];for(var i=0;i<this.visible_bubbles.length;i++){if(a.intersects(this.visible_bubbles[i].getCenterX(),this.visible_bubbles[i].getCenterY(),this.visible_bubbles[i].getRadius())){b.push(this.visible_bubbles[i].getBubbleID())}}return b}}