16
$\begingroup$

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.)

$\endgroup$
12
  • $\begingroup$ We'll see if this draws answers here. $\endgroup$
    – rcollyer
    Feb 2, 2012 at 3:31
  • $\begingroup$ On my system (Mathematica 8.0.1 Linux x64) the tooltip is displayed at the mouse position, not necessarily at the bottom right. $\endgroup$
    – David Z
    Feb 2, 2012 at 6:46
  • $\begingroup$ 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. $\endgroup$ Feb 2, 2012 at 6:51
  • 2
    $\begingroup$ 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... ;-) $\endgroup$ Mar 6, 2012 at 1:26
  • 7
    $\begingroup$ 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. $\endgroup$
    – John Fultz
    Mar 6, 2012 at 4:12

1 Answer 1

11
+50
$\begingroup$

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

$\endgroup$
7
  • $\begingroup$ 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. $\endgroup$
    – Heike
    Mar 8, 2012 at 10:07
  • $\begingroup$ 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. $\endgroup$
    – DavidC
    Mar 8, 2012 at 10:24
  • $\begingroup$ 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. $\endgroup$
    – DavidC
    Mar 8, 2012 at 10:32
  • $\begingroup$ 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. $\endgroup$
    – Heike
    Mar 8, 2012 at 10:51
  • 1
    $\begingroup$ 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. $\endgroup$ Mar 8, 2012 at 11:52

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.