CLASS Shape
(Defined in: jpgraph_canvtools.php : 69)
 Shape 
 Bezier() 
 Circle() 
 FilledCircle() 
 FilledPolygon() 
 FilledRectangle() 
 FilledRoundedRectangle() 
 IndentedRectangle() 
 Line() 
 Polygon() 
 Rectangle() 
 RoundedRectangle() 
 SetColor() 
 SetTextAlign() 
 ShadowRectangle() 
 Shape() 
 

Class usage and Overview
This is mainly awrapper class around thye current image class used. It is meant to make it easier to work with a Canvas graph and a Canvas scale. Basically the class uses the specified scale to trasnalte coordinates which is then passed on to the standard Image routines.

 

See also related classes:
CanvasScale

 


Class Methods

 

 

function Bezier($p,$aSteps)
Draw a bezier curve

ArgumentDefaultDescription
$p  Array with control points
$aSteps 40 Number of line segments in curve

Description
Draw a Bezier line with specified in the $p array. The points are specified according to the current scale. The positions in the array has the following meaning

(0,1) x0,y0 (First point on curver)
(2,3) x,y, (Control point 1)
(4,5) x,y, (Control point 2)
(6,7) x,y, (End point of curve)

See example in canvasbezierex1.php  

Example

$p = array(3,6,6,9,5,3,7,4);

$shape->SetColor('black');
$shape->Bezier($p);

 

 

function Circle($x1,$y1,$r)
Draw a circle

ArgumentDefaultDescription
$x1  Center X-coordinate
$y1  Center Y-coordinate
$r  Radius

Description
Draw a circle onto the canvas  
 
See also
Image::Circle

Example

// The shape class is wrapper around the Imgae class which translates
// the coordinates for us
$shape = new Shape($g,$scale);
$shape->SetColor('black');


// .. and a circle (x,y,diameter)
$shape->Circle(5,14,2);


 

 

function FilledCircle($x1,$y1,$r)
Draw a filled circle to a canvas

ArgumentDefaultDescription
$x1  Center X-coordinate
$y1  Center Y-coordinate
$r  Radius

Description
Draw a filled circle on the canvas using the specified scale.

Note: If you are using GD1.xx you will see moire-patterns in large circles. This is due to the lack of a proper filled circle function in GD 1.xx. Using GD 2.xx will avoid this problem.  
 

See also
Image::FilledCircle

Example

// The shape class is wrapper around the Imgae class which translates
// the coordinates for us
$shape = new Shape($g,$scale);
$shape->SetColor('black');


// .. and a circle (x,y,diameter)
$shape->FilledCircle(5,14,2);


 

 

function FilledPolygon($p)
Draw a filled polygon

ArgumentDefaultDescription
$p  Polygon array

Description
Draw a filled polygon 

 

 

function FilledRectangle($x1,$y1,$x2,$y2)
Draw a filled rectangle on the canvas

ArgumentDefaultDescription
$x1  Top left X
$y1  Top left Y
$x2  Bottom right X
$y2  Bottom right Y

Description
Draw a filled rectangle on the canvas using the current sclae.  

Example


// .. add a rectangle
$shape->SetColor('green');
$shape->FilledRectangle(15,8,19,14);

 

 

function FilledRoundedRectangle($x1,$y1,$x2,$y2,$r)
Create a filled rectangle with rounded corners

ArgumentDefaultDescription
$x1  Top left X
$y1  Top left Y
$x2  Bottom right X
$y2  Bottom right Y
$r null Corner radius

Description
Create a filled rectangle with rounded corners 

 

 

function IndentedRectangle($xt,$yt,$w,$h,$iw,$ih,$aCorner,$aFillColor,$r)
A filled rectangle with one corner 'indented'

ArgumentDefaultDescription
$xt  Top left X
$yt  Top left Y
$w  Width
$h  Height
$iw 0 Indented width
$ih 0 Indeted height
$aCorner 3 Corner to indent
$aFillColor "" Fill color
$r 4 Corner radius

