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?
@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);
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))))";
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):
A full list of the variables that are made available in the execution context is given here.
@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);