float BOTTOM = 450;
float HEIGHT = 400;
float LEFT = 50;
float WIDTH = 400;


HashMap lookup = new HashMap();
//HashSet whats = new HashSet();
String[] whats = 
{
"movie",
"video",
"tv",
"game",
"book",
"comic"
//,
//"concert"
};
int firstyear = 2000;
int lastyear = 2010;
int yearcount = lastyear-firstyear+1;

int bigmax = 0;
void setup(){
size(500,500);

  
textFont(loadFont("ArialMT-14.vlw"), 14);

background(255);
stroke(0);
strokeWeight(2);
fill(0);

String lines[] = loadStrings("sum.out");

for (int i=0; i < lines.length; i++) {
  String line = lines[i];
  String parts[] = line.split("\t");
  String year = parts[0];
  String what = parts[1];
  String countstring = parts[2];
 // whats.add(what);
  lookup.put(year+what,new Integer(countstring));
  int val = new Integer(countstring).intValue();
  if(val > bigmax) bigmax= val;
}
strokeWeight(1);
stroke(128); fill(128);
line(LEFT,BOTTOM-HEIGHT,LEFT,BOTTOM);
line(LEFT,BOTTOM,LEFT+WIDTH,BOTTOM);
stroke(200); fill(200);
for(float f  = 0; f < bigmax; f += 20){
  float h = BOTTOM - map(f,0,bigmax,0,HEIGHT);
    text((int)f,LEFT-20,h);
    line(LEFT,h,LEFT+WIDTH,h);
}
for(int i = 0; i < yearcount; i+=2){
  float v  =LEFT+(i*WIDTH/yearcount);
  text(firstyear + i,v,BOTTOM+20);
  line(v,BOTTOM,v,BOTTOM-HEIGHT);
}


strokeWeight(2);
for(int i = 0; i < whats.length; i++){
dograph(i,whats[i]);
  
}
}
void draw(){ 
}

void dograph(int c, String what){
  color cr = color(random(100,230),random(100,230),random(100,230));
 fill(cr);
stroke(cr); 
  
  pushMatrix();
   /*
   if(c % 2 == 1){
     translate(250,0);  
   }
   translate(0,20+((c/2) * 150));
   */
   //text(what,0,0);
   int max = 0;
  for(int i = 0; i < yearcount; i++){
    int year = firstyear + i;
    int val = getIntReading(year+what); 
    if(max < val) max = val;    
  }
  float last = 0;
startline();
  for(int i = 0; i < yearcount; i++){
    int year = firstyear + i;
    int val = getIntReading(year+what); 
    float amt = ((float)val )/ ((float)bigmax);
    
    float upness = amt * HEIGHT;
    line(LEFT+i*(WIDTH/yearcount), BOTTOM - upness);
    last = BOTTOM - upness;
  }
text(what,LEFT+WIDTH*(yearcount-1)/yearcount,last);
   popMatrix();
}

Float oldx,oldy;
void startline(){
  oldx = null; oldy = null;
}
void line(float x, float y){
   if(oldx != null){
      line(oldx.floatValue(),oldy.floatValue(),x,y);
   } 
   oldx = new Float(x);
   oldy = new Float(y);
}


int getIntReading(String key){
 Integer foo = (Integer)lookup.get(key); 
    if(foo == null){
      foo = new Integer(0);
    } 
    int val = foo.intValue();
return val;
}