Determine backward links in LayeredDigraphLayout

Is there a way to determine if a link in a diagram that uses LayeredDigraphLayout is a backward link? I want to use different colors between forward and backward links so that they can be easily distinguished visually. Thanks for any pointer!

Depending on the direction of the layout (i.e. LayeredDigraphLayout.direction) you can just look at the first and last points of the Link.points and decide.

So if the direction is 0 (rightwards), normal links will have link.getPoint(0).x < link.getPoint(link.pointsCount-1).x, so “backwards” links will have the opposite be true.

You’ll probably want to override LayeredDiagraphLayout.commitLinks – call the super method first and then you can look at the links and color them.

Thank you very much! That is great, though by examining the x coordinates, would it be susceptible to user dragging the “parent” node to be after the “child” node, thereby the x values change? On a second though, if the coloring is done within commitLinks, this shouldn’t be an issue as the coloring is already done before dragging happens. Thanks.