explanation of d3.layout.tree algorithm?

62 views
Skip to first unread message

Sigfried

unread,
May 10, 2013, 7:00:28 PM5/10/13
to d3...@googlegroups.com
I'm trying to modify the tree layout to allow me to merge certain nodes -- so the tree is no longer a tree, but a cyclic graph, but it still looks mostly like a tree.  I can fake it by making nodes I want to merge draw in the same location as in the attached image, but there are a bunch of problems with this approach.  The tree layout, quite reasonably, doesn't like it when nodes show up as the children of more than one parent.  If I could understand the tree algorithm, I might be able to modify it, or at least get a sense of how feasible it would be to write my own weird version from scratch.  But that is some tricky code.  I don't have a clue what it's doing.

Would anyone be willing to attempt any amount of explanation of what's happening there?  Or maybe throw in some helpful inline comments?

Thanks so much,
Sigfried


merged_nodes.tiff

Sigfried

unread,
May 24, 2013, 4:12:57 PM5/24/13
to d3...@googlegroups.com
I'm going to ask again.  With a specific problem this time:

How can I modify the position of the nodes in the tree layout?  The positioning code is buried so deep and even though the x and y values end up easily accessible, the size and x1/y1 values used to calculate them are hidden in closures, so, by the time I can fiddle with them, I have no access to the data that would allow me to do so intelligently.

The sensibile thing might just be to write my own implementation of the tree layout, but the code of D3's tree layout is so inscrutable to me, that I'm guessing it's a much harder problem than it looks like at first glance.  I'm sure whoever wrote it did so a long time ago, but any little hints at how it works would sure be appreciated.

Thanks!
Sigfried
Reply all
Reply to author
Forward
0 new messages