Description
A rounded rectangle where one of the corner has been moved "into" the rectangle. The indention is determined by the two argument 'iw' width and 'ih' height.

The corners (as used in the $aCorner) are numbered as 0=Top left, 1=top right, 2=bottom right, 3=bottom left  

 

 

function Line($x1,$y1,$x2,$y2)
Draw a line between

ArgumentDefaultDescription
$x1  X1
$y1  Y1
$x2  X2
$y2  Y2

Description
Draw a line between two points in the canvas using the current scale. 
 
See also
Image::Line

Example


// Add a black line
$shape->SetColor('black');
$shape->Line(0,0,20,20);

 

 

function Polygon($p,$aClosed)
Draw a closed polygon

ArgumentDefaultDescription
$p  Array of points in polygon
$aClosed false No description available

Description
Draw a closed polygon 

Example

$p = array(3,6,6,9,5,3,7,4);
$shape->SetColor('blue:0.35');
$shape->Polygon($p);

 

 

function Rectangle($x1,$y1,$x2,$y2)
Draw a rectangle on the canvas

ArgumentDefaultDescription
$x1  Top left X
$y1  Top left Y
$x2  Bottom right X
$y2  Bottom right Y

Description
Draw a rectangle on the canvas using the current scale. 

Example

// .. add a rectangle
$shape->SetColor('green');
$shape->Rectangle(15,8,19,14);

 

 

function RoundedRectangle($x1,$y1,$x2,$y2,$r)
Draw a rectangle with rounded corners

ArgumentDefaultDescription
$x1  Top left X
$y1  Top left Y
$x2  Bottom right X
$y2  Bottom right Y
$r null Corner radius

Description
Draw a rectangle with rounded corners 

 

 

function SetColor($aColor)
Specify color to use when drawing shapes

ArgumentDefaultDescription
$aColor  Color specification

Description
Specify color to use when drawing shapes 
 
See also
RGB::Color

Example

// Add a black line
$shape->SetColor('black');
$shape->Line(0,0,20,20);

 

 

function SetTextAlign($halign,$valign)
Specify bae point for StrokeText()

ArgumentDefaultDescription
$halign  Horizontal position for basepoint
$valign "bottom" Vertical position for base point

Description
Specifies how the coordinate for the text should be interpretated. Possible values for horizontal base-position are and for vertical  

Example

// Interpret the text coordinate as beeing the
// top left corner of the bounding box for the text
$shape->SetTextAlign('left','top');

$shape->StrokeText(....)

 

 

function ShadowRectangle($x1,$y1,$x2,$y2,$fcolor,$shadow_width,$shadow_color)
Draw a filled rectangle with a drop shadow

ArgumentDefaultDescription
$x1  Top left X
$y1  Top left Y
$x2  Bottom right X
$y2  Bottom right Y
$fcolor false Fill color
$shadow_width null Shadow width
$shadow_color array(102,102,102) Shadow color

Description
Draw a filled rectangle with a drop shadow 

 

 

function Shape(&$aGraph,&$scale)
Methods to draw shapes on canvas

ArgumentDefaultDescription
&$aGraph  Canvas graph
&$scale  Canvas scale

Description
Create a new shape class used to draw siple shape onto a canvas using the specified scale. 
 
See also
CanvasGraph::CanvasGraph and CanvasScale::CanvasScale

Example

// Setup a basic canvas we can work 
$g = new CanvasGraph(400,200,'auto');
$g->SetMargin(5,11,6,11);
$g->SetShadow();
$g->SetMarginColor("teal");

// We need to stroke the plotarea and margin before we add the
// text since we otherwise would overwrite the text.
$g->InitFrame();

// Create a new scale
$scale = new CanvasScale($g);
$scale->Set(0,$xmax,0,$ymax);

// The shape class is wrapper around the Imgae class which translates
// the coordinates for us
$shape = new Shape($g,$scale);