image, 0, 0, 0); $colors['white'] = imagecolorallocate($this->image, 255, 255, 255); $colors['grey'] = imagecolorallocate($this->image, 121, 121, 123); $graphpadding = 10; $graphspacing = 4; $diameter = $this->dimensions['height'] - (5 * $graphpadding); $radius = $diameter / 2; $graphstart = $graphpadding + imagefontheight(5) + $graphpadding; $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']); $center = array( 'x' => ($this->legend ? ($radius + $graphpadding) : ($this->dimensions['width'] / 2)), 'y' => ($this->dimensions['height'] / 2) + $graphpadding ); // 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; $lastdeg = 0; $boxoffset = 0; foreach ($this->dataset AS $plot) { $deg = (360 / 100) * $plot[1]; imagefilledarc($this->image, $center['x'], $center['y'], $diameter, $diameter, $lastdeg, $deg + $lastdeg, $plot[2], IMG_ARC_PIE); imagefilledarc($this->image, $center['x'], $center['y'], $diameter, $diameter, $lastdeg, $deg + $lastdeg, $colors['grey'], IMG_ARC_EDGED | IMG_ARC_NOFILL); $lastdeg += $deg; 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 ); 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']); $boxoffset += $graphspacing + $legendbox; } } // draw the ellipse (do here so it cleans up the arc edges) imageellipse($this->image, $center['x'], $center['y'], $diameter, $diameter, $colors['grey']); // 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 } ob_start(); imagepng($this->image); $data = ob_get_contents(); if ($data === false) { $data = ob_get_clean(); } ob_clean(); ob_end_clean(); return $data; } // ################################################################### /** * 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 Percentage of 100 */ public function addDataSet($name, $percent) { $this->dataset[] = array($name, intval($percent), $this->_fetchColor()); } // ################################################################### /** * 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 function addDataSetColor($name, $percent, $color) { $this->dataset[] = array($name, intval($percent), imagecolorallocate($this->image, $color[0], $color[1], $color[2])); } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>