Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleTips

Here's a few tips for implementing the edge routing:

  • Each edge shall be drawn with three orthogonal line segments: one vertical segment below the start node, one vertical segment below the target node, and a horizontal segment that connects the two.
  • The horizontal segments of two different edges shall not have the same y-coordinate. Two neighboring horizontal segments shall be placed at a distance of objectSpacing.
  • See the screenshot at the top of the tutorial for an example.
  • Find the edges in a graph by calling getOutgoingEdges() or getIncomingEdges() on the nodes.
  • You can add bend points to edges through the edge's edge layout:

    Code Block
    languagejava
    KEdgeLayout edgeLayout = edge.getData(KEdgeLayout.class);
    KPoint bendPoint = KLayoutDataFactory.eINSTANCE.createKPoint();
    edgeLayout.getBendPoints().add(bendPoint);
  • You will want to clear the list of bend points of each edge layout before adding bend points to it. This will remove all bend points the edge had prior to invoking your layout algorithm.
  • Set the values of the points returned by getSourcePoint() and getTargetPoint() according to the positions where an edge leaves its source node and reaches its target node.
  • If you want, you can improve the edge routing code by allowing horizontal segments to share the same y-coordinate if that doesn't make them overlap. Your goal could be to produce an edge routing that uses as little space as possible.
  • If that's not enough yet: can you find a way to find an order of the horizontal segments such that as few edge crossings as possible are produced?

Warning

The drawing framework does something intelligent. Or at least it thinks it is intelligent. When the source point or target point of an edge does not touch the boundary of a node, it moves them such that they touch the boundary. This can be confusing when you calculate and specify positions in the code that are not reflected in the diagram you see.

Once you're done implementing the edge routing code, test it by running your debug configuration again, as before.

...