cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
txnelson
Super User

Detection of changes in a Local Data Filter

 

Below is a script that uses a Data Filter that when it is changed, it triggers the Row State Handler, and updates the chart.  I really want to use a local filter, but have not been able to figure out how to detect the change in the local filter.  How does one detect a change in the Local Data Filter?

 

 

Names Default To Here( 1 );

 

dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

 

f = Function( {a},

// Capture the LCL and UCL from the Limit Summaries Outline Box in the Report Output

       myLCL = (Report( ccb )["NPN1 Limit Summaries"][Table Box( 1 )][2] << get)[1];

       myUCL = (Report( ccb )["NPN1 Limit Summaries"][Table Box( 1 )][4] << get)[1];

// Apply back to the Control Chart the new axis settings

       Report( ccb )[Axis Box( 3 )] << Min( myLCL );

       Report( ccb )[Axis Box( 3 )] << Max( myUCL );

);

   

rs = dt << make rowstate handler( f );

 

New Window( "Working Example",

       Data Filter Context Box(

              H List Box(

                     dt << Data Filter( Add Filter( Columns( :SITE ) ),Mode(select(1),show(1),include(1)) ),

                     Platform(dt,

                           ccb = Control Chart Builder(

                                  Size( 534, 453 ),

                                  Show Control Panel( 0 ),

                                  Variables( Y( :NPN1 ) ),

                                  Chart( Position( 1 ), Limits ),

                                  Chart( Position( 2 ) ), 

                                  SendToReport(

                                         Dispatch(

                                                {},

                                                "NPN1",

                                                ScaleBox,

                                                {Min( 96.6346153846154 ), Max( 131.634615384615 ), Inc( 5 ), Minor Ticks( 0 ),

                                                Add Ref Line( 104.412948990151, "Solid", "Blue", "LSL", 1 ),

                                                Add Ref Line( 131.893493064355, "Solid", "Blue", "USL", 1 ),

                                                 Add Ref Line( 118.153221027253, "Solid", "Blue", "Target", 1 )}

                                          )

                                  )

                           )

                     )

              )

       )

);

 

 

 

Sent from Mail for Windows 10

 

 

Jim
1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Staff

Re: Detection of changes in a Local Data Filter

Perhaps you could try adding the row state handler to the local data filter? For example:

NamesDefaultToHere(1);

// Some data

dt = New Table( "Fruits",

Add Rows( 3 ),

New Column( "Fruit",

Character,

"Nominal",

Set Values( {"Pear", "Apple", "Orange"} )

)

);

// A report with a local data filter

gb = dt << Graph Builder(

Size( 528, 448 ),

Show Control Panel( 0 ),

Show Legend( 0 ),

Variables( X( :Fruit ) ),

Elements( Bar( X, Legend( 3 ) ) ),

Local Data Filter( Mode, Add Filter( columns( :Fruit ) ) )

);

// Row state handler function

doSomethingWithSelection = Function({x}, {Default Local}, Beep(); Wait(0.1); Beep() );

// Get a reference to the report

gbReport = gb << Report;

// See what messages the data filter display box understands (prints to the log)

ShowProperties(gbReport[OutlineBox(1)]);

// Assign the row state handler to the local data filter display box

rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(doSomethingWithSelection);

View solution in original post

6 REPLIES 6
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Detection of changes in a Local Data Filter

I can't think of any built-in support for monitoring a local data filter by script.

Below is an hack that simply runs in the background to find filtering changes by the user.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

f = Function( {ccb},

// Capture the LCL and UCL from the Limit Summaries Outline Box in the Report Output

       myLCL = (Report( ccb )["NPN1 Limit Summaries"][Table Box( 1 )][2] << get)[1];

       myUCL = (Report( ccb )["NPN1 Limit Summaries"][Table Box( 1 )][4] << get)[1];

// Apply back to the Control Chart the new axis settings

       Report( ccb )[Axis Box( 3 )] << Min( myLCL);

       Report( ccb )[Axis Box( 3 )] << Max( myUCL);

);

    nw=New Window( "Working Example",

           Data Filter Context Box(

                  H List Box(

                         ldf=dt << Data Filter( local,Add Filter( Columns( :SITE ) ),Mode(select(1),show(1),include(1)) ),

                         Platform(dt,

                               ccb = Control Chart Builder(

                                      Size( 534, 453 ),

                                      Show Control Panel( 1 ),

                                      Variables( Y( :NPN1 ) ),

                                      Chart( Position( 1 ), Limits ),

                                      Chart( Position( 2 ) ),

                                      SendToReport(

                                             Dispatch(

                                                    {},

                                                    "NPN1",

                                                    ScaleBox,

                                                    {Min( 96.6346153846154 ), Max( 131.634615384615 ), Inc( 5 ), Minor Ticks( 0 ),

                                                    Add Ref Line( 104.412948990151, "Solid", "Blue", "LSL", 1 ),

                                                    Add Ref Line( 131.893493064355, "Solid", "Blue", "USL", 1 ),

                                                     Add Ref Line( 118.153221027253, "Solid", "Blue", "Target", 1 )}

                                              )

                                      )

                               )

                         )

                  )

           )

    );

