[ Index ]
 

Code source de jpGraph 2.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/src/ -> jpgraph_error.php (source)

   1  <?php
   2  /*=======================================================================
   3  // File:     JPGRAPH_ERROR.PHP
   4  // Description:    Error plot extension for JpGraph
   5  // Created:     2001-01-08
   6  // Ver:        $Id: jpgraph_error.php 781 2006-10-08 08:07:47Z ljp $
   7  //
   8  // Copyright (c) Aditus Consulting. All rights reserved.
   9  //========================================================================
  10  */
  11  
  12  //===================================================
  13  // CLASS ErrorPlot
  14  // Description: Error plot with min/max value for
  15  // each datapoint
  16  //===================================================
  17  class ErrorPlot extends Plot {
  18      private $errwidth=2;
  19  //---------------
  20  // CONSTRUCTOR
  21      function ErrorPlot($datay,$datax=false) {
  22      $this->Plot($datay,$datax);
  23      $this->numpoints /= 2;
  24      }
  25  //---------------
  26  // PUBLIC METHODS
  27      
  28      // Gets called before any axis are stroked
  29      function PreStrokeAdjust($graph) {
  30      if( $this->center ) {
  31          $a=0.5; $b=0.5;
  32          ++$this->numpoints;            
  33      } else {
  34          $a=0; $b=0;
  35      }
  36      $graph->xaxis->scale->ticks->SetXLabelOffset($a);
  37      $graph->SetTextScaleOff($b);                        
  38      //$graph->xaxis->scale->ticks->SupressMinorTickMarks();
  39      }
  40      
  41      // Method description
  42      function Stroke($img,$xscale,$yscale) {
  43      $numpoints=count($this->coords[0])/2;
  44      $img->SetColor($this->color);
  45      $img->SetLineWeight($this->weight);    
  46  
  47      if( isset($this->coords[1]) ) {
  48          if( count($this->coords[1])!=$numpoints )
  49          JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints);
  50  //("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
  51          else
  52          $exist_x = true;
  53      }
  54      else 
  55          $exist_x = false;
  56  
  57      for( $i=0; $i<$numpoints; ++$i) {
  58          if( $exist_x ) 
  59          $x=$this->coords[1][$i];
  60          else 
  61          $x=$i;
  62  
  63          if( !is_numeric($x) ||  
  64          !is_numeric($this->coords[0][$i*2]) || !is_numeric($this->coords[0][$i*2+1]) ) {
  65          continue;
  66          }
  67  
  68          $xt = $xscale->Translate($x);
  69          $yt1 = $yscale->Translate($this->coords[0][$i*2]);
  70          $yt2 = $yscale->Translate($this->coords[0][$i*2+1]);
  71          $img->Line($xt,$yt1,$xt,$yt2);
  72          $img->Line($xt-$this->errwidth,$yt1,$xt+$this->errwidth,$yt1);
  73          $img->Line($xt-$this->errwidth,$yt2,$xt+$this->errwidth,$yt2);
  74      }            
  75      return true;
  76      }
  77  } // Class
  78  
  79  
  80  //===================================================
  81  // CLASS ErrorLinePlot
  82  // Description: Combine a line and error plot
  83  // THIS IS A DEPRECATED PLOT TYPE JUST KEPT FOR
  84  // BACKWARD COMPATIBILITY
  85  //===================================================
  86  class ErrorLinePlot extends ErrorPlot {
  87      public $line=null;
  88  //---------------
  89  // CONSTRUCTOR
  90      function ErrorLinePlot($datay,$datax=false) {
  91      $this->ErrorPlot($datay,$datax);
  92      // Calculate line coordinates as the average of the error limits
  93      $n = count($datay);
  94      for($i=0; $i < $n; $i+=2 ) {
  95          $ly[]=($datay[$i]+$datay[$i+1])/2;
  96      }        
  97      $this->line=new LinePlot($ly,$datax);
  98      }
  99  
 100  //---------------
 101  // PUBLIC METHODS
 102      function Legend($graph) {
 103      if( $this->legend != "" )
 104          $graph->legend->Add($this->legend,$this->color);
 105      $this->line->Legend($graph);
 106      }
 107              
 108      function Stroke($img,$xscale,$yscale) {
 109      parent::Stroke($img,$xscale,$yscale);
 110      $this->line->Stroke($img,$xscale,$yscale);
 111      }
 112  } // Class
 113  
 114  
 115  //===================================================
 116  // CLASS LineErrorPlot
 117  // Description: Combine a line and error plot
 118  //===================================================
 119  class LineErrorPlot extends ErrorPlot {
 120      public $line=null;
 121  //---------------
 122  // CONSTRUCTOR
 123      // Data is (val, errdeltamin, errdeltamax)
 124      function LineErrorPlot($datay,$datax=false) {
 125      $ly=array(); $ey=array();
 126      $n = count($datay);
 127      if( $n % 3 != 0 ) {
 128          JpGraphError::RaiseL(4002);
 129  //('Error in input data to LineErrorPlot. Number of data points must be a multiple of 3');
 130      }
 131      for($i=0; $i < $n; $i+=3 ) {
 132          $ly[]=$datay[$i];
 133          $ey[]=$datay[$i]+$datay[$i+1];
 134          $ey[]=$datay[$i]+$datay[$i+2];
 135      }        
 136      $this->ErrorPlot($ey,$datax);
 137      $this->line=new LinePlot($ly,$datax);
 138      }
 139  
 140  //---------------
 141  // PUBLIC METHODS
 142      function Legend($graph) {
 143      if( $this->legend != "" )
 144          $graph->legend->Add($this->legend,$this->color);
 145      $this->line->Legend($graph);
 146      }
 147              
 148      function Stroke($img,$xscale,$yscale) {
 149      parent::Stroke($img,$xscale,$yscale);
 150      $this->line->Stroke($img,$xscale,$yscale);
 151      }
 152  } // Class
 153  
 154  
 155  /* EOF */
 156  ?>


Généré le : Sat Nov 24 09:27:55 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics