import java.util.*; import processing.opengl.*; import peasy.*; ArrayList transactions = null; //global List of the data ArrayList printTitles = new ArrayList(); // global list of titles that are currently printed to the screen HashMap hm = new HashMap(); HashMap no = new HashMap(); HashMap wc = new HashMap(); HashMap titleStrings = new HashMap(); HashMap activeIntegrators = new HashMap(); HashMap opacityIntegrators = new HashMap(); HashMap exclude = new HashMap(); HashMap connections = new HashMap(); //this is a list of all connections. int limitRecursion = 0; int countRecursion = 0; boolean showConnections = true; boolean showTitles = true; boolean pause = false; boolean showWords = false; float rotationInterval = PI/3000; //keep track of the frequency of the number used the most Iterator hmit; Integrator g; int count=0; int recursion = 0; float r; int m = 1000; int maxConnections = 0; int maxWordConnects = 0; int maxFrequency = 0; int offset = 100; PFont font1; PFont font2; Title activeTitle = null; int maxFreq; float[] rotations = new float[3]; color red = #CC0000; color yellow = #F7E503; color green = #16E200; color blue = #00C7E2; color purple = #D203F7; color tanBack = #F9F0E8; color blueBack = #080535; color connectBlue = #E1FDFF; int xLow; int xHigh; int yLow; int yHigh; int zLow; int zHigh; color colors[] = { green, blue, purple}; PeasyCam cam; String fontnames[] = { "ArialNarrow-Bold-10.vlw", "ArialNarrow-Bold-12.vlw", "ArialNarrow-Bold-14.vlw", "ArialNarrow-Bold-16.vlw", "ArialNarrow-Bold-18.vlw", "ArialNarrow-Bold-20.vlw", "ArialNarrow-Bold-22.vlw", "ArialNarrow-Bold-24.vlw", "ArialNarrow-Bold-26.vlw", "ArialNarrow-Bold-28.vlw", "ArialNarrow-Bold-30.vlw", "ArialNarrow-Bold-32.vlw"}; void setup(){ font1 = loadFont(fontnames[5]); font2 = loadFont(fontnames[7]); cam = new PeasyCam(this, 800); cam.setMinimumDistance(-5000); cam.setMaximumDistance(5000); size(1000,600, OPENGL); background(255); textAlign(LEFT,CENTER); frameRate(100); xLow = -500; xHigh= 500; yLow =-300;; yHigh = 300; zLow = 0; zHigh= 1000; this.transactions = loadTransactions(); hmit = hm.entrySet().iterator(); titleStrings.clear(); } void draw(){ Map.Entry me; String title; Title t; float dewClass; Random rand; float rx, ry, rz; //println(activeIntegrators.size()); if(activeIntegrators.size() == 0){ countRecursion = 0; }else{ ++countRecursion; } //println("recursion"+countRecursion); //if(countRecursion == 200) //activeIntegrators.clear(); if(pause == false){ exclude.clear(); //println(activeIntegrators.size()); if(hmit.hasNext() && activeIntegrators.size() == 0 && opacityIntegrators.size() == 0){ me = (Map.Entry) hmit.next(); title = (String) me.getKey(); dewClass = float(me.getValue().toString()); rand = new Random(); rx = rand.nextFloat()*1600-800; ry = rand.nextFloat()*1200-600; rz = rand.nextFloat()*1200-600; PVector k = new PVector(rx,ry,rz); t = new Title(title, k, dewClass); printTitles.add(t); titleStrings.put(t.title, t); activeTitle = t; } if(!hmit.hasNext()){ println("here"); } } if(activeTitle != null && activeIntegrators.size() == 0){ limitRecursion = 0; attractTitlesTo(activeTitle); } Iterator it = printTitles.iterator(); background(blueBack); rotations = cam.getRotations(); if((mouseX < 200 || mouseX > 700) && (mouseY < 200 || mouseY > 400)) cam.rotateY(rotationInterval); //don't integrate the next until you're done with the last while(it.hasNext()){ t = (Title) it.next(); t.updateIntegrators(); pushMatrix(); int len = t.title.length(); translate(t.p.x, t.p.y, t.p.z); rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); stroke(255); //fill(colors[t.dewCode], 50); fill(connectBlue, 100); noStroke(); box(5+t.connections.size()); if(t.connections.size() == 0){ //t.opacity.attraction = 0.01; //t.opacity.target(0); } if(showTitles){ noStroke(); fill(255, t.opacity.value); if(showWords==false){ fill(255, t.opacity.value); noStroke(); text(t.title,10+t.connections.size(),0); }else{ noStroke(); Iterator fit = t.titleWords.entrySet().iterator(); pushMatrix(); while(fit.hasNext()){ Map.Entry fme = (Map.Entry) fit.next(); String word =(String) fme.getKey(); noStroke(); text(word, 20+t.connections.size(),0); //rotateZ(PI/4); translate(word.length()*10, 0, 0); } popMatrix(); } } popMatrix(); } if(showConnections) drawConnections(); // if(countRecursion == 200) // activeIntegrators.clear(); } //compare this title with the previous title before it, instead of word connections, compare connections within titles //make this recursive void attractToTitles(Title t){ Iterator it = t.connections.entrySet().iterator(); Map.Entry me; Title bt; int count; boolean first = true; PVector distance = new PVector(); float magnitude; float angle; while(it.hasNext()){ me = (Map.Entry) it.next(); bt = (Title) me.getKey(); exclude.put(bt, bt); //update older titles with this connection if(!bt.connections.containsKey(t)) bt.connections.put(t, 1); if(first){ distance.set(bt.targetP); angle = PVector.angleBetween(t.p, bt.targetP); distance.add(offset*cos(angle), offset*sin(angle), offset*cos(angle)); t.g[0].target(distance.x); t.g[1].target(distance.y); t.g[2].target(distance.z); //println("attract to"+t.title); first = false; } else{ attractTitlesTo(t); limitRecursion++; } } } void attractTitlesTo(Title t){ //println(); //println(); if(exclude.containsKey(t)){ return; } exclude.put(t, t); Map.Entry me; Title bt; int count; float angle; boolean first = true; PVector distance = new PVector(); float magnitude; Iterator it = t.connections.entrySet().iterator(); // println("title "+t.title); while(it.hasNext()){ me = (Map.Entry) it.next(); bt = (Title) me.getKey(); distance.set(t.targetP); angle = PVector.angleBetween(bt.p, t.targetP); distance.add(offset*cos(angle), offset*sin(angle), 0); distance = checkBounds(distance); bt.g[0].target(distance.x); bt.g[1].target(distance.y); bt.g[2].target(distance.z); //if(!activeIntegrators.containsKey(bt.title)) bt.putTargetValues(distance); //println("limit"+limitRecursion); //if(limitRecursion <= 18){ attractTitlesTo(bt); limitRecursion++; //}else{ //return; //} } } PVector checkBounds(PVector distance){ if(distance.x < xLow){ distance.x = distance.x-2*(distance.x - xLow); }else if(distance.x > xHigh){ distance.x = distance.x+2*(xHigh - distance.x); } if(distance.y < yLow){ distance.y = distance.y-2*(distance.y - yLow); }else if(distance.y > yHigh){ distance.y = distance.y+2*(yHigh - distance.y); } if(distance.z < zLow){ distance.z = distance.z-2*(distance.z - zLow); }else if(distance.z > zHigh){ distance.z = distance.z+2*(zHigh - distance.z); } return distance; } void drawConnections(){ Iterator it, connectedIt; Title currentTitle, connectedTitle; int connectedCount; Map.Entry me; stroke(0, 100); it = printTitles.iterator(); while(it.hasNext()){ currentTitle = (Title) it.next(); connectedIt = currentTitle.connections.entrySet().iterator(); while(connectedIt.hasNext()){ me = (Map.Entry) connectedIt.next(); connectedTitle = (Title) me.getKey(); connectedCount = int(me.getValue().toString()); strokeWeight(1); stroke(connectBlue, 100); noFill(); //bezier(currentTitle.p.x, currentTitle.p.y, currentTitle.p.z,currentTitle.p.x*2, currentTitle.p.y*2, currentTitle.p.z*2,connectedTitle.p.x*2, connectedTitle.p.y*2,connectedTitle.p.z*2,connectedTitle.p.x, connectedTitle.p.y,connectedTitle.p.z); line(currentTitle.p.x, currentTitle.p.y, currentTitle.p.z,connectedTitle.p.x, connectedTitle.p.y,connectedTitle.p.z); } } }