[ 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/Fit/ -> Line.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: Line.php,v 1.2 2005/11/27 22:21:18 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   * Include file Image/Graph/Tool.php
  38   */
  39  require_once  'Image/Graph/Tool.php';
  40  
  41  /**
  42   * Fit the graph (to a line using linear regression).
  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_Fit_Line 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          $y = ($y0 + $y1) / 2;
  68          $dy = abs($y1 - $y0) / 6;
  69          $this->_canvas->addVertex(array('x' => $x0, 'y' => $y + $dy));
  70          $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $dy));
  71          $this->_canvas->polygon(array('connect' => false));
  72      }
  73      
  74      /**
  75       * Output the plot
  76       *
  77       * @return bool Was the output 'good' (true) or 'bad' (false).
  78       * @access private
  79       */
  80      function _done()
  81      {
  82          if (Image_Graph_Plot::_done() === false) {
  83              return false;
  84          }
  85  
  86          $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
  87          $this->_clip(true);
  88          $keys = array_keys($this->_dataset);
  89          foreach ($keys as $key) {
  90              $dataset =& $this->_dataset[$key];
  91              $dataset->_reset();
  92              $data = array();
  93              while ($point = $dataset->_next()) {
  94                  $data[] = array(
  95                      'X' => $this->_pointX($point),
  96                      'Y' => $this->_pointY($point)
  97                  );
  98              }
  99  
 100              $regression = Image_Graph_Tool::calculateLinearRegression($data);
 101              $this->_getLineStyle($key);
 102              $this->_canvas->line(
 103                  array(
 104                      'x0' => $this->_left,
 105                      'y0' => $this->_left * $regression['slope'] + $regression['intersection'],
 106                      'x1' => $this->_right,
 107                      'y1' => $this->_right * $regression['slope'] + $regression['intersection']
 108                  )
 109              );
 110          }
 111          $this->_clip(false);
 112          $this->_canvas->endGroup();
 113          
 114          return true;
 115      }
 116  }
 117  
 118  ?>


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