Calculating node-edge intersection points
Questions & AnswersSummary
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);
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.