A label placement algorithm is not a graph layout algorithm in
the sense that it does not use the class IlvGraphModel and it is not a subclass of IlvGraphLayout. However, the labeling
framework has many similarities to the graph layout framework.
Usually, a label is a text or
decoration that should be placed close to some graphic object
because the label denotes the meaning of the graphic object. The
label should not be overlapped by obstacles because this would make
it unreadable. If there are many potential positions for one label,
the automatic label placement algorithm should find the best
position for the label, so that it is close to its graphic object,
not too close to unrelated objects, and not overlapped by any
obstacle.
Labels occur in many application areas:
diagrams, geographic maps, charts, and so on. The Labeling Layout
framework can be applied to all these areas, that is, it is not
restricted to placing labels in a graph. For example, if you want
to label cities in a geographic map, you can use the Annealing
Label Layout algorithm with appropriate point label descriptors.
For simplicity, this topic shows how to place labels at links in
a graph.
The label layout framework distinguishes
between:
- Graphic objects called labels that must be placed
- Graphic objects called obstacles that must not move but occupy space that is not available for the labels
- Graphic objects that are ignored, that is, they are not moved nor considered as occupying space; every graphic object that is neither a label nor an obstacle is ignored
A label should not overlap any obstacle or
other label. In fact, this strict condition is not feasible if
there is not enough free space for the labels; in this situation
the label layout algorithm tries to reduce the amount of overlaps.
In Rogue Wave JViews, graphic objects (subclasses of
IlvGraphic
) are contained in a manager ( IlvManager), and graphs are managed by
graphers ( IlvGrapher, which is a subclass of
IlvManager
). Because the Label Layout algorithms can be applied not only to
graphs but also to any graphic objects, the algorithms work on
IlvManager
. Consequently, a label layout algorithm is not a subclass of IlvGraphLayout and does
not use an IlvGraphModel. Rogue Wave JViews Diagrammer provides
a label layout framework that is (despite many similarities)
completely independent from the graph layout framework.
Rogue Wave JViews
Diagrammer provides a Swing component that encapsulates a
manager and the view that displays the manager. It uses a
model-view architecture, that is, application objects must be
provided as an SDM model, and a style sheet (CSS file) describes
how the corresponding graphic objects are added to the manager
and are displayed in the view.
You can use the Label Layout algorithm
in the following ways:
- In a diagram component: You specify the label layout in CSS format. The diagram component loads this specification and automatically applies the label layout when necessary. The diagram component recognizes only labels of nodes and links of the types IlvGeneralNode, IlvGeneralLink, IlvSDMCompositeNode, and IlvSDMCompositeLink.
- In an application that uses Rogue Wave JViews managers: Instead of using style files, you access the API of the label layout directly. This is suitable for applications that do not need the model-view architecture. It is necessary for applications that requires the automatic placement of labels that are not part of
IlvGeneralNode
,IlvGeneralLink
,IlvSDMCompositeNode
, andIlvSDMCompositeLink
.
If you have implemented your own data structures or use
third-party data structures that represent labels, you can
provide an adapter between your data structures and the labeling
model. This complex application of the label layout package is
explained in Defining your own labeling model.