Tag: JMP & JSL

Marker State()s and states of confusion

by on May.12, 2010 , under JMP & JSL

When I wrote the first JMP Scripting Guide, way back in the dark old days of JMP 4, easily the most difficult chapter to write was the one about data tables, and the most difficult section of that chapter was the one about Row States. I must have spent the better part of a month trying to figure out all the relevant concepts. Not only was JSL still in its gestational period, but I was new to JMP entirely, so I wasn’t just confused about how to work with row states in JSL. I was confused about row states, period.

Slowly I untangled it all, but I had to keep referring to two cheat sheets I’d built for myself, so I decided they’d probably better become a part of the book. These live on in current editions of the JMP Scripting Guide as Table 5.3, “Row states and how they affect JMP’s analyses, charts, and plots,” and Table 5.4, “Operators for converting between numbers and row states.” Then I had to struggle some more to figure out how to use the operators, and on and on. By the time I was done, I still had only a tenuous grip on how to get anything done with row states, but at least I’d gotten to the point where I knew which of my pages to reread and could usually adapt one of my own examples after a few minutes of squinting and swearing.

Fast forward about a dozen years, and I’m programming in JSL full-time for a variety of clients—cool projects for big companies you’ve heard of—but I still cringe when I have to use row state operators. Unless I can refer to another recent project and steal code from myself, I know that I’ve got a good half hour in that darned book and its ridiculously confusing section on row states. I should point out that I haven’t been involved in that book since version 4—since then, it’s been updated by Lee Creighton, Ph.D. (version 5) and Melanie Drake (since version 6). Honestly, I’m not sure whether the section on row states has changed at all, so the fact that I still hate that section and how hard it is for me to read and understand could still be entirely my own fault. I hate that!

In version 8 markers and several other row state operators got a lot more complicated, because JMP 8 introduced marker themes and unicode markers, among several other improvements by the talented developer Xan Gregg, the guy who brought us Graph Builder. The new features are great, but the already confusing row state operators got even more confusing.

So, when Glenn Donahey at W.L. Gore & Associates posed a question about markers on the LinkedIn group “JMP Professional Network,” I thought, “Great! I’ll answer his question and refresh my own memory while I’m at it. Here’s his question:

Simple JSL question – assigning custom markers. This is a simple question, but I can’t seem to find the answer. Starting with a populated data table, one can right click on the row, choose Markers >> Custom… and assign a marker such as “D”. What is the analagous command in JSL?

Unfortunately, my first few attempts to bang out the command he needed didn’t work, and then I got busy with something else. Monday morning I made another attempt at it but once again got myself confused, and then the ever-helpful Mark Bailey, Ph.D., popped in with some answers. Meanwhile, I banged my head against some of the less-documented details of the Marker State() operator, and here’s what I figured out.

Either I’m dumber than the average bear…

This could be the problem. It really could.

…or row state operators are really confusing!

You know what, they are. Regardless of the first part—whether I’m some special kind of stupid or not—row state operators are confusing. And now here are the things I learned (again!) that might be helpful to everyone else!

To set one row’s state at a time, use a pinch of Whatever State( rowNumber )

For example, to set row 1 to pink, which is for no particular reason color #11:

Row State( 1 ) = Color State( 11 );

Or to set row 1 to an inverted solid triangle, which is for no particular reason marker #21:

Row State( 1 ) = Marker State( 21 );

To use Unicode characters as markers, prepare to sweat

Up until JMP 8, there were a few dozen markers known mysteriously as 1 through 31. These are pictured at right and ought to be familiar to veteran JMP users. JMP 8 introduced a way to exploit a whole mess of Unicode characters as markers—not the entire Unicode character set, unfortunately, but the first 19,560 of them—by using 16-bit numbers as arguments. You have three choices for how to give the argument:

  1. As an integer from 33 to 19,560, inclusive
  2. As a hex number in a string, inside a Hex to Number() operator
  3. As a hex number in a four-digit string escaped with \!u

That makes perfect sense, right? No, me either. Let’s go through these one at a time.

1. Integers

Integers are the easy part. We’ve already seen that 1-31 give JMP’s good old-fashioned marker symbols as seen at right. Number 32 is empty. Not coincidentally, the first 32 positions of the Unicode character set are all empty; JMP’s standard markers fill that gap, and #32 is just empty. After that, you start getting Unicode characters by their positions given in any Unicode character table.

Note: be sure to set your Marker Font() preference to a unicode font:

// set the Marker Font to be Arial Unicode MS, Lucida Grande,
// or another font containing an extensive set of Unicode characters
If( Host is( Windows ),
  Preferences( Fonts( English( Marker Font( "Arial Unicode MS", 10 ) ) ) ),
  Preferences( Fonts( English( Marker Font( "Lucida Grande", 10 ) ) ) )
);

Whoa! What are the Unicode characters, anyway?

Windows users have a decent tool for browsing Unicode. Go to Start / Programs / Accessories / System Tools / Character Map. For Font, choose a unicode font such as Arial Unicode MS. To get details for a specific character, click it and look in the lower part of the window:

The Advanced view is marginally more helpful. Searching online for “Unicode character map” yields plenty of useful options.

Mac users have a great built-in tool for browsing Unicode: in System Preferences, choose Language & Text, click the Input Sources panel, and check the Keyboard & Character Viewer from the list of input methods, and check the “Show Input menu in menu bar.” Here’s how that looks in OS 10.6 (Snow Leopard): Now you have an input menu in the upper right corner of the menu bar. From this menu, choose Show Character Viewer, and you get this handy browser of the entire Unicode character set. (The characters shown are limited to those available in fonts installed on your machine. Mac OS X’s best font for this kind of thing is Lucida Grande.)

So, once you find a symbol you like, these tools tell you which character is, but they tell you in hexadecimal notation, e.g. the FOR ALL character above is in position 2200 hexadecimal (base 16). Now, just figure out what that is in decimal (base ten) and you’re all set! To do that, you can either grab your favorite programmer’s calculator, or you can use JMP’s own conversion operator to learn that it’s 8704:

show(hex to number("2200"));
Hex To Number("2200"):8704

Armed with this knowledge, you can set FOR ALL as the marker symbol for row 5 this way:

Row State( 5 ) = Marker State( 8704 );

2. Hex numbers

But it’s kind of silly to work that hard at it. If you’re using Unicode character tables to find symbols, they’re telling you hex numbers, and you might as well just let JMP do the work:

