Search this API

y.view
Class AutoRotationSliderEdgeLabelModel

java.lang.Object
  extended by y.view.AutoRotationSliderEdgeLabelModel
All Implemented Interfaces:
EdgeLabelModel

public class AutoRotationSliderEdgeLabelModel
extends java.lang.Object
implements EdgeLabelModel

Special EdgeLabelModel implementation used specifically for labels that are being rotated automatically according to the path of the edge. This model allows for the specification of a rotation center around which the label is being rotated, as well as where the rotation center is located relative to the edge path.
To use this label model do the following:

  EdgeLabel label = edge.createLabel();

  AutoRotationSliderEdgeLabelModel model = new AutoRotationSliderEdgeLabelModel();
  //configure
  model.setDistance(0.0d);

  //register
  label.setLabelModel(model);
  label.setModelParameter(model.getDefaultParameter());
 
Note that this implementation is currently not being serialized.

See Also:
setDistance(double), setAngle(double), setAnchorRatioX(double), setAnchorRatioY(double)
 

Nested Class Summary
static class AutoRotationSliderEdgeLabelModel.Handler
          Provides GraphML (de-)serialization support for AutoRotationSliderEdgeLabelModel and its parameters.
 
Constructor Summary
AutoRotationSliderEdgeLabelModel()
           
 
Method Summary
 java.lang.Object createModelParameter(OrientedRectangle labelBounds, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Creates a model parameter that represents the given edge label position within this model.
protected  double determineRotationAngle(double dx, double dy)
          Callback method that determines the rotation angle for a given edge segment's slope.
 double getAnchorRatioX()
          Returns the position of the rotation point as a ratio within in the label's bounds.
 double getAnchorRatioY()
          Returns the position of the rotation point as a ratio within in the label's bounds.
 double getAngle()
          Returns the angle between the base line of the label and the edge segment.
 java.lang.Object getDefaultParameter()
          Returns a default parameter that indicates a position at the center of the edge's path.
 double getDensity()
          Yields the density factor that influences the number of candidates that are yield during getLabelCandidates(y.layout.EdgeLabelLayout, y.layout.EdgeLayout, y.layout.NodeLayout, y.layout.NodeLayout).
 double getDistance()
          Determines how far away from the edge's path the rotation point lies.
 YList getLabelCandidates(EdgeLabelLayout labelLayout, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Returns all EdgeLabelCandidates that describe valid label positions within this model.
 OrientedRectangle getLabelPlacement(YDimension labelSize, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout, java.lang.Object param)
          Returns the oriented box of the label for the position encoded by the given model parameter.
protected  YPointPath getPointPath(EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Returns the point path associated with the given edge layout.
 double getRotationAngle(EdgeLabel label)
          Returns the current rotation angle for the given label for this model.
 double getRotationAngle(EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout, java.lang.Object param)
          Returns the rotation angle for the given set of entities that would be used by this instance of the label model.
 void setAnchorRatioX(double anchorRatioX)
          Sets the relative position of the rotation point as a ratio within in the label's bounds.
 void setAnchorRatioY(double anchorRatioY)
          Sets the relative position of the rotation point as a ratio within in the label's bounds.
 void setAngle(double angle)
          Sets the angle between the base line of the label and the edge segment.
 void setDensity(double density)
          Sets the density factor that influences the number of candidates that are yield during getLabelCandidates(y.layout.EdgeLabelLayout, y.layout.EdgeLayout, y.layout.NodeLayout, y.layout.NodeLayout).
 void setDistance(double distance)
          Determines how far away from the edge's path the rotation point lies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoRotationSliderEdgeLabelModel

public AutoRotationSliderEdgeLabelModel()
Method Detail

getDensity

public double getDensity()
Yields the density factor that influences the number of candidates that are yield during getLabelCandidates(y.layout.EdgeLabelLayout, y.layout.EdgeLayout, y.layout.NodeLayout, y.layout.NodeLayout). Values greater than 1 will yield more candidates, values smaller than 1 will decrease the number of candidates. The default is 1.0d

Returns:
the density factor for label candidates

setDensity

public void setDensity(double density)
Sets the density factor that influences the number of candidates that are yield during getLabelCandidates(y.layout.EdgeLabelLayout, y.layout.EdgeLayout, y.layout.NodeLayout, y.layout.NodeLayout). Values greater than 1 will yield more candidates, values smaller than 1 will decrease the number of candidates. The default is 1.0d

Parameters:
density - the density factor for label candidates

getAngle

public double getAngle()
Returns the angle between the base line of the label and the edge segment. An angle of 0 results in the label being aligned in parallel with the edge's segment.

Returns:
the angle in radian

setAngle

public void setAngle(double angle)
Sets the angle between the base line of the label and the edge segment. An angle of 0 results in the label being aligned in parallel with the edge's segment.

Parameters:
angle - the new angle in radian

getAnchorRatioX

public double getAnchorRatioX()
Returns the position of the rotation point as a ratio within in the label's bounds. A value of 0.0d results in the label being rotated around its left border.

Returns:
the ratio that indicates the position of the rotation point within the label
See Also:
getAnchorRatioY()

setAnchorRatioX

public void setAnchorRatioX(double anchorRatioX)
Sets the relative position of the rotation point as a ratio within in the label's bounds. E.g. a value of 0.0d results in the label being rotated around its left border.

Parameters:
anchorRatioX - the ratio that indicates the position of the rotation point within the label

getAnchorRatioY

public double getAnchorRatioY()
Returns the position of the rotation point as a ratio within in the label's bounds. A value of 0.0d results in the label being rotated around its upper border.

Returns:
the ratio that indicates the position of the rotation point within the label
See Also:
getAnchorRatioX()

setAnchorRatioY

public void setAnchorRatioY(double anchorRatioY)
Sets the relative position of the rotation point as a ratio within in the label's bounds. E.g. a value of 0.0d results in the label being rotated around its upper border.

Parameters:
anchorRatioY - the ratio that indicates the position of the rotation point within the label

getDistance

public double getDistance()
Determines how far away from the edge's path the rotation point lies. The distance is measured perpendicularly from the edge's segment and is oriented.

Returns:
the signed distance

setDistance

public void setDistance(double distance)
Determines how far away from the edge's path the rotation point lies. The distance is measured perpendicularly from the edge's segment and is a signed value.

Parameters:
distance - the signed distance

getDefaultParameter

public java.lang.Object getDefaultParameter()
Returns a default parameter that indicates a position at the center of the edge's path.

Specified by:
getDefaultParameter in interface EdgeLabelModel
Returns:
a parameter for use with this model

getLabelPlacement

public OrientedRectangle getLabelPlacement(YDimension labelSize,
                                           EdgeLayout edgeLayout,
                                           NodeLayout sourceLayout,
                                           NodeLayout targetLayout,
                                           java.lang.Object param)
Description copied from interface: EdgeLabelModel
Returns the oriented box of the label for the position encoded by the given model parameter.

Specified by:
getLabelPlacement in interface EdgeLabelModel
Parameters:
labelSize - the width and height of the label
edgeLayout - the layout of the edge to which the label belongs
sourceLayout - the layout of the source node of the label-owning edge
targetLayout - the layout of the target node of the label-owning edge
param - the model parameter that describes the abstract position of the label within this model
Returns:
the oriented bounds of the label

getPointPath

protected YPointPath getPointPath(EdgeLayout edgeLayout,
                                  NodeLayout sourceLayout,
                                  NodeLayout targetLayout)
Returns the point path associated with the given edge layout. By default the clipped polyline path defined by the control points the the edge layout will be returned. The returned path will be clipped at the rectangular bounding boxes of the source and target layouts.


determineRotationAngle

protected double determineRotationAngle(double dx,
                                        double dy)
Callback method that determines the rotation angle for a given edge segment's slope.

Parameters:
dx - the normalized dx of the direction vector of the segment.
dy - the normalized dy of the direction vector of the segment.
Returns:
the angle in radians to store with the parameter.

getLabelCandidates

public YList getLabelCandidates(EdgeLabelLayout labelLayout,
                                EdgeLayout edgeLayout,
                                NodeLayout sourceLayout,
                                NodeLayout targetLayout)
Description copied from interface: EdgeLabelModel
Returns all EdgeLabelCandidates that describe valid label positions within this model.

In case the implementing EdgeLabelModel allows every possible location, this method always returns the current location as a LabelCandidate.

Specified by:
getLabelCandidates in interface EdgeLabelModel
Parameters:
labelLayout - the label for which candidates should be generated
edgeLayout - the layout of the edge to which the label belongs
sourceLayout - the layout of the source node of the label-owning edge
targetLayout - the layout of the target node of the label-owning edge
Returns:
a list of EdgeLabelCandidate instances

createModelParameter

public java.lang.Object createModelParameter(OrientedRectangle labelBounds,
                                             EdgeLayout edgeLayout,
                                             NodeLayout sourceLayout,
                                             NodeLayout targetLayout)
Description copied from interface: EdgeLabelModel
Creates a model parameter that represents the given edge label position within this model.

The created model parameter is the closest parameter representation of the given label location that can be achieved within this model.

This parameter can be passed to EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) to retrieve the current label box.

A model parameter can be an arbitrary Object. However it must contain all information to allow restoring of the encoded location with this EdgeLabelModel.

Specified by:
createModelParameter in interface EdgeLabelModel
Parameters:
labelBounds - the oriented box of the label, encoding the label location for which the parameter should be created
edgeLayout - the layout of the edge to which the label belongs
sourceLayout - the layout of the source node of the label-owning edge
targetLayout - the layout of the target node of the label-owning edge
Returns:
the model parameter representing the given label location
See Also:
EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object)

getRotationAngle

public double getRotationAngle(EdgeLabel label)
Returns the current rotation angle for the given label for this model.

Parameters:
label - the label that has been configured with this model.
Returns:
The angle.

getRotationAngle

public double getRotationAngle(EdgeLayout edgeLayout,
                               NodeLayout sourceLayout,
                               NodeLayout targetLayout,
                               java.lang.Object param)
Returns the rotation angle for the given set of entities that would be used by this instance of the label model.

Parameters:
edgeLayout - the layout of the edge
sourceLayout - the layout of the source node
targetLayout - the layout of the target node
param - the currently being used parameter
Returns:
the current angle.

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