[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/artichow/php5/ -> ScatterPlot.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__)."/Plot.class.php";
  11  
  12  /**
  13   * ScatterPlot
  14   *
  15   * @package Artichow
  16   */
  17  class awScatterPlot extends awPlot implements awLegendable {
  18      
  19      /**
  20       * Add marks to the scatter plot
  21       *
  22       * @var Mark
  23       */
  24      public $mark;
  25      
  26      /**
  27       * Labels on the plot
  28       *
  29       * @var Label
  30       */
  31      public $label;
  32      
  33      /**
  34       * Link points ?
  35       *
  36       * @var bool
  37       */
  38      protected $link = FALSE;
  39      
  40      /**
  41       * Display impulses
  42       *
  43       * @var bool
  44       */
  45      protected $impulse = NULL;
  46      
  47      /**
  48       * Link NULL points ?
  49       *
  50       * @var bool
  51       */
  52      protected $linkNull = FALSE;
  53      
  54      /**
  55       * Line color
  56       *
  57       * @var Color
  58       */
  59      protected $lineColor;
  60      
  61      /**
  62       * Line type
  63       *
  64       * @var int
  65       */
  66      protected $lineStyle = awLine::SOLID;
  67      
  68      /**
  69       * Line thickness
  70       *
  71       * @var int
  72       */
  73      protected $lineThickness = 1;
  74           
  75      /**
  76       * Construct a new awScatterPlot
  77       *
  78       * @param array $datay Numeric values for Y axis
  79       * @param array $datax Numeric values for X axis
  80       * @param int $mode
  81       */
  82  	public function __construct($datay, $datax = NULL) {
  83      
  84          parent::__construct();
  85          
  86          // Defaults marks
  87          $this->mark = new awMark;
  88          $this->mark->setType(awMark::CIRCLE);
  89          $this->mark->setSize(7);
  90          $this->mark->border->show();
  91          
  92          $this->label = new awLabel;
  93          
  94          $this->setValues($datay, $datax);
  95          $this->setColor(new awBlack);
  96      
  97      }
  98      
  99      /**
 100       * Display plot as impulses
 101       *
 102       * @param awColor $impulse Impulses color (or NULL to disable impulses)
 103       */
 104  	public function setImpulse($color) {
 105          $this->impulse = $color;
 106      }
 107      
 108      /**
 109       * Link scatter plot points
 110       *
 111       * @param bool $link
 112       * @param awColor $color Line color (default to black)
 113       */
 114  	public function link($link, $color = NULL) {
 115          $this->link = (bool)$link;
 116          if($color instanceof awColor) {
 117              $this->setColor($color);
 118          }
 119      }
 120      
 121      /**
 122       * Ignore null values for Y data and continue linking
 123       *
 124       * @param bool $link
 125       */
 126  	public function linkNull($link) {
 127          $this->linkNull = (bool)$link;
 128      }
 129      
 130      /**
 131       * Change line color
 132       *
 133       * @param awColor $color
 134       */
 135  	public function setColor(awColor $color) {
 136          $this->lineColor = $color;
 137      }
 138      
 139      /**
 140       * Change line style
 141       *
 142       * @param int $style
 143       */
 144  	public function setStyle($style) {
 145          $this->lineStyle = (int)$style;
 146      }
 147      
 148      /**
 149       * Change line tickness
 150       *
 151       * @param int $tickness
 152       */
 153  	public function setThickness($tickness) {
 154          $this->lineThickness = (int)$tickness;
 155      }
 156  
 157      /**
 158       * Get the line thickness
 159       *
 160       * @return int
 161       */
 162  	public function getLegendLineThickness() {
 163          return $this->lineThickness;
 164      }
 165  
 166      /**
 167       * Get the line type
 168       *
 169       * @return int
 170       */
 171  	public function getLegendLineStyle() {
 172          return $this->lineStyle;
 173      }
 174  
 175      /**
 176       * Get the color of line
 177       *
 178       * @return Color
 179       */
 180  	public function getLegendLineColor() {
 181          return $this->lineColor;
 182      }
 183  
 184      /**
 185       * Get the background color or gradient of an element of the component
 186       *
 187       * @return Color, Gradient
 188       */
 189  	public function getLegendBackground() {
 190          return NULL;
 191      }
 192  
 193      /**
 194       * Get a mark object
 195       *
 196       * @return Mark
 197       */
 198  	public function getLegendMark() {
 199          return $this->mark;
 200      }
 201      
 202  	public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
 203      
 204          $count = count($this->datay);
 205          
 206          // Get start and stop values
 207          list($start, $stop) = $this->getLimit();
 208          
 209          // Build the polygon
 210          $polygon = new awPolygon;
 211          
 212          for($key = 0; $key < $count; $key++) {
 213          
 214              $x = $this->datax[$key];
 215              $y = $this->datay[$key];
 216              
 217              if($y !== NULL) {
 218                  $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
 219                  $polygon->set($key, $p);
 220              } else if($this->linkNull === FALSE) {
 221                  $polygon->set($key, NULL);
 222              }
 223          
 224          }
 225          
 226          // Link points if needed
 227          if($this->link) {
 228          
 229              $prev = NULL;
 230              
 231              foreach($polygon->all() as $point) {
 232              
 233                  if($prev !== NULL and $point !== NULL) {
 234                      $drawer->line(
 235                          $this->lineColor,
 236                          new awLine(
 237                              $prev,
 238                              $point,
 239                              $this->lineStyle,
 240                              $this->lineThickness
 241                          )
 242                      );
 243                  }
 244                  $prev = $point;
 245                  
 246              }
 247              
 248              $this->lineColor->free();
 249              
 250          }
 251          
 252          // Draw impulses
 253          if($this->impulse instanceof awColor) {
 254              
 255              foreach($polygon->all() as $key => $point) {
 256              
 257                  if($point !== NULL) {
 258                      
 259                      $zero = awAxis::toPosition(
 260                          $this->xAxis,
 261                          $this->yAxis,
 262                          new awPoint($key, 0)
 263                      );
 264                      
 265                      $drawer->line(
 266                          $this->impulse,
 267                          new awLine(
 268                              $zero,
 269                              $point,
 270                              awLine::SOLID,
 271                              1
 272                          )
 273                      );
 274                      
 275                  }
 276                  
 277              }
 278          
 279          }
 280          
 281          // Draw marks and labels
 282          foreach($polygon->all() as $key => $point) {
 283  
 284              $this->mark->draw($drawer, $point);
 285              $this->label->draw($drawer, $point, $key);
 286              
 287          }
 288          
 289      }
 290      
 291  	protected function xAxisPoint($position) {
 292          $y = $this->xAxisZero ? 0 : $this->getRealYMin();
 293          return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
 294      }
 295      
 296  	public function getXCenter() {
 297          return FALSE;
 298      }
 299  
 300  }
 301  
 302  registerClass('ScatterPlot');
 303  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics