Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Vertical Distribution of Nodes (Read 1712 times)
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Vertical Distribution of Nodes
Jun 25th, 2009 at 3:14pm
Print Post  
Hi Stoyan,

This post is with reference to the following link.

http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=post;num=1245428165;t...

As I feel Tree Layout can arrange itself when it has some childs but in case of unconnected nodes there are child but they are disconnected so how could we arrange them(Please correct me if I am wrong).

So for that I felt there could be an alternative solution for the same, we can

1) Take the entire node's Top and Left position and store them in a array.
2) Sort Top position values and find the smallest difference.
3) Set all node's Top position such that next index value should have that minimum difference.
4) Instead of old Bounds set these new Bounds to node where only y position differs from the old bounds.

This could be an alternative way. If it is correct can you please help us to solve this problem? It would be better if you provide some line of codes because I have some doubt to save Old Bounds and set the New Bounds.

Thanks,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Vertical Distribution of Nodes
Reply #1 - Jun 26th, 2009 at 6:42am
Print Post  
It shoudl look like this

Code
Select All
private void DistributeNodesHorizontally(float offset)
{
	List<DiagramNode> nodes = new List<DiagramNode>();
	foreach (DiagramNode node in diagram.Nodes)
		nodes.Add(node);
	nodes.Sort(new NodeXComparer());

	for (int i = 1; i < nodes.Count; ++i)
	{
		double prevRight = nodes[i - 1].Bounds.Right;
		double currLeft = prevRight + offset;
		nodes[i].Move(currLeft, nodes[i].Bounds.Y);
	}
}

class NodeXComparer : IComparer<DiagramNode>
{
	public int Compare(DiagramNode node1, DiagramNode node2)
	{
		if (node1.Bounds.X < node2.Bounds.X)
			return -1;

		if (node1.Bounds.X > node2.Bounds.X)
			return 1;

		return 0;
	}
}
 



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