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 / Matrix.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  6.1 KB  |  201 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: Matrix.php,v 1.8 2005/08/24 20:35:58 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 elements in a matix.
  38.  *
  39.  * @category   Images
  40.  * @package    Image_Graph
  41.  * @subpackage Layout
  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_Layout_Matrix extends Image_Graph_Layout
  49. {
  50.  
  51.     /**
  52.      * Layout matrix
  53.      * @var array
  54.      * @access private
  55.      */
  56.     var $_matrix = false;
  57.  
  58.     /**
  59.      * The number of rows
  60.      * @var int
  61.      * @access private
  62.      */
  63.     var $_rows = false;
  64.  
  65.     /**
  66.      * The number of columns
  67.      * @var int
  68.      * @access private
  69.      */
  70.     var $_cols = false;
  71.  
  72.     /**
  73.      * Image_Graph_Layout_Matrix [Constructor]
  74.      *
  75.      * @param int $rows The number of rows
  76.      * @param int $cols The number of cols
  77.      * @param bool $autoCreate Specifies whether the matrix should automatically
  78.      *   be filled with newly created Image_Graph_Plotares objects, or they will
  79.      *   be added manually
  80.      */
  81.     function Image_Graph_Layout_Matrix($rows, $cols, $autoCreate = true)
  82.     {
  83.         parent::Image_Graph_Layout();
  84.  
  85.         $this->_rows = $rows;
  86.         $this->_cols = $cols;
  87.         if (($this->_rows > 0) && ($this->_cols > 0)) {
  88.             $this->_matrix = array(array());
  89.             for ($i = 0; $i < $this->_rows; $i++) {
  90.                 for ($j = 0; $j < $this->_cols; $j++) {
  91.                     if ($autoCreate) {
  92.                         $this->_matrix[$i][$j] =& $this->addNew('plotarea');
  93.                         $this->_pushEdges($i, $j);
  94.                     } else {
  95.                         $this->_matrix[$i][$j] = false;
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.     }
  101.  
  102.     /**
  103.      * Pushes the edges on the specified position in the matrix
  104.      *
  105.      * @param int $row The row
  106.      * @param int $col The column
  107.      * @access private
  108.      */
  109.     function _pushEdges($row, $col)
  110.     {
  111.         if ((isset($this->_matrix[$row])) && (isset($this->_matrix[$row][$col]))) {
  112.             $height = 100/$this->_rows;
  113.             $width = 100/$this->_cols;
  114.             if ($col > 0) {
  115.                 $this->_matrix[$row][$col]->_push('left', round($col*$width) . '%');
  116.             }
  117.             if ($col+1 < $this->_cols) {
  118.                 $this->_matrix[$row][$col]->_push('right', round(100-($col+1)*$width) . '%');
  119.             }
  120.             if ($row > 0) {
  121.                 $this->_matrix[$row][$col]->_push('top', round($row*$height) . '%');
  122.             }
  123.             if ($row+1 < $this->_rows) {
  124.                 $this->_matrix[$row][$col]->_push('bottom', round(100-($row+1)*$height) . '%');
  125.             }
  126.         }
  127.     }
  128.  
  129.     /**
  130.      * Get the area on the specified position in the matrix
  131.      *
  132.      * @param int $row The row
  133.      * @param int $col The column
  134.      * @return Image_Graph_Layout The element of position ($row, $col) in the
  135.      *   matrix
  136.      */
  137.     function &getEntry($row, $col)
  138.     {
  139.         if ((isset($this->_matrix[$row])) && (isset($this->_matrix[$row][$col]))) {
  140.             return $this->_matrix[$row][$col];
  141.         } else {
  142.             $result = null;
  143.             return $result;
  144.         }
  145.     }
  146.  
  147.     /**
  148.      * Get the area on the specified position in the matrix
  149.      *
  150.      * @param int $row The row
  151.      * @param int $col The column
  152.      * @param Image_Graph_Layout $element The element to set in the position
  153.      *   ($row, $col) in the matrix
  154.      */
  155.     function setEntry($row, $col, &$element)
  156.     {
  157.         $this->_matrix[$row][$col] =& $element;
  158.         $this->_pushEdges($row, $col);
  159.     }
  160.  
  161.     /**
  162.      * Update coordinates
  163.      *
  164.      * @access private
  165.      */
  166.     function _updateCoords()
  167.     {
  168.         for ($i = 0; $i < $this->_rows; $i++) {
  169.             for ($j = 0; $j < $this->_cols; $j++) {
  170.                 $element =& $this->getEntry($i, $j);
  171.                 $this->add($element);
  172.             }
  173.         }
  174.         parent::_updateCoords();
  175.     }
  176.  
  177.     /**
  178.      * Output the layout to the canvas
  179.      *
  180.      * @return bool Was the output 'good' (true) or 'bad' (false).
  181.      * @access private
  182.      */
  183.     function _done()
  184.     {
  185.         $result = true;
  186.         for ($i = 0; $i < $this->_rows; $i++) {
  187.             for ($j = 0; $j < $this->_cols; $j++) {
  188.                 $element =& $this->getEntry($i, $j);
  189.                 if ($element) {
  190.                     if (!$element->_done()) {
  191.                         $result = false;
  192.                     }
  193.                 }
  194.             }
  195.         }
  196.         return $result;
  197.     }
  198.  
  199. }
  200.  
  201. ?>