Squarify is a Processing library that implements the squarify treemap layout algorithm. It divides an area into rectangles whose areas is sized based on a set of values, the rectangles being optimized to be as squary as possible.
Open up the Contributions Manager in the Processing IDE. Search for
Squarify and install the library.
Go to the releases page of this repo and download the .zip file from there. Unzip it and move it into the libraries folder of your Processing sketches.
You can find a fully working example called
UsingSquarify.pde in this repository.
Squarify s = new Squarify(values, CANVAS_ORIGIN_X, CANVAS_ORIGIN_Y, CANVAS_WIDTH, CANVAS_HEIGHT); ArrayList<SquarifiedRect> rects = s.getRects();
Instantiating a Squarify object with values and canvas geometry will give you access to a list of
These objects contain each rectangle geomtry data:
xis the top left x coordinate
yis the top left y coordinate
dxis the rectangle width
dyis the rectangle height
As a result, to draw a rectangle on your processing sketch, you can do:
SquarifiedRect r = rects.get(0); // Draws first rect in the list rect(r.getX(), r.getY(), r.getDx(), r.getDy());