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

Display Box: Level?

Is the a command to get the level/depth (?) of a Display Box, i.e. the number ot parents to get to the top parent?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Display Box: Level?

Based on the scripting index the purpose of << Get Display Path isn't to provide you with a full path but rather "robust" expression (robust path).

XPath or recursive function might be be fairly easy to implement (no idea if this will always work, some platforms in JMP can be quite complicated and some elements might not be captured)

Names Default To Here(1);

nw = New Window("test", // 6
	Panel Box("1", // 5
		Panel Box("2", // 4
			Panel Box("3", // 3
				H List Box( // 2
					Spacer Box(100),
					Text Box("4"),
					V List Box( // 1
						Text Box("5"), 
						Spacer Box(Size(100, 100)), 
						tb = Text Box("6") // 0
					)
				)
			)
		)
	)
);

get_parents = function({elem, idx = 0}, 
	next_elem = elem << parent;
	If(Is Empty(next_elem),
		return(idx);
	);
	idx++;
	show(next_elem << class name);
	get_parents(next_elem, idx);
);

show(get_parents(tb)); // has also the headbox
parent_count = N Items(nw << XPath("//TextBox[text() = '6']/ancestor::*"));
-Jarmo

View solution in original post

8 REPLIES 8

Re: Display Box: Level?

How about using Get Display Path()? Get Display Path () gets a relatively expression to navigate between parent box and object. Ifyou want to count the number of parents to get to the top parent, try following jsl.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line );
rpt = Report( biv );
rootParent = rpt << Top Parent();
path_to_parent = rpt[number col Box( 9 )] << Get Display Path( rootParent, Mode( "Subscript" ) ); 
count = N Items( Words( Char( Eval Expr( path_to_parent ) ), "," ) );
hogi
Level XI

Re: Display Box: Level?

I had the same idea
But it seems that sometimes Get Display Path doesn't go step by step:

 

New window("test",Panel Box("1",Panel box("2",PanelBox("3",HList Box(Spacer Box(100),Text Box("4"),V List Box(Text Box("5"),Spacer Box(Size(100,100)),tb=Text Box("6")))))));
rootParent = tb << Top Parent();
path_to_parent = tb << Get Display Path( rootParent, Mode( "Subscript" ) ); 
count = N Items( Words( Char( Eval Expr( path_to_parent ) ), "," ) );

 

jthi
Super User

Re: Display Box: Level?

Based on the scripting index the purpose of << Get Display Path isn't to provide you with a full path but rather "robust" expression (robust path).

XPath or recursive function might be be fairly easy to implement (no idea if this will always work, some platforms in JMP can be quite complicated and some elements might not be captured)

Names Default To Here(1);

nw = New Window("test", // 6
	Panel Box("1", // 5
		Panel Box("2", // 4
			Panel Box("3", // 3
				H List Box( // 2
					Spacer Box(100),
					Text Box("4"),
					V List Box( // 1
						Text Box("5"), 
						Spacer Box(Size(100, 100)), 
						tb = Text Box("6") // 0
					)
				)
			)
		)
	)
);

get_parents = function({elem, idx = 0}, 
	next_elem = elem << parent;
	If(Is Empty(next_elem),
		return(idx);
	);
	idx++;
	show(next_elem << class name);
	get_parents(next_elem, idx);
);

show(get_parents(tb)); // has also the headbox
parent_count = N Items(nw << XPath("//TextBox[text() = '6']/ancestor::*"));
-Jarmo
hogi
Level XI

Re: Display Box: Level?

Thanks.

I just tried it with a slightly different tree and got a stack overflow.
Here the parent function doesn't climb up the tree?!

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Window( "test", 
H List Box( Panel Box(
 "", H List Box( Text Box( "Hallo" ), tb = Filter Col Selector() ) ) ) );


get_parents = Function( {elem, idx = 0},
	next_elem = elem << parent;
	If( Is Empty( next_elem ),
		Return( idx )
	);
	idx++;
	Print( idx );
	Show( next_elem << class name );
	get_parents( next_elem, idx );
);

Show( get_parents( tb ) );
jthi
Super User

Re: Display Box: Level?

If I would have to guess it reaches filter col selector and starts from beginning for some reason (Filter Col Selector is one of the buggiest and most annoying display boxes to work with in JMP in my opinion). XPath might still work but the query can be more annoying to build.

-Jarmo
hogi
Level XI

Re: Display Box: Level?

Ok,

let's see ...
Case TS-00034009

Re: Display Box: Level?

Thanks for reporting the issue! I can confirm that Development has received it and already made some improvements to the behavior of these display box messages for the next major release of JMP.

Re: Display Box: Level?

Thank you for your reply.
How about the following script? The script repeats the parent function until it reaches the top parent.

 

nw = New Window( "test",
	pb1 = Panel Box( "1",
		pb2 = Panel Box( "2",
			pb3 = Panel Box( "3",
				H List Box(
					Spacer Box( 100 ),
					tb4 = Text Box( "4" ),
					V List Box(
						tb5 = Text Box( "5" ),
						Spacer Box( Size( 100, 100 ) ),
						tb6 = Text Box( "6" )
					)
				)
			)
		)
	)
);

//count parent display box from target to top display box
count parent = Function( {nw, target, top}, //window, target display box, top display box
	top_parent = top;
	end = 0;
	current = target;
	displaybox_list = {};
	For( i = 1, And( end == 0, i < 100 ), i++,
		parent = current << parent();
		If( Is Empty( parent ),
			end = 1,
			current = parent;
			Insert Into( displaybox_list, current );
			If( top_parent == current,
				end = 1
			);
		);
	);
	Eval List( {i - 1, displaybox_list} );
);


{count, displaybox_list} = count parent( nw, tb6, pb1 );
show(count);