GraphRecipes.jl icon indicating copy to clipboard operation
GraphRecipes.jl copied to clipboard

Make curved edges look nicer

Open JackDevine opened this issue 5 years ago • 0 comments

Curved edges now use a cubic spline with one intermediate point to create a curve between nodes. I choose this system over Bezier curves (which are aesthetically quite nice) because I wanted to be able to make the curved edges go through a specified point.

Ideally, we should have a way to create curved edges that can be controlled precisely while still being aesthetically pleasing. I have a suspicion that ellipses might do quite well here. Solving this issue will require trying out multiple ideas and deciding on the best type.

Ultimately, this work may end with a curvature_type keyword argument. This is a really open end project.

g = wheel_digraph(7)

graphplot(g, nodeshape=:rect, curvature_scalar=0.08)

tmp

You can see that the arrows pointing at edges are not pointing at the centre of the edge and some of the curves look a little non smooth.

EDIT Finding the nearest intersection between an elliptical curve and the destiny node is not a trivial task. Let the point m be a point that is distance curvature_scalar from the mean of the source and the destiny node travelling in the direction perpendicular to the line connecting the source and destiny nodes. Right now the nearest_intersection function looks for intersections with the perimeter of the destiny node and a line that goes between m and the centre of the destiny node. Finding the intersection between two lines or the intersection between a line and a circle is quite easy, but finding the intersection between a line and an ellipse or an ellipse and a circle is a little more tricky. It is definitely not impossible, but it is a little tricky. Therefore, if you try to replace the current curvy edges with ellipses, be prepared to do a little algebra before you get to do any coding.

Also note from the above discussion that curvature_scalar dictates how far the curve deviates from a straight line connecting the source and destiny nodes. Therefore, a better name would be curvature_radius. In addition to making better looking curves, it would be nice to bikeshed the current curves API and come up with some improvements from a user perspective.

JackDevine avatar Mar 08 '20 09:03 JackDevine