2014-02-19 18:59:54 +01:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-02-19 18:59:54 +01:00
|
|
|
|
|
|
|
namespace Icinga\Chart\Inline;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to render and inline chart directly from the request params.
|
|
|
|
*
|
|
|
|
* When rendering huge amounts of inline charts it is too expensive
|
|
|
|
* to bootstrap the complete application for ever single chart and
|
|
|
|
* we need to be able render Charts in a compact environment without
|
|
|
|
* the other Icinga classes.
|
|
|
|
*
|
|
|
|
* Class Inline
|
|
|
|
* @package Icinga\Chart\Inline
|
|
|
|
*/
|
2014-07-09 18:04:03 +02:00
|
|
|
class Inline
|
|
|
|
{
|
2014-02-19 18:59:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The data displayed in this chart
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The colors used to display this chart
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $colors = array(
|
|
|
|
'#00FF00', // OK
|
|
|
|
'#FFFF00', // Warning
|
|
|
|
'#FF0000', // Critical
|
|
|
|
'#E066FF' // Unreachable
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The labels displayed on this chart
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $labels = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height in percent
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2014-03-26 17:06:21 +01:00
|
|
|
protected $height = 100;
|
2014-02-19 18:59:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The width in percent
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2014-03-26 17:06:21 +01:00
|
|
|
protected $width = 100;
|
2014-02-19 18:59:54 +01:00
|
|
|
|
|
|
|
protected function sanitizeStringArray(array $arr)
|
|
|
|
{
|
|
|
|
$sanitized = array();
|
|
|
|
foreach ($arr as $key => $value) {
|
|
|
|
$sanitized[$key] = htmlspecialchars($value);
|
|
|
|
}
|
|
|
|
return $sanitized;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the properties from the current request.
|
|
|
|
*/
|
|
|
|
public function initFromRequest()
|
|
|
|
{
|
|
|
|
$this->data = explode(',', $_GET['data']);
|
|
|
|
foreach ($this->data as $key => $value) {
|
|
|
|
$this->data[$key] = (int)$value;
|
|
|
|
}
|
2014-06-23 14:17:56 +02:00
|
|
|
for ($i = 0; $i < count($this->data); $i++) {
|
2014-02-19 18:59:54 +01:00
|
|
|
$this->labels[] = '';
|
|
|
|
}
|
|
|
|
|
2014-03-26 14:56:35 +01:00
|
|
|
if (array_key_exists('colors', $_GET)) {
|
2014-02-19 18:59:54 +01:00
|
|
|
$this->colors = $this->sanitizeStringArray(explode(',', $_GET['colors']));
|
|
|
|
}
|
2014-06-23 14:17:56 +02:00
|
|
|
while (count($this->colors) < count($this->data)) {
|
2014-02-19 18:59:54 +01:00
|
|
|
$this->colors[] = '#FEFEFE';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('width', $_GET)) {
|
|
|
|
$this->width = (int)$_GET['width'];
|
|
|
|
}
|
|
|
|
if (array_key_exists('height', $_GET)) {
|
|
|
|
$this->height = (int)$_GET['height'];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-06-30 13:59:58 +02:00
|
|
|
}
|