Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Combining Slider and SetterBar in Manipulate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115216] Re: Combining Slider and SetterBar in Manipulate
  • From: JohnH <ununquadium113 at yahoo.com>
  • Date: Tue, 4 Jan 2011 04:27:50 -0500 (EST)
  • References: <if1o6b$p86$1@smc.vnet.net>

On Dec 24 2010, 1:12 am, John Fultz <jfu... at wolfram.com> wrote:
> The string is merely a label.  The actual value of qt is the numeric value on
> the lhs of the rules.  So, instead of...
>
> {{qt, 7, "Special"}, {7 -> "Rising", 5 -> "Smile", 20 -> "Saws",
>   12 -> "Falling"}, ControlType -> SetterBar}
>
> it would be something like this...
>
> {{qt, 3}, {7 -> "Rising", 5 -> "Smile", 20 -> "Saws",
>   12 -> "Falling"}, ControlType -> SetterBar}
>
> I.e., the initial value would probably be a number (since you seem to be using
> numbers as values...although that's certainly not required), and it has to be a
> *different* number than any of the ones you're using.
>
> Also...a bit of unsolicited advice.  Your use of Block is a *bad* idea. It's
> always bad to reference Block-scoped or Module-scoped variables declared outside
> of a Manipulate or Dynamic from within that Manipulate/Dynamic.  If you're
> wanting to localize the variable 'someData', then Manipulate offers you an easy
> way to do that.  Add someData as a control variable, but no control appearance.  
> I.e.,
>
> {someData, ControlType->None}
>
> So, after my proposed changes, your code looks like:
>
> Manipulate[
>  ListLinePlot[someData[[tinx, 2 ;;]]], {{tinx, 1, "Time"}, 1, 25,
>   1}, {{qt, 3}, {7 -> "Rising", 5 -> "Smile", 20 -> "Saws",
>    12 -> "Falling"}, ControlType -> SetterBar},
>  Pane[Text@Dynamic[tinx]], {someData, ControlType -> None},
>  ControlPlacement -> Top,
>  Initialization :> (someData =
>     Table[Sin[i j]*Cos[j] // N, {i, 25}, {j, 12}];
>    tinx = 1)]
>
> Sincerely,
>
> John Fultz
> jfu... at wolfram.com
> User Interface Group
> Wolfram Research, Inc.
>
>
>
> On Thu, 23 Dec 2010 03:56:25 -0500 (EST), JohnH wrote:
> > I am looking for a solution to what should be a common and simple
> > problem. I have a slider to control time, but I also want to use a
> > SetterBar to pick out some interesting dates. The bare bones of my
> > current attempt is:
>
> > Block[{someData},
> > Manipulate[
> > ListLinePlot[someData[[tinx,2;;]]],
> > {{tinx,1,"Time"},1,25,1},
> > {{qt,7,"Special"},{7->"Rising",5->"Smile",20->"Saws",12-
> >> "Falling"},ControlType->SetterBar},
> > Pane[Text@Dynamic[tinx]],
> > ControlPlacement->Top,
> > Initialization:>(
> > someData=Table[Sin[i j]*Cos[j]//N,{i,25},{j,12}];
> > tinx=1)
> > ]
> > ]
>
> > Ideally, none of the setter buttons would be selected if the time was
> > not one of the special ones.  Clicking on one of the setter buttons
> > would set the time to that value.
>
> > Any suggestions would be appreciated.

John,

Thank you for your reply, particularly the extra advice (I'm always
looking for better ways to do things).
However, the code you proposed does not do what I am looking for. I
essentially want to pick an index
into the data using either the slider, or via the setter bar (to pick
particularly interesting cases). I did find
a way to do it. Again, advice on a more correct way to do it would be
appreciated. The code is:

Manipulate[
 ListLinePlot[someData[[tinx, 2 ;;]]],
 {{tinx, 1, "Time"}, 1, 25, 1},
 Style@Pane[
   Row@{"Special: ",
     SetterBar[Dynamic[tinx], Evaluate[si2],
      Appearance -> "Horizontal"]}],
 Pane[Text@Dynamic[tinx]],
 {someData, ControlType -> None},
 {specialIndices, ControlType -> None},
 {si2, ControlType -> None},
 ControlPlacement -> Top,
 Initialization :> (
   someData = Table[Sin[i j]*Cos[j] // N, {i, 25}, {j, 12}];
   specialIndices = {7, 5, 20, 12};
   si2 = {7 -> "Rising", 5 -> "Smile", 20 -> "Saws",
     12 -> "Falling"};
   tinx = 1)
 ]

This seems to do the right thing but is perhaps not the right way to
do it. BTW, I did remove
my use of Block by making the variables into controls.


  • Prev by Date: Re: NDSolve, three 2-d order ODE, 6 initial conditions
  • Next by Date: Re: pattern bugs and comment on intuitive syntax for the New Year
  • Previous by thread: Re: WAV Import[] and Integer16 Issue
  • Next by thread: Re: Combining Slider and SetterBar in Manipulate