The use of DynamicLocation is described in answers to the following questions:

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:


eSF[graph_Graph] := Function[{coords, edge},
     dl1 = "VertexID$" <> ToString[VertexIndex[graph, edge[[ 1]]]],
     dl2 = "VertexID$" <> ToString[VertexIndex[graph, edge[[-1]]]]
    If[PropertyValue[graph, PerformanceGoal] === "Quality",
       DynamicLocation[dl1, Automatic, Center],
       DynamicLocation[dl2, Automatic, Center]
     (* else assume "Speed" *)
 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?

  • $\begingroup$ @kglr I'd like to eliminate the need to include thisGraph as an argument of eSF. That is, I need some way for eSF to discover the Graph it's being used in without having to tell it. That way, I can give eSF to others without extra instructions on how to make it work. $\endgroup$
    – RRas
    Aug 16, 2020 at 17:11
  • $\begingroup$ @kglr There are a variety of ways to solve this problem if non-idiomatic usage is accepted. I want to avoid this though, so that users can simply write EdgeShapeFunction :> eSF and have it work, regardless of other option settings. $\endgroup$
    – RRas
    Aug 16, 2020 at 20:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.