home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / Graph / Plot / Line.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.7 KB  |  171 lines

  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.15 2006/03/02 12:37:37 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.  * Linechart.
  38.  *
  39.  * @category   Images
  40.  * @package    Image_Graph
  41.  * @subpackage Plot
  42.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  43.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  44.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  45.  * @version    Release: 0.7.2
  46.  * @link       http://pear.php.net/package/Image_Graph
  47.  */
  48. class Image_Graph_Plot_Line extends Image_Graph_Plot
  49. {
  50.  
  51.     /**
  52.      * Gets the fill style of the element
  53.      *
  54.      * @return int A GD filestyle representing the fill style
  55.      * @see Image_Graph_Fill
  56.      * @access private
  57.      */
  58.     function _getFillStyle($ID = false)
  59.     {
  60.         return IMG_COLOR_TRANSPARENT;
  61.     }
  62.  
  63.     /**
  64.      * Perform the actual drawing on the legend.
  65.      *
  66.      * @param int $x0 The top-left x-coordinate
  67.      * @param int $y0 The top-left y-coordinate
  68.      * @param int $x1 The bottom-right x-coordinate
  69.      * @param int $y1 The bottom-right y-coordinate
  70.      * @access private
  71.      */
  72.     function _drawLegendSample($x0, $y0, $x1, $y1)
  73.     {
  74.         $y = ($y0 + $y1) / 2;
  75.         $dx = abs($x1 - $x0) / 3;
  76.         $dy = abs($y1 - $y0) / 5;
  77.         $this->_canvas->addVertex(array('x' => $x0, 'y' => $y));
  78.         $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y - $dy * 2));
  79.         $this->_canvas->addVertex(array('x' => $x1 - $dx, 'y' => $y + $dy));
  80.         $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $dy));
  81.         $this->_canvas->polygon(array('connect' => false));
  82.     }
  83.  
  84.     /**
  85.      * Output the plot
  86.      *
  87.      * @return bool Was the output 'good' (true) or 'bad' (false).
  88.      * @access private
  89.      */
  90.     function _done()
  91.     {
  92.         if (parent::_done() === false) {
  93.             return false;
  94.         }
  95.  
  96.         if (!is_array($this->_dataset)) {
  97.             return false;
  98.         }
  99.         
  100.         $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
  101.         $this->_clip(true);
  102.         reset($this->_dataset);
  103.  
  104.         if ($this->_multiType == 'stacked100pct') {
  105.             $total = $this->_getTotals();
  106.         }
  107.  
  108.         $p1 = false;
  109.  
  110.         $keys = array_keys($this->_dataset);
  111.         foreach ($keys as $key) {
  112.             $dataset =& $this->_dataset[$key];
  113.             $dataset->_reset();
  114.             $numPoints = 0;
  115.             while ($point = $dataset->_next()) {
  116.                 if (($this->_multiType == 'stacked') ||
  117.                     ($this->_multiType == 'stacked100pct'))
  118.                 {
  119.                     $x = $point['X'];
  120.                     if (!isset($current[$x])) {
  121.                         $current[$x] = 0;
  122.                     }
  123.                     if ($this->_multiType == 'stacked') {
  124.                         $py = $current[$x] + $point['Y'];
  125.                     } else {
  126.                         $py = 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x];
  127.                     }
  128.                     $current[$x] += $point['Y'];
  129.                     $point['Y'] = $py;
  130.                 }
  131.  
  132.                 if ($point['Y'] === null) {
  133.                     if ($numPoints > 1) {
  134.                         $this->_getLineStyle($key);
  135.                         $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));
  136.                     }
  137.                     else {
  138.                         $this->_canvas->reset();
  139.                     }
  140.                     $numPoints = 0;
  141.                 } else {
  142.                     $p2['X'] = $this->_pointX($point);
  143.                     $p2['Y'] = $this->_pointY($point);
  144.     
  145.                     $this->_canvas->addVertex(
  146.                         $this->_mergeData(
  147.                             $point,
  148.                             array('x' => $p2['X'], 'y' => $p2['Y'])
  149.                         )
  150.                     );
  151.                     $numPoints++;
  152.                 }
  153.             }
  154.             if ($numPoints > 1) {
  155.                 $this->_getLineStyle($key);
  156.                 $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));
  157.             }
  158.             else {
  159.                 $this->_canvas->reset();
  160.             }
  161.         }
  162.         unset($keys);
  163.         $this->_drawMarker();
  164.         $this->_clip(false);
  165.         $this->_canvas->endGroup();
  166.         return true;
  167.     }
  168.  
  169. }
  170.  
  171. ?>