Advertisement
SkullCrack

/Graf/ jpgraph_error.php

Jun 27th, 2011
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.23 KB | None | 0 0
  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.11 2002/03/31 22:23:13 aditus 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.     var $center=false;
  22. //---------------
  23. // CONSTRUCTOR
  24.     function ErrorPlot(&$datay,$datax=false) {
  25.     $this->Plot($datay,$datax);
  26.     $this->numpoints /= 2;
  27.     }
  28. //---------------
  29. // PUBLIC METHODS
  30.     function SetCenter($c=true) {
  31.     $this->center=$c;
  32.     }  
  33.    
  34.     // Gets called before any axis are stroked
  35.     function PreStrokeAdjust(&$graph) {
  36.     if( $this->center ) {
  37.         $a=0.5; $b=0.5;
  38.         ++$this->numpoints;        
  39.     } else {
  40.         $a=0; $b=0;
  41.     }
  42.     $graph->xaxis->scale->ticks->SetXLabelOffset($a);
  43.     $graph->SetTextScaleOff($b);                       
  44.     $graph->xaxis->scale->ticks->SupressMinorTickMarks();
  45.     }
  46.    
  47.     // Method description
  48.     function Stroke(&$img,&$xscale,&$yscale) {
  49.     $numpoints=count($this->coords[0])/2;
  50.     $img->SetColor($this->color);
  51.     $img->SetLineWeight($this->weight);
  52.  
  53.     if( isset($this->coords[1]) ) {
  54.         if( count($this->coords[1])!=$numpoints )
  55.         JpGraphError::Raise("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
  56.         else
  57.         $exist_x = true;
  58.     }
  59.     else
  60.         $exist_x = false;
  61.  
  62.     if( $exist_x )
  63.         $xs=$this->coords[1][0];
  64.     else
  65.         $xs=0;
  66.  
  67.        
  68.     for( $i=0; $i<$numpoints; ++$i) {
  69.         if( $exist_x ) $x=$this->coords[1][$i];
  70.         else $x=$i;
  71.         $xt = $xscale->Translate($x);
  72.         $yt1 = $yscale->Translate($this->coords[0][$i*2]);
  73.         $yt2 = $yscale->Translate($this->coords[0][$i*2+1]);
  74.         $img->Line($xt,$yt1,$xt,$yt2);
  75.         $img->Line($xt-$this->errwidth,$yt1,$xt+$this->errwidth,$yt1);
  76.         $img->Line($xt-$this->errwidth,$yt2,$xt+$this->errwidth,$yt2);
  77.     }          
  78.     return true;
  79.     }
  80. } // Class
  81.  
  82.  
  83. //===================================================
  84. // CLASS ErrorLinePlot
  85. // Description: Combine a line and error plot
  86. //===================================================
  87. class ErrorLinePlot extends ErrorPlot {
  88.     var $line=null;
  89. //---------------
  90. // CONSTRUCTOR
  91.     function ErrorLinePlot(&$datay,$datax=false) {
  92.     $this->ErrorPlot($datay);
  93.     // Calculate line coordinates as the average of the error limits
  94.     for($i=0; $i < count($datay); $i+=2 ) {
  95.         $ly[]=($datay[$i]+$datay[$i+1])/2;
  96.     }      
  97.     $this->line=new LinePlot($ly);
  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. /* EOF */
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement