4
$\begingroup$

I am trying to get buttons to work simultaneously with tooltips in 3D plots. Button has a Tooltip option, but it doesn't seem to work.

Consider code that creates a red point that turns green when clicked, and the point works with a tooltip.

In the following, Button works , but its Tooltip option does not.

DynamicModule[{b = 1}, Graphics[
  
  Dynamic@Button[Style[Point[{0, 0}],
     {Red, Green}[[Mod[b, 2, 1]]],
     PointSize[0.1]], b++, Tooltip -> "hi"],
  
  ImageSize -> Small]]

1

Thankfully, we can add the Tooltip function to make it work. Both Tooltip[Button[ and Button[Tooltip[ work. For example...

DynamicModule[{b = 1}, Graphics[
  
  Dynamic@Tooltip[Button[Style[Point[{0, 0}],
      {Red, Green}[[Mod[b, 2, 1]]],
      PointSize[0.1]], b++], "hi"],
  
  ImageSize -> Small]]

2

However, all three fail in some 3D plots.

We can see the button works, but its Tooltip option still fails.

DynamicModule[{b = 1},
 Dynamic@ListLinePlot3D[
   
   {{2.1, 
     Button[Style[2.9, {Red, Green}[[Mod[b, 2, 1]]]], b++, 
      Tooltip -> "hi"], 2.8, 1.9}, {2.2, 2.7, 1.1, 2.2}},
   
   PlotMarkers -> {Automatic, 0.05}]]

3

With Tooltip[Button[, Tooltip works but Button does not.

DynamicModule[{b = 1}, Dynamic@ListLinePlot3D[
   
   {{2.1, 
     Tooltip[Button[Style[2.9, {Red, Green}[[Mod[b, 2, 1]]]], b++]], 
     2.8, 1.9}, {2.2, 2.7, 1.1, 2.2}},
   
   PlotMarkers -> {Automatic, 0.05}]]

4

With Button[Tooltip[, Button works but Tooltip does not.

5

How can I get such a button to work with a tooltip in ListLinePlot3D?

$\endgroup$

1 Answer 1

5
$\begingroup$

This may do it (it does what I think you might want):

DynamicModule[{b = 1}, 
  ListLinePlot3D[{{2.1, 
     Button[Style[2.9, {Red, Green}[[Mod[b, 2, 1]]] // Dynamic], b++, 
      Tooltip -> "hi"], 2.8, 1.9}, {2.2, 2.7, 1.1, 2.2}}, 
   PlotMarkers -> {Automatic, 0.05}]] /. 
 c : Button[p_, r___] :> 
  Button[Tooltip[p, Tooltip /. Options[c] /. Tooltip :> Sequence[]], 
   r]

Might be a bug, I suppose.

Alternative:

DynamicModule[{b = 1},
 Dynamic[
  ListLinePlot3D[{{2.1,
      Button[Style[2.9, {Red, Green}[[Mod[b, 2, 1]]]], b++, 
       Tooltip -> "hi"], 2.8, 1.9}, {2.2, 2.7, 1.1, 2.2}}, 
    PlotMarkers -> {Automatic, 0.05}] /. 
   c : Button[p_, r___] :> 
    Button[Tooltip[p, Tooltip /. Options[c] /. Tooltip :> Sequence[]],
      r]
  ]]
$\endgroup$
3
  • $\begingroup$ This is great, but unfortunately, due to the problem discussed in mathematica.stackexchange.com/q/266773/12697, my code only works with Dynamic in front of ListLinePlot3D. $\endgroup$ Apr 22, 2022 at 4:03
  • $\begingroup$ @JustSomeOldMan See update. $\endgroup$
    – Michael E2
    Apr 22, 2022 at 4:20
  • $\begingroup$ I do wonder if you are aware of the gift you are to the world. Thank you! $\endgroup$ Apr 22, 2022 at 20:48

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.