Subscribe Bookmark RSS Feed

How to script multiple rows to be selected when one is selected in a bivariate plot?

nkelleh

Community Trekker

Joined:

Dec 19, 2012

Hi all,

I have a script where one of the outputs is a bi-variate (XY) Plot using the bi-variate platform. Its basically plotting the value of a parameter of a device on the y-axis verses time on the x-axis. These parts have a common ID value in a column from the source datatable.

Now the platform already has the functionality where if you click on one marker, the row that marker is based on is selected in the datatable (other markers in the display box become faded). What I want is that when a user clicks on one marker, that all the other markers with the same ID value are highlighted also (So the user can see how this one device behaved over time). I'm just struggling to find a way to do this. Is there access to the event handling code that already exists for the platform (i.e. what allows the rows to be selected when the user clicks on a marker, or multiple rows when the user clicks and drags a rectangle in the plot window)?

Any help on this would be greatly appreciated.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
nkelleh

Community Trekker

Joined:

Dec 19, 2012

Solution

Hi all,

I found a way to do it that works. Basically, you just have to create a graphics script, and in there, write code that gets the IDs from the selected rows and then use a select where statement to match all rows with that ID. This also works if you click and drag a number of points in the Bivariate window. Sample code below.


xParam ="Column Name 1 Here";


yParam = "Column Name 2 Here";


idParam = "Column Name 3 Here";


//tableRef = data table reference



bivPlatform = Bivariate(


      Y( Eval(yParam) ),


      X( Eval(xParam) ),


);



bivReport = bivPlatform << Report;


bivFrame = bivRawReport[FrameBox( 1 )];               //Assign reference to framebox



// Add Graphics script to select all rows with matching ID when one row is selected on the graph


bivFrame << Add Graphics Script( 2, //Order graphics script is run with respect to other elements in Frame box (Not really needed here)



      //Get selected IDs


      selectedIDMatrix = tableRef:idParam[  ( tableRef << Get Selected Rows() ) ];


     


      //Get unique IDs (optional I guess)


      idArray = Associative Array(selectedIDMatrix);


      uniqueIDMatrix = idArray << Get Keys;


     


      //Select other datapoints with matching IDs


      tableRef << Select Where(  Contains( As List(uniqueIDMatrix), As Column(tableRef, idParam) )  );


           


);


4 REPLIES
scwise

Staff

Joined:

Jul 7, 2014

nkelleh,

Thanks for the question on being able to select something in an Fit X By Y Bivariate Graph, but then see all the corresponding points back to the data table highlighted that have similar IDs to the selected point.  While there still might be a more elegant "scripting from scratch" answer to what you are wanting to do, I found an easy way using the new JMP 12 Application Builder feature that allows a graph to be used as a data filter.  Then hopefully you can use parts of this ready made script in your current work, or perhaps just be able to use this out of the box capability as it stands.  Note that I am using JMP 12.1 release for Mac.

In this case we created a simple data table like you described with three columns: ID, X and Y, with several IDs having multiple rows of different X and Y measurements. We then combined the datatable and then a distribution of the columns into one window (Combine Windows in JMP to get a Custom Report view) below so you can see our initial setup.

8979_Custom Report 1.png

Then we created a graph showing the Bivariate Fit of Y by X.  At this point if you select a point, you are really selecting only based on the X and Y coordinates.  Getting the ID label for that point to show up is no problem, but this will only shade (select) that exact point back into your data table.  So the problem is that the Bivariate would be looking for matches based only on similar X and Y coordinates, and not common IDs.  See the next Custom Report view.8980_Custom Report 2.png

So thought maybe we could made this a really easy two step process by creating a "helper" graph next to the Bivariate that would allow me to then select all the ID points of interest with one click.  To do this I created a Distribution for ID (which I made into a nominal data column type for better selection capability) and then turned all display options off except for a Mosaic Plot.  Then joined both the Distribution and Bivariate graphs into one window to get another Custom Report view.  Then under the red triangle in the Report header we selected the Edit Application button that brings up the Application Builder workspace (after selecting the underlying datatable).  Now in the Application Builder it is as easy as selecting the first Distribution Mosaic Plot graph, right clicking on it and selecting Use As A Filter.  Now I can have a two click solution...where first I select the point on the Bivariate Fit Y By X chart that I care about, and then can slide over and select (click direction on) the full ID in the partially shaded Mosaic that will now highlight all the similar IDs on the Data Table.  Also nice to graphically see on the Bivariate Fit Y By X chart all the points corresponding to the same ID number after we select it on the Mosaic Plot.

