Make HierarchicLayouter Preserve Space for Node Labels
Tips & TricksSummary
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.