- Moving some important things (like painting a blank canvas and allocating common...
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 17 Feb 2007 03:56:55 +0000 (03:56 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 17 Feb 2007 03:56:55 +0000 (03:56 +0000)
- We can now properly label our axes in BSGraphLine, though we don't show any points

Graph.php
GraphLine.php
GraphPie.php
docs/phpdoc.sh

index 9e7b93f848cf8a0de5bb2e3d2d63e3bb11cc5574..fcc63575cb0909244b2087ffb0138e02b68799d2 100644 (file)
--- a/Graph.php
+++ b/Graph.php
@@ -69,6 +69,18 @@ abstract class BSGraph
        */
        protected $title = 'ISSO Pie Chart';
        
+       /**
+       * Padding in the graph
+       * @var  integer
+       */
+       const PADDING = 10;
+       
+       /**
+       * Spacing in the graph
+       * @var  integer
+       */
+       const SPACING = 4;
+       
        // ###################################################################
        /**
        * Constructor
@@ -192,6 +204,42 @@ abstract class BSGraph
                
                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;
+       }
 }
 
 /*=====================================================================*
index 466f2350c6726c6747238f2641424e39c317f4c7..4fbc14d317bbedf0ff5d2cab325afd801166643b 100644 (file)
@@ -55,6 +55,12 @@ class BSGraphLine extends BSGraph
        */
        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
@@ -72,10 +78,45 @@ class BSGraphLine extends BSGraph
                $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);
        }
        
        // ###################################################################
@@ -223,6 +264,19 @@ class BSGraphLine extends BSGraph
        {
                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;
+       }
 }
 
 /*=====================================================================*
index 127077c3ec6b16fd7bae7ef612c59330499c7cc2..ac5c57458953407b30ee96061635c79c9c3037f7 100644 (file)
@@ -56,35 +56,21 @@ class BSGraphPie extends BSGraph
        */
        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;
@@ -98,16 +84,16 @@ class BSGraphPie extends BSGraph
                        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;
                        }
                }
                
@@ -117,10 +103,10 @@ class BSGraphPie extends BSGraph
                // 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();
index f10ad045f0d7ae225ee52872210278cb799e0d6f..898cb4e490aff4e084a51d1157de5fd8ac7d3f8d 100755 (executable)
@@ -31,4 +31,4 @@ mkdir apidoc
 # 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