Tuesday, April 13, 2010

NodeLinkTreeLayout - scaling an n-tree from the child up

I have been looking into revamping the Actionscript 3.0 layout named "NodeLinkTreeLayout".  It is simply given a DataList of nodes, identifies the root node, and populates the tree based upon the order of the children of the root, recursively adding children as it paints.

Recently I realized it doesn't paint from the root "down", but paints from the root node's first child "out".
So I'm sharing this and documenting my struggles; perhaps I'll find ways in which my own mental inefficiencies will be documented and captured.  There is certainly an element of hubris in posting at all - I'm hoping that it will be balanced by the fact that these posts will tend to document my failures as well as discoveries I make.

Here are things I've discovered in the class:

1. The edge DataList is only used in setting the rendering of the edges (directed).
It does not affect the order or position of the parent-child relationship in the tree.
I am keeping a separate array of the edges, as well as the edge's inversion state.
The edges are accessible through the visualization.data.edges DataList object.

2. Depth is an unsigned integer.
The depth of the root node is 0.
The depth of a child of the root node is 1.
The depth of a parent of the root node is -1 ... a problem for unsigned integers.

3. Node positions are based upon their effective distance from the first child of the root node.
This node's breadth doesn't really change.
Adding another child to the root node moves the root node the "_dspace".
It also moves the new child node two "_dspaces" away from the first root node.

4. Prelim is distance from the reference wall to where the node "ought" to be.
The reference wall is the wall against which you're painting.
If your using the default orientation (Top to Bottom) this is the left wall
Thus the prelim in this case would be the distance from the left wall.
5. Mod is distance between the prelim and the assumed midpoint of the parent node.
Prelim effectively points to the middle between all children of the parent
Mod is the offset from that middle.

No comments:

Post a Comment