Both types of graph elements, i.e., nodes and edges, can have one or more labels that can be used to show descriptive text for the element. The label's purpose is served best when it is both readable and also near its element, where readability most importantly results from the label being placed so that it does not overlap with other graph elements.
The yFiles library offers advanced labeling algorithms that automatically generate label arrangements that, whenever feasible, completely eliminate all overlaps, or minimize the number thereof otherwise. Labeling algorithms can be applied in two different scenarios: generic labeling and integrated labeling.
Generic labeling is independent of any layout algorithms and can be applied to any kind of diagram. It generates label placements without altering node positions, node sizes, or edge paths.
Integrated labeling, in contrast, is directly provided by some layout algorithms as an integrated part of the layout calculation. It allows to consider labels as part of the overall layout.
Integrated labeling's advantage is that, by design, it can prevent label overlaps completely. Generic labeling cannot always achieve this, since it has to deal with the existing node positions, node sizes, and edge paths. However, the graph's dimensions will remain constant or grow only minimally with generic labeling.
Both node label and edge label have associated a so-called "label model," that defines a set of valid positions where the label can be placed relative to its respective graph element. In the context of automatic label placement, all valid positions are at the same time "candidates" among which a labeling algorithm can choose the best match to ultimately place the label.
In terms of minimization of overlaps, more candidates mean better prospects for the outcome of a generic labeling algorithm.
For both generic labeling as well as integrated edge labeling, labels and label models are set up using the API provided by IGraph. See also the Label Support section in the yFiles WPF Developer's Guide (UI Part).
For generic labeling around a node, FreeNodeLabelModel is a much better choice for a node label model than any on the discrete node label models. However, FreeNodeLabelModel allows for unspecified label positions only, while the positions of the discrete node label models are all predefined.
For generic labeling, FreeEdgeLabelModel with its large number of nearly continuous positions is the best choice for an edge label model, followed by the slider edge label models.
Integrated labeling also favors FreeEdgeLabelModel, followed by SliderEdgeLabelModel, since it does not work with the candidates initially. Instead, it first computes an optimal location for the label, and then tries to find the best matching label position for that location in the given label model.
A generic labeling algorithm computes label positions for the labels from a
given graph so that they, ideally, do not overlap with each other or with graph
elements.
It does so without altering nodes or edges in any way.
As an option, the set of labels can be restricted to node labels only or to
edge labels only.
Figure 5.86, “Class hierarchy for labeling algorithms” shows the class hierarchy of the generic
labeling algorithms that are provided in the
yWorks.yFiles.Layout.Labeling
namespace.
The labeling algorithm uses the model that is associated with a label to get the available candidate positions. From this set of candidates it then chooses one that best matches the label position it has calculated. The label model's model parameter is then used to encode this position.
It is important to understand that the result of a labeling algorithm is one model parameter per processed label, which is directly stored with the label after calculation. This model parameter expresses the calculated label position with respect to the corresponding label model, and it is only valid in the context of this label model. To get the actual location of a label after the labeling algorithm has finished, both model parameter and corresponding label model are necessary.
The base class for all major layout algorithms, class
CanonicMultiStageLayouter
, allows to
conveniently enable/disable generic labeling for each layout run.
The labeling algorithm is then invoked after the actual layout algorithm has
finished.
Additionally, the labeling algorithm itself can also be set.
Class CanonicMultiStageLayouter provides the following labeling-related properties:
bool LabelLayouterEnabled { get; set; } |
|
| Description | Allows to enable/disable generic as well as integrated labeling. |
ILayoutStage LabelLayouter { get; set; } |
|
| Description | Determines the actual labeling algorithm to be used. |
Generic labeling is set up using the label layout layout stage support provided by the base class of the layout algorithms, class CanonicMultiStageLayouter:
IncrementalHierarchicLayouter ihl = new IncrementalHierarchicLayouter(); // Setting up generic edge labeling. AbstractLabelingAlgorithm labeler = new GreedyMISLabeling(); labeler.PlaceNodeLabels = false; ihl.LabelLayouter = labeler; ihl.LabelLayouterEnabled = true;
Integrated labeling denotes automatic edge label placement as an integrated part of a layout algorithm. All edge labels of a graph are arranged in such a manner that there are no overlaps of edge labels with each other or with graph elements.
Table 5.54, “Layout support for integrated labeling” lists the major layout algorithms that provide support for integrated labeling.
Table 5.54. Layout support for integrated labeling
| Layout Style | Classname | Note |
|---|---|---|
| Hierarchical | IncrementalHierarchicLayouter |
With class IncrementalHierarchicLayouter, integrated labeling can be conveniently enabled using appropriate configuration methods. See the description of the hierarchical layout style for more information. |
| Orthogonal | OrthogonalLayouter |
See the descriptions of orthogonal layout, directed orthogonal layout, and orthogonal layout of grouped graphs for more information. |
| Tree | TreeLayouter |
Integrated labeling can conveniently be enabled using appropriate configuration methods. See the descriptions of directed tree layout and generic tree layout for more information. |
Integrated labeling is most conveniently triggered using the corresponding properties of the layout algorithms that support it. For example:
IncrementalHierarchicLayouter ihl = new IncrementalHierarchicLayouter(); // Enabling integrated edge labeling. ihl.IntegratedEdgeLabeling = true;
Example 5.34, “Using class LabelLayoutTranslator” shows how to configure integrated labeling
in the absence of an appropriate configuration method using LabelLayoutTranslator
.
This class converts label layout information so that it is understood by a layout
algorithm.
Example 5.34. Using class LabelLayoutTranslator
void UseIntegratedLabeling(CanonicMultiStageLayouter layouter) {
// Use integrated labeling support, and let class LabelLayoutTranslator do
// the conversion of information held by an edge label's IEdgeLabelLayout
// object to data provider-based information that is understood by the
// algorithm.
layouter.LabelLayouter = new LabelLayoutTranslator();
layouter.LabelLayouterEnabled = true;
}
The layout module class LabelingModule.cs from the LayoutModulesWindow demo application presents the setup of a labeling algorithm in an application context. NodeLabelingWindow and EdgeLabelingWindow show how to configure node labels/edge labels) and the corresponding node label models/edge label models) as well as how to apply generic labeling.
|
Copyright ©2004-2011, yWorks GmbH. All rights reserved. |