user623892
user623892

Reputation:

Organizational tree drawing algorithm

I'm implementing an organizational tree graph - top to bottom or left to right - in C# and looking for a good algorithm to draw the tree. Any recommendations?

Thanks

Update

I finally had some time to work on it so ended up writing my own library to store and draw the tree by creating a custom panel, not sure if I followed a particular algorithm, I just wrote my own - back to pen and paper + time :)

I intend to make it open source on codeplex once I'm done adding all the features I wanted. Will post another update once it's up on codeplex.

Thanks

Upvotes: 3

Views: 4013

Answers (5)

Adolfo Perez
Adolfo Perez

Reputation: 2874

This is the best article I have found on this subject : A Graph Tree Drawing Control For wpf

It has a WPF and Silverlight version. It implements John Q. Walker II algorithm for positioning nodes and works perfectly. I still have to work on the rotation so it can be displayed left to right. Currently is only top to bottom.

You can find more info on the algorithm here: http://www.cs.unc.edu/techreports/89-034.pdf

Upvotes: 0

Keith Adler
Keith Adler

Reputation: 21178

One option you might consider is to simply use the TreeView control and transforms to make it appear the way you want it to.

http://forums.silverlight.net/forums/p/149065/334501.aspx

Honestly, I think using a third-party component would be a much better "algorithm" rather than re-inventing. If you should consider, there are several products that offer this capability for SL:

http://www.nwoods.com/components/silverlight-wpf/goxam-overview.htm http://www.mindfusion.eu/diagramlite.html http://www.syncfusion.com/products/user-interface-edition/silverlight/diagram http://www.yworks.com/en/products_yfilessilverlight_about.html

Upvotes: 0

Eli
Eli

Reputation: 21

A cool visualization you can use instead of drawing the tree is a Squarified Treemap. It's a view of a hierarchical data structure that shows the leaf nodes' relative sizes when packed into a rectangle. Because it is drawn recursively, two leaf nodes will be drawn different sizes if they are in different size subtrees of the hierarchy.

http://en.wikipedia.org/wiki/Treemapping

Upvotes: 1

Bart Kiers
Bart Kiers

Reputation: 170188

I think the keyword you're looking for is Force-based algorithms.

Upvotes: 2

fixagon
fixagon

Reputation: 5566

Also possible if you use just standart Silverlight. Use an ItemsControl (which has as ContainerTemplate a StackPanel, so you can display the items the vertically or horizontally) in combination with HierarchicalDataTemplate. The way to display the items you set with ItemTemplate and it should work directly

Upvotes: 1

Related Questions