I have to create a Graph object, which can be manipulated by the user, though I do not want to have the Graph-specific cursor (an arrow with an UndirectedEdge symbol next to it) not to confuse the user with any extra information. I assumed this would work:

 Graph[{1 <-> 2, 2 <-> 3,3 <-> 1},
  ImageSize -> 200,
  EdgeShapeFunction -> ({Black, AbsoluteThickness@2, Arrowheads@.1, 
      MouseAppearance[Arrow[#1, .1], "Arrow"]} &),
  VertexShapeFunction :> ({Hue[.6, .2, .8], 
      MouseAppearance[Disk[#1, .1], "Arrow"]} &)

Mathematica graphics

But it doesn't work. While all graphics objects and the whole graph itself are wrapped into MouseAppearance still the Graph-specific cursor appears when I move the mouse away of edges or nodes. Over nodes and edges, the standard arrow cursor is displayed correctly, as expected. Unfortunately, when I capture the screen with the cursor included, it always saves the normal arrow cursor irregardless how it looks on screen. Strange. That's why I did not include a picture with a cursor over it.

Can anyone answer the following questions?

  1. Why MouseAppearance[..., "Arrow"] does not work here (only partially)?
  2. How can the Graph-specific cursor appearance be invoked? The documentation for MouseAppearance (under More nformation) does not list it among the built-in ones.
  3. Why PrintScreen or any other screenshot application is unable to capture the Graph-specific cursor?

Platform is: Win7 64bit


Heike's answer has a strong virtue of simplicity, but it has two downsides. It strips the Graph-specific context menus, and it causes the output to not evaluate as a Graph if copied back to input. Here's a version which preserves those properties:

StripGraphMouseAppearance[x_Graph] := 
 RawBoxes[ToBoxes[x, StandardForm] /. 
   TagBox[contents_, MouseAppearanceTag["NetworkGraphics"]] :> 

Now, simply apply StripGraphMouseAppearance whenever you want to strip the appearance in output. E.g., the example in the question would be reformulated as:

 Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, ImageSize -> 200, 
  EdgeShapeFunction -> ({Black, AbsoluteThickness@2, Arrowheads@.1, 
      Arrow[#1, .1]} &), 
  VertexShapeFunction :> ({Hue[.6, .2, .8], Disk[#1, .1]} &)]]

Basically, Graph typesets with the MouseAppearance built into it. My code looks for the box form of MouseAppearance and strips it out. One could conceivably rewrite MakeBoxes rules for Graph directly to do this, but doing so correctly would be a much more difficult exercise, as it would require reverse-engineering the rules we have now and carefully overriding them...and such a solution might not be stable across different Mathematica versions.


I don't know the answers to questions 1 and 3, but to get the cursor appearing as an arrow everywhere in the Graph you could wrap your graph in Show, e.g.

Show@Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 
   3 \[UndirectedEdge] 1}, ImageSize -> 200, 
  EdgeShapeFunction -> ({Black, AbsoluteThickness@2, Arrowheads@.1, 
      Arrow[#1, .1]} &), 
  VertexShapeFunction :> ({Hue[.6, .2, .8], Disk[#1, .1]} &)]
  • 1
    $\begingroup$ Interesting workaround! Since the right-click menu for graph-editing is gone, I assume that Show effectively converts Graph objects to Graphics objects. $\endgroup$ – István Zachar Jan 31 '12 at 12:18
  • $\begingroup$ +1 Heike, you beat me to it! @István: Yes, you can check by hitting it with InputForm and comparing to the Graph without the Show. As for the screenshot thing, I get the same behaviour as you using the default gnome screenshot tool (in Ubuntu 11.10). $\endgroup$ – Simon Jan 31 '12 at 12:23
  • 1
    $\begingroup$ Yes, the problem is that MouseAppearance is used when typesetting Graph objects. Your MouseAppearance doesn't work because, if you look at the underlying representation in the front end, the typeset stage effectively wraps MouseAppearance around all of the individual elements of the Graph. If you would find the answer interesting, I could propose a separate answer which preserves the contextual menu while stripping the inner MouseAppearance, although the Show method prescribed here is certainly simpler and may be good enough for you. $\endgroup$ – John Fultz Feb 1 '12 at 14:25
  • $\begingroup$ Yes, @JohnFultz, please propose that separate answer! $\endgroup$ – István Zachar Feb 13 '12 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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