Graphic Components > Network Component > Network Component Services > Label Layout

JViews TGO allows you to place labels in a network automatically to make them easier to read. This placement overrides the default placement of labels in JViews TGO, namely:

Label layout allows you to reduce overlap between labels and other objects in the current view. Therefore, it is particularly useful for positioning labels on links. Figure 2.2 shows labels positioned by default. Figure 2.3 shows the same links with customized positioning of the labels through label layout.

images/labellayoutbefore.gif

Figure 2.2 Network Links without Label Layout

images/labellayoutafter.gif

Figure 2.3 Network Links with Label Layout

Note
Label layout tries to find the best position for your labels, but sometimes even this mechanism does not achieve attractive results. To get the best results, leave large spaces between network objects.

Label layout in JViews TGO uses the label layout of ILOG JViews. See the ILOG JViews Diagrammer Using Graph Layout Algorithms documentation for more details on label layout.

Using Label Layout

JViews TGO provides the IltAnnealingLabelLayout class (a subclass of IlvAnnealingLabelLayout) that moves the labels of the nodes and the links so that they do not overlap. If it is impossible to prevent some overlap, this class will minimize the overlap between different labels.

The class IlpNetworkView provides the following method for handling label layout:

void setLabelLayout (IltAnnealingLabelLayout layout);

This method sets the given layout for the specified view. This method is also available from the class IlpNetwork, for convenience.

Unlike node layout and link layout, label layout is not performed automatically when the content of the network changes. You need to call labelLayout.performLayout() explicitly. There is a toolbar button for triggering label layout computation. See the class IlpNetworkLabelLayoutButton.

Here is a typical example of how to use label layout.

How to Use Label Layout
IlpNetwork network = new IlpNetwork();
 
// fill the network with your elements
IltAnnealingLabelLayout labelLayout =  
  new IltAnnealingLabelLayout();
network.setLabelLayout(labelLayout);
labelLayout.performLayout();
network.setLabelLayout(null);

In this example you:

  1. Create the label layout.
IltAnnealingLabelLayout labelLayout =  
  new IltAnnealingLabelLayout();
  1. Attach this layout to the current network.
network.setLabelLayout(labelLayout);
  1. Perform the layout, placing the labels esthetically and where they will be easy to read.
labelLayout.performLayout();
  1. Optionally, detach the layout from the network and release the resources used by label layout. The positions of the labels are maintained.
network.setLabelLayout(null);

Defining the Labels You Want to Position

Label layout positions only the labels of links by default. You can choose to apply the layout to other types of object through the following methods:

void setObjects (IltLabelLayoutConstants[] types)
void setObjects (int index, IltLabelLayoutConstants type)
IltLabelLayoutConstants[] getObjects()
IltLabelLayoutConstants getObjects (int index)

or through the following convenience methods:

setUsesOthers(boolean flag)
setUsesLinks(boolean flag)
setUsesNetworkElements(boolean flag)
setUsesBTS(boolean flag)
setUsesLinearGroups(boolean flag)
setUsesPolyGroups(boolean flag)
setUsesRectGroups(boolean flag)
How to Apply Label Layout to Network Elements Only
IltAnnealingLabelLayout labelLayout = 
  new IltAnnealingLabelLayout();
labelLayout.setObjects(0, IltLabelLayoutConstants.NETWORK_ELEMENTS);
network.setLabelLayout(labelLayout);
network.performLabelLayout();
network.setLabelLayout(null); 

The method setObjects indicates whether a certain type of object will have its label placed by the label layout. In this example, only Network Elements will have their labels placed by the label layout.

How to Apply Label Layout to Network Elements Only Using CSS
Network {
  labelLayout: true;
}
 
 
LabelLayout {
  class: 'ilog.tgo.graphic.graphlayout.labellayout.IltAnnealingLabelLayout";
  objects[0]: NETWORK_ELEMENTS;
}

The property objects indicates whether a certain type of object will have its label placed by the label layout. In this example, only network elements will have their labels placed by the label layout.

Defining Obstacles

The label layout positions the labels of the objects by taking into account the obstacles that are in the network view. By default, all objects are considered as obstacles, but you can configure this behavior in CSS or through the API:

How to Specify Obstables in the Label Layout Using CSS
Network {
   labelLayout: true;
}
 
LabelLayout {
   class: 
'ilog.tgo.graphic.graphlayout.labellayout.IltAnnealingLabelLayout';
   obstacles[0]: NETWORK_ELEMENTS;
   obstacles[1]: LINKS;
}
How to Specify Obstables in the Label Layout Using the API
void setObstacles (IltLabelLayoutConstants[] types)
void setObstacles (int index, IltLabelLayoutConstants type)
IltLabelLayoutConstants[] getObstacles()
IltLabelLayoutConstants getObstacles (int index)

Constraints

The following constraints exist for label layout:

Please note that you can configure the label layout in a CSS file through the labelLayout property. For more information, see The LabelLayout Rule.