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 / Smoothed / Bezier.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.4 KB  |  173 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: Bezier.php,v 1.8 2005/08/24 20:36:02 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.  * Bezier smoothed plottype.
  43.  *
  44.  * The framework for calculating the Bezier smoothed curve from the dataset.
  45.  * Used in {@link Image_Graph_Plot_Smoothed_Line} and {@link
  46.  * Image_Graph_Plot_Smoothed_Area}. Smoothed charts are only supported with non-
  47.  * stacked types
  48.  * @link http://homepages.borland.com/efg2lab/Graphics/Jean-
  49.  * YvesQueinecBezierCurves.htm efg computer lab - description of bezier curves
  50.  *
  51.  * @category   Images
  52.  * @package    Image_Graph
  53.  * @subpackage Plot
  54.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  55.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  56.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  57.  * @version    Release: 0.7.2
  58.  * @link       http://pear.php.net/package/Image_Graph
  59.  * @abstract
  60.  */
  61. class Image_Graph_Plot_Smoothed_Bezier extends Image_Graph_Plot
  62. {
  63.  
  64.     /**
  65.      * Image_Graph_Plot_Smoothed_Bezier [Constructor]
  66.      *
  67.      * Only 'normal' multitype supported
  68.      *
  69.      * @param Dataset $dataset The data set (value containter) to plot
  70.      * @param string $title The title of the plot (used for legends, {@link
  71.      *   Image_Graph_Legend})
  72.      */
  73.     function Image_Graph_Plot_Smoothed_Bezier(& $dataset, $title = '')
  74.     {
  75.         parent::Image_Graph_Plot($dataset, 'normal', $title);
  76.     }
  77.  
  78.     /**
  79.      * Return the minimum Y point
  80.      *
  81.      * @return double The minumum Y point
  82.      * @access private
  83.      */
  84.     function _minimumY()
  85.     {
  86.         return 1.05 * parent::_minimumY();
  87.     }
  88.  
  89.     /**
  90.      * Return the maximum Y point
  91.      *
  92.      * @return double The maximum Y point
  93.      * @access private
  94.      */
  95.     function _maximumY()
  96.     {
  97.         return 1.05 * parent::_maximumY();
  98.     }
  99.  
  100.     /**
  101.      * Calculates all Bezier points, for the curve
  102.      *
  103.      * @param array $p1 The actual point to calculate control points for
  104.      * @param array $p0 The point "just before" $p1
  105.      * @param array $p2 The point "just after" $p1
  106.      * @param array $p3 The point "just after" $p2
  107.      * @return array Array of Bezier points
  108.      * @access private
  109.      */
  110.     function _getControlPoints($p1, $p0, $p2, $p3)
  111.     {
  112.         $p1 = $this->_pointXY($p1);
  113.         if ($p2) {
  114.             $p2 = $this->_pointXY($p2);
  115.         }
  116.         if (!$p0) {
  117.             $p0['X'] = $p1['X'] - abs($p2['X'] - $p1['X']);
  118.             $p0['Y'] = $p1['Y']; //-($p2['Y']-$p1['Y']);
  119.         } else {
  120.             $p0 = $this->_pointXY($p0);
  121.         }
  122.         if (!$p3) {
  123.             $p3['X'] = $p1['X'] + 2*abs($p1['X'] - $p0['X']);
  124.             $p3['Y'] = $p1['Y'];
  125.         } else {
  126.             $p3 = $this->_pointXY($p3);
  127.         }
  128.  
  129.         if (!$p2) {
  130.             $p2['X'] = $p1['X'] + abs($p1['X'] - $p0['X']);
  131.             $p2['Y'] = $p1['Y'];
  132.         }
  133.  
  134.         $pC1['X'] = Image_Graph_Tool::controlPoint($p0['X'], $p1['X'], $p2['X']);
  135.         $pC1['Y'] = Image_Graph_Tool::controlPoint($p0['Y'], $p1['Y'], $p2['Y']);
  136.         $pC2['X'] = Image_Graph_Tool::controlPoint($p3['X'], $p2['X'], $p1['X']);
  137.         $pC2['Y'] = Image_Graph_Tool::controlPoint($p3['Y'], $p2['Y'], $p1['Y']);
  138.  
  139.         return array(
  140.             'X' => $p1['X'],
  141.             'Y' => $p1['Y'],
  142.             'P1X' => $pC1['X'],
  143.             'P1Y' => $pC1['Y'],
  144.             'P2X' => $pC2['X'],
  145.             'P2Y' => $pC2['Y']
  146.         );
  147.     }
  148.  
  149.     /**
  150.      * Create legend sample data for the canvas.
  151.      *
  152.      * Common for all smoothed plots
  153.      *
  154.      * @access private
  155.      */
  156.     function _addSamplePoints($x0, $y0, $x1, $y1)
  157.     {
  158.         $p = abs($x1 - $x0);
  159.         $cy = ($y0 + $y1) / 2;
  160.         $h = abs($y1 - $y0);
  161.         $dy = $h / 4;
  162.         $dw = abs($x1 - $x0) / $p;
  163.         for ($i = 0; $i < $p; $i++) {
  164.             $v = 2 * pi() * $i / $p;
  165.             $x = $x0 + $i * $dw;
  166.             $y = $cy + 2 * $v * sin($v);
  167.             $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
  168.         }
  169.     }
  170.  
  171. }
  172.  
  173. ?>