2014-02-19 18:59:54 +01:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Chart\Inline;
|
|
|
|
|
|
|
|
use Icinga\Chart\PieChart as PieChartRenderer;
|
2014-05-21 00:48:06 +02:00
|
|
|
use Imagick;
|
|
|
|
use Exception;
|
2014-08-27 16:03:15 +02:00
|
|
|
use Icinga\Exception\IcingaException;
|
2014-02-19 18:59:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw an inline pie-chart directly from the available request parameters.
|
|
|
|
*/
|
2014-05-21 01:29:13 +02:00
|
|
|
class PieChart extends Inline
|
|
|
|
{
|
|
|
|
|
2014-05-21 00:48:06 +02:00
|
|
|
public function render($output = true)
|
2014-02-19 18:59:54 +01:00
|
|
|
{
|
|
|
|
$pie = new PieChartRenderer();
|
2014-03-26 14:56:35 +01:00
|
|
|
$pie->disableLegend();
|
2014-02-19 18:59:54 +01:00
|
|
|
$pie->drawPie(array(
|
|
|
|
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
|
|
|
|
));
|
|
|
|
$pie->setWidth($this->width)->setHeight($this->height);
|
2014-05-21 00:48:06 +02:00
|
|
|
if ($output) {
|
|
|
|
echo $pie->render();
|
|
|
|
} else {
|
|
|
|
return $pie->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toPng()
|
|
|
|
{
|
2014-05-21 01:29:13 +02:00
|
|
|
if (! class_exists('Imagick')) {
|
2014-05-21 00:48:06 +02:00
|
|
|
// TODO: This is quick & dirty. 404?
|
2014-08-27 16:03:15 +02:00
|
|
|
throw new IcingaException('Cannot render PNGs without Imagick');
|
2014-05-21 00:48:06 +02:00
|
|
|
}
|
|
|
|
$image = new Imagick();
|
|
|
|
$image->readImageBlob($this->render(false));
|
|
|
|
$image->setImageFormat('png24');
|
|
|
|
$image->resizeImage($this->width, $this->height, imagick::FILTER_LANCZOS, 1);
|
|
|
|
echo $image;
|
2014-02-19 18:59:54 +01:00
|
|
|
}
|
2014-05-21 01:29:13 +02:00
|
|
|
}
|