Script I used
Few questions from Teams chat
Question1:
is there an Xpath command which corresponds to
Dispatch( {}, "X title", TextEditBox,
Answer1:
Easiest way to check is to use << Get XML and check if you can find "X title" from there. You can't (those "display elements" could be same as helpKey attribute but they just haven't been added to everything).
But you can build complicated XPath to get the axis text edit boxes (I think first is always X-axis).
GraphBuilderAxisBox <GraphBuilderComponentBox leftOffset="47" topOffset="435" width="478" height="19">
<GraphBuilderTitleBox width="478" height="19">
<TextEditBox leftOffset="223" topOffset="0" width="31" height="19">My X</TextEditBox>
</GraphBuilderTitleBox>
</GraphBuilderComponentBox>
<GraphBuilderComponentBox leftOffset="47" topOffset="408" width="478" height="27">
<GraphBuilderAxisBox width="478" height="27">
<AxisBox width="478" height="27" charID="1000"/>
</GraphBuilderAxisBox>
</GraphBuilderComponentBox>
You can base your XPath on finding GraphBuilderComponentBox + GraphBuilderAxisBox and preceding GraphBuilderComponentBox + GraphBuilderTitleBox
//GraphBuilderComponentBox[GraphBuilderAxisBox]/preceding-sibling::GraphBuilderComponentBox[1]/GraphBuilderTitleBox/TextEditBox
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(525, 454),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(3))),
SendToReport(
Dispatch({}, "X title", TextEditBox, {Set Text("My X")}),
Dispatch({}, "Y title", TextEditBox, {Set Text("My Y")})
)
);
nw = New Window("gbscript", << type("Script"), << Language("XML"),
Report(gb) << Get XML;
);
axis_title_tebs = Report(gb) << XPath("//GraphBuilderComponentBox[GraphBuilderAxisBox]/preceding-sibling::GraphBuilderComponentBox[1]/GraphBuilderTitleBox/TextEditBox");
axis_title_tebs[1] << Set Text("XXXXX");
axis_title_tebs[2] << Set Text("YYYYY");
Write();
Question 2:
This question is more related to Graph Builder though, not directly related to Scripts. Could you please show how to highlight or identify a sample in the Graph? And how to add a label to only one of the samples, and additionally to some specific samples.
Answer 2:
Different types of data (and JMP versions) can require different types of labeling techniques. In worst case you might have to script it but usually this isn't necessary.
I will go with the assumption of JMP18 and simple data. I have graph like this and I wish to label and color the highlighted point
Just by labeling that row and adding color row state it will get highlighted like this
This add-in was also mentioned Column Quick Swapper - easily change multiple Y and X-axis columns in Graph Builder
Thanks for the answers.
I wonder why there is nothing like:
current report() << XPath("//TextEditBox[@type='X title']")
real application case:
get the bottom Y axis title in a graph with 2 x axis labels and 2 y axis labels
Dispatch( {}, "Y 1 title", TextEditBox,
is wonderful compared to guessing the right entry in this list:
axis_title_tebs = Report(gb) << XPath("//GraphBuilderComponentBox[GraphBuilderAxisBox]/preceding-sibling::GraphBuilderComponentBox[1]/GraphBuilderTitleBox/TextEditBox");
You can still make it fairly robust
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(528, 448),
Show Control Panel(0),
Variables(X(:sex), X(:age), Y(:weight), Y(:height), Overlay(:sex)),
Elements(Position(1, 1), Points(X, Y, Legend(24))),
Elements(Position(1, 2), Points(X, Y, Legend(25))),
Elements(Position(2, 1), Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11))),
Elements(
Position(2, 2),
Points(X, Y, Legend(16)),
Line Of Fit(X, Y, Legend(17))
)
);
axis_title_tebs = Report(gb) << XPath("//GraphBuilderComponentBox[GraphBuilderAxisBox]/preceding-sibling::GraphBuilderComponentBox[1]/GraphBuilderTitleBox/TextEditBox");
xcount = gb << Get N Positions("X");
firstyaxis = axis_title_tebs[xcount + 1];
Show(firstyaxis << get text);
Write();
Too bad that is "Y 1 title" and not "Y title" (or maybe it should always be "Y 1 title" and we shouldn't even have just "Y title") so it will be different if you have one or multiple y-axis.
Hm ...
it's always fun to get this bonus analysis challenge "for free"
- besides the analysis you are "paid for"
Few links from Scripting Guide (not necessarily directly related to JSL for graph builder)
Since JMP18 the By variables do work a bit differently and there are new options. If you feel like you are using By variables a lot, I suggest you check out Group Platform from scripting index. It for example contains "Group Platform" which might be helpful from time to time as you can control which reference you get (highest level or all platforms in a list)
There are somewhat similar considerations with Where Filter by Value Using a Where Statement (jmp.com). One such consideration might be which data table they are utilizing or which where expression
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
gbs = dt << Graph Builder(
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11))),
By(:sex)
);
gb = dt << Graph Builder(
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11))),
Where(:sex == "F");
);
show(gbs << Get Data Table);
show(gb << Get Data Table);
show(gbs << Get Where Expr);
show(gb << Get Where Expr);
private_tables = Find All(Data Tables, Private);
Show(private_tables << get name);
Show(private_tables << Is Linked Subset);
gbs << Get Data Table = {DataTable("sex=F"), DataTable("sex=M")};
gb << Get Data Table = DataTable("Big Class, where -sex == -F- 3");
gbs << Get Where Expr = {:sex == "F", :sex == "M"};
gb << Get Where Expr = :sex == "F";
private_tables << get name = {"sex=F", "sex=M", "Big Class, where -sex == -F-", "Big Class, where -sex == -F- 2", "Big Class, where -sex == -F- 3"};
private_tables << Is Linked Subset = {1, 1, 1, 1, 1};