[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Image/Graph/Plot/ -> Area.php (source)

   1  <?php
   2  
   3  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   4  
   5  /**
   6   * Image_Graph - PEAR PHP OO Graph Rendering Utility.
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * LICENSE: This library is free software; you can redistribute it and/or modify
  11   * it under the terms of the GNU Lesser General Public License as published by
  12   * the Free Software Foundation; either version 2.1 of the License, or (at your
  13   * option) any later version. This library is distributed in the hope that it
  14   * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15   * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  16   * General Public License for more details. You should have received a copy of
  17   * the GNU Lesser General Public License along with this library; if not, write
  18   * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19   * 02111-1307 USA
  20   *
  21   * @category   Images
  22   * @package    Image_Graph
  23   * @subpackage Plot
  24   * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  25   * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  26   * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  27   * @version    CVS: $Id: Area.php,v 1.13 2005/11/27 22:21:17 nosey Exp $
  28   * @link       http://pear.php.net/package/Image_Graph
  29   */
  30  
  31  /**
  32   * Include file Image/Graph/Plot.php
  33   */
  34  require_once  'Image/Graph/Plot.php';
  35  
  36  /**
  37   * Area Chart plot.
  38   *
  39   * An area chart plots all data points similar to a {@link
  40   * Image_Graph_Plot_Line}, but the area beneath the line is filled and the whole
  41   * area 'the-line', 'the right edge', 'the x-axis' and 'the left edge' is
  42   * bounded. Smoothed charts are only supported with non-stacked types
  43   *
  44   * @category   Images
  45   * @package    Image_Graph
  46   * @subpackage Plot
  47   * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  48   * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  49   * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  50   * @version    Release: 0.7.2
  51   * @link       http://pear.php.net/package/Image_Graph
  52   */
  53  class Image_Graph_Plot_Area extends Image_Graph_Plot
  54  {
  55  
  56      /**
  57       * Perform the actual drawing on the legend.
  58       *
  59       * @param int $x0 The top-left x-coordinate
  60       * @param int $y0 The top-left y-coordinate
  61       * @param int $x1 The bottom-right x-coordinate
  62       * @param int $y1 The bottom-right y-coordinate
  63       * @access private
  64       */
  65      function _drawLegendSample($x0, $y0, $x1, $y1)
  66      {
  67          $dx = abs($x1 - $x0) / 3;
  68          $dy = abs($y1 - $y0) / 3;
  69          $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));
  70          $this->_canvas->addVertex(array('x' => $x0, 'y' => $y0 + $dy));
  71          $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0));
  72          $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0 + 2*$dy));
  73          $this->_canvas->addVertex(array('x' => $x1, 'y' => $y0 + $dy));
  74          $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));
  75          $this->_canvas->polygon(array('connect' => true));
  76      }
  77  
  78      /**
  79       * Output the plot
  80       *
  81       * @return bool Was the output 'good' (true) or 'bad' (false).
  82       * @access private
  83       */
  84      function _done()
  85      {
  86          if (parent::_done() === false) {
  87              return false;
  88          }
  89          
  90          $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
  91  
  92          $this->_clip(true);        
  93  
  94          $base = array();
  95          if ($this->_multiType == 'stacked') {
  96              reset($this->_dataset);
  97              $key = key($this->_dataset);
  98              $dataset =& $this->_dataset[$key];
  99  
 100              $first = $dataset->first();
 101              $point = array ('X' => $first['X'], 'Y' => '#min_pos#');
 102              $base[] = array();
 103              $base[] = $this->_pointY($point);
 104              $first = $this->_pointX($point);
 105              $base[] = $first;
 106      
 107              $last = $dataset->last();
 108              $point = array ('X' => $last['X'], 'Y' => '#min_pos#');
 109              $base[] = array();
 110              $base[] = $this->_pointY($point);
 111              $base[] = $this->_pointX($point);
 112                      
 113              $current = array();
 114          }
 115  
 116          $minYaxis = $this->_parent->_getMinimum($this->_axisY);
 117          $maxYaxis = $this->_parent->_getMaximum($this->_axisY);
 118  
 119          $keys = array_keys($this->_dataset);
 120          foreach ($keys as $key) {
 121              $dataset =& $this->_dataset[$key];
 122              $dataset->_reset();
 123              if ($this->_multiType == 'stacked') {
 124                  $plotarea = array_reverse($base);
 125                  $base = array();
 126                  while ($point = $dataset->_next()) {
 127                      $x = $point['X'];
 128                      $p = $point;
 129                      if (isset($current[$x])) {
 130                          $p['Y'] += $current[$x];
 131                      } else {
 132                          $current[$x] = 0;
 133                      }
 134                      $x1 = $this->_pointX($p);
 135                      $y1 = $this->_pointY($p);
 136                      $plotarea[] = $x1;
 137                      $plotarea[] = $y1;
 138                      $plotarea[] = $point;
 139                      $base[] = array();
 140                      $base[] = $y1;
 141                      $base[] = $x1;
 142                      $current[$x] += $point['Y'];
 143                  }
 144              } else {
 145                  $first = true;
 146                  $plotarea = array();
 147                  while ($point = $dataset->_next()) {
 148                      if ($first) {
 149                          $firstPoint = array ('X' => $point['X'], 'Y' => '#min_pos#');
 150                          $plotarea[] = $this->_pointX($firstPoint);
 151                          $plotarea[] = $this->_pointY($firstPoint);
 152                          $plotarea[] = array();
 153                      }
 154                      $plotarea[] = $this->_pointX($point);
 155                      $plotarea[] = $this->_pointY($point);
 156                      $plotarea[] = $point;
 157                      $lastPoint = $point;
 158                      $first = false;
 159                  }
 160                  $endPoint['X'] = $lastPoint['X'];
 161                  $endPoint['Y'] = '#min_pos#';
 162                  $plotarea[] = $this->_pointX($endPoint);
 163                  $plotarea[] = $this->_pointY($endPoint);
 164                  $plotarea[] = array();
 165              }
 166  
 167              reset($plotarea);
 168              while (list(, $x) = each($plotarea)) {
 169                  list(, $y) = each($plotarea);
 170                  list(, $data) = each($plotarea);
 171                  $this->_canvas->addVertex(
 172                      $this->_mergeData(
 173                          $data,
 174                          array('x' => $x, 'y' => $y)
 175                      )
 176                  );
 177              }
 178  
 179              $this->_getFillStyle($key);
 180              $this->_getLineStyle($key);
 181              $this->_canvas->polygon(array('connect' => true, 'map_vertices' => true));
 182          }
 183          unset($keys);
 184          $this->_drawMarker();
 185          $this->_clip(false);
 186                  
 187          $this->_canvas->endGroup();
 188  
 189          return true;
 190      }
 191  
 192  }
 193  
 194  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7