Improve interface of InlinePie

Method setLabel can also accept a simple string and title is mandatory in constructor
This commit is contained in:
Matthias Jentsch 2014-06-25 15:21:12 +02:00
parent ae4aa9c182
commit 7b19bd1d99
3 changed files with 43 additions and 28 deletions

View File

@ -127,7 +127,7 @@ EOD;
*
* @var string
*/
private $title = '';
private $title;
/**
* The style for the HtmlElement
@ -195,18 +195,22 @@ EOD;
/**
* The labels to be displayed in the pie-chart
*
* @param null $labels
* @param mixed $label The label of the displayed value, or null for no labels
*
* @return $this
* @return $this Fluent interface
*/
public function setLabels($labels = null)
public function setLabel($label)
{
if ($labels != null) {
$this->url->setParam('labels', implode(',', $labels));
if (is_array($label)) {
$this->url->setParam('labels', implode(',', array_keys($label)));
} elseif ($label != null) {
$labelArr = array($label, $label, $label, '');
$this->url->setParam('labels', implode(',', $labelArr));
$label = $labelArr;
} else {
$this->url->removeKey('labels');
}
$this->labels = $labels;
$this->labels = $label;
return $this;
}
@ -319,10 +323,12 @@ EOD;
* Create a new InlinePie
*
* @param array $data The data displayed by the slices
* @param string $title The title of this Pie
* @param array $colors An array of RGB-Color values to use
*/
public function __construct(array $data, $colors = null)
public function __construct(array $data, $title, $colors = null)
{
$this->title = $title;
$this->url = Url::fromPath('svg/chart.php');
if (array_key_exists('data', $data)) {
$this->data = $data['data'];

View File

@ -73,14 +73,18 @@ class Monitoring_MultiController extends Controller
$uniqueComments = array_keys($this->getUniqueValues($comments->getQuery()->fetchAll(), 'comment_internal_id'));
// Populate view
$this->view->objects = $this->view->hosts = $hosts;
$this->view->problems = $this->getProblems($hosts);
$this->view->comments = $uniqueComments;
$this->view->objects = $this->view->hosts = $hosts;
$this->view->problems = $this->getProblems($hosts);
$this->view->comments = $uniqueComments;
$this->view->hostnames = $this->getProperties($hosts, 'host_name');
$this->view->downtimes = $this->getDowntimes($hosts);
$this->view->errors = $errors;
$this->view->states = $this->countStates($hosts, 'host', 'host_name');
$this->view->pie = $this->createPie($this->view->states, $this->view->getHelper('MonitoringState')->getHostStateColors());
$this->view->errors = $errors;
$this->view->states = $this->countStates($hosts, 'host', 'host_name');
$this->view->pie = $this->createPie(
$this->view->states,
$this->view->getHelper('MonitoringState')->getHostStateColors(),
t('Host State')
);
// Handle configuration changes
$this->handleConfigurationForm(array(
@ -138,9 +142,17 @@ class Monitoring_MultiController extends Controller
$this->view->servicenames = $this->getProperties($services, 'service_description');
$this->view->downtimes = $this->getDowntimes($services);
$this->view->service_states = $this->countStates($services, 'service');
$this->view->host_states = $this->countStates($services, 'host', 'host_name');
$this->view->service_pie = $this->createPie($this->view->service_states, $this->view->getHelper('MonitoringState')->getServiceStateColors());
$this->view->host_pie = $this->createPie($this->view->host_states, $this->view->getHelper('MonitoringState')->getHostStateColors());
$this->view->host_states = $this->countStates($services, 'host', 'host_name');
$this->view->service_pie = $this->createPie(
$this->view->service_states,
$this->view->getHelper('MonitoringState')->getServiceStateColors(),
t('Service State')
);
$this->view->host_pie = $this->createPie(
$this->view->host_states,
$this->view->getHelper('MonitoringState')->getHostStateColors(),
t('Host State')
);
$this->view->errors = $errors;
$this->handleConfigurationForm(array(
@ -236,10 +248,11 @@ class Monitoring_MultiController extends Controller
return $states;
}
private function createPie($states, $colors)
private function createPie($states, $colors, $title)
{
$chart = new InlinePie(array_values($states), $colors);
$chart->setLabels(array_keys($states))->setHeight(100)->setWidth(100);
$chart = new InlinePie(array_values($states), $title, $colors);
$chart->setLabel(array_keys($states))->setHeight(100)->setWidth(100);
$chart->setTitle($title);
return $chart;
}

View File

@ -18,18 +18,14 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
if (!$perfdata->isPercentage() && $perfdata->getMaximumValue() === null) {
continue;
}
$pieChart = $this->createInlinePie($perfdata, $label);
$pieChart = $this->createInlinePie($perfdata, $label, htmlspecialchars($label));
if ($compact) {
$pieChart->setTitle(
htmlspecialchars($label) /* . ': ' . htmlspecialchars($this->formatPerfdataValue($perfdata) */
);
if (! $float) {
$result .= $pieChart->render();
} else {
$result .= '<div style="float: right;">' . $pieChart->render() . '</div>';
}
} else {
$pieChart->setTitle(htmlspecialchars($label));
if (! $perfdata->isPercentage()) {
$pieChart->setTooltipFormat('{{label}}: {{formatted}} ({{percent}}%)');
}
@ -85,10 +81,10 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
return $perfdata->getValue();
}
protected function createInlinePie(Perfdata $perfdata, $label = '')
protected function createInlinePie(Perfdata $perfdata, $title, $label = '')
{
$pieChart = new InlinePie($this->calculatePieChartData($perfdata));
$pieChart->setLabels(array($label, $label, $label, ''));
$pieChart = new InlinePie($this->calculatePieChartData($perfdata), $title);
$pieChart->setLabel($label);
$pieChart->setHideEmptyLabel();
//$pieChart->setHeight(32)->setWidth(32);