From 1878485487ebabea8fe9c8568994df3f253e3cf5 Mon Sep 17 00:00:00 2001 From: lexustec Date: Tue, 10 Mar 2020 13:54:37 +0100 Subject: [PATCH] Update Settings.php Added the function to scale the Labels also in decimals. sometimes You have values with more than 2 decimals.... Usage: $settings = new Settings(); $settings->setDecimals(3); $lineGraph = new Linechart(); $lineGraph->setSettings($settings); keep in mind that padding also need to be adjusted.... if the float value is the following 2.24537256 then: $settings->setDecimals(8); then the padding should be at least 10 $settings->setPadding(10); --- src/Settings.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Settings.php b/src/Settings.php index fec5392..ba97a7a 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -22,6 +22,11 @@ final class Settings * @var int */ private $offset = 2; + + /** + * @var int + */ + private $decimals = 2; /** * @var string @@ -50,9 +55,10 @@ public function __construct() { $this->format = function ($x, self $settings) { $padding = $settings->getPadding(); + $decimals = $settings->getDecimals(); $paddingLength = \strlen($padding); - return substr($padding . round($x, 2), -$paddingLength); + return substr($padding . round($x, $decimals), -$paddingLength); }; } @@ -73,6 +79,18 @@ public function setPadding(int $length, ?string $char = null): self return $this; } + public function getDecimals(): int + { + return $this->decimals; + } + + public function setDecimals(int $decimals): self + { + $this->decimals = $decimals; + + return $this; + } + public function getHeight(): ?int { return $this->height;