(Defined in: jpgraph_text.inc.php : 17)
Class usage and Overview
All text that is to be draw onto any graph is handled by this class. You create each text you want printed as an instance of this class.
It is possible to adjust both font, color, alignment and paragraph alignment.
If the text contains multiple lines (separated by "\n") the paragraph alignment determines how each line is formatted (i.e. left,center or right)
Class Methods
Specify alignment for the text in relation to the x,y position for text
Argument | Default | Description |
$aHAlign
| | Horizontal alignment |
$aVAlign
|
"top"
| Vertical alignment |
$aParagraphAlign
|
""
| Paragraph alignment |
Description:
This determines how the text's x,y position is to be interpretated.
Valid horizontal alignments are
Valid vertical position are
- 'top'
- 'middle' or 'center'
- 'bottom'
Valid paragraph alignment
See also:
$text = new Text();
Center the text between left and right coordinates
Argument | Default | Description |
$aLeft
| | Left corner X-coordinate |
$aRight
| | Right corner X-coordinate |
$aYAbsPos
| | The common Y-coodinate |
Description:
Center the text between left and right coordinates on the same Y-coordinate
$txt->Center(50,150,75);
Height of font
Argument | Default | Description |
$aImg
| | No description available |
Description:
Return the height of the font used in the text.
The difference between this method and the GetTextHeight() is that this method uses a predefined character to determine the height while GetTextHeight() uses the actual text in the string.
See also:
$height = $txt->GetFontHeight($graph->img)
Return the height of the actual text in the text object
Argument | Default | Description |
$aImg
| | No description available |
Description:
Return the height of the text in this object.
The difference between this method and the GetFontHeight() is that that method uses a predefined character to determine the height while GetTextHeight() uses the actual text in the string.
See also:
$height = $txt->GetTextHeight($graph->img);
Get total width of text
Argument | Default | Description |
$aImg
| | No description available |
Description:
Get total width of text
See also:
$width = $txt->GetWidth($graph->img);
Hide the text
Argument | Default | Description |
$aHide
|
true
| True=Hide text |
Description:
The opposite of Show()
See also:
$txt->Hide();
Specifies the alignment for a multi line text
Argument | Default | Description |
$aAlign
| | Alignment for a multiline text |
Description:
Specify the paragraph alignment for a multi line text. Each text line is separated by a "\n" character.
Valid alignments are:
See also:
$txt->Set("The first line\nSec line\nThird line");
$txt->ParagraphAlign('center');
// Will give the result:
//
// The first line
// Sec line
// Third line
Set text to be displayed
Argument | Default | Description |
$aTxt
| | Text string |
Description:
Set text to be displayed
$txt->Set('Hello world');
Alias for Align()
Argument | Default | Description |
$aHAlign
| | Horizontal anchor point |
$aVAlign
|
"top"
| Vertical anchor point |
$aParagraphAlign
|
""
| Paragraph alignment |
Description:
See Align
See also:
Specify text angle
Argument | Default | Description |
$aAngle
| | Angle in degrees |
Description:
Specify Orientation of text. If TTF fonts are used then the orientation can be a arbitrary angle. If the builtin fonts are used then only horizontal and vertical position can be used, i.e 0 or 90 degrees,
$txt->SetAngle(45);
Set parameters for poossible frame around text
Argument | Default | Description |
$aFrameColor
|
array(255,255,255)
| Color for text background |
$aBorderColor
|
array(0,0,0)
| Color for border around text |
$aShadowColor
|
false
| Color for shadow |
$aCornerRadius
|
4
| Corner radius for rectangle |
$aShadowWidth
|
3
| Drop shadow width |
Description:
Specify parameters for background color, border and possible text drop shadow.
If no shadow color is specified then no shadow will appear.
To use the old style of stright corners specify a corner radius of 0.
See also:
$txt = new Text("Note: Simple textnote.\nWIth two lines");
$txt->SetFont(FF_FONT1,FS_BOLD);
$txt->Pos(0.5,0.97,'center','bottom');
$txt->SetBox('yellow','black');
$graph->AddText($txt);
Set text color
Argument | Default | Description |
$aColor
| | Color |
Description:
Specify color for text
$txt->SetColor('darkblue');
Specify CSIM Target for text
Argument | Default | Description |
$aURITarget
| | No description available |
$aAlt
|
''
| Alt-tag text |
$aWinTarget
|
''
| No description available |
Description:
Specify Client Side Image Target for text
$graph->title->SetCSIMTarget('mainpage.html','Go to main page');
Specify font
Argument | Default | Description |
$aFamily
| | Font family |
$aStyle
|
FS_NORMAL
| Font style |
$aSize
|
10
| Font size |
Description:
Specify font family, size and style. Two major types of font families can be used, builtin bitmnapped fonts or TTF fonts. The builtin fonts have a fixed size which can't be altered.
Valid styles are
- FS_NORMAL
- FS_BOLD
- FS_ITALIC
- FS_BOLDITALIC
Valid values for the internal font families are
- FF_FONT0, Internal font 1 (small font)
- FF_FONT1, Internal font 2, (Medium size)
- FF_FONT2, Internal font 3, (large size)
Note: FF_FONT0 only suppor font style FS_NORMAL
The available TTF are by default
- FF_ARIAL
- FF_TIMES, (Times Roman)
- FF_COURIER, (Courier new)
- FF_VERDANA, (Verdana)
- FF_BOOK, (Bookman)
- FF_HANDWRT, (Handwriting)
- FF_COMIC, (Sans Comic)
See also:
$txt->SetFont(FF_ARIAL, FS_BOLD, 14);
Set the contect sensiive margin
Argument | Default | Description |
$aMarg
| | Margin in pixels |
Description:
Specify a context sensitive margin for the text. Depending on in which context the text is used the margin will be interpretated accordingly.
// Start further away from the top of graph
$graph->title->SetMargin(15);
Deprecated. Use SetAngle instead. Specify text angle
Argument | Default | Description |
$aDirection
|
0
| Orientation of text in degrees |
Description:
Deprecated. Use SetAngle() instead.
Specify Orientation of text. If TTF fonts are used then the orientation can be a arbitrary angle. If the builtin fonts are used then only horizontal and vertical position can be used, i.e 0 or 90 degrees,
$txt->SetOrientation(90); // Vertical text
Specifies the alignment for a multi line text
Argument | Default | Description |
$aAlign
| | Horizontal alignment |
Description:
Determines how a multi-line text paragraph will be formatted. Each line in the paragraph will be treated individually. Allowed values are
- "center"
- "left"
- "right"
Note: Paragraph alignment is only applicable to horizontal text, i.e. angle = 0 . For paragraphs at an angle the alignbment will always be "left".
$graph->title->Set("Multi line\ntext !");
$graph->title->SetParagraphAlign('right');
// Default for title is "center"
Alias for Pos()
Argument | Default | Description |
$aXAbsPos
| | X position |
$aYAbsPos
| | Y position |
$aHAlign
| | Horizontal align |
$aVAlign
| | Vertical align |
Description:
Alias for Pos()
See also:
$txt->Pos(100,150,'center');
Specify the position of the text using the plot scale positions
Argument | Default | Description |
$aX
| | X-position |
$aY
| | Y-position |
Description:
Specify the position of the text using the plot scale positions. The Y position is taken to be the Y axis. It is not possible to use Y2 scale to specify the position.
$txt = new Text();
$txt->SetScalePos(27.3, 278.9);
Add a drop shadow to boxed text
Argument | Default | Description |
$aShadowColor
|
'gray'
| Shadow color |
$aShadowWidth
|
3
| Shadow width (in pixels) |
Description:
If the text has been boxed (by call to SetBox()) then you can easily add a drop shadow by just calling this method.
Note: You can also specify the shadow directly in the SetBox() call. This method was added to make Text more like other graph objects which have a SetShadow() method.
See also:
$txt = new Text("Note: Simple textnote.\nWIth two lines");
$txt->SetFont(FF_FONT1,FS_BOLD);
$txt->Pos(0.5,0.97,'center','bottom');
$txt->SetBox('yellow','black');
$txt->SetShadow();
$graph->AddText($txt);
Specify a maximum line length
Argument | Default | Description |
$aCol
| | Number of chars in column |
Description:
Specify a maximum line length. This method will insert suitable line breaks to ensure thateach line never exeeds the specified number of characters. The method will not break words.
$txt = new Text('A suitable long text which will be broken');
$txt->SetWordWrap(15);
Show or hide the text string
Argument | Default | Description |
$aShow
|
true
| True=Display text |
Description:
Show or hide the text string. By default the text string is turned off. So a call to Show() is becessary for the text string to be displayed in the graph.
$txt->Show();
Constructor. Create new text at absolute pixel coordinates
Argument | Default | Description |
$aTxt
| | Text string |
$aXAbsPos
| | X-coordinate |
$aYAbsPos
| | Y-coordinate |
Description:
Create a new object to repesent a text string that is to be displayed on the graph.
If the position is not specified when the object is created it can later be specified with a call to the Pos() method.
The default alignment is to interpret the x,y coordinate as being the lower left corner of the bounding box for the text string.
Note. The texts are hidden by default and you must remember toi call Show() to make the text appear in the image.
Returns
An istance of class Text
See also:
// Possible creations of text objects
// Case 1. Text and position is specified later
$txt = new Text();
// Case 2. Position is specified later
$txt = new Text('Hello world');
// Case 3. Full specification
$txt = new Text('Hello world',100,150);
// A more real life example
$txt = new Text("Note: Simple textnote.\nWIth two lines");
$txt->SetFont(FF_FONT1,FS_BOLD);
$txt->Pos(0.5,0.97,'center','bottom');
$txt->SetBox('yellow','black');
$graph->AddText($txt);