Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Tree Layout and moving nodes (Read 3527 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Tree Layout and moving nodes
Feb 9th, 2011 at 2:45pm
Print Post  
Hi Stoyo

I have few items arranged using Tree Layout.
Once the nodes are arranged, user can move the individual nodes.

Also, if user want to move some node and all its childs he needs to select all those items (either programatically or individual node - multiple selection). Selecting all child items move all items relative to the first node.

How one can move all child nodes when parent node is moved (relative to the parent node) but the selection (adjustment handle) should not be visible for child nodes.

I tried to lock all child nodes and make selection in node modifing event. Locking the child still display the adjustment handle (when node is selected programatically ) but doesn't move the programatically selected nodes ( no matter whether node is locked or not ).

Regards
Rajesh

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Tree Layout and moving nodes
Reply #1 - Feb 10th, 2011 at 7:21am
Print Post  
Hi Rajesh,

You could handle NodeModifying to update the child node positions to move with the same offset as the parent, or if you won't show very large trees you can rearrange the branch under the moved node:

Code
Select All
private void OnNodeModifying(object sender, NodeValidationEventArgs e)
{
	var layout = new TreeLayout
	{
		 KeepRootPosition = true,
		 Root = e.Node
	 };
	layout.Arrange(diagram);
} 



Regards,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Tree Layout and moving nodes
Reply #2 - Feb 10th, 2011 at 7:41am
Print Post  
Hi Stoyo

Thanks for the reply. With the code provided when I try to reposition the nodes it works properly when node the moved horizontally. Also links of child nodes are moved relatived and the node for which move operation is triggered its incoming link changes.

Moving the node vertically ( up or down) nodes are moved properly but links of child nodes in hierachy also gets updated. Expected thing is only incoming link for top most node (which is assinged as a root in the code) gets updated.  For child node link displayed are going up from bottom anchor point and then coming again downside ( The behavior is tested with cascading lines).

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Tree Layout and moving nodes
Reply #3 - Feb 10th, 2011 at 8:05am
Print Post  
Are you using the same settings as the initial layout? This seems to work ok for cascading links:

Code
Select All
var layout = new TreeLayout
{
	KeepRootPosition = true,
	Root = e.Node,
	LinkStyle = TreeLayoutLinkType.Cascading3
}; 



Regards,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Tree Layout and moving nodes
Reply #4 - Feb 11th, 2011 at 12:04pm
Print Post  
Hi Stoyo

Thanks. Its working now.

And another issue popup/observed -

First I moved some intermediate node from tree displayed which increase the default distance between parent and child node and then tried to moved the one of the parent node and that causes to arrange all child nodes.

How one can allow moving nodes but their relative distance user placed remain same.

With above, what I need to do is first move the parent and its child gets moved automatically and then move the child items one level down at a time (It is not possible that user selects any level item radomly for moving and moving that node re-position all child node relative to selected node ).

-Rajesh


-Rajesh
  
Back to top
WWW  
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Tree Layout and moving nodes
Reply #5 - Feb 22nd, 2011 at 5:23am
Print Post  
Hi Stoyo

Any updates on same ?

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Tree Layout and moving nodes
Reply #6 - Feb 22nd, 2011 at 9:23am
Print Post  
Hi Rajesh,

You should create new posts when you have something to add, edits don't appear in the 'most recent' list. Try this:

Code
Select All
private Dictionary<DiagramNode, Rect> childRects;

private void OnNodeModifying(object sender, NodeValidationEventArgs e)
{
	if (childRects == null)
	{
		childRects = new Dictionary<DiagramNode, Rect>();
		var children = new List<DiagramNode>();
		GetChildren(e.Node, children);
		foreach (var node in children)
			childRects[node] = node.Bounds;
	}

	foreach (var node in childRects.Keys)
	{
		var rect = childRects[node];
		rect.X += diagram.Interaction.DeltaX;
		rect.Y += diagram.Interaction.DeltaY;
		node.Bounds = rect;
	}
}

private void OnNodeModified(object sender, NodeEventArgs e)
{
	childRects = null;
}

void GetChildren(DiagramNode root, List<DiagramNode> children)
{
	foreach (var link in root.OutgoingLinks)
	{
		children.Add(link.Destination);
		GetChildren(link.Destination, children);
	}
} 



You will have to extend the code to offset link control points if your links have more than one segment.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint