- I
- I
Remarks
This algorithm places the labels of a graph without moving its nodes or edges. It can switch between two internal implementations. By default, it generates high quality label placements even for difficult instances. This especially holds true if the label models allow a large number of different LabelCandidates, i.e., there is a high potential for optimizations.
If the duration of the calculation is of utmost importance, the internal algorithm can be changed to a simpler implementation by setting stopDuration to ZERO. On the downside, the results will not be as good as those of the default mode.
In default mode, this algorithm reduces the labeling problem to the maximum independent set (MIS) problem and solves the problem using simulated annealing. It is inspired by the article from Christensen, Marks and Shieber: A General Cartographic Labeling Algorithm.
Concept
Generic labeling algorithms use the label candidate factory associated with a label (see nodeLabelCandidates for node labels and edgeLabelCandidates for edge labels). The factories are necessary to compute a set of LabelCandidates, i.e., candidate positions for a label. Then, one best matching candidate from the set will be selected by the algorithm. This selection depends on several preferences, e.g., the custom weights given by weight, the specified edgeLabelCandidateProcessors, as well as the associated EdgeLabelPreferredPlacement (for edge labels).
For high quality results, it is recommended to use free edge label candidates and free node label candidates which allow free positioning of labels. Note that this usually induces a higher runtime compared to using a more restricted candidate factory (e.g. addDiscreteCandidates).
Features
By combining this stage with a coreLayout, the labeling will take place after the core layout was executed (applyLayoutImpl). This is especially useful if the core layout does not support label handling.
Performance
Specifying a stopDuration can reduce the time the GenericLabeling algorithm takes to produce a result. The acceleration is achieved by loosening the requirements for terminating the incremental improvement of the label positions. It should be noted that the stopDuration is not a guarantee for the maximum time spent, as the algorithm still has to produce a valid result.
The qualityTimeRatio can be used to specify a preference for the balance between the quality of the calculated result and the time spent on calculating it.
Default Values of Properties
| Name | Default | Description |
|---|---|---|
| coreLayout | null | |
| defaultEdgeLabelingCosts | LabelingOptimizationStrategy.BALANCED | The different types of preferences for the placement of the edge labels are balanced. |
| defaultNodeLabelingCosts | LabelingOptimizationStrategy.BALANCED | The different types of preferences for the placement of the node labels are balanced. |
| deterministic | true | Labeling results are deterministic. |
| qualityTimeRatio | 1.0 | |
| scope | LabelingScope.ALL | All labels are affected. |
| stopDuration | TimeSpan.MAX_VALUE | There is no time limit. |
See Also
Developer's Guide
Members
Constructors
Creates a new instance of GenericLabeling with default settings.
Parameters
Properties
Gets or sets the core ILayoutAlgorithm that is wrapped by this stage.
Property Value
Default Value
Defined in
LayoutStageBase.coreLayoutGets or sets the default LabelingCosts for edge labels.
The labeling algorithm chooses from a set of valid label positions (specified by EdgeLabelCandidates). The LabelingCosts allow specifying preferences on the costs for different types of positions. For example, whether a position where a label crosses an edge should have a high cost and, thus, is less likely chosen by the algorithm (see edgeOverlapCost).
Use edgeLabelingCosts to specify individual labeling costs for an edge label. The default costs are only applied for labels without individual costs.
Property Value
Throws
- Exception ({ name: 'ArgumentError' })
- if the LabelingCosts are
null
Default Value
See Also
Gets or sets the default LabelingCosts for node labels.
The labeling algorithm chooses from a set of valid label positions (specified by NodeLabelCandidates). The LabelingCosts allow specifying preferences on the costs for different types of positions. For example, whether a position where a label crosses an edge should have a high cost and, thus, is less likely chosen by the algorithm (see edgeOverlapCost).
Use nodeLabelingCosts to specify individual costs for a node label. The default costs are only applied for labels without individual costs.
Property Value
Throws
- Exception ({ name: 'ArgumentError' })
- if the LabelingCosts are
null
Default Value
See Also
Property Value
true if this algorithm works deterministically, false otherwiseDefault Value
Gets or sets a value that determines whether this stage should do anything but execute the coreLayout.
By default, when constructed, stages should be enabled. Users may disable a stage's functionality by setting this property to false.
Stages that can guarantee that the graph will not change can choose to not even execute the coreLayout when disabled.
Defined in
LayoutStageBase.enabledProperty Value
true if internal node labels may be moved, false otherwiseDefault Value
Sample Graphs
false - internal labels were not moved, even though they overlapThe larger the ratio, the better the quality of the resulting label placement but the longer it may take to perform the calculation.
The value must lie within [0,1].
Property Value
0.0 (low quality, fast) and 1.0 (high quality, slow)Throws
- Exception ({ name: 'ArgumentError' })
- if the specified ratio is outside the interval
[0,1]
Default Value
Property Value
true if a post-processing step for reducing the number of label overlaps is applied, false otherwiseDefault Value
Gets or sets which labels may be placed.
Default Value
See Also
Developer's Guide
API
- scope
Gets or sets the time limit for this algorithm.
Throws
- Exception ({ name: 'ArgumentError' })
- if the given stop duration is negative
Default Value
Methods
Implementation of the ILayoutAlgorithm interface and main entry point for the layout calculation.
Parameters
- graph: LayoutGraph
- The graph to apply the layout to.
Defined in
LayoutStageBase.applyLayoutPlaces the labels in the graph after first executing the coreLayout.
createLayoutData
(graph: LayoutGraph): GenericLabelingData<LayoutNode, LayoutEdge, LayoutNodeLabel, LayoutEdgeLabel>Returns an instance of LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel> that can be used to perform item-specific configurations for the GenericLabeling.
createLayoutData
(graph: LayoutGraph): GenericLabelingData<LayoutNode, LayoutEdge, LayoutNodeLabel, LayoutEdgeLabel>Parameters
- graph: LayoutGraph
- the graph that determines the generic type arguments of the created layout data
Return Value
- GenericLabelingData<LayoutNode, LayoutEdge, LayoutNodeLabel, LayoutEdgeLabel>
- an instance of layout data that can be used to perform item-specific configurations for the given GenericLabeling.
Returns an instance of LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel> that can be used to perform item-specific configurations for the GenericLabeling.
LayoutExecutor type is available at runtime.Parameters
- graph?: IGraph
- the graph that determines the generic type arguments of the created layout data
Return Value
- GenericLabelingData<INode, IEdge, ILabel, ILabel>
- an instance of layout data that can be used to perform item-specific configurations for the given GenericLabeling.