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

Manipulate local data filter from JSL

Given a list of values I want to write these to the limits of a local data filter. Here is a (almost) working example (remove data filter and re-add based on building the data filter expression dynamically) but it feels to complicated, is this the best way to do it? (It has to work dynamically for other tables with different number of columns as well)

 

dt = Open("$SAMPLE_DATA\Fitness 3D.jmp");
sm = dt << Scatterplot Matrix(
	Y( :Runtime, :RstPulse, :RunPulse, :MaxPulse ),
	X( :Age, :Weight, :Oxy ),
	Fit Line( 0 ),
	Local Data Filter( Add Filter( columns( :Age, :Weight, :Oxy ) ) )
);

ColExp = expr(columns( :Age, :Weight, :Oxy ));

//Modify this expression based on list values
AndExp = expr(Where(:Age >=0 & :Age <=100));

sm << Remove Local Data Filter;
Eval(
	Insert(
		Expr( Send( sm ) ),
		Insert(
			Expr( Local Data Filter() ), 
			Insert(
				insert(
					expr(Add filter()),
					name expr(ColExp)
				), 
				//name expr(WhereExp)
				insert(
					expr(Where()),
					name expr(AndExp)
				) 
			)
		)
	)
);

For a stretch goal I would like to also append a button that on press reads the current limits from the local data filter into a list or matrix.

4 REPLIES 4

Re: Manipulate local data filter from JSL

This example is for the (global) Data Filter, but it illustrates how you can add a Where() argument to set up limits the way you want. That is to say that you can specify the constraint when you open the filter.

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
obj = dt << Data Filter();
obj << Add Filter( columns( :POP ) );
obj << Add Filter(
	columns( :Region, :State, :City ),
	Where( :Region == "S" ),
	Where( :State == {"SC", "NC"} )
);
jthi
Super User

Re: Manipulate local data filter from JSL

Using Substitute might be a bit cleaner option here.

dt = Open("$SAMPLE_DATA\Fitness 3D.jmp");
sm = dt << Scatterplot Matrix(
	Y(:Runtime, :RstPulse, :RunPulse, :MaxPulse),
	X(:Age, :Weight, :Oxy),
	Fit Line(0),
	f = Local Data Filter(Add Filter(columns(:Age, :Weight, :Oxy)))
);

ColExp = Expr(
	columns(:Age, :Weight, :Oxy)
);

AndExp = Expr(
	Where(:Age >= 0 & :Age <= 50)
);

Eval(Substitute(
	sm << Remove Local Data Filter;
	Expr(
		f = sm << Local Data Filter(
			_cols_,
			_where_
		)
	),
	Expr(_cols_), Name Expr(ColExp),
	Expr(_where_), Name Expr(AndExp)
));

// You can try to parse this for local data filter limits
w = f << Get where clause;
show(w);

For limits you could parse the where clause or maybe access the DFIntMinMaxBox and NumberEditBoxes inside it (I would try to parse Where clause). There might also be other methods for this (Show Properties(f) might have some ideas).

jthi_0-1651772922347.png

 

-Jarmo
pauldeen
Level VI

Re: Manipulate local data filter from JSL

Ok thanks for confirming that I am not missing a much simpeler option (like f[1] << set limit(1, 2);) or something. Expression manipulation it shall be then

And yes for the button I will probably use xpath to extract all the numbereditboxes and from the order I can infer their meaning. I just wanted to make sure you couldn't directly querry the local data filter to tell you the limits.

 

Re: Manipulate local data filter from JSL

One thing to keep in mind is that the continuous filter Where() clause can take several different forms, depending on the limits, the Invert Selection setting, and the Include Min/Max settings.  This won't matter so much for setting the where clause, but since you mention reading the current limits, you might see expressions like:

Select Where( :Age <= 42 | :Age > 55 | Is Missing( :Age ) );