/protected/components/pChart.php
PHP | 3492 lines | 2668 code | 550 blank | 274 comment | 776 complexity | c090f992083e1e32224cd570100b6bd9 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- pChart - a PHP class to build charts!
- Copyright (C) 2008 Jean-Damien POGOLOTTI
- Version 1.27d last updated on 09/30/08
-
- http://pchart.sourceforge.net
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 1,2,3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- Class initialisation :
- pChart($XSize,$YSize)
- Draw methods :
- drawBackground($R,$G,$B)
- drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)
- drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100)
- drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
- drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
- drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
- drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
- drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
- drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
- drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)
- drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B)
- drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
- drawFromPNG($FileName,$X,$Y,$Alpha=100)
- drawFromGIF($FileName,$X,$Y,$Alpha=100)
- drawFromJPG($FileName,$X,$Y,$Alpha=100)
- Graph setup methods :
- addBorder($Width=3,$R=0,$G=0,$B=0)
- clearScale()
- clearShadow()
- createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades)
- drawGraphArea($R,$G,$B,$Stripe=FALSE)
- drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
- drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1)
- drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1)
- drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100)
- drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=FALSE)
- drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)
- drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
- drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL)
- drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50)
- drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-1)
- drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)
- drawTextBox($X1,$Y1,$X2,$Y2,$Text,$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-1,$BgB=-1,$Alpha=100)
- getLegendBoxSize($DataDescription)
- loadColorPalette($FileName,$Delimiter=",")
- reportWarnings($Interface="CLI")
- setGraphArea($X1,$Y1,$X2,$Y2)
- setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210)
- setColorPalette($ID,$R,$G,$B)
- setCurrency($Currency)
- setDateFormat($Format)
- setFontProperties($FontName,$FontSize)
- setLineStyle($Width=1,$DotSize=0)
- setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMin=0,$XDivisions=5)
- setShadowProperties($XDistance=1,$YDistance=1,$R=60,$G=60,$B=60,$Alpha)
- writeValues($Data,$DataDescription,$Series)
- Graphs methods :
- drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE)
- drawXYPlotGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1)
- drawLineGraph($Data,$DataDescription,$SerieName="")
- drawXYGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0)
- drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE)
- drawCubicCurve($Data,$DataDescription,$Accuracy=.1,$SerieName="")
- drawFilledCubicCurve($Data,$DataDescription,$Accuracy=.1,$Alpha=100,$AroundZero=FALSE)
- drawOverlayBarGraph($Data,$DataDescription,$Alpha=50)
- drawBarGraph($Data,$DataDescription,$Shadow=FALSE)
- drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
- drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
- drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)
- drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)
- drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)
- drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0)
- drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0)
- drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
- Other methods :
- setImageMap($Mode=TRUE,$GraphID="MyGraph")
- getImageMap($MapName,$Flush=TRUE)
- Render($FileName)
- Stroke()
- */
-
- /* Declare some script wide constants */
- define("SCALE_NORMAL",1);
- define("SCALE_ADDALL",2);
- define("SCALE_START0",3);
- define("SCALE_ADDALLSTART0",4);
- define("PIE_PERCENTAGE", 1);
- define("PIE_LABELS",2);
- define("PIE_NOLABEL",3);
- define("PIE_PERCENTAGE_LABEL", 4);
- define("TARGET_GRAPHAREA",1);
- define("TARGET_BACKGROUND",2);
- define("ALIGN_TOP_LEFT",1);
- define("ALIGN_TOP_CENTER",2);
- define("ALIGN_TOP_RIGHT",3);
- define("ALIGN_LEFT",4);
- define("ALIGN_CENTER",5);
- define("ALIGN_RIGHT",6);
- define("ALIGN_BOTTOM_LEFT",7);
- define("ALIGN_BOTTOM_CENTER",8);
- define("ALIGN_BOTTOM_RIGHT",9);
-
- /* pChart class definition */
- class pChart
- {
- /* Palettes definition */
- var $Palette = array("0"=>array("R"=>138,"G"=>167,"B"=>24),
- "1"=>array("R"=>224,"G"=>100,"B"=>46),
- "2"=>array("R"=>224,"G"=>214,"B"=>46),
- "3"=>array("R"=>46,"G"=>151,"B"=>224),
- "4"=>array("R"=>176,"G"=>46,"B"=>224),
- "5"=>array("R"=>224,"G"=>46,"B"=>117),
- "6"=>array("R"=>92,"G"=>224,"B"=>46),
- "7"=>array("R"=>224,"G"=>176,"B"=>46));
-
- /* Some static vars used in the class */
- var $XSize = NULL;
- var $YSize = NULL;
- var $Picture = NULL;
- var $ImageMap = NULL;
-
- /* Error management */
- var $ErrorReporting = FALSE;
- var $ErrorInterface = "CLI";
- var $Errors = NULL;
- var $ErrorFontName = "Fonts/pf_arma_five.ttf";
- var $ErrorFontSize = 6;
-
- /* vars related to the graphing area */
- var $GArea_X1 = NULL;
- var $GArea_Y1 = NULL;
- var $GArea_X2 = NULL;
- var $GArea_Y2 = NULL;
- var $GAreaXOffset = NULL;
- var $VMax = NULL;
- var $VMin = NULL;
- var $VXMax = NULL;
- var $VXMin = NULL;
- var $Divisions = NULL;
- var $XDivisions = NULL;
- var $DivisionHeight = NULL;
- var $XDivisionHeight = NULL;
- var $DivisionCount = NULL;
- var $XDivisionCount = NULL;
- var $DivisionRatio = NULL;
- var $XDivisionRatio = NULL;
- var $DivisionWidth = NULL;
- var $DataCount = NULL;
- var $Currency = "\$";
- var $FontDIR = '';
-
- /* Text format related vars */
- var $FontName = NULL;
- var $FontSize = NULL;
- var $DateFormat = "d/m/Y";
-
- /* Lines format related vars */
- var $LineWidth = 1;
- var $LineDotSize = 0;
-
- /* Layer related vars */
- var $Layers = NULL;
-
- /* Set antialias quality : 0 is maximum, 100 minimum*/
- var $AntialiasQuality = 0;
-
- /* Shadow settings */
- var $ShadowActive = FALSE;
- var $ShadowXDistance = 1;
- var $ShadowYDistance = 1;
- var $ShadowRColor = 60;
- var $ShadowGColor = 60;
- var $ShadowBColor = 60;
- var $ShadowAlpha = 50;
- var $ShadowBlur = 0;
-
- /* Image Map settings */
- var $BuildMap = FALSE;
- var $MapFunction = NULL;
- var $tmpFolder = "tmp/";
- var $MapID = NULL;
-
- /* This function create the background picture */
- function pChart($XSize,$YSize)
- {
- $this->XSize = $XSize;
- $this->YSize = $YSize;
- $this->Picture = imagecreatetruecolor($XSize,$YSize);
- $this->FontDIR = dirname($_SERVER['SCRIPT_FILENAME']).'/';
- // echo $this->FontDIR; exit;
- $C_White =$this->AllocateColor($this->Picture,255,255,255);
- imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
- imagecolortransparent($this->Picture,$C_White);
-
- $this->setFontProperties("tahoma.ttf",8);
- }
-
- /* Set if warnings should be reported */
- function reportWarnings($Interface="CLI")
- {
- $this->ErrorReporting = TRUE;
- $this->ErrorInterface = $Interface;
- }
-
- /* Set the font properties */
- function setFontProperties($FontName,$FontSize)
- {
- $this->FontName = $FontName;
- $this->FontSize = $FontSize;
- }
-
- /* Set the shadow properties */
- function setShadowProperties($XDistance=1,$YDistance=1,$R=60,$G=60,$B=60,$Alpha=50,$Blur=0)
- {
- $this->ShadowActive = TRUE;
- $this->ShadowXDistance = $XDistance;
- $this->ShadowYDistance = $YDistance;
- $this->ShadowRColor = $R;
- $this->ShadowGColor = $G;
- $this->ShadowBColor = $B;
- $this->ShadowAlpha = $Alpha;
- $this->ShadowBlur = $Blur;
- }
-
- /* Remove shadow option */
- function clearShadow()
- {
- $this->ShadowActive = FALSE;
- }
-
- /* Set Palette color */
- function setColorPalette($ID,$R,$G,$B)
- {
- if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
- if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
- if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
-
- $this->Palette[$ID]["R"] = $R;
- $this->Palette[$ID]["G"] = $G;
- $this->Palette[$ID]["B"] = $B;
- }
-
- /* Create a color palette shading from one color to another */
- function createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades)
- {
- $RFactor = ($R2-$R1)/$Shades;
- $GFactor = ($G2-$G1)/$Shades;
- $BFactor = ($B2-$B1)/$Shades;
-
- for($i=0;$i<=$Shades-1;$i++)
- {
- $this->Palette[$i]["R"] = $R1+$RFactor*$i;
- $this->Palette[$i]["G"] = $G1+$GFactor*$i;
- $this->Palette[$i]["B"] = $B1+$BFactor*$i;
- }
- }
-
- /* Load Color Palette from file */
- function loadColorPalette($FileName,$Delimiter=",")
- {
- $handle = @fopen($FileName,"r");
- $ColorID = 0;
- if ($handle)
- {
- while (!feof($handle))
- {
- $buffer = fgets($handle, 4096);
- $buffer = str_replace(chr(10),"",$buffer);
- $buffer = str_replace(chr(13),"",$buffer);
- $Values = split($Delimiter,$buffer);
- if ( count($Values) == 3 )
- {
- $this->Palette[$ColorID]["R"] = $Values[0];
- $this->Palette[$ColorID]["G"] = $Values[1];
- $this->Palette[$ColorID]["B"] = $Values[2];
- $ColorID++;
- }
- }
- }
- }
-
- /* Set line style */
- function setLineStyle($Width=1,$DotSize=0)
- {
- $this->LineWidth = $Width;
- $this->LineDotSize = $DotSize;
- }
-
- /* Set currency symbol */
- function setCurrency($Currency)
- {
- $this->Currency = $Currency;
- }
-
- /* Set the graph area location */
- function setGraphArea($X1,$Y1,$X2,$Y2)
- {
- $this->GArea_X1 = $X1;
- $this->GArea_Y1 = $Y1;
- $this->GArea_X2 = $X2;
- $this->GArea_Y2 = $Y2;
- }
-
- /* Prepare the graph area */
- function drawGraphArea($R,$G,$B,$Stripe=FALSE)
- {
- $this->drawFilledRectangle($this->GArea_X1,$this->GArea_Y1,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B,FALSE);
- $this->drawRectangle($this->GArea_X1,$this->GArea_Y1,$this->GArea_X2,$this->GArea_Y2,$R-40,$G-40,$B-40);
-
- if ( $Stripe )
- {
- $R2 = $R-15; if ( $R2 < 0 ) { $R2 = 0; }
- $G2 = $R-15; if ( $G2 < 0 ) { $G2 = 0; }
- $B2 = $R-15; if ( $B2 < 0 ) { $B2 = 0; }
-
- $LineColor =$this->AllocateColor($this->Picture,$R2,$G2,$B2);
- $SkewWidth = $this->GArea_Y2-$this->GArea_Y1-1;
-
- for($i=$this->GArea_X1-$SkewWidth;$i<=$this->GArea_X2;$i=$i+4)
- {
- $X1 = $i; $Y1 = $this->GArea_Y2;
- $X2 = $i+$SkewWidth; $Y2 = $this->GArea_Y1;
-
-
- if ( $X1 < $this->GArea_X1 )
- { $X1 = $this->GArea_X1; $Y1 = $this->GArea_Y1 + $X2 - $this->GArea_X1 + 1; }
-
- if ( $X2 >= $this->GArea_X2 )
- { $Y2 = $this->GArea_Y1 + $X2 - $this->GArea_X2 +1; $X2 = $this->GArea_X2 - 1; }
- // * Fixed in 1.27 * { $X2 = $this->GArea_X2 - 1; $Y2 = $this->GArea_Y2 - ($this->GArea_X2 - $X1); }
-
- imageline($this->Picture,$X1,$Y1,$X2,$Y2+1,$LineColor);
- }
- }
- }
-
- /* Allow you to clear the scale : used if drawing multiple charts */
- function clearScale()
- {
- $this->VMin = NULL;
- $this->VMax = NULL;
- $this->VXMin = NULL;
- $this->VXMax = NULL;
- $this->Divisions = NULL;
- $this->XDivisions = NULL; }
-
- /* Allow you to fix the scale, use this to bypass the automatic scaling */
- function setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMax=0,$XDivisions=5)
- {
- $this->VMin = $VMin;
- $this->VMax = $VMax;
- $this->Divisions = $Divisions;
-
- if ( !$VXMin == 0 )
- {
- $this->VXMin = $VXMin;
- $this->VXMax = $VXMax;
- $this->XDivisions = $XDivisions;
- }
- }
-
- /* Wrapper to the drawScale() function allowing a second scale to be drawn */
- function drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1)
- {
- $this->drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks,$Angle,$Decimals,$WithMargin,$SkipLabels,TRUE);
- }
-
- /* Compute and draw the scale */
- function drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
- {
- /* Validate the Data and DataDescription array */
- $this->validateData("drawScale",$Data);
-
- $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
-
- $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B);
- $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B);
-
- if ( $this->VMin == NULL && $this->VMax == NULL)
- {
- if (isset($DataDescription["Values"][0]))
- {
- $this->VMin = $Data[0][$DataDescription["Values"][0]];
- $this->VMax = $Data[0][$DataDescription["Values"][0]];
- }
- else { $this->VMin = 2147483647; $this->VMax = -2147483647; }
-
- /* Compute Min and Max values */
- if ( $ScaleMode == SCALE_NORMAL || $ScaleMode == SCALE_START0 )
- {
- if ( $ScaleMode == SCALE_START0 ) { $this->VMin = 0; }
-
- foreach ( $Data as $Key => $Values )
- {
- foreach ( $DataDescription["Values"] as $Key2 => $ColName )
- {
- if (isset($Data[$Key][$ColName]))
- {
- $Value = $Data[$Key][$ColName];
-
- if ( is_numeric($Value) )
- {
- if ( $this->VMax < $Value) { $this->VMax = $Value; }
- if ( $this->VMin > $Value) { $this->VMin = $Value; }
- }
- }
- }
- }
- }
- elseif ( $ScaleMode == SCALE_ADDALL || $ScaleMode == SCALE_ADDALLSTART0 ) /* Experimental */
- {
- if ( $ScaleMode == SCALE_ADDALLSTART0 ) { $this->VMin = 0; }
-
- foreach ( $Data as $Key => $Values )
- {
- $Sum = 0;
- foreach ( $DataDescription["Values"] as $Key2 => $ColName )
- {
- if (isset($Data[$Key][$ColName]))
- {
- $Value = $Data[$Key][$ColName];
- if ( is_numeric($Value) )
- $Sum += $Value;
- }
- }
- if ( $this->VMax < $Sum) { $this->VMax = $Sum; }
- if ( $this->VMin > $Sum) { $this->VMin = $Sum; }
- }
- }
-
- if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) )
- $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1;
-
- /* If all values are the same */
- if ( $this->VMax == $this->VMin )
- {
- if ( $this->VMax >= 0 ) { $this->VMax++; }
- else { $this->VMin--; }
- }
-
- $DataRange = $this->VMax - $this->VMin;
- if ( $DataRange == 0 ) { $DataRange = .1; }
-
- /* Compute automatic scaling */
- $ScaleOk = FALSE; $Factor = 1;
- $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight;
-
- if ( $this->VMin == 0 && $this->VMax == 0 )
- { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;}
- elseif ($MaxDivs > 1)
- {
- while(!$ScaleOk)
- {
- $Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
- $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
- $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
-
- if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
- if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
- if (!$ScaleOk)
- {
- if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
- if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
- }
- }
-
- if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor)
- {
- $GridID = floor ( $this->VMax / $Scale / $Factor) + 1;
- $this->VMax = $GridID * $Scale * $Factor;
- $Divisions++;
- }
-
- if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor)
- {
- $GridID = floor( $this->VMin / $Scale / $Factor);
- $this->VMin = $GridID * $Scale * $Factor;
- $Divisions++;
- }
- }
- else /* Can occurs for small graphs */
- $Scale = 1;
-
- if ( !isset($Divisions) )
- $Divisions = 2;
-
- if ($Scale == 1 && $Divisions%2 == 1)
- $Divisions--;
- }
- else
- $Divisions = $this->Divisions;
-
- $this->DivisionCount = $Divisions;
-
- $DataRange = $this->VMax - $this->VMin;
- if ( $DataRange == 0 ) { $DataRange = .1; }
-
- $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions;
- $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange;
-
- $this->GAreaXOffset = 0;
- if ( count($Data) > 1 )
- {
- if ( $WithMargin == FALSE )
- $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / (count($Data)-1);
- else
- {
- $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / (count($Data));
- $this->GAreaXOffset = $this->DivisionWidth / 2;
- }
- }
- else
- {
- $this->DivisionWidth = $this->GArea_X2 - $this->GArea_X1;
- $this->GAreaXOffset = $this->DivisionWidth / 2;
- }
-
- $this->DataCount = count($Data);
-
- if ( $DrawTicks == FALSE )
- return(0);
-
- $YPos = $this->GArea_Y2; $XMin = NULL;
- for($i=1;$i<=$Divisions+1;$i++)
- {
- if ( $RightScale )
- $this->drawLine($this->GArea_X2,$YPos,$this->GArea_X2+5,$YPos,$R,$G,$B);
- else
- $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B);
-
- $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions);
- $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
- if ( $DataDescription["Format"]["Y"] == "number" )
- $Value = $Value.$DataDescription["Unit"]["Y"];
- if ( $DataDescription["Format"]["Y"] == "time" )
- $Value = $this->ToTime($Value);
- if ( $DataDescription["Format"]["Y"] == "date" )
- $Value = $this->ToDate($Value);
- if ( $DataDescription["Format"]["Y"] == "metric" )
- $Value = $this->ToMetric($Value);
- if ( $DataDescription["Format"]["Y"] == "currency" )
- $Value = $this->ToCurrency($Value);
-
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextWidth = $Position[2]-$Position[0];
-
- if ( $RightScale )
- {
- imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+10,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
- if ( $XMin < $this->GArea_X2+15+$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X2+15+$TextWidth; }
- }
- else
- {
- imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
- if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; }
- }
-
- $YPos = $YPos - $this->DivisionHeight;
- }
-
- /* Write the Y Axis caption if set */
- if ( isset($DataDescription["Axis"]["Y"]) )
- {
- $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]);
- $TextHeight = abs($Position[1])+abs($Position[3]);
- $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2);
-
- if ( $RightScale )
- imagettftext($this->Picture,$this->FontSize,90,$XMin+$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
- else
- imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
- }
-
- /* Horizontal Axis */
- $XPos = $this->GArea_X1 + $this->GAreaXOffset;
- $ID = 1; $YMax = NULL;
- foreach ( $Data as $Key => $Values )
- {
- if ( $ID % $SkipLabels == 0 )
- {
- $this->drawLine(floor($XPos),$this->GArea_Y2,floor($XPos),$this->GArea_Y2+5,$R,$G,$B);
- $Value = $Data[$Key][$DataDescription["Position"]];
- if ( $DataDescription["Format"]["X"] == "number" )
- $Value = $Value.$DataDescription["Unit"]["X"];
- if ( $DataDescription["Format"]["X"] == "time" )
- $Value = $this->ToTime($Value);
- if ( $DataDescription["Format"]["X"] == "date" )
- $Value = $this->ToDate($Value);
- if ( $DataDescription["Format"]["X"] == "metric" )
- $Value = $this->ToMetric($Value);
- if ( $DataDescription["Format"]["X"] == "currency" )
- $Value = $this->ToCurrency($Value);
-
- $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value);
- $TextWidth = abs($Position[2])+abs($Position[0]);
- $TextHeight = abs($Position[1])+abs($Position[3]);
-
- if ( $Angle == 0 )
- {
- $YPos = $this->GArea_Y2+18;
- imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value);
- }
- else
- {
- $YPos = $this->GArea_Y2+10+$TextHeight;
- if ( $Angle <= 90 )
- imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
- else
- imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
- }
- if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; }
- }
-
- $XPos = $XPos + $this->DivisionWidth;
- $ID++;
- }
-
- /* Write the X Axis caption if set */
- if ( isset($DataDescription["Axis"]["X"]) )
- {
- $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]);
- $TextWidth = abs($Position[2])+abs($Position[0]);
- $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2);
- imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]);
- }
- }
-
- /* Compute and draw the scale for X/Y charts */
- function drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1)
- {
- /* Validate the Data and DataDescription array */
- $this->validateData("drawScale",$Data);
-
- $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
-
- $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B);
- $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B);
-
- /* Process Y scale */
- if ( $this->VMin == NULL && $this->VMax == NULL)
- {
- $this->VMin = $Data[0][$YSerieName];
- $this->VMax = $Data[0][$YSerieName];
-
- foreach ( $Data as $Key => $Values )
- {
- if (isset($Data[$Key][$YSerieName]))
- {
- $Value = $Data[$Key][$YSerieName];
- if ( $this->VMax < $Value) { $this->VMax = $Value; }
- if ( $this->VMin > $Value) { $this->VMin = $Value; }
- }
- }
-
- if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) )
- $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1;
-
- $DataRange = $this->VMax - $this->VMin;
- if ( $DataRange == 0 ) { $DataRange = .1; }
-
- /* Compute automatic scaling */
- $ScaleOk = FALSE; $Factor = 1;
- $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight;
-
- if ( $this->VMin == 0 && $this->VMax == 0 )
- { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;}
- elseif ($MaxDivs > 1)
- {
- while(!$ScaleOk)
- {
- $Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
- $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
- $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
-
- if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
- if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
- if (!$ScaleOk)
- {
- if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
- if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
- }
- }
-
- if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor)
- {
- $GridID = floor ( $this->VMax / $Scale / $Factor) + 1;
- $this->VMax = $GridID * $Scale * $Factor;
- $Divisions++;
- }
-
- if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor)
- {
- $GridID = floor( $this->VMin / $Scale / $Factor);
- $this->VMin = $GridID * $Scale * $Factor;
- $Divisions++;
- }
- }
- else /* Can occurs for small graphs */
- $Scale = 1;
-
- if ( !isset($Divisions) )
- $Divisions = 2;
-
- if ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions-1)))
- $Divisions--;
- elseif ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions+1)))
- $Divisions++;
- }
- else
- $Divisions = $this->Divisions;
-
- $this->DivisionCount = $Divisions;
-
- $DataRange = $this->VMax - $this->VMin;
- if ( $DataRange == 0 ) { $DataRange = .1; }
-
- $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions;
- $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange;
-
- $YPos = $this->GArea_Y2; $XMin = NULL;
- for($i=1;$i<=$Divisions+1;$i++)
- {
- $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B);
- $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions);
- $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
- if ( $DataDescription["Format"]["Y"] == "number" )
- $Value = $Value.$DataDescription["Unit"]["Y"];
- if ( $DataDescription["Format"]["Y"] == "time" )
- $Value = $this->ToTime($Value);
- if ( $DataDescription["Format"]["Y"] == "date" )
- $Value = $this->ToDate($Value);
- if ( $DataDescription["Format"]["Y"] == "metric" )
- $Value = $this->ToMetric($Value);
- if ( $DataDescription["Format"]["Y"] == "currency" )
- $Value = $this->ToCurrency($Value);
-
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextWidth = $Position[2]-$Position[0];
- imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
-
- if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; }
-
- $YPos = $YPos - $this->DivisionHeight;
- }
-
- /* Process X scale */
- if ( $this->VXMin == NULL && $this->VXMax == NULL)
- {
- $this->VXMin = $Data[0][$XSerieName];
- $this->VXMax = $Data[0][$XSerieName];
-
- foreach ( $Data as $Key => $Values )
- {
- if (isset($Data[$Key][$XSerieName]))
- {
- $Value = $Data[$Key][$XSerieName];
- if ( $this->VXMax < $Value) { $this->VXMax = $Value; }
- if ( $this->VXMin > $Value) { $this->VXMin = $Value; }
- }
- }
-
- if ( $this->VXMax > preg_replace('/\.[0-9]+/','',$this->VXMax) )
- $this->VXMax = preg_replace('/\.[0-9]+/','',$this->VXMax)+1;
-
- $DataRange = $this->VMax - $this->VMin;
- if ( $DataRange == 0 ) { $DataRange = .1; }
-
- /* Compute automatic scaling */
- $ScaleOk = FALSE; $Factor = 1;
- $MinDivWidth = 25; $MaxDivs = ($this->GArea_X2 - $this->GArea_X1) / $MinDivWidth;
-
- if ( $this->VXMin == 0 && $this->VXMax == 0 )
- { $this->VXMin = 0; $this->VXMax = 2; $Scale = 1; $XDivisions = 2;}
- elseif ($MaxDivs > 1)
- {
- while(!$ScaleOk)
- {
- $Scale1 = ( $this->VXMax - $this->VXMin ) / $Factor;
- $Scale2 = ( $this->VXMax - $this->VXMin ) / $Factor / 2;
- $Scale4 = ( $this->VXMax - $this->VXMin ) / $Factor / 4;
-
- if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale1); $Scale = 1;}
- if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale2); $Scale = 2;}
- if (!$ScaleOk)
- {
- if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
- if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
- }
- }
-
- if ( floor($this->VXMax / $Scale / $Factor) != $this->VXMax / $Scale / $Factor)
- {
- $GridID = floor ( $this->VXMax / $Scale / $Factor) + 1;
- $this->VXMax = $GridID * $Scale * $Factor;
- $XDivisions++;
- }
-
- if ( floor($this->VXMin / $Scale / $Factor) != $this->VXMin / $Scale / $Factor)
- {
- $GridID = floor( $this->VXMin / $Scale / $Factor);
- $this->VXMin = $GridID * $Scale * $Factor;
- $XDivisions++;
- }
- }
- else /* Can occurs for small graphs */
- $Scale = 1;
-
- if ( !isset($XDivisions) )
- $XDivisions = 2;
-
- if ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions-1)))
- $XDivisions--;
- elseif ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions+1)))
- $XDivisions++;
- }
- else
- $XDivisions = $this->XDivisions;
-
- $this->XDivisionCount = $Divisions;
- $this->DataCount = $Divisions + 2;
-
- $XDataRange = $this->VXMax - $this->VXMin;
- if ( $XDataRange == 0 ) { $XDataRange = .1; }
-
- $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDivisions;
- $this->XDivisionRatio = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDataRange;
-
- $XPos = $this->GArea_X1; $YMax = NULL;
- for($i=1;$i<=$XDivisions+1;$i++)
- {
- $this->drawLine($XPos,$this->GArea_Y2,$XPos,$this->GArea_Y2+5,$R,$G,$B);
-
- $Value = $this->VXMin + ($i-1) * (( $this->VXMax - $this->VXMin ) / $XDivisions);
- $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
- if ( $DataDescription["Format"]["Y"] == "number" )
- $Value = $Value.$DataDescription["Unit"]["Y"];
- if ( $DataDescription["Format"]["Y"] == "time" )
- $Value = $this->ToTime($Value);
- if ( $DataDescription["Format"]["Y"] == "date" )
- $Value = $this->ToDate($Value);
- if ( $DataDescription["Format"]["Y"] == "metric" )
- $Value = $this->ToMetric($Value);
- if ( $DataDescription["Format"]["Y"] == "currency" )
- $Value = $this->ToCurrency($Value);
-
- $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value);
- $TextWidth = abs($Position[2])+abs($Position[0]);
- $TextHeight = abs($Position[1])+abs($Position[3]);
-
- if ( $Angle == 0 )
- {
- $YPos = $this->GArea_Y2+18;
- imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value);
- }
- else
- {
- $YPos = $this->GArea_Y2+10+$TextHeight;
- if ( $Angle <= 90 )
- imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
- else
- imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
- }
-
- if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; }
-
- $XPos = $XPos + $this->DivisionWidth;
- }
-
- /* Write the Y Axis caption if set */
- if ( isset($DataDescription["Axis"]["Y"]) )
- {
- $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]);
- $TextHeight = abs($Position[1])+abs($Position[3]);
- $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2);
- imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
- }
-
- /* Write the X Axis caption if set */
- if ( isset($DataDescription["Axis"]["X"]) )
- {
- $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]);
- $TextWidth = abs($Position[2])+abs($Position[0]);
- $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2);
- imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]);
- }
- }
-
- /* Compute and draw the scale */
- function drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100)
- {
- /* Draw mosaic */
- if ( $Mosaic )
- {
- $LayerWidth = $this->GArea_X2-$this->GArea_X1;
- $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
-
- $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
- $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
- imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
- imagecolortransparent($this->Layers[0],$C_White);
-
- $C_Rectangle =$this->AllocateColor($this->Layers[0],250,250,250);
-
- $YPos = $LayerHeight; //$this->GArea_Y2-1;
- $LastY = $YPos;
- for($i=0;$i<=$this->DivisionCount;$i++)
- {
- $LastY = $YPos;
- $YPos = $YPos - $this->DivisionHeight;
-
- if ( $YPos <= 0 ) { $YPos = 1; }
-
- if ( $i % 2 == 0 )
- {
- imagefilledrectangle($this->Layers[0],1,$YPos,$LayerWidth-1,$LastY,$C_Rectangle);
- }
- }
- imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
- imagedestroy($this->Layers[0]);
- }
-
- /* Horizontal lines */
- $YPos = $this->GArea_Y2 - $this->DivisionHeight;
- for($i=1;$i<=$this->DivisionCount;$i++)
- {
- if ( $YPos > $this->GArea_Y1 && $YPos < $this->GArea_Y2 )
- $this->drawDottedLine($this->GArea_X1,$YPos,$this->GArea_X2,$YPos,$LineWidth,$R,$G,$B);
-
- $YPos = $YPos - $this->DivisionHeight;
- }
-
- /* Vertical lines */
- if ( $this->GAreaXOffset == 0 )
- { $XPos = $this->GArea_X1 + $this->DivisionWidth + $this->GAreaXOffset; $ColCount = $this->DataCount-2; }
- else
- { $XPos = $this->GArea_X1 + $this->GAreaXOffset; $ColCount = floor( ($this->GArea_X2 - $this->GArea_X1) / $this->DivisionWidth ); }
-
- for($i=1;$i<=$ColCount;$i++)
- {
- if ( $XPos > $this->GArea_X1 && $XPos < $this->GArea_X2 )
- $this->drawDottedLine(floor($XPos),$this->GArea_Y1,floor($XPos),$this->GArea_Y2,$LineWidth,$R,$G,$B);
- $XPos = $XPos + $this->DivisionWidth;
- }
- }
-
- /* retrieve the legends size */
- function getLegendBoxSize($DataDescription)
- {
- if ( !isset($DataDescription["Description"]) )
- return(-1);
-
- /* <-10->[8]<-4->Text<-10-> */
- $MaxWidth = 0; $MaxHeight = 8;
- foreach($DataDescription["Description"] as $Key => $Value)
- {
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextWidth = $Position[2]-$Position[0];
- $TextHeight = $Position[1]-$Position[7];
- if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
- $MaxHeight = $MaxHeight + $TextHeight + 4;
- }
- $MaxHeight = $MaxHeight - 3;
- $MaxWidth = $MaxWidth + 32;
-
- return(array($MaxWidth,$MaxHeight));
- }
-
- /* Draw the data legends */
- function drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=TRUE)
- {
- /* Validate the Data and DataDescription array */
- $this->validateDataDescription("drawLegend",$DataDescription);
-
- if ( !isset($DataDescription["Description"]) )
- return(-1);
-
- $C_TextColor =$this->AllocateColor($this->Picture,$Rt,$Gt,$Bt);
-
- /* <-10->[8]<-4->Text<-10-> */
- $MaxWidth = 0; $MaxHeight = 8;
- foreach($DataDescription["Description"] as $Key => $Value)
- {
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextWidth = $Position[2]-$Position[0];
- $TextHeight = $Position[1]-$Position[7];
- if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
- $MaxHeight = $MaxHeight + $TextHeight + 4;
- }
- $MaxHeight = $MaxHeight - 5;
- $MaxWidth = $MaxWidth + 32;
-
- if ( $Rs == -1 || $Gs == -1 || $Bs == -1 )
- { $Rs = $R-30; $Gs = $G-30; $Bs = $B-30; }
-
- if ( $Border )
- {
- $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$Rs,$Gs,$Bs);
- $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B);
- }
-
- $YOffset = 4 + $this->FontSize; $ID = 0;
- foreach($DataDescription["Description"] as $Key => $Value)
- {
- $this->drawFilledRoundedRectangle($XPos+10,$YPos+$YOffset-4,$XPos+14,$YPos+$YOffset-4,2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]);
- imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value);
-
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextHeight = $Position[1]-$Position[7];
-
- $YOffset = $YOffset + $TextHeight + 4;
- $ID++;
- }
- }
-
- /* Draw the data legends */
- function drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)
- {
- /* Validate the Data and DataDescription array */
- $this->validateDataDescription("drawPieLegend",$DataDescription,FALSE);
- $this->validateData("drawPieLegend",$Data);
-
- if ( !isset($DataDescription["Position"]) )
- return(-1);
-
- $C_TextColor =$this->AllocateColor($this->Picture,0,0,0);
-
- /* <-10->[8]<-4->Text<-10-> */
- $MaxWidth = 0; $MaxHeight = 8;
- foreach($Data as $Key => $Value)
- {
- $Value2 = $Value[$DataDescription["Position"]];
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2);
- $TextWidth = $Position[2]-$Position[0];
- $TextHeight = $Position[1]-$Position[7];
- if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
-
- $MaxHeight = $MaxHeight + $TextHeight + 4;
- }
- $MaxHeight = $MaxHeight - 3;
- $MaxWidth = $MaxWidth + 32;
-
- $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$R-30,$G-30,$B-30);
- $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B);
-
- $YOffset = 4 + $this->FontSize; $ID = 0;
- foreach($Data as $Key => $Value)
- {
- $Value2 = $Value[$DataDescription["Position"]];
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2);
- $TextHeight = $Position[1]-$Position[7];
- $this->drawFilledRectangle($XPos+10,$YPos+$YOffset-6,$XPos+14,$YPos+$YOffset-2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]);
-
- imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value2);
- $YOffset = $YOffset + $TextHeight + 4;
- $ID++;
- }
- }
-
- /* Draw the graph title */
- function drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
- {
- $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B);
-
- if ( $XPos2 != -1 )
- {
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextWidth = $Position[2]-$Position[0];
- $XPos = floor(( $XPos2 - $XPos - $TextWidth ) / 2 ) + $XPos;
- }
-
- if ( $YPos2 != -1 )
- {
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
- $TextHeight = $Position[5]-$Position[3];
- $YPos = floor(( $YPos2 - $YPos - $TextHeight ) / 2 ) + $YPos;
- }
-
- if ( $Shadow )
- {
- $C_ShadowColor = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor);
- imagettftext($this->Picture,$this->FontSize,0,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$C_ShadowColor,$this->FontName,$Value);
- }
-
- imagettftext($this->Picture,$this->FontSize,0,$XPos,$YPos,$C_TextColor,$this->FontName,$Value);
- }
-
- /* Draw a text box with text align & alpha properties */
- function drawTextBox($X1,$Y1,$X2,$Y2,$Text,$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-1,$BgB=-1,$Alpha=100)
- {
- $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Text);
- $TextWidth = $Position[2]-$Position[0];
- $TextHeight = $Position[5]-$Position[3];
- $AreaWidth = $X2 - $X1;
- $AreaHeight = $Y2 - $Y1;
-
- if ( $BgR != -1 && $BgG != -1 && $BgB != -1 )
- $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$BgR,$BgG,$BgB,FALSE,$Alpha);
-
- if ( $Align == ALIGN_TOP_LEFT ) { $X = $X1+1; $Y = $Y1+$this->FontSize+1; }
- if ( $Align == ALIGN_TOP_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+$this->FontSize+1; }
- if ( $Align == ALIGN_TOP_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+$this->FontSize+1; }
- if ( $Align == ALIGN_LEFT ) { $X = $X1+1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
- if ( $Align == ALIGN_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
- if ( $Align == ALIGN_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
- if ( $Align == ALIGN_BOTTOM_LEFT ) { $X = $X1+1; $Y = $Y2-1; }
- if ( $Align == ALIGN_BOTTOM_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y2-1; }
- if ( $Align == ALIGN_BOTTOM_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y2-1; }
-
- $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
- $C_ShadowColor =$this->AllocateColor($this->Picture,0,0,0);
- if ( $Shadow )
- imagettftext($this->Picture,$this->FontSize,$Angle,$X+1,$Y+1,$C_ShadowColor,$this->FontName,$Text);
-
- imagettftext($this->Picture,$this->FontSize,$Angle,$X,$Y,$C_TextColor,$this->FontName,$Text);
- }
-
- /* Compute and draw the scale */
- function drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL)
- {
- if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
- if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
- if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
-
- $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
- $Y = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
-
- if ( $Y <= $this->GArea_Y1 || $Y >= $this->GArea_Y2 )
- return(-1);
-
- if ( $TickWidth == 0 )
- $this->drawLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$R,$G,$B);
- else
- $this->drawDottedLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$TickWidth,$R,$G,$B);
-
- if ( $ShowLabel )
- {
- if ( $FreeText == NULL )
- { $Label = $Value; } else { $Label = $FreeText; }
-
- if ( $ShowOnRight )
- imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+2,$Y+($this->FontSize/2),$C_TextColor,$this->FontName,$Label);
- else
- imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1+2,$Y-($this->FontSize/2),$C_TextColor,$this->FontName,$Label);
- }
- }
-
- /* This function put a label on a specific point */
- function setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210)
- {
- /* Validate the Data and DataDescription array */
- $this->validateDataDescription("setLabel",$DataDescription);
- $this->validateData("setLabel",$Data);
- $ShadowFactor = 100;
- $C_Label =$this->AllocateColor($this->Picture,$R,$G,$B);
- $C_Shadow =$this->AllocateColor($this->Picture,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
- $C_TextColor =$this->AllocateColor($this->Picture,0,0,0);
-
- $Cp = 0; $Found = FALSE;
- foreach ( $Data as $Key => $Value )
- {
- if ( $Data[$Key][$DataDescription["Position"]] == $ValueName )
- { $NumericalValue = $Data[$Key][$SerieName]; $Found = TRUE; }
- if ( !$Found )
- $Cp++;
- }
-
- $XPos = $this->GArea_X1 + $this->GAreaXOffset + ( $this->DivisionWidth * $Cp ) + 2;
- $YPos = $this->GArea_Y2 - ($NumericalValue - $this->VMin) * $this->DivisionRatio;
-
- $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
- $TextHeight = $Position[3] - $Position[5];
- $TextWidth = $Position[2]-$Position[0] + 2;
- $TextOffset = floor($TextHeight/2);
-
- // Shadow
- $Poly = array($XPos+1,$YPos+1,$XPos + 9,$YPos - $TextOffset,$XPos + 8,$YPos + $TextOffset + 2);
- imagefilledpolygon($this->Picture,$Poly,3,$C_Shadow);
- $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos - $TextOffset - .2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
- $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
- $this->drawFilledRectangle($XPos + 9,$YPos - $TextOffset-.2,$XPos + 13 + $TextWidth,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
-
- // Label background
- $Poly = array($XPos,$YPos,$XPos + 8,$YPos - $TextOffset - 1,$XPos + 8,$YPos + $TextOffset + 1);
- imagefilledpolygon($this->Picture,$Poly,3,$C_Label);
- $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos - $TextOffset - 1.2,$R,$G,$B);
- $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos + $TextOffset + 1.2,$R,$G,$B);
- $this->drawFilledRectangle($XPos + 8,$YPos - $TextOffset - 1.2,$XPos + 12 + $TextWidth,$YPos + $TextOffset + 1.2,$R,$G,$B);
-
- imagettftext($this->Picture,$this->FontSize,0,$XPos + 10,$YPos + $TextOffset,$C_TextColor,$this->FontName,$Caption);
- }
-
- /* This function draw a plot graph */
- function drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE)
- {
- /* Validate the Data and DataDescription array */
- $this->validateDataDescription("drawPlotGraph",$DataDescription);
- $this->validateDa…
Large files files are truncated, but you can click here to view the full file