Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic TopologicalLayout with more than one row (Read 5301 times)
mbuechler
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 39
Joined: Oct 21st, 2009
TopologicalLayout with more than one row
Nov 30th, 2009 at 1:35pm
Print Post  
Hi.

Is it possible to use the topological Layout Engine with more than one row of DiagramNodes?
I use this Layout to draw a statemachine an if there are more than 5 States the diagram is getting really wide.
Does anyone has a solution for this?
Or has anyone a better idea for drawing a statenmachine?

thanks for all hints.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TopologicalLayout with more than one row
Reply #1 - Nov 30th, 2009 at 3:04pm
Print Post  
Hi,

That's not supported at this time. It's easy to move down and to the left nodes at X position larger than a specified width after the layout is applied, and so create additional rows. However I don't have any idea how to position links that would cross multiple rows then.

You might try LayeredLayout or SpringLayout to get more compact layouts.

Stoyan
  
Back to top
 
IP Logged
 
mbuechler
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 39
Joined: Oct 21st, 2009
Re: TopologicalLayout with more than one row
Reply #2 - Nov 30th, 2009 at 3:59pm
Print Post  
I tried to use these layouts. but these layouts dont have round / bezier links. so it dont look that good.

But thanks for help
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TopologicalLayout with more than one row
Reply #3 - Nov 30th, 2009 at 4:21pm
Print Post  
Our developer suggests you could do the following:

- clone the chart by calling LoadFromString(SaveToString())
- replace each link in the cloned chart with a sequence of two dummy nodes and links
- run SpringLayout on the clone
- copy the node coordinates from the cloned chart to the original one, and assign the center positions of dummy nodes as coordidnates for the Bezier links' intermediate points.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TopologicalLayout with more than one row
Reply #4 - Nov 30th, 2009 at 7:17pm
Print Post  
E.g. this code creates the following kind of layout:

Code
Select All
void SpringLayoutBezier(Diagram diagram)
{
	Diagram clone = new Diagram();
	clone.LoadFromString(diagram.SaveToString());
	var virtualNodes = AddVirtualNodes(clone);

	SpringLayout layout = new SpringLayout();
	layout.MinimizeCrossings = true;
	layout.NodeDistance /= 3;
	layout.IterationCount *= 3;
	layout.Arrange(clone);

	ApplyLayout(diagram, clone, virtualNodes);
}

Dictionary<DiagramNode, DiagramLink> AddVirtualNodes(Diagram diagram)
{
	var virtualNodes = new Dictionary<DiagramNode, DiagramLink>();

	DiagramLinkCollection originalLinks = diagram.Links.Clone();
	foreach (DiagramLink link in originalLinks)
	{
		PointF m = MiddlePoint(link);

		ShapeNode v1 = diagram.Factory.CreateShapeNode(m, new SizeF(1, 1));
		v1.Tag = 1;
		ShapeNode v2 = diagram.Factory.CreateShapeNode(m, new SizeF(1, 1));
		v2.Tag = 2;
		virtualNodes[v1] = virtualNodes[v2] = link;

		diagram.Factory.CreateDiagramLink(link.Origin, v1);
		diagram.Factory.CreateDiagramLink(v1, v2);
		diagram.Factory.CreateDiagramLink(v2, link.Destination);

		link.IgnoreLayout = true;
	}

	return virtualNodes;
}

private void ApplyLayout(Diagram diagram, Diagram clone, Dictionary<DiagramNode, DiagramLink> virtualNodes)
{
	foreach (DiagramNode node in diagram.Nodes)
	{
		int index = node.ZIndex;
		var clonedNode = clone.Items[index] as DiagramNode;
		node.Bounds = clonedNode.Bounds;
	}

	foreach (DiagramLink link in diagram.Links)
	{
		link.Style = LinkStyle.Polyline;
		link.Style = LinkStyle.Bezier;
		link.SegmentCount = 1;
	}

	foreach (DiagramNode vnode in virtualNodes.Keys)
	{
		var link = virtualNodes[vnode];
		int index = link.ZIndex;
		var originalLink = diagram.Items[index] as DiagramLink;
		 int pointIndex = (int)vnode.Tag;

		originalLink.ControlPoints[pointIndex] = vnode.Bounds.Location;
		if (pointIndex == 1)
			originalLink.ControlPoints[0] = vnode.IncomingLinks[0].ControlPoints[0];
		else
			originalLink.ControlPoints[3] = vnode.OutgoingLinks[0].ControlPoints[1];
		originalLink.UpdateFromPoints();
	}
}

private PointF MiddlePoint(DiagramLink link)
{
	PointCollection p = link.ControlPoints;
	PointF m = new PointF(
		(p[0].X + p[p.Count - 1].X) / 2,
		(p[0].Y + p[p.Count - 1].Y) / 2);
	return m;
}
 



  
Back to top
 
IP Logged
 
mbuechler
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 39
Joined: Oct 21st, 2009
Re: TopologicalLayout with more than one row
Reply #5 - Dec 1st, 2009 at 8:32am
Print Post  
Hi. Thanks for this. I tried it, and it nearly works Wink

The problem is, that the links do not end at the nodes. they look like bezier, but it do not end at the border of the nodes. when i move the node or the controlpoint of the link the link snaps to the node... sorry, i cannot send you a screenshot.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TopologicalLayout with more than one row
Reply #6 - Dec 1st, 2009 at 8:47am
Print Post  
Hi,

This code assumes the diagram defaults for the links are polyline with one segment. If your LinkStyle and SegmentCount are different than that, you will have to replace the right-hand side of this assignment -

originalLink.ControlPoints[3] = vnode.OutgoingLinks[0].ControlPoints[1];

with one that takes ControlPoints[ControlPoints.Count - 1] rather than ControlPoints[1].

Or set the default properties to polyline/1 on the 'clone' diagram before creating links.

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


I love YaBB 1G - SP1!

Posts: 39
Joined: Oct 21st, 2009
Re: TopologicalLayout with more than one row
Reply #7 - Dec 1st, 2009 at 11:56am
Print Post  
Yes. That helped.

Now it looks really good.
Thanks!!!!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TopologicalLayout with more than one row
Reply #8 - Dec 1st, 2009 at 3:28pm
Print Post  
Now we've noticed there is a small problem with this approach - the MinimizeLinks option does not work that well when there are three times as many nodes... So you might run the layout once on the original graph to minimize the crossings, and then run the code above to create the curved links.

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