2 /*=======================================================================
3 // File: JPGRAPH_ERROR.PHP
4 // Description: Error plot extension for JpGraph
6 // Author: Johan Persson (johanp@aditus.nu)
7 // Ver: $Id: jpgraph_error.php,v 1.16 2003/02/04 22:47:16 aditus Exp $
9 // License: This code is released under QPL
10 // Copyright (C) 2001,2002 Johan Persson
11 //========================================================================
14 //===================================================
16 // Description: Error plot with min/max value for
18 //===================================================
19 class ErrorPlot extends Plot {
23 function ErrorPlot(&$datay,$datax=false) {
24 $this->Plot($datay,$datax);
25 $this->numpoints /= 2;
30 // Gets called before any axis are stroked
31 function PreStrokeAdjust(&$graph) {
38 $graph->xaxis->scale->ticks->SetXLabelOffset($a);
39 $graph->SetTextScaleOff($b);
40 //$graph->xaxis->scale->ticks->SupressMinorTickMarks();
44 function Stroke(&$img,&$xscale,&$yscale) {
45 $numpoints=count($this->coords[0])/2;
46 $img->SetColor($this->color);
47 $img->SetLineWeight($this->weight);
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");
59 $xs=$this->coords[1][0];
64 for( $i=0; $i<$numpoints; ++$i) {
65 if( $exist_x ) $x=$this->coords[1][$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);
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 {
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;
95 $this->line=new LinePlot($ly,$datax);
100 function Legend(&$graph) {
101 if( $this->legend != "" )
102 $graph->legend->Add($this->legend,$this->color);
103 $this->line->Legend($graph);
106 function Stroke(&$img,&$xscale,&$yscale) {
107 parent::Stroke($img,$xscale,$yscale);
108 $this->line->Stroke($img,$xscale,$yscale);
113 //===================================================
114 // CLASS LineErrorPlot
115 // Description: Combine a line and error plot
116 //===================================================
117 class LineErrorPlot extends ErrorPlot {
121 // Data is (val, errdeltamin, errdeltamax)
122 function LineErrorPlot(&$datay,$datax=false) {
123 $ly=array(); $ey=array();
126 JpGraphError::Raise('Error in input data to LineErrorPlot.'.
127 'Number of data points must be a multiple of 3');
129 for($i=0; $i < count($datay); $i+=3 ) {
131 $ey[]=$datay[$i]+$datay[$i+1];
132 $ey[]=$datay[$i]+$datay[$i+2];
134 $this->ErrorPlot($ey,$datax);
135 $this->line=new LinePlot($ly,$datax);
140 function Legend(&$graph) {
141 if( $this->legend != "" )
142 $graph->legend->Add($this->legend,$this->color);
143 $this->line->Legend($graph);
146 function Stroke(&$img,&$xscale,&$yscale) {
147 parent::Stroke($img,$xscale,$yscale);
148 $this->line->Stroke($img,$xscale,$yscale);