- We can now properly label our axes in BSGraphLine, though we don't show any points
*/
protected $title = 'ISSO Pie Chart';
+ /**
+ * Padding in the graph
+ * @var integer
+ */
+ const PADDING = 10;
+
+ /**
+ * Spacing in the graph
+ * @var integer
+ */
+ const SPACING = 4;
+
// ###################################################################
/**
* Constructor
return imagecolorallocate($this->image, $color[0], $color[1], $color[2]);
}
+
+ // ###################################################################
+ /**
+ * Draws a white box, the title, and then a black border around the graph
+ */
+ protected function _paintCanvas()
+ {
+ $colors = $this->_primeColors();
+
+ // fill background
+ imagefill($this->image, 0, 0, $colors['white']);
+
+ // title the chart
+ imagestring($this->image, 5, ($this->dimensions['width'] - (imagefontwidth(5) * strlen($this->title))) / 2, self::PADDING, $this->title, $colors['black']);
+
+ // draw a border
+ imageline($this->image, 0, 0, 0, $this->dimensions['height'], $colors['black']); // left
+ imageline($this->image, 0, $this->dimensions['height'] - 1, $this->dimensions['width'], $this->dimensions['height'] - 1, $colors['black']); // bottom
+ imageline($this->image, $this->dimensions['width'] - 1, 0, $this->dimensions['width'] - 1, $this->dimensions['height'], $colors['black']); // right
+ imageline($this->image, 0, 0, $this->dimensions['width'], 0, $colors['black']); // top
+ }
+
+ // ###################################################################
+ /**
+ * Returns an array of colors that are useful (black, white, and grey)
+ *
+ * @return array Colors
+ */
+ protected function _primeColors()
+ {
+ $colors = array();
+ $colors['black'] = imagecolorallocate($this->image, 0, 0, 0);
+ $colors['white'] = imagecolorallocate($this->image, 255, 255, 255);
+ $colors['grey'] = imagecolorallocate($this->image, 121, 121, 123);
+ return $colors;
+ }
}
/*=====================================================================*
*/
private $piles = array(0 => array(), 1 => array());
+ /**
+ * The names of the axes
+ * @var array
+ */
+ private $axis = array(0 => 'X Axis', 1 => 'Y Axis');
+
// ###################################################################
/**
* Does the actual graphing and returns a byte stream of a PNG image
$xmax = max($this->piles[0]) + $xint;
$ymin = min($this->piles[1]);
- $ymin = ($ymin - $int < 0 ? 0 : $ymin - $yint);
+ $ymin = ($ymin - $yint < 0 ? 0 : $ymin - $yint);
$ymax = max($this->piles[1]) + $yint;
+ $colors = $this->_primeColors();
+ $this->_paintCanvas();
+
+ // draw the axes
+ $originx = self::PADDING + imagefontwidth(1) + self::SPACING + imagefontwidth(3) + self::PADDING;
+ $originy = $this->dimensions['height'] - (self::PADDING + imagefontheight(1) + self::SPACING + imagefontheight(3) + self::SPACING);
+ $endx = $this->dimensions['width'] - self::PADDING - 150 - self::PADDING;
+ $endy = 40;
+ $length = $endx - $originx;
+ $height = $originy - $endy;
+ imageline($this->image, $originx, $originy, $endx, $originy, $colors['grey']);
+ imageline($this->image, $originx, $originy, $originx, $endy, $colors['grey']);
+ imageline($this->image, $endx, $originy, $endx, $endy, $colors['grey']);
+
+ // label the axes
+ imagestring($this->image, 3, $length / 2, $this->dimensions['height'] - self::SPACING - imagefontheight(3), $this->axis[0], $colors['black']);
+ imagestringup($this->image, 3, self::SPACING, $height / 2 + $endy, $this->axis[1], $colors['black']);
+
+ // score the axes
+ $count = 0;
+ for ($i = $originx; $i <= $endx; $i += ($length / $xint))
+ {
+ imageline($this->image, $i - self::SPACING, $originy + self::SPACING, $i + self::SPACING, $originy - self::SPACING, $colors['grey']);
+ imagestring($this->image, 1, $i, $originy + self::PADDING, round($count), $colors['black']);
+ $count += $xint;
+ }
+ $count = 0;
+ for ($i = $originy; $i >= $endy; $i -= ($height / $yint))
+ {
+ imageline($this->image, $originx, $i, $endx, $i, $colors['grey']);
+ imagestring($this->image, 1, self::SPACING + self::PADDING, $i, round($count), $colors['black']);
+ $count += $yint;
+ }
+ header("Content-Type: image/png");
+ imagepng($this->image);
}
// ###################################################################
{
return array_sum($vals) / count($vals);
}
+
+ // ###################################################################
+ /**
+ * Sets the titles of the two axes
+ *
+ * @param string X-axis name
+ * @param string Y-axis name
+ */
+ public function setAxes($xaxis, $yaxis)
+ {
+ $this->axis[0] = $xaxis;
+ $this->axis[1] = $yaxis;
+ }
}
/*=====================================================================*
*/
public function graph()
{
- $colors['black'] = imagecolorallocate($this->image, 0, 0, 0);
- $colors['white'] = imagecolorallocate($this->image, 255, 255, 255);
- $colors['grey'] = imagecolorallocate($this->image, 121, 121, 123);
+ $colors = $this->_primeColors();
- $graphpadding = 10;
- $graphspacing = 4;
- $diameter = $this->dimensions['height'] - (5 * $graphpadding);
+ $diameter = $this->dimensions['height'] - (5 * self::PADDING);
$radius = $diameter / 2;
- $graphstart = $graphpadding + imagefontheight(5) + $graphpadding;
+ $graphstart = self::PADDING + imagefontheight(5) + self::PADDING;
$legendbox = 10;
- // fill background
- imagefill($this->image, 0, 0, $colors['white']);
-
- // title the chart
- imagestring($this->image, 5, ($this->dimensions['width'] - (imagefontwidth(5) * strlen($this->title))) / 2, $graphpadding, $this->title, $colors['black']);
+ $this->_paintCanvas();
$center = array(
- 'x' => ($this->legend ? ($radius + $graphpadding) : ($this->dimensions['width'] / 2)),
- 'y' => ($this->dimensions['height'] / 2) + $graphpadding
+ 'x' => ($this->legend ? ($radius + self::PADDING) : ($this->dimensions['width'] / 2)),
+ 'y' => ($this->dimensions['height'] / 2) + self::PADDING
);
- // draw a border
- imageline($this->image, 0, 0, 0, $this->dimensions['height'], $colors['black']); // left
- imageline($this->image, 0, $this->dimensions['height'] - 1, $this->dimensions['width'], $this->dimensions['height'] - 1, $colors['black']); // bottom
- imageline($this->image, $this->dimensions['width'] - 1, 0, $this->dimensions['width'] - 1, $this->dimensions['height'], $colors['black']); // right
- imageline($this->image, 0, 0, $this->dimensions['width'], 0, $colors['black']); // top
-
- $legx = (2 * $graphpadding) + $diameter;
+ $legx = (2 * self::PADDING) + $diameter;
$lastdeg = 0;
$boxoffset = 0;
if ($this->legend)
{
$box = array(
- $legx + 1 + $graphspacing, $graphstart + 1 + $graphspacing + $boxoffset, // top left
- $legx + 1 + $graphspacing, $graphstart + 1 + $graphspacing + $boxoffset + $legendbox, // bottom left
- $legx + 1 + $graphspacing + $legendbox, $graphstart + 1 + $graphspacing + $boxoffset + $legendbox, // bottom right
- $legx + 1 + $graphspacing + $legendbox, $graphstart + 1 + $graphspacing + $boxoffset // top right
+ $legx + 1 + self::SPACING, $graphstart + 1 + self::SPACING + $boxoffset, // top left
+ $legx + 1 + self::SPACING, $graphstart + 1 + self::SPACING + $boxoffset + $legendbox, // bottom left
+ $legx + 1 + self::SPACING + $legendbox, $graphstart + 1 + self::SPACING + $boxoffset + $legendbox, // bottom right
+ $legx + 1 + self::SPACING + $legendbox, $graphstart + 1 + self::SPACING + $boxoffset // top right
);
imagefilledpolygon($this->image, $box, 4, $plot[2]);
- imagestring($this->image, 2, ($legx + 1 + $graphspacing + $legendbox + $graphspacing), ($graphstart + $graphspacing + $boxoffset), $plot[0] . " ($plot[1]%)", $colors['black']);
+ imagestring($this->image, 2, ($legx + 1 + self::SPACING + $legendbox + self::SPACING), ($graphstart + self::SPACING + $boxoffset), $plot[0] . " ($plot[1]%)", $colors['black']);
- $boxoffset += $graphspacing + $legendbox;
+ $boxoffset += self::SPACING + $legendbox;
}
}
// do the legend
if ($this->legend)
{
- imageline($this->image, $legx, $graphstart, $this->dimensions['width'] - $graphpadding, $graphstart, $colors['black']); // top
- imageline($this->image, $legx, $graphstart, $legx, $legy = ($graphstart + $graphspacing + $boxoffset + 1), $colors['black']); // left
- imageline($this->image, $legx, $legy, $this->dimensions['width'] - $graphpadding, $legy, $colors['black']); // bottom
- imageline($this->image, $this->dimensions['width'] - $graphpadding, $graphstart, $this->dimensions['width'] - $graphpadding, $legy, $colors['black']); // right
+ imageline($this->image, $legx, $graphstart, $this->dimensions['width'] - self::PADDING, $graphstart, $colors['black']); // top
+ imageline($this->image, $legx, $graphstart, $legx, $legy = ($graphstart + self::SPACING + $boxoffset + 1), $colors['black']); // left
+ imageline($this->image, $legx, $legy, $this->dimensions['width'] - self::PADDING, $legy, $colors['black']); // bottom
+ imageline($this->image, $this->dimensions['width'] - self::PADDING, $graphstart, $this->dimensions['width'] - self::PADDING, $legy, $colors['black']); // right
}
ob_start();
# hilight source code
# output options
-/Server/bin/phpdoc -d ../ -t ./apidoc -i ../UnitTest/ -i ../docs/ -dh off -ti "Blue Static ISSO Framework" -dn ISSO -dc ISSO -s on -o HTML:Smarty:PHP > ./apidoc/log.txt
\ No newline at end of file
+/Server/bin/phpdoc -d ../ -t ./apidoc -i ../UnitTest/ -i * -dh off -ti "Blue Static ISSO Framework" -dn ISSO -dc ISSO -s on -o HTML:Smarty:PHP > ./apidoc/log.txt
\ No newline at end of file