cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
Thierry_S
Super User

Graph Builder > Add Graphics script > Add Customize Shape, Icons or Picture?

Hi JMP Community,

 

Similarly to the Graphics Script commands Circle, Oval, and Rectangle, is it possible to insert in a FrameBox customized shapes, icons, or, pictures?

Of note, I'm not looking for customize data point markers.

Here is a snippet of the type of graphics script I'm working with (gb is a graph builder heat map) where I would like to replace the Circle with a customized shape:

	gbr = report (gb);
	fb = gbr [FrameBox (1)];
	
	fb << add graphics script (
		Fill color (black);
		
		For (i = 0, i <= 24, i++,
			For (j = 0.5, j <= 7, j = j+2,
				r = (i*8) + (j+0.5);
				s = column (dt,"SIZE FDR") [r] / 8;
				if (s < 0.02, s = 0.02);
				circle ({i,j}, s, "FILL")
			 )	
		);
		
		
	);

Thank you for your help.

Best,

TS

Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Graph Builder > Add Graphics script > Add Customize Shape, Icons or Picture?

N-pointed starsN-pointed stars

 

makestar = Function( {x, y, npoints, inside, outside},
	{p = J( 2 * npoints, 3, . ), angle, i, move = 1, draw = 2},
	For( i = 1, i < N Rows( p ), 0,
		angle = 2 * Pi() * i / N Rows( p );
		p[i, 1] = x + Sin( angle ) * inside; // sin and cos are reversed here to
		p[i, 2] = y + Cos( angle ) * inside; // make the point be at the top.
		p[i, 3] = If( i == 1, move, draw ); // swap sin/cos for point at left.
		i += 1;
		angle = 2 * Pi() * i / N Rows( p );
		p[i, 1] = x + Sin( angle ) * outside; // ditto
		p[i, 2] = y + Cos( angle ) * outside;
		p[i, 3] = If( i == N Rows( p ), -draw, draw );
		i += 1;
	);
	p; // return
);

New Window( "Example",
	gb = Graph Box(
		xaxis( Show Major Grid( 1 ) ),
		yaxis( Show Major Grid( 1 ) ),
		framesize( 500, 500 ),
		Pen Color( "red" );
		Pen Size( 3 );
		Fill Color( "blue" );
		npoints = 3; // each star gets more points below
		For( xx = 20, xx <= 80, xx += 20,
			For( yy = 20, yy <= 80, yy += 20, 
				// the inside/outside ratio needs to change with more points...
				p = makestar( xx, yy, npoints, 2 + npoints / 4, 8 );
				Path( p, 1 ); // blue solid fill
				Path( p, 0 ); // red outline
				npoints += 1;
			)
		);
	)
);

// move the grid lines above the stars
grid = gb[framebox( 1 )] << find seg( SegPlaceholder( 1 ) );
// grid is the original, below the stars
gb[framebox( 1 )] << appendseg( grid ); // makes a copy above
// probably not needed...they are on top of each other...
grid << delete; // delete the original from below

 

Craige

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: Graph Builder > Add Graphics script > Add Customize Shape, Icons or Picture?

path() function? 

Bezier interpolation  and Bezier Tree using Path() (and the scripting index probably has simpler non-Bézier examples.)

 

Also the column property UseForMarker works on picture columns, but it sounds like you might not have a data point for each marker.

 

I think the only way you'll get pictures or icons without UseForMarker is to make separate picture segs for each marker. They can be positioned, seg-by-seg.

 

Craige
Thierry_S
Super User

Re: Graph Builder > Add Graphics script > Add Customize Shape, Icons or Picture?

Dear Craige,
Thank you for you suggestion, I will look into this method. However, I may not have provided enough details to get the feedback I'm specifically looking for.
In the specific case I'm working on, I'm adding shapes to a heatmap across cells to denote the significance of the contrast between these. So far, everything works as planned using Circles but I'm now looking for doing the same thing with another shape such a star or another custom shape.
Best regards,
TS
Thierry R. Sornasse
Craige_Hales
Super User

Re: Graph Builder > Add Graphics script > Add Customize Shape, Icons or Picture?

N-pointed starsN-pointed stars

 

makestar = Function( {x, y, npoints, inside, outside},
	{p = J( 2 * npoints, 3, . ), angle, i, move = 1, draw = 2},
	For( i = 1, i < N Rows( p ), 0,
		angle = 2 * Pi() * i / N Rows( p );
		p[i, 1] = x + Sin( angle ) * inside; // sin and cos are reversed here to
		p[i, 2] = y + Cos( angle ) * inside; // make the point be at the top.
		p[i, 3] = If( i == 1, move, draw ); // swap sin/cos for point at left.
		i += 1;
		angle = 2 * Pi() * i / N Rows( p );
		p[i, 1] = x + Sin( angle ) * outside; // ditto
		p[i, 2] = y + Cos( angle ) * outside;
		p[i, 3] = If( i == N Rows( p ), -draw, draw );
		i += 1;
	);
	p; // return
);

New Window( "Example",
	gb = Graph Box(
		xaxis( Show Major Grid( 1 ) ),
		yaxis( Show Major Grid( 1 ) ),
		framesize( 500, 500 ),
		Pen Color( "red" );
		Pen Size( 3 );
		Fill Color( "blue" );
		npoints = 3; // each star gets more points below
		For( xx = 20, xx <= 80, xx += 20,
			For( yy = 20, yy <= 80, yy += 20, 
				// the inside/outside ratio needs to change with more points...
				p = makestar( xx, yy, npoints, 2 + npoints / 4, 8 );
				Path( p, 1 ); // blue solid fill
				Path( p, 0 ); // red outline
				npoints += 1;
			)
		);
	)
);

// move the grid lines above the stars
grid = gb[framebox( 1 )] << find seg( SegPlaceholder( 1 ) );
// grid is the original, below the stars
gb[framebox( 1 )] << appendseg( grid ); // makes a copy above
// probably not needed...they are on top of each other...
grid << delete; // delete the original from below

 

Craige
Craige_Hales
Super User

Re: Graph Builder > Add Graphics script > Add Customize Shape, Icons or Picture?

There is also a PixelPath() function. If you run into performance issues, with 1000s of points perhaps, PixelPath allows repositioning, sizing, and rotating an existing path. (I don't see how to do that with Path().) You could pre-create the star(s) once, then re-use them with PixelPath. 

Path() and PixelPath() behave differently when you stretch the graph: Path draws in user coordinates and the drawing stretches to fit the current axes. PixelPath draws in pixels and the symbols don't change size.

The scripting index has an example for PixelPath; use PixelOrigin(x,y) and leave h,v at 0,0.

 

Craige