Make HierarchicLayouter Preserve Space for Node Labels

Tips & Tricks

Summary

HierarchicLayouter by default does not consider node labels at all. This article describes how to customize the Drawer implementation in order to preserve space for node labels.

This article was written for an older version. It is only online as a reference for customers using this old version. The information it contains is probably out of date.

The latest information can be found in the yFiles documentation

Description

HierarchicLayouter makes use of different sub modules that are responsible for assigning nodes to layers, sequencing layers, and assigning coordinates to nodes. The node assignment is performed by classes implementing the Drawer interface.
The most popular implementations of this interface are SimplexDrawer, MedianLinearSegmentDrawer, and MedianDrawerWrapper. Those implementations take space requirements into account that are provided by the main layout algorithm through DataProviders that are bound to the graph using the Drawer.NODE_BORDER_LEFT and Drawer.NODE_BORDER_RIGHT dataprovider keys.
The attached example class NodeLabelSpaceDrawer can be used to wrap the Drawer implementation as follows:

//create the layouter
HierarchicLayouter hl = new HierarchicLayouter();

//set an appropriate drawer
hl.setDrawer(new SimplexDrawer());

//wrap the drawer
hl.setDrawer(new NodeLabelSpaceDrawer(hl.getDrawer()));

This will preserve sufficient space between neighbouring nodes so that node labels will not overlap with each other anymore.

yFiles 2.3 provides IncrementalHierarchicLayouter which has sophisticated node label handling methods integrated.

Resources

Categories this article belongs to:
yFiles for Java > yFiles Layout > Automatic Graph Layout > Hierarchical Layout
Applies to:
yFiles.NET: 2.2, 2.3, 2.4
yFiles for Java 2: 2.0, 2.1, 2.2, 2.3, 2.4
Keywords:
HierarchicLayouter - customize - preserve - space - labels - NodeLabel - side - Drawer - NODE_BORDER_LEFT - NODE_BORDER_RIGHT - wrap