Adding Some Class To Your Journal Scripts

keyboard_custom_enter_11473Often we only need trivial amounts ofJSL to perform a particular task.

We don’t even need to write it – JMP automatically generates the code for us.

But that is not to say we shouldn’t think about adding a little polish!

Imagine this scenario:

I have a table open, I have created some output that I particularly like, and so I save a script to a journal.

The script might look something like this:

Open("C:\Data\Big Class.jmp") << Bivariate(Y(:weight), X(:height), Fit Line({Line Color({213, 72, 87})}))

Hidden amongst all that text is a simple structure of code:

Open(  file-path ) << Bivariate( output-options )

File paths can cause us problems when we move our scripts from one location to another – suchas when we put it on a laptop for a talk at a  conference!  So at a minimum it’s useful to clearly identify parts of code that contain filepaths and ideally you want to use relative path names:

filePath = "Big Class.jmp";
dt = Open( filePath );
dt << Bivariate(
    Y(:weight), X(:height), 
    Fit Line({Line Color({213, 72, 87})})
);

In the above example the script will work so long as the data table is in the same folder as the journal file.

When we click on the journal link two things happen:

  • the table will open (unless it is already open)
  • data from the table is used to create a bivariate plot

If you are using the journal to present to an audience then it may be that they only want to see the graphical representation of the data – in which case the data table becomes a distraction (and for some reason, whenever I have an audience the table opens in front of the graph!)

A simple piece of JSL magic helps solve the problem.  When we open a JMP table it is possible to specify that is it invisible:

dt = Open( filePath, Invisible );

Now when the table opens, you wont see it on your screen but your script still has access to the data – your will see your graph and only your graph.  If you subsequently need access to the data table then take a look at your window list as you will see the table listed (but grey-out to indicate that it is invisible).

winlist

If you want to view the table – that’s easy, just double-click on the table name.

One problem with invisible tables is that we can forget that they are there.  Chances are when we close that bivariate graph we no longer need the table.  It would be really great if we could keep on top of this type of “housekeeping” and automatic close things when they are no longer required.  The good news is that we can – we just need to look out for an event that tells us when the data is no longer required.  That event occurs when the graph window is closed.  It is an event that we can detect and respond to.

Here is the general structure of the code to handle this situation:

filePath = "Big Class.jmp";
dt = Open( filePath );
biv = dt << Bivariate(
    Y(:weight), X(:height), 
    Fit Line({Line Color({213, 72, 87})})
);
biv << On Close(
    Close( Data Table("Big Class",NoSave) ) 
);

Now we’re starting to turn our journal presentation into a class act!

4 thoughts on “Adding Some Class To Your Journal Scripts”

  1. Hi David, simple question on Journal JSL code.
    I am trying to build a report of bunch of graphs that I use every day. I am able to write the the script to create these graphs, but for the life of me, I cannot figure how to add these graph to a Journal using JSL script, any hints?
    Thanks
    Ray

    1. Hi Ray. Sorry I missed your comment. To be honest I’ve rarely had a need to script journals, but I’ll take a look at putting together a post because I know a lot of people like to use JSL to generate journal content.

Leave a Reply

Your email address will not be published. Required fields are marked *