[ Index ] |
|
Code source de Cr@wltr@ck 2.2.1 |
1 <?php 2 /* 3 * This work is hereby released into the Public Domain. 4 * To view a copy of the public domain dedication, 5 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to 6 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 7 * 8 */ 9 10 require_once dirname(__FILE__)."/../Graph.class.php"; 11 12 /** 13 * Grid 14 * 15 * @package Artichow 16 */ 17 class awGrid { 18 19 /** 20 * Vertical lines of the grid 21 * 22 * @var array 23 */ 24 var $xgrid = array(); 25 26 /** 27 * Horizontal lines of the grid 28 * 29 * @var array 30 */ 31 var $ygrid = array(); 32 33 /** 34 * Is the component grid hidden ? 35 * 36 * @var bool 37 */ 38 var $hide = FALSE; 39 40 /** 41 * Are horizontal lines hidden ? 42 * 43 * @var bool 44 */ 45 var $hideHorizontal = FALSE; 46 47 /** 48 * Are vertical lines hidden ? 49 * 50 * @var bool 51 */ 52 var $hideVertical = FALSE; 53 54 /** 55 * Grid color 56 * 57 * @var Color 58 */ 59 var $color; 60 61 /** 62 * Grid space 63 * 64 * @var int 65 */ 66 var $space; 67 68 /** 69 * Line type 70 * 71 * @var int 72 */ 73 var $type = LINE_SOLID; 74 75 /** 76 * Grid interval 77 * 78 * @var int 79 */ 80 var $interval = array(1, 1); 81 82 /** 83 * Grid background color 84 * 85 * @var Color 86 */ 87 var $background; 88 89 /** 90 * Build the factory 91 */ 92 function awGrid() { 93 94 // Set a grid default color 95 $this->color = new awColor(210, 210, 210); 96 $this->background = new awColor(255, 255, 255, 100); 97 98 } 99 100 /** 101 * Hide grid ? 102 * 103 * @param bool $hide 104 */ 105 function hide($hide = TRUE) { 106 $this->hide = (bool)$hide; 107 } 108 109 /** 110 * Hide horizontal lines ? 111 * 112 * @param bool $hideHorizontal 113 */ 114 function hideHorizontal($hide = TRUE) { 115 $this->hideHorizontal = (bool)$hide; 116 } 117 118 /** 119 * Hide vertical lines ? 120 * 121 * @param bool $hideVertical 122 */ 123 function hideVertical($hide = TRUE) { 124 $this->hideVertical = (bool)$hide; 125 } 126 127 /** 128 * Change grid color 129 * 130 * @param $color 131 */ 132 function setColor($color) { 133 $this->color = $color; 134 } 135 136 /** 137 * Remove grid background 138 */ 139 function setNoBackground() { 140 $this->background = NULL; 141 } 142 143 /** 144 * Change grid background color 145 * 146 * @param $color 147 */ 148 function setBackgroundColor($color) { 149 $this->background = $color; 150 } 151 152 /** 153 * Change line type 154 * 155 * @param int $type 156 */ 157 function setType($type) { 158 $this->type = (int)$type; 159 } 160 161 /** 162 * Change grid interval 163 * 164 * @param int $hInterval 165 * @param int $vInterval 166 */ 167 function setInterval($hInterval, $vInterval) { 168 $this->interval = array((int)$hInterval, (int)$vInterval); 169 } 170 171 /** 172 * Set grid space 173 * 174 * @param int $left Left space in pixels 175 * @param int $right Right space in pixels 176 * @param int $top Top space in pixels 177 * @param int $bottom Bottom space in pixels 178 */ 179 function setSpace($left, $right, $top, $bottom) { 180 $this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom); 181 } 182 183 /** 184 * Change the current grid 185 * 186 * @param array $xgrid Vertical lines 187 * @param array $ygrid Horizontal lines 188 */ 189 function setGrid($xgrid, $ygrid) { 190 191 $this->xgrid = $xgrid; 192 $this->ygrid = $ygrid; 193 194 } 195 196 /** 197 * Draw grids 198 * 199 * @param $drawer A drawer object 200 * @param int $x1 201 * @param int $y1 202 * @param int $x2 203 * @param int $y2 204 */ 205 function draw($drawer, $x1, $y1, $x2, $y2) { 206 207 if(is_a($this->background, 'awColor')) { 208 209 // Draw background color 210 $drawer->filledRectangle( 211 $this->background, 212 awLine::build($x1, $y1, $x2, $y2) 213 ); 214 215 $this->background->free(); 216 217 } 218 219 if($this->hide === FALSE) { 220 221 $this->drawGrid( 222 $drawer, 223 $this->color, 224 $this->hideVertical ? array() : $this->xgrid, 225 $this->hideHorizontal ? array() : $this->ygrid, 226 $x1, $y1, $x2, $y2, 227 $this->type, 228 $this->space, 229 $this->interval[0], 230 $this->interval[1] 231 ); 232 233 } 234 235 $this->color->free(); 236 237 } 238 239 function drawGrid( 240 $drawer, $color, 241 $nx, $ny, $x1, $y1, $x2, $y2, 242 $type, $space, $hInterval, $vInterval 243 ) { 244 245 list($left, $right, $top, $bottom) = $space; 246 247 $width = $x2 - $x1 - $left - $right; 248 $height = $y2 - $y1 - $top - $bottom; 249 250 foreach($nx as $key => $n) { 251 252 if(($key % $vInterval) === 0) { 253 254 $pos = (int)round($x1 + $left + $n * $width); 255 $drawer->line( 256 $color, 257 new awLine( 258 new awPoint($pos, $y1), 259 new awPoint($pos, $y2), 260 $type 261 ) 262 ); 263 264 } 265 266 } 267 268 foreach($ny as $key => $n) { 269 270 if(($key % $hInterval) === 0) { 271 272 $pos = (int)round($y1 + $top + $n * $height); 273 $drawer->line( 274 $color, 275 new awLine( 276 new awPoint($x1, $pos), 277 new awPoint($x2, $pos), 278 $type 279 ) 280 ); 281 282 } 283 284 } 285 286 } 287 288 } 289 290 registerClass('Grid'); 291 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Sep 6 14:14:11 2007 | par Balluche grâce à PHPXref 0.7 |