PFont font; PFont bigfont; String[] Series_Data; ArrayList SeriesList = new ArrayList(60000); int numSeries = 0; int graph_start_year = 1790; int graph_end_year = 2010; int graph_span = graph_end_year - graph_start_year; int grid_width = 300; int grid_height = 192; int square_dim = 2; int grid_dim = 3; Series[][] theGrid = new Series[grid_width][grid_height]; Series selectedSeries; int selected_row = int(random(grid_height)); int selected_col= int(random(grid_width)); int[] row_labels = new int[grid_height]; String keyLabel = "items"; int sort_by = 0; // 0 for content, 1 for accumulation int xmargin = 40; int ymargin = 40; PImage theGridbg; void setup() { size(1000, 650); println("started setup"); colorMode(HSB,255); background(0); hint(ENABLE_NATIVE_FONTS); font = createFont("Arial",11); println("made font - ingesting"); // bigfont = loadFont("Geneva-12.vlw"); //bigfont = loadFont("Helvetica-Bold-36.vlw"); IngestStrings("SeriesData_Str.txt", SeriesList); // args file path, arraylist println("finished ingesting - loading background"); theGridbg = loadImage("grid_items.png"); sortSeries(); println("finished sorting - building grid"); buildGrid(); } void draw(){ background(0); image(theGridbg,0,0); translate(xmargin,ymargin); updateCaption(); //Scope(100,100,2); Caption(); } void buildGrid(){ int grid_row = 0; int grid_col = 0; int draw_decade = graph_start_year; for (int s=0; s < SeriesList.size(); s++){ Series thisSeries = (Series) SeriesList.get(s); if (thisSeries.AccumStartDate >= draw_decade+10){ //grid_col+=2; draw_decade += 10; if (row_labels[grid_row] == 0){ // if we haven't yet set a label for this row row_labels[grid_row] = draw_decade; } //continue; } theGrid[grid_col][grid_row] = thisSeries; if (grid_col < grid_width-1) { grid_col++; } else { grid_col = 0; grid_row++; } } } void Caption(){ int ytextpos = 0; int xtextpos =0; textFont(font,11); fill(0,0,255); noFill(); stroke(255); rect((selected_col*grid_dim)-1,(selected_row*grid_dim)-1,grid_dim,grid_dim); String theCaption = selectedSeries.ID + ": " + selectedSeries.Title; String theCaption2 = selectedSeries.ContStartDate + "-" + selectedSeries.ContEndDate + " " + selectedSeries.Items + " items in "+ selectedSeries.Metres +"m"; if (theCaption.length() > 100) theCaption = theCaption.substring(0,100)+ "..."; // trim the text to 100 chars float txtWidth = max(textWidth(theCaption),textWidth(theCaption2)); fill(0,180); noStroke(); rect(min((grid_width*grid_dim)-txtWidth-10,(selected_col*grid_dim)+xtextpos-10),(selected_row*grid_dim)-40,txtWidth+10,35); fill(255); text(theCaption, min((grid_width*grid_dim)-txtWidth-5,(selected_col*grid_dim)+xtextpos-5), (selected_row*grid_dim)-26); text(theCaption2, min((grid_width*grid_dim)-txtWidth-5,(selected_col*grid_dim)+xtextpos-5), (selected_row*grid_dim)-11); text("brightness key: "+ keyLabel,0,(grid_height*grid_dim)+15); } void sortSeries(){ java.util.Collections.sort(SeriesList); } void keyPressed(){ if (key == 'i'){ theGridbg = loadImage("grid_items.png"); keyLabel = "items"; } if (key == 'm'){ theGridbg = loadImage("grid_metres.png"); keyLabel = "shelf metres"; } if (key == 's'){ theGridbg = loadImage("grid_span.png"); keyLabel = "none"; } if (key == 'p'){ theGridbg = loadImage("grid_items_per_m.png"); keyLabel = "items per shelf metres"; } if (keyCode == UP){ if (selected_row > 0) selected_row--; } else if (keyCode == DOWN){ if (selected_row < grid_height) selected_row++; } else if (keyCode == LEFT){ if (selected_col > 0) selected_col--; } else if (keyCode == RIGHT){ if (selected_col < grid_width) selected_col++; } //selectedSeries = theGrid[selected_col][selected_row]; } void updateCaption(){ //if (theGrid[selected_col][selected_row] != null) selectedSeries = theGrid[selected_col][selected_row]; // } } void mouseReleased(){ if ((mouseX > xmargin) && (mouseY > ymargin) && (mouseX < xmargin+(grid_dim*grid_width)) && (mouseY < ymargin+(grid_dim*grid_width))){ selected_row = (mouseY-ymargin)/grid_dim; selected_col = (mouseX-xmargin)/grid_dim; } } void Scope(int w, int h, float zoom){ int source_w = int(w/zoom); int source_h = int(h/zoom); PImage scopeImg = theGridbg.get(int(xmargin+(selected_col*grid_dim)-(0.5*source_w)),int(ymargin+(selected_row*grid_dim)-(0.5*source_h)),int(source_w),int(source_h)); noFill(); stroke(255); strokeWeight(2); rect((selected_col*grid_dim)-(w*0.5),(selected_row*grid_dim)-(h*0.5),w,h); image(scopeImg,(selected_col*grid_dim)-(w*0.5),(selected_row*grid_dim)-(h*0.5),w,h); }