cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
] />

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
SDF1
Super User

Help with relative positions of custom "legend"

Hello JSL Scripters,

  I'm working on a script, where I am adding my own "legend" to a graph. See screenshot below.

SDF1_1-1777315738647.png

 

  I've added the lines and text by right clicking in the graph Customize...> and then adding a Script to the graph. The following JSL generates the "legend" as shown above.

Pen Color( "Red" );
Pen Size( 2 );
Line Style( "Solid" );
Line( [20, 100], [65, 65] );
Text( {120, 64}, "Weight" );
Pen Color( "Blue" );
Pen Size( 2 );
Line( [20, 100], [60, 60] );
Text( {120, 59}, "Height" );

  But, what I'm really after is how to make the positions of the legend lines and text relative to, e.g. 90% the maximum value in the column :"Weight diff [g]"n. Data table is attached as well with script (non working script is commented out). I thought I could do it with something like an Eval(Substitute(Expr(...), Expr(__pos__), pos) type of JSL, but I keep getting the "Invalid Matrix Token" error. With something like the following:

Names Default To Here( 1 );

pos = Col Max( :"Weight diff[g]"n );

Eval(
	Substitute(
			Expr(
				Graph Builder(
					Size( 510, 510 ),
					Show Legend( 0 ),
					Graph Spacing( 4 ),
					Variables(
						X( :"MeasTime [s]"n ),
						Y( :"Weight diff [g]"n ),
						Y( :"Height diff [mm]"n, Position( 1 ), Side( "Right" ) )
					),
					Elements( Line( X, Y( 1 ), Legend( 5 ) ), Line( X, Y( 2 ), Legend( 6 ) ) ),
					SendToReport(
						Dispatch( {}, "MeasTime [s]", ScaleBox, {Inc( 100 )} ),
						Dispatch( {}, "Graph Builder", FrameBox,
							{Add Graphics Script(
								5,
								Description( "" ),
								Pen Color( "Red" );
								Pen Size( 2 );
								Line Style( "Solid" );
								Line( [20, 100], [__pos__, __pos__] );
								Text( {120, 64}, "Weight" );
								Pen Color( "Blue" );
								Pen Size( 2 );
								Line( [20, 100], [60, 60] );
								Text( {120, 59}, "Height" );
							)}
						)
					)
				)
			),
		Expr( __pos__ ), Eval( Round( 0.9 * pos, 0 ) )
	)
);

  I've even tried wrapping the y-coordinates of the Line() in "{ }", like: Line( [20, 100],[{_pos__,__pos__}]), and I still get the same error. I'd prefer to use a variable like "pos", that I get from a column rather than have it as an absolute value because the column values can change and I need the graph objects like the line and text to be able to move relative to what's being graphed.

  Any suggestions on how to get around this error and/or what I'm missing -- this approach should work, but I'm just not catching why.

Thanks!,

DS

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Help with relative positions of custom "legend"

Y Range() and Y Origin() are most likely what you need.

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Help with relative positions of custom "legend"

Y Range() and Y Origin() are most likely what you need.

-Jarmo
SDF1
Super User

Re: Help with relative positions of custom "legend"

Hi @jthi ,

  Thanks for the hint! With a minor modification, that helped out a lot and got me exactly what I needed, thanks!

Thank for the quick reply, too!,

DS

SDF1
Super User

Re: Help with relative positions of custom "legend"

In case other readers are interested, I modified the JSL code (see below) to:

Names Default To Here( 1 );

x1=300;
y2=36.7;

Graph Builder(
	Size( 510, 510 ),
	Show Legend( 0 ),
	Graph Spacing( 4 ),
	Variables( X( :"MeasTime [s]"n ), Y( :"Weight diff [g]"n ), Y( :"Height diff [mm]"n, Position( 1 ), Side( "Right" ) ) ),
	Elements( Line( X, Y( 1 ), Legend( 5 ) ), Line( X, Y( 2 ), Legend( 6 ) ) ),
	SendToReport(
		Dispatch( {}, "MeasTime [s]", ScaleBox, {Inc( 100 )} ),
		Dispatch( {}, "Graph Builder", FrameBox,
			{Add Graphics Script(
				5,
				Description( "" ),
				Pen Color( "Black" );
				Line Style( "Dashed" );
				Line( {x1,YOrigin()}, {x1,y2}, {XOrigin(),y2}, {x1,y2} );
				Pen Color( "Red" );
				Pen Size( 2 );
				Line Style( "Solid" );
				Line( {XOrigin()+30, 0.9*YRange()}, {XOrigin()+130, 0.9*YRange()} );
				Text( {XOrigin()+150, 0.9*YRange()-1}, "Weight" );
				Pen Color( "Blue" );
				Pen Size( 2 );
				Line( {XOrigin()+30, 0.85*YRange()}, {XOrigin()+130, 0.85*YRange()} );
				Text( {XOrigin()+150, 0.85*YRange()-1}, "Height" );
			)}
		)
	)
);

Which makes the following output:

SDF1_0-1777379422260.png

Which are demonstrations of exactly what I was looking to do -- create relative "legends" and specific reference lines that don't go across the entire length/height of the graph.

  Hopefully this can help others looking to do something similar.

Hope this helps others!,

DS

jthi
Super User

Re: Help with relative positions of custom "legend"

You might want to evaluate the x1 and y2 to the graphic script to avoid all sorts of possibly annoying issues.

View more...
Names Default To Here(1);

x1 = 300;
y2 = 36.7;

dt = Current Data Table();
gb = Eval(Substitute(
		Expr(dt << Graph Builder(
			Size(510, 510),
			Show Legend(0),
			Graph Spacing(4),
			Variables(X(:"MeasTime [s]"n), Y(:"Weight diff [g]"n), Y(:"Height diff [mm]"n, Position(1), Side("Right"))),
			Elements(Line(X, Y(1), Legend(5)), Line(X, Y(2), Legend(6))),
			SendToReport(
				Dispatch({}, "MeasTime [s]", ScaleBox, {Inc(100)}),
				Dispatch({}, "Graph Builder", FrameBox,
					{Add Graphics Script(
						5,
						Description(""),
						Pen Color("Black");
						Line Style("Dashed");
						Line({_x1_, Y Origin()}, {_x1_, _y2_}, {X Origin(), _y2_}, {_x1_, _y2_});
						Pen Color("Red");
						Pen Size(2);
						Line Style("Solid");
						Line({X Origin() + 30, 0.9 * Y Range()}, {X Origin() + 130, 0.9 * Y Range()});
						Text({X Origin() + 150, 0.9 * Y Range() - 1}, "Weight");
						Pen Color("Blue");
						Pen Size(2);
						Line({X Origin() + 30, 0.85 * Y Range()}, {X Origin() + 130, 0.85 * Y Range()});
						Text({X Origin() + 150, 0.85 * Y Range() - 1}, "Height");
					)}
				)
			)
		)),
		Expr(_x1_), x1,
		Expr(_y2_), y2
	)
);
-Jarmo

Recommended Articles