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.1 2006/07/07 13:37:14 powles Exp $
9 // Copyright (c) Aditus Consulting. All rights reserved.
10 //========================================================================
13 //===================================================
15 // Description: Error plot with min/max value for
17 //===================================================
18 class ErrorPlot
extends Plot
{
22 function ErrorPlot(&$datay,$datax=false) {
23 $this->Plot($datay,$datax);
24 $this->numpoints
/= 2;
29 // Gets called before any axis are stroked
30 function PreStrokeAdjust(&$graph) {
37 $graph->xaxis
->scale
->ticks
->SetXLabelOffset($a);
38 $graph->SetTextScaleOff($b);
39 //$graph->xaxis->scale->ticks->SupressMinorTickMarks();
43 function Stroke(&$img,&$xscale,&$yscale) {
44 $numpoints=count($this->coords
[0])/2;
45 $img->SetColor($this->color
);
46 $img->SetLineWeight($this->weight
);
48 if( isset($this->coords
[1]) ) {
49 if( count($this->coords
[1])!=$numpoints )
50 JpGraphError
::RaiseL(2003,count($this->coords
[1]),$numpoints);
51 //("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
58 for( $i=0; $i<$numpoints; ++
$i) {
60 $x=$this->coords
[1][$i];
64 if( !is_numeric($x) ||
65 !is_numeric($this->coords
[0][$i*2]) ||
!is_numeric($this->coords
[0][$i*2+
1]) ) {
69 $xt = $xscale->Translate($x);
70 $yt1 = $yscale->Translate($this->coords
[0][$i*2]);
71 $yt2 = $yscale->Translate($this->coords
[0][$i*2+
1]);
72 $img->Line($xt,$yt1,$xt,$yt2);
73 $img->Line($xt-$this->errwidth
,$yt1,$xt+
$this->errwidth
,$yt1);
74 $img->Line($xt-$this->errwidth
,$yt2,$xt+
$this->errwidth
,$yt2);
81 //===================================================
82 // CLASS ErrorLinePlot
83 // Description: Combine a line and error plot
84 // THIS IS A DEPRECATED PLOT TYPE JUST KEPT FOR
85 // BACKWARD COMPATIBILITY
86 //===================================================
87 class ErrorLinePlot
extends ErrorPlot
{
91 function ErrorLinePlot(&$datay,$datax=false) {
92 $this->ErrorPlot($datay,$datax);
93 // Calculate line coordinates as the average of the error limits
95 for($i=0; $i < $n; $i+
=2 ) {
96 $ly[]=($datay[$i]+
$datay[$i+
1])/2;
98 $this->line
=new LinePlot($ly,$datax);
103 function Legend(&$graph) {
104 if( $this->legend
!= "" )
105 $graph->legend
->Add($this->legend
,$this->color
);
106 $this->line
->Legend($graph);
109 function Stroke(&$img,&$xscale,&$yscale) {
110 parent
::Stroke($img,$xscale,$yscale);
111 $this->line
->Stroke($img,$xscale,$yscale);
116 //===================================================
117 // CLASS LineErrorPlot
118 // Description: Combine a line and error plot
119 //===================================================
120 class LineErrorPlot
extends ErrorPlot
{
124 // Data is (val, errdeltamin, errdeltamax)
125 function LineErrorPlot(&$datay,$datax=false) {
126 $ly=array(); $ey=array();
129 JpGraphError
::RaiseL(4002);
130 //('Error in input data to LineErrorPlot. Number of data points must be a multiple of 3');
132 for($i=0; $i < $n; $i+
=3 ) {
134 $ey[]=$datay[$i]+
$datay[$i+
1];
135 $ey[]=$datay[$i]+
$datay[$i+
2];
137 $this->ErrorPlot($ey,$datax);
138 $this->line
=new LinePlot($ly,$datax);
143 function Legend(&$graph) {
144 if( $this->legend
!= "" )
145 $graph->legend
->Add($this->legend
,$this->color
);
146 $this->line
->Legend($graph);
149 function Stroke(&$img,&$xscale,&$yscale) {
150 parent
::Stroke($img,$xscale,$yscale);
151 $this->line
->Stroke($img,$xscale,$yscale);