[2] | 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.16 2003/02/04 22:47:16 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 | //---------------
|
---|
| 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 | // THIS IS A DEPRECATED PLOT TYPE JUST KEPT FOR
|
---|
| 83 | // BACKWARD COMPATIBILITY
|
---|
| 84 | //===================================================
|
---|
| 85 | class ErrorLinePlot extends ErrorPlot {
|
---|
| 86 | var $line=null;
|
---|
| 87 | //---------------
|
---|
| 88 | // CONSTRUCTOR
|
---|
| 89 | function ErrorLinePlot(&$datay,$datax=false) {
|
---|
| 90 | $this->ErrorPlot($datay,$datax);
|
---|
| 91 | // Calculate line coordinates as the average of the error limits
|
---|
| 92 | for($i=0; $i < count($datay); $i+=2 ) {
|
---|
| 93 | $ly[]=($datay[$i]+$datay[$i+1])/2;
|
---|
| 94 | }
|
---|
| 95 | $this->line=new LinePlot($ly,$datax);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | //---------------
|
---|
| 99 | // PUBLIC METHODS
|
---|
| 100 | function Legend(&$graph) {
|
---|
| 101 | if( $this->legend != "" )
|
---|
| 102 | $graph->legend->Add($this->legend,$this->color);
|
---|
| 103 | $this->line->Legend($graph);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | function Stroke(&$img,&$xscale,&$yscale) {
|
---|
| 107 | parent::Stroke($img,$xscale,$yscale);
|
---|
| 108 | $this->line->Stroke($img,$xscale,$yscale);
|
---|
| 109 | }
|
---|
| 110 | } // Class
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | //===================================================
|
---|
| 114 | // CLASS LineErrorPlot
|
---|
| 115 | // Description: Combine a line and error plot
|
---|
| 116 | //===================================================
|
---|
| 117 | class LineErrorPlot extends ErrorPlot {
|
---|
| 118 | var $line=null;
|
---|
| 119 | //---------------
|
---|
| 120 | // CONSTRUCTOR
|
---|
| 121 | // Data is (val, errdeltamin, errdeltamax)
|
---|
| 122 | function LineErrorPlot(&$datay,$datax=false) {
|
---|
| 123 | $ly=array(); $ey=array();
|
---|
| 124 | $n = count($datay);
|
---|
| 125 | if( $n % 3 != 0 ) {
|
---|
| 126 | JpGraphError::Raise('Error in input data to LineErrorPlot.'.
|
---|
| 127 | 'Number of data points must be a multiple of 3');
|
---|
| 128 | }
|
---|
| 129 | for($i=0; $i < count($datay); $i+=3 ) {
|
---|
| 130 | $ly[]=$datay[$i];
|
---|
| 131 | $ey[]=$datay[$i]+$datay[$i+1];
|
---|
| 132 | $ey[]=$datay[$i]+$datay[$i+2];
|
---|
| 133 | }
|
---|
| 134 | $this->ErrorPlot($ey,$datax);
|
---|
| 135 | $this->line=new LinePlot($ly,$datax);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | //---------------
|
---|
| 139 | // PUBLIC METHODS
|
---|
| 140 | function Legend(&$graph) {
|
---|
| 141 | if( $this->legend != "" )
|
---|
| 142 | $graph->legend->Add($this->legend,$this->color);
|
---|
| 143 | $this->line->Legend($graph);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | function Stroke(&$img,&$xscale,&$yscale) {
|
---|
| 147 | parent::Stroke($img,$xscale,$yscale);
|
---|
| 148 | $this->line->Stroke($img,$xscale,$yscale);
|
---|
| 149 | }
|
---|
| 150 | } // Class
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | /* EOF */
|
---|
| 154 | ?>
|
---|