Applying a graph layout

IBM® ILOG® Dojo Diagrammer features built-in graph layout algorithms that enable you to transform the appearance of your graphs. The Graph component has methods to configure and perform graph layout algorithms that you can apply to your graph contents.
Use the setNodeLayout function to specify a graph layout algorithm that is executed on the content of a graph. The algorithm is represented by one of the subclasses of the ibm_ilog.graphlayout.GraphLayout class. Use the performGraphLayout function to execute the selected graph layout on the graph.
To apply a Force-Directed layout to a graph:
  • Use the following code:
    dojo.require("ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout");
    ...
             var layout = new ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout();
             graph.setNodeLayout(layout);
             graph.performGraphLayout();
Here is the resulting graph after performing the force-directed layout:
A graph
made up of four rectangular nodes, each having a label on them: Node
1, Node 2, Node 3, Node 4. Node 1 is located on the left, Node 2 at
the top, Node 3 at the bottom, and Node 4 on the right of the graph.
A link connects the upper border of Node 1 to the lower left border
of Node 2. Another link connects the lower border of Node 1 to the
upper left border of Node 3. A link connects the lower right border
of Node 2 to the upper border of Node 4. A link connects the upper
right border of Node 3 to the lower border of Node 4.
The Graph component provides other graph layout-related methods:
  • setLinkLayout(layout) specifies a graph layout algorithm to lay out the links of a graph.
  • setAutomaticNodeLayout(true/false) and setAutomaticLinkLayout(true/false) specifies whether to perform the graph layout automatically whenever the graph changes, such as when a node is moved.
  • setNodeLayoutActive(true/false) and setLinkLayoutActive(true/false) selectively activate or deactivate one of the graph layout algorithms.
See Introducing graph layout for more information about the available graph layout algorithms.