// Sketch that creates a treemap of treemaps. // It uses hardcoded vegetable data from the database. import treemap.*; // list of item arrays ArrayList ItemArrayList; ArrayList TreeMapList; Treemap RootTreeMap; // Root treemap array TheMapModel BigTreeModel; void setup( ) { size(800, 600) ; smooth( ); strokeWeight(0.25f) ; PFont font = createFont("Sans Serif", 28) ; textFont(font) ; colorMode(HSB,360,100,100); TreeMapList = new ArrayList(); BigTreeModel = new TheMapModel( ); ItemArrayList = new ArrayList(); for (int k =0; k<8; k++){ ItemArrayList.add( new TheMapModel( )); } /////////////////////////////////////////////////////////////// // filling the array with vegetable data: // january 2009 data // The constructor receives a label, size and a color in HSV. TheMapModel TempMap = new TheMapModel(); // Adding Items to each of the treemaps sequentially // bullbs TempMap = (TheMapModel) ItemArrayList.get(0); TempMap.addItem("Onion",44, color(0,80,100)); TempMap.addItem("Garlic",58, color(0,80,90)); TempMap.finishAdd(); BigTreeModel.addItem("Bullbs",TempMap.GetItemsSum()); // flowers TempMap = (TheMapModel) ItemArrayList.get(1); TempMap.addItem("Broccoli",9, color(45,80,100)); TempMap.addItem("Cauliflower",7, color(45,80,90)); TempMap.addItem("Artichoke",13, color(45,80,80)); TempMap.finishAdd(); BigTreeModel.addItem("Flowers",TempMap.GetItemsSum()); // fruits TempMap = (TheMapModel) ItemArrayList.get(2); TempMap.addItem("Pumpkin",285, color(90,80,100)); TempMap.addItem("Tomato",159, color(90,80,95)); TempMap.addItem("Avocado",8, color(90,80,90)); TempMap.addItem("Cucumber",9, color(90,80,85)); TempMap.addItem("Olive",232, color(90,80,80)); TempMap.addItem("Eggplant",13, color(90,80,75)); TempMap.addItem("Pepper",259, color(90,80,70)); TempMap.addItem("Zuccini",10, color(90,80,65)); TempMap.finishAdd(); BigTreeModel.addItem("Fruits",TempMap.GetItemsSum()); // roots TempMap = (TheMapModel) ItemArrayList.get(3); TempMap.addItem("Potato",444, color(135,80,100)); TempMap.addItem("Carrot",84, color(135,80,90)); TempMap.addItem("Radish",17, color(135,80,80)); TempMap.finishAdd(); BigTreeModel.addItem("Roots",TempMap.GetItemsSum()); // stems TempMap = (TheMapModel) ItemArrayList.get(4); TempMap.addItem("Celery",3, color(180,80,100)); TempMap.addItem("Asparagous",4, color(180,80,90)); TempMap.finishAdd(); BigTreeModel.addItem("Stems",TempMap.GetItemsSum()); // seeds TempMap = (TheMapModel) ItemArrayList.get(5); TempMap.addItem("Peanut",184, color(225,80,100)); TempMap.addItem("Lentil",18, color(225,80,90)); TempMap.addItem("Corn",148, color(225,80,80)); TempMap.addItem("Bean",286, color(225,80,70)); TempMap.finishAdd(); BigTreeModel.addItem("Seeds",TempMap.GetItemsSum()); // fungi TempMap = (TheMapModel) ItemArrayList.get(6); TempMap.addItem("Mushroom",117, color(270,80,100)); TempMap.finishAdd(); BigTreeModel.addItem("Fungi",TempMap.GetItemsSum()); // leaves TempMap = (TheMapModel) ItemArrayList.get(7); TempMap.addItem("Cabbage",10, color(315,80,100)); TempMap.addItem("Spinash",4, color(315,80,90)); TempMap.finishAdd(); BigTreeModel.addItem("Leaves",TempMap.GetItemsSum()); BigTreeModel.finishAdd(); /////////////////////////////////////////////////////////// // Calculating the layout for the big one. RootTreeMap = new Treemap(BigTreeModel,0,0,width,height); MapLayout algorithm = new SquarifiedLayout(); RootTreeMap.setLayout(algorithm); RootTreeMap.updateLayout(); Mappable[] RootItems = BigTreeModel.getItems(); // Going through the 8 small treemaps for (int k =0; k<8; k++){ TempMap = (TheMapModel) ItemArrayList.get(k); TheItem elItem = (TheItem)RootItems[k]; // calculating the layout for the small treemaps TreeMapList.add(new Treemap(TempMap,elItem.x,elItem.y,elItem.w,elItem.h)); algorithm = new SquarifiedLayout(); ((Treemap) TreeMapList.get(k)).setLayout(algorithm); ((Treemap) TreeMapList.get(k)).updateLayout(); } // Any combination of algorithms on the two levels 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(); } void draw( ) { background(255) ; // Drawing each treemap for (int k =0; k<8; k++){ ((Treemap)TreeMapList.get(k)).draw( ); } // Plotting the labels TheMapModel TempMap = new TheMapModel(); for (int k =0; k<8; k++){ TempMap = (TheMapModel) ItemArrayList.get(k); Mappable[] items = TempMap.getItems(); for (int i = 0; i < items.length; i++) { ((TheItem) items[i]).label(); } } }