From f7c6cd3c2a20c4157edb2171ae532dff3e4970f9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 27 Mar 2014 10:19:50 +0100 Subject: [PATCH] Make it possible to set a minimum circle width refs #4190 --- .../controllers/TimelineController.php | 2 + .../library/Monitoring/Timeline/TimeLine.php | 39 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 6c825794e..d7343e054 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -16,6 +16,7 @@ class Monitoring_TimelineController extends ActionController { public function indexAction() { + // TODO: filter for hard_states (precedence adjustments necessary!) $this->setupIntervalBox(); list($displayRange, $forecastRange) = $this->buildTimeRanges(); @@ -62,6 +63,7 @@ class Monitoring_TimelineController extends ActionController ) ); $timeline->setMaximumCircleWidth('6em'); + $timeline->setMinimumCircleWidth('0.15em'); $timeline->setDisplayRange($displayRange); $timeline->setForecastRange($forecastRange); $timeline->setSession($this->getWindowSession('timeline')); diff --git a/modules/monitoring/library/Monitoring/Timeline/TimeLine.php b/modules/monitoring/library/Monitoring/Timeline/TimeLine.php index 0a809340b..bb2651ea2 100644 --- a/modules/monitoring/library/Monitoring/Timeline/TimeLine.php +++ b/modules/monitoring/library/Monitoring/Timeline/TimeLine.php @@ -81,6 +81,13 @@ class TimeLine implements IteratorAggregate */ protected $circleDiameter = 100.0; + /** + * The minimum diameter each circle can have + * + * @var float + */ + protected $minCircleDiameter = 1.0; + /** * The unit of a circle's diameter * @@ -154,14 +161,35 @@ class TimeLine implements IteratorAggregate public function setMaximumCircleWidth($width) { $matches = array(); - if (preg_match('#([\d]+)([a-z]+|%)#', $width, $matches)) { - $this->circleDiameter = intval($matches[1]); + if (preg_match('#([\d|\.]+)([a-z]+|%)#', $width, $matches)) { + $this->circleDiameter = floatval($matches[1]); $this->diameterUnit = $matches[2]; } else { throw new Exception('Width "' . $width . '" is not a valid width'); } } + /** + * Set the minimum diameter each circle can have + * + * @param string $width The diameter to set, suffixed with its unit + * + * @throws Exception If the given diameter is invalid or its unit differs from the maximum + */ + public function setMinimumCircleWidth($width) + { + $matches = array(); + if (preg_match('#([\d|\.]+)([a-z]+|%)#', $width, $matches)) { + if ($matches[2] === $this->diameterUnit) { + $this->minCircleDiameter = floatval($matches[1]); + } else { + throw new Exception('Unit needs to be in "' . $this->diameterUnit . '"'); + } + } else { + throw new Exception('Width "' . $width . '" is not a valid width'); + } + } + /** * Return all known group types (identifiers) with their respective labels and colors as array * @@ -190,7 +218,12 @@ class TimeLine implements IteratorAggregate { $base = $this->getCalculationBase(true); $factor = log($group->getValue() * $group->getWeight(), $base) / 100; - return sprintf('%.' . $precision . 'F%s', $this->circleDiameter * $factor, $this->diameterUnit); + $width = $this->circleDiameter * $factor; + return sprintf( + '%.' . $precision . 'F%s', + $width > $this->minCircleDiameter ? $width : $this->minCircleDiameter, + $this->diameterUnit + ); } /**