[ 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 Plot 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: Step.php,v 1.15 2005/11/27 22:21:16 nosey Exp $ 28 * @link http://pear.php.net/package/Image_Graph 29 */ 30 31 /** 32 * Include file Image/Graph/Plot/Bar.php 33 */ 34 require_once 'Image/Graph/Plot/Bar.php'; 35 36 /** 37 * Step chart. 38 * 39 * @category Images 40 * @package Image_Graph 41 * @subpackage Plot 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_Plot_Step extends Image_Graph_Plot 49 { 50 51 /** 52 * Perform the actual drawing on the legend. 53 * 54 * @param int $x0 The top-left x-coordinate 55 * @param int $y0 The top-left y-coordinate 56 * @param int $x1 The bottom-right x-coordinate 57 * @param int $y1 The bottom-right y-coordinate 58 * @access private 59 */ 60 function _drawLegendSample($x0, $y0, $x1, $y1) 61 { 62 $dx = abs($x1 - $x0) / 3; 63 $dy = abs($y1 - $y0) / 3; 64 $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1)); 65 $this->_canvas->addVertex(array('x' => $x0, 'y' => $y0 + $dy)); 66 67 $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0 + $dy)); 68 $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0)); 69 70 $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0)); 71 $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0 + 2*$dy)); 72 73 $this->_canvas->addVertex(array('x' => $x1, 'y' => $y0 + 2*$dy)); 74 $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1)); 75 $this->_canvas->polygon(array('connect' => true)); 76 } 77 78 /** 79 * PlotType [Constructor] 80 * 81 * A 'normal' step chart is 'stacked' 82 * 83 * @param Dataset $dataset The data set (value containter) to plot 84 * @param string $multiType The type of the plot 85 * @param string $title The title of the plot (used for legends, 86 * {@link Image_Graph_Legend}) 87 */ 88 function Image_Graph_Plot_Step(& $dataset, $multiType = 'stacked', $title = '') 89 { 90 $multiType = strtolower($multiType); 91 if (($multiType != 'stacked') && ($multiType != 'stacked100pct')) { 92 $multiType = 'stacked'; 93 } 94 parent::Image_Graph_Plot($dataset, $multiType, $title); 95 } 96 97 /** 98 * Output the plot 99 * 100 * @return bool Was the output 'good' (true) or 'bad' (false). 101 * @access private 102 */ 103 function _done() 104 { 105 if (Image_Graph_Plot::_done() === false) { 106 return false; 107 } 108 109 $this->_canvas->startGroup(get_class($this) . '_' . $this->_title); 110 $this->_clip(true); 111 112 if ($this->_multiType == 'stacked100pct') { 113 $total = $this->_getTotals(); 114 } 115 116 if ($this->_parent->_horizontal) { 117 $width = $this->height() / ($this->_maximumX() + 2) / 2; 118 } 119 else { 120 $width = $this->width() / ($this->_maximumX() + 2) / 2; 121 } 122 123 reset($this->_dataset); 124 $key = key($this->_dataset); 125 $dataset =& $this->_dataset[$key]; 126 127 $first = $dataset->first(); 128 $last = $dataset->last(); 129 130 $point = array ('X' => $first['X'], 'Y' => '#min_pos#'); 131 $firstY = $this->_pointY($point) + ($this->_parent->_horizontal ? $width : 0); 132 $base[] = $firstY; 133 $firstX = $this->_pointX($point) - ($this->_parent->_horizontal ? 0 : $width); 134 $base[] = $firstX; 135 136 $point = array ('X' => $last['X'], 'Y' => '#min_pos#'); 137 $base[] = $this->_pointY($point) - ($this->_parent->_horizontal ? $width : 0); 138 $base[] = $this->_pointX($point) + ($this->_parent->_horizontal ? 0 : $width); 139 140 $first = ($this->_parent->_horizontal ? $firstY : $firstX); 141 142 $keys = array_keys($this->_dataset); 143 foreach ($keys as $key) { 144 $dataset =& $this->_dataset[$key]; 145 $dataset->_reset(); 146 $polygon = array_reverse($base); 147 unset ($base); 148 $last = $first; 149 while ($point = $dataset->_next()) { 150 $x = $point['X']; 151 $p = $point; 152 153 if (!isset($current[$x])) { 154 $current[$x] = 0; 155 } 156 157 if ($this->_multiType == 'stacked100pct') { 158 $p['Y'] = 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x]; 159 } else { 160 $p['Y'] += $current[$x]; 161 } 162 $current[$x] += $point['Y']; 163 $point = $p; 164 165 if ($this->_parent->_horizontal) { 166 $x0 = $this->_pointX($point); 167 $y0 = $last; 168 $x1 = $this->_pointX($point); 169 $last = $y1 = $this->_pointY($point) - $width; 170 } 171 else { 172 $x0 = $last; 173 $y0 = $this->_pointY($point); 174 $last = $x1 = $this->_pointX($point) + $width; 175 $y1 = $this->_pointY($point); 176 } 177 $polygon[] = $x0; $base[] = $y0; 178 $polygon[] = $y0; $base[] = $x0; 179 $polygon[] = $x1; $base[] = $y1; 180 $polygon[] = $y1; $base[] = $x1; 181 } 182 183 while (list(, $x) = each($polygon)) { 184 list(, $y) = each($polygon); 185 $this->_canvas->addVertex(array('x' => $x, 'y' => $y)); 186 } 187 188 $this->_getFillStyle($key); 189 $this->_getLineStyle($key); 190 $this->_canvas->polygon(array('connect' => true)); 191 } 192 unset($keys); 193 $this->_drawMarker(); 194 $this->_clip(false); 195 $this->_canvas->endGroup(); 196 return true; 197 } 198 } 199 200 ?>
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 |