Improve piechart limitation and show non-piechart perfdata as well
The perfdata helper did an improper limitation as it might have skipped valid values due to applying the limit before the filter. When not in compact view the helper now also shows non-piechart values by using their raw representation. refs #6515
This commit is contained in:
parent
5908e9fc70
commit
bacea36ad9
|
@ -11,13 +11,17 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||
{
|
||||
public function perfdata($perfdataStr, $compact = false, $float = false)
|
||||
{
|
||||
$pset = PerfdataSet::fromString($perfdataStr)->asArray();
|
||||
$onlyPieChartData = array_filter($pset, function ($e) { return $e->getPercentage() > 0; });
|
||||
if ($compact) {
|
||||
$onlyPieChartData = array_slice($onlyPieChartData, 0, 5);
|
||||
} else {
|
||||
$nonPieChartData = array_filter($pset, function ($e) { return $e->getPercentage() == 0; });
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$table = array();
|
||||
$pset = array_slice(PerfdataSet::fromString($perfdataStr)->asArray(), 0, ($compact ? 5 : null));
|
||||
foreach ($pset as $perfdata) {
|
||||
if ($perfdata->getPercentage() == 0) {
|
||||
continue;
|
||||
}
|
||||
foreach ($onlyPieChartData as $perfdata) {
|
||||
$pieChart = $this->createInlinePie($perfdata);
|
||||
if ($compact) {
|
||||
if (! $float) {
|
||||
|
@ -27,6 +31,7 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||
}
|
||||
} else {
|
||||
if (! $perfdata->isPercentage()) {
|
||||
// TODO: Should we trust sprintf-style placeholders in perfdata titles?
|
||||
$pieChart->setTooltipFormat('{{label}}: {{formatted}} ({{percent}}%)');
|
||||
}
|
||||
$pieChart->setStyle('margin: 0.2em 0.5em 0.2em 0.5em;');
|
||||
|
@ -38,11 +43,11 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: What if we have both? And should we trust sprintf-style placeholders in perfdata titles?
|
||||
if (empty($table)) {
|
||||
return $compact ? $result : $perfdataStr;
|
||||
if ($compact) {
|
||||
return $result;
|
||||
} else {
|
||||
return '<table class="perfdata">' . implode("\n", $table) . '</table>';
|
||||
$pieCharts = empty($table) ? '' : '<table class="perfdata">' . implode("\n", $table) . '</table>';
|
||||
return $pieCharts . "\n" . implode("<br>\n", $nonPieChartData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,6 +237,16 @@ class Perfdata
|
|||
return $this->maxValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this performance data as string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf(strpos($this->label, ' ') === false ? '%s=%s' : "'%s'=%s", $this->label, $this->perfdataValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the current performance data value
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue