forked from halo-battle/game
Upgrade jpgrah to 4.3.4
This commit is contained in:
parent
7c3999c5cd
commit
b5868f05f6
72 changed files with 19157 additions and 10327 deletions
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
/*=======================================================================
|
||||
// File: JPGRAPH_BAR.PHP
|
||||
// Description: Bar plot extension for JpGraph
|
||||
// Created: 2001-01-08
|
||||
// Ver: $Id: jpgraph_bar.php 957 2007-12-01 14:00:29Z ljp $
|
||||
//
|
||||
// Copyright (c) Aditus Consulting. All rights reserved.
|
||||
//========================================================================
|
||||
*/
|
||||
// File: JPGRAPH_BAR.PHP
|
||||
// Description: Bar plot extension for JpGraph
|
||||
// Created: 2001-01-08
|
||||
// Ver: $Id: jpgraph_bar.php 1905 2009-10-06 18:00:21Z ljp $
|
||||
//
|
||||
// Copyright (c) Asial Corporation. All rights reserved.
|
||||
//========================================================================
|
||||
*/
|
||||
|
||||
require_once('jpgraph_plotband.php');
|
||||
|
||||
|
|
@ -48,30 +48,42 @@ class BarPlot extends Plot
|
|||
protected $bar_shadow_color="black";
|
||||
protected $bar_shadow_hsize=3;
|
||||
protected $bar_shadow_vsize=3;
|
||||
|
||||
protected $bar_3d=false;
|
||||
protected $bar_3d_hsize=3;
|
||||
protected $bar_3d_vsize=3;
|
||||
|
||||
//---------------
|
||||
// CONSTRUCTOR
|
||||
public function BarPlot($datay, $datax=false)
|
||||
public function __construct($datay, $datax=false)
|
||||
{
|
||||
$this->Plot($datay, $datax);
|
||||
parent::__construct($datay, $datax);
|
||||
++$this->numpoints;
|
||||
}
|
||||
|
||||
//---------------
|
||||
// PUBLIC METHODS
|
||||
|
||||
|
||||
// Set a drop shadow for the bar (or rather an "up-right" shadow)
|
||||
public function SetShadow($color="black", $hsize=3, $vsize=3, $show=true)
|
||||
public function SetShadow($aColor="black", $aHSize=3, $aVSize=3, $aShow=true)
|
||||
{
|
||||
$this->bar_shadow=$show;
|
||||
$this->bar_shadow_color=$color;
|
||||
$this->bar_shadow_vsize=$vsize;
|
||||
$this->bar_shadow_hsize=$hsize;
|
||||
|
||||
$this->bar_shadow=$aShow;
|
||||
$this->bar_shadow_color=$aColor;
|
||||
$this->bar_shadow_vsize=$aVSize;
|
||||
$this->bar_shadow_hsize=$aHSize;
|
||||
|
||||
// Adjust the value margin to compensate for shadow
|
||||
$this->value->margin += $vsize;
|
||||
$this->value->margin += $aVSize;
|
||||
}
|
||||
|
||||
|
||||
public function Set3D($aHSize=3, $aVSize=3, $aShow=true)
|
||||
{
|
||||
$this->bar_3d=$aShow;
|
||||
$this->bar_3d_vsize=$aVSize;
|
||||
$this->bar_3d_hsize=$aHSize;
|
||||
|
||||
$this->value->margin += $aVSize;
|
||||
}
|
||||
|
||||
// DEPRECATED use SetYBase instead
|
||||
public function SetYMin($aYStartValue)
|
||||
{
|
||||
|
|
@ -84,7 +96,21 @@ class BarPlot extends Plot
|
|||
{
|
||||
$this->ybase=$aYStartValue;
|
||||
}
|
||||
|
||||
|
||||
// The method will take the specified pattern anre
|
||||
// return a pattern index that corresponds to the original
|
||||
// patterm being rotated 90 degreees. This is needed when plottin
|
||||
// Horizontal bars
|
||||
public function RotatePattern($aPat, $aRotate=true)
|
||||
{
|
||||
$rotate = array(1 => 2, 2 => 1, 3 => 3, 4 => 5, 5 => 4, 6 => 6, 7 => 7, 8 => 8);
|
||||
if ($aRotate) {
|
||||
return $rotate[$aPat];
|
||||
} else {
|
||||
return $aPat;
|
||||
}
|
||||
}
|
||||
|
||||
public function Legend($graph)
|
||||
{
|
||||
if ($this->grad && $this->legend!="" && !$this->fill) {
|
||||
|
|
@ -101,14 +127,17 @@ class BarPlot extends Plot
|
|||
);
|
||||
} elseif ($this->legend!="" && ($this->iPattern > -1 || is_array($this->iPattern))) {
|
||||
if (is_array($this->iPattern)) {
|
||||
$p1 = $this->iPattern[0];
|
||||
$p1 = $this->RotatePattern($this->iPattern[0], $graph->img->a == 90);
|
||||
$p2 = $this->iPatternColor[0];
|
||||
$p3 = $this->iPatternDensity[0];
|
||||
} else {
|
||||
$p1 = $this->iPattern;
|
||||
$p1 = $this->RotatePattern($this->iPattern, $graph->img->a == 90);
|
||||
$p2 = $this->iPatternColor;
|
||||
$p3 = $this->iPatternDensity;
|
||||
}
|
||||
if ($p3 < 90) {
|
||||
$p3 += 5;
|
||||
}
|
||||
$color = array($p1,$p2,$p3,$this->fill_color);
|
||||
// A kludge: Too mark that we add a pattern we use a type value of < 100
|
||||
$graph->legend->Add(
|
||||
|
|
@ -156,7 +185,7 @@ class BarPlot extends Plot
|
|||
if (substr($graph->axtype, -3, 3)=="log" && $this->ybase==0) {
|
||||
$this->ybase = $graph->yaxis->scale->GetMinVal();
|
||||
}
|
||||
|
||||
|
||||
// For a "text" X-axis scale we will adjust the
|
||||
// display of the bars a little bit.
|
||||
if (substr($graph->axtype, 0, 3)=="tex") {
|
||||
|
|
@ -180,7 +209,7 @@ class BarPlot extends Plot
|
|||
if ($this->abswidth == -1) {
|
||||
// Not set
|
||||
// set width to a visuable sensible default
|
||||
$this->abswidth = $graph->img->plotwidth/(2*count($this->coords[0]));
|
||||
$this->abswidth = $graph->img->plotwidth/(2*$this->numpoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -202,7 +231,7 @@ class BarPlot extends Plot
|
|||
}
|
||||
return $m;
|
||||
}
|
||||
|
||||
|
||||
// Specify width as fractions of the major stepo size
|
||||
public function SetWidth($aWidth)
|
||||
{
|
||||
|
|
@ -213,32 +242,37 @@ class BarPlot extends Plot
|
|||
$this->width=$aWidth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Specify width in absolute pixels. If specified this
|
||||
// overrides SetWidth()
|
||||
public function SetAbsWidth($aWidth)
|
||||
{
|
||||
$this->abswidth=$aWidth;
|
||||
}
|
||||
|
||||
|
||||
public function SetAlign($aAlign)
|
||||
{
|
||||
$this->align=$aAlign;
|
||||
}
|
||||
|
||||
|
||||
public function SetNoFill()
|
||||
{
|
||||
$this->grad = false;
|
||||
$this->fill_color=false;
|
||||
$this->fill=false;
|
||||
}
|
||||
|
||||
|
||||
public function SetFillColor($aColor)
|
||||
{
|
||||
// Do an extra error check if the color is specified as an RGB array triple
|
||||
// In that case convert it to a hex string since it will otherwise be
|
||||
// interpretated as an array of colors for each individual bar.
|
||||
|
||||
$aColor = RGB::tryHexConversion($aColor);
|
||||
$this->fill = true ;
|
||||
$this->fill_color=$aColor;
|
||||
}
|
||||
|
||||
|
||||
public function SetFillGradient($aFromColor, $aToColor=null, $aStyle=null)
|
||||
{
|
||||
$this->grad = true;
|
||||
|
|
@ -246,7 +280,7 @@ class BarPlot extends Plot
|
|||
$this->grad_tocolor = $aToColor;
|
||||
$this->grad_style = $aStyle;
|
||||
}
|
||||
|
||||
|
||||
public function SetValuePos($aPos)
|
||||
{
|
||||
$this->valuepos = $aPos;
|
||||
|
|
@ -261,7 +295,7 @@ class BarPlot extends Plot
|
|||
if (is_array($aColor)) {
|
||||
$this->iPatternColor = array();
|
||||
if (count($aColor) != $n) {
|
||||
JpGraphError::Raise('NUmber of colors is not the same as the number of patterns in BarPlot::SetPattern()');
|
||||
JpGraphError::RaiseL(2001);//('NUmber of colors is not the same as the number of patterns in BarPlot::SetPattern()');
|
||||
}
|
||||
} else {
|
||||
$this->iPatternColor = $aColor;
|
||||
|
|
@ -281,49 +315,62 @@ class BarPlot extends Plot
|
|||
public function _SetPatternHelper($aPattern, &$aPatternValue, &$aDensity)
|
||||
{
|
||||
switch ($aPattern) {
|
||||
case PATTERN_DIAG1:
|
||||
$aPatternValue= 1;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_DIAG2:
|
||||
$aPatternValue= 1;
|
||||
$aDensity = 75;
|
||||
break;
|
||||
case PATTERN_DIAG3:
|
||||
$aPatternValue= 2;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_DIAG4:
|
||||
$aPatternValue= 2;
|
||||
$aDensity = 75;
|
||||
break;
|
||||
case PATTERN_CROSS1:
|
||||
$aPatternValue= 8;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_CROSS2:
|
||||
$aPatternValue= 8;
|
||||
$aDensity = 78;
|
||||
break;
|
||||
case PATTERN_CROSS3:
|
||||
$aPatternValue= 8;
|
||||
$aDensity = 65;
|
||||
break;
|
||||
case PATTERN_CROSS4:
|
||||
$aPatternValue= 7;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_STRIPE1:
|
||||
$aPatternValue= 5;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_STRIPE2:
|
||||
$aPatternValue= 5;
|
||||
$aDensity = 75;
|
||||
break;
|
||||
default:
|
||||
JpGraphError::Raise('Unknown pattern specified in call to BarPlot::SetPattern()');
|
||||
case PATTERN_DIAG1:
|
||||
$aPatternValue= 1;
|
||||
$aDensity = 92;
|
||||
break;
|
||||
case PATTERN_DIAG2:
|
||||
$aPatternValue= 1;
|
||||
$aDensity = 78;
|
||||
break;
|
||||
case PATTERN_DIAG3:
|
||||
$aPatternValue= 2;
|
||||
$aDensity = 92;
|
||||
break;
|
||||
case PATTERN_DIAG4:
|
||||
$aPatternValue= 2;
|
||||
$aDensity = 78;
|
||||
break;
|
||||
case PATTERN_CROSS1:
|
||||
$aPatternValue= 8;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_CROSS2:
|
||||
$aPatternValue= 8;
|
||||
$aDensity = 78;
|
||||
break;
|
||||
case PATTERN_CROSS3:
|
||||
$aPatternValue= 8;
|
||||
$aDensity = 65;
|
||||
break;
|
||||
case PATTERN_CROSS4:
|
||||
$aPatternValue= 7;
|
||||
$aDensity = 90;
|
||||
break;
|
||||
case PATTERN_STRIPE1:
|
||||
$aPatternValue= 5;
|
||||
$aDensity = 94;
|
||||
break;
|
||||
case PATTERN_STRIPE2:
|
||||
$aPatternValue= 5;
|
||||
$aDensity = 85;
|
||||
break;
|
||||
default:
|
||||
JpGraphError::RaiseL(2002);
|
||||
//('Unknown pattern specified in call to BarPlot::SetPattern()');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @override
|
||||
* Without overriding this method, $this->numpoints does not updated correctly.
|
||||
*/
|
||||
public function Clear()
|
||||
{
|
||||
$this->isRunningClear = true;
|
||||
$this->__construct($this->inputValues['aDatay'], $this->inputValues['aDatax']);
|
||||
$this->isRunningClear = false;
|
||||
}
|
||||
|
||||
public function Stroke($img, $xscale, $yscale)
|
||||
|
|
@ -331,15 +378,16 @@ class BarPlot extends Plot
|
|||
$numpoints = count($this->coords[0]);
|
||||
if (isset($this->coords[1])) {
|
||||
if (count($this->coords[1])!=$numpoints) {
|
||||
JpGraphError::Raise("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])."Number of Y-points:$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");
|
||||
} else {
|
||||
$exist_x = true;
|
||||
}
|
||||
} else {
|
||||
$exist_x = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$numbars=count($this->coords[0]);
|
||||
|
||||
// Use GetMinVal() instead of scale[0] directly since in the case
|
||||
|
|
@ -361,11 +409,11 @@ class BarPlot extends Plot
|
|||
if (is_array($this->iPattern)) {
|
||||
$np = count($this->iPattern);
|
||||
}
|
||||
|
||||
|
||||
$grad = null;
|
||||
for ($i=0; $i < $numbars; ++$i) {
|
||||
|
||||
// If value is NULL, or 0 then don't draw a bar at all
|
||||
// If value is NULL, or 0 then don't draw a bar at all
|
||||
if ($this->coords[0][$i] === null || $this->coords[0][$i] === '') {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -375,25 +423,25 @@ class BarPlot extends Plot
|
|||
} else {
|
||||
$x=$i;
|
||||
}
|
||||
|
||||
|
||||
$x=$xscale->Translate($x);
|
||||
|
||||
// Comment Note: This confuses the positioning when using acc together with
|
||||
// grouped bars. Workaround for fixing #191
|
||||
/*
|
||||
if( !$xscale->textscale ) {
|
||||
if($this->align=="center")
|
||||
$x -= $abswidth/2;
|
||||
elseif($this->align=="right")
|
||||
$x -= $abswidth;
|
||||
}
|
||||
if( !$xscale->textscale ) {
|
||||
if($this->align=="center")
|
||||
$x -= $abswidth/2;
|
||||
elseif($this->align=="right")
|
||||
$x -= $abswidth;
|
||||
}
|
||||
*/
|
||||
// Stroke fill color and fill gradient
|
||||
$pts=array(
|
||||
$x,$zp,
|
||||
$x,$yscale->Translate($this->coords[0][$i]),
|
||||
$x+$abswidth,$yscale->Translate($this->coords[0][$i]),
|
||||
$x+$abswidth,$zp);
|
||||
$x,$zp,
|
||||
$x,$yscale->Translate($this->coords[0][$i]),
|
||||
$x+$abswidth,$yscale->Translate($this->coords[0][$i]),
|
||||
$x+$abswidth,$zp);
|
||||
if ($this->grad) {
|
||||
if ($grad === null) {
|
||||
$grad = new Gradient($img);
|
||||
|
|
@ -411,6 +459,10 @@ class BarPlot extends Plot
|
|||
$fromcolor = $this->grad_fromcolor;
|
||||
$tocolor = $this->grad_tocolor;
|
||||
$style = $this->grad_style;
|
||||
} else {
|
||||
$fromcolor = $this->grad_fromcolor[$i % $ng][0];
|
||||
$tocolor = $this->grad_fromcolor[$i % $ng][1];
|
||||
$style = $this->grad_fromcolor[$i % $ng][2];
|
||||
}
|
||||
} else {
|
||||
$fromcolor = $this->grad_fromcolor[$i % $ng][0];
|
||||
|
|
@ -446,13 +498,15 @@ class BarPlot extends Plot
|
|||
$img->FilledPolygon($pts);
|
||||
$img->PopColor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////kokorahen rectangle polygon//////////////////////
|
||||
|
||||
// Remember value of this bar
|
||||
$val=$this->coords[0][$i];
|
||||
|
||||
if (!empty($val) && !is_numeric($val)) {
|
||||
JpGraphError::Raise('All values for a barplot must be numeric. You have specified value['.$i.'] == \''.$val.'\'');
|
||||
JpGraphError::RaiseL(2004, $i, $val);
|
||||
//'All values for a barplot must be numeric. You have specified value['.$i.'] == \''.$val.'\'');
|
||||
}
|
||||
|
||||
// Determine the shadow
|
||||
|
|
@ -490,7 +544,7 @@ class BarPlot extends Plot
|
|||
if (is_array($this->bar_shadow_color)) {
|
||||
$numcolors = count($this->bar_shadow_color);
|
||||
if ($numcolors == 0) {
|
||||
JpGraphError::Raise('You have specified an empty array for shadow colors in the bar plot.');
|
||||
JpGraphError::RaiseL(2005);//('You have specified an empty array for shadow colors in the bar plot.');
|
||||
}
|
||||
$img->PushColor($this->bar_shadow_color[$i % $numcolors]);
|
||||
} else {
|
||||
|
|
@ -498,8 +552,62 @@ class BarPlot extends Plot
|
|||
}
|
||||
$img->FilledPolygon($sp);
|
||||
$img->PopColor();
|
||||
} elseif ($this->bar_3d && $val != 0) {
|
||||
// Determine the 3D
|
||||
|
||||
$ssh = $this->bar_3d_hsize;
|
||||
$ssv = $this->bar_3d_vsize;
|
||||
|
||||
// Create points to create a "upper-right" shadow
|
||||
if ($val > 0) {
|
||||
$sp1[0]=$pts[6];
|
||||
$sp1[1]=$pts[7];
|
||||
$sp1[2]=$pts[4];
|
||||
$sp1[3]=$pts[5];
|
||||
$sp1[4]=$pts[4]+$ssh;
|
||||
$sp1[5]=$pts[5]-$ssv;
|
||||
$sp1[6]=$pts[6]+$ssh;
|
||||
$sp1[7]=$pts[7]-$ssv;
|
||||
|
||||
$sp2[0]=$pts[4];
|
||||
$sp2[1]=$pts[5];
|
||||
$sp2[2]=$pts[2];
|
||||
$sp2[3]=$pts[3];
|
||||
$sp2[4]=$pts[2]+$ssh;
|
||||
$sp2[5]=$pts[3]-$ssv;
|
||||
$sp2[6]=$pts[4]+$ssh;
|
||||
$sp2[7]=$pts[5]-$ssv;
|
||||
} elseif ($val < 0) {
|
||||
$sp1[0]=$pts[4];
|
||||
$sp1[1]=$pts[5];
|
||||
$sp1[2]=$pts[6];
|
||||
$sp1[3]=$pts[7];
|
||||
$sp1[4]=$pts[6]+$ssh;
|
||||
$sp1[5]=$pts[7]-$ssv;
|
||||
$sp1[6]=$pts[4]+$ssh;
|
||||
$sp1[7]=$pts[5]-$ssv;
|
||||
|
||||
$sp2[0]=$pts[6];
|
||||
$sp2[1]=$pts[7];
|
||||
$sp2[2]=$pts[0];
|
||||
$sp2[3]=$pts[1];
|
||||
$sp2[4]=$pts[0]+$ssh;
|
||||
$sp2[5]=$pts[1]-$ssv;
|
||||
$sp2[6]=$pts[6]+$ssh;
|
||||
$sp2[7]=$pts[7]-$ssv;
|
||||
}
|
||||
|
||||
$base_color = $this->fill_color;
|
||||
|
||||
$img->PushColor($base_color . ':0.7');
|
||||
$img->FilledPolygon($sp1);
|
||||
$img->PopColor();
|
||||
|
||||
$img->PushColor($base_color . ':1.1');
|
||||
$img->FilledPolygon($sp2);
|
||||
$img->PopColor();
|
||||
}
|
||||
|
||||
|
||||
// Stroke the pattern
|
||||
if (is_array($this->iPattern)) {
|
||||
$f = new RectPatternFactory();
|
||||
|
|
@ -540,6 +648,7 @@ class BarPlot extends Plot
|
|||
$prect->Stroke($img);
|
||||
}
|
||||
}
|
||||
|
||||
// Stroke the outline of the bar
|
||||
if (is_array($this->color)) {
|
||||
$img->SetColor($this->color[$i % count($this->color)]);
|
||||
|
|
@ -554,9 +663,11 @@ class BarPlot extends Plot
|
|||
$img->SetLineWeight($this->weight);
|
||||
$img->Polygon($pts);
|
||||
}
|
||||
|
||||
|
||||
// Determine how to best position the values of the individual bars
|
||||
$x=$pts[2]+($pts[4]-$pts[2])/2;
|
||||
$this->value->SetMargin(5);
|
||||
|
||||
if ($this->valuepos=='top') {
|
||||
$y=$pts[3];
|
||||
if ($img->a === 90) {
|
||||
|
|
@ -565,6 +676,14 @@ class BarPlot extends Plot
|
|||
} else {
|
||||
$this->value->SetAlign('left', 'center');
|
||||
}
|
||||
} else {
|
||||
if ($val < 0) {
|
||||
$this->value->SetMargin(-5);
|
||||
$y=$pts[1];
|
||||
$this->value->SetAlign('center', 'bottom');
|
||||
} else {
|
||||
$this->value->SetAlign('center', 'bottom');
|
||||
}
|
||||
}
|
||||
$this->value->Stroke($img, $val, $x, $y);
|
||||
} elseif ($this->valuepos=='max') {
|
||||
|
|
@ -576,9 +695,13 @@ class BarPlot extends Plot
|
|||
$this->value->SetAlign('right', 'center');
|
||||
}
|
||||
} else {
|
||||
$this->value->SetAlign('center', 'top');
|
||||
if ($val < 0) {
|
||||
$this->value->SetAlign('center', 'bottom');
|
||||
} else {
|
||||
$this->value->SetAlign('center', 'top');
|
||||
}
|
||||
}
|
||||
$this->value->SetMargin(-3);
|
||||
$this->value->SetMargin(-5);
|
||||
$this->value->Stroke($img, $val, $x, $y);
|
||||
} elseif ($this->valuepos=='center') {
|
||||
$y = ($pts[3] + $pts[1])/2;
|
||||
|
|
@ -597,7 +720,8 @@ class BarPlot extends Plot
|
|||
$this->value->SetMargin(3);
|
||||
$this->value->Stroke($img, $val, $x, $y);
|
||||
} else {
|
||||
JpGraphError::Raise('Unknown position for values on bars :'.$this->valuepos);
|
||||
JpGraphError::RaiseL(2006, $this->valuepos);
|
||||
//'Unknown position for values on bars :'.$this->valuepos);
|
||||
}
|
||||
// Create the client side image map
|
||||
$rpts = $img->ArrRotate($pts);
|
||||
|
|
@ -631,21 +755,21 @@ class BarPlot extends Plot
|
|||
//===================================================
|
||||
class GroupBarPlot extends BarPlot
|
||||
{
|
||||
private $plots;
|
||||
public $plots;
|
||||
private $nbrplots=0;
|
||||
//---------------
|
||||
// CONSTRUCTOR
|
||||
public function GroupBarPlot($plots)
|
||||
public function __construct($plots)
|
||||
{
|
||||
$this->width=0.7;
|
||||
$this->plots = $plots;
|
||||
$this->nbrplots = count($plots);
|
||||
if ($this->nbrplots < 1) {
|
||||
JpGraphError::Raise('Cannot create GroupBarPlot from empty plot array.');
|
||||
JpGraphError::RaiseL(2007);//('Cannot create GroupBarPlot from empty plot array.');
|
||||
}
|
||||
for ($i=0; $i < $this->nbrplots; ++$i) {
|
||||
if (empty($this->plots[$i]) || !isset($this->plots[$i])) {
|
||||
JpGraphError::Raise("Group bar plot element nbr $i is undefined or empty.");
|
||||
JpGraphError::RaiseL(2008, $i);//("Group bar plot element nbr $i is undefined or empty.");
|
||||
}
|
||||
}
|
||||
$this->numpoints = $plots[0]->numpoints;
|
||||
|
|
@ -660,24 +784,25 @@ class GroupBarPlot extends BarPlot
|
|||
for ($i=0; $i < $n; ++$i) {
|
||||
$c = get_class($this->plots[$i]);
|
||||
if (!($this->plots[$i] instanceof BarPlot)) {
|
||||
JpGraphError::Raise('One of the objects submitted to GroupBar is not a BarPlot. Make sure that you create the Group Bar plot from an array of BarPlot or AccBarPlot objects. (Class = '.$c.')');
|
||||
JpGraphError::RaiseL(2009, $c);
|
||||
//('One of the objects submitted to GroupBar is not a BarPlot. Make sure that you create the Group Bar plot from an array of BarPlot or AccBarPlot objects. (Class = '.$c.')');
|
||||
}
|
||||
$this->plots[$i]->DoLegend($graph);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function Min()
|
||||
{
|
||||
list($xmin, $ymin) = $this->plots[0]->Min();
|
||||
$n = count($this->plots);
|
||||
for ($i=0; $i < $n; ++$i) {
|
||||
list($xm, $ym) = $this->plots[$i]->Min();
|
||||
$xmin = max($xmin, $xm);
|
||||
$xmin = min($xmin, $xm);
|
||||
$ymin = min($ymin, $ym);
|
||||
}
|
||||
return array($xmin,$ymin);
|
||||
}
|
||||
|
||||
|
||||
public function Max()
|
||||
{
|
||||
list($xmax, $ymax) = $this->plots[0]->Max();
|
||||
|
|
@ -689,7 +814,7 @@ class GroupBarPlot extends BarPlot
|
|||
}
|
||||
return array($xmax,$ymax);
|
||||
}
|
||||
|
||||
|
||||
public function GetCSIMareas()
|
||||
{
|
||||
$n = count($this->plots);
|
||||
|
|
@ -699,7 +824,7 @@ class GroupBarPlot extends BarPlot
|
|||
}
|
||||
return $csimareas;
|
||||
}
|
||||
|
||||
|
||||
// Stroke all the bars next to each other
|
||||
public function Stroke($img, $xscale, $yscale)
|
||||
{
|
||||
|
|
@ -710,7 +835,7 @@ class GroupBarPlot extends BarPlot
|
|||
for ($i=0; $i < $n; ++$i) {
|
||||
$this->plots[$i]->ymin=$this->ybase;
|
||||
$this->plots[$i]->SetWidth($subwidth);
|
||||
|
||||
|
||||
// If the client have used SetTextTickInterval() then
|
||||
// major_step will be > 1 and the positioning will fail.
|
||||
// If we assume it is always one the positioning will work
|
||||
|
|
@ -729,22 +854,35 @@ class GroupBarPlot extends BarPlot
|
|||
//===================================================
|
||||
class AccBarPlot extends BarPlot
|
||||
{
|
||||
private $plots=null;
|
||||
public $plots=null;
|
||||
private $nbrplots=0;
|
||||
//---------------
|
||||
// CONSTRUCTOR
|
||||
public function AccBarPlot($plots)
|
||||
public function __construct($plots)
|
||||
{
|
||||
$this->plots = $plots;
|
||||
$this->nbrplots = count($plots);
|
||||
if ($this->nbrplots < 1) {
|
||||
JpGraphError::Raise('Cannot create AccBarPlot from empty plot array.');
|
||||
JpGraphError::RaiseL(2010);//('Cannot create AccBarPlot from empty plot array.');
|
||||
}
|
||||
for ($i=0; $i < $this->nbrplots; ++$i) {
|
||||
if (empty($this->plots[$i]) || !isset($this->plots[$i])) {
|
||||
JpGraphError::Raise("Acc bar plot element nbr $i is undefined or empty.");
|
||||
JpGraphError::RaiseL(2011, $i);//("Acc bar plot element nbr $i is undefined or empty.");
|
||||
}
|
||||
}
|
||||
|
||||
// We can only allow individual plost which do not have specified X-positions
|
||||
for ($i=0; $i < $this->nbrplots; ++$i) {
|
||||
if (!empty($this->plots[$i]->coords[1])) {
|
||||
JpGraphError::RaiseL(2015);
|
||||
//'Individual bar plots in an AccBarPlot or GroupBarPlot can not have specified X-positions.');
|
||||
}
|
||||
}
|
||||
|
||||
// Use 0 weight by default which means that the individual bar
|
||||
// weights will be used per part n the accumulated bar
|
||||
$this->SetWeight(0);
|
||||
|
||||
$this->numpoints = $plots[0]->numpoints;
|
||||
$this->value = new DisplayValue();
|
||||
}
|
||||
|
|
@ -757,7 +895,8 @@ class AccBarPlot extends BarPlot
|
|||
for ($i=$n-1; $i >= 0; --$i) {
|
||||
$c = get_class($this->plots[$i]);
|
||||
if (!($this->plots[$i] instanceof BarPlot)) {
|
||||
JpGraphError::Raise('One of the objects submitted to AccBar is not a BarPlot. Make sure that you create the AccBar plot from an array of BarPlot objects.(Class='.$c.')');
|
||||
JpGraphError::RaiseL(2012, $c);
|
||||
//('One of the objects submitted to AccBar is not a BarPlot. Make sure that you create the AccBar plot from an array of BarPlot objects.(Class='.$c.')');
|
||||
}
|
||||
$this->plots[$i]->DoLegend($graph);
|
||||
}
|
||||
|
|
@ -846,6 +985,7 @@ class AccBarPlot extends BarPlot
|
|||
{
|
||||
$pattern=null;
|
||||
$img->SetLineWeight($this->weight);
|
||||
$grad=null;
|
||||
for ($i=0; $i < $this->numpoints-1; $i++) {
|
||||
$accy = 0;
|
||||
$accy_neg = 0;
|
||||
|
|
@ -862,7 +1002,7 @@ class AccBarPlot extends BarPlot
|
|||
$accyt=$yscale->Translate($accy_neg);
|
||||
$accy_neg+=$this->plots[$j]->coords[0][$i];
|
||||
}
|
||||
|
||||
|
||||
$xt=$xscale->Translate($i);
|
||||
|
||||
if ($this->abswidth > -1) {
|
||||
|
|
@ -870,13 +1010,13 @@ class AccBarPlot extends BarPlot
|
|||
} else {
|
||||
$abswidth=round($this->width*$xscale->scale_factor, 0);
|
||||
}
|
||||
|
||||
|
||||
$pts=array($xt,$accyt,$xt,$yt,$xt+$abswidth,$yt,$xt+$abswidth,$accyt);
|
||||
|
||||
if ($this->bar_shadow) {
|
||||
$ssh = $this->bar_shadow_hsize;
|
||||
$ssv = $this->bar_shadow_vsize;
|
||||
|
||||
|
||||
// We must also differ if we are a positive or negative bar.
|
||||
if ($j === 0) {
|
||||
// This gets extra complicated since we have to
|
||||
|
|
@ -909,7 +1049,7 @@ class AccBarPlot extends BarPlot
|
|||
if (is_array($this->bar_shadow_color)) {
|
||||
$numcolors = count($this->bar_shadow_color);
|
||||
if ($numcolors == 0) {
|
||||
JpGraphError::Raise('You have specified an empty array for shadow colors in the bar plot.');
|
||||
JpGraphError::RaiseL(2013);//('You have specified an empty array for shadow colors in the bar plot.');
|
||||
}
|
||||
$img->PushColor($this->bar_shadow_color[$i % $numcolors]);
|
||||
} else {
|
||||
|
|
@ -944,16 +1084,53 @@ class AccBarPlot extends BarPlot
|
|||
}
|
||||
|
||||
if ($this->plots[$j]->grad) {
|
||||
$grad = new Gradient($img);
|
||||
$grad->FilledRectangle(
|
||||
$pts[2],
|
||||
$pts[3],
|
||||
$pts[6],
|
||||
$pts[7],
|
||||
$this->plots[$j]->grad_fromcolor,
|
||||
$this->plots[$j]->grad_tocolor,
|
||||
$this->plots[$j]->grad_style
|
||||
);
|
||||
if ($grad === null) {
|
||||
$grad = new Gradient($img);
|
||||
}
|
||||
if (is_array($this->plots[$j]->grad_fromcolor)) {
|
||||
// The first argument (grad_fromcolor) can be either an array or a single color. If it is an array
|
||||
// then we have two choices. It can either a) be a single color specified as an RGB triple or it can be
|
||||
// an array to specify both (from, to style) for each individual bar. The way to know the difference is
|
||||
// to investgate the first element. If this element is an integer [0,255] then we assume it is an RGB
|
||||
// triple.
|
||||
$ng = count($this->plots[$j]->grad_fromcolor);
|
||||
if ($ng === 3) {
|
||||
if (is_numeric($this->plots[$j]->grad_fromcolor[0]) && $this->plots[$j]->grad_fromcolor[0] > 0 &&
|
||||
$this->plots[$j]->grad_fromcolor[0] < 256) {
|
||||
// RGB Triple
|
||||
$fromcolor = $this->plots[$j]->grad_fromcolor;
|
||||
$tocolor = $this->plots[$j]->grad_tocolor;
|
||||
$style = $this->plots[$j]->grad_style;
|
||||
} else {
|
||||
$fromcolor = $this->plots[$j]->grad_fromcolor[$i % $ng][0];
|
||||
$tocolor = $this->plots[$j]->grad_fromcolor[$i % $ng][1];
|
||||
$style = $this->plots[$j]->grad_fromcolor[$i % $ng][2];
|
||||
}
|
||||
} else {
|
||||
$fromcolor = $this->plots[$j]->grad_fromcolor[$i % $ng][0];
|
||||
$tocolor = $this->plots[$j]->grad_fromcolor[$i % $ng][1];
|
||||
$style = $this->plots[$j]->grad_fromcolor[$i % $ng][2];
|
||||
}
|
||||
$grad->FilledRectangle(
|
||||
$pts[2],
|
||||
$pts[3],
|
||||
$pts[6],
|
||||
$pts[7],
|
||||
$fromcolor,
|
||||
$tocolor,
|
||||
$style
|
||||
);
|
||||
} else {
|
||||
$grad->FilledRectangle(
|
||||
$pts[2],
|
||||
$pts[3],
|
||||
$pts[6],
|
||||
$pts[7],
|
||||
$this->plots[$j]->grad_fromcolor,
|
||||
$this->plots[$j]->grad_tocolor,
|
||||
$this->plots[$j]->grad_style
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (is_array($this->plots[$j]->fill_color)) {
|
||||
$numcolors = count($this->plots[$j]->fill_color);
|
||||
|
|
@ -971,15 +1148,16 @@ class AccBarPlot extends BarPlot
|
|||
if ($fillcolor !== false) {
|
||||
$img->FilledPolygon($pts);
|
||||
}
|
||||
$img->SetColor($this->plots[$j]->color);
|
||||
}
|
||||
|
||||
$img->SetColor($this->plots[$j]->color);
|
||||
|
||||
// Stroke the pattern
|
||||
if ($this->plots[$j]->iPattern > -1) {
|
||||
if ($pattern===null) {
|
||||
$pattern = new RectPatternFactory();
|
||||
}
|
||||
|
||||
|
||||
$prect = $pattern->Create($this->plots[$j]->iPattern, $this->plots[$j]->iPatternColor, 1);
|
||||
$prect->SetDensity($this->plots[$j]->iPatternDensity);
|
||||
if ($this->plots[$j]->coords[0][$i] < 0) {
|
||||
|
|
@ -1024,13 +1202,21 @@ class AccBarPlot extends BarPlot
|
|||
|
||||
$pts[] = $pts[0];
|
||||
$pts[] = $pts[1];
|
||||
$img->SetLineWeight($this->plots[$j]->line_weight);
|
||||
$img->SetLineWeight($this->plots[$j]->weight);
|
||||
$img->Polygon($pts);
|
||||
$img->SetLineWeight(1);
|
||||
}
|
||||
|
||||
|
||||
// Daw potential bar around the entire accbar bar
|
||||
if ($this->weight > 0) {
|
||||
$y=$yscale->Translate(0);
|
||||
$img->SetColor($this->color);
|
||||
$img->SetLineWeight($this->weight);
|
||||
$img->Rectangle($pts[0], $y, $pts[6], $pts[5]);
|
||||
}
|
||||
|
||||
// Draw labels for each acc.bar
|
||||
|
||||
|
||||
$x=$pts[2]+($pts[4]-$pts[2])/2;
|
||||
if ($this->bar_shadow) {
|
||||
$x += $ssh;
|
||||
|
|
@ -1038,23 +1224,22 @@ class AccBarPlot extends BarPlot
|
|||
|
||||
// First stroke the accumulated value for the entire bar
|
||||
// This value is always placed at the top/bottom of the bars
|
||||
if ($accy_neg < 0) {
|
||||
if ($accy + $accy_neg < 0) {
|
||||
$y=$yscale->Translate($accy_neg);
|
||||
$this->value->Stroke($img, $accy_neg, $x, $y);
|
||||
} else {
|
||||
$y=$yscale->Translate($accy);
|
||||
$this->value->Stroke($img, $accy, $x, $y);
|
||||
}
|
||||
$this->value->Stroke($img, $accy + $accy_neg, $x, $y);
|
||||
|
||||
$accy = 0;
|
||||
$accy_neg = 0;
|
||||
for ($j=0; $j < $this->nbrplots; ++$j) {
|
||||
|
||||
// We don't print 0 values in an accumulated bar plot
|
||||
// We don't print 0 values in an accumulated bar plot
|
||||
if ($this->plots[$j]->coords[0][$i] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if ($this->plots[$j]->coords[0][$i] > 0) {
|
||||
$yt=$yscale->Translate($this->plots[$j]->coords[0][$i]+$accy);
|
||||
$accyt=$yscale->Translate($accy);
|
||||
|
|
@ -1098,7 +1283,7 @@ class AccBarPlot extends BarPlot
|
|||
$this->plots[$j]->value->SetMargin(-1);
|
||||
}
|
||||
}
|
||||
$this->plots[$j]->value->Stroke($img, $this->plots[$j]->coords[0][$i], $x, $y);
|
||||
$this->plots[$j]->value->Stroke($img, $this->plots[$j]->coords[0][$i], round($x), round($y));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue