// column number in data file static final int ID = 0; static final int REVIEW_SCORE = 1; static final int SCIENCE_GPA = 2; static final int CUM_GPA = 3; static final int INTERVIEW_SCORE = 4; static final int PC_HOURS = 5; static final int APP_STATUS = 6; static final int ELLIPSE_SIZE = 6; HashMap statusColors = new HashMap(); int totalCount; Applicant[] apps; int appCount; FilterButton[] buttons; int buttonCount; // min / max boundary of all points float minPCH, maxPCH; float minGPA, maxGPA; // plot border float plotX1, plotY1; float plotX2, plotY2; PFont plotFont; void setup() { size(1100, 700, P3D); plotX1 = 200; plotX2 = width - 5; plotY1 = 20; plotY2 = height - plotY1 - 100; plotFont = createFont("SansSerif", 13); textFont(plotFont); textMode(SCREEN); smooth(); /* // fill color hashmap statusColors.put("Program", color(161, 218, 180)); statusColors.put("Accept", color(37, 52, 148)); statusColors.put("Waitlist", color(44, 127, 184)); statusColors.put("Interview", color(65, 182, 196)); statusColors.put("Deny", color(228,26,28)); */ // fill color hashmap statusColors.put("Program", color(255, 127, 0)); statusColors.put("Accept", color(0,0,0)); statusColors.put("Waitlist", color(1, 133, 113)); statusColors.put("Interview", color(152, 78, 163)); statusColors.put("Deny", color(228, 26, 28)); createButtons(); readData(); } void draw() { background(235); drawXAxis(); drawYAxis(); for (int i = 0; i < appCount; i++) { apps[i].draw(); } for (int i = 0; i < buttonCount; i++) { buttons[i].draw(); } fill(255); stroke(1); rect(610, 30, 250, 20); fill(0); textAlign(LEFT, CENTER); text("Click box to filter:", 16, 60); text("Science GPA vs. Patient Care Hours", 500, 30); text("Hover mouse for data details:", 20, 650); } void mousePressed() { for (int i = 0; i < buttonCount; i++) { if (buttons[i].clicked()) { buttons[i].filter(); break; } } } void drawXAxis() { stroke(0); strokeWeight(2); fill(0); textSize(13); textAlign(RIGHT, CENTER); line(plotX1 - 5, plotY2 + 5, plotX2, plotY2 + 5); float interval = (maxPCH - minPCH) / 6; for (float tick = minPCH; tick <= maxPCH + interval; tick += interval) { float x = TX(tick); text(floor(tick), x, plotY2 + 20); } } void drawYAxis() { stroke(0); strokeWeight(2); fill(0); textSize(13); line(plotX1 - 5, plotY1 - 5, plotX1 - 5, plotY2 + 5); float interval = (maxGPA - minGPA) / 6; for (float tick = minGPA; tick <= maxGPA + interval; tick += interval) { if (tick == minGPA) { textAlign(RIGHT); } else if (tick == maxGPA) { textAlign(RIGHT, TOP); } else { textAlign(RIGHT, CENTER); } float y = TY(tick); text(nf(tick, 1, 2), plotX1 - 15, y); } } void createButtons() { int count = 0; Iterator i = statusColors.entrySet().iterator(); buttons = new FilterButton[statusColors.size()]; while (i.hasNext()) { Map.Entry me = (Map.Entry)i.next(); buttons[count] = new FilterButton(count, me.getKey().toString()); count++; } buttonCount = count; } void readData() { String[] lines = loadStrings("my_data.tsv"); //read header line parseInfo(lines[0]); apps = new Applicant[totalCount]; for(int i = 1; i < lines.length; i++) { apps[appCount++] = parseApp(lines[i]); } } void parseInfo(String line) { String infoString = line.substring(2); // remove the # String[] infoPieces = split(infoString, ','); totalCount = int(infoPieces[0]); minPCH = float(infoPieces[1]); maxPCH = float(infoPieces[2]); minGPA = float(infoPieces[3]); maxGPA = float(infoPieces[4]); } Applicant parseApp(String line) { String pieces[] = split(line, TAB); int id = int(pieces[ID]); float reviewScore = float(pieces[REVIEW_SCORE]); float scienceGPA = float(pieces[SCIENCE_GPA]); float cumGPA = float(pieces[CUM_GPA]); float interviewScore = float(pieces[INTERVIEW_SCORE]); float pcHours = float(pieces[PC_HOURS]); String appStatus = pieces[APP_STATUS]; return new Applicant(id, reviewScore, scienceGPA, cumGPA, interviewScore, pcHours, appStatus); } float TX(float x) { return map(x, minPCH, maxPCH, plotX1, plotX2); } float TY(float y) { return map(y, maxGPA, minGPA, plotY1, plotY2); }