Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

First time posting. I am working on creating some interactive materials for the engineering classes that I teach and have run into an issue that I cannot puzzle out. I am using a slider to allow for a user to interactively change parameters but I also want to allow for the user to change the range of the slider. When I implement this using the standard Slider everything works fine, however, if I replace the Slider with a HorizontalGauge, I get a situation where the pointer does not update smoothly.

So this works fine...

DynamicModule[{y = 1, LowerLimit = 1, UpperLimit = 10},
Column[{
   Row[{
     PopupMenu[Dynamic[LowerLimit], {1, 2, 3, 4}],
     PopupMenu[Dynamic[UpperLimit], {5, 6, 7, 8, 9, 10}]
     }],
   Dynamic[Slider[Dynamic[y], {LowerLimit, UpperLimit}]],
   Framed[
    Row[{
      "Slider Value", Spacer[10], Dynamic[y], Spacer[20], 
      "Lower Limit", Spacer[10], Dynamic[LowerLimit], Spacer[20], 
      "Upper Limit", Spacer[10], Dynamic[UpperLimit]
      }]
    ]
   }]
 ]

Mathematica graphics

But with Slider replaced with HorizontalGauge, I run into problems...

DynamicModule[{y = 1, LowerLimit = 1, UpperLimit = 10},
 Column[{
   Row[{
     PopupMenu[Dynamic[LowerLimit], {1, 2, 3, 4}],
     PopupMenu[Dynamic[UpperLimit], {5, 6, 7, 8, 9, 10}]
     }],
   Dynamic[HorizontalGauge[Dynamic[y], {LowerLimit, UpperLimit}]],
   Framed[
    Row[{
      "Slider Value", Spacer[10], Dynamic[y], Spacer[20], 
      "Lower Limit", Spacer[10], Dynamic[LowerLimit], Spacer[20], 
      "Upper Limit", Spacer[10], Dynamic[UpperLimit]
      }]
    ]
   }]
     ]

Mathematica graphics

Any suggestions and/or explanations would be greatly appreciated!!!

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

I think HorizontalGauge is just buggy. It shouldn't trigger a dynamic update when you change its state but it does. Simplest case:

HorizontalGauge[Dynamic[x]] // Dynamic

I would try using this "fixed" version

horizontalGauge = Refresh[HorizontalGauge[##], None] &

By the way, you could stick this into the built-in symbol's definition, and perhaps if you are convinced, add it to an init.m autoload file

HorizontalGauge;
Unprotect[HorizontalGauge];
Module[{guard = True},
  PrependTo[DownValues[HorizontalGauge],
   HoldPattern[HorizontalGauge[args___] /; guard] :> 
    Block[{guard = False}, 
     Refresh[HorizontalGauge[##], None] &[args]]]];
Protect[HorizontalGauge];
share|improve this answer
    
Nice! This works very well. Didn't you use this Refresh[..., None] trick elsewhere recently? –  rm -rf Jan 23 '13 at 22:16
    
@rm-rf, yes to fix Histogram, in the same way –  Rojo Jan 23 '13 at 22:16
    
Ah, yes. That's the one. –  rm -rf Jan 23 '13 at 22:17
add comment

Adding the option TrackedSymbols :> {LowerLimit, UpperLimit} to the Dynamic[..] that holds HorizontalGauge fixes the issue:

 DynamicModule[{y = 1, LowerLimit = 1, UpperLimit = 10}, 
 Column[{Row[{PopupMenu[Dynamic[LowerLimit], {1, 2, 3, 4}], 
 PopupMenu[Dynamic[UpperLimit], {5, 6, 7, 8, 9, 10}]}], 
 Dynamic[HorizontalGauge[Dynamic[y], {LowerLimit, UpperLimit}], 
     TrackedSymbols :> {LowerLimit, UpperLimit}], 
 Framed[Row[{"Slider Value", Spacer[10], Dynamic[y], Spacer[20], 
  "Lower Limit", Spacer[10], Dynamic[LowerLimit], Spacer[20], 
  "Upper Limit", Spacer[10], Dynamic[UpperLimit]}]]}]]
share|improve this answer
    
Thanks for the response! –  navillus5 Jan 24 '13 at 1:52
    
@navillus5, my pleasure. Welcome to Mathematica.SE. –  kguler Jan 24 '13 at 1:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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