3
$\begingroup$

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.

A popup with the vertex's unique name as title

in contrast to

A popup with $Failed as title

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!

$\endgroup$

1 Answer 1

2
$\begingroup$

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]]
$\endgroup$
1
  • $\begingroup$ wow, that was much simpler than I suspected. thanks! $\endgroup$
    – Nailo
    Oct 11, 2017 at 14:17

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.