[ Index ]
 

Code source de Cr@wltr@ck 2.2.1

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

title

Body

[fermer]

/graphs/artichow/php5/inc/ -> Tick.class.php (source)

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


Généré le : Thu Sep 6 14:14:11 2007 par Balluche grâce à PHPXref 0.7