+++ /dev/null
-<?php
-/*=====================================================================*
-|| ###################################################################
-|| # Blue Static ISSO Framework
-|| # Copyright (c)2002-2007 Blue Static
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version 2 of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-/**
-* Graphing System (Graph.php)
-*
-* @package ISSO
-*/
-
-/**
-* Graphing System
-*
-* This is an abstract class that all other graphing systems extend. It takes
-* care of things like scales, data sets, and dimensions.
-*
-* @author Blue Static
-* @copyright Copyright (c)2002 - 2007, Blue Static
-* @package ISSO
-*
-*/
-abstract class BSGraph
-{
- /**
- * Graphing data set; 2D array of plot information
- * @var array
- */
- protected $dataset = array();
-
- /**
- * Image resource
- * @var resource
- */
- protected $image = null;
-
- /**
- * The dimensions of the image
- * @var array
- */
- protected $dimensions = array('width' => 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;
- }
-}
-
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/*=====================================================================*
-|| ###################################################################
-|| # Blue Static ISSO Framework
-|| # Copyright (c)2002-2007 Blue Static
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version 2 of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-/**
-* Graphing System: Line Graph (GraphLine.php)
-*
-* @package ISSO
-*/
-
-require_once(ISSO . '/Graph.php');
-
-/**
-* Graphing System: Line Graph
-*
-* This creates a line graph from a set of data; each point requires
-* a line name (because this supports multi-line graphing), an x-value,
-* and a y-value. It creates PNG images.
-*
-* @author Blue Static
-* @copyright Copyright (c)2002 - 2007, Blue Static
-* @package ISSO
-*
-*/
-class BSGraphLine extends BSGraph
-{
- /**
- * Graphing dataset; 4D array
- * array(array(name, array(array(xval, yval))), color)
- * @var string
- */
- protected $dataset = array();
-
- /**
- * Array of data points that are used to calculate the standard deviation
- * @var array
- */
- private $piles = array(0 => array(), 1 => array());
-
- /**
- * The names of the axes
- * @var array
- */
- private $axis = array(0 => 'X Axis', 1 => 'Y Axis');
-
- /**
- * Number of ticks to display on the axes
- * @var integer
- */
- private $ticks = 10;
-
- // ###################################################################
- /**
- * Does the actual graphing and returns a byte stream of a PNG image
- *
- * @return string Byte stream
- */
- public function graph()
- {
- $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']);
-
- // just to give us some padding
- $this->ticks++;
-
- // calculates the standard deviation of the two piles to determine the x and y intervals
- $xmin = min($this->piles[0]);
- $xmax = max($this->piles[0]);
- $xint = round(($xmax - $xmin) / $this->ticks);
- $xmin = ($xmin - $xint < 0 ? 0 : $xmin - $xint);
- $xmax = $xmax + $xint;
-
- $ymin = min($this->piles[1]);
- $ymax = max($this->piles[1]);
- $yint = round(($ymax - $ymin) / $this->ticks);
- $ymin = ($ymin - $yint < 0 ? 0 : $ymin - $yint);
- $ymax = $ymax + $yint;
-
- // 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 / $this->ticks))
- {
- 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 / $this->ticks))
- {
- imageline($this->image, $originx, $i, $endx, $i, $colors['grey']);
- imagestring($this->image, 1, self::SPACING + self::SPACING + self::PADDING + self::SPACING, $i - self::SPACING, round($count), $colors['black']);
- $count += $yint;
- }
-
- // draw the legend
- $legy = $endy + self::SPACING; // "cursor" y-coord for the legend
- $legx = $endx + self::PADDING; // x-coord for the legend BORDER
- $legex = $this->dimensions['width'] - self::PADDING; // end x-coord for the legend BORDER
- imageline($this->image, $legx, $endy, $legex, $endy, $colors['black']); // top legend border
-
- // go through and plot each dataset
- foreach ($this->dataset AS $data)
- {
- // plot each point and connect the dots
- $oldpoint = null;
- foreach ($data[1] AS $points)
- {
- $xcord = $originx + ($points[0] * ($length / $xmax));
- $ycord = $originy - ($points[1] * ($height / $ymax));
- imagefilledellipse($this->image, $xcord, $ycord, 5, 5, $data[2]);
- if ($oldpoint)
- {
- imageline($this->image, $xcord, $ycord, $oldpoint[0], $oldpoint[1], $data[2]);
- }
- $oldpoint = array($xcord, $ycord);
- }
-
- // draw the legend bit
- $box = array(
- $legx + 1 + self::SPACING, $legy, // top left
- $legx + 1 + self::SPACING, $legy + self::PADDING, // bottom left
- $legx + 11 + self::SPACING, $legy + self::PADDING, // bottom right
- $legx + 11 + self::SPACING, $legy // top right
- );
- imagefilledpolygon($this->image, $box, 4, $data[2]);
- imagestring($this->image, 2, $legx + 11 + self::SPACING + self::SPACING, $legy - 1, $data[0], $colors['black']);
- $legy += self::PADDING + self::SPACING;
- }
-
- // finish the legend border
- imageline($this->image, $legx, $legy, $legex, $legy, $colors['black']); // bottom
- imageline($this->image, $legx, $endy, $legx, $legy, $colors['black']); // left
- imageline($this->image, $legex, $endy, $legex, $legy, $colors['black']); // right
-
- return $this->_imageFlush();
- }
-
- // ###################################################################
- /**
- * Adds a "line" with a given name and a set of datapoints in the form
- * array(x, y)
- *
- * @param string The line's name
- * @param array Array of array(x,y) as data points
- */
- public function addDataSet($name, $points)
- {
- $this->_addPoints($points);
- $this->_sortPoints($points);
- $this->dataset[] = array($name, $points, $this->_fetchColor());
- }
-
- // ###################################################################
- /**
- * This does the same thing as addDataSet(), except the client code
- * can specify the color in the form of array(R, G, B)
- *
- * @param string The line's name
- * @param array Array of array(x,y) as data points
- * @param array A color in the form of 3 RGB points
- */
- public function addDataSetColor($name, $points, $color)
- {
- $this->_addPoints($points);
- $this->_sortPoints($points);
- $this->dataset[] = array($name, $points, imagecolorallocate($this->image, $color[0], $color[1], $color[2]));
- }
-
- // ###################################################################
- /**
- * Adds a set of points to the piles and ensures that they are all valid
- *
- * @param array Points to add
- */
- private function _addPoints($points)
- {
- $xpairs = array();
- foreach ($points AS $point)
- {
- if (isset($xpairs["$point[0]"]))
- {
- trigger_error('You cannot have more than one of the same x-values for a given data set');
- }
- $xpairs["$point[0]"] = $point[0];
- $this->piles[0][] = $point[0];
- $this->piles[1][] = $point[1];
- }
- }
-
- // ###################################################################
- /**
- * Sorts an array of points using quick sort so they're in x-increasing
- * order
- *
- * @param array Array of points
- */
- private function _sortPoints(&$points)
- {
- $this->_quickSortPoints($points, 0, sizeof($points) - 1);
- }
-
- // ###################################################################
- /**
- * Quicksort function for sorting function
- *
- * @param array Array of points
- * @param integer Lower bound
- * @param integer Upper bound
- */
- private function _quickSortPoints(&$points, $low, $high)
- {
- if (($high - $low) > 1)
- {
- $partition = $this->_partitionPoints($points, $low, $high);
- $this->_quickSortPoints($points, $low, $partition);
- $this->_quickSortPoints($points, $partition + 1, $high);
- }
- }
-
- // ###################################################################
- /**
- * Quicksort partitioner: returns the index of the pivot element where
- * all x-coords on the left side of pivot are less than or equal to
- * pivot, and all x-coords are higher to the right
- *
- * @param array Array of points
- * @param integer Lower bound
- * @param integer Upper bound
- *
- * @return integer Pivot index
- */
- private function _partitionPoints(&$points, $low, $high)
- {
- $pivot = $low;
- for ($unsorted = $low + 1; $unsorted <= $high; $unsorted++)
- {
- if ($points[$unsorted][0] < $points[$pivot][0])
- {
- $temp = $points[$pivot];
- $points[$pivot] = $points[$unsorted];
- $points[$unsorted] = $points[$pivot + 1];
- $points[$pivot + 1] = $temp;
- $pivot++;
- }
- }
- return $pivot;
- }
-
- // ###################################################################
- /**
- * 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;
- }
-}
-
-?>
\ No newline at end of file
+++ /dev/null
-<?php
-/*=====================================================================*\
-|| ###################################################################
-|| # Blue Static ISSO Framework
-|| # Copyright (c)2002-2007 Blue Static
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version 2 of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-/**
-* Graphing System: Pie Chart (GraphPie.php)
-*
-* @package ISSO
-*/
-
-require_once(ISSO . '/Graph.php');
-
-/**
-* Graphing System: Pie Chart
-*
-* This framework creates pie charts as PNG image strings. Simply add to
-* the data set and graph to get the byte stream returned.
-*
-* @author Blue Static
-* @copyright Copyright (c)2002 - 2007, Blue Static
-* @package ISSO
-*
-*/
-class BSGraphPie extends BSGraph
-{
- /**
- * Graphing data set; 2D array of
- * array(NAME, PERCENT, COLOR)
- * @var array
- */
- protected $dataset = array();
-
- // ###################################################################
- /**
- * Graphs the actual graph and returns a byte stream
- *
- * @return string Byte stream
- */
- public function graph()
- {
- $colors = $this->_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]));
- }
-}
-
-?>
\ No newline at end of file