[ Index ] |
|
Code source de phpMyVisites 2.3 |
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 /* <php4> */ 11 12 define("TICK_IN", 0); 13 define("TICK_OUT", 1); 14 define("TICK_IN_OUT", 2); 15 16 /* </php4> */ 17 18 /** 19 * Handle ticks 20 * 21 * @package Artichow 22 */ 23 class awTick { 24 25 /** 26 * Ticks style 27 * 28 * @var int 29 */ 30 protected $style = awTick::IN; 31 32 /** 33 * Ticks size 34 * 35 * @var int 36 */ 37 protected $size; 38 39 /** 40 * Ticks color 41 * 42 * @var Color 43 */ 44 protected $color; 45 46 /** 47 * Ticks number 48 * 49 * @var int 50 */ 51 protected $number; 52 53 /** 54 * Ticks number by other tick 55 * 56 * @var array 57 */ 58 protected $numberByTick; 59 60 /** 61 * Ticks interval 62 * 63 * @var int 64 */ 65 protected $interval = 1; 66 67 /** 68 * Hide ticks 69 * 70 * @var bool 71 */ 72 protected $hide = FALSE; 73 74 /** 75 * Hide first tick 76 * 77 * @var bool 78 */ 79 protected $hideFirst = FALSE; 80 81 /** 82 * Hide last tick 83 * 84 * @var bool 85 */ 86 protected $hideLast = FALSE; 87 88 /** 89 * In mode 90 * 91 * @param int 92 */ 93 const IN = 0; 94 95 /** 96 * Out mode 97 * 98 * @param int 99 */ 100 const OUT = 1; 101 102 /** 103 * In and out mode 104 * 105 * @param int 106 */ 107 const IN_OUT = 2; 108 109 /** 110 * Build the ticks 111 * 112 * @param int $number Number of ticks 113 * @param int $size Ticks size 114 */ 115 public function __construct($number, $size) { 116 117 $this->setSize($size); 118 $this->setNumber($number); 119 $this->setColor(new awBlack); 120 $this->style = awTick::IN; 121 122 } 123 124 /** 125 * Change ticks style 126 * 127 * @param int $style 128 */ 129 public function setStyle($style) { 130 $this->style = (int)$style; 131 } 132 133 /** 134 * Get ticks style 135 * 136 * @return int 137 */ 138 public function getStyle() { 139 return $this->style; 140 } 141 142 /** 143 * Change ticks color 144 * 145 * @param awColor $color 146 */ 147 public function setColor(awColor $color) { 148 $this->color = $color; 149 } 150 151 /** 152 * Change ticks size 153 * 154 * @param int $size 155 */ 156 public function setSize($size) { 157 $this->size = (int)$size; 158 } 159 160 /** 161 * Change interval of ticks 162 * 163 * @param int $interval 164 */ 165 public function setInterval($interval) { 166 $this->interval = (int)$interval; 167 } 168 169 /** 170 * Get interval between each tick 171 * 172 * @return int 173 */ 174 public function getInterval() { 175 return $this->interval; 176 } 177 178 /** 179 * Change number of ticks 180 * 181 * @param int $number 182 */ 183 public function setNumber($number) { 184 $this->number = (int)$number; 185 } 186 187 /** 188 * Get number of ticks 189 * 190 * @return int 191 */ 192 public function getNumber() { 193 return $this->number; 194 } 195 196 /** 197 * Change number of ticks relative to others ticks 198 * 199 * @param awTick $tick Ticks reference 200 * @param int $number Number of ticks 201 */ 202 public function setNumberByTick(awTick $tick, $number) { 203 /* <php5> */ 204 $this->numberByTick = array($tick, (int)$number); 205 /* </php5> */ 206 /* <php4> -- 207 $this->numberByTick = array(&$tick, (int)$number); 208 -- </php4> */ 209 } 210 211 /** 212 * Hide ticks 213 * 214 * @param bool $hide 215 */ 216 public function hide($hide) { 217 $this->hide = (bool)$hide; 218 } 219 220 /** 221 * Hide first tick 222 * 223 * @param bool $hide 224 */ 225 public function hideFirst($hide) { 226 $this->hideFirst = (bool)$hide; 227 } 228 229 /** 230 * Hide last tick 231 * 232 * @param bool $hide 233 */ 234 public function hideLast($hide) { 235 $this->hideLast = (bool)$hide; 236 } 237 238 /** 239 * Draw ticks on a vector 240 * 241 * @param awDrawer $drawer A drawer 242 * @param awVector $vector A vector 243 */ 244 public function draw(awDrawer $drawer, awVector $vector) { 245 246 if($this->numberByTick !== NULL) { 247 list($tick, $number) = $this->numberByTick; 248 $this->number = 1 + ($tick->getNumber() - 1) * ($number + 1); 249 $this->interval = $tick->getInterval(); 250 } 251 252 if($this->number < 2 or $this->hide) { 253 return; 254 } 255 256 $angle = $vector->getAngle(); 257 // echo "INIT:".$angle."<br>"; 258 switch($this->style) { 259 260 case awTick::IN : 261 $this->drawTicks($drawer, $vector, NULL, $angle + M_PI / 2); 262 break; 263 264 case awTick::OUT : 265 $this->drawTicks($drawer, $vector, $angle + 3 * M_PI / 2, NULL); 266 break; 267 268 default : 269 $this->drawTicks($drawer, $vector, $angle + M_PI / 2, $angle + 3 * M_PI / 2); 270 break; 271 272 } 273 274 } 275 276 protected function drawTicks(awDrawer $drawer, awVector $vector, $from, $to) { 277 278 // Draw last tick 279 if($this->hideLast === FALSE) { 280 281 //echo '<b>'; 282 if(($this->number - 1) % $this->interval === 0) { 283 $this->drawTick($drawer, $vector->p2, $from, $to); 284 } 285 //echo '</b>'; 286 287 } 288 289 $number = $this->number - 1; 290 $size = $vector->getSize(); 291 292 // Get tick increment in pixels 293 $inc = $size / $number; 294 295 // Check if we must hide the first tick 296 $start = $this->hideFirst ? $inc : 0; 297 $stop = $inc * $number; 298 299 $position = 0; 300 301 for($i = $start; round($i, 6) < $stop; $i += $inc) { 302 303 if($position % $this->interval === 0) { 304 $p = $vector->p1->move( 305 round($i * cos($vector->getAngle()), 6), 306 round($i * sin($vector->getAngle() * -1), 6) 307 ); 308 $this->drawTick($drawer, $p, $from, $to); 309 } 310 311 $position++; 312 313 } 314 //echo '<br><br>'; 315 } 316 317 protected function drawTick(awDrawer $drawer, awPoint $p, $from, $to) { 318 // echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/'; 319 // The round avoid some errors in the calcul 320 // For example, 12.00000008575245 becomes 12 321 $p1 = $p; 322 $p2 = $p; 323 324 if($from !== NULL) { 325 $p1 = $p1->move( 326 round($this->size * cos($from), 6), 327 round($this->size * sin($from) * -1, 6) 328 ); 329 } 330 331 if($to !== NULL) { 332 $p2 = $p2->move( 333 round($this->size * cos($to), 6), 334 round($this->size * sin($to) * -1, 6) 335 ); 336 } 337 //echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/'; 338 $vector = new awVector( 339 $p1, $p2 340 ); 341 342 $drawer->line( 343 $this->color, 344 $vector 345 ); 346 347 } 348 349 } 350 351 registerClass('Tick'); 352 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |