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 / Layout / Horizontal.php next >
Encoding:
PHP Script  |  2008-07-02  |  6.0 KB  |  186 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 Layout
  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: Horizontal.php,v 1.11 2006/02/28 22:48:07 nosey Exp $
  28.  * @link       http://pear.php.net/package/Image_Graph
  29.  */
  30.  
  31. /**
  32.  * Include file Image/Graph/Layout.php
  33.  */
  34. require_once 'Image/Graph/Layout.php';
  35.  
  36. /**
  37.  * Layout for displaying two elements side by side.
  38.  *
  39.  * This splits the area contained by this element in two, side by side by
  40.  * a specified percentage (relative to the left side). A layout can be nested.
  41.  * Fx. a HorizontalLayout can layout two {@link Image_Graph_Layout_Vertical}s to
  42.  * make a 2 by 2 matrix of 'element-areas'.
  43.  *
  44.  * @category   Images
  45.  * @package    Image_Graph
  46.  * @subpackage Layout
  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_Layout_Horizontal extends Image_Graph_Layout
  54. {
  55.  
  56.     /**
  57.      * Part1 of the layout
  58.      * @var GraPHPElemnt
  59.      * @access private
  60.      */
  61.     var $_part1 = false;
  62.  
  63.     /**
  64.      * Part2 of the layout
  65.      * @var GraPHPElemnt
  66.      * @access private
  67.      */
  68.     var $_part2 = false;
  69.  
  70.     /**
  71.      * The percentage of the graph where the split occurs
  72.      * @var int
  73.      * @access private
  74.      */
  75.     var $_percentage;
  76.  
  77.     /**
  78.      * An absolute position where the split occurs
  79.      * @var int
  80.      * @access private
  81.      */
  82.     var $_absolute;
  83.  
  84.     /**
  85.      * HorizontalLayout [Constructor]
  86.      *
  87.      * @param Image_Graph_Element $part1 The 1st part of the layout
  88.      * @param Image_Graph_Element $part2 The 2nd part of the layout
  89.      * @param int $percentage The percentage of the layout to split at
  90.      */
  91.     function Image_Graph_Layout_Horizontal(& $part1, & $part2, $percentage = 50)
  92.     {
  93.         parent::Image_Graph_Layout();
  94.         if (!is_a($part1, 'Image_Graph_Layout')) {
  95.             $this->_error(
  96.                 'Cannot create layout on non-layouable parts: ' . get_class($part1),
  97.                 array('part1' => &$part1, 'part2' => &$part2)
  98.             );
  99.         } elseif (!is_a($part2, 'Image_Graph_Layout')) {
  100.             $this->_error(
  101.                 'Cannot create layout on non-layouable parts: ' . get_class($part2),
  102.                 array('part1' => &$part1, 'part2' => &$part2)
  103.             );
  104.         } else {
  105.             $this->_part1 =& $part1;
  106.             $this->_part2 =& $part2;
  107.             $this->add($this->_part1);
  108.             $this->add($this->_part2);
  109.         };
  110.         if ($percentage === 'auto') {
  111.             $this->_percentage = false;
  112.             $this->_absolute = 'runtime';
  113.         } else {
  114.             $this->_absolute = false;
  115.             $this->_percentage = max(0, min(100, $percentage));
  116.         }
  117.         $this->_split();
  118.         $this->_padding = array('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);
  119.     }
  120.  
  121.     /**
  122.      * Gets the absolute size of one of the parts.
  123.      *
  124.      * @param string $part The name of the part - auto_part(1|2)
  125.      * @return int The number of pixels the edge should be pushed
  126.      * @since 0.3.0dev2
  127.      * @access private
  128.      */    
  129.     function _getAbsolute(&$part)
  130.     {
  131.         $part1Size = $this->_part1->_getAutoSize();
  132.         $part2Size = $this->_part2->_getAutoSize();
  133.         $this->_percentage = false;
  134.         if (($part1Size !== false) and ($part2Size !== false)) {
  135.             $width = $this->_fillWidth() * $part1Size / ($part1Size + $part2Size);
  136.         } elseif ($part1Size !== false) {
  137.             $width = $part1Size;
  138.         } elseif ($part2Size !== false) {
  139.             $width = -$part2Size;
  140.         } else {
  141.             $width = $this->_fillWidth() / 2;
  142.         }
  143.         if ($part == 'auto_part2') {
  144.             $width = -$width;
  145.         }
  146.  
  147.         return $width;
  148.     }
  149.  
  150.     /**
  151.      * Splits the layout between the parts, by the specified percentage
  152.      *
  153.      * @access private
  154.      */
  155.     function _split()
  156.     {
  157.         if (($this->_part1) && ($this->_part2)) {
  158.             if ($this->_percentage !== false) {
  159.                 $split1 = 100 - $this->_percentage;
  160.                 $split2 = $this->_percentage;
  161.                 $this->_part1->_push('right', "$split1%");
  162.                 $this->_part2->_push('left', "$split2%");
  163.             } else {
  164.                 $this->_part1->_push('right', 'auto_part1');
  165.                 $this->_part2->_push('left', 'auto_part2');
  166.             }
  167.         }
  168.     }
  169.  
  170.     /**
  171.      * Output the layout to the canvas
  172.      *
  173.      * @return bool Was the output 'good' (true) or 'bad' (false).
  174.      * @access private
  175.      */
  176.     function _done()
  177.     {
  178.         if (($this->_part1) && ($this->_part2)) {
  179.             return (($this->_part1->_done()) && ($this->_part2->_done()));            
  180.         }
  181.         return true;
  182.     }
  183.  
  184. }
  185.  
  186. ?>