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 / Dataset / Function.php next >
Encoding:
PHP Script  |  2008-07-02  |  4.4 KB  |  147 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 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: Function.php,v 1.7 2005/08/24 20:35:57 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.  * Function data set, points are generated by calling an external function.
  38.  *
  39.  * The function must be a single variable function and return a the result,
  40.  * builtin  functions that are fx sin() or cos(). User defined function can be
  41.  * used if they are such, i.e: function myFunction($variable)
  42.  *
  43.  * @category   Images
  44.  * @package    Image_Graph
  45.  * @subpackage Dataset
  46.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  47.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  48.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  49.  * @version    Release: 0.7.2
  50.  * @link       http://pear.php.net/package/Image_Graph
  51.  */
  52. class Image_Graph_Dataset_Function extends Image_Graph_Dataset
  53. {
  54.  
  55.     /**
  56.      * The name of the function
  57.      * @var string
  58.      * @access private
  59.      */
  60.     var $_dataFunction;
  61.  
  62.     /**
  63.      * Image_Graph_FunctionDataset [Constructor]
  64.      *
  65.      * @param double $minimumX The minimum X value
  66.      * @param double $maximumX The maximum X value
  67.      * @param string $function The name of the function, if must be a single
  68.      * parameter function like fx sin(x) or cos(x)
  69.      * @param int $points The number of points to create
  70.      */
  71.     function Image_Graph_Dataset_Function($minimumX, $maximumX, $function, $points)
  72.     {
  73.         parent::Image_Graph_Dataset();
  74.         $this->_minimumX = $minimumX;
  75.         $this->_maximumX = $maximumX;
  76.         $this->_dataFunction = $function;
  77.         $this->_count = $points;
  78.         $this->_calculateMaxima();
  79.     }
  80.  
  81.     /**
  82.      * Add a point to the dataset.
  83.      *
  84.      * You can't add points to a function dataset
  85.      *
  86.      * @param int $x The X value to add
  87.      * @param int $y The Y value to add, can be omited
  88.      * @param var $ID The ID of the point
  89.      */
  90.     function addPoint($x, $y = false, $ID = false)
  91.     {
  92.     }
  93.  
  94.     /**
  95.      * Gets a Y point from the dataset
  96.      *
  97.      * @param var $x The variable to apply the function to
  98.      * @return var The function applied to the X value
  99.      * @access private
  100.      */
  101.     function _getPointY($x)
  102.     {
  103.         $function = $this->_dataFunction;
  104.         return $function ($x);
  105.     }
  106.  
  107.     /**
  108.      * The number of values in the dataset
  109.      *
  110.      * @return int The number of values in the dataset
  111.      * @access private
  112.      */
  113.     function _count()
  114.     {
  115.         return $this->_count;
  116.     }
  117.  
  118.     /**
  119.      * The interval between 2 adjacent Y values
  120.      *
  121.      * @return var The interval
  122.      * @access private
  123.      */
  124.     function _stepX()
  125.     {
  126.         return ($this->_maximumX - $this->_minimumX) / $this->_count();
  127.     }
  128.  
  129.     /**
  130.      * Calculates the Y extrema of the function
  131.      *
  132.      * @access private
  133.      */
  134.     function _calculateMaxima()
  135.     {
  136.         $x = $this->_minimumX;
  137.         while ($x <= $this->_maximumX) {
  138.             $y = $this->_getPointY($x);
  139.             $this->_minimumY = min($y, $this->_minimumY);
  140.             $this->_maximumY = max($y, $this->_maximumY);
  141.             $x += $this->_stepX();
  142.         }
  143.     }
  144.  
  145. }
  146.  
  147. ?>