String version="1.08"; PFont ariel; TMNode rootnode; TMNode currentviewnode; TMNode highlightedNode; Rectangle splashrect; boolean fading; boolean resetTitles=true; boolean yankeemode=false; boolean bRedraw=true; float totalERA=0.0; float maxERA=0; float minERA=0; float avgERA=0; int pitchers=0; float totalOPS=0; float maxOPS=0; float minOPS=1; float avgOPS=0; int batters=0; PImage oldImg; PImage currentImg; int fadelevel; int[] fadearray1; int[] fadearray2; int[] fadearray3; int[] fadearray4; int currentColorScheme=0; TreeMap tm; int level; int viewlevel; int origdimension=570; int height=origdimension; int width=origdimension; int titlemode=0; boolean startup=true; int lastX=0; int lastY=0; void setup() { size(570, 570); background(color(255,255,255)); ariel = loadFont("Arial-BoldMT-12.vlw"); //ariel = loadFont("ArialMT-10.vlw"); fadearray1=getFadeArray(40); fadearray2=getFadeArray(80); fadearray3=getFadeArray(120); fadearray4=getFadeArray(160); rootnode=new TMNode(1); rootnode.setArea(new Rectangle(0,0,width,height)); level=3; viewlevel=0; fading=false; fadelevel=0; //load salary data String league=""; String div=""; String team=""; TMNode leagueNode=null; TMNode divNode=null; TMNode teamNode=null; String lines[] = loadStrings("salaries.csv"); for(int i=0;i0){ if(position.equals("P")){ pitchers++; totalERA+=projection; if(projection>maxERA)maxERA=projection; if(projectionmaxOPS)maxOPS=projection; if(projection3){ fading=false; } } } int[] getFadeArray(int fadelevel){ int[] fadearray=new int[width*height]; for(int ix=0;ix<(width*height);ix++){ fadearray[ix]=fadelevel; } return fadearray; } void drawtooltip(){ if(lastX==mouseX && lastY==mouseY && mouseX>0 && mouseY>0){ TMNode child=currentviewnode.getChildNode(mouseX,mouseY,level+1); if(child.area.height<55){ int tipwidth=100; int tipheight=100; int tipdistance=10; int tipcornerX=0; int tipcornerY=0; int childX=0; int childY=0; String tip=""; tip=currentviewnode.getTooltip(mouseX,mouseY,level+1); color ttcolor=currentviewnode.getTooltipColor(mouseX,mouseY,level+1); fill(ttcolor); childX=child.area.x+(child.area.width/2); int baseX=childX+tipdistance; tipcornerX=childX+tipdistance; childY=child.area.y+(child.area.height/2); int baseY=childY+tipdistance; tipcornerY=childY+tipdistance; if(baseX>width-tipwidth-tipdistance){ baseX=childX-tipwidth-tipdistance; tipcornerX=childX-tipdistance; } if(childY>height-tipheight-tipdistance){ baseY=childY-tipheight-tipdistance; tipcornerY=childY-tipdistance; } rect(baseX,baseY,tipwidth,tipheight); color textcolor=#000000; if(brightness(ttcolor)<180)textcolor=#ffffff; fill(textcolor); stroke(textcolor); line(tipcornerX,tipcornerY,childX,childY); textFont(ariel,16); textAlign(CENTER); text(tip,baseX+(tipwidth/2),baseY+(tipheight/3)); } } lastX=mouseX; lastY=mouseY; } void mousePressed() { if(currentColorScheme!=0 && currentColorScheme<8){ currentColorScheme=11; recolor(); } if(startup){ if(splashrect.contains(mouseX,mouseY)){ link("http://mlbcontracts.blogspot.com/","_new"); return; }else{ startup=false; return; } } if(mouseButton == LEFT){ zoomIn(); } else{ zoomOut(); } drawNewMap(); } void zoomIn(){ if(viewlevel<3){ currentviewnode=currentviewnode.getChildNode(mouseX,mouseY); currentviewnode.setArea(new Rectangle(0,0,width,height)); viewlevel++; } if(level>0)level--; resetTitles=true; titlemode=0; } void zoomOut(){ if(viewlevel>0)viewlevel--; if(currentviewnode==rootnode){ if(level>0)level--; }else{ if(viewlevel+level<3)level++; currentviewnode=currentviewnode.getParent(); currentviewnode.setArea(new Rectangle(0,0,width,height)); currentviewnode.clearHighlights(titlemode==0); } resetTitles=true; titlemode=0; } void detailIn(){ if(viewlevel+level<3)level++; fading=true; fadelevel=0; oldImg=currentImg; } void detailOut(){ if(level>0)level--; fading=true; fadelevel=0; oldImg=currentImg; } void keyPressed(){ if(startup){ startup=false; drawNewMap(); return; } if(key=='h'){ startup=true; return; } height=origdimension; width=origdimension; currentviewnode.setArea(new Rectangle(0,0,width,height)); if(key=='k'){ if(titlemode<2){ titlemode+=1; }else{ titlemode=0; } if(titlemode==0){ rootnode.setHighlightTitles(); }else{ rootnode.clearHighlights(false); } } if(key=='l' || keyCode==RIGHT){ detailIn(); } if(key=='j' || keyCode==LEFT){ detailOut(); } if(key=='i' || keyCode==UP)zoomIn(); if(key==',' || keyCode==DOWN)zoomOut(); if(key=='y'){ yankeemode=!yankeemode; if(yankeemode && viewlevel==3){ float yankeemultiplier=sqrt(currentviewnode.getSize()/getYankeePayroll()); currentviewnode.setArea(new Rectangle(0,0,int(width*yankeemultiplier),int(height*yankeemultiplier))); } } else{ yankeemode=false; } if(key=='a'){ if(currentColorScheme!=8){ currentColorScheme=8; rootnode.setFillingScheme(currentColorScheme); }else{ currentColorScheme=0; rootnode.setFillingScheme(currentColorScheme); } } if(key=='z'){ if(currentColorScheme!=9){ currentColorScheme=9; rootnode.setFillingScheme(currentColorScheme); }else{ currentColorScheme=0; rootnode.setFillingScheme(currentColorScheme); } } if(key=='p'||key==' '){ recolor(); } else{ if(currentColorScheme!=0 && currentColorScheme<8){ currentColorScheme=10; recolor(); } } drawNewMap(); } void drawYankeeBackground(){ fill(color(19,36,72)); rect(0,0,origdimension,origdimension); textFont(ariel,100); textAlign(CENTER); fill(color(255,255,255)); text("YANKEES\nYANKEES\nYANKEES",origdimension/2,origdimension/3); } float getYankeePayroll(){ TMNode yankeeNode=rootnode.find("Yankees"); if(yankeeNode!=null){ return yankeeNode.getSize(); } return 100.0; } void recolor(){ if(currentColorScheme<7){ currentColorScheme++; } else{ currentColorScheme=0; } rootnode.setFillingScheme(currentColorScheme); } void splashscreen(){ fill(#ffffff); rect(0,0,width,height); fill(#0000ff); textAlign(CENTER); textFont(ariel,40); text("Baseball Salary Navigator",width/2,100); textFont(ariel,30); text("A treemap-based comparison",width/2,150); int instructions=200; fill(#000000); textFont(ariel,20); textAlign(CENTER); text("ZOOM +",100,instructions); text("DETAIL - DETAIL +",100,instructions+25); text("ZOOM -",100,instructions+50); text("[ i ]",275,instructions); text("[ j ] [ l ]",275,instructions+25); text("[ , ]",275,instructions+50); text("[UP]",475,instructions); text("[LEFT] [RIGHT]",475,instructions+25); text("[DOWN]",475,instructions+50); text("ZOOM +/-: Mouse L/R Buttons",width/2,instructions+100); text("Position Highlight Toggle: [p] [space]",width/2,instructions+150); text("Title Detail Toggle: [k]",width/2,instructions+175); text("Team-to-Yankees Comparison: [y]",width/2,instructions+200); text("Shade By Age: [a]",width/2,instructions+225); fill(#ff0000); text("New! Shade By ZIPS 2006 Projection (ERA/OPS): [z]",width/2,instructions+250); fill(#000000); text("This Screen: [h]",width/2,instructions+275); textFont(ariel,10); fill(#ff0000); int disclaimer=490; text("Based on 2006 base player salaries (in $million)",width/2,disclaimer); text("Salaries are unofficial and may not include buyouts, deferred salary, etc.",width/2,disclaimer+15); text("Salaries may be the responsibility of multiple teams.",width/2,disclaimer+30); text("Salaries may appear to be larger than your lifetime earnings.",width/2,disclaimer+45); textFont(ariel,10); fill(#0000ff); splashrect=new Rectangle(0,disclaimer+55,width,15); text("Thanks to Cot's Baseball Contracts (http://mlbcontracts.blogspot.com/) for much of the data.",width/2,disclaimer+65); text("v."+version,width-20,height-5); } void drawNewMap(){ bRedraw=true; }