Skip to content

Commit

Permalink
Make it possible to set a minimum circle width
Browse files Browse the repository at this point in the history
refs #4190
  • Loading branch information
Johannes Meyer committed Apr 1, 2014
1 parent f5e4331 commit f7c6cd3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Expand Up @@ -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();

Expand Down Expand Up @@ -62,6 +63,7 @@ public function indexAction()
)
);
$timeline->setMaximumCircleWidth('6em');
$timeline->setMinimumCircleWidth('0.15em');
$timeline->setDisplayRange($displayRange);
$timeline->setForecastRange($forecastRange);
$timeline->setSession($this->getWindowSession('timeline'));
Expand Down
39 changes: 36 additions & 3 deletions modules/monitoring/library/Monitoring/Timeline/TimeLine.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -154,14 +161,35 @@ public function setForecastRange(TimeRange $range)
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
*
Expand Down Expand Up @@ -190,7 +218,12 @@ public function calculateCircleWidth(TimeEntry $group, $precision = 0)
{
$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
);
}

/**
Expand Down

0 comments on commit f7c6cd3

Please sign in to comment.