mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 14:54:24 +02:00
Pdf/Charts: add initial chart support to PDFs
Problem: TCPDF had SVG support, dompdf hasn't. This patch adds a first rudimentary PNG conversion and a sample implementation making use of such.
This commit is contained in:
parent
5e69d1d997
commit
24f2ae607f
@ -87,6 +87,17 @@ if (in_array($path, $special)) {
|
|||||||
$pie->initFromRequest();
|
$pie->initFromRequest();
|
||||||
echo $pie->render();
|
echo $pie->render();
|
||||||
|
|
||||||
|
} elseif ($path === 'png/chart.php') {
|
||||||
|
if (!array_key_exists('data', $_GET)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
include __DIR__ . '/EmbeddedWeb.php';
|
||||||
|
EmbeddedWeb::start();
|
||||||
|
header('Content-Type: image/png');
|
||||||
|
$pie = new PieChart();
|
||||||
|
$pie->initFromRequest();
|
||||||
|
$pie->toPng();
|
||||||
|
|
||||||
} elseif (file_exists($baseDir . '/' . $path) && is_file($baseDir . '/' . $path)) {
|
} elseif (file_exists($baseDir . '/' . $path) && is_file($baseDir . '/' . $path)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,12 +31,14 @@
|
|||||||
namespace Icinga\Chart\Inline;
|
namespace Icinga\Chart\Inline;
|
||||||
|
|
||||||
use Icinga\Chart\PieChart as PieChartRenderer;
|
use Icinga\Chart\PieChart as PieChartRenderer;
|
||||||
|
use Imagick;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
||||||
public function render()
|
public function render($output = true)
|
||||||
{
|
{
|
||||||
$pie = new PieChartRenderer();
|
$pie = new PieChartRenderer();
|
||||||
$pie->disableLegend();
|
$pie->disableLegend();
|
||||||
@ -44,6 +46,23 @@ class PieChart extends Inline {
|
|||||||
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
|
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
|
||||||
));
|
));
|
||||||
$pie->setWidth($this->width)->setHeight($this->height);
|
$pie->setWidth($this->width)->setHeight($this->height);
|
||||||
echo $pie->render();
|
if ($output) {
|
||||||
|
echo $pie->render();
|
||||||
|
} else {
|
||||||
|
return $pie->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toPng()
|
||||||
|
{
|
||||||
|
if (! class_exists('Imagick')) {
|
||||||
|
// TODO: This is quick & dirty. 404?
|
||||||
|
throw new Exception('Cannot render PNGs without Imagick');
|
||||||
|
}
|
||||||
|
$image = new Imagick();
|
||||||
|
$image->readImageBlob($this->render(false));
|
||||||
|
$image->setImageFormat('png24');
|
||||||
|
$image->resizeImage($this->width, $this->height, imagick::FILTER_LANCZOS, 1);
|
||||||
|
echo $image;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,6 +48,7 @@ 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()->getBootstrapDirecory() . '/img/', $html);
|
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirecory() . '/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
library/vendor/dompdf/dompdf_config.inc.php
vendored
4
library/vendor/dompdf/dompdf_config.inc.php
vendored
@ -266,7 +266,7 @@ def("DOMPDF_ENABLE_PHP", false);
|
|||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
def("DOMPDF_ENABLE_JAVASCRIPT", true);
|
def("DOMPDF_ENABLE_JAVASCRIPT", false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable remote file access
|
* Enable remote file access
|
||||||
@ -285,7 +285,7 @@ def("DOMPDF_ENABLE_JAVASCRIPT", true);
|
|||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
def("DOMPDF_ENABLE_REMOTE", false);
|
def("DOMPDF_ENABLE_REMOTE", true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The debug output log
|
* The debug output log
|
||||||
|
Loading…
x
Reference in New Issue
Block a user