Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Two issues with Container Nodes (Read 3552 times)
Mathias Z.
YaBB Newbies
*
Offline


DiagramLite is cool!

Posts: 5
Joined: Sep 27th, 2010
Two issues with Container Nodes
Oct 8th, 2010 at 12:05am
Print Post  
Hello Stoyan,

I have implemented a network-like diagram with Shape Nodes, connected via Links, where I automatically render the layout using SpringLayout.
This works very well!

Now I added Container Nodes, trying to group several Shape Nodes within one Container Node. But this isn't working like I was hoping...

My first issue:
A user can drag a child node outside the Container Node, even though I defined
  KeepInsideParent = true
for each child node.
It seems that this setting only ensures that the children are moved simultaneously with the Container Node - even if they have been moved outside the borders of the Container Node. I want them to stay within the border of their Container Node. Would I have to implement a Mouse event for this?

My second issue:
When I run the SpringLayout, the children often get re-positioned outside their Container Node.
I changed the  IgnoreLayout   (for both the childred nodes and the Container Node or only one of them) back and forth, but it would only come up with other challenges: in this case neither the Containde Node nor the childred are moved (this is somewhat okay), but the other Shapes in the diagram collide/overlap the Container Node.

Can you provide guidance?

Thank you and best regards

Mathias
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Two issues with Container Nodes
Reply #1 - Oct 8th, 2010 at 7:58am
Print Post  
Hi Mathias,

1. Use this method to arrange diagrams with containers; you can try different inner/outer layout combinations to see which work better for your case:

Code
Select All
void ArrangeContainers()
{
	var innerLayout = new LayeredLayout();
	innerLayout.StraightenLongLinks = true;
	innerLayout.EnforceLinkFlow = true;
	innerLayout.NodeDistance /= 2;

	var outerLayout = new LayeredLayout();
	outerLayout.StraightenLongLinks = true;
	outerLayout.EnforceLinkFlow = true;
	outerLayout.NodeDistance /= 2;

	Arrange(diagram, outerLayout, innerLayout);
}

private DiagramItemCollection GetContainerItems(ContainerNode container)
{
	DiagramItemCollection items = new DiagramItemCollection();
	foreach (DiagramNode node in container.Children)
	{
		items.Add(node);
		foreach (DiagramLink link in node.GetAllLinks())
		{
			DiagramNode node2 = GetOtherEnd(link, node);
			if (node2.Container == 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);

	diagram.ResizeToFitItems(5);
}

static class ContainerExtensions
{
	public static void UpdateBounds(this ContainerNode container)
	{
		if (container.Children.Count == 0)
			return;
		var r = container.Children[0].Bounds;
		foreach (DiagramNode node in container.Children)
			r.Union(node.Bounds);

		container.SetBounds(r, false);
	}
} 



2. It seems we haven't implemented that constraint yet in Silverlight, you can find an example that implements it by handling NodeModifying here:
http://mindfusion.eu/Forum/YaBB.pl?board=diaglite_disc;action=display;num=128090...

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