import java.util.*; import processing.opengl.*; import peasy.*; ArrayList transactions = null; //global List of the data static ArrayList sortedWords = new ArrayList(); //global List of sortedwords HashMap hm = new HashMap(); HashMap no = new HashMap(); HashMap secondTier = new HashMap(); static HashMap wc = new HashMap(); HashMap connections = new HashMap(); //this is a list of all connections. boolean showNumber = false; //keep track of the frequency of the number used the most Iterator wcit; Integrator g; static int count=0; static int MINVALUE = 6; //the minimum number to include float r; int m = 1000; int scanNdx = 0; PFont font1; PFont font2; String activeWord = 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 colors[] = { yellow, 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, 2000); //these control clipping cam.setMinimumDistance(1); cam.setMaximumDistance(4000); size(900,600, OPENGL); background(255); textAlign(RIGHT,CENTER); frameRate(1000); smooth(); this.transactions = loadTransactions("splxmldata.txt"); countWords(); TransactionUtils.sortWords(wc); wcit = sortedWords.iterator(); g = new Integrator(0.01,0.3, 0.8); g.target(1.0); } void draw(){ //animate the load function so that only certain parts are highlighted at a time //values x and y values within a given range will fade in and out. background(tanBack); rotations = cam.getRotations(); Word w, awobj; r = 2*PI; if(activeWord == null){ drawNewConnections(); if(g.value >= .95){ noStroke(); for(int j= 0; j < count; j++){ w = (Word) sortedWords.get(j); pushMatrix(); translate(w.x,w.y,w.z); rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); noStroke(); fill(0,100); if(activeWord == null){ fill(0, 150); textFont(font1, 20); text(w.word, 0,0,0); // fill(255, 100); // ellipse(0, 0, w.totFreq/4, w.totFreq/4); // fill(0,100); // ellipse(0, 0, w.totFreq/5, w.totFreq/5); } popMatrix(); } } } else{ awobj = (Word)wc.get(activeWord); drawActiveWord(awobj); } } void countWords(){ Iterator it; Map.Entry me; Word w; it = wc.entrySet().iterator(); while(it.hasNext()){ me = (Map.Entry)it.next(); w = (Word) me.getValue(); if(w.totFreq > MINVALUE){ count++; } if(maxFreq < w.totFreq){ maxFreq = w.totFreq; } } } void drawNewConnections(){ Iterator it; Connection c; float p; Map.Entry me; //update the itegrator so that it draws new connections g.update(); p = g.value; it = connections.entrySet().iterator(); //need a way while(it.hasNext()){ //make sure that both are above the minValue me = (Map.Entry) it.next(); c = (Connection) me.getValue(); if(c.a.totFreq > MINVALUE && c.b.totFreq > MINVALUE){ strokeWeight(c.count/6); stroke(red, 20+c.count); line(c.a.x, c.a.y, c.a.z, c.b.x*p, c.b.y*p, c.b.z*p); } } } void drawActiveWord(Word w){ Iterator it; Connection c; float p; Map.Entry me; //update the itegrator so that it draws new connections g.update(); p = g.value; it = connections.entrySet().iterator(); textFont(font2, 24); rotations = cam.getRotations(); secondTier.clear(); if(p > .95){ pushMatrix(); translate(w.x,w.y,w.z); rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); noStroke(); fill(0, 255); text(w.word+" ("+w.totFreq+")", 0, 0, 0); popMatrix(); } fill(0, 100); while(it.hasNext()){ //make sure that both are above the minValue me = (Map.Entry) it.next(); c = (Connection) me.getValue(); if(c.a == w || c.b == w){ if(c.a.totFreq > MINVALUE && c.b.totFreq > MINVALUE){ strokeWeight(c.count/4); stroke(red, 40+c.count); if(c.a == w){ line(w.x,w.y, w.z, c.b.x*p, c.b.y*p, c.b.z*p); if(p > .95){ pushMatrix(); translate( c.b.x,c.b.y,c.b.z); rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); text(c.b.word+" ("+c.b.totFreq+")", 0,0,0); secondTier.put(c.b.word, c.b); popMatrix(); } } else{ line(w.x, w.y, w.z, c.a.x*p, c.a.y*p, c.a.z*p); if(p > .95){ pushMatrix(); translate(c.a.x,c.a.y,c.a.z); rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); noStroke(); text(c.a.word+" ("+c.a.totFreq+")", 0,0,0); secondTier.put(c.a.word, c.a); popMatrix(); } } } } } drawSecondTier(secondTier); } void drawSecondTier(HashMap words){ Iterator it; Connection c; Map.Entry me; String s, a, b; String alls[]; it = connections.entrySet().iterator(); while(it.hasNext()){ me = (Map.Entry)it.next(); s = (String)me.getKey(); alls = s.split(","); a = alls[0]; b = alls[1]; if(words.containsKey(a)){ if(words.containsKey(b)){ c = (Connection) me.getValue(); strokeWeight(c.count/6); stroke(red, 20+c.count); line(c.a.x, c.a.y, c.a.z, c.b.x, c.b.y, c.b.z); } } } //recursively get all of the relations a,b, a, }