[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/Image/Graph/Dataset/ -> Trivial.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 Dataset
  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: Trivial.php,v 1.10 2005/09/25 18:08:56 nosey Exp $
  28   * @link       http://pear.php.net/package/Image_Graph
  29   */
  30  
  31  /**
  32   * Include file Image/Graph/Dataset.php
  33   */
  34  require_once  'Image/Graph/Dataset.php';
  35  
  36  /**
  37   * Trivial data set, simply add points (x, y) 1 by 1
  38   *
  39   * @category   Images
  40   * @package    Image_Graph
  41   * @subpackage Dataset
  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_Dataset_Trivial extends Image_Graph_Dataset
  49  {
  50  
  51      /**
  52       * Data storage
  53       * @var array
  54       * @access private
  55       */
  56      var $_data;
  57  
  58      /**
  59       * Image_Graph_Dataset_Trivial [Constructor]
  60       *
  61       * Pass an associated array ($data[$x] = $y) to the constructor for easy
  62       * data addition. Alternatively (if multiple entries with same x value is
  63       * required) pass an array with (x, y) values: $data[$id] = array('x' => $x,
  64       * 'y' => $y); 
  65       *
  66       * NB! If passing the 1st type array at this point, the x-values will also
  67       * be used for ID tags, i.e. when using {@link Image_Graph_Fill_Array}. In
  68       * the 2nd type the key/index of the "outermost" array will be the id tag
  69       * (i.e. $id in the example)
  70       *
  71       * @param array $dataArray An associated array with values to the dataset
  72       */
  73      function Image_Graph_Dataset_Trivial($dataArray = false)
  74      {
  75          parent::Image_Graph_Dataset();
  76          $this->_data = array ();
  77          if (is_array($dataArray)) {
  78              reset($dataArray);
  79              $keys = array_keys($dataArray);
  80              foreach ($keys as $x) {
  81                  $y =& $dataArray[$x];
  82                  if ((is_array($y)) && (isset($y['x'])) && (isset($y['y']))) {
  83                      $this->addPoint($y['x'], $y['y'], (isset($y['id']) ? $y['id'] : $x));
  84                  } else {
  85                      $this->addPoint($x, $y, $x);
  86                  }
  87              }
  88          }
  89      }
  90  
  91      /**
  92       * Add a point to the dataset
  93       *
  94       * $ID can contain either the ID of the point, i.e. 'DK', 123, 'George', etc. or it can contain
  95       * values used for creation of the HTML image map. This is achieved using is an an associated array
  96       * with the following values:
  97       * 
  98       * 'url' The URL to create the link to
  99       * 
 100       * 'alt' [optional] The alt text on the link
 101       * 
 102       * 'target' [optional] The target of the link
 103       * 
 104       * 'htmltags' [optional] An associated array with html tags (tag as key), fx. 'onMouseOver' => 'history.go(-1);', 'id' => 'thelink'
 105       *
 106       * @param int $x The X value to add
 107       * @param int $y The Y value to add, can be omited
 108       * @param var $ID The ID of the point
 109       */
 110      function addPoint($x, $y = false, $ID = false)
 111      {
 112          parent::addPoint($x, $y, $ID);
 113  
 114          if (is_array($ID)) {
 115              $data = $ID;
 116              $ID = (isset($data['id']) ? $data['id'] : false);
 117          } else {
 118              $data = false;
 119          }
 120  
 121          $this->_data[] = array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);
 122          if (!is_numeric($x)) {
 123              $this->_maximumX = count($this->_data);
 124          }
 125      }
 126  
 127      /**
 128       * The first point
 129       *
 130       * @return array The last point
 131       */
 132      function first()
 133      {
 134          reset($this->_data);
 135          return current($this->_data);
 136      }
 137  
 138      /**
 139       * The last point
 140       *
 141       * @return array The first point
 142       */
 143      function last()
 144      {
 145          return end($this->_data);
 146      }
 147  
 148      /**
 149       * Gets a X point from the dataset
 150       *
 151       * @param var $x The variable to return an X value from, fx in a
 152       *   vector function data set
 153       * @return var The X value of the variable
 154       * @access private
 155       */
 156      function _getPointX($x)
 157      {
 158          if (isset($this->_data[$x])) {
 159              return $this->_data[$x]['X'];
 160          } else {
 161              return false;
 162          }
 163      }
 164  
 165      /**
 166       * Gets a Y point from the dataset
 167       *
 168       * @param var $x The variable to return an Y value from, fx in a
 169       *   vector function data set
 170       * @return var The Y value of the variable
 171       * @access private
 172       */
 173      function _getPointY($x)
 174      {
 175          if (isset($this->_data[$x])) {
 176              return $this->_data[$x]['Y'];
 177          } else {
 178              return false;
 179          }
 180      }
 181  
 182      /**
 183       * Gets a ID from the dataset
 184       *
 185       * @param var $x The variable to return an Y value from, fx in a
 186       *   vector function data set
 187       * @return var The ID value of the variable
 188       * @access private
 189       */
 190      function _getPointID($x)
 191      {
 192          if (isset($this->_data[$x])) {
 193              return $this->_data[$x]['ID'];
 194          } else {
 195              return false;
 196          }
 197      }
 198  
 199      /**
 200       * Gets point data from the dataset
 201       *
 202       * @param var $x The variable to return an Y value from, fx in a vector
 203       *   function data set
 204       * @return array The data for the point
 205       * @access private
 206       */
 207      function _getPointData($x)
 208      {
 209          if (isset($this->_data[$x])) {
 210              return $this->_data[$x]['data'];
 211          } else {
 212              return false;
 213          }
 214      }
 215      
 216      /**
 217       * The number of values in the dataset
 218       *
 219       * @return int The number of values in the dataset
 220       */
 221      function count()
 222      {
 223          return count($this->_data);
 224      }
 225  
 226      /**
 227       * Reset the intertal dataset pointer
 228       *
 229       * @return var The first X value
 230       * @access private
 231       */
 232      function _reset()
 233      {
 234          $this->_posX = 0;
 235          return $this->_posX;
 236      }
 237  
 238      /**
 239       * Get the next point the internal pointer refers to and advance the pointer
 240       *
 241       * @return array The next point
 242       * @access private
 243       */
 244      function _next()
 245      {
 246          if ($this->_posX >= $this->count()) {
 247              return false;
 248          }
 249          $x = $this->_getPointX($this->_posX);
 250          $y = $this->_getPointY($this->_posX);
 251          $ID = $this->_getPointID($this->_posX);
 252          $data = $this->_getPointData($this->_posX);
 253          $this->_posX += $this->_stepX();
 254  
 255          return array('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);
 256      }
 257  
 258  }
 259  
 260  ?>


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