mirror of
https://github.com/Icinga/icingaweb2-module-graphite.git
synced 2026-03-27 12:53:02 -04:00
Add SPDX license headers and mark source files as GPL-3.0-or-later to preserve the option to relicense under later GPL versions.
52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
namespace Icinga\Module\Graphite\Web\Widget;
|
|
|
|
use Icinga\Module\Graphite\Graphing\Chart;
|
|
use Icinga\Web\Widget\AbstractWidget;
|
|
|
|
class InlineGraphImage extends AbstractWidget
|
|
{
|
|
/**
|
|
* The image to be rendered
|
|
*
|
|
* @var GraphImage
|
|
*/
|
|
protected $image;
|
|
|
|
/**
|
|
* The rendered <img>
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected $rendered;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param Chart $chart The chart to be rendered
|
|
*/
|
|
public function __construct(Chart $chart)
|
|
{
|
|
$this->image = new GraphImage($chart);
|
|
}
|
|
|
|
/**
|
|
* Render the graph lazily
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render()
|
|
{
|
|
if ($this->rendered === null) {
|
|
$this->rendered = '<img src="data:image/png;base64,'
|
|
. implode("\n", str_split(base64_encode($this->image->render()), 76))
|
|
. '">';
|
|
}
|
|
|
|
return $this->rendered;
|
|
}
|
|
}
|