The graph layout algorithm is most likely
the most complex part of your application. Hence it might also be
the slowest part of your application. Therefore it is useful to
design the application so that graph layout is used only when
needed. For instance, the application could offer a button that
triggers layout, so that the graph layout does not need to run
continuously during all interactions.
Graph layout places the nodes and routes the links. If moving nodes
and reshaping links is slow, graph layout cannot be fast.
Therefore, it is important to know the performance hints described
in the Optimizing the performance of JViews
Framework in addition to those hints that are related to graph
layout.
Orthogonal links without link layout
If your application requires orthogonal link shapes, you might be
tempted to use a link layout in automatic layout mode. This has
the effect that the layout is triggered whenever a node moves.
However, if you have too many links, a full automatic link layout
will be too slow. An alternative way to ensure orthogonal links
is to use the orthogonal mode of IlvEnhancedPolylineLinkImage (and its
subclasses). This mode will ensure that the link shape remains
orthogonal, without analyzing all links to reduce link crossings
and overlaps. Therefore it can be more efficient than running
link layout in automatic layout mode. To enable the orthogonal
mode on a link, call:
enhancedLinkImage.setOrthogonal(true);
Automatic layout
If you must use automatic layout (setAutoLayout), be aware that the layout is
triggered whenever any event is fired that indicates a change of
the graph. In this case, it is important to optimize the events
by using adjusting sessions as explained in Events and listeners. This avoids that a
sequence of changes triggers many layouts and ensures that the
layout is only called once at the end of the sequence of changes.
JViews Diagrammer renderingDoneMode invocation
In JViews Diagrammer, the automatic layout
is false by default, but the graph layout may be invoked
automatically by JViews Diagrammer listeners when the diagram
becomes outdated. This happens when the graph structure has
changed because model objects have been added or removed. Or when
a diagram event, like a model property change or selection, has
impacted the bounding box of at least one graphic object. In this
case, JViews Diagrammer automatically runs the current graph
layout to keep the diagram accurate. However, the graph layout
call can be expensive for large graphs or for complex algorithms.
Sometimes, the event that triggered the layout does not justify a
new computation of the layout.
To help you control when the graph layout is invoked
automatically, IlvSDMEngine provides the property renderingDoneMode. This property is read
when JViews Diagrammer receives an event, such as a new
selection, a property change, the addition, or the removal of an
object in the model.
The possible values of the property renderingDoneMode
are:
- IlvSDMEngine.ALWAYS: The graph layout is always called automatically on events.
- IlvSDMEngine.NEVER: The graph layout is never called automatically on events.
- IlvSDMEngine.IF_BBOX_CHANGED: The graph layout is called on selection or property change only if the bounding box of the selected graphic object has changed. This mode is the default mode and is suitable for most cases, because the graph or link layout generally depends only on the position and size of the objects.
You can configure the renderingDoneMode
property in the style sheet or through the API.
In the style sheet, use one of the
following string values:
- IF_BBOX_CHANGED
- NEVER
- ALWAYS
Note
Whatever the value of this property, you can always manually
perform a layout using for example IlvSDMEngine.performLayout().