Version 3.2.3
This commit is contained in:
1 parent
ae5c01cc78
commit
78706903a2
2641 files changed
+228363
-201264
No files matched your search
@@ -3,14 +3,14 @@
|
||||
/**
|
||||
* Graph class.
|
||||
* This code was written by Remco Wilting (Wizzy) and used with permission in IP.Board.
|
||||
* Last Updated : $Date: 2010-10-06 15:59:29 -0400 (Wed, 06 Oct 2010) $
|
||||
* Last Updated : $Date: 2011-09-15 17:04:35 -0400 (Thu, 15 Sep 2011) $
|
||||
* Last Updated by: $Author: bfarber $
|
||||
*
|
||||
* @author Remco Wilting
|
||||
* @copyright (c) 2008 Remco Wilting
|
||||
* @package IP.Board
|
||||
* @since Sunday 6th July 2008 16:35
|
||||
* @version $Revision: 474 $
|
||||
* @version $Revision: 9495 $
|
||||
*/
|
||||
|
||||
//+---------------------------------------------------------------------------
|
||||
@@ -51,9 +51,11 @@ class classGraph
|
||||
'yaxistitle' => '', // Title for the y-axis (no title if empty)
|
||||
'showdatalabels' => 1, // Display the datalabels (yes/no)
|
||||
'showlegend' => 1, // Display the legend (yes/no)
|
||||
'maxlegendwidth' => 20, // Percentage indicating the maximum width for the legend
|
||||
'showgridlinesx' => 1, // Show gridlines for the x-axis (yes/no)
|
||||
'showgridlinesy' => 1, // Show gridlines for the y-axis (yes/no)
|
||||
'numticks' => 5 // Number of ticks used for numeric axes
|
||||
'numticks' => 5, // Number of ticks used for numeric axes,
|
||||
'xaxisskip' => 0, // Number of x-axis bars to skip before drawing next one (only implemented for line graphs so far)
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -200,7 +202,7 @@ class classGraph
|
||||
*
|
||||
* @access public
|
||||
* @param boolean [Optional] Enable Debug Mode
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
public function __construct( $debug = 0 )
|
||||
{
|
||||
@@ -223,7 +225,7 @@ class classGraph
|
||||
*
|
||||
* @access public
|
||||
* @param array Array of data labels
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
public function addLabels( $data = array() )
|
||||
{
|
||||
@@ -236,7 +238,7 @@ class classGraph
|
||||
define( 'IPS_DOC_CHAR_SET', '' );
|
||||
}
|
||||
|
||||
$_cleanData[ $k ] = html_entity_decode( $v, ENT_QUOTES, IPS_DOC_CHAR_SET );
|
||||
$_cleanData[ $k ] = @html_entity_decode( $v, ENT_QUOTES, IPS_DOC_CHAR_SET );
|
||||
}
|
||||
|
||||
$this->data['xaxis'] = $_cleanData;
|
||||
@@ -249,7 +251,7 @@ class classGraph
|
||||
* @access public
|
||||
* @param string Name of the data series
|
||||
* @param array Array of data values
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
public function addSeries( $name = '', $data = array(), $color = '' )
|
||||
{
|
||||
@@ -271,7 +273,7 @@ class classGraph
|
||||
//-----------------------------------------
|
||||
// Check font
|
||||
//-----------------------------------------
|
||||
if ( $this->options['font'] and is_readable( $this->options['font'] ) )
|
||||
if ( $this->options['font'] and is_readable( $this->options['font'] ) and function_exists('imagettfbbox') )
|
||||
{
|
||||
$this->use_ttf = 1;
|
||||
}
|
||||
@@ -417,7 +419,7 @@ class classGraph
|
||||
* Draw the graph title
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawTitle()
|
||||
{
|
||||
@@ -462,7 +464,7 @@ class classGraph
|
||||
* Draw the legend
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawLegend()
|
||||
{
|
||||
@@ -475,25 +477,42 @@ class classGraph
|
||||
$legendx = 0;
|
||||
$legendy = 0;
|
||||
$maxtxty = 10;
|
||||
|
||||
$maxlegendwidth = ( $this->grapharea['x1'] / 100 ) * $this->options['maxlegendwidth'];
|
||||
|
||||
$lines = array();
|
||||
|
||||
foreach ( $this->legend as $name )
|
||||
foreach ( $this->legend as $k => $name )
|
||||
{
|
||||
if ( $this->use_ttf )
|
||||
{
|
||||
$txtsize = imagettfbbox('10', 0, $this->options['font'], $name );
|
||||
$legendx = ($txtsize[2]-$txtsize[0]) > $legendx ? $txtsize[2]-$txtsize[0] : $legendx;
|
||||
$txtsize = array();
|
||||
$lines[ $k ] = explode( "\n", wordwrap( $name, ceil( ( $maxlegendwidth - 10 ) / imagefontwidth($this->fontsize) ) ) );
|
||||
foreach ( $lines[ $k ] as $line )
|
||||
{
|
||||
$_txtsize = imagettfbbox('10', 0, $this->options['font'], $line );
|
||||
if ( $_txtsize[2]-$_txtsize[0] > $txtsize[2]-$txtsize[0] )
|
||||
{
|
||||
$txtsize = $_txtsize;
|
||||
}
|
||||
}
|
||||
|
||||
$legendx = ($txtsize[2]-$txtsize[0]) > $legendx ? $txtsize[2]-$txtsize[0] : $legendx;
|
||||
$maxtxty = ($txtsize[1]-$txtsize[7]) > $maxtxty ? ($txtsize[1]-$txtsize[7]) : $maxtxty;
|
||||
}
|
||||
else
|
||||
{
|
||||
$txtsize = strlen( $name ) * imagefontwidth($this->fontsize);
|
||||
$txtsize = ( $txtsize > $maxlegendwidth ) ? $maxlegendwidth : $txtsize;
|
||||
$legendx = ($txtsize > $legendx) ? $txtsize : $legendx;
|
||||
$maxtxty = imagefontheight($this->fontsize);
|
||||
$lines[ $k ] = explode( "\n", wordwrap( $name, ceil( ( $maxlegendwidth - 10 ) / imagefontwidth($this->fontsize) ) ) );
|
||||
}
|
||||
|
||||
$ci ++;
|
||||
|
||||
}
|
||||
|
||||
$legendx = $this->grapharea['x1'] - ($legendx + 25);
|
||||
$legendy = round( ($this->options['height'] / 2) - ((($maxtxty+5) * $ci) / 2) );
|
||||
|
||||
@@ -511,7 +530,7 @@ class classGraph
|
||||
// Draw legends
|
||||
//-----------------------------------------
|
||||
|
||||
foreach ( $this->legend as $name )
|
||||
foreach ( $this->legend as $k => $name )
|
||||
{
|
||||
//-----------------------------------------
|
||||
// Get Pie slice colors
|
||||
@@ -529,22 +548,25 @@ class classGraph
|
||||
|
||||
$color = imagecolorallocate( $this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2] );
|
||||
imagefilledrectangle( $this->image, $legendx+5, $ypos+7 , $legendx+15 , $ypos+17, $color );
|
||||
|
||||
if ( $this->use_ttf )
|
||||
{
|
||||
$txty = $ypos + 5 + $maxtxty/2;
|
||||
imagettftext($this->image, "10", 0, $legendx+20+1, $txty+5+1, $shadowcolor, $this->options['font'], $name );
|
||||
imagettftext($this->image, "10", 0, $legendx+20 , $txty+5 , $textcolor , $this->options['font'], $name );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageString( $this->image, $this->fontsize, $legendx+20 , $ypos+7, $name, $this->black);
|
||||
}
|
||||
|
||||
$ypos = $ypos + $maxtxty + 5;
|
||||
|
||||
imagecolordeallocate( $this->image, $color );
|
||||
$ci ++;
|
||||
|
||||
foreach ( $lines[ $k ] as $line )
|
||||
{
|
||||
if ( $this->use_ttf )
|
||||
{
|
||||
$txty = $ypos + 5 + $maxtxty/2;
|
||||
imagettftext($this->image, "10", 0, $legendx+20+1, $txty+5+1, $shadowcolor, $this->options['font'], $line );
|
||||
imagettftext($this->image, "10", 0, $legendx+20 , $txty+5 , $textcolor , $this->options['font'], $line );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageString( $this->image, $this->fontsize, $legendx+20 , $ypos+7, $line, $this->black);
|
||||
}
|
||||
|
||||
$ypos = $ypos + $maxtxty + 5;
|
||||
|
||||
imagecolordeallocate( $this->image, $color );
|
||||
}
|
||||
$ci ++;
|
||||
}
|
||||
|
||||
imagerectangle( $this->image, $legendx, $legendy, $this->grapharea['x1']-1, $ypos + 5, $textcolor );
|
||||
@@ -560,7 +582,7 @@ class classGraph
|
||||
* Draw X and Y axes
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawAxes()
|
||||
{
|
||||
@@ -857,6 +879,7 @@ class classGraph
|
||||
$stepwidth = floor( ( ( $this->grapharea['x1'] - $this->grapharea['x0'] ) / $numlabels ) );
|
||||
$this->grapharea['x1'] = $this->grapharea['x0'] + $numlabels * $stepwidth;
|
||||
|
||||
|
||||
for ( $i = 0; $i < $numlabels; $i++ )
|
||||
{
|
||||
$label = $this->x_axis['labels'][$i];
|
||||
@@ -872,6 +895,14 @@ class classGraph
|
||||
{
|
||||
imageline( $this->image, $x+$depth, $this->grapharea['y1']-$depth, $x+$depth, $this->grapharea['y0']-$depth, $this->black );
|
||||
}
|
||||
|
||||
if( $this->options['xaxisskip'] )
|
||||
{
|
||||
if( $i % $this->options['xaxisskip'] != 1 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Labels
|
||||
if ( $this->use_ttf )
|
||||
@@ -919,8 +950,11 @@ class classGraph
|
||||
}
|
||||
|
||||
$numticks = $this->options['numticks'] > $this->y_axis['max'] ? floor($this->y_axis['max']) : $this->options['numticks'];
|
||||
$numticks = $numticks ? $numticks : 1;
|
||||
$step = floor( $this->y_axis['max'] / $numticks );
|
||||
$step = $step ? $step : 1;
|
||||
$steps = ceil( $this->y_axis['max'] / $step );
|
||||
$steps = $steps ? $steps : 1;
|
||||
$stepheight = ( $this->grapharea['y1'] - $this->grapharea['y0'] ) / $steps;
|
||||
for ( $i = 1; $i <= $steps; $i++ )
|
||||
{
|
||||
@@ -1024,7 +1058,7 @@ class classGraph
|
||||
* Generate Pie Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawPie()
|
||||
{
|
||||
@@ -1176,7 +1210,7 @@ class classGraph
|
||||
* Generate Doughnut Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawDoughnut()
|
||||
{
|
||||
@@ -1457,7 +1491,7 @@ class classGraph
|
||||
* Generate Bar Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawBars()
|
||||
{
|
||||
@@ -1599,7 +1633,7 @@ class classGraph
|
||||
* Generate Horizontal Bar Charts
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawHorizontalBars()
|
||||
{
|
||||
@@ -1743,7 +1777,7 @@ class classGraph
|
||||
* Generate Line Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawLines()
|
||||
{
|
||||
@@ -1779,8 +1813,11 @@ class classGraph
|
||||
$stepwidth = floor( ( ( $this->grapharea['x1'] - $this->grapharea['x0'] ) / $numbars ) );
|
||||
|
||||
$numticks = $this->options['numticks'] > $maxvalue ? floor($maxvalue) : $this->options['numticks'];
|
||||
$numticks = $numticks ? $numticks : 1;
|
||||
$step = floor( $maxvalue / $numticks );
|
||||
$step = $step ? $step : 1;
|
||||
$steps = ceil( $maxvalue / $step );
|
||||
$steps = $steps ? $steps : 1;
|
||||
$stepheight = ( $this->grapharea['y1'] - $this->grapharea['y0'] ) / $steps;
|
||||
|
||||
$effect3DSize = 20;
|
||||
@@ -1875,17 +1912,18 @@ class classGraph
|
||||
}
|
||||
}
|
||||
|
||||
$valuecolor = ImageColorAllocate($this->image, hexdec(substr($this->options['textcolor'],1,2)), hexdec(substr($this->options['textcolor'],3,2)), hexdec(substr($this->options['textcolor'],5,2)));
|
||||
$valuecolor = imagecolorallocate($this->image, hexdec(substr($this->options['textcolor'],1,2)), hexdec(substr($this->options['textcolor'],3,2)), hexdec(substr($this->options['textcolor'],5,2)));
|
||||
$valshadecolor = imagecolorallocate( $this->image, ($this->color[$ci][0]-50)<0?0:$this->color[$ci][0]-50, ($this->color[$ci][1]-50)<0?0:$this->color[$ci][1]-50, ($this->color[$ci][2]-50)<0?0:$this->color[$ci][2]-50 );
|
||||
|
||||
if ( $this->use_ttf )
|
||||
{
|
||||
$txtsize = imagettfbbox('10', 0, $this->options['font'], $value2 );
|
||||
$textx = $x2 - round(($txtsize[2]-$txtsize[0])/2,0);
|
||||
$textx = $x2 - ( round(($txtsize[2]-$txtsize[0])/2,0) * ( strlen($value2)/1.2 ) );
|
||||
$texty = $y2 - 3;
|
||||
|
||||
imagettftext($this->image, "10", 0, $textx-1, $texty-1, $valshadecolor, $this->options['font'], $value2);
|
||||
imagettftext($this->image, "10", 0, $textx+1, $texty+1, $valshadecolor, $this->options['font'], $value2);
|
||||
imagettftext($this->image, "10", 0, $textx+2, $texty+2, $valshadecolor, $this->options['font'], $value2);
|
||||
//imagettftext($this->image, "10", 0, $textx+1, $texty+1, $valshadecolor, $this->options['font'], $value2);
|
||||
//imagettftext($this->image, "10", 0, $textx+2, $texty+2, $valshadecolor, $this->options['font'], $value2);
|
||||
imagettftext($this->image, "10", 0, $textx, $texty, $valuecolor, $this->options['font'], $value2);
|
||||
}
|
||||
else
|
||||
@@ -1912,7 +1950,7 @@ class classGraph
|
||||
* Generate Area Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawArea()
|
||||
{
|
||||
@@ -2123,7 +2161,7 @@ class classGraph
|
||||
* Generate Scatter Plot (XY Chart)
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawXY()
|
||||
{
|
||||
@@ -2238,7 +2276,7 @@ class classGraph
|
||||
* Generate Bubble Plot
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawBubble()
|
||||
{
|
||||
@@ -2358,7 +2396,7 @@ class classGraph
|
||||
* Generate Funnel Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawFunnel()
|
||||
{
|
||||
@@ -2519,7 +2557,7 @@ class classGraph
|
||||
* Generate Radar Chart
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _drawRadar()
|
||||
{
|
||||
@@ -2872,7 +2910,7 @@ class classGraph
|
||||
*
|
||||
* @access protected
|
||||
* @param int Minimum number of series
|
||||
* @param boolean Require labels
|
||||
* @param boolean Check labels exist
|
||||
* @return boolean True if all checks pass; false otherwise
|
||||
*/
|
||||
protected function _checkSeries( $minseries=0, $labelsRequired=0 )
|
||||
@@ -2923,8 +2961,7 @@ class classGraph
|
||||
* Check if a color string is valid
|
||||
*
|
||||
* @access protected
|
||||
* @param int Minimum number of series
|
||||
* @param boolean Require labels
|
||||
* @param string Color HEX
|
||||
* @return boolean True if all checks pass; false otherwise
|
||||
*/
|
||||
protected function _checkColor( $color='' )
|
||||
@@ -2949,7 +2986,7 @@ class classGraph
|
||||
*
|
||||
* @access protected
|
||||
* @param string Error message
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _error( $msg='' )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user