Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Edge label position



This article presents how to customize the label position on an edge.

Overview

To customize the position of the label on the edge, you must access the label through the EdgeLabel. This class allows to customize the position of the label relative to the edge. For example, to have the label alongside the edge, you can use:
      EdgeLabel label = edge.setLabel("The Label");
      EdgeLabel.ParamModel model = label.getParameterModel();
      model.setAutoFlip(true);
      model.setAutoRotate(true);
If you don't want to do it for all edges, you can access the default values of these parameters through the DiagramDefaults.

Customizing the position

Default position

By default, the label if horizontal.

On a horitontal edge, is will be partially shown away from the edge itself:
labeldefaultposHoriz
On a vertical edge, is will be partially shown on the edge itself:
labeldefaultpos

Left position

To put the label on the left of the edge, you can set:
      EdgeLabel label = edge.setLabel("The Label");
      EdgeLabel.ParamModel model = label.getParameterModel();
      model.setPosition(EdgeLabelPosition.POSITION_HEAD);
or more simply:
      EdgeLabel label = edge.setLabel("The Label");
      label.setPosition(EdgeLabelPosition.POSITION_HEAD);
On a horizontal edge, you will have the following result:
labelheadposHoriz
On a vertical edge, you will have the following result:
labelheadpos

Right position

To put the label on the right of the edge, you can set:
      EdgeLabel label = edge.setLabel("The Label");
      EdgeLabel.ParamModel model = label.getParameterModel();
      model.setPosition(EdgeLabelPosition.POSITION_TAIL);
or more simply:
      EdgeLabel label = edge.setLabel("The Label");
      label.setPosition(EdgeLabelPosition.POSITION_TAIL);
On a horizontal edge, you will have the following result:
labeltailposHoriz
On a vertical edge, you will have the following result:
labeltailpos

Position alongside the edge

To put the label alongside the edge, you can set:
      EdgeLabel label = edge.setLabel("The Label");
      EdgeLabel.ParamModel model = label.getParameterModel();
      model.setAutoFlip(true);
      model.setAutoRotate(true);
or more simply:
      EdgeLabel label = edge.setLabel("The Label");
      label.setAutoFlip(true);
      label.setAutoRotate(true);
or even:
      EdgeLabel label = edge.setLabel("The Label");
      label.setSmartPosition(EdgeLabelPosition.POSITION_HEAD, true);
You will have the following result:
labelonedgepos

See also


Categories: edges | general

Copyright 2021 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence