Simulating a Mouseover Event with EventHandler
- To: mathgroup at smc.vnet.net
- Subject: [mg91233] Simulating a Mouseover Event with EventHandler
- From: chandler.seth at gmail.com
- Date: Sun, 10 Aug 2008 01:54:14 -0400 (EDT)
I believe I have solved the problem I posed in a previous post or at
least improved my understanding of the problem. Here is an example of
what I am trying to do. The idea is that when one passes over an edge
the edge and associated vertices change their appearance. And when one
clicks on a vertex, the vertex and certain associated edges likewise
light up. The keys to solving my problem were (1) understanding the
MouseMoved event; (2) understanding the concept of nested
EventHandlers and (3) understanding how the PassEventsDown option
works.
The next step is to wrap this in a Manipulate so that the effect of
clicking and passing over can be set by the user. By way of example, I
would like to be able to set the variable "direction" interactively.
At the moment, I can't get this to work, as wrapping everything up in
a Manipulate seems to block the behavior I want. If anyone has more
elegant solutions (or an understanding of the Manipulate issue), I
would be grateful.
With[{g = {1 -> 2, 1 -> 10, 2 -> 3, 2 -> 7, 3 -> 4, 3 -> 6, 3 -> 9,
4 -> 6, 4 -> 7, 4 -> 8, 5 -> 8, 5 -> 9, 5 -> 10, 6 -> 8,
6 -> 10}}, (activeEdge = {};
Dynamic@EventHandler[
LayeredGraphPlot[g, Left, ImageSize -> 600, AspectRatio -> 1/3,
EdgeRenderingFunction -> (Dynamic@
EventHandler[{If[MemberQ[activeEdge, #2],
Directive[Green, Thickness[0.02]],
Directive[Red, Thickness[0.005]]],
Arrow[#1]}, {"MouseMoved" :> (activeEdge = {#2})},
PassEventsUp -> False] &),
VertexRenderingFunction -> (Dynamic@
EventHandler[
With[{activeQ = MemberQ[activeEdge, #2]}, {If[activeQ,
Directive[Green], Directive[Red]],
Disk[#1,
If[activeQ, Scaled[0.05],
Scaled[0.03]]]}], {"MouseClicked" :> (test =
List @@@ Cases[g, _[_, #2]];
activeEdge =
Switch[direction, 1, List @@@ Cases[g, _[_, #2]], 2,
List @@@ Cases[g, _[#2, _]], _,
List @@@ Cases[g, _[___, #2, ___]]])},
PassEventsUp ->
False] &)], {"MouseMoved" :> (activeEdge = {})},
PassEventsDown -> True])]