// Monitor local data filtering by peeking into the Where Clause below the control Chart

// First locate the Where-clause TextBox

// (the number varies but it seems to always be the last one)

Wait(0);

i = 1;

While(Is Scriptable(Try(parent = nw[Text Box(i)] << parent)),

    While(parentType = Char(parent << className) != "OutlineBox", parent = parent << parent);  

    i++;

);

// Scan for changes with an adequate frequency

filter = "none";

While(Is Scriptable(nw), // Will run until nw is closed

    Wait(0.1); // set the scanning frequency here

    If(!Is Missing(newfilter = Try(nw[Text Box(i)] << gettext)),

        If(filter != newfilter,

            filter = nw[Text Box(i)] << gettext;

            f(ccb); // get limits and set a axis

        )

    );

);

txnelson
Super User

Re: Detection of changes in a Local Data Filter

I was hoping there was a more direct monitor of a local filter.  Maybe 14.0 will have such a monitor. Thanks for the code. 

Jim
ian_jmp
Staff

Re: Detection of changes in a Local Data Filter

Perhaps you could try adding the row state handler to the local data filter? For example:

NamesDefaultToHere(1);

// Some data

dt = New Table( "Fruits",

Add Rows( 3 ),

New Column( "Fruit",

Character,

"Nominal",

Set Values( {"Pear", "Apple", "Orange"} )

)

);

// A report with a local data filter

gb = dt << Graph Builder(

Size( 528, 448 ),

Show Control Panel( 0 ),

Show Legend( 0 ),

Variables( X( :Fruit ) ),

Elements( Bar( X, Legend( 3 ) ) ),

Local Data Filter( Mode, Add Filter( columns( :Fruit ) ) )

);

// Row state handler function

doSomethingWithSelection = Function({x}, {Default Local}, Beep(); Wait(0.1); Beep() );

// Get a reference to the report

gbReport = gb << Report;

// See what messages the data filter display box understands (prints to the log)

ShowProperties(gbReport[OutlineBox(1)]);

// Assign the row state handler to the local data filter display box

rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(doSomethingWithSelection);

txnelson
Super User

Re: Detection of changes in a Local Data Filter

Ian,

You example worked great.  I went back to find documentation on this, in the scripting index, and only found the obscurest of reference that a "Mark Row State Handler" will work on a data table filter.  So I figured that if I set it up to be able to point directly to the filter, rather than the filter's outline box, it should work, and be an even more direct piece of code.  But that did not work.  Do you have any insight into why that doesn't work?  When I run the script, it does know that the handle "xx" is pointing to a Data Filter.

 

Names Default To Here( 1 );

 

// Some data

dt = New Table( "Fruits", 

       Add Rows( 3 ),

       New Column( "Fruit",  

              Character,  

              "Nominal",  

              Set Values( {"Pear", "Apple", "Orange"} )

       ) 

);

 

// A report with a local data filter 

gb = dt << Graph Builder( 

       Size( 528, 448 ),  

       Show Control Panel( 0 ),  

       Show Legend( 0 ),  

       Variables( X( :Fruit ) ),  

       Elements( Bar( X, Legend( 3 ) ) ) 

);

   

xx = gb << Local Data Filter( Mode, Add Filter( columns( :Fruit ) ) );

 

// Row state handler function

doSomethingWithSelection = Function( {x},

       {Default Local}, 

       Beep();

       Wait( 0.1 );

       Beep();

);

 

// Get a reference to the report

gbReport = gb << Report;

   

// See what messages the data filter display box understands (prints to the log) 

Show Properties( gbReport[Outline Box( 1 )] );

 

// Assign the row state handler to the local data filter display box

 

xx << MakeRowStateHandler( dosomethingwithselection );

//rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(dosomethingwithselection);

 

Jim
ian_jmp
Staff

Re: Detection of changes in a Local Data Filter

Not answering your question directly, Jim. But FWIW, I didn't see 'MakeRowStateHandler' on the list of messages for the local data filter object.

hogi
Level XI

Re: Detection of changes in a Local Data Filter

With 

rs = xx << Make Filter State Handler( dosomethingwithselection );

instead of 

xx << MakeRowStateHandler( dosomethingwithselection );

it will work.


Please note that it's essential to store the returned Filter State Handler to a JSL symbol: rs = 

 rs = xx << Make Filter State Handler( dosomethingwithselection );

(without rs = ) will not work: Filter Change Handler