The use of DynamicLocation
is described in answers to the following questions:
- DynamicLocation usage
- Framework behind Graph plots. DynamicNamespace and friends
- How to create a custom EdgeShapeFunction whose arrowheads snap to vertices
The last of these describes DynamicLocation
usage in an EdgeShapeFunction
. However, the example there presumes that the PerformanceGoal
option will be set to "Quality"
whenever that EdgeShapeFunction
is used. If it is used with PerformanceGoal->"Speed"
, the DynamicLocation
entries become invalid coordinates.
I've been trying unsuccessfully to define a flexible EdgeShapeFunction
that's aware of whether or not DynamicLocation
will work in the current setting (i.e., whether the effective PerformanceGoal
of its Graph
is "Quality"
). That's more or less how default edges are handled. So far though, I've found no satisfactory way to do this.
I've guessed that there might be some internal symbol or expression that could stand in for the appropriate coordinate form, but nothing has turned up. Therefore, I've tried making the EdgeShapeFunction
conditional instead, which is easy enough, but conditioned on what?
My best attempt so far is the following, where thisGraph
is passed explicitly into the EdgeShapeFunction
:
ClearAll[eSF];
eSF[graph_Graph] := Function[{coords, edge},
With[
{
dl1 = "VertexID$" <> ToString[VertexIndex[graph, edge[[ 1]]]],
dl2 = "VertexID$" <> ToString[VertexIndex[graph, edge[[-1]]]]
},
If[PropertyValue[graph, PerformanceGoal] === "Quality",
Arrow[{
DynamicLocation[dl1, Automatic, Center],
DynamicLocation[dl2, Automatic, Center]
}],
(* else assume "Speed" *)
Arrow[coords]
]
]
];
Manipulate[
thisGraph = Graph[{1 -> 2, 2 -> 3, 3 -> 1},
VertexSize -> 0.3,
VertexShapeFunction -> "ConcavePentagon",
PerformanceGoal -> perf,
EdgeShapeFunction :> eSF[thisGraph]
],
{{perf, Automatic, "PerformanceGoal"}, {Automatic, "Quality", "Speed"}}
]
To avoid an explicit reference to the graph, I've considered pulling it out of NotebookRead[EvaluationCell[]
, but that would be ugly and unreliable.
Is there a better way to accomplish this?
EdgeShapeFunction :> eSF
and have it work, regardless of other option settings. $\endgroup$