/* Please note that Much of this code was adapted from Ben Fry's * Treemap example in chapter 7 of his book: * Visualizing Data, First Edition by Ben Fry. Copyright 2008 Ben Fry * ISBN: 9780596514556 */ /* ** ======================================================== ** MAT259 Visualizaing Data | Winter 2011 | George Legrady ** ======================================================= ** Project 2 : Top 100 Most Checked Out Items from 2005 to 2010 ** ============================================================== ** Nichole Stockman ** ================ ** ** ** ===================================================================== ** For information on how the data was parsed, how the application works ** and some key notes and observations, please see the README file.` ** Thank you! ** ===================================================================== */ import java.util.ArrayList; import treemap.*; int windowWidth; int windowHeight; int treemapWidth; int treemapHeight; int sideOffset; int topOffset; int bottomOffset; int bkgdColor; PFont font; int type = 2; int cd = 0; int dvd = 1; int book = 2; int folder = 3; boolean showInfoBox = true; RankedLongArray modTimes = new RankedLongArray(); FolderItem rootItem; Item rolloverItem; FolderItem taggedItem; BoundsIntegrator zoomBounds; FolderItem zoomItem; ArrayList Panels; ArrayList DewCats; ArrayList DewSubCats; String[] DewCatNames = { "Computer Science","Philosophy & Psychology","Religion","Social Science", "Language","Science & Mathematics","Technology & Applied Science","Arts & Recreation","Literature", "History, Geography &Biology" }; void setup() { size(1024, 768); windowWidth = 1024; windowHeight = 768; treemapWidth = 800; treemapHeight = 600; sideOffset = 112; topOffset = 125; bottomOffset = windowHeight - treemapHeight - topOffset; bkgdColor = 0; zoomBounds = new BoundsIntegrator(0, 0, width, height); rectMode(CORNERS); smooth(); strokeWeight(0.5f); font = createFont("SansSerif", 13); String Rows[] = loadStrings("Top100Items.txt"); Panels = new ArrayList(); DewCats = new ArrayList(); //Only insert numbers into DewCats if there are items in the //dataset with that category (ie first digit of their dewey #) //=========================================================== for(int i = 0; i < Rows.length; i++) { String[] ParseString = split(Rows[i], ","); float num = Integer.valueOf(ParseString[2].substring(0,1)); if(Float.isNaN(num)) { //ignore } else { int intNum = (int)(num); if(!DewCats.contains(intNum)) { DewCats.add(intNum); } } }//========================================================== setRoot(Rows); setPanels(); } void setRoot(String Rows[]) { FolderItem tm = new FolderItem(null, Rows, "I am ROOT.", folder, Rows.length, 0, 1, 0); tm.setBounds(0, 0, width, height); tm.contentsVisible = true; rootItem = tm; rootItem.zoomIn(); rootItem.updateColors(); } void setPanels() { Panel leftPanel = new Panel(0, topOffset, sideOffset, windowHeight, 180); Panel upperPanel = new Panel(0, 0, windowWidth, topOffset, 180); Panel rightPanel = new Panel(sideOffset + treemapWidth, topOffset, windowWidth, windowHeight, 180); Panel bottomPanel = new Panel(sideOffset, windowHeight - bottomOffset, sideOffset + treemapWidth, windowHeight, 180); Panels.add(leftPanel); Panels.add(upperPanel); Panels.add(rightPanel); Panels.add(bottomPanel); } public void draw() { background(bkgdColor); textFont(font); frameRate(30); zoomBounds.update(); rolloverItem = null; taggedItem = null; if (rootItem != null) { rootItem.draw(); } if (rolloverItem != null) { if(rolloverItem.type != folder) { if(showInfoBox) { rolloverItem.drawInfoBox(); } } } if (taggedItem != null) { taggedItem.drawTag(); } drawPanels(); drawLabels(); } void drawPanels() { for (int i = 0; i < Panels.size(); i++) { Panels.get(i).draw(); } } void drawLabels() { fill(0); smooth(); //Title //----------------- textAlign(CENTER, CENTER); textSize(30); text("Top 100 Most Checked Out Items From 2005 to 2010", windowWidth/2, topOffset/3); //CurrentFolder Label //-------------------- textAlign(LEFT, BOTTOM); textSize(16); if(zoomItem.parent != null) { text(zoomItem.name, sideOffset, topOffset); } //Footnote //------------------- textSize(14); if(zoomItem.parent != null) { text("Press i to toggle display of information box", sideOffset, windowHeight - 5); } if(rolloverItem != null && rolloverItem.type != 3){ if(rolloverItem.parent.contentsVisible){ text("Press i to toggle display of information box", sideOffset, windowHeight - 5); } } } public void mousePressed() { if (zoomItem != null) { zoomItem.mousePressed(); } } public void keyPressed() { switch(key) { case 'i': case'I': showInfoBox = !showInfoBox; break; default: break; } }