8981_Custom Report 3.png

8983_Custom View 1.png

Now you can go to the red triangle under the Report header and save the script to a script window to see the underlying scripting work that got generated for you in creating this view.  Again while this is not as slick as being able to do this straight from the Bivariate Fit Y By X, it does show an out of the box solution and gives you a way to generate some of the scripting automatically.  Will attach in this JMP work file with saved scripts for you to check out as well.

Hope this helps!

nkelleh

Community Trekker

Joined:

Dec 19, 2012

Hi scwise,

Thanks for this and look forward to having this capability when I upgrade to JMP 12.

I was kind of looking for this functionality just within the bivariate display box. To use your example above, I'd like to click on a datapoint for 2014, and have all the 2014 points highlighted. I'm hoping there is a pure script solution out there.

In any case, thanks again for your reply.

nkelleh

Community Trekker

Joined:

Dec 19, 2012

Solution

Hi all,

I found a way to do it that works. Basically, you just have to create a graphics script, and in there, write code that gets the IDs from the selected rows and then use a select where statement to match all rows with that ID. This also works if you click and drag a number of points in the Bivariate window. Sample code below.


xParam ="Column Name 1 Here";


yParam = "Column Name 2 Here";


idParam = "Column Name 3 Here";


//tableRef = data table reference



bivPlatform = Bivariate(


      Y( Eval(yParam) ),


      X( Eval(xParam) ),


);



bivReport = bivPlatform << Report;


bivFrame = bivRawReport[FrameBox( 1 )];               //Assign reference to framebox



// Add Graphics script to select all rows with matching ID when one row is selected on the graph


bivFrame << Add Graphics Script( 2, //Order graphics script is run with respect to other elements in Frame box (Not really needed here)



      //Get selected IDs


      selectedIDMatrix = tableRef:idParam[  ( tableRef << Get Selected Rows() ) ];


     


      //Get unique IDs (optional I guess)


      idArray = Associative Array(selectedIDMatrix);


      uniqueIDMatrix = idArray << Get Keys;


     


      //Select other datapoints with matching IDs


      tableRef << Select Where(  Contains( As List(uniqueIDMatrix), As Column(tableRef, idParam) )  );


           


);


ian_jmp

Staff

Joined:

Jun 23, 2011

FYI, another approach using the row state handler:

Names Default To Here( 1 );

// Table

dt = New Table( "Bivariate ID Selection",

  Add Rows( 10 ),

  New Column( "ID", Numeric, "Nominal", Format( "Best", 12 ), Set Values( [2014, 2011, 2012, 2013, 2014, 2011, 2013, 2012, 2011, 2014] ) ),

  New Column( "X", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ) ),

  New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [20, 21, 25, 28, 30, 31, 33, 36, 37, 40] ) ),

  Set Label Columns( :ID )

);

// Row state handler function

selectMatchingID = Function( {x},

  // Get which rows are currently selected

  selectedRows = [];

  i = 1;

  For Each Row(

  If( Selected( Row State() ),

  selectedRows = V Concat( selectedRows, i )

  );

  i++;

  );

  // If there is a selection, 'expand' it to all required rows

  If( N Row( selectedRows ) > 0,

  expandedSelectedRows = [];

  For( i = 1, i <= N Row( selectedRows ), i++,

  thisID = :ID[selectedRows[i]];

  matchingRows = dt << getRowsWhere( :ID == thisID );

  expandedSelectedRows = V Concat( expandedSelectedRows, matchingRows );

  );

  dt << selectRows( expandedSelectedRows );

  );

);

// Assign the handler to the table

rsh = dt << MakeRowStateHandler( selectMatchingID );

// Try it out with Graph Builder

dt << Graph Builder(

  Size( 530, 454 ),

  Show Control Panel( 0 ),

  Variables( X( :X ), Y( :Y ) ),

  Elements( Points( X, Y, Legend( 5 ) ), Smoother( X, Y, Legend( 6 ) ) )

);