Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pChart rotated legend - refs CT#7383
- Loading branch information
Daniel Barreto
committed
Nov 17, 2014
1 parent
8eab6cb
commit 468ded5
Showing
2 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -586,6 +586,7 @@ function drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$A | |
/* Horizontal Axis */ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
danbarretodev
Contributor
|
||
$XPos = $this->GArea_X1 + $this->GAreaXOffset; | ||
$ID = 1; $YMax = NULL; | ||
$maxTextHeight = 0; | ||
foreach ( $Data as $Key => $Values ) | ||
{ | ||
if ( $ID % $SkipLabels == 0 ) | ||
|
@@ -607,14 +608,20 @@ function drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$A | |
$TextWidth = abs($Position[2])+abs($Position[0]); | ||
$TextHeight = abs($Position[1])+abs($Position[3]); | ||
|
||
// Save max text height | ||
if ($maxTextHeight < $TextHeight) { | ||
$maxTextHeight = $TextHeight; | ||
} | ||
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; | ||
$YPos = $this->GArea_Y2+10; | ||
// If rotation is top down, then add TextHeight; | ||
$YPos = (sin($Angle) < 0) ? $YPos + $TextHeight : $YPos; | ||
if ( $Angle <= 90 ) | ||
imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value); | ||
else | ||
|
@@ -633,7 +640,7 @@ function drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$A | |
$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"]); | ||
imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5+$maxTextHeight,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]); | ||
} | ||
} | ||
|
||
|
@@ -3555,6 +3562,45 @@ function isRealInt($Value) | |
return(TRUE); | ||
return(FALSE); | ||
} | ||
|
||
/** | ||
* Return a new pChart object fixing its height by legend rotations | ||
* Must be set fonts before call this method | ||
* @param array $data | ||
* @param array $dataDescription | ||
* @param float $angle | ||
* @return pChart | ||
*/ | ||
function fixHeightByRotation ($data, $dataDescription, $angle) | ||
{ | ||
$maxTextHeight = 0; | ||
foreach ( $data as $key => $values ) | ||
{ | ||
// Get legend value | ||
$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); | ||
$TextHeight = abs($Position[1])+abs($Position[3]); | ||
if ($maxTextHeight < $TextHeight) { | ||
$maxTextHeight = $TextHeight; | ||
} | ||
} | ||
$this->YSize += $maxTextHeight; | ||
$pChart = new pChart($this->XSize, $this->YSize); | ||
// set font of the axes | ||
$pChart->setFontProperties($this->FontName, $this->FontSize); | ||
|
||
return $pChart; | ||
} | ||
} | ||
|
||
function RaiseFatal($Message) | ||
|
This is very very bad. We should not update a third party library!
Did you try updating the lib to the latest version?