graph : display correctly the fist label of Y axis if there is no title

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3356 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-01-30 10:40:17 +00:00
parent 0c6e3668d4
commit 2eb030056d

View File

@@ -174,7 +174,7 @@ class graph
/** Draw the graph to the screen with the previous defined parameters /** Draw the graph to the screen with the previous defined parameters
*/ */
public function drawImage () private function drawReal ()
{ {
// Read the data // Read the data
$series = $this->data->getSeries (); $series = $this->data->getSeries ();
@@ -318,6 +318,11 @@ class graph
// Add the legend on right // Add the legend on right
$free = $this->legend->draw ($gd, $free, $this->series); $free = $this->legend->draw ($gd, $free, $this->series);
// If there is no title, add an offset of 10px to display correctely the
// first label of the Y axis
if ($free[1] === 0)
$free[1] = 10;
// Add the axis // Add the axis
// Need two passes as the X axis can modify the Y axes // Need two passes as the X axis can modify the Y axes
$this->axisX->top ($free[1]); $this->axisX->top ($free[1]);
@@ -356,18 +361,25 @@ class graph
$this->axisX, $this->axisY2); $this->axisX, $this->axisY2);
} }
$free = $lastFree; $free = $lastFree;
header ('Content-Type: image/png');
imagepng ($gd); imagepng ($gd);
imagedestroy ($gd); imagedestroy ($gd);
} }
/** Draw the graph to the screen with the previous defined parameters
*/
public function drawImage ()
{
header ('Content-Type: image/png');
$this->drawReal ();
}
/** Return the image coded in base64 /** Return the image coded in base64
* @return string The base64 string * @return string The base64 string
*/ */
public function drawBase64 () public function drawBase64 ()
{ {
ob_start (); ob_start ();
$this->drawImage (); $this->drawReal ();
return base64_encode (ob_get_clean()); return base64_encode (ob_get_clean());
} }
} }
@@ -615,7 +627,7 @@ class graphSerie
return $this->style; return $this->style;
} }
if (! is_string ($style) || if (! is_string ($style) ||
! in_array ($style, array ("line"))) ! in_array ($style, array ("line", "points", "linePoints")))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid style provided to serie"), 406); "Invalid style provided to serie"), 406);
$styleClass = "graphStyle".$style; $styleClass = "graphStyle".$style;