mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Do not show tooltips for piechart areas that indicate empty or free areas
refs #6117
This commit is contained in:
parent
6555d347a7
commit
aae49ce0c0
@ -68,6 +68,7 @@ class InlinePie extends AbstractWidget
|
|||||||
style="{style}"
|
style="{style}"
|
||||||
labels="{labels}"
|
labels="{labels}"
|
||||||
formatted="{formatted}"
|
formatted="{formatted}"
|
||||||
|
hideEmptyLabel={hideEmptyLabel}
|
||||||
values="{data}"
|
values="{data}"
|
||||||
tooltipFormat="{tooltipFormat}"
|
tooltipFormat="{tooltipFormat}"
|
||||||
sparkSliceColors="[{colors}]"
|
sparkSliceColors="[{colors}]"
|
||||||
@ -146,7 +147,14 @@ EOD;
|
|||||||
*
|
*
|
||||||
* @var array
|
* @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
|
* The format string used to display tooltips
|
||||||
@ -162,6 +170,16 @@ EOD;
|
|||||||
*/
|
*/
|
||||||
private $format = self::NUMBER_FORMAT_BYTES;
|
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.
|
* Set the data to be displayed.
|
||||||
*
|
*
|
||||||
@ -355,6 +373,7 @@ EOD;
|
|||||||
$template = preg_replace('{{colors}}', implode(',', $this->colors), $template);
|
$template = preg_replace('{{colors}}', implode(',', $this->colors), $template);
|
||||||
$template = preg_replace('{{borderWidth}}', htmlspecialchars($this->borderWidth), $template);
|
$template = preg_replace('{{borderWidth}}', htmlspecialchars($this->borderWidth), $template);
|
||||||
$template = preg_replace('{{borderColor}}', htmlspecialchars($this->borderColor), $template);
|
$template = preg_replace('{{borderColor}}', htmlspecialchars($this->borderColor), $template);
|
||||||
|
$template = preg_replace('{{hideEmptyLabel}}', $this->hideEmptyLabel ? 'true' : 'false', $template);
|
||||||
|
|
||||||
// values
|
// values
|
||||||
$formatted = array();
|
$formatted = array();
|
||||||
|
@ -18,12 +18,12 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||||||
if (!$perfdata->isPercentage() && $perfdata->getMaximumValue() === null) {
|
if (!$perfdata->isPercentage() && $perfdata->getMaximumValue() === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$pieChart = $this->createInlinePie($perfdata);
|
$pieChart = $this->createInlinePie($perfdata, $label);
|
||||||
if ($compact) {
|
if ($compact) {
|
||||||
$pieChart->setTitle(
|
$pieChart->setTitle(
|
||||||
htmlspecialchars($label) /* . ': ' . htmlspecialchars($this->formatPerfdataValue($perfdata) */
|
htmlspecialchars($label) /* . ': ' . htmlspecialchars($this->formatPerfdataValue($perfdata) */
|
||||||
);
|
);
|
||||||
if (!$float) {
|
if (! $float) {
|
||||||
$result .= $pieChart->render();
|
$result .= $pieChart->render();
|
||||||
} else {
|
} else {
|
||||||
$result .= '<div style="float: right;">' . $pieChart->render() . '</div>';
|
$result .= '<div style="float: right;">' . $pieChart->render() . '</div>';
|
||||||
@ -85,20 +85,23 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||||||
return $perfdata->getValue();
|
return $perfdata->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createInlinePie(Perfdata $perfdata)
|
protected function createInlinePie(Perfdata $perfdata, $label = '')
|
||||||
{
|
{
|
||||||
$pieChart = new InlinePie($this->calculatePieChartData($perfdata));
|
$pieChart = new InlinePie($this->calculatePieChartData($perfdata));
|
||||||
|
$pieChart->setLabels(array($label, $label, $label, ''));
|
||||||
|
$pieChart->setHideEmptyLabel();
|
||||||
|
|
||||||
//$pieChart->setHeight(32)->setWidth(32);
|
//$pieChart->setHeight(32)->setWidth(32);
|
||||||
if ($perfdata->isBytes()) {
|
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);
|
$pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_BYTES);
|
||||||
} else if ($perfdata->isSeconds()) {
|
} 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);
|
$pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_TIME);
|
||||||
} else {
|
} else {
|
||||||
$pieChart->setLabels(array(t('Packet Loss'), t('Packet Loss'), t('Packet Loss'), t('Packet Return')));
|
|
||||||
$pieChart->setTooltipFormat('{{label}}: {{formatted}}%');
|
$pieChart->setTooltipFormat('{{label}}: {{formatted}}%');
|
||||||
$pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_RATIO);
|
$pieChart->setNumberFormat(InlinePie::NUMBER_FORMAT_RATIO);
|
||||||
|
$pieChart->setHideEmptyLabel();
|
||||||
}
|
}
|
||||||
return $pieChart;
|
return $pieChart;
|
||||||
}
|
}
|
||||||
|
@ -77,12 +77,16 @@
|
|||||||
var formatted = $spark.attr('formatted').split('|');
|
var formatted = $spark.attr('formatted').split('|');
|
||||||
var tooltipChartTitle = $spark.attr('sparkTooltipChartTitle') || '';
|
var tooltipChartTitle = $spark.attr('sparkTooltipChartTitle') || '';
|
||||||
var format = $spark.attr('tooltipformat');
|
var format = $spark.attr('tooltipformat');
|
||||||
|
var hideEmpty = $spark.attr('hideEmptyLabel') === 'true';
|
||||||
$spark.sparkline(
|
$spark.sparkline(
|
||||||
'html',
|
'html',
|
||||||
{
|
{
|
||||||
enableTagOptions: true,
|
enableTagOptions: true,
|
||||||
tooltipFormatter: function (sparkline, options, fields) {
|
tooltipFormatter: function (sparkline, options, fields) {
|
||||||
var out = format;
|
var out = format;
|
||||||
|
if (hideEmpty && fields.offset === 3) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
var replace = {
|
var replace = {
|
||||||
title: tooltipChartTitle,
|
title: tooltipChartTitle,
|
||||||
label: labels[fields.offset] ? labels[fields.offset] : fields.offset,
|
label: labels[fields.offset] ? labels[fields.offset] : fields.offset,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user