cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
BHarris
Level VI

Toggle visibility of major grid lines in Graph Builder via keystroke

I'd like to configure an add-in to toggle the visibility of major grid lines in Graph Builder (both X and Y), but I'm struggling with the JSL piece...  I have the GB object, and the SendToReport( .. Dispatch... code, but it seems to want the variable name associated with the X and Y axes, and my Add-in won't know what those are.

 

Is this doable?

 

Here's what I have so far:

// steps to get last_gb scriptable object...

// send setting change
last_gb << SendToReport( Dispatch( {}, "myXaxis", ScaleBox, { Label Row (Show Major Grid( not(Label Row (Show Major Grid ) ) ) ) ) } ), Dispatch( {}, "myXYaxis", ScaleBox, { Label Row (Show Major Grid( not(Label Row (Show Major Grid ) ) ) ) ) } ) )
1 ACCEPTED SOLUTION

Accepted Solutions
BHarris
Level VI

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

That did it!  Here's the solution for anyone who needs a script to toggle on/off gridlines in all of the plots in Graph Builder:

Names Default To Here( 1 );

win = Get Window List();

//Find graph builder windows
graphs = Filter Each( {w}, win,
	If( Length( w << XPath( "//OutlineBox[@helpKey='Graph Builder']" ) ) > 0,
		1,
		0
	)
);

gb = graphs[N Items( graphs )][Outline Box( "Graph Builder" )] << Get Scriptable Object;
gb_rpt = gb << Report();
gb_axis1 = gb_rpt[AxisBox( 1 )];
axis_script = gb_axis1 << get script();
cur_gridvalue = Try(
	axis_script["Label Row"]["Show Major Grid"], // not found
	Arg( Arg( Get Preference( Major Grid Lines ) ) )
);
axisboxes = gb_rpt << XPath( "//AxisBox" );
For Each( {anAxisBox,anIndex}, axisboxes,
	If( cur_gridValue,
		anAxisBox << Show Major Grid( 0 ),
		anAxisBox << Show Major Grid( 1 )
	)
);

Thanks to Jarmo and Yuichi for their help!

 

****************************************
ps.  I don't understand the "<< Get XML" tip at all -- I tried putting it in 4 different places and never got out any XML with "<AxisBox>" in it (although I did get lots of XML out...).  How did you learn to script JSL so well?

 

View solution in original post

7 REPLIES 7

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

Hello @BHarris ,

How about using axis box to show major grid?
If you want to use send to report message, one idea is to use get variable message to get variable.

// #1 Example for Axis Box
gb_rpt = gb_ob << Report();
gb_rpt[axis box( 1 )] << Show Major Grid( 1 );
gb_rpt[axis box( 2 )] << Show Major Grid( 1 );

// #2 Example for send to report
var1 = gb_ob << Get Variable( 1 );
var2 = gb_ob << Get Variable( 2 );
Eval(
	Substitute(
			Expr(
				gb_ob << send to report(
					Dispatch(
						{},
						_var_,
						ScaleBox,
						{Label Row( Show Major Grid( 1 ) )}
					)
				)
			),
		Expr( _var_ ), Eval( Char( var1[1] ) )
	)
);


I hope it works for your problem.

BHarris
Level VI

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

This is very close!  I'd like the script to toggle the grid state on and off whenever it is run, but this is only able to turn the grids on.  I just spent about an hour trying to figure out how to read the grid state from an AxisBox, but the documentation gets very sparse when I get down to "Label Row"...

 

How can I read the current state of the major grid?

jthi
Super User

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

There might be better ways, but one option you could try is to send << get script to axisbox and get the Show Major Grid from that. If that isn't visible there at all, then you should be able to get the value from users properties

axis_script = axisbox << get script();

cur_gridvalue  = Try(
	axis_script["Label Row"]["Show Major Grid"];
	Print("Grid");
, // not found
	Arg(Arg(Get Preference(Major Grid Lines)));
	Print("Preference");
);

 

-Jarmo
BHarris
Level VI

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

Much closer!   It now turns off gridlines for the first x- and first y-axis box, but not all of the axis boxes on a multi-axis plot:

 

BHarris_0-1689820855531.png

 

How can I iterate over all the axis boxes?  Here's what I have so far:

 

Names Default To Here( 1 );

win = Get Window List();

//Find graph builder windows
graphs = Filter Each({w}, win,
	If(Length(w << XPath("//OutlineBox[@helpKey='Graph Builder']")) > 0, 1, 0)
);

