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
JanneI
Level III

Check Box to toggle jitter on/off on Graph Builder

Hello,

I would like to have a check box object on top of Graph builder view to toggle on/off separation of overlapping points (jitter). I know that this can be done from control panel but from visualization perspective, I want to keep the control panel closed.

 

Example script below which creates control elements for jitter on top of graph. Despite of my best efforts, I can't get the check box to toggle the jitter; I don't know what is the correct way to send update to report.

 

I am requesting Your help with the syntax. 

 

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

gb=Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ) ),
	Elements(
		Points( X, Y )
	)
);

jitter = 1;
jitter_elements=H List Box(
		cb=Check Box(
			{"Jitter enabled"},
			If(cb<<Get()==1,
				gb << SendToReport(Elements(Points(Jitter( "Positive Grid" ), Jitter Limit( jitter )))), // This is not correct but something like this (maybe)
				gb << SendToReport(Elements(Points(Jitter( "None" ))))									 // This is not correct but something like this (maybe)
			);		
		),
		
		sb = Slider Box( 0, 2, jitter, 
			neb << set( jitter );
		), 
	   
		neb = Number Edit Box(jitter, 
			<<setfunction(
				Function( {this}, 
					jitter = this << get; 
					sb << inval;
				)
			)
		)			
);

rgb = Report(gb);
(( rgb[PictureBox(1)] << Parent ) << Child ) << Sib Append (jitter_elements);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Check Box to toggle jitter on/off on Graph Builder

Manipulating Elements is a mess to my knowledge and it gets even messier when you have grouping. That's why I try to (usually) avoid it and just redo the graph. Here is one way you could try using Update Elements to change Jitter

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

jitter = 1;
New Window("",
	V List Box(
		H List Box(
			cb = Check Box(
				{"Jitter enabled"},
				If(cb << Get() == 1,
					Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("Positive Grid"), Jitter Limit(jitter)});
				,
					Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("None")});
				)
			),
			sb = Slider Box(0, 2, jitter, neb << set(jitter)), 
			   
			neb = Number Edit Box(
				jitter,
				<<setfunction(
					Function({this},
						jitter = this << get;
						sb << inval;
					)
				)
			)
		),
		gb = dt << Graph Builder(Show Control Panel(1), Variables(X(:height), Y(:weight)), Elements(Points(X, Y)));	
	)
);

Other useful functions might be Add Elements and Remove Elements, also see this post Updating the Graph Builder's Element statement 

-Jarmo

View solution in original post

3 REPLIES 3
Craige_Hales
Super User

Re: Check Box to toggle jitter on/off on Graph Builder

Nice idea, not obvious how to do it, looking forward to an answer.

Craige
jthi
Super User

Re: Check Box to toggle jitter on/off on Graph Builder

Manipulating Elements is a mess to my knowledge and it gets even messier when you have grouping. That's why I try to (usually) avoid it and just redo the graph. Here is one way you could try using Update Elements to change Jitter

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

jitter = 1;
New Window("",
	V List Box(
		H List Box(
			cb = Check Box(
				{"Jitter enabled"},
				If(cb << Get() == 1,
					Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("Positive Grid"), Jitter Limit(jitter)});
				,
					Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("None")});
				)
			),
			sb = Slider Box(0, 2, jitter, neb << set(jitter)), 
			   
			neb = Number Edit Box(
				jitter,
				<<setfunction(
					Function({this},
						jitter = this << get;
						sb << inval;
					)
				)
			)
		),
		gb = dt << Graph Builder(Show Control Panel(1), Variables(X(:height), Y(:weight)), Elements(Points(X, Y)));	
	)
);

Other useful functions might be Add Elements and Remove Elements, also see this post Updating the Graph Builder's Element statement 

-Jarmo
JanneI
Level III

Re: Check Box to toggle jitter on/off on Graph Builder

Thanks Jarmo,

 

Your solution (Update elements) works well, very good.

 

Below is further modified version to get also the slider and number boxes updating the graph.

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

jitter = 0.2;
New Window("",
	V List Box(
		H List Box(
			cb = Check Box(
				{"Jitter enabled"},
				If(cb << Get() == 1,
					Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("Positive Grid"), Jitter Limit(jitter)});
				,
					Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("None")});
				)
			),
			sb = Slider Box(0.1, 0.2, jitter,
					neb << set(jitter);
					If(cb << Get() == 1,
						Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("Positive Grid"), Jitter Limit(jitter)});
					);
				), 
			   
			neb = Number Edit Box(
				jitter,
				<<setfunction(
					Function({this},
						jitter = this << get;
						if(jitter<0.1, jitter=0.1,  jitter>0.2, jitter=0.2);						
						sb << inval;
						If(cb << Get() == 1,
							Report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), X, Y, Legend(3), Jitter("Positive Grid"), Jitter Limit(jitter)});
						);
						neb << set(jitter);
					)
				)
			)
		),
		gb = dt << Graph Builder(Show Control Panel(0), Variables(X(:height), Y(:weight)), Elements(Points(X, Y)));	
	)
);