16

Is it possible to change the position of tool tips, which currently always appear to the lower right of the mouse position. In the screen grab below the mouse is over 10000000 and the tooltip appears to the bottom right (8.0.4 on Mac).

enter image description here

By way of an example how would you go about making the tooltip appear to the bottom left (courtesy of photo editing):

enter image description here

(This was originally asked on StackOverflow, but it did not draw any answers.)

Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158
  • We'll see if this draws answers here. – rcollyer Feb 02 '12 at 03:31
  • On my system (Mathematica 8.0.1 Linux x64) the tooltip is displayed at the mouse position, not necessarily at the bottom right. – David Z Feb 02 '12 at 06:46
  • thanks @David. Just added an edit: my system is Mac. I wonder if that means that the position is something that Mma takes from the operating system. – Mike Honeychurch Feb 02 '12 at 06:51
  • On Windows the ToolTip appears at the bottom-right corner of the mouse cursor. I could see this being described either as Mike or David did; is the behavior actually different on other systems? – Mr.Wizard Feb 02 '12 at 07:09
  • The tooltips for me (Ubuntu) are centered below the cursor in the OS, but justified right in Mathematica. – David Feb 02 '12 at 07:11
  • On Fedora it also appears bottom right of the mouse. Moving the mouse moves the tooltip. – FJRA Mar 05 '12 at 23:35
  • I do not think that this is possible. There seems to be no option neither for Annotation nor for Mouseover to change the position. Probably just a small design oversight. (or ask John Fultz on Mathgrouop, he should know). – Rolf Mertig Mar 05 '12 at 23:58
  • 2
    It's easy to get the tooltip to come up to the left of the cursor; position your content along the right edge of your screen... ;-) – Brett Champion Mar 06 '12 at 01:26
  • 7
    Sorry, if it's a real tooltip, the answer is just simply no. Can't be done. The positioning algorithm is hard-coded into the FE source code (I just checked) and is not user-settable. You might be able to find some way to create a fake tooltip-like thing which you can have more control over, but it's just not going to be possible with the real thing. FWIW, you're the first person I'm aware of to ask for this functionality. Wasn't even on my radar before. – John Fultz Mar 06 '12 at 04:12
  • @JohnFultz Did want to implement it if possible but it is not a big deal. – Mike Honeychurch Mar 06 '12 at 06:38
  • @JohnFultz, wondering if this was ever addressed--or is it still hard coded? I tried the ToolTipStyle options in the Global options (i.e., ToolTipStyle->{TextAllignment->-1}). No change.
    My mouse cursor is enlarged, so some users might not be bothered by this.

    My mouse covers the tool tips in the new default tool bar.

    – Craig Carter Sep 04 '22 at 15:38
  • @CraigCarter nothing has changed. – John Fultz Sep 22 '22 at 14:50

1 Answers1

11

Improvised Tooltip using Text and Mouseover

Here's one way to improvise a tooltip for graphics objects--in this case, a list of points. It emulates a tooltip but does not leave a a drop shadow, and as István notes, has a few graphical shortcomings that make it less than ideal (clipping, under axes layer). Also, the code would need to be tweaked for objects displayed through functions other than Graphics.

[Edit: The present version makes use of Heike's suggestion to use the third parameter of Text for the offset. As Heike notes, "The units of the third argument of Text are scaled with respect to the bounding box of the first argument where {0,0} corresponds to the centre, {-1,-1} to the lower left corner, {1,1} to the upper right corner etc."]

Graphics[{PointSize[Medium], 
    Table[Mouseover[Point[p], {Point[p], 
        Text[Framed[p, Background -> LightYellow], p, {1.25, 2}]}], 
    {p, RandomReal[1, {10, 2}]}]}, Frame -> True, 
    PlotRange -> {{0, 1}, {0, 1}}, ImagePadding -> {{100, 10}, {50, 5}}]

tooltip

DavidC
  • 16,724
  • 1
  • 42
  • 94
  • You could use the third argument of Text for the vertical displacement as well, for example Text[Framed[p, Background -> LightYellow], p, {1.2, 1}]. This would make the relative position of the label independent of the plot range of the plot. – Heike Mar 08 '12 at 10:07
  • Thanks. I figured out how to use Scaled. What units does your adjustment use? They are not the same as scaled. Nor are they printer's points. – DavidC Mar 08 '12 at 10:24
  • It looks like the third argument of Text uses characters (in the current font size) as units. If so, that is a nice alternative to Scaled. – DavidC Mar 08 '12 at 10:32
  • The units of the third argument of Text are scaled with respect to the bounding box of the first argument where {0,0} corresponds to the centre, {-1,-1} to the lower left corner, {1,1} to the upper right corner etc. – Heike Mar 08 '12 at 10:51
  • This would seem to imply that the displacement of the tooltip will vary according to the size of the text bounding box, correct? – DavidC Mar 08 '12 at 11:00
  • 1
    While this is a really nice solution, showing how to improvise if reverse engineering is not available, it has some drawbacks: 1) tooltips are layered behind the axes/frames, 2) they are clipped at the edges, 3) they are not drawn using the generic functions of the OS, thus this tooltip won't look like standard tooltips on e.g. a Mac. – István Zachar Mar 08 '12 at 11:52
  • @István Good points. You probably noticed that I used heavier ImagePadding on the left and bottom margins to avoid clipping. But if the tooltip had been placed in another position relative to the cursor, those ImagePadding settings might not have sufficed. – DavidC Mar 08 '12 at 13:08