Layout exceptions

Inappropriate-graph exception

Some layout algorithms can only deal with a specific type of graph.If the layout is performed with an inappropriate graph, an exception of type IlvInappropriateGraphException is thrown. However, this exception type occurs rather seldom, because most layout algorithms try to work silently in the best possible way with inappropriate graphs. For instance, the Tree Layout will silently handle graphs that are not trees without throwing this exception. The Tree Layout will in this case consider a spanning tree of the input graph for the layout.

The error handling differs depending on whether you use a diagram component with CSS styling, or whether you call layout in Java™ directly.

Example of inappropriate-graph exception

In CSS

The graph layout renderer catches the exception silently and logs it to the logger ilog.views.sdm.renderer.graphlayout. See

http://java.sun.com/javase/7/docs/technotes/guides/logging

to learn more about the Java logging facilities available since JDK 1.4. Usually, it is more convenient not to receive this exception. However, if you want to receive it, add to the GraphLayout and LinkLayout sections of your style sheet:

 

graphLayoutExceptionPassedOn: "true";

In this case, all graph layout exceptions are converted into a run-time exception and re-thrown by the graph layout renderer.

In Java

You have to catch the exception yourself and handle the error or report the error to the user in an suitable way. Example:

 

try {

 layout.performLayout();

} catch (IlvInappropriateGraphException ex) {

  ... handle the exception here ...

}

Inappropriate-link exception

This exception indicates that a particular type of link or link connector cannot be used for the layout algorithm. In general, the following link types can be used safely with all layout algorithms:

The following link connector types can be used with all layout algorithms.

Link connectors of type IlvPinLinkConnector can be used only in the following situations:

How to use IlvPinLinkConnector

When?

With which layout?

Always

Grid Layout

Hierarchical Layout

Link Layout

Random Layout

Only if no link clip interface is provided

Bus Layout

Circular Layout

Topological Mesh Layout

Uniform Length Edges Layout

Never

Tree Layout

See Link clipping for details.

Link connectors of other types can sometimes be used with some layouts. However, it is recommended to use only the link connectors listed for Hierarchical Layout, Tree Layout and Link Layout.

The error handling differs depending on whether you use a diagram component with CSS styling, or work directly in Java.

Example of Inappropriate-link exception

In CSS

By default, the graph layout renderer installs appropriate links and link connectors automatically when layout is performed. It internally calls the method EnsureAppropriateLinks and replaces the inappropriate links and link connectors by instances of IlvPolylineLinkImage and IlvSDMFreeLinkConnector. However it is recommended to specify appropriate link classes and link connector classes in CSS right from the beginning, because the link replacement is time-consuming and the result is sometimes confusing.

If you need to disable the automatic handling of inappropriate links and link connectors, add to the GraphLayout and LinkLayout sections of the style sheet:

 

ensureAppropriateLinks: "false";

In this case, the graph layout renderer catches the exception silently and logs it to the logger ilog.views.sdm.renderer.graphlayout, but it does not replace any links or link connectors. See

http://java.sun.com/javase/7/docs/technotes/guides/logging

to learn more about the Java logging facilities available since JDK 1.4. Usually, it is more convenient not to receive this exception. However, if you still want to receive it, add in the GraphLayout and LinkLayout sections of your style sheet:

 

graphLayoutExceptionPassedOn: "true";

In this case, all graph layout exceptions are converted into a run-time exception and re-thrown by the graph layout renderer.

In Java

If you are not sure whether the link types are correct for a specific layout, you can call the method

 

IlvGraphLayoutUtil.EnsureAppropriateLinkTypes(

                               IlvGrapherAdapter grapherAdapter,

                               IlvGraphLayout layout,

                               boolean toStraightLine,

                               boolean traverse,

                               boolean interGraphLinks,

                               boolean redraw)

This method analyzes the graph and replaces inappropriate links by new instances of IlvPolylineLinkImage.

If you are not sure whether the link connectors are correct for a specific layout, you can call the method

 

IlvGraphLayoutUtil.EnsureAppropriateLinkConnectors(

                               IlvGrapherAdapter grapherAdapter,

                               IlvGraphLayout layout,

                               boolean moveableConnectionPoints,

                               boolean traverse,

                               boolean redraw)

This method analyzes the graph and replaces inappropriate link connectors by new instances of IlvFreeLinkConnector.

If you want to do both at the same time, you can call the method

 

IlvGraphLayoutUtil.EnsureAppropriateLinks(IlvGraphLayout layout,

                                                    boolean redraw)

This method analyzes the graph and replaces inappropriate links and link connectors of the graph that is attached to the layout.

If the layout fails with an inappropriate-link exception, you can fix the situation quite easily, as demonstrated in the following code:

 

try {

  layout.performLayout();

} catch (IlvInappropriateLinkException ex) {

  IlvGraphLayoutUtil.EnsureAppropriateLinks(ex, redraw);

  // and now, try layout a second time:

  try {

    layout.performLayout();

  } catch (IlvGraphLayoutException ex2) {

  }

}

The class IlvGraphLayoutUtil provides further variants of the “ Ensure ...” methods. See the Java API Reference Manual for more information.