How to Layout Subsets of Nodes Only
Applies to: yFiles 2.5, yFiles 2.4, yFiles 2.3, yFiles 2.2, yFiles 2.1, yFiles 2.0, yFiles WPF 1.0, yFiles.NET 3.1, yFiles.NET 3.0, yFiles.NET 2.4, yFiles.NET 2.3, yFiles.NET 2.2 print article email article

Type: Questions & Answers

Overview on the setup for incremental and non-incremental layout of a subset of nodes with the yFiles layout algorithms.

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

Similar to GenericTreeLayouter (see above), class TreeLayouter also provides support for incremental layout with the help of a java.util.Comparator implementation.

Using method setComparator a Comparator implementation that is used to determine the ordering of child nodes at their respective root node can be registered. It handles all root nodes, i.e., acts globally on the entire tree.

BalloonLayouter

Class BalloonLayouter 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

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