mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Output image for graphs with no data (#11865)
* Output image for graphs with no data * add font * Fix graph error, try to detect rrd missing * centralize graph_error use it for graph_text_and_exit() * Add SVG, right now the text can get a little big... * fix style
This commit is contained in:
@@ -591,6 +591,62 @@ function generate_port_thumbnail($port)
|
||||
return generate_port_image($port);
|
||||
}//end generate_port_thumbnail()
|
||||
|
||||
/**
|
||||
* Create image to output text instead of a graph.
|
||||
*
|
||||
* @param string $text
|
||||
* @param int[] $color
|
||||
*/
|
||||
function graph_error($text, $color = [128, 0, 0])
|
||||
{
|
||||
global $vars, $debug;
|
||||
|
||||
if (! $debug) {
|
||||
set_image_type();
|
||||
}
|
||||
|
||||
$width = $vars['width'] ?? 150;
|
||||
$height = $vars['height'] ?? 60;
|
||||
|
||||
if (Config::get('webui.graph_type') === 'svg') {
|
||||
$rgb = implode(', ', $color);
|
||||
$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
|
||||
|
||||
$px = ((imagesx($img) - 7.5 * strlen($text)) / 2);
|
||||
$font = $width < 200 ? 3 : 5;
|
||||
imagestring($img, $font, $px, ($height / 2 - 8), $text, imagecolorallocate($img, ...$color));
|
||||
|
||||
// Output the image
|
||||
imagepng($img);
|
||||
imagedestroy($img);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output message to user in image format.
|
||||
*
|
||||
* @param string $text string to display
|
||||
*/
|
||||
function graph_text_and_exit($text)
|
||||
{
|
||||
global $vars;
|
||||
|
||||
if ($vars['showcommand'] == 'yes') {
|
||||
echo $text;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
graph_error($text, [13, 21, 210]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function print_port_thumbnail($args)
|
||||
{
|
||||
echo generate_port_link($args, generate_port_image($args));
|
||||
|
||||
Reference in New Issue
Block a user