Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Edges



An edge connect two nodes. It is an instance of the GraphMLEdge.

Creating an edge

To create an edge, you can use the GraphMLDiagram.addEdge(IGraphMLNode, IGraphMLNode) method. The method return the edge which you will be able to customize (for example, to add a label).

Example

      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphmlDiagram diagram = factory.newDiagram();

      GraphMLNode node1 = diagram.addNode();
      node1.setX(10);
      node1.setY(10);
      GraphMLNode node2 = diagram.addNode();
      node2.setX(100);
      node2.setY(100);

      GraphMLEdge edge = diagram.addEdge(node1, node2);

Other ways to create an edge

You can also create an edge directly from a node. For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphmlDiagram diagram = factory.newDiagram();

      GraphMLNode node1 = diagram.addNode();
      node1.setX(10);
      node1.setY(10);
      GraphMLNode node2 = diagram.addNode();
      node2.setX(100);
      node2.setY(100);

      GraphMLEdge edge = node1.addEdgeTo(node2);

Customizing an edge

Edge style

The LineStyle class allows to set various properties of the edge:
  • Line style
  • Color
  • Line width


To set the color of an edge:
      edge.getLineStyle().setColor("red");
To set the line style of an edge:
      edge.getLineStyle().setLineStyle(LineStyle.DASHED);

Edge arrows

Main Article: Edge arrows

By default the source and the target of the edge have an arrow specified by the arrowSource and arrowTarget properties of the diagram defaults.

If is possible to customize the source and the target of the arrow by using the GraphMLEdge.getArrows() method. The resulting Arrows source and target type can be customized by the associated:

For example, to have an edge with a standard arrow at its target:
      Arrows arrows = edge.getArrows();
      arrows.setTarget(ArrowType.STANDARD);

Edge labels

Main Article: Edge labels

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


To set the label of an edge:
      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));

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

The simplest way to set the path of an edge is only to set the starting point and the end point of the edge:
      Path path = edge.getPath();
      path.setSource(10, 10);
      path.setTarget(100, 100);
It is also possible to set a complex path by adding points:
      Path path = edge.getPath();
      path.setSource(10, 10);
      path.setTarget(100, 100);
      path.addPoint(50, 50);

Port constraint on the edge

Main Article: Port constraint

It is possible to add Port constraints on an edge. These constraints allow to specify the position of the edge relative to target or the source GraphMLNode of the edge. For example:
  • Setting the position of the port for the source of an edge relative to the source node sides
  • Setting the position of the port for the target of an edge relative to the target node sides
For example in the following diagram you may have a port constraint on the edge between node1 to node2 specifying that the side of the port on the source node is South and the side of the port on the target port is North:
portconstraint

Categories: edges | general

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