// sketch that tests Ben Fry’s Treemap library // Data is hardcoded but taken from real queries to the database. import treemap.*; // The treemap object Treemap TheTreemap; void setup( ) { size(800, 600) ; smooth( ); strokeWeight(0.25f) ; PFont font = createFont("Sans Serif", 23) ; textFont(font) ; //A Collection of mappable objects TheMapModel mapData = new TheMapModel( ); // Hard coded values that will determine the area of each square mapData.addItem("Pumpkin",285); mapData.addItem("Tomato",159); mapData.addItem("Avocado",8); mapData.addItem("Cucumber",9); mapData.addItem("Olive",232); mapData.addItem("Eggplant",13); mapData.addItem("Pepper",259); mapData.addItem("Zuccini",10); mapData.finishAdd(); // Creating a treemap, here is where the layout is calculated. TheTreemap = new Treemap(mapData, 0, 0, width, height) ; // Different algorithms can be used: // MapLayout algorithm = new SliceLayout(); // MapLayout algorithm = new StripTreemap(); // MapLayout algorithm = new SquarifiedLayout(); MapLayout algorithm = new PivotBySplitSize(); // MapLayout algorithm = new PivotBySize(); // MapLayout algorithm = new PivotByMiddle(); // MapLayout algorithm = new OrderedTreemap(); // MapLayout algorithm = new BinaryTreeLayout(); // Setting the layout. TheTreemap.setLayout(algorithm); TheTreemap.updateLayout(); // Run draw( ) only once. noLoop( ); } void draw( ) { background(255) ; TheTreemap.draw( ); }