[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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 Marker 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: Value.php,v 1.10 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/Marker.php 33 */ 34 require_once 'Image/Graph/Marker.php'; 35 36 /** 37 * A marker showing the data value. 38 * 39 * @category Images 40 * @package Image_Graph 41 * @subpackage Marker 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_Marker_Value extends Image_Graph_Marker 49 { 50 51 /** 52 * Datapreproccesor to format the value 53 * @var DataPreprocessor 54 * @access private 55 */ 56 var $_dataPreprocessor = null; 57 58 /** 59 * Which value to use from the data set, ie the X or Y value 60 * @var int 61 * @access private 62 */ 63 var $_useValue; 64 65 /** 66 * Create a value marker, ie a box containing the value of the 'pointing 67 * data' 68 * 69 * @param int $useValue Defines which value to use from the dataset, i.e. the 70 * X or Y value 71 */ 72 function Image_Graph_Marker_Value($useValue = IMAGE_GRAPH_VALUE_X) 73 { 74 parent::Image_Graph_Marker(); 75 $this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2); 76 $this->_useValue = $useValue; 77 $this->_fillStyle = 'white'; 78 $this->_borderStyle = 'black'; 79 } 80 81 /** 82 * Sets the background fill style of the element 83 * 84 * @param Image_Graph_Fill $background The background 85 * @see Image_Graph_Fill 86 */ 87 function setBackground(& $background) 88 { 89 $this->setFillStyle($background); 90 } 91 92 /** 93 * Sets the background color of the element 94 * 95 * @param mixed $color The color 96 */ 97 function setBackgroundColor($color) 98 { 99 $this->setFillColor($color); 100 } 101 102 /** 103 * Sets a data preprocessor for formatting the values 104 * 105 * @param DataPreprocessor $dataPreprocessor The data preprocessor 106 * @return Image_Graph_DataPreprocessor The data preprocessor 107 */ 108 function &setDataPreprocessor(& $dataPreprocessor) 109 { 110 $this->_dataPreprocessor =& $dataPreprocessor; 111 return $dataPreprocessor; 112 } 113 114 /** 115 * Get the value to display 116 * 117 * @param array $values The values representing the data the marker 'points' 118 * to 119 * @return string The display value, this is the pre-preprocessor value, to 120 * support for customized with multiple values. i.e show 'x = y' or '(x, y)' 121 * @access private 122 */ 123 function _getDisplayValue($values) 124 { 125 switch ($this->_useValue) { 126 case IMAGE_GRAPH_VALUE_X: 127 $value = $values['X']; 128 break; 129 130 case IMAGE_GRAPH_PCT_X_MIN: 131 $value = $values['PCT_MIN_X']; 132 break; 133 134 case IMAGE_GRAPH_PCT_X_MAX: 135 $value = $values['PCT_MAX_X']; 136 break; 137 138 case IMAGE_GRAPH_PCT_Y_MIN: 139 $value = $values['PCT_MIN_Y']; 140 break; 141 142 case IMAGE_GRAPH_PCT_Y_MAX: 143 $value = $values['PCT_MAX_Y']; 144 break; 145 146 case IMAGE_GRAPH_PCT_Y_TOTAL: 147 if (isset($values['SUM_Y'])) { 148 $value = 100 * $values['Y'] / $values['SUM_Y']; 149 } 150 else { 151 $value = 0; 152 } 153 break; 154 155 case IMAGE_GRAPH_POINT_ID: 156 $value = $values['ID']; 157 break; 158 159 default: 160 $value = $values['Y']; 161 break; 162 } 163 return $value; 164 } 165 166 /** 167 * Draw the marker on the canvas 168 * 169 * @param int $x The X (horizontal) position (in pixels) of the marker on 170 * the canvas 171 * @param int $y The Y (vertical) position (in pixels) of the marker on the 172 * canvas 173 * @param array $values The values representing the data the marker 'points' 174 * to 175 * @access private 176 */ 177 function _drawMarker($x, $y, $values = false) 178 { 179 parent::_drawMarker($x, $y, $values); 180 181 $value = $this->_getDisplayValue($values); 182 183 if ($this->_dataPreprocessor) { 184 $value = $this->_dataPreprocessor->_process($value); 185 } 186 187 if ($this->_defaultFontOptions !== false) { 188 $this->_canvas->setFont($this->_defaultFontOptions); 189 } else { 190 $this->_canvas->setFont($this->_getFont()); 191 } 192 193 $width = $this->_canvas->textWidth($value); 194 $height = $this->_canvas->textHeight($value); 195 $offsetX = $width/2 + $this->_padding['left']; 196 $offsetY = $height/2 + $this->_padding['top']; 197 198 $this->_getFillStyle(); 199 $this->_getBorderStyle(); 200 $this->_canvas->rectangle( 201 array( 202 'x0' => $x - $offsetX, 203 'y0' => $y - $offsetY, 204 'x1' => $x + $offsetX, 205 'y1' => $y + $offsetY 206 ) 207 ); 208 209 $this->write($x, $y, $value, IMAGE_GRAPH_ALIGN_CENTER); 210 } 211 212 } 213 214 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |