Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Edge labels



An edge can have one or several labels:
  • The main label
  • Additional labels

Note that in the graphml format, there is only one type of label. When parsing a diagram, the parser will create a main label for the first label on an edge, and an additional label for others labels on the same edge.

Main label

Main Article: Labels

To set the main label of an edge, you can use one of the following methods:

For example:
      edge.setLabel("The Label");
By default the text color is black, and the label has no background and no border. However it is possible to set the text color, the background color, the border color and the insets of the label. For example:
      EdgeLabel label = edge.setLabel("The Label");
      label.setTextColor(Color.RED);
      label.setBackgroundColor(Color.YELLOW);
      label.setBorderColor(Color.BACK);
      label.setInsets(new Insets(1, 1, 1, 1));

Additional labels

To add an additional label for an edge, you can use one of the following methods: For example the code below will create an additional label toward the end of the edge:
      edge.createAdditionalLabel("The Label", 0.98f);

Edge label position

Main Article: Edge label position

To customize the position of the label on the edge, you must access the label through the EdgeLabel.getParameterModel() method.

The resulting EdgeLabel$ParamModel 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.getLabel();
      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.

Edge label ratio

By default the label will be on the middle of the edge, but it is possible to set the ratio of the label to put it toward the beginning or the end of the edge.

For example the following code:
      GraphMLFactory factory = GraphMLFactory.getInstance();
      GraphMLDiagram diagram = factory.newDiagram();

      GraphMLNode node1 = diagram.addNode();
      GraphMLNode node2 = diagram.addNode();
      GraphMLEdge edge = node1.addEdgeTo(node2);
      Arrows arrows = edge.getArrows();
      arrows.setTarget(ArrowType.STANDARD);

      EdgeLabel label1 = edge.createAdditionalLabel("Origin", 0.02f);
      EdgeLabel label2 = edge.createAdditionalLabel("Destination", 0.98f);
Produce the following diagram:
labelratio

See also


Categories: edges | general

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