Skip to main content
edited tags
Link
Michael E2
  • 258.7k
  • 21
  • 370
  • 830
added some explanation
Source Link
Simon Woods
  • 85.9k
  • 8
  • 183
  • 332

I have some code which displays a GraphPlot and allows the user to click on any vertex in the graph to display some information about that vertex in a popup window. There is two-way highlighting between the popup and the vertex, so that if the user hovers over either the vertex or the popup window, both the vertex and the popup will be highlighted (the vertex by changing size and the popup by changing colour).

I do this by defining a VertexRenderingFunction for the graph plot which uses Module to create a unique symbol for each vertex. This symbol is set to True whenever the mouse is over the vertex or the popup window, and the dynamic highlighting is determined by the value of the symbol.

This works okay (though I'd be interested in better ways to accomplish the same effect). However, as soon as I put the GraphPlot inside a Manipulate, the highlighting becomes rather sluggish, even if the Manipulate is not changing the plot in any way. I don't understand why that happens.

Here's a minimal working example:

(* create some data *) data = Thread[RandomChoice[Range[200], 350] -> RandomChoice[Range[200], 350]]; (* define the vertex rendering function *) vrf := Module[{mo}, PopupWindow[ Dynamic[ mo = CurrentValue["MouseOver"]; {PointSize[Dynamic[If[mo, 0.03, 0.01]]], Point[#1]}], Dynamic[ mo = CurrentValue["MouseOver"]; Panel["Popup Window Text", Background -> Dynamic[If[mo, Pink, White]]]] ]] &; (* graph plot *) gp = GraphPlot[data, VertexRenderingFunction -> vrf] 

This works nicely. But if I do this:

Manipulate[gp, {x, 0, 10}, TrackedSymbols :> {x}] 

it is much less responsive. Can anyone tell me why this happens, and more importantly how to prevent it?

I'm using version 8.0.4 by the way.

NB The first argument of the Manipulate in my example is deliberately independent of x. The slider control is nothing to do with the problem, it is just there to make a valid Manipulate expression. I have used TrackedSymbols :> {x} to make doubly certain that Manipulate isn't tracking any symbols inside the GraphPlot. In my real application the Manipulate does useful things, but I realised as I stripped the code down that merely being inside a Manipulate affects the responsiveness of the plot, even if the Manipulate doesn't change the plot in any way.

I have some code which displays a GraphPlot and allows the user to click on any vertex in the graph to display some information about that vertex in a popup window. There is two-way highlighting between the popup and the vertex, so that if the user hovers over either the vertex or the popup window, both the vertex and the popup will be highlighted (the vertex by changing size and the popup by changing colour).

I do this by defining a VertexRenderingFunction for the graph plot which uses Module to create a unique symbol for each vertex. This symbol is set to True whenever the mouse is over the vertex or the popup window, and the dynamic highlighting is determined by the value of the symbol.

This works okay (though I'd be interested in better ways to accomplish the same effect). However, as soon as I put the GraphPlot inside a Manipulate, the highlighting becomes rather sluggish, even if the Manipulate is not changing the plot in any way. I don't understand why that happens.

Here's a minimal working example:

(* create some data *) data = Thread[RandomChoice[Range[200], 350] -> RandomChoice[Range[200], 350]]; (* define the vertex rendering function *) vrf := Module[{mo}, PopupWindow[ Dynamic[ mo = CurrentValue["MouseOver"]; {PointSize[Dynamic[If[mo, 0.03, 0.01]]], Point[#1]}], Dynamic[ mo = CurrentValue["MouseOver"]; Panel["Popup Window Text", Background -> Dynamic[If[mo, Pink, White]]]] ]] &; (* graph plot *) gp = GraphPlot[data, VertexRenderingFunction -> vrf] 

This works nicely. But if I do this:

Manipulate[gp, {x, 0, 10}, TrackedSymbols :> {x}] 

it is much less responsive. Can anyone tell me why this happens, and more importantly how to prevent it?

I'm using version 8.0.4 by the way.

I have some code which displays a GraphPlot and allows the user to click on any vertex in the graph to display some information about that vertex in a popup window. There is two-way highlighting between the popup and the vertex, so that if the user hovers over either the vertex or the popup window, both the vertex and the popup will be highlighted (the vertex by changing size and the popup by changing colour).

I do this by defining a VertexRenderingFunction for the graph plot which uses Module to create a unique symbol for each vertex. This symbol is set to True whenever the mouse is over the vertex or the popup window, and the dynamic highlighting is determined by the value of the symbol.

This works okay (though I'd be interested in better ways to accomplish the same effect). However, as soon as I put the GraphPlot inside a Manipulate, the highlighting becomes rather sluggish, even if the Manipulate is not changing the plot in any way. I don't understand why that happens.

Here's a minimal working example:

(* create some data *) data = Thread[RandomChoice[Range[200], 350] -> RandomChoice[Range[200], 350]]; (* define the vertex rendering function *) vrf := Module[{mo}, PopupWindow[ Dynamic[ mo = CurrentValue["MouseOver"]; {PointSize[Dynamic[If[mo, 0.03, 0.01]]], Point[#1]}], Dynamic[ mo = CurrentValue["MouseOver"]; Panel["Popup Window Text", Background -> Dynamic[If[mo, Pink, White]]]] ]] &; (* graph plot *) gp = GraphPlot[data, VertexRenderingFunction -> vrf] 

This works nicely. But if I do this:

Manipulate[gp, {x, 0, 10}, TrackedSymbols :> {x}] 

it is much less responsive. Can anyone tell me why this happens, and more importantly how to prevent it?

I'm using version 8.0.4 by the way.

NB The first argument of the Manipulate in my example is deliberately independent of x. The slider control is nothing to do with the problem, it is just there to make a valid Manipulate expression. I have used TrackedSymbols :> {x} to make doubly certain that Manipulate isn't tracking any symbols inside the GraphPlot. In my real application the Manipulate does useful things, but I realised as I stripped the code down that merely being inside a Manipulate affects the responsiveness of the plot, even if the Manipulate doesn't change the plot in any way.

Tweeted twitter.com/#!/StackMma/status/303222059272650752
added 37 characters in body
Source Link
Simon Woods
  • 85.9k
  • 8
  • 183
  • 332
Loading
Source Link
Simon Woods
  • 85.9k
  • 8
  • 183
  • 332
Loading