For the purposes of an interactive demonstration I need to use a bullet gauge to readily show a moment in which the manipulated parameter passes a certain point. Like this, where the point Lambda=0.5 must be highlighted:

 col = If[\[Lambda] < 0.5, Red, Blue];
 Plot[Sin[\[Lambda]*x], {x, -\[Pi], \[Pi]} ],
   Control[{{\[Lambda], 0.5, 
        Row[{Style["\[Lambda]=", col, 14, Italic], 
          Style[NumberForm[\[Lambda], {3, 2}], col, 14, Italic]}], 
        ImageSize -> {70, 40}]}, 0.3, 0.7}],
     Dynamic[BulletGauge[{\[Lambda]}, {0.5}, {0.3, 0.7}, 
       GaugeStyle -> col, ImageSize -> {200, 60}]]}]

   }], SaveDefinitions -> True]

enter image description here

That works fine. What I do not like here is the excess of the elements. Indeed, there are both the slider and the bullet gauge. It is too much. It scatters the attention.

My question: Do you know a way to make the BulletGauge interactive, such that it could be picked up by the mouse (say, by the edge of the blue/red stripe) and moved like a slider?

If that were possible I would like to make a demonstration with only such an interactive BulletGauge but without any Slider.


You can use EventHandler to capture mouse clicks in the graphic of the BulletGauge. You need to rescale the mouse coordinates to make it work, but this should give you a decent start in the right direction:

DynamicModule[{x = 50, max = 100, update},
 update[] := (x = max * First[MousePosition["Graphics"]]);
  Dynamic[BulletGauge[x, 80, {0, max}]],
   "MouseClicked" :> update[],
   "MouseDragged" :> update[]


At the OP's request, here's a minimal example of the bullet gauge as a control for a plot. Note that I'm not using Manipulate: in cases like these, it's usually easier to code up your own Dynamics and controls inside of a DynamicModule.

  \[Lambda] = 0.5, 
  \[Lambda]min = 0.3,
  \[Lambda]max = 0.7,
 col[x_] := If[x < 0.5, Red, Blue];
 update[] := (\[Lambda] = \[Lambda]min + (\[Lambda]max - \[Lambda]min)*First[MousePosition["Graphics"]]);
     BulletGauge[\[Lambda], {0.5}, {\[Lambda]min, \[Lambda]max}, 
      GaugeStyle -> col[\[Lambda]]
    {"MouseClicked" :> update[], "MouseDragged" :> update[]}

   Dynamic[Plot[Sin[\[Lambda]*x], {x, -\[Pi], \[Pi]}]]

 SaveDefinitions -> True
  • $\begingroup$ Could you please integrate your construct with the plot. I did not succeed. $\endgroup$ – Alexei Boulbitch Apr 16 '18 at 12:17
  • $\begingroup$ Thank you, that's what I need. $\endgroup$ – Alexei Boulbitch Apr 17 '18 at 8:11

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.