diff options
Diffstat (limited to 'library/Graphite/Web/Widget/InlineGraphImage.php')
-rw-r--r-- | library/Graphite/Web/Widget/InlineGraphImage.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/library/Graphite/Web/Widget/InlineGraphImage.php b/library/Graphite/Web/Widget/InlineGraphImage.php new file mode 100644 index 0000000..881384d --- /dev/null +++ b/library/Graphite/Web/Widget/InlineGraphImage.php @@ -0,0 +1,49 @@ +<?php + +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; + } +} |