3

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

5 Answers5

2

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

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
1

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

fixagon
  • 5,506
  • 22
  • 26
1

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

Eli
  • 21
  • 1
0

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

Adolfo Perez
  • 2,834
  • 4
  • 41
  • 61
0

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

Keith Adler
  • 20,880
  • 28
  • 119
  • 189