cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to use Filter Change Handler to work with Page option in Graph Builder?

Attached is an example data table. The script below tries to plot each parameter selected via the Local Data Filter in a new "Page" in Graph Builder. As it stands, the y-axis title is shown as "Median" every time a new "Parameter" is selected via the Local Data Filter.

I would like the Parameter name to be the y-axis title when new a parameter gets selected and plotted on a new "Page".

I tried using the filter change handler for this, but my script does not quite work. I think I need the index below to be updated each time a new parameter is selected or may be there is another way. Any direction will be useful. 

XPath( "//TextEditBox" ))[i]

here is my script

Names Default To Here (1);
Clear Log ();
gb = Graph Builder(
	Size( 531, 325 ),
	Show Control Panel( 0 ),
	Variables( X( :PartID ), Y( :Median ), Page( :Parameter ), Color( :TestStage ) ),
	Elements( Points( X, Y, Legend( 34 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :TestStage, :Parameter ),
			Where( :TestStage == {"A", "B"} ),
			Where( :Parameter == {"BKDVoltage", "Capacitance"} )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "myTitleGoesHere" )} ) )
);

ldf = Current Report()["Local Data Filter"] << get scriptable object;

changeTitle = Function( {this},
	print(this);
  	ldfText = Regex(ldf << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");
	if(ismissing(ldfText),ldfText = " Selected Test Parameter ");
	(Report( gb ) << XPath( "//TextEditBox" ))[6] << Set Text(ldfText);
);

fsh = ldf << Make Filter Change Handler(changeTitle());
When it's too good to be true, it's neither
30 REPLIES 30
Neo
Neo
Level VI

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

@jthi In the actual data case, if I comment out

update_title(local_filter);

as in 

local_filter = Current Report()["Local Data Filter"] << get scriptable object;
//update_title(local_filter);
filter_handler = local_filter << Make Filter Change Handler(update_title());

Everything works as expected except the initial charts do not have the correct Y Axis title. Y axis title becomes correct only after another TestStage is selected. Is my placement of 

update_title(local_filter);

correct or should it be placed somewhere else? 

When it's too good to be true, it's neither
jthi
Super User

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

Like I said, it is most likely due to parameters being filtered

Names Default To Here (1);
dt = Open("$DOWNLOADS/exampleSummaryTable.jmp");

gb = dt << Graph Builder(
	Size( 531, 325 ),
	Show Control Panel( 0 ),
	Variables( X( :PartID ), Y( :Median ), Page( :Parameter ), Color( :TestStage ) ),
	Elements( Points( X, Y, Legend( 34 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :TestStage, :Parameter ),
			Where( :TestStage == {"A", "B"} ),
			Where( :Parameter == {"BKDVoltage", "Capacitance"} )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "myTitleGoesHere" )} ) )
);

Summarize(dt, uniq_params = By(:Parameter));

update_title = Function( {this},
  	param_where = Regex(local_filter << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");
  	If(Is Missing(param_where),
		param_list = uniq_params;
  	,
		param_where_list = Words(param_where, "|");
		param_list = Transform Each({where_str}, param_where_list,
			title = Trim Whitespace(Word(-1, where_str, "="));
			Substitute(title, "\!"", "");		
		);
  	);
  	
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs= tebs[4::N Items(tebs)::2]; // skip title, subtitle and xaxis?
	
	If(N Items(y_tebs) != N Items(param_list),
		return(0); // some problem
	);
	
	gb << inval;
  	For Each({param_val, idx}, param_list,
  		y_tebs[idx] << Set Text(param_val);
  	);
  	gb << update window;
  	
  	return(1);
);


local_filter = Current Report()["Local Data Filter"] << get scriptable object;
update_title(local_filter);
filter_handler = local_filter << Make Filter Change Handler(update_title());
-Jarmo
Neo
Neo
Level VI

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

@jthi Thanks. This runs without error in the case of my actual data set but the initial plots are still without the correct parameter names on the y-axis. The correct y-axis titles are trigged only when I select a second TestStage (initially only one is selected via the script).

When it's too good to be true, it's neither
jthi
Super User

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

Not sure what could be wrong as it seems to work with the original data and with the data2 after removing multiple response just fine (using JMP17.2). Does it work if you select one value and then remove all selections from your filter?

View more...
Names Default To Here(1);
dt = Current Data Table();

gb = dt << Graph Builder(
	Show Control Panel(0),
	Variables(X(:PartID), Y(:Median), Page(:Parameter), Color(:TestStage)),
	Elements(Points(X, Y, Legend(34))),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns(:TestStage, :Parameter),
			Where(:TestStage == {"A", "B"})
		)
	),
	SendToReport(Dispatch({}, "graph title", TextEditBox, {Set Text("myTitleGoesHere")}))
);

