Class Shape
(Defined in: jpgraph_canvtools.php : 69)

 Shape Bezier()   Circle()   FilledCircle()   FilledPolygon()   FilledRectangle()   FilledRoundedRectangle()   IndentedRectangle()   Line()   Polygon()   Rectangle()   RoundedRectangle()   SetColor()   SetTextAlign()   ShadowRectangle()   __construct()

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.

CanvasScale

Class Methods

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

Shape ::
Circle(\$x1, \$y1, \$r)
Draw a circle

ArgumentDefaultDescription
\$x1  Center X-coordinate
\$y1  Center Y-coordinate

Description:
Draw a circle onto the canvas

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

Shape ::
FilledCircle(\$x1, \$y1, \$r)
Draw a filled circle to a canvas

ArgumentDefaultDescription
\$x1  Center X-coordinate
\$y1  Center Y-coordinate

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.

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

Shape ::
FilledPolygon(\$p)
Draw a filled polygon

ArgumentDefaultDescription
\$p  Polygon array

Description:
Draw a filled polygon

Shape ::
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:

\$shape->SetColor('green');
\$shape->FilledRectangle(15,8,19,14);

Shape ::
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

Description:
Create a filled rectangle with rounded corners

Shape ::
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

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

Shape ::
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.

Example:

\$shape->SetColor('black');
\$shape->Line(0,0,20,20);

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

Shape ::
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:

\$shape->SetColor('green');
\$shape->Rectangle(15,8,19,14);

Shape ::
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

Description:
Draw a rectangle with rounded corners

Shape ::
SetColor(\$aColor)
Specify color to use when drawing shapes

ArgumentDefaultDescription
\$aColor  Color specification

Description:
Specify color to use when drawing shapes

Example:

\$shape->SetColor('black');
\$shape->Line(0,0,20,20);

Shape ::
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
• "left"
• "center"
• "right"
and for vertical
• "top"
• "center"
• "bottom"

Example:

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

\$shape->StrokeText(....)

Shape ::
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

Description:
Draw a filled rectangle with a drop shadow

Shape ::
__construct(\$aGraph, \$scale)
Methods to draw shapes on canvas

ArgumentDefaultDescription
\$aGraph  No description available
\$scale  No description available

Description:
Create a new shape class used to draw siple shape onto a canvas using the specified scale.

Example:

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