home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / lib / jpgraph / src / jpgraph_error.php < prev    next >
Encoding:
PHP Script  |  2002-12-11  |  3.0 KB  |  111 lines

  1. <?php
  2. /*=======================================================================
  3. // File:     JPGRAPH_ERROR.PHP
  4. // Description:    Error plot extension for JpGraph
  5. // Created:     2001-01-08
  6. // Author:    Johan Persson (johanp@aditus.nu)
  7. // Ver:        $Id: jpgraph_error.php,v 1.1 2002/12/11 09:41:58 kripper Exp $
  8. //
  9. // License:    This code is released under QPL
  10. // Copyright (C) 2001,2002 Johan Persson
  11. //========================================================================
  12. */
  13.  
  14. //===================================================
  15. // CLASS ErrorPlot
  16. // Description: Error plot with min/max value for
  17. // each datapoint
  18. //===================================================
  19. class ErrorPlot extends Plot {
  20.     var $errwidth=2;
  21. //---------------
  22. // CONSTRUCTOR
  23.     function ErrorPlot(&$datay,$datax=false) {
  24.     $this->Plot($datay,$datax);
  25.     $this->numpoints /= 2;
  26.     }
  27. //---------------
  28. // PUBLIC METHODS
  29.     
  30.     // Gets called before any axis are stroked
  31.     function PreStrokeAdjust(&$graph) {
  32.     if( $this->center ) {
  33.         $a=0.5; $b=0.5;
  34.         ++$this->numpoints;            
  35.     } else {
  36.         $a=0; $b=0;
  37.     }
  38.     $graph->xaxis->scale->ticks->SetXLabelOffset($a);
  39.     $graph->SetTextScaleOff($b);                        
  40.     $graph->xaxis->scale->ticks->SupressMinorTickMarks();
  41.     }
  42.     
  43.     // Method description
  44.     function Stroke(&$img,&$xscale,&$yscale) {
  45.     $numpoints=count($this->coords[0])/2;
  46.     $img->SetColor($this->color);
  47.     $img->SetLineWeight($this->weight);    
  48.  
  49.     if( isset($this->coords[1]) ) {
  50.         if( count($this->coords[1])!=$numpoints )
  51.         JpGraphError::Raise("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
  52.         else
  53.         $exist_x = true;
  54.     }
  55.     else 
  56.         $exist_x = false;
  57.  
  58.     if( $exist_x )
  59.         $xs=$this->coords[1][0];
  60.     else
  61.         $xs=0;
  62.  
  63.         
  64.     for( $i=0; $i<$numpoints; ++$i) {
  65.         if( $exist_x ) $x=$this->coords[1][$i];
  66.         else $x=$i;
  67.         $xt = $xscale->Translate($x);
  68.         $yt1 = $yscale->Translate($this->coords[0][$i*2]);
  69.         $yt2 = $yscale->Translate($this->coords[0][$i*2+1]);
  70.         $img->Line($xt,$yt1,$xt,$yt2);
  71.         $img->Line($xt-$this->errwidth,$yt1,$xt+$this->errwidth,$yt1);
  72.         $img->Line($xt-$this->errwidth,$yt2,$xt+$this->errwidth,$yt2);
  73.     }            
  74.     return true;
  75.     }
  76. } // Class
  77.  
  78.  
  79. //===================================================
  80. // CLASS ErrorLinePlot
  81. // Description: Combine a line and error plot
  82. //===================================================
  83. class ErrorLinePlot extends ErrorPlot {
  84.     var $line=null;
  85. //---------------
  86. // CONSTRUCTOR
  87.     function ErrorLinePlot(&$datay,$datax=false) {
  88.     $this->ErrorPlot($datay);
  89.     // Calculate line coordinates as the average of the error limits
  90.     for($i=0; $i < count($datay); $i+=2 ) {
  91.         $ly[]=($datay[$i]+$datay[$i+1])/2;
  92.     }        
  93.     $this->line=new LinePlot($ly);
  94.     }
  95.  
  96. //---------------
  97. // PUBLIC METHODS
  98.     function Legend(&$graph) {
  99.     if( $this->legend != "" )
  100.         $graph->legend->Add($this->legend,$this->color);
  101.     $this->line->Legend($graph);
  102.     }
  103.             
  104.     function Stroke(&$img,&$xscale,&$yscale) {
  105.     parent::Stroke($img,$xscale,$yscale);
  106.     $this->line->Stroke($img,$xscale,$yscale);
  107.     }
  108. } // Class
  109.  
  110. /* EOF */
  111. ?>