cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
teoten
Level II

Use if condition for a graph builder

Hi, I have been trying for a while to write a code in JSL where depending on the value of certain variable, the graph obtained from graph builder changes.

 

My particular example right now is pretty simple, I have a check box and depending on the user selection (checked/unchecked) I want to add or remove groups into the graph using the local filter. Here is a very simple example

 

dt = Open( "$SAMPLE_DATA/Analgesics.jmp" );
// Open Analgesics

cb = 1; // Predefined value

// Check box to Remove group A from the graph usw = New Window("Ignore A?", << Modal, //Check Box defaulted to checked ignore checkIgnore = check box({"Ignore A?"}, << Set(1,1), cb = checkIgnore << Get()) ); // Answer to Cancel or close buttons If( usw["button"] == -1, throw("User cancelled") ); show(cb); // I can see how the value of cb changes between 0 and 1 nw = New Window( "Example Report", // Box plot with dots dot_box_plot = dt << Graph Builder( Show Control Panel( 0 ), Show Legend( 0 ), Show Title( 0 ), Variables( X(:drug ), Y( :pain ), Color(:drug ) ), Elements( Position( 1, 1 ), Points( X, Y, Legend( 2 ) ), Box Plot( X, Y, Legend( 3 ) ) ), Elements( Position( 2, 1 ), Points( X, Y, Legend( 2 ) ), Box Plot( X, Y, Legend( 3 ) ) ), SendToReport( Dispatch( {}, "X title", TextEditBox, {Set Text( "" )} ) ), /* This is the part that I'd like to make interactive to keep or remove A-group from the plot depending on user selection */ if(cb == 1, Local Data Filter( Close Outline( 1 ), Add Filter( columns( :drug ), Where( :Drug != "A" ) ) ) ) ) );

As you can see, there should be something wrong in my part with the if statement because nothing changes, the plot keeps all groups. And of course, when I remove only the IF() part, my plot ignores the group A.

 

I would be very thankful for any suggestions.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Use if condition for a graph builder

The preferred way to handle modifications to platform code, is to pass messages to the  platform after the initial processing of the platform.  Attempting to modify the platform statements becomes too messy and too erratic.

Below is your script modified to add the filter after the Graph Builder platform has run.  And then to hide the actual display of the Local Data Filter

collapse.PNG

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Analgesics.jmp" );
// Open Analgesics

cb = 1; // Predefined value// Check box to Remove group A from the graph
usw = New Window( "Ignore A?",
	<<Modal, 
						//Check Box defaulted to checked ignore
	checkIgnore = Check Box( {"Ignore A?"}, <<Set( 1, 1 ), cb = checkIgnore << Get() )
);
				
// Answer to Cancel or close buttons
If( usw["button"] == -1,
	Throw( "User cancelled" )
);
				
Show( cb ); // I can see how the value of cb changes between 0 and 1

nw = New Window( "Example Report", 
	// Box plot with dots
	dot_box_plot = dt << Graph Builder(
		Show Control Panel( 0 ),
		Show Legend( 0 ),
		Show Title( 0 ),
		Variables( X( :drug ), Y( :pain ), Color( :drug ) ),
		Elements( Position( 1, 1 ), Points( X, Y, Legend( 2 ) ), Box Plot( X, Y, Legend( 3 ) ) ),
		Elements( Position( 2, 1 ), Points( X, Y, Legend( 2 ) ), Box Plot( X, Y, Legend( 3 ) ) ),
		SendToReport( Dispatch( {}, "X title", TextEditBox, {Set Text( "" )} ) ),

	)
);		

