How to Layout Subsets of Nodes Only |
| Applies to: yFiles for Java 2.7, 2.6, 2.5 |
Categories this article belongs to:
| yFiles for Java | > yFiles Layout | > Automatic Graph Layout | > Advanced Layout Features |
| yFiles for Java | > yFiles Layout | > Automatic Graph Layout | > Incremental Layout |
The yFiles layout algorithms provide different ways when only a subset of nodes
shall be arranged.
In the majority of scenarios, the subset of nodes to be processed is declared by
means of a data accessor (see the yFiles Developer's Guide for
more information on data accessors).
The data accessor holds specific supplemental data for the nodes of the subset.
This supplemental data can be as simple as a boolean value, but can also be more complex.
For example, IncrementalHierarchicLayouter (see below) uses so-called "hints."
Incremental Layout Algorithms
Several of the yFiles layout algorithms provide support for incremental layout where distinct parts of a graph can be rearranged and be optimally integrated into an already existing layout.
IncrementalHierarchicLayouter
Class IncrementalHierarchicLayouter
offers sophisticated support for rearranging a subset of nodes.
A variety of so-called "hints" for nodes (and edges, by the way) is made available by class
IncrementalHintsFactory
.
The hints are then associated with a subset's nodes by means of a data accessor that can be retrieved during the layout process using the look-up key
IncrementalHierarchicLayouter#INCREMENTAL_HINTS_DPKEY
.
The setup of IncrementalHierarchicLayouter and the use of hints is shown in this tutorial source code demo:
IncrementalHierarchicLayouterDemo.java
| Note |
| IncrementalHierarchicLayouterDemo is also available in C# and Visual Basic in the demos\Demo.Layout.IncrementalHierarchicLayouter directory of a yFiles.NET Layout or yFiles.NET Complete installation. |
OrganicLayouter and SmartOrganicLayouter
For indication of the subset of nodes to be processed, both organic layout algorithms
expect a data accessor to return simple boolean values.
The look-up key for the data accessor is
OrganicLayouter#SPHERE_OF_ACTION_NODES
(for OrganicLayouter)
and
SmartOrganicLayouter#NODE_SUBSET_DATA
(for SmartOrganicLayouter),
respectively.
This article outlines the setup for incremental layout using an organic layout algorithm.
GenericTreeLayouter
Class GenericTreeLayouter
provides support for incremental layout with the help of java.util.Comparator implementations.
The comparators are used to determine the ordering of child nodes at their root node.
There are two schemes available, which can also be combined:
- a single Comparator implementation can be registered as the default to handle all root nodes, i.e., to act globally on the entire tree
- individual Comparator implementations can be registered to handle specific root nodes, i.e., act locally on subtrees
Setting a single Comparator for the entire tree is done with the following line of code:
// 'myChildComparator' is a java.util.Comparator implementation. // 'gtl' is of type y.layout.tree.GenericTreeLayouter. gtl.setDefaultChildComparator(myChildComparator); |
Setting individual Comparators for specific subtrees is done by means of a data
accessor that can be retrieved by GenericTreeLayouter using the look-up key
GenericTreeLayouter#CHILD_COMPARATOR_DPKEY
.
| Note |
| An individual Comparator for a specific root node takes precedence over the default Comparator. |
TreeLayouter, BalloonLayouter, HVTreeLayouter, and ARTreeLayouter
Similar to GenericTreeLayouter (see above), the tree layout algorithm classes
TreeLayouter
, BalloonLayouter
, HVTreeLayouter
, and ARTreeLayouter
also provide support for incremental layout.
Using the setComparator
method, a NodeOrderComparator that is used to determine the ordering of child nodes at their respective root node can be registered.
It works in conjunction with a data provider that is registered with the graph using the NodeOrderComparator#NODE_ORDER_DPKEY
look-up key.
Class NodeOrderComparator, when given the outgoing edges of a (sub)tree's root node, uses the target nodes of the edges for querying the data provider. The java.lang.Comparable objects, which the comparator expects in return, are then used to determine the order of the child nodes.
Setting a NodeOrderComparator is done with the following line of code:
// 'myChildComparator' is a NodeOrderComparator. // 'tl' is an instance of one of the tree layout algorithm classes TreeLayouter, // BalloonLayouter, HVTreeLayouter, or ARTreeLayouter. tl.setComparator(myChildComparator); |
Note that class TreeLayouter in particular uses a XCoordComparator
instance as the default NodeOrderComparator to enable incremental layout by default.
BalloonLayouter
As an alternative to using an explicit Comparator implementation, class BalloonLayouter
also supports incremental layout by taking into account a diagram's current drawing when
calculating a new layout.
This special mode can be enabled using method
setFromSketchModeEnabled
.
Non-incremental Layout Algorithms
The group of layout algorithms that is not capable of incremental layout, but nevertheless
is able to process only a subset of a graph, does so by means of the data provider look-up key
Layouter#SELECTED_NODES
in conjunction with class
SubgraphLayouter
.
SubgraphLayouter is an already built-in layout stage in class CanonicMultiStageLayouter
,
which is the super class of almost all yFiles major layout algorithms.
To activate it, the following line of code suffices.
// 'layouter' is of type y.layout.CanonicMultiStageLayouter (i.e. one of the yFiles // major layouters). layouter.setSubgraphLayouterEnabled(true); |
Using SubgraphLayouter, the best results can be achieved when whole components are processed, i.e., when there are no (or only a small number of) interconnections between selected elements and non-selected elements.
| Note |
| C# users of the yFiles.NET library will have to use LayoutConstants#SELECTED_NODES instead of Layouter#SELECTED_NODES. |
| Keywords: | layout - selection - subset - nodes - selected - incremental - non-incremental - data - accessor - SELECTED_NODES - SPHERE_OF_ACTION_NODES - NODE_SUBSET_DATA - CHILD_COMPARATOR_DPKEY - INCREMENTAL_HINTS_DPKEY - SubgraphLayouter - subgraph - pinned - fixed - subtree - NodeOrderComparator - Comparator - NODE_ORDER_DPKEY |


