/* Zachary M. Rubin MAT 259 Project 1 This pro */ import processing.opengl.*; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; final int YI = 40; final int XI = 40; final int TBGX = 12*40; final int TBGY = 19*40; ArrayList transactions = null; HScrollbar hs1, hs2; PFont mainFont; int counter = 0; int squareSize = 50; HashMap itemTypes, itemTable; int lastOn = 0; float minDur = 9000.0; float maxDur = 0.0; int minCount = 9000; int maxCount = 0; char mo = 0; float avgDur; float avgCount; long totalCount = 0; int[] masterDayDistribution = { 0,0,0,0,0,0,0,0}; int masterDayMode = 0; String popLabel = " "; String[] daysOfWeek = { " ", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"}; Integrator[] dayBarLen; String chosenFormat = " "; boolean choseFormat = false; void setup() { size(1440,940); // size(screen.width/2,screen.height/2); itemTypes = new HashMap(); itemTable = getItemTable("itemTypes.html"); background(0); smooth(); frameRate(60); this.transactions = loadTransactions("splxmldata_jan8.txt"); println("loaded transactions"); mainFont = loadFont("ArialMT-48.vlw"); //this is how we go through all hashmap Entries // Set set= itemTable.keySet ( ) ; // Iterator iter = set.iterator ( ) ; // while ( iter.hasNext ( ) ) { // ItemListing I = (ItemListing)itemTable.get(iter.next()); // // println(O.getLabel()); // println (I.getLabel() + "\t\t" + I.getType() + "\t\t" + I.getFormat() + "\t\t" + I.getCategory()); // // } noStroke(); hs1 = new HScrollbar(XI*4, YI, 6, YI*13, 3*5+1); hs2 = new HScrollbar(XI*4, YI*15, XI*28, 6, 3*5+1); dayBarLen = new Integrator[7]; for (int i = 0; i<7; i++) dayBarLen[i] = new Integrator(0.0); calcMinMax(); } void draw() { // //background(255); //drawGrid(); noStroke(); updateIntegrators(); fill(0,50); rect(-1,-1,width+1,height+1); int printReady = 0; strokeWeight(1); stroke(255); line(XI*4, YI, XI*4, YI*15); line(XI*4, YI*15, XI*32, YI*15); // tics for(int i = 0; i< 8; i++){ line((i*XI*4)+4*XI, 15*YI, (i*XI*4)+4*XI, 15*YI+YI/4); } for(int i = 0; i< 7; i++){ line(XI*4, (i*YI*2)+YI, XI*4 - XI/4,(i*YI*2)+YI); } drawStaticLabels(); //scrollbar stuff //float topPos = hs1.getPos()-width/2; // fill(255); // Get the position of the bottom scrollbar // and convert to a value to display the bottom image float bottomPos = hs2.getPos() - XI*5; fill(255); hs2.update(); hs2.display(); float sidePos = hs1.getPos(); hs1.update(); hs1.display(); drawLabels(); int cnt = 0; fill(64); rectMode(CORNERS); //rect(XI*4, YI*17, XI*12, YI*24); fill(100); //rect(XI*4+XI/4, YI*17+YI/4, XI*12-XI/4, YI*24 -YI/4); stroke(2); //line(XI*8, YI*17+YI/4,XI*8, YI*24-YI/4); int keyCol = 0; int keyRow = 0; int formatIndex = 0; String[] formats = { " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," " }; Set set= itemTypes.keySet ( ) ; Iterator iter = set.iterator ( ) ; while ( iter.hasNext ( ) ) { Item I = (Item)itemTypes.get(iter.next()); if(I.count>0){ float y = map(I.dayMode, 1, 7, YI*13, YI); float x = map(I.avgCheckOutDur, 0, maxDur*((XI*27 - bottomPos)/(XI*27)), XI*4, XI*32); if (x < 200.0) x = 200; else if (x > 1280) x =1280; float sz = map(log((float)1/I.count),0, log((float)1/totalCount), 0, 330*(1.1-sidePos/hs1.sposMax)); //println(hs1.sposMax +"\t"+ sidePos); // float sz = map((float)I.dayDistribution[I.dayMode]/I.count,.2, 1, 20,200); //120 int rgb[] = getColor(I.listing.getLabel()); color c1 = color(rgb[0], rgb[1], rgb[2],100); fill(c1); strokeWeight(2); stroke(255); noStroke(); ellipseMode(CENTER); if( I.listing.getFormat().equals(chosenFormat) || !choseFormat) { //println(I.listing.getFormat()+ " and " + chosenFormat +"are equal\n"); ellipse(x,y,sz,sz); } textFont(mainFont, 12); textAlign(LEFT,CENTER);////////////////////////////////////////////////////////////////////////////////////// formats = sort(formats); int txtBxx = XI*4+XI/4+4+keyCol*4*XI; int txtBxy = YI*17+YI/2+4+keyRow*YI/2; if( Arrays.binarySearch(formats,I.listing.getFormat()) <0){ //means the value has not already been entered rectMode(CORNER); if(I.listing.getFormat().equals(chosenFormat)){ rect(txtBxx,txtBxy-6, XI*3, 12); fill(0); } text(I.listing.getFormat(), txtBxx, txtBxy ); fill(c1); keyRow++; formats[formatIndex++] = I.listing.getFormat(); if((txtBxy + 12)>= YI*22){ keyRow = 0; keyCol++; } } if(mouseX > txtBxx && mouseX < txtBxx+XI && mouseY > txtBxy && mouseY < txtBxy+YI/2) { // println("im in"+ I.listing.getFormat()); chosenFormat = I.listing.getFormat(); choseFormat = true; } else if(!(mouseX > txtBxx && mouseX < txtBxx+XI|| mouseY > txtBxy && mouseY < txtBxy+YI/2)) { // println("outside"); // chosenFormat = " " ; } if( I.listing.getFormat().equals(chosenFormat) || !choseFormat) { if ((printReady != 1) || lastOn == cnt){ // find out if we are hovering over //println(mouseX + " " + mouseY); float Xbox = x+sz/2; float Ybox = y+sz/2; rgb = getColor(I.listing.getLabel()); c1 = color(rgb[0], rgb[1], rgb[2],100); fill(c1); if(mouseX > Xbox-sz && mouseX < Xbox && mouseY > Ybox-sz && mouseY < Ybox) { lastOn = cnt; printReady = 1; for(int i = 0; i< 7; i++){ //rectMode(CENTER); dayBarLen[i].target( map ( I.dayDistribution[i+1], 0, (float)I.dayDistribution[I.dayMode], 0, XI*4)); float w = dayBarLen[i].value; //float w = map ( I.dayDistribution[i+1], 0, (float)I.dayDistribution[I.dayMode], 0, 240); // rect( 0,((6-i)*520/6)+50, w , 70); // rectMode(CORNER); //write labels } textAlign(LEFT); textFont(mainFont, 24); text( daysOfWeek[I.dayMode], TBGX+16*XI, TBGY+2*YI); if(I.avgCheckOutDur >=1) text(round(I.avgCheckOutDur), TBGX+8*XI, TBGY+YI); else text(I.avgCheckOutDur, TBGX+8*XI, TBGY+YI); text(I.count, TBGX+16*XI, TBGY+YI); text(I.listing.getType(), TBGX+8*XI, TBGY+2*YI); text(I.listing.getLabel(), TBGX+8*XI, TBGY); text(I.listing.getFormat(), TBGX+16*XI, TBGY); text(I.listing.getCategory(), TBGX+XI*8, TBGY+3*YI); } else if((mouseX > Xbox-sz && mouseX < Xbox) || (mouseY > Ybox-sz && mouseY < Ybox)) { for(int i = 0; i< 7; i++){ // rectMode(CENTER); dayBarLen[i].target(0); // rgb = getColor(I.listing.getLabel()); // c1 = color(rgb[0], rgb[1], rgb[2],100); // fill(c1); // rect( 0,((6-i)*520/6)+50, dayBarLen[i].value, 70); // rectMode(CORNER); } } if (printReady == 0) printReady = 2; rectMode(CENTER); for(int i = 0; i< 7; i++){ // float w = map ( I.dayDistribution[i+1], 0, (float)I.dayDistribution[I.dayMode], 0, 240); float w = dayBarLen[i].value; if (lastOn == cnt) // rectMode(CORNERS); //rect( XI*4,(6-i)*(YI*2)+YI, XI*4 - w ,(6-i)*(YI*2)+YI +70 ); rect( 0,((6-i)*YI*2)+YI, w , YI*2-YI/4); } rectMode(CORNER); cnt++; } } } if (printReady == 2) { // print some default information fill(120); // for(int i = 0; i< 7; i++){ // rectMode(CENTER); // float w = map ( masterDayDistribution[i+1], 0, (float)masterDayDistribution[masterDayMode], 0, 240); // rect( 0,((6-i)*520/6)+50, w, 70); // rectMode(CORNER); // //write labels // } /* textAlign(LEFT); textFont(mainFont, 24); text( (int)totalCount, TBGX, TBGY+YI); if(avgDur >=1) text(round(avgDur), TBGX+8*XI, TBGY+YI); else text(avgDur, TBGX+8*XI, TBGY+YI); text(daysOfWeek[masterDayMode], TBGX+16*XI, TBGY+YI); // text(popLabel, TBGX, TBGY); //text(((ItemListing)itemTable.get(popLabel)).getType(), TBGX+8*XI, TBGY); // text(((ItemListing)itemTable.get(popLabel)).getFormat(), TBGX+16*XI, TBGY); // text(((ItemListing)itemTable.get(popLabel)).getCategory(), TBGX*28, TBGY); */ } } } void updateIntegrators(){ for(int i = 0; i<7; i++) dayBarLen[i].update(); }