Custom Node Alignment for HierarchicLayouter
Tips & TricksSummary
Description
yFiles HierarchicLayouter provides no default means for specifying the alignment of nodes within a common layer but always places them in the center of the layer.
However the layout algorithm has been implemented in a modular fashion and different stages of the layout can be customized completely.
In order to modify the node alignment the drawer stage can be wrapped with a custom implementation.
Copy the attached java source file to your application, compile it and use the following lines of code to reconfigure HierarchicLayouter to work with the customization class:
// wrap the default drawer implemenation
hierarchicLayouter.setDrawer(
new AlignmentDrawer(hierarchicLayouter.getDrawer()));
The provided implementation provides different default alignment modes. For a top-level alignment (in LayoutOrientation.TOP_TO_BOTTOM style) you can use the following code to configure the customization:
//register a DataProvider, providing alignment data for each node
graph.addDataProvider(
AlignmentDrawer.NODE_ALIGNMENT_POINT_DPKEY,
new AlignmentDrawer.TopAlignmentDataProvider());