Row State( 5 ) = Marker State( hex to number("2200" );

3. Escaped numbers

This too is making it too hard, though. Why not just use the common \u-escaped notation, e.g. \u2200 to mean “Unicode character in position hex 2200”? In this case, our argument needs to be a string, and the usual \u escape needs to be escaped with both a backslash and a bang, like most other special characters for JSL. So what in the rest of the world is “\u2200” becomes “\!u2200” for JSL, for a command like this:

Row State( 5 ) = Marker State ( "\!u2200" );

This isn’t too bad, but if you want to store a bunch of these in a character data table column, you need to do more escaping to get them to play nicely with JSL.

New Column( "unicode",
  Character, Nominal,
  Formula( "\!"\!\\!!u" || Substr( Hex( Row(), "integer" ), 5, 4 ) || "\!"" )
);

What a mess! Let’s break it down. In the middle we ask for row numbers to be converted from integers to hex, but we only take the last four digits by using Substr().

Around the whole string, we need quotation marks, but we can’t just use them directly—the character column gets string values, which are quoted strings by definition, and those surrounding quotes are thrown away when we read the values out of the column. So we need escaped quotation marks, \!”, before and after. So far we’ve got, for example on row 8704, ” \!”2200\!” “. But we also need \!u before the number, which is two more special characters that need escaping in JSL: backslash (\) and bang (!). To get the backslash, we need to use \!\, and to get the bang, we need \!!. The u is the easy part. So add \!\ and \!! and u before the 2200, and you’ve got ” \!”\!\\!!u2200\!” ”

But it gets worse! Now if you want to ask for markers from those values, you have to parse all that to get it back to “\!u2200”!

I know: “Yikes!”

To put it all together into a useful script, let’s create a data table, give it the 19560 rows we’ll need to see all the supported Unicode characters, and then set marker states For Each Row(). We’ll add a While() in the middle to make sure the data table finishes getting built before JMP tries to run the For Each Row(); if we don’t, we’ll get an error about arguments.

// a data table to see the entire set of standard markers
// and Unicode characters available for markers
New Table( "unicode characters",
  add rows( 19561 ),
  New Property( "plot my markers",
    Overlay Plot(
      X( :X ),
      Y( :Y ),
      Separate Axes( 1 ),
      SendToReport( Dispatch( {}, "Overlay Plot",
      FrameBox, {Frame Size( 1600, 1600 )} ) )
    )
  ),
  New Column( "unicode",
    Character,
    Nominal,
    Formula( "\!"\!\\!!u" || Substr( Hex( Row(), "integer" ), 5, 4 ) || "\!"" )
  ),
  New Column( "X", Numeric, Continuous, Format( "Best", 10 ),
    Formula( Sequence( 1, 140, 1, 1 ) ) ),
  New Column( "Y", Numeric, Continuous, Format( "Best", 10 ),
    Formula( Sequence( 1, 140, 1, 140 ) ) )
);

// use While() to see when the data table is finished -
// else next line processes before the data table is built
// and you get error: "Argument should be row State{1}"
while(is missing(:Y[19561]), wait(.0001) );

// see all markers using unicode arguments
For Each Row( Row State( Row() ) = Marker State( Parse( :unicode ) ) );

// the equivalent command, using integer arguments
For Each Row( Row State( Row() ) = Marker State( Row() ) );

To set several aspect of one row’s state, add a teaspoon of Combined States()

For example, to set row 1 to a solid pink inverted triangle, stick both of the previous examples together with a Combined States() operator. This would be handy for a World War II historian plotting deaths in the Holocaust.

Row State( 1 ) = Combine States( Marker State( 21 ), Color State( 11 ) );

Or to set row 1 to a yellow (color #41) star of David (marker #10017), to plot the most horrendous statistics from the Holocaust, you could set:

Row State( 1 ) = Combine States( Marker State( 10017 ), Color State( 41 ) );

Some interesting Unicode characters to use as markers

Just scroll through the data table created above to see some Unicode characters that might be particularly useful for JMP graph markers, such as:

  • Greek and Coptic start at \u0370
  • Currency symbols start at \u20A0
  • Hebrew, Arabic, etc. start at \u0590
  • Fractions and roman numerals start at \u2150
  • Box elements and other geometric shapes and dingbats start at \u2500
  • Arrows, math operators, and technical symbols start at \u2190
  • Weather, pointing hand, smiley faces, gender, and astrology symbols start at \u2600
  • Chess pieces, card suits, musical symbols, recycling symbols, dice, monogram, digram, and trigram symbols start at \u2654
  • Braille starts at \u2800
  • Asian language characters start around \u2E80

Download the script

Don’t bother with copying and pasteing from the examples above—you can download a tidy sample script here:

  • [download id=”4″]

What did I forget?

What is still confusing about marker states? Post your questions and comments below, and I’ll do my best to address them in future posts (or in the comments, if they’re not too complex).

2 Comments : more...

Artwork

Global Pragmatica's artwork includes paintings by Zsuzsi Saper and digital photographs by Erin Vang. Further notes on specific pieces of art are given at the bottom of pages in which they appear. All artwork is copyright 2009–2010 by Global Pragmatica LLC®. All rights reserved worldwide.

© 2009-14 Global Pragmatica LLC®

All content © 2009-14 by Global Pragmatica LLC®. All rights reserved worldwide.

Global Pragmatica LLC® is a registered trademark of Global Pragmatica LLC. The ® symbol indicates USA trademark registration.

Contact Global Pragmatica LLC®

info@globalpragmatica.com
+1 415.997.9671
Oakland, CA 94611