cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
nathan-clark
Level VI

Graphics script to detect graph title

I would like to set up a custom graphics script so each graph gets a unique line based on information contained in an associative array. In the example below, I want to have a graph on the line differently for each category... for my actual use, I will need the graph to 'recognize' the heading it's under so I can use the correct values for the line creation.

 

For the example image below, I manually updated the "F" graphics script to be "F". So I am looking to find syntax to "gather the graph info" ... in my head, if I can grab the outline box title, I can manipulate that to get what I need... but I am not sure if that is the only/best option.

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

dt << Bivariate(
	Y( :height ),
	X( :weight ),
	By( :sex ),
	SendToReport(
		Dispatch(
			{},
			"1",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 30 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Add Graphics Script(
				2,
				Description( "" ),
				test = Associative Array( {{"F", {0.1, 50}}, {"M", {.8, 0}}} );
				///gather graph info to get "F" or "M" from output
				graphInfo = "M";// need to extract so it's "F" for female graph
				Y Function( test[graphInfo][1] * x + test[graphInfo][2], x );
			), Grid Line Order( 1 ), Reference Line Order( 3 )
			}
		)
	)
);
 

nathan-clark_1-1619112295335.png

 

11 REPLIES 11
txnelson
Super User

Re: Graphics script to detect graph title

Here are the modifications to your script that will update the titles

title.PNG

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

biv = dt << Bivariate(
	Y( :height ),
	X( :weight ),
	By( :sex ),
	SendToReport(
		Dispatch(
			{},
			"1",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 30 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Add Graphics Script(
				2,
				Description( "" ),
				test = Associative Array( {{"F", {0.1, 50}}, {"M", {.8, 0}}} );
				///gather graph info to get "F" or "M" from output
				graphInfo = "M";// need to extract so it's "F" for female graph
				Y Function( test[graphInfo][1] * x + test[graphInfo][2], x );
			), Grid Line Order( 1 ), Reference Line Order( 3 )}
		)
	)
);
For( i = 1, i <= N Items( biv ), i++,
	Report( biv[i] )[Outline Box( 1 )] << set title(
		Substr(
			Report( biv[i] )[Outline Box( 1 )] << get title,
			Contains( Report( biv[i] )[Outline Box( 1 )] << get title, "=" ) + 1
		)
	)
);
Jim
nathan-clark
Level VI

Re: Graphics script to detect graph title

I wasn't looking to update the title, but to grab the title information ... from within the Graphics Script. I can do all the string manipulation once I have the title information.

Ideally I need something to put within the graphics script which is like "graphTitle = graph << get title;" and go from there, but I am not sure that's possible unless the object "knows" which part of the tree it's contained within...

txnelson
Super User

Re: Graphics script to detect graph title

You will need to know which Outline Box you need to get the title from, but after that, it is a simple get title

graph title = report( biv[1] )[OutlineBox(1)] << get title;
Jim
nathan-clark
Level VI

Re: Graphics script to detect graph title

That's just it .... from within the graphics script itself, can I know that information?

Getting the title is easy from outside.

I want to be able to place the exact same graphics script into each graph of a report and have that script be able to figure out where it is.

txnelson
Super User

Re: Graphics script to detect graph title

Try this

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
i=0;
biv = dt << Bivariate(
	Y( :height ),
	X( :weight ),
	By( :sex ),
	SendToReport(
		Dispatch(
			{},
			"1",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 30 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Add Graphics Script(
				2,
				Description( "" ),
				i++;
				test = Associative Array( {{"F", {0.1, 50}}, {"M", {.8, 0}}} );
				///gather graph info to get "F" or "M" from output
				graphInfo = word(2,report(biv[i])[OutlineBox(1)] << get title,"=");
				show(graphinfo);
				Y Function( test[graphInfo][1] * x + test[graphInfo][2], x );
			), Grid Line Order( 1 ), Reference Line Order( 3 )
			}
		)
	)
);
Jim
nathan-clark
Level VI

Re: Graphics script to detect graph title

That's fascinating that you can start i at 0 and it just 'magically' iterates like that... I got the errors pasted below, but seems to have at least worked some. I created a show(i) command just before creating the graphInfo variable.
It seems to have worked great for the two graphs, but for some reason it also iterated two more times resulting in an inability to locate biv[i] ... so I wrapped that part in a Try() and it seemed to work as necessary!

 

1) I am not sure why "i" iterates like that or when I could potentially utilize that for other functions in jsl

2) I am not sure why it seems to iterate two more times ... one per graph, one per graphics script??

3) Thank you so much for the help here... I may not understand the how/why it works yet, but if I can get it to work consistently, that's the win!

 

nathan-clark_0-1619121449505.png

Names default to here(1);

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
i=0;
biv = dt << Bivariate(
	Y( :height ),
	X( :weight ),
	By( :sex ),
	SendToReport(
		Dispatch(
			{},
			"1",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 30 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Add Graphics Script(
				2,
				Description( "" ),
				i++;
				test = Associative Array( {{"F", {0.1, 50}}, {"M", {.8, 0}}} );
				///gather graph info to get "F" or "M" from output
				show(i);
				Try(
					graphInfo = word(2,report(biv[i])[OutlineBox(1)] << get title,"=");
					show(graphinfo);
					
				);
				Y Function( test[graphInfo][1] * x + test[graphInfo][2], x );
			), Grid Line Order( 1 ), Reference Line Order( 3 )
			}
		)
	)
);
jthi
Super User

Re: Graphics script to detect graph title

Expanding on one of codes by @txnelson :

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
test = Associative Array( {{"F", {0.1, 50}}, {"M", {.8, 0}}} );

biv = dt << Bivariate(
	Y( :height ),
	X( :weight ),
	By( :sex ),
	SendToReport(
		Dispatch(
			{},
			"1",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 30 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Grid Line Order(1 ), Reference Line Order( 3)}
		)
	)
);

rep = biv << Get As Report;

For( i = 1, i <= N Items(rep), i++,
	keyForAa = Substr(Report(rep [i])[Outline Box( 1 )] << get title,
	Contains(Report(rep [i])[Outline Box( 1 )] << get title, "=" ) + 1);	

	//see Add Graphics Script example from Scripting Index
	framebox = Report(rep [i])[frame box(1)];
	Eval(EvalExpr(framebox << Add Graphics Script(
		2,
		Description( "" ),
		Y Function(Expr(test[keyForAa][1]) * x + Expr(test[keyForAa][2]), x );
	)));

);
-Jarmo
nathan-clark
Level VI

Re: Graphics script to detect graph title

That could work too, @jthi ... as written it wouldn't be as dynamic as I would need long term, but I could use that to build in a custom iterator variable so each graph has teh same variable, but set to a different number, corresponding to it's place in the report.

 

Thanks again to everyone for their thoughts!

Re: Graphics script to detect graph title

Another approach might be to determine the values before you launch Bivariate. The Summarize() function can be used to determine the levels in the same order and they appear when using a By variable or Where() clause.

 

Summarize( level = By( :Group ) );

 

The variable level stores a list of strings of all the unique levels in the :Group data column in the right order. So you graphics script does not need to query the outline display box to find out where it is.