Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Advice on which automatic layout to use (Read 4232 times)
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Location: Seattle
Joined: Feb 6th, 2017
Advice on which automatic layout to use
Feb 10th, 2017 at 7:23pm
Print Post  
Hello,

I was hoping to get some advice on which automatic layout, or perhaps combination of layouts, I should use.

In this diagram, the user clicks a button for a certain node type, and the node appears in the diagram. They would then draw a link between whichever nodes they like (there are some restrictions, but I don't think it's necessary to go into those). Once a link is created, I would like the diagram to auto-arrange itself.

Here is an example of what a diagram might look like:
http://imgur.com/a/U3heU

Any nodes that are of the "Basic" category, I want aligned on the left side of the diagram. But other than that, I just want the rest of the nodes laid out in a logical way to the right.

How do I left-align just certain nodes, and auto-arrange the others?

Thanks!
Joel.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Advice on which automatic layout to use
Reply #1 - Feb 13th, 2017 at 7:43am
Print Post  
Hi,

Try horizontal LayeredLayout with custom layers for basic nodes -

Code
Select All
foreach (var node in diagram.Nodes)
	if (node.IncomingLinks.Count == 0) // replace this check with your identification of basic nodes
		node.LayoutTraits[LayeredLayoutTraits.Layer] = 0;

var layout = new LayeredLayout();
layout.EnableCustomLayers = true;
layout.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;
layout.MultipleGraphsPlacement = MultipleGraphsPlacement.Vertical;
layout.Arrange(diagram); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Location: Seattle
Joined: Feb 6th, 2017
Re: Advice on which automatic layout to use
Reply #2 - Feb 13th, 2017 at 10:12pm
Print Post  
This seems to be working well.  Thank you so much!

One follow up, however.
As mentioned in my original post, the user clicks buttons to have the nodes show up on the diagram.  For non-Basic nodes that don't yet have any links attached to them, is there a way for me to right-adjust those ones?  (I know the Bounds of the diagram can change, so perhaps a way to specify where they'll show up in a vertical list?)  Perhaps, can I exclude them from the layout and then place them manually myself?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Advice on which automatic layout to use
Reply #3 - Feb 14th, 2017 at 6:37am
Print Post  
Maybe try using the Arrange(DiagramItemCollection) overload calling it twice for the two parts of your diagram. For first Arrange with above settings add to the collection all diagram items, including links, except the nodes you want right-aligned. The second time call Arrange for the right-aligned nodes, with layout.Margins.Width set to the position you want them -

Code
Select All
var layout = new LayeredLayout();
layout.Margins = new SizeF(rightX, 10);
layout.MultipleGraphsPlacement = MultipleGraphsPlacement.Vertical;
layout.Arrange(diagram, rightNodes); 



rightNodes will be placed in a column by MultipleGraphsPlacement as each unconnected node is treated as a graph of its own.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Location: Seattle
Joined: Feb 6th, 2017
Re: Advice on which automatic layout to use
Reply #4 - Feb 15th, 2017 at 5:28am
Print Post  
The DiagramItemCollection overload seems like the way to go.  Thanks!

I'm getting some strange behavior, though.  I've got my Diagram's Bounds set to (0,0,700,300).  I have the layout1.Margin on the first set of nodes set to (17,17), and the layout2.Margin on the second set of nodes set to (200,17).

Using Snoop, I can see that the Diagram's DesiredSize is (700,300), and a child object called, CZ, is also (700,300).  But then I add a node that gets placed on the right side, and both the Diagram and the CZ object grow to (883,317), but the CZ object is offset from the top left corner of the Diagram by 183,34.  It's like the margin's are somehow getting compounded, but it's 200 - 17 and 17 + 17.  All the nodes look like they are placed correctly relative to each other, but there's that offset of 183,34 from the Diagram's top left corner.

Is there something I need to do to make sure the second arrange phase doesn't move the Margins?

Thanks so much!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Advice on which automatic layout to use
Reply #5 - Feb 15th, 2017 at 9:14am
Print Post  
Arrange on its own doesn't change diagram's size, are you maybe calling ResizetoFitItems(margin) after applying the layouts? That margin would be subtracted from leftmost nodes and added to rightmost ones to create new Diagram.Bounds.

The CZ is obfuscated name of backing field of Diagram's DocumentPlane property I guess - that one is used to support non-zero diagram Bounds origin and diagram items are actually added as its children.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Location: Seattle
Joined: Feb 6th, 2017
Re: Advice on which automatic layout to use
Reply #6 - Feb 16th, 2017 at 5:32am
Print Post  
Turns out the culprit was layout.GrowToFit.  It defaults to true and was causing the diagram to change size.  I've set it to false, and things are acting as expected.

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