import java.util.*; 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 wc = new HashMap(); boolean showNumber = false; //keep track of the frequency of the number used the most int gridInterval = 65; int PLOTX1, PLOTX2, PLOTY1, PLOTY2,LABELX, LABELY,DATAMIN, DATAMAX,XMIN, XMAX, XINTERVAL,YINTERVAL; int x, cstart, cend; int count=0; int maxFreq = 0; int startNdx = 0; int endNdx = 12; static int MINVALUE = 2; float littlex = (float)gridInterval; PFont font1; PFont font2; PFont font; color brown = #391E18; color must = #DA8312; color orange = #E13D18; color pink = #A9173C; color teal = #2A766A; color grey = #D6D6D6; color colors[] = {must, orange, pink, brown}; Integrator[] interpolators; 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[1]); font2 = loadFont(fontnames[4]); PLOTX1 = 120; PLOTX2 = width-60; PLOTY1 = 80; PLOTY2 = height-80; LABELX = 60; LABELY = height-40; DATAMIN = 0; DATAMAX = 500; XMIN = 0; XMAX = 100; XINTERVAL = 10; YINTERVAL = 100; size(910,715); background(255); frameRate(1000); //that is, as fast as possible textFont(font1, 12); this.transactions = loadTransactions("splxmldata.txt"); TransactionUtils.sortWords(wc); countWords(); } void draw(){ Iterator it; Word w; Map.Entry me; x = gridInterval; fill(255); noStroke(); background(255); boolean found = false; littlex = (float) gridInterval; int corrected; fill(0,200); textAlign(LEFT, CENTER); textFont(font2, 18); text("word frequency", gridInterval, gridInterval*9); textFont(font1, 12); fill(0,100); text("in religious text's titles", gridInterval, gridInterval*9+18); textAlign(CENTER, CENTER); drawFreqMap(); drawCats(); cstart = startNdx%count; if(cstart < 0){ cstart = count + cstart; } cend = endNdx%count; if(cend < 0){ cend = count + cend; } for(int j= startNdx-6; j <= endNdx-6; j++){ corrected = j%count; if(corrected < 0){ corrected = count + corrected; } w = (Word) sortedWords.get(corrected); printValues(w); x += gridInterval; } } void printValues(Word w){ noStroke(); int y, i, m, mc; Category c; float dew, cSize, cAlpha; String curCoords; //alpha depends on checkout frequency //barsize depends on uniquness between categories m = 0; mc = 0; //iterate through dewCodes for (i= 0; i<4; i++){ if(w.categories.containsKey(i)){ c = (Category) w.categories.get(i); if(c.catFreq > m){ m = c.catFreq; mc = i; } y = gridInterval*(i+2); cSize = gridInterval/1.25* ((float)c.catFreq/(float)w.totFreq + (float)w.totFreq/(float)maxFreq); cAlpha = 150*(float)c.checkCatFreq/(float)w.checkFreq+50; fill (colors[i], cAlpha); ellipse(x,y,cSize, cSize); if(showNumber == true){ fill (colors[i], 255); text(c.catFreq,x,y); } } } strokeWeight(5); stroke(0); //fill(colors[mc], 250); if(sortedWords.indexOf(w) == cstart){ fill(0, 255); }else{ fill(0, 100); } text(w.word,x,gridInterval*6); if(showNumber == true){ //text(w.totFreq,x,gridInterval*6+20); } } 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 drawCats(){ textAlign(RIGHT, CENTER); noStroke(); float inty = gridInterval*9; int startingx = gridInterval * 13; fill(colors[0]); ellipse(startingx,inty, 10, 10); fill(0, 100); text("christian theology (230)", startingx-15, inty); fill(colors[1]); ellipse(startingx, inty+15, 10, 10); fill(0, 100); text("buddhism (294.3)",startingx-15, inty+15); fill(colors[2]); ellipse(startingx, inty+30, 10, 10); fill(0, 100); text("hinduism (294.5)",startingx-15, inty+30); fill(colors[3]); ellipse(startingx, inty+45, 10, 10); fill(0, 100); text("islam, bábism & bahá'í (297)", startingx-15, inty+45); textAlign(CENTER, CENTER); } void drawFreqMap(){ Word w; int corrected, ccstart, ccend; float maxWidth = (float) gridInterval * 12.0; float smallInterval = maxWidth/(float)count; strokeWeight(2); float startingx = gridInterval; ccstart = cstart - 6; ccend = cend - 6; if(ccstart < 0){ ccstart = count +ccstart; } if(ccend < 0){ ccend = count +ccend; } for(int j=count/2 + cstart; j < count+ count/2+cstart+1;j++){ corrected = j%count; // corrected = j; ///lead to crash. if(corrected < 0){ corrected = count + corrected; } w = (Word) sortedWords.get(corrected); if(corrected == cstart){ stroke(0,255); fill(0); textAlign(CENTER,CENTER); text(w.totFreq+" total occurances of '"+w.word+"'", startingx, gridInterval*8+10 ); }else{ if((corrected > ccstart && corrected <= ccend) || (corrected > ccstart && ccstart > ccend) || (corrected < ccend && ccstart > ccend)){ stroke(0,100); }else{ stroke(0,50); } } line(startingx,gridInterval*8, startingx, gridInterval*8-(gridInterval*w.totFreq/maxFreq)); startingx += smallInterval; } }