If( cb == 1,
	dot_box_Plot << Local Data Filter( Add Filter( columns( :drug ), Where( :Drug != "A" ) ) );
	(report(dot_box_plot)<<top parent)["Local Data Filter"] << visibility("collapse");
	
	// Or you could specify the below commented code that would just close the filter display
	// (Report( dot_box_plot ) << top parent)["Local Data Filter"] << Close( 1 );
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Use if condition for a graph builder

The preferred way to handle modifications to platform code, is to pass messages to the  platform after the initial processing of the platform.  Attempting to modify the platform statements becomes too messy and too erratic.

Below is your script modified to add the filter after the Graph Builder platform has run.  And then to hide the actual display of the Local Data Filter

collapse.PNG

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Analgesics.jmp" );
// Open Analgesics

cb = 1; // Predefined value// Check box to Remove group A from the graph
usw = New Window( "Ignore A?",
	<<Modal, 
						//Check Box defaulted to checked ignore
	checkIgnore = Check Box( {"Ignore A?"}, <<Set( 1, 1 ), cb = checkIgnore << Get() )
);
				
// Answer to Cancel or close buttons
If( usw["button"] == -1,
	Throw( "User cancelled" )
);
				
Show( cb ); // I can see how the value of cb changes between 0 and 1

nw = New Window( "Example Report", 
	// Box plot with dots
	dot_box_plot = dt << Graph Builder(
		Show Control Panel( 0 ),
		Show Legend( 0 ),
		Show Title( 0 ),
		Variables( X( :drug ), Y( :pain ), Color( :drug ) ),
		Elements( Position( 1, 1 ), Points( X, Y, Legend( 2 ) ), Box Plot( X, Y, Legend( 3 ) ) ),
		Elements( Position( 2, 1 ), Points( X, Y, Legend( 2 ) ), Box Plot( X, Y, Legend( 3 ) ) ),
		SendToReport( Dispatch( {}, "X title", TextEditBox, {Set Text( "" )} ) ),

	)
);		

If( cb == 1,
	dot_box_Plot << Local Data Filter( Add Filter( columns( :drug ), Where( :Drug != "A" ) ) );
	(report(dot_box_plot)<<top parent)["Local Data Filter"] << visibility("collapse");
	
	// Or you could specify the below commented code that would just close the filter display
	// (Report( dot_box_plot ) << top parent)["Local Data Filter"] << Close( 1 );
);
Jim
teoten
Level II

Re: Use if condition for a graph builder

Great, it works. And thank you very much for the advice, it is good to know that the best strategy is to pass messages to the platform after the initial processing of the platform, it is what was giving me some troubles in my code in general. Noted now!
SamD
Level II

Re: Use if condition for a graph builder

Hi Jim, I need help with my most advances script yet. in a nut shell, the script will ask the use to enter a register number between 1-5

the script does nothing when I add a while statement or if statement. if add one expression only without the while or if statement it works fine.

but I am trying to half works for multiple registers, I normally get files for individual registers and wanted to use a single script to cover all 5 variety.

thanks in advance.

Sam

 

full script below

w = New Window( "Enter Register number to Analyze", // opens a window with a title and this content...

       Border Box( top( 20 ), bottom( 20 ), Left( 160 ), Right( 160 ), // window dressing

              V List Box( // V and H lists nest to organize the display boxes

                     H Center Box( Text Box( "Type in Register number below" ) ), // a second title, centered

                     Spacer Box( size( 1, 10 ) ), // a little vertical space

                     //            H List Box( Text Box( "value 1: " ), Number Edit Box( v1 ) ), // data entry

                     H List Box( Text Box( "Enter Register Num:" ), Register_Num_teb = Text Edit Box( "", <<set width( 200 ) ), ),

                     Spacer Box( size( 1, 10 ) ), // a little vertical space

                     H Center Box( // center the button

                           Button Box( "Continue", // this script runs when the button is pressed...

                                  Register = Register_Num_teb << get text();

                                  // make a new table with the values...

                           ///////////////////////////////////////////////////////////////////////////////////////////starting the loop

                                  While( Register == 1,

                                         dothis = Expr(

                                                New Column( "start_time", Numeric, Continuous, Formula( (:rise_time_scope_v_vout * 1000) / 0.8 ) )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:start_time}, After( :Register1_active ) );

                                         dothis = Expr(

                                                New Column( "SoftStart_Accuracy%",

                                                       Numeric,

                                                       Continuous,

                                                       Formula( ((:Register1_tsoftstart - :start_time) / :Register1_tsoftstart) * 100 )

                                                )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:SoftStart_Accuracy%}, After( :start_time ) );

                                  );

 

                                  While( Register == 2,

                                         dothis = Expr(

                                                New Column( "start_time", Numeric, Continuous, Formula( (:rise_time_scope_v_vout * 1000) / 0.8 ) )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:start_time}, After( :Register2_active ) );

                                         dothis = Expr(

                                                New Column( "SoftStart_Accuracy%",

                                                       Numeric,

                                                      Continuous,

                                                       Formula( ((:Register2_tsoftstart - :start_time) / :Register2_tsoftstart) * 100 )

                                                )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:SoftStart_Accuracy%}, After( :start_time ) );

                                  );

 

                                  While( Register == 3,

                                         dothis = Expr(

                                                New Column( "start_time", Numeric, Continuous, Formula( (:rise_time_scope_v_vout * 1000) / 0.8 ) )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:start_time}, After( :Register3_active ) );

                                         dothis = Expr(

                                                New Column( "SoftStart_Accuracy%",

                                                       Numeric,

                                                       Continuous,

                                                       Formula( ((:Register3_tsoftstart - :start_time) / :Register3_tsoftstart) * 100 )

                                                )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:SoftStart_Accuracy%}, After( :start_time ) );

                                  );

 

                                  While( Register == 4,

                                         dothis = Expr(

                                                New Column( "start_time", Numeric, Continuous, Formula( (:rise_time_scope_v_vout * 1000) / 0.8 ) )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:start_time}, After( :Register4_active ) );

                                         dothis = Expr(

                                                New Column( "SoftStart_Accuracy%",

                                                       Numeric,

                                                       Continuous,

                                                       Formula( ((:Register4_tsoftstart - :start_time) / :Register4_tsoftstart) * 100 )

                                                )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:SoftStart_Accuracy%}, After( :start_time ) );

                                  );

 

                                  While( Register == 5,

                                         dothis = Expr(

                                                New Column( "start_time", Numeric, Continuous, Formula( (:rise_time_scope_v_vout * 1000) / 0.8 ) )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:start_time}, After( :Register5_active ) );

                                         dothis = Expr(

                                                New Column( "SoftStart_Accuracy%",

                                                       Numeric,

                                                       Continuous,

                                                       Formula( ((:Register5_tsoftstart - :start_time) / :Register5_tsoftstart) * 100 )

                                                )

                                         );

                                         dothis;

                                         dt << MoveSelectedColumns( {:SoftStart_Accuracy%}, After( :start_time ) );

                                  );

 

                                 ///////////////////////////////////////////////////////////////////////////////////////////

                                  // optionally, close the dialog. Or, you might want to run it again...

                                  w << closeWindow; // just the dialog, not the report

                           )

                     )

              )

       )

);