Class Text
(Defined in: jpgraph_text.inc.php : 17)
 
 Text 
 Align() 
 Center() 
 GetFontHeight() 
 GetTextHeight() 
 GetWidth() 
 Hide() 
 ParagraphAlign() 
 Set() 
 SetAlign() 
 SetAngle() 
 SetBox() 
 SetColor() 
 SetCSIMTarget() 
 SetFont() 
 SetMargin() 
 SetOrientation() 
 SetParagraphAlign() 
 SetPos() 
 SetScalePos() 
 SetShadow() 
 SetWordWrap() 
 Show() 
 __construct() 
 

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

 

Text ::
Align($aHAlign, $aVAlign, $aParagraphAlign)
Specify alignment for the text in relation to the x,y position for text

ArgumentDefaultDescription
$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 Valid paragraph alignment  
 
See also:

Example:

$text = new Text();

 

Text ::
Center($aLeft, $aRight, $aYAbsPos)
Center the text between left and right coordinates

ArgumentDefaultDescription
$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 

Example:

$txt->Center(50,150,75);

 

Text ::
GetFontHeight($aImg)
Height of font

ArgumentDefaultDescription
$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:

Example:

$height $txt->GetFontHeight($graph->img)

 

Text ::
GetTextHeight($aImg)
Return the height of the actual text in the text object

ArgumentDefaultDescription
$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:

Example:

$height $txt->GetTextHeight($graph->img);

 

Text ::
GetWidth($aImg)
Get total width of text

ArgumentDefaultDescription
$aImg  No description available

Description:
Get total width of text 
 
See also:

Example:

$width $txt->GetWidth($graph->img);

 

Text ::
Hide($aHide)
Hide the text

ArgumentDefaultDescription
$aHide true True=Hide text

Description:
The opposite of Show() 
 
See also:

Example:

$txt->Hide();

 

Text ::
ParagraphAlign($aAlign)
Specifies the alignment for a multi line text

ArgumentDefaultDescription
$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:

Example:

$txt->Set("The first line\nSec line\nThird line");
$txt->ParagraphAlign('center');

// Will give the result:
//
//  The first line
//     Sec line
//    Third line

 

Text ::
Set($aTxt)
Set text to be displayed

ArgumentDefaultDescription
$aTxt  Text string

Description:
Set text to be displayed 

Example:

$txt->Set('Hello world');

 

Text ::
SetAlign($aHAlign, $aVAlign, $aParagraphAlign)
Alias for Align()

ArgumentDefaultDescription
$aHAlign  Horizontal anchor point
$aVAlign "top" Vertical anchor point
$aParagraphAlign "" Paragraph alignment

Description:
See Align 
 
See also:

 

Text ::
SetAngle($aAngle)
Specify text angle

ArgumentDefaultDescription
$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, 

Example:

$txt->SetAngle(45);

 

Text ::
SetBox($aFrameColor, $aBorderColor, $aShadowColor, $aCornerRadius, $aShadowWidth)
Set parameters for poossible frame around text

ArgumentDefaultDescription
$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:

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);


 

Text ::
SetColor($aColor)
Set text color

ArgumentDefaultDescription
$aColor  Color

Description:
Specify color for text 

Example:

$txt->SetColor('darkblue');

 

Text ::
SetCSIMTarget($aURITarget, $aAlt, $aWinTarget)
Specify CSIM Target for text

ArgumentDefaultDescription
$aURITarget  No description available
$aAlt '' Alt-tag text
$aWinTarget '' No description available

Description:
Specify Client Side Image Target for text 

Example:

$graph->title->SetCSIMTarget('mainpage.html','Go to main page');

 

Text ::
SetFont($aFamily, $aStyle, $aSize)
Specify font

ArgumentDefaultDescription
$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 Valid values for the internal font families are Note: FF_FONT0 only suppor font style FS_NORMAL The available TTF are by default  
 
See also:

Example:

$txt->SetFont(FF_ARIALFS_BOLD14);

 

Text ::
SetMargin($aMarg)
Set the contect sensiive margin

ArgumentDefaultDescription
$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. 

Example:

// Start further away from the top of graph
$graph->title->SetMargin(15);

 

Text ::
SetOrientation($aDirection)
Deprecated. Use SetAngle instead. Specify text angle

ArgumentDefaultDescription
$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, 

Example:

$txt->SetOrientation(90); // Vertical text

 

Text ::
SetParagraphAlign($aAlign)
Specifies the alignment for a multi line text

ArgumentDefaultDescription
$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
  1. "center"
  2. "left"
  3. "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".  

Example:

$graph->title->Set("Multi line\ntext !");
$graph->title->SetParagraphAlign('right');

// Default for title is "center"

 

Text ::
SetPos($aXAbsPos, $aYAbsPos, $aHAlign, $aVAlign)
Alias for Pos()

ArgumentDefaultDescription
$aXAbsPos  X position
$aYAbsPos  Y position
$aHAlign  Horizontal align
$aVAlign  Vertical align

Description:
Alias for Pos() 
 
See also:

Example:

$txt->Pos(100,150,'center');

 

Text ::
SetScalePos($aX, $aY)
Specify the position of the text using the plot scale positions

ArgumentDefaultDescription
$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. 

Example:

$txt = new Text();
$txt->SetScalePos(27.3278.9);

 

Text ::
SetShadow($aShadowColor, $aShadowWidth)
Add a drop shadow to boxed text

ArgumentDefaultDescription
$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:

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');
$txt->SetShadow();
$graph->AddText($txt);

 

Text ::
SetWordWrap($aCol)
Specify a maximum line length

ArgumentDefaultDescription
$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. 

Example:

$txt = new Text('A suitable long text which will be broken');
$txt->SetWordWrap(15);

 

Text ::
Show($aShow)
Show or hide the text string

ArgumentDefaultDescription
$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.  

Example:

$txt->Show();

 

Text ::
__construct($aTxt, $aXAbsPos, $aYAbsPos)
Constructor. Create new text at absolute pixel coordinates

ArgumentDefaultDescription
$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:

Example:

// 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);