mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
parent
b307fe2791
commit
bca28a5ae2
@ -92,7 +92,7 @@ if (in_array($path, $special)) {
|
|||||||
header('Content-Type: image/svg+xml');
|
header('Content-Type: image/svg+xml');
|
||||||
$pie = new PieChart();
|
$pie = new PieChart();
|
||||||
$pie->initFromRequest();
|
$pie->initFromRequest();
|
||||||
echo $pie->render();
|
$pie->toSvg();
|
||||||
|
|
||||||
} elseif ($path === 'png/chart.php') {
|
} elseif ($path === 'png/chart.php') {
|
||||||
if (!array_key_exists('data', $_GET)) {
|
if (!array_key_exists('data', $_GET)) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Chart;
|
namespace Icinga\Chart;
|
||||||
|
|
||||||
use Exception;
|
use Imagick;
|
||||||
use Icinga\Chart\Legend;
|
use Icinga\Chart\Legend;
|
||||||
use Icinga\Chart\Palette;
|
use Icinga\Chart\Palette;
|
||||||
use Icinga\Chart\Primitive\Drawable;
|
use Icinga\Chart\Primitive\Drawable;
|
||||||
@ -110,6 +110,29 @@ abstract class Chart implements Drawable
|
|||||||
return $this->renderer->render();
|
return $this->renderer->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this graph rendered as PNG
|
||||||
|
*
|
||||||
|
* @param int $width The width of the PNG in pixel
|
||||||
|
* @param int $height The height of the PNG in pixel
|
||||||
|
*
|
||||||
|
* @return string A PNG binary string
|
||||||
|
*
|
||||||
|
* @throws IcingaException In case ImageMagick is not available
|
||||||
|
*/
|
||||||
|
public function toPng($width, $height)
|
||||||
|
{
|
||||||
|
if (! class_exists('Imagick')) {
|
||||||
|
throw new IcingaException('Cannot render PNGs without ImageMagick');
|
||||||
|
}
|
||||||
|
|
||||||
|
$image = new Imagick();
|
||||||
|
$image->readImageBlob($this->render());
|
||||||
|
$image->setImageFormat('png24');
|
||||||
|
$image->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1);
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Align the chart to the top left corner instead of centering it
|
* Align the chart to the top left corner instead of centering it
|
||||||
*
|
*
|
||||||
|
@ -5,17 +5,13 @@
|
|||||||
namespace Icinga\Chart\Inline;
|
namespace Icinga\Chart\Inline;
|
||||||
|
|
||||||
use Icinga\Chart\PieChart as PieChartRenderer;
|
use Icinga\Chart\PieChart as PieChartRenderer;
|
||||||
use Imagick;
|
|
||||||
use Exception;
|
|
||||||
use Icinga\Exception\IcingaException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw an inline pie-chart directly from the available request parameters.
|
* Draw an inline pie-chart directly from the available request parameters.
|
||||||
*/
|
*/
|
||||||
class PieChart extends Inline
|
class PieChart extends Inline
|
||||||
{
|
{
|
||||||
|
protected function getChart()
|
||||||
public function render($output = true)
|
|
||||||
{
|
{
|
||||||
$pie = new PieChartRenderer();
|
$pie = new PieChartRenderer();
|
||||||
$pie->alignTopLeft();
|
$pie->alignTopLeft();
|
||||||
@ -23,23 +19,24 @@ class PieChart extends Inline
|
|||||||
$pie->drawPie(array(
|
$pie->drawPie(array(
|
||||||
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
|
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
|
||||||
));
|
));
|
||||||
|
return $pie;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toSvg($output = true)
|
||||||
|
{
|
||||||
if ($output) {
|
if ($output) {
|
||||||
echo $pie->render();
|
echo $this->getChart()->render();
|
||||||
} else {
|
} else {
|
||||||
return $pie->render();
|
return $this->getChart()->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toPng()
|
public function toPng($output = true)
|
||||||
{
|
{
|
||||||
if (! class_exists('Imagick')) {
|
if ($output) {
|
||||||
// TODO: This is quick & dirty. 404?
|
echo $this->getChart()->toPng($this->width, $this->height);
|
||||||
throw new IcingaException('Cannot render PNGs without Imagick');
|
} else {
|
||||||
}
|
return $this->getChart()->toPng($this->width, $this->height);
|
||||||
$image = new Imagick();
|
}
|
||||||
$image->readImageBlob($this->render(false));
|
|
||||||
$image->setImageFormat('png24');
|
|
||||||
$image->resizeImage($this->width, $this->height, imagick::FILTER_LANCZOS, 1);
|
|
||||||
echo $image;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ class Pdf extends DOMPDF
|
|||||||
$html = $layout->render();
|
$html = $layout->render();
|
||||||
$imgDir = Url::fromPath('img');
|
$imgDir = Url::fromPath('img');
|
||||||
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html);
|
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html);
|
||||||
$html = preg_replace('~src="/svg/chart.php(.*)"~', 'class="icon" src="http://master1.com/png/chart.php$1"', $html);
|
|
||||||
$this->load_html($html);
|
$this->load_html($html);
|
||||||
$this->render();
|
$this->render();
|
||||||
$this->stream(
|
$this->stream(
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
namespace Icinga\Web\Widget\Chart;
|
namespace Icinga\Web\Widget\Chart;
|
||||||
|
|
||||||
|
use Icinga\Chart\PieChart;
|
||||||
use Icinga\Web\Widget\AbstractWidget;
|
use Icinga\Web\Widget\AbstractWidget;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Util\Format;
|
use Icinga\Util\Format;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
|
use Icinga\Exception\IcingaException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A SVG-PieChart intended to be displayed as a small icon next to labels, to offer a better visualization of the
|
* A SVG-PieChart intended to be displayed as a small icon next to labels, to offer a better visualization of the
|
||||||
@ -375,6 +377,22 @@ EOD;
|
|||||||
*/
|
*/
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
if ($this->view()->layout()->getLayout() === 'pdf') {
|
||||||
|
$pie = new PieChart();
|
||||||
|
$pie->alignTopLeft();
|
||||||
|
$pie->disableLegend();
|
||||||
|
$pie->drawPie(array(
|
||||||
|
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
|
||||||
|
));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$png = $pie->toPng($this->width, $this->height);
|
||||||
|
return '<img src="data:image/png;base64,' . base64_encode($png) . '" />';
|
||||||
|
} catch (IcingaException $_) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$template = $this->template;
|
$template = $this->template;
|
||||||
$template = str_replace('{url}', $this->url, $template);
|
$template = str_replace('{url}', $this->url, $template);
|
||||||
|
|
||||||
|
@ -461,8 +461,8 @@ class WebWizard extends Wizard implements SetupWizard
|
|||||||
mt('setup', 'PHP Module: GD'),
|
mt('setup', 'PHP Module: GD'),
|
||||||
mt(
|
mt(
|
||||||
'setup',
|
'setup',
|
||||||
'In case you want icons and graphs being exported to PDF'
|
'In case you want icons being exported to PDF as'
|
||||||
. ' as well, you\'ll need the GD extension for PHP.'
|
. ' well, you\'ll need the GD extension for PHP.'
|
||||||
),
|
),
|
||||||
Platform::extensionLoaded('gd'),
|
Platform::extensionLoaded('gd'),
|
||||||
Platform::extensionLoaded('gd') ? mt('setup', 'The PHP module GD is available') : (
|
Platform::extensionLoaded('gd') ? mt('setup', 'The PHP module GD is available') : (
|
||||||
@ -470,6 +470,19 @@ class WebWizard extends Wizard implements SetupWizard
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$requirements->addOptional(
|
||||||
|
mt('setup', 'PHP Module: Imagick'),
|
||||||
|
mt(
|
||||||
|
'setup',
|
||||||
|
'In case you want graphs being exported to PDF as well'
|
||||||
|
. ', you\'ll need the ImageMagick extension for PHP.'
|
||||||
|
),
|
||||||
|
Platform::extensionLoaded('imagick'),
|
||||||
|
Platform::extensionLoaded('imagick') ? mt('setup', 'The PHP module Imagick is available') : (
|
||||||
|
mt('setup', 'The PHP module Imagick is missing')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$requirements->addOptional(
|
$requirements->addOptional(
|
||||||
mt('setup', 'PHP Module: PDO-MySQL'),
|
mt('setup', 'PHP Module: PDO-MySQL'),
|
||||||
mt(
|
mt(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user