cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
shampton82
Level VII

How to check if graph builder legend is showing or not

I was wondering what the script would be to check if the graph builder legend is showing or not.  I want to make a toolbar shortcut that would show or hide the legend depending on the state the legend is in (if showing then hide and if hidden then show).  thanks for any suggestions!

 

Steve

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to check if graph builder legend is showing or not

If you use the Visibility message to open and close the Legend, the Get Visibility message will return the status.

names default to here(1);
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );
gb =Graph Builder(
	Size( 525, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ) )
);

report(gb)[legendbox(1)]<<visibility("collapse");

report(gb)[legendbox(1)]<<get visibility;

However, the Visibility status will not change if the legend is set using  

gb << Show Legend(0);
// or
gb << Show Legend(1);
Jim

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How to check if graph builder legend is showing or not

I tried to check how I could see if legend is showing or not, but couldn't figure out how it is being hidden by Show Legend() option. Show  properties didn't help either.

jthi_0-1645300290521.png

So only thing that easily came to my mind is to get script of the graph builder as string and then check if it has Show Legend(0) in it... this won't work if user has preferences changed so you will have to check for them also. Something like this might work (and there hopefully is easier/more robust way to do this):

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(Variables(X(:Sex), Y(:Height), Group X(:Age)), Elements(Box Plot(X, Y)));

change_legend_state = function({gb_ref}, {Default Local},
	legend_pref = Char(Get Platform Preference(Graph Builder(Show Legend)));
	gb_script = Char(gb_ref << Get Script());
	If(Contains(legend_pref, "Show Legend(0)") & !Contains(gb_script, "Show Legend(1)"),
		gb_ref << Show Legend(1);
	,
		gb_ref << Show Legend(0);
	);	
);
wait(1);
change_legend_state(gb);
wait(1);
change_legend_state(gb);

 

 

 

 

-Jarmo
txnelson
Super User

Re: How to check if graph builder legend is showing or not

If you use the Visibility message to open and close the Legend, the Get Visibility message will return the status.

names default to here(1);
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );
gb =Graph Builder(
	Size( 525, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ) )
);

report(gb)[legendbox(1)]<<visibility("collapse");

report(gb)[legendbox(1)]<<get visibility;

However, the Visibility status will not change if the legend is set using  

gb << Show Legend(0);
// or
gb << Show Legend(1);
Jim
shampton82
Level VII

Re: How to check if graph builder legend is showing or not

This is close enough so appreciate it!  It's to bad there isn't something like <<get show legend(); to get the legend state (1/0) since as you said this solution will not work if the legend state has been changed through either JSL or the control panel.