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
shampton82
Level VII

Get the title from a Graph Builder Panel

I could use some help on why I can't get the title of the 1st panel in this Graph builder

shampton82_0-1732311827428.png

 

with this code

report=current report();
test=(report<< XPath("(//OutlineBox[text()='Graph Builder']//GraphBuilderGroupBox)[2]"))<<get title;

Thanks for any suggestions!

Steve

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Get the title from a Graph Builder Panel

If you check the XML for single GraphBuilderGroupBox you can see that you are looking for the value from XML

 

"<GraphBuilderGroupBox width=\!"570\!" height=\!"24\!" selected=\!"true\!">age = 12</GraphBuilderGroupBox>"

And you can get that value using XPath

 

 

gbb_texts = (Report(gb) << XPath("(//GraphBuilderGroupBox/text())"));
// {"age = 12", "age = 13", "age = 14", "age = 15", "age = 16", "age = 17"}  

And if you just want to get the first one, you can limit the index already in XPath (like you have done) and then take first index from that as << XPath will return a list (I would most likely skip XPath index in this case, as you still have to use JMP's index)

gbb_text = (Report(gb) << XPath("((//GraphBuilderGroupBox/text()))[1]"))[1];
// or gbb_text = (Report(gb) << XPath("(//GraphBuilderGroupBox)[1]/text()"))[1];

with just JMP index

gbb_text= (Report(gb) << XPath("//GraphBuilderGroupBox/text()"))[1];
Names Default To Here(1); 

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

gb = dt << Graph Builder(
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Page(:age), Overlay(:sex)),
	Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
);

group_texts = (Report(gb) << XPath("//GraphBuilderGroupBox/text()"));
// {"age = 12", "age = 13", "age = 14", "age = 15", "age = 16", "age = 17"}

 

-Jarmo

View solution in original post

3 REPLIES 3
hogi
Level XII

Re: Get the title from a Graph Builder Panel

Ah, interesting. I never noticed - or cared:
With some Xpath Parsers, one already gets the content of the node
https://www.w3schools.com/xml/xpath_examples.asp  
http://xpather.com/

E.g. after pasting the result of 

xml= current report() << Get XML;

into http://xpather.com/ and searching for 

(//OutlineBox[text()='Graph Builder']//GraphBuilderGroupBox)[2]

one gets: "age = 13"

hogi_0-1732472523457.png

 

 

JMP and others 
https://www.freeformatter.com/xpath-tester.html 

https://magictool.ai/tool/xpath-tester/de/ 
http://xpather.com/ (setting: node)
return the surrounding "object".

So, one has to retrieve the content of the node in a separate step ... 

I guess there is an easier way than this one ...
Till somebody posts it, you can use 

report=current report();
test=(report<< XPath("(//OutlineBox[text()='Graph Builder']//GraphBuilderGroupBox)[2]"))[1];
xml= test << Get XML;
Regex (xml, ">(.*?)<\/GraphBuilderGroupBox>", "\1")


by the way - thank you for the trick: 
direct indexing via [2] is possible in XPath - cool, thanks!!!

hogi_1-1732473096200.png

 

jthi
Super User

Re: Get the title from a Graph Builder Panel

If you check the XML for single GraphBuilderGroupBox you can see that you are looking for the value from XML

 

"<GraphBuilderGroupBox width=\!"570\!" height=\!"24\!" selected=\!"true\!">age = 12</GraphBuilderGroupBox>"

And you can get that value using XPath

 

 

gbb_texts = (Report(gb) << XPath("(//GraphBuilderGroupBox/text())"));
// {"age = 12", "age = 13", "age = 14", "age = 15", "age = 16", "age = 17"}  

And if you just want to get the first one, you can limit the index already in XPath (like you have done) and then take first index from that as << XPath will return a list (I would most likely skip XPath index in this case, as you still have to use JMP's index)

gbb_text = (Report(gb) << XPath("((//GraphBuilderGroupBox/text()))[1]"))[1];
// or gbb_text = (Report(gb) << XPath("(//GraphBuilderGroupBox)[1]/text()"))[1];

with just JMP index

gbb_text= (Report(gb) << XPath("//GraphBuilderGroupBox/text()"))[1];
Names Default To Here(1); 

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

gb = dt << Graph Builder(
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Page(:age), Overlay(:sex)),
	Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
);

group_texts = (Report(gb) << XPath("//GraphBuilderGroupBox/text()"));
// {"age = 12", "age = 13", "age = 14", "age = 15", "age = 16", "age = 17"}

 

-Jarmo
shampton82
Level VII

Re: Get the title from a Graph Builder Panel

Woot woot!

 

Thanks @hogi and @jthi !  As usual, fast and amazing help.

 

The reason for the ask was that I need to have different axis settings for different panels but since the # of panels change the hard coding of the axis range from the saved script Graph Builder makes (e.g. Scalebox(2)) causes the charts to be all messed up on later times when I run it. So I can now use this code to loop through the panels, check what is there, and then set the axis min and max correctly.  Still a lot of painful coding to do but at least now I have a path!

 

Steve