550, 'height' => 350); /** * Add a legend to the graph? * @var bool */ protected $legend = true; /** * Title of the graph * @var string */ protected $title = 'ISSO Pie Chart'; /** * Padding in the graph * @var integer */ const PADDING = 10; /** * Spacing in the graph * @var integer */ const SPACING = 4; // ################################################################### /** * Constructor */ public function __construct() { $this->setScale(0); } // ################################################################### /** * Sets the width and height by using scale factors of 550x350; you * can specify a positive value to multiply by that many times or a * negative one to divide * * @param float Scale factor */ public function setScale($scale) { $this->dimensions['width'] = 550; $this->dimensions['height'] = 350; if ($scale > 0) { $this->dimensions['width'] *= $scale; $this->dimensions['height'] *= $scale; } else if ($scale < 0) { $scale = abs($scale); $this->dimensions['width'] /= $scale; $this->dimensions['height'] /= $scale; } if (!is_null($this->image)) { imagedestroy($this->image); } $this->image = imagecreate($this->dimensions['width'], $this->dimensions['height']); } // ################################################################### /** * Sets whether or not a legend is created for the graph * * @param bool Draw a legend? */ public function setLegend($yesno) { $this->legend = (bool)$yesno; } // ################################################################### /** * Sets the title of the chart to be drawn above the graph * * @param string Title of the chart */ public function setTitle($title) { $this->title = $title; } // ################################################################### /** * Graphs the actual data and returns then sends the image result to * the output buffer */ public abstract function graph(); // ################################################################### /** * Adds an entry to the data set without specifying a color to add. * This is the standard method as the color should only be overridden * if necessary. * * @param string Data column name * @param integer Amount */ public abstract function addDataSet($name, $amount); // ################################################################### /** * Adds an entry ot the data set with specifying a color. This works * the same as addDataSet() but requires an array() as the 3rd parameter * of R,G,B values * * @param string Data column name * @param integer Percent of 100 * @param array Array of R,G,B values */ public abstract function addDataSetColor($name, $amount, $color); // ################################################################### /** * Fetches a color from the allocated color list and returns the value * * @return integer Allocated color resource */ protected function _fetchColor() { static $colorlist = array( array(100, 60, 175), array(221, 110, 21), array(179, 34, 31), array(69, 196, 243), array(128, 186, 33), array(28, 101, 155), array(246, 204, 95), array(6, 43, 147), array(204, 61, 7), array(170, 169, 174), array(90, 15, 24), array(45, 130, 195) ); static $allocated = 0; $color = $colorlist["$allocated"]; $allocated++; 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; } // ################################################################### /** * Runs the imagepng() function and returns the bytestream * * @return string Byte stream */ protected function _imageFlush() { ob_start(); imagepng($this->image); $data = ob_get_contents(); if ($data === false) { $data = ob_get_clean(); } ob_clean(); ob_end_clean(); return $data; } } /*=====================================================================* || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>