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,13 +1,13 @@
<?php
/*=======================================================================
// File: JPGRAPH_PIE3D.PHP
// Description: 3D Pie plot extension for JpGraph
// Created: 2001-03-24
// Ver: $Id: jpgraph_pie3d.php 956 2007-11-17 13:19:20Z ljp $
//
// Copyright (c) Aditus Consulting. All rights reserved.
//========================================================================
*/
// File: JPGRAPH_PIE3D.PHP
// Description: 3D Pie plot extension for JpGraph
// Created: 2001-03-24
// Ver: $Id: jpgraph_pie3d.php 1329 2009-06-20 19:23:30Z ljp $
//
// Copyright (c) Asial Corporation. All rights reserved.
//========================================================================
*/
//===================================================
// CLASS PiePlot3D
@ -20,13 +20,12 @@ class PiePlot3D extends PiePlot
private $showlabelhint=true;
private $angle=50;
private $edgecolor="";
private $edgeweight=1;
private $iThickness=false;
//---------------
// CONSTRUCTOR
public function PiePlot3d($data)
public function __construct($data)
{
$this->radius = 0.5;
$this->data = $data;
@ -39,7 +38,7 @@ class PiePlot3D extends PiePlot
//---------------
// PUBLIC METHODS
// Set label arrays
public function SetLegends($aLegend)
{
@ -72,22 +71,14 @@ class PiePlot3D extends PiePlot
$this->edgeweight = $aWeight;
}
// Dummy function to make Pie3D behave in a similair way to 2D
public function ShowBorder($exterior=true, $interior=true)
{
JpGraphError::RaiseL(14001);
//('Pie3D::ShowBorder() . Deprecated function. Use Pie3D::SetEdge() to control the edges around slices.');
}
// Specify projection angle for 3D in degrees
// Must be between 20 and 70 degrees
public function SetAngle($a)
{
if ($a<5 || $a>90) {
JpGraphError::RaiseL(14002);
}
//("PiePlot3D::SetAngle() 3D Pie projection angle must be between 5 and 85 degrees.");
else {
} else {
$this->angle = $a;
}
}
@ -111,7 +102,7 @@ class PiePlot3D extends PiePlot
$yp = floor($yp+$thick);
$coords.= ", $xp, $yp";
}
//add coordinates every 0.2 radians
$a=$sa+0.2;
while ($a<$ea) {
@ -124,7 +115,7 @@ class PiePlot3D extends PiePlot
$coords.= ", $xp, $yp";
$a += 0.2;
}
//Add the last point on the arc
$xp = floor($width*cos($ea)/2+$xc);
$yp = floor($yc-$height*sin($ea)/2);
@ -138,11 +129,11 @@ class PiePlot3D extends PiePlot
if (!empty($this->csimtargets[$i])) {
$this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".$this->csimtargets[$i]."\"";
if (!empty($this->csimwintargets[$i])) {
$this->csimareas .= " target=\"".$this->csimwintargets[$i]."\" ";
}
if (!empty($this->csimalts[$i])) {
$tmp=sprintf($this->csimalts[$i], $this->data[$i]);
$this->csimareas .= "alt=\"$tmp\" title=\"$tmp\" ";
@ -157,19 +148,19 @@ class PiePlot3D extends PiePlot
$this->ilabelposadj=$aLblPosAdj;
}
// Distance from the pie to the labels
public function SetLabelMargin($m)
{
$this->value->SetMargin($m);
}
// Show a thin line from the pie to the label for a specific slice
public function ShowLabelHint($f=true)
{
$this->showlabelhint=$f;
}
// Set color of hint line to label for each slice
public function SetLabelHintColor($c)
{
@ -206,13 +197,13 @@ class PiePlot3D extends PiePlot
return $a;
}
// Draw one 3D pie slice at position ($xc,$yc) with height $z
public function Pie3DSlice($img, $xc, $yc, $w, $h, $sa, $ea, $z, $fillcolor, $shadow=0.65)
{
// Due to the way the 3D Pie algorithm works we are
// Due to the way the 3D Pie algorithm works we are
// guaranteed that any slice we get into this method
// belongs to either the left or right side of the
// pie ellipse. Hence, no slice will cross 90 or 270
@ -225,9 +216,9 @@ class PiePlot3D extends PiePlot
$p[] = array();
// Setup pre-calculated values
$rsa = $sa/180*M_PI; // to Rad
$rea = $ea/180*M_PI; // to Rad
$sinsa = sin($rsa);
$rsa = $sa/180*M_PI; // to Rad
$rea = $ea/180*M_PI; // to Rad
$sinsa = sin($rsa);
$cossa = cos($rsa);
$sinea = sin($rea);
$cosea = cos($rea);
@ -246,7 +237,7 @@ class PiePlot3D extends PiePlot
}
$p = array($xc,$yc,$xc,$yc+$z,
$xc+$w*$cossa,$z+$yc-$h*$sinsa);
$xc+$w*$cossa,$z+$yc-$h*$sinsa);
$pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa);
for ($a=$rsa; $a < 2*M_PI; $a += $step) {
@ -272,16 +263,16 @@ class PiePlot3D extends PiePlot
$pt[] = $xc + $w*cos($a);
$pt[] = $yc - $h*sin($a);
}
$pt[] = $xc+$w*$cosea;
$pt[] = $yc-$h*$sinea;
$pt[] = $xc;
$pt[] = $yc;
} else {
$p = array($xc,$yc,$xc,$yc+$z,
$xc+$w*$cossa,$z+$yc-$h*$sinsa);
$xc+$w*$cossa,$z+$yc-$h*$sinsa);
$pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa);
$rea = $rea == 0.0 ? 2*M_PI : $rea;
for ($a=$rsa; $a < $rea; $a += $step) {
$tca = cos($a);
@ -296,7 +287,7 @@ class PiePlot3D extends PiePlot
$pt[] = $yc-$h*$sinea;
$pt[] = $xc;
$pt[] = $yc;
$p[] = $xc+$w*$cosea;
$p[] = $z+$yc-$h*$sinea;
$p[] = $xc+$w*$cosea;
@ -307,7 +298,7 @@ class PiePlot3D extends PiePlot
} elseif ($sa >= 180) {
$p = array($xc,$yc,$xc,$yc+$z,$xc+$w*$cosea,$z+$yc-$h*$sinea);
$pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea);
for ($a=$rea; $a>$rsa; $a -= $step) {
$tca = cos($a);
$tsa = sin($a);
@ -321,7 +312,7 @@ class PiePlot3D extends PiePlot
$pt[] = $yc-$h*$sinsa;
$pt[] = $xc;
$pt[] = $yc;
$p[] = $xc+$w*$cossa;
$p[] = $z+$yc-$h*$sinsa;
$p[] = $xc+$w*$cossa;
@ -365,9 +356,9 @@ class PiePlot3D extends PiePlot
$pt[] = $yc;
} else { // $sa >= 90 && $ea <= 180
$p = array($xc,$yc,$xc,$yc+$z,
$xc+$w*$cosea,$z+$yc-$h*$sinea,
$xc+$w*$cosea,$yc-$h*$sinea,
$xc,$yc);
$xc+$w*$cosea,$z+$yc-$h*$sinea,
$xc+$w*$cosea,$yc-$h*$sinea,
$xc,$yc);
$pt = array($xc,$yc,$xc+$w*$cosea,$yc-$h*$sinea);
@ -384,9 +375,9 @@ class PiePlot3D extends PiePlot
} else { // sa > 0 && ea < 90
$p = array($xc,$yc,$xc,$yc+$z,
$xc+$w*$cossa,$z+$yc-$h*$sinsa,
$xc+$w*$cossa,$yc-$h*$sinsa,
$xc,$yc);
$xc+$w*$cossa,$z+$yc-$h*$sinsa,
$xc+$w*$cossa,$yc-$h*$sinsa,
$xc,$yc);
$pt = array($xc,$yc,$xc+$w*$cossa,$yc-$h*$sinsa);
@ -400,7 +391,7 @@ class PiePlot3D extends PiePlot
$pt[] = $xc;
$pt[] = $yc;
}
$img->PushColor($fillcolor.":".$shadow);
$img->FilledPolygon($p);
$img->PopColor();
@ -417,7 +408,7 @@ class PiePlot3D extends PiePlot
}
$this->startangle = $aStart;
}
// Draw a 3D Pie
public function Pie3D(
$aaoption,
@ -433,9 +424,10 @@ class PiePlot3D extends PiePlot
$startangle=0,
$edgecolor="",
$edgeweight=1
) {
)
{
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// As usual the algorithm get more complicated than I originally
// envisioned. I believe that this is as simple as it is possible
// to do it with the features I want. It's a good exercise to start
@ -471,7 +463,7 @@ class PiePlot3D extends PiePlot
// slice. Not a major problem though.
//---------------------------------------------------------------------------
// Determine the height of the ellippse which gives an
// indication of the inclination angle
$h = ($angle/90.0)*$d;
@ -479,7 +471,7 @@ class PiePlot3D extends PiePlot
for ($i=0; $i<count($data); ++$i) {
$sum += $data[$i];
}
// Special optimization
if ($sum==0) {
return;
@ -514,7 +506,7 @@ class PiePlot3D extends PiePlot
$la = $a + $da/2;
$explode = array( $xc + $this->explode_radius[$i]*cos($la*M_PI/180)*$expscale,
$yc - $this->explode_radius[$i]*sin($la*M_PI/180) * ($h/$d) *$expscale );
$yc - $this->explode_radius[$i]*sin($la*M_PI/180) * ($h/$d) *$expscale );
$adjexplode[$idx] = $explode;
$labeldata[$i] = array($la,$explode[0],$explode[1]);
$originalangles[$i] = array($a,$a+$da);
@ -522,15 +514,15 @@ class PiePlot3D extends PiePlot
$ne = $this->NormAngle($a+$da);
if ($da <= 180) {
// If the slice size is <= 90 it can at maximum cut across
// one boundary (either 90 or 270) where it needs to be split
$split=-1; // no split
if (($da<=90 && ($a <= 90 && $ne > 90)) ||
(($da <= 180 && $da >90) && (($a < 90 || $a >= 270) && $ne > 90))) {
$split = 90;
} elseif (($da<=90 && ($a <= 270 && $ne > 270)) ||
// one boundary (either 90 or 270) where it needs to be split
$split=-1; // no split
if (($da<=90 && ($a <= 90 && $ne > 90)) ||
(($da <= 180 && $da >90) && (($a < 90 || $a >= 270) && $ne > 90))) {
$split = 90;
} elseif (($da<=90 && ($a <= 270 && $ne > 270)) ||
(($da<=180 && $da>90) && ($a >= 90 && $a < 270 && ($a+$da) > 270))) {
$split = 270;
}
$split = 270;
}
if ($split > 0) { // split in two
$angles[$idx] = array($a,$split);
$adjcolors[$idx] = $colors[$i % $numcolors];
@ -574,9 +566,7 @@ class PiePlot3D extends PiePlot
// c) If start is > 270 (hence the firstr split is at 90)
// and the slice is so large that it goes all the way
// around 270.
if (($a < 90 && ($a+$da > 270)) ||
($a > 90 && $a<=270 && ($a+$da>360+90)) ||
($a > 270 && $this->NormAngle($a+$da)>270)) {
if (($a < 90 && ($a+$da > 270)) || ($a > 90 && $a<=270 && ($a+$da>360+90)) || ($a > 270 && $this->NormAngle($a+$da)>270)) {
$angles[++$idx] = array($split,360-$split);
$adjcolors[$idx] = $colors[$i % $numcolors];
$adjexplode[$idx] = $explode;
@ -632,10 +622,10 @@ class PiePlot3D extends PiePlot
// Step 3. Print slices in z-order
//
$cnt = 0;
// First stroke all the slices between 90 and 270 (left half circle)
// counterclockwise
while ($angles[$j][0] < 270 && $aaoption !== 2) {
list($x, $y) = $adjexplode[$j];
@ -651,7 +641,7 @@ class PiePlot3D extends PiePlot
$adjcolors[$j],
$shadow
);
$last = array($x,$y,$j);
$j++;
@ -664,14 +654,14 @@ class PiePlot3D extends PiePlot
}
++$cnt;
}
$slice_left = $n-$cnt;
$j=$start-1;
if ($j<0) {
$j=$n-1;
}
$cnt = 0;
// The stroke all slices from 90 to -90 (right half circle)
// clockwise
while ($cnt < $slice_left && $aaoption !== 2) {
@ -699,7 +689,7 @@ class PiePlot3D extends PiePlot
}
$cnt++;
}
// Now do a special thing. Stroke the last slice on the left
// halfcircle one more time. This is needed in the case where
// the slice close to 270 have been exploded. In that case the
@ -750,7 +740,7 @@ class PiePlot3D extends PiePlot
}
$this->StrokeLabels($l, $img, $labeldata[$i][0]*M_PI/180, $x, $y, $z);
$this->Add3DSliceToCSIM(
$i,
$labeldata[$i][1],
@ -781,7 +771,7 @@ class PiePlot3D extends PiePlot
$idx=0;
$img->PushColor($edgecolor);
$img->SetLineWeight($edgeweight);
$fulledge = true;
for ($i=0; $i < count($data) && $fulledge; ++$i) {
if (empty($this->explode_radius[$i])) {
@ -791,7 +781,7 @@ class PiePlot3D extends PiePlot
$fulledge = false;
}
}
for ($i=0; $i < count($data); ++$i, ++$idx) {
$da = $data[$i]/$sum * 2*M_PI;
@ -849,15 +839,15 @@ class PiePlot3D extends PiePlot
if ($sa < M_PI && $ea > M_PI) {
$sa = M_PI;
}
if ($sa < 2*M_PI && (($ea >= 2*M_PI) || ($ea > 0 && $ea < $sa))) {
$ea = 2*M_PI;
}
if ($sa >= M_PI && $ea <= 2*M_PI) {
$p = array($xc + $w*cos($sa),$yc - $h*sin($sa),
$xc + $w*cos($sa),$z + $yc - $h*sin($sa));
$xc + $w*cos($sa),$z + $yc - $h*sin($sa));
for ($a=$sa+$step; $a < $ea; $a += $step) {
$p[] = $xc + $w*cos($a);
$p[] = $z + $yc - $h*sin($a);
@ -890,20 +880,20 @@ class PiePlot3D extends PiePlot
} else {
$ca = $this->setslicecolors;
}
if ($this->posx <= 1 && $this->posx > 0) {
$xc = round($this->posx*$img->width);
} else {
$xc = $this->posx ;
}
if ($this->posy <= 1 && $this->posy > 0) {
$yc = round($this->posy*$img->height);
} else {
$yc = $this->posy ;
}
if ($this->radius <= 1) {
$width = floor($this->radius*min($img->width, $img->height));
// Make sure that the pie doesn't overflow the image border
@ -923,7 +913,7 @@ class PiePlot3D extends PiePlot
// pie slice width (=pie radius) but since the perspective depends
// on the inclination angle we use some heuristics to make the edge
// slightly thicker the less the angle.
// Has user specified an absolute thickness? In that case use
// that instead
@ -934,6 +924,7 @@ class PiePlot3D extends PiePlot
$thick = $width/12;
}
$a = $this->angle;
if ($a <= 30) {
$thick *= 1.6;
} elseif ($a <= 40) {
@ -1008,9 +999,11 @@ class PiePlot3D extends PiePlot
} else {
$w=$img->GetTextWidth($label);
}
while ($a > 2*M_PI) {
$a -= 2*M_PI;
}
if ($a>=7*M_PI/4 || $a <= M_PI/4) {
$dx=0;
}
@ -1023,7 +1016,7 @@ class PiePlot3D extends PiePlot
if ($a>=5*M_PI/4 && $a <= 7*M_PI/4) {
$dx=(1-($a-M_PI*5/4)*2/M_PI);
}
if ($a>=7*M_PI/4) {
$dy=(($a-M_PI)-3*M_PI/4)*2/M_PI;
}
@ -1039,17 +1032,17 @@ class PiePlot3D extends PiePlot
if ($a>=5*M_PI/4 && $a <= 7*M_PI/4) {
$dy=0;
}
$x = round($xp-$dx*$w);
$y = round($yp-$dy*$h);
// Mark anchor point for debugging
/*
$img->SetColor('red');
$img->Line($xp-10,$yp,$xp+10,$yp);
$img->Line($xp,$yp-10,$xp,$yp+10);
*/
$oldmargin = $this->value->margin;
$this->value->margin=0;
$this->value->Stroke($img, $label, $x, $y);