Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic TreeLayout Question (Read 1488 times)
kwenzel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Apr 5th, 2009
TreeLayout Question
Apr 5th, 2009 at 8:49pm
Print Post  
Using the TreeLayout class to arrange some diagram nodes and having some slight issues getting it "just right" and was hoping you could help!

Here is the code I'm currently using to arrange the nodes:

Quote:
private void AutoLayout(DiagramNode rootNode)
{
TreeLayout tl = new TreeLayout();
tl.Type = TreeLayoutType.Centered;
tl.LevelDistance = LAYOUT_DISTANCE; //10
tl.NodeDistance = LAYOUT_DISTANCE; //10
tl.Direction = TreeLayoutDirections.RightToLeft;
tl.LinkStyle = TreeLayoutLinkType.Rounded;
tl.IgnoreLinkDirection = true;
tl.Root = rootNode;
tl.Arrange(diagram);
tl.Arrange(diagram);
diagram.ResizeToFitItems(5F);
}


Though the tree levels go from left to right, where left is the leaf level, the children aren't vertically centered with their parents, instead the parent nodes, those to the immediate right, are shifted to the bottom of the page.

I would rather have the children nodes vertically aligned so they are centered to the left of their parent.

Is this possible? Is my explaination as clear as mud? Smiley

I can send a diagram if you wish!

Thanks,

Kris
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TreeLayout Question
Reply #1 - Apr 6th, 2009 at 8:58am
Print Post  
Hi Kris,

In that case parent nodes should be centered relatively to the total height of the area occupied by their child nodes. If you also want the parent to be aligned to some of the child nodes, this can happen only if its child nodes have the same height as shown below.

I hope that helps,
Stoyan

  
Back to top
 
IP Logged
 
kwenzel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Apr 5th, 2009
Re: TreeLayout Question
Reply #2 - Apr 11th, 2009 at 1:15am
Print Post  
Hi,
Thanks for the reply.  Though I understand what you are saying by vertically centering the childeren relative to the parent, I don't know whether I'm supposed to do this though my own layout code or use the built-in layout features of FlowChart.Net.

Can you provide me with a hint?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TreeLayout Question
Reply #3 - Apr 12th, 2009 at 9:40am
Print Post  
Hi,

If you need vertical centering for nodes of varying height, you could use the TreeLayout to create the initial layout, and then only fix the vertical positions of parent nodes. The order of child nodes is the same as the order of the parent's OutgoingLinks, so you can align each parent node to the Destination of the link that's in the middle of the parent's OutgoingLinks collection. E.g. after TreeLaytout.Arrange, iterate over diagram.Nodes, and for each node that has more than one outgoing link do this:

Code
Select All
DiagramLinkCollection outlinks = node.OutgoingLinks;
int childnum = outlinks.Count;
int m = childnum / 2;
float vcenter = childnum % 2 == 0 ?
	(VCenter(outlinks[m-1]) + VCenter(outlinks[m])) / 2 :
	VCenter(outlinks[m]);
RectangleF r = node.Bounds;
r.Y = vcenter - e.Height / 2;
node.Bounds = r;
 



where VCenter(DiagramLink) returns Bounds.Y + Bounds.Height / 2 for the link's Destination.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
kwenzel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Apr 5th, 2009
Re: TreeLayout Question
Reply #4 - Apr 12th, 2009 at 11:26am
Print Post  
Thanks Stoyan, I'll give it a shot sometime today after the holiday's festivities (Today is Easter in the US).

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint