_primeColors(); $diameter = $this->dimensions['height'] - (5 * self::PADDING); $radius = $diameter / 2; $graphstart = self::PADDING + imagefontheight(5) + self::PADDING; $legendbox = 10; $this->_paintCanvas(); $center = array( 'x' => ($this->legend ? ($radius + self::PADDING) : ($this->dimensions['width'] / 2)), 'y' => ($this->dimensions['height'] / 2) + self::PADDING ); $legx = (2 * self::PADDING) + $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 + 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 + self::SPACING + $legendbox + self::SPACING), ($graphstart + self::SPACING + $boxoffset), $plot[0] . " ($plot[1]%)", $colors['black']); $boxoffset += self::SPACING + $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'] - 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 } return $this->_imageFlush(); } // ################################################################### /** * 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, $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, $percent, imagecolorallocate($this->image, $color[0], $color[1], $color[2])); } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>