//******************************************************* //Jennifer Kinahan //CS 424 - Visualizations //Project 1: EVL Room Temperature: "Heat of the Moment" //Andy Johnson //******************************************************* import controlP5.*; ControlP5 controlP5; FloatTable data; float dataMin, dataMax; MultiList l; CheckBox checkbox; float plotX1, plotY1; float plotX2, plotY2; int theEntryUsed = 0; int entryMin, entryMax; int[] entries; int theColor; color roomTemp; int entryInterval = 100000; int tempInterval = 10; PFont plotFont; PFont font; float focus; float range; float distGraph; float xChange; float yChange; float variableGraphRange; float theVariant; boolean celciusFlag = false; boolean R1 = true; boolean R2 = true; boolean R3 = true; boolean R4 = true; boolean R5 = true; boolean R6 = true; boolean R7 = true; int rowCount; int columnCount; int currentColumn = 7; float whichRoom = 1; PImage theRoomImage; int tempIntervalMinor = 5; void setup(){ size(1024, 768); background(0); smooth(); controlP5 = new ControlP5(this); theRoomImage = loadImage("path3015.png"); data = new FloatTable("history7.tsv"); controlP5.setControlFont(new ControlFont(createFont("Gisha",18), 18)); rowCount = data.getRowCount(); columnCount = data.getColumnCount(); entries = int(data.getRowNames()); entryMin = entries[0]; //entryMax = entries[342000]; entryMax = entries[entries.length - 1]; entryInterval = (entryMax - entryMin) / 5; println(entryInterval + " LOL"); range = entryMax - entryInterval; //println(data.getTableMin()); dataMin = 55; //data.getTableMin(); dataMax = 95; // Corners of the plotted time series plotX1 = 130; plotX2 = width - 80; plotY1 = 450; plotY2 = height - 40; plotFont = createFont("Gisha", 18); textFont(plotFont); smooth(); font = loadFont("Gisha-32.vlw"); textFont(font); fill(255); String s = "Visualization of Temperatures Within the EVL: 2005-2011"; text(s, 90, 30); font = loadFont("Gisha-18.vlw"); textFont(font); String g = "Select a Year to View:"; text(g,777,120); String img = "Image Data Showing:"; text(img,777,385); controlP5.addButton("All",8,20,450,80,25); controlP5.addButton("Room_1",1,20,480,80,25); controlP5.addButton("Room_2",2,20,510,80,25); controlP5.addButton("Room_3",3,20,540,80,25); controlP5.addButton("Room_4",4,20,570,80,25); controlP5.addButton("Room_5",5,20,600,80,25); controlP5.addButton("Room_6",6,20,630,80,25); controlP5.addButton("Room_7",7,20,660,80,25); controlP5.addButton("Clear",0,20,700,80,25); checkbox = controlP5.addCheckBox("checkBox",820,70); checkbox.setColorForeground(color(120)); checkbox.setColorActive(color(189,139,246)); checkbox.setColorLabel(color(224)); checkbox.setItemsPerRow(2); checkbox.setSpacingColumn(120); checkbox.setSpacingRow(20); checkbox.addItem("Celcius",001); controlP5.addButton("__2005__",2005,820,140,80,25); controlP5.addButton("__2006__",2006,820,170,80,25); controlP5.addButton("__2007__",2007,820,200,80,25); controlP5.addButton("__2008__",2008,820,230,80,25); controlP5.addButton("__2009__",2009,820,260,80,25); controlP5.addButton("__2010__",2010,820,290,80,25); controlP5.addButton("__2011__",2011,820,320,80,25); fill(0); rectMode(CORNERS); strokeWeight(3); rect(plotX1, plotY1, plotX2, plotY2); stroke(224); noFill(); rect(plotX1-1, plotY1-1, plotX2+1,plotY2+1); // Draw the title of the current plot All(8); } void draw(){ //background(0); smooth(); image(theRoomImage,15,45); drawTempLabels(); drawRooms(theEntryUsed); stroke(0); fill(0); rect(720,400,width,445); font = loadFont("Gisha-18.vlw"); textFont(font); fill(255); String minutes; if(int(data.getFloat(theEntryUsed,4)) == 0){ minutes = "00"; } else if(int(data.getFloat(theEntryUsed,4)) == 1){ minutes = "01"; } else{ minutes = (""+int(data.getFloat(theEntryUsed,4))); } String ap; if(int(data.getFloat(theEntryUsed,5)) == 1){ ap = "AM"; } else{ ap = (""+int(data.getFloat(theEntryUsed,5))); ap = "PM"; } String thePoint = ("" + int(data.getFloat(theEntryUsed,0))+"/" + int(data.getFloat(theEntryUsed,1))+"/" + int(data.getFloat(theEntryUsed,2))+" " + int(data.getFloat(theEntryUsed,3))+":" + minutes +" "+ap); text(thePoint,777,415); } void drawTitle() { fill(0); stroke(0); rect(plotX1,plotY1-37,plotX1+250,plotY1-4); fill(255); textSize(20); //textAlign(LEFT); if(celciusFlag == true){ currentColumn = 8; } else{ currentColumn = 7; } String title = data.getColumnName(currentColumn); text(title, plotX1, plotY1 - 10); } void drawEntryLabels() { fill(0); stroke(0); rect(0,height - 37, width, height); fill(255); textSize(14); //textAlign(CENTER, TOP); // Use thin, gray lines to draw the grid stroke(224); strokeWeight(1); String minutes; entryInterval = (entryMax - entryMin) / 5; for (int row = entryMin; row < entryMax; row++) { if (entries[row] % entryInterval == 0) { float x = map(entries[row], entryMin, entryMax, plotX1, plotX2); if(int(data.getFloat(row,4)) == 0){ minutes = "00"; } else{ minutes = ("+"+int(data.getFloat(row,4))); } text(int(data.getFloat(row,0))+","+ int(data.getFloat(row,1))+","+ int(data.getFloat(row,2))+" "+ int(data.getFloat(row,3))+":"+ (minutes) , x, plotY2 + 15); line(x, plotY1, x, plotY2); } } } void drawDataLine(int col, float room) { if (celciusFlag == true){ col = 8; } else{ col = 7; } beginShape(); noFill(); strokeWeight(2); for (int row = entryMin; row < entryMax; row++) { if (data.getFloat(row, 6) == room){ if (data.isValid(row, col)) { float value = data.getFloat(row, col); float x = map(entries[row], entryMin, entryMax, plotX1, plotX2); float y = map(value, dataMin, dataMax, plotY2, plotY1); vertex(x, y); } } } endShape(); } void drawTempLabels() { if(celciusFlag == true){ dataMin = 10; dataMax = 40; } else{ dataMin = 55; dataMax = 95; } fill(0); stroke(0); rect(plotX1-20,450,plotX1-6,height); stroke(224); strokeWeight(1); fill(224); textSize(14); for (float v = dataMin; v <= dataMax; v += tempIntervalMinor) { if (v % tempIntervalMinor == 0) { // If a tick mark float y = map(v, dataMin, dataMax, plotY2, plotY1); if (v % tempInterval == 0) { // If a major tick mark float textOffset = textAscent()/2; // Center vertically if (v == dataMin) { textOffset = 0; // Align by the bottom } else if (v == dataMax) { textOffset = textAscent(); // Align by the top } text(floor(v), plotX1 - 21, y + textOffset); line(plotX1 - 4, y, plotX2, y); // Draw major tick } else { line(plotX1 - 2, y, plotX1, y); // Draw minor tick } } } } void controlEvent(ControlEvent theEvent) { if(theEvent.isGroup()) { println(theEvent.group().name()); if(theEvent.group().name()=="checkBox"){ if(celciusFlag ==true){ celciusFlag = false; printGraph(); } else if (celciusFlag ==false){ celciusFlag = true; printGraph(); } } } } void mousePressed(){ println(mouseX+ " " + mouseY); if((mouseX > plotX1) && (mouseX < plotX2) && (mouseY > plotY1) && (mouseY < plotY2)){ focus = ((mouseX) - plotX1); //some number distGraph = (plotX2 - plotX1); //814 range = entryMax - entryMin; xChange = (focus/distGraph); yChange = 1.0-xChange; if(range > 100){ entryMax = entryMax - int(yChange*((.15)*range)); entryMin = entryMin + int(xChange*((.15)*range)); } else if(( range <= 100) && (range >= 0)){ entryMax = entryMax; entryMin = entryMin; } println(entryMax); println(entryMin); fill(0); rectMode(CORNERS); rect(plotX1, plotY1, plotX2, plotY2+2); stroke(224); strokeWeight(3); noFill(); rect(plotX1-1, plotY1-1, plotX2+1,plotY2+1); // Draw the title of the current plot drawTitle(); drawTempLabels(); if (R1 == true){ Room_1(1); } if (R2 == true){ Room_2(2); } if (R3 == true){ Room_3(3); } if (R4 == true){ Room_4(4); } if (R5 == true){ Room_5(5); } if (R6 == true){ Room_6(6); } if (R7 == true){ Room_7(7); } drawEntryLabels(); } } public void All(int theValue) { Room_1(1); Room_2(2); Room_3(3); Room_4(4); Room_5(5); Room_6(6); Room_7(7); R1 = true; R2 = true; R3 = true; R4 = true; R5 = true; R6 = true; R7 = true; } public void Room_1(int theValue) { R1 = true; drawTitle(); stroke(#E8503C); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Room_2(int theValue) { R2 = true; drawTitle(); stroke(#F9882D); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Room_3(int theValue) { R3 = true; drawTitle(); stroke(#F7ED41); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Room_4(int theValue) { R4 = true; drawTitle(); stroke(#45D0E1); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Room_5(int theValue) { R5 = true; drawTitle(); stroke(#556CD1); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Room_6(int theValue) { R6 = true; drawTitle(); stroke(#B550D6); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Room_7(int theValue) { R7 = true; drawTitle(); stroke(#F48EF8); strokeWeight(3); drawDataLine(currentColumn,theValue); drawTempLabels(); drawEntryLabels(); } public void Clear(int theValue) { R1 = false; R2 = false; R3 = false; R4 = false; R5 = false; R6 = false; R7 = false; entryMin = entries[0]; entryMax = entries[entries.length - 1]; fill(0); rectMode(CORNERS); rect(plotX1, plotY1, plotX2, plotY2+2); stroke(224); strokeWeight(3); noFill(); rect(plotX1-1, plotY1-1, plotX2+1,plotY2+1); // Draw the title of the current plot drawTitle(); drawEntryLabels(); drawTempLabels(); } public void __2005__ (int theValue){ entryMin = entries[0]; entryMax = entries[23218]; printGraph(); } public void __2006__ (int theValue){ entryMin = entries[23219]; entryMax = entries[81329]; printGraph(); } public void __2007__ (int theValue){ entryMin = entries[81330]; entryMax = entries[134566]; printGraph(); } public void __2008__ (int theValue){ entryMin = entries[134567]; entryMax = entries[195711]; printGraph(); } public void __2009__ (int theValue){ entryMin = entries[195712]; entryMax = entries[254720]; printGraph(); } public void __2010__ (int theValue){ entryMin = entries[254722]; entryMax = entries[316080]; printGraph(); } public void __2011__ (int theValue){ entryMin = entries[316081]; entryMax = entries[entries.length-1]; printGraph(); } void printGraph(){ fill(0); rectMode(CORNERS); rect(plotX1, plotY1, plotX2, plotY2+2); stroke(224); strokeWeight(3); noFill(); rect(plotX1-1, plotY1-1, plotX2+1,plotY2+1); // Draw the title of the current plot drawTitle(); drawTempLabels(); if (R1 == true){ Room_1(1); } if (R2 == true){ Room_2(2); } if (R3 == true){ Room_3(3); } if (R4 == true){ Room_4(4); } if (R5 == true){ Room_5(5); } if (R6 == true){ Room_6(6); } if (R7 == true){ Room_7(7); } drawEntryLabels(); } void keyPressed(){ if (key == '-') { println(mouseX+ " " + mouseY); if((mouseX > plotX1) && (mouseX < plotX2) && (mouseY > plotY1) && (mouseY < plotY2)){ focus = ((mouseX) - plotX1); //some number distGraph = (plotX2 - plotX1); //814 range = entryMax - entryMin; //gives a number to help figure out which entry was chosen variableGraphRange = (range/distGraph); println(variableGraphRange); //gives a number in relation to the scale of the graph //best fit point to grab an entry theVariant = variableGraphRange * focus; theEntryUsed = int(theVariant); println("THIS"+theEntryUsed); } } } void drawRooms(int theEntryUsed){ //room 7 roomTemp = getRoomColor(7, theEntryUsed); fill(roomTemp); rect(95,68,299,189); //room 1 roomTemp = getRoomColor(1, theEntryUsed); fill(roomTemp); rect(307,71,510,190); //room 2 roomTemp = getRoomColor(2, theEntryUsed); fill(roomTemp); rect(517,68,712,260); //room3 roomTemp = getRoomColor(3, theEntryUsed); fill(roomTemp); rect(517,267,711,355); //room 4 roomTemp = getRoomColor(4, theEntryUsed); fill(roomTemp); rect(408,238,510,355); //room 5 roomTemp = getRoomColor(5, theEntryUsed); fill(roomTemp); rect(307,239,403,356); //room 6 roomTemp = getRoomColor(6, theEntryUsed); fill(roomTemp); rect(97,239,298,359); } int getRoomColor(float room, int theEntryUsed){ int myEntry = theEntryUsed; float hour1 = data.getFloat(myEntry,3); float minute1 = data.getFloat(myEntry,4); float ampm1 = data.getFloat(myEntry,5); float theRoom = room; //to avoid null pointer if((myEntry >= 6)&&(myEntry <= entries.length-7)){ for(int i = (myEntry -6); i <= (myEntry +6); i++){ if(data.getFloat(i,6) == theRoom){ if(data.getFloat(i,4) == minute1){ int theTemp = int(data.getFloat(i,7)); if (theTemp > 90){ theColor = color(#FF0000,150); } else if ((theTemp < 90) && (theTemp >= 84)){ theColor = color(#FF7300,150); } else if ((theTemp < 84) && (theTemp >= 79)){ theColor = color(#FFF700,150); } else if ((theTemp < 79) && (theTemp >= 74)){ theColor = color(#00FFB7,150); } else if ((theTemp < 74) && (theTemp >= 69)){ theColor = color(#0077FF,150); } else if ((theTemp < 69) && (theTemp >= 64)){ theColor = color(#001EFF,150); } else if ((theTemp < 59) && (theTemp >= 54)){ theColor = color(#3700FF,150); } else if (theTemp < 54){ theColor = color(#9000FF,150); } stroke(255); font = loadFont("Gisha-32.vlw"); textFont(font); String theTempString = ""; if(celciusFlag == false){ theTempString = (""+int(data.getFloat(i,7))); } else if(celciusFlag == true){ theTempString = (""+int(data.getFloat(i,8))); }if(theRoom == 7){ text(theTempString,167,120); } else if(theRoom == 1){ text(theTempString,375,120); } else if(theRoom == 2){ text(theTempString,584,165); } else if(theRoom == 3){ text(theTempString,580,315); } else if(theRoom == 4){ text(theTempString,462,295); } else if(theRoom == 5){ text(theTempString,329,295); } else if(theRoom == 6){ text(theTempString,154,295); } } } } } //theColor = color(123,123,123,100); return theColor; }