class Table { HashMap dataSet = new HashMap(); Table() { } void loadDataFromFile(String fileName) { //read all the lines String[] lines = loadStrings(fileName); //loop through chunks for(int i = 0; i < lines.length; i++) { //break each chunk into an array of its words String[] tokens = split(lines[i],TAB); //add the data (key->value) into the hashmap dataSet.put(tokens[0], int(tokens[1])); } } void printData() { Iterator i = dataSet.entrySet().iterator(); // Get an iterator while (i.hasNext()) { Map.Entry e = (Map.Entry)i.next(); // print(e.getKey() + " is "); // println(e.getValue()); } } //the meat and potatoes of this code :) void drawData() { int index = 0; Iterator i = dataSet.entrySet().iterator(); // Get an iterator for crawling through the data textFont(boldFont); while (i.hasNext()) { //extract the key val pairs one by one Map.Entry element = (Map.Entry)i.next(); Integer v = (Integer)element.getValue(); String k = (String)element.getKey(); float x = locationTable.getFloat(k, 1); //get x-coordinate of states float y = locationTable.getFloat(k, 2); //get y-coordinate of states float rad = map(v, 0, 600, 1.5, 35); //maps the value on a scale between 1.5 and 35 fill(200,100,0,30); //colors the ellipses stroke(0,40); //strokes translate(0,0); //places data according to locations, adds the ellipse ellipseMode(RADIUS); ellipse(x,y,rad,rad); index++; //counter //adds capability to reveal data of closest point on mouseover closestDist = 18; float d = dist(x, y, mouseX, mouseY); if ((d < rad ) && (d < closestDist)) { closestDist = d; closestText = nf(v,0,0) + " (" + k + ")"; closestTextX = x; closestTextY = y-rad-4; } if (closestDist != 18) { smooth(); fill(random(60,255),random(60,255),random(60,255),30); //flickers colors randomly stroke(0,250); //adds stroke ellipseMode(RADIUS); //draws this new ellipse on top of old one ellipse(x,y,rad,rad); fill(0); //text textAlign(CENTER); text(closestText, closestTextX, closestTextY); } //an extra, makes the cursor go away when clicking if(mousePressed == true) { noCursor(); } else { cursor(CROSS); } } } int readDataValUsingKey(String key) { if(dataSet.containsKey(key)) { //key exists KeyValPair kv = (KeyValPair)dataSet.get(key); return kv.val; } else { //key not found return 99999; } } }