Subscribe Bookmark RSS Feed

Break up a Journal into individual graphs?

matt_p

Community Trekker

Joined:

May 25, 2012

I am looking to break a journal up into the individual graphs that make up the journal.

The idea is that I am prompting a user to save graphs, and I would like to be able to save individual graphs from within a journal, rather than the journal as a whole.

Any help is greatly appreciated.

-Matt

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Each graph is wrapped in something called a PictureBox, which is how the HTML export knows when to make an image file. You can cycle through the PictureBoxes with display box subscripting, or use XPath:

jrn = Current Journal();

graphs = jrn << xpath( "//PictureBox" );

n = N Items( graphs );

For( i = 1, i <= n, i++,

  graphs << Save Picture( "$DOCUMENTS/pic" || Char( i ) || ".png", "png" )

);

6 REPLIES
Solution

Each graph is wrapped in something called a PictureBox, which is how the HTML export knows when to make an image file. You can cycle through the PictureBoxes with display box subscripting, or use XPath:

jrn = Current Journal();

graphs = jrn << xpath( "//PictureBox" );

n = N Items( graphs );

For( i = 1, i <= n, i++,

  graphs << Save Picture( "$DOCUMENTS/pic" || Char( i ) || ".png", "png" )

);

matt_p

Community Trekker

Joined:

May 25, 2012

That worked great Xan, thank you very much.

The next hurdle I need to get over is grabbing the title for each graph in the journal. Each graph is wrapped in an outline box, with its title in that. Is there anyway I could call the parent to the PictureBox and grab the text from it?

Thanks again,

Matt

XanGregg

Staff

Joined:

Jun 23, 2011

There is a <<parent message, but you may have to apply it several times to get to the OutlineBox if there are intervening boxes like ListBox or BorderBox. You can use <<classname to see what type of box you're at.

Doing the same with xpath gets a little trickier, but this works in the loop:

  print((jrn << xpath(EvalInsert("descendant::PictureBox[^i^]/ancestor::OutlineBox[1]")))[1] << get title)

matt_p

Community Trekker

Joined:

May 25, 2012

Great work again Xan, worked like a charm.

The timely response was extremely helpful as well.

matt_p

Community Trekker

Joined:

May 25, 2012

I have one more question Xan. I am not too familiar with the ancestor/descendant part of the trees.

I now have the user selecting a graph name from the list that was created using

print((jrn << xpath(EvalInsert("descendant::PictureBox[^i^]/ancestor::OutlineBox[1]")))[1] << get title)


From the title they choose, I would like to find the corresponding picture box and save that to a file, instead of all of the picture boxes.

I was thinking of replacing ancestor::OutlineBox[1] with the title of the graph, and the descendant would be PictureBox[1], correct? From that would I be able to save the picture?


Once again, any help is greatly appreciated.


-Matt

XanGregg

Staff

Joined:

Jun 23, 2011

One approach would be to collect two lists: one of picture boxes and one of titles. Then, if they select the nth title, then output the nth picture box. To get the nth picture box on demand, I think xpath //PictureBox would do it.Or use the regular Display Box subscripting: jrn[PictureBox(n)].