Subscribe Bookmark RSS Feed

Multiple Column Switchers

msharp

Super User

Joined:

Jul 28, 2015

Is there a way from preventing the same column from being picked when running multiple column switchers?

     dt = open("$SAMPLE_DATA/Candy Bars.jmp");

     biv = dt << Bivariate(

            Y( :Saturated fat g ),

            X( :Sugars g ),

            SendToReport( Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 593, 564 )} ) )

       );

     cs1 = biv << Column Switcher(

            :Saturated fat g,

            {:Name( "Serving/pkg" ), :Calories, :Total fat g, :Saturated fat g,

            :Cholesterol g, :Sodium mg, :Carbohydrate g, :Dietary fiber g, :Sugars g,

            :Protein g, :Vitamin A %RDI, :Vitamin C %RDI, :Calcium %RDI, :Iron %RDI}

       );

     cs2 = biv << Column Switcher(

            :Sugars g,

            {:Name( "Oz/pkg" ), :Calories, :Total fat g, :Saturated fat g,

            :Cholesterol g, :Sodium mg, :Carbohydrate g, :Dietary fiber g, :Sugars g,

            :Protein g, :Vitamin A %RDI, :Iron %RDI}

       );

     cs1 << Run;

     cs2 << Run;

If you let this run long enough eventually cs2 catchs up with cs1 and throws an error.  Since the columns are now the same, cs1 and cs2 lose their X/Y dependencies and now change both parameters.  Thus X=Y is now always true.

Anyone know any work around?

4 REPLIES
David_Burnham

Super User

Joined:

Jul 13, 2011

This is an irritating limitation of the column switchers.  The workaround is to not use column switchers but implement the functionality yourself using list boxes (or combo boxes).  Attach to these list boxes a script that will delete the bivariate plot and add create a new one based on the list box selections.

-Dave
msharp

Super User

Joined:

Jul 28, 2015

So, I've done this, but since the column names are rather long I can't get them to format correctly in my list box.  Do you know how to make them appear as they do in the column switcher?  (Firstpart....lastpart)?

msharp

Super User

Joined:

Jul 28, 2015

Actually I got the formatting to work using Col List Box function.  However, if anyone spent some time to try and create the custom play and stop button, YOU'D HAVE MY MANY THANKS!

Here's the code I quickly made for the custom switchers where xcolumns and ycolumns are the list of columns wanted for switching through, and dt is the data table.

xnlines = If(nitems(xcolumns) > 15, 15, nitems(xcolumns));

ynlines = If(nitems(ycolumns) > 15, 15, nitems(ycolumns));

vlb << Append(hlb = Hlistbox(VlistBox(

     Text Box("Column X"),

     columnswitcherX = Col List Box(width(250), maxSelected(1), nlines(xnlines)),

     Text Box("Column Y"),

     columnswitcherY = Col List Box(width(250), maxSelected(1), nlines(ynlines)))));

columnswitcherX << Append(xcolumns);

columnswitcherY << Append(ycolumns);

columnswitcherX << Set Selected(1);

columnswitcherX << Set Script(

     bivcolx = columnswitcherX << get selected;

     bivcoly = columnswitcherY << get selected;

     try(interactivebiv << Delete Box);

     hlb << Append(interactivebiv = dt << Bivariate( X( Column(dtinteractive, bivcolx) ), Y( Column(dtinteractive, bivcoly) ), Fit Line( {Line Color( {213, 72, 87} )} )) )

     );

columnswitcherY << Set Script(

     bivcolx = columnswitcherX << get selected;

     bivcoly = columnswitcherY << get selected;

     try(interactivebiv << Delete Box);

     hlb << Append(interactivebiv = dt << Bivariate( X( Column(dtinteractive, bivcolx) ), Y( Column(dtinteractive, bivcoly) ), Fit Line( {Line Color( {213, 72, 87} )} )) )

     );

columnswitcherY << Set Selected(1);

Craige_Hales

Staff

Joined:

Mar 21, 2013

Here's the buttons.  This uses Schedule() to run the animation and setIcon() to get the graphic.  the Write() statements should be replaced with the logic to change the variables.  The OnClose sets up the visible window to close the scheduler window when the visible window is closed.

9673_buttons.png


stop = 0; // animating state


loopFun = Function( {},


    If( !stop,


        Write( "go again\!n" ); // logic for animation


        Schedule( .5, loopFun() ); // continue the animation 1/2 second later


    )


);


New Window( "buttons",


    <<OnClose(stop=1;window("Scheduler")<<closewindow), // clean up when the window closes


    hlistbox(


        Button Box( "",


            Write( "step forward\!n" ); // logic to step forward


        ,


            <<seticon( "StepForward" )


        ),


        Button Box( "",


            Write( "step backward\!n" ); // logic


        ,


            <<seticon( "StepBackward" )


        ),


        Button Box( "",


            Write( "stop\!n" ); // stop the animation (reset start point?)


            stop = 1; // animating state


        ,


            <<seticon( "Stop" )


        ),


        Button Box( "",


            stop = 0; // animating state: if previously stopped, allow resume


            loopFun(); // kick off the animation


            window("Scheduler")<<minimizewindow; // hide the scheduler window


        ,


            <<seticon( "Go" )


        ),


        Button Box( "",


            Write( "pause\!n" ); // pause the animation (keep current position?)


            stop = 1; // animating state


        ,


            <<seticon( "Pause" )


        )


    )


);


Craige