cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
thickey
Level III

Add Text to a graph box

I can add formatted text at a specific coordinate using the code below at the time of making the Graph box.

 

New Window( "Example",
	Graph Box(
		Text Size( 20 );
		Text( {50, 20}, "label" );
	)
);

thickey_0-1643420330974.png

 

However, I can't seem to figure out how to add text later, after the Graph Box has been created. For example I am actually trying to add multiple formatted text items to the graph box in a for loop.

 

I tried by identifying the 'inner frame box' for the 'graph box' and adding the text to it, but the frame box does not recognize the 'Text' message.  Ultimately, I want to be able to add multiple formatted text items at specific coordinates.

 

Names Default To Here( 1 );
New Window( "Example", a = Graph Box() );
frame = a[FrameBox( 1 )];
frame << Text Color( "red" );
frame << Text( Center Justified, {50, 20}, "centered" );

 

How do I achieve this?

 

Cheers, Troy

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Add Text to a graph box

Notice how the final Glue() statement in the Graph Box() function is a script as shown in the help index (see below).  To add a script to a graph box after-the-fact, use the <<Add Graphics Script method, as below.  You can put a Glue() function here as I've done.

 

Names Default To Here( 1 );
New Window( "Example", a = Graph Box() );
frame = a[FrameBox( 1 )];
frame << Add Graphics Script( Text Color( "red" ); Text( Center Justified, {50, 20}, "centered" ) );

 

ErraticAttach_0-1643487721257.png

 

Jordan

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: Add Text to a graph box

Depending on the goal, you might be able to use a data table and an existing platform and just label the points with another column. One of the column attributes is Use For Marker.

UseForMarker circled in red.UseForMarker circled in red.

But to do what you describe, the graphics script needs to have a loop that gets labels (and color and marker data) from a container of some sort. The container can be a list, a data table, or an associative array. If you add a label to the container, you can send the <<inval message to the graph to make it redraw. When it redraws, the graphics script will process all the labels from the container.

list = {{"aaa", 10, 10, "red"}};
New Window( "Example",
    gb=Graph Box(
        For( i = 1, i <= N Items( list ), i += 1,
            thisLabel = list[i];
            Text Color( thisLabel[4] );
            Text( Center Justified, {thisLabel[2], thisLabel[3]}, thisLabel[1] );
        )
    )
);
wait(1);
list[2] = {"bbb",20,20,"blue"};
gb<<inval;
wait(1);
list[3] = {"ccc",30,30,"green"};
gb<<inval;

Three seconds later...Three seconds later...

Craige
thickey
Level III

Re: Add Text to a graph box

Awesome Craige. 

 

I usually make all of my GUI Items up front and send messages to them later in the 'Logic' Part of my applications. Of course, I can just move the main loop INTO the graph box when I make it. That would work pretty well I suspect. 

 

I'll go give these two approaches a go and see how I get on.

 

Thanks for the info.

 

Incidentally, I'm using the graph box purely for making an Image (die partition map in this case) - I don't have any 'data' associated with this like I would when I use a bivariate or graphbuilder platform for analysis.

ErraticAttack
Level VI

Re: Add Text to a graph box

Notice how the final Glue() statement in the Graph Box() function is a script as shown in the help index (see below).  To add a script to a graph box after-the-fact, use the <<Add Graphics Script method, as below.  You can put a Glue() function here as I've done.

 

Names Default To Here( 1 );
New Window( "Example", a = Graph Box() );
frame = a[FrameBox( 1 )];
frame << Add Graphics Script( Text Color( "red" ); Text( Center Justified, {50, 20}, "centered" ) );

 

ErraticAttach_0-1643487721257.png

 

Jordan
thickey
Level III

Re: Add Text to a graph box

Oh man, both solutions work but I ultimately went for ErraticAttach method as it is closer to my original requirement. 

Thanks to both of you for your responses.