Nevron Forum

NLayeredGraphLayout and Top-Level Nodes

https://www.nevron.com/Forum/Topic5286.aspx

By Patrick Bergeron - Wednesday, June 29, 2011

I am using the NLayeredGraphLayout to create a graph from a dataset.  The diagram can have multiple top-level nodes (nodes with no parent).  When dealing with multiple top-level nodes, I noticed that the algorithm places these shapes in various locations within the document.  To remedy this, I created a "dummy" root node and parented all top-level nodes to this new dummy node.  Now the graph draws all top-level nodes correctly.  The problem is, I do not want the dummy node (and the edges from the dummy node to the top-level nodes) to display.  I set the Visible = false property of the root node and edges.  While these nodes are hidden as expected, there is now a blank white space above the top-level nodes.

How would I go about getting the top level nodes to draw as they do now, but without white space left by hiding the dummy node and its edges?

Any help would be greatly appreciated.

 

Thanks.

By Nevron Support - Wednesday, June 29, 2011

Hi,

there are 2 possible solutions:

  1. You can simply set the NodeRank property of the layered graph layout to TopMost. In that case you won't even need to insert the dummy node.
  2. You can insert the dummy node, layout the graph and then simply remove the dummy node and all edges connected to it.
By Patrick Bergeron - Monday, July 4, 2011

Hi,

Thanks for the response.  I set the NodeRank to TopMost and removed the root node.  The diagram doesn't display correctly.  Here is the layout code:

NLayeredGraphLayout layout = new NLayeredGraphLayout();

layout.NodeRank = LayeredLayoutNodeRank.TopMost;

layout.Direction = LayoutDirection.TopToBottom;

layout.LayerAlignment = RelativeAlignment.Near;

graphImporter.Layout = layout;

See the attachment for the rendered graph.  All nodes without paths are nodes where the parentid is set to null.  These are the nodes I would have thought were considered top-level nodes.  The CDROP_P and LOCATE nodes seem to render correctly.

 

 

By Patrick Bergeron - Monday, July 4, 2011

By the way, I am using the NGraphDataSourceImporter with a DataTable for vertices and a DataTable for paths.  The top-level nodes in the vertex DataTable are those records with a parentid of null.  Just wanted to clarify.
By Nevron Support - Monday, July 4, 2011

Hi Patrick,

You want to plot a disconnected graph (e.g. a graphs forest) with a layout method that is intended to arrange only connected graphs. All Nevron graph layouts are splitting the input graph to connected regions, that are fed to the primary layout algorithm - in your case a layered graph layout. The regions that were arranged are finally subject to flow layout arrangement - check out this topic in the docs:

Diagram for .NET > User's Guide > Layouts > Graph Parts Layouts > Graph Parts Layouts

So in order to avoid the the final flow layout arrangement step, you need to somehow make the forest of graphs a connected graph prior to layout. This will involve inserting a dummy root vertex and connections to the unparented vertices. Once the layout is performed (after graphImporter.Import() is called), you need to remove these vertices and links.

By Nevron Support - Monday, July 4, 2011

On a different note - you can also simply change the way the regions are arranged - the following code will arrange all region next to each other:

NFlowLayout flowLayout = new NFlowLayout();
flowLayout.Direction = LayoutDirection.LeftToRight;
flowLayout.ConstrainMode = CellConstrainMode.Ordinal;
flowLayout.MaxOrdinal = 1000;
graphLayout.RegionLayout = flowLayout;