ListeningHistory myHistory, originalHistory; Box graph, tailBox, roundBox, logLinBox, modifierBox; Longtail longtail; Rounder rounder; SideSlider sideslider; int logScaleFactor; boolean drawCurves=false; PFont meta32, meta24, meta18, meta12; void setup(){ size(1024,580); colorMode(HSB,1); smooth(); logScaleFactor = 50; originalHistory = new ListeningHistory("megamu"); originalHistory.loadData(); myHistory = originalHistory; meta32 = loadFont("MetaNormal-Roman-32.vlw"); meta24 = loadFont("Meta-Light-28.vlw"); meta18 = loadFont("MetaNormal-Roman-18.vlw"); meta12 = loadFont("MetaNormal-Roman-12.vlw"); graph = new Box(this, 924, 440, 50, 60); tailBox = new Box(graph, 295, 50, 15, 15); roundBox = new Box(graph, 295, 50, 325, 15); logLinBox = null; longtail = new Longtail(this, tailBox); rounder = new Rounder(this, roundBox); sideslider = new SideSlider(this, graph); } void mousePressed(){ if(logLinBox.containsMouse()){ Artists a = myHistory.getArtists(); a.setPopularityScale(!a.getPopularityScale()); } } void draw(){ background(1); // get artists Artists artists = myHistory.getArtists(); // get weeks Weeks weeks = myHistory.getWeeks(); // title String title = "Artist Popularity Over Time"; textAlign(LEFT); textFont(meta24); fill(0.6,0.6,0.3); float baseLine = graph.top - textDescent()*2; text(title, graph.left+15, baseLine); float titleWidth = 325; // draw scale type textFont(meta18); logLinBox = new Box(this, textWidth("Linear | Logarithmic"), textDescent()+textAscent(), graph.left + titleWidth, baseLine - textAscent()); // Do Linear String scaleType = "Linear"; if(logLinBox.containsMouse()) fill(0.6,0.8,0.8, artists.getPopularityScale()?0.5:1); else fill(0.6, artists.getPopularityScale()?0.5:1); text(scaleType, graph.left + titleWidth, baseLine); titleWidth += textWidth(scaleType); // Do mid fill(0.6); text(" | ", graph.left + titleWidth, baseLine); titleWidth += textWidth(" | "); // Do Log scaleType = "Logarithmic"; if(logLinBox.containsMouse()) fill(0.6,0.8,0.8, artists.getPopularityScale()?1:0.5); else fill(0.6, artists.getPopularityScale()?1:0.5); text(scaleType, graph.left + titleWidth, baseLine); titleWidth += textWidth(scaleType); // graph bg fill(0.6,0.02,0.95); rect(graph); // draw scale textAlign(RIGHT); textFont(meta12); fill(0.5); strokeWeight(1); stroke(0, 0.1); for(int i=1;i<=10;i++){ // get y float r = (float)i/10; if(artists.getPopularityScale() == Artists.LOG){ r = log(((float)i/10)*logScaleFactor) / log(logScaleFactor); } float y = lerp(graph.bottom, graph.top, r); text(i*10+"%", graph.left - textDescent(), y + textAscent()/2); line(graph.left, y, graph.right, y); } // draw y scale // iterate over weeks int monthCurrent = -1; float monthLocation = graph.left; String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}; int yearCurrent = -1; float yearLocation = graph.left; noStroke(); for(int w=0; w= longtail.getRangeMin() && popularity <= longtail.getRangeMax() && artist.getMaxPopularity() >= sideslider.getPosition()){ // count displayedArtists++; boolean mouseHover = false; color c = color(getHue(artist.getName()) , 0.8, 0.8); float lastX = 0; float lastY = 0; // iterate over weeks for(int w=0; w lastX && mouseX <= x && mouseY < graph.bottom - 5 && graph.containsMouse()){ if(abs(y-lastY) < (x-lastX)){ //taller then find y based on x float px = unlerp(lastX,x,mouseX); if(px > 0 && px <= 1){ float nny = lerp(lastY,y,px); if(abs(nny-mouseY)<5){ mouseHover = true; fill(c); text(artist.getName(), mouseX, nny-5); } } } else{ //flatter then find x based on y float py = unlerp(lastY,y,mouseY); if(py > 0 && py <= 1){ float nnx = lerp(lastX,x,py); if(abs(nnx-mouseX)<5){ mouseHover = true; fill(c); text(artist.getName(), nnx, mouseY-5); } } } } lastX = x; lastY = y; } // begin a line trace stroke(c,mouseHover?popularity:(popularity/2)); strokeWeight(mouseHover?2:1); strokeCap(ROUND); noFill(); beginShape(); for(int w=0; w