Looking at the source code of Ben's
treemap package, it looks like you cannot change the layout of
Treemap directly. But it is a fairly simple job to create a customisable version of the class:
// Treemap with customisable layout. Based on Ben Fry's TreeMap.java with
// very minor modifications by Jo Wood to allow substitution of alternative MapLayouts.
class CustomTreemap
{
private MapModel model;
private MapLayout algorithm;
private Rect bounds;
public CustomTreemap(MapModel model, MapLayout algorithm, double x, double y, double w, double h) {
this.model = model;
this.algorithm = algorithm;
updateLayout(x, y, w, h);
}
public void setLayout(MapLayout algorithm) {
this.algorithm = algorithm;
}
public void updateLayout() {
algorithm.layout(model, bounds);
}
public void updateLayout(double x, double y, double w, double h) {
bounds = new Rect(x, y, w, h);
updateLayout();
}
public void draw() {
Mappable[] items = model.getItems();
for (int i = 0; i < items.length; i++) {
items[i].draw();
}
}
}
If you create a Processing tab with the code above in it, you can then create a
CustomTreemap instead of a
TreeMap, so for example, using Ben's example from the book, the line
map = new CustomTreemap(mapData, new SquarifiedLayout(), 0, 0, width, height);
would create a treemap using the squarified layout instead of the default pivot layout:
The layouts available using this approach can be found at the top of
MapLayout page (BinaryTreeLayout, OrderedTreeMap etc.).
If you want more sophisticated control over treemap layout and appearance you may be interested in my own
treeMappa library for Processing. This has a range of 8 treemap layouts available including the ability to alter the layout at each level in your tree hierarchy.
Below is an example from one of the sketches included in the 'examples' folder of the library that shows zooming into a deep hierarchy of an ontology dataset of many thousands of categories:
Jo.