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
BHarris
Level VI

How to script frame size for existing Graph Builder window

Is there a way to set the frame size for an existing Graph Builder window with JSL?

 

E.g., suppose I have a Graph Builder window open, and I would like to run a JSL file that will set the overall frame size of the graph in that window to 800x600.  Is that possible without having the reference to the GB object in the JSL script?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to script frame size for existing Graph Builder window

Just guessing here... Fit to Window must be sent to Graph Builder not to frame box (<< Get Scriptable Object might help here). If Wrap is used (or Group X), maybe you will have to calculate the size based on how many groups there are. Or you could maybe manipulate the size of graph builder window?

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))
);

wait(0);

win = Get Window List();

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

last_gb = graphs[N Items(graphs)][OutlineBox("Graph Builder")] << Get Scriptable Object;
last_gb << Fit to Window("On");

last_gb << Size(800,600); // instead of manipulating framebox

//frame = Report(last_gb)[FrameBox(1)];
//frame << Frame Size(800, 600);

XPath isn't JMP thing XPath - Wikipedia, but it is easy way to access different objects in reports. Using << Get XML helps you seeing what you are XPathing

Report(gb) << Get Xml;

 

-Jarmo

View solution in original post

7 REPLIES 7
jthi
Super User

Re: How to script frame size for existing Graph Builder window

Easiest would be if you can get the reference to the Graph Builder. You can for example use << Get Scriptable Object after you have the reference to the outline box

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
nw = New Window("",
	Graph Builder(
		Variables(X(:height), Y(:weight)),
		Elements(Points(X, Y), Smoother(X, Y))
	);	
);

gb = (nw[OutlineBox("Graph Builder")] << Get Scriptable Object);
fb = Report(gb)[FrameBox(1)];
fb << Frame Size(800,200);

Or in some cases you might be able to find framebox directly from window

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
nw = New Window("",
	Graph Builder(
		Variables(X(:height), Y(:weight)),
		Elements(Points(X, Y), Smoother(X, Y))
	);	
);

nw[FrameBox(1)] << Frame Size(800,200);

And finally XPath

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
nw = New Window("",
	Graph Builder(
		Variables(X(:height), Y(:weight)),
		Elements(Points(X, Y), Smoother(X, Y))
	);	
);

(nw << XPath("//FrameBox")) << Frame Size(800,200);

You can get reference to the window using Current Window(), but it is a bit annoying to use from script window and works much better from toolbar/shortcut/add-in.

-Jarmo

Re: How to script frame size for existing Graph Builder window

Here is an alternative approach. You can get a list of all the current windows. They are ordered by appearance, so if you just opened Graph Builder, it will be the last item. Otherwise, you can inspect the list of windows to find the GB you want.

Names Default to Here( 1 );

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

obj = dt << Graph Builder(
	Size( 534, 456 ),
	Show Control Panel( 0 ),
	Show Legend( 0 ),
	Variables( X( :height ), Y( :weight ) ),
	Elements( Points( X, Y, Legend( 3 ) ) )
);

win = Get Window List();
frame = (win[N Items(win)] << XPath( "//FrameBox" ))[1];
frame << Select << Frame Size( 800, 600 );

Your script could be add as a menu or toolbar item, or made into an add-in. 

BHarris
Level VI

Re: How to script frame size for existing Graph Builder window

I like this answer, but it errors out when I take out the "dt =..." and "obj = ..." lines and put "//!" at the top and double-click it.  Here's the error:  

 

Subscript Range in access or evaluation of '(win[N Items(win)] << XPath("//FrameBox"))[ /*###*/1]' , (win[N Items( win )] << XPath( "//FrameBox" ))[/*###*/1]
ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to script frame size for existing Graph Builder window

For @Mark_Bailey 's script to work as-written the graph box would have to be the last window open, I am guessing when launching it from a separate script that is no longer the case.  You could modify it like this to only pick graph builder windows, you would want check that at least one window is open.

Names Default to Here( 1 );

//Find graph builder windows
graphs = filter each({w}, win, 
	if(
		length(w << XPath("//OwnerBox[@helpKey='Graph Builder']")) > 0 ,
		1,
		0
	)
);

//Choose the last one
frame = (graphs[N Items(graphs)] << XPath( "//FrameBox" ))[1];

//Modify the frame
frame << Select << Frame Size( 800, 600 );

Note that I do something similar to this when looking for 3d plot windows in this add-in: 3D Plot Tools , and there I let the user choose which windows(s) to modify. The code is on GitHub

BHarris
Level VI

Re: How to script frame size for existing Graph Builder window

Awesome. 

 

Note, that if "Fit to Window" is not "off", those Frame Sizes don't always work.  I've tried for 30 minutes to adapt this code to also modify the "Fit to Window" setting without luck.  Any ideas how to do that?

 

And, curiously, if the Graph Builder window has multiple plots, e.g. with a variable in the Wrap field, the Frame Size modifies the individual plot frames instead of the entire plot area.  Is it possible to resize the entire plot area to a given size instead of the individual plots?

 

Lastly, where did you learn to code like this?  As a 10-year python coder (and 20-year perl coder), I'll say that JSL is pretty hard to understand.  Even after reading the Scripting Index on those items (XPath, Select...) I'm still not sure what they mean here...

 

Thanks!

jthi
Super User

Re: How to script frame size for existing Graph Builder window

Just guessing here... Fit to Window must be sent to Graph Builder not to frame box (<< Get Scriptable Object might help here). If Wrap is used (or Group X), maybe you will have to calculate the size based on how many groups there are. Or you could maybe manipulate the size of graph builder window?

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))
);

wait(0);

win = Get Window List();

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

last_gb = graphs[N Items(graphs)][OutlineBox("Graph Builder")] << Get Scriptable Object;
last_gb << Fit to Window("On");

last_gb << Size(800,600); // instead of manipulating framebox

//frame = Report(last_gb)[FrameBox(1)];
//frame << Frame Size(800, 600);

XPath isn't JMP thing XPath - Wikipedia, but it is easy way to access different objects in reports. Using << Get XML helps you seeing what you are XPathing

Report(gb) << Get Xml;

 

-Jarmo
BHarris
Level VI

Re: How to script frame size for existing Graph Builder window

That did it!  Thanks, Jarmo, and to everyone who responded!!