Summarize(dt, uniq_params = By(:Parameter));

update_title = Function({this},
	param_where = Regex(local_filter << get where clause(), "\(?\s*(:Parameter == .*?)\)", "\1");
	If(Is Missing(param_where),
		param_list = uniq_params,
		param_where_list = Words(param_where, "|");
		param_list = Transform Each({where_str}, param_where_list,
			title = Trim Whitespace(Word(-1, where_str, "="));
			Substitute(title, "\!"", "");
		);
	);
  	
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs = tebs[4 :: N Items(tebs) :: 2]; // skip title, subtitle and xaxis?
	
	If(N Items(y_tebs) != N Items(param_list),
		Return(0); // some problem
	);
	
	gb << inval;
	For Each({param_val, idx}, param_list, y_tebs[idx] << Set Text(param_val));
	gb << update window;
  	
	Return(1);
);


local_filter = Current Report()["Local Data Filter"] << get scriptable object;
update_title(local_filter);
filter_handler = local_filter << Make Filter Change Handler(update_title());
-Jarmo
Neo
Neo
Level VI

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

@jthi I do not understand what you mean by "Does it work if you select one value and then remove all selections from your filter?". Could you please rephrase? Also, I am on JMP 16.2.

When it's too good to be true, it's neither
jthi
Super User

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

Using exampleSummarTable.jmp and latest script I provided.

After one value has been filtered

jthi_0-1707150114044.png

Deselect that single value (so nothing is being filtered)

jthi_1-1707150128777.png

 

-Jarmo
Neo
Neo
Level VI

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

@jthi In the example cases so far everything works as expected and matches what you see.

However, I was able to reproduce part of the issue I am facing with my actual data by creating another data table which more closely matches with my actual data. Data table is attached and using the script below

Names Default To Here(1);
dt = Current Data Table();

gb = dt << Graph Builder(
    Size( 571, 174 ),
	Show Control Panel(0),
	Variables(X(:PartID), Y(:Median), Page(:Parameter), Color(:TestStage)),
	Elements(Points(X, Y, Legend(34))),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns(:TestDate, :Has Limits?, :TestStage, :Parameter ),
			Where( :Has Limits? == "Yes" ),
			Where( :TestStage == "STG5" ),
		)
	),
	SendToReport(Dispatch({}, "graph title", TextEditBox, {Set Text("myTitleGoesHere")}))
);

Summarize(dt, uniq_params = By(:Parameter));

update_title = Function({this},
	param_where = Regex(local_filter << get where clause(), "\(?\s*(:Parameter == .*?)\)", "\1");
	If(Is Missing(param_where),
		param_list = uniq_params,
		param_where_list = Words(param_where, "|");
		param_list = Transform Each({where_str}, param_where_list,
			title = Trim Whitespace(Word(-1, where_str, "="));
			Substitute(title, "\!"", "");
		);
	);
  	
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs = tebs[4 :: N Items(tebs) :: 2]; // skip title, subtitle and xaxis?
	
	If(N Items(y_tebs) != N Items(param_list),
		Return(0); // some problem
	);
	
	gb << inval;
	For Each({param_val, idx}, param_list, y_tebs[idx] << Set Text(param_val));
	gb << update window;
  	
	Return(1);
);


local_filter = Current Report()["Local Data Filter"] << get scriptable object;
update_title(local_filter);
filter_handler = local_filter << Make Filter Change Handler(update_title());

I get the following when no Parameters are selected,

Neo_0-1707308734378.png

and this one after selecting all Parameters and unselecting them again. Here the top chart only gets the correct y-axis label.

Neo_1-1707308798896.png

Hopefully if these get resolved, my actual data case will start working as expected as well. Any direction would be very useful. 

When it's too good to be true, it's neither
jthi
Super User

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

This check is causing the issues.

jthi_0-1707310903516.png

There are more filters which can cause a situation when not all parameters are visible. One option would be to use << Get Filtered Rows and calculate which parameters are visible instead of just assuming all of them are.

-Jarmo
Neo
Neo
Level VI

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

@jthi Thanks but my Scripting Index (JMP 16.2) does got give any example on how to use << Get Filtered Rows.

Could I get some help on how to use it in my case?

Neo_0-1707314128854.png

 

When it's too good to be true, it's neither
jthi
Super User

Re: How to use Filter Change Handler to work with Page option in Graph Builder?

You could just try what it does when you send it to a data filter.

 

Here is example from JMP17 scripting index

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cities.jmp");
obj = dt << Data Filter(
	Add Filter(columns(:Region, :POP), where(:Region == {"C", "N"})),
	Mode(Select(0), Show(0), Include(1))
);
obj << Get Filtered Rows; // [1, 4, 5, 6, 7, 19, 20, 26, 36, 40, 42, 46]
-Jarmo