Graph styling: offset directed edge arrows when vertex sizes are different
Revised
My previous suggestion was not sufficient. Here is a better approach, although still not ideal.
I don't know how to achieve proper Arrow
objects without generating the Graph
object and inspecting its properties in order to figure out proper Arrow
setbacks. Rather than using the "Nearest"
vertex size spec (the default), here is how one could use two passes with the "Scaled"
vertex size spec. The "Scaled"
vertex size spec uses sizes relative to the diagonal of the vertex coordinates bounding box.
sizeRules = {1->0.5,2->0.5,3->0.3,4->0.4,5->0.5} /. r_Real:>{"Scaled", r/5};
edges={1->2,1->3,1->5,2->1,2->4,2->5,3->2,4->1,4->5,5->3,5->4};
g = Graph[
edges,
VertexSize->sizeRules,
VertexStyle->Opacity[0.5]
];
boundingBox = CoordinateBounds[VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates]];
diag = Norm[Subtract @@@ boundingBox];
actualSizeRules = sizeRules /. {"Scaled", r_} :> r diag/2;
Graph[
edges,
VertexSize -> sizeRules,
VertexStyle -> Opacity[0.5],
EdgeShapeFunction -> (Arrow[#1, List@@#2 /. actualSizeRules]&)
]
Set PerformanceGoal -> "Quality"
can help:
Graph[{1 -> 2, 2 -> 1}, VertexSize -> {1 -> 1/3, 2 -> 1/5}, VertexStyle -> Opacity[0.5],
PerformanceGoal -> "Quality"]