class Row { String label; float[] data; float max; Row(String label, float expedia, float hotelGuides, float travelYahoo, float travelocity, float tripAdvisor) { this.label = label; this.data = new float[5]; this.data[0] = expedia; this.data[1] = hotelGuides; this.data[2] = travelYahoo; this.data[3] = travelocity; this.data[4] = tripAdvisor; this.max = 0; for (int i = 0; i < 5; i++) if (this.data[i] > max) max = this.data[i]; } }; ArrayList data; PFont sansFont; int grey, highlight, black; // colors final int LABELWIDTH = 150; // width of row label final int COLWIDTH = 75; // width of columns final int LINEWIDTH = 470; // width of line to draw under each row final int ROWHEIGHT = 22; // height of each row final float MINLABEL = 0.2; // minimum size of circle for drawing a label final int LABELSIZE = 10; // font size of labels on circles final int CIRCLESCALE = 4000; // scale the size of the circles void setup() { data = new ArrayList(); data.add(new Row("[x] hotel", 0.02154, 0.00903, 0.35186, 0.16603, 0.45155)); data.add(new Row("[x] hotel [x]", 0.00000, 0.00000, 0.14872, 0.26750, 0.58378)); data.add(new Row("[x] inn [x]", 0.03185, 0.00000, 0.00000, 0.24957, 0.71859)); data.add(new Row("hotel [x]", 0.01385, 0.02769, 0.31154, 0.23692, 0.41000)); data.add(new Row("hotel in [x]", 0.03216, 0.00000, 0.53631, 0.19191, 0.23963)); data.add(new Row("[x] resort", 0.00000, 0.00000, 0.01746, 0.18254, 0.80000)); data.add(new Row("[x] resort [x]", 0.00000, 0.00000, 0.00000, 0.24522, 0.75478)); data.add(new Row("[x] ticket", 0.00000, 0.84807, 0.00000, 0.15193, 0.00000)); data.add(new Row("[x] restaurant", 0.00000, 0.00000, 0.00000, 0.54745, 0.45255)); data.add(new Row("[x] motel", 0.00000, 0.00000, 0.72564, 0.11282, 0.16154)); data.add(new Row("map of [x]", 0.00000, 0.00000, 0.00000, 0.62821, 0.37179)); data.add(new Row("[x] map", 0.00000, 0.00000, 0.03183, 0.50663, 0.46154)); data.add(new Row("[x] inn", 0.02727, 0.00606, 0.00000, 0.26667, 0.70000)); data.add(new Row("[x] vacation", 0.00635, 0.15873, 0.02222, 0.22222, 0.59048)); data.add(new Row("trip [x]", 0.00000, 0.00000, 0.00000, 0.00000, 1.00000)); data.add(new Row("[x] restaurant [x]", 0.00000, 0.00000, 0.00000, 0.45714, 0.54286)); data.add(new Row("things to do in [x]", 0.00000, 0.00000, 0.00000, 0.41818, 0.58182)); data.add(new Row("[x] hotel in [x] [x]", 0.00000, 0.00000, 0.37089, 0.00000, 0.62911)); data.add(new Row("best [x]", 0.04348, 0.00000, 0.04831, 0.29469, 0.61353)); data.add(new Row("motel [x]", 0.00000, 0.00000, 0.70732, 0.08780, 0.20488)); data.add(new Row("cheap [x]", 0.25824, 0.00000, 0.04396, 0.47802, 0.21978)); data.add(new Row("[x] attraction", 0.00000, 0.00000, 0.00000, 0.34254, 0.65746)); data.add(new Row("[x] suite [x]", 0.00000, 0.00000, 0.00000, 0.00000, 1.00000)); data.add(new Row("[x] lodging", 0.00000, 0.00000, 0.59639, 0.10843, 0.29518)); data.add(new Row("[x] travel", 0.06627, 0.19277, 0.00000, 0.64458, 0.09639)); // drawing setup size(520, 620); smooth(); noLoop(); // font setup sansFont = createFont("FreeSans", 12); textFont(sansFont); // adjust colours background(255); grey = color(90); highlight = color(130); black = color(0); } void draw() { translate(0, 30); textAlign(CENTER); fill(black); text("Expedia", LABELWIDTH - 50, 0, 100, 14); text("Travelocity", LABELWIDTH + 1 * COLWIDTH - 50, -15, 100, 14); text("Hotel-Guides", LABELWIDTH + 2 * COLWIDTH - 50, 0, 100, 14); text("Yahoo! Travel", LABELWIDTH + 3 * COLWIDTH - 50, -15, 100, 14); text("TripAdvisor", LABELWIDTH + 4 * COLWIDTH - 50, 0, 100, 14); translate(0, 30); Row row = null; for (int i = 0; i < data.size(); i++) { row = (Row)data.get(i); fill(black); textAlign(LEFT); text(row.label, 10, 0, LABELWIDTH, 12); // draw a light grey line below each row stroke(1.0, 0.0, 0.55); strokeWeight(0.2); line(0, 5, LINEWIDTH, 5); noStroke(); // save the current origin pushMatrix(); translate(LABELWIDTH, -6); for (int col = 0; col < 5; col++) { float val = row.data[col]; if (val > 0.0) { float r = pow((CIRCLESCALE * val / PI), 0.5); // draw the shape fill(val == row.max ? highlight : grey); ellipse(-r / 2, -r / 2, r, r); if (val > MINLABEL) { textSize(LABELSIZE); fill(black); text(String.format("%.1f%%", (100 * val)), 4 - r / 2, 0); } } // move over a row translate(COLWIDTH, 0); } // restore the origin popMatrix(); translate(0, ROWHEIGHT); } }