gb = graphs[N Items(graphs)][OutlineBox("Graph Builder")] << Get Scriptable Object;
gb_rpt = gb << Report();
gb_axis1 = gb_rpt[AxisBox( 1 )];
gb_axis2 = gb_rpt[AxisBox( 2 )];
axis_script = gb_axis1 << get script();
cur_gridvalue = Try(
	axis_script["Label Row"]["Show Major Grid"], // not found
	Arg( Arg( Get Preference( Major Grid Lines ) ) )
);

If( cur_gridValue,
	gb_axis1 << Show Major Grid( 0 );
	gb_axis2 << Show Major Grid( 0 );
,
	gb_axis1 << Show Major Grid( 1 );
	gb_axis2 << Show Major Grid( 1 );
);

(ps.  I would've never figured out the "get script" or "arg( arg(" thing on my own.  I feel like I'm a semi-competent 25-years-experience scripter, but I still feel quite lost in JSL -- very hard to tell what it's doing a lot of the time.)

jthi
Super User

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

You could use << XPath to get all the AxisBox references and then either loop over them and modify them one by one that OR send same message to all of them. This might need some additional checks to not modify any axisboxes you don't want to change. 

axisboxes = gb_rpt << XPath("//AxisBox"); 

<< Get XML might be helpful when you are checking if there are anything specific in the AxisBox which could help you narrow down the references (charID could be one). You can then modify the XPath query to use this and make it more accurate.

jthi_0-1689829614055.png

 

-Jarmo
BHarris
Level VI

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

That did it!  Here's the solution for anyone who needs a script to toggle on/off gridlines in all of the plots in Graph Builder:

Names Default To Here( 1 );

win = Get Window List();

//Find graph builder windows
graphs = Filter Each( {w}, win,
	If( Length( w << XPath( "//OutlineBox[@helpKey='Graph Builder']" ) ) > 0,
		1,
		0
	)
);

gb = graphs[N Items( graphs )][Outline Box( "Graph Builder" )] << Get Scriptable Object;
gb_rpt = gb << Report();
gb_axis1 = gb_rpt[AxisBox( 1 )];
axis_script = gb_axis1 << get script();
cur_gridvalue = Try(
	axis_script["Label Row"]["Show Major Grid"], // not found
	Arg( Arg( Get Preference( Major Grid Lines ) ) )
);
axisboxes = gb_rpt << XPath( "//AxisBox" );
For Each( {anAxisBox,anIndex}, axisboxes,
	If( cur_gridValue,
		anAxisBox << Show Major Grid( 0 ),
		anAxisBox << Show Major Grid( 1 )
	)
);

Thanks to Jarmo and Yuichi for their help!

 

****************************************
ps.  I don't understand the "<< Get XML" tip at all -- I tried putting it in 4 different places and never got out any XML with "<AxisBox>" in it (although I did get lots of XML out...).  How did you learn to script JSL so well?

 

jthi
Super User

Re: Toggle visibility of major grid lines in Graph Builder via keystroke

I have learned scripting just by scripting (the way I script is that I try a lot of different things, read documentation (for JSL usually in this order: Scripting Index, Scripting Guide, JMP Community, JSL Syntax Reference) and try more things and fail a lot, but in the end I almost always manage to get some kind of working solution).

 

I think you can send << get xml to either analytical or report layer of jmp object. Sometimes you can even get to closer to correct reference by first subscripting and then using << get xml, but in this case I did just send it to gb. Below is other example with Big Class.jmp and after that where I placed in your script. Usually I clear log, run << get xml line, click on log and then use ctrl+f to search something (if I know what I'm looking for). If you have to explore some very large XML it might be helpful to save the xml as .xml file and open it with some application which has syntax highlighting for xml (notepad++ is usually enough).

jthi_0-1689915987590.png

 

Names Default To Here(1);

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

dt << Select Rows([1, 2]) << Hide and Exclude(1) << Clear Select;

gb = dt << Graph Builder(
	Size(528, 456),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Overlay(:sex)),
	Elements(Points(X, Y, Legend(9)), Smoother(X, Y, Legend(10)))
);

// Report(gb) << Get Xml; // works also on report
gb << Get XML; // run just this line to see xml in log or use Write() (write is the cleanest option)
// Write(gb << Get XML);
// xml_str = gb << get xml;
// show(xml_str);

where_tb = Report(gb) << XPath("//TextBox[contains(text(), 'Where(')]");
where_tb << Text Color("Blue"); // usually used to hide where text << Set Visibility("Collapse");

 

 

and here is where I would place << Get XML in your script, run it once, check the xml and then remove the line from code as there usually is no point in leaving << Get XML to ready made scripts.

jthi_1-1689916123127.png

 

-Jarmo