Revert "RRD Graph optimization (#12735)" (#12805)

This reverts commit 2833d935e0.
This commit is contained in:
Tony Murray
2021-04-28 09:07:31 -05:00
committed by GitHub
parent 2833d935e0
commit 7de808a4e8
7 changed files with 100 additions and 160 deletions

View File

@@ -46,6 +46,14 @@ function var_get($v)
return false;
}
function data_uri($file, $mime)
{
$contents = file_get_contents($file);
$base64 = base64_encode($contents);
return 'data:' . $mime . ';base64,' . $base64;
}//end data_uri()
function toner2colour($descr, $percent)
{
$colour = \LibreNMS\Util\Colors::percentage(100 - $percent, null);
@@ -456,30 +464,19 @@ function graph_error($text, $color = [128, 0, 0])
{
global $vars, $debug;
$type = Config::get('webui.graph_type');
if (! $debug) {
header('Content-type: ' . get_image_type($type));
set_image_type();
}
$width = (int) ($vars['width'] ?? 150);
$height = (int) ($vars['height'] ?? 60);
$width = $vars['width'] ?? 150;
$height = $vars['height'] ?? 60;
if ($type === 'svg') {
if (Config::get('webui.graph_type') === 'svg') {
$rgb = implode(', ', $color);
echo <<<SVG
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
viewBox="0 0 $width $height"
preserveAspectRatio="xMinYMin">
<foreignObject x="0" y="0" width="$width" height="$height" transform="translate(0,0)">
<xhtml:div style="display:table; width:{$width}px; height:{$height}px; overflow:hidden;">
<xhtml:div style="display:table-cell; vertical-align:middle;">
<xhtml:div style="color:rgb($rgb); text-align:center; font-family:sans-serif; font-size:0.6em;">$text</xhtml:div>
</xhtml:div>
</xhtml:div>
</foreignObject>
</svg>
SVG;
$font_size = 20;
$svg_x = 100;
$svg_y = min($font_size, $width ? (($height / $width) * $svg_x) : 1);
echo "<svg viewBox=\"0 0 $svg_x $svg_y\" xmlns=\"http://www.w3.org/2000/svg\"><text x=\"50%\" y=\"50%\" dominant-baseline=\"middle\" text-anchor=\"middle\" style=\"font-family: sans-serif; fill: rgb($rgb);\">$text</text></svg>";
} else {
$img = imagecreate($width, $height);
imagecolorallocatealpha($img, 255, 255, 255, 127); // transparent background
@@ -1022,14 +1019,18 @@ function eventlog_severity($eventlog_severity)
}
} // end eventlog_severity
/**
* Get the http content type of the image
* @param string $type svg or png
* @return string
*/
function get_image_type(string $type)
function set_image_type()
{
return $type === 'svg' ? 'image/svg+xml' : 'image/png';
header('Content-type: ' . get_image_type());
}
function get_image_type()
{
if (Config::get('webui.graph_type') === 'svg') {
return 'image/svg+xml';
} else {
return 'image/png';
}
}
function get_oxidized_nodes_list()