/* MICHAEL D MCDANIEL MAT 259 Final Project get ready for some sloppy, ill-commented programming... */ import proxml.*; XMLInOut inOut; String subjects[]; PFont font; PFont font20; PFont font27; PFont font35; PFont fontBig; int sIndex; int sIndex2; int sIndexM; String subText = ""; String subText2 = ""; int[][] dataArray = new int[1001][310]; int idatei = 0; int itimei = 1; int classi = 2; boolean flagLoading = false; boolean flagParse = false; boolean flagIndex = false; boolean flagQ = true; int daysi; int[] arrayTemp = new int[310]; void setup() { size(1105,495); colorMode(HSB,10,100,100); inOut = new XMLInOut(this); subjects= loadStrings("deweySubjects.txt"); font = loadFont("HelveticaNeue-Bold-12.vlw"); font20 = loadFont("HelveticaNeue-Bold-20.vlw"); font27 = loadFont("HelveticaNeue-Bold-27.vlw"); font35 = loadFont("HelveticaNeue-Bold-35.vlw"); fontBig = loadFont("HelveticaNeue-Bold-60.vlw"); inOut.loadElement("/data/checkOut_Jan08.xml"); } void xmlEvent(XMLElement element) { println("begin parsing"); flagLoading = true; XMLElement[] days; XMLElement[] hours; XMLElement[] transactions; XMLElement d,h,t,v1; int i,j,k, numHours; if(element.hasChildren()) { days = element.getChildren(); for(daysi=0; daysi 9 && j <20) { transactions = hours[j].getChildren(); for(k=0; k 9 && checkInHou<20) int transHour = ((checkInDay-1)*10)+(checkInHou%10); dataArray[deweyClassNumber][transHour]++; } } } } } } println("parsing complete"); flagParse = true; } void draw() { smooth(); if(!flagLoading) { background(0); textFont(font35); text("loading",width/2,height/2); textFont(font20); text("this may take a while",width/2,height/2+30); } else if(flagLoading && !flagParse) { background(0); textFont(font35); text("parsing day " + daysi + " of 31",width/2,height/2+30); text("loading",width/2,height/2); } else { background(0); //text("click",width/2,height/2); // title etc textAlign(LEFT); textFont(font20); fill(100,0,100); text("Dewey Items Checked Out Per Hour", 150,50); textFont(font); text("during normal operating hours - month of Janary 2008", 150,65); textAlign(RIGHT); //text("reset", width-50,50); //text("draw all", width-100,50); // draws color gradients for(int i=0; i<10; i++) { for(int j=0; j<100; j++) { stroke(i,j,100); line(j+25,i*30+100,j+25,i*30+125); } fill(0); textAlign(LEFT); textFont(font35); text(i+"00",24,i*30+127); } //draw scale bars for(int i=1; i<11; i++) { stroke(0,0,25); line(150,height-100-(50*log(i)+1),1080,height-100-(50*log(i)+1)); line(150,height-100-(50*log(i*10)+1),1080,height-100-(50*log(i*10)+1)); if(i<5) { line(150,height-100-(50*log(i*100)+1),1080,height-100-(50*log(i*100)+1)); } } // draw day bars for(int i=0; i<31; i++) { if (i%2 == 0) { noStroke(); fill(0,0,25); rect(150+(i*30),height-98,30,4); } } // draws lines + info text stroke(100,0,100); line(150,height-48,218,height-48); // date line(243,height-48,293,height-48); // time line(318,height-48,350,height-48); // number textFont(font); fill(100,0,100); text("date", 150, height-36); text("time", 243, height-36); text("nž", 318, height-36); // writes dewey subject fill(floor(sIndex/100),sIndex%100,100); textFont(font20); textAlign(RIGHT); text(subText,width-20,445); // fill temporary array for(int i=0; i<310; i++) { arrayTemp[i] = dataArray[sIndex][i]; } // draw graph as you mouse over bars if ((mouseX >= 25) && (mouseX < 120) && (mouseY > 100) && (mouseY < 395) ) { sIndexM = floor((mouseY-100)/30)*100+(mouseX-25)%100; noFill(); stroke(floor(sIndexM/100),sIndexM%100,100); beginShape(); for(int i=0; i<310; i++) { vertex(i*3+150,height-100-(50*log(dataArray[sIndexM][i]+1))); } endShape(); } // draws dewey graph //if (flagIndex) { smooth(); stroke(floor(sIndex/100),sIndex%100,100); noFill(); beginShape(); for(int i=0; i<310; i++) { vertex(i*3+150,height-100-(50*log(dataArray[sIndex][i]+1))); } endShape(); flagIndex = false; //} //draw second dewey graph if button pressed if (keyPressed) { stroke(floor(sIndex2/100),sIndex2%100,100); noFill(); beginShape(); for(int i=0; i<310; i++) { vertex(i*3+150,height-100-(50*log(dataArray[sIndex2][i]+1))); } endShape(); fill(floor(sIndex2/100),sIndex2%100,100); textFont(font20); textAlign(RIGHT); text(subText2,width-20,465); } // draw vert line # display number if(mouseX >= 150 && mouseX < 1080 && mouseY >= 100 && mouseY <= height-100) { //stroke(100,0,100); fill(100,0,100); //line(mouseX,100,mouseX,height-100); int eY = (mouseX-150)/3; ellipse(mouseX,height-100-(50*log(dataArray[sIndex][eY])+1),4,4); textFont(font20); textAlign(LEFT); fill(floor(sIndex/100),sIndex%100,100); // during normal hours of operation, month of january 2008 text("JAN " + ((mouseX-150)%930/30+1),150,height-50); // date int timeText = (((mouseX-150)%30)/3+10); text(timeText + ":00",243,height-50); // time textAlign(RIGHT); text(dataArray[sIndex][eY],350,height-50); // number } getSubject(); } //noLoop(); // if this is not here, numbers update, graph does not stay } void getSubject() { if ((mouseX >= 25) && (mouseX < 120) && (mouseY > 100) && (mouseY < 395) ) { textFont(fontBig); textAlign(RIGHT); fill(100,0,100); text(floor((mouseY-100)/30)*100+(mouseX-25)%100, 125, 445); } /*else { textFont(font27); textAlign(LEFT); fill(0,0,25); text("DEWEY",50,465); }*/ } void mousePressed() { if ((mouseX >= 25) && (mouseX < 120) && (mouseY > 100) && (mouseY < 395) ) { if(!keyPressed) { sIndex = floor((mouseY-100)/30)*100+(mouseX-25)%100; subText = subjects[sIndex]; //flagQ = false; } else if (keyPressed) { sIndex2 = floor((mouseY-100)/30)*100+(mouseX-25)%100; subText2 = subjects[sIndex2]; } flagIndex = true; redraw(); // if this is not here, loading screen will not go away. } }