Automatic cluster sizing

210 views
Skip to first unread message

mrjogo

unread,
Sep 26, 2011, 1:46:57 PM9/26/11
to d3-js
Hi,

I'm using a cluster layout, and I'd like to size it automatically
based on the longest row and number of levels (ie, each node requires
a width of 10px and height of 20px, and the total size would adjust
accordingly). Right now, all I can think of is to generate the nodes
based on a size of [1,1], then walk through the cluster to find the
maximum row and total depth, and use that to multiply the (x, y)
values of the nodes. However, that seems like a big waste since
clearly D3 has already done something similar.

Any suggestions are appreciated.

Thanks,
Ruddick

Mike Bostock

unread,
Sep 26, 2011, 1:52:30 PM9/26/11
to d3...@googlegroups.com
Indeed, that's exactly what this code does:

https://github.com/mbostock/d3/blob/master/src/layout/cluster.js#L28-38

There's similar code for the tree layout, but it's a bit more
complicated due to the tidy algorithm:

https://github.com/mbostock/d3/blob/master/src/layout/tree.js#L110-123

This is a common feature request, and I'd like to support it. I think
we just need to decide what the right API should be for specifying the
layout's "size"; in this case, we want to specify a fixed node size
rather than the size for the entire layout. For example, one option
might be to set the layout's size to null, which would result in each
node being sized as 1x1. Then, you could scale this to the desired
size when displaying the layout.

Mike

Mike Bostock

unread,
Sep 26, 2011, 4:29:34 PM9/26/11
to d3...@googlegroups.com
> So, just to confirm, those extents variables aren't exposed right now,
> correct?

Correct, but it'd be reasonable to add one or more method to
d3.layout.hierarchy to return the extent of the tree.

Mike

mrjogo

unread,
Sep 26, 2011, 4:25:34 PM9/26/11
to d3-js

On Sep 26, 10:52 am, Mike Bostock <mbost...@cs.stanford.edu> wrote:
> Indeed, that's exactly what this code does:
>
>  https://github.com/mbostock/d3/blob/master/src/layout/cluster.js#L28-38
>

So, just to confirm, those extents variables aren't exposed right now,
correct?

>
> This is a common feature request, and I'd like to support it. I think
> we just need to decide what the right API should be for specifying the
> layout's "size"; in this case, we want to specify a fixed node size
> rather than the size for the entire layout. For example, one option
> might be to set the layout's size to null, which would result in each
> node being sized as 1x1. Then, you could scale this to the desired
> size when displaying the layout.

A few options come to mind. One is as you suggest. Alternatively,
there could be a second cluster method (nodeSize, or somesuch) that
takes the size you'd like each node to be. That could also work with
the current size method to define maximum dimensions (I'm not sure if
this confuses the function of size() too much). Another option would
be just to have getters for the extents variables. I think any of
these would satisfy most cases, albeit to varying degrees of
automagicness.

Thanks,
Ruddick
Reply all
Reply to author
Forward
0 new messages