Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Layout nodes inside a ContainerNode? (Read 5804 times)
AnthonyBrien
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Feb 5th, 2008
Layout nodes inside a ContainerNode?
Feb 5th, 2008 at 8:03pm
Print Post  
Is it possible to Layout the nodes inside a ContainerNode? The Layout.Arrange method only seems to take a diagram as a parameter.

I guess I could reconstruct the embedded diagram separately, Arrange the layout and then copy the resulting positions to my nested nodes, but I wondered if there was a simpler method.

Anthony Brien
Tools Architect, Assassin's Creed
UBISOFT
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #1 - Feb 5th, 2008 at 8:22pm
Print Post  
The Arrange(Diagram, DiagramItemCollection) overloaded method could help. Pass a collection of the container's children as the second argument to Arrange. However, this will probably move the child nodes out of the container - use the KeepRootPosition and LayoutArea properties provided by some of the layout classes to ensure the child nodes remain inside their container.

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


I love YaBB 1G - SP1!

Posts: 11
Joined: Feb 5th, 2008
Re: Layout nodes inside a ContainerNode?
Reply #2 - Feb 6th, 2008 at 2:05pm
Print Post  
I've made a method to apply a layout to all the ContainerNode's found in my diagram, but it doesn't seem to work.

I call it after all nodes and links are added to the diagram. I pass a simple SpringLayout that works fine on the top level nodes.

Is there a method I need to call between each Arrange call to make sure the diagram is ready for the next Arrange call?

Code
Select All
	  private void ApplyLayout(Layout layout, DiagramItemCollection nodes)
	  {
		foreach (DiagramItem di in nodes)
		{
		    DiagramNode n = di as DiagramNode;
		    if (n != null)
		    {
			  ContainerNode containerNode = n as ContainerNode;
			  if (containerNode != null)
			  {
				DiagramItemCollection subNodes = new DiagramItemCollection();
				foreach (DiagramNode subNode in containerNode.SubordinateGroup.AttachedNodes)
				    subNodes.Add(subNode);
				layout.Arrange(diagram, subNodes);
			  }
		    }
		}
	  }
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #3 - Feb 6th, 2008 at 4:08pm
Print Post  
Ok, I can see we have some code that excludes contained nodes from the layout, which shouldn't be done when using the Arrange(DiagramItemCollection) method. We'll try to fix that and send you an updated version tomorrow.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #4 - Feb 7th, 2008 at 2:08pm
Print Post  
Hi,

Look in the private messages area for a link to download the updated assemblies.

Stoyan
  
Back to top
 
IP Logged
 
Tobbe
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Feb 12th, 2008
Re: Layout nodes inside a ContainerNode?
Reply #5 - Feb 13th, 2008 at 2:46am
Print Post  
Hi,

I have the same need. Could I get those updated assemblies as well? I’m currently evaluating FlowChart.NET using the trial version.

Does this update imply that one would have to call Arrange(layout, children) for each ContainerNode, starting with the “leaf” ContainerNode(s).

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #6 - Feb 13th, 2008 at 7:08am
Print Post  
Hi,

https://mindfusion.org/_beta/fcnetclt.zip

If you use nested containers and want to layout the entire hierarchy, you can do that by calling a recursive function for each container, which first visits any child containers, next applies a layout on all child nodes, and finally calls the container's UpdateBounds method.

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


I love YaBB 1G - SP1!

Posts: 2
Joined: Feb 12th, 2008
Re: Layout nodes inside a ContainerNode?
Reply #7 - Feb 14th, 2008 at 6:59am
Print Post  
Thanks for the prompt response!

I followed the advice to implement a recursive method. However, child nodes of a container node seems to always get laid out horizontally from left to right in the order they were added to the container. Am I missing something?

Here's a snippet to illustrate (2 nodes in one container):

[code]
[Test]
public void TestSimpleContainerNodeLayout()
{
DiagramForm form = new DiagramForm();
Diagram diagram = form.Diagram;

ContainerNode container = diagram.Factory.CreateContainerNode(0, 0, 0, 0);

ShapeNode nodeA = diagram.Factory.CreateShapeNode(0, 0, 10, 10);
nodeA.Text = "a";
container.Add(nodeA);

ShapeNode nodeB = diagram.Factory.CreateShapeNode(0, 0, 10, 10);
nodeB.Text = "b";
container.Add(nodeB);

diagram.Factory.CreateDiagramLink(nodeB, nodeA);

LayeredLayout layout = new LayeredLayout();
layout.Orientation = MindFusion.Diagramming.Layout.Orientation.Vertical;

DiagramItemCollection childNodes = new DiagramItemCollection();
foreach (DiagramNode childNode in container.SubordinateGroup.AttachedNodes)
{
childNodes.Add(childNode);
}
layout.Arrange(diagram, childNodes);
container.UpdateBounds();

form.ShowDialog();
}
[/code]

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #8 - Feb 14th, 2008 at 7:26am
Print Post  
Hi,

The Arrange(DiagramItemCollection) method expects that the collection should also contain the links. Otherwise it considers each node as a separate graph and applies the MultipleGraphsPlacement property value, which is Horizontal by default. So you must add the links to that collection too:

Code
Select All
DiagramItemCollection childItems = new DiagramItemCollection();
foreach (DiagramNode childNode in container.SubordinateGroup.AttachedNodes)
{
	childItems.Add(childNode);
	foreach (DiagramLink link in childNode.OutgoingLinks)
		childItems.Add(link);
}
layout.Arrange(diagram, childItems);
 



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


I love YaBB 1G - SP1!

Posts: 4
Joined: Jul 29th, 2008
Re: Layout nodes inside a ContainerNode?
Reply #9 - Jul 29th, 2008 at 11:43pm
Print Post  
Hi, I just read about this solution.  It was exactly that I was looking for, but there is a distance between the upper left corner to the first child node.  How can I control the distance from the left and from the top of the container node to the child node.

I have the last evaluation version.

I copied the code from Tobbe and Stoyo. It works fine, but in this sample the node B is separated from the left upper corner of container.  How can I reduce this unnecessary space.

Thanks

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #10 - Jul 30th, 2008 at 8:05am
Print Post  
Hi,

Set a smaller ContainerNode.Margin value.

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


I love YaBB 1G - SP1!

Posts: 4
Joined: Jul 29th, 2008
Re: Layout nodes inside a ContainerNode?
Reply #11 - Jul 30th, 2008 at 3:38pm
Print Post  
Hi, thanks for your response.
The problem of the space between the upper-left corner of the container and the corner of the first child node no change. When I set the Container.Margin = 0; the margin from the bottom-right corner is OK (no space), but the upper-left corner still with a considerable space.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layout nodes inside a ContainerNode?
Reply #12 - Jul 30th, 2008 at 6:44pm
Print Post  
Hi,

Try that with ContainerNode.AutoShrink enabled. Just in case, also check if MinimumSize is small enough.

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


I love YaBB 1G - SP1!

Posts: 4
Joined: Jul 29th, 2008
Re: Layout nodes inside a ContainerNode?
Reply #13 - Jul 30th, 2008 at 8:08pm
Print Post  
Thanks Stoyo,

It works excellent !!!

ContainerNode.AutoShrink = true;
Adjust the margins.

And,

ContainerNode.MinimumSize= new SizeF(0, 0);
Controls the size of the container node.

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