When using the Graph
option PerformanceGoal -> "Quality"
, the endpoints of edges (arrows) will snap to vertices, no matter the vertex shape or size.
Example:
Graph[
{"apple" -> "banana", "banana" -> "watermelon",
"watermelon" -> "apple", "apple" -> "watermelon"},
VertexShapeFunction -> Function[{point, vertex, size}, Text[Framed@vertex, point]],
PerformanceGoal -> "Quality"
]
I am looking to change the EdgeShapeFunction
so directed reciprocal edges will always be straight.
This is the effect I am looking to achieve:
Graph[{1 -> 2, 2 -> 3, 3 -> 1, 1 -> 3},
EdgeShapeFunction ->
Function[{coord, edge}, Arrow[{First[coord], Last[coord]}]],
PerformanceGoal -> "Quality"
]
However, using a custom edge shape function disables the snapping effect. This is bad because depending on the vertex size, even circular vertices can obscure arrowheads. Example:
Graph[{1 -> 2, 2 -> 3, 3 -> 1, 1 -> 3},
EdgeShapeFunction ->
Function[{coord, edge}, Arrow[{First[coord], Last[coord]}]],
PerformanceGoal -> "Quality",
VertexSize -> 1/4
]
Question: Is there a way to define a custom EdgeShapeFunction
without disabling this spanning effect? Is there a built-in edge shape function which always draws straight lines? Built-ins do not disable the snapping effect.
I know that for this specific use case, the arrowhead could be offset manually to avoid overlapping with circular vertices. But I am looking for a solution that works with arbitrary vertex shapes, such as the one in my first example. At this time, I am only looking for straight edge shape functions, not fancy ones, so any solution specific to straight ones is still acceptable.
This is a hack that sort of works for visualization, but it is ugly, inflexible, and does not allow one to keep working with Graph
:
Show@Graph[{"apple" -> "banana", "banana" -> "watermelon",
"watermelon" -> "apple", "apple" -> "watermelon"},
VertexShapeFunction ->
Function[{point, vertex, size}, Text[Framed@vertex, point]],
PerformanceGoal -> "Quality"] /.
Arrow[BezierCurve[{first_, ___, last_}]] :> Arrow[{first, last}]