Target Ratio for Treemap?

491 views
Skip to first unread message

Adam Hisley

unread,
Feb 19, 2013, 1:49:31 PM2/19/13
to d3...@googlegroups.com
Hey everyone,

I'm implementing a d3.js treemap, and wanted to tweak the results of the squarify algorithm to try and control how my nodes end up rendering.  

According to the wiki (https://github.com/mbostock/d3/wiki/Treemap-Layout), squareness is "controlled via the target ratio," but this line links to what appears to be a non-existent anchor tag for explanation of the target ratio.

Can anyone give me a link or a quick explanation of how target ratio can be configured and how it affects the squarify algorithm?  I noticed that the zoomable treemap example at http://bost.ocks.org/mike/treemap/ sets the treemap's ratio directly using .ratio(height / width * 0.5 * (1 + Math.sqrt(5))) which is what led me down this path.  Also, will this approach work well with a sticky:false treemap?

Hopefully I'm not misunderstanding the usage of this ratio but I'm new to d3.js and wasn't able to find any more info on this topic.  Apologies if I missed something obvious.

-Adam

Marcus Crowley

unread,
Apr 8, 2014, 7:53:03 PM4/8/14
to d3...@googlegroups.com
I agree with Adam. Mike: The API docs are incomplete and don't detail the operation of the ratio operator. See https://github.com/mbostock/d3/wiki/Treemap-Layout#ratio

MC

Andrew Howe

unread,
Feb 23, 2017, 2:13:12 PM2/23/17
to d3-js
I agree the API is totally unclear, but after trying to hack results using d3 4.0 I appear to have had some success adjusting the ratio using this:
var treemap = d3.treemap()
  .size([347, 347])
  .padding(2)
  .paddingTop(20)
  .round(true)
  .tile(d3.treemapSquarify.ratio(2.5));
 
It appears that you're defining just one side of the 1:X ratio -- as 1 seems to yield near-to-squares. 
Reply all
Reply to author
Forward
0 new messages