cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.

JSL > Graphic script > Polygon > Dynamically assign coordinates

Thierry_S
Super User

Hi JMP community,

 

In a simple script I'm currently developing,  I would like to draw a rectangle polygon in Graphic Script applied to a GraphBuilder FrameBox with dynamic coordinates in function of the the axis scale (i.e. Polygon ([X1, X1, X2, X2], [Y1, Y2, Y2, Y1]). While I can easily achieve this with "hard coded" numerical coordinates for the polygon, and I can easily dynamically calculate the values of X1, X2, Y1, and Y2; I have not been able to determine the proper syntax in my script to update dynamically these coordinates: the script below does not work because of the incorrect handling of the coordinate vector.

Names Default to Here (1);

dt1 = Data Table ("TABLE1.JMP");
dt2 = Data Table ("TABLE2.JMP");

CList = dt1 << get column Names (string);


gbe = Expr (dt1 << Graph Builder(
					Size( 838, 494 ),
					Variables(
						X( :COLUMNX ),
						Y( _YS_ ),
						Group X( :COLUMNSPLIT )
					),
					Elements(
						Points( X, Y, Legend( 4 ) ),
						Line Of Fit( X, Y, Legend( 6 ) ),
						Ellipse( X, Y, Legend( 7 ) )
					),
					SendToReport(
						Dispatch(
							{},
							"Graph Builder",
							FrameBox,
							{Left( 1 ), Right( 1 ), Top( 1 ), Bottom( 1 ),
							Add Graphics Script(
								2,
								Description( "Script" ),
								Fill Color( "white" );
								Transparency( 0.6 );
								Polygon( [-1, -1, 4.5, 4.5], _YVECTOR_ );
								Transparency( 1 );
								Text Size( 14 );
								Text color ("black");
								Text( right Justified, {4, _TPY1_}, _R1_ );
								Text Color (_TXTC1_);
								Text( right Justified, {4, _TPY2_}, _P1_ );
							), Grid Line Order( 1 ), Reference Line Order( 3 )}
						),
						Dispatch(
							{},
							"Graph Builder",
							FrameBox( 2 ),
							{Left( 1 ), Right( 1 ), Top( 1 ), Bottom( 1 ),
							Add Graphics Script(
								2,
								Description( "Script" ),
								Fill Color( "white" );
								Transparency( 0.6 );
								Polygon( [-1, -1, 4.5, 4.5], _YVECTOR_ );
								Transparency( 1 );
								Text Size( 14 );
								Text color ("black");
								Text( right Justified, {4, _TPY1_}, _R2_ );
								Text Color (_TXTC2_);
								Text( right Justified, {4, _TPY2_}, _P2_ );
							), Grid Line Order( 1 ), Reference Line Order( 3 )}
						)
					)
				)
			);	


For (i = 10, i <= 13, i++,            //101
		
		YCOL = Column (dt1, i);
		
		if (Column (dt2, 6) [i-9]<= 0.05, TEXTCOL1 = "red", TEXTCOL1 = "black");
		if (Column (dt2, 7) [i-9]<= 0.05, TEXTCOL2 = "red", TEXTCOL2 = "black");
			
		PVAL1 = "BH p: "||  CHAR(format(Column (dt2, 6) [i-9],"PValue"));
		PVAL2 = "BH p: "||  CHAR(format(Column (dt2, 7) [i-9],"PValue"));
		R1 = "r: "||  CHAR(format(Column (dt2, 4) [i-9],"Fixed Dec",6,3));
		R2 = "r: "||  CHAR(format(Column (dt2, 5) [i-9],"Fixed Dec",6,3));
		
		gbx = substitute(Name Expr (gbe), 	Expr (_YS_), YCOL,
											Expr (_TPY1_), 1,
											Expr (_TPY2_), 0.6,
											Expr (__YVECTOR_),[1,0.5,0.5,1],
											Expr (_TXTC1_), TEXTCOL1,
											Expr (_TXTC2_), TEXTCOL2,
											Expr (_P1_), PVAL1,
											Expr (_P2_), PVAL2,
											Expr (_R1_), R1,
											Expr (_R2_), R2
			);
			
		gb = Eval (gbx);
		
		gbr = gb << report;
		
		Yaxis = gbr [Axis Box (2)];
		YMax = YAxis << Get Max;
		YMin = YAxis << Get Min;
		
		gbr << close window;
		
		YRange = ABS (YMax - YMin);
		
		While (YRange <= 2,
			
			YMax = YMax + (YRange * 0.2);
			YMin = YMin - (YRange * 0.2);
			YRange = abs (YMax - YMin);
		);
		
		TOPY1 = YMax - (YRange * 0.05);
		TOPY2 = YMax - (YRange * 0.10);
		
		POLY1 = YMax;
		POLY2 = YMax - (YRange * 0.15);
		
		POLYVECT = eval list ([POLY1, POLY2, POLY2, POLY1];

		
		gbx = substitute(Name Expr (gbe), 	Expr (_YS_), YCOL,
											Expr (_TPY1_), TOPY1,
											Expr (_TPY2_), TOPY2,
											Expr (_YVECTOR_), POLYVECT,
											Expr (_TXTC1_), TEXTCOL1,
											Expr (_TXTC2_), TEXTCOL2,
											Expr (_P1_), PVAL1,
											Expr (_P2_), PVAL2,
											Expr (_R1_), R1,
											Expr (_R2_), R2
			);
			
		gb = Eval (gbx);
		
		gbr = gb << report;
		
		Yaxis = gbr [Axis Box (2)];
		
		Yaxis << Max (YMax);
		Yaxis << Min (YMin);
		Yaxis << Inc (round (YRange/9, 1));
		
		gbr << Set Title (CList [i]);
		
		gbr << Journal;
		gbr << close window;
		
	);	

 

Thank you for your help.

Best,

TS 

Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions
Thierry_S
Super User

Re: JSL > Graphic script > Polygon > Dynamically assign coordinates

After digging a bit more, I realized that I needed to use the List format for the polygon (i.e. Polygon ({x1,y1}, {x1,y2}, {x2,y2}, {x2,y1}) coordinates and not the Matrix format

Best,
TS
Thierry R. Sornasse

View solution in original post

1 REPLY 1
Thierry_S
Super User

Re: JSL > Graphic script > Polygon > Dynamically assign coordinates

After digging a bit more, I realized that I needed to use the List format for the polygon (i.e. Polygon ({x1,y1}, {x1,y2}, {x2,y2}, {x2,y1}) coordinates and not the Matrix format

Best,
TS
Thierry R. Sornasse