Connect Local Data Filters between Graph Builder Windows from different data tablesSuppose I have two Graph Builder windows from different data tables, each with a Local Data Filter filtering on "run number" and "time".
Is it possible to connect the two Local Data Filters so they stay in sync?
Or perhaps with JSL to pull the current settings from Local Data Filter #1 and apply them to Local Data Filter #2?
(I guess step 1 is getting a reference to the Local Data Filters, I haven't even figured out how to do that yet -- here's what I have so far:
// get the last Graph Builder
win = Get Window List();
graphs = Filter Each({w}, win,
If(Length(w << XPath("//OutlineBox[@helpKey='Graph Builder']")) > 0, 1, 0)
);
last_gb = graphs[N Items(graphs)][OutlineBox("Graph Builder")] << Get Scriptable Object;
localDataFilter = last_gb << XPath("//OutlineBox[text()='Local Data Filter']");)
Automation and ScriptingRe: Connect Local Data Filters between Graph Builder Windows from different data tablesCould you concatenate the tables together and then use some sort of grouping column to separate them to different graphs? It might be easier than messing with filter change handler(s).
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesNot really -- one table is a high-level summary of the run results, and we identify problems from that summary, then switch to the detailed-run plot and select the specific run in the data filter. It's not obvious to me how merging those two tables would enable that type of behavior.
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesHow about virtual joins?
Re: Connect Local Data Filters between Graph Builder Windows from different data tablessimilar post:
https://community.jmp.com/t5/Discussions/Virtual-linking-two-tables-via-JSL-scripting/m-p/657682/highlight/true#M84705
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesI guess one needs not-local data filters such that the Dispatch/Receive functionality of virtual links will broadcast the filter settings.
For my case, this was too slow.
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesAnd if you want to copy the whole filter, you could use copy/paste:
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb1 = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);
gb2 = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :sex ), X( :age, Position( 1 ) ), Y( :weight ), Overlay( :sex ) ),
Elements( Bar( X( 1 ), X( 2 ), Y, Legend( 3 ) ) )
);
df1 = gb1 << Local Data Filter(
Add Filter(
columns( :age ),
Where( :age == 15 ),
Display( :age, N Items( 6 ) )
)
);
df1 << copy local data filter();
gb2 << paste local data filter();
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesI like the idea, but obviously there's something I don't understand in your solution, as it crashes when I try to run it.
Here's what I have so far:
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb1 = dt << Graph Builder(
Graph Spacing( 5 ),
Variables( X( :sex ), Y( :height ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);
gb2 = dt << Graph Builder(
Graph Spacing( 5 ),
Variables( X( :sex ), Y( :height ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);
df1 = gb1 << Local Data Filter(
Add Filter(
columns( :sex ),
Where( :sex == "M" ),
Display( :sex, N Items( 2 ) )
)
);
df2 = gb2 << Local Data Filter(
Add Filter(
columns( :sex ),
Where( :sex == "F" ),
Display( :sex, N Items( 2 ) )
)
);
broadcastFilter = Function( {},
//get the script
filterScript = df1 << get Script();
//search for the "Add filter" part
For( i = 1, i <= N Arg( filterScript ), i++,
If( Head( Arg( filterScript, i ) ) == Expr( Add Filter() ),
filterExpression = Arg( filterScript, i )
)
);
// broadcast it to the other Data filter
Eval(
Substitute(
Expr(
df2 << Start Over << _filter_
),
Expr( _filter_ ), Name Expr( filterExpression )
)
);
);
// activate the Filter Change Handler
rs = df1 << Make Filter Change Handler( broadcastFilter );Here's the error: "broadcastFilter has 0 parameters () but 1 arguments (18) were supplied". Any idea what it's talking about? I don't think I'm supplying any arguments in that last line...
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesOh. sorry.
broadcastFilter = Function( {x}, Re: Connect Local Data Filters between Graph Builder Windows from different data tablesAt the end, I switched back to local data filters and added a Filter Change Handler to the first Data Filter.
It works quite well - If you don't forget the
rs=
Filter Change Handler
broadcastFilter=Function({x}, // Make Filter Change Handler need a function with 1 Argument
//get the script
filterScript = DataFilter1 << get Script();
//search for the "Add filter" part
For( i = 1, i <= N Arg( filterScript ), i++,
If( Head( Arg( filterScript, i ) ) == Expr( Add Filter() ),
filterExpression = Arg( filterScript, i )
)
);
// broadcast it to the other Data filter
Eval( Substitute( Expr( Datafilter2 << Start Over << _filter_ ), Expr( _filter_ ),
Name Expr( filterExpression ) ) );
// activate the Filter Change Handler
rs = DataFilter1 << Make Filter Change Handler( broadcastFilter); // will call broadcastFilter() with 1 Argument: # of selected rows
edit:argument x added and commented. A Function
broadcastFilter=Function({},-without arguments - doesn't work.
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesWow, it works! I wish I understood what that code was doing...
Last question -- assuming I already have a Graph Builder window open with a Local Data Filter, I know how I can get the gb .jsl object variable:
win = Get Window List();
graphs = Filter Each({w}, win, If(Length(w << XPath("//OutlineBox[@helpKey='Graph Builder']")) > 0, 1, 0) );
gb = graphs[N Items(graphs)][OutlineBox("Graph Builder")] << Get Scriptable Object;... but how can I get the df1 object variable from the gb object variable? (It feels like I've tried 100 different things...)
Re: Connect Local Data Filters between Graph Builder Windows from different data tablesOne option is to use similar idea as you use for graph builder
df = (gb << top parent)[Outline Box("Local Data Filter")] << Get Scriptable Object;
local data filter isn't inside the graph builder, so you have to first travel to higher level (in this case I use << top parent). Using XPath with attribute helpKey and value Data Filter might be a bit more robust solution and it would be something like this
(gb << top parent) << XPath("//OutlineBox[@helpKey='Data Filter']")
Edit: If you have possibility of multiple data filters in the same window, you might have to make the definition of the starting point a bit more specific than just using << top parent.