Specific parameters of FL

The following parameters are specific to the ForceDirectedLayout class.

Link style (FL)

When the layout algorithm moves the nodes, straight-line links will automatically “follow” the new positions of their end nodes. If the graph contains other types of link, the shape of the link might not be appropriate because the intermediate points of the link are not moved. In this case, you can ask the layout algorithm to remove automatically all the intermediate points of the links (if any).
To specify that the algorithm automatically removes all the intermediate points of the links (if any):
Example of setting the link style
forceDirectedLayout.setLinkStyle(
  ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout.STRAIGHT_LINE_STYLE);  
The valid values for style are:
  • ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout.NO_RESHAPE_STYLE
    None of the links is reshaped in any way.
    ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout.STRAIGHT_LINE_STYLE
    All the intermediate points of the links (if any) are removed. This value is the default.

Connect links to node center (FL)

This feature is shared by all subclasses of the Basic Link Style Layout. See Connect links to node center for details.

Multilink and self-link features (FL)

These features are shared by all subclasses of the Basic Link Style Layout. See Multilink and self-link features for details.

Number of iterations (FL)

The iterative computation of the layout algorithm is stopped if the time exceeds the allowed time (see Allowed time) or if the number of iterations exceeds the allowed number of iterations.
To specify the number of iterations:
Example of setting the allowed number of iterations
forceDirectedLayout.setAllowedNumberOfIterations(100);  

Preferred length (FL)

The main objective of this layout algorithm is to obtain a layout where all the links have the same length, called the “preferred length”.
To specify the preferred length:
Globally
  • Example of specifying the preferred length globally
    forceDirectedLayout.setPreferredLinksLength(200);
    
    The default value is 60.0.
Individually
It is also possible to specify a length for individual links.
  • Example of specifying the preferred length individually
    forceDirectedLayout.setPreferredLength(link, 100);  
    
    To obtain the current value, use the following method:
    var length = forceDirectedLayout.getPreferredLength(link);  
    
If a specific length is not specified for a link, the global settings are used.

Respect node sizes (FL)

By default, the layout algorithm takes into account the size (width and height) of the nodes. For efficiency reasons, the nodes can be approximated with points placed in the center of the bounding box of the nodes. When dealing with large nodes, the preferred length parameter can be increased in such a way that the nodes do not overlap.
To improve the performances of graphs with constant node sizes, the algorithm provides a special mode in which the particular size of each node is not considered.
To set this mode:
Example of not taking size of nodes into account
forceDirectedLayout.setRespectNodeSizes(false);     
The default value is true.

Force fit to layout region (FL)

It is difficult to choose an appropriate size for the layout region of this layout algorithm. If the specified layout region is too small for a particular graph, the resulting layout is not the best. For this reason, by default, the Force-directed Layout algorithm does not use the layout region parameter.
It can use as much space as it needs to lay out the graph.
To specify whether the layout algorithm must use the layout region:
Example of using the layout region parameter
forceDirectedLayout.setForceFitToLayoutRegion(true);  
The default value of the parameter is false.

Layout mode

To fit various needs, the algorithm provides three optional layout modes:
Incremental mode
The algorithm starts from the current position and iteratively tries to converge towards the optimal layout. In some cases, this mode avoids a major reorganization of the graph, which helps to preserve the mental map of the user as much as possible. However, it is not guaranteed and depends on how far the initial position of the nodes is from the position that satisfies the criteria of the algorithm.
Non-incremental mode
The algorithm is free to reorganize the graph without trying to stay close to the initial positions. Often, non-incremental mode is faster than incremental mode, although sometimes at the cost of lower quality.
Fast multilevel mode
The algorithm uses a multilevel graph decomposition strategy that leads to a significant gain in speed. This mode is usually the fastest for medium and large graphs.
The default value is ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout.INCREMENTAL_MODE.
To set the layout mode:
Example of setting the layout mode
forceDirectedLayout.setLayoutMode(
  ibm_ilog.graphlayout.forcedirected.ForceDirectedLayout.FAST_MULTILEVEL_MODE);