cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Evan_Morris
Level IV

Where Clause in graph loop

I have some code that is designed to build a report based on some filtering.  It will be fed two lists, the first will determine which materials get pulled (in this example that will be Gender_List), the second determining which properties get graphed (In this example that will be Property_List).   The idea being that there will be a loop through each Gender that will create a matrix of graphs for all selected properties.   There is also an over-arching, unfiltered graph at the top of the report

 

There are two ways to do this. 

 

The first with intrinsic where clauses in the graphs.  I've mostly gotten this to work, except that the Where clause ends up taking up a position in the line up box. Also for some reason in the mockup I have below I have a bug that I don't entirely understand (my full version does not have that bug, but would still be curious if someone knows how to fix it).  Here is the mockup code

 

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


Gender_List = {"M","F"};

age_list = {12,13,14,15};

Property_List = {"Age", "Height", "Weight"};

w= new window("test",

	VLB = V List Box ("A",
		dt<<Distribution( Nominal Distribution( Column( :age ) ) );
		
	);
	
	
	
);


for (j=1, j<= N Items (Gender_List), j++,

	VLB << Append (Text Box(Gender_List[j]);
	
	LB = LB = Lineup Box(n col (2), spacing(10));
	
	for (i = 1, i <= N Items (Property_List), i++,
	
	LB<<Append(
		gb = dt<< Distribution( Continuous Distribution( Column( Property_List[i] ) ),
					where (:Sex == Gender_List[j])
				
				)

		);
		
		VLB <<Append(LB)
		
	);
);
);

 

 

The second is with data filter context boxes that wrap each iteration of the loop of graphs.  That one I haven't been able to get to work.   If I can get the where version above to work I don't think I'll need to worry too much about the data filter context box/wrap.

 

Anyways, any thoughts on how to clean up the code above to remove those Where clauses from the line up box? 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Where Clause in graph loop

If you add @jthi code to the code I provided, it will give you what you want

flus.PNG

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

Gender_List = {"M", "F"};
age_list = {12, 13, 14, 15};
Property_List = {"Age", "Height", "Weight"};

w = New Window( "test", VLB = V List Box( Text Box( "A" ), dt << Distribution( Nominal Distribution( Column( :age ) ) ) ) );

For( j = 1, j <= N Items( Gender_List ), j++,
	VLB << Append( Text Box( Gender_List[j] ) );
	VLB << Append(
		LB = LB = Lineup Box( N Col( 2 ), spacing( 10 ),
			For( i = 1, i <= N Items( Property_List ), i++,
				gb = dt << Distribution( Continuous Distribution( Column( Property_List[i] ) ), where( :Sex == Gender_List[j] ) )
			)
		)
	);
);

whereTb = w << XPath("//TextBox[contains(text(), 'Where(:sex == Gender_List[j])')]");
whereTb << Delete;
Jim

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: Where Clause in graph loop

I reworked your script a bit.  You had some recursive Appends in your code that were not working.  See if this gets you what you want

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

Gender_List = {"M", "F"};
age_list = {12, 13, 14, 15};
Property_List = {"Age", "Height", "Weight"};

w = New Window( "test", VLB = V List Box( Text Box( "A" ), dt << Distribution( Nominal Distribution( Column( :age ) ) ) ) );

For( j = 1, j <= N Items( Gender_List ), j++,
	VLB << Append( Text Box( Gender_List[j] ) );
	VLB << Append(
		LB = LB = Lineup Box( N Col( 2 ), spacing( 10 ),
			For( i = 1, i <= N Items( Property_List ), i++,
				gb = dt << Distribution( Continuous Distribution( Column( Property_List[i] ) ), where( :Sex == Gender_List[j] ) )
			)
		)
	);
);
Jim
Evan_Morris
Level IV

Re: Where Clause in graph loop

Definitely a major improvement, but it looks like I still have that hanging "where( :Sex == Gender_List[j]" clause showing up in the lineup box. Any idea how to kill that?
jthi
Super User

Re: Where Clause in graph loop

You can remove them for example with this in the end of script:

 

whereTb = w << XPath("//TextBox[contains(text(), 'Where(:sex == Gender_List[j])')]");
whereTb << Delete;

But in this case I would guess it won't help because Lineup seems those Where textboxes as elements and the window gets messed up before you delete them.

 

-Jarmo
pauldeen
Level VI

Re: Where Clause in graph loop

How about this:

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

Gender_List = {"M", "F"};
age_list = {12, 13, 14, 15};
Property_List = {"Age", "Height", "Weight"};

w = New Window( "test", VLB = V List Box( Text Box( "A" ), dt << Distribution( Nominal Distribution( Column( :age ) ) ) ) );

For( j = 1, j <= N Items( Gender_List ), j++,
	VLB << Append( Text Box( Gender_List[j] ) );
	VLB << Append(
		LB = Lineup Box( N Col( 2 ), spacing( 10 ),
			For( i = 1, i <= N Items( Property_List ), i++,
				eval(substitute(
					expr(dt << Distribution( Continuous Distribution( Column( _col_ ) ), where( :Sex == _select_) )),
					expr(_col_),Property_List[i],
					expr(_select_), Gender_List[j]
				))
			);
		);
	);
);
Evan_Morris
Level IV

