Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to rearrange containers (Read 5205 times)
yrauma
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Mar 28th, 2010
How to rearrange containers
May 10th, 2010 at 6:19pm
Print Post  
Hello Stoyan !

Im still working on my container project Cheesy
I have one last issue.

We are using the feature rearrange to rearrange our graph which worked pretty well before we used containers...

But now troubles have comes.

I would like to use this feature to reorganize the content of a container also not only outside. I found some examples on the forum, but nothing really efficient.

And also is there a way when we add a node into a container programmatically to make it look smarter ? right now when I do that, the container just grows till it is over the node but does not move the node in a logic place...

Any idea ?

Thanks for the help !
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to rearrange containers
Reply #1 - May 10th, 2010 at 7:42pm
Print Post  
Hi,

You can use this code to arrange a single level of containers and their content:

Code
Select All
private void miLayoutContainers_Click(object sender, EventArgs e)
{
	LayeredLayout layeredLayout = new LayeredLayout();
	layeredLayout.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;
	layeredLayout.StraightenLongLinks = true;

	TopologicalLayout topologicalLayout = new TopologicalLayout();
	topologicalLayout.SplitGraph = true;
	topologicalLayout.Orientation = MindFusion.Diagramming.Layout.Orientation.Vertical;

	Arrange(diagram, topologicalLayout, layeredLayout);
}

private DiagramItemCollection GetContainerItems(ContainerNode container)
{
	DiagramItemCollection items = new DiagramItemCollection();
	foreach (DiagramNode node in container.SubordinateGroup.AttachedNodes)
	{
		items.Add(node);
		foreach (DiagramLink link in node.GetAllLinks())
		{
			DiagramNode node2 = GetOtherEnd(link, node);
			if (ContainerNode.GetContainer(node2) == container && !items.Contains(link))
				items.Add(link);
		}
	}
	return items;
}

private DiagramNode GetOtherEnd(DiagramLink link, DiagramNode node)
{
	if (node == link.Origin)
		return link.Destination;

	if (node == link.Destination)
		return link.Origin;

	return null;
}

private void Arrange(Diagram diagram, Layout outerLayout, Layout innerLayout)
{
	foreach (DiagramNode node in diagram.Nodes)
	{
		ContainerNode container = node as ContainerNode;
		if (container == null)
			continue;

		innerLayout.Arrange(diagram, GetContainerItems(container));
		container.UpdateBounds();
	}

	outerLayout.Arrange(diagram);

	foreach (DiagramLink link in diagram.Links)
	{
		if (ContainerNode.GetContainer(link.Origin) != ContainerNode.GetContainer(link.Destination))
			link.Route();
	}

	diagram.ResizeToFitItems(5);
} 



Experiment with the inner and outer layouts to find ones that will work for your graphs. If your containers can have child containers, you will need to extend the Arrange method to work recursively.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
yrauma
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Mar 28th, 2010
Re: How to rearrange containers
Reply #2 - May 10th, 2010 at 8:57pm
Print Post  
Thanks a lot Stoyan !
it works pretty fine !

It actually seems that it works for containers inside container also, at least a little !

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