cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
miguello
Level VII

Text annotation size and text placement control: help needed

All, 

I need to place several text annotations on a plot.

They are one liners, but different length. So that's why I have to use Fixed Size(0) to adjust label length to match text. 

But when I do that, it also adjusts the vertical size and puts the text way too high, which for some reason bothers me very much (plot on the left). If I set Fixed Size(1), then I can control size of the label directly and text placement looks OK (plot on the right), but I have text of different length, it's either label too long, or if text goes over the label size, it snaps to "Fixed Size(0)" behavior, looking very ugly.

TextAnn1.pngTextAnn2.png

 

 

 

 

 

 

 

 

 

 

 

Any idea how to adjust text positioning within label AND use Fixed Size(0)?

<< Vertical Alignment("bottom") doesn't work.

 

Here's the code:

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;

taHeight = 20;
ta1 = rbiv << Add Text Annotation();
ta2 = rbiv << Add Text Annotation();



ta1 << Text( "We need to discuss this at the next meeting." );
ta1 << Text Box( {70, 80, 350, 80+taHeight} );

ta2 << Text( "We need to discuss this at the next " );
ta2 << Text Box( {70, 120, 350, 120+taHeight} );


{ta1, ta2} << Background Color( "Light Yellow" ) << Text Color( "red" )/*<<Set Wrap(400)*/; 
//ta1 << Vertical Alignment("Top");

ta1<<Fixed Size(0);
ta2<<Fixed Size(0);

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Text annotation size and text placement control: help needed

Not sure if you can control that in text annotation unless you calculate the sizes of the textbox yourself.

Could you maybe utilize Graphic Script?

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt << bivariate(y(:weight), x(:height));
rbiv = biv << report;

fb = rbiv[FrameBox(1)];

fb << Add Graphics Script(
	Back Color("Light Yellow");
	Text Color("Red");
	Text(Erased, {50, 150}, "We need to discuss this at the next meeting.");

	Text(Erased, {50, 135}, "We need to discuss this at the next");
);
-Jarmo

View solution in original post

jthi
Super User

Re: Text annotation size and text placement control: help needed

You might be able to do the size check also with Text Box in new window

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;

taHeight = 20;
ta1 = rbiv << Add Text Annotation();
ta2 = rbiv << Add Text Annotation();


nw = new window("", << Window View("Invisible"),
	tb1 = Text Box("We need to discuss this at the next meeting."),
	tb2 = Text Box("We need to discuss this at the next ")
);
w1 = tb1 << Get Size;
w2 = tb2 << Get Size;
nw << close window;


ta1 << Text( "We need to discuss this at the next meeting." );
ta1 << Text Box( {70, 80, w1[1]+20+70, 80+taHeight});

ta2 << Text( "We need to discuss this at the next " );
ta2 << Text Box( {70, 120, w2[1]+20+70, 120+taHeight});


{ta1, ta2} << Background Color( "Light Yellow" ) << Text Color( "red" )/*<<Set Wrap(400)*/; 
//ta1 << Vertical Alignment("Top");
-Jarmo

View solution in original post

9 REPLIES 9
jthi
Super User

Re: Text annotation size and text placement control: help needed

Not sure if you can control that in text annotation unless you calculate the sizes of the textbox yourself.

Could you maybe utilize Graphic Script?

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt << bivariate(y(:weight), x(:height));
rbiv = biv << report;

fb = rbiv[FrameBox(1)];

fb << Add Graphics Script(
	Back Color("Light Yellow");
	Text Color("Red");
	Text(Erased, {50, 150}, "We need to discuss this at the next meeting.");

	Text(Erased, {50, 135}, "We need to discuss this at the next");
);
-Jarmo
miguello
Level VII

Re: Text annotation size and text placement control: help needed

The problem with Add Graphics Script is that the position of the text is specified in actual coordinates on the plot. In my case it can be any, starting 1e-07 to over 9000 :)

I might be interested in writing a function to calculate values for positions I want, but only if I can add border\frame around the text like in the first example. The graph might be quite busy, I need to visually separate this for fast reading and dispo-ing.

miguello
Level VII

Re: Text annotation size and text placement control: help needed

I got an idea.

What if I draw text annotations with Fixed Size(0) first, measure length, then change them to Fixed Size(1), and set the measured width and desired height manually?

The problem is, << Get Size() returns some bogus values:

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;

taHeight = 40;
ta1 = rbiv << Add Text Annotation();
ta2 = rbiv << Add Text Annotation();



ta1 << Text( "We need to discuss this at the next meeting." );
ta1 << Text Box( {70, 80, 350, 80+taHeight} );

ta2 << Text( "We need to discuss this at the next " );
ta2 << Text Box( {70, 120, 350, 120+taHeight} );


