From 2eb030056db4ba60179110a1766ae24c134928a6 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 30 Jan 2017 10:40:17 +0000 Subject: [PATCH] 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 --- graph.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/graph.php b/graph.php index 50eedcd..1cfc561 100644 --- a/graph.php +++ b/graph.php @@ -174,7 +174,7 @@ class graph /** Draw the graph to the screen with the previous defined parameters */ - public function drawImage () + private function drawReal () { // Read the data $series = $this->data->getSeries (); @@ -318,6 +318,11 @@ class graph // Add the legend on right $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 // Need two passes as the X axis can modify the Y axes $this->axisX->top ($free[1]); @@ -356,18 +361,25 @@ class graph $this->axisX, $this->axisY2); } $free = $lastFree; - header ('Content-Type: image/png'); imagepng ($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 string The base64 string */ public function drawBase64 () { ob_start (); - $this->drawImage (); + $this->drawReal (); return base64_encode (ob_get_clean()); } } @@ -615,7 +627,7 @@ class graphSerie return $this->style; } if (! is_string ($style) || - ! in_array ($style, array ("line"))) + ! in_array ($style, array ("line", "points", "linePoints"))) throw new \Exception (dgettext ("domframework", "Invalid style provided to serie"), 406); $styleClass = "graphStyle".$style;