The display reference can be used to send messages to the display elements using the Send or << operator. For example, if out2 is a reference to an outline node, you can ask the node to close itself if it is open:
out2 << Close(); // close the outline node
Close() toggles an outline node back and forth between closed and open states, just like selecting items in the red triangle menu. You can include a Boolean argument (1 or 0) for “close or leave closed” or “open or leave open.”
rbiv["Fit Mean"] << Close; // toggle open and closed
rbiv["Fit Mean"] << Close( 1 ); // close or leave closed
rbiv["Fit Mean"] << Close( 0 ); // open or leave open
You can send messages to display boxes using the send (<<) operator. The operator makes it clear when the script is evaluating child arguments and optional arguments. It also helps make it clearer which argument is an option and which is a script to run inside the graph.
win = New Window( "Messages",
gb = Graph Box(
Frame Size( 400, 400 ),
X Scale( 0, 25 ),
Y Scale( 0, 25 )
)
);
gb << Background Color( "red" );
When you stack (or nest) messages, each message is evaluated left to right.
•
|
The following expression sends message1 to box, then message2 to box, then message3 to box. Note that any of the messages can change box before the next message is sent.
|
box << message1 << message2 << message3;
•
|
The following expression sends message1 to box and gets the result. Message2 is sent to that result, and message3 is sent to the result of message2.
|
( (box << message1) << message2) << message3
•
|
x = box << message1 << message2 << message3;
win = New Window( "Messages", gb = Graph Box() );
sz = gb << Background Color( "red" )
// message 1 sets the background color
<<Save Picture( "$DOCUMENTS/red.png", "png" )
// message 2 saves the graph box as a PNG file
<<Background Color( "white" )
// message 3 sets the graph box background color to white
<<Get Size();
// message 4 returns the graph box size and prints it to the log
The Send To Report() and Dispatch() functions provide a way for JMP to record display box modifications inside an analysis script in a self-contained way. For example, arguments within the two functions open and close outline nodes, resize graphics frames, or customize the colors in a graphics frame. You can also specify the arguments in separate JSL statements.
Send To Report() contains a list of options that change the display tree.
Dispatch() contains four arguments that change the display tree:
For example, open Big Class.jmp and run the attached Bivariate script. This generates a report with a fitted line. Open the Lack of Fit outline node, and close the Analysis of Variance outline node. Select Save Script > To Script Window. The following script appears in the script editor window:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Fit Line(),
SendToReport(
Dispatch(
{"Linear Fit"},
"Lack Of Fit",
OutlineBox,
{Close( 0 )} ),
Dispatch(
{"Linear Fit"},
"Analysis of Variance",
OutlineBox,
{Close( 1 )}
)
)
);
•
|
The fourth argument is the argument to send to this outline box. In this case, the message is Close(0), in other words, open the node.
|
The best way to deal with Send to Report() and Dispatch() is to first create a customized report interactively. Save the report as a script and then examine the script that JMP generates. Remember: the best JSL writer is JMP itself.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate( Y( weight ), X( height ) );
rbiv = biv << Report;
rbiv << Journal Window;
rbiv << Save Journal(
"$DOCUMENTS/test.jrn"
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate(
Y( weight ),
X( height ),
By( sex )
);
( ( Report( biv[1] ) << Parent ) << Parent ) <<
Save Journal( "test.jrn" );
To update a numeric column in a display box table, use the Set Values message.
win = New Window( "Numeric Column",
num = Number Col Box( "Values", [9, 10, 11] )
);
num << Set Values( [1, 2, 3] );
To add the thousands separator in a numeric column, use the Set Format message.
New Window( "Example",
ncb = Number Col Box( "Random Numbers",
{Random Uniform(), Random Uniform() * 10,
Random Uniform() * 100, Random Uniform() * 1000,
Random Uniform() * 10000}
)
);
ncb << Set Format(10,3, "Fixed Dec", "Use thousands separator");
To update a string column in a display box table, use the Set Values message.
win = New Window( "String Column",
str = String Col Box( "Values", {"a", "b", "c"} )
);
str << Set Values( {"A", "B", "C"} );
Generally, JMP automatically wraps text within Text Box(). However, the default wrap point can be overridden with a Set Wrap (n) message. The following script wraps the text at 200 pixels.
win = New Window( "Set Wrap",
tb = Text Box(
"Place your cursor over a data point for more information."
)
);
tb << Set Wrap( 200 );
You can add bullet points using the Bullet Point( 1 ) message.
win = New Window( "Bullet List",
text1 = Text Box( "Place your cursor over a data point for more information." ),
text2 = Text Box( "Circle your cursor over a statistic for more information." )
);
text1 << Bullet Point( 1 );
text2 << Bullet Point( 1 );
Sending the Bullet Point( 1 ) message to a text box places a bullet in front of the text and indents subsequent lines within that text box.
You can also send the Bullet Point( 1 ) message inline as shown in the following example:
text1 = Text Box( "Place your cursor over a data point for more information." ), << Bullet Point( 1 ) ),
You can use Select, Reshow, and Deselect to blink the selection highlight on a display box. As previously described, you can string together several << clauses to send an object several messages in a row. The results read left to right; for example, here Select is done first, then Reshow, then Deselect, then the other Reshow.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Fit Mean( )
);
rbiv = biv << Report;
// assign the bivariate analysis layer to rbiv
out2 = rbiv[Outline Box( "? Mean" )];
out2 << Close( 0 ); // open the outline box
// find outline box with the specified string in the
// rbiv report and assigns it to the out2 variable
scbx = rbiv[String Col Box( 1 )];
// find the first string col box in rbiv and
// assign the scbx variable
Wait( .25 ); // wait .25 seconds
For( i = 0, i < 20, i++,
// set i to 0, iterate through the loop 20 times
scbx << Select << Reshow << Deselect << Reshow
// select the string col box and reshow it,
// deselect it and reshow it
);
Headings are shaded and have column borders by default. To turn them off, use the Set Shade Headings ( 0 ) message and the Set Heading Column Borders ( 0 ) message. The following example shows the effect of turning shading and borders off:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Summarize(
meanHt = Mean( Height ),
minHt = Min( Height ),
maxHt = Max( Height )
);
win = New Window( "Summary Results",
tb = Table Box(
Number Col Box( "Mean", meanHt ),
Number Col Box( "Min", minHt ),
Number Col Box( "Max", maxHt )
)
);
Wait( 2 );
tb << Set Shade Headings( 0 );
Wait( 1 );
tb << Set Heading Column Borders( 0 );
Wait( 2 );
tb << Set Shade Headings( 1 );
Wait( 1 );