public class EdgeLabelOrientationSupport extends Object
EdgeLabelOrientationSupport
provides orientation and mirroring support for layout algorithms
with integrated edge labeling.
To calculate the position and orientation of edge labels whose placements are defined with the
PreferredPlacementDescriptor
, the OrientationLayout
would need the direction of the associated edge.
Since this direction is not available to the OrientationLayout
, because it is a wrapper, the calculation must be
done in the core layout algorithm itself with the help of the EdgeLabelOrientationSupport
.
Important: Since layout algorithms with integrated edge labeling cannot deal with ambiguous preferred placement
descriptors (combinations of the same setting, e.g., source or target for the
PlaceAlongEdge
), preProcessLabel(Graph, LabelLayoutData, Direction)
removes combinations and replaces the original descriptor with a non-ambiguous one during the layout
calculation.
Constructor and Description |
---|
EdgeLabelOrientationSupport()
Creates a new
EdgeLabelOrientationSupport instance. |
Modifier and Type | Method and Description |
---|---|
protected PreferredPlacementDescriptor |
createNonAmbiguous(PreferredPlacementDescriptor ambiguous)
Creates and returns a non-ambiguous
PreferredPlacementDescriptor of the given potentially ambiguous one. |
static YVector |
getEdgeLabelUpVector(PreferredPlacementDescriptor descriptor,
Direction segmentDirection)
Calculates the up vector of an edge label considering the preferred placement of the label as well as the direction of
the edge segment the label is attached to.
|
static YVector |
getLabelUpVector(double rightVectorAngle)
Calculates the up vector for a label whose right vector is rotated clockwise by the given angle.
|
static Direction |
getOrientedDirection(Direction direction,
LayoutOrientation orientation,
MirrorModes mirrorMask)
Transforms a direction of the layout to the oriented layout direction.
|
static boolean |
isOrientationMirrored(LayoutOrientation orientation,
MirrorModes mirrorMask)
Returns whether or not the orientation is mirrored.
|
void |
markPortLabelForFallbackPlacement(LabelLayoutData portLabel)
Marks the given port label for a non-port placement (fallback).
|
void |
postProcessLabel(Graph graph,
LabelLayoutData label)
Restores the original preferred placement and updates the label rotation according to the layout orientation.
|
void |
preProcessLabel(Graph graph,
LabelLayoutData label,
Direction segmentDirection)
Prepares the label for the core layout algorithm.
|
void |
replaceAmbiguousLabelDescriptors(Graph graph)
Replaces the
PreferredPlacementDescriptor s of all edge labels in the given graph with non-ambiguous descriptors. |
void |
resetAmbiguousLabelDescriptors(Graph graph)
Restores the
PreferredPlacementDescriptor s of all edge labels in the given graph with their original descriptors. |
static void |
updateLabelOrientation(LabelLayoutData label,
Direction segmentDirection)
Calculates and sets the up vector of an edge label considering the preferred placement of the label as well as the
direction of the edge segment the label is attached to.
|
public EdgeLabelOrientationSupport()
EdgeLabelOrientationSupport
instance.OrientationLayout
.OrientationLayout.setEdgeLabelConsiderationEnabled(boolean)
protected PreferredPlacementDescriptor createNonAmbiguous(PreferredPlacementDescriptor ambiguous)
PreferredPlacementDescriptor
of the given potentially ambiguous one.
The created descriptor will be one without any combinations of settings, e.g., source or target for the
PlaceAlongEdge
.
ambiguous
- an ambiguous PreferredPlacementDescriptor
PreferredPlacementDescriptor
public static final YVector getEdgeLabelUpVector(PreferredPlacementDescriptor descriptor, Direction segmentDirection)
descriptor
- the data describing the preferred label orientationsegmentDirection
- the direction the edge segment is pointing topublic static final YVector getLabelUpVector(double rightVectorAngle)
The up vector starts in the lower-left corner of the label and points up. If the label is paraxial it is
(0, -1)
. The right vector starts at the same point and points right. In a paraxial label it is
(1, 0)
.
rightVectorAngle
- the angle in radians the right vector is rotated bypublic static final Direction getOrientedDirection(Direction direction, LayoutOrientation orientation, MirrorModes mirrorMask)
direction
- direction in the layoutorientation
- the orientation of the layoutmirrorMask
- the mask to determine whether or not the orientation is mirroredpublic static final boolean isOrientationMirrored(LayoutOrientation orientation, MirrorModes mirrorMask)
orientation
- the orientation of the layoutmirrorMask
- the mask to determine whether or not the orientation is mirroredtrue
if the orientation is mirrored, false
otherwisepublic void markPortLabelForFallbackPlacement(LabelLayoutData portLabel)
The given edge label's PreferredPlacementDescriptor
will internally be changed such that its placement along edge
is either LabelPlacements.AT_SOURCE
or LabelPlacements.AT_TARGET
.
Algorithms that are executed after this call and before resetAmbiguousLabelDescriptors(Graph)
will handle port
labels like normal source or target labels.
IllegalStateException
- if replaceAmbiguousLabelDescriptors(Graph)
was never called for the graph containing the given label.replaceAmbiguousLabelDescriptors(Graph)
.portLabel
- an edge label that had a LabelPlacements.AT_SOURCE_PORT
or LabelPlacements.AT_TARGET_PORT
placement
preferenceLabelPlacements.AT_SOURCE_PORT
,
LabelPlacements.AT_TARGET_PORT
public void postProcessLabel(Graph graph, LabelLayoutData label)
The original PreferredPlacementDescriptor
that has been
replaced in preProcessLabel(Graph, LabelLayoutData, Direction)
gets restored. Then it moves and rotates the label box
in respect of the orientation.
This method is called by the core layout algorithm with the integrated edge labeling for each edge label after the location of the label is determined.
graph
- the graph to get the orientation information fromlabel
- the information about the edge label whose location is determinedpublic void preProcessLabel(Graph graph, LabelLayoutData label, Direction segmentDirection)
First, the preferred placement
of the edge label is replaced
by a non-ambiguous PreferredPlacementDescriptor
that has only relative references. This descriptor is
orientation independent and can be used in the core layout algorithm. Second, the method rotates the label box
in respect of its PreferredPlacementDescriptor
and the direction of the segment to which it belongs. After that
call, the core layout algorithm can use the geometry (Width
and
Height
) of the label to calculate its location.
This method is called by the core layout algorithm with the integrated edge labeling for each edge label before the layout algorithm uses the geometry of labels. It should be called as soon as the direction of the segment the label belongs to is determined.
graph
- the graph to get the orientation information fromlabel
- the information about the edge label whose segment direction is determinedsegmentDirection
- the direction of the segment the edge label belongs topublic void replaceAmbiguousLabelDescriptors(Graph graph)
PreferredPlacementDescriptor
s of all edge labels in the given graph with non-ambiguous descriptors.
The non-ambiguous descriptors are retrieved from the original descriptors. They describe only one of the possible placements.
This method should be called by a layout algorithm at the beginning of the layout calculation to assure that the label's placement is handled consistently.
graph
- the input graphpublic void resetAmbiguousLabelDescriptors(Graph graph)
PreferredPlacementDescriptor
s of all edge labels in the given graph with their original descriptors.
This method should be called by a layout algorithm at the end of the layout calculation to assure that the original state of the graph is not corrupted.
graph
- the input graphpublic static final void updateLabelOrientation(LabelLayoutData label, Direction segmentDirection)
label
- the data that describes the label orientation and is used for setting the new up vectorsegmentDirection
- the direction the edge segment is pointing togetEdgeLabelUpVector(PreferredPlacementDescriptor, Direction)