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

Make Filter Change Handler () triggering only after second filter change, why not first?

I use the Make Filter Change Handler () to dynamically change the y-axis title based on changes made by the user on the local data filter. The script uses solution by @hogi from here. However, in my example case (script below) which represents my actual case closely, the y-axis title is changes only after the second checkbox is checked on "age". How to make the y-axis tile change upon the first age selection (I am on JMP 16.2.0)?

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb = Graph Builder(
	Size( 855, 687 ),
	Show Control Panel( 0 ),
	Variables( X( :name ), Y( :age ), Group Y( :height ) ),
	Elements( Points( X, Y, Legend( 37 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age ),
			Where( :sex == "F" ),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( 
	Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ), 
	Dispatch( {}, "Y title", TextEditBox, {Rotate Text( "Left" )} )	
	)
);

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

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),"\( *(:age == .*?)\)","\1");
	if(ismissing(ldfText),ldfText = "all ages");
	(Report( gb ) << XPath( "//TextEditBox" ))[4] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);
When it's too good to be true, it's neither
5 REPLIES 5
jthi
Super User

Re: Make Filter Change Handler () triggering only after second filter change, why not first?

The regex being used doesn't work if there is only one age selected and it will result in "all ages".

 

Where clause when only one age is selected

"Select Where(:sex == \!"F\!" & :age == 15)"

Where clause when more than one ages are selected:

"Select Where(:sex == \!"F\!" & (:age == 14 | :age == 15))"

You will have to make slight modifications to the regex pattern

 

Edit:

Something like this might work https://regex101.com/r/Z6pg9N/1

-Jarmo
Neo
Neo
Level VI

Re: Make Filter Change Handler () triggering only after second filter change, why not first?

@jthi The following appears to work for my example case above

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

However, for my actual case, the above script change works only when the default selected checkboxes by the Add Filter () inside Graph Builder() are first unchecked and then rechecked. Once it stats working, all if fine. What could be wrong?

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

Re: Make Filter Change Handler () triggering only after second filter change, why not first?

Most likely the first filter state is ran before filter state handler is even added. You could call changeTitle() with a reference to the local data filter to make sure the function is run once after graph has been created

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb = Graph Builder(
	Size( 855, 687 ),
	Show Control Panel( 0 ),
	Variables( X( :name ), Y( :age ), Group Y( :height ) ),
	Elements( Points( X, Y, Legend( 37 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age ),
			Where( :sex == "F" ),
			Where(:age == 12),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( 
	Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ), 
	Dispatch( {}, "Y title", TextEditBox, {Rotate Text( "Left" )} )	
	)
);

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

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

changeTitle(ldf); // to run the changeTitle() function once

fsh = ldf << Make Filter Change Handler(
	changeTitle();
);
-Jarmo
Neo
Neo
Level VI

Re: Make Filter Change Handler () triggering only after second filter change, why not first?

@jthi . Calling Change Title () as your script did not change anything. Unfortunately I cannot share my actual script (:.

Note the first time selection shows all the checked filters on the y-axis. Perhaps this may provide a hint as to what is going on.

Unchecking all checkboxes and checking them back as desired produces the expected result. 

Any suggestions will be very useful. 

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

Re: Make Filter Change Handler () triggering only after second filter change, why not first?

No idea. You will have to create some sort of mock-up which is able to replicate the issue to make debugging easier

-Jarmo