Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to auto arrange around a node (Read 3165 times)
karenm
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: Aug 6th, 2009
How to auto arrange around a node
Aug 6th, 2009 at 12:22am
Print Post  
Hello,

I have a diagram using a spring layout. I want to be able to move a node to a new position, have that node retain its position, then automatically layout the remaining nodes around it. Not all the other nodes are directly linked to the node that is moved, but all nodes are linked together. Is there a way to implement this behaviour?

I tried using IgnoreLayout, which keeps the moved node where it is, but then all the other nodes do their layout without any reference to the moved node, this doesn't look any good.

Can someone provide any tips for this?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to auto arrange around a node
Reply #1 - Aug 6th, 2009 at 9:21am
Print Post  
Hi,

Try this:

Code
Select All
private void diagram_NodeModified(object sender, NodeEventArgs e)
{
	ArrangeAround(e.Node);
}

private void ArrangeAround(DiagramNode node)
{
	node.LayoutTraits[SpringLayoutTraits.Frozen] = true;

	SpringLayout layout = new SpringLayout();
	layout.NodeDistance = 80;
	layout.SplitGraph = false;

	// use the layout animation methods instead of Arrange, but
	// do not call EndArrange because it applies MultipleGraphsPlacement
	// and offsets all nodes to the top-left of the diagram
	layout.BeginArrange(diagram, diagram.Items);
	layout.Iterate(0, 500);

	node.LayoutTraits.Remove(SpringLayoutTraits.Frozen);
}
 



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


I love YaBB 1G - SP1!

Posts: 6
Joined: Aug 6th, 2009
Re: How to auto arrange around a node
Reply #2 - Aug 7th, 2009 at 2:29am
Print Post  
Perfect!  Thanks. 

I also tried this in the NodeModifying event to see if I could have the nodes following each other around the screen while the selected node is dragged about (i.e. before I release the mouse), but this caused choppy diagram view updates - is there an easy way to do this efficiently (i.e. to have smooth screen updates)?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to auto arrange around a node
Reply #3 - Aug 7th, 2009 at 9:21am
Print Post  
In NodeModifying you could create the layout object, call BeginArrange and start a timer with a very small interval. In the timer event call Iterate with just a few iterations. You must also call the DiagramView.RecreateCacheImage method to refresh the cache image used while modifying items.

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