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,
VertexAdd[graph, Unique[]],
graph
],
graph
]
]
), Method -> "Queued" (*should help for bigger graphs*)
}],
Initialization :> (graph = Graph[
{1 -> 3},
VertexLabels -> "Name",
PerformanceGoal -> "Quality",
VertexShapeFunction -> radioMarkedVertexFunction[Hold[graph]]
]
)
]
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?
Thanks in advance!