How to Instruct the OrganicLayouter to Fix Some Node Positions
Applies to: yFiles 2.6, yFiles WPF 1.0, yFiles.NET 3.1 print article email article

Type: Questions & Answers

This article describes how the suite of organic layout algorithms can be instructed to fix the positions of a subset of nodes. It applies to both the SmartOrganicLayouter and the OrganicLayouter both in flat mode and hierarchically nested mode.

It is often useful to specify a subset of nodes that should be laid out only or a subset of nodes that should not be laid out during a layout run. Both OrganicLayouter and SmartOrganicLayouter support this feature, even if the two subsets are in the same graph component.
In order to specify the subset to be laid out, bind a boolean DataProvider to the graph using a predefined DataProvider key.
This article describes different ways of how to pass data to layout algorithms.
The following piece of code uses the current selection to specify those nodes to be laid out by the layout algorithm:
//Add the DataProvider to the graph
graph2d.addDataProvider(SmartOrganicLayouter.NODE_SUBSET_DATA,
     Selections.createSelectionNodeMap(graph2d));

//Configure the algorithm to use the data
smartOrganicLayouter.setScope(SmartOrganicLayouter.SCOPE_SUBSET);

//and run the layout
//(buffered in this case)
new BufferedLayouter(smartOrganicLayouter).doLayout(graph2d);

//remove the DataProvider after the layout
graph2d.removeDataProvider(SmartOrganicLayouter.NODE_SUBSET_DATA);
Note
Both OrganicLayouter and SmartOrganicLayouter have to instructed to make use of the information bound to the graphs. This can be achieved by invoking either the OrganicLayouter.setSphereOfAction(byte)method with OrganicLayouter.ONLY_SELECTIONas the argument or the SmartOrganicLayouter.setScope(byte)method with SmartOrganicLayouter.SCOPE_SUBSETas the argument respectively.
Note
The positions of the nodes that belong the fixed subset may still be changed by the ComponentLayouter (the default component layouting algorithm will move the entire component back to the origin after the layout has been performed). However relative node positions of fixed nodes will stay the same.
The ComponentLayouter instance can of course be disabled or customized to your needs.
Note
When using SmartOrganicLayouter to layout a subset of nodes, its feature nodeOverlapsAllowed should be enabled, otherwise unselcted nodes might be moved to resolve node overlaps.

Keywords: SmartOrganicLayouter - fix positions - incremental layout - OrganicLayouter - node subset - ComponentLayouter

Provide feedback:
How useful was this article?    less 1 2 3 4 5 more
Email address (optional):
COPYRIGHT © 2008 yWorks · ALL RIGHTS RESERVED imprint | top | home