Hierarchical Layout of Hierarchically Organized Graphs

Class HierarchicGroupLayouter is a derived variant of the classic HierarchicLayouter that allows to layout hierarchically organized graphs. It recursively traverses a given graph bottom-up from the most nested groups to the top-level nodes and calculates both position and dimension of the group nodes in the hierarchical layout.

Figure 5.30. Hierarchical layout of a hierarchically organized graph

Hierarchical layout of a hierarchically organized graph.

Supplemental Layout Data

Class HierarchicGroupLayouter knows a number of data provider keys which are used to retrieve supplemental layout data for a graph's elements. The data is bound to the graph by means of a data provider, which is registered using a given look-up key. Table 5.18, “Data provider look-up keys” lists all look-up keys for HierarchicGroupLayouter.

Binding supplemental layout data to a graph is described in the section called “Providing Supplemental Layout Data”.

Table 5.18. Data provider look-up keys

Key Element Type Value Type Description
GROUP_DPKEY Node boolean For each node a boolean value indicating whether it is a group node or not.
NODE_ID_DPKEY Node Object For each node an Object that serves as a unique ID.
PARENT_NODE_ID_DPKEY Node Object For each node an Object indicating the group node it belongs to. The Object matches the unique ID of a group node that is in the same graph.
GROUP_NODE_INSETS_DPKEY Node Insets For each group node a java.awt.Insets object that encodes the group node's insets.

Setup of a graph's hierarchical organization and using the grouping keys (GROUP_DPKEY, NODE_ID_DPKEY, and PARENT_NODE_ID_DPKEY) is described in detail in the section called “Setup for Layout”.

Layout Options

HierarchicGroupLayouter is an extension of the hierarchical layout algorithm. Beyond the options of this layouter, further support for the specific needs of hierarchically organized graphs is provided.

Additional size requirements of group nodes (e.g., special insets or space for custom labels) can be specified in one of two different ways. Either a custom implementation of interface GroupBoundsCalculator can be set using the method from API Excerpt 5.8, “Customizing insets calculation for group nodes”, or the default implementation for that interface, class InsetsGroupBoundsCalculator, can be used.

API Excerpt 5.8. Customizing insets calculation for group nodes

// Method from class HierarchicGroupLayouter. 
void setGroupBoundsCalculator(GroupBoundsCalculator gbc)

Choosing the latter alternative additionally requires the use of a data provider that provides java.awt.Insets objects for each group node. The data provider must be registered with the input graph using the key GROUP_NODE_INSETS_DPKEY. During layout calculation it is then used by class InsetsGroupBoundsCalculator.

Tutorial Demo Code

The following yFiles tutorial demo programs demonstrate how to use class HierarchicGroupLayouter in an application context.