Custom Node Alignment for HierarchicLayouter
Applies to: yFiles 2.2, yFiles 2.1, yFiles 2.0, yFiles.NET 2.4, yFiles.NET 2.3, yFiles.NET 2.2 print article email article

Type: Tips & Tricks

Categories this article belongs to:
yFiles for Java > yFiles Layout > Automatic Graph Layout > Hierarchical Layout

This article describes how HierarchicLayouter can be customized to produce different node alignments.

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());
Warning
These DataProvider implementations will only work properly if the layout is performed in buffered mode.
Note
Note that IncrementalHierarchicLayouter included in yFiles 2.3 offers this functionality by default. The behavior can be controlled for each node separately using the NodeLayoutDescriptor.setLayerAlignment(double) method.

Keywords: HierarchicLayouter - layer - center - nodes - alignment - customization - align - top - bottom - HierarchicGroupLayouter - Drawer

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