Upgrade jpgrah to 4.3.4

This commit is contained in:
Nigel Sheldon 2021-01-03 17:10:26 +01:00
commit b5868f05f6
72 changed files with 19157 additions and 10327 deletions

View file

@ -1,22 +1,22 @@
<?php
//=======================================================================
// File: JPGRAPH_PLOTBAND.PHP
// Description: PHP4 Graph Plotting library. Extension module.
// Created: 2004-02-18
// Ver: $Id: jpgraph_plotband.php 781 2006-10-08 08:07:47Z ljp $
// File: JPGRAPH_PLOTBAND.PHP
// Description: PHP4 Graph Plotting library. Extension module.
// Created: 2004-02-18
// Ver: $Id: jpgraph_plotband.php 1106 2009-02-22 20:16:35Z ljp $
//
// Copyright (c) Aditus Consulting. All rights reserved.
// Copyright (c) Asial Corporation. All rights reserved.
//========================================================================
// Constants for types of static bands in plot area
DEFINE("BAND_RDIAG", 1); // Right diagonal lines
DEFINE("BAND_LDIAG", 2); // Left diagonal lines
DEFINE("BAND_SOLID", 3); // Solid one color
DEFINE("BAND_VLINE", 4); // Vertical lines
DEFINE("BAND_HLINE", 5); // Horizontal lines
DEFINE("BAND_3DPLANE", 6); // "3D" Plane
DEFINE("BAND_HVCROSS", 7); // Vertical/Hor crosses
DEFINE("BAND_DIAGCROSS", 8); // Diagonal crosses
define("BAND_RDIAG", 1); // Right diagonal lines
define("BAND_LDIAG", 2); // Left diagonal lines
define("BAND_SOLID", 3); // Solid one color
define("BAND_VLINE", 4); // Vertical lines
define("BAND_HLINE", 5); // Horizontal lines
define("BAND_3DPLANE", 6); // "3D" Plane
define("BAND_HVCROSS", 7); // Vertical/Hor crosses
define("BAND_DIAGCROSS", 8); // Diagonal crosses
// Utility class to hold coordinates for a rectangle
@ -28,7 +28,7 @@ class Rectangle
public $h;
public $xe;
public $ye;
public function Rectangle($aX, $aY, $aWidth, $aHeight)
public function __construct($aX, $aY, $aWidth, $aHeight)
{
$this->x=$aX;
$this->y=$aY;
@ -52,10 +52,10 @@ class RectPattern
protected $weight;
protected $rect=null;
protected $doframe=true;
protected $linespacing; // Line spacing in pixels
protected $linespacing; // Line spacing in pixels
protected $iBackgroundColor=-1; // Default is no background fill
public function RectPattern($aColor, $aWeight=1)
public function __construct($aColor, $aWeight=1)
{
$this->color = $aColor;
$this->weight = $aWeight;
@ -70,7 +70,7 @@ class RectPattern
{
$this->rect = $aRect;
}
public function ShowFrame($aShow=true)
{
$this->doframe=$aShow;
@ -119,9 +119,9 @@ class RectPattern
//=====================================================================
class RectPatternSolid extends RectPattern
{
public function RectPatternSolid($aColor="black", $aWeight=1)
public function __construct($aColor="black", $aWeight=1)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
}
public function DoPattern($aImg)
@ -142,12 +142,12 @@ class RectPatternSolid extends RectPattern
//=====================================================================
class RectPatternHor extends RectPattern
{
public function RectPatternHor($aColor="black", $aWeight=1, $aLineSpacing=7)
public function __construct($aColor="black", $aWeight=1, $aLineSpacing=7)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
$this->linespacing = $aLineSpacing;
}
public function DoPattern($aImg)
{
$x0 = $this->rect->x;
@ -166,9 +166,9 @@ class RectPatternHor extends RectPattern
//=====================================================================
class RectPatternVert extends RectPattern
{
public function RectPatternVert($aColor="black", $aWeight=1, $aLineSpacing=7)
public function __construct($aColor="black", $aWeight=1, $aLineSpacing=7)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
$this->linespacing = $aLineSpacing;
}
@ -194,9 +194,9 @@ class RectPatternVert extends RectPattern
//=====================================================================
class RectPatternRDiag extends RectPattern
{
public function RectPatternRDiag($aColor="black", $aWeight=1, $aLineSpacing=12)
public function __construct($aColor="black", $aWeight=1, $aLineSpacing=12)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
$this->linespacing = $aLineSpacing;
}
@ -230,7 +230,7 @@ class RectPatternRDiag extends RectPattern
$x0 += $this->linespacing;
$x1 += $this->linespacing;
}
$y0=$this->rect->y + ($x0-$xe);
$x0=$xe;
} else {
@ -244,7 +244,7 @@ class RectPatternRDiag extends RectPattern
$y1 += $this->linespacing;
$y0 += $this->linespacing;
}
$diff = $y1-$ye;
$y1 = $ye;
$x1 = $diff + $this->rect->x;
@ -257,17 +257,17 @@ class RectPatternRDiag extends RectPattern
}
}
}
//=====================================================================
// Class RectPatternLDiag
// Implements left diagonal pattern
//=====================================================================
class RectPatternLDiag extends RectPattern
{
public function RectPatternLDiag($aColor="black", $aWeight=1, $aLineSpacing=12)
public function __construct($aColor="black", $aWeight=1, $aLineSpacing=12)
{
$this->linespacing = $aLineSpacing;
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
}
public function DoPattern($aImg)
@ -299,7 +299,7 @@ class RectPatternLDiag extends RectPattern
$x0 += $this->linespacing;
$x1 += $this->linespacing;
}
$y0=$this->rect->ye - ($x0-$xe);
$x0=$xe;
} else {
@ -335,9 +335,9 @@ class RectPattern3DPlane extends RectPattern
// top of the band. Specifies how fast the lines
// converge.
public function RectPattern3DPlane($aColor="black", $aWeight=1)
public function __construct($aColor="black", $aWeight=1)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
$this->SetDensity(10); // Slightly larger default
}
@ -345,7 +345,7 @@ class RectPattern3DPlane extends RectPattern
{
$this->alpha=$aHorizon;
}
public function DoPattern($aImg)
{
// "Fake" a nice 3D grid-effect.
@ -395,43 +395,43 @@ class RectPattern3DPlane extends RectPattern
$x0_right = $middle + $dist * $factor;
$c = $apa - $d*$apa/$dist;
}
// Horizontal lines
// They need some serious consideration since they are a function
// of perspective depth (alpha) and density (linespacing)
$x0=$this->rect->x;
$x1=$this->rect->xe;
$y=$this->rect->ye;
// The first line is drawn directly. Makes the loop below slightly
// more readable.
$aImg->Line($x0, $y, $x1, $y);
$hls = $this->linespacing;
// A correction factor for vertical "brick" line spacing to account for
// a) the difference in number of pixels hor vs vert
// b) visual apperance to make the first layer of "bricks" look more
// square.
$vls = $this->linespacing*0.6;
$ds = $hls*($apa-$vls)/$apa;
// Get the slope for the "perspective line" going from bottom right
// corner to top left corner of the "first" brick.
// Uncomment the following lines if you want to get a visual understanding
// of what this helpline does. BTW this mimics the way you would get the
// perspective right when drawing on paper.
/*
$x0 = $middle;
$y0 = $this->rect->ye;
$len=floor(($this->rect->ye-$this->rect->y)/$vls);
$x1 = $middle+round($len*$ds);
$y1 = $this->rect->ye-$len*$vls;
$aImg->PushColor("red");
$aImg->Line($x0,$y0,$x1,$y1);
$aImg->PopColor();
$x0 = $middle;
$y0 = $this->rect->ye;
$len=floor(($this->rect->ye-$this->rect->y)/$vls);
$x1 = $middle+round($len*$ds);
$y1 = $this->rect->ye-$len*$vls;
$aImg->PushColor("red");
$aImg->Line($x0,$y0,$x1,$y1);
$aImg->PopColor();
*/
$y -= $vls;
$k=($this->rect->ye-($this->rect->ye-$vls))/($middle-($middle-$ds));
$dist = $hls;
@ -455,9 +455,9 @@ class RectPatternCross extends RectPattern
{
private $vert=null;
private $hor=null;
public function RectPatternCross($aColor="black", $aWeight=1)
public function __construct($aColor="black", $aWeight=1)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
$this->vert = new RectPatternVert($aColor, $aWeight);
$this->hor = new RectPatternHor($aColor, $aWeight);
}
@ -497,9 +497,9 @@ class RectPatternDiagCross extends RectPattern
{
private $left=null;
private $right=null;
public function RectPatternDiagCross($aColor="black", $aWeight=1)
public function __construct($aColor="black", $aWeight=1)
{
parent::RectPattern($aColor, $aWeight);
parent::__construct($aColor, $aWeight);
$this->right = new RectPatternRDiag($aColor, $aWeight);
$this->left = new RectPatternLDiag($aColor, $aWeight);
}
@ -536,41 +536,41 @@ class RectPatternDiagCross extends RectPattern
//=====================================================================
class RectPatternFactory
{
public function RectPatternFactory()
public function __construct()
{
// Empty
}
public function Create($aPattern, $aColor, $aWeight=1)
{
switch ($aPattern) {
case BAND_RDIAG:
$obj = new RectPatternRDiag($aColor, $aWeight);
break;
case BAND_LDIAG:
$obj = new RectPatternLDiag($aColor, $aWeight);
break;
case BAND_SOLID:
$obj = new RectPatternSolid($aColor, $aWeight);
break;
case BAND_VLINE:
$obj = new RectPatternVert($aColor, $aWeight);
break;
case BAND_HLINE:
$obj = new RectPatternHor($aColor, $aWeight);
break;
case BAND_3DPLANE:
$obj = new RectPattern3DPlane($aColor, $aWeight);
break;
case BAND_HVCROSS:
$obj = new RectPatternCross($aColor, $aWeight);
break;
case BAND_DIAGCROSS:
$obj = new RectPatternDiagCross($aColor, $aWeight);
break;
default:
JpGraphError::RaiseL(16003, $aPattern);
//(" Unknown pattern specification ($aPattern)");
}
case BAND_RDIAG:
$obj = new RectPatternRDiag($aColor, $aWeight);
break;
case BAND_LDIAG:
$obj = new RectPatternLDiag($aColor, $aWeight);
break;
case BAND_SOLID:
$obj = new RectPatternSolid($aColor, $aWeight);
break;
case BAND_VLINE:
$obj = new RectPatternVert($aColor, $aWeight);
break;
case BAND_HLINE:
$obj = new RectPatternHor($aColor, $aWeight);
break;
case BAND_3DPLANE:
$obj = new RectPattern3DPlane($aColor, $aWeight);
break;
case BAND_HVCROSS:
$obj = new RectPatternCross($aColor, $aWeight);
break;
case BAND_DIAGCROSS:
$obj = new RectPatternDiagCross($aColor, $aWeight);
break;
default:
JpGraphError::RaiseL(16003, $aPattern);
//(" Unknown pattern specification ($aPattern)");
}
return $obj;
}
}
@ -590,7 +590,7 @@ class PlotBand
private $min;
private $max;
public function PlotBand($aDir, $aPattern, $aMin, $aMax, $aColor="black", $aWeight=1, $aDepth=DEPTH_BACK)
public function __construct($aDir, $aPattern, $aMin, $aMax, $aColor="black", $aWeight=1, $aDepth=DEPTH_BACK)
{
$f = new RectPatternFactory();
$this->prect = $f->Create($aPattern, $aColor, $aWeight);
@ -603,14 +603,14 @@ class PlotBand
$this->max = $aMax;
$this->depth=$aDepth;
}
// Set position. aRect contains absolute image coordinates
public function SetPos($aRect)
{
assert($this->prect != null) ;
$this->prect->SetPos($aRect);
}
public function ShowFrame($aFlag=true)
{
$this->prect->ShowFrame($aFlag);
@ -621,22 +621,22 @@ class PlotBand
{
$this->depth=$aDepth;
}
public function SetDensity($aDens)
{
$this->prect->SetDensity($aDens);
}
public function GetDir()
{
return $this->dir;
}
public function GetMin()
{
return $this->min;
}
public function GetMax()
{
return $this->max;
@ -646,7 +646,7 @@ class PlotBand
{
// Nothing to do
}
// Display band
public function Stroke($aImg, $aXScale, $aYScale)
{
@ -661,8 +661,8 @@ class PlotBand
// Only draw the bar if it actually appears in the range
if ($this->min < $aYScale->GetMaxVal() && $this->max > $aYScale->GetMinVal()) {
// Trucate to limit of axis
// Trucate to limit of axis
$this->min = max($this->min, $aYScale->GetMinVal());
$this->max = min($this->max, $aYScale->GetMaxVal());
@ -673,18 +673,18 @@ class PlotBand
$this->prect->SetPos(new Rectangle($x, $y, $width, $height));
$this->prect->Stroke($aImg);
}
} else { // VERTICAL
} else { // VERTICAL
if ($this->min === 'min') {
$this->min = $aXScale->GetMinVal();
}
if ($this->max === 'max') {
$this->max = $aXScale->GetMaxVal();
}
// Only draw the bar if it actually appears in the range
if ($this->min < $aXScale->GetMaxVal() && $this->max > $aXScale->GetMinVal()) {
// Trucate to limit of axis
// Trucate to limit of axis
$this->min = max($this->min, $aXScale->GetMinVal());
$this->max = min($this->max, $aXScale->GetMaxVal());