[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/Image/Graph/ -> Layout.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 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: Layout.php,v 1.12 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/Plotarea/Element.php
  33   */
  34  require_once  'Image/Graph/Plotarea/Element.php';
  35  
  36  /**
  37   * Defines an area of the graph that can be layout'ed.
  38   *
  39   * Any class that extends this abstract class can be used within a layout on the canvas.
  40   *
  41   * @category   Images
  42   * @package    Image_Graph
  43   * @subpackage Layout
  44   * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  45   * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  46   * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  47   * @version    Release: 0.7.2
  48   * @link       http://pear.php.net/package/Image_Graph
  49   * @abstract
  50   */
  51  class Image_Graph_Layout extends Image_Graph_Plotarea_Element
  52  {
  53  
  54      /**
  55       * Has the coordinates already been updated?
  56       * @var bool
  57       * @access private
  58       */
  59      var $_updated = false;
  60  
  61      /**
  62       * Alignment of the area for each vertice (left, top, right, bottom)
  63       * @var array
  64       * @access private
  65       */
  66      var $_alignSize = array ('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);
  67  
  68      /**
  69       * Image_Graph_Layout [Constructor]
  70       */
  71      function Image_Graph_Layout()
  72      {
  73          parent::Image_Graph_Element();
  74          $this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2);
  75      }
  76  
  77      /**
  78       * Resets the elements
  79       *
  80       * @access private
  81       */
  82      function _reset()
  83      {
  84          parent::_reset();
  85          $this->_updated = false;
  86      }
  87  
  88      /**
  89       * Calculate the edge offset for a specific edge
  90       * @param array $alignSize The alignment of the edge
  91       * @param int $offset The offset/posision of the at 0% edge
  92       * @param int $total The total size (width or height) of the element
  93       * @param int $multiplier +/- 1 if the edge should pushed either toward more
  94       * negative or positive values
  95       * @since 0.3.0dev2
  96       * @access private
  97       */
  98      function _calcEdgeOffset($alignSize, $offset, $total, $multiplier)
  99      {
 100          if ($alignSize['unit'] == 'percentage') {
 101              return $offset + $multiplier * ($total * $alignSize['value'] / 100);
 102          } elseif ($alignSize['unit'] == 'pixels') {
 103              if (($alignSize['value'] == 'auto_part1') || ($alignSize['value'] == 'auto_part2')) {
 104                  $alignSize['value'] = $multiplier * $this->_parent->_getAbsolute($alignSize['value']);
 105              }
 106              if ($alignSize['value'] < 0) {
 107                  return $offset + $multiplier * ($total + $alignSize['value']);
 108              } else {
 109                  return $offset + $multiplier * $alignSize['value'];
 110              }
 111          }
 112          return $offset;
 113      }
 114  
 115      /**
 116       * Calculate the edges
 117       *
 118       * @access private
 119       */
 120      function _calcEdges()
 121      {
 122          if ((is_array($this->_alignSize)) && (!$this->_updated)) {
 123              $left = $this->_calcEdgeOffset(
 124                  $this->_alignSize['left'],
 125                  $this->_parent->_fillLeft(),
 126                  $this->_parent->_fillWidth(),
 127                  +1
 128              );
 129              $top = $this->_calcEdgeOffset(
 130                  $this->_alignSize['top'],
 131                  $this->_parent->_fillTop(),
 132                  $this->_parent->_fillHeight(),
 133                  +1
 134              );
 135              $right = $this->_calcEdgeOffset(
 136                  $this->_alignSize['right'],
 137                  $this->_parent->_fillRight(),
 138                  $this->_parent->_fillWidth(),
 139                  -1
 140              );
 141              $bottom = $this->_calcEdgeOffset(
 142                  $this->_alignSize['bottom'],
 143                  $this->_parent->_fillBottom(),
 144                  $this->_parent->_fillHeight(),
 145                  -1
 146              );
 147  
 148              $this->_setCoords(
 149                  $left + $this->_padding['left'],
 150                  $top + $this->_padding['top'],
 151                  $right - $this->_padding['right'],
 152                  $bottom - $this->_padding['bottom']
 153              );
 154          }
 155      }
 156  
 157      /**
 158       * Update coordinates
 159       *
 160       * @access private
 161       */
 162      function _updateCoords()
 163      {
 164          $this->_calcEdges();
 165          parent::_updateCoords();
 166      }
 167  
 168      /**
 169       * Pushes an edge of area a specific distance 'into' the canvas
 170       *
 171       * @param int $edge The edge of the canvas to align relative to
 172       * @param int $size The number of pixels or the percentage of the canvas total size to occupy relative to the selected alignment edge
 173       * @access private
 174       */
 175      function _push($edge, $size = '100%')
 176      {
 177          $result = array();
 178          if (ereg("([0-9]*)\%", $size, $result)) {
 179              $this->_alignSize[$edge] = array(
 180                  'value' => min(100, max(0, $result[1])),
 181                  'unit' => 'percentage'
 182              );
 183          } else {
 184              $this->_alignSize[$edge] = array(
 185                  'value' => $size,
 186                  'unit' => 'pixels'
 187              );
 188          }
 189      }
 190  
 191      /**
 192       * Sets the coordinates of the element
 193       *
 194       * @param int $left The leftmost pixel of the element on the canvas
 195       * @param int $top The topmost pixel of the element on the canvas
 196       * @param int $right The rightmost pixel of the element on the canvas
 197       * @param int $bottom The bottommost pixel of the element on the canvas
 198       * @access private
 199       */
 200      function _setCoords($left, $top, $right, $bottom)
 201      {
 202          parent::_setCoords($left, $top, $right, $bottom);
 203          $this->_updated = true;
 204      }
 205  
 206      /**
 207       * Returns the calculated "auto" size
 208       *
 209       * @return int The calculated auto size
 210       * @access private
 211       */
 212      function _getAutoSize()
 213      {
 214          return false;
 215      }
 216  
 217  }
 218  
 219  ?>


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