In Dojo Diagrammer, there are several ways to get the links laid out. Link layouts can be performed by:
- Node layout algorithms that also have extensive built-in link layout capabilities: HierarchicalLayout, TreeLayout. These provide various link styles and many configuration options.
- Node layout algorithms that only support a straight link style: CircularLayout, ForceDirectedLayout. These provide support for self-links (links connecting a node to itself) and multi-links (several links that connect the same pair of nodes).
- Specialized link layout algorithms: ShortLinkLayout and LongLinkLayout. These can be used in conjunction with a node layout.
All these algorithms can be applied to flat or nested graphs. The case of nested graph is the trickiest, mostly because of two reasons:
- The layout algorithms being applied locally to each subgraph in a bottom-to-top traversal of the graph hierarchy, the result is optimal locally (for each subgraph) but is suboptimal globally (for the entire nested graph).
- Most node layout algorithms (TreeLayout, CircularLayout, ForceDirectedLayout) are not able to lay out intergraph links, that is links that interconnect nodes from different subgraphs. (The reason being the one mentioned above: the layout being computed individually for each subgraph, it cannot treat links that traverse the boundaries of subgraphs.)
To deal with intergraph links, the node layouts such as TreeLayout, CircularLayout, and ForceDirectedLayout need to be combined with a link layout (ShortLinkLayout or LongLinkLayout) configured such that it only lays out the intergraph links, while the regular links are laid out by the node layout:
graph.setNodeLayout(nodeLayout); // Tree, Circular, ForceDirected
graph.setLinkLayout(linkLayout); // ShortLinkLayout or LongLinkLayout
// Configure it to handle the intergraph links:
// and to only handle intergraph links, not the regular links:
This feature of HierarchicalLayout is enabled by default. It can be disabled (but in this case do not forget to combine it with a link layout for intergraph links in nested graphs):
Note for users of Dojo Diagrammer 1.0: this feature is new in Dojo Diagrammer 1.1.
The picture below shows a nested graph laid out with this feature of HierarchicalLayout disabled, plus LongLinkLayout configured for the intergraph links:
- Use HierarchicalLayout in its default recursive mode whenever your graph data has hierarchical structure.
- Otherwise, combine a node layout with a link layout for intergraph links.