{ta1, ta2} << Background Color( "Light Yellow" ) << Text Color( "red" )/*<<Set Wrap(400)*/; 
ta1 << Vertical Alignment("Center");

ta1<<Fixed Size(0);
ta2<<Fixed Size(0);

{ta1_x, ta1_y} = ta1 << Get Size();
{ta2_x, ta2_y} = ta2 << Get Size();

Show(ta1_x, ta2_x);

It produces:

//:*/
Show(ta1_x, ta2_x);
/*:

ta1_x = 328;
ta2_x = 328;

even though the labels are visibly of different length on the graph. Am I missing something?

Re: Text annotation size and text placement control: help needed

Try using <<Get Width

miguello
Level VII

Re: Text annotation size and text placement control: help needed

Thanks for the tip, yes, I can now get and set the sizes of the label.

The problem is that JSL doesn't line by line, instead, it kinda computes the final state for different properties separately... And then applies.

Like:

...
...
ta1<<Fixed Size(0);
ta2<<Fixed Size(0);
...
...
{ta1, ta2} << Fixed Size(1);
//Final state should be  Fixed Size(1) so we just apply that

So then the width remains the one that I initially set up:

ta1 << Text( "We need to discuss this at the next meeting." );
ta1 << Text Box( {70, 80, 350, 80+taHeight} );

ta2 << Text( "We need to discuss this at the next " );
ta2 << Text Box( {70, 120, 350, 120+taHeight} );

Adding Wait(0.5) helped to overcome that.

 

So the final script is:

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;

taHeight = 40;
ta1 = rbiv << Add Text Annotation();
ta2 = rbiv << Add Text Annotation();



ta1 << Text( "We need to discuss this at the next meeting." );
ta1 << Text Box( {70, 80, 350, 80+taHeight} );

ta2 << Text( "We need to discuss this at the next " );
ta2 << Text Box( {70, 120, 350, 120+taHeight} );


{ta1, ta2} << Background Color( "Light Yellow" ) << Text Color( "red" )<<Fixed Size(0);

Wait(0.05);

ta1_y = ta1 << Get Height();
ta2_y = ta2 << Get Height();

Show(ta1_x, ta2_x);

{ta1, ta2} << Fixed Size(1);

ta1 << Set Height(ta1_y*0.92);
ta2 << Set Height(ta2_y*0.92);

 

miguello
Level VII

Re: Text annotation size and text placement control: help needed

Never mind, it works.

Before the loops:

taList = {};

Inside the loop:

Insert Into(taList, ta);

After the loops:

Wait(0);
taList << Fixed Size(1);
For Each({height, index}, taList << Get Height(),
	taList[index] << Set Height(height*0.93)
);

 

 

 

Now the problem is that when implementing this in real scenario, when I have multiple plots with multiple Text Annotations - doing this trick with each annotation over two level loop is too slow.

I tried to create a list of text annotations:

taList={};

and then just inside the loops add the current ta to the list:

Insert Into(taList, ta);

At the end of the loops I have:

taList
/*:

{DisplayBox[gtext], DisplayBox[gtext],......}

But operations on this list or separate members do not work.

 

Any ideas? Mine are:

1. Try to use Context Box to separate variables between different ta's

2. Somehow pull those annotations from the report - but when I pull XML (<<Get XML()) of my report, I cannot find those annotations in there.

 

jthi
Super User

Re: Text annotation size and text placement control: help needed

You might be able to do the size check also with Text Box in new window

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;

taHeight = 20;
ta1 = rbiv << Add Text Annotation();
ta2 = rbiv << Add Text Annotation();


nw = new window("", << Window View("Invisible"),
	tb1 = Text Box("We need to discuss this at the next meeting."),
	tb2 = Text Box("We need to discuss this at the next ")
);
w1 = tb1 << Get Size;
w2 = tb2 << Get Size;
nw << close window;


ta1 << Text( "We need to discuss this at the next meeting." );
ta1 << Text Box( {70, 80, w1[1]+20+70, 80+taHeight});

ta2 << Text( "We need to discuss this at the next " );
ta2 << Text Box( {70, 120, w2[1]+20+70, 120+taHeight});


{ta1, ta2} << Background Color( "Light Yellow" ) << Text Color( "red" )/*<<Set Wrap(400)*/; 
//ta1 << Vertical Alignment("Top");
-Jarmo
miguello
Level VII

Re: Text annotation size and text placement control: help needed

This one works too. Subjectively even faster than my solution. Trying to measure it with the debugging tool.

 

miguello
Level VII

Re: Text annotation size and text placement control: help needed

Setting Wait(0) speeds things up - there is now actual wait, but screen is re-drawn.

Recommended Articles