From aae49ce0c00b5a122333e7092fa3e6271bb24625 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Wed, 18 Jun 2014 17:37:01 +0200 Subject: [PATCH] Do not show tooltips for piechart areas that indicate empty or free areas refs #6117 --- library/Icinga/Web/Widget/Chart/InlinePie.php | 21 ++++++++++++++++++- .../application/views/helpers/Perfdata.php | 15 +++++++------ public/js/icinga/events.js | 4 ++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/library/Icinga/Web/Widget/Chart/InlinePie.php b/library/Icinga/Web/Widget/Chart/InlinePie.php index 256860025..7618e4771 100644 --- a/library/Icinga/Web/Widget/Chart/InlinePie.php +++ b/library/Icinga/Web/Widget/Chart/InlinePie.php @@ -68,6 +68,7 @@ class InlinePie extends AbstractWidget style="{style}" labels="{labels}" formatted="{formatted}" + hideEmptyLabel={hideEmptyLabel} values="{data}" tooltipFormat="{tooltipFormat}" sparkSliceColors="[{colors}]" @@ -146,7 +147,14 @@ EOD; * * @var array */ - private $labels; + private $labels = array(); + + /** + * If the tooltip for the "empty" area should be hidden + * + * @var bool + */ + private $hideEmptyLabel = false; /** * The format string used to display tooltips @@ -162,6 +170,16 @@ EOD; */ private $format = self::NUMBER_FORMAT_BYTES; + /** + * Set if the tooltip for the empty area should be hidden + * + * @param bool $hide Whether to hide the empty area + */ + public function setHideEmptyLabel($hide = true) + { + $this->hideEmptyLabel = $hide; + } + /** * Set the data to be displayed. * @@ -355,6 +373,7 @@ EOD; $template = preg_replace('{{colors}}', implode(',', $this->colors), $template); $template = preg_replace('{{borderWidth}}', htmlspecialchars($this->borderWidth), $template); $template = preg_replace('{{borderColor}}', htmlspecialchars($this->borderColor), $template); + $template = preg_replace('{{hideEmptyLabel}}', $this->hideEmptyLabel ? 'true' : 'false', $template); // values $formatted = array(); diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index ae3c970f5..72d99c574 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -18,12 +18,12 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract if (!$perfdata->isPercentage() && $perfdata->getMaximumValue() === null) { continue; } - $pieChart = $this->createInlinePie($perfdata); + $pieChart = $this->createInlinePie($perfdata, $label); if ($compact) { $pieChart->setTitle( htmlspecialchars($label) /* . ': ' . htmlspecialchars($this->formatPerfdataValue($perfdata) */ ); - if (!$float) { + if (! $float) { $result .= $pieChart->render(); } else { $result .= '
' . $pieChart->render() . '
'; @@ -85,20 +85,23 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract return $perfdata->getValue(); } - protected function createInlinePie(Perfdata $perfdata) + protected function createInlinePie(Perfdata $perfdata, $label = '') { $pieChart = new InlinePie($this->calculatePieChartData($perfdata)); + $pieChart->setLabels(array($label, $label, $label, '')); + $pieChart->setHideEmptyLabel(); + //$pieChart->setHeight(32)->setWidth(32); if ($perfdata->isBytes()) { - $pieChart->setLabels(array(t('Used'), t('Used'), t('Used'), t('Free'))); + $pieChart->setTooltipFormat('{{label}}: {{formatted}} ({{percent}}%)'); $pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_BYTES); } else if ($perfdata->isSeconds()) { - $pieChart->setLabels(array(t('Runtime'), t('Runtime'), t('Runtime'), t('Tolerance'))); + $pieChart->setTooltipFormat('{{label}}: {{formatted}} ({{percent}}%)'); $pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_TIME); } else { - $pieChart->setLabels(array(t('Packet Loss'), t('Packet Loss'), t('Packet Loss'), t('Packet Return'))); $pieChart->setTooltipFormat('{{label}}: {{formatted}}%'); $pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_RATIO); + $pieChart->setHideEmptyLabel(); } return $pieChart; } diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 21e8512b4..38cf8c676 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -77,12 +77,16 @@ var formatted = $spark.attr('formatted').split('|'); var tooltipChartTitle = $spark.attr('sparkTooltipChartTitle') || ''; var format = $spark.attr('tooltipformat'); + var hideEmpty = $spark.attr('hideEmptyLabel') === 'true'; $spark.sparkline( 'html', { enableTagOptions: true, tooltipFormatter: function (sparkline, options, fields) { var out = format; + if (hideEmpty && fields.offset === 3) { + return ''; + } var replace = { title: tooltipChartTitle, label: labels[fields.offset] ? labels[fields.offset] : fields.offset,