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
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

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

What is returned can be a bit finicky in my experience (especially when nothing/everything is selected). Next you would have to figure out what to do in those situations and then you should be able to modify my earlier script.

 

 

 

Below are few solutions to this whole thing which do work for me, not sure if the "simpler" one does work in JMP16. I wouldn't suggest looking into these until you have managed to figure out what you could do int the "Empty" situation so you understand what type of issues there could be.

View more...

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

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))),
	SendToReport(Dispatch({}, "graph title", TextEditBox, {Set Text("Trend Chart")}))
);

filter_ref = gb << Local Data Filter(
	Conditional,
	Add Filter(
		columns(:TestDate, :Has Limits?, :TestStage, :Parameter),
		Where( :Has Limits? == "Yes" ),
		Where( :TestStage == "STG5" ),
	)
);

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

filter_ref = (Report(gb) << top parent)[OutlineBox("Local Data Filter")] << Get Scriptable Object;

update_title = Function({this},
	cur_rows = filter_ref << Get Filtered Rows;
	
	If(!Is Empty(cur_rows),
		visible_parameters = Associative Array(dt[cur_rows, "Parameter"]) << get keys;
	, // else, this wasn't solved
		visible_parameters = all_params;
	);
  	
	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(visible_parameters),
		Return(0); // some problem
	);
	
	gb << inval;
	For Each({param_val, idx}, visible_parameters, 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());

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

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))),
	SendToReport(Dispatch({}, "graph title", TextEditBox, {Set Text("Trend Chart")}))
);

filter_ref = gb << Local Data Filter(
	Conditional,
	Add Filter(
		columns(:TestDate, :Has Limits?, :TestStage, :Parameter),
		Where( :Has Limits? == "Yes" ),
		Where( :TestStage == "STG5" ),
	)
);

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

filter_ref = (Report(gb) << top parent)[OutlineBox("Local Data Filter")] << Get Scriptable Object;

update_title = Function({this},
	gb << inval;
	
	page_texts = Report(gb) << XPath("//GraphBuilderGroupBox/text()"); // Not sure if this can be used in JMP16
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs = tebs[4 :: N Items(tebs) :: 2]; // skip title, subtitle and xaxis?

	For Each({page_text, idx}, page_texts,
		y_tebs[idx] << Set Text(Word(-1, page_text, "="));
	);
	
	gb << update window;
	wait(0);
	
	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

View solution in original post

30 REPLIES 30
jthi
Super User

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

You could try to make your XPath query more accurate (explore the XML and property tree). Something like this might work

Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox[text()='Median']")
-Jarmo
Neo
Neo
Level VI

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

@jthi This partly works, but all selected Parameters are appearing as Y-axis title in all the plotted charts under each other.

I changed 

 

(Report( gb ) << XPath( "//TextEditBox" ))[6] << Set Text(ldfText);

to 

 

 

(Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox[text()='Median']")) << Set Text(ldfText);

and get

 

Neo_1-1706797579178.png

Need only the plotted Parameter name as Y-axis title on each chart. 

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?

One option would be to parse the get where clause

  	ldfText = Regex(ldf << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");

into separate items and loop over those and set the titles in the loop.

 

Edit:

This will require a bit modification also to the part where you get references to text edit boxes for y-axis. Below is one option which might work

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" )} ) )
);

update_title = Function( {this},
  	param_where = Regex(local_filter << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");
  	param_where_list = Words(param_where, "|");
  	
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs= tebs[4::N Items(tebs)::2];

	If(N Items(y_tebs) != N Items(param_where_list),
		return(); // some problem
	);
  	For Each({where_str, idx}, param_where_list,
  		title = Trim Whitespace(Word(-1, where_str, "="));
  		Substitute Into(title, "\!"", "");
		y_tebs[idx] << Set Text(title);
  	);
	
);


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

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 This works except the initial chart (before filter change handler kids in) still has Median as y-axis title. Any way to fix this?

Neo_0-1706800220954.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?

Trigger the function once before you create the filter change handler

update_title(local_filter);

jthi_0-1706800507842.png

 

-Jarmo
Neo
Neo
Level VI

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

@jthi Ok. Noted the trigger. The script does not work if I have an underscore in my Parameter name (I have got few underscores in the parameters names in my actual data). Example data table attached with underscore in Parameter name. The script below throws an error on the Words function with the attached data table.

Also had to comment the Size() without which the initial charts looked strange. 

Names Default To Here (1);
clear log ();
dt = Current Data Table();
gb = dt << Graph Builder(
	//Size( 531, 525 ),
	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_1", "Capacitance_1"} )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "myTitleGoesHere" )} ) )
);

update_title = Function( {this},
  	param_where = Regex(local_filter << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");
  	param_where_list = Words(param_where, "|");
  	
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs= tebs[4::N Items(tebs)::2];

	If(N Items(y_tebs) != N Items(param_where_list),
		return(); 
	);
  	For Each({where_str, idx}, param_where_list,
  		title = Trim Whitespace(Word(-1, where_str, "="));
  		Substitute Into(title, "\!"", "");
		y_tebs[idx] << Set Text(title);
  	);
	
);

local_filter = Current Report()["Local Data Filter"] << get scriptable object;
update_title(local_filter);
filter_handler = local_filter << Make Filter Change Handler(update_title());
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?

Issue is most likely that you have Multiple Response column as you Parameter

jthi_0-1706806005807.png

jthi_1-1706806020681.png

 

-Jarmo
Neo
Neo
Level VI

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

@jthi Thanks, Removing Multiple Response from Parameter properties does make the script work for the example data (exampleSummaryTable2). But I am still having problems with my actual data set where there are no columns with Multiple Response set (unfortunately cannot share actual data). What else could it be?

Neo_0-1706807048204.png

 

I can also reproduce this same error if I use comment out this in the script 

//Where( :Parameter == {"BKDVoltage_1", "Capacitance_1"}

as in 

Names Default To Here (1);
clear log ();
dt = Current Data Table();
gb = dt << Graph Builder(
	Size( 531, 525 ),
	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_1", "Capacitance_1"} )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "myTitleGoesHere" )} ) )
);

update_title = Function( {this},
  	param_where = Regex(local_filter << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");
  	param_where_list = Words(param_where, "|");
  	
	tebs = Report(gb) << XPath("//GraphBuilderTitleBox/TextEditBox");
	y_tebs= tebs[4::N Items(tebs)::2]; //show (y_tebs);

	If(N Items(y_tebs) != N Items(param_where_list),
		return(); 
	);
  	For Each({where_str, idx}, param_where_list,
  		title = Trim Whitespace(Word(-1, where_str, "="));
  		Substitute Into(title, "\!"", "");
		y_tebs[idx] << Set Text(title);
  	);
	
);

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

In my actual data case, I do not have the luxury to pre-select one or more parameters via the Local Data Filter. Perhaps this is what is causing the issue in the actual data case. Any way to get around this?

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 isn't returning what it is supposed to

  	param_where = Regex(local_filter << get where clause(),"\(?\s*(:Parameter == .*?)\)","\1");

One reason could be that you have no values selected in local data filter. You could add additional check for missing values and if param_where is missing, return early from the function without doing nothing (or rather then you have all values as parameters and you have to get the parameter values some other way)

-Jarmo