cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
A_Zaid
Level III

Dynamic updating of 'Color( )' in Graph Builder with selection from menu on the same dashboard as the graphs

Hello JMP Community,

 

I am working with a JMP add-in that generates an application. This application has only one module and creates a dashboard with several graphs. It also creates a display box that is embedded in the same dashboard and contains the list of columns in the data table used to generate the graphs. When a column is selected from the list, the row state (row colour, to be specific) is updated according to that selection. This is then reflected in the graphs which are coloured according to the row state. However, since the 'Color( )' variable in the Graph Builder is still empty, the legend of the graphs does not update in accordance with the colours displayed. If I make the display box with the column list show as a modal window, I can fill the 'Color( )' field based on the selection before the graphs are generated. The problem with this approach, though, is that the modal window cannot be embedded into the dashboard (or, at least I don't know how to), and, more importantly, it is not dynamical - you can only make the selection once at the start before the graphs are generated but then cannot make another selection without having to run the add-in again. I included an excerpt from my code. The 'win' object is the display box that has the list of columns and is embedded in the dashboard.

 

JMP App(
	Set Name( "Application" ),
	Set Description(
		"An empty workspace for creating custom applications with one or more windows and scripts"
	),
	Auto Launch( 1 ),
	Snap To Grid( 1 ),
	Show Grid( 1 ),
	Show Properties( 1 ),
	Show Sources( 1 ),
	Group By Category( 1 ),
	Dashboard Mode( 0 ),
	Parameters,
	Tables,/*(
		DataTable1 = GuiTable(
			Set Path(
				"/S:/17 - Contacts - Confidential material/Siemens/2018-08 - Bangkok test/05 - Analysis/All component compilation v6 (with Row column).jmp"
			),
			Set Label( "All component compilation v5" ),
			Set Location( "Current Data Table" ),
			Set Invisible( 0 )
		)
	),*/
	Script(JSL Quote(// This script is executed when the application is run.
					 // Named objects have been created for the application modules
					 // (for example, "Module1") and the pre-defined object
					 // "thisApplication" refers to the application object itself.
					 // Variables and functions declared here are scoped to the
					 // Application namespace.
		)),
	Allocate(
		Module1 = Plan(
			PreAllocate,
			Script(JSL Quote(// This script is executed when a new module instance is
							 // created.  The pre-defined object "thisModuleInstance" refers
							 // to the instance object, but other objects such as boxes and
							 // scripts have not yet been created.  Variables declared here are
							 // scoped to the ModuleInstance namespace.

							 // This special function will receive parameters passed to CreateInstance()
							 OnModuleLoad({});
							
							 dt = current data table(); //note that dt has to be defined before the thisModuleInstance' object is created. When defined after and the new "Row" column is added, the code does not recognise the new column and so outputs empty plots. This may be due to the namespaces: maybe the dt has to be in the application namespace and the after thisModuleInstance is created, it is in the module namespace.
							 If( Is Missing (Is Scriptable( Try ( Column( "Row" )))),
								 dt << New Column( "Row", Numeric, Values( 1 :: N Row() ), Format( "Best", 12 )));
								 
							 colnames = dt << get column names;
							 
							 
							 thisModuleInstance << Create Objects;
							 // After this point your module instance objects have been created
							 // and can be referred to by name (for example, "Button1").
							 show(chosen);
				)),
			Allocate(
				Outline1 = Outline Box();
				DataFilterContext1 = Data Filter Context Box();
				List1 = H List Box();
				List2 = V List Box();
				DataFilter1 = dt << Data Filter( Local );
				win = Platform(
								dt,
								H List Box(
									Panel Box( "Colour by:",
										collist = List Box(
										colnames,
										max selected( 1 ),
										chosen = collist << get selected;
										col = column(chosen);
										dt << Color or Mark by Column( col ),
										)
									)
								)
				);
				List3 = V List Box();
				List4 = H List Box();
				Report1 = Platform(
					dt,
					Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Fit to Window( "Maintain Aspect Ratio" ),
						Variables( X( :Row ), Y( :Friction ) ),
						Elements(
							Points( X, Y, Legend( 9 ) ),
							Smoother( X, Y, Legend( 10 ) )
						),
					)
				);
				Report2 = Platform(
					dt,
					Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Fit to Window( "Maintain Aspect Ratio" ),
						Variables( X( :Row ), Y( :Velocity ) ),
						Elements(
							Points( X, Y, Legend( 6 ) ),
							Smoother( X, Y, Legend( 7 ) )
						)
					)
				);

 

I look forward to hearing your suggestions.

 

Thank you all in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: Dynamic updating of 'Color( )' in Graph Builder with selection from menu on the same dashboard as the graphs

@A_Zaid ,

 

You stated

" you can only make the selection once at the start before the graphs are generated but then cannot make another selection without having to run the add-in again."

 

Actually that was an errata in our book. You can add or remove a variable by sending messages to the GraphBuilderBox(). See the script below.

 

You might have to add the interface to add or remove a variable. 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder(
	Variables( X( :height ), Y( :weight ) ),
	Elements( Points( X, Y ), Smoother( X, Y ) )
);
gbb = Report( gb )[Graph Builder Box( 1 )];
Wait( 0.5 );
gbb << Add Variable( {:sex, Role( "Wrap" )} );
wait( 0.5 );
gbb << Add Variable( {:sex, Role( "Color" )} );

wait( 0.5 );
gbb << Remove Variable( {:sex, Role( "Color" )} );

wait( 0.5 );
gbb << Add Variable( {:age, Role( "Color" )} );

View solution in original post

2 REPLIES 2
gzmorgan0
Super User (Alumni)

Re: Dynamic updating of 'Color( )' in Graph Builder with selection from menu on the same dashboard as the graphs

@A_Zaid ,

 

You stated

" you can only make the selection once at the start before the graphs are generated but then cannot make another selection without having to run the add-in again."

 

Actually that was an errata in our book. You can add or remove a variable by sending messages to the GraphBuilderBox(). See the script below.

 

You might have to add the interface to add or remove a variable. 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder(
	Variables( X( :height ), Y( :weight ) ),
	Elements( Points( X, Y ), Smoother( X, Y ) )
);
gbb = Report( gb )[Graph Builder Box( 1 )];
Wait( 0.5 );
gbb << Add Variable( {:sex, Role( "Wrap" )} );
wait( 0.5 );
gbb << Add Variable( {:sex, Role( "Color" )} );

wait( 0.5 );
gbb << Remove Variable( {:sex, Role( "Color" )} );

wait( 0.5 );
gbb << Add Variable( {:age, Role( "Color" )} );
A_Zaid
Level III

Re: Dynamic updating of 'Color( )' in Graph Builder with selection from menu on the same dashboard as the graphs

@gzmorgan0, thanks a lot for the prompt reply.

 

Your solution worked, so thanks for that too. I show in the code below how I adapted your solution to my needs for the benefit of others.

 

JMP App(
	Set Name( "Application" ),
	Set Description(
		"An empty workspace for creating custom applications with one or more windows and scripts"
	),
	Auto Launch( 1 ),
	Snap To Grid( 1 ),
	Show Grid( 1 ),
	Show Properties( 1 ),
	Show Sources( 1 ),
	Group By Category( 1 ),
	Dashboard Mode( 0 ),
	Parameters,
	Tables,/*(
		DataTable1 = GuiTable(
			Set Path(
				"/S:/17 - Contacts - Confidential material/Siemens/2018-08 - Bangkok test/05 - Analysis/All component compilation v6 (with Row column).jmp"
			),
			Set Label( "All component compilation v5" ),
			Set Location( "Current Data Table" ),
			Set Invisible( 0 )
		)
	),*/
	Script(JSL Quote(// This script is executed when the application is run.
					 // Named objects have been created for the application modules
					 // (for example, "Module1") and the pre-defined object
					 // "thisApplication" refers to the application object itself.
					 // Variables and functions declared here are scoped to the
					 // Application namespace.
		)),
	Allocate(
		Module1 = Plan(
			PreAllocate,
			Script(JSL Quote(// This script is executed when a new module instance is
							 // created.  The pre-defined object "thisModuleInstance" refers
							 // to the instance object, but other objects such as boxes and
							 // scripts have not yet been created.  Variables declared here are
							 // scoped to the ModuleInstance namespace.

							 // This special function will receive parameters passed to CreateInstance()
							 OnModuleLoad({});
							
							 dt = current data table(); //note that dt has to be defined before the thisModuleInstance' object is created. When defined after and the new "Row" column is added, the code does not recognise the new column and so outputs empty plots. This may be due to the namespaces: maybe the dt has to be in the application namespace and the after thisModuleInstance is created, it is in the module namespace.
							 If( Is Missing (Is Scriptable( Try ( Column( "Row" )))),
								 dt << New Column( "Row", Numeric, Values( 1 :: N Row() ), Format( "Best", 12 )));
								 
							 colnames = dt << get column names;
							 
							 thisModuleInstance << Create Objects;
							
							 // After this point your module instance objects have been created
							 // and can be referred to by name (for example, "Button1").
				)),
			Allocate(
				Outline1 = Outline Box();
				DataFilterContext1 = Data Filter Context Box();
				List1 = H List Box();
				List2 = V List Box();
				DataFilter1 = dt << Data Filter( Local );
				win = Platform(
					dt,
					H List Box(
						 Panel Box( "Colour by:",
								collist = List Box(
									colnames,
										max selected( 1 ),
										if( chosen != "",
											gbb1 << Remove Variable( {col, Role( "Color" )} );
											gbb2 << Remove Variable( {col, Role( "Color" )} );
										);
										chosen = collist << get selected;
										col = column(chosen);
										dt << Color or Mark by Column( col );
										gbb1 = Report( gb1 )[Graph Builder Box( 1 )];
										gbb1 << Add Variable( {col, Role( "Color" )} );
										gbb2 = Report( gb2 )[Graph Builder Box( 1 )];
										gbb2 << Add Variable( {col, Role( "Color" )} );
								)
						)
					)
				);
				List3 = V List Box();
				List4 = H List Box();
				Report1 = Platform(
					dt,
					gb1 = Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Fit to Window( "Maintain Aspect Ratio" ),
						Variables( X( :Row ), Y( :Friction ) ),
						Elements(
							Points( X, Y, Legend( 9 ) ),
							Smoother( X, Y, Legend( 10 ) )
						)
					)
				);
				Report2 = Platform(
					dt,
					gb2 = Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Fit to Window( "Maintain Aspect Ratio" ),
						Variables( X( :Row ), Y( :Velocity ) ),
						Elements(
							Points( X, Y, Legend( 6 ) ),
							Smoother( X, Y, Legend( 7 ) )
						)
					)
				);

Again, the above is just an excerpt from the full the code. As you can see above, I have to define gbb1 and gbb2 inside the 'win' platform, which is run every time a new selection is made. This might not be optimal in terms of speed, but it seems to be the only place they can be defined in if the code is to work (I'm not sure why).

 

Thank you once again @gzmorgan0.