[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/Image/Graph/Axis/ -> Radar.php (source)

   1  <?php
   2  
   3  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   4  
   5  /**
   6   * Class for axis handling.
   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 Axis
  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: Radar.php,v 1.6 2005/08/03 21:22:11 nosey Exp $
  28   * @link       http://pear.php.net/package/Image_Graph
  29   */
  30   
  31  /**
  32   * Include file Image/Graph/Axis/Category.php
  33   */
  34  require_once  'Image/Graph/Axis/Category.php';
  35  
  36  /**
  37   * Displays an 'X'-axis in a radar plot chart.
  38   *
  39   * This axis maps the number of elements in the dataset to a angle (from 0-
  40   * 360 degrees). Displaying the axis consist of drawing a number of lines from
  41   * center to the edge of the 'circle' than encloses the radar plot. The labels
  42   * are drawn on the 'ends' of these radial lines.
  43   *
  44   * @category   Images
  45   * @package    Image_Graph
  46   * @subpackage Axis
  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_Axis_Radar extends Image_Graph_Axis_Category
  54  {
  55  
  56      /**
  57       * Specifies the number of pixels, the labels is offsetted from the end of
  58       * the axis
  59       *
  60       * @var int
  61       * @access private
  62       */
  63      var $_distanceFromEnd = 5;
  64  
  65      /**
  66       * Gets the minimum value the axis will show.
  67       *
  68       * This is always 0
  69       *
  70       * @return double The minumum value
  71       * @access private
  72       */
  73      function _getMinimum()
  74      {
  75          return 0;
  76      }
  77  
  78      /**
  79       * Gets the maximum value the axis will show.
  80       *
  81       * This is always the number of labels passed to the constructor.
  82       *
  83       * @return double The maximum value
  84       * @access private
  85       */
  86      function _getMaximum()
  87      {
  88          return count($this->_labels);
  89      }
  90  
  91      /**
  92       * Calculate the delta value (the number of pixels representing one unit
  93       * on the axis)
  94       *
  95       * @return double The label interval
  96       * @access private
  97       */
  98      function _calcDelta()
  99      {
 100          if (abs($this->_getMaximum() - $this->_getMinimum()) == 0) {
 101              $this->_delta = false;
 102          } else {
 103              $this->_delta = 360 / ($this->_getMaximum() - $this->_getMinimum());
 104          }                
 105      }    
 106  
 107      /**
 108       * Get the pixel position represented by a value on the canvas
 109       *
 110       * @param double $value the value to get the pixel-point for
 111       * @return double The pixel position along the axis
 112       * @access private
 113       */
 114      function _point($value)
 115      {
 116          return (90 + (int) ($this->_value($value) * $this->_delta)) % 360;
 117      }
 118  
 119      /**
 120       * Get the size in pixels of the axis.
 121       *
 122       * For a radar plot this is always 0
 123       *
 124       * @return int The size of the axis
 125       * @access private
 126       */
 127      function _size()
 128      {
 129          return 0;
 130      }
 131  
 132      /**
 133       * Sets the distance from the end of the category lines to the label.
 134       *
 135       * @param int $distance The distance in pixels
 136       */
 137      function setDistanceFromEnd($distance = 5)
 138      {
 139          $this->_distanceFromEnd = $distance;
 140      }
 141  
 142      /**
 143       * Draws axis lines.
 144       *
 145       * @access private
 146       */
 147      function _drawAxisLines()
 148      {
 149      }
 150  
 151      /**
 152       * Output an axis tick mark.
 153       *
 154       * @param int $value The value to output
 155       * @access private
 156       */
 157      function _drawTick($value, $level = 1)
 158      {
 159          $centerX = (int) (($this->_left + $this->_right) / 2);
 160          $centerY = (int) (($this->_top + $this->_bottom) / 2);
 161  
 162          $radius = min($this->height(), $this->width()) / 2;
 163  
 164          $endPoint = array ('X' => $value, 'Y' => '#max#');
 165          $dX = $this->_pointX($endPoint);
 166          $dY = $this->_pointY($endPoint);
 167  
 168          $offX = ($dX - $centerX);
 169          $offY = ($dY - $centerY);
 170  
 171          $hyp = sqrt($offX*$offX + $offY*$offY);
 172          if ($hyp != 0) {
 173              $scale = $this->_distanceFromEnd / $hyp;
 174          } else {
 175              $scale = 1;
 176          }
 177  
 178          $adX = $dX + $offX * $scale;
 179          $adY = $dY + $offY * $scale;
 180  
 181          if (is_object($this->_dataPreProcessor)) {
 182              $labelText = $this->_dataPreProcessor->_process($value);
 183          } else {
 184              $labelText = $value;
 185          }
 186  
 187          if ((abs($dX - $centerX) < 1.5) && ($dY < $centerY)) {
 188              $align = IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_CENTER_X;
 189          } elseif ((abs($dX - $centerX) < 1.5) && ($dY > $centerY)) {
 190              $align = IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_CENTER_X;
 191          } elseif ($dX < $centerX) {
 192              $align = IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_CENTER_Y;
 193          } else {
 194              $align = IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y;
 195          }
 196          $this->write($adX, $adY, $labelText, $align);
 197  
 198          $this->_getLineStyle();
 199          $this->_canvas->line(array('x0' => $centerX, 'y0' => $centerY, 'x1' => $dX, 'y1' => $dY));
 200      }
 201  
 202  }
 203  
 204  ?>


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