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

Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

I use the following to display "my text" at the top of my charts.

Dispatch( {}, "graph title", TextEditBox, {Set Text( "my text" )} )

However, I would like to have the item(s) selected in the local data filter to be displayed in the graph title as I select them (perhaps multiple sections as comma delimited?).

How to achieve this in JSL?

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

try this - works for both versions:

(:age == 14 );
( :age == 14 )

 

 

 

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

gb = Graph Builder(
	Size( 570, 518 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age, :weight ),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ) )
);

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

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),"\( *(:age == .*?)\)","\1");
	(Report( gb ) << XPath( "//TextEditBox" ))[1] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);

 

edit: final (?) version
https://community.jmp.com/t5/Discussions/Is-it-possible-to-dynamically-update-quot-graph-title-quot-... 

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

View solution in original post

21 REPLIES 21
txnelson
Super User

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

The approach you can take is to add to the Local Data Filter, a Change Handler (Make Filter Change Handler), that when the filter changes, it captures the Where Clause(Get where clause) and then takes that result and applies it to the Title in the Graph's title(set text).

The documentation on how to manipulate the output can be found in the Scripting Guide section on Display Trees.  This documentation is available in the JMP Documentation Library, available under the Help pull down menu.

Jim
hogi
Level XI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

Something like this:

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

gb = Graph Builder(

	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter( Conditional, Add Filter( columns( :age ) ) )
);

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

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),"Select Where\((.+)\)","\1");
	(Report( gb ) << XPath( "//TextEditBox" ))[1] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);


edit:
final (?) version tackling special more cases of Where clauses:

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

:



Neo
Neo
Level VI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

@hogi  Thanks. This will work but I have more than one data filters panel and I want to have the title changed based on only one of them (You script appears to capture all changes in any of the local data filter panels).

How to capture changes in a specific local data filter panel?

 

When it's too good to be true, it's neither
hogi
Level XI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

If there are several data filters in the same report, to get the correct one, you could start from the respective GaphBuilder object, go one step up and search for the Data Filter:

 

ldf = (gb  << parent)["Local Data Filter"] << get scriptable object;

 

 

full code:

 

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

New window("test",
H List Box(

gb1 = Graph Builder(
	Show Control Panel( 0 ),
	Local Data Filter( Conditional, Add Filter( columns( :age ) ) )
),
gb = Graph Builder(

	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter( Conditional, Add Filter( columns( :age ) ) )
)));

ldf = (gb  << parent)["Local Data Filter"] << get scriptable object;

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),"Select Where\((.+)\)","\1");
	(Report( gb ) << XPath( "//TextEditBox" ))[1] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);

 

 

Alternatives which are less robust:

ldf = (current report() << XPath("(//OutlineBox[text()='Local Data Filter'])"))[2] << get scriptable object;

ldf = current report()[OutlineBox(3)]<< get scriptable object;

 

 

Neo
Neo
Level VI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

@hogi Thanks for your suggestions. I tried your second less robust option but I can see that it is not very robust as you say and I could not get it to work properly. 

In the following script, if I want to show only the "age" selection on the chart tile, how to script it?

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

Graph Builder(
	Size( 570, 518 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age, :weight ),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ) )
);

 

When it's too good to be true, it's neither
hogi
Level XI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

Sorry, for the misunderstanding.
If there is just a single Data Filter in the report, there is no need to specify the reference more precisely.
 
On the other hand:
If you want to restrict the title to some part of the Where Clause, you need another Regex expression like the one below.
It searches for any :age ==  within round brackets and returns the whole string within the brackets.
So, For cases like

"Select Where( (:age == 14 | :age == 15) & :weight >= 113.5 )";
"Select Where(:age == 14 | :age == 16 | :age == 17 )"

it will just return the :age ... part.

 

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

gb = Graph Builder(
	Size( 570, 518 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age, :weight ),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ) )
);

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

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),".*\((:age == .*?)\).*","\1");
	(Report( gb ) << XPath( "//TextEditBox" ))[1] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);
Neo
Neo
Level VI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

@hogi . Your script below does not show or change the chart title for me in JMP 16.2.0. 

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

gb = Graph Builder(
	Size( 570, 518 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age, :weight ),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ) )
);

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

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),".*\((:age == .*?)\).*","\1");
	(Report( gb ) << XPath( "//TextEditBox" ))[1] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);

 

When it's too good to be true, it's neither
hogi
Level XI

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

try this - works for both versions:

(:age == 14 );
( :age == 14 )

 

 

 

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

gb = Graph Builder(
	Size( 570, 518 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
	Local Data Filter(
		Conditional,
		Add Filter(
			columns( :sex, :age, :weight ),
			Display( :sex, "Check Box Display" ),
			Display( :age, "Check Box Display" )
		)
	),
	SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "" )} ) )
);

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

changeTitle = Function( {this},
	print(this);
	ldfText = Regex(ldf << get where clause(),"\( *(:age == .*?)\)","\1");
	(Report( gb ) << XPath( "//TextEditBox" ))[1] << Set Text( ldfText );
);
fsh = ldf << Make Filter Change Handler(
	changeTitle();
);

 

edit: final (?) version
https://community.jmp.com/t5/Discussions/Is-it-possible-to-dynamically-update-quot-graph-title-quot-... 

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

Re: Is it possible to dynamically update "graph title" based item selection in local data filter (including multiple selections)?

Nice regex!

The parentheses are being used in two clever ways:

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

At the beginning and end of the pattern, the backslash character is escaping a parenthesis, \(...\) so it matches a literal parenthesis in the where clause. The space followed by asterisk matches zero or more spaces.

The inner pair of parentheses look like they would be matching the actual parentheses in the where clause, but no! The actual parentheses were already matched. These inner parentheses are grouping parentheses, and they form the first group in the match.

Within the grouping parentheses, the literal characters :age ==   are matched, then .*? matches characters, one at a time, until that final, escaped, literal parenthesis can be matched. The . matches anything, the * means 0 or more, and the ? changes the 0 or more from greedy (race to the end) to reluctant (one at a time). The reluctant behavior makes sure the first parenthesis is used.

Finally, the "\1" is used to format a result: everything the first set of grouping parentheses matched.

 

Craige