public abstract class AbstractLabeling extends AbstractLayoutStage
Labeling algorithms compute positions for labels in a given graph. The main goal is to place labels such that they do not overlap with other graph elements. Labeling algorithms do not modify positions of nodes and edges.
Generic labeling algorithms use the model associated with a label (i.e. node label model
for nodes and edge label model
for edges). The models are necessary to compute
a set of LabelCandidate
s, i.e., candidate positions for a label. Then, one best matching candidate from
the set will be selected. This selection depends on several preferences, e.g., if overlaps with nodes
are not allowed, candidates encoding overlapping positions will be ignored.
After one LabelCandidate
has been chosen, the label model's parameter is used for encoding the label position.
Therefore, the result of a generic labeling algorithm is one model parameter per label. The parameter is stored with the label
and expresses the label position with respect to the underlying label model.
This class provides a general frame, offering functionality which can be shared by other generic labeling algorithms.
To only place labels or a subset of labels, the main labeling methods label(LayoutGraph, Object)
, label(LayoutGraph, Object)
and label(LayoutGraph, YList, YList)
are offered.
As this class represents an AbstractLayoutStage
, it allows usage as a generic labeling stage. By combining it
with a
core layouter
, the labeling will take place after the
core layouter was executed
(applyLayout(LayoutGraph)
). This is especially useful if the core layouter does not support label handling.
Modifier and Type | Field and Description |
---|---|
static ILabelLayoutDpKey<Object> |
LABEL_MODEL_DPKEY
A
DataProvider key for mapping models to edge/node labels
The INodeLabelLayoutModel s and IEdgeLabelLayoutModel s linked to INodeLabelLayout s and
IEdgeLabelLayout s by this IDataProvider are taken as replacement models. |
Constructor and Description |
---|
AbstractLabeling()
Creates a new
AbstractLabeling instance with default settings. |
Modifier and Type | Method and Description |
---|---|
void |
applyLayout(LayoutGraph graph)
Places the labels in the graph after first executing the
core layouter . |
Object |
getAffectedLabelsDpKey()
Gets the
IDataProvider key to mark labels as selected for placement. |
double |
getProfit(LabelCandidate candidate)
Returns the profit for placing a
LabelCandidate with respect to the current
profit model . |
IProfitModel |
getProfitModel()
Gets the
IProfitModel for ranking the LabelCandidate s for labels. |
boolean |
isAutoFlippingEnabled()
Gets whether or not edge labels are automatically flipped if otherwise they would be upside-down.
|
boolean |
isEdgeGroupOverlapAllowed()
Gets whether or not edge labels may overlap with edges belonging to the same edge group as the label's edge.
|
boolean |
isEdgeLabelPlacementEnabled()
Gets whether or not labels assigned to edges are placed.
|
boolean |
isEdgeOverlapsRemovalEnabled()
Gets whether or not
label candidates that overlap with edges are removed. |
boolean |
isInternalNodeLabelMovingEnabled()
Gets whether or not internal node labels are allowed to move.
|
boolean |
isLabelOverlapsReducingEnabled()
Gets whether or not a post-processing step to reduce the number of label overlaps is applied.
|
boolean |
isNodeLabelPlacementEnabled()
Gets whether or not labels assigned to nodes are placed.
|
boolean |
isNodeOverlapsRemovalEnabled()
Gets whether or not
label candidates that overlap with nodes are removed. |
void |
label(LayoutGraph graph)
Places the labels of the input graph using a
IDataProvider registered to the input graph with the given key for
determining which labels to place. |
void |
label(LayoutGraph graph,
Object key)
Places the labels of the input graph using a
IDataProvider registered to the input graph with the given key for
determining which labels to place. |
void |
label(LayoutGraph graph,
YList nodeLabels,
YList edgeLabels)
Places the labels of the input graph restricting the placement to labels contained in the given lists.
|
void |
setAffectedLabelsDpKey(Object value)
Sets the
IDataProvider key to mark labels as selected for placement. |
void |
setAutoFlippingEnabled(boolean value)
Sets whether or not edge labels are automatically flipped if otherwise they would be upside-down.
|
void |
setEdgeGroupOverlapAllowed(boolean value)
Sets whether or not edge labels may overlap with edges belonging to the same edge group as the label's edge.
|
void |
setEdgeLabelPlacementEnabled(boolean value)
Sets whether or not labels assigned to edges are placed.
|
void |
setEdgeOverlapsRemovalEnabled(boolean value)
Sets whether or not
label candidates that overlap with edges are removed. |
void |
setInternalNodeLabelMovingEnabled(boolean value)
Sets whether or not internal node labels are allowed to move.
|
void |
setLabelOverlapsReducingEnabled(boolean value)
Sets whether or not a post-processing step to reduce the number of label overlaps is applied.
|
void |
setNodeLabelPlacementEnabled(boolean value)
Sets whether or not labels assigned to nodes are placed.
|
void |
setNodeOverlapsRemovalEnabled(boolean value)
Sets whether or not
label candidates that overlap with nodes are removed. |
void |
setProfitModel(IProfitModel value)
Sets the
IProfitModel for ranking the LabelCandidate s for labels. |
applyLayoutCore, getCoreLayout, setCoreLayout
public static final ILabelLayoutDpKey<Object> LABEL_MODEL_DPKEY
DataProvider
key for mapping models to edge/node labels
The INodeLabelLayoutModel
s and IEdgeLabelLayoutModel
s linked to INodeLabelLayout
s and
IEdgeLabelLayout
s by this IDataProvider
are taken as replacement models. This means that the
original model is internally replaced by another model when computing valid positions for the label. A model parameter
that fits the calculated position of the replacement model best is set for the original label model.
SliderEdgeLabelLayoutModel
can be used as replacement model.IDataProvider
registered with this key, then the original models will be used.public AbstractLabeling()
AbstractLabeling
instance with default settings.public void applyLayout(LayoutGraph graph)
core layouter
.applyLayout
in interface ILayoutAlgorithm
applyLayout
in class AbstractLayoutStage
label(LayoutGraph, Object)
to perform the actual labeling.graph
- the input graphlabel(LayoutGraph, Object)
public Object getAffectedLabelsDpKey()
IDataProvider
key to mark labels as selected for placement.
If a IDataProvider
is registered with this key, only the selected labels will be placed, while all other labels
are considered fixed.
The registered IDataProvider
needs to map from ILabelLayout
to Boolean
where true
indicates that a label should be placed and false
indicates that a label should be ignored.
label(LayoutGraph, Object)
or
label(LayoutGraph, YList, YList)
. Furthermore, if node labeling
or edge labeling
is disabled, the selection does not have any effect on the respective labels.null
. All labels are considered to be selected.IDataProvider
key for marking labels as selected or null
if all labels should be considered
selectedsetAffectedLabelsDpKey(Object)
public double getProfit(LabelCandidate candidate)
LabelCandidate
with respect to the current
profit model
.
Method IProfitModel.getProfit(LabelCandidate)
on the current profit model will be invoked to compute the actual
profit value.
The higher the profit (rank) of a candidate is, the more likely it will be chosen as actual position by the algorithm.
candidate
- a label candidate0
and 1
public IProfitModel getProfitModel()
IProfitModel
for ranking the LabelCandidate
s for labels.
The profit model is used when calculating the profit
of a candidate.
The higher the profit (rank) of a candidate is, the more likely it will be chosen as actual position by the algorithm.
SimpleProfitModel
IProfitModel
instance for ranking label candidatesIProfitModel
,
SimpleProfitModel
,
getProfit(LabelCandidate)
,
setProfitModel(IProfitModel)
public boolean isAutoFlippingEnabled()
false
. Edge labels being upside-down keep their orientation.true
, if edge labels automatically flip, false
otherwisesetAutoFlippingEnabled(boolean)
public boolean isEdgeGroupOverlapAllowed()
An edge group is a set of edges which share a common bus near the target or source node. They are defined using
IDataProvider
s registered with PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
and
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
.
false
. Edge labels are not allowed to overlap with edges of the same edge group.true
if edge labels may overlap with edges of the same edge group, false
otherwisePortConstraintKeys.SOURCE_GROUP_ID_DPKEY
,
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
,
setEdgeGroupOverlapAllowed(boolean)
public boolean isEdgeLabelPlacementEnabled()
selection
. If it is
disabled, edge labels marked via the selection will still be ignored. If enabled, then the selection
may determine whether a label is placed or not.true
. Edge labels will be placed.true
if edge labels should be placed, false
otherwisesetAffectedLabelsDpKey(Object)
,
setEdgeLabelPlacementEnabled(boolean)
public boolean isEdgeOverlapsRemovalEnabled()
label candidates
that overlap with edges are removed.
If overlapping candidates are not removed, they will be considered but get a penalty. Therefore, it is still less likely that an overlapping candidate is finally chosen.
The detection and removal of labels that overlap with edges may increase the runtime of this algorithm.
DefaultParameter
for node labels and DefaultParameter
for edge labels).false
. Candidates overlapping with edges are allowed.true
if candidates overlapping with edges are removed, false
otherwisesetEdgeOverlapsRemovalEnabled(boolean)
public boolean isInternalNodeLabelMovingEnabled()
A node label is internal if the label's boundaries are completely within the node's boundaries.
node labeling
is enabled.INodeLabelLayoutModel
s that restrict the positioning of labels (i.e.
non-free label models).false
. Internal node labels will not be moved.true
if internal node labels may be moved, false
otherwisesetInternalNodeLabelMovingEnabled(boolean)
public boolean isLabelOverlapsReducingEnabled()
IEdgeLabelLayoutModel
is of type FreeEdgeLabelLayoutModel
and node labels whose INodeLabelLayoutModel
is of type FreeNodeLabelLayoutModel
.false
. Post-processing to reduce overlaps is disabled.true
if a post-processing step for reducing the number of label overlaps is applied, false
otherwisesetLabelOverlapsReducingEnabled(boolean)
public boolean isNodeLabelPlacementEnabled()
selection
. If it is
disabled, node labels marked via the selection will still be ignored. If enabled, then the selection
may determine whether a label is placed or not.true
. Node labels will be placed.true
if node labels should be placed, false
otherwisesetAffectedLabelsDpKey(Object)
,
setNodeLabelPlacementEnabled(boolean)
public boolean isNodeOverlapsRemovalEnabled()
label candidates
that overlap with nodes are removed.
If overlapping candidates are not removed, they will be considered but get a penalty. Therefore, it is still less likely that an overlapping candidate is finally chosen.
The detection and removal of labels that overlap with nodes may increase the runtime of this algorithm.
DefaultParameter
for node labels and DefaultParameter
for edge labels).false
. Candidates overlapping with nodes are allowed.true
if candidates overlapping with nodes are removed, false
otherwisesetNodeOverlapsRemovalEnabled(boolean)
public final void label(LayoutGraph graph)
IDataProvider
registered to the input graph with the given key for
determining which labels to place.
Instead of considering the current selection key
, the IDataProvider
registered
with the given key will be used for selecting labels. Invoking this method has the same effect as first specifying the key
as selection key and then invoking label(LayoutGraph, Object)
.
graph
- the input graphpublic void label(LayoutGraph graph, Object key)
IDataProvider
registered to the input graph with the given key for
determining which labels to place.
Instead of considering the current selection key
, the IDataProvider
registered
with the given key will be used for selecting labels. Invoking this method has the same effect as first specifying the key
as selection key and then invoking label(LayoutGraph, Object)
.
graph
- the input graphkey
- the IDataProvider
key for label selectionpublic void label(LayoutGraph graph, YList nodeLabels, YList edgeLabels)
The selection
will not be considered; the given lists will define the selection of
labels that are to be placed.
node labeling
or edge labeling
is
disabled, then the labels of the respective given list will not be placed.graph
- the input graphnodeLabels
- a list of INodeLabelLayout
s defining the set of node labels that will be placededgeLabels
- a list of IEdgeLabelLayout
s defining the set of edge labels that will be placedpublic void setAffectedLabelsDpKey(Object value)
IDataProvider
key to mark labels as selected for placement.
If a IDataProvider
is registered with this key, only the selected labels will be placed, while all other labels
are considered fixed.
The registered IDataProvider
needs to map from ILabelLayout
to Boolean
where true
indicates that a label should be placed and false
indicates that a label should be ignored.
label(LayoutGraph, Object)
or
label(LayoutGraph, YList, YList)
. Furthermore, if node labeling
or edge labeling
is disabled, the selection does not have any effect on the respective labels.null
. All labels are considered to be selected.value
- the IDataProvider
key for marking labels as selected or null
if all labels should be considered
selectedgetAffectedLabelsDpKey()
public void setAutoFlippingEnabled(boolean value)
false
. Edge labels being upside-down keep their orientation.value
- true
, if edge labels automatically flip, false
otherwiseisAutoFlippingEnabled()
public void setEdgeGroupOverlapAllowed(boolean value)
An edge group is a set of edges which share a common bus near the target or source node. They are defined using
IDataProvider
s registered with PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
and
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
.
false
. Edge labels are not allowed to overlap with edges of the same edge group.value
- true
if edge labels may overlap with edges of the same edge group, false
otherwisePortConstraintKeys.SOURCE_GROUP_ID_DPKEY
,
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
,
isEdgeGroupOverlapAllowed()
public void setEdgeLabelPlacementEnabled(boolean value)
selection
. If it is
disabled, edge labels marked via the selection will still be ignored. If enabled, then the selection
may determine whether a label is placed or not.true
. Edge labels will be placed.value
- true
if edge labels should be placed, false
otherwisesetAffectedLabelsDpKey(Object)
,
isEdgeLabelPlacementEnabled()
public void setEdgeOverlapsRemovalEnabled(boolean value)
label candidates
that overlap with edges are removed.
If overlapping candidates are not removed, they will be considered but get a penalty. Therefore, it is still less likely that an overlapping candidate is finally chosen.
The detection and removal of labels that overlap with edges may increase the runtime of this algorithm.
DefaultParameter
for node labels and DefaultParameter
for edge labels).false
. Candidates overlapping with edges are allowed.value
- true
if candidates overlapping with edges are removed, false
otherwiseisEdgeOverlapsRemovalEnabled()
public void setInternalNodeLabelMovingEnabled(boolean value)
A node label is internal if the label's boundaries are completely within the node's boundaries.
node labeling
is enabled.INodeLabelLayoutModel
s that restrict the positioning of labels (i.e.
non-free label models).false
. Internal node labels will not be moved.value
- true
if internal node labels may be moved, false
otherwiseisInternalNodeLabelMovingEnabled()
public void setLabelOverlapsReducingEnabled(boolean value)
IEdgeLabelLayoutModel
is of type FreeEdgeLabelLayoutModel
and node labels whose INodeLabelLayoutModel
is of type FreeNodeLabelLayoutModel
.false
. Post-processing to reduce overlaps is disabled.value
- true
if a post-processing step for reducing the number of label overlaps is applied, false
otherwiseisLabelOverlapsReducingEnabled()
public void setNodeLabelPlacementEnabled(boolean value)
selection
. If it is
disabled, node labels marked via the selection will still be ignored. If enabled, then the selection
may determine whether a label is placed or not.true
. Node labels will be placed.value
- true
if node labels should be placed, false
otherwisesetAffectedLabelsDpKey(Object)
,
isNodeLabelPlacementEnabled()
public void setNodeOverlapsRemovalEnabled(boolean value)
label candidates
that overlap with nodes are removed.
If overlapping candidates are not removed, they will be considered but get a penalty. Therefore, it is still less likely that an overlapping candidate is finally chosen.
The detection and removal of labels that overlap with nodes may increase the runtime of this algorithm.
DefaultParameter
for node labels and DefaultParameter
for edge labels).false
. Candidates overlapping with nodes are allowed.value
- true
if candidates overlapping with nodes are removed, false
otherwiseisNodeOverlapsRemovalEnabled()
public void setProfitModel(IProfitModel value)
IProfitModel
for ranking the LabelCandidate
s for labels.
The profit model is used when calculating the profit
of a candidate.
The higher the profit (rank) of a candidate is, the more likely it will be chosen as actual position by the algorithm.
SimpleProfitModel
value
- a IProfitModel
instance for ranking label candidatesIProfitModel
,
SimpleProfitModel
,
getProfit(LabelCandidate)
,
getProfitModel()