Calculating node-edge intersection points
Applies to: yFiles 2.4, yFiles 2.3, yFiles 2.2, yFiles 2.1, yFiles 2.0, yFiles.NET 2.4, yFiles.NET 2.3, yFiles.NET 2.2 print article email article

Type: Questions & Answers

Categories this article belongs to:
yFiles for Java > yFiles Layout > Automatic Graph Layout

This article explains how you can calculate the intersection points between edges and node boundaries yourself.

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);

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

Keywords: edge - path - clip - bounds

Provide feedback:
How useful was this article?    less 1 2 3 4 5 more
Email address (optional):
COPYRIGHT © 2008 yWorks · ALL RIGHTS RESERVED imprint | top | home