Choose Language Hide Translation Bar
Highlighted
nikles
Level IV

Get variable names from graphbuilder

Hi.  Is there a method to get the variable names & roles used in a graph builder window?  Suppose I have a window containing a graph builder plot.  Is there a way to programmatically determine which variable was used for X, Y, Xgroup, Ygroup, etc?

 

For example, suppose the user created a plot in gb.  Now they wish to run some generalized script on the plot (e.g. a graphics script).  The script needs to know what variables were used in which roles without the user telling it.

 

Suppose I start with this plot:

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

 

Now I wish to run a script on the resulting plot.  My script is unaware of what is contained in the plot.  Here are 2 things I tried but did not work:

Names Default to Here(1);

//Try to get script used to create plot
win = Window(1);  			//gets most recent window clicked on
gb = win << Report;               //DNW: returns missing (win is not a platform)
scr = gb << Get Script;  //from here I could parse the string to determine the roles

//Another stab: try to read the XML
win = Window(1);
str = win << Get XML;  //This gives me the XML of the window, but does not provide the actual variable names used in the roles.

 

If I could figure out how to convert the window reference into a report, I think I could get that first method to work.  Any ideas?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Get variable names from graphbuilder

@nikles you are correct, the hover label functionality is based on interactivity. There are ways to trigger that using JSL (by moving the mouse, pausing, etc.) but that would add a lot of complexity to the solution that you really don't need.

Based on your reply to and the solution proposed by @txnelson, here is a script that will take you from the windows reference all the way down to the Graph Builder variable references. 

Names Default to Here(1);
win = New Window("A Title",    // Let's create a Window that contains a Graph Builder
Graph Builder(                 // with a LDF to make things interesting (multiple OutlineBoxes).
	Size( 517, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :height ) ),
	Elements( Bar( X, Y, Legend( 6 ) ) ),
	Local Data Filter(
		Add Filter( columns( :height ), Where( :height >= 60.048 & :height <= 70 ) )
	)
));
ob = win[OutlineBox("Graph Builder")]; // This is how you get the Display Box that contains the GB object
gbb = ob << Get Scriptable Object;     // Now we extract the GB object from the Display Box
gb_expr = gbb << Get Script;           // You could wrap in Char() to get the GB script as a string
gb_nargs = NArg(gb_expr);              // and use pattern matching. Instead, 
for(i = 1, i <= gb_nargs, i++,         // let's see how to inspect it as an expression.
	child = Arg(gb_expr, i);
	If (HeadName(child) == "Variables",
		var_nargs = NArg(child);
		for(j = 1, j <= var_nargs, j++,
			Show(Arg(child, j))
		);
		Break();
	)
);

you should see:

Arg(child, j) = X(:sex);
Arg(child, j) = Y(:height);

View solution in original post

6 REPLIES 6
Highlighted
txnelson
Super User

Re: Get variable names from graphbuilder

I thought that I remembered a previous question about this, but I searched and did not find one.  Regardless, the method that I have used to do this kind of thing, is to send a Message to Graph Builder to retrieve the script used to create the display, into a character variable, and then I parse through the string to find the variables mentioned.

The script

names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");
gb = Graph Builder(
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 6 ) ), Smoother( X, Y, Legend( 7 ) ) )
);

theScript = char(gb << get script);
show(theScript);

retrieves:

theScript = "Graph Builder(Variables(X(:weight), Y(:height)), Elements(Points(X, Y, Legend(6)), Smoother(X, Y, Legend(7))))";
Jim
Highlighted
nikles
Level IV

Re: Get variable names from graphbuilder

Hi Jim. Thanks for your reply. Unfortunately the problem I have is that my script will not have any knowledge of the "gb" ref in your example. The only thing my script would be able to reference is the window and the subsequent display boxes. If I could somehow get the reference to gb however, then yes, your method is precisely the way I'd prefer to go.
Highlighted

Re: Get variable names from graphbuilder

The Hover Label Extensions added in JMP 15 allow you to define a script that will be executed in the context of a graph (a Hover Label Execution Context to be precise). This context provides information in local variables about the visual element that is being hovered over, including which variables are being used as "groupings" (X, GroupX, GroupY, etc), and measurements (Y, Color, Size, etc).

You can access these variables in your own script, and perhaps use them to define a new visualization or analysis. This is precisely how the Hover Label Presets work. You might want to select one and then take a look at the generated JSL code in the Hover Label Editor (or by saving the script) to see an example.

 

 

You can also see their values by using the Textlet "context" preset (available from the Textlet panel on the Hover Label Editor):

hlec_context.PNG

 

A full list of the variables that are made available in the execution context is given here.

Highlighted
nikles
Level IV

Re: Get variable names from graphbuilder

Thanks nascif_jmp. I'm actually still on JMP14, so I'm not yet familiar with Hover Label Extensions. I can switch to 15, but old habits...

Quick question though...I'm looking for some method to programmatically read the variables from a window containing a graphbuilder plot. However, from its name it sounds like the Hover tool would require the user to interact with the window by hovering over various items. Is there a way to have this done automatically by a script? And can it be done if all I have is a reference to the window in which the gb plot exists (not a reference to the gb itself)?

Re: Get variable names from graphbuilder

@nikles you are correct, the hover label functionality is based on interactivity. There are ways to trigger that using JSL (by moving the mouse, pausing, etc.) but that would add a lot of complexity to the solution that you really don't need.

Based on your reply to and the solution proposed by @txnelson, here is a script that will take you from the windows reference all the way down to the Graph Builder variable references. 

Names Default to Here(1);
win = New Window("A Title",    // Let's create a Window that contains a Graph Builder
Graph Builder(                 // with a LDF to make things interesting (multiple OutlineBoxes).
	Size( 517, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :height ) ),
	Elements( Bar( X, Y, Legend( 6 ) ) ),
	Local Data Filter(
		Add Filter( columns( :height ), Where( :height >= 60.048 & :height <= 70 ) )
	)
));
ob = win[OutlineBox("Graph Builder")]; // This is how you get the Display Box that contains the GB object
gbb = ob << Get Scriptable Object;     // Now we extract the GB object from the Display Box
gb_expr = gbb << Get Script;           // You could wrap in Char() to get the GB script as a string
gb_nargs = NArg(gb_expr);              // and use pattern matching. Instead, 
for(i = 1, i <= gb_nargs, i++,         // let's see how to inspect it as an expression.
	child = Arg(gb_expr, i);
	If (HeadName(child) == "Variables",
		var_nargs = NArg(child);
		for(j = 1, j <= var_nargs, j++,
			Show(Arg(child, j))
		);
		Break();
	)
);

you should see:

Arg(child, j) = X(:sex);
Arg(child, j) = Y(:height);

View solution in original post

Highlighted
nikles
Level IV

Re: Get variable names from graphbuilder

Thanks. That was exactly what I needed.
Article Labels