IBM® ILOG® Dojo Diagrammer provides special support for
the layout of a disconnected graph.
If a graph is composed of several connected components or contains isolated nodes (nodes without
any links), it can be desirable to apply the layout algorithm separately
to each connected component and then to position the connected components
using a specialized layout algorithm (usually, ibm_ilog.graphlayout.grid.GridLayout). The following figure shows an example of a graph
containing four connected components. By enabling the layout of the
connected components on the regular layout instance (here, ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout), the connected components are
automatically identified and laid out individually. Finally, the four
connected components are positioned using a highly customizable placement
algorithm (ibm_ilog.graphlayout.grid.GridLayout).

Automatic layout of connected components in a disconnected
graph
To indicate whether a subclass of ibm_ilog.graphlayout.GraphLayout supports
this feature, use its method:
supportsLayoutOfConnectedComponents()
The default implementation returns
false
.
A subclass can override this method to return true
to
indicate that this feature is supported. You can enable the layout of the connected components
by using the method setLayoutOfConnectedComponentsEnabled(true).
To obtain the current setting:
var enabled = layout.isLayoutOfConnectedComponentsEnabled();
The default value is the value returned by the following
method:
isLayoutOfConnectedComponentsEnabledByDefault()
The default implementation of this method in ibm_ilog.graphlayout.GraphLayout returns
false
.
For some of the layout classes, it is appropriate that this feature
is enabled by default and they override this method to return true
.
If enabled on a layout class that supports this feature,
the method
performLayout
of the class ibm_ilog.graphlayout.GraphLayout
cuts
the attached graph model into connected components and lays out each
connected component separately. How does the layout of connected components feature work
when this mechanism is enabled in the layout classes that support
this feature? Instead of performing the layout on the entire graph,
the method performLayout first cuts the graph into connected
components.
Then, each connected component is laid out separately
by a call of the method
layout
. To do so,
the attached graph is temporarily changed into internally generated
graphs corresponding to each of the connected components of the original
graph. Finally, the layout instance specified by the method setLayoutOfConnectedComponents:
layout.setLayoutOfConnectedComponents(connectedComponentsLayout);
is used to position the connected components. To specify
the layout instance that places the connected components, call the
methodsetLayoutOfConnectedComponents.
If no layout instance is specified by using this method,
the method
getLayoutOfConnectedComponents
returns
an instance of ibm_ilog.graphlayout.grid.GridLayout. Its layout region parameter is set by default to
the rectangle (0
, 0
, 800
, 800
).
Its layout mode parameter is set to ibm_ilog.graphlayout.grid.GridLayout.TILE_TO_ROWS. Note
The Tree and Hierarchical layouts contain built-in support
for disconnected graphs. For the Tree and Hierarchical layouts, the
result can be different from the result of the generic mechanism (the
layout of connected components feature) provided by the base class ibm_ilog.graphlayout.GraphLayout. Depending on your particular needs, you can use
either the generic mechanism or the built-in support.