Calculating node-edge intersection points

Questions & Answers

Summary

This article explains how you can calculate the intersection points between edges and node boundaries yourself.
For a better user experience, please go to the integrated documentation viewer to read this article.

Description

If you are using the yFiles viewer component, edge paths are usually calculated automatically so that they connect to the (visual) boundary of the source or target nodes. This may involve clipping or prolonging the edge path. If you are doing the visualization step yourself (e.g. you are only using the yFiles layout component), you will probably have to do these steps yourself.

A typical example is when the source or target anchor point of an edge lies at the center of a node. If you just draw the edge path, it probably looks like either the edge extends into the inside of the node or the arrow is missing (the result may depend on the order in which you paint the edge and its adjacent nodes). Fortunately, yFiles provides the methods LayoutTool.clipEdgeOnBB and LayoutTool.clipEdgesOnBB to clip a selected edge resp. all edges in a graph correctly at the bounding box of the source/target node:

import y.layout.*;
....
LayoutGraph graph;
....
LayoutTool.clipEdgesOnBB(graph);

These methods always clip edges at the bounding rectangle of the nodes, so this method won't work correctly for non-rectangular nodes

If you need more control over the clipping process (i.e. you have non-rectangular nodes), an alternative is to implement IntersectionCalculator and extend and add PortCalculator stage to your layout pipeline.

Categories this article belongs to:
yFiles for Java > yFiles Layout > Automatic Graph Layout
Applies to:
yFiles for Java 2: 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 2.17, 2.18
Keywords:
edge - path - clip - bounds