Description
I love the simplicity and speed of d3's treemap -- I have several thousand nodes and it is far faster than jit or Google treemap -- but I found myself really preferring the binary tree layout algorithm, instead of the squarified algorithm, for my data. You can see an example of it in Google's treemap visualization: https://developers.google.com/chart/interactive/docs/gallery/treemap (here's a screenshot of it with my data, to give you an idea: http://i.imgur.com/clVB5.png ).
I've implemented this algorithm for d3 (screenshot of that [the gradients are unrelated]: http://i.imgur.com/3YIVs.png ), and want to contribute the code back to d3. However, after several intense days of getting it working, my brain is a bit fried and I want/need to move on to other parts of my project to get it done. Thus, it is not complete. The layout algorithm basically works, but here's what's left to do:
- More testing with various datasets.
- It doesn't utilize the optional rounding function.
- Sticky mode doesn't work. stickify() is left unmodified and will surely break horribly if you try to use it.
- There's no way to select between the squarified and binary tree layouts -- I simply replaced squarify() with binarytree().
- The ratio option is no longer used but is still there in a vestigial form.
- I ported the change into d3.v2.js but none of the other files built by the Makefile (most notably, d3.v2.min.js) are updated.
- One last thing I just noticed: The Google algorithm seems to alternate vertical/horizontal at each step of its descent, but my algorithm picks the dimension that is currently larger and chooses that dimension to cut in half. This keeps the aspect ratio of the individual rectangles more square-like, but also results in some rows of nearly-identical repeated shapes, while Google's is more random looking. Maybe it could be configurable to work either way?
I apologize for the incomplete code dump, but I figured it was better than keeping it to myself entirely. Hopefully someone can make use of it, and just maybe, finish it up and get it incorporated into d3 proper.
Here's the branch (just one new commit): https://github.com/mackstann/d3/tree/binarytree_treemap