Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic "Switch branching" with automatic layout (Read 2134 times)
Alexander_S
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Jan 20th, 2010
"Switch branching" with automatic layout
Jan 20th, 2010 at 6:05pm
Print Post  

Hi,

Probably a real beginner question:
How do you get FlowchartLayout to do automatic layout on a diagram with nodes with more than two outgoing links - as depicted in the following link.

http://mindfusion.eu/images/flowchartlayout.png

I have no problem as long as there are only one or two outgoing links - in that case the auotmatic layout performs excellent.

Or, is FlowchartLayout limited to "If-else" clauses and cannot handle "Switch statements"?

If not, could someone please provide some sample code?

Thanks!

Alexander




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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: "Switch branching" with automatic la
Reply #1 - Jan 20th, 2010 at 6:44pm
Print Post  
Hi,

This should work, as long as you have a corresponding merge node at the other side of each branching. Otherwise the layout class will fail to recognize the control flow structure.

If your graphs don’t have that kind of merge nodes, try using LayeredLayout with StraightenLongLinks enabled - it should creates similar results, but in such case you might have to implement additional handling for back links.

Stoyan
  
Back to top
 
IP Logged
 
Alexander_S
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Jan 20th, 2010
Re: "Switch branching" with automatic la
Reply #2 - Jan 20th, 2010 at 8:47pm
Print Post  
Hi again,

Thanks for your quick reply!
I still don´t manage to get the layout to work with multiple branches, I'm afraid.
Are there any sample code that does exactly this, using a FlowchartLayout - that you can provide me with?

That would be very helpful.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: "Switch branching" with automatic la
Reply #3 - Jan 21st, 2010 at 8:16am
Print Post  
Hi,

Check how the JavaScript sample project creates graph nodes for the following code:

Code
Select All
function test()
{
	switch(a)
	{
	case 1:
		test1();
		test2();
	case 2:
		test1();
		test2();
	case 3:
		for (i = 1; i < 100; ++i)
		{
			test1();
		}
	case 4:
		test1();
		test2();
	}
} 



It adds an end node / merge node for language structures such as branches and loops. If such end / merge nodes do not exist in the graph, the algorithm cannot recognize the code structure simply by following the graph links recursively. If you don't want such end nodes in your flowchart, you could add them only temporary in order to apply the layout, and remove them after that.

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


I love YaBB 1G - SP1!

Posts: 5
Joined: Jan 20th, 2010
Re: "Switch branching" with automatic la
Reply #4 - Jan 22nd, 2010 at 9:57am
Print Post  
Hi Stoyan,

Excellent answer. That solved it.
Thank you!

-Alexander
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint