From b1f90ad2cb6eb56ad53d8ce0e90c0e0fdae9d33a Mon Sep 17 00:00:00 2001 From: SaintPeter Date: Sat, 3 Feb 2018 09:50:54 -0800 Subject: [PATCH] Update to v4.2.0 Closes #19 --- lib/jpgraph/src/gd_image.inc.php | 1 + lib/jpgraph/src/jpgraph.php | 18 +++++++++--------- lib/jpgraph/src/jpgraph_bar.php | 2 +- lib/jpgraph/src/jpgraph_flags.php | 11 ++++------- lib/jpgraph/src/jpgraph_gradient.php | 4 ++-- lib/jpgraph/src/jpgraph_line.php | 2 +- lib/jpgraph/src/jpgraph_log.php | 2 +- lib/jpgraph/src/jpgraph_pie.php | 6 ++++-- lib/jpgraph/src/jpgraph_polar.php | 2 ++ lib/jpgraph/src/jpgraph_scatter.php | 2 +- lib/jpgraph/src/jpgraph_table.php | 14 ++++++++++---- 11 files changed, 36 insertions(+), 28 deletions(-) diff --git a/lib/jpgraph/src/gd_image.inc.php b/lib/jpgraph/src/gd_image.inc.php index d13ce28..97368d4 100755 --- a/lib/jpgraph/src/gd_image.inc.php +++ b/lib/jpgraph/src/gd_image.inc.php @@ -11,6 +11,7 @@ require_once 'jpgraph_rgb.inc.php'; require_once 'jpgraph_ttf.inc.php'; require_once 'imageSmoothArc.php'; +require_once 'jpgraph_errhandler.inc.php'; // Line styles define('LINESTYLE_SOLID',1); diff --git a/lib/jpgraph/src/jpgraph.php b/lib/jpgraph/src/jpgraph.php index 5db0bbc..db3ce82 100755 --- a/lib/jpgraph/src/jpgraph.php +++ b/lib/jpgraph/src/jpgraph.php @@ -19,7 +19,7 @@ require_once('gd_image.inc.php'); // Version info -define('JPG_VERSION','4.0.2'); +define('JPG_VERSION','4.2.0'); // Minimum required PHP version define('MIN_PHPVERSION','5.1.0'); @@ -1492,7 +1492,7 @@ function GetTextsYMinMax($aY2=false) { else { $txts = $this->texts; } - $n = count($txts); + $n = is_array($txts) ? count($txts) : 0; $min=null; $max=null; for( $i=0; $i < $n; ++$i ) { @@ -1521,7 +1521,7 @@ function GetTextsXMinMax($aY2=false) { else { $txts = $this->texts; } - $n = count($txts); + $n = is_array($txts) ? count($txts) : 0; $min=null; $max=null; for( $i=0; $i < $n; ++$i ) { @@ -3021,7 +3021,7 @@ function SetTextScaleAbsCenterOff($aOff) { // Get Y min and max values for added lines function GetLinesYMinMax( $aLines ) { - $n = count($aLines); + $n = is_array($aLines) ? count($aLines) : 0; if( $n == 0 ) return false; $min = $aLines[0]->scaleposition ; $max = $min ; @@ -3039,7 +3039,7 @@ function GetLinesYMinMax( $aLines ) { // Get X min and max values for added lines function GetLinesXMinMax( $aLines ) { - $n = count($aLines); + $n = is_array($aLines) ? count($aLines) : 0; if( $n == 0 ) return false ; $min = $aLines[0]->scaleposition ; $max = $min ; @@ -3588,7 +3588,7 @@ function DoStroke($aTicksPos,$aType,$aColor,$aWeight) { if( $this->fill ) { // Draw filled areas - $y2 = $aTicksPos[0]; + $y2 = !empty($aTicksPos) ? $aTicksPos[0] : null; $i=1; while( $i < $nbrgrids ) { $y1 = $y2; @@ -4335,14 +4335,14 @@ function SetTickPositions($aMajPos,$aMinPos=NULL,$aLabels=NULL) { } function HaveManualLabels() { - return count($this->iManualTickLabels) > 0; + return is_array($this->iManualTickLabels) ? count($this->iManualTickLabels) > 0 : false; } // Specify all the tick positions manually and possible also the exact labels function _doManualTickPos($aScale) { $n=count($this->iManualTickPos); - $m=count($this->iManualMinTickPos); - $doLbl=count($this->iManualTickLabels) > 0; + $m= is_array($this->iManualMinTickPos) ? count($this->iManualMinTickPos) : 0; + $doLbl= is_array($this->iManualTickLabels) ? count($this->iManualTickLabels) > 0 : false; $this->maj_ticks_pos = array(); $this->maj_ticklabels_pos = array(); diff --git a/lib/jpgraph/src/jpgraph_bar.php b/lib/jpgraph/src/jpgraph_bar.php index cedc183..ed1d367 100755 --- a/lib/jpgraph/src/jpgraph_bar.php +++ b/lib/jpgraph/src/jpgraph_bar.php @@ -681,7 +681,7 @@ class GroupBarPlot extends BarPlot { private $nbrplots=0; //--------------- // CONSTRUCTOR - function GroupBarPlot($plots) { + function __construct($plots) { $this->width=0.7; $this->plots = $plots; $this->nbrplots = count($plots); diff --git a/lib/jpgraph/src/jpgraph_flags.php b/lib/jpgraph/src/jpgraph_flags.php index a7e2187..f062eb6 100755 --- a/lib/jpgraph/src/jpgraph_flags.php +++ b/lib/jpgraph/src/jpgraph_flags.php @@ -267,7 +267,7 @@ class FlagImages { private $iFlagData ; private $iOrdIdx=array(); - function FlagImages($aSize=FLAGSIZE1) { + function __construct($aSize=FLAGSIZE1) { switch($aSize) { case FLAGSIZE1 : case FLAGSIZE2 : @@ -309,10 +309,9 @@ function GetIdxByOrdinal($aOrd,&$outFullName) { $aOrd--; $n = count($this->iOrdIdx); if( $n == 0 ) { - reset($this->iCountryNameMap); $this->iOrdIdx=array(); $i=0; - while( list($key,$val) = each($this->iCountryNameMap) ) { + foreach( $this->iCountryNameMap as $key => $val ) { $this->iOrdIdx[$i++] = array($val,$key); } $tmp=$this->iOrdIdx[$aOrd]; @@ -341,18 +340,16 @@ function GetIdxByName($aName,&$outFullName) { $found=false; $aName = strtolower($aName); $nlen = strlen($aName); - reset($this->iCountryNameMap); // Start by trying to match exact index name - while( list($key,$val) = each($this->iCountryNameMap) ) { + foreach( $this->iCountryNameMap as $key => $val ) { if( $nlen == strlen($val) && $val == $aName ) { $found=true; break; } } if( !$found ) { - reset($this->iCountryNameMap); // If the exact index doesn't work try a (partial) full name - while( list($key,$val) = each($this->iCountryNameMap) ) { + foreach( $this->iCountryNameMap as $key => $val ) { if( strpos(strtolower($key), $aName) !== false ) { $found=true; break; diff --git a/lib/jpgraph/src/jpgraph_gradient.php b/lib/jpgraph/src/jpgraph_gradient.php index 225cf60..e3c24d3 100755 --- a/lib/jpgraph/src/jpgraph_gradient.php +++ b/lib/jpgraph/src/jpgraph_gradient.php @@ -410,8 +410,8 @@ function GetColArray($from_color,$to_color,$arr_size,&$colors,$numcols=100) { $bdelta=($to_color[2]-$from_color[2])/$numcols; $colorsperstep = $numcols/$arr_size; $prevcolnum = -1; - $from_alpha = $from_color[3]; - $to_alpha = $to_color[3]; + $from_alpha = floatval($from_color[3]); + $to_alpha = floatval($to_color[3]); $adelta = ( $to_alpha - $from_alpha ) / $numcols ; for ($i=0; $i < $arr_size; ++$i) { $colnum = floor($colorsperstep*$i); diff --git a/lib/jpgraph/src/jpgraph_line.php b/lib/jpgraph/src/jpgraph_line.php index 21dd821..8175659 100755 --- a/lib/jpgraph/src/jpgraph_line.php +++ b/lib/jpgraph/src/jpgraph_line.php @@ -35,7 +35,7 @@ class LinePlot extends Plot{ //--------------- // CONSTRUCTOR - function LinePlot($datay,$datax=false) { + function __construct($datay,$datax=false) { parent::__construct($datay,$datax); $this->mark = new PlotMark() ; $this->color = ColorFactory::getColor(); diff --git a/lib/jpgraph/src/jpgraph_log.php b/lib/jpgraph/src/jpgraph_log.php index d5146ec..2f7e4e8 100755 --- a/lib/jpgraph/src/jpgraph_log.php +++ b/lib/jpgraph/src/jpgraph_log.php @@ -131,7 +131,7 @@ class LogTicks extends Ticks{ private $ticklabels_pos = array(); //--------------- // CONSTRUCTOR - function LogTicks() { + function __construct() { } //--------------- // PUBLIC METHODS diff --git a/lib/jpgraph/src/jpgraph_pie.php b/lib/jpgraph/src/jpgraph_pie.php index c79d30f..226784a 100755 --- a/lib/jpgraph/src/jpgraph_pie.php +++ b/lib/jpgraph/src/jpgraph_pie.php @@ -296,14 +296,16 @@ function Legend($graph) { // Make sure we don't plot more values than data points // (in case the user added more legends than data points) - $n = min(count($this->legends),count($this->data)); + $legendsCount = is_array($this->legends) ? count($this->legends) : 0; + $n = min($legendsCount,count($this->data)); if( $this->legends != "" ) { $this->legends = array_reverse(array_slice($this->legends,0,$n)); } for( $i=$n-1; $i >= 0; --$i ) { $l = $this->legends[$i]; // Replace possible format with actual values - if( count($this->csimalts) > $i ) { + $count = is_array($this->csimalts) ? count($this->csimalts) : 0; + if( $count > $i ) { $fmt = $this->csimalts[$i]; } else { diff --git a/lib/jpgraph/src/jpgraph_polar.php b/lib/jpgraph/src/jpgraph_polar.php index 62c6bbc..df73828 100755 --- a/lib/jpgraph/src/jpgraph_polar.php +++ b/lib/jpgraph/src/jpgraph_polar.php @@ -423,6 +423,7 @@ function StrokeAngleLabels($pos,$type) { $this->img->Line($x1,$y1,$x2,$y2); } } + $a = (int) $a; $a += $this->angle_step; } } @@ -487,6 +488,7 @@ function StrokeAngleLabels($pos,$type) { if( $this->show_angle_tick ) { $this->img->Line($x1,$y1,$x2,$y2); } + $a = (int) $a; $a += $this->angle_step; } } diff --git a/lib/jpgraph/src/jpgraph_scatter.php b/lib/jpgraph/src/jpgraph_scatter.php index fe987c2..7c99d39 100755 --- a/lib/jpgraph/src/jpgraph_scatter.php +++ b/lib/jpgraph/src/jpgraph_scatter.php @@ -136,7 +136,7 @@ class ScatterPlot extends Plot { //--------------- // CONSTRUCTOR function __construct($datay,$datax=false) { - if( (count($datax) != count($datay)) && is_array($datax)) { + if( is_array($datax) && (count($datax) != count($datay)) ) { JpGraphError::RaiseL(20003);//("Scatterplot must have equal number of X and Y points."); } parent::__construct($datay,$datax); diff --git a/lib/jpgraph/src/jpgraph_table.php b/lib/jpgraph/src/jpgraph_table.php index 852d78b..7f55cc1 100755 --- a/lib/jpgraph/src/jpgraph_table.php +++ b/lib/jpgraph/src/jpgraph_table.php @@ -141,10 +141,16 @@ function SetGridStyle($aLeft,$aTop=null,$aBottom=null,$aRight=null) { } function SetGridWeight($aLeft=null,$aTop=null,$aBottom=null,$aRight=null) { - if( $aLeft !== null ) $this->iGridWeight[0] = $aLeft; - if( $aTop !== null ) $this->iGridWeight[1] = $aTop; - if( $aBottom !== null ) $this->iGridWeight[2] = $aBottom; - if( $aRight !== null ) $this->iGridWeight[3] = $aRight; + $weight_arr = array($aLeft, $aTop, $aBottom, $aRight); + for ($i = 0; $i < count($weight_arr); $i++) { + if ($weight_arr[$i] === "") { + $weight_arr[$i] = 0; + } + } + if( $aLeft !== null ) $this->iGridWeight[0] = $weight_arr[0]; + if( $aTop !== null ) $this->iGridWeight[1] = $weight_arr[1]; + if( $aBottom !== null ) $this->iGridWeight[2] = $weight_arr[2]; + if( $aRight !== null ) $this->iGridWeight[3] = $weight_arr[3]; } function SetMargin($aLeft,$aRight,$aTop,$aBottom) {