Re: Where Clause in graph loop

Still can't seem to figure out how to get rid of that "where" clause in the lineup box.  I switched it over to a graph builder object to see if header/footer preferences would remove it, but didn't seem to do it.  

 

I've tried to re-write this a data filter wrapping the LB.  That has some advantages anyways as it allows some customization by the user.  This seems to work, however, as you can see it looks a little wonky because the Data Filter is incredibly collapsed.  

 

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

Gender_List = {"M", "F"};
age_list = {12, 13, 14, 15};
Property_List = {"Age", "Height", "Weight"};

w = New Window( "test", VLB = V List Box( Text Box( "A" ), 

dt << Graph Builder(Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :age ) ),
	Elements( Histogram( X, Legend( 6 ) ) )
	)
	)
	
);

For( j = 1, j <= N Items( Gender_List ), j++,
	VLB << Append( Text Box( Gender_List[j] ) );
	VLB << Append(
		
		data filter context box(
		
		LB = LB = Lineup Box( N Col( 2 ), spacing( 10 ),
			For( i = 1, i <= N Items( Property_List ), i++,
			
				
				gb = dt << Graph Builder(
					Size( 534, 450 ),
					Show Control Panel(0 ),
					Variables( X(Column( Property_List[i] ) )),
					Elements( Histogram( X, Legend( 6 ) ) ),
					/*Where( :Sex == Gender_List[j] ) ),*/
			),
				
			)
		),
		
		dt<<Data Filter (local,
		add filter(
			columns(:sex),
			Where (:Sex == Gender_List[j])
		)
			
		)
		)
	);
);


 

I tried loading the data filter at the top of the LB but that did not seem to work.  

 

Any thoughts on how to clean this up?  This technically works but looks a little junky.

txnelson
Super User

Re: Where Clause in graph loop

If you add @jthi code to the code I provided, it will give you what you want

flus.PNG

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

Gender_List = {"M", "F"};
age_list = {12, 13, 14, 15};
Property_List = {"Age", "Height", "Weight"};

w = New Window( "test", VLB = V List Box( Text Box( "A" ), dt << Distribution( Nominal Distribution( Column( :age ) ) ) ) );

For( j = 1, j <= N Items( Gender_List ), j++,
	VLB << Append( Text Box( Gender_List[j] ) );
	VLB << Append(
		LB = LB = Lineup Box( N Col( 2 ), spacing( 10 ),
			For( i = 1, i <= N Items( Property_List ), i++,
				gb = dt << Distribution( Continuous Distribution( Column( Property_List[i] ) ), where( :Sex == Gender_List[j] ) )
			)
		)
	);
);

whereTb = w << XPath("//TextBox[contains(text(), 'Where(:sex == Gender_List[j])')]");
whereTb << Delete;
Jim
Evan_Morris
Level IV

Re: Where Clause in graph loop

Nice, thanks.  I tried putting it in the script and didn't get it to work but it looks like it was in the wrong location.  I'm also noticing some significant performance issues with the local data filter wrapping so I'm thinking this will be the route we want to go down. 


Thanks to all for the help on this one.

Evan_Morris
Level IV

Re: Where Clause in graph loop

In case anyone comes past this in the future, I was able to sort out the problem with the data filter version.  Problem was that the data filter context box needed to have a single object it was wrapping.  In the way I had presented it above the box wrapped both the Lineup Box and the Data Filter.  This resulted in the weird behavior.  By wrapping the LineupBox and the Data filter into the same object (an HListBox) that appeared to fix the problem:

 

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

Gender_List = {"M", "F"};
age_list = {12, 13, 14, 15};
Property_List = {"Age", "Height", "Weight"};

w = New Window( "test", VLB = V List Box( Text Box( "A" ), 

dt << Graph Builder(Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :age ) ),
	Elements( Histogram( X, Legend( 6 ) ) )
	)
	)
	
);

For( j = 1, j <= N Items( Gender_List ), j++,
	VLB << Append( Text Box( Gender_List[j] ) );
	VLB << Append(
		
		data filter context box(
		
		HLB = HlistBox(
		
		LB = Lineup Box( N Col( 2 ), spacing( 10 ),
			For( i = 1, i <= N Items( Property_List ), i++,
			
				
				gb = dt << Graph Builder(
					Size( 534, 450 ),
					Show Control Panel(0 ),
					Show Legend(0),
					Variables( X(Column( Property_List[i] ) )),
					Elements( Histogram( X, Legend( 6 ) ) ),
					/*Where( :Sex == Gender_List[j] ) ),*/
					SendToReport(
					Dispatch(
					{},
					"Graph Builder",
					OutlineBox,
					{Set Title( Property_List[i] ), Image Export Display( Normal )}
		)
	)
			),
				
			)
		),
		
		dt<<Data Filter (local,
		add filter(
			
			columns(:sex),
			Where (:Sex == Gender_List[j])
		)
			
		)
		)
		)
	);
);