Search this API

y.layout
Class EdgeLabelOrientationSupport

java.lang.Object
  extended by y.layout.EdgeLabelOrientationSupport

public class EdgeLabelOrientationSupport
extends Object

Helper for layouter with integrated edge labeling to support orientation and mirroring.

To calculate the position and orientation of edge labels, whose placements are defined with the PreferredPlacementDescriptor, the OrientationLayouter would need the direction of the associated edge. Since this direction is not available for the OrientationLayouter, because it is a wrapper, the calculation must be done in the core layouter itself with the help of the EdgeLabelOrientationSupport.

Important: Since all layouters with integrated edge labeling could not deal with ambiguous preferred placement descriptors (combinations of the same setting e.g. source or target for the PreferredPlacementDescriptor.getPlaceAlongEdge()), preProcessLabel(y.base.Graph, LabelLayoutData, Direction) removes combinations and replaces the original descriptor with a "non-ambiguous" one during the layout calculation.


Constructor Summary
EdgeLabelOrientationSupport()
          Creates an instance.
 
Method Summary
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 rightVectorAngle.
static Direction getOrientedDirection(Direction direction, byte orientation, int mirrorMask)
          Transforms a direction of the layout to the oriented layout.
static boolean isOrientationMirrored(byte orientation, int mirrorMask)
          Returns whether or not the orientation is mirrored.
 void postProcessLabel(Graph graph, LabelLayoutData label)
          Called by the core layouter with the integrated edge labeling for each edge label after the location of the label is determined.
 void preProcessLabel(Graph graph, LabelLayoutData label, Direction segmentDirection)
          Called by the core layouter with the integrated edge labeling for each edge label before the layouter uses the labels geometry.
 void replaceAmbiguousLabelDescriptors(Graph graph)
          Replaces the PreferredPlacementDescriptors of all edge labels in the given graph with non-ambiguous descriptors.
 void resetAmbiguousLabelDescriptors(Graph graph)
          Restores the PreferredPlacementDescriptors of all edge labels in the given graph with their orignial 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EdgeLabelOrientationSupport

public EdgeLabelOrientationSupport()
Creates an instance. Since this class handles the orientation of the edge labels, the core layouter should switch the calculation in its OrientationLayouter off.

Method Detail

replaceAmbiguousLabelDescriptors

public void replaceAmbiguousLabelDescriptors(Graph graph)
Replaces the PreferredPlacementDescriptors of all edge labels in the given graph with non-ambiguous descriptors.

It should be called by a layouter at the beginning of layout calculation to assure that the label's placement is handled consistently.


resetAmbiguousLabelDescriptors

public void resetAmbiguousLabelDescriptors(Graph graph)
Restores the PreferredPlacementDescriptors of all edge labels in the given graph with their orignial descriptors.

It should be called by a layouter at the end of layout calculation to assure that the original state of the graph is not corrupted.


preProcessLabel

public void preProcessLabel(Graph graph,
                            LabelLayoutData label,
                            Direction segmentDirection)
Called by the core layouter with the integrated edge labeling for each edge label before the layouter uses the labels geometry. The method should be called as soon as the direction of the segment the label belongs to is determined.

First it replaces the LabelLayoutData.getPreferredPlacementDescriptor() of the edge label by a PreferredPlacementDescriptor that has only relative references. This descriptor is orientation independent and could be used in the core layouter. Second it rotates the label in respect of it PreferredPlacementDescriptor and the direction of the segment it belongs to. After that call the core layouter could use the geometry (LabelLayoutData.getWidth() and LabelLayoutData.getWidth()) of the label to calculate its location.

Parameters:
graph - graph to get the orientation information from
label - edge label whose segment direction is determined
segmentDirection - direction of the segment the edge label belongs to

postProcessLabel

public void postProcessLabel(Graph graph,
                             LabelLayoutData label)
Called by the core layouter with the integrated edge labeling for each edge label after the location of the label is determined.

It restores the original LabelLayoutData.getPreferredPlacementDescriptor() that has been replaced in preProcessLabel(y.base.Graph, LabelLayoutData, Direction). Then it move and rotates the label in respect of the orientation.

Parameters:
graph - graph to get the orientation information from
label - edge label whose location is determined

getOrientedDirection

public static Direction getOrientedDirection(Direction direction,
                                             byte orientation,
                                             int mirrorMask)
Transforms a direction of the layout to the oriented layout.

Parameters:
direction - direction in the layout
orientation -
mirrorMask - @return the direction in the oriented layout

isOrientationMirrored

public static boolean isOrientationMirrored(byte orientation,
                                            int mirrorMask)
Returns whether or not the orientation is mirrored.

Parameters:
orientation -
mirrorMask -
Returns:
true if the orientation is mirrored; false otherwise

updateLabelOrientation

public 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.

Parameters:
label - The data that describes the label orientation and is used to set the new up vector.
segmentDirection - The direction the edge segment is pointing to.
See Also:
getEdgeLabelUpVector(PreferredPlacementDescriptor, Direction)

getEdgeLabelUpVector

public 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.

Parameters:
descriptor - The data describing the preferred label orientation.
segmentDirection - The direction the edge segment is pointing to.
Returns:
An up vector for the edge label that considers the preferred placement of the label as well as the direction of the edge segment the label is attached to.

getLabelUpVector

public static YVector getLabelUpVector(double rightVectorAngle)
Calculates the up vector for a label whose right vector is rotated clockwise by the given rightVectorAngle.

Parameters:
rightVectorAngle - The angle in radians the right vector is rotated by.
Returns:
The up vector for a label whose right vector is rotated clockwise by the given angle.

© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.