Blog Home  Home Feed your aggregator (RSS 2.0)  
Debugging trees - Manuel Abadia's ASP.NET stuff
 
# Saturday, December 2, 2006

I couldn’t resist to improve StructsViz in order to add support for trees. Even if everybody has his own tree implementation, we can come up with a common agreement:

A tree is a collection of nodes, where each node has zero or more child nodes. Each node has zero or one parent. The only node that doesn’t have a parent is the root node.

So based on the previous definition, I have defined this interface that is mandatory to implement in order to visualize a tree node in StructsViz:

public interface ITreeNode<T>

{

    T Value { get; set; }

    ITreeNode<T> Parent { get; set; }

    bool HasChildren { get; }

    ICollection<ITreeNode<T>> Children { get; }

}

 

I think that any tree node implementation can easily implement this interface.

With that interface implemented, StructsViz will be able to draw your tree node.

I have been playing a bit with automatic layout positioning for trees, and with different kind of connections:





 

The pictures show debug information of the subtree areas needed to position the elements properly using a recursive algorithm. For example, the rectangle labeled as ST 2, is the subtree area for node 2, and it is calculated based on the ST 6 and ST 7 (subtree areas for node 6 and 7 respectively). With ST 1, ST 2 and ST 3, we can properly position node 0.

I’m giving the final touches to this and it will be included in the next StructsViz version.

Saturday, December 2, 2006 5:17:59 PM (Romance Standard Time, UTC+01:00)  #    Comments [2]   ASP.NET | Microsoft .NET Framework  | 
Copyright © 2019 Manuel Abadia. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.