import java.util.*; /* 259 Project 1 (2D): Pictogrid -- Version 2 Date: 26 January 2010 Author: Eliza S. Bradley -Utilizes Reza's xmlStripperFiltered code (adapt to get all DeweyClass) -Currently applied to 1-15 February 2009 SPL data -Creates grid of DeweyClass specific pictograms, where standardized count is expressed by transparency and x-dimension is time (day). Three histograms present additional info: (#1 - top): Standardized bars of class day count, can be overlayed and cleared by clicking on top gray square (#2 - side): Max daily count by class for data period (values used to normalize) (#3 - bottom): Stacked histogram of class counts for each day An additional element is the Seattle webcam imagery (www.wunderground.com) which updates with the mouse position (day). extra notes: isotypes from: http://www.gerdarntz.org/isotype http://www.syedrezaali.com/DV/ http://www.syedrezaali.com/DV/SPL_2DCircularCategram.zip week 2: xmlStripperFiltered [gets 700 category in original] Example 15-7: Displaying the pixels of an image http://www.wunderground.com/webcams/dannybain/1/show.html?year=2009&month=02&time=noon#cal */ //PUBLIC VARIABLES String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; String[] DeweyNamesLong = {"General Info & Computer Sci", "Philosophy & Psychology", "Religion", "Social Sciences", "Languages", "Science & Mathematics", "Technology & Applied Science", "Arts & Recreation", "Literature", "History & Geography" }; String[] dd={"000","100","200","300","400","500","600","700","800","900"}; String[] ddtxt={"GEN","PHI","REL","SOC","LNG","SCI","TEC","ART","LIT","HIS"}; //Redo this with Java time code so updates automatically String[] day_of_week={"Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; int currentMonth = 2; //February int [] dew_max = new int[10]; int [] dew_min = new int[10]; int xdim=31; //Number of x-elements to read in (currently days, used to be 24 for hours) int xdim_show=15; //Show 15 values across x-dimension int[][] TimeDewArray = new int[xdim][10]; int[][] hrdewAlpha=new int[xdim][10]; int counterstart=0; int counter=counterstart; PImage[] wcam=new PImage[xdim]; PImage[] images = new PImage[10]; PFont font0; PFont font1; PFont font2; PFont font3; //spacing elements int grid_ytop=115; int bgcolor=255; int txcolor=0; int yedge=50; int margin=10; int xoff=140; int sz=40; int grid=sz+2; int xrightbar=30; int xlefttext=20; int mapshift=50; int xrightline=(xdim_show)*grid+xrightbar+xoff; boolean togglegrid=true; // buttons color currentcolor; RectButton rect1, rect2; boolean locked = false; //Dewey Class Colors //Original color array -- matches images int[][] colorArrayA = {{140, 255, 2}, {203, 189, 189}, {194, 174, 147}, {39, 135, 93}, {250,221,141}, {211,37,36}, {179,105,0}, {8,168,244}, {130,79,78}, {2,162,212}}; // Color array from colorbrewer int[][] colorArrayB = {{165, 0, 38}, {215, 48, 39}, {244,109,67}, {253, 174, 97}, {254,224,144}, {214,233,238}, {171,217,233}, {116,173,209}, {69,117,180}, {9,76,157}}; int[][] colorArray={{97,97,97}, {255,33,28}, {255,87,0}, {210,128,18}, {171,142,24}, {122,69,0}, {4,91,4}, {0,71,99}, {19,19,158}, {101,22,151}}; void setup() { frameRate(60); // sixty frames per second size(1020,800); smooth(); //size(750,750); font0 = createFont("GillSans-14.vlw",14); font1 = createFont("GillSans-18.vlw",18); font2 = createFont("GillSans-24.vlw",24); font3 = createFont("GillSans-Bold-28.vlw",28); background(bgcolor); fill(txcolor); int ytitle=35; textFont(font3); textAlign(CENTER); int midpt=(2*xoff+20+15*grid)/2; text("Seattle Public Library: Isotype 2D Plot",midpt,ytitle); textAlign(LEFT); textFont(font1); int ybottom=790; text("MAT 259: Eliza Bradley",xlefttext,ybottom); fill(120); text("Max # of Transactions",xrightline,grid_ytop); text("Subject",xlefttext,grid_ytop); stroke(126); //line(xoff-20,59,15*grid+xoff+20,59); stroke(0); //BUTTON (click on to clear top histogram) color buttoncolor = color(200); color highlight = color(153,250); color buttoncolor2 = color(200); color highlight2 = color(153,250); rect1 = new RectButton(650, ybottom-15, 20, buttoncolor, highlight); rect2 = new RectButton(890, ybottom-15, 20, buttoncolor2, highlight2); fill(txcolor); text("Clear Top Graph Change Background",500,ybottom); String[] lines; lines = loadStrings("matrix.txt"); //Processed data to total transaction number as a function of day and dewey decimal category for (int i = 0; i < xdim; i++) { String sections[] = split(lines[i], ","); for (int j = 0; j < 10; j++) { TimeDewArray[i][j] = int(sections[j]); } } int [] time_max = new int[xdim_show]; int [] time_sum = new int[xdim_show]; int [] dew_temp = new int[xdim_show]; int [] offset = new int[xdim]; int barxi; // Load wcam images, write day of week & number for (int i=0; i x && mouseX<(x+sz) && mouseY>i*grid+grid_ytop && mouseY<(i*grid+sz+grid_ytop)) //x,i*grid,sz,sz { int xup_box=xrightline; int yup_box=grid*10+45+grid_ytop+yedge-35;//10*grid+10+grid_ytop; offset[0]+grid_ytop+yedge-25 stroke(bgcolor); fill(bgcolor); rect(xup_box,yup_box,400,150); fill(bgcolor); fill(colorArray[i][0],colorArray[i][1],colorArray[i][2]); textFont(font1); int daytxt=counter+1; text(daytxt+" Feb. 2009\nCount/Max="+TimeDewArray[counter][i]+"/"+dew_max[i],xup_box,yup_box+110); tint(255,255,255,255); image(wcam[counter],xup_box,yup_box,107,80); fill(bgcolor); rect(xup_box,yup_box+150,300,20); fill(txcolor); textFont(font1); text(DeweyNamesLong[i],xup_box,yup_box+160); //Bar graph on top //int grid_ytop=75; stroke(0,0); fill(colorArray[i][0],colorArray[i][1],colorArray[i][2]); int bartop=(int) map(TimeDewArray[counter][i],0,dew_max[i],0,50); //experiment w/ rotation //pushMatrix(); //translate(x+sz/3,grid_ytop-bartop-5,0); //rotate(PI/3.0); //rotate(PI/3.0); //rect(0,0,sz/3,bartop); rect(x+sz/3,grid_ytop-bartop-15,sz/3,bartop); //popMatrix(); } counter++; } } }