I would write a script like this quite differently than what you've done -- this helps separate the logic (the functions that do work) from the display tree, and flattens out the script. It also has the added benefit that all functions are easily callable and sharable and not attached directly to button call-backs.
But to answer your main question about lag, I'm honestly not sure. It was hard for me to follow the execution path on your script which is why I re-wrote it, and the rewrite does not have the lag issue.
Names Default to Here( 1 );
/*
Here I use an anonymous namespace to scope all the variable and functions -- use Eval( Eval Expr( ... Expr( self << Get Name ) ... ) ) where needed to put the reference inside funcitons and other scopes
*/
self = New Namespace();
self:dt Names = {};
For( t = 1, t <= N Table(), t++,
Insert Into( self:dtNames, Data Table( t ) << Get Name )
);
self:slider value = 1;
self:validated = 0;
self:_tables = {};
/*
The Eval( Eval Expr( ... Expr( self << Get Name ) ... ) ) part needs to encompass any functions and windows that the script will have.
This is a bit unfortunate becuase it makes using this block inside rather tricky
*/
Eval( Eval Expr(
/****************************************
Define the functions the script will use
****************************************/
self:add table = Function( {_table},
Insert Into( self:_tables, _table );
_table
);
self:update reference lines = Function( {},
{Default Local},
self = Namespace( Expr( self << Get Name ) );
self:slider value = self:sb << Get;
self:tb << Set Text( "Cpk: " || Char( self:slider value ) );
Try(
old lsl = self:lsl;
old usl = self:usl;
);
self:limits table << Rerun Formulas;
self:lsl = Associative Array( self:limits table:Analysis Columns, self:limits table:LSL );
self:usl = Associative Array( self:limits table:Analysis Columns, self:limits table:USL );
Summation( i = 1, N Items( self:col ),
If( Contains( self:lsl, self:col[i] ),
Try( self:variability report[i][Axis Box( 1 )] << Remove Ref Line( old lsl[self:col[i]] ) << Remove Ref Line( old usl[self:col[i]] ) );
/*
Here I've done a bit of trickery because we're inside an Eval( Eval Expr( ... Expr( self << Get Name ) ... ) ) block.
*/
dispatch = {};
Insert Into( dispatch, Substitute( Eval List( {self:lsl[self:col[i]], "Solid", "Red", "LSL=" || Substr( Char( self:lsl[self:col[i]] ), 1, 5 ), 2} ), As Name( "List" ), As Name( "Add Ref Line" ) ) );
Insert Into( dispatch, Substitute( Eval List( {self:usl[self:col[i]], "Solid", "Red", "New USL=" || Substr( Char( self:usl[self:col[i]] ), 1, 5 ), 2} ), As Name( "List" ), As Name( "Add Ref Line" ) ) );
Eval List( Substitute( {Send( self:variability report[i][Axis Box( 1 )], _dispatch_ )}, As Name( "_dispatch_" ), dispatch ) );
);
0
)
);
self:set limits = Function( {},
{Default Local},
self = Namespace( Expr( self << Get Name ) );
Summation( i = 1, N Items( self:col ),
If( Contains( self:aa_refs, self:col[i] ),
self:variability report[i][Axis Box( 1 )] << Min( self:aa_refs[self:col[i]] - 1 ) << Max( self:aa_refs1[self:col[i]] + 1 );
self:variability report[i][Frame Box( 1 )] << DispatchSeg( CustomStreamSeg( 3 ), {Line Width( 2 )} );
/*
Here I've done a bit of trickery because we're inside an Eval( Eval Expr( ... Expr( self << Get Name ) ... ) ) block
*/
dispatch = {};
Insert Into( dispatch, Substitute( Eval List( {self:aa_refs[self:col[i]], "Solid", "Dark Green", "New LL=" || Substr( Char( self:aa_refs[self:col[i]] ), 1, 5 ), 2} ), As Name( "List" ), As Name( "Add Ref Line" ) ) );
Insert Into( dispatch, Substitute( Eval List( {self:aa_refs1[self:col[i]], "Solid", "Dark Green", "New UL=" || Substr( Char( self:aa_Refs1[self:col[i]] ), 1, 5 ), 2} ), As Name( "List" ), As Name( "Add Ref Line" ) ) );
Eval List( Substitute( {Send( self:variability report[i][Axis Box( 1 )], _dispatch_ )}, As Name( "_dispatch_" ), dispatch ) );
);
0
)
);
/****************************************
Modal input window
****************************************/
New Window( "Select Data Table",
<< Modal
,
<< On Validate(
Local( {self = Namespace( Expr( self ) )},
If( N Items( self:dt list box << Get Selected ),
self:validated = 1;
self:dt = Data Table( (Insert( {}, self:dt list box << Get Selected ))[1] );
1
,
0
)
)
)
,
Panel Box( "Pick a Table", self:dt list box = List Box( self:dt names, Max Selected( 1 ) ) )
);
/****************************************
Quit and delete namespace if not validated
****************************************/
If( Not( self:validated ),
s = Char( "Delete Namespaces( \!"" || (self << Get Name) || "\!", Force( 1 ) )" );
self = .;
Eval( Parse( s ) );
Stop()
);
/****************************************
Some initial setup
****************************************/
self:limits table = self:add table( Data Table( "Limits table" ) << Subset( All Rows, All Columns, Not Linked, Private ) );
self:col = self:limits table:Analysis Columns << Get Values;
self:col as name = {};
Summation( i = 1, N Items( self:col ),
self:col as name[i] = As Name( self:col[i] );
0
);
Try( self:limits table << Delete Columns( "LSL" ) );
Try( self:limits table << Delete Columns( "USL" ) );
Try( self:limits table << Delete Table Variable( "cpk" ) );
self:limits table << New Table Variable( "cpk", 1.33 )
<< New Column( "LSL", "Numeric", "Continuous", Format( "Best", 12, 2 ), <<Formula( As Constant( self = Namespace( Expr( self << Get Name ) ) ); :Mean - self:slider value * 3 * :Std Dev ) )
<< New Column( "USL", "Numeric", "Continuous", Format( "Best", 12, 2 ), <<Formula( As Constant( self = Namespace( Expr( self << Get Name ) ) ); :Mean + self:slider value * 3 * :Std Dev ) );
self:aa_refs = Associative Array( self:limits table:Analysis Columns, self:limits table:LL );
self:aa_refs1 = Associative Array( self:limits table:Analysis Columns, self:limits table:UL );
/****************************************
Create main window -- this will close attached tables and delete the scoping namespace when closed
****************************************/
New Window( "WINDOW_NAME",
<<On Close(
Summation( i = 1, N Items( As Scoped( Expr( self << Get Name ), "_tables" ) ),
Close( As Scoped( Expr( self << Get Name ), "_tables" )[i], No Save );
0
);
Delete Namespaces( Expr( self << Get Name ), Force( 1 ) );
)
,
H List Box(
V List Box(
Spacer Box( Size( 10, 10 ) )
,
Border Box( Sides( 15 ),
V List Box(
Spacer Box( Size( 0, 30 ) )
,
self:tb = Text Box( "Cpk: " || Char( self:slider value ), <<Set Font Style( "Bold" ) )
,
Spacer Box( Size( 0, 5 ) )
,
self:sb = Slider Box( 1, 3, self:slider value, <<Set Function( Function( {this}, Local( {self = Namespace( Expr( self << Get Name ) )}, self:update reference lines ) ) ) )
,
)
)
)
,
V Scroll Box(
Outline Box( "",
Platform( self:dt,
self:variability chart = Variability Chart(
Y( Eval( self:col as name ) ),
X( :site ),
Show Range Bars( 0 ),
Show Grand Mean( 1 ),
Std Dev Chart( 0 ),
Points Jittered( 1 ),
Show Box Plots( 1 ),
SendToReport(
Dispatch(
{""},
"Variability Chart",
FrameBox,
{Frame Size( 846, 318 ), Row Legend(
Split,
Color( 1 ),
Color Theme( "JMP Default" ),
Marker( 0 ),
Marker Theme( "" ),
Continuous Scale( 0 ),
Reverse Scale( 0 ),
Excluded Rows( 0 )
)}
)
)
)
)
)
)
)
);
/****************************************
finalize the script after the display tree has been generated
****************************************/
self:variability report = self:variability chart << Report;
self:set limits;
self:update reference lines;
) )
Jordan