Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a note about node depth in the treemap documentation #80

Closed
ResidentMario opened this issue Feb 11, 2017 · 1 comment
Closed

Make a note about node depth in the treemap documentation #80

ResidentMario opened this issue Feb 11, 2017 · 1 comment

Comments

@ResidentMario
Copy link

I ran into an issue involving an unresponsive treemap which kept giving me garbage NaN values, even though my value properties were filled out correctly. I traced it to this call in positionNode in the D3 source:

function positionNode(node) {
    var p = paddingStack[node.depth],
    ...

paddingStack is a list which gets initialized with length 1, and I was trying to run treemap on a node that I had indexed out of my original root node which had a depth property of 1.

Once I figured this issue out, the fix was easy:

new_root.eachBefore(function(node) { node.depth--; })

I think this requirement (that the first node should have a depth of 0, and every child thereafter should increment by 1) should be noted in the docs as a prerequisite for running treemap(node). In reading them I thought that the depth property was just syntactic sugar, and that the only thing that mattered was having value properties correctly labelled...I hadn't realized it was used this way in layout!

@mbostock
Copy link
Member

That requirement is already noted in that treemap takes a root node, not any node. Per the README:

Before you can compute a hierarchical layout, you need a root node.

And:

node.depth - zero for the root node, and increasing by one for each descendant generation.

You can use node.copy to create a new root from an existing node’s subtree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants