# dynamic graph vertex name evaluation

I am trying to create a graph which allow the user to create new vertices and edges. clicking on an empty spot in the graph creates a new vertex, and clicking an existing vertex creates a popup window which allows adding edges from it. this is some minimal code for example (sorry, it's still a bit long):

radioMarkedVertexFunction[Hold[g_Symbol]] :=

Function[{pos, name, dim}, {
PopupWindow[
Disk[pos, EuclideanDistance[{0, 0}, dim]],
Row[{
PopupMenu[Dynamic[edgeAdd$dst], VertexList[g]], Button["New Edge", If[MemberQ[VertexList[g], name], g = EdgeAdd[g, name \[DirectedEdge] edgeAdd$dst]]
]
}],
WindowTitle -> Dynamic[name]
]
}
]
DynamicModule[{graph},
EventHandler[
Dynamic[graph], {
"MouseClicked" :> (graph = Block[{
pos = MousePosition["Graphics"],
near
},
If[FreeQ[pos, None],
near = Nearest[GraphEmbedding[graph], pos][[1]];
Print["pos:", pos, " nearest:", near, " \nout of: ",
Nearest[GraphEmbedding[graph], pos]];
If[
EuclideanDistance[pos, near] > 0.1,
graph
],
graph
]
]
), Method -> "Queued" (*should help for bigger graphs*)
}],
Initialization :> (graph = Graph[
{1 -> 3},
VertexLabels -> "Name",
PerformanceGoal -> "Quality",
]
)
]


The functionality described above is working fine, but I have a wierd problem, I used the option:

WindowTitle -> Dynamic[name]


so that every popup window will bear the name of its relevant vertex (s.t. if you create a new edge, you will now where it starts.) the title is fine for nodes created by clicking, e.g.

in contrast to

so what's up with that? all popups get their title as an argument to the vertex shape function, so why are some not evaluated?

It fails because WindowTitle can't handle e.g. Integers but it can e.g. Symbols or Strings. Which is even more than I thought because I was expecting that only strings work.

ref/WindowTitle/PossibleIssues says:

WindowTitle should be set to something that formats as a simple string of text

Which is not very precise but it is something.

Nevertheless, you can format it properly using e.g.:

WindowTitle -> Dynamic[ToString[name, InputForm]]

• wow, that was much simpler than I suspected. thanks! Oct 11, 2017 at 14:17