Make it possible to set a minimum circle width

refs #4190
This commit is contained in:
Johannes Meyer 2014-03-27 10:19:50 +01:00
parent f5e4331d71
commit f7c6cd3c2a
2 changed files with 38 additions and 3 deletions

View File

@ -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'));

View File

@ -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
);
}
/**