add amendments metric
[contractdashboard.git] / lib / jpgraph / jpgraph_error.php
blob:a/lib/jpgraph/jpgraph_error.php -> blob:b/lib/jpgraph/jpgraph_error.php
<?php <?php
/*======================================================================= /*=======================================================================
// File: JPGRAPH_ERROR.PHP // File: JPGRAPH_ERROR.PHP
// Description: Error plot extension for JpGraph // Description: Error plot extension for JpGraph
// Created: 2001-01-08 // Created: 2001-01-08
// Ver: $Id: jpgraph_error.php 1106 2009-02-22 20:16:35Z ljp $ // Ver: $Id: jpgraph_error.php 1106 2009-02-22 20:16:35Z ljp $
// //
// Copyright (c) Aditus Consulting. All rights reserved. // Copyright (c) Aditus Consulting. All rights reserved.
//======================================================================== //========================================================================
*/ */
//=================================================== //===================================================
// CLASS ErrorPlot // CLASS ErrorPlot
// Description: Error plot with min/max value for // Description: Error plot with min/max value for
// each datapoint // each datapoint
//=================================================== //===================================================
class ErrorPlot extends Plot { class ErrorPlot extends Plot {
private $errwidth=2; private $errwidth=2;
//--------------- //---------------
// CONSTRUCTOR // CONSTRUCTOR
function __construct($datay,$datax=false) { function __construct($datay,$datax=false) {
parent::__construct($datay,$datax); parent::__construct($datay,$datax);
$this->numpoints /= 2; $this->numpoints /= 2;
} }
//--------------- //---------------
// PUBLIC METHODS // PUBLIC METHODS
   
// Gets called before any axis are stroked // Gets called before any axis are stroked
function PreStrokeAdjust($graph) { function PreStrokeAdjust($graph) {
if( $this->center ) { if( $this->center ) {
$a=0.5; $b=0.5; $a=0.5; $b=0.5;
++$this->numpoints; ++$this->numpoints;
} else { } else {
$a=0; $b=0; $a=0; $b=0;
} }
$graph->xaxis->scale->ticks->SetXLabelOffset($a); $graph->xaxis->scale->ticks->SetXLabelOffset($a);
$graph->SetTextScaleOff($b); $graph->SetTextScaleOff($b);
//$graph->xaxis->scale->ticks->SupressMinorTickMarks(); //$graph->xaxis->scale->ticks->SupressMinorTickMarks();
} }
   
// Method description // Method description
function Stroke($img,$xscale,$yscale) { function Stroke($img,$xscale,$yscale) {
$numpoints=count($this->coords[0])/2; $numpoints=count($this->coords[0])/2;
$img->SetColor($this->color); $img->SetColor($this->color);
$img->SetLineWeight($this->weight); $img->SetLineWeight($this->weight);
   
if( isset($this->coords[1]) ) { if( isset($this->coords[1]) ) {
if( count($this->coords[1])!=$numpoints ) if( count($this->coords[1])!=$numpoints )
JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints); JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints);
//("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints"); //("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
else else
$exist_x = true; $exist_x = true;
} }
else else
$exist_x = false; $exist_x = false;
   
for( $i=0; $i<$numpoints; ++$i) { for( $i=0; $i<$numpoints; ++$i) {
if( $exist_x ) if( $exist_x )
$x=$this->coords[1][$i]; $x=$this->coords[1][$i];
else else
$x=$i; $x=$i;
   
if( !is_numeric($x) || if( !is_numeric($x) ||
!is_numeric($this->coords[0][$i*2]) || !is_numeric($this->coords[0][$i*2+1]) ) { !is_numeric($this->coords[0][$i*2]) || !is_numeric($this->coords[0][$i*2+1]) ) {
continue; continue;
} }
   
$xt = $xscale->Translate($x); $xt = $xscale->Translate($x);
$yt1 = $yscale->Translate($this->coords[0][$i*2]); $yt1 = $yscale->Translate($this->coords[0][$i*2]);
$yt2 = $yscale->Translate($this->coords[0][$i*2+1]); $yt2 = $yscale->Translate($this->coords[0][$i*2+1]);
$img->Line($xt,$yt1,$xt,$yt2); $img->Line($xt,$yt1,$xt,$yt2);
$img->Line($xt-$this->errwidth,$yt1,$xt+$this->errwidth,$yt1); $img->Line($xt-$this->errwidth,$yt1,$xt+$this->errwidth,$yt1);
$img->Line($xt-$this->errwidth,$yt2,$xt+$this->errwidth,$yt2); $img->Line($xt-$this->errwidth,$yt2,$xt+$this->errwidth,$yt2);
} }
return true; return true;
} }
} // Class } // Class
   
   
//=================================================== //===================================================
// CLASS ErrorLinePlot // CLASS ErrorLinePlot
// Description: Combine a line and error plot // Description: Combine a line and error plot
// THIS IS A DEPRECATED PLOT TYPE JUST KEPT FOR // THIS IS A DEPRECATED PLOT TYPE JUST KEPT FOR
// BACKWARD COMPATIBILITY // BACKWARD COMPATIBILITY
//=================================================== //===================================================
class ErrorLinePlot extends ErrorPlot { class ErrorLinePlot extends ErrorPlot {
public $line=null; public $line=null;
//--------------- //---------------
// CONSTRUCTOR // CONSTRUCTOR
function __construct($datay,$datax=false) { function __construct($datay,$datax=false) {
parent::__construct($datay,$datax); parent::__construct($datay,$datax);
// Calculate line coordinates as the average of the error limits // Calculate line coordinates as the average of the error limits
$n = count($datay); $n = count($datay);
for($i=0; $i < $n; $i+=2 ) { for($i=0; $i < $n; $i+=2 ) {
$ly[]=($datay[$i]+$datay[$i+1])/2; $ly[]=($datay[$i]+$datay[$i+1])/2;
} }
$this->line=new LinePlot($ly,$datax); $this->line=new LinePlot($ly,$datax);
} }
   
//--------------- //---------------
// PUBLIC METHODS // PUBLIC METHODS
function Legend($graph) { function Legend($graph) {
if( $this->legend != "" ) if( $this->legend != "" )
$graph->legend->Add($this->legend,$this->color); $graph->legend->Add($this->legend,$this->color);
$this->line->Legend($graph); $this->line->Legend($graph);
} }
function Stroke($img,$xscale,$yscale) { function Stroke($img,$xscale,$yscale) {
parent::Stroke($img,$xscale,$yscale); parent::Stroke($img,$xscale,$yscale);
$this->line->Stroke($img,$xscale,$yscale); $this->line->Stroke($img,$xscale,$yscale);
} }
} // Class } // Class
   
   
//=================================================== //===================================================
// CLASS LineErrorPlot // CLASS LineErrorPlot
// Description: Combine a line and error plot // Description: Combine a line and error plot
//=================================================== //===================================================
class LineErrorPlot extends ErrorPlot { class LineErrorPlot extends ErrorPlot {
public $line=null; public $line=null;
//--------------- //---------------
// CONSTRUCTOR // CONSTRUCTOR
// Data is (val, errdeltamin, errdeltamax) // Data is (val, errdeltamin, errdeltamax)
function __construct($datay,$datax=false) { function __construct($datay,$datax=false) {
$ly=array(); $ey=array(); $ly=array(); $ey=array();
$n = count($datay); $n = count($datay);
if( $n % 3 != 0 ) { if( $n % 3 != 0 ) {
JpGraphError::RaiseL(4002); JpGraphError::RaiseL(4002);
//('Error in input data to LineErrorPlot. Number of data points must be a multiple of 3'); //('Error in input data to LineErrorPlot. Number of data points must be a multiple of 3');
} }
for($i=0; $i < $n; $i+=3 ) { for($i=0; $i < $n; $i+=3 ) {
$ly[]=$datay[$i]; $ly[]=$datay[$i];
$ey[]=$datay[$i]+$datay[$i+1]; $ey[]=$datay[$i]+$datay[$i+1];
$ey[]=$datay[$i]+$datay[$i+2]; $ey[]=$datay[$i]+$datay[$i+2];
} }
parent::__construct($ey,$datax); parent::__construct($ey,$datax);
$this->line=new LinePlot($ly,$datax); $this->line=new LinePlot($ly,$datax);
} }
   
//--------------- //---------------
// PUBLIC METHODS // PUBLIC METHODS
function Legend($graph) { function Legend($graph) {
if( $this->legend != "" ) if( $this->legend != "" )
$graph->legend->Add($this->legend,$this->color); $graph->legend->Add($this->legend,$this->color);
$this->line->Legend($graph); $this->line->Legend($graph);
} }
function Stroke($img,$xscale,$yscale) { function Stroke($img,$xscale,$yscale) {
parent::Stroke($img,$xscale,$yscale); parent::Stroke($img,$xscale,$yscale);
$this->line->Stroke($img,$xscale,$yscale); $this->line->Stroke($img,$xscale,$yscale);
} }
} // Class } // Class
   
   
/* EOF */ /* EOF */
?> ?>