Well, we're getting closer...
It seems that max depth is actually representative of the maximum
*horizontal* depth of a single set of linked nodes, not related to
what the *height* of the effective tree will be. Looking at the
source for the tree layout, it seems that the necessary calculation
logic is probably in there, just masked in some fairly opaque variable
names like mod, vim, vop, sop, sip, sim, and som. Sorta like a Dr.
Seuss book... ;-)
If anyone can shed some insight on the internals of the layout
algorithm, I'm sure I can get there. Ultimately, my end goal can be
stated as simply resizing the layout container (parent SVG element)
and re-triggering layout so that each node has a horizontal space
allocation of a fixed amount (nH) and a vertical space allocation of a
fixed amount (nV).
On Sep 12, 12:53 am, Justin Donaldson <
donald...@bigml.com> wrote:
> True, but I'm pretty sure this isn't Rick's problem. He wants the graph
> dimensions to be dynamic, so that it can change depending on how many nodes
> are in the network. This is probably for legibility reasons.
>
> I'd still recommend extracting some of the dimensions from the tree. E.g,
> get the max depth, and use it to help define a height.
>
> var tree = d3.layout.tree()
> .size([w, h])
> .separation(function(a, b) { return (a.parent == b.parent ? 1 : 2) /
> a.depth; });
>
> var nodes = tree.nodes(some_json);
> var max_depth = d3.max(nodes, function(x) { return x.depth;});
> var w = 960; // or, calculate the width based on the max branch width.
> var h = Math.max(max_depth*100, 500);
>
> Then, set the size to be some function of the max depth:
>
> var tree = d3.layout.tree()
> .size([w, h])...
>
> You can update the graph dimensions later on, but you'll need to completely
> recalculate the tree.
>
> Hope that helps,
> -Justin
>